2 * NFC routines for Wi-Fi Protected Setup
3 * Copyright (c) 2009-2012, Masashi Honma <masashi.honma@gmail.com>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
17 struct oob_nfc_device_data *oob_nfc_dev;
21 static void * init_nfc(struct wps_context *wps,
22 struct oob_device_data *oob_dev, int registrar)
24 struct oob_nfc_device_data *oob_nfc_dev;
25 struct wps_nfc_data *data;
27 oob_nfc_dev = wps_get_oob_nfc_device(oob_dev->device_name);
28 if (oob_nfc_dev == NULL) {
29 wpa_printf(MSG_ERROR, "WPS (NFC): Unknown NFC device (%s)",
30 oob_dev->device_name);
34 if (oob_nfc_dev->init_func(oob_dev->device_path) < 0)
37 data = os_zalloc(sizeof(*data));
39 wpa_printf(MSG_ERROR, "WPS (NFC): Failed to allocate "
43 data->oob_nfc_dev = oob_nfc_dev;
48 static struct wpabuf * read_nfc(void *priv)
50 struct wps_nfc_data *data = priv;
51 struct wpabuf *wifi, *buf;
55 raw_data = data->oob_nfc_dev->read_func(&len);
59 wifi = wpabuf_alloc_copy(raw_data, len);
62 wpa_printf(MSG_ERROR, "WPS (NFC): Failed to allocate "
67 buf = ndef_parse_wifi(wifi);
70 wpa_printf(MSG_ERROR, "WPS (NFC): Failed to unwrap");
75 static int write_nfc(void *priv, struct wpabuf *buf)
77 struct wps_nfc_data *data = priv;
81 wifi = ndef_build_wifi(buf);
83 wpa_printf(MSG_ERROR, "WPS (NFC): Failed to wrap");
87 ret = data->oob_nfc_dev->write_func(wpabuf_mhead(wifi),
94 static void deinit_nfc(void *priv)
96 struct wps_nfc_data *data = priv;
98 data->oob_nfc_dev->deinit_func();
104 struct oob_device_data oob_nfc_device_data = {
107 .init_func = init_nfc,
108 .read_func = read_nfc,
109 .write_func = write_nfc,
110 .deinit_func = deinit_nfc,