Exemple #1
0
        def test_collect_voluntary_ack_within_aggregation(self, llc):
            dlc = [None, None, None, None]
            for i in range(len(dlc)):
                dlc[i] = llc.socket(nfc.llcp.DATA_LINK_CONNECTION)
                llc.setsockopt(dlc[i], nfc.llcp.SO_RCVBUF, 2)
                pdu = nfc.llcp.pdu.ConnectionComplete(32+i, 16+i, 248)
                threading.Timer(0.01, llc.collect).start()
                threading.Timer(0.02, llc.dispatch, (pdu,)).start()
                llc.connect(dlc[i], 16+i)

            llc.send(dlc[0], 230 * b'1', nfc.llcp.MSG_DONTWAIT)
            pdu = nfc.llcp.pdu.Information(33, 17, 0, 0, b'123')
            threading.Timer(0.01, llc.dispatch, (pdu,)).start()
            assert llc.recv(dlc[1]) == b'123'
            pdu = nfc.llcp.pdu.Information(34, 18, 0, 0, b'123')
            threading.Timer(0.01, llc.dispatch, (pdu,)).start()
            assert llc.recv(dlc[2]) == b'123'
            pdu = nfc.llcp.pdu.Information(35, 19, 0, 0, b'123')
            threading.Timer(0.01, llc.dispatch, (pdu,)).start()
            assert llc.recv(dlc[3]) == b'123'
            assert llc.collect() == nfc.llcp.pdu.AggregatedFrame(0, 0, [
                nfc.llcp.pdu.Information(16, 32, 0, 0, 230 * b'1'),
                nfc.llcp.pdu.ReceiveReady(17, 33, 1),
                nfc.llcp.pdu.ReceiveReady(18, 34, 1)
            ])
            assert llc.collect() == nfc.llcp.pdu.ReceiveReady(19, 35, 1)
Exemple #2
0
        def test_collect_voluntary_ack_within_aggregation(self, llc):
            dlc = [None, None, None, None]
            for i in range(len(dlc)):
                dlc[i] = llc.socket(nfc.llcp.DATA_LINK_CONNECTION)
                llc.setsockopt(dlc[i], nfc.llcp.SO_RCVBUF, 2)
                pdu = nfc.llcp.pdu.ConnectionComplete(32+i, 16+i, 248)
                threading.Timer(0.01, llc.collect).start()
                threading.Timer(0.02, llc.dispatch, (pdu,)).start()
                llc.connect(dlc[i], 16+i)

            llc.send(dlc[0], 230 * b'1', nfc.llcp.MSG_DONTWAIT)
            pdu = nfc.llcp.pdu.Information(33, 17, 0, 0, b'123')
            threading.Timer(0.01, llc.dispatch, (pdu,)).start()
            assert llc.recv(dlc[1]) == b'123'
            pdu = nfc.llcp.pdu.Information(34, 18, 0, 0, b'123')
            threading.Timer(0.01, llc.dispatch, (pdu,)).start()
            assert llc.recv(dlc[2]) == b'123'
            pdu = nfc.llcp.pdu.Information(35, 19, 0, 0, b'123')
            threading.Timer(0.01, llc.dispatch, (pdu,)).start()
            assert llc.recv(dlc[3]) == b'123'
            assert llc.collect() == nfc.llcp.pdu.AggregatedFrame(0, 0, [
                nfc.llcp.pdu.Information(16, 32, 0, 0, 230 * b'1'),
                nfc.llcp.pdu.ReceiveReady(17, 33, 1),
                nfc.llcp.pdu.ReceiveReady(18, 34, 1)
            ])
            assert llc.collect() == nfc.llcp.pdu.ReceiveReady(19, 35, 1)
Exemple #3
0
 def test_dispatch_connect_by_name(self, llc, dlc):
     llc.dispatch(nfc.llcp.pdu.Connect(1, 32, sn=b'urn:nfc:sn:service'))
     assert llc.collect() == nfc.llcp.pdu.DisconnectedMode(32, 1, 2)
     llc.bind(dlc, b'urn:nfc:sn:service')
     llc.listen(dlc, 1)
     llc.dispatch(nfc.llcp.pdu.Connect(1, 32, sn=b'urn:nfc:sn:service'))
     llc.accept(dlc)
     assert llc.collect() == nfc.llcp.pdu.ConnectionComplete(32, 16)
Exemple #4
0
 def test_dispatch_connect_by_name(self, llc, dlc):
     llc.dispatch(nfc.llcp.pdu.Connect(1, 32, sn=b'urn:nfc:sn:service'))
     assert llc.collect() == nfc.llcp.pdu.DisconnectedMode(32, 1, 2)
     llc.bind(dlc, b'urn:nfc:sn:service')
     llc.listen(dlc, 1)
     llc.dispatch(nfc.llcp.pdu.Connect(1, 32, sn=b'urn:nfc:sn:service'))
     llc.accept(dlc)
     assert llc.collect() == nfc.llcp.pdu.ConnectionComplete(32, 16)
Exemple #5
0
 def test_sendto_on_raw_prebound_socket(self, llc, raw):
     llc.bind(raw, 33)
     pdu = nfc.llcp.pdu.UnnumberedInformation(16, 33, b'123')
     llc.sendto(raw, pdu, 16, nfc.llcp.MSG_DONTWAIT)
     pdu = llc.collect()
     assert isinstance(pdu, nfc.llcp.pdu.UnnumberedInformation)
     assert pdu.dsap == 16 and pdu.ssap == 33 and pdu.data == b'123'
Exemple #6
0
 def test_sendto_on_raw_prebound_socket(self, llc, raw):
     llc.bind(raw, 33)
     pdu = nfc.llcp.pdu.UnnumberedInformation(16, 33, b'123')
     llc.sendto(raw, pdu, 16, nfc.llcp.MSG_DONTWAIT)
     pdu = llc.collect()
     assert isinstance(pdu, nfc.llcp.pdu.UnnumberedInformation)
     assert pdu.dsap == 16 and pdu.ssap == 33 and pdu.data == b'123'
Exemple #7
0
 def test_send_with_connected_dlc_socket(self, llc, dlc):
     pdu = nfc.llcp.pdu.ConnectionComplete(32, 17)
     threading.Timer(0.01, llc.collect).start()
     threading.Timer(0.02, llc.dispatch, (pdu,)).start()
     llc.connect(dlc, 17)
     llc.send(dlc, b'123', nfc.llcp.MSG_DONTWAIT)
     pdu = llc.collect()
     assert isinstance(pdu, nfc.llcp.pdu.Information)
     assert pdu.dsap == 17 and pdu.ssap == 32 and pdu.data == b'123'
Exemple #8
0
 def test_send_with_connected_dlc_socket(self, llc, dlc):
     pdu = nfc.llcp.pdu.ConnectionComplete(32, 17)
     threading.Timer(0.01, llc.collect).start()
     threading.Timer(0.02, llc.dispatch, (pdu,)).start()
     llc.connect(dlc, 17)
     llc.send(dlc, b'123', nfc.llcp.MSG_DONTWAIT)
     pdu = llc.collect()
     assert isinstance(pdu, nfc.llcp.pdu.Information)
     assert pdu.dsap == 17 and pdu.ssap == 32 and pdu.data == b'123'
Exemple #9
0
 def test_accept_send_cc(self, llc, dlc):
     llc.bind(dlc, b'urn:nfc:sn:snep')
     llc.listen(dlc, 0)
     threading.Timer(0, llc.accept, (dlc,)).start()
     time.sleep(0.01)
     llc.dispatch(nfc.llcp.pdu.Connect(4, 32))
     pdu = llc.collect(0.01)
     assert isinstance(pdu, nfc.llcp.pdu.ConnectionComplete)
     assert pdu.dsap == 32 and pdu.ssap == 4
Exemple #10
0
 def test_accept_send_cc(self, llc, dlc):
     llc.bind(dlc, b'urn:nfc:sn:snep')
     llc.listen(dlc, 0)
     threading.Timer(0, llc.accept, (dlc,)).start()
     time.sleep(0.01)
     llc.dispatch(nfc.llcp.pdu.Connect(4, 32))
     pdu = llc.collect(0.01)
     assert isinstance(pdu, nfc.llcp.pdu.ConnectionComplete)
     assert pdu.dsap == 32 and pdu.ssap == 4
Exemple #11
0
 def test_recv(self, llc, dlc):
     llc.setsockopt(dlc, nfc.llcp.SO_RCVBUF, 2)
     pdu = nfc.llcp.pdu.ConnectionComplete(32, 17)
     threading.Timer(0.01, llc.collect).start()
     threading.Timer(0.02, llc.dispatch, (pdu,)).start()
     llc.connect(dlc, 17)
     pdu = nfc.llcp.pdu.Information(32, 17, 0, 0, b'123')
     threading.Timer(0.01, llc.dispatch, (pdu,)).start()
     assert llc.recv(dlc) == b'123'
     assert llc.collect() == nfc.llcp.pdu.ReceiveReady(17, 32, 1)
Exemple #12
0
 def test_recv(self, llc, dlc):
     llc.setsockopt(dlc, nfc.llcp.SO_RCVBUF, 2)
     pdu = nfc.llcp.pdu.ConnectionComplete(32, 17)
     threading.Timer(0.01, llc.collect).start()
     threading.Timer(0.02, llc.dispatch, (pdu,)).start()
     llc.connect(dlc, 17)
     pdu = nfc.llcp.pdu.Information(32, 17, 0, 0, b'123')
     threading.Timer(0.01, llc.dispatch, (pdu,)).start()
     assert llc.recv(dlc) == b'123'
     assert llc.collect() == nfc.llcp.pdu.ReceiveReady(17, 32, 1)
Exemple #13
0
 def test_collect_with_aggregation(self, llc, ldl):
     assert llc.cfg['send-miu'] == 248
     llc.sendto(ldl, 100 * b'1', 16, nfc.llcp.MSG_DONTWAIT)
     llc.sendto(ldl, 100 * b'2', 16, nfc.llcp.MSG_DONTWAIT)
     assert llc.collect() == nfc.llcp.pdu.AggregatedFrame(0, 0, [
         nfc.llcp.pdu.UnnumberedInformation(16, 32, 100 * b'1'),
         nfc.llcp.pdu.UnnumberedInformation(16, 32, 100 * b'2'),
     ])
     llc.sendto(ldl, 120 * b'3', 16, nfc.llcp.MSG_DONTWAIT)
     llc.sendto(ldl, 119 * b'4', 16, nfc.llcp.MSG_DONTWAIT)
     assert llc.collect() == nfc.llcp.pdu.AggregatedFrame(0, 0, [
         nfc.llcp.pdu.UnnumberedInformation(16, 32, 120 * b'3'),
         nfc.llcp.pdu.UnnumberedInformation(16, 32, 119 * b'4'),
     ])
     llc.sendto(ldl, 120 * b'5', 16, nfc.llcp.MSG_DONTWAIT)
     llc.sendto(ldl, 120 * b'6', 16, nfc.llcp.MSG_DONTWAIT)
     assert llc.collect() == \
         nfc.llcp.pdu.UnnumberedInformation(16, 32, 120 * b'5')
     assert llc.collect() == \
         nfc.llcp.pdu.UnnumberedInformation(16, 32, 120 * b'6')
Exemple #14
0
 def test_collect_with_aggregation(self, llc, ldl):
     assert llc.cfg['send-miu'] == 248
     llc.sendto(ldl, 100 * b'1', 16, nfc.llcp.MSG_DONTWAIT)
     llc.sendto(ldl, 100 * b'2', 16, nfc.llcp.MSG_DONTWAIT)
     assert llc.collect() == nfc.llcp.pdu.AggregatedFrame(0, 0, [
         nfc.llcp.pdu.UnnumberedInformation(16, 32, 100 * b'1'),
         nfc.llcp.pdu.UnnumberedInformation(16, 32, 100 * b'2'),
     ])
     llc.sendto(ldl, 120 * b'3', 16, nfc.llcp.MSG_DONTWAIT)
     llc.sendto(ldl, 119 * b'4', 16, nfc.llcp.MSG_DONTWAIT)
     assert llc.collect() == nfc.llcp.pdu.AggregatedFrame(0, 0, [
         nfc.llcp.pdu.UnnumberedInformation(16, 32, 120 * b'3'),
         nfc.llcp.pdu.UnnumberedInformation(16, 32, 119 * b'4'),
     ])
     llc.sendto(ldl, 120 * b'5', 16, nfc.llcp.MSG_DONTWAIT)
     llc.sendto(ldl, 120 * b'6', 16, nfc.llcp.MSG_DONTWAIT)
     assert llc.collect() == \
         nfc.llcp.pdu.UnnumberedInformation(16, 32, 120 * b'5')
     assert llc.collect() == \
         nfc.llcp.pdu.UnnumberedInformation(16, 32, 120 * b'6')
Exemple #15
0
        def test_collect_voluntary_ack_before_aggregation(self, llc):
            dlc = [None, None, None]
            for i in range(len(dlc)):
                dlc[i] = llc.socket(nfc.llcp.DATA_LINK_CONNECTION)
                llc.setsockopt(dlc[i], nfc.llcp.SO_RCVBUF, 2)
                pdu = nfc.llcp.pdu.ConnectionComplete(32+i, 16+i)
                threading.Timer(0.01, llc.collect).start()
                threading.Timer(0.02, llc.dispatch, (pdu,)).start()
                llc.connect(dlc[i], 16+i)

            pdu = nfc.llcp.pdu.Information(32, 16, 0, 0, b'123')
            threading.Timer(0.01, llc.dispatch, (pdu,)).start()
            assert llc.recv(dlc[0]) == b'123'
            assert llc.collect() == nfc.llcp.pdu.ReceiveReady(16, 32, 1)
Exemple #16
0
        def test_collect_voluntary_ack_before_aggregation(self, llc):
            dlc = [None, None, None]
            for i in range(len(dlc)):
                dlc[i] = llc.socket(nfc.llcp.DATA_LINK_CONNECTION)
                llc.setsockopt(dlc[i], nfc.llcp.SO_RCVBUF, 2)
                pdu = nfc.llcp.pdu.ConnectionComplete(32+i, 16+i)
                threading.Timer(0.01, llc.collect).start()
                threading.Timer(0.02, llc.dispatch, (pdu,)).start()
                llc.connect(dlc[i], 16+i)

            pdu = nfc.llcp.pdu.Information(32, 16, 0, 0, b'123')
            threading.Timer(0.01, llc.dispatch, (pdu,)).start()
            assert llc.recv(dlc[0]) == b'123'
            assert llc.collect() == nfc.llcp.pdu.ReceiveReady(16, 32, 1)
Exemple #17
0
 def test_collect_raw_socket_large_pdu(self, llc, raw):
     assert llc.cfg['send-miu'] == 248
     pdu = nfc.llcp.pdu.UnnumberedInformation(16, 32, 248 * b'1')
     llc.sendto(raw, pdu, 16, nfc.llcp.MSG_DONTWAIT)
     assert llc.collect() == pdu
Exemple #18
0
 def test_sendto_with_prebound_socket(self, llc, ldl):
     llc.bind(ldl, 32)
     assert llc.sendto(ldl, b'123', 16, nfc.llcp.MSG_DONTWAIT) is True
     pdu = llc.collect()
     assert isinstance(pdu, nfc.llcp.pdu.UnnumberedInformation)
     assert pdu.dsap == 16 and pdu.ssap == 32 and pdu.data == b'123'
Exemple #19
0
 def test_send_with_connected_ldl_socket(self, llc, ldl):
     llc.connect(ldl, 16)
     assert llc.send(ldl, b'123', nfc.llcp.MSG_DONTWAIT) is True
     pdu = llc.collect()
     assert isinstance(pdu, nfc.llcp.pdu.UnnumberedInformation)
     assert pdu.dsap == 16 and pdu.ssap == 32 and pdu.data == b'123'
Exemple #20
0
 def test_sendto_with_prebound_socket(self, llc, ldl):
     llc.bind(ldl, 32)
     assert llc.sendto(ldl, b'123', 16, nfc.llcp.MSG_DONTWAIT) is True
     pdu = llc.collect()
     assert isinstance(pdu, nfc.llcp.pdu.UnnumberedInformation)
     assert pdu.dsap == 16 and pdu.ssap == 32 and pdu.data == b'123'
Exemple #21
0
 def test_send_with_connected_ldl_socket(self, llc, ldl):
     llc.connect(ldl, 16)
     assert llc.send(ldl, b'123', nfc.llcp.MSG_DONTWAIT) is True
     pdu = llc.collect()
     assert isinstance(pdu, nfc.llcp.pdu.UnnumberedInformation)
     assert pdu.dsap == 16 and pdu.ssap == 32 and pdu.data == b'123'
Exemple #22
0
 def test_collect_raw_socket_large_pdu(self, llc, raw):
     assert llc.cfg['send-miu'] == 248
     pdu = nfc.llcp.pdu.UnnumberedInformation(16, 32, 248 * b'1')
     llc.sendto(raw, pdu, 16, nfc.llcp.MSG_DONTWAIT)
     assert llc.collect() == pdu
Exemple #23
0
 def collect_and_dispatch(llc):
     tid = llc.collect().sdreq[0][0]
     pdu = nfc.llcp.pdu.ServiceNameLookup(1, 1, sdres=[(tid, sap)])
     llc.dispatch(pdu)
Exemple #24
0
 def collect_and_dispatch(llc):
     llc.collect()
     llc.dispatch(nfc.llcp.pdu.ConnectionComplete(32, 16, peer_miu))
Exemple #25
0
 def collect_and_dispatch(llc):
     tid = llc.collect().sdreq[0][0]
     pdu = nfc.llcp.pdu.ServiceNameLookup(1, 1, sdres=[(tid, sap)])
     llc.dispatch(pdu)
Exemple #26
0
 def collect_and_dispatch(llc):
     llc.collect()
     llc.dispatch(nfc.llcp.pdu.ConnectionComplete(32, 16, peer_miu))