mirror of
https://github.com/vanhoefm/fragattacks.git
synced 2024-11-26 17:28:29 -05:00
e1ee6b600b
The new file wps_nfc.c and ndef.c implements NFC device independent operation, wps_nfc_pn531.c implements NFC device dependent operation. This patch is only for the following use case: - Enrollee = wpa_supplicant - Registrar = hostapd internal Registrar Following NFC methods can be used: - Enrollee PIN with NFC - Registrar PIN with NFC - unencrypted credential with NFC Encrypted credentials are not supported. Enrollee side operation: Registrar side operation: Example configuration. CONFIG_WPS=y CONFIG_WPS_NFC=y CONFIG_WPS_NFC_PN531=y I used NFC device "NXP PN531". The NFC device access method is confidential, so I used outer library. Please download below files from https://www.saice-wpsnfc.bz/index.php [WPS NFC Library] WpsNfcLibrary/WpsNfc.h WpsNfcLibrary/WpsNfcType.h WpsNfcLibrary/WpsNfcVersion.h WpsNfcLibrary/linux/libnfc_mapping_pn53x.dll WpsNfcLibrary/linux/wpsnfc.dll [NFC Reader/Writer Kernel Driver] NFCKernelDriver-1.0.3/linux/kobj/sonyrw.ko <WiFi test> The hostapd/wpa_supplicant with this patch passed below tests on "Wi-Fi WPS Test Plan Version 1.6". 4.2.5 Add device using NFC Method with password token (I used SONY STA instead of NXP STA.) 4.2.6 Add device using NFC Method with configuration token 5.1.9 Add to AP using NFC Method with password token through internal registrar (I used SONY AP instead of NXP AP.) 5.1.10 Add to AP using NFC Method with configuration token through internal registrar
114 lines
2.3 KiB
C
114 lines
2.3 KiB
C
/*
|
|
* NFC PN531 routines for Wi-Fi Protected Setup
|
|
* Copyright (c) 2009, Masashi Honma <honma@ictec.co.jp>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*
|
|
* Alternatively, this software may be distributed under the terms of BSD
|
|
* license.
|
|
*
|
|
* See README and COPYING for more details.
|
|
*/
|
|
|
|
#include "includes.h"
|
|
#include "common.h"
|
|
|
|
#include "wps/wps.h"
|
|
#include "wps_i.h"
|
|
|
|
#include "WpsNfcType.h"
|
|
#include "WpsNfc.h"
|
|
|
|
|
|
static int init_nfc_pn531(char *path)
|
|
{
|
|
u32 ret;
|
|
|
|
ret = WpsNfcInit();
|
|
if (ret != WPS_NFCLIB_ERR_SUCCESS) {
|
|
wpa_printf(MSG_ERROR, "WPS (PN531): Failed to initialize "
|
|
"NFC Library: 0x%08x", ret);
|
|
return -1;
|
|
}
|
|
|
|
ret = WpsNfcOpenDevice((int8 *) path);
|
|
if (ret != WPS_NFCLIB_ERR_SUCCESS) {
|
|
wpa_printf(MSG_ERROR, "WPS (PN531): Failed to open "
|
|
"NFC Device(%s): 0x%08x", path, ret);
|
|
goto fail;
|
|
}
|
|
|
|
ret = WpsNfcTokenDiscovery();
|
|
if (ret != WPS_NFCLIB_ERR_SUCCESS) {
|
|
wpa_printf(MSG_ERROR, "WPS (PN531): Failed to discover "
|
|
"token: 0x%08x", ret);
|
|
WpsNfcCloseDevice();
|
|
goto fail;
|
|
}
|
|
|
|
return 0;
|
|
|
|
fail:
|
|
WpsNfcDeinit();
|
|
return -1;
|
|
}
|
|
|
|
|
|
static void * read_nfc_pn531(size_t *size)
|
|
{
|
|
uint32 len;
|
|
u32 ret;
|
|
int8 *data;
|
|
|
|
ret = WpsNfcRawReadToken(&data, &len);
|
|
if (ret != WPS_NFCLIB_ERR_SUCCESS) {
|
|
wpa_printf(MSG_ERROR, "WPS (PN531): Failed to read: 0x%08x",
|
|
ret);
|
|
return NULL;
|
|
}
|
|
|
|
*size = len;
|
|
return data;
|
|
}
|
|
|
|
|
|
static int write_nfc_pn531(void *data, size_t len)
|
|
{
|
|
u32 ret;
|
|
|
|
ret = WpsNfcRawWriteToken(data, len);
|
|
if (ret != WPS_NFCLIB_ERR_SUCCESS) {
|
|
wpa_printf(MSG_ERROR, "WPS (PN531): Failed to write: 0x%08x",
|
|
ret);
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
static void deinit_nfc_pn531(void)
|
|
{
|
|
u32 ret;
|
|
|
|
ret = WpsNfcCloseDevice();
|
|
if (ret != WPS_NFCLIB_ERR_SUCCESS)
|
|
wpa_printf(MSG_ERROR, "WPS (PN531): Failed to close "
|
|
"NFC Device: 0x%08x", ret);
|
|
|
|
ret = WpsNfcDeinit();
|
|
if (ret != WPS_NFCLIB_ERR_SUCCESS)
|
|
wpa_printf(MSG_ERROR, "WPS (PN531): Failed to deinitialize "
|
|
"NFC Library: 0x%08x", ret);
|
|
}
|
|
|
|
|
|
struct oob_nfc_device_data oob_nfc_pn531_device_data = {
|
|
.init_func = init_nfc_pn531,
|
|
.read_func = read_nfc_pn531,
|
|
.write_func = write_nfc_pn531,
|
|
.deinit_func = deinit_nfc_pn531,
|
|
};
|