DeterministicESPAsyncWebServer v6.28.0
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
mms.h
Go to the documentation of this file.
1// 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 (DETWS_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/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/cotp + the transport.
20 */
21
22#ifndef DETERMINISTICESPASYNCWEBSERVER_MMS_H
23#define DETERMINISTICESPASYNCWEBSERVER_MMS_H
24
25#include "ServerConfig.h"
26#include <stddef.h>
27#include <stdint.h>
28
29#if DETWS_ENABLE_MMS
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.
33struct Mms
34{
35 static constexpr uint8_t MMS_PDU_CONFIRMED_REQUEST = 0xA0;
36 static constexpr uint8_t MMS_PDU_CONFIRMED_RESPONSE = 0xA1;
37 static constexpr uint8_t MMS_PDU_CONFIRMED_ERROR = 0xA2;
38 static constexpr uint8_t MMS_SERVICE_READ = 0xA4; ///< confirmedServiceRequest/Response [4] read.
39 static constexpr uint8_t MMS_SERVICE_WRITE = 0xA5; ///< [5] write.
40 static constexpr uint8_t MMS_TAG_INVOKE_ID = 0x02; ///< Unsigned32 invokeID (INTEGER tag).
41};
42
43/**
44 * @brief Build an MMS confirmed-request Read PDU for one named variable.
45 * @param invoke_id the invoke id (echoed in the response).
46 * @param item_name the MMS ObjectName (e.g. "LD0/GGIO1$ST$Ind1$stVal"), a VisibleString.
47 * @return the PDU length written, or 0 on overflow / bad args.
48 */
49size_t detws_mms_read_request(uint32_t invoke_id, const char *item_name, uint8_t *out, size_t cap);
50
51/**
52 * @brief Build an MMS confirmed-response Read PDU carrying one pre-encoded AccessResult data value.
53 * @param invoke_id the invoke id from the request.
54 * @param data a caller-encoded BER Data value (e.g. `85 01 01` for a boolean-ish, or an integer);
55 * wrapped in the listOfAccessResult.
56 * @param data_len its length.
57 * @return the PDU length written, or 0 on overflow.
58 */
59size_t detws_mms_read_response(uint32_t invoke_id, const uint8_t *data, size_t data_len, uint8_t *out, size_t cap);
60
61/** @brief A parsed MMS confirmed PDU (top-level). */
62struct MmsPdu
63{
64 uint8_t pdu_tag; ///< MMS_PDU_CONFIRMED_REQUEST / _RESPONSE / _ERROR.
65 uint32_t invoke_id; ///< the decoded invokeID.
66 uint8_t service_tag; ///< the confirmedService tag (MMS_SERVICE_READ, ...), or 0 if none.
67 const uint8_t *service_body; ///< the service content (points into the input), or null.
68 size_t service_len;
69};
70
71/** @brief Parse an MMS confirmed PDU header (pdu tag + invokeID + service tag). @return true if well-formed. */
72bool detws_mms_parse(const uint8_t *pdu, size_t len, MmsPdu *out);
73
74#endif // DETWS_ENABLE_MMS
75#endif // DETERMINISTICESPASYNCWEBSERVER_MMS_H
User-facing configuration for DeterministicESPAsyncWebServer.