|
@@ -33,6 +33,20 @@ no_input = False
|
|
srv = None
|
|
srv = None
|
|
continue_loop = True
|
|
continue_loop = True
|
|
terminate_now = False
|
|
terminate_now = False
|
|
|
|
+summary_file = None
|
|
|
|
+success_file = None
|
|
|
|
+
|
|
|
|
+def summary(txt):
|
|
|
|
+ print txt
|
|
|
|
+ if summary_file:
|
|
|
|
+ with open(summary_file, 'a') as f:
|
|
|
|
+ f.write(txt + "\n")
|
|
|
|
+
|
|
|
|
+def success_report(txt):
|
|
|
|
+ summary(txt)
|
|
|
|
+ if success_file:
|
|
|
|
+ with open(success_file, 'a') as f:
|
|
|
|
+ f.write(txt + "\n")
|
|
|
|
|
|
def wpas_connect():
|
|
def wpas_connect():
|
|
ifaces = []
|
|
ifaces = []
|
|
@@ -63,7 +77,7 @@ def wpas_connect():
|
|
def wpas_tag_read(message):
|
|
def wpas_tag_read(message):
|
|
wpas = wpas_connect()
|
|
wpas = wpas_connect()
|
|
if (wpas == None):
|
|
if (wpas == None):
|
|
- return
|
|
+ return False
|
|
cmd = "WPS_NFC_TAG_READ " + str(message).encode("hex")
|
|
cmd = "WPS_NFC_TAG_READ " + str(message).encode("hex")
|
|
global force_freq
|
|
global force_freq
|
|
if force_freq:
|
|
if force_freq:
|
|
@@ -144,7 +158,7 @@ def p2p_handover_client(llc):
|
|
if include_p2p_req:
|
|
if include_p2p_req:
|
|
data = wpas_get_handover_req()
|
|
data = wpas_get_handover_req()
|
|
if (data == None):
|
|
if (data == None):
|
|
- print "Could not get handover request carrier record from wpa_supplicant"
|
|
+ summary("Could not get handover request carrier record from wpa_supplicant")
|
|
return
|
|
return
|
|
print "Handover request carrier record from wpa_supplicant: " + data.encode("hex")
|
|
print "Handover request carrier record from wpa_supplicant: " + data.encode("hex")
|
|
datamsg = nfc.ndef.Message(data)
|
|
datamsg = nfc.ndef.Message(data)
|
|
@@ -173,31 +187,33 @@ def p2p_handover_client(llc):
|
|
|
|
|
|
client = nfc.handover.HandoverClient(llc)
|
|
client = nfc.handover.HandoverClient(llc)
|
|
try:
|
|
try:
|
|
- print "Trying handover";
|
|
+ summary("Trying to initiate NFC connection handover")
|
|
client.connect()
|
|
client.connect()
|
|
- print "Connected for handover"
|
|
+ summary("Connected for handover")
|
|
except nfc.llcp.ConnectRefused:
|
|
except nfc.llcp.ConnectRefused:
|
|
- print "Handover connection refused"
|
|
+ summary("Handover connection refused")
|
|
client.close()
|
|
client.close()
|
|
return
|
|
return
|
|
except Exception, e:
|
|
except Exception, e:
|
|
- print "Other exception: " + str(e)
|
|
+ summary("Other exception: " + str(e))
|
|
client.close()
|
|
client.close()
|
|
return
|
|
return
|
|
|
|
|
|
- print "Sending handover request"
|
|
+ summary("Sending handover request")
|
|
|
|
|
|
if not client.send(message):
|
|
if not client.send(message):
|
|
- print "Failed to send handover request"
|
|
+ summary("Failed to send handover request")
|
|
|
|
+ client.close()
|
|
|
|
+ return
|
|
|
|
|
|
- print "Receiving handover response"
|
|
+ summary("Receiving handover response")
|
|
message = client._recv()
|
|
message = client._recv()
|
|
if message is None:
|
|
if message is None:
|
|
- print "No response received"
|
|
+ summary("No response received")
|
|
client.close()
|
|
client.close()
|
|
return
|
|
return
|
|
if message.type != "urn:nfc:wkt:Hs":
|
|
if message.type != "urn:nfc:wkt:Hs":
|
|
- print "Response was not Hs - received: " + message.type
|
|
+ summary("Response was not Hs - received: " + message.type)
|
|
client.close()
|
|
client.close()
|
|
return
|
|
return
|
|
|
|
|
|
@@ -208,7 +224,7 @@ def p2p_handover_client(llc):
|
|
print e
|
|
print e
|
|
print str(message).encode("hex")
|
|
print str(message).encode("hex")
|
|
message = nfc.ndef.HandoverSelectMessage(message)
|
|
message = nfc.ndef.HandoverSelectMessage(message)
|
|
- print "Handover select received"
|
|
+ summary("Handover select received")
|
|
try:
|
|
try:
|
|
print message.pretty()
|
|
print message.pretty()
|
|
except Exception, e:
|
|
except Exception, e:
|
|
@@ -218,7 +234,10 @@ def p2p_handover_client(llc):
|
|
print "Remote carrier type: " + carrier.type
|
|
print "Remote carrier type: " + carrier.type
|
|
if carrier.type == "application/vnd.wfa.p2p":
|
|
if carrier.type == "application/vnd.wfa.p2p":
|
|
print "P2P carrier type match - send to wpa_supplicant"
|
|
print "P2P carrier type match - send to wpa_supplicant"
|
|
- wpas_report_handover(data, carrier.record, "INIT")
|
|
+ if "OK" in wpas_report_handover(data, carrier.record, "INIT"):
|
|
|
|
+ success_report("P2P handover reported successfully (initiator)")
|
|
|
|
+ else:
|
|
|
|
+ summary("P2P handover report rejected")
|
|
break
|
|
break
|
|
|
|
|
|
print "Remove peer"
|
|
print "Remove peer"
|
|
@@ -275,8 +294,11 @@ class HandoverServer(nfc.handover.HandoverServer):
|
|
print "Handover select carrier record from wpa_supplicant:"
|
|
print "Handover select carrier record from wpa_supplicant:"
|
|
print data.encode("hex")
|
|
print data.encode("hex")
|
|
self.sent_carrier = data
|
|
self.sent_carrier = data
|
|
- wpas_report_handover(self.received_carrier, self.sent_carrier,
|
|
+ if "OK" in wpas_report_handover(self.received_carrier, self.sent_carrier, "RESP"):
|
|
- "RESP")
|
|
+ success_report("P2P handover reported successfully (responder)")
|
|
|
|
+ else:
|
|
|
|
+ summary("P2P handover report rejected")
|
|
|
|
+ break
|
|
|
|
|
|
message = nfc.ndef.Message(data);
|
|
message = nfc.ndef.Message(data);
|
|
sel.add_carrier(message[0], "active", message[1:])
|
|
sel.add_carrier(message[0], "active", message[1:])
|
|
@@ -302,8 +324,11 @@ class HandoverServer(nfc.handover.HandoverServer):
|
|
print "Handover select carrier record from wpa_supplicant:"
|
|
print "Handover select carrier record from wpa_supplicant:"
|
|
print data.encode("hex")
|
|
print data.encode("hex")
|
|
self.sent_carrier = data
|
|
self.sent_carrier = data
|
|
- wpas_report_handover_wsc(self.received_carrier,
|
|
+ if "OK" in wpas_report_handover_wsc(self.received_carrier, self.sent_carrier, "RESP"):
|
|
- self.sent_carrier, "RESP")
|
|
+ success_report("WSC handover reported successfully")
|
|
|
|
+ else:
|
|
|
|
+ summary("WSC handover report rejected")
|
|
|
|
+ break
|
|
|
|
|
|
message = nfc.ndef.Message(data);
|
|
message = nfc.ndef.Message(data);
|
|
sel.add_carrier(message[0], "active", message[1:])
|
|
sel.add_carrier(message[0], "active", message[1:])
|
|
@@ -317,7 +342,7 @@ class HandoverServer(nfc.handover.HandoverServer):
|
|
print e
|
|
print e
|
|
print str(sel).encode("hex")
|
|
print str(sel).encode("hex")
|
|
|
|
|
|
- print "Sending handover select"
|
|
+ summary("Sending handover select")
|
|
self.success = True
|
|
self.success = True
|
|
return sel
|
|
return sel
|
|
|
|
|
|
@@ -356,23 +381,27 @@ def p2p_tag_read(tag):
|
|
for record in tag.ndef.message:
|
|
for record in tag.ndef.message:
|
|
print "record type " + record.type
|
|
print "record type " + record.type
|
|
if record.type == "application/vnd.wfa.wsc":
|
|
if record.type == "application/vnd.wfa.wsc":
|
|
- print "WPS tag - send to wpa_supplicant"
|
|
+ summary("WPS tag - send to wpa_supplicant")
|
|
success = wpas_tag_read(tag.ndef.message)
|
|
success = wpas_tag_read(tag.ndef.message)
|
|
break
|
|
break
|
|
if record.type == "application/vnd.wfa.p2p":
|
|
if record.type == "application/vnd.wfa.p2p":
|
|
- print "P2P tag - send to wpa_supplicant"
|
|
+ summary("P2P tag - send to wpa_supplicant")
|
|
success = wpas_tag_read(tag.ndef.message)
|
|
success = wpas_tag_read(tag.ndef.message)
|
|
break
|
|
break
|
|
else:
|
|
else:
|
|
- print "Empty tag"
|
|
+ summary("Empty tag")
|
|
|
|
+
|
|
|
|
+ if success:
|
|
|
|
+ success_report("Tag read succeeded")
|
|
|
|
|
|
return success
|
|
return success
|
|
|
|
|
|
|
|
|
|
def rdwr_connected_p2p_write(tag):
|
|
def rdwr_connected_p2p_write(tag):
|
|
- print "Tag found - writing"
|
|
+ summary("Tag found - writing - " + str(tag))
|
|
global p2p_sel_data
|
|
global p2p_sel_data
|
|
tag.ndef.message = str(p2p_sel_data)
|
|
tag.ndef.message = str(p2p_sel_data)
|
|
|
|
+ success_report("Tag write succeeded")
|
|
print "Done - remove tag"
|
|
print "Done - remove tag"
|
|
global only_one
|
|
global only_one
|
|
if only_one:
|
|
if only_one:
|
|
@@ -385,7 +414,7 @@ def wps_write_p2p_handover_sel(clf, wait_remove=True):
|
|
print "Write P2P handover select"
|
|
print "Write P2P handover select"
|
|
data = wpas_get_handover_sel(tag=True)
|
|
data = wpas_get_handover_sel(tag=True)
|
|
if (data == None):
|
|
if (data == None):
|
|
- print "Could not get P2P handover select from wpa_supplicant"
|
|
+ summary("Could not get P2P handover select from wpa_supplicant")
|
|
return
|
|
return
|
|
|
|
|
|
global p2p_sel_wait_remove
|
|
global p2p_sel_wait_remove
|
|
@@ -407,7 +436,7 @@ def wps_write_p2p_handover_sel(clf, wait_remove=True):
|
|
|
|
|
|
def rdwr_connected(tag):
|
|
def rdwr_connected(tag):
|
|
global only_one, no_wait
|
|
global only_one, no_wait
|
|
- print "Tag connected: " + str(tag)
|
|
+ summary("Tag connected: " + str(tag))
|
|
|
|
|
|
if tag.ndef:
|
|
if tag.ndef:
|
|
print "NDEF tag: " + tag.type
|
|
print "NDEF tag: " + tag.type
|
|
@@ -420,7 +449,8 @@ def rdwr_connected(tag):
|
|
global continue_loop
|
|
global continue_loop
|
|
continue_loop = False
|
|
continue_loop = False
|
|
else:
|
|
else:
|
|
- print "Not an NDEF tag - remove tag"
|
|
+ summary("Not an NDEF tag - remove tag")
|
|
|
|
+ return True
|
|
|
|
|
|
return not no_wait
|
|
return not no_wait
|
|
|
|
|
|
@@ -515,6 +545,10 @@ def main():
|
|
help='connection handover only (do not allow tag read)')
|
|
help='connection handover only (do not allow tag read)')
|
|
parser.add_argument('--freq', '-f',
|
|
parser.add_argument('--freq', '-f',
|
|
help='forced frequency of operating channel in MHz')
|
|
help='forced frequency of operating channel in MHz')
|
|
|
|
+ parser.add_argument('--summary',
|
|
|
|
+ help='summary file for writing status updates')
|
|
|
|
+ parser.add_argument('--success',
|
|
|
|
+ help='success file for writing success update')
|
|
parser.add_argument('command', choices=['write-p2p-sel'],
|
|
parser.add_argument('command', choices=['write-p2p-sel'],
|
|
nargs='?')
|
|
nargs='?')
|
|
args = parser.parse_args()
|
|
args = parser.parse_args()
|
|
@@ -542,6 +576,14 @@ def main():
|
|
global include_wps_req
|
|
global include_wps_req
|
|
include_wps_req = False
|
|
include_wps_req = False
|
|
|
|
|
|
|
|
+ if args.summary:
|
|
|
|
+ global summary_file
|
|
|
|
+ summary_file = args.summary
|
|
|
|
+
|
|
|
|
+ if args.success:
|
|
|
|
+ global success_file
|
|
|
|
+ success_file = args.success
|
|
|
|
+
|
|
if args.no_input:
|
|
if args.no_input:
|
|
global no_input
|
|
global no_input
|
|
no_input = True
|
|
no_input = True
|