Merge branch 'develop' into le-data-channel

This commit is contained in:
Matthias Ringwald 2016-10-14 15:38:50 +02:00
commit 8e6286ddc5
18 changed files with 93 additions and 64 deletions

View File

@ -107,6 +107,13 @@ static int btstack_uart_embedded_open(void){
}
static int btstack_uart_embedded_close(void){
// remove data source
btstack_run_loop_disable_data_source_callbacks(&transport_data_source, DATA_SOURCE_CALLBACK_POLL);
btstack_run_loop_remove_data_source(&transport_data_source);
// close device
// ...
return 0;
}

View File

@ -210,9 +210,10 @@ static int h4_set_baudrate(uint32_t baudrate){
}
static int h4_close(void){
// first remove run loop handler
btstack_run_loop_remove_data_source(&hci_transport_h4_dma_ds);
// remove data source
btstack_run_loop_disable_data_source_callbacks(&hci_transport_h4_dma_ds, DATA_SOURCE_CALLBACK_POLL);
btstack_run_loop_remove_data_source(&hci_transport_h4_dma_ds);
// stop IRQ
hal_uart_dma_set_csr_irq_handler(NULL);

View File

@ -157,7 +157,9 @@ static int h4_open(void){
}
static int h4_close(void){
// first remove run loop handler
// remove data source
btstack_run_loop_disable_data_source_callbacks(&hci_transport_h4_dma_ds, DATA_SOURCE_CALLBACK_POLL);
btstack_run_loop_remove_data_source(&hci_transport_h4_dma_ds);
// close device

View File

@ -48,6 +48,10 @@
#include "btstack_run_loop.h"
#include "wiced.h"
#if defined __cplusplus
extern "C" {
#endif
/**
* @brief Provide btstack_run_loop_posix instance for use with btstack_run_loop_init
*/

View File

@ -87,11 +87,12 @@ static int att_db_util_assert_space(uint16_t size){
if (att_db_size + size <= att_db_max_size) return 1;
#ifdef HAVE_MALLOC
int new_size = att_db_size + att_db_size / 2;
att_db = (uint8_t*) realloc(att_db, new_size);
if (!att_db) {
uint8_t * new_db = (uint8_t*) realloc(att_db, new_size);
if (!new_db) {
log_error("att_db: realloc failed");
return 0;
}
att_db = new_db;
att_db_max_size = new_size;
return 1;
#else

View File

@ -485,7 +485,7 @@ static void sm_aes128_start(sm_key_t key, sm_key_t plaintext, void * context){
// ah(k,r) helper
// r = padding || r
// r - 24 bit value
static void sm_ah_r_prime(uint8_t r[3], sm_key_t r_prime){
static void sm_ah_r_prime(uint8_t r[3], uint8_t * r_prime){
// r'= padding || r
memset(r_prime, 0, 16);
memcpy(&r_prime[13], r, 3);
@ -494,7 +494,7 @@ static void sm_ah_r_prime(uint8_t r[3], sm_key_t r_prime){
// d1 helper
// d' = padding || r || d
// d,r - 16 bit values
static void sm_d1_d_prime(uint16_t d, uint16_t r, sm_key_t d1_prime){
static void sm_d1_d_prime(uint16_t d, uint16_t r, uint8_t * d1_prime){
// d'= padding || r || d
memset(d1_prime, 0, 16);
big_endian_store_16(d1_prime, 12, r);
@ -504,13 +504,13 @@ static void sm_d1_d_prime(uint16_t d, uint16_t r, sm_key_t d1_prime){
// dm helper
// r = padding || r
// r - 64 bit value
static void sm_dm_r_prime(uint8_t r[8], sm_key_t r_prime){
static void sm_dm_r_prime(uint8_t r[8], uint8_t * r_prime){
memset(r_prime, 0, 16);
memcpy(&r_prime[8], r, 8);
}
// calculate arguments for first AES128 operation in C1 function
static void sm_c1_t1(sm_key_t r, uint8_t preq[7], uint8_t pres[7], uint8_t iat, uint8_t rat, sm_key_t t1){
static void sm_c1_t1(sm_key_t r, uint8_t preq[7], uint8_t pres[7], uint8_t iat, uint8_t rat, uint8_t * t1){
// p1 = pres || preq || rat || iat
// "The octet of iat becomes the least significant octet of p1 and the most signifi-
@ -536,7 +536,7 @@ static void sm_c1_t1(sm_key_t r, uint8_t preq[7], uint8_t pres[7], uint8_t iat,
}
// calculate arguments for second AES128 operation in C1 function
static void sm_c1_t3(sm_key_t t2, bd_addr_t ia, bd_addr_t ra, sm_key_t t3){
static void sm_c1_t3(sm_key_t t2, bd_addr_t ia, bd_addr_t ra, uint8_t * t3){
// p2 = padding || ia || ra
// "The least significant octet of ra becomes the least significant octet of p2 and
// the most significant octet of padding becomes the most significant octet of p2.
@ -557,7 +557,7 @@ static void sm_c1_t3(sm_key_t t2, bd_addr_t ia, bd_addr_t ra, sm_key_t t3){
log_info_key("t3", t3);
}
static void sm_s1_r_prime(sm_key_t r1, sm_key_t r2, sm_key_t r_prime){
static void sm_s1_r_prime(sm_key_t r1, sm_key_t r2, uint8_t * r_prime){
log_info_key("r1", r1);
log_info_key("r2", r2);
memcpy(&r_prime[8], &r2[8], 8);

View File

@ -64,7 +64,7 @@ size_t mbed_memory_allocated_max;
size_t mbed_memory_space_max;
size_t mbed_memory_max;
size_t mbed_memory_smallest_buffer = 0xfffffff;
int mbed_memory_num_allocations;
unsigned int mbed_memory_num_allocations;
#define NUM_SIZES 150
int current_individual_allocation[NUM_SIZES];
@ -94,7 +94,7 @@ static void dump_allocations(void){
mbed_memory_allocated_current, overhead, mbed_memory_allocated_current + overhead,
mbed_memory_allocated_max);
int i;
int total = 0;
unsigned int total = 0;
printf("- current : [ ");
for (i=0;i<sizeof(current_individual_allocation) / sizeof(int);i++){
printf("%02u ", current_individual_allocation[i]);

View File

@ -50,7 +50,6 @@
#include <stdio.h>
#include <string.h>
/**
* @brief Compare two Bluetooth addresses
* @param a
@ -156,6 +155,14 @@ char char_for_nibble(int nibble){
return '?';
}
static inline char char_for_high_nibble(int value){
return char_for_nibble((value >> 4) & 0x0f);
}
static inline char char_for_low_nibble(int value){
return char_for_nibble(value & 0x0f);
}
int nibble_for_char(char c){
if (c >= '0' && c <= '9') return c - '0';
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
@ -175,30 +182,29 @@ void printf_hexdump(const void *data, int size){
void log_info_hexdump(const void *data, int size){
#ifdef ENABLE_LOG_INFO
const int items_per_line = 16;
const int bytes_per_byte = 6; // strlen('0x12, ')
const uint8_t low = 0x0F;
const uint8_t high = 0xF0;
#define ITEMS_PER_LINE 16
// template '0x12, '
#define BYTES_PER_BYTE 6
char buffer[bytes_per_byte*items_per_line+1];
char buffer[BYTES_PER_BYTE*ITEMS_PER_LINE+1];
int i, j;
j = 0;
for (i=0; i<size;i++){
// help static analyzer proof that j stays within bounds
if (j > bytes_per_byte * (items_per_line-1)){
if (j > BYTES_PER_BYTE * (ITEMS_PER_LINE-1)){
j = 0;
}
uint8_t byte = ((uint8_t *)data)[i];
buffer[j++] = '0';
buffer[j++] = 'x';
buffer[j++] = char_for_nibble((byte & high) >> 4);
buffer[j++] = char_for_nibble(byte & low);
buffer[j++] = char_for_high_nibble(byte);
buffer[j++] = char_for_low_nibble(byte);
buffer[j++] = ',';
buffer[j++] = ' ';
if (j >= bytes_per_byte * items_per_line ){
if (j >= BYTES_PER_BYTE * ITEMS_PER_LINE ){
buffer[j] = 0;
log_info("%s", buffer);
j = 0;
@ -214,14 +220,12 @@ void log_info_hexdump(const void *data, int size){
void log_info_key(const char * name, sm_key_t key){
#ifdef ENABLE_LOG_INFO
char buffer[16*2+1];
const uint8_t low = 0x0F;
const uint8_t high = 0xF0;
int i;
int j = 0;
for (i=0; i<16;i++){
uint8_t byte = key[i];
buffer[j++] = char_for_nibble((byte & high) >> 4);
buffer[j++] = char_for_nibble(byte & low);
buffer[j++] = char_for_high_nibble(byte);
buffer[j++] = char_for_low_nibble(byte);
}
buffer[j] = 0;
log_info("%-6s %s", name, buffer);
@ -247,13 +251,12 @@ static char uuid128_to_str_buffer[32+4+1];
char * uuid128_to_str(uint8_t * uuid){
int i;
int j = 0;
const uint8_t low = 0x0F;
const uint8_t high = 0xF0;
// after 4, 6, 8, and 10 bytes = XYXYXYXY-XYXY-XYXY-XYXY-XYXYXYXYXYXY, there's a dash
const int dash_locations = (1<<3) | (1<<5) | (1<<7) | (1<<9);
for (i=0;i<16;i++){
uuid128_to_str_buffer[j++] = char_for_nibble((uuid[i] & high) >> 4);
uuid128_to_str_buffer[j++] = char_for_nibble(uuid[i] & low);
uint8_t byte = uuid[i];
uuid128_to_str_buffer[j++] = char_for_high_nibble(byte);
uuid128_to_str_buffer[j++] = char_for_low_nibble(byte);
if (dash_locations & (1<<i)){
uuid128_to_str_buffer[j++] = '-';
}
@ -269,8 +272,9 @@ char * bd_addr_to_str(bd_addr_t addr){
char * p = bd_addr_to_str_buffer;
int i;
for (i = 0; i < 6 ; i++) {
*p++ = char_for_nibble((addr[i] >> 4) & 0x0F);
*p++ = char_for_nibble((addr[i] >> 0) & 0x0F);
uint8_t byte = addr[i];
*p++ = char_for_high_nibble(byte);
*p++ = char_for_low_nibble(byte);
*p++ = ':';
}
*--p = 0;

View File

@ -46,6 +46,10 @@
#include <stdint.h>
#include "btstack_sbc_plc.h"
#if defined __cplusplus
extern "C" {
#endif
typedef enum{
SBC_MODE_STANDARD,
SBC_MODE_mSBC

View File

@ -184,9 +184,11 @@ int btstack_sbc_decoder_sample_rate(btstack_sbc_decoder_state_t * state){
}
#ifdef OI_DEBUG
void OI_AssertFail(char* file, int line, char* reason){
printf("AssertFail file %s, line %d, reason %s\n", file, line, reason);
}
#endif
void btstack_sbc_decoder_init(btstack_sbc_decoder_state_t * state, btstack_sbc_mode_t mode, void (*callback)(int16_t * data, int num_samples, int num_channels, int sample_rate, void * context), void * context){
if (sbc_decoder_state_singleton && sbc_decoder_state_singleton != state ){

View File

@ -352,7 +352,7 @@ static int hfp_hf_send_chup(uint16_t cid){
return send_str_over_rfcomm(cid, buffer);
}
static int hfp_hf_send_chld(uint16_t cid, int number){
static int hfp_hf_send_chld(uint16_t cid, unsigned int number){
char buffer[20];
sprintf(buffer, "AT%s=%u\r\n", HFP_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES, number);
return send_str_over_rfcomm(cid, buffer);

View File

@ -626,8 +626,8 @@ static int de_traversal_dump_data(uint8_t * element, de_type_t de_type, de_size_
int indent = *(int*) my_context;
int i;
for (i=0; i<indent;i++) printf(" ");
int pos = de_get_header_size(element);
int end_pos = de_get_len(element);
unsigned int pos = de_get_header_size(element);
unsigned int end_pos = de_get_len(element);
printf("type %5s (%u), element len %2u ", type_names[de_type], de_type, end_pos);
if (de_type == DE_DES) {
printf("\n");
@ -636,7 +636,7 @@ static int de_traversal_dump_data(uint8_t * element, de_type_t de_type, de_size_
} else if (de_type == DE_UUID && de_size == DE_SIZE_128) {
printf(", value: %s\n", uuid128_to_str(element+1));
} else if (de_type == DE_STRING) {
int len = 0;
unsigned int len = 0;
switch (de_size){
case DE_SIZE_VAR_8:
len = element[1];

View File

@ -291,8 +291,8 @@ static int nr_hci_connections(void){
static int hci_number_free_acl_slots_for_connection_type(bd_addr_type_t address_type){
int num_packets_sent_classic = 0;
int num_packets_sent_le = 0;
unsigned int num_packets_sent_classic = 0;
unsigned int num_packets_sent_le = 0;
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) hci_stack->connections; it ; it = it->next){
@ -355,7 +355,7 @@ int hci_number_free_acl_slots_for_handle(hci_con_handle_t con_handle){
}
static int hci_number_free_sco_slots(void){
int num_sco_packets_sent = 0;
unsigned int num_sco_packets_sent = 0;
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;
@ -498,7 +498,7 @@ static int hci_send_acl_packet_fragments(hci_connection_t *connection){
// count packet
connection->num_acl_packets_sent++;
log_debug("hci_send_acl_packet_fragments loop before send (more fragments %u)", more_fragments);
log_debug("hci_send_acl_packet_fragments loop before send (more fragments %d)", more_fragments);
// update state for next fragment (if any) as "transport done" might be sent during send_packet already
if (more_fragments){
@ -516,7 +516,7 @@ static int hci_send_acl_packet_fragments(hci_connection_t *connection){
hci_dump_packet(HCI_ACL_DATA_PACKET, 0, packet, size);
err = hci_stack->hci_transport->send_packet(HCI_ACL_DATA_PACKET, packet, size);
log_debug("hci_send_acl_packet_fragments loop after send (more fragments %u)", more_fragments);
log_debug("hci_send_acl_packet_fragments loop after send (more fragments %d)", more_fragments);
// done yet?
if (!more_fragments) break;
@ -639,7 +639,7 @@ static void acl_handler(uint8_t *packet, int size){
// assert packet is complete
if (acl_length + 4 != size){
log_error("hci.c: acl_handler called with ACL packet of wrong size %u, expected %u => dropping packet", size, acl_length + 4);
log_error("hci.c: acl_handler called with ACL packet of wrong size %d, expected %u => dropping packet", size, acl_length + 4);
return;
}
@ -769,7 +769,7 @@ static uint16_t hci_acl_packet_types_for_buffer_size_and_local_features(uint16_t
}
// disable packet types due to missing local supported features
for (i=0;i<sizeof(packet_type_feature_requirement_bit);i++){
int bit_idx = packet_type_feature_requirement_bit[i];
unsigned int bit_idx = packet_type_feature_requirement_bit[i];
int feature_set = (local_supported_features[bit_idx >> 3] & (1<<(bit_idx & 7))) != 0;
if (feature_set) continue;
log_info("Features bit %02u is not set, removing packet types 0x%04x", bit_idx, packet_type_feature_packet_mask[i]);
@ -1251,7 +1251,7 @@ static void hci_initializing_event_handler(uint8_t * packet, uint16_t size){
btstack_run_loop_remove_timer(&hci_stack->timeout);
break;
case HCI_INIT_W4_SEND_READ_LOCAL_VERSION_INFORMATION:
log_info("Received local version info, need baud change %u", need_baud_change);
log_info("Received local version info, need baud change %d", need_baud_change);
if (need_baud_change){
hci_stack->substate = HCI_INIT_SEND_BAUD_CHANGE;
return;
@ -1397,7 +1397,7 @@ static void event_handler(uint8_t *packet, int size){
// assert packet is complete
if (size != event_length + 2){
log_error("hci.c: event_handler called with event packet of wrong size %u, expected %u => dropping packet", size, event_length + 2);
log_error("hci.c: event_handler called with event packet of wrong size %d, expected %u => dropping packet", size, event_length + 2);
return;
}
@ -2218,7 +2218,7 @@ static void hci_power_transition_to_initializing(void){
int hci_power_control(HCI_POWER_MODE power_mode){
log_info("hci_power_control: %u, current mode %u", power_mode, hci_stack->state);
log_info("hci_power_control: %d, current mode %u", power_mode, hci_stack->state);
int err = 0;
switch (hci_stack->state){
@ -2228,7 +2228,7 @@ int hci_power_control(HCI_POWER_MODE power_mode){
case HCI_POWER_ON:
err = hci_power_control_on();
if (err) {
log_error("hci_power_control_on() error %u", err);
log_error("hci_power_control_on() error %d", err);
return err;
}
hci_power_transition_to_initializing();
@ -3273,7 +3273,7 @@ int gap_dedicated_bonding(bd_addr_t device, int mitm_protection_required){
// configure LEVEL_2/3, dedicated bonding
connection->state = SEND_CREATE_CONNECTION;
connection->requested_security_level = mitm_protection_required ? LEVEL_3 : LEVEL_2;
log_info("gap_dedicated_bonding, mitm %u -> level %u", mitm_protection_required, connection->requested_security_level);
log_info("gap_dedicated_bonding, mitm %d -> level %u", mitm_protection_required, connection->requested_security_level);
connection->bonding_flags = BONDING_DEDICATED;
// wait for GAP Security Result and send GAP Dedicated Bonding complete

View File

@ -155,11 +155,11 @@ static void printf_timestamp(void){
uint32_t time_ms = btstack_run_loop_get_time_ms();
int seconds = time_ms / 1000;
int minutes = seconds / 60;
int hours = minutes / 60;
unsigned int hours = minutes / 60;
int p_ms = time_ms - (seconds * 1000);
int p_seconds = seconds - (minutes * 60);
int p_minutes = minutes - (hours * 60);
uint16_t p_ms = time_ms - (seconds * 1000);
uint16_t p_seconds = seconds - (minutes * 60);
uint16_t p_minutes = minutes - (hours * 60);
printf("[%02u:%02u:%02u.%03u] ", hours, p_minutes, p_seconds, p_ms);
}
#endif

View File

@ -197,7 +197,7 @@ static void hci_transport_h4_block_read(void){
bytes_to_read = little_endian_read_16( hci_packet, 3);
// check ACL length
if (HCI_ACL_HEADER_SIZE + bytes_to_read > HCI_PACKET_BUFFER_SIZE){
log_error("hci_transport_h4: invalid ACL payload len %u - only space for %u", bytes_to_read, HCI_PACKET_BUFFER_SIZE - HCI_ACL_HEADER_SIZE);
log_error("hci_transport_h4: invalid ACL payload len %d - only space for %u", bytes_to_read, HCI_PACKET_BUFFER_SIZE - HCI_ACL_HEADER_SIZE);
hci_transport_h4_reset_statemachine();
break;
}

View File

@ -145,7 +145,7 @@ static void hci_transport_slip_init(void);
// -----------------------------
static void hci_transport_inactivity_timeout_handler(btstack_timer_source_t * ts){
log_info("h5: inactivity timeout. link state %u, peer asleep %u, actions 0x%02x, outgoing packet %u",
log_info("h5: inactivity timeout. link state %d, peer asleep %u, actions 0x%02x, outgoing packet %u",
link_state, link_peer_asleep, hci_transport_link_actions, hci_transport_link_have_outgoing_packet());
if (hci_transport_link_have_outgoing_packet()) return;
if (link_state != LINK_ACTIVE) return;
@ -176,7 +176,7 @@ static void hci_transport_slip_encode_chunk_and_send(int pos){
slip_outgoing_buffer[pos++] = BTSTACK_SLIP_SOF;
}
slip_write_active = 1;
log_info("hci_transport_slip: send %u bytes", pos);
log_info("hci_transport_slip: send %d bytes", pos);
btstack_uart->send_block(slip_outgoing_buffer, pos);
}
@ -424,10 +424,10 @@ static void hci_transport_h5_process_frame(uint16_t frame_size){
uint8_t * slip_payload = &hci_packet_with_pre_buffer[HCI_INCOMING_PRE_BUFFER_SIZE + 4];
int frame_size_without_header = frame_size - 4;
int seq_nr = slip_header[0] & 0x07;
int ack_nr = (slip_header[0] >> 3) & 0x07;
int data_integrity_check_present = (slip_header[0] & 0x40) != 0;
int reliable_packet = (slip_header[0] & 0x80) != 0;
uint8_t seq_nr = slip_header[0] & 0x07;
uint8_t ack_nr = (slip_header[0] >> 3) & 0x07;
uint8_t data_integrity_check_present = (slip_header[0] & 0x40) != 0;
uint8_t reliable_packet = (slip_header[0] & 0x80) != 0;
uint8_t link_packet_type = slip_header[1] & 0x0f;
uint16_t link_payload_len = (slip_header[1] >> 4) | (slip_header[2] << 4);
@ -716,7 +716,7 @@ static int hci_transport_h5_can_send_packet_now(uint8_t packet_type){
static int hci_transport_h5_send_packet(uint8_t packet_type, uint8_t *packet, int size){
if (!hci_transport_h5_can_send_packet_now(packet_type)){
log_error("hci_transport_h5_send_packet called but in state %u", link_state);
log_error("hci_transport_h5_send_packet called but in state %d", link_state);
return -1;
}

View File

@ -105,7 +105,9 @@ int attribute_value_buffer_size = 1000;
void assertBuffer(int size){
if (size > attribute_value_buffer_size){
attribute_value_buffer_size *= 2;
attribute_value = (uint8_t *) realloc(attribute_value, attribute_value_buffer_size);
uint8_t * new_attribute = (uint8_t *) realloc(attribute_value, attribute_value_buffer_size);
if (!new_attribute) return;
attribute_value = new_attribute;
}
}

View File

@ -49,7 +49,9 @@ int attribute_value_buffer_size = 1000;
void assertBuffer(int size){
if (size > attribute_value_buffer_size){
attribute_value_buffer_size *= 2;
attribute_value = (uint8_t *) realloc(attribute_value, attribute_value_buffer_size);
uint8_t * new_attribute = (uint8_t *) realloc(attribute_value, attribute_value_buffer_size);
if (!new_attribute) return;
attribute_value = new_attribute;
}
}