You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/01/16 09:44:15 UTC
[GitHub] andrzej-kaczmarek closed pull request #719: nimble: Add meta-package for HCI transports
andrzej-kaczmarek closed pull request #719: nimble: Add meta-package for HCI transports
URL: https://github.com/apache/mynewt-core/pull/719
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/apps/bleprph-emspi/src/bleprph.h b/apps/bleprph-emspi/src/bleprph.h
deleted file mode 100644
index ec1444594..000000000
--- a/apps/bleprph-emspi/src/bleprph.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * 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.
- */
-
-#ifndef H_BLEPRPH_
-#define H_BLEPRPH_
-
-#include <stdbool.h>
-#include "log/log.h"
-#include "nimble/ble.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct ble_hs_cfg;
-struct ble_gatt_register_ctxt;
-
-extern struct log bleprph_log;
-
-/* bleprph uses the first "peruser" log module. */
-#define BLEPRPH_LOG_MODULE (LOG_MODULE_PERUSER + 0)
-
-/* Convenience macro for logging to the bleprph module. */
-#define BLEPRPH_LOG(lvl, ...) \
- LOG_ ## lvl(&bleprph_log, BLEPRPH_LOG_MODULE, __VA_ARGS__)
-
-/** GATT server. */
-#define GATT_SVR_SVC_ALERT_UUID 0x1811
-#define GATT_SVR_CHR_SUP_NEW_ALERT_CAT_UUID 0x2A47
-#define GATT_SVR_CHR_NEW_ALERT 0x2A46
-#define GATT_SVR_CHR_SUP_UNR_ALERT_CAT_UUID 0x2A48
-#define GATT_SVR_CHR_UNR_ALERT_STAT_UUID 0x2A45
-#define GATT_SVR_CHR_ALERT_NOT_CTRL_PT 0x2A44
-
-void gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg);
-int gatt_svr_init(void);
-
-/* PHY support */
-#if MYNEWT_VAL(BLEPRPH_LE_PHY_SUPPORT)
-#define CONN_HANDLE_INVALID 0xffff
-
-void phy_init(void);
-void phy_conn_changed(uint16_t handle);
-void phy_update(uint8_t phy);
-#endif
-
-/** Misc. */
-void print_bytes(const uint8_t *bytes, int len);
-void print_addr(const void *addr);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/apps/bleprph-emspi/src/gatt_svr.c b/apps/bleprph-emspi/src/gatt_svr.c
deleted file mode 100644
index 7025aaf35..000000000
--- a/apps/bleprph-emspi/src/gatt_svr.c
+++ /dev/null
@@ -1,204 +0,0 @@
-/*
- * 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 <assert.h>
-#include <stdio.h>
-#include <string.h>
-#include "bsp/bsp.h"
-#include "host/ble_hs.h"
-#include "host/ble_uuid.h"
-#include "bleprph.h"
-
-/**
- * The vendor specific security test service consists of two characteristics:
- * o random-number-generator: generates a random 32-bit number each time
- * it is read. This characteristic can only be read over an encrypted
- * connection.
- * o static-value: a single-byte characteristic that can always be read,
- * but can only be written over an encrypted connection.
- */
-
-/* 59462f12-9543-9999-12c8-58b459a2712d */
-static const ble_uuid128_t gatt_svr_svc_sec_test_uuid =
- BLE_UUID128_INIT(0x2d, 0x71, 0xa2, 0x59, 0xb4, 0x58, 0xc8, 0x12,
- 0x99, 0x99, 0x43, 0x95, 0x12, 0x2f, 0x46, 0x59);
-
-/* 5c3a659e-897e-45e1-b016-007107c96df6 */
-static const ble_uuid128_t gatt_svr_chr_sec_test_rand_uuid =
- BLE_UUID128_INIT(0xf6, 0x6d, 0xc9, 0x07, 0x71, 0x00, 0x16, 0xb0,
- 0xe1, 0x45, 0x7e, 0x89, 0x9e, 0x65, 0x3a, 0x5c);
-
-/* 5c3a659e-897e-45e1-b016-007107c96df7 */
-static const ble_uuid128_t gatt_svr_chr_sec_test_static_uuid =
- BLE_UUID128_INIT(0xf7, 0x6d, 0xc9, 0x07, 0x71, 0x00, 0x16, 0xb0,
- 0xe1, 0x45, 0x7e, 0x89, 0x9e, 0x65, 0x3a, 0x5c);
-
-static uint8_t gatt_svr_sec_test_static_val;
-
-static int
-gatt_svr_chr_access_sec_test(uint16_t conn_handle, uint16_t attr_handle,
- struct ble_gatt_access_ctxt *ctxt,
- void *arg);
-
-static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
- {
- /*** Service: Security test. */
- .type = BLE_GATT_SVC_TYPE_PRIMARY,
- .uuid = &gatt_svr_svc_sec_test_uuid.u,
- .characteristics = (struct ble_gatt_chr_def[]) { {
- /*** Characteristic: Random number generator. */
- .uuid = &gatt_svr_chr_sec_test_rand_uuid.u,
- .access_cb = gatt_svr_chr_access_sec_test,
- .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_READ_ENC,
- }, {
- /*** Characteristic: Static value. */
- .uuid = &gatt_svr_chr_sec_test_static_uuid.u,
- .access_cb = gatt_svr_chr_access_sec_test,
- .flags = BLE_GATT_CHR_F_READ |
- BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_WRITE_ENC,
- }, {
- 0, /* No more characteristics in this service. */
- } },
- },
-
- {
- 0, /* No more services. */
- },
-};
-
-static int
-gatt_svr_chr_write(struct os_mbuf *om, uint16_t min_len, uint16_t max_len,
- void *dst, uint16_t *len)
-{
- uint16_t om_len;
- int rc;
-
- om_len = OS_MBUF_PKTLEN(om);
- if (om_len < min_len || om_len > max_len) {
- return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
- }
-
- rc = ble_hs_mbuf_to_flat(om, dst, max_len, len);
- if (rc != 0) {
- return BLE_ATT_ERR_UNLIKELY;
- }
-
- return 0;
-}
-
-static int
-gatt_svr_chr_access_sec_test(uint16_t conn_handle, uint16_t attr_handle,
- struct ble_gatt_access_ctxt *ctxt,
- void *arg)
-{
- const ble_uuid_t *uuid;
- int rand_num;
- int rc;
-
- uuid = ctxt->chr->uuid;
-
- /* Determine which characteristic is being accessed by examining its
- * 128-bit UUID.
- */
-
- if (ble_uuid_cmp(uuid, &gatt_svr_chr_sec_test_rand_uuid.u) == 0) {
- assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
-
- /* Respond with a 32-bit random number. */
- rand_num = rand();
- rc = os_mbuf_append(ctxt->om, &rand_num, sizeof rand_num);
- return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
- }
-
- if (ble_uuid_cmp(uuid, &gatt_svr_chr_sec_test_static_uuid.u) == 0) {
- switch (ctxt->op) {
- case BLE_GATT_ACCESS_OP_READ_CHR:
- rc = os_mbuf_append(ctxt->om, &gatt_svr_sec_test_static_val,
- sizeof gatt_svr_sec_test_static_val);
- return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
-
- case BLE_GATT_ACCESS_OP_WRITE_CHR:
- rc = gatt_svr_chr_write(ctxt->om,
- sizeof gatt_svr_sec_test_static_val,
- sizeof gatt_svr_sec_test_static_val,
- &gatt_svr_sec_test_static_val, NULL);
- return rc;
-
- default:
- assert(0);
- return BLE_ATT_ERR_UNLIKELY;
- }
- }
-
- /* Unknown characteristic; the nimble stack should not have called this
- * function.
- */
- assert(0);
- return BLE_ATT_ERR_UNLIKELY;
-}
-
-void
-gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg)
-{
- char buf[BLE_UUID_STR_LEN];
-
- switch (ctxt->op) {
- case BLE_GATT_REGISTER_OP_SVC:
- BLEPRPH_LOG(DEBUG, "registered service %s with handle=%d\n",
- ble_uuid_to_str(ctxt->svc.svc_def->uuid, buf),
- ctxt->svc.handle);
- break;
-
- case BLE_GATT_REGISTER_OP_CHR:
- BLEPRPH_LOG(DEBUG, "registering characteristic %s with "
- "def_handle=%d val_handle=%d\n",
- ble_uuid_to_str(ctxt->chr.chr_def->uuid, buf),
- ctxt->chr.def_handle,
- ctxt->chr.val_handle);
- break;
-
- case BLE_GATT_REGISTER_OP_DSC:
- BLEPRPH_LOG(DEBUG, "registering descriptor %s with handle=%d\n",
- ble_uuid_to_str(ctxt->dsc.dsc_def->uuid, buf),
- ctxt->dsc.handle);
- break;
-
- default:
- assert(0);
- break;
- }
-}
-
-int
-gatt_svr_init(void)
-{
- int rc;
-
- rc = ble_gatts_count_cfg(gatt_svr_svcs);
- if (rc != 0) {
- return rc;
- }
-
- rc = ble_gatts_add_svcs(gatt_svr_svcs);
- if (rc != 0) {
- return rc;
- }
-
- return 0;
-}
diff --git a/apps/bleprph-emspi/src/main.c b/apps/bleprph-emspi/src/main.c
deleted file mode 100755
index 82c834c72..000000000
--- a/apps/bleprph-emspi/src/main.c
+++ /dev/null
@@ -1,346 +0,0 @@
-/*
- * 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 <assert.h>
-#include <string.h>
-#include <stdio.h>
-#include <errno.h>
-#include "sysinit/sysinit.h"
-#include "bsp/bsp.h"
-#include "os/os.h"
-#include "bsp/bsp.h"
-#include "hal/hal_gpio.h"
-#include "console/console.h"
-#include "hal/hal_system.h"
-#include "config/config.h"
-#include "split/split.h"
-
-/* BLE */
-#include "nimble/ble.h"
-#include "host/ble_hs.h"
-#include "services/gap/ble_svc_gap.h"
-
-/* Application-specified header. */
-#include "bleprph.h"
-
-/** Log data. */
-struct log bleprph_log;
-
-static int bleprph_gap_event(struct ble_gap_event *event, void *arg);
-
-/**
- * Logs information about a connection to the console.
- */
-static void
-bleprph_print_conn_desc(struct ble_gap_conn_desc *desc)
-{
- BLEPRPH_LOG(INFO, "handle=%d our_ota_addr_type=%d our_ota_addr=",
- desc->conn_handle, desc->our_ota_addr.type);
- print_addr(desc->our_ota_addr.val);
- BLEPRPH_LOG(INFO, " our_id_addr_type=%d our_id_addr=",
- desc->our_id_addr.type);
- print_addr(desc->our_id_addr.val);
- BLEPRPH_LOG(INFO, " peer_ota_addr_type=%d peer_ota_addr=",
- desc->peer_ota_addr.type);
- print_addr(desc->peer_ota_addr.val);
- BLEPRPH_LOG(INFO, " peer_id_addr_type=%d peer_id_addr=",
- desc->peer_id_addr.type);
- print_addr(desc->peer_id_addr.val);
- BLEPRPH_LOG(INFO, " conn_itvl=%d conn_latency=%d supervision_timeout=%d "
- "encrypted=%d authenticated=%d bonded=%d\n",
- desc->conn_itvl, desc->conn_latency,
- desc->supervision_timeout,
- desc->sec_state.encrypted,
- desc->sec_state.authenticated,
- desc->sec_state.bonded);
-}
-
-/**
- * Enables advertising with the following parameters:
- * o General discoverable mode.
- * o Undirected connectable mode.
- */
-static void
-bleprph_advertise(void)
-{
- struct ble_gap_adv_params adv_params;
- struct ble_hs_adv_fields fields;
- const char *name;
- int rc;
-
- /**
- * Set the advertisement data included in our advertisements:
- * o Flags (indicates advertisement type and other general info).
- * o Advertising tx power.
- * o Device name.
- * o 16-bit service UUIDs (alert notifications).
- */
-
- memset(&fields, 0, sizeof fields);
-
- /* Advertise two flags:
- * o Discoverability in forthcoming advertisement (general)
- * o BLE-only (BR/EDR unsupported).
- */
- fields.flags = BLE_HS_ADV_F_DISC_GEN |
- BLE_HS_ADV_F_BREDR_UNSUP;
-
- /* Indicate that the TX power level field should be included; have the
- * stack fill this value automatically. This is done by assiging the
- * special value BLE_HS_ADV_TX_PWR_LVL_AUTO.
- */
- fields.tx_pwr_lvl_is_present = 1;
- fields.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO;
-
- name = ble_svc_gap_device_name();
- fields.name = (uint8_t *)name;
- fields.name_len = strlen(name);
- fields.name_is_complete = 1;
-
- fields.uuids16 = (ble_uuid16_t[]){
- BLE_UUID16_INIT(GATT_SVR_SVC_ALERT_UUID)
- };
- fields.num_uuids16 = 1;
- fields.uuids16_is_complete = 1;
-
- rc = ble_gap_adv_set_fields(&fields);
- if (rc != 0) {
- BLEPRPH_LOG(ERROR, "error setting advertisement data; rc=%d\n", rc);
- return;
- }
-
- /* Begin advertising. */
- memset(&adv_params, 0, sizeof adv_params);
- adv_params.conn_mode = BLE_GAP_CONN_MODE_UND;
- adv_params.disc_mode = BLE_GAP_DISC_MODE_GEN;
- rc = ble_gap_adv_start(BLE_OWN_ADDR_PUBLIC, NULL, BLE_HS_FOREVER,
- &adv_params, bleprph_gap_event, NULL);
- if (rc != 0) {
- BLEPRPH_LOG(ERROR, "error enabling advertisement; rc=%d\n", rc);
- return;
- }
-}
-
-/**
- * The nimble host executes this callback when a GAP event occurs. The
- * application associates a GAP event callback with each connection that forms.
- * bleprph uses the same callback for all connections.
- *
- * @param event The type of event being signalled.
- * @param ctxt Various information pertaining to the event.
- * @param arg Application-specified argument; unuesd by
- * bleprph.
- *
- * @return 0 if the application successfully handled the
- * event; nonzero on failure. The semantics
- * of the return code is specific to the
- * particular GAP event being signalled.
- */
-static int
-bleprph_gap_event(struct ble_gap_event *event, void *arg)
-{
- struct ble_gap_conn_desc desc;
- int rc;
-
- switch (event->type) {
- case BLE_GAP_EVENT_CONNECT:
- /* A new connection was established or a connection attempt failed. */
- BLEPRPH_LOG(INFO, "connection %s; status=%d ",
- event->connect.status == 0 ? "established" : "failed",
- event->connect.status);
- if (event->connect.status == 0) {
- rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
- assert(rc == 0);
- bleprph_print_conn_desc(&desc);
-
-#if MYNEWT_VAL(BLEPRPH_LE_PHY_SUPPORT)
- phy_conn_changed(event->connect.conn_handle);
-#endif
- }
- BLEPRPH_LOG(INFO, "\n");
-
- if (event->connect.status != 0) {
- /* Connection failed; resume advertising. */
- bleprph_advertise();
- }
- return 0;
-
- case BLE_GAP_EVENT_DISCONNECT:
- BLEPRPH_LOG(INFO, "disconnect; reason=%d ", event->disconnect.reason);
- bleprph_print_conn_desc(&event->disconnect.conn);
- BLEPRPH_LOG(INFO, "\n");
-
-#if MYNEWT_VAL(BLEPRPH_LE_PHY_SUPPORT)
- phy_conn_changed(CONN_HANDLE_INVALID);
-#endif
-
- /* Connection terminated; resume advertising. */
- bleprph_advertise();
- return 0;
-
- case BLE_GAP_EVENT_CONN_UPDATE:
- /* The central has updated the connection parameters. */
- BLEPRPH_LOG(INFO, "connection updated; status=%d ",
- event->conn_update.status);
- rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
- assert(rc == 0);
- bleprph_print_conn_desc(&desc);
- BLEPRPH_LOG(INFO, "\n");
- return 0;
-
- case BLE_GAP_EVENT_ADV_COMPLETE:
- BLEPRPH_LOG(INFO, "advertise complete; reason=%d",
- event->adv_complete.reason);
- bleprph_advertise();
- return 0;
-
- case BLE_GAP_EVENT_ENC_CHANGE:
- /* Encryption has been enabled or disabled for this connection. */
- BLEPRPH_LOG(INFO, "encryption change event; status=%d ",
- event->enc_change.status);
- rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
- assert(rc == 0);
- bleprph_print_conn_desc(&desc);
- BLEPRPH_LOG(INFO, "\n");
- return 0;
-
- case BLE_GAP_EVENT_SUBSCRIBE:
- BLEPRPH_LOG(INFO, "subscribe event; conn_handle=%d attr_handle=%d "
- "reason=%d prevn=%d curn=%d previ=%d curi=%d\n",
- event->subscribe.conn_handle,
- event->subscribe.attr_handle,
- event->subscribe.reason,
- event->subscribe.prev_notify,
- event->subscribe.cur_notify,
- event->subscribe.prev_indicate,
- event->subscribe.cur_indicate);
- return 0;
-
- case BLE_GAP_EVENT_MTU:
- BLEPRPH_LOG(INFO, "mtu update event; conn_handle=%d cid=%d mtu=%d\n",
- event->mtu.conn_handle,
- event->mtu.channel_id,
- event->mtu.value);
- return 0;
-
- case BLE_GAP_EVENT_REPEAT_PAIRING:
- /* We already have a bond with the peer, but it is attempting to
- * establish a new secure link. This app sacrifices security for
- * convenience: just throw away the old bond and accept the new link.
- */
-
- /* Delete the old bond. */
- rc = ble_gap_conn_find(event->repeat_pairing.conn_handle, &desc);
- assert(rc == 0);
- ble_store_util_delete_peer(&desc.peer_id_addr);
-
- /* Return BLE_GAP_REPEAT_PAIRING_RETRY to indicate that the host should
- * continue with the pairing operation.
- */
- return BLE_GAP_REPEAT_PAIRING_RETRY;
-
-#if MYNEWT_VAL(BLEPRPH_LE_PHY_SUPPORT)
- case BLE_GAP_EVENT_PHY_UPDATE_COMPLETE:
- /* XXX: assume symmetric phy for now */
- phy_update(event->phy_updated.tx_phy);
- return 0;
-#endif
- }
-
- return 0;
-}
-
-static void
-bleprph_on_reset(int reason)
-{
- BLEPRPH_LOG(ERROR, "Resetting state; reason=%d\n", reason);
-}
-
-static void
-bleprph_on_sync(void)
-{
- /* Begin advertising. */
- bleprph_advertise();
-}
-
-/**
- * main
- *
- * The main task for the project. This function initializes the packages,
- * then starts serving events from default event queue.
- *
- * @return int NOTE: this function should never return!
- */
-int
-main(void)
-{
- int rc;
-
- /* Set initial BLE device address. */
- //memcpy(g_dev_addr, (uint8_t[6]){0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a}, 6);
-
- /* Initialize OS */
- sysinit();
-
- /* Initialize the bleprph log. */
- log_register("bleprph", &bleprph_log, &log_console_handler, NULL,
- LOG_SYSLEVEL);
-
- /* Initialize the NimBLE host configuration. */
- log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL,
- LOG_SYSLEVEL);
- ble_hs_cfg.reset_cb = bleprph_on_reset;
- ble_hs_cfg.sync_cb = bleprph_on_sync;
- ble_hs_cfg.gatts_register_cb = gatt_svr_register_cb;
- ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
-
- rc = gatt_svr_init();
- assert(rc == 0);
-
- /* Set the default device name. */
- rc = ble_svc_gap_device_name_set("bleprph-emspi");
- assert(rc == 0);
-
-#if MYNEWT_VAL(BLEPRPH_LE_PHY_SUPPORT)
- phy_init();
-#endif
-
- conf_load();
-
- /* If this app is acting as the loader in a split image setup, jump into
- * the second stage application instead of starting the OS.
- */
-#if MYNEWT_VAL(SPLIT_LOADER)
- {
- void *entry;
- rc = split_app_go(&entry, true);
- if (rc == 0) {
- hal_system_start(entry);
- }
- }
-#endif
-
- /*
- * As the last thing, process events from default event queue.
- */
- while (1) {
- os_eventq_run(os_eventq_dflt_get());
- }
- return 0;
-}
diff --git a/apps/bleprph-emspi/src/misc.c b/apps/bleprph-emspi/src/misc.c
deleted file mode 100644
index 8ec785e51..000000000
--- a/apps/bleprph-emspi/src/misc.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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 "bleprph.h"
-
-/**
- * Utility function to log an array of bytes.
- */
-void
-print_bytes(const uint8_t *bytes, int len)
-{
- int i;
-
- for (i = 0; i < len; i++) {
- BLEPRPH_LOG(INFO, "%s0x%02x", i != 0 ? ":" : "", bytes[i]);
- }
-}
-
-void
-print_addr(const void *addr)
-{
- const uint8_t *u8p;
-
- u8p = addr;
- BLEPRPH_LOG(INFO, "%02x:%02x:%02x:%02x:%02x:%02x",
- u8p[5], u8p[4], u8p[3], u8p[2], u8p[1], u8p[0]);
-}
diff --git a/apps/bleprph-emspi/src/phy.c b/apps/bleprph-emspi/src/phy.c
deleted file mode 100755
index 55c367ea3..000000000
--- a/apps/bleprph-emspi/src/phy.c
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * 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 "bsp/bsp.h"
-#include "hal/hal_gpio.h"
-#include "host/ble_gap.h"
-#include "os/os_eventq.h"
-#include "syscfg/syscfg.h"
-#include "bleprph.h"
-
-#if MYNEWT_VAL(BLEPRPH_LE_PHY_SUPPORT)
-
-static const int button_gpio[4] = MYNEWT_VAL(BLEPRPH_LE_PHY_BUTTON_GPIO);
-static const int led_gpio[3] = MYNEWT_VAL(BLEPRPH_LE_PHY_LED_GPIO);
-
-#define PHY_TO_PTR(_mask, _opts) (void *)(((_opts) << 16) | ((_mask)))
-#define PTR_TO_PHY_MASK(_ptr) (uint8_t)(((int)_ptr) & 0x0ff)
-#define PTR_TO_PHY_OPTS(_ptr) (uint8_t)(((int)_ptr) >> 16)
-
-static struct os_event gpio_event;
-
-static uint16_t conn_handle = CONN_HANDLE_INVALID;
-
-static void
-gpio_irq_handler(void *arg)
-{
- gpio_event.ev_arg = arg;
- os_eventq_put(os_eventq_dflt_get(), &gpio_event);
-}
-
-static void
-gpio_event_handler(struct os_event *ev)
-{
- uint8_t phy_mask;
- uint8_t phy_opts;
- int sr;
-
- OS_ENTER_CRITICAL(sr);
- phy_mask = PTR_TO_PHY_MASK(ev->ev_arg);
- phy_opts = PTR_TO_PHY_OPTS(ev->ev_arg);
- OS_EXIT_CRITICAL(sr);
-
- if (conn_handle != CONN_HANDLE_INVALID) {
- ble_gap_set_prefered_le_phy(conn_handle, phy_mask, phy_mask, phy_opts);
- }
-}
-
-static void
-setup_button_gpio(int button, uint8_t phy_mask, uint8_t phy_opts)
-{
- if (button < 0) {
- return;
- }
-
- hal_gpio_irq_init(button, gpio_irq_handler, PHY_TO_PTR(phy_mask, phy_opts),
- HAL_GPIO_TRIG_FALLING, HAL_GPIO_PULL_UP);
- hal_gpio_irq_enable(button);
-}
-
-void
-phy_init(void)
-{
- gpio_event.ev_cb = gpio_event_handler;
-
- /*
- * XXX: we could make this configurable, but for now assume all pins are
- * valid, buttons gpio pins are pulled-up and LEDs are active-low - this
- * is valid for nRF52840 PDK.
- */
- setup_button_gpio(button_gpio[0], BLE_GAP_LE_PHY_1M_MASK,
- BLE_GAP_LE_PHY_CODED_ANY);
- setup_button_gpio(button_gpio[1], BLE_GAP_LE_PHY_2M_MASK,
- BLE_GAP_LE_PHY_CODED_ANY);
- setup_button_gpio(button_gpio[2], BLE_GAP_LE_PHY_CODED_MASK,
- BLE_GAP_LE_PHY_CODED_S2);
- setup_button_gpio(button_gpio[3], BLE_GAP_LE_PHY_CODED_MASK,
- BLE_GAP_LE_PHY_CODED_S8);
-
- hal_gpio_init_out(led_gpio[0], 1);
- hal_gpio_init_out(led_gpio[1], 1);
- hal_gpio_init_out(led_gpio[2], 1);
-}
-
-void
-phy_conn_changed(uint16_t handle)
-{
- uint8_t phy = 0;
-
- conn_handle = handle;
-
- if (handle != CONN_HANDLE_INVALID) {
- /* XXX: assume symmetric phy for now */
- ble_gap_read_le_phy(handle, &phy, &phy);
- }
-
- phy_update(phy);
-}
-
-void
-phy_update(uint8_t phy)
-{
- if (conn_handle == CONN_HANDLE_INVALID) {
- hal_gpio_write(led_gpio[0], 1);
- hal_gpio_write(led_gpio[1], 1);
- hal_gpio_write(led_gpio[2], 1);
- } else {
- hal_gpio_write(led_gpio[0], !(phy == BLE_GAP_LE_PHY_1M));
- hal_gpio_write(led_gpio[1], !(phy == BLE_GAP_LE_PHY_2M));
- hal_gpio_write(led_gpio[2], !(phy == BLE_GAP_LE_PHY_CODED));
- }
-}
-
-#endif
diff --git a/apps/bleprph-emspi/syscfg.yml b/apps/bleprph-emspi/syscfg.yml
deleted file mode 100644
index ec1ee64eb..000000000
--- a/apps/bleprph-emspi/syscfg.yml
+++ /dev/null
@@ -1,65 +0,0 @@
-# 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.
-#
-
-# Package: apps/bleprph
-
-syscfg.defs:
- BLEPRPH_LE_PHY_SUPPORT:
- description: >
- Enable support for changing PHY preference on active connection.
- PHY preference change is triggered by configured GPIO pins.
- Current PHY is indicated using LEDs connected to configured
- GPIO pins.
- value: 0
- BLEPRPH_LE_PHY_BUTTON_GPIO:
- description: >
- GPIO pins for changing PHY preference on active connection. This
- is an array of 4 GPIO pin numbers for 1M, 2M, LE Coded S=2 and
- LE Coded S=8 respectively.
- value: "(int[]){ BUTTON_1, BUTTON_2, BUTTON_3, BUTTON_4 }"
- BLEPRPH_LE_PHY_LED_GPIO:
- description: >
- GPIO pins for indicating current PHY on active connection. This
- is an array of 3 GPIO pin numbers for 1M, 2M and LE Coded
- respectively.
- value: "(int[]){ LED_1, LED_2, LED_3 }"
-
-syscfg.vals:
- # Disable central and observer roles.
- BLE_ROLE_BROADCASTER: 1
- BLE_ROLE_CENTRAL: 0
- BLE_ROLE_OBSERVER: 0
- BLE_ROLE_PERIPHERAL: 1
-
- # Log reboot messages to a flash circular buffer.
- REBOOT_LOG_FCB: 1
- LOG_FCB: 1
- CONFIG_FCB: 1
-
- # Enable newtmgr commands.
- STATS_NEWTMGR: 1
- LOG_NEWTMGR: 1
- CONFIG_NEWTMGR: 1
-
- # OS main/default task
- OS_MAIN_STACK_SIZE: 468
-
- # Lots of smaller mbufs are required for newtmgr using typical BLE ATT MTU
- # values.
- MSYS_1_BLOCK_COUNT: 22
- MSYS_1_BLOCK_SIZE: 110
diff --git a/apps/bleprph/pkg.yml b/apps/bleprph/pkg.yml
index 34d13c75a..9288db901 100644
--- a/apps/bleprph/pkg.yml
+++ b/apps/bleprph/pkg.yml
@@ -29,13 +29,13 @@ pkg.deps:
- mgmt/imgmgr
- mgmt/newtmgr
- mgmt/newtmgr/transport/ble
- - net/nimble/controller
- net/nimble/host
- net/nimble/host/services/ans
- net/nimble/host/services/gap
- net/nimble/host/services/gatt
- net/nimble/host/store/config
- - net/nimble/transport/ram
+ - net/nimble/host/util
+ - net/nimble/transport
- sys/console/full
- sys/log/full
- sys/stats/full
diff --git a/apps/bleprph/src/main.c b/apps/bleprph/src/main.c
index 343ca6ad9..1b4b26fdd 100755
--- a/apps/bleprph/src/main.c
+++ b/apps/bleprph/src/main.c
@@ -34,6 +34,7 @@
/* BLE */
#include "nimble/ble.h"
#include "host/ble_hs.h"
+#include "host/util/util.h"
#include "services/gap/ble_svc_gap.h"
/* Application-specified header. */
@@ -79,11 +80,19 @@ bleprph_print_conn_desc(struct ble_gap_conn_desc *desc)
static void
bleprph_advertise(void)
{
+ uint8_t own_addr_type;
struct ble_gap_adv_params adv_params;
struct ble_hs_adv_fields fields;
const char *name;
int rc;
+ /* Figure out address to use while advertising (no privacy for now) */
+ rc = ble_hs_id_infer_auto(0, &own_addr_type);
+ if (rc != 0) {
+ BLEPRPH_LOG(ERROR, "error determining address type; rc=%d\n", rc);
+ return;
+ }
+
/**
* Set the advertisement data included in our advertisements:
* o Flags (indicates advertisement type and other general info).
@@ -129,7 +138,7 @@ bleprph_advertise(void)
memset(&adv_params, 0, sizeof adv_params);
adv_params.conn_mode = BLE_GAP_CONN_MODE_UND;
adv_params.disc_mode = BLE_GAP_DISC_MODE_GEN;
- rc = ble_gap_adv_start(BLE_OWN_ADDR_PUBLIC, NULL, BLE_HS_FOREVER,
+ rc = ble_gap_adv_start(own_addr_type, NULL, BLE_HS_FOREVER,
&adv_params, bleprph_gap_event, NULL);
if (rc != 0) {
BLEPRPH_LOG(ERROR, "error enabling advertisement; rc=%d\n", rc);
@@ -275,6 +284,12 @@ bleprph_on_reset(int reason)
static void
bleprph_on_sync(void)
{
+ int rc;
+
+ /* Make sure we have proper identity address set (public preferred) */
+ rc = ble_hs_util_ensure_addr(0);
+ assert(rc == 0);
+
/* Begin advertising. */
bleprph_advertise();
}
@@ -292,9 +307,6 @@ main(void)
{
int rc;
- /* Set initial BLE device address. */
- memcpy(g_dev_addr, (uint8_t[6]){0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a}, 6);
-
/* Initialize OS */
sysinit();
diff --git a/apps/btshell/pkg.yml b/apps/btshell/pkg.yml
index 74ceb58d4..2e1084ce6 100644
--- a/apps/btshell/pkg.yml
+++ b/apps/btshell/pkg.yml
@@ -24,12 +24,11 @@ pkg.keywords:
pkg.deps:
- kernel/os
- - net/nimble/controller
- net/nimble/host
- net/nimble/host/services/gap
- net/nimble/host/services/gatt
- net/nimble/host/store/ram
- - net/nimble/transport/ram
+ - net/nimble/transport
- sys/log/full
- sys/stats/full
- sys/console/full
diff --git a/apps/btshell/src/cmd.c b/apps/btshell/src/cmd.c
index b1a3ebe1c..cd17ce732 100644
--- a/apps/btshell/src/cmd.c
+++ b/apps/btshell/src/cmd.c
@@ -1312,6 +1312,7 @@ cmd_set_addr(void)
}
switch (addr_type) {
+#if MYNEWT_VAL(BLE_DEVICE)
case BLE_ADDR_PUBLIC:
/* We shouldn't be writing to the controller's address (g_dev_addr).
* There is no standard way to set the local public address, so this is
@@ -1320,6 +1321,7 @@ cmd_set_addr(void)
memcpy(g_dev_addr, addr, 6);
ble_hs_id_set_pub(g_dev_addr);
break;
+#endif
case BLE_ADDR_RANDOM:
rc = ble_hs_id_set_rnd(addr);
diff --git a/apps/bleprph-emspi/pkg.yml b/net/nimble/transport/pkg.yml
similarity index 62%
rename from apps/bleprph-emspi/pkg.yml
rename to net/nimble/transport/pkg.yml
index bb0fc9af9..3a59081f9 100644
--- a/apps/bleprph-emspi/pkg.yml
+++ b/net/nimble/transport/pkg.yml
@@ -1,3 +1,4 @@
+#
# 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
@@ -15,30 +16,27 @@
# specific language governing permissions and limitations
# under the License.
#
-pkg.name: apps/bleprph-emspi
-pkg.type: app
-pkg.description: >
- Simple BLE peripheral application. It uses the emspi transport (EM
- SPI protocol).
+
+pkg.name: net/nimble/transport
+pkg.description: Meta-package for NimBLE HCI transport
pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
pkg.homepage: "http://mynewt.apache.org/"
pkg.keywords:
+ - ble
+ - bluetooth
+
+pkg.deps.BLE_HCI_TRANSPORT_NIMBLE_BUILTIN:
+ - net/nimble/transport/ram
+ - net/nimble/controller
-pkg.deps:
- - boot/bootutil
- - boot/split
- - kernel/os
- - mgmt/imgmgr
- - mgmt/newtmgr
- - mgmt/newtmgr/transport/ble
- - net/nimble/host
- - net/nimble/host/services/ans
- - net/nimble/host/services/gap
- - net/nimble/host/services/gatt
- - net/nimble/host/store/config
+pkg.deps.BLE_HCI_TRANSPORT_EMSPI:
- net/nimble/transport/emspi
- - sys/console/full
- - sys/id
- - sys/log/full
- - sys/stats/full
- - sys/sysinit
+
+pkg.deps.BLE_HCI_TRANSPORT_RAM:
+ - net/nimble/transport/ram
+
+pkg.deps.BLE_HCI_TRANSPORT_SOCKET:
+ - net/nimble/transport/socket
+
+pkg.deps.BLE_HCI_TRANSPORT_UART:
+ - net/nimble/transport/uart
diff --git a/net/nimble/transport/syscfg.yml b/net/nimble/transport/syscfg.yml
new file mode 100644
index 000000000..f9aec5f9a
--- /dev/null
+++ b/net/nimble/transport/syscfg.yml
@@ -0,0 +1,39 @@
+# 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.
+#
+
+# Package: net/nimble/transport
+
+syscfg.defs:
+ BLE_HCI_TRANSPORT_NIMBLE_BUILTIN:
+ description: >
+ Enables HCI transport for built-in NimBLE controller.
+ This is virtually the same as enabling RAM HCI transport and
+ adding dependency to NimBLE controller package explicitly.
+ value: 1
+ BLE_HCI_TRANSPORT_EMSPI:
+ description: Enables EM SPI HCI transport package
+ value: 0
+ BLE_HCI_TRANSPORT_RAM:
+ description: Enables RAM HCI transport package
+ value: 0
+ BLE_HCI_TRANSPORT_SOCKET:
+ description: Enables socket HCI transport package
+ value: 0
+ BLE_HCI_TRANSPORT_UART:
+ description: Enables UART HCI transport package
+ value: 0
----------------------------------------------------------------
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