From 09800028e1b224f4f64180b91a38648660c7ed7c Mon Sep 17 00:00:00 2001 From: isha pardikar Date: Wed, 8 Sep 2021 13:11:33 +0530 Subject: [PATCH] Wifi_prov_mgr:Fix for ios device needs to do forget device --- .../include/transports/protocomm_ble.h | 22 +++++++--------- .../protocomm/src/simple_ble/simple_ble.c | 25 ++++++++----------- .../protocomm/src/simple_ble/simple_ble.h | 20 ++++++--------- .../protocomm/src/transports/protocomm_ble.c | 20 ++++++--------- .../src/transports/protocomm_nimble.c | 24 ++++++++---------- components/wifi_provisioning/Kconfig | 7 ++++++ components/wifi_provisioning/src/scheme_ble.c | 22 +++++++--------- tools/ci/check_copyright_ignore.txt | 6 ----- 8 files changed, 60 insertions(+), 86 deletions(-) diff --git a/components/protocomm/include/transports/protocomm_ble.h b/components/protocomm/include/transports/protocomm_ble.h index a9e7b6a209..f899f95b18 100644 --- a/components/protocomm/include/transports/protocomm_ble.h +++ b/components/protocomm/include/transports/protocomm_ble.h @@ -1,16 +1,8 @@ -// Copyright 2018 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2018-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #pragma once @@ -86,6 +78,10 @@ typedef struct protocomm_ble_config { * Pointer to the Name-UUID lookup table */ protocomm_ble_name_uuid_t *nu_lookup; + + /* BLE bonding */ + unsigned ble_bonding:1; + } protocomm_ble_config_t; /** diff --git a/components/protocomm/src/simple_ble/simple_ble.c b/components/protocomm/src/simple_ble/simple_ble.c index 2f98e09143..c6db16a9f8 100644 --- a/components/protocomm/src/simple_ble/simple_ble.c +++ b/components/protocomm/src/simple_ble/simple_ble.c @@ -1,16 +1,8 @@ -// Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include #include @@ -277,7 +269,12 @@ esp_err_t simple_ble_start(simple_ble_cfg_t *cfg) ESP_LOGD(TAG, "Free mem at end of simple_ble_init %d", esp_get_free_heap_size()); /* set the security iocap & auth_req & key size & init key response key parameters to the stack*/ - esp_ble_auth_req_t auth_req = ESP_LE_AUTH_REQ_SC_MITM_BOND; //bonding with peer device after authentication + esp_ble_auth_req_t auth_req; + if (cfg->ble_bonding) { + auth_req = ESP_LE_AUTH_REQ_SC_MITM_BOND; //bonding with peer device after authentication + } else { + auth_req = ESP_LE_AUTH_REQ_SC_MITM; + } esp_ble_io_cap_t iocap = ESP_IO_CAP_NONE; //set the IO capability to No output No input uint8_t key_size = 16; //the key size should be 7~16 bytes uint8_t init_key = ESP_BLE_ENC_KEY_MASK | ESP_BLE_ID_KEY_MASK; diff --git a/components/protocomm/src/simple_ble/simple_ble.h b/components/protocomm/src/simple_ble/simple_ble.h index 46f37f6d46..458fc52b36 100644 --- a/components/protocomm/src/simple_ble/simple_ble.h +++ b/components/protocomm/src/simple_ble/simple_ble.h @@ -1,16 +1,8 @@ -// Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #ifndef _SIMPLE_BLE_ #define _SIMPLE_BLE_ @@ -57,6 +49,8 @@ typedef struct { simple_ble_cb_t *connect_fn; /** MTU set callback */ simple_ble_cb_t *set_mtu_fn; + /* BLE bonding */ + unsigned ble_bonding:1; } simple_ble_cfg_t; diff --git a/components/protocomm/src/transports/protocomm_ble.c b/components/protocomm/src/transports/protocomm_ble.c index c2ac4176b4..2a2c892307 100644 --- a/components/protocomm/src/transports/protocomm_ble.c +++ b/components/protocomm/src/transports/protocomm_ble.c @@ -1,16 +1,8 @@ -// Copyright 2018 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2018-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include #include @@ -654,6 +646,8 @@ esp_err_t protocomm_ble_start(protocomm_t *pc, const protocomm_ble_config_t *con ble_config->device_name = protocomm_ble_device_name; ble_config->gatt_db_count = populate_gatt_db(&ble_config->gatt_db); + ble_config->ble_bonding = config->ble_bonding; + if (ble_config->gatt_db_count == -1) { ESP_LOGE(TAG, "Invalid GATT database count"); simple_ble_deinit(); diff --git a/components/protocomm/src/transports/protocomm_nimble.c b/components/protocomm/src/transports/protocomm_nimble.c index 5edf532550..dd3fc25965 100644 --- a/components/protocomm/src/transports/protocomm_nimble.c +++ b/components/protocomm/src/transports/protocomm_nimble.c @@ -1,16 +1,8 @@ -// Copyright 2019 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2019-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include #include @@ -129,6 +121,8 @@ typedef struct { simple_ble_cb_t *connect_fn; /** MTU set callback */ simple_ble_cb_t *set_mtu_fn; + /* BLE bonding */ + unsigned ble_bonding:1; } simple_ble_cfg_t; static simple_ble_cfg_t *ble_cfg_p; @@ -490,9 +484,10 @@ static int simple_ble_start(const simple_ble_cfg_t *cfg) /* Initialize security manager configuration in NimBLE host */ ble_hs_cfg.sm_io_cap = BLE_SM_IO_CAP_NO_IO; /* Just Works */ - ble_hs_cfg.sm_bonding = 1; /* Enable bonding inline with bluedroid */ + ble_hs_cfg.sm_bonding = cfg->ble_bonding; ble_hs_cfg.sm_mitm = 1; ble_hs_cfg.sm_sc = 1; /* Enable secure connection by default */ + /* Distribute LTK and IRK */ ble_hs_cfg.sm_our_key_dist = BLE_SM_PAIR_KEY_DIST_ENC | BLE_SM_PAIR_KEY_DIST_ID; ble_hs_cfg.sm_their_key_dist = BLE_SM_PAIR_KEY_DIST_ENC | BLE_SM_PAIR_KEY_DIST_ID; @@ -907,6 +902,7 @@ esp_err_t protocomm_ble_start(protocomm_t *pc, const protocomm_ble_config_t *con ble_config->adv_params = adv_params; ble_config->device_name = protocomm_ble_device_name; + ble_config->ble_bonding = config->ble_bonding; if (populate_gatt_db(&ble_config->gatt_db, config) != 0) { ESP_LOGE(TAG, "Error populating GATT Database"); diff --git a/components/wifi_provisioning/Kconfig b/components/wifi_provisioning/Kconfig index cfadd5a997..0d37a9b820 100644 --- a/components/wifi_provisioning/Kconfig +++ b/components/wifi_provisioning/Kconfig @@ -15,4 +15,11 @@ menu "Wi-Fi Provisioning Manager" Time (in seconds) after which the Wi-Fi provisioning manager will auto-stop after connecting to a Wi-Fi network successfully. + config WIFI_PROV_BLE_BONDING + bool + default n + prompt "Enable BLE bonding" + depends on BT_ENABLED + help + This option is applicable only when provisioning transport is BLE. endmenu diff --git a/components/wifi_provisioning/src/scheme_ble.c b/components/wifi_provisioning/src/scheme_ble.c index 3961633985..147465ecf1 100644 --- a/components/wifi_provisioning/src/scheme_ble.c +++ b/components/wifi_provisioning/src/scheme_ble.c @@ -1,16 +1,8 @@ -// Copyright 2019 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2019-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include #include @@ -46,6 +38,10 @@ static esp_err_t prov_start(protocomm_t *pc, void *config) protocomm_ble_config_t *ble_config = (protocomm_ble_config_t *) config; + #ifdef CONFIG_WIFI_PROV_BLE_BONDING + ble_config->ble_bonding = 1; + #endif + /* Start protocomm as BLE service */ if (protocomm_ble_start(pc, ble_config) != ESP_OK) { ESP_LOGE(TAG, "Failed to start protocomm BLE service"); diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index e907e8755c..203094a011 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -2159,7 +2159,6 @@ components/protocomm/include/common/protocomm.h components/protocomm/include/security/protocomm_security.h components/protocomm/include/security/protocomm_security0.h components/protocomm/include/security/protocomm_security1.h -components/protocomm/include/transports/protocomm_ble.h components/protocomm/include/transports/protocomm_console.h components/protocomm/include/transports/protocomm_httpd.h components/protocomm/proto-c/constants.pb-c.c @@ -2178,12 +2177,8 @@ components/protocomm/src/common/protocomm.c components/protocomm/src/common/protocomm_priv.h components/protocomm/src/security/security0.c components/protocomm/src/security/security1.c -components/protocomm/src/simple_ble/simple_ble.c -components/protocomm/src/simple_ble/simple_ble.h -components/protocomm/src/transports/protocomm_ble.c components/protocomm/src/transports/protocomm_console.c components/protocomm/src/transports/protocomm_httpd.c -components/protocomm/src/transports/protocomm_nimble.c components/protocomm/test/test_protocomm.c components/pthread/include/esp_pthread.h components/pthread/pthread.c @@ -2987,7 +2982,6 @@ components/wifi_provisioning/python/wifi_constants_pb2.py components/wifi_provisioning/python/wifi_scan_pb2.py components/wifi_provisioning/src/handlers.c components/wifi_provisioning/src/manager.c -components/wifi_provisioning/src/scheme_ble.c components/wifi_provisioning/src/scheme_console.c components/wifi_provisioning/src/scheme_softap.c components/wifi_provisioning/src/wifi_config.c