mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-26 21:35:16 +00:00
Merge branch 'develop' of https://github.com/bluekitchen/btstack into develop
This commit is contained in:
commit
219d8683c5
@ -291,7 +291,7 @@ static void hci_event_handler(uint8_t packet_type, uint16_t channel, uint8_t *pa
|
||||
|
||||
if (cmdline_addr_found){
|
||||
printf("\nDisconnected %s\n", bd_addr_to_str(cmdline_addr));
|
||||
exit(0);
|
||||
return;
|
||||
}
|
||||
|
||||
printf("\nDisconnected %s\n", bd_addr_to_str(report.address));
|
||||
@ -304,14 +304,17 @@ static void hci_event_handler(uint8_t packet_type, uint16_t channel, uint8_t *pa
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_POSIX_STDIN
|
||||
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");
|
||||
}
|
||||
#endif
|
||||
|
||||
int btstack_main(int argc, const char * argv[]);
|
||||
int btstack_main(int argc, const char * argv[]){
|
||||
|
||||
#ifdef HAVE_POSIX_STDIN
|
||||
int arg = 1;
|
||||
cmdline_addr_found = 0;
|
||||
|
||||
@ -326,6 +329,10 @@ int btstack_main(int argc, const char * argv[]){
|
||||
usage(argv[0]);
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
UNUSED(argc);
|
||||
UNUSED(argv);
|
||||
#endif
|
||||
|
||||
hci_event_callback_registration.callback = &hci_event_handler;
|
||||
hci_add_event_handler(&hci_event_callback_registration);
|
||||
|
@ -201,7 +201,6 @@ static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *pac
|
||||
break;
|
||||
case HCI_EVENT_DISCONNECTION_COMPLETE:
|
||||
printf("\nGATT browser - DISCONNECTED\n");
|
||||
exit(0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -266,14 +265,17 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
|
||||
}
|
||||
/* LISTING_END */
|
||||
|
||||
#ifdef HAVE_POSIX_STDIN
|
||||
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");
|
||||
}
|
||||
#endif
|
||||
|
||||
int btstack_main(int argc, const char * argv[]);
|
||||
int btstack_main(int argc, const char * argv[]){
|
||||
|
||||
#ifdef HAVE_POSIX_STDIN
|
||||
int arg = 1;
|
||||
cmdline_addr_found = 0;
|
||||
|
||||
@ -287,6 +289,10 @@ int btstack_main(int argc, const char * argv[]){
|
||||
usage(argv[0]);
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
UNUSED(argc);
|
||||
UNUSED(argv);
|
||||
#endif
|
||||
|
||||
gatt_client_setup();
|
||||
|
||||
|
@ -269,6 +269,9 @@ static int tap_alloc(char *dev, bd_addr_t bd_addr)
|
||||
/* LISTING_START(processTapData): Process incoming network packets */
|
||||
static void process_tap_dev_data(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type)
|
||||
{
|
||||
UNUSED(ds);
|
||||
UNUSED(callback_type);
|
||||
|
||||
ssize_t len;
|
||||
len = read(ds->fd, network_buffer, sizeof(network_buffer));
|
||||
if (len <= 0){
|
||||
@ -317,6 +320,10 @@ static char * get_string_from_data_element(uint8_t * element){
|
||||
*/
|
||||
static void handle_sdp_client_query_result(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) {
|
||||
|
||||
UNUSED(packet_type);
|
||||
UNUSED(channel);
|
||||
UNUSED(size);
|
||||
|
||||
des_iterator_t des_list_it;
|
||||
des_iterator_t prot_it;
|
||||
char *str;
|
||||
@ -424,6 +431,8 @@ static void handle_sdp_client_query_result(uint8_t packet_type, uint16_t channel
|
||||
static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)
|
||||
{
|
||||
/* LISTING_PAUSE */
|
||||
UNUSED(channel);
|
||||
|
||||
int rc;
|
||||
uint8_t event;
|
||||
bd_addr_t event_addr;
|
||||
@ -561,6 +570,9 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
int btstack_main(int argc, const char * argv[]);
|
||||
int btstack_main(int argc, const char * argv[]){
|
||||
|
||||
UNUSED(argc);
|
||||
UNUSED(argv);
|
||||
|
||||
printf("Client HCI init done\n");
|
||||
|
||||
panu_setup();
|
||||
|
@ -169,7 +169,6 @@ static void handle_sdp_client_query_result(uint8_t packet_type, uint16_t channel
|
||||
break;
|
||||
case SDP_EVENT_QUERY_COMPLETE:
|
||||
printf("General query done with status %d.\n\n", sdp_event_query_complete_get_status(packet));
|
||||
exit(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -66,9 +66,6 @@ static btstack_linked_list_t bnep_channels = NULL;
|
||||
|
||||
static gap_security_level_t bnep_security_level;
|
||||
|
||||
static void (*app_packet_handler)(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
|
||||
|
||||
|
||||
static bnep_channel_t * bnep_channel_for_l2cap_cid(uint16_t l2cap_cid);
|
||||
static void bnep_channel_finalize(bnep_channel_t *channel);
|
||||
static void bnep_channel_start_timer(bnep_channel_t *channel, int timeout);
|
||||
@ -1090,8 +1087,10 @@ static int bnep_handle_ethernet_packet(bnep_channel_t *channel, bd_addr_t addr_d
|
||||
#endif
|
||||
|
||||
/* Notify application layer and deliver the ethernet packet */
|
||||
(*app_packet_handler)(BNEP_DATA_PACKET, channel->l2cap_cid,
|
||||
ethernet_packet, size + sizeof(uint16_t) + 2 * sizeof(bd_addr_t));
|
||||
if (channel->packet_handler){
|
||||
(*channel->packet_handler)(BNEP_DATA_PACKET, channel->l2cap_cid, ethernet_packet,
|
||||
size + sizeof(uint16_t) + 2 * sizeof(bd_addr_t));
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
48
src/hci.c
48
src/hci.c
@ -45,9 +45,11 @@
|
||||
#include "btstack_config.h"
|
||||
|
||||
|
||||
#ifdef ENABLE_CLASSIC
|
||||
#ifdef HAVE_EMBEDDED_TICK
|
||||
#include "btstack_run_loop_embedded.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_PLATFORM_IPHONE_OS
|
||||
#include "../port/ios/src/btstack_control_iphone.h"
|
||||
@ -814,10 +816,12 @@ uint16_t hci_max_acl_data_packet_length(void){
|
||||
return hci_stack->acl_data_packet_length;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_CLASSIC
|
||||
int hci_extended_sco_link_supported(void){
|
||||
// No. 31, byte 3, bit 7
|
||||
return (hci_stack->local_supported_features[3] & (1 << 7)) != 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int hci_non_flushable_packet_boundary_flag_supported(void){
|
||||
// No. 54, byte 6, bit 6
|
||||
@ -888,6 +892,8 @@ void le_handle_advertisement_report(uint8_t *packet, int size){
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_PLATFORM_IPHONE_OS) && !defined (HAVE_HOST_CONTROLLER_API)
|
||||
|
||||
static uint32_t hci_transport_uart_get_main_baud_rate(void){
|
||||
if (!hci_stack->config) return 0;
|
||||
uint32_t baud_rate = ((hci_transport_config_uart_t *)hci_stack->config)->baudrate_main;
|
||||
@ -936,6 +942,7 @@ static void hci_initialization_timeout_handler(btstack_timer_source_t * ds){
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void hci_initializing_next_state(void){
|
||||
hci_stack->substate = (hci_substate_t )( ((int) hci_stack->substate) + 1);
|
||||
@ -948,7 +955,7 @@ static void hci_initializing_run(void){
|
||||
case HCI_INIT_SEND_RESET:
|
||||
hci_state_reset();
|
||||
|
||||
#ifndef HAVE_PLATFORM_IPHONE_OS
|
||||
#if !defined(HAVE_PLATFORM_IPHONE_OS) && !defined (HAVE_HOST_CONTROLLER_API)
|
||||
// prepare reset if command complete not received in 100ms
|
||||
btstack_run_loop_set_timer(&hci_stack->timeout, HCI_RESET_RESEND_TIMEOUT_MS);
|
||||
btstack_run_loop_set_timer_handler(&hci_stack->timeout, hci_initialization_timeout_handler);
|
||||
@ -966,6 +973,8 @@ static void hci_initializing_run(void){
|
||||
hci_send_cmd(&hci_read_local_name);
|
||||
hci_stack->substate = HCI_INIT_W4_SEND_READ_LOCAL_NAME;
|
||||
break;
|
||||
|
||||
#if !defined(HAVE_PLATFORM_IPHONE_OS) && !defined (HAVE_HOST_CONTROLLER_API)
|
||||
case HCI_INIT_SEND_RESET_CSR_WARM_BOOT:
|
||||
hci_state_reset();
|
||||
// prepare reset if command complete not received in 100ms
|
||||
@ -1056,11 +1065,6 @@ static void hci_initializing_run(void){
|
||||
hci_stack->substate = HCI_INIT_W4_READ_LOCAL_SUPPORTED_COMMANDS;
|
||||
hci_send_cmd(&hci_read_local_supported_commands);
|
||||
break;
|
||||
case HCI_INIT_READ_LOCAL_SUPPORTED_COMMANDS:
|
||||
log_info("Resend hci_read_local_supported_commands after CSR Warm Boot double reset");
|
||||
hci_stack->substate = HCI_INIT_W4_READ_LOCAL_SUPPORTED_COMMANDS;
|
||||
hci_send_cmd(&hci_read_local_supported_commands);
|
||||
break;
|
||||
case HCI_INIT_SET_BD_ADDR:
|
||||
log_info("Set Public BD ADDR to %s", bd_addr_to_str(hci_stack->custom_bd_addr));
|
||||
hci_stack->chipset->set_bd_addr_command(hci_stack->custom_bd_addr, hci_stack->hci_packet_buffer);
|
||||
@ -1068,6 +1072,13 @@ static void hci_initializing_run(void){
|
||||
hci_stack->substate = HCI_INIT_W4_SET_BD_ADDR;
|
||||
hci_send_cmd_packet(hci_stack->hci_packet_buffer, 3 + hci_stack->hci_packet_buffer[2]);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case HCI_INIT_READ_LOCAL_SUPPORTED_COMMANDS:
|
||||
log_info("Resend hci_read_local_supported_commands after CSR Warm Boot double reset");
|
||||
hci_stack->substate = HCI_INIT_W4_READ_LOCAL_SUPPORTED_COMMANDS;
|
||||
hci_send_cmd(&hci_read_local_supported_commands);
|
||||
break;
|
||||
case HCI_INIT_READ_BD_ADDR:
|
||||
hci_stack->substate = HCI_INIT_W4_READ_BD_ADDR;
|
||||
hci_send_cmd(&hci_read_bd_addr);
|
||||
@ -1202,6 +1213,8 @@ static void hci_initializing_event_handler(uint8_t * packet, uint16_t size){
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(HAVE_PLATFORM_IPHONE_OS) && !defined (HAVE_HOST_CONTROLLER_API)
|
||||
|
||||
// Vendor == CSR
|
||||
if (hci_stack->substate == HCI_INIT_W4_CUSTOM_INIT && hci_event_packet_get_type(packet) == HCI_EVENT_VENDOR_SPECIFIC){
|
||||
// TODO: track actual command
|
||||
@ -1265,20 +1278,28 @@ static void hci_initializing_event_handler(uint8_t * packet, uint16_t size){
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (!command_completed) return;
|
||||
|
||||
int need_baud_change = hci_stack->config
|
||||
int need_baud_change = 0;
|
||||
int need_addr_change = 0;
|
||||
|
||||
#if !defined(HAVE_PLATFORM_IPHONE_OS) && !defined (HAVE_HOST_CONTROLLER_API)
|
||||
need_baud_change = hci_stack->config
|
||||
&& hci_stack->chipset
|
||||
&& hci_stack->chipset->set_baudrate_command
|
||||
&& hci_stack->hci_transport->set_baudrate
|
||||
&& ((hci_transport_config_uart_t *)hci_stack->config)->baudrate_main;
|
||||
|
||||
int need_addr_change = hci_stack->custom_bd_addr_set
|
||||
need_addr_change = hci_stack->custom_bd_addr_set
|
||||
&& hci_stack->chipset
|
||||
&& hci_stack->chipset->set_bd_addr_command;
|
||||
#endif
|
||||
|
||||
switch(hci_stack->substate){
|
||||
|
||||
#if !defined(HAVE_PLATFORM_IPHONE_OS) && !defined (HAVE_HOST_CONTROLLER_API)
|
||||
case HCI_INIT_SEND_RESET:
|
||||
// on CSR with BCSP/H5, resend triggers resend of HCI Reset and leads to substate == HCI_INIT_SEND_RESET
|
||||
// fix: just correct substate and behave as command below
|
||||
@ -1315,6 +1336,12 @@ static void hci_initializing_event_handler(uint8_t * packet, uint16_t size){
|
||||
// repeat custom init
|
||||
hci_stack->substate = HCI_INIT_CUSTOM_INIT;
|
||||
return;
|
||||
#else
|
||||
case HCI_INIT_W4_SEND_RESET:
|
||||
hci_stack->substate = HCI_INIT_READ_LOCAL_SUPPORTED_COMMANDS;
|
||||
return ;
|
||||
#endif
|
||||
|
||||
case HCI_INIT_W4_READ_LOCAL_SUPPORTED_COMMANDS:
|
||||
if (need_baud_change && hci_stack->manufacturer == COMPANY_ID_BROADCOM_CORPORATION){
|
||||
hci_stack->substate = HCI_INIT_SEND_BAUD_CHANGE_BCM;
|
||||
@ -1326,6 +1353,7 @@ static void hci_initializing_event_handler(uint8_t * packet, uint16_t size){
|
||||
}
|
||||
hci_stack->substate = HCI_INIT_READ_BD_ADDR;
|
||||
return;
|
||||
#if !defined(HAVE_PLATFORM_IPHONE_OS) && !defined (HAVE_HOST_CONTROLLER_API)
|
||||
case HCI_INIT_W4_SEND_BAUD_CHANGE_BCM:
|
||||
if (need_baud_change){
|
||||
uint32_t baud_rate = hci_transport_uart_get_main_baud_rate();
|
||||
@ -1350,6 +1378,7 @@ static void hci_initializing_event_handler(uint8_t * packet, uint16_t size){
|
||||
case HCI_INIT_W4_SEND_RESET_ST_WARM_BOOT:
|
||||
hci_stack->substate = HCI_INIT_READ_BD_ADDR;
|
||||
return;
|
||||
#endif
|
||||
case HCI_INIT_W4_READ_BD_ADDR:
|
||||
// only read buffer size if supported
|
||||
if (hci_stack->local_supported_commands[0] & 0x01) {
|
||||
@ -1456,6 +1485,7 @@ static void event_handler(uint8_t *packet, int size){
|
||||
hci_stack->num_cmd_packets = packet[2] ? 1 : 0;
|
||||
|
||||
if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_read_local_name)){
|
||||
if (packet[5]) break;
|
||||
// terminate, name 248 chars
|
||||
packet[6+248] = 0;
|
||||
log_info("local name: %s", &packet[6]);
|
||||
@ -3253,6 +3283,7 @@ static void hci_emit_discoverable_enabled(uint8_t enabled){
|
||||
hci_emit_event(event, sizeof(event), 1);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_CLASSIC
|
||||
// query if remote side supports eSCO
|
||||
int hci_remote_esco_supported(hci_con_handle_t con_handle){
|
||||
hci_connection_t * connection = hci_connection_for_handle(con_handle);
|
||||
@ -3270,6 +3301,7 @@ int hci_remote_ssp_supported(hci_con_handle_t con_handle){
|
||||
int gap_ssp_supported_on_both_sides(hci_con_handle_t handle){
|
||||
return hci_local_ssp_activated() && hci_remote_ssp_supported(handle);
|
||||
}
|
||||
#endif
|
||||
|
||||
// GAP API
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user