2018-03-31 22:55:03 +02:00
|
|
|
/****************************************************************************
|
2020-12-01 07:55:16 +01:00
|
|
|
* net/bluetooth/bluetooth_sendmsg.c
|
2018-03-31 22:55:03 +02:00
|
|
|
*
|
2024-09-11 14:39:39 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2020-05-17 16:47:40 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2018-03-31 22:55:03 +02:00
|
|
|
*
|
2020-05-17 16:47:40 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-03-31 22:55:03 +02:00
|
|
|
*
|
2020-05-17 16:47:40 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2018-03-31 22:55:03 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include <netpacket/bluetooth.h>
|
|
|
|
#include <arch/irq.h>
|
|
|
|
|
|
|
|
#include <nuttx/semaphore.h>
|
|
|
|
#include <nuttx/mm/iob.h>
|
|
|
|
#include <nuttx/net/radiodev.h>
|
|
|
|
#include <nuttx/net/bluetooth.h>
|
|
|
|
#include <nuttx/net/net.h>
|
|
|
|
#include <nuttx/net/ip.h>
|
2018-04-29 20:43:09 +02:00
|
|
|
#include <nuttx/wireless/bluetooth/bt_hci.h>
|
2018-03-31 22:55:03 +02:00
|
|
|
|
2018-07-07 16:26:13 +02:00
|
|
|
#include "utils/utils.h"
|
2018-03-31 22:55:03 +02:00
|
|
|
#include "netdev/netdev.h"
|
|
|
|
#include "devif/devif.h"
|
|
|
|
#include "socket/socket.h"
|
|
|
|
#include "bluetooth/bluetooth.h"
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_BLUETOOTH
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* This structure holds the state of the send operation until it can be
|
2018-06-23 22:09:06 +02:00
|
|
|
* operated upon from the event handler.
|
2018-03-31 22:55:03 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
struct bluetooth_sendto_s
|
|
|
|
{
|
|
|
|
FAR struct socket *is_sock; /* Points to the parent socket structure */
|
|
|
|
FAR struct devif_callback_s *is_cb; /* Reference to callback instance */
|
|
|
|
bt_addr_t is_destaddr; /* Frame destination address */
|
2020-09-20 21:45:09 +02:00
|
|
|
uint16_t is_channel; /* Frame destination channel */
|
2018-03-31 22:55:03 +02:00
|
|
|
sem_t is_sem; /* Used to wake up the waiting thread */
|
|
|
|
FAR const uint8_t *is_buffer; /* User buffer of data to send */
|
|
|
|
size_t is_buflen; /* Number of bytes in the is_buffer */
|
|
|
|
ssize_t is_sent; /* The number of bytes sent (or error) */
|
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: bluetooth_sendto_eventhandler
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static uint16_t bluetooth_sendto_eventhandler(FAR struct net_driver_s *dev,
|
|
|
|
FAR void *pvpriv,
|
|
|
|
uint16_t flags)
|
|
|
|
{
|
|
|
|
FAR struct radio_driver_s *radio;
|
|
|
|
FAR struct bluetooth_sendto_s *pstate;
|
|
|
|
struct bluetooth_frame_meta_s meta;
|
|
|
|
FAR struct iob_s *iob;
|
|
|
|
int hdrlen;
|
|
|
|
int ret;
|
|
|
|
|
2020-10-13 03:37:15 +02:00
|
|
|
DEBUGASSERT(pvpriv != NULL && dev != NULL);
|
2018-03-31 22:55:03 +02:00
|
|
|
|
|
|
|
/* Ignore polls from non Bluetooth network drivers */
|
|
|
|
|
|
|
|
if (dev->d_lltype != NET_LL_BLUETOOTH)
|
|
|
|
{
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure that this is the driver to which the socket is connected. */
|
2019-10-25 19:31:42 +02:00
|
|
|
|
2023-05-01 16:15:05 +02:00
|
|
|
/* #warning Missing logic */
|
2018-03-31 22:55:03 +02:00
|
|
|
|
2022-08-25 15:17:57 +02:00
|
|
|
pstate = pvpriv;
|
2018-03-31 22:55:03 +02:00
|
|
|
radio = (FAR struct radio_driver_s *)dev;
|
|
|
|
|
2020-11-23 08:47:41 +01:00
|
|
|
ninfo("flags: %04x sent: %zd\n", flags, pstate->is_sent);
|
2018-03-31 22:55:03 +02:00
|
|
|
|
|
|
|
if (pstate != NULL && (flags & BLUETOOTH_POLL) != 0)
|
|
|
|
{
|
|
|
|
/* Initialize the meta data */
|
|
|
|
|
|
|
|
BLUETOOTH_ADDRCOPY(&meta.bm_raddr, &pstate->is_destaddr);
|
|
|
|
meta.bm_channel = pstate->is_channel;
|
2020-09-20 21:45:09 +02:00
|
|
|
meta.bm_proto = pstate->is_sock->s_proto;
|
2018-03-31 22:55:03 +02:00
|
|
|
|
|
|
|
/* Get the Bluetooth MAC header length */
|
|
|
|
|
|
|
|
hdrlen = radio->r_get_mhrlen(radio, &meta);
|
|
|
|
if (hdrlen < 0)
|
|
|
|
{
|
|
|
|
nerr("ERROR: Failed to get header length: %d\n", hdrlen);
|
|
|
|
ret = hdrlen;
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Verify that the user buffer can fit within the frame with this
|
|
|
|
* MAC header.
|
|
|
|
*/
|
|
|
|
|
2018-04-01 23:21:58 +02:00
|
|
|
DEBUGASSERT(BLUETOOTH_MAX_FRAMELEN <= CONFIG_IOB_BUFSIZE);
|
|
|
|
if (pstate->is_buflen + hdrlen > BLUETOOTH_MAX_FRAMELEN)
|
2018-03-31 22:55:03 +02:00
|
|
|
{
|
|
|
|
nerr("ERROR: User buffer will not fit into the frame: %u > %u\n",
|
|
|
|
(unsigned int)(pstate->is_buflen + hdrlen),
|
|
|
|
(unsigned int)CONFIG_IOB_BUFSIZE);
|
|
|
|
ret = -E2BIG;
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate an IOB to hold the frame data */
|
|
|
|
|
2022-08-08 04:21:03 +02:00
|
|
|
iob = net_ioballoc(false);
|
2018-03-31 22:55:03 +02:00
|
|
|
if (iob == NULL)
|
|
|
|
{
|
|
|
|
nwarn("WARNING: Failed to allocate IOB\n");
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the IOB */
|
|
|
|
|
|
|
|
iob->io_offset = hdrlen;
|
|
|
|
iob->io_len = pstate->is_buflen + hdrlen;
|
|
|
|
iob->io_pktlen = pstate->is_buflen + hdrlen;
|
|
|
|
|
|
|
|
/* Copy the user data into the IOB */
|
|
|
|
|
|
|
|
memcpy(&iob->io_data[hdrlen], pstate->is_buffer, pstate->is_buflen);
|
|
|
|
|
|
|
|
/* And submit the IOB to the network driver */
|
|
|
|
|
|
|
|
ret = radio->r_req_data(radio, &meta, iob);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
nerr("ERROR: r_req_data() failed: %d\n", ret);
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Save the successful result */
|
|
|
|
|
|
|
|
pstate->is_sent = pstate->is_buflen;
|
|
|
|
|
|
|
|
/* Don't allow any further call backs. */
|
|
|
|
|
2022-09-26 06:56:25 +02:00
|
|
|
pstate->is_cb->flags = 0;
|
|
|
|
pstate->is_cb->priv = NULL;
|
|
|
|
pstate->is_cb->event = NULL;
|
2018-03-31 22:55:03 +02:00
|
|
|
|
|
|
|
/* Wake up the waiting thread */
|
|
|
|
|
|
|
|
nxsem_post(&pstate->is_sem);
|
|
|
|
}
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
|
|
|
|
errout:
|
2019-10-25 19:31:42 +02:00
|
|
|
|
2018-03-31 22:55:03 +02:00
|
|
|
/* Don't allow any further call backs. */
|
|
|
|
|
2022-09-26 06:56:25 +02:00
|
|
|
pstate->is_cb->flags = 0;
|
|
|
|
pstate->is_cb->priv = NULL;
|
|
|
|
pstate->is_cb->event = NULL;
|
|
|
|
pstate->is_sent = ret;
|
2018-03-31 22:55:03 +02:00
|
|
|
|
|
|
|
/* Wake up the waiting thread */
|
|
|
|
|
|
|
|
nxsem_post(&pstate->is_sem);
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2020-12-01 07:55:16 +01:00
|
|
|
* Name: bluetooth_sendto
|
2018-03-31 22:55:03 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* If sendto() is used on a connection-mode (SOCK_STREAM, SOCK_SEQPACKET)
|
|
|
|
* socket, the parameters to and 'tolen' are ignored (and the error EISCONN
|
|
|
|
* may be returned when they are not NULL and 0), and the error ENOTCONN is
|
|
|
|
* returned when the socket was not actually connected.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* psock A pointer to a NuttX-specific, internal socket structure
|
|
|
|
* buf Data to send
|
|
|
|
* len Length of data to send
|
|
|
|
* flags Send flags
|
|
|
|
* to Address of recipient
|
|
|
|
* tolen The length of the address structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* On success, returns the number of characters sent. On error,
|
|
|
|
* a negated errno value is retruend. See sendto() for the complete list
|
|
|
|
* of return values.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-12-01 07:55:16 +01:00
|
|
|
static ssize_t bluetooth_sendto(FAR struct socket *psock,
|
|
|
|
FAR const void *buf, size_t len, int flags,
|
|
|
|
FAR const struct sockaddr *to,
|
|
|
|
socklen_t tolen)
|
2018-03-31 22:55:03 +02:00
|
|
|
{
|
|
|
|
FAR struct radio_driver_s *radio;
|
|
|
|
FAR struct bluetooth_conn_s *conn;
|
|
|
|
struct bluetooth_sendto_s state;
|
|
|
|
int ret = OK;
|
|
|
|
|
2020-12-01 07:55:16 +01:00
|
|
|
/* Only SOCK_RAW is supported */
|
|
|
|
|
|
|
|
if (psock->s_type != SOCK_RAW)
|
|
|
|
{
|
|
|
|
/* EDESTADDRREQ. Signifies that the socket is not connection-mode and
|
|
|
|
* no peer address is set.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return -EDESTADDRREQ;
|
|
|
|
}
|
|
|
|
|
2018-03-31 22:55:03 +02:00
|
|
|
/* Verify that the sockfd corresponds to valid, allocated socket */
|
|
|
|
|
2021-02-23 11:04:13 +01:00
|
|
|
if (psock == NULL || psock->s_conn == NULL)
|
2018-03-31 22:55:03 +02:00
|
|
|
{
|
|
|
|
return -EBADF;
|
|
|
|
}
|
|
|
|
|
2023-05-08 16:11:04 +02:00
|
|
|
conn = psock->s_conn;
|
2018-03-31 22:55:03 +02:00
|
|
|
|
|
|
|
/* Verify that the address is large enough to be a valid PF_BLUETOOTH
|
|
|
|
* address.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (tolen < sizeof(bt_addr_t))
|
|
|
|
{
|
|
|
|
return -EDESTADDRREQ;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the device driver that will service this transfer */
|
|
|
|
|
2020-09-20 21:45:09 +02:00
|
|
|
if (psock->s_proto == BTPROTO_L2CAP)
|
2018-03-31 22:55:03 +02:00
|
|
|
{
|
2020-09-20 21:45:09 +02:00
|
|
|
radio = bluetooth_find_device(conn, &conn->bc_laddr);
|
|
|
|
if (radio == NULL)
|
|
|
|
{
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (psock->s_proto == BTPROTO_HCI)
|
|
|
|
{
|
|
|
|
/* TODO: should actually look among BT devices */
|
|
|
|
|
|
|
|
radio =
|
|
|
|
(FAR struct radio_driver_s *)netdev_findbyindex(conn->bc_ldev + 1);
|
|
|
|
|
|
|
|
DEBUGASSERT(radio->r_dev.d_lltype == NET_LL_BLUETOOTH);
|
|
|
|
|
|
|
|
if (radio == NULL)
|
|
|
|
{
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return -EOPNOTSUPP;
|
2018-03-31 22:55:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Perform the send operation */
|
|
|
|
|
2018-06-23 23:03:01 +02:00
|
|
|
/* Initialize the state structure. This is done with the network locked
|
|
|
|
* because we don't want anything to happen until we are ready.
|
2018-03-31 22:55:03 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
net_lock();
|
|
|
|
memset(&state, 0, sizeof(struct bluetooth_sendto_s));
|
2020-01-02 17:49:34 +01:00
|
|
|
nxsem_init(&state.is_sem, 0, 0); /* Doesn't really fail */
|
2018-03-31 22:55:03 +02:00
|
|
|
|
|
|
|
state.is_sock = psock; /* Socket descriptor to use */
|
|
|
|
state.is_buflen = len; /* Number of bytes to send */
|
|
|
|
state.is_buffer = buf; /* Buffer to send from */
|
|
|
|
|
|
|
|
/* Copy the destination address */
|
|
|
|
|
2020-09-20 21:45:09 +02:00
|
|
|
if (psock->s_proto == BTPROTO_L2CAP)
|
|
|
|
{
|
|
|
|
FAR struct sockaddr_l2 *destaddr = (FAR struct sockaddr_l2 *)to;
|
|
|
|
memcpy(&state.is_destaddr, &destaddr->l2_bdaddr,
|
|
|
|
sizeof(bt_addr_t));
|
|
|
|
}
|
|
|
|
else if (psock->s_proto == BTPROTO_HCI)
|
|
|
|
{
|
|
|
|
FAR struct sockaddr_hci *destaddr = (FAR struct sockaddr_hci *)to;
|
|
|
|
state.is_channel = destaddr->hci_channel;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = -EOPNOTSUPP;
|
|
|
|
goto err_with_net;
|
|
|
|
}
|
2018-03-31 22:55:03 +02:00
|
|
|
|
|
|
|
if (len > 0)
|
|
|
|
{
|
|
|
|
/* Allocate resource to receive a callback */
|
|
|
|
|
|
|
|
state.is_cb = bluetooth_callback_alloc(&radio->r_dev, conn);
|
|
|
|
if (state.is_cb)
|
|
|
|
{
|
|
|
|
/* Set up the callback in the connection */
|
|
|
|
|
|
|
|
state.is_cb->flags = PKT_POLL;
|
|
|
|
state.is_cb->priv = (FAR void *)&state;
|
|
|
|
state.is_cb->event = bluetooth_sendto_eventhandler;
|
|
|
|
|
|
|
|
/* Notify the device driver that new TX data is available. */
|
|
|
|
|
|
|
|
netdev_txnotify_dev(&radio->r_dev);
|
|
|
|
|
2018-06-23 23:03:01 +02:00
|
|
|
/* Wait for the send to complete or an error to occur.
|
2023-01-13 07:51:38 +01:00
|
|
|
* net_sem_wait will also terminate if a signal is received.
|
2018-03-31 22:55:03 +02:00
|
|
|
*/
|
|
|
|
|
2023-01-13 07:51:38 +01:00
|
|
|
ret = net_sem_wait(&state.is_sem);
|
2018-03-31 22:55:03 +02:00
|
|
|
|
2018-06-23 23:03:01 +02:00
|
|
|
/* Make sure that no further events are processed */
|
2018-03-31 22:55:03 +02:00
|
|
|
|
|
|
|
bluetooth_callback_free(&radio->r_dev, conn, state.is_cb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nxsem_destroy(&state.is_sem);
|
|
|
|
net_unlock();
|
|
|
|
|
|
|
|
/* Check for a errors, Errors are signaled by negative errno values
|
|
|
|
* for the send length
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (state.is_sent < 0)
|
|
|
|
{
|
|
|
|
return state.is_sent;
|
|
|
|
}
|
|
|
|
|
2023-01-13 07:51:38 +01:00
|
|
|
/* If net_sem_wait failed, then we were probably reawakened by a signal.
|
|
|
|
* In this case, net_sem_wait will have returned negated errno
|
2020-05-17 16:47:40 +02:00
|
|
|
* appropriately.
|
2018-03-31 22:55:03 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the number of bytes actually sent */
|
|
|
|
|
|
|
|
return state.is_sent;
|
2020-09-20 21:45:09 +02:00
|
|
|
|
|
|
|
err_with_net:
|
|
|
|
nxsem_destroy(&state.is_sem);
|
|
|
|
net_unlock();
|
|
|
|
|
|
|
|
return ret;
|
2018-03-31 22:55:03 +02:00
|
|
|
}
|
|
|
|
|
2020-12-01 07:55:16 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: bluetooth_l2cap_send
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Socket send() method for the PF_BLUETOOTH socket over BTPROTO_L2CAP.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* psock An instance of the internal socket structure.
|
|
|
|
* buf Data to send
|
|
|
|
* len Length of data to send
|
|
|
|
* flags Send flags
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* On success, returns the number of characters sent. On error, a negated
|
|
|
|
* errno value is returned (see send() for the list of appropriate error
|
|
|
|
* values.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static ssize_t bluetooth_l2cap_send(FAR struct socket *psock,
|
|
|
|
FAR const void *buf,
|
|
|
|
size_t len, int flags)
|
|
|
|
{
|
|
|
|
struct sockaddr_l2 to;
|
|
|
|
FAR struct bluetooth_conn_s *conn;
|
|
|
|
ssize_t ret;
|
|
|
|
|
2023-05-08 16:11:04 +02:00
|
|
|
conn = psock->s_conn;
|
2020-12-01 07:55:16 +01:00
|
|
|
|
2022-02-08 06:18:01 +01:00
|
|
|
if (!_SS_ISCONNECTED(conn->bc_conn.s_flags))
|
2020-12-01 07:55:16 +01:00
|
|
|
{
|
|
|
|
ret = -ENOTCONN;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
to.l2_family = AF_BLUETOOTH;
|
|
|
|
memcpy(&to.l2_bdaddr, &conn->bc_raddr, sizeof(bt_addr_t));
|
|
|
|
to.l2_cid = conn->bc_channel;
|
|
|
|
|
|
|
|
/* Then perform the send() as sendto() */
|
|
|
|
|
|
|
|
ret = bluetooth_sendto(psock, buf, len, flags,
|
|
|
|
(FAR const struct sockaddr *)&to,
|
|
|
|
sizeof(struct sockaddr_l2));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: bluetooth_hci_send
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Socket send() method for the PF_BLUETOOTH socket over BTPROTO_HCI.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* psock An instance of the internal socket structure.
|
|
|
|
* buf Data to send
|
|
|
|
* len Length of data to send
|
|
|
|
* flags Send flags
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* On success, returns the number of characters sent. On error, a negated
|
|
|
|
* errno value is returned (see send() for the list of appropriate error
|
|
|
|
* values.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static ssize_t bluetooth_hci_send(FAR struct socket *psock,
|
|
|
|
FAR const void *buf,
|
|
|
|
size_t len, int flags)
|
|
|
|
{
|
|
|
|
/* We only support sendto() for HCI sockets */
|
|
|
|
|
|
|
|
return -EPFNOSUPPORT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: bluetooth_send
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Socket send() method for the PF_BLUETOOTH socket.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* psock An instance of the internal socket structure.
|
|
|
|
* buf Data to send
|
|
|
|
* len Length of data to send
|
|
|
|
* flags Send flags
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* On success, returns the number of characters sent. On error, a negated
|
|
|
|
* errno value is returned (see send() for the list of appropriate error
|
|
|
|
* values.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static ssize_t bluetooth_send(FAR struct socket *psock, FAR const void *buf,
|
|
|
|
size_t len, int flags)
|
|
|
|
{
|
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
/* Only SOCK_RAW is supported */
|
|
|
|
|
|
|
|
if (psock->s_type == SOCK_RAW)
|
|
|
|
{
|
|
|
|
switch (psock->s_proto)
|
|
|
|
{
|
|
|
|
case BTPROTO_L2CAP:
|
|
|
|
{
|
|
|
|
ret = bluetooth_l2cap_send(psock, buf, len, flags);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BTPROTO_HCI:
|
|
|
|
{
|
|
|
|
ret = bluetooth_hci_send(psock, buf, len, flags);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
ret = -EPFNOSUPPORT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: bluetooth_sendmsg
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* If sendmsg() is used on a connection-mode (SOCK_STREAM, SOCK_SEQPACKET)
|
|
|
|
* socket, the parameters 'msg_name' and 'msg_namelen' are ignored (and the
|
|
|
|
* error EISCONN may be returned when they are not NULL and 0), and the
|
|
|
|
* error ENOTCONN is returned when the socket was not actually connected.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* psock A pointer to a NuttX-specific, internal socket structure
|
|
|
|
* msg data to send
|
|
|
|
* flags Send flags
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* On success, returns the number of characters sent. On error,
|
|
|
|
* a negated errno value is returned. See sendmsg() for the complete list
|
|
|
|
* of return values.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
ssize_t bluetooth_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
|
|
|
int flags)
|
|
|
|
{
|
|
|
|
FAR const void *buf = msg->msg_iov->iov_base;
|
|
|
|
size_t len = msg->msg_iov->iov_len;
|
|
|
|
FAR const struct sockaddr *to = msg->msg_name;
|
|
|
|
socklen_t tolen = msg->msg_namelen;
|
|
|
|
|
|
|
|
/* Validity check, only single iov supported */
|
|
|
|
|
|
|
|
if (msg->msg_iovlen != 1)
|
|
|
|
{
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
return to ? bluetooth_sendto(psock, buf, len, flags, to, tolen) :
|
|
|
|
bluetooth_send(psock, buf, len, flags);
|
|
|
|
}
|
|
|
|
|
2018-03-31 22:55:03 +02:00
|
|
|
#endif /* CONFIG_NET_BLUETOOTH */
|