mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-28 08:37:22 +00:00
use getters in GAP_EVENT_ADVERTISING_REPORT
This commit is contained in:
parent
f3bf92b5f8
commit
3ee82ab15a
@ -128,11 +128,11 @@ static char * flags[] = {
|
||||
*/
|
||||
|
||||
/* LISTING_START(GAPLEAdvDataParsing): Parsing advertising data */
|
||||
static void dump_advertisement_data(uint8_t * adv_data, uint8_t adv_size){
|
||||
static void dump_advertisement_data(const uint8_t * adv_data, uint8_t adv_size){
|
||||
ad_context_t context;
|
||||
bd_addr_t address;
|
||||
uint8_t uuid_128[16];
|
||||
for (ad_iterator_init(&context, adv_size, adv_data) ; ad_iterator_has_more(&context) ; ad_iterator_next(&context)){
|
||||
for (ad_iterator_init(&context, adv_size, (uint8_t *)adv_data) ; ad_iterator_has_more(&context) ; ad_iterator_next(&context)){
|
||||
uint8_t data_type = ad_iterator_get_data_type(&context);
|
||||
uint8_t size = ad_iterator_get_data_len(&context);
|
||||
uint8_t * data = ad_iterator_get_data(&context);
|
||||
@ -242,15 +242,13 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
}
|
||||
break;
|
||||
case GAP_EVENT_ADVERTISING_REPORT:{
|
||||
int pos = 2;
|
||||
uint8_t event_type = packet[pos++];
|
||||
uint8_t address_type = packet[pos++];
|
||||
bd_addr_t address;
|
||||
reverse_bd_addr(&packet[pos], address);
|
||||
pos += 6;
|
||||
int8_t rssi = (int8_t) packet[pos++];
|
||||
uint8_t length = packet[pos++];
|
||||
uint8_t * data = &packet[pos];
|
||||
gap_event_advertising_report_get_address(packet, address);
|
||||
uint8_t event_type = gap_event_advertising_report_get_advertising_event_type(packet);
|
||||
uint8_t address_type = gap_event_advertising_report_get_address_type(packet);
|
||||
int8_t rssi = gap_event_advertising_report_get_rssi(packet);
|
||||
uint8_t length = gap_event_advertising_report_get_data_length(packet);
|
||||
const uint8_t * data = gap_event_advertising_report_get_data(packet);
|
||||
|
||||
printf("Advertisement event: evt-type %u, addr-type %u, addr %s, rssi %d, data[%u] ", event_type,
|
||||
address_type, bd_addr_to_str(address), rssi, length);
|
||||
|
@ -55,7 +55,7 @@ typedef struct advertising_report {
|
||||
bd_addr_t address;
|
||||
uint8_t rssi;
|
||||
uint8_t length;
|
||||
uint8_t * data;
|
||||
const uint8_t * data;
|
||||
} advertising_report_t;
|
||||
|
||||
|
||||
@ -190,16 +190,12 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
|
||||
}
|
||||
|
||||
static void fill_advertising_report_from_packet(advertising_report_t * report, uint8_t *packet){
|
||||
int pos = 2;
|
||||
report->event_type = packet[pos++];
|
||||
report->address_type = packet[pos++];
|
||||
reverse_bd_addr(&packet[pos], report->address);
|
||||
pos += 6;
|
||||
report->rssi = packet[pos++];
|
||||
report->length = packet[pos++];
|
||||
report->data = &packet[pos];
|
||||
pos += report->length;
|
||||
dump_advertising_report(report);
|
||||
gap_event_advertising_report_get_address(packet, report->address);
|
||||
report->event_type = gap_event_advertising_report_get_advertising_event_type(packet);
|
||||
report->address_type = gap_event_advertising_report_get_address_type(packet);
|
||||
report->rssi = gap_event_advertising_report_get_rssi(packet);
|
||||
report->length = gap_event_advertising_report_get_data_length(packet);
|
||||
report->data = gap_event_advertising_report_get_data(packet);
|
||||
}
|
||||
|
||||
static void hci_event_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||
@ -224,6 +220,8 @@ static void hci_event_handler(uint8_t packet_type, uint16_t channel, uint8_t *pa
|
||||
case GAP_EVENT_ADVERTISING_REPORT:
|
||||
if (state != TC_W4_SCAN_RESULT) return;
|
||||
fill_advertising_report_from_packet(&report, packet);
|
||||
dump_advertising_report(&report);
|
||||
|
||||
// stop scanning, and connect to the device
|
||||
state = TC_W4_CONNECT;
|
||||
gap_stop_scan();
|
||||
|
@ -65,7 +65,7 @@ typedef struct advertising_report {
|
||||
bd_addr_t address;
|
||||
uint8_t rssi;
|
||||
uint8_t length;
|
||||
uint8_t * data;
|
||||
const uint8_t * data;
|
||||
} advertising_report_t;
|
||||
|
||||
static bd_addr_t cmdline_addr = { };
|
||||
@ -144,19 +144,14 @@ static void dump_service(gatt_client_service_t * service){
|
||||
}
|
||||
|
||||
static void fill_advertising_report_from_packet(advertising_report_t * report, uint8_t *packet){
|
||||
int pos = 2;
|
||||
report->event_type = packet[pos++];
|
||||
report->address_type = packet[pos++];
|
||||
reverse_bd_addr(&packet[pos], report->address);
|
||||
pos += 6;
|
||||
report->rssi = packet[pos++];
|
||||
report->length = packet[pos++];
|
||||
report->data = &packet[pos];
|
||||
pos += report->length;
|
||||
dump_advertising_report(report);
|
||||
gap_event_advertising_report_get_address(packet, report->address);
|
||||
report->event_type = gap_event_advertising_report_get_advertising_event_type(packet);
|
||||
report->address_type = gap_event_advertising_report_get_address_type(packet);
|
||||
report->rssi = gap_event_advertising_report_get_rssi(packet);
|
||||
report->length = gap_event_advertising_report_get_data_length(packet);
|
||||
report->data = gap_event_advertising_report_get_data(packet);
|
||||
}
|
||||
|
||||
|
||||
/* @section HCI packet handler
|
||||
*
|
||||
* @text The HCI packet handler has to start the scanning,
|
||||
@ -188,6 +183,8 @@ static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *pac
|
||||
break;
|
||||
case GAP_EVENT_ADVERTISING_REPORT:
|
||||
fill_advertising_report_from_packet(&report, packet);
|
||||
dump_advertising_report(&report);
|
||||
|
||||
// stop scanning, and connect to the device
|
||||
gap_stop_scan();
|
||||
gap_connect(report.address,report.address_type);
|
||||
|
@ -55,8 +55,7 @@ static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *pac
|
||||
case GAP_EVENT_ADVERTISING_REPORT:{
|
||||
advertisement_received = 1;
|
||||
memcpy(advertisement_packet, packet, size);
|
||||
|
||||
reverse_bd_addr(&packet[4], address);
|
||||
gap_event_advertising_report_get_address(packet, address);
|
||||
gap_connect(address, (bd_addr_type_t)packet[3]);
|
||||
break;
|
||||
}
|
||||
|
@ -255,21 +255,21 @@ const char * ad_event_types[] = {
|
||||
static void handle_advertising_event(uint8_t * packet, int size){
|
||||
// filter PTS
|
||||
bd_addr_t addr;
|
||||
reverse_bd_addr(&packet[4], addr);
|
||||
|
||||
gap_event_advertising_report_get_address(packet, addr);
|
||||
uint8_t addr_type = gap_event_advertising_report_get_address_type(packet);
|
||||
// always request address resolution
|
||||
sm_address_resolution_lookup(packet[3], addr);
|
||||
sm_address_resolution_lookup(addr_type, addr);
|
||||
|
||||
// ignore advertisement from devices other than pts
|
||||
// if (memcmp(addr, current_pts_address, 6)) return;
|
||||
|
||||
printf("Advertisement: %s - %s, ", bd_addr_to_str(addr), ad_event_types[packet[2]]);
|
||||
int adv_size = packet[11];
|
||||
uint8_t * adv_data = &packet[12];
|
||||
uint8_t adv_event_type = gap_event_advertising_report_get_advertising_event_type(packet);
|
||||
printf("Advertisement: %s - %s, ", bd_addr_to_str(addr), ad_event_types[adv_event_type]);
|
||||
int adv_size = gap_event_advertising_report_get_data_length(packet);
|
||||
const uint8_t * adv_data = gap_event_advertising_report_get_data(packet);
|
||||
|
||||
// check flags
|
||||
ad_context_t context;
|
||||
for (ad_iterator_init(&context, adv_size, adv_data) ; ad_iterator_has_more(&context) ; ad_iterator_next(&context)){
|
||||
for (ad_iterator_init(&context, adv_size, (uint8_t *)adv_data) ; ad_iterator_has_more(&context) ; ad_iterator_next(&context)){
|
||||
uint8_t data_type = ad_iterator_get_data_type(&context);
|
||||
// uint8_t size = ad_iterator_get_data_len(&context);
|
||||
uint8_t * data = ad_iterator_get_data(&context);
|
||||
|
Loading…
x
Reference in New Issue
Block a user