From 3fdfc0617e404ac3df795cf1bbea9c23180aa120 Mon Sep 17 00:00:00 2001 From: Euripedes Rocha Filho Date: Tue, 14 Jul 2026 16:27:51 +0200 Subject: [PATCH] fix(mqtt5): Removes incorrect reason code verification when resending pubrel Fixes #333 --- lib/mqtt5_msg.c | 7 ++++--- mqtt_client.c | 2 -- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/mqtt5_msg.c b/lib/mqtt5_msg.c index 05cae62..634dfd1 100644 --- a/lib/mqtt5_msg.c +++ b/lib/mqtt5_msg.c @@ -1178,8 +1178,9 @@ int mqtt5_msg_get_reason_code(uint8_t *buffer, size_t length) size_t offset = 1; // Message type size_t variable_len = get_variable_len(buffer, offset, length, &len_bytes); offset += len_bytes; + uint8_t type = mqtt5_get_type(buffer); - switch (mqtt5_get_type(buffer)) { + switch (type) { case MQTT_MSG_TYPE_PUBACK: case MQTT_MSG_TYPE_PUBREC: case MQTT_MSG_TYPE_PUBREL: @@ -1191,7 +1192,7 @@ int mqtt5_msg_get_reason_code(uint8_t *buffer, size_t length) offset += 2; //skip the message id if (offset >= length) { - ESP_LOGE(TAG, "Invalid control packet, reason code is absent"); + ESP_LOGE(TAG, "Invalid control packet type %d, reason code is absent", type); return -1; } @@ -1209,7 +1210,7 @@ int mqtt5_msg_get_reason_code(uint8_t *buffer, size_t length) offset = offset + len_bytes + property_len; if (offset >= length) { - ESP_LOGE(TAG, "Invalid control packet, reason code is absent"); + ESP_LOGE(TAG, "Invalid control packet type %d, reason code is absent", type); return -1; } diff --git a/mqtt_client.c b/mqtt_client.c index 6db0d29..252e8dc 100644 --- a/mqtt_client.c +++ b/mqtt_client.c @@ -1840,8 +1840,6 @@ static esp_err_t mqtt_resend_pubrel(esp_mqtt_client_handle_t client, outbox_item if (client->mqtt_state.connection.information.protocol_ver == MQTT_PROTOCOL_V_5) { #ifdef MQTT_PROTOCOL_5 - ESP_LOGI(TAG, "MQTT_MSG_TYPE_PUBREC return code is %d", mqtt5_msg_get_reason_code(client->mqtt_state.in_buffer, - client->mqtt_state.in_buffer_read_len)); mqtt5_msg_pubrel(&client->mqtt_state.connection, client->mqtt_state.pending_msg_id); #endif } else {