51#ifndef DETERMINISTICESPASYNCWEBSERVER_OPCUA_H
52#define DETERMINISTICESPASYNCWEBSERVER_OPCUA_H
72void ua_w_u8(UaWriter *w, uint8_t v);
73void ua_w_u16(UaWriter *w, uint16_t v);
74void ua_w_u32(UaWriter *w, uint32_t v);
75void ua_w_u64(UaWriter *w, uint64_t v);
76void ua_w_i32(UaWriter *w, int32_t v);
77void ua_w_f32(UaWriter *w,
float v);
78void ua_w_f64(UaWriter *w,
double v);
79void ua_w_bool(UaWriter *w,
bool v);
81void ua_w_string(UaWriter *w,
const char *s, int32_t len);
91uint8_t ua_r_u8(UaReader *r);
92uint16_t ua_r_u16(UaReader *r);
93uint32_t ua_r_u32(UaReader *r);
94uint64_t ua_r_u64(UaReader *r);
95int32_t ua_r_i32(UaReader *r);
96float ua_r_f32(UaReader *r);
97double ua_r_f64(UaReader *r);
98bool ua_r_bool(UaReader *r);
104bool ua_r_string(UaReader *r,
char *out,
size_t cap, int32_t *out_len);
119bool opcua_parse_header(
const uint8_t *buf,
size_t len, UaMsgHeader *h);
128 uint32_t protocol_version;
129 uint32_t recv_buf_size;
130 uint32_t send_buf_size;
131 uint32_t max_msg_size;
132 uint32_t max_chunk_count;
136bool opcua_parse_hello(
const uint8_t *msg,
size_t len, OpcUaHello *out);
143size_t opcua_build_ack(
const OpcUaHello *hello, uint8_t *out,
size_t cap);
158void ua_w_nodeid_numeric(UaWriter *w, uint16_t ns, uint32_t
id);
164bool ua_r_nodeid(UaReader *r, UaNodeId *out);
167int64_t opcua_filetime_from_unix(int64_t unix_seconds);
170#define OPCUA_ID_OPEN_REQ 446
171#define OPCUA_ID_OPEN_RESP 449
174#define OPCUA_POLICY_NONE_URI "http://opcfoundation.org/UA/SecurityPolicy#None"
181struct OpcUaOpenChannel
183 uint32_t secure_channel_id;
184 uint32_t sequence_number;
186 uint32_t request_handle;
187 uint32_t client_protocol_version;
188 uint32_t security_token_request_type;
189 uint32_t message_security_mode;
190 uint32_t requested_lifetime;
194bool opcua_parse_open(
const uint8_t *msg,
size_t len, OpcUaOpenChannel *out);
206size_t opcua_build_open_response(
const OpcUaOpenChannel *req, uint32_t channel_id, uint32_t token_id,
207 uint32_t seq_number, int64_t now_ft, uint32_t lifetime, uint8_t *out,
size_t cap);
214#define OPCUA_ID_CREATE_SESSION_REQ 461
215#define OPCUA_ID_CREATE_SESSION_RESP 464
216#define OPCUA_ID_ACTIVATE_SESSION_REQ 467
217#define OPCUA_ID_ACTIVATE_SESSION_RESP 470
222 uint32_t secure_channel_id;
224 uint32_t sequence_number;
227 uint32_t request_handle;
235bool opcua_parse_msg(
const uint8_t *msg,
size_t len, OpcUaMsg *out);
238struct OpcUaServerInfo
240 const char *endpoint_url;
241 const char *application_uri;
242 const char *application_name;
258size_t opcua_build_create_session_response(
const OpcUaMsg *req, uint32_t session_id, uint32_t auth_token,
259 double revised_timeout,
const OpcUaServerInfo *info, uint32_t seq,
260 int64_t now_ft, uint8_t *out,
size_t cap);
267size_t opcua_build_activate_session_response(
const OpcUaMsg *req, uint32_t seq, int64_t now_ft, uint8_t *out,
275#define OPCUA_ID_READ_REQ 631
276#define OPCUA_ID_READ_RESP 634
279#define OPCUA_ATTR_VALUE 13
282#define OPCUA_STATUS_GOOD 0x00000000u
283#define OPCUA_STATUS_BAD_NODE_ID_UNKNOWN 0x80340000u
286enum class OpcUaVariantType : uint8_t
291 OPCUA_VAR_UINT32 = 7,
292 OPCUA_VAR_FLOAT = 10,
293 OPCUA_VAR_DOUBLE = 11,
294 OPCUA_VAR_STRING = 12,
300 OpcUaVariantType type;
311void ua_w_variant(UaWriter *w,
const OpcUaVariant *v);
314void ua_w_datavalue(UaWriter *w,
const OpcUaVariant *v, uint32_t status);
320bool ua_r_variant(UaReader *r, OpcUaVariant *out);
328bool ua_r_datavalue(UaReader *r, OpcUaVariant *out_value, uint32_t *out_status);
340struct OpcUaReadRequest
345 OpcUaReadItem items[DETWS_OPCUA_READ_MAX];
349bool opcua_parse_read(
const uint8_t *msg,
size_t len, OpcUaReadRequest *out);
357size_t opcua_build_read_response(
const OpcUaReadRequest *req,
const OpcUaVariant *values,
const uint32_t *statuses,
358 uint32_t seq, int64_t now_ft, uint8_t *out,
size_t cap);
364typedef bool (*OpcUaReadHandler)(uint16_t ns, uint32_t id, uint32_t attribute, OpcUaVariant *out);
367void opcua_set_read_handler(OpcUaReadHandler fn);
374#define OPCUA_ID_BROWSE_REQ 527
375#define OPCUA_ID_BROWSE_RESP 530
376#define OPCUA_ID_CLOSE_SESSION_REQ 473
377#define OPCUA_ID_CLOSE_SESSION_RESP 476
380#define OPCUA_NODECLASS_OBJECT 1
381#define OPCUA_NODECLASS_VARIABLE 2
382#define OPCUA_REFTYPE_ORGANIZES 35
383#define OPCUA_REFTYPE_HAS_COMPONENT 47
384#define OPCUA_TYPEDEF_BASE_OBJECT 58
385#define OPCUA_TYPEDEF_BASE_DATA_VARIABLE 63
388void ua_w_qualifiedname(UaWriter *w, uint16_t ns,
const char *name);
391void ua_w_localizedtext(UaWriter *w,
const char *locale,
const char *text);
396 uint32_t ref_type_id;
400 uint16_t browse_name_ns;
401 const char *browse_name;
402 const char *display_name;
404 uint32_t type_def_id;
408void ua_w_reference(UaWriter *w,
const OpcUaReference *ref);
411struct OpcUaBrowseItem
419struct OpcUaBrowseRequest
424 OpcUaBrowseItem items[DETWS_OPCUA_BROWSE_MAX];
428bool opcua_parse_browse(
const uint8_t *msg,
size_t len, OpcUaBrowseRequest *out);
435typedef int32_t (*OpcUaBrowseHandler)(uint16_t ns, uint32_t id, OpcUaReference *out, uint32_t max);
438void opcua_set_browse_handler(OpcUaBrowseHandler fn);
445size_t opcua_build_browse_response(
const OpcUaBrowseRequest *req, OpcUaBrowseHandler handler, uint32_t seq,
446 int64_t now_ft, uint8_t *out,
size_t cap);
449size_t opcua_build_close_session_response(
const OpcUaMsg *req, uint32_t seq, int64_t now_ft, uint8_t *out,
size_t cap);
456#define OPCUA_ID_GET_ENDPOINTS_REQ 428
457#define OPCUA_ID_GET_ENDPOINTS_RESP 431
458#define OPCUA_ID_SERVICE_FAULT 397
461#define OPCUA_STATUS_BAD_SERVICE_UNSUPPORTED 0x800B0000u
464void ua_w_endpoint_description(UaWriter *w,
const OpcUaServerInfo *info);
467size_t opcua_build_get_endpoints_response(
const OpcUaMsg *req,
const OpcUaServerInfo *info, uint32_t seq,
468 int64_t now_ft, uint8_t *out,
size_t cap);
474size_t opcua_build_service_fault(
const OpcUaMsg *req, uint32_t service_result, uint32_t seq, int64_t now_ft,
475 uint8_t *out,
size_t cap);
478void opcua_set_endpoint_url(
const char *url);
485#define OPCUA_ID_WRITE_REQ 673
486#define OPCUA_ID_WRITE_RESP 676
489#define OPCUA_STATUS_BAD_NOT_WRITABLE 0x803B0000u
502struct OpcUaWriteRequest
507 OpcUaWriteItem items[DETWS_OPCUA_WRITE_MAX];
511bool opcua_parse_write(
const uint8_t *msg,
size_t len, OpcUaWriteRequest *out);
518size_t opcua_build_write_response(
const OpcUaWriteRequest *req,
const uint32_t *results, uint32_t seq, int64_t now_ft,
519 uint8_t *out,
size_t cap);
526typedef uint32_t (*OpcUaWriteHandler)(uint16_t ns, uint32_t id, uint32_t attribute,
const OpcUaVariant *value);
529void opcua_set_write_handler(OpcUaWriteHandler fn);
545void opcua_rx(uint8_t slot);
User-facing configuration for DeterministicESPAsyncWebServer.
Per-protocol connection event/poll callbacks (Layer 5 dispatch vtable).