[PATCH 6/6] Bluetooth: Add Advertising Added/Removed events

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch introduces the Advertising Added and Advertising Removed
events. The events are sent when an advertising instance is added
or removed from an hci_dev.

Signed-off-by: Arman Uguray <armansito@xxxxxxxxxxxx>
---
 include/net/bluetooth/mgmt.h | 10 ++++++++++
 net/bluetooth/mgmt.c         | 37 +++++++++++++++++++++++++++++--------
 2 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index c60a408..874e2a2 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -766,3 +766,13 @@ struct mgmt_ev_local_oob_data_updated {
 	__le16	eir_len;
 	__u8	eir[0];
 } __packed;
+
+#define MGMT_EV_ADVERTISING_ADDED	0x0023
+struct mgmt_ev_advertising_added {
+	__u8	instance;
+} __packed;
+
+#define MGMT_EV_ADVERTISING_REMOVED	0x0024
+struct mgmt_ev_advertising_removed {
+	__u8	instance;
+} __packed;
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index eae280d..5d04dd8 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -137,6 +137,8 @@ static const u16 mgmt_events[] = {
 	MGMT_EV_EXT_INDEX_ADDED,
 	MGMT_EV_EXT_INDEX_REMOVED,
 	MGMT_EV_LOCAL_OOB_DATA_UPDATED,
+	MGMT_EV_ADVERTISING_ADDED,
+	MGMT_EV_ADVERTISING_REMOVED,
 };
 
 #define CACHE_TIMEOUT	msecs_to_jiffies(2 * 1000)
@@ -6441,6 +6443,24 @@ static bool adv_data_is_valid(struct hci_dev *hdev, u32 adv_flags, u8 *adv_data,
 	return true;
 }
 
+static void advertising_added(struct hci_dev *hdev, u8 instance)
+{
+	struct mgmt_ev_advertising_added ev;
+
+	ev.instance = instance;
+
+	mgmt_event(MGMT_EV_ADVERTISING_ADDED, hdev, &ev, sizeof(ev), NULL);
+}
+
+static void advertising_removed(struct hci_dev *hdev, u8 instance)
+{
+	struct mgmt_ev_advertising_removed ev;
+
+	ev.instance = instance;
+
+	mgmt_event(MGMT_EV_ADVERTISING_REMOVED, hdev, &ev, sizeof(ev), NULL);
+}
+
 static void add_advertising_complete(struct hci_dev *hdev, u8 status,
 				     u16 opcode)
 {
@@ -6453,9 +6473,9 @@ static void add_advertising_complete(struct hci_dev *hdev, u8 status,
 
 	if (status) {
 		hci_dev_clear_flag(hdev, HCI_ADVERTISING_INSTANCE);
-		hdev->cur_adv_index = 0;
+		advertising_removed(hdev, hdev->cur_adv_index);
 
-		/* TODO: Send Advertising Removed event */
+		hdev->cur_adv_index = 0;
 	}
 
 	cmd = pending_find(MGMT_OP_ADD_ADVERTISING, hdev);
@@ -6535,10 +6555,11 @@ static int add_advertising(struct sock *sk, struct hci_dev *hdev,
 		memcpy(hdev->adv_instance.scan_rsp_data,
 		       cp->data + cp->adv_data_len, cp->scan_rsp_len);
 
-	/* TODO: Send Advertising Added event if the index changed
-	 * from 0 to 1.
-	 */
-	hdev->cur_adv_index = cp->instance;
+	if (hdev->cur_adv_index != cp->instance) {
+		hdev->cur_adv_index = cp->instance;
+
+		advertising_added(hdev, hdev->cur_adv_index);
+	}
 
 	hci_dev_set_flag(hdev, HCI_ADVERTISING_INSTANCE);
 
@@ -6640,11 +6661,11 @@ static int remove_advertising(struct sock *sk, struct hci_dev *hdev,
 		goto unlock;
 	}
 
+	advertising_removed(hdev, hdev->cur_adv_index);
+
 	memset(&hdev->adv_instance, 0, sizeof(hdev->adv_instance));
 	hdev->cur_adv_index = 0;
 
-	/* TODO" Send Advertising Removed event */
-
 	hci_dev_clear_flag(hdev, HCI_ADVERTISING_INSTANCE);
 
 	/* If the HCI_ADVERTISING flag is set or the device isn't powered then
-- 
2.2.0.rc0.207.ga3a616c

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux