From b0285ab48a83bad501d0dfa88837af65016671ec Mon Sep 17 00:00:00 2001 From: Santiago Carot-Nemesio Date: Sat, 10 Jul 2010 00:08:50 +0200 Subject: [PATCH] obexd: Add mode option for L2CAP sockets to the BtIO API Some profiles like MCAP or HDP need set an specific L2CAP configuraton such as Streaming, ERTM or another else. This patch enables the BtIO API to set the mode for L2CAP socket options. --- obexd/src/btio.c | 19 +++++++++++++------ obexd/src/btio.h | 1 + 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/obexd/src/btio.c b/obexd/src/btio.c index 0adbceec1..485eec60a 100644 --- a/obexd/src/btio.c +++ b/obexd/src/btio.c @@ -57,6 +57,7 @@ struct set_opts { uint16_t imtu; uint16_t omtu; int master; + uint8_t mode; }; struct connect { @@ -474,10 +475,10 @@ static gboolean get_sec_level(int sock, BtIOType type, int *level, return TRUE; } -static gboolean l2cap_set(int sock, int sec_level, uint16_t imtu, - uint16_t omtu, int master, GError **err) +static gboolean l2cap_set(int sock, int sec_level, uint16_t imtu, uint16_t omtu, + uint8_t mode, int master, GError **err) { - if (imtu || omtu) { + if (imtu || omtu || mode) { struct l2cap_options l2o; socklen_t len; @@ -493,6 +494,8 @@ static gboolean l2cap_set(int sock, int sec_level, uint16_t imtu, l2o.imtu = imtu; if (omtu) l2o.omtu = omtu; + if (mode) + l2o.mode = mode; if (setsockopt(sock, SOL_L2CAP, L2CAP_OPTIONS, &l2o, sizeof(l2o)) < 0) { @@ -629,6 +632,7 @@ static gboolean parse_set_opts(struct set_opts *opts, GError **err, opts->defer = DEFAULT_DEFER_TIMEOUT; opts->master = -1; opts->sec_level = BT_IO_SEC_MEDIUM; + opts->mode = L2CAP_MODE_BASIC; while (opt != BT_IO_OPT_INVALID) { switch (opt) { @@ -678,6 +682,9 @@ static gboolean parse_set_opts(struct set_opts *opts, GError **err, case BT_IO_OPT_MASTER: opts->master = va_arg(args, gboolean); break; + case BT_IO_OPT_MODE: + opts->mode = va_arg(args, int); + break; default: g_set_error(err, BT_IO_ERROR, BT_IO_ERROR_INVALID_ARGS, "Unknown option %d", opt); @@ -1088,7 +1095,7 @@ gboolean bt_io_set(GIOChannel *io, BtIOType type, GError **err, case BT_IO_L2RAW: case BT_IO_L2CAP: return l2cap_set(sock, opts.sec_level, opts.imtu, opts.omtu, - opts.master, err); + opts.mode, opts.master, err); case BT_IO_RFCOMM: return rfcomm_set(sock, opts.sec_level, opts.master, err); case BT_IO_SCO: @@ -1129,7 +1136,7 @@ static GIOChannel *create_io(BtIOType type, gboolean server, if (l2cap_bind(sock, &opts->src, server ? opts->psm : 0, err) < 0) goto failed; - if (!l2cap_set(sock, opts->sec_level, 0, 0, -1, err)) + if (!l2cap_set(sock, opts->sec_level, 0, 0, 0, -1, err)) goto failed; break; case BT_IO_L2CAP: @@ -1142,7 +1149,7 @@ static GIOChannel *create_io(BtIOType type, gboolean server, server ? opts->psm : 0, err) < 0) goto failed; if (!l2cap_set(sock, opts->sec_level, opts->imtu, opts->omtu, - opts->master, err)) + opts->mode, opts->master, err)) goto failed; break; case BT_IO_RFCOMM: diff --git a/obexd/src/btio.h b/obexd/src/btio.h index 7df597291..e9dcc9f97 100644 --- a/obexd/src/btio.h +++ b/obexd/src/btio.h @@ -62,6 +62,7 @@ typedef enum { BT_IO_OPT_MASTER, BT_IO_OPT_HANDLE, BT_IO_OPT_CLASS, + BT_IO_OPT_MODE, } BtIOOption; typedef enum { -- 2.47.3