Example #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)
Example #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)
Example #3
0
 def test_recvfrom_with_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)
     pdu = nfc.llcp.pdu.Information(32, 17, 0, 0, b'123')
     threading.Timer(0.01, llc.dispatch, (pdu,)).start()
     assert llc.recvfrom(dlc) == (b'123', 17)
Example #4
0
 def test_recvfrom_with_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)
     pdu = nfc.llcp.pdu.Information(32, 17, 0, 0, b'123')
     threading.Timer(0.01, llc.dispatch, (pdu,)).start()
     assert llc.recvfrom(dlc) == (b'123', 17)
Example #5
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'
Example #6
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'
Example #7
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)
Example #8
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)
Example #9
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)
Example #10
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)
Example #11
0
 def test_connect(self, llc, ldl, dlc, peer_miu, send_miu):
     def collect_and_dispatch(llc):
         llc.collect()
         llc.dispatch(nfc.llcp.pdu.ConnectionComplete(32, 16, peer_miu))
     threading.Timer(0.01, collect_and_dispatch, (llc,)).start()
     llc.bind(dlc, 32)
     llc.connect(dlc, 16)
     assert llc.getsockopt(dlc, nfc.llcp.SO_SNDMIU) == send_miu
     llc.connect(ldl, 17)
     assert llc.getsockname(ldl) == 33
     assert llc.getpeername(ldl) == 17
     with pytest.raises(nfc.llcp.Error) as excinfo:
         llc.connect(object(), 18)
     assert excinfo.value.errno == errno.ENOTSOCK
Example #12
0
 def test_connect(self, llc, ldl, dlc, peer_miu, send_miu):
     def collect_and_dispatch(llc):
         llc.collect()
         llc.dispatch(nfc.llcp.pdu.ConnectionComplete(32, 16, peer_miu))
     threading.Timer(0.01, collect_and_dispatch, (llc,)).start()
     llc.bind(dlc, 32)
     llc.connect(dlc, 16)
     assert llc.getsockopt(dlc, nfc.llcp.SO_SNDMIU) == send_miu
     llc.connect(ldl, 17)
     assert llc.getsockname(ldl) == 33
     assert llc.getpeername(ldl) == 17
     with pytest.raises(nfc.llcp.Error) as excinfo:
         llc.connect(object(), 18)
     assert excinfo.value.errno == errno.ENOTSOCK
Example #13
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'
Example #14
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'