From 26048659cd215510a6521869dcbf516556d75d58 Mon Sep 17 00:00:00 2001 From: rgoliver Date: Thu, 2 Jun 2022 01:22:58 -0400 Subject: [PATCH] Remove ipv6only-app (#19057) Example apps now have ipv6only mode and this example is no longer needed for testing. --- .github/workflows/examples-esp32.yaml | 4 - examples/ipv6only-app/esp32/.gitignore | 5 - examples/ipv6only-app/esp32/CMakeLists.txt | 53 --- examples/ipv6only-app/esp32/README.md | 129 ------- .../ipv6only-app/esp32/include/wifi_service.h | 163 --------- .../ipv6only-app/esp32/main/CMakeLists.txt | 59 --- .../ipv6only-app/esp32/main/Kconfig.projbuild | 39 -- examples/ipv6only-app/esp32/main/main.cpp | 152 -------- .../ipv6only-app/esp32/main/wifi_service.cpp | 341 ------------------ examples/ipv6only-app/esp32/partitions.csv | 6 - .../ipv6only-app/esp32/sdkconfig.defaults | 43 --- .../esp32/third_party/connectedhomeip | 1 - 12 files changed, 995 deletions(-) delete mode 100644 examples/ipv6only-app/esp32/.gitignore delete mode 100644 examples/ipv6only-app/esp32/CMakeLists.txt delete mode 100644 examples/ipv6only-app/esp32/README.md delete mode 100644 examples/ipv6only-app/esp32/include/wifi_service.h delete mode 100644 examples/ipv6only-app/esp32/main/CMakeLists.txt delete mode 100644 examples/ipv6only-app/esp32/main/Kconfig.projbuild delete mode 100644 examples/ipv6only-app/esp32/main/main.cpp delete mode 100644 examples/ipv6only-app/esp32/main/wifi_service.cpp delete mode 100644 examples/ipv6only-app/esp32/partitions.csv delete mode 100644 examples/ipv6only-app/esp32/sdkconfig.defaults delete mode 120000 examples/ipv6only-app/esp32/third_party/connectedhomeip diff --git a/.github/workflows/examples-esp32.yaml b/.github/workflows/examples-esp32.yaml index a6099debcf8ccd..f7f27572b4b35f 100644 --- a/.github/workflows/examples-esp32.yaml +++ b/.github/workflows/examples-esp32.yaml @@ -163,10 +163,6 @@ jobs: timeout-minutes: 15 run: scripts/examples/esp_example.sh temperature-measurement-app sdkconfig.optimize.defaults - - name: Build example IPv6 Only App - timeout-minutes: 15 - run: scripts/examples/esp_example.sh ipv6only-app sdkconfig.defaults - - name: Build example OTA Requestor App run: scripts/examples/esp_example.sh ota-requestor-app sdkconfig.defaults timeout-minutes: 15 diff --git a/examples/ipv6only-app/esp32/.gitignore b/examples/ipv6only-app/esp32/.gitignore deleted file mode 100644 index 234526a082ad26..00000000000000 --- a/examples/ipv6only-app/esp32/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -*.vscode - -/build/ -/sdkconfig -/sdkconfig.old diff --git a/examples/ipv6only-app/esp32/CMakeLists.txt b/examples/ipv6only-app/esp32/CMakeLists.txt deleted file mode 100644 index 4b125c1cc43895..00000000000000 --- a/examples/ipv6only-app/esp32/CMakeLists.txt +++ /dev/null @@ -1,53 +0,0 @@ -# -# Copyright (c) 2021 Project CHIP Authors -# All rights reserved. -# -# 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. - -# The following lines of boilerplate have to be in your project's -# CMakeLists in this exact order for cmake to work correctly -cmake_minimum_required(VERSION 3.5) -include($ENV{IDF_PATH}/tools/cmake/project.cmake) - -set(EXTRA_COMPONENT_DIRS - "${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/config/esp32/components" -) - -project(chip-ipv6only-app) -idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++17;-Os;-DLWIP_IPV6_SCOPES=0;-DCHIP_HAVE_CONFIG_H" APPEND) -idf_build_set_property(C_COMPILE_OPTIONS "-Os;-DLWIP_IPV6_SCOPES=0" APPEND) -# For the C3, project_include.cmake sets -Wno-format, but does not clear various -# flags that depend on -Wformat -idf_build_set_property(COMPILE_OPTIONS "-Wno-format-nonliteral;-Wno-format-security" APPEND) - -# -Wmaybe-uninitialized has too many false positives, including on std::optional -# and chip::Optional. Make it nonfatal. -# -# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80635 -idf_build_set_property(COMPILE_OPTIONS "-Wno-error=maybe-uninitialized" APPEND) - -get_filename_component(CHIP_ROOT ./third_party/connectedhomeip REALPATH) -include(third_party/connectedhomeip/third_party/pigweed/repo/pw_build/pigweed.cmake) -pw_set_module_config(pw_rpc_CONFIG pw_rpc.disable_global_mutex_config) -pw_set_backend(pw_log pw_log_basic) -pw_set_backend(pw_assert pw_assert_log) -pw_set_backend(pw_sys_io pw_sys_io.esp32) - -add_subdirectory(third_party/connectedhomeip/third_party/pigweed/repo) -add_subdirectory(third_party/connectedhomeip/third_party/nanopb/repo) -add_subdirectory(third_party/connectedhomeip/examples/platform/esp32/pw_sys_io) - -get_target_property(_target_cxx_flags pw_build.cpp17 INTERFACE_COMPILE_OPTIONS) -list(REMOVE_ITEM _target_cxx_flags $<$:-std=c++17>) -list(APPEND _target_cxx_flags $<$:-std=gnu++17>) -set_target_properties(pw_build.cpp17 PROPERTIES INTERFACE_COMPILE_OPTIONS "${_target_cxx_flags}") diff --git a/examples/ipv6only-app/esp32/README.md b/examples/ipv6only-app/esp32/README.md deleted file mode 100644 index 41c6d5f2ae3374..00000000000000 --- a/examples/ipv6only-app/esp32/README.md +++ /dev/null @@ -1,129 +0,0 @@ -# CHIP ESP32 IPV6 Only Example Application - -This application implements ESP32 wifi control to support IPV6 tests. - -Once connected the application acts as a UDP echo server and will echo udp -messages it receives, this can be used to test for disconnect events. - -- [CHIP ESP32 IPV6 Only Example Application](#chip-esp32-ipv6-only-example-application) - - [Building the Example Application](#building-the-example-application) - - [To build the application, follow these steps:](#to-build-the-application-follow-these-steps) - - [Testing the Example Application](#testing-the-example-application) - ---- - -## Building the Example Application - -Building the example application requires the use of the Espressif ESP32 IoT -Development Framework and the xtensa-esp32-elf toolchain. - -The VSCode devcontainer has these components pre-installed, so you can skip this -step. To install these components manually, follow these steps: - -- Clone the Espressif ESP-IDF and checkout - [v4.4.1 release](https://github.com/espressif/esp-idf/releases/tag/v4.4.1) - - ``` - $ mkdir ${HOME}/tools - $ cd ${HOME}/tools - $ git clone https://github.com/espressif/esp-idf.git - $ cd esp-idf - $ git checkout v4.4.1 - $ git submodule update --init - $ ./install.sh - ``` - -- Install ninja-build - - ``` - $ sudo apt-get install ninja-build - ``` - -### To build the application, follow these steps: - -Currently building in VSCode _and_ deploying from native is not supported, so -make sure the IDF_PATH has been exported(See the manual setup steps above). - -- Setting up the environment - - ``` - $ cd ${HOME}/tools/esp-idf - $ ./install.sh - $ . ./export.sh - $ cd {path-to-connectedhomeip} - ``` - - To download and install packages. - - ``` - $ source ./scripts/bootstrap.sh - $ source ./scripts/activate.sh - ``` - - If packages are already installed then simply activate them. - - ``` - $ source ./scripts/activate.sh - ``` - -- Select IDF Target - - ``` - $ idf.py set-target esp32(or esp32c3) - ``` - -- Configuration Options - - To choose from the different configuration options, run menuconfig - - ``` - $ idf.py menuconfig - ``` - - This example uses UART0 for serial communication. You can change this through - `PW RPC Example Configuration`. As a result, the console has been shifted to UART1 - You can change this through `Component config` -> `Common ESP-related` -> - `UART for console output` - -- Build the demo application. - - $ idf.py build - -- After building the application, to flash it outside of VSCode, connect your - device via USB. Then run the following command to flash the demo application - onto the device and then monitor its output. If necessary, replace - `/dev/tty.SLAB_USBtoUART`(MacOS) with the correct USB device name for your - system(like `/dev/ttyUSB0` on Linux). Note that sometimes you might have to - press and hold the `boot` button on the device while it's trying to connect - before flashing. For ESP32-DevKitC devices this is labeled in the - [functional description diagram](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/hw-reference/esp32/get-started-devkitc.html#functional-description). - - ``` - $ idf.py flash -p /dev/tty.SLAB_USBtoUART - ``` - - Note: Some users might have to install the - [VCP driver](https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers) - before the device shows up on `/dev/tty`. - -## Testing the Example Application - -Build or install the [rpc console](../../common/pigweed/rpc_console/README.md) - -Start the console: - - ``` - $ chip-console --device /dev/ttyUSB0 -b 115200 - ``` - -An example flow of performing a scan, connecting, and getting the IPv6 address: - - ``` - scan = rpcs.chip.rpc.WiFi.StartScan(pw_rpc_timeout_s=5) - ap = next(filter(lambda a: b"SSID\000" in a.ssid, next(scan.responses()).aps)) - - connect = protos.chip.rpc.ConnectionData(ssid=ap.ssid,security_type=ap.security_type,secret=b"PASSWORD") - rpcs.chip.rpc.WiFi.Connect(connect, pw_rpc_timeout_s=10) - - rpcs.chip.rpc.WiFi.GetIP6Address() - ``` diff --git a/examples/ipv6only-app/esp32/include/wifi_service.h b/examples/ipv6only-app/esp32/include/wifi_service.h deleted file mode 100644 index 12dc0e9a2d0f46..00000000000000 --- a/examples/ipv6only-app/esp32/include/wifi_service.h +++ /dev/null @@ -1,163 +0,0 @@ -/* - * - * Copyright (c) 2021 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. - */ - -#pragma once - -#include "esp_event.h" -#include "esp_log.h" -#include "esp_netif.h" -#include "esp_system.h" -#include "esp_wifi.h" -#include "freertos/FreeRTOS.h" -#include "freertos/semphr.h" -#include "pw_status/status.h" -#include "pw_status/try.h" -#include "wifi_service/wifi_service.rpc.pb.h" - -namespace chip { -namespace rpc { - -class WiFi final : public pw_rpc::nanopb::WiFi::Service -{ -public: - // Singleton - static WiFi & Instance() { return instance_; } - - // Initalize the wifi station - pw::Status Init(); - - // Blocks the calling thread until wifi connection is completed successfully. - // NOTE: Currently only supports blocking a single thread. - void BlockUntilWiFiConnected() { xSemaphoreTake(wifi_connected_semaphore_, portMAX_DELAY); } - - // The following functions are the RPC handlers - - pw::Status GetChannel(const pw_protobuf_Empty & request, chip_rpc_Channel & response) - { - uint8_t channel = 0; - wifi_second_chan_t second; - PW_TRY(EspToPwStatus(esp_wifi_get_channel(&channel, &second))); - response.channel = channel; - return pw::OkStatus(); - } - - pw::Status GetSsid(const pw_protobuf_Empty & request, chip_rpc_Ssid & response) - { - wifi_config_t config; - PW_TRY(EspToPwStatus(esp_wifi_get_config(WIFI_IF_STA, &config))); - size_t size = std::min(sizeof(response.ssid.bytes), sizeof(config.sta.ssid)); - memcpy(response.ssid.bytes, config.sta.ssid, sizeof(response.ssid.bytes)); - response.ssid.size = size; - return pw::OkStatus(); - } - - pw::Status GetState(const pw_protobuf_Empty & request, chip_rpc_State & response) - { - wifi_ap_record_t ap_info; - esp_err_t err = esp_wifi_sta_get_ap_info(&ap_info); - PW_TRY(EspToPwStatus(err)); - response.connected = (err != ESP_ERR_WIFI_NOT_CONNECT); - return pw::OkStatus(); - } - - pw::Status GetMacAddress(const pw_protobuf_Empty & request, chip_rpc_MacAddress & response) - { - uint8_t mac[6]; - PW_TRY(EspToPwStatus(esp_wifi_get_mac(WIFI_IF_STA, mac))); - sprintf(response.mac_address, "%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - return pw::OkStatus(); - } - - pw::Status GetWiFiInterface(const pw_protobuf_Empty & request, chip_rpc_WiFiInterface & response) - { - wifi_ap_record_t ap_info; - PW_TRY(EspToPwStatus(esp_wifi_sta_get_ap_info(&ap_info))); - sprintf(response.interface, "STA"); - return pw::OkStatus(); - } - - pw::Status GetIP4Address(const pw_protobuf_Empty & request, chip_rpc_IP4Address & response) - { - esp_netif_ip_info_t ip_info; - PW_TRY(EspToPwStatus(esp_netif_get_ip_info(esp_netif_, &ip_info))); - sprintf(response.address, IPSTR, IP2STR(&ip_info.ip)); - return pw::OkStatus(); - } - - pw::Status GetIP6Address(const pw_protobuf_Empty & request, chip_rpc_IP6Address & response) - { - esp_ip6_addr_t ip6{ 0 }; - PW_TRY(EspToPwStatus(esp_netif_get_ip6_linklocal(esp_netif_, &ip6))); - sprintf(response.address, IPV6STR, IPV62STR(ip6)); - return pw::OkStatus(); - } - - // NOTE: Currently this is blocking, it can be made non-blocking if needed - // but would require another worker thread to handle the scanning. - void StartScan(const chip_rpc_ScanConfig & request, ServerWriter & writer); - - pw::Status StopScan(const pw_protobuf_Empty & request, pw_protobuf_Empty & response) - { - esp_wifi_scan_stop(); - return pw::OkStatus(); - } - - pw::Status Connect(const chip_rpc_ConnectionData & request, chip_rpc_ConnectionResult & response); - - pw::Status Disconnect(const pw_protobuf_Empty & request, pw_protobuf_Empty & response) - { - PW_TRY(EspToPwStatus(esp_wifi_disconnect())); - return pw::OkStatus(); - } - -private: - static WiFi instance_; - esp_netif_t * esp_netif_ = nullptr; - SemaphoreHandle_t wifi_connected_semaphore_; - - static constexpr pw::Status EspToPwStatus(esp_err_t err) - { - switch (err) - { - case ESP_OK: - return pw::OkStatus(); - case ESP_ERR_WIFI_NOT_INIT: - return pw::Status::FailedPrecondition(); - case ESP_ERR_INVALID_ARG: - return pw::Status::InvalidArgument(); - case ESP_ERR_ESP_NETIF_INVALID_PARAMS: - return pw::Status::InvalidArgument(); - case ESP_ERR_WIFI_IF: - return pw::Status::NotFound(); - case ESP_ERR_WIFI_NOT_CONNECT: - return pw::Status::FailedPrecondition(); - case ESP_ERR_WIFI_NOT_STARTED: - return pw::Status::FailedPrecondition(); - case ESP_ERR_WIFI_CONN: - return pw::Status::Internal(); - case ESP_FAIL: - return pw::Status::Internal(); - default: - return pw::Status::Unknown(); - } - } - - static void WiFiEventHandler(void * arg, esp_event_base_t event_base, int32_t event_id, void * event_data); -}; - -} // namespace rpc -} // namespace chip diff --git a/examples/ipv6only-app/esp32/main/CMakeLists.txt b/examples/ipv6only-app/esp32/main/CMakeLists.txt deleted file mode 100644 index 853edf5628e99c..00000000000000 --- a/examples/ipv6only-app/esp32/main/CMakeLists.txt +++ /dev/null @@ -1,59 +0,0 @@ -# -# Copyright (c) 2021 Project CHIP Authors -# All rights reserved. -# -# 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. - -idf_component_register(INCLUDE_DIRS - "${CMAKE_CURRENT_LIST_DIR}" - "${CMAKE_CURRENT_LIST_DIR}/../include" - "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/pw_sys_io/public" - "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32" - "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/common/pigweed" - "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/common/pigweed/esp32" - "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/lib/support" - "${IDF_PATH}/components/freertos/include/freertos" - - SRC_DIRS - "${CMAKE_CURRENT_LIST_DIR}" - "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32" - "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/common/pigweed" - "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/common/pigweed/esp32" - PRIV_REQUIRES bt chip) - -get_filename_component(CHIP_ROOT ${CMAKE_SOURCE_DIR}/third_party/connectedhomeip REALPATH) -set(PIGWEED_ROOT "${CHIP_ROOT}/third_party/pigweed/repo") -include(${PIGWEED_ROOT}/pw_build/pigweed.cmake) -include(${PIGWEED_ROOT}/pw_protobuf_compiler/proto.cmake) -set(dir_pw_third_party_nanopb "${CHIP_ROOT}/third_party/nanopb/repo" CACHE STRING "" FORCE) - -pw_proto_library(wifi_service - SOURCES - ${CHIP_ROOT}/examples/common/pigweed/protos/wifi_service.proto - INPUTS - ${CHIP_ROOT}/examples/common/pigweed/protos/wifi_service.options - PREFIX - wifi_service - DEPS - pw_protobuf.common_protos - STRIP_PREFIX - ${CHIP_ROOT}/examples/common/pigweed/protos -) - -target_link_libraries(${COMPONENT_LIB} PUBLIC - wifi_service.nanopb_rpc - pw_checksum - pw_hdlc - pw_log - pw_rpc.server -) diff --git a/examples/ipv6only-app/esp32/main/Kconfig.projbuild b/examples/ipv6only-app/esp32/main/Kconfig.projbuild deleted file mode 100644 index eaa289dfc60e12..00000000000000 --- a/examples/ipv6only-app/esp32/main/Kconfig.projbuild +++ /dev/null @@ -1,39 +0,0 @@ -menu "PW RPC Example Configuration" - -depends on ENABLE_PW_RPC - config EXAMPLE_UART_PORT_NUM - int "UART port number" - range 0 2 if IDF_TARGET_ESP32 - range 0 1 if IDF_TARGET_ESP32C3 - default 0 - help - UART communication port number for the example. - See UART documentation for available port numbers. - - config EXAMPLE_UART_BAUD_RATE - int "UART communication speed" - range 1200 115200 - default 115200 - help - UART communication speed for Modbus example. - - config EXAMPLE_UART_RXD - int "UART RXD pin number" - range 0 34 if IDF_TARGET_ESP32 - range 0 19 if IDF_TARGET_ESP32C3 - default 5 - help - GPIO number for UART RX pin. See UART documentation for more information - about available pin numbers for UART. - - config EXAMPLE_UART_TXD - int "UART TXD pin number" - range 0 34 if IDF_TARGET_ESP32 - range 0 19 if IDF_TARGET_ESP32C3 - default 4 - help - GPIO number for UART TX pin. See UART documentation for more information - about available pin numbers for UART. - - -endmenu diff --git a/examples/ipv6only-app/esp32/main/main.cpp b/examples/ipv6only-app/esp32/main/main.cpp deleted file mode 100644 index 608350a38ad053..00000000000000 --- a/examples/ipv6only-app/esp32/main/main.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/* - * - * Copyright (c) 2021 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. - */ - -#include "PigweedLoggerMutex.h" -#include "RpcService.h" -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "nvs_flash.h" -#include "pw_rpc/server.h" -#include "wifi_service.h" - -#include "lwip/err.h" -#include "lwip/sockets.h" -#include "lwip/sys.h" - -namespace { - -const char * TAG = "ipv6only"; - -constexpr size_t kUdpBufferSize = 512; - -constexpr size_t kRpcStackSizeBytes = (6 * 1024); -constexpr uint8_t kRpcTaskPriority = 5; -constexpr size_t kTestStackSizeBytes = (8 * 1024); -constexpr uint8_t kTestTaskPriority = 5; - -TaskHandle_t rpcTaskHandle; -TaskHandle_t testTaskHandle; - -void UdpReceiver(void * pvParameters) -{ - int portno; // port to listen on - struct sockaddr_in6 serveraddr; // server's addr - char buf[kUdpBufferSize]; // rx message buf - char * hostaddrp; // dotted decimal host addr string - int optval; // flag value for setsockopt - int n; // message byte size - int sockfd = 0; - socklen_t clientlen; // byte size of client's address - struct sockaddr_in6 clientaddr; // client addr - - while (1) - { - // Start the udp server after the wifi is connectd. - chip::rpc::WiFi::Instance().BlockUntilWiFiConnected(); - ESP_LOGI(TAG, "UDP server starting"); - - portno = 8765; - // socket: create the parent socket - sockfd = socket(AF_INET6, SOCK_DGRAM, 0); - if (sockfd < 0) - { - ESP_LOGE(TAG, "ERROR opening socket"); - assert(0); - return; - } - - // setsockopt: Handy debugging trick that lets - // us rerun the server immediately after we kill it; - // otherwise we have to wait about 20 secs. - // Eliminates "ERROR on binding: Address already in use" error. - optval = 1; - setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, static_cast(&optval), sizeof(int)); - - // build the server's Internet address - memset(&serveraddr, 0, sizeof(serveraddr)); - serveraddr.sin6_len = sizeof(serveraddr); - serveraddr.sin6_family = AF_INET6; - serveraddr.sin6_addr = in6addr_any; - serveraddr.sin6_port = htons((unsigned short) portno); - - // bind: associate the parent socket with a port - if (bind(sockfd, reinterpret_cast(&serveraddr), sizeof(serveraddr)) < 0) - { - ESP_LOGE(TAG, "ERROR on binding"); - assert(0); - vTaskDelete(NULL); - } - - ESP_LOGI(TAG, "UDP server bound to port %d", portno); - - // main loop: wait for a datagram, then respond - clientlen = sizeof(clientaddr); - wifi_ap_record_t ap_info; - fd_set readset; - while (ESP_OK == esp_wifi_sta_get_ap_info(&ap_info)) - { - // recvfrom: receive a UDP datagram from a client - memset(buf, 0, sizeof(buf)); - - FD_ZERO(&readset); - FD_SET(sockfd, &readset); - - int select_err = select(sockfd + 1, &readset, nullptr, nullptr, nullptr); - if (select_err < 0) - continue; - - n = recvfrom(sockfd, buf, kUdpBufferSize, 0, reinterpret_cast(&clientaddr), &clientlen); - if (n < 0) - continue; - // Echo back - n = sendto(sockfd, buf, n, 0, reinterpret_cast(&clientaddr), clientlen); - } - } - // Never returns -} - -void RegisterServices(pw::rpc::Server & server) -{ - server.RegisterService(chip::rpc::WiFi::Instance()); -} - -void RunRpcService(void *) -{ - ::chip::rpc::Start(RegisterServices, &::chip::rpc::logger_mutex); -} - -} // namespace - -extern "C" void app_main() -{ - PigweedLogger::init(); - - // Initialize NVS - esp_err_t ret = nvs_flash_init(); - if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) - { - ESP_ERROR_CHECK(nvs_flash_erase()); - ret = nvs_flash_init(); - } - ESP_ERROR_CHECK(ret); - - ESP_LOGI(TAG, "WiFi Init: %s", pw_StatusString(chip::rpc::WiFi::Instance().Init())); - ESP_LOGI(TAG, "----------- chip-esp32-ipv6-example starting -----------"); - - xTaskCreate(RunRpcService, "RPC", kRpcStackSizeBytes / sizeof(StackType_t), nullptr, kRpcTaskPriority, &rpcTaskHandle); - xTaskCreate(UdpReceiver, "TestTask", kTestStackSizeBytes / sizeof(StackType_t), nullptr, kTestTaskPriority, &testTaskHandle); -} diff --git a/examples/ipv6only-app/esp32/main/wifi_service.cpp b/examples/ipv6only-app/esp32/main/wifi_service.cpp deleted file mode 100644 index 3b51c44eac891a..00000000000000 --- a/examples/ipv6only-app/esp32/main/wifi_service.cpp +++ /dev/null @@ -1,341 +0,0 @@ -/* - * - * Copyright (c) 2021 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. - */ -#include "wifi_service.h" - -#include "freertos/FreeRTOS.h" -#include "freertos/event_groups.h" -#include "pw_containers/flat_map.h" - -namespace chip { -namespace rpc { - -namespace { - -const char * TAG = "ipv6only"; - -constexpr pw::containers::FlatMap kChannelToFreqMap({ { - { 1, 2412 }, { 2, 2417 }, { 3, 2422 }, { 4, 2427 }, { 5, 2432 }, { 6, 2437 }, { 7, 2442 }, { 8, 2447 }, - { 9, 2452 }, { 10, 2457 }, { 11, 2462 }, { 12, 2467 }, { 13, 2472 }, { 14, 2484 }, { 32, 5160 }, { 34, 5170 }, - { 36, 5180 }, { 38, 5190 }, { 40, 5200 }, { 42, 5210 }, { 44, 5220 }, { 46, 5230 }, { 48, 5240 }, { 50, 5250 }, - { 52, 5260 }, { 54, 5270 }, { 56, 5280 }, { 58, 5290 }, { 60, 5300 }, { 62, 5310 }, { 64, 5320 }, { 68, 5340 }, - { 96, 5480 }, { 100, 5500 }, { 102, 5510 }, { 104, 5520 }, { 106, 5530 }, { 108, 5540 }, { 110, 5550 }, { 112, 5560 }, - { 114, 5570 }, { 116, 5580 }, { 118, 5590 }, { 120, 5600 }, { 122, 5610 }, { 124, 5620 }, { 126, 5630 }, { 128, 5640 }, - { 132, 5660 }, { 134, 5670 }, { 136, 5680 }, { 138, 5690 }, { 140, 5700 }, { 142, 5710 }, { 144, 5720 }, { 149, 5745 }, - { 151, 5755 }, { 153, 5765 }, { 155, 5775 }, { 157, 5785 }, { 159, 5795 }, { 161, 5805 }, { 165, 5825 }, { 169, 5845 }, - { 173, 5865 }, { 183, 4915 }, { 184, 4920 }, { 185, 4925 }, { 187, 4935 }, { 188, 4940 }, { 189, 4945 }, { 192, 4960 }, - { 196, 4980 }, -} }); - -// Class handles the event handlers needed for station startup. -// Creating the object will register all handlers needed, destroying will -// unregister. The object is only needed during initialization, after the station -// is up it is safe to destroy this object. -class WiFiInitStationEventHandler -{ -public: - WiFiInitStationEventHandler() - { - handler_context_.event_group = xEventGroupCreate(); - esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &EventHandler, &handler_context_); - } - - ~WiFiInitStationEventHandler() - { - vEventGroupDelete(handler_context_.event_group); - esp_event_handler_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, &EventHandler); - } - - pw::Status WaitForStationUp() - { - EventBits_t bits = xEventGroupWaitBits(handler_context_.event_group, kWiFiStationUpBit, pdFALSE, pdFALSE, portMAX_DELAY); - if (!(bits & kWiFiStationUpBit)) - { - return pw::Status::Unknown(); - } - return pw::OkStatus(); - } - -private: - static constexpr uint8_t kWiFiStationUpBit = BIT0; - struct HandlerContext - { - size_t retry_count = 0; - uint8_t error_code = 0; - EventGroupHandle_t event_group; - } handler_context_; - - static void EventHandler(void * arg, esp_event_base_t event_base, int32_t event_id, void * event_data) - { - HandlerContext * context = static_cast(arg); - if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) - { - ESP_LOGI(TAG, "EVENT: WIFI_EVENT_STATION_START"); - xEventGroupSetBits(context->event_group, kWiFiStationUpBit); - } - } -}; - -// Class handles the event handlers needed for wifi connection. -// Creating the object will register all handlers needed, destroying will -// unregister. The object is only needed during connection, once connected -// is up it is safe to destroy this object. -class WiFiConnectionEventHandler -{ -public: - WiFiConnectionEventHandler(esp_netif_t * esp_netif) - { - handler_context_.esp_netif = esp_netif; - handler_context_.event_group = xEventGroupCreate(); - esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &EventHandler, &handler_context_); - esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &EventHandler, &handler_context_); - esp_event_handler_register(IP_EVENT, IP_EVENT_GOT_IP6, &EventHandler, &handler_context_); - } - - ~WiFiConnectionEventHandler() - { - esp_event_handler_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, &EventHandler); - esp_event_handler_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, &EventHandler); - esp_event_handler_unregister(IP_EVENT, IP_EVENT_STA_GOT_IP, &EventHandler); - esp_event_handler_unregister(IP_EVENT, IP_EVENT_GOT_IP6, &EventHandler); - vEventGroupDelete(handler_context_.event_group); - } - - // Waits for the events to determine if connected successfully. - pw::Status WaitForConnection(chip_rpc_ConnectionResult * result) - { - EventBits_t bits = xEventGroupWaitBits(handler_context_.event_group, kWiFiFailBit | kWiFiIpv6ConnectedBit, pdFALSE, pdFALSE, - portMAX_DELAY); - if (bits & kWiFiIpv6ConnectedBit) - { - result->error = chip_rpc_CONNECTION_ERROR_OK; - } - else if (bits & kWiFiFailBit) - { - result->error = handler_context_.error_code; - return pw::Status::Unavailable(); - } - else - { - ESP_LOGE(TAG, "UNEXPECTED EVENT"); - return pw::Status::Unknown(); - } - return pw::OkStatus(); - } - -private: - static constexpr size_t kWiFiConnectRetryMax = 5; - static constexpr uint8_t kWiFiIpv6ConnectedBit = BIT0; - static constexpr uint8_t kWiFiIpv4ConnectedBit = BIT1; - static constexpr uint8_t kWiFiFailBit = BIT2; - - struct HandlerContext - { - size_t retry_count = 0; - enum _chip_rpc_CONNECTION_ERROR error_code; - EventGroupHandle_t event_group; - esp_netif_t * esp_netif; - } handler_context_; - - static void EventHandler(void * arg, esp_event_base_t event_base, int32_t event_id, void * event_data) - { - HandlerContext * context = static_cast(arg); - if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) - { - ESP_LOGI(TAG, "EVENT: WIFI_EVENT_STA_DISCONNECTED, reason: %d", - (static_cast(event_data))->reason); - if (context->retry_count < kWiFiConnectRetryMax) - { - esp_wifi_connect(); - context->retry_count++; - ESP_LOGI(TAG, "retry to connect to the AP"); - } - else - { - context->error_code = - static_cast<_chip_rpc_CONNECTION_ERROR>((static_cast(event_data))->reason); - xEventGroupSetBits(context->event_group, kWiFiFailBit); - } - } - else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_CONNECTED) - { - ESP_ERROR_CHECK(esp_netif_create_ip6_linklocal(context->esp_netif)); - ESP_LOGI(TAG, "Connected, link local address created"); - } - else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) - { - auto * event = static_cast(event_data); - ESP_LOGI(TAG, "got ip4: " IPSTR, IP2STR(&event->ip_info.ip)); - xEventGroupSetBits(context->event_group, kWiFiIpv4ConnectedBit); - } - else if (event_base == IP_EVENT && event_id == IP_EVENT_GOT_IP6) - { - auto * event = static_cast(event_data); - ESP_LOGI(TAG, "got ip6: " IPV6STR, IPV62STR(event->ip6_info.ip)); - xEventGroupSetBits(context->event_group, kWiFiIpv6ConnectedBit); - } - } -}; - -// These are potentially large objects for the scan results. -constexpr size_t kScanRecordsMax = sizeof(chip_rpc_ScanResults().aps) / sizeof(chip_rpc_ScanResult); -chip_rpc_ScanResults out_scan_records; -wifi_ap_record_t scan_records[kScanRecordsMax] = { 0 }; - -} // namespace - -WiFi WiFi::instance_; - -pw::Status WiFi::Init() -{ - wifi_connected_semaphore_ = xSemaphoreCreateBinary(); - PW_TRY(EspToPwStatus(esp_netif_init())); - PW_TRY(EspToPwStatus(esp_event_loop_create_default())); - esp_netif_ = esp_netif_create_default_wifi_sta(); - PW_TRY(EspToPwStatus(esp_netif_dhcpc_stop(esp_netif_))); - - WiFiInitStationEventHandler event_handler; - - wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); - PW_TRY(EspToPwStatus(esp_wifi_init(&cfg))); - PW_TRY(EspToPwStatus(esp_wifi_set_mode(WIFI_MODE_STA))); - PW_TRY(EspToPwStatus(esp_wifi_start())); - - PW_TRY(event_handler.WaitForStationUp()); - return pw::OkStatus(); -} - -pw::Status WiFi::Connect(const chip_rpc_ConnectionData & request, chip_rpc_ConnectionResult & response) -{ - wifi_config_t wifi_config { - .sta = { - /* Setting a password implies station will connect to all security modes including WEP/WPA. - * However these modes are deprecated and not advisable to be used. Incase your Access point - * doesn't support WPA2, these mode can be enabled by commenting below line */ - .threshold = { - .authmode = static_cast(request.security_type), - }, - - .pmf_cfg = { - .capable = true, - .required = false - }, - }, - }; - memcpy(wifi_config.sta.ssid, request.ssid.bytes, - std::min(sizeof(wifi_config.sta.ssid), static_cast(request.ssid.size))); - memcpy(wifi_config.sta.password, request.secret.bytes, - std::min(sizeof(wifi_config.sta.password), static_cast(request.secret.size))); - - WiFiConnectionEventHandler event_handler(esp_netif_); - PW_TRY(EspToPwStatus(esp_wifi_set_config(WIFI_IF_STA, &wifi_config))); - esp_err_t err = esp_wifi_connect(); - - if (ESP_ERR_WIFI_SSID == err) - { - ESP_LOGI(TAG, "AP not found SSID:%s", wifi_config.sta.ssid); - response.error = chip_rpc_CONNECTION_ERROR_NO_AP_FOUND; - return pw::Status::NotFound(); - } - if (pw::Status status = event_handler.WaitForConnection(&response); status.ok()) - { - ESP_LOGI(TAG, "connected to ap SSID:%s password:%s", wifi_config.sta.ssid, wifi_config.sta.password); - xSemaphoreGive(wifi_connected_semaphore_); - } - else - { - ESP_LOGI(TAG, "Failed to connect to SSID:%s, password:%s", wifi_config.sta.ssid, wifi_config.sta.password); - return status; - } - return pw::OkStatus(); -} - -void WiFi::StartScan(const chip_rpc_ScanConfig & request, ServerWriter & writer) -{ - wifi_scan_config_t scan_config{ 0 }; - if (request.ssid_count != 0) - { - scan_config.ssid = const_cast(reinterpret_cast(request.ssid[0].bytes)); - } - if (request.bssid_count != 0) - { - scan_config.bssid = const_cast(reinterpret_cast(request.bssid[0].bytes)); - } - scan_config.channel = request.channel; - scan_config.show_hidden = request.show_hidden; - scan_config.scan_type = static_cast(request.active_scan); - if (request.active_scan) - { - scan_config.scan_time.active.min = request.scan_time_min_ms; - scan_config.scan_time.active.max = request.scan_time_max_ms; - } - else - { - scan_config.scan_time.passive = request.scan_time_min_ms; - } - - auto err = esp_wifi_scan_start(&scan_config, true /* block */); - if (ESP_OK != err) - { - ESP_LOGI(TAG, "Error starting scan: %d", err); - return; - } - - // Output scan results - uint16_t num_scan_records = kScanRecordsMax; - err = esp_wifi_scan_get_ap_records(&num_scan_records, scan_records); - if (ESP_OK != err) - { - ESP_LOGI(TAG, "Error getting scanned APs: %d", err); - num_scan_records = 0; - } - ESP_LOGI(TAG, "%d", num_scan_records); - out_scan_records.aps_count = num_scan_records; - - for (size_t i = 0; i < num_scan_records; ++i) - { - memcpy(out_scan_records.aps[i].ssid.bytes, scan_records[i].ssid, sizeof(out_scan_records.aps[i].ssid.bytes)); - out_scan_records.aps[i].ssid.size = sizeof(out_scan_records.aps[i].ssid.bytes); - memcpy(out_scan_records.aps[i].bssid.bytes, scan_records[i].bssid, sizeof(out_scan_records.aps[i].bssid.bytes)); - out_scan_records.aps[i].bssid.size = sizeof(out_scan_records.aps[i].bssid.bytes); - out_scan_records.aps[i].security_type = static_cast(scan_records[i].authmode); - out_scan_records.aps[i].channel = scan_records[i].primary; - auto found_channel = kChannelToFreqMap.find(scan_records[i].primary); - out_scan_records.aps[i].frequency = (found_channel ? found_channel->second : 0); - out_scan_records.aps[i].signal = scan_records[i].rssi; - } - writer.Write(out_scan_records); - writer.Finish(); -} - -void WiFi::WiFiEventHandler(void * arg, esp_event_base_t event_base, int32_t event_id, void * event_data) -{ - if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) - { - ESP_LOGI(TAG, "******** DISCONNECTED FROM AP *********"); - esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, &WiFiEventHandler); - esp_event_handler_unregister(IP_EVENT, IP_EVENT_GOT_IP6, &WiFiEventHandler); - } - else if (event_base == IP_EVENT && event_id == IP_EVENT_GOT_IP6) - { - // This is in case not only link-local address is provided - auto * event = static_cast(event_data); - ESP_LOGI(TAG, "got ip6 :" IPV6STR, IPV62STR(event->ip6_info.ip)); - } -} - -} // namespace rpc -} // namespace chip diff --git a/examples/ipv6only-app/esp32/partitions.csv b/examples/ipv6only-app/esp32/partitions.csv deleted file mode 100644 index b338ff11a11589..00000000000000 --- a/examples/ipv6only-app/esp32/partitions.csv +++ /dev/null @@ -1,6 +0,0 @@ -# Name, Type, SubType, Offset, Size, Flags -# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap -nvs, data, nvs, , 0x6000, -phy_init, data, phy, , 0x1000, -# Factory partition size about 1.9MB -factory, app, factory, , 1945K, diff --git a/examples/ipv6only-app/esp32/sdkconfig.defaults b/examples/ipv6only-app/esp32/sdkconfig.defaults deleted file mode 100644 index e4ce5edbb3c0fd..00000000000000 --- a/examples/ipv6only-app/esp32/sdkconfig.defaults +++ /dev/null @@ -1,43 +0,0 @@ -# -# Copyright (c) 2021 Project CHIP Authors -# Copyright (c) 2018 Nest Labs, Inc. -# All rights reserved. -# -# 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. -# -# Description: -# Some useful defaults for the demo app configuration. -# - - -# Default to 921600 baud when flashing and monitoring device -CONFIG_ESPTOOLPY_BAUD_921600B=y -CONFIG_ESPTOOLPY_BAUD=921600 -CONFIG_ESPTOOLPY_COMPRESSED=y -CONFIG_ESPTOOLPY_MONITOR_BAUD_115200B=y -CONFIG_ESPTOOLPY_MONITOR_BAUD=115200 - -# UART -CONFIG_ESP_CONSOLE_UART_CUSTOM=y -CONFIG_ESP_CONSOLE_UART_CUSTOM_NUM_1=y -CONFIG_ESP_CONSOLE_UART_NUM=1 - -#enable lwip ipv6 autoconfig -CONFIG_LWIP_IPV6_AUTOCONFIG=y - -# Use a custom partition table -CONFIG_PARTITION_TABLE_CUSTOM=y -CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" - -# Enable Pigweed RPC Library in CHIP -CONFIG_ENABLE_PW_RPC=y diff --git a/examples/ipv6only-app/esp32/third_party/connectedhomeip b/examples/ipv6only-app/esp32/third_party/connectedhomeip deleted file mode 120000 index 11a54ed360106c..00000000000000 --- a/examples/ipv6only-app/esp32/third_party/connectedhomeip +++ /dev/null @@ -1 +0,0 @@ -../../../../ \ No newline at end of file