def parse_diag_ext_msg(self, pkt, radio_id): # 79 | 00 | 00 | 00 | 00 00 1c fc 0f 16 e4 00 | e6 04 | 94 13 | 02 00 00 00 # cmd_code, ts_type, num_args, drop_cnt, TS, Line number, Message subsystem ID, ? # Message: two null-terminated strings, one for log and another for filename xdm_hdr = pkt[0:20] xdm_hdr = struct.unpack('<BBBBQHHL', xdm_hdr) pkt_ts = util.parse_qxdm_ts(xdm_hdr[4]) pkt_body = pkt[20 + 4 * xdm_hdr[2]:] pkt_body = pkt_body.rstrip(b'\0').rsplit(b'\0', maxsplit=1) if len(pkt_body) == 2: src_fname = pkt_body[1] log_content = pkt_body[0] else: src_fname = b'' log_content = pkt_body[0] osmocore_log_hdr = util.create_osmocore_logging_header( timestamp=pkt_ts, subsys_name=str(xdm_hdr[6]).encode('utf-8'), filename=src_fname, line_number=xdm_hdr[5]) gsmtap_hdr = util.create_gsmtap_header( version=2, payload_type=util.gsmtap_type.OSMOCORE_LOG) self.writer.write_cp(gsmtap_hdr + osmocore_log_hdr + log_content, radio_id, pkt_ts)
def parse_diag_log(self, pkt: "DIAG_LOG_F data without trailing CRC", radio_id=0): if len(pkt) < 16: return xdm_hdr = pkt[4:16] xdm_hdr = struct.unpack('<HHQ', xdm_hdr) # len, ID, TS pkt_ts = util.parse_qxdm_ts(xdm_hdr[2]) pkt_body = pkt[16:] if len(pkt_body) != (xdm_hdr[0] - 12): self.logger.log( logging.WARNING, "Packet length mismatch: expected {}, got {}".format( xdm_hdr[0], len(pkt_body))) if xdm_hdr[1] in self.process.keys(): self.process[xdm_hdr[1]](pkt_ts, pkt_body, radio_id) elif xdm_hdr[1] in self.no_process.keys(): #print("Not handling XDM Header 0x%04x (%s)" % (xdm_hdr[1], self.no_process[xdm_hdr[1]])) return else: #print("Unhandled XDM Header 0x%04x" % xdm_hdr[1]) #util.xxd(pkt) return
def parse_diag_event(self, pkt, radio_id): cmd_code, len_msg = struct.unpack('<BH', pkt[0:3]) pos = 3 while pos < len(pkt): # id 12b, _pad 1b, payload_len 2b, ts_trunc 1b _eid = struct.unpack('<H', pkt[pos:pos + 2])[0] event_id = _eid & 0xfff payload_len = (_eid & 0x6000) >> 13 ts_trunc = (_eid & 0x8000) >> 15 # 0: 64bit, 1: 16bit TS if ts_trunc == 0: ts = struct.unpack('<Q', pkt[pos + 2:pos + 10])[0] ts = util.parse_qxdm_ts(ts) pos += 10 else: #ts = struct.unpack('<H', pkt[pos+2:pos+4])[0] # TODO: correctly parse ts ts = datetime.datetime.now() pos += 4 assert (payload_len >= 0) and (payload_len <= 3) if payload_len == 0: # No payload if event_id in self.process_event.keys(): self.process_event[event_id](radio_id, ts) elif event_id in self.no_process_event.keys(): pass else: print("Event: {} {}".format(event_id, ts)) elif payload_len == 1: # 1x uint8 arg1 = pkt[pos] if event_id in self.process_event.keys(): self.process_event[event_id](radio_id, ts, arg1) elif event_id in self.no_process_event.keys(): pass else: print("Event: {} {}: 0x{:02x}".format(event_id, ts, arg1)) pos += 1 elif payload_len == 2: # 2x uint8 arg1 = pkt[pos] arg2 = pkt[pos + 1] if event_id in self.process_event.keys(): self.process_event[event_id](radio_id, ts, arg1, arg2) elif event_id in self.no_process_event.keys(): pass else: print("Event: {} {}: 0x{:02x} 0x{:02x}".format( event_id, ts, arg1, arg2)) pos += 2 elif payload_len == 3: # Pascal string bin_len = pkt[pos] arg_bin = pkt[pos + 1:pos + 1 + bin_len] if event_id in self.process_event.keys(): self.process_event[event_id](radio_id, ts, arg_bin) elif event_id in self.no_process_event.keys(): pass else: print("Event {}: {}: Binary(len=0x{:02x}) = {}".format( event_id, ts, bin_len, ' '.join('{:02x}'.format(x) for x in arg_bin))) pos += (1 + pkt[pos])