2 * nfc_pw_token - Tool for building NFC password tokens for WPS
3 * Copyright (c) 2012, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
11 #include "utils/common.h"
12 #include "crypto/random.h"
13 #include "wpa_supplicant_i.h"
15 #include "wps_supplicant.h"
18 static void print_bin(const char *title, const struct wpabuf *buf)
28 pos = wpabuf_head(buf);
29 len = wpabuf_len(buf);
30 for (i = 0; i < len; i++)
31 printf("%02X", *pos++);
37 int main(int argc, char *argv[])
39 struct wpa_supplicant wpa_s;
41 struct wpabuf *buf = NULL, *ndef = NULL;
44 if (os_program_init())
48 os_memset(&wpa_s, 0, sizeof(wpa_s));
49 wpa_s.conf = os_zalloc(sizeof(*wpa_s.conf));
50 if (wpa_s.conf == NULL)
53 buf = wpas_wps_nfc_token(&wpa_s, 0);
57 ndef = ndef_build_wifi(buf);
61 wpa_snprintf_hex_uppercase(txt, sizeof(txt), wpabuf_head(buf),
63 printf("#WPS=%s\n", txt);
65 wpa_snprintf_hex_uppercase(txt, sizeof(txt), wpabuf_head(ndef),
67 printf("#NDEF=%s\n", txt);
69 printf("wps_nfc_dev_pw_id=%d\n", wpa_s.conf->wps_nfc_dev_pw_id);
70 print_bin("wps_nfc_dh_pubkey", wpa_s.conf->wps_nfc_dh_pubkey);
71 print_bin("wps_nfc_dh_privkey", wpa_s.conf->wps_nfc_dh_privkey);
72 print_bin("wps_nfc_dev_pw", wpa_s.conf->wps_nfc_dev_pw);
78 wpa_config_free(wpa_s.conf);