Skip to contentSkip to conversation

Bluetooth: Implement automatic setup procedure for local adapters

PATCH In review [email protected] 2 participants 13 messages Jan 4, 2011 – Jan 25, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/11 Bluetooth: Implement automatic setup procedure for local adapters

From: Johan Hedberg <[email protected]>

This patch implements automatic initialization of basic information about newly registered Bluetooth adapters. E.g. the address and features are always needed so it makes sense for the kernel to automatically power on adapters and read this information. A new HCI_SETUP flag is added to track this state.

In order to not consume unnecessary amounts of power if there isn't a user space available that could switch the adapter back off, a timer is added to do this automatically as long as no Bluetooth user space seems to be present. A new HCI_AUTO_OFF flag is added that user space needs to clear to avoid the automatic power off.

Additionally, the management interface index_added event is moved to the end of the HCI_SETUP stage so a user space supporting the managment inteface has all the necessary information available for fetching when it gets notified of a new adapter. The HCI_DEV_REG event is kept in the same place as before since existing HCI raw socket based user space versions depend on seeing the kernels initialization sequence (hci_init_req) to determine when the adapter is ready for use.

---
 include/net/bluetooth/hci.h      |    3 ++
 include/net/bluetooth/hci_core.h |    6 +++
 net/bluetooth/hci_core.c         |   64 ++++++++++++++++++++++++++++++++++++-
 net/bluetooth/mgmt.c             |    8 +++++
 4 files changed, 79 insertions(+), 2 deletions(-)
include/net/bluetooth/hci.h +3 -0
index 29a7a8c..6469d67 100644
@@ -76,6 +76,9 @@ enum {
 	HCI_INQUIRY,
 
 	HCI_RAW,
+
+	HCI_SETUP,
+	HCI_AUTO_OFF,
 };
 
 /* HCI ioctl defines */
include/net/bluetooth/hci_core.h +6 -0
index a29feb0..dfbb325 100644
@@ -114,6 +114,10 @@ struct hci_dev {
 
 	struct workqueue_struct	*workqueue;
 
+	struct work_struct	power_on;
+	struct work_struct	power_off;
+	struct timer_list	off_timer;
+
 	struct tasklet_struct	cmd_task;
 	struct tasklet_struct	rx_task;
 	struct tasklet_struct	tx_task;
@@ -436,6 +440,8 @@ int hci_inquiry(void __user *arg);
 struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev, bdaddr_t *bdaddr);
 int hci_blacklist_clear(struct hci_dev *hdev);
 
+void hci_del_off_timer(struct hci_dev *hdev);
+
 void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
 
 int hci_recv_frame(struct sk_buff *skb);
net/bluetooth/hci_core.c +62 -2

106 lines not on this page · raw message

net/bluetooth/mgmt.c +8 -0
index f827fd9..2a88b35 100644
@@ -127,6 +127,12 @@ static int read_index_list(struct sock *sk)
 	i = 0;
 	list_for_each(p, &hci_dev_list) {
 		struct hci_dev *d = list_entry(p, struct hci_dev, list);
+
+		hci_del_off_timer(d);
+
+		if (test_bit(HCI_SETUP, &d->flags))
+			continue;
+
 		put_unaligned_le16(d->id, &rp->index[i++]);
 		BT_DBG("Added hci%u", d->id);
 	}
@@ -178,6 +184,8 @@ static int read_controller_info(struct sock *sk, unsigned char *data, u16 len)
 		return cmd_status(sk, MGMT_OP_READ_INFO, ENODEV);
 	}
 
+	hci_del_off_timer(hdev);
+
 	hci_dev_lock_bh(hdev);
 
 	put_unaligned_le16(hdev->id, &rp->index);
Signature · 1 line
1.7.2.3
#1 lore raw

PATCH 2/11 Bluetooth: Add support for management powered event

From: Johan Hedberg <[email protected]>

This patch adds support for the powered event that's used to indicate to userspace when the powered state of a local adapter changes.

---
 include/net/bluetooth/hci_core.h |    1 +
 include/net/bluetooth/mgmt.h     |    6 ++++++
 net/bluetooth/hci_core.c         |    4 ++++
 net/bluetooth/mgmt.c             |   10 ++++++++++
 4 files changed, 21 insertions(+), 0 deletions(-)
include/net/bluetooth/hci_core.h +1 -0
index dfbb325..6449ff8 100644
@@ -671,6 +671,7 @@ void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb);
 int mgmt_control(struct sock *sk, struct msghdr *msg, size_t len);
 int mgmt_index_added(u16 index);
 int mgmt_index_removed(u16 index);
+int mgmt_powered(u16 index, u8 powered);
 
 /* HCI info for socket */
 #define hci_pi(sk) ((struct hci_pinfo *) sk)
include/net/bluetooth/mgmt.h +6 -0
index ca29c13..0ac1520 100644
@@ -85,3 +85,9 @@ struct mgmt_ev_index_added {
 struct mgmt_ev_index_removed {
 	__le16 index;
 } __packed;
+
+#define MGMT_EV_POWERED			0x0006
+struct mgmt_ev_powered {
+	__le16 index;
+	__u8 powered;
+} __packed;
net/bluetooth/hci_core.c +4 -0
index d5a315c..36b08a4 100644
@@ -535,6 +535,8 @@ int hci_dev_open(__u16 dev)
 		hci_dev_hold(hdev);
 		set_bit(HCI_UP, &hdev->flags);
 		hci_notify(hdev, HCI_DEV_UP);
+		if (!test_bit(HCI_SETUP, &hdev->flags))
+			mgmt_powered(hdev->id, 1);
 	} else {
 		/* Init failed, cleanup */
 		tasklet_kill(&hdev->rx_task);
@@ -616,6 +618,8 @@ static int hci_dev_do_close(struct hci_dev *hdev)
 	 * and no tasks are scheduled. */
 	hdev->close(hdev);
 
+	mgmt_powered(hdev->id, 0);
+
 	/* Clear flags */
 	hdev->flags = 0;
 
net/bluetooth/mgmt.c +10 -0
index 2a88b35..b7aeb7c 100644
@@ -314,3 +314,13 @@ int mgmt_index_removed(u16 index)
 
 	return mgmt_event(MGMT_EV_INDEX_REMOVED, &ev, sizeof(ev));
 }
+
+int mgmt_powered(u16 index, u8 powered)
+{
+	struct mgmt_ev_powered ev;
+
+	put_unaligned_le16(index, &ev.index);
+	ev.powered = powered;
+
+	return mgmt_event(MGMT_EV_POWERED, &ev, sizeof(ev));
+}
Signature · 1 line
1.7.2.3
#2 lore raw

PATCH 3/11 Bluetooth: Add support for set_powered management command

In reply to [email protected]

From: Johan Hedberg <[email protected]>

This patch adds a set_powered command to the management interface through which the powered state of local adapters can be controlled.

---
 include/net/bluetooth/hci_core.h |    3 +-
 include/net/bluetooth/mgmt.h     |   10 ++
 net/bluetooth/hci_core.c         |    4 +-
 net/bluetooth/hci_event.c        |    2 +-
 net/bluetooth/hci_sock.c         |    6 +-
 net/bluetooth/mgmt.c             |  200 +++++++++++++++++++++++++++++++++++++-
 6 files changed, 215 insertions(+), 10 deletions(-)
include/net/bluetooth/hci_core.h +2 -1
index 6449ff8..b6078ba 100644
@@ -665,7 +665,8 @@ void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode);
 void hci_si_event(struct hci_dev *hdev, int type, int dlen, void *data);
 
 /* ----- HCI Sockets ----- */
-void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb);
+void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb,
+							struct sock *skip_sk);
 
 /* Management interface */
 int mgmt_control(struct sock *sk, struct msghdr *msg, size_t len);
include/net/bluetooth/mgmt.h +10 -0
index 0ac1520..81ef789 100644
@@ -58,6 +58,16 @@ struct mgmt_rp_read_info {
 	__u16 hci_rev;
 } __packed;
 
+#define MGMT_OP_SET_POWERED		0x0005
+struct mgmt_cp_set_powered {
+	__le16 index;
+	__u8 powered;
+} __packed;
+struct mgmt_rp_set_powered {
+	__le16 index;
+	__u8 powered;
+} __packed;
+
 #define MGMT_EV_CMD_COMPLETE		0x0001
 struct mgmt_ev_cmd_complete {
 	__le16 opcode;
net/bluetooth/hci_core.c +2 -2
index 36b08a4..de40a8a 100644
@@ -1373,7 +1373,7 @@ static int hci_send_frame(struct sk_buff *skb)
 		/* Time stamp */
 		__net_timestamp(skb);
 
-		hci_send_to_sock(hdev, skb);
+		hci_send_to_sock(hdev, skb, NULL);
 	}
 
 	/* Get rid of skb owner, prior to sending to the driver. */
@@ -1760,7 +1760,7 @@ static void hci_rx_task(unsigned long arg)
 	while ((skb = skb_dequeue(&hdev->rx_q))) {
 		if (atomic_read(&hdev->promisc)) {
 			/* Send copy to the sockets */
-			hci_send_to_sock(hdev, skb);
+			hci_send_to_sock(hdev, skb, NULL);
 		}
 
 		if (test_bit(HCI_RAW, &hdev->flags)) {
net/bluetooth/hci_event.c +1 -1
index 3810017..b19b061 100644
@@ -2082,6 +2082,6 @@ void hci_si_event(struct hci_dev *hdev, int type, int dlen, void *data)
 
 	bt_cb(skb)->pkt_type = HCI_EVENT_PKT;
 	skb->dev = (void *) hdev;
-	hci_send_to_sock(hdev, skb);
+	hci_send_to_sock(hdev, skb, NULL);
 	kfree_skb(skb);
 }
net/bluetooth/hci_sock.c +5 -1
index 29827c7..d50e961 100644
@@ -85,7 +85,8 @@ static struct bt_sock_list hci_sk_list = {
 };
 
 /* Send frame to RAW socket */
-void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb)
+void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb,
+							struct sock *skip_sk)
 {
 	struct sock *sk;
 	struct hlist_node *node;
@@ -97,6 +98,9 @@ void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb)
 		struct hci_filter *flt;
 		struct sk_buff *nskb;
 
+		if (sk == skip_sk)
+			continue;
+
 		if (sk->sk_state != BT_BOUND || hci_pi(sk)->hdev != hdev)
 			continue;
 
net/bluetooth/mgmt.c +195 -5

249 lines not on this page · raw message

Signature · 1 line
1.7.2.3
#3 lore raw

PATCH 4/11 Bluetooth: Add support for set_discoverable management command

In reply to [email protected]

From: Johan Hedberg <[email protected]>

This patch adds a set_discoverable command to the management interface as well as the corresponding event. The command is used to control the discoverable state of adapters.

---
 include/net/bluetooth/hci_core.h |    1 +
 include/net/bluetooth/mgmt.h     |   16 ++++
 net/bluetooth/hci_event.c        |    5 +-
 net/bluetooth/mgmt.c             |  142 ++++++++++++++++++++++++++++++++++++--
 4 files changed, 158 insertions(+), 6 deletions(-)
include/net/bluetooth/hci_core.h +1 -0
index b6078ba..2b7c31f 100644
@@ -673,6 +673,7 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t len);
 int mgmt_index_added(u16 index);
 int mgmt_index_removed(u16 index);
 int mgmt_powered(u16 index, u8 powered);
+int mgmt_discoverable(u16 index, u8 discoverable);
 
 /* HCI info for socket */
 #define hci_pi(sk) ((struct hci_pinfo *) sk)
include/net/bluetooth/mgmt.h +16 -0
index 81ef789..434dbcf 100644
@@ -68,6 +68,16 @@ struct mgmt_rp_set_powered {
 	__u8 powered;
 } __packed;
 
+#define MGMT_OP_SET_DISCOVERABLE	0x0006
+struct mgmt_cp_set_discoverable {
+	__le16 index;
+	__u8 discoverable;
+} __packed;
+struct mgmt_rp_set_discoverable {
+	__le16 index;
+	__u8 discoverable;
+} __packed;
+
 #define MGMT_EV_CMD_COMPLETE		0x0001
 struct mgmt_ev_cmd_complete {
 	__le16 opcode;
@@ -101,3 +111,9 @@ struct mgmt_ev_powered {
 	__le16 index;
 	__u8 powered;
 } __packed;
+
+#define MGMT_EV_DISCOVERABLE		0x0007
+struct mgmt_ev_discoverable {
+	__le16 index;
+	__u8 discoverable;
+} __packed;
net/bluetooth/hci_event.c +4 -1
index b19b061..f47ceb1 100644
@@ -278,8 +278,11 @@ static void hci_cc_write_scan_enable(struct hci_dev *hdev, struct sk_buff *skb)
 		clear_bit(HCI_PSCAN, &hdev->flags);
 		clear_bit(HCI_ISCAN, &hdev->flags);
 
-		if (param & SCAN_INQUIRY)
+		if (param & SCAN_INQUIRY) {
 			set_bit(HCI_ISCAN, &hdev->flags);
+			mgmt_discoverable(hdev->id, 1);
+		} else
+			mgmt_discoverable(hdev->id, 0);
 
 		if (param & SCAN_PAGE)
 			set_bit(HCI_PSCAN, &hdev->flags);
net/bluetooth/mgmt.c +137 -5

182 lines not on this page · raw message

Signature · 1 line
1.7.2.3
#4 lore raw

PATCH 5/11 Bluetooth: Add set_connectable management command

In reply to [email protected]

From: Johan Hedberg <[email protected]>

This patch adds a set_connectable command as well as a corresponding event to the management interface. It's mainly useful for setting an adapter as connectable from a non-initialized state as well as setting an already initialized adapter as non-connectable (mostly useful for qualification purposes).

---
 include/net/bluetooth/hci_core.h |    1 +
 include/net/bluetooth/mgmt.h     |   17 +++++
 net/bluetooth/hci_event.c        |   16 ++++--
 net/bluetooth/mgmt.c             |  122 +++++++++++++++++++++++++++++++++++++-
 4 files changed, 149 insertions(+), 7 deletions(-)
include/net/bluetooth/hci_core.h +1 -0
index 2b7c31f..8d800d9 100644
@@ -674,6 +674,7 @@ int mgmt_index_added(u16 index);
 int mgmt_index_removed(u16 index);
 int mgmt_powered(u16 index, u8 powered);
 int mgmt_discoverable(u16 index, u8 discoverable);
+int mgmt_connectable(u16 index, u8 connectable);
 
 /* HCI info for socket */
 #define hci_pi(sk) ((struct hci_pinfo *) sk)
include/net/bluetooth/mgmt.h +17 -0
index 434dbcf..008acf5 100644
@@ -47,6 +47,7 @@ struct mgmt_rp_read_info {
 	__le16 index;
 	__u8 type;
 	__u8 powered;
+	__u8 connectable;
 	__u8 discoverable;
 	__u8 pairable;
 	__u8 sec_mode;
@@ -78,6 +79,16 @@ struct mgmt_rp_set_discoverable {
 	__u8 discoverable;
 } __packed;
 
+#define MGMT_OP_SET_CONNECTABLE		0x0007
+struct mgmt_cp_set_connectable {
+	__le16 index;
+	__u8 connectable;
+} __packed;
+struct mgmt_rp_set_connectable {
+	__le16 index;
+	__u8 connectable;
+} __packed;
+
 #define MGMT_EV_CMD_COMPLETE		0x0001
 struct mgmt_ev_cmd_complete {
 	__le16 opcode;
@@ -117,3 +128,9 @@ struct mgmt_ev_discoverable {
 	__le16 index;
 	__u8 discoverable;
 } __packed;
+
+#define MGMT_EV_CONNECTABLE		0x0008
+struct mgmt_ev_connectable {
+	__le16 index;
+	__u8 connectable;
+} __packed;
net/bluetooth/hci_event.c +11 -5
index f47ceb1..319f954 100644
@@ -274,18 +274,24 @@ static void hci_cc_write_scan_enable(struct hci_dev *hdev, struct sk_buff *skb)
 
 	if (!status) {
 		__u8 param = *((__u8 *) sent);
+		int old_pscan, old_iscan;
 
-		clear_bit(HCI_PSCAN, &hdev->flags);
-		clear_bit(HCI_ISCAN, &hdev->flags);
+		old_pscan = test_and_clear_bit(HCI_PSCAN, &hdev->flags);
+		old_iscan = test_and_clear_bit(HCI_ISCAN, &hdev->flags);
 
 		if (param & SCAN_INQUIRY) {
 			set_bit(HCI_ISCAN, &hdev->flags);
-			mgmt_discoverable(hdev->id, 1);
-		} else
+			if (!old_iscan)
+				mgmt_discoverable(hdev->id, 1);
+		} else if (old_iscan)
 			mgmt_discoverable(hdev->id, 0);
 
-		if (param & SCAN_PAGE)
+		if (param & SCAN_PAGE) {
 			set_bit(HCI_PSCAN, &hdev->flags);
+			if (!old_pscan)
+				mgmt_connectable(hdev->id, 1);
+		} else if (old_pscan)
+			mgmt_connectable(hdev->id, 0);
 	}
 
 	hci_req_complete(hdev, HCI_OP_WRITE_SCAN_ENABLE, status);
net/bluetooth/mgmt.c +120 -2

149 lines not on this page · raw message

Signature · 1 line
1.7.2.3
#5 lore raw

PATCH 6/11 Bluetooth: Unify mode related management messages to a single struct

In reply to [email protected]

From: Johan Hedberg <[email protected]>

The powered, connectable and discoverable messages all have the same format. By using a single struct for all of them a lot of code can be simplified and reused.

---
 include/net/bluetooth/mgmt.h |   39 +-----------
 net/bluetooth/mgmt.c         |  137 +++++++++---------------------------------
 2 files changed, 32 insertions(+), 144 deletions(-)
include/net/bluetooth/mgmt.h +4 -35
index 008acf5..f61fd67 100644
@@ -59,35 +59,16 @@ struct mgmt_rp_read_info {
 	__u16 hci_rev;
 } __packed;
 
-#define MGMT_OP_SET_POWERED		0x0005
-struct mgmt_cp_set_powered {
+struct mgmt_mode {
 	__le16 index;
-	__u8 powered;
-} __packed;
-struct mgmt_rp_set_powered {
-	__le16 index;
-	__u8 powered;
+	__u8 val;
 } __packed;
 
+#define MGMT_OP_SET_POWERED		0x0005
+
 #define MGMT_OP_SET_DISCOVERABLE	0x0006
-struct mgmt_cp_set_discoverable {
-	__le16 index;
-	__u8 discoverable;
-} __packed;
-struct mgmt_rp_set_discoverable {
-	__le16 index;
-	__u8 discoverable;
-} __packed;
 
 #define MGMT_OP_SET_CONNECTABLE		0x0007
-struct mgmt_cp_set_connectable {
-	__le16 index;
-	__u8 connectable;
-} __packed;
-struct mgmt_rp_set_connectable {
-	__le16 index;
-	__u8 connectable;
-} __packed;
 
 #define MGMT_EV_CMD_COMPLETE		0x0001
 struct mgmt_ev_cmd_complete {
@@ -118,19 +99,7 @@ struct mgmt_ev_index_removed {
 } __packed;
 
 #define MGMT_EV_POWERED			0x0006
-struct mgmt_ev_powered {
-	__le16 index;
-	__u8 powered;
-} __packed;
 
 #define MGMT_EV_DISCOVERABLE		0x0007
-struct mgmt_ev_discoverable {
-	__le16 index;
-	__u8 discoverable;
-} __packed;
 
 #define MGMT_EV_CONNECTABLE		0x0008
-struct mgmt_ev_connectable {
-	__le16 index;
-	__u8 connectable;
-} __packed;
net/bluetooth/mgmt.c +28 -109

246 lines not on this page · raw message

Signature · 1 line
1.7.2.3
#6 lore raw

PATCH 7/11 Bluetooth: Add flag to track managment controlled adapters

In reply to [email protected]

From: Johan Hedberg <[email protected]>

This patch adds a HCI_MGMT flag to track adapters which are under the control of the management interface. This is needed to make sure that new kernels will work with old user space versions. I.e. behaviour which could break old user space versions (but is needed by the management interface) should not be exhibited when the HCI_MGMT flag is not set.

---
 include/net/bluetooth/hci.h |    1 +
 net/bluetooth/mgmt.c        |    4 ++++
 2 files changed, 5 insertions(+), 0 deletions(-)
include/net/bluetooth/hci.h +1 -0
index 6469d67..a34f638 100644
@@ -79,6 +79,7 @@ enum {
 
 	HCI_SETUP,
 	HCI_AUTO_OFF,
+	HCI_MGMT,
 };
 
 /* HCI ioctl defines */
net/bluetooth/mgmt.c +4 -0
index 36a3e1c..9d82da9 100644
@@ -140,6 +140,8 @@ static int read_index_list(struct sock *sk)
 
 		hci_del_off_timer(d);
 
+		set_bit(HCI_MGMT, &d->flags);
+
 		if (test_bit(HCI_SETUP, &d->flags))
 			continue;
 
@@ -198,6 +200,8 @@ static int read_controller_info(struct sock *sk, unsigned char *data, u16 len)
 
 	hci_dev_lock_bh(hdev);
 
+	set_bit(HCI_MGMT, &hdev->flags);
+
 	put_unaligned_le16(hdev->id, &rp->index);
 	rp->type = hdev->dev_type;
 
Signature · 1 line
1.7.2.3
#7 lore raw

PATCH 8/11 Bluetooth: Implement set_pairable managment command

In reply to [email protected]

From: Johan Hedberg <[email protected]>

This patch implements a new set_pairable management command to control the pairable state of local adapters. The state is represented using a new HCI_PAIRABLE flag in the hci_dev struct.

For backwards compatibility with older user space versions the HCI_PAIRABLE flag gets automatically set when the existence of an adapter is reported to user space through legacy methods and the HCI_MGMT flag is not set.

---
 include/net/bluetooth/hci.h  |    1 +
 include/net/bluetooth/mgmt.h |    4 +
 net/bluetooth/hci_core.c     |   10 +++
 net/bluetooth/mgmt.c         |  138 ++++++++++++++++++++++++++++-------------
 4 files changed, 109 insertions(+), 44 deletions(-)
include/net/bluetooth/hci.h +1 -0
index a34f638..2b370ba 100644
@@ -80,6 +80,7 @@ enum {
 	HCI_SETUP,
 	HCI_AUTO_OFF,
 	HCI_MGMT,
+	HCI_PAIRABLE,
 };
 
 /* HCI ioctl defines */
include/net/bluetooth/mgmt.h +4 -0
index f61fd67..a554802 100644
@@ -70,6 +70,8 @@ struct mgmt_mode {
 
 #define MGMT_OP_SET_CONNECTABLE		0x0007
 
+#define MGMT_OP_SET_PAIRABLE		0x0008
+
 #define MGMT_EV_CMD_COMPLETE		0x0001
 struct mgmt_ev_cmd_complete {
 	__le16 opcode;
@@ -103,3 +105,5 @@ struct mgmt_ev_index_removed {
 #define MGMT_EV_DISCOVERABLE		0x0007
 
 #define MGMT_EV_CONNECTABLE		0x0008
+
+#define MGMT_EV_PAIRABLE		0x0009
net/bluetooth/hci_core.c +10 -0
index de40a8a..c03e6c9 100644
@@ -799,10 +799,17 @@ int hci_get_dev_list(void __user *arg)
 	read_lock_bh(&hci_dev_list_lock);
 	list_for_each(p, &hci_dev_list) {
 		struct hci_dev *hdev;
+
 		hdev = list_entry(p, struct hci_dev, list);
+
 		hci_del_off_timer(hdev);
+
+		if (!test_bit(HCI_MGMT, &hdev->flags))
+			set_bit(HCI_PAIRABLE, &hdev->flags);
+
 		(dr + n)->dev_id  = hdev->id;
 		(dr + n)->dev_opt = hdev->flags;
+
 		if (++n >= dev_num)
 			break;
 	}
@@ -832,6 +839,9 @@ int hci_get_dev_info(void __user *arg)
 
 	hci_del_off_timer(hdev);
 
+	if (!test_bit(HCI_MGMT, &hdev->flags))
+		set_bit(HCI_PAIRABLE, &hdev->flags);
+
 	strcpy(di.name, hdev->name);
 	di.bdaddr   = hdev->bdaddr;
 	di.type     = (hdev->bus & 0x0f) | (hdev->dev_type << 4);
net/bluetooth/mgmt.c +94 -44

168 lines not on this page · raw message

Signature · 1 line
1.7.2.3
#8 lore raw

PATCH 9/11 Bluetooth: Fix leaking blacklist when unregistering a hci device

In reply to [email protected]

From: Johan Hedberg <[email protected]>

The blacklist should be freed before the hci device gets unregistered.

---
 net/bluetooth/hci_core.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
net/bluetooth/hci_core.c +4 -0
index c03e6c9..f01dcea 100644
@@ -1085,6 +1085,10 @@ int hci_unregister_dev(struct hci_dev *hdev)
 
 	destroy_workqueue(hdev->workqueue);
 
+	hci_dev_lock_bh(hdev);
+	hci_blacklist_clear(hdev);
+	hci_dev_unlock_bh(hdev);
+
 	__hci_dev_put(hdev);
 
 	return 0;
Signature · 1 line
1.7.2.3
#9 lore raw

Re: [PATCH 09/11] Bluetooth: Fix leaking blacklist when unregistering a hci device

Hi Johan,

Quoted 8 lines · * [email protected] <[email protected]> [2011-01-04 12:08:50 +0200]:

From: Johan Hedberg <[email protected]>

The blacklist should be freed before the hci device gets unregistered.

---
 net/bluetooth/hci_core.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

This one is applied. Thanks.

Signature · 2 lines
Gustavo F. Padovan
http://profusion.mobi
#10 lore raw

PATCH 10/11 Bluetooth: Implement UUID handling through the management interface

In reply to [email protected]

From: Johan Hedberg <[email protected]>

This patch adds methods to the management interface for userspace to notify the kernel of which services have been registered for specific adapters. This information is needed for setting the appropriate Class of Device value as well as the Extended Inquiry Response value. This patch doesn't actually implement setting of these values but just provides the storage of the UUIDs so the needed functionality can be built on top of it.

---
 include/net/bluetooth/hci_core.h |   10 +++
 include/net/bluetooth/mgmt.h     |   12 ++++
 net/bluetooth/hci_core.c         |   19 ++++++
 net/bluetooth/mgmt.c             |  120 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 161 insertions(+), 0 deletions(-)
include/net/bluetooth/hci_core.h +10 -0
index 8d800d9..3008f33 100644
@@ -66,6 +66,12 @@ struct bdaddr_list {
 	struct list_head list;
 	bdaddr_t bdaddr;
 };
+
+struct bt_uuid {
+	struct list_head list;
+	u8 uuid[16];
+};
+
 #define NUM_REASSEMBLY 4
 struct hci_dev {
 	struct list_head list;
@@ -139,6 +145,8 @@ struct hci_dev {
 	struct hci_conn_hash	conn_hash;
 	struct list_head	blacklist;
 
+	struct list_head	uuids;
+
 	struct hci_dev_stats	stat;
 
 	struct sk_buff_head	driver_init;
@@ -440,6 +448,8 @@ int hci_inquiry(void __user *arg);
 struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev, bdaddr_t *bdaddr);
 int hci_blacklist_clear(struct hci_dev *hdev);
 
+int hci_uuids_clear(struct hci_dev *hdev);
+
 void hci_del_off_timer(struct hci_dev *hdev);
 
 void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
include/net/bluetooth/mgmt.h +12 -0
index a554802..c118ad3 100644
@@ -72,6 +72,18 @@ struct mgmt_mode {
 
 #define MGMT_OP_SET_PAIRABLE		0x0008
 
+#define MGMT_OP_ADD_UUID		0x0009
+struct mgmt_cp_add_uuid {
+	__le16 index;
+	__u8 uuid[16];
+} __packed;
+
+#define MGMT_OP_REMOVE_UUID		0x000A
+struct mgmt_cp_remove_uuid {
+	__le16 index;
+	__u8 uuid[16];
+} __packed;
+
 #define MGMT_EV_CMD_COMPLETE		0x0001
 struct mgmt_ev_cmd_complete {
 	__le16 opcode;
net/bluetooth/hci_core.c +19 -0
index f01dcea..49590c6 100644
@@ -955,6 +955,22 @@ void hci_del_off_timer(struct hci_dev *hdev)
 	del_timer(&hdev->off_timer);
 }
 
+int hci_uuids_clear(struct hci_dev *hdev)
+{
+	struct list_head *p, *n;
+
+	list_for_each_safe(p, n, &hdev->uuids) {
+		struct bt_uuid *uuid;
+
+		uuid = list_entry(p, struct bt_uuid, list);
+
+		list_del(p);
+		kfree(uuid);
+	}
+
+	return 0;
+}
+
 /* Register HCI device */
 int hci_register_dev(struct hci_dev *hdev)
 {
@@ -1012,6 +1028,8 @@ int hci_register_dev(struct hci_dev *hdev)
 
 	INIT_LIST_HEAD(&hdev->blacklist);
 
+	INIT_LIST_HEAD(&hdev->uuids);
+
 	INIT_WORK(&hdev->power_on, hci_power_on);
 	INIT_WORK(&hdev->power_off, hci_power_off);
 	setup_timer(&hdev->off_timer, hci_auto_off, (unsigned long) hdev);
@@ -1087,6 +1105,7 @@ int hci_unregister_dev(struct hci_dev *hdev)
 
 	hci_dev_lock_bh(hdev);
 	hci_blacklist_clear(hdev);
+	hci_uuids_clear(hdev);
 	hci_dev_unlock_bh(hdev);
 
 	__hci_dev_put(hdev);
net/bluetooth/mgmt.c +120 -0

132 lines not on this page · raw message

Signature · 1 line
1.7.2.3
#11 lore raw

PATCH v2 10/11 Bluetooth: Implement UUID handling through the management interface

From: Johan Hedberg <[email protected]>

This patch adds methods to the management interface for userspace to notify the kernel of which services have been registered for specific adapters. This information is needed for setting the appropriate Class of Device value as well as the Extended Inquiry Response value. This patch doesn't actually implement setting of these values but just provides the storage of the UUIDs so the needed functionality can be built on top of it.

---
v2: Fix compiler warning due to potentially uninitialized variable.

 include/net/bluetooth/hci_core.h |   10 +++
 include/net/bluetooth/mgmt.h     |   12 ++++
 net/bluetooth/hci_core.c         |   19 ++++++
 net/bluetooth/mgmt.c             |  120 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 161 insertions(+), 0 deletions(-)
include/net/bluetooth/hci_core.h +10 -0
index ba3dbe3..8ee0b8b 100644
@@ -66,6 +66,12 @@ struct bdaddr_list {
 	struct list_head list;
 	bdaddr_t bdaddr;
 };
+
+struct bt_uuid {
+	struct list_head list;
+	u8 uuid[16];
+};
+
 #define NUM_REASSEMBLY 4
 struct hci_dev {
 	struct list_head list;
@@ -139,6 +145,8 @@ struct hci_dev {
 	struct hci_conn_hash	conn_hash;
 	struct list_head	blacklist;
 
+	struct list_head	uuids;
+
 	struct hci_dev_stats	stat;
 
 	struct sk_buff_head	driver_init;
@@ -441,6 +449,8 @@ int hci_inquiry(void __user *arg);
 struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev, bdaddr_t *bdaddr);
 int hci_blacklist_clear(struct hci_dev *hdev);
 
+int hci_uuids_clear(struct hci_dev *hdev);
+
 void hci_del_off_timer(struct hci_dev *hdev);
 
 void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
include/net/bluetooth/mgmt.h +12 -0
index a554802..c118ad3 100644
@@ -72,6 +72,18 @@ struct mgmt_mode {
 
 #define MGMT_OP_SET_PAIRABLE		0x0008
 
+#define MGMT_OP_ADD_UUID		0x0009
+struct mgmt_cp_add_uuid {
+	__le16 index;
+	__u8 uuid[16];
+} __packed;
+
+#define MGMT_OP_REMOVE_UUID		0x000A
+struct mgmt_cp_remove_uuid {
+	__le16 index;
+	__u8 uuid[16];
+} __packed;
+
 #define MGMT_EV_CMD_COMPLETE		0x0001
 struct mgmt_ev_cmd_complete {
 	__le16 opcode;
net/bluetooth/hci_core.c +19 -0
index 13eb5a8..b99248d 100644
@@ -955,6 +955,22 @@ void hci_del_off_timer(struct hci_dev *hdev)
 	del_timer(&hdev->off_timer);
 }
 
+int hci_uuids_clear(struct hci_dev *hdev)
+{
+	struct list_head *p, *n;
+
+	list_for_each_safe(p, n, &hdev->uuids) {
+		struct bt_uuid *uuid;
+
+		uuid = list_entry(p, struct bt_uuid, list);
+
+		list_del(p);
+		kfree(uuid);
+	}
+
+	return 0;
+}
+
 /* Register HCI device */
 int hci_register_dev(struct hci_dev *hdev)
 {
@@ -1012,6 +1028,8 @@ int hci_register_dev(struct hci_dev *hdev)
 
 	INIT_LIST_HEAD(&hdev->blacklist);
 
+	INIT_LIST_HEAD(&hdev->uuids);
+
 	INIT_WORK(&hdev->power_on, hci_power_on);
 	INIT_WORK(&hdev->power_off, hci_power_off);
 	setup_timer(&hdev->off_timer, hci_auto_off, (unsigned long) hdev);
@@ -1087,6 +1105,7 @@ int hci_unregister_dev(struct hci_dev *hdev)
 
 	hci_dev_lock_bh(hdev);
 	hci_blacklist_clear(hdev);
+	hci_uuids_clear(hdev);
 	hci_dev_unlock_bh(hdev);
 
 	__hci_dev_put(hdev);
net/bluetooth/mgmt.c +120 -0

132 lines not on this page · raw message

Signature · 1 line
1.7.2.3
#12 lore raw

PATCH 11/11 Bluetooth: Implement debugfs support for listing UUIDs

In reply to [email protected]

From: Johan Hedberg <[email protected]>

This patch adds a debugfs entry to list the UUIDs that have been registered through the management interface.

---
 net/bluetooth/hci_sysfs.c |   52 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 52 insertions(+), 0 deletions(-)
net/bluetooth/hci_sysfs.c +52 -0
index 5fce3d6..23471dd 100644
@@ -461,6 +461,56 @@ static const struct file_operations blacklist_fops = {
 	.llseek		= seq_lseek,
 	.release	= single_release,
 };
+
+static void print_bt_uuid(struct seq_file *f, u8 *uuid)
+{
+	u32 data0, data4;
+	u16 data1, data2, data3, data5;
+
+	memcpy(&data0, &uuid[0], 4);
+	memcpy(&data1, &uuid[4], 2);
+	memcpy(&data2, &uuid[6], 2);
+	memcpy(&data3, &uuid[8], 2);
+	memcpy(&data4, &uuid[10], 4);
+	memcpy(&data5, &uuid[14], 2);
+
+	seq_printf(f, "%.8x-%.4x-%.4x-%.4x-%.8x%.4x\n",
+				ntohl(data0), ntohs(data1), ntohs(data2),
+				ntohs(data3), ntohl(data4), ntohs(data5));
+}
+
+static int uuids_show(struct seq_file *f, void *p)
+{
+	struct hci_dev *hdev = f->private;
+	struct list_head *l;
+
+	hci_dev_lock_bh(hdev);
+
+	list_for_each(l, &hdev->uuids) {
+		struct bt_uuid *uuid;
+
+		uuid = list_entry(l, struct bt_uuid, list);
+
+		print_bt_uuid(f, uuid->uuid);
+	}
+
+	hci_dev_unlock_bh(hdev);
+
+	return 0;
+}
+
+static int uuids_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, uuids_show, inode->i_private);
+}
+
+static const struct file_operations uuids_fops = {
+	.open		= uuids_open,
+	.read		= seq_read,
+	.llseek		= seq_lseek,
+	.release	= single_release,
+};
+
 int hci_register_sysfs(struct hci_dev *hdev)
 {
 	struct device *dev = &hdev->dev;
@@ -493,6 +543,8 @@ int hci_register_sysfs(struct hci_dev *hdev)
 	debugfs_create_file("blacklist", 0444, hdev->debugfs,
 						hdev, &blacklist_fops);
 
+	debugfs_create_file("uuids", 0444, hdev->debugfs, hdev, &uuids_fops);
+
 	return 0;
 }
 
Signature · 1 line
1.7.2.3