diff --git a/examples/platform/silabs/SiWx917/BUILD.gn b/examples/platform/silabs/SiWx917/BUILD.gn index f2ddfd59a4347c..6ead7f31154b09 100644 --- a/examples/platform/silabs/SiWx917/BUILD.gn +++ b/examples/platform/silabs/SiWx917/BUILD.gn @@ -50,9 +50,10 @@ declare_args() { # Sanity check assert(chip_enable_wifi) +silabs_plat_dir = "${chip_root}/src/platform/silabs" silabs_plat_si91x_wifi_dir = "${chip_root}/src/platform/silabs/SiWx917/wifi" -import("${silabs_common_plat_dir}/args.gni") +import("${silabs_common_plat_dir}/args.gni") config("chip_examples_project_config") { include_dirs = [ "project_include" ] @@ -181,9 +182,11 @@ source_set("siwx917-common") { include_dirs = [ ".", "SiWx917/", + "${silabs_plat_dir}/wifi", "${silabs_plat_si91x_wifi_dir}", ] + #TO-DO Cleanup to be done for all the wifi files into common folder sources = [ "${silabs_common_plat_dir}/BaseApplication.cpp", "${silabs_common_plat_dir}/LEDWidget.cpp", @@ -193,7 +196,7 @@ source_set("siwx917-common") { "${silabs_common_plat_dir}/syscalls_stubs.cpp", "${silabs_common_plat_dir}/wifi/wfx_notify.cpp", "${silabs_common_plat_dir}/wifi/wfx_rsi_host.cpp", - "${silabs_plat_si91x_wifi_dir}/dhcp_client.cpp", + "${silabs_plat_dir}/wifi/dhcp_client.cpp", "${silabs_plat_si91x_wifi_dir}/ethernetif.cpp", "${silabs_plat_si91x_wifi_dir}/lwip_netif.cpp", "SiWx917/sl_wifi_if.cpp", diff --git a/examples/platform/silabs/efr32/wf200/host_if.cpp b/examples/platform/silabs/efr32/wf200/host_if.cpp index 44e65e2728fa4b..8247e385f61bcf 100644 --- a/examples/platform/silabs/efr32/wf200/host_if.cpp +++ b/examples/platform/silabs/efr32/wf200/host_if.cpp @@ -1197,9 +1197,19 @@ bool wfx_hw_ready(void) ******************************************************************************/ void wfx_dhcp_got_ipv4(uint32_t ip) { - /* Acquire the new IP address + /* + * Acquire the new IP address */ + uint8_t ip4_addr[4]; + + ip4_addr[0] = (ip) &HEX_VALUE_FF; + ip4_addr[1] = (ip >> 8) & HEX_VALUE_FF; + ip4_addr[2] = (ip >> 16) & HEX_VALUE_FF; + ip4_addr[3] = (ip >> 24) & HEX_VALUE_FF; + + ChipLogDetail(DeviceLayer, "DHCP IP=%d.%d.%d.%d", ip4_addr[0], ip4_addr[1], ip4_addr[2], ip4_addr[3]); sta_ip = ip; + wfx_ip_changed_notify(IP_STATUS_SUCCESS); } #endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ diff --git a/src/platform/silabs/efr32/BUILD.gn b/src/platform/silabs/efr32/BUILD.gn index a71a0cd8b335e6..177cfc01fa33fe 100644 --- a/src/platform/silabs/efr32/BUILD.gn +++ b/src/platform/silabs/efr32/BUILD.gn @@ -166,8 +166,7 @@ static_library("efr32") { if (use_wf200 || use_rs9116 || use_SiWx917) { sources += [ - "wifi/dhcp_client.cpp", - "wifi/dhcp_client.h", + "${silabs_platform_dir}/wifi/dhcp_client.cpp", "wifi/ethernetif.cpp", "wifi/ethernetif.h", "wifi/lwip_netif.cpp", diff --git a/src/platform/silabs/efr32/wifi/dhcp_client.cpp b/src/platform/silabs/efr32/wifi/dhcp_client.cpp deleted file mode 100644 index c2a46d61dd6805..00000000000000 --- a/src/platform/silabs/efr32/wifi/dhcp_client.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/* - * - * Copyright (c) 2022 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#if LWIP_IPV4 && LWIP_DHCP - -#include -#include -#include - -#include "em_bus.h" -#include "em_cmu.h" -#include "em_gpio.h" -#include "em_ldma.h" -#include "em_usart.h" - -#include "dhcp_client.h" -#include "lwip/dhcp.h" -#include "wfx_host_events.h" -#include "wifi_config.h" - -#include "FreeRTOS.h" -#include "event_groups.h" - -#include - -#define MAX_DHCP_TRIES 4 -#define NETIF_IPV4_ADDRESS(X, Y) (((X) >> (8 * Y)) & 0xFF) - -/* Station IP address */ -uint8_t sta_ip_addr0 = STA_IP_ADDR0_DEFAULT; -uint8_t sta_ip_addr1 = STA_IP_ADDR1_DEFAULT; -uint8_t sta_ip_addr2 = STA_IP_ADDR2_DEFAULT; -uint8_t sta_ip_addr3 = STA_IP_ADDR3_DEFAULT; -uint8_t sta_netmask_addr0 = STA_NETMASK_ADDR0_DEFAULT; -uint8_t sta_netmask_addr1 = STA_NETMASK_ADDR1_DEFAULT; -uint8_t sta_netmask_addr2 = STA_NETMASK_ADDR2_DEFAULT; -uint8_t sta_netmask_addr3 = STA_NETMASK_ADDR3_DEFAULT; -uint8_t sta_gw_addr0 = STA_GW_ADDR0_DEFAULT; -uint8_t sta_gw_addr1 = STA_GW_ADDR1_DEFAULT; -uint8_t sta_gw_addr2 = STA_GW_ADDR2_DEFAULT; -uint8_t sta_gw_addr3 = STA_GW_ADDR3_DEFAULT; - -/// Current DHCP state machine state. -static volatile uint8_t dhcp_state = DHCP_OFF; - -/***************************************************************************** - * @fn void dhcpclient_set_link_state(int link_up) - * @brief - * Notify DHCP client task about the wifi status - * @param link_up link status - * @return None - ******************************************************************************/ -void dhcpclient_set_link_state(int link_up) -{ - if (link_up) - { - dhcp_state = DHCP_START; - ChipLogProgress(DeviceLayer, "DHCP: Starting"); - } - else - { - /* Update DHCP state machine */ - dhcp_state = DHCP_LINK_DOWN; - } -} - -/********************************************************************************** - * @fn uint8_t dhcpclient_poll(void *arg) - * @brief - * Don't need a task here. We get polled every 250ms - * @return None - ************************************************************************************/ -uint8_t dhcpclient_poll(void * arg) -{ - struct netif * netif = (struct netif *) arg; - ip_addr_t ipaddr; - ip_addr_t netmask; - ip_addr_t gw; - struct dhcp * dhcp; - - switch (dhcp_state) - { - case DHCP_START: - ChipLogProgress(DeviceLayer, "DHCP: Wait addr"); - ip_addr_set_zero_ip4(&netif->ip_addr); - ip_addr_set_zero_ip4(&netif->netmask); - ip_addr_set_zero_ip4(&netif->gw); - dhcp_start(netif); - dhcp_state = DHCP_WAIT_ADDRESS; - break; - - case DHCP_WAIT_ADDRESS: - if (dhcp_supplied_address(netif)) - { - dhcp_state = DHCP_ADDRESS_ASSIGNED; - - uint64_t addr = netif->ip_addr.u_addr.ip4.addr; - ChipLogProgress(DeviceLayer, "DHCP IP: %d.%d.%d.%d", NETIF_IPV4_ADDRESS(addr, 0), NETIF_IPV4_ADDRESS(addr, 1), - NETIF_IPV4_ADDRESS(addr, 2), NETIF_IPV4_ADDRESS(addr, 3)); - } - else - { - dhcp = (struct dhcp *) netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP); - - /* DHCP timeout */ - if (dhcp->tries > MAX_DHCP_TRIES) - { - dhcp_state = DHCP_TIMEOUT; - - ChipLogProgress(DeviceLayer, "*ERR*DHCP: Failed"); - /* Stop DHCP */ - dhcp_stop(netif); - - /* TODO - I am not sure that this is best */ - /* Static address used */ - IP_ADDR4(&ipaddr, sta_ip_addr0, sta_ip_addr1, sta_ip_addr2, sta_ip_addr3); - IP_ADDR4(&netmask, sta_netmask_addr0, sta_netmask_addr1, sta_netmask_addr2, sta_netmask_addr3); - IP_ADDR4(&gw, sta_gw_addr0, sta_gw_addr1, sta_gw_addr2, sta_gw_addr3); - netif_set_addr(netif, ip_2_ip4(&ipaddr), ip_2_ip4(&netmask), ip_2_ip4(&gw)); - } - } - break; - - case DHCP_LINK_DOWN: - /* Stop DHCP */ - ChipLogProgress(DeviceLayer, "*ERR*DHCP Link down"); - dhcp_stop(netif); - dhcp_state = DHCP_OFF; - break; - default: - break; - } - return dhcp_state; -} - -#endif /* LWIP_IPV4 && LWIP_DHCP */ diff --git a/src/platform/silabs/efr32/wifi/dhcp_client.h b/src/platform/silabs/efr32/wifi/dhcp_client.h deleted file mode 100644 index 4ee9d2f5d0d68d..00000000000000 --- a/src/platform/silabs/efr32/wifi/dhcp_client.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * - * Copyright (c) 2022 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#if LWIP_IPV4 && LWIP_DHCP - -#pragma once -#ifdef __cplusplus -extern "C" { -#endif - -// DHCP client states -#define DHCP_OFF ((uint8_t) 0) -#define DHCP_START ((uint8_t) 1) -#define DHCP_WAIT_ADDRESS ((uint8_t) 2) -#define DHCP_ADDRESS_ASSIGNED ((uint8_t) 3) -#define DHCP_TIMEOUT ((uint8_t) 4) -#define DHCP_LINK_DOWN ((uint8_t) 5) - -/***************************************************************************** - * @fn void dhcpclient_set_link_state(int link_up) - * @brief - * Notify DHCP client task about the wifi status - * @param link_up link status - ******************************************************************************/ -void dhcpclient_set_link_state(int link_up); -uint8_t dhcpclient_poll(void * arg); -#ifdef __cplusplus -} -#endif - -#endif /* LWIP_IPV4 && LWIP_DHCP */ diff --git a/src/platform/silabs/SiWx917/wifi/dhcp_client.cpp b/src/platform/silabs/wifi/dhcp_client.cpp similarity index 94% rename from src/platform/silabs/SiWx917/wifi/dhcp_client.cpp rename to src/platform/silabs/wifi/dhcp_client.cpp index 2ffc45d491ac66..c8b47a9f2b3735 100644 --- a/src/platform/silabs/SiWx917/wifi/dhcp_client.cpp +++ b/src/platform/silabs/wifi/dhcp_client.cpp @@ -101,10 +101,6 @@ uint8_t dhcpclient_poll(void * arg) if (dhcp_supplied_address(netif)) { dhcp_state = DHCP_ADDRESS_ASSIGNED; - - uint64_t addr = netif->ip_addr.u_addr.ip4.addr; - ChipLogProgress(DeviceLayer, "DHCP IP: %d.%d.%d.%d", NETIF_IPV4_ADDRESS(addr, 0), NETIF_IPV4_ADDRESS(addr, 1), - NETIF_IPV4_ADDRESS(addr, 2), NETIF_IPV4_ADDRESS(addr, 3)); } else { diff --git a/src/platform/silabs/SiWx917/wifi/dhcp_client.h b/src/platform/silabs/wifi/dhcp_client.h similarity index 100% rename from src/platform/silabs/SiWx917/wifi/dhcp_client.h rename to src/platform/silabs/wifi/dhcp_client.h diff --git a/third_party/silabs/SiWx917_sdk.gni b/third_party/silabs/SiWx917_sdk.gni index 1163cd28c99de3..ea9d6beaefd970 100644 --- a/third_party/silabs/SiWx917_sdk.gni +++ b/third_party/silabs/SiWx917_sdk.gni @@ -256,7 +256,7 @@ template("siwx917_sdk") { } defines += [ "LWIP_NETIF_API=1" ] - if (lwip_ipv4) { + if (chip_enable_wifi_ipv4) { defines += [ "LWIP_IPV4=1", diff --git a/third_party/silabs/efr32_sdk.gni b/third_party/silabs/efr32_sdk.gni index c75f67694e8d5c..1cd69d31e7084b 100644 --- a/third_party/silabs/efr32_sdk.gni +++ b/third_party/silabs/efr32_sdk.gni @@ -362,6 +362,9 @@ template("efr32_sdk") { if (use_rs9116 || use_SiWx917) { _include_dirs += [ "${chip_root}/src/platform/silabs/rs911x" ] } + if (use_wf200 || use_rs9116 || use_SiWx917) { + _include_dirs += [ "${chip_root}/src/platform/silabs/wifi" ] + } if (silabs_family != "mgm24") { _include_dirs += [ "${efr32_sdk_root}/platform/radio/rail_lib/hal",