diff --git a/components/esp8266/include/esp_smartconfig.h b/components/esp8266/include/esp_smartconfig.h index 52be7899..c0f796b7 100644 --- a/components/esp8266/include/esp_smartconfig.h +++ b/components/esp8266/include/esp_smartconfig.h @@ -28,6 +28,7 @@ typedef enum { SC_TYPE_ESPTOUCH = 0, /**< protocol: ESPTouch */ SC_TYPE_AIRKISS, /**< protocol: AirKiss */ SC_TYPE_ESPTOUCH_AIRKISS, /**< protocol: ESPTouch and AirKiss */ + SC_TYPE_ESPTOUCH_V2, /**< protocol: ESPTouch V2*/ } smartconfig_type_t; /** Smartconfig event declarations */ @@ -54,12 +55,16 @@ typedef struct { /** Configure structure for esp_smartconfig_start */ typedef struct { - bool enable_log; /**< Enable smartconfig logs. */ + bool enable_log; /**< Enable smartconfig logs. */ + bool esp_touch_v2_enable_crypt; /**< Enable ESPTOUCH V2 crypt. */ + char* esp_touch_v2_key; /**< ESPTOUCH V2 crypt key, len should be 16. */ } smartconfig_start_config_t; #define SMARTCONFIG_START_CONFIG_DEFAULT() { \ - .enable_log = false \ - }; + .enable_log = false, \ + .esp_touch_v2_enable_crypt = false,\ + .esp_touch_v2_key = NULL \ +}; /** * @brief Get the version of SmartConfig. @@ -139,6 +144,18 @@ esp_err_t esp_smartconfig_set_type(smartconfig_type_t type); */ esp_err_t esp_smartconfig_fast_mode(bool enable); +/** + * @brief Get reserved data of ESPTouch_v2. + * + * @param rvd_data reserved data + * @param len length of reserved data + * + * @return + * - ESP_OK: succeed + * - others: fail + */ +esp_err_t esp_smartconfig_get_rvd_data(uint8_t* rvd_data, uint8_t len); + #ifdef __cplusplus } #endif diff --git a/components/esp8266/include/esp_wifi_crypto_types.h b/components/esp8266/include/esp_wifi_crypto_types.h index 0638a918..efe76866 100644 --- a/components/esp8266/include/esp_wifi_crypto_types.h +++ b/components/esp8266/include/esp_wifi_crypto_types.h @@ -761,6 +761,8 @@ typedef struct { esp_aes_decrypt_t aes_decrypt; esp_aes_decrypt_init_t aes_decrypt_init; esp_aes_decrypt_deinit_t aes_decrypt_deinit; + esp_aes_128_encrypt_t aes_128_encrypt; + esp_aes_128_decrypt_t aes_128_decrypt; esp_omac1_aes_128_t omac1_aes_128; esp_ccmp_decrypt_t ccmp_decrypt; esp_ccmp_encrypt_t ccmp_encrypt; diff --git a/components/esp8266/lib/VERSION b/components/esp8266/lib/VERSION index 14c9bd31..2faa668b 100644 --- a/components/esp8266/lib/VERSION +++ b/components/esp8266/lib/VERSION @@ -1,8 +1,8 @@ gwen: - core: 5a78602 - net80211: 8c48ba9 - pp: 8c48ba9 - espnow: 5a78602 + core: 7a93d71 + net80211: 7a93d71 + pp: 7a93d71 + espnow: 7a93d71 - smartconfig: 2.9.0 + smartconfig: 3.0.0 phy: 1163.0 diff --git a/components/esp8266/lib/libcore.a b/components/esp8266/lib/libcore.a index 9bdb73e4..43a378a1 100755 Binary files a/components/esp8266/lib/libcore.a and b/components/esp8266/lib/libcore.a differ diff --git a/components/esp8266/lib/libcore_dbg.a b/components/esp8266/lib/libcore_dbg.a index 6cef4eb4..b7ed8abf 100755 Binary files a/components/esp8266/lib/libcore_dbg.a and b/components/esp8266/lib/libcore_dbg.a differ diff --git a/components/esp8266/lib/libespnow.a b/components/esp8266/lib/libespnow.a index 016d4e76..807bac79 100755 Binary files a/components/esp8266/lib/libespnow.a and b/components/esp8266/lib/libespnow.a differ diff --git a/components/esp8266/lib/libespnow_dbg.a b/components/esp8266/lib/libespnow_dbg.a index 984bd468..e3c2f9d3 100755 Binary files a/components/esp8266/lib/libespnow_dbg.a and b/components/esp8266/lib/libespnow_dbg.a differ diff --git a/components/esp8266/lib/libnet80211.a b/components/esp8266/lib/libnet80211.a index 9840d8dc..db3443ac 100755 Binary files a/components/esp8266/lib/libnet80211.a and b/components/esp8266/lib/libnet80211.a differ diff --git a/components/esp8266/lib/libnet80211_dbg.a b/components/esp8266/lib/libnet80211_dbg.a index 214f225e..fa82624d 100755 Binary files a/components/esp8266/lib/libnet80211_dbg.a and b/components/esp8266/lib/libnet80211_dbg.a differ diff --git a/components/esp8266/lib/libpp.a b/components/esp8266/lib/libpp.a index 8a8a777d..1a1f17e3 100755 Binary files a/components/esp8266/lib/libpp.a and b/components/esp8266/lib/libpp.a differ diff --git a/components/esp8266/lib/libpp_dbg.a b/components/esp8266/lib/libpp_dbg.a index 742a008c..245ef6d6 100755 Binary files a/components/esp8266/lib/libpp_dbg.a and b/components/esp8266/lib/libpp_dbg.a differ diff --git a/components/esp8266/lib/libsmartconfig.a b/components/esp8266/lib/libsmartconfig.a old mode 100644 new mode 100755 index 5f079f17..69709e31 Binary files a/components/esp8266/lib/libsmartconfig.a and b/components/esp8266/lib/libsmartconfig.a differ diff --git a/components/esp8266/source/smartconfig_ack.c b/components/esp8266/source/smartconfig_ack.c index b2f3aa19..7c434747 100644 --- a/components/esp8266/source/smartconfig_ack.c +++ b/components/esp8266/source/smartconfig_ack.c @@ -35,7 +35,9 @@ #define SC_ACK_TASK_PRIORITY 2 /*!< Priority of sending smartconfig ACK task */ #define SC_ACK_TASK_STACK_SIZE 2048 /*!< Stack size of sending smartconfig ACK task */ +#define SC_ACK_TOUCH_DEVICE_PORT 7001 /*!< ESPTOUCH UDP port of server on device */ #define SC_ACK_TOUCH_SERVER_PORT 18266 /*!< ESP touch UDP port of server on cellphone */ +#define SC_ACK_TOUCH_V2_SERVER_PORT(i) (18266+i*10000) /*!< ESP touch_v2 UDP port of server on cellphone */ #define SC_ACK_AIRKISS_SERVER_PORT 10000 /*!< Airkiss UDP port of server on cellphone */ #define SC_ACK_AIRKISS_DEVICE_PORT 10001 /*!< Airkiss UDP port of server on device */ #define SC_ACK_AIRKISS_TIMEOUT 1500 /*!< Airkiss read data timout millisecond */ @@ -78,7 +80,6 @@ static void sc_ack_send_task(void* pvParameters) tcpip_adapter_ip_info_t local_ip; uint8_t remote_ip[4]; memset(remote_ip, 0xFF, sizeof(remote_ip)); - int remote_port = (ack->type == SC_TYPE_ESPTOUCH) ? SC_ACK_TOUCH_SERVER_PORT : SC_ACK_AIRKISS_SERVER_PORT; struct sockaddr_in server_addr; socklen_t sin_size = sizeof(server_addr); int send_sock = -1; @@ -88,6 +89,19 @@ static void sc_ack_send_task(void* pvParameters) uint8_t packet_count = 1; int err; int ret; + int remote_port = 0; + + if (ack->type == SC_TYPE_ESPTOUCH) { + remote_port = SC_ACK_TOUCH_SERVER_PORT; + } else if (ack->type == SC_TYPE_ESPTOUCH_V2) { + uint8_t port_bit = ack->ctx.token; + if(port_bit > 3) { + port_bit = 0; + } + remote_port = SC_ACK_TOUCH_V2_SERVER_PORT(port_bit); + } else { + remote_port = SC_ACK_AIRKISS_SERVER_PORT; + } bzero(&server_addr, sizeof(struct sockaddr_in)); server_addr.sin_family = AF_INET; @@ -152,7 +166,7 @@ static void sc_ack_send_task(void* pvParameters) sendlen = sendto(send_sock, &ack->ctx, ack_len, 0, (struct sockaddr*) &server_addr, sin_size); if (sendlen > 0) { - /* Totally send 30 smartconfig ACKs. Then smartconfig is successful. */ + /* Totally send 60 smartconfig ACKs. Then smartconfig is successful. */ if (packet_count++ >= SC_ACK_MAX_COUNT) { esp_event_post(SC_EVENT, SC_EVENT_SEND_ACK_DONE, NULL, 0, portMAX_DELAY); goto _end; diff --git a/components/wpa_supplicant/src/crypto/crypto_ops.c b/components/wpa_supplicant/src/crypto/crypto_ops.c index 5657adcc..7533f9bb 100644 --- a/components/wpa_supplicant/src/crypto/crypto_ops.c +++ b/components/wpa_supplicant/src/crypto/crypto_ops.c @@ -50,6 +50,8 @@ const wpa_crypto_funcs_t g_wifi_default_wpa_crypto_funcs = { .aes_decrypt = (esp_aes_decrypt_t)aes_decrypt, .aes_decrypt_init = (esp_aes_decrypt_init_t)aes_decrypt_init, .aes_decrypt_deinit = (esp_aes_decrypt_deinit_t)aes_decrypt_deinit, + .aes_128_encrypt = (esp_aes_128_encrypt_t)aes_128_cbc_encrypt, + .aes_128_decrypt = (esp_aes_128_decrypt_t)aes_128_cbc_decrypt, .omac1_aes_128 = (esp_omac1_aes_128_t)omac1_aes_128, .ccmp_decrypt = (esp_ccmp_decrypt_t)ccmp_decrypt, .ccmp_encrypt = (esp_ccmp_encrypt_t)ccmp_encrypt diff --git a/examples/wifi/smart_config/README.md b/examples/wifi/smart_config/README.md index f9a41059..7d20862d 100644 --- a/examples/wifi/smart_config/README.md +++ b/examples/wifi/smart_config/README.md @@ -8,43 +8,104 @@ This example shows how ESP8266 connects to AP with ESPTOUCH. Example does the fo * Make sure your phone connect to target AP (2.4GHz). +* Make sure that the smartconfig type selected on your device corresponds to the APP. + * Open ESPTOUCH app and input password. There will be success message after few sec. -### Example output +## Support ESP-Touch-V2 + +* ESP-Touch-V2 is a new SmartConfig method developed by Espressif. With ESP-Touch-V2, the configuration time and success rate of connecting to an AP are highly improved when compares to the old version ESP-Touch, which we call it "ESP-Touch-V1" in this doc. + +* New features: In addition to get ssid and password, ESP-Touch-V2 supports to get user-defined reserved data and encrypted transmission. + +**ESP-Touch-V2 is not compatible with the old ESP-Touch-V1. It is recommended to use ESP-Touch-V2 in your new products, not your existing ESP-Touch-V1 products.** + +* Since ESP-Touch-V2 is implemented in a new way, it is not compatible with the old ESP-Touch-V1. The phone APP is also not compatible between V1 and V2. So, if you already have a product using ESP-Touch-V1, we do not recommend to update it to ESP-Touch-V2. +If your phone APP has already supported ESP-Touch-V1, and wants to add ESP-Touch-V2 for future new products, then your phone APP must able to choose different SmartConfig methods, V1 or V2, otherwise, keep using ESP-Touch-V1 is the best choice. + +## How to use example + +### Configure the project -Here is an example of smartconfig console output. ``` -I (162) boot: Loaded app from partition at offset 0x10000 -mode : sta(ec:fa:bc:1d:33:e0) -add if0 -SC version: V2.5.4 -scandone -scandone -I (5) sc: SC_STATUS_FINDING_CHANNEL +idf.py menuconfig +``` -TYPE: ESPTOUCH -T|PHONE MAC: 90 f0 52 0c 16 2d -T|AP MAC : bc 5f f6 1b e8 1c -I (8) sc: SC_STATUS_GETTING_SSID_PSWD -T|pswd: 1234567890 +* Set serial port under Serial Flasher Options. + +* Set WiFi SSID and WiFi Password and Maximal STA connections under Example Configuration Options. + +### Build and Flash + +Build the project and flash it to the board, then run monitor tool to view serial output: + +``` +idf.py -p PORT flash monitor +``` + +(To exit the serial monitor, type ``Ctrl-]``.) + +See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects. + +## Example output + +Here is an example of smartconfig (ESP-Touch) console output. +``` +I (369) boot: Loaded app from partition at offset 0x10000 +I (403) system_api: Base MAC address is not set, read default base MAC address from EFUSE +I (408) system_api: Base MAC address is not set, read default base MAC address from EFUSE +phy_version: 1163.0, 665d56c, Jun 24 2020, 10:00:08, RTOS new +I (478) phy_init: phy ver: 1163_0 +I (497) wifi:pm stop +SC version: V3.0.0, TYPE: 0 +sync_len: [60,643] +I (3689) smartconfig_example: Scan done +TYPE: ESPTOUCH, ch:13 +T|PHONE MAC: e0:b5:5f:e5:05:9f +T|AP MAC: 8c:ab:8e:bb:82:08 +I (51619) smartconfig_example: Found channel +T|pswd: espressif T|ssid: TEST001 -I (17) sc: SC_STATUS_LINK -I (17) sc: SSID:TEST001 -I (17) sc: PASSWORD:1234567890 -scandone -state: 0 -> 2 (b0) -state: 2 -> 3 (0) -state: 3 -> 5 (10) -add 0 -aid 2 -pm open phy_2,type:2 0 0 -cnt +I (52877) smartconfig_example: Got SSID and password +I (52880) smartconfig_example: SSID:TEST001 +I (52882) smartconfig_example: PASSWORD:espressif +I (58070) wifi:state: 0 -> 2 (b0) +I (58079) wifi:state: 2 -> 3 (0) +I (58088) wifi:state: 3 -> 5 (10) +I (58377) wifi:connected with TEST001, aid = 4, channel 13, HT20, bssid = 8c:ab:8e:bb:82:08 +I (61567) tcpip_adapter: sta ip: 192.168.103.154, mask: 255.255.255.0, gw: 192.168.103.1 +I (61574) smartconfig_example: WiFi Connected to ap +I (67667) smartconfig_example: smartconfig over -connected with TEST001, channel 3 -I (22) event: sta ip: 192.168.0.108, mask: 255.255.255.0, gw: 192.168.0.1 -I (22) sc: WiFi Connected to ap -I (25) sc: SC_STATUS_LINK_OVER -I (25) sc: Phone ip: 192.168.0.108 - -I (25) sc: smartconfig over ``` +Here is an example of smartconfig (ESP-Touch-V2) console output. +``` +I (369) boot: Loaded app from partition at offset 0x10000 +I (396) system_api: Base MAC address is not set, read default base MAC address from EFUSE +I (401) system_api: Base MAC address is not set, read default base MAC address from EFUSE +phy_version: 1163.0, 665d56c, Jun 24 2020, 10:00:08, RTOS new +I (471) phy_init: phy ver: 1163_0 +I (491) wifi:pm stop +SC version: V3.0.0, TYPE: 3 +sync_len: [127,1200] +I (3683) smartconfig_example: Scan done +lock channel: 13 +TYPE: ESPTOUCH_V2, ch: 13 +offset:52 tods: 1 +I (5528) smartconfig_example: Found channel +lock channel: 13 +offset:52 tods: 0 +total_seq: 7 +I (15033) smartconfig_example: Got SSID and password +I (15036) smartconfig_example: SSID:TEST001 +I (15039) smartconfig_example: PASSWORD:espressif +I (15044) smartconfig_example: RVD_DATA:1234567890 +I (15414) wifi:state: 0 -> 2 (b0) +I (15468) wifi:state: 2 -> 3 (0) +I (15475) wifi:state: 3 -> 5 (10) +I (15821) wifi:connected with TEST001, aid = 4, channel 13, HT20, bssid = 8c:ab:8e:bb:82:08 +I (16409) tcpip_adapter: sta ip: 192.168.103.154, mask: 255.255.255.0, gw: 192.168.103.1 +I (16415) smartconfig_example: WiFi Connected to ap +I (22448) smartconfig_example: smartconfig over + +``` \ No newline at end of file diff --git a/examples/wifi/smart_config/main/Kconfig.projbuild b/examples/wifi/smart_config/main/Kconfig.projbuild new file mode 100644 index 00000000..533a7140 --- /dev/null +++ b/examples/wifi/smart_config/main/Kconfig.projbuild @@ -0,0 +1,28 @@ +menu "Example Configuration" + +choice ESP_SMARTCONFIG_TYPE + prompt "Smartconfig Type" + default ESP_TOUCH + help + Set protocol type of SmartConfig. + + Start SmartConfig method according to the selected type when user select "ESPTouch", "AirKiss", "ESPTouch and AirKiss" or "ESPTouch V2" type. + +config ESP_TOUCH + bool "ESPTouch" +config AIRKISS + bool "AirKiss" +config ESP_TOUCH-AIRKISS + bool "ESPTouch and AirKiss" +config ESP_TOUCH_V2 + bool "ESPTouch-V2" +endchoice + +config ESP_SMARTCONFIG_TYPE + int + default 0 if ESP_TOUCH + default 1 if AIRKISS + default 2 if ESP_TOUCH-AIRKISS + default 3 if ESP_TOUCH_V2 + +endmenu diff --git a/examples/wifi/smart_config/main/smartconfig_main.c b/examples/wifi/smart_config/main/smartconfig_main.c index fd1299a8..0beb9612 100644 --- a/examples/wifi/smart_config/main/smartconfig_main.c +++ b/examples/wifi/smart_config/main/smartconfig_main.c @@ -21,6 +21,13 @@ #include "esp_smartconfig.h" #include "smartconfig_ack.h" +/* The examples use smartconfig type that you can set via project configuration menu. + + If you'd rather not, just change the below entries to enum with + the config you want - ie #define EXAMPLE_ESP_SMARTCOFNIG_TYPE SC_TYPE_ESPTOUCH +*/ +#define EXAMPLE_ESP_SMARTCOFNIG_TYPE CONFIG_ESP_SMARTCONFIG_TYPE + /* FreeRTOS event group to signal when we are connected & ready to make a request */ static EventGroupHandle_t s_wifi_event_group; @@ -54,6 +61,7 @@ static void event_handler(void* arg, esp_event_base_t event_base, wifi_config_t wifi_config; uint8_t ssid[33] = { 0 }; uint8_t password[65] = { 0 }; + uint8_t rvd_data[33] = { 0 }; bzero(&wifi_config, sizeof(wifi_config_t)); memcpy(wifi_config.sta.ssid, evt->ssid, sizeof(wifi_config.sta.ssid)); @@ -68,6 +76,10 @@ static void event_handler(void* arg, esp_event_base_t event_base, memcpy(password, evt->password, sizeof(evt->password)); ESP_LOGI(TAG, "SSID:%s", ssid); ESP_LOGI(TAG, "PASSWORD:%s", password); + if (evt->type == SC_TYPE_ESPTOUCH_V2) { + ESP_ERROR_CHECK( esp_smartconfig_get_rvd_data(rvd_data, sizeof(rvd_data)) ); + ESP_LOGI(TAG, "RVD_DATA:%s", rvd_data); + } ESP_ERROR_CHECK(esp_wifi_disconnect()); ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config)); @@ -99,7 +111,7 @@ static void initialise_wifi(void) static void smartconfig_example_task(void* parm) { EventBits_t uxBits; - ESP_ERROR_CHECK(esp_smartconfig_set_type(SC_TYPE_ESPTOUCH)); + ESP_ERROR_CHECK(esp_smartconfig_set_type(EXAMPLE_ESP_SMARTCOFNIG_TYPE)); smartconfig_start_config_t cfg = SMARTCONFIG_START_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_smartconfig_start(&cfg));