Example #1
0
    def parse_dlf(self):
        oldbuf = b''
        while True:
            buf = self.io_device.read(0x100000)
            #print("%d"% len(buf))
            if len(buf) == 0:
                break
            buf = oldbuf + buf

            pkt_len = struct.unpack('<H', buf[0:2])[0]
            while len(buf) >= pkt_len:
                # DLF lacks CRC16/other fancy stuff
                pkt = buf[0:pkt_len]
                pkt = b'\x10\x00' + pkt[0:2] + pkt
                calculated_crc = util.dm_crc16(pkt)
                pkt = pkt + struct.pack('<H', calculated_crc)

                #print("%02x %02x" % (pkt_len, len(buf)))
                self.parse_diag(pkt, hdlc_encoded=False)
                buf = buf[pkt_len:]

                if len(buf) < 2:
                    break
                pkt_len = struct.unpack('<H', buf[0:2])[0]

            oldbuf = buf
Example #2
0
    def parse_diag(self, pkt, hdlc_encoded=True, check_crc=True, radio_id=0):
        # Should contain DIAG command and CRC16
        # pkt should not contain trailing 0x7E, and either HDLC encoded or not
        # When the pkt is not HDLC encoded, hdlc_encoded should be set to True
        # radio_id = 0 for default, larger than 1 for SIM 1 and such

        if len(pkt) < 3:
            return

        if hdlc_encoded:
            pkt = util.unwrap(pkt)

        # Check and strip CRC if existing
        if check_crc:
            crc = util.dm_crc16(pkt[:-2])
            crc_pkt = (pkt[-1] << 8) | pkt[-2]
            if crc != crc_pkt:
                self.logger.log(
                    logging.WARNING,
                    "CRC mismatch: expected 0x{:04x}, got 0x{:04x}".format(
                        crc, crc_pkt))
                self.logger.log(logging.DEBUG, util.xxd(pkt))
            pkt = pkt[:-2]

        if pkt[0] == diagcmd.DIAG_LOG_F:
            self.parse_diag_log(pkt, radio_id)
        elif pkt[0] == diagcmd.DIAG_EVENT_REPORT_F and self.parse_events:
            self.parse_diag_event(pkt, radio_id)
        elif pkt[0] == diagcmd.DIAG_EXT_MSG_F and self.parse_msgs:
            self.parse_diag_ext_msg(pkt, radio_id)
        elif pkt[0] == diagcmd.DIAG_QSR_EXT_MSG_TERSE_F and self.parse_msgs:
            #self.parse_diag_qsr_ext_msg(pkt, radio_id)
            pass
        elif pkt[0] == diagcmd.DIAG_QSR4_EXT_MSG_TERSE_F and self.parse_msgs:
            #self.parse_diag_qsr4_ext_msg(pkt, radio_id)
            pass
        elif pkt[0] == diagcmd.DIAG_MULTI_RADIO_CMD_F:
            self.parse_diag_multisim(pkt)
        else:
            #print("Not parsing non-Log packet %02x" % pkt[0])
            #util.xxd(pkt)
            return