From 391dbdefa0dfe3e8cddcd280019cb39b5aa0b24e Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Wed, 29 May 2013 11:05:32 +0300 Subject: [PATCH] emulator: Make bthost L2CAP sender strictly only for requests --- emulator/bthost.c | 31 ++++++++++++++++++++++--------- emulator/bthost.h | 4 ++-- src/shared/hciemu.c | 1 + tools/l2cap-tester.c | 3 ++- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/emulator/bthost.c b/emulator/bthost.c index 5e3592be6..20d90c990 100644 --- a/emulator/bthost.c +++ b/emulator/bthost.c @@ -257,8 +257,9 @@ static void send_acl(struct bthost *bthost, uint16_t handle, uint16_t cid, free(pkt_data); } -uint8_t bthost_l2cap_cmd(struct bthost *bthost, uint16_t handle, uint8_t code, - uint8_t ident, const void *data, uint16_t len) +static uint8_t l2cap_sig_send(struct bthost *bthost, uint16_t handle, + uint8_t code, uint8_t ident, + const void *data, uint16_t len) { static uint8_t next_ident = 1; struct bt_l2cap_hdr_sig *hdr; @@ -292,6 +293,18 @@ uint8_t bthost_l2cap_cmd(struct bthost *bthost, uint16_t handle, uint8_t code, return ident; } +bool bthost_l2cap_req(struct bthost *bthost, uint16_t handle, uint8_t req, + const void *data, uint16_t len) +{ + uint8_t ident; + + ident = l2cap_sig_send(bthost, handle, req, 0, data, len); + if (!ident) + return false; + + return true; +} + static void send_command(struct bthost *bthost, uint16_t opcode, const void *data, uint8_t len) { @@ -567,7 +580,7 @@ static bool l2cap_conn_req(struct bthost *bthost, uint16_t handle, else rsp.result = cpu_to_le16(0x0002); /* PSM Not Supported */ - bthost_l2cap_cmd(bthost, handle, BT_L2CAP_PDU_CONN_RSP, ident, &rsp, + l2cap_sig_send(bthost, handle, BT_L2CAP_PDU_CONN_RSP, ident, &rsp, sizeof(rsp)); if (!rsp.result) { @@ -579,7 +592,7 @@ static bool l2cap_conn_req(struct bthost *bthost, uint16_t handle, memset(&conf_req, 0, sizeof(conf_req)); conf_req.dcid = rsp.dcid; - bthost_l2cap_cmd(bthost, handle, BT_L2CAP_PDU_CONFIG_REQ, 0, + l2cap_sig_send(bthost, handle, BT_L2CAP_PDU_CONFIG_REQ, 0, &conf_req, sizeof(conf_req)); } @@ -603,7 +616,7 @@ static bool l2cap_conn_rsp(struct bthost *bthost, uint16_t handle, memset(&req, 0, sizeof(req)); req.dcid = rsp->dcid; - bthost_l2cap_cmd(bthost, handle, BT_L2CAP_PDU_CONFIG_REQ, 0, + l2cap_sig_send(bthost, handle, BT_L2CAP_PDU_CONFIG_REQ, 0, &req, sizeof(req)); } @@ -631,7 +644,7 @@ static bool l2cap_config_req(struct bthost *bthost, uint16_t handle, rsp.scid = cpu_to_le16(l2conn->dcid); rsp.flags = req->flags; - bthost_l2cap_cmd(bthost, handle, BT_L2CAP_PDU_CONFIG_RSP, ident, &rsp, + l2cap_sig_send(bthost, handle, BT_L2CAP_PDU_CONFIG_RSP, ident, &rsp, sizeof(rsp)); return true; @@ -661,7 +674,7 @@ static bool l2cap_disconn_req(struct bthost *bthost, uint16_t handle, rsp.dcid = req->dcid; rsp.scid = req->scid; - bthost_l2cap_cmd(bthost, handle, BT_L2CAP_PDU_DISCONN_RSP, ident, &rsp, + l2cap_sig_send(bthost, handle, BT_L2CAP_PDU_DISCONN_RSP, ident, &rsp, sizeof(rsp)); return true; @@ -679,7 +692,7 @@ static bool l2cap_info_req(struct bthost *bthost, uint16_t handle, rsp.type = req->type; rsp.result = cpu_to_le16(0x0001); /* Not Supported */ - bthost_l2cap_cmd(bthost, handle, BT_L2CAP_PDU_INFO_RSP, ident, &rsp, + l2cap_sig_send(bthost, handle, BT_L2CAP_PDU_INFO_RSP, ident, &rsp, sizeof(rsp)); return true; @@ -742,7 +755,7 @@ static void l2cap_sig(struct bthost *bthost, uint16_t handle, const void *data, reject: memset(&rej, 0, sizeof(rej)); - bthost_l2cap_cmd(bthost, handle, BT_L2CAP_PDU_CMD_REJECT, 0, + l2cap_sig_send(bthost, handle, BT_L2CAP_PDU_CMD_REJECT, 0, &rej, sizeof(rej)); } diff --git a/emulator/bthost.h b/emulator/bthost.h index 777dfb4f8..609da8076 100644 --- a/emulator/bthost.h +++ b/emulator/bthost.h @@ -51,8 +51,8 @@ void bthost_set_connect_cb(struct bthost *bthost, bthost_new_conn_cb cb, void bthost_hci_connect(struct bthost *bthost, const uint8_t *bdaddr); -uint8_t bthost_l2cap_cmd(struct bthost *bthost, uint16_t handle, uint8_t code, - uint8_t ident, const void *data, uint16_t len); +bool bthost_l2cap_req(struct bthost *bthost, uint16_t handle, uint8_t req, + const void *data, uint16_t len); void bthost_write_scan_enable(struct bthost *bthost, uint8_t scan); diff --git a/src/shared/hciemu.c b/src/shared/hciemu.c index f9a7d1d88..a0b347cae 100644 --- a/src/shared/hciemu.c +++ b/src/shared/hciemu.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include diff --git a/tools/l2cap-tester.c b/tools/l2cap-tester.c index 540569180..f6426a706 100644 --- a/tools/l2cap-tester.c +++ b/tools/l2cap-tester.c @@ -28,6 +28,7 @@ #include #include #include +#include #include @@ -479,7 +480,7 @@ static void client_new_conn(uint16_t handle, void *user_data) req.scid = htobs(0x0041); bthost = hciemu_client_get_host(data->hciemu); - bthost_l2cap_cmd(bthost, handle, BT_L2CAP_PDU_CONN_REQ, 0, + bthost_l2cap_req(bthost, handle, BT_L2CAP_PDU_CONN_REQ, &req, sizeof(req)); } -- 2.47.3