Esempio n. 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)
Esempio n. 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)
Esempio n. 3
0
 def test_bind_by_none(self, llc, raw, ldl, dlc):
     llc.bind(dlc)
     assert llc.getsockname(dlc) == 32
     for sap in range(33, 64):
         sock = llc.socket(nfc.llcp.llc.RAW_ACCESS_POINT)
         llc.bind(sock)
         assert llc.getsockname(sock) == sap
     with pytest.raises(nfc.llcp.Error) as excinfo:
         llc.bind(ldl)
     assert excinfo.value.errno == errno.EAGAIN
Esempio n. 4
0
 def test_bind_by_none(self, llc, raw, ldl, dlc):
     llc.bind(dlc)
     assert llc.getsockname(dlc) == 32
     for sap in range(33, 64):
         sock = llc.socket(nfc.llcp.llc.RAW_ACCESS_POINT)
         llc.bind(sock)
         assert llc.getsockname(sock) == sap
     with pytest.raises(nfc.llcp.Error) as excinfo:
         llc.bind(ldl)
     assert excinfo.value.errno == errno.EAGAIN
Esempio n. 5
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)
Esempio n. 6
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)
Esempio n. 7
0
 def test_bind_by_name(self, llc, raw, ldl, dlc):
     with pytest.raises(nfc.llcp.Error) as excinfo:
         llc.bind(dlc, 'urn:nfc:snep')
     assert excinfo.value.errno == errno.EFAULT
     llc.bind(dlc, 'urn:nfc:sn:snep')
     assert llc.getsockname(dlc) == 4
     with pytest.raises(nfc.llcp.Error) as excinfo:
         llc.bind(ldl, 'urn:nfc:sn:snep')
     assert excinfo.value.errno == errno.EADDRINUSE
     llc.bind(ldl, 'urn:nfc:xsn:nfcpy.org:service')
     assert llc.getsockname(ldl) == 16
     for sap in range(17, 32):
         sock = llc.socket(nfc.llcp.llc.RAW_ACCESS_POINT)
         llc.bind(sock, 'urn:nfc:sn:use_sap-{}'.format(sap))
         assert llc.getsockname(sock) == sap
     with pytest.raises(nfc.llcp.Error) as excinfo:
         llc.bind(raw, 'urn:nfc:sn:sap-32')
     assert excinfo.value.errno == errno.EADDRNOTAVAIL
Esempio n. 8
0
 def test_bind_by_name(self, llc, raw, ldl, dlc):
     with pytest.raises(nfc.llcp.Error) as excinfo:
         llc.bind(dlc, 'urn:nfc:snep')
     assert excinfo.value.errno == errno.EFAULT
     llc.bind(dlc, 'urn:nfc:sn:snep')
     assert llc.getsockname(dlc) == 4
     with pytest.raises(nfc.llcp.Error) as excinfo:
         llc.bind(ldl, 'urn:nfc:sn:snep')
     assert excinfo.value.errno == errno.EADDRINUSE
     llc.bind(ldl, 'urn:nfc:xsn:nfcpy.org:service')
     assert llc.getsockname(ldl) == 16
     for sap in range(17, 32):
         sock = llc.socket(nfc.llcp.llc.RAW_ACCESS_POINT)
         llc.bind(sock, 'urn:nfc:sn:use_sap-{}'.format(sap))
         assert llc.getsockname(sock) == sap
     with pytest.raises(nfc.llcp.Error) as excinfo:
         llc.bind(raw, 'urn:nfc:sn:sap-32')
     assert excinfo.value.errno == errno.EADDRNOTAVAIL
Esempio n. 9
0
 def dlc(self, llc):
     return llc.socket(nfc.llcp.DATA_LINK_CONNECTION)
Esempio n. 10
0
 def ldl(self, llc):
     return llc.socket(nfc.llcp.LOGICAL_DATA_LINK)
Esempio n. 11
0
 def raw(self, llc):
     return llc.socket(nfc.llcp.llc.RAW_ACCESS_POINT)
Esempio n. 12
0
 def test_socket(self, llc, socket_type, socket_class):
     assert isinstance(llc.socket(socket_type), socket_class)
Esempio n. 13
0
 def dlc(self, llc):
     return llc.socket(nfc.llcp.DATA_LINK_CONNECTION)
Esempio n. 14
0
 def ldl(self, llc):
     return llc.socket(nfc.llcp.LOGICAL_DATA_LINK)
Esempio n. 15
0
 def raw(self, llc):
     return llc.socket(nfc.llcp.llc.RAW_ACCESS_POINT)
Esempio n. 16
0
 def test_socket(self, llc, socket_type, socket_class):
     assert isinstance(llc.socket(socket_type), socket_class)