mirror of
https://git.kernel.org/pub/scm/bluetooth/bluez.git
synced 2025-01-22 04:13:30 +08:00
tools/l2cap_tester: Add write server test case
These test case send data from local server to remote client.
This commit is contained in:
parent
89095eae05
commit
a663775dbf
@ -297,6 +297,16 @@ static const struct l2cap_server_data l2cap_server_read_success_test = {
|
||||
.data_len = sizeof(l2_data),
|
||||
};
|
||||
|
||||
static const struct l2cap_server_data l2cap_server_write_success_test = {
|
||||
.server_psm = 0x1001,
|
||||
.send_req_code = BT_L2CAP_PDU_CONN_REQ,
|
||||
.send_req = l2cap_connect_req,
|
||||
.send_req_len = sizeof(l2cap_connect_req),
|
||||
.expect_rsp_code = BT_L2CAP_PDU_CONN_RSP,
|
||||
.write_data = l2_data,
|
||||
.data_len = sizeof(l2_data),
|
||||
};
|
||||
|
||||
static const uint8_t l2cap_nval_psm_rsp[] = { 0x00, 0x00, /* dcid */
|
||||
0x41, 0x00, /* scid */
|
||||
0x02, 0x00, /* nval PSM */
|
||||
@ -547,6 +557,23 @@ static void bthost_received_data(const void *buf, uint16_t len,
|
||||
tester_test_passed();
|
||||
}
|
||||
|
||||
static void server_bthost_received_data(const void *buf, uint16_t len,
|
||||
void *user_data)
|
||||
{
|
||||
struct test_data *data = tester_get_data();
|
||||
const struct l2cap_server_data *l2data = data->test_data;
|
||||
|
||||
if (len != l2data->data_len) {
|
||||
tester_test_failed();
|
||||
return;
|
||||
}
|
||||
|
||||
if (memcmp(buf, l2data->write_data, l2data->data_len))
|
||||
tester_test_failed();
|
||||
else
|
||||
tester_test_passed();
|
||||
}
|
||||
|
||||
static gboolean l2cap_connect_cb(GIOChannel *io, GIOCondition cond,
|
||||
gpointer user_data)
|
||||
{
|
||||
@ -750,6 +777,17 @@ static gboolean l2cap_listen_cb(GIOChannel *io, GIOCondition cond,
|
||||
bthost_send_cid(bthost, data->handle, data->dcid,
|
||||
l2data->read_data, l2data->data_len);
|
||||
|
||||
return FALSE;
|
||||
} else if (l2data->write_data) {
|
||||
struct bthost *bthost;
|
||||
|
||||
bthost = hciemu_client_get_host(data->hciemu);
|
||||
bthost_add_cid_hook(bthost, data->handle, data->scid,
|
||||
server_bthost_received_data, NULL);
|
||||
|
||||
write(new_sk, l2data->write_data, l2data->data_len);
|
||||
close(new_sk);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -923,6 +961,10 @@ int main(int argc, char *argv[])
|
||||
&l2cap_server_read_success_test,
|
||||
setup_powered_server, test_server);
|
||||
|
||||
test_l2cap_bredr("L2CAP BR/EDR Server - Write Success",
|
||||
&l2cap_server_write_success_test,
|
||||
setup_powered_server, test_server);
|
||||
|
||||
test_l2cap_bredr("L2CAP BR/EDR Server - Invalid PSM",
|
||||
&l2cap_server_nval_psm_test,
|
||||
setup_powered_server, test_server);
|
||||
|
Loading…
Reference in New Issue
Block a user