This is an automated email from the ASF dual-hosted git repository.

rymek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git


The following commit(s) were added to refs/heads/master by this push:
     new ce39050  nimble/gap: Adding LE Clear Advertising Sets Command
ce39050 is described below

commit ce39050c6bd26fc58092645a9248857aed661faf
Author: Mohamed Essayed <mohamed.essa...@synopsys.com>
AuthorDate: Thu May 2 14:46:06 2019 +0200

    nimble/gap: Adding LE Clear Advertising Sets Command
---
 nimble/host/include/host/ble_gap.h |  7 +++++++
 nimble/host/src/ble_gap.c          | 41 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)

diff --git a/nimble/host/include/host/ble_gap.h 
b/nimble/host/include/host/ble_gap.h
index 5c45a1a..7a805f0 100644
--- a/nimble/host/include/host/ble_gap.h
+++ b/nimble/host/include/host/ble_gap.h
@@ -965,6 +965,13 @@ int ble_gap_ext_adv_stop(uint8_t instance);
 int ble_gap_ext_adv_set_data(uint8_t instance, struct os_mbuf *data);
 int ble_gap_ext_adv_rsp_set_data(uint8_t instance, struct os_mbuf *data);
 int ble_gap_ext_adv_remove(uint8_t instance);
+/**
+ * Clear All existing extended Adv Sets.
+ * @return              0 on success,
+ *                      BLE_HS_EBUSY if advertising is in progress,
+ *                      other error code on failure.
+ */
+int ble_gap_ext_adv_clear(void);
 
 #if MYNEWT_VAL(BLE_PERIODIC_ADV)
 /* Periodic Advertising */
diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c
index 4f51a29..5058504 100644
--- a/nimble/host/src/ble_gap.c
+++ b/nimble/host/src/ble_gap.c
@@ -3007,6 +3007,47 @@ ble_gap_ext_adv_remove(uint8_t instance)
     return 0;
 }
 
+int
+ble_gap_ext_adv_clear(void)
+{
+    int rc;
+    uint8_t instance;
+    uint16_t opcode;
+
+    ble_hs_lock();
+
+    for (instance = 0; instance < BLE_ADV_INSTANCES; instance++) {
+        /* If there is an active instance or periodic adv instance,
+         * Don't send the command
+         * */
+        if ((ble_gap_slave[instance].op == BLE_GAP_OP_S_ADV)) {
+            ble_hs_unlock();
+            return BLE_HS_EBUSY;
+        }
+
+#if MYNEWT_VAL(BLE_PERIODIC_ADV)
+        if ((ble_gap_slave[instance].periodic_op ==
+                        BLE_GAP_OP_S_PERIODIC_ADV)) {
+            ble_hs_unlock();
+            return BLE_HS_EBUSY;
+        }
+#endif
+    }
+
+    opcode = BLE_HCI_OP(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_CLEAR_ADV_SETS);
+
+    rc = ble_hs_hci_cmd_tx_empty_ack(opcode, NULL, 0);
+    if (rc != 0) {
+        ble_hs_unlock();
+        return rc;
+    }
+
+    memset(ble_gap_slave, 0, sizeof(ble_gap_slave));
+    ble_hs_unlock();
+
+    return 0;
+}
+
 #if MYNEWT_VAL(BLE_PERIODIC_ADV)
 static int
 ble_gap_periodic_adv_params_tx(uint8_t instance,

Reply via email to