~ubuntu-branches/ubuntu/oneiric/wpasupplicant/oneiric

« back to all changes in this revision

Viewing changes to driver_ndis_.c

  • Committer: Bazaar Package Importer
  • Author(s): Kel Modderman
  • Date: 2006-10-05 08:04:01 UTC
  • mfrom: (1.2.1 upstream) (2.1.14 edgy)
  • Revision ID: james.westby@ubuntu.com-20061005080401-myfwjtq7di70dyeo
* Update madwifi headers to latest SVN. (Closes: #388316)
* Remove failed attempt at action locking. [debian/functions.sh,
  debian/wpa_action.sh]
* Add hysteresis checking functions, to avoid "event loops" while
  using wpa-roam. [debian/functions.sh, debian/wpa_action.sh]
* Change of co-maintainer email address.
* Add ishex() function to functions.sh to determine wpa-psk value type in
  plaintext or hex. This effectively eliminates the need for the bogus and
  somewhat confusing wpa-passphrase contruct specific to our scripts and
  allows wpa-psk to work with either a 8 to 63 character long plaintext
  string or 64 character long hex string.
* Adjust README.modes to not refer to the redundant wpa-passphrase stuff.
* Add big fat NOTE about acceptable wpa-psk's to top of example gallery.
* Strip surrounding quotes from wpa-ssid if present, instead of just whining
  about them.
* Update email address in copyright blurb of functions.sh, ifupdown.sh and
  wpa_action.sh.  

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
 * See README and COPYING for more details.
13
13
 */
14
14
 
15
 
#include <stdlib.h>
16
 
#include <stdio.h>
17
 
#include <string.h>
18
 
#include <sys/unistd.h>
19
 
#include <sys/types.h>
20
 
#ifndef CONFIG_NATIVE_WINDOWS
21
 
#include <sys/socket.h>
22
 
#include <netinet/in.h>
23
 
#endif /* CONFIG_NATIVE_WINDOWS */
 
15
#include "includes.h"
24
16
 
25
17
#include "common.h"
26
18
#include "driver.h"
40
32
void wpa_driver_ndis_event_disconnect(struct wpa_driver_ndis_data *drv);
41
33
void wpa_driver_ndis_event_media_specific(struct wpa_driver_ndis_data *drv,
42
34
                                          const u8 *data, size_t data_len);
 
35
void wpa_driver_ndis_event_adapter_arrival(struct wpa_driver_ndis_data *drv);
 
36
void wpa_driver_ndis_event_adapter_removal(struct wpa_driver_ndis_data *drv);
43
37
 
44
38
 
45
39
enum event_types { EVENT_CONNECT, EVENT_DISCONNECT,
46
 
                   EVENT_MEDIA_SPECIFIC };
 
40
                   EVENT_MEDIA_SPECIFIC, EVENT_ADAPTER_ARRIVAL,
 
41
                   EVENT_ADAPTER_REMOVAL };
47
42
 
48
43
/* Event data:
49
44
 * enum event_types (as int, i.e., 4 octets)
50
 
 * InstanceName length (1 octet)
51
 
 * InstanceName (variable len)
52
 
 * data length (1 octet, optional)
 
45
 * data length (2 octets (big endian), optional)
53
46
 * data (variable len, optional)
54
47
 */
55
48
 
56
49
 
57
 
static void wpa_driver_ndis_event_cb(int sock, void *eloop_ctx, void *sock_ctx)
 
50
static void wpa_driver_ndis_event_process(struct wpa_driver_ndis_data *drv,
 
51
                                          u8 *buf, size_t len)
58
52
{
59
 
        struct wpa_driver_ndis_data *drv = eloop_ctx;
60
 
        u8 buf[512], *pos, *data = NULL;
61
 
        int res, i, desc_len;
 
53
        u8 *pos, *data = NULL;
62
54
        enum event_types type;
63
 
        unsigned char instance_len;
64
 
        char *instance;
65
55
        size_t data_len = 0;
66
56
 
67
 
        res = recv(sock, buf, sizeof(buf), 0);
68
 
        if (res < 0) {
69
 
                perror("wpa_driver_ndis_event_cb - recv");
70
 
                return;
71
 
        }
72
 
        wpa_hexdump(MSG_MSGDUMP, "NDIS: received event data", buf, res);
73
 
        if (res < sizeof(int) + 1)
 
57
        wpa_hexdump(MSG_MSGDUMP, "NDIS: received event data", buf, len);
 
58
        if (len < sizeof(int))
74
59
                return;
75
60
        type = *((int *) buf);
76
61
        pos = buf + sizeof(int);
77
62
        wpa_printf(MSG_DEBUG, "NDIS: event - type %d", type);
78
 
        instance_len = *pos++;
79
 
        if (instance_len > buf + res - pos) {
80
 
                wpa_printf(MSG_DEBUG, "NDIS: event InstanceName overflow");
81
 
                return;
82
 
        }
83
 
        instance = pos;
84
 
        pos += instance_len;
85
 
        wpa_hexdump_ascii(MSG_MSGDUMP, "NDIS: event InstanceName",
86
 
                          instance, instance_len);
87
63
 
88
 
        if (buf + res - pos > 1) {
89
 
                data_len = *pos++;
90
 
                if (data_len > buf + res - pos) {
 
64
        if (buf + len - pos > 2) {
 
65
                data_len = (int) *pos++ << 8;
 
66
                data_len += *pos++;
 
67
                if (data_len > (size_t) (buf + len - pos)) {
91
68
                        wpa_printf(MSG_DEBUG, "NDIS: event data overflow");
92
69
                        return;
93
70
                }
95
72
                wpa_hexdump(MSG_MSGDUMP, "NDIS: event data", data, data_len);
96
73
        }
97
74
 
98
 
        if (drv->adapter_desc) {
99
 
                desc_len = strlen(drv->adapter_desc);
100
 
                if (instance_len < desc_len ||
101
 
                    strncmp(drv->adapter_desc, instance, desc_len)) {
102
 
                        wpa_printf(MSG_DEBUG, "NDIS: ignored event for "
103
 
                                   "another adapter");
104
 
                        return;
105
 
                }
106
 
 
107
 
                /* InstanceName:
108
 
                 * <driver desc> #<num>
109
 
                 * <driver desc> #<num> - <intermediate drv name> Miniport
110
 
                 */
111
 
                for (i = desc_len + 1; i < instance_len; i++) {
112
 
                        if (instance[i] == '-') {
113
 
                                wpa_printf(MSG_DEBUG, "NDIS: ignored event "
114
 
                                           "for intermediate miniport");
115
 
                                return;
116
 
                        }
117
 
                }
118
 
        }
119
 
 
120
75
        switch (type) {
121
76
        case EVENT_CONNECT:
122
77
                wpa_driver_ndis_event_connect(drv);
127
82
        case EVENT_MEDIA_SPECIFIC:
128
83
                wpa_driver_ndis_event_media_specific(drv, data, data_len);
129
84
                break;
 
85
        case EVENT_ADAPTER_ARRIVAL:
 
86
                wpa_driver_ndis_event_adapter_arrival(drv);
 
87
                break;
 
88
        case EVENT_ADAPTER_REMOVAL:
 
89
                wpa_driver_ndis_event_adapter_removal(drv);
 
90
                break;
130
91
        }
131
92
}
132
93
 
133
94
 
134
 
int wpa_driver_register_event_cb(struct wpa_driver_ndis_data *drv)
 
95
void wpa_driver_ndis_event_pipe_cb(void *eloop_data, void *user_data)
135
96
{
136
 
        struct sockaddr_in addr;
137
 
 
138
 
        drv->event_sock = socket(PF_INET, SOCK_DGRAM, 0);
139
 
        if (drv->event_sock < 0) {
140
 
                perror("socket");
141
 
                return -1;
142
 
        }
143
 
 
144
 
        /* These events are received from an external program, ndis_events,
145
 
         * which is converting WMI events to more "UNIX-like" input for
146
 
         * wpa_supplicant, i.e., UDP packets that can be received through the
147
 
         * eloop mechanism. */
148
 
        memset(&addr, 0, sizeof(addr));
149
 
        addr.sin_family = AF_INET;
150
 
        addr.sin_addr.s_addr = htonl((127 << 24) | 1);
151
 
        addr.sin_port = htons(9876);
152
 
        if (bind(drv->event_sock, (struct sockaddr *) &addr, sizeof(addr)) < 0)
153
 
        {
154
 
                perror("bind");
155
 
                close(drv->event_sock);
156
 
                drv->event_sock = -1;
157
 
                return -1;
158
 
        }
159
 
 
160
 
        eloop_register_read_sock(drv->event_sock, wpa_driver_ndis_event_cb,
161
 
                                 drv, NULL);
162
 
 
163
 
        return 0;
 
97
        struct wpa_driver_ndis_data *drv = eloop_data;
 
98
        u8 buf[512];
 
99
        DWORD len;
 
100
 
 
101
        ResetEvent(drv->event_avail);
 
102
        if (ReadFile(drv->events_pipe, buf, sizeof(buf), &len, NULL))
 
103
                wpa_driver_ndis_event_process(drv, buf, len);
 
104
        else {
 
105
                wpa_printf(MSG_DEBUG, "%s: ReadFile() failed: %d", __func__,
 
106
                           (int) GetLastError());
 
107
        }
164
108
}