test/pts/l2cap_cbm_ecbm: use unified functinos

This commit is contained in:
Matthias Ringwald 2021-11-22 12:38:51 +01:00
parent d2bf13739d
commit 372dd7ce8a

View File

@ -104,9 +104,8 @@ static int todo_send_long;
// note: must be smaller than TSPX_tester_mtu for l2cap/le/cfc/bv-02-c to succeed // note: must be smaller than TSPX_tester_mtu for l2cap/le/cfc/bv-02-c to succeed
static uint8_t buffer_x[500]; static uint8_t buffer_x[500];
static uint16_t cid_le;
static uint16_t cid_classic; static uint16_t cid_classic;
static uint16_t cid_enhanced; static uint16_t cid_credit_based;
uint8_t receive_buffer_X[100]; uint8_t receive_buffer_X[100];
@ -134,7 +133,6 @@ static void app_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *
hci_con_handle_t handle; hci_con_handle_t handle;
uint16_t cids[2]; uint16_t cids[2];
uint8_t status; uint8_t status;
uint16_t mps, mtu;
switch (packet_type) { switch (packet_type) {
@ -191,16 +189,7 @@ static void app_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *
enhanced_data_channel = false; enhanced_data_channel = false;
printf("L2CAP: Classic Channel successfully opened: %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n", printf("L2CAP: Classic Channel successfully opened: %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n",
bd_addr_to_str(event_address), handle, psm, cid, l2cap_event_channel_opened_get_remote_cid(packet)); bd_addr_to_str(event_address), handle, psm, cid, l2cap_event_channel_opened_get_remote_cid(packet));
switch (psm){ cid_classic = cid;
case TSPX_LE_PSM:
cid_le = cid;
break;
case TSPX_PSM:
cid_classic = cid;
break;
default:
break;
}
} else { } else {
printf("L2CAP: classic connection to device %s failed. status code %u\n", bd_addr_to_str(event_address), packet[2]); printf("L2CAP: classic connection to device %s failed. status code %u\n", bd_addr_to_str(event_address), packet[2]);
} }
@ -230,16 +219,7 @@ static void app_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *
enhanced_data_channel = false; enhanced_data_channel = false;
printf("L2CAP: LE Data Channel successfully opened: %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n", printf("L2CAP: LE Data Channel successfully opened: %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n",
bd_addr_to_str(event_address), handle, psm, cid, little_endian_read_16(packet, 15)); bd_addr_to_str(event_address), handle, psm, cid, little_endian_read_16(packet, 15));
switch (psm){ cid_credit_based = cid;
case TSPX_LE_PSM:
cid_le = cid;
break;
case TSPX_PSM:
cid_classic = cid;
break;
default:
break;
}
} else { } else {
printf("L2CAP: LE Data Channel connection to device %s failed. status code %u\n", bd_addr_to_str(event_address), packet[2]); printf("L2CAP: LE Data Channel connection to device %s failed. status code %u\n", bd_addr_to_str(event_address), packet[2]);
} }
@ -248,21 +228,16 @@ static void app_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *
case L2CAP_EVENT_CBM_CAN_SEND_NOW: case L2CAP_EVENT_CBM_CAN_SEND_NOW:
if (todo_send_short){ if (todo_send_short){
todo_send_short = 0; todo_send_short = 0;
if (enhanced_data_channel){ l2cap_send(cid_credit_based, (uint8_t *) data_short, strlen(data_short));
l2cap_ecbm_send_data(cid_enhanced, (uint8_t *) data_short, strlen(data_short));
} else {
l2cap_cbm_send_data(cid_le, (uint8_t *) data_short, strlen(data_short));
}
break; break;
} }
if (todo_send_long){ if (todo_send_long){
todo_send_long = 0; todo_send_long = 0;
if (enhanced_data_channel){ if (enhanced_data_channel){
// l2cap_ecbm_send_data(cid_enhanced, (uint8_t *) data_long, strlen(data_long));
memset(receive_buffer_X, 0x33, enhanced_remote_mtu); memset(receive_buffer_X, 0x33, enhanced_remote_mtu);
l2cap_ecbm_send_data(cid_enhanced, (uint8_t *) receive_buffer_X, enhanced_remote_mtu); l2cap_send(cid_credit_based, (uint8_t *) receive_buffer_X, enhanced_remote_mtu);
} else { } else {
l2cap_cbm_send_data(cid_le, (uint8_t *) data_long, strlen(data_long)); l2cap_send(cid_credit_based, (uint8_t *) data_long, strlen(data_long));
} }
} }
break; break;
@ -282,14 +257,14 @@ static void app_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *
cid = l2cap_event_data_channel_opened_get_local_cid(packet); cid = l2cap_event_data_channel_opened_get_local_cid(packet);
status = l2cap_event_channel_opened_get_status(packet); status = l2cap_event_channel_opened_get_status(packet);
if (l2cap_event_channel_opened_get_status(packet) == 0){ if (l2cap_event_channel_opened_get_status(packet) == 0){
cid_enhanced = cid; cid_credit_based = cid;
enhanced_remote_mtu = l2cap_event_data_channel_opened_get_remote_mtu(packet); enhanced_remote_mtu = l2cap_event_data_channel_opened_get_remote_mtu(packet);
} }
printf("L2CAP_EVENT_ECBM_CHANNEL_OPENED - cid 0x%04x mtu %u, status 0x%02x\n", cid, enhanced_remote_mtu, status); printf("L2CAP_EVENT_ECBM_CHANNEL_OPENED - cid 0x%04x mtu %u, status 0x%02x\n", cid, enhanced_remote_mtu, status);
break; break;
case L2CAP_EVENT_ECBM_INCOMING_CONNECTION: case L2CAP_EVENT_ECBM_INCOMING_CONNECTION:
printf("L2CAP_EVENT_ECBM_INCOMING_CONNECTION - remote mtu %u\n", mtu); printf("L2CAP_EVENT_ECBM_INCOMING_CONNECTION\n");
cid = l2cap_event_data_channel_incoming_get_local_cid(packet); cid = l2cap_event_data_channel_incoming_get_local_cid(packet);
if (enhanced_authorization_required){ if (enhanced_authorization_required){
enhanced_authorization_required = false; enhanced_authorization_required = false;
@ -407,13 +382,13 @@ static void stdin_process(char buffer){
case 'b': case 'b':
printf("Connect to PSM 0x%02x - CFC LE\n", TSPX_LE_PSM); printf("Connect to PSM 0x%02x - CFC LE\n", TSPX_LE_PSM);
l2cap_cbm_create_channel(&app_packet_handler, handle_le, TSPX_LE_PSM, buffer_x, l2cap_cbm_create_channel(&app_packet_handler, handle_le, TSPX_LE_PSM, buffer_x,
sizeof(buffer_x), L2CAP_LE_AUTOMATIC_CREDITS, LEVEL_0, &cid_le); sizeof(buffer_x), L2CAP_LE_AUTOMATIC_CREDITS, LEVEL_0, &cid_credit_based);
break; break;
case 'B': case 'B':
printf("Creating connection to %s 0x%02x - CFC LE\n", bd_addr_to_str(pts_address), TSPX_PSM_UNSUPPORTED); printf("Creating connection to %s 0x%02x - CFC LE\n", bd_addr_to_str(pts_address), TSPX_PSM_UNSUPPORTED);
l2cap_cbm_create_channel(&app_packet_handler, handle_le, TSPX_PSM_UNSUPPORTED, buffer_x, l2cap_cbm_create_channel(&app_packet_handler, handle_le, TSPX_PSM_UNSUPPORTED, buffer_x,
sizeof(buffer_x), L2CAP_LE_AUTOMATIC_CREDITS, LEVEL_0, &cid_le); sizeof(buffer_x), L2CAP_LE_AUTOMATIC_CREDITS, LEVEL_0, &cid_credit_based);
break; break;
case 'd': case 'd':
@ -441,9 +416,9 @@ static void stdin_process(char buffer){
case 'c': case 'c':
printf("Provide 10 credits\n"); printf("Provide 10 credits\n");
if (enhanced_data_channel){ if (enhanced_data_channel){
l2cap_ecbm_provide_credits(cid_enhanced, 10); l2cap_ecbm_provide_credits(cid_credit_based, 10);
} else { } else {
l2cap_cbm_provide_credits(cid_le, 10); l2cap_cbm_provide_credits(cid_credit_based, 10);
} }
break; break;
@ -475,7 +450,7 @@ static void stdin_process(char buffer){
case 'r': case 'r':
printf("Reconfigure MTU = %u, MPS = %u\n", ENHANCED_MTU_RECONFIGURE, enhanced_reconfigure_mps[enhanced_reconfigure_index]); printf("Reconfigure MTU = %u, MPS = %u\n", ENHANCED_MTU_RECONFIGURE, enhanced_reconfigure_mps[enhanced_reconfigure_index]);
l2cap_ecbm_mps_set_max(enhanced_reconfigure_mps[enhanced_reconfigure_index++]); l2cap_ecbm_mps_set_max(enhanced_reconfigure_mps[enhanced_reconfigure_index++]);
l2cap_ecbm_reconfigure_channels(1, &cid_enhanced, ENHANCED_MTU_RECONFIGURE, receive_buffers_2); l2cap_ecbm_reconfigure_channels(1, &cid_credit_based, ENHANCED_MTU_RECONFIGURE, receive_buffers_2);
if (enhanced_reconfigure_index == enhanced_reconfigure_choices){ if (enhanced_reconfigure_index == enhanced_reconfigure_choices){
enhanced_reconfigure_index = 0; enhanced_reconfigure_index = 0;
} }
@ -484,21 +459,13 @@ static void stdin_process(char buffer){
case 's': case 's':
printf("Send L2CAP Data Short %s\n", data_short); printf("Send L2CAP Data Short %s\n", data_short);
todo_send_short = 1; todo_send_short = 1;
if (enhanced_data_channel){ l2cap_request_can_send_now_event(cid_credit_based);
l2cap_ecbm_request_can_send_now_event(cid_enhanced);
} else {
l2cap_cbm_request_can_send_now_event(cid_le);
}
break; break;
case 'S': case 'S':
printf("Send L2CAP Data Long %s\n", data_long); printf("Send L2CAP Data Long %s\n", data_long);
todo_send_long = 1; todo_send_long = 1;
if (enhanced_data_channel){ l2cap_request_can_send_now_event(cid_credit_based);
l2cap_ecbm_request_can_send_now_event(cid_enhanced);
} else {
l2cap_cbm_request_can_send_now_event(cid_le);
}
break; break;
case 'y': case 'y':
@ -512,13 +479,8 @@ static void stdin_process(char buffer){
break; break;
case 't': case 't':
if (enhanced_data_channel){ printf("Disconnect channel 0x%02x\n", cid_credit_based);
printf("Disconnect channel 0x%02x\n", cid_enhanced); l2cap_disconnect(cid_credit_based);
l2cap_disconnect(cid_enhanced);
} else {
printf("Disconnect channel 0x%02x\n", cid_le);
l2cap_disconnect(cid_le);
}
break; break;
default: default: