diff --git a/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c b/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c index 51f3db7db..801c26341 100644 --- a/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c +++ b/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c @@ -47,12 +47,7 @@ struct bt_mesh_dev bt_mesh_dev; /* P-256 Variables */ static u8_t bt_mesh_public_key[64]; -static BT_OCTET32 bt_mesh_private_key = { - 0x3f, 0x49, 0xf6, 0xd4, 0xa3, 0xc5, 0x5f, 0x38, - 0x74, 0xc9, 0xb3, 0xe3, 0xd2, 0x10, 0x3f, 0x50, - 0x4a, 0xff, 0x60, 0x7b, 0xeb, 0x40, 0xb7, 0x99, - 0x58, 0x99, 0xb8, 0xa6, 0xcd, 0x3c, 0x1a, 0xbd -}; +static BT_OCTET32 bt_mesh_private_key; /* Scan related functions */ static bt_mesh_scan_cb_t *bt_mesh_scan_dev_found_cb; @@ -103,11 +98,6 @@ int bt_mesh_host_init(void) return 0; } -int bt_mesh_host_deinit(void) -{ - return 0; -} - void bt_mesh_hci_init(void) { const uint8_t *features = controller_get_interface()->get_features_ble()->as_array; @@ -1798,8 +1788,17 @@ void bt_mesh_gatt_deinit(void) void bt_mesh_adapt_init(void) { BT_DBG("%s", __func__); + /* initialization of P-256 parameters */ p_256_init_curve(KEY_LENGTH_DWORDS_P256); + + /* Set "bt_mesh_dev.flags" to 0 (only the "BLE_MESH_DEV_HAS_PUB_KEY" + * flag is used) here, because we need to make sure each time after + * the private key is initialized, a corresponding public key must + * be generated. + */ + bt_mesh_atomic_set(bt_mesh_dev.flags, 0); + bt_mesh_rand(bt_mesh_private_key, sizeof(bt_mesh_private_key)); } int bt_mesh_rand(void *buf, size_t len) @@ -1855,7 +1854,8 @@ const u8_t *bt_mesh_pub_key_get(void) memcpy(bt_mesh_public_key + BT_OCTET32_LEN, public_key.y, BT_OCTET32_LEN); bt_mesh_atomic_set_bit(bt_mesh_dev.flags, BLE_MESH_DEV_HAS_PUB_KEY); - BT_DBG("gen the bt_mesh_public_key:%s", bt_hex(bt_mesh_public_key, sizeof(bt_mesh_public_key))); + + BT_DBG("Public Key %s", bt_hex(bt_mesh_public_key, sizeof(bt_mesh_public_key))); return bt_mesh_public_key; } diff --git a/components/bt/esp_ble_mesh/mesh_core/include/mesh_bearer_adapt.h b/components/bt/esp_ble_mesh/mesh_core/include/mesh_bearer_adapt.h index 99a53a6f3..ea4ba202b 100644 --- a/components/bt/esp_ble_mesh/mesh_core/include/mesh_bearer_adapt.h +++ b/components/bt/esp_ble_mesh/mesh_core/include/mesh_bearer_adapt.h @@ -665,7 +665,6 @@ struct bt_mesh_gatt_attr { } int bt_mesh_host_init(void); -int bt_mesh_host_deinit(void); int bt_le_adv_start(const struct bt_mesh_adv_param *param, const struct bt_mesh_adv_data *ad, size_t ad_len, diff --git a/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c b/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c index fb6d1fe8f..037296f6c 100644 --- a/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c +++ b/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c @@ -63,12 +63,7 @@ struct bt_mesh_dev bt_mesh_dev; /* P-256 Variables */ static u8_t bt_mesh_public_key[64]; -static u8_t bt_mesh_private_key[32] = { - 0x3f, 0x49, 0xf6, 0xd4, 0xa3, 0xc5, 0x5f, 0x38, - 0x74, 0xc9, 0xb3, 0xe3, 0xd2, 0x10, 0x3f, 0x50, - 0x4a, 0xff, 0x60, 0x7b, 0xeb, 0x40, 0xb7, 0x99, - 0x58, 0x99, 0xb8, 0xa6, 0xcd, 0x3c, 0x1a, 0xbd -}; +static u8_t bt_mesh_private_key[32]; /* Scan related functions */ static bt_mesh_scan_cb_t *bt_mesh_scan_dev_found_cb; @@ -1758,8 +1753,17 @@ void ble_sm_alg_ecc_init(void); void bt_mesh_adapt_init(void) { BT_DBG("%s", __func__); + /* initialization of P-256 parameters */ ble_sm_alg_ecc_init(); + + /* Set "bt_mesh_dev.flags" to 0 (only the "BLE_MESH_DEV_HAS_PUB_KEY" + * flag is used) here, because we need to make sure each time after + * the private key is initialized, a corresponding public key must + * be generated. + */ + bt_mesh_atomic_set(bt_mesh_dev.flags, 0); + bt_mesh_rand(bt_mesh_private_key, sizeof(bt_mesh_private_key)); } int bt_mesh_rand(void *buf, size_t len) @@ -1815,7 +1819,8 @@ const u8_t *bt_mesh_pub_key_get(void) memcpy(bt_mesh_private_key, pri_key, 32); bt_mesh_atomic_set_bit(bt_mesh_dev.flags, BLE_MESH_DEV_HAS_PUB_KEY); - BT_DBG("gen the bt_mesh_public_key:%s", bt_hex(bt_mesh_public_key, sizeof(bt_mesh_public_key))); + + BT_DBG("Public Key %s", bt_hex(bt_mesh_public_key, sizeof(bt_mesh_public_key))); return bt_mesh_public_key; } diff --git a/components/bt/esp_ble_mesh/mesh_core/prov.c b/components/bt/esp_ble_mesh/mesh_core/prov.c index 8f624cd0a..446987f2f 100644 --- a/components/bt/esp_ble_mesh/mesh_core/prov.c +++ b/components/bt/esp_ble_mesh/mesh_core/prov.c @@ -98,7 +98,7 @@ enum { REMOTE_PUB_KEY, /* Remote key has been received */ OOB_PUB_KEY, /* OOB public key is available */ LINK_ACTIVE, /* Link has been opened */ - HAVE_DHKEY, /* DHKey has been calcualted */ + HAVE_DHKEY, /* DHKey has been calculated */ SEND_CONFIRM, /* Waiting to send Confirm value */ WAIT_NUMBER, /* Waiting for number input from user */ WAIT_STRING, /* Waiting for string input from user */