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