]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blob - drivers/staging/ks7010/ks_hostif.c
staging: ks7010: change two parameter types in hostif_mic_failure_request
[mirror_ubuntu-hirsute-kernel.git] / drivers / staging / ks7010 / ks_hostif.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Driver for KeyStream wireless LAN cards.
4 *
5 * Copyright (C) 2005-2008 KeyStream Corp.
6 * Copyright (C) 2009 Renesas Technology Corp.
7 */
8
9 #include <linux/circ_buf.h>
10 #include <linux/if_arp.h>
11 #include <net/iw_handler.h>
12 #include <uapi/linux/llc.h>
13 #include "eap_packet.h"
14 #include "ks_wlan.h"
15 #include "michael_mic.h"
16 #include "ks_hostif.h"
17
18 static inline void inc_smeqhead(struct ks_wlan_private *priv)
19 {
20 priv->sme_i.qhead = (priv->sme_i.qhead + 1) % SME_EVENT_BUFF_SIZE;
21 }
22
23 static inline void inc_smeqtail(struct ks_wlan_private *priv)
24 {
25 priv->sme_i.qtail = (priv->sme_i.qtail + 1) % SME_EVENT_BUFF_SIZE;
26 }
27
28 static inline unsigned int cnt_smeqbody(struct ks_wlan_private *priv)
29 {
30 return CIRC_CNT_TO_END(priv->sme_i.qhead, priv->sme_i.qtail,
31 SME_EVENT_BUFF_SIZE);
32 }
33
34 static inline u8 get_byte(struct ks_wlan_private *priv)
35 {
36 u8 data;
37
38 data = *(priv->rxp)++;
39 /* length check in advance ! */
40 --(priv->rx_size);
41 return data;
42 }
43
44 static inline u16 get_word(struct ks_wlan_private *priv)
45 {
46 u16 data;
47
48 data = (get_byte(priv) & 0xff);
49 data |= ((get_byte(priv) << 8) & 0xff00);
50 return data;
51 }
52
53 static inline u32 get_dword(struct ks_wlan_private *priv)
54 {
55 u32 data;
56
57 data = (get_byte(priv) & 0xff);
58 data |= ((get_byte(priv) << 8) & 0x0000ff00);
59 data |= ((get_byte(priv) << 16) & 0x00ff0000);
60 data |= ((get_byte(priv) << 24) & 0xff000000);
61 return data;
62 }
63
64 static void ks_wlan_hw_wakeup_task(struct work_struct *work)
65 {
66 struct ks_wlan_private *priv;
67 int ps_status;
68 long time_left;
69
70 priv = container_of(work, struct ks_wlan_private, wakeup_work);
71 ps_status = atomic_read(&priv->psstatus.status);
72
73 if (ps_status == PS_SNOOZE) {
74 ks_wlan_hw_wakeup_request(priv);
75 time_left = wait_for_completion_interruptible_timeout(
76 &priv->psstatus.wakeup_wait,
77 msecs_to_jiffies(20));
78 if (time_left <= 0) {
79 netdev_dbg(priv->net_dev, "wake up timeout or interrupted !!!\n");
80 schedule_work(&priv->wakeup_work);
81 return;
82 }
83 }
84
85 /* power save */
86 if (atomic_read(&priv->sme_task.count) > 0)
87 tasklet_enable(&priv->sme_task);
88 }
89
90 static void ks_wlan_do_power_save(struct ks_wlan_private *priv)
91 {
92 if (is_connect_status(priv->connect_status))
93 hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
94 else
95 priv->dev_state = DEVICE_STATE_READY;
96 }
97
98 static
99 int get_current_ap(struct ks_wlan_private *priv, struct link_ap_info *ap_info)
100 {
101 struct local_ap *ap;
102 union iwreq_data wrqu;
103 struct net_device *netdev = priv->net_dev;
104 u8 size;
105
106 ap = &priv->current_ap;
107
108 if (is_disconnect_status(priv->connect_status)) {
109 memset(ap, 0, sizeof(struct local_ap));
110 return -EPERM;
111 }
112
113 ether_addr_copy(ap->bssid, ap_info->bssid);
114 memcpy(ap->ssid.body, priv->reg.ssid.body,
115 priv->reg.ssid.size);
116 ap->ssid.size = priv->reg.ssid.size;
117 memcpy(ap->rate_set.body, ap_info->rate_set.body,
118 ap_info->rate_set.size);
119 ap->rate_set.size = ap_info->rate_set.size;
120 if (ap_info->ext_rate_set.size != 0) {
121 memcpy(&ap->rate_set.body[ap->rate_set.size],
122 ap_info->ext_rate_set.body,
123 ap_info->ext_rate_set.size);
124 ap->rate_set.size += ap_info->ext_rate_set.size;
125 }
126 ap->channel = ap_info->ds_parameter.channel;
127 ap->rssi = ap_info->rssi;
128 ap->sq = ap_info->sq;
129 ap->noise = ap_info->noise;
130 ap->capability = le16_to_cpu(ap_info->capability);
131 size = (ap_info->rsn.size <= RSN_IE_BODY_MAX) ?
132 ap_info->rsn.size : RSN_IE_BODY_MAX;
133 if ((ap_info->rsn_mode & RSN_MODE_WPA2) &&
134 (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)) {
135 ap->rsn_ie.id = RSN_INFO_ELEM_ID;
136 ap->rsn_ie.size = size;
137 memcpy(ap->rsn_ie.body, ap_info->rsn.body, size);
138 } else if ((ap_info->rsn_mode & RSN_MODE_WPA) &&
139 (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA)) {
140 ap->wpa_ie.id = WPA_INFO_ELEM_ID;
141 ap->wpa_ie.size = size;
142 memcpy(ap->wpa_ie.body, ap_info->rsn.body, size);
143 } else {
144 ap->rsn_ie.id = 0;
145 ap->rsn_ie.size = 0;
146 ap->wpa_ie.id = 0;
147 ap->wpa_ie.size = 0;
148 }
149
150 wrqu.data.length = 0;
151 wrqu.data.flags = 0;
152 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
153 if (is_connect_status(priv->connect_status)) {
154 ether_addr_copy(wrqu.ap_addr.sa_data, priv->current_ap.bssid);
155 netdev_dbg(priv->net_dev,
156 "IWEVENT: connect bssid=%pM\n",
157 wrqu.ap_addr.sa_data);
158 wireless_send_event(netdev, SIOCGIWAP, &wrqu, NULL);
159 }
160 netdev_dbg(priv->net_dev, "Link AP\n"
161 "- bssid=%02X:%02X:%02X:%02X:%02X:%02X\n"
162 "- essid=%s\n"
163 "- rate_set=%02X,%02X,%02X,%02X,%02X,%02X,%02X,%02X\n"
164 "- channel=%d\n"
165 "- rssi=%d\n"
166 "- sq=%d\n"
167 "- capability=%04X\n"
168 "- rsn.mode=%d\n"
169 "- rsn.size=%d\n"
170 "- ext_rate_set_size=%d\n"
171 "- rate_set_size=%d\n",
172 ap->bssid[0], ap->bssid[1], ap->bssid[2],
173 ap->bssid[3], ap->bssid[4], ap->bssid[5],
174 &(ap->ssid.body[0]),
175 ap->rate_set.body[0], ap->rate_set.body[1],
176 ap->rate_set.body[2], ap->rate_set.body[3],
177 ap->rate_set.body[4], ap->rate_set.body[5],
178 ap->rate_set.body[6], ap->rate_set.body[7],
179 ap->channel, ap->rssi, ap->sq, ap->capability,
180 ap_info->rsn_mode, ap_info->rsn.size,
181 ap_info->ext_rate_set.size, ap_info->rate_set.size);
182
183 return 0;
184 }
185
186 static u8 read_ie(unsigned char *bp, u8 max, u8 *body)
187 {
188 u8 size = (*(bp + 1) <= max) ? *(bp + 1) : max;
189
190 memcpy(body, bp + 2, size);
191 return size;
192 }
193
194
195 static
196 int get_ap_information(struct ks_wlan_private *priv, struct ap_info *ap_info,
197 struct local_ap *ap)
198 {
199 unsigned char *bp;
200 int bsize, offset;
201
202 memset(ap, 0, sizeof(struct local_ap));
203
204 ether_addr_copy(ap->bssid, ap_info->bssid);
205 ap->rssi = ap_info->rssi;
206 ap->sq = ap_info->sq;
207 ap->noise = ap_info->noise;
208 ap->capability = le16_to_cpu(ap_info->capability);
209 ap->channel = ap_info->ch_info;
210
211 bp = ap_info->body;
212 bsize = le16_to_cpu(ap_info->body_size);
213 offset = 0;
214
215 while (bsize > offset) {
216 switch (*bp) { /* Information Element ID */
217 case WLAN_EID_SSID:
218 ap->ssid.size = read_ie(bp, IEEE80211_MAX_SSID_LEN,
219 ap->ssid.body);
220 break;
221 case WLAN_EID_SUPP_RATES:
222 case WLAN_EID_EXT_SUPP_RATES:
223 if ((*(bp + 1) + ap->rate_set.size) <=
224 RATE_SET_MAX_SIZE) {
225 memcpy(&ap->rate_set.body[ap->rate_set.size],
226 bp + 2, *(bp + 1));
227 ap->rate_set.size += *(bp + 1);
228 } else {
229 memcpy(&ap->rate_set.body[ap->rate_set.size],
230 bp + 2,
231 RATE_SET_MAX_SIZE - ap->rate_set.size);
232 ap->rate_set.size +=
233 (RATE_SET_MAX_SIZE - ap->rate_set.size);
234 }
235 break;
236 case WLAN_EID_RSN:
237 ap->rsn_ie.id = *bp;
238 ap->rsn_ie.size = read_ie(bp, RSN_IE_BODY_MAX,
239 ap->rsn_ie.body);
240 break;
241 case WLAN_EID_VENDOR_SPECIFIC: /* WPA */
242 /* WPA OUI check */
243 if (memcmp(bp + 2, CIPHER_ID_WPA_WEP40, 4) == 0) {
244 ap->wpa_ie.id = *bp;
245 ap->wpa_ie.size = read_ie(bp, RSN_IE_BODY_MAX,
246 ap->wpa_ie.body);
247 }
248 break;
249 case WLAN_EID_DS_PARAMS:
250 case WLAN_EID_FH_PARAMS:
251 case WLAN_EID_CF_PARAMS:
252 case WLAN_EID_TIM:
253 case WLAN_EID_IBSS_PARAMS:
254 case WLAN_EID_COUNTRY:
255 case WLAN_EID_ERP_INFO:
256 break;
257 default:
258 netdev_err(priv->net_dev,
259 "unknown Element ID=%d\n", *bp);
260 break;
261 }
262
263 offset += 2; /* id & size field */
264 offset += *(bp + 1); /* +size offset */
265 bp += (*(bp + 1) + 2); /* pointer update */
266 }
267
268 return 0;
269 }
270
271 static
272 int hostif_data_indication_wpa(struct ks_wlan_private *priv,
273 unsigned short auth_type)
274 {
275 struct ether_hdr *eth_hdr;
276 unsigned short eth_proto;
277 unsigned char recv_mic[8];
278 char buf[128];
279 unsigned long now;
280 struct mic_failure *mic_failure;
281 struct michael_mic michael_mic;
282 union iwreq_data wrqu;
283 unsigned int key_index = auth_type - 1;
284 struct wpa_key *key = &priv->wpa.key[key_index];
285
286 eth_hdr = (struct ether_hdr *)(priv->rxp);
287 eth_proto = ntohs(eth_hdr->h_proto);
288
289 if (eth_hdr->h_dest_snap != eth_hdr->h_source_snap) {
290 netdev_err(priv->net_dev, "invalid data format\n");
291 priv->nstats.rx_errors++;
292 return -EINVAL;
293 }
294 if (((auth_type == TYPE_PMK1 &&
295 priv->wpa.pairwise_suite == IW_AUTH_CIPHER_TKIP) ||
296 (auth_type == TYPE_GMK1 &&
297 priv->wpa.group_suite == IW_AUTH_CIPHER_TKIP) ||
298 (auth_type == TYPE_GMK2 &&
299 priv->wpa.group_suite == IW_AUTH_CIPHER_TKIP)) &&
300 key->key_len) {
301 netdev_dbg(priv->net_dev, "TKIP: protocol=%04X: size=%u\n",
302 eth_proto, priv->rx_size);
303 /* MIC save */
304 memcpy(&recv_mic[0], (priv->rxp) + ((priv->rx_size) - 8), 8);
305 priv->rx_size = priv->rx_size - 8;
306 if (auth_type > 0 && auth_type < 4) { /* auth_type check */
307 michael_mic_function(&michael_mic, key->rx_mic_key,
308 priv->rxp, priv->rx_size,
309 0, michael_mic.result);
310 }
311 if (memcmp(michael_mic.result, recv_mic, 8) != 0) {
312 now = jiffies;
313 mic_failure = &priv->wpa.mic_failure;
314 /* MIC FAILURE */
315 if (mic_failure->last_failure_time &&
316 (now - mic_failure->last_failure_time) / HZ >= 60) {
317 mic_failure->failure = 0;
318 }
319 netdev_err(priv->net_dev, "MIC FAILURE\n");
320 if (mic_failure->failure == 0) {
321 mic_failure->failure = 1;
322 mic_failure->counter = 0;
323 } else if (mic_failure->failure == 1) {
324 mic_failure->failure = 2;
325 mic_failure->counter =
326 (u16)((now - mic_failure->last_failure_time) / HZ);
327 /* range 1-60 */
328 if (!mic_failure->counter)
329 mic_failure->counter = 1;
330 }
331 priv->wpa.mic_failure.last_failure_time = now;
332
333 /* needed parameters: count, keyid, key type, TSC */
334 sprintf(buf,
335 "MLME-MICHAELMICFAILURE.indication(keyid=%d %scast addr=%pM)",
336 key_index,
337 eth_hdr->h_dest[0] & 0x01 ? "broad" : "uni",
338 eth_hdr->h_source);
339 memset(&wrqu, 0, sizeof(wrqu));
340 wrqu.data.length = strlen(buf);
341 wireless_send_event(priv->net_dev, IWEVCUSTOM, &wrqu,
342 buf);
343 return -EINVAL;
344 }
345 }
346 return 0;
347 }
348
349 static
350 void hostif_data_indication(struct ks_wlan_private *priv)
351 {
352 unsigned int rx_ind_size; /* indicate data size */
353 struct sk_buff *skb;
354 u16 auth_type;
355 unsigned char temp[256];
356 struct ether_hdr *eth_hdr;
357 unsigned short eth_proto;
358 struct ieee802_1x_hdr *aa1x_hdr;
359 size_t size;
360 int ret;
361
362 /* min length check */
363 if (priv->rx_size <= ETH_HLEN) {
364 priv->nstats.rx_errors++;
365 return;
366 }
367
368 auth_type = get_word(priv); /* AuthType */
369 get_word(priv); /* Reserve Area */
370
371 eth_hdr = (struct ether_hdr *)(priv->rxp);
372 eth_proto = ntohs(eth_hdr->h_proto);
373
374 /* source address check */
375 if (ether_addr_equal(&priv->eth_addr[0], eth_hdr->h_source)) {
376 netdev_err(priv->net_dev, "invalid : source is own mac address !!\n");
377 netdev_err(priv->net_dev,
378 "eth_hdrernet->h_dest=%02X:%02X:%02X:%02X:%02X:%02X\n",
379 eth_hdr->h_source[0], eth_hdr->h_source[1],
380 eth_hdr->h_source[2], eth_hdr->h_source[3],
381 eth_hdr->h_source[4], eth_hdr->h_source[5]);
382 priv->nstats.rx_errors++;
383 return;
384 }
385
386 /* for WPA */
387 if (auth_type != TYPE_DATA && priv->wpa.rsn_enabled) {
388 ret = hostif_data_indication_wpa(priv, auth_type);
389 if (ret)
390 return;
391 }
392
393 if ((priv->connect_status & FORCE_DISCONNECT) ||
394 priv->wpa.mic_failure.failure == 2) {
395 return;
396 }
397
398 /* check 13th byte at rx data */
399 switch (*(priv->rxp + 12)) {
400 case LLC_SAP_SNAP:
401 rx_ind_size = priv->rx_size - 6;
402 skb = dev_alloc_skb(rx_ind_size);
403 if (!skb) {
404 priv->nstats.rx_dropped++;
405 return;
406 }
407 netdev_dbg(priv->net_dev, "SNAP, rx_ind_size = %d\n",
408 rx_ind_size);
409
410 size = ETH_ALEN * 2;
411 skb_put_data(skb, priv->rxp, size);
412
413 /* (SNAP+UI..) skip */
414
415 size = rx_ind_size - (ETH_ALEN * 2);
416 skb_put_data(skb, &eth_hdr->h_proto, size);
417
418 aa1x_hdr = (struct ieee802_1x_hdr *)(priv->rxp + ETHER_HDR_SIZE);
419 break;
420 case LLC_SAP_NETBEUI:
421 rx_ind_size = (priv->rx_size + 2);
422 skb = dev_alloc_skb(rx_ind_size);
423 if (!skb) {
424 priv->nstats.rx_dropped++;
425 return;
426 }
427 netdev_dbg(priv->net_dev, "NETBEUI/NetBIOS rx_ind_size=%d\n",
428 rx_ind_size);
429
430 /* 8802/FDDI MAC copy */
431 skb_put_data(skb, priv->rxp, 12);
432
433 /* NETBEUI size add */
434 temp[0] = (((rx_ind_size - 12) >> 8) & 0xff);
435 temp[1] = ((rx_ind_size - 12) & 0xff);
436 skb_put_data(skb, temp, 2);
437
438 /* copy after Type */
439 skb_put_data(skb, priv->rxp + 12, rx_ind_size - 14);
440
441 aa1x_hdr = (struct ieee802_1x_hdr *)(priv->rxp + 14);
442 break;
443 default: /* other rx data */
444 netdev_err(priv->net_dev, "invalid data format\n");
445 priv->nstats.rx_errors++;
446 return;
447 }
448
449 if (aa1x_hdr->type == IEEE802_1X_TYPE_EAPOL_KEY &&
450 priv->wpa.rsn_enabled)
451 atomic_set(&priv->psstatus.snooze_guard, 1);
452
453 /* rx indication */
454 skb->dev = priv->net_dev;
455 skb->protocol = eth_type_trans(skb, skb->dev);
456 priv->nstats.rx_packets++;
457 priv->nstats.rx_bytes += rx_ind_size;
458 netif_rx(skb);
459 }
460
461 static
462 void hostif_mib_get_confirm(struct ks_wlan_private *priv)
463 {
464 struct net_device *dev = priv->net_dev;
465 u32 mib_status;
466 u32 mib_attribute;
467 u16 mib_val_size;
468 u16 mib_val_type;
469
470 mib_status = get_dword(priv);
471 mib_attribute = get_dword(priv);
472 mib_val_size = get_word(priv);
473 mib_val_type = get_word(priv);
474
475 if (mib_status) {
476 netdev_err(priv->net_dev, "attribute=%08X, status=%08X\n",
477 mib_attribute, mib_status);
478 return;
479 }
480
481 switch (mib_attribute) {
482 case DOT11_MAC_ADDRESS:
483 hostif_sme_enqueue(priv, SME_GET_MAC_ADDRESS);
484 ether_addr_copy(priv->eth_addr, priv->rxp);
485 priv->mac_address_valid = true;
486 ether_addr_copy(dev->dev_addr, priv->eth_addr);
487 netdev_info(dev, "MAC ADDRESS = %pM\n", priv->eth_addr);
488 break;
489 case DOT11_PRODUCT_VERSION:
490 priv->version_size = priv->rx_size;
491 memcpy(priv->firmware_version, priv->rxp, priv->rx_size);
492 priv->firmware_version[priv->rx_size] = '\0';
493 netdev_info(dev, "firmware ver. = %s\n",
494 priv->firmware_version);
495 hostif_sme_enqueue(priv, SME_GET_PRODUCT_VERSION);
496 /* wake_up_interruptible_all(&priv->confirm_wait); */
497 complete(&priv->confirm_wait);
498 break;
499 case LOCAL_GAIN:
500 memcpy(&priv->gain, priv->rxp, sizeof(priv->gain));
501 netdev_dbg(priv->net_dev, "tx_mode=%d, rx_mode=%d, tx_gain=%d, rx_gain=%d\n",
502 priv->gain.tx_mode, priv->gain.rx_mode,
503 priv->gain.tx_gain, priv->gain.rx_gain);
504 break;
505 case LOCAL_EEPROM_SUM:
506 memcpy(&priv->eeprom_sum, priv->rxp, sizeof(priv->eeprom_sum));
507 if (priv->eeprom_sum.type != 0 &&
508 priv->eeprom_sum.type != 1) {
509 netdev_err(dev, "LOCAL_EEPROM_SUM error!\n");
510 return;
511 }
512 priv->eeprom_checksum = (priv->eeprom_sum.type == 0) ?
513 EEPROM_CHECKSUM_NONE :
514 (priv->eeprom_sum.result == 0) ?
515 EEPROM_NG : EEPROM_OK;
516 break;
517 default:
518 netdev_err(priv->net_dev, "mib_attribute=%08x\n",
519 (unsigned int)mib_attribute);
520 break;
521 }
522 }
523
524 static
525 void hostif_mib_set_confirm(struct ks_wlan_private *priv)
526 {
527 u32 mib_status;
528 u32 mib_attribute;
529
530 mib_status = get_dword(priv);
531 mib_attribute = get_dword(priv);
532
533 if (mib_status) {
534 /* in case of error */
535 netdev_err(priv->net_dev, "error :: attribute=%08X, status=%08X\n",
536 mib_attribute, mib_status);
537 }
538
539 switch (mib_attribute) {
540 case DOT11_RTS_THRESHOLD:
541 hostif_sme_enqueue(priv, SME_RTS_THRESHOLD_CONFIRM);
542 break;
543 case DOT11_FRAGMENTATION_THRESHOLD:
544 hostif_sme_enqueue(priv, SME_FRAGMENTATION_THRESHOLD_CONFIRM);
545 break;
546 case DOT11_WEP_DEFAULT_KEY_ID:
547 if (!priv->wpa.wpa_enabled)
548 hostif_sme_enqueue(priv, SME_WEP_INDEX_CONFIRM);
549 break;
550 case DOT11_WEP_DEFAULT_KEY_VALUE1:
551 if (priv->wpa.rsn_enabled)
552 hostif_sme_enqueue(priv, SME_SET_PMK_TSC);
553 else
554 hostif_sme_enqueue(priv, SME_WEP_KEY1_CONFIRM);
555 break;
556 case DOT11_WEP_DEFAULT_KEY_VALUE2:
557 if (priv->wpa.rsn_enabled)
558 hostif_sme_enqueue(priv, SME_SET_GMK1_TSC);
559 else
560 hostif_sme_enqueue(priv, SME_WEP_KEY2_CONFIRM);
561 break;
562 case DOT11_WEP_DEFAULT_KEY_VALUE3:
563 if (priv->wpa.rsn_enabled)
564 hostif_sme_enqueue(priv, SME_SET_GMK2_TSC);
565 else
566 hostif_sme_enqueue(priv, SME_WEP_KEY3_CONFIRM);
567 break;
568 case DOT11_WEP_DEFAULT_KEY_VALUE4:
569 if (!priv->wpa.rsn_enabled)
570 hostif_sme_enqueue(priv, SME_WEP_KEY4_CONFIRM);
571 break;
572 case DOT11_PRIVACY_INVOKED:
573 if (!priv->wpa.rsn_enabled)
574 hostif_sme_enqueue(priv, SME_WEP_FLAG_CONFIRM);
575 break;
576 case DOT11_RSN_ENABLED:
577 hostif_sme_enqueue(priv, SME_RSN_ENABLED_CONFIRM);
578 break;
579 case LOCAL_RSN_MODE:
580 hostif_sme_enqueue(priv, SME_RSN_MODE_CONFIRM);
581 break;
582 case LOCAL_MULTICAST_ADDRESS:
583 hostif_sme_enqueue(priv, SME_MULTICAST_REQUEST);
584 break;
585 case LOCAL_MULTICAST_FILTER:
586 hostif_sme_enqueue(priv, SME_MULTICAST_CONFIRM);
587 break;
588 case LOCAL_CURRENTADDRESS:
589 priv->mac_address_valid = true;
590 break;
591 case DOT11_RSN_CONFIG_MULTICAST_CIPHER:
592 hostif_sme_enqueue(priv, SME_RSN_MCAST_CONFIRM);
593 break;
594 case DOT11_RSN_CONFIG_UNICAST_CIPHER:
595 hostif_sme_enqueue(priv, SME_RSN_UCAST_CONFIRM);
596 break;
597 case DOT11_RSN_CONFIG_AUTH_SUITE:
598 hostif_sme_enqueue(priv, SME_RSN_AUTH_CONFIRM);
599 break;
600 case DOT11_GMK1_TSC:
601 if (atomic_read(&priv->psstatus.snooze_guard))
602 atomic_set(&priv->psstatus.snooze_guard, 0);
603 break;
604 case DOT11_GMK2_TSC:
605 if (atomic_read(&priv->psstatus.snooze_guard))
606 atomic_set(&priv->psstatus.snooze_guard, 0);
607 break;
608 case DOT11_PMK_TSC:
609 case LOCAL_PMK:
610 case LOCAL_GAIN:
611 case LOCAL_WPS_ENABLE:
612 case LOCAL_WPS_PROBE_REQ:
613 case LOCAL_REGION:
614 default:
615 break;
616 }
617 }
618
619 static
620 void hostif_power_mgmt_confirm(struct ks_wlan_private *priv)
621 {
622 if (priv->reg.power_mgmt > POWER_MGMT_ACTIVE &&
623 priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
624 atomic_set(&priv->psstatus.confirm_wait, 0);
625 priv->dev_state = DEVICE_STATE_SLEEP;
626 ks_wlan_hw_power_save(priv);
627 } else {
628 priv->dev_state = DEVICE_STATE_READY;
629 }
630 }
631
632 static
633 void hostif_sleep_confirm(struct ks_wlan_private *priv)
634 {
635 atomic_set(&priv->sleepstatus.doze_request, 1);
636 queue_delayed_work(priv->wq, &priv->rw_dwork, 1);
637 }
638
639 static
640 void hostif_start_confirm(struct ks_wlan_private *priv)
641 {
642 union iwreq_data wrqu;
643
644 wrqu.data.length = 0;
645 wrqu.data.flags = 0;
646 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
647 if (is_connect_status(priv->connect_status)) {
648 eth_zero_addr(wrqu.ap_addr.sa_data);
649 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
650 }
651 netdev_dbg(priv->net_dev, " scan_ind_count=%d\n", priv->scan_ind_count);
652 hostif_sme_enqueue(priv, SME_START_CONFIRM);
653 }
654
655 static
656 void hostif_connect_indication(struct ks_wlan_private *priv)
657 {
658 u16 connect_code;
659 unsigned int tmp = 0;
660 unsigned int old_status = priv->connect_status;
661 struct net_device *netdev = priv->net_dev;
662 union iwreq_data wrqu0;
663
664 connect_code = get_word(priv);
665
666 switch (connect_code) {
667 case RESULT_CONNECT:
668 if (!(priv->connect_status & FORCE_DISCONNECT))
669 netif_carrier_on(netdev);
670 tmp = FORCE_DISCONNECT & priv->connect_status;
671 priv->connect_status = tmp + CONNECT_STATUS;
672 break;
673 case RESULT_DISCONNECT:
674 netif_carrier_off(netdev);
675 tmp = FORCE_DISCONNECT & priv->connect_status;
676 priv->connect_status = tmp + DISCONNECT_STATUS;
677 break;
678 default:
679 netdev_dbg(priv->net_dev, "unknown connect_code=%d :: scan_ind_count=%d\n",
680 connect_code, priv->scan_ind_count);
681 netif_carrier_off(netdev);
682 tmp = FORCE_DISCONNECT & priv->connect_status;
683 priv->connect_status = tmp + DISCONNECT_STATUS;
684 break;
685 }
686
687 get_current_ap(priv, (struct link_ap_info *)priv->rxp);
688 if (is_connect_status(priv->connect_status) &&
689 is_disconnect_status(old_status)) {
690 /* for power save */
691 atomic_set(&priv->psstatus.snooze_guard, 0);
692 atomic_set(&priv->psstatus.confirm_wait, 0);
693 }
694 ks_wlan_do_power_save(priv);
695
696 wrqu0.data.length = 0;
697 wrqu0.data.flags = 0;
698 wrqu0.ap_addr.sa_family = ARPHRD_ETHER;
699 if (is_disconnect_status(priv->connect_status) &&
700 is_connect_status(old_status)) {
701 eth_zero_addr(wrqu0.ap_addr.sa_data);
702 netdev_dbg(priv->net_dev, "disconnect :: scan_ind_count=%d\n",
703 priv->scan_ind_count);
704 wireless_send_event(netdev, SIOCGIWAP, &wrqu0, NULL);
705 }
706 priv->scan_ind_count = 0;
707 }
708
709 static
710 void hostif_scan_indication(struct ks_wlan_private *priv)
711 {
712 int i;
713 struct ap_info *ap_info;
714
715 netdev_dbg(priv->net_dev,
716 "scan_ind_count = %d\n", priv->scan_ind_count);
717 ap_info = (struct ap_info *)(priv->rxp);
718
719 if (priv->scan_ind_count) {
720 /* bssid check */
721 for (i = 0; i < priv->aplist.size; i++) {
722 u8 *bssid = priv->aplist.ap[i].bssid;
723
724 if (ether_addr_equal(ap_info->bssid, bssid))
725 continue;
726
727 if (ap_info->frame_type == IEEE80211_STYPE_PROBE_RESP)
728 get_ap_information(priv, ap_info,
729 &priv->aplist.ap[i]);
730 return;
731 }
732 }
733 priv->scan_ind_count++;
734 if (priv->scan_ind_count < LOCAL_APLIST_MAX + 1) {
735 netdev_dbg(priv->net_dev, " scan_ind_count=%d :: aplist.size=%d\n",
736 priv->scan_ind_count, priv->aplist.size);
737 get_ap_information(priv, (struct ap_info *)(priv->rxp),
738 &(priv->aplist.ap[priv->scan_ind_count - 1]));
739 priv->aplist.size = priv->scan_ind_count;
740 } else {
741 netdev_dbg(priv->net_dev, " count over :: scan_ind_count=%d\n",
742 priv->scan_ind_count);
743 }
744 }
745
746 static
747 void hostif_stop_confirm(struct ks_wlan_private *priv)
748 {
749 unsigned int tmp = 0;
750 unsigned int old_status = priv->connect_status;
751 struct net_device *netdev = priv->net_dev;
752 union iwreq_data wrqu0;
753
754 if (priv->dev_state == DEVICE_STATE_SLEEP)
755 priv->dev_state = DEVICE_STATE_READY;
756
757 /* disconnect indication */
758 if (is_connect_status(priv->connect_status)) {
759 netif_carrier_off(netdev);
760 tmp = FORCE_DISCONNECT & priv->connect_status;
761 priv->connect_status = tmp | DISCONNECT_STATUS;
762 netdev_info(netdev, "IWEVENT: disconnect\n");
763
764 wrqu0.data.length = 0;
765 wrqu0.data.flags = 0;
766 wrqu0.ap_addr.sa_family = ARPHRD_ETHER;
767 if (is_disconnect_status(priv->connect_status) &&
768 is_connect_status(old_status)) {
769 eth_zero_addr(wrqu0.ap_addr.sa_data);
770 netdev_info(netdev, "IWEVENT: disconnect\n");
771 wireless_send_event(netdev, SIOCGIWAP, &wrqu0, NULL);
772 }
773 priv->scan_ind_count = 0;
774 }
775
776 hostif_sme_enqueue(priv, SME_STOP_CONFIRM);
777 }
778
779 static
780 void hostif_ps_adhoc_set_confirm(struct ks_wlan_private *priv)
781 {
782 priv->infra_status = 0; /* infrastructure mode cancel */
783 hostif_sme_enqueue(priv, SME_MODE_SET_CONFIRM);
784 }
785
786 static
787 void hostif_infrastructure_set_confirm(struct ks_wlan_private *priv)
788 {
789 u16 result_code;
790
791 result_code = get_word(priv);
792 priv->infra_status = 1; /* infrastructure mode set */
793 hostif_sme_enqueue(priv, SME_MODE_SET_CONFIRM);
794 }
795
796 static
797 void hostif_adhoc_set_confirm(struct ks_wlan_private *priv)
798 {
799 priv->infra_status = 1; /* infrastructure mode set */
800 hostif_sme_enqueue(priv, SME_MODE_SET_CONFIRM);
801 }
802
803 static
804 void hostif_associate_indication(struct ks_wlan_private *priv)
805 {
806 struct association_request *assoc_req;
807 struct association_response *assoc_resp;
808 unsigned char *pb;
809 union iwreq_data wrqu;
810 char buf[IW_CUSTOM_MAX];
811 char *pbuf = &buf[0];
812 int i;
813
814 static const char associnfo_leader0[] = "ASSOCINFO(ReqIEs=";
815 static const char associnfo_leader1[] = " RespIEs=";
816
817 assoc_req = (struct association_request *)(priv->rxp);
818 assoc_resp = (struct association_response *)(assoc_req + 1);
819 pb = (unsigned char *)(assoc_resp + 1);
820
821 memset(&wrqu, 0, sizeof(wrqu));
822 memcpy(pbuf, associnfo_leader0, sizeof(associnfo_leader0) - 1);
823 wrqu.data.length += sizeof(associnfo_leader0) - 1;
824 pbuf += sizeof(associnfo_leader0) - 1;
825
826 for (i = 0; i < le16_to_cpu(assoc_req->req_ies_size); i++)
827 pbuf += sprintf(pbuf, "%02x", *(pb + i));
828 wrqu.data.length += (le16_to_cpu(assoc_req->req_ies_size)) * 2;
829
830 memcpy(pbuf, associnfo_leader1, sizeof(associnfo_leader1) - 1);
831 wrqu.data.length += sizeof(associnfo_leader1) - 1;
832 pbuf += sizeof(associnfo_leader1) - 1;
833
834 pb += le16_to_cpu(assoc_req->req_ies_size);
835 for (i = 0; i < le16_to_cpu(assoc_resp->resp_ies_size); i++)
836 pbuf += sprintf(pbuf, "%02x", *(pb + i));
837 wrqu.data.length += (le16_to_cpu(assoc_resp->resp_ies_size)) * 2;
838
839 pbuf += sprintf(pbuf, ")");
840 wrqu.data.length += 1;
841
842 wireless_send_event(priv->net_dev, IWEVCUSTOM, &wrqu, buf);
843 }
844
845 static
846 void hostif_bss_scan_confirm(struct ks_wlan_private *priv)
847 {
848 u32 result_code;
849 struct net_device *dev = priv->net_dev;
850 union iwreq_data wrqu;
851
852 result_code = get_dword(priv);
853 netdev_dbg(priv->net_dev, "result=%d :: scan_ind_count=%d\n",
854 result_code, priv->scan_ind_count);
855
856 priv->sme_i.sme_flag &= ~SME_AP_SCAN;
857 hostif_sme_enqueue(priv, SME_BSS_SCAN_CONFIRM);
858
859 wrqu.data.length = 0;
860 wrqu.data.flags = 0;
861 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
862 priv->scan_ind_count = 0;
863 }
864
865 static
866 void hostif_phy_information_confirm(struct ks_wlan_private *priv)
867 {
868 struct iw_statistics *wstats = &priv->wstats;
869 u8 rssi, signal, noise;
870 u8 link_speed;
871 u32 transmitted_frame_count, received_fragment_count;
872 u32 failed_count, fcs_error_count;
873
874 rssi = get_byte(priv);
875 signal = get_byte(priv);
876 noise = get_byte(priv);
877 link_speed = get_byte(priv);
878 transmitted_frame_count = get_dword(priv);
879 received_fragment_count = get_dword(priv);
880 failed_count = get_dword(priv);
881 fcs_error_count = get_dword(priv);
882
883 netdev_dbg(priv->net_dev, "phyinfo confirm rssi=%d signal=%d\n",
884 rssi, signal);
885 priv->current_rate = (link_speed & RATE_MASK);
886 wstats->qual.qual = signal;
887 wstats->qual.level = 256 - rssi;
888 wstats->qual.noise = 0; /* invalid noise value */
889 wstats->qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
890
891 netdev_dbg(priv->net_dev, "\n rssi=%u\n"
892 " signal=%u\n"
893 " link_speed=%ux500Kbps\n"
894 " transmitted_frame_count=%u\n"
895 " received_fragment_count=%u\n"
896 " failed_count=%u\n"
897 " fcs_error_count=%u\n",
898 rssi, signal, link_speed, transmitted_frame_count,
899 received_fragment_count, failed_count, fcs_error_count);
900 /* wake_up_interruptible_all(&priv->confirm_wait); */
901 complete(&priv->confirm_wait);
902 }
903
904 static
905 void hostif_mic_failure_confirm(struct ks_wlan_private *priv)
906 {
907 netdev_dbg(priv->net_dev, "mic_failure=%u\n",
908 priv->wpa.mic_failure.failure);
909 hostif_sme_enqueue(priv, SME_MIC_FAILURE_CONFIRM);
910 }
911
912 static
913 void hostif_event_check(struct ks_wlan_private *priv)
914 {
915 u16 event;
916
917 event = get_word(priv);
918 switch (event) {
919 case HIF_DATA_IND:
920 hostif_data_indication(priv);
921 break;
922 case HIF_MIB_GET_CONF:
923 hostif_mib_get_confirm(priv);
924 break;
925 case HIF_MIB_SET_CONF:
926 hostif_mib_set_confirm(priv);
927 break;
928 case HIF_POWER_MGMT_CONF:
929 hostif_power_mgmt_confirm(priv);
930 break;
931 case HIF_SLEEP_CONF:
932 hostif_sleep_confirm(priv);
933 break;
934 case HIF_START_CONF:
935 hostif_start_confirm(priv);
936 break;
937 case HIF_CONNECT_IND:
938 hostif_connect_indication(priv);
939 break;
940 case HIF_STOP_CONF:
941 hostif_stop_confirm(priv);
942 break;
943 case HIF_PS_ADH_SET_CONF:
944 hostif_ps_adhoc_set_confirm(priv);
945 break;
946 case HIF_INFRA_SET_CONF:
947 case HIF_INFRA_SET2_CONF:
948 hostif_infrastructure_set_confirm(priv);
949 break;
950 case HIF_ADH_SET_CONF:
951 case HIF_ADH_SET2_CONF:
952 hostif_adhoc_set_confirm(priv);
953 break;
954 case HIF_ASSOC_INFO_IND:
955 hostif_associate_indication(priv);
956 break;
957 case HIF_MIC_FAILURE_CONF:
958 hostif_mic_failure_confirm(priv);
959 break;
960 case HIF_SCAN_CONF:
961 hostif_bss_scan_confirm(priv);
962 break;
963 case HIF_PHY_INFO_CONF:
964 case HIF_PHY_INFO_IND:
965 hostif_phy_information_confirm(priv);
966 break;
967 case HIF_SCAN_IND:
968 hostif_scan_indication(priv);
969 break;
970 case HIF_AP_SET_CONF:
971 default:
972 netdev_err(priv->net_dev, "undefined event[%04X]\n", event);
973 /* wake_up_all(&priv->confirm_wait); */
974 complete(&priv->confirm_wait);
975 break;
976 }
977
978 /* add event to hostt buffer */
979 priv->hostt.buff[priv->hostt.qtail] = event;
980 priv->hostt.qtail = (priv->hostt.qtail + 1) % SME_EVENT_BUFF_SIZE;
981 }
982
983 /* allocate size bytes, set header size and event */
984 static void *hostif_generic_request(size_t size, int event)
985 {
986 struct hostif_hdr *p;
987
988 p = kzalloc(hif_align_size(size), GFP_ATOMIC);
989 if (!p)
990 return NULL;
991
992 p->size = cpu_to_le16((u16)(size - sizeof(p->size)));
993 p->event = cpu_to_le16(event);
994
995 return p;
996 }
997
998 int hostif_data_request(struct ks_wlan_private *priv, struct sk_buff *skb)
999 {
1000 unsigned int skb_len = 0;
1001 unsigned char *buffer = NULL;
1002 unsigned int length = 0;
1003 struct hostif_data_request *pp;
1004 unsigned char *p;
1005 int result = 0;
1006 unsigned short eth_proto;
1007 struct ether_hdr *eth_hdr;
1008 struct michael_mic michael_mic;
1009 unsigned short keyinfo = 0;
1010 struct ieee802_1x_hdr *aa1x_hdr;
1011 struct wpa_eapol_key *eap_key;
1012 struct ethhdr *eth;
1013 size_t size;
1014 int ret;
1015
1016 skb_len = skb->len;
1017 if (skb_len > ETH_FRAME_LEN) {
1018 netdev_err(priv->net_dev, "bad length skb_len=%d\n", skb_len);
1019 ret = -EOVERFLOW;
1020 goto err_kfree_skb;
1021 }
1022
1023 if (is_disconnect_status(priv->connect_status) ||
1024 (priv->connect_status & FORCE_DISCONNECT) ||
1025 priv->wpa.mic_failure.stop) {
1026 if (netif_queue_stopped(priv->net_dev))
1027 netif_wake_queue(priv->net_dev);
1028 if (skb)
1029 dev_kfree_skb(skb);
1030
1031 return 0;
1032 }
1033
1034 /* power save wakeup */
1035 if (atomic_read(&priv->psstatus.status) == PS_SNOOZE) {
1036 if (!netif_queue_stopped(priv->net_dev))
1037 netif_stop_queue(priv->net_dev);
1038 }
1039
1040 size = sizeof(*pp) + 6 + skb_len + 8;
1041 pp = kmalloc(hif_align_size(size), GFP_ATOMIC);
1042 if (!pp) {
1043 ret = -ENOMEM;
1044 goto err_kfree_skb;
1045 }
1046
1047 p = (unsigned char *)pp->data;
1048
1049 buffer = skb->data;
1050 length = skb->len;
1051
1052 /* skb check */
1053 eth = (struct ethhdr *)skb->data;
1054 if (!ether_addr_equal(&priv->eth_addr[0], eth->h_source)) {
1055 netdev_err(priv->net_dev,
1056 "Invalid mac address: ethernet->h_source=%pM\n",
1057 eth->h_source);
1058 ret = -ENXIO;
1059 goto err_kfree;
1060 }
1061
1062 /* dest and src MAC address copy */
1063 size = ETH_ALEN * 2;
1064 memcpy(p, buffer, size);
1065 p += size;
1066 buffer += size;
1067 length -= size;
1068
1069 /* EtherType/Length check */
1070 if (*(buffer + 1) + (*buffer << 8) > 1500) {
1071 /* ProtocolEAP = *(buffer+1) + (*buffer << 8); */
1072 /* SAP/CTL/OUI(6 byte) add */
1073 *p++ = 0xAA; /* DSAP */
1074 *p++ = 0xAA; /* SSAP */
1075 *p++ = 0x03; /* CTL */
1076 *p++ = 0x00; /* OUI ("000000") */
1077 *p++ = 0x00; /* OUI ("000000") */
1078 *p++ = 0x00; /* OUI ("000000") */
1079 skb_len += 6;
1080 } else {
1081 /* Length(2 byte) delete */
1082 buffer += 2;
1083 length -= 2;
1084 skb_len -= 2;
1085 }
1086
1087 /* pp->data copy */
1088 memcpy(p, buffer, length);
1089
1090 p += length;
1091
1092 /* for WPA */
1093 eth_hdr = (struct ether_hdr *)&pp->data[0];
1094 eth_proto = ntohs(eth_hdr->h_proto);
1095
1096 /* for MIC FAILURE REPORT check */
1097 if (eth_proto == ETH_P_PAE &&
1098 priv->wpa.mic_failure.failure > 0) {
1099 aa1x_hdr = (struct ieee802_1x_hdr *)(eth_hdr + 1);
1100 if (aa1x_hdr->type == IEEE802_1X_TYPE_EAPOL_KEY) {
1101 eap_key = (struct wpa_eapol_key *)(aa1x_hdr + 1);
1102 keyinfo = ntohs(eap_key->key_info);
1103 }
1104 }
1105
1106 if (priv->wpa.rsn_enabled && priv->wpa.key[0].key_len) {
1107 /* no encryption */
1108 if (eth_proto == ETH_P_PAE &&
1109 priv->wpa.key[1].key_len == 0 &&
1110 priv->wpa.key[2].key_len == 0 &&
1111 priv->wpa.key[3].key_len == 0) {
1112 pp->auth_type = cpu_to_le16((u16)TYPE_AUTH);
1113 } else {
1114 if (priv->wpa.pairwise_suite == IW_AUTH_CIPHER_TKIP) {
1115 michael_mic_function(&michael_mic,
1116 priv->wpa.key[0].tx_mic_key,
1117 &pp->data[0], skb_len,
1118 0, michael_mic.result);
1119 memcpy(p, michael_mic.result, 8);
1120 length += 8;
1121 skb_len += 8;
1122 p += 8;
1123 pp->auth_type =
1124 cpu_to_le16((u16)TYPE_DATA);
1125
1126 } else if (priv->wpa.pairwise_suite ==
1127 IW_AUTH_CIPHER_CCMP) {
1128 pp->auth_type =
1129 cpu_to_le16((u16)TYPE_DATA);
1130 }
1131 }
1132 } else {
1133 if (eth_proto == ETH_P_PAE)
1134 pp->auth_type = cpu_to_le16((u16)TYPE_AUTH);
1135 else
1136 pp->auth_type = cpu_to_le16((u16)TYPE_DATA);
1137 }
1138
1139 /* header value set */
1140 pp->header.size =
1141 cpu_to_le16((u16)
1142 (sizeof(*pp) - sizeof(pp->header.size) + skb_len));
1143 pp->header.event = cpu_to_le16((u16)HIF_DATA_REQ);
1144
1145 /* tx request */
1146 result = ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp) + skb_len),
1147 send_packet_complete, skb);
1148
1149 /* MIC FAILURE REPORT check */
1150 if (eth_proto == ETH_P_PAE &&
1151 priv->wpa.mic_failure.failure > 0) {
1152 if (keyinfo & WPA_KEY_INFO_ERROR &&
1153 keyinfo & WPA_KEY_INFO_REQUEST) {
1154 netdev_err(priv->net_dev,
1155 "MIC ERROR Report SET : %04X\n", keyinfo);
1156 hostif_sme_enqueue(priv, SME_MIC_FAILURE_REQUEST);
1157 }
1158 if (priv->wpa.mic_failure.failure == 2)
1159 priv->wpa.mic_failure.stop = 1;
1160 }
1161
1162 return result;
1163
1164 err_kfree:
1165 kfree(pp);
1166 err_kfree_skb:
1167 dev_kfree_skb(skb);
1168
1169 return ret;
1170 }
1171
1172 static inline void ps_confirm_wait_inc(struct ks_wlan_private *priv)
1173 {
1174 if (atomic_read(&priv->psstatus.status) > PS_ACTIVE_SET)
1175 atomic_inc(&priv->psstatus.confirm_wait);
1176 }
1177
1178 static inline void send_request_to_device(struct ks_wlan_private *priv,
1179 void *data, size_t size)
1180 {
1181 ps_confirm_wait_inc(priv);
1182 ks_wlan_hw_tx(priv, data, size, NULL, NULL);
1183 }
1184
1185 static void hostif_mib_get_request(struct ks_wlan_private *priv,
1186 u32 mib_attribute)
1187 {
1188 struct hostif_mib_get_request *pp;
1189
1190 pp = hostif_generic_request(sizeof(*pp), HIF_MIB_GET_REQ);
1191 if (!pp)
1192 return;
1193
1194 pp->mib_attribute = cpu_to_le32(mib_attribute);
1195
1196 send_request_to_device(priv, pp, hif_align_size(sizeof(*pp)));
1197 }
1198
1199 static void hostif_mib_set_request(struct ks_wlan_private *priv,
1200 enum mib_attribute attr,
1201 enum mib_data_type type,
1202 void *data, size_t size)
1203 {
1204 struct hostif_mib_set_request_t *pp;
1205
1206 if (priv->dev_state < DEVICE_STATE_BOOT)
1207 return;
1208
1209 pp = hostif_generic_request(sizeof(*pp), HIF_MIB_SET_REQ);
1210 if (!pp)
1211 return;
1212
1213 pp->mib_attribute = cpu_to_le32(attr);
1214 pp->mib_value.size = cpu_to_le16((u16)size);
1215 pp->mib_value.type = cpu_to_le16(type);
1216 memcpy(&pp->mib_value.body, data, size);
1217
1218 send_request_to_device(priv, pp, hif_align_size(sizeof(*pp) + size));
1219 }
1220
1221 static inline void hostif_mib_set_request_int(struct ks_wlan_private *priv,
1222 enum mib_attribute attr, int val)
1223 {
1224 __le32 v = cpu_to_le32((u32)val);
1225 size_t size = sizeof(v);
1226
1227 hostif_mib_set_request(priv, attr, MIB_VALUE_TYPE_INT, &v, size);
1228 }
1229
1230 static inline void hostif_mib_set_request_bool(struct ks_wlan_private *priv,
1231 enum mib_attribute attr,
1232 bool val)
1233 {
1234 __le32 v = cpu_to_le32((u32)val);
1235 size_t size = sizeof(v);
1236
1237 hostif_mib_set_request(priv, attr, MIB_VALUE_TYPE_BOOL, &v, size);
1238 }
1239
1240 static inline void hostif_mib_set_request_ostring(struct ks_wlan_private *priv,
1241 enum mib_attribute attr,
1242 void *data, size_t size)
1243 {
1244 hostif_mib_set_request(priv, attr, MIB_VALUE_TYPE_OSTRING, data, size);
1245 }
1246
1247 static
1248 void hostif_start_request(struct ks_wlan_private *priv, unsigned char mode)
1249 {
1250 struct hostif_start_request *pp;
1251
1252 pp = hostif_generic_request(sizeof(*pp), HIF_START_REQ);
1253 if (!pp)
1254 return;
1255
1256 pp->mode = cpu_to_le16((u16)mode);
1257
1258 send_request_to_device(priv, pp, hif_align_size(sizeof(*pp)));
1259
1260 priv->aplist.size = 0;
1261 priv->scan_ind_count = 0;
1262 }
1263
1264 static __le16 ks_wlan_cap(struct ks_wlan_private *priv)
1265 {
1266 u16 capability = 0x0000;
1267
1268 if (priv->reg.preamble == SHORT_PREAMBLE)
1269 capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
1270
1271 capability &= ~(WLAN_CAPABILITY_PBCC); /* pbcc not support */
1272
1273 if (priv->reg.phy_type != D_11B_ONLY_MODE) {
1274 capability |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
1275 capability &= ~(WLAN_CAPABILITY_DSSS_OFDM);
1276 }
1277
1278 return cpu_to_le16(capability);
1279 }
1280
1281 static void init_request(struct ks_wlan_private *priv,
1282 struct hostif_request *req)
1283 {
1284 req->phy_type = cpu_to_le16((u16)(priv->reg.phy_type));
1285 req->cts_mode = cpu_to_le16((u16)(priv->reg.cts_mode));
1286 req->scan_type = cpu_to_le16((u16)(priv->reg.scan_type));
1287 req->rate_set.size = priv->reg.rate_set.size;
1288 req->capability = ks_wlan_cap(priv);
1289 memcpy(&req->rate_set.body[0], &priv->reg.rate_set.body[0],
1290 priv->reg.rate_set.size);
1291 }
1292
1293 static
1294 void hostif_ps_adhoc_set_request(struct ks_wlan_private *priv)
1295 {
1296 struct hostif_ps_adhoc_set_request *pp;
1297
1298 pp = hostif_generic_request(sizeof(*pp), HIF_PS_ADH_SET_REQ);
1299 if (!pp)
1300 return;
1301
1302 init_request(priv, &pp->request);
1303 pp->channel = cpu_to_le16((u16)(priv->reg.channel));
1304
1305 send_request_to_device(priv, pp, hif_align_size(sizeof(*pp)));
1306 }
1307
1308 static
1309 void hostif_infrastructure_set_request(struct ks_wlan_private *priv, int event)
1310 {
1311 struct hostif_infrastructure_set_request *pp;
1312
1313 pp = hostif_generic_request(sizeof(*pp), event);
1314 if (!pp)
1315 return;
1316
1317 init_request(priv, &pp->request);
1318 pp->ssid.size = priv->reg.ssid.size;
1319 memcpy(&pp->ssid.body[0], &priv->reg.ssid.body[0], priv->reg.ssid.size);
1320 pp->beacon_lost_count =
1321 cpu_to_le16((u16)(priv->reg.beacon_lost_count));
1322 pp->auth_type = cpu_to_le16((u16)(priv->reg.authenticate_type));
1323
1324 pp->channel_list.body[0] = 1;
1325 pp->channel_list.body[1] = 8;
1326 pp->channel_list.body[2] = 2;
1327 pp->channel_list.body[3] = 9;
1328 pp->channel_list.body[4] = 3;
1329 pp->channel_list.body[5] = 10;
1330 pp->channel_list.body[6] = 4;
1331 pp->channel_list.body[7] = 11;
1332 pp->channel_list.body[8] = 5;
1333 pp->channel_list.body[9] = 12;
1334 pp->channel_list.body[10] = 6;
1335 pp->channel_list.body[11] = 13;
1336 pp->channel_list.body[12] = 7;
1337 if (priv->reg.phy_type == D_11G_ONLY_MODE) {
1338 pp->channel_list.size = 13;
1339 } else {
1340 pp->channel_list.body[13] = 14;
1341 pp->channel_list.size = 14;
1342 }
1343
1344 send_request_to_device(priv, pp, hif_align_size(sizeof(*pp)));
1345 }
1346
1347 static
1348 void hostif_adhoc_set_request(struct ks_wlan_private *priv)
1349 {
1350 struct hostif_adhoc_set_request *pp;
1351
1352 pp = hostif_generic_request(sizeof(*pp), HIF_ADH_SET_REQ);
1353 if (!pp)
1354 return;
1355
1356 init_request(priv, &pp->request);
1357 pp->channel = cpu_to_le16((u16)(priv->reg.channel));
1358 pp->ssid.size = priv->reg.ssid.size;
1359 memcpy(&pp->ssid.body[0], &priv->reg.ssid.body[0], priv->reg.ssid.size);
1360
1361 send_request_to_device(priv, pp, hif_align_size(sizeof(*pp)));
1362 }
1363
1364 static
1365 void hostif_adhoc_set2_request(struct ks_wlan_private *priv)
1366 {
1367 struct hostif_adhoc_set2_request *pp;
1368
1369 pp = hostif_generic_request(sizeof(*pp), HIF_ADH_SET_REQ);
1370 if (!pp)
1371 return;
1372
1373 init_request(priv, &pp->request);
1374 pp->ssid.size = priv->reg.ssid.size;
1375 memcpy(&pp->ssid.body[0], &priv->reg.ssid.body[0], priv->reg.ssid.size);
1376
1377 pp->channel_list.body[0] = priv->reg.channel;
1378 pp->channel_list.size = 1;
1379 memcpy(pp->bssid, priv->reg.bssid, ETH_ALEN);
1380
1381 send_request_to_device(priv, pp, hif_align_size(sizeof(*pp)));
1382 }
1383
1384 static
1385 void hostif_stop_request(struct ks_wlan_private *priv)
1386 {
1387 struct hostif_stop_request *pp;
1388
1389 pp = hostif_generic_request(sizeof(*pp), HIF_STOP_REQ);
1390 if (!pp)
1391 return;
1392
1393 send_request_to_device(priv, pp, hif_align_size(sizeof(*pp)));
1394 }
1395
1396 static
1397 void hostif_phy_information_request(struct ks_wlan_private *priv)
1398 {
1399 struct hostif_phy_information_request *pp;
1400
1401 pp = hostif_generic_request(sizeof(*pp), HIF_PHY_INFO_REQ);
1402 if (!pp)
1403 return;
1404
1405 if (priv->reg.phy_info_timer) {
1406 pp->type = cpu_to_le16((u16)TIME_TYPE);
1407 pp->time = cpu_to_le16((u16)(priv->reg.phy_info_timer));
1408 } else {
1409 pp->type = cpu_to_le16((u16)NORMAL_TYPE);
1410 pp->time = cpu_to_le16((u16)0);
1411 }
1412
1413 send_request_to_device(priv, pp, hif_align_size(sizeof(*pp)));
1414 }
1415
1416 static
1417 void hostif_power_mgmt_request(struct ks_wlan_private *priv,
1418 u32 mode, u32 wake_up, u32 receive_dtims)
1419 {
1420 struct hostif_power_mgmt_request *pp;
1421
1422 pp = hostif_generic_request(sizeof(*pp), HIF_POWER_MGMT_REQ);
1423 if (!pp)
1424 return;
1425
1426 pp->mode = cpu_to_le32(mode);
1427 pp->wake_up = cpu_to_le32(wake_up);
1428 pp->receive_dtims = cpu_to_le32(receive_dtims);
1429
1430 send_request_to_device(priv, pp, hif_align_size(sizeof(*pp)));
1431 }
1432
1433 static
1434 void hostif_sleep_request(struct ks_wlan_private *priv,
1435 enum sleep_mode_type mode)
1436 {
1437 struct hostif_sleep_request *pp;
1438
1439 if (mode == SLP_SLEEP) {
1440 pp = hostif_generic_request(sizeof(*pp), HIF_SLEEP_REQ);
1441 if (!pp)
1442 return;
1443
1444 send_request_to_device(priv, pp, hif_align_size(sizeof(*pp)));
1445 } else if (mode == SLP_ACTIVE) {
1446 atomic_set(&priv->sleepstatus.wakeup_request, 1);
1447 queue_delayed_work(priv->wq, &priv->rw_dwork, 1);
1448 } else {
1449 netdev_err(priv->net_dev, "invalid mode %ld\n", (long)mode);
1450 return;
1451 }
1452 }
1453
1454 static
1455 void hostif_bss_scan_request(struct ks_wlan_private *priv,
1456 unsigned long scan_type, u8 *scan_ssid,
1457 u8 scan_ssid_len)
1458 {
1459 struct hostif_bss_scan_request *pp;
1460
1461 pp = hostif_generic_request(sizeof(*pp), HIF_SCAN_REQ);
1462 if (!pp)
1463 return;
1464
1465 pp->scan_type = scan_type;
1466
1467 pp->ch_time_min = cpu_to_le32((u32)110); /* default value */
1468 pp->ch_time_max = cpu_to_le32((u32)130); /* default value */
1469 pp->channel_list.body[0] = 1;
1470 pp->channel_list.body[1] = 8;
1471 pp->channel_list.body[2] = 2;
1472 pp->channel_list.body[3] = 9;
1473 pp->channel_list.body[4] = 3;
1474 pp->channel_list.body[5] = 10;
1475 pp->channel_list.body[6] = 4;
1476 pp->channel_list.body[7] = 11;
1477 pp->channel_list.body[8] = 5;
1478 pp->channel_list.body[9] = 12;
1479 pp->channel_list.body[10] = 6;
1480 pp->channel_list.body[11] = 13;
1481 pp->channel_list.body[12] = 7;
1482 if (priv->reg.phy_type == D_11G_ONLY_MODE) {
1483 pp->channel_list.size = 13;
1484 } else {
1485 pp->channel_list.body[13] = 14;
1486 pp->channel_list.size = 14;
1487 }
1488 pp->ssid.size = 0;
1489
1490 /* specified SSID SCAN */
1491 if (scan_ssid_len > 0 && scan_ssid_len <= 32) {
1492 pp->ssid.size = scan_ssid_len;
1493 memcpy(&pp->ssid.body[0], scan_ssid, scan_ssid_len);
1494 }
1495
1496 send_request_to_device(priv, pp, hif_align_size(sizeof(*pp)));
1497
1498 priv->aplist.size = 0;
1499 priv->scan_ind_count = 0;
1500 }
1501
1502 static
1503 void hostif_mic_failure_request(struct ks_wlan_private *priv,
1504 u16 failure_count, u16 timer)
1505 {
1506 struct hostif_mic_failure_request *pp;
1507
1508 pp = hostif_generic_request(sizeof(*pp), HIF_MIC_FAILURE_REQ);
1509 if (!pp)
1510 return;
1511
1512 pp->failure_count = cpu_to_le16(failure_count);
1513 pp->timer = cpu_to_le16(timer);
1514
1515 send_request_to_device(priv, pp, hif_align_size(sizeof(*pp)));
1516 }
1517
1518 /* Device I/O Receive indicate */
1519 static void devio_rec_ind(struct ks_wlan_private *priv, unsigned char *p,
1520 unsigned int size)
1521 {
1522 if (!priv->is_device_open)
1523 return;
1524
1525 spin_lock(&priv->dev_read_lock);
1526 priv->dev_data[atomic_read(&priv->rec_count)] = p;
1527 priv->dev_size[atomic_read(&priv->rec_count)] = size;
1528
1529 if (atomic_read(&priv->event_count) != DEVICE_STOCK_COUNT) {
1530 /* rx event count inc */
1531 atomic_inc(&priv->event_count);
1532 }
1533 atomic_inc(&priv->rec_count);
1534 if (atomic_read(&priv->rec_count) == DEVICE_STOCK_COUNT)
1535 atomic_set(&priv->rec_count, 0);
1536
1537 wake_up_interruptible_all(&priv->devread_wait);
1538
1539 spin_unlock(&priv->dev_read_lock);
1540 }
1541
1542 void hostif_receive(struct ks_wlan_private *priv, unsigned char *p,
1543 unsigned int size)
1544 {
1545 devio_rec_ind(priv, p, size);
1546
1547 priv->rxp = p;
1548 priv->rx_size = size;
1549
1550 if (get_word(priv) == priv->rx_size)
1551 hostif_event_check(priv);
1552 }
1553
1554 static void hostif_sme_set_wep(struct ks_wlan_private *priv, int type)
1555 {
1556 switch (type) {
1557 case SME_WEP_INDEX_REQUEST:
1558 hostif_mib_set_request_int(priv, DOT11_WEP_DEFAULT_KEY_ID,
1559 priv->reg.wep_index);
1560 break;
1561 case SME_WEP_KEY1_REQUEST:
1562 if (priv->wpa.wpa_enabled)
1563 return;
1564 hostif_mib_set_request_ostring(priv,
1565 DOT11_WEP_DEFAULT_KEY_VALUE1,
1566 &priv->reg.wep_key[0].val[0],
1567 priv->reg.wep_key[0].size);
1568 break;
1569 case SME_WEP_KEY2_REQUEST:
1570 if (priv->wpa.wpa_enabled)
1571 return;
1572 hostif_mib_set_request_ostring(priv,
1573 DOT11_WEP_DEFAULT_KEY_VALUE2,
1574 &priv->reg.wep_key[1].val[0],
1575 priv->reg.wep_key[1].size);
1576 break;
1577 case SME_WEP_KEY3_REQUEST:
1578 if (priv->wpa.wpa_enabled)
1579 return;
1580 hostif_mib_set_request_ostring(priv,
1581 DOT11_WEP_DEFAULT_KEY_VALUE3,
1582 &priv->reg.wep_key[2].val[0],
1583 priv->reg.wep_key[2].size);
1584 break;
1585 case SME_WEP_KEY4_REQUEST:
1586 if (priv->wpa.wpa_enabled)
1587 return;
1588 hostif_mib_set_request_ostring(priv,
1589 DOT11_WEP_DEFAULT_KEY_VALUE4,
1590 &priv->reg.wep_key[3].val[0],
1591 priv->reg.wep_key[3].size);
1592 break;
1593 case SME_WEP_FLAG_REQUEST:
1594 hostif_mib_set_request_bool(priv, DOT11_PRIVACY_INVOKED,
1595 priv->reg.privacy_invoked);
1596 break;
1597 }
1598 }
1599
1600 struct wpa_suite {
1601 __le16 size;
1602 unsigned char suite[4][CIPHER_ID_LEN];
1603 } __packed;
1604
1605 struct rsn_mode {
1606 __le32 rsn_mode;
1607 __le16 rsn_capability;
1608 } __packed;
1609
1610 static void hostif_sme_set_rsn(struct ks_wlan_private *priv, int type)
1611 {
1612 struct wpa_suite wpa_suite;
1613 struct rsn_mode rsn_mode;
1614 size_t size;
1615 u32 mode;
1616 const u8 *buf = NULL;
1617
1618 memset(&wpa_suite, 0, sizeof(wpa_suite));
1619
1620 switch (type) {
1621 case SME_RSN_UCAST_REQUEST:
1622 wpa_suite.size = cpu_to_le16((uint16_t)1);
1623 switch (priv->wpa.pairwise_suite) {
1624 case IW_AUTH_CIPHER_NONE:
1625 buf = (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) ?
1626 CIPHER_ID_WPA2_NONE : CIPHER_ID_WPA_NONE;
1627 break;
1628 case IW_AUTH_CIPHER_WEP40:
1629 buf = (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) ?
1630 CIPHER_ID_WPA2_WEP40 : CIPHER_ID_WPA_WEP40;
1631 break;
1632 case IW_AUTH_CIPHER_TKIP:
1633 buf = (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) ?
1634 CIPHER_ID_WPA2_TKIP : CIPHER_ID_WPA_TKIP;
1635 break;
1636 case IW_AUTH_CIPHER_CCMP:
1637 buf = (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) ?
1638 CIPHER_ID_WPA2_CCMP : CIPHER_ID_WPA_CCMP;
1639 break;
1640 case IW_AUTH_CIPHER_WEP104:
1641 buf = (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) ?
1642 CIPHER_ID_WPA2_WEP104 : CIPHER_ID_WPA_WEP104;
1643 break;
1644 }
1645
1646 if (buf)
1647 memcpy(&wpa_suite.suite[0][0], buf, CIPHER_ID_LEN);
1648 size = sizeof(wpa_suite.size) +
1649 (CIPHER_ID_LEN * le16_to_cpu(wpa_suite.size));
1650 hostif_mib_set_request_ostring(priv,
1651 DOT11_RSN_CONFIG_UNICAST_CIPHER,
1652 &wpa_suite, size);
1653 break;
1654 case SME_RSN_MCAST_REQUEST:
1655 switch (priv->wpa.group_suite) {
1656 case IW_AUTH_CIPHER_NONE:
1657 buf = (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) ?
1658 CIPHER_ID_WPA2_NONE : CIPHER_ID_WPA_NONE;
1659 break;
1660 case IW_AUTH_CIPHER_WEP40:
1661 buf = (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) ?
1662 CIPHER_ID_WPA2_WEP40 : CIPHER_ID_WPA_WEP40;
1663 break;
1664 case IW_AUTH_CIPHER_TKIP:
1665 buf = (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) ?
1666 CIPHER_ID_WPA2_TKIP : CIPHER_ID_WPA_TKIP;
1667 break;
1668 case IW_AUTH_CIPHER_CCMP:
1669 buf = (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) ?
1670 CIPHER_ID_WPA2_CCMP : CIPHER_ID_WPA_CCMP;
1671 break;
1672 case IW_AUTH_CIPHER_WEP104:
1673 buf = (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) ?
1674 CIPHER_ID_WPA2_WEP104 : CIPHER_ID_WPA_WEP104;
1675 break;
1676 }
1677 if (buf)
1678 memcpy(&wpa_suite.suite[0][0], buf, CIPHER_ID_LEN);
1679 hostif_mib_set_request_ostring(priv,
1680 DOT11_RSN_CONFIG_MULTICAST_CIPHER,
1681 &wpa_suite.suite[0][0],
1682 CIPHER_ID_LEN);
1683 break;
1684 case SME_RSN_AUTH_REQUEST:
1685 wpa_suite.size = cpu_to_le16((uint16_t)1);
1686 switch (priv->wpa.key_mgmt_suite) {
1687 case IW_AUTH_KEY_MGMT_802_1X:
1688 buf = (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) ?
1689 KEY_MGMT_ID_WPA2_1X : KEY_MGMT_ID_WPA_1X;
1690 break;
1691 case IW_AUTH_KEY_MGMT_PSK:
1692 buf = (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) ?
1693 KEY_MGMT_ID_WPA2_PSK : KEY_MGMT_ID_WPA_PSK;
1694 break;
1695 case 0:
1696 buf = (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) ?
1697 KEY_MGMT_ID_WPA2_NONE : KEY_MGMT_ID_WPA_NONE;
1698 break;
1699 case 4:
1700 buf = (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) ?
1701 KEY_MGMT_ID_WPA2_WPANONE :
1702 KEY_MGMT_ID_WPA_WPANONE;
1703 break;
1704 }
1705
1706 if (buf)
1707 memcpy(&wpa_suite.suite[0][0], buf, KEY_MGMT_ID_LEN);
1708 size = sizeof(wpa_suite.size) +
1709 (KEY_MGMT_ID_LEN * le16_to_cpu(wpa_suite.size));
1710 hostif_mib_set_request_ostring(priv,
1711 DOT11_RSN_CONFIG_AUTH_SUITE,
1712 &wpa_suite, size);
1713 break;
1714 case SME_RSN_ENABLED_REQUEST:
1715 hostif_mib_set_request_bool(priv, DOT11_RSN_ENABLED,
1716 priv->wpa.rsn_enabled);
1717 break;
1718 case SME_RSN_MODE_REQUEST:
1719 mode = (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) ?
1720 RSN_MODE_WPA2 :
1721 (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA) ?
1722 RSN_MODE_WPA : RSN_MODE_NONE;
1723 rsn_mode.rsn_mode = cpu_to_le32(mode);
1724 rsn_mode.rsn_capability = cpu_to_le16((uint16_t)0);
1725 hostif_mib_set_request_ostring(priv, LOCAL_RSN_MODE,
1726 &rsn_mode, sizeof(rsn_mode));
1727 break;
1728 }
1729 }
1730
1731 static
1732 void hostif_sme_mode_setup(struct ks_wlan_private *priv)
1733 {
1734 unsigned char rate_size;
1735 unsigned char rate_octet[RATE_SET_MAX_SIZE];
1736 int i = 0;
1737
1738 /* rate setting if rate segging is auto for changing phy_type (#94) */
1739 if (priv->reg.tx_rate == TX_RATE_FULL_AUTO) {
1740 if (priv->reg.phy_type == D_11B_ONLY_MODE) {
1741 priv->reg.rate_set.body[3] = TX_RATE_11M;
1742 priv->reg.rate_set.body[2] = TX_RATE_5M;
1743 priv->reg.rate_set.body[1] = TX_RATE_2M | BASIC_RATE;
1744 priv->reg.rate_set.body[0] = TX_RATE_1M | BASIC_RATE;
1745 priv->reg.rate_set.size = 4;
1746 } else { /* D_11G_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
1747 priv->reg.rate_set.body[11] = TX_RATE_54M;
1748 priv->reg.rate_set.body[10] = TX_RATE_48M;
1749 priv->reg.rate_set.body[9] = TX_RATE_36M;
1750 priv->reg.rate_set.body[8] = TX_RATE_18M;
1751 priv->reg.rate_set.body[7] = TX_RATE_9M;
1752 priv->reg.rate_set.body[6] = TX_RATE_24M | BASIC_RATE;
1753 priv->reg.rate_set.body[5] = TX_RATE_12M | BASIC_RATE;
1754 priv->reg.rate_set.body[4] = TX_RATE_6M | BASIC_RATE;
1755 priv->reg.rate_set.body[3] = TX_RATE_11M | BASIC_RATE;
1756 priv->reg.rate_set.body[2] = TX_RATE_5M | BASIC_RATE;
1757 priv->reg.rate_set.body[1] = TX_RATE_2M | BASIC_RATE;
1758 priv->reg.rate_set.body[0] = TX_RATE_1M | BASIC_RATE;
1759 priv->reg.rate_set.size = 12;
1760 }
1761 }
1762
1763 /* rate mask by phy setting */
1764 if (priv->reg.phy_type == D_11B_ONLY_MODE) {
1765 for (i = 0; i < priv->reg.rate_set.size; i++) {
1766 if (!is_11b_rate(priv->reg.rate_set.body[i]))
1767 break;
1768
1769 if ((priv->reg.rate_set.body[i] & RATE_MASK) >= TX_RATE_5M) {
1770 rate_octet[i] = priv->reg.rate_set.body[i] &
1771 RATE_MASK;
1772 } else {
1773 rate_octet[i] = priv->reg.rate_set.body[i];
1774 }
1775 }
1776
1777 } else { /* D_11G_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
1778 for (i = 0; i < priv->reg.rate_set.size; i++) {
1779 if (!is_11bg_rate(priv->reg.rate_set.body[i]))
1780 break;
1781
1782 if (is_ofdm_ext_rate(priv->reg.rate_set.body[i])) {
1783 rate_octet[i] = priv->reg.rate_set.body[i] &
1784 RATE_MASK;
1785 } else {
1786 rate_octet[i] = priv->reg.rate_set.body[i];
1787 }
1788 }
1789 }
1790 rate_size = i;
1791 if (rate_size == 0) {
1792 if (priv->reg.phy_type == D_11G_ONLY_MODE)
1793 rate_octet[0] = TX_RATE_6M | BASIC_RATE;
1794 else
1795 rate_octet[0] = TX_RATE_2M | BASIC_RATE;
1796 rate_size = 1;
1797 }
1798
1799 /* rate set update */
1800 priv->reg.rate_set.size = rate_size;
1801 memcpy(&priv->reg.rate_set.body[0], &rate_octet[0], rate_size);
1802
1803 switch (priv->reg.operation_mode) {
1804 case MODE_PSEUDO_ADHOC:
1805 hostif_ps_adhoc_set_request(priv);
1806 break;
1807 case MODE_INFRASTRUCTURE:
1808 if (!is_valid_ether_addr((u8 *)priv->reg.bssid)) {
1809 hostif_infrastructure_set_request(priv,
1810 HIF_INFRA_SET_REQ);
1811 } else {
1812 hostif_infrastructure_set_request(priv,
1813 HIF_INFRA_SET2_REQ);
1814 netdev_dbg(priv->net_dev,
1815 "Infra bssid = %pM\n", priv->reg.bssid);
1816 }
1817 break;
1818 case MODE_ADHOC:
1819 if (!is_valid_ether_addr((u8 *)priv->reg.bssid)) {
1820 hostif_adhoc_set_request(priv);
1821 } else {
1822 hostif_adhoc_set2_request(priv);
1823 netdev_dbg(priv->net_dev,
1824 "Adhoc bssid = %pM\n", priv->reg.bssid);
1825 }
1826 break;
1827 default:
1828 break;
1829 }
1830 }
1831
1832 static
1833 void hostif_sme_multicast_set(struct ks_wlan_private *priv)
1834 {
1835 struct net_device *dev = priv->net_dev;
1836 int mc_count;
1837 struct netdev_hw_addr *ha;
1838 char set_address[NIC_MAX_MCAST_LIST * ETH_ALEN];
1839 int i = 0;
1840
1841 spin_lock(&priv->multicast_spin);
1842
1843 memset(set_address, 0, NIC_MAX_MCAST_LIST * ETH_ALEN);
1844
1845 if (dev->flags & IFF_PROMISC) {
1846 hostif_mib_set_request_bool(priv, LOCAL_MULTICAST_FILTER,
1847 MCAST_FILTER_PROMISC);
1848 goto spin_unlock;
1849 }
1850
1851 if ((netdev_mc_count(dev) > NIC_MAX_MCAST_LIST) ||
1852 (dev->flags & IFF_ALLMULTI)) {
1853 hostif_mib_set_request_bool(priv, LOCAL_MULTICAST_FILTER,
1854 MCAST_FILTER_MCASTALL);
1855 goto spin_unlock;
1856 }
1857
1858 if (priv->sme_i.sme_flag & SME_MULTICAST) {
1859 mc_count = netdev_mc_count(dev);
1860 netdev_for_each_mc_addr(ha, dev) {
1861 ether_addr_copy(&set_address[i * ETH_ALEN], ha->addr);
1862 i++;
1863 }
1864 priv->sme_i.sme_flag &= ~SME_MULTICAST;
1865 hostif_mib_set_request_ostring(priv, LOCAL_MULTICAST_ADDRESS,
1866 &set_address[0],
1867 ETH_ALEN * mc_count);
1868 } else {
1869 priv->sme_i.sme_flag |= SME_MULTICAST;
1870 hostif_mib_set_request_bool(priv, LOCAL_MULTICAST_FILTER,
1871 MCAST_FILTER_MCAST);
1872 }
1873
1874 spin_unlock:
1875 spin_unlock(&priv->multicast_spin);
1876 }
1877
1878 static void hostif_sme_power_mgmt_set(struct ks_wlan_private *priv)
1879 {
1880 u32 mode, wake_up, receive_dtims;
1881
1882 if (priv->reg.power_mgmt != POWER_MGMT_SAVE1 &&
1883 priv->reg.power_mgmt != POWER_MGMT_SAVE2) {
1884 mode = POWER_ACTIVE;
1885 wake_up = 0;
1886 receive_dtims = 0;
1887 } else {
1888 mode = (priv->reg.operation_mode == MODE_INFRASTRUCTURE) ?
1889 POWER_SAVE : POWER_ACTIVE;
1890 wake_up = 0;
1891 receive_dtims = (priv->reg.operation_mode == MODE_INFRASTRUCTURE &&
1892 priv->reg.power_mgmt == POWER_MGMT_SAVE2);
1893 }
1894
1895 hostif_power_mgmt_request(priv, mode, wake_up, receive_dtims);
1896 }
1897
1898 static void hostif_sme_sleep_set(struct ks_wlan_private *priv)
1899 {
1900 if (priv->sleep_mode != SLP_SLEEP &&
1901 priv->sleep_mode != SLP_ACTIVE)
1902 return;
1903
1904 hostif_sleep_request(priv, priv->sleep_mode);
1905 }
1906
1907 static
1908 void hostif_sme_set_key(struct ks_wlan_private *priv, int type)
1909 {
1910 switch (type) {
1911 case SME_SET_FLAG:
1912 hostif_mib_set_request_bool(priv, DOT11_PRIVACY_INVOKED,
1913 priv->reg.privacy_invoked);
1914 break;
1915 case SME_SET_TXKEY:
1916 hostif_mib_set_request_int(priv, DOT11_WEP_DEFAULT_KEY_ID,
1917 priv->wpa.txkey);
1918 break;
1919 case SME_SET_KEY1:
1920 hostif_mib_set_request_ostring(priv,
1921 DOT11_WEP_DEFAULT_KEY_VALUE1,
1922 &priv->wpa.key[0].key_val[0],
1923 priv->wpa.key[0].key_len);
1924 break;
1925 case SME_SET_KEY2:
1926 hostif_mib_set_request_ostring(priv,
1927 DOT11_WEP_DEFAULT_KEY_VALUE2,
1928 &priv->wpa.key[1].key_val[0],
1929 priv->wpa.key[1].key_len);
1930 break;
1931 case SME_SET_KEY3:
1932 hostif_mib_set_request_ostring(priv,
1933 DOT11_WEP_DEFAULT_KEY_VALUE3,
1934 &priv->wpa.key[2].key_val[0],
1935 priv->wpa.key[2].key_len);
1936 break;
1937 case SME_SET_KEY4:
1938 hostif_mib_set_request_ostring(priv,
1939 DOT11_WEP_DEFAULT_KEY_VALUE4,
1940 &priv->wpa.key[3].key_val[0],
1941 priv->wpa.key[3].key_len);
1942 break;
1943 case SME_SET_PMK_TSC:
1944 hostif_mib_set_request_ostring(priv, DOT11_PMK_TSC,
1945 &priv->wpa.key[0].rx_seq[0],
1946 WPA_RX_SEQ_LEN);
1947 break;
1948 case SME_SET_GMK1_TSC:
1949 hostif_mib_set_request_ostring(priv, DOT11_GMK1_TSC,
1950 &priv->wpa.key[1].rx_seq[0],
1951 WPA_RX_SEQ_LEN);
1952 break;
1953 case SME_SET_GMK2_TSC:
1954 hostif_mib_set_request_ostring(priv, DOT11_GMK2_TSC,
1955 &priv->wpa.key[2].rx_seq[0],
1956 WPA_RX_SEQ_LEN);
1957 break;
1958 }
1959 }
1960
1961 static
1962 void hostif_sme_set_pmksa(struct ks_wlan_private *priv)
1963 {
1964 struct pmk_cache {
1965 __le16 size;
1966 struct {
1967 u8 bssid[ETH_ALEN];
1968 u8 pmkid[IW_PMKID_LEN];
1969 } __packed list[PMK_LIST_MAX];
1970 } __packed pmkcache;
1971 struct pmk *pmk;
1972 size_t size;
1973 int i = 0;
1974
1975 list_for_each_entry(pmk, &priv->pmklist.head, list) {
1976 if (i >= PMK_LIST_MAX)
1977 break;
1978 ether_addr_copy(pmkcache.list[i].bssid, pmk->bssid);
1979 memcpy(pmkcache.list[i].pmkid, pmk->pmkid, IW_PMKID_LEN);
1980 i++;
1981 }
1982 pmkcache.size = cpu_to_le16((uint16_t)(priv->pmklist.size));
1983 size = sizeof(priv->pmklist.size) +
1984 ((ETH_ALEN + IW_PMKID_LEN) * priv->pmklist.size);
1985 hostif_mib_set_request_ostring(priv, LOCAL_PMK, &pmkcache, size);
1986 }
1987
1988 /* execute sme */
1989 static void hostif_sme_execute(struct ks_wlan_private *priv, int event)
1990 {
1991 u16 failure;
1992
1993 switch (event) {
1994 case SME_START:
1995 if (priv->dev_state == DEVICE_STATE_BOOT)
1996 hostif_mib_get_request(priv, DOT11_MAC_ADDRESS);
1997 break;
1998 case SME_MULTICAST_REQUEST:
1999 hostif_sme_multicast_set(priv);
2000 break;
2001 case SME_MACADDRESS_SET_REQUEST:
2002 hostif_mib_set_request_ostring(priv, LOCAL_CURRENTADDRESS,
2003 &priv->eth_addr[0], ETH_ALEN);
2004 break;
2005 case SME_BSS_SCAN_REQUEST:
2006 hostif_bss_scan_request(priv, priv->reg.scan_type,
2007 priv->scan_ssid, priv->scan_ssid_len);
2008 break;
2009 case SME_POW_MNGMT_REQUEST:
2010 hostif_sme_power_mgmt_set(priv);
2011 break;
2012 case SME_PHY_INFO_REQUEST:
2013 hostif_phy_information_request(priv);
2014 break;
2015 case SME_MIC_FAILURE_REQUEST:
2016 failure = priv->wpa.mic_failure.failure;
2017 if (failure != 1 && failure != 2) {
2018 netdev_err(priv->net_dev,
2019 "SME_MIC_FAILURE_REQUEST: failure count=%u error?\n",
2020 failure);
2021 return;
2022 }
2023 hostif_mic_failure_request(priv, failure - 1, (failure == 1) ?
2024 0 : priv->wpa.mic_failure.counter);
2025 break;
2026 case SME_MIC_FAILURE_CONFIRM:
2027 if (priv->wpa.mic_failure.failure == 2) {
2028 if (priv->wpa.mic_failure.stop)
2029 priv->wpa.mic_failure.stop = 0;
2030 priv->wpa.mic_failure.failure = 0;
2031 hostif_start_request(priv, priv->reg.operation_mode);
2032 }
2033 break;
2034 case SME_GET_MAC_ADDRESS:
2035 if (priv->dev_state == DEVICE_STATE_BOOT)
2036 hostif_mib_get_request(priv, DOT11_PRODUCT_VERSION);
2037 break;
2038 case SME_GET_PRODUCT_VERSION:
2039 if (priv->dev_state == DEVICE_STATE_BOOT)
2040 priv->dev_state = DEVICE_STATE_PREINIT;
2041 break;
2042 case SME_STOP_REQUEST:
2043 hostif_stop_request(priv);
2044 break;
2045 case SME_RTS_THRESHOLD_REQUEST:
2046 hostif_mib_set_request_int(priv, DOT11_RTS_THRESHOLD,
2047 priv->reg.rts);
2048 break;
2049 case SME_FRAGMENTATION_THRESHOLD_REQUEST:
2050 hostif_mib_set_request_int(priv, DOT11_FRAGMENTATION_THRESHOLD,
2051 priv->reg.fragment);
2052 break;
2053 case SME_WEP_INDEX_REQUEST:
2054 case SME_WEP_KEY1_REQUEST:
2055 case SME_WEP_KEY2_REQUEST:
2056 case SME_WEP_KEY3_REQUEST:
2057 case SME_WEP_KEY4_REQUEST:
2058 case SME_WEP_FLAG_REQUEST:
2059 hostif_sme_set_wep(priv, event);
2060 break;
2061 case SME_RSN_UCAST_REQUEST:
2062 case SME_RSN_MCAST_REQUEST:
2063 case SME_RSN_AUTH_REQUEST:
2064 case SME_RSN_ENABLED_REQUEST:
2065 case SME_RSN_MODE_REQUEST:
2066 hostif_sme_set_rsn(priv, event);
2067 break;
2068 case SME_SET_FLAG:
2069 case SME_SET_TXKEY:
2070 case SME_SET_KEY1:
2071 case SME_SET_KEY2:
2072 case SME_SET_KEY3:
2073 case SME_SET_KEY4:
2074 case SME_SET_PMK_TSC:
2075 case SME_SET_GMK1_TSC:
2076 case SME_SET_GMK2_TSC:
2077 hostif_sme_set_key(priv, event);
2078 break;
2079 case SME_SET_PMKSA:
2080 hostif_sme_set_pmksa(priv);
2081 break;
2082 case SME_WPS_ENABLE_REQUEST:
2083 hostif_mib_set_request_int(priv, LOCAL_WPS_ENABLE,
2084 priv->wps.wps_enabled);
2085 break;
2086 case SME_WPS_PROBE_REQUEST:
2087 hostif_mib_set_request_ostring(priv, LOCAL_WPS_PROBE_REQ,
2088 priv->wps.ie, priv->wps.ielen);
2089 break;
2090 case SME_MODE_SET_REQUEST:
2091 hostif_sme_mode_setup(priv);
2092 break;
2093 case SME_SET_GAIN:
2094 hostif_mib_set_request_ostring(priv, LOCAL_GAIN,
2095 &priv->gain, sizeof(priv->gain));
2096 break;
2097 case SME_GET_GAIN:
2098 hostif_mib_get_request(priv, LOCAL_GAIN);
2099 break;
2100 case SME_GET_EEPROM_CKSUM:
2101 priv->eeprom_checksum = EEPROM_FW_NOT_SUPPORT; /* initialize */
2102 hostif_mib_get_request(priv, LOCAL_EEPROM_SUM);
2103 break;
2104 case SME_START_REQUEST:
2105 hostif_start_request(priv, priv->reg.operation_mode);
2106 break;
2107 case SME_START_CONFIRM:
2108 /* for power save */
2109 atomic_set(&priv->psstatus.snooze_guard, 0);
2110 atomic_set(&priv->psstatus.confirm_wait, 0);
2111 if (priv->dev_state == DEVICE_STATE_PREINIT)
2112 priv->dev_state = DEVICE_STATE_INIT;
2113 /* wake_up_interruptible_all(&priv->confirm_wait); */
2114 complete(&priv->confirm_wait);
2115 break;
2116 case SME_SLEEP_REQUEST:
2117 hostif_sme_sleep_set(priv);
2118 break;
2119 case SME_SET_REGION:
2120 hostif_mib_set_request_int(priv, LOCAL_REGION, priv->region);
2121 break;
2122 case SME_MULTICAST_CONFIRM:
2123 case SME_BSS_SCAN_CONFIRM:
2124 case SME_POW_MNGMT_CONFIRM:
2125 case SME_PHY_INFO_CONFIRM:
2126 case SME_STOP_CONFIRM:
2127 case SME_RTS_THRESHOLD_CONFIRM:
2128 case SME_FRAGMENTATION_THRESHOLD_CONFIRM:
2129 case SME_WEP_INDEX_CONFIRM:
2130 case SME_WEP_KEY1_CONFIRM:
2131 case SME_WEP_KEY2_CONFIRM:
2132 case SME_WEP_KEY3_CONFIRM:
2133 case SME_WEP_KEY4_CONFIRM:
2134 case SME_WEP_FLAG_CONFIRM:
2135 case SME_RSN_UCAST_CONFIRM:
2136 case SME_RSN_MCAST_CONFIRM:
2137 case SME_RSN_AUTH_CONFIRM:
2138 case SME_RSN_ENABLED_CONFIRM:
2139 case SME_RSN_MODE_CONFIRM:
2140 case SME_MODE_SET_CONFIRM:
2141 case SME_TERMINATE:
2142 default:
2143 break;
2144 }
2145 }
2146
2147 static
2148 void hostif_sme_task(unsigned long dev)
2149 {
2150 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev;
2151
2152 if (priv->dev_state < DEVICE_STATE_BOOT)
2153 return;
2154
2155 if (cnt_smeqbody(priv) <= 0)
2156 return;
2157
2158 hostif_sme_execute(priv, priv->sme_i.event_buff[priv->sme_i.qhead]);
2159 inc_smeqhead(priv);
2160 if (cnt_smeqbody(priv) > 0)
2161 tasklet_schedule(&priv->sme_task);
2162 }
2163
2164 /* send to Station Management Entity module */
2165 void hostif_sme_enqueue(struct ks_wlan_private *priv, u16 event)
2166 {
2167 /* enqueue sme event */
2168 if (cnt_smeqbody(priv) < (SME_EVENT_BUFF_SIZE - 1)) {
2169 priv->sme_i.event_buff[priv->sme_i.qtail] = event;
2170 inc_smeqtail(priv);
2171 } else {
2172 /* in case of buffer overflow */
2173 netdev_err(priv->net_dev, "sme queue buffer overflow\n");
2174 }
2175
2176 tasklet_schedule(&priv->sme_task);
2177 }
2178
2179 static inline void hostif_aplist_init(struct ks_wlan_private *priv)
2180 {
2181 size_t size = LOCAL_APLIST_MAX * sizeof(struct local_ap);
2182
2183 priv->aplist.size = 0;
2184 memset(&priv->aplist.ap[0], 0, size);
2185 }
2186
2187 static inline void hostif_status_init(struct ks_wlan_private *priv)
2188 {
2189 priv->infra_status = 0;
2190 priv->current_rate = 4;
2191 priv->connect_status = DISCONNECT_STATUS;
2192 }
2193
2194 static inline void hostif_sme_init(struct ks_wlan_private *priv)
2195 {
2196 priv->sme_i.sme_status = SME_IDLE;
2197 priv->sme_i.qhead = 0;
2198 priv->sme_i.qtail = 0;
2199 spin_lock_init(&priv->sme_i.sme_spin);
2200 priv->sme_i.sme_flag = 0;
2201 tasklet_init(&priv->sme_task, hostif_sme_task, (unsigned long)priv);
2202 }
2203
2204 static inline void hostif_wpa_init(struct ks_wlan_private *priv)
2205 {
2206 memset(&priv->wpa, 0, sizeof(priv->wpa));
2207 priv->wpa.rsn_enabled = false;
2208 priv->wpa.mic_failure.failure = 0;
2209 priv->wpa.mic_failure.last_failure_time = 0;
2210 priv->wpa.mic_failure.stop = 0;
2211 }
2212
2213 static inline void hostif_power_save_init(struct ks_wlan_private *priv)
2214 {
2215 atomic_set(&priv->psstatus.status, PS_NONE);
2216 atomic_set(&priv->psstatus.confirm_wait, 0);
2217 atomic_set(&priv->psstatus.snooze_guard, 0);
2218 init_completion(&priv->psstatus.wakeup_wait);
2219 INIT_WORK(&priv->wakeup_work, ks_wlan_hw_wakeup_task);
2220 }
2221
2222 static inline void hostif_pmklist_init(struct ks_wlan_private *priv)
2223 {
2224 int i;
2225
2226 memset(&priv->pmklist, 0, sizeof(priv->pmklist));
2227 INIT_LIST_HEAD(&priv->pmklist.head);
2228 for (i = 0; i < PMK_LIST_MAX; i++)
2229 INIT_LIST_HEAD(&priv->pmklist.pmk[i].list);
2230 }
2231
2232 static inline void hostif_counters_init(struct ks_wlan_private *priv)
2233 {
2234 priv->dev_count = 0;
2235 atomic_set(&priv->event_count, 0);
2236 atomic_set(&priv->rec_count, 0);
2237 }
2238
2239 int hostif_init(struct ks_wlan_private *priv)
2240 {
2241 hostif_aplist_init(priv);
2242 hostif_status_init(priv);
2243
2244 spin_lock_init(&priv->multicast_spin);
2245 spin_lock_init(&priv->dev_read_lock);
2246 init_waitqueue_head(&priv->devread_wait);
2247
2248 hostif_counters_init(priv);
2249 hostif_power_save_init(priv);
2250 hostif_wpa_init(priv);
2251 hostif_pmklist_init(priv);
2252 hostif_sme_init(priv);
2253
2254 return 0;
2255 }
2256
2257 void hostif_exit(struct ks_wlan_private *priv)
2258 {
2259 tasklet_kill(&priv->sme_task);
2260 }