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/05 11:52:01 UTC
[14/43] incubator-mynewt-core git commit: BLE Host - rename sm
identifiers for consistency.
BLE Host - rename sm identifiers for consistency.
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/ac11583f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/ac11583f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/ac11583f
Branch: refs/heads/develop
Commit: ac11583f7baf651f964b0ec34f3d7c37554ba694
Parents: 2fa2f24
Author: Christopher Collins <cc...@apache.org>
Authored: Mon May 30 23:32:40 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Sun Jun 5 19:09:19 2016 +0800
----------------------------------------------------------------------
apps/bletiny/src/cmd.c | 6 +-
net/nimble/host/include/host/ble_l2cap.h | 85 ----------------
net/nimble/host/include/host/ble_sm.h | 96 ++++++++++++++++++
net/nimble/host/src/ble_gap.c | 2 +-
net/nimble/host/src/ble_gap_priv.h | 2 +-
net/nimble/host/src/ble_sm.c | 136 +++++++++++++-------------
net/nimble/host/src/ble_sm_cmd.c | 55 +++++------
net/nimble/host/src/ble_sm_lgcy.c | 25 ++---
net/nimble/host/src/ble_sm_priv.h | 129 ++++++++++++------------
net/nimble/host/src/ble_sm_sc.c | 13 +--
net/nimble/host/src/test/ble_sm_test.c | 23 ++---
11 files changed, 292 insertions(+), 280 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac11583f/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index 7216377..27971dc 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -1940,8 +1940,8 @@ cmd_passkey(int argc, char **argv)
}
switch(pk.action) {
- case BLE_GAP_PKACT_INPUT:
- case BLE_GAP_PKACT_DISP:
+ case BLE_SM_PKACT_INPUT:
+ case BLE_SM_PKACT_DISP:
/* passkey is 6 digit number */
pk.passkey = parse_arg_long_bounds("key", 0, 999999, &rc);
if (rc != 0) {
@@ -1949,7 +1949,7 @@ cmd_passkey(int argc, char **argv)
}
break;
- case BLE_GAP_PKACT_OOB:
+ case BLE_SM_PKACT_OOB:
rc = parse_arg_byte_stream_exact_length("oob", pk.oob, 16);
if (rc != 0) {
return rc;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac11583f/net/nimble/host/include/host/ble_l2cap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_l2cap.h b/net/nimble/host/include/host/ble_l2cap.h
index 05b75ff..620e0eb 100644
--- a/net/nimble/host/include/host/ble_l2cap.h
+++ b/net/nimble/host/include/host/ble_l2cap.h
@@ -52,68 +52,6 @@ struct ble_hs_conn;
#define BLE_L2CAP_SIG_ERR_MTU_EXCEEDED 0x0001
#define BLE_L2CAP_SIG_ERR_INVALID_CID 0x0002
-#define BLE_SM_OP_PAIR_REQ 0x01
-#define BLE_SM_OP_PAIR_RSP 0x02
-#define BLE_SM_OP_PAIR_CONFIRM 0x03
-#define BLE_SM_OP_PAIR_RANDOM 0x04
-#define BLE_SM_OP_PAIR_FAIL 0x05
-#define BLE_SM_OP_ENC_INFO 0x06
-#define BLE_SM_OP_MASTER_ID 0x07
-#define BLE_SM_OP_IDENTITY_INFO 0x08
-#define BLE_SM_OP_IDENTITY_ADDR_INFO 0x09
-#define BLE_SM_OP_SIGN_INFO 0x0a
-#define BLE_SM_OP_SEC_REQ 0x0b
-#define BLE_SM_OP_PAIR_PUBLIC_KEY 0x0c
-#define BLE_SM_OP_PAIR_DHKEY_CHECK 0x0d
-#define BLE_SM_OP_PAIR_KEYPRESS_NOTIFY 0x0e
-
-#define BLE_SM_ERR_PASSKEY 0x01
-#define BLE_SM_ERR_OOB 0x02
-#define BLE_SM_ERR_AUTHREQ 0x03
-#define BLE_SM_ERR_CONFIRM_MISMATCH 0x04
-#define BLE_SM_ERR_PAIR_NOT_SUPP 0x05
-#define BLE_SM_ERR_ENC_KEY_SZ 0x06
-#define BLE_SM_ERR_CMD_NOT_SUPP 0x07
-#define BLE_SM_ERR_UNSPECIFIED 0x08
-#define BLE_SM_ERR_REPEATED 0x09
-#define BLE_SM_ERR_INVAL 0x0a
-#define BLE_SM_ERR_DHKEY 0x0b
-#define BLE_SM_ERR_NUM_CMP 0x0c
-#define BLE_SM_ERR_ALREADY 0x0d
-#define BLE_SM_ERR_CROSS_TRANS 0x0e
-#define BLE_SM_ERR_MAX_PLUS_1 0x0f
-
-#define BLE_SM_PAIR_ALG_JW 0
-#define BLE_SM_PAIR_ALG_PASSKEY 1
-#define BLE_SM_PAIR_ALG_OOB 2
-#define BLE_SM_PAIR_ALG_NUM_CMP 3
-
-#define BLE_SM_PAIR_KEY_DIST_ENC 0x01
-#define BLE_SM_PAIR_KEY_DIST_ID 0x02
-#define BLE_SM_PAIR_KEY_DIST_SIGN 0x04
-#define BLE_SM_PAIR_KEY_DIST_LINK 0x08
-#define BLE_SM_PAIR_KEY_DIST_RESERVED 0xf0
-
-#define BLE_SM_IO_CAP_DISP_ONLY 0x00
-#define BLE_SM_IO_CAP_DISP_YES_NO 0x01
-#define BLE_SM_IO_CAP_KEYBOARD_ONLY 0x02
-#define BLE_SM_IO_CAP_NO_IO 0x03
-#define BLE_SM_IO_CAP_KEYBOARD_DISP 0x04
-#define BLE_SM_IO_CAP_RESERVED 0x05
-
-#define BLE_SM_PAIR_OOB_NO 0x00
-#define BLE_SM_PAIR_OOB_YES 0x01
-#define BLE_SM_PAIR_OOB_RESERVED 0x02
-
-#define BLE_SM_PAIR_AUTHREQ_BOND 0x01
-#define BLE_SM_PAIR_AUTHREQ_MITM 0x04
-#define BLE_SM_PAIR_AUTHREQ_SC 0x08
-#define BLE_SM_PAIR_AUTHREQ_KEYPRESS 0x10
-#define BLE_SM_PAIR_AUTHREQ_RESERVED 0xe2
-
-#define BLE_SM_PAIR_KEY_SZ_MIN 7
-#define BLE_SM_PAIR_KEY_SZ_MAX 16
-
typedef void ble_l2cap_sig_update_fn(int status, void *arg);
struct ble_l2cap_sig_update_params {
@@ -127,27 +65,4 @@ int ble_l2cap_sig_update(uint16_t conn_handle,
struct ble_l2cap_sig_update_params *params,
ble_l2cap_sig_update_fn *cb, void *cb_arg);
-/* Strucure to pass the passkey info back to the l2cap */
-struct ble_sm_passkey
-{
- uint8_t action;
- union
- {
- uint32_t passkey;
- uint8_t oob[16];
- };
-};
-
-#if NIMBLE_OPT(SM)
-/* If the application gets a passkey action, it must peform the action
- * and then call this function to notify the host that the action is
- * complete
- */
-int ble_sm_set_tk(uint16_t conn_handle, struct ble_sm_passkey *pkey);
-void ble_sm_connection_broken(uint16_t conn_handle);
-#else
-#define ble_sm_set_tk(conn_handle, pkey) (BLE_HS_ENOTSUP)
-#define ble_sm_connection_broken(conn_handle)
-#endif
-
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac11583f/net/nimble/host/include/host/ble_sm.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_sm.h b/net/nimble/host/include/host/ble_sm.h
new file mode 100644
index 0000000..d6c54a9
--- /dev/null
+++ b/net/nimble/host/include/host/ble_sm.h
@@ -0,0 +1,96 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_BLE_SM_
+#define H_BLE_SM_
+
+#include <inttypes.h>
+#include "nimble/nimble_opt.h"
+
+#define BLE_SM_ERR_PASSKEY 0x01
+#define BLE_SM_ERR_OOB 0x02
+#define BLE_SM_ERR_AUTHREQ 0x03
+#define BLE_SM_ERR_CONFIRM_MISMATCH 0x04
+#define BLE_SM_ERR_PAIR_NOT_SUPP 0x05
+#define BLE_SM_ERR_ENC_KEY_SZ 0x06
+#define BLE_SM_ERR_CMD_NOT_SUPP 0x07
+#define BLE_SM_ERR_UNSPECIFIED 0x08
+#define BLE_SM_ERR_REPEATED 0x09
+#define BLE_SM_ERR_INVAL 0x0a
+#define BLE_SM_ERR_DHKEY 0x0b
+#define BLE_SM_ERR_NUM_CMP 0x0c
+#define BLE_SM_ERR_ALREADY 0x0d
+#define BLE_SM_ERR_CROSS_TRANS 0x0e
+#define BLE_SM_ERR_MAX_PLUS_1 0x0f
+
+#define BLE_SM_PAIR_ALG_JW 0
+#define BLE_SM_PAIR_ALG_PASSKEY 1
+#define BLE_SM_PAIR_ALG_OOB 2
+#define BLE_SM_PAIR_ALG_NUM_CMP 3
+
+#define BLE_SM_PAIR_KEY_DIST_ENC 0x01
+#define BLE_SM_PAIR_KEY_DIST_ID 0x02
+#define BLE_SM_PAIR_KEY_DIST_SIGN 0x04
+#define BLE_SM_PAIR_KEY_DIST_LINK 0x08
+#define BLE_SM_PAIR_KEY_DIST_RESERVED 0xf0
+
+#define BLE_SM_IO_CAP_DISP_ONLY 0x00
+#define BLE_SM_IO_CAP_DISP_YES_NO 0x01
+#define BLE_SM_IO_CAP_KEYBOARD_ONLY 0x02
+#define BLE_SM_IO_CAP_NO_IO 0x03
+#define BLE_SM_IO_CAP_KEYBOARD_DISP 0x04
+#define BLE_SM_IO_CAP_RESERVED 0x05
+
+#define BLE_SM_PAIR_OOB_NO 0x00
+#define BLE_SM_PAIR_OOB_YES 0x01
+#define BLE_SM_PAIR_OOB_RESERVED 0x02
+
+#define BLE_SM_PAIR_AUTHREQ_BOND 0x01
+#define BLE_SM_PAIR_AUTHREQ_MITM 0x04
+#define BLE_SM_PAIR_AUTHREQ_SC 0x08
+#define BLE_SM_PAIR_AUTHREQ_KEYPRESS 0x10
+#define BLE_SM_PAIR_AUTHREQ_RESERVED 0xe2
+
+#define BLE_SM_PAIR_KEY_SZ_MIN 7
+#define BLE_SM_PAIR_KEY_SZ_MAX 16
+
+/*
+ * The security manager asks the application to perform a key generation
+ * action. The application passes the passkey back to SM via ble_sm_set_tk().
+ */
+#define BLE_SM_PKACT_NONE 0
+#define BLE_SM_PKACT_OOB 1
+#define BLE_SM_PKACT_INPUT 2
+#define BLE_SM_PKACT_DISP 3
+
+struct ble_sm_passkey {
+ uint8_t action;
+ union {
+ uint32_t passkey;
+ uint8_t oob[16];
+ };
+};
+
+#if NIMBLE_OPT(SM)
+int ble_sm_set_tk(uint16_t conn_handle, struct ble_sm_passkey *pkey);
+#else
+#define ble_sm_set_tk(conn_handle, pkey) (BLE_HS_ENOTSUP)
+#endif
+
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac11583f/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index 2ce1828..2fe4c8f 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -2178,7 +2178,7 @@ ble_gap_passkey_event(uint16_t conn_handle, uint8_t passkey_action)
}
void
-ble_gap_enc_changed(uint16_t conn_handle, int status,
+ble_gap_enc_event(uint16_t conn_handle, int status,
struct ble_gap_sec_state *sec_state)
{
struct ble_gap_conn_ctxt ctxt;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac11583f/net/nimble/host/src/ble_gap_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap_priv.h b/net/nimble/host/src/ble_gap_priv.h
index 6fb987f..f7b8e5d 100644
--- a/net/nimble/host/src/ble_gap_priv.h
+++ b/net/nimble/host/src/ble_gap_priv.h
@@ -74,7 +74,7 @@ void ble_gap_rx_update_complete(struct hci_le_conn_upd_complete *evt);
void ble_gap_rx_param_req(struct hci_le_conn_param_req *evt);
int ble_gap_rx_l2cap_update_req(uint16_t conn_handle,
struct ble_gap_upd_params *params);
-void ble_gap_enc_changed(uint16_t conn_handle, int status,
+void ble_gap_enc_event(uint16_t conn_handle, int status,
struct ble_gap_sec_state *sec_state);
void ble_gap_passkey_event(uint16_t conn_handle, uint8_t passkey_action);
void ble_gap_notify_event(uint16_t conn_handle, uint16_t attr_handle,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac11583f/net/nimble/host/src/ble_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm.c b/net/nimble/host/src/ble_sm.c
index 8b4fa3e..21a42e2 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -46,6 +46,7 @@
#include "console/console.h"
#include "nimble/ble.h"
#include "nimble/nimble_opt.h"
+#include "host/ble_sm.h"
#include "ble_hs_priv.h"
#if NIMBLE_OPT(SM)
@@ -520,10 +521,10 @@ ble_sm_fill_store_value(uint8_t peer_addr_type, uint8_t *peer_addr,
}
static void
-ble_sm_key_exchange_events(uint16_t conn_handle,
- struct ble_sm_keys *our_keys,
- struct ble_sm_keys *peer_keys,
- int authenticated)
+ble_sm_persist_keys(uint16_t conn_handle,
+ struct ble_sm_keys *our_keys,
+ struct ble_sm_keys *peer_keys,
+ int authenticated)
{
struct ble_store_value_sec value_sec;
struct ble_hs_conn *conn;
@@ -550,12 +551,12 @@ ble_sm_key_exchange_events(uint16_t conn_handle,
}
static void
-ble_sm_gap_event(struct ble_sm_proc *proc, int status, int enc_enabled)
+ble_sm_enc_event(struct ble_sm_proc *proc, int status, int enc_enabled)
{
struct ble_gap_sec_state sec_state;
ble_sm_sec_state(proc, &sec_state, enc_enabled);
- ble_gap_enc_changed(proc->conn_handle, status, &sec_state);
+ ble_gap_enc_event(proc->conn_handle, status, &sec_state);
}
static int
@@ -729,7 +730,7 @@ ble_sm_process_result(uint16_t conn_handle, struct ble_sm_result *res)
&prev);
if (proc != NULL) {
- if (res->do_state) {
+ if (res->execute) {
ble_sm_go(proc, res, res->state_arg);
}
@@ -760,18 +761,17 @@ ble_sm_process_result(uint16_t conn_handle, struct ble_sm_result *res)
if (res->enc_cb) {
BLE_HS_DBG_ASSERT(rm);
- ble_sm_gap_event(proc, res->app_status, res->app_status == 0);
+ ble_sm_enc_event(proc, res->app_status, res->app_status == 0);
}
- if (res->passkey_action != BLE_GAP_PKACT_NONE) {
+ if (res->passkey_action != BLE_SM_PKACT_NONE) {
ble_gap_passkey_event(conn_handle, res->passkey_action);
}
if (res->persist_keys) {
BLE_HS_DBG_ASSERT(rm);
- ble_sm_key_exchange_events(
- conn_handle, &proc->our_keys, &proc->peer_keys,
- proc->flags & BLE_SM_PROC_F_AUTHENTICATED);
+ ble_sm_persist_keys(conn_handle, &proc->our_keys, &proc->peer_keys,
+ proc->flags & BLE_SM_PROC_F_AUTHENTICATED);
}
if (rm) {
@@ -779,12 +779,12 @@ ble_sm_process_result(uint16_t conn_handle, struct ble_sm_result *res)
break;
}
- if (!res->do_state) {
+ if (!res->execute) {
break;
}
memset(res, 0, sizeof *res);
- res->do_state = 1;
+ res->execute = 1;
}
}
@@ -1125,10 +1125,10 @@ ble_sm_check_key_exchange(struct ble_sm_proc *proc)
proc->rx_key_flags = 0;
if (rx_key_dist & BLE_SM_PAIR_KEY_DIST_ENC) {
proc->rx_key_flags |= BLE_SM_KE_F_ENC_INFO |
- BLE_SM_KE_F_MASTER_IDEN;
+ BLE_SM_KE_F_MASTER_ID;
}
if (rx_key_dist & BLE_SM_PAIR_KEY_DIST_ID) {
- proc->rx_key_flags |= BLE_SM_KE_F_IDEN_INFO |
+ proc->rx_key_flags |= BLE_SM_KE_F_ID_INFO |
BLE_SM_KE_F_ADDR_INFO;
}
if (rx_key_dist & BLE_SM_PAIR_KEY_DIST_SIGN) {
@@ -1140,10 +1140,10 @@ static void
ble_sm_key_exch_go(struct ble_sm_proc *proc,
struct ble_sm_result *res, void *arg)
{
- struct ble_sm_iden_addr_info addr_info;
- struct ble_sm_signing_info sign_info;
- struct ble_sm_master_iden master_iden;
- struct ble_sm_iden_info iden_info;
+ struct ble_sm_id_addr_info addr_info;
+ struct ble_sm_sign_info sign_info;
+ struct ble_sm_master_id master_iden;
+ struct ble_sm_id_info iden_info;
struct ble_sm_enc_info enc_info;
uint8_t our_key_dist;
int rc;
@@ -1160,7 +1160,7 @@ ble_sm_key_exch_go(struct ble_sm_proc *proc,
if (our_key_dist & BLE_SM_PAIR_KEY_DIST_ENC) {
/* Send encryption information. */
- rc = ble_sm_gen_ltk(proc, enc_info.ltk_le);
+ rc = ble_sm_gen_ltk(proc, enc_info.ltk);
if (rc != 0) {
goto err;
}
@@ -1169,7 +1169,7 @@ ble_sm_key_exch_go(struct ble_sm_proc *proc,
goto err;
}
proc->our_keys.ltk_valid = 1;
- memcpy(proc->our_keys.ltk, enc_info.ltk_le, 16);
+ memcpy(proc->our_keys.ltk, enc_info.ltk, 16);
/* Send master identification. */
rc = ble_sm_gen_ediv(&master_iden.ediv);
@@ -1180,7 +1180,7 @@ ble_sm_key_exch_go(struct ble_sm_proc *proc,
if (rc != 0) {
goto err;
}
- rc = ble_sm_master_iden_tx(proc->conn_handle, &master_iden);
+ rc = ble_sm_master_id_tx(proc->conn_handle, &master_iden);
if (rc != 0) {
goto err;
}
@@ -1191,45 +1191,45 @@ ble_sm_key_exch_go(struct ble_sm_proc *proc,
if (our_key_dist & BLE_SM_PAIR_KEY_DIST_ID) {
/* Send identity information. */
- rc = ble_sm_gen_irk(proc, iden_info.irk_le);
+ rc = ble_sm_gen_irk(proc, iden_info.irk);
if (rc != 0) {
goto err;
}
- rc = ble_sm_iden_info_tx(proc->conn_handle, &iden_info);
+ rc = ble_sm_id_info_tx(proc->conn_handle, &iden_info);
if (rc != 0) {
goto err;
}
proc->our_keys.irk_valid = 1;
- memcpy(proc->our_keys.irk, iden_info.irk_le, 16);
+ memcpy(proc->our_keys.irk, iden_info.irk, 16);
/* Send identity address information. */
if (ble_hs_our_dev.has_random_addr) {
addr_info.addr_type = BLE_ADDR_TYPE_RANDOM;
- memcpy(addr_info.bd_addr_le, ble_hs_our_dev.random_addr, 6);
+ memcpy(addr_info.bd_addr, ble_hs_our_dev.random_addr, 6);
} else {
addr_info.addr_type = BLE_ADDR_TYPE_PUBLIC;
- memcpy(addr_info.bd_addr_le, ble_hs_our_dev.public_addr, 6);
+ memcpy(addr_info.bd_addr, ble_hs_our_dev.public_addr, 6);
}
rc = ble_sm_iden_addr_tx(proc->conn_handle, &addr_info);
if (rc != 0) {
goto err;
}
proc->our_keys.addr_type = addr_info.addr_type;
- memcpy(proc->our_keys.addr, addr_info.bd_addr_le, 6);
+ memcpy(proc->our_keys.addr, addr_info.bd_addr, 6);
}
if (our_key_dist & BLE_SM_PAIR_KEY_DIST_SIGN) {
/* Send signing information. */
- rc = ble_sm_gen_csrk(proc, sign_info.sig_key_le);
+ rc = ble_sm_gen_csrk(proc, sign_info.sig_key);
if (rc != 0) {
goto err;
}
- rc = ble_sm_signing_info_tx(proc->conn_handle, &sign_info);
+ rc = ble_sm_sign_info_tx(proc->conn_handle, &sign_info);
if (rc != 0) {
goto err;
}
proc->our_keys.csrk_valid = 1;
- memcpy(proc->our_keys.csrk, sign_info.sig_key_le, 16);
+ memcpy(proc->our_keys.csrk, sign_info.sig_key, 16);
}
if (proc->flags & BLE_SM_PROC_F_INITIATOR) {
@@ -1259,7 +1259,7 @@ ble_sm_key_rxed(struct ble_sm_proc *proc, struct ble_sm_result *res)
* send ours. If we are the responder, the procedure is complete.
*/
if (proc->flags & BLE_SM_PROC_F_INITIATOR) {
- res->do_state = 1;
+ res->execute = 1;
} else {
proc->flags |= BLE_SM_PROC_F_BONDED;
proc->state = BLE_SM_PROC_STATE_NONE;
@@ -1296,7 +1296,7 @@ ble_sm_rx_enc_info(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
} else {
proc->rx_key_flags &= ~BLE_SM_KE_F_ENC_INFO;
proc->peer_keys.ltk_valid = 1;
- memcpy(proc->peer_keys.ltk, cmd.ltk_le, 16);
+ memcpy(proc->peer_keys.ltk, cmd.ltk, 16);
ble_sm_key_rxed(proc, res);
}
@@ -1308,18 +1308,18 @@ static void
ble_sm_rx_master_id(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
struct ble_sm_result *res)
{
- struct ble_sm_master_iden cmd;
+ struct ble_sm_master_id cmd;
struct ble_sm_proc *proc;
struct ble_sm_proc *prev;
- res->app_status = ble_hs_misc_pullup_base(om, BLE_SM_MASTER_IDEN_SZ);
+ res->app_status = ble_hs_misc_pullup_base(om, BLE_SM_MASTER_ID_SZ);
if (res->app_status != 0) {
res->sm_err = BLE_SM_ERR_UNSPECIFIED;
res->enc_cb = 1;
return;
}
- ble_sm_master_iden_parse((*om)->om_data, (*om)->om_len, &cmd);
+ ble_sm_master_id_parse((*om)->om_data, (*om)->om_len, &cmd);
ble_hs_lock();
@@ -1329,7 +1329,7 @@ ble_sm_rx_master_id(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
res->app_status = BLE_HS_ENOENT;
res->sm_err = BLE_SM_ERR_UNSPECIFIED;
} else {
- proc->rx_key_flags &= ~BLE_SM_KE_F_MASTER_IDEN;
+ proc->rx_key_flags &= ~BLE_SM_KE_F_MASTER_ID;
proc->peer_keys.ediv_rand_valid = 1;
proc->peer_keys.ediv = cmd.ediv;
proc->peer_keys.rand_val = cmd.rand_val;
@@ -1344,18 +1344,18 @@ static void
ble_sm_rx_id_info(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
struct ble_sm_result *res)
{
- struct ble_sm_iden_info cmd;
+ struct ble_sm_id_info cmd;
struct ble_sm_proc *proc;
struct ble_sm_proc *prev;
- res->app_status = ble_hs_misc_pullup_base(om, BLE_SM_IDEN_INFO_SZ);
+ res->app_status = ble_hs_misc_pullup_base(om, BLE_SM_ID_INFO_SZ);
if (res->app_status != 0) {
res->sm_err = BLE_SM_ERR_UNSPECIFIED;
res->enc_cb = 1;
return;
}
- ble_sm_iden_info_parse((*om)->om_data, (*om)->om_len, &cmd);
+ ble_sm_id_info_parse((*om)->om_data, (*om)->om_len, &cmd);
ble_hs_lock();
@@ -1365,9 +1365,9 @@ ble_sm_rx_id_info(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
res->app_status = BLE_HS_ENOENT;
res->sm_err = BLE_SM_ERR_UNSPECIFIED;
} else {
- proc->rx_key_flags &= ~BLE_SM_KE_F_IDEN_INFO;
+ proc->rx_key_flags &= ~BLE_SM_KE_F_ID_INFO;
proc->peer_keys.irk_valid = 1;
- memcpy(proc->peer_keys.irk, cmd.irk_le, 16);
+ memcpy(proc->peer_keys.irk, cmd.irk, 16);
ble_sm_key_rxed(proc, res);
}
@@ -1379,11 +1379,11 @@ static void
ble_sm_rx_id_addr_info(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
struct ble_sm_result *res)
{
- struct ble_sm_iden_addr_info cmd;
+ struct ble_sm_id_addr_info cmd;
struct ble_sm_proc *proc;
struct ble_sm_proc *prev;
- res->app_status = ble_hs_misc_pullup_base(om, BLE_SM_IDEN_ADDR_INFO_SZ);
+ res->app_status = ble_hs_misc_pullup_base(om, BLE_SM_ID_ADDR_INFO_SZ);
if (res->app_status != 0) {
res->sm_err = BLE_SM_ERR_UNSPECIFIED;
res->enc_cb = 1;
@@ -1403,7 +1403,7 @@ ble_sm_rx_id_addr_info(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
proc->rx_key_flags &= ~BLE_SM_KE_F_ADDR_INFO;
proc->peer_keys.addr_valid = 1;
proc->peer_keys.addr_type = cmd.addr_type;
- memcpy(proc->peer_keys.addr, cmd.bd_addr_le, 6);
+ memcpy(proc->peer_keys.addr, cmd.bd_addr, 6);
ble_sm_key_rxed(proc, res);
}
@@ -1415,18 +1415,18 @@ static void
ble_sm_rx_sign_info(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
struct ble_sm_result *res)
{
- struct ble_sm_signing_info cmd;
+ struct ble_sm_sign_info cmd;
struct ble_sm_proc *proc;
struct ble_sm_proc *prev;
- res->app_status = ble_hs_misc_pullup_base(om, BLE_SM_SIGNING_INFO_SZ);
+ res->app_status = ble_hs_misc_pullup_base(om, BLE_SM_SIGN_INFO_SZ);
if (res->app_status != 0) {
res->sm_err = BLE_SM_ERR_UNSPECIFIED;
res->enc_cb = 1;
return;
}
- ble_sm_signing_info_parse((*om)->om_data, (*om)->om_len, &cmd);
+ ble_sm_sign_info_parse((*om)->om_data, (*om)->om_len, &cmd);
ble_hs_lock();
@@ -1438,7 +1438,7 @@ ble_sm_rx_sign_info(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
} else {
proc->rx_key_flags &= ~BLE_SM_KE_F_SIGN_INFO;
proc->peer_keys.csrk_valid = 1;
- memcpy(proc->peer_keys.csrk, cmd.sig_key_le, 16);
+ memcpy(proc->peer_keys.csrk, cmd.sig_key, 16);
ble_sm_key_rxed(proc, res);
}
@@ -1505,7 +1505,7 @@ ble_sm_rx_pair_req(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
res->sm_err = BLE_SM_ERR_INVAL;
res->app_status = BLE_HS_SM_US_ERR(BLE_SM_ERR_INVAL);
} else {
- res->do_state = 1;
+ res->execute = 1;
}
}
@@ -1546,9 +1546,9 @@ ble_sm_rx_pair_rsp(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
ble_sm_check_key_exchange(proc);
res->passkey_action = ble_sm_passkey_action(proc);
- if (res->passkey_action == BLE_GAP_PKACT_NONE) {
+ if (res->passkey_action == BLE_SM_PKACT_NONE) {
proc->state = ble_sm_state_after_pair(proc);
- res->do_state = 1;
+ res->execute = 1;
}
}
}
@@ -1586,15 +1586,15 @@ ble_sm_rx_pair_confirm(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
if (proc->flags & BLE_SM_PROC_F_INITIATOR) {
proc->state = BLE_SM_PROC_STATE_RANDOM;
- res->do_state = 1;
+ res->execute = 1;
} else {
proc->flags |= BLE_SM_PROC_F_RX_CONFIRM;
passkey_action = ble_sm_passkey_action(proc);
- if (passkey_action == BLE_GAP_PKACT_NONE ||
+ if (passkey_action == BLE_SM_PKACT_NONE ||
proc->flags & BLE_SM_PROC_F_TK_VALID) {
- res->do_state = 1;
+ res->execute = 1;
}
}
}
@@ -1629,9 +1629,9 @@ ble_sm_rx_pair_random(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
memcpy(ble_sm_their_pair_rand(proc), cmd.value, 16);
if (proc->flags & BLE_SM_PROC_F_SC) {
- ble_sm_sc_random_handle(proc, res);
+ ble_sm_sc_rx_pair_random(proc, res);
} else {
- ble_sm_lgcy_random_handle(proc, res);
+ ble_sm_lgcy_rx_pair_random(proc, res);
}
}
ble_hs_unlock();
@@ -1740,7 +1740,7 @@ ble_sm_rx_lt_key_req(struct hci_le_lt_key_req *evt)
proc = ble_sm_proc_find(evt->connection_handle,
BLE_SM_PROC_STATE_NONE, 0, NULL);
if (proc != NULL) {
- res.do_state = 1;
+ res.execute = 1;
}
ble_hs_unlock();
@@ -1786,7 +1786,7 @@ ble_sm_rx_encryption_change(struct hci_encrypt_change *evt)
/* The responder sends its keys first. */
if (!(proc->flags & BLE_SM_PROC_F_INITIATOR)) {
- res.do_state = 1;
+ res.execute = 1;
}
} else {
proc->state = BLE_SM_PROC_STATE_NONE;
@@ -1925,7 +1925,7 @@ ble_sm_heartbeat(void)
* object.
*/
while ((proc = STAILQ_FIRST(&exp_list)) != NULL) {
- ble_sm_gap_event(proc, BLE_HS_ETIMEOUT, 0);
+ ble_sm_enc_event(proc, BLE_HS_ETIMEOUT, 0);
STAILQ_REMOVE_HEAD(&exp_list, next);
ble_sm_proc_free(proc);
@@ -1960,7 +1960,7 @@ ble_sm_pair_initiate(uint16_t conn_handle)
proc->flags |= BLE_SM_PROC_F_INITIATOR;
ble_sm_insert(proc);
- res.do_state = 1;
+ res.execute = 1;
}
}
@@ -1998,7 +1998,7 @@ ble_sm_slave_initiate(uint16_t conn_handle)
proc->state = BLE_SM_PROC_STATE_SEC_REQ;
ble_sm_insert(proc);
- res.do_state = 1;
+ res.execute = 1;
}
}
@@ -2051,7 +2051,7 @@ ble_sm_enc_initiate(uint16_t conn_handle, uint8_t *ltk, uint16_t ediv,
cmd.random_number = rand_val;
memcpy(cmd.long_term_key, ltk, sizeof cmd.long_term_key);
- res.do_state = 1;
+ res.execute = 1;
res.state_arg = &cmd;
}
}
@@ -2105,7 +2105,7 @@ ble_sm_set_tk(uint16_t conn_handle, struct ble_sm_passkey *pkey)
} else {
/* Add the passkey range. */
switch (pkey->action) {
- case BLE_GAP_PKACT_OOB:
+ case BLE_SM_PKACT_OOB:
if (pkey->oob == NULL) {
res.app_status = BLE_HS_SM_US_ERR(BLE_HS_EINVAL);
res.sm_err = BLE_SM_ERR_OOB;
@@ -2114,8 +2114,8 @@ ble_sm_set_tk(uint16_t conn_handle, struct ble_sm_passkey *pkey)
}
break;
- case BLE_GAP_PKACT_INPUT:
- case BLE_GAP_PKACT_DISP:
+ case BLE_SM_PKACT_INPUT:
+ case BLE_SM_PKACT_DISP:
if (pkey->passkey > 999999) {
res.app_status = BLE_HS_EINVAL;
res.sm_err = BLE_SM_ERR_PASSKEY;
@@ -2143,7 +2143,7 @@ ble_sm_set_tk(uint16_t conn_handle, struct ble_sm_passkey *pkey)
if (proc->flags &
(BLE_SM_PROC_F_INITIATOR | BLE_SM_PROC_F_RX_CONFIRM)) {
- res.do_state = 1;
+ res.execute = 1;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac11583f/net/nimble/host/src/ble_sm_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_cmd.c b/net/nimble/host/src/ble_sm_cmd.c
index 8100e24..790ca4c 100644
--- a/net/nimble/host/src/ble_sm_cmd.c
+++ b/net/nimble/host/src/ble_sm_cmd.c
@@ -22,6 +22,7 @@
#include "console/console.h"
#include "nimble/ble.h"
#include "nimble/nimble_opt.h"
+#include "host/ble_sm.h"
#include "ble_hs_priv.h"
#if NIMBLE_OPT(SM)
@@ -189,8 +190,7 @@ ble_sm_pair_confirm_write(void *payload, int len,
}
int
-ble_sm_pair_confirm_tx(uint16_t conn_handle,
- struct ble_sm_pair_confirm *cmd)
+ble_sm_pair_confirm_tx(uint16_t conn_handle, struct ble_sm_pair_confirm *cmd)
{
struct os_mbuf *txom;
int rc;
@@ -238,8 +238,7 @@ ble_sm_pair_random_write(void *payload, int len,
}
int
-ble_sm_pair_random_tx(uint16_t conn_handle,
- struct ble_sm_pair_random *cmd)
+ble_sm_pair_random_tx(uint16_t conn_handle, struct ble_sm_pair_random *cmd)
{
struct os_mbuf *txom;
int rc;
@@ -261,8 +260,7 @@ done:
}
void
-ble_sm_pair_fail_parse(void *payload, int len,
- struct ble_sm_pair_fail *cmd)
+ble_sm_pair_fail_parse(void *payload, int len, struct ble_sm_pair_fail *cmd)
{
uint8_t *u8ptr;
@@ -316,12 +314,11 @@ void
ble_sm_enc_info_parse(void *payload, int len, struct ble_sm_enc_info *cmd)
{
uint8_t *u8ptr = payload;
- memcpy(cmd->ltk_le, u8ptr, 16);
+ memcpy(cmd->ltk, u8ptr, 16);
}
int
-ble_sm_enc_info_tx(uint16_t conn_handle,
- struct ble_sm_enc_info *cmd)
+ble_sm_enc_info_tx(uint16_t conn_handle, struct ble_sm_enc_info *cmd)
{
struct os_mbuf *txom;
int rc;
@@ -333,7 +330,7 @@ ble_sm_enc_info_tx(uint16_t conn_handle,
}
txom->om_data[0] = BLE_SM_OP_ENC_INFO;
- memcpy(txom->om_data + 1, cmd->ltk_le, sizeof cmd->ltk_le);
+ memcpy(txom->om_data + 1, cmd->ltk, sizeof cmd->ltk);
rc = ble_sm_tx(conn_handle, txom);
txom = NULL;
@@ -344,8 +341,7 @@ done:
}
void
-ble_sm_master_iden_parse(void *payload, int len,
- struct ble_sm_master_iden *cmd)
+ble_sm_master_id_parse(void *payload, int len, struct ble_sm_master_id *cmd)
{
uint8_t *u8ptr = payload;
cmd->ediv = le16toh(u8ptr);
@@ -353,12 +349,12 @@ ble_sm_master_iden_parse(void *payload, int len,
}
int
-ble_sm_master_iden_tx(uint16_t conn_handle, struct ble_sm_master_iden *cmd)
+ble_sm_master_id_tx(uint16_t conn_handle, struct ble_sm_master_id *cmd)
{
struct os_mbuf *txom;
int rc;
- rc = ble_sm_init_req(BLE_SM_MASTER_IDEN_SZ, &txom);
+ rc = ble_sm_init_req(BLE_SM_MASTER_ID_SZ, &txom);
if (rc != 0) {
rc = BLE_HS_ENOMEM;
goto done;
@@ -376,26 +372,26 @@ done:
}
void
-ble_sm_iden_info_parse(void *payload, int len, struct ble_sm_iden_info *cmd)
+ble_sm_id_info_parse(void *payload, int len, struct ble_sm_id_info *cmd)
{
uint8_t *u8ptr = payload;
- memcpy(cmd->irk_le, u8ptr, 16);
+ memcpy(cmd->irk, u8ptr, 16);
}
int
-ble_sm_iden_info_tx(uint16_t conn_handle, struct ble_sm_iden_info *cmd)
+ble_sm_id_info_tx(uint16_t conn_handle, struct ble_sm_id_info *cmd)
{
struct os_mbuf *txom;
int rc;
- rc = ble_sm_init_req(BLE_SM_IDEN_INFO_SZ, &txom);
+ rc = ble_sm_init_req(BLE_SM_ID_INFO_SZ, &txom);
if (rc != 0) {
rc = BLE_HS_ENOMEM;
goto done;
}
txom->om_data[0] = BLE_SM_OP_IDENTITY_INFO;
- memcpy(txom->om_data + 1, cmd->irk_le, sizeof cmd->irk_le);
+ memcpy(txom->om_data + 1, cmd->irk, sizeof cmd->irk);
rc = ble_sm_tx(conn_handle, txom);
txom = NULL;
@@ -406,20 +402,20 @@ done:
void
ble_sm_iden_addr_parse(void *payload, int len,
- struct ble_sm_iden_addr_info *cmd)
+ struct ble_sm_id_addr_info *cmd)
{
uint8_t *u8ptr = payload;
cmd->addr_type = *u8ptr;
- memcpy(cmd->bd_addr_le, u8ptr + 1, 6);
+ memcpy(cmd->bd_addr, u8ptr + 1, 6);
}
int
-ble_sm_iden_addr_tx(uint16_t conn_handle, struct ble_sm_iden_addr_info *cmd)
+ble_sm_iden_addr_tx(uint16_t conn_handle, struct ble_sm_id_addr_info *cmd)
{
struct os_mbuf *txom;
int rc;
- rc = ble_sm_init_req(BLE_SM_IDEN_ADDR_INFO_SZ, &txom);
+ rc = ble_sm_init_req(BLE_SM_ID_ADDR_INFO_SZ, &txom);
if (rc != 0) {
rc = BLE_HS_ENOMEM;
goto done;
@@ -427,7 +423,7 @@ ble_sm_iden_addr_tx(uint16_t conn_handle, struct ble_sm_iden_addr_info *cmd)
txom->om_data[0] = BLE_SM_OP_IDENTITY_ADDR_INFO;
txom->om_data[1] = cmd->addr_type;
- memcpy(txom->om_data + 2, cmd->bd_addr_le, sizeof cmd->bd_addr_le);
+ memcpy(txom->om_data + 2, cmd->bd_addr, sizeof cmd->bd_addr);
rc = ble_sm_tx(conn_handle, txom);
txom = NULL;
@@ -437,27 +433,26 @@ done:
}
void
-ble_sm_signing_info_parse(void *payload, int len,
- struct ble_sm_signing_info *cmd)
+ble_sm_sign_info_parse(void *payload, int len, struct ble_sm_sign_info *cmd)
{
uint8_t *u8ptr = payload;
- memcpy(cmd->sig_key_le, u8ptr, 16);
+ memcpy(cmd->sig_key, u8ptr, 16);
}
int
-ble_sm_signing_info_tx(uint16_t conn_handle, struct ble_sm_signing_info *cmd)
+ble_sm_sign_info_tx(uint16_t conn_handle, struct ble_sm_sign_info *cmd)
{
struct os_mbuf *txom;
int rc;
- rc = ble_sm_init_req(BLE_SM_SIGNING_INFO_SZ, &txom);
+ rc = ble_sm_init_req(BLE_SM_SIGN_INFO_SZ, &txom);
if (rc != 0) {
rc = BLE_HS_ENOMEM;
goto done;
}
txom->om_data[0] = BLE_SM_OP_SIGN_INFO;
- memcpy(txom->om_data + 1, cmd->sig_key_le, sizeof cmd->sig_key_le);
+ memcpy(txom->om_data + 1, cmd->sig_key, sizeof cmd->sig_key);
rc = ble_sm_tx(conn_handle, txom);
txom = NULL;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac11583f/net/nimble/host/src/ble_sm_lgcy.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_lgcy.c b/net/nimble/host/src/ble_sm_lgcy.c
index 9748d3b..275d942 100644
--- a/net/nimble/host/src/ble_sm_lgcy.c
+++ b/net/nimble/host/src/ble_sm_lgcy.c
@@ -22,16 +22,17 @@
#include "console/console.h"
#include "nimble/ble.h"
#include "nimble/nimble_opt.h"
+#include "host/ble_sm.h"
#include "ble_hs_priv.h"
/**
* Create some shortened names for the passkey actions so that the table is
* easier to read.
*/
-#define PKACT_NONE BLE_GAP_PKACT_NONE
-#define PKACT_OOB BLE_GAP_PKACT_OOB
-#define PKACT_INPUT BLE_GAP_PKACT_INPUT
-#define PKACT_DISP BLE_GAP_PKACT_DISP
+#define PKACT_NONE BLE_SM_PKACT_NONE
+#define PKACT_OOB BLE_SM_PKACT_OOB
+#define PKACT_INPUT BLE_SM_PKACT_INPUT
+#define PKACT_DISP BLE_SM_PKACT_DISP
/* This is the initiator passkey action action dpeneding on the io
* capabilties of both parties
@@ -62,11 +63,11 @@ ble_sm_lgcy_passkey_action(struct ble_sm_proc *proc)
int action;
if (proc->pair_req.oob_data_flag && proc->pair_rsp.oob_data_flag) {
- action = BLE_GAP_PKACT_OOB;
+ action = BLE_SM_PKACT_OOB;
} else if (!(proc->pair_req.authreq & BLE_SM_PAIR_AUTHREQ_MITM) ||
!(proc->pair_rsp.authreq & BLE_SM_PAIR_AUTHREQ_MITM)) {
- action = BLE_GAP_PKACT_NONE;
+ action = BLE_SM_PKACT_NONE;
} else if (proc->flags & BLE_SM_PROC_F_INITIATOR) {
action = ble_sm_lgcy_init_pka[proc->pair_req.io_cap]
[proc->pair_rsp.io_cap];
@@ -76,17 +77,17 @@ ble_sm_lgcy_passkey_action(struct ble_sm_proc *proc)
}
switch (action) {
- case BLE_GAP_PKACT_NONE:
+ case BLE_SM_PKACT_NONE:
proc->pair_alg = BLE_SM_PAIR_ALG_JW;
break;
- case BLE_GAP_PKACT_OOB:
+ case BLE_SM_PKACT_OOB:
proc->pair_alg = BLE_SM_PAIR_ALG_OOB;
proc->flags |= BLE_SM_PROC_F_AUTHENTICATED;
break;
- case BLE_GAP_PKACT_INPUT:
- case BLE_GAP_PKACT_DISP:
+ case BLE_SM_PKACT_INPUT:
+ case BLE_SM_PKACT_DISP:
proc->pair_alg = BLE_SM_PAIR_ALG_PASSKEY;
proc->flags |= BLE_SM_PROC_F_AUTHENTICATED;
break;
@@ -224,7 +225,7 @@ ble_sm_lgcy_random_go(struct ble_sm_proc *proc,
}
void
-ble_sm_lgcy_random_handle(struct ble_sm_proc *proc, struct ble_sm_result *res)
+ble_sm_lgcy_rx_pair_random(struct ble_sm_proc *proc, struct ble_sm_result *res)
{
uint8_t preq[BLE_SM_HDR_SZ + BLE_SM_PAIR_CMD_SZ];
uint8_t pres[BLE_SM_HDR_SZ + BLE_SM_PAIR_CMD_SZ];
@@ -279,5 +280,5 @@ ble_sm_lgcy_random_handle(struct ble_sm_proc *proc, struct ble_sm_result *res)
proc->state = BLE_SM_PROC_STATE_ENC_START;
}
- res->do_state = 1;
+ res->execute = 1;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac11583f/net/nimble/host/src/ble_sm_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_priv.h b/net/nimble/host/src/ble_sm_priv.h
index 25130df..8e155cb 100644
--- a/net/nimble/host/src/ble_sm_priv.h
+++ b/net/nimble/host/src/ble_sm_priv.h
@@ -17,8 +17,8 @@
* under the License.
*/
-#ifndef H_BLE_SM_
-#define H_BLE_SM_
+#ifndef H_BLE_SM_PRIV_
+#define H_BLE_SM_PRIV_
#include <inttypes.h>
#include "os/queue.h"
@@ -28,9 +28,24 @@ struct ble_gap_sec_state;
struct hci_le_lt_key_req;
struct hci_encrypt_change;
-#define BLE_SM_MTU 65
-
-#define BLE_SM_HDR_SZ 1
+#define BLE_SM_MTU 65
+
+#define BLE_SM_HDR_SZ 1
+
+#define BLE_SM_OP_PAIR_REQ 0x01
+#define BLE_SM_OP_PAIR_RSP 0x02
+#define BLE_SM_OP_PAIR_CONFIRM 0x03
+#define BLE_SM_OP_PAIR_RANDOM 0x04
+#define BLE_SM_OP_PAIR_FAIL 0x05
+#define BLE_SM_OP_ENC_INFO 0x06
+#define BLE_SM_OP_MASTER_ID 0x07
+#define BLE_SM_OP_IDENTITY_INFO 0x08
+#define BLE_SM_OP_IDENTITY_ADDR_INFO 0x09
+#define BLE_SM_OP_SIGN_INFO 0x0a
+#define BLE_SM_OP_SEC_REQ 0x0b
+#define BLE_SM_OP_PAIR_PUBLIC_KEY 0x0c
+#define BLE_SM_OP_PAIR_DHKEY_CHECK 0x0d
+#define BLE_SM_OP_PAIR_KEYPRESS_NOTIFY 0x0e
/**
* | Parameter | Size (octets) |
@@ -43,7 +58,7 @@ struct hci_encrypt_change;
* | Initiator Key Distribution | 1 |
* | Responder Key Distribution | 1 |
*/
-#define BLE_SM_PAIR_CMD_SZ 6
+#define BLE_SM_PAIR_CMD_SZ 6
struct ble_sm_pair_cmd {
uint8_t io_cap;
uint8_t oob_data_flag;
@@ -59,7 +74,7 @@ struct ble_sm_pair_cmd {
* | (Code=0x03) | 1 |
* | Confirm Value | 16 |
*/
-#define BLE_SM_PAIR_CONFIRM_SZ 16
+#define BLE_SM_PAIR_CONFIRM_SZ 16
struct ble_sm_pair_confirm {
uint8_t value[16];
};
@@ -70,7 +85,7 @@ struct ble_sm_pair_confirm {
* | (Code=0x04) | 1 |
* | Random Value | 16 |
*/
-#define BLE_SM_PAIR_RANDOM_SZ 16
+#define BLE_SM_PAIR_RANDOM_SZ 16
struct ble_sm_pair_random {
uint8_t value[16];
};
@@ -81,7 +96,7 @@ struct ble_sm_pair_random {
* | (Code=0x05) | 1 |
* | Reason | 1 |
*/
-#define BLE_SM_PAIR_FAIL_SZ 1
+#define BLE_SM_PAIR_FAIL_SZ 1
struct ble_sm_pair_fail {
uint8_t reason;
};
@@ -92,9 +107,9 @@ struct ble_sm_pair_fail {
* | (Code=0x06) | 1 |
* | ltk | 16 |
*/
-#define BLE_SM_ENC_INFO_SZ 16
+#define BLE_SM_ENC_INFO_SZ 16
struct ble_sm_enc_info {
- uint8_t ltk_le[16];
+ uint8_t ltk[16];
};
/**
@@ -104,8 +119,8 @@ struct ble_sm_enc_info {
* | EDIV | 2 |
* | RAND | 8 |
*/
-#define BLE_SM_MASTER_IDEN_SZ 10
-struct ble_sm_master_iden {
+#define BLE_SM_MASTER_ID_SZ 10
+struct ble_sm_master_id {
uint16_t ediv;
uint64_t rand_val;
};
@@ -116,10 +131,10 @@ struct ble_sm_master_iden {
* | (Code=0x08) | 1 |
* | irk | 16 |
*/
-#define BLE_SM_IDEN_INFO_SZ 16
-struct ble_sm_iden_info {
+#define BLE_SM_ID_INFO_SZ 16
+struct ble_sm_id_info {
/* Stored in little-endian. */
- uint8_t irk_le[16];
+ uint8_t irk[16];
};
/**
@@ -129,10 +144,10 @@ struct ble_sm_iden_info {
* | addr_type | 1 |
* | address | 6 |
*/
-#define BLE_SM_IDEN_ADDR_INFO_SZ 7
-struct ble_sm_iden_addr_info {
+#define BLE_SM_ID_ADDR_INFO_SZ 7
+struct ble_sm_id_addr_info {
uint8_t addr_type;
- uint8_t bd_addr_le[6];
+ uint8_t bd_addr[6];
};
/**
@@ -141,9 +156,9 @@ struct ble_sm_iden_addr_info {
* | (Code=0x0A) | 1 |
* | csrk | 16 |
*/
-#define BLE_SM_SIGNING_INFO_SZ 16
-struct ble_sm_signing_info {
- uint8_t sig_key_le[16];
+#define BLE_SM_SIGN_INFO_SZ 16
+struct ble_sm_sign_info {
+ uint8_t sig_key[16];
};
/**
@@ -152,7 +167,7 @@ struct ble_sm_signing_info {
* | (Code=0x0B) | 1 |
* | authreq | 1 |
*/
-#define BLE_SM_SEC_REQ_SZ 1
+#define BLE_SM_SEC_REQ_SZ 1
struct ble_sm_sec_req {
uint8_t authreq;
};
@@ -164,7 +179,7 @@ struct ble_sm_sec_req {
* | Public Key X | 32 |
* | Public Key Y | 32 |
*/
-#define BLE_SM_PUBLIC_KEY_SZ 64
+#define BLE_SM_PUBLIC_KEY_SZ 64
struct ble_sm_public_key {
uint8_t x[32];
uint8_t y[32];
@@ -176,7 +191,7 @@ struct ble_sm_public_key {
* | (Code=0x0d) | 1 |
* | DHKey Check | 16 |
*/
-#define BLE_SM_DHKEY_CHECK_SZ 16
+#define BLE_SM_DHKEY_CHECK_SZ 16
struct ble_sm_dhkey_check {
uint8_t value[16];
};
@@ -207,8 +222,8 @@ struct ble_sm_dhkey_check {
#define BLE_SM_PROC_F_SC 0x40
#define BLE_SM_KE_F_ENC_INFO 0x01
-#define BLE_SM_KE_F_MASTER_IDEN 0x02
-#define BLE_SM_KE_F_IDEN_INFO 0x04
+#define BLE_SM_KE_F_MASTER_ID 0x02
+#define BLE_SM_KE_F_ID_INFO 0x04
#define BLE_SM_KE_F_ADDR_INFO 0x08
#define BLE_SM_KE_F_SIGN_INFO 0x10
@@ -264,7 +279,7 @@ struct ble_sm_result {
uint8_t sm_err;
uint8_t passkey_action;
void *state_arg;
- unsigned do_state:1;
+ unsigned execute:1;
unsigned enc_cb:1;
unsigned persist_keys:1;
};
@@ -328,36 +343,26 @@ int ble_sm_alg_gen_key_pair(uint8_t *pub, uint8_t *priv);
void ble_sm_enc_info_parse(void *payload, int len,
struct ble_sm_enc_info *cmd);
-int ble_sm_enc_info_tx(uint16_t conn_handle,
- struct ble_sm_enc_info *cmd);
-void ble_sm_master_iden_parse(void *payload, int len,
- struct ble_sm_master_iden *cmd);
-int ble_sm_master_iden_tx(uint16_t conn_handle,
- struct ble_sm_master_iden *cmd);
-void ble_sm_iden_info_parse(void *payload, int len,
- struct ble_sm_iden_info *cmd);
-int ble_sm_iden_info_tx(uint16_t conn_handle,
- struct ble_sm_iden_info *cmd);
+int ble_sm_enc_info_tx(uint16_t conn_handle, struct ble_sm_enc_info *cmd);
+void ble_sm_master_id_parse(void *payload, int len,
+ struct ble_sm_master_id *cmd);
+int ble_sm_master_id_tx(uint16_t conn_handle, struct ble_sm_master_id *cmd);
+void ble_sm_id_info_parse(void *payload, int len, struct ble_sm_id_info *cmd);
+int ble_sm_id_info_tx(uint16_t conn_handle, struct ble_sm_id_info *cmd);
void ble_sm_iden_addr_parse(void *payload, int len,
- struct ble_sm_iden_addr_info *cmd);
-int ble_sm_iden_addr_tx(uint16_t conn_handle,
- struct ble_sm_iden_addr_info *cmd);
-void ble_sm_signing_info_parse(void *payload, int len,
- struct ble_sm_signing_info *cmd);
-int ble_sm_signing_info_tx(uint16_t conn_handle,
- struct ble_sm_signing_info *cmd);
-void ble_sm_sec_req_parse(void *payload, int len,
- struct ble_sm_sec_req *cmd);
-void ble_sm_sec_req_write(void *payload, int len,
- struct ble_sm_sec_req *cmd);
-int ble_sm_sec_req_tx(uint16_t conn_handle,
- struct ble_sm_sec_req *cmd);
+ struct ble_sm_id_addr_info *cmd);
+int ble_sm_iden_addr_tx(uint16_t conn_handle, struct ble_sm_id_addr_info *cmd);
+void ble_sm_sign_info_parse(void *payload, int len,
+ struct ble_sm_sign_info *cmd);
+int ble_sm_sign_info_tx(uint16_t conn_handle, struct ble_sm_sign_info *cmd);
+void ble_sm_sec_req_parse(void *payload, int len, struct ble_sm_sec_req *cmd);
+void ble_sm_sec_req_write(void *payload, int len, struct ble_sm_sec_req *cmd);
+int ble_sm_sec_req_tx(uint16_t conn_handle, struct ble_sm_sec_req *cmd);
int ble_sm_public_key_parse(void *payload, int len,
struct ble_sm_public_key *cmd);
int ble_sm_public_key_write(void *payload, int len,
struct ble_sm_public_key *cmd);
-int ble_sm_public_key_tx(uint16_t conn_handle,
- struct ble_sm_public_key *cmd);
+int ble_sm_public_key_tx(uint16_t conn_handle, struct ble_sm_public_key *cmd);
int ble_sm_dhkey_check_parse(void *payload, int len,
struct ble_sm_dhkey_check *cmd);
int ble_sm_dhkey_check_write(void *payload, int len,
@@ -374,16 +379,14 @@ void ble_sm_lgcy_confirm_go(struct ble_sm_proc *proc,
struct ble_sm_result *res);
void ble_sm_lgcy_random_go(struct ble_sm_proc *proc,
struct ble_sm_result *res);
-void ble_sm_lgcy_random_handle(struct ble_sm_proc *proc,
+void ble_sm_lgcy_rx_pair_random(struct ble_sm_proc *proc,
struct ble_sm_result *res);
int ble_sm_sc_next_state(struct ble_sm_proc *proc);
int ble_sm_sc_passkey_action(struct ble_sm_proc *proc);
-void ble_sm_sc_confirm_go(struct ble_sm_proc *proc,
- struct ble_sm_result *res);
-void ble_sm_sc_random_go(struct ble_sm_proc *proc,
- struct ble_sm_result *res);
-void ble_sm_sc_random_handle(struct ble_sm_proc *proc,
+void ble_sm_sc_confirm_go(struct ble_sm_proc *proc, struct ble_sm_result *res);
+void ble_sm_sc_random_go(struct ble_sm_proc *proc, struct ble_sm_result *res);
+void ble_sm_sc_rx_pair_random(struct ble_sm_proc *proc,
struct ble_sm_result *res);
void ble_sm_sc_public_key_go(struct ble_sm_proc *proc,
struct ble_sm_result *res,
@@ -394,22 +397,21 @@ void ble_sm_sc_public_key_handle(struct ble_sm_proc *proc,
void ble_sm_sc_rx_public_key(uint16_t conn_handle, uint8_t op,
struct os_mbuf **om, struct ble_sm_result *res);
void ble_sm_sc_dhkey_check_go(struct ble_sm_proc *proc,
- struct ble_sm_result *res, void *arg);
+ struct ble_sm_result *res, void *arg);
void ble_sm_sc_rx_dhkey_check(uint16_t conn_handle, uint8_t op,
struct os_mbuf **om, struct ble_sm_result *res);
struct ble_sm_proc *ble_sm_proc_find(uint16_t conn_handle, uint8_t state,
int is_initiator,
struct ble_sm_proc **out_prev);
-int ble_sm_gen_pub_priv(struct ble_sm_proc *proc,
- uint8_t *pub, uint8_t *priv);
+int ble_sm_gen_pub_priv(struct ble_sm_proc *proc, uint8_t *pub, uint8_t *priv);
uint8_t *ble_sm_our_pair_rand(struct ble_sm_proc *proc);
uint8_t *ble_sm_their_pair_rand(struct ble_sm_proc *proc);
void ble_sm_go(struct ble_sm_proc *proc, struct ble_sm_result *res, void *arg);
void ble_sm_process_result(uint16_t conn_handle, struct ble_sm_result *res);
-
void ble_sm_heartbeat(void);
+void ble_sm_connection_broken(uint16_t conn_handle);
int ble_sm_pair_initiate(uint16_t conn_handle);
int ble_sm_slave_initiate(uint16_t conn_handle);
int ble_sm_enc_initiate(uint16_t conn_handle, uint8_t *ltk,
@@ -438,6 +440,7 @@ int ble_sm_init(void);
#define ble_sm_rx_lt_key_req(evt) ((void)(evt))
#define ble_sm_heartbeat()
+#define ble_sm_connection_broken(conn_handle)
#define ble_sm_init() 0
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac11583f/net/nimble/host/src/ble_sm_sc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_sc.c b/net/nimble/host/src/ble_sm_sc.c
index ca12025..658f62f 100644
--- a/net/nimble/host/src/ble_sm_sc.c
+++ b/net/nimble/host/src/ble_sm_sc.c
@@ -19,6 +19,7 @@
#include <string.h>
+#include "host/ble_sm.h"
#include "ble_hs_priv.h"
#include "ble_sm_priv.h"
@@ -109,7 +110,7 @@ ble_sm_sc_random_go(struct ble_sm_proc *proc,
}
void
-ble_sm_sc_random_handle(struct ble_sm_proc *proc,
+ble_sm_sc_rx_pair_random(struct ble_sm_proc *proc,
struct ble_sm_result *res)
{
uint8_t confirm_val[16];
@@ -152,7 +153,7 @@ ble_sm_sc_random_handle(struct ble_sm_proc *proc,
proc->state = BLE_SM_PROC_STATE_DHKEY_CHECK;
}
- res->do_state = 1;
+ res->execute = 1;
}
void
@@ -181,7 +182,7 @@ ble_sm_sc_public_key_go(struct ble_sm_proc *proc,
(!initiator_txes && !is_initiator)) {
proc->state = BLE_SM_PROC_STATE_CONFIRM;
- res->do_state = 1;
+ res->execute = 1;
}
return;
@@ -203,10 +204,10 @@ ble_sm_sc_public_key_handle(struct ble_sm_proc *proc,
proc->state = BLE_SM_PROC_STATE_CONFIRM;
if (ble_sm_sc_initiator_txes_confirm(proc)) {
- res->do_state = 1;
+ res->execute = 1;
}
} else {
- res->do_state = 1;
+ res->execute = 1;
}
}
@@ -297,7 +298,7 @@ ble_sm_dhkey_check_handle(struct ble_sm_proc *proc,
proc->state = BLE_SM_PROC_STATE_ENC_START;
}
- res->do_state = 1;
+ res->execute = 1;
}
void
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac11583f/net/nimble/host/src/test/ble_sm_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_sm_test.c b/net/nimble/host/src/test/ble_sm_test.c
index 4d84c98..c83e4a6 100644
--- a/net/nimble/host/src/test/ble_sm_test.c
+++ b/net/nimble/host/src/test/ble_sm_test.c
@@ -24,6 +24,7 @@
#include "nimble/hci_common.h"
#include "nimble/nimble_opt.h"
#include "host/host_hci.h"
+#include "host/ble_sm.h"
#include "host/ble_hs_test.h"
#include "ble_hs_test_util.h"
@@ -56,9 +57,9 @@ struct ble_sm_test_lgcy_params {
struct ble_sm_pair_random random_req;
struct ble_sm_pair_random random_rsp;
struct ble_sm_enc_info enc_info_req;
- struct ble_sm_master_iden master_id_req;
+ struct ble_sm_master_id master_id_req;
struct ble_sm_enc_info enc_info_rsp;
- struct ble_sm_master_iden master_id_rsp;
+ struct ble_sm_master_id master_id_rsp;
int pair_alg;
unsigned authenticated:1;
uint8_t tk[16];
@@ -500,7 +501,7 @@ ble_sm_test_util_verify_tx_enc_info(
BLE_SM_ENC_INFO_SZ);
ble_sm_enc_info_parse(om->om_data, om->om_len, &cmd);
- TEST_ASSERT(memcmp(cmd.ltk_le, exp_cmd->ltk_le, sizeof cmd.ltk_le) == 0);
+ TEST_ASSERT(memcmp(cmd.ltk, exp_cmd->ltk, sizeof cmd.ltk) == 0);
}
static void
@@ -1002,7 +1003,7 @@ ble_sm_test_util_peer_lgcy_good(
ble_sm_dbg_set_next_start_rand(params->r);
if (params->has_enc_info_req) {
- ble_sm_dbg_set_next_ltk(params->enc_info_req.ltk_le);
+ ble_sm_dbg_set_next_ltk(params->enc_info_req.ltk);
}
ble_hs_test_util_create_conn(2, params->init_addr,
@@ -1223,11 +1224,11 @@ TEST_CASE(ble_sm_test_case_peer_lgcy_passkey_good)
.ediv = 61621,
.passkey = {
- .action = BLE_GAP_PKACT_INPUT,
+ .action = BLE_SM_PKACT_INPUT,
.passkey = 884570,
},
.enc_info_req = {
- .ltk_le = {
+ .ltk = {
0x2b, 0x9c, 0x1e, 0x42, 0xa8, 0xcb, 0xab, 0xd1,
0x4b, 0xde, 0x50, 0x05, 0x50, 0xd9, 0x95, 0xc6
},
@@ -1241,7 +1242,7 @@ TEST_CASE(ble_sm_test_case_peer_lgcy_passkey_good)
.has_master_id_req = 1,
.enc_info_rsp = {
- .ltk_le = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 }
+ .ltk = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 }
},
.has_enc_info_rsp = 1,
@@ -1708,7 +1709,7 @@ ble_sm_test_util_us_lgcy_good(
ble_sm_dbg_set_next_start_rand(params->r);
if (params->has_enc_info_req) {
- ble_sm_dbg_set_next_ltk(params->enc_info_req.ltk_le);
+ ble_sm_dbg_set_next_ltk(params->enc_info_req.ltk);
}
ble_hs_test_util_create_conn(2, params->rsp_addr,
@@ -2169,12 +2170,12 @@ TEST_CASE(ble_sm_test_case_us_sec_req_pair)
.ediv = 61621,
.passkey = {
- .action = BLE_GAP_PKACT_INPUT,
+ .action = BLE_SM_PKACT_INPUT,
.passkey = 884570,
},
.enc_info_req = {
- .ltk_le = {
+ .ltk = {
0x2b, 0x9c, 0x1e, 0x42, 0xa8, 0xcb, 0xab, 0xd1,
0x4b, 0xde, 0x50, 0x05, 0x50, 0xd9, 0x95, 0xc6
},
@@ -2188,7 +2189,7 @@ TEST_CASE(ble_sm_test_case_us_sec_req_pair)
.has_master_id_req = 1,
.enc_info_rsp = {
- .ltk_le = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 }
+ .ltk = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 }
},
.has_enc_info_rsp = 1,