mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-02 16:20:31 +00:00
send vendor specific command to set bd addr if both set and provided via bt_control_t
This commit is contained in:
parent
c6af8a746f
commit
f456b2d087
61
src/hci.c
61
src/hci.c
@ -754,7 +754,7 @@ static void hci_initializing_event_handler(uint8_t * packet, uint16_t size){
|
|||||||
uint16_t opcode = READ_BT_16(packet,3);
|
uint16_t opcode = READ_BT_16(packet,3);
|
||||||
if (opcode == hci_stack->last_cmd_opcode){
|
if (opcode == hci_stack->last_cmd_opcode){
|
||||||
command_completed = 1;
|
command_completed = 1;
|
||||||
log_info("Command complete for expected opcode %04x -> new substate %u", opcode, hci_stack->substate);
|
log_info("Command complete for expected opcode %04x -> new substate %u", opcode, hci_stack->substate >> 1);
|
||||||
} else {
|
} else {
|
||||||
log_info("Command complete for opcode %04x, expected %04x", opcode, hci_stack->last_cmd_opcode);
|
log_info("Command complete for opcode %04x, expected %04x", opcode, hci_stack->last_cmd_opcode);
|
||||||
}
|
}
|
||||||
@ -765,7 +765,7 @@ static void hci_initializing_event_handler(uint8_t * packet, uint16_t size){
|
|||||||
if (opcode == hci_stack->last_cmd_opcode){
|
if (opcode == hci_stack->last_cmd_opcode){
|
||||||
if (status){
|
if (status){
|
||||||
command_completed = 1;
|
command_completed = 1;
|
||||||
log_error("Command status error 0x%02x for expected opcode %04x -> new substate %u", status, opcode, hci_stack->substate);
|
log_error("Command status error 0x%02x for expected opcode %04x -> new substate %u", status, opcode, hci_stack->substate >> 1);
|
||||||
} else {
|
} else {
|
||||||
log_info("Command status OK for expected opcode %04x, waiting for command complete", opcode);
|
log_info("Command status OK for expected opcode %04x, waiting for command complete", opcode);
|
||||||
}
|
}
|
||||||
@ -784,11 +784,11 @@ static void hci_initializing_event_handler(uint8_t * packet, uint16_t size){
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void hci_initializing_state_machine(){
|
static void hci_initializing_state_machine(){
|
||||||
// log_info("hci_init: substate %u", hci_stack->substate);
|
|
||||||
if (hci_stack->substate % 2) {
|
if (hci_stack->substate % 2) {
|
||||||
// odd: waiting for command completion
|
// odd: waiting for command completion
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// log_info("hci_init: substate %u", hci_stack->substate >> 1);
|
||||||
switch (hci_stack->substate >> 1){
|
switch (hci_stack->substate >> 1){
|
||||||
case 0: // RESET
|
case 0: // RESET
|
||||||
hci_state_reset();
|
hci_state_reset();
|
||||||
@ -796,7 +796,7 @@ static void hci_initializing_state_machine(){
|
|||||||
hci_send_cmd(&hci_reset);
|
hci_send_cmd(&hci_reset);
|
||||||
if (hci_stack->config == NULL || ((hci_uart_config_t *)hci_stack->config)->baudrate_main == 0){
|
if (hci_stack->config == NULL || ((hci_uart_config_t *)hci_stack->config)->baudrate_main == 0){
|
||||||
// skip baud change
|
// skip baud change
|
||||||
hci_stack->substate = 4; // >> 1 = 2
|
hci_stack->substate = 2 << 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1: // SEND BAUD CHANGE
|
case 1: // SEND BAUD CHANGE
|
||||||
@ -811,7 +811,18 @@ static void hci_initializing_state_machine(){
|
|||||||
hci_stack->substate += 2;
|
hci_stack->substate += 2;
|
||||||
// break missing here for fall through
|
// break missing here for fall through
|
||||||
|
|
||||||
case 3:
|
case 3: // SET BD ADDR
|
||||||
|
if ( hci_stack->custom_bd_addr_set && hci_stack->control && hci_stack->control->set_bd_addr_cmd){
|
||||||
|
log_info("Set Public BD ADDR to %s", bd_addr_to_str(hci_stack->custom_bd_addr));
|
||||||
|
hci_stack->control->set_bd_addr_cmd(hci_stack->config, hci_stack->custom_bd_addr, hci_stack->hci_packet_buffer);
|
||||||
|
hci_dump_packet(HCI_COMMAND_DATA_PACKET, 0, hci_stack->hci_packet_buffer, 3 + hci_stack->hci_packet_buffer[2]);
|
||||||
|
hci_send_cmd_packet(hci_stack->hci_packet_buffer, 3 + hci_stack->hci_packet_buffer[2]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
hci_stack->substate += 2;
|
||||||
|
// break missing here for fall through
|
||||||
|
|
||||||
|
case 4:
|
||||||
log_info("Custom init");
|
log_info("Custom init");
|
||||||
// Custom initialization
|
// Custom initialization
|
||||||
if (hci_stack->control && hci_stack->control->next_cmd){
|
if (hci_stack->control && hci_stack->control->next_cmd){
|
||||||
@ -821,7 +832,7 @@ static void hci_initializing_state_machine(){
|
|||||||
hci_stack->last_cmd_opcode = READ_BT_16(hci_stack->hci_packet_buffer, 0);
|
hci_stack->last_cmd_opcode = READ_BT_16(hci_stack->hci_packet_buffer, 0);
|
||||||
hci_dump_packet(HCI_COMMAND_DATA_PACKET, 0, hci_stack->hci_packet_buffer, size);
|
hci_dump_packet(HCI_COMMAND_DATA_PACKET, 0, hci_stack->hci_packet_buffer, size);
|
||||||
hci_stack->hci_transport->send_packet(HCI_COMMAND_DATA_PACKET, hci_stack->hci_packet_buffer, size);
|
hci_stack->hci_transport->send_packet(HCI_COMMAND_DATA_PACKET, hci_stack->hci_packet_buffer, size);
|
||||||
hci_stack->substate = 4; // more init commands
|
hci_stack->substate = 3 << 1; // more init commands
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
log_info("hci_run: init script done");
|
log_info("hci_run: init script done");
|
||||||
@ -829,31 +840,31 @@ static void hci_initializing_state_machine(){
|
|||||||
// otherwise continue
|
// otherwise continue
|
||||||
hci_send_cmd(&hci_read_bd_addr);
|
hci_send_cmd(&hci_read_bd_addr);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 5:
|
||||||
hci_send_cmd(&hci_read_buffer_size);
|
hci_send_cmd(&hci_read_buffer_size);
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 6:
|
||||||
hci_send_cmd(&hci_read_local_supported_features);
|
hci_send_cmd(&hci_read_local_supported_features);
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 7:
|
||||||
if (hci_le_supported()){
|
if (hci_le_supported()){
|
||||||
hci_send_cmd(&hci_set_event_mask,0xffffffff, 0x3FFFFFFF);
|
hci_send_cmd(&hci_set_event_mask,0xffffffff, 0x3FFFFFFF);
|
||||||
} else {
|
} else {
|
||||||
// Kensington Bluetoot 2.1 USB Dongle (CSR Chipset) returns an error for 0xffff...
|
// Kensington Bluetooth 2.1 USB Dongle (CSR Chipset) returns an error for 0xffff...
|
||||||
hci_send_cmd(&hci_set_event_mask,0xffffffff, 0x1FFFFFFF);
|
hci_send_cmd(&hci_set_event_mask,0xffffffff, 0x1FFFFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
// skip Classic init commands for LE only chipsets
|
// skip Classic init commands for LE only chipsets
|
||||||
if (!hci_classic_supported()){
|
if (!hci_classic_supported()){
|
||||||
if (hci_le_supported()){
|
if (hci_le_supported()){
|
||||||
hci_stack->substate = 11 << 1; // skip all classic command
|
hci_stack->substate = 12 << 1; // skip all classic command
|
||||||
} else {
|
} else {
|
||||||
log_error("Neither BR/EDR nor LE supported");
|
log_error("Neither BR/EDR nor LE supported");
|
||||||
hci_stack->substate = 14 << 1; // skip all
|
hci_stack->substate = 15 << 1; // skip all
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 8:
|
||||||
if (hci_ssp_supported()){
|
if (hci_ssp_supported()){
|
||||||
hci_send_cmd(&hci_write_simple_pairing_mode, hci_stack->ssp_enable);
|
hci_send_cmd(&hci_write_simple_pairing_mode, hci_stack->ssp_enable);
|
||||||
break;
|
break;
|
||||||
@ -861,14 +872,14 @@ static void hci_initializing_state_machine(){
|
|||||||
hci_stack->substate += 2;
|
hci_stack->substate += 2;
|
||||||
// break missing here for fall through
|
// break missing here for fall through
|
||||||
|
|
||||||
case 8:
|
case 9:
|
||||||
// ca. 15 sec
|
// ca. 15 sec
|
||||||
hci_send_cmd(&hci_write_page_timeout, 0x6000);
|
hci_send_cmd(&hci_write_page_timeout, 0x6000);
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 10:
|
||||||
hci_send_cmd(&hci_write_class_of_device, hci_stack->class_of_device);
|
hci_send_cmd(&hci_write_class_of_device, hci_stack->class_of_device);
|
||||||
break;
|
break;
|
||||||
case 10:
|
case 11:
|
||||||
if (hci_stack->local_name){
|
if (hci_stack->local_name){
|
||||||
hci_send_cmd(&hci_write_local_name, hci_stack->local_name);
|
hci_send_cmd(&hci_write_local_name, hci_stack->local_name);
|
||||||
} else {
|
} else {
|
||||||
@ -886,31 +897,31 @@ static void hci_initializing_state_machine(){
|
|||||||
hci_send_cmd(&hci_write_local_name, hostname);
|
hci_send_cmd(&hci_write_local_name, hostname);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 11:
|
case 12:
|
||||||
hci_send_cmd(&hci_write_scan_enable, (hci_stack->connectable << 1) | hci_stack->discoverable); // page scan
|
hci_send_cmd(&hci_write_scan_enable, (hci_stack->connectable << 1) | hci_stack->discoverable); // page scan
|
||||||
if (!hci_le_supported()){
|
if (!hci_le_supported()){
|
||||||
// SKIP LE init for Classic only configuration
|
// SKIP LE init for Classic only configuration
|
||||||
hci_stack->substate = 14 << 1;
|
hci_stack->substate = 15 << 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#ifdef HAVE_BLE
|
#ifdef HAVE_BLE
|
||||||
// LE INIT
|
// LE INIT
|
||||||
case 12:
|
case 13:
|
||||||
hci_send_cmd(&hci_le_read_buffer_size);
|
hci_send_cmd(&hci_le_read_buffer_size);
|
||||||
break;
|
break;
|
||||||
case 13:
|
case 14:
|
||||||
// LE Supported Host = 1, Simultaneous Host = 0
|
// LE Supported Host = 1, Simultaneous Host = 0
|
||||||
hci_send_cmd(&hci_write_le_host_supported, 1, 0);
|
hci_send_cmd(&hci_write_le_host_supported, 1, 0);
|
||||||
break;
|
break;
|
||||||
case 14:
|
case 15:
|
||||||
// LE Scan Parameters: active scanning, 300 ms interval, 30 ms window, public address, accept all advs
|
// LE Scan Parameters: active scanning, 300 ms interval, 30 ms window, public address, accept all advs
|
||||||
hci_send_cmd(&hci_le_set_scan_parameters, 1, 0x1e0, 0x30, 0, 0);
|
hci_send_cmd(&hci_le_set_scan_parameters, 1, 0x1e0, 0x30, 0, 0);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// DONE
|
// DONE
|
||||||
case 15:
|
case 16:
|
||||||
// done.
|
// done.
|
||||||
hci_stack->state = HCI_STATE_WORKING;
|
hci_stack->state = HCI_STATE_WORKING;
|
||||||
hci_emit_state();
|
hci_emit_state();
|
||||||
@ -1500,6 +1511,12 @@ void hci_set_class_of_device(uint32_t class_of_device){
|
|||||||
hci_stack->class_of_device = class_of_device;
|
hci_stack->class_of_device = class_of_device;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set Public BD ADDR - passed on to Bluetooth chipset if supported in bt_control_h
|
||||||
|
void hci_set_bd_addr(bd_addr_t addr){
|
||||||
|
memcpy(hci_stack->custom_bd_addr, addr, 6);
|
||||||
|
hci_stack->custom_bd_addr_set = 1;
|
||||||
|
}
|
||||||
|
|
||||||
void hci_disable_l2cap_timeout_check(){
|
void hci_disable_l2cap_timeout_check(){
|
||||||
disable_l2cap_timeouts = 1;
|
disable_l2cap_timeouts = 1;
|
||||||
}
|
}
|
||||||
|
11
src/hci.h
11
src/hci.h
@ -391,7 +391,6 @@ typedef struct {
|
|||||||
uint16_t le_update_con_parameter_response;
|
uint16_t le_update_con_parameter_response;
|
||||||
} hci_connection_t;
|
} hci_connection_t;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* main data structure
|
* main data structure
|
||||||
*/
|
*/
|
||||||
@ -400,7 +399,7 @@ typedef struct {
|
|||||||
hci_transport_t * hci_transport;
|
hci_transport_t * hci_transport;
|
||||||
void * config;
|
void * config;
|
||||||
|
|
||||||
// bsic configuration
|
// basic configuration
|
||||||
const char * local_name;
|
const char * local_name;
|
||||||
uint32_t class_of_device;
|
uint32_t class_of_device;
|
||||||
bd_addr_t local_bd_addr;
|
bd_addr_t local_bd_addr;
|
||||||
@ -471,6 +470,11 @@ typedef struct {
|
|||||||
uint16_t le_scan_window;
|
uint16_t le_scan_window;
|
||||||
|
|
||||||
le_connection_parameter_range_t le_connection_parameter_range;
|
le_connection_parameter_range_t le_connection_parameter_range;
|
||||||
|
|
||||||
|
// custom BD ADDR
|
||||||
|
bd_addr_t custom_bd_addr;
|
||||||
|
uint8_t custom_bd_addr_set;
|
||||||
|
|
||||||
} hci_stack_t;
|
} hci_stack_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -576,6 +580,9 @@ void hci_init(hci_transport_t *transport, void *config, bt_control_t *control, r
|
|||||||
// Set class of device that will be set during Bluetooth init
|
// Set class of device that will be set during Bluetooth init
|
||||||
void hci_set_class_of_device(uint32_t class_of_device);
|
void hci_set_class_of_device(uint32_t class_of_device);
|
||||||
|
|
||||||
|
// Set Public BD ADDR - passed on to Bluetooth chipset if supported in bt_control_h
|
||||||
|
void hci_set_bd_addr(bd_addr_t addr);
|
||||||
|
|
||||||
// Registers a packet handler. Used if L2CAP is not used (rarely).
|
// Registers a packet handler. Used if L2CAP is not used (rarely).
|
||||||
void hci_register_packet_handler(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size));
|
void hci_register_packet_handler(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user