Zhang, Zhenhua
2009-09-14 10:02:03 UTC
Dear all,
I am calling ioctl(RFCOMMCREATEDEV) to create tty device from a rfcomm fd
using hands-free profile. If the HF send connection request to AG and make
rfcomm connect, the tty could be made successfully. However, if the
AG(mobile) side make request to create rfcomm connection, the rfcomm could
be created but fail to create the tty device. The kernel returns error
because socket is not connected, see below code. Any idea? Thanks much!
if (req.flags & (1 << RFCOMM_REUSE_DLC)) {
/* Socket must be connected */
if (sk->sk_state != BT_CONNECTED)
return -EBADFD;
The pseudo code logic looks like this:
void rfcomm_connect_cb(GIOChannel *rfcomm, GError *err,
gpointer user_data)
{
...
ba2str(&dev->src, src);
ba2str(&dev->dst, dst);
/* make /dev/rfcomm serial port from rfcomm */
memset(&req, 0, sizeof(req));
req.dev_id = -1;
req.flags = (1 << RFCOMM_REUSE_DLC); <---set RFCOMM_REUSE_DLC flag
bacpy(&req.src, &dev->src);
bacpy(&req.dst, &dev->dst);
req.channel = gw->channel;
sk = g_io_channel_unix_get_fd(rfcomm);
id = ioctl(sk, RFCOMMCREATEDEV, &req);
if (id < 0) {
int err = errno; <---return errno 77
error("ioctl(RFCOMMCREATEDEV) failed: %s (%d)", strerror(err), err);
g_io_channel_shutdown(rfcomm, TRUE, NULL);
g_io_channel_unref(rfcomm);
gw->rfcomm = NULL;
goto fail;
}
gw->rfcomm = g_io_channel_ref(rfcomm);
gw->rfcomm_id = id;
gw->tty = g_strdup_printf("/dev/rfcomm%d", id);
failed:
return;
}
static void hf_io_cb(...)
{
bt_io_get(chan, BT_IO_RFCOMM, &err,
BT_IO_OPT_SOURCE_BDADDR, &src,
BT_IO_OPT_DEST_BDADDR, &dst,
BT_IO_OPT_CHANNEL, &ch,
BT_IO_OPT_INVALID);
//request authorization
if (!bt_io_accept(gw->rfcomm, rfcomm_connect_cb, dev, NULL,
&err)) {
error("bt_io_accept: %s", err->message);
g_error_free(err);
}
}
Regar
I am calling ioctl(RFCOMMCREATEDEV) to create tty device from a rfcomm fd
using hands-free profile. If the HF send connection request to AG and make
rfcomm connect, the tty could be made successfully. However, if the
AG(mobile) side make request to create rfcomm connection, the rfcomm could
be created but fail to create the tty device. The kernel returns error
because socket is not connected, see below code. Any idea? Thanks much!
if (req.flags & (1 << RFCOMM_REUSE_DLC)) {
/* Socket must be connected */
if (sk->sk_state != BT_CONNECTED)
return -EBADFD;
The pseudo code logic looks like this:
void rfcomm_connect_cb(GIOChannel *rfcomm, GError *err,
gpointer user_data)
{
...
ba2str(&dev->src, src);
ba2str(&dev->dst, dst);
/* make /dev/rfcomm serial port from rfcomm */
memset(&req, 0, sizeof(req));
req.dev_id = -1;
req.flags = (1 << RFCOMM_REUSE_DLC); <---set RFCOMM_REUSE_DLC flag
bacpy(&req.src, &dev->src);
bacpy(&req.dst, &dev->dst);
req.channel = gw->channel;
sk = g_io_channel_unix_get_fd(rfcomm);
id = ioctl(sk, RFCOMMCREATEDEV, &req);
if (id < 0) {
int err = errno; <---return errno 77
error("ioctl(RFCOMMCREATEDEV) failed: %s (%d)", strerror(err), err);
g_io_channel_shutdown(rfcomm, TRUE, NULL);
g_io_channel_unref(rfcomm);
gw->rfcomm = NULL;
goto fail;
}
gw->rfcomm = g_io_channel_ref(rfcomm);
gw->rfcomm_id = id;
gw->tty = g_strdup_printf("/dev/rfcomm%d", id);
failed:
return;
}
static void hf_io_cb(...)
{
bt_io_get(chan, BT_IO_RFCOMM, &err,
BT_IO_OPT_SOURCE_BDADDR, &src,
BT_IO_OPT_DEST_BDADDR, &dst,
BT_IO_OPT_CHANNEL, &ch,
BT_IO_OPT_INVALID);
//request authorization
if (!bt_io_accept(gw->rfcomm, rfcomm_connect_cb, dev, NULL,
&err)) {
error("bt_io_accept: %s", err->message);
g_error_free(err);
}
}
Regar