Linux-libre 4.11.5-gnu
[librecmc/linux-libre.git] / drivers / staging / ks7010 / ks_hostif.c
1 /*
2  *   Driver for KeyStream wireless LAN cards.
3  *
4  *   Copyright (C) 2005-2008 KeyStream Corp.
5  *   Copyright (C) 2009 Renesas Technology Corp.
6  *
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.
10  */
11
12 #include "ks_wlan.h"
13 #include "ks_hostif.h"
14 #include "eap_packet.h"
15 #include "michael_mic.h"
16
17 #include <linux/etherdevice.h>
18 #include <linux/if_ether.h>
19 #include <linux/if_arp.h>
20
21 /* Include Wireless Extension definition and check version */
22 #include <net/iw_handler.h>     /* New driver API */
23
24 /* macro */
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)
31
32 #define KS_WLAN_MEM_FLAG (GFP_ATOMIC)
33
34 static
35 inline u8 get_BYTE(struct ks_wlan_private *priv)
36 {
37         u8 data;
38
39         data = *(priv->rxp)++;
40         /* length check in advance ! */
41         --(priv->rx_size);
42         return data;
43 }
44
45 static
46 inline u16 get_WORD(struct ks_wlan_private *priv)
47 {
48         u16 data;
49
50         data = (get_BYTE(priv) & 0xff);
51         data |= ((get_BYTE(priv) << 8) & 0xff00);
52         return data;
53 }
54
55 static
56 inline u32 get_DWORD(struct ks_wlan_private *priv)
57 {
58         u32 data;
59
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);
64         return data;
65 }
66
67 static void ks_wlan_hw_wakeup_task(struct work_struct *work)
68 {
69         struct ks_wlan_private *priv =
70             container_of(work, struct ks_wlan_private, ks_wlan_wakeup_task);
71         int ps_status = atomic_read(&priv->psstatus.status);
72         long time_left;
73
74         if (ps_status == PS_SNOOZE) {
75                 ks_wlan_hw_wakeup_request(priv);
76                 time_left = wait_for_completion_interruptible_timeout(
77                                 &priv->psstatus.wakeup_wait,
78                                 msecs_to_jiffies(20));
79                 if (time_left <= 0) {
80                         DPRINTK(1, "wake up timeout or interrupted !!!\n");
81                         schedule_work(&priv->ks_wlan_wakeup_task);
82                         return;
83                 }
84         } else {
85                 DPRINTK(1, "ps_status=%d\n", ps_status);
86         }
87
88         /* power save */
89         if (atomic_read(&priv->sme_task.count) > 0) {
90                 DPRINTK(4, "sme task enable.\n");
91                 tasklet_enable(&priv->sme_task);
92         }
93 }
94
95 static
96 int ks_wlan_do_power_save(struct ks_wlan_private *priv)
97 {
98         DPRINTK(4, "psstatus.status=%d\n", atomic_read(&priv->psstatus.status));
99
100         if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS)
101                 hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
102         else
103                 priv->dev_state = DEVICE_STATE_READY;
104         return 0;
105 }
106
107 static
108 int get_current_ap(struct ks_wlan_private *priv, struct link_ap_info_t *ap_info)
109 {
110         struct local_ap_t *ap;
111         union iwreq_data wrqu;
112         struct net_device *netdev = priv->net_dev;
113         int rc = 0;
114
115         DPRINTK(3, "\n");
116         ap = &(priv->current_ap);
117
118         if ((priv->connect_status & CONNECT_STATUS_MASK) == DISCONNECT_STATUS) {
119                 memset(ap, 0, sizeof(struct local_ap_t));
120                 return 1;
121         }
122
123         /* bssid */
124         memcpy(&(ap->bssid[0]), &(ap_info->bssid[0]), ETH_ALEN);
125         /* essid */
126         memcpy(&(ap->ssid.body[0]), &(priv->reg.ssid.body[0]),
127                priv->reg.ssid.size);
128         ap->ssid.size = priv->reg.ssid.size;
129         /* rate_set */
130         memcpy(&(ap->rate_set.body[0]), &(ap_info->rate_set.body[0]),
131                ap_info->rate_set.size);
132         ap->rate_set.size = ap_info->rate_set.size;
133         if (ap_info->ext_rate_set.size) {
134                 /* rate_set */
135                 memcpy(&(ap->rate_set.body[ap->rate_set.size]),
136                        &(ap_info->ext_rate_set.body[0]),
137                        ap_info->ext_rate_set.size);
138                 ap->rate_set.size += ap_info->ext_rate_set.size;
139         }
140         /* channel */
141         ap->channel = ap_info->ds_parameter.channel;
142         /* rssi */
143         ap->rssi = ap_info->rssi;
144         /* sq */
145         ap->sq = ap_info->sq;
146         /* noise */
147         ap->noise = ap_info->noise;
148         /* capability */
149         ap->capability = ap_info->capability;
150         /* rsn */
151         if ((ap_info->rsn_mode & RSN_MODE_WPA2)
152             && (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)) {
153                 ap->rsn_ie.id = 0x30;
154                 if (ap_info->rsn.size <= RSN_IE_BODY_MAX) {
155                         ap->rsn_ie.size = ap_info->rsn.size;
156                         memcpy(&(ap->rsn_ie.body[0]), &(ap_info->rsn.body[0]),
157                                ap_info->rsn.size);
158                 } else {
159                         ap->rsn_ie.size = RSN_IE_BODY_MAX;
160                         memcpy(&(ap->rsn_ie.body[0]), &(ap_info->rsn.body[0]),
161                                RSN_IE_BODY_MAX);
162                 }
163         } else if ((ap_info->rsn_mode & RSN_MODE_WPA)
164                    && (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA)) {
165                 ap->wpa_ie.id = 0xdd;
166                 if (ap_info->rsn.size <= RSN_IE_BODY_MAX) {
167                         ap->wpa_ie.size = ap_info->rsn.size;
168                         memcpy(&(ap->wpa_ie.body[0]), &(ap_info->rsn.body[0]),
169                                ap_info->rsn.size);
170                 } else {
171                         ap->wpa_ie.size = RSN_IE_BODY_MAX;
172                         memcpy(&(ap->wpa_ie.body[0]), &(ap_info->rsn.body[0]),
173                                RSN_IE_BODY_MAX);
174                 }
175         } else {
176                 ap->rsn_ie.id = 0;
177                 ap->rsn_ie.size = 0;
178                 ap->wpa_ie.id = 0;
179                 ap->wpa_ie.size = 0;
180         }
181
182         wrqu.data.length = 0;
183         wrqu.data.flags = 0;
184         wrqu.ap_addr.sa_family = ARPHRD_ETHER;
185         if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
186                 memcpy(wrqu.ap_addr.sa_data,
187                        &(priv->current_ap.bssid[0]), ETH_ALEN);
188                 DPRINTK(3,
189                         "IWEVENT: connect bssid=%pM\n", wrqu.ap_addr.sa_data);
190                 wireless_send_event(netdev, SIOCGIWAP, &wrqu, NULL);
191         }
192         DPRINTK(4, "\n    Link AP\n");
193         DPRINTK(4, "    bssid=%02X:%02X:%02X:%02X:%02X:%02X\n \
194    essid=%s\n    rate_set=%02X,%02X,%02X,%02X,%02X,%02X,%02X,%02X\n    channel=%d\n \
195    rssi=%d\n    sq=%d\n    capability=%04X\n", ap->bssid[0], ap->bssid[1], ap->bssid[2], ap->bssid[3], ap->bssid[4], ap->bssid[5], &(ap->ssid.body[0]), ap->rate_set.body[0], ap->rate_set.body[1], ap->rate_set.body[2], ap->rate_set.body[3], ap->rate_set.body[4], ap->rate_set.body[5], ap->rate_set.body[6], ap->rate_set.body[7], ap->channel, ap->rssi, ap->sq, ap->capability);
196         DPRINTK(4, "\n    Link AP\n    rsn.mode=%d\n    rsn.size=%d\n",
197                 ap_info->rsn_mode, ap_info->rsn.size);
198         DPRINTK(4, "\n    ext_rate_set_size=%d\n    rate_set_size=%d\n",
199                 ap_info->ext_rate_set.size, ap_info->rate_set.size);
200
201         return rc;
202 }
203
204 static
205 int get_ap_information(struct ks_wlan_private *priv, struct ap_info_t *ap_info,
206                        struct local_ap_t *ap)
207 {
208         unsigned char *bp;
209         int bsize, offset;
210
211         DPRINTK(3, "\n");
212         memset(ap, 0, sizeof(struct local_ap_t));
213
214         /* bssid */
215         memcpy(&(ap->bssid[0]), &(ap_info->bssid[0]), ETH_ALEN);
216         /* rssi */
217         ap->rssi = ap_info->rssi;
218         /* sq */
219         ap->sq = ap_info->sq;
220         /* noise */
221         ap->noise = ap_info->noise;
222         /* capability */
223         ap->capability = ap_info->capability;
224         /* channel */
225         ap->channel = ap_info->ch_info;
226
227         bp = &(ap_info->body[0]);
228         bsize = ap_info->body_size;
229         offset = 0;
230
231         while (bsize > offset) {
232                 /* DPRINTK(4, "Element ID=%d\n",*bp); */
233                 switch (*bp) {
234                 case 0: /* ssid */
235                         if (*(bp + 1) <= SSID_MAX_SIZE) {
236                                 ap->ssid.size = *(bp + 1);
237                         } else {
238                                 DPRINTK(1, "size over :: ssid size=%d\n",
239                                         *(bp + 1));
240                                 ap->ssid.size = SSID_MAX_SIZE;
241                         }
242                         memcpy(&(ap->ssid.body[0]), bp + 2, ap->ssid.size);
243                         break;
244                 case 1: /* rate */
245                 case 50:        /* ext rate */
246                         if ((*(bp + 1) + ap->rate_set.size) <=
247                             RATE_SET_MAX_SIZE) {
248                                 memcpy(&(ap->rate_set.body[ap->rate_set.size]),
249                                        bp + 2, *(bp + 1));
250                                 ap->rate_set.size += *(bp + 1);
251                         } else {
252                                 DPRINTK(1, "size over :: rate size=%d\n",
253                                         (*(bp + 1) + ap->rate_set.size));
254                                 memcpy(&(ap->rate_set.body[ap->rate_set.size]),
255                                        bp + 2,
256                                        RATE_SET_MAX_SIZE - ap->rate_set.size);
257                                 ap->rate_set.size +=
258                                     (RATE_SET_MAX_SIZE - ap->rate_set.size);
259                         }
260                         break;
261                 case 3: /* DS parameter */
262                         break;
263                 case 48:        /* RSN(WPA2) */
264                         ap->rsn_ie.id = *bp;
265                         if (*(bp + 1) <= RSN_IE_BODY_MAX) {
266                                 ap->rsn_ie.size = *(bp + 1);
267                         } else {
268                                 DPRINTK(1, "size over :: rsn size=%d\n",
269                                         *(bp + 1));
270                                 ap->rsn_ie.size = RSN_IE_BODY_MAX;
271                         }
272                         memcpy(&(ap->rsn_ie.body[0]), bp + 2, ap->rsn_ie.size);
273                         break;
274                 case 221:       /* WPA */
275                         if (!memcmp(bp + 2, "\x00\x50\xf2\x01", 4)) {   /* WPA OUI check */
276                                 ap->wpa_ie.id = *bp;
277                                 if (*(bp + 1) <= RSN_IE_BODY_MAX) {
278                                         ap->wpa_ie.size = *(bp + 1);
279                                 } else {
280                                         DPRINTK(1,
281                                                 "size over :: wpa size=%d\n",
282                                                 *(bp + 1));
283                                         ap->wpa_ie.size = RSN_IE_BODY_MAX;
284                                 }
285                                 memcpy(&(ap->wpa_ie.body[0]), bp + 2,
286                                        ap->wpa_ie.size);
287                         }
288                         break;
289
290                 case 2: /* FH parameter */
291                 case 4: /* CF parameter */
292                 case 5: /* TIM */
293                 case 6: /* IBSS parameter */
294                 case 7: /* Country */
295                 case 42:        /* ERP information */
296                 case 47:        /* Reserve ID 47 Broadcom AP */
297                         break;
298                 default:
299                         DPRINTK(4, "unknown Element ID=%d\n", *bp);
300                         break;
301                 }
302                 offset += 2;    /* id & size field */
303                 offset += *(bp + 1);    /* +size offset */
304                 bp += (*(bp + 1) + 2);  /* pointer update */
305         }
306
307         return 0;
308 }
309
310 static
311 void hostif_data_indication(struct ks_wlan_private *priv)
312 {
313         unsigned int rx_ind_size;       /* indicate data size */
314         struct sk_buff *skb;
315         unsigned short auth_type;
316         unsigned char temp[256];
317
318         unsigned char RecvMIC[8];
319         char buf[128];
320         struct ether_hdr *eth_hdr;
321         unsigned short eth_proto;
322         unsigned long now;
323         struct mic_failure_t *mic_failure;
324         struct ieee802_1x_hdr *aa1x_hdr;
325         struct wpa_eapol_key *eap_key;
326         struct michel_mic_t michel_mic;
327         union iwreq_data wrqu;
328
329         DPRINTK(3, "\n");
330
331         /* min length check */
332         if (priv->rx_size <= ETH_HLEN) {
333                 DPRINTK(3, "rx_size = %d\n", priv->rx_size);
334                 priv->nstats.rx_errors++;
335                 return;
336         }
337
338         auth_type = get_WORD(priv);     /* AuthType */
339         get_WORD(priv); /* Reserve Area */
340
341         eth_hdr = (struct ether_hdr *)(priv->rxp);
342         eth_proto = ntohs(eth_hdr->h_proto);
343         DPRINTK(3, "ether protocol = %04X\n", eth_proto);
344
345         /* source address check */
346         if (!memcmp(&priv->eth_addr[0], eth_hdr->h_source, ETH_ALEN)) {
347                 DPRINTK(1, "invalid : source is own mac address !!\n");
348                 DPRINTK(1,
349                         "eth_hdrernet->h_dest=%02X:%02X:%02X:%02X:%02X:%02X\n",
350                         eth_hdr->h_source[0], eth_hdr->h_source[1],
351                         eth_hdr->h_source[2], eth_hdr->h_source[3],
352                         eth_hdr->h_source[4], eth_hdr->h_source[5]);
353                 priv->nstats.rx_errors++;
354                 return;
355         }
356
357         /*  for WPA */
358         if (auth_type != TYPE_DATA && priv->wpa.rsn_enabled) {
359                 if (memcmp(&eth_hdr->h_source[0], &priv->eth_addr[0], ETH_ALEN)) {      /* source address check */
360                         if (eth_hdr->h_dest_snap != eth_hdr->h_source_snap) {
361                                 DPRINTK(1, "invalid data format\n");
362                                 priv->nstats.rx_errors++;
363                                 return;
364                         }
365                         if (((auth_type == TYPE_PMK1
366                               && priv->wpa.pairwise_suite ==
367                               IW_AUTH_CIPHER_TKIP) || (auth_type == TYPE_GMK1
368                                                        && priv->wpa.
369                                                        group_suite ==
370                                                        IW_AUTH_CIPHER_TKIP)
371                              || (auth_type == TYPE_GMK2
372                                  && priv->wpa.group_suite ==
373                                  IW_AUTH_CIPHER_TKIP))
374                             && priv->wpa.key[auth_type - 1].key_len) {
375                                 DPRINTK(4, "TKIP: protocol=%04X: size=%u\n",
376                                         eth_proto, priv->rx_size);
377                                 /* MIC save */
378                                 memcpy(&RecvMIC[0],
379                                        (priv->rxp) + ((priv->rx_size) - 8), 8);
380                                 priv->rx_size = priv->rx_size - 8;
381                                 if (auth_type > 0 && auth_type < 4) {   /* auth_type check */
382                                         MichaelMICFunction(&michel_mic, (uint8_t *) priv->wpa.key[auth_type - 1].rx_mic_key, (uint8_t *) priv->rxp, (int)priv->rx_size, (uint8_t) 0,    /* priority */
383                                                            (uint8_t *)
384                                                            michel_mic.Result);
385                                 }
386                                 if (memcmp(michel_mic.Result, RecvMIC, 8)) {
387                                         now = jiffies;
388                                         mic_failure = &priv->wpa.mic_failure;
389                                         /* MIC FAILURE */
390                                         if (mic_failure->last_failure_time &&
391                                             (now -
392                                              mic_failure->last_failure_time) /
393                                             HZ >= 60) {
394                                                 mic_failure->failure = 0;
395                                         }
396                                         DPRINTK(4, "MIC FAILURE\n");
397                                         if (mic_failure->failure == 0) {
398                                                 mic_failure->failure = 1;
399                                                 mic_failure->counter = 0;
400                                         } else if (mic_failure->failure == 1) {
401                                                 mic_failure->failure = 2;
402                                                 mic_failure->counter =
403                                                     (uint16_t) ((now -
404                                                                  mic_failure->
405                                                                  last_failure_time)
406                                                                 / HZ);
407                                                 if (!mic_failure->counter)      /* mic_failure counter value range 1-60 */
408                                                         mic_failure->counter =
409                                                             1;
410                                         }
411                                         priv->wpa.mic_failure.
412                                             last_failure_time = now;
413                                         /*  needed parameters: count, keyid, key type, TSC */
414                                         sprintf(buf,
415                                                 "MLME-MICHAELMICFAILURE.indication(keyid=%d %scast addr="
416                                                 "%pM)",
417                                                 auth_type - 1,
418                                                 eth_hdr->
419                                                 h_dest[0] & 0x01 ? "broad" :
420                                                 "uni", eth_hdr->h_source);
421                                         memset(&wrqu, 0, sizeof(wrqu));
422                                         wrqu.data.length = strlen(buf);
423                                         DPRINTK(4,
424                                                 "IWEVENT:MICHAELMICFAILURE\n");
425                                         wireless_send_event(priv->net_dev,
426                                                             IWEVCUSTOM, &wrqu,
427                                                             buf);
428                                         return;
429                                 }
430                         }
431                 }
432         }
433
434         if ((priv->connect_status & FORCE_DISCONNECT) ||
435             priv->wpa.mic_failure.failure == 2) {
436                 return;
437         }
438
439         /* check 13th byte at rx data */
440         switch (*(priv->rxp + 12)) {
441         case 0xAA:      /* SNAP */
442                 rx_ind_size = priv->rx_size - 6;
443                 skb = dev_alloc_skb(rx_ind_size);
444                 DPRINTK(4, "SNAP, rx_ind_size = %d\n", rx_ind_size);
445
446                 if (skb) {
447                         memcpy(skb_put(skb, 12), priv->rxp, 12);        /* 8802/FDDI MAC copy */
448                         /* (SNAP+UI..) skip */
449                         memcpy(skb_put(skb, rx_ind_size - 12), priv->rxp + 18, rx_ind_size - 12);       /* copy after Type */
450
451                         aa1x_hdr = (struct ieee802_1x_hdr *)(priv->rxp + 20);
452                         if (aa1x_hdr->type == IEEE802_1X_TYPE_EAPOL_KEY
453                             && priv->wpa.rsn_enabled) {
454                                 eap_key =
455                                     (struct wpa_eapol_key *)(aa1x_hdr + 1);
456                                 atomic_set(&priv->psstatus.snooze_guard, 1);
457                         }
458
459                         /* rx indication */
460                         skb->dev = priv->net_dev;
461                         skb->protocol = eth_type_trans(skb, skb->dev);
462                         priv->nstats.rx_packets++;
463                         priv->nstats.rx_bytes += rx_ind_size;
464                         netif_rx(skb);
465                 } else {
466                         priv->nstats.rx_dropped++;
467                 }
468                 break;
469         case 0xF0:      /* NETBEUI/NetBIOS */
470                 rx_ind_size = (priv->rx_size + 2);
471                 skb = dev_alloc_skb(rx_ind_size);
472                 DPRINTK(3, "NETBEUI/NetBIOS rx_ind_size=%d\n", rx_ind_size);
473
474                 if (skb) {
475                         memcpy(skb_put(skb, 12), priv->rxp, 12);        /* 8802/FDDI MAC copy */
476
477                         temp[0] = (((rx_ind_size - 12) >> 8) & 0xff);   /* NETBEUI size add */
478                         temp[1] = ((rx_ind_size - 12) & 0xff);
479                         memcpy(skb_put(skb, 2), temp, 2);
480
481                         memcpy(skb_put(skb, rx_ind_size - 14), priv->rxp + 12, rx_ind_size - 14);       /* copy after Type */
482
483                         aa1x_hdr = (struct ieee802_1x_hdr *)(priv->rxp + 14);
484                         if (aa1x_hdr->type == IEEE802_1X_TYPE_EAPOL_KEY
485                             && priv->wpa.rsn_enabled) {
486                                 eap_key =
487                                     (struct wpa_eapol_key *)(aa1x_hdr + 1);
488                                 atomic_set(&priv->psstatus.snooze_guard, 1);
489                         }
490
491                         /* rx indication */
492                         skb->dev = priv->net_dev;
493                         skb->protocol = eth_type_trans(skb, skb->dev);
494                         priv->nstats.rx_packets++;
495                         priv->nstats.rx_bytes += rx_ind_size;
496                         netif_rx(skb);
497                 } else {
498                         priv->nstats.rx_dropped++;
499                 }
500                 break;
501         default:        /* other rx data */
502                 DPRINTK(2, "invalid data format\n");
503                 priv->nstats.rx_errors++;
504         }
505 }
506
507 static
508 void hostif_mib_get_confirm(struct ks_wlan_private *priv)
509 {
510         struct net_device *dev = priv->net_dev;
511         uint32_t mib_status;
512         uint32_t mib_attribute;
513         uint16_t mib_val_size;
514         uint16_t mib_val_type;
515
516         DPRINTK(3, "\n");
517
518         mib_status = get_DWORD(priv);   /* MIB status */
519         mib_attribute = get_DWORD(priv);        /* MIB atttibute */
520         mib_val_size = get_WORD(priv);  /* MIB value size */
521         mib_val_type = get_WORD(priv);  /* MIB value type */
522
523         if (mib_status != 0) {
524                 /* in case of error */
525                 DPRINTK(1, "attribute=%08X, status=%08X\n", mib_attribute,
526                         mib_status);
527                 return;
528         }
529
530         switch (mib_attribute) {
531         case DOT11_MAC_ADDRESS:
532                 /* MAC address */
533                 DPRINTK(3, " mib_attribute=DOT11_MAC_ADDRESS\n");
534                 hostif_sme_enqueue(priv, SME_GET_MAC_ADDRESS);
535                 memcpy(priv->eth_addr, priv->rxp, ETH_ALEN);
536                 priv->mac_address_valid = 1;
537                 dev->dev_addr[0] = priv->eth_addr[0];
538                 dev->dev_addr[1] = priv->eth_addr[1];
539                 dev->dev_addr[2] = priv->eth_addr[2];
540                 dev->dev_addr[3] = priv->eth_addr[3];
541                 dev->dev_addr[4] = priv->eth_addr[4];
542                 dev->dev_addr[5] = priv->eth_addr[5];
543                 dev->dev_addr[6] = 0x00;
544                 dev->dev_addr[7] = 0x00;
545                 netdev_info(dev, "MAC ADDRESS = %pM\n", priv->eth_addr);
546                 break;
547         case DOT11_PRODUCT_VERSION:
548                 /* firmware version */
549                 DPRINTK(3, " mib_attribute=DOT11_PRODUCT_VERSION\n");
550                 priv->version_size = priv->rx_size;
551                 memcpy(priv->firmware_version, priv->rxp, priv->rx_size);
552                 priv->firmware_version[priv->rx_size] = '\0';
553                 netdev_info(dev, "firmware ver. = %s\n",
554                             priv->firmware_version);
555                 hostif_sme_enqueue(priv, SME_GET_PRODUCT_VERSION);
556                 /* wake_up_interruptible_all(&priv->confirm_wait); */
557                 complete(&priv->confirm_wait);
558                 break;
559         case LOCAL_GAIN:
560                 memcpy(&priv->gain, priv->rxp, sizeof(priv->gain));
561                 DPRINTK(3, "TxMode=%d, RxMode=%d, TxGain=%d, RxGain=%d\n",
562                         priv->gain.TxMode, priv->gain.RxMode, priv->gain.TxGain,
563                         priv->gain.RxGain);
564                 break;
565         case LOCAL_EEPROM_SUM:
566                 memcpy(&priv->eeprom_sum, priv->rxp, sizeof(priv->eeprom_sum));
567                 DPRINTK(1, "eeprom_sum.type=%x, eeprom_sum.result=%x\n",
568                         priv->eeprom_sum.type, priv->eeprom_sum.result);
569                 if (priv->eeprom_sum.type == 0) {
570                         priv->eeprom_checksum = EEPROM_CHECKSUM_NONE;
571                 } else if (priv->eeprom_sum.type == 1) {
572                         if (priv->eeprom_sum.result == 0) {
573                                 priv->eeprom_checksum = EEPROM_NG;
574                                 netdev_info(dev, "LOCAL_EEPROM_SUM NG\n");
575                         } else if (priv->eeprom_sum.result == 1) {
576                                 priv->eeprom_checksum = EEPROM_OK;
577                         }
578                 } else {
579                         netdev_err(dev, "LOCAL_EEPROM_SUM error!\n");
580                 }
581                 break;
582         default:
583                 DPRINTK(1, "mib_attribute=%08x\n", (unsigned int)mib_attribute);
584                 break;
585         }
586 }
587
588 static
589 void hostif_mib_set_confirm(struct ks_wlan_private *priv)
590 {
591         uint32_t mib_status;    /* +04 MIB Status */
592         uint32_t mib_attribute; /* +08 MIB attribute */
593
594         DPRINTK(3, "\n");
595
596         mib_status = get_DWORD(priv);   /* MIB Status */
597         mib_attribute = get_DWORD(priv);        /* MIB attribute */
598
599         if (mib_status != 0) {
600                 /* in case of error */
601                 DPRINTK(1, "error :: attribute=%08X, status=%08X\n",
602                         mib_attribute, mib_status);
603         }
604
605         switch (mib_attribute) {
606         case DOT11_RTS_THRESHOLD:
607                 hostif_sme_enqueue(priv, SME_RTS_THRESHOLD_CONFIRM);
608                 break;
609         case DOT11_FRAGMENTATION_THRESHOLD:
610                 hostif_sme_enqueue(priv, SME_FRAGMENTATION_THRESHOLD_CONFIRM);
611                 break;
612         case DOT11_WEP_DEFAULT_KEY_ID:
613                 if (!priv->wpa.wpa_enabled)
614                         hostif_sme_enqueue(priv, SME_WEP_INDEX_CONFIRM);
615                 break;
616         case DOT11_WEP_DEFAULT_KEY_VALUE1:
617                 DPRINTK(2, "DOT11_WEP_DEFAULT_KEY_VALUE1:mib_status=%d\n",
618                         (int)mib_status);
619                 if (priv->wpa.rsn_enabled)
620                         hostif_sme_enqueue(priv, SME_SET_PMK_TSC);
621                 else
622                         hostif_sme_enqueue(priv, SME_WEP_KEY1_CONFIRM);
623                 break;
624         case DOT11_WEP_DEFAULT_KEY_VALUE2:
625                 DPRINTK(2, "DOT11_WEP_DEFAULT_KEY_VALUE2:mib_status=%d\n",
626                         (int)mib_status);
627                 if (priv->wpa.rsn_enabled)
628                         hostif_sme_enqueue(priv, SME_SET_GMK1_TSC);
629                 else
630                         hostif_sme_enqueue(priv, SME_WEP_KEY2_CONFIRM);
631                 break;
632         case DOT11_WEP_DEFAULT_KEY_VALUE3:
633                 DPRINTK(2, "DOT11_WEP_DEFAULT_KEY_VALUE3:mib_status=%d\n",
634                         (int)mib_status);
635                 if (priv->wpa.rsn_enabled)
636                         hostif_sme_enqueue(priv, SME_SET_GMK2_TSC);
637                 else
638                         hostif_sme_enqueue(priv, SME_WEP_KEY3_CONFIRM);
639                 break;
640         case DOT11_WEP_DEFAULT_KEY_VALUE4:
641                 DPRINTK(2, "DOT11_WEP_DEFAULT_KEY_VALUE4:mib_status=%d\n",
642                         (int)mib_status);
643                 if (!priv->wpa.rsn_enabled)
644                         hostif_sme_enqueue(priv, SME_WEP_KEY4_CONFIRM);
645                 break;
646         case DOT11_PRIVACY_INVOKED:
647                 if (!priv->wpa.rsn_enabled)
648                         hostif_sme_enqueue(priv, SME_WEP_FLAG_CONFIRM);
649                 break;
650         case DOT11_RSN_ENABLED:
651                 DPRINTK(2, "DOT11_RSN_ENABLED:mib_status=%d\n",
652                         (int)mib_status);
653                 hostif_sme_enqueue(priv, SME_RSN_ENABLED_CONFIRM);
654                 break;
655         case LOCAL_RSN_MODE:
656                 hostif_sme_enqueue(priv, SME_RSN_MODE_CONFIRM);
657                 break;
658         case LOCAL_MULTICAST_ADDRESS:
659                 hostif_sme_enqueue(priv, SME_MULTICAST_REQUEST);
660                 break;
661         case LOCAL_MULTICAST_FILTER:
662                 hostif_sme_enqueue(priv, SME_MULTICAST_CONFIRM);
663                 break;
664         case LOCAL_CURRENTADDRESS:
665                 priv->mac_address_valid = 1;
666                 break;
667         case DOT11_RSN_CONFIG_MULTICAST_CIPHER:
668                 DPRINTK(2, "DOT11_RSN_CONFIG_MULTICAST_CIPHER:mib_status=%d\n",
669                         (int)mib_status);
670                 hostif_sme_enqueue(priv, SME_RSN_MCAST_CONFIRM);
671                 break;
672         case DOT11_RSN_CONFIG_UNICAST_CIPHER:
673                 DPRINTK(2, "DOT11_RSN_CONFIG_UNICAST_CIPHER:mib_status=%d\n",
674                         (int)mib_status);
675                 hostif_sme_enqueue(priv, SME_RSN_UCAST_CONFIRM);
676                 break;
677         case DOT11_RSN_CONFIG_AUTH_SUITE:
678                 DPRINTK(2, "DOT11_RSN_CONFIG_AUTH_SUITE:mib_status=%d\n",
679                         (int)mib_status);
680                 hostif_sme_enqueue(priv, SME_RSN_AUTH_CONFIRM);
681                 break;
682         case DOT11_PMK_TSC:
683                 DPRINTK(2, "DOT11_PMK_TSC:mib_status=%d\n", (int)mib_status);
684                 break;
685         case DOT11_GMK1_TSC:
686                 DPRINTK(2, "DOT11_GMK1_TSC:mib_status=%d\n", (int)mib_status);
687                 if (atomic_read(&priv->psstatus.snooze_guard))
688                         atomic_set(&priv->psstatus.snooze_guard, 0);
689                 break;
690         case DOT11_GMK2_TSC:
691                 DPRINTK(2, "DOT11_GMK2_TSC:mib_status=%d\n", (int)mib_status);
692                 if (atomic_read(&priv->psstatus.snooze_guard))
693                         atomic_set(&priv->psstatus.snooze_guard, 0);
694                 break;
695         case LOCAL_PMK:
696                 DPRINTK(2, "LOCAL_PMK:mib_status=%d\n", (int)mib_status);
697                 break;
698         case LOCAL_GAIN:
699                 DPRINTK(2, "LOCAL_GAIN:mib_status=%d\n", (int)mib_status);
700                 break;
701 #ifdef WPS
702         case LOCAL_WPS_ENABLE:
703                 DPRINTK(2, "LOCAL_WPS_ENABLE:mib_status=%d\n", (int)mib_status);
704                 break;
705         case LOCAL_WPS_PROBE_REQ:
706                 DPRINTK(2, "LOCAL_WPS_PROBE_REQ:mib_status=%d\n",
707                         (int)mib_status);
708                 break;
709 #endif /* WPS */
710         case LOCAL_REGION:
711                 DPRINTK(2, "LOCAL_REGION:mib_status=%d\n", (int)mib_status);
712         default:
713                 break;
714         }
715 }
716
717 static
718 void hostif_power_mngmt_confirm(struct ks_wlan_private *priv)
719 {
720         DPRINTK(3, "\n");
721
722         if (priv->reg.powermgt > POWMGT_ACTIVE_MODE &&
723             priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
724                 atomic_set(&priv->psstatus.confirm_wait, 0);
725                 priv->dev_state = DEVICE_STATE_SLEEP;
726                 ks_wlan_hw_power_save(priv);
727         } else {
728                 priv->dev_state = DEVICE_STATE_READY;
729         }
730 }
731
732 static
733 void hostif_sleep_confirm(struct ks_wlan_private *priv)
734 {
735         DPRINTK(3, "\n");
736
737         atomic_set(&priv->sleepstatus.doze_request, 1);
738         queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq,
739                            &priv->ks_wlan_hw.rw_wq, 1);
740 }
741
742 static
743 void hostif_start_confirm(struct ks_wlan_private *priv)
744 {
745 #ifdef WPS
746         union iwreq_data wrqu;
747
748         wrqu.data.length = 0;
749         wrqu.data.flags = 0;
750         wrqu.ap_addr.sa_family = ARPHRD_ETHER;
751         if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
752                 eth_zero_addr(wrqu.ap_addr.sa_data);
753                 DPRINTK(3, "IWEVENT: disconnect\n");
754                 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
755         }
756 #endif
757         DPRINTK(3, " scan_ind_count=%d\n", priv->scan_ind_count);
758         hostif_sme_enqueue(priv, SME_START_CONFIRM);
759 }
760
761 static
762 void hostif_connect_indication(struct ks_wlan_private *priv)
763 {
764         unsigned short connect_code;
765         unsigned int tmp = 0;
766         unsigned int old_status = priv->connect_status;
767         struct net_device *netdev = priv->net_dev;
768         union iwreq_data wrqu0;
769
770         connect_code = get_WORD(priv);
771
772         switch (connect_code) {
773         case RESULT_CONNECT:    /* connect */
774                 DPRINTK(3, "connect :: scan_ind_count=%d\n",
775                         priv->scan_ind_count);
776                 if (!(priv->connect_status & FORCE_DISCONNECT))
777                         netif_carrier_on(netdev);
778                 tmp = FORCE_DISCONNECT & priv->connect_status;
779                 priv->connect_status = tmp + CONNECT_STATUS;
780                 break;
781         case RESULT_DISCONNECT: /* disconnect */
782                 DPRINTK(3, "disconnect :: scan_ind_count=%d\n",
783                         priv->scan_ind_count);
784                 netif_carrier_off(netdev);
785                 tmp = FORCE_DISCONNECT & priv->connect_status;
786                 priv->connect_status = tmp + DISCONNECT_STATUS;
787                 break;
788         default:
789                 DPRINTK(1, "unknown connect_code=%d :: scan_ind_count=%d\n",
790                         connect_code, priv->scan_ind_count);
791                 netif_carrier_off(netdev);
792                 tmp = FORCE_DISCONNECT & priv->connect_status;
793                 priv->connect_status = tmp + DISCONNECT_STATUS;
794                 break;
795         }
796
797         get_current_ap(priv, (struct link_ap_info_t *)priv->rxp);
798         if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS &&
799             (old_status & CONNECT_STATUS_MASK) == DISCONNECT_STATUS) {
800                 /* for power save */
801                 atomic_set(&priv->psstatus.snooze_guard, 0);
802                 atomic_set(&priv->psstatus.confirm_wait, 0);
803         }
804         ks_wlan_do_power_save(priv);
805
806         wrqu0.data.length = 0;
807         wrqu0.data.flags = 0;
808         wrqu0.ap_addr.sa_family = ARPHRD_ETHER;
809         if ((priv->connect_status & CONNECT_STATUS_MASK) == DISCONNECT_STATUS &&
810             (old_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
811                 eth_zero_addr(wrqu0.ap_addr.sa_data);
812                 DPRINTK(3, "IWEVENT: disconnect\n");
813                 DPRINTK(3, "disconnect :: scan_ind_count=%d\n",
814                         priv->scan_ind_count);
815                 wireless_send_event(netdev, SIOCGIWAP, &wrqu0, NULL);
816         }
817         priv->scan_ind_count = 0;
818 }
819
820 static
821 void hostif_scan_indication(struct ks_wlan_private *priv)
822 {
823         int i;
824         struct ap_info_t *ap_info;
825
826         DPRINTK(3, "scan_ind_count = %d\n", priv->scan_ind_count);
827         ap_info = (struct ap_info_t *)(priv->rxp);
828
829         if (priv->scan_ind_count != 0) {
830                 for (i = 0; i < priv->aplist.size; i++) {       /* bssid check */
831                         if (!memcmp
832                             (&(ap_info->bssid[0]),
833                              &(priv->aplist.ap[i].bssid[0]), ETH_ALEN)) {
834                                 if (ap_info->frame_type ==
835                                     FRAME_TYPE_PROBE_RESP)
836                                         get_ap_information(priv, ap_info,
837                                                            &(priv->aplist.
838                                                              ap[i]));
839                                 return;
840                         }
841                 }
842         }
843         priv->scan_ind_count++;
844         if (priv->scan_ind_count < LOCAL_APLIST_MAX + 1) {
845                 DPRINTK(4, " scan_ind_count=%d :: aplist.size=%d\n",
846                         priv->scan_ind_count, priv->aplist.size);
847                 get_ap_information(priv, (struct ap_info_t *)(priv->rxp),
848                                    &(priv->aplist.
849                                      ap[priv->scan_ind_count - 1]));
850                 priv->aplist.size = priv->scan_ind_count;
851         } else {
852                 DPRINTK(4, " count over :: scan_ind_count=%d\n",
853                         priv->scan_ind_count);
854         }
855 }
856
857 static
858 void hostif_stop_confirm(struct ks_wlan_private *priv)
859 {
860         unsigned int tmp = 0;
861         unsigned int old_status = priv->connect_status;
862         struct net_device *netdev = priv->net_dev;
863         union iwreq_data wrqu0;
864
865         DPRINTK(3, "\n");
866         if (priv->dev_state == DEVICE_STATE_SLEEP)
867                 priv->dev_state = DEVICE_STATE_READY;
868
869         /* disconnect indication */
870         if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
871                 netif_carrier_off(netdev);
872                 tmp = FORCE_DISCONNECT & priv->connect_status;
873                 priv->connect_status = tmp | DISCONNECT_STATUS;
874                 netdev_info(netdev, "IWEVENT: disconnect\n");
875
876                 wrqu0.data.length = 0;
877                 wrqu0.data.flags = 0;
878                 wrqu0.ap_addr.sa_family = ARPHRD_ETHER;
879                 if ((priv->connect_status & CONNECT_STATUS_MASK) ==
880                     DISCONNECT_STATUS
881                     && (old_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
882                         eth_zero_addr(wrqu0.ap_addr.sa_data);
883                         DPRINTK(3, "IWEVENT: disconnect\n");
884                         netdev_info(netdev, "IWEVENT: disconnect\n");
885                         DPRINTK(3, "disconnect :: scan_ind_count=%d\n",
886                                 priv->scan_ind_count);
887                         wireless_send_event(netdev, SIOCGIWAP, &wrqu0, NULL);
888                 }
889                 priv->scan_ind_count = 0;
890         }
891
892         hostif_sme_enqueue(priv, SME_STOP_CONFIRM);
893 }
894
895 static
896 void hostif_ps_adhoc_set_confirm(struct ks_wlan_private *priv)
897 {
898         DPRINTK(3, "\n");
899         priv->infra_status = 0; /* infrastructure mode cancel */
900         hostif_sme_enqueue(priv, SME_MODE_SET_CONFIRM);
901 }
902
903 static
904 void hostif_infrastructure_set_confirm(struct ks_wlan_private *priv)
905 {
906         uint16_t result_code;
907
908         DPRINTK(3, "\n");
909         result_code = get_WORD(priv);
910         DPRINTK(3, "result code = %d\n", result_code);
911         priv->infra_status = 1; /* infrastructure mode set */
912         hostif_sme_enqueue(priv, SME_MODE_SET_CONFIRM);
913 }
914
915 static
916 void hostif_adhoc_set_confirm(struct ks_wlan_private *priv)
917 {
918         DPRINTK(3, "\n");
919         priv->infra_status = 1; /* infrastructure mode set */
920         hostif_sme_enqueue(priv, SME_MODE_SET_CONFIRM);
921 }
922
923 static
924 void hostif_associate_indication(struct ks_wlan_private *priv)
925 {
926         struct association_request_t *assoc_req;
927         struct association_response_t *assoc_resp;
928         unsigned char *pb;
929         union iwreq_data wrqu;
930         char buf[IW_CUSTOM_MAX];
931         char *pbuf = &buf[0];
932         int i;
933
934         static const char associnfo_leader0[] = "ASSOCINFO(ReqIEs=";
935         static const char associnfo_leader1[] = " RespIEs=";
936
937         DPRINTK(3, "\n");
938         assoc_req = (struct association_request_t *)(priv->rxp);
939         assoc_resp = (struct association_response_t *)(assoc_req + 1);
940         pb = (unsigned char *)(assoc_resp + 1);
941
942         memset(&wrqu, 0, sizeof(wrqu));
943         memcpy(pbuf, associnfo_leader0, sizeof(associnfo_leader0) - 1);
944         wrqu.data.length += sizeof(associnfo_leader0) - 1;
945         pbuf += sizeof(associnfo_leader0) - 1;
946
947         for (i = 0; i < assoc_req->reqIEs_size; i++)
948                 pbuf += sprintf(pbuf, "%02x", *(pb + i));
949         wrqu.data.length += (assoc_req->reqIEs_size) * 2;
950
951         memcpy(pbuf, associnfo_leader1, sizeof(associnfo_leader1) - 1);
952         wrqu.data.length += sizeof(associnfo_leader1) - 1;
953         pbuf += sizeof(associnfo_leader1) - 1;
954
955         pb += assoc_req->reqIEs_size;
956         for (i = 0; i < assoc_resp->respIEs_size; i++)
957                 pbuf += sprintf(pbuf, "%02x", *(pb + i));
958         wrqu.data.length += (assoc_resp->respIEs_size) * 2;
959
960         pbuf += sprintf(pbuf, ")");
961         wrqu.data.length += 1;
962
963         DPRINTK(3, "IWEVENT:ASSOCINFO\n");
964         wireless_send_event(priv->net_dev, IWEVCUSTOM, &wrqu, buf);
965 }
966
967 static
968 void hostif_bss_scan_confirm(struct ks_wlan_private *priv)
969 {
970         unsigned int result_code;
971         struct net_device *dev = priv->net_dev;
972         union iwreq_data wrqu;
973
974         result_code = get_DWORD(priv);
975         DPRINTK(2, "result=%d :: scan_ind_count=%d\n", result_code,
976                 priv->scan_ind_count);
977
978         priv->sme_i.sme_flag &= ~SME_AP_SCAN;
979         hostif_sme_enqueue(priv, SME_BSS_SCAN_CONFIRM);
980
981         wrqu.data.length = 0;
982         wrqu.data.flags = 0;
983         DPRINTK(3, "IWEVENT: SCAN CONFIRM\n");
984         wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
985         priv->scan_ind_count = 0;
986 }
987
988 static
989 void hostif_phy_information_confirm(struct ks_wlan_private *priv)
990 {
991         struct iw_statistics *wstats = &priv->wstats;
992         unsigned char rssi, signal, noise;
993         unsigned char LinkSpeed;
994         unsigned int TransmittedFrameCount, ReceivedFragmentCount;
995         unsigned int FailedCount, FCSErrorCount;
996
997         DPRINTK(3, "\n");
998         rssi = get_BYTE(priv);
999         signal = get_BYTE(priv);
1000         noise = get_BYTE(priv);
1001         LinkSpeed = get_BYTE(priv);
1002         TransmittedFrameCount = get_DWORD(priv);
1003         ReceivedFragmentCount = get_DWORD(priv);
1004         FailedCount = get_DWORD(priv);
1005         FCSErrorCount = get_DWORD(priv);
1006
1007         DPRINTK(4, "phyinfo confirm rssi=%d signal=%d\n", rssi, signal);
1008         priv->current_rate = (LinkSpeed & RATE_MASK);
1009         wstats->qual.qual = signal;
1010         wstats->qual.level = 256 - rssi;
1011         wstats->qual.noise = 0; /* invalid noise value */
1012         wstats->qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
1013
1014         DPRINTK(3, "\n    rssi=%u\n    signal=%u\n    LinkSpeed=%ux500Kbps\n \
1015    TransmittedFrameCount=%u\n    ReceivedFragmentCount=%u\n    FailedCount=%u\n \
1016    FCSErrorCount=%u\n", rssi, signal, LinkSpeed, TransmittedFrameCount, ReceivedFragmentCount, FailedCount, FCSErrorCount);
1017
1018         /* wake_up_interruptible_all(&priv->confirm_wait); */
1019         complete(&priv->confirm_wait);
1020 }
1021
1022 static
1023 void hostif_mic_failure_confirm(struct ks_wlan_private *priv)
1024 {
1025         DPRINTK(3, "mic_failure=%u\n", priv->wpa.mic_failure.failure);
1026         hostif_sme_enqueue(priv, SME_MIC_FAILURE_CONFIRM);
1027 }
1028
1029 static
1030 void hostif_event_check(struct ks_wlan_private *priv)
1031 {
1032         unsigned short event;
1033
1034         DPRINTK(4, "\n");
1035         event = get_WORD(priv); /* get event */
1036         switch (event) {
1037         case HIF_DATA_IND:
1038                 hostif_data_indication(priv);
1039                 break;
1040         case HIF_MIB_GET_CONF:
1041                 hostif_mib_get_confirm(priv);
1042                 break;
1043         case HIF_MIB_SET_CONF:
1044                 hostif_mib_set_confirm(priv);
1045                 break;
1046         case HIF_POWERMGT_CONF:
1047                 hostif_power_mngmt_confirm(priv);
1048                 break;
1049         case HIF_SLEEP_CONF:
1050                 hostif_sleep_confirm(priv);
1051                 break;
1052         case HIF_START_CONF:
1053                 hostif_start_confirm(priv);
1054                 break;
1055         case HIF_CONNECT_IND:
1056                 hostif_connect_indication(priv);
1057                 break;
1058         case HIF_STOP_CONF:
1059                 hostif_stop_confirm(priv);
1060                 break;
1061         case HIF_PS_ADH_SET_CONF:
1062                 hostif_ps_adhoc_set_confirm(priv);
1063                 break;
1064         case HIF_INFRA_SET_CONF:
1065         case HIF_INFRA_SET2_CONF:
1066                 hostif_infrastructure_set_confirm(priv);
1067                 break;
1068         case HIF_ADH_SET_CONF:
1069         case HIF_ADH_SET2_CONF:
1070                 hostif_adhoc_set_confirm(priv);
1071                 break;
1072         case HIF_ASSOC_INFO_IND:
1073                 hostif_associate_indication(priv);
1074                 break;
1075         case HIF_MIC_FAILURE_CONF:
1076                 hostif_mic_failure_confirm(priv);
1077                 break;
1078         case HIF_SCAN_CONF:
1079                 hostif_bss_scan_confirm(priv);
1080                 break;
1081         case HIF_PHY_INFO_CONF:
1082         case HIF_PHY_INFO_IND:
1083                 hostif_phy_information_confirm(priv);
1084                 break;
1085         case HIF_SCAN_IND:
1086                 hostif_scan_indication(priv);
1087                 break;
1088         case HIF_AP_SET_CONF:
1089         default:
1090                 //DPRINTK(1, "undefined event[%04X]\n", event);
1091                 netdev_err(priv->net_dev, "undefined event[%04X]\n", event);
1092                 /* wake_up_all(&priv->confirm_wait); */
1093                 complete(&priv->confirm_wait);
1094                 break;
1095         }
1096
1097         /* add event to hostt buffer */
1098         priv->hostt.buff[priv->hostt.qtail] = event;
1099         priv->hostt.qtail = (priv->hostt.qtail + 1) % SME_EVENT_BUFF_SIZE;
1100 }
1101
1102 #define CHECK_ALINE(size) (size % 4 ? (size + (4 - (size % 4))) : size)
1103
1104 int hostif_data_request(struct ks_wlan_private *priv, struct sk_buff *packet)
1105 {
1106         unsigned int packet_len = 0;
1107
1108         unsigned char *buffer = NULL;
1109         unsigned int length = 0;
1110         struct hostif_data_request_t *pp;
1111         unsigned char *p;
1112         int result = 0;
1113         unsigned short eth_proto;
1114         struct ether_hdr *eth_hdr;
1115         struct michel_mic_t michel_mic;
1116         unsigned short keyinfo = 0;
1117         struct ieee802_1x_hdr *aa1x_hdr;
1118         struct wpa_eapol_key *eap_key;
1119         struct ethhdr *eth;
1120
1121         packet_len = packet->len;
1122         if (packet_len > ETH_FRAME_LEN) {
1123                 DPRINTK(1, "bad length packet_len=%d\n", packet_len);
1124                 dev_kfree_skb(packet);
1125                 return -1;
1126         }
1127
1128         if (((priv->connect_status & CONNECT_STATUS_MASK) == DISCONNECT_STATUS)
1129             || (priv->connect_status & FORCE_DISCONNECT)
1130             || priv->wpa.mic_failure.stop) {
1131                 DPRINTK(3, " DISCONNECT\n");
1132                 if (netif_queue_stopped(priv->net_dev))
1133                         netif_wake_queue(priv->net_dev);
1134                 if (packet)
1135                         dev_kfree_skb(packet);
1136
1137                 return 0;
1138         }
1139
1140         /* for PowerSave */
1141         if (atomic_read(&priv->psstatus.status) == PS_SNOOZE) { /* power save wakeup */
1142                 if (!netif_queue_stopped(priv->net_dev))
1143                         netif_stop_queue(priv->net_dev);
1144         }
1145
1146         DPRINTK(4, "skb_buff length=%d\n", packet_len);
1147         pp = kmalloc(hif_align_size(sizeof(*pp) + 6 + packet_len + 8),
1148                      KS_WLAN_MEM_FLAG);
1149
1150         if (!pp) {
1151                 DPRINTK(3, "allocate memory failed..\n");
1152                 dev_kfree_skb(packet);
1153                 return -2;
1154         }
1155
1156         p = (unsigned char *)pp->data;
1157
1158         buffer = packet->data;
1159         length = packet->len;
1160
1161         /* packet check */
1162         eth = (struct ethhdr *)packet->data;
1163         if (memcmp(&priv->eth_addr[0], eth->h_source, ETH_ALEN)) {
1164                 DPRINTK(1, "invalid mac address !!\n");
1165                 DPRINTK(1, "ethernet->h_source=%pM\n", eth->h_source);
1166                 dev_kfree_skb(packet);
1167                 kfree(pp);
1168                 return -3;
1169         }
1170
1171         /* MAC address copy */
1172         memcpy(p, buffer, 12);  /* DST/SRC MAC address */
1173         p += 12;
1174         buffer += 12;
1175         length -= 12;
1176         /* EtherType/Length check */
1177         if (*(buffer + 1) + (*buffer << 8) > 1500) {
1178                 /* ProtocolEAP = *(buffer+1) + (*buffer << 8); */
1179                 /* DPRINTK(2, "Send [SNAP]Type %x\n",ProtocolEAP); */
1180                 /* SAP/CTL/OUI(6 byte) add */
1181                 *p++ = 0xAA;    /* DSAP */
1182                 *p++ = 0xAA;    /* SSAP */
1183                 *p++ = 0x03;    /* CTL */
1184                 *p++ = 0x00;    /* OUI ("000000") */
1185                 *p++ = 0x00;    /* OUI ("000000") */
1186                 *p++ = 0x00;    /* OUI ("000000") */
1187                 packet_len += 6;
1188         } else {
1189                 DPRINTK(4, "DIX\n");
1190                 /* Length(2 byte) delete */
1191                 buffer += 2;
1192                 length -= 2;
1193                 packet_len -= 2;
1194         }
1195
1196         /* pp->data copy */
1197         memcpy(p, buffer, length);
1198
1199         p += length;
1200
1201         /* for WPA */
1202         eth_hdr = (struct ether_hdr *)&pp->data[0];
1203         eth_proto = ntohs(eth_hdr->h_proto);
1204
1205         /* for MIC FAILURE REPORT check */
1206         if (eth_proto == ETHER_PROTOCOL_TYPE_EAP
1207             && priv->wpa.mic_failure.failure > 0) {
1208                 aa1x_hdr = (struct ieee802_1x_hdr *)(eth_hdr + 1);
1209                 if (aa1x_hdr->type == IEEE802_1X_TYPE_EAPOL_KEY) {
1210                         eap_key = (struct wpa_eapol_key *)(aa1x_hdr + 1);
1211                         keyinfo = ntohs(eap_key->key_info);
1212                 }
1213         }
1214
1215         if (priv->wpa.rsn_enabled && priv->wpa.key[0].key_len) {
1216                 if (eth_proto == ETHER_PROTOCOL_TYPE_EAP
1217                     && !(priv->wpa.key[1].key_len)
1218                     && !(priv->wpa.key[2].key_len)
1219                     && !(priv->wpa.key[3].key_len)) {
1220                         pp->auth_type = cpu_to_le16((uint16_t) TYPE_AUTH);      /* no encryption */
1221                 } else {
1222                         if (priv->wpa.pairwise_suite == IW_AUTH_CIPHER_TKIP) {
1223                                 MichaelMICFunction(&michel_mic, (uint8_t *) priv->wpa.key[0].tx_mic_key, (uint8_t *) &pp->data[0], (int)packet_len, (uint8_t) 0,        /* priority */
1224                                                    (uint8_t *) michel_mic.
1225                                                    Result);
1226                                 memcpy(p, michel_mic.Result, 8);
1227                                 length += 8;
1228                                 packet_len += 8;
1229                                 p += 8;
1230                                 pp->auth_type =
1231                                     cpu_to_le16((uint16_t) TYPE_DATA);
1232
1233                         } else if (priv->wpa.pairwise_suite ==
1234                                    IW_AUTH_CIPHER_CCMP) {
1235                                 pp->auth_type =
1236                                     cpu_to_le16((uint16_t) TYPE_DATA);
1237                         }
1238                 }
1239         } else {
1240                 if (eth_proto == ETHER_PROTOCOL_TYPE_EAP)
1241                         pp->auth_type = cpu_to_le16((uint16_t) TYPE_AUTH);
1242                 else
1243                         pp->auth_type = cpu_to_le16((uint16_t) TYPE_DATA);
1244         }
1245
1246         /* header value set */
1247         pp->header.size =
1248             cpu_to_le16((uint16_t)
1249                         (sizeof(*pp) - sizeof(pp->header.size) + packet_len));
1250         pp->header.event = cpu_to_le16((uint16_t) HIF_DATA_REQ);
1251
1252         /* tx request */
1253         result =
1254             ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp) + packet_len),
1255                           (void *)send_packet_complete, (void *)priv,
1256                           (void *)packet);
1257
1258         /* MIC FAILURE REPORT check */
1259         if (eth_proto == ETHER_PROTOCOL_TYPE_EAP
1260             && priv->wpa.mic_failure.failure > 0) {
1261                 if (keyinfo & WPA_KEY_INFO_ERROR
1262                     && keyinfo & WPA_KEY_INFO_REQUEST) {
1263                         DPRINTK(3, " MIC ERROR Report SET : %04X\n", keyinfo);
1264                         hostif_sme_enqueue(priv, SME_MIC_FAILURE_REQUEST);
1265                 }
1266                 if (priv->wpa.mic_failure.failure == 2)
1267                         priv->wpa.mic_failure.stop = 1;
1268         }
1269
1270         return result;
1271 }
1272
1273 #define ps_confirm_wait_inc(priv) do { \
1274         if (atomic_read(&priv->psstatus.status) > PS_ACTIVE_SET) { \
1275                 atomic_inc(&priv->psstatus.confirm_wait); \
1276                 /* atomic_set(&priv->psstatus.status, PS_CONF_WAIT);*/ \
1277         } } while (0)
1278
1279 static
1280 void hostif_mib_get_request(struct ks_wlan_private *priv,
1281                             unsigned long mib_attribute)
1282 {
1283         struct hostif_mib_get_request_t *pp;
1284
1285         DPRINTK(3, "\n");
1286
1287         /* make primitive */
1288         pp = kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
1289         if (!pp) {
1290                 DPRINTK(3, "allocate memory failed..\n");
1291                 return;
1292         }
1293         pp->header.size =
1294             cpu_to_le16((uint16_t) (sizeof(*pp) - sizeof(pp->header.size)));
1295         pp->header.event = cpu_to_le16((uint16_t) HIF_MIB_GET_REQ);
1296         pp->mib_attribute = cpu_to_le32((uint32_t) mib_attribute);
1297
1298         /* send to device request */
1299         ps_confirm_wait_inc(priv);
1300         ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1301 }
1302
1303 static
1304 void hostif_mib_set_request(struct ks_wlan_private *priv,
1305                             unsigned long mib_attribute, unsigned short size,
1306                             unsigned short type, void *vp)
1307 {
1308         struct hostif_mib_set_request_t *pp;
1309
1310         DPRINTK(3, "\n");
1311
1312         if (priv->dev_state < DEVICE_STATE_BOOT) {
1313                 DPRINTK(3, "DeviceRemove\n");
1314                 return;
1315         }
1316
1317         /* make primitive */
1318         pp = kmalloc(hif_align_size(sizeof(*pp) + size), KS_WLAN_MEM_FLAG);
1319         if (!pp) {
1320                 DPRINTK(3, "allocate memory failed..\n");
1321                 return;
1322         }
1323
1324         pp->header.size =
1325             cpu_to_le16((uint16_t)
1326                         (sizeof(*pp) - sizeof(pp->header.size) + size));
1327         pp->header.event = cpu_to_le16((uint16_t) HIF_MIB_SET_REQ);
1328         pp->mib_attribute = cpu_to_le32((uint32_t) mib_attribute);
1329         pp->mib_value.size = cpu_to_le16((uint16_t) size);
1330         pp->mib_value.type = cpu_to_le16((uint16_t) type);
1331         memcpy(&pp->mib_value.body, vp, size);
1332
1333         /* send to device request */
1334         ps_confirm_wait_inc(priv);
1335         ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp) + size), NULL, NULL,
1336                       NULL);
1337 }
1338
1339 static
1340 void hostif_start_request(struct ks_wlan_private *priv, unsigned char mode)
1341 {
1342         struct hostif_start_request_t *pp;
1343
1344         DPRINTK(3, "\n");
1345
1346         /* make primitive */
1347         pp = kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
1348         if (!pp) {
1349                 DPRINTK(3, "allocate memory failed..\n");
1350                 return;
1351         }
1352         pp->header.size =
1353             cpu_to_le16((uint16_t) (sizeof(*pp) - sizeof(pp->header.size)));
1354         pp->header.event = cpu_to_le16((uint16_t) HIF_START_REQ);
1355         pp->mode = cpu_to_le16((uint16_t) mode);
1356
1357         /* send to device request */
1358         ps_confirm_wait_inc(priv);
1359         ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1360
1361         priv->aplist.size = 0;
1362         priv->scan_ind_count = 0;
1363 }
1364
1365 static
1366 void hostif_ps_adhoc_set_request(struct ks_wlan_private *priv)
1367 {
1368         struct hostif_ps_adhoc_set_request_t *pp;
1369         uint16_t capability;
1370
1371         DPRINTK(3, "\n");
1372
1373         /* make primitive */
1374         pp = kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
1375         if (!pp) {
1376                 DPRINTK(3, "allocate memory failed..\n");
1377                 return;
1378         }
1379         memset(pp, 0, sizeof(*pp));
1380         pp->header.size =
1381             cpu_to_le16((uint16_t) (sizeof(*pp) - sizeof(pp->header.size)));
1382         pp->header.event = cpu_to_le16((uint16_t) HIF_PS_ADH_SET_REQ);
1383         pp->phy_type = cpu_to_le16((uint16_t) (priv->reg.phy_type));
1384         pp->cts_mode = cpu_to_le16((uint16_t) (priv->reg.cts_mode));
1385         pp->scan_type = cpu_to_le16((uint16_t) (priv->reg.scan_type));
1386         pp->channel = cpu_to_le16((uint16_t) (priv->reg.channel));
1387         pp->rate_set.size = priv->reg.rate_set.size;
1388         memcpy(&pp->rate_set.body[0], &priv->reg.rate_set.body[0],
1389                priv->reg.rate_set.size);
1390
1391         capability = 0x0000;
1392         if (priv->reg.preamble == SHORT_PREAMBLE) {
1393                 /* short preamble */
1394                 capability |= BSS_CAP_SHORT_PREAMBLE;
1395         }
1396         capability &= ~(BSS_CAP_PBCC);  /* pbcc not support */
1397         if (priv->reg.phy_type != D_11B_ONLY_MODE) {
1398                 capability |= BSS_CAP_SHORT_SLOT_TIME;  /* ShortSlotTime support */
1399                 capability &= ~(BSS_CAP_DSSS_OFDM);     /* DSSS OFDM */
1400         }
1401         pp->capability = cpu_to_le16((uint16_t) capability);
1402
1403         /* send to device request */
1404         ps_confirm_wait_inc(priv);
1405         ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1406 }
1407
1408 static
1409 void hostif_infrastructure_set_request(struct ks_wlan_private *priv)
1410 {
1411         struct hostif_infrastructure_set_request_t *pp;
1412         uint16_t capability;
1413
1414         DPRINTK(3, "ssid.size=%d\n", priv->reg.ssid.size);
1415
1416         /* make primitive */
1417         pp = kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
1418         if (!pp) {
1419                 DPRINTK(3, "allocate memory failed..\n");
1420                 return;
1421         }
1422         pp->header.size =
1423             cpu_to_le16((uint16_t) (sizeof(*pp) - sizeof(pp->header.size)));
1424         pp->header.event = cpu_to_le16((uint16_t) 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));
1428
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);
1434
1435         capability = 0x0000;
1436         if (priv->reg.preamble == SHORT_PREAMBLE) {
1437                 /* short preamble */
1438                 capability |= BSS_CAP_SHORT_PREAMBLE;
1439         }
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 */
1444         }
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));
1449
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;
1465         } else {
1466                 pp->channel_list.body[13] = 14;
1467                 pp->channel_list.size = 14;
1468         }
1469
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, NULL);
1473 }
1474
1475 static void hostif_infrastructure_set2_request(struct ks_wlan_private *priv)
1476 {
1477         struct hostif_infrastructure_set2_request_t *pp;
1478         uint16_t capability;
1479
1480         DPRINTK(2, "ssid.size=%d\n", priv->reg.ssid.size);
1481
1482         /* make primitive */
1483         pp = kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
1484         if (!pp) {
1485                 DPRINTK(3, "allocate memory failed..\n");
1486                 return;
1487         }
1488         pp->header.size =
1489             cpu_to_le16((uint16_t) (sizeof(*pp) - sizeof(pp->header.size)));
1490         pp->header.event = cpu_to_le16((uint16_t) HIF_INFRA_SET2_REQ);
1491         pp->phy_type = cpu_to_le16((uint16_t) (priv->reg.phy_type));
1492         pp->cts_mode = cpu_to_le16((uint16_t) (priv->reg.cts_mode));
1493         pp->scan_type = cpu_to_le16((uint16_t) (priv->reg.scan_type));
1494
1495         pp->rate_set.size = priv->reg.rate_set.size;
1496         memcpy(&pp->rate_set.body[0], &priv->reg.rate_set.body[0],
1497                priv->reg.rate_set.size);
1498         pp->ssid.size = priv->reg.ssid.size;
1499         memcpy(&pp->ssid.body[0], &priv->reg.ssid.body[0], priv->reg.ssid.size);
1500
1501         capability = 0x0000;
1502         if (priv->reg.preamble == SHORT_PREAMBLE) {
1503                 /* short preamble */
1504                 capability |= BSS_CAP_SHORT_PREAMBLE;
1505         }
1506         capability &= ~(BSS_CAP_PBCC);  /* pbcc not support */
1507         if (priv->reg.phy_type != D_11B_ONLY_MODE) {
1508                 capability |= BSS_CAP_SHORT_SLOT_TIME;  /* ShortSlotTime support */
1509                 capability &= ~(BSS_CAP_DSSS_OFDM);     /* DSSS OFDM not support */
1510         }
1511         pp->capability = cpu_to_le16((uint16_t) capability);
1512         pp->beacon_lost_count =
1513             cpu_to_le16((uint16_t) (priv->reg.beacon_lost_count));
1514         pp->auth_type = cpu_to_le16((uint16_t) (priv->reg.authenticate_type));
1515
1516         pp->channel_list.body[0] = 1;
1517         pp->channel_list.body[1] = 8;
1518         pp->channel_list.body[2] = 2;
1519         pp->channel_list.body[3] = 9;
1520         pp->channel_list.body[4] = 3;
1521         pp->channel_list.body[5] = 10;
1522         pp->channel_list.body[6] = 4;
1523         pp->channel_list.body[7] = 11;
1524         pp->channel_list.body[8] = 5;
1525         pp->channel_list.body[9] = 12;
1526         pp->channel_list.body[10] = 6;
1527         pp->channel_list.body[11] = 13;
1528         pp->channel_list.body[12] = 7;
1529         if (priv->reg.phy_type == D_11G_ONLY_MODE) {
1530                 pp->channel_list.size = 13;
1531         } else {
1532                 pp->channel_list.body[13] = 14;
1533                 pp->channel_list.size = 14;
1534         }
1535
1536         memcpy(pp->bssid, priv->reg.bssid, ETH_ALEN);
1537
1538         /* send to device request */
1539         ps_confirm_wait_inc(priv);
1540         ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1541 }
1542
1543 static
1544 void hostif_adhoc_set_request(struct ks_wlan_private *priv)
1545 {
1546         struct hostif_adhoc_set_request_t *pp;
1547         uint16_t capability;
1548
1549         DPRINTK(3, "\n");
1550
1551         /* make primitive */
1552         pp = kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
1553         if (!pp) {
1554                 DPRINTK(3, "allocate memory failed..\n");
1555                 return;
1556         }
1557         memset(pp, 0, sizeof(*pp));
1558         pp->header.size =
1559             cpu_to_le16((uint16_t) (sizeof(*pp) - sizeof(pp->header.size)));
1560         pp->header.event = cpu_to_le16((uint16_t) HIF_ADH_SET_REQ);
1561         pp->phy_type = cpu_to_le16((uint16_t) (priv->reg.phy_type));
1562         pp->cts_mode = cpu_to_le16((uint16_t) (priv->reg.cts_mode));
1563         pp->scan_type = cpu_to_le16((uint16_t) (priv->reg.scan_type));
1564         pp->channel = cpu_to_le16((uint16_t) (priv->reg.channel));
1565         pp->rate_set.size = priv->reg.rate_set.size;
1566         memcpy(&pp->rate_set.body[0], &priv->reg.rate_set.body[0],
1567                priv->reg.rate_set.size);
1568         pp->ssid.size = priv->reg.ssid.size;
1569         memcpy(&pp->ssid.body[0], &priv->reg.ssid.body[0], priv->reg.ssid.size);
1570
1571         capability = 0x0000;
1572         if (priv->reg.preamble == SHORT_PREAMBLE) {
1573                 /* short preamble */
1574                 capability |= BSS_CAP_SHORT_PREAMBLE;
1575         }
1576         capability &= ~(BSS_CAP_PBCC);  /* pbcc not support */
1577         if (priv->reg.phy_type != D_11B_ONLY_MODE) {
1578                 capability |= BSS_CAP_SHORT_SLOT_TIME;  /* ShortSlotTime support */
1579                 capability &= ~(BSS_CAP_DSSS_OFDM);     /* DSSS OFDM not support */
1580         }
1581         pp->capability = cpu_to_le16((uint16_t) capability);
1582
1583         /* send to device request */
1584         ps_confirm_wait_inc(priv);
1585         ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1586 }
1587
1588 static
1589 void hostif_adhoc_set2_request(struct ks_wlan_private *priv)
1590 {
1591         struct hostif_adhoc_set2_request_t *pp;
1592         uint16_t capability;
1593
1594         DPRINTK(3, "\n");
1595
1596         /* make primitive */
1597         pp = kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
1598         if (!pp) {
1599                 DPRINTK(3, "allocate memory failed..\n");
1600                 return;
1601         }
1602         memset(pp, 0, sizeof(*pp));
1603         pp->header.size =
1604             cpu_to_le16((uint16_t) (sizeof(*pp) - sizeof(pp->header.size)));
1605         pp->header.event = cpu_to_le16((uint16_t) HIF_ADH_SET_REQ);
1606         pp->phy_type = cpu_to_le16((uint16_t) (priv->reg.phy_type));
1607         pp->cts_mode = cpu_to_le16((uint16_t) (priv->reg.cts_mode));
1608         pp->scan_type = cpu_to_le16((uint16_t) (priv->reg.scan_type));
1609         pp->rate_set.size = priv->reg.rate_set.size;
1610         memcpy(&pp->rate_set.body[0], &priv->reg.rate_set.body[0],
1611                priv->reg.rate_set.size);
1612         pp->ssid.size = priv->reg.ssid.size;
1613         memcpy(&pp->ssid.body[0], &priv->reg.ssid.body[0], priv->reg.ssid.size);
1614
1615         capability = 0x0000;
1616         if (priv->reg.preamble == SHORT_PREAMBLE) {
1617                 /* short preamble */
1618                 capability |= BSS_CAP_SHORT_PREAMBLE;
1619         }
1620         capability &= ~(BSS_CAP_PBCC);  /* pbcc not support */
1621         if (priv->reg.phy_type != D_11B_ONLY_MODE) {
1622                 capability |= BSS_CAP_SHORT_SLOT_TIME;  /* ShortSlotTime support */
1623                 capability &= ~(BSS_CAP_DSSS_OFDM);     /* DSSS OFDM not support */
1624         }
1625         pp->capability = cpu_to_le16((uint16_t) capability);
1626
1627         pp->channel_list.body[0] = priv->reg.channel;
1628         pp->channel_list.size = 1;
1629         memcpy(pp->bssid, priv->reg.bssid, ETH_ALEN);
1630
1631         /* send to device request */
1632         ps_confirm_wait_inc(priv);
1633         ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1634 }
1635
1636 static
1637 void hostif_stop_request(struct ks_wlan_private *priv)
1638 {
1639         struct hostif_stop_request_t *pp;
1640
1641         DPRINTK(3, "\n");
1642
1643         /* make primitive */
1644         pp = kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
1645         if (!pp) {
1646                 DPRINTK(3, "allocate memory failed..\n");
1647                 return;
1648         }
1649         pp->header.size =
1650             cpu_to_le16((uint16_t) (sizeof(*pp) - sizeof(pp->header.size)));
1651         pp->header.event = cpu_to_le16((uint16_t) HIF_STOP_REQ);
1652
1653         /* send to device request */
1654         ps_confirm_wait_inc(priv);
1655         ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1656 }
1657
1658 static
1659 void hostif_phy_information_request(struct ks_wlan_private *priv)
1660 {
1661         struct hostif_phy_information_request_t *pp;
1662
1663         DPRINTK(3, "\n");
1664
1665         /* make primitive */
1666         pp = kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
1667         if (!pp) {
1668                 DPRINTK(3, "allocate memory failed..\n");
1669                 return;
1670         }
1671         pp->header.size =
1672             cpu_to_le16((uint16_t) (sizeof(*pp) - sizeof(pp->header.size)));
1673         pp->header.event = cpu_to_le16((uint16_t) HIF_PHY_INFO_REQ);
1674         if (priv->reg.phy_info_timer) {
1675                 pp->type = cpu_to_le16((uint16_t) TIME_TYPE);
1676                 pp->time = cpu_to_le16((uint16_t) (priv->reg.phy_info_timer));
1677         } else {
1678                 pp->type = cpu_to_le16((uint16_t) NORMAL_TYPE);
1679                 pp->time = cpu_to_le16((uint16_t) 0);
1680         }
1681
1682         /* send to device request */
1683         ps_confirm_wait_inc(priv);
1684         ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1685 }
1686
1687 static
1688 void hostif_power_mngmt_request(struct ks_wlan_private *priv,
1689                                 unsigned long mode, unsigned long wake_up,
1690                                 unsigned long receiveDTIMs)
1691 {
1692         struct hostif_power_mngmt_request_t *pp;
1693
1694         DPRINTK(3, "mode=%lu wake_up=%lu receiveDTIMs=%lu\n", mode, wake_up,
1695                 receiveDTIMs);
1696         /* make primitive */
1697         pp = kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
1698         if (!pp) {
1699                 DPRINTK(3, "allocate memory failed..\n");
1700                 return;
1701         }
1702         pp->header.size =
1703             cpu_to_le16((uint16_t) (sizeof(*pp) - sizeof(pp->header.size)));
1704         pp->header.event = cpu_to_le16((uint16_t) HIF_POWERMGT_REQ);
1705         pp->mode = cpu_to_le32((uint32_t) mode);
1706         pp->wake_up = cpu_to_le32((uint32_t) wake_up);
1707         pp->receiveDTIMs = cpu_to_le32((uint32_t) receiveDTIMs);
1708
1709         /* send to device request */
1710         ps_confirm_wait_inc(priv);
1711         ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1712 }
1713
1714 static
1715 void hostif_sleep_request(struct ks_wlan_private *priv, unsigned long mode)
1716 {
1717         struct hostif_sleep_request_t *pp;
1718
1719         DPRINTK(3, "mode=%lu\n", mode);
1720
1721         if (mode == SLP_SLEEP) {
1722                 /* make primitive */
1723                 pp = kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
1724                 if (!pp) {
1725                         DPRINTK(3, "allocate memory failed..\n");
1726                         return;
1727                 }
1728                 pp->header.size =
1729                     cpu_to_le16((uint16_t)
1730                                 (sizeof(*pp) - sizeof(pp->header.size)));
1731                 pp->header.event = cpu_to_le16((uint16_t) HIF_SLEEP_REQ);
1732
1733                 /* send to device request */
1734                 ps_confirm_wait_inc(priv);
1735                 ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL,
1736                               NULL);
1737         } else if (mode == SLP_ACTIVE) {
1738                 atomic_set(&priv->sleepstatus.wakeup_request, 1);
1739                 queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq,
1740                                    &priv->ks_wlan_hw.rw_wq, 1);
1741         } else {
1742                 DPRINTK(3, "invalid mode %ld\n", mode);
1743                 return;
1744         }
1745 }
1746
1747 static
1748 void hostif_bss_scan_request(struct ks_wlan_private *priv,
1749                              unsigned long scan_type, uint8_t *scan_ssid,
1750                              uint8_t scan_ssid_len)
1751 {
1752         struct hostif_bss_scan_request_t *pp;
1753
1754         DPRINTK(2, "\n");
1755         /* make primitive */
1756         pp = kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
1757         if (!pp) {
1758                 DPRINTK(3, "allocate memory failed..\n");
1759                 return;
1760         }
1761         pp->header.size =
1762             cpu_to_le16((uint16_t) (sizeof(*pp) - sizeof(pp->header.size)));
1763         pp->header.event = cpu_to_le16((uint16_t) HIF_SCAN_REQ);
1764         pp->scan_type = scan_type;
1765
1766         pp->ch_time_min = cpu_to_le32((uint32_t) 110);  /* default value */
1767         pp->ch_time_max = cpu_to_le32((uint32_t) 130);  /* default value */
1768         pp->channel_list.body[0] = 1;
1769         pp->channel_list.body[1] = 8;
1770         pp->channel_list.body[2] = 2;
1771         pp->channel_list.body[3] = 9;
1772         pp->channel_list.body[4] = 3;
1773         pp->channel_list.body[5] = 10;
1774         pp->channel_list.body[6] = 4;
1775         pp->channel_list.body[7] = 11;
1776         pp->channel_list.body[8] = 5;
1777         pp->channel_list.body[9] = 12;
1778         pp->channel_list.body[10] = 6;
1779         pp->channel_list.body[11] = 13;
1780         pp->channel_list.body[12] = 7;
1781         if (priv->reg.phy_type == D_11G_ONLY_MODE) {
1782                 pp->channel_list.size = 13;
1783         } else {
1784                 pp->channel_list.body[13] = 14;
1785                 pp->channel_list.size = 14;
1786         }
1787         pp->ssid.size = 0;
1788
1789         /* specified SSID SCAN */
1790         if (scan_ssid_len > 0 && scan_ssid_len <= 32) {
1791                 pp->ssid.size = scan_ssid_len;
1792                 memcpy(&pp->ssid.body[0], scan_ssid, scan_ssid_len);
1793         }
1794
1795         /* send to device request */
1796         ps_confirm_wait_inc(priv);
1797         ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1798
1799         priv->aplist.size = 0;
1800         priv->scan_ind_count = 0;
1801 }
1802
1803 static
1804 void hostif_mic_failure_request(struct ks_wlan_private *priv,
1805                                 unsigned short failure_count,
1806                                 unsigned short timer)
1807 {
1808         struct hostif_mic_failure_request_t *pp;
1809
1810         DPRINTK(3, "count=%d :: timer=%d\n", failure_count, timer);
1811         /* make primitive */
1812         pp = kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
1813         if (!pp) {
1814                 DPRINTK(3, "allocate memory failed..\n");
1815                 return;
1816         }
1817         pp->header.size =
1818             cpu_to_le16((uint16_t) (sizeof(*pp) - sizeof(pp->header.size)));
1819         pp->header.event = cpu_to_le16((uint16_t) HIF_MIC_FAILURE_REQ);
1820         pp->failure_count = cpu_to_le16((uint16_t) failure_count);
1821         pp->timer = cpu_to_le16((uint16_t) timer);
1822
1823         /* send to device request */
1824         ps_confirm_wait_inc(priv);
1825         ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1826 }
1827
1828 /* Device I/O Receive indicate */
1829 static void devio_rec_ind(struct ks_wlan_private *priv, unsigned char *p,
1830                           unsigned int size)
1831 {
1832         if (priv->device_open_status) {
1833                 spin_lock(&priv->dev_read_lock);        /* request spin lock */
1834                 priv->dev_data[atomic_read(&priv->rec_count)] = p;
1835                 priv->dev_size[atomic_read(&priv->rec_count)] = size;
1836
1837                 if (atomic_read(&priv->event_count) != DEVICE_STOCK_COUNT) {
1838                         /* rx event count inc */
1839                         atomic_inc(&priv->event_count);
1840                 }
1841                 atomic_inc(&priv->rec_count);
1842                 if (atomic_read(&priv->rec_count) == DEVICE_STOCK_COUNT)
1843                         atomic_set(&priv->rec_count, 0);
1844
1845                 wake_up_interruptible_all(&priv->devread_wait);
1846
1847                 /* release spin lock */
1848                 spin_unlock(&priv->dev_read_lock);
1849         }
1850 }
1851
1852 void hostif_receive(struct ks_wlan_private *priv, unsigned char *p,
1853                     unsigned int size)
1854 {
1855         DPRINTK(4, "\n");
1856
1857         devio_rec_ind(priv, p, size);
1858
1859         priv->rxp = p;
1860         priv->rx_size = size;
1861
1862         if (get_WORD(priv) == priv->rx_size) {  /* length check !! */
1863                 hostif_event_check(priv);       /* event check */
1864         }
1865 }
1866
1867 static
1868 void hostif_sme_set_wep(struct ks_wlan_private *priv, int type)
1869 {
1870         uint32_t val;
1871
1872         switch (type) {
1873         case SME_WEP_INDEX_REQUEST:
1874                 val = cpu_to_le32((uint32_t) (priv->reg.wep_index));
1875                 hostif_mib_set_request(priv, DOT11_WEP_DEFAULT_KEY_ID,
1876                                        sizeof(val), MIB_VALUE_TYPE_INT, &val);
1877                 break;
1878         case SME_WEP_KEY1_REQUEST:
1879                 if (!priv->wpa.wpa_enabled)
1880                         hostif_mib_set_request(priv,
1881                                                DOT11_WEP_DEFAULT_KEY_VALUE1,
1882                                                priv->reg.wep_key[0].size,
1883                                                MIB_VALUE_TYPE_OSTRING,
1884                                                &priv->reg.wep_key[0].val[0]);
1885                 break;
1886         case SME_WEP_KEY2_REQUEST:
1887                 if (!priv->wpa.wpa_enabled)
1888                         hostif_mib_set_request(priv,
1889                                                DOT11_WEP_DEFAULT_KEY_VALUE2,
1890                                                priv->reg.wep_key[1].size,
1891                                                MIB_VALUE_TYPE_OSTRING,
1892                                                &priv->reg.wep_key[1].val[0]);
1893                 break;
1894         case SME_WEP_KEY3_REQUEST:
1895                 if (!priv->wpa.wpa_enabled)
1896                         hostif_mib_set_request(priv,
1897                                                DOT11_WEP_DEFAULT_KEY_VALUE3,
1898                                                priv->reg.wep_key[2].size,
1899                                                MIB_VALUE_TYPE_OSTRING,
1900                                                &priv->reg.wep_key[2].val[0]);
1901                 break;
1902         case SME_WEP_KEY4_REQUEST:
1903                 if (!priv->wpa.wpa_enabled)
1904                         hostif_mib_set_request(priv,
1905                                                DOT11_WEP_DEFAULT_KEY_VALUE4,
1906                                                priv->reg.wep_key[3].size,
1907                                                MIB_VALUE_TYPE_OSTRING,
1908                                                &priv->reg.wep_key[3].val[0]);
1909                 break;
1910         case SME_WEP_FLAG_REQUEST:
1911                 val = cpu_to_le32((uint32_t) (priv->reg.privacy_invoked));
1912                 hostif_mib_set_request(priv, DOT11_PRIVACY_INVOKED,
1913                                        sizeof(val), MIB_VALUE_TYPE_BOOL, &val);
1914                 break;
1915         }
1916 }
1917
1918 struct wpa_suite_t {
1919         unsigned short size;
1920         unsigned char suite[4][CIPHER_ID_LEN];
1921 } __packed;
1922
1923 struct rsn_mode_t {
1924         uint32_t rsn_mode;
1925         uint16_t rsn_capability;
1926 } __packed;
1927
1928 static
1929 void hostif_sme_set_rsn(struct ks_wlan_private *priv, int type)
1930 {
1931         struct wpa_suite_t wpa_suite;
1932         struct rsn_mode_t rsn_mode;
1933         uint32_t val;
1934
1935         memset(&wpa_suite, 0, sizeof(wpa_suite));
1936
1937         switch (type) {
1938         case SME_RSN_UCAST_REQUEST:
1939                 wpa_suite.size = cpu_to_le16((uint16_t) 1);
1940                 switch (priv->wpa.pairwise_suite) {
1941                 case IW_AUTH_CIPHER_NONE:
1942                         if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
1943                                 memcpy(&wpa_suite.suite[0][0],
1944                                        CIPHER_ID_WPA2_NONE, CIPHER_ID_LEN);
1945                         else
1946                                 memcpy(&wpa_suite.suite[0][0],
1947                                        CIPHER_ID_WPA_NONE, CIPHER_ID_LEN);
1948                         break;
1949                 case IW_AUTH_CIPHER_WEP40:
1950                         if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
1951                                 memcpy(&wpa_suite.suite[0][0],
1952                                        CIPHER_ID_WPA2_WEP40, CIPHER_ID_LEN);
1953                         else
1954                                 memcpy(&wpa_suite.suite[0][0],
1955                                        CIPHER_ID_WPA_WEP40, CIPHER_ID_LEN);
1956                         break;
1957                 case IW_AUTH_CIPHER_TKIP:
1958                         if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
1959                                 memcpy(&wpa_suite.suite[0][0],
1960                                        CIPHER_ID_WPA2_TKIP, CIPHER_ID_LEN);
1961                         else
1962                                 memcpy(&wpa_suite.suite[0][0],
1963                                        CIPHER_ID_WPA_TKIP, CIPHER_ID_LEN);
1964                         break;
1965                 case IW_AUTH_CIPHER_CCMP:
1966                         if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
1967                                 memcpy(&wpa_suite.suite[0][0],
1968                                        CIPHER_ID_WPA2_CCMP, CIPHER_ID_LEN);
1969                         else
1970                                 memcpy(&wpa_suite.suite[0][0],
1971                                        CIPHER_ID_WPA_CCMP, CIPHER_ID_LEN);
1972                         break;
1973                 case IW_AUTH_CIPHER_WEP104:
1974                         if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
1975                                 memcpy(&wpa_suite.suite[0][0],
1976                                        CIPHER_ID_WPA2_WEP104, CIPHER_ID_LEN);
1977                         else
1978                                 memcpy(&wpa_suite.suite[0][0],
1979                                        CIPHER_ID_WPA_WEP104, CIPHER_ID_LEN);
1980                         break;
1981                 }
1982
1983                 hostif_mib_set_request(priv, DOT11_RSN_CONFIG_UNICAST_CIPHER,
1984                                        sizeof(wpa_suite.size) +
1985                                        CIPHER_ID_LEN * wpa_suite.size,
1986                                        MIB_VALUE_TYPE_OSTRING, &wpa_suite);
1987                 break;
1988         case SME_RSN_MCAST_REQUEST:
1989                 switch (priv->wpa.group_suite) {
1990                 case IW_AUTH_CIPHER_NONE:
1991                         if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
1992                                 memcpy(&wpa_suite.suite[0][0],
1993                                        CIPHER_ID_WPA2_NONE, CIPHER_ID_LEN);
1994                         else
1995                                 memcpy(&wpa_suite.suite[0][0],
1996                                        CIPHER_ID_WPA_NONE, CIPHER_ID_LEN);
1997                         break;
1998                 case IW_AUTH_CIPHER_WEP40:
1999                         if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
2000                                 memcpy(&wpa_suite.suite[0][0],
2001                                        CIPHER_ID_WPA2_WEP40, CIPHER_ID_LEN);
2002                         else
2003                                 memcpy(&wpa_suite.suite[0][0],
2004                                        CIPHER_ID_WPA_WEP40, CIPHER_ID_LEN);
2005                         break;
2006                 case IW_AUTH_CIPHER_TKIP:
2007                         if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
2008                                 memcpy(&wpa_suite.suite[0][0],
2009                                        CIPHER_ID_WPA2_TKIP, CIPHER_ID_LEN);
2010                         else
2011                                 memcpy(&wpa_suite.suite[0][0],
2012                                        CIPHER_ID_WPA_TKIP, CIPHER_ID_LEN);
2013                         break;
2014                 case IW_AUTH_CIPHER_CCMP:
2015                         if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
2016                                 memcpy(&wpa_suite.suite[0][0],
2017                                        CIPHER_ID_WPA2_CCMP, CIPHER_ID_LEN);
2018                         else
2019                                 memcpy(&wpa_suite.suite[0][0],
2020                                        CIPHER_ID_WPA_CCMP, CIPHER_ID_LEN);
2021                         break;
2022                 case IW_AUTH_CIPHER_WEP104:
2023                         if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
2024                                 memcpy(&wpa_suite.suite[0][0],
2025                                        CIPHER_ID_WPA2_WEP104, CIPHER_ID_LEN);
2026                         else
2027                                 memcpy(&wpa_suite.suite[0][0],
2028                                        CIPHER_ID_WPA_WEP104, CIPHER_ID_LEN);
2029                         break;
2030                 }
2031
2032                 hostif_mib_set_request(priv, DOT11_RSN_CONFIG_MULTICAST_CIPHER,
2033                                        CIPHER_ID_LEN, MIB_VALUE_TYPE_OSTRING,
2034                                        &wpa_suite.suite[0][0]);
2035                 break;
2036         case SME_RSN_AUTH_REQUEST:
2037                 wpa_suite.size = cpu_to_le16((uint16_t) 1);
2038                 switch (priv->wpa.key_mgmt_suite) {
2039                 case IW_AUTH_KEY_MGMT_802_1X:
2040                         if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
2041                                 memcpy(&wpa_suite.suite[0][0],
2042                                        KEY_MGMT_ID_WPA2_1X, KEY_MGMT_ID_LEN);
2043                         else
2044                                 memcpy(&wpa_suite.suite[0][0],
2045                                        KEY_MGMT_ID_WPA_1X, KEY_MGMT_ID_LEN);
2046                         break;
2047                 case IW_AUTH_KEY_MGMT_PSK:
2048                         if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
2049                                 memcpy(&wpa_suite.suite[0][0],
2050                                        KEY_MGMT_ID_WPA2_PSK, KEY_MGMT_ID_LEN);
2051                         else
2052                                 memcpy(&wpa_suite.suite[0][0],
2053                                        KEY_MGMT_ID_WPA_PSK, KEY_MGMT_ID_LEN);
2054                         break;
2055                 case 0:
2056                         if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
2057                                 memcpy(&wpa_suite.suite[0][0],
2058                                        KEY_MGMT_ID_WPA2_NONE, KEY_MGMT_ID_LEN);
2059                         else
2060                                 memcpy(&wpa_suite.suite[0][0],
2061                                        KEY_MGMT_ID_WPA_NONE, KEY_MGMT_ID_LEN);
2062                         break;
2063                 case 4:
2064                         if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
2065                                 memcpy(&wpa_suite.suite[0][0],
2066                                        KEY_MGMT_ID_WPA2_WPANONE,
2067                                        KEY_MGMT_ID_LEN);
2068                         else
2069                                 memcpy(&wpa_suite.suite[0][0],
2070                                        KEY_MGMT_ID_WPA_WPANONE,
2071                                        KEY_MGMT_ID_LEN);
2072                         break;
2073                 }
2074
2075                 hostif_mib_set_request(priv, DOT11_RSN_CONFIG_AUTH_SUITE,
2076                                        sizeof(wpa_suite.size) +
2077                                        KEY_MGMT_ID_LEN * wpa_suite.size,
2078                                        MIB_VALUE_TYPE_OSTRING, &wpa_suite);
2079                 break;
2080         case SME_RSN_ENABLED_REQUEST:
2081                 val = cpu_to_le32((uint32_t) (priv->wpa.rsn_enabled));
2082                 hostif_mib_set_request(priv, DOT11_RSN_ENABLED,
2083                                        sizeof(val), MIB_VALUE_TYPE_BOOL, &val);
2084                 break;
2085         case SME_RSN_MODE_REQUEST:
2086                 if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) {
2087                         rsn_mode.rsn_mode =
2088                             cpu_to_le32((uint32_t) RSN_MODE_WPA2);
2089                         rsn_mode.rsn_capability = cpu_to_le16((uint16_t) 0);
2090                 } else if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA) {
2091                         rsn_mode.rsn_mode =
2092                             cpu_to_le32((uint32_t) RSN_MODE_WPA);
2093                         rsn_mode.rsn_capability = cpu_to_le16((uint16_t) 0);
2094                 } else {
2095                         rsn_mode.rsn_mode =
2096                             cpu_to_le32((uint32_t) RSN_MODE_NONE);
2097                         rsn_mode.rsn_capability = cpu_to_le16((uint16_t) 0);
2098                 }
2099                 hostif_mib_set_request(priv, LOCAL_RSN_MODE, sizeof(rsn_mode),
2100                                        MIB_VALUE_TYPE_OSTRING, &rsn_mode);
2101                 break;
2102         }
2103 }
2104
2105 static
2106 void hostif_sme_mode_setup(struct ks_wlan_private *priv)
2107 {
2108         unsigned char rate_size;
2109         unsigned char rate_octet[RATE_SET_MAX_SIZE];
2110         int i = 0;
2111
2112         /* rate setting if rate segging is auto for changing phy_type (#94) */
2113         if (priv->reg.tx_rate == TX_RATE_FULL_AUTO) {
2114                 if (priv->reg.phy_type == D_11B_ONLY_MODE) {
2115                         priv->reg.rate_set.body[3] = TX_RATE_11M;
2116                         priv->reg.rate_set.body[2] = TX_RATE_5M;
2117                         priv->reg.rate_set.body[1] = TX_RATE_2M | BASIC_RATE;
2118                         priv->reg.rate_set.body[0] = TX_RATE_1M | BASIC_RATE;
2119                         priv->reg.rate_set.size = 4;
2120                 } else {        /* D_11G_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
2121                         priv->reg.rate_set.body[11] = TX_RATE_54M;
2122                         priv->reg.rate_set.body[10] = TX_RATE_48M;
2123                         priv->reg.rate_set.body[9] = TX_RATE_36M;
2124                         priv->reg.rate_set.body[8] = TX_RATE_18M;
2125                         priv->reg.rate_set.body[7] = TX_RATE_9M;
2126                         priv->reg.rate_set.body[6] = TX_RATE_24M | BASIC_RATE;
2127                         priv->reg.rate_set.body[5] = TX_RATE_12M | BASIC_RATE;
2128                         priv->reg.rate_set.body[4] = TX_RATE_6M | BASIC_RATE;
2129                         priv->reg.rate_set.body[3] = TX_RATE_11M | BASIC_RATE;
2130                         priv->reg.rate_set.body[2] = TX_RATE_5M | BASIC_RATE;
2131                         priv->reg.rate_set.body[1] = TX_RATE_2M | BASIC_RATE;
2132                         priv->reg.rate_set.body[0] = TX_RATE_1M | BASIC_RATE;
2133                         priv->reg.rate_set.size = 12;
2134                 }
2135         }
2136
2137         /* rate mask by phy setting */
2138         if (priv->reg.phy_type == D_11B_ONLY_MODE) {
2139                 for (i = 0; i < priv->reg.rate_set.size; i++) {
2140                         if (IS_11B_RATE(priv->reg.rate_set.body[i])) {
2141                                 if ((priv->reg.rate_set.body[i] & RATE_MASK) >=
2142                                     TX_RATE_5M)
2143                                         rate_octet[i] =
2144                                             priv->reg.rate_set.
2145                                             body[i] & RATE_MASK;
2146                                 else
2147                                         rate_octet[i] =
2148                                             priv->reg.rate_set.body[i];
2149                         } else
2150                                 break;
2151                 }
2152
2153         } else {        /* D_11G_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
2154                 for (i = 0; i < priv->reg.rate_set.size; i++) {
2155                         if (IS_11BG_RATE(priv->reg.rate_set.body[i])) {
2156                                 if (IS_OFDM_EXT_RATE
2157                                     (priv->reg.rate_set.body[i]))
2158                                         rate_octet[i] =
2159                                             priv->reg.rate_set.
2160                                             body[i] & RATE_MASK;
2161                                 else
2162                                         rate_octet[i] =
2163                                             priv->reg.rate_set.body[i];
2164                         } else
2165                                 break;
2166                 }
2167         }
2168         rate_size = i;
2169         if (rate_size == 0) {
2170                 if (priv->reg.phy_type == D_11G_ONLY_MODE)
2171                         rate_octet[0] = TX_RATE_6M | BASIC_RATE;
2172                 else
2173                         rate_octet[0] = TX_RATE_2M | BASIC_RATE;
2174                 rate_size = 1;
2175         }
2176
2177         /* rate set update */
2178         priv->reg.rate_set.size = rate_size;
2179         memcpy(&priv->reg.rate_set.body[0], &rate_octet[0], rate_size);
2180
2181         switch (priv->reg.operation_mode) {
2182         case MODE_PSEUDO_ADHOC:
2183                 /* Pseudo Ad-Hoc mode */
2184                 hostif_ps_adhoc_set_request(priv);
2185                 break;
2186         case MODE_INFRASTRUCTURE:
2187                 /* Infrastructure mode */
2188                 if (!is_valid_ether_addr((u8 *) priv->reg.bssid)) {
2189                         hostif_infrastructure_set_request(priv);
2190                 } else {
2191                         hostif_infrastructure_set2_request(priv);
2192                         DPRINTK(2,
2193                                 "Infra bssid = %pM\n", priv->reg.bssid);
2194                 }
2195                 break;
2196         case MODE_ADHOC:
2197                 /* IEEE802.11 Ad-Hoc mode */
2198                 if (!is_valid_ether_addr((u8 *) priv->reg.bssid)) {
2199                         hostif_adhoc_set_request(priv);
2200                 } else {
2201                         hostif_adhoc_set2_request(priv);
2202                         DPRINTK(2,
2203                                 "Adhoc bssid = %pM\n", priv->reg.bssid);
2204                 }
2205                 break;
2206         default:
2207                 break;
2208         }
2209 }
2210
2211 static
2212 void hostif_sme_multicast_set(struct ks_wlan_private *priv)
2213 {
2214         struct net_device *dev = priv->net_dev;
2215         int mc_count;
2216         struct netdev_hw_addr *ha;
2217         char set_address[NIC_MAX_MCAST_LIST * ETH_ALEN];
2218         unsigned long filter_type;
2219         int i = 0;
2220
2221         DPRINTK(3, "\n");
2222
2223         spin_lock(&priv->multicast_spin);
2224
2225         memset(set_address, 0, NIC_MAX_MCAST_LIST * ETH_ALEN);
2226
2227         if (dev->flags & IFF_PROMISC) {
2228                 filter_type = cpu_to_le32((uint32_t) MCAST_FILTER_PROMISC);
2229                 hostif_mib_set_request(priv, LOCAL_MULTICAST_FILTER,
2230                                        sizeof(filter_type), MIB_VALUE_TYPE_BOOL,
2231                                        &filter_type);
2232         } else if ((netdev_mc_count(dev) > NIC_MAX_MCAST_LIST)
2233                    || (dev->flags & IFF_ALLMULTI)) {
2234                 filter_type = cpu_to_le32((uint32_t) MCAST_FILTER_MCASTALL);
2235                 hostif_mib_set_request(priv, LOCAL_MULTICAST_FILTER,
2236                                        sizeof(filter_type), MIB_VALUE_TYPE_BOOL,
2237                                        &filter_type);
2238         } else {
2239                 if (priv->sme_i.sme_flag & SME_MULTICAST) {
2240                         mc_count = netdev_mc_count(dev);
2241                         netdev_for_each_mc_addr(ha, dev) {
2242                                 memcpy(&set_address[i * ETH_ALEN], ha->addr,
2243                                        ETH_ALEN);
2244                                 i++;
2245                         }
2246                         priv->sme_i.sme_flag &= ~SME_MULTICAST;
2247                         hostif_mib_set_request(priv, LOCAL_MULTICAST_ADDRESS,
2248                                                (ETH_ALEN * mc_count),
2249                                                MIB_VALUE_TYPE_OSTRING,
2250                                                &set_address[0]);
2251                 } else {
2252                         filter_type =
2253                             cpu_to_le32((uint32_t) MCAST_FILTER_MCAST);
2254                         priv->sme_i.sme_flag |= SME_MULTICAST;
2255                         hostif_mib_set_request(priv, LOCAL_MULTICAST_FILTER,
2256                                                sizeof(filter_type),
2257                                                MIB_VALUE_TYPE_BOOL,
2258                                                &filter_type);
2259                 }
2260         }
2261
2262         spin_unlock(&priv->multicast_spin);
2263 }
2264
2265 static
2266 void hostif_sme_powermgt_set(struct ks_wlan_private *priv)
2267 {
2268         unsigned long mode, wake_up, receiveDTIMs;
2269
2270         DPRINTK(3, "\n");
2271         switch (priv->reg.powermgt) {
2272         case POWMGT_ACTIVE_MODE:
2273                 mode = POWER_ACTIVE;
2274                 wake_up = 0;
2275                 receiveDTIMs = 0;
2276                 break;
2277         case POWMGT_SAVE1_MODE:
2278                 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
2279                         mode = POWER_SAVE;
2280                         wake_up = 0;
2281                         receiveDTIMs = 0;
2282                 } else {
2283                         mode = POWER_ACTIVE;
2284                         wake_up = 0;
2285                         receiveDTIMs = 0;
2286                 }
2287                 break;
2288         case POWMGT_SAVE2_MODE:
2289                 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
2290                         mode = POWER_SAVE;
2291                         wake_up = 0;
2292                         receiveDTIMs = 1;
2293                 } else {
2294                         mode = POWER_ACTIVE;
2295                         wake_up = 0;
2296                         receiveDTIMs = 0;
2297                 }
2298                 break;
2299         default:
2300                 mode = POWER_ACTIVE;
2301                 wake_up = 0;
2302                 receiveDTIMs = 0;
2303                 break;
2304         }
2305         hostif_power_mngmt_request(priv, mode, wake_up, receiveDTIMs);
2306 }
2307
2308 static
2309 void hostif_sme_sleep_set(struct ks_wlan_private *priv)
2310 {
2311         DPRINTK(3, "\n");
2312         switch (priv->sleep_mode) {
2313         case SLP_SLEEP:
2314                 hostif_sleep_request(priv, priv->sleep_mode);
2315                 break;
2316         case SLP_ACTIVE:
2317                 hostif_sleep_request(priv, priv->sleep_mode);
2318                 break;
2319         default:
2320                 break;
2321         }
2322 }
2323
2324 static
2325 void hostif_sme_set_key(struct ks_wlan_private *priv, int type)
2326 {
2327         uint32_t val;
2328
2329         switch (type) {
2330         case SME_SET_FLAG:
2331                 val = cpu_to_le32((uint32_t) (priv->reg.privacy_invoked));
2332                 hostif_mib_set_request(priv, DOT11_PRIVACY_INVOKED,
2333                                        sizeof(val), MIB_VALUE_TYPE_BOOL, &val);
2334                 break;
2335         case SME_SET_TXKEY:
2336                 val = cpu_to_le32((uint32_t) (priv->wpa.txkey));
2337                 hostif_mib_set_request(priv, DOT11_WEP_DEFAULT_KEY_ID,
2338                                        sizeof(val), MIB_VALUE_TYPE_INT, &val);
2339                 break;
2340         case SME_SET_KEY1:
2341                 hostif_mib_set_request(priv, DOT11_WEP_DEFAULT_KEY_VALUE1,
2342                                        priv->wpa.key[0].key_len,
2343                                        MIB_VALUE_TYPE_OSTRING,
2344                                        &priv->wpa.key[0].key_val[0]);
2345                 break;
2346         case SME_SET_KEY2:
2347                 hostif_mib_set_request(priv, DOT11_WEP_DEFAULT_KEY_VALUE2,
2348                                        priv->wpa.key[1].key_len,
2349                                        MIB_VALUE_TYPE_OSTRING,
2350                                        &priv->wpa.key[1].key_val[0]);
2351                 break;
2352         case SME_SET_KEY3:
2353                 hostif_mib_set_request(priv, DOT11_WEP_DEFAULT_KEY_VALUE3,
2354                                        priv->wpa.key[2].key_len,
2355                                        MIB_VALUE_TYPE_OSTRING,
2356                                        &priv->wpa.key[2].key_val[0]);
2357                 break;
2358         case SME_SET_KEY4:
2359                 hostif_mib_set_request(priv, DOT11_WEP_DEFAULT_KEY_VALUE4,
2360                                        priv->wpa.key[3].key_len,
2361                                        MIB_VALUE_TYPE_OSTRING,
2362                                        &priv->wpa.key[3].key_val[0]);
2363                 break;
2364         case SME_SET_PMK_TSC:
2365                 hostif_mib_set_request(priv, DOT11_PMK_TSC,
2366                                        WPA_RX_SEQ_LEN, MIB_VALUE_TYPE_OSTRING,
2367                                        &priv->wpa.key[0].rx_seq[0]);
2368                 break;
2369         case SME_SET_GMK1_TSC:
2370                 hostif_mib_set_request(priv, DOT11_GMK1_TSC,
2371                                        WPA_RX_SEQ_LEN, MIB_VALUE_TYPE_OSTRING,
2372                                        &priv->wpa.key[1].rx_seq[0]);
2373                 break;
2374         case SME_SET_GMK2_TSC:
2375                 hostif_mib_set_request(priv, DOT11_GMK2_TSC,
2376                                        WPA_RX_SEQ_LEN, MIB_VALUE_TYPE_OSTRING,
2377                                        &priv->wpa.key[2].rx_seq[0]);
2378                 break;
2379         }
2380 }
2381
2382 static
2383 void hostif_sme_set_pmksa(struct ks_wlan_private *priv)
2384 {
2385         struct pmk_cache_t {
2386                 uint16_t size;
2387                 struct {
2388                         uint8_t bssid[ETH_ALEN];
2389                         uint8_t pmkid[IW_PMKID_LEN];
2390                 } __packed list[PMK_LIST_MAX];
2391         } __packed pmkcache;
2392         struct pmk_t *pmk;
2393         int i;
2394
2395         DPRINTK(4, "pmklist.size=%d\n", priv->pmklist.size);
2396         i = 0;
2397         list_for_each_entry(pmk, &priv->pmklist.head, list) {
2398                 if (i < PMK_LIST_MAX) {
2399                         memcpy(pmkcache.list[i].bssid, pmk->bssid, ETH_ALEN);
2400                         memcpy(pmkcache.list[i].pmkid, pmk->pmkid,
2401                                IW_PMKID_LEN);
2402                         i++;
2403                 }
2404         }
2405         pmkcache.size = cpu_to_le16((uint16_t) (priv->pmklist.size));
2406         hostif_mib_set_request(priv, LOCAL_PMK,
2407                                sizeof(priv->pmklist.size) + (ETH_ALEN +
2408                                                              IW_PMKID_LEN) *
2409                                (priv->pmklist.size), MIB_VALUE_TYPE_OSTRING,
2410                                &pmkcache);
2411 }
2412
2413 /* execute sme */
2414 static
2415 void hostif_sme_execute(struct ks_wlan_private *priv, int event)
2416 {
2417         uint32_t val;
2418
2419         DPRINTK(3, "event=%d\n", event);
2420         switch (event) {
2421         case SME_START:
2422                 if (priv->dev_state == DEVICE_STATE_BOOT)
2423                         hostif_mib_get_request(priv, DOT11_MAC_ADDRESS);
2424                 break;
2425         case SME_MULTICAST_REQUEST:
2426                 hostif_sme_multicast_set(priv);
2427                 break;
2428         case SME_MACADDRESS_SET_REQUEST:
2429                 hostif_mib_set_request(priv, LOCAL_CURRENTADDRESS, ETH_ALEN,
2430                                        MIB_VALUE_TYPE_OSTRING,
2431                                        &priv->eth_addr[0]);
2432                 break;
2433         case SME_BSS_SCAN_REQUEST:
2434                 hostif_bss_scan_request(priv, priv->reg.scan_type,
2435                                         priv->scan_ssid, priv->scan_ssid_len);
2436                 break;
2437         case SME_POW_MNGMT_REQUEST:
2438                 hostif_sme_powermgt_set(priv);
2439                 break;
2440         case SME_PHY_INFO_REQUEST:
2441                 hostif_phy_information_request(priv);
2442                 break;
2443         case SME_MIC_FAILURE_REQUEST:
2444                 if (priv->wpa.mic_failure.failure == 1) {
2445                         hostif_mic_failure_request(priv,
2446                                                    priv->wpa.mic_failure.
2447                                                    failure - 1, 0);
2448                 } else if (priv->wpa.mic_failure.failure == 2) {
2449                         hostif_mic_failure_request(priv,
2450                                                    priv->wpa.mic_failure.
2451                                                    failure - 1,
2452                                                    priv->wpa.mic_failure.
2453                                                    counter);
2454                 } else
2455                         DPRINTK(4,
2456                                 "SME_MIC_FAILURE_REQUEST: failure count=%u error?\n",
2457                                 priv->wpa.mic_failure.failure);
2458                 break;
2459         case SME_MIC_FAILURE_CONFIRM:
2460                 if (priv->wpa.mic_failure.failure == 2) {
2461                         if (priv->wpa.mic_failure.stop)
2462                                 priv->wpa.mic_failure.stop = 0;
2463                         priv->wpa.mic_failure.failure = 0;
2464                         hostif_start_request(priv, priv->reg.operation_mode);
2465                 }
2466                 break;
2467         case SME_GET_MAC_ADDRESS:
2468                 if (priv->dev_state == DEVICE_STATE_BOOT)
2469                         hostif_mib_get_request(priv, DOT11_PRODUCT_VERSION);
2470                 break;
2471         case SME_GET_PRODUCT_VERSION:
2472                 if (priv->dev_state == DEVICE_STATE_BOOT)
2473                         priv->dev_state = DEVICE_STATE_PREINIT;
2474                 break;
2475         case SME_STOP_REQUEST:
2476                 hostif_stop_request(priv);
2477                 break;
2478         case SME_RTS_THRESHOLD_REQUEST:
2479                 val = cpu_to_le32((uint32_t) (priv->reg.rts));
2480                 hostif_mib_set_request(priv, DOT11_RTS_THRESHOLD,
2481                                        sizeof(val), MIB_VALUE_TYPE_INT, &val);
2482                 break;
2483         case SME_FRAGMENTATION_THRESHOLD_REQUEST:
2484                 val = cpu_to_le32((uint32_t) (priv->reg.fragment));
2485                 hostif_mib_set_request(priv, DOT11_FRAGMENTATION_THRESHOLD,
2486                                        sizeof(val), MIB_VALUE_TYPE_INT, &val);
2487                 break;
2488         case SME_WEP_INDEX_REQUEST:
2489         case SME_WEP_KEY1_REQUEST:
2490         case SME_WEP_KEY2_REQUEST:
2491         case SME_WEP_KEY3_REQUEST:
2492         case SME_WEP_KEY4_REQUEST:
2493         case SME_WEP_FLAG_REQUEST:
2494                 hostif_sme_set_wep(priv, event);
2495                 break;
2496         case SME_RSN_UCAST_REQUEST:
2497         case SME_RSN_MCAST_REQUEST:
2498         case SME_RSN_AUTH_REQUEST:
2499         case SME_RSN_ENABLED_REQUEST:
2500         case SME_RSN_MODE_REQUEST:
2501                 hostif_sme_set_rsn(priv, event);
2502                 break;
2503         case SME_SET_FLAG:
2504         case SME_SET_TXKEY:
2505         case SME_SET_KEY1:
2506         case SME_SET_KEY2:
2507         case SME_SET_KEY3:
2508         case SME_SET_KEY4:
2509         case SME_SET_PMK_TSC:
2510         case SME_SET_GMK1_TSC:
2511         case SME_SET_GMK2_TSC:
2512                 hostif_sme_set_key(priv, event);
2513                 break;
2514         case SME_SET_PMKSA:
2515                 hostif_sme_set_pmksa(priv);
2516                 break;
2517 #ifdef WPS
2518         case SME_WPS_ENABLE_REQUEST:
2519                 hostif_mib_set_request(priv, LOCAL_WPS_ENABLE,
2520                                        sizeof(priv->wps.wps_enabled),
2521                                        MIB_VALUE_TYPE_INT,
2522                                        &priv->wps.wps_enabled);
2523                 break;
2524         case SME_WPS_PROBE_REQUEST:
2525                 hostif_mib_set_request(priv, LOCAL_WPS_PROBE_REQ,
2526                                        priv->wps.ielen,
2527                                        MIB_VALUE_TYPE_OSTRING, priv->wps.ie);
2528                 break;
2529 #endif /* WPS */
2530         case SME_MODE_SET_REQUEST:
2531                 hostif_sme_mode_setup(priv);
2532                 break;
2533         case SME_SET_GAIN:
2534                 hostif_mib_set_request(priv, LOCAL_GAIN,
2535                                        sizeof(priv->gain),
2536                                        MIB_VALUE_TYPE_OSTRING, &priv->gain);
2537                 break;
2538         case SME_GET_GAIN:
2539                 hostif_mib_get_request(priv, LOCAL_GAIN);
2540                 break;
2541         case SME_GET_EEPROM_CKSUM:
2542                 priv->eeprom_checksum = EEPROM_FW_NOT_SUPPORT;  /* initialize */
2543                 hostif_mib_get_request(priv, LOCAL_EEPROM_SUM);
2544                 break;
2545         case SME_START_REQUEST:
2546                 hostif_start_request(priv, priv->reg.operation_mode);
2547                 break;
2548         case SME_START_CONFIRM:
2549                 /* for power save */
2550                 atomic_set(&priv->psstatus.snooze_guard, 0);
2551                 atomic_set(&priv->psstatus.confirm_wait, 0);
2552                 if (priv->dev_state == DEVICE_STATE_PREINIT)
2553                         priv->dev_state = DEVICE_STATE_INIT;
2554                 /* wake_up_interruptible_all(&priv->confirm_wait); */
2555                 complete(&priv->confirm_wait);
2556                 break;
2557         case SME_SLEEP_REQUEST:
2558                 hostif_sme_sleep_set(priv);
2559                 break;
2560         case SME_SET_REGION:
2561                 val = cpu_to_le32((uint32_t) (priv->region));
2562                 hostif_mib_set_request(priv, LOCAL_REGION,
2563                                        sizeof(val), MIB_VALUE_TYPE_INT, &val);
2564                 break;
2565         case SME_MULTICAST_CONFIRM:
2566         case SME_BSS_SCAN_CONFIRM:
2567         case SME_POW_MNGMT_CONFIRM:
2568         case SME_PHY_INFO_CONFIRM:
2569         case SME_STOP_CONFIRM:
2570         case SME_RTS_THRESHOLD_CONFIRM:
2571         case SME_FRAGMENTATION_THRESHOLD_CONFIRM:
2572         case SME_WEP_INDEX_CONFIRM:
2573         case SME_WEP_KEY1_CONFIRM:
2574         case SME_WEP_KEY2_CONFIRM:
2575         case SME_WEP_KEY3_CONFIRM:
2576         case SME_WEP_KEY4_CONFIRM:
2577         case SME_WEP_FLAG_CONFIRM:
2578         case SME_RSN_UCAST_CONFIRM:
2579         case SME_RSN_MCAST_CONFIRM:
2580         case SME_RSN_AUTH_CONFIRM:
2581         case SME_RSN_ENABLED_CONFIRM:
2582         case SME_RSN_MODE_CONFIRM:
2583         case SME_MODE_SET_CONFIRM:
2584                 break;
2585         case SME_TERMINATE:
2586         default:
2587                 break;
2588         }
2589 }
2590
2591 static
2592 void hostif_sme_task(unsigned long dev)
2593 {
2594         struct ks_wlan_private *priv = (struct ks_wlan_private *)dev;
2595
2596         DPRINTK(3, "\n");
2597
2598         if (priv->dev_state >= DEVICE_STATE_BOOT) {
2599                 if (0 < cnt_smeqbody(priv)
2600                     && priv->dev_state >= DEVICE_STATE_BOOT) {
2601                         hostif_sme_execute(priv,
2602                                            priv->sme_i.event_buff[priv->sme_i.
2603                                                                   qhead]);
2604                         inc_smeqhead(priv);
2605                         if (0 < cnt_smeqbody(priv))
2606                                 tasklet_schedule(&priv->sme_task);
2607                 }
2608         }
2609 }
2610
2611 /* send to Station Management Entity module */
2612 void hostif_sme_enqueue(struct ks_wlan_private *priv, unsigned short event)
2613 {
2614         DPRINTK(3, "\n");
2615
2616         /* enqueue sme event */
2617         if (cnt_smeqbody(priv) < (SME_EVENT_BUFF_SIZE - 1)) {
2618                 priv->sme_i.event_buff[priv->sme_i.qtail] = event;
2619                 inc_smeqtail(priv);
2620                 //DPRINTK(3,"inc_smeqtail \n");
2621 #ifdef KS_WLAN_DEBUG
2622                 if (priv->sme_i.max_event_count < cnt_smeqbody(priv))
2623                         priv->sme_i.max_event_count = cnt_smeqbody(priv);
2624 #endif /* KS_WLAN_DEBUG */
2625         } else {
2626                 /* in case of buffer overflow */
2627                 //DPRINTK(2,"sme queue buffer overflow\n");
2628                 netdev_err(priv->net_dev, "sme queue buffer overflow\n");
2629         }
2630
2631         tasklet_schedule(&priv->sme_task);
2632 }
2633
2634 int hostif_init(struct ks_wlan_private *priv)
2635 {
2636         int i;
2637
2638         DPRINTK(3, "\n");
2639
2640         priv->aplist.size = 0;
2641         for (i = 0; i < LOCAL_APLIST_MAX; i++)
2642                 memset(&(priv->aplist.ap[i]), 0, sizeof(struct local_ap_t));
2643         priv->infra_status = 0;
2644         priv->current_rate = 4;
2645         priv->connect_status = DISCONNECT_STATUS;
2646
2647         spin_lock_init(&priv->multicast_spin);
2648
2649         spin_lock_init(&priv->dev_read_lock);
2650         init_waitqueue_head(&priv->devread_wait);
2651         priv->dev_count = 0;
2652         atomic_set(&priv->event_count, 0);
2653         atomic_set(&priv->rec_count, 0);
2654
2655         /* for power save */
2656         atomic_set(&priv->psstatus.status, PS_NONE);
2657         atomic_set(&priv->psstatus.confirm_wait, 0);
2658         atomic_set(&priv->psstatus.snooze_guard, 0);
2659         /* init_waitqueue_head(&priv->psstatus.wakeup_wait); */
2660         init_completion(&priv->psstatus.wakeup_wait);
2661         //INIT_WORK(&priv->ks_wlan_wakeup_task, ks_wlan_hw_wakeup_task, (void *)priv);
2662         INIT_WORK(&priv->ks_wlan_wakeup_task, ks_wlan_hw_wakeup_task);
2663
2664         /* WPA */
2665         memset(&(priv->wpa), 0, sizeof(priv->wpa));
2666         priv->wpa.rsn_enabled = 0;
2667         priv->wpa.mic_failure.failure = 0;
2668         priv->wpa.mic_failure.last_failure_time = 0;
2669         priv->wpa.mic_failure.stop = 0;
2670         memset(&(priv->pmklist), 0, sizeof(priv->pmklist));
2671         INIT_LIST_HEAD(&priv->pmklist.head);
2672         for (i = 0; i < PMK_LIST_MAX; i++)
2673                 INIT_LIST_HEAD(&priv->pmklist.pmk[i].list);
2674
2675         priv->sme_i.sme_status = SME_IDLE;
2676         priv->sme_i.qhead = priv->sme_i.qtail = 0;
2677 #ifdef KS_WLAN_DEBUG
2678         priv->sme_i.max_event_count = 0;
2679 #endif
2680         spin_lock_init(&priv->sme_i.sme_spin);
2681         priv->sme_i.sme_flag = 0;
2682
2683         tasklet_init(&priv->sme_task, hostif_sme_task, (unsigned long)priv);
2684
2685         return 0;
2686 }
2687
2688 void hostif_exit(struct ks_wlan_private *priv)
2689 {
2690         tasklet_kill(&priv->sme_task);
2691 }