Lines Matching +full:num +full:- +full:channels
1 /* l2cap.c - Bluetooth L2CAP Tester */
6 * SPDX-License-Identifier: Apache-2.0
26 #define CHANNELS 2 macro
29 NET_BUF_POOL_FIXED_DEFINE(data_pool, CHANNELS, BT_L2CAP_SDU_BUF_SIZE(DATA_MTU),
46 } channels[CHANNELS]; variable
60 ev = (void *)chan->recv_cb_buf; in seg_recv_cb()
61 memcpy(&ev->data[seg_offset], seg->data, seg->len); in seg_recv_cb()
64 if (seg_offset + seg->len == sdu_len) { in seg_recv_cb()
65 ev->chan_id = chan->chan_id; in seg_recv_cb()
66 ev->data_length = sys_cpu_to_le16(sdu_len); in seg_recv_cb()
68 tester_event(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_EV_DATA_RECEIVED, chan->recv_cb_buf, in seg_recv_cb()
72 if (chan->hold_credit) { in seg_recv_cb()
73 chan->pending_credits++; in seg_recv_cb()
93 ev->chan_id = chan->chan_id; in recv_cb()
94 ev->data_length = sys_cpu_to_le16(buf->len); in recv_cb()
95 memcpy(ev->data, buf->data, buf->len); in recv_cb()
98 recv_cb_buf, sizeof(*ev) + buf->len); in recv_cb()
100 if (chan->hold_credit && !chan->pending_credit) { in recv_cb()
104 chan->pending_credit = buf; in recv_cb()
105 return -EINPROGRESS; in recv_cb()
120 ev.chan_id = chan->chan_id; in connected_cb()
122 if (!bt_conn_get_info(l2cap_chan->conn, &info)) { in connected_cb()
125 ev.mtu_remote = sys_cpu_to_le16(chan->le.tx.mtu); in connected_cb()
126 ev.mps_remote = sys_cpu_to_le16(chan->le.tx.mps); in connected_cb()
127 ev.mtu_local = sys_cpu_to_le16(chan->le.rx.mtu); in connected_cb()
128 ev.mps_local = sys_cpu_to_le16(chan->le.rx.mps); in connected_cb()
151 if (chan->pending_credit) { in disconnected_cb()
152 net_buf_unref(chan->pending_credit); in disconnected_cb()
153 chan->pending_credit = NULL; in disconnected_cb()
160 ev.chan_id = chan->chan_id; in disconnected_cb()
162 if (!bt_conn_get_info(l2cap_chan->conn, &info)) { in disconnected_cb()
174 chan->in_use = false; in disconnected_cb()
189 ev.chan_id = chan->chan_id; in reconfigured_cb()
190 ev.mtu_remote = sys_cpu_to_le16(chan->le.tx.mtu); in reconfigured_cb()
191 ev.mps_remote = sys_cpu_to_le16(chan->le.tx.mps); in reconfigured_cb()
192 ev.mtu_local = sys_cpu_to_le16(chan->le.rx.mtu); in reconfigured_cb()
193 ev.mps_local = sys_cpu_to_le16(chan->le.rx.mps); in reconfigured_cb()
218 for (i = 0U; i < CHANNELS; i++) { in get_free_channel()
219 if (channels[i].in_use) { in get_free_channel()
223 chan = &channels[i]; in get_free_channel()
226 chan->chan_id = i; in get_free_channel()
228 channels[i].in_use = true; in get_free_channel()
244 uint16_t mtu = sys_le16_to_cpu(cp->mtu); in connect()
245 uint16_t psm = sys_le16_to_cpu(cp->psm); in connect()
247 bool ecfc = cp->options & BTP_L2CAP_CONNECT_OPT_ECFC; in connect()
250 if (cp->num == 0 || cp->num > CHANNELS || mtu > DATA_MTU_INITIAL) { in connect()
254 conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); in connect()
259 for (i = 0U; i < cp->num; i++) { in connect()
264 chan->le.chan.ops = &l2cap_ops; in connect()
265 chan->le.rx.mtu = mtu; in connect()
267 chan->le.rx.mps = L2CAP_MPS; in connect()
269 rp->chan_id[i] = chan->chan_id; in connect()
270 allocated_channels[i] = &chan->le.chan; in connect()
272 chan->hold_credit = cp->options & BTP_L2CAP_CONNECT_OPT_HOLD_CREDIT; in connect()
274 bt_l2cap_chan_give_credits(&chan->le.chan, 1); in connect()
277 if (cp->num == 1 && !ecfc) { in connect()
278 err = bt_l2cap_chan_connect(conn, &chan->le.chan, psm); in connect()
293 LOG_ERR("Invalid 'num' parameter value"); in connect()
297 rp->num = cp->num; in connect()
298 *rsp_len = sizeof(*rp) + (rp->num * sizeof(rp->chan_id[0])); in connect()
305 channels[BT_L2CAP_LE_CHAN(allocated_channels[i])->ident].in_use = false; in connect()
318 if (cp->chan_id >= CHANNELS) { in disconnect()
322 chan = &channels[cp->chan_id]; in disconnect()
324 err = bt_l2cap_chan_disconnect(&chan->le.chan); in disconnect()
341 struct bt_l2cap_chan *reconf_channels[CHANNELS + 1] = {}; in reconfigure()
344 cmd_len != sizeof(*cp) + cp->num) { in reconfigure()
348 if (cp->num > CHANNELS) { in reconfigure()
352 mtu = sys_le16_to_cpu(cp->mtu); in reconfigure()
357 for (int i = 0; i < cp->num; i++) { in reconfigure()
358 if (cp->chan_id[i] > CHANNELS) { in reconfigure()
362 reconf_channels[i] = &channels[cp->chan_id[i]].le.chan; in reconfigure()
365 conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); in reconfigure()
372 err = bt_l2cap_ecred_chan_reconfigure_explicit(reconf_channels, cp->num, mtu, mps); in reconfigure()
391 conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); in disconnect_eatt_chans()
397 for (int i = 0; i < cp->count; i++) { in disconnect_eatt_chans()
421 cmd_len != sizeof(*cp) + sys_le16_to_cpu(cp->data_len)) { in send_data()
425 if (cp->chan_id >= CHANNELS) { in send_data()
429 chan = &channels[cp->chan_id]; in send_data()
430 data_len = sys_le16_to_cpu(cp->data_len); in send_data()
439 if (data_len > chan->le.tx.mtu) { in send_data()
446 net_buf_add_mem(buf, cp->data, data_len); in send_data()
447 ret = bt_l2cap_chan_send(&chan->le.chan, buf); in send_data()
449 LOG_ERR("Unable to send data: %d", -ret); in send_data()
491 return -EPERM; in accept()
495 return -EACCES; in accept()
500 return -ENOMEM; in accept()
503 chan->le.chan.ops = &l2cap_ops; in accept()
504 chan->le.rx.mtu = DATA_MTU_INITIAL; in accept()
506 chan->le.rx.mps = L2CAP_MPS; in accept()
509 *l2cap_chan = &chan->le.chan; in accept()
511 bt_l2cap_chan_give_credits(&chan->le.chan, 1); in accept()
521 uint16_t psm = sys_le16_to_cpu(cp->psm); in listen()
523 /* TODO: Handle cmd->transport flag */ in listen()
534 server->accept = accept; in listen()
535 server->psm = psm; in listen()
537 switch (cp->response) { in listen()
548 server->sec_level = BT_SECURITY_L3; in listen()
551 server->sec_level = BT_SECURITY_L2; in listen()
558 server->psm = 0U; in listen()
571 if (cp->chan_id >= CHANNELS) { in credits()
575 chan = &channels[cp->chan_id]; in credits()
577 if (!chan->in_use) { in credits()
581 if (chan->pending_credits) { in credits()
582 if (bt_l2cap_chan_give_credits(&chan->le.chan, chan->pending_credits) < 0) { in credits()
586 chan->pending_credits = 0; in credits()
589 if (chan->pending_credit) { in credits()
590 if (bt_l2cap_chan_recv_complete(&chan->le.chan, in credits()
591 chan->pending_credit) < 0) { in credits()
595 chan->pending_credit = NULL; in credits()
608 tester_set_bit(rp->data, BTP_L2CAP_READ_SUPPORTED_COMMANDS); in supported_commands()
609 tester_set_bit(rp->data, BTP_L2CAP_CONNECT); in supported_commands()
610 tester_set_bit(rp->data, BTP_L2CAP_DISCONNECT); in supported_commands()
611 tester_set_bit(rp->data, BTP_L2CAP_SEND_DATA); in supported_commands()
612 tester_set_bit(rp->data, BTP_L2CAP_LISTEN); in supported_commands()
614 tester_set_bit(rp->data, BTP_L2CAP_RECONFIGURE); in supported_commands()
617 tester_set_bit(rp->data, BTP_L2CAP_CREDITS); in supported_commands()
619 tester_set_bit(rp->data, BTP_L2CAP_DISCONNECT_EATT_CHANS); in supported_commands()