1 /**************************************************************************/ 2 /* */ 3 /* Copyright (c) Microsoft Corporation. All rights reserved. */ 4 /* */ 5 /* This software is licensed under the Microsoft Software License */ 6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */ 7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ 8 /* and in the root directory of this software. */ 9 /* */ 10 /**************************************************************************/ 11 12 13 /**************************************************************************/ 14 /**************************************************************************/ 15 /** */ 16 /** NetX Component */ 17 /** */ 18 /** MQTT (MQTT) */ 19 /** */ 20 /**************************************************************************/ 21 /**************************************************************************/ 22 23 24 /**************************************************************************/ 25 /* */ 26 /* APPLICATION INTERFACE DEFINITION RELEASE */ 27 /* */ 28 /* nxd_mqtt_client.h PORTABLE C */ 29 /* 6.2.0 */ 30 /* AUTHOR */ 31 /* */ 32 /* Yuxin Zhou, Microsoft Corporation */ 33 /* */ 34 /* DESCRIPTION */ 35 /* */ 36 /* This file defines the NetX MQTT Client component, including all */ 37 /* data types and external references. It is assumed that nx_api.h */ 38 /* and nx_port.h have already been included. */ 39 /* */ 40 /* RELEASE HISTORY */ 41 /* */ 42 /* DATE NAME DESCRIPTION */ 43 /* */ 44 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ 45 /* 09-30-2020 Yuxin Zhou Modified comment(s), and */ 46 /* added ack receive notify, */ 47 /* resulting in version 6.1 */ 48 /* 11-09-2020 Yuxin Zhou Modified comment(s), and */ 49 /* added packet id parameter, */ 50 /* resulting in version 6.1.2 */ 51 /* 08-02-2021 Yuxin Zhou Modified comment(s), and */ 52 /* supported maximum transmit */ 53 /* queue depth, */ 54 /* resulting in version 6.1.8 */ 55 /* 10-15-2021 Yuxin Zhou Modified comment(s), included */ 56 /* necessary header file, */ 57 /* resulting in version 6.1.9 */ 58 /* 10-31-2022 Bo Chen Modified comment(s), supported*/ 59 /* mqtt over websocket, */ 60 /* resulting in version 6.2.0 */ 61 /* */ 62 /**************************************************************************/ 63 64 #ifndef _NXD_MQTT_CLIENT_H_ 65 #define _NXD_MQTT_CLIENT_H_ 66 67 /* Determine if a C++ compiler is being used. If so, ensure that standard 68 C is used to process the API information. */ 69 70 #ifdef __cplusplus 71 72 /* Yes, C++ compiler is present. Use standard C. */ 73 extern "C" { 74 75 #endif 76 77 #include "nx_api.h" 78 79 #ifdef NX_SECURE_ENABLE 80 #include "nx_secure_tls_api.h" 81 #endif /* NX_SECURE_ENABLE */ 82 83 #ifdef NXD_MQTT_CLOUD_ENABLE 84 #include "nx_cloud.h" 85 #endif /* NXD_MQTT_CLOUD_ENABLE */ 86 87 #ifdef NXD_MQTT_REQUIRE_TLS 88 #ifndef NX_SECURE_ENABLE 89 #error "The feature NXD_MQTT_REQUIRE_TLS requires NX_SECURE_ENABLE." 90 #endif /* NX_SECURE_ENABLE */ 91 #endif /* NXD_MQTT_REQUIRE_TLS */ 92 93 #ifdef NXD_MQTT_OVER_WEBSOCKET 94 #include "nx_websocket_client.h" 95 #endif /* NXD_MQTT_OVER_WEBSOCKET */ 96 97 /* Defined, MQTT transmit queue depth is enabled. It must be positive integer. */ 98 /* 99 #define NXD_MQTT_MAXIMUM_TRANSMIT_QUEUE_DEPTH 20 100 */ 101 102 /* Define MQTT protocol for websocket. */ 103 #define NXD_MQTT_OVER_WEBSOCKET_PROTOCOL "mqtt" 104 105 /* Define memcpy, memset and memcmp functions used internal. */ 106 #ifndef NXD_MQTT_SECURE_MEMCPY 107 #define NXD_MQTT_SECURE_MEMCPY memcpy 108 #endif /* NXD_MQTT_SECURE_MEMCPY */ 109 110 #ifndef NXD_MQTT_SECURE_MEMCMP 111 #define NXD_MQTT_SECURE_MEMCMP memcmp 112 #endif /* NXD_MQTT_SECURE_MEMCMP */ 113 114 #ifndef NXD_MQTT_SECURE_MEMSET 115 #define NXD_MQTT_SECURE_MEMSET memset 116 #endif /* NXD_SECURE_MEMSET */ 117 118 #ifndef NXD_MQTT_SECURE_MEMMOVE 119 #define NXD_MQTT_SECURE_MEMMOVE memmove 120 #endif /* NXD_MQTT_SECURE_MEMMOVE */ 121 122 /* Define the default MQTT Non-TLS (Non-secure) port number */ 123 #define NXD_MQTT_PORT 1883 124 125 126 /* Define the default TCP socket window size. */ 127 #ifndef NXD_MQTT_CLIENT_SOCKET_WINDOW_SIZE 128 #define NXD_MQTT_CLIENT_SOCKET_WINDOW_SIZE 8192 129 #endif /* NXD_MQTT_CLIENT_SOCKET_WINDOW_SIZE */ 130 131 /* Define the default MQTT Thread time slice. */ 132 #ifndef NXD_MQTT_CLIENT_THREAD_TIME_SLICE 133 #define NXD_MQTT_CLIENT_THREAD_TIME_SLICE 2 134 #endif 135 136 /* Set the default timer rate for the keepalive timer, in ThreadX timer ticks. 137 THe default is one second. */ 138 #ifndef NXD_MQTT_KEEPALIVE_TIMER_RATE 139 #define NXD_MQTT_KEEPALIVE_TIMER_RATE (NX_IP_PERIODIC_RATE) 140 #endif 141 142 /* Set the default timeout for PING response. */ 143 /* After sending out the MQTT Ping Request, if the client does not receive Ping Response within this 144 time, the client shall disconnect from the server. The default is one second. */ 145 #ifndef NXD_MQTT_PING_TIMEOUT_DELAY 146 #define NXD_MQTT_PING_TIMEOUT_DELAY (NX_IP_PERIODIC_RATE) 147 #endif 148 149 150 /* Deprecated. This symbol is defined for compatibility. */ 151 #ifndef NXD_MQTT_MAX_TOPIC_NAME_LENGTH 152 #define NXD_MQTT_MAX_TOPIC_NAME_LENGTH 12 153 #endif 154 155 /* Deprecated. This symbol is defined for compatibility. */ 156 #ifndef NXD_MQTT_MAX_MESSAGE_LENGTH 157 #define NXD_MQTT_MAX_MESSAGE_LENGTH 32 158 #endif 159 160 #ifndef NXD_MQTT_INITIAL_PACKET_ID_VALUE 161 #define NXD_MQTT_INITIAL_PACKET_ID_VALUE 1 162 #endif 163 164 /* Set a timeout for socket operations (send, receive, disconnect). */ 165 #ifndef NXD_MQTT_SOCKET_TIMEOUT 166 #define NXD_MQTT_SOCKET_TIMEOUT NX_WAIT_FOREVER 167 #endif 168 169 /* Define the default MQTT TLS (secure) port number */ 170 #define NXD_MQTT_TLS_PORT 8883 171 172 /* Define the default MQTT TLS (secure) over WebSocket port number */ 173 #define NXD_MQTT_OVER_WEBSOCKET_TLS_PORT 443 174 175 176 #define MQTT_PROTOCOL_LEVEL 4 177 178 /* Define bit fields and constant values used in the CONNECT packet. */ 179 #define MQTT_CONNECT_FLAGS_USERNAME (1 << 7) 180 #define MQTT_CONNECT_FLAGS_PASSWORD (1 << 6) 181 #define MQTT_CONNECT_FLAGS_WILL_RETAIN (1 << 5) 182 #define MQTT_CONNECT_FLAGS_WILL_QOS_0 0 183 #define MQTT_CONNECT_FLAGS_WILL_QOS_1 (1 << 3) 184 #define MQTT_CONNECT_FLAGS_WILL_QOS_2 (2 << 3) 185 #define MQTT_CONNECT_FLAGS_WILL_FLAG (1 << 2) 186 #define MQTT_CONNECT_FLAGS_CLEAN_SESSION (1 << 1) 187 #define MQTT_CONNECT_FLAGS_WILL_QOS_FIELD (3 << 3) 188 189 /* Define bit fields and constant values used in the CONNACK packet. */ 190 #define MQTT_CONNACK_CONNECT_FLAGS_SP (1) 191 #define MQTT_CONNACK_CONNECT_RETURN_CODE_ACCEPTED (0) 192 #define MQTT_CONNACK_CONNECT_RETURN_CODE_UNACCEPTABLE_PROTOCOL_VERSION (1) 193 #define MQTT_CONNACK_CONNECT_RETURN_CODE_IDENTIFIER_REJECTED (2) 194 #define MQTT_CONNACK_CONNECT_RETURN_CODE_SERVER_UNAVAILABLE (3) 195 #define MQTT_CONNACK_CONNECT_RETURN_CODE_BAD_USERNAME_PASSWORD (4) 196 #define MQTT_CONNACK_CONNECT_RETURN_CODE_NOT_AUTHORIZED (5) 197 198 /* Define bit fields and constant values used in the PUBLISH packet. */ 199 #define MQTT_PUBLISH_DUP_FLAG (1 << 3) 200 #define MQTT_PUBLISH_QOS_LEVEL_0 (0) 201 #define MQTT_PUBLISH_QOS_LEVEL_1 (1 << 1) 202 #define MQTT_PUBLISH_QOS_LEVEL_2 (2 << 1) 203 #define MQTT_PUBLISH_QOS_LEVEL_FIELD (3 << 1) 204 #define MQTT_PUBLISH_RETAIN (1) 205 206 #define MQTT_CONTROL_PACKET_TYPE_FIELD 0xF0 207 208 #define MQTT_FIXED_HEADER_SIZE 2 209 210 211 #define MQTT_CONTROL_PACKET_TYPE_CONNECT (1) 212 #define MQTT_CONTROL_PACKET_TYPE_CONNACK (2) 213 #define MQTT_CONTROL_PACKET_TYPE_PUBLISH (3) 214 #define MQTT_CONTROL_PACKET_TYPE_PUBACK (4) 215 #define MQTT_CONTROL_PACKET_TYPE_PUBREC (5) 216 #define MQTT_CONTROL_PACKET_TYPE_PUBREL (6) 217 #define MQTT_CONTROL_PACKET_TYPE_PUBCOMP (7) 218 #define MQTT_CONTROL_PACKET_TYPE_SUBSCRIBE (8) 219 #define MQTT_CONTROL_PACKET_TYPE_SUBACK (9) 220 #define MQTT_CONTROL_PACKET_TYPE_UNSUBSCRIBE (10) 221 #define MQTT_CONTROL_PACKET_TYPE_UNSUBACK (11) 222 #define MQTT_CONTROL_PACKET_TYPE_PINGREQ (12) 223 #define MQTT_CONTROL_PACKET_TYPE_PINGRESP (13) 224 #define MQTT_CONTROL_PACKET_TYPE_DISCONNECT (14) 225 /* Determine if a C++ compiler is being used. If so, complete the standard 226 C conditional started above. */ 227 228 229 typedef struct MQTT_PACKET_CONNACK_STRUCT 230 { 231 232 UCHAR mqtt_connack_packet_header; 233 UCHAR mqtt_connack_packet_remaining_length; 234 UCHAR mqtt_connack_packet_ack_flags; 235 UCHAR mqtt_connack_packet_return_code; 236 } MQTT_PACKET_CONNACK; 237 238 typedef struct MQTT_PACKET_PUBLISH_STRUCT 239 { 240 UCHAR mqtt_publish_packet_header; 241 UCHAR mqtt_publish_packet_remaining_length; 242 } MQTT_PACKET_PUBLISH; 243 244 typedef struct MQTT_PACKET_PUBLISH_RESPONSE_STRUCT 245 { 246 UCHAR mqtt_publish_response_packet_header; 247 UCHAR mqtt_publish_response_packet_remaining_length; 248 UCHAR mqtt_publish_response_packet_packet_identifier_msb; 249 UCHAR mqtt_publish_response_packet_packet_identifier_lsb; 250 } MQTT_PACKET_PUBLISH_RESPONSE; 251 252 253 typedef struct MQTT_PACKET_SUBSCRIBE_STRUCT 254 { 255 UCHAR mqtt_subscribe_packet_header; 256 UCHAR mqtt_subscribe_packet_remaining_length; 257 UCHAR mqtt_subscribe_packet_packet_identifier_msb; 258 UCHAR mqtt_subscribe_packet_packet_identifier_lsb; 259 } MQTT_PACKET_SUBSCRIBE; 260 261 typedef struct MQTT_PACKET_PING_STRUCT 262 { 263 UCHAR mqtt_ping_packet_header; 264 UCHAR mqtt_ping_packet_remaining_length; 265 } MQTT_PACKET_PING; 266 267 typedef struct MQTT_PACKET_DISCONNECT_STRUCT 268 { 269 UCHAR mqtt_disconnect_packet_header; 270 UCHAR mqtt_disconnect_packet_remaining_length; 271 } MQTT_PACKET_DISCONNECT; 272 273 274 /* Define the NetX MQTT CLIENT ID. */ 275 #define NXD_MQTT_CLIENT_ID 0x4D515454 276 277 /* Define the default MQTT Non-TLS (Non-secure) port number */ 278 #define NXD_MQTT_CLIENT_NONTLS_PORT 1883 279 280 /* Define the default MQTT TLS (secure) port number */ 281 #define NXD_MQTT_CLIENT_TLS_PORT 8883 282 283 284 #define NXD_MQTT_CLIENT_STATE_INITIALIZE 0 285 #define NXD_MQTT_CLIENT_STATE_IDLE 1 286 #define NXD_MQTT_CLIENT_STATE_CONNECTING 2 287 #define NXD_MQTT_CLIENT_STATE_CONNECTED 3 288 289 290 #define NXD_MQTT_SUCCESS 0x0 291 #define NXD_MQTT_ALREADY_CONNECTED 0x10001 292 #define NXD_MQTT_NOT_CONNECTED 0x10002 293 #define NXD_MQTT_MUTEX_FAILURE 0x10003 294 #define NXD_MQTT_INTERNAL_ERROR 0x10004 295 #define NXD_MQTT_CONNECT_FAILURE 0x10005 296 #define NXD_MQTT_PACKET_POOL_FAILURE 0x10006 297 #define NXD_MQTT_COMMUNICATION_FAILURE 0x10007 298 #define NXD_MQTT_SERVER_MESSAGE_FAILURE 0x10008 299 #define NXD_MQTT_INVALID_PARAMETER 0x10009 300 #define NXD_MQTT_NO_MESSAGE 0x1000A 301 #define NXD_MQTT_PACKET_POOL_EMPTY 0x1000B 302 #define NXD_MQTT_QOS2_NOT_SUPPORTED 0x1000C 303 #define NXD_MQTT_INSUFFICIENT_BUFFER_SPACE 0x1000D 304 #define NXD_MQTT_CLIENT_NOT_RUNNING 0x1000E 305 #define NXD_MQTT_INVALID_PACKET 0x1000F 306 #define NXD_MQTT_PARTIAL_PACKET 0x10010 307 #define NXD_MQTT_CONNECTING 0x10011 308 #define NXD_MQTT_INVALID_STATE 0x10012 309 310 /* The following error codes match the Connect Return code in CONNACK message. */ 311 #define NXD_MQTT_ERROR_CONNECT_RETURN_CODE 0x10080 312 #define NXD_MQTT_ERROR_UNACCEPTABLE_PROTOCOL 0x10081 313 #define NXD_MQTT_ERROR_IDENTIFYIER_REJECTED 0x10082 314 #define NXD_MQTT_ERROR_SERVER_UNAVAILABLE 0x10083 315 #define NXD_MQTT_ERROR_BAD_USERNAME_PASSWORD 0x10084 316 #define NXD_MQTT_ERROR_NOT_AUTHORIZED 0x10085 317 318 319 /* Define the basic MQTT Client control block. */ 320 typedef struct NXD_MQTT_CLIENT_STRUCT 321 { 322 CHAR *nxd_mqtt_client_name; 323 CHAR *nxd_mqtt_client_id; 324 UINT nxd_mqtt_client_id_length; 325 CHAR *nxd_mqtt_client_username; 326 USHORT nxd_mqtt_client_username_length; 327 CHAR *nxd_mqtt_client_password; 328 USHORT nxd_mqtt_client_password_length; 329 UCHAR nxd_mqtt_client_will_qos_retain; 330 const UCHAR *nxd_mqtt_client_will_topic; 331 UINT nxd_mqtt_client_will_topic_length; 332 const UCHAR *nxd_mqtt_client_will_message; 333 UINT nxd_mqtt_client_will_message_length; 334 NX_IP *nxd_mqtt_client_ip_ptr; /* Pointer to associated IP structure */ 335 NX_PACKET_POOL *nxd_mqtt_client_packet_pool_ptr; /* Pointer to client packet pool */ 336 TX_MUTEX *nxd_mqtt_client_mutex_ptr; /* Pointer to client mutex */ 337 TX_TIMER nxd_mqtt_timer; 338 #ifndef NXD_MQTT_CLOUD_ENABLE 339 TX_MUTEX nxd_mqtt_protection; 340 TX_THREAD nxd_mqtt_thread; 341 TX_EVENT_FLAGS_GROUP nxd_mqtt_events; 342 #else 343 NX_CLOUD *nxd_mqtt_client_cloud_ptr; /* Pointer to associated CLOUD structure. */ 344 NX_CLOUD nxd_mqtt_client_cloud; /* MQTT cloud. */ 345 NX_CLOUD_MODULE nxd_mqtt_client_cloud_module; /* Define mqtt module that running on cloud helper thread. */ 346 #endif /* NXD_MQTT_CLOUD_ENABLE */ 347 UINT nxd_mqtt_ping_timeout; 348 UINT nxd_mqtt_ping_not_responded; /* Flag indicating the ping has been responded or not. */ 349 UINT nxd_mqtt_ping_sent_time; /* TX Timer tick when the ping message was sent. */ 350 UINT nxd_mqtt_timeout; /* TX Timer tick when the next timeout happens. */ 351 UINT nxd_mqtt_timer_value; /* MQTT Client periodic timer tick value. */ 352 UINT nxd_mqtt_keepalive; /* Keepalive value, converted to TX ticks. */ 353 UINT nxd_mqtt_clean_session; /* Clean session flag. */ 354 UINT nxd_mqtt_client_state; /* Record client state */ 355 NX_TCP_SOCKET nxd_mqtt_client_socket; 356 struct NXD_MQTT_CLIENT_STRUCT *nxd_mqtt_client_next; 357 UINT nxd_mqtt_client_packet_identifier; 358 NX_PACKET *nxd_mqtt_client_processing_packet; 359 NX_PACKET *message_transmit_queue_head; 360 NX_PACKET *message_transmit_queue_tail; 361 #ifdef NXD_MQTT_MAXIMUM_TRANSMIT_QUEUE_DEPTH 362 UINT message_transmit_queue_depth; 363 #endif /* NXD_MQTT_MAXIMUM_TRANSMIT_QUEUE_DEPTH */ 364 NX_PACKET *message_receive_queue_head; 365 NX_PACKET *message_receive_queue_tail; 366 UINT message_receive_queue_depth; 367 VOID (*nxd_mqtt_client_receive_notify)(struct NXD_MQTT_CLIENT_STRUCT *client_ptr, UINT number_of_messages); 368 VOID (*nxd_mqtt_connect_notify)(struct NXD_MQTT_CLIENT_STRUCT *client_ptr, UINT status, VOID *context); 369 VOID *nxd_mqtt_connect_context; 370 VOID (*nxd_mqtt_disconnect_notify)(struct NXD_MQTT_CLIENT_STRUCT *client_ptr); 371 UINT (*nxd_mqtt_packet_receive_notify)(struct NXD_MQTT_CLIENT_STRUCT *client_ptr, NX_PACKET *packet_ptr, VOID *context); 372 VOID *nxd_mqtt_packet_receive_context; 373 VOID (*nxd_mqtt_ack_receive_notify)(struct NXD_MQTT_CLIENT_STRUCT *client_ptr, UINT type, USHORT packet_id, NX_PACKET *transmit_packet_ptr, VOID *context); 374 VOID *nxd_mqtt_ack_receive_context; 375 #ifdef NX_SECURE_ENABLE 376 UINT nxd_mqtt_client_use_tls; 377 UINT (*nxd_mqtt_tls_setup)(struct NXD_MQTT_CLIENT_STRUCT *, NX_SECURE_TLS_SESSION *, 378 NX_SECURE_X509_CERT *, NX_SECURE_X509_CERT *); 379 NX_SECURE_X509_CERT nxd_mqtt_tls_certificate; 380 NX_SECURE_X509_CERT nxd_mqtt_tls_trusted_certificate; 381 NX_SECURE_TLS_SESSION nxd_mqtt_tls_session; 382 UINT nxd_mqtt_tls_in_progress; 383 #endif 384 #ifdef NXD_MQTT_OVER_WEBSOCKET 385 UINT nxd_mqtt_client_use_websocket; 386 NX_WEBSOCKET_CLIENT nxd_mqtt_client_websocket; 387 UCHAR *nxd_mqtt_client_websocket_host; 388 UINT nxd_mqtt_client_websocket_host_length; 389 UCHAR *nxd_mqtt_client_websocket_uri_path; 390 UINT nxd_mqtt_client_websocket_uri_path_length; 391 #endif /* NXD_MQTT_OVER_WEBSOCKET */ 392 } NXD_MQTT_CLIENT; 393 394 395 396 #ifndef NXD_MQTT_CLIENT_SOURCE_CODE 397 398 /* Application caller is present, perform API mapping. */ 399 400 /* Determine if error checking is desired. If so, map API functions 401 to the appropriate error checking front-ends. Otherwise, map API 402 functions to the core functions that actually perform the work. 403 Note: error checking is enabled by default. */ 404 405 #ifdef NX_DISABLE_ERROR_CHECKING 406 407 #define nxd_mqtt_client_create _nxd_mqtt_client_create 408 #define nxd_mqtt_client_login_set _nxd_mqtt_client_login_set 409 #define nxd_mqtt_client_will_message_set _nxd_mqtt_client_will_message_set 410 #define nxd_mqtt_client_delete _nxd_mqtt_client_delete 411 #define nxd_mqtt_client_connect _nxd_mqtt_client_connect 412 #define nxd_mqtt_client_secure_connect _nxd_mqtt_client_secure_connect 413 #define nxd_mqtt_client_publish _nxd_mqtt_client_publish 414 #define nxd_mqtt_client_subscribe _nxd_mqtt_client_subscribe 415 #define nxd_mqtt_client_unsubscribe _nxd_mqtt_client_unsubscribe 416 #define nxd_mqtt_client_disconnect _nxd_mqtt_client_disconnect 417 #define nxd_mqtt_client_receive_notify_set _nxd_mqtt_client_receive_notify_set 418 #define nxd_mqtt_client_message_get _nxd_mqtt_client_message_get 419 #define nxd_mqtt_client_disconnect_notify_set _nxd_mqtt_client_disconnect_notify_set 420 #ifdef NXD_MQTT_OVER_WEBSOCKET 421 #define nxd_mqtt_client_websocket_set _nxd_mqtt_client_websocket_set 422 #endif /* NXD_MQTT_OVER_WEBSOCKET */ 423 #else /* if !NXD_MQTT_CLIENT_SOURCE_CODE */ 424 425 #define nxd_mqtt_client_create _nxde_mqtt_client_create 426 #define nxd_mqtt_client_login_set _nxde_mqtt_client_login_set 427 #define nxd_mqtt_client_will_message_set _nxde_mqtt_client_will_message_set 428 #define nxd_mqtt_client_delete _nxde_mqtt_client_delete 429 #define nxd_mqtt_client_connect _nxde_mqtt_client_connect 430 #define nxd_mqtt_client_secure_connect _nxde_mqtt_client_secure_connect 431 #define nxd_mqtt_client_publish _nxde_mqtt_client_publish 432 #define nxd_mqtt_client_subscribe _nxde_mqtt_client_subscribe 433 #define nxd_mqtt_client_unsubscribe _nxde_mqtt_client_unsubscribe 434 #define nxd_mqtt_client_disconnect _nxde_mqtt_client_disconnect 435 #define nxd_mqtt_client_receive_notify_set _nxde_mqtt_client_receive_notify_set 436 #define nxd_mqtt_client_message_get _nxde_mqtt_client_message_get 437 #define nxd_mqtt_client_disconnect_notify_set _nxde_mqtt_client_disconnect_notify_set 438 #ifdef NXD_MQTT_OVER_WEBSOCKET 439 #define nxd_mqtt_client_websocket_set _nxde_mqtt_client_websocket_set 440 #endif /* NXD_MQTT_OVER_WEBSOCKET */ 441 #endif /* NX_DISABLE_ERROR_CHECKING */ 442 443 444 UINT nxd_mqtt_client_create(NXD_MQTT_CLIENT *client_ptr, CHAR *client_name, CHAR *client_id, UINT client_id_length, 445 NX_IP *ip_ptr, NX_PACKET_POOL *pool_ptr, VOID *stack_ptr, ULONG stack_size, UINT mqtt_thread_priority, 446 VOID *memory_ptr, ULONG memory_size); 447 448 UINT nxd_mqtt_client_connect(NXD_MQTT_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port, 449 UINT keepalive, UINT clean_session, ULONG timeout); 450 451 UINT nxd_mqtt_client_login_set(NXD_MQTT_CLIENT *client_ptr, 452 CHAR *username, UINT username_length, CHAR *password, UINT password_length); 453 454 UINT nxd_mqtt_client_will_message_set(NXD_MQTT_CLIENT *client_ptr, 455 const UCHAR *will_topic, UINT will_topic_length, UCHAR *will_message, UINT will_message_length, 456 UINT will_retain_flag, UINT will_QoS); 457 #ifdef NX_SECURE_ENABLE 458 UINT nxd_mqtt_client_secure_connect(NXD_MQTT_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port, 459 UINT (*tls_setup)(NXD_MQTT_CLIENT *client_ptr, NX_SECURE_TLS_SESSION *, NX_SECURE_X509_CERT *, NX_SECURE_X509_CERT *), 460 UINT keepalive, UINT clean_session, ULONG timeout); 461 #endif /* NX_SECURE_ENABLE */ 462 UINT nxd_mqtt_client_publish(NXD_MQTT_CLIENT *client_ptr, CHAR *topic_name, UINT topic_name_length, CHAR *message, UINT message_length, 463 UINT retain, UINT QoS, ULONG timeout); 464 UINT nxd_mqtt_client_subscribe(NXD_MQTT_CLIENT *mqtt_client_pr, CHAR *topic_name, UINT topic_name_length, UINT QoS); 465 UINT nxd_mqtt_client_unsubscribe(NXD_MQTT_CLIENT *mqtt_client_pr, CHAR *topic_name, UINT topic_name_length); 466 UINT nxd_mqtt_client_receive_notify_set(NXD_MQTT_CLIENT *client_ptr, 467 VOID (*receive_notify)(NXD_MQTT_CLIENT *client_ptr, UINT number_of_messages)); 468 UINT nxd_mqtt_client_message_get(NXD_MQTT_CLIENT *client_ptr, UCHAR *topic_buffer, UINT topic_buffer_size, UINT *actual_topic_length, 469 UCHAR *message_buffer, UINT message_buffer_size, UINT *actual_message_length); 470 UINT nxd_mqtt_client_disconnect(NXD_MQTT_CLIENT *client_ptr); 471 472 UINT nxd_mqtt_client_delete(NXD_MQTT_CLIENT *client_ptr); 473 UINT nxd_mqtt_client_disconnect_notify_set(NXD_MQTT_CLIENT *client_ptr, VOID (*disconnect_notify)(NXD_MQTT_CLIENT *)); 474 #ifdef NXD_MQTT_OVER_WEBSOCKET 475 UINT nxd_mqtt_client_websocket_set(NXD_MQTT_CLIENT *client_ptr, UCHAR *host, UINT host_length, UCHAR *uri_path, UINT uri_path_length); 476 #endif /* NXD_MQTT_OVER_WEBSOCKET */ 477 478 #else /* ifdef NXD_MQTT_CLIENT_SOURCE_CODE */ 479 480 UINT _nxd_mqtt_client_connect(NXD_MQTT_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port, 481 UINT keepalive, UINT clean_session, ULONG wait_option); 482 UINT _nxd_mqtt_client_create(NXD_MQTT_CLIENT *client_ptr, CHAR *client_name, 483 CHAR *client_id, UINT client_id_length, 484 NX_IP *ip_ptr, NX_PACKET_POOL *pool_ptr, 485 VOID *stack_ptr, ULONG stack_size, UINT mqtt_thread_priority, 486 VOID *memory_ptr, ULONG memory_size); 487 UINT _nxd_mqtt_client_delete(NXD_MQTT_CLIENT *client_ptr); 488 UINT _nxd_mqtt_client_disconnect(NXD_MQTT_CLIENT *client_ptr); 489 UINT _nxd_mqtt_client_disconnect_notify_set(NXD_MQTT_CLIENT *client_ptr, VOID (*disconnect_notify)(NXD_MQTT_CLIENT *)); 490 UINT _nxd_mqtt_client_login_set(NXD_MQTT_CLIENT *client_ptr, 491 CHAR *username, UINT username_length, CHAR *password, UINT password_length); 492 UINT _nxd_mqtt_client_message_get(NXD_MQTT_CLIENT *client_ptr, UCHAR *topic_buffer, UINT topic_buffer_size, UINT *actual_topic_length, 493 UCHAR *message_buffer, UINT message_buffer_size, UINT *actual_message_length); 494 UINT _nxd_mqtt_client_publish_packet_send(NXD_MQTT_CLIENT *client_ptr, NX_PACKET *packet_ptr, 495 USHORT packet_id, UINT QoS, ULONG wait_option); 496 UINT _nxd_mqtt_client_publish(NXD_MQTT_CLIENT *client_ptr, CHAR *topic_name, UINT topic_name_length, 497 CHAR *message, UINT message_length, UINT retain, UINT QoS, ULONG timeout); 498 UINT _nxd_mqtt_client_receive_notify_set(NXD_MQTT_CLIENT *client_ptr, 499 VOID (*receive_notify)(NXD_MQTT_CLIENT *client_ptr, UINT message_count)); 500 UINT _nxd_mqtt_client_release_callback_set(NXD_MQTT_CLIENT *client_ptr, VOID (*memory_release_function)(CHAR *, UINT)); 501 UINT _nxd_mqtt_client_sub_unsub(NXD_MQTT_CLIENT *client_ptr, UINT op, 502 CHAR *topic_name, UINT topic_name_length, USHORT *packet_id_ptr, UINT QoS); 503 UINT _nxd_mqtt_client_subscribe(NXD_MQTT_CLIENT *client_ptr, CHAR *topic_name, UINT topic_name_length, UINT QoS); 504 UINT _nxd_mqtt_client_unsubscribe(NXD_MQTT_CLIENT *client_ptr, CHAR *topic_name, UINT topic_name_length); 505 UINT _nxd_mqtt_client_will_message_set(NXD_MQTT_CLIENT *client_ptr, 506 const UCHAR *will_topic, UINT will_topic_length, const UCHAR *will_message, 507 UINT will_message_length, UINT will_retain_flag, UINT will_QoS); 508 UINT _nxd_mqtt_read_remaining_length(NX_PACKET *packet_ptr, UINT *remaining_length, ULONG *offset_ptr); 509 UINT _nxd_mqtt_client_set_fixed_header(NXD_MQTT_CLIENT *client_ptr, NX_PACKET *packet_ptr, UCHAR control_header, UINT length, UINT wait_option); 510 UINT _nxd_mqtt_client_append_message(NXD_MQTT_CLIENT *client_ptr, NX_PACKET *packet_ptr, CHAR *message, UINT length, ULONG wait_option); 511 VOID _nxd_mqtt_client_connection_end(NXD_MQTT_CLIENT *client_ptr, ULONG wait_option); 512 UINT _nxd_mqtt_process_publish_packet(NX_PACKET *packet_ptr, ULONG *topic_offset_ptr, USHORT *topic_length_ptr, 513 ULONG *message_offset_ptr, ULONG *message_length_ptr); 514 515 UINT _nxde_mqtt_client_connect(NXD_MQTT_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port, 516 UINT keepalive, UINT clean_session, ULONG timeout); 517 UINT _nxde_mqtt_client_create(NXD_MQTT_CLIENT *client_ptr, CHAR *client_name, CHAR *client_id, UINT client_id_length, 518 NX_IP *ip_ptr, NX_PACKET_POOL *pool_ptr, 519 VOID *stack_ptr, ULONG stack_size, UINT mqtt_thread_priority, 520 VOID *memory_ptr, ULONG memory_size); 521 UINT _nxde_mqtt_client_delete(NXD_MQTT_CLIENT *client_ptr); 522 UINT _nxde_mqtt_client_disconnect_notify_set(NXD_MQTT_CLIENT *client_ptr, VOID (*disconnect_notify)(NXD_MQTT_CLIENT *)); 523 UINT _nxde_mqtt_client_disconnect(NXD_MQTT_CLIENT *client_ptr); 524 UINT _nxde_mqtt_client_login_set(NXD_MQTT_CLIENT *client_ptr, 525 CHAR *username, UINT username_length, CHAR *password, UINT password_length); 526 UINT _nxde_mqtt_client_message_get(NXD_MQTT_CLIENT *client_ptr, UCHAR *topic_buffer, UINT topic_buffer_size, UINT *actual_topic_length, 527 UCHAR *message_buffer, UINT message_buffer_size, UINT *actual_message_length); 528 UINT _nxde_mqtt_client_publish(NXD_MQTT_CLIENT *client_ptr, CHAR *topic_name, UINT topic_name_length, 529 CHAR *message, UINT message_length, UINT retain, UINT QoS, ULONG timeout); 530 UINT _nxde_mqtt_client_receive_notify_set(NXD_MQTT_CLIENT *client_ptr, 531 VOID (*receive_notify)(NXD_MQTT_CLIENT *client_ptr, UINT message_count)); 532 UINT _nxde_mqtt_client_release_callback_set(NXD_MQTT_CLIENT *client_ptr, VOID (*release_callback)(CHAR *, UINT)); 533 UINT _nxde_mqtt_client_subscribe(NXD_MQTT_CLIENT *client_ptr, CHAR *topic_name, UINT topic_name_length, UINT QoS); 534 UINT _nxde_mqtt_client_unsubscribe(NXD_MQTT_CLIENT *client_ptr, CHAR *topic_name, UINT topic_name_length); 535 UINT _nxde_mqtt_client_will_message_set(NXD_MQTT_CLIENT *client_ptr, 536 const UCHAR *will_topic, UINT will_topic_length, const UCHAR *will_message, 537 UINT will_message_length, UINT will_retain_flag, UINT will_QoS); 538 539 #ifdef NX_SECURE_ENABLE 540 UINT _nxd_mqtt_client_secure_connect(NXD_MQTT_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port, 541 UINT (*tls_setup)(NXD_MQTT_CLIENT *client_ptr, NX_SECURE_TLS_SESSION *, 542 NX_SECURE_X509_CERT *, NX_SECURE_X509_CERT *), 543 UINT keepalive, UINT clean_session, ULONG wait_option); 544 UINT _nxde_mqtt_client_secure_connect(NXD_MQTT_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port, 545 UINT (*tls_setup)(NXD_MQTT_CLIENT *client_ptr, NX_SECURE_TLS_SESSION *, 546 NX_SECURE_X509_CERT *, NX_SECURE_X509_CERT *), 547 UINT keepalive, UINT clean_session, ULONG timeout); 548 #endif /* NX_SECURE_ENABLE */ 549 550 #ifdef NXD_MQTT_OVER_WEBSOCKET 551 UINT _nxd_mqtt_client_websocket_set(NXD_MQTT_CLIENT *client_ptr, UCHAR *host, UINT host_length, UCHAR *uri_path, UINT uri_path_length); 552 UINT _nxde_mqtt_client_websocket_set(NXD_MQTT_CLIENT *client_ptr, UCHAR *host, UINT host_length, UCHAR *uri_path, UINT uri_path_length); 553 VOID _nxd_mqtt_client_websocket_connection_status_callback(NX_WEBSOCKET_CLIENT *websocket_client_ptr, VOID *context, UINT status); 554 #endif /* NXD_MQTT_OVER_WEBSOCKET */ 555 556 #endif /* ifndef NXD_MQTT_CLIENT_SOURCE_CODE */ 557 558 #ifdef NXD_MQTT_CLOUD_ENABLE 559 /* MQTT create function based on cloud helper. */ 560 UINT _nxd_mqtt_client_cloud_create(NXD_MQTT_CLIENT *client_ptr, CHAR *client_name, 561 CHAR *client_id, UINT client_id_length, 562 NX_IP *ip_ptr, NX_PACKET_POOL *pool_ptr, NX_CLOUD *cloud_ptr); 563 #endif /* NXD_MQTT_CLOUD_ENABLE */ 564 565 /* Determine if a C++ compiler is being used. If so, complete the standard 566 C conditional started above. */ 567 #ifdef __cplusplus 568 } 569 #endif 570 571 572 #endif /* NXD_MQTT_CLIENT_H */ 573 574