Skip to content

Commit

Permalink
Add remaining tests for dep module.
Browse files Browse the repository at this point in the history
  • Loading branch information
nehpetsde committed Jun 7, 2017
1 parent 3e2b449 commit 8549382
Show file tree
Hide file tree
Showing 2 changed files with 436 additions and 29 deletions.
11 changes: 8 additions & 3 deletions src/nfc/dep.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ def ATN(did, nad):
if req is None:
return None
elif req.did != self.did:
log.debug("ignore non-matching device identifier")
res = None
elif type(req) == DSL_REQ:
return self.send_res_recv_req(DSL_RES(self.did), 0)
Expand All @@ -596,6 +597,9 @@ def ATN(did, nad):
res = dep_res
else:
dep_req = req
else:
log.debug("invalid command in data exchange context")
res = None
return dep_req

def send_res_recv_req(self, res, deadline):
Expand Down Expand Up @@ -732,15 +736,16 @@ def decode(cls, data):
if data.startswith(cls.PDU_CODE):
try:
return cls(*data[2:])
except ValueError:
except TypeError:
errstr = "invalid format of the " + cls.PDU_NAME
raise nfc.clf.ProtocolError(errstr)


class PSL_REQ(PSL_REQ_RES):
PDU_CODE = bytearray(b'\xD4\x04')
PDU_NAME = 'PSL-REQ'
PDU_SHOW = "{name} DID={self.did} BRS={self.brs:02x}, FSL={self.fsl:02x}"
PDU_SHOW = "{name} DID={self.did:02x} BRS={self.brs:02x} " \
"FSL={self.fsl:02x}"

def __init__(self, did, brs, fsl):
self.did, self.brs, self.fsl = did if did else 0, brs, fsl
Expand All @@ -764,7 +769,7 @@ def lr(self):
class PSL_RES(PSL_REQ_RES):
PDU_CODE = bytearray(b'\xD5\x05')
PDU_NAME = 'PSL-RES'
PDU_SHOW = "{name} DID={self.did}"
PDU_SHOW = "{name} DID={self.did:02x}"

def __init__(self, did):
self.did = did
Expand Down

0 comments on commit 8549382

Please sign in to comment.