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)
Beispiel #2
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)
#!/usr/bin/env python3
import os
import sys

try:
    import hytera_homebrew_bridge
except ImportError:
    sys.path.append(
        os.path.dirname(
            os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))

from hytera_homebrew_bridge.tests.prettyprint import prettyprint
from hytera_homebrew_bridge.kaitai.hytera_dmr_application_protocol import (
    HyteraDmrApplicationProtocol, )

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

    packet = HyteraDmrApplicationProtocol.from_bytes(bytes.fromhex(
        sys.argv[1]))
    print(packet)
    print(packet.message_type)
    prettyprint(packet)