diff --git a/chipset/cc256x/btstack_chipset_cc256x.c b/chipset/cc256x/btstack_chipset_cc256x.c index 63289ec2f..ffb7ba23b 100644 --- a/chipset/cc256x/btstack_chipset_cc256x.c +++ b/chipset/cc256x/btstack_chipset_cc256x.c @@ -112,10 +112,12 @@ static void chipset_set_baudrate_command(uint32_t baudrate, uint8_t *hci_cmd_buf hci_cmd_buffer[6] = 0; } -#if 0 static void chipset_set_bd_addr_command(bd_addr_t addr, uint8_t *hci_cmd_buffer){ + hci_cmd_buffer[0] = 0x06; + hci_cmd_buffer[1] = 0xFC; + hci_cmd_buffer[2] = 0x06; + reverse_bd_addr(addr, &hci_cmd_buffer[3]); } -#endif // Output Power control from: http://e2e.ti.com/support/low_power_rf/f/660/p/134853/484767.aspx #define NUM_POWER_LEVELS 16 @@ -284,7 +286,7 @@ static const btstack_chipset_t btstack_chipset_cc256x = { chipset_init, chipset_next_command, chipset_set_baudrate_command, - NULL, // set bd addr command not available or impemented + chipset_set_bd_addr_command, }; const btstack_chipset_t * btstack_chipset_cc256x_instance(void){ diff --git a/platform/daemon/src/daemon.c b/platform/daemon/src/daemon.c index 7adf89489..5d256d40b 100644 --- a/platform/daemon/src/daemon.c +++ b/platform/daemon/src/daemon.c @@ -1012,7 +1012,7 @@ static int btstack_command_handler(connection_t *connection, uint8_t *packet, ui case L2CAP_DECLINE_CONNECTION: cid = little_endian_read_16(packet, 3); reason = packet[7]; - l2cap_decline_connection(cid, reason); + l2cap_decline_connection(cid); break; case RFCOMM_CREATE_CHANNEL: reverse_bd_addr(&packet[3], addr); diff --git a/platform/daemon/src/daemon_cmds.c b/platform/daemon/src/daemon_cmds.c index 24f2b9f86..72274e58f 100644 --- a/platform/daemon/src/daemon_cmds.c +++ b/platform/daemon/src/daemon_cmds.c @@ -145,7 +145,7 @@ OPCODE(OGF_BTSTACK, L2CAP_ACCEPT_CONNECTION), "2" /** * @param source_cid (16) - * @param reason + * @param reason (deprecated) */ const hci_cmd_t l2cap_decline_connection_cmd = { OPCODE(OGF_BTSTACK, L2CAP_DECLINE_CONNECTION), "21" diff --git a/port/arduino/BTstack.cpp b/port/arduino/BTstack.cpp index c0accdb9f..60db7059e 100644 --- a/port/arduino/BTstack.cpp +++ b/port/arduino/BTstack.cpp @@ -721,8 +721,8 @@ void BTstackManager::setPublicBdAddr(bd_addr_t addr){ memcpy(public_bd_addr, addr ,6); } -void bluetooth_hardware_error(){ - printf("Bluetooth Hardware Error event. Restarting...\n\n\n"); +void bluetooth_hardware_error(uint8_t error){ + printf("Bluetooth Hardware Error event 0x%02x. Restarting...\n\n\n", error); #ifdef __AVR__ wdt_enable(WDTO_15MS); // wait for watchdog to trigger diff --git a/port/ez430-rf2560/btstack_config.h b/port/ez430-rf2560/btstack_config.h index 7db358a8d..a45fca371 100644 --- a/port/ez430-rf2560/btstack_config.h +++ b/port/ez430-rf2560/btstack_config.h @@ -6,7 +6,6 @@ #define __BTSTACK_CONFIG // Port related features -#define HAVE_INIT_SCRIPT #define HAVE_EMBEDDED_TICK // BTstack features that can be enabled diff --git a/port/libusb/main.c b/port/libusb/main.c index a6822f733..a97c972c6 100644 --- a/port/libusb/main.c +++ b/port/libusb/main.c @@ -108,7 +108,7 @@ int main(int argc, const char * argv[]){ usb_path_len++; printf("%02x ", port); if (!delimiter) break; - if (*delimiter != ':') break; + if (*delimiter != ':' && *delimiter != '-') break; port_str = delimiter+1; } printf("\n"); diff --git a/port/msp-exp430f5438-cc2564b/btstack_config.h b/port/msp-exp430f5438-cc2564b/btstack_config.h index 1bd975fd7..c7383fe10 100644 --- a/port/msp-exp430f5438-cc2564b/btstack_config.h +++ b/port/msp-exp430f5438-cc2564b/btstack_config.h @@ -6,7 +6,6 @@ #define __BTSTACK_CONFIG // Port related features -#define HAVE_INIT_SCRIPT #define HAVE_EMBEDDED_TICK // BTstack features that can be enabled diff --git a/port/msp430f5229lp-cc2564b/btstack_config.h b/port/msp430f5229lp-cc2564b/btstack_config.h index 96ca2563a..f8bd5b38d 100644 --- a/port/msp430f5229lp-cc2564b/btstack_config.h +++ b/port/msp430f5229lp-cc2564b/btstack_config.h @@ -6,7 +6,6 @@ #define __BTSTACK_CONFIG // Port related features -#define HAVE_INIT_SCRIPT #define HAVE_EMBEDDED_TICK // BTstack features that can be enabled diff --git a/port/stm32-f103rb-nucleo/btstack_config.h b/port/stm32-f103rb-nucleo/btstack_config.h index a3fb65477..42861f2cf 100644 --- a/port/stm32-f103rb-nucleo/btstack_config.h +++ b/port/stm32-f103rb-nucleo/btstack_config.h @@ -6,7 +6,6 @@ #define __BTSTACK_CONFIG // Port related features -#define HAVE_INIT_SCRIPT #define HAVE_EMBEDDED_TICK // BTstack features that can be enabled diff --git a/src/ble/sm.c b/src/ble/sm.c index 96854771b..1e75dffeb 100644 --- a/src/ble/sm.c +++ b/src/ble/sm.c @@ -1961,7 +1961,18 @@ static void sm_run(void){ sm_connection->sm_engine_state = SM_INITIATOR_PH0_SEND_START_ENCRYPTION; break; case SM_RESPONDER_PH0_RECEIVED_LTK_REQUEST: + sm_reset_setup(); + sm_start_calculating_ltk_from_ediv_and_rand(sm_connection); + break; + case SM_INITIATOR_PH1_W2_SEND_PAIRING_REQUEST: + sm_reset_setup(); + sm_init_setup(sm_connection); + sm_timeout_start(sm_connection); + sm_connection->sm_engine_state = SM_INITIATOR_PH1_SEND_PAIRING_REQUEST; + break; + #ifdef ENABLE_LE_SECURE_CONNECTIONS + case SM_SC_RECEIVED_LTK_REQUEST: switch (sm_connection->sm_irk_lookup_state){ case IRK_LOOKUP_SUCCEEDED: // assuming Secure Connection, we have a stored LTK and the EDIV/RAND are null @@ -1989,14 +2000,8 @@ static void sm_run(void){ done = 0; break; } + break; #endif - break; - case SM_INITIATOR_PH1_W2_SEND_PAIRING_REQUEST: - sm_reset_setup(); - sm_init_setup(sm_connection); - sm_timeout_start(sm_connection); - sm_connection->sm_engine_state = SM_INITIATOR_PH1_SEND_PAIRING_REQUEST; - break; default: done = 0; break; @@ -2920,17 +2925,17 @@ static void sm_event_packet_handler (uint8_t packet_type, uint16_t channel, uint // store rand and ediv reverse_64(&packet[5], sm_conn->sm_local_rand); - sm_conn->sm_local_ediv = little_endian_read_16(packet, 13); + sm_conn->sm_local_ediv = little_endian_read_16(packet, 13); // For Legacy Pairing (<=> EDIV != 0 || RAND != NULL), we need to recalculated our LTK as a // potentially stored LTK is from the master if (sm_conn->sm_local_ediv != 0 || !sm_is_null_random(sm_conn->sm_local_rand)){ - sm_start_calculating_ltk_from_ediv_and_rand(sm_conn); + sm_conn->sm_engine_state = SM_RESPONDER_PH0_RECEIVED_LTK_REQUEST; break; } #ifdef ENABLE_LE_SECURE_CONNECTIONS - sm_conn->sm_engine_state = SM_RESPONDER_PH0_RECEIVED_LTK_REQUEST; + sm_conn->sm_engine_state = SM_SC_RECEIVED_LTK_REQUEST; #else log_info("LTK Request: ediv & random are empty, but LE Secure Connections not supported"); sm_conn->sm_engine_state = SM_RESPONDER_PH0_SEND_LTK_REQUESTED_NEGATIVE_REPLY; diff --git a/src/btstack_defines.h b/src/btstack_defines.h index 568183956..846053b41 100644 --- a/src/btstack_defines.h +++ b/src/btstack_defines.h @@ -118,7 +118,7 @@ typedef uint8_t sm_key_t[16]; #define L2CAP_SERVICE_ALREADY_REGISTERED 0x69 #define L2CAP_DATA_LEN_EXCEEDS_REMOTE_MTU 0x6A -#define L2CAP_SERVICE_NOT_FOUND 0x6B +#define L2CAP_SERVICE_DOES_NOT_EXIST 0x6B #define L2CAP_LOCAL_CID_INVALID 0x6C #define RFCOMM_MULTIPLEXER_STOPPED 0x70 diff --git a/src/btstack_slip.c b/src/btstack_slip.c index d82a0d61f..3a9e4e847 100644 --- a/src/btstack_slip.c +++ b/src/btstack_slip.c @@ -120,6 +120,9 @@ uint8_t btstack_slip_encoder_get_byte(void){ case SLIP_ENCODER_SEND_DD: encoder_state = SLIP_ENCODER_DEFAULT; return 0x0dd; + default: + log_error("btstack_slip_encoder_get_byte invalid state %x", encoder_state); + return 0x00; } } diff --git a/src/classic/bnep.c b/src/classic/bnep.c index 3670114d2..8ba02ffd4 100644 --- a/src/classic/bnep.c +++ b/src/classic/bnep.c @@ -1193,7 +1193,7 @@ static int bnep_hci_event_handler(uint8_t *packet, uint16_t size) if (channel) { log_error("INCOMING_CONNECTION (l2cap_cid 0x%02x) for PSM_BNEP => decline - channel already exists", l2cap_cid); - l2cap_decline_connection(l2cap_cid, 0x04); // no resources available + l2cap_decline_connection(l2cap_cid); return 1; } @@ -1202,7 +1202,7 @@ static int bnep_hci_event_handler(uint8_t *packet, uint16_t size) if (!channel) { log_error("INCOMING_CONNECTION (l2cap_cid 0x%02x) for PSM_BNEP => decline - no memory left", l2cap_cid); - l2cap_decline_connection(l2cap_cid, 0x04); // no resources available + l2cap_decline_connection(l2cap_cid); return 1; } diff --git a/src/classic/rfcomm.c b/src/classic/rfcomm.c index 6f73e9759..59b9a2746 100644 --- a/src/classic/rfcomm.c +++ b/src/classic/rfcomm.c @@ -932,7 +932,7 @@ static int rfcomm_hci_event_handler(uint8_t *packet, uint16_t size){ if (multiplexer) { log_info("INCOMING_CONNECTION (l2cap_cid 0x%02x) for PSM_RFCOMM => decline - multiplexer already exists", l2cap_cid); - l2cap_decline_connection(l2cap_cid, 0x04); // no resources available + l2cap_decline_connection(l2cap_cid); return 1; } @@ -940,7 +940,7 @@ static int rfcomm_hci_event_handler(uint8_t *packet, uint16_t size){ multiplexer = rfcomm_multiplexer_create_for_addr(event_addr); if (!multiplexer){ log_info("INCOMING_CONNECTION (l2cap_cid 0x%02x) for PSM_RFCOMM => decline - no memory left", l2cap_cid); - l2cap_decline_connection(l2cap_cid, 0x04); // no resources available + l2cap_decline_connection(l2cap_cid); return 1; } diff --git a/src/classic/sdp_server.c b/src/classic/sdp_server.c index aaaea2299..dc6e9989d 100644 --- a/src/classic/sdp_server.c +++ b/src/classic/sdp_server.c @@ -495,7 +495,7 @@ static void sdp_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *p case L2CAP_EVENT_INCOMING_CONNECTION: if (l2cap_cid) { // CONNECTION REJECTED DUE TO LIMITED RESOURCES - l2cap_decline_connection(channel, 0x04); + l2cap_decline_connection(channel); break; } // accept diff --git a/src/hci.c b/src/hci.c index bae1a7f04..45f9e7e7f 100644 --- a/src/hci.c +++ b/src/hci.c @@ -1727,8 +1727,9 @@ static void event_handler(uint8_t *packet, int size){ break; case HCI_EVENT_HARDWARE_ERROR: + log_error("Hardware Error: 0x%02x", packet[2]); if (hci_stack->hardware_error_callback){ - (*hci_stack->hardware_error_callback)(); + (*hci_stack->hardware_error_callback)(packet[2]); } else { // if no special requests, just reboot stack hci_power_control_off(); @@ -1975,6 +1976,9 @@ void hci_init(const hci_transport_t *transport, const void *config){ // reference to used config hci_stack->config = config; + // setup pointer for outgoing packet buffer + hci_stack->hci_packet_buffer = &hci_stack->hci_packet_buffer_data[HCI_OUTGOING_PRE_BUFFER_SIZE]; + // max acl payload size defined in config.h hci_stack->acl_data_packet_length = HCI_ACL_PAYLOAD_SIZE; @@ -3613,7 +3617,7 @@ int hci_get_sco_packet_length(void){ /** * @brief Set callback for Bluetooth Hardware Error */ -void hci_set_hardware_error_callback(void (*fn)(void)){ +void hci_set_hardware_error_callback(void (*fn)(uint8_t error)){ hci_stack->hardware_error_callback = fn; } diff --git a/src/hci.h b/src/hci.h index 29ae28532..2bcd4634d 100644 --- a/src/hci.h +++ b/src/hci.h @@ -303,6 +303,7 @@ typedef enum { SM_INITIATOR_PH3_SEND_START_ENCRYPTION, // LE Secure Connections + SM_SC_RECEIVED_LTK_REQUEST, SM_SC_SEND_PUBLIC_KEY_COMMAND, SM_SC_W4_PUBLIC_KEY_COMMAND, SM_SC_W2_GET_RANDOM_A, @@ -569,7 +570,7 @@ typedef struct { void (*local_version_information_callback)(uint8_t * local_version_information); // hardware error callback - void (*hardware_error_callback)(void); + void (*hardware_error_callback)(uint8_t error); // basic configuration const char * local_name; @@ -581,8 +582,8 @@ typedef struct { uint8_t ssp_auto_accept; // single buffer for HCI packet assembly + additional prebuffer for H4 drivers - uint8_t hci_packet_buffer_prefix[HCI_OUTGOING_PRE_BUFFER_SIZE]; - uint8_t hci_packet_buffer[HCI_PACKET_BUFFER_SIZE]; // opcode (16), len(8) + uint8_t * hci_packet_buffer; + uint8_t hci_packet_buffer_data[HCI_OUTGOING_PRE_BUFFER_SIZE + HCI_PACKET_BUFFER_SIZE]; uint8_t hci_packet_buffer_reserved; uint16_t acl_fragmentation_pos; uint16_t acl_fragmentation_total_size; @@ -712,7 +713,7 @@ void hci_set_link_key_db(btstack_link_key_db_t const * link_key_db); /** * @brief Set callback for Bluetooth Hardware Error */ -void hci_set_hardware_error_callback(void (*fn)(void)); +void hci_set_hardware_error_callback(void (*fn)(uint8_t error)); /** * @brief Set callback for local information from Bluetooth controller right after HCI Reset diff --git a/src/hci_transport_h4.c b/src/hci_transport_h4.c index ca1d5d220..ecdfc2021 100644 --- a/src/hci_transport_h4.c +++ b/src/hci_transport_h4.c @@ -50,16 +50,17 @@ #include "hci_transport.h" #include "btstack_uart_block.h" +#define ENABLE_LOG_EHCILL + #ifdef ENABLE_EHCILL // eHCILL commands -#define EHCILL_GO_TO_SLEEP_IND 0x030 -#define EHCILL_GO_TO_SLEEP_ACK 0x031 -#define EHCILL_WAKE_UP_IND 0x032 -#define EHCILL_WAKE_UP_ACK 0x033 +static const uint8_t EHCILL_GO_TO_SLEEP_IND = 0x030; +static const uint8_t EHCILL_GO_TO_SLEEP_ACK = 0x031; +static const uint8_t EHCILL_WAKE_UP_IND = 0x032; +static const uint8_t EHCILL_WAKE_UP_ACK = 0x033; static int hci_transport_h4_ehcill_outgoing_packet_ready(void); -static int hci_transport_h4_ehcill_sleep_mode_active(void); static void hci_transport_h4_echill_send_wakeup_ind(void); static void hci_transport_h4_ehcill_handle_command(uint8_t action); static void hci_transport_h4_ehcill_handle_ehcill_command_sent(void); @@ -71,8 +72,9 @@ static void hci_transport_h4_ehcill_sleep_ack_timer_setup(void); static void hci_transport_h4_ehcill_trigger_wakeup(void); typedef enum { + EHCILL_STATE_W2_SEND_SLEEP_ACK, EHCILL_STATE_SLEEP, - EHCILL_STATE_W4_ACK, + EHCILL_STATE_W4_WAKEUP_IND_OR_ACK, EHCILL_STATE_AWAKE } EHCILL_STATE; @@ -258,9 +260,14 @@ static int hci_transport_h4_send_packet(uint8_t packet_type, uint8_t * packet, i tx_data = packet; #ifdef ENABLE_EHCILL - if (hci_transport_h4_ehcill_sleep_mode_active()){ - hci_transport_h4_ehcill_trigger_wakeup(); - return 0; + switch (ehcill_state){ + case EHCILL_STATE_SLEEP: + hci_transport_h4_ehcill_trigger_wakeup(); + return 0; + case EHCILL_STATE_W2_SEND_SLEEP_ACK: + return 0; + default: + break; } #endif @@ -347,9 +354,12 @@ static void hci_transport_h4_ehcill_open(void){ } static void hci_transport_h4_echill_send_wakeup_ind(void){ +#ifdef ENABLE_LOG_EHCILL + log_info("eHCILL: send WAKEUP_IND"); +#endif // update state tx_state = TX_W4_WAKEUP; - ehcill_state = EHCILL_STATE_W4_ACK; + ehcill_state = EHCILL_STATE_W4_WAKEUP_IND_OR_ACK; ehcill_command_to_send = EHCILL_WAKE_UP_IND; btstack_uart->send_block(&ehcill_command_to_send, 1); } @@ -358,28 +368,33 @@ static int hci_transport_h4_ehcill_outgoing_packet_ready(void){ return tx_len != 0; } -static int hci_transport_h4_ehcill_sleep_mode_active(void){ - return ehcill_state == EHCILL_STATE_SLEEP; -} - static void hci_transport_h4_ehcill_reset_statemachine(void){ ehcill_state = EHCILL_STATE_AWAKE; } static void hci_transport_h4_ehcill_send_ehcill_command(void){ - log_debug("eHCILL: send command %02x", ehcill_command_to_send); +#ifdef ENABLE_LOG_EHCILL + log_info("eHCILL: send command %02x", ehcill_command_to_send); +#endif tx_state = TX_W4_EHCILL_SENT; + if (ehcill_command_to_send == EHCILL_GO_TO_SLEEP_ACK){ + ehcill_state = EHCILL_STATE_SLEEP; + } btstack_uart->send_block(&ehcill_command_to_send, 1); } static void hci_transport_h4_ehcill_sleep_ack_timer_handler(btstack_timer_source_t * timer){ - log_debug("eHCILL: timer triggered"); +#ifdef ENABLE_LOG_EHCILL + log_info("eHCILL: timer triggered"); +#endif hci_transport_h4_ehcill_send_ehcill_command(); } static void hci_transport_h4_ehcill_sleep_ack_timer_setup(void){ // setup timer - log_debug("eHCILL: set timer for sending command"); +#ifdef ENABLE_LOG_EHCILL + log_info("eHCILL: set timer for sending command %02x", ehcill_command_to_send); +#endif btstack_run_loop_set_timer_handler(&ehcill_sleep_ack_timer, &hci_transport_h4_ehcill_sleep_ack_timer_handler); btstack_run_loop_set_timer(&ehcill_sleep_ack_timer, 50); btstack_run_loop_add_timer(&ehcill_sleep_ack_timer); @@ -403,7 +418,10 @@ static void hci_transport_h4_ehcill_trigger_wakeup(void){ hci_transport_h4_echill_send_wakeup_ind(); } -static void hci_transport_h4_ehcill_schedule_ecill_command(uint8_t command){ +static void hci_transport_h4_ehcill_schedule_ehcill_command(uint8_t command){ +#ifdef ENABLE_LOG_EHCILL + log_info("eHCILL: schedule eHCILL command %02x", command); +#endif ehcill_command_to_send = command; switch (tx_state){ case TX_IDLE: @@ -427,9 +445,11 @@ static void hci_transport_h4_ehcill_handle_command(uint8_t action){ case EHCILL_STATE_AWAKE: switch(action){ case EHCILL_GO_TO_SLEEP_IND: - ehcill_state = EHCILL_STATE_SLEEP; - log_info("eHCILL: GO_TO_SLEEP_IND RX"); - hci_transport_h4_ehcill_schedule_ecill_command(EHCILL_GO_TO_SLEEP_ACK); + ehcill_state = EHCILL_STATE_W2_SEND_SLEEP_ACK; +#ifdef ENABLE_LOG_EHCILL + log_info("eHCILL: Received GO_TO_SLEEP_IND RX"); +#endif + hci_transport_h4_ehcill_schedule_ehcill_command(EHCILL_GO_TO_SLEEP_ACK); break; default: break; @@ -437,11 +457,14 @@ static void hci_transport_h4_ehcill_handle_command(uint8_t action){ break; case EHCILL_STATE_SLEEP: + case EHCILL_STATE_W2_SEND_SLEEP_ACK: switch(action){ case EHCILL_WAKE_UP_IND: ehcill_state = EHCILL_STATE_AWAKE; - log_info("eHCILL: WAKE_UP_IND RX"); - hci_transport_h4_ehcill_schedule_ecill_command(EHCILL_WAKE_UP_ACK); +#ifdef ENABLE_LOG_EHCILL + log_info("eHCILL: Received WAKE_UP_IND RX"); +#endif + hci_transport_h4_ehcill_schedule_ehcill_command(EHCILL_WAKE_UP_ACK); break; default: @@ -449,11 +472,13 @@ static void hci_transport_h4_ehcill_handle_command(uint8_t action){ } break; - case EHCILL_STATE_W4_ACK: + case EHCILL_STATE_W4_WAKEUP_IND_OR_ACK: switch(action){ case EHCILL_WAKE_UP_IND: case EHCILL_WAKE_UP_ACK: - log_info("eHCILL: WAKE_UP_IND or ACK"); +#ifdef ENABLE_LOG_EHCILL + log_info("eHCILL: Received WAKE_UP (%02x)", action); +#endif tx_state = TX_W4_PACKET_SENT; ehcill_state = EHCILL_STATE_AWAKE; btstack_uart->send_block(tx_data, tx_len); @@ -466,6 +491,9 @@ static void hci_transport_h4_ehcill_handle_command(uint8_t action){ } static void hci_transport_h4_ehcill_handle_packet_sent(void){ +#ifdef ENABLE_LOG_EHCILL + log_info("eHCILL: handle packet sent, command to send %02x", ehcill_command_to_send); +#endif // now, send pending ehcill command if neccessary switch (ehcill_command_to_send){ case EHCILL_GO_TO_SLEEP_ACK: @@ -483,8 +511,15 @@ static void hci_transport_h4_ehcill_handle_ehcill_command_sent(void){ tx_state = TX_IDLE; int command = ehcill_command_to_send; ehcill_command_to_send = 0; + +#ifdef ENABLE_LOG_EHCILL + log_info("eHCILL: handle eHCILL sent, command was %02x", command); +#endif + if (command == EHCILL_GO_TO_SLEEP_ACK) { +#ifdef ENABLE_LOG_EHCILL log_info("eHCILL: GO_TO_SLEEP_ACK sent, enter sleep mode"); +#endif // UART not needed after EHCILL_GO_TO_SLEEP_ACK was sent if (btstack_uart_sleep_mode != BTSTACK_UART_SLEEP_OFF){ btstack_uart->set_sleep(btstack_uart_sleep_mode); @@ -495,7 +530,9 @@ static void hci_transport_h4_ehcill_handle_ehcill_command_sent(void){ if (btstack_uart_sleep_mode){ btstack_uart->set_sleep(BTSTACK_UART_SLEEP_OFF); } - hci_transport_h4_echill_send_wakeup_ind(); + if (command != EHCILL_WAKE_UP_IND){ + hci_transport_h4_echill_send_wakeup_ind(); + } } } diff --git a/src/l2cap.c b/src/l2cap.c index a209bb678..5bf7f4c3e 100644 --- a/src/l2cap.c +++ b/src/l2cap.c @@ -1168,15 +1168,15 @@ void l2cap_accept_connection(uint16_t local_cid){ l2cap_run(); } -void l2cap_decline_connection(uint16_t local_cid, uint8_t reason){ - log_info("L2CAP_DECLINE_CONNECTION local_cid 0x%x, reason %x", local_cid, reason); +void l2cap_decline_connection(uint16_t local_cid){ + log_info("L2CAP_DECLINE_CONNECTION local_cid 0x%x", local_cid); l2cap_channel_t * channel = l2cap_get_channel_for_local_cid( local_cid); if (!channel) { log_error( "l2cap_decline_connection called but local_cid 0x%x not found", local_cid); return; } channel->state = L2CAP_STATE_WILL_SEND_CONNECTION_RESPONSE_DECLINE; - channel->reason = reason; + channel->reason = 0x04; // no resources available l2cap_run(); } @@ -1595,18 +1595,20 @@ uint8_t l2cap_register_service(btstack_packet_handler_t service_packet_handler, return 0; } -void l2cap_unregister_service(uint16_t psm){ +uint8_t l2cap_unregister_service(uint16_t psm){ log_info("L2CAP_UNREGISTER_SERVICE psm 0x%x", psm); l2cap_service_t *service = l2cap_get_service(psm); - if (!service) return; + if (!service) return L2CAP_SERVICE_DOES_NOT_EXIST; 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 (!btstack_linked_list_empty(&l2cap_services)) return; - gap_connectable_control(0); + if (btstack_linked_list_empty(&l2cap_services)) { + gap_connectable_control(0); + } + return 0; } // Bluetooth 4.0 - allows to register handler for Attribute Protocol and Security Manager Protocol @@ -1655,7 +1657,7 @@ uint8_t l2cap_le_register_service(btstack_packet_handler_t packet_handler, uint1 uint8_t l2cap_le_unregister_service(uint16_t psm) { log_info("L2CAP_LE_UNREGISTER_SERVICE psm 0x%x", psm); l2cap_service_t *service = l2cap_le_get_service(psm); - if (!service) return L2CAP_SERVICE_NOT_FOUND; + if (!service) return L2CAP_SERVICE_DOES_NOT_EXIST; btstack_linked_list_remove(&l2cap_le_services, (btstack_linked_item_t *) service); btstack_memory_l2cap_service_free(service); diff --git a/src/l2cap.h b/src/l2cap.h index 293d44e1f..3b7af9f88 100644 --- a/src/l2cap.h +++ b/src/l2cap.h @@ -252,7 +252,7 @@ uint8_t l2cap_register_service(btstack_packet_handler_t packet_handler, uint16_t /** * @brief Unregisters L2CAP service with given PSM. On embedded systems, use NULL for connection parameter. */ -void l2cap_unregister_service(uint16_t psm); +uint8_t l2cap_unregister_service(uint16_t psm); /** * @brief Accepts incoming L2CAP connection. @@ -262,7 +262,7 @@ void l2cap_accept_connection(uint16_t local_cid); /** * @brief Deny incoming L2CAP connection. */ -void l2cap_decline_connection(uint16_t local_cid, uint8_t reason); +void l2cap_decline_connection(uint16_t local_cid); /** * @brief Check if outgoing buffer is available and that there's space on the Bluetooth module diff --git a/test/btstack_config.h b/test/btstack_config.h index 195caef28..47a5deb40 100644 --- a/test/btstack_config.h +++ b/test/btstack_config.h @@ -6,7 +6,6 @@ #define __BTSTACK_CONFIG // Port related features -#define HAVE_INIT_SCRIPT #define HAVE_POSIX_TIME #define HAVE_MALLOC diff --git a/test/btstack_link_key_db/btstack_config.h b/test/btstack_link_key_db/btstack_config.h index 6ff70b29b..64b271fd7 100644 --- a/test/btstack_link_key_db/btstack_config.h +++ b/test/btstack_link_key_db/btstack_config.h @@ -6,7 +6,6 @@ #define __BTSTACK_CONFIG // Port related features -#define HAVE_INIT_SCRIPT #define HAVE_POSIX_TIME // BTstack features that can be enabled