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