fragattacks/src/wps/wps_nfc.c
Masashi Honma e1ee6b600b WPS: Add support for NFC out-of-band mechanism
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
2009-03-06 16:16:22 +02:00

118 lines
2.4 KiB
C

/*
* NFC 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"
struct wps_nfc_data {
struct oob_nfc_device_data *oob_nfc_dev;
};
static void * init_nfc(struct wps_context *wps,
struct oob_device_data *oob_dev, int registrar)
{
struct oob_nfc_device_data *oob_nfc_dev;
struct wps_nfc_data *data;
oob_nfc_dev = wps_get_oob_nfc_device(oob_dev->device_name);
if (oob_nfc_dev == NULL) {
wpa_printf(MSG_ERROR, "WPS (NFC): Unknown NFC device (%s)",
oob_dev->device_name);
return NULL;
}
if (oob_nfc_dev->init_func(oob_dev->device_path) < 0)
return NULL;
data = os_zalloc(sizeof(*data));
if (data == NULL) {
wpa_printf(MSG_ERROR, "WPS (NFC): Failed to allocate "
"nfc data area");
return NULL;
}
data->oob_nfc_dev = oob_nfc_dev;
return data;
}
static struct wpabuf * read_nfc(void *priv)
{
struct wps_nfc_data *data = priv;
struct wpabuf *wifi, *buf;
char *raw_data;
size_t len;
raw_data = data->oob_nfc_dev->read_func(&len);
if (raw_data == NULL)
return NULL;
wifi = wpabuf_alloc_copy(raw_data, len);
os_free(raw_data);
if (wifi == NULL) {
wpa_printf(MSG_ERROR, "WPS (NFC): Failed to allocate "
"nfc read area");
return NULL;
}
buf = ndef_parse_wifi(wifi);
wpabuf_free(wifi);
if (buf == NULL)
wpa_printf(MSG_ERROR, "WPS (NFC): Failed to unwrap");
return buf;
}
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;
}
static void deinit_nfc(void *priv)
{
struct wps_nfc_data *data = priv;
data->oob_nfc_dev->deinit_func();
os_free(data);
}
struct oob_device_data oob_nfc_device_data = {
.device_name = NULL,
.device_path = NULL,
.init_func = init_nfc,
.read_func = read_nfc,
.write_func = write_nfc,
.deinit_func = deinit_nfc,
};