Bluetooth: Intro of basic ADV handler
Adds basic handler deserializing advertising data. Adds helper reformat function. Change-Id: I6385249c39e92b2f068a01e89d34530b7a321f34 Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
This commit is contained in:
parent
f170898634
commit
e60b8f1927
3 changed files with 55 additions and 0 deletions
|
@ -172,6 +172,8 @@ struct bt_hci_rp_le_read_local_features {
|
|||
#define BT_LE_ADV_DIRECT_IND 0x01
|
||||
#define BT_LE_ADV_SCAN_IND 0x02
|
||||
#define BT_LE_ADV_NONCONN_IND 0x03
|
||||
/* Needed in advertising reports when getting info about */
|
||||
#define BT_LE_ADV_SCAN_RSP 0x04
|
||||
|
||||
#define BT_HCI_OP_LE_SET_ADV_PARAMETERS BT_OP(BT_OGF_LE, 0x0006)
|
||||
struct bt_hci_cp_le_set_adv_parameters {
|
||||
|
@ -282,4 +284,16 @@ struct bt_hci_evt_le_conn_complete {
|
|||
uint8_t clock_accuracy;
|
||||
} PACK_STRUCT;
|
||||
|
||||
#define BT_ADDR_LE_DEV_PUBLIC 0x00
|
||||
#define BT_ADDR_LE_DEV_RANDOM 0x01
|
||||
|
||||
#define BT_HCI_EVT_LE_ADVERTISING_REPORT 0x02
|
||||
struct bt_hci_ev_le_advertising_info {
|
||||
uint8_t evt_type;
|
||||
uint8_t bdaddr_type;
|
||||
uint8_t bdaddr[6];
|
||||
uint8_t length;
|
||||
uint8_t data[0];
|
||||
} PACK_STRUCT;
|
||||
|
||||
#endif /* __BT_HCI_H */
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include <nanokernel.h>
|
||||
#include <toolchain.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <misc/byteorder.h>
|
||||
|
||||
|
@ -59,6 +60,16 @@ static char cmd_fiber_stack[CMD_STACK_SIZE];
|
|||
|
||||
static struct bt_dev dev;
|
||||
|
||||
const char *bt_bdaddr_str(const uint8_t bdaddr[6])
|
||||
{
|
||||
static char bdaddr_str[18];
|
||||
|
||||
sprintf(bdaddr_str, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
|
||||
bdaddr[5], bdaddr[4], bdaddr[3], bdaddr[2], bdaddr[1], bdaddr[0]);
|
||||
|
||||
return bdaddr_str;
|
||||
}
|
||||
|
||||
struct bt_buf *bt_hci_cmd_create(uint16_t opcode, uint8_t param_len)
|
||||
{
|
||||
struct bt_hci_cmd_hdr *hdr;
|
||||
|
@ -347,6 +358,28 @@ static void le_conn_complete(struct bt_buf *buf)
|
|||
conn->le_conn_interval = sys_le16_to_cpu(evt->interval);
|
||||
}
|
||||
|
||||
static void le_adv_report(struct bt_buf *buf)
|
||||
{
|
||||
uint8_t num_reports = buf->data[0];
|
||||
struct bt_hci_ev_le_advertising_info *info = (void *)&buf->data[1];
|
||||
|
||||
BT_DBG("Adv number of reports %u\n", num_reports);
|
||||
|
||||
while (num_reports--) {
|
||||
int8_t rssi = info->data[info->length];
|
||||
|
||||
BT_DBG("addr [%s], type:%u, event:%u, len:%u, rssi:%d dBm\n",
|
||||
bt_bdaddr_str(info->bdaddr), info->bdaddr_type,
|
||||
info->evt_type, info->length, rssi);
|
||||
|
||||
/* Get next report iteration by moving pointer to right offset
|
||||
* in buf according to spec 4.2, Vol 2, Part E, 7.7.65.2.
|
||||
*/
|
||||
info = (void *)bt_buf_pull(buf, sizeof(*info) + info->length +
|
||||
sizeof(rssi));
|
||||
}
|
||||
}
|
||||
|
||||
static void hci_le_meta_event(struct bt_buf *buf)
|
||||
{
|
||||
struct bt_hci_evt_le_meta_event *evt = (void *)buf->data;
|
||||
|
@ -357,6 +390,9 @@ static void hci_le_meta_event(struct bt_buf *buf)
|
|||
case BT_HCI_EVT_LE_CONN_COMPLETE:
|
||||
le_conn_complete(buf);
|
||||
break;
|
||||
case BT_HCI_EVT_LE_ADVERTISING_REPORT:
|
||||
le_adv_report(buf);
|
||||
break;
|
||||
default:
|
||||
BT_DBG("Unhandled LE event %x\n", evt->subevent);
|
||||
break;
|
||||
|
|
|
@ -82,3 +82,8 @@ struct bt_buf *bt_hci_cmd_create(uint16_t opcode, uint8_t param_len);
|
|||
int bt_hci_cmd_send(uint16_t opcode, struct bt_buf *buf);
|
||||
int bt_hci_cmd_send_sync(uint16_t opcode, struct bt_buf *buf,
|
||||
struct bt_buf **rsp);
|
||||
|
||||
/* The helper is only safe to be called from internal fibers as it's
|
||||
* not multi-threading safe
|
||||
*/
|
||||
const char *bt_bdaddr_str(const uint8_t bdaddr[6]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue