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