From 9f36eac6e54e3a6c8378c89dcc7daee6a3a9d314 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sun, 28 Oct 2012 18:20:03 +0200 Subject: [PATCH] WPS: Remove old OOB NFC interface The old WPS interface for using NFC has no known deployments and even the binary libraries referenced here are not easily available anymore. Since the new interface for using NFC with WPS covers the same functionality, remove the old implementation to clean up WPS implementation. Signed-hostap: Jouni Malinen --- hostapd/Android.mk | 9 --- hostapd/Makefile | 9 --- hostapd/ctrl_iface.c | 8 +-- hostapd/hostapd_cli.c | 18 ++---- src/ap/wps_hostapd.c | 3 +- src/ap/wps_hostapd.h | 2 +- src/wps/wps.h | 9 --- src/wps/wps_common.c | 19 ------ src/wps/wps_i.h | 2 - src/wps/wps_nfc.c | 111 -------------------------------- src/wps/wps_nfc_pn531.c | 107 ------------------------------ src/wps/wps_ufd.c | 1 - wpa_supplicant/Android.mk | 9 --- wpa_supplicant/Makefile | 9 --- wpa_supplicant/ctrl_iface.c | 8 +-- wpa_supplicant/wpa_cli.c | 12 ++-- wpa_supplicant/wps_supplicant.c | 3 +- wpa_supplicant/wps_supplicant.h | 2 +- 18 files changed, 19 insertions(+), 322 deletions(-) delete mode 100644 src/wps/wps_nfc.c delete mode 100644 src/wps/wps_nfc_pn531.c diff --git a/hostapd/Android.mk b/hostapd/Android.mk index 475bdd8f1..7c29a5f65 100644 --- a/hostapd/Android.mk +++ b/hostapd/Android.mk @@ -378,16 +378,7 @@ endif ifdef CONFIG_WPS_NFC L_CFLAGS += -DCONFIG_WPS_NFC OBJS += src/wps/ndef.c -OBJS += src/wps/wps_nfc.c NEED_WPS_OOB=y -ifdef CONFIG_WPS_NFC_PN531 -PN531_PATH ?= /usr/local/src/nfc -L_CFLAGS += -DCONFIG_WPS_NFC_PN531 -L_CFLAGS += -I${PN531_PATH}/inc -OBJS += src/wps/wps_nfc_pn531.c -LIBS += ${PN531_PATH}/lib/wpsnfc.dll -LIBS += ${PN531_PATH}/lib/libnfc_mapping_pn53x.dll -endif endif ifdef NEED_WPS_OOB diff --git a/hostapd/Makefile b/hostapd/Makefile index 277e1d462..e3d9e6937 100644 --- a/hostapd/Makefile +++ b/hostapd/Makefile @@ -370,16 +370,7 @@ endif ifdef CONFIG_WPS_NFC CFLAGS += -DCONFIG_WPS_NFC OBJS += ../src/wps/ndef.o -OBJS += ../src/wps/wps_nfc.o NEED_WPS_OOB=y -ifdef CONFIG_WPS_NFC_PN531 -PN531_PATH ?= /usr/local/src/nfc -CFLAGS += -DCONFIG_WPS_NFC_PN531 -CFLAGS += -I${PN531_PATH}/inc -OBJS += ../src/wps/wps_nfc_pn531.o -LIBS += ${PN531_PATH}/lib/wpsnfc.dll -LIBS += ${PN531_PATH}/lib/libnfc_mapping_pn53x.dll -endif endif ifdef NEED_WPS_OOB diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c index 1b8bede1a..2faef7af6 100644 --- a/hostapd/ctrl_iface.c +++ b/hostapd/ctrl_iface.c @@ -253,7 +253,7 @@ static int hostapd_ctrl_iface_wps_check_pin( #ifdef CONFIG_WPS_OOB static int hostapd_ctrl_iface_wps_oob(struct hostapd_data *hapd, char *txt) { - char *path, *method, *name; + char *path, *method; path = os_strchr(txt, ' '); if (path == NULL) @@ -265,11 +265,7 @@ static int hostapd_ctrl_iface_wps_oob(struct hostapd_data *hapd, char *txt) return -1; *method++ = '\0'; - name = os_strchr(method, ' '); - if (name != NULL) - *name++ = '\0'; - - return hostapd_wps_start_oob(hapd, txt, path, method, name); + return hostapd_wps_start_oob(hapd, txt, path, method); } #endif /* CONFIG_WPS_OOB */ diff --git a/hostapd/hostapd_cli.c b/hostapd/hostapd_cli.c index aed981c43..54e9b705b 100644 --- a/hostapd/hostapd_cli.c +++ b/hostapd/hostapd_cli.c @@ -412,24 +412,18 @@ static int hostapd_cli_cmd_wps_oob(struct wpa_ctrl *ctrl, int argc, char cmd[256]; int res; - if (argc != 3 && argc != 4) { - printf("Invalid WPS_OOB command: need three or four " + if (argc != 3) { + printf("Invalid WPS_OOB command: need three " "arguments:\n" - "- DEV_TYPE: use 'ufd' or 'nfc'\n" + "- DEV_TYPE: use 'ufd'\n" "- PATH: path of OOB device like '/mnt'\n" "- METHOD: OOB method 'pin-e' or 'pin-r', " - "'cred'\n" - "- DEV_NAME: (only for NFC) device name like " - "'pn531'\n"); + "'cred'\n"); return -1; } - if (argc == 3) - res = os_snprintf(cmd, sizeof(cmd), "WPS_OOB %s %s %s", - argv[0], argv[1], argv[2]); - else - res = os_snprintf(cmd, sizeof(cmd), "WPS_OOB %s %s %s %s", - argv[0], argv[1], argv[2], argv[3]); + res = os_snprintf(cmd, sizeof(cmd), "WPS_OOB %s %s %s", + argv[0], argv[1], argv[2]); if (res < 0 || (size_t) res >= sizeof(cmd) - 1) { printf("Too long WPS_OOB command.\n"); return -1; diff --git a/src/ap/wps_hostapd.c b/src/ap/wps_hostapd.c index 5e44c72c5..ffef16eb6 100644 --- a/src/ap/wps_hostapd.c +++ b/src/ap/wps_hostapd.c @@ -1157,7 +1157,7 @@ int hostapd_wps_cancel(struct hostapd_data *hapd) #ifdef CONFIG_WPS_OOB int hostapd_wps_start_oob(struct hostapd_data *hapd, char *device_type, - char *path, char *method, char *name) + char *path, char *method) { struct wps_context *wps = hapd->wps; struct oob_device_data *oob_dev; @@ -1166,7 +1166,6 @@ int hostapd_wps_start_oob(struct hostapd_data *hapd, char *device_type, if (oob_dev == NULL) return -1; oob_dev->device_path = path; - oob_dev->device_name = name; wps->oob_conf.oob_method = wps_get_oob_method(method); if (wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_R) { diff --git a/src/ap/wps_hostapd.h b/src/ap/wps_hostapd.h index f968e151f..b9c9530df 100644 --- a/src/ap/wps_hostapd.h +++ b/src/ap/wps_hostapd.h @@ -22,7 +22,7 @@ int hostapd_wps_button_pushed(struct hostapd_data *hapd, const u8 *p2p_dev_addr); int hostapd_wps_cancel(struct hostapd_data *hapd); int hostapd_wps_start_oob(struct hostapd_data *hapd, char *device_type, - char *path, char *method, char *name); + char *path, char *method); int hostapd_wps_get_mib_sta(struct hostapd_data *hapd, const u8 *addr, char *buf, size_t buflen); void hostapd_wps_ap_pin_disable(struct hostapd_data *hapd); diff --git a/src/wps/wps.h b/src/wps/wps.h index 74304dc23..9ebbbf87a 100644 --- a/src/wps/wps.h +++ b/src/wps/wps.h @@ -767,7 +767,6 @@ struct wps_context { }; struct oob_device_data { - char *device_name; char *device_path; void * (*init_func)(struct wps_context *, struct oob_device_data *, int); @@ -776,13 +775,6 @@ struct oob_device_data { void (*deinit_func)(void *); }; -struct oob_nfc_device_data { - int (*init_func)(char *); - void * (*read_func)(size_t *); - int (*write_func)(void *, size_t); - void (*deinit_func)(void); -}; - struct wps_registrar * wps_registrar_init(struct wps_context *wps, const struct wps_registrar_config *cfg); @@ -822,7 +814,6 @@ int wps_pin_str_valid(const char *pin); void wps_free_pending_msgs(struct upnp_pending_message *msgs); struct oob_device_data * wps_get_oob_device(char *device_type); -struct oob_nfc_device_data * wps_get_oob_nfc_device(char *device_name); int wps_get_oob_method(char *method); int wps_process_oob(struct wps_context *wps, struct oob_device_data *oob_dev, int registrar); diff --git a/src/wps/wps_common.c b/src/wps/wps_common.c index 5a8817f26..f48bd3bd8 100644 --- a/src/wps/wps_common.c +++ b/src/wps/wps_common.c @@ -543,30 +543,11 @@ struct oob_device_data * wps_get_oob_device(char *device_type) if (os_strstr(device_type, "ufd") != NULL) return &oob_ufd_device_data; #endif /* CONFIG_WPS_UFD */ -#ifdef CONFIG_WPS_NFC - if (os_strstr(device_type, "nfc") != NULL) - return &oob_nfc_device_data; -#endif /* CONFIG_WPS_NFC */ return NULL; } -#ifdef CONFIG_WPS_NFC -struct oob_nfc_device_data * wps_get_oob_nfc_device(char *device_name) -{ - if (device_name == NULL) - return NULL; -#ifdef CONFIG_WPS_NFC_PN531 - if (os_strstr(device_name, "pn531") != NULL) - return &oob_nfc_pn531_device_data; -#endif /* CONFIG_WPS_NFC_PN531 */ - - return NULL; -} -#endif /* CONFIG_WPS_NFC */ - - int wps_get_oob_method(char *method) { if (os_strstr(method, "pin-e") != NULL) diff --git a/src/wps/wps_i.h b/src/wps/wps_i.h index 86ad248d3..e89424b04 100644 --- a/src/wps/wps_i.h +++ b/src/wps/wps_i.h @@ -138,8 +138,6 @@ void wps_pbc_overlap_event(struct wps_context *wps); void wps_pbc_timeout_event(struct wps_context *wps); extern struct oob_device_data oob_ufd_device_data; -extern struct oob_device_data oob_nfc_device_data; -extern struct oob_nfc_device_data oob_nfc_pn531_device_data; struct wpabuf * wps_build_wsc_ack(struct wps_data *wps); struct wpabuf * wps_build_wsc_nack(struct wps_data *wps); diff --git a/src/wps/wps_nfc.c b/src/wps/wps_nfc.c deleted file mode 100644 index 680435039..000000000 --- a/src/wps/wps_nfc.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * NFC routines for Wi-Fi Protected Setup - * Copyright (c) 2009-2012, Masashi Honma - * - * This software may be distributed under the terms of the BSD license. - * See README 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, -}; diff --git a/src/wps/wps_nfc_pn531.c b/src/wps/wps_nfc_pn531.c deleted file mode 100644 index c2bf4570b..000000000 --- a/src/wps/wps_nfc_pn531.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - * NFC PN531 routines for Wi-Fi Protected Setup - * Copyright (c) 2009-2012, Masashi Honma - * - * This software may be distributed under the terms of the BSD license. - * See README 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, -}; diff --git a/src/wps/wps_ufd.c b/src/wps/wps_ufd.c index f83bdf471..6b51e6656 100644 --- a/src/wps/wps_ufd.c +++ b/src/wps/wps_ufd.c @@ -221,7 +221,6 @@ static void deinit_ufd(void *priv) struct oob_device_data oob_ufd_device_data = { - .device_name = NULL, .device_path = NULL, .init_func = init_ufd, .read_func = read_ufd, diff --git a/wpa_supplicant/Android.mk b/wpa_supplicant/Android.mk index cc334c8c2..d486a32ae 100644 --- a/wpa_supplicant/Android.mk +++ b/wpa_supplicant/Android.mk @@ -593,16 +593,7 @@ endif ifdef CONFIG_WPS_NFC L_CFLAGS += -DCONFIG_WPS_NFC OBJS += src/wps/ndef.c -OBJS += src/wps/wps_nfc.c NEED_WPS_OOB=y -ifdef CONFIG_WPS_NFC_PN531 -PN531_PATH ?= /usr/local/src/nfc -L_CFLAGS += -DCONFIG_WPS_NFC_PN531 -L_CFLAGS += -I${PN531_PATH}/inc -OBJS += src/wps/wps_nfc_pn531.c -LIBS += ${PN531_PATH}/lib/wpsnfc.dll -LIBS += ${PN531_PATH}/lib/libnfc_mapping_pn53x.dll -endif endif ifdef NEED_WPS_OOB diff --git a/wpa_supplicant/Makefile b/wpa_supplicant/Makefile index 9684cfad9..b33aa8f3a 100644 --- a/wpa_supplicant/Makefile +++ b/wpa_supplicant/Makefile @@ -601,16 +601,7 @@ endif ifdef CONFIG_WPS_NFC CFLAGS += -DCONFIG_WPS_NFC OBJS += ../src/wps/ndef.o -OBJS += ../src/wps/wps_nfc.o NEED_WPS_OOB=y -ifdef CONFIG_WPS_NFC_PN531 -PN531_PATH ?= /usr/local/src/nfc -CFLAGS += -DCONFIG_WPS_NFC_PN531 -CFLAGS += -I${PN531_PATH}/inc -OBJS += ../src/wps/wps_nfc_pn531.o -LIBS += ${PN531_PATH}/lib/wpsnfc.dll -LIBS += ${PN531_PATH}/lib/libnfc_mapping_pn53x.dll -endif endif ifdef NEED_WPS_OOB diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c index 21b0e17b3..2f0b38c78 100644 --- a/wpa_supplicant/ctrl_iface.c +++ b/wpa_supplicant/ctrl_iface.c @@ -754,7 +754,7 @@ static int wpa_supplicant_ctrl_iface_wps_check_pin( static int wpa_supplicant_ctrl_iface_wps_oob(struct wpa_supplicant *wpa_s, char *cmd) { - char *path, *method, *name; + char *path, *method; path = os_strchr(cmd, ' '); if (path == NULL) @@ -766,11 +766,7 @@ static int wpa_supplicant_ctrl_iface_wps_oob(struct wpa_supplicant *wpa_s, return -1; *method++ = '\0'; - name = os_strchr(method, ' '); - if (name != NULL) - *name++ = '\0'; - - return wpas_wps_start_oob(wpa_s, cmd, path, method, name); + return wpas_wps_start_oob(wpa_s, cmd, path, method); } #endif /* CONFIG_WPS_OOB */ diff --git a/wpa_supplicant/wpa_cli.c b/wpa_supplicant/wpa_cli.c index f7e622776..eda41e781 100644 --- a/wpa_supplicant/wpa_cli.c +++ b/wpa_supplicant/wpa_cli.c @@ -739,15 +739,13 @@ static int wpa_cli_cmd_wps_cancel(struct wpa_ctrl *ctrl, int argc, #ifdef CONFIG_WPS_OOB static int wpa_cli_cmd_wps_oob(struct wpa_ctrl *ctrl, int argc, char *argv[]) { - if (argc != 3 && argc != 4) { - printf("Invalid WPS_OOB command: need three or four " + if (argc != 3) { + printf("Invalid WPS_OOB command: need three " "arguments:\n" - "- DEV_TYPE: use 'ufd' or 'nfc'\n" + "- DEV_TYPE: use 'ufd'\n" "- PATH: path of OOB device like '/mnt'\n" "- METHOD: OOB method 'pin-e' or 'pin-r', " - "'cred'\n" - "- DEV_NAME: (only for NFC) device name like " - "'pn531'\n"); + "'cred'\n"); return -1; } @@ -2490,7 +2488,7 @@ static struct wpa_cli_cmd wpa_cli_commands[] = { #ifdef CONFIG_WPS_OOB { "wps_oob", wpa_cli_cmd_wps_oob, NULL, cli_cmd_flag_sensitive, - " [DEV_NAME] = start WPS OOB" }, + " = start WPS OOB" }, #endif /* CONFIG_WPS_OOB */ #ifdef CONFIG_WPS_NFC { "wps_nfc", wpa_cli_cmd_wps_nfc, wpa_cli_complete_bss, diff --git a/wpa_supplicant/wps_supplicant.c b/wpa_supplicant/wps_supplicant.c index 5977e1a1a..41aa5dbd7 100644 --- a/wpa_supplicant/wps_supplicant.c +++ b/wpa_supplicant/wps_supplicant.c @@ -996,7 +996,7 @@ int wpas_wps_cancel(struct wpa_supplicant *wpa_s) #ifdef CONFIG_WPS_OOB int wpas_wps_start_oob(struct wpa_supplicant *wpa_s, char *device_type, - char *path, char *method, char *name) + char *path, char *method) { struct wps_context *wps = wpa_s->wps; struct oob_device_data *oob_dev; @@ -1005,7 +1005,6 @@ int wpas_wps_start_oob(struct wpa_supplicant *wpa_s, char *device_type, if (oob_dev == NULL) return -1; oob_dev->device_path = path; - oob_dev->device_name = name; wps->oob_conf.oob_method = wps_get_oob_method(method); if (wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_E) { diff --git a/wpa_supplicant/wps_supplicant.h b/wpa_supplicant/wps_supplicant.h index 2a3fea0c9..4737f24a2 100644 --- a/wpa_supplicant/wps_supplicant.h +++ b/wpa_supplicant/wps_supplicant.h @@ -36,7 +36,7 @@ int wpas_wps_start_pin(struct wpa_supplicant *wpa_s, const u8 *bssid, const char *pin, int p2p_group, u16 dev_pw_id); int wpas_wps_cancel(struct wpa_supplicant *wpa_s); int wpas_wps_start_oob(struct wpa_supplicant *wpa_s, char *device_type, - char *path, char *method, char *name); + char *path, char *method); int wpas_wps_start_reg(struct wpa_supplicant *wpa_s, const u8 *bssid, const char *pin, struct wps_new_ap_settings *settings); int wpas_wps_ssid_bss_match(struct wpa_supplicant *wpa_s,