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