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