Added WirelessManager, a port of wpa_supplicant.
[AROS.git] / workbench / network / WirelessManager / src / wps / wps_nfc_pn531.c
blob7e05e4dd5d881d2bfa0a051519ac6e6d4aa49708
1 /*
2 * NFC PN531 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
10 * license.
12 * See README and COPYING for more details.
15 #include "includes.h"
16 #include "common.h"
18 #include "wps/wps.h"
19 #include "wps_i.h"
21 #include "WpsNfcType.h"
22 #include "WpsNfc.h"
25 static int init_nfc_pn531(char *path)
27 u32 ret;
29 ret = WpsNfcInit();
30 if (ret != WPS_NFCLIB_ERR_SUCCESS) {
31 wpa_printf(MSG_ERROR, "WPS (PN531): Failed to initialize "
32 "NFC Library: 0x%08x", ret);
33 return -1;
36 ret = WpsNfcOpenDevice((int8 *) path);
37 if (ret != WPS_NFCLIB_ERR_SUCCESS) {
38 wpa_printf(MSG_ERROR, "WPS (PN531): Failed to open "
39 "NFC Device(%s): 0x%08x", path, ret);
40 goto fail;
43 ret = WpsNfcTokenDiscovery();
44 if (ret != WPS_NFCLIB_ERR_SUCCESS) {
45 wpa_printf(MSG_ERROR, "WPS (PN531): Failed to discover "
46 "token: 0x%08x", ret);
47 WpsNfcCloseDevice();
48 goto fail;
51 return 0;
53 fail:
54 WpsNfcDeinit();
55 return -1;
59 static void * read_nfc_pn531(size_t *size)
61 uint32 len;
62 u32 ret;
63 int8 *data;
65 ret = WpsNfcRawReadToken(&data, &len);
66 if (ret != WPS_NFCLIB_ERR_SUCCESS) {
67 wpa_printf(MSG_ERROR, "WPS (PN531): Failed to read: 0x%08x",
68 ret);
69 return NULL;
72 *size = len;
73 return data;
77 static int write_nfc_pn531(void *data, size_t len)
79 u32 ret;
81 ret = WpsNfcRawWriteToken(data, len);
82 if (ret != WPS_NFCLIB_ERR_SUCCESS) {
83 wpa_printf(MSG_ERROR, "WPS (PN531): Failed to write: 0x%08x",
84 ret);
85 return -1;
88 return 0;
92 static void deinit_nfc_pn531(void)
94 u32 ret;
96 ret = WpsNfcCloseDevice();
97 if (ret != WPS_NFCLIB_ERR_SUCCESS)
98 wpa_printf(MSG_ERROR, "WPS (PN531): Failed to close "
99 "NFC Device: 0x%08x", ret);
101 ret = WpsNfcDeinit();
102 if (ret != WPS_NFCLIB_ERR_SUCCESS)
103 wpa_printf(MSG_ERROR, "WPS (PN531): Failed to deinitialize "
104 "NFC Library: 0x%08x", ret);
108 struct oob_nfc_device_data oob_nfc_pn531_device_data = {
109 .init_func = init_nfc_pn531,
110 .read_func = read_nfc_pn531,
111 .write_func = write_nfc_pn531,
112 .deinit_func = deinit_nfc_pn531,