Ejemplo n.º 1
0
def test_03_SOMEIP_SubPackages():
    """ test SOMEIP packet : MessageId and RequestId subpackages."""
    p = someip.SOMEIP()

    # MessageId subpackage
    p.msg_id.srv_id = 0x1111
    p.msg_id.method_id = 0x0222
    p.msg_id.event_id = 0x0333

    p.msg_id.sub_id = 0
    pstr = binascii.hexlify(bytes(p))
    binstr = b'11110222' + b'00'*3 + b'08' + b'00'*4 + b'01010000'
    assert(pstr == binstr)

    p.msg_id.sub_id = 1
    pstr = binascii.hexlify(bytes(p))
    binstr = b'11118333' + b'00'*3 + b'08' + b'00'*4 + b'01010000'
    assert(pstr == binstr)

    # RequestId subpackage
    del (p)
    p = someip.SOMEIP()
    p.req_id.client_id = 0x1111
    p.req_id.session_id = 0x2222

    pstr = binascii.hexlify(bytes(p))
    binstr = b'00'*4 + b'00'*3 + b'08' + b'11112222' + b'01010000'
    assert(pstr == binstr)
Ejemplo n.º 2
0
    def test_03_SOMEIP_SubPackages(self):
        """ test SOMEIP packet : MessageId and RequestId subpackages."""
        p = someip.SOMEIP()

        # MessageId subpackage
        p.msg_id.srv_id = 0x1111
        p.msg_id.method_id = 0x0222
        p.msg_id.event_id = 0x0333

        p.msg_id.sub_id = 0
        pstr = binascii.hexlify(str(p))
        binstr = "11110222" + "00" * 3 + "08" + "00" * 4 + "01010000"
        self.assertTrue(pstr == binstr)

        p.msg_id.sub_id = 1
        pstr = binascii.hexlify(str(p))
        binstr = "11118333" + "00" * 3 + "08" + "00" * 4 + "01010000"
        self.assertTrue(pstr == binstr)

        # RequestId subpackage
        del (p)
        p = someip.SOMEIP()
        p.req_id.client_id = 0x1111
        p.req_id.session_id = 0x2222

        pstr = binascii.hexlify(str(p))
        binstr = "00" * 4 + "00" * 3 + "08" + "11112222" + "01010000"
        self.assertTrue(pstr == binstr)
Ejemplo n.º 3
0
def test_05_SOMEIP_TP():
    hex_stream = b'07d000640000040c000100030101220000001801' + b'0'*2048

    someip_tp_p = someip.SOMEIP(codecs.decode(hex_stream,'hex_codec'))
    assert(someip_tp_p.msg_type in someip.SOMEIP.SOMEIP_TP_TYPES)
    assert(someip_tp_p.offset == 384)
    assert(someip_tp_p.reserved == 0)
    assert(someip_tp_p.more_segments == someip.SOMEIP.SOMEIP_TP_MORE_SEGMENTS)
Ejemplo n.º 4
0
def test_04_SOMEIP_Fields():
    """ test SOMEIP packet : defaults."""
    p = someip.SOMEIP()

    # default values
    assert(p.proto_ver == someip.SOMEIP.PROTOCOL_VERSION)
    assert(p.iface_ver == someip.SOMEIP.INTERFACE_VERSION)
    assert(p.msg_type == someip.SOMEIP.TYPE_REQUEST)
    assert(p.retcode == someip.SOMEIP.RET_E_OK)
Ejemplo n.º 5
0
    def test_05_SOMEIP_TP(self):
        hex_stream = '07d000640000040c000100030101220000001801' + '0' * 2048

        someip_tp_p = someip.SOMEIP(hex_stream.decode('hex'))
        self.assertTrue(someip_tp_p.msg_type in someip.SOMEIP.SOMEIP_TP_TYPES)
        self.assertTrue(someip_tp_p.offset == 384)
        self.assertTrue(someip_tp_p.reserved == 0)
        self.assertTrue(
            someip_tp_p.more_segments == someip.SOMEIP.SOMEIP_TP_MORE_SEGMENTS)
Ejemplo n.º 6
0
  def test_00(self):
    """ SOME/IP magic cookie (client >> server). TR_SOMEIP_00159."""
    # build SOME/IP packet
    sip = someip.SOMEIP()
    sip.msg_id.srv_id = 0xffff
    sip.msg_id.sub_id = 0x0
    sip.msg_id.method_id = 0x0000

    sip.req_id.client_id = 0xdead
    sip.req_id.session_id = 0xbeef

    sip.msg_type = 0x01
    sip.retcode = 0x00

    # send message
    p = Ether()/IP(src=ETH_IFACE_B.ip,dst=ETH_IFACE_A.ip)/UDP(sport=30490,dport=30490)/sip

    sendp(p,iface=ETH_IFACE_B.name)
Ejemplo n.º 7
0
    def test_02_SOMEIP(self):
        """ test SOMEIP packet : overall, payload and length."""
        p = someip.SOMEIP()

        # overall package (with default values)
        pstr = binascii.hexlify(str(p))
        binstr = "00" * 4 + "00" * 3 + "08" + "00" * 4 + "01010000"
        self.assertTrue(pstr == binstr)

        # add payload and check length
        p.payload = binascii.unhexlify("DEADBEEF")
        pstr = binascii.hexlify(str(p))
        binstr = "00" * 4 + "00" * 3 + "0c" + "00" * 4 + "01010000" + "deadbeef"
        self.assertTrue(pstr == binstr)
        # empty payload, recheck dynamic length calculation
        p.payload = None
        pstr = binascii.hexlify(str(p))
        binstr = "00" * 4 + "00" * 3 + "08" + "00" * 4 + "01010000"
        self.assertTrue(pstr == binstr)
Ejemplo n.º 8
0
def test_02_SOMEIP():
    """ test SOMEIP packet : overall, payload and length."""
    someip_p = someip.SOMEIP()

    # overall package (with default values)
    pstr = binascii.hexlify(bytes(someip_p))
    binstr = b'00'*4 + b'00'*3 + b'08' + b'00'*4 + b'01010000'
    assert(pstr == binstr)

    # add payload and check length
    p = someip_p / binascii.unhexlify("DEADBEEF")
    pstr = binascii.hexlify(bytes(p))
    binstr = b'00'*4 + b'00'*3 + b'0c' + b'00'*4 + b'01010000' + b'deadbeef'
    assert(pstr == binstr)

    # empty payload, recheck dynamic length calculation
    p.remove_payload()
    pstr = binascii.hexlify(bytes(p))
    binstr = b'00'*4 + b'00'*3 + b'08' + b'00'*4 + b'01010000'
    assert(pstr == binstr)