ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
mms.h
Go to the documentation of this file.
1// ProtoCore v1.0.16 - Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file mms.h
6 * @brief IEC 61850 MMS (Manufacturing Message Specification) PDU codec (PROTOCORE_ENABLE_MMS).
7 *
8 * MMS (ISO 9506) is the client/server core of IEC 61850: an ACSI object model (logical devices/nodes,
9 * data objects, datasets) carried as BER-encoded MMS PDUs over ISO-on-TCP (TPKT + COTP, already shipped
10 * as services/fieldbus/cotp) on port 102. This builds the two most-used PDUs:
11 *
12 * - **confirmed-request / Read**: `[A0 { 02 invokeID A4 confirmedServiceRequest { A4 read { A1
13 * variableAccessSpecification { A0 listOfVariable { 30 { A0 objectName { 1A domain-specific { ... }}}}}}}]`
14 * - a request to read one named variable (a Data Object reference like "LD0/GGIO1$ST$Ind1$stVal").
15 * - **confirmed-response / Read data**: the response carrying the AccessResult data value.
16 *
17 * This is the MMS PDU framing + the Read request/response builders (the variable name passed as a MMS
18 * ObjectName VisibleString; the response data as a caller-encoded BER blob). Pure, zero heap, no stdlib,
19 * host-testable; TPKT/COTP wrapping + the socket are services/fieldbus/cotp + the transport.
20 */
21
22#ifndef PROTOCORE_MMS_H
23#define PROTOCORE_MMS_H
24
25#include "protocore_config.h" // the entry point: protocore_types.h for the widths
26
27#if PROTOCORE_ENABLE_MMS
28
30
31/** @brief MMS PDU tags (context-specific) + the service tags used here. */
32// MMS PDU / service / BER tags: wire bytes, so integer constants in a namespacing struct.
33#define MMS_PDU_CONFIRMED_REQUEST 0xA0
34#define MMS_PDU_CONFIRMED_RESPONSE 0xA1
35#define MMS_PDU_CONFIRMED_ERROR 0xA2
36#define MMS_SERVICE_READ 0xA4 ///< confirmedServiceRequest/Response [4] read.
37#define MMS_SERVICE_WRITE 0xA5 ///< [5] write.
38#define MMS_TAG_INVOKE_ID 0x02 ///< Unsigned32 invokeID (INTEGER tag).
39
40/**
41 * @brief Build an MMS confirmed-request Read PDU for one named variable.
42 * @param invoke_id the invoke id (echoed in the response).
43 * @param item_name the MMS ObjectName (e.g. "LD0/GGIO1$ST$Ind1$stVal"), a VisibleString.
44 * @return the PDU length written, or 0 on overflow / bad args.
45 */
46size_t protocore_mms_read_request(uint32_t invoke_id, const char *item_name, uint8_t *out, size_t cap);
47
48/**
49 * @brief Build an MMS confirmed-response Read PDU carrying one pre-encoded AccessResult data value.
50 * @param invoke_id the invoke id from the request.
51 * @param data a caller-encoded BER Data value (e.g. `85 01 01` for a boolean-ish, or an integer);
52 * wrapped in the listOfAccessResult.
53 * @param data_len its length.
54 * @return the PDU length written, or 0 on overflow.
55 */
56size_t protocore_mms_read_response(uint32_t invoke_id, const uint8_t *data, size_t data_len, uint8_t *out, size_t cap);
57
58/** @brief A parsed MMS confirmed PDU (top-level). */
59typedef struct
60{
61 uint8_t pdu_tag; ///< MMS_PDU_CONFIRMED_REQUEST / _RESPONSE / _ERROR.
62 uint32_t invoke_id; ///< the decoded invokeID.
63 uint8_t service_tag; ///< the confirmedService tag (MMS_SERVICE_READ, ...), or 0 if none.
64 const uint8_t *service_body; ///< the service content (points into the input), or null.
65 size_t service_len;
66} MmsPdu;
67
68/** @brief Parse an MMS confirmed PDU header (pdu tag + invokeID + service tag). @return true if well-formed. */
69proto_bool protocore_mms_parse(const uint8_t *pdu, size_t len, MmsPdu *out);
70
72
73#endif // PROTOCORE_ENABLE_MMS
74
75#endif // PROTOCORE_MMS_H
#define PROTOCORE_BEGIN_DECLS
Give a header's declarations C linkage, so their symbol names carry no parameter types.
Definition types.h:96
_Bool proto_bool
The truth value.
Definition types.h:64
#define PROTOCORE_END_DECLS
Definition types.h:97