int main(int argc, char *argv[]) { struct wpa_supplicant wpa_s; int ret = -1; struct wpabuf *buf = NULL, *ndef = NULL; char txt[1000]; if (os_program_init()) return -1; random_init(NULL); os_memset(&wpa_s, 0, sizeof(wpa_s)); wpa_s.conf = os_zalloc(sizeof(*wpa_s.conf)); if (wpa_s.conf == NULL) goto fail; buf = wpas_wps_nfc_token(&wpa_s, 0); if (buf == NULL) goto fail; ndef = ndef_build_wifi(buf); if (ndef == NULL) goto fail; wpa_snprintf_hex_uppercase(txt, sizeof(txt), wpabuf_head(buf), wpabuf_len(buf)); printf("#WPS=%s\n", txt); wpa_snprintf_hex_uppercase(txt, sizeof(txt), wpabuf_head(ndef), wpabuf_len(ndef)); printf("#NDEF=%s\n", txt); printf("wps_nfc_dev_pw_id=%d\n", wpa_s.conf->wps_nfc_dev_pw_id); print_bin("wps_nfc_dh_pubkey", wpa_s.conf->wps_nfc_dh_pubkey); print_bin("wps_nfc_dh_privkey", wpa_s.conf->wps_nfc_dh_privkey); print_bin("wps_nfc_dev_pw", wpa_s.conf->wps_nfc_dev_pw); ret = 0; fail: wpabuf_free(ndef); wpabuf_free(buf); wpa_config_free(wpa_s.conf); random_deinit(); os_program_deinit(); return ret; }
static int write_nfc(void *priv, struct wpabuf *buf) { struct wps_nfc_data *data = priv; struct wpabuf *wifi; int ret; wifi = ndef_build_wifi(buf); if (wifi == NULL) { wpa_printf(MSG_ERROR, "WPS (NFC): Failed to wrap"); return -1; } ret = data->oob_nfc_dev->write_func(wpabuf_mhead(wifi), wpabuf_len(wifi)); wpabuf_free(wifi); return ret; }
struct wpabuf * hostapd_wps_nfc_config_token(struct hostapd_data *hapd, int ndef) { struct wpabuf *ret; if (hapd->wps == NULL) return NULL; ret = wps_get_oob_cred(hapd->wps); if (ndef && ret) { struct wpabuf *tmp; tmp = ndef_build_wifi(ret); wpabuf_free(ret); if (tmp == NULL) return NULL; ret = tmp; } return ret; }
struct wpabuf * wps_nfc_token_build(int ndef, int id, struct wpabuf *pubkey, struct wpabuf *dev_pw) { struct wpabuf *ret; if (pubkey == NULL || dev_pw == NULL) return NULL; ret = wps_build_nfc_pw_token(id, pubkey, dev_pw); if (ndef && ret) { struct wpabuf *tmp; tmp = ndef_build_wifi(ret); wpabuf_free(ret); if (tmp == NULL) return NULL; ret = tmp; } return ret; }