summaryrefslogtreecommitdiff
path: root/recipes/wpa-supplicant/wpa-supplicant-0.4.9/driver-zd1211.patch
blob: 3c731c1256a2664521a1b11a737a84f7b54547c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
diff -Nur wpa_supplicant-0.4.7/defconfig wpa_supplicant-0.4.7.new/defconfig
--- wpa_supplicant-0.4.7/defconfig	2005-09-24 20:30:43.000000000 +0200
+++ wpa_supplicant-0.4.7.new/defconfig	2005-12-26 19:18:14.000000000 +0100
@@ -68,6 +68,9 @@
 # Driver interface for Intel ipw2100/2200 driver
 #CONFIG_DRIVER_IPW=y
 
+# Driver interface for Zydas zd1211 driver
+#CONFIG_DRIVER_ZD1211=y
+
 # Driver interface for generic Linux wireless extensions
 CONFIG_DRIVER_WEXT=y
 
diff -Nur wpa_supplicant-0.4.7/drivers.c wpa_supplicant-0.4.7.new/drivers.c
--- wpa_supplicant-0.4.7/drivers.c	2005-02-20 01:15:54.000000000 +0100
+++ wpa_supplicant-0.4.7.new/drivers.c	2005-12-26 19:19:16.000000000 +0100
@@ -55,6 +55,9 @@
 #ifdef CONFIG_DRIVER_TEST
 extern struct wpa_driver_ops wpa_driver_test_ops; /* driver_test.c */
 #endif /* CONFIG_DRIVER_TEST */
+#ifdef CONFIG_DRIVER_ZD1211
+extern struct wpa_driver_ops wpa_driver_zd1211_ops; /* driver_zd1211.c */
+#endif /* CONFIG_DRIVER_ZD1211 */
 
 
 struct wpa_driver_ops *wpa_supplicant_drivers[] =
@@ -98,5 +101,8 @@
 #ifdef CONFIG_DRIVER_TEST
 	&wpa_driver_test_ops,
 #endif /* CONFIG_DRIVER_TEST */
+#ifdef CONFIG_DRIVER_ZD1211
+	&wpa_driver_zd1211_ops,
+#endif /* CONFIG_DRIVER_ZD1211 */
 	NULL
 };
diff -Nur wpa_supplicant-0.4.7/driver_zd1211.c wpa_supplicant-0.4.7.new/driver_zd1211.c
--- wpa_supplicant-0.4.7/driver_zd1211.c	1970-01-01 01:00:00.000000000 +0100
+++ wpa_supplicant-0.4.7.new/driver_zd1211.c	2005-12-27 16:28:46.000000000 +0100
@@ -0,0 +1,408 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+
+#include "common.h"
+#include "driver.h"
+#include "driver_wext.h"
+#include "eloop.h"
+#include "wireless_copy.h"
+#include "wpa_supplicant.h"
+
+#include "zd1211_common.h"
+
+
+struct wpa_driver_zd1211_data {
+	void *ctx;
+	void *wext; /* private data for driver_wext */
+	char ifname[IFNAMSIZ + 1];
+	int sock;
+};
+
+
+static int zd1211_ioctl(struct wpa_driver_zd1211_data *zd1211_drv, struct zd1211_wlan_param *param, int len, int show_err) {
+	struct iwreq iwr;
+
+	memset(&iwr, 0, sizeof(iwr));
+	strncpy(iwr.ifr_name, zd1211_drv->ifname, IFNAMSIZ);
+	iwr.u.data.pointer = (caddr_t) param;
+	iwr.u.data.length = len;
+
+	if (ioctl(zd1211_drv->sock, ZD_IOCTL_WPA, &iwr) < 0) {
+		int ret;
+
+		ret = errno;
+		if (show_err) 
+			perror("ioctl[ZD_IOCTL_WPA]");
+		return ret;
+	}
+
+	return 0;
+}
+
+
+static int zd1211_set_param(struct wpa_driver_zd1211_data *zd1211_drv, int op, int arg, int show_err) {
+	struct iwreq iwr;
+	int *i, ret = 0;
+
+	memset(&iwr, 0, sizeof(iwr));
+	strncpy(iwr.ifr_name, zd1211_drv->ifname, IFNAMSIZ);
+	i = (int *) iwr.u.name;
+	*i++ = op;
+	*i++ = arg;
+
+	if (ioctl(zd1211_drv->sock, ZD_IOCTL_PARAM, &iwr) < 0) {
+		perror("ioctl[ZD_IOCTL_PARAM]");
+		ret = -1;
+	}
+
+	return ret;
+}
+
+
+static int wpa_driver_zd1211_get_scan_results(void *priv, struct wpa_scan_result *results, size_t max_size) {
+	struct wpa_driver_zd1211_data *zd1211_drv;
+
+	zd1211_drv = priv;
+	return wpa_driver_wext_get_scan_results(zd1211_drv->wext, results, max_size);
+}
+
+
+static int wpa_driver_zd1211_get_bssid(void *priv, u8 *bssid) {
+	struct wpa_driver_zd1211_data *zd1211_drv;
+
+	zd1211_drv = priv;
+	return wpa_driver_wext_get_bssid(zd1211_drv->wext, bssid);
+}
+
+
+static int wpa_driver_zd1211_get_ssid(void *priv, u8 *ssid) {
+	struct wpa_driver_zd1211_data *zd1211_drv;
+
+	zd1211_drv = priv;
+	return wpa_driver_wext_get_ssid(zd1211_drv->wext, ssid);
+}
+
+
+static int wpa_driver_zd1211_set_auth_alg(void *priv, int auth_alg) {
+	struct wpa_driver_zd1211_data *zd1211_drv = priv;
+	int algs = 0;
+
+	if (auth_alg & AUTH_ALG_OPEN_SYSTEM)
+		algs = 0;
+	if (auth_alg & AUTH_ALG_SHARED_KEY)
+		algs = 1;
+
+	return zd1211_set_param(zd1211_drv, ZD_PARAM_AUTH_ALGS, algs, 1);
+}
+
+
+static int wpa_driver_zd1211_set_countermeasures(void *priv, int enabled) {
+	struct wpa_driver_zd1211_data *zd1211_drv = priv;
+
+	/* Enable the countermeasure */
+	wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled);
+	return zd1211_set_param(zd1211_drv, ZD_PARAM_COUNTERMEASURES, enabled, 1);
+}
+
+
+static int wpa_driver_zd1211_set_drop_unencrypted(void *priv, int enabled) {
+	struct wpa_driver_zd1211_data *zd1211_drv = priv;
+
+	/* Enable the countermeasure */
+	wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled);
+	return zd1211_set_param(zd1211_drv, ZD_PARAM_DROPUNENCRYPTED, enabled, 1);
+}
+
+
+static int wpa_driver_zd1211_set_key(void *priv, wpa_alg alg,
+					const u8 *addr, int key_idx,
+					int set_tx, const u8 *seq, size_t seq_len,
+					const u8 *key, size_t key_len) {
+	struct wpa_driver_zd1211_data *zd1211_drv = priv;
+	struct zd1211_wlan_param *param;
+	u8 *buf;
+	size_t blen;
+	int ret = 0;
+	char *alg_name;
+
+	switch (alg) {
+		case WPA_ALG_NONE:
+			alg_name = "NONE";
+			break;
+		case WPA_ALG_WEP:
+			alg_name = "WEP";
+			break;
+		case WPA_ALG_TKIP:
+			alg_name = "TKIP";
+			break;
+		case WPA_ALG_CCMP:
+			alg_name = "CCMP";
+			break;
+		default:
+			return -1;
+	}
+
+	wpa_printf(MSG_DEBUG, "%s: alg=%s key_idx=%d set_tx=%d seq_len=%d "
+		   "key_len=%d", __FUNCTION__, alg_name, key_idx, set_tx,
+		   seq_len, key_len);
+
+	if (seq_len > 8)
+		return -2;
+
+	blen = sizeof(*param) + key_len;
+	buf = malloc(blen);
+	if (buf == NULL)
+		return -1;
+	memset(buf, 0, blen);
+
+	param = (struct zd1211_wlan_param *) buf;
+	param->cmd = ZD_CMD_SET_ENCRYPT_KEY;
+	/* TODO: In theory, STA in client mode can use five keys; four default
+	 * keys for receiving (with keyidx 0..3) and one individual key for
+	 * both transmitting and receiving (keyidx 0) _unicast_ packets. Now,
+	 * keyidx 0 is reserved for this unicast use and default keys can only
+	 * use keyidx 1..3 (i.e., default key with keyidx 0 is not supported).
+	 * This should be fine for more or less all cases, but for completeness
+	 * sake, the driver could be enhanced to support the missing key. */
+#if 0
+	if (addr == NULL)
+		memset(param->sta_addr, 0xff, ETH_ALEN);
+	else
+		memcpy(param->sta_addr, addr, ETH_ALEN);
+#else
+	memset(param->sta_addr, 0xff, ETH_ALEN);
+#endif
+	strncpy(param->u.crypt.alg, alg_name, ZD_CRYPT_ALG_NAME_LEN);
+	param->u.crypt.flags = set_tx ? ZD_FLAG_SET_TX_KEY : 0;
+	param->u.crypt.idx = key_idx;
+	memcpy(param->u.crypt.seq, seq, seq_len);
+	param->u.crypt.key_len = key_len;
+	memcpy((u8 *) param->u.crypt.key, key, key_len);
+
+	/* Dump key context */
+	if(alg == WPA_ALG_TKIP) {
+		int ii;
+
+		wpa_printf(MSG_DEBUG, "Key Context:");
+		for(ii = 0; ii < key_len; ) {
+			printf("0x%02x ", key[ii]);
+
+			if((++ii % 16) == 0)
+				printf("\n");
+		}
+
+		printf("\n");
+	}
+
+	if (zd1211_ioctl(zd1211_drv, param, blen, 1)) {
+		wpa_printf(MSG_WARNING, "Failed to set encryption.");
+		//show_set_key_error(param);
+		ret = -1;
+	}
+	free(buf);
+
+	return ret;
+}
+
+
+static int wpa_driver_zd1211_set_wpa_ie(struct wpa_driver_zd1211_data *zd1211_drv, const u8 *wpa_ie, size_t wpa_ie_len) {
+	int res;
+	struct zd1211_wlan_param *param;
+	size_t blen = ZD_GENERIC_ELEMENT_HDR_LEN + wpa_ie_len;
+
+	if (blen < sizeof(*param))
+		blen = sizeof(*param);
+
+	param = (struct zd1211_wlan_param *) malloc(blen);
+	if (param == NULL)
+		return -1;
+
+	memset(param, 0, blen);
+	param->cmd = ZD_CMD_SET_GENERIC_ELEMENT;
+	param->u.generic_elem.len = wpa_ie_len;
+	memcpy(param->u.generic_elem.data, wpa_ie, wpa_ie_len);
+	res = zd1211_ioctl(zd1211_drv, param, blen, 1);
+
+	free(param);
+
+	return res;
+}
+
+
+static int wpa_driver_zd1211_set_wpa(void *priv, int enabled) {
+	struct wpa_driver_zd1211_data *zd1211_drv = priv;
+	int ret = 0;
+
+	wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled);
+
+	if (!enabled && wpa_driver_zd1211_set_wpa_ie(zd1211_drv, NULL, 0) < 0)
+		ret = -1;
+	if (zd1211_set_param(zd1211_drv, ZD_PARAM_ROAMING, enabled, 1) < 0)
+		ret = -1;
+	if (zd1211_set_param(zd1211_drv, ZD_PARAM_PRIVACY, enabled, 1) < 0)
+		ret = -1;
+	if (zd1211_set_param(zd1211_drv, ZD_PARAM_WPA, enabled, 1) < 0)
+		ret = -1;
+
+	return ret;
+}
+
+
+static int wpa_driver_zd1211_associate(void *priv, struct wpa_driver_associate_params *params) {
+	struct wpa_driver_zd1211_data *zd1211_drv = priv;
+	int ret = 0;
+
+	wpa_printf(MSG_DEBUG, "%s", __FUNCTION__);
+
+	/* Because there might be the case, two or more APs with the same
+	 * SSID, in order to identify them, we need to set the BSSID. */
+	if (wpa_driver_zd1211_set_wpa_ie(zd1211_drv, params->wpa_ie, params->wpa_ie_len) < 0)
+		ret = -1;
+	if (wpa_driver_wext_set_ssid(zd1211_drv->wext, params->ssid, params->ssid_len) < 0)
+		ret = -1;
+
+	// Mark for test
+	//if (wpa_driver_wext_set_bssid(ifname, bssid) < 0)
+	//	ret = -1;
+
+#if 0
+	/* Allow unencrypted EAPOL messages even if pairwise keys are set when
+	 * not using WPA. IEEE 802.1X specifies that these frames are not
+	 * encrypted, but WPA encrypts them when pairwise keys are in use. */
+	if (key_mgmt_suite == KEY_MGMT_802_1X ||
+	    key_mgmt_suite == KEY_MGMT_PSK)
+		allow_unencrypted_eapol = 0;
+	else
+		allow_unencrypted_eapol = 1;
+	
+	if (prism2param(ifname, PRISM2_PARAM_IEEE_802_1X,
+			allow_unencrypted_eapol) < 0) {
+		wpa_printf(MSG_DEBUG, "hostap: Failed to configure "
+			   "ieee_802_1x param");
+		/* Ignore this error.. driver_hostap.c can also be used with
+		 * other drivers that do not support this prism2_param. */
+	}
+#endif
+
+	return ret;
+}
+
+
+static int wpa_driver_zd1211_deauthenticate(void *priv, const u8 *addr, int reason_code) {
+	struct zd1211_wlan_param *param;
+	struct wpa_driver_zd1211_data *zd1211_drv = priv;
+	int blen;
+        int ret;
+
+	wpa_printf(MSG_DEBUG, "%s", __FUNCTION__);
+
+	blen = sizeof(*param);
+	param = (struct zd1211_wlan_param *) malloc(blen);
+	if (param == NULL)
+		return -1;
+
+	memset(param, 0, blen);
+	param->cmd = ZD_CMD_SET_MLME;
+	param->u.mlme.cmd = MLME_STA_DEAUTH;
+	param->u.mlme.reason_code = reason_code;
+	memcpy(param->sta_addr, addr, ETH_ALEN);
+	ret = zd1211_ioctl(zd1211_drv, param, blen, 1);
+        usleep(100000);
+        free(param);
+        return ret;
+}
+
+
+static int wpa_driver_zd1211_disassociate(void *priv, const u8 *addr, int reason_code) {
+	struct zd1211_wlan_param *param;
+	struct wpa_driver_zd1211_data *zd1211_drv = priv;
+	int blen;
+        int ret;
+
+	wpa_printf(MSG_DEBUG, "%s", __FUNCTION__);
+
+	blen = sizeof(*param);
+	param = (struct zd1211_wlan_param *) malloc(blen);
+	if (param == NULL)
+		return -1;
+
+	memset(param, 0, blen);
+	param->cmd = ZD_CMD_SET_MLME;
+	param->u.mlme.cmd = MLME_STA_DISASSOC;
+	param->u.mlme.reason_code = reason_code;
+	memcpy(param->sta_addr, addr, ETH_ALEN);
+	ret = zd1211_ioctl(zd1211_drv, param, blen, 1);
+        free(param);
+        return ret;
+}
+
+
+static int wpa_driver_zd1211_scan(void *priv, const u8 *ssid, size_t ssid_len) {
+	struct wpa_driver_zd1211_data *zd1211_drv;
+
+	zd1211_drv = priv;
+	return wpa_driver_wext_scan(zd1211_drv->wext, ssid, ssid_len);
+}
+
+
+static void * wpa_driver_zd1211_init(void *ctx, const char *ifname) {
+	struct wpa_driver_zd1211_data *zd1211_drv;
+
+	zd1211_drv = malloc(sizeof(*zd1211_drv));
+	if (zd1211_drv == NULL)
+		return NULL;
+	memset(zd1211_drv, 0, sizeof(*zd1211_drv));
+
+	zd1211_drv->wext = wpa_driver_wext_init(ctx, ifname);
+	if (zd1211_drv->wext == NULL)
+		goto exit_no_wext;
+
+	zd1211_drv->ctx = ctx;
+	strncpy(zd1211_drv->ifname, ifname, sizeof(zd1211_drv->ifname));
+
+	zd1211_drv->sock = socket(PF_INET, SOCK_DGRAM, 0);
+	if (zd1211_drv->sock < 0)
+		goto exit_no_socket;
+
+	return zd1211_drv;
+
+exit_no_socket:
+	wpa_driver_wext_deinit(zd1211_drv->wext);
+exit_no_wext:
+	free(zd1211_drv);
+	return NULL;
+}
+
+
+static void wpa_driver_zd1211_deinit(void *ctx) {
+	struct wpa_driver_zd1211_data *zd1211_drv = ctx;
+
+	wpa_driver_wext_deinit(zd1211_drv->wext);
+	close(zd1211_drv->sock);
+	free(zd1211_drv);
+}
+
+
+struct wpa_driver_ops wpa_driver_zd1211_ops = {
+	.name = "zd1211",
+	.desc = "Zydas zd1211 drivers",
+	.init			= wpa_driver_zd1211_init,
+	.deinit			= wpa_driver_zd1211_deinit,
+	.associate		= wpa_driver_zd1211_associate,
+	.deauthenticate		= wpa_driver_zd1211_deauthenticate,
+	.disassociate		= wpa_driver_zd1211_disassociate,
+	.get_bssid		= wpa_driver_zd1211_get_bssid,
+	.get_scan_results	= wpa_driver_zd1211_get_scan_results,
+	.get_ssid		= wpa_driver_zd1211_get_ssid,
+//	.get_capa		= wpa_driver_zd1211_get_capa,
+	.scan			= wpa_driver_zd1211_scan,
+	.set_auth_alg		= wpa_driver_zd1211_set_auth_alg,
+	.set_countermeasures	= wpa_driver_zd1211_set_countermeasures,
+	.set_drop_unencrypted	= wpa_driver_zd1211_set_drop_unencrypted,
+	.set_key		= wpa_driver_zd1211_set_key,
+	.set_wpa		= wpa_driver_zd1211_set_wpa,
+};
diff -Nur wpa_supplicant-0.4.7/Makefile wpa_supplicant-0.4.7.new/Makefile
--- wpa_supplicant-0.4.7/Makefile	2005-11-21 02:42:12.000000000 +0100
+++ wpa_supplicant-0.4.7.new/Makefile	2005-12-26 19:17:14.000000000 +0100
@@ -107,6 +107,12 @@
 CONFIG_WIRELESS_EXTENSION=y
 endif
 
+ifdef CONFIG_DRIVER_ZD1211
+CFLAGS += -DCONFIG_DRIVER_ZD1211
+OBJS_d += driver_zd1211.o
+CONFIG_WIRELESS_EXTENSION=y
+endif
+
 ifdef CONFIG_DRIVER_BSD
 CFLAGS += -DCONFIG_DRIVER_BSD
 OBJS_d += driver_bsd.o
diff -Nur wpa_supplicant-0.4.7/zd1211_common.h wpa_supplicant-0.4.7.new/zd1211_common.h
--- wpa_supplicant-0.4.7/zd1211_common.h	1970-01-01 01:00:00.000000000 +0100
+++ wpa_supplicant-0.4.7.new/zd1211_common.h	2005-12-27 16:00:36.000000000 +0100
@@ -0,0 +1,68 @@
+#ifndef ZD1211_COMMON_H
+#define ZD1211_COMMON_H
+
+
+#define ZD_IOCTL_WPA			(SIOCDEVPRIVATE + 1)
+#define ZD_IOCTL_PARAM			(SIOCDEVPRIVATE + 2)
+
+#define ZD_PARAM_ROAMING		0x0001
+#define ZD_PARAM_PRIVACY		0x0002
+#define ZD_PARAM_WPA			0x0003
+#define ZD_PARAM_COUNTERMEASURES	0x0004
+#define ZD_PARAM_DROPUNENCRYPTED	0x0005
+#define ZD_PARAM_AUTH_ALGS		0x0006
+
+#define ZD_CMD_SET_ENCRYPT_KEY		0x0001
+#define ZD_CMD_SET_MLME			0x0002
+//#define ZD_CMD_SCAN_REQ			0x0003
+#define ZD_CMD_SET_GENERIC_ELEMENT	0x0004
+
+#define ZD_FLAG_SET_TX_KEY              0x0001
+
+#define ZD_GENERIC_ELEMENT_HDR_LEN \
+((int) (&((struct zd1211_wlan_param *) 0)->u.generic_elem.data))
+
+#define ZD_CRYPT_ALG_NAME_LEN		16
+#define ZD_MAX_KEY_SIZE			32
+#define ZD_MAX_GENERIC_SIZE		64
+
+/* structure definition */
+
+struct zd1211_wlan_param {
+	u32 cmd;
+	u8 sta_addr[ETH_ALEN];
+	union {
+		struct {
+			u8 alg[ZD_CRYPT_ALG_NAME_LEN];
+			u32 flags;
+			u32 err;
+			u8 idx;
+			u8 seq[8]; /* sequence counter (set: RX, get: TX) */
+			u16 key_len;
+			u8 key[ZD_MAX_KEY_SIZE];
+		} crypt;
+/*
+		struct {
+			u32 flags_and;
+			u32 flags_or;
+		} set_flags_sta;
+*/
+		struct {
+			u8 len;
+			u8 data[ZD_MAX_GENERIC_SIZE];
+		} generic_elem;
+		struct {
+#define MLME_STA_DEAUTH 0
+#define MLME_STA_DISASSOC 1
+			u16 cmd;
+			u16 reason_code;
+		} mlme;
+		struct {
+			u8 ssid_len;
+			u8 ssid[32];
+		} scan_req;
+	} u;
+};
+
+
+#endif