uint8_t expect_rsp_code;
const void *expect_rsp;
uint16_t expect_rsp_len;
+ uint16_t data_len;
+ const void *read_data;
+ const void *write_data;
};
static void mgmt_debug(const char *str, void *user_data)
.expect_rsp_code = BT_L2CAP_PDU_CONN_RSP,
};
+static const struct l2cap_server_data l2cap_server_read_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,
+ .read_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 */
return FALSE;
}
+static gboolean server_received_data(GIOChannel *io, GIOCondition cond,
+ gpointer user_data)
+{
+ struct test_data *data = tester_get_data();
+ const struct l2cap_server_data *l2data = data->test_data;
+ char buf[1024];
+ int sk;
+
+ sk = g_io_channel_unix_get_fd(io);
+ read(sk, buf, l2data->data_len);
+
+ if (memcmp(buf, l2data->read_data, l2data->data_len))
+ tester_test_failed();
+ else
+ tester_test_passed();
+
+ close(sk);
+
+ return FALSE;
+}
+
static void bthost_received_data(const void *buf, uint16_t len,
void *user_data)
{
gpointer user_data)
{
struct test_data *data = tester_get_data();
+ const struct l2cap_server_data *l2data = data->test_data;
int sk, new_sk;
data->io_id = 0;
return FALSE;
}
+ if (l2data->read_data) {
+ struct bthost *bthost;
+ GIOChannel *new_io;
+
+ new_io = g_io_channel_unix_new(new_sk);
+
+ bthost = hciemu_client_get_host(data->hciemu);
+ g_io_add_watch(new_io, G_IO_IN, server_received_data, NULL);
+ bthost_send_cid(bthost, data->handle, data->dcid,
+ l2data->read_data, l2data->data_len);
+
+ return FALSE;
+ }
+
tester_print("Successfully connected");
close(new_sk);
goto failed;
}
+ if (code == BT_L2CAP_PDU_CONN_RSP) {
+
+ const struct bt_l2cap_pdu_conn_rsp *rsp = data;
+ if (len == sizeof(rsp) && !rsp->result && !rsp->status)
+ return;
+
+ test_data->dcid = rsp->dcid;
+ test_data->scid = rsp->scid;
+
+ if (l2data->data_len)
+ return;
+ }
+
if (!l2data->expect_rsp) {
tester_test_passed();
return;
tester_print("New client connection with handle 0x%04x", handle);
+ data->handle = handle;
+
if (l2data->send_req) {
bthost_l2cap_rsp_cb cb;
test_l2cap_bredr("L2CAP BR/EDR Server - Success",
&l2cap_server_success_test,
setup_powered_server, test_server);
+
+ test_l2cap_bredr("L2CAP BR/EDR Server - Read Success",
+ &l2cap_server_read_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);