1d5814ca7SMatthias Ringwald#!/usr/bin/env python 2d5814ca7SMatthias Ringwald# BlueKitchen GmbH (c) 2012-2014 3d5814ca7SMatthias Ringwald 4d5814ca7SMatthias Ringwald# documentation for TI Vendor Specific commands: 5d5814ca7SMatthias Ringwald# http://processors.wiki.ti.com/index.php/CC256x_VS_HCI_Commands 6d5814ca7SMatthias Ringwald 7d5814ca7SMatthias Ringwaldimport glob 8d5814ca7SMatthias Ringwaldimport re 9d5814ca7SMatthias Ringwaldimport sys 10d5814ca7SMatthias Ringwaldimport os 11d5814ca7SMatthias Ringwald 12f55dd2adSMatthias Ringwaldprint(''' 13d5814ca7SMatthias RingwaldCC256x init script conversion tool for use with BTstack, v0.1 14d5814ca7SMatthias RingwaldCopyright 2012-2014 BlueKitchen GmbH 15f55dd2adSMatthias Ringwald''') 16d5814ca7SMatthias Ringwald 17c4054521SMatthias Ringwaldusage = '''This script prepares init scripts for TI's 18d5814ca7SMatthias RingwaldCC256x chipsets for use with BTstack . 19d5814ca7SMatthias Ringwald 20d5814ca7SMatthias RingwaldPlease download the Service Pack for your module from http://processors.wiki.ti.com/index.php/CC256x_Downloads 21d5814ca7SMatthias RingwaldThen, unzip it and copy the *.bts file into this folder and start the script again. 22d5814ca7SMatthias Ringwald''' 23d5814ca7SMatthias Ringwald 24d5814ca7SMatthias Ringwaldfartext = ''' 25d5814ca7SMatthias Ringwald#if defined(__GNUC__) && defined(__MSP430X__) && (__MSP430X__ > 0) 26d5814ca7SMatthias Ringwald__attribute__((section (".fartext"))) 27d5814ca7SMatthias Ringwald#endif 28d5814ca7SMatthias Ringwald#ifdef __AVR__ 29d5814ca7SMatthias Ringwald__attribute__((__progmem__)) 30d5814ca7SMatthias Ringwald#endif 31d5814ca7SMatthias Ringwald''' 32d5814ca7SMatthias Ringwald 33d5814ca7SMatthias Ringwalddata_indent = ' ' 34d5814ca7SMatthias Ringwald 35d5814ca7SMatthias Ringwalddef read_little_endian_16(f): 36d5814ca7SMatthias Ringwald low = f.read(1) 37f55dd2adSMatthias Ringwald if len(low) == 0: 38d5814ca7SMatthias Ringwald return -1 39d5814ca7SMatthias Ringwald high = f.read(1) 40d5814ca7SMatthias Ringwald return ord(high) << 8 | ord(low) 41d5814ca7SMatthias Ringwald 42d5814ca7SMatthias Ringwalddef append_power_vector_gfsk(additions, str_list, data_indent): 43d5814ca7SMatthias Ringwald additions.append("- added HCI_VS_SET_POWER_VECTOR(GFSK) template") 44d5814ca7SMatthias Ringwald str_list.append(data_indent) 45d5814ca7SMatthias Ringwald str_list.append('// BTstack: added HCI_VS_SET_POWER_VECTOR(GFSK) 0xFD82 template\n'); 46d5814ca7SMatthias Ringwald str_list.append(data_indent) 47d5814ca7SMatthias Ringwald str_list.append("0x01, 0x82, 0xfd, 0x14, 0x00, 0x9c, 0x18, 0xd2, 0xd2, 0xd2, 0xd2, 0xd2, 0xd2, 0xd2, 0xdc,\n"); 48d5814ca7SMatthias Ringwald str_list.append(data_indent) 49d5814ca7SMatthias Ringwald str_list.append("0xe6, 0xf0, 0xfa, 0x04, 0x0e, 0x18, 0xff, 0x00, 0x00,\n\n"); 50c4054521SMatthias Ringwald return 24 51d5814ca7SMatthias Ringwald 52d5814ca7SMatthias Ringwalddef append_power_vector_edr2(additions, str_list, data_indent): 53d5814ca7SMatthias Ringwald additions.append("- added HCI_VS_SET_POWER_VECTOR(EDR2) template") 54d5814ca7SMatthias Ringwald str_list.append(data_indent) 55d5814ca7SMatthias Ringwald str_list.append('// BTstack: added HCI_VS_SET_POWER_VECTOR(EDR2) 0xFD82 template\n'); 56d5814ca7SMatthias Ringwald str_list.append(data_indent) 57d5814ca7SMatthias Ringwald str_list.append("0x01, 0x82, 0xfd, 0x14, 0x01, 0x9c, 0xce, 0xce, 0xce, 0xce, 0xce, 0xce, 0xce, 0xce, 0xd8, \n"); 58d5814ca7SMatthias Ringwald str_list.append(data_indent) 59d5814ca7SMatthias Ringwald str_list.append("0xe2, 0xec, 0xf6, 0x00, 0x0a, 0x14, 0xff, 0x00, 0x00,\n\n"); 60c4054521SMatthias Ringwald return 24 61d5814ca7SMatthias Ringwald 62d5814ca7SMatthias Ringwalddef append_power_vector_edr3(additions, str_list, data_indent): 63d5814ca7SMatthias Ringwald additions.append("- added HCI_VS_SET_POWER_VECTOR(EDR3) template") 64d5814ca7SMatthias Ringwald str_list.append(data_indent) 65d5814ca7SMatthias Ringwald str_list.append('// BTstack: added HCI_VS_SET_POWER_VECTOR(EDR3) 0xFD82 for EDR3 template\n'); 66d5814ca7SMatthias Ringwald str_list.append(data_indent) 67d5814ca7SMatthias Ringwald str_list.append("0x01, 0x82, 0xfd, 0x14, 0x02, 0x9c, 0xce, 0xce, 0xce, 0xce, 0xce, 0xce, 0xce, 0xce, 0xd8,\n"); 68d5814ca7SMatthias Ringwald str_list.append(data_indent) 69d5814ca7SMatthias Ringwald str_list.append("0xe2, 0xec, 0xf6, 0x00, 0x0a, 0x14, 0xff, 0x00, 0x00,\n\n"); 70c4054521SMatthias Ringwald return 24 71d5814ca7SMatthias Ringwald 72d5814ca7SMatthias Ringwalddef append_class2_single_power(additions, str_list, data_indent): 73d5814ca7SMatthias Ringwald additions.append("- added HCI_VS_SET_CLASS2_SINGLE_POWER template") 74d5814ca7SMatthias Ringwald str_list.append(data_indent) 75d5814ca7SMatthias Ringwald str_list.append('// BTstack: added HCI_VS_SET_CLASS2_SINGLE_POWER 0xFD87 template\n'); 76d5814ca7SMatthias Ringwald str_list.append(data_indent) 77d5814ca7SMatthias Ringwald str_list.append("0x01, 0x87, 0xfd, 0x03, 0x0d, 0x0d, 0x0d,\n\n"); 78d5814ca7SMatthias Ringwald return 7 79d5814ca7SMatthias Ringwald 80d5814ca7SMatthias Ringwalddef append_ehcill(additions, str_list, data_indent): 81d5814ca7SMatthias Ringwald additions.append("- added eHCILL template") 82d5814ca7SMatthias Ringwald str_list.append('\n') 83d5814ca7SMatthias Ringwald str_list.append(data_indent) 84d5814ca7SMatthias Ringwald str_list.append('// BTstack: added HCI_VS_Sleep_Mode_Configurations 0xFD0C template for eHCILL\n'); 85d5814ca7SMatthias Ringwald str_list.append(data_indent) 86d5814ca7SMatthias Ringwald str_list.append('0x01, 0x0c, 0xfd, 9 , 1, 0, 0, 0xff, 0xff, 0xff, 0xff, 100, 0,\n\n'); 87d5814ca7SMatthias Ringwald return 13 88d5814ca7SMatthias Ringwald 89d5814ca7SMatthias Ringwalddef append_calibration_sequence(additions, str_list, data_indent): 90d5814ca7SMatthias Ringwald additions.append("- added calibration sequence") 91d5814ca7SMatthias Ringwald str_list.append(data_indent) 92d5814ca7SMatthias Ringwald str_list.append("// BTstack: added calibration sequence\n") 93d5814ca7SMatthias Ringwald str_list.append(data_indent) 94d5814ca7SMatthias Ringwald str_list.append("0x01, 0x80, 0xfd, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,\n") 95d5814ca7SMatthias Ringwald str_list.append(data_indent) 96d5814ca7SMatthias Ringwald str_list.append("0x01, 0x80, 0xfd, 0x06, 0x3c, 0xf0, 0x5f, 0x00, 0x00, 0x00,\n\n") 97d5814ca7SMatthias Ringwald return 20 98d5814ca7SMatthias Ringwald 99*73ff2b1cSMatthias Ringwalddef convert_bts(main_bts_file, bts_add_on, aka, lmp_subversion): 100d5814ca7SMatthias Ringwald array_name = 'cc256x' 101d5814ca7SMatthias Ringwald c_file = main_bts_file.replace('bts', 'c') 102d5814ca7SMatthias Ringwald 103d5814ca7SMatthias Ringwald input_files = [ main_bts_file ] 104d5814ca7SMatthias Ringwald if bts_add_on != "": 105d5814ca7SMatthias Ringwald input_files.append(bts_add_on) 106d5814ca7SMatthias Ringwald 107d5814ca7SMatthias Ringwald with open(c_file, 'w') as fout: 108d5814ca7SMatthias Ringwald 109d5814ca7SMatthias Ringwald # assert script contains templates for configuration by BTstack 110d5814ca7SMatthias Ringwald have_eHCILL = False 111d5814ca7SMatthias Ringwald have_power_vector_gfsk = False; 112d5814ca7SMatthias Ringwald have_power_vector_edr2 = False; 113d5814ca7SMatthias Ringwald have_power_vector_edr3 = False; 114d5814ca7SMatthias Ringwald have_class2_single_power = False; 115d5814ca7SMatthias Ringwald 116f55dd2adSMatthias Ringwald print("Creating {0}".format(c_file)) 117d5814ca7SMatthias Ringwald 118d5814ca7SMatthias Ringwald part_size = 0 119d5814ca7SMatthias Ringwald 120d5814ca7SMatthias Ringwald parts = 0 121d5814ca7SMatthias Ringwald str_list = [] 122d5814ca7SMatthias Ringwald part_strings = [] 123d5814ca7SMatthias Ringwald part_sizes = [] 124d5814ca7SMatthias Ringwald additions = [] 125d5814ca7SMatthias Ringwald 126d5814ca7SMatthias Ringwald for bts_file in input_files: 127d5814ca7SMatthias Ringwald 128d5814ca7SMatthias Ringwald with open (bts_file, 'rb') as fin: 129d5814ca7SMatthias Ringwald 130f55dd2adSMatthias Ringwald print("- parsing {0:32}".format(bts_file)) 131d5814ca7SMatthias Ringwald 132d5814ca7SMatthias Ringwald header = fin.read(32) 133f55dd2adSMatthias Ringwald if header[0:4].decode('ascii') != 'BTSB': 134f55dd2adSMatthias Ringwald print('Error', bts_file, 'is not a valid .BTS file') 135d5814ca7SMatthias Ringwald sys.exit(1) 136d5814ca7SMatthias Ringwald 137d5814ca7SMatthias Ringwald 138d5814ca7SMatthias Ringwald while True: 139d5814ca7SMatthias Ringwald action_type = read_little_endian_16(fin) 140d5814ca7SMatthias Ringwald action_size = read_little_endian_16(fin) 141f55dd2adSMatthias Ringwald action_data = bytearray(fin.read(action_size)) 142d5814ca7SMatthias Ringwald 143d5814ca7SMatthias Ringwald if (action_type == 1): # hci command 144d5814ca7SMatthias Ringwald 145f55dd2adSMatthias Ringwald opcode = (action_data[2] << 8) | action_data[1] 146d5814ca7SMatthias Ringwald if opcode == 0xFF36: 147d5814ca7SMatthias Ringwald continue # skip baud rate command 148d5814ca7SMatthias Ringwald if opcode == 0xFD0C: 149d5814ca7SMatthias Ringwald have_eHCILL = True 150d5814ca7SMatthias Ringwald if opcode == 0xFD82: 151a3fe55ccSMatthias Ringwald modulation_type = action_data[4] 152d5814ca7SMatthias Ringwald if modulation_type == 0: 153d5814ca7SMatthias Ringwald have_power_vector_gfsk = True 154d5814ca7SMatthias Ringwald elif modulation_type == 1: 155d5814ca7SMatthias Ringwald have_power_vector_edr2 + True 156d5814ca7SMatthias Ringwald elif modulation_type == 2: 157d5814ca7SMatthias Ringwald have_power_vector_edr3 = True 158d5814ca7SMatthias Ringwald if opcode == 0xFD80: 159d5814ca7SMatthias Ringwald # add missing power command templates 160d5814ca7SMatthias Ringwald if not have_power_vector_gfsk: 161d5814ca7SMatthias Ringwald part_size += append_power_vector_gfsk(additions, str_list, data_indent) 162d5814ca7SMatthias Ringwald have_power_vector_gfsk = True; 163d5814ca7SMatthias Ringwald if not have_power_vector_edr2: 164d5814ca7SMatthias Ringwald part_size += append_power_vector_edr2(additions, str_list, data_indent) 165d5814ca7SMatthias Ringwald have_power_vector_edr2 = True; 166d5814ca7SMatthias Ringwald if not have_power_vector_edr3: 167d5814ca7SMatthias Ringwald part_size += append_power_vector_edr2(additions, str_list, data_indent) 168d5814ca7SMatthias Ringwald have_power_vector_edr3 = True; 169d5814ca7SMatthias Ringwald if not have_class2_single_power: 170d5814ca7SMatthias Ringwald part_size += append_class2_single_power(additions, str_list, data_indent) 171d5814ca7SMatthias Ringwald have_class2_single_power = True; 172d5814ca7SMatthias Ringwald 173d5814ca7SMatthias Ringwald counter = 0 174d5814ca7SMatthias Ringwald str_list.append(data_indent) 175d5814ca7SMatthias Ringwald for byte in action_data: 176f55dd2adSMatthias Ringwald str_list.append("0x{0:02x}, ".format(byte)) 177d5814ca7SMatthias Ringwald counter = counter + 1 178d5814ca7SMatthias Ringwald if (counter != 15): 179d5814ca7SMatthias Ringwald continue 180d5814ca7SMatthias Ringwald counter = 0 181d5814ca7SMatthias Ringwald str_list.append("\n") 182d5814ca7SMatthias Ringwald str_list.append(data_indent) 183d5814ca7SMatthias Ringwald str_list.append("\n\n") 184d5814ca7SMatthias Ringwald 185d5814ca7SMatthias Ringwald part_size = part_size + action_size 186d5814ca7SMatthias Ringwald 187d5814ca7SMatthias Ringwald # 30 kB chunks 188d5814ca7SMatthias Ringwald if part_size < 30 * 1024: 189d5814ca7SMatthias Ringwald continue 190d5814ca7SMatthias Ringwald 191d5814ca7SMatthias Ringwald part_strings.append(''.join(str_list)) 192d5814ca7SMatthias Ringwald part_sizes.append(part_size) 193d5814ca7SMatthias Ringwald parts += 1 194d5814ca7SMatthias Ringwald 195d5814ca7SMatthias Ringwald str_list = [] 196d5814ca7SMatthias Ringwald part_size = 0 197d5814ca7SMatthias Ringwald 198d5814ca7SMatthias Ringwald if (action_type == 6): # comment 199f55dd2adSMatthias Ringwald action_data = action_data.decode('ascii').rstrip('\0') 200d5814ca7SMatthias Ringwald str_list.append(data_indent) 201d5814ca7SMatthias Ringwald str_list.append("// " + action_data + "\n") 202d5814ca7SMatthias Ringwald 203d5814ca7SMatthias Ringwald if (action_type < 0): # EOF 204d5814ca7SMatthias Ringwald break; 205d5814ca7SMatthias Ringwald 206d5814ca7SMatthias Ringwald 207d5814ca7SMatthias Ringwald if not have_eHCILL: 208d5814ca7SMatthias Ringwald part_size += append_ehcill(additions, str_list, data_indent) 209d5814ca7SMatthias Ringwald 210d5814ca7SMatthias Ringwald # append calibration step, if missing so far 211d5814ca7SMatthias Ringwald all_power_commands_provided = have_power_vector_gfsk and have_power_vector_edr2 and have_power_vector_edr3 and have_class2_single_power 212d5814ca7SMatthias Ringwald if not all_power_commands_provided: 213d5814ca7SMatthias Ringwald str_list.append("\n" + data_indent + "// BTstack: no calibration sequence found, adding power commands and calibration\n\n") 214d5814ca7SMatthias Ringwald part_size += append_power_vector_gfsk(additions, str_list, data_indent) 215d5814ca7SMatthias Ringwald part_size += append_power_vector_edr2(additions, str_list, data_indent) 216d5814ca7SMatthias Ringwald part_size += append_power_vector_edr2(additions, str_list, data_indent) 217d5814ca7SMatthias Ringwald part_size += append_class2_single_power(additions, str_list, data_indent) 218d5814ca7SMatthias Ringwald part_size += append_calibration_sequence(additions, str_list, data_indent) 219d5814ca7SMatthias Ringwald 220d5814ca7SMatthias Ringwald part_strings.append(''.join(str_list)) 221d5814ca7SMatthias Ringwald part_sizes.append(part_size) 222d5814ca7SMatthias Ringwald parts += 1 223d5814ca7SMatthias Ringwald 224d5814ca7SMatthias Ringwald fout.write( '// init script created from\n') 225d5814ca7SMatthias Ringwald fout.write( '// - {0}\n'.format(main_bts_file)) 2266ab4420aSMatthias Ringwald if aka != "": 2276ab4420aSMatthias Ringwald fout.write( '// - AKA TIInit_{0}.bts\n'.format(aka)) 228d5814ca7SMatthias Ringwald if bts_add_on != "": 229d5814ca7SMatthias Ringwald fout.write( '// - {0}\n'.format(bts_add_on)) 230d5814ca7SMatthias Ringwald fout.write( '#include <stdint.h>\n') 2316ab4420aSMatthias Ringwald fout.write( '\n') 2326ab4420aSMatthias Ringwald # if aka != "": 2336ab4420aSMatthias Ringwald # fout.write( 'const char * {0}_init_script_aka = "{1}";\n'.format(array_name, aka)) 234*73ff2b1cSMatthias Ringwald if lmp_subversion != 0: 235*73ff2b1cSMatthias Ringwald fout.write( 'const uint16_t %s_init_script_lmp_subversion = 0x%04x;\n' % (array_name, lmp_subversion)) 236d5814ca7SMatthias Ringwald part = 0 237d5814ca7SMatthias Ringwald size = 0 238d5814ca7SMatthias Ringwald for part_size in part_sizes: 239d5814ca7SMatthias Ringwald part += 1 240d5814ca7SMatthias Ringwald size += part_size 24169316fe8SMatthias Ringwald print("- part %u, size %u" % (part,part_size)) 242d5814ca7SMatthias Ringwald 24369316fe8SMatthias Ringwald print('- total size %u' % size) 244d5814ca7SMatthias Ringwald 245f55dd2adSMatthias Ringwald print("\n".join(additions)) 246d5814ca7SMatthias Ringwald 247d5814ca7SMatthias Ringwald 248d5814ca7SMatthias Ringwald part = 0 249d5814ca7SMatthias Ringwald for part_text in part_strings: 250d5814ca7SMatthias Ringwald part += 1 251d5814ca7SMatthias Ringwald suffix = '' 252d5814ca7SMatthias Ringwald 253d5814ca7SMatthias Ringwald if part == 1: 254d5814ca7SMatthias Ringwald fout.write( fartext ) 255d5814ca7SMatthias Ringwald 256d5814ca7SMatthias Ringwald if (part > 1): 257d5814ca7SMatthias Ringwald suffix = '_{0}'.format(part) 258d5814ca7SMatthias Ringwald fout.write('#if defined(__GNUC__) && defined(__GNUC__) && (__MSP430X__ > 0)\n') 259d5814ca7SMatthias Ringwald fout.write('};\n') 260d5814ca7SMatthias Ringwald fout.write('__attribute__((section (".fartext")))\n') 261d5814ca7SMatthias Ringwald 262d5814ca7SMatthias Ringwald fout.write('const uint8_t {0}_init_script{1}[] = {2}\n\n'.format(array_name, suffix, '{')) 263d5814ca7SMatthias Ringwald 264d5814ca7SMatthias Ringwald if (part > 1): 265d5814ca7SMatthias Ringwald fout.write('#endif\n') 266d5814ca7SMatthias Ringwald 267d5814ca7SMatthias Ringwald fout.write(part_text) 268d5814ca7SMatthias Ringwald 269d5814ca7SMatthias Ringwald 270d5814ca7SMatthias Ringwald fout.write('};\n\n') 271d5814ca7SMatthias Ringwald 272d5814ca7SMatthias Ringwald fout.write('const uint32_t {0}_init_script_size = {1};\n\n'.format(array_name,size)); 273d5814ca7SMatthias Ringwald # fout.write('void main() {0} printf("size {1}\\n", {2}_init_script_size); {3}'.format('{', '%u', array_name,'}')); 274d5814ca7SMatthias Ringwald 275d5814ca7SMatthias Ringwald# get list of *.bts files 276d5814ca7SMatthias Ringwaldfiles = glob.glob('*.bts') 277d5814ca7SMatthias Ringwaldif not files: 278f55dd2adSMatthias Ringwald print(usage) 279d5814ca7SMatthias Ringwald sys.exit(1) 280d5814ca7SMatthias Ringwald 281d5814ca7SMatthias Ringwald# convert each of them 282d5814ca7SMatthias Ringwaldfor name in files: 283d5814ca7SMatthias Ringwald name_lower = name.lower() 284d5814ca7SMatthias Ringwald # skip BLE and AVRP add-ons 285d5814ca7SMatthias Ringwald if name_lower.startswith('ble_init_cc'): 28669316fe8SMatthias Ringwald print("Skipping BLE add-on " + name) 287d5814ca7SMatthias Ringwald continue 288d5814ca7SMatthias Ringwald if name_lower.startswith('avpr_init_cc'): 28969316fe8SMatthias Ringwald print("Skipping AVPR add-on " + name) 290d5814ca7SMatthias Ringwald continue 291edc52946SMatthias Ringwald if re.match("tiinit_.*_ble_add-on.bts", name_lower): 29269316fe8SMatthias Ringwald print("Skipping BLE add-on " + name) 293edc52946SMatthias Ringwald continue 294d5814ca7SMatthias Ringwald if re.match("initscripts_tiinit_.*_ble_add-on.bts", name_lower): 29569316fe8SMatthias Ringwald print("Skipping BLE add-on " + name) 296d5814ca7SMatthias Ringwald continue 297d5814ca7SMatthias Ringwald if re.match("initscripts_tiinit_.*_avpr_add-on.bts", name_lower): 29869316fe8SMatthias Ringwald print("Skipping AVPR add-on " + name) 29969316fe8SMatthias Ringwald continue 30069316fe8SMatthias Ringwald if re.match("initscripts_tiinit.*", name_lower): 30169316fe8SMatthias Ringwald print("Skipping " + name) 30269316fe8SMatthias Ringwald continue 30369316fe8SMatthias Ringwald if re.match("initscripts-tiinit_.*_ble_add-on.bts", name_lower): 30469316fe8SMatthias Ringwald print("Skipping BLE add-on " + name) 30569316fe8SMatthias Ringwald continue 30669316fe8SMatthias Ringwald if re.match("initscripts-tiinit_.*_avpr_add-on.bts", name_lower): 30769316fe8SMatthias Ringwald print("Skipping AVPR add-on " + name) 30869316fe8SMatthias Ringwald continue 30969316fe8SMatthias Ringwald if re.match("initscripts-tiinit.*", name_lower): 31069316fe8SMatthias Ringwald print("Skipping " + name) 311f55dd2adSMatthias Ringwald continue 312d5814ca7SMatthias Ringwald 3136ab4420aSMatthias Ringwald 314439b93a1SMatthias Ringwald print ("\nMain script " + name) 315edc52946SMatthias Ringwald 3166ab4420aSMatthias Ringwald # set AKA and lmp subversion 3176ab4420aSMatthias Ringwald aka = "" 3186ab4420aSMatthias Ringwald lmp_subversion = 0 3196ab4420aSMatthias Ringwald if name_lower == "bluetooth_init_cc2560_2.44.bts": 3206ab4420aSMatthias Ringwald aka = "6.2.31" 3216ab4420aSMatthias Ringwald if name_lower == "bluetooth_init_cc2560a_2.14.bts": 3226ab4420aSMatthias Ringwald aka = "6.6.15" 3236ab4420aSMatthias Ringwald if name_lower == "bluetooth_init_cc2564_2.14.bts": 3246ab4420aSMatthias Ringwald aka = "6.6.15" 3256ab4420aSMatthias Ringwald if name_lower == "bluetooth_init_cc2560b_1.2_bt_spec_4.1.bts": 3266ab4420aSMatthias Ringwald aka = "6.7.16" 3276ab4420aSMatthias Ringwald if name_lower == "bluetooth_init_cc2564b_1.2_bt_spec_4.1.bts": 3286ab4420aSMatthias Ringwald aka = "6.7.16" 3296ab4420aSMatthias Ringwald if name_lower == "bluetooth_init_cc2560b_1.4_bt_spec_4.1.bts": 3306ab4420aSMatthias Ringwald aka = "6.7.16" 3316ab4420aSMatthias Ringwald if name_lower == "bluetooth_init_cc2564b_1.4_bt_spec_4.1.bts": 3326ab4420aSMatthias Ringwald aka = "6.7.16" 3336ab4420aSMatthias Ringwald if name_lower == "bluetooth_init_cc2560b_1.5_bt_spec_4.1.bts": 3346ab4420aSMatthias Ringwald aka = "6.7.16" 3356ab4420aSMatthias Ringwald if name_lower == "bluetooth_init_cc2564b_1.5_bt_spec_4.1.bts": 3366ab4420aSMatthias Ringwald aka = "6.7.16" 3376ab4420aSMatthias Ringwald 3386ab4420aSMatthias Ringwald if name_lower == "bluetooth_init_cc2560c_1.0.bts": 3396ab4420aSMatthias Ringwald aka = "6.12.26" 3406ab4420aSMatthias Ringwald if name_lower == "bluetooth_init_cc2564c_1.0.bts": 3416ab4420aSMatthias Ringwald aka = "6.12.26" 3426ab4420aSMatthias Ringwald 343d5814ca7SMatthias Ringwald # check for BLE add-on 344d5814ca7SMatthias Ringwald add_on = "" 34569316fe8SMatthias Ringwald name_parts = re.match('bluetooth_init_(.....+_...).*.bts', name) 346d5814ca7SMatthias Ringwald if name_parts: 347d5814ca7SMatthias Ringwald potential_add_on = 'BLE_init_%s.bts' % name_parts.group(1) 348d5814ca7SMatthias Ringwald if os.path.isfile(potential_add_on): 349d5814ca7SMatthias Ringwald add_on = potential_add_on 350d5814ca7SMatthias Ringwald 3516ab4420aSMatthias Ringwald name_parts = re.match('TIInit_(\d*\.\d*\.\d*).*.bts', name) 352edc52946SMatthias Ringwald if name_parts: 3536ab4420aSMatthias Ringwald aka = name_parts.group(1) 3546ab4420aSMatthias Ringwald potential_add_on = 'TIInit_%s_ble_add-on.bts' % aka 355edc52946SMatthias Ringwald if os.path.isfile(potential_add_on): 356edc52946SMatthias Ringwald add_on = potential_add_on 357edc52946SMatthias Ringwald 358d5814ca7SMatthias Ringwald name_parts = re.match('initscripts_TIInit_(\d*\.\d*\.\d*)_.*.bts', name) 359d5814ca7SMatthias Ringwald if name_parts: 3606ab4420aSMatthias Ringwald aka = name_parts.group(1) 3616ab4420aSMatthias Ringwald potential_add_on = 'initscripts_TIInit_%s_ble_add-on.bts' % aka 362d5814ca7SMatthias Ringwald if os.path.isfile(potential_add_on): 363d5814ca7SMatthias Ringwald add_on = potential_add_on 364d5814ca7SMatthias Ringwald 36569316fe8SMatthias Ringwald name_parts = re.match('initscripts-TIInit_(\d*\.\d*\.\d*).*.bts', name) 36669316fe8SMatthias Ringwald if name_parts: 3676ab4420aSMatthias Ringwald aka = name_parts.group(1) 3686ab4420aSMatthias Ringwald potential_add_on = 'initscripts-TIInit_%s_ble_add-on.bts' % aka 36969316fe8SMatthias Ringwald if os.path.isfile(potential_add_on): 37069316fe8SMatthias Ringwald add_on = potential_add_on 37169316fe8SMatthias Ringwald 3726ab4420aSMatthias Ringwald if aka != "": 3736ab4420aSMatthias Ringwald print ("- AKA TIInit_%s.bts" % aka) 3746ab4420aSMatthias Ringwald 375*73ff2b1cSMatthias Ringwald # map aka to lmp sub revision number 376*73ff2b1cSMatthias Ringwald if aka == "6.2.31": 377*73ff2b1cSMatthias Ringwald lmp_subversion = 0x191f 378*73ff2b1cSMatthias Ringwald if aka == "6.6.15": 379*73ff2b1cSMatthias Ringwald lmp_subversion = 0x1B0F 380*73ff2b1cSMatthias Ringwald if aka == "6.7.16": 381*73ff2b1cSMatthias Ringwald lmp_subversion = 0x1B90 382*73ff2b1cSMatthias Ringwald if aka == "6.12.26": 383*73ff2b1cSMatthias Ringwald lmp_subversion = 0x9a1a 384*73ff2b1cSMatthias Ringwald if lmp_subversion: 385*73ff2b1cSMatthias Ringwald print ("- LMP Subversion: 0x%04x" % lmp_subversion) 386*73ff2b1cSMatthias Ringwald else: 387*73ff2b1cSMatthias Ringwald print ("- LMP Subversion: Unknown") 388*73ff2b1cSMatthias Ringwald 38969316fe8SMatthias Ringwald if add_on != "": 390*73ff2b1cSMatthias Ringwald print("+ Add-on " + add_on) 39169316fe8SMatthias Ringwald 39269316fe8SMatthias Ringwald print("--------") 393*73ff2b1cSMatthias Ringwald convert_bts(name, add_on, aka, lmp_subversion) 39469316fe8SMatthias Ringwald print 395d5814ca7SMatthias Ringwald 396d5814ca7SMatthias Ringwald# done 397f55dd2adSMatthias Ringwaldprint('\nConversion(s) successful!\n') 398d5814ca7SMatthias Ringwald 399d5814ca7SMatthias Ringwald 400d5814ca7SMatthias Ringwald 401