Skip to content

Commit

Permalink
Add some listen tests for udp device.
Browse files Browse the repository at this point in the history
  • Loading branch information
nehpetsde committed Apr 8, 2017
1 parent 39aad24 commit 3d7721f
Show file tree
Hide file tree
Showing 2 changed files with 301 additions and 40 deletions.
10 changes: 9 additions & 1 deletion src/nfc/clf/udp.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ def _listen_tta(self, target, time_to_return, init=None):
brty, data, addr = self._recv_data(wait, target.brty)
except nfc.clf.TimeoutError:
return None
except nfc.clf.CommunicationError:
continue
else:
(brty, data, addr), init = init, None
if data == "\x26":
Expand Down Expand Up @@ -271,7 +273,7 @@ def _listen_tta(self, target, time_to_return, init=None):
self._send_data(brty, sel_res, addr)
elif data == "\x95\x70" + sdd_res[10:15]:
log.debug("rcvd SEL_REQ CL3 %s", hexlify(data))
sel_res[0] = (sel_res[0] & 0xFB)
sel_res[0] = (sel_res[0] & 0xFB) | (len(sdd_res) > 15) << 2
log.debug("send SEL_RES %s", hexlify(sel_res))
self._send_data(brty, sel_res, addr)
elif sel_res[0] & 0b00000100 == 0:
Expand Down Expand Up @@ -307,6 +309,8 @@ def listen_ttb(self, target, timeout):
brty, data, addr = self._recv_data(wait, target.brty)
except nfc.clf.TimeoutError:
return None
except nfc.clf.CommunicationError:
continue
if data and len(data) == 3 and data.startswith('\x05'):
req = "ALLB_REQ" if data[1] & 0x08 else "SENSB_REQ"
sensb_req = data
Expand Down Expand Up @@ -341,6 +345,8 @@ def _listen_ttf(self, target, time_to_return, init=None):
brty, data, addr = self._recv_data(wait, target.brty)
except nfc.clf.TimeoutError:
return None
except nfc.clf.CommunicationError:
continue
else:
(brty, data, addr), init = init, None
if data and len(data) == data[0]:
Expand All @@ -357,6 +363,8 @@ def _listen_ttf(self, target, time_to_return, init=None):
data += "\x00" + chr(1 << (target.brty == "424F"))
data = chr(len(data)+1) + data
self._send_data(brty, data, addr)
else:
sensf_req = sensf_res = None
elif sensf_req and sensf_res:
if data[2:10] == target.sensf_res[1:9]:
target = nfc.clf.LocalTarget(brty, _addr=addr)
Expand Down

0 comments on commit 3d7721f

Please sign in to comment.