wps_nfc.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 
00023 struct wps_nfc_data {
00024         struct oob_nfc_device_data *oob_nfc_dev;
00025 };
00026 
00027 
00028 static void * init_nfc(struct wps_context *wps,
00029                        struct oob_device_data *oob_dev, int registrar)
00030 {
00031         struct oob_nfc_device_data *oob_nfc_dev;
00032         struct wps_nfc_data *data;
00033 
00034         oob_nfc_dev = wps_get_oob_nfc_device(oob_dev->device_name);
00035         if (oob_nfc_dev == NULL) {
00036                 wpa_printf(MSG_ERROR, "WPS (NFC): Unknown NFC device (%s)",
00037                            oob_dev->device_name);
00038                 return NULL;
00039         }
00040 
00041         if (oob_nfc_dev->init_func(oob_dev->device_path) < 0)
00042                 return NULL;
00043 
00044         data = os_zalloc(sizeof(*data));
00045         if (data == NULL) {
00046                 wpa_printf(MSG_ERROR, "WPS (NFC): Failed to allocate "
00047                            "nfc data area");
00048                 return NULL;
00049         }
00050         data->oob_nfc_dev = oob_nfc_dev;
00051         return data;
00052 }
00053 
00054 
00055 static struct wpabuf * read_nfc(void *priv)
00056 {
00057         struct wps_nfc_data *data = priv;
00058         struct wpabuf *wifi, *buf;
00059         char *raw_data;
00060         size_t len;
00061 
00062         raw_data = data->oob_nfc_dev->read_func(&len);
00063         if (raw_data == NULL)
00064                 return NULL;
00065 
00066         wifi = wpabuf_alloc_copy(raw_data, len);
00067         os_free(raw_data);
00068         if (wifi == NULL) {
00069                 wpa_printf(MSG_ERROR, "WPS (NFC): Failed to allocate "
00070                            "nfc read area");
00071                 return NULL;
00072         }
00073 
00074         buf = ndef_parse_wifi(wifi);
00075         wpabuf_free(wifi);
00076         if (buf == NULL)
00077                 wpa_printf(MSG_ERROR, "WPS (NFC): Failed to unwrap");
00078         return buf;
00079 }
00080 
00081 
00082 static int write_nfc(void *priv, struct wpabuf *buf)
00083 {
00084         struct wps_nfc_data *data = priv;
00085         struct wpabuf *wifi;
00086         int ret;
00087 
00088         wifi = ndef_build_wifi(buf);
00089         if (wifi == NULL) {
00090                 wpa_printf(MSG_ERROR, "WPS (NFC): Failed to wrap");
00091                 return -1;
00092         }
00093 
00094         ret = data->oob_nfc_dev->write_func(wpabuf_mhead(wifi),
00095                                             wpabuf_len(wifi));
00096         wpabuf_free(wifi);
00097         return ret;
00098 }
00099 
00100 
00101 static void deinit_nfc(void *priv)
00102 {
00103         struct wps_nfc_data *data = priv;
00104 
00105         data->oob_nfc_dev->deinit_func();
00106 
00107         os_free(data);
00108 }
00109 
00110 
00111 struct oob_device_data oob_nfc_device_data = {
00112         .device_name    = NULL,
00113         .device_path    = NULL,
00114         .init_func      = init_nfc,
00115         .read_func      = read_nfc,
00116         .write_func     = write_nfc,
00117         .deinit_func    = deinit_nfc,
00118 };
00119 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on Sat Nov 21 23:16:55 2009 for hostapd by  doxygen 1.6.1