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 11:04:51 UTC
[8/9] 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/b6e799f1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/b6e799f1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/b6e799f1
Branch: refs/heads/upf54
Commit: b6e799f166de0b5b4d679dba0e8b160a165c07a8
Parents: e38c2ad
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 18:43:21 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/b6e799f1/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