You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by gi...@git.apache.org on 2017/06/29 20:52:06 UTC

[GitHub] sjanc commented on a change in pull request #360: MYNEWT-715 Extended Advertising - Advertiser support for controller

sjanc commented on a change in pull request #360: MYNEWT-715 Extended Advertising - Advertiser support for controller
URL: https://github.com/apache/mynewt-core/pull/360#discussion_r124909978
 
 

 ##########
 File path: net/nimble/controller/src/ble_ll_adv.c
 ##########
 @@ -894,228 +1418,676 @@ ble_ll_adv_sm_start(struct ble_ll_adv_sm *advsm)
     advsm->adv_pdu_start_time = os_cputime_get32() +
         os_cputime_usecs_to_ticks(BLE_LL_SCHED_MAX_TXRX_SLOT);
 
-    /*
-     * Schedule advertising. We set the initial schedule start and end
-     * times to the earliest possible start/end.
-     */
-    ble_ll_adv_set_sched(advsm);
-    ble_ll_sched_adv_new(&advsm->adv_sch);
+    /*
+     * Schedule advertising. We set the initial schedule start and end
+     * times to the earliest possible start/end.
+     */
+    ble_ll_adv_set_sched(advsm);
+    ble_ll_sched_adv_new(&advsm->adv_sch, ble_ll_adv_scheduled);
+
+#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
+    if (!(advsm->props & BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY)) {
+        ble_ll_set_adv_secondary_start_time(advsm);
+        ble_ll_adv_secondary_set_sched(advsm);
+        ble_ll_sched_adv_new(&advsm->adv_secondary_sch,
+                             ble_ll_adv_secondary_scheduled);
+    }
+#endif
+
+    return BLE_ERR_SUCCESS;
+}
+
+/**
+ * Called when the LE HCI command read advertising channel tx power command
+ * has been received. Returns the current advertising transmit power.
+ *
+ * Context: Link Layer task (HCI command parser)
+ *
+ * @return int
+ */
+int
+ble_ll_adv_read_txpwr(uint8_t *rspbuf, uint8_t *rsplen)
+{
+    rspbuf[0] = MYNEWT_VAL(BLE_LL_TX_PWR_DBM);
+    *rsplen = 1;
+    return BLE_ERR_SUCCESS;
+}
+
+/**
+ * Turn advertising on/off.
+ *
+ * Context: Link Layer task
+ *
+ * @param cmd
+ *
+ * @return int
+ */
+int
+ble_ll_adv_set_enable(uint8_t instance, uint8_t enable, uint16_t duration,
+                          uint8_t events)
+{
+    int rc;
+    struct ble_ll_adv_sm *advsm;
+
+    if (instance >= BLE_LL_ADV_INSTANCES) {
+        return BLE_ERR_INV_HCI_CMD_PARMS;
+    }
+
+    advsm = &g_ble_ll_adv_sm[instance];
+
+    rc = BLE_ERR_SUCCESS;
+    if (enable == 1) {
+#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
+        advsm->duration = duration;
+        advsm->events_max = events;
+        advsm->events = 0;
+#endif
+
+        /* If already enabled, do nothing */
+        if (!advsm->adv_enabled) {
+            /* Start the advertising state machine */
+            rc = ble_ll_adv_sm_start(advsm);
+        }
+    } else if (enable == 0) {
+        ble_ll_adv_sm_stop(advsm);
+    } else {
+        rc = BLE_ERR_INV_HCI_CMD_PARMS;
+    }
+
+    return rc;
+}
+
+/**
+ * Set the scan response data that the controller will send.
+ *
+ * @param cmd
+ * @param len
+ *
+ * @return int
+ */
+int
+ble_ll_adv_set_scan_rsp_data(uint8_t *cmd, uint8_t instance, uint8_t operation)
+{
+    uint8_t datalen;
+    uint8_t off = 0;
+    struct ble_ll_adv_sm *advsm;
+
+    if (instance >= BLE_LL_ADV_INSTANCES) {
+        return BLE_ERR_INV_HCI_CMD_PARMS;
+    }
+
+    advsm = &g_ble_ll_adv_sm[instance];
+    datalen = cmd[0];
+
+    /* check if type of advertising support scan rsp */
+    if (!(advsm->props & BLE_HCI_LE_SET_EXT_ADV_PROP_SCANNABLE)) {
+        return BLE_ERR_INV_HCI_CMD_PARMS;
+    }
+
+    if (!(advsm->props & BLE_HCI_LE_SET_EXT_ADV_PROP_SCANNABLE)) {
+        return BLE_ERR_INV_HCI_CMD_PARMS;
+    }
+
+    switch (operation) {
+    case BLE_HCI_LE_SET_EXT_SCAN_RSP_DATA_OPER_COMPLETE:
+        if (advsm->props & BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY) {
+            if (datalen > BLE_ADV_DATA_MAX_LEN) {
+                return BLE_ERR_INV_HCI_CMD_PARMS;
+            }
+        }
+
+        break;
+#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
+    case BLE_HCI_LE_SET_EXT_SCAN_RSP_DATA_OPER_UNCHANGED:
+        if (advsm->props & BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY) {
+            return BLE_ERR_INV_HCI_CMD_PARMS;
+        }
+
+        if (!advsm->adv_enabled || !advsm->adv_len || datalen) {
+            return BLE_ERR_INV_HCI_CMD_PARMS;
 
 Review comment:
   yeah,  some operations are not allowed if advertising is enabled,   but I just noticed that operation 0x04 is valid only for setting advertising data, not scan_rsp. I'lld fix that.
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services