Merge branch 'develop' into le-secure-connection

This commit is contained in:
Matthias Ringwald 2016-06-09 21:44:03 +02:00
commit b8f36d6c46
14 changed files with 188 additions and 197 deletions

View File

@ -50,10 +50,6 @@ SM_REAL += \
sm.c \
le_device_db_memory.c \
SM_MINIMAL += \
sm_minimal.c \
le_device_db_dummy.c \
PAN += \
pan.c \
@ -99,7 +95,6 @@ EXAMPLES_USING_LE = \
CORE_OBJ = $(CORE:.c=.o)
COMMON_OBJ = $(COMMON:.c=.o)
SM_REAL_OBJ = $(SM_REAL:.c=.o) $(MBEDTLS:.c=.o)
SM_MINIMAL_OBJ = $(SM_MINIMAL:.c=.o)
ATT_OBJ = $(ATT:.c=.o)
GATT_CLIENT_OBJ = $(GATT_CLIENT:.c=.o)
GATT_SERVER_OBJ = $(GATT_SERVER:.c=.o)

View File

@ -73,8 +73,8 @@
#include "ancs_client_demo.h"
static const uint8_t adv_data[] = {
// Flags general discoverable
0x02, 0x01, 0x02,
// Flags general discoverable, BR/EDR not supported
0x02, 0x01, 0x06,
// Name
0x05, 0x09, 'A', 'N', 'C', 'S',
// Service Solicitation, 128-bit UUIDs - ANCS (little endian)

View File

@ -68,6 +68,10 @@ typedef enum {
TC_W4_BATTERY_DATA
} gc_state_t;
static int blacklist_index = 0;
static bd_addr_t blacklist[20];
static advertising_report_t report;
static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
static bd_addr_t cmdline_addr = { };
@ -90,6 +94,24 @@ static void printUUID(uint8_t * uuid128, uint16_t uuid16){
}
}
static int blacklist_size(void){
return sizeof(blacklist) / sizeof(bd_addr_t);
}
static int blacklist_contains(bd_addr_t addr){
int i;
for (i=0; i<blacklist_size(); i++){
if (bd_addr_cmp(addr, blacklist[i]) == 0) return 1;
}
return 0;
}
static void add_to_blacklist(bd_addr_t addr){
printf("%s added to blacklist (no battery service found\n", bd_addr_to_str(addr));
bd_addr_copy(blacklist[blacklist_index], addr);
blacklist_index = (blacklist_index + 1) % blacklist_size();
}
static void dump_advertising_report(advertising_report_t * e){
printf(" * adv. event: evt-type %u, addr-type %u, addr %s, rssi %u, length adv %u, data: ", e->event_type,
e->address_type, bd_addr_to_str(e->address), e->rssi, e->length);
@ -116,36 +138,27 @@ static void dump_service(gatt_client_service_t * service){
printf("\n");
}
static void error_code(int status){
switch(status){
case ATT_ERROR_INSUFFICIENT_AUTHENTICATION:
printf("ATT_ERROR_INSUFFICIENT_AUTHENTICATION. TODO: security manager is not complete yet.\n");
break;
default:
printf(" status 0x%02x\n", status);
break;
}
}
static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
int status;
uint8_t battery_level;
switch(state){
case TC_W4_SERVICE_RESULT:
switch(hci_event_packet_get_type(packet)){
case GATT_EVENT_SERVICE_QUERY_RESULT:
gatt_event_service_query_result_get_service(packet, &battery_service);
printf("Battery service found:\n");
dump_service(&battery_service);
break;
case GATT_EVENT_QUERY_COMPLETE:
if (!packet[4]){
printf("Battery service not found. Restart scan.\n");
state = TC_W4_SCAN_RESULT;
gap_start_scan();
if (packet[4] != 0){
printf("SERVICE_QUERY_RESULT - Error status %x.\n", packet[4]);
add_to_blacklist(report.address);
gap_disconnect(connection_handle);
break;
}
state = TC_W4_CHARACTERISTIC_RESULT;
printf("\nSearch for battery level characteristic in battery service. ");
printf("\nSearch for battery level characteristic.\n");
gatt_client_discover_characteristics_for_service_by_uuid16(handle_gatt_client_event, connection_handle, &battery_service, battery_level_characteristic_uuid);
break;
default:
@ -156,30 +169,54 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
case TC_W4_CHARACTERISTIC_RESULT:
switch(hci_event_packet_get_type(packet)){
case GATT_EVENT_CHARACTERISTIC_QUERY_RESULT:
printf("Battery level characteristic found:\n");
gatt_event_characteristic_query_result_get_characteristic(packet, &config_characteristic);
dump_characteristic(&config_characteristic);
break;
case GATT_EVENT_QUERY_COMPLETE:
if (packet[4] != 0){
printf("CHARACTERISTIC_QUERY_RESULT - Error status %x.\n", packet[4]);
add_to_blacklist(report.address);
gap_disconnect(connection_handle);
break;
}
state = TC_W4_BATTERY_DATA;
printf("\nConfigure battery level characteristic for notify.");
gatt_client_write_client_characteristic_configuration(handle_gatt_client_event, connection_handle, &config_characteristic, GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION);
printf("\nConfigure battery level characteristic for notify.\n");
status = gatt_client_write_client_characteristic_configuration(handle_gatt_client_event, connection_handle, &config_characteristic, GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION);
if (status != 0){
printf("\nNotification not supported. Query value of characteristic.\n");
gatt_client_read_value_of_characteristic(handle_gatt_client_event, connection_handle, &config_characteristic);
}
break;
default:
break;
}
break;
case TC_W4_BATTERY_DATA:
if (hci_event_packet_get_type(packet) == GATT_EVENT_QUERY_COMPLETE){
if (packet[4] != 0){
printf("\nNotification is not possible: ");
error_code(packet[4]);
}
break;
switch(hci_event_packet_get_type(packet)){
case GATT_EVENT_NOTIFICATION:
printf("\nBattery Data:\n");
dump_characteristic_value(&packet[8], little_endian_read_16(packet, 6));
break;
case GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT:
if (gatt_event_characteristic_value_query_result_get_value_length(packet) < 1) break;
battery_level = gatt_event_characteristic_value_query_result_get_value(packet)[0];
printf("Battry level %d \n", battery_level);
break;
case GATT_EVENT_QUERY_COMPLETE:
if (packet[4] != 0){
printf("CHARACTERISTIC_VALUE_QUERY_RESULT - Error status %x.\n", packet[4]);
break;
}
// Use timer if repeated request is needed and notification is not supperted
gap_disconnect(connection_handle);
break;
default:
printf("Unknown packet type %x\n", hci_event_packet_get_type(packet));
break;
}
if (hci_event_packet_get_type(packet) != GATT_EVENT_NOTIFICATION) break;
printf("\nBattery Data:\n");
dump_characteristic_value(&packet[8], little_endian_read_16(packet, 6));
break;
default:
@ -189,30 +226,30 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
}
static void fill_advertising_report_from_packet(advertising_report_t * report, uint8_t *packet){
gap_event_advertising_report_get_address(packet, report->address);
report->event_type = gap_event_advertising_report_get_advertising_event_type(packet);
report->address_type = gap_event_advertising_report_get_address_type(packet);
report->rssi = gap_event_advertising_report_get_rssi(packet);
report->length = gap_event_advertising_report_get_data_length(packet);
report->data = gap_event_advertising_report_get_data(packet);
static void fill_advertising_report_from_packet(advertising_report_t * adv_report, uint8_t *packet){
gap_event_advertising_report_get_address(packet, adv_report->address);
adv_report->event_type = gap_event_advertising_report_get_advertising_event_type(packet);
adv_report->address_type = gap_event_advertising_report_get_address_type(packet);
adv_report->rssi = gap_event_advertising_report_get_rssi(packet);
adv_report->length = gap_event_advertising_report_get_data_length(packet);
adv_report->data = gap_event_advertising_report_get_data(packet);
}
static void hci_event_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
if (packet_type != HCI_EVENT_PACKET) return;
advertising_report_t report;
uint8_t event = hci_event_packet_get_type(packet);
switch (event) {
case BTSTACK_EVENT_STATE:
// BTstack activated, get started
if (btstack_event_state_get_state(packet) != HCI_STATE_WORKING) break;
if (cmdline_addr_found){
printf("Start connect to %s\n", bd_addr_to_str(cmdline_addr));
printf("Connect to %s\n", bd_addr_to_str(cmdline_addr));
state = TC_W4_CONNECT;
gap_connect(cmdline_addr, 0);
break;
}
printf("BTstack activated, start scanning!\n");
printf("Start scanning!\n");
state = TC_W4_SCAN_RESULT;
gap_set_scan_parameters(0,0x0030, 0x0030);
gap_start_scan();
@ -220,13 +257,17 @@ static void hci_event_handler(uint8_t packet_type, uint16_t channel, uint8_t *pa
case GAP_EVENT_ADVERTISING_REPORT:
if (state != TC_W4_SCAN_RESULT) return;
fill_advertising_report_from_packet(&report, packet);
if (blacklist_contains(report.address)) {
break;
}
dump_advertising_report(&report);
// stop scanning, and connect to the device
state = TC_W4_CONNECT;
gap_stop_scan();
printf("Stop scan. Start connect to device with addr %s.\n", bd_addr_to_str(report.address));
printf("Stop scan. Connect to device with addr %s.\n", bd_addr_to_str(report.address));
gap_connect(report.address,report.address_type);
break;
case HCI_EVENT_LE_META:
// wait for connection complete
@ -240,8 +281,16 @@ static void hci_event_handler(uint8_t packet_type, uint16_t channel, uint8_t *pa
gatt_client_discover_primary_services_by_uuid16(handle_gatt_client_event, connection_handle, battery_service_uuid);
break;
case HCI_EVENT_DISCONNECTION_COMPLETE:
printf("\nDISCONNECTED\n");
exit(0);
if (cmdline_addr_found){
printf("\nDisconnected %s\n", bd_addr_to_str(cmdline_addr));
exit(0);
}
printf("\nDisconnected %s\n", bd_addr_to_str(report.address));
printf("Restart scan.\n");
state = TC_W4_SCAN_RESULT;
gap_start_scan();
break;
default:
break;
@ -249,8 +298,8 @@ static void hci_event_handler(uint8_t packet_type, uint16_t channel, uint8_t *pa
}
static void usage(const char *name){
fprintf(stderr, "\nUsage: %s [-a|--address aa:bb:cc:dd:ee:ff]\n", name);
fprintf(stderr, "If no argument is provided, GATT browser will start scanning and connect to the first found device.\nTo connect to a specific device use argument [-a].\n\n");
fprintf(stderr, "\nUsage: %s [-a|--address aa:bb:cc:dd:ee:ff]\n", name);
fprintf(stderr, "If no argument is provided, GATT browser will start scanning and connect to the first found device.\nTo connect to a specific device use argument [-a].\n\n");
}
int btstack_main(int argc, const char * argv[]);
@ -260,15 +309,16 @@ int btstack_main(int argc, const char * argv[]){
cmdline_addr_found = 0;
while (arg < argc) {
if(!strcmp(argv[arg], "-a") || !strcmp(argv[arg], "--address")){
arg++;
cmdline_addr_found = sscanf_bd_addr(argv[arg], cmdline_addr);
if(!strcmp(argv[arg], "-a") || !strcmp(argv[arg], "--address")){
arg++;
cmdline_addr_found = sscanf_bd_addr(argv[arg], cmdline_addr);
arg++;
if (!cmdline_addr_found) exit(1);
continue;
}
usage(argv[0]);
return 0;
}
}
hci_event_callback_registration.callback = &hci_event_handler;
hci_add_event_handler(&hci_event_callback_registration);

View File

@ -79,7 +79,7 @@ static void heartbeat_handler(struct btstack_timer_source *ts);
static void beat(void);
const uint8_t adv_data[] = {
// Flags general discoverable
// Flags general discoverable, BR/EDR not supported
0x02, 0x01, 0x06,
// Name
0x0b, 0x09, 'L', 'E', ' ', 'C', 'o', 'u', 'n', 't', 'e', 'r',

View File

@ -64,7 +64,7 @@ static void streamer(void);
static btstack_packet_callback_registration_t hci_event_callback_registration;
const uint8_t adv_data[] = {
// Flags general discoverable
// Flags general discoverable, BR/EDR not supported
0x02, 0x01, 0x06,
// Name
0x0c, 0x09, 'L', 'E', ' ', 'S', 't', 'r', 'e', 'a', 'm', 'e', 'r',

View File

@ -73,6 +73,9 @@ static void db_open(void){
[pool release];
}
static void db_set_local_bd_addr(bd_addr_t bd_addr){
}
static void db_synchronize(void){
log_info("stored prefs for %u devices\n", (unsigned int) [remote_devices count]);
@ -160,6 +163,7 @@ static void delete_link_key(bd_addr_t bd_addr){
const btstack_link_key_db_t btstack_link_key_db_cocoa = {
db_open,
db_set_local_bd_addr,
db_close,
get_link_key,
put_link_key,

View File

@ -46,10 +46,14 @@
#include "btstack_util.h"
#define LINK_KEY_PATH "/tmp/"
#define LINK_KEY_PREFIX "btstack_link_key_"
#define LINK_KEY_SUFIX ".txt"
#define LINK_KEY_PREFIX "btstack_at_"
#define LINK_KEY_FOR "_link_key_for_"
#define LINK_KEY_SUFFIX ".txt"
#define LINK_KEY_STRING_LEN 17
static char keypath[sizeof(LINK_KEY_PATH) + sizeof(LINK_KEY_PREFIX) + 17 + sizeof(LINK_KEY_SUFIX) + 1];
static bd_addr_t local_addr;
// note: sizeof for string literals works at compile time while strlen only works with some optimizations turned on. sizeof inlcudes the  \0
static char keypath[sizeof(LINK_KEY_PATH) + sizeof(LINK_KEY_PREFIX) + LINK_KEY_STRING_LEN + sizeof(LINK_KEY_FOR) + LINK_KEY_STRING_LEN + sizeof(LINK_KEY_SUFFIX) + 1];
static char bd_addr_to_dash_str_buffer[6*3]; // 12-45-78-01-34-67\0
static char * bd_addr_to_dash_str(bd_addr_t addr){
@ -64,17 +68,65 @@ static char * bd_addr_to_dash_str(bd_addr_t addr){
return (char *) bd_addr_to_dash_str_buffer;
}
static char link_key_to_str_buffer[LINK_KEY_STR_LEN+1]; // 11223344556677889900112233445566\0
char *link_key_to_str(link_key_t link_key){
char * p = link_key_to_str_buffer;
int i;
for (i = 0; i < LINK_KEY_LEN ; i++) {
*p++ = char_for_nibble((link_key[i] >> 4) & 0x0F);
*p++ = char_for_nibble((link_key[i] >> 0) & 0x0F);
}
*p = 0;
return (char *) link_key_to_str_buffer;
}
static char link_key_type_to_str_buffer[2];
char *link_key_type_to_str(link_key_type_t link_key){
snprintf(link_key_type_to_str_buffer, sizeof(link_key_type_to_str_buffer), "%d", link_key);
return (char *) link_key_type_to_str_buffer;
}
int sscanf_link_key(char * addr_string, link_key_t link_key){
unsigned int buffer[LINK_KEY_LEN];
// reset result buffer
memset(&buffer, 0, sizeof(buffer));
// parse
int result = sscanf( (char *) addr_string, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x",
&buffer[0], &buffer[1], &buffer[2], &buffer[3],
&buffer[4], &buffer[5], &buffer[6], &buffer[7],
&buffer[8], &buffer[9], &buffer[10], &buffer[11],
&buffer[12], &buffer[13], &buffer[14], &buffer[15] );
if (result != LINK_KEY_LEN) return 0;
// store
int i;
uint8_t *p = (uint8_t *) link_key;
for (i=0; i<LINK_KEY_LEN; i++ ) {
*p++ = (uint8_t) buffer[i];
}
return 1;
}
static void set_path(bd_addr_t bd_addr){
strcpy(keypath, LINK_KEY_PATH);
strcat(keypath, LINK_KEY_PREFIX);
strcat(keypath, bd_addr_to_dash_str(local_addr));
strcat(keypath, LINK_KEY_FOR);
strcat(keypath, bd_addr_to_dash_str(bd_addr));
strcat(keypath, LINK_KEY_SUFIX);
strcat(keypath, LINK_KEY_SUFFIX);
}
// Device info
static void db_open(void){
}
static void db_set_local_bd_addr(bd_addr_t bd_addr){
memcpy(local_addr, bd_addr, 6);
}
static void db_close(void){
}
@ -129,55 +181,16 @@ static void delete_link_key(bd_addr_t bd_addr){
}
const btstack_link_key_db_t btstack_link_key_db_fs = {
db_open,
db_close,
get_link_key,
put_link_key,
delete_link_key,
&db_open,
&db_set_local_bd_addr,
&db_close,
&get_link_key,
&put_link_key,
&delete_link_key,
};
const btstack_link_key_db_t * btstack_link_key_db_fs_instance(void){
return &btstack_link_key_db_fs;
}
static char link_key_to_str_buffer[LINK_KEY_STR_LEN+1]; // 11223344556677889900112233445566\0
char *link_key_to_str(link_key_t link_key){
char * p = link_key_to_str_buffer;
int i;
for (i = 0; i < LINK_KEY_LEN ; i++) {
*p++ = char_for_nibble((link_key[i] >> 4) & 0x0F);
*p++ = char_for_nibble((link_key[i] >> 0) & 0x0F);
}
*p = 0;
return (char *) link_key_to_str_buffer;
}
static char link_key_type_to_str_buffer[2];
char *link_key_type_to_str(link_key_type_t link_key){
snprintf(link_key_type_to_str_buffer, sizeof(link_key_type_to_str_buffer), "%d", link_key);
return (char *) link_key_type_to_str_buffer;
}
int sscanf_link_key(char * addr_string, link_key_t link_key){
unsigned int buffer[LINK_KEY_LEN];
// reset result buffer
memset(&buffer, 0, sizeof(buffer));
// parse
int result = sscanf( (char *) addr_string, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x",
&buffer[0], &buffer[1], &buffer[2], &buffer[3],
&buffer[4], &buffer[5], &buffer[6], &buffer[7],
&buffer[8], &buffer[9], &buffer[10], &buffer[11],
&buffer[12], &buffer[13], &buffer[14], &buffer[15] );
if (result != LINK_KEY_LEN) return 0;
// store
int i;
uint8_t *p = (uint8_t *) link_key;
for (i=0; i<LINK_KEY_LEN; i++ ) {
*p++ = (uint8_t) buffer[i];
}
return 1;
}

View File

@ -450,6 +450,7 @@ static void gatt_client_handle_transaction_complete(gatt_client_t * peripheral){
static void emit_event_new(btstack_packet_handler_t callback, uint8_t * packet, uint16_t size){
if (!callback) return;
hci_dump_packet(HCI_EVENT_PACKET, 0, packet, size);
(*callback)(HCI_EVENT_PACKET, 0, packet, size);
}

View File

@ -1,89 +0,0 @@
/*
* Copyright (C) 2014 BlueKitchen GmbH
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* 4. Any redistribution, use, or modification is done solely for
* personal benefit and not for any commercial purpose or for
* monetary gain.
*
* THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
* RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* Please inquire about commercial licensing options at
* contact@bluekitchen-gmbh.com
*
*/
#include "le_device_db.h"
#include "ble/core.h"
// Central Device db interface
void le_device_db_init(void){}
// @returns index if successful, -1 otherwise
int le_device_db_add(int addr_type, bd_addr_t addr, sm_key_t irk){
return -1;
}
// @returns number of device in db
int le_device_db_count(void){
return 0;
}
void le_device_db_encryption_set(int index, uint16_t ediv, uint8_t rand[8], sm_key_t ltk, int key_size, int authenticated, int authorized){}
void le_device_db_encryption_get(int index, uint16_t * ediv, uint8_t rand[8], sm_key_t ltk, int * key_size, int * authenticated, int * authorized){}
// get device information: addr type and address
void le_device_db_info(int index, int * addr_type, bd_addr_t addr, sm_key_t csrk){}
// get signature key
void le_device_db_remote_csrk_get(int index, sm_key_t csrk){}
void le_device_db_remote_csrk_set(int index, sm_key_t csrk){}
// get signature key
void le_device_db_local_csrk_get(int index, sm_key_t csrk){}
void le_device_db_local_csrk_set(int index, sm_key_t csrk){}
// query last used/seen signing counter
uint32_t le_device_db_remote_counter_get(int index){
return 0xffffffff;
}
// update signing counter
void le_device_db_local_counter_set(int index, uint32_t counter){}
// query last used/seen signing counter
uint32_t le_device_db_local_counter_get(int index){
return 0xffffffff;
}
// update signing counter
void le_device_db_remote_counter_set(int index, uint32_t counter){}
// free device
void le_device_db_remove(int index){}

View File

@ -54,7 +54,7 @@
* @brief Compare two Bluetooth addresses
* @param a
* @param b
* @return true if equal
* @return 0 if equal
*/
int bd_addr_cmp(bd_addr_t a, bd_addr_t b){
return memcmp(a,b, BD_ADDR_LEN);
@ -264,7 +264,7 @@ int sscanf_bd_addr(const char * addr_string, bd_addr_t addr){
int single_byte = scan_hex_byte(addr_string);
if (single_byte < 0) break;
addr_string += 2;
addr[i] = single_byte;
buffer[i] = single_byte;
// don't check seperator after last byte
if (i == BD_ADDR_LEN - 1) {
result = 1;

View File

@ -54,6 +54,7 @@ typedef struct {
// management
void (*open)(void);
void (*set_local_bd_addr)(bd_addr_t bd_addr);
void (*close)(void);
// link key

View File

@ -53,6 +53,9 @@ btstack_linked_list_t db_mem_link_keys = NULL;
static void db_open(void){
}
static void db_set_local_bd_addr(bd_addr_t bd_addr){
}
static void db_close(void){
}
@ -123,6 +126,7 @@ static void put_link_key(bd_addr_t bd_addr, link_key_t link_key, link_key_type_t
const btstack_link_key_db_t btstack_link_key_db_memory = {
db_open,
db_set_local_bd_addr,
db_close,
get_link_key,
put_link_key,

View File

@ -2187,6 +2187,7 @@ static uint8_t rfcomm_channel_create_internal(btstack_packet_handler_t packet_ha
// create new multiplexer if necessary
uint8_t status = 0;
uint8_t dlci = 0;
int new_multiplexer = 0;
rfcomm_channel_t * channel = NULL;
rfcomm_multiplexer_t * multiplexer = rfcomm_multiplexer_for_addr(addr);
@ -2201,6 +2202,14 @@ static uint8_t rfcomm_channel_create_internal(btstack_packet_handler_t packet_ha
new_multiplexer = 1;
}
// check if channel for this remote service already exists
dlci = (server_channel << 1) | (multiplexer->outgoing ^ 1);
channel = rfcomm_channel_for_multiplexer_and_dlci(multiplexer, dlci);
if (channel){
status = RFCOMM_CHANNEL_ALREADY_REGISTERED;
goto fail;
}
// prepare channel
channel = rfcomm_channel_create(multiplexer, NULL, server_channel);
if (!channel){

View File

@ -1423,6 +1423,9 @@ static void event_handler(uint8_t *packet, int size){
hci_stack->local_bd_addr);
log_info("Local Address, Status: 0x%02x: Addr: %s",
packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE], bd_addr_to_str(hci_stack->local_bd_addr));
if (hci_stack->link_key_db){
hci_stack->link_key_db->set_local_bd_addr(hci_stack->local_bd_addr);
}
}
if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_write_scan_enable)){
hci_emit_discoverable_enabled(hci_stack->discoverable);