From a3fe55ccff32e8dbd9221275424b6315c4da8a23 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Fri, 20 May 2016 10:36:17 +0200 Subject: [PATCH 1/6] cc256x: support older chipsets --- chipset/cc256x/Makefile.inc | 53 +++++++++++++++++++++- chipset/cc256x/convert_bts_init_scripts.py | 3 +- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/chipset/cc256x/Makefile.inc b/chipset/cc256x/Makefile.inc index 5937c414d..bb312c532 100644 --- a/chipset/cc256x/Makefile.inc +++ b/chipset/cc256x/Makefile.inc @@ -4,6 +4,38 @@ # BASE_URL = https://git.ti.com/ti-bt/service-packs/blobs/raw/a027ae390d8790e56e1c78136c78fe6537470e91 +# first generation CC2560 - TIInit_6.2.31.bts part of .zip archive + +CC2560_BT_SP_BTS.zip: + curl -O http://processors.wiki.ti.com/images/d/da/CC2560_BT_SP_BTS.zip + +bluetooth_init_cc2560_2.44.bts: CC2560_BT_SP_BTS.zip + unzip CC2560_BT_SP_BTS.zip + mv CC2560_BT_SP_BTS/bluetooth_init_cc2560_2.44.bts . + rm -rf CC2560_BT_SP_BTS + + +# second generation CC2560A and CC2564 - TIInit_6.6.15.bts part of .zip archive + +CC2560A_BT_SP_BTS.zip: + curl -O http://processors.wiki.ti.com/images/e/e7/CC2560A_BT_SP_BTS.zip + +CC2564_BT_BLE_SP_BTS.zip: + curl -O http://processors.wiki.ti.com/images/1/1e/CC2564_BT_BLE_SP_BTS.zip + +bluetooth_init_cc2560A_2.14.bts: CC2560A_BT_SP_BTS.zip + unzip CC2560A_BT_SP_BTS.zip + mv CC2560A_BT_SP_BTS/bluetooth_init_cc2560a_2.14.bts . + rm -rf CC2560A_BT_SP_BTS + +bluetooth_init_cc2564_2.14.bts: CC2564_BT_BLE_SP_BTS.zip + unzip CC2564_BT_BLE_SP_BTS.zip + mv CC2564_BT_BLE_SP_BTS/bluetooth_init_cc2564_2.14.bts . + rm -rf CC2564_BT_BLE_SP_BTS + + +# third generation + bluetooth_init_cc2560B_1.2_BT_Spec_4.0.bts: curl -O $(BASE_URL)/bluetooth_init_cc2560B_1.2_BT_Spec_4.0.bts @@ -31,6 +63,17 @@ TIInit_12.8.32.bts: # convert to .c files CONVERSION_SCRIPT=$(BTSTACK_ROOT)/chipset/cc256x/convert_bts_init_scripts.py +bluetooth_init_cc2560_2.44.c: bluetooth_init_cc2560_2.44.bts + $(CONVERSION_SCRIPT) + + +bluetooth_init_cc2560A_2.14.c: bluetooth_init_cc2560A_2.14.bts + $(CONVERSION_SCRIPT) + +bluetooth_init_cc2564_2.14.c: bluetooth_init_cc2564_2.14.bts + $(CONVERSION_SCRIPT) + + bluetooth_init_cc2560B_1.2_BT_Spec_4.0.c: bluetooth_init_cc2560B_1.2_BT_Spec_4.0.bts $(CONVERSION_SCRIPT) @@ -43,11 +86,19 @@ bluetooth_init_cc2560B_1.2_BT_Spec_4.1.c: bluetooth_init_cc2560B_1.2_BT_Spec_4.1 bluetooth_init_cc2564B_1.2_BT_Spec_4.1.c: bluetooth_init_cc2564B_1.2_BT_Spec_4.1.bts BLE_init_cc2564B_1.2.bts $(CONVERSION_SCRIPT) + TIInit_11.8.32.c: TIInit_11.8.32.bts $(CONVERSION_SCRIPT) TIInit_12.10.28.c: TIInit_12.10.28.bts $(CONVERSION_SCRIPT) -TIInit_12.8.32.c: /TIInit_12.8.32.bts +TIInit_12.8.32.c: TIInit_12.8.32.bts $(CONVERSION_SCRIPT) + +all-scripts: bluetooth_init_cc2560_2.44.c bluetooth_init_cc2560A_2.14.c bluetooth_init_cc2564_2.14.bts bluetooth_init_cc2560B_1.2_BT_Spec_4.0.c bluetooth_init_cc2564B_1.2_BT_Spec_4.0.c bluetooth_init_cc2560B_1.2_BT_Spec_4.1.c bluetooth_init_cc2564B_1.2_BT_Spec_4.1.c TIInit_11.8.32.c TIInit_12.10.28.c TIInit_12.8.32.c + +clean-scripts: + rm -fr CC256*.zip bluetooth_init_cc256*.bts bluetooth_init_cc256*.c TIInit_*.bts TIInit_*.c BLE_init_cc256*.bts BLE_init_cc256*.c + + diff --git a/chipset/cc256x/convert_bts_init_scripts.py b/chipset/cc256x/convert_bts_init_scripts.py index 71a9b3c12..c4119ea42 100755 --- a/chipset/cc256x/convert_bts_init_scripts.py +++ b/chipset/cc256x/convert_bts_init_scripts.py @@ -142,14 +142,13 @@ def convert_bts(main_bts_file, bts_add_on): if (action_type == 1): # hci command - # opcode = (ord(action_data[2]) << 8) | ord(action_data[1]) opcode = (action_data[2] << 8) | action_data[1] if opcode == 0xFF36: continue # skip baud rate command if opcode == 0xFD0C: have_eHCILL = True if opcode == 0xFD82: - modulation_type = ord(action_data[4]) + modulation_type = action_data[4] if modulation_type == 0: have_power_vector_gfsk = True elif modulation_type == 1: From edc52946c24d9ab476077fb84eb31aad41033de2 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Fri, 20 May 2016 11:13:49 +0200 Subject: [PATCH 2/6] cc256x: support CC256xB v1.4 init scripts --- chipset/cc256x/Makefile.inc | 26 +++++++++++++++------- chipset/cc256x/convert_bts_init_scripts.py | 12 ++++++++++ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/chipset/cc256x/Makefile.inc b/chipset/cc256x/Makefile.inc index bb312c532..732804df8 100644 --- a/chipset/cc256x/Makefile.inc +++ b/chipset/cc256x/Makefile.inc @@ -3,6 +3,7 @@ # http://processors.wiki.ti.com/index.php/CC256x_Downloads # BASE_URL = https://git.ti.com/ti-bt/service-packs/blobs/raw/a027ae390d8790e56e1c78136c78fe6537470e91 +CONVERSION_SCRIPT=$(BTSTACK_ROOT)/chipset/cc256x/convert_bts_init_scripts.py # first generation CC2560 - TIInit_6.2.31.bts part of .zip archive @@ -36,12 +37,7 @@ bluetooth_init_cc2564_2.14.bts: CC2564_BT_BLE_SP_BTS.zip # third generation -bluetooth_init_cc2560B_1.2_BT_Spec_4.0.bts: - curl -O $(BASE_URL)/bluetooth_init_cc2560B_1.2_BT_Spec_4.0.bts - -bluetooth_init_cc2564B_1.2_BT_Spec_4.0.bts: - curl -O $(BASE_URL)/bluetooth_init_cc2564B_1.2_BT_Spec_4.0.bts - +# versioned files for v1.2 bluetooth_init_cc2560B_1.2_BT_Spec_4.1.bts: curl -O $(BASE_URL)/bluetooth_init_cc2560B_1.2_BT_Spec_4.1.bts @@ -51,6 +47,14 @@ bluetooth_init_cc2564B_1.2_BT_Spec_4.1.bts: BLE_init_cc2564B_1.2.bts: curl -O $(BASE_URL)/BLE_init_cc2564B_1.2.bts +# unversioned files for v1.4 +TIInit_6.7.16_bt_spec_4.1.bts: + curl -O https://git.ti.com/ti-bt/service-packs/blobs/raw/54f5c151dacc608b19ab2ce4c30e27a3983048b2/initscripts/TIInit_6.7.16_bt_spec_4.1.bts + +TIInit_6.7.16_ble_add-on.bts: + curl -O https://git.ti.com/ti-bt/service-packs/blobs/raw/89c8db14929f10d75627b132690432cd71f5f54f/initscripts/TIInit_6.7.16_ble_add-on.bts + +# WL chipset TIInit_11.8.32.bts: curl -O $(BASE_URL)/TIInit_11.8.32.bts @@ -61,8 +65,6 @@ TIInit_12.8.32.bts: curl -O $(BASE_URL)/TIInit_12.8.32.bts # convert to .c files -CONVERSION_SCRIPT=$(BTSTACK_ROOT)/chipset/cc256x/convert_bts_init_scripts.py - bluetooth_init_cc2560_2.44.c: bluetooth_init_cc2560_2.44.bts $(CONVERSION_SCRIPT) @@ -86,6 +88,14 @@ bluetooth_init_cc2560B_1.2_BT_Spec_4.1.c: bluetooth_init_cc2560B_1.2_BT_Spec_4.1 bluetooth_init_cc2564B_1.2_BT_Spec_4.1.c: bluetooth_init_cc2564B_1.2_BT_Spec_4.1.bts BLE_init_cc2564B_1.2.bts $(CONVERSION_SCRIPT) +bluetooth_init_cc2560B_1.4_BT_Spec_4.1.c: TIInit_6.7.16_bt_spec_4.1.bts + cp TIInit_6.7.16_bt_spec_4.1.bts bluetooth_init_cc2560B_1.4_BT_Spec_4.1.bts + $(CONVERSION_SCRIPT) + +bluetooth_init_cc2564B_1.4_BT_Spec_4.1.c: TIInit_6.7.16_bt_spec_4.1.bts TIInit_6.7.16_ble_add-on.bts + cp TIInit_6.7.16_bt_spec_4.1.bts bluetooth_init_cc2564B_1.4_BT_Spec_4.1.bts + cp TIInit_6.7.16_ble_add-on.bts BLE_init_cc2564B_1.4.bts + $(CONVERSION_SCRIPT) TIInit_11.8.32.c: TIInit_11.8.32.bts $(CONVERSION_SCRIPT) diff --git a/chipset/cc256x/convert_bts_init_scripts.py b/chipset/cc256x/convert_bts_init_scripts.py index c4119ea42..6b340aebf 100755 --- a/chipset/cc256x/convert_bts_init_scripts.py +++ b/chipset/cc256x/convert_bts_init_scripts.py @@ -282,6 +282,9 @@ for name in files: if name_lower.startswith('avpr_init_cc'): print("Skipping AVPR add-on", name) continue + if re.match("tiinit_.*_ble_add-on.bts", name_lower): + print("Skipping BLE add-on", name) + continue if re.match("initscripts_tiinit_.*_ble_add-on.bts", name_lower): print("Skipping BLE add-on", name) continue @@ -289,6 +292,8 @@ for name in files: print("Skipping AVPR add-on", name) continue + print "check", name + # check for BLE add-on add_on = "" name_parts = re.match('bluetooth_init_(.....+_...)_.*.bts', name) @@ -298,6 +303,13 @@ for name in files: add_on = potential_add_on print("Found", add_on, "add-on for", name) + name_parts = re.match('TIInit_(\d*\.\d*\.\d*)_.*.bts', name) + if name_parts: + potential_add_on = 'TIInit_%s_ble_add-on.bts' % name_parts.group(1) + if os.path.isfile(potential_add_on): + add_on = potential_add_on + print("Found", add_on, "add-on for", name) + name_parts = re.match('initscripts_TIInit_(\d*\.\d*\.\d*)_.*.bts', name) if name_parts: potential_add_on = 'initscripts_TIInit_%s_ble_add-on.bts' % name_parts.group(1) From 36c8a70fe0e50121634358d17c605432da49ea8e Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Fri, 20 May 2016 11:27:32 +0200 Subject: [PATCH 3/6] cc256x:use v1.4 init script for CC2560B and CC2564B ports --- .gitignore | 5 +++-- port/ez430-rf2560/Makefile | 4 ++-- port/msp-exp430f5438-cc2564b/Makefile | 4 ++-- port/msp430f5229lp-cc2564b/Makefile | 4 ++-- port/posix-h4/Makefile | 2 +- port/posix-h5/Makefile | 2 +- port/stm32-f103rb-nucleo/Makefile | 2 +- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index a4c85c315..0c0823b52 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,8 @@ *.map .theos .stamp -bluetooth_init_cc2560B_1.2_BT_Spec_4.1.c -bluetooth_init_cc2564B_1.2_BT_Spec_4.1.c +.bts +bluetooth_init_cc2560B_1.*_BT_Spec_4.1.c +bluetooth_init_cc2564B_1.*_BT_Spec_4.1.c TIInit_11.8.32.c initscripts_TIInit_6.7.16_bt_spec_4.1.c diff --git a/port/ez430-rf2560/Makefile b/port/ez430-rf2560/Makefile index b53f0136a..88c7786f7 100644 --- a/port/ez430-rf2560/Makefile +++ b/port/ez430-rf2560/Makefile @@ -4,8 +4,8 @@ # # init scripts -CC2560B = bluetooth_init_cc2560B_1.2_BT_Spec_4.1.o -CC2564B = bluetooth_init_cc2564B_1.2_BT_Spec_4.1.o +CC2560B = bluetooth_init_cc2560B_1.4_BT_Spec_4.1.o +CC2564B = bluetooth_init_cc2564B_1.4_BT_Spec_4.1.o CC2567 = CC256x_BT_Service_Pack_2.8_ANT_1.16.o BTSTACK_ROOT = ../.. diff --git a/port/msp-exp430f5438-cc2564b/Makefile b/port/msp-exp430f5438-cc2564b/Makefile index 470e8cc74..433c9fe41 100644 --- a/port/msp-exp430f5438-cc2564b/Makefile +++ b/port/msp-exp430f5438-cc2564b/Makefile @@ -4,8 +4,8 @@ # # init scripts -CC2560B = bluetooth_init_cc2560B_1.2_BT_Spec_4.1.o -CC2564B = bluetooth_init_cc2564B_1.2_BT_Spec_4.1.o +CC2560B = bluetooth_init_cc2560B_1.4_BT_Spec_4.1.o +CC2564B = bluetooth_init_cc2564B_1.4_BT_Spec_4.1.o CC2567 = CC256x_BT_Service_Pack_2.8_ANT_1.16.o BTSTACK_ROOT = ../.. diff --git a/port/msp430f5229lp-cc2564b/Makefile b/port/msp430f5229lp-cc2564b/Makefile index 9b0d95e94..abe9e94bf 100644 --- a/port/msp430f5229lp-cc2564b/Makefile +++ b/port/msp430f5229lp-cc2564b/Makefile @@ -4,8 +4,8 @@ # # init scripts -CC2560B = bluetooth_init_cc2560B_1.2_BT_Spec_4.1.o -CC2564B = bluetooth_init_cc2564B_1.2_BT_Spec_4.1.o +CC2560B = bluetooth_init_cc2560B_1.4_BT_Spec_4.1.o +CC2564B = bluetooth_init_cc2564B_1.4_BT_Spec_4.1.o CC2567 = CC256x_BT_Service_Pack_2.8_ANT_1.16.o BTSTACK_ROOT = ../.. diff --git a/port/posix-h4/Makefile b/port/posix-h4/Makefile index 810b5aa2b..9002a15ad 100644 --- a/port/posix-h4/Makefile +++ b/port/posix-h4/Makefile @@ -2,7 +2,7 @@ BTSTACK_ROOT = ../.. CORE += \ - bluetooth_init_cc2564B_1.2_BT_Spec_4.1.c \ + bluetooth_init_cc2564B_1.4_BT_Spec_4.1.c \ btstack_chipset_cc256x.c \ btstack_chipset_csr.c \ btstack_chipset_em9301.c \ diff --git a/port/posix-h5/Makefile b/port/posix-h5/Makefile index b98920889..b335fd85a 100644 --- a/port/posix-h5/Makefile +++ b/port/posix-h5/Makefile @@ -2,7 +2,7 @@ BTSTACK_ROOT = ../.. CORE += \ - bluetooth_init_cc2564B_1.2_BT_Spec_4.1.c \ + bluetooth_init_cc2564B_1.4_BT_Spec_4.1.c \ btstack_chipset_cc256x.c \ btstack_chipset_csr.c \ btstack_chipset_em9301.c \ diff --git a/port/stm32-f103rb-nucleo/Makefile b/port/stm32-f103rb-nucleo/Makefile index 4e78f7df2..907371543 100644 --- a/port/stm32-f103rb-nucleo/Makefile +++ b/port/stm32-f103rb-nucleo/Makefile @@ -24,7 +24,7 @@ CORE = \ btstack_run_loop_embedded.c \ COMMON = \ - bluetooth_init_cc2564B_1.2_BT_Spec_4.1.c \ + bluetooth_init_cc2564B_1.4_BT_Spec_4.1.c \ btstack_chipset_cc256x.c \ btstack_link_key_db_memory.c \ rfcomm.c \ From 5415113f9fc6cad3e4ab204ca0c3279e4d2e73c8 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Fri, 20 May 2016 14:26:01 +0200 Subject: [PATCH 4/6] cc256x: follow recommendations for SCO over HCI --- chipset/cc256x/btstack_chipset_cc256x.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/chipset/cc256x/btstack_chipset_cc256x.c b/chipset/cc256x/btstack_chipset_cc256x.c index 2a3719ec9..63289ec2f 100644 --- a/chipset/cc256x/btstack_chipset_cc256x.c +++ b/chipset/cc256x/btstack_chipset_cc256x.c @@ -88,9 +88,10 @@ static int16_t init_power_in_dB = 13; // 13 dBm // support for SCO over HCI #ifdef ENABLE_SCO_OVER_HCI static int init_send_route_sco_over_hci = 0; -// route SCO over HCI (connection type=1, tx buffer size = 0x00 (don't change), tx buffer max latency=0x0000(don't chnage)), accept packets - 0) +// Follow recommendation from https://e2e.ti.com/support/wireless_connectivity/bluetooth_cc256x/f/660/t/397004 +// route SCO over HCI (connection type=1, tx buffer size = 120, tx buffer max latency= 720, accept packets with CRC Error static const uint8_t hci_route_sco_over_hci[] = { - 0x10, 0xfe, 0x05, 0x01, 0x00, 0x00, 0x00, 0x00 + 0x10, 0xfe, 0x05, 0x01, 0x78, 0xd0, 0x02, 0x01, }; #endif From 483c50788b3c8c2f67b26032efb11fa77cad2be6 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Fri, 20 May 2016 14:26:48 +0200 Subject: [PATCH 5/6] hci: enable Default Erroneous Data Reporting for SCO over HCI --- src/hci.c | 9 +++++++-- src/hci.h | 2 ++ src/hci_cmd.c | 8 ++++++++ src/hci_cmd.h | 1 + 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/hci.c b/src/hci.c index 3aa22a97c..d0089a19f 100644 --- a/src/hci.c +++ b/src/hci.c @@ -1074,10 +1074,15 @@ static void hci_initializing_run(void){ hci_send_cmd(&hci_write_scan_enable, (hci_stack->connectable << 1) | hci_stack->discoverable); // page scan hci_stack->substate = HCI_INIT_W4_WRITE_SCAN_ENABLE; break; + // only sent if ENABLE_SCO_OVER_HCI is defined case HCI_INIT_WRITE_SYNCHRONOUS_FLOW_CONTROL_ENABLE: hci_stack->substate = HCI_INIT_W4_WRITE_SYNCHRONOUS_FLOW_CONTROL_ENABLE; hci_send_cmd(&hci_write_synchronous_flow_control_enable, 1); // SCO tracking enabled break; + case HCI_INIT_WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING: + hci_stack->substate = HCI_INIT_W4_WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING; + hci_send_cmd(&hci_write_default_erroneous_data_reporting, 1); + break; #ifdef ENABLE_BLE // LE INIT case HCI_INIT_LE_READ_BUFFER_SIZE: @@ -1323,9 +1328,9 @@ static void hci_initializing_event_handler(uint8_t * packet, uint16_t size){ #ifdef ENABLE_SCO_OVER_HCI case HCI_INIT_W4_WRITE_SCAN_ENABLE: - // just go to next state - break; case HCI_INIT_W4_WRITE_SYNCHRONOUS_FLOW_CONTROL_ENABLE: + break; + case HCI_INIT_WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING: if (!hci_le_supported()){ // SKIP LE init for Classic only configuration hci_init_done(); diff --git a/src/hci.h b/src/hci.h index ce9b15265..1edf83512 100644 --- a/src/hci.h +++ b/src/hci.h @@ -457,6 +457,8 @@ typedef enum hci_init_state{ HCI_INIT_WRITE_SYNCHRONOUS_FLOW_CONTROL_ENABLE, HCI_INIT_W4_WRITE_SYNCHRONOUS_FLOW_CONTROL_ENABLE, + HCI_INIT_WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING, + HCI_INIT_W4_WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING, HCI_INIT_LE_READ_BUFFER_SIZE, HCI_INIT_W4_LE_READ_BUFFER_SIZE, diff --git a/src/hci_cmd.c b/src/hci_cmd.c index 36bfd05ab..247cbb675 100644 --- a/src/hci_cmd.c +++ b/src/hci_cmd.c @@ -656,6 +656,14 @@ const hci_cmd_t hci_write_simple_pairing_mode = { OPCODE(OGF_CONTROLLER_BASEBAND, 0x56), "1" }; + +/** + * @param mode (0 = off, 1 = on) + */ +const hci_cmd_t hci_write_default_erroneous_data_reporting = { +OPCODE(OGF_CONTROLLER_BASEBAND, 0x5B), "1" +}; + /** */ const hci_cmd_t hci_read_le_host_supported = { diff --git a/src/hci_cmd.h b/src/hci_cmd.h index 16eda89d2..28ac366b7 100644 --- a/src/hci_cmd.h +++ b/src/hci_cmd.h @@ -134,6 +134,7 @@ extern const hci_cmd_t hci_user_passkey_request_negative_reply; extern const hci_cmd_t hci_user_passkey_request_reply; extern const hci_cmd_t hci_write_authentication_enable; extern const hci_cmd_t hci_write_class_of_device; +extern const hci_cmd_t hci_write_default_erroneous_data_reporting; extern const hci_cmd_t hci_write_extended_inquiry_response; extern const hci_cmd_t hci_write_inquiry_mode; extern const hci_cmd_t hci_write_le_host_supported; From db7b6733b7bdff335ec3fb76cbd1151e8f0610ba Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Fri, 20 May 2016 22:08:13 +0200 Subject: [PATCH 6/6] bnep: provide bnep_cid in packet handler for BNEP_DATA_PACKET --- src/classic/bnep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/classic/bnep.c b/src/classic/bnep.c index 3617663fc..1665f6745 100644 --- a/src/classic/bnep.c +++ b/src/classic/bnep.c @@ -1090,7 +1090,7 @@ 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->uuid_source, + (*app_packet_handler)(BNEP_DATA_PACKET, channel->l2cap_cid, ethernet_packet, size + sizeof(uint16_t) + 2 * sizeof(bd_addr_t)); return size;