My Modify MQTTPacket Packet size 100 -> 400
Fork of MQTTPacket by
Revision 16:d0b3886ada32, committed 2014-08-01
- Comitter:
- icraggs
- Date:
- Fri Aug 01 16:58:18 2014 +0000
- Parent:
- 15:f0ae0b8d4418
- Child:
- 17:c5bd28cc139a
- Commit message:
- Add session present flag on connack
Changed in this revision
--- a/MQTTConnect.h Fri Aug 01 16:27:19 2014 +0000
+++ b/MQTTConnect.h Fri Aug 01 16:58:18 2014 +0000
@@ -94,14 +94,32 @@
MQTTString password;
} MQTTPacket_connectData;
+typedef union
+{
+ unsigned char all; /**< all connack flags */
+#if defined(REVERSED)
+ struct
+ {
+ unsigned int sessionpresent : 1; /**< session present flag */
+ unsigned int : y; /**< unused */
+ } bits;
+#else
+ struct
+ {
+ unsigned int : 7; /**< unused */
+ unsigned int sessionpresent : 1; /**< session present flag */
+ } bits;
+#endif
+} MQTTConnackFlags; /**< connack flags byte */
+
#define MQTTPacket_connectData_initializer { {'M', 'Q', 'T', 'C'}, 0, 4, {NULL, {0, NULL}}, 60, 1, 0, \
MQTTPacket_willOptions_initializer, {NULL, {0, NULL}}, {NULL, {0, NULL}} }
int MQTTSerialize_connect(unsigned char* buf, int buflen, MQTTPacket_connectData* options);
int MQTTDeserialize_connect(MQTTPacket_connectData* data, unsigned char* buf, int len);
-int MQTTSerialize_connack(unsigned char* buf, int buflen, unsigned char connack_rc);
-int MQTTDeserialize_connack(unsigned char* connack_rc, unsigned char* buf, int buflen);
+int MQTTSerialize_connack(unsigned char* buf, int buflen, unsigned char connack_rc, unsigned char sessionPresent);
+int MQTTDeserialize_connack(unsigned char* sessionPresent, unsigned char* connack_rc, unsigned char* buf, int buflen);
int MQTTSerialize_disconnect(unsigned char* buf, int buflen);
int MQTTSerialize_pingreq(unsigned char* buf, int buflen);
--- a/MQTTConnectClient.c Fri Aug 01 16:27:19 2014 +0000
+++ b/MQTTConnectClient.c Fri Aug 01 16:58:18 2014 +0000
@@ -123,19 +123,20 @@
/**
* Deserializes the supplied (wire) buffer into connack data - return code
+ * @param sessionPresent the session present flag returned (only for MQTT 3.1.1)
* @param connack_rc returned integer value of the connack return code
* @param buf the raw buffer data, of the correct length determined by the remaining length field
* @param len the length in bytes of the data in the supplied buffer
* @return error code. 1 is success, 0 is failure
*/
-int MQTTDeserialize_connack(unsigned char* connack_rc, unsigned char* buf, int buflen)
+int MQTTDeserialize_connack(unsigned char* sessionPresent, unsigned char* connack_rc, unsigned char* buf, int buflen)
{
MQTTHeader header;
unsigned char* curdata = buf;
unsigned char* enddata = NULL;
int rc = 0;
int mylen;
- int compression;
+ MQTTConnackFlags flags;
FUNC_ENTRY;
header.byte = readChar(&curdata);
@@ -147,7 +148,8 @@
if (enddata - curdata < 2)
goto exit;
- compression = readChar(&curdata);
+ flags.all = readChar(&curdata);
+ *sessionPresent = flags.bits.sessionpresent;
*connack_rc = readChar(&curdata);
rc = 1;
--- a/MQTTConnectServer.c Fri Aug 01 16:27:19 2014 +0000
+++ b/MQTTConnectServer.c Fri Aug 01 16:58:18 2014 +0000
@@ -61,6 +61,8 @@
FUNC_ENTRY;
header.byte = readChar(&curdata);
+ if (header.bits.type != CONNECT)
+ goto exit;
curdata += MQTTPacket_decodeBuf(curdata, &mylen); /* read remaining length */
@@ -111,13 +113,15 @@
* @param buf the buffer into which the packet will be serialized
* @param buflen the length in bytes of the supplied buffer
* @param connack_rc the integer connack return code to be used
+ * @param sessionPresent the MQTT 3.1.1 sessionPresent flag
* @return serialized length, or error if 0
*/
-int MQTTSerialize_connack(unsigned char* buf, int buflen, unsigned char connack_rc)
+int MQTTSerialize_connack(unsigned char* buf, int buflen, unsigned char connack_rc, unsigned char sessionPresent)
{
MQTTHeader header;
int rc = 0;
unsigned char *ptr = buf;
+ MQTTConnackFlags flags;
FUNC_ENTRY;
if (buflen < 2)
@@ -131,7 +135,9 @@
ptr += MQTTPacket_encode(ptr, 2); /* write remaining length */
- writeChar(&ptr, 0); /* compression byte - not used */
+ flags.all = 0;
+ flags.bits.sessionpresent = sessionPresent;
+ writeChar(&ptr, flags.all);
writeChar(&ptr, connack_rc);
rc = ptr - buf;
--- a/MQTTDeserializePublish.c Fri Aug 01 16:27:19 2014 +0000 +++ b/MQTTDeserializePublish.c Fri Aug 01 16:58:18 2014 +0000 @@ -44,6 +44,8 @@ FUNC_ENTRY; header.byte = readChar(&curdata); + if (header.bits.type != PUBLISH) + goto exit; *dup = header.bits.dup; *qos = header.bits.qos; *retained = header.bits.retain;
--- a/MQTTSubscribeClient.c Fri Aug 01 16:27:19 2014 +0000 +++ b/MQTTSubscribeClient.c Fri Aug 01 16:58:18 2014 +0000 @@ -107,6 +107,8 @@ FUNC_ENTRY; header.byte = readChar(&curdata); + if (header.bits.type != SUBACK) + goto exit; curdata += (rc = MQTTPacket_decodeBuf(curdata, &mylen)); /* read remaining length */ enddata = curdata + mylen;
--- a/MQTTSubscribeServer.c Fri Aug 01 16:27:19 2014 +0000 +++ b/MQTTSubscribeServer.c Fri Aug 01 16:58:18 2014 +0000 @@ -43,6 +43,8 @@ FUNC_ENTRY; header.byte = readChar(&curdata); + if (header.bits.type != SUBSCRIBE) + goto exit; *dup = header.bits.dup; curdata += (rc = MQTTPacket_decodeBuf(curdata, &mylen)); /* read remaining length */
--- a/MQTTUnsubscribeServer.c Fri Aug 01 16:27:19 2014 +0000 +++ b/MQTTUnsubscribeServer.c Fri Aug 01 16:58:18 2014 +0000 @@ -42,6 +42,8 @@ FUNC_ENTRY; header.byte = readChar(&curdata); + if (header.bits.type != UNSUBSCRIBE) + goto exit; *dup = header.bits.dup; curdata += (rc = MQTTPacket_decodeBuf(curdata, &mylen)); /* read remaining length */
