kopia lustrzana https://github.com/espressif/esp-idf
Add secure connection for just works in provisioning app for bluedroid
This MR adds support of secure connection, encryption flags to characteristics and bonding with Just Work as association model [BLE Provisioning] Added secure connection pairing support to unified provisioning framework.pull/6828/head
rodzic
b9efd5d8dd
commit
105497f861
|
@ -62,6 +62,9 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
|
|||
esp_ble_gap_start_advertising(&g_ble_cfg_p->adv_params);
|
||||
}
|
||||
break;
|
||||
case ESP_GAP_BLE_SEC_REQ_EVT:
|
||||
esp_ble_gap_security_rsp(param->ble_security.ble_req.bd_addr, true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -272,6 +275,20 @@ esp_err_t simple_ble_start(simple_ble_cfg_t *cfg)
|
|||
ESP_LOGE(TAG, "set local MTU failed, error code = 0x%x", local_mtu_ret);
|
||||
}
|
||||
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_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;
|
||||
uint8_t rsp_key = ESP_BLE_ENC_KEY_MASK | ESP_BLE_ID_KEY_MASK;
|
||||
|
||||
esp_ble_gap_set_security_param(ESP_BLE_SM_AUTHEN_REQ_MODE, &auth_req, sizeof(uint8_t));
|
||||
esp_ble_gap_set_security_param(ESP_BLE_SM_IOCAP_MODE, &iocap, sizeof(uint8_t));
|
||||
esp_ble_gap_set_security_param(ESP_BLE_SM_MAX_KEY_SIZE, &key_size, sizeof(uint8_t));
|
||||
esp_ble_gap_set_security_param(ESP_BLE_SM_SET_INIT_KEY, &init_key, sizeof(uint8_t));
|
||||
esp_ble_gap_set_security_param(ESP_BLE_SM_SET_RSP_KEY, &rsp_key, sizeof(uint8_t));
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -393,7 +393,8 @@ static ssize_t populate_gatt_db(esp_gatts_attr_db_t **gatt_db_generated)
|
|||
(*gatt_db_generated)[i].att_desc.value = (uint8_t *) &character_prop_read_write;
|
||||
} else if (i % 3 == 2) {
|
||||
/* Characteristic Value */
|
||||
(*gatt_db_generated)[i].att_desc.perm = ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE;
|
||||
(*gatt_db_generated)[i].att_desc.perm = ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE | \
|
||||
ESP_GATT_PERM_READ_ENCRYPTED | ESP_GATT_PERM_WRITE_ENCRYPTED;
|
||||
(*gatt_db_generated)[i].att_desc.uuid_length = ESP_UUID_LEN_128;
|
||||
(*gatt_db_generated)[i].att_desc.uuid_p = protoble_internal->g_nu_lookup[i / 3].uuid128;
|
||||
(*gatt_db_generated)[i].att_desc.max_length = CHAR_VAL_LEN_MAX;
|
||||
|
|
Ładowanie…
Reference in New Issue