driver_ndis_.c
Go to the documentation of this file.
00001 /*
00002  * WPA Supplicant - Windows/NDIS driver interface - event processing
00003  * Copyright (c) 2004-2005, Jouni Malinen <j@w1.fi>
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 
00017 #include "common.h"
00018 #include "driver.h"
00019 #include "eloop.h"
00020 
00021 /* Keep this event processing in a separate file and without WinPcap headers to
00022  * avoid conflicts with some of the header files. */
00023 struct _ADAPTER;
00024 typedef struct _ADAPTER * LPADAPTER;
00025 #include "driver_ndis.h"
00026 
00027 
00028 void wpa_driver_ndis_event_connect(struct wpa_driver_ndis_data *drv);
00029 void wpa_driver_ndis_event_disconnect(struct wpa_driver_ndis_data *drv);
00030 void wpa_driver_ndis_event_media_specific(struct wpa_driver_ndis_data *drv,
00031                                           const u8 *data, size_t data_len);
00032 void wpa_driver_ndis_event_adapter_arrival(struct wpa_driver_ndis_data *drv);
00033 void wpa_driver_ndis_event_adapter_removal(struct wpa_driver_ndis_data *drv);
00034 
00035 
00036 enum event_types { EVENT_CONNECT, EVENT_DISCONNECT,
00037                    EVENT_MEDIA_SPECIFIC, EVENT_ADAPTER_ARRIVAL,
00038                    EVENT_ADAPTER_REMOVAL };
00039 
00040 /* Event data:
00041  * enum event_types (as int, i.e., 4 octets)
00042  * data length (2 octets (big endian), optional)
00043  * data (variable len, optional)
00044  */
00045 
00046 
00047 static void wpa_driver_ndis_event_process(struct wpa_driver_ndis_data *drv,
00048                                           u8 *buf, size_t len)
00049 {
00050         u8 *pos, *data = NULL;
00051         enum event_types type;
00052         size_t data_len = 0;
00053 
00054         wpa_hexdump(MSG_MSGDUMP, "NDIS: received event data", buf, len);
00055         if (len < sizeof(int))
00056                 return;
00057         type = *((int *) buf);
00058         pos = buf + sizeof(int);
00059         wpa_printf(MSG_DEBUG, "NDIS: event - type %d", type);
00060 
00061         if (buf + len - pos > 2) {
00062                 data_len = (int) *pos++ << 8;
00063                 data_len += *pos++;
00064                 if (data_len > (size_t) (buf + len - pos)) {
00065                         wpa_printf(MSG_DEBUG, "NDIS: event data overflow");
00066                         return;
00067                 }
00068                 data = pos;
00069                 wpa_hexdump(MSG_MSGDUMP, "NDIS: event data", data, data_len);
00070         }
00071 
00072         switch (type) {
00073         case EVENT_CONNECT:
00074                 wpa_driver_ndis_event_connect(drv);
00075                 break;
00076         case EVENT_DISCONNECT:
00077                 wpa_driver_ndis_event_disconnect(drv);
00078                 break;
00079         case EVENT_MEDIA_SPECIFIC:
00080                 wpa_driver_ndis_event_media_specific(drv, data, data_len);
00081                 break;
00082         case EVENT_ADAPTER_ARRIVAL:
00083                 wpa_driver_ndis_event_adapter_arrival(drv);
00084                 break;
00085         case EVENT_ADAPTER_REMOVAL:
00086                 wpa_driver_ndis_event_adapter_removal(drv);
00087                 break;
00088         }
00089 }
00090 
00091 
00092 void wpa_driver_ndis_event_pipe_cb(void *eloop_data, void *user_data)
00093 {
00094         struct wpa_driver_ndis_data *drv = eloop_data;
00095         u8 buf[512];
00096         DWORD len;
00097 
00098         ResetEvent(drv->event_avail);
00099         if (ReadFile(drv->events_pipe, buf, sizeof(buf), &len, NULL))
00100                 wpa_driver_ndis_event_process(drv, buf, len);
00101         else {
00102                 wpa_printf(MSG_DEBUG, "%s: ReadFile() failed: %d", __func__,
00103                            (int) GetLastError());
00104         }
00105 }


wpa_supplicant_node
Author(s): Package maintained by Blaise Gassend
autogenerated on Thu Apr 24 2014 15:33:19