1#!/usr/bin/env python3 2# BlueKitchen GmbH (c) 2019 3 4# primitive dump for PacketLogger format 5 6# APPLE PacketLogger 7# typedef struct { 8# uint32_t len; 9# uint32_t ts_sec; 10# uint32_t ts_usec; 11# uint8_t type; // 0xfc for note 12# } 13 14#define BLUETOOTH_DATA_TYPE_PB_ADV 0x29 // PB-ADV 15#define BLUETOOTH_DATA_TYPE_MESH_MESSAGE 0x2A // Mesh Message 16#define BLUETOOTH_DATA_TYPE_MESH_BEACON 0x2B // Mesh Beacon 17 18import re 19import sys 20import time 21import datetime 22import struct 23from mesh_crypto import * 24 25# state 26netkeys = {} 27appkeys = {} 28devkey = b'' 29ivi = b'\x00' 30segmented_messages = {} 31 32access_messages = { 33# Foundation 340x0000: 'Config Appkey Add', 350x0001: 'Config Appkey Update', 360x0002: 'Config Composition Data Status', 370x0003: 'Config Model Publication Set', 380x0004: 'Config Health Current Status', 390x0005: 'Config Health Fault Status', 400x0006: 'Config Heartbeat Publication Status', 410x8000: 'Config Appkey Delete', 420x8001: 'Config Appkey Get', 430x8002: 'Config Appkey List', 440x8003: 'Config Appkey Status', 450x8004: 'Config Health Attention Get', 460x8005: 'Config Health Attention Set', 470x8006: 'Config Health Attention Set Unacknowledged', 480x8007: 'Config Health Attention Status', 490x8008: 'Config Composition Data Get', 500x8009: 'Config Beacon Get', 510x800a: 'Config Beacon Set', 520x800b: 'Config Beacon Status', 530x800c: 'Config Default Ttl Get', 540x800d: 'Config Default Ttl Set', 550x800e: 'Config Default Ttl Status', 560x800f: 'Config Friend Get', 570x8010: 'Config Friend Set', 580x8011: 'Config Friend Status', 590x8012: 'Config Gatt Proxy Get', 600x8013: 'Config Gatt Proxy Set', 610x8014: 'Config Gatt Proxy Status', 620x8015: 'Config Key Refresh Phase Get', 630x8016: 'Config Key Refresh Phase Set', 640x8017: 'Config Key Refresh Phase Status', 650x8018: 'Config Model Publication Get', 660x8019: 'Config Model Publication Status', 670x801a: 'Config Model Publication Virtual Address Set', 680x801b: 'Config Model Subscription Add', 690x801c: 'Config Model Subscription Delete', 700x801d: 'Config Model Subscription Delete All', 710x801e: 'Config Model Subscription Overwrite', 720x801f: 'Config Model Subscription Status', 730x8020: 'Config Model Subscription Virtual Address Add', 740x8021: 'Config Model Subscription Virtual Address Delete', 750x8022: 'Config Model Subscription Virtual Address Overwrite', 760x8023: 'Config Network Transmit Get', 770x8024: 'Config Network Transmit Set', 780x8025: 'Config Network Transmit Status', 790x8026: 'Config Relay Get', 800x8027: 'Config Relay Set', 810x8028: 'Config Relay Status', 820x8029: 'Config Sig Model Subscription Get', 830x802a: 'Config Sig Model Subscription List', 840x802b: 'Config Vendor Model Subscription Get', 850x802c: 'Config Vendor Model Subscription List', 860x802d: 'Config Low Power Node Poll Timeout Get', 870x802e: 'Config Low Power Node Poll Timeout Status', 880x802f: 'Config Health Fault Clear', 890x8030: 'Config Health Fault Clear Unacknowledged', 900x8031: 'Config Health Fault Get', 910x8032: 'Config Health Fault Test', 920x8033: 'Config Health Fault Test Unacknowledged', 930x8034: 'Config Health Period Get', 940x8035: 'Config Health Period Set', 950x8036: 'Config Health Period Set Unacknowledged', 960x8037: 'Config Health Period Status', 970x8038: 'Config Heartbeat Publication Get', 980x8039: 'Config Heartbeat Publication Set', 990x803a: 'Config Heartbeat Subscription Get', 1000x803b: 'Config Heartbeat Subscription Set', 1010x803c: 'Config Heartbeat Subscription Status', 1020x803d: 'Config Model App Bind', 1030x803e: 'Config Model App Status', 1040x803f: 'Config Model App Unbind', 1050x8040: 'Config Netkey Add', 1060x8041: 'Config Netkey Delete', 1070x8042: 'Config Netkey Get', 1080x8043: 'Config Netkey List', 1090x8044: 'Config Netkey Status', 1100x8045: 'Config Netkey Update', 1110x8046: 'Config Node Identity Get', 1120x8047: 'Config Node Identity Set', 1130x8048: 'Config Node Identity Status', 1140x8049: 'Config Node Reset', 1150x804a: 'Config Node Reset Status', 1160x804b: 'Config Sig Model App Get', 1170x804c: 'Config Sig Model App List', 1180x804d: 'Config Vendor Model App Get', 1190x804e: 'Config Vendor Model App List', 120# Generic 1210x8201: 'Generic On Off Get', 1220x8202: 'Generic On Off Set', 1230x8203: 'Generic On Off Set Unacknowledged', 1240x8204: 'Generic On Off Status', 1250x8205: 'Generic Level Get', 1260x8206: 'Generic Level Set', 1270x8207: 'Generic Level Set Unacknowledged', 1280x8208: 'Generic Level Status', 1290x8209: 'Generic Delta Set', 1300x820A: 'Generic Delta Set Unacknowledged', 1310x820B: 'Generic Move Set', 1320x820C: 'Generic Move Set Unacknowledged', 133} 134 135# quick hack to convert Access message opcode + names 136tmp_messages =[ 137# 'GENERIC_ON_OFF_GET :0x8201', 138] 139for message in tmp_messages: 140 parts = message.split(':') 141 print ("%s: '%s'," % (parts[1].strip(),parts[0].strip().title().replace('_',' '))) 142 143# helpers 144def read_net_32_from_file(f): 145 data = f.read(4) 146 if len(data) < 4: 147 return -1 148 return struct.unpack('>I', data)[0] 149 150def as_hex(data): 151 return ''.join(["{0:02x} ".format(byte) for byte in data]) 152 153def as_big_endian32(value): 154 return struct.pack('>I', value) 155 156def read_net_16(data): 157 return struct.unpack('>H', data)[0] 158 159def read_net_24(data): 160 return data[0] << 16 | struct.unpack('>H', data[1:3])[0] 161 162def read_net_32(data): 163 return struct.unpack('>I', data)[0] 164 165# log engine - simple pretty printer 166max_indent = 0 167def log_pdu(pdu, indent = 0, hide_properties = []): 168 spaces = ' ' * indent 169 print(spaces + "%-20s %s" % (pdu.type, pdu.summary)) 170 if indent >= max_indent: 171 return 172 for property in pdu.properties: 173 if property.key in hide_properties: 174 continue 175 if isinstance( property.value, int): 176 print (spaces + "|%20s: 0x%x (%u)" % (property.key, property.value, property.value)) 177 elif isinstance( property.value, bytes): 178 print (spaces + "|%20s: %s" % (property.key, as_hex(property.value))) 179 else: 180 print (spaces + "|%20s: %s" % (property.key, str(property.value))) 181 hide_properties.append(property.key) 182 print (spaces + '| data: ' + as_hex(pdu.data)) 183 print (spaces + '----') 184 for origin in pdu.origins: 185 log_pdu(origin, indent + 1, hide_properties) 186 187# classes 188 189class network_key(object): 190 def __init__(self, index, netkey): 191 self.index = index 192 self.netkey = netkey 193 (self.nid, self.encryption_key, self.privacy_key) = k2(netkey, b'\x00') 194 195 def __repr__(self): 196 return ("NetKey-%04x %s: NID %02x Encryption %s Privacy %s" % (self.index, self.netkey.hex(), self.nid, self.encryption_key.hex(), self.privacy_key.hex())) 197 198class application_key(object): 199 def __init__(self, index, appkey): 200 self.index = index 201 self.appkey = appkey 202 self.aid = k4(self.appkey) 203 204 def __repr__(self): 205 return ("AppKey-%04x %s: AID %02x" % (self.index, self.appkey.hex(), self.aid)) 206 207class property(object): 208 def __init__(self, key, value): 209 self.key = key 210 self.value = value 211 212class layer_pdu(object): 213 def __init__(self, pdu_type, pdu_data): 214 self.summary = '' 215 self.src = None 216 self.dst = None 217 self.type = pdu_type 218 self.data = pdu_data 219 self.origins = [] 220 self.properties = [] 221 222 def add_property(self, key, value): 223 self.properties.append(property(key, value)) 224 225class network_pdu(layer_pdu): 226 def __init__(self, pdu_data): 227 super().__init__("Network(unencrpyted)", pdu_data) 228 229 # parse pdu 230 self.ivi = (self.data[1] & 0x80) >> 7 231 self.nid = self.data[0] & 0x7f 232 self.ctl = (self.data[1] & 0x80) == 0x80 233 self.ttl = self.data[1] & 0x7f 234 self.seq = read_net_24(self.data[2:5]) 235 self.src = read_net_16(self.data[5:7]) 236 self.dst = read_net_16(self.data[7:9]) 237 self.lower_transport = self.data[9:] 238 239 # set properties 240 self.add_property('ivi', self.ivi) 241 self.add_property('nid', self.nid) 242 self.add_property('ctl', self.ctl) 243 self.add_property('ttl', self.ttl) 244 self.add_property('seq', self.seq) 245 self.add_property('src', self.src) 246 self.add_property('dst', self.dst) 247 self.add_property('lower_transport', self.lower_transport) 248 249class lower_transport_pdu(layer_pdu): 250 def __init__(self, network_pdu): 251 super().__init__('Lower Transport', network_pdu.lower_transport) 252 253 # inherit properties 254 self.ctl = network_pdu.ctl 255 self.seq = network_pdu.seq 256 self.src = network_pdu.src 257 self.dst = network_pdu.dst 258 self.add_property('ctl', self.ctl) 259 self.add_property('seq', self.seq) 260 self.add_property('src', self.src) 261 self.add_property('dst', self.dst) 262 263 # parse pdu and set propoerties 264 self.seg = (self.data[0] & 0x80) == 0x80 265 self.add_property('seg', self.seg) 266 self.szmic = False 267 if self.ctl: 268 self.opcode = self.data[0] & 0x7f 269 self.add_property('opcode', self.opcode) 270 else: 271 self.aid = self.data[0] & 0x3f 272 self.add_property('aid', self.aid) 273 self.akf = self.data[0] & 0x40 == 0x040 274 self.add_property('akf', self.akf) 275 if self.seg: 276 if not self.ctl: 277 self.szmic = self.data[1] & 0x80 == 0x80 278 self.add_property('szmic', self.szmic) 279 temp_12 = struct.unpack('>H', self.data[1:3])[0] 280 self.seq_zero = (temp_12 >> 2) & 0x1fff 281 self.add_property('seq_zero', self.seq_zero) 282 temp_23 = struct.unpack('>H', self.data[2:4])[0] 283 self.seg_o = (temp_23 >> 5) & 0x1f 284 self.add_property('seg_o', self.seg_o) 285 self.seg_n = temp_23 & 0x1f 286 self.add_property('seg_n', self.seg_n) 287 self.segment = self.data[4:] 288 self.add_property('segment', self.segment) 289 else: 290 self.seq_auth = self.seq 291 self.upper_transport = self.data[1:] 292 self.add_property('upper_transport', self.upper_transport) 293 294class upper_transport_pdu(layer_pdu): 295 def __init__(self, segment): 296 if segment.ctl: 297 super().__init__('Segmented Control', b'') 298 else: 299 super().__init__('Segmented Transport', b'') 300 self.ctl = segment.ctl 301 self.src = segment.src 302 self.dst = segment.dst 303 self.seq = segment.seq 304 self.akf = segment.akf 305 self.aid = segment.aid 306 self.szmic = segment.szmic 307 self.seg_n = segment.seg_n 308 self.seq_zero = segment.seq_zero 309 self.direction = segment.direction 310 # TODO handle seq_zero overrun 311 self.seq_auth = segment.seq & 0xffffe000 | segment.seq_zero 312 self.add_property('seq_auth', self.seq_auth) 313 self.missing = (1 << (segment.seg_n+1)) - 1 314 self.data = b'' 315 self.processed = False 316 self.origins = [] 317 if self.ctl: 318 self.segment_len = 8 319 else: 320 self.segment_len = 12 321 322 self.add_property('src', self.src) 323 self.add_property('dst', self.dst) 324 self.add_property('aid', self.aid) 325 self.add_property('akf', self.akf) 326 self.add_property('segment_len', self.segment_len) 327 self.add_property('dir', self.direction) 328 329 def add_segment(self, network_pdu): 330 self.origins.append(network_pdu) 331 self.missing &= ~ (1 << network_pdu.seg_o) 332 if network_pdu.seg_o == self.seg_n: 333 # last segment, set len 334 self.len = (self.seg_n * self.segment_len) + len(network_pdu.segment) 335 if len(self.data) == 0 and self.complete(): 336 self.reassemble() 337 338 def complete(self): 339 return self.missing == 0 340 341 def reassemble(self): 342 self.data = bytearray(self.len) 343 missing = (1 << (self.seg_n+1)) - 1 344 for pdu in self.origins: 345 # copy data 346 pos = pdu.seg_o * self.segment_len 347 self.data[pos:pos+len(pdu.segment)] = pdu.segment 348 # done? 349 missing &= ~ (1 << pdu.seg_o) 350 if missing == 0: 351 break 352 353class access_pdu(layer_pdu): 354 def __init__(self, lower_pdu, data): 355 super().__init__('Access', b'') 356 self.src = lower_pdu.src 357 self.dst = lower_pdu.dst 358 self.akf = lower_pdu.akf 359 self.aid = lower_pdu.aid 360 self.seq_auth = lower_pdu.seq_auth 361 self.data = data 362 self.direction = lower_pdu.direction 363 self.add_property('src', self.src) 364 self.add_property('dst', self.dst) 365 self.add_property('akf', self.akf) 366 self.add_property('aid', self.aid) 367 self.add_property('seq_auth', self.seq_auth) 368 self.add_property('dir', self.direction) 369 370 upper_bits = data[0] >> 6 371 if upper_bits == 0 or upper_bits == 1: 372 self.opcode = data[0] 373 self.opcode_len = 1 374 elif upper_bits == 2: 375 self.opcode = read_net_16(data[0:2]) 376 self.opcode_len = 2 377 elif upper_bits == 3: 378 self.opcode = read_net_24(data[0:3]) 379 self.opcode_len = 3 380 self.add_property('opcode', self.opcode) 381 self.params = data[self.opcode_len:] 382 self.add_property('params', self.params) 383 if self.opcode in access_messages: 384 self.summary = access_messages[self.opcode] 385 386def segmented_message_tag(src, direction): 387 tag = str(src) + direction 388 return tag 389 390def segmented_message_for_pdu(pdu): 391 tag = segmented_message_tag(pdu.src, pdu.direction) 392 if tag in segmented_messages: 393 seg_message = segmented_messages[tag] 394 # check seq zero 395 if pdu.seq_zero == seg_message.seq_zero: 396 return seg_message 397 # print("new segmented message: src %04x, seq_zero %04x" % (pdu.src, pdu.seq_zero)) 398 seg_message = upper_transport_pdu(pdu) 399 segmented_messages[tag] = seg_message 400 return seg_message 401 402def mesh_set_iv_index(iv_index): 403 global ivi 404 ivi = iv_index 405 print ("IV-Index: " + as_big_endian32(ivi).hex()) 406 407# key management 408def mesh_add_netkey(index, netkey): 409 key = network_key(index, netkey) 410 print (key) 411 netkeys[index] = key 412 413def mesh_network_keys_for_nid(nid): 414 for (index, key) in netkeys.items(): 415 if key.nid == nid: 416 yield key 417 418def mesh_set_device_key(key): 419 global devkey 420 print ("DevKey: " + key.hex()) 421 devkey = key 422 423def mesh_add_application_key(index, appkey): 424 key = application_key(index, appkey) 425 print (key) 426 appkeys[index] = key 427 428def mesh_application_keys_for_aid(aid): 429 for (index, key) in appkeys.items(): 430 if key.aid == aid: 431 yield key 432 433def mesh_transport_nonce(pdu, nonce_type): 434 if pdu.szmic: 435 aszmic = 0x80 436 else: 437 aszmic = 0x00 438 return bytes( [nonce_type, aszmic, pdu.seq_auth >> 16, (pdu.seq_auth >> 8) & 0xff, pdu.seq_auth & 0xff, pdu.src >> 8, pdu.src & 0xff, pdu.dst >> 8, pdu.dst & 0xff]) + as_big_endian32(ivi) 439 440def mesh_application_nonce(pdu): 441 return mesh_transport_nonce(pdu, 0x01) 442 443def mesh_device_nonce(pdu): 444 return mesh_transport_nonce(pdu, 0x02) 445 446def mesh_upper_transport_decrypt(message, data): 447 if message.szmic: 448 trans_mic_len = 8 449 else: 450 trans_mic_len = 4 451 ciphertext = data[:-trans_mic_len] 452 trans_mic = data[-trans_mic_len:] 453 decrypted = None 454 if message.akf: 455 nonce = mesh_application_nonce(message) 456 # print( as_hex(nonce)) 457 for key in mesh_application_keys_for_aid(message.aid): 458 decrypted = aes_ccm_decrypt(key.appkey, nonce, ciphertext, b'', trans_mic_len, trans_mic) 459 if decrypted != None: 460 break 461 else: 462 nonce = mesh_device_nonce(message) 463 decrypted = aes_ccm_decrypt(devkey, nonce, ciphertext, b'', trans_mic_len, trans_mic) 464 return decrypted 465 466def mesh_process_control(control_pdu): 467 # TODO decode control message 468 # TODO add Seg Ack to sender access message origins 469 control_pdu.opcode = control_pdu.data[0] 470 control_pdu.add_property('opcode', control_pdu.opcode) 471 control_pdu.obo = (control_pdu.data[1] & 0x80) >> 7 472 control_pdu.add_property('obo', control_pdu.obo) 473 temp_12 = read_net_16(control_pdu.data[1:3]) 474 control_pdu.seq_zero = (temp_12 >> 2) & 0x1fff 475 control_pdu.add_property('seq_zero', control_pdu.seq_zero) 476 control_pdu.block_ack = read_net_32(control_pdu.data[3:7]) 477 control_pdu.add_property('block_ack', control_pdu.block_ack) 478 479 # try to add it to access message 480 inverse_direction = 'RX' 481 if control_pdu.direction == 'RX': 482 inverse_direcgtion = 'TX' 483 tag = segmented_message_tag(control_pdu.dst, inverse_direction) 484 if tag in segmented_messages: 485 seg_message = segmented_messages[tag] 486 seg_message.origins.append(control_pdu) 487 else: 488 log_pdu(control_pdu, 0, []) 489 490def mesh_process_access(access_pdu): 491 log_pdu(access_pdu, 0, []) 492 493def mesh_process_network_pdu_tx(network_pdu_encrypted): 494 495 # network layer - decrypt pdu 496 nid = network_pdu_encrypted.data[0] & 0x7f 497 for key in mesh_network_keys_for_nid(nid): 498 network_pdu_decrypted_data = network_decrypt(network_pdu_encrypted.data, as_big_endian32(ivi), key.encryption_key, key.privacy_key) 499 if network_pdu_decrypted_data != None: 500 break 501 if network_pdu_decrypted_data == None: 502 network_pdu_encrypted.summary = 'No encryption key found' 503 log_pdu(network_pdu_encrypted, 0, []) 504 return 505 506 # decrypted network pdu 507 network_pdu_decrypted = network_pdu(network_pdu_decrypted_data) 508 network_pdu_decrypted.direction = network_pdu_encrypted.direction 509 network_pdu_decrypted.add_property('dir', network_pdu_decrypted.direction) 510 network_pdu_decrypted.origins.append(network_pdu_encrypted) 511 512 # print("network pdu (enc)" + network_pdu_encrypted.data.hex()) 513 # print("network pdu (dec)" + network_pdu_decrypted_data.hex()) 514 515 # lower transport - reassemble 516 lower_transport = lower_transport_pdu(network_pdu_decrypted) 517 lower_transport.direction = network_pdu_decrypted.direction 518 lower_transport.add_property('dir', lower_transport.direction) 519 lower_transport.origins.append(network_pdu_decrypted) 520 521 if lower_transport.seg: 522 message = segmented_message_for_pdu(lower_transport) 523 message.add_segment(lower_transport) 524 if not message.complete(): 525 return 526 if message.processed: 527 return 528 529 message.processed = True 530 if message.ctl: 531 mesh_process_control(message) 532 else: 533 access_payload = mesh_upper_transport_decrypt(message, message.data) 534 if access_payload == None: 535 message.summary = 'No encryption key found' 536 log_pdu(message, 0, []) 537 else: 538 access = access_pdu(message, access_payload) 539 access.direction = message.direction 540 access.origins.append(message) 541 mesh_process_access(access) 542 543 else: 544 # print("lower_transport.ctl = " + str(lower_transport.ctl)) 545 if lower_transport.ctl: 546 control = layer_pdu('Unsegmented Control', lower_transport.data) 547 control.direction = lower_transport.direction 548 control.seq = lower_transport.seq 549 control.src = lower_transport.src 550 control.dst = lower_transport.dst 551 control.add_property('seq', lower_transport.seq) 552 control.add_property('src', lower_transport.src) 553 control.add_property('dst', lower_transport.dst) 554 control.origins.append(lower_transport) 555 mesh_process_control(control) 556 else: 557 access_payload = mesh_upper_transport_decrypt(lower_transport, lower_transport.upper_transport) 558 if access_payload == None: 559 lower_transport.summary = 'No encryption key found' 560 log_pdu(lower_transport, 0, []) 561 else: 562 access = access_pdu(lower_transport, access_payload) 563 access.add_property('seq_auth', lower_transport.seq) 564 access.direction = lower_transport.direction 565 access.origins.append(lower_transport) 566 mesh_process_access(access) 567 568 569def mesh_process_beacon_pdu(adv_pdu): 570 log_pdu(adv_pdu, 0, []) 571 572def mesh_process_adv(adv_pdu): 573 ad_len = adv_pdu.data[0] - 1 574 ad_type = adv_pdu.data[1] 575 if ad_type == 0x2A: 576 network_pdu_encrypted = layer_pdu("Network(encrypted)", adv_data[2:2+ad_len]) 577 network_pdu_encrypted.add_property('ivi', adv_data[2] >> 7) 578 network_pdu_encrypted.add_property('nid', adv_data[2] & 0x7f) 579 network_pdu_encrypted.add_property('dir', adv_pdu.direction) 580 network_pdu_encrypted.direction = adv_pdu.direction 581 network_pdu_encrypted.origins.append(adv_pdu) 582 mesh_process_network_pdu_tx(network_pdu_encrypted) 583 if ad_type == 0x2b: 584 beacon_pdu = layer_pdu("Beacon", adv_data[2:2+ad_len]) 585 beacon_pdu.origins.append(adv_pdu) 586 mesh_process_beacon_pdu(beacon_pdu) 587 588 589if len(sys.argv) == 1: 590 print ('Dump Mesh PacketLogger file') 591 print ('Copyright 2019, BlueKitchen GmbH') 592 print ('') 593 print ('Usage: ' + sys.argv[0] + 'hci_dump.pklg') 594 exit(0) 595 596infile = sys.argv[1] 597 598with open (infile, 'rb') as fin: 599 pos = 0 600 while True: 601 payload_length = read_net_32_from_file(fin) 602 if payload_length < 0: 603 break 604 ts_sec = read_net_32_from_file(fin) 605 ts_usec = read_net_32_from_file(fin) 606 type = ord(fin.read(1)) 607 packet_len = payload_length - 9; 608 if (packet_len > 66000): 609 print ("Error parsing pklg at offset %u (%x)." % (pos, pos)) 610 break 611 612 packet = fin.read(packet_len) 613 pos = pos + 4 + payload_length 614 # time = "[%s.%03u] " % (datetime.datetime.fromtimestamp(ts_sec).strftime("%Y-%m-%d %H:%M:%S"), ts_usec / 1000) 615 616 if type == 0: 617 # CMD 618 if packet[0] != 0x08: 619 continue 620 if packet[1] != 0x20: 621 continue 622 adv_data = packet[4:] 623 adv_pdu = layer_pdu("ADV(TX)", adv_data) 624 adv_pdu.add_property('dir', 'TX') 625 adv_pdu.direction = 'TX' 626 mesh_process_adv(adv_pdu) 627 628 elif type == 1: 629 # EVT 630 event = packet[0] 631 if event != 0x3e: 632 continue 633 event_len = packet[1] 634 if event_len < 14: 635 continue 636 adv_data = packet[13:-1] 637 adv_pdu = layer_pdu("ADV(RX)", adv_data) 638 adv_pdu.add_property('dir', 'RX') 639 adv_pdu.direction = 'RX' 640 mesh_process_adv(adv_pdu) 641 642 elif type == 0xfc: 643 # LOG 644 log = packet.decode("utf-8") 645 parts = re.match('mesh-iv-index: (.*)', log) 646 if parts and len(parts.groups()) == 1: 647 mesh_set_iv_index(int(parts.groups()[0], 16)) 648 continue 649 parts = re.match('mesh-devkey: (.*)', log) 650 if parts and len(parts.groups()) == 1: 651 mesh_set_device_key(bytes.fromhex(parts.groups()[0])) 652 continue 653 parts = re.match('mesh-appkey-(.*): (.*)', log) 654 if parts and len(parts.groups()) == 2: 655 mesh_add_application_key(int(parts.groups()[0], 16), bytes.fromhex(parts.groups()[1])) 656 continue 657 parts = re.match('mesh-netkey-(.*): (.*)', log) 658 if parts and len(parts.groups()) == 2: 659 mesh_add_netkey(int(parts.groups()[0], 16), bytes.fromhex(parts.groups()[1])) 660 continue 661 662