fixed scanning (forgot flag, dueto google not sending it)

This commit is contained in:
Lurkars 2020-07-11 17:33:47 +02:00
parent aa9d39fd46
commit 7bdbe82914
5 changed files with 41 additions and 21 deletions

View File

@ -69,6 +69,12 @@ recommended
### Build and Flash
May flash partition table:
```
idf.py partition_table-flash
```
Build the project and flash it to the board, then run monitor tool to view serial output:
```

View File

@ -34,19 +34,33 @@ void ena_bluetooth_scan_event_callback(esp_gap_ble_cb_event_t event, esp_ble_gap
case ESP_GAP_BLE_SCAN_RESULT_EVT:
if (p->scan_rst.search_evt == ESP_GAP_SEARCH_INQ_RES_EVT)
{
// check for ENA Service UUID:
if (p->scan_rst.ble_adv[0] == 0x3 && p->scan_rst.ble_adv[1] == 0x3 && p->scan_rst.ble_adv[2] == 0x6f && p->scan_rst.ble_adv[3] == 0xfd)
if (p->scan_rst.adv_data_len < 28)
{
// adv_data too short for exposure notification
break;
}
int flag_offset = 0;
// received payload from Google does not contain flag specified in Bluetooth Specification!? So check for length and then add offset
if (p->scan_rst.adv_data_len == 31)
{
// data contains flag
flag_offset = 3;
}
// check for ENA Service UUID: (after flag 0x03 0x03 0x6f 0xfd for ENA service)
if (p->scan_rst.ble_adv[0 + flag_offset] == 0x3 && p->scan_rst.ble_adv[1 + flag_offset] == 0x3 && p->scan_rst.ble_adv[2 + flag_offset] == 0x6f && p->scan_rst.ble_adv[3 + flag_offset] == 0xfd)
{
uint8_t rpi[ENA_KEY_LENGTH] = {0};
for (int i = 0; i < ENA_KEY_LENGTH; i++)
{
rpi[i] = p->scan_rst.ble_adv[8 + i];
rpi[i] = p->scan_rst.ble_adv[i + 8 + flag_offset];
}
uint8_t aem[ENA_AEM_METADATA_LENGTH] = {0};
for (int i = 0; i < ENA_AEM_METADATA_LENGTH; i++)
{
aem[i] = p->scan_rst.ble_adv[8 + ENA_KEY_LENGTH + i];
aem[i] = p->scan_rst.ble_adv[i + ENA_KEY_LENGTH + 8 + flag_offset];
}
ena_detection((uint32_t)time(NULL), rpi, aem, p->scan_rst.rssi);

View File

@ -30,27 +30,26 @@ void ena_init(void)
ESP_ERROR_CHECK(nvs_flash_erase());
ESP_ERROR_CHECK(nvs_flash_init());
}
// init BLE
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_bt_controller_init(&bt_cfg));
ESP_ERROR_CHECK(esp_bt_controller_enable(ESP_BT_MODE_BLE));
ESP_ERROR_CHECK(esp_bluedroid_init());
ESP_ERROR_CHECK(esp_bluedroid_enable());
// new bluetooth address nesseccary?
uint8_t bt_address[ESP_BD_ADDR_LEN];
esp_fill_random(bt_address, ESP_BD_ADDR_LEN);
bt_address[0] |= 0xC0;
ESP_ERROR_CHECK(esp_ble_gap_set_rand_addr(bt_address));
ESP_ERROR_CHECK(esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_DEFAULT, ESP_PWR_LVL_P9));
ESP_ERROR_CHECK(esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_ADV, ESP_PWR_LVL_P9));
ESP_ERROR_CHECK(esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_SCAN, ESP_PWR_LVL_P9));
ESP_ERROR_CHECK(esp_ble_gap_config_local_privacy(true));
/* nesseccary?
// new bluetooth address
uint8_t bt_address[ESP_BD_ADDR_LEN];
esp_fill_random(bt_address, ESP_BD_ADDR_LEN);
bt_address[0] |= 0xC0;
ESP_ERROR_CHECK(esp_ble_gap_set_rand_addr(bt_address));
*/
// init ENA
ena_crypto_init();

View File

@ -31,7 +31,7 @@ void app_main(void)
settimeofday(&tv, NULL);
esp_log_level_set(ENA_STORAGE_LOG, ESP_LOG_INFO);
// ena_storage_erase();
ena_storage_erase(); // only needed on first start! TODO automatically check
ena_init();
@ -42,3 +42,4 @@ void app_main(void)
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}

View File

@ -3,4 +3,4 @@
nvs, data, nvs, 0x9000, 0x6000,
phy_init, data, phy, 0xf000, 0x1000,
factory, app, factory, 0x10000, 1M,
ena, data, nvs, 0x110000,0x2C0000,
ena, data, 0xFF, 0x110000,0x2C0000,
1 # ESP-IDF Partition Table
3 nvs, data, nvs, 0x9000, 0x6000,
4 phy_init, data, phy, 0xf000, 0x1000,
5 factory, app, factory, 0x10000, 1M,
6 ena, data, nvs, 0x110000,0x2C0000, ena, data, 0xFF, 0x110000,0x2C0000,