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/06/06 14:30:13 UTC

[05/13] incubator-mynewt-core git commit: bletiny - Require all fields for store add sec.

bletiny - Require all fields for store add sec.


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/770709a6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/770709a6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/770709a6

Branch: refs/heads/upf54
Commit: 770709a69b2682400ef4f1db6434a15fb57ecf6f
Parents: 0b12025
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Jun 6 18:43:21 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jun 6 19:06:25 2016 +0800

----------------------------------------------------------------------
 apps/bletiny/src/cmd.c | 62 ++++++++++++++++++++-------------------------
 1 file changed, 28 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/770709a6/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index f64879a..ec9e34b 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -1714,20 +1714,17 @@ cmd_write(int argc, char **argv)
 /*****************************************************************************
  * store                                                                     *
  *****************************************************************************/
-#define BLETINY_CMD_KEYSTORE_ENTRY_TYPE_MST_SEC 0
-#define BLETINY_CMD_KEYSTORE_ENTRY_TYPE_SLV_SEC 1
-#define BLETINY_CMD_KEYSTORE_ENTRY_TYPE_CCCD_SEC 2
 
 static struct kv_pair cmd_keystore_entry_type[] = {
-    { "msec",         BLE_STORE_OBJ_TYPE_MST_SEC },
-    { "ssec",         BLE_STORE_OBJ_TYPE_SLV_SEC },
-    { "cccd",         BLE_STORE_OBJ_TYPE_CCCD },
+    { "msec",       BLE_STORE_OBJ_TYPE_MST_SEC },
+    { "ssec",       BLE_STORE_OBJ_TYPE_SLV_SEC },
+    { "cccd",       BLE_STORE_OBJ_TYPE_CCCD },
     { NULL }
 };
 
 static struct kv_pair cmd_keystore_addr_type[] = {
-    { "public",         BLE_ADDR_TYPE_PUBLIC },
-    { "random",         BLE_ADDR_TYPE_RANDOM },
+    { "public",     BLE_ADDR_TYPE_PUBLIC },
+    { "random",     BLE_ADDR_TYPE_RANDOM },
     { NULL }
 };
 
@@ -1735,41 +1732,38 @@ static int
 cmd_keystore_parse_keydata(int argc, char **argv, union ble_store_key *out,
                            int *obj_type)
 {
-    int type;
     int rc;
 
     memset(out, 0, sizeof(*out));
-    type = parse_arg_kv("type", cmd_keystore_entry_type);
-    *obj_type = type;
-
-    switch (type) {
-        case BLE_STORE_OBJ_TYPE_MST_SEC:
-        case BLE_STORE_OBJ_TYPE_SLV_SEC:
-            /* try to parse by address and type */
-                out->sec.peer_addr_type =
-                        parse_arg_kv("addr_type", cmd_keystore_addr_type);
-                rc = parse_arg_mac("addr", out->sec.peer_addr);
+    *obj_type = parse_arg_kv("type", cmd_keystore_entry_type);
 
-                if (rc || out->sec.peer_addr_type < 0) {
+    switch (*obj_type) {
+    case BLE_STORE_OBJ_TYPE_MST_SEC:
+    case BLE_STORE_OBJ_TYPE_SLV_SEC:
+        rc = parse_arg_kv("addr_type", cmd_keystore_addr_type);
+        if (rc < 0) {
+            return EINVAL;
+        }
 
-                    out->sec.peer_addr_type = BLE_STORE_ADDR_TYPE_NONE;
+        rc = parse_arg_mac("addr", out->sec.peer_addr);
+        if (rc != 0) {
+            return rc;
+        }
 
-                    out->sec.ediv = parse_arg_uint16("ediv", &rc);
-                    if (rc != 0) {
-                        return rc;
-                    }
+        out->sec.ediv = parse_arg_uint16("ediv", &rc);
+        if (rc != 0) {
+            return rc;
+        }
 
-                    out->sec.rand_num = parse_arg_uint64("rand", &rc);
-                    if (rc != 0) {
-                        return rc;
-                    }
-                }
+        out->sec.rand_num = parse_arg_uint64("rand", &rc);
+        if (rc != 0) {
+            return rc;
+        }
+        return 0;
 
-                break;
-        default:
-            return -1;
+    default:
+        return -1;
     }
-    return 0;
 }
 
 static int