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 2017/01/27 18:45:35 UTC
[08/18] incubator-mynewt-core git commit: nimble/sm: Use packed
structures for dhkey check
nimble/sm: Use packed structures for dhkey check
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/bd23aef1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/bd23aef1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/bd23aef1
Branch: refs/heads/develop
Commit: bd23aef107a64dd3d2b46afd0753110129cd4f7d
Parents: 6ab4a71
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Tue Jan 17 19:24:42 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Wed Jan 25 15:44:15 2017 +0100
----------------------------------------------------------------------
net/nimble/host/src/ble_sm_cmd.c | 4 ++--
net/nimble/host/src/ble_sm_priv.h | 3 +--
net/nimble/host/src/ble_sm_sc.c | 25 +++++++++++++++---------
net/nimble/host/test/src/ble_sm_test_util.c | 6 +++---
4 files changed, 22 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd23aef1/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 427c8d7..5251dae 100644
--- a/net/nimble/host/src/ble_sm_cmd.c
+++ b/net/nimble/host/src/ble_sm_cmd.c
@@ -715,7 +715,7 @@ ble_sm_dhkey_check_write(void *payload, int len,
{
uint8_t *u8ptr;
- if (len < sizeof(struct ble_sm_hdr) + BLE_SM_DHKEY_CHECK_SZ) {
+ if (len < sizeof(struct ble_sm_hdr) + sizeof(struct ble_sm_dhkey_check)) {
return BLE_HS_EMSGSIZE;
}
@@ -735,7 +735,7 @@ ble_sm_dhkey_check_tx(uint16_t conn_handle, struct ble_sm_dhkey_check *cmd)
struct os_mbuf *txom;
int rc;
- rc = ble_sm_init_req(BLE_SM_DHKEY_CHECK_SZ, &txom);
+ rc = ble_sm_init_req(sizeof(struct ble_sm_dhkey_check), &txom);
if (rc != 0) {
return BLE_HS_ENOMEM;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd23aef1/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 131385b..6c2bc74 100644
--- a/net/nimble/host/src/ble_sm_priv.h
+++ b/net/nimble/host/src/ble_sm_priv.h
@@ -189,10 +189,9 @@ struct ble_sm_public_key {
* | (Code=0x0d) | 1 |
* | DHKey Check | 16 |
*/
-#define BLE_SM_DHKEY_CHECK_SZ 16
struct ble_sm_dhkey_check {
uint8_t value[16];
-};
+} __attribute__((packed));
#if NIMBLE_BLE_SM
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd23aef1/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 b8ced1a..2cf9ad8 100644
--- a/net/nimble/host/src/ble_sm_sc.c
+++ b/net/nimble/host/src/ble_sm_sc.c
@@ -631,11 +631,12 @@ void
ble_sm_sc_dhkey_check_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
void *arg)
{
- struct ble_sm_dhkey_check cmd;
+ struct ble_sm_dhkey_check *cmd;
const uint8_t *our_ota_addr;
const uint8_t *peer_ota_addr;
uint8_t peer_id_addr_type;
uint8_t our_id_addr_type;
+ struct os_mbuf *txom;
uint8_t *iocap;
int rc;
@@ -655,16 +656,23 @@ ble_sm_sc_dhkey_check_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
&our_id_addr_type, &our_ota_addr,
&peer_id_addr_type, &peer_ota_addr);
+ cmd = ble_sm_cmd_get(BLE_SM_OP_PAIR_DHKEY_CHECK, sizeof(*cmd), &txom);
+ if (!cmd) {
+ rc = BLE_HS_ENOMEM;
+ goto err;
+ }
+
rc = ble_sm_alg_f6(proc->mackey, ble_sm_our_pair_rand(proc),
ble_sm_peer_pair_rand(proc), proc->tk, iocap,
our_id_addr_type, our_ota_addr,
peer_id_addr_type, peer_ota_addr,
- cmd.value);
+ cmd->value);
if (rc != 0) {
+ os_mbuf_free_chain(txom);
goto err;
}
- rc = ble_sm_dhkey_check_tx(proc->conn_handle, &cmd);
+ rc = ble_sm_tx(proc->conn_handle, txom);
if (rc != 0) {
goto err;
}
@@ -755,19 +763,18 @@ void
ble_sm_sc_dhkey_check_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
struct ble_sm_result *res)
{
- struct ble_sm_dhkey_check cmd;
+ struct ble_sm_dhkey_check *cmd;
struct ble_sm_proc *proc;
- res->app_status = ble_hs_mbuf_pullup_base(om, BLE_SM_DHKEY_CHECK_SZ);
+ res->app_status = ble_hs_mbuf_pullup_base(om, sizeof(*cmd));
if (res->app_status != 0) {
res->enc_cb = 1;
res->sm_err = BLE_SM_ERR_UNSPECIFIED;
return;
}
- ble_sm_dhkey_check_parse((*om)->om_data, (*om)->om_len, &cmd);
- BLE_SM_LOG_CMD(0, "dhkey check", conn_handle, ble_sm_dhkey_check_log,
- &cmd);
+ cmd = (struct ble_sm_dhkey_check *)(*om)->om_data;
+ BLE_SM_LOG_CMD(0, "dhkey check", conn_handle, ble_sm_dhkey_check_log, cmd);
ble_hs_lock();
proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_DHKEY_CHECK, -1,
@@ -775,7 +782,7 @@ ble_sm_sc_dhkey_check_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
if (proc == NULL) {
res->app_status = BLE_HS_ENOENT;
} else {
- ble_sm_dhkey_check_process(proc, &cmd, res);
+ ble_sm_dhkey_check_process(proc, cmd, res);
}
ble_hs_unlock();
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd23aef1/net/nimble/host/test/src/ble_sm_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_sm_test_util.c b/net/nimble/host/test/src/ble_sm_test_util.c
index f501ba8..8b1c427 100644
--- a/net/nimble/host/test/src/ble_sm_test_util.c
+++ b/net/nimble/host/test/src/ble_sm_test_util.c
@@ -439,12 +439,12 @@ ble_sm_test_util_rx_dhkey_check(uint16_t conn_handle,
hci_hdr = BLE_SM_TEST_UTIL_HCI_HDR(
2, BLE_HCI_PB_FIRST_FLUSH,
- BLE_L2CAP_HDR_SZ + sizeof(struct ble_sm_hdr) + BLE_SM_DHKEY_CHECK_SZ);
+ BLE_L2CAP_HDR_SZ + sizeof(struct ble_sm_hdr) + sizeof(struct ble_sm_dhkey_check));
om = ble_hs_mbuf_l2cap_pkt();
TEST_ASSERT_FATAL(om != NULL);
- payload_len = sizeof(struct ble_sm_hdr) + BLE_SM_DHKEY_CHECK_SZ;
+ payload_len = sizeof(struct ble_sm_hdr) + sizeof(struct ble_sm_dhkey_check);
v = os_mbuf_extend(om, payload_len);
TEST_ASSERT_FATAL(v != NULL);
@@ -710,7 +710,7 @@ ble_sm_test_util_verify_tx_dhkey_check(
struct os_mbuf *om;
om = ble_sm_test_util_verify_tx_hdr(BLE_SM_OP_PAIR_DHKEY_CHECK,
- BLE_SM_DHKEY_CHECK_SZ);
+ sizeof(struct ble_sm_dhkey_check));
ble_sm_dhkey_check_parse(om->om_data, om->om_len, &cmd);
TEST_ASSERT(memcmp(cmd.value, exp_cmd->value, 16) == 0);