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