Microchip® Advanced Software Framework

l2cap.c File Reference
#include "l2cap.h"
#include "hci.h"
#include "hci_dump.h"
#include "bluetooth_sdp.h"
#include "btstack_debug.h"
#include "btstack_event.h"
#include "btstack_memory.h"
#include <stdarg.h>
#include <string.h>
#include <stdio.h>

Data Structures

struct  l2cap_fixed_channel
 

Macros

#define __BTSTACK_FILE__   "l2cap.c"
 
#define L2CAP_FIXED_CHANNEL_TABLE_INDEX_ATTRIBUTE_PROTOCOL   0
 
#define L2CAP_FIXED_CHANNEL_TABLE_INDEX_CONNECTIONLESS_CHANNEL   2
 
#define L2CAP_FIXED_CHANNEL_TABLE_INDEX_SECURITY_MANAGER_PROTOCOL   1
 
#define L2CAP_FIXED_CHANNEL_TABLE_SIZE   (L2CAP_FIXED_CHANNEL_TABLE_INDEX_CONNECTIONLESS_CHANNEL+1)
 
#define L2CAP_LE_DATA_CHANNELS_AUTOMATIC_CREDITS_INCREMENT   5
 
#define L2CAP_LE_DATA_CHANNELS_AUTOMATIC_CREDITS_WATERMARK   5
 
#define L2CAP_SIGNALING_COMMAND_CODE_OFFSET   0
 
#define L2CAP_SIGNALING_COMMAND_DATA_OFFSET   4
 
#define L2CAP_SIGNALING_COMMAND_LENGTH_OFFSET   2
 
#define L2CAP_SIGNALING_COMMAND_SIGID_OFFSET   1
 
#define NR_BUFFERED_ACL_PACKETS   3
 
#define NR_PENDING_SIGNALING_RESPONSES   3
 

Typedefs

typedef struct l2cap_fixed_channel l2cap_fixed_channel_t
 

Functions

static void l2cap_acl_classic_handler (hci_con_handle_t handle, uint8_t *packet, uint16_t size)
 
static void l2cap_acl_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)
 
static void l2cap_acl_le_handler (hci_con_handle_t handle, uint8_t *packet, uint16_t size)
 
int l2cap_can_send_fixed_channel_packet_now (hci_con_handle_t con_handle, uint16_t channel_id)
 
static void l2cap_emit_can_send_now (btstack_packet_handler_t packet_handler, uint16_t channel)
 
static uint16_t l2cap_fixed_channel_table_channel_id_for_index (int index)
 
static int l2cap_fixed_channel_table_index_for_channel_id (uint16_t channel_id)
 
static int l2cap_fixed_channel_table_index_is_le (int index)
 
uint8_t * l2cap_get_outgoing_buffer (void)
 Get outgoing buffer and prepare data. More...
 
static void l2cap_hci_event_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)
 
void l2cap_init (void)
 Set up L2CAP and register L2CAP with HCI layer. More...
 
uint16_t l2cap_max_le_mtu (void)
 Get max MTU for LE connections based on btstack configuration. More...
 
uint16_t l2cap_max_mtu (void)
 Get max MTU for Classic connections based on btstack configuration. More...
 
static void l2cap_notify_channel_can_send (void)
 
void l2cap_register_fixed_channel (btstack_packet_handler_t the_packet_handler, uint16_t channel_id)
 
void l2cap_register_packet_handler (void(*handler)(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size))
 Registers packet handler for LE Connection Parameter Update events. More...
 
static void l2cap_register_signaling_response (hci_con_handle_t handle, uint8_t code, uint8_t sig_id, uint16_t cid, uint16_t data)
 
void l2cap_release_packet_buffer (void)
 Release outgoing buffer (only needed if l2cap_send_prepared is not called) More...
 
void l2cap_request_can_send_fix_channel_now_event (hci_con_handle_t con_handle, uint16_t channel_id)
 
int l2cap_reserve_packet_buffer (void)
 Reserve outgoing buffer. More...
 
static void l2cap_run (void)
 
int l2cap_send_connectionless (hci_con_handle_t con_handle, uint16_t cid, uint8_t *data, uint16_t len)
 
int l2cap_send_prepared_connectionless (hci_con_handle_t con_handle, uint16_t cid, uint16_t len)
 
static void l2cap_setup_header (uint8_t *acl_buffer, hci_con_handle_t con_handle, uint8_t packet_boundary, uint16_t remote_cid, uint16_t len)
 

Variables

static l2cap_fixed_channel_t fixed_channels [L2CAP_FIXED_CHANNEL_TABLE_SIZE]
 
static
btstack_packet_callback_registration_t 
hci_event_callback_registration
 
static l2cap_signaling_response_t signaling_responses [NR_PENDING_SIGNALING_RESPONSES]
 
static int signaling_responses_pending
 

#define __BTSTACK_FILE__   "l2cap.c"
#define L2CAP_FIXED_CHANNEL_TABLE_INDEX_ATTRIBUTE_PROTOCOL   0
#define L2CAP_FIXED_CHANNEL_TABLE_INDEX_CONNECTIONLESS_CHANNEL   2
#define L2CAP_FIXED_CHANNEL_TABLE_INDEX_SECURITY_MANAGER_PROTOCOL   1
#define L2CAP_FIXED_CHANNEL_TABLE_SIZE   (L2CAP_FIXED_CHANNEL_TABLE_INDEX_CONNECTIONLESS_CHANNEL+1)
#define L2CAP_LE_DATA_CHANNELS_AUTOMATIC_CREDITS_INCREMENT   5

Referenced by l2cap_acl_le_handler().

#define L2CAP_LE_DATA_CHANNELS_AUTOMATIC_CREDITS_WATERMARK   5

Referenced by l2cap_acl_le_handler().

#define L2CAP_SIGNALING_COMMAND_CODE_OFFSET   0
#define L2CAP_SIGNALING_COMMAND_DATA_OFFSET   4
#define L2CAP_SIGNALING_COMMAND_LENGTH_OFFSET   2
#define L2CAP_SIGNALING_COMMAND_SIGID_OFFSET   1
#define NR_BUFFERED_ACL_PACKETS   3
#define NR_PENDING_SIGNALING_RESPONSES   3

static void l2cap_acl_handler ( uint8_t  packet_type,
uint16_t  channel,
uint8_t *  packet,
uint16_t  size 
)
static
int l2cap_can_send_fixed_channel_packet_now ( hci_con_handle_t  con_handle,
uint16_t  channel_id 
)
static void l2cap_emit_can_send_now ( btstack_packet_handler_t  packet_handler,
uint16_t  channel 
)
static
static int l2cap_fixed_channel_table_index_is_le ( int  index)
static
uint16_t l2cap_max_le_mtu ( void  )

Get max MTU for LE connections based on btstack configuration.

References l2cap_max_mtu().

Referenced by att_event_packet_handler(), att_exchange_mtu_request(), gatt_client_att_packet_handler(), and peripheral_mtu().

uint16_t l2cap_max_mtu ( void  )

Get max MTU for Classic connections based on btstack configuration.

References L2CAP_HEADER_SIZE.

Referenced by l2cap_max_le_mtu().

void l2cap_register_fixed_channel ( btstack_packet_handler_t  the_packet_handler,
uint16_t  channel_id 
)
void l2cap_register_packet_handler ( void(*)(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)  handler)

Registers packet handler for LE Connection Parameter Update events.

References UNUSED.

static void l2cap_register_signaling_response ( hci_con_handle_t  handle,
uint8_t  code,
uint8_t  sig_id,
uint16_t  cid,
uint16_t  data 
)
static
void l2cap_release_packet_buffer ( void  )

Release outgoing buffer (only needed if l2cap_send_prepared is not called)

References hci_release_packet_buffer().

Referenced by att_server_process_validated_request().

static void l2cap_run ( void  )
static

References l2cap_channel_t::address, hci_connection_t::address_type, BD_ADDR_TYPE_LE_PUBLIC, BD_ADDR_TYPE_LE_RANDOM, btstack_linked_list_iterator_has_next(), btstack_linked_list_iterator_init(), btstack_linked_list_iterator_next(), btstack_linked_list_iterator_remove(), btstack_memory_l2cap_channel_free(), btstack_min(), l2cap_signaling_response::cid, l2cap_signaling_response::code, COMMAND_REJECT, COMMAND_REJECT_LE, l2cap_channel_t::con_handle, hci_connection_t::con_handle, CON_PARAMETER_UPDATE_CHANGE_HCI_CON_PARAMETERS, CON_PARAMETER_UPDATE_DENY, CON_PARAMETER_UPDATE_NONE, CON_PARAMETER_UPDATE_SEND_REQUEST, CON_PARAMETER_UPDATE_SEND_RESPONSE, CONFIGURE_REQUEST, CONFIGURE_RESPONSE, CONNECTION_PARAMETER_UPDATE_REQUEST, CONNECTION_PARAMETER_UPDATE_RESPONSE, CONNECTION_REQUEST, CONNECTION_RESPONSE, l2cap_channel_t::credits_incoming, l2cap_channel_t::credits_outgoing, l2cap_signaling_response::data, DISCONNECTION_REQUEST, DISCONNECTION_RESPONSE, ECHO_REQUEST, ECHO_RESPONSE, l2cap_signaling_response::handle, hci_can_send_acl_packet_now(), hci_can_send_command_packet_now(), hci_connections_get_iterator(), hci_create_connection, hci_disconnect_security_block(), hci_get_outgoing_packet_buffer(), hci_max_acl_data_packet_length(), hci_reserve_packet_buffer(), hci_send_acl_packet_buffer(), hci_send_cmd(), hci_usable_acl_packet_types(), INFORMATION_REQUEST, INFORMATION_RESPONSE, L2CAP_CHANNEL_STATE_VAR_SEND_CONF_REQ, L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP, L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP_CONT, L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP_INVALID, L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP_MTU, L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP_REJECTED, L2CAP_CHANNEL_STATE_VAR_SEND_CONN_RESP_PEND, L2CAP_CHANNEL_STATE_VAR_SENT_CONF_REQ, L2CAP_CHANNEL_STATE_VAR_SENT_CONF_RSP, L2CAP_CONF_RESULT_SUCCESS, L2CAP_CONF_RESULT_UNACCEPTABLE_PARAMETERS, L2CAP_CONF_RESULT_UNKNOWN_OPTIONS, L2CAP_EVENT_LE_PACKET_SENT, L2CAP_INFO_TYPE_CONNECTIONLESS_MTU, L2CAP_INFO_TYPE_EXTENDED_FEATURES_SUPPORTED, L2CAP_INFO_TYPE_FIXED_CHANNELS_SUPPORTED, l2cap_next_sig_id(), l2cap_setup_header(), L2CAP_STATE_CONFIG, L2CAP_STATE_INVALID, L2CAP_STATE_OPEN, L2CAP_STATE_WAIT_CLIENT_ACCEPT_OR_REJECT, L2CAP_STATE_WAIT_CONNECT_RSP, L2CAP_STATE_WAIT_CONNECTION_COMPLETE, L2CAP_STATE_WAIT_DISCONNECT, L2CAP_STATE_WAIT_INCOMING_SECURITY_LEVEL_UPDATE, L2CAP_STATE_WAIT_LE_CONNECTION_RESPONSE, L2CAP_STATE_WILL_SEND_CONNECTION_REQUEST, L2CAP_STATE_WILL_SEND_CONNECTION_RESPONSE_ACCEPT, L2CAP_STATE_WILL_SEND_CONNECTION_RESPONSE_DECLINE, L2CAP_STATE_WILL_SEND_CREATE_CONNECTION, L2CAP_STATE_WILL_SEND_DISCONNECT_REQUEST, L2CAP_STATE_WILL_SEND_DISCONNECT_RESPONSE, L2CAP_STATE_WILL_SEND_LE_CONNECTION_REQUEST, L2CAP_STATE_WILL_SEND_LE_CONNECTION_RESPONSE_ACCEPT, L2CAP_STATE_WILL_SEND_LE_CONNECTION_RESPONSE_DECLINE, L2CAP_SUPERVISORY_FUNCTION_REJ_REJECT, L2CAP_SUPERVISORY_FUNCTION_RNR_RECEIVER_NOT_READY, L2CAP_SUPERVISORY_FUNCTION_RR_RECEIVER_READY, L2CAP_SUPERVISORY_FUNCTION_SREJ_SELECTIVE_REJECT, hci_connection_t::le_con_param_update_identifier, hci_connection_t::le_con_parameter_update_state, hci_connection_t::le_conn_interval_max, hci_connection_t::le_conn_interval_min, hci_connection_t::le_conn_latency, LE_CREDIT_BASED_CONNECTION_REQUEST, LE_CREDIT_BASED_CONNECTION_RESPONSE, LE_FLOW_CONTROL_CREDIT, hci_connection_t::le_supervision_timeout, little_endian_store_16(), l2cap_channel_t::local_cid, l2cap_channel_t::local_mtu, l2cap_channel_t::local_sig_id, log_info, l2cap_channel_t::new_credits_incoming, NULL, l2cap_channel_t::psm, l2cap_channel_t::reason, l2cap_channel_t::remote_cid, l2cap_channel_t::remote_mps, l2cap_channel_t::remote_sig_id, l2cap_ertm_tx_packet_state_t::retransmission_requested, l2cap_channel_t::send_sdu_buffer, l2cap_channel_t::send_sdu_len, l2cap_channel_t::send_sdu_pos, l2cap_signaling_response::sig_id, signaling_responses_pending, source_cid, l2cap_channel_t::state, and l2cap_channel_t::state_var.

Referenced by l2cap_acl_handler(), l2cap_hci_event_handler(), and l2cap_register_signaling_response().

int l2cap_send_connectionless ( hci_con_handle_t  con_handle,
uint16_t  cid,
uint8_t *  data,
uint16_t  len 
)
static void l2cap_setup_header ( uint8_t *  acl_buffer,
hci_con_handle_t  con_handle,
uint8_t  packet_boundary,
uint16_t  remote_cid,
uint16_t  len 
)
static

btstack_packet_callback_registration_t hci_event_callback_registration
static
int signaling_responses_pending
static