diff --git a/epicardium/ble/ble_main.c b/epicardium/ble/ble_main.c index 89af35a38e36092558d5bebc84a77c13e507fee6..fc8336dac1b1d79f77f1c44c2cd505e94cc5d2c3 100644 --- a/epicardium/ble/ble_main.c +++ b/epicardium/ble/ble_main.c @@ -188,6 +188,15 @@ static const uint8_t bleAdvDataConn[] = DM_FLAG_LE_BREDR_NOT_SUP, }; +static const appMasterCfg_t scannerMasterCfg = +{ + 420, /*! The scan interval, in 0.625 ms units */ + 420, /*! The scan window, in 0.625 ms units */ + 0, /*! The scan duration in ms */ + DM_DISC_MODE_NONE, /*! The GAP discovery mode */ + DM_SCAN_TYPE_PASSIVE + /*!< The scan type (active or passive) */ +}; /************************************************************************************************** Client Characteristic Configuration Descriptors @@ -470,9 +479,13 @@ static void bleSetup(bleMsg_t *pMsg) AppAdvSetData(APP_ADV_DATA_CONNECTABLE, sizeof(bleAdvDataConn), (uint8_t *) bleAdvDataConn); AppAdvSetData(APP_SCAN_DATA_CONNECTABLE, 0, NULL); - active = true; + //active = true; /* TODO: Sadly, not advertising leads to a higher current consumption... */ epic_ble_set_bondable(false); + + //AppScanStart(scannerMasterCfg.discMode, scannerMasterCfg.scanType, scannerMasterCfg.scanDuration); + DmScanSetInterval(HCI_SCAN_PHY_LE_1M_BIT, &pAppMasterCfg->scanInterval, &pAppMasterCfg->scanWindow); + DmScanStart(HCI_SCAN_PHY_LE_1M_BIT, scannerMasterCfg.discMode, &scannerMasterCfg.scanType, FALSE, scannerMasterCfg.scanDuration, 0); } void epic_ble_set_bondable(bool bondable) @@ -576,6 +589,46 @@ static void bleHandleNumericComparison(dmSecCnfIndEvt_t *pCnfInd) trigger_event(1); } +static void hexdump(uint8_t *data, int len) +{ + while(len--) printf("%02x ", *data++); +} + +static void scannerScanReport(dmEvt_t *pMsg) +{ + uint8_t *pData; + static bool c; + pData = DmFindAdType(0x16, + pMsg->scanReport.len, pMsg->scanReport.pData); + if(pData) { + uint8_t len= pData[0]; + uint8_t uuid_1 = pData[2]; + uint8_t uuid_2 = pData[3]; + if(uuid_1 == 0x6f && uuid_2 == 0xfd) { + printf("COVID : %02x:%02x:%02x:%02x:%02x:%02x", + pMsg->scanReport.addr[5], + pMsg->scanReport.addr[4], + pMsg->scanReport.addr[3], + pMsg->scanReport.addr[2], + pMsg->scanReport.addr[1], + pMsg->scanReport.addr[0]); + + printf(" rssi %d, data ", pMsg->scanReport.rssi); + hexdump(&pData[4], len - 4); + printf("\n"); + epic_vibra_vibrate(30); + if(c) { + epic_leds_set(14, 255, 0, 0); + c = false; + } else { + epic_leds_set(14, 0, 255, 0); + c = true; + } + } + } +} + + /*************************************************************************************************/ /*! * \brief Process messages from the event handler. @@ -720,6 +773,10 @@ static void bleProcMsg(bleMsg_t *pMsg) bleHandleNumericComparison(&pMsg->dm.cnfInd); break; + case DM_SCAN_REPORT_IND: + scannerScanReport((dmEvt_t *)pMsg); + break; + case DM_HW_ERROR_IND: LOG_ERR("ble", "HW Error"); break; @@ -750,6 +807,7 @@ static void BleHandlerInit(void) pAppSlaveCfg = (appSlaveCfg_t *) &bleSlaveCfg; pAppSecCfg = (appSecCfg_t *) &bleSecCfg; pAppUpdateCfg = (appUpdateCfg_t *) &bleUpdateCfg; + pAppMasterCfg = (appMasterCfg_t *) &scannerMasterCfg; /* Initialize application framework */ AppSlaveInit(); @@ -780,7 +838,7 @@ static void BleHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg) if (pMsg->event >= DM_CBACK_START && pMsg->event <= DM_CBACK_END) { - LOG_INFO("ble", "Ble got evt %d: %s", pMsg->event, dm_events[pMsg->event - DM_CBACK_START]); + if(pMsg->event != DM_SCAN_REPORT_IND) LOG_INFO("ble", "Ble got evt %d: %s", pMsg->event, dm_events[pMsg->event - DM_CBACK_START]); /* process advertising and connection-related messages */ AppSlaveProcDmMsg((dmEvt_t *) pMsg); diff --git a/epicardium/ble/stack.c b/epicardium/ble/stack.c index a7896b68fa7c35a9d85a173b67d495ae95204e8d..3d24b0c5957b2df1195cbf22638c0db90560ac82 100644 --- a/epicardium/ble/stack.c +++ b/epicardium/ble/stack.c @@ -130,11 +130,7 @@ void StackInit(void) .freeMemAvail = LL_MEMORY_FOOTPRINT }; -#ifdef DATS_APP_USE_LEGACY_API memUsed = LlInitControllerExtInit(&ll_init_cfg); -#else /* DATS_APP_USE_LEGACY_API */ - memUsed = LlInitControllerExtInit(&ll_init_cfg); -#endif /* DATS_APP_USE_LEGACY_API */ if(memUsed != LL_MEMORY_FOOTPRINT) { printf("Controller memory mismatch 0x%x != 0x%x\n", (unsigned int)memUsed, @@ -142,6 +138,11 @@ void StackInit(void) } #endif + SecInit(); + SecRandInit(); + SecAesInit(); + SecCmacInit(); + SecEccInit(); /* card10: * These calls register a queue for callbacks in the OS abstraction @@ -153,14 +154,10 @@ void StackInit(void) handlerId = WsfOsSetNextHandler(HciHandler); HciHandlerInit(handlerId); - SecInit(); - SecAesInit(); - SecCmacInit(); - SecEccInit(); - handlerId = WsfOsSetNextHandler(DmHandler); DmDevVsInit(0); DmAdvInit(); + DmScanInit(); DmConnInit(); DmConnSlaveInit(); DmSecInit(); diff --git a/lib/sdk/Libraries/BTLE/meson.build b/lib/sdk/Libraries/BTLE/meson.build index 6dd10ee6a04dc62c8036da9681b739fa64ecf328..0f301cf1823469e2434d214d88ddf964423216c1 100644 --- a/lib/sdk/Libraries/BTLE/meson.build +++ b/lib/sdk/Libraries/BTLE/meson.build @@ -421,6 +421,7 @@ ble_compileargs = [ '-DINIT_BROADCASTER', '-DINIT_PERIPHERAL', '-DINIT_ENCRYPTED', + '-DINIT_OBSERVER', ] if get_option('ble_trace') diff --git a/lib/sdk/Libraries/BTLE/stack/ble-profiles/sources/apps/app/app_master_leg.c b/lib/sdk/Libraries/BTLE/stack/ble-profiles/sources/apps/app/app_master_leg.c index 6a56651a72e1e242f452bf7466d8b513ff9be1ca..91613609e535560dd4c43525779be84d64b65231 100644 --- a/lib/sdk/Libraries/BTLE/stack/ble-profiles/sources/apps/app/app_master_leg.c +++ b/lib/sdk/Libraries/BTLE/stack/ble-profiles/sources/apps/app/app_master_leg.c @@ -73,7 +73,7 @@ void AppScanStart(uint8_t mode, uint8_t scanType, uint16_t duration) { DmScanSetInterval(HCI_SCAN_PHY_LE_1M_BIT, &pAppMasterCfg->scanInterval, &pAppMasterCfg->scanWindow); - DmScanStart(HCI_SCAN_PHY_LE_1M_BIT, mode, &scanType, TRUE, duration, 0); + DmScanStart(HCI_SCAN_PHY_LE_1M_BIT, mode, &scanType, FALSE, duration, 0); } }