add l2cap_max_le_mtu

This commit is contained in:
matthias.ringwald@gmail.com 2014-08-14 15:36:00 +00:00
parent ee303eddf0
commit e5e1518d8a
5 changed files with 19 additions and 12 deletions

View File

@ -123,7 +123,7 @@ static void att_event_packet_handler (uint8_t packet_type, uint16_t channel, uin
bt_flip_addr(att_client_address, &packet[8]);
// reset connection properties
att_connection.con_handle = READ_BT_16(packet, 4);
att_connection.mtu = ATT_DEFAULT_MTU;
att_connection.mtu = l2cap_max_le_mtu();
att_connection.encryption_key_size = 0;
att_connection.authenticated = 0;
att_connection.authorized = 0;

View File

@ -95,14 +95,6 @@ int gatt_client_is_ready(gatt_client_t *context){
return context->gatt_client_state == P_READY;
}
// START Helper Functions - to be sorted
static uint16_t l2cap_max_mtu_for_handle(uint16_t handle){
return l2cap_max_mtu();
}
// END Helper Functions
// precondition: can_send_packet_now == TRUE
static void att_confirmation(uint16_t peripheral_handle){
l2cap_reserve_packet_buffer();
@ -574,7 +566,6 @@ gatt_client_t * get_gatt_client_context_for_handle(uint16_t handle){
static void gatt_client_run(){
linked_item_t *it;
for (it = (linked_item_t *) gatt_client_connections; it ; it = it->next){
@ -587,7 +578,7 @@ static void gatt_client_run(){
switch (peripheral->mtu_state) {
case SEND_MTU_EXCHANGE:{
peripheral->mtu_state = SENT_MTU_EXCHANGE;
uint16_t mtu = l2cap_max_mtu_for_handle(peripheral->handle);
uint16_t mtu = l2cap_max_le_mtu();
// TODO: extract as att_exchange_mtu_request
l2cap_reserve_packet_buffer();
uint8_t * request = l2cap_get_outgoing_buffer();
@ -773,7 +764,7 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle,
case ATT_EXCHANGE_MTU_RESPONSE:
{
uint16_t remote_rx_mtu = READ_BT_16(packet, 1);
uint16_t local_rx_mtu = l2cap_max_mtu_for_handle(handle);
uint16_t local_rx_mtu = l2cap_max_le_mtu());
peripheral->mtu = remote_rx_mtu < local_rx_mtu ? remote_rx_mtu : local_rx_mtu;
peripheral->mtu_state = MTU_EXCHANGED;
break;

View File

@ -73,9 +73,15 @@ void l2cap_init(){
}
uint16_t l2cap_max_mtu(void){
int classic_acl_lenght = hci_max_acl_data_packet_length();
if (classic_acl_lenght == 0) return 0;
return hci_max_acl_data_packet_length() - L2CAP_HEADER_SIZE;
}
uint16_t l2cap_max_le_mtu(){
return L2CAP_LE_DEFAULT_MTU;
}
/** Register L2CAP packet handlers */
void l2cap_register_packet_handler(void (*handler)(void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)){
packet_handler = handler;

View File

@ -682,10 +682,17 @@ void l2cap_run(void){
}
}
uint16_t l2cap_max_mtu(void){
int classic_acl_lenght = hci_max_acl_data_packet_length();
if (classic_acl_lenght == 0) return 0;
return hci_max_acl_data_packet_length() - L2CAP_HEADER_SIZE;
}
uint16_t l2cap_max_le_mtu(){
return L2CAP_LE_DEFAULT_MTU;
}
static void l2cap_handle_connection_complete(uint16_t handle, l2cap_channel_t * channel){
if (channel->state == L2CAP_STATE_WAIT_CONNECTION_COMPLETE || channel->state == L2CAP_STATE_WILL_SEND_CREATE_CONNECTION) {
log_info("l2cap_handle_connection_complete expected state");

View File

@ -65,6 +65,9 @@ extern "C" {
#define L2CAP_MINIMAL_MTU 48
#define L2CAP_DEFAULT_MTU 672
// Minimum/default MTU
#define L2CAP_LE_DEFAULT_MTU 23
// check L2CAP MTU
#if (L2CAP_MINIMAL_MTU + L2CAP_HEADER_SIZE) > HCI_ACL_PAYLOAD_SIZE
#error "HCI_ACL_PAYLOAD_SIZE too small for minimal L2CAP MTU of 48 bytes"