Skip to content

Commit

Permalink
Bluetooth: EWS: extended window size option support
Browse files Browse the repository at this point in the history
Adds support for extended window size (EWS) config option. We enable EWS
feature in L2CAP Info RSP when hs enabled. EWS option is included in L2CAP
Config Req if tx_win (which is set via socket) bigger then standard default
value (63) && hs enabled && remote side supports EWS feature.

Using EWS selects extended control field in L2CAP.

Code partly based on Qualcomm and Atheros patches sent upstream a year ago.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
  • Loading branch information
Andrei Emeltchenko authored and Gustavo F. Padovan committed Oct 13, 2011
1 parent 669bb39 commit 6327eb9
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 9 deletions.
8 changes: 6 additions & 2 deletions include/net/bluetooth/l2cap.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#define L2CAP_DEFAULT_MIN_MTU 48
#define L2CAP_DEFAULT_FLUSH_TO 0xffff
#define L2CAP_DEFAULT_TX_WINDOW 63
#define L2CAP_DEFAULT_EXT_WINDOW 0x3FFF
#define L2CAP_DEFAULT_MAX_TX 3
#define L2CAP_DEFAULT_RETRANS_TO 2000 /* 2 seconds */
#define L2CAP_DEFAULT_MONITOR_TO 12000 /* 12 seconds */
Expand Down Expand Up @@ -233,6 +234,7 @@ struct l2cap_conf_opt {
#define L2CAP_CONF_QOS 0x03
#define L2CAP_CONF_RFC 0x04
#define L2CAP_CONF_FCS 0x05
#define L2CAP_CONF_EWS 0x07

#define L2CAP_CONF_MAX_SIZE 22

Expand Down Expand Up @@ -333,7 +335,7 @@ struct l2cap_chan {

__u8 fcs;

__u8 tx_win;
__u16 tx_win;
__u8 max_tx;
__u16 retrans_timeout;
__u16 monitor_timeout;
Expand All @@ -357,7 +359,7 @@ struct l2cap_chan {
struct sk_buff *sdu;
struct sk_buff *sdu_last_frag;

__u8 remote_tx_win;
__u16 remote_tx_win;
__u8 remote_max_tx;
__u16 remote_mps;

Expand Down Expand Up @@ -442,6 +444,7 @@ enum {
CONF_CONNECT_PEND,
CONF_NO_FCS_RECV,
CONF_STATE2_DEVICE,
CONF_EWS_RECV,
};

#define L2CAP_CONF_MAX_CONF_REQ 2
Expand All @@ -465,6 +468,7 @@ enum {
FLAG_FORCE_ACTIVE,
FLAG_FORCE_RELIABLE,
FLAG_FLUSHABLE,
FLAG_EXT_CTRL,
};

#define __set_chan_timer(c, t) l2cap_set_timer(c, &c->chan_timer, (t))
Expand Down
51 changes: 48 additions & 3 deletions net/bluetooth/l2cap_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1898,6 +1898,22 @@ static inline __u8 l2cap_select_mode(__u8 mode, __u16 remote_feat_mask)
}
}

static inline bool __l2cap_ews_supported(struct l2cap_chan *chan)
{
return enable_hs && chan->conn->feat_mask & L2CAP_FEAT_EXT_WINDOW;
}

static inline void l2cap_txwin_setup(struct l2cap_chan *chan)
{
if (chan->tx_win > L2CAP_DEFAULT_TX_WINDOW &&
__l2cap_ews_supported(chan))
/* use extended control field */
set_bit(FLAG_EXT_CTRL, &chan->flags);
else
chan->tx_win = min_t(u16, chan->tx_win,
L2CAP_DEFAULT_TX_WINDOW);
}

static int l2cap_build_conf_req(struct l2cap_chan *chan, void *data)
{
struct l2cap_conf_req *req = data;
Expand Down Expand Up @@ -1944,14 +1960,18 @@ static int l2cap_build_conf_req(struct l2cap_chan *chan, void *data)

case L2CAP_MODE_ERTM:
rfc.mode = L2CAP_MODE_ERTM;
rfc.txwin_size = chan->tx_win;
rfc.max_transmit = chan->max_tx;
rfc.retrans_timeout = 0;
rfc.monitor_timeout = 0;
rfc.max_pdu_size = cpu_to_le16(L2CAP_DEFAULT_MAX_PDU_SIZE);
if (L2CAP_DEFAULT_MAX_PDU_SIZE > chan->conn->mtu - 10)
rfc.max_pdu_size = cpu_to_le16(chan->conn->mtu - 10);

l2cap_txwin_setup(chan);

rfc.txwin_size = min_t(u16, chan->tx_win,
L2CAP_DEFAULT_TX_WINDOW);

l2cap_add_conf_opt(&ptr, L2CAP_CONF_RFC, sizeof(rfc),
(unsigned long) &rfc);

Expand All @@ -1963,6 +1983,10 @@ static int l2cap_build_conf_req(struct l2cap_chan *chan, void *data)
chan->fcs = L2CAP_FCS_NONE;
l2cap_add_conf_opt(&ptr, L2CAP_CONF_FCS, 1, chan->fcs);
}

if (test_bit(FLAG_EXT_CTRL, &chan->flags))
l2cap_add_conf_opt(&ptr, L2CAP_CONF_EWS, 2,
chan->tx_win);
break;

case L2CAP_MODE_STREAMING:
Expand Down Expand Up @@ -2038,6 +2062,15 @@ static int l2cap_parse_conf_req(struct l2cap_chan *chan, void *data)

break;

case L2CAP_CONF_EWS:
if (!enable_hs)
return -ECONNREFUSED;

set_bit(FLAG_EXT_CTRL, &chan->flags);
set_bit(CONF_EWS_RECV, &chan->conf_state);
chan->remote_tx_win = val;
break;

default:
if (hint)
break;
Expand Down Expand Up @@ -2098,7 +2131,11 @@ static int l2cap_parse_conf_req(struct l2cap_chan *chan, void *data)
break;

case L2CAP_MODE_ERTM:
chan->remote_tx_win = rfc.txwin_size;
if (!test_bit(CONF_EWS_RECV, &chan->conf_state))
chan->remote_tx_win = rfc.txwin_size;
else
rfc.txwin_size = L2CAP_DEFAULT_TX_WINDOW;

chan->remote_max_tx = rfc.max_transmit;

if (le16_to_cpu(rfc.max_pdu_size) > chan->conn->mtu - 10)
Expand Down Expand Up @@ -2190,6 +2227,13 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
l2cap_add_conf_opt(&ptr, L2CAP_CONF_RFC,
sizeof(rfc), (unsigned long) &rfc);
break;

case L2CAP_CONF_EWS:
chan->tx_win = min_t(u16, val,
L2CAP_DEFAULT_EXT_WINDOW);
l2cap_add_conf_opt(&ptr, L2CAP_CONF_EWS,
2, chan->tx_win);
break;
}
}

Expand Down Expand Up @@ -2785,7 +2829,8 @@ static inline int l2cap_information_req(struct l2cap_conn *conn, struct l2cap_cm
feat_mask |= L2CAP_FEAT_ERTM | L2CAP_FEAT_STREAMING
| L2CAP_FEAT_FCS;
if (enable_hs)
feat_mask |= L2CAP_FEAT_EXT_FLOW;
feat_mask |= L2CAP_FEAT_EXT_FLOW
| L2CAP_FEAT_EXT_WINDOW;

put_unaligned_le32(feat_mask, rsp->data);
l2cap_send_cmd(conn, cmd->ident,
Expand Down
8 changes: 4 additions & 4 deletions net/bluetooth/l2cap_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ static int l2cap_sock_getsockopt_old(struct socket *sock, int optname, char __us
opts.mode = chan->mode;
opts.fcs = chan->fcs;
opts.max_tx = chan->max_tx;
opts.txwin_size = (__u16)chan->tx_win;
opts.txwin_size = chan->tx_win;

len = min_t(unsigned int, len, sizeof(opts));
if (copy_to_user(optval, (char *) &opts, len))
Expand Down Expand Up @@ -501,15 +501,15 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
opts.mode = chan->mode;
opts.fcs = chan->fcs;
opts.max_tx = chan->max_tx;
opts.txwin_size = (__u16)chan->tx_win;
opts.txwin_size = chan->tx_win;

len = min_t(unsigned int, sizeof(opts), optlen);
if (copy_from_user((char *) &opts, optval, len)) {
err = -EFAULT;
break;
}

if (opts.txwin_size > L2CAP_DEFAULT_TX_WINDOW) {
if (opts.txwin_size > L2CAP_DEFAULT_EXT_WINDOW) {
err = -EINVAL;
break;
}
Expand All @@ -533,7 +533,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
chan->omtu = opts.omtu;
chan->fcs = opts.fcs;
chan->max_tx = opts.max_tx;
chan->tx_win = (__u8)opts.txwin_size;
chan->tx_win = opts.txwin_size;
break;

case L2CAP_LM:
Expand Down

0 comments on commit 6327eb9

Please sign in to comment.