]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/staging/wilc1000/wilc_wlan_cfg.c
Merge branch 'scsi-target-for-v4.10' of git://git.kernel.org/pub/scm/linux/kernel...
[mirror_ubuntu-artful-kernel.git] / drivers / staging / wilc1000 / wilc_wlan_cfg.c
1 /* ////////////////////////////////////////////////////////////////////////// */
2 /* */
3 /* Copyright (c) Atmel Corporation. All rights reserved. */
4 /* */
5 /* Module Name: wilc_wlan_cfg.c */
6 /* */
7 /* */
8 /* ///////////////////////////////////////////////////////////////////////// */
9
10 #include <linux/string.h>
11 #include "wilc_wlan_if.h"
12 #include "wilc_wlan.h"
13 #include "wilc_wlan_cfg.h"
14 #include "coreconfigurator.h"
15
16 /********************************************
17 *
18 * Global Data
19 *
20 ********************************************/
21 enum cfg_cmd_type {
22 CFG_BYTE_CMD = 0,
23 CFG_HWORD_CMD = 1,
24 CFG_WORD_CMD = 2,
25 CFG_STR_CMD = 3,
26 CFG_BIN_CMD = 4
27 };
28
29 struct wilc_mac_cfg {
30 int mac_status;
31 u8 mac_address[7];
32 u8 ip_address[5];
33 u8 bssid[7];
34 u8 ssid[34];
35 u8 firmware_version[129];
36 u8 supp_rate[24];
37 u8 wep_key[28];
38 u8 i_psk[66];
39 u8 hw_product_version[33];
40 u8 phyversion[17];
41 u8 supp_username[21];
42 u8 supp_password[64];
43 u8 assoc_req[256];
44 u8 assoc_rsp[256];
45 u8 firmware_info[8];
46 u8 scan_result[256];
47 u8 scan_result1[256];
48 };
49
50 static struct wilc_mac_cfg g_mac;
51
52 static struct wilc_cfg_byte g_cfg_byte[] = {
53 {WID_BSS_TYPE, 0},
54 {WID_CURRENT_TX_RATE, 0},
55 {WID_CURRENT_CHANNEL, 0},
56 {WID_PREAMBLE, 0},
57 {WID_11G_OPERATING_MODE, 0},
58 {WID_STATUS, 0},
59 {WID_SCAN_TYPE, 0},
60 {WID_KEY_ID, 0},
61 {WID_QOS_ENABLE, 0},
62 {WID_POWER_MANAGEMENT, 0},
63 {WID_11I_MODE, 0},
64 {WID_AUTH_TYPE, 0},
65 {WID_SITE_SURVEY, 0},
66 {WID_LISTEN_INTERVAL, 0},
67 {WID_DTIM_PERIOD, 0},
68 {WID_ACK_POLICY, 0},
69 {WID_BCAST_SSID, 0},
70 {WID_REKEY_POLICY, 0},
71 {WID_SHORT_SLOT_ALLOWED, 0},
72 {WID_START_SCAN_REQ, 0},
73 {WID_RSSI, 0},
74 {WID_LINKSPEED, 0},
75 {WID_AUTO_RX_SENSITIVITY, 0},
76 {WID_DATAFLOW_CONTROL, 0},
77 {WID_SCAN_FILTER, 0},
78 {WID_11N_PROT_MECH, 0},
79 {WID_11N_ERP_PROT_TYPE, 0},
80 {WID_11N_ENABLE, 0},
81 {WID_11N_OPERATING_MODE, 0},
82 {WID_11N_OBSS_NONHT_DETECTION, 0},
83 {WID_11N_HT_PROT_TYPE, 0},
84 {WID_11N_RIFS_PROT_ENABLE, 0},
85 {WID_11N_SMPS_MODE, 0},
86 {WID_11N_CURRENT_TX_MCS, 0},
87 {WID_11N_SHORT_GI_ENABLE, 0},
88 {WID_RIFS_MODE, 0},
89 {WID_TX_ABORT_CONFIG, 0},
90 {WID_11N_IMMEDIATE_BA_ENABLED, 0},
91 {WID_11N_TXOP_PROT_DISABLE, 0},
92 {WID_NIL, 0}
93 };
94
95 static struct wilc_cfg_hword g_cfg_hword[] = {
96 {WID_LINK_LOSS_THRESHOLD, 0},
97 {WID_RTS_THRESHOLD, 0},
98 {WID_FRAG_THRESHOLD, 0},
99 {WID_SHORT_RETRY_LIMIT, 0},
100 {WID_LONG_RETRY_LIMIT, 0},
101 {WID_BEACON_INTERVAL, 0},
102 {WID_RX_SENSE, 0},
103 {WID_ACTIVE_SCAN_TIME, 0},
104 {WID_PASSIVE_SCAN_TIME, 0},
105 {WID_SITE_SURVEY_SCAN_TIME, 0},
106 {WID_JOIN_START_TIMEOUT, 0},
107 {WID_AUTH_TIMEOUT, 0},
108 {WID_ASOC_TIMEOUT, 0},
109 {WID_11I_PROTOCOL_TIMEOUT, 0},
110 {WID_EAPOL_RESPONSE_TIMEOUT, 0},
111 {WID_11N_SIG_QUAL_VAL, 0},
112 {WID_CCA_THRESHOLD, 0},
113 {WID_NIL, 0}
114 };
115
116 static struct wilc_cfg_word g_cfg_word[] = {
117 {WID_FAILED_COUNT, 0},
118 {WID_RETRY_COUNT, 0},
119 {WID_MULTIPLE_RETRY_COUNT, 0},
120 {WID_FRAME_DUPLICATE_COUNT, 0},
121 {WID_ACK_FAILURE_COUNT, 0},
122 {WID_RECEIVED_FRAGMENT_COUNT, 0},
123 {WID_MCAST_RECEIVED_FRAME_COUNT, 0},
124 {WID_FCS_ERROR_COUNT, 0},
125 {WID_SUCCESS_FRAME_COUNT, 0},
126 {WID_TX_FRAGMENT_COUNT, 0},
127 {WID_TX_MULTICAST_FRAME_COUNT, 0},
128 {WID_RTS_SUCCESS_COUNT, 0},
129 {WID_RTS_FAILURE_COUNT, 0},
130 {WID_WEP_UNDECRYPTABLE_COUNT, 0},
131 {WID_REKEY_PERIOD, 0},
132 {WID_REKEY_PACKET_COUNT, 0},
133 {WID_HW_RX_COUNT, 0},
134 {WID_GET_INACTIVE_TIME, 0},
135 {WID_NIL, 0}
136
137 };
138
139 static struct wilc_cfg_str g_cfg_str[] = {
140 {WID_SSID, g_mac.ssid}, /* 33 + 1 bytes */
141 {WID_FIRMWARE_VERSION, g_mac.firmware_version},
142 {WID_OPERATIONAL_RATE_SET, g_mac.supp_rate},
143 {WID_BSSID, g_mac.bssid}, /* 6 bytes */
144 {WID_WEP_KEY_VALUE, g_mac.wep_key}, /* 27 bytes */
145 {WID_11I_PSK, g_mac.i_psk}, /* 65 bytes */
146 {WID_HARDWARE_VERSION, g_mac.hw_product_version},
147 {WID_MAC_ADDR, g_mac.mac_address},
148 {WID_PHY_VERSION, g_mac.phyversion},
149 {WID_SUPP_USERNAME, g_mac.supp_username},
150 {WID_SUPP_PASSWORD, g_mac.supp_password},
151 {WID_SITE_SURVEY_RESULTS, g_mac.scan_result},
152 {WID_SITE_SURVEY_RESULTS, g_mac.scan_result1},
153 {WID_ASSOC_REQ_INFO, g_mac.assoc_req},
154 {WID_ASSOC_RES_INFO, g_mac.assoc_rsp},
155 {WID_FIRMWARE_INFO, g_mac.firmware_version},
156 {WID_IP_ADDRESS, g_mac.ip_address},
157 {WID_NIL, NULL}
158 };
159
160 /********************************************
161 *
162 * Configuration Functions
163 *
164 ********************************************/
165
166 static int wilc_wlan_cfg_set_byte(u8 *frame, u32 offset, u16 id, u8 val8)
167 {
168 u8 *buf;
169
170 if ((offset + 4) >= MAX_CFG_FRAME_SIZE)
171 return 0;
172
173 buf = &frame[offset];
174
175 buf[0] = (u8)id;
176 buf[1] = (u8)(id >> 8);
177 buf[2] = 1;
178 buf[3] = val8;
179 return 4;
180 }
181
182 static int wilc_wlan_cfg_set_hword(u8 *frame, u32 offset, u16 id, u16 val16)
183 {
184 u8 *buf;
185
186 if ((offset + 5) >= MAX_CFG_FRAME_SIZE)
187 return 0;
188
189 buf = &frame[offset];
190
191 buf[0] = (u8)id;
192 buf[1] = (u8)(id >> 8);
193 buf[2] = 2;
194 buf[3] = (u8)val16;
195 buf[4] = (u8)(val16 >> 8);
196
197 return 5;
198 }
199
200 static int wilc_wlan_cfg_set_word(u8 *frame, u32 offset, u16 id, u32 val32)
201 {
202 u8 *buf;
203
204 if ((offset + 7) >= MAX_CFG_FRAME_SIZE)
205 return 0;
206
207 buf = &frame[offset];
208
209 buf[0] = (u8)id;
210 buf[1] = (u8)(id >> 8);
211 buf[2] = 4;
212 buf[3] = (u8)val32;
213 buf[4] = (u8)(val32 >> 8);
214 buf[5] = (u8)(val32 >> 16);
215 buf[6] = (u8)(val32 >> 24);
216
217 return 7;
218 }
219
220 static int wilc_wlan_cfg_set_str(u8 *frame, u32 offset, u16 id, u8 *str, u32 size)
221 {
222 u8 *buf;
223
224 if ((offset + size + 3) >= MAX_CFG_FRAME_SIZE)
225 return 0;
226
227 buf = &frame[offset];
228
229 buf[0] = (u8)id;
230 buf[1] = (u8)(id >> 8);
231 buf[2] = (u8)size;
232
233 if ((str) && (size != 0))
234 memcpy(&buf[3], str, size);
235
236 return (size + 3);
237 }
238
239 static int wilc_wlan_cfg_set_bin(u8 *frame, u32 offset, u16 id, u8 *b, u32 size)
240 {
241 u8 *buf;
242 u32 i;
243 u8 checksum = 0;
244
245 if ((offset + size + 5) >= MAX_CFG_FRAME_SIZE)
246 return 0;
247
248 buf = &frame[offset];
249 buf[0] = (u8)id;
250 buf[1] = (u8)(id >> 8);
251 buf[2] = (u8)size;
252 buf[3] = (u8)(size >> 8);
253
254 if ((b) && (size != 0)) {
255 memcpy(&buf[4], b, size);
256 for (i = 0; i < size; i++)
257 checksum += buf[i + 4];
258 }
259
260 buf[size + 4] = checksum;
261
262 return (size + 5);
263 }
264
265 /********************************************
266 *
267 * Configuration Response Functions
268 *
269 ********************************************/
270
271 static void wilc_wlan_parse_response_frame(u8 *info, int size)
272 {
273 u32 wid, len = 0, i = 0;
274
275 while (size > 0) {
276 i = 0;
277 wid = info[0] | (info[1] << 8);
278 wid = cpu_to_le32(wid);
279
280 switch ((wid >> 12) & 0x7) {
281 case WID_CHAR:
282 do {
283 if (g_cfg_byte[i].id == WID_NIL)
284 break;
285
286 if (g_cfg_byte[i].id == wid) {
287 g_cfg_byte[i].val = info[3];
288 break;
289 }
290 i++;
291 } while (1);
292 len = 2;
293 break;
294
295 case WID_SHORT:
296 do {
297 if (g_cfg_hword[i].id == WID_NIL)
298 break;
299
300 if (g_cfg_hword[i].id == wid) {
301 g_cfg_hword[i].val = cpu_to_le16(info[3] | (info[4] << 8));
302 break;
303 }
304 i++;
305 } while (1);
306 len = 3;
307 break;
308
309 case WID_INT:
310 do {
311 if (g_cfg_word[i].id == WID_NIL)
312 break;
313
314 if (g_cfg_word[i].id == wid) {
315 g_cfg_word[i].val = cpu_to_le32(info[3] | (info[4] << 8) | (info[5] << 16) | (info[6] << 24));
316 break;
317 }
318 i++;
319 } while (1);
320 len = 5;
321 break;
322
323 case WID_STR:
324 do {
325 if (g_cfg_str[i].id == WID_NIL)
326 break;
327
328 if (g_cfg_str[i].id == wid) {
329 if (wid == WID_SITE_SURVEY_RESULTS) {
330 static int toggle;
331
332 i += toggle;
333 toggle ^= 1;
334 }
335 memcpy(g_cfg_str[i].str, &info[2], (info[2] + 1));
336 break;
337 }
338 i++;
339 } while (1);
340 len = 1 + info[2];
341 break;
342
343 default:
344 break;
345 }
346 size -= (2 + len);
347 info += (2 + len);
348 }
349 }
350
351 static int wilc_wlan_parse_info_frame(u8 *info, int size)
352 {
353 struct wilc_mac_cfg *pd = &g_mac;
354 u32 wid, len;
355 int type = WILC_CFG_RSP_STATUS;
356
357 wid = info[0] | (info[1] << 8);
358
359 len = info[2];
360
361 if ((len == 1) && (wid == WID_STATUS)) {
362 pd->mac_status = info[3];
363 type = WILC_CFG_RSP_STATUS;
364 }
365
366 return type;
367 }
368
369 /********************************************
370 *
371 * Configuration Exported Functions
372 *
373 ********************************************/
374
375 int wilc_wlan_cfg_set_wid(u8 *frame, u32 offset, u16 id, u8 *buf, int size)
376 {
377 u8 type = (id >> 12) & 0xf;
378 int ret = 0;
379
380 switch (type) {
381 case CFG_BYTE_CMD:
382 if (size >= 1)
383 ret = wilc_wlan_cfg_set_byte(frame, offset, id, *buf);
384 break;
385
386 case CFG_HWORD_CMD:
387 if (size >= 2)
388 ret = wilc_wlan_cfg_set_hword(frame, offset, id,
389 *((u16 *)buf));
390 break;
391
392 case CFG_WORD_CMD:
393 if (size >= 4)
394 ret = wilc_wlan_cfg_set_word(frame, offset, id,
395 *((u32 *)buf));
396 break;
397
398 case CFG_STR_CMD:
399 ret = wilc_wlan_cfg_set_str(frame, offset, id, buf, size);
400 break;
401
402 case CFG_BIN_CMD:
403 ret = wilc_wlan_cfg_set_bin(frame, offset, id, buf, size);
404 break;
405 }
406
407 return ret;
408 }
409
410 int wilc_wlan_cfg_get_wid(u8 *frame, u32 offset, u16 id)
411 {
412 u8 *buf;
413
414 if ((offset + 2) >= MAX_CFG_FRAME_SIZE)
415 return 0;
416
417 buf = &frame[offset];
418
419 buf[0] = (u8)id;
420 buf[1] = (u8)(id >> 8);
421
422 return 2;
423 }
424
425 int wilc_wlan_cfg_get_wid_value(u16 wid, u8 *buffer, u32 buffer_size)
426 {
427 u32 type = (wid >> 12) & 0xf;
428 int i, ret = 0;
429
430 if (wid == WID_STATUS) {
431 *((u32 *)buffer) = g_mac.mac_status;
432 return 4;
433 }
434
435 i = 0;
436 if (type == CFG_BYTE_CMD) {
437 do {
438 if (g_cfg_byte[i].id == WID_NIL)
439 break;
440
441 if (g_cfg_byte[i].id == wid) {
442 memcpy(buffer, &g_cfg_byte[i].val, 1);
443 ret = 1;
444 break;
445 }
446 i++;
447 } while (1);
448 } else if (type == CFG_HWORD_CMD) {
449 do {
450 if (g_cfg_hword[i].id == WID_NIL)
451 break;
452
453 if (g_cfg_hword[i].id == wid) {
454 memcpy(buffer, &g_cfg_hword[i].val, 2);
455 ret = 2;
456 break;
457 }
458 i++;
459 } while (1);
460 } else if (type == CFG_WORD_CMD) {
461 do {
462 if (g_cfg_word[i].id == WID_NIL)
463 break;
464
465 if (g_cfg_word[i].id == wid) {
466 memcpy(buffer, &g_cfg_word[i].val, 4);
467 ret = 4;
468 break;
469 }
470 i++;
471 } while (1);
472 } else if (type == CFG_STR_CMD) {
473 do {
474 if (g_cfg_str[i].id == WID_NIL)
475 break;
476
477 if (g_cfg_str[i].id == wid) {
478 u32 size = g_cfg_str[i].str[0];
479
480 if (buffer_size >= size) {
481 if (g_cfg_str[i].id == WID_SITE_SURVEY_RESULTS) {
482 static int toggle;
483
484 i += toggle;
485 toggle ^= 1;
486
487 }
488 memcpy(buffer, &g_cfg_str[i].str[1], size);
489 ret = size;
490 }
491 break;
492 }
493 i++;
494 } while (1);
495 }
496
497 return ret;
498 }
499
500 int wilc_wlan_cfg_indicate_rx(struct wilc *wilc, u8 *frame, int size,
501 struct wilc_cfg_rsp *rsp)
502 {
503 int ret = 1;
504 u8 msg_type;
505 u8 msg_id;
506
507 msg_type = frame[0];
508 msg_id = frame[1]; /* seq no */
509 frame += 4;
510 size -= 4;
511
512 /**
513 * The valid types of response messages are 'R' (Response), 'I' (Information), and 'N' (Network Information)
514 **/
515
516 switch (msg_type) {
517 case 'R':
518 wilc_wlan_parse_response_frame(frame, size);
519 rsp->type = WILC_CFG_RSP;
520 rsp->seq_no = msg_id;
521 break;
522
523 case 'I':
524 rsp->type = wilc_wlan_parse_info_frame(frame, size);
525 rsp->seq_no = msg_id;
526 /*call host interface info parse as well*/
527 wilc_gnrl_async_info_received(wilc, frame - 4, size + 4);
528 break;
529
530 case 'N':
531 wilc_network_info_received(wilc, frame - 4, size + 4);
532 rsp->type = 0;
533 break;
534
535 case 'S':
536 wilc_scan_complete_received(wilc, frame - 4, size + 4);
537 break;
538
539 default:
540 rsp->type = 0;
541 rsp->seq_no = msg_id;
542 ret = 0;
543 break;
544 }
545
546 return ret;
547 }
548
549 int wilc_wlan_cfg_init(void)
550 {
551 memset((void *)&g_mac, 0, sizeof(struct wilc_mac_cfg));
552 return 1;
553 }