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