From 5dd11f465bb965e9c6ce9a72ca4848247e6a88e8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 1 Apr 2018 17:53:07 -0600 Subject: [PATCH] net/bluetooth: Add support for connection to any address and any channel. --- include/netpacket/bluetooth.h | 8 ++++++-- net/bluetooth/bluetooth_conn.c | 15 ++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/include/netpacket/bluetooth.h b/include/netpacket/bluetooth.h index cac7ea7f64..cdba4e0aa8 100644 --- a/include/netpacket/bluetooth.h +++ b/include/netpacket/bluetooth.h @@ -51,8 +51,12 @@ /* Well known addresses: */ -#define BDADDR_ANY {0, 0, 0, 0, 0, 0} -#define BDADDR_LOCAL {0, 0, 0, 0xff, 0xff, 0xff} +#define BT_ADDR_ANY {0, 0, 0, 0, 0, 0} +#define BT_ADDR_LOCAL {0, 0, 0, 0xff, 0xff, 0xff} + +/* Any channel */ + +#define BT_CHANNEL_ANY 0 /* Socket protocols. * diff --git a/net/bluetooth/bluetooth_conn.c b/net/bluetooth/bluetooth_conn.c index 20a091e4d7..ec6c9fbbc4 100644 --- a/net/bluetooth/bluetooth_conn.c +++ b/net/bluetooth/bluetooth_conn.c @@ -43,6 +43,7 @@ #include #include +#include #include #include @@ -75,6 +76,11 @@ static dq_queue_t g_free_bluetooth_connections; static dq_queue_t g_active_bluetooth_connections; +static const bt_addr_t g_any_addr = +{ + BT_ADDR_ANY +}; + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -218,12 +224,11 @@ FAR struct bluetooth_conn_s * conn = (FAR struct bluetooth_conn_s *)conn->bc_node.flink) { /* Does the destination address match the bound address of the socket. */ - /* REVISIT: Currently and explicit address must be assigned. Should we - * support some moral equivalent to INADDR_ANY? - */ - if (!BLUETOOTH_ADDRCMP(&meta->bm_raddr, &conn->bc_laddr) || - meta->bm_channel != conn->bc_channel) + if ((BLUETOOTH_ADDRCMP(&conn->bc_raddr, &meta->bm_raddr) || + BLUETOOTH_ADDRCMP(&conn->bc_raddr, &g_any_addr)) && + (meta->bm_channel == conn->bc_channel || + BT_CHANNEL_ANY == conn->bc_channel)) { continue; }