mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-17 02:42:33 +00:00
l2cap-ertm: add ertm_mandatory flag to create and accept connection
This commit is contained in:
parent
3232a1c67c
commit
45caebe58e
@ -1077,7 +1077,7 @@ uint8_t l2cap_create_channel(btstack_packet_handler_t channel_packet_handler, bd
|
||||
}
|
||||
|
||||
#ifdef ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE
|
||||
uint8_t l2cap_create_ertm_channel(btstack_packet_handler_t channel_packet_handler, bd_addr_t address, uint16_t psm, uint16_t mtu, uint16_t * out_local_cid){
|
||||
uint8_t l2cap_create_ertm_channel(btstack_packet_handler_t channel_packet_handler, bd_addr_t address, uint16_t psm, uint16_t mtu, int ertm_mandatory, uint16_t * out_local_cid){
|
||||
// limit MTU to the size of our outtgoing HCI buffer
|
||||
uint16_t local_mtu = btstack_min(mtu, l2cap_max_mtu());
|
||||
|
||||
@ -1089,7 +1089,7 @@ uint8_t l2cap_create_ertm_channel(btstack_packet_handler_t channel_packet_handle
|
||||
}
|
||||
|
||||
channel->mode = L2CAP_CHANNEL_MODE_ENHANCED_RETRANSMISSION;
|
||||
channel->ertm_mandatory = 1;
|
||||
channel->ertm_mandatory = ertm_mandatory;
|
||||
|
||||
// add to connections list
|
||||
btstack_linked_list_add(&l2cap_channels, (btstack_linked_item_t *) channel);
|
||||
@ -1447,7 +1447,7 @@ void l2cap_accept_connection(uint16_t local_cid){
|
||||
|
||||
|
||||
#ifdef ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE
|
||||
void l2cap_accept_ertm_connection(uint16_t local_cid){
|
||||
void l2cap_accept_ertm_connection(uint16_t local_cid, int ertm_mandatory){
|
||||
log_info("L2CAP_ACCEPT_ERTM_CONNECTION local_cid 0x%x", local_cid);
|
||||
l2cap_channel_t * channel = l2cap_get_channel_for_local_cid(local_cid);
|
||||
if (!channel) {
|
||||
@ -1457,7 +1457,7 @@ void l2cap_accept_ertm_connection(uint16_t local_cid){
|
||||
|
||||
// configure L2CAP ERTM
|
||||
channel->mode = L2CAP_CHANNEL_MODE_ENHANCED_RETRANSMISSION;
|
||||
channel->ertm_mandatory = 1;
|
||||
channel->ertm_mandatory = ertm_mandatory;
|
||||
|
||||
channel->state = L2CAP_STATE_WILL_SEND_CONNECTION_RESPONSE_ACCEPT;
|
||||
|
||||
|
@ -266,10 +266,11 @@ uint8_t l2cap_create_channel(btstack_packet_handler_t packet_handler, bd_addr_t
|
||||
* @param address
|
||||
* @param psm
|
||||
* @param mtu
|
||||
* @param ertm_mandatory If not mandatory, the use of ERTM can be decided by the remote
|
||||
* @param local_cid
|
||||
* @return status
|
||||
*/
|
||||
uint8_t l2cap_create_ertm_channel(btstack_packet_handler_t packet_handler, bd_addr_t address, uint16_t psm, uint16_t mtu, uint16_t * out_local_cid);
|
||||
uint8_t l2cap_create_ertm_channel(btstack_packet_handler_t packet_handler, bd_addr_t address, uint16_t psm, uint16_t mtu, int ertm_mandatory, uint16_t * out_local_cid);
|
||||
|
||||
/**
|
||||
* @brief Disconnects L2CAP channel with given identifier.
|
||||
@ -303,8 +304,9 @@ void l2cap_accept_connection(uint16_t local_cid);
|
||||
|
||||
/**
|
||||
* @brief Accepts incoming L2CAP connection for Enhanced Retransmission Mode
|
||||
* @param ertm_mandatory If not mandatory, the use of ERTM can be decided by the remote
|
||||
*/
|
||||
void l2cap_accept_ertm_connection(uint16_t local_cid);
|
||||
void l2cap_accept_ertm_connection(uint16_t local_cid, int ertm_mandatory);
|
||||
|
||||
/**
|
||||
* @brief Deny incoming L2CAP connection.
|
||||
|
@ -68,6 +68,7 @@ static bd_addr_t remote = {0x00, 0x1B, 0xDC, 0x07, 0x32, 0xef};;
|
||||
static uint16_t handle;
|
||||
static uint16_t local_cid;
|
||||
static int l2cap_ertm;
|
||||
static int l2cap_ertm_mandatory;
|
||||
|
||||
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||
|
||||
@ -110,7 +111,7 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
uint16_t l2cap_cid = little_endian_read_16(packet, 12);
|
||||
if (l2cap_ertm){
|
||||
printf("L2CAP Accepting incoming connection request in ERTM\n");
|
||||
l2cap_accept_ertm_connection(l2cap_cid);
|
||||
l2cap_accept_ertm_connection(l2cap_cid, l2cap_ertm_mandatory);
|
||||
} else {
|
||||
printf("L2CAP Accepting incoming connection request in Basic Mode\n");
|
||||
l2cap_accept_connection(l2cap_cid);
|
||||
@ -129,8 +130,9 @@ static void show_usage(void){
|
||||
printf("L2CAP Channel Mode %s\n", l2cap_ertm ? "Enahnced Retransmission" : "Basic");
|
||||
printf("c - create connection to SDP at addr %s\n", bd_addr_to_str(remote));
|
||||
printf("s - send data\n");
|
||||
printf("e - send echo request\n");
|
||||
printf("E - enable ERTM mode\n");
|
||||
printf("p - send echo request\n");
|
||||
printf("e - optional ERTM mode\n");
|
||||
printf("E - mandatory ERTM mode\n");
|
||||
printf("d - disconnect\n");
|
||||
printf("t - terminate ACL connection\n");
|
||||
printf("Ctrl-c - exit\n");
|
||||
@ -142,7 +144,7 @@ static void stdin_process(char buffer){
|
||||
case 'c':
|
||||
printf("Creating L2CAP Connection to %s, PSM SDP\n", bd_addr_to_str(remote));
|
||||
if (l2cap_ertm){
|
||||
l2cap_create_ertm_channel(packet_handler, remote, BLUETOOTH_PROTOCOL_SDP, 100, NULL);
|
||||
l2cap_create_ertm_channel(packet_handler, remote, BLUETOOTH_PROTOCOL_SDP, 100, l2cap_ertm_mandatory, NULL);
|
||||
} else {
|
||||
l2cap_create_channel(packet_handler, remote, BLUETOOTH_PROTOCOL_SDP, 100, NULL);
|
||||
}
|
||||
@ -151,19 +153,26 @@ static void stdin_process(char buffer){
|
||||
printf("Send L2CAP Data\n");
|
||||
l2cap_send(local_cid, (uint8_t *) "0123456789", 10);
|
||||
break;
|
||||
case 'e':
|
||||
printf("Send L2CAP ECHO Request\n");
|
||||
l2cap_send_echo_request(handle, (uint8_t *) "Hello World!", 13);
|
||||
break;
|
||||
case 'd':
|
||||
printf("L2CAP Channel Closed\n");
|
||||
l2cap_disconnect(local_cid, 0);
|
||||
break;
|
||||
case 'E':
|
||||
printf("L2CAP Enhanced Retransmission Mode (ERTM) enabled\n");
|
||||
case 'e':
|
||||
printf("L2CAP Enhanced Retransmission Mode (ERTM) optional\n");
|
||||
l2cap_ertm = 1;
|
||||
l2cap_ertm_mandatory = 0;
|
||||
break;
|
||||
case 'E':
|
||||
printf("L2CAP Enhanced Retransmission Mode (ERTM) mandatory\n");
|
||||
l2cap_ertm = 1;
|
||||
l2cap_ertm_mandatory = 1;
|
||||
break;
|
||||
case 'p':
|
||||
printf("Send L2CAP ECHO Request\n");
|
||||
l2cap_send_echo_request(handle, (uint8_t *) "Hello World!", 13);
|
||||
break;
|
||||
case 't':
|
||||
printf("Disconnect ACL handle\n");
|
||||
gap_disconnect(handle);
|
||||
break;
|
||||
case '\n':
|
||||
|
Loading…
x
Reference in New Issue
Block a user