mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-15 23:42:52 +00:00
l2ap-ertm: send retransmission and flow control option when channel accepted with l2cap_accept_ertm_connection
This commit is contained in:
parent
5f78701e41
commit
43ec931d38
56
src/l2cap.c
56
src/l2cap.c
@ -655,7 +655,7 @@ static void l2cap_run(void){
|
||||
UNUSED(it);
|
||||
|
||||
#ifdef ENABLE_CLASSIC
|
||||
uint8_t config_options[4];
|
||||
uint8_t config_options[10];
|
||||
btstack_linked_list_iterator_init(&it, &l2cap_channels);
|
||||
while (btstack_linked_list_iterator_has_next(&it)){
|
||||
|
||||
@ -733,10 +733,30 @@ static void l2cap_run(void){
|
||||
channelStateVarClearFlag(channel, L2CAP_CHANNEL_STATE_VAR_SEND_CONF_REQ);
|
||||
channelStateVarSetFlag(channel, L2CAP_CHANNEL_STATE_VAR_SENT_CONF_REQ);
|
||||
channel->local_sig_id = l2cap_next_sig_id();
|
||||
config_options[0] = 1; // MTU
|
||||
config_options[1] = 2; // len param
|
||||
little_endian_store_16( (uint8_t*)&config_options, 2, channel->local_mtu);
|
||||
l2cap_send_signaling_packet(channel->con_handle, CONFIGURE_REQUEST, channel->local_sig_id, channel->remote_cid, 0, 4, &config_options);
|
||||
int send_retransmission_and_flow_control_option = 0;
|
||||
#ifdef ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE
|
||||
if (channel->mode == L2CAP_CHANNEL_MODE_ENHANCED_RETRANSMISSION){
|
||||
send_retransmission_and_flow_control_option = 1;
|
||||
}
|
||||
#endif
|
||||
if (send_retransmission_and_flow_control_option){
|
||||
#ifdef ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE
|
||||
config_options[0] = 0x04; // RETRANSMISSION AND FLOW CONTROL OPTION
|
||||
config_options[1] = 9; // length
|
||||
config_options[2] = (uint8_t) channel->mode;
|
||||
config_options[3] = 1; // TxWindows size
|
||||
config_options[4] = 1; // max retransmit
|
||||
little_endian_store_16( config_options, 5, 100); // Retransmission timeout: 100 ms
|
||||
little_endian_store_16( config_options, 5, 300); // Monitor timeout: 300 ms
|
||||
little_endian_store_16( config_options, 7, channel->local_mtu); // Max PDU size
|
||||
l2cap_send_signaling_packet(channel->con_handle, CONFIGURE_REQUEST, channel->local_sig_id, channel->remote_cid, 0, 10, &config_options);
|
||||
#endif
|
||||
} else {
|
||||
config_options[0] = 1; // MTU
|
||||
config_options[1] = 2; // len param
|
||||
little_endian_store_16( (uint8_t*)&config_options, 2, channel->local_mtu);
|
||||
l2cap_send_signaling_packet(channel->con_handle, CONFIGURE_REQUEST, channel->local_sig_id, channel->remote_cid, 0, 4, &config_options);
|
||||
}
|
||||
l2cap_start_rtx(channel);
|
||||
}
|
||||
if (l2cap_channel_ready_for_open(channel)){
|
||||
@ -1324,12 +1344,38 @@ void l2cap_accept_connection(uint16_t local_cid){
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE
|
||||
// configure L2CAP Basic mode
|
||||
channel->mode = L2CAP_CHANNEL_MODE_BASIC;
|
||||
#endif
|
||||
|
||||
channel->state = L2CAP_STATE_WILL_SEND_CONNECTION_RESPONSE_ACCEPT;
|
||||
|
||||
// process
|
||||
l2cap_run();
|
||||
}
|
||||
|
||||
|
||||
#ifdef ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE
|
||||
void l2cap_accept_ertm_connection(uint16_t local_cid){
|
||||
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) {
|
||||
log_error("l2cap_accept_connection called but local_cid 0x%x not found", local_cid);
|
||||
return;
|
||||
}
|
||||
|
||||
// configure L2CAP ERTM
|
||||
channel->mode = L2CAP_CHANNEL_MODE_ENHANCED_RETRANSMISSION;
|
||||
|
||||
channel->state = L2CAP_STATE_WILL_SEND_CONNECTION_RESPONSE_ACCEPT;
|
||||
|
||||
// process
|
||||
l2cap_run();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void l2cap_decline_connection(uint16_t local_cid){
|
||||
log_info("L2CAP_DECLINE_CONNECTION local_cid 0x%x", local_cid);
|
||||
l2cap_channel_t * channel = l2cap_get_channel_for_local_cid( local_cid);
|
||||
|
11
src/l2cap.h
11
src/l2cap.h
@ -176,6 +176,10 @@ typedef struct {
|
||||
// automatic credits incoming
|
||||
uint16_t automatic_credits;
|
||||
|
||||
#ifdef ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE
|
||||
// l2cap channel mode: basic or enhanced retransmission mode
|
||||
l2cap_channel_mode_t mode;
|
||||
#endif
|
||||
} l2cap_channel_t;
|
||||
|
||||
// info regarding potential connections
|
||||
@ -274,7 +278,7 @@ int l2cap_send(uint16_t local_cid, uint8_t *data, uint16_t len);
|
||||
uint8_t l2cap_register_service(btstack_packet_handler_t packet_handler, uint16_t psm, uint16_t mtu, gap_security_level_t security_level);
|
||||
|
||||
/**
|
||||
* @brief Unregisters L2CAP service with given PSM. On embedded systems, use NULL for connection parameter.
|
||||
* @brief Unregisters L2CAP service with given PSM.
|
||||
*/
|
||||
uint8_t l2cap_unregister_service(uint16_t psm);
|
||||
|
||||
@ -283,6 +287,11 @@ uint8_t l2cap_unregister_service(uint16_t psm);
|
||||
*/
|
||||
void l2cap_accept_connection(uint16_t local_cid);
|
||||
|
||||
/**
|
||||
* @brief Accepts incoming L2CAP connection for Enhanced Retransmission Mode
|
||||
*/
|
||||
void l2cap_accept_ertm_connection(uint16_t local_cid);
|
||||
|
||||
/**
|
||||
* @brief Deny incoming L2CAP connection.
|
||||
*/
|
||||
|
@ -74,6 +74,14 @@ typedef enum {
|
||||
COMMAND_REJECT_LE = 0x1F // internal to BTstack
|
||||
} L2CAP_SIGNALING_COMMANDS;
|
||||
|
||||
typedef enum {
|
||||
L2CAP_CHANNEL_MODE_BASIC = 0,
|
||||
L2CAP_CHANNEL_MODE_RETRANSMISSION = 1,
|
||||
L2CAP_CHANNEL_MODE_FLOW_CONTROL = 2,
|
||||
L2CAP_CHANNEL_MODE_ENHANCED_RETRANSMISSION = 3,
|
||||
L2CAP_CHANNEL_MODE_STREAMING_MODE = 4,
|
||||
} l2cap_channel_mode_t;
|
||||
|
||||
uint16_t l2cap_create_signaling_classic(uint8_t * acl_buffer,hci_con_handle_t handle, L2CAP_SIGNALING_COMMANDS cmd, uint8_t identifier, va_list argptr);
|
||||
uint16_t l2cap_create_signaling_le(uint8_t * acl_buffer, hci_con_handle_t handle, L2CAP_SIGNALING_COMMANDS cmd, uint8_t identifier, va_list argptr);
|
||||
uint8_t l2cap_next_sig_id(void);
|
||||
|
@ -67,6 +67,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 btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||
|
||||
@ -101,10 +102,16 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
printf("L2CAP connection to device %s failed. status code %u\n", bd_addr_to_str(event_addr), packet[2]);
|
||||
}
|
||||
break;
|
||||
|
||||
case L2CAP_EVENT_INCOMING_CONNECTION: {
|
||||
uint16_t l2cap_cid = little_endian_read_16(packet, 12);
|
||||
printf("L2CAP Accepting incoming connection request\n");
|
||||
l2cap_accept_connection(l2cap_cid);
|
||||
if (l2cap_ertm){
|
||||
printf("L2CAP Accepting incoming connection request in Basic Mode\n");
|
||||
l2cap_accept_ertm_connection(l2cap_cid);
|
||||
} else {
|
||||
printf("L2CAP Accepting incoming connection request in ERTM\n");
|
||||
l2cap_accept_connection(l2cap_cid);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -116,9 +123,11 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
|
||||
static void show_usage(void){
|
||||
printf("\n--- CLI for L2CAP TEST ---\n");
|
||||
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("d - disconnect\n");
|
||||
printf("Ctrl-c - exit\n");
|
||||
printf("---\n");
|
||||
@ -142,6 +151,10 @@ static void stdin_process(char buffer){
|
||||
printf("L2CAP Channel Closed\n");
|
||||
l2cap_disconnect(local_cid, 0);
|
||||
break;
|
||||
case 'E':
|
||||
printf("L2CAP Enhanced Retransmission Mode (ERTM) enabled\n");
|
||||
l2cap_ertm = 1;
|
||||
break;
|
||||
case '\n':
|
||||
case '\r':
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user