nimble/sm: Use packed structures for id info

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

Branch: refs/heads/develop
Commit: b9abdc407533f4a425b784b4a4a6f5520898572a
Parents: be16f18
Author: Szymon Janc <[email protected]>
Authored: Tue Jan 17 19:24:37 2017 +0100
Committer: Szymon Janc <[email protected]>
Committed: Wed Jan 25 15:44:15 2017 +0100

----------------------------------------------------------------------
 net/nimble/host/src/ble_sm.c                | 21 ++++++++++++---------
 net/nimble/host/src/ble_sm_cmd.c            |  4 ++--
 net/nimble/host/src/ble_sm_priv.h           |  4 +---
 net/nimble/host/test/src/ble_sm_test_util.c |  8 ++++----
 4 files changed, 19 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b9abdc40/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 81f6824..74ecc39 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -1723,7 +1723,7 @@ ble_sm_key_exch_exec(struct ble_sm_proc *proc, struct 
ble_sm_result *res,
     struct ble_sm_sign_info sign_info;
     struct ble_sm_master_id *master_id;
     struct ble_sm_enc_info *enc_info;
-    struct ble_sm_id_info id_info;
+    struct ble_sm_id_info *id_info;
     struct ble_hs_conn *conn;
     uint8_t init_key_dist;
     uint8_t resp_key_dist;
@@ -1791,18 +1791,21 @@ ble_sm_key_exch_exec(struct ble_sm_proc *proc, struct 
ble_sm_result *res,
 
     if (our_key_dist & BLE_SM_PAIR_KEY_DIST_ID) {
         /* Send identity information. */
+        id_info = ble_sm_cmd_get(BLE_SM_OP_IDENTITY_INFO, sizeof(*id_info),
+                                 &txom);
+
         rc = ble_hs_pvcy_our_irk(&irk);
         if (rc != 0) {
             goto err;
         }
 
-        memcpy(id_info.irk, irk, 16);
+        memcpy(id_info->irk, irk, 16);
+        proc->our_keys.irk_valid = 1;
 
-        rc = ble_sm_id_info_tx(proc->conn_handle, &id_info);
+        rc = ble_sm_tx(proc->conn_handle, txom);
         if (rc != 0) {
             goto err;
         }
-        proc->our_keys.irk_valid = 1;
 
         /* Send identity address information. */
         conn = ble_hs_conn_find_assert(proc->conn_handle);
@@ -1939,18 +1942,18 @@ static void
 ble_sm_id_info_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
                   struct ble_sm_result *res)
 {
-    struct ble_sm_id_info cmd;
+    struct ble_sm_id_info *cmd;
     struct ble_sm_proc *proc;
 
-    res->app_status = ble_hs_mbuf_pullup_base(om, BLE_SM_ID_INFO_SZ);
+    res->app_status = ble_hs_mbuf_pullup_base(om, sizeof(*cmd));
     if (res->app_status != 0) {
         res->sm_err = BLE_SM_ERR_UNSPECIFIED;
         res->enc_cb = 1;
         return;
     }
 
-    ble_sm_id_info_parse((*om)->om_data, (*om)->om_len, &cmd);
-    BLE_SM_LOG_CMD(0, "id info", conn_handle, ble_sm_id_info_log, &cmd);
+    cmd = (struct ble_sm_id_info *)(*om)->om_data;
+    BLE_SM_LOG_CMD(0, "id info", conn_handle, ble_sm_id_info_log, cmd);
 
     ble_hs_lock();
 
@@ -1961,7 +1964,7 @@ ble_sm_id_info_rx(uint16_t conn_handle, uint8_t op, 
struct os_mbuf **om,
     } else {
         proc->rx_key_flags &= ~BLE_SM_KE_F_ID_INFO;
 
-        memcpy(proc->peer_keys.irk, cmd.irk, 16);
+        memcpy(proc->peer_keys.irk, cmd->irk, 16);
         proc->peer_keys.irk_valid = 1;
 
         ble_sm_key_rxed(proc, res);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b9abdc40/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 f7e218f..626010c 100644
--- a/net/nimble/host/src/ble_sm_cmd.c
+++ b/net/nimble/host/src/ble_sm_cmd.c
@@ -440,7 +440,7 @@ ble_sm_id_info_write(void *payload, int len, struct 
ble_sm_id_info *cmd)
 {
     uint8_t *u8ptr;
 
-    BLE_HS_DBG_ASSERT(len >= sizeof(struct ble_sm_hdr) + BLE_SM_ID_INFO_SZ);
+    BLE_HS_DBG_ASSERT(len >= sizeof(struct ble_sm_hdr) + sizeof(struct 
ble_sm_id_info));
 
     u8ptr = payload;
 
@@ -456,7 +456,7 @@ ble_sm_id_info_tx(uint16_t conn_handle, struct 
ble_sm_id_info *cmd)
 
     BLE_SM_LOG_CMD(1, "id info", conn_handle, ble_sm_id_info_log, cmd);
 
-    rc = ble_sm_init_req(BLE_SM_ID_INFO_SZ, &txom);
+    rc = ble_sm_init_req(sizeof(struct ble_sm_id_info), &txom);
     if (rc != 0) {
         return BLE_HS_ENOMEM;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b9abdc40/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 2447c19..95ec4ff 100644
--- a/net/nimble/host/src/ble_sm_priv.h
+++ b/net/nimble/host/src/ble_sm_priv.h
@@ -135,11 +135,9 @@ struct ble_sm_master_id {
  * | (Code=0x08)                        | 1                 |
  * | irk                                | 16                |
  */
-#define BLE_SM_ID_INFO_SZ           16
 struct ble_sm_id_info {
-    /* Sent and stored in little-endian. */
     uint8_t irk[16];
-};
+} __attribute__((packed));
 
 /**
  * | Parameter                          | Size (octets)     |

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b9abdc40/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 21aa443..99f7c89 100644
--- a/net/nimble/host/test/src/ble_sm_test_util.c
+++ b/net/nimble/host/test/src/ble_sm_test_util.c
@@ -529,12 +529,12 @@ ble_sm_test_util_rx_id_info(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_ID_INFO_SZ);
+        BLE_L2CAP_HDR_SZ + sizeof(struct ble_sm_hdr) + sizeof(struct 
ble_sm_id_info));
 
     om = ble_hs_mbuf_l2cap_pkt();
     TEST_ASSERT_FATAL(om != NULL);
 
-    payload_len = sizeof(struct ble_sm_hdr) + BLE_SM_ID_INFO_SZ;
+    payload_len = sizeof(struct ble_sm_hdr) + sizeof(struct ble_sm_id_info);
 
     v = os_mbuf_extend(om, payload_len);
     TEST_ASSERT_FATAL(v != NULL);
@@ -756,7 +756,7 @@ ble_sm_test_util_verify_tx_id_info(struct ble_sm_id_info 
*exp_cmd)
 
     ble_hs_test_util_tx_all();
     om = ble_sm_test_util_verify_tx_hdr(BLE_SM_OP_IDENTITY_INFO,
-                                        BLE_SM_ID_INFO_SZ);
+                                        sizeof(struct ble_sm_id_info));
     ble_sm_id_info_parse(om->om_data, om->om_len, &cmd);
 
     TEST_ASSERT(memcmp(cmd.irk, exp_cmd->irk, 16) == 0);
@@ -797,7 +797,7 @@ ble_sm_test_util_verify_tx_sign_info(struct 
ble_sm_sign_info *exp_cmd)
 
     ble_hs_test_util_tx_all();
     om = ble_sm_test_util_verify_tx_hdr(BLE_SM_OP_SIGN_INFO,
-                                        BLE_SM_ID_INFO_SZ);
+                                        BLE_SM_SIGN_INFO_SZ);
     ble_sm_sign_info_parse(om->om_data, om->om_len, &cmd);
 
     TEST_ASSERT(memcmp(cmd.sig_key, exp_cmd->sig_key, 16) == 0);

Reply via email to