From 6a9420465c991936f0aae20f56dfb4ae362bcf5a Mon Sep 17 00:00:00 2001 From: zhiweijian Date: Fri, 23 Mar 2018 16:12:47 +0800 Subject: [PATCH] Component/bt: fix strncp error in blufi --- examples/bluetooth/blufi/main/blufi_example_main.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/bluetooth/blufi/main/blufi_example_main.c b/examples/bluetooth/blufi/main/blufi_example_main.c index 6c1382ba17..9a55cfe019 100644 --- a/examples/bluetooth/blufi/main/blufi_example_main.c +++ b/examples/bluetooth/blufi/main/blufi_example_main.c @@ -223,6 +223,10 @@ static void example_event_callback(esp_blufi_cb_event_t event, esp_blufi_cb_para break; case ESP_BLUFI_EVENT_REQ_CONNECT_TO_AP: BLUFI_INFO("BLUFI requset wifi connect to AP\n"); + /* there is no wifi callback when the device has already connected to this wifi + so disconnect wifi before connection. + */ + esp_wifi_disconnect(); esp_wifi_connect(); break; case ESP_BLUFI_EVENT_REQ_DISCONNECT_FROM_AP: @@ -280,14 +284,16 @@ static void example_event_callback(esp_blufi_cb_event_t event, esp_blufi_cb_para break; case ESP_BLUFI_EVENT_RECV_SOFTAP_SSID: strncpy((char *)ap_config.ap.ssid, (char *)param->softap_ssid.ssid, param->softap_ssid.ssid_len); + ap_config.ap.ssid[param->softap_ssid.ssid_len] = '\0'; ap_config.ap.ssid_len = param->softap_ssid.ssid_len; esp_wifi_set_config(WIFI_IF_AP, &ap_config); BLUFI_INFO("Recv SOFTAP SSID %s, ssid len %d\n", ap_config.ap.ssid, ap_config.ap.ssid_len); break; case ESP_BLUFI_EVENT_RECV_SOFTAP_PASSWD: strncpy((char *)ap_config.ap.password, (char *)param->softap_passwd.passwd, param->softap_passwd.passwd_len); + ap_config.ap.password[param->softap_passwd.passwd_len] = '\0'; esp_wifi_set_config(WIFI_IF_AP, &ap_config); - BLUFI_INFO("Recv SOFTAP PASSWORD %s\n", ap_config.ap.password); + BLUFI_INFO("Recv SOFTAP PASSWORD %s len = %d\n", ap_config.ap.password, param->softap_passwd.passwd_len); break; case ESP_BLUFI_EVENT_RECV_SOFTAP_MAX_CONN_NUM: if (param->softap_max_conn_num.max_conn_num > 4) {