forked from openthread/openthread
-
Notifications
You must be signed in to change notification settings - Fork 5
/
mqttsn.h
768 lines (709 loc) · 26.3 KB
/
mqttsn.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
/*
* Copyright (c) 2018, Vit Holasek
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef OPENTHREAD_MQTTSN_H_
#define OPENTHREAD_MQTTSN_H_
#include <openthread/instance.h>
#include <openthread/ip6.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @addtogroup api-mqttsn
*
* @brief
* This module provides API for MQTT-SN client library. Client provides functionality
* for MQTT-SN connection established and full messaging capabilities over UDP.
*
* @{
*
*/
enum
{
/**
* Maximum number of active gateways to be maintained. Static buffer is allocated
* for the gateway information.
*
*/
kMaxGatewayInfoCount = 5
};
/**
* MQTT-SN message return code.
*
*/
typedef enum
{
kCodeAccepted = 0,
kCodeRejectedCongestion = 1,
kCodeRejectedTopicId = 2,
kCodeRejectedNotSupported = 3,
/**
* Pending message timed out. this value is not returned by gateway.
*/
kCodeTimeout = -1,
} otMqttsnReturnCode;
/**
* MQTT-SN quality of service level.
*
*/
typedef enum
{
kQos0 = 0x0,
kQos1 = 0x1,
kQos2 = 0x2,
kQosm1 = 0x3
} otMqttsnQos;
/**
* Client lifecycle states.
*
*/
typedef enum
{
/**
* Client is not connected to gateway.
*/
kStateDisconnected,
/**
* Client is connected to gateway and currently alive.
*/
kStateActive,
/**
* Client is in sleeping state.
*/
kStateAsleep,
/**
* Client is awaken from sleep.
*/
kStateAwake,
/**
* Client connection is lost due to communication error.
*/
kStateLost,
} otMqttsnClientState;
/**
* MQTT-SN topic identificator type.
*/
typedef enum
{
/**
* Two character short topic name.
*
*/
kShortTopicName,
/**
* Long topic name.
*
*/
kTopicName,
/**
* Registered topic ID.
*
*/
kTopicId,
/**
* Predefined topic ID.
*
*/
kPredefinedTopicId
} otMqttsnTopicIdType;
/**
* Numeric topic ID.
*
*/
typedef uint16_t otMqttsnTopicId;
/**
* Topic ID structure.
*
* @note This structure aggregates all possible topic id types.
*
*/
typedef struct otMqttsnTopic
{
otMqttsnTopicIdType mType;
union
{
const char *mTopicName;
char mShortTopicName[3];
otMqttsnTopicId mTopicId;
} mData;
} otMqttsnTopic;
/**
* Disconnected state reason.
*
*/
typedef enum
{
/**
* Client was disconnected by gateway/broker.
*/
kDisconnectServer,
/**
* Disconnection was invoked by client.
*/
kDisconnectClient,
/**
* Client changed state to asleep
*/
kDisconnectAsleep,
/**
* Communication timeout.
*/
kDisconnectTimeout
} otMqttsnDisconnectType;
/**
* This structure contains MQTT-SN connection parameters.
*
*/
typedef struct otMqttsnConfig {
/**
* Gateway IPv6 address.
*/
otIp6Address *mAddress;
/**
* Gateway interface port number.
*/
uint16_t mPort;
/**
* Client id string.
*/
char *mClientId;
/**
* Keepalive period in seconds.
*/
uint16_t mKeepAlive;
/**
* Clean session flag.
*/
bool mCleanSession;
/**
* Retransmission timeout in seconds.
*/
uint32_t mRetransmissionTimeout;
/**
* Retransmission count.
*/
uint8_t mRetransmissionCount;
} otMqttsnConfig;
/**
* MQTT-SN gateway ID.
*
*/
typedef uint8_t otMqttsnGatewayId;
/**
* This structure contains information about advertised MQTT-SN gateway.
*/
typedef struct otMqttsnGatewayInfo {
/**
* ID of the gateway.
*/
otMqttsnGatewayId mGatewayId;
/**
* IPv6 address of the gateway.
*/
otIp6Address mGatewayAddress;
} otMqttsnGatewayInfo;
/**
* Declaration of function for connection callback.
*
* @param[in] aCode CONNACK return code value or -1 when connection establishment timed out.
* @param[in] aContext A pointer to connection callback context object.
*
*/
typedef void (*otMqttsnConnectedHandler)(otMqttsnReturnCode aCode, void *aContext);
/**
* Declaration of function for subscribe callback.
*
* @param[in] aCode SUBACK return code or -1 when subscription timed out.
* @param[in] aTopic Subscribed topic. The value is NULL when timed out or short topic name was subscribed.
* @param[in] aQos Subscribed quality of service level.
* @param[in] aContext A pointer to subscription callback context object.
*
*/
typedef void (*otMqttsnSubscribedHandler)(otMqttsnReturnCode aCode, const otMqttsnTopic* aTopic, otMqttsnQos aQos, void* aContext);
/**
* Declaration of function for register callback.
*
* @param[in] aCode REGACK return code or -1 when subscription timed out.
* @param[in] aTopic Registered topic. Only topic ID type can be registered.
* @param[in] aContext A pointer to register callback context object.
*
*/
typedef void (*otMqttsnRegisteredHandler)(otMqttsnReturnCode aCode, const otMqttsnTopic* aTopic, void* aContext);
/**
* Declaration of function for publish callback. It is invoked only when quality of service level is 1 or 2.
*
* @param[in] aCode Publish response code or -1 when publish timed out.
* @param[in] aTopicId Topic ID of published message. It is set to 0 when timed out or short topic name is used.
* @param[in] aContext A pointer to publish callback context object.
*
*/
typedef void (*otMqttsnPublishedHandler)(otMqttsnReturnCode aCode, void* aContext);
/**
* Declaration of function for unsubscribe callback.
*
* @param[in] aCode UNSUBACK response code or -1 when publish timed out.
* @param[in] aContext A pointer to unsubscribe callback context object.
*
*/
typedef void (*otMqttsnUnsubscribedHandler)(otMqttsnReturnCode aCode, void* aContext);
/**
* Declaration of function for callback invoked when publish message received.
*
* @param[in] aPayload A pointer to PUBLISH message payload byte array.
* @param[in] aPayloadLength PUBLISH message payload length.
* @param[in] aTopic Published topic. Can be only short topic name, topic ID and predefined topic ID.
* @param[in] aContext A pointer to publish received callback context object.
*
* @returns Code to be send in response PUBACK message. Timeout value is not relevant.
*/
typedef otMqttsnReturnCode (*otMqttsnPublishReceivedHandler)(const uint8_t* aPayload, int32_t aPayloadLength, const otMqttsnTopic* aTopic, void* aContext);
/**
* Declaration of function for disconnection callback.
*
* @param[in] aType Disconnection reason.
* @param[in] aContext A pointer to disconnection callback context object.
*
*/
typedef void (*otMqttsnDisconnectedHandler)(otMqttsnDisconnectType aType, void* aContext);
/**
* Declaration of function for search gateway callback.
*
* @param[in] aAddress A pointer to IPv6 address of discovered gateway.
* @param[in] aAddress Discovered gateway ID.
* @param[in] aContext A pointer to search gateway context object.
*
*/
typedef void (*otMqttsnSearchgwHandler)(const otIp6Address* aAddress, uint8_t aGatewayId, void* aContext);
/**
* Declaration of function for advertise callback.
*
* @param[in] aAddress A pointer to advertised gateway IPv6 address.
* @param[in] aGatewayId Advertised gateway ID.
* @param[in] aDuration Advertise message duration parameter.
* @param[in] aContext A pointer to advertise callback context object.
*
*/
typedef void (*otMqttsnAdvertiseHandler)(const otIp6Address* aAddress, uint8_t aGatewayId, uint32_t aDuration, void* aContext);
/**
* Declaration of function for callback invoked when register message received.
*
* @param[in] aTopicId Registered topic ID.
* @param[in] aTopicName Long topic name string mapped to registered topic.
* @param[in] aContext A pointer to register received callback context object.
*
* @returns Code to be send in response REGACK message. Timeout value is not relevant.
*
*/
typedef otMqttsnReturnCode (*otMqttsnRegisterReceivedHandler)(otMqttsnTopicId aTopicId, const char *aTopicName, void* aContext);
/**
* Create and initialize topic structure with topic name string. If is of length 1 or 2 then short topic name is sent.
*
* @note It can be used only for MQTT-SN subscribe or unsubscribe.
*
* @param[in] aTopicName A pointer full topic name string.
*
* @return Topic of type kTopicName initialized with topic name string.
*
*/
otMqttsnTopic otMqttsnCreateTopicName(const char *aTopicName);
/**
* Create and initialize topic structure with numeric topic ID.
*
* @note It should be used only for MQTT-SN publish.
*
* @param[in] aTopicId Numeric topic ID. Must not be 0.
*
* @return Topic of type kTopicId initialized with numeric topic ID.
*
*/
otMqttsnTopic otMqttsnCreateTopicId(otMqttsnTopicId aTopicId);
/**
* Create and initialize topic structure with predefined topic ID.
*
* @note It can be used only for MQTT-SN subscribe, unsubscribe and publish.
*
* @param[in] aTopicId Numeric topic ID. Must not be 0.
*
* @return Topic of type kTopicId initialized with numeric topic ID.
*
*/
otMqttsnTopic otMqttsnCreatePredefinedTopicId(otMqttsnTopicId aTopicId);
/**
* Get MQTT-SN topic name from topic structure. Topic must be of type kTopicName or kShortTopicName.
*
* @param[in] aTopic A pointer to topic.
*
* @return A pointer to full or short topic name string.
*
*/
const char *otMqttsnGetTopicName(const otMqttsnTopic *aTopic);
/**
* Get MQTT-SN numeric topic ID from topic structure. Topic must be of type kTopicId.
*
* @param[in] aTopic A pointer to topic.
*
* @return Numeric MQTT-SN topic ID.
*
*/
otMqttsnTopicId otMqttsnGetTopicId(const otMqttsnTopic *aTopic);
/**
* Start MQTT-SN service and start connection and listening.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aPort MQTT-SN client listening port.
*
* @retval OT_ERROR_NONE Successfully started the service.
* @retval OT_ERROR_INVALID_STATE MQTT-SN client is already running.
*
*/
otError otMqttsnStart(otInstance *aInstance, uint16_t aPort);
/**
* Stop MQTT-SN service.
*
* @param[in] aInstance A pointer to an OpenThread instance.
*
* @retval OT_ERROR_NONE Successfully stopped the service.
*
*/
otError otMqttsnStop(otInstance *aInstance);
/**
* Get current MQTT-SN client state.
*
* @param[in] aInstance A pointer to an OpenThread instance.
*
* @return Returns current MQTT-SN client state.
*
*/
otMqttsnClientState otMqttsnGetState(otInstance *aInstance);
/**
* Establish MQTT-SN connection with gateway.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aConfig A pointer to configuration object with connection parameters.
*
* @retval OT_ERROR_NONE Connection message successfully queued.
* @retval OT_ERROR_INVALID_ARGS Invalid connection parameters.
* @retval OT_ERROR_INVALID_STATE Previous connection is still pending.
* @retval OT_ERROR_NO_BUFS Insufficient available buffers to process.
*
*/
otError otMqttsnConnect(otInstance *aInstance, const otMqttsnConfig *aConfig);
/**
* Establish MQTT-SN connection with gateway with default configuration.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] mAddress A pointer to a gateway IPv6 address.
* @param[in] mPort Gateway interface port number.
*
* @retval OT_ERROR_NONE Connection message successfully queued.
* @retval OT_ERROR_INVALID_ARGS Invalid connection parameters.
* @retval OT_ERROR_INVALID_STATE The client is in invalid state. It must be disconnected before new connection establishment.
* @retval OT_ERROR_NO_BUFS Insufficient available buffers to process.
*
*/
otError otMqttsnConnectDefault(otInstance *aInstance, const otIp6Address* aAddress, uint16_t mPort);
/**
* Reconnect MQTT-SN client with current connection settings. This is method is useful
* e.g. for returning from sleep mode to active mode.
*
* @param[in] aInstance A pointer to an OpenThread instance.
*
* @retval OT_ERROR_NONE Connection message successfully queued.
* @retval OT_ERROR_INVALID_STATE The client is in invalid state. It must be disconnected before new connection establishment.
* @retval OT_ERROR_NO_BUFS Insufficient available buffers to process.
*
*/
otError otMqttsnReconnect(otInstance *aInstance);
/**
* Subscribe to the topic.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aTopic A pointer to the topic to be subscribed. Topic name, short topic name and topic ID are supported.
* @param[in] aQos Quality of service level to be subscribed.
* @param[in] aHandler A function pointer to handler which is invoked when subscription is acknowledged.
* @param[in] aContext A pointer to context object passed to handler.
*
* @retval OT_ERROR_NONE Subscription message successfully queued.
* @retval OT_ERROR_INVALID_ARGS Invalid subscription parameters.
* @retval OT_ERROR_INVALID_STATE The client cannot connect in active state.
* @retval OT_ERROR_NO_BUFS Insufficient available buffers to process.
*
*/
otError otMqttsnSubscribe(otInstance *aInstance, const otMqttsnTopic* aTopic, otMqttsnQos aQos, otMqttsnSubscribedHandler aHandler, void *aContext);
/**
* Register to topic with long topic name and obtain related topic ID.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aTopicName A pointer to long topic name string.
* @param[in] aHandler A function pointer to callback invoked when registration is acknowledged.
* @param[in] aContext A pointer to context object passed to callback.
*
* @retval OT_ERROR_NONE Registration message successfully queued.
* @retval OT_ERROR_INVALID_STATE The client is not in active state.
* @retval OT_ERROR_NO_BUFS Insufficient available buffers to process.
*
*/
otError otMqttsnRegister(otInstance *aInstance, const char* aTopicName, otMqttsnRegisteredHandler aHandler, void* aContext);
/**
* Publish message to the topic.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aData A pointer to byte array to be send as message payload.
* @param[in] aLength Length of message payload data.
* @param[in] aQos Message quality of service level.
* @param[in] aRetained Set retained flag of MQTT-SN publish message.
* @param[in] aTopic A pointer to the topic to publish to. Only short topic name, topic ID and predefined topic ID are allowed.
* @param[in] aHandler A function pointer to callback invoked when publish is acknowledged.
* @param[in] aContext A pointer to context object passed to callback.
*
* @retval OT_ERROR_NONE Publish message successfully queued.
* @retval OT_ERROR_INVALID_ARGS Invalid publish parameters. Short topic name must have one or two characters.
* @retval OT_ERROR_INVALID_STATE The client is not in active state.
* @retval OT_ERROR_NO_BUFS Insufficient available buffers to process.
*
*/
otError otMqttsnPublish(otInstance *aInstance, const uint8_t* aData, int32_t aLength, otMqttsnQos aQos, bool aRetained, const otMqttsnTopic* aTopic, otMqttsnPublishedHandler aHandler, void* aContext);
/**
* Publish message to the topic with QoS level -1. No connection or subscription is required.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aData A pointer to byte array to be send as message payload.
* @param[in] aLength Length of message payload data.
* @param[in] aRetained Set retained flag of MQTT-SN publish message.
* @param[in] aTopic A pointer to the topic to publish to. Only short topic name and predefined topic ID are allowed.
* @param[in] aAddress Gateway address.
* @param[in] aPort Gateway port.
*
* @retval OT_ERROR_NONE Publish message successfully queued.
* @retval OT_ERROR_NO_BUFS Insufficient available buffers to process.
*
*/
otError otMqttsnPublishQosm1(otInstance *aInstance, const uint8_t* aData, int32_t aLength, bool aRetained, const otMqttsnTopic *aTopic, const otIp6Address* aAddress, uint16_t aPort);
/**
* Unsubscribe from the topic by topic name string.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aTopic A pointer to the topic to be unsubscribed. Long topic name, short topic name and topic ID are supported.
* @param[in] aHandler A function pointer to callback invoked when unsubscription is acknowledged.
* @param[in] aContext A pointer to context object passed to callback.
*
* @retval OT_ERROR_NONE Unsubscribe message successfully queued.
* @retval OT_ERROR_INVALID_STATE The client is not in active state.
* @retval OT_ERROR_NO_BUFS Insufficient available buffers to unsubscribe.
*
*/
otError otMqttsnUnsubscribe(otInstance *aInstance, const otMqttsnTopic* aTopic, otMqttsnUnsubscribedHandler aHandler, void* aContext);
/**
* Disconnect MQTT-SN client from gateway.
*
* @param[in] aInstance A pointer to an OpenThread instance.
*
* @retval OT_ERROR_NONE Disconnection message successfully queued.
* @retval OT_ERROR_INVALID_STATE The client is not in relevant state. It must be asleep, awake or active.
* @retval OT_ERROR_NO_BUFS Insufficient available buffers to process.
*
*/
otError otMqttsnDisconnect(otInstance *aInstance);
/**
* Put the client into asleep state or change sleep duration. Client must be awaken or reconnected before duration time passes.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aDuration Duration time in seconds for which will the client stay in asleep state.
*
* @retval OT_ERROR_NONE Sleep request successfully queued.
* @retval OT_ERROR_INVALID_STATE The client is not in relevant state. It must be asleep, awake or active.
* @retval OT_ERROR_NO_BUFS Insufficient available buffers to process.
*
*/
otError otMqttsnSleep(otInstance *aInstance, uint16_t aDuration);
/**
* Awake the client and receive pending messages.
*
* @note Configuration retransmission count is still applied.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aTimeout Timeout in milliseconds for staying in awake state. PINGRESP message must be received before timeout time passes.
*
* @retval OT_ERROR_NONE Awake request successfully queued.
* @retval OT_ERROR_INVALID_STATE The client is not in relevant state. It must be asleep or awake.
* @retval OT_ERROR_NO_BUFS Insufficient available buffers to process.
*
*/
otError otMqttsnAwake(otInstance *aInstance, uint32_t aTimeout);
/**
* Search for gateway with multicast message.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aMulticastAddress A pointer to multicast IPv6 address.
* @param[in] aPort Gateway port number.
* @param[in] aRadius Message hop limit (time to live)
*
* @retval OT_ERROR_NONE Search gateway request successfully queued.
* @retval OT_ERROR_NO_BUFS Insufficient available buffers to process.
*
*/
otError otMqttsnSearchGateway(otInstance *aInstance, const otIp6Address *aMulticastAddress, uint16_t aPort, uint8_t aRadius);
/**
* Get number of active gateways. Gateways are periodically advertised or obtained
* with gwinfo message.
*
* @param[in] aInstance A pointer to an OpenThread instance.
*
* @returns Number of active gateways cached in MQTT-SN client.
*
*/
uint16_t otMqttsnGetActiveGatewaysCount(otInstance *aInstance);
/**
* Get informations about active gateways. Gateways are periodically advertised or obtained
* with gwinfo message.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aBuffer A pointer to statically allocated buffer for storing gateway informations.
* @param[in] aBufferSize Maximal number of items which can be stored in the buffer.
*
* @returns Number of active gateways written in the buffer.
*
*/
uint16_t otMqttsnGetActiveGateways(otInstance *aInstance, otMqttsnGatewayInfo *aBuffer, uint16_t aBufferSize);
/**
* Set handler which is invoked when connection is acknowledged.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aHandler A function pointer to handler which is invoked when connection is acknowledged.
* @param[in] aContext A pointer to context object passed to handler.
*
* @retval OT_ERROR_NONE Handler correctly set.
*
*/
otError otMqttsnSetConnectedHandler(otInstance *aInstance, otMqttsnConnectedHandler aHandler, void *aContext);
/**
* Set callback function invoked when publish message received from the topic.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aHandler A function pointer to publish received callback function.
* @param[in] aContext A pointer to context object passed to callback.
*
* @retval OT_ERROR_NONE Callback function successfully set.
*
*/
otError otMqttsnSetPublishReceivedHandler(otInstance *aInstance, otMqttsnPublishReceivedHandler aHandler, void* aContext);
/**
* Set callback function invoked when disconnect acknowledged or timed out.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aHandler A function pointer to disconnect callback function.
* @param[in] aContext A pointer to context object passed to callback.
*
* @retval OT_ERROR_NONE Callback function successfully set.
*
*/
otError otMqttsnSetDisconnectedHandler(otInstance *aInstance, otMqttsnDisconnectedHandler aHandler, void* aContext);
/**
* Set callback function invoked when gateway info received from gateway.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aHandler A function pointer to gateway info received callback function.
* @param[in] aContext A pointer to context object passed to callback.
*
* @retval OT_ERROR_NONE Callback function successfully set.
*
*/
otError otMqttsnSetSearchgwHandler(otInstance *aInstance, otMqttsnSearchgwHandler aHandler, void* aContext);
/**
* Set callback function invoked when advertise message received from the gateway.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aHandler A function pointer to advertise callback function.
* @param[in] aContext A pointer to context object passed to callback.
*
* @retval OT_ERROR_NONE Callback function successfully set.
*
*/
otError otMqttsnSetAdvertiseHandler(otInstance *aInstance, otMqttsnAdvertiseHandler aHandler, void* aContext);
/**
* Set callback function invoked when register message received.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aHandler A function pointer to register callback function.
* @param[in] aContext A pointer to context object passed to callback.
*
* @retval OT_ERROR_NONE Callback function successfully set.
*
*/
otError otMqttsnSetRegisterReceivedHandler(otInstance *aInstance, otMqttsnRegisterReceivedHandler aHandler, void* aContext);
/**
* Get string value of given return code.
*
* @param[in] aCode MQTT-SN message return code.
* @param[out] aCodeString A pointer to string pointer which will contain return code string value.
*
* @retval OT_ERROR_NONE String value was obtained.
* @retval OT_ERROR_INVALID_ARGS Invalid return code value.
*
*/
otError otMqttsnReturnCodeToString(otMqttsnReturnCode aCode, const char** aCodeString);
/**
* Get MQTT-SN quality of service level from string value. Only values '0', '1', '2' and '-1' are allowed.
*
* @param[in] aQosString A pointer to string with MQTT-SN QoS level value
* @param[out] aQos A pointer to MQTT-SN QoS level which will be set.
*
* @retval OT_ERROR_NONE MQTT-SN QoS level was obtained..
* @retval OT_ERROR_INVALID_ARGS Invalid QoS string value.
*
*/
otError otMqttsnStringToQos(const char* aQosString, otMqttsnQos *aQos);
/**
* Get string value of given MQTT-SN client state.
*
* @param[in] aClientState MQTT-SN client state.
* @param[out] aClientStateString A pointer to string pointer which will contain client state string value.
*
* @retval OT_ERROR_NONE String value was obtained.
* @retval OT_ERROR_INVALID_ARGS Invalid client state value.
*
*/
otError otMqttsnClientStateToString(otMqttsnClientState aClientState, const char** aClientStateString);
/**
* Get string value of given MQTT-SN disconnect type.
*
* @param[in] aDisconnectType MQTT-SN disconnect type.
* @param[out] aDisconnectTypeString A pointer to string pointer which will contain disconnect type string value.
*
* @retval OT_ERROR_NONE String value was obtained.
* @retval OT_ERROR_INVALID_ARGS Invalid disconnect type value.
*
*/
otError otMqttsnDisconnectTypeToString(otMqttsnDisconnectType aDisconnectType, const char** aDisconnectTypeString);
/**
* @}
*
*/
#ifdef __cplusplus
} // extern "C"
#endif
#endif /* OPENTHREAD_MQTTSN_H_ */