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
12 * See README and COPYING for more details.
21 #include "WpsNfcType.h"
25 static int init_nfc_pn531(char *path
)
30 if (ret
!= WPS_NFCLIB_ERR_SUCCESS
) {
31 wpa_printf(MSG_ERROR
, "WPS (PN531): Failed to initialize "
32 "NFC Library: 0x%08x", ret
);
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
);
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
);
59 static void * read_nfc_pn531(size_t *size
)
65 ret
= WpsNfcRawReadToken(&data
, &len
);
66 if (ret
!= WPS_NFCLIB_ERR_SUCCESS
) {
67 wpa_printf(MSG_ERROR
, "WPS (PN531): Failed to read: 0x%08x",
77 static int write_nfc_pn531(void *data
, size_t len
)
81 ret
= WpsNfcRawWriteToken(data
, len
);
82 if (ret
!= WPS_NFCLIB_ERR_SUCCESS
) {
83 wpa_printf(MSG_ERROR
, "WPS (PN531): Failed to write: 0x%08x",
92 static void deinit_nfc_pn531(void)
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
,