From 4520fc67a58f121fd44fd33c88733ef0a32df07d Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Mon, 13 Sep 2021 21:59:11 +0200 Subject: [PATCH] pkg/nimble/scanlist: adapt to scanner changes --- pkg/nimble/scanlist/include/nimble_scanlist.h | 8 ++++-- pkg/nimble/scanlist/nimble_scanlist.c | 7 ++++-- pkg/nimble/scanlist/nimble_scanlist_print.c | 25 ++++++++++++++++++- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/pkg/nimble/scanlist/include/nimble_scanlist.h b/pkg/nimble/scanlist/include/nimble_scanlist.h index 9ff872f615..bc80cd072d 100644 --- a/pkg/nimble/scanlist/include/nimble_scanlist.h +++ b/pkg/nimble/scanlist/include/nimble_scanlist.h @@ -28,6 +28,7 @@ #include "clist.h" #include "net/ble.h" #include "nimble/ble.h" +#include "nimble_scanner.h" #ifdef __cplusplus extern "C" { @@ -53,6 +54,8 @@ typedef struct { uint32_t first_update; /**< first packet timestamp */ uint32_t last_update; /**< last packet timestamp */ uint8_t type; /**< advertising packet type */ + uint8_t phy_pri; /**< primary PHY used */ + uint8_t phy_sec; /**< secondary PHY advertised */ } nimble_scanlist_entry_t; /** @@ -67,11 +70,12 @@ void nimble_scanlist_init(void); * * @param[in] type type of the advertising packet received * @param[in] addr BLE address of the scanned node - * @param[in] rssi RSSI of the received advertising packet + * @param[in] info Additional information on received advertising event * @param[in] ad the payload of the advertising packet * @param[in] len length of @p ad */ -void nimble_scanlist_update(uint8_t type, const ble_addr_t *addr, int8_t rssi, +void nimble_scanlist_update(uint8_t type, const ble_addr_t *addr, + const nimble_scanner_info_t *info, const uint8_t *ad, size_t len); /** diff --git a/pkg/nimble/scanlist/nimble_scanlist.c b/pkg/nimble/scanlist/nimble_scanlist.c index 2e1bc8214f..e8674ecb44 100644 --- a/pkg/nimble/scanlist/nimble_scanlist.c +++ b/pkg/nimble/scanlist/nimble_scanlist.c @@ -66,7 +66,8 @@ nimble_scanlist_entry_t *nimble_scanlist_get_by_pos(unsigned pos) return e; } -void nimble_scanlist_update(uint8_t type, const ble_addr_t *addr, int8_t rssi, +void nimble_scanlist_update(uint8_t type, const ble_addr_t *addr, + const nimble_scanner_info_t *info, const uint8_t *ad, size_t len) { assert(addr); @@ -86,10 +87,12 @@ void nimble_scanlist_update(uint8_t type, const ble_addr_t *addr, int8_t rssi, memcpy(e->ad, ad, len); } e->ad_len = len; - e->last_rssi = rssi; + e->last_rssi = info->rssi; e->first_update = now; e->adv_msg_cnt = 1; e->type = type; + e->phy_pri = info->phy_pri; + e->phy_sec = info->phy_sec; clist_rpush(&_list, (clist_node_t *)e); } else { diff --git a/pkg/nimble/scanlist/nimble_scanlist_print.c b/pkg/nimble/scanlist/nimble_scanlist_print.c index 090f693999..8f9579fdb0 100644 --- a/pkg/nimble/scanlist/nimble_scanlist_print.c +++ b/pkg/nimble/scanlist/nimble_scanlist_print.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Freie Universität Berlin + * Copyright (C) 2019-2021 Freie Universität Berlin * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level @@ -27,8 +27,30 @@ #include "nimble_scanlist.h" #include "nimble/hci_common.h" +static const char *_phys[] = { "N/A", "1M", "2M", "CODED" }; + static void _print_type(uint8_t type) { +#if MYNEWT_VAL_BLE_EXT_ADV + if (type & NIMBLE_SCANNER_EXT_ADV) { + printf(" [EXT"); + if (type & BLE_HCI_ADV_CONN_MASK) { + printf("-CONN"); + } + if (type & BLE_HCI_ADV_SCAN_MASK) { + printf("-SCAN"); + } + if (type & BLE_HCI_ADV_DIRECT_MASK) { + printf("-DIR"); + } + if (type & BLE_HCI_ADV_SCAN_RSP_MASK) { + printf("-SCANRSP"); + } + printf("]"); + return; + } +#endif + switch (type) { case BLE_HCI_ADV_RPT_EVTYPE_ADV_IND: printf(" [IND]"); @@ -80,6 +102,7 @@ void nimble_scanlist_print_entry(nimble_scanlist_entry_t *e) nimble_addr_print(&e->addr); _print_type(e->type); + printf(" phy:%s-%s", _phys[e->phy_pri], _phys[e->phy_sec]); unsigned adv_int = ((e->last_update - e->first_update) / e->adv_msg_cnt); printf(" \"%s\", adv_msg_cnt: %u, adv_int: %uus, last_rssi: %i\n", name, (unsigned)e->adv_msg_cnt, adv_int, (int)e->last_rssi);