static void put_link_key(bd_addr_t bd_addr, link_key_t link_key, link_key_type_t link_key_type){

    // check for existing record and remove if found
    btstack_link_key_db_memory_entry_t * record = get_item(db_mem_link_keys, bd_addr);
    if (record){
        btstack_linked_list_remove(&db_mem_link_keys, (btstack_linked_item_t*) record);
    }

    // record not found, get new one from memory pool
    if (!record) {
        record = btstack_memory_btstack_link_key_db_memory_entry_get();
    }

    // if none left, re-use last item and remove from list
    if (!record){
        record = (btstack_link_key_db_memory_entry_t*) btstack_linked_list_get_last_item(&db_mem_link_keys);
        if (record) {
            btstack_linked_list_remove(&db_mem_link_keys, (btstack_linked_item_t*) record);
        }
    }
        
    if (!record) return;
    
    memcpy(record->bd_addr, bd_addr, sizeof(bd_addr_t));
    memcpy(record->link_key, link_key, LINK_KEY_LEN);
    record->link_key_type = link_key_type;
    btstack_linked_list_add(&db_mem_link_keys, (btstack_linked_item_t *) record);
}
示例#2
0
/**
 * @brief register read/write callbacks for specific handle range
 * @param att_service_handler_t
 */
void att_server_register_service_handler(att_service_handler_t * handler){
    if (att_service_handler_for_handle(handler->start_handle) ||
        att_service_handler_for_handle(handler->end_handle)){
        log_error("handler for range 0x%04x-0x%04x already registered", handler->start_handle, handler->end_handle);
        return;
    }
    btstack_linked_list_add(&service_handlers, (btstack_linked_item_t*) handler);
}
static int get_link_key(bd_addr_t bd_addr, link_key_t link_key, link_key_type_t * link_key_type) {
    btstack_link_key_db_memory_entry_t * item = get_item(db_mem_link_keys, bd_addr);
    
    if (!item) return 0;
    
    memcpy(link_key, item->link_key, LINK_KEY_LEN);
    if (link_key_type) {
        *link_key_type = item->link_key_type;
    }
	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;
}
/**
 * Add data_source to run_loop
 */
static void btstack_run_loop_embedded_add_data_source(btstack_data_source_t *ds){
    btstack_linked_list_add(&data_sources, (btstack_linked_item_t *) ds);
}
/**
 * Add data_source to run_loop
 */
static void btstack_run_loop_posix_add_data_source(btstack_data_source_t *ds){
    data_sources_modified = 1;
    // log_info("btstack_run_loop_posix_add_data_source %x with fd %u\n", (int) ds, ds->fd);
    btstack_linked_list_add(&data_sources, (btstack_linked_item_t *) ds);
}