From d29bf7557bd1e2f6907d8800b96f243c350fb6b1 Mon Sep 17 00:00:00 2001 From: David Garske Date: Fri, 24 Apr 2020 13:01:54 -0700 Subject: [PATCH 1/3] wolfMQTT Release v1.6 preparation. --- ChangeLog.md | 18 ++++++++++++++++++ configure.ac | 4 ++-- wolfmqtt/version.h | 4 ++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index b3eefcc86..a5c45c612 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,6 +1,24 @@ ## Release Notes +### v1.6 (04/24/2020) + +* Fixes to improve buffer size checking when using a small tx or rx buffer. (PR #137) +* Fix for MQTT v5 issue with using wrong property free. (PR #152) +* Refactor of the thread locking to use binary semaphore, which resolves issue with thread synchronization. (PR #146) +* Improved multi-thread example exit (ctrl+c). Use internal pipe to wake "select()" and use semaphore signal to "wake" ping thread. (PR #146) +* Adjust multi-threading use case to use separate thread for ping keep-alive. (PR #146) +* Added simple standalone MQTT client example. (PR #138) +* Added include for "user_settings.h" when `WOLFMQTT_USER_SETTINGS` is defined. (PR #138) +* Added broker compatibility list (PR #145) +* Added protocol version API's. (PR #152) +* Added multithread example for Windows and Visual Studio. (PR #146) +* Made protocol level a run time option (PR #147) +* Remove obsolete "sched_yield" call. (PR #146) +* Remove deprecated call to `wolfSSL_set_using_nonblock()` (PR #148) +* Sync automake fixes from wolfSSL to wolfMQTT. (PR #150) +* Moved `MAX_PACKET_ID` to library. (PR #138) + ### v1.4 (12/27/19) * Fixes for non-blocking and multi-threading edge cases. (PR #130) diff --git a/configure.ac b/configure.ac index 76c228b22..749cf5551 100644 --- a/configure.ac +++ b/configure.ac @@ -3,7 +3,7 @@ # All right reserved. AC_COPYRIGHT([Copyright (C) 2014-2020 wolfSSL Inc.]) -AC_INIT([wolfmqtt],[1.4.0],[https://github.com/wolfssl/wolfMQTT/issues],[wolfmqtt],[http://www.wolfssl.com]) +AC_INIT([wolfmqtt],[1.6.0],[https://github.com/wolfssl/wolfMQTT/issues],[wolfmqtt],[http://www.wolfssl.com]) AC_PREREQ([2.63]) AC_CONFIG_AUX_DIR([build-aux]) @@ -23,7 +23,7 @@ AC_ARG_PROGRAM AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_HEADERS([src/config.h]) -WOLFMQTT_LIBRARY_VERSION=5:1:0 +WOLFMQTT_LIBRARY_VERSION=6:0:0 # | | | # +------+ | +---+ # | | | diff --git a/wolfmqtt/version.h b/wolfmqtt/version.h index 2be4e723d..3f7d98292 100644 --- a/wolfmqtt/version.h +++ b/wolfmqtt/version.h @@ -34,8 +34,8 @@ extern "C" { #endif -#define LIBWOLFMQTT_VERSION_STRING "1.4.0" -#define LIBWOLFMQTT_VERSION_HEX 0x01004000 +#define LIBWOLFMQTT_VERSION_STRING "1.6.0" +#define LIBWOLFMQTT_VERSION_HEX 0x01006000 #ifdef __cplusplus } From 2094c31d9181a8454f6642acfabefd7eed05d61e Mon Sep 17 00:00:00 2001 From: David Garske Date: Mon, 27 Apr 2020 14:08:13 -0700 Subject: [PATCH 2/3] Fixes for scan-build and G++ compiler warnings. --- examples/multithread/multithread.c | 8 ++++---- src/mqtt_client.c | 30 +++++++++++++++++------------- src/mqtt_packet.c | 10 +++++----- wolfmqtt/mqtt_packet.h | 3 ++- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/examples/multithread/multithread.c b/examples/multithread/multithread.c index d0b247160..b76781774 100755 --- a/examples/multithread/multithread.c +++ b/examples/multithread/multithread.c @@ -317,7 +317,7 @@ static void *subscribe_task(void *param) { int rc = MQTT_CODE_SUCCESS; uint16_t i; - MQTTCtx *mqttCtx = param; + MQTTCtx *mqttCtx = (MQTTCtx*)param; /* Build list of topics */ XMEMSET(&mqttCtx->subscribe, 0, sizeof(MqttSubscribe)); @@ -375,7 +375,7 @@ static void *waitMessage_task(void *param) #endif { int rc; - MQTTCtx *mqttCtx = param; + MQTTCtx *mqttCtx = (MQTTCtx*)param; /* Read Loop */ PRINTF("MQTT Waiting for message..."); @@ -453,7 +453,7 @@ static void *publish_task(void *param) { int rc; char buf[7]; - MQTTCtx *mqttCtx = param; + MQTTCtx *mqttCtx = (MQTTCtx*)param; MqttPublish publish; /* Publish Topic */ @@ -485,7 +485,7 @@ static void *ping_task(void *param) #endif { int rc; - MQTTCtx *mqttCtx = param; + MQTTCtx *mqttCtx = (MQTTCtx*)param; MqttPing ping; XMEMSET(&ping, 0, sizeof(ping)); diff --git a/src/mqtt_client.c b/src/mqtt_client.c index bf1163d88..e16d13320 100644 --- a/src/mqtt_client.c +++ b/src/mqtt_client.c @@ -748,7 +748,7 @@ static int MqttClient_WaitType(MqttClient *client, void *packet_obj, MqttPacket_TypeDesc(wait_type), wait_type, wait_packet_id); #endif - switch (*mms_stat) + switch ((int)*mms_stat) { case MQTT_MSG_BEGIN: { @@ -776,8 +776,8 @@ static int MqttClient_WaitType(MqttClient *client, void *packet_obj, pendResp = NULL; rc = wm_SemLock(&client->lockClient); if (rc == 0) { - if (MqttClient_RespList_Find(client, wait_type, wait_packet_id, - &pendResp)) { + if (MqttClient_RespList_Find(client, (MqttPacketType)wait_type, + wait_packet_id, &pendResp)) { if (pendResp->packetDone) { /* pending response is already done, so return */ rc = pendResp->packet_ret; @@ -2336,19 +2336,23 @@ static int SN_Client_WaitType(MqttClient *client, void* packet_obj, { int rc; SN_MsgType packet_type; - word16 packet_id = 0; - MqttMsgStat* stat; + word16 packet_id; + MqttMsgStat* mms_stat; if (client == NULL || packet_obj == NULL) { return MQTT_CODE_ERROR_BAD_ARG; } /* all packet type structures must have MqttMsgStat at top */ - stat = (MqttMsgStat*)packet_obj; + mms_stat = (MqttMsgStat*)packet_obj; wait_again: - switch ((int)*stat) + /* initialize variables */ + packet_id = 0; + packet_type = SN_MSG_TYPE_RESERVED; + + switch ((int)*mms_stat) { case MQTT_MSG_BEGIN: { @@ -2366,7 +2370,7 @@ static int SN_Client_WaitType(MqttClient *client, void* packet_obj, return rc; } - *stat = MQTT_MSG_WAIT; + *mms_stat = MQTT_MSG_WAIT; client->packet.buf_len = rc; /* Decode header */ @@ -2380,7 +2384,7 @@ static int SN_Client_WaitType(MqttClient *client, void* packet_obj, client->packet.buf_len, packet_type); #endif - *stat = MQTT_MSG_READ; + *mms_stat = MQTT_MSG_READ; FALL_THROUGH; } @@ -2388,7 +2392,7 @@ static int SN_Client_WaitType(MqttClient *client, void* packet_obj, case MQTT_MSG_READ: case MQTT_MSG_READ_PAYLOAD: { - if (*stat == MQTT_MSG_READ_PAYLOAD) { + if (*mms_stat == MQTT_MSG_READ_PAYLOAD) { packet_type = SN_MSG_TYPE_PUBLISH; } rc = SN_Client_HandlePacket(client, packet_type, packet_obj, @@ -2405,7 +2409,7 @@ static int SN_Client_WaitType(MqttClient *client, void* packet_obj, break; } - *stat = MQTT_MSG_BEGIN; + *mms_stat = MQTT_MSG_BEGIN; goto wait_again; } @@ -2416,7 +2420,7 @@ static int SN_Client_WaitType(MqttClient *client, void* packet_obj, default: { #ifdef WOLFMQTT_DEBUG_CLIENT - PRINTF("SN_Client_WaitType: Invalid state %d!", *stat); + PRINTF("SN_Client_WaitType: Invalid state %d!", *mms_stat); #endif rc = MQTT_CODE_ERROR_STAT; break; @@ -2424,7 +2428,7 @@ static int SN_Client_WaitType(MqttClient *client, void* packet_obj, } /* switch (msg->stat) */ /* reset state */ - *stat = MQTT_MSG_BEGIN; + *mms_stat = MQTT_MSG_BEGIN; return rc; } diff --git a/src/mqtt_packet.c b/src/mqtt_packet.c index 2a37ae4a0..82a7174f7 100755 --- a/src/mqtt_packet.c +++ b/src/mqtt_packet.c @@ -837,8 +837,8 @@ int MqttEncode_Publish(byte *tx_buf, int tx_buf_len, MqttPublish *publish, tx_payload += MqttEncode_Vbi(tx_payload, props_len); /* Encode properties */ - tx_payload += MqttEncode_Props(publish->type, publish->props, - tx_payload); + tx_payload += MqttEncode_Props((MqttPacketType)publish->type, + publish->props, tx_payload); } #endif @@ -912,8 +912,8 @@ int MqttDecode_Publish(byte *rx_buf, int rx_buf_len, MqttPublish *publish) variable_len += tmp + props_len; if (props_len > 0) { /* Decode the Properties */ - rx_payload += MqttDecode_Props(publish->type, &publish->props, - rx_payload, props_len); + rx_payload += MqttDecode_Props((MqttPacketType)publish->type, + &publish->props, rx_payload, props_len); if (publish->props != NULL) { /* Parse properties. */ } @@ -1854,7 +1854,7 @@ int SN_Decode_Header(byte *rx_buf, int rx_buf_len, } /* Message Type */ - packet_type = *rx_buf++; + packet_type = (SN_MsgType)*rx_buf++; if (p_packet_type) *p_packet_type = packet_type; diff --git a/wolfmqtt/mqtt_packet.h b/wolfmqtt/mqtt_packet.h index 54e395e60..14808f1f0 100644 --- a/wolfmqtt/mqtt_packet.h +++ b/wolfmqtt/mqtt_packet.h @@ -759,8 +759,9 @@ typedef enum _SN_MsgType { SN_MSG_TYPE_WILLMSGUPD = 0x1C, SN_MSG_TYPE_WILLMSGRESP = 0x1D, /* 0x1E - 0xFD reserved */ - SN_MSG_TYPE_ENCAPMSG = 0xFE /* Encapsulated message */ + SN_MSG_TYPE_ENCAPMSG = 0xFE, /* Encapsulated message */ /* 0xFF reserved */ + SN_MSG_TYPE_RESERVED = 0xFF } SN_MsgType; /* Topic ID types */ From 3c8d7526d4f109dc149419ff998e829a35a834ec Mon Sep 17 00:00:00 2001 From: David Garske Date: Mon, 27 Apr 2020 14:11:51 -0700 Subject: [PATCH 3/3] Fix for MQTT v5 property name typo. --- examples/mqttclient/mqttclient.c | 4 ++-- src/mqtt_packet.c | 2 +- wolfmqtt/mqtt_packet.h | 5 ++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/mqttclient/mqttclient.c b/examples/mqttclient/mqttclient.c index 547a1166c..ddf8c6e5d 100644 --- a/examples/mqttclient/mqttclient.c +++ b/examples/mqttclient/mqttclient.c @@ -177,7 +177,7 @@ static int mqtt_property_cb(MqttClient *client, MqttProp *head, void *ctx) PRINTF("Reason String: %s", prop->data_str.str); break; - case MQTT_PROP_PLAYLOAD_FORMAT_IND: + case MQTT_PROP_PAYLOAD_FORMAT_IND: case MQTT_PROP_MSG_EXPIRY_INTERVAL: case MQTT_PROP_CONTENT_TYPE: case MQTT_PROP_RESP_TOPIC: @@ -428,7 +428,7 @@ int mqttclient_test(MQTTCtx *mqttCtx) { /* Payload Format Indicator */ MqttProp* prop = MqttClient_PropsAdd(&mqttCtx->publish.props); - prop->type = MQTT_PROP_PLAYLOAD_FORMAT_IND; + prop->type = MQTT_PROP_PAYLOAD_FORMAT_IND; prop->data_int = 1; } { diff --git a/src/mqtt_packet.c b/src/mqtt_packet.c index 82a7174f7..66a2d5f54 100755 --- a/src/mqtt_packet.c +++ b/src/mqtt_packet.c @@ -35,7 +35,7 @@ struct MqttPropMatrix { }; static const struct MqttPropMatrix gPropMatrix[] = { { MQTT_PROP_NONE, MQTT_DATA_TYPE_NONE, 0 }, - { MQTT_PROP_PLAYLOAD_FORMAT_IND, MQTT_DATA_TYPE_BYTE, + { MQTT_PROP_PAYLOAD_FORMAT_IND, MQTT_DATA_TYPE_BYTE, (1 << MQTT_PACKET_TYPE_PUBLISH) }, { MQTT_PROP_MSG_EXPIRY_INTERVAL, MQTT_DATA_TYPE_INT, (1 << MQTT_PACKET_TYPE_PUBLISH) }, diff --git a/wolfmqtt/mqtt_packet.h b/wolfmqtt/mqtt_packet.h index 14808f1f0..fbe4e2e70 100644 --- a/wolfmqtt/mqtt_packet.h +++ b/wolfmqtt/mqtt_packet.h @@ -62,7 +62,7 @@ typedef enum MqttDataType { /* PROPERTIES */ typedef enum MqttPropertyType { MQTT_PROP_NONE = 0, - MQTT_PROP_PLAYLOAD_FORMAT_IND = 1, + MQTT_PROP_PAYLOAD_FORMAT_IND = 1, MQTT_PROP_MSG_EXPIRY_INTERVAL = 2, MQTT_PROP_CONTENT_TYPE = 3, MQTT_PROP_RESP_TOPIC = 8, @@ -92,6 +92,9 @@ typedef enum MqttPropertyType { MQTT_PROP_TYPE_MAX = 0xFF } MqttPropertyType; +/* backwards compatibility for anyone using the typo name */ +#define MQTT_PROP_PLAYLOAD_FORMAT_IND MQTT_PROP_PAYLOAD_FORMAT_IND + struct _MqttProp_Str { word16 len; char *str;