3 # Example nfcpy to wpa_supplicant wrapper for WPS NFC operations
4 # Copyright (c) 2012, Jouni Malinen <j@w1.fi>
6 # This software may be distributed under the terms of the BSD license.
7 # See README for more details.
18 wpas_ctrl = '/var/run/wpa_supplicant'
20 def wpas_tag_read(message):
22 if os.path.isdir(wpas_ctrl):
24 ifaces = [os.path.join(wpas_ctrl, i) for i in os.listdir(wpas_ctrl)]
25 except OSError, error:
26 print "Could not find wpa_supplicant: ", error
30 print "No wpa_supplicant control interface found"
35 wpas = wpactrl.WPACtrl(ctrl)
36 print wpas.request("WPS_NFC_TAG_READ " + message.encode("hex"))
37 except wpactrl.error, error:
38 print "Error: ", error
42 clf = nfc.ContactlessFrontend()
46 print "Waiting for a tag to be touched"
53 print "Not an NDEF tag"
57 if len(tag.ndef.message):
58 message = nfc.ndef.Message(tag.ndef.message)
59 print "message type " + message.type
61 for record in message:
62 print "record type " + record.type
63 if record.type == "application/vnd.wfa.wsc":
64 print "WPS tag - send to wpa_supplicant"
65 wpas_tag_read(tag.ndef.message)
76 except KeyboardInterrupt:
83 if __name__ == '__main__':