2
* NFC routines for Wi-Fi Protected Setup
3
* Copyright (c) 2009, Masashi Honma <honma@ictec.co.jp>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation.
9
* Alternatively, this software may be distributed under the terms of BSD
12
* See README and COPYING for more details.
23
struct oob_nfc_device_data *oob_nfc_dev;
27
static void * init_nfc(struct wps_context *wps,
28
struct oob_device_data *oob_dev, int registrar)
30
struct oob_nfc_device_data *oob_nfc_dev;
31
struct wps_nfc_data *data;
33
oob_nfc_dev = wps_get_oob_nfc_device(oob_dev->device_name);
34
if (oob_nfc_dev == NULL) {
35
wpa_printf(MSG_ERROR, "WPS (NFC): Unknown NFC device (%s)",
36
oob_dev->device_name);
40
if (oob_nfc_dev->init_func(oob_dev->device_path) < 0)
43
data = os_zalloc(sizeof(*data));
45
wpa_printf(MSG_ERROR, "WPS (NFC): Failed to allocate "
49
data->oob_nfc_dev = oob_nfc_dev;
54
static struct wpabuf * read_nfc(void *priv)
56
struct wps_nfc_data *data = priv;
57
struct wpabuf *wifi, *buf;
61
raw_data = data->oob_nfc_dev->read_func(&len);
65
wifi = wpabuf_alloc_copy(raw_data, len);
68
wpa_printf(MSG_ERROR, "WPS (NFC): Failed to allocate "
73
buf = ndef_parse_wifi(wifi);
76
wpa_printf(MSG_ERROR, "WPS (NFC): Failed to unwrap");
81
static int write_nfc(void *priv, struct wpabuf *buf)
83
struct wps_nfc_data *data = priv;
87
wifi = ndef_build_wifi(buf);
89
wpa_printf(MSG_ERROR, "WPS (NFC): Failed to wrap");
93
ret = data->oob_nfc_dev->write_func(wpabuf_mhead(wifi),
100
static void deinit_nfc(void *priv)
102
struct wps_nfc_data *data = priv;
104
data->oob_nfc_dev->deinit_func();
110
struct oob_device_data oob_nfc_device_data = {
113
.init_func = init_nfc,
114
.read_func = read_nfc,
115
.write_func = write_nfc,
116
.deinit_func = deinit_nfc,