diff --git a/platform/daemon/example/l2cap_server.c b/platform/daemon/example/l2cap_server.c index 8c5fbbb39..21e755d2f 100644 --- a/platform/daemon/example/l2cap_server.c +++ b/platform/daemon/example/l2cap_server.c @@ -61,7 +61,7 @@ uint16_t hid_interrupt = 0; void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ bd_addr_t event_addr; - uint16_t handle; + hci_con_handle_t con_handle; uint16_t psm; uint16_t local_cid; uint16_t remote_cid; @@ -112,12 +112,12 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint // data: event(8), len(8), address(48), handle (16), psm (16), source cid(16) dest cid(16) reverse_bd_addr(&packet[2], event_addr); - handle = little_endian_read_16(packet, 8); + con_handle = little_endian_read_16(packet, 8); psm = little_endian_read_16(packet, 10); local_cid = little_endian_read_16(packet, 12); remote_cid = little_endian_read_16(packet, 14); printf("L2CAP_EVENT_INCOMING_CONNECTION %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n", - bd_addr_to_str(event_addr), handle, psm, local_cid, remote_cid); + bd_addr_to_str(event_addr), con_handle, psm, local_cid, remote_cid); // accept bt_send_cmd(&l2cap_accept_connection_cmd, local_cid); @@ -150,10 +150,10 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint event_addr); psm = little_endian_read_16(packet, 11); local_cid = little_endian_read_16(packet, 13); - handle = little_endian_read_16(packet, 9); + con_handle = little_endian_read_16(packet, 9); if (packet[2] == 0) { printf("Channel successfully opened: %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n", - bd_addr_to_str(event_addr), handle, psm, local_cid, little_endian_read_16(packet, 15)); + bd_addr_to_str(event_addr), con_handle, psm, local_cid, little_endian_read_16(packet, 15)); if (psm == PSM_HID_CONTROL){ hid_control = local_cid; diff --git a/platform/daemon/example/l2cap_throughput.c b/platform/daemon/example/l2cap_throughput.c index 14323a2a3..2941b644c 100644 --- a/platform/daemon/example/l2cap_throughput.c +++ b/platform/daemon/example/l2cap_throughput.c @@ -80,7 +80,7 @@ void timer_handler(struct btstack_timer_source *ts){ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ bd_addr_t event_addr; - uint16_t handle; + hci_con_handle_t con_handle; uint16_t psm; uint16_t local_cid; char pin[20]; @@ -126,11 +126,11 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint // data: event(8), len(8), address(48), handle (16), psm (16), source cid(16) dest cid(16) reverse_bd_addr(&packet[2], event_addr); - handle = little_endian_read_16(packet, 8); + con_handle = little_endian_read_16(packet, 8); psm = little_endian_read_16(packet, 10); local_cid = little_endian_read_16(packet, 12); // remote_cid = little_endian_read_16(packet, 14); - printf("L2CAP_EVENT_INCOMING_CONNECTION %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x\n", bd_addr_to_str(event_addr), handle, psm, local_cid); + printf("L2CAP_EVENT_INCOMING_CONNECTION %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x\n", bd_addr_to_str(event_addr), con_handle, psm, local_cid); // accept bt_send_cmd(&l2cap_accept_connection_cmd, local_cid); break; @@ -163,10 +163,10 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint event_addr); psm = little_endian_read_16(packet, 11); local_cid = little_endian_read_16(packet, 13); - handle = little_endian_read_16(packet, 9); + con_handle = little_endian_read_16(packet, 9); if (packet[2] == 0) { printf("Channel successfully opened: %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n", - bd_addr_to_str(event_addr), handle, psm, local_cid, little_endian_read_16(packet, 15)); + bd_addr_to_str(event_addr), con_handle, psm, local_cid, little_endian_read_16(packet, 15)); } else { printf("L2CAP connection to device %s failed. status code %u\n", bd_addr_to_str(event_addr), packet[2]); } diff --git a/platform/daemon/src/daemon.c b/platform/daemon/src/daemon.c index e54ee0123..99f91b450 100644 --- a/platform/daemon/src/daemon.c +++ b/platform/daemon/src/daemon.c @@ -774,10 +774,10 @@ static void sdp_emit_service_registered(void *connection, uint32_t handle, uint8 #ifdef ENABLE_BLE -btstack_linked_list_gatt_client_helper_t * daemon_get_gatt_client_helper(uint16_t handle) { +btstack_linked_list_gatt_client_helper_t * daemon_get_gatt_client_helper(hci_con_handle_t con_handle) { btstack_linked_list_iterator_t it; if (!gatt_client_helpers) return NULL; - log_info("daemon_get_gatt_client_helper for handle 0x%02x", handle); + log_info("daemon_get_gatt_client_helper for handle 0x%02x", con_handle); btstack_linked_list_iterator_init(&it, &gatt_client_helpers); while (btstack_linked_list_iterator_has_next(&it)){ @@ -786,31 +786,31 @@ btstack_linked_list_gatt_client_helper_t * daemon_get_gatt_client_helper(uint16_ log_info("daemon_get_gatt_client_helper gatt_client_helpers null item"); break; } - if (item->con_handle == handle){ + if (item->con_handle == con_handle){ return item; } } - log_info("daemon_get_gatt_client_helper for handle 0x%02x is NULL.", handle); + log_info("daemon_get_gatt_client_helper for handle 0x%02x is NULL.", con_handle); return NULL; } -static void send_gatt_query_complete(connection_t * connection, uint16_t handle, uint8_t status){ +static void send_gatt_query_complete(connection_t * connection, hci_con_handle_t con_handle, uint8_t status){ // @format H1 uint8_t event[5]; event[0] = GATT_EVENT_QUERY_COMPLETE; event[1] = 3; - little_endian_store_16(event, 2, handle); + little_endian_store_16(event, 2, con_handle); event[4] = status; hci_dump_packet(HCI_EVENT_PACKET, 0, event, sizeof(event)); socket_connection_send_packet(connection, HCI_EVENT_PACKET, 0, event, sizeof(event)); } -static void send_gatt_mtu_event(connection_t * connection, uint16_t handle, uint16_t mtu){ +static void send_gatt_mtu_event(connection_t * connection, hci_con_handle_t con_handle, uint16_t mtu){ uint8_t event[6]; int pos = 0; event[pos++] = GATT_EVENT_MTU; event[pos++] = sizeof(event) - 2; - little_endian_store_16(event, pos, handle); + little_endian_store_16(event, pos, con_handle); pos += 2; little_endian_store_16(event, pos, mtu); pos += 2; @@ -819,31 +819,31 @@ static void send_gatt_mtu_event(connection_t * connection, uint16_t handle, uint } btstack_linked_list_gatt_client_helper_t * daemon_setup_gatt_client_request(connection_t *connection, uint8_t *packet, int track_active_connection) { - hci_con_handle_t handle = little_endian_read_16(packet, 3); - log_info("daemon_setup_gatt_client_request for handle 0x%02x", handle); - hci_connection_t * hci_con = hci_connection_for_handle(handle); + hci_con_handle_t con_handle = little_endian_read_16(packet, 3); + log_info("daemon_setup_gatt_client_request for handle 0x%02x", con_handle); + hci_connection_t * hci_con = hci_connection_for_handle(con_handle); if ((hci_con == NULL) || (hci_con->state != OPEN)){ - send_gatt_query_complete(connection, handle, GATT_CLIENT_NOT_CONNECTED); + send_gatt_query_complete(connection, con_handle, GATT_CLIENT_NOT_CONNECTED); return NULL; } - btstack_linked_list_gatt_client_helper_t * helper = daemon_get_gatt_client_helper(handle); + btstack_linked_list_gatt_client_helper_t * helper = daemon_get_gatt_client_helper(con_handle); if (!helper){ log_info("helper does not exist"); helper = malloc(sizeof(btstack_linked_list_gatt_client_helper_t)); if (!helper) return NULL; memset(helper, 0, sizeof(btstack_linked_list_gatt_client_helper_t)); - helper->con_handle = handle; + helper->con_handle = con_handle; btstack_linked_list_add(&gatt_client_helpers, (btstack_linked_item_t *) helper); } if (track_active_connection && helper->active_connection){ - send_gatt_query_complete(connection, handle, GATT_CLIENT_BUSY); + send_gatt_query_complete(connection, con_handle, GATT_CLIENT_BUSY); return NULL; } - daemon_add_gatt_client_handle(connection, handle); + daemon_add_gatt_client_handle(connection, con_handle); if (track_active_connection){ // remember connection responsible for this request @@ -1806,8 +1806,8 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint // we receive a HCI event packet in disguise if (packet[0] == HCI_EVENT_DISCONNECTION_COMPLETE){ log_info("daemon hack: handle disconnection_complete in handle_gatt_client_event instead of main hci event packet handler"); - uint16_t handle = little_endian_read_16(packet, 3); - daemon_remove_gatt_client_helper(handle); + hci_con_handle_t con_handle = little_endian_read_16(packet, 3); + daemon_remove_gatt_client_helper(con_handle); return; } diff --git a/port/arduino/BTstack.cpp b/port/arduino/BTstack.cpp index a9ed90100..3ac0b0fd2 100644 --- a/port/arduino/BTstack.cpp +++ b/port/arduino/BTstack.cpp @@ -129,7 +129,7 @@ extern "C" void hal_cpu_enable_irqs_and_sleep(void) { } static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ bd_addr_t addr; - uint16_t handle; + hci_con_handle_t con_handle; switch (packet_type) { @@ -148,8 +148,8 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack case HCI_EVENT_DISCONNECTION_COMPLETE: if (bleDeviceDisconnectedCallback) { - handle = little_endian_read_16(packet, 3); - BLEDevice device(handle); + con_handle = little_endian_read_16(packet, 3); + BLEDevice device(con_handle); (*bleDeviceDisconnectedCallback)(&device); } le_peripheral_todos |= SET_ADVERTISEMENT_ENABLED; @@ -174,14 +174,14 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack case HCI_EVENT_LE_META: switch (packet[2]) { case HCI_SUBEVENT_LE_CONNECTION_COMPLETE: - handle = little_endian_read_16(packet, 4); - printf("Connection complete, handle 0x%04x\n", handle); + con_handle = little_endian_read_16(packet, 4); + printf("Connection complete, con_handle 0x%04x\n", con_handle); btstack_run_loop_remove_timer(&connection_timer); if (!bleDeviceConnectedCallback) break; if (packet[3]){ (*bleDeviceConnectedCallback)(BLE_STATUS_CONNECTION_ERROR, NULL); } else { - BLEDevice device(handle); + BLEDevice device(con_handle); (*bleDeviceConnectedCallback)(BLE_STATUS_OK, &device); } break; @@ -222,7 +222,7 @@ static void gatt_client_callback(uint8_t packet_type, uint8_t * packet, uint16_t if (packet[0] < GATT_EVENT_QUERY_COMPLETE) return; if (packet[0] > GATT_EVENT_MTU) return; - uint16_t con_handle = little_endian_read_16(packet, 2); + hci_con_handle_t con_handle = little_endian_read_16(packet, 2); uint8_t status; uint8_t * value; uint16_t value_handle; @@ -526,7 +526,7 @@ const gatt_client_service_t * BLEService::getService(void){ // discovery of services and characteristics BLEDevice::BLEDevice(void){ } -BLEDevice::BLEDevice(uint16_t handle) +BLEDevice::BLEDevice(hci_con_handle_t handle) : handle(handle){ } uint16_t BLEDevice::getHandle(void){ diff --git a/port/daemon/example/Makefile.in b/port/daemon/example/Makefile.in index fac1a3dc3..a98e424f4 100644 --- a/port/daemon/example/Makefile.in +++ b/port/daemon/example/Makefile.in @@ -3,7 +3,7 @@ BTSTACK_ROOT=../../.. CC = @CC@ LDFLAGS = @LDFLAGS@ -lBTstack -L../src CFLAGS = @CFLAGS@ \ - -I$(BTSTACK_ROOT)/platform/daemon \ + -I$(BTSTACK_ROOT)/platform/daemon/src \ -I$(BTSTACK_ROOT)/platform/posix \ -I$(BTSTACK_ROOT)/src \ -I.. diff --git a/src/ble/att_db.c b/src/ble/att_db.c index 4d7035f31..6818f7d2f 100644 --- a/src/ble/att_db.c +++ b/src/ble/att_db.c @@ -152,9 +152,9 @@ static int att_find_handle(att_iterator_t *it, uint16_t handle){ } // experimental client API -uint16_t att_uuid_for_handle(uint16_t handle){ +uint16_t att_uuid_for_handle(uint16_t attribute_handle){ att_iterator_t it; - int ok = att_find_handle(&it, handle); + int ok = att_find_handle(&it, attribute_handle); if (!ok) return 0; if (it.flags & ATT_PROPERTY_UUID128) return 0; return little_endian_read_16(it.uuid, 0); diff --git a/src/ble/att_db.h b/src/ble/att_db.h index 4222bfe63..2f57a00c7 100644 --- a/src/ble/att_db.h +++ b/src/ble/att_db.h @@ -122,11 +122,13 @@ uint16_t att_handle_request(att_connection_t * att_connection, /* * @brief setup value notification in response buffer for a given handle and value * @param att_connection - * @param value, value_len: new attribute value + * @param attribute_handle + * @param value + * @param value_len * @param response_buffer for notification */ uint16_t att_prepare_handle_value_notification(att_connection_t * att_connection, - uint16_t handle, + uint16_t attribute_handle, uint8_t *value, uint16_t value_len, uint8_t * response_buffer); @@ -134,11 +136,13 @@ uint16_t att_prepare_handle_value_notification(att_connection_t * att_connection /* * @brief setup value indication in response buffer for a given handle and value * @param att_connection - * @param value, value_len: new attribute value + * @param attribute_handle + * @param value + * @param value_len * @param response_buffer for indication */ uint16_t att_prepare_handle_value_indication(att_connection_t * att_connection, - uint16_t handle, + uint16_t attribute_handle, uint8_t *value, uint16_t value_len, uint8_t * response_buffer); @@ -149,7 +153,7 @@ uint16_t att_prepare_handle_value_indication(att_connection_t * att_connection, void att_clear_transaction_queue(att_connection_t * att_connection); // experimental client API -uint16_t att_uuid_for_handle(uint16_t handle); +uint16_t att_uuid_for_handle(uint16_t attribute_handle); #if defined __cplusplus } diff --git a/src/ble/att_dispatch.c b/src/ble/att_dispatch.c index 0aa7e5cc0..86ce0556e 100644 --- a/src/ble/att_dispatch.c +++ b/src/ble/att_dispatch.c @@ -104,8 +104,8 @@ void att_dispatch_register_server(btstack_packet_handler_t packet_handler){ * @brief can send packet for client * @param handle */ -int att_dispatch_client_can_send_now(uint16_t handle){ - int res = l2cap_can_send_fixed_channel_packet_now(handle, L2CAP_CID_ATTRIBUTE_PROTOCOL); +int att_dispatch_client_can_send_now(hci_con_handle_t con_handle){ + int res = l2cap_can_send_fixed_channel_packet_now(con_handle, L2CAP_CID_ATTRIBUTE_PROTOCOL); if (!res){ att_client_waiting_for_can_send =1; } @@ -116,8 +116,8 @@ int att_dispatch_client_can_send_now(uint16_t handle){ * @brief can send packet for server * @param handle */ -int att_dispatch_server_can_send_now(uint16_t handle){ - int res = l2cap_can_send_fixed_channel_packet_now(handle, L2CAP_CID_ATTRIBUTE_PROTOCOL); +int att_dispatch_server_can_send_now(hci_con_handle_t con_handle){ + int res = l2cap_can_send_fixed_channel_packet_now(con_handle, L2CAP_CID_ATTRIBUTE_PROTOCOL); if (!res){ att_server_waiting_for_can_send =1; } diff --git a/src/ble/att_dispatch.h b/src/ble/att_dispatch.h index 0523fb9b2..eb09b0399 100644 --- a/src/ble/att_dispatch.h +++ b/src/ble/att_dispatch.h @@ -63,15 +63,15 @@ void att_dispatch_register_server(btstack_packet_handler_t packet_handler); /** * @brief can send packet for client - * @param handle + * @param con_handle */ -int att_dispatch_client_can_send_now(uint16_t handle); +int att_dispatch_client_can_send_now(hci_con_handle_t con_handle); /** * @brief can send packet for server - * @param handle + * @param con_handle */ -int att_dispatch_server_can_send_now(uint16_t handle); +int att_dispatch_server_can_send_now(hci_con_handle_t con_handle); #if defined __cplusplus diff --git a/src/ble/att_server.c b/src/ble/att_server.c index 7e3e7f223..02ceeabd5 100644 --- a/src/ble/att_server.c +++ b/src/ble/att_server.c @@ -111,7 +111,7 @@ static void att_handle_value_indication_notify_client(uint8_t status, uint16_t c (*att_client_packet_handler)(HCI_EVENT_PACKET, 0, &event[0], sizeof(event)); } -static void att_emit_mtu_event(uint16_t handle, uint16_t mtu){ +static void att_emit_mtu_event(hci_con_handle_t con_handle, uint16_t mtu){ if (!att_client_packet_handler) return; @@ -119,7 +119,7 @@ static void att_emit_mtu_event(uint16_t handle, uint16_t mtu){ int pos = 0; event[pos++] = ATT_EVENT_MTU_EXCHANGE_COMPLETE; event[pos++] = sizeof(event) - 2; - little_endian_store_16(event, pos, handle); + little_endian_store_16(event, pos, con_handle); pos += 2; little_endian_store_16(event, pos, mtu); pos += 2; @@ -383,28 +383,28 @@ int att_server_can_send_packet_now(void){ return att_dispatch_server_can_send_now(att_connection.con_handle); } -int att_server_notify(uint16_t handle, uint8_t *value, uint16_t value_len){ +int att_server_notify(uint16_t attribute_handle, uint8_t *value, uint16_t value_len){ if (!att_dispatch_server_can_send_now(att_connection.con_handle)) return BTSTACK_ACL_BUFFERS_FULL; l2cap_reserve_packet_buffer(); uint8_t * packet_buffer = l2cap_get_outgoing_buffer(); - uint16_t size = att_prepare_handle_value_notification(&att_connection, handle, value, value_len, packet_buffer); + uint16_t size = att_prepare_handle_value_notification(&att_connection, attribute_handle, value, value_len, packet_buffer); return l2cap_send_prepared_connectionless(att_connection.con_handle, L2CAP_CID_ATTRIBUTE_PROTOCOL, size); } -int att_server_indicate(uint16_t handle, uint8_t *value, uint16_t value_len){ +int att_server_indicate(uint16_t attribute_handle, uint8_t *value, uint16_t value_len){ if (att_handle_value_indication_handle) return ATT_HANDLE_VALUE_INDICATION_IN_PORGRESS; if (!att_dispatch_server_can_send_now(att_connection.con_handle)) return BTSTACK_ACL_BUFFERS_FULL; // track indication - att_handle_value_indication_handle = handle; + att_handle_value_indication_handle = attribute_handle; btstack_run_loop_set_timer_handler(&att_handle_value_indication_timer, att_handle_value_indication_timeout); btstack_run_loop_set_timer(&att_handle_value_indication_timer, ATT_TRANSACTION_TIMEOUT_MS); btstack_run_loop_add_timer(&att_handle_value_indication_timer); l2cap_reserve_packet_buffer(); uint8_t * packet_buffer = l2cap_get_outgoing_buffer(); - uint16_t size = att_prepare_handle_value_indication(&att_connection, handle, value, value_len, packet_buffer); + uint16_t size = att_prepare_handle_value_indication(&att_connection, attribute_handle, value, value_len, packet_buffer); l2cap_send_prepared_connectionless(att_connection.con_handle, L2CAP_CID_ATTRIBUTE_PROTOCOL, size); return 0; } diff --git a/src/ble/att_server.h b/src/ble/att_server.h index 9b179e9f0..0c6c6a90d 100644 --- a/src/ble/att_server.h +++ b/src/ble/att_server.h @@ -69,15 +69,21 @@ int att_server_can_send_packet_now(void); /* * @brief notify client about attribute value change + * @param attribute_handle + * @param value + * @param value_len * @return 0 if ok, error otherwise */ -int att_server_notify(uint16_t handle, uint8_t *value, uint16_t value_len); +int att_server_notify(uint16_t attribute_handle, uint8_t *value, uint16_t value_len); /* * @brief indicate value change to client. client is supposed to reply with an indication_response + * @param attribute_handle + * @param value + * @param value_len * @return 0 if ok, error otherwise */ -int att_server_indicate(uint16_t handle, uint8_t *value, uint16_t value_len); +int att_server_indicate(uint16_t attribute_handle, uint8_t *value, uint16_t value_len); /* API_END */ diff --git a/src/ble/gatt_client.c b/src/ble/gatt_client.c index 1ded3e474..47d3c75b7 100644 --- a/src/ble/gatt_client.c +++ b/src/ble/gatt_client.c @@ -104,12 +104,12 @@ static gatt_client_t * gatt_client_for_timer(btstack_timer_source_t * ts){ static void gatt_client_timeout_handler(btstack_timer_source_t * timer){ gatt_client_t * peripheral = gatt_client_for_timer(timer); if (!peripheral) return; - log_info("GATT client timeout handle, handle 0x%02x", peripheral->handle); + log_info("GATT client timeout handle, handle 0x%02x", peripheral->con_handle); gatt_client_report_error_if_pending(peripheral, ATT_ERROR_TIMEOUT); } static void gatt_client_timeout_start(gatt_client_t * peripheral){ - log_info("GATT client timeout start, handle 0x%02x", peripheral->handle); + log_info("GATT client timeout start, handle 0x%02x", peripheral->con_handle); btstack_run_loop_remove_timer(&peripheral->gc_timeout); btstack_run_loop_set_timer_handler(&peripheral->gc_timeout, gatt_client_timeout_handler); btstack_run_loop_set_timer(&peripheral->gc_timeout, 30000); // 30 seconds sm timeout @@ -117,7 +117,7 @@ static void gatt_client_timeout_start(gatt_client_t * peripheral){ } static void gatt_client_timeout_stop(gatt_client_t * peripheral){ - log_info("GATT client timeout stop, handle 0x%02x", peripheral->handle); + log_info("GATT client timeout stop, handle 0x%02x", peripheral->con_handle); btstack_run_loop_remove_timer(&peripheral->gc_timeout); } @@ -125,7 +125,7 @@ static gatt_client_t * get_gatt_client_context_for_handle(uint16_t handle){ btstack_linked_item_t *it; for (it = (btstack_linked_item_t *) gatt_client_connections; it ; it = it->next){ gatt_client_t * peripheral = (gatt_client_t *) it; - if (peripheral->handle == handle){ + if (peripheral->con_handle == handle){ return peripheral; } } @@ -143,7 +143,7 @@ static gatt_client_t * provide_context_for_conn_handle(hci_con_handle_t con_hand if (!context) return NULL; // init state memset(context, 0, sizeof(gatt_client_t)); - context->handle = con_handle; + context->con_handle = con_handle; context->mtu = ATT_DEFAULT_MTU; context->mtu_state = SEND_MTU_EXCHANGE; context->gatt_client_state = P_READY; @@ -167,14 +167,14 @@ static int is_ready(gatt_client_t * context){ return context->gatt_client_state == P_READY; } -int gatt_client_is_ready(uint16_t handle){ - gatt_client_t * context = provide_context_for_conn_handle(handle); +int gatt_client_is_ready(hci_con_handle_t con_handle){ + gatt_client_t * context = provide_context_for_conn_handle(con_handle); if (!context) return 0; return is_ready(context); } -uint8_t gatt_client_get_mtu(uint16_t handle, uint16_t * mtu){ - gatt_client_t * context = provide_context_for_conn_handle(handle); +uint8_t gatt_client_get_mtu(hci_con_handle_t con_handle, uint16_t * mtu){ + gatt_client_t * context = provide_context_for_conn_handle(con_handle); if (context && context->mtu_state == MTU_EXCHANGED){ *mtu = context->mtu; return 0; @@ -340,19 +340,19 @@ static uint16_t write_blob_length(gatt_client_t * peripheral){ } static void send_gatt_services_request(gatt_client_t *peripheral){ - att_read_by_type_or_group_request_for_uuid16(ATT_READ_BY_GROUP_TYPE_REQUEST, GATT_PRIMARY_SERVICE_UUID, peripheral->handle, peripheral->start_group_handle, peripheral->end_group_handle); + att_read_by_type_or_group_request_for_uuid16(ATT_READ_BY_GROUP_TYPE_REQUEST, GATT_PRIMARY_SERVICE_UUID, peripheral->con_handle, peripheral->start_group_handle, peripheral->end_group_handle); } static void send_gatt_by_uuid_request(gatt_client_t *peripheral, uint16_t attribute_group_type){ if (peripheral->uuid16){ uint8_t uuid16[2]; little_endian_store_16(uuid16, 0, peripheral->uuid16); - att_find_by_type_value_request(ATT_FIND_BY_TYPE_VALUE_REQUEST, attribute_group_type, peripheral->handle, peripheral->start_group_handle, peripheral->end_group_handle, uuid16, 2); + att_find_by_type_value_request(ATT_FIND_BY_TYPE_VALUE_REQUEST, attribute_group_type, peripheral->con_handle, peripheral->start_group_handle, peripheral->end_group_handle, uuid16, 2); return; } uint8_t uuid128[16]; reverse_128(peripheral->uuid128, uuid128); - att_find_by_type_value_request(ATT_FIND_BY_TYPE_VALUE_REQUEST, attribute_group_type, peripheral->handle, peripheral->start_group_handle, peripheral->end_group_handle, uuid128, 16); + att_find_by_type_value_request(ATT_FIND_BY_TYPE_VALUE_REQUEST, attribute_group_type, peripheral->con_handle, peripheral->start_group_handle, peripheral->end_group_handle, uuid128, 16); } static void send_gatt_services_by_uuid_request(gatt_client_t *peripheral){ @@ -360,71 +360,71 @@ static void send_gatt_services_by_uuid_request(gatt_client_t *peripheral){ } static void send_gatt_included_service_uuid_request(gatt_client_t *peripheral){ - att_read_request(ATT_READ_REQUEST, peripheral->handle, peripheral->query_start_handle); + att_read_request(ATT_READ_REQUEST, peripheral->con_handle, peripheral->query_start_handle); } static void send_gatt_included_service_request(gatt_client_t *peripheral){ - att_read_by_type_or_group_request_for_uuid16(ATT_READ_BY_TYPE_REQUEST, GATT_INCLUDE_SERVICE_UUID, peripheral->handle, peripheral->start_group_handle, peripheral->end_group_handle); + att_read_by_type_or_group_request_for_uuid16(ATT_READ_BY_TYPE_REQUEST, GATT_INCLUDE_SERVICE_UUID, peripheral->con_handle, peripheral->start_group_handle, peripheral->end_group_handle); } static void send_gatt_characteristic_request(gatt_client_t *peripheral){ - att_read_by_type_or_group_request_for_uuid16(ATT_READ_BY_TYPE_REQUEST, GATT_CHARACTERISTICS_UUID, peripheral->handle, peripheral->start_group_handle, peripheral->end_group_handle); + att_read_by_type_or_group_request_for_uuid16(ATT_READ_BY_TYPE_REQUEST, GATT_CHARACTERISTICS_UUID, peripheral->con_handle, peripheral->start_group_handle, peripheral->end_group_handle); } static void send_gatt_characteristic_descriptor_request(gatt_client_t *peripheral){ - att_find_information_request(ATT_FIND_INFORMATION_REQUEST, peripheral->handle, peripheral->start_group_handle, peripheral->end_group_handle); + att_find_information_request(ATT_FIND_INFORMATION_REQUEST, peripheral->con_handle, peripheral->start_group_handle, peripheral->end_group_handle); } static void send_gatt_read_characteristic_value_request(gatt_client_t *peripheral){ - att_read_request(ATT_READ_REQUEST, peripheral->handle, peripheral->attribute_handle); + att_read_request(ATT_READ_REQUEST, peripheral->con_handle, peripheral->attribute_handle); } static void send_gatt_read_by_type_request(gatt_client_t * peripheral){ if (peripheral->uuid16){ - att_read_by_type_or_group_request_for_uuid16(ATT_READ_BY_TYPE_REQUEST, peripheral->uuid16, peripheral->handle, peripheral->start_group_handle, peripheral->end_group_handle); + att_read_by_type_or_group_request_for_uuid16(ATT_READ_BY_TYPE_REQUEST, peripheral->uuid16, peripheral->con_handle, peripheral->start_group_handle, peripheral->end_group_handle); } else { - att_read_by_type_or_group_request_for_uuid128(ATT_READ_BY_TYPE_REQUEST, peripheral->uuid128, peripheral->handle, peripheral->start_group_handle, peripheral->end_group_handle); + att_read_by_type_or_group_request_for_uuid128(ATT_READ_BY_TYPE_REQUEST, peripheral->uuid128, peripheral->con_handle, peripheral->start_group_handle, peripheral->end_group_handle); } } static void send_gatt_read_blob_request(gatt_client_t *peripheral){ - att_read_blob_request(ATT_READ_BLOB_REQUEST, peripheral->handle, peripheral->attribute_handle, peripheral->attribute_offset); + att_read_blob_request(ATT_READ_BLOB_REQUEST, peripheral->con_handle, peripheral->attribute_handle, peripheral->attribute_offset); } static void send_gatt_read_multiple_request(gatt_client_t * peripheral){ - att_read_multiple_request(peripheral->handle, peripheral->read_multiple_handle_count, peripheral->read_multiple_handles); + att_read_multiple_request(peripheral->con_handle, peripheral->read_multiple_handle_count, peripheral->read_multiple_handles); } static void send_gatt_write_attribute_value_request(gatt_client_t * peripheral){ - att_write_request(ATT_WRITE_REQUEST, peripheral->handle, peripheral->attribute_handle, peripheral->attribute_length, peripheral->attribute_value); + att_write_request(ATT_WRITE_REQUEST, peripheral->con_handle, peripheral->attribute_handle, peripheral->attribute_length, peripheral->attribute_value); } static void send_gatt_write_client_characteristic_configuration_request(gatt_client_t * peripheral){ - att_write_request(ATT_WRITE_REQUEST, peripheral->handle, peripheral->client_characteristic_configuration_handle, 2, peripheral->client_characteristic_configuration_value); + att_write_request(ATT_WRITE_REQUEST, peripheral->con_handle, peripheral->client_characteristic_configuration_handle, 2, peripheral->client_characteristic_configuration_value); } static void send_gatt_prepare_write_request(gatt_client_t * peripheral){ - att_prepare_write_request(ATT_PREPARE_WRITE_REQUEST, peripheral->handle, peripheral->attribute_handle, peripheral->attribute_offset, write_blob_length(peripheral), peripheral->attribute_value); + att_prepare_write_request(ATT_PREPARE_WRITE_REQUEST, peripheral->con_handle, peripheral->attribute_handle, peripheral->attribute_offset, write_blob_length(peripheral), peripheral->attribute_value); } static void send_gatt_execute_write_request(gatt_client_t * peripheral){ - att_execute_write_request(ATT_EXECUTE_WRITE_REQUEST, peripheral->handle, 1); + att_execute_write_request(ATT_EXECUTE_WRITE_REQUEST, peripheral->con_handle, 1); } static void send_gatt_cancel_prepared_write_request(gatt_client_t * peripheral){ - att_execute_write_request(ATT_EXECUTE_WRITE_REQUEST, peripheral->handle, 0); + att_execute_write_request(ATT_EXECUTE_WRITE_REQUEST, peripheral->con_handle, 0); } static void send_gatt_read_client_characteristic_configuration_request(gatt_client_t * peripheral){ - att_read_by_type_or_group_request_for_uuid16(ATT_READ_BY_TYPE_REQUEST, GATT_CLIENT_CHARACTERISTICS_CONFIGURATION, peripheral->handle, peripheral->start_group_handle, peripheral->end_group_handle); + att_read_by_type_or_group_request_for_uuid16(ATT_READ_BY_TYPE_REQUEST, GATT_CLIENT_CHARACTERISTICS_CONFIGURATION, peripheral->con_handle, peripheral->start_group_handle, peripheral->end_group_handle); } static void send_gatt_read_characteristic_descriptor_request(gatt_client_t * peripheral){ - att_read_request(ATT_READ_REQUEST, peripheral->handle, peripheral->attribute_handle); + att_read_request(ATT_READ_REQUEST, peripheral->con_handle, peripheral->attribute_handle); } static void send_gatt_signed_write_request(gatt_client_t * peripheral, uint32_t sign_counter){ - att_signed_write_request(ATT_SIGNED_WRITE_COMMAND, peripheral->handle, peripheral->attribute_handle, peripheral->attribute_length, peripheral->attribute_value, sign_counter, peripheral->cmac); + att_signed_write_request(ATT_SIGNED_WRITE_COMMAND, peripheral->con_handle, peripheral->attribute_handle, peripheral->attribute_length, peripheral->attribute_value, sign_counter, peripheral->cmac); } static uint16_t get_last_result_handle_from_service_list(uint8_t * packet, uint16_t size){ @@ -480,7 +480,7 @@ static void emit_gatt_complete_event(gatt_client_t * peripheral, uint8_t status) uint8_t packet[5]; packet[0] = GATT_EVENT_QUERY_COMPLETE; packet[1] = 3; - little_endian_store_16(packet, 2, peripheral->handle); + little_endian_store_16(packet, 2, peripheral->con_handle); packet[4] = status; emit_event_new(peripheral->callback, packet, sizeof(packet)); } @@ -490,7 +490,7 @@ static void emit_gatt_service_query_result_event(gatt_client_t * peripheral, uin uint8_t packet[24]; packet[0] = GATT_EVENT_SERVICE_QUERY_RESULT; packet[1] = sizeof(packet) - 2; - little_endian_store_16(packet, 2, peripheral->handle); + little_endian_store_16(packet, 2, peripheral->con_handle); /// little_endian_store_16(packet, 4, start_group_handle); little_endian_store_16(packet, 6, end_group_handle); @@ -503,7 +503,7 @@ static void emit_gatt_included_service_query_result_event(gatt_client_t * periph uint8_t packet[26]; packet[0] = GATT_EVENT_INCLUDED_SERVICE_QUERY_RESULT; packet[1] = sizeof(packet) - 2; - little_endian_store_16(packet, 2, peripheral->handle); + little_endian_store_16(packet, 2, peripheral->con_handle); /// little_endian_store_16(packet, 4, include_handle); // @@ -519,7 +519,7 @@ static void emit_gatt_characteristic_query_result_event(gatt_client_t * peripher uint8_t packet[28]; packet[0] = GATT_EVENT_CHARACTERISTIC_QUERY_RESULT; packet[1] = sizeof(packet) - 2; - little_endian_store_16(packet, 2, peripheral->handle); + little_endian_store_16(packet, 2, peripheral->con_handle); /// little_endian_store_16(packet, 4, start_handle); little_endian_store_16(packet, 6, value_handle); @@ -535,7 +535,7 @@ static void emit_gatt_all_characteristic_descriptors_result_event( uint8_t packet[22]; packet[0] = GATT_EVENT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT; packet[1] = sizeof(packet) - 2; - little_endian_store_16(packet, 2, peripheral->handle); + little_endian_store_16(packet, 2, peripheral->con_handle); /// little_endian_store_16(packet, 4, descriptor_handle); reverse_128(uuid128, &packet[6]); @@ -562,7 +562,7 @@ static void report_gatt_services(gatt_client_t * peripheral, uint8_t * packet, } emit_gatt_service_query_result_event(peripheral, start_group_handle, end_group_handle, uuid128); } - // log_info("report_gatt_services for %02X done", peripheral->handle); + // log_info("report_gatt_services for %02X done", peripheral->con_handle); } // helper @@ -673,24 +673,24 @@ static void report_gatt_indication(hci_con_handle_t con_handle, uint16_t value_h // @note assume that value is part of an l2cap buffer - overwrite parts of the HCI/L2CAP/ATT packet (4/4/3) bytes static void report_gatt_characteristic_value(gatt_client_t * peripheral, uint16_t attribute_handle, uint8_t * value, uint16_t length){ - uint8_t * packet = setup_characteristic_value_packet(GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT, peripheral->handle, attribute_handle, value, length); + uint8_t * packet = setup_characteristic_value_packet(GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT, peripheral->con_handle, attribute_handle, value, length); emit_event_new(peripheral->callback, packet, characteristic_value_event_header_size + length); } // @note assume that value is part of an l2cap buffer - overwrite parts of the HCI/L2CAP/ATT packet (4/4/3) bytes static void report_gatt_long_characteristic_value_blob(gatt_client_t * peripheral, uint16_t attribute_handle, uint8_t * blob, uint16_t blob_length, int value_offset){ - uint8_t * packet = setup_long_characteristic_value_packet(GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT, peripheral->handle, attribute_handle, value_offset, blob, blob_length); + uint8_t * packet = setup_long_characteristic_value_packet(GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT, peripheral->con_handle, attribute_handle, value_offset, blob, blob_length); if (!packet) return; emit_event_new(peripheral->callback, packet, blob_length + long_characteristic_value_event_header_size); } static void report_gatt_characteristic_descriptor(gatt_client_t * peripheral, uint16_t descriptor_handle, uint8_t *value, uint16_t value_length, uint16_t value_offset){ - uint8_t * packet = setup_characteristic_value_packet(GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT, peripheral->handle, descriptor_handle, value, value_length); + uint8_t * packet = setup_characteristic_value_packet(GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT, peripheral->con_handle, descriptor_handle, value, value_length); emit_event_new(peripheral->callback, packet, value_length + 8); } static void report_gatt_long_characteristic_descriptor(gatt_client_t * peripheral, uint16_t descriptor_handle, uint8_t *blob, uint16_t blob_length, uint16_t value_offset){ - uint8_t * packet = setup_long_characteristic_value_packet(GATT_EVENT_LONG_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT, peripheral->handle, descriptor_handle, value_offset, blob, blob_length); + uint8_t * packet = setup_long_characteristic_value_packet(GATT_EVENT_LONG_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT, peripheral->con_handle, descriptor_handle, value_offset, blob, blob_length); if (!packet) return; emit_event_new(peripheral->callback, packet, blob_length + long_characteristic_value_event_header_size); } @@ -797,14 +797,14 @@ static void gatt_client_run(void){ gatt_client_t * peripheral = (gatt_client_t *) it; - if (!att_dispatch_server_can_send_now(peripheral->handle)) return; + if (!att_dispatch_server_can_send_now(peripheral->con_handle)) return; // log_info("- handle_peripheral_list, mtu state %u, client state %u", peripheral->mtu_state, peripheral->gatt_client_state); switch (peripheral->mtu_state) { case SEND_MTU_EXCHANGE:{ peripheral->mtu_state = SENT_MTU_EXCHANGE; - att_exchange_mtu_request(peripheral->handle); + att_exchange_mtu_request(peripheral->con_handle); return; } case SENT_MTU_EXCHANGE: @@ -815,7 +815,7 @@ static void gatt_client_run(void){ if (peripheral->send_confirmation){ peripheral->send_confirmation = 0; - att_confirmation(peripheral->handle); + att_confirmation(peripheral->con_handle); return; } @@ -1612,10 +1612,10 @@ uint8_t gatt_client_write_value_of_characteristic_without_response(btstack_packe if (!is_ready(peripheral)) return GATT_CLIENT_IN_WRONG_STATE; if (value_length > peripheral_mtu(peripheral) - 3) return GATT_CLIENT_VALUE_TOO_LONG; - if (!att_dispatch_server_can_send_now(peripheral->handle)) return GATT_CLIENT_BUSY; + if (!att_dispatch_server_can_send_now(peripheral->con_handle)) return GATT_CLIENT_BUSY; peripheral->callback = callback; - att_write_request(ATT_WRITE_COMMAND, peripheral->handle, value_handle, value_length, value); + att_write_request(ATT_WRITE_COMMAND, peripheral->con_handle, value_handle, value_length, value); return 0; } diff --git a/src/ble/gatt_client.h b/src/ble/gatt_client.h index 05884d14e..cb1716bb5 100644 --- a/src/ble/gatt_client.h +++ b/src/ble/gatt_client.h @@ -137,7 +137,7 @@ typedef struct gatt_client{ // user callback btstack_packet_handler_t callback; - uint16_t handle; + hci_con_handle_t con_handle; uint8_t address_type; bd_addr_t address; @@ -216,12 +216,12 @@ void gatt_client_init(void); /** * @brief MTU is available after the first query has completed. If status is equal to 0, it returns the real value, otherwise the default value of 23. */ -uint8_t gatt_client_get_mtu(uint16_t handle, uint16_t * mtu); +uint8_t gatt_client_get_mtu(hci_con_handle_t con_handle, uint16_t * mtu); /** * @brief Returns if the GATT client is ready to receive a query. It is used with daemon. */ -int gatt_client_is_ready(uint16_t handle); +int gatt_client_is_ready(hci_con_handle_t con_handle); /** * @brief Discovers all primary services. For each found service, an le_service_event_t with type set to GATT_EVENT_SERVICE_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t, with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of discovery. diff --git a/src/classic/hfp.c b/src/classic/hfp.c index 029125e38..ff5ebb258 100644 --- a/src/classic/hfp.c +++ b/src/classic/hfp.c @@ -487,8 +487,8 @@ void hfp_handle_hci_event(uint8_t packet_type, uint8_t *packet, uint16_t size){ hfp_emit_event(hfp_callback, HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED, packet[2]); remove_hfp_connection_context(context); } else { - context->con_handle = little_endian_read_16(packet, 9); - printf("RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE con_handle 0x%02x\n", context->con_handle); + context->acl_handle = little_endian_read_16(packet, 9); + printf("RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE con_handle 0x%02x\n", context->acl_handle); context->rfcomm_cid = little_endian_read_16(packet, 12); uint16_t mtu = little_endian_read_16(packet, 14); @@ -505,8 +505,6 @@ void hfp_handle_hci_event(uint8_t packet_type, uint8_t *packet, uint16_t size){ default: break; } - // forward event to app, to learn about con_handle - (*hfp_callback)(packet, size); } break; @@ -634,13 +632,7 @@ void hfp_handle_hci_event(uint8_t packet_type, uint8_t *packet, uint16_t size){ } break; - case HCI_EVENT_INQUIRY_RESULT: - case HCI_EVENT_INQUIRY_RESULT_WITH_RSSI: - case HCI_EVENT_INQUIRY_COMPLETE: - case DAEMON_EVENT_REMOTE_NAME_CACHED: - case HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE: - // forward inquiry events to app - TODO: replace with new event handler architecture - (*hfp_callback)(packet, size); + default: break; } } diff --git a/src/classic/hfp.h b/src/classic/hfp.h index cd0524e85..444106358 100644 --- a/src/classic/hfp.h +++ b/src/classic/hfp.h @@ -464,8 +464,8 @@ typedef struct hfp_connection { btstack_linked_item_t item; bd_addr_t remote_addr; - hci_con_handle_t con_handle; - uint16_t sco_handle; + hci_con_handle_t acl_handle; + hci_con_handle_t sco_handle; uint16_t rfcomm_channel_nr; uint16_t rfcomm_cid; diff --git a/src/classic/hfp_ag.c b/src/classic/hfp_ag.c index dc60ee6ab..ae81064d7 100644 --- a/src/classic/hfp_ag.c +++ b/src/classic/hfp_ag.c @@ -604,7 +604,7 @@ static int codecs_exchange_state_machine(hfp_connection_t * context){ static void hfp_init_link_settings(hfp_connection_t * context){ // determine highest possible link setting context->link_setting = HFP_LINK_SETTINGS_D1; - if (hci_remote_esco_supported(context->con_handle)){ + if (hci_remote_esco_supported(context->acl_handle)){ context->link_setting = HFP_LINK_SETTINGS_S3; if ((context->remote_supported_features & (1<establish_audio_connection){ context->state = HFP_W4_SCO_CONNECTED; context->establish_audio_connection = 0; - hfp_setup_synchronous_connection(context->con_handle, context->link_setting); + hfp_setup_synchronous_connection(context->acl_handle, context->link_setting); return 1; } return 0; @@ -825,7 +825,7 @@ static void hfp_timeout_handler(btstack_timer_source_t * timer){ hfp_connection_t * context = hfp_ag_context_for_timer(timer); if (!context) return; - log_info("HFP start ring timeout, con handle 0x%02x", context->con_handle); + log_info("HFP start ring timeout, con handle 0x%02x", context->acl_handle); context->ag_ring = 1; context->ag_send_clip = hfp_gsm_clip_type() && context->clip_enabled; @@ -843,7 +843,7 @@ static void hfp_timeout_start(hfp_connection_t * context){ } static void hfp_timeout_stop(hfp_connection_t * context){ - log_info("HFP stop ring timeout, con handle 0x%02x", context->con_handle); + log_info("HFP stop ring timeout, con handle 0x%02x", context->acl_handle); btstack_run_loop_remove_timer(&context->hfp_timeout); } diff --git a/src/classic/hfp_hf.c b/src/classic/hfp_hf.c index 36fbae9a1..878c5ec03 100644 --- a/src/classic/hfp_hf.c +++ b/src/classic/hfp_hf.c @@ -525,7 +525,7 @@ static int hfp_hf_run_for_audio_connection(hfp_connection_t * context){ if (context->establish_audio_connection){ context->state = HFP_W4_SCO_CONNECTED; context->establish_audio_connection = 0; - hfp_setup_synchronous_connection(context->con_handle, context->link_setting); + hfp_setup_synchronous_connection(context->acl_handle, context->link_setting); return 1; } @@ -782,7 +782,7 @@ static void hfp_run_for_context(hfp_connection_t * context){ static void hfp_init_link_settings(hfp_connection_t * context){ // determine highest possible link setting context->link_setting = HFP_LINK_SETTINGS_D1; - if (hci_remote_esco_supported(context->con_handle)){ + if (hci_remote_esco_supported(context->acl_handle)){ context->link_setting = HFP_LINK_SETTINGS_S3; if ((hfp_supported_features & (1<remote_supported_features & (1<address), channel->handle, channel->psm, + status, bd_addr_to_str(channel->address), channel->con_handle, channel->psm, channel->local_cid, channel->remote_cid, channel->local_mtu, channel->remote_mtu, channel->flush_timeout); uint8_t event[23]; event[0] = L2CAP_EVENT_CHANNEL_OPENED; event[1] = sizeof(event) - 2; event[2] = status; reverse_bd_addr(channel->address, &event[3]); - little_endian_store_16(event, 9, channel->handle); + little_endian_store_16(event, 9, channel->con_handle); little_endian_store_16(event, 11, channel->psm); little_endian_store_16(event, 13, channel->local_cid); little_endian_store_16(event, 15, channel->remote_cid); @@ -187,7 +187,7 @@ void l2cap_emit_channel_opened(l2cap_channel_t *channel, uint8_t status) { // if channel opened successfully, also send can send now if possible if (status) return; - if (hci_can_send_acl_packet_now(channel->handle)){ + if (hci_can_send_acl_packet_now(channel->con_handle)){ l2cap_emit_can_send_now(channel->packet_handler, channel->local_cid); } else { channel->waiting_for_can_send_now = 1; @@ -206,12 +206,12 @@ void l2cap_emit_channel_closed(l2cap_channel_t *channel) { void l2cap_emit_connection_request(l2cap_channel_t *channel) { log_info("L2CAP_EVENT_INCOMING_CONNECTION addr %s handle 0x%x psm 0x%x local_cid 0x%x remote_cid 0x%x", - bd_addr_to_str(channel->address), channel->handle, channel->psm, channel->local_cid, channel->remote_cid); + bd_addr_to_str(channel->address), channel->con_handle, channel->psm, channel->local_cid, channel->remote_cid); uint8_t event[16]; event[0] = L2CAP_EVENT_INCOMING_CONNECTION; event[1] = sizeof(event) - 2; reverse_bd_addr(channel->address, &event[2]); - little_endian_store_16(event, 8, channel->handle); + little_endian_store_16(event, 8, channel->con_handle); little_endian_store_16(event, 10, channel->psm); little_endian_store_16(event, 12, channel->local_cid); little_endian_store_16(event, 14, channel->remote_cid); @@ -229,11 +229,11 @@ static void l2cap_emit_can_send_now(btstack_packet_handler_t packet_handler, uin packet_handler(HCI_EVENT_PACKET, channel, event, sizeof(event)); } -static void l2cap_emit_connection_parameter_update_response(uint16_t handle, uint16_t result){ +static void l2cap_emit_connection_parameter_update_response(hci_con_handle_t con_handle, uint16_t result){ uint8_t event[6]; event[0] = L2CAP_EVENT_CONNECTION_PARAMETER_UPDATE_RESPONSE; event[1] = 4; - little_endian_store_16(event, 2, handle); + little_endian_store_16(event, 2, con_handle); little_endian_store_16(event, 4, result); hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event)); if (!l2cap_event_packet_handler) return; @@ -255,7 +255,7 @@ static l2cap_channel_t * l2cap_get_channel_for_local_cid(uint16_t local_cid){ int l2cap_can_send_packet_now(uint16_t local_cid){ l2cap_channel_t *channel = l2cap_get_channel_for_local_cid(local_cid); if (!channel) return 0; - int can_send = hci_can_send_acl_packet_now(channel->handle); + int can_send = hci_can_send_acl_packet_now(channel->con_handle); if (!can_send){ channel->waiting_for_can_send_now = 1; } @@ -265,15 +265,15 @@ int l2cap_can_send_packet_now(uint16_t local_cid){ int l2cap_can_send_prepared_packet_now(uint16_t local_cid){ l2cap_channel_t *channel = l2cap_get_channel_for_local_cid(local_cid); if (!channel) return 0; - int can_send = hci_can_send_prepared_acl_packet_now(channel->handle); + int can_send = hci_can_send_prepared_acl_packet_now(channel->con_handle); if (!can_send){ channel->waiting_for_can_send_now = 1; } return can_send; } -int l2cap_can_send_fixed_channel_packet_now(uint16_t handle, uint16_t channel_id){ - int can_send = hci_can_send_acl_packet_now(handle); +int l2cap_can_send_fixed_channel_packet_now(hci_con_handle_t con_handle, uint16_t channel_id){ + int can_send = hci_can_send_acl_packet_now(con_handle); if (!can_send){ int index = l2cap_fixed_channel_table_index_for_channel_id(channel_id); if (index >= 0){ @@ -413,19 +413,19 @@ int l2cap_send_prepared(uint16_t local_cid, uint16_t len){ return -1; // TODO: define error } - if (!hci_can_send_prepared_acl_packet_now(channel->handle)){ + if (!hci_can_send_prepared_acl_packet_now(channel->con_handle)){ log_info("l2cap_send_prepared cid 0x%02x, cannot send", local_cid); return BTSTACK_ACL_BUFFERS_FULL; } - log_debug("l2cap_send_prepared cid 0x%02x, handle %u, 1 credit used", local_cid, channel->handle); + log_debug("l2cap_send_prepared cid 0x%02x, handle %u, 1 credit used", local_cid, channel->con_handle); uint8_t *acl_buffer = hci_get_outgoing_packet_buffer(); int pb = hci_non_flushable_packet_boundary_flag_supported() ? 0x00 : 0x02; // 0 - Connection handle : PB=pb : BC=00 - little_endian_store_16(acl_buffer, 0, channel->handle | (pb << 12) | (0 << 14)); + little_endian_store_16(acl_buffer, 0, channel->con_handle | (pb << 12) | (0 << 14)); // 2 - ACL length little_endian_store_16(acl_buffer, 2, len + 4); // 4 - L2CAP packet length @@ -438,26 +438,26 @@ int l2cap_send_prepared(uint16_t local_cid, uint16_t len){ return err; } -int l2cap_send_prepared_connectionless(uint16_t handle, uint16_t cid, uint16_t len){ +int l2cap_send_prepared_connectionless(hci_con_handle_t con_handle, uint16_t cid, uint16_t len){ if (!hci_is_packet_buffer_reserved()){ log_error("l2cap_send_prepared_connectionless called without reserving packet first"); return BTSTACK_ACL_BUFFERS_FULL; } - if (!hci_can_send_prepared_acl_packet_now(handle)){ - log_info("l2cap_send_prepared_connectionless handle 0x%02x, cid 0x%02x, cannot send", handle, cid); + if (!hci_can_send_prepared_acl_packet_now(con_handle)){ + log_info("l2cap_send_prepared_connectionless handle 0x%02x, cid 0x%02x, cannot send", con_handle, cid); return BTSTACK_ACL_BUFFERS_FULL; } - log_debug("l2cap_send_prepared_connectionless handle %u, cid 0x%02x", handle, cid); + log_debug("l2cap_send_prepared_connectionless handle %u, cid 0x%02x", con_handle, cid); uint8_t *acl_buffer = hci_get_outgoing_packet_buffer(); int pb = hci_non_flushable_packet_boundary_flag_supported() ? 0x00 : 0x02; // 0 - Connection handle : PB=pb : BC=00 - little_endian_store_16(acl_buffer, 0, handle | (pb << 12) | (0 << 14)); + little_endian_store_16(acl_buffer, 0, con_handle | (pb << 12) | (0 << 14)); // 2 - ACL length little_endian_store_16(acl_buffer, 2, len + 4); // 4 - L2CAP packet length @@ -483,7 +483,7 @@ int l2cap_send(uint16_t local_cid, uint8_t *data, uint16_t len){ return L2CAP_DATA_LEN_EXCEEDS_REMOTE_MTU; } - if (!hci_can_send_acl_packet_now(channel->handle)){ + if (!hci_can_send_acl_packet_now(channel->con_handle)){ log_info("l2cap_send cid 0x%02x, cannot send", local_cid); return BTSTACK_ACL_BUFFERS_FULL; } @@ -496,9 +496,9 @@ int l2cap_send(uint16_t local_cid, uint8_t *data, uint16_t len){ return l2cap_send_prepared(local_cid, len); } -int l2cap_send_connectionless(uint16_t handle, uint16_t cid, uint8_t *data, uint16_t len){ +int l2cap_send_connectionless(hci_con_handle_t con_handle, uint16_t cid, uint8_t *data, uint16_t len){ - if (!hci_can_send_acl_packet_now(handle)){ + if (!hci_can_send_acl_packet_now(con_handle)){ log_info("l2cap_send cid 0x%02x, cannot send", cid); return BTSTACK_ACL_BUFFERS_FULL; } @@ -508,11 +508,11 @@ int l2cap_send_connectionless(uint16_t handle, uint16_t cid, uint8_t *data, uint memcpy(&acl_buffer[8], data, len); - return l2cap_send_prepared_connectionless(handle, cid, len); + return l2cap_send_prepared_connectionless(con_handle, cid, len); } -int l2cap_send_echo_request(uint16_t handle, uint8_t *data, uint16_t len){ - return l2cap_send_signaling_packet(handle, ECHO_REQUEST, 0x77, len, data); +int l2cap_send_echo_request(hci_con_handle_t con_handle, uint8_t *data, uint16_t len){ + return l2cap_send_signaling_packet(con_handle, ECHO_REQUEST, 0x77, len, data); } static inline void channelStateVarSetFlag(l2cap_channel_t *channel, L2CAP_CHANNEL_STATE_VAR flag){ @@ -611,10 +611,10 @@ static void l2cap_run(void){ case L2CAP_STATE_WAIT_INCOMING_SECURITY_LEVEL_UPDATE: case L2CAP_STATE_WAIT_CLIENT_ACCEPT_OR_REJECT: - if (!hci_can_send_acl_packet_now(channel->handle)) break; + if (!hci_can_send_acl_packet_now(channel->con_handle)) break; if (channel->state_var & L2CAP_CHANNEL_STATE_VAR_SEND_CONN_RESP_PEND) { channelStateVarClearFlag(channel, L2CAP_CHANNEL_STATE_VAR_SEND_CONN_RESP_PEND); - l2cap_send_signaling_packet(channel->handle, CONNECTION_RESPONSE, channel->remote_sig_id, channel->local_cid, channel->remote_cid, 1, 0); + l2cap_send_signaling_packet(channel->con_handle, CONNECTION_RESPONSE, channel->remote_sig_id, channel->local_cid, channel->remote_cid, 1, 0); } break; @@ -627,9 +627,9 @@ static void l2cap_run(void){ break; case L2CAP_STATE_WILL_SEND_CONNECTION_RESPONSE_DECLINE: - if (!hci_can_send_acl_packet_now(channel->handle)) break; + if (!hci_can_send_acl_packet_now(channel->con_handle)) break; channel->state = L2CAP_STATE_INVALID; - l2cap_send_signaling_packet(channel->handle, CONNECTION_RESPONSE, channel->remote_sig_id, channel->local_cid, channel->remote_cid, channel->reason, 0); + l2cap_send_signaling_packet(channel->con_handle, CONNECTION_RESPONSE, channel->remote_sig_id, channel->local_cid, channel->remote_cid, channel->reason, 0); // discard channel - l2cap_finialize_channel_close without sending l2cap close event l2cap_stop_rtx(channel); btstack_linked_list_iterator_remove(&it); @@ -637,23 +637,23 @@ static void l2cap_run(void){ break; case L2CAP_STATE_WILL_SEND_CONNECTION_RESPONSE_ACCEPT: - if (!hci_can_send_acl_packet_now(channel->handle)) break; + if (!hci_can_send_acl_packet_now(channel->con_handle)) break; channel->state = L2CAP_STATE_CONFIG; channelStateVarSetFlag(channel, L2CAP_CHANNEL_STATE_VAR_SEND_CONF_REQ); - l2cap_send_signaling_packet(channel->handle, CONNECTION_RESPONSE, channel->remote_sig_id, channel->local_cid, channel->remote_cid, 0, 0); + l2cap_send_signaling_packet(channel->con_handle, CONNECTION_RESPONSE, channel->remote_sig_id, channel->local_cid, channel->remote_cid, 0, 0); break; case L2CAP_STATE_WILL_SEND_CONNECTION_REQUEST: - if (!hci_can_send_acl_packet_now(channel->handle)) break; + if (!hci_can_send_acl_packet_now(channel->con_handle)) break; // success, start l2cap handshake channel->local_sig_id = l2cap_next_sig_id(); channel->state = L2CAP_STATE_WAIT_CONNECT_RSP; - l2cap_send_signaling_packet( channel->handle, CONNECTION_REQUEST, channel->local_sig_id, channel->psm, channel->local_cid); + l2cap_send_signaling_packet( channel->con_handle, CONNECTION_REQUEST, channel->local_sig_id, channel->psm, channel->local_cid); l2cap_start_rtx(channel); break; case L2CAP_STATE_CONFIG: - if (!hci_can_send_acl_packet_now(channel->handle)) break; + if (!hci_can_send_acl_packet_now(channel->con_handle)) break; if (channel->state_var & L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP){ uint16_t flags = 0; channelStateVarClearFlag(channel, L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP); @@ -663,15 +663,15 @@ static void l2cap_run(void){ channelStateVarSetFlag(channel, L2CAP_CHANNEL_STATE_VAR_SENT_CONF_RSP); } if (channel->state_var & L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP_INVALID){ - l2cap_send_signaling_packet(channel->handle, CONFIGURE_RESPONSE, channel->remote_sig_id, channel->remote_cid, flags, L2CAP_CONF_RESULT_UNKNOWN_OPTIONS, 0, NULL); + l2cap_send_signaling_packet(channel->con_handle, CONFIGURE_RESPONSE, channel->remote_sig_id, channel->remote_cid, flags, L2CAP_CONF_RESULT_UNKNOWN_OPTIONS, 0, NULL); } else if (channel->state_var & L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP_MTU){ config_options[0] = 1; // MTU config_options[1] = 2; // len param little_endian_store_16( (uint8_t*)&config_options, 2, channel->remote_mtu); - l2cap_send_signaling_packet(channel->handle, CONFIGURE_RESPONSE, channel->remote_sig_id, channel->remote_cid, flags, 0, 4, &config_options); + l2cap_send_signaling_packet(channel->con_handle, CONFIGURE_RESPONSE, channel->remote_sig_id, channel->remote_cid, flags, 0, 4, &config_options); channelStateVarClearFlag(channel,L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP_MTU); } else { - l2cap_send_signaling_packet(channel->handle, CONFIGURE_RESPONSE, channel->remote_sig_id, channel->remote_cid, flags, 0, 0, NULL); + l2cap_send_signaling_packet(channel->con_handle, CONFIGURE_RESPONSE, channel->remote_sig_id, channel->remote_cid, flags, 0, 0, NULL); } channelStateVarClearFlag(channel, L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP_CONT); } @@ -682,7 +682,7 @@ static void l2cap_run(void){ 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->handle, CONFIGURE_REQUEST, channel->local_sig_id, channel->remote_cid, 0, 4, &config_options); + 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)){ @@ -692,18 +692,18 @@ static void l2cap_run(void){ break; case L2CAP_STATE_WILL_SEND_DISCONNECT_RESPONSE: - if (!hci_can_send_acl_packet_now(channel->handle)) break; + if (!hci_can_send_acl_packet_now(channel->con_handle)) break; channel->state = L2CAP_STATE_INVALID; - l2cap_send_signaling_packet( channel->handle, DISCONNECTION_RESPONSE, channel->remote_sig_id, channel->local_cid, channel->remote_cid); + l2cap_send_signaling_packet( channel->con_handle, DISCONNECTION_RESPONSE, channel->remote_sig_id, channel->local_cid, channel->remote_cid); // we don't start an RTX timer for a disconnect - there's no point in closing the channel if the other side doesn't respond :) l2cap_finialize_channel_close(channel); // -- remove from list break; case L2CAP_STATE_WILL_SEND_DISCONNECT_REQUEST: - if (!hci_can_send_acl_packet_now(channel->handle)) break; + if (!hci_can_send_acl_packet_now(channel->con_handle)) break; channel->local_sig_id = l2cap_next_sig_id(); channel->state = L2CAP_STATE_WAIT_DISCONNECT; - l2cap_send_signaling_packet( channel->handle, DISCONNECTION_REQUEST, channel->local_sig_id, channel->remote_cid, channel->local_cid); + l2cap_send_signaling_packet( channel->con_handle, DISCONNECTION_REQUEST, channel->local_sig_id, channel->remote_cid, channel->local_cid); break; default: break; @@ -748,11 +748,11 @@ uint16_t l2cap_max_le_mtu(void){ return l2cap_max_mtu(); } -static void l2cap_handle_connection_complete(uint16_t handle, l2cap_channel_t * channel){ +static void l2cap_handle_connection_complete(hci_con_handle_t con_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"); // success, start l2cap handshake - channel->handle = handle; + channel->con_handle = con_handle; // check remote SSP feature first channel->state = L2CAP_STATE_WAIT_REMOTE_SUPPORTED_FEATURES; } @@ -763,10 +763,10 @@ static void l2cap_handle_remote_supported_features_received(l2cap_channel_t * ch // we have been waiting for remote supported features, if both support SSP, log_info("l2cap received remote supported features, sec_level_0_allowed for psm %u = %u", channel->psm, l2cap_security_level_0_allowed_for_PSM(channel->psm)); - if (gap_ssp_supported_on_both_sides(channel->handle) && !l2cap_security_level_0_allowed_for_PSM(channel->psm)){ + if (gap_ssp_supported_on_both_sides(channel->con_handle) && !l2cap_security_level_0_allowed_for_PSM(channel->psm)){ // request security level 2 channel->state = L2CAP_STATE_WAIT_OUTGOING_SECURITY_LEVEL_UPDATE; - gap_request_security_level(channel->handle, LEVEL_2); + gap_request_security_level(channel->con_handle, LEVEL_2); return; } // fine, go ahead @@ -785,50 +785,50 @@ uint8_t l2cap_create_channel(btstack_packet_handler_t channel_packet_handler, bd log_info("L2CAP_CREATE_CHANNEL addr %s psm 0x%x mtu %u", bd_addr_to_str(address), psm, mtu); // alloc structure - l2cap_channel_t * chan = btstack_memory_l2cap_channel_get(); - if (!chan) { + l2cap_channel_t * channel = btstack_memory_l2cap_channel_get(); + if (!channel) { return BTSTACK_MEMORY_ALLOC_FAILED; } // Init memory (make valgrind happy) - memset(chan, 0, sizeof(l2cap_channel_t)); + memset(channel, 0, sizeof(l2cap_channel_t)); // limit local mtu to max acl packet length - l2cap header if (mtu > l2cap_max_mtu()) { mtu = l2cap_max_mtu(); } // fill in - bd_addr_copy(chan->address, address); - chan->psm = psm; - chan->handle = 0; - chan->packet_handler = channel_packet_handler; - chan->remote_mtu = L2CAP_MINIMAL_MTU; - chan->local_mtu = mtu; - chan->local_cid = l2cap_next_local_cid(); + bd_addr_copy(channel->address, address); + channel->psm = psm; + channel->con_handle = 0; + channel->packet_handler = channel_packet_handler; + channel->remote_mtu = L2CAP_MINIMAL_MTU; + channel->local_mtu = mtu; + channel->local_cid = l2cap_next_local_cid(); // set initial state - chan->state = L2CAP_STATE_WILL_SEND_CREATE_CONNECTION; - chan->state_var = L2CAP_CHANNEL_STATE_VAR_NONE; - chan->remote_sig_id = L2CAP_SIG_ID_INVALID; - chan->local_sig_id = L2CAP_SIG_ID_INVALID; - chan->required_security_level = LEVEL_0; + channel->state = L2CAP_STATE_WILL_SEND_CREATE_CONNECTION; + channel->state_var = L2CAP_CHANNEL_STATE_VAR_NONE; + channel->remote_sig_id = L2CAP_SIG_ID_INVALID; + channel->local_sig_id = L2CAP_SIG_ID_INVALID; + channel->required_security_level = LEVEL_0; // add to connections list - btstack_linked_list_add(&l2cap_channels, (btstack_linked_item_t *) chan); + btstack_linked_list_add(&l2cap_channels, (btstack_linked_item_t *) channel); // store local_cid if (out_local_cid){ - *out_local_cid = chan->local_cid; + *out_local_cid = channel->local_cid; } // check if hci connection is already usable hci_connection_t * conn = hci_connection_for_bd_addr_and_type(address, BD_ADDR_TYPE_CLASSIC); if (conn){ log_info("l2cap_create_channel, hci connection already exists"); - l2cap_handle_connection_complete(conn->con_handle, chan); + l2cap_handle_connection_complete(conn->con_handle, channel); // check if remote supported fearures are already received if (conn->bonding_flags & BONDING_RECEIVED_REMOTE_FEATURES) { - l2cap_handle_remote_supported_features_received(chan); + l2cap_handle_remote_supported_features_received(channel); } } @@ -891,7 +891,7 @@ static void l2cap_notify_channel_can_send(void){ while (btstack_linked_list_iterator_has_next(&it)){ l2cap_channel_t * channel = (l2cap_channel_t *) btstack_linked_list_iterator_next(&it); if (!channel->waiting_for_can_send_now) continue; - if (!hci_can_send_acl_packet_now(channel->handle)) continue; + if (!hci_can_send_acl_packet_now(channel->con_handle)) continue; channel->waiting_for_can_send_now = 0; l2cap_emit_can_send_now(channel->packet_handler, channel->local_cid); } @@ -955,7 +955,7 @@ static void l2cap_hci_event_handler(uint8_t packet_type, uint16_t cid, uint8_t * btstack_linked_list_iterator_init(&it, &l2cap_channels); while (btstack_linked_list_iterator_has_next(&it)){ l2cap_channel_t * channel = (l2cap_channel_t *) btstack_linked_list_iterator_next(&it); - if (channel->handle != handle) continue; + if (channel->con_handle != handle) continue; l2cap_emit_channel_closed(channel); l2cap_stop_rtx(channel); btstack_linked_list_iterator_remove(&it); @@ -979,7 +979,7 @@ static void l2cap_hci_event_handler(uint8_t packet_type, uint16_t cid, uint8_t * btstack_linked_list_iterator_init(&it, &l2cap_channels); while (btstack_linked_list_iterator_has_next(&it)){ l2cap_channel_t * channel = (l2cap_channel_t *) btstack_linked_list_iterator_next(&it); - if (channel->handle != handle) continue; + if (channel->con_handle != handle) continue; hci_con_used = 1; break; } @@ -993,7 +993,7 @@ static void l2cap_hci_event_handler(uint8_t packet_type, uint16_t cid, uint8_t * btstack_linked_list_iterator_init(&it, &l2cap_channels); while (btstack_linked_list_iterator_has_next(&it)){ l2cap_channel_t * channel = (l2cap_channel_t *) btstack_linked_list_iterator_next(&it); - if (channel->handle != handle) continue; + if (channel->con_handle != handle) continue; l2cap_handle_remote_supported_features_received(channel); break; } @@ -1005,7 +1005,7 @@ static void l2cap_hci_event_handler(uint8_t packet_type, uint16_t cid, uint8_t * btstack_linked_list_iterator_init(&it, &l2cap_channels); while (btstack_linked_list_iterator_has_next(&it)){ l2cap_channel_t * channel = (l2cap_channel_t *) btstack_linked_list_iterator_next(&it); - if (channel->handle != handle) continue; + if (channel->con_handle != handle) continue; log_info("l2cap - state %u", channel->state); @@ -1093,7 +1093,7 @@ static void l2cap_handle_connection_request(hci_con_handle_t handle, uint8_t sig // fill in bd_addr_copy(channel->address, hci_connection->address); channel->psm = psm; - channel->handle = handle; + channel->con_handle = handle; channel->packet_handler = service->packet_handler; channel->local_cid = l2cap_next_local_cid(); channel->remote_cid = source_cid; @@ -1365,7 +1365,7 @@ static void l2cap_signaling_handler_dispatch( hci_con_handle_t handle, uint8_t * btstack_linked_list_iterator_init(&it, &l2cap_channels); while (btstack_linked_list_iterator_has_next(&it)){ l2cap_channel_t * channel = (l2cap_channel_t *) btstack_linked_list_iterator_next(&it); - if (channel->handle != handle) continue; + if (channel->con_handle != handle) continue; if (code & 1) { // match odd commands (responses) by previous signaling identifier if (channel->local_sig_id == sig_id) { diff --git a/src/l2cap.h b/src/l2cap.h index 6f4566003..0914cca65 100644 --- a/src/l2cap.h +++ b/src/l2cap.h @@ -113,7 +113,7 @@ typedef struct { // info bd_addr_t address; - hci_con_handle_t handle; + hci_con_handle_t con_handle; uint8_t remote_sig_id; // used by other side, needed for delayed response uint8_t local_sig_id; // own signaling identifier @@ -166,12 +166,12 @@ typedef struct l2cap_signaling_response { void l2cap_register_fixed_channel(btstack_packet_handler_t packet_handler, uint16_t channel_id); -int l2cap_can_send_fixed_channel_packet_now(uint16_t handle, uint16_t channel_id); -int l2cap_send_connectionless(uint16_t handle, uint16_t cid, uint8_t *data, uint16_t len); -int l2cap_send_prepared_connectionless(uint16_t handle, uint16_t cid, uint16_t len); +int l2cap_can_send_fixed_channel_packet_now(hci_con_handle_t con_handle, uint16_t channel_id); +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); // PTS Testing -int l2cap_send_echo_request(uint16_t handle, uint8_t *data, uint16_t len); +int l2cap_send_echo_request(hci_con_handle_t con_handle, uint8_t *data, uint16_t len); void l2cap_require_security_level_2_for_outgoing_sdp(void); /* API_START */