MQTT-SN Gateway Library
Library that allows implementation of MQTT-SN gateway.
Loading...
Searching...
No Matches
gateway_all.h
Go to the documentation of this file.
1//
2// Copyright 2016 - 2026 (C). Alex Robenko. All rights reserved.
3//
4// SPDX-License-Identifier: MPL-2.0
5//
6// This Source Code Form is subject to the terms of the Mozilla Public
7// License, v. 2.0. If a copy of the MPL was not distributed with this
8// file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
12
13#pragma once
14
15#include "version.h"
16
17#ifdef __cplusplus
18extern "C" {
19#else // #ifdef __cplusplus
20#include <stdbool.h>
21#endif // #ifdef __cplusplus
22
23/*===================== Gateway Object ======================*/
24
26struct CC_MqttsnGateway;
27
29typedef struct CC_MqttsnGateway* CC_MqttsnGatewayHandle;
30
38typedef void (*CC_MqttsnGwTickReqCb)(void* userData, unsigned duration);
39
50typedef void (*CC_MqttsnGwBroadcastReqCb)(void* userData, const unsigned char* buf, unsigned bufLen);
51
59
63
68
72
77
81
90
98 void* data);
99
108
112
118
119/*===================== Session Object ======================*/
120
122struct CC_MqttsnSession;
123
125typedef struct CC_MqttsnSession* CC_MqttsnSessionHandle;
126
133typedef void (*CC_MqttsnSessionTickReqCb)(void* userData, CC_MqttsnSessionHandle session, unsigned duration);
134
143typedef unsigned (*CC_MqttsnSessionCancelTickReqCb)(void* userData, CC_MqttsnSessionHandle session);
144
152typedef void (*CC_MqttsnSessionClientSendDataReqCb)(void* userData, CC_MqttsnSessionHandle session, const unsigned char* buf, unsigned bufLen, unsigned broadcastRadius);
153
160typedef void (*CC_MqttsnSessionBrokerSendDataReqCb)(void* userData, CC_MqttsnSessionHandle session, const unsigned char* buf, unsigned bufLen);
161
168typedef void (*CC_MqttsnSessionTermReqCb)(void* userData, CC_MqttsnSessionHandle session);
169
175typedef void (*CC_MqttsnSessionBrokerReconnectReqCb)(void* userData, CC_MqttsnSessionHandle session);
176
184typedef void (*CC_MqttsnSessionClientConnectReportCb)(void* userData, CC_MqttsnSessionHandle session, const char* clientId);
185
195 void* userData,
197 const char* clientId,
198 const char** username,
199 const unsigned char** password,
200 unsigned* passwordLen);
201
206typedef void (*CC_MqttsnSessionErrorReportCb)(void* userData, CC_MqttsnSessionHandle session, const char* msg);
207
217typedef bool (*CC_MqttsnSessionFwdEncSessionCreatedCb)(void* userData, CC_MqttsnSessionHandle session);
218
223typedef void (*CC_MqttsnSessionFwdEncSessionDeletedCb)(void* userData, CC_MqttsnSessionHandle session);
224
232
236
247 void* data);
248
260 void* data);
261
273 void* data);
274
286 void* data);
287
299 void* data);
300
312 void* data);
313
326 void* data);
327
340 void* data);
341
351 void* data);
352
363 void* data);
364
374 void* data);
375
381
385
395
399
409
413
425 unsigned long long value);
426
430
436
440
454
458
466
470
476
489 const unsigned char* buf,
490 unsigned bufLen);
491
504 const unsigned char* buf,
505 unsigned bufLen);
506
515
519
527 const char* topic,
528 unsigned short topicId);
529
537 unsigned short minTopicId,
538 unsigned short maxTopicId);
539
540/*===================== Config Object ======================*/
541
543typedef struct
544{
545 const char* clientId;
546 const char* topic;
547 unsigned short topicId;
549
551typedef struct
552{
553 const char* clientId;
554 const char* username;
555 const char* password;
557
564
571
573struct CC_MqttsnConfig;
574
576typedef struct CC_MqttsnConfig* CC_MqttsnConfigHandle;
577
585
589
595
600bool cc_mqttsn_gw_config_read(CC_MqttsnConfigHandle config, const char* filename);
601
607
613
619
625
631
637
644
648
657 unsigned bufLen);
658
662
671 unsigned bufLen);
672
680 unsigned short* min,
681 unsigned short* max);
682
687
692
697
701
705
712
717const char* cc_mqttsn_gw_config_get_value(CC_MqttsnConfigHandle config, const char* key, unsigned idx);
718
719#ifdef __cplusplus
720}
721#endif
722
unsigned cc_mqttsn_gw_config_retry_count(CC_MqttsnConfigHandle config)
Get number of retry attempts.
void(* CC_MqttsnSessionBrokerSendDataReqCb)(void *userData, CC_MqttsnSessionHandle session, const unsigned char *buf, unsigned bufLen)
Type of callback, used to request delivery of serialised message to the broker.
Definition gateway_all.h:160
void cc_mqttsn_gw_session_set_error_report_cb(CC_MqttsnSessionHandle session, CC_MqttsnSessionErrorReportCb cb, void *data)
Set the callback to be used to report error messages detected by the session.
bool cc_mqttsn_gw_start(CC_MqttsnGatewayHandle gw)
Start operation of the Gateway object.
bool cc_mqttsn_gw_session_add_predefined_topic(CC_MqttsnSessionHandle session, const char *topic, unsigned short topicId)
Add predefined topic string and ID information.
void cc_mqttsn_gw_config_free(CC_MqttsnConfigHandle config)
Free allocated Config object.
struct CC_MqttsnGateway * CC_MqttsnGatewayHandle
Handle for gateway object used in all cc_mqttsn_gw_* functions.
Definition gateway_all.h:29
struct CC_MqttsnConfig * CC_MqttsnConfigHandle
Handle for session object used in all cc_mqttsn_gw_config_* functions.
Definition gateway_all.h:576
const char * cc_mqttsn_gw_session_get_default_client_id(CC_MqttsnSessionHandle session)
Get current default client ID configuration.
void cc_mqttsn_gw_session_set_broker_reconnect_req_cb(CC_MqttsnSessionHandle session, CC_MqttsnSessionBrokerReconnectReqCb cb, void *data)
Set the callback to be invoked when the Session needs to close existing TCP/IP connection to the brok...
unsigned long long cc_mqttsn_gw_session_get_sleeping_client_msg_limit(CC_MqttsnSessionHandle session)
Get currenly configured limit to pending messages being accumulated for the sleeping client.
struct CC_MqttsnSession * CC_MqttsnSessionHandle
Handle for session object used in all cc_mqttsn_gw_session_* functions.
Definition gateway_all.h:125
bool cc_mqttsn_gw_session_get_broker_connected(CC_MqttsnSessionHandle session)
Get currently recorded broker connection status.
unsigned cc_mqttsn_gw_config_pub_only_keep_alive(CC_MqttsnConfigHandle config)
Get keep alive period for publish only clients.
void(* CC_MqttsnSessionAuthInfoReqCb)(void *userData, CC_MqttsnSessionHandle session, const char *clientId, const char **username, const unsigned char **password, unsigned *passwordLen)
Type of callback used to request authentication information of the client that is trying to connect.
Definition gateway_all.h:194
void cc_mqttsn_gw_session_set_send_data_to_broker_cb(CC_MqttsnSessionHandle session, CC_MqttsnSessionBrokerSendDataReqCb cb, void *data)
Set the callback to be invoked when new data needs to be sent to the broker.
unsigned cc_mqttsn_gw_config_values_count(CC_MqttsnConfigHandle config, const char *key)
Get number of available configuration values for the provided key.
CC_MqttsnBrokerConnectionType
Broker I/O socket connection type.
Definition gateway_all.h:567
@ CC_MqttsnBrokerConnectionType_ValuesLimit
Limit to available values, must be last.
Definition gateway_all.h:569
@ CC_MqttsnBrokerConnectionType_Tcp
TCP/IP.
Definition gateway_all.h:568
CC_MqttsnConfigHandle cc_mqttsn_gw_config_alloc(void)
Allocate Config object.
void(* CC_MqttsnSessionClientSendDataReqCb)(void *userData, CC_MqttsnSessionHandle session, const unsigned char *buf, unsigned bufLen, unsigned broadcastRadius)
Type of callback, used to request delivery of serialised message to the client.
Definition gateway_all.h:152
bool cc_mqttsn_gw_session_start(CC_MqttsnSessionHandle session)
Start the Session's object's operation.
void(* CC_MqttsnSessionBrokerReconnectReqCb)(void *userData, CC_MqttsnSessionHandle session)
Type of callback used to request reconnection to the broker.
Definition gateway_all.h:175
void cc_mqttsn_gw_set_advertise_broadcast_req_cb(CC_MqttsnGatewayHandle gw, CC_MqttsnGwBroadcastReqCb cb, void *data)
Set callback that requests to send serialised ADVERTISE message.
void cc_mqttsn_gw_session_set_retry_count(CC_MqttsnSessionHandle session, unsigned value)
Set number of retry attempts to perform before abandoning attempt to send unacknowledged message.
unsigned char cc_mqttsn_gw_session_get_id(CC_MqttsnSessionHandle session)
Get current gateway numeric ID configuration.
void cc_mqttsn_gw_session_set_pub_only_keep_alive(CC_MqttsnSessionHandle session, unsigned value)
Provide default "keep alive" period for "publish only" clients, that do not make an attempt to connec...
unsigned short cc_mqttsn_gw_config_broker_port(CC_MqttsnConfigHandle config)
Get TCP/IP port of the broker.
void cc_mqttsn_gw_session_set_fwd_enc_session_deleted_cb(CC_MqttsnSessionHandle session, CC_MqttsnSessionFwdEncSessionDeletedCb cb, void *data)
Set the callback to be invoked when the forwarding encapsulation session is about to be deleted.
bool(* CC_MqttsnSessionFwdEncSessionCreatedCb)(void *userData, CC_MqttsnSessionHandle session)
Type of callback used to report forwarding encapsulated session creation.
Definition gateway_all.h:217
void cc_mqttsn_gw_set_id(CC_MqttsnGatewayHandle gw, unsigned char id)
Set the numeric gateway ID.
CC_MqttsnClientConnectionType cc_mqttsn_gw_config_client_connection_type(CC_MqttsnConfigHandle config)
Get client I/O socket connection type.
CC_MqttsnSessionHandle cc_mqttsn_gw_session_alloc(void)
Allocate Session object.
unsigned cc_mqttsn_gw_config_retry_period(CC_MqttsnConfigHandle config)
Get retry period.
void cc_mqttsn_gw_session_tick(CC_MqttsnSessionHandle session)
Notify the Session object about requested time period expiry.
void cc_mqttsn_gw_config_parse(CC_MqttsnConfigHandle config, const char *str)
Parse configuration contents from string.
const char * cc_mqttsn_gw_config_broker_address(CC_MqttsnConfigHandle config)
Get TCP/IP address of the broker.
unsigned cc_mqttsn_gw_config_get_auth_infos(CC_MqttsnConfigHandle config, CC_MqttsnAuthInfo *buf, unsigned bufLen)
Read clients' authentication information into a buffer.
void(* CC_MqttsnSessionClientConnectReportCb)(void *userData, CC_MqttsnSessionHandle session, const char *clientId)
Type of callback used to report client ID of the newly connected MQTT-SN client.
Definition gateway_all.h:184
const char * cc_mqttsn_gw_config_log_file(CC_MqttsnConfigHandle config)
Get log file.
const char * cc_mqttsn_gw_config_default_client_id(CC_MqttsnConfigHandle config)
Get default client ID.
void cc_mqttsn_gw_session_set_auth_info_req_cb(CC_MqttsnSessionHandle session, CC_MqttsnSessionAuthInfoReqCb cb, void *data)
Set the callback to be used to request authentication information for specific client.
void cc_mqttsn_gw_set_advertise_period(CC_MqttsnGatewayHandle gw, unsigned short value)
Set the advertise period.
void(* CC_MqttsnSessionTickReqCb)(void *userData, CC_MqttsnSessionHandle session, unsigned duration)
Type of callback, used to request new time measurement.
Definition gateway_all.h:133
void cc_mqttsn_gw_set_tick_req_cb(CC_MqttsnGatewayHandle gw, CC_MqttsnGwTickReqCb cb, void *data)
Set callback that requests to perform time measurement.
unsigned short cc_mqttsn_gw_config_advertise_period(CC_MqttsnConfigHandle config)
Get advertise period.
unsigned cc_mqttsn_gw_config_get_predefined_topics(CC_MqttsnConfigHandle config, CC_MqttsnPredefinedTopicInfo *buf, unsigned bufLen)
Read information about available topic IDs into a buffer.
void cc_mqttsn_gw_session_set_term_req_cb(CC_MqttsnSessionHandle session, CC_MqttsnSessionTermReqCb cb, void *data)
Set the callback to be invoked when the Session needs to be terminated and the calling Session object...
void cc_mqttsn_gw_free(CC_MqttsnGatewayHandle gw)
Free allocated Gateway object.
void(* CC_MqttsnSessionTermReqCb)(void *userData, CC_MqttsnSessionHandle session)
Type of callback, used to request session termination.
Definition gateway_all.h:168
void cc_mqttsn_gw_session_free(CC_MqttsnSessionHandle session)
Free allocated Session object.
void cc_mqttsn_gw_session_set_tick_req_cb(CC_MqttsnSessionHandle session, CC_MqttsnSessionTickReqCb cb, void *data)
Set the callback to be invoked when new time measurement is required.
unsigned cc_mqttsn_gw_session_data_from_client(CC_MqttsnSessionHandle session, const unsigned char *buf, unsigned bufLen)
Provide data received from the client for processing.
void cc_mqttsn_gw_session_set_cancel_tick_cb(CC_MqttsnSessionHandle session, CC_MqttsnSessionCancelTickReqCb cb, void *data)
Set the callback to be invoked when previously requested time measurement needs to be cancelled.
CC_MqttsnClientConnectionType
Client I/O socket connection type.
Definition gateway_all.h:560
@ CC_MqttsnClientConnectionType_ValuesLimit
Limit to available values, must be last.
Definition gateway_all.h:562
@ CC_MqttsnClientConnectionType_Udp
UDP/IP.
Definition gateway_all.h:561
CC_MqttsnGatewayHandle cc_mqttsn_gw_alloc(void)
Allocate Gateway object.
unsigned cc_mqttsn_gw_session_get_retry_period(CC_MqttsnSessionHandle session)
Get the current configuration of the retry period.
unsigned cc_mqttsn_gw_config_sleeping_client_msg_limit(CC_MqttsnConfigHandle config)
Get limit for max number of messages to accumulate for sleeping clients.
void cc_mqttsn_gw_session_set_id(CC_MqttsnSessionHandle session, unsigned char id)
Set gateway numeric ID to be reported when requested.
void cc_mqttsn_gw_session_stop(CC_MqttsnSessionHandle session)
Stop the operation of the Session object.
void(* CC_MqttsnSessionFwdEncSessionDeletedCb)(void *userData, CC_MqttsnSessionHandle session)
Type of callback used to report forwarding encapsulated session about to be deleted.
Definition gateway_all.h:223
void cc_mqttsn_gw_session_set_retry_period(CC_MqttsnSessionHandle session, unsigned value)
Set retry period to wait between resending unacknowledged message to the client and/or broker.
void cc_mqttsn_gw_session_set_sleeping_client_msg_limit(CC_MqttsnSessionHandle session, unsigned long long value)
Provide limit to number pending messages being accumulated for the sleeping client.
void cc_mqttsn_gw_session_set_send_data_to_client_cb(CC_MqttsnSessionHandle session, CC_MqttsnSessionClientSendDataReqCb cb, void *data)
Set the callback to be invoked when new data needs to be sent to the client.
void(* CC_MqttsnGwBroadcastReqCb)(void *userData, const unsigned char *buf, unsigned bufLen)
Type of callback function, to be used to request broadcast of serialised ADVERTISE message.
Definition gateway_all.h:50
unsigned short cc_mqttsn_gw_get_advertise_period(CC_MqttsnGatewayHandle gw)
Get current configuration of the advertise period.
void cc_mqttsn_gw_session_set_fwd_enc_session_created_cb(CC_MqttsnSessionHandle session, CC_MqttsnSessionFwdEncSessionCreatedCb cb, void *data)
Set the callback to be invoked when the forwarding encapsulation session is detected and to notify ap...
unsigned char cc_mqttsn_gw_get_id(CC_MqttsnGatewayHandle gw)
Get current configuration of the numeric gateway id.
unsigned char cc_mqttsn_gw_config_id(CC_MqttsnConfigHandle config)
Get gateway numeric ID.
void cc_mqttsn_gw_stop(CC_MqttsnGatewayHandle gw)
Stop operation of the Gateway object.
void cc_mqttsn_gw_session_set_client_connect_report_cb(CC_MqttsnSessionHandle session, CC_MqttsnSessionClientConnectReportCb cb, void *data)
Set the callback to be invoked when MQTT-SN client is successfully connected to the broker.
const char * cc_mqttsn_gw_config_get_value(CC_MqttsnConfigHandle config, const char *key, unsigned idx)
Get the available value for the configuration key.
unsigned cc_mqttsn_gw_session_get_retry_count(CC_MqttsnSessionHandle session)
Get the current configuration of the retry count.
unsigned(* CC_MqttsnSessionCancelTickReqCb)(void *userData, CC_MqttsnSessionHandle session)
Type of callback, used to cancel existing time measurement.
Definition gateway_all.h:143
void cc_mqttsn_gw_session_set_broker_connected(CC_MqttsnSessionHandle session, bool connected)
Notify the Session object about broker being connected / disconnected.
unsigned cc_mqttsn_gw_session_data_from_broker(CC_MqttsnSessionHandle session, const unsigned char *buf, unsigned bufLen)
Provide data received from the broker for processing.
unsigned cc_mqttsn_gw_session_get_pub_only_keep_alive(CC_MqttsnSessionHandle session)
Get current configuration of the default "keep alive" period for "publish only" clients.
void(* CC_MqttsnGwTickReqCb)(void *userData, unsigned duration)
Type of callback function, to be used to request time measurement for the Gateway object.
Definition gateway_all.h:38
void cc_mqttsn_gw_session_set_default_client_id(CC_MqttsnSessionHandle session, const char *clientId)
Provide default client ID for clients that report empty one in their attempt to connect.
void cc_mqttsn_gw_tick(CC_MqttsnGatewayHandle gw)
Notify the Gateway object about requested time expiry.
bool cc_mqttsn_gw_config_read(CC_MqttsnConfigHandle config, const char *filename)
Read configuration file.
void cc_mqttsn_gw_config_topic_id_alloc_range(CC_MqttsnConfigHandle config, unsigned short *min, unsigned short *max)
Get range of allowed topic IDs for allocation.
unsigned cc_mqttsn_gw_config_available_auth_infos(CC_MqttsnConfigHandle config)
Get number of available authenticatin infos for all the clients.
unsigned cc_mqttsn_gw_config_available_predefined_topics(CC_MqttsnConfigHandle config)
Get number of available predefined topic IDs.
void(* CC_MqttsnSessionErrorReportCb)(void *userData, CC_MqttsnSessionHandle session, const char *msg)
Type of callback used to report error messages detected by the session.
Definition gateway_all.h:206
CC_MqttsnBrokerConnectionType cc_mqttsn_gw_config_broker_connection_type(CC_MqttsnConfigHandle config)
Get broker I/O socket connection type.
bool cc_mqttsn_gw_session_set_topic_id_alloc_range(CC_MqttsnSessionHandle session, unsigned short minTopicId, unsigned short maxTopicId)
Limit range of topic IDs allocated for newly registered topics.
Authentication infor for a single client.
Definition gateway_all.h:552
const char * clientId
Client ID.
Definition gateway_all.h:553
const char * password
Password string (from the configuration)
Definition gateway_all.h:555
const char * username
Username string.
Definition gateway_all.h:554
Info about single predefined topic.
Definition gateway_all.h:544
unsigned short topicId
Numeric topic ID.
Definition gateway_all.h:547
const char * topic
Topic string.
Definition gateway_all.h:546
const char * clientId
Client ID.
Definition gateway_all.h:545
Contains version information of the library.