You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by vi...@apache.org on 2020/09/14 23:42:07 UTC

[mynewt-core] branch master updated: Allow oc gatt client as BLE central (#2363)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 44fb4ae  Allow oc gatt client as BLE central (#2363)
44fb4ae is described below

commit 44fb4ae179819e0c66659664d9d7f276da998f68
Author: Brian Giori <br...@gmail.com>
AuthorDate: Mon Sep 14 16:41:56 2020 -0700

    Allow oc gatt client as BLE central (#2363)
    
    * allow oc gatt client as central
---
 net/oic/include/oic/oc_gatt.h         |  5 ++++
 net/oic/include/oic/port/mynewt/ble.h |  8 +++++++
 net/oic/src/port/mynewt/ble_adaptor.c | 44 ++++++++++++++++++++++++++++++++---
 net/oic/syscfg.yml                    |  4 ++++
 4 files changed, 58 insertions(+), 3 deletions(-)

diff --git a/net/oic/include/oic/oc_gatt.h b/net/oic/include/oic/oc_gatt.h
index 7f5bf03..c8befa4 100644
--- a/net/oic/include/oic/oc_gatt.h
+++ b/net/oic/include/oic/oc_gatt.h
@@ -52,6 +52,11 @@ int oc_ble_coap_gatt_srv_init(void);
 void oc_ble_coap_conn_new(uint16_t conn_handle);
 void oc_ble_coap_conn_del(uint16_t conn_handle);
 
+#if (MYNEWT_VAL(OC_BLE_CENTRAL) == 1)
+void oc_ble_coap_gatt_notify_rx(uint16_t conn_handle, uint16_t att_handle,
+                                struct os_mbuf *om);
+#endif
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/net/oic/include/oic/port/mynewt/ble.h b/net/oic/include/oic/port/mynewt/ble.h
index 25bf98e..85eba35 100644
--- a/net/oic/include/oic/port/mynewt/ble.h
+++ b/net/oic/include/oic/port/mynewt/ble.h
@@ -31,6 +31,9 @@ struct oc_endpoint_ble {
     struct oc_ep_hdr ep;
     uint8_t srv_idx;
     uint16_t conn_handle;
+#if (MYNEWT_VAL(OC_BLE_CENTRAL) == 1)
+    uint16_t tx_att_handle;
+#endif
 };
 
 /**
@@ -54,6 +57,11 @@ int oc_endpoint_is_gatt(const struct oc_endpoint *oe);
 int oc_endpoint_gatt_conn_eq(const struct oc_endpoint *oe1,
                              const struct oc_endpoint *oe2);
 
+#if (MYNEWT_VAL(OC_BLE_CENTRAL) == 1)
+void oc_endpoint_gatt_create(struct oc_endpoint_ble *ep, uint16_t conn_handle,
+                             uint16_t attr_handle);
+#endif
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/net/oic/src/port/mynewt/ble_adaptor.c b/net/oic/src/port/mynewt/ble_adaptor.c
index 1288472..e3f06e2 100644
--- a/net/oic/src/port/mynewt/ble_adaptor.c
+++ b/net/oic/src/port/mynewt/ble_adaptor.c
@@ -192,6 +192,7 @@ static const struct ble_gatt_svc_def oc_gatt_svr_svcs[] = { {
     },
 };
 
+#if (MYNEWT_VAL(OC_BLE_CENTRAL) == 0)
 /*
  * Look up service index based on characteristic handle from request.
  */
@@ -207,6 +208,8 @@ oc_ble_req_attr_to_idx(uint16_t attr_handle)
     }
     return -1;
 }
+#endif
+
 
 static uint8_t
 oc_ep_gatt_size(const struct oc_endpoint *oe)
@@ -321,8 +324,11 @@ oc_gatt_chr_access(uint16_t conn_handle, uint16_t attr_handle,
     switch (ctxt->op) {
     case BLE_GATT_ACCESS_OP_WRITE_CHR:
         m = ctxt->om;
-
+#if (MYNEWT_VAL(OC_BLE_CENTRAL) == 1)
+        srv_idx = OC_BLE_SRV_NONE;
+#else
         srv_idx = oc_ble_req_attr_to_idx(attr_handle);
+#endif
         assert(srv_idx >= 0);
         rc = oc_ble_reass(m, conn_handle, srv_idx);
         if (rc) {
@@ -391,6 +397,32 @@ oc_ble_coap_conn_del(uint16_t conn_handle)
     oc_stream_conn_del(&oc_ble_r, &ep_desc);
 }
 
+#if (MYNEWT_VAL(OC_BLE_CENTRAL) == 1)
+void
+oc_endpoint_gatt_create(struct oc_endpoint_ble *ep, uint16_t conn_handle,
+                        uint16_t attr_handle)
+{
+    ep->ep.oe_type = oc_gatt_transport_id;
+    ep->conn_handle = conn_handle;
+    ep->tx_att_handle = attr_handle;
+    ep->srv_idx = OC_BLE_SRV_NONE;
+}
+#endif
+
+#if (MYNEWT_VAL(OC_BLE_CENTRAL) == 1)
+void
+oc_ble_coap_gatt_notify_rx(uint16_t conn_handle, uint16_t att_handle,
+                           struct os_mbuf *om)
+{
+    struct ble_gatt_access_ctxt ctxt = {
+            .op = BLE_GATT_ACCESS_OP_WRITE_CHR,
+            .om = om,
+    };
+    oc_gatt_chr_access(conn_handle, att_handle, &ctxt, NULL);
+    om = NULL;
+}
+#endif
+
 /*
  * This runs in the context of task handling coap.
  */
@@ -500,11 +532,14 @@ oc_send_buffer_gatt(struct os_mbuf *m)
     STATS_INC(oc_ble_stats, oframe);
     STATS_INCN(oc_ble_stats, obytes, OS_MBUF_PKTLEN(m));
 
+#if (MYNEWT_VAL(OC_BLE_CENTRAL) == 1)
+    attr_handle = oe_ble->tx_att_handle;
+#else
     if (oe_ble->srv_idx >= OC_BLE_SRV_CNT) {
         goto err;
     }
     attr_handle = oc_ble_srv_handles[oe_ble->srv_idx].rsp;
-
+#endif
     mtu = ble_att_mtu(conn_handle);
     if (mtu < 4) {
         oc_ble_coap_conn_del(conn_handle);
@@ -519,8 +554,11 @@ oc_send_buffer_gatt(struct os_mbuf *m)
     while (1) {
         STATS_INC(oc_ble_stats, oseg);
         pkt = STAILQ_NEXT(OS_MBUF_PKTHDR(m), omp_next);
-
+#if (MYNEWT_VAL(OC_BLE_CENTRAL) == 1)
+        ble_gattc_write_no_rsp(conn_handle, attr_handle, m);
+#else
         ble_gattc_notify_custom(conn_handle, attr_handle, m);
+#endif
         if (pkt) {
             m = OS_MBUF_PKTHDR_TO_MBUF(pkt);
         } else {
diff --git a/net/oic/syscfg.yml b/net/oic/syscfg.yml
index fed24de..982b59f 100644
--- a/net/oic/syscfg.yml
+++ b/net/oic/syscfg.yml
@@ -64,6 +64,10 @@ syscfg.defs:
         description: 'Enables OIC server support'
         value: '0'
 
+    OC_BLE_CENTRAL:
+        description: 'Send messages as characteristic writes'
+        value: '0'
+
     OC_DEBUG:
         description: 'Enables OIC debug logs'
         value: '0'