1 // SPDX-License-Identifier: GPL-2.0
3 * Driver for KeyStream wireless LAN cards.
5 * Copyright (C) 2005-2008 KeyStream Corp.
6 * Copyright (C) 2009 Renesas Technology Corp.
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"
15 #include "michael_mic.h"
16 #include "ks_hostif.h"
18 static inline void inc_smeqhead(struct ks_wlan_private *priv)
20 priv->sme_i.qhead = (priv->sme_i.qhead + 1) % SME_EVENT_BUFF_SIZE;
23 static inline void inc_smeqtail(struct ks_wlan_private *priv)
25 priv->sme_i.qtail = (priv->sme_i.qtail + 1) % SME_EVENT_BUFF_SIZE;
28 static inline unsigned int cnt_smeqbody(struct ks_wlan_private *priv)
30 return CIRC_CNT_TO_END(priv->sme_i.qhead, priv->sme_i.qtail,
34 static inline u8 get_byte(struct ks_wlan_private *priv)
38 data = *(priv->rxp)++;
39 /* length check in advance ! */
44 static inline u16 get_word(struct ks_wlan_private *priv)
48 data = (get_byte(priv) & 0xff);
49 data |= ((get_byte(priv) << 8) & 0xff00);
53 static inline u32 get_dword(struct ks_wlan_private *priv)
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);
64 static void ks_wlan_hw_wakeup_task(struct work_struct *work)
66 struct ks_wlan_private *priv;
70 priv = container_of(work, struct ks_wlan_private, wakeup_work);
71 ps_status = atomic_read(&priv->psstatus.status);
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));
79 netdev_dbg(priv->net_dev, "wake up timeout or interrupted !!!\n");
80 schedule_work(&priv->wakeup_work);
86 if (atomic_read(&priv->sme_task.count) > 0)
87 tasklet_enable(&priv->sme_task);
90 static void ks_wlan_do_power_save(struct ks_wlan_private *priv)
92 if (is_connect_status(priv->connect_status))
93 hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
95 priv->dev_state = DEVICE_STATE_READY;
99 int get_current_ap(struct ks_wlan_private *priv, struct link_ap_info *ap_info)
102 union iwreq_data wrqu;
103 struct net_device *netdev = priv->net_dev;
106 ap = &priv->current_ap;
108 if (is_disconnect_status(priv->connect_status)) {
109 memset(ap, 0, sizeof(struct local_ap));
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;
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);
150 wrqu.data.length = 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);
160 netdev_dbg(priv->net_dev, "Link AP\n"
161 "- bssid=%02X:%02X:%02X:%02X:%02X:%02X\n"
163 "- rate_set=%02X,%02X,%02X,%02X,%02X,%02X,%02X,%02X\n"
167 "- capability=%04X\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],
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);
186 static u8 read_ie(unsigned char *bp, u8 max, u8 *body)
188 u8 size = (*(bp + 1) <= max) ? *(bp + 1) : max;
190 memcpy(body, bp + 2, size);
196 int get_ap_information(struct ks_wlan_private *priv, struct ap_info *ap_info,
202 memset(ap, 0, sizeof(struct local_ap));
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;
212 bsize = le16_to_cpu(ap_info->body_size);
215 while (bsize > offset) {
216 switch (*bp) { /* Information Element ID */
218 ap->ssid.size = read_ie(bp, IEEE80211_MAX_SSID_LEN,
221 case WLAN_EID_SUPP_RATES:
222 case WLAN_EID_EXT_SUPP_RATES:
223 if ((*(bp + 1) + ap->rate_set.size) <=
225 memcpy(&ap->rate_set.body[ap->rate_set.size],
227 ap->rate_set.size += *(bp + 1);
229 memcpy(&ap->rate_set.body[ap->rate_set.size],
231 RATE_SET_MAX_SIZE - ap->rate_set.size);
233 (RATE_SET_MAX_SIZE - ap->rate_set.size);
238 ap->rsn_ie.size = read_ie(bp, RSN_IE_BODY_MAX,
241 case WLAN_EID_VENDOR_SPECIFIC: /* WPA */
243 if (memcmp(bp + 2, CIPHER_ID_WPA_WEP40, 4) == 0) {
245 ap->wpa_ie.size = read_ie(bp, RSN_IE_BODY_MAX,
249 case WLAN_EID_DS_PARAMS:
250 case WLAN_EID_FH_PARAMS:
251 case WLAN_EID_CF_PARAMS:
253 case WLAN_EID_IBSS_PARAMS:
254 case WLAN_EID_COUNTRY:
255 case WLAN_EID_ERP_INFO:
258 netdev_err(priv->net_dev,
259 "unknown Element ID=%d\n", *bp);
263 offset += 2; /* id & size field */
264 offset += *(bp + 1); /* +size offset */
265 bp += (*(bp + 1) + 2); /* pointer update */
272 int hostif_data_indication_wpa(struct ks_wlan_private *priv,
273 unsigned short auth_type)
275 struct ether_hdr *eth_hdr;
276 unsigned short eth_proto;
277 unsigned char recv_mic[8];
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];
286 eth_hdr = (struct ether_hdr *)(priv->rxp);
287 eth_proto = ntohs(eth_hdr->h_proto);
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++;
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)) &&
301 netdev_dbg(priv->net_dev, "TKIP: protocol=%04X: size=%u\n",
302 eth_proto, priv->rx_size);
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);
311 if (memcmp(michael_mic.result, recv_mic, 8) != 0) {
313 mic_failure = &priv->wpa.mic_failure;
315 if (mic_failure->last_failure_time &&
316 (now - mic_failure->last_failure_time) / HZ >= 60) {
317 mic_failure->failure = 0;
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 (uint16_t)((now - mic_failure->last_failure_time) / HZ);
328 if (!mic_failure->counter)
329 mic_failure->counter = 1;
331 priv->wpa.mic_failure.last_failure_time = now;
333 /* needed parameters: count, keyid, key type, TSC */
335 "MLME-MICHAELMICFAILURE.indication(keyid=%d %scast addr=%pM)",
337 eth_hdr->h_dest[0] & 0x01 ? "broad" : "uni",
339 memset(&wrqu, 0, sizeof(wrqu));
340 wrqu.data.length = strlen(buf);
341 wireless_send_event(priv->net_dev, IWEVCUSTOM, &wrqu,
350 void hostif_data_indication(struct ks_wlan_private *priv)
352 unsigned int rx_ind_size; /* indicate data size */
355 unsigned char temp[256];
356 struct ether_hdr *eth_hdr;
357 unsigned short eth_proto;
358 struct ieee802_1x_hdr *aa1x_hdr;
362 /* min length check */
363 if (priv->rx_size <= ETH_HLEN) {
364 priv->nstats.rx_errors++;
368 auth_type = get_word(priv); /* AuthType */
369 get_word(priv); /* Reserve Area */
371 eth_hdr = (struct ether_hdr *)(priv->rxp);
372 eth_proto = ntohs(eth_hdr->h_proto);
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++;
387 if (auth_type != TYPE_DATA && priv->wpa.rsn_enabled) {
388 ret = hostif_data_indication_wpa(priv, auth_type);
393 if ((priv->connect_status & FORCE_DISCONNECT) ||
394 priv->wpa.mic_failure.failure == 2) {
398 /* check 13th byte at rx data */
399 switch (*(priv->rxp + 12)) {
401 rx_ind_size = priv->rx_size - 6;
402 skb = dev_alloc_skb(rx_ind_size);
404 priv->nstats.rx_dropped++;
407 netdev_dbg(priv->net_dev, "SNAP, rx_ind_size = %d\n",
411 skb_put_data(skb, priv->rxp, size);
413 /* (SNAP+UI..) skip */
415 size = rx_ind_size - (ETH_ALEN * 2);
416 skb_put_data(skb, ð_hdr->h_proto, size);
418 aa1x_hdr = (struct ieee802_1x_hdr *)(priv->rxp + ETHER_HDR_SIZE);
420 case LLC_SAP_NETBEUI:
421 rx_ind_size = (priv->rx_size + 2);
422 skb = dev_alloc_skb(rx_ind_size);
424 priv->nstats.rx_dropped++;
427 netdev_dbg(priv->net_dev, "NETBEUI/NetBIOS rx_ind_size=%d\n",
430 /* 8802/FDDI MAC copy */
431 skb_put_data(skb, priv->rxp, 12);
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);
438 /* copy after Type */
439 skb_put_data(skb, priv->rxp + 12, rx_ind_size - 14);
441 aa1x_hdr = (struct ieee802_1x_hdr *)(priv->rxp + 14);
443 default: /* other rx data */
444 netdev_err(priv->net_dev, "invalid data format\n");
445 priv->nstats.rx_errors++;
449 if (aa1x_hdr->type == IEEE802_1X_TYPE_EAPOL_KEY &&
450 priv->wpa.rsn_enabled)
451 atomic_set(&priv->psstatus.snooze_guard, 1);
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;
462 void hostif_mib_get_confirm(struct ks_wlan_private *priv)
464 struct net_device *dev = priv->net_dev;
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);
476 netdev_err(priv->net_dev, "attribute=%08X, status=%08X\n",
477 mib_attribute, mib_status);
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);
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);
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);
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");
512 priv->eeprom_checksum = (priv->eeprom_sum.type == 0) ?
513 EEPROM_CHECKSUM_NONE :
514 (priv->eeprom_sum.result == 0) ?
515 EEPROM_NG : EEPROM_OK;
518 netdev_err(priv->net_dev, "mib_attribute=%08x\n",
519 (unsigned int)mib_attribute);
525 void hostif_mib_set_confirm(struct ks_wlan_private *priv)
530 mib_status = get_dword(priv);
531 mib_attribute = get_dword(priv);
534 /* in case of error */
535 netdev_err(priv->net_dev, "error :: attribute=%08X, status=%08X\n",
536 mib_attribute, mib_status);
539 switch (mib_attribute) {
540 case DOT11_RTS_THRESHOLD:
541 hostif_sme_enqueue(priv, SME_RTS_THRESHOLD_CONFIRM);
543 case DOT11_FRAGMENTATION_THRESHOLD:
544 hostif_sme_enqueue(priv, SME_FRAGMENTATION_THRESHOLD_CONFIRM);
546 case DOT11_WEP_DEFAULT_KEY_ID:
547 if (!priv->wpa.wpa_enabled)
548 hostif_sme_enqueue(priv, SME_WEP_INDEX_CONFIRM);
550 case DOT11_WEP_DEFAULT_KEY_VALUE1:
551 if (priv->wpa.rsn_enabled)
552 hostif_sme_enqueue(priv, SME_SET_PMK_TSC);
554 hostif_sme_enqueue(priv, SME_WEP_KEY1_CONFIRM);
556 case DOT11_WEP_DEFAULT_KEY_VALUE2:
557 if (priv->wpa.rsn_enabled)
558 hostif_sme_enqueue(priv, SME_SET_GMK1_TSC);
560 hostif_sme_enqueue(priv, SME_WEP_KEY2_CONFIRM);
562 case DOT11_WEP_DEFAULT_KEY_VALUE3:
563 if (priv->wpa.rsn_enabled)
564 hostif_sme_enqueue(priv, SME_SET_GMK2_TSC);
566 hostif_sme_enqueue(priv, SME_WEP_KEY3_CONFIRM);
568 case DOT11_WEP_DEFAULT_KEY_VALUE4:
569 if (!priv->wpa.rsn_enabled)
570 hostif_sme_enqueue(priv, SME_WEP_KEY4_CONFIRM);
572 case DOT11_PRIVACY_INVOKED:
573 if (!priv->wpa.rsn_enabled)
574 hostif_sme_enqueue(priv, SME_WEP_FLAG_CONFIRM);
576 case DOT11_RSN_ENABLED:
577 hostif_sme_enqueue(priv, SME_RSN_ENABLED_CONFIRM);
580 hostif_sme_enqueue(priv, SME_RSN_MODE_CONFIRM);
582 case LOCAL_MULTICAST_ADDRESS:
583 hostif_sme_enqueue(priv, SME_MULTICAST_REQUEST);
585 case LOCAL_MULTICAST_FILTER:
586 hostif_sme_enqueue(priv, SME_MULTICAST_CONFIRM);
588 case LOCAL_CURRENTADDRESS:
589 priv->mac_address_valid = true;
591 case DOT11_RSN_CONFIG_MULTICAST_CIPHER:
592 hostif_sme_enqueue(priv, SME_RSN_MCAST_CONFIRM);
594 case DOT11_RSN_CONFIG_UNICAST_CIPHER:
595 hostif_sme_enqueue(priv, SME_RSN_UCAST_CONFIRM);
597 case DOT11_RSN_CONFIG_AUTH_SUITE:
598 hostif_sme_enqueue(priv, SME_RSN_AUTH_CONFIRM);
601 if (atomic_read(&priv->psstatus.snooze_guard))
602 atomic_set(&priv->psstatus.snooze_guard, 0);
605 if (atomic_read(&priv->psstatus.snooze_guard))
606 atomic_set(&priv->psstatus.snooze_guard, 0);
611 case LOCAL_WPS_ENABLE:
612 case LOCAL_WPS_PROBE_REQ:
620 void hostif_power_mgmt_confirm(struct ks_wlan_private *priv)
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);
628 priv->dev_state = DEVICE_STATE_READY;
633 void hostif_sleep_confirm(struct ks_wlan_private *priv)
635 atomic_set(&priv->sleepstatus.doze_request, 1);
636 queue_delayed_work(priv->wq, &priv->rw_dwork, 1);
640 void hostif_start_confirm(struct ks_wlan_private *priv)
642 union iwreq_data wrqu;
644 wrqu.data.length = 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);
651 netdev_dbg(priv->net_dev, " scan_ind_count=%d\n", priv->scan_ind_count);
652 hostif_sme_enqueue(priv, SME_START_CONFIRM);
656 void hostif_connect_indication(struct ks_wlan_private *priv)
658 unsigned short 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;
664 connect_code = get_word(priv);
666 switch (connect_code) {
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;
673 case RESULT_DISCONNECT:
674 netif_carrier_off(netdev);
675 tmp = FORCE_DISCONNECT & priv->connect_status;
676 priv->connect_status = tmp + DISCONNECT_STATUS;
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;
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)) {
691 atomic_set(&priv->psstatus.snooze_guard, 0);
692 atomic_set(&priv->psstatus.confirm_wait, 0);
694 ks_wlan_do_power_save(priv);
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);
706 priv->scan_ind_count = 0;
710 void hostif_scan_indication(struct ks_wlan_private *priv)
713 struct ap_info *ap_info;
715 netdev_dbg(priv->net_dev,
716 "scan_ind_count = %d\n", priv->scan_ind_count);
717 ap_info = (struct ap_info *)(priv->rxp);
719 if (priv->scan_ind_count) {
721 for (i = 0; i < priv->aplist.size; i++) {
722 u8 *bssid = priv->aplist.ap[i].bssid;
724 if (ether_addr_equal(ap_info->bssid, bssid))
727 if (ap_info->frame_type == IEEE80211_STYPE_PROBE_RESP)
728 get_ap_information(priv, ap_info,
729 &priv->aplist.ap[i]);
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;
741 netdev_dbg(priv->net_dev, " count over :: scan_ind_count=%d\n",
742 priv->scan_ind_count);
747 void hostif_stop_confirm(struct ks_wlan_private *priv)
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;
754 if (priv->dev_state == DEVICE_STATE_SLEEP)
755 priv->dev_state = DEVICE_STATE_READY;
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");
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);
773 priv->scan_ind_count = 0;
776 hostif_sme_enqueue(priv, SME_STOP_CONFIRM);
780 void hostif_ps_adhoc_set_confirm(struct ks_wlan_private *priv)
782 priv->infra_status = 0; /* infrastructure mode cancel */
783 hostif_sme_enqueue(priv, SME_MODE_SET_CONFIRM);
787 void hostif_infrastructure_set_confirm(struct ks_wlan_private *priv)
791 result_code = get_word(priv);
792 priv->infra_status = 1; /* infrastructure mode set */
793 hostif_sme_enqueue(priv, SME_MODE_SET_CONFIRM);
797 void hostif_adhoc_set_confirm(struct ks_wlan_private *priv)
799 priv->infra_status = 1; /* infrastructure mode set */
800 hostif_sme_enqueue(priv, SME_MODE_SET_CONFIRM);
804 void hostif_associate_indication(struct ks_wlan_private *priv)
806 struct association_request *assoc_req;
807 struct association_response *assoc_resp;
809 union iwreq_data wrqu;
810 char buf[IW_CUSTOM_MAX];
811 char *pbuf = &buf[0];
814 static const char associnfo_leader0[] = "ASSOCINFO(ReqIEs=";
815 static const char associnfo_leader1[] = " RespIEs=";
817 assoc_req = (struct association_request *)(priv->rxp);
818 assoc_resp = (struct association_response *)(assoc_req + 1);
819 pb = (unsigned char *)(assoc_resp + 1);
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;
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;
830 memcpy(pbuf, associnfo_leader1, sizeof(associnfo_leader1) - 1);
831 wrqu.data.length += sizeof(associnfo_leader1) - 1;
832 pbuf += sizeof(associnfo_leader1) - 1;
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;
839 pbuf += sprintf(pbuf, ")");
840 wrqu.data.length += 1;
842 wireless_send_event(priv->net_dev, IWEVCUSTOM, &wrqu, buf);
846 void hostif_bss_scan_confirm(struct ks_wlan_private *priv)
848 unsigned int result_code;
849 struct net_device *dev = priv->net_dev;
850 union iwreq_data wrqu;
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);
856 priv->sme_i.sme_flag &= ~SME_AP_SCAN;
857 hostif_sme_enqueue(priv, SME_BSS_SCAN_CONFIRM);
859 wrqu.data.length = 0;
861 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
862 priv->scan_ind_count = 0;
866 void hostif_phy_information_confirm(struct ks_wlan_private *priv)
868 struct iw_statistics *wstats = &priv->wstats;
869 unsigned char rssi, signal, noise;
870 unsigned char link_speed;
871 unsigned int transmitted_frame_count, received_fragment_count;
872 unsigned int failed_count, fcs_error_count;
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);
883 netdev_dbg(priv->net_dev, "phyinfo confirm rssi=%d signal=%d\n",
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;
891 netdev_dbg(priv->net_dev, "\n rssi=%u\n"
893 " link_speed=%ux500Kbps\n"
894 " transmitted_frame_count=%u\n"
895 " received_fragment_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);
905 void hostif_mic_failure_confirm(struct ks_wlan_private *priv)
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);
913 void hostif_event_check(struct ks_wlan_private *priv)
917 event = get_word(priv);
920 hostif_data_indication(priv);
922 case HIF_MIB_GET_CONF:
923 hostif_mib_get_confirm(priv);
925 case HIF_MIB_SET_CONF:
926 hostif_mib_set_confirm(priv);
928 case HIF_POWER_MGMT_CONF:
929 hostif_power_mgmt_confirm(priv);
932 hostif_sleep_confirm(priv);
935 hostif_start_confirm(priv);
937 case HIF_CONNECT_IND:
938 hostif_connect_indication(priv);
941 hostif_stop_confirm(priv);
943 case HIF_PS_ADH_SET_CONF:
944 hostif_ps_adhoc_set_confirm(priv);
946 case HIF_INFRA_SET_CONF:
947 case HIF_INFRA_SET2_CONF:
948 hostif_infrastructure_set_confirm(priv);
950 case HIF_ADH_SET_CONF:
951 case HIF_ADH_SET2_CONF:
952 hostif_adhoc_set_confirm(priv);
954 case HIF_ASSOC_INFO_IND:
955 hostif_associate_indication(priv);
957 case HIF_MIC_FAILURE_CONF:
958 hostif_mic_failure_confirm(priv);
961 hostif_bss_scan_confirm(priv);
963 case HIF_PHY_INFO_CONF:
964 case HIF_PHY_INFO_IND:
965 hostif_phy_information_confirm(priv);
968 hostif_scan_indication(priv);
970 case HIF_AP_SET_CONF:
972 netdev_err(priv->net_dev, "undefined event[%04X]\n", event);
973 /* wake_up_all(&priv->confirm_wait); */
974 complete(&priv->confirm_wait);
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;
983 /* allocate size bytes, set header size and event */
984 static void *hostif_generic_request(size_t size, int event)
986 struct hostif_hdr *p;
988 p = kzalloc(hif_align_size(size), GFP_ATOMIC);
992 p->size = cpu_to_le16((u16)(size - sizeof(p->size)));
993 p->event = cpu_to_le16(event);
998 int hostif_data_request(struct ks_wlan_private *priv, struct sk_buff *skb)
1000 unsigned int skb_len = 0;
1001 unsigned char *buffer = NULL;
1002 unsigned int length = 0;
1003 struct hostif_data_request *pp;
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;
1017 if (skb_len > ETH_FRAME_LEN) {
1018 netdev_err(priv->net_dev, "bad length skb_len=%d\n", skb_len);
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);
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);
1040 size = sizeof(*pp) + 6 + skb_len + 8;
1041 pp = kmalloc(hif_align_size(size), GFP_ATOMIC);
1047 p = (unsigned char *)pp->data;
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",
1062 /* dest and src MAC address copy */
1063 size = ETH_ALEN * 2;
1064 memcpy(p, buffer, size);
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") */
1081 /* Length(2 byte) delete */
1088 memcpy(p, buffer, length);
1093 eth_hdr = (struct ether_hdr *)&pp->data[0];
1094 eth_proto = ntohs(eth_hdr->h_proto);
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);
1106 if (priv->wpa.rsn_enabled && priv->wpa.key[0].key_len) {
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((uint16_t)TYPE_AUTH);
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);
1124 cpu_to_le16((uint16_t)TYPE_DATA);
1126 } else if (priv->wpa.pairwise_suite ==
1127 IW_AUTH_CIPHER_CCMP) {
1129 cpu_to_le16((uint16_t)TYPE_DATA);
1133 if (eth_proto == ETH_P_PAE)
1134 pp->auth_type = cpu_to_le16((uint16_t)TYPE_AUTH);
1136 pp->auth_type = cpu_to_le16((uint16_t)TYPE_DATA);
1139 /* header value set */
1141 cpu_to_le16((uint16_t)
1142 (sizeof(*pp) - sizeof(pp->header.size) + skb_len));
1143 pp->header.event = cpu_to_le16((uint16_t)HIF_DATA_REQ);
1146 result = ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp) + skb_len),
1147 send_packet_complete, skb);
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);
1158 if (priv->wpa.mic_failure.failure == 2)
1159 priv->wpa.mic_failure.stop = 1;
1172 static inline void ps_confirm_wait_inc(struct ks_wlan_private *priv)
1174 if (atomic_read(&priv->psstatus.status) > PS_ACTIVE_SET)
1175 atomic_inc(&priv->psstatus.confirm_wait);
1178 static inline void send_request_to_device(struct ks_wlan_private *priv,
1179 void *data, size_t size)
1181 ps_confirm_wait_inc(priv);
1182 ks_wlan_hw_tx(priv, data, size, NULL, NULL);
1186 void hostif_mib_get_request(struct ks_wlan_private *priv,
1187 unsigned long mib_attribute)
1189 struct hostif_mib_get_request *pp;
1191 pp = hostif_generic_request(sizeof(*pp), HIF_MIB_GET_REQ);
1195 pp->mib_attribute = cpu_to_le32((uint32_t)mib_attribute);
1197 send_request_to_device(priv, pp, hif_align_size(sizeof(*pp)));
1200 static void hostif_mib_set_request(struct ks_wlan_private *priv,
1201 enum mib_attribute attr,
1202 enum mib_data_type type,
1203 void *data, size_t size)
1205 struct hostif_mib_set_request_t *pp;
1207 if (priv->dev_state < DEVICE_STATE_BOOT)
1210 pp = hostif_generic_request(sizeof(*pp), HIF_MIB_SET_REQ);
1214 pp->mib_attribute = cpu_to_le32(attr);
1215 pp->mib_value.size = cpu_to_le16((u16)size);
1216 pp->mib_value.type = cpu_to_le16(type);
1217 memcpy(&pp->mib_value.body, data, size);
1219 send_request_to_device(priv, pp, hif_align_size(sizeof(*pp) + size));
1222 static inline void hostif_mib_set_request_int(struct ks_wlan_private *priv,
1223 enum mib_attribute attr, int val)
1225 __le32 v = cpu_to_le32((u32)val);
1226 size_t size = sizeof(v);
1228 hostif_mib_set_request(priv, attr, MIB_VALUE_TYPE_INT, &v, size);
1231 static inline void hostif_mib_set_request_bool(struct ks_wlan_private *priv,
1232 enum mib_attribute attr,
1235 __le32 v = cpu_to_le32((u32)val);
1236 size_t size = sizeof(v);
1238 hostif_mib_set_request(priv, attr, MIB_VALUE_TYPE_BOOL, &v, size);
1241 static inline void hostif_mib_set_request_ostring(struct ks_wlan_private *priv,
1242 enum mib_attribute attr,
1243 void *data, size_t size)
1245 hostif_mib_set_request(priv, attr, MIB_VALUE_TYPE_OSTRING, data, size);
1249 void hostif_start_request(struct ks_wlan_private *priv, unsigned char mode)
1251 struct hostif_start_request *pp;
1253 pp = hostif_generic_request(sizeof(*pp), HIF_START_REQ);
1257 pp->mode = cpu_to_le16((uint16_t)mode);
1259 send_request_to_device(priv, pp, hif_align_size(sizeof(*pp)));
1261 priv->aplist.size = 0;
1262 priv->scan_ind_count = 0;
1265 static __le16 ks_wlan_cap(struct ks_wlan_private *priv)
1267 u16 capability = 0x0000;
1269 if (priv->reg.preamble == SHORT_PREAMBLE)
1270 capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
1272 capability &= ~(WLAN_CAPABILITY_PBCC); /* pbcc not support */
1274 if (priv->reg.phy_type != D_11B_ONLY_MODE) {
1275 capability |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
1276 capability &= ~(WLAN_CAPABILITY_DSSS_OFDM);
1279 return cpu_to_le16((uint16_t)capability);
1282 static void init_request(struct ks_wlan_private *priv,
1283 struct hostif_request *req)
1285 req->phy_type = cpu_to_le16((uint16_t)(priv->reg.phy_type));
1286 req->cts_mode = cpu_to_le16((uint16_t)(priv->reg.cts_mode));
1287 req->scan_type = cpu_to_le16((uint16_t)(priv->reg.scan_type));
1288 req->rate_set.size = priv->reg.rate_set.size;
1289 req->capability = ks_wlan_cap(priv);
1290 memcpy(&req->rate_set.body[0], &priv->reg.rate_set.body[0],
1291 priv->reg.rate_set.size);
1295 void hostif_ps_adhoc_set_request(struct ks_wlan_private *priv)
1297 struct hostif_ps_adhoc_set_request *pp;
1299 pp = hostif_generic_request(sizeof(*pp), HIF_PS_ADH_SET_REQ);
1303 init_request(priv, &pp->request);
1304 pp->channel = cpu_to_le16((uint16_t)(priv->reg.channel));
1306 send_request_to_device(priv, pp, hif_align_size(sizeof(*pp)));
1310 void hostif_infrastructure_set_request(struct ks_wlan_private *priv, int event)
1312 struct hostif_infrastructure_set_request *pp;
1314 pp = hostif_generic_request(sizeof(*pp), event);
1318 init_request(priv, &pp->request);
1319 pp->ssid.size = priv->reg.ssid.size;
1320 memcpy(&pp->ssid.body[0], &priv->reg.ssid.body[0], priv->reg.ssid.size);
1321 pp->beacon_lost_count =
1322 cpu_to_le16((uint16_t)(priv->reg.beacon_lost_count));
1323 pp->auth_type = cpu_to_le16((uint16_t)(priv->reg.authenticate_type));
1325 pp->channel_list.body[0] = 1;
1326 pp->channel_list.body[1] = 8;
1327 pp->channel_list.body[2] = 2;
1328 pp->channel_list.body[3] = 9;
1329 pp->channel_list.body[4] = 3;
1330 pp->channel_list.body[5] = 10;
1331 pp->channel_list.body[6] = 4;
1332 pp->channel_list.body[7] = 11;
1333 pp->channel_list.body[8] = 5;
1334 pp->channel_list.body[9] = 12;
1335 pp->channel_list.body[10] = 6;
1336 pp->channel_list.body[11] = 13;
1337 pp->channel_list.body[12] = 7;
1338 if (priv->reg.phy_type == D_11G_ONLY_MODE) {
1339 pp->channel_list.size = 13;
1341 pp->channel_list.body[13] = 14;
1342 pp->channel_list.size = 14;
1345 send_request_to_device(priv, pp, hif_align_size(sizeof(*pp)));
1349 void hostif_adhoc_set_request(struct ks_wlan_private *priv)
1351 struct hostif_adhoc_set_request *pp;
1353 pp = hostif_generic_request(sizeof(*pp), HIF_ADH_SET_REQ);
1357 init_request(priv, &pp->request);
1358 pp->channel = cpu_to_le16((uint16_t)(priv->reg.channel));
1359 pp->ssid.size = priv->reg.ssid.size;
1360 memcpy(&pp->ssid.body[0], &priv->reg.ssid.body[0], priv->reg.ssid.size);
1362 send_request_to_device(priv, pp, hif_align_size(sizeof(*pp)));
1366 void hostif_adhoc_set2_request(struct ks_wlan_private *priv)
1368 struct hostif_adhoc_set2_request *pp;
1370 pp = hostif_generic_request(sizeof(*pp), HIF_ADH_SET_REQ);
1374 init_request(priv, &pp->request);
1375 pp->ssid.size = priv->reg.ssid.size;
1376 memcpy(&pp->ssid.body[0], &priv->reg.ssid.body[0], priv->reg.ssid.size);
1378 pp->channel_list.body[0] = priv->reg.channel;
1379 pp->channel_list.size = 1;
1380 memcpy(pp->bssid, priv->reg.bssid, ETH_ALEN);
1382 send_request_to_device(priv, pp, hif_align_size(sizeof(*pp)));
1386 void hostif_stop_request(struct ks_wlan_private *priv)
1388 struct hostif_stop_request *pp;
1390 pp = hostif_generic_request(sizeof(*pp), HIF_STOP_REQ);
1394 send_request_to_device(priv, pp, hif_align_size(sizeof(*pp)));
1398 void hostif_phy_information_request(struct ks_wlan_private *priv)
1400 struct hostif_phy_information_request *pp;
1402 pp = hostif_generic_request(sizeof(*pp), HIF_PHY_INFO_REQ);
1406 if (priv->reg.phy_info_timer) {
1407 pp->type = cpu_to_le16((uint16_t)TIME_TYPE);
1408 pp->time = cpu_to_le16((uint16_t)(priv->reg.phy_info_timer));
1410 pp->type = cpu_to_le16((uint16_t)NORMAL_TYPE);
1411 pp->time = cpu_to_le16((uint16_t)0);
1414 send_request_to_device(priv, pp, hif_align_size(sizeof(*pp)));
1418 void hostif_power_mgmt_request(struct ks_wlan_private *priv,
1419 u32 mode, u32 wake_up, u32 receive_dtims)
1421 struct hostif_power_mgmt_request *pp;
1423 pp = hostif_generic_request(sizeof(*pp), HIF_POWER_MGMT_REQ);
1427 pp->mode = cpu_to_le32(mode);
1428 pp->wake_up = cpu_to_le32(wake_up);
1429 pp->receive_dtims = cpu_to_le32(receive_dtims);
1431 send_request_to_device(priv, pp, hif_align_size(sizeof(*pp)));
1435 void hostif_sleep_request(struct ks_wlan_private *priv,
1436 enum sleep_mode_type mode)
1438 struct hostif_sleep_request *pp;
1440 if (mode == SLP_SLEEP) {
1441 pp = hostif_generic_request(sizeof(*pp), HIF_SLEEP_REQ);
1445 send_request_to_device(priv, pp, hif_align_size(sizeof(*pp)));
1446 } else if (mode == SLP_ACTIVE) {
1447 atomic_set(&priv->sleepstatus.wakeup_request, 1);
1448 queue_delayed_work(priv->wq, &priv->rw_dwork, 1);
1450 netdev_err(priv->net_dev, "invalid mode %ld\n", (long)mode);
1456 void hostif_bss_scan_request(struct ks_wlan_private *priv,
1457 unsigned long scan_type, uint8_t *scan_ssid,
1458 uint8_t scan_ssid_len)
1460 struct hostif_bss_scan_request *pp;
1462 pp = hostif_generic_request(sizeof(*pp), HIF_SCAN_REQ);
1466 pp->scan_type = scan_type;
1468 pp->ch_time_min = cpu_to_le32((uint32_t)110); /* default value */
1469 pp->ch_time_max = cpu_to_le32((uint32_t)130); /* default value */
1470 pp->channel_list.body[0] = 1;
1471 pp->channel_list.body[1] = 8;
1472 pp->channel_list.body[2] = 2;
1473 pp->channel_list.body[3] = 9;
1474 pp->channel_list.body[4] = 3;
1475 pp->channel_list.body[5] = 10;
1476 pp->channel_list.body[6] = 4;
1477 pp->channel_list.body[7] = 11;
1478 pp->channel_list.body[8] = 5;
1479 pp->channel_list.body[9] = 12;
1480 pp->channel_list.body[10] = 6;
1481 pp->channel_list.body[11] = 13;
1482 pp->channel_list.body[12] = 7;
1483 if (priv->reg.phy_type == D_11G_ONLY_MODE) {
1484 pp->channel_list.size = 13;
1486 pp->channel_list.body[13] = 14;
1487 pp->channel_list.size = 14;
1491 /* specified SSID SCAN */
1492 if (scan_ssid_len > 0 && scan_ssid_len <= 32) {
1493 pp->ssid.size = scan_ssid_len;
1494 memcpy(&pp->ssid.body[0], scan_ssid, scan_ssid_len);
1497 send_request_to_device(priv, pp, hif_align_size(sizeof(*pp)));
1499 priv->aplist.size = 0;
1500 priv->scan_ind_count = 0;
1504 void hostif_mic_failure_request(struct ks_wlan_private *priv,
1505 unsigned short failure_count,
1506 unsigned short timer)
1508 struct hostif_mic_failure_request *pp;
1510 pp = hostif_generic_request(sizeof(*pp), HIF_MIC_FAILURE_REQ);
1514 pp->failure_count = cpu_to_le16((uint16_t)failure_count);
1515 pp->timer = cpu_to_le16((uint16_t)timer);
1517 send_request_to_device(priv, pp, hif_align_size(sizeof(*pp)));
1520 /* Device I/O Receive indicate */
1521 static void devio_rec_ind(struct ks_wlan_private *priv, unsigned char *p,
1524 if (!priv->is_device_open)
1527 spin_lock(&priv->dev_read_lock);
1528 priv->dev_data[atomic_read(&priv->rec_count)] = p;
1529 priv->dev_size[atomic_read(&priv->rec_count)] = size;
1531 if (atomic_read(&priv->event_count) != DEVICE_STOCK_COUNT) {
1532 /* rx event count inc */
1533 atomic_inc(&priv->event_count);
1535 atomic_inc(&priv->rec_count);
1536 if (atomic_read(&priv->rec_count) == DEVICE_STOCK_COUNT)
1537 atomic_set(&priv->rec_count, 0);
1539 wake_up_interruptible_all(&priv->devread_wait);
1541 spin_unlock(&priv->dev_read_lock);
1544 void hostif_receive(struct ks_wlan_private *priv, unsigned char *p,
1547 devio_rec_ind(priv, p, size);
1550 priv->rx_size = size;
1552 if (get_word(priv) == priv->rx_size)
1553 hostif_event_check(priv);
1556 static void hostif_sme_set_wep(struct ks_wlan_private *priv, int type)
1559 case SME_WEP_INDEX_REQUEST:
1560 hostif_mib_set_request_int(priv, DOT11_WEP_DEFAULT_KEY_ID,
1561 priv->reg.wep_index);
1563 case SME_WEP_KEY1_REQUEST:
1564 if (priv->wpa.wpa_enabled)
1566 hostif_mib_set_request_ostring(priv,
1567 DOT11_WEP_DEFAULT_KEY_VALUE1,
1568 &priv->reg.wep_key[0].val[0],
1569 priv->reg.wep_key[0].size);
1571 case SME_WEP_KEY2_REQUEST:
1572 if (priv->wpa.wpa_enabled)
1574 hostif_mib_set_request_ostring(priv,
1575 DOT11_WEP_DEFAULT_KEY_VALUE2,
1576 &priv->reg.wep_key[1].val[0],
1577 priv->reg.wep_key[1].size);
1579 case SME_WEP_KEY3_REQUEST:
1580 if (priv->wpa.wpa_enabled)
1582 hostif_mib_set_request_ostring(priv,
1583 DOT11_WEP_DEFAULT_KEY_VALUE3,
1584 &priv->reg.wep_key[2].val[0],
1585 priv->reg.wep_key[2].size);
1587 case SME_WEP_KEY4_REQUEST:
1588 if (priv->wpa.wpa_enabled)
1590 hostif_mib_set_request_ostring(priv,
1591 DOT11_WEP_DEFAULT_KEY_VALUE4,
1592 &priv->reg.wep_key[3].val[0],
1593 priv->reg.wep_key[3].size);
1595 case SME_WEP_FLAG_REQUEST:
1596 hostif_mib_set_request_bool(priv, DOT11_PRIVACY_INVOKED,
1597 priv->reg.privacy_invoked);
1604 unsigned char suite[4][CIPHER_ID_LEN];
1609 __le16 rsn_capability;
1612 static void hostif_sme_set_rsn(struct ks_wlan_private *priv, int type)
1614 struct wpa_suite wpa_suite;
1615 struct rsn_mode rsn_mode;
1618 const u8 *buf = NULL;
1620 memset(&wpa_suite, 0, sizeof(wpa_suite));
1623 case SME_RSN_UCAST_REQUEST:
1624 wpa_suite.size = cpu_to_le16((uint16_t)1);
1625 switch (priv->wpa.pairwise_suite) {
1626 case IW_AUTH_CIPHER_NONE:
1627 buf = (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) ?
1628 CIPHER_ID_WPA2_NONE : CIPHER_ID_WPA_NONE;
1630 case IW_AUTH_CIPHER_WEP40:
1631 buf = (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) ?
1632 CIPHER_ID_WPA2_WEP40 : CIPHER_ID_WPA_WEP40;
1634 case IW_AUTH_CIPHER_TKIP:
1635 buf = (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) ?
1636 CIPHER_ID_WPA2_TKIP : CIPHER_ID_WPA_TKIP;
1638 case IW_AUTH_CIPHER_CCMP:
1639 buf = (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) ?
1640 CIPHER_ID_WPA2_CCMP : CIPHER_ID_WPA_CCMP;
1642 case IW_AUTH_CIPHER_WEP104:
1643 buf = (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) ?
1644 CIPHER_ID_WPA2_WEP104 : CIPHER_ID_WPA_WEP104;
1649 memcpy(&wpa_suite.suite[0][0], buf, CIPHER_ID_LEN);
1650 size = sizeof(wpa_suite.size) +
1651 (CIPHER_ID_LEN * le16_to_cpu(wpa_suite.size));
1652 hostif_mib_set_request_ostring(priv,
1653 DOT11_RSN_CONFIG_UNICAST_CIPHER,
1656 case SME_RSN_MCAST_REQUEST:
1657 switch (priv->wpa.group_suite) {
1658 case IW_AUTH_CIPHER_NONE:
1659 buf = (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) ?
1660 CIPHER_ID_WPA2_NONE : CIPHER_ID_WPA_NONE;
1662 case IW_AUTH_CIPHER_WEP40:
1663 buf = (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) ?
1664 CIPHER_ID_WPA2_WEP40 : CIPHER_ID_WPA_WEP40;
1666 case IW_AUTH_CIPHER_TKIP:
1667 buf = (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) ?
1668 CIPHER_ID_WPA2_TKIP : CIPHER_ID_WPA_TKIP;
1670 case IW_AUTH_CIPHER_CCMP:
1671 buf = (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) ?
1672 CIPHER_ID_WPA2_CCMP : CIPHER_ID_WPA_CCMP;
1674 case IW_AUTH_CIPHER_WEP104:
1675 buf = (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) ?
1676 CIPHER_ID_WPA2_WEP104 : CIPHER_ID_WPA_WEP104;
1680 memcpy(&wpa_suite.suite[0][0], buf, CIPHER_ID_LEN);
1681 hostif_mib_set_request_ostring(priv,
1682 DOT11_RSN_CONFIG_MULTICAST_CIPHER,
1683 &wpa_suite.suite[0][0],
1686 case SME_RSN_AUTH_REQUEST:
1687 wpa_suite.size = cpu_to_le16((uint16_t)1);
1688 switch (priv->wpa.key_mgmt_suite) {
1689 case IW_AUTH_KEY_MGMT_802_1X:
1690 buf = (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) ?
1691 KEY_MGMT_ID_WPA2_1X : KEY_MGMT_ID_WPA_1X;
1693 case IW_AUTH_KEY_MGMT_PSK:
1694 buf = (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) ?
1695 KEY_MGMT_ID_WPA2_PSK : KEY_MGMT_ID_WPA_PSK;
1698 buf = (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) ?
1699 KEY_MGMT_ID_WPA2_NONE : KEY_MGMT_ID_WPA_NONE;
1702 buf = (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) ?
1703 KEY_MGMT_ID_WPA2_WPANONE :
1704 KEY_MGMT_ID_WPA_WPANONE;
1709 memcpy(&wpa_suite.suite[0][0], buf, KEY_MGMT_ID_LEN);
1710 size = sizeof(wpa_suite.size) +
1711 (KEY_MGMT_ID_LEN * le16_to_cpu(wpa_suite.size));
1712 hostif_mib_set_request_ostring(priv,
1713 DOT11_RSN_CONFIG_AUTH_SUITE,
1716 case SME_RSN_ENABLED_REQUEST:
1717 hostif_mib_set_request_bool(priv, DOT11_RSN_ENABLED,
1718 priv->wpa.rsn_enabled);
1720 case SME_RSN_MODE_REQUEST:
1721 mode = (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) ?
1723 (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA) ?
1724 RSN_MODE_WPA : RSN_MODE_NONE;
1725 rsn_mode.rsn_mode = cpu_to_le32(mode);
1726 rsn_mode.rsn_capability = cpu_to_le16((uint16_t)0);
1727 hostif_mib_set_request_ostring(priv, LOCAL_RSN_MODE,
1728 &rsn_mode, sizeof(rsn_mode));
1734 void hostif_sme_mode_setup(struct ks_wlan_private *priv)
1736 unsigned char rate_size;
1737 unsigned char rate_octet[RATE_SET_MAX_SIZE];
1740 /* rate setting if rate segging is auto for changing phy_type (#94) */
1741 if (priv->reg.tx_rate == TX_RATE_FULL_AUTO) {
1742 if (priv->reg.phy_type == D_11B_ONLY_MODE) {
1743 priv->reg.rate_set.body[3] = TX_RATE_11M;
1744 priv->reg.rate_set.body[2] = TX_RATE_5M;
1745 priv->reg.rate_set.body[1] = TX_RATE_2M | BASIC_RATE;
1746 priv->reg.rate_set.body[0] = TX_RATE_1M | BASIC_RATE;
1747 priv->reg.rate_set.size = 4;
1748 } else { /* D_11G_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
1749 priv->reg.rate_set.body[11] = TX_RATE_54M;
1750 priv->reg.rate_set.body[10] = TX_RATE_48M;
1751 priv->reg.rate_set.body[9] = TX_RATE_36M;
1752 priv->reg.rate_set.body[8] = TX_RATE_18M;
1753 priv->reg.rate_set.body[7] = TX_RATE_9M;
1754 priv->reg.rate_set.body[6] = TX_RATE_24M | BASIC_RATE;
1755 priv->reg.rate_set.body[5] = TX_RATE_12M | BASIC_RATE;
1756 priv->reg.rate_set.body[4] = TX_RATE_6M | BASIC_RATE;
1757 priv->reg.rate_set.body[3] = TX_RATE_11M | BASIC_RATE;
1758 priv->reg.rate_set.body[2] = TX_RATE_5M | BASIC_RATE;
1759 priv->reg.rate_set.body[1] = TX_RATE_2M | BASIC_RATE;
1760 priv->reg.rate_set.body[0] = TX_RATE_1M | BASIC_RATE;
1761 priv->reg.rate_set.size = 12;
1765 /* rate mask by phy setting */
1766 if (priv->reg.phy_type == D_11B_ONLY_MODE) {
1767 for (i = 0; i < priv->reg.rate_set.size; i++) {
1768 if (!is_11b_rate(priv->reg.rate_set.body[i]))
1771 if ((priv->reg.rate_set.body[i] & RATE_MASK) >= TX_RATE_5M) {
1772 rate_octet[i] = priv->reg.rate_set.body[i] &
1775 rate_octet[i] = priv->reg.rate_set.body[i];
1779 } else { /* D_11G_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
1780 for (i = 0; i < priv->reg.rate_set.size; i++) {
1781 if (!is_11bg_rate(priv->reg.rate_set.body[i]))
1784 if (is_ofdm_ext_rate(priv->reg.rate_set.body[i])) {
1785 rate_octet[i] = priv->reg.rate_set.body[i] &
1788 rate_octet[i] = priv->reg.rate_set.body[i];
1793 if (rate_size == 0) {
1794 if (priv->reg.phy_type == D_11G_ONLY_MODE)
1795 rate_octet[0] = TX_RATE_6M | BASIC_RATE;
1797 rate_octet[0] = TX_RATE_2M | BASIC_RATE;
1801 /* rate set update */
1802 priv->reg.rate_set.size = rate_size;
1803 memcpy(&priv->reg.rate_set.body[0], &rate_octet[0], rate_size);
1805 switch (priv->reg.operation_mode) {
1806 case MODE_PSEUDO_ADHOC:
1807 hostif_ps_adhoc_set_request(priv);
1809 case MODE_INFRASTRUCTURE:
1810 if (!is_valid_ether_addr((u8 *)priv->reg.bssid)) {
1811 hostif_infrastructure_set_request(priv,
1814 hostif_infrastructure_set_request(priv,
1815 HIF_INFRA_SET2_REQ);
1816 netdev_dbg(priv->net_dev,
1817 "Infra bssid = %pM\n", priv->reg.bssid);
1821 if (!is_valid_ether_addr((u8 *)priv->reg.bssid)) {
1822 hostif_adhoc_set_request(priv);
1824 hostif_adhoc_set2_request(priv);
1825 netdev_dbg(priv->net_dev,
1826 "Adhoc bssid = %pM\n", priv->reg.bssid);
1835 void hostif_sme_multicast_set(struct ks_wlan_private *priv)
1837 struct net_device *dev = priv->net_dev;
1839 struct netdev_hw_addr *ha;
1840 char set_address[NIC_MAX_MCAST_LIST * ETH_ALEN];
1843 spin_lock(&priv->multicast_spin);
1845 memset(set_address, 0, NIC_MAX_MCAST_LIST * ETH_ALEN);
1847 if (dev->flags & IFF_PROMISC) {
1848 hostif_mib_set_request_bool(priv, LOCAL_MULTICAST_FILTER,
1849 MCAST_FILTER_PROMISC);
1853 if ((netdev_mc_count(dev) > NIC_MAX_MCAST_LIST) ||
1854 (dev->flags & IFF_ALLMULTI)) {
1855 hostif_mib_set_request_bool(priv, LOCAL_MULTICAST_FILTER,
1856 MCAST_FILTER_MCASTALL);
1860 if (priv->sme_i.sme_flag & SME_MULTICAST) {
1861 mc_count = netdev_mc_count(dev);
1862 netdev_for_each_mc_addr(ha, dev) {
1863 ether_addr_copy(&set_address[i * ETH_ALEN], ha->addr);
1866 priv->sme_i.sme_flag &= ~SME_MULTICAST;
1867 hostif_mib_set_request_ostring(priv, LOCAL_MULTICAST_ADDRESS,
1869 ETH_ALEN * mc_count);
1871 priv->sme_i.sme_flag |= SME_MULTICAST;
1872 hostif_mib_set_request_bool(priv, LOCAL_MULTICAST_FILTER,
1873 MCAST_FILTER_MCAST);
1877 spin_unlock(&priv->multicast_spin);
1880 static void hostif_sme_power_mgmt_set(struct ks_wlan_private *priv)
1882 u32 mode, wake_up, receive_dtims;
1884 if (priv->reg.power_mgmt != POWER_MGMT_SAVE1 &&
1885 priv->reg.power_mgmt != POWER_MGMT_SAVE2) {
1886 mode = POWER_ACTIVE;
1890 mode = (priv->reg.operation_mode == MODE_INFRASTRUCTURE) ?
1891 POWER_SAVE : POWER_ACTIVE;
1893 receive_dtims = (priv->reg.operation_mode == MODE_INFRASTRUCTURE &&
1894 priv->reg.power_mgmt == POWER_MGMT_SAVE2);
1897 hostif_power_mgmt_request(priv, mode, wake_up, receive_dtims);
1900 static void hostif_sme_sleep_set(struct ks_wlan_private *priv)
1902 if (priv->sleep_mode != SLP_SLEEP &&
1903 priv->sleep_mode != SLP_ACTIVE)
1906 hostif_sleep_request(priv, priv->sleep_mode);
1910 void hostif_sme_set_key(struct ks_wlan_private *priv, int type)
1914 hostif_mib_set_request_bool(priv, DOT11_PRIVACY_INVOKED,
1915 priv->reg.privacy_invoked);
1918 hostif_mib_set_request_int(priv, DOT11_WEP_DEFAULT_KEY_ID,
1922 hostif_mib_set_request_ostring(priv,
1923 DOT11_WEP_DEFAULT_KEY_VALUE1,
1924 &priv->wpa.key[0].key_val[0],
1925 priv->wpa.key[0].key_len);
1928 hostif_mib_set_request_ostring(priv,
1929 DOT11_WEP_DEFAULT_KEY_VALUE2,
1930 &priv->wpa.key[1].key_val[0],
1931 priv->wpa.key[1].key_len);
1934 hostif_mib_set_request_ostring(priv,
1935 DOT11_WEP_DEFAULT_KEY_VALUE3,
1936 &priv->wpa.key[2].key_val[0],
1937 priv->wpa.key[2].key_len);
1940 hostif_mib_set_request_ostring(priv,
1941 DOT11_WEP_DEFAULT_KEY_VALUE4,
1942 &priv->wpa.key[3].key_val[0],
1943 priv->wpa.key[3].key_len);
1945 case SME_SET_PMK_TSC:
1946 hostif_mib_set_request_ostring(priv, DOT11_PMK_TSC,
1947 &priv->wpa.key[0].rx_seq[0],
1950 case SME_SET_GMK1_TSC:
1951 hostif_mib_set_request_ostring(priv, DOT11_GMK1_TSC,
1952 &priv->wpa.key[1].rx_seq[0],
1955 case SME_SET_GMK2_TSC:
1956 hostif_mib_set_request_ostring(priv, DOT11_GMK2_TSC,
1957 &priv->wpa.key[2].rx_seq[0],
1964 void hostif_sme_set_pmksa(struct ks_wlan_private *priv)
1970 u8 pmkid[IW_PMKID_LEN];
1971 } __packed list[PMK_LIST_MAX];
1972 } __packed pmkcache;
1977 list_for_each_entry(pmk, &priv->pmklist.head, list) {
1978 if (i >= PMK_LIST_MAX)
1980 ether_addr_copy(pmkcache.list[i].bssid, pmk->bssid);
1981 memcpy(pmkcache.list[i].pmkid, pmk->pmkid, IW_PMKID_LEN);
1984 pmkcache.size = cpu_to_le16((uint16_t)(priv->pmklist.size));
1985 size = sizeof(priv->pmklist.size) +
1986 ((ETH_ALEN + IW_PMKID_LEN) * priv->pmklist.size);
1987 hostif_mib_set_request_ostring(priv, LOCAL_PMK, &pmkcache, size);
1991 static void hostif_sme_execute(struct ks_wlan_private *priv, int event)
1997 if (priv->dev_state == DEVICE_STATE_BOOT)
1998 hostif_mib_get_request(priv, DOT11_MAC_ADDRESS);
2000 case SME_MULTICAST_REQUEST:
2001 hostif_sme_multicast_set(priv);
2003 case SME_MACADDRESS_SET_REQUEST:
2004 hostif_mib_set_request_ostring(priv, LOCAL_CURRENTADDRESS,
2005 &priv->eth_addr[0], ETH_ALEN);
2007 case SME_BSS_SCAN_REQUEST:
2008 hostif_bss_scan_request(priv, priv->reg.scan_type,
2009 priv->scan_ssid, priv->scan_ssid_len);
2011 case SME_POW_MNGMT_REQUEST:
2012 hostif_sme_power_mgmt_set(priv);
2014 case SME_PHY_INFO_REQUEST:
2015 hostif_phy_information_request(priv);
2017 case SME_MIC_FAILURE_REQUEST:
2018 failure = priv->wpa.mic_failure.failure;
2019 if (failure != 1 && failure != 2) {
2020 netdev_err(priv->net_dev,
2021 "SME_MIC_FAILURE_REQUEST: failure count=%u error?\n",
2025 hostif_mic_failure_request(priv, failure - 1, (failure == 1) ?
2026 0 : priv->wpa.mic_failure.counter);
2028 case SME_MIC_FAILURE_CONFIRM:
2029 if (priv->wpa.mic_failure.failure == 2) {
2030 if (priv->wpa.mic_failure.stop)
2031 priv->wpa.mic_failure.stop = 0;
2032 priv->wpa.mic_failure.failure = 0;
2033 hostif_start_request(priv, priv->reg.operation_mode);
2036 case SME_GET_MAC_ADDRESS:
2037 if (priv->dev_state == DEVICE_STATE_BOOT)
2038 hostif_mib_get_request(priv, DOT11_PRODUCT_VERSION);
2040 case SME_GET_PRODUCT_VERSION:
2041 if (priv->dev_state == DEVICE_STATE_BOOT)
2042 priv->dev_state = DEVICE_STATE_PREINIT;
2044 case SME_STOP_REQUEST:
2045 hostif_stop_request(priv);
2047 case SME_RTS_THRESHOLD_REQUEST:
2048 hostif_mib_set_request_int(priv, DOT11_RTS_THRESHOLD,
2051 case SME_FRAGMENTATION_THRESHOLD_REQUEST:
2052 hostif_mib_set_request_int(priv, DOT11_FRAGMENTATION_THRESHOLD,
2053 priv->reg.fragment);
2055 case SME_WEP_INDEX_REQUEST:
2056 case SME_WEP_KEY1_REQUEST:
2057 case SME_WEP_KEY2_REQUEST:
2058 case SME_WEP_KEY3_REQUEST:
2059 case SME_WEP_KEY4_REQUEST:
2060 case SME_WEP_FLAG_REQUEST:
2061 hostif_sme_set_wep(priv, event);
2063 case SME_RSN_UCAST_REQUEST:
2064 case SME_RSN_MCAST_REQUEST:
2065 case SME_RSN_AUTH_REQUEST:
2066 case SME_RSN_ENABLED_REQUEST:
2067 case SME_RSN_MODE_REQUEST:
2068 hostif_sme_set_rsn(priv, event);
2076 case SME_SET_PMK_TSC:
2077 case SME_SET_GMK1_TSC:
2078 case SME_SET_GMK2_TSC:
2079 hostif_sme_set_key(priv, event);
2082 hostif_sme_set_pmksa(priv);
2084 case SME_WPS_ENABLE_REQUEST:
2085 hostif_mib_set_request_int(priv, LOCAL_WPS_ENABLE,
2086 priv->wps.wps_enabled);
2088 case SME_WPS_PROBE_REQUEST:
2089 hostif_mib_set_request_ostring(priv, LOCAL_WPS_PROBE_REQ,
2090 priv->wps.ie, priv->wps.ielen);
2092 case SME_MODE_SET_REQUEST:
2093 hostif_sme_mode_setup(priv);
2096 hostif_mib_set_request_ostring(priv, LOCAL_GAIN,
2097 &priv->gain, sizeof(priv->gain));
2100 hostif_mib_get_request(priv, LOCAL_GAIN);
2102 case SME_GET_EEPROM_CKSUM:
2103 priv->eeprom_checksum = EEPROM_FW_NOT_SUPPORT; /* initialize */
2104 hostif_mib_get_request(priv, LOCAL_EEPROM_SUM);
2106 case SME_START_REQUEST:
2107 hostif_start_request(priv, priv->reg.operation_mode);
2109 case SME_START_CONFIRM:
2110 /* for power save */
2111 atomic_set(&priv->psstatus.snooze_guard, 0);
2112 atomic_set(&priv->psstatus.confirm_wait, 0);
2113 if (priv->dev_state == DEVICE_STATE_PREINIT)
2114 priv->dev_state = DEVICE_STATE_INIT;
2115 /* wake_up_interruptible_all(&priv->confirm_wait); */
2116 complete(&priv->confirm_wait);
2118 case SME_SLEEP_REQUEST:
2119 hostif_sme_sleep_set(priv);
2121 case SME_SET_REGION:
2122 hostif_mib_set_request_int(priv, LOCAL_REGION, priv->region);
2124 case SME_MULTICAST_CONFIRM:
2125 case SME_BSS_SCAN_CONFIRM:
2126 case SME_POW_MNGMT_CONFIRM:
2127 case SME_PHY_INFO_CONFIRM:
2128 case SME_STOP_CONFIRM:
2129 case SME_RTS_THRESHOLD_CONFIRM:
2130 case SME_FRAGMENTATION_THRESHOLD_CONFIRM:
2131 case SME_WEP_INDEX_CONFIRM:
2132 case SME_WEP_KEY1_CONFIRM:
2133 case SME_WEP_KEY2_CONFIRM:
2134 case SME_WEP_KEY3_CONFIRM:
2135 case SME_WEP_KEY4_CONFIRM:
2136 case SME_WEP_FLAG_CONFIRM:
2137 case SME_RSN_UCAST_CONFIRM:
2138 case SME_RSN_MCAST_CONFIRM:
2139 case SME_RSN_AUTH_CONFIRM:
2140 case SME_RSN_ENABLED_CONFIRM:
2141 case SME_RSN_MODE_CONFIRM:
2142 case SME_MODE_SET_CONFIRM:
2150 void hostif_sme_task(unsigned long dev)
2152 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev;
2154 if (priv->dev_state < DEVICE_STATE_BOOT)
2157 if (cnt_smeqbody(priv) <= 0)
2160 hostif_sme_execute(priv, priv->sme_i.event_buff[priv->sme_i.qhead]);
2162 if (cnt_smeqbody(priv) > 0)
2163 tasklet_schedule(&priv->sme_task);
2166 /* send to Station Management Entity module */
2167 void hostif_sme_enqueue(struct ks_wlan_private *priv, u16 event)
2169 /* enqueue sme event */
2170 if (cnt_smeqbody(priv) < (SME_EVENT_BUFF_SIZE - 1)) {
2171 priv->sme_i.event_buff[priv->sme_i.qtail] = event;
2174 /* in case of buffer overflow */
2175 netdev_err(priv->net_dev, "sme queue buffer overflow\n");
2178 tasklet_schedule(&priv->sme_task);
2181 static inline void hostif_aplist_init(struct ks_wlan_private *priv)
2183 size_t size = LOCAL_APLIST_MAX * sizeof(struct local_ap);
2185 priv->aplist.size = 0;
2186 memset(&priv->aplist.ap[0], 0, size);
2189 static inline void hostif_status_init(struct ks_wlan_private *priv)
2191 priv->infra_status = 0;
2192 priv->current_rate = 4;
2193 priv->connect_status = DISCONNECT_STATUS;
2196 static inline void hostif_sme_init(struct ks_wlan_private *priv)
2198 priv->sme_i.sme_status = SME_IDLE;
2199 priv->sme_i.qhead = 0;
2200 priv->sme_i.qtail = 0;
2201 spin_lock_init(&priv->sme_i.sme_spin);
2202 priv->sme_i.sme_flag = 0;
2203 tasklet_init(&priv->sme_task, hostif_sme_task, (unsigned long)priv);
2206 static inline void hostif_wpa_init(struct ks_wlan_private *priv)
2208 memset(&priv->wpa, 0, sizeof(priv->wpa));
2209 priv->wpa.rsn_enabled = false;
2210 priv->wpa.mic_failure.failure = 0;
2211 priv->wpa.mic_failure.last_failure_time = 0;
2212 priv->wpa.mic_failure.stop = 0;
2215 static inline void hostif_power_save_init(struct ks_wlan_private *priv)
2217 atomic_set(&priv->psstatus.status, PS_NONE);
2218 atomic_set(&priv->psstatus.confirm_wait, 0);
2219 atomic_set(&priv->psstatus.snooze_guard, 0);
2220 init_completion(&priv->psstatus.wakeup_wait);
2221 INIT_WORK(&priv->wakeup_work, ks_wlan_hw_wakeup_task);
2224 static inline void hostif_pmklist_init(struct ks_wlan_private *priv)
2228 memset(&priv->pmklist, 0, sizeof(priv->pmklist));
2229 INIT_LIST_HEAD(&priv->pmklist.head);
2230 for (i = 0; i < PMK_LIST_MAX; i++)
2231 INIT_LIST_HEAD(&priv->pmklist.pmk[i].list);
2234 static inline void hostif_counters_init(struct ks_wlan_private *priv)
2236 priv->dev_count = 0;
2237 atomic_set(&priv->event_count, 0);
2238 atomic_set(&priv->rec_count, 0);
2241 int hostif_init(struct ks_wlan_private *priv)
2243 hostif_aplist_init(priv);
2244 hostif_status_init(priv);
2246 spin_lock_init(&priv->multicast_spin);
2247 spin_lock_init(&priv->dev_read_lock);
2248 init_waitqueue_head(&priv->devread_wait);
2250 hostif_counters_init(priv);
2251 hostif_power_save_init(priv);
2252 hostif_wpa_init(priv);
2253 hostif_pmklist_init(priv);
2254 hostif_sme_init(priv);
2259 void hostif_exit(struct ks_wlan_private *priv)
2261 tasklet_kill(&priv->sme_task);