|
| 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 | +} |
0 commit comments