From: Andrei Emeltchenko <Andrei.Emeltchenko.news@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCHv1 09/16] android/hal-sock: Implement accept signal over Android fd
Date: Thu, 14 Nov 2013 17:11:48 +0200 [thread overview]
Message-ID: <1384441915-23966-10-git-send-email-Andrei.Emeltchenko.news@gmail.com> (raw)
In-Reply-To: <1384441915-23966-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Android expects to get accept signal over file descriptor which was
set during listen HAL call.
---
android/socket.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git a/android/socket.c b/android/socket.c
index 01c73db..7d1ada8 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -37,6 +37,7 @@
#include "hal-msg.h"
#include "hal-ipc.h"
#include "ipc.h"
+#include "utils.h"
#include "socket.h"
static bdaddr_t adapter_addr;
@@ -103,6 +104,45 @@ static struct {
{ {0} }
};
+static int bt_sock_send_fd(int sock_fd, const void *buf, int len, int send_fd)
+{
+ ssize_t ret;
+ struct msghdr msg;
+ struct cmsghdr *cmsg;
+ struct iovec iv;
+ char msgbuf[CMSG_SPACE(1)];
+
+ DBG("len %d sock_fd %d send_fd %d", len, sock_fd, send_fd);
+
+ if (sock_fd == -1 || send_fd == -1)
+ return -1;
+
+ memset(&msg, 0, sizeof(msg));
+
+ msg.msg_control = msgbuf;
+ msg.msg_controllen = sizeof(msgbuf);
+ cmsg = CMSG_FIRSTHDR(&msg);
+ cmsg->cmsg_level = SOL_SOCKET;
+ cmsg->cmsg_type = SCM_RIGHTS;
+ cmsg->cmsg_len = CMSG_LEN(sizeof(send_fd));
+ memcpy(CMSG_DATA(cmsg), &send_fd, sizeof(send_fd));
+
+ iv.iov_base = (unsigned char *) buf;
+ iv.iov_len = len;
+
+ msg.msg_iov = &iv;
+ msg.msg_iovlen = 1;
+
+ ret = sendmsg(sock_fd, &msg, MSG_NOSIGNAL);
+ if (ret < 0) {
+ error("sendmsg(): sock_fd %d send_fd %d: %s",
+ sock_fd, send_fd, strerror(errno));
+ return ret;
+ }
+
+ return ret;
+}
+
static int get_rfcomm_default_chan(const uint8_t *uuid)
{
int i;
@@ -211,6 +251,21 @@ static gboolean sock_rfcomm_event_cb(GIOChannel *io, GIOCondition cond,
return TRUE;
}
+static void sock_send_accept(struct rfcomm_slot *rfslot, bdaddr_t *bdaddr,
+ int fd_accepted)
+{
+ struct hal_sock_connect_signal cmd;
+
+ DBG("");
+
+ cmd.size = sizeof(cmd);
+ bdaddr2android(bdaddr, cmd.bdaddr);
+ cmd.channel = rfslot->channel;
+ cmd.status = 0;
+
+ bt_sock_send_fd(rfslot->fd, &cmd, sizeof(cmd), fd_accepted);
+}
+
static void accept_cb(GIOChannel *io, GError *err, gpointer user_data)
{
struct rfcomm_slot *rfslot = user_data;
@@ -242,6 +297,8 @@ static void accept_cb(GIOChannel *io, GError *err, gpointer user_data)
rfcomm_connected_list =
g_list_append(rfcomm_connected_list, rfslot_acc);
+ sock_send_accept(rfslot, &dst, hal_fd);
+
/* Handle events from Android */
io_stack = g_io_channel_unix_new(rfslot_acc->fd);
g_io_add_watch(io_stack, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
--
1.7.10.4
next prev parent reply other threads:[~2013-11-14 15:11 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-14 15:11 [PATCHv1 00/16] Socket HAL Andrei Emeltchenko
2013-11-14 15:11 ` [PATCHv1 01/16] android/hal-sock: Add debug flag printing Andrei Emeltchenko
2013-11-14 15:11 ` [PATCHv1 02/16] android/hal-sock: Use static local adapter address Andrei Emeltchenko
2013-11-14 15:11 ` [PATCHv1 03/16] android/hal-sock: Add connect signal to socket Andrei Emeltchenko
2013-11-14 15:11 ` [PATCHv1 04/16] android/hal-sock: Define structures for socket HAL Andrei Emeltchenko
2013-11-15 12:29 ` Luiz Augusto von Dentz
2013-11-14 15:11 ` [PATCHv1 05/16] android/hal-sock: Initial listen handle Andrei Emeltchenko
2013-11-14 15:11 ` [PATCHv1 06/16] android/hal-sock: Implement socket accepted event Andrei Emeltchenko
2013-11-14 15:11 ` [PATCHv1 07/16] android/hal-sock: Implement Android RFCOMM stack events Andrei Emeltchenko
2013-11-15 0:00 ` Marcel Holtmann
2013-11-15 9:23 ` Andrei Emeltchenko
2013-11-15 9:32 ` Marcel Holtmann
2013-11-14 15:11 ` [PATCHv1 08/16] android/hal-sock: Implement RFCOMM events Andrei Emeltchenko
2013-11-14 15:11 ` Andrei Emeltchenko [this message]
2013-11-14 15:11 ` [PATCHv1 10/16] android/hal-sock: Write channel to Android fd Andrei Emeltchenko
2013-11-14 15:11 ` [PATCHv1 11/16] android/hal-sock: Implement socket connect HAL method Andrei Emeltchenko
2013-11-14 15:11 ` [PATCHv1 12/16] android/hal-sock: Parse SDP response and connect Andrei Emeltchenko
2013-11-14 15:11 ` [PATCHv1 13/16] android/hal-sock: Implement HAL connect call Andrei Emeltchenko
2013-11-14 15:11 ` [PATCHv1 14/16] android/hal-sock: Send RFCOMM channel to framework Andrei Emeltchenko
2013-11-14 15:11 ` [PATCHv1 15/16] android/hal-sock: Send connect signal on connect Andrei Emeltchenko
2013-11-14 15:11 ` [PATCHv1 16/16] android/hal-sock: Close file descriptor after sending Andrei Emeltchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1384441915-23966-10-git-send-email-Andrei.Emeltchenko.news@gmail.com \
--to=andrei.emeltchenko.news@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).