Skip to content

Commit e654c05

Browse files
committed
wiseconnect: ICMP 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 ICMP 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 ef4e9c4 commit e654c05

File tree

2 files changed

+162
-0
lines changed

2 files changed

+162
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/***************************************************************************/ /**
2+
* @file sl_net_ping.c
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+
#include "sl_status.h"
30+
#include "sl_constants.h"
31+
#include "sl_net_ping.h"
32+
#include "sl_si91x_driver.h"
33+
#include <string.h>
34+
35+
/******************************************************
36+
* Macros
37+
******************************************************/
38+
39+
// This macro must be used while sending ping timeout in sli_si91x_ping_request_t
40+
#define SLI_CONVERT_TO_SI91X_PING_TIMEOUT(timeout) (timeout / 100)
41+
42+
/******************************************************
43+
* Constants
44+
******************************************************/
45+
#define SLI_PING_RESPONSE_TIMEOUT_MS 1000 // timeout in ms
46+
47+
/******************************************************
48+
* Static Function Declarations
49+
******************************************************/
50+
51+
/******************************************************
52+
* Extern Variable
53+
******************************************************/
54+
extern bool device_initialized;
55+
56+
/******************************************************
57+
* Global Variable
58+
******************************************************/
59+
60+
/******************************************************
61+
* Function Definitions
62+
******************************************************/
63+
64+
sl_status_t sl_si91x_send_ping(sl_ip_address_t ip_address, uint16_t ping_size)
65+
{
66+
sl_status_t status = SL_STATUS_OK;
67+
sli_si91x_ping_request_t request = { 0 };
68+
69+
if (!device_initialized) {
70+
return SL_STATUS_NOT_INITIALIZED;
71+
}
72+
73+
if ((ip_address.type != SL_IPV4) && (ip_address.type != SL_IPV6)) {
74+
return SL_STATUS_INVALID_PARAMETER;
75+
}
76+
77+
if (ip_address.type == SL_IPV6) {
78+
request.ip_version = SL_IPV6_VERSION;
79+
memcpy(&request.ping_address.ipv6_address, &ip_address.ip.v6, SL_IPV6_ADDRESS_LENGTH); // Copy IPv6 address
80+
} else {
81+
request.ip_version = SL_IPV4_VERSION;
82+
memcpy(&request.ping_address.ipv4_address, &ip_address.ip.v4, SL_IPV4_ADDRESS_LENGTH); // Copy IPv4 address
83+
}
84+
85+
request.ping_size = ping_size; // Copy Ping size
86+
request.timeout = SLI_CONVERT_TO_SI91X_PING_TIMEOUT(SLI_PING_RESPONSE_TIMEOUT_MS); // Copy Ping timeout
87+
88+
status = sli_si91x_driver_send_command(SLI_WLAN_REQ_PING_PACKET,
89+
SLI_SI91X_NETWORK_CMD,
90+
&request,
91+
sizeof(sli_si91x_ping_request_t),
92+
SLI_SI91X_RETURN_IMMEDIATELY,
93+
NULL,
94+
NULL);
95+
VERIFY_STATUS_AND_RETURN(status);
96+
97+
return status;
98+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/***************************************************************************/ /**
2+
* @file
3+
* @brief
4+
*******************************************************************************
5+
* # License
6+
* <b>Copyright 2019 Silicon Laboratories Inc. www.silabs.com</b>
7+
*******************************************************************************
8+
*
9+
* SPDX-License-Identifier: Zlib
10+
*
11+
* The licensor of this software is Silicon Laboratories Inc.
12+
*
13+
* This software is provided 'as-is', without any express or implied
14+
* warranty. In no event will the authors be held liable for any damages
15+
* arising from the use of this software.
16+
*
17+
* Permission is granted to anyone to use this software for any purpose,
18+
* including commercial applications, and to alter it and redistribute it
19+
* freely, subject to the following restrictions:
20+
*
21+
* 1. The origin of this software must not be misrepresented; you must not
22+
* claim that you wrote the original software. If you use this software
23+
* in a product, an acknowledgment in the product documentation would be
24+
* appreciated but is not required.
25+
* 2. Altered source versions must be plainly marked as such, and must not be
26+
* misrepresented as being the original software.
27+
* 3. This notice may not be removed or altered from any source distribution.
28+
*
29+
******************************************************************************/
30+
#pragma once
31+
32+
#include "sl_status.h"
33+
#include "sl_net_types.h"
34+
35+
/** \addtogroup SL_PING_FUNCTIONS Functions
36+
* \ingroup SL_PING_APIS
37+
* @{ */
38+
39+
/***************************************************************************/ /**
40+
* @brief
41+
* Send an ICMP ping request to a specific IP address.
42+
* @details
43+
* This function sends an ICMP ping request to a specific IP address (IPv4 or IPv6) with a user defined ping packet size.
44+
* It verifies the device’s initialization status and validates the IP address type before sending the request to the specific IP address.
45+
* @pre Pre-condition:
46+
* - [sl_net_up](../wiseconnect-api-reference-guide-nwk-mgmt/net-interface-functions#sl-net-up) should be called before this API.
47+
* @param[in] ip_address
48+
* 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.
49+
* @param[in] ping_packet_size
50+
* The size of the ping packet must fall within the valid range of [0, 300].
51+
* @return
52+
* [sl_status_t](https://docs.silabs.com/gecko-platform/latest/platform-common/status) - Status of the operation.
53+
* - SL_STATUS_OK: Operation successful.
54+
* - SL_STATUS_NOT_INITIALIZED: Device is not initialized.
55+
* - SL_STATUS_INVALID_PARAMETER: Invalid IP address type.
56+
*
57+
* @note
58+
* 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,
59+
* using the event type [SL_NET_PING_RESPONSE_EVENT](../wiseconnect-api-reference-guide-nwk-mgmt/sl-net-constants#sl-net-event-t).
60+
* 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.
61+
******************************************************************************/
62+
sl_status_t sl_si91x_send_ping(sl_ip_address_t ip_address, uint16_t ping_packet_size);
63+
64+
/** @} */

0 commit comments

Comments
 (0)