2 * Driver for KeyStream wireless LAN cards.
4 * Copyright (C) 2005-2008 KeyStream Corp.
5 * Copyright (C) 2009 Renesas Technology Corp.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
13 #include "ks_hostif.h"
14 #include "eap_packet.h"
15 #include "michael_mic.h"
17 #include <linux/etherdevice.h>
18 #include <linux/if_ether.h>
19 #include <linux/if_arp.h>
21 /* Include Wireless Extension definition and check version */
22 #include <net/iw_handler.h> /* New driver API */
25 #define inc_smeqhead(priv) \
26 (priv->sme_i.qhead = (priv->sme_i.qhead + 1) % SME_EVENT_BUFF_SIZE)
27 #define inc_smeqtail(priv) \
28 (priv->sme_i.qtail = (priv->sme_i.qtail + 1) % SME_EVENT_BUFF_SIZE)
29 #define cnt_smeqbody(priv) \
30 (((priv->sme_i.qtail + SME_EVENT_BUFF_SIZE) - (priv->sme_i.qhead)) % SME_EVENT_BUFF_SIZE)
32 #define KS_WLAN_MEM_FLAG (GFP_ATOMIC)
35 inline u8 get_BYTE(struct ks_wlan_private *priv)
39 data = *(priv->rxp)++;
40 /* length check in advance ! */
46 inline u16 get_WORD(struct ks_wlan_private *priv)
50 data = (get_BYTE(priv) & 0xff);
51 data |= ((get_BYTE(priv) << 8) & 0xff00);
56 inline u32 get_DWORD(struct ks_wlan_private *priv)
60 data = (get_BYTE(priv) & 0xff);
61 data |= ((get_BYTE(priv) << 8) & 0x0000ff00);
62 data |= ((get_BYTE(priv) << 16) & 0x00ff0000);
63 data |= ((get_BYTE(priv) << 24) & 0xff000000);
67 static void ks_wlan_hw_wakeup_task(struct work_struct *work)
69 struct ks_wlan_private *priv;
73 priv = container_of(work, struct ks_wlan_private, wakeup_work);
74 ps_status = atomic_read(&priv->psstatus.status);
76 if (ps_status == PS_SNOOZE) {
77 ks_wlan_hw_wakeup_request(priv);
78 time_left = wait_for_completion_interruptible_timeout(
79 &priv->psstatus.wakeup_wait,
80 msecs_to_jiffies(20));
82 DPRINTK(1, "wake up timeout or interrupted !!!\n");
83 schedule_work(&priv->wakeup_work);
87 DPRINTK(1, "ps_status=%d\n", ps_status);
91 if (atomic_read(&priv->sme_task.count) > 0) {
92 DPRINTK(4, "sme task enable.\n");
93 tasklet_enable(&priv->sme_task);
98 int ks_wlan_do_power_save(struct ks_wlan_private *priv)
100 DPRINTK(4, "psstatus.status=%d\n", atomic_read(&priv->psstatus.status));
102 if (is_connect_status(priv->connect_status))
103 hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
105 priv->dev_state = DEVICE_STATE_READY;
110 int get_current_ap(struct ks_wlan_private *priv, struct link_ap_info_t *ap_info)
112 struct local_ap_t *ap;
113 union iwreq_data wrqu;
114 struct net_device *netdev = priv->net_dev;
117 ap = &priv->current_ap;
119 if (is_disconnect_status(priv->connect_status)) {
120 memset(ap, 0, sizeof(struct local_ap_t));
125 memcpy(ap->bssid, ap_info->bssid, ETH_ALEN);
127 memcpy(ap->ssid.body, priv->reg.ssid.body,
128 priv->reg.ssid.size);
129 ap->ssid.size = priv->reg.ssid.size;
131 memcpy(ap->rate_set.body, ap_info->rate_set.body,
132 ap_info->rate_set.size);
133 ap->rate_set.size = ap_info->rate_set.size;
134 if (ap_info->ext_rate_set.size != 0) {
136 memcpy(&ap->rate_set.body[ap->rate_set.size],
137 ap_info->ext_rate_set.body,
138 ap_info->ext_rate_set.size);
139 ap->rate_set.size += ap_info->ext_rate_set.size;
142 ap->channel = ap_info->ds_parameter.channel;
144 ap->rssi = ap_info->rssi;
146 ap->sq = ap_info->sq;
148 ap->noise = ap_info->noise;
150 ap->capability = le16_to_cpu(ap_info->capability);
152 if ((ap_info->rsn_mode & RSN_MODE_WPA2) &&
153 (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)) {
154 ap->rsn_ie.id = 0x30;
155 if (ap_info->rsn.size <= RSN_IE_BODY_MAX) {
156 ap->rsn_ie.size = ap_info->rsn.size;
157 memcpy(ap->rsn_ie.body, ap_info->rsn.body,
160 ap->rsn_ie.size = RSN_IE_BODY_MAX;
161 memcpy(ap->rsn_ie.body, ap_info->rsn.body,
164 } else if ((ap_info->rsn_mode & RSN_MODE_WPA) &&
165 (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA)) {
166 ap->wpa_ie.id = 0xdd;
167 if (ap_info->rsn.size <= RSN_IE_BODY_MAX) {
168 ap->wpa_ie.size = ap_info->rsn.size;
169 memcpy(ap->wpa_ie.body, ap_info->rsn.body,
172 ap->wpa_ie.size = RSN_IE_BODY_MAX;
173 memcpy(ap->wpa_ie.body, ap_info->rsn.body,
183 wrqu.data.length = 0;
185 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
186 if (is_connect_status(priv->connect_status)) {
187 memcpy(wrqu.ap_addr.sa_data,
188 priv->current_ap.bssid, ETH_ALEN);
190 "IWEVENT: connect bssid=%pM\n", wrqu.ap_addr.sa_data);
191 wireless_send_event(netdev, SIOCGIWAP, &wrqu, NULL);
193 DPRINTK(4, "\n Link AP\n");
194 DPRINTK(4, " bssid=%02X:%02X:%02X:%02X:%02X:%02X\n"
196 " rate_set=%02X,%02X,%02X,%02X,%02X,%02X,%02X,%02X\n"
200 " capability=%04X\n",
201 ap->bssid[0], ap->bssid[1], ap->bssid[2],
202 ap->bssid[3], ap->bssid[4], ap->bssid[5],
204 ap->rate_set.body[0], ap->rate_set.body[1],
205 ap->rate_set.body[2], ap->rate_set.body[3],
206 ap->rate_set.body[4], ap->rate_set.body[5],
207 ap->rate_set.body[6], ap->rate_set.body[7],
208 ap->channel, ap->rssi, ap->sq, ap->capability);
209 DPRINTK(4, "\n Link AP\n rsn.mode=%d\n rsn.size=%d\n",
210 ap_info->rsn_mode, ap_info->rsn.size);
211 DPRINTK(4, "\n ext_rate_set_size=%d\n rate_set_size=%d\n",
212 ap_info->ext_rate_set.size, ap_info->rate_set.size);
218 int get_ap_information(struct ks_wlan_private *priv, struct ap_info_t *ap_info,
219 struct local_ap_t *ap)
225 memset(ap, 0, sizeof(struct local_ap_t));
228 memcpy(ap->bssid, ap_info->bssid, ETH_ALEN);
230 ap->rssi = ap_info->rssi;
232 ap->sq = ap_info->sq;
234 ap->noise = ap_info->noise;
236 ap->capability = le16_to_cpu(ap_info->capability);
238 ap->channel = ap_info->ch_info;
241 bsize = le16_to_cpu(ap_info->body_size);
244 while (bsize > offset) {
245 /* DPRINTK(4, "Element ID=%d\n",*bp); */
248 if (*(bp + 1) <= SSID_MAX_SIZE) {
249 ap->ssid.size = *(bp + 1);
251 DPRINTK(1, "size over :: ssid size=%d\n",
253 ap->ssid.size = SSID_MAX_SIZE;
255 memcpy(ap->ssid.body, bp + 2, ap->ssid.size);
258 case 50: /* ext rate */
259 if ((*(bp + 1) + ap->rate_set.size) <=
261 memcpy(&ap->rate_set.body[ap->rate_set.size],
263 ap->rate_set.size += *(bp + 1);
265 DPRINTK(1, "size over :: rate size=%d\n",
266 (*(bp + 1) + ap->rate_set.size));
267 memcpy(&ap->rate_set.body[ap->rate_set.size],
269 RATE_SET_MAX_SIZE - ap->rate_set.size);
271 (RATE_SET_MAX_SIZE - ap->rate_set.size);
274 case 3: /* DS parameter */
276 case 48: /* RSN(WPA2) */
278 if (*(bp + 1) <= RSN_IE_BODY_MAX) {
279 ap->rsn_ie.size = *(bp + 1);
281 DPRINTK(1, "size over :: rsn size=%d\n",
283 ap->rsn_ie.size = RSN_IE_BODY_MAX;
285 memcpy(ap->rsn_ie.body, bp + 2, ap->rsn_ie.size);
288 if (memcmp(bp + 2, "\x00\x50\xf2\x01", 4) == 0) { /* WPA OUI check */
290 if (*(bp + 1) <= RSN_IE_BODY_MAX) {
291 ap->wpa_ie.size = *(bp + 1);
294 "size over :: wpa size=%d\n",
296 ap->wpa_ie.size = RSN_IE_BODY_MAX;
298 memcpy(ap->wpa_ie.body, bp + 2,
303 case 2: /* FH parameter */
304 case 4: /* CF parameter */
306 case 6: /* IBSS parameter */
307 case 7: /* Country */
308 case 42: /* ERP information */
309 case 47: /* Reserve ID 47 Broadcom AP */
312 DPRINTK(4, "unknown Element ID=%d\n", *bp);
315 offset += 2; /* id & size field */
316 offset += *(bp + 1); /* +size offset */
317 bp += (*(bp + 1) + 2); /* pointer update */
324 int hostif_data_indication_wpa(struct ks_wlan_private *priv,
325 unsigned short auth_type)
327 struct ether_hdr *eth_hdr;
328 unsigned short eth_proto;
329 unsigned char recv_mic[8];
332 struct mic_failure_t *mic_failure;
333 struct michael_mic_t michael_mic;
334 union iwreq_data wrqu;
335 unsigned int key_index = auth_type - 1;
336 struct wpa_key_t *key = &priv->wpa.key[key_index];
338 eth_hdr = (struct ether_hdr *)(priv->rxp);
339 eth_proto = ntohs(eth_hdr->h_proto);
341 if (eth_hdr->h_dest_snap != eth_hdr->h_source_snap) {
342 DPRINTK(1, "invalid data format\n");
343 priv->nstats.rx_errors++;
346 if (((auth_type == TYPE_PMK1 &&
347 priv->wpa.pairwise_suite == IW_AUTH_CIPHER_TKIP) ||
348 (auth_type == TYPE_GMK1 &&
349 priv->wpa.group_suite == IW_AUTH_CIPHER_TKIP) ||
350 (auth_type == TYPE_GMK2 &&
351 priv->wpa.group_suite == IW_AUTH_CIPHER_TKIP)) &&
353 DPRINTK(4, "TKIP: protocol=%04X: size=%u\n",
354 eth_proto, priv->rx_size);
356 memcpy(&recv_mic[0], (priv->rxp) + ((priv->rx_size) - 8), 8);
357 priv->rx_size = priv->rx_size - 8;
358 if (auth_type > 0 && auth_type < 4) { /* auth_type check */
359 MichaelMICFunction(&michael_mic,
360 (uint8_t *)key->rx_mic_key,
361 (uint8_t *)priv->rxp,
363 (uint8_t)0, /* priority */
364 (uint8_t *)michael_mic.Result);
366 if (memcmp(michael_mic.Result, recv_mic, 8) != 0) {
368 mic_failure = &priv->wpa.mic_failure;
370 if (mic_failure->last_failure_time &&
371 (now - mic_failure->last_failure_time) / HZ >= 60) {
372 mic_failure->failure = 0;
374 DPRINTK(4, "MIC FAILURE\n");
375 if (mic_failure->failure == 0) {
376 mic_failure->failure = 1;
377 mic_failure->counter = 0;
378 } else if (mic_failure->failure == 1) {
379 mic_failure->failure = 2;
380 mic_failure->counter =
381 (uint16_t)((now - mic_failure->last_failure_time) / HZ);
382 if (!mic_failure->counter) /* range 1-60 */
383 mic_failure->counter = 1;
385 priv->wpa.mic_failure.last_failure_time = now;
387 /* needed parameters: count, keyid, key type, TSC */
389 "MLME-MICHAELMICFAILURE.indication(keyid=%d %scast addr=%pM)",
391 eth_hdr->h_dest[0] & 0x01 ? "broad" : "uni",
393 memset(&wrqu, 0, sizeof(wrqu));
394 wrqu.data.length = strlen(buf);
395 DPRINTK(4, "IWEVENT:MICHAELMICFAILURE\n");
396 wireless_send_event(priv->net_dev, IWEVCUSTOM, &wrqu,
405 void hostif_data_indication(struct ks_wlan_private *priv)
407 unsigned int rx_ind_size; /* indicate data size */
409 unsigned short auth_type;
410 unsigned char temp[256];
411 struct ether_hdr *eth_hdr;
412 unsigned short eth_proto;
413 struct ieee802_1x_hdr *aa1x_hdr;
419 /* min length check */
420 if (priv->rx_size <= ETH_HLEN) {
421 DPRINTK(3, "rx_size = %d\n", priv->rx_size);
422 priv->nstats.rx_errors++;
426 auth_type = get_WORD(priv); /* AuthType */
427 get_WORD(priv); /* Reserve Area */
429 eth_hdr = (struct ether_hdr *)(priv->rxp);
430 eth_proto = ntohs(eth_hdr->h_proto);
431 DPRINTK(3, "ether protocol = %04X\n", eth_proto);
433 /* source address check */
434 if (memcmp(&priv->eth_addr[0], eth_hdr->h_source, ETH_ALEN) == 0) {
435 DPRINTK(1, "invalid : source is own mac address !!\n");
437 "eth_hdrernet->h_dest=%02X:%02X:%02X:%02X:%02X:%02X\n",
438 eth_hdr->h_source[0], eth_hdr->h_source[1],
439 eth_hdr->h_source[2], eth_hdr->h_source[3],
440 eth_hdr->h_source[4], eth_hdr->h_source[5]);
441 priv->nstats.rx_errors++;
446 if (auth_type != TYPE_DATA && priv->wpa.rsn_enabled) {
447 ret = hostif_data_indication_wpa(priv, auth_type);
452 if ((priv->connect_status & FORCE_DISCONNECT) ||
453 priv->wpa.mic_failure.failure == 2) {
457 /* check 13th byte at rx data */
458 switch (*(priv->rxp + 12)) {
459 case 0xAA: /* SNAP */
460 rx_ind_size = priv->rx_size - 6;
461 skb = dev_alloc_skb(rx_ind_size);
463 priv->nstats.rx_dropped++;
466 DPRINTK(4, "SNAP, rx_ind_size = %d\n", rx_ind_size);
469 skb_put_data(skb, priv->rxp, size);
471 /* (SNAP+UI..) skip */
473 size = rx_ind_size - (ETH_ALEN * 2);
474 skb_put_data(skb, ð_hdr->h_proto, size);
476 aa1x_hdr = (struct ieee802_1x_hdr *)(priv->rxp + ETHER_HDR_SIZE);
478 case 0xF0: /* NETBEUI/NetBIOS */
479 rx_ind_size = (priv->rx_size + 2);
480 skb = dev_alloc_skb(rx_ind_size);
482 priv->nstats.rx_dropped++;
485 DPRINTK(3, "NETBEUI/NetBIOS rx_ind_size=%d\n", rx_ind_size);
487 skb_put_data(skb, priv->rxp, 12); /* 8802/FDDI MAC copy */
489 temp[0] = (((rx_ind_size - 12) >> 8) & 0xff); /* NETBEUI size add */
490 temp[1] = ((rx_ind_size - 12) & 0xff);
491 skb_put_data(skb, temp, 2);
493 skb_put_data(skb, priv->rxp + 12, rx_ind_size - 14); /* copy after Type */
495 aa1x_hdr = (struct ieee802_1x_hdr *)(priv->rxp + 14);
497 default: /* other rx data */
498 DPRINTK(2, "invalid data format\n");
499 priv->nstats.rx_errors++;
503 if (aa1x_hdr->type == IEEE802_1X_TYPE_EAPOL_KEY &&
504 priv->wpa.rsn_enabled)
505 atomic_set(&priv->psstatus.snooze_guard, 1);
508 skb->dev = priv->net_dev;
509 skb->protocol = eth_type_trans(skb, skb->dev);
510 priv->nstats.rx_packets++;
511 priv->nstats.rx_bytes += rx_ind_size;
516 void hostif_mib_get_confirm(struct ks_wlan_private *priv)
518 struct net_device *dev = priv->net_dev;
526 mib_status = get_DWORD(priv); /* MIB status */
527 mib_attribute = get_DWORD(priv); /* MIB atttibute */
528 mib_val_size = get_WORD(priv); /* MIB value size */
529 mib_val_type = get_WORD(priv); /* MIB value type */
532 /* in case of error */
533 DPRINTK(1, "attribute=%08X, status=%08X\n", mib_attribute,
538 switch (mib_attribute) {
539 case DOT11_MAC_ADDRESS:
541 DPRINTK(3, " mib_attribute=DOT11_MAC_ADDRESS\n");
542 hostif_sme_enqueue(priv, SME_GET_MAC_ADDRESS);
543 memcpy(priv->eth_addr, priv->rxp, ETH_ALEN);
544 priv->mac_address_valid = 1;
545 dev->dev_addr[0] = priv->eth_addr[0];
546 dev->dev_addr[1] = priv->eth_addr[1];
547 dev->dev_addr[2] = priv->eth_addr[2];
548 dev->dev_addr[3] = priv->eth_addr[3];
549 dev->dev_addr[4] = priv->eth_addr[4];
550 dev->dev_addr[5] = priv->eth_addr[5];
551 dev->dev_addr[6] = 0x00;
552 dev->dev_addr[7] = 0x00;
553 netdev_info(dev, "MAC ADDRESS = %pM\n", priv->eth_addr);
555 case DOT11_PRODUCT_VERSION:
556 /* firmware version */
557 DPRINTK(3, " mib_attribute=DOT11_PRODUCT_VERSION\n");
558 priv->version_size = priv->rx_size;
559 memcpy(priv->firmware_version, priv->rxp, priv->rx_size);
560 priv->firmware_version[priv->rx_size] = '\0';
561 netdev_info(dev, "firmware ver. = %s\n",
562 priv->firmware_version);
563 hostif_sme_enqueue(priv, SME_GET_PRODUCT_VERSION);
564 /* wake_up_interruptible_all(&priv->confirm_wait); */
565 complete(&priv->confirm_wait);
568 memcpy(&priv->gain, priv->rxp, sizeof(priv->gain));
569 DPRINTK(3, "tx_mode=%d, rx_mode=%d, tx_gain=%d, rx_gain=%d\n",
570 priv->gain.tx_mode, priv->gain.rx_mode,
571 priv->gain.tx_gain, priv->gain.rx_gain);
573 case LOCAL_EEPROM_SUM:
574 memcpy(&priv->eeprom_sum, priv->rxp, sizeof(priv->eeprom_sum));
575 DPRINTK(1, "eeprom_sum.type=%x, eeprom_sum.result=%x\n",
576 priv->eeprom_sum.type, priv->eeprom_sum.result);
577 if (priv->eeprom_sum.type == 0) {
578 priv->eeprom_checksum = EEPROM_CHECKSUM_NONE;
579 } else if (priv->eeprom_sum.type == 1) {
580 if (priv->eeprom_sum.result == 0) {
581 priv->eeprom_checksum = EEPROM_NG;
582 netdev_info(dev, "LOCAL_EEPROM_SUM NG\n");
583 } else if (priv->eeprom_sum.result == 1) {
584 priv->eeprom_checksum = EEPROM_OK;
587 netdev_err(dev, "LOCAL_EEPROM_SUM error!\n");
591 DPRINTK(1, "mib_attribute=%08x\n", (unsigned int)mib_attribute);
597 void hostif_mib_set_confirm(struct ks_wlan_private *priv)
599 u32 mib_status; /* +04 MIB Status */
600 u32 mib_attribute; /* +08 MIB attribute */
604 mib_status = get_DWORD(priv); /* MIB Status */
605 mib_attribute = get_DWORD(priv); /* MIB attribute */
608 /* in case of error */
609 DPRINTK(1, "error :: attribute=%08X, status=%08X\n",
610 mib_attribute, mib_status);
613 switch (mib_attribute) {
614 case DOT11_RTS_THRESHOLD:
615 hostif_sme_enqueue(priv, SME_RTS_THRESHOLD_CONFIRM);
617 case DOT11_FRAGMENTATION_THRESHOLD:
618 hostif_sme_enqueue(priv, SME_FRAGMENTATION_THRESHOLD_CONFIRM);
620 case DOT11_WEP_DEFAULT_KEY_ID:
621 if (!priv->wpa.wpa_enabled)
622 hostif_sme_enqueue(priv, SME_WEP_INDEX_CONFIRM);
624 case DOT11_WEP_DEFAULT_KEY_VALUE1:
625 DPRINTK(2, "DOT11_WEP_DEFAULT_KEY_VALUE1:mib_status=%d\n",
627 if (priv->wpa.rsn_enabled)
628 hostif_sme_enqueue(priv, SME_SET_PMK_TSC);
630 hostif_sme_enqueue(priv, SME_WEP_KEY1_CONFIRM);
632 case DOT11_WEP_DEFAULT_KEY_VALUE2:
633 DPRINTK(2, "DOT11_WEP_DEFAULT_KEY_VALUE2:mib_status=%d\n",
635 if (priv->wpa.rsn_enabled)
636 hostif_sme_enqueue(priv, SME_SET_GMK1_TSC);
638 hostif_sme_enqueue(priv, SME_WEP_KEY2_CONFIRM);
640 case DOT11_WEP_DEFAULT_KEY_VALUE3:
641 DPRINTK(2, "DOT11_WEP_DEFAULT_KEY_VALUE3:mib_status=%d\n",
643 if (priv->wpa.rsn_enabled)
644 hostif_sme_enqueue(priv, SME_SET_GMK2_TSC);
646 hostif_sme_enqueue(priv, SME_WEP_KEY3_CONFIRM);
648 case DOT11_WEP_DEFAULT_KEY_VALUE4:
649 DPRINTK(2, "DOT11_WEP_DEFAULT_KEY_VALUE4:mib_status=%d\n",
651 if (!priv->wpa.rsn_enabled)
652 hostif_sme_enqueue(priv, SME_WEP_KEY4_CONFIRM);
654 case DOT11_PRIVACY_INVOKED:
655 if (!priv->wpa.rsn_enabled)
656 hostif_sme_enqueue(priv, SME_WEP_FLAG_CONFIRM);
658 case DOT11_RSN_ENABLED:
659 DPRINTK(2, "DOT11_RSN_ENABLED:mib_status=%d\n",
661 hostif_sme_enqueue(priv, SME_RSN_ENABLED_CONFIRM);
664 hostif_sme_enqueue(priv, SME_RSN_MODE_CONFIRM);
666 case LOCAL_MULTICAST_ADDRESS:
667 hostif_sme_enqueue(priv, SME_MULTICAST_REQUEST);
669 case LOCAL_MULTICAST_FILTER:
670 hostif_sme_enqueue(priv, SME_MULTICAST_CONFIRM);
672 case LOCAL_CURRENTADDRESS:
673 priv->mac_address_valid = 1;
675 case DOT11_RSN_CONFIG_MULTICAST_CIPHER:
676 DPRINTK(2, "DOT11_RSN_CONFIG_MULTICAST_CIPHER:mib_status=%d\n",
678 hostif_sme_enqueue(priv, SME_RSN_MCAST_CONFIRM);
680 case DOT11_RSN_CONFIG_UNICAST_CIPHER:
681 DPRINTK(2, "DOT11_RSN_CONFIG_UNICAST_CIPHER:mib_status=%d\n",
683 hostif_sme_enqueue(priv, SME_RSN_UCAST_CONFIRM);
685 case DOT11_RSN_CONFIG_AUTH_SUITE:
686 DPRINTK(2, "DOT11_RSN_CONFIG_AUTH_SUITE:mib_status=%d\n",
688 hostif_sme_enqueue(priv, SME_RSN_AUTH_CONFIRM);
691 DPRINTK(2, "DOT11_PMK_TSC:mib_status=%d\n", (int)mib_status);
694 DPRINTK(2, "DOT11_GMK1_TSC:mib_status=%d\n", (int)mib_status);
695 if (atomic_read(&priv->psstatus.snooze_guard))
696 atomic_set(&priv->psstatus.snooze_guard, 0);
699 DPRINTK(2, "DOT11_GMK2_TSC:mib_status=%d\n", (int)mib_status);
700 if (atomic_read(&priv->psstatus.snooze_guard))
701 atomic_set(&priv->psstatus.snooze_guard, 0);
704 DPRINTK(2, "LOCAL_PMK:mib_status=%d\n", (int)mib_status);
707 DPRINTK(2, "LOCAL_GAIN:mib_status=%d\n", (int)mib_status);
710 case LOCAL_WPS_ENABLE:
711 DPRINTK(2, "LOCAL_WPS_ENABLE:mib_status=%d\n", (int)mib_status);
713 case LOCAL_WPS_PROBE_REQ:
714 DPRINTK(2, "LOCAL_WPS_PROBE_REQ:mib_status=%d\n",
719 DPRINTK(2, "LOCAL_REGION:mib_status=%d\n", (int)mib_status);
726 void hostif_power_mgmt_confirm(struct ks_wlan_private *priv)
730 if (priv->reg.power_mgmt > POWER_MGMT_ACTIVE &&
731 priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
732 atomic_set(&priv->psstatus.confirm_wait, 0);
733 priv->dev_state = DEVICE_STATE_SLEEP;
734 ks_wlan_hw_power_save(priv);
736 priv->dev_state = DEVICE_STATE_READY;
741 void hostif_sleep_confirm(struct ks_wlan_private *priv)
745 atomic_set(&priv->sleepstatus.doze_request, 1);
746 queue_delayed_work(priv->wq, &priv->rw_dwork, 1);
750 void hostif_start_confirm(struct ks_wlan_private *priv)
753 union iwreq_data wrqu;
755 wrqu.data.length = 0;
757 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
758 if (is_connect_status(priv->connect_status)) {
759 eth_zero_addr(wrqu.ap_addr.sa_data);
760 DPRINTK(3, "IWEVENT: disconnect\n");
761 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
764 DPRINTK(3, " scan_ind_count=%d\n", priv->scan_ind_count);
765 hostif_sme_enqueue(priv, SME_START_CONFIRM);
769 void hostif_connect_indication(struct ks_wlan_private *priv)
771 unsigned short connect_code;
772 unsigned int tmp = 0;
773 unsigned int old_status = priv->connect_status;
774 struct net_device *netdev = priv->net_dev;
775 union iwreq_data wrqu0;
777 connect_code = get_WORD(priv);
779 switch (connect_code) {
780 case RESULT_CONNECT: /* connect */
781 DPRINTK(3, "connect :: scan_ind_count=%d\n",
782 priv->scan_ind_count);
783 if (!(priv->connect_status & FORCE_DISCONNECT))
784 netif_carrier_on(netdev);
785 tmp = FORCE_DISCONNECT & priv->connect_status;
786 priv->connect_status = tmp + CONNECT_STATUS;
788 case RESULT_DISCONNECT: /* disconnect */
789 DPRINTK(3, "disconnect :: scan_ind_count=%d\n",
790 priv->scan_ind_count);
791 netif_carrier_off(netdev);
792 tmp = FORCE_DISCONNECT & priv->connect_status;
793 priv->connect_status = tmp + DISCONNECT_STATUS;
796 DPRINTK(1, "unknown connect_code=%d :: scan_ind_count=%d\n",
797 connect_code, priv->scan_ind_count);
798 netif_carrier_off(netdev);
799 tmp = FORCE_DISCONNECT & priv->connect_status;
800 priv->connect_status = tmp + DISCONNECT_STATUS;
804 get_current_ap(priv, (struct link_ap_info_t *)priv->rxp);
805 if (is_connect_status(priv->connect_status) &&
806 is_disconnect_status(old_status)) {
808 atomic_set(&priv->psstatus.snooze_guard, 0);
809 atomic_set(&priv->psstatus.confirm_wait, 0);
811 ks_wlan_do_power_save(priv);
813 wrqu0.data.length = 0;
814 wrqu0.data.flags = 0;
815 wrqu0.ap_addr.sa_family = ARPHRD_ETHER;
816 if (is_disconnect_status(priv->connect_status) &&
817 is_connect_status(old_status)) {
818 eth_zero_addr(wrqu0.ap_addr.sa_data);
819 DPRINTK(3, "IWEVENT: disconnect\n");
820 DPRINTK(3, "disconnect :: scan_ind_count=%d\n",
821 priv->scan_ind_count);
822 wireless_send_event(netdev, SIOCGIWAP, &wrqu0, NULL);
824 priv->scan_ind_count = 0;
828 void hostif_scan_indication(struct ks_wlan_private *priv)
831 struct ap_info_t *ap_info;
833 DPRINTK(3, "scan_ind_count = %d\n", priv->scan_ind_count);
834 ap_info = (struct ap_info_t *)(priv->rxp);
836 if (priv->scan_ind_count) {
837 for (i = 0; i < priv->aplist.size; i++) { /* bssid check */
838 if (memcmp(ap_info->bssid,
839 priv->aplist.ap[i].bssid, ETH_ALEN) != 0)
842 if (ap_info->frame_type == FRAME_TYPE_PROBE_RESP)
843 get_ap_information(priv, ap_info,
844 &priv->aplist.ap[i]);
848 priv->scan_ind_count++;
849 if (priv->scan_ind_count < LOCAL_APLIST_MAX + 1) {
850 DPRINTK(4, " scan_ind_count=%d :: aplist.size=%d\n",
851 priv->scan_ind_count, priv->aplist.size);
852 get_ap_information(priv, (struct ap_info_t *)(priv->rxp),
853 &(priv->aplist.ap[priv->scan_ind_count - 1]));
854 priv->aplist.size = priv->scan_ind_count;
856 DPRINTK(4, " count over :: scan_ind_count=%d\n",
857 priv->scan_ind_count);
862 void hostif_stop_confirm(struct ks_wlan_private *priv)
864 unsigned int tmp = 0;
865 unsigned int old_status = priv->connect_status;
866 struct net_device *netdev = priv->net_dev;
867 union iwreq_data wrqu0;
870 if (priv->dev_state == DEVICE_STATE_SLEEP)
871 priv->dev_state = DEVICE_STATE_READY;
873 /* disconnect indication */
874 if (is_connect_status(priv->connect_status)) {
875 netif_carrier_off(netdev);
876 tmp = FORCE_DISCONNECT & priv->connect_status;
877 priv->connect_status = tmp | DISCONNECT_STATUS;
878 netdev_info(netdev, "IWEVENT: disconnect\n");
880 wrqu0.data.length = 0;
881 wrqu0.data.flags = 0;
882 wrqu0.ap_addr.sa_family = ARPHRD_ETHER;
883 if (is_disconnect_status(priv->connect_status) &&
884 is_connect_status(old_status)) {
885 eth_zero_addr(wrqu0.ap_addr.sa_data);
886 DPRINTK(3, "IWEVENT: disconnect\n");
887 netdev_info(netdev, "IWEVENT: disconnect\n");
888 DPRINTK(3, "disconnect :: scan_ind_count=%d\n",
889 priv->scan_ind_count);
890 wireless_send_event(netdev, SIOCGIWAP, &wrqu0, NULL);
892 priv->scan_ind_count = 0;
895 hostif_sme_enqueue(priv, SME_STOP_CONFIRM);
899 void hostif_ps_adhoc_set_confirm(struct ks_wlan_private *priv)
902 priv->infra_status = 0; /* infrastructure mode cancel */
903 hostif_sme_enqueue(priv, SME_MODE_SET_CONFIRM);
907 void hostif_infrastructure_set_confirm(struct ks_wlan_private *priv)
912 result_code = get_WORD(priv);
913 DPRINTK(3, "result code = %d\n", result_code);
914 priv->infra_status = 1; /* infrastructure mode set */
915 hostif_sme_enqueue(priv, SME_MODE_SET_CONFIRM);
919 void hostif_adhoc_set_confirm(struct ks_wlan_private *priv)
922 priv->infra_status = 1; /* infrastructure mode set */
923 hostif_sme_enqueue(priv, SME_MODE_SET_CONFIRM);
927 void hostif_associate_indication(struct ks_wlan_private *priv)
929 struct association_request_t *assoc_req;
930 struct association_response_t *assoc_resp;
932 union iwreq_data wrqu;
933 char buf[IW_CUSTOM_MAX];
934 char *pbuf = &buf[0];
937 static const char associnfo_leader0[] = "ASSOCINFO(ReqIEs=";
938 static const char associnfo_leader1[] = " RespIEs=";
941 assoc_req = (struct association_request_t *)(priv->rxp);
942 assoc_resp = (struct association_response_t *)(assoc_req + 1);
943 pb = (unsigned char *)(assoc_resp + 1);
945 memset(&wrqu, 0, sizeof(wrqu));
946 memcpy(pbuf, associnfo_leader0, sizeof(associnfo_leader0) - 1);
947 wrqu.data.length += sizeof(associnfo_leader0) - 1;
948 pbuf += sizeof(associnfo_leader0) - 1;
950 for (i = 0; i < le16_to_cpu(assoc_req->req_ies_size); i++)
951 pbuf += sprintf(pbuf, "%02x", *(pb + i));
952 wrqu.data.length += (le16_to_cpu(assoc_req->req_ies_size)) * 2;
954 memcpy(pbuf, associnfo_leader1, sizeof(associnfo_leader1) - 1);
955 wrqu.data.length += sizeof(associnfo_leader1) - 1;
956 pbuf += sizeof(associnfo_leader1) - 1;
958 pb += le16_to_cpu(assoc_req->req_ies_size);
959 for (i = 0; i < le16_to_cpu(assoc_resp->resp_ies_size); i++)
960 pbuf += sprintf(pbuf, "%02x", *(pb + i));
961 wrqu.data.length += (le16_to_cpu(assoc_resp->resp_ies_size)) * 2;
963 pbuf += sprintf(pbuf, ")");
964 wrqu.data.length += 1;
966 DPRINTK(3, "IWEVENT:ASSOCINFO\n");
967 wireless_send_event(priv->net_dev, IWEVCUSTOM, &wrqu, buf);
971 void hostif_bss_scan_confirm(struct ks_wlan_private *priv)
973 unsigned int result_code;
974 struct net_device *dev = priv->net_dev;
975 union iwreq_data wrqu;
977 result_code = get_DWORD(priv);
978 DPRINTK(2, "result=%d :: scan_ind_count=%d\n", result_code,
979 priv->scan_ind_count);
981 priv->sme_i.sme_flag &= ~SME_AP_SCAN;
982 hostif_sme_enqueue(priv, SME_BSS_SCAN_CONFIRM);
984 wrqu.data.length = 0;
986 DPRINTK(3, "IWEVENT: SCAN CONFIRM\n");
987 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
988 priv->scan_ind_count = 0;
992 void hostif_phy_information_confirm(struct ks_wlan_private *priv)
994 struct iw_statistics *wstats = &priv->wstats;
995 unsigned char rssi, signal, noise;
996 unsigned char link_speed;
997 unsigned int transmitted_frame_count, received_fragment_count;
998 unsigned int failed_count, fcs_error_count;
1001 rssi = get_BYTE(priv);
1002 signal = get_BYTE(priv);
1003 noise = get_BYTE(priv);
1004 link_speed = get_BYTE(priv);
1005 transmitted_frame_count = get_DWORD(priv);
1006 received_fragment_count = get_DWORD(priv);
1007 failed_count = get_DWORD(priv);
1008 fcs_error_count = get_DWORD(priv);
1010 DPRINTK(4, "phyinfo confirm rssi=%d signal=%d\n", rssi, signal);
1011 priv->current_rate = (link_speed & RATE_MASK);
1012 wstats->qual.qual = signal;
1013 wstats->qual.level = 256 - rssi;
1014 wstats->qual.noise = 0; /* invalid noise value */
1015 wstats->qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
1017 DPRINTK(3, "\n rssi=%u\n"
1019 " link_speed=%ux500Kbps\n"
1020 " transmitted_frame_count=%u\n"
1021 " received_fragment_count=%u\n"
1022 " failed_count=%u\n"
1023 " fcs_error_count=%u\n",
1024 rssi, signal, link_speed, transmitted_frame_count,
1025 received_fragment_count, failed_count, fcs_error_count);
1026 /* wake_up_interruptible_all(&priv->confirm_wait); */
1027 complete(&priv->confirm_wait);
1031 void hostif_mic_failure_confirm(struct ks_wlan_private *priv)
1033 DPRINTK(3, "mic_failure=%u\n", priv->wpa.mic_failure.failure);
1034 hostif_sme_enqueue(priv, SME_MIC_FAILURE_CONFIRM);
1038 void hostif_event_check(struct ks_wlan_private *priv)
1040 unsigned short event;
1043 event = get_WORD(priv); /* get event */
1046 hostif_data_indication(priv);
1048 case HIF_MIB_GET_CONF:
1049 hostif_mib_get_confirm(priv);
1051 case HIF_MIB_SET_CONF:
1052 hostif_mib_set_confirm(priv);
1054 case HIF_POWER_MGMT_CONF:
1055 hostif_power_mgmt_confirm(priv);
1057 case HIF_SLEEP_CONF:
1058 hostif_sleep_confirm(priv);
1060 case HIF_START_CONF:
1061 hostif_start_confirm(priv);
1063 case HIF_CONNECT_IND:
1064 hostif_connect_indication(priv);
1067 hostif_stop_confirm(priv);
1069 case HIF_PS_ADH_SET_CONF:
1070 hostif_ps_adhoc_set_confirm(priv);
1072 case HIF_INFRA_SET_CONF:
1073 case HIF_INFRA_SET2_CONF:
1074 hostif_infrastructure_set_confirm(priv);
1076 case HIF_ADH_SET_CONF:
1077 case HIF_ADH_SET2_CONF:
1078 hostif_adhoc_set_confirm(priv);
1080 case HIF_ASSOC_INFO_IND:
1081 hostif_associate_indication(priv);
1083 case HIF_MIC_FAILURE_CONF:
1084 hostif_mic_failure_confirm(priv);
1087 hostif_bss_scan_confirm(priv);
1089 case HIF_PHY_INFO_CONF:
1090 case HIF_PHY_INFO_IND:
1091 hostif_phy_information_confirm(priv);
1094 hostif_scan_indication(priv);
1096 case HIF_AP_SET_CONF:
1098 //DPRINTK(1, "undefined event[%04X]\n", event);
1099 netdev_err(priv->net_dev, "undefined event[%04X]\n", event);
1100 /* wake_up_all(&priv->confirm_wait); */
1101 complete(&priv->confirm_wait);
1105 /* add event to hostt buffer */
1106 priv->hostt.buff[priv->hostt.qtail] = event;
1107 priv->hostt.qtail = (priv->hostt.qtail + 1) % SME_EVENT_BUFF_SIZE;
1110 /* allocate size bytes, set header size and event */
1111 static void *hostif_generic_request(size_t size, int event)
1113 struct hostif_hdr *p;
1115 p = kzalloc(hif_align_size(size), KS_WLAN_MEM_FLAG);
1119 p->size = cpu_to_le16((u16)(size - sizeof(p->size)));
1120 p->event = cpu_to_le16(event);
1125 int hostif_data_request(struct ks_wlan_private *priv, struct sk_buff *skb)
1127 unsigned int skb_len = 0;
1129 unsigned char *buffer = NULL;
1130 unsigned int length = 0;
1131 struct hostif_data_request_t *pp;
1134 unsigned short eth_proto;
1135 struct ether_hdr *eth_hdr;
1136 struct michael_mic_t michael_mic;
1137 unsigned short keyinfo = 0;
1138 struct ieee802_1x_hdr *aa1x_hdr;
1139 struct wpa_eapol_key *eap_key;
1145 if (skb_len > ETH_FRAME_LEN) {
1146 DPRINTK(1, "bad length skb_len=%d\n", skb_len);
1151 if (is_disconnect_status(priv->connect_status) ||
1152 (priv->connect_status & FORCE_DISCONNECT) ||
1153 priv->wpa.mic_failure.stop) {
1154 DPRINTK(3, " DISCONNECT\n");
1155 if (netif_queue_stopped(priv->net_dev))
1156 netif_wake_queue(priv->net_dev);
1164 if (atomic_read(&priv->psstatus.status) == PS_SNOOZE) { /* power save wakeup */
1165 if (!netif_queue_stopped(priv->net_dev))
1166 netif_stop_queue(priv->net_dev);
1169 size = sizeof(*pp) + 6 + skb_len + 8;
1170 pp = kmalloc(hif_align_size(size), KS_WLAN_MEM_FLAG);
1176 p = (unsigned char *)pp->data;
1182 eth = (struct ethhdr *)skb->data;
1183 if (memcmp(&priv->eth_addr[0], eth->h_source, ETH_ALEN) != 0) {
1184 DPRINTK(1, "invalid mac address !!\n");
1185 DPRINTK(1, "ethernet->h_source=%pM\n", eth->h_source);
1190 /* dest and src MAC address copy */
1191 size = ETH_ALEN * 2;
1192 memcpy(p, buffer, size);
1197 /* EtherType/Length check */
1198 if (*(buffer + 1) + (*buffer << 8) > 1500) {
1199 /* ProtocolEAP = *(buffer+1) + (*buffer << 8); */
1200 /* DPRINTK(2, "Send [SNAP]Type %x\n",ProtocolEAP); */
1201 /* SAP/CTL/OUI(6 byte) add */
1202 *p++ = 0xAA; /* DSAP */
1203 *p++ = 0xAA; /* SSAP */
1204 *p++ = 0x03; /* CTL */
1205 *p++ = 0x00; /* OUI ("000000") */
1206 *p++ = 0x00; /* OUI ("000000") */
1207 *p++ = 0x00; /* OUI ("000000") */
1210 DPRINTK(4, "DIX\n");
1211 /* Length(2 byte) delete */
1218 memcpy(p, buffer, length);
1223 eth_hdr = (struct ether_hdr *)&pp->data[0];
1224 eth_proto = ntohs(eth_hdr->h_proto);
1226 /* for MIC FAILURE REPORT check */
1227 if (eth_proto == ETHER_PROTOCOL_TYPE_EAP &&
1228 priv->wpa.mic_failure.failure > 0) {
1229 aa1x_hdr = (struct ieee802_1x_hdr *)(eth_hdr + 1);
1230 if (aa1x_hdr->type == IEEE802_1X_TYPE_EAPOL_KEY) {
1231 eap_key = (struct wpa_eapol_key *)(aa1x_hdr + 1);
1232 keyinfo = ntohs(eap_key->key_info);
1236 if (priv->wpa.rsn_enabled && priv->wpa.key[0].key_len) {
1237 if (eth_proto == ETHER_PROTOCOL_TYPE_EAP &&
1238 priv->wpa.key[1].key_len == 0 &&
1239 priv->wpa.key[2].key_len == 0 &&
1240 priv->wpa.key[3].key_len == 0) {
1241 pp->auth_type = cpu_to_le16((uint16_t)TYPE_AUTH); /* no encryption */
1243 if (priv->wpa.pairwise_suite == IW_AUTH_CIPHER_TKIP) {
1244 MichaelMICFunction(&michael_mic,
1245 (uint8_t *)priv->wpa.key[0].tx_mic_key,
1246 (uint8_t *)&pp->data[0],
1248 (uint8_t)0, /* priority */
1249 (uint8_t *)michael_mic.Result);
1250 memcpy(p, michael_mic.Result, 8);
1255 cpu_to_le16((uint16_t)TYPE_DATA);
1257 } else if (priv->wpa.pairwise_suite ==
1258 IW_AUTH_CIPHER_CCMP) {
1260 cpu_to_le16((uint16_t)TYPE_DATA);
1264 if (eth_proto == ETHER_PROTOCOL_TYPE_EAP)
1265 pp->auth_type = cpu_to_le16((uint16_t)TYPE_AUTH);
1267 pp->auth_type = cpu_to_le16((uint16_t)TYPE_DATA);
1270 /* header value set */
1272 cpu_to_le16((uint16_t)
1273 (sizeof(*pp) - sizeof(pp->header.size) + skb_len));
1274 pp->header.event = cpu_to_le16((uint16_t)HIF_DATA_REQ);
1277 result = ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp) + skb_len),
1278 send_packet_complete, skb);
1280 /* MIC FAILURE REPORT check */
1281 if (eth_proto == ETHER_PROTOCOL_TYPE_EAP &&
1282 priv->wpa.mic_failure.failure > 0) {
1283 if (keyinfo & WPA_KEY_INFO_ERROR &&
1284 keyinfo & WPA_KEY_INFO_REQUEST) {
1285 DPRINTK(3, " MIC ERROR Report SET : %04X\n", keyinfo);
1286 hostif_sme_enqueue(priv, SME_MIC_FAILURE_REQUEST);
1288 if (priv->wpa.mic_failure.failure == 2)
1289 priv->wpa.mic_failure.stop = 1;
1302 #define ps_confirm_wait_inc(priv) \
1304 if (atomic_read(&priv->psstatus.status) > PS_ACTIVE_SET) \
1305 atomic_inc(&priv->psstatus.confirm_wait); \
1309 void hostif_mib_get_request(struct ks_wlan_private *priv,
1310 unsigned long mib_attribute)
1312 struct hostif_mib_get_request_t *pp;
1316 pp = hostif_generic_request(sizeof(*pp), HIF_MIB_GET_REQ);
1320 pp->mib_attribute = cpu_to_le32((uint32_t)mib_attribute);
1322 /* send to device request */
1323 ps_confirm_wait_inc(priv);
1324 ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL);
1328 void hostif_mib_set_request(struct ks_wlan_private *priv,
1329 unsigned long mib_attribute, unsigned short size,
1330 unsigned short type, void *vp)
1332 struct hostif_mib_set_request_t *pp;
1336 if (priv->dev_state < DEVICE_STATE_BOOT) {
1337 DPRINTK(3, "DeviceRemove\n");
1341 pp = hostif_generic_request(sizeof(*pp), HIF_MIB_SET_REQ);
1345 pp->mib_attribute = cpu_to_le32((uint32_t)mib_attribute);
1346 pp->mib_value.size = cpu_to_le16((uint16_t)size);
1347 pp->mib_value.type = cpu_to_le16((uint16_t)type);
1348 memcpy(&pp->mib_value.body, vp, size);
1350 /* send to device request */
1351 ps_confirm_wait_inc(priv);
1352 ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp) + size), NULL, NULL);
1356 void hostif_start_request(struct ks_wlan_private *priv, unsigned char mode)
1358 struct hostif_start_request_t *pp;
1362 pp = hostif_generic_request(sizeof(*pp), HIF_START_REQ);
1366 pp->mode = cpu_to_le16((uint16_t)mode);
1368 /* send to device request */
1369 ps_confirm_wait_inc(priv);
1370 ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL);
1372 priv->aplist.size = 0;
1373 priv->scan_ind_count = 0;
1377 void hostif_ps_adhoc_set_request(struct ks_wlan_private *priv)
1379 struct hostif_ps_adhoc_set_request_t *pp;
1384 pp = hostif_generic_request(sizeof(*pp), HIF_PS_ADH_SET_REQ);
1388 pp->phy_type = cpu_to_le16((uint16_t)(priv->reg.phy_type));
1389 pp->cts_mode = cpu_to_le16((uint16_t)(priv->reg.cts_mode));
1390 pp->scan_type = cpu_to_le16((uint16_t)(priv->reg.scan_type));
1391 pp->channel = cpu_to_le16((uint16_t)(priv->reg.channel));
1392 pp->rate_set.size = priv->reg.rate_set.size;
1393 memcpy(&pp->rate_set.body[0], &priv->reg.rate_set.body[0],
1394 priv->reg.rate_set.size);
1396 capability = 0x0000;
1397 if (priv->reg.preamble == SHORT_PREAMBLE) {
1398 /* short preamble */
1399 capability |= BSS_CAP_SHORT_PREAMBLE;
1401 capability &= ~(BSS_CAP_PBCC); /* pbcc not support */
1402 if (priv->reg.phy_type != D_11B_ONLY_MODE) {
1403 capability |= BSS_CAP_SHORT_SLOT_TIME; /* ShortSlotTime support */
1404 capability &= ~(BSS_CAP_DSSS_OFDM); /* DSSS OFDM */
1406 pp->capability = cpu_to_le16((uint16_t)capability);
1408 /* send to device request */
1409 ps_confirm_wait_inc(priv);
1410 ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL);
1414 void hostif_infrastructure_set_request(struct ks_wlan_private *priv)
1416 struct hostif_infrastructure_set_request_t *pp;
1419 DPRINTK(3, "ssid.size=%d\n", priv->reg.ssid.size);
1421 pp = hostif_generic_request(sizeof(*pp), HIF_INFRA_SET_REQ);
1425 pp->phy_type = cpu_to_le16((uint16_t)(priv->reg.phy_type));
1426 pp->cts_mode = cpu_to_le16((uint16_t)(priv->reg.cts_mode));
1427 pp->scan_type = cpu_to_le16((uint16_t)(priv->reg.scan_type));
1429 pp->rate_set.size = priv->reg.rate_set.size;
1430 memcpy(&pp->rate_set.body[0], &priv->reg.rate_set.body[0],
1431 priv->reg.rate_set.size);
1432 pp->ssid.size = priv->reg.ssid.size;
1433 memcpy(&pp->ssid.body[0], &priv->reg.ssid.body[0], priv->reg.ssid.size);
1435 capability = 0x0000;
1436 if (priv->reg.preamble == SHORT_PREAMBLE) {
1437 /* short preamble */
1438 capability |= BSS_CAP_SHORT_PREAMBLE;
1440 capability &= ~(BSS_CAP_PBCC); /* pbcc not support */
1441 if (priv->reg.phy_type != D_11B_ONLY_MODE) {
1442 capability |= BSS_CAP_SHORT_SLOT_TIME; /* ShortSlotTime support */
1443 capability &= ~(BSS_CAP_DSSS_OFDM); /* DSSS OFDM not support */
1445 pp->capability = cpu_to_le16((uint16_t)capability);
1446 pp->beacon_lost_count =
1447 cpu_to_le16((uint16_t)(priv->reg.beacon_lost_count));
1448 pp->auth_type = cpu_to_le16((uint16_t)(priv->reg.authenticate_type));
1450 pp->channel_list.body[0] = 1;
1451 pp->channel_list.body[1] = 8;
1452 pp->channel_list.body[2] = 2;
1453 pp->channel_list.body[3] = 9;
1454 pp->channel_list.body[4] = 3;
1455 pp->channel_list.body[5] = 10;
1456 pp->channel_list.body[6] = 4;
1457 pp->channel_list.body[7] = 11;
1458 pp->channel_list.body[8] = 5;
1459 pp->channel_list.body[9] = 12;
1460 pp->channel_list.body[10] = 6;
1461 pp->channel_list.body[11] = 13;
1462 pp->channel_list.body[12] = 7;
1463 if (priv->reg.phy_type == D_11G_ONLY_MODE) {
1464 pp->channel_list.size = 13;
1466 pp->channel_list.body[13] = 14;
1467 pp->channel_list.size = 14;
1470 /* send to device request */
1471 ps_confirm_wait_inc(priv);
1472 ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL);
1475 static void hostif_infrastructure_set2_request(struct ks_wlan_private *priv)
1477 struct hostif_infrastructure_set2_request_t *pp;
1480 DPRINTK(2, "ssid.size=%d\n", priv->reg.ssid.size);
1482 pp = hostif_generic_request(sizeof(*pp), HIF_INFRA_SET2_REQ);
1486 pp->phy_type = cpu_to_le16((uint16_t)(priv->reg.phy_type));
1487 pp->cts_mode = cpu_to_le16((uint16_t)(priv->reg.cts_mode));
1488 pp->scan_type = cpu_to_le16((uint16_t)(priv->reg.scan_type));
1490 pp->rate_set.size = priv->reg.rate_set.size;
1491 memcpy(&pp->rate_set.body[0], &priv->reg.rate_set.body[0],
1492 priv->reg.rate_set.size);
1493 pp->ssid.size = priv->reg.ssid.size;
1494 memcpy(&pp->ssid.body[0], &priv->reg.ssid.body[0], priv->reg.ssid.size);
1496 capability = 0x0000;
1497 if (priv->reg.preamble == SHORT_PREAMBLE) {
1498 /* short preamble */
1499 capability |= BSS_CAP_SHORT_PREAMBLE;
1501 capability &= ~(BSS_CAP_PBCC); /* pbcc not support */
1502 if (priv->reg.phy_type != D_11B_ONLY_MODE) {
1503 capability |= BSS_CAP_SHORT_SLOT_TIME; /* ShortSlotTime support */
1504 capability &= ~(BSS_CAP_DSSS_OFDM); /* DSSS OFDM not support */
1506 pp->capability = cpu_to_le16((uint16_t)capability);
1507 pp->beacon_lost_count =
1508 cpu_to_le16((uint16_t)(priv->reg.beacon_lost_count));
1509 pp->auth_type = cpu_to_le16((uint16_t)(priv->reg.authenticate_type));
1511 pp->channel_list.body[0] = 1;
1512 pp->channel_list.body[1] = 8;
1513 pp->channel_list.body[2] = 2;
1514 pp->channel_list.body[3] = 9;
1515 pp->channel_list.body[4] = 3;
1516 pp->channel_list.body[5] = 10;
1517 pp->channel_list.body[6] = 4;
1518 pp->channel_list.body[7] = 11;
1519 pp->channel_list.body[8] = 5;
1520 pp->channel_list.body[9] = 12;
1521 pp->channel_list.body[10] = 6;
1522 pp->channel_list.body[11] = 13;
1523 pp->channel_list.body[12] = 7;
1524 if (priv->reg.phy_type == D_11G_ONLY_MODE) {
1525 pp->channel_list.size = 13;
1527 pp->channel_list.body[13] = 14;
1528 pp->channel_list.size = 14;
1531 memcpy(pp->bssid, priv->reg.bssid, ETH_ALEN);
1533 /* send to device request */
1534 ps_confirm_wait_inc(priv);
1535 ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL);
1539 void hostif_adhoc_set_request(struct ks_wlan_private *priv)
1541 struct hostif_adhoc_set_request_t *pp;
1546 pp = hostif_generic_request(sizeof(*pp), HIF_ADH_SET_REQ);
1550 pp->phy_type = cpu_to_le16((uint16_t)(priv->reg.phy_type));
1551 pp->cts_mode = cpu_to_le16((uint16_t)(priv->reg.cts_mode));
1552 pp->scan_type = cpu_to_le16((uint16_t)(priv->reg.scan_type));
1553 pp->channel = cpu_to_le16((uint16_t)(priv->reg.channel));
1554 pp->rate_set.size = priv->reg.rate_set.size;
1555 memcpy(&pp->rate_set.body[0], &priv->reg.rate_set.body[0],
1556 priv->reg.rate_set.size);
1557 pp->ssid.size = priv->reg.ssid.size;
1558 memcpy(&pp->ssid.body[0], &priv->reg.ssid.body[0], priv->reg.ssid.size);
1560 capability = 0x0000;
1561 if (priv->reg.preamble == SHORT_PREAMBLE) {
1562 /* short preamble */
1563 capability |= BSS_CAP_SHORT_PREAMBLE;
1565 capability &= ~(BSS_CAP_PBCC); /* pbcc not support */
1566 if (priv->reg.phy_type != D_11B_ONLY_MODE) {
1567 capability |= BSS_CAP_SHORT_SLOT_TIME; /* ShortSlotTime support */
1568 capability &= ~(BSS_CAP_DSSS_OFDM); /* DSSS OFDM not support */
1570 pp->capability = cpu_to_le16((uint16_t)capability);
1572 /* send to device request */
1573 ps_confirm_wait_inc(priv);
1574 ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL);
1578 void hostif_adhoc_set2_request(struct ks_wlan_private *priv)
1580 struct hostif_adhoc_set2_request_t *pp;
1585 pp = hostif_generic_request(sizeof(*pp), HIF_ADH_SET_REQ);
1589 pp->phy_type = cpu_to_le16((uint16_t)(priv->reg.phy_type));
1590 pp->cts_mode = cpu_to_le16((uint16_t)(priv->reg.cts_mode));
1591 pp->scan_type = cpu_to_le16((uint16_t)(priv->reg.scan_type));
1592 pp->rate_set.size = priv->reg.rate_set.size;
1593 memcpy(&pp->rate_set.body[0], &priv->reg.rate_set.body[0],
1594 priv->reg.rate_set.size);
1595 pp->ssid.size = priv->reg.ssid.size;
1596 memcpy(&pp->ssid.body[0], &priv->reg.ssid.body[0], priv->reg.ssid.size);
1598 capability = 0x0000;
1599 if (priv->reg.preamble == SHORT_PREAMBLE) {
1600 /* short preamble */
1601 capability |= BSS_CAP_SHORT_PREAMBLE;
1603 capability &= ~(BSS_CAP_PBCC); /* pbcc not support */
1604 if (priv->reg.phy_type != D_11B_ONLY_MODE) {
1605 capability |= BSS_CAP_SHORT_SLOT_TIME; /* ShortSlotTime support */
1606 capability &= ~(BSS_CAP_DSSS_OFDM); /* DSSS OFDM not support */
1608 pp->capability = cpu_to_le16((uint16_t)capability);
1610 pp->channel_list.body[0] = priv->reg.channel;
1611 pp->channel_list.size = 1;
1612 memcpy(pp->bssid, priv->reg.bssid, ETH_ALEN);
1614 /* send to device request */
1615 ps_confirm_wait_inc(priv);
1616 ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL);
1620 void hostif_stop_request(struct ks_wlan_private *priv)
1622 struct hostif_stop_request_t *pp;
1626 pp = hostif_generic_request(sizeof(*pp), HIF_STOP_REQ);
1630 /* send to device request */
1631 ps_confirm_wait_inc(priv);
1632 ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL);
1636 void hostif_phy_information_request(struct ks_wlan_private *priv)
1638 struct hostif_phy_information_request_t *pp;
1642 pp = hostif_generic_request(sizeof(*pp), HIF_PHY_INFO_REQ);
1646 if (priv->reg.phy_info_timer) {
1647 pp->type = cpu_to_le16((uint16_t)TIME_TYPE);
1648 pp->time = cpu_to_le16((uint16_t)(priv->reg.phy_info_timer));
1650 pp->type = cpu_to_le16((uint16_t)NORMAL_TYPE);
1651 pp->time = cpu_to_le16((uint16_t)0);
1654 /* send to device request */
1655 ps_confirm_wait_inc(priv);
1656 ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL);
1660 void hostif_power_mgmt_request(struct ks_wlan_private *priv,
1661 unsigned long mode, unsigned long wake_up,
1662 unsigned long receive_dtims)
1664 struct hostif_power_mgmt_request_t *pp;
1666 DPRINTK(3, "mode=%lu wake_up=%lu receive_dtims=%lu\n", mode, wake_up,
1669 pp = hostif_generic_request(sizeof(*pp), HIF_POWER_MGMT_REQ);
1673 pp->mode = cpu_to_le32((uint32_t)mode);
1674 pp->wake_up = cpu_to_le32((uint32_t)wake_up);
1675 pp->receive_dtims = cpu_to_le32((uint32_t)receive_dtims);
1677 /* send to device request */
1678 ps_confirm_wait_inc(priv);
1679 ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL);
1683 void hostif_sleep_request(struct ks_wlan_private *priv,
1684 enum sleep_mode_type mode)
1686 struct hostif_sleep_request_t *pp;
1688 DPRINTK(3, "mode=%lu\n", (long)mode);
1690 if (mode == SLP_SLEEP) {
1691 pp = hostif_generic_request(sizeof(*pp), HIF_SLEEP_REQ);
1695 /* send to device request */
1696 ps_confirm_wait_inc(priv);
1697 ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL,
1699 } else if (mode == SLP_ACTIVE) {
1700 atomic_set(&priv->sleepstatus.wakeup_request, 1);
1701 queue_delayed_work(priv->wq, &priv->rw_dwork, 1);
1703 DPRINTK(3, "invalid mode %ld\n", (long)mode);
1709 void hostif_bss_scan_request(struct ks_wlan_private *priv,
1710 unsigned long scan_type, uint8_t *scan_ssid,
1711 uint8_t scan_ssid_len)
1713 struct hostif_bss_scan_request_t *pp;
1717 pp = hostif_generic_request(sizeof(*pp), HIF_SCAN_REQ);
1721 pp->scan_type = scan_type;
1723 pp->ch_time_min = cpu_to_le32((uint32_t)110); /* default value */
1724 pp->ch_time_max = cpu_to_le32((uint32_t)130); /* default value */
1725 pp->channel_list.body[0] = 1;
1726 pp->channel_list.body[1] = 8;
1727 pp->channel_list.body[2] = 2;
1728 pp->channel_list.body[3] = 9;
1729 pp->channel_list.body[4] = 3;
1730 pp->channel_list.body[5] = 10;
1731 pp->channel_list.body[6] = 4;
1732 pp->channel_list.body[7] = 11;
1733 pp->channel_list.body[8] = 5;
1734 pp->channel_list.body[9] = 12;
1735 pp->channel_list.body[10] = 6;
1736 pp->channel_list.body[11] = 13;
1737 pp->channel_list.body[12] = 7;
1738 if (priv->reg.phy_type == D_11G_ONLY_MODE) {
1739 pp->channel_list.size = 13;
1741 pp->channel_list.body[13] = 14;
1742 pp->channel_list.size = 14;
1746 /* specified SSID SCAN */
1747 if (scan_ssid_len > 0 && scan_ssid_len <= 32) {
1748 pp->ssid.size = scan_ssid_len;
1749 memcpy(&pp->ssid.body[0], scan_ssid, scan_ssid_len);
1752 /* send to device request */
1753 ps_confirm_wait_inc(priv);
1754 ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL);
1756 priv->aplist.size = 0;
1757 priv->scan_ind_count = 0;
1761 void hostif_mic_failure_request(struct ks_wlan_private *priv,
1762 unsigned short failure_count,
1763 unsigned short timer)
1765 struct hostif_mic_failure_request_t *pp;
1767 DPRINTK(3, "count=%d :: timer=%d\n", failure_count, timer);
1769 pp = hostif_generic_request(sizeof(*pp), HIF_MIC_FAILURE_REQ);
1773 pp->failure_count = cpu_to_le16((uint16_t)failure_count);
1774 pp->timer = cpu_to_le16((uint16_t)timer);
1776 /* send to device request */
1777 ps_confirm_wait_inc(priv);
1778 ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL);
1781 /* Device I/O Receive indicate */
1782 static void devio_rec_ind(struct ks_wlan_private *priv, unsigned char *p,
1785 if (priv->device_open_status) {
1786 spin_lock(&priv->dev_read_lock); /* request spin lock */
1787 priv->dev_data[atomic_read(&priv->rec_count)] = p;
1788 priv->dev_size[atomic_read(&priv->rec_count)] = size;
1790 if (atomic_read(&priv->event_count) != DEVICE_STOCK_COUNT) {
1791 /* rx event count inc */
1792 atomic_inc(&priv->event_count);
1794 atomic_inc(&priv->rec_count);
1795 if (atomic_read(&priv->rec_count) == DEVICE_STOCK_COUNT)
1796 atomic_set(&priv->rec_count, 0);
1798 wake_up_interruptible_all(&priv->devread_wait);
1800 /* release spin lock */
1801 spin_unlock(&priv->dev_read_lock);
1805 void hostif_receive(struct ks_wlan_private *priv, unsigned char *p,
1810 devio_rec_ind(priv, p, size);
1813 priv->rx_size = size;
1815 if (get_WORD(priv) == priv->rx_size) { /* length check !! */
1816 hostif_event_check(priv); /* event check */
1821 void hostif_sme_set_wep(struct ks_wlan_private *priv, int type)
1826 case SME_WEP_INDEX_REQUEST:
1827 val = cpu_to_le32((uint32_t)(priv->reg.wep_index));
1828 hostif_mib_set_request(priv, DOT11_WEP_DEFAULT_KEY_ID,
1829 sizeof(val), MIB_VALUE_TYPE_INT, &val);
1831 case SME_WEP_KEY1_REQUEST:
1832 if (!priv->wpa.wpa_enabled)
1833 hostif_mib_set_request(priv,
1834 DOT11_WEP_DEFAULT_KEY_VALUE1,
1835 priv->reg.wep_key[0].size,
1836 MIB_VALUE_TYPE_OSTRING,
1837 &priv->reg.wep_key[0].val[0]);
1839 case SME_WEP_KEY2_REQUEST:
1840 if (!priv->wpa.wpa_enabled)
1841 hostif_mib_set_request(priv,
1842 DOT11_WEP_DEFAULT_KEY_VALUE2,
1843 priv->reg.wep_key[1].size,
1844 MIB_VALUE_TYPE_OSTRING,
1845 &priv->reg.wep_key[1].val[0]);
1847 case SME_WEP_KEY3_REQUEST:
1848 if (!priv->wpa.wpa_enabled)
1849 hostif_mib_set_request(priv,
1850 DOT11_WEP_DEFAULT_KEY_VALUE3,
1851 priv->reg.wep_key[2].size,
1852 MIB_VALUE_TYPE_OSTRING,
1853 &priv->reg.wep_key[2].val[0]);
1855 case SME_WEP_KEY4_REQUEST:
1856 if (!priv->wpa.wpa_enabled)
1857 hostif_mib_set_request(priv,
1858 DOT11_WEP_DEFAULT_KEY_VALUE4,
1859 priv->reg.wep_key[3].size,
1860 MIB_VALUE_TYPE_OSTRING,
1861 &priv->reg.wep_key[3].val[0]);
1863 case SME_WEP_FLAG_REQUEST:
1864 val = cpu_to_le32((uint32_t)(priv->reg.privacy_invoked));
1865 hostif_mib_set_request(priv, DOT11_PRIVACY_INVOKED,
1866 sizeof(val), MIB_VALUE_TYPE_BOOL, &val);
1871 struct wpa_suite_t {
1873 unsigned char suite[4][CIPHER_ID_LEN];
1878 __le16 rsn_capability;
1882 void hostif_sme_set_rsn(struct ks_wlan_private *priv, int type)
1884 struct wpa_suite_t wpa_suite;
1885 struct rsn_mode_t rsn_mode;
1888 memset(&wpa_suite, 0, sizeof(wpa_suite));
1891 case SME_RSN_UCAST_REQUEST:
1892 wpa_suite.size = cpu_to_le16((uint16_t)1);
1893 switch (priv->wpa.pairwise_suite) {
1894 case IW_AUTH_CIPHER_NONE:
1895 if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
1896 memcpy(&wpa_suite.suite[0][0],
1897 CIPHER_ID_WPA2_NONE, CIPHER_ID_LEN);
1899 memcpy(&wpa_suite.suite[0][0],
1900 CIPHER_ID_WPA_NONE, CIPHER_ID_LEN);
1902 case IW_AUTH_CIPHER_WEP40:
1903 if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
1904 memcpy(&wpa_suite.suite[0][0],
1905 CIPHER_ID_WPA2_WEP40, CIPHER_ID_LEN);
1907 memcpy(&wpa_suite.suite[0][0],
1908 CIPHER_ID_WPA_WEP40, CIPHER_ID_LEN);
1910 case IW_AUTH_CIPHER_TKIP:
1911 if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
1912 memcpy(&wpa_suite.suite[0][0],
1913 CIPHER_ID_WPA2_TKIP, CIPHER_ID_LEN);
1915 memcpy(&wpa_suite.suite[0][0],
1916 CIPHER_ID_WPA_TKIP, CIPHER_ID_LEN);
1918 case IW_AUTH_CIPHER_CCMP:
1919 if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
1920 memcpy(&wpa_suite.suite[0][0],
1921 CIPHER_ID_WPA2_CCMP, CIPHER_ID_LEN);
1923 memcpy(&wpa_suite.suite[0][0],
1924 CIPHER_ID_WPA_CCMP, CIPHER_ID_LEN);
1926 case IW_AUTH_CIPHER_WEP104:
1927 if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
1928 memcpy(&wpa_suite.suite[0][0],
1929 CIPHER_ID_WPA2_WEP104, CIPHER_ID_LEN);
1931 memcpy(&wpa_suite.suite[0][0],
1932 CIPHER_ID_WPA_WEP104, CIPHER_ID_LEN);
1936 hostif_mib_set_request(priv, DOT11_RSN_CONFIG_UNICAST_CIPHER,
1937 sizeof(wpa_suite.size) +
1939 le16_to_cpu(wpa_suite.size),
1940 MIB_VALUE_TYPE_OSTRING, &wpa_suite);
1942 case SME_RSN_MCAST_REQUEST:
1943 switch (priv->wpa.group_suite) {
1944 case IW_AUTH_CIPHER_NONE:
1945 if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
1946 memcpy(&wpa_suite.suite[0][0],
1947 CIPHER_ID_WPA2_NONE, CIPHER_ID_LEN);
1949 memcpy(&wpa_suite.suite[0][0],
1950 CIPHER_ID_WPA_NONE, CIPHER_ID_LEN);
1952 case IW_AUTH_CIPHER_WEP40:
1953 if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
1954 memcpy(&wpa_suite.suite[0][0],
1955 CIPHER_ID_WPA2_WEP40, CIPHER_ID_LEN);
1957 memcpy(&wpa_suite.suite[0][0],
1958 CIPHER_ID_WPA_WEP40, CIPHER_ID_LEN);
1960 case IW_AUTH_CIPHER_TKIP:
1961 if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
1962 memcpy(&wpa_suite.suite[0][0],
1963 CIPHER_ID_WPA2_TKIP, CIPHER_ID_LEN);
1965 memcpy(&wpa_suite.suite[0][0],
1966 CIPHER_ID_WPA_TKIP, CIPHER_ID_LEN);
1968 case IW_AUTH_CIPHER_CCMP:
1969 if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
1970 memcpy(&wpa_suite.suite[0][0],
1971 CIPHER_ID_WPA2_CCMP, CIPHER_ID_LEN);
1973 memcpy(&wpa_suite.suite[0][0],
1974 CIPHER_ID_WPA_CCMP, CIPHER_ID_LEN);
1976 case IW_AUTH_CIPHER_WEP104:
1977 if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
1978 memcpy(&wpa_suite.suite[0][0],
1979 CIPHER_ID_WPA2_WEP104, CIPHER_ID_LEN);
1981 memcpy(&wpa_suite.suite[0][0],
1982 CIPHER_ID_WPA_WEP104, CIPHER_ID_LEN);
1986 hostif_mib_set_request(priv, DOT11_RSN_CONFIG_MULTICAST_CIPHER,
1987 CIPHER_ID_LEN, MIB_VALUE_TYPE_OSTRING,
1988 &wpa_suite.suite[0][0]);
1990 case SME_RSN_AUTH_REQUEST:
1991 wpa_suite.size = cpu_to_le16((uint16_t)1);
1992 switch (priv->wpa.key_mgmt_suite) {
1993 case IW_AUTH_KEY_MGMT_802_1X:
1994 if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
1995 memcpy(&wpa_suite.suite[0][0],
1996 KEY_MGMT_ID_WPA2_1X, KEY_MGMT_ID_LEN);
1998 memcpy(&wpa_suite.suite[0][0],
1999 KEY_MGMT_ID_WPA_1X, KEY_MGMT_ID_LEN);
2001 case IW_AUTH_KEY_MGMT_PSK:
2002 if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
2003 memcpy(&wpa_suite.suite[0][0],
2004 KEY_MGMT_ID_WPA2_PSK, KEY_MGMT_ID_LEN);
2006 memcpy(&wpa_suite.suite[0][0],
2007 KEY_MGMT_ID_WPA_PSK, KEY_MGMT_ID_LEN);
2010 if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
2011 memcpy(&wpa_suite.suite[0][0],
2012 KEY_MGMT_ID_WPA2_NONE, KEY_MGMT_ID_LEN);
2014 memcpy(&wpa_suite.suite[0][0],
2015 KEY_MGMT_ID_WPA_NONE, KEY_MGMT_ID_LEN);
2018 if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
2019 memcpy(&wpa_suite.suite[0][0],
2020 KEY_MGMT_ID_WPA2_WPANONE,
2023 memcpy(&wpa_suite.suite[0][0],
2024 KEY_MGMT_ID_WPA_WPANONE,
2029 hostif_mib_set_request(priv, DOT11_RSN_CONFIG_AUTH_SUITE,
2030 sizeof(wpa_suite.size) +
2032 le16_to_cpu(wpa_suite.size),
2033 MIB_VALUE_TYPE_OSTRING, &wpa_suite);
2035 case SME_RSN_ENABLED_REQUEST:
2036 val = cpu_to_le32((uint32_t)(priv->wpa.rsn_enabled));
2037 hostif_mib_set_request(priv, DOT11_RSN_ENABLED,
2038 sizeof(val), MIB_VALUE_TYPE_BOOL, &val);
2040 case SME_RSN_MODE_REQUEST:
2041 if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) {
2043 cpu_to_le32((uint32_t)RSN_MODE_WPA2);
2044 rsn_mode.rsn_capability = cpu_to_le16((uint16_t)0);
2045 } else if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA) {
2047 cpu_to_le32((uint32_t)RSN_MODE_WPA);
2048 rsn_mode.rsn_capability = cpu_to_le16((uint16_t)0);
2051 cpu_to_le32((uint32_t)RSN_MODE_NONE);
2052 rsn_mode.rsn_capability = cpu_to_le16((uint16_t)0);
2054 hostif_mib_set_request(priv, LOCAL_RSN_MODE, sizeof(rsn_mode),
2055 MIB_VALUE_TYPE_OSTRING, &rsn_mode);
2061 void hostif_sme_mode_setup(struct ks_wlan_private *priv)
2063 unsigned char rate_size;
2064 unsigned char rate_octet[RATE_SET_MAX_SIZE];
2067 /* rate setting if rate segging is auto for changing phy_type (#94) */
2068 if (priv->reg.tx_rate == TX_RATE_FULL_AUTO) {
2069 if (priv->reg.phy_type == D_11B_ONLY_MODE) {
2070 priv->reg.rate_set.body[3] = TX_RATE_11M;
2071 priv->reg.rate_set.body[2] = TX_RATE_5M;
2072 priv->reg.rate_set.body[1] = TX_RATE_2M | BASIC_RATE;
2073 priv->reg.rate_set.body[0] = TX_RATE_1M | BASIC_RATE;
2074 priv->reg.rate_set.size = 4;
2075 } else { /* D_11G_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
2076 priv->reg.rate_set.body[11] = TX_RATE_54M;
2077 priv->reg.rate_set.body[10] = TX_RATE_48M;
2078 priv->reg.rate_set.body[9] = TX_RATE_36M;
2079 priv->reg.rate_set.body[8] = TX_RATE_18M;
2080 priv->reg.rate_set.body[7] = TX_RATE_9M;
2081 priv->reg.rate_set.body[6] = TX_RATE_24M | BASIC_RATE;
2082 priv->reg.rate_set.body[5] = TX_RATE_12M | BASIC_RATE;
2083 priv->reg.rate_set.body[4] = TX_RATE_6M | BASIC_RATE;
2084 priv->reg.rate_set.body[3] = TX_RATE_11M | BASIC_RATE;
2085 priv->reg.rate_set.body[2] = TX_RATE_5M | BASIC_RATE;
2086 priv->reg.rate_set.body[1] = TX_RATE_2M | BASIC_RATE;
2087 priv->reg.rate_set.body[0] = TX_RATE_1M | BASIC_RATE;
2088 priv->reg.rate_set.size = 12;
2092 /* rate mask by phy setting */
2093 if (priv->reg.phy_type == D_11B_ONLY_MODE) {
2094 for (i = 0; i < priv->reg.rate_set.size; i++) {
2095 if (!IS_11B_RATE(priv->reg.rate_set.body[i]))
2098 if ((priv->reg.rate_set.body[i] & RATE_MASK) >= TX_RATE_5M) {
2099 rate_octet[i] = priv->reg.rate_set.body[i] &
2102 rate_octet[i] = priv->reg.rate_set.body[i];
2106 } else { /* D_11G_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
2107 for (i = 0; i < priv->reg.rate_set.size; i++) {
2108 if (!IS_11BG_RATE(priv->reg.rate_set.body[i]))
2111 if (IS_OFDM_EXT_RATE(priv->reg.rate_set.body[i])) {
2112 rate_octet[i] = priv->reg.rate_set.body[i] &
2115 rate_octet[i] = priv->reg.rate_set.body[i];
2120 if (rate_size == 0) {
2121 if (priv->reg.phy_type == D_11G_ONLY_MODE)
2122 rate_octet[0] = TX_RATE_6M | BASIC_RATE;
2124 rate_octet[0] = TX_RATE_2M | BASIC_RATE;
2128 /* rate set update */
2129 priv->reg.rate_set.size = rate_size;
2130 memcpy(&priv->reg.rate_set.body[0], &rate_octet[0], rate_size);
2132 switch (priv->reg.operation_mode) {
2133 case MODE_PSEUDO_ADHOC:
2134 /* Pseudo Ad-Hoc mode */
2135 hostif_ps_adhoc_set_request(priv);
2137 case MODE_INFRASTRUCTURE:
2138 /* Infrastructure mode */
2139 if (!is_valid_ether_addr((u8 *)priv->reg.bssid)) {
2140 hostif_infrastructure_set_request(priv);
2142 hostif_infrastructure_set2_request(priv);
2144 "Infra bssid = %pM\n", priv->reg.bssid);
2148 /* IEEE802.11 Ad-Hoc mode */
2149 if (!is_valid_ether_addr((u8 *)priv->reg.bssid)) {
2150 hostif_adhoc_set_request(priv);
2152 hostif_adhoc_set2_request(priv);
2154 "Adhoc bssid = %pM\n", priv->reg.bssid);
2163 void hostif_sme_multicast_set(struct ks_wlan_private *priv)
2165 struct net_device *dev = priv->net_dev;
2167 struct netdev_hw_addr *ha;
2168 char set_address[NIC_MAX_MCAST_LIST * ETH_ALEN];
2174 spin_lock(&priv->multicast_spin);
2176 memset(set_address, 0, NIC_MAX_MCAST_LIST * ETH_ALEN);
2178 if (dev->flags & IFF_PROMISC) {
2179 filter_type = cpu_to_le32((uint32_t)MCAST_FILTER_PROMISC);
2180 hostif_mib_set_request(priv, LOCAL_MULTICAST_FILTER,
2181 sizeof(filter_type), MIB_VALUE_TYPE_BOOL,
2186 if ((netdev_mc_count(dev) > NIC_MAX_MCAST_LIST) ||
2187 (dev->flags & IFF_ALLMULTI)) {
2188 filter_type = cpu_to_le32((uint32_t)MCAST_FILTER_MCASTALL);
2189 hostif_mib_set_request(priv, LOCAL_MULTICAST_FILTER,
2190 sizeof(filter_type), MIB_VALUE_TYPE_BOOL,
2195 if (priv->sme_i.sme_flag & SME_MULTICAST) {
2196 mc_count = netdev_mc_count(dev);
2197 netdev_for_each_mc_addr(ha, dev) {
2198 memcpy(&set_address[i * ETH_ALEN], ha->addr, ETH_ALEN);
2201 priv->sme_i.sme_flag &= ~SME_MULTICAST;
2202 hostif_mib_set_request(priv, LOCAL_MULTICAST_ADDRESS,
2203 ETH_ALEN * mc_count,
2204 MIB_VALUE_TYPE_OSTRING,
2207 filter_type = cpu_to_le32((uint32_t)MCAST_FILTER_MCAST);
2208 priv->sme_i.sme_flag |= SME_MULTICAST;
2209 hostif_mib_set_request(priv, LOCAL_MULTICAST_FILTER,
2210 sizeof(filter_type), MIB_VALUE_TYPE_BOOL,
2215 spin_unlock(&priv->multicast_spin);
2219 void hostif_sme_power_mgmt_set(struct ks_wlan_private *priv)
2221 unsigned long mode, wake_up, receive_dtims;
2224 switch (priv->reg.power_mgmt) {
2225 case POWER_MGMT_ACTIVE:
2226 mode = POWER_ACTIVE;
2230 case POWER_MGMT_SAVE1:
2231 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
2236 mode = POWER_ACTIVE;
2241 case POWER_MGMT_SAVE2:
2242 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
2247 mode = POWER_ACTIVE;
2253 mode = POWER_ACTIVE;
2258 hostif_power_mgmt_request(priv, mode, wake_up, receive_dtims);
2262 void hostif_sme_sleep_set(struct ks_wlan_private *priv)
2265 switch (priv->sleep_mode) {
2267 hostif_sleep_request(priv, priv->sleep_mode);
2270 hostif_sleep_request(priv, priv->sleep_mode);
2278 void hostif_sme_set_key(struct ks_wlan_private *priv, int type)
2284 val = cpu_to_le32((uint32_t)(priv->reg.privacy_invoked));
2285 hostif_mib_set_request(priv, DOT11_PRIVACY_INVOKED,
2286 sizeof(val), MIB_VALUE_TYPE_BOOL, &val);
2289 val = cpu_to_le32((uint32_t)(priv->wpa.txkey));
2290 hostif_mib_set_request(priv, DOT11_WEP_DEFAULT_KEY_ID,
2291 sizeof(val), MIB_VALUE_TYPE_INT, &val);
2294 hostif_mib_set_request(priv, DOT11_WEP_DEFAULT_KEY_VALUE1,
2295 priv->wpa.key[0].key_len,
2296 MIB_VALUE_TYPE_OSTRING,
2297 &priv->wpa.key[0].key_val[0]);
2300 hostif_mib_set_request(priv, DOT11_WEP_DEFAULT_KEY_VALUE2,
2301 priv->wpa.key[1].key_len,
2302 MIB_VALUE_TYPE_OSTRING,
2303 &priv->wpa.key[1].key_val[0]);
2306 hostif_mib_set_request(priv, DOT11_WEP_DEFAULT_KEY_VALUE3,
2307 priv->wpa.key[2].key_len,
2308 MIB_VALUE_TYPE_OSTRING,
2309 &priv->wpa.key[2].key_val[0]);
2312 hostif_mib_set_request(priv, DOT11_WEP_DEFAULT_KEY_VALUE4,
2313 priv->wpa.key[3].key_len,
2314 MIB_VALUE_TYPE_OSTRING,
2315 &priv->wpa.key[3].key_val[0]);
2317 case SME_SET_PMK_TSC:
2318 hostif_mib_set_request(priv, DOT11_PMK_TSC,
2319 WPA_RX_SEQ_LEN, MIB_VALUE_TYPE_OSTRING,
2320 &priv->wpa.key[0].rx_seq[0]);
2322 case SME_SET_GMK1_TSC:
2323 hostif_mib_set_request(priv, DOT11_GMK1_TSC,
2324 WPA_RX_SEQ_LEN, MIB_VALUE_TYPE_OSTRING,
2325 &priv->wpa.key[1].rx_seq[0]);
2327 case SME_SET_GMK2_TSC:
2328 hostif_mib_set_request(priv, DOT11_GMK2_TSC,
2329 WPA_RX_SEQ_LEN, MIB_VALUE_TYPE_OSTRING,
2330 &priv->wpa.key[2].rx_seq[0]);
2336 void hostif_sme_set_pmksa(struct ks_wlan_private *priv)
2338 struct pmk_cache_t {
2342 u8 pmkid[IW_PMKID_LEN];
2343 } __packed list[PMK_LIST_MAX];
2344 } __packed pmkcache;
2348 DPRINTK(4, "pmklist.size=%d\n", priv->pmklist.size);
2350 list_for_each_entry(pmk, &priv->pmklist.head, list) {
2351 if (i < PMK_LIST_MAX) {
2352 memcpy(pmkcache.list[i].bssid, pmk->bssid, ETH_ALEN);
2353 memcpy(pmkcache.list[i].pmkid, pmk->pmkid,
2358 pmkcache.size = cpu_to_le16((uint16_t)(priv->pmklist.size));
2359 hostif_mib_set_request(priv, LOCAL_PMK,
2360 sizeof(priv->pmklist.size) + (ETH_ALEN +
2362 (priv->pmklist.size), MIB_VALUE_TYPE_OSTRING,
2368 void hostif_sme_execute(struct ks_wlan_private *priv, int event)
2372 DPRINTK(3, "event=%d\n", event);
2375 if (priv->dev_state == DEVICE_STATE_BOOT)
2376 hostif_mib_get_request(priv, DOT11_MAC_ADDRESS);
2378 case SME_MULTICAST_REQUEST:
2379 hostif_sme_multicast_set(priv);
2381 case SME_MACADDRESS_SET_REQUEST:
2382 hostif_mib_set_request(priv, LOCAL_CURRENTADDRESS, ETH_ALEN,
2383 MIB_VALUE_TYPE_OSTRING,
2384 &priv->eth_addr[0]);
2386 case SME_BSS_SCAN_REQUEST:
2387 hostif_bss_scan_request(priv, priv->reg.scan_type,
2388 priv->scan_ssid, priv->scan_ssid_len);
2390 case SME_POW_MNGMT_REQUEST:
2391 hostif_sme_power_mgmt_set(priv);
2393 case SME_PHY_INFO_REQUEST:
2394 hostif_phy_information_request(priv);
2396 case SME_MIC_FAILURE_REQUEST:
2397 if (priv->wpa.mic_failure.failure == 1) {
2398 hostif_mic_failure_request(priv,
2399 priv->wpa.mic_failure.failure - 1,
2401 } else if (priv->wpa.mic_failure.failure == 2) {
2402 hostif_mic_failure_request(priv,
2403 priv->wpa.mic_failure.failure - 1,
2404 priv->wpa.mic_failure.counter);
2406 DPRINTK(4, "SME_MIC_FAILURE_REQUEST: failure count=%u error?\n",
2407 priv->wpa.mic_failure.failure);
2410 case SME_MIC_FAILURE_CONFIRM:
2411 if (priv->wpa.mic_failure.failure == 2) {
2412 if (priv->wpa.mic_failure.stop)
2413 priv->wpa.mic_failure.stop = 0;
2414 priv->wpa.mic_failure.failure = 0;
2415 hostif_start_request(priv, priv->reg.operation_mode);
2418 case SME_GET_MAC_ADDRESS:
2419 if (priv->dev_state == DEVICE_STATE_BOOT)
2420 hostif_mib_get_request(priv, DOT11_PRODUCT_VERSION);
2422 case SME_GET_PRODUCT_VERSION:
2423 if (priv->dev_state == DEVICE_STATE_BOOT)
2424 priv->dev_state = DEVICE_STATE_PREINIT;
2426 case SME_STOP_REQUEST:
2427 hostif_stop_request(priv);
2429 case SME_RTS_THRESHOLD_REQUEST:
2430 val = cpu_to_le32((uint32_t)(priv->reg.rts));
2431 hostif_mib_set_request(priv, DOT11_RTS_THRESHOLD,
2432 sizeof(val), MIB_VALUE_TYPE_INT, &val);
2434 case SME_FRAGMENTATION_THRESHOLD_REQUEST:
2435 val = cpu_to_le32((uint32_t)(priv->reg.fragment));
2436 hostif_mib_set_request(priv, DOT11_FRAGMENTATION_THRESHOLD,
2437 sizeof(val), MIB_VALUE_TYPE_INT, &val);
2439 case SME_WEP_INDEX_REQUEST:
2440 case SME_WEP_KEY1_REQUEST:
2441 case SME_WEP_KEY2_REQUEST:
2442 case SME_WEP_KEY3_REQUEST:
2443 case SME_WEP_KEY4_REQUEST:
2444 case SME_WEP_FLAG_REQUEST:
2445 hostif_sme_set_wep(priv, event);
2447 case SME_RSN_UCAST_REQUEST:
2448 case SME_RSN_MCAST_REQUEST:
2449 case SME_RSN_AUTH_REQUEST:
2450 case SME_RSN_ENABLED_REQUEST:
2451 case SME_RSN_MODE_REQUEST:
2452 hostif_sme_set_rsn(priv, event);
2460 case SME_SET_PMK_TSC:
2461 case SME_SET_GMK1_TSC:
2462 case SME_SET_GMK2_TSC:
2463 hostif_sme_set_key(priv, event);
2466 hostif_sme_set_pmksa(priv);
2469 case SME_WPS_ENABLE_REQUEST:
2470 hostif_mib_set_request(priv, LOCAL_WPS_ENABLE,
2471 sizeof(priv->wps.wps_enabled),
2473 &priv->wps.wps_enabled);
2475 case SME_WPS_PROBE_REQUEST:
2476 hostif_mib_set_request(priv, LOCAL_WPS_PROBE_REQ,
2478 MIB_VALUE_TYPE_OSTRING, priv->wps.ie);
2481 case SME_MODE_SET_REQUEST:
2482 hostif_sme_mode_setup(priv);
2485 hostif_mib_set_request(priv, LOCAL_GAIN,
2487 MIB_VALUE_TYPE_OSTRING, &priv->gain);
2490 hostif_mib_get_request(priv, LOCAL_GAIN);
2492 case SME_GET_EEPROM_CKSUM:
2493 priv->eeprom_checksum = EEPROM_FW_NOT_SUPPORT; /* initialize */
2494 hostif_mib_get_request(priv, LOCAL_EEPROM_SUM);
2496 case SME_START_REQUEST:
2497 hostif_start_request(priv, priv->reg.operation_mode);
2499 case SME_START_CONFIRM:
2500 /* for power save */
2501 atomic_set(&priv->psstatus.snooze_guard, 0);
2502 atomic_set(&priv->psstatus.confirm_wait, 0);
2503 if (priv->dev_state == DEVICE_STATE_PREINIT)
2504 priv->dev_state = DEVICE_STATE_INIT;
2505 /* wake_up_interruptible_all(&priv->confirm_wait); */
2506 complete(&priv->confirm_wait);
2508 case SME_SLEEP_REQUEST:
2509 hostif_sme_sleep_set(priv);
2511 case SME_SET_REGION:
2512 val = cpu_to_le32((uint32_t)(priv->region));
2513 hostif_mib_set_request(priv, LOCAL_REGION,
2514 sizeof(val), MIB_VALUE_TYPE_INT, &val);
2516 case SME_MULTICAST_CONFIRM:
2517 case SME_BSS_SCAN_CONFIRM:
2518 case SME_POW_MNGMT_CONFIRM:
2519 case SME_PHY_INFO_CONFIRM:
2520 case SME_STOP_CONFIRM:
2521 case SME_RTS_THRESHOLD_CONFIRM:
2522 case SME_FRAGMENTATION_THRESHOLD_CONFIRM:
2523 case SME_WEP_INDEX_CONFIRM:
2524 case SME_WEP_KEY1_CONFIRM:
2525 case SME_WEP_KEY2_CONFIRM:
2526 case SME_WEP_KEY3_CONFIRM:
2527 case SME_WEP_KEY4_CONFIRM:
2528 case SME_WEP_FLAG_CONFIRM:
2529 case SME_RSN_UCAST_CONFIRM:
2530 case SME_RSN_MCAST_CONFIRM:
2531 case SME_RSN_AUTH_CONFIRM:
2532 case SME_RSN_ENABLED_CONFIRM:
2533 case SME_RSN_MODE_CONFIRM:
2534 case SME_MODE_SET_CONFIRM:
2543 void hostif_sme_task(unsigned long dev)
2545 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev;
2549 if (priv->dev_state < DEVICE_STATE_BOOT)
2552 if (cnt_smeqbody(priv) <= 0)
2555 hostif_sme_execute(priv, priv->sme_i.event_buff[priv->sme_i.qhead]);
2557 if (cnt_smeqbody(priv) > 0)
2558 tasklet_schedule(&priv->sme_task);
2561 /* send to Station Management Entity module */
2562 void hostif_sme_enqueue(struct ks_wlan_private *priv, unsigned short event)
2566 /* enqueue sme event */
2567 if (cnt_smeqbody(priv) < (SME_EVENT_BUFF_SIZE - 1)) {
2568 priv->sme_i.event_buff[priv->sme_i.qtail] = event;
2570 #ifdef KS_WLAN_DEBUG
2571 if (priv->sme_i.max_event_count < cnt_smeqbody(priv))
2572 priv->sme_i.max_event_count = cnt_smeqbody(priv);
2573 #endif /* KS_WLAN_DEBUG */
2575 /* in case of buffer overflow */
2576 netdev_err(priv->net_dev, "sme queue buffer overflow\n");
2579 tasklet_schedule(&priv->sme_task);
2582 int hostif_init(struct ks_wlan_private *priv)
2588 priv->aplist.size = 0;
2589 for (i = 0; i < LOCAL_APLIST_MAX; i++)
2590 memset(&priv->aplist.ap[i], 0, sizeof(struct local_ap_t));
2591 priv->infra_status = 0;
2592 priv->current_rate = 4;
2593 priv->connect_status = DISCONNECT_STATUS;
2595 spin_lock_init(&priv->multicast_spin);
2597 spin_lock_init(&priv->dev_read_lock);
2598 init_waitqueue_head(&priv->devread_wait);
2599 priv->dev_count = 0;
2600 atomic_set(&priv->event_count, 0);
2601 atomic_set(&priv->rec_count, 0);
2603 /* for power save */
2604 atomic_set(&priv->psstatus.status, PS_NONE);
2605 atomic_set(&priv->psstatus.confirm_wait, 0);
2606 atomic_set(&priv->psstatus.snooze_guard, 0);
2607 init_completion(&priv->psstatus.wakeup_wait);
2608 INIT_WORK(&priv->wakeup_work, ks_wlan_hw_wakeup_task);
2611 memset(&priv->wpa, 0, sizeof(priv->wpa));
2612 priv->wpa.rsn_enabled = 0;
2613 priv->wpa.mic_failure.failure = 0;
2614 priv->wpa.mic_failure.last_failure_time = 0;
2615 priv->wpa.mic_failure.stop = 0;
2616 memset(&priv->pmklist, 0, sizeof(priv->pmklist));
2617 INIT_LIST_HEAD(&priv->pmklist.head);
2618 for (i = 0; i < PMK_LIST_MAX; i++)
2619 INIT_LIST_HEAD(&priv->pmklist.pmk[i].list);
2621 priv->sme_i.sme_status = SME_IDLE;
2622 priv->sme_i.qhead = 0;
2623 priv->sme_i.qtail = 0;
2624 #ifdef KS_WLAN_DEBUG
2625 priv->sme_i.max_event_count = 0;
2627 spin_lock_init(&priv->sme_i.sme_spin);
2628 priv->sme_i.sme_flag = 0;
2630 tasklet_init(&priv->sme_task, hostif_sme_task, (unsigned long)priv);
2635 void hostif_exit(struct ks_wlan_private *priv)
2637 tasklet_kill(&priv->sme_task);