wps_nfc_pn531.c
Go to the documentation of this file.00001
00016 #include "includes.h"
00017 #include "common.h"
00018
00019 #include "wps/wps.h"
00020 #include "wps_i.h"
00021
00022 #include "WpsNfcType.h"
00023 #include "WpsNfc.h"
00024
00025
00026 static int init_nfc_pn531(char *path)
00027 {
00028 u32 ret;
00029
00030 ret = WpsNfcInit();
00031 if (ret != WPS_NFCLIB_ERR_SUCCESS) {
00032 wpa_printf(MSG_ERROR, "WPS (PN531): Failed to initialize "
00033 "NFC Library: 0x%08x", ret);
00034 return -1;
00035 }
00036
00037 ret = WpsNfcOpenDevice((int8 *) path);
00038 if (ret != WPS_NFCLIB_ERR_SUCCESS) {
00039 wpa_printf(MSG_ERROR, "WPS (PN531): Failed to open "
00040 "NFC Device(%s): 0x%08x", path, ret);
00041 goto fail;
00042 }
00043
00044 ret = WpsNfcTokenDiscovery();
00045 if (ret != WPS_NFCLIB_ERR_SUCCESS) {
00046 wpa_printf(MSG_ERROR, "WPS (PN531): Failed to discover "
00047 "token: 0x%08x", ret);
00048 WpsNfcCloseDevice();
00049 goto fail;
00050 }
00051
00052 return 0;
00053
00054 fail:
00055 WpsNfcDeinit();
00056 return -1;
00057 }
00058
00059
00060 static void * read_nfc_pn531(size_t *size)
00061 {
00062 uint32 len;
00063 u32 ret;
00064 int8 *data;
00065
00066 ret = WpsNfcRawReadToken(&data, &len);
00067 if (ret != WPS_NFCLIB_ERR_SUCCESS) {
00068 wpa_printf(MSG_ERROR, "WPS (PN531): Failed to read: 0x%08x",
00069 ret);
00070 return NULL;
00071 }
00072
00073 *size = len;
00074 return data;
00075 }
00076
00077
00078 static int write_nfc_pn531(void *data, size_t len)
00079 {
00080 u32 ret;
00081
00082 ret = WpsNfcRawWriteToken(data, len);
00083 if (ret != WPS_NFCLIB_ERR_SUCCESS) {
00084 wpa_printf(MSG_ERROR, "WPS (PN531): Failed to write: 0x%08x",
00085 ret);
00086 return -1;
00087 }
00088
00089 return 0;
00090 }
00091
00092
00093 static void deinit_nfc_pn531(void)
00094 {
00095 u32 ret;
00096
00097 ret = WpsNfcCloseDevice();
00098 if (ret != WPS_NFCLIB_ERR_SUCCESS)
00099 wpa_printf(MSG_ERROR, "WPS (PN531): Failed to close "
00100 "NFC Device: 0x%08x", ret);
00101
00102 ret = WpsNfcDeinit();
00103 if (ret != WPS_NFCLIB_ERR_SUCCESS)
00104 wpa_printf(MSG_ERROR, "WPS (PN531): Failed to deinitialize "
00105 "NFC Library: 0x%08x", ret);
00106 }
00107
00108
00109 struct oob_nfc_device_data oob_nfc_pn531_device_data = {
00110 .init_func = init_nfc_pn531,
00111 .read_func = read_nfc_pn531,
00112 .write_func = write_nfc_pn531,
00113 .deinit_func = deinit_nfc_pn531,
00114 };
00115