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