mirror of
https://github.com/isometimes/rpi4-osdev
synced 2024-11-22 02:00:40 +00:00
More work to the scanning code, with whitelist working
This commit is contained in:
parent
78c9eaa64c
commit
6f9df254a6
2 changed files with 45 additions and 33 deletions
|
@ -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() {
|
||||||
|
|
|
@ -67,45 +67,48 @@ 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(")");
|
|
||||||
|
|
||||||
unsigned char buf_len = buf[10];
|
if (event_type == 0x00) {
|
||||||
|
unsigned char buf_len = buf[10];
|
||||||
|
unsigned char ad_len = buf[11];
|
||||||
|
|
||||||
if ((buf_len + 11) <= data_len - 1) {
|
if (ad_len < data_len &&
|
||||||
buf += 11;
|
buf_len + 11 == data_len - 1) {
|
||||||
|
for (int c=9;c>=4;c--) uart_byte(buf[c]);
|
||||||
|
|
||||||
while (c < numreports) {
|
buf += 11;
|
||||||
unsigned char ad_len = buf[0];
|
|
||||||
unsigned char ad_type = buf[1];
|
|
||||||
buf += 2;
|
|
||||||
|
|
||||||
if (ad_len > 2) {
|
unsigned char rssi = buf[buf_len];
|
||||||
if (ad_type == 0x09 || ad_type == 0x08) {
|
uart_writeText("-> rssi("); uart_hex(rssi); uart_writeText(")");
|
||||||
unsigned int d=0;
|
|
||||||
|
|
||||||
|
do {
|
||||||
|
ad_len = buf[0];
|
||||||
|
unsigned char ad_type = buf[1];
|
||||||
|
buf += 2;
|
||||||
|
|
||||||
|
if (ad_len >= 2) {
|
||||||
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(")");
|
||||||
uart_writeText(" -> ");
|
|
||||||
while (d<ad_len - 1) {
|
|
||||||
uart_writeByteBlockingActual(buf[d]);
|
|
||||||
d++;
|
|
||||||
}
|
|
||||||
uart_writeText("\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
buf += ad_len - 1;
|
if (ad_type == 0x09) {
|
||||||
c++;
|
unsigned int d=0;
|
||||||
}
|
uart_writeText(" -> ");
|
||||||
|
while (d<ad_len - 1) {
|
||||||
|
uart_writeByteBlockingActual(buf[d]);
|
||||||
|
d++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buf += ad_len - 1;
|
||||||
|
} 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) {
|
||||||
|
|
Loading…
Reference in a new issue