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/04/05 05:24:36 UTC
[2/3] incubator-mynewt-core git commit: bletiny - Add "sec start"
command.
bletiny - Add "sec start" command.
This command initializes pairing.
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/7432082f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/7432082f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/7432082f
Branch: refs/heads/develop
Commit: 7432082fc125d48f7c34d34d83953d5a798b2f00
Parents: adb982f
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Apr 4 20:18:18 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Apr 4 20:18:18 2016 -0700
----------------------------------------------------------------------
apps/bletiny/src/bletiny_priv.h | 1 +
apps/bletiny/src/cmd.c | 42 ++++++++++++++++++++++++++++++++++++
apps/bletiny/src/main.c | 23 +++++++++++++++++++-
3 files changed, 65 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7432082f/apps/bletiny/src/bletiny_priv.h
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/bletiny_priv.h b/apps/bletiny/src/bletiny_priv.h
index e32251b..12551d7 100644
--- a/apps/bletiny/src/bletiny_priv.h
+++ b/apps/bletiny/src/bletiny_priv.h
@@ -161,6 +161,7 @@ void bletiny_chrup(uint16_t attr_handle);
int bletiny_l2cap_update(uint16_t conn_handle,
struct ble_l2cap_sig_update_params *params);
int bletiny_show_rssi(uint16_t conn_handle);
+int bletiny_sec_start(uint16_t conn_handle);
#define BLETINY_LOG_MODULE (LOG_MODULE_PERUSER + 0)
#define BLETINY_LOG(lvl, ...) \
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7432082f/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index b89e5e3..421d49a 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -884,6 +884,47 @@ cmd_show(int argc, char **argv)
}
/*****************************************************************************
+ * $sec *
+ *****************************************************************************/
+
+static int
+cmd_sec_start(int argc, char **argv)
+{
+ uint16_t conn_handle;
+ int rc;
+
+ conn_handle = parse_arg_uint16("conn", &rc);
+ if (rc != 0) {
+ return rc;
+ }
+
+ rc = bletiny_sec_start(conn_handle);
+ if (rc != 0) {
+ console_printf("error starting security; rc=%d\n", rc);
+ return rc;
+ }
+
+ return 0;
+}
+
+static struct cmd_entry cmd_sec_entries[] = {
+ { "start", cmd_sec_start },
+};
+
+static int
+cmd_sec(int argc, char **argv)
+{
+ int rc;
+
+ rc = cmd_exec(cmd_sec_entries, argc, argv);
+ if (rc != 0) {
+ return rc;
+ }
+
+ return 0;
+}
+
+/*****************************************************************************
* $set *
*****************************************************************************/
@@ -1436,6 +1477,7 @@ static struct cmd_entry cmd_b_entries[] = {
{ "read", cmd_read },
{ "scan", cmd_scan },
{ "show", cmd_show },
+ { "sec", cmd_sec },
{ "set", cmd_set },
{ "term", cmd_term },
{ "update", cmd_update },
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7432082f/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index 44815fc..17b4744 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -188,6 +188,13 @@ bletiny_print_conn_desc(struct ble_gap_conn_desc *desc)
}
static void
+bletiny_print_sec_params(struct ble_gap_sec_params *sec_params)
+{
+ console_printf("pair_alg=%d enc_enabled=%d\n", sec_params->pair_alg,
+ sec_params->enc_enabled);
+}
+
+static void
bletiny_print_adv_fields(struct ble_hs_adv_fields *fields)
{
uint32_t u32;
@@ -882,7 +889,7 @@ bletiny_on_notify(uint16_t conn_handle, uint16_t attr_handle,
static int
bletiny_on_connect(int event, int status, struct ble_gap_conn_ctxt *ctxt,
- void *arg)
+ void *arg)
{
int conn_idx;
@@ -926,6 +933,11 @@ bletiny_on_connect(int event, int status, struct ble_gap_conn_ctxt *ctxt,
console_printf("connection update request; status=%d ", status);
*ctxt->update.self_params = *ctxt->update.peer_params;
break;
+
+ case BLE_GAP_EVENT_SECURITY:
+ console_printf("security event; status=%d ", status);
+ bletiny_print_sec_params(ctxt->sec_params);
+ break;
}
bletiny_unlock();
@@ -1297,6 +1309,15 @@ bletiny_show_rssi(uint16_t conn_handle)
}
+int
+bletiny_sec_start(uint16_t conn_handle)
+{
+ int rc;
+
+ rc = ble_gap_security_initiate(conn_handle);
+ return rc;
+}
+
/**
* BLE test task
*