Пример #1
0
def parse_hytera_data(bytedata: bytes) -> KaitaiStruct:
    if len(bytedata) < 2:
        # probably just heartbeat response
        return IpSiteConnectHeartbeat.from_bytes(bytedata)
    elif bytedata[0:2] == bytes([0x32, 0x42]):
        # HSTRP
        return HyteraSimpleTransportReliabilityProtocol.from_bytes(bytedata)
    elif bytedata[0:1] == bytes([0x7E]):
        # HRNP
        return HyteraRadioNetworkProtocol.from_bytes(bytedata)
    elif (int.from_bytes(bytedata[0:1], byteorder="big") & 0x80) == 0x80 and (
            int.from_bytes(bytedata[0:1], byteorder="big") & 0xC0) == 2:
        rtsp = RealTimeTransportProtocol.from_bytes(bytedata)
        return rtsp
    elif (int.from_bytes(bytedata[0:8], byteorder="little") == 0
          or bytedata[0:4] == b"ZZZZ" or bytedata[20]
          == bytedata[21]  # color code shall be same in both bytes
          ):
        if bytedata[5:9] == bytes([0x00, 0x00, 0x00, 0x14]):
            return IpSiteConnectHeartbeat.from_bytes(bytedata)
        else:
            return IpSiteConnectProtocol.from_bytes(bytedata)
    else:
        # HDAP
        return HyteraDmrApplicationProtocol.from_bytes(bytedata)
Пример #2
0
def parse_hytera_data(bytedata):
    if len(bytedata) < 2:
        # probably just heartbeat response
        return IpSiteConnectHeartbeat.from_bytes(bytedata)
    elif bytedata[0:2] == bytes([0x32, 0x42]):
        # HSTRP
        return HyteraSimpleTransportReliabilityProtocol.from_bytes(bytedata)
    elif bytedata[0:1] == bytes([0x7E]):
        # HRNP
        return HyteraRadioNetworkProtocol.from_bytes(bytedata)
    elif (int.from_bytes(bytedata[0:1], byteorder="big") & 0x80) == 0x80 and (
            int.from_bytes(bytedata[0:1], byteorder="big") & 0xC0) == 2:
        rtsp = RealTimeTransportProtocol.from_bytes(bytedata)
        if rtsp.fixed_header.padding:
            print("{0}={1}".format(
                col256(rtsp.__class__.__name__, bg="001", fg="345"),
                col256(str(_prettyprint(rtsp)), "352"),
            ))
            print("RTSP %s has padding bytes")
            exit(1)
        return rtsp
    elif (int.from_bytes(bytedata[0:8], byteorder="little") == 0
          or bytedata[0:4] == b"ZZZZ"
          or bytedata[20:22] == bytes([0x11, 0x11])):
        if bytedata[5:9] == bytes([0x00, 0x00, 0x00, 0x14]):
            return IpSiteConnectHeartbeat.from_bytes(bytedata)
        else:
            return IpSiteConnectProtocol.from_bytes(bytedata)
    else:
        # HDAP
        return HyteraDmrApplicationProtocol.from_bytes(bytedata)
    import hytera_homebrew_bridge
except ImportError:
    sys.path.append(
        os.path.dirname(
            os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))

from dmr_utils3.decode import voice_head_term
from hytera_homebrew_bridge.tests.prettyprint import prettyprint
from hytera_homebrew_bridge.kaitai.ip_site_connect_protocol import IpSiteConnectProtocol

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("use as %s <hexstring>" % sys.argv[0])
        exit(0)

    packet = IpSiteConnectProtocol.from_bytes(bytes.fromhex(sys.argv[1]))
    print(
        "source id: \t%s\ntarget id: \t%s\ncall type: \t%s\ntimeslot: \t%s\npacket_type: \t%s\nslot_type: \t%s\n\n"
        % (
            packet.source_radio_id,
            packet.destination_radio_id,
            IpSiteConnectProtocol.CallTypes(packet.call_type),
            packet.Timeslots(packet.timeslot_raw),
            packet.packet_type,
            packet.slot_type,
        ))

    prettyprint(packet)

    original = bytearray(packet.ipsc_payload)
    # swap bytes