diff --git a/include/lwmqtt.h b/include/lwmqtt.h index 0fa9758..dbd3b43 100644 --- a/include/lwmqtt.h +++ b/include/lwmqtt.h @@ -13,7 +13,7 @@ typedef enum { LWMQTT_UNANSWERED_PING = -1, LWMQTT_BUFFER_TOO_SHORT = -2, LWMQTT_REMAINING_LENGTH_OVERFLOW = -3, - LWMQTT_LENGTH_MISMATCH = -4, + LWMQTT_REMAINING_LENGTH_MISMATCH = -4, LWMQTT_NOT_ENOUGH_DATA = -5, LWMQTT_NETWORK_CONNECT_ERROR = -6, LWMQTT_NETWORK_READ_ERROR = -7, @@ -21,7 +21,7 @@ typedef enum { LWMQTT_MISSING_OR_WRONG_PACKET = -9, LWMQTT_CONNECTION_DENIED = -10, LWMQTT_FAILED_SUBSCRIPTION = -11, - LWMQTT_DECODE_ERROR = -12, + LWMQTT_SUBACK_ARRAY_OVERFLOW = -12, LWMQTT_VARNUM_OVERFLOW = -13 } lwmqtt_err_t; diff --git a/src/packet.c b/src/packet.c index 6a36301..2ce97e7 100644 --- a/src/packet.c +++ b/src/packet.c @@ -65,7 +65,7 @@ lwmqtt_err_t lwmqtt_detect_packet_type(uint8_t *buf, size_t buf_len, lwmqtt_pack return LWMQTT_SUCCESS; default: *packet_type = LWMQTT_NO_PACKET; - return LWMQTT_DECODE_ERROR; + return LWMQTT_MISSING_OR_WRONG_PACKET; } } @@ -246,7 +246,7 @@ lwmqtt_err_t lwmqtt_decode_connack(uint8_t *buf, size_t buf_len, bool *session_p if (err != LWMQTT_SUCCESS) { return err; } else if (header.bits.type != LWMQTT_CONNACK_PACKET) { - return LWMQTT_DECODE_ERROR; + return LWMQTT_MISSING_OR_WRONG_PACKET; } // read remaining length @@ -258,7 +258,7 @@ lwmqtt_err_t lwmqtt_decode_connack(uint8_t *buf, size_t buf_len, bool *session_p // check remaining length if (rem_len != 2) { - return LWMQTT_LENGTH_MISMATCH; + return LWMQTT_REMAINING_LENGTH_MISMATCH; } // read flags @@ -333,7 +333,7 @@ lwmqtt_err_t lwmqtt_decode_ack(uint8_t *buf, size_t buf_len, lwmqtt_packet_type_ // check remaining length if (rem_len != 2) { - return LWMQTT_LENGTH_MISMATCH; + return LWMQTT_REMAINING_LENGTH_MISMATCH; } // read packet id @@ -393,7 +393,7 @@ lwmqtt_err_t lwmqtt_decode_publish(uint8_t *buf, size_t buf_len, bool *dup, uint if (err != LWMQTT_SUCCESS) { return err; } else if (header.bits.type != LWMQTT_PUBLISH_PACKET) { - return LWMQTT_DECODE_ERROR; + return LWMQTT_MISSING_OR_WRONG_PACKET; } // set variables @@ -410,7 +410,7 @@ lwmqtt_err_t lwmqtt_decode_publish(uint8_t *buf, size_t buf_len, bool *dup, uint // check remaining length (topic length) if (rem_len < 2) { - return LWMQTT_LENGTH_MISMATCH; + return LWMQTT_REMAINING_LENGTH_MISMATCH; } // read topic @@ -578,7 +578,7 @@ lwmqtt_err_t lwmqtt_decode_suback(uint8_t *buf, size_t buf_len, uint16_t *packet if (err != LWMQTT_SUCCESS) { return err; } else if (header.bits.type != LWMQTT_SUBACK_PACKET) { - return LWMQTT_DECODE_ERROR; + return LWMQTT_MISSING_OR_WRONG_PACKET; } // read remaining length @@ -590,7 +590,7 @@ lwmqtt_err_t lwmqtt_decode_suback(uint8_t *buf, size_t buf_len, uint16_t *packet // check remaining length (packet id + min. one suback code) if (rem_len < 3) { - return LWMQTT_LENGTH_MISMATCH; + return LWMQTT_REMAINING_LENGTH_MISMATCH; } // read packet id @@ -603,7 +603,7 @@ lwmqtt_err_t lwmqtt_decode_suback(uint8_t *buf, size_t buf_len, uint16_t *packet for (*count = 0; *count < (int)rem_len - 2; (*count)++) { // check max count if (*count > max_count) { - return LWMQTT_DECODE_ERROR; + return LWMQTT_SUBACK_ARRAY_OVERFLOW; } // read qos level diff --git a/tests/packet.cpp b/tests/packet.cpp index f7434cf..c35a664 100644 --- a/tests/packet.cpp +++ b/tests/packet.cpp @@ -25,7 +25,7 @@ TEST(DetectPacketType, Invalid) { lwmqtt_packet_type_t p; lwmqtt_err_t err = lwmqtt_detect_packet_type(&h, 1, &p); EXPECT_EQ(p, LWMQTT_NO_PACKET); - EXPECT_EQ(err, LWMQTT_DECODE_ERROR); + EXPECT_EQ(err, LWMQTT_MISSING_OR_WRONG_PACKET); } TEST(DetectRemainingLength, Valid1) { @@ -213,7 +213,7 @@ TEST(ConnackTest, DecodeError1) { lwmqtt_return_code_t return_code; lwmqtt_err_t err = lwmqtt_decode_connack(pkt, 4, &session_present, &return_code); - EXPECT_EQ(err, LWMQTT_LENGTH_MISMATCH); + EXPECT_EQ(err, LWMQTT_REMAINING_LENGTH_MISMATCH); } TEST(ConnackTest, DecodeError2) { @@ -227,7 +227,7 @@ TEST(ConnackTest, DecodeError2) { lwmqtt_return_code_t return_code; lwmqtt_err_t err = lwmqtt_decode_connack(pkt, 3, &session_present, &return_code); - EXPECT_EQ(err, LWMQTT_LENGTH_MISMATCH); + EXPECT_EQ(err, LWMQTT_REMAINING_LENGTH_MISMATCH); } TEST(ZeroTest, Encode1) { @@ -273,7 +273,7 @@ TEST(AckTest, DecodeError1) { uint16_t packet_id; lwmqtt_err_t err = lwmqtt_decode_ack(pkt, 4, &packet_type, &dup, &packet_id); - EXPECT_EQ(err, LWMQTT_LENGTH_MISMATCH); + EXPECT_EQ(err, LWMQTT_REMAINING_LENGTH_MISMATCH); } TEST(AckTest, DecodeError2) { @@ -289,7 +289,7 @@ TEST(AckTest, DecodeError2) { uint16_t packet_id; lwmqtt_err_t err = lwmqtt_decode_ack(pkt, 4, &packet_type, &dup, &packet_id); - EXPECT_EQ(err, LWMQTT_LENGTH_MISMATCH); + EXPECT_EQ(err, LWMQTT_REMAINING_LENGTH_MISMATCH); } TEST(AckTest, Encode1) { @@ -554,7 +554,7 @@ TEST(SubackTest, DecodeError1) { lwmqtt_qos_t granted_qos_levels[2]; lwmqtt_err_t err = lwmqtt_decode_suback(pkt, 5, &packet_id, 2, &count, granted_qos_levels); - EXPECT_EQ(err, LWMQTT_LENGTH_MISMATCH); + EXPECT_EQ(err, LWMQTT_REMAINING_LENGTH_MISMATCH); } TEST(SubscribeTest, Encode1) {