blob: d77f18c2f8f91875d5256f119f7fbf9b687fd62c [file] [log] [blame]
liubin281ac462023-07-19 14:22:54 +08001/*******************************************************************************
2 * Copyright (c) 2014 IBM Corp.
3 *
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * and Eclipse Distribution License v1.0 which accompany this distribution.
7 *
8 * The Eclipse Public License is available at
9 * http://www.eclipse.org/legal/epl-v10.html
10 * and the Eclipse Distribution License is available at
11 * http://www.eclipse.org/org/documents/edl-v10.php.
12 *
13 * Contributors:
14 * Ian Craggs - initial API and implementation and/or initial documentation
15 * Xiang Rong - 442039 Add makefile to Embedded C client
16 *******************************************************************************/
17
18#ifndef MQTTCONNECT_H_
19#define MQTTCONNECT_H_
20
21#if !defined(DLLImport)
22 #define DLLImport
23#endif
24#if !defined(DLLExport)
25 #define DLLExport
26#endif
27
28
29typedef union
30{
31 unsigned char all; /**< all connect flags */
32#if defined(REVERSED)
33 struct
34 {
35 unsigned int username : 1; /**< 3.1 user name */
36 unsigned int password : 1; /**< 3.1 password */
37 unsigned int willRetain : 1; /**< will retain setting */
38 unsigned int willQoS : 2; /**< will QoS value */
39 unsigned int will : 1; /**< will flag */
40 unsigned int cleansession : 1; /**< clean session flag */
41 unsigned int : 1; /**< unused */
42 } bits;
43#else
44 struct
45 {
46 unsigned int : 1; /**< unused */
47 unsigned int cleansession : 1; /**< cleansession flag */
48 unsigned int will : 1; /**< will flag */
49 unsigned int willQoS : 2; /**< will QoS value */
50 unsigned int willRetain : 1; /**< will retain setting */
51 unsigned int password : 1; /**< 3.1 password */
52 unsigned int username : 1; /**< 3.1 user name */
53 } bits;
54#endif
55} MQTTConnectFlags; /**< connect flags byte */
56
57
58
59/**
60 * Defines the MQTT "Last Will and Testament" (LWT) settings for
61 * the connect packet.
62 */
63typedef struct
64{
65 /** The eyecatcher for this structure. must be MQTW. */
66 char struct_id[4];
67 /** The version number of this structure. Must be 0 */
68 int struct_version;
69 /** The LWT topic to which the LWT message will be published. */
70 MQTTString topicName;
71 /** The LWT payload. */
72 MQTTString message;
73 /**
74 * The retained flag for the LWT message (see MQTTAsync_message.retained).
75 */
76 unsigned char retained;
77 /**
78 * The quality of service setting for the LWT message (see
79 * MQTTAsync_message.qos and @ref qos).
80 */
81 char qos;
82} MQTTPacket_willOptions;
83
84
85#define MQTTPacket_willOptions_initializer { {'M', 'Q', 'T', 'W'}, 0, {NULL, {0, NULL}}, {NULL, {0, NULL}}, 0, 0 }
86
87
88typedef struct
89{
90 /** The eyecatcher for this structure. must be MQTC. */
91 char struct_id[4];
92 /** The version number of this structure. Must be 0 */
93 int struct_version;
94 /** Version of MQTT to be used. 3 = 3.1 4 = 3.1.1
95 */
96 unsigned char MQTTVersion;
97 MQTTString clientID;
98 unsigned short keepAliveInterval;
99 unsigned char cleansession;
100 unsigned char willFlag;
101 MQTTPacket_willOptions will;
102 MQTTString username;
103 MQTTString password;
104} MQTTPacket_connectData;
105
106typedef union
107{
108 unsigned char all; /**< all connack flags */
109#if defined(REVERSED)
110 struct
111 {
112 unsigned int sessionpresent : 1; /**< session present flag */
113 unsigned int : 7; /**< unused */
114 } bits;
115#else
116 struct
117 {
118 unsigned int : 7; /**< unused */
119 unsigned int sessionpresent : 1; /**< session present flag */
120 } bits;
121#endif
122} MQTTConnackFlags; /**< connack flags byte */
123
124#define MQTTPacket_connectData_initializer { {'M', 'Q', 'T', 'C'}, 0, 4, {NULL, {0, NULL}}, 60, 1, 0, \
125 MQTTPacket_willOptions_initializer, {NULL, {0, NULL}}, {NULL, {0, NULL}} }
126
127DLLExport int MQTTSerialize_connect(unsigned char* buf, int buflen, MQTTPacket_connectData* options);
128DLLExport int MQTTDeserialize_connect(MQTTPacket_connectData* data, unsigned char* buf, int len);
129
130DLLExport int MQTTSerialize_connack(unsigned char* buf, int buflen, unsigned char connack_rc, unsigned char sessionPresent);
131DLLExport int MQTTDeserialize_connack(unsigned char* sessionPresent, unsigned char* connack_rc, unsigned char* buf, int buflen);
132
133DLLExport int MQTTSerialize_disconnect(unsigned char* buf, int buflen);
134DLLExport int MQTTSerialize_pingreq(unsigned char* buf, int buflen);
135
136#endif /* MQTTCONNECT_H_ */