You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/04/07 01:52:09 UTC

[4/4] incubator-mynewt-core git commit: MYNEWT-265 BLE - advertise iBeacon

MYNEWT-265 BLE - advertise iBeacon


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/03a60f65
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/03a60f65
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/03a60f65

Branch: refs/heads/develop
Commit: 03a60f654edf91393ec217240e2ba1e2311ebaeb
Parents: 8fc5098
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Apr 6 16:49:56 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Wed Apr 6 16:50:43 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_hs.h |  1 +
 net/nimble/host/src/ble_ibeacon.c     | 68 ++++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/03a60f65/net/nimble/host/include/host/ble_hs.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_hs.h b/net/nimble/host/include/host/ble_hs.h
index 1016ccd..dfffc97 100644
--- a/net/nimble/host/include/host/ble_hs.h
+++ b/net/nimble/host/include/host/ble_hs.h
@@ -105,6 +105,7 @@ struct ble_hs_cfg {
 
 extern const struct ble_hs_cfg ble_hs_cfg_dflt;
 
+int ble_ibeacon_set_adv_data(void *uuid128, uint16_t major, uint16_t minor);
 int ble_hs_init(uint8_t prio, struct ble_hs_cfg *cfg);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/03a60f65/net/nimble/host/src/ble_ibeacon.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_ibeacon.c b/net/nimble/host/src/ble_ibeacon.c
new file mode 100644
index 0000000..92cf382
--- /dev/null
+++ b/net/nimble/host/src/ble_ibeacon.c
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <string.h>
+#include "ble_hs_priv.h"
+
+#define BLE_IBEACON_MFG_DATA_SIZE       25
+
+int
+ble_ibeacon_set_adv_data(void *uuid128, uint16_t major, uint16_t minor)
+{
+    struct ble_hci_block_params params;
+    struct ble_hci_block_result result;
+    struct ble_hs_adv_fields fields;
+    uint8_t buf[BLE_IBEACON_MFG_DATA_SIZE];
+    int rc;
+
+    /** Company identifier (Apple). */
+    buf[0] = 0x4c;
+    buf[1] = 0x00;
+
+    /** iBeacon indicator. */
+    buf[2] = 0x02;
+    buf[3] = 0x15;
+
+    /** UUID. */
+    memcpy(buf + 4, uuid128, 16);
+
+    /** Version number. */
+    htole16(buf + 20, major);
+    htole16(buf + 22, minor);
+
+    /** Last byte (tx power level) filled in after HCI exchange. */
+
+    memset(&params, 0, sizeof params);
+    params.cmd_opcode = host_hci_opcode_join(BLE_HCI_OGF_LE,
+                                             BLE_HCI_OCF_LE_RD_ADV_CHAN_TXPWR);
+    params.evt_buf = buf + 24;
+    params.evt_buf_len = 1;
+
+    rc = ble_hci_block_tx(&params, &result);
+    if (rc != 0) {
+        return rc;
+    }
+
+    memset(&fields, 0, sizeof fields);
+    fields.mfg_data = buf;
+    fields.mfg_data_len = sizeof buf;
+
+    rc = ble_gap_adv_set_fields(&fields);
+    return rc;
+}