Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH 04/10] Bluetooth: Use EIO code to report HCI error to userpace
From: Szymon Janc @ 2011-02-17 13:16 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: par-gunnar.p.hjalmdahl, henrik.possung, Szymon Janc
In-Reply-To: <1297948601-12723-1-git-send-email-szymon.janc@tieto.com>

Signed-off-by: Szymon Janc <szymon.janc@tieto.com>
---
 net/bluetooth/mgmt.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index aee1da6..dee82fe 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -1372,8 +1372,7 @@ int mgmt_pin_code_reply_complete(u16 index, bdaddr_t *bdaddr, u8 status)
 		return -ENOENT;
 
 	if (status != 0)
-		err = cmd_status(cmd->sk, MGMT_OP_PIN_CODE_REPLY, status, NULL,
-									0);
+		err = cmd_status(cmd->sk, MGMT_OP_PIN_CODE_REPLY, EIO, NULL, 0);
 	else
 		err = cmd_complete(cmd->sk, MGMT_OP_PIN_CODE_REPLY,
 						bdaddr, sizeof(*bdaddr));
@@ -1394,8 +1393,8 @@ int mgmt_pin_code_neg_reply_complete(u16 index, bdaddr_t *bdaddr, u8 status)
 		return -ENOENT;
 
 	if (status != 0)
-		err = cmd_status(cmd->sk, MGMT_OP_PIN_CODE_NEG_REPLY, status,
-								NULL, 0);
+		err = cmd_status(cmd->sk, MGMT_OP_PIN_CODE_NEG_REPLY, EIO, NULL,
+									0);
 	else
 		err = cmd_complete(cmd->sk, MGMT_OP_PIN_CODE_NEG_REPLY,
 						bdaddr, sizeof(*bdaddr));
-- 
1.7.0.4


^ permalink raw reply related

* [PATCH 03/10] Bluetooth: Add optional data parameter to mgmt_ev_cmd_status event
From: Szymon Janc @ 2011-02-17 13:16 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: par-gunnar.p.hjalmdahl, henrik.possung, Szymon Janc
In-Reply-To: <1297948601-12723-1-git-send-email-szymon.janc@tieto.com>

In managment interface command status event is used to report command failure.
Some commands (i.e. Read Local Oob Data) should be able to provide extra data
on failure.

Signed-off-by: Szymon Janc <szymon.janc@tieto.com>
---
 include/net/bluetooth/mgmt.h |    1 +
 net/bluetooth/mgmt.c         |   95 ++++++++++++++++++++++++------------------
 2 files changed, 56 insertions(+), 40 deletions(-)

diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index 44ac55c..a5cc1e0 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -170,6 +170,7 @@ struct mgmt_ev_cmd_complete {
 struct mgmt_ev_cmd_status {
 	__u8 status;
 	__le16 opcode;
+	__u8 data[0];
 } __packed;
 
 #define MGMT_EV_CONTROLLER_ERROR	0x0003
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index f5ef7a3..aee1da6 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -42,7 +42,8 @@ struct pending_cmd {
 
 LIST_HEAD(cmd_list);
 
-static int cmd_status(struct sock *sk, u16 cmd, u8 status)
+static int cmd_status(struct sock *sk, u16 cmd, u8 status, void *data,
+								size_t data_len)
 {
 	struct sk_buff *skb;
 	struct mgmt_hdr *hdr;
@@ -50,19 +51,22 @@ static int cmd_status(struct sock *sk, u16 cmd, u8 status)
 
 	BT_DBG("sock %p", sk);
 
-	skb = alloc_skb(sizeof(*hdr) + sizeof(*ev), GFP_ATOMIC);
+	skb = alloc_skb(sizeof(*hdr) + sizeof(*ev) + data_len, GFP_ATOMIC);
 	if (!skb)
 		return -ENOMEM;
 
 	hdr = (void *) skb_put(skb, sizeof(*hdr));
 
 	hdr->opcode = cpu_to_le16(MGMT_EV_CMD_STATUS);
-	hdr->len = cpu_to_le16(sizeof(*ev));
+	hdr->len = cpu_to_le16(sizeof(*ev) + data_len);
 
-	ev = (void *) skb_put(skb, sizeof(*ev));
+	ev = (void *) skb_put(skb, sizeof(*ev) + data_len);
 	ev->status = status;
 	put_unaligned_le16(cmd, &ev->opcode);
 
+	if (data)
+		memcpy(ev->data, data, data_len);
+
 	if (sock_queue_rcv_skb(sk, skb) < 0)
 		kfree_skb(skb);
 
@@ -168,7 +172,7 @@ static int read_controller_info(struct sock *sk, unsigned char *data, u16 len)
 	BT_DBG("sock %p", sk);
 
 	if (len != 2)
-		return cmd_status(sk, MGMT_OP_READ_INFO, EINVAL);
+		return cmd_status(sk, MGMT_OP_READ_INFO, EINVAL, NULL, 0);
 
 	dev_id = get_unaligned_le16(&cp->index);
 
@@ -176,7 +180,7 @@ static int read_controller_info(struct sock *sk, unsigned char *data, u16 len)
 
 	hdev = hci_dev_get(dev_id);
 	if (!hdev)
-		return cmd_status(sk, MGMT_OP_READ_INFO, ENODEV);
+		return cmd_status(sk, MGMT_OP_READ_INFO, ENODEV, NULL, 0);
 
 	hci_del_off_timer(hdev);
 
@@ -315,18 +319,18 @@ static int set_powered(struct sock *sk, unsigned char *data, u16 len)
 
 	hdev = hci_dev_get(dev_id);
 	if (!hdev)
-		return cmd_status(sk, MGMT_OP_SET_POWERED, ENODEV);
+		return cmd_status(sk, MGMT_OP_SET_POWERED, ENODEV, NULL, 0);
 
 	hci_dev_lock_bh(hdev);
 
 	up = test_bit(HCI_UP, &hdev->flags);
 	if ((cp->val && up) || (!cp->val && !up)) {
-		ret = cmd_status(sk, MGMT_OP_SET_POWERED, EALREADY);
+		ret = cmd_status(sk, MGMT_OP_SET_POWERED, EALREADY, NULL, 0);
 		goto failed;
 	}
 
 	if (mgmt_pending_find(MGMT_OP_SET_POWERED, dev_id)) {
-		ret = cmd_status(sk, MGMT_OP_SET_POWERED, EBUSY);
+		ret = cmd_status(sk, MGMT_OP_SET_POWERED, EBUSY, NULL, 0);
 		goto failed;
 	}
 
@@ -362,24 +366,27 @@ static int set_discoverable(struct sock *sk, unsigned char *data, u16 len)
 
 	hdev = hci_dev_get(dev_id);
 	if (!hdev)
-		return cmd_status(sk, MGMT_OP_SET_DISCOVERABLE, ENODEV);
+		return cmd_status(sk, MGMT_OP_SET_DISCOVERABLE, ENODEV, NULL,
+									0);
 
 	hci_dev_lock_bh(hdev);
 
 	if (!test_bit(HCI_UP, &hdev->flags)) {
-		err = cmd_status(sk, MGMT_OP_SET_DISCOVERABLE, ENETDOWN);
+		err = cmd_status(sk, MGMT_OP_SET_DISCOVERABLE, ENETDOWN, NULL,
+									0);
 		goto failed;
 	}
 
 	if (mgmt_pending_find(MGMT_OP_SET_DISCOVERABLE, dev_id) ||
 			mgmt_pending_find(MGMT_OP_SET_CONNECTABLE, dev_id)) {
-		err = cmd_status(sk, MGMT_OP_SET_DISCOVERABLE, EBUSY);
+		err = cmd_status(sk, MGMT_OP_SET_DISCOVERABLE, EBUSY, NULL, 0);
 		goto failed;
 	}
 
 	if (cp->val == test_bit(HCI_ISCAN, &hdev->flags) &&
 					test_bit(HCI_PSCAN, &hdev->flags)) {
-		err = cmd_status(sk, MGMT_OP_SET_DISCOVERABLE, EALREADY);
+		err = cmd_status(sk, MGMT_OP_SET_DISCOVERABLE, EALREADY, NULL,
+									0);
 		goto failed;
 	}
 
@@ -418,23 +425,25 @@ static int set_connectable(struct sock *sk, unsigned char *data, u16 len)
 
 	hdev = hci_dev_get(dev_id);
 	if (!hdev)
-		return cmd_status(sk, MGMT_OP_SET_CONNECTABLE, ENODEV);
+		return cmd_status(sk, MGMT_OP_SET_CONNECTABLE, ENODEV, NULL, 0);
 
 	hci_dev_lock_bh(hdev);
 
 	if (!test_bit(HCI_UP, &hdev->flags)) {
-		err = cmd_status(sk, MGMT_OP_SET_CONNECTABLE, ENETDOWN);
+		err = cmd_status(sk, MGMT_OP_SET_CONNECTABLE, ENETDOWN, NULL,
+									0);
 		goto failed;
 	}
 
 	if (mgmt_pending_find(MGMT_OP_SET_DISCOVERABLE, dev_id) ||
 			mgmt_pending_find(MGMT_OP_SET_CONNECTABLE, dev_id)) {
-		err = cmd_status(sk, MGMT_OP_SET_CONNECTABLE, EBUSY);
+		err = cmd_status(sk, MGMT_OP_SET_CONNECTABLE, EBUSY, NULL, 0);
 		goto failed;
 	}
 
 	if (cp->val == test_bit(HCI_PSCAN, &hdev->flags)) {
-		err = cmd_status(sk, MGMT_OP_SET_CONNECTABLE, EALREADY);
+		err = cmd_status(sk, MGMT_OP_SET_CONNECTABLE, EALREADY, NULL,
+									0);
 		goto failed;
 	}
 
@@ -505,7 +514,7 @@ static int set_pairable(struct sock *sk, unsigned char *data, u16 len)
 
 	hdev = hci_dev_get(dev_id);
 	if (!hdev)
-		return cmd_status(sk, MGMT_OP_SET_PAIRABLE, ENODEV);
+		return cmd_status(sk, MGMT_OP_SET_PAIRABLE, ENODEV, NULL, 0);
 
 	hci_dev_lock_bh(hdev);
 
@@ -578,7 +587,7 @@ static int add_uuid(struct sock *sk, unsigned char *data, u16 len)
 
 	hdev = hci_dev_get(dev_id);
 	if (!hdev)
-		return cmd_status(sk, MGMT_OP_ADD_UUID, ENODEV);
+		return cmd_status(sk, MGMT_OP_ADD_UUID, ENODEV, NULL, 0);
 
 	hci_dev_lock_bh(hdev);
 
@@ -622,7 +631,7 @@ static int remove_uuid(struct sock *sk, unsigned char *data, u16 len)
 
 	hdev = hci_dev_get(dev_id);
 	if (!hdev)
-		return cmd_status(sk, MGMT_OP_REMOVE_UUID, ENODEV);
+		return cmd_status(sk, MGMT_OP_REMOVE_UUID, ENODEV, NULL, 0);
 
 	hci_dev_lock_bh(hdev);
 
@@ -644,7 +653,7 @@ static int remove_uuid(struct sock *sk, unsigned char *data, u16 len)
 	}
 
 	if (found == 0) {
-		err = cmd_status(sk, MGMT_OP_REMOVE_UUID, ENOENT);
+		err = cmd_status(sk, MGMT_OP_REMOVE_UUID, ENOENT, NULL, 0);
 		goto unlock;
 	}
 
@@ -675,7 +684,7 @@ static int set_dev_class(struct sock *sk, unsigned char *data, u16 len)
 
 	hdev = hci_dev_get(dev_id);
 	if (!hdev)
-		return cmd_status(sk, MGMT_OP_SET_DEV_CLASS, ENODEV);
+		return cmd_status(sk, MGMT_OP_SET_DEV_CLASS, ENODEV, NULL, 0);
 
 	hci_dev_lock_bh(hdev);
 
@@ -706,7 +715,8 @@ static int set_service_cache(struct sock *sk, unsigned char *data, u16 len)
 
 	hdev = hci_dev_get(dev_id);
 	if (!hdev)
-		return cmd_status(sk, MGMT_OP_SET_SERVICE_CACHE, ENODEV);
+		return cmd_status(sk, MGMT_OP_SET_SERVICE_CACHE, ENODEV, NULL,
+									0);
 
 	hci_dev_lock_bh(hdev);
 
@@ -750,7 +760,7 @@ static int load_keys(struct sock *sk, unsigned char *data, u16 len)
 
 	hdev = hci_dev_get(dev_id);
 	if (!hdev)
-		return cmd_status(sk, MGMT_OP_LOAD_KEYS, ENODEV);
+		return cmd_status(sk, MGMT_OP_LOAD_KEYS, ENODEV, NULL, 0);
 
 	BT_DBG("hci%u debug_keys %u key_count %u", dev_id, cp->debug_keys,
 								key_count);
@@ -792,13 +802,13 @@ static int remove_key(struct sock *sk, unsigned char *data, u16 len)
 
 	hdev = hci_dev_get(dev_id);
 	if (!hdev)
-		return cmd_status(sk, MGMT_OP_REMOVE_KEY, ENODEV);
+		return cmd_status(sk, MGMT_OP_REMOVE_KEY, ENODEV, NULL, 0);
 
 	hci_dev_lock_bh(hdev);
 
 	err = hci_remove_link_key(hdev, &cp->bdaddr);
 	if (err < 0) {
-		err = cmd_status(sk, MGMT_OP_REMOVE_KEY, -err);
+		err = cmd_status(sk, MGMT_OP_REMOVE_KEY, -err, NULL, 0);
 		goto unlock;
 	}
 
@@ -839,23 +849,23 @@ static int disconnect(struct sock *sk, unsigned char *data, u16 len)
 
 	hdev = hci_dev_get(dev_id);
 	if (!hdev)
-		return cmd_status(sk, MGMT_OP_DISCONNECT, ENODEV);
+		return cmd_status(sk, MGMT_OP_DISCONNECT, ENODEV, NULL, 0);
 
 	hci_dev_lock_bh(hdev);
 
 	if (!test_bit(HCI_UP, &hdev->flags)) {
-		err = cmd_status(sk, MGMT_OP_DISCONNECT, ENETDOWN);
+		err = cmd_status(sk, MGMT_OP_DISCONNECT, ENETDOWN, NULL, 0);
 		goto failed;
 	}
 
 	if (mgmt_pending_find(MGMT_OP_DISCONNECT, dev_id)) {
-		err = cmd_status(sk, MGMT_OP_DISCONNECT, EBUSY);
+		err = cmd_status(sk, MGMT_OP_DISCONNECT, EBUSY, NULL, 0);
 		goto failed;
 	}
 
 	conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
 	if (!conn) {
-		err = cmd_status(sk, MGMT_OP_DISCONNECT, ENOTCONN);
+		err = cmd_status(sk, MGMT_OP_DISCONNECT, ENOTCONN, NULL, 0);
 		goto failed;
 	}
 
@@ -894,7 +904,7 @@ static int get_connections(struct sock *sk, unsigned char *data, u16 len)
 
 	hdev = hci_dev_get(dev_id);
 	if (!hdev)
-		return cmd_status(sk, MGMT_OP_GET_CONNECTIONS, ENODEV);
+		return cmd_status(sk, MGMT_OP_GET_CONNECTIONS, ENODEV, NULL, 0);
 
 	hci_dev_lock_bh(hdev);
 
@@ -948,12 +958,12 @@ static int pin_code_reply(struct sock *sk, unsigned char *data, u16 len)
 
 	hdev = hci_dev_get(dev_id);
 	if (!hdev)
-		return cmd_status(sk, MGMT_OP_DISCONNECT, ENODEV);
+		return cmd_status(sk, MGMT_OP_DISCONNECT, ENODEV, NULL, 0);
 
 	hci_dev_lock_bh(hdev);
 
 	if (!test_bit(HCI_UP, &hdev->flags)) {
-		err = cmd_status(sk, MGMT_OP_PIN_CODE_REPLY, ENETDOWN);
+		err = cmd_status(sk, MGMT_OP_PIN_CODE_REPLY, ENETDOWN, NULL, 0);
 		goto failed;
 	}
 
@@ -990,12 +1000,14 @@ static int pin_code_neg_reply(struct sock *sk, unsigned char *data, u16 len)
 
 	hdev = hci_dev_get(dev_id);
 	if (!hdev)
-		return cmd_status(sk, MGMT_OP_PIN_CODE_NEG_REPLY, ENODEV);
+		return cmd_status(sk, MGMT_OP_PIN_CODE_NEG_REPLY, ENODEV, NULL,
+									0);
 
 	hci_dev_lock_bh(hdev);
 
 	if (!test_bit(HCI_UP, &hdev->flags)) {
-		err = cmd_status(sk, MGMT_OP_PIN_CODE_NEG_REPLY, ENETDOWN);
+		err = cmd_status(sk, MGMT_OP_PIN_CODE_NEG_REPLY, ENETDOWN, NULL,
+									0);
 		goto failed;
 	}
 
@@ -1029,7 +1041,8 @@ static int set_io_capability(struct sock *sk, unsigned char *data, u16 len)
 
 	hdev = hci_dev_get(dev_id);
 	if (!hdev)
-		return cmd_status(sk, MGMT_OP_SET_IO_CAPABILITY, ENODEV);
+		return cmd_status(sk, MGMT_OP_SET_IO_CAPABILITY, ENODEV, NULL,
+									0);
 
 	hci_dev_lock_bh(hdev);
 
@@ -1132,7 +1145,7 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
 		break;
 	default:
 		BT_DBG("Unknown op %u", opcode);
-		err = cmd_status(sk, opcode, 0x01);
+		err = cmd_status(sk, opcode, 0x01, NULL, 0);
 		break;
 	}
 
@@ -1320,7 +1333,7 @@ int mgmt_disconnect_failed(u16 index)
 	if (!cmd)
 		return -ENOENT;
 
-	err = cmd_status(cmd->sk, MGMT_OP_DISCONNECT, EIO);
+	err = cmd_status(cmd->sk, MGMT_OP_DISCONNECT, EIO, NULL, 0);
 
 	list_del(&cmd->list);
 	mgmt_pending_free(cmd);
@@ -1359,7 +1372,8 @@ int mgmt_pin_code_reply_complete(u16 index, bdaddr_t *bdaddr, u8 status)
 		return -ENOENT;
 
 	if (status != 0)
-		err = cmd_status(cmd->sk, MGMT_OP_PIN_CODE_REPLY, status);
+		err = cmd_status(cmd->sk, MGMT_OP_PIN_CODE_REPLY, status, NULL,
+									0);
 	else
 		err = cmd_complete(cmd->sk, MGMT_OP_PIN_CODE_REPLY,
 						bdaddr, sizeof(*bdaddr));
@@ -1380,7 +1394,8 @@ int mgmt_pin_code_neg_reply_complete(u16 index, bdaddr_t *bdaddr, u8 status)
 		return -ENOENT;
 
 	if (status != 0)
-		err = cmd_status(cmd->sk, MGMT_OP_PIN_CODE_NEG_REPLY, status);
+		err = cmd_status(cmd->sk, MGMT_OP_PIN_CODE_NEG_REPLY, status,
+								NULL, 0);
 	else
 		err = cmd_complete(cmd->sk, MGMT_OP_PIN_CODE_NEG_REPLY,
 						bdaddr, sizeof(*bdaddr));
-- 
1.7.0.4


^ permalink raw reply related

* [PATCH 02/10] Bluetooth: Clean up hci_sniff_subrate_evt function
From: Szymon Janc @ 2011-02-17 13:16 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: par-gunnar.p.hjalmdahl, henrik.possung, Szymon Janc
In-Reply-To: <1297948601-12723-1-git-send-email-szymon.janc@tieto.com>

Signed-off-by: Szymon Janc <szymon.janc@tieto.com>
---
 net/bluetooth/hci_event.c |    9 ---------
 1 files changed, 0 insertions(+), 9 deletions(-)

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 09cb29e..1741936 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -2242,17 +2242,8 @@ static inline void hci_sync_conn_changed_evt(struct hci_dev *hdev, struct sk_buf
 static inline void hci_sniff_subrate_evt(struct hci_dev *hdev, struct sk_buff *skb)
 {
 	struct hci_ev_sniff_subrate *ev = (void *) skb->data;
-	struct hci_conn *conn;
 
 	BT_DBG("%s status %d", hdev->name, ev->status);
-
-	hci_dev_lock(hdev);
-
-	conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
-	if (conn) {
-	}
-
-	hci_dev_unlock(hdev);
 }
 
 static inline void hci_extended_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *skb)
-- 
1.7.0.4


^ permalink raw reply related

* [PATCH 01/10] Bluetooth: Use #include <linux/uaccess.h> instead of <asm/uaccess.h>
From: Szymon Janc @ 2011-02-17 13:16 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: par-gunnar.p.hjalmdahl, henrik.possung, Szymon Janc
In-Reply-To: <1297948601-12723-1-git-send-email-szymon.janc@tieto.com>

As warned by checkpatch.pl, use #include <linux/uaccess.h> instead of
<asm/uaccess.h>.

Signed-off-by: Szymon Janc <szymon.janc@tieto.com>
---
 net/bluetooth/mgmt.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index b2bda83..f5ef7a3 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -22,7 +22,7 @@
 
 /* Bluetooth HCI Management interface */
 
-#include <asm/uaccess.h>
+#include <linux/uaccess.h>
 #include <asm/unaligned.h>
 
 #include <net/bluetooth/bluetooth.h>
-- 
1.7.0.4


^ permalink raw reply related

* [PATCH 00/10] Support for OOB in mgmt interface
From: Szymon Janc @ 2011-02-17 13:16 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: par-gunnar.p.hjalmdahl, henrik.possung, Szymon Janc

Hi,

Following patches add support for OOB in mgmt interface. New commands added:
- mgmt_read_local_oob_data - read local oob data from chip and forward it to
  userspace
- mgmt_add/remote_oob_data - allow to store(or remove) remote oob data in
  kernel, this data is then used by kernel while pairing, storing that data
  in kernel minimize kernel<->userpace interaction on pairing (approche
  suggested by Johan on irc)

There are also patches that do some clean up work on files touched by new mgmt
commands (mostly issues reported by checkpatch).

"Add optional data parameter to mgmt_ev_cmd_status event" and
"Use EIO code to report HCI error to userpace." touch some issues with mgmt
interface that I've mentioned already on irc:
- On error mgmt_read_local_oob_data needs to report to userspace on which
  adapter request failed. In mgmt cmd_status is used to report errors so this
  adds optional data[0] parameter to it. This may also be usefull for other
  commands as well.
- It is not possible to distinguish in cmd status if error was from kernel
  or from HCI. Since in mgmt only kernel sends HCI commands their errors
  shouldn't be needed for userspace so report EIO to userspace on HCI error
  (if HCI error is needed for debugging, logs can be added on kernel side)


When mgmt interface to OOB will be agreed, I'll prepare patches for bluetoothd
as well.


Comments are welcome.


BR,
Szymon Janc
on behalf of ST-Ericsson

Szymon Janc (10):
  Bluetooth: Use #include <linux/uaccess.h> instead of <asm/uaccess.h>
  Bluetooth: Clean up hci_sniff_subrate_evt function
  Bluetooth: Add optional data parameter to mgmt_ev_cmd_status event
  Bluetooth: Use EIO code to report HCI error to userpace
  Bluetooth: Add read_local_oob_data management command
  Bluetooth: Add add/remove_remote_oob_data management commands
  Bluetooth: Fix code style issues and make checkpatch silent about
    hci_core.h
  Bluetooth: Fix code style issues and make checkpatch silent about
    hci_core.c
  Bluetooth: Fix code style issues, make checkpatch less noisy about
    hci_event.c
  Bluetooth: Log command and status parameters in command status event

 include/net/bluetooth/hci.h      |   24 ++++
 include/net/bluetooth/hci_core.h |  109 ++++++++++------
 include/net/bluetooth/mgmt.h     |   29 ++++
 net/bluetooth/hci_core.c         |  106 +++++++++++++--
 net/bluetooth/hci_event.c        |  201 +++++++++++++++++++++--------
 net/bluetooth/mgmt.c             |  263 ++++++++++++++++++++++++++++++++------
 6 files changed, 580 insertions(+), 152 deletions(-)


^ permalink raw reply

* Re: BUG in Mobile initiated pairing
From: Gustavo F. Padovan @ 2011-02-17 13:03 UTC (permalink / raw)
  To: sachin.athanikar; +Cc: linux-bluetooth
In-Reply-To: <23B1B83C3513ED4B8E8B2B9029CDE8EFC9388671C2@INDXM3113.dir.svc.accenture.com>

HI Sachin,

* sachin.athanikar@accenture.com <sachin.athanikar@accenture.com> [2011-02-17 14:17:47 +0530]:

> Hi Gustavo,
> 
> I have a question on pairing.
> 
> Is standard pairing working fine in BlueZ with all necessary events being generated?
> 
> I am using blueZ 4.88 on Ubuntu 10.10.
> 
> Adapter initiated pairing:
> -------------------------
> I am using agent.c which is part of test folder of BlueZ code base.
> Agent.c is used for adapter initiated pairing where I am able to get the response and event from BlueZ (observed in DBUS monitor).
> 
> 
> Mobile Phone initiated pairing:
> ------------------------------------------
> I have modified the agent.c in test folder of BlueZ to accept the mobile initiated pairing request.
> 
> When the pairing is initiated from Mobile phone, after the successful pairing, the property changed event for "Paired" is not generated. And even the agent is not released.

The "Paired" is generated, and not releasing the agent is the usual behaviour
for this case.

-- 
Gustavo F. Padovan
http://profusion.mobi

^ permalink raw reply

* Re: [PATCH v2] Fix no SEP if corresponding interface is disabled
From: Luiz Augusto von Dentz @ 2011-02-17 10:57 UTC (permalink / raw)
  To: Dmitriy Paliy; +Cc: linux-bluetooth
In-Reply-To: <1297935077-25540-2-git-send-email-dmitriy.paliy@nokia.com>

Hi,

On Thu, Feb 17, 2011 at 11:31 AM, Dmitriy Paliy <dmitriy.paliy@nokia.com> wrote:
> A2DP sink endpoint shall not be created if A2DP sink interface is disabled.
> Same holds for A2DP source endpoint and A2DP source interface.
>
> Such fixes bluetoothd crash when SDP record is registered and remote
> device tries to connect and stream to A2DP sink which is not initialized.
> Dereferencing of NULL happens in source_new_stream since device->source
> was not created.
> ---
>  audio/a2dp.c |   11 ++++++++++-
>  1 files changed, 10 insertions(+), 1 deletions(-)
>
> diff --git a/audio/a2dp.c b/audio/a2dp.c
> index 012fce8..3407d6f 100644
> --- a/audio/a2dp.c
> +++ b/audio/a2dp.c
> @@ -110,6 +110,8 @@ struct a2dp_server {
>        uint32_t source_record_id;
>        uint32_t sink_record_id;
>        uint16_t version;
> +       gboolean sink_enabled;
> +       gboolean source_enabled;
>  };
>
>  static GSList *servers = NULL;
> @@ -1480,6 +1482,7 @@ proceed:
>        else
>                server->version = 0x0102;
>
> +       server->source_enabled = source;
>        if (source) {
>                for (i = 0; i < sbc_srcs; i++)
>                        a2dp_add_sep(src, AVDTP_SEP_TYPE_SOURCE,
> @@ -1489,7 +1492,7 @@ proceed:
>                        a2dp_add_sep(src, AVDTP_SEP_TYPE_SOURCE,
>                                        A2DP_CODEC_MPEG12, delay_reporting, NULL);
>        }
> -
> +       server->sink_enabled = sink;
>        if (sink) {
>                for (i = 0; i < sbc_sinks; i++)
>                        a2dp_add_sep(src, AVDTP_SEP_TYPE_SINK,
> @@ -1551,6 +1554,12 @@ struct a2dp_sep *a2dp_add_sep(const bdaddr_t *src, uint8_t type,
>        if (server == NULL)
>                return NULL;
>
> +       if (type == AVDTP_SEP_TYPE_SINK && !server->sink_enabled)
> +               return NULL;
> +
> +       if (type == AVDTP_SEP_TYPE_SOURCE && !server->source_enabled)
> +               return NULL;
> +
>        sep = g_new0(struct a2dp_sep, 1);
>
>        if (endpoint) {

Looks much better.

-- 
Luiz Augusto von Dentz
Computer Engineer

^ permalink raw reply

* [PATCH v2] Fix no SEP if corresponding interface is disabled
From: Dmitriy Paliy @ 2011-02-17  9:31 UTC (permalink / raw)
  To: linux-bluetooth, luiz.dentz; +Cc: Dmitriy Paliy
In-Reply-To: <1297935077-25540-1-git-send-email-dmitriy.paliy@nokia.com>

A2DP sink endpoint shall not be created if A2DP sink interface is disabled.
Same holds for A2DP source endpoint and A2DP source interface.

Such fixes bluetoothd crash when SDP record is registered and remote
device tries to connect and stream to A2DP sink which is not initialized.
Dereferencing of NULL happens in source_new_stream since device->source
was not created.
---
 audio/a2dp.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/audio/a2dp.c b/audio/a2dp.c
index 012fce8..3407d6f 100644
--- a/audio/a2dp.c
+++ b/audio/a2dp.c
@@ -110,6 +110,8 @@ struct a2dp_server {
 	uint32_t source_record_id;
 	uint32_t sink_record_id;
 	uint16_t version;
+	gboolean sink_enabled;
+	gboolean source_enabled;
 };
 
 static GSList *servers = NULL;
@@ -1480,6 +1482,7 @@ proceed:
 	else
 		server->version = 0x0102;
 
+	server->source_enabled = source;
 	if (source) {
 		for (i = 0; i < sbc_srcs; i++)
 			a2dp_add_sep(src, AVDTP_SEP_TYPE_SOURCE,
@@ -1489,7 +1492,7 @@ proceed:
 			a2dp_add_sep(src, AVDTP_SEP_TYPE_SOURCE,
 					A2DP_CODEC_MPEG12, delay_reporting, NULL);
 	}
-
+	server->sink_enabled = sink;
 	if (sink) {
 		for (i = 0; i < sbc_sinks; i++)
 			a2dp_add_sep(src, AVDTP_SEP_TYPE_SINK,
@@ -1551,6 +1554,12 @@ struct a2dp_sep *a2dp_add_sep(const bdaddr_t *src, uint8_t type,
 	if (server == NULL)
 		return NULL;
 
+	if (type == AVDTP_SEP_TYPE_SINK && !server->sink_enabled)
+		return NULL;
+
+	if (type == AVDTP_SEP_TYPE_SOURCE && !server->source_enabled)
+		return NULL;
+
 	sep = g_new0(struct a2dp_sep, 1);
 
 	if (endpoint) {
-- 
1.7.1


^ permalink raw reply related

* [PATCH 0/1 v2] Fix no SEP if corresponding interface is disabled
From: Dmitriy Paliy @ 2011-02-17  9:31 UTC (permalink / raw)
  To: linux-bluetooth, luiz.dentz

Hi,

Patch reworked wrt comments of Luiz provided in previous submission. Here
check is done on enabled A2DP interfaces in audio.conf configuration file.
If interface is not enabled then corresponding SEPs will not be created.

BR,
Dmitriy


^ permalink raw reply

* [PATCH 2/2] Add workaround for devices which use absolute path in pbap Name header
From: Luiz Augusto von Dentz @ 2011-02-17  8:53 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1297932809-3460-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.dentz-von@nokia.com>

The pbap spec says:

"5.1.2 Name
The Name header shall contain the absolute path in the virtual folders
architecture of the PSE, appended with the name of the file representation of
one of the Phone Book Objects.
Example: telecom/pb.vcf or SIM1/telecom/pb.vcf for the main phone book
objects."

The example actually uses relative paths but text state absolute paths although
the OBEX specification says that the Name header is always relative to the
current path.
---
 plugins/pbap.c              |    6 +++++-
 plugins/phonebook-tracker.c |   26 +++++++++++++-------------
 2 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/plugins/pbap.c b/plugins/pbap.c
index b04dca9..61e7e42 100644
--- a/plugins/pbap.c
+++ b/plugins/pbap.c
@@ -658,7 +658,11 @@ static int pbap_get(struct obex_session *os, obex_object_t *obj,
 
 	if (strcmp(type, PHONEBOOK_TYPE) == 0) {
 		/* Always contains the absolute path */
-		path = g_strdup(name);
+		if (g_path_is_absolute(name))
+			path = g_strdup(name);
+		else
+			path = g_build_filename("/", name, NULL);
+
 		*stream = (params->maxlistcount == 0 ? FALSE : TRUE);
 	} else if (strcmp(type, VCARDLISTING_TYPE) == 0) {
 		/* Always relative */
diff --git a/plugins/phonebook-tracker.c b/plugins/phonebook-tracker.c
index eb38a46..8a0246a 100644
--- a/plugins/phonebook-tracker.c
+++ b/plugins/phonebook-tracker.c
@@ -934,15 +934,15 @@ static TrackerSparqlConnection *connection = NULL;
 
 static const char *name2query(const char *name)
 {
-	if (g_str_equal(name, "telecom/pb.vcf"))
+	if (g_str_equal(name, "/telecom/pb.vcf"))
 		return CONTACTS_QUERY_ALL;
-	else if (g_str_equal(name, "telecom/ich.vcf"))
+	else if (g_str_equal(name, "/telecom/ich.vcf"))
 		return INCOMING_CALLS_QUERY;
-	else if (g_str_equal(name, "telecom/och.vcf"))
+	else if (g_str_equal(name, "/telecom/och.vcf"))
 		return OUTGOING_CALLS_QUERY;
-	else if (g_str_equal(name, "telecom/mch.vcf"))
+	else if (g_str_equal(name, "/telecom/mch.vcf"))
 		return MISSED_CALLS_QUERY;
-	else if (g_str_equal(name, "telecom/cch.vcf"))
+	else if (g_str_equal(name, "/telecom/cch.vcf"))
 		return COMBINED_CALLS_QUERY;
 
 	return NULL;
@@ -950,15 +950,15 @@ static const char *name2query(const char *name)
 
 static const char *name2count_query(const char *name)
 {
-	if (g_str_equal(name, "telecom/pb.vcf"))
+	if (g_str_equal(name, "/telecom/pb.vcf"))
 		return CONTACTS_COUNT_QUERY;
-	else if (g_str_equal(name, "telecom/ich.vcf"))
+	else if (g_str_equal(name, "/telecom/ich.vcf"))
 		return INCOMING_CALLS_COUNT_QUERY;
-	else if (g_str_equal(name, "telecom/och.vcf"))
+	else if (g_str_equal(name, "/telecom/och.vcf"))
 		return OUTGOING_CALLS_COUNT_QUERY;
-	else if (g_str_equal(name, "telecom/mch.vcf"))
+	else if (g_str_equal(name, "/telecom/mch.vcf"))
 		return MISSED_CALLS_COUNT_QUERY;
-	else if (g_str_equal(name, "telecom/cch.vcf"))
+	else if (g_str_equal(name, "/telecom/cch.vcf"))
 		return COMBINED_CALLS_COUNT_QUERY;
 
 	return NULL;
@@ -1921,11 +1921,11 @@ done:
 	}
 
 	if (data->params->maxlistcount == 0) {
-		query = name2count_query("telecom/mch.vcf");
+		query = name2count_query("/telecom/mch.vcf");
 		col_amount = COUNT_QUERY_COL_AMOUNT;
 		pull_cb = pull_contacts_size;
 	} else {
-		query = name2query("telecom/mch.vcf");
+		query = name2query("/telecom/mch.vcf");
 		col_amount = PULL_QUERY_COL_AMOUNT;
 		pull_cb = pull_contacts;
 	}
@@ -1970,7 +1970,7 @@ int phonebook_pull_read(void *request)
 	if(!data)
 		return -ENOENT;
 
-	if (g_strcmp0(data->req_name, "telecom/mch.vcf") == 0) {
+	if (g_strcmp0(data->req_name, "/telecom/mch.vcf") == 0) {
 		query = NEW_MISSED_CALLS_LIST;
 		col_amount = PULL_QUERY_COL_AMOUNT;
 		pull_cb = pull_newmissedcalls;
-- 
1.7.1


^ permalink raw reply related

* [PATCH 1/2] Fix not responding to pbap GET when data is already cached
From: Luiz Augusto von Dentz @ 2011-02-17  8:53 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.dentz-von@nokia.com>

When data is cached but no stream/body is set the driver .write is never
called so no response is generated.
---
 src/obex.c |   35 +++++++++++++++--------------------
 1 files changed, 15 insertions(+), 20 deletions(-)

diff --git a/src/obex.c b/src/obex.c
index 98f0e4d..e6e22f5 100644
--- a/src/obex.c
+++ b/src/obex.c
@@ -813,30 +813,25 @@ static void cmd_get(struct obex_session *os, obex_t *obex, obex_object_t *obj)
 
 	/* Add body header */
 	hd.bs = NULL;
-	if (os->size == 0)
-		OBEX_ObjectAddHeader (obex, obj, OBEX_HDR_BODY,
-				hd, 0, OBEX_FL_FIT_ONE_PACKET);
-	else if (!stream) {
-		/* Asynchronous operation that doesn't use stream */
+	if (os->size == 0) {
+		OBEX_ObjectAddHeader(obex, obj, OBEX_HDR_BODY, hd, 0,
+						OBEX_FL_FIT_ONE_PACKET);
+		goto done;
+	}
+
+	if (stream)
+		/* Standard data stream */
+		OBEX_ObjectAddHeader(obex, obj, OBEX_HDR_BODY, hd, 0,
+						OBEX_FL_STREAM_START);
+
+	/* Try to write to stream and suspend the stream immediately
+	 * if no data available to send. */
+	err = obex_write_stream(os, obex, obj);
+	if (err == -EAGAIN) {
 		OBEX_SuspendRequest(obex, obj);
 		os->obj = obj;
 		os->driver->set_io_watch(os->object, handle_async_io, os);
 		return;
-	} else {
-		/* Standard data stream */
-		OBEX_ObjectAddHeader (obex, obj, OBEX_HDR_BODY,
-				hd, 0, OBEX_FL_STREAM_START);
-
-		/* Try to write to stream and suspend the stream immediately
-		 * if no data available to send. */
-		err = obex_write_stream(os, obex, obj);
-		if (err == -EAGAIN) {
-			OBEX_SuspendRequest(obex, obj);
-			os->obj = obj;
-			os->driver->set_io_watch(os->object, handle_async_io,
-									os);
-			return;
-		}
 	}
 
 done:
-- 
1.7.1


^ permalink raw reply related

* Re: bluetooth disabled with current 2.6.38-rc4
From: Justin Mattock @ 2011-02-17  5:19 UTC (permalink / raw)
  To: Gustavo F. Padovan; +Cc: Johan Hedberg, linux-bluetooth
In-Reply-To: <20110216193504.GH14085@joana>


On Feb 16, 2011, at 11:35 AM, Gustavo F. Padovan wrote:

> Hi Justin,
>
> * Justin Mattock <justinmattock@gmail.com> [2011-02-16 07:34:52  
> -0800]:
>
>>
>> On Feb 16, 2011, at 5:34 AM, Gustavo F. Padovan wrote:
>>
>>> Hi Justin,
>>>
>>> * Justin Mattock <justinmattock@gmail.com> [2011-02-15 19:26:12
>>> -0800]:
>>>
>>>>
>>>> On Feb 15, 2011, at 5:52 AM, Johan Hedberg wrote:
>>>>
>>>>> Hi Justin,
>>>>>
>>>>> On Sun, Feb 13, 2011, Justin Mattock wrote:
>>>>>> maybe I missed something, but my bluetooth is just not  
>>>>>> functioning
>>>>>> with
>>>>>> 2.6.38-rc4(works with 2.6.37-rc4)
>>>>>>
>>>>>> I've done a bisect on this, but was pointed to:
>>>>>> c0e45c1ca3162acb2e77b3d9e152ce6e7b6fa3f5
>>>>>> but doesn't look correct to me
>>>>>>
>>>>>> here is what I am seeing with the bluetooth-applet etc..:
>>>>>>
>>>>>> working correctly:
>>>>>> http://www.flickr.com/photos/44066293@N08/5443727238/
>>>>>>
>>>>>> not working:
>>>>>> http://www.flickr.com/photos/44066293@N08/5443124859/
>>>>>>
>>>>>> my /var/log/daemon.log shows:
>>>>>>
>>>>>> Feb 13 17:12:22 Linux-2 acpid: 1 client rule loaded
>>>>>> Feb 13 17:12:23 Linux-2 bluetoothd[1950]: HCI dev 0 registered
>>>>>> Feb 13 17:12:23 Linux-2 bluetoothd[1950]: Listening for HCI  
>>>>>> events
>>>>>> on hci0
>>>>>> Feb 13 17:12:23 Linux-2 bluetoothd[1950]: HCI dev 0 up
>>>>>> Feb 13 17:12:23 Linux-2 bluetoothd[1950]: Unable to find matching
>>>>>> adapter
>>>>>>
>>>>>> I can try at another bisect, but might take some time.. let me  
>>>>>> know
>>>>>> if there is something I can test
>>>>>> or do.
>>>>>
>>>>> Are you sure this is a kernel problem? There was a similar issue
>>>>> with
>>>>> BlueZ 4.86 or 4.87 which was already fixed. Could you try with  
>>>>> 4.88?
>>>>>
>>>>> Johan
>>>>
>>>> o.k. I built 4.88 and still had the issue show up, except this time
>>>> no
>>>> icon(instead of the icon, that is not lit up)..
>>>>
>>>>
>>>> anyways I did do another bisect and had better  
>>>> results(hopefully)this
>>>> time..:
>>>>
>>>> 23bb57633df97ede067ea26f3cdc8a7ba2cd8109 is the first bad commit
>>>> commit 23bb57633df97ede067ea26f3cdc8a7ba2cd8109
>>>> Author: Johan Hedberg <johan.hedberg@nokia.com>
>>>> Date:   Tue Dec 21 23:01:27 2010 +0200
>>>>
>>>>   Bluetooth: Fix __hci_request synchronization for hci_open_dev
>>>>
>>>>   The initialization function used by hci_open_dev (hci_init_req)
>>>> sends
>>>>   many different HCI commands. The __hci_request function should
>>>> only
>>>>   return when all of these commands have completed (or a timeout
>>>> occurs).
>>>>   Several of these commands cause hci_req_complete to be called
>>>> which
>>>>   causes __hci_request to return prematurely.
>>>>
>>>>   This patch fixes the issue by adding a new hdev->req_last_cmd
>>>> variable
>>>>   which is set during the initialization procedure. The
>>>> hci_req_complete
>>>>   function will no longer mark the request as complete until the
>>>> command
>>>>   matching hdev->req_last_cmd completes.
>>>>
>>>>   Signed-off-by: Johan Hedberg <johan.hedberg@nokia.com>
>>>>   Acked-by: Marcel Holtmann <marcel@holtmann.org>
>>>>   Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
>>>>
>>>> :040000 040000 e8d8ae5fab74b2ba73d0c52e7e09b30e5df8484e
>>>> 8d1409e8dc2206492cb86e8848c8c23aff182e2a M      include
>>>> :040000 040000 07fdb5f6ceadcfde12c46a3b5c82937b7dac892c
>>>> 8f3b08fbbc9fcd078d0f5224b8bc818eeb072dc4 M      net
>>>
>>> Can you please send the hcidump output? There should be a package
>>> for it in
>>> your distribution, if not get the bluez-hcidump from git.kernel.org
>>>
>>> -- 
>>> Gustavo F. Padovan
>>> http://profusion.mobi
>>
>>
>>
>> o.k...keep in mind I hve never really used that tool, but here goes:
>>
>> HCI sniffer - Bluetooth packet analyzer ver 2.0
>> device: hci0 snap_len: 1028 filter: 0xffffffffffffffff
>>> ACL data: handle 46 flags 0x02 dlen 12
>>    L2CAP(d): cid 0x0041 len 8 [psm 0]
>>      A1 02 00 11 FD 00 00 00
>>> ACL data: handle 46 flags 0x02 dlen 12
>>    L2CAP(d): cid 0x0041 len 8 [psm 0]
>>      A1 02 00 0A FF 00 00 00
>>> ACL data: handle 46 flags 0x02 dlen 12
>>    L2CAP(d): cid 0x0041 len 8 [psm 0]
>>      A1 02 00 1B FC 00 00 00
>>> ACL data: handle 46 flags 0x02 dlen 12
>>    L2CAP(d): cid 0x0041 len 8 [psm 0]
>>      A1 02 00 22 FE 00 00 00
>>> ACL data: handle 46 flags 0x02 dlen 12
>>    L2CAP(d): cid 0x0041 len 8 [psm 0]
>>      A1 02 00 27 FF 00 00 00
>>> ACL data: handle 46 flags 0x02 dlen 12
>>    L2CAP(d): cid 0x0041 len 8 [psm 0]
>>      A1 02 00 15 FF 00 00 00
>>> ACL data: handle 46 flags 0x02 dlen 12
>>    L2CAP(d): cid 0x0041 len 8 [psm 0]
>>      A1 02 00 2C 00 00 00 00
>>> ACL data: handle 46 flags 0x02 dlen 12
>>    L2CAP(d): cid 0x0041 len 8 [psm 0]
>>      A1 02 00 2B 00 00 00 00
>>> ACL data: handle 46 flags 0x02 dlen 12
>>    L2CAP(d): cid 0x0041 len 8 [psm 0]
>>      A1 02 00 14 FF 00 00 00
>>> ACL data: handle 46 flags 0x02 dlen 12
>>    L2CAP(d): cid 0x0041 len 8 [psm 0]
>>      A1 02 00 21 FD 00 00 00
>>> ACL data: handle 46 flags 0x02 dlen 12
>>    L2CAP(d): cid 0x0041 len 8 [psm 0]
>>      A1 02 00 18 FB 00 00 00
>>> ACL data: handle 46 flags 0x02 dlen 12
>>    L2CAP(d): cid 0x0041 len 8 [psm 0]
>>      A1 02 00 09 FD 00 00 00
>>> ACL data: handle 46 flags 0x02 dlen 12
>>    L2CAP(d): cid 0x0041 len 8 [psm 0]
>>      A1 02 00 0C FC 00 00 00
>>> ACL data: handle 46 flags 0x02 dlen 12
>>    L2CAP(d): cid 0x0041 len 8 [psm 0]
>>      A1 02 00 04 FE 00 00 00
>>> ACL data: handle 46 flags 0x02 dlen 12
>>    L2CAP(d): cid 0x0041 len 8 [psm 0]
>>
>> Justin P. Mattock
>>
>
> It seems that Bluetooth is working for you. If you really have an  
> issue,
> please run "bluetooth -nd" by hand and get the full debugs logs.  
> Also check
> if you can run "hciconfig -a".
>
>
> -- 
> Gustavo F. Padovan
> http://profusion.mobi


yeah it is working when I revert the commit that I bisected down to..
I will post what hcidump gives with the bad kernel then!!(as well as  
an other info that I can supply)

Justin P. Mattock


^ permalink raw reply

* Re: [PATCH v4 1/2] HID: Documentation for hidraw
From: Randy Dunlap @ 2011-02-17  0:56 UTC (permalink / raw)
  To: Alan Ott
  Cc: Jonathan Corbet, linux-doc, linux-kernel, jkosina, ospite,
	linux-input, linux-bluetooth, bgood
In-Reply-To: <4D5C202B.5030403@signal11.us>

On Wed, 16 Feb 2011 14:06:19 -0500 Alan Ott wrote:

> On 02/16/2011 09:12 AM, Jonathan Corbet wrote:
> >>   Documentation/hid/Makefile      |    8 ++
> >>   Documentation/hid/hid-example.c |  167 +++++++++++++++++++++++++++++++++++++++
> >>      
> > I believe we're trying to get code - especially runnable code - out of the
> > Documentation tree.  Should this go under samples/ or, if it's useful
> > enough, under tools/?
> >    
> 
> Hi Jon,
> 
> Not a problem. I'd say samples/ over tools/ for this stuff. I'll re-spin 
> and re-submit.

and then
Acked-by: Randy Dunlap <rdunlap@xenotime.net>

Thanks.
---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

^ permalink raw reply

* Re: [RFC 3/3 v2] Bluetooth: Send LE Connection Update Command
From: Gustavo F. Padovan @ 2011-02-16 23:15 UTC (permalink / raw)
  To: Claudio Takahasi; +Cc: linux-bluetooth
In-Reply-To: <1297896293-6057-1-git-send-email-claudio.takahasi@openbossa.org>

Hi Claudio,

* Claudio Takahasi <claudio.takahasi@openbossa.org> [2011-02-16 20:44:53 -0200]:

> If the new connection update parameter are accepted, the LE master
> host sends the LE Connection Update Command to its controller informing
> the new requested parameters.
> 
> Signed-off-by: Claudio Takahasi <claudio.takahasi@openbossa.org>
> ---
>  include/net/bluetooth/hci.h      |   11 +++++++++++
>  include/net/bluetooth/hci_core.h |    2 ++
>  net/bluetooth/hci_conn.c         |   20 ++++++++++++++++++++
>  net/bluetooth/l2cap_core.c       |    8 +++++++-
>  4 files changed, 40 insertions(+), 1 deletions(-)

Applied, thanks.

-- 
Gustavo F. Padovan
http://profusion.mobi

^ permalink raw reply

* [PATCH 4/4] Fix Device Name Characteristic
From: Claudio Takahasi @ 2011-02-16 23:07 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi
In-Reply-To: <1297897651-27731-1-git-send-email-claudio.takahasi@openbossa.org>

"Name" key value defined in the main.conf file can not be used without
substitution(hostname and adapter id). This patch adds Device Name
Characteristic with length 0 and updates the value when the adapter is
initialized.

Multiple adapters with different settings is not supported at the moment
by the attribute server. GAP characteristics values will be overwritten
if the host has multiple adapters.
---
 src/adapter.c       |    4 ++++
 src/attrib-server.c |    4 +---
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 2a19ace..dbae219 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2658,6 +2658,10 @@ gboolean adapter_init(struct btd_adapter *adapter)
 		expand_name(adapter->dev.name, MAX_NAME_LENGTH, main_opts.name,
 							adapter->dev_id);
 
+	if (main_opts.attrib_server)
+		attrib_gap_set(GATT_CHARAC_DEVICE_NAME,
+			(const uint8_t *) dev->name, strlen(dev->name));
+
 	sdp_init_services_list(&adapter->bdaddr);
 	load_drivers(adapter);
 	clear_blocked(adapter);
diff --git a/src/attrib-server.c b/src/attrib-server.c
index c1ca5ba..5e00601 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -802,7 +802,6 @@ static void register_core_services(void)
 {
 	uint8_t atval[256];
 	uuid_t uuid;
-	int len;
 	uint16_t appearance = 0x0000;
 
 	/* GAP service: primary service definition */
@@ -820,9 +819,8 @@ static void register_core_services(void)
 
 	/* GAP service: device name attribute */
 	sdp_uuid16_create(&uuid, GATT_CHARAC_DEVICE_NAME);
-	len = strlen(main_opts.name);
 	attrib_db_add(name_handle, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
-					(uint8_t *) main_opts.name, len);
+								NULL, 0);
 
 	/* GAP service: device appearance characteristic */
 	appearance_handle = 0x0008;
-- 
1.7.4.1


^ permalink raw reply related

* [PATCH 3/4] Update the Device Name characteristic when the local name has changed
From: Claudio Takahasi @ 2011-02-16 23:07 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi
In-Reply-To: <1297897651-27731-1-git-send-email-claudio.takahasi@openbossa.org>

---
 src/adapter.c       |    4 ++++
 src/attrib-server.c |   12 +++++++++---
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index e7b2495..2a19ace 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -892,6 +892,10 @@ void adapter_update_local_name(struct btd_adapter *adapter, const char *name)
 
 	strncpy(dev->name, name, MAX_NAME_LENGTH);
 
+	if (main_opts.attrib_server)
+		attrib_gap_set(GATT_CHARAC_DEVICE_NAME,
+			(const uint8_t *) dev->name, strlen(dev->name));
+
 	if (!adapter->name_stored) {
 		char *name_ptr = dev->name;
 
diff --git a/src/attrib-server.c b/src/attrib-server.c
index b4df137..c1ca5ba 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -72,6 +72,8 @@ static GIOChannel *le_io = NULL;
 static GSList *clients = NULL;
 static uint32_t sdp_handle = 0;
 
+/* GAP attribute handles */
+static uint16_t name_handle = 0x0000;
 static uint16_t appearance_handle = 0x0000;
 
 static uuid_t prim_uuid = {
@@ -809,16 +811,17 @@ static void register_core_services(void)
 	attrib_db_add(0x0001, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 2);
 
 	/* GAP service: device name characteristic */
+	name_handle = 0x0006;
 	sdp_uuid16_create(&uuid, GATT_CHARAC_UUID);
 	atval[0] = ATT_CHAR_PROPER_READ;
-	att_put_u16(0x0006, &atval[1]);
+	att_put_u16(name_handle, &atval[1]);
 	att_put_u16(GATT_CHARAC_DEVICE_NAME, &atval[3]);
 	attrib_db_add(0x0004, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 5);
 
 	/* GAP service: device name attribute */
 	sdp_uuid16_create(&uuid, GATT_CHARAC_DEVICE_NAME);
 	len = strlen(main_opts.name);
-	attrib_db_add(0x0006, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+	attrib_db_add(name_handle, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
 					(uint8_t *) main_opts.name, len);
 
 	/* GAP service: device appearance characteristic */
@@ -1011,11 +1014,14 @@ int attrib_gap_set(uint16_t uuid, const uint8_t *value, int len)
 	uuid_t u16;
 	uint16_t handle;
 
-	/* FIXME: Missing Name, Privacy and Reconnection Address */
+	/* FIXME: Missing Privacy and Reconnection Address */
 
 	sdp_uuid16_create(&u16, uuid);
 
 	switch (uuid) {
+	case GATT_CHARAC_DEVICE_NAME:
+		handle = name_handle;
+		break;
 	case GATT_CHARAC_APPEARANCE:
 		handle = appearance_handle;
 		break;
-- 
1.7.4.1


^ permalink raw reply related

* [PATCH 2/4] Update Device Appearance Characteristic based on device class
From: Claudio Takahasi @ 2011-02-16 23:07 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi
In-Reply-To: <1297897651-27731-1-git-send-email-claudio.takahasi@openbossa.org>

Appearance Characteristic value is still under discussion. Temporary
solution which maps directly the device class of device(major and minor)
into Device Characteristic value without shifting the two less significant
bits reserved to Format Type. The second byte of the device class
contains the major class in the 5 less significant bits.
---
 src/adapter.c       |    7 +++++++
 src/attrib-server.c |   28 ++++++++++++++++++++++++++--
 src/attrib-server.h |    2 ++
 3 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index f63d9e4..e7b2495 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -55,6 +55,7 @@
 #include "glib-helper.h"
 #include "agent.h"
 #include "storage.h"
+#include "attrib-server.h"
 #include "att.h"
 
 /* Flags Descriptions */
@@ -871,6 +872,12 @@ void btd_adapter_class_changed(struct btd_adapter *adapter, uint32_t new_class)
 
 	adapter->dev_class = new_class;
 
+	if (main_opts.attrib_server) {
+		/* Removes service class */
+		class[1] = class[1] & 0x1f;
+		attrib_gap_set(GATT_CHARAC_APPEARANCE, class, 2);
+	}
+
 	emit_property_changed(connection, adapter->path,
 				ADAPTER_INTERFACE, "Class",
 				DBUS_TYPE_UINT32, &new_class);
diff --git a/src/attrib-server.c b/src/attrib-server.c
index fe5d68c..b4df137 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -72,6 +72,8 @@ static GIOChannel *le_io = NULL;
 static GSList *clients = NULL;
 static uint32_t sdp_handle = 0;
 
+static uint16_t appearance_handle = 0x0000;
+
 static uuid_t prim_uuid = {
 			.type = SDP_UUID16,
 			.value.uuid16 = GATT_PRIM_SVC_UUID
@@ -820,16 +822,18 @@ static void register_core_services(void)
 					(uint8_t *) main_opts.name, len);
 
 	/* GAP service: device appearance characteristic */
+	appearance_handle = 0x0008;
 	sdp_uuid16_create(&uuid, GATT_CHARAC_UUID);
 	atval[0] = ATT_CHAR_PROPER_READ;
-	att_put_u16(0x0008, &atval[1]);
+	att_put_u16(appearance_handle, &atval[1]);
 	att_put_u16(GATT_CHARAC_APPEARANCE, &atval[3]);
 	attrib_db_add(0x0007, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 5);
 
 	/* GAP service: device appearance attribute */
 	sdp_uuid16_create(&uuid, GATT_CHARAC_APPEARANCE);
 	att_put_u16(appearance, &atval[0]);
-	attrib_db_add(0x0008, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 2);
+	attrib_db_add(appearance_handle, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+								atval, 2);
 
 	/* GATT service: primary service definition */
 	sdp_uuid16_create(&uuid, GATT_PRIM_SVC_UUID);
@@ -1001,3 +1005,23 @@ int attrib_db_del(uint16_t handle)
 
 	return 0;
 }
+
+int attrib_gap_set(uint16_t uuid, const uint8_t *value, int len)
+{
+	uuid_t u16;
+	uint16_t handle;
+
+	/* FIXME: Missing Name, Privacy and Reconnection Address */
+
+	sdp_uuid16_create(&u16, uuid);
+
+	switch (uuid) {
+	case GATT_CHARAC_APPEARANCE:
+		handle = appearance_handle;
+		break;
+	default:
+		return -ENOSYS;
+	}
+
+	return attrib_db_update(handle, &u16, value, len);
+}
diff --git a/src/attrib-server.h b/src/attrib-server.h
index ba90ff4..252700f 100644
--- a/src/attrib-server.h
+++ b/src/attrib-server.h
@@ -30,3 +30,5 @@ int attrib_db_add(uint16_t handle, uuid_t *uuid, int read_reqs, int write_reqs,
 int attrib_db_update(uint16_t handle, uuid_t *uuid, const uint8_t *value,
 								int len);
 int attrib_db_del(uint16_t handle);
+
+int attrib_gap_set(uint16_t uuid, const uint8_t *value, int len);
-- 
1.7.4.1


^ permalink raw reply related

* [PATCH 1/4] Add static Device Appearance Characteristic
From: Claudio Takahasi @ 2011-02-16 23:07 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

Declaration and definition of the Device Appearance Characteristic
defined in the GAP Characteristics for Low Energy section: Bluetooth
Core Specification, Volume 3, Part C, section 12.2.
---
 src/attrib-server.c |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/attrib-server.c b/src/attrib-server.c
index 85b39a8..fe5d68c 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -799,6 +799,7 @@ static void register_core_services(void)
 	uint8_t atval[256];
 	uuid_t uuid;
 	int len;
+	uint16_t appearance = 0x0000;
 
 	/* GAP service: primary service definition */
 	sdp_uuid16_create(&uuid, GATT_PRIM_SVC_UUID);
@@ -818,8 +819,17 @@ static void register_core_services(void)
 	attrib_db_add(0x0006, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
 					(uint8_t *) main_opts.name, len);
 
-	/* TODO: Implement Appearance characteristic. It is mandatory for
-	 * Peripheral/Central GAP roles. */
+	/* GAP service: device appearance characteristic */
+	sdp_uuid16_create(&uuid, GATT_CHARAC_UUID);
+	atval[0] = ATT_CHAR_PROPER_READ;
+	att_put_u16(0x0008, &atval[1]);
+	att_put_u16(GATT_CHARAC_APPEARANCE, &atval[3]);
+	attrib_db_add(0x0007, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 5);
+
+	/* GAP service: device appearance attribute */
+	sdp_uuid16_create(&uuid, GATT_CHARAC_APPEARANCE);
+	att_put_u16(appearance, &atval[0]);
+	attrib_db_add(0x0008, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 2);
 
 	/* GATT service: primary service definition */
 	sdp_uuid16_create(&uuid, GATT_PRIM_SVC_UUID);
-- 
1.7.4.1


^ permalink raw reply related

* [RFC 3/3 v2] Bluetooth: Send LE Connection Update Command
From: Claudio Takahasi @ 2011-02-16 22:44 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: padovan, Claudio Takahasi
In-Reply-To: <AANLkTinJmoaepBp+C6VnXSZ1P06CNYzJwJiTFJ7bAFDm@mail.gmail.com>

If the new connection update parameter are accepted, the LE master
host sends the LE Connection Update Command to its controller informing
the new requested parameters.

Signed-off-by: Claudio Takahasi <claudio.takahasi@openbossa.org>
---
 include/net/bluetooth/hci.h      |   11 +++++++++++
 include/net/bluetooth/hci_core.h |    2 ++
 net/bluetooth/hci_conn.c         |   20 ++++++++++++++++++++
 net/bluetooth/l2cap_core.c       |    8 +++++++-
 4 files changed, 40 insertions(+), 1 deletions(-)

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 6d4e116..a5f8c46 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -677,6 +677,17 @@ struct hci_cp_le_create_conn {
 
 #define HCI_OP_LE_CREATE_CONN_CANCEL	0x200e
 
+#define HCI_OP_LE_CONN_UPDATE		0x2013
+struct hci_cp_le_conn_update {
+	__le16   handle;
+	__le16   conn_interval_min;
+	__le16   conn_interval_max;
+	__le16   conn_latency;
+	__le16   supervision_timeout;
+	__le16   min_ce_len;
+	__le16   max_ce_len;
+} __packed;
+
 /* ---- HCI Events ---- */
 #define HCI_EV_INQUIRY_COMPLETE		0x01
 
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index ecd2acf..7ee921d 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -777,4 +777,6 @@ struct hci_sec_filter {
 
 void hci_req_complete(struct hci_dev *hdev, __u16 cmd, int result);
 
+void hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max,
+					u16 latency, u16 to_multiplier);
 #endif /* __HCI_CORE_H */
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index efcd2b5..a050a69 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -183,6 +183,26 @@ void hci_setup_sync(struct hci_conn *conn, __u16 handle)
 	hci_send_cmd(hdev, HCI_OP_SETUP_SYNC_CONN, sizeof(cp), &cp);
 }
 
+void hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max,
+					u16 latency, u16 to_multiplier)
+{
+	struct hci_cp_le_conn_update cp;
+	struct hci_dev *hdev = conn->hdev;
+
+	memset(&cp, 0, sizeof(cp));
+
+	cp.handle		= cpu_to_le16(conn->handle);
+	cp.conn_interval_min	= cpu_to_le16(min);
+	cp.conn_interval_max	= cpu_to_le16(max);
+	cp.conn_latency		= cpu_to_le16(latency);
+	cp.supervision_timeout	= cpu_to_le16(to_multiplier);
+	cp.min_ce_len		= cpu_to_le16(0x0001);
+	cp.max_ce_len		= cpu_to_le16(0x0001);
+
+	hci_send_cmd(hdev, HCI_OP_LE_CONN_UPDATE, sizeof(cp), &cp);
+}
+EXPORT_SYMBOL(hci_le_conn_update);
+
 /* Device _must_ be locked */
 void hci_sco_setup(struct hci_conn *conn, __u8 status)
 {
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index e0e7b82..bd31367 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -2529,6 +2529,7 @@ static inline int l2cap_conn_param_update_req(struct l2cap_conn *conn,
 	struct l2cap_conn_param_update_req *req;
 	struct l2cap_conn_param_update_rsp rsp;
 	u16 min, max, latency, to_multiplier, cmd_len;
+	int err;
 
 	if (!(hcon->link_mode & HCI_LM_MASTER))
 		return -EINVAL;
@@ -2547,7 +2548,9 @@ static inline int l2cap_conn_param_update_req(struct l2cap_conn *conn,
 						min, max, latency, to_multiplier);
 
 	memset(&rsp, 0, sizeof(rsp));
-	if (l2cap_check_conn_param(min, max, latency, to_multiplier))
+
+	err = l2cap_check_conn_param(min, max, latency, to_multiplier);
+	if (err)
 		rsp.result = cpu_to_le16(L2CAP_CONN_PARAM_REJECTED);
 	else
 		rsp.result = cpu_to_le16(L2CAP_CONN_PARAM_ACCEPTED);
@@ -2555,6 +2558,9 @@ static inline int l2cap_conn_param_update_req(struct l2cap_conn *conn,
 	l2cap_send_cmd(conn, cmd->ident, L2CAP_CONN_PARAM_UPDATE_RSP,
 							sizeof(rsp), &rsp);
 
+	if (!err)
+		hci_le_conn_update(hcon, min, max, latency, to_multiplier);
+
 	return 0;
 }
 
-- 
1.7.4.1


^ permalink raw reply related

* [PATCH 1/1] Fix gatttool to use existing MTU defines
From: Brian Gix @ 2011-02-16 22:25 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: johan.hedberg, padovan, anderson.lizardo, Brian Gix
In-Reply-To: <1297895146-20873-1-git-send-email-bgix@codeaurora.org>

---
 attrib/gatttool.c |    9 +++------
 1 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/attrib/gatttool.c b/attrib/gatttool.c
index 38636f9..7391eb3 100644
--- a/attrib/gatttool.c
+++ b/attrib/gatttool.c
@@ -44,10 +44,6 @@
 #include "gatt.h"
 #include "gatttool.h"
 
-/* Minimum MTU for ATT connections */
-#define ATT_MIN_MTU_LE		23
-#define ATT_MIN_MTU_L2CAP	48
-
 static gchar *opt_src = NULL;
 static gchar *opt_dst = NULL;
 static gchar *opt_value = NULL;
@@ -94,9 +90,10 @@ GIOChannel *do_connect(gchar *dst, gboolean le, BtIOConnect connect_cb)
 
 	/* This check is required because currently setsockopt() returns no
 	 * errors for MTU values smaller than the allowed minimum. */
-	if (opt_mtu != 0 && opt_mtu < (le ? ATT_MIN_MTU_LE : ATT_MIN_MTU_L2CAP)) {
+	if (opt_mtu != 0 &&
+		opt_mtu < (le ? ATT_DEFAULT_LE_MTU : ATT_DEFAULT_L2CAP_MTU)) {
 		g_printerr("MTU cannot be smaller than %d\n",
-				(le ? ATT_MIN_MTU_LE : ATT_MIN_MTU_L2CAP));
+				le ? ATT_DEFAULT_LE_MTU : ATT_DEFAULT_L2CAP_MTU);
 		return NULL;
 	}
 
-- 
1.7.1

-- 
Brian Gix
bgix@codeaurora.org
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum

^ permalink raw reply related

* [PATCH 0/1]
From: Brian Gix @ 2011-02-16 22:25 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: johan.hedberg, padovan, anderson.lizardo

Per Anderson request --> header based #defines used.

-- 
Brian Gix
bgix@codeaurora.org
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum

^ permalink raw reply

* Bluetooth Mighty Mouse buttons do not work
From: Mark Szentes-Wanner @ 2011-02-16 21:52 UTC (permalink / raw)
  To: linux-bluetooth

Hello,

my Apple Wireless Mighty Mouse stopped working years ago after a 
kernel&userland tools upgrade. More exactly, button 1, button 2 and button 3 
register no klicks, the rest works perfectly. There is an extensive bug 
report at Ubuntu's Launchpad:
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/319053?comments=all

The bug was filed more than 2 years ago. Is it worth waiting for a solution 
or will it never be fixed? Is it a lack of hardware to test? (Apple 
discontinued the product in 2009.)

Greetings,

Mark

^ permalink raw reply

* Re: [PATCH 1/1] Fix Min MTU to reflect values for both L2CAP & LE
From: Anderson Lizardo @ 2011-02-16 21:36 UTC (permalink / raw)
  To: Brian Gix; +Cc: linux-bluetooth, johan.hedberg, padovan
In-Reply-To: <1297890984-7809-2-git-send-email-bgix@codeaurora.org>

Hi Brian,

On Wed, Feb 16, 2011 at 6:16 PM, Brian Gix <bgix@codeaurora.org> wrote:
> -/* Minimum MTU for L2CAP connections over BR/EDR */
> -#define ATT_MIN_MTU_L2CAP 48
> +/* Minimum MTU for ATT connections */
> +#define ATT_MIN_MTU_LE         23
> +#define ATT_MIN_MTU_L2CAP      48

on attrib/att.h we have:

#define ATT_DEFAULT_L2CAP_MTU 48
#define ATT_DEFAULT_LE_MTU 23

I think It's better to reuse them. Johan has applied your patch
already, so you will need to create a fixup for it.

Regards,
-- 
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

^ permalink raw reply

* Re: [PATCH 1/1] Fix Min MTU to reflect values for both L2CAP & LE
From: Johan Hedberg @ 2011-02-16 21:23 UTC (permalink / raw)
  To: Brian Gix; +Cc: linux-bluetooth, padovan, anderson.lizardo
In-Reply-To: <1297890984-7809-2-git-send-email-bgix@codeaurora.org>

Hi Brian,

On Wed, Feb 16, 2011, Brian Gix wrote:
> ---
>  attrib/gatttool.c |    9 +++++----
>  1 files changed, 5 insertions(+), 4 deletions(-)

Pushed upstream. Thanks.

Johan

^ permalink raw reply

* [PATCH 3/3] Add gatttool enhancements for UPF
From: Brian Gix @ 2011-02-16 21:18 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: johan.hedberg, padovan, Brian Gix
In-Reply-To: <1297891081-27976-1-git-send-email-bgix@codeaurora.org>

Including seperating write-cmd from write-char, and enabling
--listen to stand on it's own if needed. (PTS tester)
---
 attrib/gatttool.c |   57 ++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 52 insertions(+), 5 deletions(-)

diff --git a/attrib/gatttool.c b/attrib/gatttool.c
index 8e8ed8e..054adb1 100644
--- a/attrib/gatttool.c
+++ b/attrib/gatttool.c
@@ -63,6 +63,7 @@ static gboolean opt_listen = FALSE;
 static gboolean opt_char_desc = FALSE;
 static gboolean opt_le = FALSE;
 static gboolean opt_char_write = FALSE;
+static gboolean opt_char_cmd = FALSE;
 static GMainLoop *event_loop;
 static gboolean got_error = FALSE;
 
@@ -90,9 +91,9 @@ static GIOChannel *do_connect(gboolean le)
 
 	/* This check is required because currently setsockopt() returns no
 	 * errors for MTU values smaller than the allowed minimum. */
-	if (opt_mtu != 0 && opt_mtu < ATT_MIN_MTU_L2CAP) {
+	if (opt_mtu != 0 && opt_mtu < 23) {
 		g_printerr("MTU cannot be smaller than %d\n",
-							ATT_MIN_MTU_L2CAP);
+							23);
 		return NULL;
 	}
 
@@ -277,6 +278,14 @@ static gboolean characteristics(gpointer user_data)
 	return FALSE;
 }
 
+static void char_write_cb(guint8 status, const guint8 *pdu, guint16 plen,
+							gpointer user_data)
+{
+	if (plen == 1)
+		g_print("Attrib Write Succeeded\n");
+	else
+		g_printerr("Attrib Write failed: %s\n", att_ecode2str(status));
+}
 static void char_read_cb(guint8 status, const guint8 *pdu, guint16 plen,
 							gpointer user_data)
 {
@@ -427,7 +436,40 @@ static gboolean characteristics_write(gpointer user_data)
 		goto error;
 	}
 
+	gatt_write_char(attrib, opt_handle, value, len, char_write_cb, value);
+	gatt_read_char(attrib, opt_handle, char_read_cb, attrib);
+
+	return FALSE;
+
+error:
+	g_main_loop_quit(event_loop);
+	return FALSE;
+}
+
+static gboolean characteristics_cmd(gpointer user_data)
+{
+	GAttrib *attrib = user_data;
+	uint8_t *value;
+	size_t len;
+
+	if (opt_handle <= 0) {
+		g_printerr("A valid handle is required\n");
+		goto error;
+	}
+
+	if (opt_value == NULL || opt_value[0] == '\0') {
+		g_printerr("A value is required\n");
+		goto error;
+	}
+
+	len = attr_data_from_string(opt_value, &value);
+	if (len == 0) {
+		g_printerr("Invalid value\n");
+		goto error;
+	}
+
 	gatt_write_cmd(attrib, opt_handle, value, len, mainloop_quit, value);
+	gatt_read_char(attrib, opt_handle, char_read_cb, attrib);
 
 	return FALSE;
 
@@ -531,6 +573,8 @@ static GOptionEntry gatt_options[] = {
 		"Characteristics Value/Descriptor Read", NULL },
 	{ "char-write", 0, 0, G_OPTION_ARG_NONE, &opt_char_write,
 		"Characteristics Value Write", NULL },
+	{ "char-cmd", 0, 0, G_OPTION_ARG_NONE, &opt_char_cmd,
+		"Characteristics Value Cmd", NULL },
 	{ "char-desc", 0, 0, G_OPTION_ARG_NONE, &opt_char_desc,
 		"Characteristics Descriptor Discovery", NULL },
 	{ "listen", 0, 0, G_OPTION_ARG_NONE, &opt_listen,
@@ -561,7 +605,7 @@ int main(int argc, char *argv[])
 	GError *gerr = NULL;
 	GAttrib *attrib;
 	GIOChannel *chan;
-	GSourceFunc callback;
+	GSourceFunc callback = NULL;
 
 	context = g_option_context_new(NULL);
 	g_option_context_add_main_entries(context, options, NULL);
@@ -602,9 +646,11 @@ int main(int argc, char *argv[])
 		callback = characteristics_read;
 	else if (opt_char_write)
 		callback = characteristics_write;
+	else if (opt_char_cmd)
+		callback = characteristics_cmd;
 	else if (opt_char_desc)
 		callback = characteristics_desc;
-	else {
+	else if (!opt_listen) {
 		gchar *help = g_option_context_get_help(context, TRUE, NULL);
 		g_print("%s\n", help);
 		g_free(help);
@@ -625,7 +671,8 @@ int main(int argc, char *argv[])
 	if (opt_listen)
 		g_idle_add(listen_start, attrib);
 
-	g_idle_add(callback, attrib);
+	if (callback)
+		g_idle_add(callback, attrib);
 
 	g_main_loop_run(event_loop);
 
-- 
1.7.1

--
Brian Gix
bgix@codeaurora.org
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum 

^ permalink raw reply related


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox