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

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

commit ef71328177fb8d061501656e53fa3b2f77a19a37
Author: Christopher Collins <ccoll...@apache.org>
AuthorDate: Tue Aug 8 16:23:22 2017 -0700

    nmxact - Allow BLE security in CoAP services.
---
 nmxact/nmble/ble_util.go | 35 +++++++++++++++++++++++++----------
 1 file changed, 25 insertions(+), 10 deletions(-)

diff --git a/nmxact/nmble/ble_util.go b/nmxact/nmble/ble_util.go
index 932cb30..470db01 100644
--- a/nmxact/nmble/ble_util.go
+++ b/nmxact/nmble/ble_util.go
@@ -682,31 +682,46 @@ func GattService() BleSvc {
        }
 }
 
-func GenCoapService(x *BleXport, svcUuid BleUuid, reqChrUuid BleUuid,
-       rspChrUuid BleUuid, resources []oic.Resource) (BleSvc, error) {
-
-       svr := NewBleOicSvr(x, svcUuid, rspChrUuid)
-       for _, r := range resources {
+type CoapServiceCfg struct {
+       x          *BleXport
+       svcUuid    BleUuid
+       reqChrUuid BleUuid
+       rspChrUuid BleUuid
+       enc        bool
+       auth       bool
+       resources  []oic.Resource
+}
+
+func GenCoapService(cfg CoapServiceCfg) (BleSvc, error) {
+       svr := NewBleOicSvr(cfg.x, cfg.svcUuid, cfg.rspChrUuid)
+       for _, r := range cfg.resources {
                if err := svr.AddResource(r); err != nil {
                        return BleSvc{}, err
                }
        }
 
+       var secFlags BleChrFlags
+       if cfg.enc {
+               secFlags |= BLE_GATT_F_WRITE_ENC
+       }
+       if cfg.auth {
+               secFlags |= BLE_GATT_F_WRITE_AUTHEN
+       }
        svc := BleSvc{
-               Uuid:    svcUuid,
+               Uuid:    cfg.svcUuid,
                SvcType: BLE_SVC_TYPE_PRIMARY,
                Chrs: []BleChr{
                        BleChr{
-                               Uuid:       reqChrUuid,
-                               Flags:      BLE_GATT_F_WRITE_NO_RSP, /* XXX: 
Security */
+                               Uuid:       cfg.reqChrUuid,
+                               Flags:      BLE_GATT_F_WRITE_NO_RSP | secFlags,
                                MinKeySize: 0,
                                AccessCb: func(access BleGattAccess) (uint8, 
[]byte) {
                                        return svr.Rx(access), nil
                                },
                        },
                        BleChr{
-                               Uuid:       rspChrUuid,
-                               Flags:      BLE_GATT_F_NOTIFY, /* XXX: Security 
*/
+                               Uuid:       cfg.rspChrUuid,
+                               Flags:      BLE_GATT_F_NOTIFY,
                                MinKeySize: 0,
                                AccessCb:   nil,
                        },

-- 
To stop receiving notification emails like this one, please contact
"commits@mynewt.apache.org" <commits@mynewt.apache.org>.

Reply via email to