#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) |
#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) |
Referenced by l2cap_notify_channel_can_send().
#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 |
Referenced by l2cap_acl_classic_handler().
#define L2CAP_SIGNALING_COMMAND_LENGTH_OFFSET 2 |
Referenced by l2cap_acl_classic_handler().
#define L2CAP_SIGNALING_COMMAND_SIGID_OFFSET 1 |
#define NR_BUFFERED_ACL_PACKETS 3 |
#define NR_PENDING_SIGNALING_RESPONSES 3 |
Referenced by l2cap_register_signaling_response().
typedef struct l2cap_fixed_channel l2cap_fixed_channel_t |
|
static |
References callback, l2cap_fixed_channel::callback, COMPLETE_L2CAP_HEADER, L2CAP_CHANNEL_MODE_ENHANCED_RETRANSMISSION, L2CAP_CID_CONNECTIONLESS_CHANNEL, L2CAP_CID_SIGNALING, L2CAP_DATA_PACKET, L2CAP_FIXED_CHANNEL_TABLE_INDEX_CONNECTIONLESS_CHANNEL, L2CAP_SIGNALING_COMMAND_DATA_OFFSET, L2CAP_SIGNALING_COMMAND_LENGTH_OFFSET, L2CAP_SUPERVISORY_FUNCTION_REJ_REJECT, L2CAP_SUPERVISORY_FUNCTION_RNR_RECEIVER_NOT_READY, L2CAP_SUPERVISORY_FUNCTION_RR_RECEIVER_READY, L2CAP_SUPERVISORY_FUNCTION_SREJ_SELECTIVE_REJECT, l2cap_ertm_rx_packet_state_t::len, little_endian_read_16(), log_error, log_info, READ_L2CAP_CHANNEL_ID, l2cap_ertm_tx_packet_state_t::retransmission_requested, l2cap_ertm_rx_packet_state_t::sar, tx_state, UCD_DATA_PACKET, UNUSED, and l2cap_ertm_rx_packet_state_t::valid.
Referenced by l2cap_acl_handler().
|
static |
|
static |
References ATT_DATA_PACKET, l2cap_channel_t::automatic_credits, callback, l2cap_fixed_channel::callback, COMMAND_REJECT_LE, COMPLETE_L2CAP_HEADER, l2cap_channel_t::credits_incoming, L2CAP_CID_ATTRIBUTE_PROTOCOL, L2CAP_CID_SECURITY_MANAGER_PROTOCOL, L2CAP_CID_SIGNALING_LE, L2CAP_DATA_PACKET, L2CAP_FIXED_CHANNEL_TABLE_INDEX_ATTRIBUTE_PROTOCOL, L2CAP_FIXED_CHANNEL_TABLE_INDEX_SECURITY_MANAGER_PROTOCOL, L2CAP_LE_DATA_CHANNELS_AUTOMATIC_CREDITS_INCREMENT, L2CAP_LE_DATA_CHANNELS_AUTOMATIC_CREDITS_WATERMARK, l2cap_register_signaling_response(), L2CAP_REJ_CMD_UNKNOWN, L2CAP_STATE_WILL_SEND_DISCONNECT_REQUEST, little_endian_read_16(), l2cap_channel_t::local_mtu, log_error, log_info, l2cap_channel_t::new_credits_incoming, READ_L2CAP_CHANNEL_ID, l2cap_channel_t::receive_sdu_buffer, l2cap_channel_t::receive_sdu_len, l2cap_channel_t::receive_sdu_pos, SM_DATA_PACKET, l2cap_channel_t::state, and UNUSED.
Referenced by l2cap_acl_handler().
int l2cap_can_send_fixed_channel_packet_now | ( | hci_con_handle_t | con_handle, |
uint16_t | channel_id | ||
) |
References hci_can_send_acl_packet_now(), and UNUSED.
Referenced by att_dispatch_client_can_send_now(), att_dispatch_server_can_send_now(), and sm_run().
|
static |
References hci_dump_packet(), HCI_EVENT_PACKET, L2CAP_EVENT_CAN_SEND_NOW, little_endian_store_16(), log_debug, and packet_handler.
Referenced by l2cap_notify_channel_can_send().
|
static |
References L2CAP_CID_ATTRIBUTE_PROTOCOL, L2CAP_CID_CONNECTIONLESS_CHANNEL, L2CAP_CID_SECURITY_MANAGER_PROTOCOL, L2CAP_FIXED_CHANNEL_TABLE_INDEX_ATTRIBUTE_PROTOCOL, L2CAP_FIXED_CHANNEL_TABLE_INDEX_CONNECTIONLESS_CHANNEL, and L2CAP_FIXED_CHANNEL_TABLE_INDEX_SECURITY_MANAGER_PROTOCOL.
Referenced by l2cap_notify_channel_can_send().
|
static |
References L2CAP_CID_ATTRIBUTE_PROTOCOL, L2CAP_CID_CONNECTIONLESS_CHANNEL, L2CAP_CID_SECURITY_MANAGER_PROTOCOL, L2CAP_FIXED_CHANNEL_TABLE_INDEX_ATTRIBUTE_PROTOCOL, L2CAP_FIXED_CHANNEL_TABLE_INDEX_CONNECTIONLESS_CHANNEL, and L2CAP_FIXED_CHANNEL_TABLE_INDEX_SECURITY_MANAGER_PROTOCOL.
Referenced by l2cap_register_fixed_channel(), and l2cap_request_can_send_fix_channel_now_event().
|
static |
References L2CAP_CID_CONNECTIONLESS_CHANNEL.
Referenced by l2cap_notify_channel_can_send().
uint8_t* l2cap_get_outgoing_buffer | ( | void | ) |
Get outgoing buffer and prepare data.
References COMPLETE_L2CAP_HEADER, and hci_get_outgoing_packet_buffer().
Referenced by att_confirmation(), att_exchange_mtu_request(), att_execute_write_request(), att_find_by_type_value_request(), att_find_information_request(), att_prepare_write_request(), att_read_blob_request(), att_read_by_type_or_group_request_for_uuid128(), att_read_by_type_or_group_request_for_uuid16(), att_read_multiple_request(), att_read_request(), att_server_indicate(), att_server_notify(), att_server_process_validated_request(), and att_write_request().
|
static |
References btstack_linked_list_iterator_has_next(), btstack_linked_list_iterator_init(), btstack_linked_list_iterator_next(), btstack_linked_list_iterator_remove(), l2cap_channel_t::con_handle, GAP_CONNECTION_ACL, GAP_EVENT_SECURITY_LEVEL, gap_get_connection_type(), hci_authentication_active_for_handle(), hci_can_send_command_packet_now(), hci_connection_for_handle(), hci_create_connection_cancel, hci_disconnect, hci_disconnect_security_block(), HCI_EVENT_COMMAND_COMPLETE, HCI_EVENT_COMMAND_STATUS, HCI_EVENT_CONNECTION_COMPLETE, HCI_EVENT_DISCONNECTION_COMPLETE, HCI_EVENT_IS_COMMAND_COMPLETE, HCI_EVENT_NUMBER_OF_COMPLETED_PACKETS, hci_event_packet_get_type(), HCI_EVENT_READ_REMOTE_SUPPORTED_FEATURES_COMPLETE, HCI_EVENT_TRANSPORT_PACKET_SENT, hci_send_cmd(), L2CAP_EVENT_TIMEOUT_CHECK, l2cap_notify_channel_can_send(), l2cap_run(), L2CAP_STATE_WAIT_CLIENT_ACCEPT_OR_REJECT, L2CAP_STATE_WAIT_INCOMING_EXTENDED_FEATURES, L2CAP_STATE_WAIT_INCOMING_SECURITY_LEVEL_UPDATE, L2CAP_STATE_WAIT_OUTGOING_SECURITY_LEVEL_UPDATE, L2CAP_STATE_WILL_SEND_CONNECTION_RESPONSE_DECLINE, little_endian_read_16(), log_info, l2cap_channel_t::reason, l2cap_channel_t::required_security_level, reverse_bd_addr(), l2cap_channel_t::state, and UNUSED.
Referenced by l2cap_init().
void l2cap_init | ( | void | ) |
Set up L2CAP and register L2CAP with HCI layer.
References btstack_packet_callback_registration_t::callback, gap_connectable_control(), hci_add_event_handler(), hci_register_acl_packet_handler(), l2cap_acl_handler(), l2cap_hci_event_handler(), NULL, and signaling_responses_pending.
Referenced by le_counter_setup(), le_prov_app_setup(), and tss_app_setup().
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().
|
static |
References btstack_linked_list_iterator_has_next(), btstack_linked_list_iterator_init(), btstack_linked_list_iterator_next(), callback, l2cap_channel_t::con_handle, hci_can_send_acl_classic_packet_now(), hci_can_send_acl_le_packet_now(), hci_can_send_acl_packet_now(), l2cap_emit_can_send_now(), l2cap_fixed_channel_table_channel_id_for_index(), l2cap_fixed_channel_table_index_is_le(), L2CAP_FIXED_CHANNEL_TABLE_SIZE, l2cap_channel_t::local_cid, l2cap_channel_t::packet_handler, l2cap_fixed_channel::waiting_for_can_send_now, and l2cap_channel_t::waiting_for_can_send_now.
Referenced by l2cap_hci_event_handler(), and l2cap_request_can_send_fix_channel_now_event().
void l2cap_register_fixed_channel | ( | btstack_packet_handler_t | the_packet_handler, |
uint16_t | channel_id | ||
) |
References l2cap_fixed_channel::callback, and l2cap_fixed_channel_table_index_for_channel_id().
Referenced by att_dispatch_register_client(), att_dispatch_register_server(), and sm_init().
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_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().
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.
References hci_reserve_packet_buffer().
Referenced by att_confirmation(), att_exchange_mtu_request(), att_execute_write_request(), att_find_by_type_value_request(), att_find_information_request(), att_prepare_write_request(), att_read_blob_request(), att_read_by_type_or_group_request_for_uuid128(), att_read_by_type_or_group_request_for_uuid16(), att_read_multiple_request(), att_read_request(), att_server_indicate(), att_server_notify(), att_server_process_validated_request(), and att_write_request().
|
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 | ||
) |
References BTSTACK_ACL_BUFFERS_FULL, hci_can_send_acl_packet_now(), hci_get_outgoing_packet_buffer(), hci_reserve_packet_buffer(), l2cap_send_prepared_connectionless(), and log_info.
Referenced by sm_run().
int l2cap_send_prepared_connectionless | ( | hci_con_handle_t | con_handle, |
uint16_t | cid, | ||
uint16_t | len | ||
) |
References BTSTACK_ACL_BUFFERS_FULL, hci_can_send_prepared_acl_packet_now(), hci_get_outgoing_packet_buffer(), hci_is_packet_buffer_reserved(), hci_send_acl_packet_buffer(), l2cap_setup_header(), log_debug, log_error, and log_info.
Referenced by att_confirmation(), att_exchange_mtu_request(), att_execute_write_request(), att_find_by_type_value_request(), att_find_information_request(), att_prepare_write_request(), att_read_blob_request(), att_read_by_type_or_group_request_for_uuid128(), att_read_by_type_or_group_request_for_uuid16(), att_read_multiple_request(), att_read_request(), att_server_indicate(), att_server_notify(), att_server_process_validated_request(), att_write_request(), and l2cap_send_connectionless().
|
static |
References little_endian_store_16().
Referenced by l2cap_run(), and l2cap_send_prepared_connectionless().
|
static |
|
static |
|
static |
|
static |
Referenced by l2cap_init(), l2cap_register_signaling_response(), and l2cap_run().