wps_nfc_pn531.c
Go to the documentation of this file.
00001 /*
00002  * NFC PN531 routines for Wi-Fi Protected Setup
00003  * Copyright (c) 2009, Masashi Honma <honma@ictec.co.jp>
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 2 as
00007  * published by the Free Software Foundation.
00008  *
00009  * Alternatively, this software may be distributed under the terms of BSD
00010  * license.
00011  *
00012  * See README and COPYING for more details.
00013  */
00014 
00015 #include "includes.h"
00016 #include "common.h"
00017 
00018 #include "wps/wps.h"
00019 #include "wps_i.h"
00020 
00021 #include "WpsNfcType.h"
00022 #include "WpsNfc.h"
00023 
00024 
00025 static int init_nfc_pn531(char *path)
00026 {
00027         u32 ret;
00028 
00029         ret = WpsNfcInit();
00030         if (ret != WPS_NFCLIB_ERR_SUCCESS) {
00031                 wpa_printf(MSG_ERROR, "WPS (PN531): Failed to initialize "
00032                            "NFC Library: 0x%08x", ret);
00033                 return -1;
00034         }
00035 
00036         ret = WpsNfcOpenDevice((int8 *) path);
00037         if (ret != WPS_NFCLIB_ERR_SUCCESS) {
00038                 wpa_printf(MSG_ERROR, "WPS (PN531): Failed to open "
00039                            "NFC Device(%s): 0x%08x", path, ret);
00040                 goto fail;
00041         }
00042 
00043         ret = WpsNfcTokenDiscovery();
00044         if (ret != WPS_NFCLIB_ERR_SUCCESS) {
00045                 wpa_printf(MSG_ERROR, "WPS (PN531): Failed to discover "
00046                            "token: 0x%08x", ret);
00047                 WpsNfcCloseDevice();
00048                 goto fail;
00049         }
00050 
00051         return 0;
00052 
00053 fail:
00054         WpsNfcDeinit();
00055         return -1;
00056 }
00057 
00058 
00059 static void * read_nfc_pn531(size_t *size)
00060 {
00061         uint32 len;
00062         u32 ret;
00063         int8 *data;
00064 
00065         ret = WpsNfcRawReadToken(&data, &len);
00066         if (ret != WPS_NFCLIB_ERR_SUCCESS) {
00067                 wpa_printf(MSG_ERROR, "WPS (PN531): Failed to read: 0x%08x",
00068                            ret);
00069                 return NULL;
00070         }
00071 
00072         *size = len;
00073         return data;
00074 }
00075 
00076 
00077 static int write_nfc_pn531(void *data, size_t len)
00078 {
00079         u32 ret;
00080 
00081         ret = WpsNfcRawWriteToken(data, len);
00082         if (ret != WPS_NFCLIB_ERR_SUCCESS) {
00083                 wpa_printf(MSG_ERROR, "WPS (PN531): Failed to write: 0x%08x",
00084                            ret);
00085                 return -1;
00086         }
00087 
00088         return 0;
00089 }
00090 
00091 
00092 static void deinit_nfc_pn531(void)
00093 {
00094         u32 ret;
00095 
00096         ret = WpsNfcCloseDevice();
00097         if (ret != WPS_NFCLIB_ERR_SUCCESS)
00098                 wpa_printf(MSG_ERROR, "WPS (PN531): Failed to close "
00099                            "NFC Device: 0x%08x", ret);
00100 
00101         ret = WpsNfcDeinit();
00102         if (ret != WPS_NFCLIB_ERR_SUCCESS)
00103                 wpa_printf(MSG_ERROR, "WPS (PN531): Failed to deinitialize "
00104                            "NFC Library: 0x%08x", ret);
00105 }
00106 
00107 
00108 struct oob_nfc_device_data oob_nfc_pn531_device_data = {
00109         .init_func      = init_nfc_pn531,
00110         .read_func      = read_nfc_pn531,
00111         .write_func     = write_nfc_pn531,
00112         .deinit_func    = deinit_nfc_pn531,
00113 };


wpa_supplicant
Author(s): Package maintained by Blaise Gassend
autogenerated on Thu Apr 24 2014 15:34:36