@@ -810,25 +810,132 @@ int publish_decode(const struct mqtt_client *client, uint8_t flags,
810810 return 0 ;
811811}
812812
813- int publish_ack_decode (struct buf_ctx * buf , struct mqtt_puback_param * param )
813+ #if defined(CONFIG_MQTT_VERSION_5_0 )
814+ static int common_ack_properties_decode (struct buf_ctx * buf ,
815+ struct mqtt_common_ack_properties * prop )
814816{
815- return unpack_uint16 (buf , & param -> message_id );
817+ struct property_decoder prop_dec [] = {
818+ {
819+ & prop -> reason_string ,
820+ & prop -> rx .has_reason_string ,
821+ MQTT_PROP_REASON_STRING
822+ },
823+ {
824+ & prop -> user_prop ,
825+ & prop -> rx .has_user_prop ,
826+ MQTT_PROP_USER_PROPERTY
827+ }
828+ };
829+
830+ return properties_decode (prop_dec , ARRAY_SIZE (prop_dec ), buf );
831+ }
832+ #else
833+ static int common_ack_properties_decode (struct buf_ctx * buf ,
834+ struct mqtt_common_ack_properties * prop )
835+ {
836+ ARG_UNUSED (prop );
837+ ARG_UNUSED (buf );
838+
839+ return - ENOTSUP ;
816840}
841+ #endif /* CONFIG_MQTT_VERSION_5_0 */
817842
818- int publish_receive_decode (struct buf_ctx * buf , struct mqtt_pubrec_param * param )
843+ static int common_pub_ack_decode (struct buf_ctx * buf , uint16_t * message_id ,
844+ uint8_t * reason_code ,
845+ struct mqtt_common_ack_properties * prop )
819846{
820- return unpack_uint16 (buf , & param -> message_id );
847+ size_t remaining_len ;
848+ int err ;
849+
850+ err = unpack_uint16 (buf , message_id );
851+ if (err < 0 ) {
852+ return err ;
853+ }
854+
855+ remaining_len = buf -> end - buf -> cur ;
856+
857+ /* For MQTT < 5.0 properties are NULL. */
858+ if (prop != NULL && reason_code != NULL ) {
859+ if (remaining_len > 0 ) {
860+ err = unpack_uint8 (buf , reason_code );
861+ if (err < 0 ) {
862+ return err ;
863+ }
864+ }
865+
866+ if (remaining_len > 1 ) {
867+ err = common_ack_properties_decode (buf , prop );
868+ if (err < 0 ) {
869+ return err ;
870+ }
871+ }
872+ }
873+
874+ return 0 ;
821875}
822876
823- int publish_release_decode (struct buf_ctx * buf , struct mqtt_pubrel_param * param )
877+ int publish_ack_decode (const struct mqtt_client * client , struct buf_ctx * buf ,
878+ struct mqtt_puback_param * param )
824879{
825- return unpack_uint16 (buf , & param -> message_id );
880+ struct mqtt_common_ack_properties * prop = NULL ;
881+ uint8_t * reason_code = NULL ;
882+
883+ #if defined(CONFIG_MQTT_VERSION_5_0 )
884+ if (mqtt_is_version_5_0 (client )) {
885+ prop = & param -> prop ;
886+ reason_code = & param -> reason_code ;
887+ }
888+ #endif
889+
890+ return common_pub_ack_decode (buf , & param -> message_id , reason_code , prop );
891+ }
892+
893+ int publish_receive_decode (const struct mqtt_client * client , struct buf_ctx * buf ,
894+ struct mqtt_pubrec_param * param )
895+ {
896+ struct mqtt_common_ack_properties * prop = NULL ;
897+ uint8_t * reason_code = NULL ;
898+
899+ #if defined(CONFIG_MQTT_VERSION_5_0 )
900+ if (mqtt_is_version_5_0 (client )) {
901+ prop = & param -> prop ;
902+ reason_code = & param -> reason_code ;
903+ }
904+ #endif
905+
906+ return common_pub_ack_decode (buf , & param -> message_id , reason_code , prop );
826907}
827908
828- int publish_complete_decode (struct buf_ctx * buf ,
909+ int publish_release_decode (const struct mqtt_client * client , struct buf_ctx * buf ,
910+ struct mqtt_pubrel_param * param )
911+ {
912+ struct mqtt_common_ack_properties * prop = NULL ;
913+ uint8_t * reason_code = NULL ;
914+
915+ #if defined(CONFIG_MQTT_VERSION_5_0 )
916+ if (mqtt_is_version_5_0 (client )) {
917+ prop = & param -> prop ;
918+ reason_code = & param -> reason_code ;
919+ }
920+ #endif
921+
922+ return common_pub_ack_decode (buf , & param -> message_id , reason_code , prop );
923+ }
924+
925+ int publish_complete_decode (const struct mqtt_client * client , struct buf_ctx * buf ,
829926 struct mqtt_pubcomp_param * param )
830927{
831- return unpack_uint16 (buf , & param -> message_id );
928+ struct mqtt_common_ack_properties * prop = NULL ;
929+ uint8_t * reason_code = NULL ;
930+
931+ #if defined(CONFIG_MQTT_VERSION_5_0 )
932+ if (mqtt_is_version_5_0 (client )) {
933+ prop = & param -> prop ;
934+ reason_code = & param -> reason_code ;
935+ }
936+ #endif
937+
938+ return common_ack_decode (buf , & param -> message_id , reason_code , prop );
832939}
833940
834941int subscribe_ack_decode (struct buf_ctx * buf , struct mqtt_suback_param * param )
0 commit comments