diff options
author | Luiz Augusto von Dentz <luiz.dentz@openbossa.org> | 2008-05-16 22:25:51 +0000 |
---|---|---|
committer | Luiz Augusto von Dentz <luiz.dentz@openbossa.org> | 2008-05-16 22:25:51 +0000 |
commit | 3cb3d3d7e4aa089dd5840980c8846927631757f6 (patch) | |
tree | 63f8ca4ea44de9c72ba26f70db7e8bec358718b4 /common | |
parent | 86ca72eb302bc00c6c58b56d20ba06f1d7000214 (diff) |
Introduce bt_rfcomm_listen_allocate.
Diffstat (limited to 'common')
-rw-r--r-- | common/glib-helper.c | 32 | ||||
-rw-r--r-- | common/glib-helper.h | 2 |
2 files changed, 29 insertions, 5 deletions
diff --git a/common/glib-helper.c b/common/glib-helper.c index ef5a1d13..59293334 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; + addr->rc_channel = *channel; err = bind(io_ctxt->fd, (struct sockaddr *) addr, sizeof(*addr)); if (err < 0) { @@ -764,11 +764,13 @@ static int rfcomm_bind(struct io_context *io_ctxt, const bdaddr_t *src, return -errno; } + *channel = addr->rc_channel; + return 0; } static int rfcomm_listen(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; @@ -834,8 +836,8 @@ static void io_context_cleanup(struct io_context *io_ctxt) g_free(io_ctxt); } -GIOChannel *bt_rfcomm_listen(const bdaddr_t *src, uint8_t channel, uint32_t flags, - bt_io_callback_t cb, void *user_data) +GIOChannel *rfcomm_listen_internal(const bdaddr_t *src, uint8_t *channel, + uint32_t flags, bt_io_callback_t cb, void *user_data) { struct io_context *io_ctxt; int err; @@ -853,6 +855,26 @@ GIOChannel *bt_rfcomm_listen(const bdaddr_t *src, uint8_t channel, uint32_t flag return io_ctxt->io; } +GIOChannel *bt_rfcomm_listen_allocate(const bdaddr_t *src, uint8_t *channel, + uint32_t flags, bt_io_callback_t cb, void *user_data) +{ + if (!channel) + return NULL; + + *channel = 0; + + return rfcomm_listen_internal(src, channel, flags, cb, user_data); +} + +GIOChannel *bt_rfcomm_listen(const bdaddr_t *src, uint8_t channel, + uint32_t flags, bt_io_callback_t cb, void *user_data) +{ + if (channel < 1 || channel > 30) + return NULL; + + return rfcomm_listen_internal(src, &channel, flags, cb, user_data); +} + int bt_rfcomm_connect(const bdaddr_t *src, const bdaddr_t *dst, uint8_t channel, bt_io_callback_t cb, void *user_data) { diff --git a/common/glib-helper.h b/common/glib-helper.h index 23a04046..8d346b49 100644 --- a/common/glib-helper.h +++ b/common/glib-helper.h @@ -42,6 +42,8 @@ GSList *bt_string2list(const gchar *str); GIOChannel *bt_rfcomm_listen(const bdaddr_t *src, uint8_t channel, uint32_t flags, bt_io_callback_t cb, void *user_data); +GIOChannel *bt_rfcomm_listen_allocate(const bdaddr_t *src, uint8_t *channel, + uint32_t flags, bt_io_callback_t cb, void *user_data); int bt_rfcomm_connect(const bdaddr_t *src, const bdaddr_t *dst, uint8_t channel, bt_io_callback_t cb, void *user_data); |