Annotation of libaitmqtt/inc/aitmqtt.h, revision 1.3.4.4
1.1 misho 1: /*************************************************************************
2: * (C) 2011 AITNET ltd - Sofia/Bulgaria - <misho@aitbg.com>
3: * by Michael Pounov <misho@openbsd-bg.org>
4: *
5: * $Author: misho $
1.3.4.4 ! misho 6: * $Id: aitmqtt.h,v 1.3.4.3 2022/09/12 22:09:29 misho Exp $
1.1 misho 7: *
8: **************************************************************************
9: The ELWIX and AITNET software is distributed under the following
10: terms:
11:
12: All of the documentation and software included in the ELWIX and AITNET
13: Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
14:
1.3.4.2 misho 15: Copyright 2004 - 2022
1.1 misho 16: by Michael Pounov <misho@elwix.org>. All rights reserved.
17:
18: Redistribution and use in source and binary forms, with or without
19: modification, are permitted provided that the following conditions
20: are met:
21: 1. Redistributions of source code must retain the above copyright
22: notice, this list of conditions and the following disclaimer.
23: 2. Redistributions in binary form must reproduce the above copyright
24: notice, this list of conditions and the following disclaimer in the
25: documentation and/or other materials provided with the distribution.
26: 3. All advertising materials mentioning features or use of this software
27: must display the following acknowledgement:
28: This product includes software developed by Michael Pounov <misho@elwix.org>
29: ELWIX - Embedded LightWeight unIX and its contributors.
30: 4. Neither the name of AITNET nor the names of its contributors
31: may be used to endorse or promote products derived from this software
32: without specific prior written permission.
33:
34: THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND
35: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37: ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
38: FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39: DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
40: OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42: LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
43: OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44: SUCH DAMAGE.
45: */
46: #ifndef __AITMQTT_H
47: #define __AITMQTT_H
48:
49:
1.2 misho 50: #define MAX_CONNID 24
51: #define MAX_CRED 13
1.3.4.2 misho 52: #define MQTTMSG_MAX 65535
1.3.4.3 misho 53: #define MQTTMSG_BIN_MAX 65535
1.2 misho 54: #define MQTT_DATA_MAX 268435455
55:
56: #define MQTT_PROTO_VER 3
57: #define MQTT_KEEPALIVE 10
58: #define MQTT_DEFAULT_MSGID 0xDEBA
59:
1.1 misho 60: /* FIXED HEADER */
61:
62: struct mqtthdr {
63: union {
64: struct {
65: unsigned char retain:1,
66: qos:2,
67: dup:1,
68: type:4;
69: };
70: unsigned char val;
71: } mqtt_msg;
72: unsigned char mqtt_len[1]; /* may be grow to 4 bytes */
1.3.4.1 misho 73: } __attribute__((packed));
1.3.4.3 misho 74: #define MQTTHDR_MSGINIT(x) (assert((x)), (x)->mqtt_msg.val ^= (x)->mqtt_msg.val, *mqtt_len = 0)
1.2 misho 75: #define MQTTHDR_DATA_SIZEOF(x) (assert((x)), mqtt_decodeLen((x)->mqtt_len, NULL))
1.1 misho 76:
77: #define MQTT_TYPE_UNKNOWN 0 /* reserved */
1.3.4.3 misho 78: #define MQTT_TYPE_CONNECT 1 /* client request to connect to server (CLI) */
1.3.4.4 ! misho 79: #define MQTT_TYPE_CONNACK 2 /* connect acknowledgment (SRV) [ret_no_data] */
! 80: #define MQTT_TYPE_PUBLISH 3 /* publish message [ret_is_optional] */
! 81: #define MQTT_TYPE_PUBACK 4 /* publish acknowledgment [ret_no_data] */
! 82: #define MQTT_TYPE_PUBREC 5 /* publish received (assured delivery part 1) [ret_no_data] */
! 83: #define MQTT_TYPE_PUBREL 6 /* publish release (assured delivery part 2) [ret_no_data] */
! 84: #define MQTT_TYPE_PUBCOMP 7 /* publish complete (assured delivery part 3) [ret_no_data] */
1.3.4.3 misho 85: #define MQTT_TYPE_SUBSCRIBE 8 /* client subscribe request (CLI) */
86: #define MQTT_TYPE_SUBACK 9 /* subscribe acknowledgment (SRV) */
87: #define MQTT_TYPE_UNSUBSCRIBE 10 /* client unsubscribe request (CLI) */
88: #define MQTT_TYPE_UNSUBACK 11 /* unsubscribe acknowledgment (SRV) */
1.3.4.4 ! misho 89: #define MQTT_TYPE_PINGREQ 12 /* PING request (CLI) [ret_no_data] */
! 90: #define MQTT_TYPE_PINGRESP 13 /* PING response (SRV) [ret_no_data] */
! 91: #define MQTT_TYPE_DISCONNECT 14 /* client is disconnecting [ret_no_data] */
! 92: #define MQTT_TYPE_AUTH 15 /* authentication exchange [ret_no_data] */
1.3.4.3 misho 93:
94: #define MQTT_TYPE_MAX 15
1.1 misho 95:
96: #define MQTT_FLAG_DUP 1 /* This flag is set when the client or server attempts to re-deliver
97: a PUBLISH, PUBREL, SUBSCRIBE or UNSUBSCRIBE message.
98: This applies to messages where the value of QoS is greater than
99: zero (0), and an acknowledgment is required.
100: When the DUP bit is set, the variable header includes a Message ID.
101:
102: The recipient should treat this flag as a hint as to whether
103: the message may have been previously received.
104: It should not be relied on to detect duplicates. */
105:
106: #define MQTT_QOS_ONCE 0 /* At most once, Fire and Forget, <=1 */
107: #define MQTT_QOS_ACK 1 /* At least once, Acknowledged delivery, >=1 */
108: #define MQTT_QOS_EXACTLY 2 /* Exactly once, Assured delivery, =1 */
109: #define MQTT_QOS_RESERVED 3 /* reserved */
110:
1.2 misho 111: #define MQTT_QOS_DENY 0 /* Not granted QoS for SUBACK */
112: #define MQTT_QOS_PASS 2 /* Granted QoS for SUBACK */
113:
1.1 misho 114: #define MQTT_FLAG_RETAIN 1 /* This flag is only used on PUBLISH messages.
115:
116: When a client sends a PUBLISH to a server,
117: if the Retain flag is set (1),
118: the server should hold on to the message after it has been
119: delivered to the current subscribers.
120: When a new subscription is established on a topic,
121: the last retained message on that topic should be sent to
122: the subscriber with the Retain flag set.
123: If there is no retained message, nothing is sent
124: This is useful where publishers send messages on a
125: "report by exception" basis, where it might be some time between messages.
126: This allows new subscribers to instantly receive data with the retained,
127: or Last Known Good, value.
128:
129: When a server sends a PUBLISH to a client as a result of
130: a subscription that already existed when the original PUBLISH arrived,
131: the Retain flag should not be set, regardless of the Retain flag
132: of the original PUBLISH. This allows a client to distinguish messages
133: that are being received because they were retained and those
134: that are being received "live".
135:
136: Retained messages should be kept over restarts of the server.
137: A server may delete a retained message if it receives a message
138: with a zero-length payload and the Retain flag set on the same topic. */
139:
140: /* VARIABLE HEADERS */
141:
142: #define MQTT_RETCODE_ACCEPTED 0
143: #define MQTT_RETCODE_REFUSE_VER 1
144: #define MQTT_RETCODE_REFUSE_ID 2
145: #define MQTT_RETCODE_REFUSE_UNAVAIL 3
146: #define MQTT_RETCODE_REFUSE_USERPASS 4
147: #define MQTT_RETCODE_DENIED 5
148:
1.3.4.4 ! misho 149: /* REASON CODES */
! 150:
! 151: #define MQTT_REASON_OK 0x0 /* CONNACK, PUBACK, PUBREC, PUBREL, PUBCOMP, UNSUBACK, AUTH, DISCONNECT, SUBACK */
! 152: #define MQTT_REASON_QOS1 0x1 /* SUBACK */
! 153: #define MQTT_REASON_QOS2 0x2 /* SUBACK */
! 154: #define MQTT_REASON_DWILL 0x4 /* DISCONNECT */
! 155: #define MQTT_REASON_NOMATCH 0x10 /* PUBACK, PUBREC */
! 156: #define MQTT_REASON_NOSUBEXIST 0x11 /* UNSUBACK */
! 157: #define MQTT_REASON_CONTAUTH 0x18 /* AUTH */
! 158: #define MQTT_REASON_REAUTH 0x19 /* AUTH */
! 159:
! 160: /* REASON ERROR CODES */
! 161:
! 162: #define MQTT_REASON_ERROR 0x80 /* CONNACK, PUBACK, PUBREC, SUBACK, UNSUBACK, DISCONNECT */
! 163: #define MQTT_REASON_MALFORMPKT 0x81 /* CONNACK, DISCONNECT */
! 164: #define MQTT_REASON_PROTOERR 0x82 /* CONNACK, DISCONNECT */
! 165: #define MQTT_REASON_IMPLSPECERR 0x83 /* CONNACK, PUBACK, PUBREC, SUBACK, UNSUBACK, DISCONNECT */
! 166: #define MQTT_REASON_UNSUPVERPROTO 0x84 /* CONNACK */
! 167: #define MQTT_REASON_CLINOVALID 0x85 /* CONNACK */
! 168: #define MQTT_REASON_BADUSERPASS 0x86 /* CONNACK */
! 169: #define MQTT_REASON_NOAUTH 0x87 /* CONNACK, PUBACK, PUBREC, SUBACK, UNSUBACK, DISCONNECT */
! 170: #define MQTT_REASON_SRVUNAVAIL 0x88 /* CONNACK */
! 171: #define MQTT_REASON_SRVBUSY 0x89 /* CONNACK, DISCONNECT */
! 172: #define MQTT_REASON_BANNED 0x8A /* CONNACK */
! 173: #define MQTT_REASON_SRVSHUTDOWN 0x8B /* DISCONNECT */
! 174: #define MQTT_REASON_BADAUTHMETHOD 0x8C /* CONNACK, DISCONNECT */
! 175: #define MQTT_REASON_KEEPALIVETO 0x8D /* DISCONNECT */
! 176: #define MQTT_REASON_SESTAKEOVER 0x8E /* DISCONNECT */
! 177: #define MQTT_REASON_TOPICFLTINVAL 0x8F /* SUBACK, UNSUBACK, DISCONNECT */
! 178: #define MQTT_REASON_TOPICNAMEINV 0x90 /* CONNACK, PUBACK, PUBREC, DISCONNECT */
! 179: #define MQTT_REASON_PKTIDINUSE 0x91 /* PUBACK, PUBREC, SUBACK, UNSUBACK */
! 180: #define MQTT_REASON_PKTIDNOTFOUND 0x92 /* PUBREL, PUBCOMP */
! 181: #define MQTT_REASON_RCVMAXEXCEED 0x93 /* DISCONNECT */
! 182: #define MQTT_REASON_TOPICALIASINV 0x94 /* DISCONNECT */
! 183: #define MQTT_REASON_PKTTOOLARGE 0x95 /* CONNACK, DISCONNECT */
! 184: #define MQTT_REASON_MSGRATETOHIGH 0x96 /* DISCONNECT */
! 185: #define MQTT_REASON_QUOTAEXCEED 0x97 /* CONNACK, PUBACK, PUBREC, SUBACK, DISCONNECT */
! 186: #define MQTT_REASON_ADMINACTION 0x98 /* DISCONNECT */
! 187: #define MQTT_REASON_PAYLOADFMTINV 0x99 /* CONNACK, PUBACK, PUBREC, DISCONNECT */
! 188: #define MQTT_REASON_RETAINNOTSUP 0x9A /* CONNACK, DISCONNECT */
! 189: #define MQTT_REASON_QOSNOTSUP 0x9B /* CONNACK, DISCONNECT */
! 190: #define MQTT_REASON_USENEXTSRV 0x9C /* CONNACK, DISCONNECT */
! 191: #define MQTT_REASON_SRVMOVED 0x9D /* CONNACK, DISCONNECT */
! 192: #define MQTT_REASON_SHARSUBNOTSUP 0x9E /* SUBACK, DISCONNECT */
! 193: #define MQTT_REASON_CONRATEEXCEED 0x9F /* CONNACK, DISCONNECT */
! 194: #define MQTT_REASON_MAXCONNTIME 0xA0 /* DISCONNECT */
! 195: #define MQTT_REASON_SUBIDNOTSUP 0xA1 /* SUBACK, DISCONNECT */
! 196: #define MQTT_RESON_WILDSUBNOTSUP 0xA2 /* SUBACK, DISCONNECT */
1.1 misho 197:
198: /* MQTT Message buffer */
199:
200: typedef struct {
201: void *msg_base;
202: unsigned short msg_len;
203: } mqtt_msg_t;
204:
205: /* MQTT structures */
206:
207: typedef union {
208: struct {
209: unsigned short m:8,
210: l:8;
211: } sb;
212: unsigned short val;
213: } mqtt_len_t;
214:
215: typedef struct {
216: unsigned char sub_ret;
217: mqtt_msg_t sub_topic;
218: mqtt_msg_t sub_value;
219: } mqtt_subscr_t;
220:
221: typedef struct {
222: mqtt_len_t var_sb;
223: unsigned char var_data[0];
1.3.4.1 misho 224: } __attribute__((packed)) mqtthdr_var_t;
1.1 misho 225: #define MQTTHDR_VAR_SIZEOF(x) (assert((x)), sizeof(mqtt_len_t) + ntohs((x)->var_sb.val))
226:
227: typedef unsigned char mqtthdr_protover_t;
228:
229: typedef union {
230: struct {
231: unsigned char reserved:1,
232: clean_sess:1,
233: will_flg:1,
234: will_qos:2,
235: will_retain:1,
236: password:1,
237: username:1;
238: };
239: unsigned char flags;
1.3.4.1 misho 240: } __attribute__((packed)) mqtthdr_connflgs_t;
1.1 misho 241:
242: typedef struct {
243: unsigned char reserved;
244: unsigned char retcode;
1.3.4.1 misho 245: } __attribute__((packed)) mqtthdr_connack_t;
1.1 misho 246:
247:
248: // -------------------------------------------------------
249: // mqtt_GetErrno() Get error code of last operation
1.3 misho 250: int mqtt_GetErrno();
1.1 misho 251: // mqtt_GetError() Get error text of last operation
1.3 misho 252: const char *mqtt_GetError();
1.1 misho 253: // -------------------------------------------------------
254:
255:
256: /*
257: * mqtt_msgAlloc() Allocate memory for MQTT Message
258: *
259: * @len = >0 Allocate buffer with length
260: * return: NULL error or Message, after use must call mqtt_msgFree() with all!=0
261: */
1.3 misho 262: mqtt_msg_t *mqtt_msgAlloc(unsigned short len);
1.1 misho 263: /*
264: * mqtt_msgFree() Free MQTT message
265: *
266: * @msg = Message buffer
267: * @all = !=0 Destroy entire message, if MQTT Message allocated with mqtt_msgAlloc()
268: * return: none
269: */
1.3 misho 270: void mqtt_msgFree(mqtt_msg_t ** __restrict msg, int all);
1.1 misho 271: /*
272: * mqtt_msgRealloc() Reallocate MQTT message buffer
273: *
274: * @msg = MQTT message
275: * @len = new length
276: * return: -1 error or >-1 old buffer length
277: */
1.3 misho 278: int mqtt_msgRealloc(mqtt_msg_t * __restrict msg, unsigned short len);
1.2 misho 279: /*
280: * mqtt_msgDup() - Duplicate message buffer
281: *
282: * @msg = Message
283: * return: NULL error or !=NULL duplicated message, after use must call mqtt_msgFree() with all!=0
284: */
1.3 misho 285: mqtt_msg_t *mqtt_msgDup(mqtt_msg_t * __restrict msg);
1.2 misho 286:
287: /*
288: * mqtt_expandTopic() - Expanding topic to regular expression
289: *
290: * @csInput = Input topic
291: * @psRegEx = Output to regular expression
292: * @regexLen = Length of psRegEx
293: * @BOL = Begin of Line, if =0 not added
294: * @EOL = End of Line, if =0 not appended
295: * return: -1 error, 0 nothing expanded or >0 expanded bytes
296: */
297: int mqtt_expandTopic(const char *csInput, char * __restrict psRegEx, int regexLen,
298: unsigned char BOL, unsigned char EOL);
299: /*
300: * mqtt_sqlTopic() - Expanding topic to SQL search string
301: *
302: * @csInput = Input topic
303: * @psSQL = Output to SQL search string
304: * @sqlLen = Length of psSQL
305: * return: -1 error, 0 changed bytes
306: */
307: int mqtt_sqlTopic(const char *csInput, char * __restrict psSQL, int sqlLen);
1.1 misho 308:
309: /*
310: * mqtt_encodeLen() Encode number to MQTT length field
311: *
312: * @num = number for encode
313: * return: -1 error or >-1 length
314: */
1.3 misho 315: unsigned int mqtt_encodeLen(unsigned int num);
1.1 misho 316: /*
317: * mqtt_decodeLen() Decode length from MQTT packet
318: *
319: * @len = length from MQTT header
320: * @n = sizeof bytes, if !=NULL
321: * return: -1 error, >-1 length of message
322: */
1.3 misho 323: unsigned int mqtt_decodeLen(void * __restrict len, int * __restrict n);
1.1 misho 324: /*
325: * mqtt_sizeLen Return sizeof len field
326: *
327: * @len = length
328: * return: -1 error, >-1 sizeof len in bytes
329: */
1.3 misho 330: char mqtt_sizeLen(unsigned int len);
1.1 misho 331: /*
1.2 misho 332: * mqtt_pktLen() - Get total packet length
1.1 misho 333: *
1.2 misho 334: * @hdr = MQTT packet header
335: * return: packet length
336: */
1.3 misho 337: unsigned int mqtt_pktLen(struct mqtthdr * __restrict hdr);
1.2 misho 338: /*
339: * mqtt_str2subs Create MQTT subscribe variable from string(s)
340: *
341: * @csStr = null terminated string array
342: * @strnum = copy at most number of strings elements
1.1 misho 343: * @qoses = QoS elements applied to subscribe variable,
344: * count of elements must be equal with csStr elements
345: * return: NULL error or != subscribe variables array, must be free after use with mqtt_freeSub()
346: */
1.3 misho 347: mqtt_subscr_t *mqtt_str2subs(const char **csStr, unsigned short strnum,
1.2 misho 348: unsigned char *qoses);
1.1 misho 349: /*
350: * mqtt_subFree() Free array from subscribe variables
351: *
352: * @subs = Subscribe variables
353: * return: none
354: */
1.3 misho 355: void mqtt_subFree(mqtt_subscr_t ** __restrict subs);
1.1 misho 356: /*
357: * mqtt_subAlloc() Create array from subscribe variables
358: *
359: * @num = Number of elements
360: * return: NULL error or subscribe array, after use must call mqtt_subFree()
361: */
1.3 misho 362: mqtt_subscr_t *mqtt_subAlloc(unsigned short num);
1.1 misho 363: /*
364: * mqtt_subRealloc() Reallocate array from subscribe variables
365: *
366: * @subs = Subscribe array
367: * @num = Number of elements
368: * return: NULL error or subscribe array, after use must call mqtt_subFree()
369: */
1.3 misho 370: mqtt_subscr_t *mqtt_subRealloc(mqtt_subscr_t ** __restrict subs, unsigned short num);
1.2 misho 371: /*
372: * mqtt_subCopy() - Copy subscription structure to another one
373: *
374: * @dst = destination subscription
375: * @src = source subscription
376: * return: =NULL error or !=NULL successful copied a structure
377: */
1.3 misho 378: mqtt_subscr_t *mqtt_subCopy(mqtt_subscr_t * __restrict dst, mqtt_subscr_t * __restrict src);
1.1 misho 379:
380:
381: /*** SENDER FUNCTIONS ***/
382:
383: /*
384: * mqtt_msgCONNECT() Create CONNECT message
385: *
386: * @buf = Message buffer
387: * @csConnID = ConnectID
1.2 misho 388: * @kasec = Keep alive timeout, if =0 default timeout for MQTT
1.1 misho 389: * @csUser = Username if !=NULL
390: * @csPass = Password for Username, only if csUser is set
391: * @csWillTopic = Will Topic if !=NULL Will Flags set into message
392: * @csWillMessage = Will Message, may be NULL
393: * @ClrSess = Clear Session subscriptions after disconnect
394: * @WillQOS = Will QOS if csWillTopic is set
395: * @WillRetain = Will Retain Will Message if csWillTopic is set
396: * return: -1 error or >-1 message size for send
397: */
398: int mqtt_msgCONNECT(mqtt_msg_t * __restrict buf, const char *csConnID,
399: unsigned short kasec, const char *csUser, const char *csPass,
400: const char *csWillTopic, const char *csWillMessage,
401: unsigned char ClrSess, unsigned char WillQOS, unsigned char WillRetain);
402: /*
403: * mqtt_msgCONNACK() Create CONNACK message
404: *
405: * @buf = Message buffer
406: * @retcode = Return code
407: * return: -1 error or >-1 message size for send
408: */
409: int mqtt_msgCONNACK(mqtt_msg_t * __restrict buf, unsigned char retcode);
410: /*
411: * mqtt_msgDISCONNECT() Create DISCONNECT message
412: *
413: * @buf = Message buffer
414: * return: -1 error or >-1 message size for send
415: */
416: int mqtt_msgDISCONNECT(mqtt_msg_t * __restrict buf);
417: /*
418: * mqtt_msgPINGREQ() Create PINGREQ message
419: *
420: * @buf = Message buffer
421: * return: -1 error or >-1 message size for send
422: */
423: int mqtt_msgPINGREQ(mqtt_msg_t * __restrict buf);
424: /*
425: * mqtt_msgPINGRESP() Create PINGRESP message
426: *
427: * @buf = Message buffer
428: * return: -1 error or >-1 message size for send
429: */
430: int mqtt_msgPINGRESP(mqtt_msg_t * __restrict buf);
431:
432: /*
433: * mqtt_msgPUBLISH() Create PUBLISH message
434: *
435: * @buf = Message buffer
436: * @csTopic = Publish topic
437: * @msgID = MessageID >0, if QOS != MQTT_QOS_ONCE
438: * @Dup = Duplicate message
439: * @QOS = QoS
440: * @Retain = Retain message
441: * @pData = Publish data into topic
442: * @datlen = Publish data length
443: * return: -1 error or >-1 message size for send
444: */
445: int mqtt_msgPUBLISH(mqtt_msg_t * __restrict buf, const char *csTopic,
446: unsigned short msgID, unsigned char Dup, unsigned char QOS,
447: unsigned char Retain, const void *pData, int datlen);
448: /*
449: * mqtt_msgPUBACK() Create PUBACK message
450: *
451: * @buf = Message buffer
452: * @msgID = MessageID
453: * return: -1 error or >-1 message size for send
454: */
1.3 misho 455: int mqtt_msgPUBACK(mqtt_msg_t * __restrict buf, unsigned short msgID);
1.1 misho 456: /*
457: * mqtt_msgPUBREC() Create PUBREC message
458: *
459: * @buf = Message buffer
460: * @msgID = MessageID
461: * return: -1 error or >-1 message size for send
462: */
1.3 misho 463: int mqtt_msgPUBREC(mqtt_msg_t * __restrict buf, unsigned short msgID);
1.1 misho 464: /*
465: * mqtt_msgPUBREL() Create PUBREL message
466: *
467: * @buf = Message buffer
468: * @msgID = MessageID
469: * return: -1 error or >-1 message size for send
470: */
1.3 misho 471: int mqtt_msgPUBREL(mqtt_msg_t * __restrict buf, unsigned short msgID);
1.1 misho 472: /*
473: * mqtt_msgPUBCOMP() Create PUBCOMP message
474: *
475: * @buf = Message buffer
476: * @msgID = MessageID
477: * return: -1 error or >-1 message size for send
478: */
1.3 misho 479: int mqtt_msgPUBCOMP(mqtt_msg_t * __restrict buf, unsigned short msgID);
1.1 misho 480:
481: /*
482: * mqtt_msgSUBSCRIBE() Create SUBSCRIBE message
483: *
484: * @buf = Message buffer
485: * @Topics = MQTT subscription topics
486: * @msgID = MessageID
487: * @Dup = Duplicate message
488: * @QOS = QoS
489: * return: -1 error or >-1 message size for send
490: */
491: int
492: mqtt_msgSUBSCRIBE(mqtt_msg_t * __restrict buf, mqtt_subscr_t * __restrict Topics,
493: unsigned short msgID, unsigned char Dup, unsigned char QOS);
494: /*
495: * mqtt_msgSUBACK() Create SUBACK message
496: *
497: * @buf = Message buffer
498: * @Topics = MQTT subscription topics
499: * @msgID = MessageID
500: * return: -1 error or >-1 message size for send
501: */
502: int mqtt_msgSUBACK(mqtt_msg_t * __restrict buf, mqtt_subscr_t * __restrict Topics,
503: unsigned short msgID);
504: /*
505: * mqtt_msgUNSUBSCRIBE() Create UNSUBSCRIBE message
506: *
507: * @buf = Message buffer
508: * @Topics = MQTT subscription topics
509: * @msgID = MessageID
510: * @Dup = Duplicate message
511: * @QOS = QoS
512: * return: -1 error or >-1 message size for send
513: */
514: int
515: mqtt_msgUNSUBSCRIBE(mqtt_msg_t * __restrict buf, mqtt_subscr_t * __restrict Topics,
516: unsigned short msgID, unsigned char Dup, unsigned char QOS);
517: /*
518: * mqtt_msgUNSUBACK() Create UNSUBACK message
519: *
520: * @buf = Message buffer
521: * @msgID = MessageID
522: * return: -1 error or >-1 message size for send
523: */
524: int mqtt_msgUNSUBACK(mqtt_msg_t * __restrict buf, unsigned short msgID);
525:
526:
527: /*** RECEIVER FUNCTIONS ***/
528:
529: /*
530: * mqtt_readCONNECT() Read elements from CONNECT message
531: *
532: * @buf = Message buffer
533: * @kasec = Keep Alive in seconds for current connection
534: * @psConnID = ConnectID
535: * @connLen = ConnectID length
536: * @psUser = Username if !=NULL
537: * @userLen = Username length
538: * @psPass = Password for Username, only if csUser is set
539: * @passLen = Password length
540: * @psWillTopic = Will Topic if !=NULL Will Flags set into message and must be free()
541: * @psWillMessage = Will Message, may be NULL if !NULL must be free() after use!
542: * return: .reserved == 1 is error or == 0 connection flags & msg ok
543: */
544: mqtthdr_connack_t mqtt_readCONNECT(mqtt_msg_t * __restrict buf, unsigned short *kasec,
545: char * __restrict psConnID, int connLen,
546: char * __restrict psUser, int userLen, char * __restrict psPass, int passLen,
547: char ** __restrict psWillTopic, char ** __restrict psWillMessage);
548: /*
549: * mqtt_readCONNACK() Read CONNACK message
550: *
551: * @buf = Message buffer
552: * return: -1 error or >-1 CONNECT message return code
553: */
554: unsigned char mqtt_readCONNACK(mqtt_msg_t * __restrict buf);
555: /*
556: * mqtt_readDISCONNECT() Read DISCONNECT message
557: *
558: * @buf = Message buffer
559: * return: -1 error, 0 ok, >0 undefined result
560: */
561: int mqtt_readDISCONNECT(mqtt_msg_t * __restrict buf);
562: /*
563: * mqtt_readPINGREQ() Read PINGREQ message
564: *
565: * @buf = Message buffer
566: * return: -1 error, 0 ok, >0 undefined result
567: */
568: int mqtt_readPINGREQ(mqtt_msg_t * __restrict buf);
569: /*
570: * mqtt_readPINGRESP() Read PINGRESP message
571: *
572: * @buf = Message buffer
573: * return: -1 error, 0 ok, >0 undefined result
574: */
575: int mqtt_readPINGRESP(mqtt_msg_t * __restrict buf);
576:
577: /*
578: * mqtt_readPUBLISH() Read PUBLISH message
579: *
580: * @buf = Message buffer
581: * @psTopic = Topic
582: * @topicLen = Topic length
583: * @msgID = MessageID
1.2 misho 584: * @pData = Data buffer, may be NULL
585: * return: -1 error or !=-1 allocated data buffer length
1.1 misho 586: */
1.2 misho 587: int mqtt_readPUBLISH(mqtt_msg_t * __restrict buf, char * __restrict psTopic,
588: int topicLen, unsigned short *msgID, void ** __restrict pData);
1.1 misho 589: /*
590: * mqtt_readPUBACK() Read PUBACK message
591: *
592: * @buf = Message buffer
593: * return: -1 error or MessageID
594: */
1.2 misho 595: unsigned short mqtt_readPUBACK(mqtt_msg_t * __restrict buf);
1.1 misho 596: /*
597: * mqtt_readPUBREC() Read PUBREC message
598: *
599: * @buf = Message buffer
600: * return: -1 error or MessageID
601: */
1.2 misho 602: unsigned short mqtt_readPUBREC(mqtt_msg_t * __restrict buf);
1.1 misho 603: /*
604: * mqtt_readPUBREL() Read PUBREL message
605: *
606: * @buf = Message buffer
607: * return: -1 error or MessageID
608: */
1.2 misho 609: unsigned short mqtt_readPUBREL(mqtt_msg_t * __restrict buf);
1.1 misho 610: /*
611: * mqtt_readPUBCOMP() Read PUBCOMP message
612: *
613: * @buf = Message buffer
614: * return: -1 error or MessageID
615: */
1.2 misho 616: unsigned short mqtt_readPUBCOMP(mqtt_msg_t * __restrict buf);
1.1 misho 617:
618: /*
619: * mqtt_readSUBSCRIBE() Read SUBSCRIBE message
620: *
621: * @buf = Message buffer
622: * @msgID = MessageID
623: * @subscr = Subscriptions, must be free after use with mqtt_subFree()
1.2 misho 624: * return: -1 error or >-1 elements into subscr
1.1 misho 625: */
1.2 misho 626: int mqtt_readSUBSCRIBE(mqtt_msg_t * __restrict buf, unsigned short *msgID,
1.1 misho 627: mqtt_subscr_t **subscr);
628: /*
629: * mqtt_readSUBACK() Read SUBACK message
630: *
631: * @buf = Message buffer
632: * @msgID = MessageID
633: * @subqos = Subscribes QoS, must be free after use with free()
634: * return: -1 error or >-1 readed subscribes QoS elements
635: */
1.2 misho 636: int mqtt_readSUBACK(mqtt_msg_t * __restrict buf, unsigned short *msgID, unsigned char **subqos);
1.1 misho 637: /*
638: * mqtt_readUNSUBSCRIBE() Read UNSUBSCRIBE message
639: *
640: * @buf = Message buffer
641: * @msgID = MessageID
642: * @subscr = Subscriptions, must be free after use with mqtt_subFree()
1.2 misho 643: * return: -1 error or >-1 elements into subscr
1.1 misho 644: */
1.2 misho 645: int mqtt_readUNSUBSCRIBE(mqtt_msg_t * __restrict buf, unsigned short *msgID,
1.1 misho 646: mqtt_subscr_t **subscr);
647: /*
648: * mqtt_readUNSUBACK() Read UNSUBACK message
649: *
650: * @buf = Message buffer
651: * return: -1 error or MessageID
652: */
1.2 misho 653: unsigned short mqtt_readUNSUBACK(mqtt_msg_t * __restrict buf);
1.1 misho 654:
655:
656: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>