Skip to content

Commit ef4e9c4

Browse files
committed
wiseconnect: MQTT Network Stack Application protocol offloading APIs
Origin: Silicon Labs WiseConnect SDK License: Zlib URL: https://github.com/siliconlabs/wiseconnect Commit: 05ef77e82bb473fdf157d33fb9cbf6e1d9a11a9e Version: v3.5.0-rc3 Purpose: To support the SiWx917 MQTT Network Stack Application protocol offloading, we need to add the Silicon Labs APIs, so adding the corresponding source files and include files Signed-off-by: Rahul Gurram <[email protected]>
1 parent f31fcc1 commit ef4e9c4

File tree

6 files changed

+1988
-0
lines changed

6 files changed

+1988
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/***************************************************************************/ /**
2+
* @file si91x_mqtt_client_callback_framework.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+
32+
#include "sl_mqtt_client.h"
33+
#include "sl_mqtt_client_types.h"
34+
#include "sl_si91x_types.h"
35+
#include "sl_status.h"
36+
37+
/**
38+
* @addtogroup SERVICE_MQTT_TYPES
39+
* @{
40+
*/
41+
typedef struct {
42+
sl_mqtt_client_event_t event;
43+
sl_mqtt_client_t *client;
44+
void *user_context;
45+
void *sdk_data;
46+
} sl_si91x_mqtt_client_context_t;
47+
48+
sl_status_t sli_si91x_mqtt_event_handler(sl_status_t status,
49+
sl_si91x_mqtt_client_context_t *sdk_context,
50+
sl_wifi_packet_t *rx_packet);
51+
52+
/** @} */
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
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;
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/***************************************************************************/ /**
2+
* @file si91x_mqtt_client_utility.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+
32+
#include "si91x_mqtt_client_callback_framework.h"
33+
34+
/**
35+
* An internal helper function to build sl_mqtt_client_event_t in case an API is called in asynchronous mode.
36+
* @param event Event that needs to be stored in context.
37+
* @param client Client address that needs to be stored in context.
38+
* @param user_context user_context provided by user while calling API.
39+
* @param timeout timeout which determines if API needs to be executed in sync or async mode.
40+
* @param si91x_mqtt_client_context_t** A double pointer to client context.This function allocates memory and initializes members if timeout is greater than 0 else pointer is initialized with null.
41+
* @return return SL_STATUS_OK in case of success or appropriate status.
42+
*/
43+
sl_status_t sli_si91x_build_mqtt_sdk_context_if_async(sl_mqtt_client_event_t event,
44+
sl_mqtt_client_t *client,
45+
void *user_context,
46+
void *sdk_data,
47+
uint32_t timeout,
48+
sl_si91x_mqtt_client_context_t **context);
49+
50+
/**
51+
* An internal helper function to get current mqtt client.
52+
* @param client current mqtt client
53+
*
54+
* Note: client would be NULL if this function is called before sl_mqtt_client_init or after sl_mqtt_client_deint
55+
*/
56+
void sli_si91x_get_mqtt_client(sl_mqtt_client_t **client);
57+
58+
/**
59+
* Cleans up resources used by the MQTT client.
60+
*
61+
* This function is responsible for releasing any resources allocated to the MQTT client,
62+
* ensuring a clean shutdown of the client instance. It should be called when the MQTT
63+
* client is no longer needed, typically at the end of the application or before a restart
64+
* of the MQTT client.
65+
*
66+
* Note: It is important to call this function to prevent resource leaks.
67+
*/
68+
void sli_mqtt_client_cleanup();

0 commit comments

Comments
 (0)