driver_ndis_.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * WPA Supplicant - Windows/NDIS driver interface - event processing
  3. * Copyright (c) 2004-2005, Jouni Malinen <j@w1.fi>
  4. *
  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.
  8. *
  9. * Alternatively, this software may be distributed under the terms of BSD
  10. * license.
  11. *
  12. * See README and COPYING for more details.
  13. */
  14. #include "includes.h"
  15. #include "common.h"
  16. #include "driver.h"
  17. #include "eloop.h"
  18. /* Keep this event processing in a separate file and without WinPcap headers to
  19. * avoid conflicts with some of the header files. */
  20. struct _ADAPTER;
  21. typedef struct _ADAPTER * LPADAPTER;
  22. #include "driver_ndis.h"
  23. void wpa_driver_ndis_event_connect(struct wpa_driver_ndis_data *drv);
  24. void wpa_driver_ndis_event_disconnect(struct wpa_driver_ndis_data *drv);
  25. void wpa_driver_ndis_event_media_specific(struct wpa_driver_ndis_data *drv,
  26. const u8 *data, size_t data_len);
  27. void wpa_driver_ndis_event_adapter_arrival(struct wpa_driver_ndis_data *drv);
  28. void wpa_driver_ndis_event_adapter_removal(struct wpa_driver_ndis_data *drv);
  29. enum event_types { EVENT_CONNECT, EVENT_DISCONNECT,
  30. EVENT_MEDIA_SPECIFIC, EVENT_ADAPTER_ARRIVAL,
  31. EVENT_ADAPTER_REMOVAL };
  32. /* Event data:
  33. * enum event_types (as int, i.e., 4 octets)
  34. * data length (2 octets (big endian), optional)
  35. * data (variable len, optional)
  36. */
  37. static void wpa_driver_ndis_event_process(struct wpa_driver_ndis_data *drv,
  38. u8 *buf, size_t len)
  39. {
  40. u8 *pos, *data = NULL;
  41. enum event_types type;
  42. size_t data_len = 0;
  43. wpa_hexdump(MSG_MSGDUMP, "NDIS: received event data", buf, len);
  44. if (len < sizeof(int))
  45. return;
  46. type = *((int *) buf);
  47. pos = buf + sizeof(int);
  48. wpa_printf(MSG_DEBUG, "NDIS: event - type %d", type);
  49. if (buf + len - pos > 2) {
  50. data_len = (int) *pos++ << 8;
  51. data_len += *pos++;
  52. if (data_len > (size_t) (buf + len - pos)) {
  53. wpa_printf(MSG_DEBUG, "NDIS: event data overflow");
  54. return;
  55. }
  56. data = pos;
  57. wpa_hexdump(MSG_MSGDUMP, "NDIS: event data", data, data_len);
  58. }
  59. switch (type) {
  60. case EVENT_CONNECT:
  61. wpa_driver_ndis_event_connect(drv);
  62. break;
  63. case EVENT_DISCONNECT:
  64. wpa_driver_ndis_event_disconnect(drv);
  65. break;
  66. case EVENT_MEDIA_SPECIFIC:
  67. wpa_driver_ndis_event_media_specific(drv, data, data_len);
  68. break;
  69. case EVENT_ADAPTER_ARRIVAL:
  70. wpa_driver_ndis_event_adapter_arrival(drv);
  71. break;
  72. case EVENT_ADAPTER_REMOVAL:
  73. wpa_driver_ndis_event_adapter_removal(drv);
  74. break;
  75. }
  76. }
  77. void wpa_driver_ndis_event_pipe_cb(void *eloop_data, void *user_data)
  78. {
  79. struct wpa_driver_ndis_data *drv = eloop_data;
  80. u8 buf[512];
  81. DWORD len;
  82. ResetEvent(drv->event_avail);
  83. if (ReadFile(drv->events_pipe, buf, sizeof(buf), &len, NULL))
  84. wpa_driver_ndis_event_process(drv, buf, len);
  85. else {
  86. wpa_printf(MSG_DEBUG, "%s: ReadFile() failed: %d", __func__,
  87. (int) GetLastError());
  88. }
  89. }