|
| 1 | +/***************************************************************************/ /** |
| 2 | + * @file si91x_mqtt_client_types.h |
| 3 | + ******************************************************************************* |
| 4 | + * # License |
| 5 | + * <b>Copyright 2025 Silicon Laboratories Inc. www.silabs.com</b> |
| 6 | + ******************************************************************************* |
| 7 | + * |
| 8 | + * SPDX-License-Identifier: Zlib |
| 9 | + * |
| 10 | + * The licensor of this software is Silicon Laboratories Inc. |
| 11 | + * |
| 12 | + * This software is provided 'as-is', without any express or implied |
| 13 | + * warranty. In no event will the authors be held liable for any damages |
| 14 | + * arising from the use of this software. |
| 15 | + * |
| 16 | + * Permission is granted to anyone to use this software for any purpose, |
| 17 | + * including commercial applications, and to alter it and redistribute it |
| 18 | + * freely, subject to the following restrictions: |
| 19 | + * |
| 20 | + * 1. The origin of this software must not be misrepresented; you must not |
| 21 | + * claim that you wrote the original software. If you use this software |
| 22 | + * in a product, an acknowledgment in the product documentation would be |
| 23 | + * appreciated but is not required. |
| 24 | + * 2. Altered source versions must be plainly marked as such, and must not be |
| 25 | + * misrepresented as being the original software. |
| 26 | + * 3. This notice may not be removed or altered from any source distribution. |
| 27 | + * |
| 28 | + ******************************************************************************/ |
| 29 | + |
| 30 | +#pragma once |
| 31 | +#include "stdint.h" |
| 32 | +#include "sl_common.h" |
| 33 | + |
| 34 | +//Note: Please go through http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html |
| 35 | + |
| 36 | +#define SI91X_MQTT_CLIENT_TOPIC_MAXIMUM_LENGTH 202 // This size is including the NULL terminating character. |
| 37 | +#define SI91X_MQTT_CLIENT_WILL_TOPIC_MAXIMUM_LENGTH 202 // This size is including the NULL terminating character. |
| 38 | +#define SLI_SI91X_MQTT_CLIENT_MESSAGE_MAXIMUM_LENGTH 100 |
| 39 | + |
| 40 | +#define SLI_SI91X_MQTT_CLIENT_ID_MAXIMUM_LENGTH 62 // This size is including the NULL terminating character. |
| 41 | +#define SI91X_MQTT_CLIENT_USERNAME_MAXIMUM_LENGTH 122 // This size is including the NULL terminating character. |
| 42 | +#define SI91X_MQTT_CLIENT_PASSWORD_MAXIMUM_LENGTH 62 // This size is including the NULL terminating character. |
| 43 | + |
| 44 | +#define SLI_SI91X_MQTT_CLIENT_INIT_COMMAND 1 |
| 45 | +#define SLI_SI91X_MQTT_CLIENT_CONNECT_COMMAND 2 |
| 46 | +#define SLI_SI91X_MQTT_CLIENT_SUBSCRIBE_COMMAND 3 |
| 47 | +#define SLI_SI91X_MQTT_CLIENT_PUBLISH_COMMAND 4 |
| 48 | +#define SLI_SI91X_MQTT_CLIENT_UNSUBSCRIBE_COMMAND 5 |
| 49 | +#define SLI_SI91X_MQTT_CLIENT_DISCONNECT_COMMAND 8 |
| 50 | +#define SLI_SI91X_MQTT_CLIENT_DEINIT_COMMAND 9 |
| 51 | + |
| 52 | +#define SLI_SI91X_MQTT_CLIENT_TOPIC_DELIMITER "/" |
| 53 | +#define SLI_SI91X_MQTT_CLIENT_SINGLE_LEVEL_WILD_CARD "+" |
| 54 | +#define SLI_SI91X_MQTT_CLIENT_MULTI_LEVEL_WILD_CARD "#" |
| 55 | + |
| 56 | +typedef struct { |
| 57 | + // IP version |
| 58 | + uint32_t ip_version; |
| 59 | + union { |
| 60 | + uint8_t ipv4_address[4]; |
| 61 | + uint8_t ipv6_address[16]; |
| 62 | + } server_ip_address; |
| 63 | +} sli_si91x_mqtt_client_ip_address_t; |
| 64 | + |
| 65 | +typedef struct SL_ATTRIBUTE_PACKED { |
| 66 | + uint32_t command_type; |
| 67 | + // MQTT server IP address |
| 68 | + sli_si91x_mqtt_client_ip_address_t server_ip; |
| 69 | + // MQTT server port |
| 70 | + uint32_t server_port; |
| 71 | + // Client ID Length |
| 72 | + uint8_t client_id_len; |
| 73 | + // client ID, should be unique |
| 74 | + int8_t client_id[SLI_SI91X_MQTT_CLIENT_ID_MAXIMUM_LENGTH]; |
| 75 | + // keep alive interval (s) |
| 76 | + uint16_t keep_alive_interval; |
| 77 | + // username Length |
| 78 | + uint8_t username_len; |
| 79 | + // user name |
| 80 | + uint8_t user_name[SI91X_MQTT_CLIENT_USERNAME_MAXIMUM_LENGTH]; |
| 81 | + // password Length |
| 82 | + uint8_t password_len; |
| 83 | + // password |
| 84 | + uint8_t password[SI91X_MQTT_CLIENT_PASSWORD_MAXIMUM_LENGTH]; |
| 85 | + // clean session(0-1) |
| 86 | + uint8_t clean; |
| 87 | + // 0 : TCP , 1 : SSl |
| 88 | + uint8_t encrypt; |
| 89 | + // MQTT Client port |
| 90 | + uint32_t client_port; |
| 91 | +#if defined(SLI_SI917) || defined(SLI_SI915) |
| 92 | + //! Capping tcp retransmission timeout |
| 93 | + uint8_t tcp_max_retransmission_cap_for_emb_mqtt; |
| 94 | +#endif |
| 95 | + //! MQTT ping retries. |
| 96 | + uint16_t keep_alive_retries; |
| 97 | +} si91x_mqtt_client_init_request_t; |
| 98 | + |
| 99 | +typedef struct SL_ATTRIBUTE_PACKED { |
| 100 | + uint32_t command_type; |
| 101 | + // whether to use username (0-1) |
| 102 | + uint8_t is_username_present; |
| 103 | + // whether to use pwdFlag (0-1) |
| 104 | + uint8_t is_password_present; |
| 105 | + // whether to set willmsg (0-1) |
| 106 | + uint8_t will_flag; |
| 107 | + // retained flag(0-1) |
| 108 | + uint8_t will_retain; |
| 109 | + // message Qos(0-2) |
| 110 | + uint8_t will_qos; |
| 111 | + // length of topic |
| 112 | + uint8_t will_topic_len; |
| 113 | + // topic name of will |
| 114 | + uint8_t will_topic[SI91X_MQTT_CLIENT_WILL_TOPIC_MAXIMUM_LENGTH]; |
| 115 | + // Length of Will message |
| 116 | + uint8_t will_message_len; |
| 117 | + // message of will |
| 118 | + uint8_t will_msg[SLI_SI91X_MQTT_CLIENT_MESSAGE_MAXIMUM_LENGTH]; |
| 119 | + |
| 120 | +} sli_si91x_mqtt_client_connect_request_t; |
| 121 | + |
| 122 | +typedef struct SL_ATTRIBUTE_PACKED { |
| 123 | + uint32_t command_type; |
| 124 | + // length of TOPIC |
| 125 | + uint8_t topic_len; |
| 126 | + // topic of subscribe message |
| 127 | + int8_t topic[SI91X_MQTT_CLIENT_TOPIC_MAXIMUM_LENGTH]; |
| 128 | + // message Qos, can be 0, 1, or 2 |
| 129 | + int8_t qos; |
| 130 | + |
| 131 | +} sli_si91x_mqtt_client_subscribe_t; |
| 132 | + |
| 133 | +typedef struct SL_ATTRIBUTE_PACKED { |
| 134 | + uint32_t command_type; |
| 135 | + // length of TOPIC |
| 136 | + uint8_t topic_len; |
| 137 | + // topic of unsubscribe message |
| 138 | + uint8_t topic[SI91X_MQTT_CLIENT_TOPIC_MAXIMUM_LENGTH]; |
| 139 | + // message Qos, can be 0, 1, or 2 |
| 140 | + uint8_t qos; |
| 141 | + // retained flag, can be 0 or 1 |
| 142 | + uint8_t retained; |
| 143 | + // duplicate flag, can be 0 or 1 |
| 144 | + uint8_t dup; |
| 145 | + // length of publish message(option), if set to 0 or |
| 146 | + //omitted, <message> will be parsed in text format, else |
| 147 | + //hexidecimai format |
| 148 | + uint16_t msg_len; |
| 149 | + // publish message |
| 150 | + int8_t *msg; |
| 151 | + |
| 152 | +} sli_si91x_mqtt_client_publish_request_t; |
| 153 | + |
| 154 | +typedef struct SL_ATTRIBUTE_PACKED { |
| 155 | + uint32_t command_type; |
| 156 | + // length of TOPIC |
| 157 | + uint8_t topic_len; |
| 158 | + // topic of unsubscribe message |
| 159 | + uint8_t topic[SI91X_MQTT_CLIENT_TOPIC_MAXIMUM_LENGTH]; |
| 160 | + |
| 161 | +} sli_si91x_mqtt_client_unsubscribe_request_t; |
| 162 | + |
| 163 | +typedef struct { |
| 164 | + uint32_t command_type; |
| 165 | + |
| 166 | +} sli_si91x_mqtt_client_command_request_t; |
| 167 | + |
| 168 | +typedef struct SL_ATTRIBUTE_PACKED { |
| 169 | + uint16_t mqtt_flags; |
| 170 | + uint16_t current_chunk_length; |
| 171 | + uint16_t topic_length; |
| 172 | + uint8_t data[]; |
| 173 | +} sli_si91x_mqtt_client_received_message_t; |
0 commit comments