rfid imports

This commit is contained in:
gg 2024-12-24 11:06:51 +01:00
parent 270366af32
commit 4bf753e50a
6 changed files with 38 additions and 38 deletions

View File

@ -105,7 +105,7 @@ def connect(path):
for drv in drivers: for drv in drivers:
for dev in devices: for dev in devices:
log.debug("trying {0} on {1}".format(drv, dev)) log.debug("trying {0} on {1}".format(drv, dev))
driver = importlib.import_module("nfc.clf." + drv) driver = importlib.import_module("src.lib.nfc.clf." + drv)
tty = None tty = None
try: try:
tty = transport.TTY(dev) tty = transport.TTY(dev)

View File

@ -52,7 +52,7 @@ listen_dep yes
========== ======= ============ ========== ======= ============
""" """
import nfc.clf import src.lib.nfc.clf
from . import pn53x from . import pn53x
import os import os

View File

@ -26,7 +26,7 @@ interface chips, namely the NXP PN531, PN532, PN533 and the Sony
RC-S956. RC-S956.
""" """
import nfc.clf import src.lib.nfc.clf
from . import device from . import device
import os import os
@ -518,7 +518,7 @@ class Device(device.Device):
self.log.debug("disable crc check for type 2 tag") self.log.debug("disable crc check for type 2 tag")
rxmode = self.chipset.read_register("CIU_RxMode") rxmode = self.chipset.read_register("CIU_RxMode")
self.chipset.write_register("CIU_RxMode", rxmode & 0x7F) self.chipset.write_register("CIU_RxMode", rxmode & 0x7F)
return nfc.clf.RemoteTarget( return src.lib.nfc.clf.RemoteTarget(
"106A", sens_res=sens_res, sel_res=sel_res, sdd_res=sdd_res) "106A", sens_res=sens_res, sel_res=sel_res, sdd_res=sdd_res)
if self.chipset.read_register("CIU_FIFOData") == 0x26: if self.chipset.read_register("CIU_FIFOData") == 0x26:
@ -668,15 +668,15 @@ class Device(device.Device):
except Chipset.Error as error: except Chipset.Error as error:
self.log.debug(error) self.log.debug(error)
if error.errno == 1: if error.errno == 1:
raise nfc.clf.TimeoutError raise src.lib.nfc.clf.TimeoutError
else: else:
raise nfc.clf.TransmissionError(str(error)) raise src.lib.nfc.clf.TransmissionError(str(error))
except IOError as error: except IOError as error:
self.log.debug(error) self.log.debug(error)
if not error.errno == errno.ETIMEDOUT: if not error.errno == errno.ETIMEDOUT:
raise error raise error
else: else:
raise nfc.clf.TimeoutError("send_cmd_recv_rsp") raise src.lib.nfc.clf.TimeoutError("send_cmd_recv_rsp")
def _tt1_send_cmd_recv_rsp(self, data, timeout): def _tt1_send_cmd_recv_rsp(self, data, timeout):
cname = self.__class__.__module__ + '.' + self.__class__.__name__ cname = self.__class__.__module__ + '.' + self.__class__.__name__

View File

@ -423,7 +423,7 @@ class TagCommandError(Exception):
def activate(clf, target): def activate(clf, target):
import nfc.clf import src.lib.nfc.clf
try: try:
log.debug("trying to activate {0}".format(target)) log.debug("trying to activate {0}".format(target))
if target.brty.endswith('A'): if target.brty.endswith('A'):
@ -437,32 +437,32 @@ def activate(clf, target):
return activate_tt4(clf, target) return activate_tt4(clf, target)
elif target.brty.endswith('F'): elif target.brty.endswith('F'):
return activate_tt3(clf, target) return activate_tt3(clf, target)
except nfc.clf.CommunicationError: except src.lib.nfc.clf.CommunicationError:
return None return None
def activate_tt1(clf, target): def activate_tt1(clf, target):
log.debug("trying type 1 tag activation for {0}".format(target.brty)) log.debug("trying type 1 tag activation for {0}".format(target.brty))
import nfc.tag.tt1 import src.lib.nfc.tag.tt1
return nfc.tag.tt1.activate(clf, target) return src.lib.nfc.tag.tt1.activate(clf, target)
def activate_tt2(clf, target): def activate_tt2(clf, target):
log.debug("trying type 2 tag activation for {0}".format(target.brty)) log.debug("trying type 2 tag activation for {0}".format(target.brty))
import nfc.tag.tt2 import src.lib.nfc.tag.tt2
return nfc.tag.tt2.activate(clf, target) return src.lib.nfc.tag.tt2.activate(clf, target)
def activate_tt3(clf, target): def activate_tt3(clf, target):
log.debug("trying type 3 tag activation for {0}".format(target.brty)) log.debug("trying type 3 tag activation for {0}".format(target.brty))
import nfc.tag.tt3 import src.lib.nfc.tag.tt3
return nfc.tag.tt3.activate(clf, target) return src.lib.nfc.tag.tt3.activate(clf, target)
def activate_tt4(clf, target): def activate_tt4(clf, target):
log.debug("trying type 4 tag activation for {0}".format(target.brty)) log.debug("trying type 4 tag activation for {0}".format(target.brty))
import nfc.tag.tt4 import src.lib.nfc.tag.tt4
return nfc.tag.tt4.activate(clf, target) return src.lib.nfc.tag.tt4.activate(clf, target)
class TagEmulation(object): class TagEmulation(object):
@ -471,10 +471,10 @@ class TagEmulation(object):
def emulate(clf, target): def emulate(clf, target):
import nfc.clf import src.lib.nfc.clf
assert isinstance(target, nfc.clf.LocalTarget) assert isinstance(target, src.lib.nfc.clf.LocalTarget)
if target.tt3_cmd: if target.tt3_cmd:
import nfc.tag.tt3 import src.lib.nfc.tag.tt3
return nfc.tag.tt3.Type3TagEmulation(clf, target) return src.lib.nfc.tag.tt3.Type3TagEmulation(clf, target)
else: else:
log.debug("can't emulate with %s", target) log.debug("can't emulate with %s", target)

View File

@ -25,7 +25,7 @@ from binascii import hexlify
from struct import pack, unpack from struct import pack, unpack
from . import Tag, TagCommandError from . import Tag, TagCommandError
import nfc.clf import src.lib.nfc.clf
import logging import logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -489,7 +489,7 @@ class Type2Tag(Tag):
self.target.sel_req = self.target.sdd_res[:] self.target.sel_req = self.target.sdd_res[:]
self._target = self.clf.sense(self.target) self._target = self.clf.sense(self.target)
raise Type2TagCommandError( raise Type2TagCommandError(
INVALID_PAGE_ERROR if self.target else nfc.tag.RECEIVE_ERROR) INVALID_PAGE_ERROR if self.target else src.lib.nfc.tag.RECEIVE_ERROR)
if len(data) != 16: if len(data) != 16:
log.debug("invalid response %s", hexlify(data).decode()) log.debug("invalid response %s", hexlify(data).decode())
@ -583,7 +583,7 @@ class Type2Tag(Tag):
# communication. If that failed (tag gone) then any # communication. If that failed (tag gone) then any
# further attempt to transceive() is the same as # further attempt to transceive() is the same as
# "unrecoverable timeout error". # "unrecoverable timeout error".
raise Type2TagCommandError(nfc.tag.TIMEOUT_ERROR) raise Type2TagCommandError(src.lib.nfc.tag.TIMEOUT_ERROR)
started = time.time() started = time.time()
error = None error = None
@ -591,17 +591,17 @@ class Type2Tag(Tag):
try: try:
data = self.clf.exchange(data, timeout) data = self.clf.exchange(data, timeout)
break break
except nfc.clf.CommunicationError as e: except src.lib.nfc.clf.CommunicationError as e:
error = e error = e
reason = error.__class__.__name__ reason = error.__class__.__name__
log.debug("%s after %d retries" % (reason, retry)) log.debug("%s after %d retries" % (reason, retry))
else: else:
if type(error) is nfc.clf.TimeoutError: if type(error) is src.lib.nfc.clf.TimeoutError:
raise Type2TagCommandError(nfc.tag.TIMEOUT_ERROR) raise Type2TagCommandError(src.lib.nfc.tag.TIMEOUT_ERROR)
if type(error) is nfc.clf.TransmissionError: if type(error) is src.lib.nfc.clf.TransmissionError:
raise Type2TagCommandError(nfc.tag.RECEIVE_ERROR) raise Type2TagCommandError(src.lib.nfc.tag.RECEIVE_ERROR)
if type(error) is nfc.clf.ProtocolError: if type(error) is src.lib.nfc.clf.ProtocolError:
raise Type2TagCommandError(nfc.tag.PROTOCOL_ERROR) raise Type2TagCommandError(src.lib.nfc.tag.PROTOCOL_ERROR)
raise RuntimeError("unexpected " + repr(error)) raise RuntimeError("unexpected " + repr(error))
elapsed = time.time() - started elapsed = time.time() - started
@ -686,8 +686,8 @@ def activate(clf, target):
# sel_req we ensure that only the same tag will be found. # sel_req we ensure that only the same tag will be found.
target.sel_req = target.sdd_res[:] target.sel_req = target.sdd_res[:]
if target.sdd_res[0] == 0x04: # NXP if target.sdd_res[0] == 0x04: # NXP
import nfc.tag.tt2_nxp import src.lib.nfc.tag.tt2_nxp
tag = nfc.tag.tt2_nxp.activate(clf, target) tag = src.lib.nfc.tag.tt2_nxp.activate(clf, target)
if tag is not None: if tag is not None:
return tag return tag
else: else:

View File

@ -19,7 +19,7 @@
# See the Licence for the specific language governing # See the Licence for the specific language governing
# permissions and limitations under the Licence. # permissions and limitations under the Licence.
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
import nfc.clf import src.lib.nfc.clf
from . import tt2 from . import tt2
import os import os
@ -742,10 +742,10 @@ def activate(clf, target):
return return
if rsp.startswith(b"\xAF"): if rsp.startswith(b"\xAF"):
return MifareUltralightC(clf, target) return MifareUltralightC(clf, target)
except nfc.clf.TimeoutError: except src.lib.nfc.clf.TimeoutError:
if clf.sense(target) is None: if clf.sense(target) is None:
return return
except nfc.clf.CommunicationError as error: except src.lib.nfc.clf.CommunicationError as error:
log.debug(repr(error)) log.debug(repr(error))
return return
@ -761,10 +761,10 @@ def activate(clf, target):
return NTAG203(clf, target) return NTAG203(clf, target)
log.debug("no match for version %s", hexlify(rsp).decode().upper()) log.debug("no match for version %s", hexlify(rsp).decode().upper())
return return
except nfc.clf.TimeoutError: except src.lib.nfc.clf.TimeoutError:
if clf.sense(target) is None: if clf.sense(target) is None:
return return
except nfc.clf.CommunicationError as error: except src.lib.nfc.clf.CommunicationError as error:
log.debug(repr(error)) log.debug(repr(error))
return return