prefixed all linked list types and functions with btstack_

This commit is contained in:
Matthias Ringwald 2016-01-20 14:50:38 +01:00
parent 2c539f6e7e
commit 665d90f25e
37 changed files with 781 additions and 775 deletions

View File

@ -49,7 +49,7 @@ Implementation:
* if specified, call custom packet_handler instead of general one
* acl -> l2cap -> l2cap_channel -> acl/event handler OR daemon
* LinkedList of service records
* alloc { linked_list_item_t ; ServiceRecord }
* alloc { btstack_linked_list_item_t ; ServiceRecord }
* add service record: service record -> service record handle or 0
* remove service record: service record handle (32bit)
* SDP as part of stack itself

View File

@ -96,7 +96,7 @@ void run_loop_cocoa_add_data_source(data_source_t *dataSource){
// create run loop source
CFRunLoopSourceRef socketRunLoop = CFSocketCreateRunLoopSource ( kCFAllocatorDefault, socket, 0);
// hack: store CFSocketRef in "next" and CFRunLoopSourceRef in "user_data" of linked_item_t
// hack: store CFSocketRef in "next" and CFRunLoopSourceRef in "user_data" of btstack_linked_item_t
dataSource->item.next = (void *) socket;
dataSource->item.user_data = (void *) socketRunLoop;

View File

@ -120,17 +120,17 @@
typedef struct {
// linked list - assert: first field
linked_item_t item;
btstack_linked_item_t item;
// connection
connection_t * connection;
btstack_linked_list_t rfcomm_cids;
btstack_linked_list_t rfcomm_services;
btstack_linked_list_t l2cap_cids;
btstack_linked_list_t l2cap_psms;
btstack_linked_list_t sdp_record_handles;
btstack_linked_list_t gatt_con_handles;
btstack_btstack_linked_list_t rfcomm_cids;
btstack_btstack_linked_list_t rfcomm_services;
btstack_btstack_linked_list_t l2cap_cids;
btstack_btstack_linked_list_t l2cap_psms;
btstack_btstack_linked_list_t sdp_record_handles;
btstack_btstack_linked_list_t gatt_con_handles;
// power mode
HCI_POWER_MODE power_mode;
@ -139,26 +139,26 @@ typedef struct {
} client_state_t;
typedef struct linked_list_uint32 {
linked_item_t item;
typedef struct btstack_linked_list_uint32 {
btstack_linked_item_t item;
uint32_t value;
} linked_list_uint32_t;
} btstack_linked_list_uint32_t;
typedef struct linked_list_connection {
linked_item_t item;
typedef struct btstack_linked_list_connection {
btstack_linked_item_t item;
connection_t * connection;
} linked_list_connection_t;
} btstack_linked_list_connection_t;
typedef struct linked_list_gatt_client_helper{
linked_item_t item;
typedef struct btstack_linked_list_gatt_client_helper{
btstack_linked_item_t item;
uint16_t con_handle;
connection_t * active_connection; // the one that started the current query
btstack_linked_list_t all_connections; // list of all connections that ever used this helper
btstack_btstack_linked_list_t all_connections; // list of all connections that ever used this helper
uint16_t characteristic_length;
uint16_t characteristic_handle;
uint8_t characteristic_buffer[10 + ATT_MAX_LONG_ATTRIBUTE_SIZE]; // header for sending event right away
uint8_t long_query_type;
} linked_list_gatt_client_helper_t;
} btstack_linked_list_gatt_client_helper_t;
// MARK: prototypes
static void handle_sdp_rfcomm_service_result(sdp_query_event_t * event, void * context);
@ -179,9 +179,9 @@ static hci_transport_config_uart_t hci_transport_config_uart;
static timer_source_t timeout;
static uint8_t timeout_active = 0;
static int power_management_sleep = 0;
static btstack_linked_list_t clients = NULL; // list of connected clients `
static btstack_btstack_linked_list_t clients = NULL; // list of connected clients `
#ifdef HAVE_BLE
static btstack_linked_list_t gatt_client_helpers = NULL; // list of used gatt client (helpers)
static btstack_btstack_linked_list_t gatt_client_helpers = NULL; // list of used gatt client (helpers)
static uint16_t gatt_client_id = 0;
#endif
@ -216,10 +216,10 @@ static void l2cap_emit_credits(l2cap_channel_t *channel, uint8_t credits) {
}
static void l2cap_hand_out_credits(void){
linked_list_iterator_t it;
linked_list_iterator_init(&it, &l2cap_channels);
while (linked_list_iterator_has_next(&it)){
l2cap_channel_t * channel = (l2cap_channel_t *) linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
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->state != L2CAP_STATE_OPEN) continue;
if (!hci_number_free_acl_slots_for_handle(channel->handle)) return;
l2cap_emit_credits(channel, 1);
@ -236,8 +236,8 @@ static void rfcomm_emit_credits(rfcomm_channel_t * channel, uint8_t credits) {
(*app_packet_handler)(HCI_EVENT_PACKET, 0, (uint8_t *) event, sizeof(event));
}
static void rfcomm_hand_out_credits(void){
linked_item_t * it;
for (it = (linked_item_t *) rfcomm_channels; it ; it = it->next){
btstack_linked_item_t * it;
for (it = (btstack_linked_item_t *) rfcomm_channels; it ; it = it->next){
rfcomm_channel_t * channel = (rfcomm_channel_t *) it;
if (channel->state != RFCOMM_CHANNEL_OPEN) {
// log_info("RFCOMM_EVENT_CREDITS: multiplexer not open");
@ -266,27 +266,27 @@ static void daemon_no_connections_timeout(struct timer *ts){
}
static void add_uint32_to_list(btstack_linked_list_t *list, uint32_t value){
linked_list_iterator_t it;
linked_list_iterator_init(&it, list);
while (linked_list_iterator_has_next(&it)){
linked_list_uint32_t * item = (linked_list_uint32_t*) linked_list_iterator_next(&it);
static void add_uint32_to_list(btstack_btstack_linked_list_t *list, uint32_t value){
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, list);
while (btstack_linked_list_iterator_has_next(&it)){
btstack_linked_list_uint32_t * item = (btstack_linked_list_uint32_t*) btstack_linked_list_iterator_next(&it);
if ( item->value == value) return; // already in list
}
linked_list_uint32_t * item = malloc(sizeof(linked_list_uint32_t));
btstack_linked_list_uint32_t * item = malloc(sizeof(btstack_linked_list_uint32_t));
if (!item) return;
item->value = value;
linked_list_add(list, (linked_item_t *) item);
btstack_linked_list_add(list, (btstack_linked_item_t *) item);
}
static void remove_and_free_uint32_from_list(btstack_linked_list_t *list, uint32_t value){
linked_list_iterator_t it;
linked_list_iterator_init(&it, list);
while (linked_list_iterator_has_next(&it)){
linked_list_uint32_t * item = (linked_list_uint32_t*) linked_list_iterator_next(&it);
static void remove_and_free_uint32_from_list(btstack_btstack_linked_list_t *list, uint32_t value){
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, list);
while (btstack_linked_list_iterator_has_next(&it)){
btstack_linked_list_uint32_t * item = (btstack_linked_list_uint32_t*) btstack_linked_list_iterator_next(&it);
if ( item->value != value) continue;
linked_list_remove(list, (linked_item_t *) item);
btstack_linked_list_remove(list, (btstack_linked_item_t *) item);
free(item);
}
}
@ -357,11 +357,11 @@ static void daemon_add_gatt_client_handle(connection_t * connection, uint32_t ha
if (!client_state) return;
// check if handle already exists in the gatt_con_handles list
linked_list_iterator_t it;
btstack_linked_list_iterator_t it;
int handle_found = 0;
linked_list_iterator_init(&it, &client_state->gatt_con_handles);
while (linked_list_iterator_has_next(&it)){
linked_list_uint32_t * item = (linked_list_uint32_t*) linked_list_iterator_next(&it);
btstack_linked_list_iterator_init(&it, &client_state->gatt_con_handles);
while (btstack_linked_list_iterator_has_next(&it)){
btstack_linked_list_uint32_t * item = (btstack_linked_list_uint32_t*) btstack_linked_list_iterator_next(&it);
if (item->value == handle){
handle_found = 1;
break;
@ -373,10 +373,10 @@ static void daemon_add_gatt_client_handle(connection_t * connection, uint32_t ha
}
// check if there is a helper with given handle
linked_list_gatt_client_helper_t * gatt_helper = NULL;
linked_list_iterator_init(&it, &gatt_client_helpers);
while (linked_list_iterator_has_next(&it)){
linked_list_gatt_client_helper_t * item = (linked_list_gatt_client_helper_t*) linked_list_iterator_next(&it);
btstack_linked_list_gatt_client_helper_t * gatt_helper = NULL;
btstack_linked_list_iterator_init(&it, &gatt_client_helpers);
while (btstack_linked_list_iterator_has_next(&it)){
btstack_linked_list_gatt_client_helper_t * item = (btstack_linked_list_gatt_client_helper_t*) btstack_linked_list_iterator_next(&it);
if (item->con_handle == handle){
gatt_helper = item;
break;
@ -385,18 +385,18 @@ static void daemon_add_gatt_client_handle(connection_t * connection, uint32_t ha
// if gatt_helper doesn't exist, create it and add it to gatt_client_helpers list
if (!gatt_helper){
gatt_helper = malloc(sizeof(linked_list_gatt_client_helper_t));
gatt_helper = malloc(sizeof(btstack_linked_list_gatt_client_helper_t));
if (!gatt_helper) return;
memset(gatt_helper, 0, sizeof(linked_list_gatt_client_helper_t));
memset(gatt_helper, 0, sizeof(btstack_linked_list_gatt_client_helper_t));
gatt_helper->con_handle = handle;
linked_list_add(&gatt_client_helpers, (linked_item_t *) gatt_helper);
btstack_linked_list_add(&gatt_client_helpers, (btstack_linked_item_t *) gatt_helper);
}
// check if connection exists
int connection_found = 0;
linked_list_iterator_init(&it, &gatt_helper->all_connections);
while (linked_list_iterator_has_next(&it)){
linked_list_connection_t * item = (linked_list_connection_t*) linked_list_iterator_next(&it);
btstack_linked_list_iterator_init(&it, &gatt_helper->all_connections);
while (btstack_linked_list_iterator_has_next(&it)){
btstack_linked_list_connection_t * item = (btstack_linked_list_connection_t*) btstack_linked_list_iterator_next(&it);
if (item->connection == connection){
connection_found = 1;
break;
@ -405,11 +405,11 @@ static void daemon_add_gatt_client_handle(connection_t * connection, uint32_t ha
// if connection is not found, add it to the all_connections, and set it as active connection
if (!connection_found){
linked_list_connection_t * con = malloc(sizeof(linked_list_connection_t));
btstack_linked_list_connection_t * con = malloc(sizeof(btstack_linked_list_connection_t));
if (!con) return;
memset(con, 0, sizeof(linked_list_connection_t));
memset(con, 0, sizeof(btstack_linked_list_connection_t));
con->connection = connection;
linked_list_add(&gatt_helper->all_connections, (linked_item_t *)con);
btstack_linked_list_add(&gatt_helper->all_connections, (btstack_linked_item_t *)con);
}
}
@ -420,13 +420,13 @@ static void daemon_remove_gatt_client_handle(connection_t * connection, uint32_t
client_state_t * client_state = client_for_connection(connection);
if (!client_state) return;
linked_list_iterator_t it;
btstack_linked_list_iterator_t it;
// remove handle from gatt_con_handles list
linked_list_iterator_init(&it, &client_state->gatt_con_handles);
while (linked_list_iterator_has_next(&it)){
linked_list_uint32_t * item = (linked_list_uint32_t*) linked_list_iterator_next(&it);
btstack_linked_list_iterator_init(&it, &client_state->gatt_con_handles);
while (btstack_linked_list_iterator_has_next(&it)){
btstack_linked_list_uint32_t * item = (btstack_linked_list_uint32_t*) btstack_linked_list_iterator_next(&it);
if (item->value == handle){
linked_list_remove(&client_state->gatt_con_handles, (linked_item_t *) item);
btstack_linked_list_remove(&client_state->gatt_con_handles, (btstack_linked_item_t *) item);
free(item);
}
}
@ -434,10 +434,10 @@ static void daemon_remove_gatt_client_handle(connection_t * connection, uint32_t
// PART 2 - only uses handle
// find helper with given handle
linked_list_gatt_client_helper_t * helper = NULL;
linked_list_iterator_init(&it, &gatt_client_helpers);
while (linked_list_iterator_has_next(&it)){
linked_list_gatt_client_helper_t * item = (linked_list_gatt_client_helper_t*) linked_list_iterator_next(&it);
btstack_linked_list_gatt_client_helper_t * helper = NULL;
btstack_linked_list_iterator_init(&it, &gatt_client_helpers);
while (btstack_linked_list_iterator_has_next(&it)){
btstack_linked_list_gatt_client_helper_t * item = (btstack_linked_list_gatt_client_helper_t*) btstack_linked_list_iterator_next(&it);
if (item->con_handle == handle){
helper = item;
break;
@ -446,11 +446,11 @@ static void daemon_remove_gatt_client_handle(connection_t * connection, uint32_t
if (!helper) return;
// remove connection from helper
linked_list_iterator_init(&it, &helper->all_connections);
while (linked_list_iterator_has_next(&it)){
linked_list_connection_t * item = (linked_list_connection_t*) linked_list_iterator_next(&it);
btstack_linked_list_iterator_init(&it, &helper->all_connections);
while (btstack_linked_list_iterator_has_next(&it)){
btstack_linked_list_connection_t * item = (btstack_linked_list_connection_t*) btstack_linked_list_iterator_next(&it);
if (item->connection == connection){
linked_list_remove(&helper->all_connections, (linked_item_t *) item);
btstack_linked_list_remove(&helper->all_connections, (btstack_linked_item_t *) item);
free(item);
break;
}
@ -467,12 +467,12 @@ static void daemon_remove_gatt_client_handle(connection_t * connection, uint32_t
static void daemon_remove_gatt_client_helper(uint32_t con_handle){
linked_list_iterator_t it, cl;
btstack_linked_list_iterator_t it, cl;
// find helper with given handle
linked_list_gatt_client_helper_t * helper = NULL;
linked_list_iterator_init(&it, &gatt_client_helpers);
while (linked_list_iterator_has_next(&it)){
linked_list_gatt_client_helper_t * item = (linked_list_gatt_client_helper_t*) linked_list_iterator_next(&it);
btstack_linked_list_gatt_client_helper_t * helper = NULL;
btstack_linked_list_iterator_init(&it, &gatt_client_helpers);
while (btstack_linked_list_iterator_has_next(&it)){
btstack_linked_list_gatt_client_helper_t * item = (btstack_linked_list_gatt_client_helper_t*) btstack_linked_list_iterator_next(&it);
if (item->con_handle == con_handle){
helper = item;
break;
@ -482,24 +482,24 @@ static void daemon_remove_gatt_client_helper(uint32_t con_handle){
if (!helper) return;
// remove all connection from helper
linked_list_iterator_init(&it, &helper->all_connections);
while (linked_list_iterator_has_next(&it)){
linked_list_connection_t * item = (linked_list_connection_t*) linked_list_iterator_next(&it);
linked_list_remove(&helper->all_connections, (linked_item_t *) item);
btstack_linked_list_iterator_init(&it, &helper->all_connections);
while (btstack_linked_list_iterator_has_next(&it)){
btstack_linked_list_connection_t * item = (btstack_linked_list_connection_t*) btstack_linked_list_iterator_next(&it);
btstack_linked_list_remove(&helper->all_connections, (btstack_linked_item_t *) item);
free(item);
}
linked_list_remove(&gatt_client_helpers, (linked_item_t *) helper);
btstack_linked_list_remove(&gatt_client_helpers, (btstack_linked_item_t *) helper);
free(helper);
linked_list_iterator_init(&cl, &clients);
while (linked_list_iterator_has_next(&cl)){
client_state_t * client_state = (client_state_t *) linked_list_iterator_next(&cl);
linked_list_iterator_init(&it, &client_state->gatt_con_handles);
while (linked_list_iterator_has_next(&it)){
linked_list_uint32_t * item = (linked_list_uint32_t*) linked_list_iterator_next(&it);
btstack_linked_list_iterator_init(&cl, &clients);
while (btstack_linked_list_iterator_has_next(&cl)){
client_state_t * client_state = (client_state_t *) btstack_linked_list_iterator_next(&cl);
btstack_linked_list_iterator_init(&it, &client_state->gatt_con_handles);
while (btstack_linked_list_iterator_has_next(&it)){
btstack_linked_list_uint32_t * item = (btstack_linked_list_uint32_t*) btstack_linked_list_iterator_next(&it);
if (item->value == con_handle){
linked_list_remove(&client_state->gatt_con_handles, (linked_item_t *) item);
btstack_linked_list_remove(&client_state->gatt_con_handles, (btstack_linked_item_t *) item);
free(item);
}
}
@ -508,71 +508,71 @@ static void daemon_remove_gatt_client_helper(uint32_t con_handle){
#endif
static void daemon_rfcomm_close_connection(client_state_t * daemon_client){
linked_list_iterator_t it;
btstack_linked_list_t *rfcomm_services = &daemon_client->rfcomm_services;
btstack_linked_list_t *rfcomm_cids = &daemon_client->rfcomm_cids;
btstack_linked_list_iterator_t it;
btstack_btstack_linked_list_t *rfcomm_services = &daemon_client->rfcomm_services;
btstack_btstack_linked_list_t *rfcomm_cids = &daemon_client->rfcomm_cids;
linked_list_iterator_init(&it, rfcomm_services);
while (linked_list_iterator_has_next(&it)){
linked_list_uint32_t * item = (linked_list_uint32_t*) linked_list_iterator_next(&it);
btstack_linked_list_iterator_init(&it, rfcomm_services);
while (btstack_linked_list_iterator_has_next(&it)){
btstack_linked_list_uint32_t * item = (btstack_linked_list_uint32_t*) btstack_linked_list_iterator_next(&it);
rfcomm_unregister_service(item->value);
linked_list_remove(rfcomm_services, (linked_item_t *) item);
btstack_linked_list_remove(rfcomm_services, (btstack_linked_item_t *) item);
free(item);
}
linked_list_iterator_init(&it, rfcomm_cids);
while (linked_list_iterator_has_next(&it)){
linked_list_uint32_t * item = (linked_list_uint32_t*) linked_list_iterator_next(&it);
btstack_linked_list_iterator_init(&it, rfcomm_cids);
while (btstack_linked_list_iterator_has_next(&it)){
btstack_linked_list_uint32_t * item = (btstack_linked_list_uint32_t*) btstack_linked_list_iterator_next(&it);
rfcomm_disconnect_internal(item->value);
linked_list_remove(rfcomm_cids, (linked_item_t *) item);
btstack_linked_list_remove(rfcomm_cids, (btstack_linked_item_t *) item);
free(item);
}
}
static void daemon_l2cap_close_connection(client_state_t * daemon_client){
linked_list_iterator_t it;
btstack_linked_list_t *l2cap_psms = &daemon_client->l2cap_psms;
btstack_linked_list_t *l2cap_cids = &daemon_client->l2cap_cids;
btstack_linked_list_iterator_t it;
btstack_btstack_linked_list_t *l2cap_psms = &daemon_client->l2cap_psms;
btstack_btstack_linked_list_t *l2cap_cids = &daemon_client->l2cap_cids;
linked_list_iterator_init(&it, l2cap_psms);
while (linked_list_iterator_has_next(&it)){
linked_list_uint32_t * item = (linked_list_uint32_t*) linked_list_iterator_next(&it);
btstack_linked_list_iterator_init(&it, l2cap_psms);
while (btstack_linked_list_iterator_has_next(&it)){
btstack_linked_list_uint32_t * item = (btstack_linked_list_uint32_t*) btstack_linked_list_iterator_next(&it);
l2cap_unregister_service(item->value);
linked_list_remove(l2cap_psms, (linked_item_t *) item);
btstack_linked_list_remove(l2cap_psms, (btstack_linked_item_t *) item);
free(item);
}
linked_list_iterator_init(&it, l2cap_cids);
while (linked_list_iterator_has_next(&it)){
linked_list_uint32_t * item = (linked_list_uint32_t*) linked_list_iterator_next(&it);
btstack_linked_list_iterator_init(&it, l2cap_cids);
while (btstack_linked_list_iterator_has_next(&it)){
btstack_linked_list_uint32_t * item = (btstack_linked_list_uint32_t*) btstack_linked_list_iterator_next(&it);
l2cap_disconnect_internal(item->value, 0); // note: reason isn't used
linked_list_remove(l2cap_cids, (linked_item_t *) item);
btstack_linked_list_remove(l2cap_cids, (btstack_linked_item_t *) item);
free(item);
}
}
static void daemon_sdp_close_connection(client_state_t * daemon_client){
btstack_linked_list_t * list = &daemon_client->sdp_record_handles;
linked_list_iterator_t it;
linked_list_iterator_init(&it, list);
while (linked_list_iterator_has_next(&it)){
linked_list_uint32_t * item = (linked_list_uint32_t*) linked_list_iterator_next(&it);
btstack_btstack_linked_list_t * list = &daemon_client->sdp_record_handles;
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, list);
while (btstack_linked_list_iterator_has_next(&it)){
btstack_linked_list_uint32_t * item = (btstack_linked_list_uint32_t*) btstack_linked_list_iterator_next(&it);
sdp_unregister_service(item->value);
linked_list_remove(list, (linked_item_t *) item);
btstack_linked_list_remove(list, (btstack_linked_item_t *) item);
free(item);
}
}
static connection_t * connection_for_l2cap_cid(uint16_t cid){
linked_list_iterator_t cl;
linked_list_iterator_init(&cl, &clients);
while (linked_list_iterator_has_next(&cl)){
client_state_t * client_state = (client_state_t *) linked_list_iterator_next(&cl);
linked_list_iterator_t it;
linked_list_iterator_init(&it, &client_state->l2cap_cids);
while (linked_list_iterator_has_next(&it)){
linked_list_uint32_t * item = (linked_list_uint32_t*) linked_list_iterator_next(&it);
btstack_linked_list_iterator_t cl;
btstack_linked_list_iterator_init(&cl, &clients);
while (btstack_linked_list_iterator_has_next(&cl)){
client_state_t * client_state = (client_state_t *) btstack_linked_list_iterator_next(&cl);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, &client_state->l2cap_cids);
while (btstack_linked_list_iterator_has_next(&it)){
btstack_linked_list_uint32_t * item = (btstack_linked_list_uint32_t*) btstack_linked_list_iterator_next(&it);
if (item->value == cid){
return client_state->connection;
}
@ -621,14 +621,14 @@ static uint32_t daemon_sdp_create_and_register_service(uint8_t * record){
}
static connection_t * connection_for_rfcomm_cid(uint16_t cid){
linked_list_iterator_t cl;
linked_list_iterator_init(&cl, &clients);
while (linked_list_iterator_has_next(&cl)){
client_state_t * client_state = (client_state_t *) linked_list_iterator_next(&cl);
linked_list_iterator_t it;
linked_list_iterator_init(&it, &client_state->rfcomm_cids);
while (linked_list_iterator_has_next(&it)){
linked_list_uint32_t * item = (linked_list_uint32_t*) linked_list_iterator_next(&it);
btstack_linked_list_iterator_t cl;
btstack_linked_list_iterator_init(&cl, &clients);
while (btstack_linked_list_iterator_has_next(&cl)){
client_state_t * client_state = (client_state_t *) btstack_linked_list_iterator_next(&cl);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, &client_state->rfcomm_cids);
while (btstack_linked_list_iterator_has_next(&it)){
btstack_linked_list_uint32_t * item = (btstack_linked_list_uint32_t*) btstack_linked_list_iterator_next(&it);
if (item->value == cid){
return client_state->connection;
}
@ -642,10 +642,10 @@ static void daemon_gatt_client_close_connection(connection_t * connection){
client_state_t * client = client_for_connection(connection);
if (!client) return;
linked_list_iterator_t it;
linked_list_iterator_init(&it, &client->gatt_con_handles);
while (linked_list_iterator_has_next(&it)){
linked_list_uint32_t * item = (linked_list_uint32_t*) linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, &client->gatt_con_handles);
while (btstack_linked_list_iterator_has_next(&it)){
btstack_linked_list_uint32_t * item = (btstack_linked_list_uint32_t*) btstack_linked_list_iterator_next(&it);
daemon_remove_gatt_client_handle(connection, item->value);
}
}
@ -666,7 +666,7 @@ static void daemon_disconnect_client(connection_t * connection){
daemon_gatt_client_close_connection(connection);
#endif
linked_list_remove(&clients, (linked_item_t *) client);
btstack_linked_list_remove(&clients, (btstack_linked_item_t *) client);
free(client);
}
@ -740,14 +740,14 @@ static void sdp_emit_service_registered(void *connection, uint32_t handle, uint8
#ifdef HAVE_BLE
linked_list_gatt_client_helper_t * daemon_get_gatt_client_helper(uint16_t handle) {
linked_list_iterator_t it;
btstack_linked_list_gatt_client_helper_t * daemon_get_gatt_client_helper(uint16_t 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);
linked_list_iterator_init(&it, &gatt_client_helpers);
while (linked_list_iterator_has_next(&it)){
linked_list_gatt_client_helper_t * item = (linked_list_gatt_client_helper_t*) linked_list_iterator_next(&it);
btstack_linked_list_iterator_init(&it, &gatt_client_helpers);
while (btstack_linked_list_iterator_has_next(&it)){
btstack_linked_list_gatt_client_helper_t * item = (btstack_linked_list_gatt_client_helper_t*) btstack_linked_list_iterator_next(&it);
if (!item ) {
log_info("daemon_get_gatt_client_helper gatt_client_helpers null item");
break;
@ -784,7 +784,7 @@ static void send_gatt_mtu_event(connection_t * connection, uint16_t handle, uint
socket_connection_send_packet(connection, HCI_EVENT_PACKET, 0, event, sizeof(event));
}
linked_list_gatt_client_helper_t * daemon_setup_gatt_client_request(connection_t *connection, uint8_t *packet, int track_active_connection) {
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 = READ_BT_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);
@ -793,15 +793,15 @@ linked_list_gatt_client_helper_t * daemon_setup_gatt_client_request(connection_t
return NULL;
}
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(handle);
if (!helper){
log_info("helper does not exist");
helper = malloc(sizeof(linked_list_gatt_client_helper_t));
helper = malloc(sizeof(btstack_linked_list_gatt_client_helper_t));
if (!helper) return NULL;
memset(helper, 0, sizeof(linked_list_gatt_client_helper_t));
memset(helper, 0, sizeof(btstack_linked_list_gatt_client_helper_t));
helper->con_handle = handle;
linked_list_add(&gatt_client_helpers, (linked_item_t *) helper);
btstack_linked_list_add(&gatt_client_helpers, (btstack_linked_item_t *) helper);
}
if (track_active_connection && helper->active_connection){
@ -884,7 +884,7 @@ static int btstack_command_handler(connection_t *connection, uint8_t *packet, ui
le_characteristic_t characteristic;
le_characteristic_descriptor_t descriptor;
uint16_t data_length;
linked_list_gatt_client_helper_t * gatt_helper;
btstack_linked_list_gatt_client_helper_t * gatt_helper;
#endif
uint16_t serviceSearchPatternLen;
@ -1322,7 +1322,7 @@ static int daemon_client_handler(connection_t *connection, uint16_t packet_type,
client->connection = connection;
client->power_mode = HCI_POWER_OFF;
client->discoverable = 0;
linked_list_add(&clients, (linked_item_t *) client);
btstack_linked_list_add(&clients, (btstack_linked_item_t *) client);
break;
case DAEMON_EVENT_CONNECTION_CLOSED:
log_info("DAEMON_EVENT_CONNECTION_CLOSED %p\n",connection);
@ -1708,8 +1708,8 @@ static void start_power_off_timer(void){
static client_state_t * client_for_connection(connection_t *connection) {
linked_item_t *it;
for (it = (linked_item_t *) clients; it ; it = it->next){
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) clients; it ; it = it->next){
client_state_t * client_state = (client_state_t *) it;
if (client_state->connection == connection) {
return client_state;
@ -1719,8 +1719,8 @@ static client_state_t * client_for_connection(connection_t *connection) {
}
static void clients_clear_power_request(void){
linked_item_t *it;
for (it = (linked_item_t *) clients; it ; it = it->next){
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) clients; it ; it = it->next){
client_state_t * client_state = (client_state_t *) it;
client_state->power_mode = HCI_POWER_OFF;
}
@ -1730,8 +1730,8 @@ static int clients_require_power_on(void){
if (global_enable) return 1;
linked_item_t *it;
for (it = (linked_item_t *) clients; it ; it = it->next){
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) clients; it ; it = it->next){
client_state_t * client_state = (client_state_t *) it;
if (client_state->power_mode == HCI_POWER_ON) {
return 1;
@ -1741,8 +1741,8 @@ static int clients_require_power_on(void){
}
static int clients_require_discoverable(void){
linked_item_t *it;
for (it = (linked_item_t *) clients; it ; it = it->next){
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) clients; it ; it = it->next){
client_state_t * client_state = (client_state_t *) it;
if (client_state->discoverable) {
return 1;
@ -1798,7 +1798,7 @@ static void handle_gatt_client_event(uint8_t packet_type, uint8_t * packet, uint
}
uint16_t con_handle = READ_BT_16(packet, 2);
linked_list_gatt_client_helper_t * gatt_client_helper = daemon_get_gatt_client_helper(con_handle);
btstack_linked_list_gatt_client_helper_t * gatt_client_helper = daemon_get_gatt_client_helper(con_handle);
if (!gatt_client_helper){
log_info("daemon handle_gatt_client_event: gc helper for handle 0x%2x is NULL.", con_handle);
return;
@ -1812,8 +1812,8 @@ static void handle_gatt_client_event(uint8_t packet_type, uint8_t * packet, uint
case GATT_INDICATION:{
hci_dump_packet(HCI_EVENT_PACKET, 0, packet, size);
linked_item_t *it;
for (it = (linked_item_t *) clients; it ; it = it->next){
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) clients; it ; it = it->next){
client_state_t * client_state = (client_state_t *) it;
socket_connection_send_packet(client_state->connection, HCI_EVENT_PACKET, 0, packet, size);
}

View File

@ -46,7 +46,7 @@
#include "btstack_linked_list.h"
// This lists should be only accessed by tests.
static btstack_linked_list_t db_mem_services = NULL;
static btstack_btstack_linked_list_t db_mem_services = NULL;
// Device info
static void db_open(void){
@ -58,11 +58,11 @@ static void db_close(void){
// MARK: PERSISTENT RFCOMM CHANNEL ALLOCATION
uint8_t rfcomm_service_db_channel_for_service(const char *serviceName){
linked_item_t *it;
btstack_linked_item_t *it;
db_mem_service_t * item;
uint8_t max_channel = 1;
for (it = (linked_item_t *) db_mem_services; it ; it = it->next){
for (it = (btstack_linked_item_t *) db_mem_services; it ; it = it->next){
item = (db_mem_service_t *) it;
if (strncmp(item->service_name, serviceName, MAX_NAME_LEN) == 0) {
// Match found
@ -80,6 +80,6 @@ uint8_t rfcomm_service_db_channel_for_service(const char *serviceName){
strncpy(newItem->service_name, serviceName, MAX_NAME_LEN);
newItem->channel = max_channel;
linked_list_add(&db_mem_services, (linked_item_t *) newItem);
btstack_linked_list_add(&db_mem_services, (btstack_linked_item_t *) newItem);
return max_channel;
}

View File

@ -112,7 +112,7 @@ typedef enum {
struct connection {
data_source_t ds; // used for run loop
linked_item_t item; // used for connection list, user_data points to connection_t base
btstack_linked_item_t item; // used for connection list, user_data points to connection_t base
SOCKET_STATE state;
uint16_t bytes_read;
uint16_t bytes_to_read;
@ -120,8 +120,8 @@ struct connection {
};
/** list of socket connections */
static btstack_linked_list_t connections = NULL;
static btstack_linked_list_t parked = NULL;
static btstack_btstack_linked_list_t connections = NULL;
static btstack_btstack_linked_list_t parked = NULL;
/** client packet handler */
@ -144,7 +144,7 @@ void socket_connection_free_connection(connection_t *conn){
run_loop_remove_data_source(&conn->ds);
// and from connection list
linked_list_remove(&connections, &conn->item);
btstack_linked_list_remove(&connections, &conn->item);
// destroy
free(conn);
@ -161,7 +161,7 @@ connection_t * socket_connection_register_new_connection(int fd){
// create connection objec
connection_t * conn = malloc( sizeof(connection_t));
if (conn == NULL) return 0;
linked_item_set_user( &conn->item, conn);
btstack_linked_item_set_user( &conn->item, conn);
conn->ds.fd = fd;
conn->ds.process = socket_connection_hci_process;
@ -172,7 +172,7 @@ connection_t * socket_connection_register_new_connection(int fd){
run_loop_add_data_source( &conn->ds );
// and the connection list
linked_list_add( &connections, &conn->item);
btstack_linked_list_add( &connections, &conn->item);
return conn;
}
@ -190,9 +190,9 @@ void static socket_connection_emit_connection_closed(connection_t *connection){
}
void static socket_connection_emit_nr_connections(void){
linked_item_t *it;
btstack_linked_item_t *it;
uint8_t nr_connections = 0;
for (it = (linked_item_t *) connections; it != NULL ; it = it->next, nr_connections++);
for (it = (btstack_linked_item_t *) connections; it != NULL ; it = it->next, nr_connections++);
uint8_t event[2];
event[0] = DAEMON_NR_CONNECTIONS_CHANGED;
@ -210,7 +210,7 @@ int socket_connection_hci_process(struct data_source *ds) {
socket_connection_emit_connection_closed(conn);
// free connection
socket_connection_free_connection(linked_item_get_user(&conn->item));
socket_connection_free_connection(btstack_linked_item_get_user(&conn->item));
socket_connection_emit_nr_connections();
return 0;
@ -250,7 +250,7 @@ int socket_connection_hci_process(struct data_source *ds) {
if (dispatch_err) {
log_info("socket_connection_hci_process dispatch failed -> park connection");
run_loop_remove_data_source(ds);
linked_list_add_tail(&parked, (linked_item_t *) ds);
btstack_linked_list_add_tail(&parked, (btstack_linked_item_t *) ds);
}
}
return 0;
@ -263,7 +263,7 @@ int socket_connection_hci_process(struct data_source *ds) {
*/
void socket_connection_retry_parked(void){
// log_info("socket_connection_hci_process retry parked");
linked_item_t *it = (linked_item_t *) &parked;
btstack_linked_item_t *it = (btstack_linked_item_t *) &parked;
while (it->next) {
connection_t * conn = (connection_t *) it->next;
@ -534,11 +534,11 @@ void socket_connection_send_packet(connection_t *conn, uint16_t type, uint16_t c
* send HCI packet to all connections
*/
void socket_connection_send_packet_all(uint16_t type, uint16_t channel, uint8_t *packet, uint16_t size){
linked_item_t *next;
linked_item_t *it;
for (it = (linked_item_t *) connections; it ; it = next){
btstack_linked_item_t *next;
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) connections; it ; it = next){
next = it->next; // cache pointer to next connection_t to allow for removal
socket_connection_send_packet( (connection_t *) linked_item_get_user(it), type, channel, packet, size);
socket_connection_send_packet( (connection_t *) btstack_linked_item_get_user(it), type, channel, packet, size);
}
}

View File

@ -79,10 +79,10 @@
static const run_loop_t run_loop_embedded;
// the run loop
static btstack_linked_list_t data_sources;
static btstack_btstack_linked_list_t data_sources;
#ifdef TIMER_SUPPORT
static btstack_linked_list_t timers;
static btstack_btstack_linked_list_t timers;
#endif
#ifdef HAVE_TICK
@ -95,14 +95,14 @@ static int trigger_event_received = 0;
* Add data_source to run_loop
*/
static void run_loop_embedded_add_data_source(data_source_t *ds){
linked_list_add(&data_sources, (linked_item_t *) ds);
btstack_linked_list_add(&data_sources, (btstack_linked_item_t *) ds);
}
/**
* Remove data_source from run loop
*/
static int run_loop_embedded_remove_data_source(data_source_t *ds){
return linked_list_remove(&data_sources, (linked_item_t *) ds);
return btstack_linked_list_remove(&data_sources, (btstack_linked_item_t *) ds);
}
// set timer
@ -123,8 +123,8 @@ static void run_loop_embedded_set_timer(timer_source_t *ts, uint32_t timeout_in_
*/
static void run_loop_embedded_add_timer(timer_source_t *ts){
#ifdef TIMER_SUPPORT
linked_item_t *it;
for (it = (linked_item_t *) &timers; it->next ; it = it->next){
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) &timers; it->next ; it = it->next){
// don't add timer that's already in there
if ((timer_source_t *) it->next == ts){
log_error( "run_loop_timer_add error: timer to add already in list!");
@ -135,7 +135,7 @@ static void run_loop_embedded_add_timer(timer_source_t *ts){
}
}
ts->item.next = it->next;
it->next = (linked_item_t *) ts;
it->next = (btstack_linked_item_t *) ts;
#endif
}
@ -144,7 +144,7 @@ static void run_loop_embedded_add_timer(timer_source_t *ts){
*/
static int run_loop_embedded_remove_timer(timer_source_t *ts){
#ifdef TIMER_SUPPORT
return linked_list_remove(&timers, (linked_item_t *) ts);
return btstack_linked_list_remove(&timers, (btstack_linked_item_t *) ts);
#else
return 0;
#endif
@ -153,9 +153,9 @@ static int run_loop_embedded_remove_timer(timer_source_t *ts){
static void run_loop_embedded_dump_timer(void){
#ifdef TIMER_SUPPORT
#ifdef ENABLE_LOG_INFO
linked_item_t *it;
btstack_linked_item_t *it;
int i = 0;
for (it = (linked_item_t *) timers; it ; it = it->next){
for (it = (btstack_linked_item_t *) timers; it ; it = it->next){
timer_source_t *ts = (timer_source_t*) it;
log_info("timer %u, timeout %u\n", i, (unsigned int) ts->timeout);
}

View File

@ -60,9 +60,9 @@ static int run_loop_posix_timeval_compare(struct timeval *a, struct timeval *b)
static int run_loop_posix_timer_compare(timer_source_t *a, timer_source_t *b);
// the run loop
static btstack_linked_list_t data_sources;
static btstack_btstack_linked_list_t data_sources;
static int data_sources_modified;
static btstack_linked_list_t timers;
static btstack_btstack_linked_list_t timers;
static struct timeval init_tv;
/**
@ -71,7 +71,7 @@ static struct timeval init_tv;
static void run_loop_posix_add_data_source(data_source_t *ds){
data_sources_modified = 1;
// log_info("run_loop_posix_add_data_source %x with fd %u\n", (int) ds, ds->fd);
linked_list_add(&data_sources, (linked_item_t *) ds);
btstack_linked_list_add(&data_sources, (btstack_linked_item_t *) ds);
}
/**
@ -80,15 +80,15 @@ static void run_loop_posix_add_data_source(data_source_t *ds){
static int run_loop_posix_remove_data_source(data_source_t *ds){
data_sources_modified = 1;
// log_info("run_loop_posix_remove_data_source %x\n", (int) ds);
return linked_list_remove(&data_sources, (linked_item_t *) ds);
return btstack_linked_list_remove(&data_sources, (btstack_linked_item_t *) ds);
}
/**
* Add timer to run_loop (keep list sorted)
*/
static void run_loop_posix_add_timer(timer_source_t *ts){
linked_item_t *it;
for (it = (linked_item_t *) &timers; it->next ; it = it->next){
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) &timers; it->next ; it = it->next){
if ((timer_source_t *) it->next == ts){
log_error( "run_loop_timer_add error: timer to add already in list!");
return;
@ -98,7 +98,7 @@ static void run_loop_posix_add_timer(timer_source_t *ts){
}
}
ts->item.next = it->next;
it->next = (linked_item_t *) ts;
it->next = (btstack_linked_item_t *) ts;
// log_info("Added timer %x at %u\n", (int) ts, (unsigned int) ts->timeout.tv_sec);
// run_loop_posix_dump_timer();
}
@ -109,13 +109,13 @@ static void run_loop_posix_add_timer(timer_source_t *ts){
static int run_loop_posix_remove_timer(timer_source_t *ts){
// log_info("Removed timer %x at %u\n", (int) ts, (unsigned int) ts->timeout.tv_sec);
// run_loop_posix_dump_timer();
return linked_list_remove(&timers, (linked_item_t *) ts);
return btstack_linked_list_remove(&timers, (btstack_linked_item_t *) ts);
}
static void run_loop_posix_dump_timer(void){
linked_item_t *it;
btstack_linked_item_t *it;
int i = 0;
for (it = (linked_item_t *) timers; it ; it = it->next){
for (it = (btstack_linked_item_t *) timers; it ; it = it->next){
timer_source_t *ts = (timer_source_t*) it;
log_info("timer %u, timeout %u\n", i, (unsigned int) ts->timeout.tv_sec);
}
@ -131,15 +131,15 @@ static void run_loop_posix_execute(void) {
struct timeval current_tv;
struct timeval next_tv;
struct timeval *timeout;
linked_list_iterator_t it;
btstack_linked_list_iterator_t it;
while (1) {
// collect FDs
FD_ZERO(&descriptors);
int highest_fd = 0;
linked_list_iterator_init(&it, &data_sources);
while (linked_list_iterator_has_next(&it)){
data_source_t *ds = (data_source_t*) linked_list_iterator_next(&it);
btstack_linked_list_iterator_init(&it, &data_sources);
while (btstack_linked_list_iterator_has_next(&it)){
data_source_t *ds = (data_source_t*) btstack_linked_list_iterator_next(&it);
if (ds->fd >= 0) {
FD_SET(ds->fd, &descriptors);
if (ds->fd > highest_fd) {
@ -175,9 +175,9 @@ static void run_loop_posix_execute(void) {
// log_info("run_loop_posix_execute: before ds check\n");
data_sources_modified = 0;
linked_list_iterator_init(&it, &data_sources);
while (linked_list_iterator_has_next(&it) && !data_sources_modified){
data_source_t *ds = (data_source_t*) linked_list_iterator_next(&it);
btstack_linked_list_iterator_init(&it, &data_sources);
while (btstack_linked_list_iterator_has_next(&it) && !data_sources_modified){
data_source_t *ds = (data_source_t*) btstack_linked_list_iterator_next(&it);
// log_info("run_loop_posix_execute: check %x with fd %u\n", (int) ds, ds->fd);
if (FD_ISSET(ds->fd, &descriptors)) {
// log_info("run_loop_posix_execute: process %x with fd %u\n", (int) ds, ds->fd);

View File

@ -62,7 +62,7 @@ static const run_loop_t run_loop_wiced;
static wiced_queue_t run_loop_queue;
// the run loop
static btstack_linked_list_t timers;
static btstack_btstack_linked_list_t timers;
static uint32_t run_loop_wiced_get_time_ms(void){
wiced_time_t time;
@ -79,8 +79,8 @@ static void run_loop_wiced_set_timer(timer_source_t *ts, uint32_t timeout_in_ms)
* Add timer to run_loop (keep list sorted)
*/
static void run_loop_wiced_add_timer(timer_source_t *ts){
linked_item_t *it;
for (it = (linked_item_t *) &timers; it->next ; it = it->next){
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) &timers; it->next ; it = it->next){
// don't add timer that's already in there
if ((timer_source_t *) it->next == ts){
log_error( "run_loop_timer_add error: timer to add already in list!");
@ -91,21 +91,21 @@ static void run_loop_wiced_add_timer(timer_source_t *ts){
}
}
ts->item.next = it->next;
it->next = (linked_item_t *) ts;
it->next = (btstack_linked_item_t *) ts;
}
/**
* Remove timer from run loop
*/
static int run_loop_wiced_remove_timer(timer_source_t *ts){
return linked_list_remove(&timers, (linked_item_t *) ts);
return btstack_linked_list_remove(&timers, (btstack_linked_item_t *) ts);
}
static void run_loop_wiced_dump_timer(void){
#ifdef ENABLE_LOG_INFO
linked_item_t *it;
btstack_linked_item_t *it;
int i = 0;
for (it = (linked_item_t *) timers; it ; it = it->next){
for (it = (btstack_linked_item_t *) timers; it ; it = it->next){
timer_source_t *ts = (timer_source_t*) it;
log_info("timer %u, timeout %u\n", i, (unsigned int) ts->timeout);
}

View File

@ -59,8 +59,8 @@
#include "ble/sm.h"
#include "ble/le_device_db.h"
static btstack_linked_list_t gatt_client_connections = NULL;
static btstack_linked_list_t gatt_subclients = NULL;
static btstack_btstack_linked_list_t gatt_client_connections = NULL;
static btstack_btstack_linked_list_t gatt_subclients = NULL;
static uint16_t next_gatt_client_id = 0;
static uint8_t pts_suppress_mtu_exchange;
@ -86,10 +86,10 @@ static uint16_t gatt_client_next_id(void){
}
static gatt_client_callback_t gatt_client_callback_for_id_new(uint16_t id){
linked_list_iterator_t it;
linked_list_iterator_init(&it, &gatt_subclients);
while (linked_list_iterator_has_next(&it)){
gatt_subclient_t * item = (gatt_subclient_t*) linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, &gatt_subclients);
while (btstack_linked_list_iterator_has_next(&it)){
gatt_subclient_t * item = (gatt_subclient_t*) btstack_linked_list_iterator_next(&it);
if ( item->id != id) continue;
return item->callback;
}
@ -110,19 +110,19 @@ uint16_t gatt_client_register_packet_handler(gatt_client_callback_t gatt_callbac
subclient->id = gatt_client_next_id();
subclient->callback = gatt_callback;
linked_list_add(&gatt_subclients, (linked_item_t *) subclient);
btstack_linked_list_add(&gatt_subclients, (btstack_linked_item_t *) subclient);
log_info("gatt_client_register_packet_handler with new id %u", subclient->id);
return subclient->id;
}
void gatt_client_unregister_packet_handler(uint16_t gatt_client_id){
linked_list_iterator_t it;
linked_list_iterator_init(&it, &gatt_subclients);
while (linked_list_iterator_has_next(&it)){
gatt_subclient_t * subclient = (gatt_subclient_t*) linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, &gatt_subclients);
while (btstack_linked_list_iterator_has_next(&it)){
gatt_subclient_t * subclient = (gatt_subclient_t*) btstack_linked_list_iterator_next(&it);
if ( subclient->id != gatt_client_id) continue;
linked_list_remove(&gatt_subclients, (linked_item_t *) subclient);
btstack_linked_list_remove(&gatt_subclients, (btstack_linked_item_t *) subclient);
btstack_memory_gatt_subclient_free(subclient);
}
}
@ -134,10 +134,10 @@ void gatt_client_init(void){
}
static gatt_client_t * gatt_client_for_timer(timer_source_t * ts){
linked_list_iterator_t it;
linked_list_iterator_init(&it, &gatt_client_connections);
while (linked_list_iterator_has_next(&it)){
gatt_client_t * peripheral = (gatt_client_t *) linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, &gatt_client_connections);
while (btstack_linked_list_iterator_has_next(&it)){
gatt_client_t * peripheral = (gatt_client_t *) btstack_linked_list_iterator_next(&it);
if ( &peripheral->gc_timeout == ts) {
return peripheral;
}
@ -166,8 +166,8 @@ static void gatt_client_timeout_stop(gatt_client_t * peripheral){
}
static gatt_client_t * get_gatt_client_context_for_handle(uint16_t handle){
linked_item_t *it;
for (it = (linked_item_t *) gatt_client_connections; it ; it = it->next){
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){
return peripheral;
@ -191,7 +191,7 @@ static gatt_client_t * provide_context_for_conn_handle(uint16_t con_handle){
context->mtu = ATT_DEFAULT_MTU;
context->mtu_state = SEND_MTU_EXCHANGE;
context->gatt_client_state = P_READY;
linked_list_add(&gatt_client_connections, (linked_item_t*)context);
btstack_linked_list_add(&gatt_client_connections, (btstack_linked_item_t*)context);
// skip mtu exchange for testing sm with pts
if (pts_suppress_mtu_exchange){
@ -498,10 +498,10 @@ static void emit_event_new(uint16_t gatt_client_id, uint8_t * packet, uint16_t s
}
static void emit_event_to_all_subclients_new(uint8_t * packet, uint16_t size){
linked_list_iterator_t it;
linked_list_iterator_init(&it, &gatt_subclients);
while (linked_list_iterator_has_next(&it)){
gatt_subclient_t * subclient = (gatt_subclient_t*) linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, &gatt_subclients);
while (btstack_linked_list_iterator_has_next(&it)){
gatt_subclient_t * subclient = (gatt_subclient_t*) btstack_linked_list_iterator_next(&it);
(*subclient->callback)(HCI_EVENT_PACKET, packet, size);
}
}
@ -823,8 +823,8 @@ static int is_value_valid(gatt_client_t *peripheral, uint8_t *packet, uint16_t s
static void gatt_client_run(void){
linked_item_t *it;
for (it = (linked_item_t *) gatt_client_connections; it ; it = it->next){
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;
@ -1036,7 +1036,7 @@ static void gatt_client_hci_event_packet_handler(uint8_t packet_type, uint8_t *p
if (!peripheral) break;
gatt_client_report_error_if_pending(peripheral, ATT_ERROR_HCI_DISCONNECT_RECEIVED);
linked_list_remove(&gatt_client_connections, (linked_item_t *) peripheral);
btstack_linked_list_remove(&gatt_client_connections, (btstack_linked_item_t *) peripheral);
btstack_memory_gatt_client_free(peripheral);
break;
}
@ -1375,10 +1375,10 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle,
}
static void att_signed_write_handle_cmac_result(uint8_t hash[8]){
linked_list_iterator_t it;
linked_list_iterator_init(&it, &gatt_client_connections);
while (linked_list_iterator_has_next(&it)){
gatt_client_t * peripheral = (gatt_client_t *) linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, &gatt_client_connections);
while (btstack_linked_list_iterator_has_next(&it)){
gatt_client_t * peripheral = (gatt_client_t *) btstack_linked_list_iterator_next(&it);
if (peripheral->gatt_client_state == P_W4_CMAC_RESULT){
// store result
memcpy(peripheral->cmac, hash, 8);

View File

@ -137,7 +137,7 @@ typedef enum{
} gatt_client_mtu_t;
typedef struct gatt_client{
linked_item_t item;
btstack_linked_item_t item;
// TODO: rename gatt_client_state -> state
gatt_client_state_t gatt_client_state;
@ -185,7 +185,7 @@ typedef struct gatt_client{
} gatt_client_t;
typedef struct gatt_subclient {
linked_item_t item;
btstack_linked_item_t item;
uint16_t id;
gatt_client_callback_t callback;
} gatt_subclient_t;

View File

@ -164,7 +164,7 @@ static uint8_t sm_address_resolution_addr_type;
static bd_addr_t sm_address_resolution_address;
static void * sm_address_resolution_context;
static address_resolution_mode_t sm_address_resolution_mode;
static btstack_linked_list_t sm_address_resolution_general_queue;
static btstack_btstack_linked_list_t sm_address_resolution_general_queue;
// aes128 crypto engine. store current sm_connection_t in sm_aes128_context
static sm_aes128_state_t sm_aes128_state;
@ -311,7 +311,7 @@ static void sm_truncate_key(sm_key_t key, int max_encryption_size){
static void sm_timeout_handler(timer_source_t * timer){
log_info("SM timeout");
sm_connection_t * sm_conn = (sm_connection_t *) linked_item_get_user((linked_item_t*) timer);
sm_connection_t * sm_conn = (sm_connection_t *) btstack_linked_item_get_user((btstack_linked_item_t*) timer);
sm_conn->sm_engine_state = SM_GENERAL_TIMEOUT;
sm_done_for_handle(sm_conn->sm_handle);
@ -322,7 +322,7 @@ static void sm_timeout_start(sm_connection_t * sm_conn){
run_loop_remove_timer(&setup->sm_timeout);
run_loop_set_timer_handler(&setup->sm_timeout, sm_timeout_handler);
run_loop_set_timer(&setup->sm_timeout, 30000); // 30 seconds sm timeout
linked_item_set_user((linked_item_t*) &setup->sm_timeout, sm_conn);
btstack_linked_item_set_user((btstack_linked_item_t*) &setup->sm_timeout, sm_conn);
run_loop_add_timer(&setup->sm_timeout);
}
static void sm_timeout_stop(void){
@ -587,11 +587,11 @@ static void sm_address_resolution_start_lookup(uint8_t addr_type, uint16_t handl
int sm_address_resolution_lookup(uint8_t address_type, bd_addr_t address){
// check if already in list
linked_list_iterator_t it;
btstack_linked_list_iterator_t it;
sm_lookup_entry_t * entry;
linked_list_iterator_init(&it, &sm_address_resolution_general_queue);
while(linked_list_iterator_has_next(&it)){
entry = (sm_lookup_entry_t *) linked_list_iterator_next(&it);
btstack_linked_list_iterator_init(&it, &sm_address_resolution_general_queue);
while(btstack_linked_list_iterator_has_next(&it)){
entry = (sm_lookup_entry_t *) btstack_linked_list_iterator_next(&it);
if (entry->address_type != address_type) continue;
if (memcmp(entry->address, address, 6)) continue;
// already in list
@ -601,7 +601,7 @@ int sm_address_resolution_lookup(uint8_t address_type, bd_addr_t address){
if (!entry) return BTSTACK_MEMORY_ALLOC_FAILED;
entry->address_type = (bd_addr_type_t) address_type;
memcpy(entry->address, address, 6);
linked_list_add(&sm_address_resolution_general_queue, (linked_item_t *) entry);
btstack_linked_list_add(&sm_address_resolution_general_queue, (btstack_linked_item_t *) entry);
sm_run();
return 0;
}
@ -1057,7 +1057,7 @@ static void sm_key_distribution_handle_all_received(sm_connection_t * sm_conn){
static void sm_run(void){
linked_list_iterator_t it;
btstack_linked_list_iterator_t it;
// assert that we can send at least commands
if (!hci_can_send_command_packet_now()) return;
@ -1136,8 +1136,8 @@ static void sm_run(void){
// -- if csrk lookup ready, find connection that require csrk lookup
if (sm_address_resolution_idle()){
hci_connections_get_iterator(&it);
while(linked_list_iterator_has_next(&it)){
hci_connection_t * hci_connection = (hci_connection_t *) linked_list_iterator_next(&it);
while(btstack_linked_list_iterator_has_next(&it)){
hci_connection_t * hci_connection = (hci_connection_t *) btstack_linked_list_iterator_next(&it);
sm_connection_t * sm_connection = &hci_connection->sm_connection;
if (sm_connection->sm_irk_lookup_state == IRK_LOOKUP_W4_READY){
// and start lookup
@ -1150,9 +1150,9 @@ static void sm_run(void){
// -- if csrk lookup ready, resolved addresses for received addresses
if (sm_address_resolution_idle()) {
if (!linked_list_empty(&sm_address_resolution_general_queue)){
if (!btstack_linked_list_empty(&sm_address_resolution_general_queue)){
sm_lookup_entry_t * entry = (sm_lookup_entry_t *) sm_address_resolution_general_queue;
linked_list_remove(&sm_address_resolution_general_queue, (linked_item_t *) entry);
btstack_linked_list_remove(&sm_address_resolution_general_queue, (btstack_linked_item_t *) entry);
sm_address_resolution_start_lookup(entry->address_type, 0, entry->address, ADDRESS_RESOLUTION_GENERAL, NULL);
btstack_memory_sm_lookup_entry_free(entry);
}
@ -1206,8 +1206,8 @@ static void sm_run(void){
// Find connections that requires setup context and make active if no other is locked
hci_connections_get_iterator(&it);
while(!sm_active_connection && linked_list_iterator_has_next(&it)){
hci_connection_t * hci_connection = (hci_connection_t *) linked_list_iterator_next(&it);
while(!sm_active_connection && btstack_linked_list_iterator_has_next(&it)){
hci_connection_t * hci_connection = (hci_connection_t *) btstack_linked_list_iterator_next(&it);
sm_connection_t * sm_connection = &hci_connection->sm_connection;
// - if no connection locked and we're ready/waiting for setup context, fetch it and start
int done = 1;

View File

@ -49,7 +49,7 @@ extern "C" {
void sm_test_set_irk(sm_key_t irk);
typedef struct {
linked_item_t item;
btstack_linked_item_t item;
bd_addr_t address;
bd_addr_type_t address_type;
} sm_lookup_entry_t;

View File

@ -48,16 +48,16 @@
/**
* tests if list is empty
*/
int linked_list_empty(btstack_linked_list_t * list){
int btstack_linked_list_empty(btstack_btstack_linked_list_t * list){
return *list == (void *) 0;
}
/**
* linked_list_get_last_item
* btstack_linked_list_get_last_item
*/
linked_item_t * linked_list_get_last_item(btstack_linked_list_t * list){ // <-- find the last item in the list
linked_item_t *lastItem = NULL;
linked_item_t *it;
btstack_linked_item_t * btstack_linked_list_get_last_item(btstack_btstack_linked_list_t * list){ // <-- find the last item in the list
btstack_linked_item_t *lastItem = NULL;
btstack_linked_item_t *it;
for (it = *list; it ; it = it->next){
if (it) {
lastItem = it;
@ -68,11 +68,11 @@ linked_item_t * linked_list_get_last_item(btstack_linked_list_t * list){
/**
* linked_list_add
* btstack_linked_list_add
*/
void linked_list_add(btstack_linked_list_t * list, linked_item_t *item){ // <-- add item to list
void btstack_linked_list_add(btstack_btstack_linked_list_t * list, btstack_linked_item_t *item){ // <-- add item to list
// check if already in list
linked_item_t *it;
btstack_linked_item_t *it;
for (it = *list; it ; it = it->next){
if (it == item) {
return;
@ -83,15 +83,15 @@ void linked_list_add(btstack_linked_list_t * list, linked_item_t *item){
*list = item;
}
void linked_list_add_tail(btstack_linked_list_t * list, linked_item_t *item){ // <-- add item to list as last element
void btstack_linked_list_add_tail(btstack_btstack_linked_list_t * list, btstack_linked_item_t *item){ // <-- add item to list as last element
// check if already in list
linked_item_t *it;
for (it = (linked_item_t *) list; it->next ; it = it->next){
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) list; it->next ; it = it->next){
if (it->next == item) {
return;
}
}
item->next = (linked_item_t*) 0;
item->next = (btstack_linked_item_t*) 0;
it->next = item;
}
@ -100,10 +100,10 @@ void linked_list_add_tail(btstack_linked_list_t * list, linked_item_t *item){
*
* @note: assumes that data_source_t.next is first element in data_source
*/
int linked_list_remove(btstack_linked_list_t * list, linked_item_t *item){ // <-- remove item from list
int btstack_linked_list_remove(btstack_btstack_linked_list_t * list, btstack_linked_item_t *item){ // <-- remove item from list
if (!item) return -1;
linked_item_t *it;
for (it = (linked_item_t *) list; it ; it = it->next){
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) list; it ; it = it->next){
if (it->next == item){
it->next = item->next;
return 0;
@ -115,22 +115,22 @@ int linked_list_remove(btstack_linked_list_t * list, linked_item_t *item){ /
/**
* @returns number of items in list
*/
int linked_list_count(btstack_linked_list_t * list){
linked_item_t *it;
int btstack_linked_list_count(btstack_btstack_linked_list_t * list){
btstack_linked_item_t *it;
int counter = 0;
for (it = (linked_item_t *) list; it ; it = it->next) {
for (it = (btstack_linked_item_t *) list; it ; it = it->next) {
counter++;
}
return counter;
}
void linked_item_set_user(linked_item_t *item, void *user_data){
item->next = (linked_item_t *) 0;
void btstack_linked_item_set_user(btstack_linked_item_t *item, void *user_data){
item->next = (btstack_linked_item_t *) 0;
item->user_data = user_data;
}
void * linked_item_get_user(linked_item_t *item) {
void * btstack_linked_item_get_user(btstack_linked_item_t *item) {
return item->user_data;
}
@ -138,14 +138,14 @@ void * linked_item_get_user(linked_item_t *item) {
// Linked List Iterator implementation
//
void linked_list_iterator_init(linked_list_iterator_t * it, btstack_linked_list_t * head){
void btstack_linked_list_iterator_init(btstack_linked_list_iterator_t * it, btstack_btstack_linked_list_t * head){
it->advance_on_next = 0;
it->prev = (linked_item_t*) head;
it->prev = (btstack_linked_item_t*) head;
it->curr = * head;
}
int linked_list_iterator_has_next(linked_list_iterator_t * it){
// log_info("linked_list_iterator_has_next: advance on next %u, it->prev %p, it->curr %p", it->advance_on_next, it->prev, it->curr);
int btstack_linked_list_iterator_has_next(btstack_linked_list_iterator_t * it){
// log_info("btstack_linked_list_iterator_has_next: advance on next %u, it->prev %p, it->curr %p", it->advance_on_next, it->prev, it->curr);
if (!it->advance_on_next){
return it->curr != NULL;
}
@ -157,7 +157,7 @@ int linked_list_iterator_has_next(linked_list_iterator_t * it){
return it->curr->next != NULL;
}
linked_item_t * linked_list_iterator_next(linked_list_iterator_t * it){
btstack_linked_item_t * btstack_linked_list_iterator_next(btstack_linked_list_iterator_t * it){
if (it->advance_on_next){
if (it->prev->next == it->curr){
it->prev = it->curr;
@ -172,7 +172,7 @@ linked_item_t * linked_list_iterator_next(linked_list_iterator_t * it){
return it->curr;
}
void linked_list_iterator_remove(linked_list_iterator_t * it){
void btstack_linked_list_iterator_remove(btstack_linked_list_iterator_t * it){
it->curr = it->curr->next;
it->prev->next = it->curr;
it->advance_on_next = 0;

View File

@ -36,53 +36,59 @@
*/
/*
* linked_list.h
*
* Created by Matthias Ringwald on 7/13/09.
* btstack_linked_list.h
*/
#ifndef __LINKED_LIST_H
#define __LINKED_LIST_H
#ifndef __BTSTACK_LINKED_LIST_H
#define __BTSTACK_LINKED_LIST_H
#if defined __cplusplus
extern "C" {
#endif
typedef struct linked_item {
struct linked_item *next; // <-- next element in list, or NULL
typedef struct btstack_linked_item {
struct btstack_linked_item *next; // <-- next element in list, or NULL
void *user_data; // <-- pointer to struct base
} linked_item_t;
} btstack_linked_item_t;
typedef linked_item_t * btstack_linked_list_t;
typedef btstack_linked_item_t * btstack_btstack_linked_list_t;
typedef struct {
int advance_on_next;
linked_item_t * prev; // points to the item before the current one
linked_item_t * curr; // points to the current item (to detect item removal)
} linked_list_iterator_t;
btstack_linked_item_t * prev; // points to the item before the current one
btstack_linked_item_t * curr; // points to the current item (to detect item removal)
} btstack_linked_list_iterator_t;
void linked_item_set_user(linked_item_t *item, void *user_data); // <-- set user data
void * linked_item_get_user(linked_item_t *item); // <-- get user data
int linked_list_empty(btstack_linked_list_t * list);
void linked_list_add(btstack_linked_list_t * list, linked_item_t *item); // <-- add item to list as first element
void linked_list_add_tail(btstack_linked_list_t * list, linked_item_t *item); // <-- add item to list as last element
int linked_list_remove(btstack_linked_list_t * list, linked_item_t *item); // <-- remove item from list
linked_item_t * linked_list_get_last_item(btstack_linked_list_t * list); // <-- find the last item in the list
// set user data
void btstack_linked_item_set_user(btstack_linked_item_t *item, void *user_data);
// get user data
void * btstack_linked_item_get_user(btstack_linked_item_t *item);
// test if list is empty
int btstack_linked_list_empty(btstack_btstack_linked_list_t * list);
// add item to list as first element
void btstack_linked_list_add(btstack_btstack_linked_list_t * list, btstack_linked_item_t *item);
// add item to list as last element
void btstack_linked_list_add_tail(btstack_btstack_linked_list_t * list, btstack_linked_item_t *item);
// remove item from list
int btstack_linked_list_remove(btstack_btstack_linked_list_t * list, btstack_linked_item_t *item);
// find the last item in the list
btstack_linked_item_t * btstack_linked_list_get_last_item(btstack_btstack_linked_list_t * list);
/**
* @brief Counts number of items in list
* @returns number of items in list
*/
int linked_list_count(btstack_linked_list_t * list);
int btstack_linked_list_count(btstack_btstack_linked_list_t * list);
//
// iterator for linked lists. alloes to remove current element. also robust against removal of current element by linked_list_remove
// iterator for linked lists. allows to remove current element.
// robust against removal of current element by btstack_linked_list_remove.
//
void linked_list_iterator_init(linked_list_iterator_t * it, btstack_linked_list_t * list);
int linked_list_iterator_has_next(linked_list_iterator_t * it);
linked_item_t * linked_list_iterator_next(linked_list_iterator_t * it);
void linked_list_iterator_remove(linked_list_iterator_t * it);
void btstack_linked_list_iterator_init(btstack_linked_list_iterator_t * it, btstack_btstack_linked_list_t * list);
int btstack_linked_list_iterator_has_next(btstack_linked_list_iterator_t * it);
btstack_linked_item_t * btstack_linked_list_iterator_next(btstack_linked_list_iterator_t * it);
void btstack_linked_list_iterator_remove(btstack_linked_list_iterator_t * it);
void test_linked_list(void);
@ -90,4 +96,4 @@ void test_linked_list(void);
}
#endif
#endif // __LINKED_LIST_H
#endif // __BTSTACK_LINKED_LIST_H

View File

@ -61,8 +61,8 @@
#define BNEP_CONNECTION_TIMEOUT_MS 10000
#define BNEP_CONNECTION_MAX_RETRIES 1
static btstack_linked_list_t bnep_services = NULL;
static btstack_linked_list_t bnep_channels = NULL;
static btstack_btstack_linked_list_t bnep_services = NULL;
static btstack_btstack_linked_list_t bnep_channels = NULL;
static gap_security_level_t bnep_security_level;
@ -612,7 +612,7 @@ int bnep_set_multicast_filter(uint16_t bnep_cid, bnep_multi_filter_t *filter, u
/* BNEP timeout timer helper function */
static void bnep_channel_timer_handler(timer_source_t *timer)
{
bnep_channel_t *channel = (bnep_channel_t *)linked_item_get_user((linked_item_t *) timer);
bnep_channel_t *channel = (bnep_channel_t *)btstack_linked_item_get_user((btstack_linked_item_t *) timer);
// retry send setup connection at least one time
if (channel->state == BNEP_CHANNEL_STATE_WAIT_FOR_CONNECTION_RESPONSE){
if (channel->retry_count < BNEP_CONNECTION_MAX_RETRIES){
@ -646,7 +646,7 @@ static void bnep_channel_start_timer(bnep_channel_t *channel, int timeout)
/* Start bnep channel timeout check timer */
run_loop_set_timer(&channel->timer, timeout);
channel->timer.process = bnep_channel_timer_handler;
linked_item_set_user((linked_item_t*) &channel->timer, channel);
btstack_linked_item_set_user((btstack_linked_item_t*) &channel->timer, channel);
run_loop_add_timer(&channel->timer);
channel->timer_active = 1;
}
@ -692,15 +692,15 @@ static bnep_channel_t * bnep_channel_create_for_addr(bd_addr_t addr)
channel->retry_count = 0;
/* Finally add it to the channel list */
linked_list_add(&bnep_channels, (linked_item_t *) channel);
btstack_linked_list_add(&bnep_channels, (btstack_linked_item_t *) channel);
return channel;
}
static bnep_channel_t* bnep_channel_for_addr(bd_addr_t addr)
{
linked_item_t *it;
for (it = (linked_item_t *) bnep_channels; it ; it = it->next){
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) bnep_channels; it ; it = it->next){
bnep_channel_t *channel = ((bnep_channel_t *) it);
if (BD_ADDR_CMP(addr, channel->remote_addr) == 0) {
return channel;
@ -711,8 +711,8 @@ static bnep_channel_t* bnep_channel_for_addr(bd_addr_t addr)
static bnep_channel_t * bnep_channel_for_l2cap_cid(uint16_t l2cap_cid)
{
linked_item_t *it;
for (it = (linked_item_t *) bnep_channels; it ; it = it->next){
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) bnep_channels; it ; it = it->next){
bnep_channel_t *channel = ((bnep_channel_t *) it);
if (channel->l2cap_cid == l2cap_cid) {
return channel;
@ -723,8 +723,8 @@ static bnep_channel_t * bnep_channel_for_l2cap_cid(uint16_t l2cap_cid)
static bnep_service_t * bnep_service_for_uuid(uint16_t uuid)
{
linked_item_t *it;
for (it = (linked_item_t *) bnep_services; it ; it = it->next){
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) bnep_services; it ; it = it->next){
bnep_service_t * service = ((bnep_service_t *) it);
if ( service->service_uuid == uuid){
return service;
@ -735,7 +735,7 @@ static bnep_service_t * bnep_service_for_uuid(uint16_t uuid)
static void bnep_channel_free(bnep_channel_t *channel)
{
linked_list_remove( &bnep_channels, (linked_item_t *) channel);
btstack_linked_list_remove( &bnep_channels, (btstack_linked_item_t *) channel);
btstack_memory_bnep_channel_free(channel);
}
@ -1507,10 +1507,10 @@ static void bnep_channel_state_machine(bnep_channel_t* channel, bnep_channel_eve
/* Process oustanding signaling tasks */
static void bnep_run(void)
{
linked_item_t *it;
linked_item_t *next;
btstack_linked_item_t *it;
btstack_linked_item_t *next;
for (it = (linked_item_t *) bnep_channels; it ; it = next){
for (it = (btstack_linked_item_t *) bnep_channels; it ; it = next){
next = it->next; // be prepared for removal of channel in state machine
@ -1607,7 +1607,7 @@ uint8_t bnep_register_service(uint16_t service_uuid, uint16_t max_frame_size)
service->service_uuid = service_uuid;
/* Add to services list */
linked_list_add(&bnep_services, (linked_item_t *) service);
btstack_linked_list_add(&bnep_services, (btstack_linked_item_t *) service);
return 0;
}
@ -1621,7 +1621,7 @@ void bnep_unregister_service(uint16_t service_uuid)
return;
}
linked_list_remove(&bnep_services, (linked_item_t *) service);
btstack_linked_list_remove(&bnep_services, (btstack_linked_item_t *) service);
btstack_memory_bnep_service_free(service);
service = NULL;

View File

@ -100,7 +100,7 @@ typedef struct {
// note: spec mandates single multplexer per device combination
typedef struct {
// linked list - assert: first field
linked_item_t item;
btstack_linked_item_t item;
BNEP_CHANNEL_STATE state; // Channel state
@ -141,7 +141,7 @@ typedef struct {
/* Internal BNEP service descriptor */
typedef struct {
linked_item_t item; // linked list - assert: first field
btstack_linked_item_t item; // linked list - assert: first field
uint16_t service_uuid; // Service class: PANU, NAP, GN
uint16_t max_frame_size; // incomming max. frame size

View File

@ -100,7 +100,7 @@ static const char * hfp_ag_features[] = {
static int hfp_generic_status_indicators_nr = 0;
static hfp_generic_status_indicator_t hfp_generic_status_indicators[HFP_MAX_NUM_HF_INDICATORS];
static btstack_linked_list_t hfp_connections = NULL;
static btstack_btstack_linked_list_t hfp_connections = NULL;
static void parse_sequence(hfp_connection_t * context);
hfp_generic_status_indicator_t * get_hfp_generic_status_indicators(void){
@ -229,15 +229,15 @@ static void hfp_emit_audio_connection_established_event(hfp_callback_t callback,
(*callback)(event, sizeof(event));
}
btstack_linked_list_t * hfp_get_connections(){
return (btstack_linked_list_t *) &hfp_connections;
btstack_btstack_linked_list_t * hfp_get_connections(){
return (btstack_btstack_linked_list_t *) &hfp_connections;
}
hfp_connection_t * get_hfp_connection_context_for_rfcomm_cid(uint16_t cid){
linked_list_iterator_t it;
linked_list_iterator_init(&it, hfp_get_connections());
while (linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, hfp_get_connections());
while (btstack_linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)btstack_linked_list_iterator_next(&it);
if (connection->rfcomm_cid == cid){
return connection;
}
@ -246,10 +246,10 @@ hfp_connection_t * get_hfp_connection_context_for_rfcomm_cid(uint16_t cid){
}
hfp_connection_t * get_hfp_connection_context_for_bd_addr(bd_addr_t bd_addr){
linked_list_iterator_t it;
linked_list_iterator_init(&it, hfp_get_connections());
while (linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, hfp_get_connections());
while (btstack_linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)btstack_linked_list_iterator_next(&it);
if (memcmp(connection->remote_addr, bd_addr, 6) == 0) {
return connection;
}
@ -258,10 +258,10 @@ hfp_connection_t * get_hfp_connection_context_for_bd_addr(bd_addr_t bd_addr){
}
hfp_connection_t * get_hfp_connection_context_for_sco_handle(uint16_t handle){
linked_list_iterator_t it;
linked_list_iterator_init(&it, hfp_get_connections());
while (linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, hfp_get_connections());
while (btstack_linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)btstack_linked_list_iterator_next(&it);
if (connection->sco_handle == handle){
return connection;
}
@ -309,12 +309,12 @@ static hfp_connection_t * create_hfp_connection_context(){
context->generic_status_indicators_nr = hfp_generic_status_indicators_nr;
memcpy(context->generic_status_indicators, hfp_generic_status_indicators, hfp_generic_status_indicators_nr * sizeof(hfp_generic_status_indicator_t));
linked_list_add(&hfp_connections, (linked_item_t*)context);
btstack_linked_list_add(&hfp_connections, (btstack_linked_item_t*)context);
return context;
}
static void remove_hfp_connection_context(hfp_connection_t * context){
linked_list_remove(&hfp_connections, (linked_item_t*)context);
btstack_linked_list_remove(&hfp_connections, (btstack_linked_item_t*)context);
}
static hfp_connection_t * provide_hfp_connection_context_for_bd_addr(bd_addr_t bd_addr){

View File

@ -461,7 +461,7 @@ typedef struct{
typedef struct hfp_connection {
linked_item_t item;
btstack_linked_item_t item;
bd_addr_t remote_addr;
uint16_t con_handle;
@ -628,7 +628,7 @@ int get_hfp_generic_status_indicators_nr(void);
hfp_generic_status_indicator_t * get_hfp_generic_status_indicators(void);
void set_hfp_generic_status_indicators(hfp_generic_status_indicator_t * indicators, int indicator_nr);
btstack_linked_list_t * hfp_get_connections(void);
btstack_btstack_linked_list_t * hfp_get_connections(void);
void hfp_parse(hfp_connection_t * context, uint8_t byte, int isHandsFree);
void hfp_init(uint16_t rfcomm_channel_nr);

View File

@ -801,11 +801,11 @@ static int hfp_ag_run_for_audio_connection(hfp_connection_t * context){
}
static hfp_connection_t * hfp_ag_context_for_timer(timer_source_t * ts){
linked_list_iterator_t it;
linked_list_iterator_init(&it, hfp_get_connections());
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, hfp_get_connections());
while (linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)linked_list_iterator_next(&it);
while (btstack_linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)btstack_linked_list_iterator_next(&it);
if ( &connection->hfp_timeout == ts) {
return connection;
}
@ -867,10 +867,10 @@ static void hfp_ag_trigger_incoming_call(void){
int indicator_index = get_ag_indicator_index_for_name("callsetup");
if (indicator_index < 0) return;
linked_list_iterator_t it;
linked_list_iterator_init(&it, hfp_get_connections());
while (linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, hfp_get_connections());
while (btstack_linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)btstack_linked_list_iterator_next(&it);
hfp_ag_establish_service_level_connection(connection->remote_addr);
if (connection->call_state == HFP_CALL_IDLE){
connection->ag_indicators_status_update_bitmap = store_bit(connection->ag_indicators_status_update_bitmap, indicator_index, 1);
@ -887,10 +887,10 @@ static void hfp_ag_transfer_callsetup_state(void){
int indicator_index = get_ag_indicator_index_for_name("callsetup");
if (indicator_index < 0) return;
linked_list_iterator_t it;
linked_list_iterator_init(&it, hfp_get_connections());
while (linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, hfp_get_connections());
while (btstack_linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)btstack_linked_list_iterator_next(&it);
hfp_ag_establish_service_level_connection(connection->remote_addr);
connection->ag_indicators_status_update_bitmap = store_bit(connection->ag_indicators_status_update_bitmap, indicator_index, 1);
hfp_run_for_context(connection);
@ -901,10 +901,10 @@ static void hfp_ag_transfer_call_state(void){
int indicator_index = get_ag_indicator_index_for_name("call");
if (indicator_index < 0) return;
linked_list_iterator_t it;
linked_list_iterator_init(&it, hfp_get_connections());
while (linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, hfp_get_connections());
while (btstack_linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)btstack_linked_list_iterator_next(&it);
hfp_ag_establish_service_level_connection(connection->remote_addr);
connection->ag_indicators_status_update_bitmap = store_bit(connection->ag_indicators_status_update_bitmap, indicator_index, 1);
hfp_run_for_context(connection);
@ -915,10 +915,10 @@ static void hfp_ag_transfer_callheld_state(void){
int indicator_index = get_ag_indicator_index_for_name("callheld");
if (indicator_index < 0) return;
linked_list_iterator_t it;
linked_list_iterator_init(&it, hfp_get_connections());
while (linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, hfp_get_connections());
while (btstack_linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)btstack_linked_list_iterator_next(&it);
hfp_ag_establish_service_level_connection(connection->remote_addr);
connection->ag_indicators_status_update_bitmap = store_bit(connection->ag_indicators_status_update_bitmap, indicator_index, 1);
hfp_run_for_context(connection);
@ -930,10 +930,10 @@ static void hfp_ag_hf_accept_call(hfp_connection_t * source){
int call_indicator_index = get_ag_indicator_index_for_name("call");
int callsetup_indicator_index = get_ag_indicator_index_for_name("callsetup");
linked_list_iterator_t it;
linked_list_iterator_init(&it, hfp_get_connections());
while (linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, hfp_get_connections());
while (btstack_linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)btstack_linked_list_iterator_next(&it);
if (connection->call_state != HFP_CALL_RINGING &&
connection->call_state != HFP_CALL_W4_AUDIO_CONNECTION_FOR_IN_BAND_RING) continue;
@ -963,10 +963,10 @@ static void hfp_ag_ag_accept_call(void){
int call_indicator_index = get_ag_indicator_index_for_name("call");
int callsetup_indicator_index = get_ag_indicator_index_for_name("callsetup");
linked_list_iterator_t it;
linked_list_iterator_init(&it, hfp_get_connections());
while (linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, hfp_get_connections());
while (btstack_linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)btstack_linked_list_iterator_next(&it);
if (connection->call_state != HFP_CALL_RINGING) continue;
hfp_ag_hf_stop_ringing(connection);
@ -982,10 +982,10 @@ static void hfp_ag_ag_accept_call(void){
static void hfp_ag_trigger_reject_call(void){
int callsetup_indicator_index = get_ag_indicator_index_for_name("callsetup");
linked_list_iterator_t it;
linked_list_iterator_init(&it, hfp_get_connections());
while (linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, hfp_get_connections());
while (btstack_linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)btstack_linked_list_iterator_next(&it);
if (connection->call_state != HFP_CALL_RINGING &&
connection->call_state != HFP_CALL_W4_AUDIO_CONNECTION_FOR_IN_BAND_RING) continue;
hfp_ag_hf_stop_ringing(connection);
@ -998,10 +998,10 @@ static void hfp_ag_trigger_reject_call(void){
static void hfp_ag_trigger_terminate_call(void){
int call_indicator_index = get_ag_indicator_index_for_name("call");
linked_list_iterator_t it;
linked_list_iterator_init(&it, hfp_get_connections());
while (linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, hfp_get_connections());
while (btstack_linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)btstack_linked_list_iterator_next(&it);
hfp_ag_establish_service_level_connection(connection->remote_addr);
if (connection->call_state == HFP_CALL_IDLE) continue;
connection->call_state = HFP_CALL_IDLE;
@ -1037,10 +1037,10 @@ static void hfp_ag_set_call_indicator(){
}
static void hfp_ag_stop_ringing(void){
linked_list_iterator_t it;
linked_list_iterator_init(&it, hfp_get_connections());
while (linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, hfp_get_connections());
while (btstack_linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)btstack_linked_list_iterator_next(&it);
if (connection->call_state != HFP_CALL_RINGING &&
connection->call_state != HFP_CALL_W4_AUDIO_CONNECTION_FOR_IN_BAND_RING) continue;
hfp_ag_hf_stop_ringing(connection);
@ -1048,20 +1048,20 @@ static void hfp_ag_stop_ringing(void){
}
static hfp_connection_t * hfp_ag_connection_for_call_state(hfp_call_state_t call_state){
linked_list_iterator_t it;
linked_list_iterator_init(&it, hfp_get_connections());
while (linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, hfp_get_connections());
while (btstack_linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)btstack_linked_list_iterator_next(&it);
if (connection->call_state == call_state) return connection;
}
return NULL;
}
static void hfp_ag_send_response_and_hold_state(hfp_response_and_hold_state_t state){
linked_list_iterator_t it;
linked_list_iterator_init(&it, hfp_get_connections());
while (linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, hfp_get_connections());
while (btstack_linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)btstack_linked_list_iterator_next(&it);
connection->send_response_and_hold_status = state + 1;
}
}
@ -1904,10 +1904,10 @@ static void hfp_handle_rfcomm_data(uint8_t packet_type, uint16_t channel, uint8_
}
static void hfp_run(void){
linked_list_iterator_t it;
linked_list_iterator_init(&it, hfp_get_connections());
while (linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, hfp_get_connections());
while (btstack_linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)btstack_linked_list_iterator_next(&it);
hfp_run_for_context(connection);
}
}
@ -2041,10 +2041,10 @@ void hfp_ag_set_use_in_band_ring_tone(int use_in_band_ring_tone){
}
hfp_supported_features = store_bit(hfp_supported_features, HFP_AGSF_IN_BAND_RING_TONE, use_in_band_ring_tone);
linked_list_iterator_t it;
linked_list_iterator_init(&it, hfp_get_connections());
while (linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, hfp_get_connections());
while (btstack_linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)btstack_linked_list_iterator_next(&it);
connection->command = HFP_CMD_CHANGE_IN_BAND_RING_TONE_SETTING;
hfp_run_for_context(connection);
}
@ -2115,10 +2115,10 @@ static void hfp_ag_set_ag_indicator(const char * name, int value){
hfp_ag_indicators[indicator_index].status = value;
linked_list_iterator_t it;
linked_list_iterator_init(&it, hfp_get_connections());
while (linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, hfp_get_connections());
while (btstack_linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)btstack_linked_list_iterator_next(&it);
if (!connection->ag_indicators[indicator_index].enabled) {
log_info("AG indicator '%s' changed to %u but not enabled", hfp_ag_indicators[indicator_index].name, value);
continue;

View File

@ -1001,10 +1001,10 @@ static void hfp_handle_rfcomm_event(uint8_t packet_type, uint16_t channel, uint8
}
static void hfp_run(){
linked_list_iterator_t it;
linked_list_iterator_init(&it, hfp_get_connections());
while (linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, hfp_get_connections());
while (btstack_linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)btstack_linked_list_iterator_next(&it);
hfp_run_for_context(connection);
}
}
@ -1037,10 +1037,10 @@ void hfp_hf_set_codecs(uint8_t * codecs, int codecs_nr){
char buffer[30];
int offset = join(buffer, sizeof(buffer), hfp_codecs, hfp_codecs_nr);
buffer[offset] = 0;
linked_list_iterator_t it;
linked_list_iterator_init(&it, hfp_get_connections());
while (linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, hfp_get_connections());
while (btstack_linked_list_iterator_has_next(&it)){
hfp_connection_t * connection = (hfp_connection_t *)btstack_linked_list_iterator_next(&it);
if (!connection) continue;
connection->command = HFP_CMD_AVAILABLE_CODECS;
hfp_run_for_context(connection);

View File

@ -93,7 +93,7 @@ const remote_device_db_t * remote_device_db_fs_instance(void);
#define MAX_NAME_LEN 32
typedef struct {
// linked list - assert: first field
linked_item_t item;
btstack_linked_item_t item;
bd_addr_t bd_addr;
} db_mem_device_t;
@ -111,7 +111,7 @@ typedef struct {
typedef struct {
// linked list - assert: first field
linked_item_t item;
btstack_linked_item_t item;
char service_name[MAX_NAME_LEN];
uint8_t channel;

View File

@ -46,8 +46,8 @@
#include "btstack_linked_list.h"
// This lists should be only accessed by tests.
btstack_linked_list_t db_mem_link_keys = NULL;
btstack_linked_list_t db_mem_names = NULL;
btstack_btstack_linked_list_t db_mem_link_keys = NULL;
btstack_btstack_linked_list_t db_mem_names = NULL;
// Device info
static void db_open(void){
@ -56,9 +56,9 @@ static void db_open(void){
static void db_close(void){
}
static db_mem_device_t * get_item(btstack_linked_list_t list, bd_addr_t bd_addr) {
linked_item_t *it;
for (it = (linked_item_t *) list; it ; it = it->next){
static db_mem_device_t * get_item(btstack_btstack_linked_list_t list, bd_addr_t bd_addr) {
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) list; it ; it = it->next){
db_mem_device_t * item = (db_mem_device_t *) it;
if (BD_ADDR_CMP(item->bd_addr, bd_addr) == 0) {
return item;
@ -74,8 +74,8 @@ static int get_name(bd_addr_t bd_addr, device_name_t *device_name) {
strncpy((char*)device_name, item->device_name, MAX_NAME_LEN);
linked_list_remove(&db_mem_names, (linked_item_t *) item);
linked_list_add(&db_mem_names, (linked_item_t *) item);
btstack_linked_list_remove(&db_mem_names, (btstack_linked_item_t *) item);
btstack_linked_list_add(&db_mem_names, (btstack_linked_item_t *) item);
return 1;
}
@ -89,8 +89,8 @@ static int get_link_key(bd_addr_t bd_addr, link_key_t link_key, link_key_type_t
if (link_key_type) {
*link_key_type = item->link_key_type;
}
linked_list_remove(&db_mem_link_keys, (linked_item_t *) item);
linked_list_add(&db_mem_link_keys, (linked_item_t *) item);
btstack_linked_list_remove(&db_mem_link_keys, (btstack_linked_item_t *) item);
btstack_linked_list_add(&db_mem_link_keys, (btstack_linked_item_t *) item);
return 1;
}
@ -100,7 +100,7 @@ static void delete_link_key(bd_addr_t bd_addr){
if (!item) return;
linked_list_remove(&db_mem_link_keys, (linked_item_t *) item);
btstack_linked_list_remove(&db_mem_link_keys, (btstack_linked_item_t *) item);
btstack_memory_db_mem_device_link_key_free((db_mem_device_link_key_t*)item);
}
@ -110,7 +110,7 @@ static void put_link_key(bd_addr_t bd_addr, link_key_t link_key, link_key_type_t
// check for existing record and remove if found
db_mem_device_link_key_t * record = (db_mem_device_link_key_t *) get_item(db_mem_link_keys, bd_addr);
if (record){
linked_list_remove(&db_mem_link_keys, (linked_item_t*) record);
btstack_linked_list_remove(&db_mem_link_keys, (btstack_linked_item_t*) record);
}
// record not found, get new one from memory pool
@ -120,9 +120,9 @@ static void put_link_key(bd_addr_t bd_addr, link_key_t link_key, link_key_type_t
// if none left, re-use last item and remove from list
if (!record){
record = (db_mem_device_link_key_t*)linked_list_get_last_item(&db_mem_link_keys);
record = (db_mem_device_link_key_t*)btstack_linked_list_get_last_item(&db_mem_link_keys);
if (record) {
linked_list_remove(&db_mem_link_keys, (linked_item_t*) record);
btstack_linked_list_remove(&db_mem_link_keys, (btstack_linked_item_t*) record);
}
}
@ -131,7 +131,7 @@ static void put_link_key(bd_addr_t bd_addr, link_key_t link_key, link_key_type_t
memcpy(record->device.bd_addr, bd_addr, sizeof(bd_addr_t));
memcpy(record->link_key, link_key, LINK_KEY_LEN);
record->link_key_type = link_key_type;
linked_list_add(&db_mem_link_keys, (linked_item_t *) record);
btstack_linked_list_add(&db_mem_link_keys, (btstack_linked_item_t *) record);
}
static void delete_name(bd_addr_t bd_addr){
@ -139,7 +139,7 @@ static void delete_name(bd_addr_t bd_addr){
if (!item) return;
linked_list_remove(&db_mem_names, (linked_item_t *) item);
btstack_linked_list_remove(&db_mem_names, (btstack_linked_item_t *) item);
btstack_memory_db_mem_device_name_free((db_mem_device_name_t*)item);
}
@ -148,7 +148,7 @@ static void put_name(bd_addr_t bd_addr, device_name_t *device_name){
// check for existing record and remove if found
db_mem_device_name_t * record = (db_mem_device_name_t *) get_item(db_mem_names, bd_addr);
if (record){
linked_list_remove(&db_mem_names, (linked_item_t*) record);
btstack_linked_list_remove(&db_mem_names, (btstack_linked_item_t*) record);
}
// record not found, get new one from memory pool
@ -158,9 +158,9 @@ static void put_name(bd_addr_t bd_addr, device_name_t *device_name){
// if none left, re-use last item and remove from list
if (!record){
record = (db_mem_device_name_t*)linked_list_get_last_item(&db_mem_names);
record = (db_mem_device_name_t*)btstack_linked_list_get_last_item(&db_mem_names);
if (record) {
linked_list_remove(&db_mem_names, (linked_item_t*) record);
btstack_linked_list_remove(&db_mem_names, (btstack_linked_item_t*) record);
}
}
@ -168,7 +168,7 @@ static void put_name(bd_addr_t bd_addr, device_name_t *device_name){
memcpy(record->device.bd_addr, bd_addr, sizeof(bd_addr_t));
strncpy(record->device_name, (const char*) device_name, MAX_NAME_LEN);
linked_list_add(&db_mem_names, (linked_item_t *) record);
btstack_linked_list_add(&db_mem_names, (btstack_linked_item_t *) record);
}
const remote_device_db_t remote_device_db_memory = {

View File

@ -78,9 +78,9 @@
static uint16_t rfcomm_client_cid_generator; // used for client channel IDs
// linked lists for all
static btstack_linked_list_t rfcomm_multiplexers = NULL;
static btstack_linked_list_t rfcomm_channels = NULL;
static btstack_linked_list_t rfcomm_services = NULL;
static btstack_btstack_linked_list_t rfcomm_multiplexers = NULL;
static btstack_btstack_linked_list_t rfcomm_channels = NULL;
static btstack_btstack_linked_list_t rfcomm_services = NULL;
static gap_security_level_t rfcomm_security_level;
@ -240,14 +240,14 @@ static rfcomm_multiplexer_t * rfcomm_multiplexer_create_for_addr(bd_addr_t addr)
BD_ADDR_COPY(&multiplexer->remote_addr, addr);
// add to services list
linked_list_add(&rfcomm_multiplexers, (linked_item_t *) multiplexer);
btstack_linked_list_add(&rfcomm_multiplexers, (btstack_linked_item_t *) multiplexer);
return multiplexer;
}
static rfcomm_multiplexer_t * rfcomm_multiplexer_for_addr(bd_addr_t addr){
linked_item_t *it;
for (it = (linked_item_t *) rfcomm_multiplexers; it ; it = it->next){
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) rfcomm_multiplexers; it ; it = it->next){
rfcomm_multiplexer_t * multiplexer = ((rfcomm_multiplexer_t *) it);
if (BD_ADDR_CMP(addr, multiplexer->remote_addr) == 0) {
return multiplexer;
@ -257,8 +257,8 @@ static rfcomm_multiplexer_t * rfcomm_multiplexer_for_addr(bd_addr_t addr){
}
static rfcomm_multiplexer_t * rfcomm_multiplexer_for_l2cap_cid(uint16_t l2cap_cid) {
linked_item_t *it;
for (it = (linked_item_t *) rfcomm_multiplexers; it ; it = it->next){
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) rfcomm_multiplexers; it ; it = it->next){
rfcomm_multiplexer_t * multiplexer = ((rfcomm_multiplexer_t *) it);
if (multiplexer->l2cap_cid == l2cap_cid) {
return multiplexer;
@ -268,8 +268,8 @@ static rfcomm_multiplexer_t * rfcomm_multiplexer_for_l2cap_cid(uint16_t l2cap_ci
}
static int rfcomm_multiplexer_has_channels(rfcomm_multiplexer_t * multiplexer){
linked_item_t *it;
for (it = (linked_item_t *) rfcomm_channels; it ; it = it->next){
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) rfcomm_channels; it ; it = it->next){
rfcomm_channel_t * channel = ((rfcomm_channel_t *) it);
if (channel->multiplexer == multiplexer) {
return 1;
@ -282,9 +282,9 @@ static int rfcomm_multiplexer_has_channels(rfcomm_multiplexer_t * multiplexer){
static void rfcomm_dump_channels(void){
#ifndef EMBEDDED
linked_item_t * it;
btstack_linked_item_t * it;
int channels = 0;
for (it = (linked_item_t *) rfcomm_channels; it ; it = it->next){
for (it = (btstack_linked_item_t *) rfcomm_channels; it ; it = it->next){
rfcomm_channel_t * channel = (rfcomm_channel_t *) it;
log_info("Channel #%u: addr %p, state %u", channels, channel, channel->state);
channels++;
@ -353,14 +353,14 @@ static rfcomm_channel_t * rfcomm_channel_create(rfcomm_multiplexer_t * multiplex
rfcomm_channel_initialize(channel, multiplexer, service, server_channel);
// add to services list
linked_list_add(&rfcomm_channels, (linked_item_t *) channel);
btstack_linked_list_add(&rfcomm_channels, (btstack_linked_item_t *) channel);
return channel;
}
static rfcomm_channel_t * rfcomm_channel_for_rfcomm_cid(uint16_t rfcomm_cid){
linked_item_t *it;
for (it = (linked_item_t *) rfcomm_channels; it ; it = it->next){
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) rfcomm_channels; it ; it = it->next){
rfcomm_channel_t * channel = ((rfcomm_channel_t *) it);
if (channel->rfcomm_cid == rfcomm_cid) {
return channel;
@ -370,8 +370,8 @@ static rfcomm_channel_t * rfcomm_channel_for_rfcomm_cid(uint16_t rfcomm_cid){
}
static rfcomm_channel_t * rfcomm_channel_for_multiplexer_and_dlci(rfcomm_multiplexer_t * multiplexer, uint8_t dlci){
linked_item_t *it;
for (it = (linked_item_t *) rfcomm_channels; it ; it = it->next){
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) rfcomm_channels; it ; it = it->next){
rfcomm_channel_t * channel = ((rfcomm_channel_t *) it);
if (channel->dlci == dlci && channel->multiplexer == multiplexer) {
return channel;
@ -381,8 +381,8 @@ static rfcomm_channel_t * rfcomm_channel_for_multiplexer_and_dlci(rfcomm_multipl
}
static rfcomm_service_t * rfcomm_service_for_channel(uint8_t server_channel){
linked_item_t *it;
for (it = (linked_item_t *) rfcomm_services; it ; it = it->next){
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) rfcomm_services; it ; it = it->next){
rfcomm_service_t * service = ((rfcomm_service_t *) it);
if ( service->server_channel == server_channel){
return service;
@ -684,7 +684,7 @@ static void rfcomm_multiplexer_stop_timer(rfcomm_multiplexer_t * multiplexer){
}
}
static void rfcomm_multiplexer_free(rfcomm_multiplexer_t * multiplexer){
linked_list_remove( &rfcomm_multiplexers, (linked_item_t *) multiplexer);
btstack_linked_list_remove( &rfcomm_multiplexers, (btstack_linked_item_t *) multiplexer);
btstack_memory_rfcomm_multiplexer_free(multiplexer);
}
@ -693,7 +693,7 @@ static void rfcomm_multiplexer_finalize(rfcomm_multiplexer_t * multiplexer){
rfcomm_multiplexer_stop_timer(multiplexer);
// close and remove all channels
linked_item_t *it = (linked_item_t *) &rfcomm_channels;
btstack_linked_item_t *it = (btstack_linked_item_t *) &rfcomm_channels;
while (it->next){
rfcomm_channel_t * channel = (rfcomm_channel_t *) it->next;
if (channel->multiplexer == multiplexer) {
@ -717,7 +717,7 @@ static void rfcomm_multiplexer_finalize(rfcomm_multiplexer_t * multiplexer){
}
static void rfcomm_multiplexer_timer_handler(timer_source_t *timer){
rfcomm_multiplexer_t * multiplexer = (rfcomm_multiplexer_t *) linked_item_get_user( (linked_item_t *) timer);
rfcomm_multiplexer_t * multiplexer = (rfcomm_multiplexer_t *) btstack_linked_item_get_user( (btstack_linked_item_t *) timer);
if (rfcomm_multiplexer_has_channels(multiplexer)) return;
log_info("rfcomm_multiplexer_timer_handler timeout: shutting down multiplexer! (no channels)");
@ -736,7 +736,7 @@ static void rfcomm_multiplexer_prepare_idle_timer(rfcomm_multiplexer_t * multipl
// start idle timer for multiplexer timeout check as there are no rfcomm channels yet
run_loop_set_timer(&multiplexer->timer, RFCOMM_MULIPLEXER_TIMEOUT_MS);
multiplexer->timer.process = rfcomm_multiplexer_timer_handler;
linked_item_set_user((linked_item_t*) &multiplexer->timer, multiplexer);
btstack_linked_item_set_user((btstack_linked_item_t*) &multiplexer->timer, multiplexer);
run_loop_add_timer(&multiplexer->timer);
multiplexer->timer_active = 1;
}
@ -748,8 +748,8 @@ static void rfcomm_multiplexer_opened(rfcomm_multiplexer_t *multiplexer){
rfcomm_channel_event_t event = { CH_EVT_MULTIPLEXER_READY };
// transition of channels that wait for multiplexer
linked_item_t *it;
for (it = (linked_item_t *) rfcomm_channels; it ; it = it->next){
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) rfcomm_channels; it ; it = it->next){
rfcomm_channel_t * channel = ((rfcomm_channel_t *) it);
if (channel->multiplexer != multiplexer) continue;
rfcomm_channel_state_machine(channel, &event);
@ -832,7 +832,7 @@ static int rfcomm_multiplexer_hci_event_handler(uint8_t *packet, uint16_t size){
rfcomm_multiplexer_stop_timer(multiplexer);
// emit rfcomm_channel_opened with status and free channel
linked_item_t * it = (linked_item_t *) &rfcomm_channels;
btstack_linked_item_t * it = (btstack_linked_item_t *) &rfcomm_channels;
while (it->next) {
rfcomm_channel_t * channel = (rfcomm_channel_t *) it->next;
if (channel->multiplexer == multiplexer){
@ -1019,8 +1019,8 @@ static void rfcomm_multiplexer_state_machine(rfcomm_multiplexer_t * multiplexer,
if (multiplexer->fcon == 0) return;
// trigger client to send again after sending FCon Response
uint8_t packet_sent_event[] = { DAEMON_EVENT_HCI_PACKET_SENT, 0};
linked_item_t *it;
for (it = (linked_item_t *) rfcomm_channels; it ; it = it->next){
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) rfcomm_channels; it ; it = it->next){
rfcomm_channel_t * channel = ((rfcomm_channel_t *) it);
if (channel->multiplexer != multiplexer) continue;
(*app_packet_handler)(HCI_EVENT_PACKET, 0, (uint8_t *) packet_sent_event, sizeof(packet_sent_event));
@ -1184,7 +1184,7 @@ static void rfcomm_channel_finalize(rfcomm_channel_t *channel){
rfcomm_multiplexer_t *multiplexer = channel->multiplexer;
// remove from list
linked_list_remove( &rfcomm_channels, (linked_item_t *) channel);
btstack_linked_list_remove( &rfcomm_channels, (btstack_linked_item_t *) channel);
// free channel
btstack_memory_rfcomm_channel_free(channel);
@ -1809,10 +1809,10 @@ static void rfcomm_channel_state_machine(rfcomm_channel_t *channel, rfcomm_chann
// process outstanding signaling tasks
static void rfcomm_run(void){
linked_item_t *it;
linked_item_t *next;
btstack_linked_item_t *it;
btstack_linked_item_t *next;
for (it = (linked_item_t *) rfcomm_multiplexers; it ; it = next){
for (it = (btstack_linked_item_t *) rfcomm_multiplexers; it ; it = next){
next = it->next; // be prepared for removal of channel in state machine
@ -1827,7 +1827,7 @@ static void rfcomm_run(void){
rfcomm_multiplexer_state_machine(multiplexer, MULT_EV_READY_TO_SEND);
}
for (it = (linked_item_t *) rfcomm_channels; it ; it = next){
for (it = (btstack_linked_item_t *) rfcomm_channels; it ; it = next){
next = it->next; // be prepared for removal of channel in state machine
@ -2097,7 +2097,7 @@ static uint8_t rfcomm_register_service_internal(uint8_t channel, uint16_t max_fr
}
// register with l2cap if not registered before, max MTU
if (linked_list_empty(&rfcomm_services)){
if (btstack_linked_list_empty(&rfcomm_services)){
l2cap_register_service(rfcomm_packet_handler, PSM_RFCOMM, 0xffff, rfcomm_security_level);
}
@ -2108,7 +2108,7 @@ static uint8_t rfcomm_register_service_internal(uint8_t channel, uint16_t max_fr
service->incoming_initial_credits = initial_credits;
// add to services list
linked_list_add(&rfcomm_services, (linked_item_t *) service);
btstack_linked_list_add(&rfcomm_services, (btstack_linked_item_t *) service);
return 0;
}
@ -2125,11 +2125,11 @@ void rfcomm_unregister_service(uint8_t service_channel){
log_info("RFCOMM_UNREGISTER_SERVICE #%u", service_channel);
rfcomm_service_t *service = rfcomm_service_for_channel(service_channel);
if (!service) return;
linked_list_remove(&rfcomm_services, (linked_item_t *) service);
btstack_linked_list_remove(&rfcomm_services, (btstack_linked_item_t *) service);
btstack_memory_rfcomm_service_free(service);
// unregister if no services active
if (linked_list_empty(&rfcomm_services)){
if (btstack_linked_list_empty(&rfcomm_services)){
// bt_send_cmd(&l2cap_unregister_service, PSM_RFCOMM);
l2cap_unregister_service(PSM_RFCOMM);
}

View File

@ -173,7 +173,7 @@ typedef struct rfcomm_channel_event_msc {
// info regarding potential connections
typedef struct {
// linked list - assert: first field
linked_item_t item;
btstack_linked_item_t item;
// server channel
uint8_t server_channel;
@ -196,7 +196,7 @@ typedef struct {
// note: spec mandates single multiplexer per device combination
typedef struct {
// linked list - assert: first field
linked_item_t item;
btstack_linked_item_t item;
timer_source_t timer;
int timer_active;
@ -232,7 +232,7 @@ typedef struct {
// info regarding an actual connection
typedef struct {
// linked list - assert: first field
linked_item_t item;
btstack_linked_item_t item;
rfcomm_multiplexer_t *multiplexer;
uint16_t rfcomm_cid;

View File

@ -61,7 +61,7 @@
static void sdp_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
// registered service records
static btstack_linked_list_t sdp_service_records = NULL;
static btstack_btstack_linked_list_t sdp_service_records = NULL;
// our handles start after the reserved range
static uint32_t sdp_next_service_record_handle = ((uint32_t) maxReservedServiceRecordHandle) + 2;
@ -86,8 +86,8 @@ uint32_t sdp_get_service_record_handle(const uint8_t * record){
}
static service_record_item_t * sdp_get_record_item_for_handle(uint32_t handle){
linked_item_t *it;
for (it = (linked_item_t *) sdp_service_records; it ; it = it->next){
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) sdp_service_records; it ; it = it->next){
service_record_item_t * item = (service_record_item_t *) it;
if (item->service_record_handle == handle){
return item;
@ -136,7 +136,7 @@ uint8_t sdp_register_service(const uint8_t * record){
newRecordItem->service_record = (uint8_t*) record;
// add to linked list
linked_list_add(&sdp_service_records, (linked_item_t *) newRecordItem);
btstack_linked_list_add(&sdp_service_records, (btstack_linked_item_t *) newRecordItem);
return 0;
}
@ -147,7 +147,7 @@ uint8_t sdp_register_service(const uint8_t * record){
void sdp_unregister_service(uint32_t service_record_handle){
service_record_item_t * record_item = sdp_get_record_item_for_handle(service_record_handle);
if (!record_item) return;
linked_list_remove(&sdp_service_records, (linked_item_t *) record_item);
btstack_linked_list_remove(&sdp_service_records, (btstack_linked_item_t *) record_item);
}
// PDU
@ -182,9 +182,9 @@ int sdp_handle_service_search_request(uint8_t * packet, uint16_t remote_mtu){
}
// get and limit total count
linked_item_t *it;
btstack_linked_item_t *it;
uint16_t total_service_count = 0;
for (it = (linked_item_t *) sdp_service_records; it ; it = it->next){
for (it = (btstack_linked_item_t *) sdp_service_records; it ; it = it->next){
service_record_item_t * item = (service_record_item_t *) it;
if (!sdp_record_matches_service_search_pattern(item->service_record, serviceSearchPattern)) continue;
total_service_count++;
@ -198,7 +198,7 @@ int sdp_handle_service_search_request(uint8_t * packet, uint16_t remote_mtu){
uint16_t current_service_count = 0;
uint16_t current_service_index = 0;
uint16_t matching_service_count = 0;
for (it = (linked_item_t *) sdp_service_records; it ; it = it->next, ++current_service_index){
for (it = (btstack_linked_item_t *) sdp_service_records; it ; it = it->next, ++current_service_index){
service_record_item_t * item = (service_record_item_t *) it;
if (!sdp_record_matches_service_search_pattern(item->service_record, serviceSearchPattern)) continue;
@ -310,8 +310,8 @@ int sdp_handle_service_attribute_request(uint8_t * packet, uint16_t remote_mtu){
static uint16_t sdp_get_size_for_service_search_attribute_response(uint8_t * serviceSearchPattern, uint8_t * attributeIDList){
uint16_t total_response_size = 0;
linked_item_t *it;
for (it = (linked_item_t *) sdp_service_records; it ; it = it->next){
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) sdp_service_records; it ; it = it->next){
service_record_item_t * item = (service_record_item_t *) it;
if (!sdp_record_matches_service_search_pattern(item->service_record, serviceSearchPattern)) continue;
@ -370,7 +370,7 @@ int sdp_handle_service_search_attribute_request(uint8_t * packet, uint16_t remot
int first_answer = 1;
int continuation = 0;
uint16_t current_service_index = 0;
linked_item_t *it = (linked_item_t *) sdp_service_records;
btstack_linked_item_t *it = (btstack_linked_item_t *) sdp_service_records;
for ( ; it ; it = it->next, ++current_service_index){
service_record_item_t * item = (service_record_item_t *) it;

View File

@ -48,7 +48,7 @@ extern "C" {
typedef struct {
// linked list - assert: first field
linked_item_t item;
btstack_linked_item_t item;
uint32_t service_record_handle;
uint8_t * service_record;

114
src/hci.c
View File

@ -121,7 +121,7 @@ static hci_connection_t * create_connection_for_bd_addr_and_type(bd_addr_t addr,
conn->authentication_flags = AUTH_FLAGS_NONE;
conn->bonding_flags = 0;
conn->requested_security_level = LEVEL_0;
linked_item_set_user(&conn->timeout.item, conn);
btstack_linked_item_set_user(&conn->timeout.item, conn);
conn->timeout.process = hci_connection_timeout_handler;
hci_connection_timestamp(conn);
conn->acl_recombination_length = 0;
@ -129,7 +129,7 @@ static hci_connection_t * create_connection_for_bd_addr_and_type(bd_addr_t addr,
conn->num_acl_packets_sent = 0;
conn->num_sco_packets_sent = 0;
conn->le_con_parameter_update_state = CON_PARAMETER_UPDATE_NONE;
linked_list_add(&hci_stack->connections, (linked_item_t *) conn);
btstack_linked_list_add(&hci_stack->connections, (btstack_linked_item_t *) conn);
return conn;
}
@ -158,8 +158,8 @@ void gap_le_set_connection_parameter_range(le_connection_parameter_range_t range
* @return hci connections iterator
*/
void hci_connections_get_iterator(linked_list_iterator_t *it){
linked_list_iterator_init(it, &hci_stack->connections);
void hci_connections_get_iterator(btstack_linked_list_iterator_t *it){
btstack_linked_list_iterator_init(it, &hci_stack->connections);
}
/**
@ -168,10 +168,10 @@ void hci_connections_get_iterator(linked_list_iterator_t *it){
* @return connection OR NULL, if not found
*/
hci_connection_t * hci_connection_for_handle(hci_con_handle_t con_handle){
linked_list_iterator_t it;
linked_list_iterator_init(&it, &hci_stack->connections);
while (linked_list_iterator_has_next(&it)){
hci_connection_t * item = (hci_connection_t *) linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, &hci_stack->connections);
while (btstack_linked_list_iterator_has_next(&it)){
hci_connection_t * item = (hci_connection_t *) btstack_linked_list_iterator_next(&it);
if ( item->con_handle == con_handle ) {
return item;
}
@ -185,10 +185,10 @@ hci_connection_t * hci_connection_for_handle(hci_con_handle_t con_handle){
* @return connection OR NULL, if not found
*/
hci_connection_t * hci_connection_for_bd_addr_and_type(bd_addr_t addr, bd_addr_type_t addr_type){
linked_list_iterator_t it;
linked_list_iterator_init(&it, &hci_stack->connections);
while (linked_list_iterator_has_next(&it)){
hci_connection_t * connection = (hci_connection_t *) linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, &hci_stack->connections);
while (btstack_linked_list_iterator_has_next(&it)){
hci_connection_t * connection = (hci_connection_t *) btstack_linked_list_iterator_next(&it);
if (connection->address_type != addr_type) continue;
if (memcmp(addr, connection->address, 6) != 0) continue;
return connection;
@ -197,7 +197,7 @@ hci_connection_t * hci_connection_for_bd_addr_and_type(bd_addr_t addr, bd_addr_
}
static void hci_connection_timeout_handler(timer_source_t *timer){
hci_connection_t * connection = (hci_connection_t *) linked_item_get_user(&timer->item);
hci_connection_t * connection = (hci_connection_t *) btstack_linked_item_get_user(&timer->item);
#ifdef HAVE_TIME
struct timeval tv;
gettimeofday(&tv, NULL);
@ -284,8 +284,8 @@ int hci_is_le_connection(hci_connection_t * connection){
*/
static int nr_hci_connections(void){
int count = 0;
linked_item_t *it;
for (it = (linked_item_t *) hci_stack->connections; it ; it = it->next, count++);
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) hci_stack->connections; it ; it = it->next, count++);
return count;
}
@ -311,8 +311,8 @@ uint8_t hci_number_free_acl_slots_for_handle(hci_con_handle_t con_handle){
bd_addr_type_t address_type = BD_ADDR_TYPE_UNKNOWN;
linked_item_t *it;
for (it = (linked_item_t *) hci_stack->connections; it ; it = it->next){
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) hci_stack->connections; it ; it = it->next){
hci_connection_t * connection = (hci_connection_t *) it;
if (connection->address_type == BD_ADDR_TYPE_CLASSIC){
num_packets_sent_classic += connection->num_acl_packets_sent;
@ -367,8 +367,8 @@ uint8_t hci_number_free_acl_slots_for_handle(hci_con_handle_t con_handle){
static int hci_number_free_sco_slots_for_handle(hci_con_handle_t handle){
int num_sco_packets_sent = 0;
linked_item_t *it;
for (it = (linked_item_t *) hci_stack->connections; it ; it = it->next){
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) hci_stack->connections; it ; it = it->next){
hci_connection_t * connection = (hci_connection_t *) it;
num_sco_packets_sent += connection->num_sco_packets_sent;
}
@ -716,7 +716,7 @@ static void hci_shutdown_connection(hci_connection_t *conn){
run_loop_remove_timer(&conn->timeout);
linked_list_remove(&hci_stack->connections, (linked_item_t *) conn);
btstack_linked_list_remove(&hci_stack->connections, (btstack_linked_item_t *) conn);
btstack_memory_hci_connection_free( conn );
// now it's gone
@ -1497,7 +1497,7 @@ static void event_handler(uint8_t *packet, int size){
memcpy(&bd_address, conn->address, 6);
// connection failed, remove entry
linked_list_remove(&hci_stack->connections, (linked_item_t *) conn);
btstack_linked_list_remove(&hci_stack->connections, (btstack_linked_item_t *) conn);
btstack_memory_hci_connection_free( conn );
// notify client if dedicated bonding
@ -1749,7 +1749,7 @@ static void event_handler(uint8_t *packet, int size){
hci_stack->le_connecting_state = LE_CONNECTING_IDLE;
// remove entry
if (conn){
linked_list_remove(&hci_stack->connections, (linked_item_t *) conn);
btstack_linked_list_remove(&hci_stack->connections, (btstack_linked_item_t *) conn);
btstack_memory_hci_connection_free( conn );
}
break;
@ -2262,7 +2262,7 @@ void hci_local_bd_addr(bd_addr_t address_buffer){
void hci_run(void){
// log_info("hci_run: entered");
linked_item_t * it;
btstack_linked_item_t * it;
// send continuation fragments first, as they block the prepared packet buffer
if (hci_stack->acl_fragmentation_total_size > 0) {
@ -2360,11 +2360,11 @@ void hci_run(void){
//
// check if whitelist needs modification
linked_list_iterator_t lit;
btstack_linked_list_iterator_t lit;
int modification_pending = 0;
linked_list_iterator_init(&lit, &hci_stack->le_whitelist);
while (linked_list_iterator_has_next(&lit)){
whitelist_entry_t * entry = (whitelist_entry_t*) linked_list_iterator_next(&lit);
btstack_linked_list_iterator_init(&lit, &hci_stack->le_whitelist);
while (btstack_linked_list_iterator_has_next(&lit)){
whitelist_entry_t * entry = (whitelist_entry_t*) btstack_linked_list_iterator_next(&lit);
if (entry->state & (LE_WHITELIST_REMOVE_FROM_CONTROLLER | LE_WHITELIST_ADD_TO_CONTROLLER)){
modification_pending = 1;
break;
@ -2379,9 +2379,9 @@ void hci_run(void){
}
// add/remove entries
linked_list_iterator_init(&lit, &hci_stack->le_whitelist);
while (linked_list_iterator_has_next(&lit)){
whitelist_entry_t * entry = (whitelist_entry_t*) linked_list_iterator_next(&lit);
btstack_linked_list_iterator_init(&lit, &hci_stack->le_whitelist);
while (btstack_linked_list_iterator_has_next(&lit)){
whitelist_entry_t * entry = (whitelist_entry_t*) btstack_linked_list_iterator_next(&lit);
if (entry->state & LE_WHITELIST_ADD_TO_CONTROLLER){
entry->state = LE_WHITELIST_ON_CONTROLLER;
hci_send_cmd(&hci_le_add_device_to_white_list, entry->address_type, entry->address);
@ -2392,7 +2392,7 @@ void hci_run(void){
bd_addr_t address;
bd_addr_type_t address_type = entry->address_type;
memcpy(address, entry->address, 6);
linked_list_remove(&hci_stack->le_whitelist, (linked_item_t *) entry);
btstack_linked_list_remove(&hci_stack->le_whitelist, (btstack_linked_item_t *) entry);
btstack_memory_whitelist_entry_free(entry);
hci_send_cmd(&hci_le_remove_device_from_white_list, address_type, address);
return;
@ -2402,7 +2402,7 @@ void hci_run(void){
// start connecting
if ( hci_stack->le_connecting_state == LE_CONNECTING_IDLE &&
!linked_list_empty(&hci_stack->le_whitelist)){
!btstack_linked_list_empty(&hci_stack->le_whitelist)){
bd_addr_t null_addr;
memset(null_addr, 0, 6);
hci_send_cmd(&hci_le_create_connection,
@ -2425,7 +2425,7 @@ void hci_run(void){
#endif
// send pending HCI commands
for (it = (linked_item_t *) hci_stack->connections; it ; it = it->next){
for (it = (btstack_linked_item_t *) hci_stack->connections; it ; it = it->next){
hci_connection_t * connection = (hci_connection_t *) it;
switch(connection->state){
@ -2609,11 +2609,11 @@ void hci_run(void){
// free whitelist entries
#ifdef HAVE_BLE
{
linked_list_iterator_t lit;
linked_list_iterator_init(&lit, &hci_stack->le_whitelist);
while (linked_list_iterator_has_next(&lit)){
whitelist_entry_t * entry = (whitelist_entry_t*) linked_list_iterator_next(&lit);
linked_list_remove(&hci_stack->le_whitelist, (linked_item_t *) entry);
btstack_linked_list_iterator_t lit;
btstack_linked_list_iterator_init(&lit, &hci_stack->le_whitelist);
while (btstack_linked_list_iterator_has_next(&lit)){
whitelist_entry_t * entry = (whitelist_entry_t*) btstack_linked_list_iterator_next(&lit);
btstack_linked_list_remove(&hci_stack->le_whitelist, (btstack_linked_item_t *) entry);
btstack_memory_whitelist_entry_free(entry);
}
}
@ -3250,8 +3250,8 @@ uint8_t le_central_connect(bd_addr_t addr, bd_addr_type_t addr_type){
// @assumption: only a single outgoing LE Connection exists
static hci_connection_t * le_central_get_outgoing_connection(void){
linked_item_t *it;
for (it = (linked_item_t *) hci_stack->connections; it ; it = it->next){
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) hci_stack->connections; it ; it = it->next){
hci_connection_t * conn = (hci_connection_t *) it;
if (!hci_is_le_connection(conn)) continue;
switch (conn->state){
@ -3272,7 +3272,7 @@ uint8_t le_central_connect_cancel(void){
case SEND_CREATE_CONNECTION:
// skip sending create connection and emit event instead
hci_emit_le_connection_complete(conn->address_type, conn->address, 0, ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER);
linked_list_remove(&hci_stack->connections, (linked_item_t *) conn);
btstack_linked_list_remove(&hci_stack->connections, (btstack_linked_item_t *) conn);
btstack_memory_hci_connection_free( conn );
break;
case SENT_CREATE_CONNECTION:
@ -3439,23 +3439,23 @@ gap_connection_type_t gap_get_connection_type(hci_con_handle_t connection_handle
*/
int gap_auto_connection_start(bd_addr_type_t address_type, bd_addr_t address){
// check capacity
int num_entries = linked_list_count(&hci_stack->le_whitelist);
int num_entries = btstack_linked_list_count(&hci_stack->le_whitelist);
if (num_entries >= hci_stack->le_whitelist_capacity) return ERROR_CODE_MEMORY_CAPACITY_EXCEEDED;
whitelist_entry_t * entry = btstack_memory_whitelist_entry_get();
if (!entry) return BTSTACK_MEMORY_ALLOC_FAILED;
entry->address_type = address_type;
memcpy(entry->address, address, 6);
entry->state = LE_WHITELIST_ADD_TO_CONTROLLER;
linked_list_add(&hci_stack->le_whitelist, (linked_item_t*) entry);
btstack_linked_list_add(&hci_stack->le_whitelist, (btstack_linked_item_t*) entry);
hci_run();
return 0;
}
static void hci_remove_from_whitelist(bd_addr_type_t address_type, bd_addr_t address){
linked_list_iterator_t it;
linked_list_iterator_init(&it, &hci_stack->le_whitelist);
while (linked_list_iterator_has_next(&it)){
whitelist_entry_t * entry = (whitelist_entry_t*) linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, &hci_stack->le_whitelist);
while (btstack_linked_list_iterator_has_next(&it)){
whitelist_entry_t * entry = (whitelist_entry_t*) btstack_linked_list_iterator_next(&it);
if (entry->address_type != address_type) continue;
if (memcmp(entry->address, address, 6) != 0) continue;
if (entry->state & LE_WHITELIST_ON_CONTROLLER){
@ -3464,7 +3464,7 @@ static void hci_remove_from_whitelist(bd_addr_type_t address_type, bd_addr_t add
continue;
}
// direclty remove entry from whitelist
linked_list_iterator_remove(&it);
btstack_linked_list_iterator_remove(&it);
btstack_memory_whitelist_entry_free(entry);
}
}
@ -3486,17 +3486,17 @@ int gap_auto_connection_stop(bd_addr_type_t address_type, bd_addr_t address){
* @note Convenience function to stop all active auto connection attempts
*/
void gap_auto_connection_stop_all(void){
linked_list_iterator_t it;
linked_list_iterator_init(&it, &hci_stack->le_whitelist);
while (linked_list_iterator_has_next(&it)){
whitelist_entry_t * entry = (whitelist_entry_t*) linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, &hci_stack->le_whitelist);
while (btstack_linked_list_iterator_has_next(&it)){
whitelist_entry_t * entry = (whitelist_entry_t*) btstack_linked_list_iterator_next(&it);
if (entry->state & LE_WHITELIST_ON_CONTROLLER){
// remove from controller if already present
entry->state |= LE_WHITELIST_REMOVE_FROM_CONTROLLER;
continue;
}
// directly remove entry from whitelist
linked_list_iterator_remove(&it);
btstack_linked_list_iterator_remove(&it);
btstack_memory_whitelist_entry_free(entry);
}
hci_run();
@ -3538,10 +3538,10 @@ void hci_set_hardware_error_callback(void (*fn)(void)){
void hci_disconnect_all(void){
linked_list_iterator_t it;
linked_list_iterator_init(&it, &hci_stack->connections);
while (linked_list_iterator_has_next(&it)){
hci_connection_t * con = (hci_connection_t*) linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, &hci_stack->connections);
while (btstack_linked_list_iterator_has_next(&it)){
hci_connection_t * con = (hci_connection_t*) btstack_linked_list_iterator_next(&it);
if (con->state == SENT_DISCONNECT) continue;
con->state = SEND_DISCONNECT;
}

View File

@ -347,7 +347,7 @@ typedef struct sm_connection {
typedef struct {
// linked list - assert: first field
linked_item_t item;
btstack_linked_item_t item;
// remote side
bd_addr_t address;
@ -502,7 +502,7 @@ enum {
};
typedef struct {
linked_item_t item;
btstack_linked_item_t item;
bd_addr_t address;
bd_addr_type_t address_type;
uint8_t state;
@ -529,7 +529,7 @@ typedef struct {
bt_control_t * control;
// list of existing baseband connections
btstack_linked_list_t connections;
btstack_btstack_linked_list_t connections;
// single buffer for HCI packet assembly + additional prebuffer for H4 drivers
uint8_t hci_packet_buffer_prefix[HCI_OUTGOING_PRE_BUFFER_SIZE];
@ -629,7 +629,7 @@ typedef struct {
// LE Whitelist Management
uint16_t le_whitelist_capacity;
btstack_linked_list_t le_whitelist;
btstack_btstack_linked_list_t le_whitelist;
// custom BD ADDR
bd_addr_t custom_bd_addr;
@ -643,7 +643,7 @@ typedef struct {
/**
* set connection iterator
*/
void hci_connections_get_iterator(linked_list_iterator_t *it);
void hci_connections_get_iterator(btstack_linked_list_iterator_t *it);
// create and send hci command packets based on a template and a list of parameters
uint16_t hci_create_cmd(uint8_t *hci_cmd_buffer, hci_cmd_t *cmd, ...);

View File

@ -73,10 +73,10 @@ static void l2cap_packet_handler(uint8_t packet_type, uint8_t *packet, uint16_t
static l2cap_signaling_response_t signaling_responses[NR_PENDING_SIGNALING_RESPONSES];
static int signaling_responses_pending;
static btstack_linked_list_t l2cap_channels;
static btstack_linked_list_t l2cap_services;
static btstack_linked_list_t l2cap_le_channels;
static btstack_linked_list_t l2cap_le_services;
static btstack_btstack_linked_list_t l2cap_channels;
static btstack_btstack_linked_list_t l2cap_services;
static btstack_btstack_linked_list_t l2cap_le_channels;
static btstack_btstack_linked_list_t l2cap_le_services;
static void (*packet_handler) (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) = null_packet_handler;
static btstack_packet_handler_t attribute_protocol_packet_handler;
@ -188,10 +188,10 @@ static void l2cap_emit_connection_parameter_update_response(uint16_t handle, uin
}
static l2cap_channel_t * l2cap_get_channel_for_local_cid(uint16_t local_cid){
linked_list_iterator_t it;
linked_list_iterator_init(&it, &l2cap_channels);
while (linked_list_iterator_has_next(&it)){
l2cap_channel_t * channel = (l2cap_channel_t *) linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
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->local_cid == local_cid) {
return channel;
}
@ -224,10 +224,10 @@ uint16_t l2cap_get_remote_mtu_for_local_cid(uint16_t local_cid){
}
static l2cap_channel_t * l2cap_channel_for_rtx_timer(timer_source_t * ts){
linked_list_iterator_t it;
linked_list_iterator_init(&it, &l2cap_channels);
while (linked_list_iterator_has_next(&it)){
l2cap_channel_t * channel = (l2cap_channel_t *) linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
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->rtx == ts) {
return channel;
}
@ -248,7 +248,7 @@ static void l2cap_rtx_timeout(timer_source_t * ts){
// discard channel
// no need to stop timer here, it is removed from list during timer callback
linked_list_remove(&l2cap_channels, (linked_item_t *) channel);
btstack_linked_list_remove(&l2cap_channels, (btstack_linked_item_t *) channel);
btstack_memory_l2cap_channel_free(channel);
}
@ -533,11 +533,11 @@ static void l2cap_run(void){
}
uint8_t config_options[4];
linked_list_iterator_t it;
linked_list_iterator_init(&it, &l2cap_channels);
while (linked_list_iterator_has_next(&it)){
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, &l2cap_channels);
while (btstack_linked_list_iterator_has_next(&it)){
l2cap_channel_t * channel = (l2cap_channel_t *) linked_list_iterator_next(&it);
l2cap_channel_t * channel = (l2cap_channel_t *) btstack_linked_list_iterator_next(&it);
// log_info("l2cap_run: channel %p, state %u, var 0x%02x", channel, channel->state, channel->state_var);
switch (channel->state){
@ -564,7 +564,7 @@ static void l2cap_run(void){
l2cap_send_signaling_packet(channel->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);
linked_list_iterator_remove(&it);
btstack_linked_list_iterator_remove(&it);
btstack_memory_l2cap_channel_free(channel);
break;
@ -645,8 +645,8 @@ static void l2cap_run(void){
#ifdef HAVE_BLE
// send l2cap con paramter update if necessary
hci_connections_get_iterator(&it);
while(linked_list_iterator_has_next(&it)){
hci_connection_t * connection = (hci_connection_t *) linked_list_iterator_next(&it);
while(btstack_linked_list_iterator_has_next(&it)){
hci_connection_t * connection = (hci_connection_t *) btstack_linked_list_iterator_next(&it);
if (connection->address_type != BD_ADDR_TYPE_LE_PUBLIC && connection->address_type != BD_ADDR_TYPE_LE_RANDOM) continue;
if (!hci_can_send_acl_packet_now(connection->con_handle)) continue;
switch (connection->le_con_parameter_update_state){
@ -746,7 +746,7 @@ uint8_t l2cap_create_channel(btstack_packet_handler_t channel_packet_handler, bd
chan->required_security_level = LEVEL_0;
// add to connections list
linked_list_add(&l2cap_channels, (linked_item_t *) chan);
btstack_linked_list_add(&l2cap_channels, (btstack_linked_item_t *) chan);
// store local_cid
if (out_local_cid){
@ -781,10 +781,10 @@ void l2cap_disconnect_internal(uint16_t local_cid, uint8_t reason){
}
static void l2cap_handle_connection_failed_for_addr(bd_addr_t address, uint8_t status){
linked_list_iterator_t it;
linked_list_iterator_init(&it, &l2cap_channels);
while (linked_list_iterator_has_next(&it)){
l2cap_channel_t * channel = (l2cap_channel_t *) linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
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 ( BD_ADDR_CMP( channel->address, address) != 0) continue;
// channel for this address found
switch (channel->state){
@ -794,7 +794,7 @@ static void l2cap_handle_connection_failed_for_addr(bd_addr_t address, uint8_t s
l2cap_emit_channel_opened(channel, status);
// discard channel
l2cap_stop_rtx(channel);
linked_list_iterator_remove(&it);
btstack_linked_list_iterator_remove(&it);
btstack_memory_l2cap_channel_free(channel);
break;
default:
@ -804,10 +804,10 @@ static void l2cap_handle_connection_failed_for_addr(bd_addr_t address, uint8_t s
}
static void l2cap_handle_connection_success_for_addr(bd_addr_t address, hci_con_handle_t handle){
linked_list_iterator_t it;
linked_list_iterator_init(&it, &l2cap_channels);
while (linked_list_iterator_has_next(&it)){
l2cap_channel_t * channel = (l2cap_channel_t *) linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
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 ( ! BD_ADDR_CMP( channel->address, address) ){
l2cap_handle_connection_complete(handle, channel);
}
@ -820,7 +820,7 @@ static void l2cap_event_handler(uint8_t *packet, uint16_t size){
bd_addr_t address;
hci_con_handle_t handle;
linked_list_iterator_t it;
btstack_linked_list_iterator_t it;
int hci_con_used;
switch(packet[0]){
@ -856,13 +856,13 @@ static void l2cap_event_handler(uint8_t *packet, uint16_t size){
case HCI_EVENT_DISCONNECTION_COMPLETE:
// send l2cap disconnect events for all channels on this handle and free them
handle = READ_BT_16(packet, 3);
linked_list_iterator_init(&it, &l2cap_channels);
while (linked_list_iterator_has_next(&it)){
l2cap_channel_t * channel = (l2cap_channel_t *) linked_list_iterator_next(&it);
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;
l2cap_emit_channel_closed(channel);
l2cap_stop_rtx(channel);
linked_list_iterator_remove(&it);
btstack_linked_list_iterator_remove(&it);
btstack_memory_l2cap_channel_free(channel);
}
break;
@ -877,9 +877,9 @@ static void l2cap_event_handler(uint8_t *packet, uint16_t size){
if (gap_get_connection_type(handle) != GAP_CONNECTION_ACL) break;
if (hci_authentication_active_for_handle(handle)) break;
hci_con_used = 0;
linked_list_iterator_init(&it, &l2cap_channels);
while (linked_list_iterator_has_next(&it)){
l2cap_channel_t * channel = (l2cap_channel_t *) linked_list_iterator_next(&it);
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;
hci_con_used = 1;
break;
@ -892,9 +892,9 @@ static void l2cap_event_handler(uint8_t *packet, uint16_t size){
case DAEMON_EVENT_HCI_PACKET_SENT:
l2cap_run(); // try sending signaling packets first
linked_list_iterator_init(&it, &l2cap_channels);
while (linked_list_iterator_has_next(&it)){
l2cap_channel_t * channel = (l2cap_channel_t *) linked_list_iterator_next(&it);
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->packet_handler) continue;
(* (channel->packet_handler))(HCI_EVENT_PACKET, channel->local_cid, packet, size);
}
@ -911,9 +911,9 @@ static void l2cap_event_handler(uint8_t *packet, uint16_t size){
case HCI_EVENT_READ_REMOTE_SUPPORTED_FEATURES_COMPLETE:
handle = READ_BT_16(packet, 3);
linked_list_iterator_init(&it, &l2cap_channels);
while (linked_list_iterator_has_next(&it)){
l2cap_channel_t * channel = (l2cap_channel_t *) linked_list_iterator_next(&it);
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;
l2cap_handle_remote_supported_features_received(channel);
break;
@ -923,9 +923,9 @@ static void l2cap_event_handler(uint8_t *packet, uint16_t size){
case GAP_SECURITY_LEVEL:
handle = READ_BT_16(packet, 2);
log_info("l2cap - security level update");
linked_list_iterator_init(&it, &l2cap_channels);
while (linked_list_iterator_has_next(&it)){
l2cap_channel_t * channel = (l2cap_channel_t *) linked_list_iterator_next(&it);
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;
log_info("l2cap - state %u", channel->state);
@ -1045,7 +1045,7 @@ static void l2cap_handle_connection_request(hci_con_handle_t handle, uint8_t sig
channel->state_var = L2CAP_CHANNEL_STATE_VAR_SEND_CONN_RESP_PEND;
// add to connections list
linked_list_add(&l2cap_channels, (linked_item_t *) channel);
btstack_linked_list_add(&l2cap_channels, (btstack_linked_item_t *) channel);
// assert security requirements
gap_request_security_level(handle, channel->required_security_level);
@ -1180,7 +1180,7 @@ static void l2cap_signaling_handler_channel(l2cap_channel_t *channel, uint8_t *c
}
// discard channel
linked_list_remove(&l2cap_channels, (linked_item_t *) channel);
btstack_linked_list_remove(&l2cap_channels, (btstack_linked_item_t *) channel);
btstack_memory_l2cap_channel_free(channel);
break;
}
@ -1294,10 +1294,10 @@ static void l2cap_signaling_handler_dispatch( hci_con_handle_t handle, uint8_t *
uint16_t dest_cid = READ_BT_16(command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET);
// Find channel for this sig_id and connection handle
linked_list_iterator_t it;
linked_list_iterator_init(&it, &l2cap_channels);
while (linked_list_iterator_has_next(&it)){
l2cap_channel_t * channel = (l2cap_channel_t *) linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
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 (code & 1) {
// match odd commands (responses) by previous signaling identifier
@ -1450,15 +1450,15 @@ void l2cap_finialize_channel_close(l2cap_channel_t *channel){
l2cap_emit_channel_closed(channel);
// discard channel
l2cap_stop_rtx(channel);
linked_list_remove(&l2cap_channels, (linked_item_t *) channel);
btstack_linked_list_remove(&l2cap_channels, (btstack_linked_item_t *) channel);
btstack_memory_l2cap_channel_free(channel);
}
static l2cap_service_t * l2cap_get_service_internal(btstack_linked_list_t * services, uint16_t psm){
linked_list_iterator_t it;
linked_list_iterator_init(&it, services);
while (linked_list_iterator_has_next(&it)){
l2cap_service_t * service = (l2cap_service_t *) linked_list_iterator_next(&it);
static l2cap_service_t * l2cap_get_service_internal(btstack_btstack_linked_list_t * services, uint16_t psm){
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, services);
while (btstack_linked_list_iterator_has_next(&it)){
l2cap_service_t * service = (l2cap_service_t *) btstack_linked_list_iterator_next(&it);
if ( service->psm == psm){
return service;
};
@ -1498,7 +1498,7 @@ uint8_t l2cap_register_service(btstack_packet_handler_t service_packet_handler,
service->required_security_level = security_level;
// add to services list
linked_list_add(&l2cap_services, (linked_item_t *) service);
btstack_linked_list_add(&l2cap_services, (btstack_linked_item_t *) service);
// enable page scan
hci_connectable_control(1);
@ -1512,11 +1512,11 @@ void l2cap_unregister_service(uint16_t psm){
l2cap_service_t *service = l2cap_get_service(psm);
if (!service) return;
linked_list_remove(&l2cap_services, (linked_item_t *) service);
btstack_linked_list_remove(&l2cap_services, (btstack_linked_item_t *) service);
btstack_memory_l2cap_service_free(service);
// disable page scan when no services registered
if (!linked_list_empty(&l2cap_services)) return;
if (!btstack_linked_list_empty(&l2cap_services)) return;
hci_connectable_control(0);
}
@ -1577,7 +1577,7 @@ void l2cap_le_register_service(btstack_packet_handler_t packet_handler, uint16_t
service->required_security_level = security_level;
// add to services list
linked_list_add(&l2cap_le_services, (linked_item_t *) service);
btstack_linked_list_add(&l2cap_le_services, (btstack_linked_item_t *) service);
// done
l2cap_emit_service_registered(connection, 0, psm);
@ -1589,7 +1589,7 @@ void l2cap_le_unregister_service(uint16_t psm) {
l2cap_service_t *service = l2cap_le_get_service(psm);
if (!service) return;
linked_list_remove(&l2cap_le_services, (linked_item_t *) service);
btstack_linked_list_remove(&l2cap_le_services, (btstack_linked_item_t *) service);
btstack_memory_l2cap_service_free(service);
}
#endif

View File

@ -100,7 +100,7 @@ typedef enum {
// info regarding an actual connection
typedef struct {
// linked list - assert: first field
linked_item_t item;
btstack_linked_item_t item;
L2CAP_STATE state;
L2CAP_CHANNEL_STATE_VAR state_var;
@ -135,7 +135,7 @@ typedef struct {
// info regarding potential connections
typedef struct {
// linked list - assert: first field
linked_item_t item;
btstack_linked_item_t item;
// service id
uint16_t psm;

View File

@ -59,13 +59,13 @@ extern "C" {
#endif
typedef struct data_source {
linked_item_t item;
btstack_linked_item_t item;
int fd; // <-- file descriptor to watch or 0
int (*process)(struct data_source *ds); // <-- do processing
} data_source_t;
typedef struct timer {
linked_item_t item;
btstack_linked_item_t item;
#ifdef HAVE_TIME
struct timeval timeout; // <-- next timeout
#endif

View File

@ -14,7 +14,7 @@
static btstack_packet_handler_t att_packet_handler;
static void (*registered_l2cap_packet_handler) (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) = NULL;
static btstack_linked_list_t connections;
static btstack_btstack_linked_list_t connections;
static const uint16_t max_mtu = 23;
static uint8_t l2cap_stack_buffer[HCI_INCOMING_PRE_BUFFER_SIZE + 8 + max_mtu]; // pre buffer + HCI Header + L2CAP header
uint16_t gatt_client_handle = 0x40;
@ -147,9 +147,9 @@ hci_connection_t * hci_connection_for_handle(hci_con_handle_t con_handle){
printf("hci_connection_for_handle not implemented in mock backend\n");
return NULL;
}
void hci_connections_get_iterator(linked_list_iterator_t *it){
void hci_connections_get_iterator(btstack_linked_list_iterator_t *it){
// printf("hci_connections_get_iterator not implemented in mock backend\n");
linked_list_iterator_init(it, &connections);
btstack_linked_list_iterator_init(it, &connections);
}
// int hci_send_cmd(const hci_cmd_t *cmd, ...){

View File

@ -1 +1 @@
btstack_linked_list_test
btstack_btstack_linked_list_test

View File

@ -17,14 +17,14 @@ COMMON = \
COMMON_OBJ = $(COMMON:.c=.o)
all: btstack_linked_list_test
all: btstack_btstack_linked_list_test
btstack_linked_list_test: ${COMMON_OBJ} linked_list_test.c
btstack_btstack_linked_list_test: ${COMMON_OBJ} btstack_linked_list_test.c
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
test: all
./btstack_linked_list_test
./btstack_btstack_linked_list_test
clean:
rm -fr btstack_linked_list_test *.dSYM *.o ../src/*.o
rm -fr btstack_btstack_linked_list_test *.dSYM *.o ../src/*.o

View File

@ -2,210 +2,210 @@
#include "CppUTest/CommandLineTestRunner.h"
#include "btstack_linked_list.h"
btstack_linked_list_t testList;
linked_item_t itemA;
linked_item_t itemB;
linked_item_t itemC;
linked_item_t itemD;
btstack_btstack_linked_list_t testList;
btstack_linked_item_t itemA;
btstack_linked_item_t itemB;
btstack_linked_item_t itemC;
btstack_linked_item_t itemD;
TEST_GROUP(LinkedList){
void setup(void){
testList = NULL;
linked_list_add(&testList, &itemD);
linked_list_add(&testList, &itemC);
linked_list_add(&testList, &itemB);
linked_list_add(&testList, &itemA);
btstack_linked_list_add(&testList, &itemD);
btstack_linked_list_add(&testList, &itemC);
btstack_linked_list_add(&testList, &itemB);
btstack_linked_list_add(&testList, &itemA);
}
};
TEST(LinkedList, Iterator){
linked_list_iterator_t it;
linked_list_iterator_init(&it, &testList);
linked_item_t * item;
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, &testList);
btstack_linked_item_t * item;
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemA);
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemB);
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemC);
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemD);
CHECK(!linked_list_iterator_has_next(&it));
CHECK(!btstack_linked_list_iterator_has_next(&it));
}
TEST(LinkedList, RemoveFirstUsingIterator){
linked_list_iterator_t it;
linked_list_iterator_init(&it, &testList);
linked_item_t * item;
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, &testList);
btstack_linked_item_t * item;
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemA);
linked_list_iterator_remove(&it);
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
btstack_linked_list_iterator_remove(&it);
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemB);
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemC);
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemD);
CHECK(!linked_list_iterator_has_next(&it));
CHECK(!btstack_linked_list_iterator_has_next(&it));
}
TEST(LinkedList, RemoveFirstUsingListRemove){
linked_list_iterator_t it;
linked_list_iterator_init(&it, &testList);
linked_item_t * item;
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, &testList);
btstack_linked_item_t * item;
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemA);
linked_list_remove(&testList, &itemA);
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
btstack_linked_list_remove(&testList, &itemA);
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemB);
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemC);
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemD);
CHECK(!linked_list_iterator_has_next(&it));
CHECK(!btstack_linked_list_iterator_has_next(&it));
}
TEST(LinkedList, RemoveSecondUsingIterator){
linked_list_iterator_t it;
linked_list_iterator_init(&it, &testList);
linked_item_t * item;
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, &testList);
btstack_linked_item_t * item;
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemB);
linked_list_iterator_remove(&it);
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
btstack_linked_list_iterator_remove(&it);
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemC);
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemD);
CHECK(!linked_list_iterator_has_next(&it));
CHECK(!btstack_linked_list_iterator_has_next(&it));
}
TEST(LinkedList, RemoveSecondUsingListRemove){
linked_list_iterator_t it;
linked_list_iterator_init(&it, &testList);
linked_item_t * item;
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, &testList);
btstack_linked_item_t * item;
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemB);
linked_list_remove(&testList, &itemB);
item = linked_list_iterator_next(&it);
btstack_linked_list_remove(&testList, &itemB);
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemC);
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemD);
CHECK(!linked_list_iterator_has_next(&it));
CHECK(!btstack_linked_list_iterator_has_next(&it));
}
TEST(LinkedList, RemoveThirdUsingIterator){
linked_list_iterator_t it;
linked_list_iterator_init(&it, &testList);
linked_item_t * item;
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, &testList);
btstack_linked_item_t * item;
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemB);
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemC);
linked_list_iterator_remove(&it);
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
btstack_linked_list_iterator_remove(&it);
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemD);
CHECK(!linked_list_iterator_has_next(&it));
CHECK(!btstack_linked_list_iterator_has_next(&it));
}
TEST(LinkedList, RemoveLastUsingIterator){
linked_list_iterator_t it;
linked_list_iterator_init(&it, &testList);
linked_item_t * item;
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, &testList);
btstack_linked_item_t * item;
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemB);
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemC);
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemD);
linked_list_iterator_remove(&it);
CHECK(!linked_list_iterator_has_next(&it));
btstack_linked_list_iterator_remove(&it);
CHECK(!btstack_linked_list_iterator_has_next(&it));
}
TEST(LinkedList, RemoveLastUsingListRemove){
linked_list_iterator_t it;
linked_list_iterator_init(&it, &testList);
linked_item_t * item;
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, &testList);
btstack_linked_item_t * item;
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemB);
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemC);
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemD);
linked_list_remove(&testList, &itemD);
CHECK(!linked_list_iterator_has_next(&it));
btstack_linked_list_remove(&testList, &itemD);
CHECK(!btstack_linked_list_iterator_has_next(&it));
}
TEST(LinkedList, RemoveSecondAndThirdUsingIterator){
linked_list_iterator_t it;
linked_list_iterator_init(&it, &testList);
linked_item_t * item;
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, &testList);
btstack_linked_item_t * item;
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemB);
linked_list_iterator_remove(&it); // B
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
btstack_linked_list_iterator_remove(&it); // B
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemC);
linked_list_iterator_remove(&it); // C
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
btstack_linked_list_iterator_remove(&it); // C
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemD);
CHECK(!linked_list_iterator_has_next(&it));
CHECK(!btstack_linked_list_iterator_has_next(&it));
}
TEST(LinkedList, RemoveSecondAndThirdUsingListRemove){
linked_list_iterator_t it;
linked_list_iterator_init(&it, &testList);
linked_item_t * item;
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, &testList);
btstack_linked_item_t * item;
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemB);
linked_list_remove(&testList, &itemB);
linked_list_remove(&testList, &itemC);
CHECK(linked_list_iterator_has_next(&it));
item = linked_list_iterator_next(&it);
btstack_linked_list_remove(&testList, &itemB);
btstack_linked_list_remove(&testList, &itemC);
CHECK(btstack_linked_list_iterator_has_next(&it));
item = btstack_linked_list_iterator_next(&it);
CHECK_EQUAL(item, &itemD);
CHECK(!linked_list_iterator_has_next(&it));
CHECK(!btstack_linked_list_iterator_has_next(&it));
}
int main (int argc, const char * argv[]){

View File

@ -9,17 +9,17 @@
#include "btstack-config.h"
extern btstack_linked_list_t db_mem_link_keys ;
extern btstack_linked_list_t db_mem_names ;
extern btstack_btstack_linked_list_t db_mem_link_keys ;
extern btstack_btstack_linked_list_t db_mem_names ;
// const extern "C" db_mem_device_name_t * btstack_memory_db_mem_device_name_get(void);
// const extern "C" void btstack_memory_init(void);
void dump(btstack_linked_list_t list){
void dump(btstack_btstack_linked_list_t list){
printf("dump:\n");
int i;
linked_item_t *it;
for (it = (linked_item_t *) list, i = 1; it ; it = it->next, i++){
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) list, i = 1; it ; it = it->next, i++){
db_mem_device_t * item = (db_mem_device_t *) it;
db_mem_device_name_t * item1 = (db_mem_device_name_t *) it;
db_mem_device_link_key_t * item2 = (db_mem_device_link_key_t *) it;

View File

@ -19,7 +19,7 @@ static uint16_t packet_buffer_len = 0;
static uint8_t aes128_cyphertext[16];
static hci_connection_t the_connection;
static btstack_linked_list_t connections;
static btstack_btstack_linked_list_t connections;
void mock_init(void){
the_connection.item.next = NULL;
@ -131,8 +131,8 @@ hci_connection_t * hci_connection_for_bd_addr_and_type(bd_addr_t addr, bd_addr_t
hci_connection_t * hci_connection_for_handle(hci_con_handle_t con_handle){
return &the_connection;
}
void hci_connections_get_iterator(linked_list_iterator_t *it){
linked_list_iterator_init(it, &connections);
void hci_connections_get_iterator(btstack_linked_list_iterator_t *it){
btstack_linked_list_iterator_init(it, &connections);
}
// get addr type and address used in advertisement packets