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/10/25 18:34:38 UTC
incubator-mynewt-core git commit: oic - Remove high-level operations
from lib.
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/develop bb7a847e7 -> fda91e8ac
oic - Remove high-level operations from lib.
The application now chooses when / how / what to advertise and scan,
rather than the OIC library.
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/fda91e8a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/fda91e8a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/fda91e8a
Branch: refs/heads/develop
Commit: fda91e8ac5e4f9df70c4473e85e860c8145a16b7
Parents: bb7a847
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Oct 25 11:33:13 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Oct 25 11:34:34 2016 -0700
----------------------------------------------------------------------
apps/ocf_sample/src/main.c | 8 +
net/oic/src/port/mynewt/adaptor.c | 8 +-
net/oic/src/port/mynewt/adaptor.h | 2 -
net/oic/src/port/mynewt/ble_adaptor.c | 268 ++---------------------------
4 files changed, 23 insertions(+), 263 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fda91e8a/apps/ocf_sample/src/main.c
----------------------------------------------------------------------
diff --git a/apps/ocf_sample/src/main.c b/apps/ocf_sample/src/main.c
index 0f5a559..dffe4d2 100644
--- a/apps/ocf_sample/src/main.c
+++ b/apps/ocf_sample/src/main.c
@@ -35,6 +35,7 @@
#endif
#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
+#include "host/ble_hs.h"
#include "ocf_sample.h"
#endif
@@ -237,6 +238,13 @@ oc_signal_main_loop(void)
void
ocf_task_handler(void *arg)
{
+#if MYNEWT_VAL(OC_TRANSPORT_GATT)
+ int rc;
+
+ rc = ble_hs_start();
+ assert(rc == 0);
+#endif
+
os_sem_init(&ocf_main_loop_sem, 1);
while (1) {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fda91e8a/net/oic/src/port/mynewt/adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/adaptor.c b/net/oic/src/port/mynewt/adaptor.c
index 73ecc8b..b61ba02 100644
--- a/net/oic/src/port/mynewt/adaptor.c
+++ b/net/oic/src/port/mynewt/adaptor.c
@@ -111,12 +111,8 @@ void oc_send_multicast_message(oc_message_t *message)
/* send all the entries to the OCF stack through the same task */
void
-oc_task_handler(void *arg) {
-
-#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
- oc_connectivity_start_gatt();
-#endif
-
+oc_task_handler(void *arg)
+{
while (1) {
struct os_callout_func *cf;
oc_message_t *pmsg;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fda91e8a/net/oic/src/port/mynewt/adaptor.h
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/adaptor.h b/net/oic/src/port/mynewt/adaptor.h
index 16ebd6c..9378f49 100644
--- a/net/oic/src/port/mynewt/adaptor.h
+++ b/net/oic/src/port/mynewt/adaptor.h
@@ -41,12 +41,10 @@ oc_message_t *oc_attempt_rx_ip(void);
#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
int oc_connectivity_init_gatt(void);
-void oc_connectivity_start_gatt(void);
void oc_connectivity_shutdown_gatt(void);
void oc_send_buffer_gatt(oc_message_t *message);
void oc_send_buffer_gatt_mcast(oc_message_t *message);
oc_message_t *oc_attempt_rx_gatt(void);
-
#endif
#if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fda91e8a/net/oic/src/port/mynewt/ble_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/ble_adaptor.c b/net/oic/src/port/mynewt/ble_adaptor.c
index ad28c72..13b0ba6 100644
--- a/net/oic/src/port/mynewt/ble_adaptor.c
+++ b/net/oic/src/port/mynewt/ble_adaptor.c
@@ -46,9 +46,6 @@ const uint8_t gatt_svr_chr_coap[16] = {
/* queue to hold mbufs until we get called from oic */
struct os_mqueue ble_coap_mq;
-static int
-blecoap_gap_event(struct ble_gap_event *event, void *arg);
-
#if (MYNEWT_VAL(OC_SERVER) == 1)
/* ble nmgr attr handle */
uint16_t g_ble_coap_attr_handle;
@@ -79,7 +76,7 @@ static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
static int
gatt_svr_chr_access_coap(uint16_t conn_handle, uint16_t attr_handle,
- struct ble_gatt_access_ctxt *ctxt, void *arg)
+ struct ble_gatt_access_ctxt *ctxt, void *arg)
{
struct os_mbuf *m;
int rc;
@@ -111,182 +108,9 @@ gatt_svr_chr_access_coap(uint16_t conn_handle, uint16_t attr_handle,
return 0;
}
-static int
-oc_gatt_advertise(void)
-{
- struct ble_gap_adv_params adv_params;
- struct ble_hs_adv_fields fields;
- int rc;
-
- /*
- * Set the advertisement data included in our advertisements:
- * o Flags (indicates advertisement type and other general info).
- * o Advertising tx power.
- * o 128 bit UUID
- */
-
- memset(&fields, 0, sizeof fields);
-
- /* Indicate that the flags field should be included; specify a value of 0
- * to instruct the stack to fill the value in for us.
- */
- fields.flags_is_present = 1;
- fields.flags = 0;
-
- /* Indicate that the TX power level field should be included; have the
- * stack fill this one automatically as well. This is done by assigning
- * 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;
-
- fields.uuids128 = (void *)gatt_svr_svc_coap;
- fields.num_uuids128 = 1;
- fields.uuids128_is_complete = 1;
-
- rc = ble_gap_adv_set_fields(&fields);
- if (rc != 0) {
- return rc;
- }
-
- memset(&fields, 0, sizeof fields);
- fields.name = (uint8_t *)ble_svc_gap_device_name();
- fields.name_len = strlen((char *)fields.name);
- fields.name_is_complete = 1;
-
- rc = ble_gap_adv_rsp_set_fields(&fields);
- if (rc != 0) {
- return rc;
- }
-
- /* 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_ADDR_TYPE_PUBLIC, 0, NULL, BLE_HS_FOREVER,
- &adv_params, blecoap_gap_event, NULL);
- return rc;
-}
-#endif
-
-#if (MYNEWT_VAL(OC_CLIENT) == 1)
-static char *
-addr_str(const void *addr)
-{
- static char buf[6 * 2 + 5 + 1];
- const uint8_t *u8p;
-
- u8p = addr;
- sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x",
- u8p[5], u8p[4], u8p[3], u8p[2], u8p[1], u8p[0]);
-
- return buf;
-}
-
-
-/**
- * Indicates whether we should tre to connect to the sender of the specified
- * advertisement. The function returns a positive result if the device
- * advertises connectability and support for the Alert Notification service.
- */
-static int
-oc_gatt_should_connect(const struct ble_gap_disc_desc *disc)
-{
- int i;
-
- /* The device has to be advertising connectability. */
- if (disc->event_type != BLE_HCI_ADV_RPT_EVTYPE_ADV_IND &&
- disc->event_type != BLE_HCI_ADV_RPT_EVTYPE_DIR_IND) {
-
- return 0;
- }
-
- /* The device has to advertise support for the COAP service
- */
- for (i = 0; i < disc->fields->num_uuids128; i++) {
- char *ptr = ((char*) disc->fields->uuids128) + 16 * i;
- if (memcmp(ptr, gatt_svr_svc_coap, sizeof(gatt_svr_svc_coap)) == 0) {
- return 1;
- }
- }
-
- return 0;
-}
-
-/**
- * Connects to the sender of the specified advertisement of it looks
- * interesting. A device is "interesting" if it advertises connectability and
- * support for the Alert Notification service.
- */
-static void
-oc_gatt_connect_if_interesting(const struct ble_gap_disc_desc *disc)
-{
- int rc;
-
- /* Don't do anything if we don't care about this advertiser. */
- if (!oc_gatt_should_connect(disc)) {
- return;
- }
-
- /* Scanning must be stopped before a connection can be initiated. */
- rc = ble_gap_disc_cancel();
- if (rc != 0) {
- ERROR("Failed to cancel scan; rc=%d\n", rc);
- return;
- }
-
- /* Try to connect the the advertiser. Allow 30 seconds (30000 ms) for
- * timeout.
- */
- rc = ble_gap_connect(BLE_ADDR_TYPE_PUBLIC, disc->addr_type, disc->addr,
- 30000, NULL, blecoap_gap_event, NULL);
- if (rc != 0) {
- ERROR("Error: Failed to connect to device; addr_type=%d "
- "addr=%s\n", disc->addr_type, addr_str(disc->addr));
- return;
- }
-}
-
-
-/**
- * Initiates the GAP general discovery procedure.
- */
-static int
-oc_gatt_scan(void)
-{
- struct ble_gap_disc_params disc_params;
- int rc;
-
- /* Tell the controller to filter duplicates; we don't want to process
- * repeated advertisements from the same device.
- */
- disc_params.filter_duplicates = 1;
-
- /**
- * Perform a passive scan. I.e., don't send follow-up scan requests to
- * each advertiser.
- */
- disc_params.passive = 1;
-
- /* Use defaults for the rest of the parameters. */
- disc_params.itvl = 0;
- disc_params.window = 0;
- disc_params.filter_policy = 0;
- disc_params.limited = 0;
-
- rc = ble_gap_disc(BLE_ADDR_TYPE_PUBLIC, BLE_HS_FOREVER, &disc_params,
- blecoap_gap_event, NULL);
- if (rc != 0) {
- ERROR("Error initiating GAP discovery procedure; rc=%d\n",
- rc);
- }
- return rc;
-}
-
-#endif
-
oc_message_t *
-oc_attempt_rx_gatt(void) {
+oc_attempt_rx_gatt(void)
+{
int rc;
struct os_mbuf *m = NULL;
struct os_mbuf_pkthdr *pkt;
@@ -312,7 +136,7 @@ oc_attempt_rx_gatt(void) {
LOG("oc_transport_gatt rx %p-%u\n", pkt, pkt->omp_len);
/* get the conn handle from the end of the message */
rc = os_mbuf_copydata(m, pkt->omp_len - sizeof(conn_handle),
- sizeof(conn_handle), &conn_handle);
+ sizeof(conn_handle), &conn_handle);
if (rc != 0) {
ERROR("Failed to retrieve conn_handle from mbuf \n");
goto rx_attempt_err;
@@ -355,55 +179,7 @@ rx_attempt_err:
}
return NULL;
}
-
-static int
-blecoap_gap_event(struct ble_gap_event *event, void *arg)
-{
- switch (event->type) {
-#if (MYNEWT_VAL(OC_CLIENT) == 1)
- case BLE_GAP_EVENT_DISC:
- /* Try to connect to the advertiser if it looks interesting. */
- oc_gatt_connect_if_interesting(&event->disc);
- return 0;
-#endif
- case BLE_GAP_EVENT_CONNECT:
- /* A new connection was established or a connection attempt failed. */
- if (event->connect.status == 0) {
- /* nothing to do here on the server */
- }
- if (event->connect.status != 0) {
- /* nothing to do here on the client */
- }
-
-#if (MYNEWT_VAL(OC_SERVER) == 1)
- /* keep advertising for multiple connections */
- oc_gatt_advertise();
-#endif
-#if (MYNEWT_VAL(OC_CLIENT) == 1)
- /* keep scanning for new connections */
- oc_gatt_scan();
-#endif
- return 0;
-
- case BLE_GAP_EVENT_DISCONNECT:
- /* Connection terminated; resume advertising. */
-#if (MYNEWT_VAL(OC_CLIENT) == 1)
- /* keep scanning for new connections */
- oc_gatt_scan();
-#endif
-#if (MYNEWT_VAL(OC_SERVER) == 1)
- /* resume advertising */
- oc_gatt_advertise();
-#endif
- return 0;
-#if (MYNEWT_VAL(OC_CLIENT) == 1)
- case BLE_GAP_EVENT_NOTIFY_RX:
- /* TODO queue the packet */
- return 0;
#endif
- }
- return 0;
-}
int
ble_coap_gatt_srv_init(struct os_eventq **out)
@@ -425,40 +201,22 @@ ble_coap_gatt_srv_init(struct os_eventq **out)
return 0;
}
-int oc_connectivity_init_gatt(void) {
+int
+oc_connectivity_init_gatt(void)
+{
os_mqueue_init(&ble_coap_mq, NULL);
ble_coap_mq.mq_ev.ev_type = OC_ADATOR_EVENT_GATT;
return 0;
}
-void oc_connectivity_start_gatt(void) {
- int rc;
- rc = ble_hs_start();
- if (rc != 0) {
- goto err;
- }
-#if (MYNEWT_VAL(OC_SERVER) == 1)
- rc = oc_gatt_advertise();
- if (rc != 0) {
- goto err;
- }
-#endif
-#if (MYNEWT_VAL(OC_CLIENT) == 1)
- rc = oc_gatt_scan();
- if (rc != 0) {
- goto err;
- }
-#endif
-err:
- ERROR("error enabling advertisement; rc=%d\n", rc);
-}
-
-void oc_connectivity_shutdown_gatt(void)
+void
+oc_connectivity_shutdown_gatt(void)
{
/* there is not unregister for BLE */
}
-void oc_send_buffer_gatt(oc_message_t *message)
+void
+oc_send_buffer_gatt(oc_message_t *message)
{
struct os_mbuf *m = NULL;
int rc;
@@ -483,7 +241,7 @@ void oc_send_buffer_gatt(oc_message_t *message)
#if (MYNEWT_VAL(OC_SERVER) == 1)
ble_gattc_notify_custom(message->endpoint.bt_addr.conn_handle,
- g_ble_coap_attr_handle, m);
+ g_ble_coap_attr_handle, m);
m = NULL;
#endif
@@ -506,4 +264,4 @@ oc_send_buffer_gatt_mcast(oc_message_t *message)
#endif
}
-#endif
\ No newline at end of file
+#endif