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 - 2024 (C). Alex Robenko. All rights reserved.
3//
4// This Source Code Form is subject to the terms of the Mozilla Public
5// License, v. 2.0. If a copy of the MPL was not distributed with this
6// file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
10
11#pragma once
12
13#include "version.h"
14
15#ifdef __cplusplus
16extern "C" {
17#else // #ifdef __cplusplus
18#include <stdbool.h>
19#endif // #ifdef __cplusplus
20
21/*===================== Gateway Object ======================*/
22
24struct CC_MqttsnGateway;
25
27typedef struct CC_MqttsnGateway* CC_MqttsnGatewayHandle;
28
36typedef void (*CC_MqttsnGwTickReqCb)(void* userData, unsigned duration);
37
48typedef void (*CC_MqttsnGwBroadcastReqCb)(void* userData, const unsigned char* buf, unsigned bufLen);
49
57
61
66
70
75
79
88
96 void* data);
97
106
110
116
117/*===================== Session Object ======================*/
118
120struct CC_MqttsnSession;
121
123typedef struct CC_MqttsnSession* CC_MqttsnSessionHandle;
124
131typedef void (*CC_MqttsnSessionTickReqCb)(void* userData, CC_MqttsnSessionHandle session, unsigned duration);
132
141typedef unsigned (*CC_MqttsnSessionCancelTickReqCb)(void* userData, CC_MqttsnSessionHandle session);
142
150typedef void (*CC_MqttsnSessionClientSendDataReqCb)(void* userData, CC_MqttsnSessionHandle session, const unsigned char* buf, unsigned bufLen, unsigned broadcastRadius);
151
158typedef void (*CC_MqttsnSessionBrokerSendDataReqCb)(void* userData, CC_MqttsnSessionHandle session, const unsigned char* buf, unsigned bufLen);
159
166typedef void (*CC_MqttsnSessionTermReqCb)(void* userData, CC_MqttsnSessionHandle session);
167
173typedef void (*CC_MqttsnSessionBrokerReconnectReqCb)(void* userData, CC_MqttsnSessionHandle session);
174
182typedef void (*CC_MqttsnSessionClientConnectReportCb)(void* userData, CC_MqttsnSessionHandle session, const char* clientId);
183
193 void* userData,
195 const char* clientId,
196 const char** username,
197 const unsigned char** password,
198 unsigned* passwordLen);
199
204typedef void (*CC_MqttsnSessionErrorReportCb)(void* userData, CC_MqttsnSessionHandle session, const char* msg);
205
215typedef bool (*CC_MqttsnSessionFwdEncSessionCreatedCb)(void* userData, CC_MqttsnSessionHandle session);
216
221typedef void (*CC_MqttsnSessionFwdEncSessionDeletedCb)(void* userData, CC_MqttsnSessionHandle session);
222
230
234
245 void* data);
246
258 void* data);
259
271 void* data);
272
284 void* data);
285
297 void* data);
298
310 void* data);
311
324 void* data);
325
338 void* data);
339
349 void* data);
350
361 void* data);
362
372 void* data);
373
379
383
393
397
407
411
423 unsigned long long value);
424
428
434
438
452
456
464
468
474
487 const unsigned char* buf,
488 unsigned bufLen);
489
502 const unsigned char* buf,
503 unsigned bufLen);
504
513
517
525 const char* topic,
526 unsigned short topicId);
527
535 unsigned short minTopicId,
536 unsigned short maxTopicId);
537
538/*===================== Config Object ======================*/
539
541typedef struct
542{
543 const char* clientId;
544 const char* topic;
545 unsigned short topicId;
547
549typedef struct
550{
551 const char* clientId;
552 const char* username;
553 const char* password;
555
562
569
571struct CC_MqttsnConfig;
572
574typedef struct CC_MqttsnConfig* CC_MqttsnConfigHandle;
575
583
587
593
598bool cc_mqttsn_gw_config_read(CC_MqttsnConfigHandle config, const char* filename);
599
605
611
617
623
629
635
642
646
655 unsigned bufLen);
656
660
669 unsigned bufLen);
670
678 unsigned short* min,
679 unsigned short* max);
680
685
690
695
699
703
710
715const char* cc_mqttsn_gw_config_get_value(CC_MqttsnConfigHandle config, const char* key, unsigned idx);
716
717
718#ifdef __cplusplus
719}
720#endif
721
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:158
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:27
struct CC_MqttsnConfig * CC_MqttsnConfigHandle
Handle for session object used in all cc_mqttsn_gw_config_* functions.
Definition gateway_all.h:574
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:123
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:192
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:565
@ CC_MqttsnBrokerConnectionType_ValuesLimit
Limit to available values, must be last.
Definition gateway_all.h:567
@ CC_MqttsnBrokerConnectionType_Tcp
TCP/IP.
Definition gateway_all.h:566
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:150
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:173
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:215
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:182
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:131
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:166
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:558
@ CC_MqttsnClientConnectionType_ValuesLimit
Limit to available values, must be last.
Definition gateway_all.h:560
@ CC_MqttsnClientConnectionType_Udp
UDP/IP.
Definition gateway_all.h:559
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:221
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:48
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:141
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:36
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:204
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:550
const char * clientId
Client ID.
Definition gateway_all.h:551
const char * password
Password string (from the configuration)
Definition gateway_all.h:553
const char * username
Username string.
Definition gateway_all.h:552
Info about single predefined topic.
Definition gateway_all.h:542
unsigned short topicId
Numeric topic ID.
Definition gateway_all.h:545
const char * topic
Topic string.
Definition gateway_all.h:544
const char * clientId
Client ID.
Definition gateway_all.h:543
Contains version information of the library.