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/03/03 17:36:25 UTC

[10/26] incubator-mynewt-core git commit: nimble/l2cap: Refactor handling L2CAP reject command

nimble/l2cap: Refactor handling L2CAP reject command

With this patch L2CAP reject command uses a new way of preparing
command and sending it


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

Branch: refs/heads/develop
Commit: ba9de55afb41bf1c1b837ae93041953aa2f59493
Parents: a443035
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Tue Feb 28 12:14:46 2017 +0100
Committer: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Committed: Fri Mar 3 12:40:42 2017 +0100

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap_sig_cmd.c  | 40 +++++----------------------
 net/nimble/host/src/ble_l2cap_sig_priv.h |  1 +
 2 files changed, 8 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ba9de55a/net/nimble/host/src/ble_l2cap_sig_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig_cmd.c b/net/nimble/host/src/ble_l2cap_sig_cmd.c
index 189efd7..e6a7209 100644
--- a/net/nimble/host/src/ble_l2cap_sig_cmd.c
+++ b/net/nimble/host/src/ble_l2cap_sig_cmd.c
@@ -94,48 +94,22 @@ ble_l2cap_sig_hdr_write(void *payload, uint16_t len,
     BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_HDR_SZ);
     ble_l2cap_sig_hdr_swap(payload, src);
 }
-static void
-ble_l2cap_sig_reject_swap(struct ble_l2cap_sig_reject *dst,
-                          struct ble_l2cap_sig_reject *src)
-{
-    dst->reason = TOFROMLE16(src->reason);
-}
-
-static void
-ble_l2cap_sig_reject_write(void *payload, uint16_t len,
-                           struct ble_l2cap_sig_reject *src,
-                           void *data, int data_len)
-{
-    uint8_t *u8ptr;
-
-    BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_REJECT_MIN_SZ + data_len);
-
-    ble_l2cap_sig_reject_swap(payload, src);
-
-    u8ptr = payload;
-    u8ptr += BLE_L2CAP_SIG_REJECT_MIN_SZ;
-    memcpy(u8ptr, data, data_len);
-}
 
 int
 ble_l2cap_sig_reject_tx(uint16_t conn_handle, uint8_t id, uint16_t reason,
                         void *data, int data_len)
 {
-    struct ble_l2cap_sig_reject cmd;
+    struct ble_l2cap_sig_reject *cmd;
     struct os_mbuf *txom;
-    void *payload_buf;
-    int rc;
 
-    rc = ble_l2cap_sig_init_cmd(BLE_L2CAP_SIG_OP_REJECT, id,
-                                BLE_L2CAP_SIG_REJECT_MIN_SZ + data_len, &txom,
-                                &payload_buf);
-    if (rc != 0) {
-        return rc;
+    cmd = ble_l2cap_sig_cmd_get(BLE_L2CAP_SIG_OP_REJECT, id,
+                           sizeof(*cmd) + data_len, &txom);
+    if (!cmd) {
+        return BLE_HS_ENOMEM;
     }
 
-    cmd.reason = reason;
-    ble_l2cap_sig_reject_write(payload_buf, txom->om_len, &cmd,
-                               data, data_len);
+    cmd->reason = htole16(reason);
+    memcpy(cmd->data, data, data_len);
 
     STATS_INC(ble_l2cap_stats, sig_rx);
     return ble_l2cap_sig_tx(conn_handle, txom);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ba9de55a/net/nimble/host/src/ble_l2cap_sig_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig_priv.h b/net/nimble/host/src/ble_l2cap_sig_priv.h
index f089dcb..ad3b846 100644
--- a/net/nimble/host/src/ble_l2cap_sig_priv.h
+++ b/net/nimble/host/src/ble_l2cap_sig_priv.h
@@ -39,6 +39,7 @@ struct ble_l2cap_sig_hdr {
 #define BLE_L2CAP_SIG_REJECT_MIN_SZ         2
 struct ble_l2cap_sig_reject {
     uint16_t reason;
+    uint8_t data[0];
 } __attribute__((packed));
 
 #define BLE_L2CAP_SIG_UPDATE_REQ_SZ         8