This comment adds (1) basic support for AF_BLUETOOTH sockets. The logic compiles but is still incomplete. Support for Bluetooth is general is still dependent on CONFIG_EXPERMIMENTAL because it is not yet ready for used.

Squashed commit of the following:

    wireless/bluetooth:  Some small changes that gets to a clean compile by just eliminating some incorrect implementations (still with a lot of warnings.  The logic is still incomplete but now not so lethal.
    wireless/bluetooth:  Restructuring:  Connection interfaces should internal to wireless/bluetooth.  include/nuttx/wireless/bt_conn.h removed and merged with wireless/bluetooth/bt_conn.h.  Several fix to get closer to bt_netdev.c compiling.  Need to design some not interfaces and use some existing interfaces to send and receiv packets.
    wireless/bluetooth: Some organization with some network device compile errors fixed.  Still not even close to compiling.
    net/bluetooth:  Fix numerous compile issues; Still open design issues with regard to the interface with the Bluetooth stack.
    wireless/bluetooth:  Create bt_netdev.c with a crude copy of mac802154_netdev.c.  Does not not even compile yet.
    include/nuttx/net:  Add bluetooth.h.  Content is not yet correct.
    net/netpackets:  Add bluetooth.h.  Update net/bluetooth to use new socket address definition.
    net/bluetooth:  Some fixes for initial build.
    net/bluetooth:  Add initial support for Bluetooth sockets.  The initial cut is just the a clone of the IEEE 802.15.4 socket support with name changes.
    net/ieee802154:  Fix some typos noted when cloning to create net/bluetooth.
This commit is contained in:
Gregory Nutt
2018-03-31 14:55:03 -06:00
parent fd068f17ca
commit 0c007be4bd
43 changed files with 5843 additions and 617 deletions
+2 -1
View File
@@ -38,7 +38,8 @@ ifeq ($(CONFIG_WIRELESS_BLUETOOTH),y)
# Include Bluetooth support
CSRCS += bt_atomic.c bt_att.c bt_buf.c bt_conn.c bt_gatt.c bt_hcicore.c
CSRCS += bt_ioctl.c bt_keys.c bt_l2cap.c bt_queue.c bt_smp.c bt_uuid.c
CSRCS += bt_ioctl.c bt_keys.c bt_l2cap.c bt_netdev.c bt_queue.c bt_smp.c
CSRCS += bt_uuid.c
DEPPATH += --dep-path bluetooth
VPATH += :bluetooth
File diff suppressed because it is too large Load Diff
+281 -20
View File
@@ -50,8 +50,6 @@
#include <mqueue.h>
#include <nuttx/wireless/bt_conn.h>
#include "bt_atomic.h"
/****************************************************************************
@@ -116,39 +114,302 @@ struct bt_conn_s
* Public Data
****************************************************************************/
/* Process incoming data for a connection */
/****************************************************************************
* Name: bt_conn_input
*
* Description:
* Receive packets from the HCI core on a registered connection.
*
* Input Parameters:
* conn - The registered connection
* buf - The buffer structure containing the received packet
* flags - Packet boundary flags
*
* Returned Value:
* None
*
****************************************************************************/
void bt_conn_recv(FAR struct bt_conn_s *conn, FAR struct bt_buf_s *buf,
uint8_t flags);
void bt_conn_input(FAR struct bt_conn_s *conn, FAR struct bt_buf_s *buf,
uint8_t flags);
/* Send data over a connection */
/****************************************************************************
* Name: bt_conn_send
*
* Description:
* Send data over a connection
*
* Input Parameters:
* conn - The registered connection
* buf - The buffer structure containing the packet to be sent
*
* Returned Value:
* None
*
****************************************************************************/
void bt_conn_send(FAR struct bt_conn_s *conn, FAR struct bt_buf_s *buf);
/* Add a new connection */
/****************************************************************************
* Name: bt_conn_add
*
* Description:
* Add a new connection
*
* Input Parameters:
* peer - The address of the Bluetooth peer
* role - Either BT_HCI_ROLE_MASTER or BT_HCI_ROLE_SLAVE
*
* Returned Value:
* A reference to the new connection structure is returned on success.
*
****************************************************************************/
FAR struct bt_conn_s *bt_conn_add(FAR const bt_addr_le_t *peer, uint8_t role);
/* Look up an existing connection */
FAR struct bt_conn_s *bt_conn_lookup_handle(uint16_t handle);
/* Look up a connection state. For BT_ADDR_LE_ANY, returns the first connection
* with the specific state
*/
FAR struct bt_conn_s *bt_conn_lookup_state(FAR const bt_addr_le_t * peer,
enum bt_conn_state_e state);
/* Set connection object in certain state and perform action related to state */
/****************************************************************************
* Name: bt_conn_set_state
*
* Description:
* Set connection object in certain state and perform actions related to
* state change.
*
* Input Parameters:
* conn - The connection whose state will be changed.
* state - The new state of the connection.
*
* Returned Value:
* None
*
****************************************************************************/
void bt_conn_set_state(FAR struct bt_conn_s *conn, enum bt_conn_state_e state);
/* rand and ediv should be in BT order */
/****************************************************************************
* Name: bt_conn_lookup_handle
*
* Description:
* Look up an existing connection
*
* Input Parameters:
* handle - The handle to be used to perform the lookup
*
* Returned Value:
* A reference to the connection state instance is returned on success.
* NULL is returned if the connection is not found. On succes, the
* caller gets a new reference to the connection object which must be
* released with bt_conn_release() once done using the connection.
*
****************************************************************************/
FAR struct bt_conn_s *bt_conn_lookup_handle(uint16_t handle);
/****************************************************************************
* Name: bt_conn_lookup_addr_le
*
* Description:
* Look up an existing connection based on the remote address.
*
* Input Parameters:
* peer - Remote address.
*
* Returned Value:
* A reference to the connection state instance is returned on success.
* NULL is returned if the connection is not found. On succes, the
* caller gets a new reference to the connection object which must be
* released with bt_conn_release() once done using the connection.
*
****************************************************************************/
FAR struct bt_conn_s *bt_conn_lookup_addr_le(const bt_addr_le_t *peer);
/****************************************************************************
* Name: bt_conn_lookup_state
*
* Description:
* Look up a connection state. For BT_ADDR_LE_ANY, returns the first
* connection with the specific state
*
* Input Parameters:
* peer - The peer address to match
* state - The connection state to match
*
* Returned Value:
* A reference to the connection state instance is returned on success.
* NULL is returned if the connection is not found. On succes, the
* caller gets a new reference to the connection object which must be
* released with bt_conn_release() once done using the connection.
*
****************************************************************************/
FAR struct bt_conn_s *bt_conn_lookup_state(FAR const bt_addr_le_t *peer,
enum bt_conn_state_e state);
/****************************************************************************
* Name: bt_conn_addref
*
* Description:
* Increment the reference count of a connection object.
*
* Input Parameters:
* conn - Connection object.
*
* Returned Value:
* Connection object with incremented reference count.
*
****************************************************************************/
FAR struct bt_conn_s *bt_conn_addref(FAR struct bt_conn_s *conn);
/****************************************************************************
* Name: bt_conn_release
*
* Description:
* Decrement the reference count of a connection object.
*
* Input Parameters:
* conn - Connection object.
*
* Returned Value:
* None
*
****************************************************************************/
void bt_conn_release(FAR struct bt_conn_s *conn);
/****************************************************************************
* Name: bt_conn_get_dst
*
* Description:
* Get destination (peer) address of a connection.
*
* Input Parameters:
* conn - Connection object.
*
* Returned Value:
* Destination address.
*
****************************************************************************/
FAR const bt_addr_le_t *bt_conn_get_dst(FAR const struct bt_conn_s *conn);
/****************************************************************************
* Name: bt_conn_security
*
* Description:
* This function enable security (encryption) for a connection. If device is
* already paired with sufficiently strong key encryption will be enabled. If
* link is already encrypted with sufficiently strong key this function does
* nothing.
*
* If device is not paired pairing will be initiated. If device is paired and
* keys are too weak but input output capabilities allow for strong enough keys
* pairing will be initiated.
*
* This function may return error if required level of security is not possible
* to achieve due to local or remote device limitation (eg input output
* capabilities).
*
* Input Parameters:
* conn - Connection object.
* sec - Requested security level.
*
* Returned Value:
* 0 on success or negative error
*
****************************************************************************/
int bt_conn_security(FAR struct bt_conn_s *conn, enum bt_security_e sec);
/****************************************************************************
* Name:bt_conn_set_auto_conn
*
* Description:
* This function enables/disables automatic connection initiation.
* Every time the device looses the connection with peer, this connection
* will be re-established if connectible advertisement from peer is
* received.
*
* Input Parameters:
* conn - Existing connection object.
* auto_conn - boolean value. If true, auto connect is enabled, if false,
* auto connect is disabled.
*
* Returned Value:
* None
*
****************************************************************************/
void bt_conn_set_auto_conn(FAR struct bt_conn_s *conn, bool auto_conn);
/****************************************************************************
* Name: bt_conn_disconnect
*
* Description:
* Disconnect an active connection with the specified reason code or cancel
* pending outgoing connection.
*
* Input Parameters:
* conn - Connection to disconnect.
* reason - Reason code for the disconnection.
*
* Returned Value:
* Zero on success or (negative) error code on failure.
*
****************************************************************************/
int bt_conn_disconnect(FAR struct bt_conn_s *conn, uint8_t reason);
/****************************************************************************
* Name: bt_conn_create_le
*
* Description:
* Allows initiate new LE link to remote peer using its address.
* Returns a new reference that the the caller is responsible for managing.
*
* Input Parameters:
* peer - Remote address.
*
* Returned Value:
* Valid connection object on success or NULL otherwise.
*
****************************************************************************/
FAR struct bt_conn_s *bt_conn_create_le(FAR const bt_addr_le_t *peer);
/****************************************************************************
* Name: bt_conn_le_start_encryption
*
* Description:
* See the HCI start encryption command.
*
* NOTE: rand and ediv should be in BT order.
*
* Input Parameters:
* conn - The connection to send the command on.
* rand, ediv - Values to use for the encryption key
* ltk -
*
* Returned Value:
* Zero is returned on success; a negated errno value is returned on any
* failure.
*
****************************************************************************/
int bt_conn_le_start_encryption(FAR struct bt_conn_s *conn, uint64_t rand,
uint16_t ediv, FAR const uint8_t *ltk);
/****************************************************************************
* Name:
*
* Description:
*
* Input Parameters:
*
* Returned Value:
*
****************************************************************************/
int bt_conn_le_conn_update(FAR struct bt_conn_s *conn, uint16_t min,
uint16_t max, uint16_t latency,
uint16_t timeout);
+3 -3
View File
@@ -436,7 +436,7 @@ static uint8_t notify_cb(FAR const struct bt_gatt_attr_s *attr,
if (!buf)
{
wlwarn("No buffer available to send notification");
bt_conn_put(conn);
bt_conn_release(conn);
return BT_GATT_ITER_STOP;
}
@@ -449,7 +449,7 @@ static uint8_t notify_cb(FAR const struct bt_gatt_attr_s *attr,
memcpy(nfy->value, data->data, data->len);
bt_l2cap_send(conn, BT_L2CAP_CID_ATT, buf);
bt_conn_put(conn);
bt_conn_release(conn);
}
return BT_GATT_ITER_CONTINUE;
@@ -555,7 +555,7 @@ static uint8_t disconnected_cb(FAR const struct bt_gatt_attr_s *attr,
tmp = bt_conn_lookup_addr_le(&ccc->cfg[i].peer);
if (tmp && tmp->state == BT_CONN_CONNECTED)
{
bt_conn_put(tmp);
bt_conn_release(tmp);
return BT_GATT_ITER_CONTINUE;
}
}
File diff suppressed because it is too large Load Diff
+72 -2
View File
@@ -1,5 +1,5 @@
/****************************************************************************
* wireless/bluetooth/bt_att.c
* wireless/bluetooth/bt_hdicore.h
* HCI core Bluetooth handling.
*
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
@@ -139,6 +139,16 @@ struct bt_dev_s
FAR const struct bt_driver_s *dev;
};
/* Connection callback structure */
struct bt_conn_s; /* Forward reference */
struct bt_conn_cb_s
{
CODE void (*connected)(FAR struct bt_conn_s *conn);
CODE void (*disconnected)(FAR struct bt_conn_s *conn);
FAR struct bt_conn_cb_s *next;
};
/****************************************************************************
* Name: bt_le_scan_cb_t
*
@@ -227,11 +237,40 @@ static inline bool bt_addr_le_is_identity(FAR const bt_addr_le_t *addr)
* Public Function Prototypes
****************************************************************************/
struct bt_eir_s; /* Forward reference */
/****************************************************************************
* Name: bt_initialize
*
* Description:
* Initialize Bluetooth. Must be the called before anything else.
*
* Returned Value:
* Zero on success or (negative) error code otherwise.
*
****************************************************************************/
int bt_initialize(void);
/****************************************************************************
* Name: bt_hci_cmd_create
*
* Description:
* Allocate and initialize a buffer for a command
*
* Returned Value:
* A reference to the allocated buffer. NULL could possibly be returned
* on any failure to allocate.
*
****************************************************************************/
FAR struct bt_buf_s *bt_hci_cmd_create(uint16_t opcode, uint8_t param_len);
/* Send HCI commands */
int bt_hci_cmd_send(uint16_t opcode, FAR struct bt_buf_s *buf);
int bt_hci_cmd_send_sync(uint16_t opcode, FAR struct bt_buf_s *buf,
FAR struct bt_buf_s **rsp);
int bt_le_scan_update(void);
/* The helper is only safe to be called from internal kernel threads as it's
* not multi-threading safe
@@ -308,4 +347,35 @@ int bt_start_scanning(uint8_t filter_dups, bt_le_scan_cb_t cb);
int bt_stop_scanning(void);
/****************************************************************************
* Name: bt_le_scan_update
*
* Description:
* Used to determine whether to start scan and which scan type should be
* used.
*
* Returned Value:
* Zero on success or error code otherwise, positive in case
* of protocol error or negative (POSIX) in case of stack internal error
*
****************************************************************************/
int bt_le_scan_update(void);
/****************************************************************************
* Name: bt_conn_cb_register
*
* Description:
* Register callbacks to monitor the state of connections.
*
* Input Parameters:
* cb - Instance of the callback structure.
*
* Returned Value:
* None
*
****************************************************************************/
void bt_conn_cb_register(FAR struct bt_conn_cb_s *cb);
#endif /* __WIRELESS_BLUETOOTH_BT_HDICORE_H */
+12 -12
View File
@@ -62,7 +62,7 @@
/* This structure encapsulates all globals used by the IOCTL logic */
struct bt_scanstate_s
struct btnet_scanstate_s
{
sem_t bs_exclsem; /* Manages exclusive access */
bool bs_scanning; /* True: Scanning in progress */
@@ -80,14 +80,14 @@ struct bt_scanstate_s
* maintain the scan state as a global.
*/
static struct bt_scanstate_s g_scanstate;
static struct btnet_scanstate_s g_scanstate;
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: bt_scan_callback
* Name: btnet_scan_callback
*
* Description:
* This is an HCI callback function. HCI provides scan result data via
@@ -102,9 +102,9 @@ static struct bt_scanstate_s g_scanstate;
*
****************************************************************************/
static void bt_scan_callback(FAR const bt_addr_le_t *addr, int8_t rssi,
uint8_t adv_type, FAR const uint8_t *adv_data,
uint8_t len)
static void btnet_scan_callback(FAR const bt_addr_le_t *addr, int8_t rssi,
uint8_t adv_type, FAR const uint8_t *adv_data,
uint8_t len)
{
FAR struct bt_scanresponse_s *rsp;
uint8_t nexttail;
@@ -174,7 +174,7 @@ static void bt_scan_callback(FAR const bt_addr_le_t *addr, int8_t rssi,
}
/****************************************************************************
* Name: bt_scan_result
* Name: btnet_scan_result
*
* Description:
* This is an HCI callback function. HCI provides scan result data via
@@ -189,7 +189,7 @@ static void bt_scan_callback(FAR const bt_addr_le_t *addr, int8_t rssi,
*
****************************************************************************/
static int bt_scan_result(FAR struct bt_scanresult_s *result)
static int btnet_scan_result(FAR struct bt_scanresult_s *result)
{
uint8_t head;
uint8_t tail;
@@ -248,7 +248,7 @@ static int bt_scan_result(FAR struct bt_scanresult_s *result)
****************************************************************************/
/****************************************************************************
* Name: bt_ioctl
* Name: btnet_ioctl
*
* Description:
* Handle network IOCTL commands directed to this device.
@@ -263,7 +263,7 @@ static int bt_scan_result(FAR struct bt_scanresult_s *result)
*
****************************************************************************/
int bt_ioctl(FAR struct net_driver_s *dev, int cmd, unsigned long arg)
int btnet_ioctl(FAR struct net_driver_s *dev, int cmd, unsigned long arg)
{
int ret;
@@ -338,7 +338,7 @@ int bt_ioctl(FAR struct net_driver_s *dev, int cmd, unsigned long arg)
g_scanstate.bs_head = 0;
g_scanstate.bs_tail = 0;
ret = bt_start_scanning(dup_enable, bt_scan_callback);
ret = bt_start_scanning(dup_enable, btnet_scan_callback);
wlinfo("Start scan: %d\n", ret);
if (ret < 0)
@@ -370,7 +370,7 @@ int bt_ioctl(FAR struct net_driver_s *dev, int cmd, unsigned long arg)
}
else
{
ret = bt_scan_result(result);
ret = btnet_scan_result(result);
wlinfo("Get scan results: %d\n", ret);
}
}
+2 -2
View File
@@ -52,7 +52,7 @@
****************************************************************************/
/****************************************************************************
* Name: bt_ioctl
* Name: btnet_ioctl
*
* Description:
* Handle network IOCTL commands directed to this device.
@@ -68,6 +68,6 @@
****************************************************************************/
struct net_driver_s; /* Forward reference */
int bt_ioctl(FAR struct net_driver_s *dev, int cmd, unsigned long arg);
int btnet_ioctl(FAR struct net_driver_s *dev, int cmd, unsigned long arg);
#endif /* __WIRELESS_BLUETOOTH_BT_IOCTL_H */
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -48,7 +48,7 @@
#include <nuttx/config.h>
#include <nuttx/wireless/bt_conn.h>
#include "bt_conn.h"
/****************************************************************************
* Pre-processor Definitions