mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-29 12:32:54 +00:00
l2cap-ertm: move retransmission and monitor timers into l2cap_channel, extract l2cap_ertm_start_retransmission_timer and l2cap_ertm_start_monitor_timer
This commit is contained in:
parent
db9a684459
commit
c9300dca9a
37
src/l2cap.c
37
src/l2cap.c
@ -113,6 +113,7 @@ static inline l2cap_service_t * l2cap_le_get_service(uint16_t psm);
|
|||||||
#ifdef ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE
|
#ifdef ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE
|
||||||
static void l2cap_ertm_notify_channel_can_send(l2cap_channel_t * channel);
|
static void l2cap_ertm_notify_channel_can_send(l2cap_channel_t * channel);
|
||||||
static int l2cap_ertm_num_unacknowledged_tx_packets(l2cap_channel_t * channel);
|
static int l2cap_ertm_num_unacknowledged_tx_packets(l2cap_channel_t * channel);
|
||||||
|
static void l2cap_ertm_monitor_timeout_callback(btstack_timer_source_t * ts);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct l2cap_fixed_channel {
|
typedef struct l2cap_fixed_channel {
|
||||||
@ -605,6 +606,15 @@ static void l2cap_ertm_next_tx_write_index(l2cap_channel_t * channel){
|
|||||||
if (channel->tx_write_index < channel->num_tx_buffers) return;
|
if (channel->tx_write_index < channel->num_tx_buffers) return;
|
||||||
channel->tx_write_index = 0;
|
channel->tx_write_index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void l2cap_ertm_start_monitor_timer(l2cap_channel_t * channel){
|
||||||
|
btstack_run_loop_remove_timer(&channel->monitor_timer);
|
||||||
|
btstack_run_loop_set_timer_handler(&channel->monitor_timer, &l2cap_ertm_monitor_timeout_callback);
|
||||||
|
btstack_run_loop_set_timer_context(&channel->monitor_timer, channel);
|
||||||
|
btstack_run_loop_set_timer(&channel->monitor_timer, channel->local_monitor_timeout_ms);
|
||||||
|
btstack_run_loop_add_timer(&channel->monitor_timer);
|
||||||
|
}
|
||||||
|
|
||||||
static void l2cap_ertm_monitor_timeout_callback(btstack_timer_source_t * ts){
|
static void l2cap_ertm_monitor_timeout_callback(btstack_timer_source_t * ts){
|
||||||
log_info("l2cap_ertm_monitor_timeout_callback");
|
log_info("l2cap_ertm_monitor_timeout_callback");
|
||||||
l2cap_channel_t * l2cap_channel = (l2cap_channel_t *) btstack_run_loop_get_timer_context(ts);
|
l2cap_channel_t * l2cap_channel = (l2cap_channel_t *) btstack_run_loop_get_timer_context(ts);
|
||||||
@ -618,11 +628,7 @@ static void l2cap_ertm_monitor_timeout_callback(btstack_timer_source_t * ts){
|
|||||||
// increment retry count
|
// increment retry count
|
||||||
tx_state->retry_count++;
|
tx_state->retry_count++;
|
||||||
|
|
||||||
// start monitor timer
|
l2cap_ertm_start_monitor_timer(l2cap_channel);
|
||||||
btstack_run_loop_set_timer_handler(&tx_state->monitor_timer, &l2cap_ertm_monitor_timeout_callback);
|
|
||||||
btstack_run_loop_set_timer_context(&tx_state->monitor_timer, l2cap_channel);
|
|
||||||
btstack_run_loop_set_timer(&tx_state->monitor_timer, l2cap_channel->local_monitor_timeout_ms);
|
|
||||||
btstack_run_loop_add_timer(&tx_state->monitor_timer);
|
|
||||||
|
|
||||||
// send RR/P=1
|
// send RR/P=1
|
||||||
l2cap_channel->send_supervisor_frame_receiver_ready_poll = 1;
|
l2cap_channel->send_supervisor_frame_receiver_ready_poll = 1;
|
||||||
@ -644,10 +650,7 @@ static void l2cap_ertm_retransmission_timeout_callback(btstack_timer_source_t *
|
|||||||
tx_state->retry_count = 1;
|
tx_state->retry_count = 1;
|
||||||
|
|
||||||
// start monitor timer
|
// start monitor timer
|
||||||
btstack_run_loop_set_timer_handler(&tx_state->monitor_timer, &l2cap_ertm_monitor_timeout_callback);
|
l2cap_ertm_start_monitor_timer(l2cap_channel);
|
||||||
btstack_run_loop_set_timer_context(&tx_state->monitor_timer, l2cap_channel);
|
|
||||||
btstack_run_loop_set_timer(&tx_state->monitor_timer, l2cap_channel->local_monitor_timeout_ms);
|
|
||||||
btstack_run_loop_add_timer(&tx_state->monitor_timer);
|
|
||||||
|
|
||||||
// send RR/P=1
|
// send RR/P=1
|
||||||
l2cap_channel->send_supervisor_frame_receiver_ready_poll = 1;
|
l2cap_channel->send_supervisor_frame_receiver_ready_poll = 1;
|
||||||
@ -665,6 +668,14 @@ static int l2cap_ertm_send_information_frame(l2cap_channel_t * channel, int inde
|
|||||||
return l2cap_send_prepared(channel->local_cid, 2 + tx_state->len);
|
return l2cap_send_prepared(channel->local_cid, 2 + tx_state->len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void l2cap_ertm_start_retransmission_timer(l2cap_channel_t * channel){
|
||||||
|
btstack_run_loop_remove_timer(&channel->retransmission_timer);
|
||||||
|
btstack_run_loop_set_timer_handler(&channel->retransmission_timer, &l2cap_ertm_retransmission_timeout_callback);
|
||||||
|
btstack_run_loop_set_timer_context(&channel->retransmission_timer, channel);
|
||||||
|
btstack_run_loop_set_timer(&channel->retransmission_timer, channel->local_retransmission_timeout_ms);
|
||||||
|
btstack_run_loop_add_timer(&channel->retransmission_timer);
|
||||||
|
}
|
||||||
|
|
||||||
static void l2cap_ertm_store_fragment(l2cap_channel_t * channel, l2cap_segmentation_and_reassembly_t sar, uint16_t sdu_length, uint8_t * data, uint16_t len){
|
static void l2cap_ertm_store_fragment(l2cap_channel_t * channel, l2cap_segmentation_and_reassembly_t sar, uint16_t sdu_length, uint8_t * data, uint16_t len){
|
||||||
// get next index for storing packets
|
// get next index for storing packets
|
||||||
int index = channel->tx_write_index;
|
int index = channel->tx_write_index;
|
||||||
@ -687,11 +698,7 @@ static void l2cap_ertm_store_fragment(l2cap_channel_t * channel, l2cap_segmentat
|
|||||||
channel->next_tx_seq = l2cap_next_ertm_seq_nr(channel->next_tx_seq);
|
channel->next_tx_seq = l2cap_next_ertm_seq_nr(channel->next_tx_seq);
|
||||||
l2cap_ertm_next_tx_write_index(channel);
|
l2cap_ertm_next_tx_write_index(channel);
|
||||||
|
|
||||||
// set retransmission timer
|
l2cap_ertm_start_retransmission_timer(channel);
|
||||||
btstack_run_loop_set_timer_handler(&tx_state->retransmission_timer, &l2cap_ertm_retransmission_timeout_callback);
|
|
||||||
btstack_run_loop_set_timer_context(&tx_state->retransmission_timer, channel);
|
|
||||||
btstack_run_loop_set_timer(&tx_state->retransmission_timer, channel->local_retransmission_timeout_ms);
|
|
||||||
btstack_run_loop_add_timer(&tx_state->retransmission_timer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l2cap_ertm_send(l2cap_channel_t * channel, uint8_t * data, uint16_t len){
|
static int l2cap_ertm_send(l2cap_channel_t * channel, uint8_t * data, uint16_t len){
|
||||||
@ -1960,7 +1967,7 @@ static void l2cap_ertm_handle_req_seq(l2cap_channel_t * l2cap_channel, uint8_t r
|
|||||||
log_info("RR seq %u => packet with tx_seq %u done", req_seq, tx_state->tx_seq);
|
log_info("RR seq %u => packet with tx_seq %u done", req_seq, tx_state->tx_seq);
|
||||||
|
|
||||||
// stop retransmission timer
|
// stop retransmission timer
|
||||||
btstack_run_loop_remove_timer(&tx_state->retransmission_timer);
|
btstack_run_loop_remove_timer(&l2cap_channel->retransmission_timer);
|
||||||
l2cap_channel->tx_read_index++;
|
l2cap_channel->tx_read_index++;
|
||||||
if (l2cap_channel->tx_read_index >= l2cap_channel->num_rx_buffers){
|
if (l2cap_channel->tx_read_index >= l2cap_channel->num_rx_buffers){
|
||||||
l2cap_channel->tx_read_index = 0;
|
l2cap_channel->tx_read_index = 0;
|
||||||
|
@ -122,8 +122,6 @@ typedef struct {
|
|||||||
} l2cap_ertm_rx_packet_state_t;
|
} l2cap_ertm_rx_packet_state_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
btstack_timer_source_t retransmission_timer;
|
|
||||||
btstack_timer_source_t monitor_timer;
|
|
||||||
l2cap_segmentation_and_reassembly_t sar;
|
l2cap_segmentation_and_reassembly_t sar;
|
||||||
uint16_t len;
|
uint16_t len;
|
||||||
uint8_t tx_seq;
|
uint8_t tx_seq;
|
||||||
@ -201,6 +199,12 @@ typedef struct {
|
|||||||
// l2cap channel mode: basic or enhanced retransmission mode
|
// l2cap channel mode: basic or enhanced retransmission mode
|
||||||
l2cap_channel_mode_t mode;
|
l2cap_channel_mode_t mode;
|
||||||
|
|
||||||
|
// retransmission timer
|
||||||
|
btstack_timer_source_t retransmission_timer;
|
||||||
|
|
||||||
|
// monitor timer
|
||||||
|
btstack_timer_source_t monitor_timer;
|
||||||
|
|
||||||
// local/remote config options
|
// local/remote config options
|
||||||
uint16_t local_retransmission_timeout_ms;
|
uint16_t local_retransmission_timeout_ms;
|
||||||
uint16_t local_monitor_timeout_ms;
|
uint16_t local_monitor_timeout_ms;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user