summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2008-05-17 09:11:21 +0000
committerJohan Hedberg <johan.hedberg@nokia.com>2008-05-17 09:11:21 +0000
commitd7d35ec921ce7fcc138c36a738e337603d122cf0 (patch)
tree0e1d6939124b87d9ca02714b9b215f4706048644 /common
parentf7ff6ba7386a4fb7b5750945731012e8735ee069 (diff)
Fix bt_rfcomm_listen_allocate since channel allocation happens after listen() and not bind()
Diffstat (limited to 'common')
-rw-r--r--common/glib-helper.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/common/glib-helper.c b/common/glib-helper.c
index 0333ca07..91b167b0 100644
--- a/common/glib-helper.c
+++ b/common/glib-helper.c
@@ -734,7 +734,7 @@ static int l2cap_connect(struct io_context *io_ctxt, const bdaddr_t *src,
}
static int rfcomm_bind(struct io_context *io_ctxt, const bdaddr_t *src,
- uint8_t *channel, uint32_t flags,
+ uint8_t channel, uint32_t flags,
struct sockaddr_rc *addr)
{
int err;
@@ -756,7 +756,7 @@ static int rfcomm_bind(struct io_context *io_ctxt, const bdaddr_t *src,
memset(addr, 0, sizeof(*addr));
addr->rc_family = AF_BLUETOOTH;
bacpy(&addr->rc_bdaddr, src);
- addr->rc_channel = channel ? *channel : 0;
+ addr->rc_channel = channel;
err = bind(io_ctxt->fd, (struct sockaddr *) addr, sizeof(*addr));
if (err < 0) {
@@ -764,9 +764,6 @@ static int rfcomm_bind(struct io_context *io_ctxt, const bdaddr_t *src,
return -errno;
}
- if (channel)
- *channel = addr->rc_channel;
-
return 0;
}
@@ -774,9 +771,10 @@ static int rfcomm_listen(struct io_context *io_ctxt, const bdaddr_t *src,
uint8_t *channel, uint32_t flags)
{
struct sockaddr_rc addr;
+ socklen_t sa_len;
int err;
- err = rfcomm_bind(io_ctxt, src, channel, flags, &addr);
+ err = rfcomm_bind(io_ctxt, src, *channel, flags, &addr);
if (err < 0)
return err;
@@ -786,6 +784,16 @@ static int rfcomm_listen(struct io_context *io_ctxt, const bdaddr_t *src,
return err;
}
+ sa_len = sizeof(struct sockaddr_rc);
+ memset(&addr, 0, sizeof(addr));
+ if (getsockname(io_ctxt->fd, (struct sockaddr *) &addr, &sa_len) < 0) {
+ err = -errno;
+ close(io_ctxt->fd);
+ return err;
+ }
+
+ *channel = addr.rc_channel;
+
return 0;
}
@@ -795,7 +803,7 @@ static int rfcomm_connect(struct io_context *io_ctxt, const bdaddr_t *src,
struct sockaddr_rc addr;
int err;
- err = rfcomm_bind(io_ctxt, src, NULL, 0, &addr);
+ err = rfcomm_bind(io_ctxt, src, 0, 0, &addr);
if (err < 0)
return err;