* [PATCH v2 06/32] Bluetooth: Move LE L2CAP initiator procedure to its own function
From: johan.hedberg @ 2013-12-05 13:11 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1386249090-10236-1-git-send-email-johan.hedberg@gmail.com>
From: Johan Hedberg <johan.hedberg@intel.com>
Once connection oriented L2CAP channels over LE are supported they will
need a completely separate handling from BR/EDR channels.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/l2cap_core.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index eafcdf65718b..d250d8af7fd6 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1170,12 +1170,17 @@ static void l2cap_start_connection(struct l2cap_chan *chan)
}
}
+static void l2cap_le_start(struct l2cap_chan *chan)
+{
+ l2cap_chan_ready(chan);
+}
+
static void l2cap_do_start(struct l2cap_chan *chan)
{
struct l2cap_conn *conn = chan->conn;
if (conn->hcon->type == LE_LINK) {
- l2cap_chan_ready(chan);
+ l2cap_le_start(chan);
return;
}
--
1.8.4.2
^ permalink raw reply related
* [PATCH v2 05/32] Bluetooth: Pass command length to LE signaling channel handlers
From: johan.hedberg @ 2013-12-05 13:11 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1386249090-10236-1-git-send-email-johan.hedberg@gmail.com>
From: Johan Hedberg <johan.hedberg@intel.com>
The LE signaling PDU length is already calculated in the
l2cap_le_sig_channel function so we can just pass the value to the
various handler functions to avoid unnecessary recalculations (byte
order conversions). Right now the only user is the connection parameter
update procedure, but as new LE signaling operations become available
(for connection oriented channels) they will also be able to make use of
the value.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/l2cap_core.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 510a17cefd26..eafcdf65718b 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -5165,18 +5165,17 @@ static inline int l2cap_check_conn_param(u16 min, u16 max, u16 latency,
static inline int l2cap_conn_param_update_req(struct l2cap_conn *conn,
struct l2cap_cmd_hdr *cmd,
- u8 *data)
+ u16 cmd_len, u8 *data)
{
struct hci_conn *hcon = conn->hcon;
struct l2cap_conn_param_update_req *req;
struct l2cap_conn_param_update_rsp rsp;
- u16 min, max, latency, to_multiplier, cmd_len;
+ u16 min, max, latency, to_multiplier;
int err;
if (!(hcon->link_mode & HCI_LM_MASTER))
return -EINVAL;
- cmd_len = __le16_to_cpu(cmd->len);
if (cmd_len != sizeof(struct l2cap_conn_param_update_req))
return -EPROTO;
@@ -5287,14 +5286,15 @@ static inline int l2cap_bredr_sig_cmd(struct l2cap_conn *conn,
}
static inline int l2cap_le_sig_cmd(struct l2cap_conn *conn,
- struct l2cap_cmd_hdr *cmd, u8 *data)
+ struct l2cap_cmd_hdr *cmd, u16 cmd_len,
+ u8 *data)
{
switch (cmd->code) {
case L2CAP_COMMAND_REJ:
return 0;
case L2CAP_CONN_PARAM_UPDATE_REQ:
- return l2cap_conn_param_update_req(conn, cmd, data);
+ return l2cap_conn_param_update_req(conn, cmd, cmd_len, data);
case L2CAP_CONN_PARAM_UPDATE_RSP:
return 0;
@@ -5331,7 +5331,7 @@ static inline void l2cap_le_sig_channel(struct l2cap_conn *conn,
goto drop;
}
- err = l2cap_le_sig_cmd(conn, cmd, skb->data);
+ err = l2cap_le_sig_cmd(conn, cmd, len, skb->data);
if (err) {
struct l2cap_cmd_rej_unk rej;
--
1.8.4.2
^ permalink raw reply related
* [PATCH v2 04/32] Bluetooth: Allow l2cap_chan_check_security() to be used for LE links.
From: johan.hedberg @ 2013-12-05 13:11 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1386249090-10236-1-git-send-email-johan.hedberg@gmail.com>
From: Johan Hedberg <johan.hedberg@intel.com>
With connection oriented L2CAP channels some code paths will be shared
with BR/EDR links. It is therefore necessary to allow the
l2cap_chan_check_security function to be usable also for LE links in
addition to BR/EDR ones. This means that smp_conn_security() needs to be
called instead of hci_conn_security() in the case of an LE link.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/l2cap_core.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 03b641c2f39d..510a17cefd26 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -726,6 +726,9 @@ int l2cap_chan_check_security(struct l2cap_chan *chan)
struct l2cap_conn *conn = chan->conn;
__u8 auth_type;
+ if (conn->hcon->type == LE_LINK)
+ return smp_conn_security(conn->hcon, chan->sec_level);
+
auth_type = l2cap_get_auth_type(chan);
return hci_conn_security(conn->hcon, chan->sec_level, auth_type);
--
1.8.4.2
^ permalink raw reply related
* [PATCH v2 03/32] Bluetooth: Update l2cap_global_chan_by_psm() to take a link type
From: johan.hedberg @ 2013-12-05 13:11 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1386249090-10236-1-git-send-email-johan.hedberg@gmail.com>
From: Johan Hedberg <johan.hedberg@intel.com>
Once connection oriented L2CAP channels become possible for LE we need
to be able to specify the link type we're interested in when looking up
L2CAP channels. Therefore, add a link_type parameter to the
l2cap_global_chan_by_psm() function which gets compared to the address
type associated with each l2cap_chan.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/l2cap_core.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 70be2eb8ed03..03b641c2f39d 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1703,7 +1703,8 @@ EXPORT_SYMBOL(l2cap_conn_put);
*/
static struct l2cap_chan *l2cap_global_chan_by_psm(int state, __le16 psm,
bdaddr_t *src,
- bdaddr_t *dst)
+ bdaddr_t *dst,
+ u8 link_type)
{
struct l2cap_chan *c, *c1 = NULL;
@@ -1713,6 +1714,12 @@ static struct l2cap_chan *l2cap_global_chan_by_psm(int state, __le16 psm,
if (state && c->state != state)
continue;
+ if (link_type == ACL_LINK && c->src_type != BDADDR_BREDR)
+ continue;
+
+ if (link_type == LE_LINK && c->src_type == BDADDR_BREDR)
+ continue;
+
if (c->psm == psm) {
int src_match, dst_match;
int src_any, dst_any;
@@ -3713,7 +3720,7 @@ static struct l2cap_chan *l2cap_connect(struct l2cap_conn *conn,
/* Check if we have socket listening on psm */
pchan = l2cap_global_chan_by_psm(BT_LISTEN, psm, &conn->hcon->src,
- &conn->hcon->dst);
+ &conn->hcon->dst, ACL_LINK);
if (!pchan) {
result = L2CAP_CR_BAD_PSM;
goto sendresp;
@@ -6380,7 +6387,8 @@ static void l2cap_conless_channel(struct l2cap_conn *conn, __le16 psm,
if (hcon->type != ACL_LINK)
goto drop;
- chan = l2cap_global_chan_by_psm(0, psm, &hcon->src, &hcon->dst);
+ chan = l2cap_global_chan_by_psm(0, psm, &hcon->src, &hcon->dst,
+ ACL_LINK);
if (!chan)
goto drop;
--
1.8.4.2
^ permalink raw reply related
* [PATCH v2 02/32] Bluetooth: Add module parameter to enable LE CoC support
From: johan.hedberg @ 2013-12-05 13:11 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1386249090-10236-1-git-send-email-johan.hedberg@gmail.com>
From: Johan Hedberg <johan.hedberg@intel.com>
Along with the L2CAP Connection Oriented Channels features it is now
allowed to use both custom fixed CIDs as well as PSM based (connection
oriented connections). Since the support for this (with the subsequent
patches) is still on an experimental stage, add a module parameter to
enable it.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
include/net/bluetooth/l2cap.h | 1 +
net/bluetooth/l2cap_sock.c | 18 ++++++++++++------
2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index c853b16de4ef..94645d56fea7 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -809,6 +809,7 @@ static inline long l2cap_chan_no_get_sndtimeo(struct l2cap_chan *chan)
}
extern bool disable_ertm;
+extern bool enable_lecoc;
int l2cap_init_sockets(void);
void l2cap_cleanup_sockets(void);
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index 7cc24d263caa..5a1d0cb0b8d5 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -27,6 +27,7 @@
/* Bluetooth L2CAP sockets. */
+#include <linux/module.h>
#include <linux/export.h>
#include <net/bluetooth/bluetooth.h>
@@ -35,6 +36,8 @@
#include "smp.h"
+bool enable_lecoc;
+
static struct bt_sock_list l2cap_sk_list = {
.lock = __RW_LOCK_UNLOCKED(l2cap_sk_list.lock)
};
@@ -73,11 +76,11 @@ static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen)
return -EINVAL;
if (bdaddr_type_is_le(la.l2_bdaddr_type)) {
- /* Connection oriented channels are not supported on LE */
- if (la.l2_psm)
+ if (!enable_lecoc && la.l2_psm)
return -EINVAL;
/* We only allow ATT user space socket */
- if (la.l2_cid != __constant_cpu_to_le16(L2CAP_CID_ATT))
+ if (la.l2_cid &&
+ la.l2_cid != __constant_cpu_to_le16(L2CAP_CID_ATT))
return -EINVAL;
}
@@ -189,11 +192,11 @@ static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr,
return -EINVAL;
if (bdaddr_type_is_le(la.l2_bdaddr_type)) {
- /* Connection oriented channels are not supported on LE */
- if (la.l2_psm)
+ if (!enable_lecoc && la.l2_psm)
return -EINVAL;
/* We only allow ATT user space socket */
- if (la.l2_cid != __constant_cpu_to_le16(L2CAP_CID_ATT))
+ if (la.l2_cid &&
+ la.l2_cid != __constant_cpu_to_le16(L2CAP_CID_ATT))
return -EINVAL;
}
@@ -1469,3 +1472,6 @@ void l2cap_cleanup_sockets(void)
bt_sock_unregister(BTPROTO_L2CAP);
proto_unregister(&l2cap_proto);
}
+
+module_param(enable_lecoc, bool, 0644);
+MODULE_PARM_DESC(enable_lecoc, "Enable support for LE CoC");
--
1.8.4.2
^ permalink raw reply related
* [PATCH v2 01/32] Bluetooth: Remove unnecessary braces from one-line if-statement
From: johan.hedberg @ 2013-12-05 13:10 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1386249090-10236-1-git-send-email-johan.hedberg@gmail.com>
From: Johan Hedberg <johan.hedberg@intel.com>
This patch is just a trivial coding style fix to remove unnecessary
braces from a one-line if-statement.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/l2cap_core.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 4af3821df880..70be2eb8ed03 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -6612,11 +6612,10 @@ int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
}
if (chan->state == BT_CONNECT) {
- if (!status) {
+ if (!status)
l2cap_start_connection(chan);
- } else {
+ else
__set_chan_timer(chan, L2CAP_DISC_TIMEOUT);
- }
} else if (chan->state == BT_CONNECT2) {
struct l2cap_conn_rsp rsp;
__u16 res, stat;
--
1.8.4.2
^ permalink raw reply related
* [PATCH v2 00/32] Bluetooth: LE CoC support
From: johan.hedberg @ 2013-12-05 13:10 UTC (permalink / raw)
To: linux-bluetooth
Hi,
Here's v2 of the patches with all comments taken into account.
Additionally I've fixed the permissions of the debugfs files, fixed the
credits calculation for max_credits == 1, and added a cleanup patch at
the end of the set for simplifying l2cap_chan initialization for LE CoC.
I've also updated user space l2test now to support the new BT_SNDMTU and
BT_RCVMTU socket options, i.e. the LE CoC functionality can now be
tested using upstream l2test.
Johan
----------------------------------------------------------------
Johan Hedberg (32):
Bluetooth: Remove unnecessary braces from one-line if-statement
Bluetooth: Add module parameter to enable LE CoC support
Bluetooth: Update l2cap_global_chan_by_psm() to take a link type
Bluetooth: Allow l2cap_chan_check_security() to be used for LE links.
Bluetooth: Pass command length to LE signaling channel handlers
Bluetooth: Move LE L2CAP initiator procedure to its own function
Bluetooth: Add definitions for LE connection oriented channels
Bluetooth: Add initial code for LE L2CAP Connect Request
Bluetooth: Add smp_sufficient_security helper function
Bluetooth: Refactor L2CAP connect rejection to its own function
Bluetooth: Add basic LE L2CAP connect request receiving support
Bluetooth: Fix L2CAP channel closing for LE connections
Bluetooth: Add L2CAP Disconnect suppport for LE
Bluetooth: Make l2cap_le_sig_cmd logic consistent
Bluetooth: Add LE L2CAP flow control mode
Bluetooth: Track LE L2CAP credits in l2cap_chan
Bluetooth: Limit L2CAP_OPTIONS socket option usage with LE
Bluetooth: Add new BT_SNDMTU and BT_RCVMTU socket options
Bluetooth: Implement returning of LE L2CAP credits
Bluetooth: Add LE flow control discipline
Bluetooth: Reject LE CoC commands when the feature is not enabled
Bluetooth: Introduce L2CAP channel callback for suspending
Bluetooth: Add LE L2CAP segmentation support for outgoing data
Bluetooth: Implement LE L2CAP reassembly
Bluetooth: Fix LE L2CAP Connect Request handling together with SMP
Bluetooth: Fix suspending the L2CAP socket if we start with 0 credits
Bluetooth: Limit LE MPS to the MTU value
Bluetooth: Fix clearing of chan->omtu for LE CoC channels
Bluetooth: Fix CID ranges for LE CoC CID allocations
Bluetooth: Fix validating LE PSM values
Bluetooth: Add debugfs controls for LE CoC MPS and Credits
Bluetooth: Simplify l2cap_chan initialization for LE CoC
include/net/bluetooth/bluetooth.h | 3 +
include/net/bluetooth/l2cap.h | 45 +++
net/bluetooth/l2cap_core.c | 720 ++++++++++++++++++++++++++++++++++---
net/bluetooth/l2cap_sock.c | 157 +++++++-
net/bluetooth/smp.c | 16 +-
net/bluetooth/smp.h | 1 +
6 files changed, 873 insertions(+), 69 deletions(-)
^ permalink raw reply
* Re: [PATCH 1/8] android: Fix turning BT off during pairing
From: Tyszkowski Jakub @ 2013-12-05 13:02 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1386239837-4102-1-git-send-email-jakub.tyszkowski@tieto.com>
On 12/05/2013 11:37 AM, Jakub Tyszkowski wrote:
> Not turning BT off in time due to actions queued in mgmt makes Android
> unstable and locks Bluetooth UI controlls. This patch fixes this issue
> by cancelling queued actions.
>
> ---
> android/bluetooth.c | 22 +++++++++++++++++++++-
> 1 file changed, 21 insertions(+), 1 deletion(-)
>
> diff --git a/android/bluetooth.c b/android/bluetooth.c
> index 6174b1f..e67864a 100644
> --- a/android/bluetooth.c
> +++ b/android/bluetooth.c
> @@ -1982,6 +1982,9 @@ static void pair_device_complete(uint8_t status, uint16_t length,
>
> DBG("status %u", status);
>
> + /*Data used for bond cancelling can be freed now*/
> + g_free(user_data);
> +
> /* On success bond state change will be send when new link key event
> * is received */
> if (status == MGMT_STATUS_SUCCESS)
> @@ -1991,19 +1994,34 @@ static void pair_device_complete(uint8_t status, uint16_t length,
> HAL_BOND_STATE_NONE);
> }
>
> +static void pair_device_cancelled(void *data)
> +{
> + bdaddr_t *addr = data;
> +
> + set_device_bond_state(addr, HAL_STATUS_FAILED, HAL_BOND_STATE_NONE);
> +
> + g_free(data);
> +}
> +
> static void handle_create_bond_cmd(const void *buf, uint16_t len)
> {
> const struct hal_cmd_create_bond *cmd = buf;
> uint8_t status;
> struct mgmt_cp_pair_device cp;
> + bdaddr_t *addr;
>
> cp.io_cap = DEFAULT_IO_CAPABILITY;
> cp.addr.type = BDADDR_BREDR;
> android2bdaddr(cmd->bdaddr, &cp.addr.bdaddr);
>
> + addr = g_new(bdaddr_t, 1);
> + bacpy(addr, &cp.addr.bdaddr);
> +
> if (mgmt_send(mgmt_if, MGMT_OP_PAIR_DEVICE, adapter.index, sizeof(cp),
> - &cp, pair_device_complete, NULL, NULL) == 0) {
> + &cp, pair_device_complete,
> + addr, pair_device_cancelled) == 0) {
> status = HAL_STATUS_FAILED;
> + g_free(addr);
> goto fail;
> }
>
> @@ -2253,6 +2271,8 @@ static void handle_disable_cmd(const void *buf, uint16_t len)
> goto failed;
> }
>
> + mgmt_cancel_index(mgmt_if, adapter.index);
> +
> if (!set_mode(MGMT_OP_SET_POWERED, 0x00)) {
> status = HAL_STATUS_FAILED;
> goto failed;
>
Hi,
Please ignore this one patch as it makes user_data being freed twice.
BR,
Jakub Tyszkowski
^ permalink raw reply
* Re: [PATCHv2 2/4] android/socket Use 64K buffer for socket handling
From: Luiz Augusto von Dentz @ 2013-12-05 12:43 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <1386085873-21715-3-git-send-email-Andrei.Emeltchenko.news@gmail.com>
Hi Andrei,
On Tue, Dec 3, 2013 at 5:51 PM, Andrei Emeltchenko
<Andrei.Emeltchenko.news@gmail.com> wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
>
> Make SOCKET_BUFFER define and use 0xFFFE instead of 1K.
> The value 0XFFFE is what Android sends in OBEX Connect packet in
> Maximum Packet Length field. Though OBEX specify meximum packet
> length as 64K - 1 which is 0xFFFF.
> ---
> android/socket.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/android/socket.c b/android/socket.c
> index 9020874..9ff9019 100644
> --- a/android/socket.c
> +++ b/android/socket.c
> @@ -52,6 +52,8 @@
>
> #define SVC_HINT_OBEX 0x10
>
> +#define SOCKET_BUFFER 0xFFFE
> +
> static bdaddr_t adapter_addr;
>
> /* Simple list of RFCOMM server sockets */
> @@ -487,7 +489,7 @@ static gboolean sock_stack_event_cb(GIOChannel *io, GIOCondition cond,
> gpointer data)
> {
> struct rfcomm_sock *rfsock = data;
> - unsigned char buf[1024];
> + unsigned char buf[SOCKET_BUFFER];
> int len, sent;
>
> if (cond & G_IO_HUP) {
> @@ -526,7 +528,7 @@ static gboolean sock_rfcomm_event_cb(GIOChannel *io, GIOCondition cond,
> gpointer data)
> {
> struct rfcomm_sock *rfsock = data;
> - unsigned char buf[1024];
> + unsigned char buf[SOCKET_BUFFER];
> int len, sent;
>
> if (cond & G_IO_HUP) {
> --
> 1.8.3.2
We need to be a bit more generic here, the socket HAL is not
restricted to OBEX only, also it doesn't seems you are adjusting the
buffer level of the sockets, the buffer itself is just to copy between
the sockets so we have to follow how much the sockets can
transmit/receive not the other way around.
So it seems to me that we should either set the maximum MTU size we
could use with RFCOMM (UINT16_MAX?) or read the MTU once connected
(not sure if makes sense since it is SOCK_STREAM) and then allocate
the same amount as buffer in a field in struct rfcomm_sock, also this
needs then to be set back to socketpair with
setsocketopt(SO_RCVBUF/SO_SNDBUF) so we minimize context switches and
wakeups.
--
Luiz Augusto von Dentz
^ permalink raw reply
* [PATCH 8/8] android/pan: Move logic from HAL to daemon
From: Jakub Tyszkowski @ 2013-12-05 10:37 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1386239837-4102-1-git-send-email-jakub.tyszkowski@tieto.com>
HAL should contain as little logic as possible, but we should be doing
these checks on daemon side anyway.
---
android/hal-pan.c | 14 --------------
android/pan.c | 19 +++++++++++++++++++
2 files changed, 19 insertions(+), 14 deletions(-)
diff --git a/android/hal-pan.c b/android/hal-pan.c
index ec52672..8c0f8d8 100644
--- a/android/hal-pan.c
+++ b/android/hal-pan.c
@@ -109,20 +109,6 @@ static bt_status_t pan_connect(const bt_bdaddr_t *bd_addr, int local_role,
if (!interface_ready())
return BT_STATUS_NOT_READY;
- switch (local_role) {
- case BTPAN_ROLE_PANNAP:
- if (remote_role != BTPAN_ROLE_PANU)
- return BT_STATUS_UNSUPPORTED;
- break;
- case BTPAN_ROLE_PANU:
- if (remote_role != BTPAN_ROLE_PANNAP &&
- remote_role != BTPAN_ROLE_PANU)
- return BT_STATUS_UNSUPPORTED;
- break;
- default:
- return BT_STATUS_UNSUPPORTED;
- }
-
memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
cmd.local_role = local_role;
cmd.remote_role = remote_role;
diff --git a/android/pan.c b/android/pan.c
index f6e0ca9..78a1055 100644
--- a/android/pan.c
+++ b/android/pan.c
@@ -200,6 +200,25 @@ static void bt_pan_connect(const void *buf, uint16_t len)
DBG("");
+ switch (cmd->local_role) {
+ case HAL_PAN_ROLE_NAP:
+ if (cmd->remote_role != HAL_PAN_ROLE_PANU) {
+ status = HAL_STATUS_UNSUPPORTED;
+ goto failed;
+ }
+ break;
+ case HAL_PAN_ROLE_PANU:
+ if (cmd->remote_role != HAL_PAN_ROLE_NAP &&
+ cmd->remote_role != HAL_PAN_ROLE_PANU) {
+ status = HAL_STATUS_UNSUPPORTED;
+ goto failed;
+ }
+ break;
+ default:
+ status = HAL_STATUS_UNSUPPORTED;
+ goto failed;
+ }
+
android2bdaddr(&cmd->bdaddr, &dst);
l = g_slist_find_custom(devices, &dst, device_cmp);
--
1.8.5
^ permalink raw reply related
* [PATCH 7/8] android/pan: Move logic from HAL layer to daemon
From: Jakub Tyszkowski @ 2013-12-05 10:37 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1386239837-4102-1-git-send-email-jakub.tyszkowski@tieto.com>
HAL should contain as little logic as possible, but we should be doing
these checks on daemon side anyway.
---
android/hal-pan.c | 3 ---
android/pan.c | 16 ++++++++++++++--
2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/android/hal-pan.c b/android/hal-pan.c
index 6aaf8af..ec52672 100644
--- a/android/hal-pan.c
+++ b/android/hal-pan.c
@@ -74,9 +74,6 @@ static bt_status_t pan_enable(int local_role)
if (!interface_ready())
return BT_STATUS_NOT_READY;
- if (!(local_role == BTPAN_ROLE_PANU || local_role == BTPAN_ROLE_PANNAP))
- return BT_STATUS_UNSUPPORTED;
-
cmd.local_role = local_role;
return hal_ipc_cmd(HAL_SERVICE_ID_PAN, HAL_OP_PAN_ENABLE,
diff --git a/android/pan.c b/android/pan.c
index fe6ee26..f6e0ca9 100644
--- a/android/pan.c
+++ b/android/pan.c
@@ -280,9 +280,21 @@ failed:
static void bt_pan_enable(const void *buf, uint16_t len)
{
- DBG("Not Implemented");
+ const struct hal_cmd_pan_enable *cmd = buf;
+ uint8_t status;
+
+ switch (cmd->local_role) {
+ case HAL_PAN_ROLE_PANU:
+ case HAL_PAN_ROLE_NAP:
+ DBG("Not Implemented");
+ status = HAL_STATUS_FAILED;
+ break;
+ default:
+ status = HAL_STATUS_UNSUPPORTED;
+ break;
+ }
- ipc_send_rsp(HAL_SERVICE_ID_PAN, HAL_OP_PAN_ENABLE, HAL_STATUS_FAILED);
+ ipc_send_rsp(HAL_SERVICE_ID_PAN, HAL_OP_PAN_ENABLE, status);
}
static void bt_pan_get_role(const void *buf, uint16_t len)
--
1.8.5
^ permalink raw reply related
* [PATCH 6/8] android/a2dp: Unregister ipc handlers if init fails
From: Jakub Tyszkowski @ 2013-12-05 10:37 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1386239837-4102-1-git-send-email-jakub.tyszkowski@tieto.com>
Add ipc handlers cleanup if init fails. Send proper status if
already initialized.
---
android/hal-a2dp.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/android/hal-a2dp.c b/android/hal-a2dp.c
index cf39ba2..c898995 100644
--- a/android/hal-a2dp.c
+++ b/android/hal-a2dp.c
@@ -96,9 +96,13 @@ static bt_status_t disconnect(bt_bdaddr_t *bd_addr)
static bt_status_t init(btav_callbacks_t *callbacks)
{
struct hal_cmd_register_module cmd;
+ int ret;
DBG("");
+ if (interface_ready())
+ return BT_STATUS_DONE;
+
cbs = callbacks;
hal_ipc_register(HAL_SERVICE_ID_A2DP, ev_handlers,
@@ -106,8 +110,15 @@ static bt_status_t init(btav_callbacks_t *callbacks)
cmd.service_id = HAL_SERVICE_ID_A2DP;
- return hal_ipc_cmd(HAL_SERVICE_ID_CORE, HAL_OP_REGISTER_MODULE,
+ ret = hal_ipc_cmd(HAL_SERVICE_ID_CORE, HAL_OP_REGISTER_MODULE,
sizeof(cmd), &cmd, 0, NULL, NULL);
+
+ if (ret != BT_STATUS_SUCCESS) {
+ cbs = NULL;
+ hal_ipc_unregister(HAL_SERVICE_ID_A2DP);
+ }
+
+ return ret;
}
static void cleanup()
--
1.8.5
^ permalink raw reply related
* [PATCH 5/8] android/pan: Unregister ipc handlers if init fails
From: Jakub Tyszkowski @ 2013-12-05 10:37 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1386239837-4102-1-git-send-email-jakub.tyszkowski@tieto.com>
Add ipc handlers cleanup if init fails. Send proper status if
already initialized.
---
android/hal-pan.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/android/hal-pan.c b/android/hal-pan.c
index e7b8a20..6aaf8af 100644
--- a/android/hal-pan.c
+++ b/android/hal-pan.c
@@ -152,9 +152,13 @@ static bt_status_t pan_disconnect(const bt_bdaddr_t *bd_addr)
static bt_status_t pan_init(const btpan_callbacks_t *callbacks)
{
struct hal_cmd_register_module cmd;
+ int ret;
DBG("");
+ if (interface_ready())
+ return BT_STATUS_DONE;
+
cbs = callbacks;
hal_ipc_register(HAL_SERVICE_ID_PAN, ev_handlers,
@@ -162,8 +166,15 @@ static bt_status_t pan_init(const btpan_callbacks_t *callbacks)
cmd.service_id = HAL_SERVICE_ID_PAN;
- return hal_ipc_cmd(HAL_SERVICE_ID_CORE, HAL_OP_REGISTER_MODULE,
+ ret = hal_ipc_cmd(HAL_SERVICE_ID_CORE, HAL_OP_REGISTER_MODULE,
sizeof(cmd), &cmd, 0, NULL, NULL);
+
+ if (ret != BT_STATUS_SUCCESS) {
+ cbs = NULL;
+ hal_ipc_unregister(HAL_SERVICE_ID_PAN);
+ }
+
+ return ret;
}
static void pan_cleanup()
--
1.8.5
^ permalink raw reply related
* [PATCH 4/8] android/hidhost: Unregister ipc handlers if init fails
From: Jakub Tyszkowski @ 2013-12-05 10:37 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1386239837-4102-1-git-send-email-jakub.tyszkowski@tieto.com>
Add ipc handlers cleanup if init fails. Send proper status if
already initialized.
---
android/hal-hidhost.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
index 0573006..6a6b682 100644
--- a/android/hal-hidhost.c
+++ b/android/hal-hidhost.c
@@ -363,9 +363,13 @@ static bt_status_t send_data(bt_bdaddr_t *bd_addr, char *data)
static bt_status_t init(bthh_callbacks_t *callbacks)
{
struct hal_cmd_register_module cmd;
+ int ret;
DBG("");
+ if (interface_ready())
+ return BT_STATUS_DONE;
+
/* store reference to user callbacks */
cbacks = callbacks;
@@ -374,8 +378,15 @@ static bt_status_t init(bthh_callbacks_t *callbacks)
cmd.service_id = HAL_SERVICE_ID_HIDHOST;
- return hal_ipc_cmd(HAL_SERVICE_ID_CORE, HAL_OP_REGISTER_MODULE,
+ ret = hal_ipc_cmd(HAL_SERVICE_ID_CORE, HAL_OP_REGISTER_MODULE,
sizeof(cmd), &cmd, 0, NULL, NULL);
+
+ if (ret != BT_STATUS_SUCCESS) {
+ cbacks = NULL;
+ hal_ipc_unregister(HAL_SERVICE_ID_HIDHOST);
+ }
+
+ return ret;
}
static void cleanup(void)
--
1.8.5
^ permalink raw reply related
* [PATCH 3/8] android: Fix sending status on bluetooth init if already initialized
From: Jakub Tyszkowski @ 2013-12-05 10:37 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1386239837-4102-1-git-send-email-jakub.tyszkowski@tieto.com>
We should be sending BT_STATUS_DONE when calling init on already
initialized interface like Bluedroid does. This indicates that previosly
registered callbacks are still registered, not those passed with second
init call.
---
android/hal-bluetooth.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 87d6fc7..7cac15c 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -373,7 +373,7 @@ static int init(bt_callbacks_t *callbacks)
DBG("");
if (interface_ready())
- return BT_STATUS_SUCCESS;
+ return BT_STATUS_DONE;
bt_hal_cbacks = callbacks;
--
1.8.5
^ permalink raw reply related
* [PATCH 2/8] android: Update haltest tool entry in README
From: Jakub Tyszkowski @ 2013-12-05 10:37 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1386239837-4102-1-git-send-email-jakub.tyszkowski@tieto.com>
Update informations about 'adapter' interface being renamed to 'bluetooth' and
init being called on haltest startup by default.
---
android/README | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/android/README b/android/README
index 6c2c53f..68c3e9f 100644
--- a/android/README
+++ b/android/README
@@ -82,9 +82,12 @@ Testing tool
============
BT HAL test tools located in android/haltest is provided for HAL level testing
-of both Android daemon and HAL library. Start it and type 'adapter init' in
-prompt to initialize HAL library. On Android required bluetoothd service will
-be started automatically. On Linux it is required to start android/bluetoothd
-manually before init command timeout. To deinitialize HAL library and stop
-daemon type 'adapter cleanup'. Type 'help' for more information. Tab completion
-is also supported.
+of both Android daemon and HAL library. Start it with '-n' parameter and type
+'bluetooth init' in prompt to initialize HAL library. Running without parameter
+will make haltest try to initialize all services after start. On Android
+required bluetoothd service will be started automatically. On Linux it is
+required to start android/bluetoothd manually before init command timeout or
+use provided android/system-emulator, which takes care of launching daemon
+automatically on HAL library initialization. To deinitialize HAL library and
+stop daemon type 'bluetooth cleanup'. Type 'help' for more information. Tab
+completion is also supported.
--
1.8.5
^ permalink raw reply related
* [PATCH 1/8] android: Fix turning BT off during pairing
From: Jakub Tyszkowski @ 2013-12-05 10:37 UTC (permalink / raw)
To: linux-bluetooth
Not turning BT off in time due to actions queued in mgmt makes Android
unstable and locks Bluetooth UI controlls. This patch fixes this issue
by cancelling queued actions.
---
android/bluetooth.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index 6174b1f..e67864a 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -1982,6 +1982,9 @@ static void pair_device_complete(uint8_t status, uint16_t length,
DBG("status %u", status);
+ /*Data used for bond cancelling can be freed now*/
+ g_free(user_data);
+
/* On success bond state change will be send when new link key event
* is received */
if (status == MGMT_STATUS_SUCCESS)
@@ -1991,19 +1994,34 @@ static void pair_device_complete(uint8_t status, uint16_t length,
HAL_BOND_STATE_NONE);
}
+static void pair_device_cancelled(void *data)
+{
+ bdaddr_t *addr = data;
+
+ set_device_bond_state(addr, HAL_STATUS_FAILED, HAL_BOND_STATE_NONE);
+
+ g_free(data);
+}
+
static void handle_create_bond_cmd(const void *buf, uint16_t len)
{
const struct hal_cmd_create_bond *cmd = buf;
uint8_t status;
struct mgmt_cp_pair_device cp;
+ bdaddr_t *addr;
cp.io_cap = DEFAULT_IO_CAPABILITY;
cp.addr.type = BDADDR_BREDR;
android2bdaddr(cmd->bdaddr, &cp.addr.bdaddr);
+ addr = g_new(bdaddr_t, 1);
+ bacpy(addr, &cp.addr.bdaddr);
+
if (mgmt_send(mgmt_if, MGMT_OP_PAIR_DEVICE, adapter.index, sizeof(cp),
- &cp, pair_device_complete, NULL, NULL) == 0) {
+ &cp, pair_device_complete,
+ addr, pair_device_cancelled) == 0) {
status = HAL_STATUS_FAILED;
+ g_free(addr);
goto fail;
}
@@ -2253,6 +2271,8 @@ static void handle_disable_cmd(const void *buf, uint16_t len)
goto failed;
}
+ mgmt_cancel_index(mgmt_if, adapter.index);
+
if (!set_mode(MGMT_OP_SET_POWERED, 0x00)) {
status = HAL_STATUS_FAILED;
goto failed;
--
1.8.5
^ permalink raw reply related
* Re: [PATCH 19/31] Bluetooth: Implement returning of LE L2CAP credits
From: Vinicius Costa Gomes @ 2013-12-04 16:15 UTC (permalink / raw)
To: Johan Hedberg; +Cc: linux-bluetooth
In-Reply-To: <1386166287-13693-20-git-send-email-johan.hedberg@gmail.com>
Hi Johan,
On 16:11 Wed 04 Dec, Johan Hedberg wrote:
> From: Johan Hedberg <johan.hedberg@intel.com>
>
> We should return credits to the remote side whenever they fall below a
> certain level (in our case under half of the initially given amount).
>
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
> net/bluetooth/l2cap_core.c | 33 ++++++++++++++++++++++++++++++++-
> 1 file changed, 32 insertions(+), 1 deletion(-)
>
> diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
> index 8a1c528908fb..b99bdc53c57b 100644
> --- a/net/bluetooth/l2cap_core.c
> +++ b/net/bluetooth/l2cap_core.c
> @@ -2542,8 +2542,10 @@ int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len,
> }
>
> switch (chan->mode) {
> - case L2CAP_MODE_BASIC:
> case L2CAP_MODE_LE_FLOWCTL:
> + chan->tx_credits--;
> + /* fall through */
I guess that this change makes more sense in the next commit, no?
> + case L2CAP_MODE_BASIC:
> /* Check outgoing MTU */
> if (len > chan->omtu)
> return -EMSGSIZE;
> @@ -6608,6 +6610,32 @@ drop:
> return 0;
> }
>
Cheers,
--
Vinicius
^ permalink raw reply
* Re: [PATCH 10/31] Bluetooth: Refactor L2CAP connect rejection to its own function
From: Vinicius Costa Gomes @ 2013-12-04 16:14 UTC (permalink / raw)
To: Johan Hedberg; +Cc: linux-bluetooth
In-Reply-To: <1386166287-13693-11-git-send-email-johan.hedberg@gmail.com>
Hi Johan,
On 16:11 Wed 04 Dec, Johan Hedberg wrote:
> From: Johan Hedberg <johan.hedberg@intel.com>
>
> We'll need to have a separate code patch for LE based connection
Nitpick: 'path' instead of 'patch'.
> rejection so it's cleaner to move out the response construction code
> into its own function (and later a second one for LE).
>
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Cheers,
--
Vinicius
^ permalink raw reply
* Re: [PATCHv1 0/2] Introduce default adapter property
From: Timo Müller @ 2013-12-04 15:39 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth, Timo Mueller
In-Reply-To: <3146259.c398076Ovj@uw000953>
Hi Szymon,
Szymon Janc wrote, On 04.12.2013 09:32:
> Hi Timo,
>
>> From: Timo Mueller <timo.mueller@bmw-carit.de>
>>
>> Hi,
>>
>> the information about the default adapter is currently not available
>> through the D-Bus API of BlueZ. But as plugins can use this
>> information to choose the adapter they act upon it would be helpful
>> for users to be able to retrieve this information as well.
>>
>> For example the neard plugin uses this information to decide for which
>> adapter oob data is generated. Users could use the same information to
>> power the adapter before actually sending the oob data.
>
> I think this property is bluetoothd internal detail and should not be needed
> to be exported to user.
Alright. Is the default information needed at all? I might be missing
something but the default information seems to only be used by the
hostname, sixaxis and neard plugins. I don't know about sixaxis, but the
hostname plugin could also do without this information. If the neard
plugin would handle multiple adapters, then the default adapter property
could be dropped completely.
> If reason for this is scenario where multiple BT and
> NFC adapters are present and you need to match them in pairs, then proper
> solution would probably require extending neard agent interface. Neard plugin
> could be also made 'smarter' about multiple adapters eg. try to choose other
> controller if default one is not powered etc. Regarding changing power state
> of bt controller, I think this could be done by neard plugin itself (possible
> based on some static configuration or even runtime dbus setting...). It is on
> my 'TODO when have some spare time' list :)
Automatic powering, if enabled by 'configuration', sounds good to me.
Regarding the adapter selection, how about a runtime dbus setting to set
the adapter that the neard plugin is using? It could then behave as
bluetoothctl does right now. Choosing the first adapter on start and use
the selected adapter afterwards.
>
> It would be good if you could outline usecases you are trying to address with
> this change.
The use case was to only send the oob data when the device has not yet
been paired with the adapter that is used. On Android this wouldn't
interrupt the regular Android Beam behaviour (when sending an URL from
the browser for example). Of course this requires a unique ID that could
be requested via NFC and mapped to a BD_ADDR. Unfortunately this ID, as
just discussed in IRC, does not exist. So, admittedly this use case is
broken.
Best regards,
Timo
^ permalink raw reply
* Re: [RFC v3 00/12] LE auto connection and connection parameters
From: Andre Guedes @ 2013-12-04 14:35 UTC (permalink / raw)
To: linux-bluetooth@vger.kernel.org
In-Reply-To: <1384985340-2902-1-git-send-email-andre.guedes@openbossa.org>
Ping.
On Wed, Nov 20, 2013 at 7:08 PM, Andre Guedes
<andre.guedes@openbossa.org> wrote:
> Hi all,
>
> The main changes from the previous version are:
> * Debugfs interface to add auto connect address instead of new mgmt
> commands.
> * We always stop LE scanning in favor of connection establishment even if
> the controller supports scanning and connection at the same time.
> * Background scanning is now controlled in one single place (hci_update_
> background_scan function).
> * RCU was replaced by hdev->lock to protect hdev->le_conn_params list. After
> all the changes since the original version of this patch set, I realized
> we always operate on hdev->le_conn_params with hdev->lock held so there is
> no point in use RCU to protect this list.
>
> In order to test the LE auto connection mechanism please follow the
> instructions below.
>
> To add a new auto connection address we write on le_auto_conn file following
> the format <address> <address type> <auto_connect>.
>
> The <address type> values are:
> * 0 for public address
> * 1 for random address
>
> The <auto_connect> values are (for more details see struct hci_conn_params):
> * 0 for disabled
> * 1 for always
> * 2 for link loss
>
> So for instance, if you want the kernel autonomously establishes connections
> with device AA:BB:CC:DD:EE:FF (public address) every time the device enters in
> connectable mode (starts advertising), you should run the command:
> $ echo "AA:BB:CC:DD:EE:FF 0 1" > /sys/kernel/debug/bluetooth/hci0/le_auto_conn
>
> To get the list of connection parameters configured in kernel, read the
> le_auto_conn file:
> $ cat /sys/kernel/debug/bluetooth/hci0/le_auto_conn
>
> Finally, to clear the connection parameters list, write an empty string:
> $ echo "" > /sys/kernel/debug/bluetooth/hci0/le_auto_conn
>
> Regards,
>
> Andre Guedes
>
>
> Andre Guedes (12):
> Bluetooth: Save connection interval parameters in hci_conn
> Bluetooth: Group list_head fields from strcut hci_dev together
> Bluetooth: Introduce connection parameters list
> Bluetooth: Use connection parameters if any
> Bluetooth: Stop scanning on LE connection
> Bluetooth: Introduce hdev->pend_le_conn list
> Bluetooth: Introduce LE auto connection infrastructure
> Bluetooth: Re-enable background scan in case of error
> Bluetooth: Temporarily stop background scanning on discovery
> Bluetooth: Auto connection and power on
> Bleutooth: Add support for auto connect options
> Bluetooth: Add le_auto_conn file on debugfs
>
> include/net/bluetooth/hci_core.h | 43 +++++-
> net/bluetooth/hci_conn.c | 39 ++++-
> net/bluetooth/hci_core.c | 318 +++++++++++++++++++++++++++++++++++++++
> net/bluetooth/hci_event.c | 60 ++++++++
> net/bluetooth/mgmt.c | 25 ++-
> 5 files changed, 473 insertions(+), 12 deletions(-)
>
> --
> 1.8.4
>
^ permalink raw reply
* [PATCH 31/31] Bluetooth: Add debugfs controls for LE CoC MPS and Credits
From: Johan Hedberg @ 2013-12-04 14:11 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1386166287-13693-1-git-send-email-johan.hedberg@gmail.com>
From: Johan Hedberg <johan.hedberg@intel.com>
This patch adds entries to debugfs to control the values used for the
MPS and Credits for LE Flow Control Mode.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/l2cap_core.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index ccfee0194a2b..abcd17220706 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -49,6 +49,9 @@ static u8 l2cap_fixed_chan[8] = { L2CAP_FC_L2CAP | L2CAP_FC_CONNLESS, };
static LIST_HEAD(chan_list);
static DEFINE_RWLOCK(chan_list_lock);
+static u16 le_max_credits = L2CAP_LE_MAX_CREDITS;
+static u16 le_default_mps = L2CAP_LE_DEFAULT_MPS;
+
static struct sk_buff *l2cap_build_cmd(struct l2cap_conn *conn,
u8 code, u8 ident, u16 dlen, void *data);
static void l2cap_send_cmd(struct l2cap_conn *conn, u8 ident, u8 code, u16 len,
@@ -501,7 +504,7 @@ void l2cap_le_flowctl_init(struct l2cap_chan *chan)
chan->omtu = L2CAP_LE_MIN_MTU;
chan->mode = L2CAP_MODE_LE_FLOWCTL;
chan->tx_credits = 0;
- chan->rx_credits = L2CAP_LE_MAX_CREDITS;
+ chan->rx_credits = le_max_credits;
if (chan->imtu < L2CAP_LE_DEFAULT_MPS)
chan->mps = chan->imtu;
@@ -1214,7 +1217,7 @@ static void l2cap_le_flowctl_start(struct l2cap_chan *chan)
if (chan->imtu < L2CAP_LE_DEFAULT_MPS)
chan->mps = chan->imtu;
else
- chan->mps = L2CAP_LE_DEFAULT_MPS;
+ chan->mps = le_default_mps;
skb_queue_head_init(&chan->tx_q);
@@ -6829,10 +6832,10 @@ static void l2cap_chan_le_send_credits(struct l2cap_chan *chan)
/* We return more credits to the sender only after the amount of
* credits falls below half of the initial amount.
*/
- if (chan->rx_credits >= L2CAP_LE_MAX_CREDITS / 2)
+ if (chan->rx_credits >= le_max_credits / 2)
return;
- return_credits = L2CAP_LE_MAX_CREDITS - chan->rx_credits;
+ return_credits = le_max_credits - chan->rx_credits;
BT_DBG("chan %p returning %u credits to sender", chan, return_credits);
@@ -7446,6 +7449,11 @@ int __init l2cap_init(void)
l2cap_debugfs = debugfs_create_file("l2cap", 0444, bt_debugfs,
NULL, &l2cap_debugfs_fops);
+ debugfs_create_u16("l2cap_le_max_credits", 0444, bt_debugfs,
+ &le_max_credits);
+ debugfs_create_u16("l2cap_le_default_mps", 0444, bt_debugfs,
+ &le_default_mps);
+
return 0;
}
--
1.8.4.2
^ permalink raw reply related
* [PATCH 30/31] Bluetooth: Fix validating LE PSM values
From: Johan Hedberg @ 2013-12-04 14:11 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1386166287-13693-1-git-send-email-johan.hedberg@gmail.com>
From: Johan Hedberg <johan.hedberg@intel.com>
LE PSM values have different ranges than those for BR/EDR. The valid
ranges for fixed, SIG assigned values is 0x0001-0x007f and for dynamic
PSM values 0x0080-0x00ff. We need to ensure that bind() and connect()
calls conform to these ranges when operating on LE CoC sockets.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/l2cap_core.c | 15 +++++++++++++--
net/bluetooth/l2cap_sock.c | 40 +++++++++++++++++++++++++++++++---------
2 files changed, 44 insertions(+), 11 deletions(-)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index a1143127414a..ccfee0194a2b 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1861,6 +1861,18 @@ static struct l2cap_chan *l2cap_global_chan_by_psm(int state, __le16 psm,
return c1;
}
+static bool is_valid_psm(u16 psm, u8 dst_type)
+{
+ if (!psm)
+ return false;
+
+ if (bdaddr_type_is_le(dst_type))
+ return (psm < 0x00ff);
+
+ /* PSM must be odd and lsb of upper byte must be 0 */
+ return ((psm & 0x0101) == 0x0001);
+}
+
int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
bdaddr_t *dst, u8 dst_type)
{
@@ -1881,8 +1893,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
l2cap_chan_lock(chan);
- /* PSM must be odd and lsb of upper byte must be 0 */
- if ((__le16_to_cpu(psm) & 0x0101) != 0x0001 && !cid &&
+ if (!is_valid_psm(__le16_to_cpu(psm), dst_type) && !cid &&
chan->chan_type != L2CAP_CHAN_RAW) {
err = -EINVAL;
goto done;
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index c2424782c245..f4471fd6e99e 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -53,6 +53,32 @@ bool l2cap_is_socket(struct socket *sock)
}
EXPORT_SYMBOL(l2cap_is_socket);
+static int l2cap_validate_bredr_psm(u16 psm)
+{
+ /* PSM must be odd and lsb of upper byte must be 0 */
+ if ((psm & 0x0101) != 0x0001)
+ return -EINVAL;
+
+ /* Restrict usage of well-known PSMs */
+ if (psm < 0x1001 && !capable(CAP_NET_BIND_SERVICE))
+ return -EACCES;
+
+ return 0;
+}
+
+static int l2cap_validate_le_psm(u16 psm)
+{
+ /* Valid LE_PSM ranges are defined only until 0x00ff */
+ if (psm > 0x00ff)
+ return -EINVAL;
+
+ /* Restrict fixed, SIG assigned PSM values to CAP_NET_BIND_SERVICE */
+ if (psm <= 0x007f && !capable(CAP_NET_BIND_SERVICE))
+ return -EACCES;
+
+ return 0;
+}
+
static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen)
{
struct sock *sk = sock->sk;
@@ -94,17 +120,13 @@ static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen)
if (la.l2_psm) {
__u16 psm = __le16_to_cpu(la.l2_psm);
- /* PSM must be odd and lsb of upper byte must be 0 */
- if ((psm & 0x0101) != 0x0001) {
- err = -EINVAL;
- goto done;
- }
+ if (la.l2_bdaddr_type == BDADDR_BREDR)
+ err = l2cap_validate_bredr_psm(psm);
+ else
+ err = l2cap_validate_le_psm(psm);
- /* Restrict usage of well-known PSMs */
- if (psm < 0x1001 && !capable(CAP_NET_BIND_SERVICE)) {
- err = -EACCES;
+ if (err)
goto done;
- }
}
if (la.l2_cid)
--
1.8.4.2
^ permalink raw reply related
* [PATCH 29/31] Bluetooth: Fix CID ranges for LE CoC CID allocations
From: Johan Hedberg @ 2013-12-04 14:11 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1386166287-13693-1-git-send-email-johan.hedberg@gmail.com>
From: Johan Hedberg <johan.hedberg@intel.com>
LE CoC used differend CIC ranges than BR/EDR L2CAP. The start of the
range is the same (0x0040) but the range ends at 0x007f (unlike BR/EDR
where it goes all the way to 0xffff).
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
include/net/bluetooth/l2cap.h | 1 +
net/bluetooth/l2cap_core.c | 9 +++++++--
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index a4616eeeb8b5..ef6ca5fa8f5e 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -252,6 +252,7 @@ struct l2cap_conn_rsp {
#define L2CAP_CID_SMP 0x0006
#define L2CAP_CID_DYN_START 0x0040
#define L2CAP_CID_DYN_END 0xffff
+#define L2CAP_CID_LE_DYN_END 0x007f
/* connect/create channel results */
#define L2CAP_CR_SUCCESS 0x0000
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 8a74b36273b9..a1143127414a 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -213,9 +213,14 @@ int l2cap_add_scid(struct l2cap_chan *chan, __u16 scid)
static u16 l2cap_alloc_cid(struct l2cap_conn *conn)
{
- u16 cid = L2CAP_CID_DYN_START;
+ u16 cid, dyn_end;
- for (; cid < L2CAP_CID_DYN_END; cid++) {
+ if (conn->hcon->type == LE_LINK)
+ dyn_end = L2CAP_CID_LE_DYN_END;
+ else
+ dyn_end = L2CAP_CID_DYN_END;
+
+ for (cid = L2CAP_CID_DYN_START; cid < dyn_end; cid++) {
if (!__l2cap_get_chan_by_scid(conn, cid))
return cid;
}
--
1.8.4.2
^ permalink raw reply related
* [PATCH 28/31] Bluetooth: Fix clearing of chan->omtu for LE CoC channels
From: Johan Hedberg @ 2013-12-04 14:11 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1386166287-13693-1-git-send-email-johan.hedberg@gmail.com>
From: Johan Hedberg <johan.hedberg@intel.com>
The outgoing MTU should only be set upon channel creation to the initial
minimum value (23) or from a remote connect req/rsp PDU.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/l2cap_core.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 58fbb78a703f..8a74b36273b9 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -516,12 +516,12 @@ void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan)
switch (chan->chan_type) {
case L2CAP_CHAN_CONN_ORIENTED:
if (conn->hcon->type == LE_LINK) {
- /* LE connection */
- chan->omtu = L2CAP_DEFAULT_MTU;
- if (chan->dcid == L2CAP_CID_ATT)
+ if (chan->dcid == L2CAP_CID_ATT) {
+ chan->omtu = L2CAP_DEFAULT_MTU;
chan->scid = L2CAP_CID_ATT;
- else
+ } else {
chan->scid = l2cap_alloc_cid(conn);
+ }
} else {
/* Alloc CID for connection-oriented socket */
chan->scid = l2cap_alloc_cid(conn);
--
1.8.4.2
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox