Skip to content

wiseconnect: Adding SiWx917 Network Stack Application APIs #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions scripts/import_wiseconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@
"components/device/silabs/si91x/wireless/crypto/wrap/src/sl_si91x_psa_wrap.c",
"components/device/silabs/si91x/wireless/crypto/wrap/src/sl_si91x_wrap.c",
"components/device/silabs/si91x/wireless/host_mcu/si91x/siwx917_soc_ncp_host.c",
"components/device/silabs/si91x/wireless/icmp/sl_net_ping.c",
"components/device/silabs/si91x/wireless/icmp/sl_net_ping.h",
"components/device/silabs/si91x/wireless/inc/http_client/inc/sl_si91x_http_client_callback_framework.h",
"components/device/silabs/si91x/wireless/inc/http_client/src/sl_si91x_http_client_callback_framework.c",
"components/device/silabs/si91x/wireless/inc/sl_rsi_utility.h",
"components/device/silabs/si91x/wireless/inc/sl_si91x_constants.h",
"components/device/silabs/si91x/wireless/inc/sl_si91x_core_utilities.h",
Expand All @@ -216,12 +220,18 @@
"components/device/silabs/si91x/wireless/inc/sl_si91x_status.h",
"components/device/silabs/si91x/wireless/inc/sl_si91x_types.h",
"components/device/silabs/si91x/wireless/inc/sl_wifi_device.h",
"components/device/silabs/si91x/wireless/inc//mqtt/inc/si91x_mqtt_client_callback_framework.h",
"components/device/silabs/si91x/wireless/inc//mqtt/inc/si91x_mqtt_client_types.h",
"components/device/silabs/si91x/wireless/inc//mqtt/inc/si91x_mqtt_client_utility.h",
"components/device/silabs/si91x/wireless/inc/sntp/si91x_sntp_client_callback_framework.h",
"components/device/silabs/si91x/wireless/inc/sntp/si91x_sntp_client_types.h",
"components/device/silabs/si91x/wireless/memory/malloc_buffers.c",
"components/device/silabs/si91x/wireless/sl_net/inc/sli_net_utility.h",
"components/device/silabs/si91x/wireless/sl_net/inc/sl_net_si91x.h",
"components/device/silabs/si91x/wireless/sl_net/inc/sl_net_si91x_integration_handler.h",
"components/device/silabs/si91x/wireless/sl_net/src/sli_net_si91x_utility.c",
"components/device/silabs/si91x/wireless/sl_net/src/sl_net_rsi_utility.c",
"components/device/silabs/si91x/wireless/sl_net/src/sl_net_si91x.c",
"components/device/silabs/si91x/wireless/sl_net/src/sl_net_si91x_callback_framework.c",
"components/device/silabs/si91x/wireless/sl_net/src/sl_net_si91x_integration_handler.c",
"components/device/silabs/si91x/wireless/sl_net/src/sl_si91x_net_internal_stack.c",
Expand All @@ -244,6 +254,13 @@
"components/protocol/wifi/src/sl_wifi_basic_credentials.c",
"components/protocol/wifi/src/sl_wifi_callback_framework.c",
"components/service/bsd_socket/si91x_socket/sl_si91x_socket_support.h",
"components/service/http_client/http_client/si91x_socket/sl_http_client.c",
"components/service/http_client/inc/sl_http_client.h",
"components/service/mdns/inc/sl_mdns.h",
"components/service/mdns/si91x/sl_mdns.c",
"components/service/mqtt/inc/sl_mqtt_client.h",
"components/service/mqtt/inc/sl_mqtt_client_types.h",
"components/service/mqtt/si91x/sl_mqtt_client.c",
"components/service/network_manager/inc/sli_net_common_utility.h",
"components/service/network_manager/inc/sli_net_constants.h",
"components/service/network_manager/inc/sl_net_constants.h",
Expand All @@ -256,6 +273,13 @@
"components/service/network_manager/src/sl_net_basic_profiles.c",
"components/service/network_manager/src/sl_net.c",
"components/service/network_manager/src/sl_net_credentials.c",
"components/service/sntp/inc/sl_sntp.h",
"components/service/sntp/si91x/sl_sntp.c",
"components/service/sl_websocket_client/inc/sl_websocket_client.h",
"components/service/sl_websocket_client/inc/sl_websocket_client_types.h",
"components/service/sl_websocket_client/inc/sli_websocket_client_sync.h",
"components/service/sl_websocket_client/src/sl_websocket_client.c",
"components/service/sl_websocket_client/src/sli_websocket_client_sync.c",
"components/sli_si91x_wifi_event_handler/src/sli_si91x_wifi_event_handler.c",
"components/sli_wifi_command_engine/inc/sli_wifi_command_engine.h",
"components/sli_wifi_command_engine/inc/sli_wifi_event_handler.h",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/***************************************************************************/ /**
* @file sl_net_ping.c
*******************************************************************************
* # License
* <b>Copyright 2025 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* SPDX-License-Identifier: Zlib
*
* The licensor of this software is Silicon Laboratories Inc.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
******************************************************************************/
#include "sl_status.h"
#include "sl_constants.h"
#include "sl_net_ping.h"
#include "sl_si91x_driver.h"
#include <string.h>

/******************************************************
* Macros
******************************************************/

// This macro must be used while sending ping timeout in sli_si91x_ping_request_t
#define SLI_CONVERT_TO_SI91X_PING_TIMEOUT(timeout) (timeout / 100)

/******************************************************
* Constants
******************************************************/
#define SLI_PING_RESPONSE_TIMEOUT_MS 1000 // timeout in ms

/******************************************************
* Static Function Declarations
******************************************************/

/******************************************************
* Extern Variable
******************************************************/
extern bool device_initialized;

/******************************************************
* Global Variable
******************************************************/

/******************************************************
* Function Definitions
******************************************************/

sl_status_t sl_si91x_send_ping(sl_ip_address_t ip_address, uint16_t ping_size)
{
sl_status_t status = SL_STATUS_OK;
sli_si91x_ping_request_t request = { 0 };

if (!device_initialized) {
return SL_STATUS_NOT_INITIALIZED;
}

if ((ip_address.type != SL_IPV4) && (ip_address.type != SL_IPV6)) {
return SL_STATUS_INVALID_PARAMETER;
}

if (ip_address.type == SL_IPV6) {
request.ip_version = SL_IPV6_VERSION;
memcpy(&request.ping_address.ipv6_address, &ip_address.ip.v6, SL_IPV6_ADDRESS_LENGTH); // Copy IPv6 address
} else {
request.ip_version = SL_IPV4_VERSION;
memcpy(&request.ping_address.ipv4_address, &ip_address.ip.v4, SL_IPV4_ADDRESS_LENGTH); // Copy IPv4 address
}

request.ping_size = ping_size; // Copy Ping size
request.timeout = SLI_CONVERT_TO_SI91X_PING_TIMEOUT(SLI_PING_RESPONSE_TIMEOUT_MS); // Copy Ping timeout

status = sli_si91x_driver_send_command(SLI_WLAN_REQ_PING_PACKET,
SLI_SI91X_NETWORK_CMD,
&request,
sizeof(sli_si91x_ping_request_t),
SLI_SI91X_RETURN_IMMEDIATELY,
NULL,
NULL);
VERIFY_STATUS_AND_RETURN(status);

return status;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/***************************************************************************/ /**
* @file
* @brief
*******************************************************************************
* # License
* <b>Copyright 2019 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* SPDX-License-Identifier: Zlib
*
* The licensor of this software is Silicon Laboratories Inc.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
******************************************************************************/
#pragma once

#include "sl_status.h"
#include "sl_net_types.h"

/** \addtogroup SL_PING_FUNCTIONS Functions
* \ingroup SL_PING_APIS
* @{ */

/***************************************************************************/ /**
* @brief
* Send an ICMP ping request to a specific IP address.
* @details
* This function sends an ICMP ping request to a specific IP address (IPv4 or IPv6) with a user defined ping packet size.
* It verifies the device’s initialization status and validates the IP address type before sending the request to the specific IP address.
* @pre Pre-condition:
* - [sl_net_up](../wiseconnect-api-reference-guide-nwk-mgmt/net-interface-functions#sl-net-up) should be called before this API.
* @param[in] ip_address
* The destination IP address should be of type [sl_ip_address_type_t](../wiseconnect-api-reference-guide-common/sl-ip-address-t) either IPv4 or IPv6.
* @param[in] ping_packet_size
* The size of the ping packet must fall within the valid range of [0, 300].
* @return
* [sl_status_t](https://docs.silabs.com/gecko-platform/latest/platform-common/status) - Status of the operation.
* - SL_STATUS_OK: Operation successful.
* - SL_STATUS_NOT_INITIALIZED: Device is not initialized.
* - SL_STATUS_INVALID_PARAMETER: Invalid IP address type.
*
* @note
* 1. This API is asynchronous. The ping response is delivered through the registered [sl_net_event_handler_t](../wiseconnect-api-reference-guide-nwk-mgmt/sl-net-types#sl-net-event-handler-t) callback,
* using the event type [SL_NET_PING_RESPONSE_EVENT](../wiseconnect-api-reference-guide-nwk-mgmt/sl-net-constants#sl-net-event-t).
* To receive this event, the sl_net_event_handler_t must be registered via the [sl_net_init()](../wiseconnect-api-reference-guide-nwk-mgmt/net-interface-functions#sl-net-init) API.
******************************************************************************/
sl_status_t sl_si91x_send_ping(sl_ip_address_t ip_address, uint16_t ping_packet_size);

/** @} */
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/***************************************************************************/ /**
* @file
* @brief sl_si91x_http_client_callback_framework.h
*******************************************************************************
* # License
* <b>Copyright 2019 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* SPDX-License-Identifier: Zlib
*
* The licensor of this software is Silicon Laboratories Inc.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
******************************************************************************/

#include "sl_http_client.h"
#include "sl_si91x_core_utilities.h"
#include "sl_si91x_constants.h"
#include "sl_si91x_driver.h"
#include "sl_si91x_protocol_types.h"

/******************************************************
* Function Declarations
******************************************************/
sl_status_t sli_http_client_register_callback(sl_http_client_event_t event,
sl_http_client_t client_handle,
sl_http_client_event_handler_t function);

sl_status_t sli_http_client_default_event_handler(sl_http_client_event_t event,
sl_wifi_buffer_t *buffer,
void *sdk_context);
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/***************************************************************************/ /**
* @file si91x_mqtt_client_callback_framework.h
*******************************************************************************
* # License
* <b>Copyright 2025 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* SPDX-License-Identifier: Zlib
*
* The licensor of this software is Silicon Laboratories Inc.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
******************************************************************************/

#pragma once

#include "sl_mqtt_client.h"
#include "sl_mqtt_client_types.h"
#include "sl_si91x_types.h"
#include "sl_status.h"

/**
* @addtogroup SERVICE_MQTT_TYPES
* @{
*/
typedef struct {
sl_mqtt_client_event_t event;
sl_mqtt_client_t *client;
void *user_context;
void *sdk_data;
} sl_si91x_mqtt_client_context_t;

sl_status_t sli_si91x_mqtt_event_handler(sl_status_t status,
sl_si91x_mqtt_client_context_t *sdk_context,
sl_wifi_packet_t *rx_packet);

/** @} */
Loading