More work to the scanning code, with whitelist working

This commit is contained in:
Adam Greenwood-Byrne 2020-08-10 12:39:28 +01:00
parent 78c9eaa64c
commit 6f9df254a6
2 changed files with 45 additions and 33 deletions

View file

@ -218,6 +218,12 @@ void setLEadvertdata() {
if (!hciCommand(OGF_LE_CONTROL, 0x08, params, 32)) uart_writeText("setLEadvertdata failed\n"); if (!hciCommand(OGF_LE_CONTROL, 0x08, params, 32)) uart_writeText("setLEadvertdata failed\n");
} }
void setLEwhitelist() {
static unsigned char params[] = { 0x00,
0xBC, 0xF2, 0xCA, 0x32, 0xBC, 0xAC };
if (!hciCommand(OGF_LE_CONTROL, 0x11, params, 7)) uart_writeText("setLEwhitelist failed\n");
}
void stopScanning() { void stopScanning() {
setLEscanenable(0, 0); setLEscanenable(0, 0);
} }
@ -234,8 +240,11 @@ void startActiveScanning() {
unsigned int p = BleScanInterval * BleScanUnitsPerSecond; unsigned int p = BleScanInterval * BleScanUnitsPerSecond;
unsigned int q = BleScanWindow * BleScanUnitsPerSecond; unsigned int q = BleScanWindow * BleScanUnitsPerSecond;
setLEscanparameters(LL_SCAN_ACTIVE, lo(p), hi(p), lo(q), hi(q), 0, 0); setLEwhitelist();
setLEscanparameters(LL_SCAN_ACTIVE, lo(p), hi(p), lo(q), hi(q), 0, 1);
setLEscanenable(1, 0); setLEscanenable(1, 0);
wait_msec(0x100000);
} }
void startActiveAdvertising() { void startActiveAdvertising() {

View file

@ -67,42 +67,45 @@ void bt_update()
while ( (buf = poll()) ) { while ( (buf = poll()) ) {
if (data_len >= 2 && buf[0] == LE_ADREPORT_CODE) { if (data_len >= 2 && buf[0] == LE_ADREPORT_CODE) {
unsigned char numreports = buf[1]; unsigned char numreports = buf[1];
unsigned int c=0;
if (numreports > 0 && data_len >= 11) { if (numreports == 1) {
uart_writeText("\ra("); unsigned char event_type = buf[2];
for (int c=9;c>=4;c--) {
if (c != 9) uart_writeText(":");
uart_hex(buf[c]);
}
uart_writeText(")");
if (event_type == 0x00) {
unsigned char buf_len = buf[10]; unsigned char buf_len = buf[10];
unsigned char ad_len = buf[11];
if (ad_len < data_len &&
buf_len + 11 == data_len - 1) {
for (int c=9;c>=4;c--) uart_byte(buf[c]);
if ((buf_len + 11) <= data_len - 1) {
buf += 11; buf += 11;
while (c < numreports) { unsigned char rssi = buf[buf_len];
unsigned char ad_len = buf[0]; uart_writeText("-> rssi("); uart_hex(rssi); uart_writeText(")");
do {
ad_len = buf[0];
unsigned char ad_type = buf[1]; unsigned char ad_type = buf[1];
buf += 2; buf += 2;
if (ad_len > 2) { if (ad_len >= 2) {
if (ad_type == 0x09 || ad_type == 0x08) {
unsigned int d=0;
uart_writeText(" -> adtype("); uart_hex(ad_type); uart_writeText(":"); uart_hex(ad_len); uart_writeText(")"); uart_writeText(" -> adtype("); uart_hex(ad_type); uart_writeText(":"); uart_hex(ad_len); uart_writeText(")");
if (ad_type == 0x09) {
unsigned int d=0;
uart_writeText(" -> "); uart_writeText(" -> ");
while (d<ad_len - 1) { while (d<ad_len - 1) {
uart_writeByteBlockingActual(buf[d]); uart_writeByteBlockingActual(buf[d]);
d++; d++;
} }
uart_writeText("\n");
} }
} }
buf += ad_len - 1; buf += ad_len - 1;
c++; } while (buf[1]);
uart_writeText("\n");
} }
} }
} }
@ -136,15 +139,15 @@ void main()
uart_writeText("\n"); uart_writeText("\n");
// Start scanning for devices around us // Start scanning for devices around us
/*
uart_writeText("startActiveScanning()\n"); uart_writeText("startActiveScanning()\n");
setLEeventmask(0xff); setLEeventmask(0xff);
startActiveScanning(); startActiveScanning();
*/
// Get the Eddystone beacon going // Get the Eddystone beacon going
/*
uart_writeText("startActiveAdvertising()\n"); uart_writeText("startActiveAdvertising()\n");
startActiveAdvertising(); startActiveAdvertising();
*/
uart_writeText("Waiting for input...\n"); uart_writeText("Waiting for input...\n");
while (1) { while (1) {