mirror of
https://github.com/apache/nuttx.git
synced 2026-05-20 12:33:27 +08:00
Bluetooth: Bring in some definitions from NetBSD. Update some usage and naming to be more consistent.
This commit is contained in:
@@ -49,7 +49,140 @@
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Well known addresses */
|
||||
/* Well known addresses: */
|
||||
|
||||
#define BDADDR_ANY {0, 0, 0, 0, 0, 0}
|
||||
#define BDADDR_LOCAL {0, 0, 0, 0xff, 0xff, 0xff}
|
||||
|
||||
/* Socket protocols.
|
||||
*
|
||||
* All Bluetooth sockets should select address family = AF_BLUETOOTH and
|
||||
* type = SOCK_RAW. Protocol options are listed here (from NetBSD):
|
||||
*
|
||||
* BTPROTO_HCI
|
||||
* This gives raw access to the Host Controller Interface of local devices
|
||||
* using the HCI protocol as described in the Bluetooth Core Specification.
|
||||
* The local address specified by bind() may be used to select the device
|
||||
* that the socket will receive packets from. If BDADDR_ANY is specified
|
||||
* then the socket will receive packets from all devices on the system.
|
||||
* connect() may be used to create connections such that packets sent with
|
||||
* send() will be delivered to the specified device, otherwise sendto()
|
||||
* should be used.
|
||||
* BTPROTO_L2CAP
|
||||
* L2CAP sockets give sequential packet access over channels to other
|
||||
* Bluetooth devices and make use of the bt_psm field in the sockaddr_bt_s
|
||||
* structure to select the Protocol/Sevice Multiplexer to specify when
|
||||
* making connections. If the special value of L2CAP_PSM_ANY is bound
|
||||
* when the listen() call is made, the next available PSM from the
|
||||
* dynamic range above 0x1001 will be selected and may be discovered
|
||||
* using the getsockname() call.
|
||||
* BTPROTO_RFCOMM
|
||||
* RFCOMM sockets provide streamed data over Bluetooth connection and
|
||||
* make use of the bt_psm, and bt_channel fields in the sockaddr_bt_s
|
||||
* structure. The channel number must be between 1 and 30 inclusive
|
||||
* except that if the special value RFCOMM_CHANNEL_ANY is bound, when
|
||||
* the listen() call is made, the first unused channel for the relevant
|
||||
* bdaddr will be allocated and may be discovered using the
|
||||
* getsockname(2) call. If no PSM is specified, a default value of
|
||||
* L2CAP_PSM_RFCOMM (0x0003) will be used.
|
||||
*
|
||||
* NOTE: All protocol values currently ignored. Only BTPROTO_L2CAP is
|
||||
* supported by default.
|
||||
*/
|
||||
|
||||
#define BTPROTO_L2CAP 0
|
||||
#define BTPROTO_HCI 1
|
||||
#define BTPROTO_SCO 2
|
||||
#define BTPROTO_RFCOMM 3
|
||||
#define BTPROTO_BNEP 4
|
||||
#define BTPROTO_CMTP 5
|
||||
#define BTPROTO_HIDP 6
|
||||
#define BTPROTO_AVDTP 7
|
||||
|
||||
/* HCI socket options:
|
||||
*
|
||||
* SO_HCI_EVT_FILTER
|
||||
* Controls which events will be received at the socket. By default,
|
||||
* Command_Complete and Command_Status events only are enabled.
|
||||
* SO_HCI_PKT_FILTER [struct hci_filter]
|
||||
* This filter controls the type of packets that will be received at
|
||||
* the socket. By default, Event packets only are enabled.
|
||||
* SO_HCI_DIRECTION [int]
|
||||
* When set, this enables control messages on packets received at the
|
||||
* socket indicating the direction of travel of the packet.
|
||||
*/
|
||||
|
||||
#define SO_HCI_EVT_FILTER (__SO_PROTOCOL + 0)
|
||||
#define SO_HCI_PKT_FILTER (__SO_PROTOCOL + 1)
|
||||
#define SO_HCI_DIRECTION (__SO_PROTOCOL + 2)
|
||||
|
||||
/* L2CAP socket options:
|
||||
|
||||
* SO_L2CAP_IMTU [uint16_t]
|
||||
* Incoming MTU
|
||||
* SO_L2CAP_OMTU [uint16_t]
|
||||
* Outgoing MTU (read-only)
|
||||
* SO_L2CAP_LM [int]
|
||||
* Link Mode. The following bits may be set:
|
||||
*
|
||||
* L2CAP_LM_AUTH Request authentication (pairing).
|
||||
* L2CAP_LM_ENCRYPT Request encryption (includes authentication).
|
||||
* L2CAP_LM_SECURE Request secured link (encryption, plus
|
||||
* change link key).
|
||||
*
|
||||
* Link mode settings will be applied to the baseband link during L2CAP
|
||||
* connection establishment. If the L2CAP connection is already
|
||||
* established, EINPROGRESS may be returned, and it is not possible to
|
||||
* guarantee that data already queued (from either end) will not be
|
||||
* delivered. If the mode change fails, the L2CAP connection will be
|
||||
* aborted.
|
||||
*/
|
||||
|
||||
#define SO_L2CAP_IMTU (__SO_PROTOCOL + 3)
|
||||
#define SO_L2CAP_OMTU (__SO_PROTOCOL + 4)
|
||||
#define SO_L2CAP_LM (__SO_PROTOCOL + 5)
|
||||
# define L2CAP_LM_AUTH (1 << 0)
|
||||
# define L2CAP_LM_ENCRYPT (1 << 1)
|
||||
# define L2CAP_LM_SECURE (1 << 2)
|
||||
|
||||
/* RFCOMM socket options:
|
||||
*
|
||||
* SO_RFCOMM_MTU [uint16_t]
|
||||
* Maximum Frame Size to use for this link.
|
||||
* SO_RFCOMM_LM [int]
|
||||
* Link Mode. The following bits may be set at any time:
|
||||
*
|
||||
* RFCOMM_LM_AUTH Request authentication (pairing).
|
||||
* RFCOMM_LM_ENCRYPT Request encryption (includes authentication).
|
||||
* RFCOMM_LM_SECURE Request secured link (encryption, plus
|
||||
* change link key).
|
||||
*
|
||||
* Link mode settings will be applied to the baseband link during RFCOMM
|
||||
* connection establishment. If the RFCOMM connection is already
|
||||
* established, EINPROGRESS may be returned, and it is not possible to
|
||||
* guarantee that data already queued (from either end) will not be
|
||||
* delivered. If the mode change fails, the RFCOMM connection will be
|
||||
* aborted.
|
||||
*/
|
||||
|
||||
#define SO_RFCOMM_MTU (__SO_PROTOCOL + 6)
|
||||
#define SO_RFCOMM_LM (__SO_PROTOCOL + 7)
|
||||
# define RFCOMM_LM_AUTH (1 << 0)
|
||||
# define RFCOMM_LM_ENCRYPT (1 << 1)
|
||||
# define RFCOMM_LM_SECURE (1 << 2)
|
||||
|
||||
/* SCO socket options:
|
||||
*
|
||||
* SO_SCO_MTU [uint16_t]
|
||||
* Maximum packet size for use on this link. This is read-only and will
|
||||
* be set by the protocol code when a connection is made.
|
||||
* SO_SCO_HANDLE [uint16_t]
|
||||
* Connection handle for this link. This is read-only and provided for
|
||||
* informational purposes only.
|
||||
*/
|
||||
|
||||
#define SO_SCO_MTU (__SO_PROTOCOL + 8)
|
||||
#define SO_SCO_HANDLE (__SO_PROTOCOL + 9)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
@@ -66,15 +199,14 @@
|
||||
* sendto() - Send to specified remote address
|
||||
* recvfrom()- Receive from indicated remote address.
|
||||
*
|
||||
* The 'rc' in the naming derives from RFCCOMM as used in Linux. The
|
||||
* resemblances are superficial beyond that, however.
|
||||
* REVISIT: Some protocols would require a bt_psm field as well.
|
||||
*/
|
||||
|
||||
struct sockaddr_rc_s
|
||||
struct sockaddr_bt_s
|
||||
{
|
||||
sa_family_t rc_family;
|
||||
bt_addr_t rc_bdaddr;
|
||||
uint8_t rc_channel;
|
||||
sa_family_t bt_family;
|
||||
bt_addr_t bt_bdaddr;
|
||||
uint8_t bt_channel;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -53,12 +53,55 @@
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define HCI_DEVNAME_SIZE 32 /* Maximum size of node name */
|
||||
#define HCI_FEATURES_SIZE 8 /* LMP features */
|
||||
|
||||
/* Bluetooth network device IOCTL commands. */
|
||||
|
||||
#ifndef WL_BLUETOOTHCMDS != 5
|
||||
#ifndef WL_BLUETOOTHCMDS != 14
|
||||
# error Incorrect setting for number of Bluetooth IOCTL commands
|
||||
#endif
|
||||
|
||||
/* All of the following use an argument of type struct btreg_s:
|
||||
*
|
||||
* SIOCGBTINFO
|
||||
* Get Bluetooth device Info. Given the device name, fill in the btreq_s
|
||||
* structure including the address field for use with socket addressing as
|
||||
* above.
|
||||
* SIOCGBTINFOA
|
||||
* Get Bluetooth device Info from Address. Given the device address, fill
|
||||
* in the btreq_s structure including the name field.
|
||||
* SIOCNBTINFO
|
||||
* Next Bluetooth device Info. If name field is empty, the first device
|
||||
* will be returned. Otherwise, the next device will be returned until
|
||||
* no more devices are found when the call will fail, with error ENXIO.
|
||||
* Thus, you can cycle through all devices in the system.
|
||||
* SIOCSBTFLAGS
|
||||
* Set Bluetooth device Flags. Not all flags are settable.
|
||||
* SIOCGBTFEAT
|
||||
* Get Bluetooth device Features. This returns the cached basic (page 0)
|
||||
* and extended (page 1 & 2) features.
|
||||
* SIOCSBTPOLICY
|
||||
* Set Bluetooth device Link Policy bits.
|
||||
* SIOCSBTPTYPE
|
||||
* Set Bluetooth device Packet Types. You can only set packet types that
|
||||
* the device supports.
|
||||
* SIOCGBTSTATS
|
||||
* Read device statistics.
|
||||
* SIOCZBTSTATS
|
||||
* Read device statistics, and zero them.
|
||||
*/
|
||||
|
||||
#define SIOCGBTINFO _WLIOC(WL_BLUETOOTHFIRST + 0)
|
||||
#define SIOCGBTINFOA _WLIOC(WL_BLUETOOTHFIRST + 1)
|
||||
#define SIOCNBTINFO _WLIOC(WL_BLUETOOTHFIRST + 2)
|
||||
#define SIOCSBTFLAGS _WLIOC(WL_BLUETOOTHFIRST + 3)
|
||||
#define SIOCGBTFEAT _WLIOC(WL_BLUETOOTHFIRST + 4)
|
||||
#define SIOCSBTPOLICY _WLIOC(WL_BLUETOOTHFIRST + 5)
|
||||
#define SIOCSBTPTYPE _WLIOC(WL_BLUETOOTHFIRST + 6)
|
||||
#define SIOCGBTSTATS _WLIOC(WL_BLUETOOTHFIRST + 7)
|
||||
#define SIOCZBTSTATS _WLIOC(WL_BLUETOOTHFIRST + 8)
|
||||
|
||||
/* SIOCBT_ADVERTISESTART
|
||||
* Description: Set advertisement data, scan response data,
|
||||
* advertisement parameters and start advertising.
|
||||
@@ -67,7 +110,7 @@
|
||||
* Output: None
|
||||
*/
|
||||
|
||||
#define SIOCBT_ADVERTISESTART _WLIOC(WL_BLUETOOTHFIRST + 0)
|
||||
#define SIOCBT_ADVERTISESTART _WLIOC(WL_BLUETOOTHFIRST + 9)
|
||||
|
||||
/* SIOCBT_ADVERTISESTOP
|
||||
* Description: Stop advertising.
|
||||
@@ -75,7 +118,7 @@
|
||||
* Output: None
|
||||
*/
|
||||
|
||||
#define SIOCBT_ADVERTISESTOP _WLIOC(WL_BLUETOOTHFIRST + 1)
|
||||
#define SIOCBT_ADVERTISESTOP _WLIOC(WL_BLUETOOTHFIRST + 10)
|
||||
|
||||
/* SIOCBT_SCANSTART
|
||||
* Description: Start LE scanning. Buffered scan results may be
|
||||
@@ -84,7 +127,7 @@
|
||||
* Output: None
|
||||
*/
|
||||
|
||||
#define SIOCBT_SCANSTART _WLIOC(WL_BLUETOOTHFIRST + 2)
|
||||
#define SIOCBT_SCANSTART _WLIOC(WL_BLUETOOTHFIRST + 11)
|
||||
|
||||
/* SIOCBT_SCANGET
|
||||
* Description: Return scan results buffered since the call time that
|
||||
@@ -95,7 +138,7 @@
|
||||
* provided buffer space.
|
||||
*/
|
||||
|
||||
#define SIOCBT_SCANGET _WLIOC(WL_BLUETOOTHFIRST + 3)
|
||||
#define SIOCBT_SCANGET _WLIOC(WL_BLUETOOTHFIRST + 12)
|
||||
|
||||
/* SIOCBT_SCANSTOP
|
||||
* Description: Stop LE scanning and discard any buffered results.
|
||||
@@ -103,18 +146,96 @@
|
||||
* Output: None
|
||||
*/
|
||||
|
||||
#define SIOCBT_SCANSTOP _WLIOC(WL_BLUETOOTHFIRST + 4)
|
||||
#define SIOCBT_SCANSTOP _WLIOC(WL_BLUETOOTHFIRST + 13)
|
||||
|
||||
/* struct btreq_s union field accessors */
|
||||
|
||||
#define btr_flags btru.btri.btri_flags
|
||||
#define btr_bdaddr btru.btri.btri_bdaddr
|
||||
#define btr_num_cmd btru.btri.btri_num_cmd
|
||||
#define btr_num_acl btru.btri.btri_num_acl
|
||||
#define btr_num_sco btru.btri.btri_num_sco
|
||||
#define btr_acl_mtu btru.btri.btri_acl_mtu
|
||||
#define btr_sco_mtu btru.btri.btri_sco_mtu
|
||||
#define btr_link_policy btru.btri.btri_link_policy
|
||||
#define btr_packet_type btru.btri.btri_packet_type
|
||||
#define btr_max_acl btru.btri.btri_max_acl
|
||||
#define btr_max_sco btru.btri.btri_max_sco
|
||||
#define btr_features0 btru.btrf.btrf_page0
|
||||
#define btr_features1 btru.btrf.btrf_page1
|
||||
#define btr_features2 btru.btrf.btrf_page2
|
||||
#define btr_stats btru.btrs
|
||||
|
||||
/* btr_flags */
|
||||
|
||||
#define BTF_UP (1 << 0) /* unit is up */
|
||||
#define BTF_RUNNING (1 << 1) /* unit is running */
|
||||
#define BTF_XMIT_CMD (1 << 2) /* transmitting CMD packets */
|
||||
#define BTF_XMIT_ACL (1 << 3) /* transmitting ACL packets */
|
||||
#define BTF_XMIT_SCO (1 << 4) /* transmitting SCO packets */
|
||||
#define BTF_INIT_BDADDR (1 << 5) /* waiting for bdaddr */
|
||||
#define BTF_INIT_BUFFER_SIZE (1 << 6) /* waiting for buffer size */
|
||||
#define BTF_INIT_FEATURES (1 << 7) /* waiting for features */
|
||||
#define BTF_NOOP_ON_RESET (1 << 8) /* wait for No-op on reset */
|
||||
#define BTF_INIT_COMMANDS (1 << 9) /* waiting for supported commands */
|
||||
#define BTF_MASTER (1 << 10) /* request Master role */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* Common structure for Bluetooth IOCTL commands */
|
||||
|
||||
struct bt_stats
|
||||
{
|
||||
uint32_t err_tx;
|
||||
uint32_t err_rx;
|
||||
uint32_t cmd_tx;
|
||||
uint32_t evt_rx;
|
||||
uint32_t acl_tx;
|
||||
uint32_t acl_rx;
|
||||
uint32_t sco_tx;
|
||||
uint32_t sco_rx;
|
||||
uint32_t byte_tx;
|
||||
uint32_t byte_rx;
|
||||
};
|
||||
|
||||
struct btreq_s
|
||||
{
|
||||
char btr_name[HCI_DEVNAME_SIZE]; /* Device name */
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
bt_addr_t btri_bdaddr; /* Device bdaddr */
|
||||
uint16_t btri_flags; /* flags */
|
||||
uint16_t btri_num_cmd; /* # of free cmd buffers */
|
||||
uint16_t btri_num_acl; /* # of free ACL buffers */
|
||||
uint16_t btri_num_sco; /* # of free SCO buffers */
|
||||
uint16_t btri_acl_mtu; /* ACL mtu */
|
||||
uint16_t btri_sco_mtu; /* SCO mtu */
|
||||
uint16_t btri_link_policy; /* Link Policy */
|
||||
uint16_t btri_packet_type; /* Packet Type */
|
||||
uint16_t btri_max_acl; /* max ACL buffers */
|
||||
uint16_t btri_max_sco; /* max SCO buffers */
|
||||
} btri;
|
||||
struct
|
||||
{
|
||||
uint8_t btrf_page0[HCI_FEATURES_SIZE]; /* basic */
|
||||
uint8_t btrf_page1[HCI_FEATURES_SIZE]; /* extended page 1 */
|
||||
uint8_t btrf_page2[HCI_FEATURES_SIZE]; /* extended page 2 */
|
||||
} btrf;
|
||||
struct bt_stats btrs; /* unit stats */
|
||||
} btru;
|
||||
};
|
||||
|
||||
/* Read-only data that accompanies the SIOCBT_ADVERTISESTART IOCTL command.
|
||||
* Advertising types are defined in bt_hci.h.
|
||||
*/
|
||||
|
||||
struct bt_advertisestart_s
|
||||
{
|
||||
char as_name[HCI_DEVNAME_SIZE]; /* Device name */
|
||||
uint8_t as_type; /* Advertising type */
|
||||
FAR const struct bt_eir_s as_ad; /* Data for advertisement packets */
|
||||
FAR const struct bt_eir_s as_sd; /* Data for scan response packets */
|
||||
@@ -124,17 +245,19 @@ struct bt_advertisestart_s
|
||||
|
||||
struct bt_scanresponse_s
|
||||
{
|
||||
bt_addr_le_t sr_addr; /* Advertiser LE address and type */
|
||||
int8_t sr_rssi; /* Strength of advertiser signal */
|
||||
uint8_t sr_type; /* Type of advertising response */
|
||||
uint8_t sr_len; /* Length of advertiser data */
|
||||
uint8_t sr_data[CONFIG_BLUETOOTH_MAXSCANDATA];
|
||||
char sr_name[HCI_DEVNAME_SIZE]; /* Device name */
|
||||
bt_addr_le_t sr_addr; /* Advertiser LE address and type */
|
||||
int8_t sr_rssi; /* Strength of advertiser signal */
|
||||
uint8_t sr_type; /* Type of advertising response */
|
||||
uint8_t sr_len; /* Length of advertiser data */
|
||||
uint8_t sr_data[CONFIG_BLUETOOTH_MAXSCANDATA];
|
||||
};
|
||||
|
||||
struct bt_scanresult_s
|
||||
{
|
||||
uint8_t sc_nrsp; /* Input: Max number of responses
|
||||
* Return: Actual number of responses */
|
||||
char sr_name[HCI_DEVNAME_SIZE]; /* Device name */
|
||||
uint8_t sc_nrsp; /* Input: Max number of responses
|
||||
* Return: Actual number of responses */
|
||||
struct bt_scanresponse_s sc_rsp[1];
|
||||
};
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@
|
||||
/* Reserved for Bluetooth network devices (see bt_ioctls.h) */
|
||||
|
||||
#define WL_BLUETOOTHFIRST (WL_NETFIRST + WL_NNETCMDS)
|
||||
#define WL_BLUETOOTHCMDS (5)
|
||||
#define WL_BLUETOOTHCMDS (14)
|
||||
#define WL_IBLUETOOTHCMD(cmd) (_WLIOCVALID(cmd) && \
|
||||
_IOC_NR(cmd) >= WL_BLUETOOTHFIRST && \
|
||||
_IOC_NR(cmd) < (WL_BLUETOOTHFIRST + WL_BLUETOOTHCMDS))
|
||||
|
||||
@@ -158,6 +158,10 @@
|
||||
#define SOL_IPV6 2 /* See options in include/netinet/ip6.h */
|
||||
#define SOL_TCP 3 /* See options in include/netinet/tcp.h */
|
||||
#define SOL_UDP 4 /* See options in include/netinit/udp.h */
|
||||
#define SOL_HCI 5 /* See options in include/netpacket/bluetooth.h */
|
||||
#define SOL_L2CAP 6 /* See options in include/netpacket/bluetooth.h */
|
||||
#define SOL_SCO 7 /* See options in include/netpacket/bluetooth.h */
|
||||
#define SOL_RFCOMM 8 /* See options in include/netpacket/bluetooth.h */
|
||||
|
||||
/* Protocol-level socket options may begin with this value */
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ static ssize_t bluetooth_recvfrom_rxqueue(FAR struct radio_driver_s *radio,
|
||||
FAR struct bluetooth_recvfrom_s *pstate)
|
||||
{
|
||||
FAR struct bluetooth_container_s *container;
|
||||
FAR struct sockaddr_rc_s *iaddr;
|
||||
FAR struct sockaddr_bt_s *iaddr;
|
||||
FAR struct bluetooth_conn_s *conn;
|
||||
FAR struct iob_s *iob;
|
||||
size_t copylen;
|
||||
@@ -190,10 +190,10 @@ static ssize_t bluetooth_recvfrom_rxqueue(FAR struct radio_driver_s *radio,
|
||||
|
||||
if (pstate->ir_from != NULL)
|
||||
{
|
||||
iaddr = (FAR struct sockaddr_rc_s *)pstate->ir_from;
|
||||
iaddr->rc_family = AF_BLUETOOTH;
|
||||
BLUETOOTH_ADDRCOPY(&iaddr->rc_bdaddr, &container->bn_raddr);
|
||||
iaddr->rc_channel = container->bn_channel;
|
||||
iaddr = (FAR struct sockaddr_bt_s *)pstate->ir_from;
|
||||
iaddr->bt_family = AF_BLUETOOTH;
|
||||
BLUETOOTH_ADDRCOPY(&iaddr->bt_bdaddr, &container->bn_raddr);
|
||||
iaddr->bt_channel = container->bn_channel;
|
||||
}
|
||||
|
||||
/* Free both the IOB and the container */
|
||||
@@ -332,12 +332,12 @@ ssize_t bluetooth_recvfrom(FAR struct socket *psock, FAR void *buf,
|
||||
* enough to hold this address family.
|
||||
*/
|
||||
|
||||
if (from != NULL && *fromlen < sizeof(struct sockaddr_rc_s))
|
||||
if (from != NULL && *fromlen < sizeof(struct sockaddr_bt_s))
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (psock->s_type != SOCK_DGRAM)
|
||||
if (psock->s_type != SOCK_RAW)
|
||||
{
|
||||
nerr("ERROR: Unsupported socket type: %d\n", psock->s_type);
|
||||
return -EPROTONOSUPPORT;
|
||||
|
||||
@@ -247,7 +247,7 @@ ssize_t psock_bluetooth_sendto(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags,
|
||||
FAR const struct sockaddr *to, socklen_t tolen)
|
||||
{
|
||||
FAR struct sockaddr_rc_s *destaddr;
|
||||
FAR struct sockaddr_bt_s *destaddr;
|
||||
FAR struct radio_driver_s *radio;
|
||||
FAR struct bluetooth_conn_s *conn;
|
||||
struct bluetooth_sendto_s state;
|
||||
@@ -307,8 +307,8 @@ ssize_t psock_bluetooth_sendto(FAR struct socket *psock, FAR const void *buf,
|
||||
|
||||
/* Copy the destination address */
|
||||
|
||||
destaddr = (FAR struct sockaddr_rc_s *)to;
|
||||
memcpy(&state.is_destaddr, &destaddr->rc_bdaddr,
|
||||
destaddr = (FAR struct sockaddr_bt_s *)to;
|
||||
memcpy(&state.is_destaddr, &destaddr->bt_bdaddr,
|
||||
sizeof(bt_addr_t));
|
||||
|
||||
if (len > 0)
|
||||
|
||||
@@ -180,10 +180,10 @@ static int bluetooth_setup(FAR struct socket *psock, int protocol)
|
||||
* the connection structure is is unallocated at this point. It will
|
||||
* not actually be initialized until the socket is connected.
|
||||
*
|
||||
* Only SOCK_DGRAM is supported (since the MAC header is stripped)
|
||||
* Only SOCK_RAW is supported
|
||||
*/
|
||||
|
||||
if (psock->s_type == SOCK_DGRAM)
|
||||
if (psock->s_type == SOCK_RAW)
|
||||
{
|
||||
return bluetooth_sockif_alloc(psock);
|
||||
}
|
||||
@@ -233,7 +233,7 @@ static void bluetooth_addref(FAR struct socket *psock)
|
||||
FAR struct bluetooth_conn_s *conn;
|
||||
|
||||
DEBUGASSERT(psock != NULL && psock->s_conn != NULL &&
|
||||
psock->s_type == SOCK_DGRAM);
|
||||
psock->s_type == SOCK_RAW);
|
||||
|
||||
conn = (FAR struct bluetooth_conn_s *)psock->s_conn;
|
||||
DEBUGASSERT(conn->bc_crefs > 0 && conn->bc_crefs < 255);
|
||||
@@ -249,17 +249,11 @@ static void bluetooth_addref(FAR struct socket *psock)
|
||||
* specifies the size of 'addr'. The format of the address in 'addr' is
|
||||
* determined by the address space of the socket 'psock'.
|
||||
*
|
||||
* If the socket 'psock' is of type SOCK_DGRAM then 'addr' is the address
|
||||
* to which datagrams are sent by default, and the only address from which
|
||||
* datagrams are received. If the socket is of type SOCK_STREAM or
|
||||
* SOCK_SEQPACKET, this call attempts to make a connection to the socket
|
||||
* that is bound to the address specified by 'addr'.
|
||||
*
|
||||
* Generally, connection-based protocol sockets may successfully
|
||||
* bluetooth_connect() only once; connectionless protocol sockets may use
|
||||
* bluetooth_connect() multiple times to change their association.
|
||||
* Connectionless sockets may dissolve the association by connecting to
|
||||
* an address with the rc_family member of sockaddr set to AF_UNSPEC.
|
||||
* an address with the bt_family member of sockaddr set to AF_UNSPEC.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock Pointer to a socket structure initialized by psock_socket()
|
||||
@@ -277,7 +271,7 @@ static int bluetooth_connect(FAR struct socket *psock,
|
||||
socklen_t addrlen)
|
||||
{
|
||||
FAR struct bluetooth_conn_s *conn;
|
||||
FAR struct sockaddr_rc_s *btaddr;
|
||||
FAR struct sockaddr_bt_s *btaddr;
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(psock != NULL || addr != NULL);
|
||||
@@ -290,9 +284,9 @@ static int bluetooth_connect(FAR struct socket *psock,
|
||||
{
|
||||
/* Save the "connection" address */
|
||||
|
||||
btaddr = (FAR struct sockaddr_rc_s *)addr;
|
||||
memcpy(&conn->bc_raddr, &btaddr->rc_bdaddr, sizeof(bt_addr_t));
|
||||
conn->bc_channel = btaddr->rc_channel;
|
||||
btaddr = (FAR struct sockaddr_bt_s *)addr;
|
||||
memcpy(&conn->bc_raddr, &btaddr->bt_bdaddr, sizeof(bt_addr_t));
|
||||
conn->bc_channel = btaddr->bt_channel;
|
||||
|
||||
/* Mark the socket as connected. */
|
||||
|
||||
@@ -386,7 +380,7 @@ static int bluetooth_accept(FAR struct socket *psock,
|
||||
static int bluetooth_bind(FAR struct socket *psock,
|
||||
FAR const struct sockaddr *addr, socklen_t addrlen)
|
||||
{
|
||||
FAR const struct sockaddr_rc_s *iaddr;
|
||||
FAR const struct sockaddr_bt_s *iaddr;
|
||||
FAR struct radio_driver_s *radio;
|
||||
FAR struct bluetooth_conn_s *conn;
|
||||
|
||||
@@ -395,16 +389,19 @@ static int bluetooth_bind(FAR struct socket *psock,
|
||||
/* Verify that a valid address has been provided */
|
||||
|
||||
if (addr->sa_family != AF_BLUETOOTH ||
|
||||
addrlen < sizeof(struct sockaddr_rc_s))
|
||||
addrlen < sizeof(struct sockaddr_bt_s))
|
||||
{
|
||||
nerr("ERROR: Invalid family: %u or address length: %d < %d\n",
|
||||
addr->sa_family, addrlen, sizeof(struct sockaddr_ll));
|
||||
return -EBADF;
|
||||
}
|
||||
|
||||
/* Bind a PF_BLUETOOTH socket to an network device. */
|
||||
/* Bind a PF_BLUETOOTH socket to an network device.
|
||||
*
|
||||
* Only SOCK_RAW is supported
|
||||
*/
|
||||
|
||||
if (psock->s_type != SOCK_DGRAM)
|
||||
if (psock->s_type != SOCK_RAW)
|
||||
{
|
||||
nerr("ERROR: Invalid socket type: %u\n", psock->s_type);
|
||||
return -EBADF;
|
||||
@@ -418,7 +415,7 @@ static int bluetooth_bind(FAR struct socket *psock,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
iaddr = (FAR const struct sockaddr_rc_s *)addr;
|
||||
iaddr = (FAR const struct sockaddr_bt_s *)addr;
|
||||
|
||||
/* Very that some address was provided */
|
||||
/* REVISIT: Currently and explict address must be assigned. Should we
|
||||
@@ -429,7 +426,7 @@ static int bluetooth_bind(FAR struct socket *psock,
|
||||
|
||||
/* Find the device associated with the requested address */
|
||||
|
||||
radio = bluetooth_find_device(conn, &iaddr->rc_bdaddr);
|
||||
radio = bluetooth_find_device(conn, &iaddr->bt_bdaddr);
|
||||
if (radio == NULL)
|
||||
{
|
||||
nerr("ERROR: No radio at this address\n");
|
||||
@@ -438,7 +435,7 @@ static int bluetooth_bind(FAR struct socket *psock,
|
||||
|
||||
/* Save the address as the socket's local address */
|
||||
|
||||
memcpy(&conn->bc_laddr, &iaddr->rc_bdaddr, sizeof(bt_addr_t));
|
||||
memcpy(&conn->bc_laddr, &iaddr->bt_bdaddr, sizeof(bt_addr_t));
|
||||
|
||||
/* Mark the socket bound */
|
||||
|
||||
@@ -479,7 +476,7 @@ static int bluetooth_getsockname(FAR struct socket *psock,
|
||||
socklen_t *addrlen)
|
||||
{
|
||||
FAR struct bluetooth_conn_s *conn;
|
||||
FAR struct sockaddr_rc_s tmp;
|
||||
FAR struct sockaddr_bt_s tmp;
|
||||
socklen_t copylen;
|
||||
|
||||
DEBUGASSERT(psock != NULL && addr != NULL && addrlen != NULL);
|
||||
@@ -489,12 +486,12 @@ static int bluetooth_getsockname(FAR struct socket *psock,
|
||||
|
||||
/* Create a copy of the full address on the stack */
|
||||
|
||||
tmp.rc_family = AF_BLUETOOTH;
|
||||
memcpy(&tmp.rc_bdaddr, &conn->bc_laddr, sizeof(bt_addr_t));
|
||||
tmp.bt_family = AF_BLUETOOTH;
|
||||
memcpy(&tmp.bt_bdaddr, &conn->bc_laddr, sizeof(bt_addr_t));
|
||||
|
||||
/* Copy to the user buffer, truncating if necessary */
|
||||
|
||||
copylen = sizeof(struct sockaddr_rc_s);
|
||||
copylen = sizeof(struct sockaddr_bt_s);
|
||||
if (copylen > *addrlen)
|
||||
{
|
||||
copylen = *addrlen;
|
||||
@@ -591,7 +588,7 @@ static int bluetooth_poll_local(FAR struct socket *psock,
|
||||
static ssize_t bluetooth_send(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags)
|
||||
{
|
||||
struct sockaddr_rc_s to;
|
||||
struct sockaddr_bt_s to;
|
||||
FAR struct bluetooth_conn_s *conn;
|
||||
ssize_t ret;
|
||||
|
||||
@@ -599,9 +596,9 @@ static ssize_t bluetooth_send(FAR struct socket *psock, FAR const void *buf,
|
||||
conn = (FAR struct bluetooth_conn_s *)psock->s_conn;
|
||||
DEBUGASSERT(conn != NULL);
|
||||
|
||||
/* Only SOCK_DGRAM is supported (because the MAC header is stripped) */
|
||||
/* Only SOCK_RAW is supported */
|
||||
|
||||
if (psock->s_type == SOCK_DGRAM)
|
||||
if (psock->s_type == SOCK_RAW)
|
||||
{
|
||||
/* send() may be used only if the socket is has been connected. */
|
||||
|
||||
@@ -611,15 +608,15 @@ static ssize_t bluetooth_send(FAR struct socket *psock, FAR const void *buf,
|
||||
}
|
||||
else
|
||||
{
|
||||
to.rc_family = AF_BLUETOOTH;
|
||||
memcpy(&to.rc_bdaddr, &conn->bc_raddr, sizeof(bt_addr_t));
|
||||
to.rc_channel = conn->bc_channel;
|
||||
to.bt_family = AF_BLUETOOTH;
|
||||
memcpy(&to.bt_bdaddr, &conn->bc_raddr, sizeof(bt_addr_t));
|
||||
to.bt_channel = conn->bc_channel;
|
||||
|
||||
/* Then perform the send() as sendto() */
|
||||
|
||||
ret = psock_bluetooth_sendto(psock, buf, len, flags,
|
||||
(FAR const struct sockaddr *)&to,
|
||||
sizeof(struct sockaddr_rc_s));
|
||||
sizeof(struct sockaddr_bt_s));
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -662,9 +659,9 @@ static ssize_t bluetooth_sendto(FAR struct socket *psock, FAR const void *buf,
|
||||
{
|
||||
ssize_t ret;
|
||||
|
||||
/* Only SOCK_DGRAM is supported (because the MAC header is stripped) */
|
||||
/* Only SOCK_RAW is supported */
|
||||
|
||||
if (psock->s_type == SOCK_DGRAM)
|
||||
if (psock->s_type == SOCK_RAW)
|
||||
{
|
||||
/* Raw packet send */
|
||||
|
||||
@@ -704,7 +701,9 @@ static int bluetooth_close(FAR struct socket *psock)
|
||||
|
||||
switch (psock->s_type)
|
||||
{
|
||||
case SOCK_DGRAM:
|
||||
/* Only SOCK_RAW is supported */
|
||||
|
||||
case SOCK_RAW:
|
||||
{
|
||||
FAR struct bluetooth_conn_s *conn = psock->s_conn;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user