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