diff --git a/.github/workflows/pear-ci.yml b/.github/workflows/build.yml similarity index 65% rename from .github/workflows/pear-ci.yml rename to .github/workflows/build.yml index d387c66..f30147a 100644 --- a/.github/workflows/pear-ci.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: pear-ci +name: build on: [push] @@ -14,16 +14,7 @@ jobs: - name: install run: > sudo apt-get update && sudo apt-get --no-install-recommends -y install - libglib2.0-dev cmake - ninja-build - libssl-dev - - name: python - run: > - sudo pip3 install meson - - name: deps - run: > - ./build-third-party.sh - name: build run: > mkdir cmake ; diff --git a/.gitignore b/.gitignore index aa077cd..a3ea3e4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ cmake -dist diff --git a/CMakeLists.txt b/CMakeLists.txt index 836383e..b6302f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,12 +3,13 @@ project(peer) option(ENABLE_TESTS "Enable tests" OFF) +include(ExternalProject) include(third_party/coreHTTP/httpFilePaths.cmake) include(third_party/coreMQTT/mqttFilePaths.cmake) -include_directories(dist/include dist/include/cjson) +include_directories(${CMAKE_BINARY_DIR}/dist/include ${CMAKE_BINARY_DIR}/dist/include/cjson) -link_directories(dist/lib) +link_directories(${CMAKE_BINARY_DIR}/dist/lib) set(DEP_LIBS "srtp2" "usrsctp" "mbedtls" "mbedcrypto" "mbedx509" "cjson") # Extended debug information (symbols, source code, and macro definitions) @@ -24,3 +25,43 @@ if(ENABLE_TESTS) add_subdirectory(tests) endif() +ExternalProject_Add(cjson + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/cJSON + CMAKE_ARGS + -DCMAKE_C_FLAGS="-fPIC" + -DBUILD_SHARED_LIBS=off + -DENABLE_CJSON_TEST=off + -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/dist + -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} +) + +ExternalProject_Add(mbedtls + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/mbedtls + CMAKE_ARGS + -DCMAKE_C_FLAGS="-fPIC" + -DENABLE_TESTING=off + -DENABLE_PROGRAMS=off + -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/dist + -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} +) +file(READ ${CMAKE_CURRENT_SOURCE_DIR}/third_party/mbedtls/include/mbedtls/mbedtls_config.h INPUT_CONTENT) +string(REPLACE "//#define MBEDTLS_SSL_DTLS_SRTP" "#define MBEDTLS_SSL_DTLS_SRTP" MODIFIED_CONTENT ${INPUT_CONTENT}) +file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/third_party/mbedtls/include/mbedtls/mbedtls_config.h ${MODIFIED_CONTENT}) + +ExternalProject_Add(srtp2 + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/libsrtp + CMAKE_ARGS + -DCMAKE_C_FLAGS="-fPIC" + -DTEST_APPS=off + -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/dist + -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} +) + +ExternalProject_Add(usrsctp + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/usrsctp + CMAKE_ARGS + -DCMAKE_C_FLAGS="-fPIC" + -Dsctp_build_programs=off + -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/dist + -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} +) diff --git a/build-third-party.sh b/build-third-party.sh deleted file mode 100755 index f6a7627..0000000 --- a/build-third-party.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash - -BASE_PATH=$(readlink -f $0) -BASE_DIR=$(dirname $BASE_PATH) - -mkdir -p $BASE_DIR/dist/ - -# Build libsrtp -cd $BASE_DIR/third_party/libsrtp -mkdir -p build && cd build -cmake -DCMAKE_C_FLAGS="-fPIC" -DTEST_APPS=off -DCMAKE_INSTALL_PREFIX=$BASE_DIR/dist .. -make -j4 -make install - -# Build cJSON -cd $BASE_DIR/third_party/cJSON -mkdir -p build && cd build -cmake -DCMAKE_C_FLAGS="-fPIC" -DBUILD_SHARED_LIBS=off -DENABLE_CJSON_TEST=off -DCMAKE_INSTALL_PREFIX=$BASE_DIR/dist .. -make -j4 -make install -# keep the path consistent with esp-idf -ln -s $BASE_DIR/dist/include/cjson/cJSON.h $BASE_DIR/dist/include/cJSON.h - -# Build mbedTLS -cd $BASE_DIR/third_party/mbedtls -sed -i 's/\/\/#define MBEDTLS_SSL_DTLS_SRTP/#define MBEDTLS_SSL_DTLS_SRTP/g' include/mbedtls/mbedtls_config.h -mkdir -p build && cd build -cmake -DCMAKE_C_FLAGS="-fPIC" -DENABLE_TESTING=off -DENABLE_PROGRAMS=off -DCMAKE_INSTALL_PREFIX=$BASE_DIR/dist .. -make install - -cd $BASE_DIR/third_party/usrsctp -mkdir -p build && cd build -cmake -DCMAKE_C_FLAGS="-fPIC" -Dsctp_build_programs=off -DCMAKE_INSTALL_PREFIX=$BASE_DIR/dist .. -make -j4 -make install - diff --git a/examples/esp32/.gitignore b/examples/esp32/.gitignore index b7521d7..debe0fe 100644 --- a/examples/esp32/.gitignore +++ b/examples/esp32/.gitignore @@ -3,3 +3,4 @@ build dependencies.lock managed_components sdkconfig +sdkconfig.old diff --git a/examples/esp32/README.md b/examples/esp32/README.md index 42f1af0..8eff8eb 100644 --- a/examples/esp32/README.md +++ b/examples/esp32/README.md @@ -21,10 +21,8 @@ $ source export.sh ### Download ```bash -$ git clone https://github.com/sepfy/libpeer +$ git clone --recursive https://github.com/sepfy/libpeer $ cd libpeer/examples/esp32 -$ idf.py add-dependency "espressif/esp32-camera^2.0.4" -$ idf.py add-dependency "mdns" $ git clone --recursive https://github.com/sepfy/esp_ports.git components/srtp ``` diff --git a/examples/esp32/components/peer/CMakeLists.txt b/examples/esp32/components/peer/CMakeLists.txt index df40339..0036589 100644 --- a/examples/esp32/components/peer/CMakeLists.txt +++ b/examples/esp32/components/peer/CMakeLists.txt @@ -16,7 +16,7 @@ file(GLOB CODES "${PEER_PROJECT_PATH}/src/*.c") idf_component_register( SRCS ${CODES} ${HTTP_SOURCES} ${MQTT_SOURCES} ${MQTT_SERIALIZER_SOURCES} INCLUDE_DIRS "${PEER_PROJECT_PATH}/src" ${HTTP_INCLUDE_PUBLIC_DIRS} ${MQTT_INCLUDE_PUBLIC_DIRS} - REQUIRES mbedtls srtp json mdns + REQUIRES mbedtls srtp json esp_netif ) add_definitions("-DESP32 -DHTTP_DO_NOT_USE_CUSTOM_CONFIG -DMQTT_DO_NOT_USE_CUSTOM_CONFIG") diff --git a/examples/esp32/main/CMakeLists.txt b/examples/esp32/main/CMakeLists.txt index 52679d9..424fc44 100644 --- a/examples/esp32/main/CMakeLists.txt +++ b/examples/esp32/main/CMakeLists.txt @@ -1,5 +1,5 @@ idf_component_register(SRCS - "app_main.c" "camera.c" + "app_main.c" "camera.c" "audio.c" INCLUDE_DIRS "." ) diff --git a/examples/esp32/main/app_main.c b/examples/esp32/main/app_main.c index a34db1e..6dfd2d0 100644 --- a/examples/esp32/main/app_main.c +++ b/examples/esp32/main/app_main.c @@ -22,12 +22,16 @@ static const char *TAG = "webrtc"; static TaskHandle_t xPcTaskHandle = NULL; -static TaskHandle_t xCameraTaskHandle = NULL; static TaskHandle_t xPsTaskHandle = NULL; +static TaskHandle_t xCameraTaskHandle = NULL; +static TaskHandle_t xAudioTaskHandle = NULL; extern esp_err_t camera_init(); +extern esp_err_t audio_init(); extern void camera_task(void *pvParameters); -extern void wifi_init_sta(); +extern void audio_task(void *pvParameters); + +SemaphoreHandle_t xSemaphore = NULL; PeerConnection *g_pc; PeerConnectionState eState = PEER_CONNECTION_CLOSED; @@ -50,9 +54,9 @@ static void oniceconnectionstatechange(PeerConnectionState state, void *user_dat } } -static void onmessasge(char *msg, size_t len, void *userdata) { +static void onmessage(char *msg, size_t len, void *userdata, uint16_t sid) { - ESP_LOGI(TAG, "Datachannel message: %.*s, size", len, msg); + ESP_LOGI(TAG, "Datachannel message: %.*s", len, msg); } void onopen(void *userdata) { @@ -84,7 +88,10 @@ void peer_connection_task(void *arg) { for(;;) { - peer_connection_loop(g_pc); + if (xSemaphoreTake(xSemaphore, portMAX_DELAY)) { + peer_connection_loop(g_pc); + xSemaphoreGive(xSemaphore); + } vTaskDelay(pdMS_TO_TICKS(1)); } @@ -99,6 +106,7 @@ void app_main(void) { .ice_servers = { { .urls = "stun:stun.l.google.com:19302" } }, + .audio_codec = CODEC_PCMA, .datachannel = DATA_CHANNEL_BINARY, }; @@ -117,7 +125,6 @@ void app_main(void) { ESP_ERROR_CHECK(nvs_flash_init()); ESP_ERROR_CHECK(esp_netif_init()); ESP_ERROR_CHECK(esp_event_loop_create_default()); - ESP_ERROR_CHECK(mdns_init()); ESP_ERROR_CHECK(example_connect()); if (esp_read_mac(mac, ESP_MAC_WIFI_STA) == ESP_OK) { @@ -125,21 +132,38 @@ void app_main(void) { ESP_LOGI(TAG, "Device ID: %s", deviceid); } + xSemaphore = xSemaphoreCreateMutex(); + peer_init(); camera_init(); +#if defined(CONFIG_ESP32S3_XIAO_SENSE) + audio_init(); +#endif + g_pc = peer_connection_create(&config); peer_connection_oniceconnectionstatechange(g_pc, oniceconnectionstatechange); - peer_connection_ondatachannel(g_pc, onmessasge, onopen, onclose); + peer_connection_ondatachannel(g_pc, onmessage, onopen, onclose); + + ServiceConfiguration service_config = SERVICE_CONFIG_DEFAULT(); + service_config.client_id = deviceid; + service_config.pc = g_pc; + service_config.mqtt_url = "broker.emqx.io"; + peer_signaling_set_config(&service_config); + peer_signaling_join_channel(); peer_signaling_join_channel(deviceid, g_pc); - xTaskCreatePinnedToCore(camera_task, "camera", 4096, NULL, 6, &xCameraTaskHandle, 0); +#if defined(CONFIG_ESP32S3_XIAO_SENSE) + xTaskCreatePinnedToCore(audio_task, "audio", 8192, NULL, 7, &xAudioTaskHandle, 0); +#endif + + xTaskCreatePinnedToCore(camera_task, "camera", 4096, NULL, 8, &xCameraTaskHandle, 1); - xTaskCreatePinnedToCore(peer_connection_task, "peer_connection", 8192, NULL, 10, &xPcTaskHandle, 1); + xTaskCreatePinnedToCore(peer_connection_task, "peer_connection", 8192, NULL, 5, &xPcTaskHandle, 1); - xTaskCreatePinnedToCore(peer_signaling_task, "peer_signaling", 8192, NULL, 10, &xPsTaskHandle, 0); + xTaskCreatePinnedToCore(peer_signaling_task, "peer_signaling", 8192, NULL, 6, &xPsTaskHandle, 1); ESP_LOGI(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size()); ESP_LOGI(TAG, "open https://sepfy.github.io/webrtc?deviceId=%s", deviceid); diff --git a/examples/esp32s3/main/audio.c b/examples/esp32/main/audio.c similarity index 64% rename from examples/esp32s3/main/audio.c rename to examples/esp32/main/audio.c index 472c6a5..612766c 100644 --- a/examples/esp32s3/main/audio.c +++ b/examples/esp32/main/audio.c @@ -3,10 +3,10 @@ #include "esp_log.h" #include "driver/i2s_pdm.h" +#include "esp_audio_enc_default.h" +#include "esp_audio_enc_reg.h" +#include "esp_g711_enc.h" #include "esp_audio_enc.h" -#include "esp_audio_enc_def.h" -#include "esp_audio_def.h" -#include "esp_opus_enc.h" #include "peer_connection.h" @@ -24,51 +24,55 @@ i2s_chan_handle_t rx_handle = NULL; esp_audio_enc_handle_t enc_handle = NULL; esp_audio_enc_in_frame_t aenc_in_frame = { 0 }; esp_audio_enc_out_frame_t aenc_out_frame = { 0 }; +esp_g711_enc_config_t g711_cfg; +esp_audio_enc_config_t enc_cfg; esp_err_t audio_codec_init() { - uint8_t *inbuf = NULL; - uint8_t *outbuf = NULL; - int aenc_in_frame_size = 0; - int aenc_out_frame_size = 0; + uint8_t *read_buf = NULL; + uint8_t *write_buf = NULL; + int read_size = 0; + int out_size = 0; esp_audio_err_t ret = ESP_AUDIO_ERR_OK; - esp_opus_enc_config_t config = ESP_OPUS_ENC_CONFIG_DEFAULT(); - config.sample_rate = ESP_AUDIO_SAMPLE_RATE_8K; - config.channel = ESP_AUDIO_MONO; - config.bitrate = 18000; - config.frame_duration = ESP_OPUS_ENC_FRAME_DURATION_40_MS; + esp_audio_enc_register_default(); - ret = esp_opus_enc_open(&config, sizeof(esp_opus_enc_config_t), &enc_handle); + g711_cfg.sample_rate = ESP_AUDIO_SAMPLE_RATE_8K; + g711_cfg.channel = ESP_AUDIO_MONO; + g711_cfg.bits_per_sample = ESP_AUDIO_BIT16; + + enc_cfg.type = ESP_AUDIO_TYPE_G711A; + enc_cfg.cfg = &g711_cfg; + enc_cfg.cfg_sz = sizeof(g711_cfg); + + ret = esp_audio_enc_open(&enc_cfg, &enc_handle); if (ret != ESP_AUDIO_ERR_OK) { ESP_LOGE(TAG, "audio encoder open failed"); return ESP_FAIL; } - ret = esp_opus_enc_get_frame_size(enc_handle, &aenc_in_frame_size, &aenc_out_frame_size); - if (ret != ESP_AUDIO_ERR_OK) { - ESP_LOGE(TAG, "audio encoder get frame size failed"); - return ESP_FAIL; + int frame_size = (g711_cfg.bits_per_sample * g711_cfg.channel) >> 3; + // Get frame_size + esp_audio_enc_get_frame_size(enc_handle, &read_size, &out_size); + ESP_LOGI(TAG, "audio codec init. frame size: %d, read size: %d, out size: %d", frame_size, read_size, out_size); + // 8000HZ duration 20ms + if (frame_size == read_size) { + read_size *= 8000 / 1000 * 20; + out_size *= 8000 / 1000 * 20; } - - inbuf = calloc(1, aenc_in_frame_size*2); - if (!inbuf) { - ESP_LOGE(TAG, "inbuf malloc failed"); + read_buf = malloc(read_size); + write_buf = malloc(out_size); + if (read_buf == NULL || write_buf == NULL) { return ESP_FAIL; } - outbuf = calloc(1, aenc_out_frame_size); - if (!outbuf) { - ESP_LOGE(TAG, "outbuf malloc failed"); - return ESP_FAIL; - } + aenc_in_frame.buffer = read_buf; + aenc_in_frame.len = read_size; + aenc_out_frame.buffer = write_buf; + aenc_out_frame.len = out_size; - aenc_in_frame.buffer = inbuf; - aenc_in_frame.len = aenc_in_frame_size; - aenc_out_frame.buffer = outbuf; - aenc_out_frame.len = aenc_out_frame_size; - ESP_LOGI(TAG, "audio codec init done. in_frame_size=%d, out_frame_size=%d", aenc_in_frame_size, aenc_out_frame_size); + ESP_LOGI(TAG, "audio codec init done. in buffer size: %d, out buffer size: %d", read_size, out_size); return 0; } @@ -130,7 +134,7 @@ void audio_task(void *arg) { if (ret == aenc_in_frame.len) { - if (esp_opus_enc_process(enc_handle, &aenc_in_frame, &aenc_out_frame) == ESP_AUDIO_ERR_OK) { + if (esp_audio_enc_process(enc_handle, &aenc_in_frame, &aenc_out_frame) == ESP_AUDIO_ERR_OK) { peer_connection_send_audio(g_pc, aenc_out_frame.buffer, aenc_out_frame.encoded_bytes); diff --git a/examples/esp32/main/camera.c b/examples/esp32/main/camera.c index 337ac05..edec5f3 100644 --- a/examples/esp32/main/camera.c +++ b/examples/esp32/main/camera.c @@ -14,6 +14,7 @@ extern PeerConnection *g_pc; extern int gDataChannelOpened; extern PeerConnectionState eState; +extern SemaphoreHandle_t xSemaphore; extern int get_timestamp(); static const char *TAG = "Camera"; @@ -134,7 +135,10 @@ void camera_task(void *pvParameters) { } //ESP_LOGI(TAG, "Camera captured. size=%zu, timestamp=%llu", fb->len, fb->timestamp); - peer_connection_datachannel_send(g_pc, (char*)fb->buf, fb->len); + if (xSemaphoreTake(xSemaphore, portMAX_DELAY)) { + peer_connection_datachannel_send(g_pc, (char*)fb->buf, fb->len); + xSemaphoreGive(xSemaphore); + } fps++; @@ -148,8 +152,7 @@ void camera_task(void *pvParameters) { esp_camera_fb_return(fb); } - // 10 FPS - vTaskDelay(pdMS_TO_TICKS(1000/10)); + vTaskDelay(pdMS_TO_TICKS(1000/20)); } } diff --git a/examples/esp32/main/idf_component.yml b/examples/esp32/main/idf_component.yml index e6cf4bd..8975ba1 100644 --- a/examples/esp32/main/idf_component.yml +++ b/examples/esp32/main/idf_component.yml @@ -1,6 +1,6 @@ ## IDF Component Manager Manifest File dependencies: - espressif/mdns: "*" + espressif/esp_audio_codec: "^2.0.0" espressif/esp32-camera: "^2.0.4" protocol_examples_common: path: ${IDF_PATH}/examples/common_components/protocol_examples_common diff --git a/examples/esp32/sdkconfig.defaults b/examples/esp32/sdkconfig.defaults index 7287cb7..c6537a9 100644 --- a/examples/esp32/sdkconfig.defaults +++ b/examples/esp32/sdkconfig.defaults @@ -1,23 +1,28 @@ # This file was generated using idf.py save-defconfig. It can be edited manually. # Espressif IoT Development Framework (ESP-IDF) 5.2.2 Project Minimal Configuration # +CONFIG_IDF_TARGET="esp32s3" CONFIG_APP_RETRIEVE_LEN_ELF_SHA=16 CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_ESP32S3_XIAO_SENSE=y +CONFIG_EXAMPLE_WIFI_SSID="myssid" +CONFIG_EXAMPLE_WIFI_PASSWORD="mypassword" CONFIG_EXAMPLE_CONNECT_IPV6=n CONFIG_ESP_PHY_REDUCE_TX_POWER=y CONFIG_SPIRAM=y -CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY=y +CONFIG_SPIRAM_MODE_OCT=y +CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=2048 CONFIG_ESP_MAIN_TASK_STACK_SIZE=8102 -CONFIG_ESP_INT_WDT_TIMEOUT_MS=300 CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1=n CONFIG_ESP_IPC_TASK_STACK_SIZE=2048 +CONFIG_ESP_WIFI_DYNAMIC_RX_BUFFER_NUM=16 +CONFIG_ESP_WIFI_STATIC_TX_BUFFER_NUM=32 +CONFIG_ESP_WIFI_CACHE_TX_BUFFER_NUM=64 CONFIG_LWIP_IPV6_AUTOCONFIG=y CONFIG_LWIP_IPV6_DHCP6=y CONFIG_LWIP_TCP_SND_BUF_DEFAULT=5744 CONFIG_LWIP_TCP_WND_DEFAULT=5744 CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC=y CONFIG_MBEDTLS_SSL_PROTO_DTLS=y -CONFIG_MDNS_TASK_STACK_SIZE=2048 -CONFIG_MDNS_NETWORKING_SOCKET=y diff --git a/examples/esp32s3/.gitignore b/examples/esp32s3/.gitignore deleted file mode 120000 index 014029e..0000000 --- a/examples/esp32s3/.gitignore +++ /dev/null @@ -1 +0,0 @@ -../esp32/.gitignore \ No newline at end of file diff --git a/examples/esp32s3/CMakeLists.txt b/examples/esp32s3/CMakeLists.txt deleted file mode 100644 index 7149a78..0000000 --- a/examples/esp32s3/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -# The following four 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.16) - -include($ENV{IDF_PATH}/tools/cmake/project.cmake) -project(esp32-peer) - diff --git a/examples/esp32s3/README.md b/examples/esp32s3/README.md deleted file mode 100644 index 7b27622..0000000 --- a/examples/esp32s3/README.md +++ /dev/null @@ -1,40 +0,0 @@ -# ESP32-S3 -Push H.264 video and OPUS audio to the WebRTC media server, such as Janus and ZLMediakit by WHIP - -## Instructions - -### Install esp-idf -at lease v5.2 -```bash -$ git clone -b v5.2.2 https://github.com/espressif/esp-idf.git -$ cd esp-idf -$ source install.sh -$ source export.sh -``` - -### Download -```bash -$ git clone --recursive https://github.com/sepfy/libpeer -$ cd libpeer/examples/esp32s3 -$ git clone --recursive https://github.com/sepfy/esp_ports.git components/srtp -``` - -### Configure -```bash -$ idf.py menuconfig -# Choose Example Connection Configuration and change the SSID and password -``` - -Modify the ```WHIP_HOST```, ```WHIP_PATH``` of ```src/config.h``` - -### Build -```bash -$ idf.py build -``` - -### Test -```bash -$ idf.py flash -``` - - diff --git a/examples/esp32s3/components/peer/CMakeLists.txt b/examples/esp32s3/components/peer/CMakeLists.txt deleted file mode 100644 index f54d2b4..0000000 --- a/examples/esp32s3/components/peer/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ - -set(COREMQTT_CMAKE_FILE ${CMAKE_SOURCE_DIR}/../../third_party/coreMQTT/mqttFilePaths.cmake) -set(COREHTTP_CMAKE_FILE ${CMAKE_SOURCE_DIR}/../../third_party/coreHTTP/httpFilePaths.cmake) -set(PEER_PROJECT_PATH "../../../..") - -if (EXISTS ${COREHTTP_CMAKE_FILE}) - include(${COREHTTP_CMAKE_FILE}) -endif() - -if (EXISTS ${COREMQTT_CMAKE_FILE}) - include(${COREMQTT_CMAKE_FILE}) -endif() - -file(GLOB CODES "${PEER_PROJECT_PATH}/src/*.c") - -idf_component_register( - SRCS ${CODES} ${HTTP_SOURCES} ${MQTT_SOURCES} ${MQTT_SERIALIZER_SOURCES} - INCLUDE_DIRS "${PEER_PROJECT_PATH}/src" ${HTTP_INCLUDE_PUBLIC_DIRS} ${MQTT_INCLUDE_PUBLIC_DIRS} - REQUIRES mbedtls srtp json mdns -) - -add_definitions("-DESP32 -DCONFIG_MQTT=0 -DCONFIG_HTTP=1 -DHTTP_DO_NOT_USE_CUSTOM_CONFIG -DMQTT_DO_NOT_USE_CUSTOM_CONFIG") - diff --git a/examples/esp32s3/main/CMakeLists.txt b/examples/esp32s3/main/CMakeLists.txt deleted file mode 100644 index bfad440..0000000 --- a/examples/esp32s3/main/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -idf_component_register(SRCS - "app_main.c" "audio.c" "video.c" - INCLUDE_DIRS "." -) - -target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") diff --git a/examples/esp32s3/main/Kconfig.projbuild b/examples/esp32s3/main/Kconfig.projbuild deleted file mode 120000 index 4cfd4d2..0000000 --- a/examples/esp32s3/main/Kconfig.projbuild +++ /dev/null @@ -1 +0,0 @@ -../../esp32/main/Kconfig.projbuild \ No newline at end of file diff --git a/examples/esp32s3/main/app_main.c b/examples/esp32s3/main/app_main.c deleted file mode 100644 index 074939c..0000000 --- a/examples/esp32s3/main/app_main.c +++ /dev/null @@ -1,101 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "esp_system.h" -#include "esp_partition.h" -#include "nvs_flash.h" -#include "esp_event.h" -#include "esp_netif.h" -#include "esp_mac.h" -#include "mdns.h" -#include "esp_log.h" -#include "esp_tls.h" -#include "esp_ota_ops.h" -#include "freertos/FreeRTOS.h" -#include "protocol_examples_common.h" -#include "peer.h" - -static const char *TAG = "webrtc"; - -static TaskHandle_t xPcTaskHandle = NULL; -static TaskHandle_t xAudioTaskHandle = NULL; -static TaskHandle_t xVideoTaskHandle = NULL; - -extern esp_err_t audio_init(); -extern esp_err_t video_init(); -extern void audio_task(void *pvParameters); -extern void video_task(void *pvParameters); - -PeerConnection *g_pc; -PeerConnectionState eState = PEER_CONNECTION_CLOSED; - -int64_t get_timestamp() { - - struct timeval tv; - gettimeofday(&tv, NULL); - return (tv.tv_sec * 1000LL + (tv.tv_usec / 1000LL)); -} - -static void oniceconnectionstatechange(PeerConnectionState state, void *user_data) { - - ESP_LOGI(TAG, "PeerConnectionState: %d", state); - eState = state; -} - -void peer_connection_task(void *arg) { - - ESP_LOGI(TAG, "peer_connection_task started"); - - for(;;) { - - peer_connection_loop(g_pc); - - vTaskDelay(pdMS_TO_TICKS(1)); - } -} - -void app_main(void) { - - PeerConfiguration config = { - .ice_servers = { - { .urls = "stun:stun.l.google.com:19302" } - }, - .audio_codec = CODEC_OPUS, - .video_codec = CODEC_H264 - }; - - ESP_LOGI(TAG, "[APP] Startup.."); - ESP_LOGI(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size()); - ESP_LOGI(TAG, "[APP] IDF version: %s", esp_get_idf_version()); - - esp_log_level_set("*", ESP_LOG_INFO); - esp_log_level_set("esp-tls", ESP_LOG_VERBOSE); - - ESP_ERROR_CHECK(nvs_flash_init()); - ESP_ERROR_CHECK(esp_netif_init()); - ESP_ERROR_CHECK(esp_event_loop_create_default()); - ESP_ERROR_CHECK(mdns_init()); - - ESP_ERROR_CHECK(example_connect()); - - audio_init(); - - video_init(); - - peer_init(); - - g_pc = peer_connection_create(&config); - peer_connection_oniceconnectionstatechange(g_pc, oniceconnectionstatechange); - peer_signaling_join_channel(NULL, g_pc); - - xTaskCreatePinnedToCore(audio_task, "audio", 20480, NULL, 5, &xAudioTaskHandle, 0); - - xTaskCreatePinnedToCore(video_task, "video", 10240, NULL, 6, &xVideoTaskHandle, 0); - - xTaskCreatePinnedToCore(peer_connection_task, "peer_connection", 8192, NULL, 10, &xPcTaskHandle, 1); - - ESP_LOGI(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size()); -} diff --git a/examples/esp32s3/main/idf_component.yml b/examples/esp32s3/main/idf_component.yml deleted file mode 100644 index 2b23153..0000000 --- a/examples/esp32s3/main/idf_component.yml +++ /dev/null @@ -1,22 +0,0 @@ -## IDF Component Manager Manifest File -dependencies: - espressif/esp_audio_codec: "^1.0.1" - espressif/esp_h264: "^0.1.1" - espressif/mdns: "*" - espressif/esp32-camera: "^2.0.4" - protocol_examples_common: - path: ${IDF_PATH}/examples/common_components/protocol_examples_common - ## Required IDF version - idf: - version: ">=4.1.0" - # # Put list of dependencies here - # # For components maintained by Espressif: - # component: "~1.0.0" - # # For 3rd party components: - # username/component: ">=1.0.0,<2.0.0" - # username2/component2: - # version: "~1.0.0" - # # For transient dependencies `public` flag can be set. - # # `public` flag doesn't have an effect dependencies of the `main` component. - # # All dependencies of `main` are public by default. - # public: true diff --git a/examples/esp32s3/main/video.c b/examples/esp32s3/main/video.c deleted file mode 100644 index 34bf546..0000000 --- a/examples/esp32s3/main/video.c +++ /dev/null @@ -1,186 +0,0 @@ -#include -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" - -#include "esp_log.h" -#include "esp_h264_enc.h" -#include "esp_camera.h" -#include "esp_timer.h" - -#include "peer_connection.h" - -extern PeerConnection *g_pc; -extern PeerConnectionState eState; -extern int get_timestamp(); -static const char *TAG = "VIDEO"; - -esp_h264_enc_t handle = NULL; -esp_h264_enc_frame_t out_frame = { 0 }; -esp_h264_raw_frame_t in_frame = { 0 }; -esp_h264_enc_cfg_t cfg = DEFAULT_H264_ENCODER_CONFIG(); - -#define CAM_PIN_PWDN -1 -#define CAM_PIN_RESET -1 -#define CAM_PIN_XCLK 10 -#define CAM_PIN_SIOD 40 -#define CAM_PIN_SIOC 39 -#define CAM_PIN_D7 48 -#define CAM_PIN_D6 11 -#define CAM_PIN_D5 12 -#define CAM_PIN_D4 14 -#define CAM_PIN_D3 16 -#define CAM_PIN_D2 18 -#define CAM_PIN_D1 17 -#define CAM_PIN_D0 15 -#define CAM_PIN_VSYNC 38 -#define CAM_PIN_HREF 47 -#define CAM_PIN_PCLK 13 - -static camera_config_t camera_config = { - - .ledc_timer = LEDC_TIMER_0, - .ledc_channel = LEDC_CHANNEL_0, - .pin_d7 = CAM_PIN_D7, - .pin_d6 = CAM_PIN_D6, - .pin_d5 = CAM_PIN_D5, - .pin_d4 = CAM_PIN_D4, - .pin_d3 = CAM_PIN_D3, - .pin_d2 = CAM_PIN_D2, - .pin_d1 = CAM_PIN_D1, - .pin_d0 = CAM_PIN_D0, - .pin_xclk = CAM_PIN_XCLK, - .pin_pclk = CAM_PIN_PCLK, - .pin_vsync = CAM_PIN_VSYNC, - .pin_href = CAM_PIN_HREF, - .pin_sccb_sda = CAM_PIN_SIOD, - .pin_sccb_scl = CAM_PIN_SIOC, - .pin_pwdn = CAM_PIN_PWDN, - .pin_reset = CAM_PIN_RESET, - .xclk_freq_hz = 10000000, - .pixel_format = PIXFORMAT_YUV422, - .frame_size = FRAMESIZE_96X96, - .jpeg_quality = 20, - .fb_count = 3, - .grab_mode = CAMERA_GRAB_WHEN_EMPTY, -}; - -esp_err_t video_init(){ - - esp_err_t err = esp_camera_init(&camera_config); - if (err != ESP_OK) { - ESP_LOGE(TAG, "Camera Init Failed"); - return err; - } - - int one_image_size = 0; - esp_h264_err_t ret = ESP_H264_ERR_OK; - - cfg.fps = 7; - cfg.height = 96; - cfg.width = 96; - cfg.pic_type = ESP_H264_RAW_FMT_YUV422; - one_image_size = cfg.height * cfg.width * 2.0; - ESP_LOGI(TAG, "one_image_size %d", one_image_size); - in_frame.raw_data.buffer = (uint8_t *)heap_caps_aligned_alloc(16, one_image_size, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); - - if (in_frame.raw_data.buffer == NULL) { - - ESP_LOGE(TAG, "Failed to allocate memory for in_frame.raw_data.buffer"); - return ESP_FAIL; - } - - ret = esp_h264_enc_open(&cfg, &handle); - if (ret != ESP_H264_ERR_OK) { - ESP_LOGE(TAG, "Open h264 encoder failed. ret %d", ret); - return ESP_FAIL; - - } else { - ESP_LOGI(TAG, "Open OK. handle: %p", handle); - } - - return ESP_OK; -} - -void video_task(void *pvParameters) { - - int frame_count = 0; - static int fps = 0; - static int64_t last_time; - int64_t curr_time; - int64_t start_time; - int64_t end_time; - - camera_fb_t * fb = NULL; - - ESP_LOGI(TAG, "video task started"); - - last_time = get_timestamp(); - - for(;;) { - - if (eState == PEER_CONNECTION_COMPLETED) { - - fb = esp_camera_fb_get(); - - if (!fb) { - - ESP_LOGE(TAG, "Camera capture failed"); - } - - memcpy(in_frame.raw_data.buffer, fb->buf, fb->len); - - in_frame.pts = frame_count * (1000 / cfg.fps); - - start_time = get_timestamp(); - - if (esp_h264_enc_process(handle, &in_frame, &out_frame) != ESP_H264_ERR_OK) { - - ESP_LOGE(TAG, "h264 encode failed"); - - } else { - - if (out_frame.frame_type_t == 0) { - - peer_connection_send_video(g_pc, out_frame.layer_data[0].buffer, out_frame.layer_data[0].len); - peer_connection_send_video(g_pc, out_frame.layer_data[1].buffer, out_frame.layer_data[1].len); - } else { - - peer_connection_send_video(g_pc, out_frame.layer_data[0].buffer, out_frame.layer_data[0].len); - } - -#if 0 - for (int layer = 0; layer < out_frame.layer_num; layer++) { - printf("layer number: %d, type: %d, size: %d, ", layer, out_frame.frame_type_t, out_frame.layer_data[layer].len); - for (int i = 0; i < 6; i++) { - printf("%02x ", out_frame.layer_data[layer].buffer[i]); - } - printf("\r\n"); - } -#endif - frame_count++; - //ESP_LOGI(TAG, "Camera captured. size=%zu, timestamp=%llu", fb->len, fb->timestamp); - } - - end_time = get_timestamp(); - //ESP_LOGI(TAG, "h264 encode time: %lld", end_time - start_time); - fps++; - - if ((fps % 100) == 0) { - - curr_time = get_timestamp(); - ESP_LOGI(TAG, "Camera FPS=%.2f", 1000.0f / (float)(curr_time - last_time) * 100.0f); - last_time = curr_time; - } - - esp_camera_fb_return(fb); - vTaskDelay(pdMS_TO_TICKS(90)); - - } else { - - vTaskDelay(pdMS_TO_TICKS(1000)); - } - - } - -} - diff --git a/examples/esp32s3/partitions.csv b/examples/esp32s3/partitions.csv deleted file mode 120000 index e5e7c6b..0000000 --- a/examples/esp32s3/partitions.csv +++ /dev/null @@ -1 +0,0 @@ -../esp32/partitions.csv \ No newline at end of file diff --git a/examples/esp32s3/sdkconfig b/examples/esp32s3/sdkconfig deleted file mode 100644 index f1f139f..0000000 --- a/examples/esp32s3/sdkconfig +++ /dev/null @@ -1,1910 +0,0 @@ -# -# Automatically generated file. DO NOT EDIT. -# Espressif IoT Development Framework (ESP-IDF) Project Configuration -# -CONFIG_SOC_LEDC_SUPPORT_APB_CLOCK=y -CONFIG_SOC_LEDC_SUPPORT_XTAL_CLOCK=y -CONFIG_SOC_LEDC_CHANNEL_NUM=8 -CONFIG_SOC_LEDC_TIMER_BIT_WIDE_NUM=14 -CONFIG_SOC_LEDC_SUPPORT_FADE_STOP=y -CONFIG_SOC_MPU_MIN_REGION_SIZE=0x20000000 -CONFIG_SOC_MPU_REGIONS_MAX_NUM=8 -CONFIG_SOC_ADC_SUPPORTED=y -CONFIG_SOC_PCNT_SUPPORTED=y -CONFIG_SOC_WIFI_SUPPORTED=y -CONFIG_SOC_TWAI_SUPPORTED=y -CONFIG_SOC_GDMA_SUPPORTED=y -CONFIG_SOC_LCDCAM_SUPPORTED=y -CONFIG_SOC_MCPWM_SUPPORTED=y -CONFIG_SOC_DEDICATED_GPIO_SUPPORTED=y -CONFIG_SOC_CACHE_SUPPORT_WRAP=y -CONFIG_SOC_ULP_SUPPORTED=y -CONFIG_SOC_RISCV_COPROC_SUPPORTED=y -CONFIG_SOC_BT_SUPPORTED=y -CONFIG_SOC_USB_OTG_SUPPORTED=y -CONFIG_SOC_USB_SERIAL_JTAG_SUPPORTED=y -CONFIG_SOC_CCOMP_TIMER_SUPPORTED=y -CONFIG_SOC_ASYNC_MEMCPY_SUPPORTED=y -CONFIG_SOC_SUPPORTS_SECURE_DL_MODE=y -CONFIG_SOC_EFUSE_KEY_PURPOSE_FIELD=y -CONFIG_SOC_SDMMC_HOST_SUPPORTED=y -CONFIG_SOC_RTC_FAST_MEM_SUPPORTED=y -CONFIG_SOC_RTC_SLOW_MEM_SUPPORTED=y -CONFIG_SOC_RTC_MEM_SUPPORTED=y -CONFIG_SOC_PSRAM_DMA_CAPABLE=y -CONFIG_SOC_XT_WDT_SUPPORTED=y -CONFIG_SOC_I2S_SUPPORTED=y -CONFIG_SOC_RMT_SUPPORTED=y -CONFIG_SOC_SDM_SUPPORTED=y -CONFIG_SOC_SYSTIMER_SUPPORTED=y -CONFIG_SOC_SUPPORT_COEXISTENCE=y -CONFIG_SOC_TEMP_SENSOR_SUPPORTED=y -CONFIG_SOC_AES_SUPPORTED=y -CONFIG_SOC_MPI_SUPPORTED=y -CONFIG_SOC_SHA_SUPPORTED=y -CONFIG_SOC_HMAC_SUPPORTED=y -CONFIG_SOC_DIG_SIGN_SUPPORTED=y -CONFIG_SOC_FLASH_ENC_SUPPORTED=y -CONFIG_SOC_SECURE_BOOT_SUPPORTED=y -CONFIG_SOC_MEMPROT_SUPPORTED=y -CONFIG_SOC_TOUCH_SENSOR_SUPPORTED=y -CONFIG_SOC_XTAL_SUPPORT_40M=y -CONFIG_SOC_APPCPU_HAS_CLOCK_GATING_BUG=y -CONFIG_SOC_ADC_RTC_CTRL_SUPPORTED=y -CONFIG_SOC_ADC_DIG_CTRL_SUPPORTED=y -CONFIG_SOC_ADC_ARBITER_SUPPORTED=y -CONFIG_SOC_ADC_FILTER_SUPPORTED=y -CONFIG_SOC_ADC_MONITOR_SUPPORTED=y -CONFIG_SOC_ADC_DMA_SUPPORTED=y -CONFIG_SOC_ADC_PERIPH_NUM=2 -CONFIG_SOC_ADC_MAX_CHANNEL_NUM=10 -CONFIG_SOC_ADC_ATTEN_NUM=4 -CONFIG_SOC_ADC_DIGI_CONTROLLER_NUM=2 -CONFIG_SOC_ADC_PATT_LEN_MAX=24 -CONFIG_SOC_ADC_DIGI_MIN_BITWIDTH=12 -CONFIG_SOC_ADC_DIGI_MAX_BITWIDTH=12 -CONFIG_SOC_ADC_DIGI_RESULT_BYTES=4 -CONFIG_SOC_ADC_DIGI_DATA_BYTES_PER_CONV=4 -CONFIG_SOC_ADC_SAMPLE_FREQ_THRES_HIGH=83333 -CONFIG_SOC_ADC_SAMPLE_FREQ_THRES_LOW=611 -CONFIG_SOC_ADC_RTC_MIN_BITWIDTH=12 -CONFIG_SOC_ADC_RTC_MAX_BITWIDTH=12 -CONFIG_SOC_RTC_SLOW_CLOCK_SUPPORT_8MD256=y -CONFIG_SOC_ADC_CALIBRATION_V1_SUPPORTED=y -CONFIG_SOC_APB_BACKUP_DMA=y -CONFIG_SOC_BROWNOUT_RESET_SUPPORTED=y -CONFIG_SOC_MMU_LINEAR_ADDRESS_REGION_NUM=1 -CONFIG_SOC_CPU_CORES_NUM=2 -CONFIG_SOC_CPU_INTR_NUM=32 -CONFIG_SOC_CPU_HAS_FPU=y -CONFIG_SOC_CPU_BREAKPOINTS_NUM=2 -CONFIG_SOC_CPU_WATCHPOINTS_NUM=2 -CONFIG_SOC_CPU_WATCHPOINT_SIZE=64 -CONFIG_SOC_DS_SIGNATURE_MAX_BIT_LEN=4096 -CONFIG_SOC_DS_KEY_PARAM_MD_IV_LENGTH=16 -CONFIG_SOC_DS_KEY_CHECK_MAX_WAIT_US=1100 -CONFIG_SOC_GDMA_GROUPS=y -CONFIG_SOC_GDMA_PAIRS_PER_GROUP=5 -CONFIG_SOC_GDMA_SUPPORT_PSRAM=y -CONFIG_SOC_GDMA_PSRAM_MIN_ALIGN=16 -CONFIG_SOC_GPIO_PORT=1 -CONFIG_SOC_GPIO_PIN_COUNT=49 -CONFIG_SOC_GPIO_SUPPORT_RTC_INDEPENDENT=y -CONFIG_SOC_GPIO_SUPPORT_FORCE_HOLD=y -CONFIG_SOC_GPIO_VALID_GPIO_MASK=0x1FFFFFFFFFFFF -CONFIG_SOC_GPIO_VALID_DIGITAL_IO_PAD_MASK=0x0001FFFFFC000000 -CONFIG_SOC_DEDIC_GPIO_OUT_CHANNELS_NUM=8 -CONFIG_SOC_DEDIC_GPIO_IN_CHANNELS_NUM=8 -CONFIG_SOC_DEDIC_GPIO_OUT_AUTO_ENABLE=y -CONFIG_SOC_I2C_NUM=2 -CONFIG_SOC_I2C_FIFO_LEN=32 -CONFIG_SOC_I2C_SUPPORT_SLAVE=y -CONFIG_SOC_I2C_SUPPORT_HW_CLR_BUS=y -CONFIG_SOC_I2C_SUPPORT_XTAL=y -CONFIG_SOC_I2C_SUPPORT_RTC=y -CONFIG_SOC_I2S_NUM=2 -CONFIG_SOC_I2S_HW_VERSION_2=y -CONFIG_SOC_I2S_SUPPORTS_PCM=y -CONFIG_SOC_I2S_SUPPORTS_PDM=y -CONFIG_SOC_I2S_SUPPORTS_PDM_TX=y -CONFIG_SOC_I2S_SUPPORTS_PDM_RX=y -CONFIG_SOC_I2S_SUPPORTS_PDM_CODEC=y -CONFIG_SOC_I2S_SUPPORTS_TDM=y -CONFIG_SOC_MCPWM_GROUPS=2 -CONFIG_SOC_MCPWM_TIMERS_PER_GROUP=3 -CONFIG_SOC_MCPWM_OPERATORS_PER_GROUP=3 -CONFIG_SOC_MCPWM_COMPARATORS_PER_OPERATOR=2 -CONFIG_SOC_MCPWM_GENERATORS_PER_OPERATOR=2 -CONFIG_SOC_MCPWM_TRIGGERS_PER_OPERATOR=2 -CONFIG_SOC_MCPWM_GPIO_FAULTS_PER_GROUP=3 -CONFIG_SOC_MCPWM_CAPTURE_TIMERS_PER_GROUP=y -CONFIG_SOC_MCPWM_CAPTURE_CHANNELS_PER_TIMER=3 -CONFIG_SOC_MCPWM_GPIO_SYNCHROS_PER_GROUP=3 -CONFIG_SOC_MCPWM_SWSYNC_CAN_PROPAGATE=y -CONFIG_SOC_PCNT_GROUPS=y -CONFIG_SOC_PCNT_UNITS_PER_GROUP=4 -CONFIG_SOC_PCNT_CHANNELS_PER_UNIT=2 -CONFIG_SOC_PCNT_THRES_POINT_PER_UNIT=2 -CONFIG_SOC_RMT_GROUPS=1 -CONFIG_SOC_RMT_TX_CANDIDATES_PER_GROUP=4 -CONFIG_SOC_RMT_RX_CANDIDATES_PER_GROUP=4 -CONFIG_SOC_RMT_CHANNELS_PER_GROUP=8 -CONFIG_SOC_RMT_MEM_WORDS_PER_CHANNEL=48 -CONFIG_SOC_RMT_SUPPORT_RX_PINGPONG=y -CONFIG_SOC_RMT_SUPPORT_RX_DEMODULATION=y -CONFIG_SOC_RMT_SUPPORT_TX_ASYNC_STOP=y -CONFIG_SOC_RMT_SUPPORT_TX_LOOP_COUNT=y -CONFIG_SOC_RMT_SUPPORT_TX_LOOP_AUTO_STOP=y -CONFIG_SOC_RMT_SUPPORT_TX_SYNCHRO=y -CONFIG_SOC_RMT_SUPPORT_TX_CARRIER_DATA_ONLY=y -CONFIG_SOC_RMT_SUPPORT_XTAL=y -CONFIG_SOC_RMT_SUPPORT_RC_FAST=y -CONFIG_SOC_RMT_SUPPORT_APB=y -CONFIG_SOC_RMT_SUPPORT_DMA=y -CONFIG_SOC_LCD_I80_SUPPORTED=y -CONFIG_SOC_LCD_RGB_SUPPORTED=y -CONFIG_SOC_LCD_I80_BUSES=1 -CONFIG_SOC_LCD_RGB_PANELS=1 -CONFIG_SOC_LCD_I80_BUS_WIDTH=16 -CONFIG_SOC_LCD_RGB_DATA_WIDTH=16 -CONFIG_SOC_LCD_SUPPORT_RGB_YUV_CONV=y -CONFIG_SOC_RTC_CNTL_CPU_PD_DMA_BUS_WIDTH=128 -CONFIG_SOC_RTC_CNTL_CPU_PD_REG_FILE_NUM=549 -CONFIG_SOC_RTC_CNTL_TAGMEM_PD_DMA_BUS_WIDTH=128 -CONFIG_SOC_RTCIO_PIN_COUNT=22 -CONFIG_SOC_RTCIO_INPUT_OUTPUT_SUPPORTED=y -CONFIG_SOC_RTCIO_HOLD_SUPPORTED=y -CONFIG_SOC_RTCIO_WAKE_SUPPORTED=y -CONFIG_SOC_SDM_GROUPS=y -CONFIG_SOC_SDM_CHANNELS_PER_GROUP=8 -CONFIG_SOC_SPI_PERIPH_NUM=3 -CONFIG_SOC_SPI_MAX_CS_NUM=6 -CONFIG_SOC_SPI_MAXIMUM_BUFFER_SIZE=64 -CONFIG_SOC_SPI_SUPPORT_DDRCLK=y -CONFIG_SOC_SPI_SLAVE_SUPPORT_SEG_TRANS=y -CONFIG_SOC_SPI_SUPPORT_CD_SIG=y -CONFIG_SOC_SPI_SUPPORT_CONTINUOUS_TRANS=y -CONFIG_SOC_SPI_SUPPORT_SLAVE_HD_VER2=y -CONFIG_SOC_SPI_PERIPH_SUPPORT_CONTROL_DUMMY_OUT=y -CONFIG_SOC_MEMSPI_IS_INDEPENDENT=y -CONFIG_SOC_SPI_MAX_PRE_DIVIDER=16 -CONFIG_SOC_SPI_SUPPORT_OCT=y -CONFIG_SOC_MEMSPI_SRC_FREQ_120M=y -CONFIG_SOC_MEMSPI_SRC_FREQ_80M_SUPPORTED=y -CONFIG_SOC_MEMSPI_SRC_FREQ_40M_SUPPORTED=y -CONFIG_SOC_MEMSPI_SRC_FREQ_20M_SUPPORTED=y -CONFIG_SOC_SPIRAM_SUPPORTED=y -CONFIG_SOC_SYSTIMER_COUNTER_NUM=2 -CONFIG_SOC_SYSTIMER_ALARM_NUM=3 -CONFIG_SOC_SYSTIMER_BIT_WIDTH_LO=32 -CONFIG_SOC_SYSTIMER_BIT_WIDTH_HI=20 -CONFIG_SOC_SYSTIMER_FIXED_DIVIDER=y -CONFIG_SOC_SYSTIMER_INT_LEVEL=y -CONFIG_SOC_SYSTIMER_ALARM_MISS_COMPENSATE=y -CONFIG_SOC_TIMER_GROUPS=2 -CONFIG_SOC_TIMER_GROUP_TIMERS_PER_GROUP=2 -CONFIG_SOC_TIMER_GROUP_COUNTER_BIT_WIDTH=54 -CONFIG_SOC_TIMER_GROUP_SUPPORT_XTAL=y -CONFIG_SOC_TIMER_GROUP_SUPPORT_APB=y -CONFIG_SOC_TIMER_GROUP_TOTAL_TIMERS=4 -CONFIG_SOC_TOUCH_VERSION_2=y -CONFIG_SOC_TOUCH_SENSOR_NUM=15 -CONFIG_SOC_TOUCH_PROXIMITY_CHANNEL_NUM=3 -CONFIG_SOC_TOUCH_PROXIMITY_MEAS_DONE_SUPPORTED=y -CONFIG_SOC_TOUCH_PAD_THRESHOLD_MAX=0x1FFFFF -CONFIG_SOC_TOUCH_PAD_MEASURE_WAIT_MAX=0xFF -CONFIG_SOC_UART_NUM=3 -CONFIG_SOC_UART_FIFO_LEN=128 -CONFIG_SOC_UART_BITRATE_MAX=5000000 -CONFIG_SOC_UART_SUPPORT_FSM_TX_WAIT_SEND=y -CONFIG_SOC_UART_SUPPORT_WAKEUP_INT=y -CONFIG_SOC_UART_SUPPORT_APB_CLK=y -CONFIG_SOC_UART_SUPPORT_RTC_CLK=y -CONFIG_SOC_UART_SUPPORT_XTAL_CLK=y -CONFIG_SOC_UART_REQUIRE_CORE_RESET=y -CONFIG_SOC_USB_PERIPH_NUM=y -CONFIG_SOC_SHA_DMA_MAX_BUFFER_SIZE=3968 -CONFIG_SOC_SHA_SUPPORT_DMA=y -CONFIG_SOC_SHA_SUPPORT_RESUME=y -CONFIG_SOC_SHA_GDMA=y -CONFIG_SOC_SHA_SUPPORT_SHA1=y -CONFIG_SOC_SHA_SUPPORT_SHA224=y -CONFIG_SOC_SHA_SUPPORT_SHA256=y -CONFIG_SOC_SHA_SUPPORT_SHA384=y -CONFIG_SOC_SHA_SUPPORT_SHA512=y -CONFIG_SOC_SHA_SUPPORT_SHA512_224=y -CONFIG_SOC_SHA_SUPPORT_SHA512_256=y -CONFIG_SOC_SHA_SUPPORT_SHA512_T=y -CONFIG_SOC_RSA_MAX_BIT_LEN=4096 -CONFIG_SOC_AES_SUPPORT_DMA=y -CONFIG_SOC_AES_GDMA=y -CONFIG_SOC_AES_SUPPORT_AES_128=y -CONFIG_SOC_AES_SUPPORT_AES_256=y -CONFIG_SOC_PM_SUPPORT_EXT_WAKEUP=y -CONFIG_SOC_PM_SUPPORT_WIFI_WAKEUP=y -CONFIG_SOC_PM_SUPPORT_BT_WAKEUP=y -CONFIG_SOC_PM_SUPPORT_TOUCH_SENSOR_WAKEUP=y -CONFIG_SOC_PM_SUPPORT_CPU_PD=y -CONFIG_SOC_PM_SUPPORT_TAGMEM_PD=y -CONFIG_SOC_PM_SUPPORT_RTC_PERIPH_PD=y -CONFIG_SOC_PM_SUPPORT_MODEM_PD=y -CONFIG_SOC_PM_SUPPORT_DEEPSLEEP_CHECK_STUB_ONLY=y -CONFIG_SOC_EFUSE_DIS_DOWNLOAD_DCACHE=y -CONFIG_SOC_EFUSE_HARD_DIS_JTAG=y -CONFIG_SOC_EFUSE_DIS_USB_JTAG=y -CONFIG_SOC_EFUSE_SOFT_DIS_JTAG=y -CONFIG_SOC_EFUSE_DIS_DIRECT_BOOT=y -CONFIG_SOC_SECURE_BOOT_V2_RSA=y -CONFIG_SOC_EFUSE_SECURE_BOOT_KEY_DIGESTS=3 -CONFIG_SOC_EFUSE_REVOKE_BOOT_KEY_DIGESTS=y -CONFIG_SOC_SUPPORT_SECURE_BOOT_REVOKE_KEY=y -CONFIG_SOC_FLASH_ENCRYPTED_XTS_AES_BLOCK_MAX=64 -CONFIG_SOC_FLASH_ENCRYPTION_XTS_AES=y -CONFIG_SOC_FLASH_ENCRYPTION_XTS_AES_OPTIONS=y -CONFIG_SOC_FLASH_ENCRYPTION_XTS_AES_128=y -CONFIG_SOC_FLASH_ENCRYPTION_XTS_AES_256=y -CONFIG_SOC_MEMPROT_CPU_PREFETCH_PAD_SIZE=16 -CONFIG_SOC_MEMPROT_MEM_ALIGN_SIZE=256 -CONFIG_SOC_PHY_DIG_REGS_MEM_SIZE=21 -CONFIG_SOC_MAC_BB_PD_MEM_SIZE=192 -CONFIG_SOC_WIFI_LIGHT_SLEEP_CLK_WIDTH=12 -CONFIG_SOC_SPI_MEM_SUPPORT_AUTO_WAIT_IDLE=y -CONFIG_SOC_SPI_MEM_SUPPORT_AUTO_SUSPEND=y -CONFIG_SOC_SPI_MEM_SUPPORT_AUTO_RESUME=y -CONFIG_SOC_SPI_MEM_SUPPORT_SW_SUSPEND=y -CONFIG_SOC_SPI_MEM_SUPPORT_OPI_MODE=y -CONFIG_SOC_SPI_MEM_SUPPORT_TIME_TUNING=y -CONFIG_SOC_SPI_MEM_SUPPORT_CONFIG_GPIO_BY_EFUSE=y -CONFIG_SOC_COEX_HW_PTI=y -CONFIG_SOC_SDMMC_USE_GPIO_MATRIX=y -CONFIG_SOC_SDMMC_NUM_SLOTS=2 -CONFIG_SOC_SDMMC_SUPPORT_XTAL_CLOCK=y -CONFIG_SOC_TEMPERATURE_SENSOR_SUPPORT_FAST_RC=y -CONFIG_SOC_WIFI_HW_TSF=y -CONFIG_SOC_WIFI_FTM_SUPPORT=y -CONFIG_SOC_WIFI_GCMP_SUPPORT=y -CONFIG_SOC_WIFI_WAPI_SUPPORT=y -CONFIG_SOC_WIFI_CSI_SUPPORT=y -CONFIG_SOC_WIFI_MESH_SUPPORT=y -CONFIG_SOC_BLE_SUPPORTED=y -CONFIG_SOC_BLE_MESH_SUPPORTED=y -CONFIG_SOC_BLE_50_SUPPORTED=y -CONFIG_SOC_TWAI_BRP_MIN=2 -CONFIG_SOC_TWAI_BRP_MAX=16384 -CONFIG_SOC_TWAI_SUPPORTS_RX_STATUS=y -CONFIG_IDF_CMAKE=y -CONFIG_IDF_TARGET_ARCH_XTENSA=y -CONFIG_IDF_TARGET_ARCH="xtensa" -CONFIG_IDF_TARGET="esp32s3" -CONFIG_IDF_TARGET_ESP32S3=y -CONFIG_IDF_FIRMWARE_CHIP_ID=0x0009 - -# -# Build type -# -CONFIG_APP_BUILD_TYPE_APP_2NDBOOT=y -# CONFIG_APP_BUILD_TYPE_ELF_RAM is not set -CONFIG_APP_BUILD_GENERATE_BINARIES=y -CONFIG_APP_BUILD_BOOTLOADER=y -CONFIG_APP_BUILD_USE_FLASH_SECTIONS=y -# CONFIG_APP_REPRODUCIBLE_BUILD is not set -# CONFIG_APP_NO_BLOBS is not set -# end of Build type - -# -# Bootloader config -# -CONFIG_BOOTLOADER_OFFSET_IN_FLASH=0x0 -CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y -# CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_DEBUG is not set -# CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_PERF is not set -# CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_NONE is not set -# CONFIG_BOOTLOADER_LOG_LEVEL_NONE is not set -# CONFIG_BOOTLOADER_LOG_LEVEL_ERROR is not set -# CONFIG_BOOTLOADER_LOG_LEVEL_WARN is not set -CONFIG_BOOTLOADER_LOG_LEVEL_INFO=y -# CONFIG_BOOTLOADER_LOG_LEVEL_DEBUG is not set -# CONFIG_BOOTLOADER_LOG_LEVEL_VERBOSE is not set -CONFIG_BOOTLOADER_LOG_LEVEL=3 -CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V=y -# CONFIG_BOOTLOADER_FACTORY_RESET is not set -# CONFIG_BOOTLOADER_APP_TEST is not set -CONFIG_BOOTLOADER_REGION_PROTECTION_ENABLE=y -CONFIG_BOOTLOADER_WDT_ENABLE=y -# CONFIG_BOOTLOADER_WDT_DISABLE_IN_USER_CODE is not set -CONFIG_BOOTLOADER_WDT_TIME_MS=9000 -# CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE is not set -# CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP is not set -# CONFIG_BOOTLOADER_SKIP_VALIDATE_ON_POWER_ON is not set -# CONFIG_BOOTLOADER_SKIP_VALIDATE_ALWAYS is not set -CONFIG_BOOTLOADER_RESERVE_RTC_SIZE=0 -# CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC is not set -CONFIG_BOOTLOADER_FLASH_XMC_SUPPORT=y -# end of Bootloader config - -# -# Security features -# -CONFIG_SECURE_BOOT_V2_RSA_SUPPORTED=y -CONFIG_SECURE_BOOT_V2_PREFERRED=y -# CONFIG_SECURE_SIGNED_APPS_NO_SECURE_BOOT is not set -# CONFIG_SECURE_BOOT is not set -# CONFIG_SECURE_FLASH_ENC_ENABLED is not set -CONFIG_SECURE_ROM_DL_MODE_ENABLED=y -# end of Security features - -# -# Application manager -# -CONFIG_APP_COMPILE_TIME_DATE=y -# CONFIG_APP_EXCLUDE_PROJECT_VER_VAR is not set -# CONFIG_APP_EXCLUDE_PROJECT_NAME_VAR is not set -# CONFIG_APP_PROJECT_VER_FROM_CONFIG is not set -CONFIG_APP_RETRIEVE_LEN_ELF_SHA=16 -# end of Application manager - -CONFIG_ESP_ROM_HAS_CRC_LE=y -CONFIG_ESP_ROM_HAS_CRC_BE=y -CONFIG_ESP_ROM_HAS_MZ_CRC32=y -CONFIG_ESP_ROM_HAS_JPEG_DECODE=y -CONFIG_ESP_ROM_UART_CLK_IS_XTAL=y -CONFIG_ESP_ROM_HAS_RETARGETABLE_LOCKING=y -CONFIG_ESP_ROM_USB_SERIAL_DEVICE_NUM=4 -CONFIG_ESP_ROM_HAS_ERASE_0_REGION_BUG=y -CONFIG_ESP_ROM_GET_CLK_FREQ=y -CONFIG_ESP_ROM_HAS_HAL_WDT=y -CONFIG_ESP_ROM_NEEDS_SWSETUP_WORKAROUND=y -CONFIG_ESP_ROM_HAS_ETS_PRINTF_BUG=y - -# -# Boot ROM Behavior -# -CONFIG_BOOT_ROM_LOG_ALWAYS_ON=y -# CONFIG_BOOT_ROM_LOG_ALWAYS_OFF is not set -# CONFIG_BOOT_ROM_LOG_ON_GPIO_HIGH is not set -# CONFIG_BOOT_ROM_LOG_ON_GPIO_LOW is not set -# end of Boot ROM Behavior - -# -# Serial flasher config -# -# CONFIG_ESPTOOLPY_NO_STUB is not set -# CONFIG_ESPTOOLPY_OCT_FLASH is not set -# CONFIG_ESPTOOLPY_FLASHMODE_QIO is not set -# CONFIG_ESPTOOLPY_FLASHMODE_QOUT is not set -CONFIG_ESPTOOLPY_FLASHMODE_DIO=y -# CONFIG_ESPTOOLPY_FLASHMODE_DOUT is not set -CONFIG_ESPTOOLPY_FLASH_SAMPLE_MODE_STR=y -CONFIG_ESPTOOLPY_FLASHMODE="dio" -# CONFIG_ESPTOOLPY_FLASHFREQ_120M is not set -CONFIG_ESPTOOLPY_FLASHFREQ_80M=y -# CONFIG_ESPTOOLPY_FLASHFREQ_40M is not set -# CONFIG_ESPTOOLPY_FLASHFREQ_20M is not set -CONFIG_ESPTOOLPY_FLASHFREQ="80m" -# CONFIG_ESPTOOLPY_FLASHSIZE_1MB is not set -# CONFIG_ESPTOOLPY_FLASHSIZE_2MB is not set -# CONFIG_ESPTOOLPY_FLASHSIZE_4MB is not set -CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y -# CONFIG_ESPTOOLPY_FLASHSIZE_16MB is not set -# CONFIG_ESPTOOLPY_FLASHSIZE_32MB is not set -# CONFIG_ESPTOOLPY_FLASHSIZE_64MB is not set -# CONFIG_ESPTOOLPY_FLASHSIZE_128MB is not set -CONFIG_ESPTOOLPY_FLASHSIZE="8MB" -# CONFIG_ESPTOOLPY_HEADER_FLASHSIZE_UPDATE is not set -CONFIG_ESPTOOLPY_BEFORE_RESET=y -# CONFIG_ESPTOOLPY_BEFORE_NORESET is not set -CONFIG_ESPTOOLPY_BEFORE="default_reset" -CONFIG_ESPTOOLPY_AFTER_RESET=y -# CONFIG_ESPTOOLPY_AFTER_NORESET is not set -CONFIG_ESPTOOLPY_AFTER="hard_reset" -CONFIG_ESPTOOLPY_MONITOR_BAUD=115200 -# end of Serial flasher config - -# -# Partition Table -# -# CONFIG_PARTITION_TABLE_SINGLE_APP is not set -# CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE is not set -# CONFIG_PARTITION_TABLE_TWO_OTA is not set -CONFIG_PARTITION_TABLE_CUSTOM=y -CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" -CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" -CONFIG_PARTITION_TABLE_OFFSET=0x8000 -CONFIG_PARTITION_TABLE_MD5=y -# end of Partition Table - -# -# Example Configuration -# -CONFIG_ESP32_EYE=y -# CONFIG_ESP32_M5STACK_CAMERA_B is not set -# CONFIG_ESP32S3_XIAO_SENSE is not set -CONFIG_BROKER_URI="mqtts://mqtt.eclipseprojects.io:8883" -CONFIG_BROKER_CERTIFICATE_OVERRIDE="" -CONFIG_BROKER_BIN_SIZE_TO_SEND=20000 -CONFIG_ESP_WIFI_SSID="myssid" -CONFIG_ESP_WIFI_PASSWORD="mypassword" -CONFIG_ESP_MAXIMUM_RETRY=5 -# CONFIG_ESP_WIFI_AUTH_OPEN is not set -# CONFIG_ESP_WIFI_AUTH_WEP is not set -# CONFIG_ESP_WIFI_AUTH_WPA_PSK is not set -CONFIG_ESP_WIFI_AUTH_WPA2_PSK=y -# CONFIG_ESP_WIFI_AUTH_WPA_WPA2_PSK is not set -# CONFIG_ESP_WIFI_AUTH_WPA3_PSK is not set -# CONFIG_ESP_WIFI_AUTH_WPA2_WPA3_PSK is not set -# CONFIG_ESP_WIFI_AUTH_WAPI_PSK is not set -# end of Example Configuration - -# -# Compiler options -# -CONFIG_COMPILER_OPTIMIZATION_DEFAULT=y -# CONFIG_COMPILER_OPTIMIZATION_SIZE is not set -# CONFIG_COMPILER_OPTIMIZATION_PERF is not set -# CONFIG_COMPILER_OPTIMIZATION_NONE is not set -CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE=y -# CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT is not set -# CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE is not set -CONFIG_COMPILER_FLOAT_LIB_FROM_GCCLIB=y -CONFIG_COMPILER_OPTIMIZATION_ASSERTION_LEVEL=2 -# CONFIG_COMPILER_OPTIMIZATION_CHECKS_SILENT is not set -CONFIG_COMPILER_HIDE_PATHS_MACROS=y -# CONFIG_COMPILER_CXX_EXCEPTIONS is not set -# CONFIG_COMPILER_CXX_RTTI is not set -CONFIG_COMPILER_STACK_CHECK_MODE_NONE=y -# CONFIG_COMPILER_STACK_CHECK_MODE_NORM is not set -# CONFIG_COMPILER_STACK_CHECK_MODE_STRONG is not set -# CONFIG_COMPILER_STACK_CHECK_MODE_ALL is not set -# CONFIG_COMPILER_WARN_WRITE_STRINGS is not set -# CONFIG_COMPILER_DUMP_RTL_FILES is not set -# end of Compiler options - -# -# Component config -# - -# -# Application Level Tracing -# -# CONFIG_APPTRACE_DEST_JTAG is not set -CONFIG_APPTRACE_DEST_NONE=y -# CONFIG_APPTRACE_DEST_UART1 is not set -# CONFIG_APPTRACE_DEST_UART2 is not set -# CONFIG_APPTRACE_DEST_USB_CDC is not set -CONFIG_APPTRACE_DEST_UART_NONE=y -CONFIG_APPTRACE_UART_TASK_PRIO=1 -CONFIG_APPTRACE_LOCK_ENABLE=y -# end of Application Level Tracing - -# -# Bluetooth -# -# CONFIG_BT_ENABLED is not set -# end of Bluetooth - -# -# Driver Configurations -# - -# -# Legacy ADC Configuration -# -# CONFIG_ADC_SUPPRESS_DEPRECATE_WARN is not set - -# -# Legacy ADC Calibration Configuration -# -# CONFIG_ADC_CALI_SUPPRESS_DEPRECATE_WARN is not set -# end of Legacy ADC Calibration Configuration -# end of Legacy ADC Configuration - -# -# SPI Configuration -# -# CONFIG_SPI_MASTER_IN_IRAM is not set -CONFIG_SPI_MASTER_ISR_IN_IRAM=y -# CONFIG_SPI_SLAVE_IN_IRAM is not set -CONFIG_SPI_SLAVE_ISR_IN_IRAM=y -# end of SPI Configuration - -# -# TWAI Configuration -# -# CONFIG_TWAI_ISR_IN_IRAM is not set -CONFIG_TWAI_ERRATA_FIX_LISTEN_ONLY_DOM=y -# end of TWAI Configuration - -# -# Temperature sensor Configuration -# -# CONFIG_TEMP_SENSOR_SUPPRESS_DEPRECATE_WARN is not set -# CONFIG_TEMP_SENSOR_ENABLE_DEBUG_LOG is not set -# end of Temperature sensor Configuration - -# -# UART Configuration -# -# CONFIG_UART_ISR_IN_IRAM is not set -# end of UART Configuration - -# -# GPIO Configuration -# -# CONFIG_GPIO_CTRL_FUNC_IN_IRAM is not set -# end of GPIO Configuration - -# -# Sigma Delta Modulator Configuration -# -# CONFIG_SDM_CTRL_FUNC_IN_IRAM is not set -# CONFIG_SDM_SUPPRESS_DEPRECATE_WARN is not set -# CONFIG_SDM_ENABLE_DEBUG_LOG is not set -# end of Sigma Delta Modulator Configuration - -# -# GPTimer Configuration -# -# CONFIG_GPTIMER_CTRL_FUNC_IN_IRAM is not set -# CONFIG_GPTIMER_ISR_IRAM_SAFE is not set -# CONFIG_GPTIMER_SUPPRESS_DEPRECATE_WARN is not set -# CONFIG_GPTIMER_ENABLE_DEBUG_LOG is not set -# end of GPTimer Configuration - -# -# PCNT Configuration -# -# CONFIG_PCNT_CTRL_FUNC_IN_IRAM is not set -# CONFIG_PCNT_ISR_IRAM_SAFE is not set -# CONFIG_PCNT_SUPPRESS_DEPRECATE_WARN is not set -# CONFIG_PCNT_ENABLE_DEBUG_LOG is not set -# end of PCNT Configuration - -# -# RMT Configuration -# -# CONFIG_RMT_ISR_IRAM_SAFE is not set -# CONFIG_RMT_SUPPRESS_DEPRECATE_WARN is not set -# CONFIG_RMT_ENABLE_DEBUG_LOG is not set -# end of RMT Configuration - -# -# MCPWM Configuration -# -# CONFIG_MCPWM_ISR_IRAM_SAFE is not set -# CONFIG_MCPWM_CTRL_FUNC_IN_IRAM is not set -# CONFIG_MCPWM_SUPPRESS_DEPRECATE_WARN is not set -# CONFIG_MCPWM_ENABLE_DEBUG_LOG is not set -# end of MCPWM Configuration - -# -# I2S Configuration -# -# CONFIG_I2S_ISR_IRAM_SAFE is not set -# CONFIG_I2S_SUPPRESS_DEPRECATE_WARN is not set -# CONFIG_I2S_ENABLE_DEBUG_LOG is not set -# end of I2S Configuration -# end of Driver Configurations - -# -# eFuse Bit Manager -# -# CONFIG_EFUSE_CUSTOM_TABLE is not set -# CONFIG_EFUSE_VIRTUAL is not set -CONFIG_EFUSE_MAX_BLK_LEN=256 -# end of eFuse Bit Manager - -# -# ESP-TLS -# -CONFIG_ESP_TLS_USING_MBEDTLS=y -CONFIG_ESP_TLS_USE_DS_PERIPHERAL=y -# CONFIG_ESP_TLS_CLIENT_SESSION_TICKETS is not set -# CONFIG_ESP_TLS_SERVER is not set -# CONFIG_ESP_TLS_PSK_VERIFICATION is not set -# CONFIG_ESP_TLS_INSECURE is not set -# end of ESP-TLS - -# -# Camera configuration -# -CONFIG_OV7670_SUPPORT=y -CONFIG_OV7725_SUPPORT=y -CONFIG_NT99141_SUPPORT=y -CONFIG_OV2640_SUPPORT=y -CONFIG_OV3660_SUPPORT=y -CONFIG_OV5640_SUPPORT=y -CONFIG_GC2145_SUPPORT=y -CONFIG_GC032A_SUPPORT=y -CONFIG_GC0308_SUPPORT=y -CONFIG_BF3005_SUPPORT=y -CONFIG_BF20A6_SUPPORT=y -# CONFIG_SC101IOT_SUPPORT is not set -CONFIG_SC030IOT_SUPPORT=y -# CONFIG_SC031GS_SUPPORT is not set -# CONFIG_SCCB_HARDWARE_I2C_PORT0 is not set -CONFIG_SCCB_HARDWARE_I2C_PORT1=y -CONFIG_SCCB_CLK_FREQ=100000 -# CONFIG_GC_SENSOR_WINDOWING_MODE is not set -CONFIG_GC_SENSOR_SUBSAMPLE_MODE=y -CONFIG_CAMERA_TASK_STACK_SIZE=2048 -CONFIG_CAMERA_CORE0=y -# CONFIG_CAMERA_CORE1 is not set -# CONFIG_CAMERA_NO_AFFINITY is not set -CONFIG_CAMERA_DMA_BUFFER_SIZE_MAX=32768 -# CONFIG_CAMERA_CONVERTER_ENABLED is not set -# end of Camera configuration - -# -# ADC and ADC Calibration -# -# CONFIG_ADC_ONESHOT_CTRL_FUNC_IN_IRAM is not set -# CONFIG_ADC_CONTINUOUS_ISR_IRAM_SAFE is not set -# CONFIG_ADC_CONTINUOUS_FORCE_USE_ADC2_ON_C3_S3 is not set -# end of ADC and ADC Calibration - -# -# Common ESP-related -# -CONFIG_ESP_ERR_TO_NAME_LOOKUP=y -CONFIG_ESP_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y -# end of Common ESP-related - -# -# Ethernet -# -CONFIG_ETH_ENABLED=y -CONFIG_ETH_USE_SPI_ETHERNET=y -# CONFIG_ETH_SPI_ETHERNET_DM9051 is not set -# CONFIG_ETH_SPI_ETHERNET_W5500 is not set -# CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL is not set -# CONFIG_ETH_USE_OPENETH is not set -# CONFIG_ETH_TRANSMIT_MUTEX is not set -# end of Ethernet - -# -# Event Loop Library -# -# CONFIG_ESP_EVENT_LOOP_PROFILING is not set -CONFIG_ESP_EVENT_POST_FROM_ISR=y -CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR=y -# end of Event Loop Library - -# -# GDB Stub -# -# end of GDB Stub - -# -# ESP HTTP client -# -CONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS=y -# CONFIG_ESP_HTTP_CLIENT_ENABLE_BASIC_AUTH is not set -# CONFIG_ESP_HTTP_CLIENT_ENABLE_DIGEST_AUTH is not set -# end of ESP HTTP client - -# -# HTTP Server -# -CONFIG_HTTPD_MAX_REQ_HDR_LEN=512 -CONFIG_HTTPD_MAX_URI_LEN=512 -CONFIG_HTTPD_ERR_RESP_NO_DELAY=y -CONFIG_HTTPD_PURGE_BUF_LEN=32 -# CONFIG_HTTPD_LOG_PURGE_DATA is not set -# CONFIG_HTTPD_WS_SUPPORT is not set -# CONFIG_HTTPD_QUEUE_WORK_BLOCKING is not set -# end of HTTP Server - -# -# ESP HTTPS OTA -# -# CONFIG_ESP_HTTPS_OTA_DECRYPT_CB is not set -# CONFIG_ESP_HTTPS_OTA_ALLOW_HTTP is not set -# end of ESP HTTPS OTA - -# -# ESP HTTPS server -# -# CONFIG_ESP_HTTPS_SERVER_ENABLE is not set -# end of ESP HTTPS server - -# -# Hardware Settings -# - -# -# Chip revision -# -CONFIG_ESP32S3_REV_MIN_0=y -# CONFIG_ESP32S3_REV_MIN_1 is not set -# CONFIG_ESP32S3_REV_MIN_2 is not set -CONFIG_ESP32S3_REV_MIN_FULL=0 -CONFIG_ESP_REV_MIN_FULL=0 - -# -# Maximum Supported ESP32-S3 Revision (Rev v0.99) -# -CONFIG_ESP32S3_REV_MAX_FULL=99 -CONFIG_ESP_REV_MAX_FULL=99 -# end of Chip revision - -# -# MAC Config -# -CONFIG_ESP_MAC_ADDR_UNIVERSE_WIFI_STA=y -CONFIG_ESP_MAC_ADDR_UNIVERSE_WIFI_AP=y -CONFIG_ESP_MAC_ADDR_UNIVERSE_BT=y -CONFIG_ESP_MAC_ADDR_UNIVERSE_ETH=y -# CONFIG_ESP32S3_UNIVERSAL_MAC_ADDRESSES_TWO is not set -CONFIG_ESP32S3_UNIVERSAL_MAC_ADDRESSES_FOUR=y -CONFIG_ESP32S3_UNIVERSAL_MAC_ADDRESSES=4 -# end of MAC Config - -# -# Sleep Config -# -CONFIG_ESP_SLEEP_RTC_BUS_ISO_WORKAROUND=y -CONFIG_ESP_SLEEP_GPIO_RESET_WORKAROUND=y -CONFIG_ESP_SLEEP_PSRAM_LEAKAGE_WORKAROUND=y -CONFIG_ESP_SLEEP_FLASH_LEAKAGE_WORKAROUND=y -CONFIG_ESP_SLEEP_MSPI_NEED_ALL_IO_PU=y -CONFIG_ESP_SLEEP_DEEP_SLEEP_WAKEUP_DELAY=2000 -# end of Sleep Config - -# -# RTC Clock Config -# -CONFIG_RTC_CLK_SRC_INT_RC=y -# CONFIG_RTC_CLK_SRC_EXT_CRYS is not set -# CONFIG_RTC_CLK_SRC_EXT_OSC is not set -# CONFIG_RTC_CLK_SRC_INT_8MD256 is not set -CONFIG_RTC_CLK_CAL_CYCLES=1024 -CONFIG_RTC_CLOCK_BBPLL_POWER_ON_WITH_USB=y -# end of RTC Clock Config - -# -# Peripheral Control -# -# CONFIG_PERIPH_CTRL_FUNC_IN_IRAM is not set -# end of Peripheral Control - -# -# GDMA Configuration -# -# CONFIG_GDMA_CTRL_FUNC_IN_IRAM is not set -# CONFIG_GDMA_ISR_IRAM_SAFE is not set -# end of GDMA Configuration - -# -# Main XTAL Config -# -CONFIG_XTAL_FREQ_40=y -CONFIG_XTAL_FREQ=40 -# end of Main XTAL Config -# end of Hardware Settings - -# -# LCD and Touch Panel -# - -# -# LCD Touch Drivers are maintained in the IDF Component Registry -# - -# -# LCD Peripheral Configuration -# -CONFIG_LCD_PANEL_IO_FORMAT_BUF_SIZE=32 -# CONFIG_LCD_ENABLE_DEBUG_LOG is not set -# CONFIG_LCD_RGB_ISR_IRAM_SAFE is not set -# CONFIG_LCD_RGB_RESTART_IN_VSYNC is not set -# end of LCD Peripheral Configuration -# end of LCD and Touch Panel - -# -# ESP NETIF Adapter -# -CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL=120 -CONFIG_ESP_NETIF_TCPIP_LWIP=y -# CONFIG_ESP_NETIF_LOOPBACK is not set -# CONFIG_ESP_NETIF_L2_TAP is not set -# CONFIG_ESP_NETIF_BRIDGE_EN is not set -# end of ESP NETIF Adapter - -# -# PHY -# -CONFIG_ESP_PHY_CALIBRATION_AND_DATA_STORAGE=y -# CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION is not set -CONFIG_ESP_PHY_MAX_WIFI_TX_POWER=20 -CONFIG_ESP_PHY_MAX_TX_POWER=20 -CONFIG_ESP_PHY_REDUCE_TX_POWER=y -CONFIG_ESP_PHY_ENABLE_USB=y -# end of PHY - -# -# Power Management -# -# CONFIG_PM_ENABLE is not set -CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP=y -CONFIG_PM_POWER_DOWN_TAGMEM_IN_LIGHT_SLEEP=y -# end of Power Management - -# -# ESP PSRAM -# -CONFIG_SPIRAM=y - -# -# SPI RAM config -# -# CONFIG_SPIRAM_MODE_QUAD is not set -CONFIG_SPIRAM_MODE_OCT=y -CONFIG_SPIRAM_TYPE_AUTO=y -# CONFIG_SPIRAM_TYPE_ESPPSRAM64 is not set -CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY=y -CONFIG_SPIRAM_CLK_IO=30 -CONFIG_SPIRAM_CS_IO=26 -# CONFIG_SPIRAM_FETCH_INSTRUCTIONS is not set -# CONFIG_SPIRAM_RODATA is not set -# CONFIG_SPIRAM_SPEED_80M is not set -CONFIG_SPIRAM_SPEED_40M=y -CONFIG_SPIRAM_SPEED=40 -CONFIG_SPIRAM_BOOT_INIT=y -# CONFIG_SPIRAM_USE_MEMMAP is not set -# CONFIG_SPIRAM_USE_CAPS_ALLOC is not set -CONFIG_SPIRAM_USE_MALLOC=y -CONFIG_SPIRAM_MEMTEST=y -CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=16384 -# CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP is not set -CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=32768 -CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y -# CONFIG_SPIRAM_ECC_ENABLE is not set -# end of SPI RAM config -# end of ESP PSRAM - -# -# ESP Ringbuf -# -# CONFIG_RINGBUF_PLACE_FUNCTIONS_INTO_FLASH is not set -# CONFIG_RINGBUF_PLACE_ISR_FUNCTIONS_INTO_FLASH is not set -# end of ESP Ringbuf - -# -# ESP System Settings -# -# CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_80 is not set -CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_160=y -# CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240 is not set -CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ=160 - -# -# Cache config -# -CONFIG_ESP32S3_INSTRUCTION_CACHE_16KB=y -# CONFIG_ESP32S3_INSTRUCTION_CACHE_32KB is not set -CONFIG_ESP32S3_INSTRUCTION_CACHE_SIZE=0x4000 -# CONFIG_ESP32S3_INSTRUCTION_CACHE_4WAYS is not set -CONFIG_ESP32S3_INSTRUCTION_CACHE_8WAYS=y -CONFIG_ESP32S3_ICACHE_ASSOCIATED_WAYS=8 -# CONFIG_ESP32S3_INSTRUCTION_CACHE_LINE_16B is not set -CONFIG_ESP32S3_INSTRUCTION_CACHE_LINE_32B=y -CONFIG_ESP32S3_INSTRUCTION_CACHE_LINE_SIZE=32 -# CONFIG_ESP32S3_DATA_CACHE_16KB is not set -CONFIG_ESP32S3_DATA_CACHE_32KB=y -# CONFIG_ESP32S3_DATA_CACHE_64KB is not set -CONFIG_ESP32S3_DATA_CACHE_SIZE=0x8000 -# CONFIG_ESP32S3_DATA_CACHE_4WAYS is not set -CONFIG_ESP32S3_DATA_CACHE_8WAYS=y -CONFIG_ESP32S3_DCACHE_ASSOCIATED_WAYS=8 -# CONFIG_ESP32S3_DATA_CACHE_LINE_16B is not set -CONFIG_ESP32S3_DATA_CACHE_LINE_32B=y -# CONFIG_ESP32S3_DATA_CACHE_LINE_64B is not set -CONFIG_ESP32S3_DATA_CACHE_LINE_SIZE=32 -# end of Cache config - -# -# Memory -# -# CONFIG_ESP32S3_RTCDATA_IN_FAST_MEM is not set -# CONFIG_ESP32S3_USE_FIXED_STATIC_RAM_SIZE is not set -# end of Memory - -# -# Trace memory -# -# CONFIG_ESP32S3_TRAX is not set -CONFIG_ESP32S3_TRACEMEM_RESERVE_DRAM=0x0 -# end of Trace memory - -# CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT is not set -CONFIG_ESP_SYSTEM_PANIC_PRINT_REBOOT=y -# CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT is not set -# CONFIG_ESP_SYSTEM_PANIC_GDBSTUB is not set -# CONFIG_ESP_SYSTEM_GDBSTUB_RUNTIME is not set -CONFIG_ESP_SYSTEM_RTC_FAST_MEM_AS_HEAP_DEPCHECK=y -CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP=y - -# -# Memory protection -# -CONFIG_ESP_SYSTEM_MEMPROT_FEATURE=y -CONFIG_ESP_SYSTEM_MEMPROT_FEATURE_LOCK=y -# end of Memory protection - -CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE=32 -CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=2304 -CONFIG_ESP_MAIN_TASK_STACK_SIZE=35840 -CONFIG_ESP_MAIN_TASK_AFFINITY_CPU0=y -# CONFIG_ESP_MAIN_TASK_AFFINITY_CPU1 is not set -# CONFIG_ESP_MAIN_TASK_AFFINITY_NO_AFFINITY is not set -CONFIG_ESP_MAIN_TASK_AFFINITY=0x0 -CONFIG_ESP_MINIMAL_SHARED_STACK_SIZE=2048 -CONFIG_ESP_CONSOLE_UART_DEFAULT=y -# CONFIG_ESP_CONSOLE_USB_CDC is not set -# CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG is not set -# CONFIG_ESP_CONSOLE_UART_CUSTOM is not set -# CONFIG_ESP_CONSOLE_NONE is not set -# CONFIG_ESP_CONSOLE_SECONDARY_NONE is not set -CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG=y -CONFIG_ESP_CONSOLE_UART=y -CONFIG_ESP_CONSOLE_MULTIPLE_UART=y -CONFIG_ESP_CONSOLE_UART_NUM=0 -CONFIG_ESP_CONSOLE_UART_BAUDRATE=115200 -CONFIG_ESP_INT_WDT=y -CONFIG_ESP_INT_WDT_TIMEOUT_MS=300 -CONFIG_ESP_INT_WDT_CHECK_CPU1=y -CONFIG_ESP_TASK_WDT_EN=y -CONFIG_ESP_TASK_WDT_INIT=y -# CONFIG_ESP_TASK_WDT_PANIC is not set -CONFIG_ESP_TASK_WDT_TIMEOUT_S=5 -# CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 is not set -# CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1 is not set -# CONFIG_ESP_PANIC_HANDLER_IRAM is not set -# CONFIG_ESP_DEBUG_STUBS_ENABLE is not set -CONFIG_ESP_DEBUG_OCDAWARE=y -CONFIG_ESP_SYSTEM_CHECK_INT_LEVEL_4=y - -# -# Brownout Detector -# -CONFIG_ESP_BROWNOUT_DET=y -CONFIG_ESP_BROWNOUT_DET_LVL_SEL_7=y -# CONFIG_ESP_BROWNOUT_DET_LVL_SEL_6 is not set -# CONFIG_ESP_BROWNOUT_DET_LVL_SEL_5 is not set -# CONFIG_ESP_BROWNOUT_DET_LVL_SEL_4 is not set -# CONFIG_ESP_BROWNOUT_DET_LVL_SEL_3 is not set -# CONFIG_ESP_BROWNOUT_DET_LVL_SEL_2 is not set -# CONFIG_ESP_BROWNOUT_DET_LVL_SEL_1 is not set -CONFIG_ESP_BROWNOUT_DET_LVL=7 -# end of Brownout Detector - -CONFIG_ESP_SYSTEM_BROWNOUT_INTR=y -# end of ESP System Settings - -# -# IPC (Inter-Processor Call) -# -CONFIG_ESP_IPC_TASK_STACK_SIZE=1280 -CONFIG_ESP_IPC_USES_CALLERS_PRIORITY=y -CONFIG_ESP_IPC_ISR_ENABLE=y -# end of IPC (Inter-Processor Call) - -# -# High resolution timer (esp_timer) -# -# CONFIG_ESP_TIMER_PROFILING is not set -CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER=y -CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER=y -CONFIG_ESP_TIMER_TASK_STACK_SIZE=3584 -CONFIG_ESP_TIMER_INTERRUPT_LEVEL=1 -# CONFIG_ESP_TIMER_SUPPORTS_ISR_DISPATCH_METHOD is not set -CONFIG_ESP_TIMER_IMPL_SYSTIMER=y -# end of High resolution timer (esp_timer) - -# -# Wi-Fi -# -CONFIG_ESP32_WIFI_ENABLED=y -CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM=10 -CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=32 -CONFIG_ESP32_WIFI_STATIC_TX_BUFFER=y -CONFIG_ESP32_WIFI_TX_BUFFER_TYPE=0 -CONFIG_ESP32_WIFI_STATIC_TX_BUFFER_NUM=16 -CONFIG_ESP32_WIFI_CACHE_TX_BUFFER_NUM=32 -# CONFIG_ESP32_WIFI_CSI_ENABLED is not set -CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED=y -CONFIG_ESP32_WIFI_TX_BA_WIN=6 -CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED=y -CONFIG_ESP32_WIFI_RX_BA_WIN=6 -# CONFIG_ESP32_WIFI_AMSDU_TX_ENABLED is not set -CONFIG_ESP32_WIFI_NVS_ENABLED=y -CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_0=y -# CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_1 is not set -CONFIG_ESP32_WIFI_SOFTAP_BEACON_MAX_LEN=752 -CONFIG_ESP32_WIFI_MGMT_SBUF_NUM=32 -CONFIG_ESP32_WIFI_IRAM_OPT=y -CONFIG_ESP32_WIFI_RX_IRAM_OPT=y -CONFIG_ESP32_WIFI_ENABLE_WPA3_SAE=y -CONFIG_ESP32_WIFI_ENABLE_WPA3_OWE_STA=y -# CONFIG_ESP_WIFI_SLP_IRAM_OPT is not set -# CONFIG_ESP_WIFI_FTM_ENABLE is not set -CONFIG_ESP_WIFI_STA_DISCONNECTED_PM_ENABLE=y -# CONFIG_ESP_WIFI_EXTERNAL_COEXIST_ENABLE is not set -# CONFIG_ESP_WIFI_GCMP_SUPPORT is not set -# CONFIG_ESP_WIFI_GMAC_SUPPORT is not set -CONFIG_ESP_WIFI_SOFTAP_SUPPORT=y -# CONFIG_ESP_WIFI_SLP_BEACON_LOST_OPT is not set -CONFIG_ESP_WIFI_ESPNOW_MAX_ENCRYPT_NUM=7 -# end of Wi-Fi - -# -# Core dump -# -# CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH is not set -# CONFIG_ESP_COREDUMP_ENABLE_TO_UART is not set -CONFIG_ESP_COREDUMP_ENABLE_TO_NONE=y -# end of Core dump - -# -# FAT Filesystem support -# -CONFIG_FATFS_VOLUME_COUNT=2 -# CONFIG_FATFS_SECTOR_512 is not set -# CONFIG_FATFS_SECTOR_1024 is not set -# CONFIG_FATFS_SECTOR_2048 is not set -CONFIG_FATFS_SECTOR_4096=y -CONFIG_FATFS_SECTORS_PER_CLUSTER_1=y -# CONFIG_FATFS_SECTORS_PER_CLUSTER_2 is not set -# CONFIG_FATFS_SECTORS_PER_CLUSTER_4 is not set -# CONFIG_FATFS_SECTORS_PER_CLUSTER_8 is not set -# CONFIG_FATFS_SECTORS_PER_CLUSTER_16 is not set -# CONFIG_FATFS_SECTORS_PER_CLUSTER_32 is not set -# CONFIG_FATFS_SECTORS_PER_CLUSTER_64 is not set -# CONFIG_FATFS_SECTORS_PER_CLUSTER_128 is not set -# CONFIG_FATFS_CODEPAGE_DYNAMIC is not set -CONFIG_FATFS_CODEPAGE_437=y -# CONFIG_FATFS_CODEPAGE_720 is not set -# CONFIG_FATFS_CODEPAGE_737 is not set -# CONFIG_FATFS_CODEPAGE_771 is not set -# CONFIG_FATFS_CODEPAGE_775 is not set -# CONFIG_FATFS_CODEPAGE_850 is not set -# CONFIG_FATFS_CODEPAGE_852 is not set -# CONFIG_FATFS_CODEPAGE_855 is not set -# CONFIG_FATFS_CODEPAGE_857 is not set -# CONFIG_FATFS_CODEPAGE_860 is not set -# CONFIG_FATFS_CODEPAGE_861 is not set -# CONFIG_FATFS_CODEPAGE_862 is not set -# CONFIG_FATFS_CODEPAGE_863 is not set -# CONFIG_FATFS_CODEPAGE_864 is not set -# CONFIG_FATFS_CODEPAGE_865 is not set -# CONFIG_FATFS_CODEPAGE_866 is not set -# CONFIG_FATFS_CODEPAGE_869 is not set -# CONFIG_FATFS_CODEPAGE_932 is not set -# CONFIG_FATFS_CODEPAGE_936 is not set -# CONFIG_FATFS_CODEPAGE_949 is not set -# CONFIG_FATFS_CODEPAGE_950 is not set -CONFIG_FATFS_AUTO_TYPE=y -# CONFIG_FATFS_FAT12 is not set -# CONFIG_FATFS_FAT16 is not set -CONFIG_FATFS_CODEPAGE=437 -CONFIG_FATFS_LFN_NONE=y -# CONFIG_FATFS_LFN_HEAP is not set -# CONFIG_FATFS_LFN_STACK is not set -CONFIG_FATFS_FS_LOCK=0 -CONFIG_FATFS_TIMEOUT_MS=10000 -CONFIG_FATFS_PER_FILE_CACHE=y -CONFIG_FATFS_ALLOC_PREFER_EXTRAM=y -# CONFIG_FATFS_USE_FASTSEEK is not set -# end of FAT Filesystem support - -# -# FreeRTOS -# - -# -# Kernel -# -# CONFIG_FREERTOS_SMP is not set -# CONFIG_FREERTOS_UNICORE is not set -CONFIG_FREERTOS_HZ=100 -# CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE is not set -# CONFIG_FREERTOS_CHECK_STACKOVERFLOW_PTRVAL is not set -CONFIG_FREERTOS_CHECK_STACKOVERFLOW_CANARY=y -CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=1 -CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=1536 -# CONFIG_FREERTOS_USE_IDLE_HOOK is not set -# CONFIG_FREERTOS_USE_TICK_HOOK is not set -CONFIG_FREERTOS_MAX_TASK_NAME_LEN=16 -# CONFIG_FREERTOS_ENABLE_BACKWARD_COMPATIBILITY is not set -CONFIG_FREERTOS_TIMER_TASK_PRIORITY=1 -CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=2048 -CONFIG_FREERTOS_TIMER_QUEUE_LENGTH=10 -CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE=0 -# CONFIG_FREERTOS_USE_TRACE_FACILITY is not set -# CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS is not set -# end of Kernel - -# -# Port -# -CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER=y -# CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK is not set -# CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP is not set -CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER=y -CONFIG_FREERTOS_ISR_STACKSIZE=1536 -CONFIG_FREERTOS_INTERRUPT_BACKTRACE=y -CONFIG_FREERTOS_TICK_SUPPORT_SYSTIMER=y -CONFIG_FREERTOS_CORETIMER_SYSTIMER_LVL1=y -# CONFIG_FREERTOS_CORETIMER_SYSTIMER_LVL3 is not set -CONFIG_FREERTOS_SYSTICK_USES_SYSTIMER=y -# CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH is not set -# CONFIG_FREERTOS_PLACE_SNAPSHOT_FUNS_INTO_FLASH is not set -# CONFIG_FREERTOS_CHECK_PORT_CRITICAL_COMPLIANCE is not set -CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION=y -CONFIG_FREERTOS_ENABLE_TASK_SNAPSHOT=y -# end of Port - -CONFIG_FREERTOS_NO_AFFINITY=0x7FFFFFFF -CONFIG_FREERTOS_SUPPORT_STATIC_ALLOCATION=y -CONFIG_FREERTOS_DEBUG_OCDAWARE=y -# end of FreeRTOS - -# -# Hardware Abstraction Layer (HAL) and Low Level (LL) -# -CONFIG_HAL_ASSERTION_EQUALS_SYSTEM=y -# CONFIG_HAL_ASSERTION_DISABLE is not set -# CONFIG_HAL_ASSERTION_SILENT is not set -# CONFIG_HAL_ASSERTION_ENABLE is not set -CONFIG_HAL_DEFAULT_ASSERTION_LEVEL=2 -CONFIG_HAL_WDT_USE_ROM_IMPL=y -# end of Hardware Abstraction Layer (HAL) and Low Level (LL) - -# -# Heap memory debugging -# -CONFIG_HEAP_POISONING_DISABLED=y -# CONFIG_HEAP_POISONING_LIGHT is not set -# CONFIG_HEAP_POISONING_COMPREHENSIVE is not set -CONFIG_HEAP_TRACING_OFF=y -# CONFIG_HEAP_TRACING_STANDALONE is not set -# CONFIG_HEAP_TRACING_TOHOST is not set -# CONFIG_HEAP_ABORT_WHEN_ALLOCATION_FAILS is not set -# end of Heap memory debugging - -# -# Log output -# -# CONFIG_LOG_DEFAULT_LEVEL_NONE is not set -# CONFIG_LOG_DEFAULT_LEVEL_ERROR is not set -# CONFIG_LOG_DEFAULT_LEVEL_WARN is not set -CONFIG_LOG_DEFAULT_LEVEL_INFO=y -# CONFIG_LOG_DEFAULT_LEVEL_DEBUG is not set -# CONFIG_LOG_DEFAULT_LEVEL_VERBOSE is not set -CONFIG_LOG_DEFAULT_LEVEL=3 -CONFIG_LOG_MAXIMUM_EQUALS_DEFAULT=y -# CONFIG_LOG_MAXIMUM_LEVEL_DEBUG is not set -# CONFIG_LOG_MAXIMUM_LEVEL_VERBOSE is not set -CONFIG_LOG_MAXIMUM_LEVEL=3 -CONFIG_LOG_COLORS=y -CONFIG_LOG_TIMESTAMP_SOURCE_RTOS=y -# CONFIG_LOG_TIMESTAMP_SOURCE_SYSTEM is not set -# end of Log output - -# -# LWIP -# -CONFIG_LWIP_LOCAL_HOSTNAME="espressif" -# CONFIG_LWIP_NETIF_API is not set -# CONFIG_LWIP_TCPIP_CORE_LOCKING is not set -# CONFIG_LWIP_CHECK_THREAD_SAFETY is not set -CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES=y -# CONFIG_LWIP_L2_TO_L3_COPY is not set -# CONFIG_LWIP_IRAM_OPTIMIZATION is not set -CONFIG_LWIP_TIMERS_ONDEMAND=y -CONFIG_LWIP_MAX_SOCKETS=10 -# CONFIG_LWIP_USE_ONLY_LWIP_SELECT is not set -# CONFIG_LWIP_SO_LINGER is not set -CONFIG_LWIP_SO_REUSE=y -CONFIG_LWIP_SO_REUSE_RXTOALL=y -# CONFIG_LWIP_SO_RCVBUF is not set -# CONFIG_LWIP_NETBUF_RECVINFO is not set -CONFIG_LWIP_IP4_FRAG=y -CONFIG_LWIP_IP6_FRAG=y -# CONFIG_LWIP_IP4_REASSEMBLY is not set -# CONFIG_LWIP_IP6_REASSEMBLY is not set -# CONFIG_LWIP_IP_FORWARD is not set -# CONFIG_LWIP_STATS is not set -CONFIG_LWIP_ESP_GRATUITOUS_ARP=y -CONFIG_LWIP_GARP_TMR_INTERVAL=60 -CONFIG_LWIP_ESP_MLDV6_REPORT=y -CONFIG_LWIP_MLDV6_TMR_INTERVAL=40 -CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=32 -CONFIG_LWIP_DHCP_DOES_ARP_CHECK=y -# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set -CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y -# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set -CONFIG_LWIP_DHCP_OPTIONS_LEN=68 -CONFIG_LWIP_NUM_NETIF_CLIENT_DATA=0 -CONFIG_LWIP_DHCP_COARSE_TIMER_SECS=1 - -# -# DHCP server -# -CONFIG_LWIP_DHCPS=y -CONFIG_LWIP_DHCPS_LEASE_UNIT=60 -CONFIG_LWIP_DHCPS_MAX_STATION_NUM=8 -# end of DHCP server - -# CONFIG_LWIP_AUTOIP is not set -CONFIG_LWIP_IPV6=y -# CONFIG_LWIP_IPV6_AUTOCONFIG is not set -CONFIG_LWIP_IPV6_NUM_ADDRESSES=3 -# CONFIG_LWIP_IPV6_FORWARD is not set -# CONFIG_LWIP_NETIF_STATUS_CALLBACK is not set -CONFIG_LWIP_NETIF_LOOPBACK=y -CONFIG_LWIP_LOOPBACK_MAX_PBUFS=8 - -# -# TCP -# -CONFIG_LWIP_MAX_ACTIVE_TCP=16 -CONFIG_LWIP_MAX_LISTENING_TCP=16 -CONFIG_LWIP_TCP_HIGH_SPEED_RETRANSMISSION=y -CONFIG_LWIP_TCP_MAXRTX=12 -CONFIG_LWIP_TCP_SYNMAXRTX=12 -CONFIG_LWIP_TCP_MSS=1440 -CONFIG_LWIP_TCP_TMR_INTERVAL=250 -CONFIG_LWIP_TCP_MSL=60000 -CONFIG_LWIP_TCP_FIN_WAIT_TIMEOUT=20000 -CONFIG_LWIP_TCP_SND_BUF_DEFAULT=5744 -CONFIG_LWIP_TCP_WND_DEFAULT=5744 -CONFIG_LWIP_TCP_RECVMBOX_SIZE=6 -CONFIG_LWIP_TCP_QUEUE_OOSEQ=y -# CONFIG_LWIP_TCP_SACK_OUT is not set -CONFIG_LWIP_TCP_OVERSIZE_MSS=y -# CONFIG_LWIP_TCP_OVERSIZE_QUARTER_MSS is not set -# CONFIG_LWIP_TCP_OVERSIZE_DISABLE is not set -CONFIG_LWIP_TCP_RTO_TIME=1500 -# end of TCP - -# -# UDP -# -CONFIG_LWIP_MAX_UDP_PCBS=16 -CONFIG_LWIP_UDP_RECVMBOX_SIZE=6 -# end of UDP - -# -# Checksums -# -# CONFIG_LWIP_CHECKSUM_CHECK_IP is not set -# CONFIG_LWIP_CHECKSUM_CHECK_UDP is not set -CONFIG_LWIP_CHECKSUM_CHECK_ICMP=y -# end of Checksums - -CONFIG_LWIP_TCPIP_TASK_STACK_SIZE=3072 -CONFIG_LWIP_TCPIP_TASK_AFFINITY_NO_AFFINITY=y -# CONFIG_LWIP_TCPIP_TASK_AFFINITY_CPU0 is not set -# CONFIG_LWIP_TCPIP_TASK_AFFINITY_CPU1 is not set -CONFIG_LWIP_TCPIP_TASK_AFFINITY=0x7FFFFFFF -# CONFIG_LWIP_PPP_SUPPORT is not set -CONFIG_LWIP_IPV6_MEMP_NUM_ND6_QUEUE=3 -CONFIG_LWIP_IPV6_ND6_NUM_NEIGHBORS=5 -# CONFIG_LWIP_SLIP_SUPPORT is not set - -# -# ICMP -# -CONFIG_LWIP_ICMP=y -# CONFIG_LWIP_MULTICAST_PING is not set -# CONFIG_LWIP_BROADCAST_PING is not set -# end of ICMP - -# -# LWIP RAW API -# -CONFIG_LWIP_MAX_RAW_PCBS=16 -# end of LWIP RAW API - -# -# SNTP -# -CONFIG_LWIP_SNTP_MAX_SERVERS=1 -# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set -CONFIG_LWIP_SNTP_UPDATE_DELAY=3600000 -# end of SNTP - -CONFIG_LWIP_BRIDGEIF_MAX_PORTS=7 -CONFIG_LWIP_ESP_LWIP_ASSERT=y - -# -# Hooks -# -# CONFIG_LWIP_HOOK_TCP_ISN_NONE is not set -CONFIG_LWIP_HOOK_TCP_ISN_DEFAULT=y -# CONFIG_LWIP_HOOK_TCP_ISN_CUSTOM is not set -CONFIG_LWIP_HOOK_IP6_ROUTE_NONE=y -# CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT is not set -# CONFIG_LWIP_HOOK_IP6_ROUTE_CUSTOM is not set -CONFIG_LWIP_HOOK_ND6_GET_GW_NONE=y -# CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT is not set -# CONFIG_LWIP_HOOK_ND6_GET_GW_CUSTOM is not set -CONFIG_LWIP_HOOK_NETCONN_EXT_RESOLVE_NONE=y -# CONFIG_LWIP_HOOK_NETCONN_EXT_RESOLVE_DEFAULT is not set -# CONFIG_LWIP_HOOK_NETCONN_EXT_RESOLVE_CUSTOM is not set -CONFIG_LWIP_HOOK_IP6_INPUT_NONE=y -# CONFIG_LWIP_HOOK_IP6_INPUT_DEFAULT is not set -# CONFIG_LWIP_HOOK_IP6_INPUT_CUSTOM is not set -# end of Hooks - -# CONFIG_LWIP_DEBUG is not set -# end of LWIP - -# -# mbedTLS -# -# CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC is not set -CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC=y -# CONFIG_MBEDTLS_DEFAULT_MEM_ALLOC is not set -# CONFIG_MBEDTLS_CUSTOM_MEM_ALLOC is not set -CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN=y -CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN=16384 -CONFIG_MBEDTLS_SSL_OUT_CONTENT_LEN=4096 -# CONFIG_MBEDTLS_DEBUG is not set - -# -# mbedTLS v3.x related -# -# CONFIG_MBEDTLS_SSL_PROTO_TLS1_3 is not set -# CONFIG_MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH is not set -# CONFIG_MBEDTLS_X509_TRUSTED_CERT_CALLBACK is not set -# CONFIG_MBEDTLS_SSL_CONTEXT_SERIALIZATION is not set -CONFIG_MBEDTLS_SSL_KEEP_PEER_CERTIFICATE=y - -# -# DTLS-based configurations -# -# CONFIG_MBEDTLS_SSL_DTLS_CONNECTION_ID is not set -CONFIG_MBEDTLS_SSL_DTLS_SRTP=y -# end of DTLS-based configurations -# end of mbedTLS v3.x related - -# -# Certificate Bundle -# -CONFIG_MBEDTLS_CERTIFICATE_BUNDLE=y -CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_FULL=y -# CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_CMN is not set -# CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_NONE is not set -# CONFIG_MBEDTLS_CUSTOM_CERTIFICATE_BUNDLE is not set -CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_MAX_CERTS=200 -# end of Certificate Bundle - -# CONFIG_MBEDTLS_ECP_RESTARTABLE is not set -# CONFIG_MBEDTLS_CMAC_C is not set -CONFIG_MBEDTLS_HARDWARE_AES=y -CONFIG_MBEDTLS_AES_USE_INTERRUPT=y -CONFIG_MBEDTLS_HARDWARE_MPI=y -CONFIG_MBEDTLS_MPI_USE_INTERRUPT=y -CONFIG_MBEDTLS_HARDWARE_SHA=y -CONFIG_MBEDTLS_ROM_MD5=y -# CONFIG_MBEDTLS_ATCA_HW_ECDSA_SIGN is not set -# CONFIG_MBEDTLS_ATCA_HW_ECDSA_VERIFY is not set -CONFIG_MBEDTLS_HAVE_TIME=y -# CONFIG_MBEDTLS_PLATFORM_TIME_ALT is not set -# CONFIG_MBEDTLS_HAVE_TIME_DATE is not set -CONFIG_MBEDTLS_ECDSA_DETERMINISTIC=y -CONFIG_MBEDTLS_SHA512_C=y -CONFIG_MBEDTLS_TLS_SERVER_AND_CLIENT=y -# CONFIG_MBEDTLS_TLS_SERVER_ONLY is not set -# CONFIG_MBEDTLS_TLS_CLIENT_ONLY is not set -# CONFIG_MBEDTLS_TLS_DISABLED is not set -CONFIG_MBEDTLS_TLS_SERVER=y -CONFIG_MBEDTLS_TLS_CLIENT=y -CONFIG_MBEDTLS_TLS_ENABLED=y - -# -# TLS Key Exchange Methods -# -# CONFIG_MBEDTLS_PSK_MODES is not set -CONFIG_MBEDTLS_KEY_EXCHANGE_RSA=y -CONFIG_MBEDTLS_KEY_EXCHANGE_ELLIPTIC_CURVE=y -CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_RSA=y -CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA=y -CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA=y -CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_RSA=y -# end of TLS Key Exchange Methods - -CONFIG_MBEDTLS_SSL_RENEGOTIATION=y -CONFIG_MBEDTLS_SSL_PROTO_TLS1_2=y -# CONFIG_MBEDTLS_SSL_PROTO_GMTSSL1_1 is not set -CONFIG_MBEDTLS_SSL_PROTO_DTLS=y -CONFIG_MBEDTLS_SSL_ALPN=y -CONFIG_MBEDTLS_CLIENT_SSL_SESSION_TICKETS=y -CONFIG_MBEDTLS_SERVER_SSL_SESSION_TICKETS=y - -# -# Symmetric Ciphers -# -CONFIG_MBEDTLS_AES_C=y -# CONFIG_MBEDTLS_CAMELLIA_C is not set -# CONFIG_MBEDTLS_DES_C is not set -# CONFIG_MBEDTLS_BLOWFISH_C is not set -# CONFIG_MBEDTLS_XTEA_C is not set -CONFIG_MBEDTLS_CCM_C=y -CONFIG_MBEDTLS_GCM_C=y -# CONFIG_MBEDTLS_NIST_KW_C is not set -# end of Symmetric Ciphers - -# CONFIG_MBEDTLS_RIPEMD160_C is not set - -# -# Certificates -# -CONFIG_MBEDTLS_PEM_PARSE_C=y -CONFIG_MBEDTLS_PEM_WRITE_C=y -CONFIG_MBEDTLS_X509_CRL_PARSE_C=y -CONFIG_MBEDTLS_X509_CSR_PARSE_C=y -# end of Certificates - -CONFIG_MBEDTLS_ECP_C=y -# CONFIG_MBEDTLS_DHM_C is not set -CONFIG_MBEDTLS_ECDH_C=y -CONFIG_MBEDTLS_ECDSA_C=y -# CONFIG_MBEDTLS_ECJPAKE_C is not set -CONFIG_MBEDTLS_ECP_DP_SECP192R1_ENABLED=y -CONFIG_MBEDTLS_ECP_DP_SECP224R1_ENABLED=y -CONFIG_MBEDTLS_ECP_DP_SECP256R1_ENABLED=y -CONFIG_MBEDTLS_ECP_DP_SECP384R1_ENABLED=y -CONFIG_MBEDTLS_ECP_DP_SECP521R1_ENABLED=y -CONFIG_MBEDTLS_ECP_DP_SECP192K1_ENABLED=y -CONFIG_MBEDTLS_ECP_DP_SECP224K1_ENABLED=y -CONFIG_MBEDTLS_ECP_DP_SECP256K1_ENABLED=y -CONFIG_MBEDTLS_ECP_DP_BP256R1_ENABLED=y -CONFIG_MBEDTLS_ECP_DP_BP384R1_ENABLED=y -CONFIG_MBEDTLS_ECP_DP_BP512R1_ENABLED=y -CONFIG_MBEDTLS_ECP_DP_CURVE25519_ENABLED=y -CONFIG_MBEDTLS_ECP_NIST_OPTIM=y -# CONFIG_MBEDTLS_POLY1305_C is not set -# CONFIG_MBEDTLS_CHACHA20_C is not set -# CONFIG_MBEDTLS_HKDF_C is not set -# CONFIG_MBEDTLS_THREADING_C is not set -# CONFIG_MBEDTLS_LARGE_KEY_SOFTWARE_MPI is not set -# CONFIG_MBEDTLS_SECURITY_RISKS is not set -# end of mbedTLS - -# -# mDNS -# -CONFIG_MDNS_MAX_INTERFACES=3 -CONFIG_MDNS_MAX_SERVICES=10 -CONFIG_MDNS_TASK_PRIORITY=1 -CONFIG_MDNS_TASK_STACK_SIZE=4096 -# CONFIG_MDNS_TASK_AFFINITY_NO_AFFINITY is not set -CONFIG_MDNS_TASK_AFFINITY_CPU0=y -# CONFIG_MDNS_TASK_AFFINITY_CPU1 is not set -CONFIG_MDNS_TASK_AFFINITY=0x0 -CONFIG_MDNS_SERVICE_ADD_TIMEOUT_MS=2000 -CONFIG_MDNS_TIMER_PERIOD_MS=100 -# CONFIG_MDNS_NETWORKING_SOCKET is not set -# CONFIG_MDNS_SKIP_SUPPRESSING_OWN_QUERIES is not set -# CONFIG_MDNS_ENABLE_DEBUG_PRINTS is not set -# CONFIG_MDNS_RESPOND_REVERSE_QUERIES is not set -CONFIG_MDNS_MULTIPLE_INSTANCE=y - -# -# MDNS Predefined interfaces -# -CONFIG_MDNS_PREDEF_NETIF_STA=y -CONFIG_MDNS_PREDEF_NETIF_AP=y -CONFIG_MDNS_PREDEF_NETIF_ETH=y -# end of MDNS Predefined interfaces -# end of mDNS - -# -# ESP-MQTT Configurations -# -CONFIG_MQTT_PROTOCOL_311=y -# CONFIG_MQTT_PROTOCOL_5 is not set -CONFIG_MQTT_TRANSPORT_SSL=y -CONFIG_MQTT_TRANSPORT_WEBSOCKET=y -CONFIG_MQTT_TRANSPORT_WEBSOCKET_SECURE=y -# CONFIG_MQTT_MSG_ID_INCREMENTAL is not set -# CONFIG_MQTT_SKIP_PUBLISH_IF_DISCONNECTED is not set -# CONFIG_MQTT_REPORT_DELETED_MESSAGES is not set -# CONFIG_MQTT_USE_CUSTOM_CONFIG is not set -# CONFIG_MQTT_TASK_CORE_SELECTION_ENABLED is not set -# CONFIG_MQTT_CUSTOM_OUTBOX is not set -# end of ESP-MQTT Configurations - -# -# Newlib -# -CONFIG_NEWLIB_STDOUT_LINE_ENDING_CRLF=y -# CONFIG_NEWLIB_STDOUT_LINE_ENDING_LF is not set -# CONFIG_NEWLIB_STDOUT_LINE_ENDING_CR is not set -# CONFIG_NEWLIB_STDIN_LINE_ENDING_CRLF is not set -# CONFIG_NEWLIB_STDIN_LINE_ENDING_LF is not set -CONFIG_NEWLIB_STDIN_LINE_ENDING_CR=y -# CONFIG_NEWLIB_NANO_FORMAT is not set -CONFIG_NEWLIB_TIME_SYSCALL_USE_RTC_HRT=y -# CONFIG_NEWLIB_TIME_SYSCALL_USE_RTC is not set -# CONFIG_NEWLIB_TIME_SYSCALL_USE_HRT is not set -# CONFIG_NEWLIB_TIME_SYSCALL_USE_NONE is not set -# end of Newlib - -# -# NVS -# -# CONFIG_NVS_ASSERT_ERROR_CHECK is not set -# end of NVS - -# -# OpenThread -# -# CONFIG_OPENTHREAD_ENABLED is not set -# end of OpenThread - -# -# Protocomm -# -CONFIG_ESP_PROTOCOMM_SUPPORT_SECURITY_VERSION_0=y -CONFIG_ESP_PROTOCOMM_SUPPORT_SECURITY_VERSION_1=y -CONFIG_ESP_PROTOCOMM_SUPPORT_SECURITY_VERSION_2=y -# end of Protocomm - -# -# PThreads -# -CONFIG_PTHREAD_TASK_PRIO_DEFAULT=5 -CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT=3072 -CONFIG_PTHREAD_STACK_MIN=768 -CONFIG_PTHREAD_DEFAULT_CORE_NO_AFFINITY=y -# CONFIG_PTHREAD_DEFAULT_CORE_0 is not set -# CONFIG_PTHREAD_DEFAULT_CORE_1 is not set -CONFIG_PTHREAD_TASK_CORE_DEFAULT=-1 -CONFIG_PTHREAD_TASK_NAME_DEFAULT="pthread" -# end of PThreads - -# -# MMU Config -# -CONFIG_MMU_PAGE_SIZE_64KB=y -CONFIG_MMU_PAGE_MODE="64KB" -CONFIG_MMU_PAGE_SIZE=0x10000 -# end of MMU Config - -# -# SPI Flash driver -# -# CONFIG_SPI_FLASH_VERIFY_WRITE is not set -# CONFIG_SPI_FLASH_ENABLE_COUNTERS is not set -CONFIG_SPI_FLASH_ROM_DRIVER_PATCH=y -CONFIG_SPI_FLASH_HAS_ROM_IMPL=y -# CONFIG_SPI_FLASH_ROM_IMPL is not set -CONFIG_SPI_FLASH_DANGEROUS_WRITE_ABORTS=y -# CONFIG_SPI_FLASH_DANGEROUS_WRITE_FAILS is not set -# CONFIG_SPI_FLASH_DANGEROUS_WRITE_ALLOWED is not set -# CONFIG_SPI_FLASH_SHARE_SPI1_BUS is not set -# CONFIG_SPI_FLASH_BYPASS_BLOCK_ERASE is not set -CONFIG_SPI_FLASH_YIELD_DURING_ERASE=y -CONFIG_SPI_FLASH_ERASE_YIELD_DURATION_MS=20 -CONFIG_SPI_FLASH_ERASE_YIELD_TICKS=1 -CONFIG_SPI_FLASH_WRITE_CHUNK_SIZE=8192 -# CONFIG_SPI_FLASH_SIZE_OVERRIDE is not set -# CONFIG_SPI_FLASH_CHECK_ERASE_TIMEOUT_DISABLED is not set -# CONFIG_SPI_FLASH_OVERRIDE_CHIP_DRIVER_LIST is not set - -# -# SPI Flash behavior when brownout -# -CONFIG_SPI_FLASH_BROWNOUT_RESET_XMC=y -CONFIG_SPI_FLASH_BROWNOUT_RESET=y -# end of SPI Flash behavior when brownout - -# -# Auto-detect flash chips -# -CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=y -CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP=y -CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=y -CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP=y -CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP=y -CONFIG_SPI_FLASH_SUPPORT_TH_CHIP=y -CONFIG_SPI_FLASH_SUPPORT_MXIC_OPI_CHIP=y -# end of Auto-detect flash chips - -CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE=y -# end of SPI Flash driver - -# -# SPIFFS Configuration -# -CONFIG_SPIFFS_MAX_PARTITIONS=3 - -# -# SPIFFS Cache Configuration -# -CONFIG_SPIFFS_CACHE=y -CONFIG_SPIFFS_CACHE_WR=y -# CONFIG_SPIFFS_CACHE_STATS is not set -# end of SPIFFS Cache Configuration - -CONFIG_SPIFFS_PAGE_CHECK=y -CONFIG_SPIFFS_GC_MAX_RUNS=10 -# CONFIG_SPIFFS_GC_STATS is not set -CONFIG_SPIFFS_PAGE_SIZE=256 -CONFIG_SPIFFS_OBJ_NAME_LEN=32 -# CONFIG_SPIFFS_FOLLOW_SYMLINKS is not set -CONFIG_SPIFFS_USE_MAGIC=y -CONFIG_SPIFFS_USE_MAGIC_LENGTH=y -CONFIG_SPIFFS_META_LENGTH=4 -CONFIG_SPIFFS_USE_MTIME=y - -# -# Debug Configuration -# -# CONFIG_SPIFFS_DBG is not set -# CONFIG_SPIFFS_API_DBG is not set -# CONFIG_SPIFFS_GC_DBG is not set -# CONFIG_SPIFFS_CACHE_DBG is not set -# CONFIG_SPIFFS_CHECK_DBG is not set -# CONFIG_SPIFFS_TEST_VISUALISATION is not set -# end of Debug Configuration -# end of SPIFFS Configuration - -# -# TCP Transport -# - -# -# Websocket -# -CONFIG_WS_TRANSPORT=y -CONFIG_WS_BUFFER_SIZE=1024 -# CONFIG_WS_DYNAMIC_BUFFER is not set -# end of Websocket -# end of TCP Transport - -# -# Ultra Low Power (ULP) Co-processor -# -# CONFIG_ULP_COPROC_ENABLED is not set -# end of Ultra Low Power (ULP) Co-processor - -# -# Unity unit testing library -# -CONFIG_UNITY_ENABLE_FLOAT=y -CONFIG_UNITY_ENABLE_DOUBLE=y -# CONFIG_UNITY_ENABLE_64BIT is not set -# CONFIG_UNITY_ENABLE_COLOR is not set -CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=y -# CONFIG_UNITY_ENABLE_FIXTURE is not set -# CONFIG_UNITY_ENABLE_BACKTRACE_ON_FAIL is not set -# end of Unity unit testing library - -# -# USB-OTG -# -CONFIG_USB_OTG_SUPPORTED=y -CONFIG_USB_HOST_CONTROL_TRANSFER_MAX_SIZE=256 -CONFIG_USB_HOST_HW_BUFFER_BIAS_BALANCED=y -# CONFIG_USB_HOST_HW_BUFFER_BIAS_IN is not set -# CONFIG_USB_HOST_HW_BUFFER_BIAS_PERIODIC_OUT is not set - -# -# Root Hub configuration -# -CONFIG_USB_HOST_DEBOUNCE_DELAY_MS=250 -CONFIG_USB_HOST_RESET_HOLD_MS=30 -CONFIG_USB_HOST_RESET_RECOVERY_MS=30 -CONFIG_USB_HOST_SET_ADDR_RECOVERY_MS=10 -# end of Root Hub configuration -# end of USB-OTG - -# -# Virtual file system -# -CONFIG_VFS_SUPPORT_IO=y -CONFIG_VFS_SUPPORT_DIR=y -CONFIG_VFS_SUPPORT_SELECT=y -CONFIG_VFS_SUPPRESS_SELECT_DEBUG_OUTPUT=y -CONFIG_VFS_SUPPORT_TERMIOS=y - -# -# Host File System I/O (Semihosting) -# -CONFIG_VFS_SEMIHOSTFS_MAX_MOUNT_POINTS=1 -# end of Host File System I/O (Semihosting) -# end of Virtual file system - -# -# Wear Levelling -# -# CONFIG_WL_SECTOR_SIZE_512 is not set -CONFIG_WL_SECTOR_SIZE_4096=y -CONFIG_WL_SECTOR_SIZE=4096 -# end of Wear Levelling - -# -# Wi-Fi Provisioning Manager -# -CONFIG_WIFI_PROV_SCAN_MAX_ENTRIES=16 -CONFIG_WIFI_PROV_AUTOSTOP_TIMEOUT=30 -# CONFIG_WIFI_PROV_BLE_FORCE_ENCRYPTION is not set -CONFIG_WIFI_PROV_STA_ALL_CHANNEL_SCAN=y -# CONFIG_WIFI_PROV_STA_FAST_SCAN is not set -# end of Wi-Fi Provisioning Manager - -# -# Supplicant -# -CONFIG_WPA_MBEDTLS_CRYPTO=y -CONFIG_WPA_MBEDTLS_TLS_CLIENT=y -# CONFIG_WPA_WAPI_PSK is not set -# CONFIG_WPA_SUITE_B_192 is not set -# CONFIG_WPA_DEBUG_PRINT is not set -# CONFIG_WPA_TESTING_OPTIONS is not set -# CONFIG_WPA_WPS_STRICT is not set -# CONFIG_WPA_11KV_SUPPORT is not set -# CONFIG_WPA_MBO_SUPPORT is not set -# CONFIG_WPA_DPP_SUPPORT is not set -# CONFIG_WPA_11R_SUPPORT is not set -# CONFIG_WPA_WPS_SOFTAP_REGISTRAR is not set -# end of Supplicant -# end of Component config - -# Deprecated options for backward compatibility -# CONFIG_NO_BLOBS is not set -# CONFIG_LOG_BOOTLOADER_LEVEL_NONE is not set -# CONFIG_LOG_BOOTLOADER_LEVEL_ERROR is not set -# CONFIG_LOG_BOOTLOADER_LEVEL_WARN is not set -CONFIG_LOG_BOOTLOADER_LEVEL_INFO=y -# CONFIG_LOG_BOOTLOADER_LEVEL_DEBUG is not set -# CONFIG_LOG_BOOTLOADER_LEVEL_VERBOSE is not set -CONFIG_LOG_BOOTLOADER_LEVEL=3 -# CONFIG_APP_ROLLBACK_ENABLE is not set -# CONFIG_FLASH_ENCRYPTION_ENABLED is not set -# CONFIG_FLASHMODE_QIO is not set -# CONFIG_FLASHMODE_QOUT is not set -CONFIG_FLASHMODE_DIO=y -# CONFIG_FLASHMODE_DOUT is not set -CONFIG_MONITOR_BAUD=115200 -CONFIG_OPTIMIZATION_LEVEL_DEBUG=y -CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG=y -# CONFIG_OPTIMIZATION_LEVEL_RELEASE is not set -# CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE is not set -CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED=y -# CONFIG_OPTIMIZATION_ASSERTIONS_SILENT is not set -# CONFIG_OPTIMIZATION_ASSERTIONS_DISABLED is not set -CONFIG_OPTIMIZATION_ASSERTION_LEVEL=2 -# CONFIG_CXX_EXCEPTIONS is not set -CONFIG_STACK_CHECK_NONE=y -# CONFIG_STACK_CHECK_NORM is not set -# CONFIG_STACK_CHECK_STRONG is not set -# CONFIG_STACK_CHECK_ALL is not set -# CONFIG_WARN_WRITE_STRINGS is not set -# CONFIG_ESP32_APPTRACE_DEST_TRAX is not set -CONFIG_ESP32_APPTRACE_DEST_NONE=y -CONFIG_ESP32_APPTRACE_LOCK_ENABLE=y -# CONFIG_MCPWM_ISR_IN_IRAM is not set -# CONFIG_EVENT_LOOP_PROFILING is not set -CONFIG_POST_EVENTS_FROM_ISR=y -CONFIG_POST_EVENTS_FROM_IRAM_ISR=y -# CONFIG_OTA_ALLOW_HTTP is not set -CONFIG_ESP32S3_DEEP_SLEEP_WAKEUP_DELAY=2000 -CONFIG_ESP32S3_RTC_CLK_SRC_INT_RC=y -# CONFIG_ESP32S3_RTC_CLK_SRC_EXT_CRYS is not set -# CONFIG_ESP32S3_RTC_CLK_SRC_EXT_OSC is not set -# CONFIG_ESP32S3_RTC_CLK_SRC_INT_8MD256 is not set -CONFIG_ESP32S3_RTC_CLK_CAL_CYCLES=1024 -CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE=y -# CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION is not set -CONFIG_ESP32_PHY_MAX_WIFI_TX_POWER=20 -CONFIG_ESP32_PHY_MAX_TX_POWER=20 -CONFIG_REDUCE_PHY_TX_POWER=y -CONFIG_ESP32_REDUCE_PHY_TX_POWER=y -CONFIG_ESP_SYSTEM_PM_POWER_DOWN_CPU=y -CONFIG_ESP32S3_SPIRAM_SUPPORT=y -CONFIG_DEFAULT_PSRAM_CLK_IO=30 -CONFIG_DEFAULT_PSRAM_CS_IO=26 -# CONFIG_ESP32S3_DEFAULT_CPU_FREQ_80 is not set -CONFIG_ESP32S3_DEFAULT_CPU_FREQ_160=y -# CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240 is not set -CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ=160 -CONFIG_SYSTEM_EVENT_QUEUE_SIZE=32 -CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE=2304 -CONFIG_MAIN_TASK_STACK_SIZE=35840 -CONFIG_CONSOLE_UART_DEFAULT=y -# CONFIG_CONSOLE_UART_CUSTOM is not set -# CONFIG_CONSOLE_UART_NONE is not set -# CONFIG_ESP_CONSOLE_UART_NONE is not set -CONFIG_CONSOLE_UART=y -CONFIG_CONSOLE_UART_NUM=0 -CONFIG_CONSOLE_UART_BAUDRATE=115200 -CONFIG_INT_WDT=y -CONFIG_INT_WDT_TIMEOUT_MS=300 -CONFIG_INT_WDT_CHECK_CPU1=y -CONFIG_TASK_WDT=y -CONFIG_ESP_TASK_WDT=y -# CONFIG_TASK_WDT_PANIC is not set -CONFIG_TASK_WDT_TIMEOUT_S=5 -# CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0 is not set -# CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1 is not set -# CONFIG_ESP32_DEBUG_STUBS_ENABLE is not set -CONFIG_ESP32S3_DEBUG_OCDAWARE=y -CONFIG_BROWNOUT_DET=y -CONFIG_ESP32S3_BROWNOUT_DET=y -CONFIG_ESP32S3_BROWNOUT_DET=y -CONFIG_BROWNOUT_DET_LVL_SEL_7=y -CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_7=y -# CONFIG_BROWNOUT_DET_LVL_SEL_6 is not set -# CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_6 is not set -# CONFIG_BROWNOUT_DET_LVL_SEL_5 is not set -# CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_5 is not set -# CONFIG_BROWNOUT_DET_LVL_SEL_4 is not set -# CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_4 is not set -# CONFIG_BROWNOUT_DET_LVL_SEL_3 is not set -# CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_3 is not set -# CONFIG_BROWNOUT_DET_LVL_SEL_2 is not set -# CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_2 is not set -# CONFIG_BROWNOUT_DET_LVL_SEL_1 is not set -# CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_1 is not set -CONFIG_BROWNOUT_DET_LVL=7 -CONFIG_ESP32S3_BROWNOUT_DET_LVL=7 -CONFIG_IPC_TASK_STACK_SIZE=1280 -CONFIG_TIMER_TASK_STACK_SIZE=3584 -# CONFIG_EXTERNAL_COEX_ENABLE is not set -# CONFIG_ESP32_ENABLE_COREDUMP_TO_FLASH is not set -# CONFIG_ESP32_ENABLE_COREDUMP_TO_UART is not set -CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE=y -CONFIG_TIMER_TASK_PRIORITY=1 -CONFIG_TIMER_TASK_STACK_DEPTH=2048 -CONFIG_TIMER_QUEUE_LENGTH=10 -# CONFIG_ENABLE_STATIC_TASK_CLEAN_UP_HOOK is not set -# CONFIG_HAL_ASSERTION_SILIENT is not set -# CONFIG_L2_TO_L3_COPY is not set -CONFIG_ESP_GRATUITOUS_ARP=y -CONFIG_GARP_TMR_INTERVAL=60 -CONFIG_TCPIP_RECVMBOX_SIZE=32 -CONFIG_TCP_MAXRTX=12 -CONFIG_TCP_SYNMAXRTX=12 -CONFIG_TCP_MSS=1440 -CONFIG_TCP_MSL=60000 -CONFIG_TCP_SND_BUF_DEFAULT=5744 -CONFIG_TCP_WND_DEFAULT=5744 -CONFIG_TCP_RECVMBOX_SIZE=6 -CONFIG_TCP_QUEUE_OOSEQ=y -CONFIG_TCP_OVERSIZE_MSS=y -# CONFIG_TCP_OVERSIZE_QUARTER_MSS is not set -# CONFIG_TCP_OVERSIZE_DISABLE is not set -CONFIG_UDP_RECVMBOX_SIZE=6 -CONFIG_TCPIP_TASK_STACK_SIZE=3072 -CONFIG_TCPIP_TASK_AFFINITY_NO_AFFINITY=y -# CONFIG_TCPIP_TASK_AFFINITY_CPU0 is not set -# CONFIG_TCPIP_TASK_AFFINITY_CPU1 is not set -CONFIG_TCPIP_TASK_AFFINITY=0x7FFFFFFF -# CONFIG_PPP_SUPPORT is not set -CONFIG_ESP32S3_TIME_SYSCALL_USE_RTC_SYSTIMER=y -CONFIG_ESP32S3_TIME_SYSCALL_USE_RTC_FRC1=y -# CONFIG_ESP32S3_TIME_SYSCALL_USE_RTC is not set -# CONFIG_ESP32S3_TIME_SYSCALL_USE_SYSTIMER is not set -# CONFIG_ESP32S3_TIME_SYSCALL_USE_FRC1 is not set -# CONFIG_ESP32S3_TIME_SYSCALL_USE_NONE is not set -CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT=5 -CONFIG_ESP32_PTHREAD_TASK_STACK_SIZE_DEFAULT=3072 -CONFIG_ESP32_PTHREAD_STACK_MIN=768 -CONFIG_ESP32_DEFAULT_PTHREAD_CORE_NO_AFFINITY=y -# CONFIG_ESP32_DEFAULT_PTHREAD_CORE_0 is not set -# CONFIG_ESP32_DEFAULT_PTHREAD_CORE_1 is not set -CONFIG_ESP32_PTHREAD_TASK_CORE_DEFAULT=-1 -CONFIG_ESP32_PTHREAD_TASK_NAME_DEFAULT="pthread" -CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ABORTS=y -# CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_FAILS is not set -# CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ALLOWED is not set -CONFIG_SUPPRESS_SELECT_DEBUG_OUTPUT=y -CONFIG_SUPPORT_TERMIOS=y -CONFIG_SEMIHOSTFS_MAX_MOUNT_POINTS=1 -# End of deprecated options diff --git a/examples/sample/main.c b/examples/sample/main.c index 4d420e6..36123f6 100644 --- a/examples/sample/main.c +++ b/examples/sample/main.c @@ -79,6 +79,11 @@ int main(int argc, char *argv[]) { pthread_t peer_singaling_thread; pthread_t peer_connection_thread; + if (argc < 2) { + printf("Usage: %s \n", argv[0]); + return -1; + } + signal(SIGINT, signal_handler); PeerConfiguration config = { @@ -90,15 +95,19 @@ int main(int argc, char *argv[]) { .audio_codec = CODEC_PCMA }; - snprintf((char*)buf, sizeof(buf), "test_%d", getpid()); - printf("open https://sepfy.github.io/webrtc?deviceId=%s\n", buf); + ServiceConfiguration service_config = SERVICE_CONFIG_DEFAULT(); + + printf("open https://sepfy.github.io/webrtc?deviceId=%s\n", argv[1]); peer_init(); g_pc = peer_connection_create(&config); peer_connection_oniceconnectionstatechange(g_pc, onconnectionstatechange); peer_connection_ondatachannel(g_pc, onmessage, onopen, onclose); - peer_signaling_join_channel((const char*)buf, g_pc); + service_config.client_id = argv[1]; + service_config.pc = g_pc; + peer_signaling_set_config(&service_config); + peer_signaling_join_channel(); pthread_create(&peer_connection_thread, NULL, peer_connection_task, NULL); pthread_create(&peer_singaling_thread, NULL, peer_singaling_task, NULL); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0da7b39..c05ccdb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,6 +16,8 @@ include_directories(peer PUBLIC ${MQTT_INCLUDE_PUBLIC_DIRS} ) +add_dependencies(peer cjson mbedtls usrsctp srtp2) + target_link_libraries(peer ${DEP_LIBS}) set_target_properties(peer PROPERTIES PUBLIC_HEADER "${HEADERS}") diff --git a/src/address.c b/src/address.c index f63a727..541538c 100644 --- a/src/address.c +++ b/src/address.c @@ -6,70 +6,60 @@ #include #include +#include "utils.h" #include "address.h" -int addr_ipv4_validate(const char *ipv4, size_t len, Address *addr) { - - int start = 0; - int index = 0; - for (int i = 0; i < len; i++) { - - if (ipv4[i] != '.' && (ipv4[i] < '0' || ipv4[i] > '9')) { - return 0; - } else if (ipv4[i] == '.') { - - addr->ipv4[index++] = atoi(ipv4 + start); - start = i + 1; - } else if (i == (len - 1)) { - - addr->ipv4[index++] = atoi(ipv4 + start); - } else if (index == 4) { - return 0; - } +void addr_set_family(Address *addr, int family) { + switch (family) { + case AF_INET6: + addr->family = AF_INET6; + break; + case AF_INET: + default: + addr->family = AF_INET; + break; } - addr->family = AF_INET; - return 1; } -int addr_ipv6_validate(const char *ipv6, size_t len, Address *addr) { - int ret; - struct sockaddr_in6 sa6; - char astring[INET6_ADDRSTRLEN]; - ret = inet_pton(AF_INET6, ipv6, &(sa6.sin6_addr)); - inet_ntop(AF_INET6, &(sa6.sin6_addr), astring, INET6_ADDRSTRLEN); - memcpy(addr->ipv6, sa6.sin6_addr.s6_addr, 16); - return ret; +void addr_set_port(Address *addr, uint16_t port) { + addr->port = port; + switch (addr->family) { + case AF_INET6: + addr->sin6.sin6_port = htons(port); + break; + case AF_INET: + default: + addr->sin.sin_port = htons(port); + break; + } } -int addr_to_text(const Address *addr, char *buf, size_t len) { - switch (addr->family) { - case AF_INET: - return inet_ntop(AF_INET, addr->ipv4, buf, len) != NULL; - break; - case AF_INET6: - return inet_ntop(AF_INET6, addr->ipv6, buf, len) != NULL; - break; +int addr_from_string(const char *buf, Address *addr) { + if (inet_pton(AF_INET, buf, &(addr->sin.sin_addr)) == 1) { + addr_set_family(addr, AF_INET); + return 1; + } else if (inet_pton(AF_INET6, buf, &(addr->sin6.sin6_addr)) == 1) { + addr_set_family(addr, AF_INET6); + return 1; } return 0; } -int addr_equal(const Address *a, const Address *b) { - if (a->family != b->family) { - return 0; - } +int addr_to_string(const Address *addr, char *buf, size_t len) { - switch (a->family) { - case AF_INET: - for (int i = 0; i < 4; i++) { - if (a->ipv4[i] != b->ipv4[i]) { - return 0; - } - } - break; + memset(buf, 0, sizeof(len)); + switch (addr->family) { case AF_INET6: - break; + return inet_ntop(AF_INET6, &addr->sin6.sin6_addr, buf, len) != NULL; + case AF_INET: + default: + return inet_ntop(AF_INET, &addr->sin.sin_addr, buf, len) != NULL; } + return 0; +} +int addr_equal(const Address *a, const Address *b) { + // TODO return 1; } diff --git a/src/address.h b/src/address.h index 52e2eb1..a036144 100644 --- a/src/address.h +++ b/src/address.h @@ -1,24 +1,30 @@ #ifndef ADDRESS_H_ #define ADDRESS_H_ +#include +#include #include -typedef struct Address Address; - -struct Address { +#define ADDRSTRLEN INET6_ADDRSTRLEN +typedef struct Address { uint8_t family; + struct sockaddr_in sin; + struct sockaddr_in6 sin6; uint16_t port; - uint8_t ipv4[4]; - uint16_t ipv6[8]; +} Address; + +void addr_set_family(Address *addr, int family); + +void addr_set_port(Address *addr, uint16_t port); -}; +int addr_inet6_validate(const char *ipv6, size_t len, Address *addr); -int addr_ipv6_validate(const char *ipv6, size_t len, Address *addr); +int addr_inet_validate(const char *ipv4, size_t len, Address *addr); -int addr_ipv4_validate(const char *ipv4, size_t len, Address *addr); +int addr_to_string(const Address *addr, char *buf, size_t len); -int addr_to_text(const Address *addr, char *buf, size_t len); +int addr_from_string(const char *str, Address *addr); int addr_equal(const Address *a, const Address *b); diff --git a/src/agent.c b/src/agent.c index 4368bf3..7ac6281 100644 --- a/src/agent.c +++ b/src/agent.c @@ -6,7 +6,7 @@ #include #include -#include "udp.h" +#include "socket.h" #include "utils.h" #include "stun.h" #include "ice.h" @@ -21,14 +21,14 @@ static int agent_create_sockets(Agent *agent) { int ret; - if ((ret = udp_socket_create(&agent->udp_sockets[0], AF_INET)) < 0) { + if ((ret = udp_socket_open(&agent->udp_sockets[0], AF_INET, 0)) < 0) { LOGE("Failed to create UDP socket."); return ret; } LOGI("create IPv4 UDP socket: %d", agent->udp_sockets[0].fd); #if CONFIG_IPV6 - if ((ret = udp_socket_create(&agent->udp_sockets[1], AF_INET6)) < 0) { + if ((ret = udp_socket_open(&agent->udp_sockets[1], AF_INET6, 0)) < 0) { LOGE("Failed to create IPv6 UDP socket."); return ret; } @@ -92,7 +92,7 @@ static int agent_create_host_addr(Agent *agent) { udp_socket = &agent->udp_sockets[0]; if (ports_get_host_addr(&udp_socket->bind_addr)) { - LOGD("addr: %d.%d.%d.%d", udp_socket->bind_addr.ipv4[0], udp_socket->bind_addr.ipv4[1], udp_socket->bind_addr.ipv4[2], udp_socket->bind_addr.ipv4[3]); + //LOGD("addr: %d.%d.%d.%d", udp_socket->bind_addr.ipv4[0], udp_socket->bind_addr.ipv4[1], udp_socket->bind_addr.ipv4[2], udp_socket->bind_addr.ipv4[3]); IceCandidate *ice_candidate = agent->local_candidates + agent->local_candidates_count++; ice_candidate_create(ice_candidate, agent->local_candidates_count, ICE_CANDIDATE_TYPE_HOST, &udp_socket->bind_addr); } @@ -100,7 +100,7 @@ static int agent_create_host_addr(Agent *agent) { #if CONFIG_IPV6 udp_socket = &agent->udp_sockets[1]; if (ports_get_host_addr(&udp_socket->bind_addr)) { - LOGD("addr: %x:%x:%x:%x:%x:%x:%x:%x", udp_socket->bind_addr.ipv6[0], udp_socket->bind_addr.ipv6[1], udp_socket->bind_addr.ipv6[2], udp_socket->bind_addr.ipv6[3], udp_socket->bind_addr.ipv6[4], udp_socket->bind_addr.ipv6[5], udp_socket->bind_addr.ipv6[6], udp_socket->bind_addr.ipv6[7]); + //LOGD("addr: %x:%x:%x:%x:%x:%x:%x:%x", udp_socket->bind_addr.ipv6[0], udp_socket->bind_addr.ipv6[1], udp_socket->bind_addr.ipv6[2], udp_socket->bind_addr.ipv6[3], udp_socket->bind_addr.ipv6[4], udp_socket->bind_addr.ipv6[5], udp_socket->bind_addr.ipv6[6], udp_socket->bind_addr.ipv6[7]); IceCandidate *ice_candidate = agent->local_candidates + agent->local_candidates_count++; ice_candidate_create(ice_candidate, agent->local_candidates_count, ICE_CANDIDATE_TYPE_HOST, &udp_socket->bind_addr); } @@ -234,8 +234,10 @@ void agent_deinit(Agent *agent) { */ void agent_gather_candidate(Agent *agent, const char *urls, const char *username, const char *credential) { - char *port = NULL; + char *pos; + int port; char hostname[64]; + char addr_string[ADDRSTRLEN]; int i; int addr_type[1] = {AF_INET}; // ipv6 no need stun Address resolved_addr; @@ -247,24 +249,27 @@ void agent_gather_candidate(Agent *agent, const char *urls, const char *username do { - if ((port = strstr(urls + 5, ":")) == NULL) { + if ((pos = strstr(urls + 5, ":")) == NULL) { break; } - resolved_addr.port = atoi(port + 1); - if (resolved_addr.port <= 0) { + port = atoi(pos + 1); + if (port <= 0) { break; + LOGE("Cannot parse port"); } - LOGI("resolved_addr.port: %d", resolved_addr.port); - snprintf(hostname, port - urls - 5 + 1, "%s", urls + 5); + snprintf(hostname, pos - urls - 5 + 1, "%s", urls + 5); for (i = 0; i < sizeof(addr_type) / sizeof(addr_type[0]); i++) { - resolved_addr.family = addr_type[i]; - if (ports_resolve_addr(hostname, &resolved_addr) == 0) { - LOGI("resolved_addr.ipv4: %d.%d.%d.%d", - resolved_addr.ipv4[0], resolved_addr.ipv4[1], resolved_addr.ipv4[2], resolved_addr.ipv4[3]); + + if (ports_resolve_addr(hostname, &resolved_addr) != 0) { + continue; } + + addr_set_port(&resolved_addr, port); + addr_to_string(&resolved_addr, addr_string, sizeof(addr_string)); + LOGI("stun/turn server %s:%d", addr_string, port); if (strncmp(urls, "stun:", 5) == 0) { LOGD("create stun addr"); @@ -349,6 +354,7 @@ void agent_process_stun_request(Agent *agent, StunMessage *stun_msg, Address *ad memcpy(agent->transaction_id, header->transaction_id, sizeof(header->transaction_id)); agent_create_binding_response(agent, &msg, addr); agent_socket_send(agent, addr, msg.buf, msg.size); + agent->binding_request_time = ports_get_epoch_time(); } break; default: @@ -452,6 +458,7 @@ a=candidate:1 1 UDP 1 36.231.28.50 38143 typ srflx int agent_connectivity_check(Agent *agent) { + char addr_string[ADDRSTRLEN]; uint8_t buf[1400]; StunMessage msg; @@ -464,13 +471,8 @@ int agent_connectivity_check(Agent *agent) { if (agent->nominated_pair->conncheck % AGENT_CONNCHECK_PERIOD == 0) { - if (agent->nominated_pair->remote->addr.family == AF_INET) { - LOGD("send binding request to remote ip: %d.%d.%d.%d, port: %d", agent->nominated_pair->remote->addr.ipv4[0], agent->nominated_pair->remote->addr.ipv4[1], agent->nominated_pair->remote->addr.ipv4[2], agent->nominated_pair->remote->addr.ipv4[3], agent->nominated_pair->remote->addr.port); - } else { - char astring[INET6_ADDRSTRLEN]; - addr_to_text(&(agent->nominated_pair->remote->addr), astring, INET6_ADDRSTRLEN); - LOGD("send binding request to remote ip: %s, port: %d", astring, agent->nominated_pair->remote->addr.port); - } + addr_to_string(&agent->nominated_pair->remote->addr, addr_string, sizeof(addr_string)); + LOGD("send binding request to remote ip: %s, port: %d", addr_string, agent->nominated_pair->remote->addr.port); agent_create_binding_request(agent, &msg); agent_socket_send(agent, &agent->nominated_pair->remote->addr, msg.buf, msg.size); } diff --git a/src/agent.h b/src/agent.h index 58567fc..fe1b9e9 100644 --- a/src/agent.h +++ b/src/agent.h @@ -10,7 +10,7 @@ #include -#include "udp.h" +#include "socket.h" #include "utils.h" #include "stun.h" #include "ice.h" diff --git a/src/config.h b/src/config.h index b3ba16c..502c5c3 100644 --- a/src/config.h +++ b/src/config.h @@ -9,33 +9,16 @@ #define VIDEO_RB_DATA_LENGTH (CONFIG_MTU * 64) #define AUDIO_RB_DATA_LENGTH (CONFIG_MTU * 64) #define DATA_RB_DATA_LENGTH (SCTP_MTU * 128) -#define AUDIO_LATENCY 40 // ms #else #define HAVE_USRSCTP #define VIDEO_RB_DATA_LENGTH (CONFIG_MTU * 256) #define AUDIO_RB_DATA_LENGTH (CONFIG_MTU * 256) #define DATA_RB_DATA_LENGTH (SCTP_MTU * 128) -#define AUDIO_LATENCY 20 // ms -#endif - -#ifndef CONFIG_MQTT -#define CONFIG_MQTT 1 -#endif - -#ifndef CONFIG_WHIP -#define CONFIG_WHIP 0 #endif -// siganling -#define MQTT_HOST "broker.emqx.io" -#define MQTT_PORT 8883 - -#define WHIP_HOST "192.168.1.110" -#define WHIP_PATH "/index/api/whip?app=live&stream=test" -#define WHIP_PORT 443 - -#define KEEPALIVE_CONNCHECK 0 -#define CONFIG_IPV6 1 +#define AUDIO_LATENCY 20 // ms +#define KEEPALIVE_CONNCHECK 10000 +#define CONFIG_IPV6 0 // default use wifi interface #define IFR_NAME "w" diff --git a/src/dtls_srtp.c b/src/dtls_srtp.c index ca60d51..79e412f 100644 --- a/src/dtls_srtp.c +++ b/src/dtls_srtp.c @@ -7,7 +7,7 @@ #include "mbedtls/ssl.h" #include "dtls_srtp.h" #include "address.h" -#include "udp.h" +#include "socket.h" #include "config.h" #include "utils.h" diff --git a/src/dtls_srtp.h b/src/dtls_srtp.h index e6acfbd..c9322a6 100644 --- a/src/dtls_srtp.h +++ b/src/dtls_srtp.h @@ -15,7 +15,6 @@ #include -#include "udp.h" #include "address.h" #define SRTP_MASTER_KEY_LENGTH 16 diff --git a/src/ice.c b/src/ice.c index 4618343..e11ba2d 100644 --- a/src/ice.c +++ b/src/ice.c @@ -7,8 +7,9 @@ #include #include +#include "mdns.h" #include "ports.h" -#include "udp.h" +#include "socket.h" #include "utils.h" #include "ice.h" @@ -52,59 +53,34 @@ void ice_candidate_create(IceCandidate *candidate, int foundation, IceCandidateT void ice_candidate_to_description(IceCandidate *candidate, char *description, int length) { - char typ_raddr[64]; + char addr_string[ADDRSTRLEN]; + char typ_raddr[128]; memset(typ_raddr, 0, sizeof(typ_raddr)); + addr_to_string(&candidate->raddr, addr_string, sizeof(addr_string)); switch (candidate->type) { - case ICE_CANDIDATE_TYPE_HOST: snprintf(typ_raddr, sizeof(typ_raddr), "host"); break; - case ICE_CANDIDATE_TYPE_SRFLX: - snprintf(typ_raddr, sizeof(typ_raddr), "srflx raddr %d.%d.%d.%d rport %d", - candidate->raddr.ipv4[0], - candidate->raddr.ipv4[1], - candidate->raddr.ipv4[2], - candidate->raddr.ipv4[3], - candidate->raddr.port); + snprintf(typ_raddr, sizeof(typ_raddr), "srflx raddr %s rport %d", addr_string, candidate->raddr.port); break; case ICE_CANDIDATE_TYPE_RELAY: - snprintf(typ_raddr, sizeof(typ_raddr), "relay raddr %d.%d.%d.%d rport %d", - candidate->raddr.ipv4[0], - candidate->raddr.ipv4[1], - candidate->raddr.ipv4[2], - candidate->raddr.ipv4[3], - candidate->raddr.port); + snprintf(typ_raddr, sizeof(typ_raddr), "relay raddr %s rport %d", addr_string, candidate->raddr.port); default: break; } - LOGI("candidate->addr.family: %d", candidate->addr.family); - if (candidate->addr.family == AF_INET6) { - char ipv6str[INET6_ADDRSTRLEN]; - inet_ntop(AF_INET6, candidate->addr.ipv6, ipv6str, INET6_ADDRSTRLEN); - snprintf(description, length, "a=candidate:%d %d %s %" PRIu32 " %s %d typ %s\n", - candidate->foundation, - candidate->component, - candidate->transport, - candidate->priority, - ipv6str, - candidate->addr.port, - typ_raddr); - } else { - snprintf(description, length, "a=candidate:%d %d %s %" PRIu32 " %d.%d.%d.%d %d typ %s\n", - candidate->foundation, - candidate->component, - candidate->transport, - candidate->priority, - candidate->addr.ipv4[0], - candidate->addr.ipv4[1], - candidate->addr.ipv4[2], - candidate->addr.ipv4[3], - candidate->addr.port, - typ_raddr); - } + + addr_to_string(&candidate->addr, addr_string, sizeof(addr_string)); + snprintf(description, length, "a=candidate:%d %d %s %" PRIu32 " %s %d typ %s\n", + candidate->foundation, + candidate->component, + candidate->transport, + candidate->priority, + addr_string, + candidate->addr.port, + typ_raddr); } int ice_candidate_from_description(IceCandidate *candidate, char *description, char *end) { @@ -120,7 +96,6 @@ int ice_candidate_from_description(IceCandidate *candidate, char *description, c memset(buf, 0, sizeof(buf)); strncpy(buf, split_start, split_end - split_start); switch (index) { - case 0: candidate->foundation = atoi(buf); break; @@ -139,21 +114,15 @@ int ice_candidate_from_description(IceCandidate *candidate, char *description, c break; case 4: if (strstr(buf, "local") != 0) { - if (ports_resolve_mdns_host(buf, &candidate->addr) < 0) { + if (mdns_resolve_addr(buf, &candidate->addr) == 0) { return -1; } - LOGD("mDNS host: %s, ip: %d.%d.%d.%d", buf, candidate->addr.ipv4[0], candidate->addr.ipv4[1], candidate->addr.ipv4[2], candidate->addr.ipv4[3]); - } else if (addr_ipv4_validate(buf, strlen(buf), &candidate->addr)) { - candidate->addr.family = AF_INET; - } else if (addr_ipv6_validate(buf, strlen(buf), &candidate->addr)) { - candidate->addr.family = AF_INET6; - } else { - return -1; - } - + } else if (addr_from_string(buf, &candidate->addr) == 0) { + return -1; + } break; case 5: - candidate->addr.port = atoi(buf); + addr_set_port(&candidate->addr, atoi(buf)); break; case 7: diff --git a/src/mdns.c b/src/mdns.c new file mode 100644 index 0000000..98efc09 --- /dev/null +++ b/src/mdns.c @@ -0,0 +1,169 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include "utils.h" +#include "address.h" +#include "socket.h" + +#define MDNS_GROUP "224.0.0.251" +#define MDNS_PORT 5353 + +typedef struct DnsHeader { + uint16_t id; + uint16_t flags; + uint16_t qestions; + uint16_t answer_rrs; + uint16_t authority_rrs; + uint16_t additional_rrs; +} DnsHeader; + +typedef struct DnsAnswer { + uint16_t type; + uint16_t class; + uint32_t ttl; + uint16_t length; + uint8_t data[0]; +} DnsAnswer; + +typedef struct DnsQuery { + uint16_t type; + uint16_t class; +} DnsQuery; + +static int mdns_parse_answer(uint8_t *buf, int size, Address *addr) { + + char *pos; + int flags_qr; + DnsHeader *header; + DnsAnswer *answer; + + if (size < sizeof(DnsHeader)) { + LOGE("response too short"); + return -1; + } + + header = (DnsHeader *)buf; + flags_qr = ntohs(header->flags) >> 15; + if (flags_qr != 1) { + LOGD("flag is not a DNS response"); + return -1; + } + + buf += sizeof(DnsHeader); + pos = strstr((char*)buf, "local"); + if (pos == NULL) { + LOGI("not a mDNS response"); + return -1; + } + + + pos += 6; + answer = (DnsAnswer *)pos; + LOGD("type: %"PRIu16", class: %"PRIu16", ttl: %"PRIu32", length: %"PRIu16"", ntohs(answer->type), ntohs(answer->class), ntohl(answer->ttl), ntohs(answer->length)); + if (ntohs(answer->length) != 4) { + LOGI("invalid length"); + return -1; + } + + memcpy(&addr->sin.sin_addr, answer->data, 4); + return 0; +} + +static int mdns_build_query(const char *hostname, uint8_t *buf, int size) { + + int total_size, len, offset; + const char *label, *dot; + DnsHeader *dns_header; + DnsQuery *dns_query; + + total_size = sizeof(DnsHeader) + strlen(hostname) + sizeof(DnsQuery) + 2; + if (size < total_size) { + printf("buf size is not enough"); + return -1; + } + + memset(buf, 0, size); + dns_header = (DnsHeader*)buf; + dns_header->qestions = 0x0100; + offset = sizeof(DnsHeader); + + // Append hostname to query + label = hostname; + while (*label) { + dot = strchr(label, '.'); + if (!dot) { + dot = label + strlen(label); + } + len = dot - label; + buf[offset++] = len; + memcpy(buf + offset, label, len); + offset += len; + label = *dot ? dot + 1 : dot; + } + + buf[offset++] = 0x00; + + dns_query = (DnsQuery*) (buf + offset); + dns_query->type = 0x0100; + dns_query->class = 0x0100; + return total_size; +} + +int mdns_resolve_addr(const char *hostname, Address *addr) { + Address mcast_addr = {0}; + UdpSocket udp_socket; + uint8_t buf[256]; + char addr_string[ADDRSTRLEN]; + struct timeval tv = {1, 0}; + fd_set rfds; + int maxfd, send_retry, recv_retry, size, ret; + + if (udp_socket_open(&udp_socket, AF_INET, MDNS_PORT) < 0) { + LOGE("Failed to create socket"); + return -1; + } + + addr_from_string(MDNS_GROUP, &mcast_addr); + addr_set_port(&mcast_addr, MDNS_PORT); + if (udp_socket_add_multicast_group(&udp_socket, &mcast_addr) < 0) { + LOGE("Failed to add multicast group"); + return -1; + } + + maxfd = udp_socket.fd; + FD_ZERO(&rfds); + + for (send_retry = 3; send_retry > 0; send_retry--) { + size = mdns_build_query(hostname, buf, sizeof(buf)); + udp_socket_sendto(&udp_socket, &mcast_addr, buf, size); + for (recv_retry = 5; recv_retry > 0; recv_retry--) { + FD_SET(udp_socket.fd, &rfds); + ret = select(maxfd + 1, &rfds, NULL, NULL, &tv); + + if (ret < 0) { + LOGE("select error"); + break; + } else if (ret > 0 && FD_ISSET(udp_socket.fd, &rfds)) { + ret = udp_socket_recvfrom(&udp_socket, NULL, buf, sizeof(buf)); + if (!mdns_parse_answer(buf, ret, addr)) { + addr_to_string(addr, addr_string, sizeof(addr_string)); + addr_set_family(addr, AF_INET); + LOGI("Resolved %s -> %s", hostname, addr_string); + udp_socket_close(&udp_socket); + return 1; + } else { + LOGD("timeout"); + } + } + } + } + + LOGI("Failed to resolve hostname"); + udp_socket_close(&udp_socket); + return 0; +} diff --git a/src/mdns.h b/src/mdns.h new file mode 100644 index 0000000..a2c73a1 --- /dev/null +++ b/src/mdns.h @@ -0,0 +1,9 @@ +#ifndef MDNS_H_ +#define MDNS_H_ + +#include +#include "address.h" + +int mdns_resolve_addr(const char *hostname, Address *addr); + +#endif // MDNS_H_ diff --git a/src/peer_connection.c b/src/peer_connection.c index 91b7066..14de686 100644 --- a/src/peer_connection.c +++ b/src/peer_connection.c @@ -286,7 +286,7 @@ static void peer_connection_state_new(PeerConnection *pc) { for (int i = 0; i < sizeof(pc->config.ice_servers)/sizeof(pc->config.ice_servers[0]); ++i) { if (pc->config.ice_servers[i].urls) { - LOGI("ice_servers: %s\n", pc->config.ice_servers[i].urls); + LOGI("ice_servers: %s", pc->config.ice_servers[i].urls); agent_gather_candidate(&pc->agent, pc->config.ice_servers[i].urls, pc->config.ice_servers[i].username, pc->config.ice_servers[i].credential); } } @@ -451,7 +451,7 @@ int peer_connection_loop(PeerConnection *pc) { } - if (KEEPALIVE_CONNCHECK > 0 && (utils_get_timestamp() - pc->agent.binding_request_time) > KEEPALIVE_CONNCHECK) { + if (KEEPALIVE_CONNCHECK > 0 && (ports_get_epoch_time() - pc->agent.binding_request_time) > KEEPALIVE_CONNCHECK) { LOGI("binding request timeout"); STATE_CHANGED(pc, PEER_CONNECTION_CLOSED); diff --git a/src/peer_signaling.c b/src/peer_signaling.c index 65a9b14..82d846a 100644 --- a/src/peer_signaling.c +++ b/src/peer_signaling.c @@ -10,20 +10,31 @@ #include "config.h" #include "base64.h" #include "utils.h" +#include "ports.h" #include "ssl_transport.h" #include "peer_signaling.h" #define KEEP_ALIVE_TIMEOUT_SECONDS 60 #define CONNACK_RECV_TIMEOUT_MS 1000 - -#define JRPC_PEER_STATE "state" -#define JRPC_PEER_OFFER "offer" -#define JRPC_PEER_ANSWER "answer" -#define JRPC_PEER_CLOSE "close" - #define BUF_SIZE 4096 #define TOPIC_SIZE 128 +#define HOST_LEN 64 +#define CRED_LEN 128 + +#define RPC_VERSION "2.0" + +#define RPC_METHOD_STATE "state" +#define RPC_METHOD_OFFER "offer" +#define RPC_METHOD_ANSWER "answer" +#define RPC_METHOD_CLOSE "close" + +#define RPC_ERROR_PARSE_ERROR "{\"code\":-32700,\"message\":\"Parse error\"}" +#define RPC_ERROR_INVALID_REQUEST "{\"code\":-32600,\"message\":\"Invalid Request\"}" +#define RPC_ERROR_METHOD_NOT_FOUND "{\"code\":-32601,\"message\":\"Method not found\"}" +#define RPC_ERROR_INVALID_PARAMS "{\"code\":-32602,\"message\":\"Invalid params\"}" +#define RPC_ERROR_INTERNAL_ERROR "{\"code\":-32603,\"message\":\"Internal error\"}" + typedef struct PeerSignaling { MQTTContext_t mqtt_ctx; @@ -40,6 +51,15 @@ typedef struct PeerSignaling { uint16_t packet_id; int id; + + int mqtt_port; + int http_port; + char mqtt_host[HOST_LEN]; + char http_host[HOST_LEN]; + char http_path[HOST_LEN]; + char username[CRED_LEN]; + char password[CRED_LEN]; + char client_id[CRED_LEN]; PeerConnection *pc; } PeerSignaling; @@ -71,123 +91,115 @@ static void peer_signaling_mqtt_publish(MQTTContext_t *mqtt_ctx, const char *mes } -static cJSON* peer_signaling_create_response(int id) { - - cJSON *json = cJSON_CreateObject(); - - cJSON_AddStringToObject(json, "jsonrpc", "2.0"); - - cJSON_AddNumberToObject(json, "id", id); - - return json; -} - -static void peer_signaling_process_response(cJSON *json) { - - char *payload = cJSON_PrintUnformatted(json); - - if (payload) { - - peer_signaling_mqtt_publish(&g_ps.mqtt_ctx, payload); - - free(payload); - } - - cJSON_Delete(json); -} - -static void peer_signaling_process_request(const char *msg, size_t size) { - - cJSON *request, *response = NULL; - cJSON *method, *id; +static void peer_signaling_on_pub_event(const char *msg, size_t size) { - request = cJSON_Parse(msg); + cJSON *req, *res, *item, *result, *error; + int id = -1; + char *payload = NULL; + PeerConnectionState state; - if (!request) { + req = res = item = result = error = NULL; + state = peer_connection_get_state(g_ps.pc); + do { - LOGW("Parse json failed"); - return; - } + req = cJSON_Parse(msg); + if (!req) { + error = cJSON_CreateRaw(RPC_ERROR_PARSE_ERROR); + LOGW("Parse json failed"); + break; + } - do { - method = cJSON_GetObjectItem(request, "method"); - - id = cJSON_GetObjectItem(request, "id"); - - if (!id && !cJSON_IsNumber(id)) { - + item = cJSON_GetObjectItem(req, "id"); + if (!item && !cJSON_IsNumber(item)) { + error = cJSON_CreateRaw(RPC_ERROR_INVALID_REQUEST); LOGW("Cannot find id"); break; } - if (!method && cJSON_IsString(method)) { + id = item->valueint; + item = cJSON_GetObjectItem(req, "method"); + if (!item && cJSON_IsString(item)) { + error = cJSON_CreateRaw(RPC_ERROR_INVALID_REQUEST); LOGW("Cannot find method"); break; } - PeerConnectionState state = peer_connection_get_state(g_ps.pc); - response = peer_signaling_create_response(id->valueint); - - if (strcmp(method->valuestring, JRPC_PEER_OFFER) == 0) { - - if (state == PEER_CONNECTION_CLOSED) { - - g_ps.id = id->valueint; - peer_connection_create_offer(g_ps.pc); - cJSON_Delete(response); - response = NULL; - - } else { - - cJSON_AddStringToObject(response, "result", "busy"); + if (strcmp(item->valuestring, RPC_METHOD_OFFER) == 0) { + switch (state) { + case PEER_CONNECTION_NEW: + case PEER_CONNECTION_DISCONNECTED: + case PEER_CONNECTION_FAILED: + case PEER_CONNECTION_CLOSED: { + g_ps.id = id; + peer_connection_create_offer(g_ps.pc); + } break; + default: { + error = cJSON_CreateRaw(RPC_ERROR_INTERNAL_ERROR); + } break; } + } else if (strcmp(item->valuestring, RPC_METHOD_ANSWER) == 0) { - } else if (strcmp(method->valuestring, JRPC_PEER_ANSWER) == 0) { + item = cJSON_GetObjectItem(req, "params"); + if (!item && !cJSON_IsString(item)) { + error = cJSON_CreateRaw(RPC_ERROR_INVALID_PARAMS); + LOGW("Cannot find params"); + break; + } if (state == PEER_CONNECTION_NEW) { - - cJSON *params = cJSON_GetObjectItem(request, "params"); - - if (!params && !cJSON_IsString(params)) { - - LOGW("Cannot find params"); - break; - } - - peer_connection_set_remote_description(g_ps.pc, params->valuestring); - cJSON_AddStringToObject(response, "result", ""); + peer_connection_set_remote_description(g_ps.pc, item->valuestring); + result = cJSON_CreateString(""); } - } else if (strcmp(method->valuestring, JRPC_PEER_STATE) == 0) { + } else if (strcmp(item->valuestring, RPC_METHOD_STATE) == 0) { - cJSON_AddStringToObject(response, "result", peer_connection_state_to_string(state)); + result = cJSON_CreateString(peer_connection_state_to_string(state)); - } else if (strcmp(method->valuestring, JRPC_PEER_CLOSE) == 0) { + } else if (strcmp(item->valuestring, RPC_METHOD_CLOSE) == 0) { peer_connection_close(g_ps.pc); - cJSON_AddStringToObject(response, "result", ""); + result = cJSON_CreateString(""); } else { - + error = cJSON_CreateRaw(RPC_ERROR_METHOD_NOT_FOUND); LOGW("Unsupport method"); } } while (0); - if (response) { + if (result || error) { - peer_signaling_process_response(response); + res = cJSON_CreateObject(); + cJSON_AddStringToObject(res, "jsonrpc", RPC_VERSION); + cJSON_AddNumberToObject(res, "id", id); + + if (result) { + cJSON_AddItemToObject(res, "result", result); + } else if (error) { + cJSON_AddItemToObject(res, "error", error); + } + + payload = cJSON_PrintUnformatted(res); + + if (payload) { + peer_signaling_mqtt_publish(&g_ps.mqtt_ctx, payload); + free(payload); + } + cJSON_Delete(res); } - cJSON_Delete(request); + if (req) { + cJSON_Delete(req); + } } HTTPResponse_t peer_signaling_http_request(const TransportInterface_t *transport_interface, const char *method, size_t method_len, const char *host, size_t host_len, const char *path, size_t path_len, + const char *auth, size_t auth_len, const char *body, size_t body_len) { HTTPStatus_t status = HTTPSuccess; @@ -213,6 +225,11 @@ HTTPResponse_t peer_signaling_http_request(const TransportInterface_t *transport HTTPClient_AddHeader(&request_headers, "Content-Type", strlen("Content-Type"), "application/sdp", strlen("application/sdp")); + if (auth_len > 0) { + HTTPClient_AddHeader(&request_headers, + "Authorization", strlen("Authorization"), auth, auth_len); + } + response.pBuffer = g_ps.http_buf; response.bufferLen = sizeof(g_ps.http_buf); @@ -227,16 +244,23 @@ HTTPResponse_t peer_signaling_http_request(const TransportInterface_t *transport return response; } -static int peer_signaling_http_post(const char *hostname, const char *path, int port, const char *body) { - int32_t ret = EXIT_SUCCESS; +static int peer_signaling_http_post(const char *hostname, const char *path, int port, + const char *auth, const char *body) { + int ret = 0; TransportInterface_t trans_if = {0}; NetworkContext_t net_ctx; + HTTPResponse_t res; trans_if.recv = ssl_transport_recv; trans_if.send = ssl_transport_send; trans_if.pNetworkContext = &net_ctx; + if (port <= 0) { + LOGE("Invalid port number: %d", port); + return -1; + } + ret = ssl_transport_connect(&net_ctx, hostname, port, NULL); if (ret < 0) { @@ -244,22 +268,22 @@ static int peer_signaling_http_post(const char *hostname, const char *path, int return ret; } - HTTPResponse_t response = peer_signaling_http_request(&trans_if, "POST", 4, hostname, strlen(hostname), path, strlen(path), body, strlen(body)); + res = peer_signaling_http_request(&trans_if, "POST", 4, hostname, strlen(hostname), path, + strlen(path), auth, strlen(auth), body, strlen(body)); - LOGI("Received HTTP response from %s%s...\n" + LOGI("Received HTTP response from %s%s\n" "Response Headers: %s\nResponse Status: %u\nResponse Body: %s\n", - hostname, path, response.pHeaders, response.statusCode, response.pBody); + hostname, path, res.pHeaders, res.statusCode, res.pBody); ssl_transport_disconnect(&net_ctx); - if (response.statusCode == 201) { - - peer_connection_set_remote_description(g_ps.pc, (const char*)response.pBody); + if (res.statusCode == 201) { + peer_connection_set_remote_description(g_ps.pc, (const char*)res.pBody); } return 0; } -static void peer_signaling_mqtt_cb(MQTTContext_t *mqtt_ctx, +static void peer_signaling_mqtt_event_cb(MQTTContext_t *mqtt_ctx, MQTTPacketInfo_t *packet_info, MQTTDeserializedInfo_t *deserialized_info) { switch (packet_info->type) { @@ -269,7 +293,7 @@ static void peer_signaling_mqtt_cb(MQTTContext_t *mqtt_ctx, break; case MQTT_PACKET_TYPE_PUBLISH: LOGI("MQTT_PACKET_TYPE_PUBLISH"); - peer_signaling_process_request(deserialized_info->pPublishInfo->pPayload, + peer_signaling_on_pub_event(deserialized_info->pPublishInfo->pPayload, deserialized_info->pPublishInfo->payloadLength); break; case MQTT_PACKET_TYPE_SUBACK: @@ -287,6 +311,7 @@ static int peer_signaling_mqtt_connect(const char *hostname, int port) { bool session_present; if (ssl_transport_connect(&g_ps.net_ctx, hostname, port, NULL) < 0) { + LOGE("ssl transport connect failed"); return -1; } @@ -296,17 +321,25 @@ static int peer_signaling_mqtt_connect(const char *hostname, int port) { g_ps.mqtt_fixed_buf.pBuffer = g_ps.mqtt_buf; g_ps.mqtt_fixed_buf.size = sizeof(g_ps.mqtt_buf); status = MQTT_Init(&g_ps.mqtt_ctx, &g_ps.transport, - utils_get_timestamp, peer_signaling_mqtt_cb, &g_ps.mqtt_fixed_buf); + ports_get_epoch_time, peer_signaling_mqtt_event_cb, &g_ps.mqtt_fixed_buf); memset(&conn_info, 0, sizeof(conn_info)); conn_info.cleanSession = false; - conn_info.pUserName = NULL; - conn_info.userNameLength = 0U; - conn_info.pPassword = NULL; - conn_info.passwordLength = 0U; - conn_info.pClientIdentifier = "peer"; - conn_info.clientIdentifierLength = 4; + if (strlen(g_ps.username) > 0) { + conn_info.pUserName = g_ps.username; + conn_info.userNameLength = strlen(g_ps.username); + } + + if (strlen(g_ps.password) > 0) { + conn_info.pPassword = g_ps.password; + conn_info.passwordLength = strlen(g_ps.password); + } + + if (strlen(g_ps.client_id) > 0) { + conn_info.pClientIdentifier = g_ps.client_id; + conn_info.clientIdentifierLength = strlen(g_ps.client_id); + } conn_info.keepAliveSeconds = KEEP_ALIVE_TIMEOUT_SECONDS; @@ -356,58 +389,148 @@ static int peer_signaling_mqtt_subscribe(int subscribed) { } static void peer_signaling_onicecandidate(char *description, void *userdata) { -#if CONFIG_HTTP - peer_signaling_http_post(WHIP_HOST, WHIP_PATH, WHIP_PORT, description); -#endif - -#if CONFIG_MQTT - cJSON *json = peer_signaling_create_response(g_ps.id); - cJSON_AddStringToObject(json, "result", description); - peer_signaling_process_response(json); - g_ps.id = 0; -#endif + + cJSON *res; + char *payload; + char cred_plaintext[2*CRED_LEN + 1]; + char cred_base64[2*CRED_LEN + 10]; + + if (g_ps.id > 0) { + res = cJSON_CreateObject(); + cJSON_AddStringToObject(res, "jsonrpc", RPC_VERSION); + cJSON_AddNumberToObject(res, "id", g_ps.id); + cJSON_AddStringToObject(res, "result", description); + payload = cJSON_PrintUnformatted(res); + if (payload) { + peer_signaling_mqtt_publish(&g_ps.mqtt_ctx, payload); + free(payload); + } + cJSON_Delete(res); + g_ps.id = 0; + } else { + + // enable authentication + if (strlen(g_ps.username) > 0 && strlen(g_ps.password) > 0) { + snprintf(cred_plaintext, sizeof(cred_plaintext), "%s:%s", g_ps.username, g_ps.password); + snprintf(cred_base64, sizeof(cred_base64), "Basic "); + base64_encode((unsigned char*)cred_plaintext, strlen(cred_plaintext), + cred_base64 + strlen(cred_base64), sizeof(cred_base64) - strlen(cred_base64)); + LOGD("Basic Auth: %s", cred_base64); + peer_signaling_http_post(g_ps.http_host, g_ps.http_path, g_ps.http_port, cred_base64, description); + } else { + peer_signaling_http_post(g_ps.http_host, g_ps.http_path, g_ps.http_port, NULL, description); + } + } } -int peer_signaling_join_channel(const char *client_id, PeerConnection *pc) { +int peer_signaling_whip_connect() { + + if (g_ps.pc == NULL) { + LOGW("PeerConnection is NULL"); + return -1; + } else if (g_ps.http_port <= 0) { + LOGW("Invalid HTTP port number: %d", g_ps.http_port); + return -1; + } - g_ps.pc = pc; - peer_connection_onicecandidate(pc, peer_signaling_onicecandidate); + peer_connection_create_offer(g_ps.pc); + return 0; +} -#if CONFIG_HTTP - peer_connection_create_offer(pc); -#endif +void peer_signaling_whip_disconnect() { + // TODO: implement +} -#if CONFIG_MQTT - snprintf(g_ps.subtopic, sizeof(g_ps.subtopic), "webrtc/%s/jsonrpc", client_id); - snprintf(g_ps.pubtopic, sizeof(g_ps.pubtopic), "webrtc/%s/jsonrpc-reply", client_id); - peer_signaling_mqtt_connect(MQTT_HOST, MQTT_PORT); - peer_signaling_mqtt_subscribe(1); -#endif +int peer_signaling_join_channel() { + if (g_ps.pc == NULL) { + LOGW("PeerConnection is NULL"); + return -1; + } else if (g_ps.mqtt_port <= 0) { + LOGW("Invalid MQTT port number: %d", g_ps.mqtt_port); + return -1; + } + + if (peer_signaling_mqtt_connect(g_ps.mqtt_host, g_ps.mqtt_port) < 0) { + LOGW("Connect MQTT server failed"); + return -1; + } + + peer_signaling_mqtt_subscribe(1); return 0; } int peer_signaling_loop() { -#if CONFIG_MQTT - MQTT_ProcessLoop(&g_ps.mqtt_ctx); -#endif + + if (g_ps.mqtt_port > 0) { + MQTT_ProcessLoop(&g_ps.mqtt_ctx); + } return 0; } void peer_signaling_leave_channel() { - // TODO: HTTP DELETE with Location? -#if CONFIG_MQTT + MQTTStatus_t status = MQTTSuccess; - if (peer_signaling_mqtt_subscribe(0) == 0) { + if (g_ps.mqtt_port > 0 && peer_signaling_mqtt_subscribe(0) == 0) { status = MQTT_Disconnect(&g_ps.mqtt_ctx); - } + if(status != MQTTSuccess) { - if(status != MQTTSuccess) { - - LOGE("Failed to disconnect with broker: %s", MQTT_Status_strerror(status)); + LOGE("Failed to disconnect with broker: %s", MQTT_Status_strerror(status)); + } } -#endif } +void peer_signaling_set_config(ServiceConfiguration *service_config) { + + char *pos; + + memset(&g_ps, 0, sizeof(g_ps)); + + do { + + if (service_config->http_url == NULL || strlen(service_config->http_url) == 0) { + break; + } + + if ((pos = strstr(service_config->http_url, "/")) != NULL) { + strncpy(g_ps.http_host, service_config->http_url, pos - service_config->http_url); + strncpy(g_ps.http_path, pos, HOST_LEN); + } else { + strncpy(g_ps.http_host, service_config->http_url, HOST_LEN); + } + + g_ps.http_port = service_config->http_port; + LOGI("HTTP Host: %s, Port: %d, Path: %s", g_ps.http_host, g_ps.http_port, g_ps.http_path); + } while (0); + + + do { + + if (service_config->mqtt_url == NULL || strlen(service_config->mqtt_url) == 0) { + break; + } + + strncpy(g_ps.mqtt_host, service_config->mqtt_url, HOST_LEN); + g_ps.mqtt_port = service_config->mqtt_port; + LOGD("MQTT Host: %s, Port: %d", g_ps.mqtt_host, g_ps.mqtt_port); + } while (0); + + if (service_config->client_id != NULL && strlen(service_config->client_id) > 0) { + strncpy(g_ps.client_id, service_config->client_id, CRED_LEN); + snprintf(g_ps.subtopic, sizeof(g_ps.subtopic), "webrtc/%s/jsonrpc", service_config->client_id); + snprintf(g_ps.pubtopic, sizeof(g_ps.pubtopic), "webrtc/%s/jsonrpc-reply", service_config->client_id); + } + + if (service_config->username != NULL && strlen(service_config->username) > 0) { + strncpy(g_ps.username, service_config->username, CRED_LEN); + } + + if (service_config->password != NULL && strlen(service_config->password) > 0) { + strncpy(g_ps.password, service_config->password, CRED_LEN); + } + + g_ps.pc = service_config->pc; + peer_connection_onicecandidate(g_ps.pc, peer_signaling_onicecandidate); +} diff --git a/src/peer_signaling.h b/src/peer_signaling.h index a3ae829..7ecff41 100644 --- a/src/peer_signaling.h +++ b/src/peer_signaling.h @@ -7,7 +7,35 @@ extern "C" { #endif -int peer_signaling_join_channel(const char *client_id, PeerConnection *pc); +typedef struct ServiceConfiguration { + const char *mqtt_url; + int mqtt_port; + const char *client_id; + const char *http_url; + int http_port; + const char *username; + const char *password; + PeerConnection *pc; +} ServiceConfiguration; + +#define SERVICE_CONFIG_DEFAULT() { \ + .mqtt_url = "broker.emqx.io", \ + .mqtt_port = 8883, \ + .client_id = "peer", \ + .http_url = "", \ + .http_port = 443, \ + .username = "", \ + .password = "", \ + .pc = NULL \ +} + +void peer_signaling_set_config(ServiceConfiguration *config); + +int peer_signaling_whip_connect(); + +void peer_signaling_whip_disconnect(); + +int peer_signaling_join_channel(); void peer_signaling_leave_channel(); diff --git a/src/ports.c b/src/ports.c index e10519d..be7229f 100644 --- a/src/ports.c +++ b/src/ports.c @@ -4,9 +4,9 @@ #include #include #include +#include #ifdef ESP32 -#include #include #else #include @@ -29,17 +29,17 @@ int ports_get_host_addr(Address *addr) { switch (addr->family) { case AF_INET6: if (esp_netif_get_ip6_global(netif, &ip6_info) == ESP_OK) { - memcpy(addr->ipv6, &ip6_info.addr, 16); + memcpy(&addr->sin6.sin6_addr, &ip6_info.addr, 16); ret = 1; } else if (esp_netif_get_ip6_linklocal(netif, &ip6_info) == ESP_OK) { - memcpy(addr->ipv6, &ip6_info.addr, 16); + memcpy(&addr->sin6.sin6_addr, &ip6_info.addr, 16); ret = 1; } break; case AF_INET: default: if (esp_netif_get_ip_info(netif, &ip_info) == ESP_OK) { - memcpy(addr->ipv4, &ip_info.ip.addr, 4); + memcpy(&addr->sin.sin_addr, &ip_info.ip.addr, 4); ret = 1; } break; @@ -58,11 +58,11 @@ int ports_get_host_addr(Address *addr) { if (ifa->ifa_addr->sa_family == addr->family) { switch (ifa->ifa_addr->sa_family) { case AF_INET: - memcpy(addr->ipv4, &((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr, 4); + memcpy(&addr->sin, ifa->ifa_addr, sizeof(struct sockaddr_in)); ret = 1; break; case AF_INET6: - memcpy(addr->ipv6, &((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr.s6_addr, 16); + memcpy(&addr->sin6, ifa->ifa_addr, sizeof(struct sockaddr_in6)); ret = 1; break; default: @@ -129,70 +129,46 @@ LOGI("get_host_address inside while loop"); } int ports_resolve_addr(const char *host, Address *addr) { + + char addr_string[ADDRSTRLEN]; int ret = -1; struct addrinfo hints, *res, *p; - int family; int status; memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; if ((status = getaddrinfo(host, NULL, &hints, &res)) != 0) { - //LOGE("getaddrinfo error: %s\n", gai_strerror(status)); LOGE("getaddrinfo error: %d\n", status); return ret; } - if (addr->family == AF_INET6) { - family = AF_INET6; - } else { - family = AF_INET; - } - - for (p = res; p != NULL; p = p->ai_next) { - if (p->ai_family == family) { - switch (p->ai_family) { + // TODO: Support for IPv6 + addr_set_family(addr, AF_INET); + for (p = res; p != NULL; p = p->ai_next) { + if (p->ai_family == addr->family) { + switch (addr->family) { case AF_INET6: - memcpy(addr->ipv6, &((struct sockaddr_in6 *)p->ai_addr)->sin6_addr.s6_addr, 16); + memcpy(&addr->sin6, p->ai_addr, sizeof(struct sockaddr_in6)); break; case AF_INET: - LOGI("AF_INET"); - memcpy(addr->ipv4, &((struct sockaddr_in *)p->ai_addr)->sin_addr.s_addr, 4); default: + memcpy(&addr->sin, p->ai_addr, sizeof(struct sockaddr_in)); break; } ret = 0; } } + addr_to_string(addr, addr_string, sizeof(addr_string)); + LOGI("Resolved %s -> %s", host, addr_string); freeaddrinfo(res); return ret; } -int ports_resolve_mdns_host(const char *host, Address *addr) { -#ifdef ESP32 - int ret = -1; - struct esp_ip4_addr esp_addr; - char host_name[64] = {0}; - char *pos = strstr(host, ".local"); - snprintf(host_name, pos - host + 1, "%s", host); - esp_addr.addr = 0; - - esp_err_t err = mdns_query_a(host_name, 2000, &esp_addr); - if (err) { - if (err == ESP_ERR_NOT_FOUND) { - LOGW("%s: Host was not found!", esp_err_to_name(err)); - return ret; - } - LOGE("Query Failed: %s", esp_err_to_name(err)); - return ret; - } +uint32_t ports_get_epoch_time() { - memcpy(addr->ipv4, &esp_addr.addr, 4); - return ret; -#else - return ports_resolve_addr(host, addr); -#endif + struct timeval tv; + gettimeofday(&tv, NULL); + return (uint32_t) tv.tv_sec * 1000 + tv.tv_usec / 1000; } - - diff --git a/src/ports.h b/src/ports.h index 7a57f59..d5b4eee 100644 --- a/src/ports.h +++ b/src/ports.h @@ -3,7 +3,6 @@ #include #include "address.h" -#include "udp.h" int ports_resolve_addr(const char *host, Address *addr); @@ -11,5 +10,6 @@ int ports_resolve_mdns_host(const char *host, Address *addr); int ports_get_host_addr(Address *addr); -#endif // PORTS_H_ +uint32_t ports_get_epoch_time(); +#endif // PORTS_H_ diff --git a/src/socket.c b/src/socket.c new file mode 100644 index 0000000..5ce568a --- /dev/null +++ b/src/socket.c @@ -0,0 +1,332 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "utils.h" +#include "socket.h" + +int udp_socket_add_multicast_group(UdpSocket *udp_socket, Address *mcast_addr) { + + int ret = 0; + struct ip_mreq imreq = {0}; + struct in_addr iaddr = {0}; + + imreq.imr_interface.s_addr = INADDR_ANY; + // IPV4 only + imreq.imr_multiaddr.s_addr = mcast_addr->sin.sin_addr.s_addr; + + if ((ret = setsockopt(udp_socket->fd, IPPROTO_IP, IP_MULTICAST_IF, &iaddr, sizeof(struct in_addr))) < 0) { + LOGE("Failed to set IP_MULTICAST_IF: %d", ret); + return ret; + } + + if ((ret = setsockopt(udp_socket->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &imreq, sizeof(struct ip_mreq))) < 0) { + LOGE("Failed to set IP_ADD_MEMBERSHIP: %d", ret); + return ret; + } + + return 0; +} + +int udp_socket_open(UdpSocket *udp_socket, int family, int port) { + + int ret; + int reuse = 1; + struct sockaddr *sa; + socklen_t sock_len; + + udp_socket->bind_addr.family = family; + switch (family) { + case AF_INET6: + udp_socket->fd = socket(AF_INET6, SOCK_DGRAM, 0); + udp_socket->bind_addr.sin6.sin6_family = AF_INET6; + udp_socket->bind_addr.sin6.sin6_port = htons(port); + udp_socket->bind_addr.sin6.sin6_addr = in6addr_any; + udp_socket->bind_addr.port = ntohs(udp_socket->bind_addr.sin6.sin6_port); + sa = (struct sockaddr *)&udp_socket->bind_addr.sin6; + sock_len = sizeof(struct sockaddr_in6); + break; + case AF_INET: + default: + udp_socket->fd = socket(AF_INET, SOCK_DGRAM, 0); + udp_socket->bind_addr.sin.sin_family = AF_INET; + udp_socket->bind_addr.sin.sin_port = htons(port); + udp_socket->bind_addr.sin.sin_addr.s_addr = htonl(INADDR_ANY); + sa = (struct sockaddr *)&udp_socket->bind_addr.sin; + sock_len = sizeof(struct sockaddr_in); + break; + } + + if (udp_socket->fd < 0) { + LOGE("Failed to create socket"); + return -1; + } + + do { + if ((ret = setsockopt(udp_socket->fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse))) < 0) { + LOGE("reuse failed"); + break; + } + + if ((ret = bind(udp_socket->fd, sa, sock_len)) < 0) { + LOGE("Failed to bind socket: %d", ret); + break; + } + + if (getsockname(udp_socket->fd, sa, &sock_len) < 0) { + LOGE("Get socket info failed"); + break; + } + } while (0); + + if (ret < 0) { + udp_socket_close(udp_socket); + return -1; + } + + switch (udp_socket->bind_addr.family) { + case AF_INET6: + udp_socket->bind_addr.port = ntohs(udp_socket->bind_addr.sin6.sin6_port); + break; + case AF_INET: + default: + udp_socket->bind_addr.port = ntohs(udp_socket->bind_addr.sin.sin_port); + break; + } + + return 0; +} + +void udp_socket_close(UdpSocket *udp_socket) { + + if (udp_socket->fd > 0) { + close(udp_socket->fd); + } +} + +int udp_socket_sendto(UdpSocket *udp_socket, Address *addr, const uint8_t *buf, int len) { + + struct sockaddr *sa; + socklen_t sock_len; + int ret = -1; + + if (udp_socket->fd < 0) { + LOGE("sendto before socket init"); + return -1; + } + + switch (addr->family) { + case AF_INET6: + addr->sin6.sin6_family = AF_INET6; + sa = (struct sockaddr *)&addr->sin6; + sock_len = sizeof(struct sockaddr_in6); + break; + case AF_INET: + default: + addr->sin.sin_family = AF_INET; + sa = (struct sockaddr *)&addr->sin; + sock_len = sizeof(struct sockaddr_in); + break; + } + + if ((ret = sendto(udp_socket->fd, buf, len, 0, sa, sock_len)) < 0) { + LOGE("Failed to sendto: %s", strerror(errno)); + return -1; + } + + return ret; +} + +int udp_socket_recvfrom(UdpSocket *udp_socket, Address *addr, uint8_t *buf, int len) { + + struct sockaddr_in6 sin6; + struct sockaddr_in sin; + struct sockaddr *sa; + socklen_t sock_len; + int ret; + + if (udp_socket->fd < 0) { + LOGE("recvfrom before socket init"); + return -1; + } + + switch (udp_socket->bind_addr.family) { + case AF_INET6: + sin6.sin6_family = AF_INET6; + sa = (struct sockaddr *)&sin6; + sock_len = sizeof(struct sockaddr_in6); + break; + case AF_INET: + default: + sin.sin_family = AF_INET; + sa = (struct sockaddr *)&sin; + sock_len = sizeof(struct sockaddr_in); + break; + } + + if ((ret = recvfrom(udp_socket->fd, buf, len, 0, sa, &sock_len)) < 0) { + LOGE("Failed to recvfrom: %s", strerror(errno)); + return -1; + } + + if (addr) { + switch (udp_socket->bind_addr.family) { + case AF_INET6: + addr->family = AF_INET6; + addr->port = htons(addr->sin6.sin6_port); + memcpy(&addr->sin6, &sin6, sizeof(struct sockaddr_in6)); + break; + case AF_INET: + default: + addr->family = AF_INET; + addr->port = htons(addr->sin.sin_port); + memcpy(&addr->sin, &sin, sizeof(struct sockaddr_in)); + break; + } + } + + return ret; +} + +int tcp_socket_open(TcpSocket *tcp_socket, int family) { + + tcp_socket->bind_addr.family = family; + switch (family) { + case AF_INET6: + tcp_socket->fd = socket(AF_INET6, SOCK_STREAM, 0); + break; + case AF_INET: + default: + tcp_socket->fd = socket(AF_INET, SOCK_STREAM, 0); + break; + } + + if (tcp_socket->fd < 0) { + LOGE("Failed to create socket"); + return -1; + } + return 0; +} + +int tcp_socket_connect(TcpSocket *tcp_socket, Address *addr) { + + char addr_string[ADDRSTRLEN]; + int ret; + struct sockaddr *sa; + socklen_t sock_len; + + if (tcp_socket->fd < 0) { + LOGE("Connect before socket init"); + return -1; + } + + switch (addr->family) { + case AF_INET6: + addr->sin6.sin6_family = AF_INET6; + sa = (struct sockaddr *)&addr->sin6; + sock_len = sizeof(struct sockaddr_in6); + break; + case AF_INET: + default: + addr->sin.sin_family = AF_INET; + sa = (struct sockaddr *)&addr->sin; + sock_len = sizeof(struct sockaddr_in); + break; + } + + addr_to_string(addr, addr_string, sizeof(addr_string)); + LOGI("Connecting to server: %s:%d", addr_string, addr->port); + if ((ret = connect(tcp_socket->fd, sa, sock_len)) < 0) { + LOGE("Failed to connect to server"); + return -1; + } + + LOGI("Server is connected"); + return 0; +} + +void tcp_socket_close(TcpSocket *tcp_socket) { + + if (tcp_socket->fd > 0) { + close(tcp_socket->fd); + } +} + +int tcp_socket_send(TcpSocket *tcp_socket, const uint8_t *buf, int len) { + + fd_set write_set; + struct timeval tv; + int ret = -1; + + if (tcp_socket->fd < 0) { + + LOGE("sendto before socket init"); + return -1; + } + + FD_ZERO(&write_set); + FD_SET(tcp_socket->fd, &write_set); + + tv.tv_sec = 0; + tv.tv_usec = 500000; + + if ((ret = select(tcp_socket->fd + 1, NULL, &write_set, NULL, &tv)) < 0) { + + LOGE("Failed to select: %s", strerror(errno)); + return -1; + } + + if (FD_ISSET(tcp_socket->fd, &write_set)) { + + ret = send(tcp_socket->fd, buf, len, 0); + if (ret < 0) { + LOGE("Failed to send: %s", strerror(errno)); + return -1; + } + } + + return ret; +} + +int tcp_socket_recv(TcpSocket *tcp_socket, uint8_t *buf, int len) { + + fd_set read_set; + struct timeval tv; + int ret; + + if (tcp_socket->fd < 0) { + + LOGE("recvfrom before socket init"); + return -1; + } + + FD_ZERO(&read_set); + FD_SET(tcp_socket->fd, &read_set); + tv.tv_sec = 0; + tv.tv_usec = 500000; + + if ((ret = select(tcp_socket->fd + 1, &read_set, NULL, NULL, &tv)) < 0) { + + LOGE("Failed to select: %s", strerror(errno)); + return -1; + } + + if (FD_ISSET(tcp_socket->fd, &read_set)) { + + ret = recv(tcp_socket->fd, buf, len, 0); + if (ret < 0) { + LOGE("Failed to recv: %s", strerror(errno)); + return -1; + } + } + + return ret; +} diff --git a/src/socket.h b/src/socket.h new file mode 100644 index 0000000..e87f5b3 --- /dev/null +++ b/src/socket.h @@ -0,0 +1,38 @@ +#ifndef SOCKET_H_ +#define SOCKET_H_ + +#include "address.h" + +typedef struct UdpSocket { + int fd; + Address bind_addr; +} UdpSocket; + +typedef struct TcpSocket { + int fd; + Address bind_addr; +} TcpSocket; + +int udp_socket_open(UdpSocket *udp_socket, int family, int port); + +int udp_socket_bind(UdpSocket *udp_socket, int port); + +void udp_socket_close(UdpSocket *udp_socket); + +int udp_socket_sendto(UdpSocket *udp_socket, Address *bind_addr, const uint8_t *buf, int len); + +int udp_socket_recvfrom(UdpSocket *udp_sock, Address *bind_addr, uint8_t *buf, int len); + +int udp_socket_add_multicast_group(UdpSocket *udp_socket, Address *mcast_addr); + +int tcp_socket_open(TcpSocket *tcp_socket, int family); + +int tcp_socket_connect(TcpSocket *tcp_socket, Address *addr); + +void tcp_socket_close(TcpSocket *tcp_socket); + +int tcp_socket_send(TcpSocket *tcp_socket, const uint8_t *buf, int len); + +int tcp_socket_recv(TcpSocket *tcp_socket, uint8_t *buf, int len); + +#endif // SOCKET_H_ diff --git a/src/ssl_transport.c b/src/ssl_transport.c index e874dd1..6ae67a8 100644 --- a/src/ssl_transport.c +++ b/src/ssl_transport.c @@ -37,6 +37,7 @@ int ssl_transport_connect(NetworkContext_t *net_ctx, if ((ret = mbedtls_ctr_drbg_seed(&net_ctx->ctr_drbg, mbedtls_entropy_func, &net_ctx->entropy, (const unsigned char *) pers, strlen(pers))) != 0) { + return -1; } if ((ret = mbedtls_ssl_config_defaults(&net_ctx->conf, @@ -45,11 +46,10 @@ int ssl_transport_connect(NetworkContext_t *net_ctx, MBEDTLS_SSL_PRESET_DEFAULT)) != 0) { LOGE("ssl config error: -0x%x", (unsigned int) -ret); + return -1; } - mbedtls_ssl_conf_authmode(&net_ctx->conf, MBEDTLS_SSL_VERIFY_OPTIONAL); - /* XXX: not sure if this is needed ret = mbedtls_x509_crt_parse(&net_ctx->cacert, (const unsigned char *) cacert, strlen(cacert) + 1); @@ -63,18 +63,21 @@ int ssl_transport_connect(NetworkContext_t *net_ctx, if ((ret = mbedtls_ssl_setup(&net_ctx->ssl, &net_ctx->conf)) != 0) { LOGE("ssl setup error: -0x%x", (unsigned int) -ret); + return -1; } if ((ret = mbedtls_ssl_set_hostname(&net_ctx->ssl, host)) != 0) { LOGE("ssl set hostname error: -0x%x", (unsigned int) -ret); + return -1; } - tcp_socket_open(&net_ctx->tcp_socket); - tcp_blocking_timeout(&net_ctx->tcp_socket, 1000); + memset(&resolved_addr, 0, sizeof(resolved_addr)); + tcp_socket_open(&net_ctx->tcp_socket, AF_INET); ports_resolve_addr(host, &resolved_addr); - - resolved_addr.port = port; - tcp_socket_connect(&net_ctx->tcp_socket, &resolved_addr); + addr_set_port(&resolved_addr, port); + if ((ret = tcp_socket_connect(&net_ctx->tcp_socket, &resolved_addr) < 0)) { + return -1; + } mbedtls_ssl_set_bio(&net_ctx->ssl, &net_ctx->tcp_socket, ssl_transport_mbedlts_send, ssl_transport_mbedtls_recv, NULL); diff --git a/src/ssl_transport.h b/src/ssl_transport.h index 1180517..fd1cbe5 100644 --- a/src/ssl_transport.h +++ b/src/ssl_transport.h @@ -6,7 +6,7 @@ #include #include -#include "tcp.h" +#include "socket.h" #include "transport_interface.h" struct NetworkContext { diff --git a/src/stun.c b/src/stun.c index 80e6794..aaa9421 100644 --- a/src/stun.c +++ b/src/stun.c @@ -63,18 +63,14 @@ void stun_msg_create(StunMessage *msg, uint16_t type) { void stun_set_mapped_address(char *value, uint8_t *mask, Address *addr) { - int i; - uint8_t *family = (uint8_t *)(value + 1); uint16_t *port = (uint16_t *)(value + 2); uint8_t *ipv4 = (uint8_t *)(value + 4); *family = 0x01; *port = htons(addr->port); - - for (i = 0; i < 4; i++) { - ipv4[i] = addr->ipv4[i]; - } + + memcpy(ipv4, &addr->sin.sin_addr, 4); //LOGD("XOR Mapped Address Family: 0x%02x", *family); //LOGD("XOR Mapped Address Port: %d", *port); @@ -84,26 +80,26 @@ void stun_set_mapped_address(char *value, uint8_t *mask, Address *addr) { void stun_get_mapped_address(char *value, uint8_t *mask, Address *addr) { int i; - uint32_t *addr32 = (uint32_t *)addr->ipv4; - uint16_t *addr16 = (uint16_t *)addr->ipv6; - addr->family = value[1]; - addr->port = ntohs(*(uint16_t *)(value + 2) ^ *(uint16_t*)mask); - LOGD("family: %d, %d", AF_INET, AF_INET6); - LOGD("XOR Mapped Address Family: 0x%02x", addr->family); - LOGD("XOR Mapped Address Port: %d", addr->port); - if (addr->family == 0x02) { - addr->family = AF_INET6; + char addr_string[ADDRSTRLEN]; + uint32_t *addr32 = (uint32_t *)&addr->sin.sin_addr; + uint16_t *addr16 = (uint16_t *)&addr->sin6.sin6_addr; + uint8_t family = value[1]; + if (family == 0x02) { + addr_set_family(addr, AF_INET6); for (i = 0; i < 8; i++) { addr16[i] = (*(uint16_t *)(value + 4 + 2*i) ^ *(uint16_t*)(mask + 2*i)); } - LOGD("XOR Mapped Address Address: %x:%x:%x:%x:%x:%x:%x:%x", addr->ipv6[0], addr->ipv6[1], addr->ipv6[2], addr->ipv6[3], addr->ipv6[4], addr->ipv6[5], addr->ipv6[6], addr->ipv6[7]); - - } else if (addr->family == 0x01) { - addr->family = AF_INET; - *addr32 = (*(uint32_t *)(value + 4) ^ *(uint32_t*)mask); - LOGD("XOR Mapped Address Address: %d.%d.%d.%d", addr->ipv4[0], addr->ipv4[1], addr->ipv4[2], addr->ipv4[3]); + } else if (family == 0x01) { + addr_set_family(addr, AF_INET); + *addr32 = (*(uint32_t *)(value + 4) ^ *(uint32_t*)mask); } + addr_to_string(addr, addr_string, sizeof(addr_string)); + addr_set_port(addr, ntohs(*(uint16_t *)(value + 2) ^ *(uint16_t*)mask)); + + LOGD("XOR Mapped Address Family: 0x%02x", addr->family); + LOGD("XOR Mapped Address Port: %d", addr->port); + LOGD("XOR Mapped Address Address: %s", addr_string); } void stun_parse_msg_buf(StunMessage *msg) { diff --git a/src/tcp.c b/src/tcp.c deleted file mode 100644 index 825aa84..0000000 --- a/src/tcp.c +++ /dev/null @@ -1,168 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "utils.h" -#include "tcp.h" - -void tcp_blocking_timeout(TcpSocket *tcp_socket, long long int ms) { - - tcp_socket->timeout_sec = ms/1000; - tcp_socket->timeout_usec = ms%1000*1000; -} - -int tcp_socket_open(TcpSocket *tcp_socket) { - - tcp_socket->fd = socket(AF_INET, SOCK_STREAM, 0); - - if (tcp_socket->fd < 0) { - - LOGE("Failed to create socket"); - return -1; - } - - tcp_blocking_timeout(tcp_socket, 5); - return 0; -} - -int tcp_socket_connect(TcpSocket *tcp_socket, Address *addr) { - - if (tcp_socket->fd < 0) { - LOGE("Failed to create socket"); - return -1; - } - - struct sockaddr_in sin; - socklen_t sin_len = sizeof(sin); - sin.sin_family = AF_INET; - sin.sin_port = htons(addr->port); - memcpy(&sin.sin_addr.s_addr, addr->ipv4, 4); - LOGI("port: %d", addr->port); - LOGI("addr: %s", inet_ntoa(sin.sin_addr)); - if (connect(tcp_socket->fd, (struct sockaddr *)&sin, sin_len) < 0) { - - LOGE("Failed to connect to server"); - return -1; - } - LOGI("Connected to server"); - return 0; -} - -void tcp_socket_close(TcpSocket *tcp_socket) { - - if (tcp_socket->fd > 0) { - close(tcp_socket->fd); - } -} - -int tcp_get_local_address(TcpSocket *tcp_socket, Address *addr) { - - struct sockaddr_in sin; - - socklen_t len = sizeof(sin); - - if (tcp_socket->fd < 0) { - LOGE("Failed to create socket"); - return -1; - } - - if (getsockname(tcp_socket->fd, (struct sockaddr *)&sin, &len) < 0) { - LOGE("Failed to get local address"); - return -1; - } - - memcpy(addr->ipv4, &sin.sin_addr.s_addr, 4); - - addr->port = ntohs(sin.sin_port); - - addr->family = AF_INET; - - LOGD("local port: %d", addr->port); - LOGD("local address: %d.%d.%d.%d", addr->ipv4[0], addr->ipv4[1], addr->ipv4[2], addr->ipv4[3]); - - return 0; -} - -int tcp_socket_send(TcpSocket *tcp_socket, const uint8_t *buf, int len) { - - fd_set write_set; - struct timeval tv; - int ret = -1; - - if (tcp_socket->fd < 0) { - - LOGE("sendto before socket init"); - return -1; - } - - FD_ZERO(&write_set); - FD_SET(tcp_socket->fd, &write_set); - - tv.tv_sec = tcp_socket->timeout_sec; - tv.tv_usec = tcp_socket->timeout_usec; - - if ((ret = select(tcp_socket->fd + 1, NULL, &write_set, NULL, &tv)) < 0) { - - LOGE("Failed to select: %s", strerror(errno)); - return -1; - } - - if (FD_ISSET(tcp_socket->fd, &write_set)) { - - ret = send(tcp_socket->fd, buf, len, 0); - - if (ret < 0) { - - LOGE("Failed to send: %s", strerror(errno)); - return -1; - } - } - - return ret; -} - -int tcp_socket_recv(TcpSocket *tcp_socket, uint8_t *buf, int len) { - - fd_set read_set; - struct timeval tv; - int ret; - - if (tcp_socket->fd < 0) { - - LOGE("recvfrom before socket init"); - return -1; - } - - FD_ZERO(&read_set); - FD_SET(tcp_socket->fd, &read_set); - tv.tv_sec = tcp_socket->timeout_sec; - tv.tv_usec = tcp_socket->timeout_usec; - - if ((ret = select(tcp_socket->fd + 1, &read_set, NULL, NULL, &tv)) < 0) { - - LOGE("Failed to select: %s", strerror(errno)); - return -1; - } - - if (FD_ISSET(tcp_socket->fd, &read_set)) { - - ret = recv(tcp_socket->fd, buf, len, 0); - - if (ret < 0) { - - LOGE("Failed to recv: %s", strerror(errno)); - return -1; - } - } - - return ret; -} - diff --git a/src/tcp.h b/src/tcp.h deleted file mode 100644 index 3c80534..0000000 --- a/src/tcp.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef TCP_SOCKET_H_ -#define TCP_SOCKET_H_ - -#include "address.h" - -typedef struct TcpSocket TcpSocket; - -struct TcpSocket { - - int fd; - Address bind_addr; - long long int timeout_sec; - long int timeout_usec; -}; - -int tcp_socket_open(TcpSocket *tcp_socket); - -int tcp_socket_connect(TcpSocket *tcp_socket, Address *addr); - -void tcp_socket_close(TcpSocket *tcp_socket); - -int tcp_socket_send(TcpSocket *tcp_socket, const uint8_t *buf, int len); - -int tcp_socket_recv(TcpSocket *tcp_socket, uint8_t *buf, int len); - -void tcp_blocking_timeout(TcpSocket *tcp_socket, long long int ms); - -#endif // TCP_SOCKET_H_ - diff --git a/src/udp.c b/src/udp.c deleted file mode 100644 index 9801c2d..0000000 --- a/src/udp.c +++ /dev/null @@ -1,268 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -#include "utils.h" -#include "udp.h" - -void udp_blocking_timeout(UdpSocket *udp_socket, long long int ms) { - - udp_socket->timeout_sec = ms/1000; - udp_socket->timeout_usec = ms%1000*1000; -} - -int udp_socket_create(UdpSocket *udp_socket, int family) { - - struct sockaddr_in sin; - struct sockaddr_in6 sin6; - struct sockaddr *sa; - socklen_t sin_len; - - switch (family) { - case AF_INET6: - udp_socket->fd = socket(AF_INET6, SOCK_DGRAM, 0); - sin6.sin6_family = AF_INET6; - sin6.sin6_port = htons(0); - sin6.sin6_addr = in6addr_any; - sa = (struct sockaddr *)&sin6; - sin_len = sizeof(sin6); - break; - case AF_INET: - default: - udp_socket->fd = socket(AF_INET, SOCK_DGRAM, 0); - sin.sin_family = AF_INET; - sin.sin_port = htons(0); - sin.sin_addr.s_addr = htonl(INADDR_ANY); - sa = (struct sockaddr *)&sin; - sin_len = sizeof(sin); - break; - } - - if (udp_socket->fd < 0) { - - LOGE("Failed to create socket"); - return -1; - } - - if (bind(udp_socket->fd, sa, sin_len) < 0) { - - LOGE("Failed to bind socket"); - return -1; - } - - if (getsockname(udp_socket->fd, (struct sockaddr *)&sin, &sin_len) < 0) { - LOGE("Failed to get local address"); - return -1; - } - - LOGI("local port: %d", ntohs(sin.sin_port)); - udp_socket->bind_addr.family = sin.sin_family; - udp_socket->bind_addr.port = ntohs(sin.sin_port); - return 0; -} - -int udp_socket_open(UdpSocket *udp_socket, int family) { - - switch (family) { - case AF_INET6: - udp_socket->fd = socket(AF_INET6, SOCK_DGRAM, 0); - break; - case AF_INET: - default: - udp_socket->fd = socket(AF_INET, SOCK_DGRAM, 0); - break; - } - - if (udp_socket->fd < 0) { - - LOGE("Failed to create socket"); - return -1; - } - - //int flags = fcntl(udp_socket->fd, F_GETFL, 0); - //fcntl(udp_socket->fd, F_SETFL, flags | O_NONBLOCK); - udp_blocking_timeout(udp_socket, 5); - return 0; -} - -int udp_socket_bind(UdpSocket *udp_socket, Address *addr) { - - struct sockaddr_in sin; - struct sockaddr_in6 sin6; - struct sockaddr *sa; - socklen_t sin_len; - - if (udp_socket->fd < 0) { - LOGE("Failed to create socket"); - return -1; - } - - switch (addr->family) { - case AF_INET6: - sin6.sin6_family = AF_INET6; - sin6.sin6_port = htons(addr->port); - sin6.sin6_addr = in6addr_any; - sa = (struct sockaddr *)&sin6; - sin_len = sizeof(sin6); - break; - case AF_INET: - default: - sin.sin_family = AF_INET; - sin.sin_port = htons(addr->port); - sin.sin_addr.s_addr = htonl(INADDR_ANY); - sa = (struct sockaddr *)&sin; - sin_len = sizeof(sin); - break; - } - - if (bind(udp_socket->fd, sa, sin_len) < 0) { - - LOGE("Failed to bind socket"); - return -1; - } - - udp_socket->bind_addr.family = addr->family; - udp_socket->bind_addr.port = addr->port; - memcpy(udp_socket->bind_addr.ipv4, addr->ipv4, 4); - LOGD("bind_addr: %p", &udp_socket->bind_addr); - return 0; -} - -void udp_socket_close(UdpSocket *udp_socket) { - - if (udp_socket->fd > 0) { - close(udp_socket->fd); - } -} - -int udp_get_local_address(UdpSocket *udp_socket, Address *addr) { - - struct sockaddr_in sin; - - socklen_t len = sizeof(sin); - - if (udp_socket->fd < 0) { - LOGE("Failed to create socket"); - return -1; - } - - if (getsockname(udp_socket->fd, (struct sockaddr *)&sin, &len) < 0) { - LOGE("Failed to get local address"); - return -1; - } - - memcpy(addr->ipv4, &sin.sin_addr.s_addr, 4); - - addr->port = ntohs(sin.sin_port); - - addr->family = AF_INET; - - LOGD("local port: %d", addr->port); - LOGD("local address: %d.%d.%d.%d", addr->ipv4[0], addr->ipv4[1], addr->ipv4[2], addr->ipv4[3]); - - return 0; -} - -int udp_socket_sendto(UdpSocket *udp_socket, Address *addr, const uint8_t *buf, int len) { - - struct sockaddr_in sin; - struct sockaddr_in6 sin6; - struct sockaddr *sa; - socklen_t sin_len; - int ret = -1; - - if (udp_socket->fd < 0) { - - LOGE("sendto before socket init"); - return -1; - } - - switch (addr->family) { - case AF_INET6: - sin6.sin6_family = AF_INET6; - sin6.sin6_port = htons(addr->port); - memcpy(&sin6.sin6_addr, addr->ipv6, 16); - sa = (struct sockaddr *)&sin6; - sin_len = sizeof(sin6); - break; - case AF_INET: - default: - sin.sin_family = AF_INET; - sin.sin_port = htons(addr->port); - memcpy(&sin.sin_addr.s_addr, addr->ipv4, 4); - sa = (struct sockaddr *)&sin; - sin_len = sizeof(sin); - break; - } - - ret = sendto(udp_socket->fd, buf, len, 0, sa, sin_len); - - if (ret < 0) { - - LOGE("Failed to sendto: %s", strerror(errno)); - return -1; - } - - return ret; -} - -int udp_socket_recvfrom(UdpSocket *udp_socket, Address *addr, uint8_t *buf, int len) { - - struct sockaddr_in sin; - struct sockaddr_in6 sin6; - struct sockaddr *sa; - socklen_t sin_len; - int ret; - - if (udp_socket->fd < 0) { - - LOGE("recvfrom before socket init"); - return -1; - } - - switch (udp_socket->bind_addr.family) { - case AF_INET6: - sin_len = sizeof(sin6); - sa = (struct sockaddr *)&sin6; - break; - case AF_INET: - default: - sin_len = sizeof(sin); - sa = (struct sockaddr *)&sin; - break; - } - - ret = recvfrom(udp_socket->fd, buf, len, 0, sa, &sin_len); - if (ret < 0) { - LOGE("Failed to recvfrom: %s", strerror(errno)); - return -1; - } - - if (addr) { - switch (udp_socket->bind_addr.family) { - case AF_INET6: - addr->family = AF_INET6; - addr->port = ntohs(sin6.sin6_port); - memcpy(addr->ipv6, &sin6.sin6_addr, 16); - break; - case AF_INET: - default: - addr->family = AF_INET; - addr->port = ntohs(sin.sin_port); - memcpy(addr->ipv4, &sin.sin_addr.s_addr, 4); - break; - } - } - - return ret; -} - diff --git a/src/udp.h b/src/udp.h deleted file mode 100644 index 90fda81..0000000 --- a/src/udp.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef UDP_SOCKET_H_ -#define UDP_SOCKET_H_ - -#include "address.h" - -typedef struct UdpSocket UdpSocket; - -struct UdpSocket { - - int fd; - Address bind_addr; - long long int timeout_sec; - long int timeout_usec; -}; - -int udp_socket_create(UdpSocket *udp_socket, int family); - -int udp_socket_open(UdpSocket *udp_socket, int family); - -int udp_socket_bind(UdpSocket *udp_socket, Address *addr); - -void udp_socket_close(UdpSocket *udp_socket); - -int udp_socket_sendto(UdpSocket *udp_socket, Address *addr, const uint8_t *buf, int len); - -int udp_socket_recvfrom(UdpSocket *udp_socket, Address *addr, uint8_t *buf, int len); - -int udp_socket_get_host_address(UdpSocket *udp_socket, Address *addr); - -int udp_resolve_mdns_host(const char *host, Address *addr); - -void udp_blocking_timeout(UdpSocket *udp_socket, long long int ms); - -#endif // UDP_SOCKET_H_ - diff --git a/src/utils.c b/src/utils.c index a94ae99..9d999f8 100644 --- a/src/utils.c +++ b/src/utils.c @@ -3,46 +3,12 @@ #include #include #include -#include #include #include #include "utils.h" #include "mbedtls/md.h" -// http://haoyuanliu.github.io/2017/01/16/%E5%9C%B0%E5%9D%80%E6%9F%A5%E8%AF%A2%E5%87%BD%E6%95%B0gethostbyname-%E5%92%8Cgetaddrinfo/ -int utils_get_ipv4addr(char *hostname, char *ipv4addr, size_t size) { -#if 0 - struct addrinfo *ai, *aip; - struct addrinfo hint; - struct sockaddr_in *sinp; - int err; - - hint.ai_flags = AI_CANONNAME; - hint.ai_family = AF_INET; - hint.ai_socktype = 0; - hint.ai_protocol = SOCK_DGRAM; - hint.ai_addrlen = 0; - hint.ai_canonname = NULL; - hint.ai_addr = NULL; - hint.ai_next = NULL; - - if((err = getaddrinfo(hostname, NULL, &hint, &ai)) != 0) { - printf("ERROR: getaddrinfo error: %s\n", gai_strerror(err)); - return -1; - } - - for(aip = ai; aip != NULL; aip = aip->ai_next) { - if(aip->ai_family == AF_INET) { - sinp = (struct sockaddr_in *)aip->ai_addr; - inet_ntop(AF_INET, &sinp->sin_addr, ipv4addr, size); - return 0; - } - } -#endif - return -1; -} - void utils_random_string(char *s, const int len) { int i; @@ -84,11 +50,3 @@ void utils_get_md5(const char *input, size_t input_len, unsigned char *output) { mbedtls_md_finish(&ctx, output); mbedtls_md_free(&ctx); } - -uint32_t utils_get_timestamp() { - - struct timeval tv; - gettimeofday(&tv, NULL); - return (uint32_t) tv.tv_sec * 1000 + tv.tv_usec / 1000; -} - diff --git a/src/utils.h b/src/utils.h index 5741db0..6f3e461 100644 --- a/src/utils.h +++ b/src/utils.h @@ -55,6 +55,4 @@ void utils_get_hmac_sha1(const char *input, size_t input_len, const char *key, s void utils_get_md5(const char *input, size_t input_len, unsigned char *output); -uint32_t utils_get_timestamp(); - #endif // UTILS_H_