@@ -79,6 +79,9 @@ enum mqtt_evt_type {
7979
8080 /** Ping Response from server. */
8181 MQTT_EVT_PINGRESP ,
82+
83+ /** Authentication packet received from server. MQTT 5.0 only. */
84+ MQTT_EVT_AUTH ,
8285};
8386
8487/** @brief MQTT version protocol level. */
@@ -208,6 +211,13 @@ enum mqtt_disconnect_reason_code {
208211 MQTT_DISCONNECT_WILDCARD_SUB_NOT_SUPPORTED = 162 ,
209212};
210213
214+ /** @brief MQTT Authenticate reason codes (MQTT 5.0, chapter 3.15.2.1). */
215+ enum mqtt_auth_reason_code {
216+ MQTT_AUTH_SUCCESS = 0 ,
217+ MQTT_AUTH_CONTINUE_AUTHENTICATION = 24 ,
218+ MQTT_AUTH_RE_AUTHENTICATE = 25 ,
219+ };
220+
211221/** @brief Abstracts UTF-8 encoded strings. */
212222struct mqtt_utf8 {
213223 const uint8_t * utf8 ; /**< Pointer to UTF-8 string. */
@@ -602,6 +612,39 @@ struct mqtt_disconnect_param {
602612#endif /* CONFIG_MQTT_VERSION_5_0 */
603613};
604614
615+ #if defined(CONFIG_MQTT_VERSION_5_0 )
616+ struct mqtt_auth_param {
617+ /* MQTT 5.0, chapter 3.15.2.1 Authenticate Reason Code */
618+ enum mqtt_auth_reason_code reason_code ;
619+
620+ struct {
621+ /** MQTT 5.0, chapter 3.15.2.2.5 User Property. */
622+ struct mqtt_utf8_pair user_prop [CONFIG_MQTT_USER_PROPERTIES_MAX ];
623+
624+ /** MQTT 5.0, chapter 3.15.2.2.2 Authentication Method. */
625+ struct mqtt_utf8 auth_method ;
626+
627+ /** MQTT 5.0, chapter 3.15.2.2.3 Authentication Data. */
628+ struct mqtt_binstr auth_data ;
629+
630+ /** MQTT 5.0, chapter 3.15.2.2.4 Reason String. */
631+ struct mqtt_utf8 reason_string ;
632+
633+ /** Flags indicating whether given property was present in received packet. */
634+ struct {
635+ /** Authentication Method property was present. */
636+ bool has_auth_method ;
637+ /** Authentication Data property was present. */
638+ bool has_auth_data ;
639+ /** Reason String property was present. */
640+ bool has_reason_string ;
641+ /** User Property property was present. */
642+ bool has_user_prop ;
643+ } rx ;
644+ } prop ;
645+ };
646+ #endif /* CONFIG_MQTT_VERSION_5_0 */
647+
605648/**
606649 * @brief Defines event parameters notified along with asynchronous events
607650 * to the application.
@@ -639,6 +682,9 @@ union mqtt_evt_param {
639682#if defined(CONFIG_MQTT_VERSION_5_0 )
640683 /** Parameters accompanying MQTT_EVT_DISCONNECT event. */
641684 struct mqtt_disconnect_param disconnect ;
685+
686+ /** Parameters accompanying MQTT_EVT_AUTH event. */
687+ struct mqtt_auth_param auth ;
642688#endif /* CONFIG_MQTT_VERSION_5_0 */
643689};
644690
@@ -1117,6 +1163,20 @@ int mqtt_ping(struct mqtt_client *client);
11171163int mqtt_disconnect (struct mqtt_client * client ,
11181164 const struct mqtt_disconnect_param * param );
11191165
1166+ #if defined(CONFIG_MQTT_VERSION_5_0 )
1167+ /**
1168+ * @brief API to send an authentication packet to the server.
1169+ *
1170+ * @param[in] client Client instance for which the procedure is requested.
1171+ * Shall not be NULL.
1172+ * @param[in] param Parameters to be used for the auth message.
1173+ * Shall not be NULL.
1174+ *
1175+ * @return 0 or a negative error code (errno.h) indicating reason of failure.
1176+ */
1177+ int mqtt_auth (struct mqtt_client * client , const struct mqtt_auth_param * param );
1178+ #endif /* CONFIG_MQTT_VERSION_5_0 */
1179+
11201180/**
11211181 * @brief API to abort MQTT connection. This will close the corresponding
11221182 * transport without closing the connection gracefully at the MQTT level
0 commit comments