Date:2010-10-30 17:04:14 (13 years 4 months ago)
Author:Xiangfu Liu
Commit:bc937d1dfcb5df6a51aee251ce8db0d711f516be
Message:add ks7010 drivers

Signed-off-by: Xiangfu Liu <xiangfu@sharism.cc>
Files: package/ks7010/Makefile (1 diff)
package/ks7010/src/Kconfig (1 diff)
package/ks7010/src/Makefile (1 diff)
package/ks7010/src/eap_packet.h (1 diff)
package/ks7010/src/ks7010_config.c (1 diff)
package/ks7010/src/ks7010_sdio.c (1 diff)
package/ks7010/src/ks7010_sdio.h (1 diff)
package/ks7010/src/ks_debug.c (1 diff)
package/ks7010/src/ks_debug.h (1 diff)
package/ks7010/src/ks_hostif.c (1 diff)
package/ks7010/src/ks_hostif.h (1 diff)
package/ks7010/src/ks_wlan.h (1 diff)
package/ks7010/src/ks_wlan_ioctl.h (1 diff)
package/ks7010/src/ks_wlan_net.c (1 diff)
package/ks7010/src/michael_mic.c (1 diff)
package/ks7010/src/michael_mic.h (1 diff)

Change Details

package/ks7010/Makefile
1#
2# Copyright (C) 2008 OpenWrt.org
3#
4# This is free software, licensed under the GNU General Public License v2.
5# See /LICENSE for more information.
6#
7
8include $(TOPDIR)/rules.mk
9include $(INCLUDE_DIR)/kernel.mk
10
11PKG_NAME:=ks7010
12PKG_RELEASE:=1
13
14include $(INCLUDE_DIR)/package.mk
15
16define KernelPackage/ks7010
17  SUBMENU:=Wireless Drivers
18  TITLE:=ks7010 SDIO wireless card
19  DEPENDS:=
20  FILES:=$(PKG_BUILD_DIR)/ks7010.$(LINUX_KMOD_SUFFIX)
21  AUTOLOAD:=$(call AutoLoad,10,ks7010)
22endef
23
24MAKE_OPTS:= \
25    ARCH="$(LINUX_KARCH)" \
26    CROSS_COMPILE="$(TARGET_CROSS)" \
27    SUBDIRS="$(PKG_BUILD_DIR)"
28
29define Build/Prepare
30    $(INSTALL_DIR) $(PKG_BUILD_DIR)
31    $(CP) ./src/* $(PKG_BUILD_DIR)/
32endef
33
34define Build/Compile
35    $(MAKE) -C "$(LINUX_DIR)" \
36        $(MAKE_OPTS) \
37        modules
38endef
39
40$(eval $(call KernelPackage,ks7010))
package/ks7010/src/Kconfig
1config KS7010
2    tristate "KeyStream KS7010 SDIO support"
3    ---help---
4      This is a driver for KS7010 Wi-Fi SDIO based SD cards.
5      This driver is tested for Ben NanoNote gadget from qi-hardware.com
6
7      Thanks to Renesas/KeyStream for their donation!
package/ks7010/src/Makefile
1obj-m += ks7010.o
2
3ccflags-y += -D_SDIO_ -DKS_WLAN_DEBUG=0
4ks7010-y := michael_mic.o ks_hostif.o ks_wlan_net.o ks_debug.o \
5                    ks7010_sdio.o ks7010_config.o
package/ks7010/src/eap_packet.h
1/*
2 *
3 * eap_packet.h
4 * $Id: eap_packet.h 991 2009-09-14 01:38:58Z sekine $
5 *
6 */
7#ifndef EAP_PACKET_H
8#define EAP_PACKET_H
9
10#define WBIT(n) (1 << (n))
11
12#ifndef ETH_ALEN
13#define ETH_ALEN 6
14#endif
15
16struct ether_hdr {
17    unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
18    unsigned char h_source[ETH_ALEN]; /* source ether addr */
19    unsigned char h_dest_snap;
20    unsigned char h_source_snap;
21    unsigned char h_command;
22    unsigned char h_vendor_id[3];
23    unsigned short h_proto; /* packet type ID field */
24#define ETHER_PROTOCOL_TYPE_EAP 0x888e
25#define ETHER_PROTOCOL_TYPE_IP 0x0800
26#define ETHER_PROTOCOL_TYPE_ARP 0x0806
27    /* followed by length octets of data */
28} __attribute__ ((packed));
29
30struct ieee802_1x_hdr {
31    unsigned char version;
32    unsigned char type;
33    unsigned short length;
34    /* followed by length octets of data */
35} __attribute__ ((packed));
36
37#define EAPOL_VERSION 2
38
39enum { IEEE802_1X_TYPE_EAP_PACKET = 0,
40       IEEE802_1X_TYPE_EAPOL_START = 1,
41       IEEE802_1X_TYPE_EAPOL_LOGOFF = 2,
42       IEEE802_1X_TYPE_EAPOL_KEY = 3,
43       IEEE802_1X_TYPE_EAPOL_ENCAPSULATED_ASF_ALERT = 4
44};
45
46enum { EAPOL_KEY_TYPE_RC4 = 1, EAPOL_KEY_TYPE_RSN = 2,
47       EAPOL_KEY_TYPE_WPA = 254 };
48
49
50#define IEEE8021X_REPLAY_COUNTER_LEN 8
51#define IEEE8021X_KEY_SIGN_LEN 16
52#define IEEE8021X_KEY_IV_LEN 16
53
54#define IEEE8021X_KEY_INDEX_FLAG 0x80
55#define IEEE8021X_KEY_INDEX_MASK 0x03
56
57struct ieee802_1x_eapol_key {
58    unsigned char type;
59    unsigned short key_length;
60    /* does not repeat within the life of the keying material used to
61     * encrypt the Key field; 64-bit NTP timestamp MAY be used here */
62    unsigned char replay_counter[IEEE8021X_REPLAY_COUNTER_LEN];
63    unsigned char key_iv[IEEE8021X_KEY_IV_LEN]; /* cryptographically random number */
64    unsigned char key_index; /* key flag in the most significant bit:
65               * 0 = broadcast (default key),
66               * 1 = unicast (key mapping key); key index is in the
67               * 7 least significant bits */
68    /* HMAC-MD5 message integrity check computed with MS-MPPE-Send-Key as
69     * the key */
70    unsigned char key_signature[IEEE8021X_KEY_SIGN_LEN];
71
72    /* followed by key: if packet body length = 44 + key length, then the
73     * key field (of key_length bytes) contains the key in encrypted form;
74     * if packet body length = 44, key field is absent and key_length
75     * represents the number of least significant octets from
76     * MS-MPPE-Send-Key attribute to be used as the keying material;
77     * RC4 key used in encryption = Key-IV + MS-MPPE-Recv-Key */
78} __attribute__ ((packed));
79
80
81#define WPA_NONCE_LEN 32
82#define WPA_REPLAY_COUNTER_LEN 8
83
84struct wpa_eapol_key {
85    unsigned char type;
86     unsigned short key_info;
87    unsigned short key_length;
88    unsigned char replay_counter[WPA_REPLAY_COUNTER_LEN];
89    unsigned char key_nonce[WPA_NONCE_LEN];
90    unsigned char key_iv[16];
91    unsigned char key_rsc[8];
92    unsigned char key_id[8]; /* Reserved in IEEE 802.11i/RSN */
93    unsigned char key_mic[16];
94    unsigned short key_data_length;
95    /* followed by key_data_length bytes of key_data */
96} __attribute__ ((packed));
97
98#define WPA_KEY_INFO_TYPE_MASK (WBIT(0) | WBIT(1) | WBIT(2))
99#define WPA_KEY_INFO_TYPE_HMAC_MD5_RC4 WBIT(0)
100#define WPA_KEY_INFO_TYPE_HMAC_SHA1_AES WBIT(1)
101#define WPA_KEY_INFO_KEY_TYPE WBIT(3) /* 1 = Pairwise, 0 = Group key */
102/* bit4..5 is used in WPA, but is reserved in IEEE 802.11i/RSN */
103#define WPA_KEY_INFO_KEY_INDEX_MASK (WBIT(4) | WBIT(5))
104#define WPA_KEY_INFO_KEY_INDEX_SHIFT 4
105#define WPA_KEY_INFO_INSTALL WBIT(6) /* pairwise */
106#define WPA_KEY_INFO_TXRX WBIT(6) /* group */
107#define WPA_KEY_INFO_ACK WBIT(7)
108#define WPA_KEY_INFO_MIC WBIT(8)
109#define WPA_KEY_INFO_SECURE WBIT(9)
110#define WPA_KEY_INFO_ERROR WBIT(10)
111#define WPA_KEY_INFO_REQUEST WBIT(11)
112#define WPA_KEY_INFO_ENCR_KEY_DATA WBIT(12) /* IEEE 802.11i/RSN only */
113
114#define WPA_CAPABILITY_PREAUTH WBIT(0)
115
116#define GENERIC_INFO_ELEM 0xdd
117#define RSN_INFO_ELEM 0x30
118
119enum {
120    REASON_UNSPECIFIED = 1,
121    REASON_DEAUTH_LEAVING = 3,
122    REASON_INVALID_IE = 13,
123    REASON_MICHAEL_MIC_FAILURE = 14,
124    REASON_4WAY_HANDSHAKE_TIMEOUT = 15,
125    REASON_GROUP_KEY_UPDATE_TIMEOUT = 16,
126    REASON_IE_IN_4WAY_DIFFERS = 17,
127    REASON_GROUP_CIPHER_NOT_VALID = 18,
128    REASON_PAIRWISE_CIPHER_NOT_VALID = 19,
129    REASON_AKMP_NOT_VALID = 20,
130    REASON_UNSUPPORTED_RSN_IE_VERSION = 21,
131    REASON_INVALID_RSN_IE_CAPAB = 22,
132    REASON_IEEE_802_1X_AUTH_FAILED = 23,
133    REASON_CIPHER_SUITE_REJECTED = 24
134};
135
136#endif /* EAP_PACKET_H */
package/ks7010/src/ks7010_config.c
1#include <linux/kernel.h>
2#include <linux/mmc/sdio_func.h>
3
4#include "ks_wlan.h"
5#include "ks_hostif.h"
6#include "ks_wlan_ioctl.h"
7#include "ks_debug.h"
8
9static int wep_on_off;
10#define WEP_OFF 0
11#define WEP_ON_64BIT 1
12#define WEP_ON_128BIT 2
13
14static int wep_type;
15#define WEP_KEY_CHARACTER 0
16#define WEP_KEY_HEX 1
17
18static
19void analyze_character_wep_key(struct ks_wlan_parameter *param, int wep_key_index, char *value)
20{
21    int i;
22    unsigned char wep_key[26], key_length;
23
24    key_length = (wep_on_off == WEP_ON_64BIT) ? 5 : 13;
25    /* 64bit key_length = 5; 128bit key_length = 13; */
26
27    for (i=0; i<key_length; i++) {
28        wep_key[i] = value[i];
29    }
30
31    if(wep_key_index < 0 || wep_key_index > 3)
32        return;
33
34    param->wep_key[wep_key_index].size = key_length;
35    for (i=0; i<(param->wep_key[wep_key_index].size); i++) {
36        param->wep_key[wep_key_index].val[i] = wep_key[i];
37    }
38}
39
40static
41void analyze_hex_wep_key(struct ks_wlan_parameter *param, int wep_key_index, char *value)
42{
43    unsigned char wep_end[26], i, j, key_length;
44
45    key_length = (wep_on_off == WEP_ON_64BIT) ? 10 : 26;
46    /* 64bit key_length = 10; 128bit key_length = 26; */
47
48    for (i=0; i<key_length; i++) {
49        wep_end[i] = value[i];
50        if (i % 2) {
51            /* Odd */
52            for (j=0x00; j<0x10; j++) {
53                if (j<0x0a) {
54                    if (wep_end[i] == j+0x30)
55                        wep_end[i] = j;
56                } else {
57                    if ((wep_end[i] == j+0x37) | (wep_end[i] == j+0x57))
58                        wep_end[i] = j;
59                }
60            }
61        } else {
62            /* Even */
63            for (j=0x00; j<0x10; j++) {
64                if (j<0x0a) {
65                    if (wep_end[i] == j+0x30) {
66                        wep_end[i] = j*16;
67                    }
68                } else {
69                    if ((wep_end[i] == j+0x37) | (wep_end[i] == j+0x57))
70                        wep_end[i] = j*16;
71                }
72            }
73        }
74    }
75
76    for (i=0; i<key_length/2; i++) {
77        wep_end[i] = wep_end[i*2] + wep_end[(i*2)+1];
78    }
79
80    if(wep_key_index < 0 || wep_key_index > 3)
81        return ;
82
83    param->wep_key[wep_key_index].size = key_length/2;
84    for (i=0; i<(param->wep_key[wep_key_index].size); i++) {
85        param->wep_key[wep_key_index].val[i] = wep_end[i];
86    }
87
88}
89
90static
91int rate_set_configuration(ks_wlan_private *priv, char *value)
92{
93    int rc=0;
94
95    priv->reg.tx_rate = TX_RATE_FIXED;
96    priv->reg.rate_set.size = 1;
97
98    switch(*value){
99    case '1': /* 1M 11M 12M 18M */
100        if(*(value+1) == '8'){
101            priv->reg.rate_set.body[0] = TX_RATE_18M;
102        }
103        else if(*(value+1) == '2'){
104            priv->reg.rate_set.body[0] = TX_RATE_12M|BASIC_RATE;
105        }
106        else if(*(value+1) == '1'){
107            priv->reg.rate_set.body[0] = TX_RATE_11M|BASIC_RATE;
108        }
109        else{
110            priv->reg.rate_set.body[0] = TX_RATE_1M|BASIC_RATE;
111        }
112        break;
113    case '2': /* 2M 24M */
114        if(*(value+1) == '4'){
115            priv->reg.rate_set.body[0] = TX_RATE_24M|BASIC_RATE;
116        }
117        else{
118            priv->reg.rate_set.body[0] = TX_RATE_2M|BASIC_RATE;
119        }
120        break;
121    case '3': /* 36M */
122        priv->reg.rate_set.body[0] = TX_RATE_36M;
123        break;
124    case '4': /* 48M */
125        priv->reg.rate_set.body[0] = TX_RATE_48M;
126        break;
127    case '5': /* 5.5M 54M */
128        if(*(value+1) == '4'){
129            priv->reg.rate_set.body[0] = TX_RATE_54M;
130        }
131        else{
132            priv->reg.rate_set.body[0] = TX_RATE_5M|BASIC_RATE;
133        }
134        break;
135    case '6': /* 6M */
136        priv->reg.rate_set.body[0] = TX_RATE_6M|BASIC_RATE;
137        break;
138    case '9': /* 9M */
139        priv->reg.rate_set.body[0] = TX_RATE_9M;
140        break;
141    case 'K':
142        priv->reg.rate_set.body[6] = TX_RATE_36M;
143        priv->reg.rate_set.body[5] = TX_RATE_18M;
144        priv->reg.rate_set.body[4] = TX_RATE_24M|BASIC_RATE;
145        priv->reg.rate_set.body[3] = TX_RATE_12M|BASIC_RATE;
146        priv->reg.rate_set.body[2] = TX_RATE_6M|BASIC_RATE;
147        priv->reg.rate_set.body[1] = TX_RATE_11M|BASIC_RATE;
148        priv->reg.rate_set.body[0] = TX_RATE_2M|BASIC_RATE;
149        priv->reg.tx_rate = TX_RATE_FULL_AUTO;
150        priv->reg.rate_set.size = 7;
151        break;
152    default:
153        priv->reg.rate_set.body[11] = TX_RATE_54M;
154        priv->reg.rate_set.body[10] = TX_RATE_48M;
155        priv->reg.rate_set.body[9] = TX_RATE_36M;
156        priv->reg.rate_set.body[8] = TX_RATE_18M;
157        priv->reg.rate_set.body[7] = TX_RATE_9M;
158        priv->reg.rate_set.body[6] = TX_RATE_24M|BASIC_RATE;
159        priv->reg.rate_set.body[5] = TX_RATE_12M|BASIC_RATE;
160        priv->reg.rate_set.body[4] = TX_RATE_6M|BASIC_RATE;
161        priv->reg.rate_set.body[3] = TX_RATE_11M|BASIC_RATE;
162        priv->reg.rate_set.body[2] = TX_RATE_5M|BASIC_RATE;
163        priv->reg.rate_set.body[1] = TX_RATE_2M|BASIC_RATE;
164        priv->reg.rate_set.body[0] = TX_RATE_1M|BASIC_RATE;
165        priv->reg.tx_rate = TX_RATE_FULL_AUTO;
166        priv->reg.rate_set.size = 12;
167        break;
168    }
169    return rc;
170}
171
172#ifndef NO_FIRMWARE_CLASS
173#include <linux/firmware.h>
174#else
175#define MAX_CONFIG_FILE_SIZE (1024*10)
176#endif
177int ks_wlan_read_config_file(ks_wlan_private *priv)
178{
179    struct {
180        const int key_len;
181        const char *key;
182        const char *val;
183    } cfg_tbl[] = {
184        {15,"BeaconLostCount", "20"}, /* 0 */
185        {7,"Channel", "1"}, /* 1 */
186        {17,"FragmentThreshold","2346"}, /* 2 */
187        {13,"OperationMode","Infrastructure"}, /* 3 */
188        {19,"PowerManagementMode","ACTIVE"}, /* 4 */
189        {12,"RTSThreshold","2347"}, /* 5 */
190        {4,"SSID","default"}, /* 6 */
191        {6,"TxRate","Auto"}, /* 7 */
192        {23,"AuthenticationAlgorithm",""}, /* 8 */
193        {12,"WepKeyValue1",""}, /* 9 */
194        {12,"WepKeyValue2",""}, /* 10 */
195        {12,"WepKeyValue3",""}, /* 11 */
196        {12,"WepKeyValue4",""}, /* 12 */
197        {8,"WepIndex","1"}, /* 13 */
198        {7,"WepType","STRING"}, /* 14 */
199        {3,"Wep","OFF"}, /* 15 */
200        {13,"PREAMBLE_TYPE","SHORT"}, /* 16 */
201        {8,"ScanType","ACTIVE_SCAN"}, /* 17 */
202        {8,"ROM_FILE", ROM_FILE}, /* 18 */
203        {7,"PhyType", "BG_MODE"}, /* 19 */
204        {7,"CtsMode", "FALSE"}, /* 20 */
205        {19,"PhyInformationTimer", "0"}, /* 21 */
206        {0,"",""},
207    };
208
209#ifndef NO_FIRMWARE_CLASS
210    const struct firmware *fw_entry;
211    struct device *dev = NULL;
212    int retval;
213#else
214    struct file *srcf;
215    int nr_read ;
216    int retval;
217    char *cfg_buf=NULL;
218    int orgfsuid, orgfsgid;
219    mm_segment_t orgfs;
220#endif
221    char cfg_file[]=CFG_FILE;
222    char *cur_p, *end_p;
223    char wk_buff[256], *wk_p;
224
225    /* Initialize Variable */
226    priv->reg.operation_mode = MODE_INFRASTRUCTURE; /* Infrastructure */
227    priv->reg.channel = 10; /* 10 */
228    memset(priv->reg.bssid, 0x0, ETH_ALEN); /* BSSID */
229    priv->reg.ssid.body[0] = '\0'; /* SSID */
230    priv->reg.ssid.size = 0; /* SSID size */
231    priv->reg.tx_rate = TX_RATE_AUTO; /* TxRate Fully Auto */
232    priv->reg.preamble = SHORT_PREAMBLE; /* Preamble = SHORT */
233    priv->reg.powermgt = POWMGT_ACTIVE_MODE; /* POWMGT_ACTIVE_MODE */
234    priv->reg.scan_type = ACTIVE_SCAN; /* Active */
235    priv->reg.beacon_lost_count = 20; /* Beacon Lost Count */
236    priv->reg.rts = 2347UL; /* RTS Threashold */
237    priv->reg.fragment = 2346UL; /* Fragmentation Threashold */
238
239    strcpy(&priv->reg.rom_file[0], ROM_FILE);
240
241    priv->skb = NULL;
242
243    priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM; /* AuthenticationAlgorithm */
244
245    priv->reg.privacy_invoked = 0x00; /* WEP */
246    priv->reg.wep_index=0;
247    memset(&priv->reg.wep_key[0],0,sizeof(priv->reg.wep_key[0]));
248    memset(&priv->reg.wep_key[1],0,sizeof(priv->reg.wep_key[0]));
249    memset(&priv->reg.wep_key[2],0,sizeof(priv->reg.wep_key[0]));
250    memset(&priv->reg.wep_key[3],0,sizeof(priv->reg.wep_key[0]));
251
252    priv->reg.phy_type = D_11BG_COMPATIBLE_MODE;
253    priv->reg.cts_mode = CTS_MODE_FALSE;
254    priv->reg.phy_info_timer = 0;
255    priv->reg.rate_set.body[11] = TX_RATE_54M;
256    priv->reg.rate_set.body[10] = TX_RATE_48M;
257    priv->reg.rate_set.body[9] = TX_RATE_36M;
258    priv->reg.rate_set.body[8] = TX_RATE_18M;
259    priv->reg.rate_set.body[7] = TX_RATE_9M;
260    priv->reg.rate_set.body[6] = TX_RATE_24M|BASIC_RATE;
261    priv->reg.rate_set.body[5] = TX_RATE_12M|BASIC_RATE;
262    priv->reg.rate_set.body[4] = TX_RATE_6M|BASIC_RATE;
263    priv->reg.rate_set.body[3] = TX_RATE_11M|BASIC_RATE;
264    priv->reg.rate_set.body[2] = TX_RATE_5M|BASIC_RATE;
265    priv->reg.rate_set.body[1] = TX_RATE_2M|BASIC_RATE;
266    priv->reg.rate_set.body[0] = TX_RATE_1M|BASIC_RATE;
267    priv->reg.tx_rate = TX_RATE_FULL_AUTO;
268    priv->reg.rate_set.size = 12;
269
270#ifndef NO_FIRMWARE_CLASS
271#if (defined _PCMCIA_)
272    dev = &priv->ks_wlan_hw.pcmcia_dev->dev;
273#elif (defined _PCI_)
274    dev = &priv->ks_wlan_hw.pci_dev->dev;
275#elif (defined _SDIO_)
276    dev = &priv->ks_wlan_hw.sdio_card->func->dev;
277#endif
278    if((retval = request_firmware(&fw_entry, cfg_file, dev)) !=0 ){
279        DPRINTK(1, "error request_firmware() file=%s ret=%d\n", cfg_file, retval);
280        return 1;
281    }
282
283    DPRINTK(4, "success request_firmware() file=%s size=%d\n", cfg_file, fw_entry->size);
284    cur_p = fw_entry->data;
285    end_p = cur_p + fw_entry->size;
286#else
287    orgfsuid=current->fsuid;
288    orgfsgid=current->fsgid;
289    orgfs=get_fs();
290    set_fs(KERNEL_DS);
291
292    srcf = filp_open(cfg_file, O_RDONLY, 0);
293    if (IS_ERR(srcf)) {
294        printk(KERN_ERR "error %ld opening %s\n", -PTR_ERR(srcf),cfg_file);
295        goto no_config_file;
296    }
297
298        if (!(srcf->f_op && srcf->f_op->read)) {
299                printk(KERN_ERR "%s does not have a read method\n", cfg_file);
300        goto no_config_file;
301        }
302
303    cfg_buf = (char *)kzalloc(MAX_CONFIG_FILE_SIZE, GFP_ATOMIC);
304        if (!cfg_buf) {
305                printk(KERN_ERR "%s does not read : out of memory \n", cfg_file);
306        goto no_config_file;
307        }
308
309        nr_read = srcf->f_op->read(srcf, (unsigned char *)cfg_buf, MAX_CONFIG_FILE_SIZE, &srcf->f_pos);
310
311    DPRINTK(1, "read retval=%d file=%s\n", nr_read, priv->reg.cfg_file);
312    retval=filp_close(srcf ,NULL);
313    if (retval)
314        DPRINTK(1, "error %d closing %s\n", -retval,priv->reg.cfg_file);
315
316        if (nr_read < 1) {
317                printk(KERN_ERR "%s does not read : file is empty num=%d\n", cfg_file, nr_read);
318        goto no_config_file;
319        }else if(nr_read > MAX_CONFIG_FILE_SIZE){
320                printk(KERN_ERR "%s does not read : file is too big \n", cfg_file);
321        goto no_config_file;
322    }
323    cur_p = cfg_buf;
324    end_p = cur_p + nr_read;
325#endif
326    *end_p = '\0';
327
328    while (cur_p < end_p) {
329        int i, j, len;
330
331        len = end_p - cur_p;
332        for (i=0; cfg_tbl[i].key_len != 0; i++) {
333            if (*cur_p == '#') {
334                break;
335            }
336            if (len < cfg_tbl[i].key_len) {
337                continue;
338            }
339            if (!strncmp(cfg_tbl[i].key, cur_p, cfg_tbl[i].key_len)) {
340                break;
341            }
342        }
343        if ((*cur_p == '#') || (cfg_tbl[i].key_len == 0)) {
344            while (*cur_p != '\n') {
345                if (cur_p >= end_p) {
346                    break;
347                }
348                cur_p++;
349            }
350            cur_p++;
351        } else {
352            cur_p += cfg_tbl[i].key_len;
353            if (*cur_p != '=') {
354                while (*cur_p != '\n') {
355                    if (cur_p >= end_p) {
356                        break;
357                    }
358                    cur_p++;
359                }
360                continue;
361            }
362            cur_p++;
363
364            for (j=0,wk_p=cur_p; *wk_p != '\n' && wk_p < end_p; j++,wk_p++) {
365                wk_buff[j] = *wk_p;
366            }
367            wk_buff[j] = '\0';
368            cur_p = wk_p;
369            DPRINTK(4,"%s=%s\n",cfg_tbl[i].key, wk_buff);
370            wk_p = wk_buff;
371
372            switch (i) {
373            case 0: /* "BeaconLostCount", "10" */
374                priv->reg.beacon_lost_count = simple_strtol(wk_buff, NULL, 10);
375                break;
376            case 1: /* "Channel", "1" */
377                priv->reg.channel = simple_strtol(wk_buff, NULL, 10);
378                break;
379            case 2: /* "FragmentThreshold","2346" */
380                j = simple_strtol(wk_buff, NULL, 10);
381                priv->reg.fragment = (unsigned long)j;
382                break;
383            case 3: /* "OperationMode","Infrastructure" */
384                switch (*wk_buff) {
385                case 'P':
386                    priv->reg.operation_mode = MODE_PSEUDO_ADHOC;
387                    break;
388                case 'I':
389                    priv->reg.operation_mode = MODE_INFRASTRUCTURE;
390                    break;
391                case '8':
392                    priv->reg.operation_mode = MODE_ADHOC;
393                    break;
394                default:
395                    priv->reg.operation_mode = MODE_INFRASTRUCTURE;
396                }
397                break;
398            case 4: /* "PowerManagementMode","POWER_ACTIVE" */
399                if (!strncmp(wk_buff, "SAVE1", 5)) {
400                    priv->reg.powermgt = POWMGT_SAVE1_MODE;
401                } else if (!strncmp(wk_buff, "SAVE2", 5)){
402                    priv->reg.powermgt = POWMGT_SAVE2_MODE;
403                } else {
404                    priv->reg.powermgt = POWMGT_ACTIVE_MODE;
405                }
406                break;
407            case 5: /* "RTSThreshold","2347" */
408                j = simple_strtol(wk_buff, NULL, 10);
409                priv->reg.rts = (unsigned long)j;
410                break;
411            case 6: /* "SSID","" */
412                if (*wk_p != '"')
413                    break;
414                wk_p++;
415                for (j=0; *wk_p != '"'; j++) {
416                    if (wk_p == '\0') {
417                        break;
418                    }
419                    priv->reg.ssid.body[j] = *wk_p++;
420                }
421                priv->reg.ssid.body[j] = '\0';
422                priv->reg.ssid.size = j;
423                wk_p++;
424                break;
425            case 7: /* "TxRate","Auto" */
426                rate_set_configuration(priv, wk_p);
427                break;
428            case 8: /* "AuthenticationAlgorithm","OPEN_SYSTEM" */
429                switch (*wk_p) {
430                case 'O': /* Authenticate System : Open System */
431                    priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
432                    break;
433                case 'S': /* Authenticate System : Shared Key */
434                    priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
435                    break;
436                }
437                break;
438            case 9: /* "WepKeyValue1","" */
439            case 10: /* "WepKeyValue2","" */
440            case 11: /* "WepKeyValue3","" */
441            case 12: /* "WepKeyValue4","" */
442                if (wep_on_off != WEP_OFF) {
443                    switch (wep_type) {
444                    case WEP_KEY_CHARACTER:
445                        analyze_character_wep_key(&priv->reg, (i-9), wk_p);
446                        break;
447                    case WEP_KEY_HEX:
448                        analyze_hex_wep_key(&priv->reg, (i-9), wk_p);
449                        break;
450                    }
451                }
452                break;
453            case 13: /* "WepIndex","1"->0 (So, Zero Origin) */
454                priv->reg.wep_index = simple_strtol(wk_buff, NULL, 10) - 1;
455                break;
456            case 14: /* "WepType","STRING" */
457                if (!strncmp(wk_buff, "STRING", 6)) {
458                    wep_type = WEP_KEY_CHARACTER;
459                } else {
460                    wep_type = WEP_KEY_HEX;
461                }
462                break;
463            case 15: /* "Wep","OFF" */
464                if (!strncmp(wk_buff, "OFF", 3)) {
465                    priv->reg.privacy_invoked = 0x00;
466                    wep_on_off = WEP_OFF;
467                } else { /* 64bit or 128bit */
468                    priv->reg.privacy_invoked = 0x01;
469                    if (*wk_buff == '6') { /* 64bit */
470                        wep_on_off = WEP_ON_64BIT;
471                    } else { /* 128bit */
472                        wep_on_off = WEP_ON_128BIT;
473                    }
474                }
475                break;
476            case 16: /* "PREAMBLE_TYPE","LONG" */
477                if (!strncmp(wk_buff, "SHORT", 5)) {
478                    priv->reg.preamble = SHORT_PREAMBLE;
479                } else { /* "LONG" */
480                    priv->reg.preamble = LONG_PREAMBLE;
481                }
482                break;
483            case 17: /* "ScanType","ACTIVE_SCAN" */
484                if (!strncmp(wk_buff, "PASSIVE_SCAN", 12)) {
485                    priv->reg.scan_type = PASSIVE_SCAN;
486                } else { /* "ACTIVE_SCAN" */
487                    priv->reg.scan_type = ACTIVE_SCAN;
488                }
489                break;
490            case 18: // "ROM_FILE",ROMFILE
491                if (*wk_p != '"')
492                    break;
493                wk_p++;
494                for (j=0; *wk_p != '"'; j++) {
495                    if (wk_p == '\0') {
496                        break;
497                    }
498                    priv->reg.rom_file[j] = *wk_p++;
499                }
500                priv->reg.rom_file[j] = '\0';
501                wk_p++;
502                break;
503            case 19: /*"PhyType", "BG_MODE" */
504                if (!strncmp(wk_buff, "B_MODE", 6)) {
505                    priv->reg.phy_type = D_11B_ONLY_MODE;
506                } else if (!strncmp(wk_buff, "G_MODE", 6)) {
507                    priv->reg.phy_type = D_11G_ONLY_MODE;
508                } else {
509                    priv->reg.phy_type = D_11BG_COMPATIBLE_MODE;
510                }
511                break;
512            case 20: /* "CtsMode", "FALSE" */
513                if (!strncmp(wk_buff, "TRUE", 4)) {
514                    priv->reg.cts_mode = CTS_MODE_TRUE;
515                } else {
516                    priv->reg.cts_mode = CTS_MODE_FALSE;
517                }
518                break;
519            case 21: /* "PhyInformationTimer", "0" */
520                j = simple_strtol(wk_buff, NULL, 10);
521                priv->reg.phy_info_timer = (uint16_t)j;
522                break;
523            default:
524                break;
525            }
526            if (cur_p >= end_p) {
527                break;
528            }
529            cur_p++;
530        }
531
532    }
533#ifndef NO_FIRMWARE_CLASS
534    release_firmware(fw_entry);
535#else
536no_config_file:
537    kfree(cfg_buf);
538    set_fs(orgfs);
539    current->fsuid=orgfsuid;
540    current->fsgid=orgfsgid;
541#endif
542
543    DPRINTK(3,"\n operation_mode = %d\n channel = %d\n ssid = %s\n tx_rate = %d\n \
544   preamble = %d\n powermgt = %d\n scan_type = %d\n beacon_lost_count = %d\n rts = %d\n \
545   fragment = %d\n privacy_invoked = %d\n wep_type = %d\n wep_on_off = %d\n wep_index = %d\n romfile = %s\n",
546        priv->reg.operation_mode,priv->reg.channel,&priv->reg.ssid.body[0],priv->reg.tx_rate,
547        priv->reg.preamble,priv->reg.powermgt,priv->reg.scan_type,priv->reg.beacon_lost_count,
548        priv->reg.rts,priv->reg.fragment,priv->reg.privacy_invoked,wep_type,wep_on_off,priv->reg.wep_index,
549        &priv->reg.rom_file[0]
550        );
551    DPRINTK(3,"\n phy_type = %d\n cts_mode = %d\n tx_rate = %d\n phy_info_timer = %d\n",
552        priv->reg.phy_type,priv->reg.cts_mode,priv->reg.tx_rate,priv->reg.phy_info_timer );
553
554    return(0);
555}
556
package/ks7010/src/ks7010_sdio.c
1/*
2 * Driver for KeyStream, KS7010 based SDIO cards.
3 *
4 * ks7010_sdio.c
5 * $Id: ks7010_sdio.c 996 2009-09-14 02:54:21Z sekine $
6 *
7 * Copyright (C) 2006-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 <linux/workqueue.h>
16#include <asm/atomic.h>
17#include <linux/mmc/card.h>
18#include <linux/mmc/sdio_func.h>
19
20#include "ks_wlan.h"
21#include "ks_wlan_ioctl.h"
22#include "ks_debug.h"
23#include "ks_hostif.h"
24
25#include "ks7010_sdio.h"
26
27#define KS7010_FUNC_NUM 1
28#define KS7010_IO_BLOCK_SIZE 512
29#define KS7010_MAX_CLOCK 25000000
30
31static int reg_net = 0;
32
33static const struct sdio_device_id if_sdio_ids[] = {
34    { SDIO_DEVICE(SDIO_VENDOR_ID_KS_CODE_A, SDIO_DEVICE_ID_KS_7010) },
35    { SDIO_DEVICE(SDIO_VENDOR_ID_KS_CODE_B, SDIO_DEVICE_ID_KS_7010) },
36    { /* all zero */ }
37};
38
39struct ks_sdio_model {
40        int model;
41        const char *firmware;
42};
43
44static struct ks_sdio_model ks_sdio_models[] = {
45        {
46                /* ks7010 */
47                .model = 0x10,
48                .firmware = "ks7010sd.rom",
49        },
50};
51
52static int ks7910_sdio_probe(struct sdio_func *function, const struct sdio_device_id *device);
53static void ks7910_sdio_remove(struct sdio_func *function);
54static void ks7010_rw_function(struct work_struct *work);
55static int ks7010_sdio_read( ks_wlan_private *priv, unsigned int address,
56                 unsigned char *buffer, int length );
57static int ks7010_sdio_write( ks_wlan_private *priv, unsigned int address,
58                  unsigned char *buffer, int length );
59#ifdef NO_FIRMWARE_CLASS
60static char *romfile = ROM_FILE;
61module_param(romfile, charp, S_IRUGO);
62#endif
63/* macro */
64
65#define inc_txqhead(priv) \
66        ( priv->tx_dev.qhead = (priv->tx_dev.qhead + 1) % TX_DEVICE_BUFF_SIZE )
67#define inc_txqtail(priv) \
68        ( priv->tx_dev.qtail = (priv->tx_dev.qtail + 1) % TX_DEVICE_BUFF_SIZE )
69#define cnt_txqbody(priv) \
70        (((priv->tx_dev.qtail + TX_DEVICE_BUFF_SIZE) - (priv->tx_dev.qhead)) % TX_DEVICE_BUFF_SIZE )
71
72#define inc_rxqhead(priv) \
73        ( priv->rx_dev.qhead = (priv->rx_dev.qhead + 1) % RX_DEVICE_BUFF_SIZE )
74#define inc_rxqtail(priv) \
75        ( priv->rx_dev.qtail = (priv->rx_dev.qtail + 1) % RX_DEVICE_BUFF_SIZE )
76#define cnt_rxqbody(priv) \
77        (((priv->rx_dev.qtail + RX_DEVICE_BUFF_SIZE) - (priv->rx_dev.qhead)) % RX_DEVICE_BUFF_SIZE )
78
79void ks_wlan_hw_sleep_doze_request(ks_wlan_private *priv)
80{
81    unsigned char rw_data;
82    int retval;
83
84    DPRINTK(4, "\n");
85
86    /* clear request */
87    atomic_set(&priv->sleepstatus.doze_request,0);
88
89    if( atomic_read(&priv->sleepstatus.status) == 0){
90        rw_data = GCR_B_DOZE;
91        retval = ks7010_sdio_write(priv, GCR_B, &rw_data, sizeof(rw_data));
92        if(retval){
93            DPRINTK(1, " error : GCR_B=%02X\n", rw_data);
94            goto out;
95        }
96        DPRINTK(4, "PMG SET!! : GCR_B=%02X\n", rw_data);
97        DPRINTK(3,"sleep_mode=SLP_SLEEP\n");
98        atomic_set(&priv->sleepstatus.status, 1);
99         priv->last_doze = jiffies;
100    }
101    else{
102        DPRINTK(1,"sleep_mode=%d\n",priv->sleep_mode);
103    }
104
105out:
106    priv->sleep_mode = atomic_read(&priv->sleepstatus.status);
107    return;
108}
109
110void ks_wlan_hw_sleep_wakeup_request(ks_wlan_private *priv)
111{
112    unsigned char rw_data;
113    int retval;
114
115    DPRINTK(4, "\n");
116
117    /* clear request */
118    atomic_set(&priv->sleepstatus.wakeup_request,0);
119
120    if( atomic_read(&priv->sleepstatus.status) == 1){
121        rw_data = WAKEUP_REQ;
122        retval = ks7010_sdio_write(priv, WAKEUP, &rw_data, sizeof(rw_data));
123        if(retval){
124            DPRINTK(1, " error : WAKEUP=%02X\n", rw_data);
125            goto out;
126        }
127        DPRINTK(4, "wake up : WAKEUP=%02X\n", rw_data);
128        atomic_set(&priv->sleepstatus.status, 0);
129         priv->last_wakeup = jiffies;
130        ++priv->wakeup_count;
131    }
132    else{
133        DPRINTK(1,"sleep_mode=%d\n",priv->sleep_mode);
134    }
135
136out:
137    priv->sleep_mode = atomic_read(&priv->sleepstatus.status);
138    return;
139}
140
141
142void ks_wlan_hw_wakeup_request(ks_wlan_private *priv)
143{
144    unsigned char rw_data;
145    int retval;
146
147    DPRINTK(4, "\n");
148    if(atomic_read(&priv->psstatus.status)==PS_SNOOZE){
149        rw_data = WAKEUP_REQ;
150        retval = ks7010_sdio_write(priv, WAKEUP, &rw_data, sizeof(rw_data));
151        if(retval){
152            DPRINTK(1, " error : WAKEUP=%02X\n", rw_data);
153        }
154        DPRINTK(4, "wake up : WAKEUP=%02X\n", rw_data);
155         priv->last_wakeup = jiffies;
156        ++priv->wakeup_count;
157    }
158    else{
159        DPRINTK(1,"psstatus=%d\n",atomic_read(&priv->psstatus.status));
160    }
161}
162
163int _ks_wlan_hw_power_save(ks_wlan_private *priv)
164{
165    int rc=0;
166    unsigned char rw_data;
167    int retval;
168
169    if(priv->reg.powermgt == POWMGT_ACTIVE_MODE)
170        return rc;
171
172    if(priv->reg.operation_mode == MODE_INFRASTRUCTURE &&
173       (priv->connect_status & CONNECT_STATUS_MASK)== CONNECT_STATUS){
174
175        //DPRINTK(1,"psstatus.status=%d\n",atomic_read(&priv->psstatus.status));
176    if (priv->dev_state == DEVICE_STATE_SLEEP) {
177        switch(atomic_read(&priv->psstatus.status)){
178        case PS_SNOOZE: /* 4 */
179            break;
180        default:
181            DPRINTK(5,"\n\
182                psstatus.status=%d\n\
183                psstatus.confirm_wait=%d\n\
184                psstatus.snooze_guard=%d\n\
185                cnt_txqbody=%d\n",
186                atomic_read(&priv->psstatus.status),
187                atomic_read(&priv->psstatus.confirm_wait),
188                atomic_read(&priv->psstatus.snooze_guard),
189                cnt_txqbody(priv));
190
191            if(!atomic_read(&priv->psstatus.confirm_wait)&&
192               !atomic_read(&priv->psstatus.snooze_guard)&&
193               !cnt_txqbody(priv)){
194                retval = ks7010_sdio_read(priv, INT_PENDING, &rw_data, sizeof(rw_data));
195                if(retval){
196                    DPRINTK(1, " error : INT_PENDING=%02X\n", rw_data);
197                    queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq,&priv->ks_wlan_hw.rw_wq, 1);
198                    break;
199                }
200                if(!rw_data){
201                    rw_data = GCR_B_DOZE;
202                    retval = ks7010_sdio_write(priv, GCR_B, &rw_data, sizeof(rw_data));
203                    if(retval){
204                        DPRINTK(1, " error : GCR_B=%02X\n", rw_data);
205                        queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq,&priv->ks_wlan_hw.rw_wq, 1);
206                        break;
207                    }
208                    DPRINTK(4, "PMG SET!! : GCR_B=%02X\n", rw_data);
209                    atomic_set(&priv->psstatus.status, PS_SNOOZE);
210                    DPRINTK(3,"psstatus.status=PS_SNOOZE\n");
211                }
212                else{
213                    queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq,&priv->ks_wlan_hw.rw_wq, 1);
214                }
215            }
216            else{
217                queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq,&priv->ks_wlan_hw.rw_wq, 0);
218            }
219            break;
220        }
221    }
222
223    }
224
225    return rc;
226}
227
228int ks_wlan_hw_power_save(ks_wlan_private *priv)
229{
230    queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq,&priv->ks_wlan_hw.rw_wq, 1);
231    return 0;
232}
233
234static int ks7010_sdio_read(ks_wlan_private *priv, unsigned int address,
235                unsigned char *buffer, int length)
236{
237    int rc = -1;
238    struct ks_sdio_card *card;
239
240    card = priv->ks_wlan_hw.sdio_card;
241
242    if (length == 1) /* CMD52 */
243        *buffer = sdio_readb(card->func, address, &rc);
244    else /* CMD53 multi-block transfer */
245        rc = sdio_memcpy_fromio(card->func, buffer, address, length);
246
247    if(rc != 0){
248        printk("sdio error erorr=%d size=%d\n", rc, length);
249        ++priv->sdio_error_count;
250    }else{
251        priv->sdio_error_count=0;
252    }
253
254    return rc;
255}
256
257static int ks7010_sdio_write(ks_wlan_private *priv, unsigned int address,
258                 unsigned char *buffer, int length)
259{
260    int rc = -1;
261    struct ks_sdio_card *card;
262
263    card = priv->ks_wlan_hw.sdio_card;
264
265    if (length == 1) /* CMD52 */
266        sdio_writeb(card->func, *buffer, (unsigned int) address, &rc);
267    else /* CMD53 */
268        rc = sdio_memcpy_toio(card->func, (unsigned int) address, buffer, length);
269
270    if(rc != 0){
271        printk("sdio error erorr=%d size=%d\n", rc, length);
272        ++priv->sdio_error_count;
273    }else{
274        priv->sdio_error_count=0;
275    }
276
277    return rc;
278}
279
280static int enqueue_txdev(ks_wlan_private *priv, unsigned char *p, unsigned long size,
281          void (*complete_handler)(void *arg1, void *arg2),
282          void *arg1, void *arg2 )
283{
284    struct tx_device_buffer *sp;
285
286    if (priv->dev_state < DEVICE_STATE_BOOT) {
287        kfree(p);
288        if (complete_handler != NULL)
289            (*complete_handler)(arg1, arg2);
290        return 1;
291    }
292
293    if ((TX_DEVICE_BUFF_SIZE - 1) <= cnt_txqbody(priv)) {
294        /* in case of buffer overflow */
295        DPRINTK(1,"tx buffer overflow\n");
296        kfree(p);
297        if (complete_handler != NULL)
298            (*complete_handler)(arg1, arg2);
299        return 1;
300    }
301
302    sp = &priv->tx_dev.tx_dev_buff[priv->tx_dev.qtail];
303    sp->sendp = p;
304    sp->size = size;
305    sp->complete_handler = complete_handler;
306    sp->arg1 = arg1;
307    sp->arg2 = arg2;
308    inc_txqtail(priv);
309
310    return 0;
311}
312
313/* write data */
314static int write_to_device(ks_wlan_private *priv, unsigned char *buffer, unsigned long size )
315{
316    int rc,retval;
317    unsigned char rw_data;
318    struct hostif_hdr *hdr;
319    hdr = (struct hostif_hdr *)buffer;
320    rc=0;
321
322    DPRINTK(4,"size=%d\n", hdr->size);
323    if(hdr->event < HIF_DATA_REQ || HIF_REQ_MAX < hdr->event){
324        DPRINTK(1,"unknown event=%04X\n",hdr->event);
325        return 0;
326    }
327
328    retval = ks7010_sdio_write(priv, DATA_WINDOW, buffer, size);
329    if(retval){
330        DPRINTK(1, " write error : retval=%d\n", retval);
331        return -4;
332    }
333
334    rw_data = WRITE_STATUS_BUSY;
335    retval = ks7010_sdio_write(priv, WRITE_STATUS, &rw_data, sizeof(rw_data));
336    if(retval){
337        DPRINTK(1, " error : WRITE_STATUS=%02X\n", rw_data);
338        return -3;
339    }
340
341    return 0;
342}
343
344static void tx_device_task(void *dev)
345{
346    ks_wlan_private *priv = (ks_wlan_private *)dev;
347    struct tx_device_buffer *sp;
348    int rc = 0;
349
350    DPRINTK(4, "\n");
351    if(cnt_txqbody(priv)>0 && atomic_read(&priv->psstatus.status) != PS_SNOOZE){
352        sp = &priv->tx_dev.tx_dev_buff[priv->tx_dev.qhead];
353        if(priv->dev_state >= DEVICE_STATE_BOOT){
354            rc = write_to_device(priv, sp->sendp, sp->size);
355            if(rc){
356                DPRINTK(1, "write_to_device error !!(%d)\n", rc);
357                queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq,&priv->ks_wlan_hw.rw_wq, 1);
358                return;
359            }
360
361        }
362        kfree(sp->sendp); /* allocated memory free */
363        if(sp->complete_handler != NULL) /* TX Complete */
364            (*sp->complete_handler)(sp->arg1, sp->arg2);
365        inc_txqhead(priv);
366
367        if(cnt_txqbody(priv)>0){
368            queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq,&priv->ks_wlan_hw.rw_wq, 0);
369        }
370    }
371    return;
372}
373
374int ks_wlan_hw_tx( ks_wlan_private *priv, void *p, unsigned long size,
375           void (*complete_handler)(void *arg1, void *arg2),
376           void *arg1, void *arg2 )
377{
378    int result=0;
379    struct hostif_hdr *hdr;
380    hdr = (struct hostif_hdr *)p;
381
382    if(hdr->event < HIF_DATA_REQ || HIF_REQ_MAX < hdr->event){
383        DPRINTK(1,"unknown event=%04X\n",hdr->event);
384        return 0;
385    }
386
387    /* add event to hostt buffer */
388    priv->hostt.buff[priv->hostt.qtail] = hdr->event;
389        priv->hostt.qtail = (priv->hostt.qtail + 1) % SME_EVENT_BUFF_SIZE;
390
391    DPRINTK(4, "event=%04X\n",hdr->event);
392    spin_lock(&priv->tx_dev.tx_dev_lock);
393    result = enqueue_txdev(priv, p, size, complete_handler, arg1, arg2);
394    spin_unlock(&priv->tx_dev.tx_dev_lock);
395
396    if(cnt_txqbody(priv)>0){
397        queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq,&priv->ks_wlan_hw.rw_wq, 0);
398    }
399    return result;
400}
401
402static void rx_event_task(unsigned long dev)
403{
404        ks_wlan_private *priv = (ks_wlan_private *)dev;
405    struct rx_device_buffer *rp;
406
407    DPRINTK(4,"\n");
408
409    if(cnt_rxqbody(priv) > 0 && priv->dev_state >= DEVICE_STATE_BOOT){
410        rp = &priv->rx_dev.rx_dev_buff[priv->rx_dev.qhead];
411        hostif_receive(priv, rp->data, rp->size);
412        inc_rxqhead(priv);
413
414        if(cnt_rxqbody(priv) > 0){
415            tasklet_schedule(&priv->ks_wlan_hw.rx_bh_task);
416        }
417    }
418
419    return;
420}
421
422static void ks_wlan_hw_rx(void *dev, uint16_t size)
423{
424    ks_wlan_private *priv = (ks_wlan_private *)dev;
425    int retval;
426    struct rx_device_buffer *rx_buffer;
427    struct hostif_hdr *hdr;
428    unsigned char read_status;
429    unsigned short event=0;
430
431    DPRINTK(4,"\n");
432
433    /* receive data */
434    if (cnt_rxqbody(priv) >= (RX_DEVICE_BUFF_SIZE-1)) {
435        /* in case of buffer overflow */
436        DPRINTK(1,"rx buffer overflow \n");
437        goto error_out;
438    }
439    rx_buffer = &priv->rx_dev.rx_dev_buff[priv->rx_dev.qtail];
440
441    retval = ks7010_sdio_read(priv, DATA_WINDOW, &rx_buffer->data[0], hif_align_size(size));
442    if(retval){
443        goto error_out;
444    }
445
446    /* length check */
447    if(size > 2046 || size == 0){
448
449        DPRINTK(5,"-INVAILED DATA dump\n");
450        print_buffer(&rx_buffer->data[0],32);
451
452        /* rx_status update */
453        read_status = READ_STATUS_IDLE;
454        retval = ks7010_sdio_write(priv, READ_STATUS, &read_status, sizeof(read_status));
455        if(retval){
456            DPRINTK(1, " error : READ_STATUS=%02X\n", read_status);
457        }
458        goto error_out;
459    }
460
461    hdr = (struct hostif_hdr *)&rx_buffer->data[0];
462    rx_buffer->size = le16_to_cpu(hdr->size) + sizeof(hdr->size);
463    event = hdr->event;
464    inc_rxqtail(priv);
465
466    /* read status update */
467    read_status = READ_STATUS_IDLE;
468    retval = ks7010_sdio_write(priv, READ_STATUS, &read_status, sizeof(read_status));
469    if(retval){
470        DPRINTK(1, " error : READ_STATUS=%02X\n", read_status);
471    }
472    DPRINTK(4, "READ_STATUS=%02X\n", read_status);
473
474    if(atomic_read(&priv->psstatus.confirm_wait)){
475        if(IS_HIF_CONF(event)){
476            DPRINTK(4, "IS_HIF_CONF true !!\n");
477            atomic_dec(&priv->psstatus.confirm_wait);
478        }
479    }
480
481    /* rx_event_task((void *)priv); */
482    tasklet_schedule(&priv->ks_wlan_hw.rx_bh_task);
483
484error_out:
485    return;
486}
487
488static void ks7010_rw_function(struct work_struct *work)
489{
490    struct hw_info_t *hw;
491    struct ks_wlan_private *priv;
492    unsigned char rw_data;
493    int retval;
494
495    hw = container_of(work, struct hw_info_t, rw_wq.work);
496    priv = container_of(hw, struct ks_wlan_private, ks_wlan_hw);
497
498    DPRINTK(4,"\n");
499
500
501     /* wiat after DOZE */
502     if(time_after(priv->last_doze + ((30*HZ)/1000), jiffies )){
503         DPRINTK(4, "wait after DOZE \n");
504        queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq,&priv->ks_wlan_hw.rw_wq, 1);
505        return;
506    }
507
508    /* wiat after WAKEUP */
509    while(time_after(priv->last_wakeup + ((30*HZ)/1000), jiffies )){
510        DPRINTK(4, "wait after WAKEUP \n");
511/* queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq,&priv->ks_wlan_hw.rw_wq,
512        (priv->last_wakeup + ((30*HZ)/1000) - jiffies));*/
513        printk("wake: %lu %lu\n", priv->last_wakeup + (30* HZ)/1000, jiffies);
514        msleep(30);
515    }
516
517    sdio_claim_host(priv->ks_wlan_hw.sdio_card->func);
518
519    /* power save wakeup */
520    if(atomic_read(&priv->psstatus.status)==PS_SNOOZE){
521        if(cnt_txqbody(priv)>0){
522            ks_wlan_hw_wakeup_request(priv);
523            queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq,&priv->ks_wlan_hw.rw_wq, 1);
524        }
525        goto err_out;
526    }
527
528    /* sleep mode doze */
529    if(atomic_read(&priv->sleepstatus.doze_request)==1){
530        ks_wlan_hw_sleep_doze_request(priv);
531        goto err_out;
532    }
533    /* sleep mode wakeup */
534    if(atomic_read(&priv->sleepstatus.wakeup_request)==1){
535        ks_wlan_hw_sleep_wakeup_request(priv);
536        goto err_out;
537    }
538
539    /* read (WriteStatus/ReadDataSize FN1:00_0014) */
540    retval = ks7010_sdio_read(priv, WSTATUS_RSIZE, &rw_data, sizeof(rw_data));
541    if(retval){
542        DPRINTK(1, " error : WSTATUS_RSIZE=%02X psstatus=%d\n", rw_data,atomic_read(&priv->psstatus.status));
543        goto err_out;
544    }
545    DPRINTK(4, "WSTATUS_RSIZE=%02X\n", rw_data);
546
547    if(rw_data&RSIZE_MASK){ /* Read schedule */
548        ks_wlan_hw_rx((void *)priv, (uint16_t)(((rw_data&RSIZE_MASK)<<4)));
549    }
550    if((rw_data&WSTATUS_MASK)){
551        tx_device_task((void *)priv);
552    }
553    _ks_wlan_hw_power_save(priv);
554
555err_out:
556    sdio_release_host(priv->ks_wlan_hw.sdio_card->func);
557
558    return;
559}
560
561
562
563static void ks_sdio_interrupt(struct sdio_func *func)
564{
565    int retval;
566    struct ks_sdio_card *card;
567    ks_wlan_private *priv;
568    unsigned char status, rsize, rw_data;
569
570    card = sdio_get_drvdata(func);
571    priv = card->priv;
572    DPRINTK(4, "\n");
573    printk("%s:%s[%d]\n", __FILE__, __func__, __LINE__);
574
575    if(priv->dev_state >= DEVICE_STATE_BOOT){
576        retval = ks7010_sdio_read(priv, INT_PENDING, &status, sizeof(status));
577        if(retval){
578            DPRINTK(1, "read INT_PENDING Failed!!(%d)\n",retval);
579            goto intr_out;
580        }
581        DPRINTK(4, "INT_PENDING=%02X\n", rw_data);
582
583        /* schedule task for interrupt status */
584        /* bit7 -> Write General Communication B register */
585        /* read (General Communication B register) */
586        /* bit5 -> Write Status Idle */
587        /* bit2 -> Read Status Busy */
588        if(status&INT_GCR_B || atomic_read(&priv->psstatus.status)==PS_SNOOZE){
589            retval = ks7010_sdio_read(priv, GCR_B, &rw_data, sizeof(rw_data));
590            if(retval){
591                DPRINTK(1, " error : GCR_B=%02X\n", rw_data);
592                goto intr_out;
593            }
594            /* DPRINTK(1, "GCR_B=%02X\n", rw_data); */
595            if(rw_data == GCR_B_ACTIVE){
596                if(atomic_read(&priv->psstatus.status)==PS_SNOOZE){
597                    atomic_set(&priv->psstatus.status, PS_WAKEUP);
598                    priv->wakeup_count=0;
599                }
600                complete(&priv->psstatus.wakeup_wait);
601            }
602
603
604        }
605
606        do{
607            /* read (WriteStatus/ReadDataSize FN1:00_0014) */
608            retval = ks7010_sdio_read(priv, WSTATUS_RSIZE, &rw_data, sizeof(rw_data));
609            if(retval){
610                DPRINTK(1, " error : WSTATUS_RSIZE=%02X\n", rw_data);
611                goto intr_out;
612            }
613            DPRINTK(4, "WSTATUS_RSIZE=%02X\n", rw_data);
614            rsize=rw_data&RSIZE_MASK;
615            if(rsize){ /* Read schedule */
616                ks_wlan_hw_rx((void *)priv, (uint16_t)(((rsize)<<4)));
617            }
618            if(rw_data&WSTATUS_MASK){
619#if 0
620                if(status&INT_WRITE_STATUS && !cnt_txqbody(priv)){
621                    /* dummy write for interrupt clear */
622                    rw_data =0;
623                    retval = ks7010_sdio_write(priv, DATA_WINDOW, &rw_data, sizeof(rw_data));
624                    if (retval) {
625                        DPRINTK(1, "write DATA_WINDOW Failed!!(%d)\n",retval);
626                    }
627                    status &= ~INT_WRITE_STATUS;
628                }
629                else{
630#endif
631                    if(atomic_read(&priv->psstatus.status)==PS_SNOOZE){
632                        if(cnt_txqbody(priv)){
633                            ks_wlan_hw_wakeup_request(priv);
634                            queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq, &priv->ks_wlan_hw.rw_wq, 1);
635                            return;
636                        }
637                    }
638                    else{
639                        printk("%s:%s[%d]\n", __FILE__, __func__, __LINE__);
640                        tx_device_task((void *)priv);
641                    }
642// }
643            }
644        }while(rsize);
645    }
646
647    printk("%s:%s[%d]\n", __FILE__, __func__, __LINE__);
648
649intr_out:
650    queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq,&priv->ks_wlan_hw.rw_wq, 0);
651    printk("%s:%s[%d]\n", __FILE__, __func__, __LINE__);
652    return;
653}
654
655static int trx_device_init( ks_wlan_private *priv )
656{
657    /* initialize values (tx) */
658    priv->tx_dev.qtail = priv->tx_dev.qhead = 0;
659
660    /* initialize values (rx) */
661    priv->rx_dev.qtail = priv->rx_dev.qhead = 0;
662
663    /* initialize spinLock (tx,rx) */
664    spin_lock_init(&priv->tx_dev.tx_dev_lock);
665    spin_lock_init(&priv->rx_dev.rx_dev_lock);
666
667    tasklet_init(&priv->ks_wlan_hw.rx_bh_task, rx_event_task, (unsigned long)priv);
668
669    return 0;
670}
671
672static void trx_device_exit( ks_wlan_private *priv )
673{
674    struct tx_device_buffer *sp;
675
676    /* tx buffer clear */
677    while (cnt_txqbody(priv)>0) {
678        sp = &priv->tx_dev.tx_dev_buff[priv->tx_dev.qhead];
679        kfree(sp->sendp); /* allocated memory free */
680        if (sp->complete_handler != NULL) /* TX Complete */
681            (*sp->complete_handler)(sp->arg1, sp->arg2);
682        inc_txqhead(priv);
683    }
684
685    tasklet_kill(&priv->ks_wlan_hw.rx_bh_task);
686
687    return;
688}
689static int ks7010_sdio_update_index(ks_wlan_private *priv, u32 index)
690{
691    int rc=0;
692    int retval;
693    unsigned char *data_buf;
694    data_buf = NULL;
695
696    data_buf = kmalloc(sizeof(u32), GFP_KERNEL);
697    if(!data_buf){ rc = 1; goto error_out; }
698
699    memcpy(data_buf, &index, sizeof(index));
700    retval = ks7010_sdio_write(priv, WRITE_INDEX, data_buf, sizeof(index));
701    if(retval){ rc = 2; goto error_out; }
702
703    retval = ks7010_sdio_write(priv, READ_INDEX, data_buf, sizeof(index));
704    if(retval){ rc = 3; goto error_out; }
705error_out:
706    if(data_buf) kfree(data_buf);
707    return rc;
708}
709
710#define ROM_BUFF_SIZE (64*1024)
711static int ks7010_sdio_data_compare(ks_wlan_private *priv, u32 address,
712                    unsigned char *data, unsigned int size)
713{
714    int rc=0;
715    int retval;
716    unsigned char *read_buf;
717    read_buf = NULL;
718    read_buf = kmalloc(ROM_BUFF_SIZE, GFP_KERNEL);
719    if(!read_buf){ rc = 1; goto error_out; }
720    retval = ks7010_sdio_read(priv, address, read_buf, size);
721    if(retval){ rc = 2; goto error_out; }
722    retval = memcmp(data, read_buf, size);
723
724    if(retval){
725        DPRINTK(0, "data compare error (%d) \n",retval); rc = 3; goto error_out;
726    }
727error_out:
728    if(read_buf) kfree(read_buf);
729    return rc;
730}
731#ifndef NO_FIRMWARE_CLASS
732#include <linux/firmware.h>
733#endif
734static int ks79xx_upload_firmware(ks_wlan_private *priv, struct ks_sdio_card *card)
735{
736    unsigned int size, offset, n = 0;
737    unsigned char *rom_buf;
738    unsigned char rw_data =0;
739    int retval, rc=0;
740#ifndef NO_FIRMWARE_CLASS
741    int length;
742    const struct firmware *fw_entry = NULL;
743#else
744    int orgfsuid, orgfsgid;
745    struct file *srcf;
746    mm_segment_t orgfs;
747#endif
748
749    rom_buf = NULL;
750
751    /* buffer allocate */
752    rom_buf = kmalloc(ROM_BUFF_SIZE, GFP_KERNEL);
753    if(!rom_buf){ rc = 3; goto error_out0; }
754
755
756    sdio_claim_host(card->func);
757
758    /* Firmware running ? */
759    retval = ks7010_sdio_read(priv, GCR_A, &rw_data, sizeof(rw_data));
760    if(rw_data == GCR_A_RUN){
761        DPRINTK( 0, "MAC firmware running ...\n");
762        rc = 0;
763        goto error_out0;
764    }
765
766#ifndef NO_FIRMWARE_CLASS
767    if(request_firmware(&fw_entry, priv->reg.rom_file, &priv->ks_wlan_hw.sdio_card->func->dev)!=0){
768        DPRINTK(1,"error request_firmware() file=%s\n", priv->reg.rom_file);
769        return 1;
770    }
771    DPRINTK(4,"success request_firmware() file=%s size=%d\n", priv->reg.rom_file, fw_entry->size);
772    length = fw_entry->size;
773#else
774    orgfsuid=current->fsuid;
775    orgfsgid=current->fsgid;
776    current->fsuid=current->fsgid=0;
777    orgfs=get_fs();
778    set_fs(KERNEL_DS);
779
780    srcf = filp_open(romfile, O_RDONLY, 0);
781    if (IS_ERR(srcf)) {
782        DPRINTK(1, "error %ld opening %s\n", -PTR_ERR(srcf),romfile);
783        rc = 1;
784        goto error_out1;
785    }
786
787        if (!(srcf->f_op && srcf->f_op->read)) {
788                DPRINTK(1, "%s does not have a read method\n", romfile);
789                rc = 2;
790                goto error_out2;
791        }
792#endif
793
794    /* Load Program */
795    n = 0;
796        do {
797#ifndef NO_FIRMWARE_CLASS
798        if(length >= ROM_BUFF_SIZE){
799            size = ROM_BUFF_SIZE;
800            length = length - ROM_BUFF_SIZE;
801        }
802        else{
803            size=length;
804            length=0;
805        }
806        DPRINTK(4, "size = %d\n",size);
807        if(size == 0) break;
808        memcpy(rom_buf,fw_entry->data+n,size);
809#else
810        /* The object must have a read method */
811        size = srcf->f_op->read(srcf, rom_buf, ROM_BUFF_SIZE, &srcf->f_pos);
812        if (size < 0) {
813            DPRINTK(1, "Read %s error %d\n", priv->reg.rom_file, -retval);
814            rc = 5;
815            goto error_out2;
816        }
817        else if (size == 0) break;
818#endif
819        /* Update write index */
820        offset = n;
821        retval = ks7010_sdio_update_index(priv, KS7010_IRAM_ADDRESS+offset);
822        if(retval){ rc = 6; goto error_out1; }
823
824        /* Write data */
825        retval = ks7010_sdio_write(priv, DATA_WINDOW, rom_buf, size);
826        if(retval){ rc = 8; goto error_out1; }
827
828        /* compare */
829        retval = ks7010_sdio_data_compare(priv, DATA_WINDOW, rom_buf, size);
830        if(retval){ rc = 9; goto error_out1; }
831        n += size;
832
833       }while(size);
834
835    /* Remap request */
836    rw_data = GCR_A_REMAP;
837    retval = ks7010_sdio_write(priv, GCR_A, &rw_data, sizeof(rw_data));
838    if(retval){
839        rc = 11;
840        goto error_out1;
841    }
842    DPRINTK( 4, " REMAP Request : GCR_A=%02X\n", rw_data);
843
844    /* Firmware running check */
845    for (n = 0; n < 50; ++n) {
846        mdelay(10);/* wait_ms(10); */
847        retval = ks7010_sdio_read(priv, GCR_A, &rw_data, sizeof(rw_data));
848        if(retval){ rc = 11; goto error_out1; }
849        if(rw_data == GCR_A_RUN) break;
850    }
851    DPRINTK(4, "firmware wakeup (%d)!!!!\n",n);
852    if ((50) <= n) {
853        DPRINTK(1, "firmware can't start\n");
854                rc = 12;
855        goto error_out1;
856    }
857
858    rc = 0;
859
860#ifdef NO_FIRMWARE_CLASS
861 error_out2:
862    retval=filp_close(srcf ,NULL);
863    if (retval)
864        DPRINTK(1, "error %d closing %s\n", -retval,priv->reg.rom_file);
865
866 error_out1:
867    set_fs(orgfs);
868    current->fsuid=orgfsuid;
869    current->fsgid=orgfsgid;
870#else
871 error_out1:
872    release_firmware(fw_entry);
873#endif
874 error_out0:
875    sdio_release_host(card->func);
876    if(rom_buf)
877        kfree(rom_buf);
878    return rc;
879}
880
881static void card_init_task(struct work_struct *work)
882{
883    struct hw_info_t *hw;
884    struct ks_wlan_private *priv;
885
886    hw = container_of(work, struct hw_info_t, init_task);
887    priv = container_of(hw, struct ks_wlan_private, ks_wlan_hw);
888
889    DPRINTK(5,"\ncard_init_task()\n");
890
891    /* init_waitqueue_head(&priv->confirm_wait); */
892    init_completion(&priv->confirm_wait);
893
894    DPRINTK(5,"init_completion()\n");
895
896    /* get mac address & firmware version */
897    hostif_sme_enqueue(priv, SME_START);
898
899    DPRINTK(5,"hostif_sme_enqueu()\n");
900
901    if(!wait_for_completion_interruptible_timeout(&priv->confirm_wait,5*HZ)){
902        DPRINTK(1,"wait time out!! SME_START\n");
903    }
904
905    if(priv->mac_address_valid && priv->version_size){
906        priv->dev_state = DEVICE_STATE_PREINIT;
907    }
908
909    hostif_sme_enqueue(priv, SME_GET_EEPROM_CKSUM);
910
911    /* load initial wireless parameter */
912    hostif_sme_enqueue(priv, SME_STOP_REQUEST);
913
914    hostif_sme_enqueue(priv, SME_RTS_THRESHOLD_REQUEST);
915    hostif_sme_enqueue(priv, SME_FRAGMENTATION_THRESHOLD_REQUEST);
916
917    hostif_sme_enqueue(priv, SME_WEP_INDEX_REQUEST);
918    hostif_sme_enqueue(priv, SME_WEP_KEY1_REQUEST);
919    hostif_sme_enqueue(priv, SME_WEP_KEY2_REQUEST);
920    hostif_sme_enqueue(priv, SME_WEP_KEY3_REQUEST);
921    hostif_sme_enqueue(priv, SME_WEP_KEY4_REQUEST);
922
923    hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
924    hostif_sme_enqueue(priv, SME_RSN_ENABLED_REQUEST);
925    hostif_sme_enqueue(priv, SME_MODE_SET_REQUEST);
926    hostif_sme_enqueue(priv, SME_START_REQUEST);
927
928    if(!wait_for_completion_interruptible_timeout(&priv->confirm_wait,5*HZ)){
929        DPRINTK(1,"wait time out!! wireless parameter set\n");
930    }
931
932    if(priv->dev_state >= DEVICE_STATE_PREINIT){
933        DPRINTK(1, "DEVICE READY!!\n");
934        priv->dev_state = DEVICE_STATE_READY;
935        reg_net = register_netdev (priv->net_dev);
936        DPRINTK(3, "register_netdev=%d\n",reg_net);
937    }
938    else {
939        DPRINTK(1, "dev_state=%d\n",priv->dev_state);
940    }
941}
942
943static struct sdio_driver ks7010_sdio_driver = {
944    .name = "ks7910_sdio",
945    .id_table = if_sdio_ids,
946    .probe = ks7910_sdio_probe,
947    .remove = ks7910_sdio_remove,
948};
949
950
951extern int ks_wlan_net_start(struct net_device *dev);
952extern int ks_wlan_net_stop(struct net_device *dev);
953
954static int ks7910_sdio_probe(struct sdio_func *func, const struct sdio_device_id *device)
955{
956    ks_wlan_private *priv;
957    struct ks_sdio_card *card;
958    struct net_device *netdev;
959    unsigned char rw_data;
960    int i=0, ret;
961
962    DPRINTK(5, "ks7910_sdio_probe()\n");
963
964    priv = NULL;
965    netdev=NULL;
966
967
968    /* initilize ks_sdio_card */
969    card = kzalloc(sizeof(struct ks_sdio_card), GFP_KERNEL);
970    if (!card)
971        return -ENOMEM;
972
973    card->func = func;
974    card->model = 0x10;
975    spin_lock_init(&card->lock);
976
977    /* select model */
978    for (i = 0;i < ARRAY_SIZE(ks_sdio_models);i++) {
979        if (card->model == ks_sdio_models[i].model)
980            break;
981    }
982
983    if (i == ARRAY_SIZE(ks_sdio_models)) {
984        DPRINTK(5, "unkown card model 0x%x\n", card->model);
985        goto error;
986    }
987
988    card->firmware = ks_sdio_models[i].firmware;
989
990
991    /*** Initialize SDIO ***/
992    sdio_claim_host(func);
993
994    /* bus setting */
995    /* Issue config request to override clock rate */
996
997    /* function blocksize set */
998    ret = sdio_set_block_size(func, KS7010_IO_BLOCK_SIZE);
999    DPRINTK(5, "multi_block=%d sdio_set_block_size()=%d %d\n", func->card->cccr.multi_block, func->cur_blksize, ret);
1000
1001    /* Allocate the slot current */
1002
1003    /* function enable */
1004    ret = sdio_enable_func(func);
1005    DPRINTK(5, "sdio_enable_func() %d\n", ret);
1006    if (ret)
1007        goto error_free_card;
1008
1009    /* interrupt disable */
1010    sdio_writeb(func, 0, INT_ENABLE, &ret);
1011    if (ret)
1012        goto error_free_card;
1013    sdio_writeb(func, 0xff, INT_PENDING, &ret);
1014    if (ret)
1015        goto error_disable_func;
1016
1017    /* setup interrupt handler */
1018    ret = sdio_claim_irq(func, ks_sdio_interrupt);
1019    if (ret)
1020        goto error_disable_func;
1021
1022    sdio_release_host(func);
1023
1024    sdio_set_drvdata(func, card);
1025
1026    DPRINTK(5, "class = 0x%X, vendor = 0x%X, "
1027        "device = 0x%X\n",
1028        func->class, func->vendor, func->device);
1029
1030
1031    /* private memory allocate */
1032    netdev = alloc_etherdev(sizeof(*priv));
1033    if (netdev == NULL) {
1034        printk (KERN_ERR "ks79xx : Unable to alloc new net device\n");
1035        goto error_release_irq;
1036    }
1037    if (dev_alloc_name(netdev, netdev->name) < 0) {
1038        printk (KERN_ERR "ks79xx : Couldn't get name!\n");
1039        goto error_free_netdev;
1040    }
1041
1042    priv = netdev_priv(netdev);
1043
1044    card->priv = priv;
1045    SET_NETDEV_DEV(netdev, &card->func->dev); /* for create sysfs symlinks */
1046
1047    /* private memory initialize */
1048    priv->ks_wlan_hw.sdio_card = card;
1049    init_completion(&priv->ks_wlan_hw.ks7010_sdio_wait);
1050    priv->ks_wlan_hw.read_buf = NULL;
1051    priv->ks_wlan_hw.read_buf = kmalloc(RX_DATA_SIZE, GFP_KERNEL);
1052    if(!priv->ks_wlan_hw.read_buf){
1053        goto error_free_netdev;
1054    }
1055    priv->dev_state = DEVICE_STATE_PREBOOT;
1056    priv->net_dev = netdev;
1057    priv->firmware_version[0] = '\0';
1058    priv->version_size = 0;
1059    priv->last_doze = jiffies; /* set current jiffies */
1060    priv->last_wakeup = jiffies;
1061    memset(&priv->nstats, 0, sizeof(priv->nstats));
1062    memset(&priv->wstats, 0, sizeof(priv->wstats));
1063
1064    /* sleep mode */
1065    atomic_set(&priv->sleepstatus.doze_request,0);
1066    atomic_set(&priv->sleepstatus.wakeup_request,0);
1067    atomic_set(&priv->sleepstatus.wakeup_request,0);
1068
1069    trx_device_init(priv);
1070    hostif_init(priv);
1071        ks_wlan_net_start(netdev);
1072
1073    /* Read config file */
1074    ret = ks_wlan_read_config_file(priv);
1075    if (ret) {
1076        printk(KERN_ERR "ks79xx: read configuration file failed !! retern code = %d\n", ret);
1077        goto error_free_read_buf;
1078    }
1079
1080    /* Upload firmware */
1081    ret = ks79xx_upload_firmware(priv, card); /* firmware load */
1082    if(ret){
1083        printk(KERN_ERR "ks79xx: firmware load failed !! retern code = %d\n", ret);
1084        goto error_free_read_buf;
1085    }
1086
1087    /* interrupt setting */
1088    /* clear Interrupt status write (ARMtoSD_InterruptPending FN1:00_0024) */
1089    rw_data = 0xff;
1090    sdio_claim_host(func);
1091    ret = ks7010_sdio_write(priv, INT_PENDING, &rw_data, sizeof(rw_data));
1092    sdio_release_host(func);
1093    if(ret){
1094        DPRINTK(1, " error : INT_PENDING=%02X\n", rw_data);
1095    }
1096    DPRINTK(4, " clear Interrupt : INT_PENDING=%02X\n", rw_data);
1097
1098
1099    /* enable ks7010sdio interrupt (INT_GCR_B|INT_READ_STATUS|INT_WRITE_STATUS) */
1100    rw_data = (INT_GCR_B|INT_READ_STATUS|INT_WRITE_STATUS);
1101    sdio_claim_host(func);
1102    ret = ks7010_sdio_write(priv, INT_ENABLE, &rw_data, sizeof(rw_data));
1103    sdio_release_host(func);
1104    if(ret){
1105        DPRINTK(1, " error : INT_ENABLE=%02X\n", rw_data);
1106    }
1107    DPRINTK(4, " enable Interrupt : INT_ENABLE=%02X\n", rw_data);
1108    priv->dev_state = DEVICE_STATE_BOOT;
1109
1110    priv->ks_wlan_hw.ks7010sdio_wq = create_workqueue("ks7010sdio_wq");
1111    if(!priv->ks_wlan_hw.ks7010sdio_wq){
1112        DPRINTK(1, "create_workqueue failed !!\n");
1113        goto error_free_read_buf;
1114    }
1115
1116    priv->ks_wlan_hw.ks7010sdio_init = create_singlethread_workqueue("ks7010sdio_init");
1117    if(!priv->ks_wlan_hw.ks7010sdio_init){
1118        DPRINTK(1, "create_workqueue failed !!\n");
1119        goto error_free_sdio_wq;
1120    }
1121
1122    INIT_WORK(&priv->ks_wlan_hw.init_task, card_init_task);
1123    INIT_DELAYED_WORK(&priv->ks_wlan_hw.rw_wq, ks7010_rw_function);
1124
1125    queue_work(priv->ks_wlan_hw.ks7010sdio_init, &priv->ks_wlan_hw.init_task);
1126
1127    return 0;
1128
1129error_free_sdio_wq:
1130    flush_workqueue(priv->ks_wlan_hw.ks7010sdio_wq);
1131    destroy_workqueue(priv->ks_wlan_hw.ks7010sdio_wq);
1132    priv->ks_wlan_hw.ks7010sdio_wq = NULL;
1133error_free_read_buf:
1134    kfree(priv->ks_wlan_hw.read_buf);
1135    priv->ks_wlan_hw.read_buf = NULL;
1136error_free_netdev:
1137    free_netdev(priv->net_dev);
1138    card->priv = NULL;
1139error_release_irq:
1140    sdio_claim_host(func);
1141    sdio_release_irq(func);
1142error_disable_func:
1143    sdio_disable_func(func);
1144error_free_card:
1145    sdio_release_host(func);
1146    sdio_set_drvdata(func, NULL);
1147    kfree(card);
1148error:
1149    return -ENODEV;
1150}
1151
1152static void ks7910_sdio_remove(struct sdio_func *func)
1153{
1154    int ret;
1155    struct ks_sdio_card *card;
1156    struct ks_wlan_private *priv;
1157    struct net_device *netdev;
1158    DPRINTK(1, "ks7910_sdio_remove()\n");
1159
1160    card = sdio_get_drvdata(func);
1161
1162    if(card == NULL)
1163        return;
1164
1165    DPRINTK(1, "priv = card->priv\n");
1166    priv = card->priv;
1167    netdev = priv->net_dev;
1168    if(priv){
1169        ks_wlan_net_stop(netdev);
1170        DPRINTK(1, "ks_wlan_net_stop\n");
1171
1172        /* interrupt disable */
1173        sdio_claim_host(func);
1174        sdio_writeb(func, 0, INT_ENABLE, &ret);
1175        sdio_writeb(func, 0xff, INT_PENDING, &ret);
1176        sdio_release_host(func);
1177        DPRINTK(1, "interrupt disable\n");
1178
1179        /* send stop request to MAC */
1180        {
1181            struct hostif_stop_request_t *pp;
1182            pp = (struct hostif_stop_request_t *)kzalloc(hif_align_size(sizeof(*pp)), GFP_KERNEL );
1183            if (pp==NULL) {
1184                DPRINTK(3,"allocate memory failed..\n");
1185                return; /* to do goto ni suru*/
1186            }
1187            pp->header.size = cpu_to_le16((uint16_t)(sizeof(*pp)-sizeof(pp->header.size)));
1188            pp->header.event = cpu_to_le16((uint16_t)HIF_STOP_REQ);
1189
1190            sdio_claim_host(func);
1191            write_to_device(priv, (unsigned char *) pp, hif_align_size(sizeof(*pp)));
1192            sdio_release_host(func);
1193            kfree(pp);
1194        }
1195        DPRINTK(1, "STOP Req\n");
1196
1197        if(priv->ks_wlan_hw.ks7010sdio_wq){
1198            flush_workqueue(priv->ks_wlan_hw.ks7010sdio_wq);
1199            destroy_workqueue(priv->ks_wlan_hw.ks7010sdio_wq);
1200        }
1201        DPRINTK(1, "destroy_workqueue(priv->ks_wlan_hw.ks7010sdio_wq);\n");
1202
1203        if(priv->ks_wlan_hw.ks7010sdio_init){
1204            flush_workqueue(priv->ks_wlan_hw.ks7010sdio_init);
1205            destroy_workqueue(priv->ks_wlan_hw.ks7010sdio_init);
1206        }
1207        DPRINTK(1, "destroy_workqueue(priv->ks_wlan_hw.ks7010sdio_init);\n");
1208
1209        hostif_exit(priv);
1210        DPRINTK(1, "hostif_exit\n");
1211
1212        if(!reg_net)
1213            unregister_netdev(netdev);
1214        DPRINTK(1, "unregister_netdev\n");
1215
1216        trx_device_exit(priv);
1217        if(priv->ks_wlan_hw.read_buf){
1218            kfree(priv->ks_wlan_hw.read_buf);
1219        }
1220        free_netdev(priv->net_dev);
1221        card->priv = NULL;
1222    }
1223
1224    sdio_claim_host(func);
1225    sdio_release_irq(func);
1226    DPRINTK(1, "sdio_release_irq()\n");
1227    sdio_disable_func(func);
1228    DPRINTK(1, "sdio_disable_func()\n");
1229    sdio_release_host(func);
1230
1231    sdio_set_drvdata(func, NULL);
1232
1233    kfree(card);
1234    DPRINTK(1, "kfree()\n");
1235
1236
1237    DPRINTK(5," Bye !!\n");
1238    return;
1239}
1240
1241static int __init ks7010_sdio_init( void )
1242{
1243    int status;
1244    printk(KERN_INFO "ks7010_sdio : %s %s\n" ,__DATE__,__TIME__);
1245
1246    /* register with bus driver core */
1247    status = sdio_register_driver(&ks7010_sdio_driver);
1248    if(status != 0){
1249        DPRINTK(1,"ks79xx_sdio : failed to register with bus driver, %d\n", status );
1250    }
1251    return status;
1252}
1253
1254static void __exit ks7010_sdio_exit( void )
1255{
1256    DPRINTK(5," \n");
1257    sdio_unregister_driver(&ks7010_sdio_driver);
1258    return;
1259}
1260
1261module_init(ks7010_sdio_init);
1262module_exit(ks7010_sdio_exit);
1263
1264MODULE_AUTHOR("Qi-Hardware based on KeyStream driver");
1265MODULE_DESCRIPTION("Driver for KeyStream, KS7010 based SDIO cards. ");
1266#ifdef MODULE_LICENSE
1267MODULE_LICENSE("GPL");
1268#endif
1269MODULE_SUPPORTED_DEVICE("KS7910");
package/ks7010/src/ks7010_sdio.h
1/*
2 *
3 * Driver for KeyStream, KS7010 based SDIO cards.
4 *
5 * ks7010_sdio.h
6 * $Id: ks7010_sdio.h 1019 2009-09-28 05:41:07Z sekine $
7 *
8 * Copyright (C) 2006-2008 KeyStream Corp.
9 * Copyright (C) 2009 Renesas Technology Corp.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it undr the terms of the GNU General Public License version 2 as
13 * published by the Free Sotware Foundation.
14 */
15#ifndef _KS7010_SDIO_H
16#define _KS7010_SDIO_H
17
18#ifdef DEVICE_ALIGNMENT
19#undef DEVICE_ALIGNMENT
20#endif
21#define DEVICE_ALIGNMENT 32
22
23/* SDIO KeyStream vendor and device */
24#define SDIO_VENDOR_ID_KS_CODE_A 0x005b
25#define SDIO_VENDOR_ID_KS_CODE_B 0x0023
26#define SDIO_DEVICE_ID_KS_7010 0x7910
27
28/* Read Status Register */
29#define READ_STATUS 0x000000
30#define READ_STATUS_BUSY 0
31#define READ_STATUS_IDLE 1
32
33/* Read Index Register */
34#define READ_INDEX 0x000004
35
36/* Read Data Size Register */
37#define READ_DATA_SIZE 0x000008
38
39/* Write Status Register */
40#define WRITE_STATUS 0x00000C
41#define WRITE_STATUS_BUSY 0
42#define WRITE_STATUS_IDLE 1
43
44/* Write Index Register */
45#define WRITE_INDEX 0x000010
46
47/* Write Status/Read Data Size Register
48 * for network packet (less than 2048 bytes data)
49 */
50#define WSTATUS_RSIZE 0x000014
51#define WSTATUS_MASK 0x80 /* Write Status Register value */
52#define RSIZE_MASK 0x7F /* Read Data Size Register value [10:4] */
53
54/* ARM to SD interrupt Enable */
55#define INT_ENABLE 0x000020
56/* ARM to SD interrupt Pending */
57#define INT_PENDING 0x000024
58
59#define INT_GCR_B (1<<7)
60#define INT_GCR_A (1<<6)
61#define INT_WRITE_STATUS (1<<5)
62#define INT_WRITE_INDEX (1<<4)
63#define INT_WRITE_SIZE (1<<3)
64#define INT_READ_STATUS (1<<2)
65#define INT_READ_INDEX (1<<1)
66#define INT_READ_SIZE (1<<0)
67
68/* General Communication Register A */
69#define GCR_A 0x000028
70#define GCR_A_INIT 0
71#define GCR_A_REMAP 1
72#define GCR_A_RUN 2
73
74/* General Communication Register B */
75#define GCR_B 0x00002C
76#define GCR_B_ACTIVE 0
77#define GCR_B_DOZE 1
78
79/* Wakeup Register */
80/* #define WAKEUP 0x008104 */
81/* #define WAKEUP_REQ 0x00 */
82#define WAKEUP 0x008018
83#define WAKEUP_REQ 0x5a
84
85/* AHB Data Window 0x010000-0x01FFFF */
86#define DATA_WINDOW 0x010000
87#define WINDOW_SIZE 64*1024
88
89#define KS7010_IRAM_ADDRESS 0x06000000
90
91
92/*
93 * struct define
94 */
95struct hw_info_t {
96    struct ks_sdio_card *sdio_card;
97    struct completion ks7010_sdio_wait;
98    struct workqueue_struct *ks7010sdio_wq;
99    struct workqueue_struct *ks7010sdio_init;
100    struct work_struct init_task;
101    struct delayed_work rw_wq;
102    unsigned char *read_buf;
103    struct tasklet_struct rx_bh_task;
104};
105
106struct ks_sdio_packet {
107        struct ks_sdio_packet *next;
108        u16 nb;
109        u8 buffer[0] __attribute__((aligned(4)));
110};
111
112
113struct ks_sdio_card {
114    struct sdio_func *func;
115    struct ks_wlan_private *priv;
116    int model;
117    const char *firmware;
118        spinlock_t lock;
119};
120
121
122
123/* Tx Device struct */
124#define TX_DEVICE_BUFF_SIZE 1024
125
126struct tx_device_buffer {
127        unsigned char *sendp; /* pointer of send req data */
128        unsigned int size;
129    void (*complete_handler)(void *arg1, void *arg2);
130    void *arg1;
131    void *arg2;
132};
133
134struct tx_device{
135        struct tx_device_buffer tx_dev_buff[TX_DEVICE_BUFF_SIZE];
136        unsigned int qhead; /* tx buffer queue first pointer */
137        unsigned int qtail; /* tx buffer queue last pointer */
138        spinlock_t tx_dev_lock;
139};
140
141/* Rx Device struct */
142#define RX_DATA_SIZE (2 + 2 + 2347 + 1)
143#define RX_DEVICE_BUFF_SIZE 32
144
145struct rx_device_buffer {
146       unsigned char data[RX_DATA_SIZE];
147       unsigned int size;
148};
149
150struct rx_device{
151        struct rx_device_buffer rx_dev_buff[RX_DEVICE_BUFF_SIZE];
152        unsigned int qhead; /* rx buffer queue first pointer */
153    unsigned int qtail; /* rx buffer queue last pointer */
154    spinlock_t rx_dev_lock;
155};
156#ifndef NO_FIRMWARE_CLASS
157#define ROM_FILE "ks7010sd.rom"
158#define CFG_FILE "ks79xx.cfg"
159#else
160#define ROM_FILE "/lib/firmware/ks7010sd.rom"
161#define CFG_FILE "/lib/firmware/ks79xx.cfg"
162#endif
163#define KS_WLAN_DRIVER_VERSION_INFO "ks7010 sdio linux 007 ["__DATE__" "__TIME__"]"
164
165#endif /* _KS7010_SDIO_H */
package/ks7010/src/ks_debug.c
1/*
2 * Driver for KeyStream 11b/g wireless LAN cards.
3 *
4 * ks_debug.c
5 * $Id: ks_debug.c 991 2009-09-14 01:38:58Z 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#include "ks_wlan.h"
15#include "ks_debug.h"
16
17void print_buffer(unsigned char *p, int length)
18{
19#ifdef KS_WLAN_DEBUG
20        int i;
21#define HEX_OFFSET "\
22           +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F"
23        printk(HEX_OFFSET);
24        for (i=0; i<length; i++) {
25                if (i % 16 == 0) printk("\n%04X-%04X:", i, i+15);
26                printk(" %02X", *(p+i));
27        }
28        printk("\n");
29#endif
30}
package/ks7010/src/ks_debug.h
1/*
2 * Driver for KeyStream 11b/g wireless LAN cards.
3 *
4 * ks_debug.h
5 * $Id: ks_debug.h 991 2009-09-14 01:38:58Z 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#ifndef _KS_DEBUG_H
16#define _KS_DEBUG_H
17
18#include <linux/kernel.h>
19
20
21#ifdef KS_WLAN_DEBUG
22#define DPRINTK(n, fmt, args...) \
23                 if (KS_WLAN_DEBUG>(n)) printk(KERN_NOTICE "%s: "fmt, __FUNCTION__, ## args)
24#else
25#define DPRINTK(n, fmt, args...)
26#endif
27
28extern void print_buffer(unsigned char *p, int size);
29
30#endif /* _KS_DEBUG_H */
package/ks7010/src/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#ifndef WIRELESS_EXT
26#include <linux/wireless.h>
27#endif /* WIRELESS_EXT */
28#if WIRELESS_EXT > 12
29#include <net/iw_handler.h> /* New driver API */
30#endif /* WIRELESS_EXT > 12 */
31
32extern int ks_wlan_hw_tx(ks_wlan_private *priv, void *p, unsigned long size,
33             void (*complete_handler)(void *arg1, void *arg2),
34             void *arg1, void *arg2 );
35extern void send_packet_complete(void *, void *);
36
37extern void ks_wlan_hw_wakeup_request(ks_wlan_private *priv);
38extern int ks_wlan_hw_power_save(ks_wlan_private *priv);
39
40/* macro */
41#define inc_smeqhead(priv) \
42        ( priv->sme_i.qhead = (priv->sme_i.qhead + 1) % SME_EVENT_BUFF_SIZE )
43#define inc_smeqtail(priv) \
44        ( priv->sme_i.qtail = (priv->sme_i.qtail + 1) % SME_EVENT_BUFF_SIZE )
45#define cnt_smeqbody(priv) \
46        (((priv->sme_i.qtail + SME_EVENT_BUFF_SIZE) - (priv->sme_i.qhead)) % SME_EVENT_BUFF_SIZE )
47
48#define KS_WLAN_MEM_FLAG (GFP_ATOMIC)
49
50static
51inline u8 get_BYTE(ks_wlan_private *priv)
52{
53    u8 data;
54    data = *(priv->rxp)++;
55    /* length check in advance ! */
56    --(priv->rx_size);
57    return data;
58}
59
60static
61inline u16 get_WORD(ks_wlan_private *priv)
62{
63    u16 data;
64    data = (get_BYTE(priv) & 0xff);
65    data |= ((get_BYTE(priv) << 8) & 0xff00);
66    return data;
67}
68
69static
70inline u32 get_DWORD(ks_wlan_private *priv)
71{
72    u32 data;
73    data = (get_BYTE(priv) & 0xff);
74    data |= ((get_BYTE(priv) << 8) & 0x0000ff00);
75    data |= ((get_BYTE(priv) << 16) & 0x00ff0000);
76    data |= ((get_BYTE(priv) << 24) & 0xff000000);
77    return data;
78}
79
80void ks_wlan_hw_wakeup_task(struct work_struct *work)
81{
82    ks_wlan_private *priv = container_of(work, struct ks_wlan_private, ks_wlan_wakeup_task);
83    int ps_status = atomic_read(&priv->psstatus.status);
84
85    if(ps_status==PS_SNOOZE){
86        ks_wlan_hw_wakeup_request(priv);
87        if(!wait_for_completion_interruptible_timeout(&priv->psstatus.wakeup_wait,HZ/50)){ /* 20ms timeout */
88            DPRINTK(1,"wake up timeout !!!\n");
89            schedule_work(&priv->ks_wlan_wakeup_task);
90            return;
91        }
92    }
93    else{
94        DPRINTK(1,"ps_status=%d\n",ps_status);
95    }
96
97    /* power save */
98    if(atomic_read(&priv->sme_task.count) > 0){
99        DPRINTK(4,"sme task enable.\n");
100        tasklet_enable(&priv->sme_task);
101    }
102}
103
104static
105int ks_wlan_do_power_save(ks_wlan_private *priv)
106{
107    int rc=0;
108
109    DPRINTK(4,"psstatus.status=%d\n",atomic_read(&priv->psstatus.status));
110
111#ifdef _SDIO_
112    if((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS){
113        hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
114    }
115    else{
116        priv->dev_state = DEVICE_STATE_READY;
117    }
118#else
119    if((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS){
120        switch(atomic_read(&priv->psstatus.status)){
121        case PS_ACTIVE_SET:
122        case PS_WAKEUP:
123        case PS_SAVE_SET:
124        case PS_SNOOZE:
125            break;
126        case PS_CONF_WAIT:
127            atomic_set(&priv->psstatus.confirm_wait,0);
128            break;
129        case PS_NONE:
130        default:
131            hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
132            break;
133        }
134
135    }
136    else{
137        switch(atomic_read(&priv->psstatus.status)){
138        case PS_ACTIVE_SET:
139        case PS_WAKEUP:
140        case PS_SAVE_SET:
141            break;
142        case PS_CONF_WAIT:
143            atomic_set(&priv->psstatus.confirm_wait,0);
144            atomic_set(&priv->psstatus.status, PS_WAKEUP);
145            break;
146        case PS_SNOOZE:
147            ks_wlan_hw_power_save(priv);
148            break;
149        case PS_NONE:
150        default:
151            hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
152            break;
153        }
154    }
155#endif
156    return rc;
157}
158
159static
160int get_current_ap(ks_wlan_private *priv, struct link_ap_info_t *ap_info)
161{
162    struct local_ap_t *ap;
163#if WIRELESS_EXT > 13
164    union iwreq_data wrqu;
165    struct net_device *netdev=priv->net_dev;
166#endif /* WIRELESS_EXT > 13 */
167    int rc=0;
168
169    DPRINTK(3,"\n");
170    ap = &(priv->current_ap);
171
172    if((priv->connect_status & CONNECT_STATUS_MASK)== DISCONNECT_STATUS){
173        memset(ap,0,sizeof(struct local_ap_t));
174        return 1;
175    }
176
177    /* bssid */
178    memcpy(&(ap->bssid[0]),&(ap_info->bssid[0]),ETH_ALEN);
179    /* essid */
180    memcpy(&(ap->ssid.body[0]),&(priv->reg.ssid.body[0]),priv->reg.ssid.size);
181    ap->ssid.size = priv->reg.ssid.size;
182    /* rate_set */
183    memcpy(&(ap->rate_set.body[0]),&(ap_info->rate_set.body[0]),ap_info->rate_set.size);
184    ap->rate_set.size = ap_info->rate_set.size;
185    if(ap_info->ext_rate_set.size){
186        /* rate_set */
187        memcpy(&(ap->rate_set.body[ap->rate_set.size]),
188               &(ap_info->ext_rate_set.body[0]),
189               ap_info->ext_rate_set.size);
190        ap->rate_set.size += ap_info->ext_rate_set.size;
191    }
192    /* channel */
193    ap->channel = ap_info->ds_parameter.channel;
194    /* rssi */
195    ap->rssi = ap_info->rssi;
196    /* sq */
197    ap->sq = ap_info->sq;
198    /* noise */
199    ap->noise = ap_info->noise;
200    /* capability */
201    ap->capability = ap_info->capability;
202    /* rsn */
203    if((ap_info->rsn_mode & RSN_MODE_WPA2) && (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)){
204        ap->rsn_ie.id = 0x30;
205        if(ap_info->rsn.size <= RSN_IE_BODY_MAX){
206            ap->rsn_ie.size = ap_info->rsn.size;
207            memcpy(&(ap->rsn_ie.body[0]),&(ap_info->rsn.body[0]),ap_info->rsn.size);
208        }
209        else{
210            ap->rsn_ie.size = RSN_IE_BODY_MAX;
211            memcpy(&(ap->rsn_ie.body[0]),&(ap_info->rsn.body[0]),RSN_IE_BODY_MAX);
212        }
213    }
214    else if((ap_info->rsn_mode & RSN_MODE_WPA) && (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA)){
215        ap->wpa_ie.id = 0xdd;
216        if(ap_info->rsn.size <= RSN_IE_BODY_MAX){
217            ap->wpa_ie.size = ap_info->rsn.size;
218            memcpy(&(ap->wpa_ie.body[0]),&(ap_info->rsn.body[0]),ap_info->rsn.size);
219        }
220        else{
221            ap->wpa_ie.size = RSN_IE_BODY_MAX;
222            memcpy(&(ap->wpa_ie.body[0]),&(ap_info->rsn.body[0]),RSN_IE_BODY_MAX);
223        }
224    }
225    else{
226        ap->rsn_ie.id = 0;
227        ap->rsn_ie.size = 0;
228        ap->wpa_ie.id = 0;
229        ap->wpa_ie.size = 0;
230    }
231
232#if WIRELESS_EXT > 13
233    wrqu.data.length = 0;
234    wrqu.data.flags = 0;
235    wrqu.ap_addr.sa_family = ARPHRD_ETHER;
236    if((priv->connect_status & CONNECT_STATUS_MASK)==CONNECT_STATUS){
237        memcpy(wrqu.ap_addr.sa_data,
238               &(priv->current_ap.bssid[0]), ETH_ALEN);
239        DPRINTK(3,"IWEVENT: connect bssid=%02x:%02x:%02x:%02x:%02x:%02x\n",
240            (unsigned char)wrqu.ap_addr.sa_data[0],(unsigned char)wrqu.ap_addr.sa_data[1],
241            (unsigned char)wrqu.ap_addr.sa_data[2],(unsigned char)wrqu.ap_addr.sa_data[3],
242            (unsigned char)wrqu.ap_addr.sa_data[4],(unsigned char)wrqu.ap_addr.sa_data[5]);
243        wireless_send_event(netdev, SIOCGIWAP, &wrqu, NULL);
244    }
245#endif
246    DPRINTK(4,"\n Link AP\n");
247    DPRINTK(4," bssid=%02X:%02X:%02X:%02X:%02X:%02X\n \
248   essid=%s\n rate_set=%02X,%02X,%02X,%02X,%02X,%02X,%02X,%02X\n channel=%d\n \
249   rssi=%d\n sq=%d\n capability=%04X\n",
250        ap->bssid[0],ap->bssid[1],ap->bssid[2],ap->bssid[3],ap->bssid[4],
251        ap->bssid[5],&(ap->ssid.body[0]),ap->rate_set.body[0],ap->rate_set.body[1],
252        ap->rate_set.body[2],ap->rate_set.body[3],ap->rate_set.body[4],
253        ap->rate_set.body[5],ap->rate_set.body[6],ap->rate_set.body[7],
254        ap->channel,ap->rssi,ap->sq,ap->capability);
255    DPRINTK(4,"\n Link AP\n rsn.mode=%d\n rsn.size=%d\n",
256        ap_info->rsn_mode,ap_info->rsn.size);
257    DPRINTK(4,"\n ext_rate_set_size=%d\n rate_set_size=%d\n",
258        ap_info->ext_rate_set.size,ap_info->rate_set.size);
259
260
261    return rc;
262}
263
264static
265int get_ap_information(ks_wlan_private *priv, struct ap_info_t *ap_info, struct local_ap_t *ap)
266{
267    unsigned char *bp;
268    int bsize,offset;
269    int rc=0;
270
271    DPRINTK(3,"\n");
272    memset(ap,0,sizeof(struct local_ap_t));
273
274    /* bssid */
275    memcpy(&(ap->bssid[0]),&(ap_info->bssid[0]),ETH_ALEN);
276    /* rssi */
277    ap->rssi = ap_info->rssi;
278    /* sq */
279    ap->sq = ap_info->sq;
280    /* noise */
281    ap->noise = ap_info->noise;
282    /* capability */
283    ap->capability = ap_info->capability;
284    /* channel */
285    ap->channel = ap_info->ch_info;
286
287    bp = &(ap_info->body[0]);
288    bsize = ap_info->body_size;
289    offset = 0;
290
291    while(bsize > offset){
292        /* DPRINTK(4, "Element ID=%d \n",*bp); */
293        switch(*bp){
294        case 0: /* ssid */
295            if(*(bp+1) <= SSID_MAX_SIZE){
296                ap->ssid.size = *(bp+1);
297            }
298            else {
299                DPRINTK(1, "size over :: ssid size=%d \n",*(bp+1));
300                ap->ssid.size = SSID_MAX_SIZE;
301            }
302            memcpy(&(ap->ssid.body[0]),bp+2,ap->ssid.size);
303            break;
304        case 1: /* rate */
305        case 50: /* ext rate */
306            if((*(bp+1) + ap->rate_set.size) <= RATE_SET_MAX_SIZE){
307                memcpy(&(ap->rate_set.body[ap->rate_set.size]),bp+2,*(bp+1));
308                ap->rate_set.size += *(bp+1);
309            }
310            else{
311                DPRINTK(1, "size over :: rate size=%d \n",
312                    (*(bp+1) + ap->rate_set.size));
313                memcpy(&(ap->rate_set.body[ap->rate_set.size]),bp+2,
314                       RATE_SET_MAX_SIZE - ap->rate_set.size);
315                ap->rate_set.size += (RATE_SET_MAX_SIZE - ap->rate_set.size);
316            }
317            break;
318        case 3: /* DS parameter */
319            break;
320        case 48: /* RSN(WPA2) */
321            ap->rsn_ie.id = *bp;
322            if(*(bp+1) <= RSN_IE_BODY_MAX){
323                ap->rsn_ie.size = *(bp+1);
324            }else{
325                DPRINTK(1, "size over :: rsn size=%d \n",*(bp+1));
326                ap->rsn_ie.size = RSN_IE_BODY_MAX;
327            }
328            memcpy(&(ap->rsn_ie.body[0]),bp+2,ap->rsn_ie.size);
329            break;
330        case 221: /* WPA */
331            if(!memcmp(bp+2, "\x00\x50\xf2\x01", 4)){ /* WPA OUI check */
332                ap->wpa_ie.id = *bp;
333                if(*(bp+1) <= RSN_IE_BODY_MAX){
334                    ap->wpa_ie.size = *(bp+1);
335                }else{
336                    DPRINTK(1, "size over :: wpa size=%d \n",*(bp+1));
337                    ap->wpa_ie.size = RSN_IE_BODY_MAX;
338                }
339                memcpy(&(ap->wpa_ie.body[0]),bp+2,ap->wpa_ie.size);
340            }
341            break;
342
343        case 2: /* FH parameter */
344        case 4: /* CF parameter */
345        case 5: /* TIM */
346        case 6: /* IBSS parameter */
347        case 7: /* Country */
348        case 42: /* ERP information */
349        case 47: /* Reserve ID 47 Broadcom AP */
350            break;
351        default:
352            DPRINTK(4, "unknown Element ID=%d \n",*bp);
353            break;
354        }
355        offset += 2; /* id & size field */
356        offset += *(bp+1); /* +size offset */
357        bp += (*(bp+1) + 2); /* pointer update */
358    }
359
360    return rc;
361}
362
363static
364void hostif_data_indication(ks_wlan_private *priv)
365{
366    unsigned int rx_ind_size; /* indicate data size */
367    struct sk_buff *skb;
368    unsigned short auth_type;
369    unsigned char temp[256];
370
371    unsigned char RecvMIC[8];
372    char buf[128];
373    struct ether_hdr *eth_hdr;
374    unsigned short eth_proto;
375    unsigned long now;
376    struct mic_failure_t *mic_failure;
377    struct ieee802_1x_hdr *aa1x_hdr;
378    struct wpa_eapol_key *eap_key;
379    struct michel_mic_t michel_mic;
380#if WIRELESS_EXT > 14
381    union iwreq_data wrqu;
382#endif /* WIRELESS_EXT > 14 */
383
384    DPRINTK(3,"\n");
385
386    /* min length check */
387    if (priv->rx_size <= ETH_HLEN) {
388        DPRINTK(3,"rx_size = %d\n", priv->rx_size);
389        priv->nstats.rx_errors++;
390        return;
391    }
392
393    auth_type = get_WORD(priv); /* AuthType */
394    get_WORD(priv); /* Reserve Area */
395
396    eth_hdr = (struct ether_hdr *)(priv->rxp);
397    eth_proto = ntohs(eth_hdr->h_proto);
398    DPRINTK(3,"ether protocol = %04X\n", eth_proto);
399
400    /* source address check */
401    if (!memcmp(&priv->eth_addr[0],eth_hdr->h_source, ETH_ALEN)){
402        DPRINTK(1, "invalid : source is own mac address !!\n");
403        DPRINTK(1, "eth_hdrernet->h_dest=%02X:%02X:%02X:%02X:%02X:%02X\n",
404            eth_hdr->h_source[0],eth_hdr->h_source[1],eth_hdr->h_source[2],
405            eth_hdr->h_source[3],eth_hdr->h_source[4],eth_hdr->h_source[5]);
406        priv->nstats.rx_errors++;
407        return;
408    }
409
410    /* for WPA */
411    if (auth_type != TYPE_DATA && priv->wpa.rsn_enabled){
412        if(memcmp(&eth_hdr->h_source[0],&priv->eth_addr[0],ETH_ALEN)){ /* source address check */
413            if (eth_hdr->h_dest_snap != eth_hdr->h_source_snap){
414                DPRINTK(1,"invalid data format\n");
415                priv->nstats.rx_errors++;
416                return;
417            }
418            if(((auth_type==TYPE_PMK1 && priv->wpa.pairwise_suite == IW_AUTH_CIPHER_TKIP)||
419                (auth_type==TYPE_GMK1 && priv->wpa.group_suite == IW_AUTH_CIPHER_TKIP)||
420                (auth_type==TYPE_GMK2 && priv->wpa.group_suite == IW_AUTH_CIPHER_TKIP))
421               && priv->wpa.key[auth_type-1].key_len){
422                DPRINTK(4,"TKIP: protocol=%04X: size=%u\n", eth_proto, priv->rx_size);
423                /* MIC save */
424                memcpy(&RecvMIC[0], (priv->rxp)+((priv->rx_size)-8), 8);
425                priv->rx_size = priv->rx_size - 8;
426                if(auth_type > 0 && auth_type < 4){ /* auth_type check */
427                    MichaelMICFunction(&michel_mic,
428                               (uint8_t*)priv->wpa.key[auth_type-1].rx_mic_key,
429                               (uint8_t*)priv->rxp,
430                               (int)priv->rx_size,
431                               (uint8_t)0, /* priority */
432                               (uint8_t*)michel_mic.Result);
433                }
434                if(memcmp(michel_mic.Result, RecvMIC, 8)){
435                    now = jiffies;
436                    mic_failure = &priv->wpa.mic_failure;
437                    /* MIC FAILURE */
438                    if(mic_failure->last_failure_time &&
439                       (now - mic_failure->last_failure_time)/HZ >= 60){
440                        mic_failure->failure=0;
441                    }
442                    DPRINTK(4,"MIC FAILURE \n");
443                    if(mic_failure->failure==0){
444                        mic_failure->failure=1;
445                        mic_failure->counter=0;
446                    }else if(mic_failure->failure==1){
447                        mic_failure->failure=2;
448                        mic_failure->counter =
449                            (uint16_t)((now - mic_failure->last_failure_time)/HZ);
450                        if(!mic_failure->counter) /* mic_failure counter value range 1-60 */
451                            mic_failure->counter = 1;
452                    }
453                    priv->wpa.mic_failure.last_failure_time = now;
454#if WIRELESS_EXT > 14
455                    /* needed parameters: count, keyid, key type, TSC */
456                    sprintf(buf, "MLME-MICHAELMICFAILURE.indication(keyid=%d %scast addr="
457                        "%02x:%02x:%02x:%02x:%02x:%02x)",
458                        auth_type-1, eth_hdr->h_dest[0] & 0x01 ? "broad" : "uni",
459                        eth_hdr->h_source[0],eth_hdr->h_source[1],
460                        eth_hdr->h_source[2],eth_hdr->h_source[3],
461                        eth_hdr->h_source[4],eth_hdr->h_source[5]);
462                    memset(&wrqu, 0, sizeof(wrqu));
463                    wrqu.data.length = strlen(buf);
464                    DPRINTK(4,"IWEVENT:MICHAELMICFAILURE\n");
465                    wireless_send_event(priv->net_dev, IWEVCUSTOM, &wrqu, buf);
466#endif /* WIRELESS_EXT > 14 */
467                    return;
468                }
469            }
470        }
471    }
472
473    if((priv->connect_status & FORCE_DISCONNECT)||
474       priv->wpa.mic_failure.failure==2){
475        return;
476    }
477
478    /* check 13th byte at rx data */
479    switch (*(priv->rxp+12)) {
480    case 0xAA: /* SNAP */
481        rx_ind_size = priv->rx_size - 6;
482        skb = dev_alloc_skb (rx_ind_size);
483        DPRINTK(4,"SNAP, rx_ind_size = %d\n", rx_ind_size);
484
485        if(skb) {
486                memcpy(skb_put(skb,12),priv->rxp,12); /* 8802/FDDI MAC copy */
487                /* (SNAP+UI..) skip */
488            memcpy(skb_put(skb,rx_ind_size-12),priv->rxp+18,rx_ind_size-12); /* copy after Type */
489
490            aa1x_hdr=(struct ieee802_1x_hdr *)(priv->rxp+20);
491            if(aa1x_hdr->type == IEEE802_1X_TYPE_EAPOL_KEY && priv->wpa.rsn_enabled){
492                eap_key = (struct wpa_eapol_key *)(aa1x_hdr+1);
493                atomic_set(&priv->psstatus.snooze_guard, 1);
494            }
495
496            /* rx indication */
497            skb->dev = priv->net_dev;
498            skb->protocol = eth_type_trans (skb, skb->dev);
499            priv->nstats.rx_packets++;
500            priv->nstats.rx_bytes += rx_ind_size;
501            skb->dev->last_rx = jiffies;
502            netif_rx (skb);
503        } else {
504            printk (KERN_WARNING"%s: Memory squeeze, dropping packet.\n",skb->dev->name);
505            priv->nstats.rx_dropped++;
506        }
507        break;
508    case 0xF0: /* NETBEUI/NetBIOS */
509        rx_ind_size = (priv->rx_size + 2);
510        skb = dev_alloc_skb (rx_ind_size);
511        DPRINTK(3,"NETBEUI/NetBIOS rx_ind_size=%d\n", rx_ind_size);
512
513        if(skb) {
514                memcpy(skb_put(skb,12),priv->rxp,12); /* 8802/FDDI MAC copy */
515
516            temp[0] = (((rx_ind_size-12) >> 8) & 0xff); /* NETBEUI size add */
517            temp[1] = ((rx_ind_size-12) & 0xff);
518            memcpy(skb_put(skb,2),temp,2);
519
520            memcpy(skb_put(skb,rx_ind_size-14),priv->rxp+12,rx_ind_size-14); /* copy after Type */
521
522            aa1x_hdr=(struct ieee802_1x_hdr *)(priv->rxp+14);
523            if(aa1x_hdr->type == IEEE802_1X_TYPE_EAPOL_KEY && priv->wpa.rsn_enabled){
524                eap_key = (struct wpa_eapol_key *)(aa1x_hdr+1);
525                atomic_set(&priv->psstatus.snooze_guard, 1);
526            }
527
528            /* rx indication */
529            skb->dev = priv->net_dev;
530            skb->protocol = eth_type_trans (skb, skb->dev);
531            priv->nstats.rx_packets++;
532            priv->nstats.rx_bytes += rx_ind_size;
533            skb->dev->last_rx = jiffies;
534            netif_rx (skb);
535        } else {
536            printk (KERN_WARNING"%s: Memory squeeze, dropping packet.\n",skb->dev->name);
537            priv->nstats.rx_dropped++;
538        }
539        break;
540    default: /* other rx data */
541        DPRINTK(2,"invalid data format\n");
542        priv->nstats.rx_errors++;
543    }
544}
545
546static
547void hostif_mib_get_confirm(ks_wlan_private *priv)
548{
549    struct net_device *dev=priv->net_dev;
550    uint32_t mib_status;
551    uint32_t mib_attribute;
552    uint16_t mib_val_size;
553    uint16_t mib_val_type;
554
555    DPRINTK(3, "\n");
556
557    mib_status = get_DWORD(priv); /* MIB status */
558    mib_attribute = get_DWORD(priv); /* MIB atttibute */
559    mib_val_size = get_WORD(priv); /* MIB value size */
560    mib_val_type = get_WORD(priv); /* MIB value type */
561
562    if (mib_status != 0) {
563        /* in case of error */
564        DPRINTK(1, "attribute=%08X, status=%08X\n", mib_attribute, mib_status);
565        return;
566    }
567
568    switch (mib_attribute) {
569    case DOT11_MAC_ADDRESS:
570        /* MAC address */
571        DPRINTK(3," mib_attribute=DOT11_MAC_ADDRESS\n");
572        hostif_sme_enqueue(priv, SME_GET_MAC_ADDRESS);
573        memcpy(priv->eth_addr, priv->rxp, ETH_ALEN);
574        priv->mac_address_valid = 1;
575        dev->dev_addr[0] = priv->eth_addr[0];
576        dev->dev_addr[1] = priv->eth_addr[1];
577        dev->dev_addr[2] = priv->eth_addr[2];
578        dev->dev_addr[3] = priv->eth_addr[3];
579        dev->dev_addr[4] = priv->eth_addr[4];
580        dev->dev_addr[5] = priv->eth_addr[5];
581        dev->dev_addr[6] = 0x00;
582        dev->dev_addr[7] = 0x00;
583        printk(KERN_INFO "ks_wlan: MAC ADDRESS = %02x:%02x:%02x:%02x:%02x:%02x\n",
584               priv->eth_addr[0],priv->eth_addr[1],priv->eth_addr[2],
585               priv->eth_addr[3],priv->eth_addr[4],priv->eth_addr[5]);
586        break;
587    case DOT11_PRODUCT_VERSION:
588        /* firmware version */
589        DPRINTK(3," mib_attribute=DOT11_PRODUCT_VERSION\n");
590        priv->version_size = priv->rx_size;
591        memcpy(priv->firmware_version, priv->rxp, priv->rx_size);
592        priv->firmware_version[priv->rx_size] = '\0';
593            printk(KERN_INFO "ks_wlan: firmware ver. = %s\n",priv->firmware_version);
594        hostif_sme_enqueue(priv, SME_GET_PRODUCT_VERSION);
595        /* wake_up_interruptible_all(&priv->confirm_wait); */
596        complete(&priv->confirm_wait);
597        break;
598    case LOCAL_GAIN:
599        memcpy(&priv->gain, priv->rxp, sizeof(priv->gain));
600            DPRINTK(3, "TxMode=%d, RxMode=%d, TxGain=%d, RxGain=%d\n",
601            priv->gain.TxMode, priv->gain.RxMode, priv->gain.TxGain, priv->gain.RxGain);
602        break;
603    case LOCAL_EEPROM_SUM:
604        memcpy(&priv->eeprom_sum, priv->rxp, sizeof(priv->eeprom_sum));
605            DPRINTK(1, "eeprom_sum.type=%x, eeprom_sum.result=%x\n", priv->eeprom_sum.type, priv->eeprom_sum.result);
606        if(priv->eeprom_sum.type == 0){
607            priv->eeprom_checksum = EEPROM_CHECKSUM_NONE;
608        }else if(priv->eeprom_sum.type == 1){
609            if(priv->eeprom_sum.result == 0){
610                priv->eeprom_checksum = EEPROM_NG;
611                printk("LOCAL_EEPROM_SUM NG\n");
612            }else if(priv->eeprom_sum.result == 1){
613                priv->eeprom_checksum = EEPROM_OK;
614            }
615        }else{
616            printk("LOCAL_EEPROM_SUM error!\n");
617        }
618        break;
619    default:
620        DPRINTK(1,"mib_attribute=%08x\n",(unsigned int)mib_attribute);
621        break;
622    }
623}
624
625static
626void hostif_mib_set_confirm(ks_wlan_private *priv)
627{
628    uint32_t mib_status; /* +04 MIB Status */
629    uint32_t mib_attribute; /* +08 MIB attribute */
630
631    DPRINTK(3,"\n");
632
633    mib_status = get_DWORD(priv); /* MIB Status */
634    mib_attribute = get_DWORD(priv); /* MIB attribute */
635
636    if (mib_status != 0) {
637        /* in case of error */
638        DPRINTK(1, "error :: attribute=%08X, status=%08X\n", mib_attribute, mib_status);
639    }
640
641    switch (mib_attribute) {
642    case DOT11_RTS_THRESHOLD:
643        hostif_sme_enqueue(priv, SME_RTS_THRESHOLD_CONFIRM);
644        break;
645    case DOT11_FRAGMENTATION_THRESHOLD:
646        hostif_sme_enqueue(priv, SME_FRAGMENTATION_THRESHOLD_CONFIRM);
647        break;
648    case DOT11_WEP_DEFAULT_KEY_ID:
649        if(!priv->wpa.wpa_enabled)
650            hostif_sme_enqueue(priv, SME_WEP_INDEX_CONFIRM);
651        break;
652    case DOT11_WEP_DEFAULT_KEY_VALUE1:
653        DPRINTK(2,"DOT11_WEP_DEFAULT_KEY_VALUE1:mib_status=%d\n",(int)mib_status);
654        if(priv->wpa.rsn_enabled)
655            hostif_sme_enqueue(priv, SME_SET_PMK_TSC);
656        else
657            hostif_sme_enqueue(priv, SME_WEP_KEY1_CONFIRM);
658        break;
659    case DOT11_WEP_DEFAULT_KEY_VALUE2:
660        DPRINTK(2,"DOT11_WEP_DEFAULT_KEY_VALUE2:mib_status=%d\n",(int)mib_status);
661        if(priv->wpa.rsn_enabled)
662            hostif_sme_enqueue(priv, SME_SET_GMK1_TSC);
663        else
664            hostif_sme_enqueue(priv, SME_WEP_KEY2_CONFIRM);
665        break;
666    case DOT11_WEP_DEFAULT_KEY_VALUE3:
667        DPRINTK(2,"DOT11_WEP_DEFAULT_KEY_VALUE3:mib_status=%d\n",(int)mib_status);
668        if(priv->wpa.rsn_enabled)
669            hostif_sme_enqueue(priv, SME_SET_GMK2_TSC);
670        else
671            hostif_sme_enqueue(priv, SME_WEP_KEY3_CONFIRM);
672        break;
673    case DOT11_WEP_DEFAULT_KEY_VALUE4:
674        DPRINTK(2,"DOT11_WEP_DEFAULT_KEY_VALUE4:mib_status=%d\n",(int)mib_status);
675        if(!priv->wpa.rsn_enabled)
676            hostif_sme_enqueue(priv, SME_WEP_KEY4_CONFIRM);
677        break;
678    case DOT11_PRIVACY_INVOKED:
679        if(!priv->wpa.rsn_enabled)
680            hostif_sme_enqueue(priv, SME_WEP_FLAG_CONFIRM);
681        break;
682    case DOT11_RSN_ENABLED:
683        DPRINTK(2,"DOT11_RSN_ENABLED:mib_status=%d\n",(int)mib_status);
684        hostif_sme_enqueue(priv, SME_RSN_ENABLED_CONFIRM);
685        break;
686    case LOCAL_RSN_MODE:
687        hostif_sme_enqueue(priv, SME_RSN_MODE_CONFIRM);
688        break;
689    case LOCAL_MULTICAST_ADDRESS:
690        hostif_sme_enqueue(priv, SME_MULTICAST_REQUEST);
691        break;
692    case LOCAL_MULTICAST_FILTER:
693        hostif_sme_enqueue(priv, SME_MULTICAST_CONFIRM);
694        break;
695    case LOCAL_CURRENTADDRESS:
696        priv->mac_address_valid = 1;
697        break;
698    case DOT11_RSN_CONFIG_MULTICAST_CIPHER:
699        DPRINTK(2,"DOT11_RSN_CONFIG_MULTICAST_CIPHER:mib_status=%d\n",(int)mib_status);
700        hostif_sme_enqueue(priv, SME_RSN_MCAST_CONFIRM);
701        break;
702    case DOT11_RSN_CONFIG_UNICAST_CIPHER:
703        DPRINTK(2,"DOT11_RSN_CONFIG_UNICAST_CIPHER:mib_status=%d\n",(int)mib_status);
704        hostif_sme_enqueue(priv, SME_RSN_UCAST_CONFIRM);
705        break;
706    case DOT11_RSN_CONFIG_AUTH_SUITE:
707        DPRINTK(2,"DOT11_RSN_CONFIG_AUTH_SUITE:mib_status=%d\n",(int)mib_status);
708        hostif_sme_enqueue(priv, SME_RSN_AUTH_CONFIRM);
709        break;
710    case DOT11_PMK_TSC:
711        DPRINTK(2,"DOT11_PMK_TSC:mib_status=%d\n",(int)mib_status);
712        break;
713    case DOT11_GMK1_TSC:
714        DPRINTK(2,"DOT11_GMK1_TSC:mib_status=%d\n",(int)mib_status);
715        if(atomic_read(&priv->psstatus.snooze_guard)){
716            atomic_set(&priv->psstatus.snooze_guard, 0);
717        }
718        break;
719    case DOT11_GMK2_TSC:
720        DPRINTK(2,"DOT11_GMK2_TSC:mib_status=%d\n",(int)mib_status);
721        if(atomic_read(&priv->psstatus.snooze_guard)){
722            atomic_set(&priv->psstatus.snooze_guard, 0);
723        }
724        break;
725    case LOCAL_PMK:
726        DPRINTK(2,"LOCAL_PMK:mib_status=%d\n",(int)mib_status);
727        break;
728    case LOCAL_GAIN:
729        DPRINTK(2,"LOCAL_GAIN:mib_status=%d\n",(int)mib_status);
730        break;
731#ifdef WPS
732    case LOCAL_WPS_ENABLE:
733        DPRINTK(2,"LOCAL_WPS_ENABLE:mib_status=%d\n",(int)mib_status);
734        break;
735    case LOCAL_WPS_PROBE_REQ:
736        DPRINTK(2,"LOCAL_WPS_PROBE_REQ:mib_status=%d\n",(int)mib_status);
737        break;
738#endif /* WPS */
739    case LOCAL_REGION:
740        DPRINTK(2,"LOCAL_REGION:mib_status=%d\n",(int)mib_status);
741    default :
742        break;
743    }
744}
745
746static
747void hostif_power_mngmt_confirm(ks_wlan_private *priv)
748{
749    DPRINTK(3,"\n");
750
751    if(priv->reg.powermgt > POWMGT_ACTIVE_MODE &&
752       priv->reg.operation_mode == MODE_INFRASTRUCTURE){
753#if !defined(_SDIO_)
754        atomic_set(&priv->psstatus.status,PS_SAVE_SET);
755#endif
756        atomic_set(&priv->psstatus.confirm_wait, 0);
757        priv->dev_state = DEVICE_STATE_SLEEP;
758        ks_wlan_hw_power_save(priv);
759    }else{
760        priv->dev_state = DEVICE_STATE_READY;
761#if !defined(_SDIO_)
762        atomic_set(&priv->psstatus.status,PS_ACTIVE_SET);
763#endif
764    }
765
766}
767
768static
769void hostif_sleep_confirm(ks_wlan_private *priv)
770{
771    DPRINTK(3,"\n");
772
773    atomic_set(&priv->sleepstatus.doze_request,1);
774    queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq,&priv->ks_wlan_hw.rw_wq, 1);
775}
776
777static
778void hostif_start_confirm(ks_wlan_private *priv)
779{
780#ifdef WPS
781       union iwreq_data wrqu;
782       wrqu.data.length = 0;
783       wrqu.data.flags = 0;
784       wrqu.ap_addr.sa_family = ARPHRD_ETHER;
785       if((priv->connect_status & CONNECT_STATUS_MASK)== CONNECT_STATUS){
786               memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
787               DPRINTK(3,"IWEVENT: disconnect\n");
788               wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
789       }
790#endif
791    DPRINTK(3," scan_ind_count=%d\n",priv->scan_ind_count);
792    hostif_sme_enqueue(priv, SME_START_CONFIRM);
793}
794
795static
796void hostif_connect_indication(ks_wlan_private *priv)
797{
798    unsigned short connect_code;
799    unsigned int tmp=0;
800    unsigned int old_status=priv->connect_status;
801    struct net_device *netdev=priv->net_dev;
802#if WIRELESS_EXT > 13
803    union iwreq_data wrqu0;
804#endif /* WIRELESS_EXT > 13 */
805    connect_code = get_WORD(priv);
806
807    switch(connect_code){
808    case RESULT_CONNECT: /* connect */
809        DPRINTK(3,"connect :: scan_ind_count=%d\n",priv->scan_ind_count);
810        if(!(priv->connect_status & FORCE_DISCONNECT))
811            netif_carrier_on(netdev);
812        tmp = FORCE_DISCONNECT & priv->connect_status;
813        priv->connect_status = tmp + CONNECT_STATUS;
814        break;
815    case RESULT_DISCONNECT: /* disconnect */
816        DPRINTK(3,"disconnect :: scan_ind_count=%d\n",priv->scan_ind_count);
817        netif_carrier_off(netdev);
818        tmp = FORCE_DISCONNECT & priv->connect_status;
819        priv->connect_status = tmp + DISCONNECT_STATUS;
820        break;
821    default:
822        DPRINTK(1,"unknown connect_code=%d :: scan_ind_count=%d\n",
823            connect_code,priv->scan_ind_count);
824        netif_carrier_off(netdev);
825        tmp = FORCE_DISCONNECT & priv->connect_status;
826        priv->connect_status = tmp + DISCONNECT_STATUS;
827        break;
828    }
829
830    get_current_ap(priv, (struct link_ap_info_t *)priv->rxp);
831    if((priv->connect_status & CONNECT_STATUS_MASK)== CONNECT_STATUS &&
832       (old_status & CONNECT_STATUS_MASK)==DISCONNECT_STATUS ){
833        /* for power save */
834        atomic_set(&priv->psstatus.snooze_guard, 0);
835        atomic_set(&priv->psstatus.confirm_wait,0);
836#if !defined(_SDIO_)
837        atomic_set(&priv->psstatus.status, PS_NONE);
838#endif
839    }
840    ks_wlan_do_power_save(priv);
841
842#if WIRELESS_EXT > 13
843    wrqu0.data.length = 0;
844    wrqu0.data.flags = 0;
845    wrqu0.ap_addr.sa_family = ARPHRD_ETHER;
846    if((priv->connect_status & CONNECT_STATUS_MASK)== DISCONNECT_STATUS &&
847       (old_status & CONNECT_STATUS_MASK)==CONNECT_STATUS ){
848        memset(wrqu0.ap_addr.sa_data, '\0', ETH_ALEN);
849        DPRINTK(3,"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#endif /* WIRELESS_EXT > 13 */
854    priv->scan_ind_count=0;
855}
856
857static
858void hostif_scan_indication(ks_wlan_private *priv)
859{
860    int i;
861    struct ap_info_t *ap_info;
862
863    DPRINTK(3,"scan_ind_count = %d\n", priv->scan_ind_count);
864    ap_info = (struct ap_info_t *)(priv->rxp);
865
866    if(priv->scan_ind_count!=0){
867        for(i=0;i<priv->aplist.size;i++){ /* bssid check */
868            if(!memcmp(&(ap_info->bssid[0]),&(priv->aplist.ap[i].bssid[0]),ETH_ALEN)){
869                if(ap_info->frame_type == FRAME_TYPE_PROBE_RESP)
870                    get_ap_information(priv,ap_info,&(priv->aplist.ap[i]));
871                return;
872            }
873        }
874    }
875    priv->scan_ind_count++;
876    if(priv->scan_ind_count < LOCAL_APLIST_MAX+1){
877        DPRINTK(4," scan_ind_count=%d :: aplist.size=%d\n", priv->scan_ind_count, priv->aplist.size);
878        get_ap_information(priv,(struct ap_info_t *)(priv->rxp),&(priv->aplist.ap[priv->scan_ind_count-1]));
879        priv->aplist.size = priv->scan_ind_count;
880    }
881    else{
882        DPRINTK(4," count over :: scan_ind_count=%d\n", priv->scan_ind_count);
883    }
884
885
886}
887
888static
889void hostif_stop_confirm(ks_wlan_private *priv)
890{
891    unsigned int tmp=0;
892    unsigned int old_status=priv->connect_status;
893    struct net_device *netdev=priv->net_dev;
894    union iwreq_data wrqu0;
895
896    DPRINTK(3,"\n");
897#ifdef _SDIO_
898    if(priv->dev_state == DEVICE_STATE_SLEEP)
899        priv->dev_state = DEVICE_STATE_READY;
900#endif
901
902    /* disconnect indication */
903    if( (priv->connect_status & CONNECT_STATUS_MASK)== CONNECT_STATUS){
904        netif_carrier_off(netdev);
905        tmp = FORCE_DISCONNECT & priv->connect_status;
906        priv->connect_status = tmp | DISCONNECT_STATUS;
907        printk("IWEVENT: disconnect\n");
908
909        wrqu0.data.length = 0;
910        wrqu0.data.flags = 0;
911        wrqu0.ap_addr.sa_family = ARPHRD_ETHER;
912        if((priv->connect_status & CONNECT_STATUS_MASK)== DISCONNECT_STATUS &&
913           (old_status & CONNECT_STATUS_MASK)==CONNECT_STATUS ){
914            memset(wrqu0.ap_addr.sa_data, '\0', ETH_ALEN);
915            DPRINTK(3,"IWEVENT: disconnect\n");
916            printk("IWEVENT: disconnect\n");
917            DPRINTK(3,"disconnect :: scan_ind_count=%d\n",priv->scan_ind_count);
918            wireless_send_event(netdev, SIOCGIWAP, &wrqu0, NULL);
919        }
920        priv->scan_ind_count=0;
921    }
922
923    hostif_sme_enqueue(priv, SME_STOP_CONFIRM);
924}
925
926static
927void hostif_ps_adhoc_set_confirm(ks_wlan_private *priv)
928{
929    DPRINTK(3,"\n");
930    priv->infra_status = 0; /* infrastructure mode cancel */
931    hostif_sme_enqueue(priv, SME_MODE_SET_CONFIRM);
932
933}
934
935static
936void hostif_infrastructure_set_confirm(ks_wlan_private *priv)
937{
938    uint16_t result_code;
939    DPRINTK(3,"\n");
940    result_code = get_WORD(priv);
941    DPRINTK(3,"result code = %d\n",result_code);
942    priv->infra_status = 1; /* infrastructure mode set */
943    hostif_sme_enqueue(priv, SME_MODE_SET_CONFIRM);
944}
945
946static
947void hostif_adhoc_set_confirm(ks_wlan_private *priv)
948{
949    DPRINTK(3,"\n");
950    priv->infra_status = 1; /* infrastructure mode set */
951    hostif_sme_enqueue(priv, SME_MODE_SET_CONFIRM);
952}
953
954static
955void hostif_associate_indication(ks_wlan_private *priv)
956{
957#if WIRELESS_EXT > 14
958    struct association_request_t *assoc_req;
959    struct association_response_t *assoc_resp;
960    unsigned char *pb;
961    union iwreq_data wrqu;
962    char buf[IW_CUSTOM_MAX];
963    char *pbuf = &buf[0];
964    int i;
965
966    static const char associnfo_leader0[] = "ASSOCINFO(ReqIEs=";
967    static const char associnfo_leader1[] = " RespIEs=";
968
969    DPRINTK(3,"\n");
970    assoc_req = (struct association_request_t *)(priv->rxp);
971    assoc_resp = (struct association_response_t *)(assoc_req+1);
972    pb = (unsigned char *)(assoc_resp+1);
973
974    memset(&wrqu, 0, sizeof(wrqu));
975    memcpy(pbuf,associnfo_leader0,sizeof(associnfo_leader0)-1);
976    wrqu.data.length += sizeof(associnfo_leader0)-1;
977    pbuf += sizeof(associnfo_leader0)-1;
978
979    for (i = 0; i < assoc_req->reqIEs_size; i++)
980        pbuf += sprintf(pbuf, "%02x", *(pb+i));
981    wrqu.data.length += (assoc_req->reqIEs_size)*2;
982
983    memcpy(pbuf,associnfo_leader1,sizeof(associnfo_leader1)-1);
984    wrqu.data.length += sizeof(associnfo_leader1)-1;
985    pbuf += sizeof(associnfo_leader1)-1;
986
987    pb += assoc_req->reqIEs_size;
988    for (i = 0; i < assoc_resp->respIEs_size; i++)
989        pbuf += sprintf(pbuf, "%02x", *(pb+i));
990    wrqu.data.length += (assoc_resp->respIEs_size)*2;
991
992    pbuf += sprintf(pbuf, ")");
993    wrqu.data.length += 1;
994
995    DPRINTK(3,"IWEVENT:ASSOCINFO\n");
996    wireless_send_event(priv->net_dev, IWEVCUSTOM, &wrqu, buf);
997#endif /* WIRELESS_EXT > 14 */
998}
999
1000static
1001void hostif_bss_scan_confirm(ks_wlan_private *priv)
1002{
1003    unsigned int result_code;
1004#if WIRELESS_EXT > 13
1005    struct net_device *dev = priv->net_dev;
1006    union iwreq_data wrqu;
1007#endif /* WIRELESS_EXT > 13 */
1008    result_code = get_DWORD(priv);
1009    DPRINTK(2,"result=%d :: scan_ind_count=%d\n", result_code, priv->scan_ind_count);
1010
1011    priv->sme_i.sme_flag &= ~SME_AP_SCAN;
1012    hostif_sme_enqueue(priv, SME_BSS_SCAN_CONFIRM);
1013
1014#if WIRELESS_EXT > 13
1015    wrqu.data.length = 0;
1016    wrqu.data.flags = 0;
1017    DPRINTK(3,"IWEVENT: SCAN CONFIRM\n");
1018    wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1019#endif /* WIRELESS_EXT > 13 */
1020    priv->scan_ind_count=0;
1021}
1022
1023static
1024void hostif_phy_information_confirm(ks_wlan_private *priv)
1025{
1026    struct iw_statistics *wstats = &priv->wstats;
1027    unsigned char rssi,signal,noise;
1028    unsigned char LinkSpeed;
1029    unsigned int TransmittedFrameCount, ReceivedFragmentCount;
1030    unsigned int FailedCount, FCSErrorCount;
1031
1032    DPRINTK(3,"\n");
1033    rssi = get_BYTE(priv);
1034    signal = get_BYTE(priv);
1035    noise = get_BYTE(priv);
1036    LinkSpeed = get_BYTE(priv);
1037    TransmittedFrameCount = get_DWORD(priv);
1038    ReceivedFragmentCount = get_DWORD(priv);
1039    FailedCount = get_DWORD(priv);
1040    FCSErrorCount = get_DWORD(priv);
1041
1042    DPRINTK(4, "phyinfo confirm rssi=%d signal=%d\n", rssi, signal);
1043    priv->current_rate = (LinkSpeed & RATE_MASK);
1044    wstats->qual.qual = signal;
1045    wstats->qual.level = 256 - rssi;
1046    wstats->qual.noise = 0; /* invalid noise value */
1047    wstats->qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
1048
1049    DPRINTK(3,"\n rssi=%u\n signal=%u\n LinkSpeed=%ux500Kbps\n \
1050   TransmittedFrameCount=%u\n ReceivedFragmentCount=%u\n FailedCount=%u\n \
1051   FCSErrorCount=%u\n",
1052        rssi,signal,LinkSpeed,TransmittedFrameCount,
1053        ReceivedFragmentCount,FailedCount,FCSErrorCount);
1054
1055    /* wake_up_interruptible_all(&priv->confirm_wait); */
1056    complete(&priv->confirm_wait);
1057}
1058
1059static
1060void hostif_mic_failure_confirm(ks_wlan_private *priv)
1061{
1062    DPRINTK(3,"mic_failure=%u\n",priv->wpa.mic_failure.failure);
1063    hostif_sme_enqueue(priv, SME_MIC_FAILURE_CONFIRM);
1064}
1065
1066
1067static
1068void hostif_event_check(ks_wlan_private *priv)
1069{
1070    unsigned short event;
1071
1072    DPRINTK(4, "\n");
1073    event = get_WORD(priv); /* get event */
1074    switch (event) {
1075    case HIF_DATA_IND:
1076        hostif_data_indication(priv);
1077        break;
1078    case HIF_MIB_GET_CONF:
1079        hostif_mib_get_confirm(priv);
1080        break;
1081    case HIF_MIB_SET_CONF:
1082        hostif_mib_set_confirm(priv);
1083        break;
1084    case HIF_POWERMGT_CONF:
1085        hostif_power_mngmt_confirm(priv);
1086        break;
1087    case HIF_SLEEP_CONF:
1088        hostif_sleep_confirm(priv);
1089        break;
1090    case HIF_START_CONF:
1091        hostif_start_confirm(priv);
1092        break;
1093    case HIF_CONNECT_IND:
1094        hostif_connect_indication(priv);
1095        break;
1096    case HIF_STOP_CONF:
1097        hostif_stop_confirm(priv);
1098        break;
1099    case HIF_PS_ADH_SET_CONF:
1100        hostif_ps_adhoc_set_confirm(priv);
1101        break;
1102    case HIF_INFRA_SET_CONF:
1103    case HIF_INFRA_SET2_CONF:
1104        hostif_infrastructure_set_confirm(priv);
1105        break;
1106    case HIF_ADH_SET_CONF:
1107    case HIF_ADH_SET2_CONF:
1108        hostif_adhoc_set_confirm(priv);
1109        break;
1110    case HIF_ASSOC_INFO_IND:
1111        hostif_associate_indication(priv);
1112        break;
1113    case HIF_MIC_FAILURE_CONF:
1114        hostif_mic_failure_confirm(priv);
1115        break;
1116    case HIF_SCAN_CONF:
1117        hostif_bss_scan_confirm(priv);
1118        break;
1119    case HIF_PHY_INFO_CONF:
1120    case HIF_PHY_INFO_IND:
1121        hostif_phy_information_confirm(priv);
1122        break;
1123    case HIF_SCAN_IND:
1124        hostif_scan_indication(priv);
1125        break;
1126    case HIF_AP_SET_CONF:
1127    default:
1128        //DPRINTK(1, "undefined event[%04X]\n", event);
1129        printk("undefined event[%04X]\n", event);
1130        /* wake_up_all(&priv->confirm_wait); */
1131        complete(&priv->confirm_wait);
1132        break;
1133    }
1134
1135    /* add event to hostt buffer */
1136    priv->hostt.buff[priv->hostt.qtail] = event;
1137        priv->hostt.qtail = (priv->hostt.qtail + 1) % SME_EVENT_BUFF_SIZE;
1138}
1139
1140#define CHECK_ALINE(size) (size%4 ? (size+(4-(size%4))):size)
1141
1142int hostif_data_request(ks_wlan_private *priv, struct sk_buff *packet)
1143{
1144    unsigned int packet_len=0;
1145
1146    unsigned char *buffer=NULL;
1147    unsigned int length=0;
1148    struct hostif_data_request_t *pp;
1149    unsigned char *p;
1150    int result=0;
1151    unsigned short eth_proto;
1152    struct ether_hdr *eth_hdr;
1153    struct michel_mic_t michel_mic;
1154    unsigned short keyinfo=0;
1155    struct ieee802_1x_hdr *aa1x_hdr;
1156    struct wpa_eapol_key *eap_key;
1157    struct ethhdr *eth;
1158
1159    packet_len = packet->len;
1160    if (packet_len > ETH_FRAME_LEN) {
1161        DPRINTK(1,"bad length packet_len=%d \n", packet_len);
1162        dev_kfree_skb(packet);
1163        return -1;
1164    }
1165
1166    if(((priv->connect_status & CONNECT_STATUS_MASK)== DISCONNECT_STATUS) ||
1167       (priv->connect_status & FORCE_DISCONNECT) || priv->wpa.mic_failure.stop){
1168        DPRINTK(3," DISCONNECT\n");
1169        if(netif_queue_stopped(priv->net_dev))
1170            netif_wake_queue(priv->net_dev);
1171        if(packet)
1172            dev_kfree_skb(packet);
1173
1174        return 0;
1175    }
1176
1177    /* for PowerSave */
1178    if(atomic_read(&priv->psstatus.status)==PS_SNOOZE){ /* power save wakeup */
1179        if(!netif_queue_stopped(priv->net_dev))
1180            netif_stop_queue(priv->net_dev);
1181#if !defined(_SDIO_)
1182        schedule_work(&priv->ks_wlan_wakeup_task);
1183#endif
1184    }
1185
1186    DPRINTK(4, "skb_buff length=%d\n", packet_len);
1187    pp = (struct hostif_data_request_t *)kmalloc(hif_align_size(sizeof(*pp)+6+packet_len+8),KS_WLAN_MEM_FLAG );
1188
1189    if (pp==NULL) {
1190        DPRINTK(3, "allocate memory failed..\n");
1191        dev_kfree_skb(packet);
1192        return -2;
1193    }
1194
1195    p = (unsigned char *)pp->data;
1196
1197    buffer = packet->data;
1198    length = packet->len;
1199
1200    /* packet check */
1201    eth = (struct ethhdr *)packet->data;
1202    if (memcmp(&priv->eth_addr[0],eth->h_source, ETH_ALEN)){
1203        DPRINTK(1, "invalid mac address !!\n");
1204        DPRINTK(1, "ethernet->h_source=%02X:%02X:%02X:%02X:%02X:%02X\n",
1205            eth->h_source[0],eth->h_source[1],eth->h_source[2],
1206            eth->h_source[3],eth->h_source[4],eth->h_source[5]);
1207        return -3;
1208    }
1209
1210    /* MAC address copy */
1211        memcpy(p, buffer, 12); /* DST/SRC MAC address */
1212    p += 12;
1213    buffer += 12;
1214    length -= 12;
1215    /* EtherType/Length check */
1216    if (*(buffer+1) + (*buffer << 8) > 1500) {
1217        /* ProtocolEAP = *(buffer+1) + (*buffer << 8); */
1218            /* DPRINTK(2, "Send [SNAP]Type %x\n",ProtocolEAP); */
1219        /* SAP/CTL/OUI(6 byte) add */
1220            *p++ = 0xAA; /* DSAP */
1221        *p++ = 0xAA; /* SSAP */
1222        *p++ = 0x03; /* CTL */
1223        *p++ = 0x00; /* OUI ("000000") */
1224        *p++ = 0x00; /* OUI ("000000") */
1225        *p++ = 0x00; /* OUI ("000000") */
1226        packet_len += 6;
1227    } else {
1228        DPRINTK(4,"DIX\n");
1229            /* Length(2 byte) delete */
1230        buffer += 2;
1231        length -= 2;
1232        packet_len -= 2;
1233    }
1234
1235    /* pp->data copy */
1236    memcpy(p, buffer, length);
1237
1238    p += length;
1239
1240    /* for WPA */
1241    eth_hdr = (struct ether_hdr *)&pp->data[0];
1242    eth_proto = ntohs(eth_hdr->h_proto);
1243
1244    /* for MIC FAILUER REPORT check */
1245    if(eth_proto == ETHER_PROTOCOL_TYPE_EAP && priv->wpa.mic_failure.failure>0){
1246        aa1x_hdr=(struct ieee802_1x_hdr *)(eth_hdr+1);
1247        if(aa1x_hdr->type == IEEE802_1X_TYPE_EAPOL_KEY){
1248            eap_key = (struct wpa_eapol_key *)(aa1x_hdr+1);
1249            keyinfo=ntohs(eap_key->key_info);
1250        }
1251    }
1252
1253    if (priv->wpa.rsn_enabled && priv->wpa.key[0].key_len){
1254        if(eth_proto == ETHER_PROTOCOL_TYPE_EAP && !(priv->wpa.key[1].key_len) &&
1255           !(priv->wpa.key[2].key_len) && !(priv->wpa.key[3].key_len)){
1256            pp->auth_type = cpu_to_le16((uint16_t)TYPE_AUTH); /* no encryption */
1257        }
1258        else{
1259            if(priv->wpa.pairwise_suite == IW_AUTH_CIPHER_TKIP){
1260                MichaelMICFunction( &michel_mic,
1261                           (uint8_t*)priv->wpa.key[0].tx_mic_key,
1262                           (uint8_t*)&pp->data[0],
1263                           (int)packet_len,
1264                           (uint8_t)0, /* priority */
1265                           (uint8_t*)michel_mic.Result );
1266                memcpy(p, michel_mic.Result, 8);
1267                length += 8;
1268                packet_len += 8;
1269                p += 8;
1270                pp->auth_type = cpu_to_le16((uint16_t)TYPE_DATA);
1271
1272            }else if(priv->wpa.pairwise_suite == IW_AUTH_CIPHER_CCMP){
1273                pp->auth_type = cpu_to_le16((uint16_t)TYPE_DATA);
1274            }
1275        }
1276    }
1277    else{
1278        if(eth_proto == ETHER_PROTOCOL_TYPE_EAP)
1279            pp->auth_type = cpu_to_le16((uint16_t)TYPE_AUTH);
1280        else
1281            pp->auth_type = cpu_to_le16((uint16_t)TYPE_DATA);
1282    }
1283
1284    /* header value set */
1285    pp->header.size = cpu_to_le16((uint16_t)(sizeof(*pp)-sizeof(pp->header.size)+packet_len));
1286    pp->header.event = cpu_to_le16((uint16_t)HIF_DATA_REQ);
1287
1288    /* tx request */
1289    result = ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp) + packet_len),
1290                  (void *)send_packet_complete, (void *)priv, (void *)packet);
1291
1292    /* MIC FAILUER REPORT check */
1293    if(eth_proto == ETHER_PROTOCOL_TYPE_EAP && priv->wpa.mic_failure.failure>0){
1294        if(keyinfo & WPA_KEY_INFO_ERROR && keyinfo & WPA_KEY_INFO_REQUEST){
1295            DPRINTK(3," MIC ERROR Report SET : %04X\n", keyinfo);
1296            hostif_sme_enqueue(priv, SME_MIC_FAILURE_REQUEST);
1297        }
1298        if(priv->wpa.mic_failure.failure==2)
1299            priv->wpa.mic_failure.stop=1;
1300    }
1301
1302    return result;
1303}
1304
1305#if defined(_SPI_)
1306#define ps_confirm_wait_inc(priv)
1307#else
1308#define ps_confirm_wait_inc(priv) do{if(atomic_read(&priv->psstatus.status) > PS_ACTIVE_SET){ \
1309                                                  atomic_inc(&priv->psstatus.confirm_wait); \
1310                                                  /* atomic_set(&priv->psstatus.status, PS_CONF_WAIT);*/ \
1311                                      } }while(0)
1312#endif
1313
1314static
1315void hostif_mib_get_request( ks_wlan_private *priv, unsigned long mib_attribute)
1316{
1317    struct hostif_mib_get_request_t *pp;
1318
1319    DPRINTK(3, "\n");
1320
1321    /* make primitive */
1322    pp = (struct hostif_mib_get_request_t *)kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG );
1323    if (pp==NULL) {
1324        DPRINTK(3,"allocate memory failed..\n");
1325        return;
1326    }
1327    pp->header.size = cpu_to_le16((uint16_t)(sizeof(*pp)-sizeof(pp->header.size)));
1328    pp->header.event = cpu_to_le16((uint16_t)HIF_MIB_GET_REQ);
1329    pp->mib_attribute = cpu_to_le32((uint32_t)mib_attribute);
1330
1331    /* send to device request */
1332    ps_confirm_wait_inc(priv);
1333    ks_wlan_hw_tx( priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1334}
1335
1336static
1337void hostif_mib_set_request( ks_wlan_private *priv, unsigned long mib_attribute,
1338                 unsigned short size, unsigned short type,
1339                 void *vp )
1340{
1341    struct hostif_mib_set_request_t *pp;
1342
1343    DPRINTK(3,"\n");
1344
1345    if (priv->dev_state < DEVICE_STATE_BOOT) {
1346        DPRINTK(3,"DeviceRemove\n");
1347        return;
1348    }
1349
1350    /* make primitive */
1351    pp = (struct hostif_mib_set_request_t *)kmalloc(hif_align_size(sizeof(*pp)+size), KS_WLAN_MEM_FLAG );
1352    if (pp==NULL) {
1353        DPRINTK(3, "allocate memory failed..\n");
1354        return;
1355    }
1356
1357    pp->header.size = cpu_to_le16((uint16_t)(sizeof(*pp)-sizeof(pp->header.size)+size));
1358    pp->header.event = cpu_to_le16((uint16_t)HIF_MIB_SET_REQ);
1359    pp->mib_attribute = cpu_to_le32((uint32_t)mib_attribute);
1360    pp->mib_value.size = cpu_to_le16((uint16_t)size);
1361    pp->mib_value.type = cpu_to_le16((uint16_t)type);
1362    memcpy(&pp->mib_value.body, vp, size);
1363
1364    /* send to device request */
1365    ps_confirm_wait_inc(priv);
1366    ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp) + size), NULL, NULL, NULL);
1367}
1368
1369static
1370void hostif_start_request( ks_wlan_private *priv, unsigned char mode )
1371{
1372    struct hostif_start_request_t *pp;
1373
1374    DPRINTK(3,"\n");
1375
1376    /* make primitive */
1377    pp = (struct hostif_start_request_t *)kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG );
1378    if (pp==NULL) {
1379        DPRINTK(3, "allocate memory failed..\n");
1380        return;
1381    }
1382    pp->header.size = cpu_to_le16((uint16_t)(sizeof(*pp)-sizeof(pp->header.size)));
1383    pp->header.event = cpu_to_le16((uint16_t)HIF_START_REQ);
1384    pp->mode = cpu_to_le16((uint16_t)mode);
1385
1386    /* send to device request */
1387    ps_confirm_wait_inc(priv);
1388    ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1389
1390    priv->aplist.size = 0;
1391    priv->scan_ind_count=0;
1392}
1393
1394static
1395void hostif_ps_adhoc_set_request(ks_wlan_private *priv)
1396{
1397    struct hostif_ps_adhoc_set_request_t *pp;
1398    uint16_t capability;
1399
1400        DPRINTK(3,"\n");
1401
1402    /* make primitive */
1403    pp = (struct hostif_ps_adhoc_set_request_t *)kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG );
1404    if (pp==NULL) {
1405        DPRINTK(3, "allocate memory failed..\n");
1406        return;
1407    }
1408    memset(pp, 0, sizeof(*pp));
1409    pp->header.size = cpu_to_le16((uint16_t)(sizeof(*pp)-sizeof(pp->header.size)));
1410    pp->header.event = cpu_to_le16((uint16_t)HIF_PS_ADH_SET_REQ);
1411    pp->phy_type = cpu_to_le16((uint16_t)(priv->reg.phy_type));
1412    pp->cts_mode = cpu_to_le16((uint16_t)(priv->reg.cts_mode));
1413    pp->scan_type = cpu_to_le16((uint16_t)(priv->reg.scan_type));
1414    pp->channel = cpu_to_le16((uint16_t)(priv->reg.channel));
1415    pp->rate_set.size = priv->reg.rate_set.size;
1416    memcpy(&pp->rate_set.body[0], &priv->reg.rate_set.body[0], priv->reg.rate_set.size);
1417
1418    capability = 0x0000;
1419    if (priv->reg.preamble==SHORT_PREAMBLE) {
1420        /* short preamble */
1421        capability |= BSS_CAP_SHORT_PREAMBLE;
1422    }
1423    capability &= ~(BSS_CAP_PBCC); /* pbcc not support */
1424    if(priv->reg.phy_type != D_11B_ONLY_MODE){
1425        capability |= BSS_CAP_SHORT_SLOT_TIME; /* ShortSlotTime support */
1426        capability &= ~(BSS_CAP_DSSS_OFDM); /* DSSS OFDM */
1427    }
1428    pp->capability = cpu_to_le16((uint16_t)capability);
1429
1430    /* send to device request */
1431    ps_confirm_wait_inc(priv);
1432    ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1433}
1434
1435static
1436void hostif_infrastructure_set_request(ks_wlan_private *priv)
1437{
1438    struct hostif_infrastructure_set_request_t *pp;
1439    uint16_t capability;
1440
1441    DPRINTK(3, "ssid.size=%d \n",priv->reg.ssid.size);
1442
1443    /* make primitive */
1444    pp = (struct hostif_infrastructure_set_request_t *)kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG );
1445    if (pp==NULL) {
1446        DPRINTK(3, "allocate memory failed..\n");
1447        return;
1448    }
1449    pp->header.size = cpu_to_le16((uint16_t)(sizeof(*pp)-sizeof(pp->header.size)));
1450    pp->header.event = cpu_to_le16((uint16_t)HIF_INFRA_SET_REQ);
1451    pp->phy_type = cpu_to_le16((uint16_t)(priv->reg.phy_type));
1452    pp->cts_mode = cpu_to_le16((uint16_t)(priv->reg.cts_mode));
1453    pp->scan_type = cpu_to_le16((uint16_t)(priv->reg.scan_type));
1454
1455    pp->rate_set.size = priv->reg.rate_set.size;
1456    memcpy(&pp->rate_set.body[0], &priv->reg.rate_set.body[0], priv->reg.rate_set.size);
1457    pp->ssid.size = priv->reg.ssid.size;
1458    memcpy(&pp->ssid.body[0], &priv->reg.ssid.body[0], priv->reg.ssid.size);
1459
1460    capability = 0x0000;
1461    if (priv->reg.preamble==SHORT_PREAMBLE) {
1462        /* short preamble */
1463        capability |= BSS_CAP_SHORT_PREAMBLE;
1464    }
1465    capability &= ~(BSS_CAP_PBCC); /* pbcc not support */
1466    if(priv->reg.phy_type != D_11B_ONLY_MODE){
1467        capability |= BSS_CAP_SHORT_SLOT_TIME; /* ShortSlotTime support */
1468        capability &= ~(BSS_CAP_DSSS_OFDM); /* DSSS OFDM not support */
1469    }
1470    pp->capability = cpu_to_le16((uint16_t)capability);
1471    pp->beacon_lost_count = cpu_to_le16((uint16_t)(priv->reg.beacon_lost_count));
1472    pp->auth_type = cpu_to_le16((uint16_t)(priv->reg.authenticate_type));
1473
1474    pp->channel_list.body[0] = 1;
1475    pp->channel_list.body[1] = 8;
1476    pp->channel_list.body[2] = 2;
1477    pp->channel_list.body[3] = 9;
1478    pp->channel_list.body[4] = 3;
1479    pp->channel_list.body[5] = 10;
1480    pp->channel_list.body[6] = 4;
1481    pp->channel_list.body[7] = 11;
1482    pp->channel_list.body[8] = 5;
1483    pp->channel_list.body[9] = 12;
1484    pp->channel_list.body[10] = 6;
1485    pp->channel_list.body[11] = 13;
1486    pp->channel_list.body[12] = 7;
1487    if(priv->reg.phy_type == D_11G_ONLY_MODE){
1488        pp->channel_list.size = 13;
1489    }else{
1490        pp->channel_list.body[13] = 14;
1491        pp->channel_list.size = 14;
1492    }
1493
1494    /* send to device request */
1495    ps_confirm_wait_inc(priv);
1496    ks_wlan_hw_tx( priv, pp, hif_align_size(sizeof(*pp)),NULL, NULL, NULL);
1497}
1498
1499void hostif_infrastructure_set2_request(ks_wlan_private *priv)
1500{
1501    struct hostif_infrastructure_set2_request_t *pp;
1502    uint16_t capability;
1503
1504    DPRINTK(2, "ssid.size=%d \n",priv->reg.ssid.size);
1505
1506    /* make primitive */
1507    pp = (struct hostif_infrastructure_set2_request_t *)kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG );
1508    if (pp==NULL) {
1509        DPRINTK(3, "allocate memory failed..\n");
1510        return;
1511    }
1512    pp->header.size = cpu_to_le16((uint16_t)(sizeof(*pp)-sizeof(pp->header.size)));
1513    pp->header.event = cpu_to_le16((uint16_t)HIF_INFRA_SET2_REQ);
1514    pp->phy_type = cpu_to_le16((uint16_t)(priv->reg.phy_type));
1515    pp->cts_mode = cpu_to_le16((uint16_t)(priv->reg.cts_mode));
1516    pp->scan_type = cpu_to_le16((uint16_t)(priv->reg.scan_type));
1517
1518    pp->rate_set.size = priv->reg.rate_set.size;
1519    memcpy(&pp->rate_set.body[0], &priv->reg.rate_set.body[0], priv->reg.rate_set.size);
1520    pp->ssid.size = priv->reg.ssid.size;
1521    memcpy(&pp->ssid.body[0], &priv->reg.ssid.body[0], priv->reg.ssid.size);
1522
1523    capability = 0x0000;
1524    if (priv->reg.preamble==SHORT_PREAMBLE) {
1525        /* short preamble */
1526        capability |= BSS_CAP_SHORT_PREAMBLE;
1527    }
1528    capability &= ~(BSS_CAP_PBCC); /* pbcc not support */
1529    if(priv->reg.phy_type != D_11B_ONLY_MODE){
1530        capability |= BSS_CAP_SHORT_SLOT_TIME; /* ShortSlotTime support */
1531        capability &= ~(BSS_CAP_DSSS_OFDM); /* DSSS OFDM not support */
1532    }
1533    pp->capability = cpu_to_le16((uint16_t)capability);
1534    pp->beacon_lost_count = cpu_to_le16((uint16_t)(priv->reg.beacon_lost_count));
1535    pp->auth_type = cpu_to_le16((uint16_t)(priv->reg.authenticate_type));
1536
1537    pp->channel_list.body[0] = 1;
1538    pp->channel_list.body[1] = 8;
1539    pp->channel_list.body[2] = 2;
1540    pp->channel_list.body[3] = 9;
1541    pp->channel_list.body[4] = 3;
1542    pp->channel_list.body[5] = 10;
1543    pp->channel_list.body[6] = 4;
1544    pp->channel_list.body[7] = 11;
1545    pp->channel_list.body[8] = 5;
1546    pp->channel_list.body[9] = 12;
1547    pp->channel_list.body[10] = 6;
1548    pp->channel_list.body[11] = 13;
1549    pp->channel_list.body[12] = 7;
1550    if(priv->reg.phy_type == D_11G_ONLY_MODE){
1551        pp->channel_list.size = 13;
1552    }else{
1553        pp->channel_list.body[13] = 14;
1554        pp->channel_list.size = 14;
1555    }
1556
1557    memcpy(pp->bssid, priv->reg.bssid, ETH_ALEN);
1558
1559    /* send to device request */
1560    ps_confirm_wait_inc(priv);
1561    ks_wlan_hw_tx( priv, pp, hif_align_size(sizeof(*pp)),NULL, NULL, NULL);
1562}
1563
1564static
1565void hostif_adhoc_set_request(ks_wlan_private *priv)
1566{
1567    struct hostif_adhoc_set_request_t *pp;
1568    uint16_t capability;
1569
1570    DPRINTK(3, "\n");
1571
1572    /* make primitive */
1573    pp = (struct hostif_adhoc_set_request_t *)kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG );
1574    if (pp==NULL) {
1575        DPRINTK(3, "allocate memory failed..\n");
1576        return;
1577    }
1578    memset(pp, 0, sizeof(*pp));
1579    pp->header.size = cpu_to_le16((uint16_t)(sizeof(*pp)-sizeof(pp->header.size)));
1580    pp->header.event = cpu_to_le16((uint16_t)HIF_ADH_SET_REQ);
1581    pp->phy_type = cpu_to_le16((uint16_t)(priv->reg.phy_type));
1582    pp->cts_mode = cpu_to_le16((uint16_t)(priv->reg.cts_mode));
1583    pp->scan_type = cpu_to_le16((uint16_t)(priv->reg.scan_type));
1584    pp->channel = cpu_to_le16((uint16_t)(priv->reg.channel));
1585    pp->rate_set.size = priv->reg.rate_set.size;
1586    memcpy(&pp->rate_set.body[0], &priv->reg.rate_set.body[0], priv->reg.rate_set.size);
1587    pp->ssid.size = priv->reg.ssid.size;
1588    memcpy(&pp->ssid.body[0], &priv->reg.ssid.body[0], priv->reg.ssid.size);
1589
1590    capability = 0x0000;
1591    if (priv->reg.preamble==SHORT_PREAMBLE) {
1592        /* short preamble */
1593        capability |= BSS_CAP_SHORT_PREAMBLE;
1594    }
1595    capability &= ~(BSS_CAP_PBCC); /* pbcc not support */
1596    if(priv->reg.phy_type != D_11B_ONLY_MODE){
1597        capability |= BSS_CAP_SHORT_SLOT_TIME; /* ShortSlotTime support */
1598        capability &= ~(BSS_CAP_DSSS_OFDM); /* DSSS OFDM not support */
1599    }
1600    pp->capability = cpu_to_le16((uint16_t)capability);
1601
1602    /* send to device request */
1603    ps_confirm_wait_inc(priv);
1604    ks_wlan_hw_tx( priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1605}
1606
1607static
1608void hostif_adhoc_set2_request(ks_wlan_private *priv)
1609{
1610    struct hostif_adhoc_set2_request_t *pp;
1611    uint16_t capability;
1612
1613    DPRINTK(3, "\n");
1614
1615    /* make primitive */
1616    pp = (struct hostif_adhoc_set2_request_t *)kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG );
1617    if (pp==NULL) {
1618        DPRINTK(3, "allocate memory failed..\n");
1619        return;
1620    }
1621    memset(pp, 0, sizeof(*pp));
1622    pp->header.size = cpu_to_le16((uint16_t)(sizeof(*pp)-sizeof(pp->header.size)));
1623    pp->header.event = cpu_to_le16((uint16_t)HIF_ADH_SET_REQ);
1624    pp->phy_type = cpu_to_le16((uint16_t)(priv->reg.phy_type));
1625    pp->cts_mode = cpu_to_le16((uint16_t)(priv->reg.cts_mode));
1626    pp->scan_type = cpu_to_le16((uint16_t)(priv->reg.scan_type));
1627    pp->rate_set.size = priv->reg.rate_set.size;
1628    memcpy(&pp->rate_set.body[0], &priv->reg.rate_set.body[0], priv->reg.rate_set.size);
1629    pp->ssid.size = priv->reg.ssid.size;
1630    memcpy(&pp->ssid.body[0], &priv->reg.ssid.body[0], priv->reg.ssid.size);
1631
1632    capability = 0x0000;
1633    if (priv->reg.preamble==SHORT_PREAMBLE) {
1634        /* short preamble */
1635        capability |= BSS_CAP_SHORT_PREAMBLE;
1636    }
1637    capability &= ~(BSS_CAP_PBCC); /* pbcc not support */
1638    if(priv->reg.phy_type != D_11B_ONLY_MODE){
1639        capability |= BSS_CAP_SHORT_SLOT_TIME; /* ShortSlotTime support */
1640        capability &= ~(BSS_CAP_DSSS_OFDM); /* DSSS OFDM not support */
1641    }
1642    pp->capability = cpu_to_le16((uint16_t)capability);
1643
1644    pp->channel_list.body[0] = priv->reg.channel;
1645    pp->channel_list.size = 1;
1646    memcpy(pp->bssid, priv->reg.bssid, ETH_ALEN);
1647
1648    /* send to device request */
1649    ps_confirm_wait_inc(priv);
1650    ks_wlan_hw_tx( priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1651}
1652
1653static
1654void hostif_stop_request( ks_wlan_private *priv )
1655{
1656    struct hostif_stop_request_t *pp;
1657
1658    DPRINTK(3,"\n");
1659
1660    /* make primitive */
1661    pp = (struct hostif_stop_request_t *)kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG );
1662    if (pp==NULL) {
1663        DPRINTK(3,"allocate memory failed..\n");
1664        return;
1665    }
1666    pp->header.size = cpu_to_le16((uint16_t)(sizeof(*pp)-sizeof(pp->header.size)));
1667    pp->header.event = cpu_to_le16((uint16_t)HIF_STOP_REQ);
1668
1669    /* send to device request */
1670    ps_confirm_wait_inc(priv);
1671    ks_wlan_hw_tx( priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1672}
1673
1674static
1675void hostif_phy_information_request( ks_wlan_private *priv )
1676{
1677    struct hostif_phy_information_request_t *pp;
1678
1679    DPRINTK(3,"\n");
1680
1681    /* make primitive */
1682    pp = (struct hostif_phy_information_request_t *)kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG );
1683    if (pp==NULL) {
1684        DPRINTK(3, "allocate memory failed..\n");
1685        return;
1686    }
1687    pp->header.size = cpu_to_le16((uint16_t)(sizeof(*pp)-sizeof(pp->header.size)));
1688    pp->header.event = cpu_to_le16((uint16_t)HIF_PHY_INFO_REQ);
1689    if(priv->reg.phy_info_timer){
1690        pp->type = cpu_to_le16((uint16_t)TIME_TYPE);
1691        pp->time = cpu_to_le16((uint16_t)(priv->reg.phy_info_timer));
1692    }else{
1693        pp->type = cpu_to_le16((uint16_t)NORMAL_TYPE);
1694        pp->time = cpu_to_le16((uint16_t)0);
1695    }
1696
1697    /* send to device request */
1698    ps_confirm_wait_inc(priv);
1699    ks_wlan_hw_tx( priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1700}
1701
1702static
1703void hostif_power_mngmt_request( ks_wlan_private *priv, unsigned long mode,
1704                 unsigned long wake_up, unsigned long receiveDTIMs )
1705{
1706    struct hostif_power_mngmt_request_t *pp;
1707
1708    DPRINTK(3,"mode=%lu wake_up=%lu receiveDTIMs=%lu\n",mode,wake_up,receiveDTIMs);
1709    /* make primitive */
1710    pp = (struct hostif_power_mngmt_request_t *)kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG );
1711    if (pp==NULL) {
1712        DPRINTK(3,"allocate memory failed..\n");
1713        return;
1714    }
1715    pp->header.size = cpu_to_le16((uint16_t)(sizeof(*pp)-sizeof(pp->header.size)));
1716    pp->header.event = cpu_to_le16((uint16_t)HIF_POWERMGT_REQ);
1717    pp->mode = cpu_to_le32((uint32_t)mode);
1718    pp->wake_up = cpu_to_le32((uint32_t)wake_up);
1719    pp->receiveDTIMs = cpu_to_le32((uint32_t)receiveDTIMs);
1720
1721    /* send to device request */
1722    ps_confirm_wait_inc(priv);
1723    ks_wlan_hw_tx( priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1724}
1725
1726static
1727void hostif_sleep_request( ks_wlan_private *priv, unsigned long mode)
1728{
1729    struct hostif_sleep_request_t *pp;
1730
1731    DPRINTK(3,"mode=%lu \n",mode);
1732
1733    if(mode == SLP_SLEEP){
1734        /* make primitive */
1735        pp = (struct hostif_sleep_request_t *)kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG );
1736        if (pp==NULL) {
1737            DPRINTK(3,"allocate memory failed..\n");
1738            return;
1739        }
1740        pp->header.size = cpu_to_le16((uint16_t)(sizeof(*pp)-sizeof(pp->header.size)));
1741        pp->header.event = cpu_to_le16((uint16_t)HIF_SLEEP_REQ);
1742
1743        /* send to device request */
1744        ps_confirm_wait_inc(priv);
1745        ks_wlan_hw_tx( priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1746    }else if(mode == SLP_ACTIVE){
1747        atomic_set(&priv->sleepstatus.wakeup_request,1);
1748        queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq,&priv->ks_wlan_hw.rw_wq, 1);
1749    }else{
1750        DPRINTK(3,"invalid mode %ld \n", mode);
1751        return;
1752    }
1753}
1754
1755
1756static
1757void hostif_bss_scan_request( ks_wlan_private *priv, unsigned long scan_type , uint8_t *scan_ssid, uint8_t scan_ssid_len)
1758{
1759    struct hostif_bss_scan_request_t *pp;
1760
1761    DPRINTK(2,"\n");
1762    /* make primitive */
1763    pp = (struct hostif_bss_scan_request_t *)kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG );
1764    if (pp==NULL) {
1765        DPRINTK(3,"allocate memory failed..\n");
1766        return;
1767    }
1768    pp->header.size = cpu_to_le16((uint16_t)(sizeof(*pp)-sizeof(pp->header.size)));
1769    pp->header.event = cpu_to_le16((uint16_t)HIF_SCAN_REQ);
1770    pp->scan_type = scan_type;
1771
1772    pp->ch_time_min = cpu_to_le32((uint32_t)110); /* default value */
1773    pp->ch_time_max = cpu_to_le32((uint32_t)130); /* default value */
1774    pp->channel_list.body[0] = 1;
1775    pp->channel_list.body[1] = 8;
1776    pp->channel_list.body[2] = 2;
1777    pp->channel_list.body[3] = 9;
1778    pp->channel_list.body[4] = 3;
1779    pp->channel_list.body[5] = 10;
1780    pp->channel_list.body[6] = 4;
1781    pp->channel_list.body[7] = 11;
1782    pp->channel_list.body[8] = 5;
1783    pp->channel_list.body[9] = 12;
1784    pp->channel_list.body[10] = 6;
1785    pp->channel_list.body[11] = 13;
1786    pp->channel_list.body[12] = 7;
1787    if(priv->reg.phy_type == D_11G_ONLY_MODE){
1788        pp->channel_list.size = 13;
1789    }else{
1790        pp->channel_list.body[13] = 14;
1791        pp->channel_list.size = 14;
1792    }
1793    pp->ssid.size = 0;
1794
1795    /* specified SSID SCAN */
1796    if(scan_ssid_len > 0 && scan_ssid_len <= 32){
1797        pp->ssid.size = scan_ssid_len;
1798        memcpy(&pp->ssid.body[0], scan_ssid, scan_ssid_len);
1799    }
1800
1801
1802    /* send to device request */
1803    ps_confirm_wait_inc(priv);
1804    ks_wlan_hw_tx( priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1805
1806    priv->aplist.size = 0;
1807    priv->scan_ind_count=0;
1808}
1809
1810static
1811void hostif_mic_failure_request( ks_wlan_private *priv, unsigned short failure_count,
1812                 unsigned short timer )
1813{
1814    struct hostif_mic_failure_request_t *pp;
1815
1816    DPRINTK(3,"count=%d :: timer=%d\n",failure_count,timer);
1817    /* make primitive */
1818    pp = (struct hostif_mic_failure_request_t *)kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG );
1819    if (pp==NULL) {
1820        DPRINTK(3,"allocate memory failed..\n");
1821        return;
1822    }
1823    pp->header.size = cpu_to_le16((uint16_t)(sizeof(*pp)-sizeof(pp->header.size)));
1824    pp->header.event = cpu_to_le16((uint16_t)HIF_MIC_FAILURE_REQ);
1825    pp->failure_count = cpu_to_le16((uint16_t)failure_count);
1826    pp->timer = cpu_to_le16((uint16_t)timer);
1827
1828    /* send to device request */
1829    ps_confirm_wait_inc(priv);
1830    ks_wlan_hw_tx( priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1831}
1832
1833/* Device I/O Recieve indicate */
1834static void devio_rec_ind(ks_wlan_private *priv, unsigned char *p, unsigned int size)
1835{
1836    if (priv->device_open_status) {
1837        spin_lock(&priv->dev_read_lock); /* request spin lock */
1838        priv->dev_data[atomic_read(&priv->rec_count)] = p;
1839        priv->dev_size[atomic_read(&priv->rec_count)] = size;
1840
1841        if (atomic_read(&priv->event_count) != DEVICE_STOCK_COUNT) {
1842            /* rx event count inc */
1843            atomic_inc(&priv->event_count);
1844        }
1845        atomic_inc(&priv->rec_count);
1846        if (atomic_read(&priv->rec_count)==DEVICE_STOCK_COUNT)
1847            atomic_set(&priv->rec_count, 0);
1848
1849            wake_up_interruptible_all(&priv->devread_wait);
1850
1851        /* release spin lock */
1852        spin_unlock(&priv->dev_read_lock);
1853    }
1854}
1855
1856void hostif_receive( ks_wlan_private *priv, unsigned char *p, unsigned int size )
1857{
1858    DPRINTK(4,"\n");
1859
1860    devio_rec_ind(priv, p, size);
1861
1862    priv->rxp = p;
1863    priv->rx_size = size;
1864
1865    if (get_WORD(priv) == priv->rx_size) { /* length check !! */
1866        hostif_event_check(priv); /* event check */
1867    }
1868}
1869
1870
1871static
1872void hostif_sme_set_wep(ks_wlan_private *priv, int type)
1873{
1874    uint32_t val;
1875    switch(type){
1876    case SME_WEP_INDEX_REQUEST:
1877        val = cpu_to_le32((uint32_t)(priv->reg.wep_index));
1878        hostif_mib_set_request(priv, DOT11_WEP_DEFAULT_KEY_ID,
1879                       sizeof(val), MIB_VALUE_TYPE_INT,
1880                       &val );
1881        break;
1882    case SME_WEP_KEY1_REQUEST:
1883        if(!priv->wpa.wpa_enabled)
1884            hostif_mib_set_request(priv, DOT11_WEP_DEFAULT_KEY_VALUE1,
1885                           priv->reg.wep_key[0].size, MIB_VALUE_TYPE_OSTRING,
1886                           &priv->reg.wep_key[0].val[0] );
1887        break;
1888    case SME_WEP_KEY2_REQUEST:
1889        if(!priv->wpa.wpa_enabled)
1890            hostif_mib_set_request(priv, DOT11_WEP_DEFAULT_KEY_VALUE2,
1891                           priv->reg.wep_key[1].size, MIB_VALUE_TYPE_OSTRING,
1892                           &priv->reg.wep_key[1].val[0]);
1893        break;
1894    case SME_WEP_KEY3_REQUEST:
1895        if(!priv->wpa.wpa_enabled)
1896            hostif_mib_set_request(priv, DOT11_WEP_DEFAULT_KEY_VALUE3,
1897                           priv->reg.wep_key[2].size, MIB_VALUE_TYPE_OSTRING,
1898                           &priv->reg.wep_key[2].val[0] );
1899        break;
1900    case SME_WEP_KEY4_REQUEST:
1901        if(!priv->wpa.wpa_enabled)
1902            hostif_mib_set_request(priv, DOT11_WEP_DEFAULT_KEY_VALUE4,
1903                           priv->reg.wep_key[3].size, MIB_VALUE_TYPE_OSTRING,
1904                           &priv->reg.wep_key[3].val[0]);
1905        break;
1906    case SME_WEP_FLAG_REQUEST:
1907        val = cpu_to_le32((uint32_t)(priv->reg.privacy_invoked));
1908        hostif_mib_set_request(priv, DOT11_PRIVACY_INVOKED,
1909                       sizeof(val), MIB_VALUE_TYPE_BOOL,
1910                       &val );
1911        break;
1912    }
1913
1914    return ;
1915}
1916
1917struct wpa_suite_t {
1918    unsigned short size;
1919    unsigned char suite[4][CIPHER_ID_LEN];
1920} __attribute__((packed));
1921
1922struct rsn_mode_t {
1923    uint32_t rsn_mode;
1924    uint16_t rsn_capability;
1925} __attribute__((packed));
1926
1927static
1928void hostif_sme_set_rsn(ks_wlan_private *priv, int type)
1929{
1930    struct wpa_suite_t wpa_suite;
1931    struct rsn_mode_t rsn_mode;
1932    uint32_t val;
1933
1934    memset(&wpa_suite,0,sizeof(wpa_suite));
1935
1936    switch(type){
1937    case SME_RSN_UCAST_REQUEST:
1938        wpa_suite.size=cpu_to_le16((uint16_t)1);
1939        switch(priv->wpa.pairwise_suite){
1940        case IW_AUTH_CIPHER_NONE:
1941            if(priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
1942                memcpy(&wpa_suite.suite[0][0],CIPHER_ID_WPA2_NONE,CIPHER_ID_LEN);
1943            else
1944                memcpy(&wpa_suite.suite[0][0],CIPHER_ID_WPA_NONE,CIPHER_ID_LEN);
1945            break;
1946        case IW_AUTH_CIPHER_WEP40:
1947            if(priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
1948                memcpy(&wpa_suite.suite[0][0],CIPHER_ID_WPA2_WEP40,CIPHER_ID_LEN);
1949            else
1950                memcpy(&wpa_suite.suite[0][0],CIPHER_ID_WPA_WEP40,CIPHER_ID_LEN);
1951            break;
1952        case IW_AUTH_CIPHER_TKIP:
1953            if(priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
1954                memcpy(&wpa_suite.suite[0][0],CIPHER_ID_WPA2_TKIP,CIPHER_ID_LEN);
1955            else
1956                memcpy(&wpa_suite.suite[0][0],CIPHER_ID_WPA_TKIP,CIPHER_ID_LEN);
1957            break;
1958        case IW_AUTH_CIPHER_CCMP:
1959            if(priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
1960                memcpy(&wpa_suite.suite[0][0],CIPHER_ID_WPA2_CCMP,CIPHER_ID_LEN);
1961            else
1962                memcpy(&wpa_suite.suite[0][0],CIPHER_ID_WPA_CCMP,CIPHER_ID_LEN);
1963            break;
1964        case IW_AUTH_CIPHER_WEP104:
1965            if(priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
1966                memcpy(&wpa_suite.suite[0][0],CIPHER_ID_WPA2_WEP104,CIPHER_ID_LEN);
1967            else
1968                memcpy(&wpa_suite.suite[0][0],CIPHER_ID_WPA_WEP104,CIPHER_ID_LEN);
1969            break;
1970        }
1971
1972        hostif_mib_set_request(priv, DOT11_RSN_CONFIG_UNICAST_CIPHER,
1973                       sizeof(wpa_suite.size)+CIPHER_ID_LEN*wpa_suite.size,
1974                       MIB_VALUE_TYPE_OSTRING, &wpa_suite);
1975        break;
1976    case SME_RSN_MCAST_REQUEST:
1977        switch(priv->wpa.group_suite){
1978        case IW_AUTH_CIPHER_NONE:
1979            if(priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
1980                memcpy(&wpa_suite.suite[0][0],CIPHER_ID_WPA2_NONE,CIPHER_ID_LEN);
1981            else
1982                memcpy(&wpa_suite.suite[0][0],CIPHER_ID_WPA_NONE,CIPHER_ID_LEN);
1983            break;
1984        case IW_AUTH_CIPHER_WEP40:
1985            if(priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
1986                memcpy(&wpa_suite.suite[0][0],CIPHER_ID_WPA2_WEP40,CIPHER_ID_LEN);
1987            else
1988                memcpy(&wpa_suite.suite[0][0],CIPHER_ID_WPA_WEP40,CIPHER_ID_LEN);
1989            break;
1990        case IW_AUTH_CIPHER_TKIP:
1991            if(priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
1992                memcpy(&wpa_suite.suite[0][0],CIPHER_ID_WPA2_TKIP,CIPHER_ID_LEN);
1993            else
1994                memcpy(&wpa_suite.suite[0][0],CIPHER_ID_WPA_TKIP,CIPHER_ID_LEN);
1995            break;
1996        case IW_AUTH_CIPHER_CCMP:
1997            if(priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
1998                memcpy(&wpa_suite.suite[0][0],CIPHER_ID_WPA2_CCMP,CIPHER_ID_LEN);
1999            else
2000                memcpy(&wpa_suite.suite[0][0],CIPHER_ID_WPA_CCMP,CIPHER_ID_LEN);
2001            break;
2002        case IW_AUTH_CIPHER_WEP104:
2003            if(priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
2004                memcpy(&wpa_suite.suite[0][0],CIPHER_ID_WPA2_WEP104,CIPHER_ID_LEN);
2005            else
2006                memcpy(&wpa_suite.suite[0][0],CIPHER_ID_WPA_WEP104,CIPHER_ID_LEN);
2007            break;
2008        }
2009
2010        hostif_mib_set_request(priv, DOT11_RSN_CONFIG_MULTICAST_CIPHER,
2011                       CIPHER_ID_LEN, MIB_VALUE_TYPE_OSTRING,
2012                       &wpa_suite.suite[0][0] );
2013        break;
2014    case SME_RSN_AUTH_REQUEST:
2015        wpa_suite.size=cpu_to_le16((uint16_t)1);
2016        switch(priv->wpa.key_mgmt_suite){
2017        case IW_AUTH_KEY_MGMT_802_1X:
2018            if(priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
2019                memcpy(&wpa_suite.suite[0][0],KEY_MGMT_ID_WPA2_1X,KEY_MGMT_ID_LEN);
2020            else
2021                memcpy(&wpa_suite.suite[0][0],KEY_MGMT_ID_WPA_1X,KEY_MGMT_ID_LEN);
2022            break;
2023        case IW_AUTH_KEY_MGMT_PSK:
2024            if(priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
2025                memcpy(&wpa_suite.suite[0][0],KEY_MGMT_ID_WPA2_PSK,KEY_MGMT_ID_LEN);
2026            else
2027                memcpy(&wpa_suite.suite[0][0],KEY_MGMT_ID_WPA_PSK,KEY_MGMT_ID_LEN);
2028            break;
2029        case 0:
2030            if(priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
2031                memcpy(&wpa_suite.suite[0][0],KEY_MGMT_ID_WPA2_NONE,KEY_MGMT_ID_LEN);
2032            else
2033                memcpy(&wpa_suite.suite[0][0],KEY_MGMT_ID_WPA_NONE,KEY_MGMT_ID_LEN);
2034            break;
2035        case 4:
2036            if(priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
2037                memcpy(&wpa_suite.suite[0][0],KEY_MGMT_ID_WPA2_WPANONE,KEY_MGMT_ID_LEN);
2038            else
2039                memcpy(&wpa_suite.suite[0][0],KEY_MGMT_ID_WPA_WPANONE,KEY_MGMT_ID_LEN);
2040            break;
2041        }
2042
2043        hostif_mib_set_request(priv, DOT11_RSN_CONFIG_AUTH_SUITE,
2044                       sizeof(wpa_suite.size)+KEY_MGMT_ID_LEN*wpa_suite.size,
2045                       MIB_VALUE_TYPE_OSTRING, &wpa_suite);
2046        break;
2047    case SME_RSN_ENABLED_REQUEST:
2048        val = cpu_to_le32((uint32_t)(priv->wpa.rsn_enabled));
2049        hostif_mib_set_request(priv, DOT11_RSN_ENABLED,
2050                       sizeof(val), MIB_VALUE_TYPE_BOOL,
2051                       &val );
2052        break;
2053    case SME_RSN_MODE_REQUEST:
2054        if(priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2){
2055            rsn_mode.rsn_mode = cpu_to_le32((uint32_t)RSN_MODE_WPA2);
2056            rsn_mode.rsn_capability = cpu_to_le16((uint16_t)0);
2057        }
2058        else if(priv->wpa.version == IW_AUTH_WPA_VERSION_WPA){
2059            rsn_mode.rsn_mode = cpu_to_le32((uint32_t)RSN_MODE_WPA);
2060            rsn_mode.rsn_capability = cpu_to_le16((uint16_t)0);
2061        }
2062        else{
2063            rsn_mode.rsn_mode = cpu_to_le32((uint32_t)RSN_MODE_NONE);
2064            rsn_mode.rsn_capability = cpu_to_le16((uint16_t)0);
2065        }
2066        hostif_mib_set_request(priv, LOCAL_RSN_MODE,sizeof(rsn_mode),
2067                       MIB_VALUE_TYPE_OSTRING,&rsn_mode );
2068        break;
2069
2070    }
2071    return;
2072}
2073
2074static
2075void hostif_sme_mode_setup(ks_wlan_private *priv)
2076{
2077    unsigned char rate_size;
2078    unsigned char rate_octet[RATE_SET_MAX_SIZE];
2079    int i=0;
2080
2081    /* rate setting if rate segging is auto for changing phy_type (#94)*/
2082    if(priv->reg.tx_rate == TX_RATE_FULL_AUTO){
2083        if(priv->reg.phy_type == D_11B_ONLY_MODE){
2084            priv->reg.rate_set.body[3] = TX_RATE_11M;
2085            priv->reg.rate_set.body[2] = TX_RATE_5M;
2086            priv->reg.rate_set.body[1] = TX_RATE_2M|BASIC_RATE;
2087            priv->reg.rate_set.body[0] = TX_RATE_1M|BASIC_RATE;
2088            priv->reg.rate_set.size = 4;
2089        }else{ /* D_11G_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
2090            priv->reg.rate_set.body[11] = TX_RATE_54M;
2091            priv->reg.rate_set.body[10] = TX_RATE_48M;
2092            priv->reg.rate_set.body[9] = TX_RATE_36M;
2093            priv->reg.rate_set.body[8] = TX_RATE_18M;
2094            priv->reg.rate_set.body[7] = TX_RATE_9M;
2095            priv->reg.rate_set.body[6] = TX_RATE_24M|BASIC_RATE;
2096            priv->reg.rate_set.body[5] = TX_RATE_12M|BASIC_RATE;
2097            priv->reg.rate_set.body[4] = TX_RATE_6M|BASIC_RATE;
2098            priv->reg.rate_set.body[3] = TX_RATE_11M|BASIC_RATE;
2099            priv->reg.rate_set.body[2] = TX_RATE_5M|BASIC_RATE;
2100            priv->reg.rate_set.body[1] = TX_RATE_2M|BASIC_RATE;
2101            priv->reg.rate_set.body[0] = TX_RATE_1M|BASIC_RATE;
2102            priv->reg.rate_set.size = 12;
2103        }
2104    }
2105
2106    /* rate mask by phy setting */
2107    if(priv->reg.phy_type == D_11B_ONLY_MODE){
2108        for(i=0;i<priv->reg.rate_set.size;i++){
2109            if(IS_11B_RATE(priv->reg.rate_set.body[i])){
2110                if((priv->reg.rate_set.body[i] & RATE_MASK) >= TX_RATE_5M)
2111                    rate_octet[i] = priv->reg.rate_set.body[i] & RATE_MASK ;
2112                else
2113                    rate_octet[i] = priv->reg.rate_set.body[i];
2114            }
2115            else
2116                break;
2117        }
2118
2119    }else{ /* D_11G_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
2120        for(i=0;i<priv->reg.rate_set.size;i++){
2121            if(IS_11BG_RATE(priv->reg.rate_set.body[i])){
2122                if(IS_OFDM_EXT_RATE(priv->reg.rate_set.body[i]))
2123                    rate_octet[i] = priv->reg.rate_set.body[i] & RATE_MASK ;
2124                else
2125                    rate_octet[i] = priv->reg.rate_set.body[i];
2126            }
2127            else
2128                break;
2129        }
2130    }
2131    rate_size = i;
2132    if(rate_size==0){
2133        if(priv->reg.phy_type == D_11G_ONLY_MODE)
2134            rate_octet[0]=TX_RATE_6M | BASIC_RATE;
2135        else
2136            rate_octet[0]=TX_RATE_2M | BASIC_RATE;
2137        rate_size = 1;
2138    }
2139
2140    /* rate set update */
2141    priv->reg.rate_set.size = rate_size;
2142    memcpy(&priv->reg.rate_set.body[0], &rate_octet[0], rate_size);
2143
2144    switch ( priv->reg.operation_mode ) {
2145    case MODE_PSEUDO_ADHOC:
2146        /* Pseudo Ad-Hoc mode */
2147        hostif_ps_adhoc_set_request(priv);
2148        break;
2149    case MODE_INFRASTRUCTURE:
2150        /* Infrastructure mode */
2151        if (!is_valid_ether_addr((u8 *)priv->reg.bssid)) {
2152            hostif_infrastructure_set_request(priv);
2153        }
2154        else {
2155            hostif_infrastructure_set2_request(priv);
2156            DPRINTK(2, "Infra bssid = %02x:%02x:%02x:%02x:%02x:%02x\n",
2157                   priv->reg.bssid[0],priv->reg.bssid[1],priv->reg.bssid[2],
2158                   priv->reg.bssid[3],priv->reg.bssid[4],priv->reg.bssid[5]);
2159        }
2160        break;
2161    case MODE_ADHOC:
2162        /* IEEE802.11 Ad-Hoc mode */
2163        if (!is_valid_ether_addr((u8 *)priv->reg.bssid)) {
2164            hostif_adhoc_set_request(priv);
2165        }
2166        else {
2167            hostif_adhoc_set2_request(priv);
2168            DPRINTK(2, "Adhoc bssid = %02x:%02x:%02x:%02x:%02x:%02x\n",
2169                   priv->reg.bssid[0],priv->reg.bssid[1],priv->reg.bssid[2],
2170                   priv->reg.bssid[3],priv->reg.bssid[4],priv->reg.bssid[5]);
2171        }
2172        break;
2173    default:
2174        break;
2175    }
2176
2177    return ;
2178}
2179
2180static
2181void hostif_sme_multicast_set(ks_wlan_private *priv)
2182{
2183
2184        struct net_device *dev = priv->net_dev;
2185    int mc_count;
2186    struct dev_mc_list *mclist;
2187    char set_address[NIC_MAX_MCAST_LIST*ETH_ALEN];
2188    unsigned long filter_type;
2189    int i;
2190
2191    DPRINTK(3,"\n");
2192
2193    spin_lock(&priv->multicast_spin);
2194
2195    memset(set_address, 0, NIC_MAX_MCAST_LIST*ETH_ALEN);
2196
2197    if (dev->flags & IFF_PROMISC ){
2198        filter_type = cpu_to_le32((uint32_t)MCAST_FILTER_PROMISC);
2199        hostif_mib_set_request(priv, LOCAL_MULTICAST_FILTER, sizeof(filter_type),
2200                       MIB_VALUE_TYPE_BOOL, &filter_type);
2201    }
2202    else if ((dev->mc_count > NIC_MAX_MCAST_LIST) || (dev->flags & IFF_ALLMULTI)){
2203        filter_type = cpu_to_le32((uint32_t)MCAST_FILTER_MCASTALL);
2204        hostif_mib_set_request(priv, LOCAL_MULTICAST_FILTER, sizeof(filter_type),
2205                       MIB_VALUE_TYPE_BOOL, &filter_type);
2206    }
2207    else {
2208        if (priv->sme_i.sme_flag & SME_MULTICAST){
2209            mc_count = dev->mc_count;
2210            for (i = 0, mclist = dev->mc_list; mclist && i < mc_count; i++, mclist = mclist->next)
2211                memcpy(&set_address[i*ETH_ALEN], mclist->dmi_addr, ETH_ALEN);
2212            priv->sme_i.sme_flag &= ~SME_MULTICAST;
2213            hostif_mib_set_request(priv, LOCAL_MULTICAST_ADDRESS,
2214                           (ETH_ALEN*mc_count), MIB_VALUE_TYPE_OSTRING, &set_address[0]);
2215        }else {
2216            filter_type = cpu_to_le32((uint32_t)MCAST_FILTER_MCAST);
2217            priv->sme_i.sme_flag |= SME_MULTICAST;
2218            hostif_mib_set_request(priv, LOCAL_MULTICAST_FILTER, sizeof(filter_type),
2219                           MIB_VALUE_TYPE_BOOL, &filter_type);
2220        }
2221    }
2222
2223    spin_unlock(&priv->multicast_spin);
2224
2225}
2226
2227static
2228void hostif_sme_powermgt_set(ks_wlan_private *priv)
2229{
2230    unsigned long mode,wake_up,receiveDTIMs ;
2231
2232    DPRINTK(3,"\n");
2233    switch(priv->reg.powermgt){
2234    case POWMGT_ACTIVE_MODE:
2235        mode = POWER_ACTIVE;
2236        wake_up = 0;
2237        receiveDTIMs = 0;
2238        break;
2239    case POWMGT_SAVE1_MODE:
2240        if(priv->reg.operation_mode == MODE_INFRASTRUCTURE){
2241            mode = POWER_SAVE;
2242            wake_up = 0;
2243            receiveDTIMs = 0;
2244        } else {
2245            mode = POWER_ACTIVE;
2246            wake_up = 0;
2247            receiveDTIMs = 0;
2248        }
2249        break;
2250    case POWMGT_SAVE2_MODE:
2251        if(priv->reg.operation_mode == MODE_INFRASTRUCTURE){
2252            mode = POWER_SAVE;
2253            wake_up = 0;
2254            receiveDTIMs = 1;
2255        } else {
2256            mode = POWER_ACTIVE;
2257            wake_up = 0;
2258            receiveDTIMs = 0;
2259        }
2260        break;
2261    default:
2262        mode = POWER_ACTIVE;
2263        wake_up = 0;
2264        receiveDTIMs = 0;
2265        break;
2266    }
2267    hostif_power_mngmt_request(priv, mode, wake_up, receiveDTIMs);
2268
2269    return;
2270}
2271
2272static
2273void hostif_sme_sleep_set(ks_wlan_private *priv)
2274{
2275    DPRINTK(3,"\n");
2276    switch(priv->sleep_mode){
2277    case SLP_SLEEP:
2278        hostif_sleep_request(priv, priv->sleep_mode);
2279        break;
2280    case SLP_ACTIVE:
2281        hostif_sleep_request(priv, priv->sleep_mode);
2282        break;
2283    default:
2284        break;
2285    }
2286
2287    return;
2288}
2289
2290static
2291void hostif_sme_set_key(ks_wlan_private *priv, int type)
2292{
2293    uint32_t val;
2294    switch(type){
2295    case SME_SET_FLAG:
2296        val = cpu_to_le32((uint32_t)(priv->reg.privacy_invoked));
2297        hostif_mib_set_request(priv, DOT11_PRIVACY_INVOKED,
2298                       sizeof(val), MIB_VALUE_TYPE_BOOL,
2299                       &val );
2300        break;
2301    case SME_SET_TXKEY:
2302        val = cpu_to_le32((uint32_t)(priv->wpa.txkey));
2303        hostif_mib_set_request(priv, DOT11_WEP_DEFAULT_KEY_ID,
2304                       sizeof(val), MIB_VALUE_TYPE_INT,
2305                       &val );
2306        break;
2307    case SME_SET_KEY1:
2308        hostif_mib_set_request(priv, DOT11_WEP_DEFAULT_KEY_VALUE1,
2309                       priv->wpa.key[0].key_len, MIB_VALUE_TYPE_OSTRING,
2310                       &priv->wpa.key[0].key_val[0] );
2311        break;
2312    case SME_SET_KEY2:
2313        hostif_mib_set_request(priv, DOT11_WEP_DEFAULT_KEY_VALUE2,
2314                       priv->wpa.key[1].key_len, MIB_VALUE_TYPE_OSTRING,
2315                       &priv->wpa.key[1].key_val[0] );
2316        break;
2317    case SME_SET_KEY3:
2318        hostif_mib_set_request(priv, DOT11_WEP_DEFAULT_KEY_VALUE3,
2319                       priv->wpa.key[2].key_len, MIB_VALUE_TYPE_OSTRING,
2320                       &priv->wpa.key[2].key_val[0] );
2321        break;
2322    case SME_SET_KEY4:
2323        hostif_mib_set_request(priv, DOT11_WEP_DEFAULT_KEY_VALUE4,
2324                       priv->wpa.key[3].key_len, MIB_VALUE_TYPE_OSTRING,
2325                       &priv->wpa.key[3].key_val[0] );
2326        break;
2327    case SME_SET_PMK_TSC:
2328        hostif_mib_set_request(priv, DOT11_PMK_TSC,
2329                       WPA_RX_SEQ_LEN, MIB_VALUE_TYPE_OSTRING,
2330                       &priv->wpa.key[0].rx_seq[0] );
2331        break;
2332    case SME_SET_GMK1_TSC:
2333        hostif_mib_set_request(priv, DOT11_GMK1_TSC,
2334                       WPA_RX_SEQ_LEN, MIB_VALUE_TYPE_OSTRING,
2335                       &priv->wpa.key[1].rx_seq[0] );
2336        break;
2337    case SME_SET_GMK2_TSC:
2338        hostif_mib_set_request(priv, DOT11_GMK2_TSC,
2339                       WPA_RX_SEQ_LEN, MIB_VALUE_TYPE_OSTRING,
2340                       &priv->wpa.key[2].rx_seq[0] );
2341        break;
2342    }
2343    return;
2344}
2345
2346static
2347void hostif_sme_set_pmksa(ks_wlan_private *priv)
2348{
2349    struct pmk_cache_t {
2350        uint16_t size;
2351        struct {
2352            uint8_t bssid[ETH_ALEN];
2353            uint8_t pmkid[IW_PMKID_LEN];
2354        } __attribute__((packed)) list[PMK_LIST_MAX];
2355    } __attribute__((packed)) pmkcache;
2356    struct pmk_t *pmk;
2357    struct list_head *ptr;
2358    int i;
2359
2360    DPRINTK(4,"pmklist.size=%d\n",priv->pmklist.size);
2361    i=0;
2362    list_for_each(ptr, &priv->pmklist.head){
2363        pmk = list_entry(ptr, struct pmk_t, list);
2364        if(i<PMK_LIST_MAX){
2365            memcpy(pmkcache.list[i].bssid, pmk->bssid, ETH_ALEN);
2366            memcpy(pmkcache.list[i].pmkid, pmk->pmkid, IW_PMKID_LEN);
2367            i++;
2368        }
2369    }
2370    pmkcache.size = cpu_to_le16((uint16_t)(priv->pmklist.size));
2371    hostif_mib_set_request(priv, LOCAL_PMK,
2372                   sizeof(priv->pmklist.size)+(ETH_ALEN+IW_PMKID_LEN)*(priv->pmklist.size),
2373                   MIB_VALUE_TYPE_OSTRING,&pmkcache );
2374}
2375
2376/* execute sme */
2377static
2378void hostif_sme_execute(ks_wlan_private *priv, int event)
2379{
2380    uint32_t val;
2381
2382    DPRINTK(3,"event=%d\n",event);
2383    switch (event) {
2384    case SME_START:
2385        if ( priv->dev_state == DEVICE_STATE_BOOT ){
2386            hostif_mib_get_request(priv, DOT11_MAC_ADDRESS);
2387        }
2388        break;
2389    case SME_MULTICAST_REQUEST:
2390        hostif_sme_multicast_set(priv);
2391        break;
2392    case SME_MACADDRESS_SET_REQUEST:
2393        hostif_mib_set_request(priv, LOCAL_CURRENTADDRESS, ETH_ALEN,
2394                       MIB_VALUE_TYPE_OSTRING, &priv->eth_addr[0]);
2395        break;
2396    case SME_BSS_SCAN_REQUEST:
2397        hostif_bss_scan_request(priv, priv->reg.scan_type, priv->scan_ssid, priv->scan_ssid_len);
2398        break;
2399    case SME_POW_MNGMT_REQUEST:
2400        hostif_sme_powermgt_set(priv);
2401        break;
2402    case SME_PHY_INFO_REQUEST:
2403        hostif_phy_information_request(priv);
2404        break;
2405    case SME_MIC_FAILURE_REQUEST:
2406        if(priv->wpa.mic_failure.failure == 1){
2407            hostif_mic_failure_request(priv, priv->wpa.mic_failure.failure-1, 0);
2408        }else if(priv->wpa.mic_failure.failure == 2){
2409            hostif_mic_failure_request(priv, priv->wpa.mic_failure.failure-1,
2410                           priv->wpa.mic_failure.counter);
2411        }else
2412            DPRINTK(4,"SME_MIC_FAILURE_REQUEST: failure count=%u error?\n",
2413                priv->wpa.mic_failure.failure);
2414        break;
2415    case SME_MIC_FAILURE_CONFIRM:
2416        if(priv->wpa.mic_failure.failure == 2){
2417            if(priv->wpa.mic_failure.stop)
2418                priv->wpa.mic_failure.stop = 0;
2419            priv->wpa.mic_failure.failure = 0;
2420            hostif_start_request( priv, priv->reg.operation_mode );
2421        }
2422        break;
2423    case SME_GET_MAC_ADDRESS:
2424        if ( priv->dev_state == DEVICE_STATE_BOOT ){
2425            hostif_mib_get_request(priv, DOT11_PRODUCT_VERSION);
2426        }
2427        break;
2428    case SME_GET_PRODUCT_VERSION:
2429        if ( priv->dev_state == DEVICE_STATE_BOOT ){
2430            priv->dev_state = DEVICE_STATE_PREINIT;
2431        }
2432        break;
2433    case SME_STOP_REQUEST:
2434        hostif_stop_request(priv);
2435        break;
2436    case SME_RTS_THRESHOLD_REQUEST:
2437        val = cpu_to_le32((uint32_t)(priv->reg.rts));
2438        hostif_mib_set_request(priv, DOT11_RTS_THRESHOLD,
2439                       sizeof(val), MIB_VALUE_TYPE_INT,
2440                       &val );
2441        break;
2442    case SME_FRAGMENTATION_THRESHOLD_REQUEST:
2443        val = cpu_to_le32((uint32_t)(priv->reg.fragment));
2444        hostif_mib_set_request(priv, DOT11_FRAGMENTATION_THRESHOLD,
2445                       sizeof(val), MIB_VALUE_TYPE_INT,
2446                       &val );
2447        break;
2448    case SME_WEP_INDEX_REQUEST: case SME_WEP_KEY1_REQUEST:
2449    case SME_WEP_KEY2_REQUEST: case SME_WEP_KEY3_REQUEST:
2450    case SME_WEP_KEY4_REQUEST: case SME_WEP_FLAG_REQUEST:
2451        hostif_sme_set_wep(priv,event);
2452        break;
2453    case SME_RSN_UCAST_REQUEST: case SME_RSN_MCAST_REQUEST:
2454    case SME_RSN_AUTH_REQUEST: case SME_RSN_ENABLED_REQUEST:
2455    case SME_RSN_MODE_REQUEST:
2456        hostif_sme_set_rsn(priv,event);
2457        break;
2458    case SME_SET_FLAG: case SME_SET_TXKEY:
2459    case SME_SET_KEY1: case SME_SET_KEY2:
2460    case SME_SET_KEY3: case SME_SET_KEY4:
2461    case SME_SET_PMK_TSC: case SME_SET_GMK1_TSC:
2462    case SME_SET_GMK2_TSC:
2463        hostif_sme_set_key(priv,event);
2464        break;
2465    case SME_SET_PMKSA:
2466        hostif_sme_set_pmksa(priv);
2467        break;
2468#ifdef WPS
2469    case SME_WPS_ENABLE_REQUEST:
2470        hostif_mib_set_request(priv, LOCAL_WPS_ENABLE,
2471                       sizeof(priv->wps.wps_enabled),
2472                       MIB_VALUE_TYPE_INT, &priv->wps.wps_enabled );
2473        break;
2474    case SME_WPS_PROBE_REQUEST:
2475        hostif_mib_set_request(priv, LOCAL_WPS_PROBE_REQ,
2476                       priv->wps.ielen,
2477                       MIB_VALUE_TYPE_OSTRING, priv->wps.ie);
2478        break;
2479#endif /* WPS */
2480    case SME_MODE_SET_REQUEST:
2481        hostif_sme_mode_setup(priv);
2482        break;
2483    case SME_SET_GAIN:
2484        hostif_mib_set_request(priv, LOCAL_GAIN,
2485                       sizeof(priv->gain), MIB_VALUE_TYPE_OSTRING,
2486                       &priv->gain);
2487        break;
2488    case SME_GET_GAIN:
2489        hostif_mib_get_request(priv, LOCAL_GAIN);
2490        break;
2491    case SME_GET_EEPROM_CKSUM:
2492        priv->eeprom_checksum = EEPROM_FW_NOT_SUPPORT; /* initialize */
2493        hostif_mib_get_request(priv, LOCAL_EEPROM_SUM);
2494        break;
2495    case SME_START_REQUEST:
2496        hostif_start_request( priv, priv->reg.operation_mode );
2497        break;
2498    case SME_START_CONFIRM:
2499        /* for power save */
2500        atomic_set(&priv->psstatus.snooze_guard, 0);
2501        atomic_set(&priv->psstatus.confirm_wait,0);
2502#if !defined(_SDIO_)
2503        atomic_set(&priv->psstatus.status, PS_NONE);
2504#endif
2505        if ( priv->dev_state == DEVICE_STATE_PREINIT ){
2506            priv->dev_state = DEVICE_STATE_INIT;
2507        }
2508        /* wake_up_interruptible_all(&priv->confirm_wait); */
2509        complete(&priv->confirm_wait);
2510        break;
2511    case SME_SLEEP_REQUEST:
2512        hostif_sme_sleep_set(priv);
2513        break;
2514    case SME_SET_REGION:
2515        val = cpu_to_le32((uint32_t)(priv->region));
2516        hostif_mib_set_request(priv, LOCAL_REGION,
2517                       sizeof(val), MIB_VALUE_TYPE_INT,
2518                       &val );
2519        break;
2520    case SME_MULTICAST_CONFIRM:
2521    case SME_BSS_SCAN_CONFIRM:
2522    case SME_POW_MNGMT_CONFIRM:
2523    case SME_PHY_INFO_CONFIRM:
2524    case SME_STOP_CONFIRM:
2525    case SME_RTS_THRESHOLD_CONFIRM:
2526    case SME_FRAGMENTATION_THRESHOLD_CONFIRM:
2527    case SME_WEP_INDEX_CONFIRM: case SME_WEP_KEY1_CONFIRM:
2528    case SME_WEP_KEY2_CONFIRM: case SME_WEP_KEY3_CONFIRM:
2529    case SME_WEP_KEY4_CONFIRM: case SME_WEP_FLAG_CONFIRM:
2530    case SME_RSN_UCAST_CONFIRM: case SME_RSN_MCAST_CONFIRM:
2531    case SME_RSN_AUTH_CONFIRM: case SME_RSN_ENABLED_CONFIRM:
2532    case SME_RSN_MODE_CONFIRM:
2533    case SME_MODE_SET_CONFIRM:
2534        break;
2535    case SME_TERMINATE:
2536    default:
2537        break;
2538    }
2539}
2540
2541static
2542void hostif_sme_task( unsigned long dev )
2543{
2544    ks_wlan_private *priv = (ks_wlan_private *)dev;
2545
2546    DPRINTK(3,"\n");
2547
2548    if(priv->dev_state >= DEVICE_STATE_BOOT){
2549        if (0 < cnt_smeqbody(priv) && priv->dev_state >= DEVICE_STATE_BOOT) {
2550            hostif_sme_execute(priv, priv->sme_i.event_buff[priv->sme_i.qhead]);
2551            inc_smeqhead(priv);
2552            if (0 < cnt_smeqbody(priv))
2553                    tasklet_schedule(&priv->sme_task);
2554        }
2555    }
2556    return;
2557}
2558
2559/* send to Station Management Entity module */
2560void hostif_sme_enqueue(ks_wlan_private *priv, unsigned short event)
2561{
2562    DPRINTK(3,"\n");
2563
2564#if !defined(_SDIO_)
2565    if(atomic_read(&priv->psstatus.status)==PS_SNOOZE && event < SME_START_CONFIRM){ /* power save wakeup*/
2566        schedule_work(&priv->ks_wlan_wakeup_task);
2567        if(atomic_read(&priv->sme_task.count) <= 0){
2568            /* schedule_work(&priv->ks_wlan_wakeup_task); */
2569            DPRINTK(4,"sme task disable.\n");
2570            tasklet_disable(&priv->sme_task);
2571        }
2572    }
2573#endif
2574
2575
2576    /* enqueue sme event */
2577    if (cnt_smeqbody(priv) < (SME_EVENT_BUFF_SIZE - 1)) {
2578        priv->sme_i.event_buff[priv->sme_i.qtail] = event;
2579        inc_smeqtail(priv);
2580        //DPRINTK(3,"inc_smeqtail \n");
2581#ifdef KS_WLAN_DEBUG
2582        if (priv->sme_i.max_event_count < cnt_smeqbody(priv))
2583            priv->sme_i.max_event_count = cnt_smeqbody(priv);
2584#endif /* KS_WLAN_DEBUG */
2585    } else {
2586        /* in case of buffer overflow */
2587        //DPRINTK(2,"sme queue buffer overflow\n");
2588        printk("sme queue buffer overflow\n");
2589    }
2590
2591    tasklet_schedule(&priv->sme_task);
2592
2593}
2594
2595int hostif_init( ks_wlan_private *priv )
2596{
2597    int rc=0;
2598    int i;
2599
2600    DPRINTK(3,"\n");
2601
2602    priv->aplist.size =0;
2603    for(i=0;i<LOCAL_APLIST_MAX;i++)
2604        memset(&(priv->aplist.ap[i]),0,sizeof(struct local_ap_t));
2605    priv->infra_status = 0;
2606    priv->current_rate = 4;
2607    priv->connect_status = DISCONNECT_STATUS;
2608
2609    spin_lock_init(&priv->multicast_spin);
2610
2611    spin_lock_init(&priv->dev_read_lock);
2612    init_waitqueue_head (&priv->devread_wait);
2613    priv->dev_count = 0;
2614    atomic_set(&priv->event_count, 0);
2615    atomic_set(&priv->rec_count, 0);
2616
2617    /* for power save */
2618    atomic_set(&priv->psstatus.status, PS_NONE);
2619    atomic_set(&priv->psstatus.confirm_wait, 0);
2620    atomic_set(&priv->psstatus.snooze_guard, 0);
2621    /* init_waitqueue_head(&priv->psstatus.wakeup_wait); */
2622    init_completion(&priv->psstatus.wakeup_wait);
2623    //INIT_WORK(&priv->ks_wlan_wakeup_task, ks_wlan_hw_wakeup_task, (void *)priv);
2624    INIT_WORK(&priv->ks_wlan_wakeup_task, ks_wlan_hw_wakeup_task);
2625
2626    /* WPA */
2627    memset(&(priv->wpa), 0, sizeof(priv->wpa));
2628    priv->wpa.rsn_enabled = 0;
2629    priv->wpa.mic_failure.failure = 0;
2630    priv->wpa.mic_failure.last_failure_time = 0;
2631    priv->wpa.mic_failure.stop = 0;
2632    memset(&(priv->pmklist), 0, sizeof(priv->pmklist));
2633    INIT_LIST_HEAD(&priv->pmklist.head);
2634    for(i=0;i<PMK_LIST_MAX;i++)
2635        INIT_LIST_HEAD(&priv->pmklist.pmk[i].list);
2636
2637    priv->sme_i.sme_status = SME_IDLE;
2638    priv->sme_i.qhead = priv->sme_i.qtail = 0;
2639#ifdef KS_WLAN_DEBUG
2640    priv->sme_i.max_event_count = 0;
2641#endif
2642        spin_lock_init(&priv->sme_i.sme_spin);
2643    priv->sme_i.sme_flag = 0;
2644
2645    tasklet_init(&priv->sme_task, hostif_sme_task, (unsigned long)priv);
2646
2647    return rc;
2648}
2649
2650void hostif_exit( ks_wlan_private *priv )
2651{
2652    tasklet_kill(&priv->sme_task);
2653    return;
2654}
2655
package/ks7010/src/ks_hostif.h
1/*
2 * Driver for KeyStream wireless LAN
3 *
4 * ks_hostif.h
5 * $Id: ks_hostif.h 994 2009-09-14 01:51:16Z 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#ifndef _KS_HOSTIF_H_
16#define _KS_HOSTIF_H_
17/*
18 * HOST-MAC I/F events
19 */
20#define HIF_DATA_REQ 0xE001
21#define HIF_DATA_IND 0xE801
22#define HIF_MIB_GET_REQ 0xE002
23#define HIF_MIB_GET_CONF 0xE802
24#define HIF_MIB_SET_REQ 0xE003
25#define HIF_MIB_SET_CONF 0xE803
26#define HIF_POWERMGT_REQ 0xE004
27#define HIF_POWERMGT_CONF 0xE804
28#define HIF_START_REQ 0xE005
29#define HIF_START_CONF 0xE805
30#define HIF_CONNECT_IND 0xE806
31#define HIF_STOP_REQ 0xE006
32#define HIF_STOP_CONF 0xE807
33#define HIF_PS_ADH_SET_REQ 0xE007
34#define HIF_PS_ADH_SET_CONF 0xE808
35#define HIF_INFRA_SET_REQ 0xE008
36#define HIF_INFRA_SET_CONF 0xE809
37#define HIF_ADH_SET_REQ 0xE009
38#define HIF_ADH_SET_CONF 0xE80A
39#define HIF_AP_SET_REQ 0xE00A
40#define HIF_AP_SET_CONF 0xE80B
41#define HIF_ASSOC_INFO_IND 0xE80C
42#define HIF_MIC_FAILURE_REQ 0xE00B
43#define HIF_MIC_FAILURE_CONF 0xE80D
44#define HIF_SCAN_REQ 0xE00C
45#define HIF_SCAN_CONF 0xE80E
46#define HIF_PHY_INFO_REQ 0xE00D
47#define HIF_PHY_INFO_CONF 0xE80F
48#define HIF_SLEEP_REQ 0xE00E
49#define HIF_SLEEP_CONF 0xE810
50#define HIF_PHY_INFO_IND 0xE811
51#define HIF_SCAN_IND 0xE812
52#define HIF_INFRA_SET2_REQ 0xE00F
53#define HIF_INFRA_SET2_CONF 0xE813
54#define HIF_ADH_SET2_REQ 0xE010
55#define HIF_ADH_SET2_CONF 0xE814
56
57#define HIF_REQ_MAX 0xE010
58
59/*
60 * HOST-MAC I/F data structure
61 * Byte alignmet Little Endian
62 */
63
64struct hostif_hdr {
65    uint16_t size;
66    uint16_t event;
67} __attribute__((packed));
68
69struct hostif_data_request_t {
70    struct hostif_hdr header;
71    uint16_t auth_type;
72#define TYPE_DATA 0x0000
73#define TYPE_AUTH 0x0001
74    uint16_t reserved;
75    uint8_t data[0];
76} __attribute__((packed));
77
78struct hostif_data_indication_t {
79    struct hostif_hdr header;
80    uint16_t auth_type;
81/* #define TYPE_DATA 0x0000 */
82#define TYPE_PMK1 0x0001
83#define TYPE_GMK1 0x0002
84#define TYPE_GMK2 0x0003
85    uint16_t reserved;
86    uint8_t data[0];
87} __attribute__((packed));
88
89#define CHANNEL_LIST_MAX_SIZE 14
90struct channel_list_t {
91    uint8_t size;
92    uint8_t body[CHANNEL_LIST_MAX_SIZE];
93    uint8_t pad;
94} __attribute__((packed));
95
96/* MIB Attribute */
97#define DOT11_MAC_ADDRESS 0x21010100 /* MAC Address (R) */
98#define DOT11_PRODUCT_VERSION 0x31024100 /* FirmWare Version (R)*/
99#define DOT11_RTS_THRESHOLD 0x21020100 /* RTS Threshold (R/W) */
100#define DOT11_FRAGMENTATION_THRESHOLD 0x21050100 /* Fragment Threshold (R/W) */
101#define DOT11_PRIVACY_INVOKED 0x15010100 /* WEP ON/OFF (W) */
102#define DOT11_WEP_DEFAULT_KEY_ID 0x15020100 /* WEP Index (W) */
103#define DOT11_WEP_DEFAULT_KEY_VALUE1 0x13020101 /* WEP Key#1(TKIP AES: PairwiseTemporalKey) (W) */
104#define DOT11_WEP_DEFAULT_KEY_VALUE2 0x13020102 /* WEP Key#2(TKIP AES: GroupKey1) (W) */
105#define DOT11_WEP_DEFAULT_KEY_VALUE3 0x13020103 /* WEP Key#3(TKIP AES: GroupKey2) (W) */
106#define DOT11_WEP_DEFAULT_KEY_VALUE4 0x13020104 /* WEP Key#4 (W) */
107#define DOT11_WEP_LIST 0x13020100 /* WEP LIST */
108#define DOT11_DESIRED_SSID 0x11090100 /* SSID */
109#define DOT11_CURRENT_CHANNEL 0x45010100 /* channel set */
110#define DOT11_OPERATION_RATE_SET 0x11110100 /* rate set */
111
112#define LOCAL_AP_SEARCH_INTEAVAL 0xF1010100 /* AP search interval (R/W) */
113#define LOCAL_CURRENTADDRESS 0xF1050100 /* MAC Adress change (W) */
114#define LOCAL_MULTICAST_ADDRESS 0xF1060100 /* Multicast Adress (W) */
115#define LOCAL_MULTICAST_FILTER 0xF1060200 /* Multicast Adress Filter enable/disable (W) */
116#define LOCAL_SEARCHED_AP_LIST 0xF1030100 /* AP list (R) */
117#define LOCAL_LINK_AP_STATUS 0xF1040100 /* Link AP status (R) */
118#define LOCAL_PACKET_STATISTICS 0xF1020100 /* tx,rx packets statistics */
119#define LOCAL_AP_SCAN_LIST_TYPE_SET 0xF1030200 /* AP_SCAN_LIST_TYPE */
120
121#define DOT11_RSN_ENABLED 0x15070100 /* WPA enable/disable (W) */
122#define LOCAL_RSN_MODE 0x56010100 /* RSN mode WPA/WPA2 (W) */
123#define DOT11_RSN_CONFIG_MULTICAST_CIPHER 0x51040100 /* GroupKeyCipherSuite (W) */
124#define DOT11_RSN_CONFIG_UNICAST_CIPHER 0x52020100 /* PairwiseKeyCipherSuite (W) */
125#define DOT11_RSN_CONFIG_AUTH_SUITE 0x53020100 /* AuthenticationKeyManagementSuite (W) */
126#define DOT11_RSN_CONFIG_VERSION 0x51020100 /* RSN version (W) */
127#define LOCAL_RSN_CONFIG_ALL 0x5F010100 /* RSN CONFIG ALL (W) */
128#define DOT11_PMK_TSC 0x55010100 /* PMK_TSC (W) */
129#define DOT11_GMK1_TSC 0x55010101 /* GMK1_TSC (W) */
130#define DOT11_GMK2_TSC 0x55010102 /* GMK2_TSC (W) */
131#define DOT11_GMK3_TSC 0x55010103 /* GMK3_TSC */
132#define LOCAL_PMK 0x58010100 /* Pairwise Master Key cache (W) */
133
134#define LOCAL_REGION 0xF10A0100 /* Region setting */
135
136#ifdef WPS
137#define LOCAL_WPS_ENABLE 0xF10B0100 /* WiFi Protected Setup */
138#define LOCAL_WPS_PROBE_REQ 0xF10C0100 /* WPS Probe Request */
139#endif /* WPS */
140
141#define LOCAL_GAIN 0xF10D0100 /* Carrer sense threshold for demo ato show */
142#define LOCAL_EEPROM_SUM 0xF10E0100 /* EEPROM checksum information */
143
144struct hostif_mib_get_request_t {
145    struct hostif_hdr header;
146    uint32_t mib_attribute;
147} __attribute__((packed));
148
149
150struct hostif_mib_value_t {
151    uint16_t size;
152    uint16_t type;
153#define MIB_VALUE_TYPE_NULL 0
154#define MIB_VALUE_TYPE_INT 1
155#define MIB_VALUE_TYPE_BOOL 2
156#define MIB_VALUE_TYPE_COUNT32 3
157#define MIB_VALUE_TYPE_OSTRING 4
158    uint8_t body[0];
159} __attribute__((packed));
160
161struct hostif_mib_get_confirm_t {
162    struct hostif_hdr header;
163    uint32_t mib_status;
164#define MIB_SUCCESS 0
165#define MIB_INVALID 1
166#define MIB_READ_ONLY 2
167#define MIB_WRITE_ONLY 3
168    uint32_t mib_attribute;
169    struct hostif_mib_value_t mib_value;
170} __attribute__((packed));
171
172struct hostif_mib_set_request_t {
173    struct hostif_hdr header;
174    uint32_t mib_attribute;
175    struct hostif_mib_value_t mib_value;
176} __attribute__((packed));
177
178struct hostif_mib_set_confirm_t {
179    struct hostif_hdr header;
180    uint32_t mib_status;
181    uint32_t mib_attribute;
182} __attribute__((packed));
183
184struct hostif_power_mngmt_request_t {
185    struct hostif_hdr header;
186    uint32_t mode;
187#define POWER_ACTIVE 1
188#define POWER_SAVE 2
189    uint32_t wake_up;
190#define SLEEP_FALSE 0
191#define SLEEP_TRUE 1 /* not used */
192    uint32_t receiveDTIMs;
193#define DTIM_FALSE 0
194#define DTIM_TRUE 1
195} __attribute__((packed));
196
197/* power management mode */
198enum {
199    POWMGT_ACTIVE_MODE=0,
200    POWMGT_SAVE1_MODE,
201    POWMGT_SAVE2_MODE
202};
203
204#define RESULT_SUCCESS 0
205#define RESULT_INVALID_PARAMETERS 1
206#define RESULT_NOT_SUPPORTED 2
207/* #define RESULT_ALREADY_RUNNING 3 */
208#define RESULT_ALREADY_RUNNING 7
209
210struct hostif_power_mngmt_confirm_t {
211    struct hostif_hdr header;
212    uint16_t result_code;
213} __attribute__((packed));
214
215struct hostif_start_request_t {
216    struct hostif_hdr header;
217    uint16_t mode;
218#define MODE_PSEUDO_ADHOC 0
219#define MODE_INFRASTRUCTURE 1
220#define MODE_AP 2 /* not used */
221#define MODE_ADHOC 3
222} __attribute__((packed));
223
224struct hostif_start_confirm_t {
225    struct hostif_hdr header;
226    uint16_t result_code;
227} __attribute__((packed));
228
229#define SSID_MAX_SIZE 32
230struct ssid_t {
231    uint8_t size;
232    uint8_t body[SSID_MAX_SIZE];
233    uint8_t ssid_pad;
234} __attribute__((packed));
235
236#define RATE_SET_MAX_SIZE 16
237struct rate_set8_t {
238    uint8_t size;
239    uint8_t body[8];
240    uint8_t rate_pad;
241} __attribute__((packed));
242
243struct FhParms_t {
244    uint16_t dwellTime;
245    uint8_t hopSet;
246    uint8_t hopPattern;
247    uint8_t hopIndex;
248} __attribute__((packed));
249
250struct DsParms_t {
251    uint8_t channel;
252} __attribute__((packed));
253
254struct CfParms_t {
255    uint8_t count;
256    uint8_t period;
257    uint16_t maxDuration;
258    uint16_t durRemaining;
259} __attribute__((packed));
260
261struct IbssParms_t {
262    uint16_t atimWindow;
263} __attribute__((packed));
264
265
266struct rsn_t {
267    uint8_t size;
268#define RSN_BODY_SIZE 64
269    uint8_t body[RSN_BODY_SIZE];
270} __attribute__((packed));
271
272struct ErpParams_t {
273    uint8_t erp_info;
274} __attribute__((packed));
275
276struct rate_set16_t{
277    uint8_t size;
278    uint8_t body[16];
279    uint8_t rate_pad;
280} __attribute__((packed));
281
282struct ap_info_t{
283    uint8_t bssid[6]; /* +00 */
284    uint8_t rssi; /* +06 */
285    uint8_t sq; /* +07 */
286    uint8_t noise; /* +08 */
287    uint8_t pad0; /* +09 */
288    uint16_t beacon_period; /* +10 */
289    uint16_t capability; /* +12 */
290#define BSS_CAP_ESS (1<<0)
291#define BSS_CAP_IBSS (1<<1)
292#define BSS_CAP_CF_POLABLE (1<<2)
293#define BSS_CAP_CF_POLL_REQ (1<<3)
294#define BSS_CAP_PRIVACY (1<<4)
295#define BSS_CAP_SHORT_PREAMBLE (1<<5)
296#define BSS_CAP_PBCC (1<<6)
297#define BSS_CAP_CHANNEL_AGILITY (1<<7)
298#define BSS_CAP_SHORT_SLOT_TIME (1<<10)
299#define BSS_CAP_DSSS_OFDM (1<<13)
300    uint8_t frame_type; /* +14 */
301    uint8_t ch_info; /* +15 */
302#define FRAME_TYPE_BEACON 0x80
303#define FRAME_TYPE_PROBE_RESP 0x50
304    uint16_t body_size; /* +16 */
305    uint8_t body[1024]; /* +18 */
306                        /* +1032 */
307} __attribute__((packed));
308
309struct link_ap_info_t{
310    uint8_t bssid[6]; /* +00 */
311    uint8_t rssi; /* +06 */
312    uint8_t sq; /* +07 */
313    uint8_t noise; /* +08 */
314    uint8_t pad0; /* +09 */
315    uint16_t beacon_period; /* +10 */
316    uint16_t capability; /* +12 */
317    struct rate_set8_t rate_set; /* +14 */
318    struct FhParms_t fh_parameter; /* +24 */
319    struct DsParms_t ds_parameter; /* +29 */
320    struct CfParms_t cf_parameter; /* +30 */
321    struct IbssParms_t ibss_parameter; /* +36 */
322    struct ErpParams_t erp_parameter; /* +38 */
323    uint8_t pad1; /* +39 */
324    struct rate_set8_t ext_rate_set; /* +40 */
325    uint8_t DTIM_period; /* +50 */
326    uint8_t rsn_mode; /* +51 */
327#define RSN_MODE_NONE 0
328#define RSN_MODE_WPA 1
329#define RSN_MODE_WPA2 2
330    struct {
331        uint8_t size; /* +52 */
332        uint8_t body[128]; /* +53 */
333    } __attribute__((packed)) rsn;
334} __attribute__((packed));
335
336struct hostif_connect_indication_t {
337    struct hostif_hdr header;
338    uint16_t connect_code;
339#define RESULT_CONNECT 0
340#define RESULT_DISCONNECT 1
341    struct link_ap_info_t link_ap_info;
342} __attribute__((packed));
343
344struct hostif_stop_request_t {
345    struct hostif_hdr header;
346} __attribute__((packed));
347
348struct hostif_stop_confirm_t {
349    struct hostif_hdr header;
350    uint16_t result_code;
351} __attribute__((packed));
352
353struct hostif_ps_adhoc_set_request_t {
354    struct hostif_hdr header;
355    uint16_t phy_type;
356#define D_11B_ONLY_MODE 0
357#define D_11G_ONLY_MODE 1
358#define D_11BG_COMPATIBLE_MODE 2
359#define D_11A_ONLY_MODE 3
360    uint16_t cts_mode;
361#define CTS_MODE_FALSE 0
362#define CTS_MODE_TRUE 1
363    uint16_t channel;
364    struct rate_set16_t rate_set;
365    uint16_t capability; /* bit5:preamble bit6:pbcc pbcc not supported always 0
366                     * bit10:ShortSlotTime bit13:DSSS-OFDM DSSS-OFDM not supported always 0 */
367    uint16_t scan_type;
368} __attribute__((packed));
369
370struct hostif_ps_adhoc_set_confirm_t {
371    struct hostif_hdr header;
372    uint16_t result_code;
373} __attribute__((packed));
374
375struct hostif_infrastructure_set_request_t {
376    struct hostif_hdr header;
377    uint16_t phy_type;
378    uint16_t cts_mode;
379    struct rate_set16_t rate_set;
380    struct ssid_t ssid;
381    uint16_t capability; /* bit5:preamble bit6:pbcc pbcc not supported always 0
382                      * bit10:ShortSlotTime bit13:DSSS-OFDM DSSS-OFDM not supported always 0 */
383    uint16_t beacon_lost_count;
384    uint16_t auth_type;
385#define AUTH_TYPE_OPEN_SYSTEM 0
386#define AUTH_TYPE_SHARED_KEY 1
387    struct channel_list_t channel_list;
388    uint16_t scan_type;
389} __attribute__((packed));
390
391struct hostif_infrastructure_set2_request_t {
392    struct hostif_hdr header;
393    uint16_t phy_type;
394    uint16_t cts_mode;
395    struct rate_set16_t rate_set;
396    struct ssid_t ssid;
397    uint16_t capability; /* bit5:preamble bit6:pbcc pbcc not supported always 0
398                      * bit10:ShortSlotTime bit13:DSSS-OFDM DSSS-OFDM not supported always 0 */
399    uint16_t beacon_lost_count;
400    uint16_t auth_type;
401#define AUTH_TYPE_OPEN_SYSTEM 0
402#define AUTH_TYPE_SHARED_KEY 1
403    struct channel_list_t channel_list;
404    uint16_t scan_type;
405    uint8_t bssid[ETH_ALEN];
406} __attribute__((packed));
407
408
409struct hostif_infrastructure_set_confirm_t {
410    struct hostif_hdr header;
411    uint16_t result_code;
412} __attribute__((packed));
413
414struct hostif_adhoc_set_request_t {
415    struct hostif_hdr header;
416    uint16_t phy_type;
417    uint16_t cts_mode;
418    uint16_t channel;
419    struct rate_set16_t rate_set;
420    struct ssid_t ssid;
421    uint16_t capability; /* bit5:preamble bit6:pbcc pbcc not supported always 0
422                     * bit10:ShortSlotTime bit13:DSSS-OFDM DSSS-OFDM not supported always 0 */
423    uint16_t scan_type;
424} __attribute__((packed));
425
426struct hostif_adhoc_set2_request_t {
427    struct hostif_hdr header;
428    uint16_t phy_type;
429    uint16_t cts_mode;
430    uint16_t reserved;
431    struct rate_set16_t rate_set;
432    struct ssid_t ssid;
433    uint16_t capability; /* bit5:preamble bit6:pbcc pbcc not supported always 0
434                     * bit10:ShortSlotTime bit13:DSSS-OFDM DSSS-OFDM not supported always 0 */
435    uint16_t scan_type;
436    struct channel_list_t channel_list;
437    uint8_t bssid[ETH_ALEN];
438} __attribute__((packed));
439
440struct hostif_adhoc_set_confirm_t {
441    struct hostif_hdr header;
442    uint16_t result_code;
443} __attribute__((packed));
444
445
446struct last_associate_t {
447    uint8_t type;
448    uint8_t status;
449} __attribute__((packed));
450
451struct association_request_t {
452    uint8_t type;
453#define FRAME_TYPE_ASSOC_REQ 0x00
454#define FRAME_TYPE_REASSOC_REQ 0x20
455    uint8_t pad;
456    uint16_t capability;
457    uint16_t listen_interval;
458    uint8_t ap_address[6];
459    uint16_t reqIEs_size;
460} __attribute__((packed));
461
462struct association_response_t {
463    uint8_t type;
464#define FRAME_TYPE_ASSOC_RESP 0x10
465#define FRAME_TYPE_REASSOC_RESP 0x30
466    uint8_t pad;
467    uint16_t capability;
468    uint16_t status;
469    uint16_t association_id;
470    uint16_t respIEs_size;
471} __attribute__((packed));
472
473struct hostif_associate_indication_t {
474    struct hostif_hdr header;
475    struct association_request_t assoc_req;
476    struct association_response_t assoc_resp;
477    /* followed by (reqIEs_size + respIEs_size) octets of data */
478    /* reqIEs data *//* respIEs data */
479} __attribute__((packed));
480
481struct hostif_bss_scan_request_t {
482    struct hostif_hdr header;
483    uint8_t scan_type;
484#define ACTIVE_SCAN 0
485#define PASSIVE_SCAN 1
486    uint8_t pad[3];
487    uint32_t ch_time_min;
488    uint32_t ch_time_max;
489    struct channel_list_t channel_list;
490    struct ssid_t ssid;
491} __attribute__((packed));
492
493struct hostif_bss_scan_confirm_t {
494    struct hostif_hdr header;
495    uint16_t result_code;
496    uint16_t reserved;
497} __attribute__((packed));
498
499struct hostif_phy_information_request_t {
500    struct hostif_hdr header;
501    uint16_t type;
502#define NORMAL_TYPE 0
503#define TIME_TYPE 1
504    uint16_t time; /* unit 100ms */
505} __attribute__((packed));
506
507struct hostif_phy_information_confirm_t {
508    struct hostif_hdr header;
509    uint8_t rssi;
510    uint8_t sq;
511    uint8_t noise;
512    uint8_t link_speed;
513    uint32_t tx_frame;
514    uint32_t rx_frame;
515    uint32_t tx_error;
516    uint32_t rx_error;
517} __attribute__((packed));
518
519/* sleep mode */
520#define SLP_ACTIVE 0
521#define SLP_SLEEP 1
522struct hostif_sleep_request_t {
523    struct hostif_hdr header;
524} __attribute__((packed));
525
526struct hostif_sleep_confirm_t {
527    struct hostif_hdr header;
528    uint16_t result_code;
529} __attribute__((packed));
530
531struct hostif_mic_failure_request_t {
532    struct hostif_hdr header;
533    uint16_t failure_count;
534    uint16_t timer;
535} __attribute__((packed));
536
537struct hostif_mic_failure_confirm_t {
538    struct hostif_hdr header;
539    uint16_t result_code;
540} __attribute__((packed));
541
542#define BASIC_RATE 0x80
543#define RATE_MASK 0x7F
544
545#define TX_RATE_AUTO 0xff
546#define TX_RATE_1M_FIXED 0
547#define TX_RATE_2M_FIXED 1
548#define TX_RATE_1_2M_AUTO 2
549#define TX_RATE_5M_FIXED 3
550#define TX_RATE_11M_FIXED 4
551
552#define TX_RATE_FULL_AUTO 0
553#define TX_RATE_11_AUTO 1
554#define TX_RATE_11B_AUTO 2
555#define TX_RATE_11BG_AUTO 3
556#define TX_RATE_MANUAL_AUTO 4
557#define TX_RATE_FIXED 5
558
559/* 11b rate */
560#define TX_RATE_1M (uint8_t)(10/5) /* 11b 11g basic rate */
561#define TX_RATE_2M (uint8_t)(20/5) /* 11b 11g basic rate */
562#define TX_RATE_5M (uint8_t)(55/5) /* 11g basic rate */
563#define TX_RATE_11M (uint8_t)(110/5) /* 11g basic rate */
564
565/* 11g rate */
566#define TX_RATE_6M (uint8_t)(60/5) /* 11g basic rate */
567#define TX_RATE_12M (uint8_t)(120/5) /* 11g basic rate */
568#define TX_RATE_24M (uint8_t)(240/5) /* 11g basic rate */
569#define TX_RATE_9M (uint8_t)(90/5)
570#define TX_RATE_18M (uint8_t)(180/5)
571#define TX_RATE_36M (uint8_t)(360/5)
572#define TX_RATE_48M (uint8_t)(480/5)
573#define TX_RATE_54M (uint8_t)(540/5)
574
575#define IS_11B_RATE(A) (((A&RATE_MASK)==TX_RATE_1M)||((A&RATE_MASK)==TX_RATE_2M)||\
576                        ((A&RATE_MASK)==TX_RATE_5M)||((A&RATE_MASK)==TX_RATE_11M))
577
578#define IS_OFDM_RATE(A) (((A&RATE_MASK)==TX_RATE_6M)||((A&RATE_MASK)==TX_RATE_12M)||\
579                        ((A&RATE_MASK)==TX_RATE_24M)||((A&RATE_MASK)==TX_RATE_9M)||\
580                        ((A&RATE_MASK)==TX_RATE_18M)||((A&RATE_MASK)==TX_RATE_36M)||\
581                        ((A&RATE_MASK)==TX_RATE_48M)||((A&RATE_MASK)==TX_RATE_54M))
582
583#define IS_11BG_RATE(A) (IS_11B_RATE(A)||IS_OFDM_RATE(A))
584
585#define IS_OFDM_EXT_RATE(A) (((A&RATE_MASK)==TX_RATE_9M)||((A&RATE_MASK)==TX_RATE_18M)||\
586                             ((A&RATE_MASK)==TX_RATE_36M)||((A&RATE_MASK)==TX_RATE_48M)||\
587                             ((A&RATE_MASK)==TX_RATE_54M))
588
589enum {
590    CONNECT_STATUS=0,
591    DISCONNECT_STATUS
592};
593
594/* preamble type */
595enum {
596    LONG_PREAMBLE=0,
597    SHORT_PREAMBLE
598};
599
600/* multicast filter */
601#define MCAST_FILTER_MCAST 0
602#define MCAST_FILTER_MCASTALL 1
603#define MCAST_FILTER_PROMISC 2
604
605#define NIC_MAX_MCAST_LIST 32
606
607/* macro function */
608#define HIF_EVENT_MASK 0xE800
609#define IS_HIF_IND(_EVENT) ((_EVENT&HIF_EVENT_MASK)==0xE800 && \
610                             ((_EVENT&~HIF_EVENT_MASK)==0x0001 || \
611                              (_EVENT&~HIF_EVENT_MASK)==0x0006 || \
612                              (_EVENT&~HIF_EVENT_MASK)==0x000C || \
613                              (_EVENT&~HIF_EVENT_MASK)==0x0011 || \
614                              (_EVENT&~HIF_EVENT_MASK)==0x0012))
615
616#define IS_HIF_CONF(_EVENT) ((_EVENT&HIF_EVENT_MASK)==0xE800 && \
617                             (_EVENT&~HIF_EVENT_MASK)>0x0000 && \
618                             (_EVENT&~HIF_EVENT_MASK)<0x0012 && \
619                             !IS_HIF_IND(_EVENT) )
620
621#ifdef __KERNEL__
622
623#include "ks_wlan.h"
624
625/* function prototype */
626extern int hostif_data_request( ks_wlan_private *priv, struct sk_buff *packet );
627extern void hostif_receive( ks_wlan_private *priv, unsigned char *p, unsigned int size );
628extern void hostif_sme_enqueue(ks_wlan_private *priv, uint16_t event);
629extern int hostif_init( ks_wlan_private *priv );
630extern void hostif_exit( ks_wlan_private *priv );
631
632static
633inline int hif_align_size(int size)
634{
635#ifdef KS_ATOM
636    if( size < 1024 )
637        size = 1024;
638#endif
639#ifdef DEVICE_ALIGNMENT
640    return (size%DEVICE_ALIGNMENT) ? size + DEVICE_ALIGNMENT - (size % DEVICE_ALIGNMENT) : size;
641#else
642    return size;
643#endif
644}
645
646#endif /* __KERNEL__ */
647
648#endif /* _KS_HOSTIF_H_ */
package/ks7010/src/ks_wlan.h
1/*
2 * Driver for KeyStream IEEE802.11 b/g wireless LAN cards.
3 *
4 * ks_wlan.h
5 * $Id: ks_wlan.h 994 2009-09-14 01:51:16Z sekine $
6 *
7 * Copyright (C) 2006-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#ifndef _KS_WLAN_H
16#define _KS_WLAN_H
17
18#define WPS
19
20#include <linux/version.h>
21#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24))
22#include <linux/config.h>
23#endif
24#include <linux/kernel.h>
25#include <linux/module.h>
26
27#include <linux/spinlock.h> /* spinlock_t */
28#include <linux/sched.h> /* wait_queue_head_t */
29#include <linux/types.h> /* pid_t */
30#include <linux/netdevice.h> /* struct net_device_stats, struct sk_buff */
31#include <linux/etherdevice.h>
32#include <linux/wireless.h>
33#include <asm/atomic.h> /* struct atmic_t */
34#include <linux/timer.h> /* struct timer_list */
35#include <linux/string.h>
36#include <linux/completion.h> /* struct completion */
37
38#include <asm/io.h>
39
40/* Workqueue / task queue backwards compatibility stuff */
41#if ((LINUX_VERSION_CODE > KERNEL_VERSION(2,5,41)) || (defined _MVL31_) || (defined _CELF3_))
42#include <linux/workqueue.h>
43#else
44#include <linux/tqueue.h>
45#define work_struct tq_struct
46#define INIT_WORK INIT_TQUEUE
47#define schedule_work schedule_task
48#endif
49
50/* Interrupt handler backwards compatibility stuff */
51/*
52#ifndef IRQ_NONE
53#define IRQ_NONE
54#define IRQ_HANDLED
55typedef void irqreturn_t;
56#endif
57*/
58
59#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,23)
60#define free_netdev(x) kfree(x)
61#define pci_name(x) x->slot_name
62#endif
63
64#if (defined _PCMCIA_)
65#include "pcmcia/ks7010_pcmcia.h"
66#elif (defined _PCI_)
67#include "pci/ks7010_pci.h"
68#elif (defined _SDIO_)
69#include "ks7010_sdio.h"
70#elif (defined _SPI_)
71#include "spi/ks7010_spi.h"
72#else
73#error not defined bus type !
74#endif
75
76struct ks_wlan_parameter {
77    uint8_t operation_mode; /* Operation Mode */
78    uint8_t channel; /* Channel */
79    uint8_t tx_rate; /* Transmit Rate */
80    struct {
81        uint8_t size;
82        uint8_t body[16];
83    } rate_set;
84    uint8_t bssid[ETH_ALEN]; /* BSSID */
85    struct {
86        uint8_t size;
87        uint8_t body[32+1];
88    } ssid; /* SSID */
89    uint8_t preamble; /* Preamble */
90    uint8_t powermgt; /* PowerManagementMode */
91    uint32_t scan_type; /* AP List Scan Type */
92#define BEACON_LOST_COUNT_MIN 0
93#define BEACON_LOST_COUNT_MAX 65535
94    uint32_t beacon_lost_count; /* Beacon Lost Count */
95    uint32_t rts; /* RTS Threashold */
96    uint32_t fragment; /* Fragmentation Threashold */
97    uint32_t privacy_invoked;
98    uint32_t wep_index;
99    struct {
100        uint8_t size;
101        uint8_t val[13*2+1];
102    } wep_key[4];
103    uint16_t authenticate_type;
104    uint16_t phy_type; /* 11b/11g/11bg mode type*/
105    uint16_t cts_mode; /* for 11g/11bg mode cts mode */
106    uint16_t phy_info_timer; /* phy information timer */
107    char rom_file[256];
108};
109
110enum {
111    DEVICE_STATE_OFF = 0, /* this means hw_unavailable is != 0 */
112    DEVICE_STATE_PREBOOT, /* we are in a pre-boot state (empty RAM) */
113    DEVICE_STATE_BOOT, /* boot state (fw upload, run fw) */
114    DEVICE_STATE_PREINIT, /* pre-init state */
115    DEVICE_STATE_INIT, /* init state (restore MIB backup to device) */
116    DEVICE_STATE_READY, /* driver&device are in operational state */
117    DEVICE_STATE_SLEEP /* device in sleep mode */
118};
119
120/* SME flag */
121#define SME_MODE_SET (1<<0)
122#define SME_RTS (1<<1)
123#define SME_FRAG (1<<2)
124#define SME_WEP_FLAG (1<<3)
125#define SME_WEP_INDEX (1<<4)
126#define SME_WEP_VAL1 (1<<5)
127#define SME_WEP_VAL2 (1<<6)
128#define SME_WEP_VAL3 (1<<7)
129#define SME_WEP_VAL4 (1<<8)
130#define SME_WEP_VAL_MASK (SME_WEP_VAL1|SME_WEP_VAL2|SME_WEP_VAL3|SME_WEP_VAL4)
131#define SME_RSN (1<<9)
132#define SME_RSN_MULTICAST (1<<10)
133#define SME_RSN_UNICAST (1<<11)
134#define SME_RSN_AUTH (1<<12)
135
136#define SME_AP_SCAN (1<<13)
137#define SME_MULTICAST (1<<14)
138
139/* SME Event */
140enum {
141    SME_START,
142
143    SME_MULTICAST_REQUEST,
144    SME_MACADDRESS_SET_REQUEST,
145    SME_BSS_SCAN_REQUEST,
146    SME_SET_FLAG,
147    SME_SET_TXKEY,
148    SME_SET_KEY1,
149    SME_SET_KEY2,
150    SME_SET_KEY3,
151    SME_SET_KEY4,
152    SME_SET_PMK_TSC,
153    SME_SET_GMK1_TSC,
154    SME_SET_GMK2_TSC,
155    SME_SET_GMK3_TSC,
156    SME_SET_PMKSA,
157    SME_POW_MNGMT_REQUEST,
158    SME_PHY_INFO_REQUEST,
159    SME_MIC_FAILURE_REQUEST,
160    SME_GET_MAC_ADDRESS,
161    SME_GET_PRODUCT_VERSION,
162    SME_STOP_REQUEST,
163    SME_RTS_THRESHOLD_REQUEST,
164    SME_FRAGMENTATION_THRESHOLD_REQUEST,
165    SME_WEP_INDEX_REQUEST,
166    SME_WEP_KEY1_REQUEST,
167    SME_WEP_KEY2_REQUEST,
168    SME_WEP_KEY3_REQUEST,
169    SME_WEP_KEY4_REQUEST,
170    SME_WEP_FLAG_REQUEST,
171    SME_RSN_UCAST_REQUEST,
172    SME_RSN_MCAST_REQUEST,
173    SME_RSN_AUTH_REQUEST,
174    SME_RSN_ENABLED_REQUEST,
175    SME_RSN_MODE_REQUEST,
176#ifdef WPS
177    SME_WPS_ENABLE_REQUEST,
178    SME_WPS_PROBE_REQUEST,
179#endif
180    SME_SET_GAIN,
181    SME_GET_GAIN,
182    SME_SLEEP_REQUEST,
183    SME_SET_REGION,
184    SME_MODE_SET_REQUEST,
185    SME_START_REQUEST,
186    SME_GET_EEPROM_CKSUM,
187
188
189    SME_MIC_FAILURE_CONFIRM,
190    SME_START_CONFIRM,
191
192    SME_MULTICAST_CONFIRM,
193    SME_BSS_SCAN_CONFIRM,
194    SME_GET_CURRENT_AP,
195    SME_POW_MNGMT_CONFIRM,
196    SME_PHY_INFO_CONFIRM,
197    SME_STOP_CONFIRM,
198    SME_RTS_THRESHOLD_CONFIRM,
199    SME_FRAGMENTATION_THRESHOLD_CONFIRM,
200    SME_WEP_INDEX_CONFIRM,
201    SME_WEP_KEY1_CONFIRM,
202    SME_WEP_KEY2_CONFIRM,
203    SME_WEP_KEY3_CONFIRM,
204    SME_WEP_KEY4_CONFIRM,
205    SME_WEP_FLAG_CONFIRM,
206    SME_RSN_UCAST_CONFIRM,
207    SME_RSN_MCAST_CONFIRM,
208    SME_RSN_AUTH_CONFIRM,
209    SME_RSN_ENABLED_CONFIRM,
210    SME_RSN_MODE_CONFIRM,
211    SME_MODE_SET_CONFIRM,
212    SME_SLEEP_CONFIRM,
213
214    SME_RSN_SET_CONFIRM,
215    SME_WEP_SET_CONFIRM,
216    SME_TERMINATE,
217
218    SME_EVENT_SIZE /* end */
219};
220
221/* SME Status */
222enum {
223    SME_IDLE,
224    SME_SETUP,
225    SME_DISCONNECT,
226    SME_CONNECT
227};
228
229#define SME_EVENT_BUFF_SIZE 128
230
231struct sme_info{
232    int sme_status;
233    int event_buff[SME_EVENT_BUFF_SIZE];
234    unsigned int qhead;
235    unsigned int qtail;
236#ifdef KS_WLAN_DEBUG
237  /* for debug */
238    unsigned int max_event_count;
239#endif
240    spinlock_t sme_spin;
241    unsigned long sme_flag;
242};
243
244struct hostt_t{
245    int buff[SME_EVENT_BUFF_SIZE];
246    unsigned int qhead;
247    unsigned int qtail;
248};
249
250#define RSN_IE_BODY_MAX 64
251struct rsn_ie_t {
252    uint8_t id; /* 0xdd = WPA or 0x30 = RSN */
253    uint8_t size; /* max ? 255 ? */
254    uint8_t body[RSN_IE_BODY_MAX];
255} __attribute__((packed));
256
257#ifdef WPS
258#define WPS_IE_BODY_MAX 255
259struct wps_ie_t {
260    uint8_t id; /* 221 'dd <len> 00 50 F2 04' */
261    uint8_t size; /* max ? 255 ? */
262    uint8_t body[WPS_IE_BODY_MAX];
263} __attribute__((packed));
264#endif /* WPS */
265
266struct local_ap_t {
267    uint8_t bssid[6];
268    uint8_t rssi;
269    uint8_t sq;
270    struct {
271        uint8_t size;
272        uint8_t body[32];
273        uint8_t ssid_pad;
274    } ssid;
275    struct {
276        uint8_t size;
277        uint8_t body[16];
278        uint8_t rate_pad;
279    } rate_set;
280    uint16_t capability;
281    uint8_t channel;
282    uint8_t noise;
283    struct rsn_ie_t wpa_ie;
284    struct rsn_ie_t rsn_ie;
285#ifdef WPS
286    struct wps_ie_t wps_ie;
287#endif /* WPS */
288};
289
290#define LOCAL_APLIST_MAX 31
291#define LOCAL_CURRENT_AP LOCAL_APLIST_MAX
292struct local_aplist_t {
293    int size;
294    struct local_ap_t ap[LOCAL_APLIST_MAX+1];
295};
296
297struct local_gain_t{
298    uint8_t TxMode;
299    uint8_t RxMode;
300    uint8_t TxGain;
301    uint8_t RxGain;
302};
303
304struct local_eeprom_sum_t{
305    uint8_t type;
306    uint8_t result;
307};
308
309enum {
310    EEPROM_OK,
311    EEPROM_CHECKSUM_NONE,
312    EEPROM_FW_NOT_SUPPORT,
313    EEPROM_NG,
314};
315
316
317/* Power Save Status */
318enum {
319    PS_NONE,
320    PS_ACTIVE_SET,
321    PS_SAVE_SET,
322    PS_CONF_WAIT,
323    PS_SNOOZE,
324    PS_WAKEUP
325};
326
327struct power_save_status_t {
328        atomic_t status; /* initialvalue 0 */
329    struct completion wakeup_wait;
330    atomic_t confirm_wait;
331    atomic_t snooze_guard;
332};
333
334struct sleep_status_t {
335        atomic_t status; /* initialvalue 0 */
336    atomic_t doze_request;
337    atomic_t wakeup_request;
338};
339
340/* WPA */
341struct scan_ext_t {
342    unsigned int flag;
343    char ssid[IW_ESSID_MAX_SIZE+1];
344};
345
346enum {
347    CIPHER_NONE,
348    CIPHER_WEP40,
349    CIPHER_TKIP,
350    CIPHER_CCMP,
351    CIPHER_WEP104
352};
353
354#define CIPHER_ID_WPA_NONE "\x00\x50\xf2\x00"
355#define CIPHER_ID_WPA_WEP40 "\x00\x50\xf2\x01"
356#define CIPHER_ID_WPA_TKIP "\x00\x50\xf2\x02"
357#define CIPHER_ID_WPA_CCMP "\x00\x50\xf2\x04"
358#define CIPHER_ID_WPA_WEP104 "\x00\x50\xf2\x05"
359
360#define CIPHER_ID_WPA2_NONE "\x00\x0f\xac\x00"
361#define CIPHER_ID_WPA2_WEP40 "\x00\x0f\xac\x01"
362#define CIPHER_ID_WPA2_TKIP "\x00\x0f\xac\x02"
363#define CIPHER_ID_WPA2_CCMP "\x00\x0f\xac\x04"
364#define CIPHER_ID_WPA2_WEP104 "\x00\x0f\xac\x05"
365
366#define CIPHER_ID_LEN 4
367
368enum {
369    KEY_MGMT_802_1X,
370    KEY_MGMT_PSK,
371    KEY_MGMT_WPANONE,
372};
373
374#define KEY_MGMT_ID_WPA_NONE "\x00\x50\xf2\x00"
375#define KEY_MGMT_ID_WPA_1X "\x00\x50\xf2\x01"
376#define KEY_MGMT_ID_WPA_PSK "\x00\x50\xf2\x02"
377#define KEY_MGMT_ID_WPA_WPANONE "\x00\x50\xf2\xff"
378
379#define KEY_MGMT_ID_WPA2_NONE "\x00\x0f\xac\x00"
380#define KEY_MGMT_ID_WPA2_1X "\x00\x0f\xac\x01"
381#define KEY_MGMT_ID_WPA2_PSK "\x00\x0f\xac\x02"
382#define KEY_MGMT_ID_WPA2_WPANONE "\x00\x0f\xac\xff"
383
384#define KEY_MGMT_ID_LEN 4
385
386#define MIC_KEY_SIZE 8
387
388struct wpa_key_t {
389    uint32_t ext_flags; /* IW_ENCODE_EXT_xxx */
390    uint8_t tx_seq[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */
391    uint8_t rx_seq[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */
392    struct sockaddr addr; /* ff:ff:ff:ff:ff:ff for broadcast/multicast
393                   * (group) keys or unicast address for
394                   * individual keys */
395    uint16_t alg;
396    uint16_t key_len; /* WEP: 5 or 13, TKIP: 32, CCMP: 16 */
397    uint8_t key_val[IW_ENCODING_TOKEN_MAX];
398    uint8_t tx_mic_key[MIC_KEY_SIZE];
399    uint8_t rx_mic_key[MIC_KEY_SIZE];
400};
401#define WPA_KEY_INDEX_MAX 4
402#define WPA_RX_SEQ_LEN 6
403
404struct mic_failure_t {
405    uint16_t failure; /* MIC Failure counter 0 or 1 or 2 */
406    uint16_t counter; /* 1sec counter 0-60 */
407    uint32_t last_failure_time;
408    int stop; /* stop flag */
409};
410
411struct wpa_status_t {
412    int wpa_enabled;
413    unsigned int rsn_enabled;
414    int version;
415    int pairwise_suite; /* unicast cipher */
416    int group_suite; /* multicast cipher */
417    int key_mgmt_suite; /* authentication key management suite */
418    int auth_alg;
419    int txkey;
420    struct wpa_key_t key[WPA_KEY_INDEX_MAX];
421    struct scan_ext_t scan_ext;
422    struct mic_failure_t mic_failure;
423};
424
425#include <linux/list.h>
426#define PMK_LIST_MAX 8
427struct pmk_list_t {
428    uint16_t size;
429    struct list_head head;
430    struct pmk_t {
431        struct list_head list;
432        uint8_t bssid[ETH_ALEN];
433        uint8_t pmkid[IW_PMKID_LEN];
434    } pmk[PMK_LIST_MAX];
435};
436
437#ifdef WPS
438struct wps_status_t {
439       int wps_enabled;
440       int ielen;
441       uint8_t ie[255];
442};
443#endif /* WPS */
444
445typedef struct ks_wlan_private{
446
447    struct hw_info_t ks_wlan_hw; /* hardware information */
448
449    struct net_device *net_dev;
450    int reg_net; /* register_netdev */
451    struct net_device_stats nstats;
452    struct iw_statistics wstats;
453
454    struct completion confirm_wait;
455
456        /* trx device & sme */
457    struct tx_device tx_dev;
458    struct rx_device rx_dev;
459    struct sme_info sme_i;
460    u8 *rxp;
461    unsigned int rx_size;
462    struct tasklet_struct sme_task;
463    struct work_struct ks_wlan_wakeup_task;
464    int scan_ind_count;
465
466    unsigned char eth_addr[ETH_ALEN];
467
468    struct local_aplist_t aplist;
469    struct local_ap_t current_ap;
470    struct power_save_status_t psstatus;
471    struct sleep_status_t sleepstatus;
472    struct wpa_status_t wpa;
473    struct pmk_list_t pmklist;
474        /* wireless parameter */
475    struct ks_wlan_parameter reg;
476    uint8_t current_rate;
477
478    char nick[IW_ESSID_MAX_SIZE+1];
479
480        spinlock_t multicast_spin;
481
482    spinlock_t dev_read_lock;
483        wait_queue_head_t devread_wait;
484
485    unsigned int need_commit; /* for ioctl */
486
487        /* DeviceIoControl */
488    int device_open_status;
489    atomic_t event_count;
490        atomic_t rec_count;
491        int dev_count;
492#define DEVICE_STOCK_COUNT 20
493    unsigned char *dev_data[DEVICE_STOCK_COUNT];
494    int dev_size[DEVICE_STOCK_COUNT];
495
496        /* ioctl : IOCTL_FIRMWARE_VERSION */
497    unsigned char firmware_version[128+1];
498    int version_size;
499
500    int mac_address_valid; /* Mac Address Status */
501
502    int dev_state;
503
504    struct sk_buff *skb;
505    unsigned int cur_rx; /* Index into the Rx buffer of next Rx pkt. */
506    /* spinlock_t lock; */
507#define FORCE_DISCONNECT 0x80000000
508#define CONNECT_STATUS_MASK 0x7FFFFFFF
509    uint32_t connect_status; /* connect status */
510    int infra_status; /* Infractructure status */
511
512        uint8_t data_buff[0x1000];
513
514    uint8_t scan_ssid_len;
515    uint8_t scan_ssid[IW_ESSID_MAX_SIZE+1];
516    struct local_gain_t gain;
517#ifdef WPS
518    struct net_device *l2_dev;
519    int l2_fd;
520    struct wps_status_t wps;
521#endif /* WPS */
522     uint8_t sleep_mode;
523
524    uint8_t region;
525    struct local_eeprom_sum_t eeprom_sum;
526    uint8_t eeprom_checksum;
527
528    struct hostt_t hostt;
529
530    unsigned long last_doze;
531    unsigned long last_wakeup;
532
533    uint sdio_error_count; /* SDIO error */
534    uint wakeup_count; /* for detect wakeup loop */
535
536} ks_wlan_private;
537
538
539
540#endif /* _KS_WLAN_H */
package/ks7010/src/ks_wlan_ioctl.h
1/*
2 * Driver for KeyStream 11b/g wireless LAN
3 *
4 * ks_wlan_ioctl.h
5 * $Id: ks_wlan_ioctl.h 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#ifndef _KS_WLAN_IOCTL_H
16#define _KS_WLAN_IOCTL_H
17
18#include <linux/wireless.h>
19/* The low order bit identify a SET (0) or a GET (1) ioctl. */
20
21/* SIOCIWFIRSTPRIV+0 */
22#define KS_WLAN_GET_DRIVER_VERSION SIOCIWFIRSTPRIV+1
23/* SIOCIWFIRSTPRIV+2 */
24#define KS_WLAN_GET_FIRM_VERSION SIOCIWFIRSTPRIV+3
25#ifdef WPS
26#define KS_WLAN_SET_WPS_ENABLE SIOCIWFIRSTPRIV+4
27#define KS_WLAN_GET_WPS_ENABLE SIOCIWFIRSTPRIV+5
28#define KS_WLAN_SET_WPS_PROBE_REQ SIOCIWFIRSTPRIV+6
29#endif
30#define KS_WLAN_GET_EEPROM_CKSUM SIOCIWFIRSTPRIV+7
31#define KS_WLAN_SET_PREAMBLE SIOCIWFIRSTPRIV+8
32#define KS_WLAN_GET_PREAMBLE SIOCIWFIRSTPRIV+9
33#define KS_WLAN_SET_POWER_SAVE SIOCIWFIRSTPRIV+10
34#define KS_WLAN_GET_POWER_SAVE SIOCIWFIRSTPRIV+11
35#define KS_WLAN_SET_SCAN_TYPE SIOCIWFIRSTPRIV+12
36#define KS_WLAN_GET_SCAN_TYPE SIOCIWFIRSTPRIV+13
37#define KS_WLAN_SET_RX_GAIN SIOCIWFIRSTPRIV+14
38#define KS_WLAN_GET_RX_GAIN SIOCIWFIRSTPRIV+15
39#define KS_WLAN_HOSTT SIOCIWFIRSTPRIV+16 /* unused */
40//#define KS_WLAN_SET_REGION SIOCIWFIRSTPRIV+17
41#define KS_WLAN_SET_BEACON_LOST SIOCIWFIRSTPRIV+18
42#define KS_WLAN_GET_BEACON_LOST SIOCIWFIRSTPRIV+19
43
44#define KS_WLAN_SET_TX_GAIN SIOCIWFIRSTPRIV+20
45#define KS_WLAN_GET_TX_GAIN SIOCIWFIRSTPRIV+21
46
47/* for KS7010 */
48#define KS_WLAN_SET_PHY_TYPE SIOCIWFIRSTPRIV+22
49#define KS_WLAN_GET_PHY_TYPE SIOCIWFIRSTPRIV+23
50#define KS_WLAN_SET_CTS_MODE SIOCIWFIRSTPRIV+24
51#define KS_WLAN_GET_CTS_MODE SIOCIWFIRSTPRIV+25
52/* SIOCIWFIRSTPRIV+26 */
53/* SIOCIWFIRSTPRIV+27 */
54#define KS_WLAN_SET_SLEEP_MODE SIOCIWFIRSTPRIV+28 /* sleep mode */
55#define KS_WLAN_GET_SLEEP_MODE SIOCIWFIRSTPRIV+29 /* sleep mode */
56/* SIOCIWFIRSTPRIV+30 */
57/* SIOCIWFIRSTPRIV+31 */
58
59#ifdef __KERNEL__
60
61#include "ks_wlan.h"
62#include <linux/netdevice.h>
63
64extern int ks_wlan_read_config_file(ks_wlan_private *priv);
65extern int ks_wlan_setup_parameter(ks_wlan_private *priv, unsigned int commit_flag);
66
67#endif /* __KERNEL__ */
68
69#endif /* _KS_WLAN_IOCTL_H */
package/ks7010/src/ks_wlan_net.c
1/*
2 * Driver for KeyStream 11b/g wireless LAN
3 *
4 * ks_wlan_net.c
5 * $Id: ks_wlan_net.c 1020 2009-09-28 05:48:31Z 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 <linux/version.h>
16#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24))
17#include <linux/config.h>
18#endif
19#include <linux/module.h>
20#include <linux/kernel.h>
21#include <linux/compiler.h>
22#include <linux/init.h>
23#include <linux/ioport.h>
24#include <linux/netdevice.h>
25#include <linux/etherdevice.h>
26#include <linux/if_arp.h>
27#include <linux/rtnetlink.h>
28#include <linux/delay.h>
29#include <linux/completion.h>
30#include <linux/mii.h>
31#include <linux/pci.h>
32#include <linux/ctype.h>
33#include <linux/timer.h>
34#include <asm/atomic.h>
35#include <linux/io.h>
36#include <asm/uaccess.h>
37
38static int wep_on_off;
39#define WEP_OFF 0
40#define WEP_ON_64BIT 1
41#define WEP_ON_128BIT 2
42
43#include "ks_wlan.h"
44#include "ks_hostif.h"
45#include "ks_wlan_ioctl.h"
46#include "ks_debug.h"
47
48/* Include Wireless Extension definition and check version */
49#include <linux/wireless.h>
50#define WIRELESS_SPY /* enable iwspy support */
51#include <net/iw_handler.h> /* New driver API */
52
53#ifdef WIRELESS_EXT
54/* Frequency list (map channels to frequencies) */
55static const long frequency_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442,
56                       2447, 2452, 2457, 2462, 2467, 2472, 2484 };
57
58/* A few details needed for WEP (Wireless Equivalent Privacy) */
59#define MAX_KEY_SIZE 13 /* 128 (?) bits */
60#define MIN_KEY_SIZE 5 /* 40 bits RC4 - WEP */
61typedef struct wep_key_t {
62    u16 len;
63    u8 key[16]; /* 40-bit and 104-bit keys */
64} wep_key_t;
65
66/* Backward compatibility */
67#ifndef IW_ENCODE_NOKEY
68#define IW_ENCODE_NOKEY 0x0800 /* Key is write only, so not present */
69#define IW_ENCODE_MODE (IW_ENCODE_DISABLED | IW_ENCODE_RESTRICTED | IW_ENCODE_OPEN)
70#endif /* IW_ENCODE_NOKEY */
71
72/* List of Wireless Handlers (new API) */
73static const struct iw_handler_def ks_wlan_handler_def;
74
75#define KSC_OPNOTSUPP /* Operation Not Support*/
76
77#endif /* WIRELESS_EXT */
78
79/*
80 * function prototypes
81 */
82extern int ks_wlan_hw_tx(ks_wlan_private *priv, void *p, unsigned long size,
83            void (*complete_handler)(void *arg1, void *arg2),
84            void *arg1,
85            void *arg2 );
86static int ks_wlan_open (struct net_device *dev);
87static void ks_wlan_tx_timeout (struct net_device *dev);
88static int ks_wlan_start_xmit (struct sk_buff *skb, struct net_device *dev);
89static int ks_wlan_close (struct net_device *dev);
90static void ks_wlan_set_multicast_list (struct net_device *dev);
91static struct net_device_stats *ks_wlan_get_stats (struct net_device *dev);
92static int ks_wlan_set_mac_address(struct net_device *dev, void *addr);
93static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
94
95static atomic_t update_phyinfo;
96static struct timer_list update_phyinfo_timer;
97static
98int ks_wlan_update_phy_information(ks_wlan_private *priv)
99{
100        struct iw_statistics *wstats = &priv->wstats;
101
102    DPRINTK(4, "in_interrupt = %ld\n", in_interrupt());
103
104    if (priv->dev_state < DEVICE_STATE_READY) {
105                return -1; /* not finished initialize */
106        }
107    if(atomic_read(&update_phyinfo))
108        return 1;
109
110    /* The status */
111    wstats->status = priv->reg.operation_mode; /* Operation mode */
112
113    /* Signal quality and co. But where is the noise level ??? */
114    hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST);
115
116    /* interruptible_sleep_on_timeout(&priv->confirm_wait, HZ/2); */
117    if(!wait_for_completion_interruptible_timeout(&priv->confirm_wait,HZ/2)){
118        DPRINTK(1,"wait time out!!\n");
119    }
120
121    atomic_inc(&update_phyinfo);
122    update_phyinfo_timer.expires = jiffies + HZ; /* 1sec */
123    add_timer(&update_phyinfo_timer);
124
125    return 0;
126}
127
128static
129void ks_wlan_update_phyinfo_timeout(unsigned long ptr)
130{
131    DPRINTK(4, "in_interrupt = %ld\n", in_interrupt());
132    atomic_set(&update_phyinfo,0);
133}
134
135int ks_wlan_setup_parameter(ks_wlan_private *priv, unsigned int commit_flag)
136{
137    DPRINTK(2,"\n");
138
139    hostif_sme_enqueue(priv, SME_STOP_REQUEST);
140
141    if(commit_flag & SME_RTS)
142        hostif_sme_enqueue(priv, SME_RTS_THRESHOLD_REQUEST);
143    if(commit_flag & SME_FRAG)
144        hostif_sme_enqueue(priv, SME_FRAGMENTATION_THRESHOLD_REQUEST);
145
146    if(commit_flag & SME_WEP_INDEX)
147        hostif_sme_enqueue(priv, SME_WEP_INDEX_REQUEST);
148    if(commit_flag & SME_WEP_VAL1)
149        hostif_sme_enqueue(priv, SME_WEP_KEY1_REQUEST);
150    if(commit_flag & SME_WEP_VAL2)
151        hostif_sme_enqueue(priv, SME_WEP_KEY2_REQUEST);
152    if(commit_flag & SME_WEP_VAL3)
153        hostif_sme_enqueue(priv, SME_WEP_KEY3_REQUEST);
154    if(commit_flag & SME_WEP_VAL4)
155        hostif_sme_enqueue(priv, SME_WEP_KEY4_REQUEST);
156    if(commit_flag & SME_WEP_FLAG)
157        hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
158
159    if(commit_flag & SME_RSN){
160        hostif_sme_enqueue(priv, SME_RSN_ENABLED_REQUEST);
161        hostif_sme_enqueue(priv, SME_RSN_MODE_REQUEST);
162    }
163    if(commit_flag & SME_RSN_MULTICAST)
164        hostif_sme_enqueue(priv, SME_RSN_MCAST_REQUEST);
165    if(commit_flag & SME_RSN_UNICAST)
166        hostif_sme_enqueue(priv, SME_RSN_UCAST_REQUEST);
167    if(commit_flag & SME_RSN_AUTH)
168        hostif_sme_enqueue(priv, SME_RSN_AUTH_REQUEST);
169
170    hostif_sme_enqueue(priv, SME_MODE_SET_REQUEST);
171
172    hostif_sme_enqueue(priv, SME_START_REQUEST);
173
174    return 0;
175}
176
177#ifdef WIRELESS_EXT
178/*
179 * Initial Wireless Extension code for Ks_Wlannet driver by :
180 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 17 November 00
181 * Conversion to new driver API by :
182 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 26 March 02
183 * Javier also did a good amount of work here, adding some new extensions
184 * and fixing my code. Let's just say that without him this code just
185 * would not work at all... - Jean II
186 */
187
188/*------------------------------------------------------------------*/
189/* Wireless Handler : get protocol name */
190static int ks_wlan_get_name(struct net_device *dev, struct iw_request_info *info,
191                char *cwrq, char *extra)
192{
193    ks_wlan_private *priv = (ks_wlan_private *) netdev_priv(dev);
194
195    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
196
197    if (priv->dev_state < DEVICE_STATE_READY) {
198        strcpy(cwrq, "NOT READY!");
199        }
200    else if(priv->reg.phy_type == D_11B_ONLY_MODE){
201        strcpy(cwrq, "IEEE 802.11b");
202    }
203    else if(priv->reg.phy_type == D_11G_ONLY_MODE){
204        strcpy(cwrq, "IEEE 802.11g");
205    }
206    else {
207        strcpy(cwrq, "IEEE 802.11b/g");
208    }
209
210    return 0;
211}
212
213/*------------------------------------------------------------------*/
214/* Wireless Handler : set frequency */
215static int ks_wlan_set_freq(struct net_device *dev, struct iw_request_info *info,
216                struct iw_freq *fwrq, char *extra)
217{
218    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
219    int rc = -EINPROGRESS; /* Call commit handler */
220
221    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
222
223    /* If setting by frequency, convert to a channel */
224    if((fwrq->e == 1) &&
225       (fwrq->m >= (int) 2.412e8) &&
226       (fwrq->m <= (int) 2.487e8)) {
227        int f = fwrq->m / 100000;
228        int c = 0;
229        while((c < 14) && (f != frequency_list[c]))
230            c++;
231        /* Hack to fall through... */
232        fwrq->e = 0;
233        fwrq->m = c + 1;
234    }
235    /* Setting by channel number */
236    if((fwrq->m > 1000) || (fwrq->e > 0))
237        rc = -EOPNOTSUPP;
238    else {
239        int channel = fwrq->m;
240        /* We should do a better check than that,
241         * based on the card capability !!! */
242        if((channel < 1) || (channel > 14)) {
243            printk(KERN_DEBUG "%s: New channel value of %d is invalid!\n", dev->name, fwrq->m);
244            rc = -EINVAL;
245        } else {
246            /* Yes ! We can set it !!! */
247            priv->reg.channel = (u8)(channel);
248            priv->need_commit |= SME_MODE_SET;
249        }
250    }
251
252    return rc;
253}
254
255/*------------------------------------------------------------------*/
256/* Wireless Handler : get frequency */
257static int ks_wlan_get_freq(struct net_device *dev, struct iw_request_info *info,
258                struct iw_freq *fwrq, char *extra)
259{
260    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
261    int f;
262
263    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
264
265    if((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS){
266        f = (int)priv->current_ap.channel;
267    }
268    else
269        f = (int)priv->reg.channel;
270    fwrq->m = frequency_list[f-1] * 100000;
271    fwrq->e = 1;
272
273    return 0;
274}
275
276/*------------------------------------------------------------------*/
277/* Wireless Handler : set ESSID */
278static int ks_wlan_set_essid(struct net_device *dev, struct iw_request_info *info,
279                 struct iw_point *dwrq, char *extra)
280{
281    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
282    size_t len;
283
284    DPRINTK(2," %d\n", dwrq->flags);
285
286    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
287
288    /* Check if we asked for `any' */
289    if(dwrq->flags == 0) {
290        /* Just send an empty SSID list */
291        memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body));
292        priv->reg.ssid.size = 0;
293    } else {
294#if 1
295        len = dwrq->length;
296        /* iwconfig uses nul termination in SSID.. */
297        if (len > 0 && extra[len - 1] == '\0')
298            len--;
299
300        /* Check the size of the string */
301        if(len > IW_ESSID_MAX_SIZE) {
302            return -EINVAL;
303        }
304#else
305        /* Check the size of the string */
306        if(dwrq->length > IW_ESSID_MAX_SIZE+1) {
307            return -E2BIG ;
308        }
309#endif
310
311        /* Set the SSID */
312        memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body));
313
314#if 1
315        memcpy(priv->reg.ssid.body, extra, len);
316        priv->reg.ssid.size = len;
317#else
318        memcpy(priv->reg.ssid.body, extra, dwrq->length);
319        priv->reg.ssid.size = dwrq->length;
320#endif
321    }
322    /* Write it to the card */
323    priv->need_commit |= SME_MODE_SET;
324
325// return -EINPROGRESS; /* Call commit handler */
326    ks_wlan_setup_parameter(priv, priv->need_commit);
327    priv->need_commit=0;
328    return 0;
329}
330
331/*------------------------------------------------------------------*/
332/* Wireless Handler : get ESSID */
333static int ks_wlan_get_essid(struct net_device *dev, struct iw_request_info *info,
334                 struct iw_point *dwrq, char *extra)
335{
336    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
337
338    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
339
340    /* Note : if dwrq->flags != 0, we should
341     * get the relevant SSID from the SSID list... */
342
343    if(priv->reg.ssid.size){
344        /* Get the current SSID */
345        memcpy(extra, priv->reg.ssid.body, priv->reg.ssid.size);
346#if 0
347        extra[priv->reg.ssid.size] = '\0';
348#endif
349        /* If none, we may want to get the one that was set */
350
351        /* Push it out ! */
352#if 1
353        dwrq->length = priv->reg.ssid.size;
354#else
355        dwrq->length = priv->reg.ssid.size+1;
356#endif
357        dwrq->flags = 1; /* active */
358    }else{
359#if 1
360        dwrq->length = 0;
361#else
362        extra[0] = '\0';
363        dwrq->length = 1;
364#endif
365        dwrq->flags = 0; /* ANY */
366    }
367
368    return 0;
369}
370
371/*------------------------------------------------------------------*/
372/* Wireless Handler : set AP address */
373static int ks_wlan_set_wap(struct net_device *dev, struct iw_request_info *info,
374               struct sockaddr *ap_addr, char *extra)
375{
376    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
377
378    DPRINTK(2,"\n");
379
380    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
381
382    if (priv->reg.operation_mode == MODE_ADHOC ||
383        priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
384        memcpy(priv->reg.bssid, (u8 *)&ap_addr->sa_data, ETH_ALEN);
385
386        if (is_valid_ether_addr((u8 *)priv->reg.bssid)) {
387            priv->need_commit |= SME_MODE_SET;
388        }
389    }
390    else {
391        memset(priv->reg.bssid, 0x0, ETH_ALEN);
392        return -EOPNOTSUPP;
393    }
394
395    DPRINTK(2, "bssid = %02x:%02x:%02x:%02x:%02x:%02x\n",
396               priv->reg.bssid[0],priv->reg.bssid[1],priv->reg.bssid[2],
397               priv->reg.bssid[3],priv->reg.bssid[4],priv->reg.bssid[5]);
398
399    /* Write it to the card */
400    if (priv->need_commit) {
401        priv->need_commit |= SME_MODE_SET;
402        return -EINPROGRESS; /* Call commit handler */
403    }
404    return 0;
405}
406
407/*------------------------------------------------------------------*/
408/* Wireless Handler : get AP address */
409static int ks_wlan_get_wap(struct net_device *dev, struct iw_request_info *info,
410               struct sockaddr *awrq, char *extra)
411{
412        ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
413
414    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
415
416    if((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS){
417        memcpy(awrq->sa_data, &(priv->current_ap.bssid[0]), ETH_ALEN);
418    }
419    else{
420        memset(awrq->sa_data, 0, ETH_ALEN);
421    }
422
423    awrq->sa_family = ARPHRD_ETHER;
424
425    return 0;
426}
427
428/*------------------------------------------------------------------*/
429/* Wireless Handler : set Nickname */
430static int ks_wlan_set_nick(struct net_device *dev, struct iw_request_info *info,
431                struct iw_point *dwrq, char *extra)
432{
433    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
434
435    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
436
437    /* Check the size of the string */
438    if(dwrq->length > 16 + 1) {
439        return -E2BIG;
440    }
441    memset(priv->nick, 0, sizeof(priv->nick));
442    memcpy(priv->nick, extra, dwrq->length);
443
444    return -EINPROGRESS; /* Call commit handler */
445}
446
447/*------------------------------------------------------------------*/
448/* Wireless Handler : get Nickname */
449static int ks_wlan_get_nick(struct net_device *dev, struct iw_request_info *info,
450                struct iw_point *dwrq, char *extra)
451{
452    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
453
454    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
455
456    strncpy(extra, priv->nick, 16);
457    extra[16] = '\0';
458    dwrq->length = strlen(extra) + 1;
459
460    return 0;
461}
462
463/*------------------------------------------------------------------*/
464/* Wireless Handler : set Bit-Rate */
465static int ks_wlan_set_rate(struct net_device *dev, struct iw_request_info *info,
466                struct iw_param *vwrq, char *extra)
467{
468    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
469    int i = 0;
470
471    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
472
473    if(priv->reg.phy_type == D_11B_ONLY_MODE){
474        if(vwrq->fixed == 1) {
475            switch(vwrq->value){
476            case 11000000:
477            case 5500000:
478                priv->reg.rate_set.body[0] = (uint8_t)(vwrq->value/500000);
479                break;
480            case 2000000:
481            case 1000000:
482                priv->reg.rate_set.body[0] = ((uint8_t)(vwrq->value/500000))|BASIC_RATE;
483                break;
484            default:
485                return -EINVAL;
486            }
487            priv->reg.tx_rate = TX_RATE_FIXED;
488            priv->reg.rate_set.size = 1;
489        }else{ /* vwrq->fixed == 0 */
490            if(vwrq->value > 0){
491                switch(vwrq->value){
492                case 11000000:
493                    priv->reg.rate_set.body[3] = TX_RATE_11M; i++;
494                case 5500000:
495                    priv->reg.rate_set.body[2] = TX_RATE_5M; i++;
496                case 2000000:
497                    priv->reg.rate_set.body[1] = TX_RATE_2M|BASIC_RATE; i++;
498                case 1000000:
499                    priv->reg.rate_set.body[0] = TX_RATE_1M|BASIC_RATE; i++;
500                    break;
501                default:
502                    return -EINVAL;
503                }
504                priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
505                priv->reg.rate_set.size = i;
506            }else{
507                priv->reg.rate_set.body[3] = TX_RATE_11M;
508                priv->reg.rate_set.body[2] = TX_RATE_5M;
509                priv->reg.rate_set.body[1] = TX_RATE_2M|BASIC_RATE;
510                priv->reg.rate_set.body[0] = TX_RATE_1M|BASIC_RATE;
511                priv->reg.tx_rate = TX_RATE_FULL_AUTO;
512                priv->reg.rate_set.size = 4;
513            }
514        }
515    }else{ /* D_11B_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
516        if(vwrq->fixed == 1) {
517            switch(vwrq->value){
518            case 54000000:
519            case 48000000:
520            case 36000000:
521            case 18000000:
522            case 9000000:
523                priv->reg.rate_set.body[0] = (uint8_t)(vwrq->value/500000);
524                break;
525            case 24000000:
526            case 12000000:
527            case 11000000:
528            case 6000000:
529            case 5500000:
530            case 2000000:
531            case 1000000:
532                priv->reg.rate_set.body[0] = ((uint8_t)(vwrq->value/500000))|BASIC_RATE;
533                break;
534            default:
535                return -EINVAL;
536            }
537            priv->reg.tx_rate = TX_RATE_FIXED;
538            priv->reg.rate_set.size = 1;
539        }else{ /* vwrq->fixed == 0 */
540            if(vwrq->value > 0){
541                switch(vwrq->value){
542                case 54000000:
543                    priv->reg.rate_set.body[11] = TX_RATE_54M; i++;
544                case 48000000:
545                    priv->reg.rate_set.body[10] = TX_RATE_48M; i++;
546                case 36000000:
547                    priv->reg.rate_set.body[9] = TX_RATE_36M; i++;
548                case 24000000: case 18000000: case 12000000:
549                case 11000000: case 9000000: case 6000000:
550                    if(vwrq->value == 24000000){
551                        priv->reg.rate_set.body[8] = TX_RATE_18M; i++;
552                        priv->reg.rate_set.body[7] = TX_RATE_9M; i++;
553                        priv->reg.rate_set.body[6] = TX_RATE_24M|BASIC_RATE; i++;
554                        priv->reg.rate_set.body[5] = TX_RATE_12M|BASIC_RATE; i++;
555                        priv->reg.rate_set.body[4] = TX_RATE_6M|BASIC_RATE; i++;
556                        priv->reg.rate_set.body[3] = TX_RATE_11M|BASIC_RATE; i++;
557                    }else if(vwrq->value == 18000000){
558                        priv->reg.rate_set.body[7] = TX_RATE_18M; i++;
559                        priv->reg.rate_set.body[6] = TX_RATE_9M; i++;
560                        priv->reg.rate_set.body[5] = TX_RATE_12M|BASIC_RATE; i++;
561                        priv->reg.rate_set.body[4] = TX_RATE_6M|BASIC_RATE; i++;
562                        priv->reg.rate_set.body[3] = TX_RATE_11M|BASIC_RATE; i++;
563                    }else if(vwrq->value == 12000000){
564                        priv->reg.rate_set.body[6] = TX_RATE_9M; i++;
565                        priv->reg.rate_set.body[5] = TX_RATE_12M|BASIC_RATE; i++;
566                        priv->reg.rate_set.body[4] = TX_RATE_6M|BASIC_RATE; i++;
567                        priv->reg.rate_set.body[3] = TX_RATE_11M|BASIC_RATE; i++;
568                    }else if(vwrq->value == 11000000){
569                        priv->reg.rate_set.body[5] = TX_RATE_9M; i++;
570                        priv->reg.rate_set.body[4] = TX_RATE_6M|BASIC_RATE; i++;
571                        priv->reg.rate_set.body[3] = TX_RATE_11M|BASIC_RATE; i++;
572                    }else if(vwrq->value == 9000000){
573                        priv->reg.rate_set.body[4] = TX_RATE_9M; i++;
574                        priv->reg.rate_set.body[3] = TX_RATE_6M|BASIC_RATE; i++;
575                    }else{ /* vwrq->value == 6000000 */
576                        priv->reg.rate_set.body[3] = TX_RATE_6M|BASIC_RATE; i++;
577                    }
578                case 5500000:
579                    priv->reg.rate_set.body[2] = TX_RATE_5M|BASIC_RATE; i++;
580                case 2000000:
581                    priv->reg.rate_set.body[1] = TX_RATE_2M|BASIC_RATE; i++;
582                case 1000000:
583                    priv->reg.rate_set.body[0] = TX_RATE_1M|BASIC_RATE; i++;
584                    break;
585                default:
586                    return -EINVAL;
587                }
588                priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
589                priv->reg.rate_set.size = i;
590            }else{
591                priv->reg.rate_set.body[11] = TX_RATE_54M;
592                priv->reg.rate_set.body[10] = TX_RATE_48M;
593                priv->reg.rate_set.body[9] = TX_RATE_36M;
594                priv->reg.rate_set.body[8] = TX_RATE_18M;
595                priv->reg.rate_set.body[7] = TX_RATE_9M;
596                priv->reg.rate_set.body[6] = TX_RATE_24M|BASIC_RATE;
597                priv->reg.rate_set.body[5] = TX_RATE_12M|BASIC_RATE;
598                priv->reg.rate_set.body[4] = TX_RATE_6M|BASIC_RATE;
599                priv->reg.rate_set.body[3] = TX_RATE_11M|BASIC_RATE;
600                priv->reg.rate_set.body[2] = TX_RATE_5M|BASIC_RATE;
601                priv->reg.rate_set.body[1] = TX_RATE_2M|BASIC_RATE;
602                priv->reg.rate_set.body[0] = TX_RATE_1M|BASIC_RATE;
603                priv->reg.tx_rate = TX_RATE_FULL_AUTO;
604                priv->reg.rate_set.size = 12;
605            }
606        }
607    }
608
609    priv->need_commit |= SME_MODE_SET;
610
611    return -EINPROGRESS; /* Call commit handler */
612}
613
614/*------------------------------------------------------------------*/
615/* Wireless Handler : get Bit-Rate */
616static int ks_wlan_get_rate(struct net_device *dev, struct iw_request_info *info,
617                struct iw_param *vwrq, char *extra)
618{
619    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
620
621    DPRINTK(2, "in_interrupt = %ld update_phyinfo = %d\n",
622        in_interrupt(),atomic_read(&update_phyinfo));
623
624    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
625
626    if(!atomic_read(&update_phyinfo)){
627        ks_wlan_update_phy_information(priv);
628    }
629    vwrq->value = ((priv->current_rate) & RATE_MASK) * 500000;
630    if(priv->reg.tx_rate == TX_RATE_FIXED)
631        vwrq->fixed = 1;
632    else
633        vwrq->fixed = 0;
634
635    return 0;
636}
637
638/*------------------------------------------------------------------*/
639/* Wireless Handler : set RTS threshold */
640static int ks_wlan_set_rts(struct net_device *dev, struct iw_request_info *info,
641               struct iw_param *vwrq, char *extra)
642{
643    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
644    int rthr = vwrq->value;
645
646    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
647
648    if(vwrq->disabled)
649        rthr = 2347;
650    if((rthr < 0) || (rthr > 2347)) {
651        return -EINVAL;
652    }
653    priv->reg.rts = rthr;
654    priv->need_commit |= SME_RTS;
655
656    return -EINPROGRESS; /* Call commit handler */
657}
658
659/*------------------------------------------------------------------*/
660/* Wireless Handler : get RTS threshold */
661static int ks_wlan_get_rts(struct net_device *dev, struct iw_request_info *info,
662               struct iw_param *vwrq, char *extra)
663{
664    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
665
666    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
667
668    vwrq->value = priv->reg.rts;
669    vwrq->disabled = (vwrq->value >= 2347);
670    vwrq->fixed = 1;
671
672    return 0;
673}
674
675/*------------------------------------------------------------------*/
676/* Wireless Handler : set Fragmentation threshold */
677static int ks_wlan_set_frag(struct net_device *dev, struct iw_request_info *info,
678                struct iw_param *vwrq, char *extra)
679{
680    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
681    int fthr = vwrq->value;
682
683    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
684
685    if(vwrq->disabled)
686        fthr = 2346;
687    if((fthr < 256) || (fthr > 2346)) {
688        return -EINVAL;
689    }
690    fthr &= ~0x1; /* Get an even value - is it really needed ??? */
691    priv->reg.fragment = fthr;
692    priv->need_commit |= SME_FRAG;
693
694    return -EINPROGRESS; /* Call commit handler */
695}
696
697/*------------------------------------------------------------------*/
698/* Wireless Handler : get Fragmentation threshold */
699static int ks_wlan_get_frag(struct net_device *dev, struct iw_request_info *info,
700                struct iw_param *vwrq, char *extra)
701{
702    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
703
704    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
705
706    vwrq->value = priv->reg.fragment;
707    vwrq->disabled = (vwrq->value >= 2346);
708    vwrq->fixed = 1;
709
710    return 0;
711}
712
713/*------------------------------------------------------------------*/
714/* Wireless Handler : set Mode of Operation */
715static int ks_wlan_set_mode(struct net_device *dev, struct iw_request_info *info,
716                __u32 *uwrq, char *extra)
717{
718    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
719
720    DPRINTK(2,"mode=%d\n",*uwrq);
721
722    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
723
724    switch(*uwrq) {
725    case IW_MODE_ADHOC:
726        priv->reg.operation_mode = MODE_ADHOC;
727        priv->need_commit |= SME_MODE_SET;
728        break;
729    case IW_MODE_INFRA:
730        priv->reg.operation_mode = MODE_INFRASTRUCTURE;
731        priv->need_commit |= SME_MODE_SET;
732        break;
733    case IW_MODE_AUTO:
734    case IW_MODE_MASTER:
735    case IW_MODE_REPEAT:
736    case IW_MODE_SECOND:
737    case IW_MODE_MONITOR:
738    default:
739        return -EINVAL;
740    }
741
742    return -EINPROGRESS; /* Call commit handler */
743}
744
745/*------------------------------------------------------------------*/
746/* Wireless Handler : get Mode of Operation */
747static int ks_wlan_get_mode(struct net_device *dev, struct iw_request_info *info,
748                __u32 *uwrq, char *extra)
749{
750    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
751
752    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
753
754    /* If not managed, assume it's ad-hoc */
755    switch (priv->reg.operation_mode) {
756        case MODE_INFRASTRUCTURE:
757            *uwrq = IW_MODE_INFRA;
758            break;
759        case MODE_ADHOC:
760            *uwrq = IW_MODE_ADHOC;
761            break;
762        default:
763            *uwrq = IW_MODE_ADHOC;
764    }
765
766    return 0;
767}
768
769/*------------------------------------------------------------------*/
770/* Wireless Handler : set Encryption Key */
771static int ks_wlan_set_encode(struct net_device *dev, struct iw_request_info *info,
772                  struct iw_point *dwrq, char *extra)
773{
774    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
775
776    wep_key_t key;
777    int index = (dwrq->flags & IW_ENCODE_INDEX);
778    int current_index = priv->reg.wep_index;
779    int i;
780
781    DPRINTK(2,"flags=%04X\n",dwrq->flags);
782
783    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
784
785    /* index check */
786    if((index<0) || (index>4))
787        return -EINVAL;
788    else if (index==0)
789        index = current_index;
790    else
791        index--;
792
793    /* Is WEP supported ? */
794    /* Basic checking: do we have a key to set ? */
795    if (dwrq->length > 0) {
796        if (dwrq->length > MAX_KEY_SIZE) { /* Check the size of the key */
797            return -EINVAL;
798        }
799        if (dwrq->length > MIN_KEY_SIZE) { /* Set the length */
800            key.len = MAX_KEY_SIZE;
801            priv->reg.privacy_invoked = 0x01;
802            priv->need_commit |= SME_WEP_FLAG;
803            wep_on_off = WEP_ON_128BIT;
804        } else {
805            if (dwrq->length > 0) {
806                key.len = MIN_KEY_SIZE;
807                priv->reg.privacy_invoked = 0x01;
808                priv->need_commit |= SME_WEP_FLAG;
809                wep_on_off = WEP_ON_64BIT;
810            } else { /* Disable the key */
811                key.len = 0;
812            }
813        }
814        /* Check if the key is not marked as invalid */
815        if(!(dwrq->flags & IW_ENCODE_NOKEY)) {
816            /* Cleanup */
817            memset(key.key, 0, MAX_KEY_SIZE);
818            /* Copy the key in the driver */
819            if(copy_from_user(key.key,dwrq->pointer,dwrq->length)) {
820                key.len = 0;
821                return -EFAULT;
822            }
823            /* Send the key to the card */
824            priv->reg.wep_key[index].size = key.len;
825            for (i=0; i<(priv->reg.wep_key[index].size); i++) {
826                priv->reg.wep_key[index].val[i] = key.key[i];
827            }
828            priv->need_commit |= (SME_WEP_VAL1<<index);
829            priv->reg.wep_index = index;
830            priv->need_commit |= SME_WEP_INDEX;
831        }
832    } else {
833        if(dwrq->flags & IW_ENCODE_DISABLED){
834            priv->reg.wep_key[0].size = 0;
835            priv->reg.wep_key[1].size = 0;
836            priv->reg.wep_key[2].size = 0;
837            priv->reg.wep_key[3].size = 0;
838            priv->reg.privacy_invoked = 0x00;
839            if(priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY){
840                priv->need_commit |= SME_MODE_SET;
841            }
842            priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
843            wep_on_off = WEP_OFF;
844            priv->need_commit |= SME_WEP_FLAG;
845        }else{
846            /* Do we want to just set the transmit key index ? */
847            if ((index>=0) && (index<4)) {
848                /* set_wep_key(priv, index, 0, 0, 1); xxx */
849                if(priv->reg.wep_key[index].size){
850                    priv->reg.wep_index = index;
851                    priv->need_commit |= SME_WEP_INDEX;
852                }
853                else
854                    return -EINVAL;
855            }
856        }
857    }
858
859    /* Commit the changes if needed */
860    if(dwrq->flags & IW_ENCODE_MODE)
861        priv->need_commit |= SME_WEP_FLAG;
862
863    if(dwrq->flags & IW_ENCODE_OPEN) {
864        if(priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY){
865            priv->need_commit |= SME_MODE_SET;
866        }
867        priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
868    } else if(dwrq->flags & IW_ENCODE_RESTRICTED) {
869        if(priv->reg.authenticate_type == AUTH_TYPE_OPEN_SYSTEM){
870            priv->need_commit |= SME_MODE_SET;
871        }
872        priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
873    }
874
875// return -EINPROGRESS; /* Call commit handler */
876    if(priv->need_commit){
877        ks_wlan_setup_parameter(priv, priv->need_commit);
878        priv->need_commit=0;
879    }
880    return 0;
881}
882
883/*------------------------------------------------------------------*/
884/* Wireless Handler : get Encryption Key */
885static int ks_wlan_get_encode(struct net_device *dev, struct iw_request_info *info,
886                  struct iw_point *dwrq, char *extra)
887{
888    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
889    char zeros[16];
890    int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
891
892    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
893
894    dwrq->flags = IW_ENCODE_DISABLED;
895
896    /* Check encryption mode */
897    switch(priv->reg.authenticate_type) {
898    case AUTH_TYPE_OPEN_SYSTEM:
899        dwrq->flags = IW_ENCODE_OPEN;
900        break;
901    case AUTH_TYPE_SHARED_KEY:
902        dwrq->flags = IW_ENCODE_RESTRICTED;
903        break;
904    }
905
906    memset(zeros,0, sizeof(zeros));
907
908    /* Which key do we want ? -1 -> tx index */
909    if((index < 0) || (index >= 4))
910        index = priv->reg.wep_index;
911    if (priv->reg.privacy_invoked){
912        dwrq->flags &= ~IW_ENCODE_DISABLED;
913        /* dwrq->flags |= IW_ENCODE_NOKEY; */
914    }
915    dwrq->flags |= index + 1;
916    DPRINTK(2,"encoding flag = 0x%04X\n",dwrq->flags);
917    /* Copy the key to the user buffer */
918    if((index >= 0) && (index < 4))
919        dwrq->length = priv->reg.wep_key[index].size;
920    if (dwrq->length > 16) {
921        dwrq->length=0;
922    }
923#if 1 /* IW_ENCODE_NOKEY; */
924    if (dwrq->length) {
925        if((index >= 0) && (index < 4))
926            memcpy(extra,priv->reg.wep_key[index].val,dwrq->length);
927    } else
928        memcpy(extra,zeros,dwrq->length);
929#endif
930    return 0;
931}
932
933#ifndef KSC_OPNOTSUPP
934/*------------------------------------------------------------------*/
935/* Wireless Handler : set Tx-Power */
936static int ks_wlan_set_txpow(struct net_device *dev, struct iw_request_info *info,
937                 struct iw_param *vwrq, char *extra)
938{
939    return -EOPNOTSUPP; /* Not Support */
940}
941
942/*------------------------------------------------------------------*/
943/* Wireless Handler : get Tx-Power */
944static int ks_wlan_get_txpow(struct net_device *dev, struct iw_request_info *info,
945                 struct iw_param *vwrq, char *extra)
946{
947    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
948
949    /* Not Support */
950    vwrq->value = 0;
951    vwrq->disabled = (vwrq->value == 0);
952    vwrq->fixed = 1;
953    return 0;
954}
955
956/*------------------------------------------------------------------*/
957/* Wireless Handler : set Retry limits */
958static int ks_wlan_set_retry(struct net_device *dev, struct iw_request_info *info,
959                 struct iw_param *vwrq, char *extra)
960{
961    return -EOPNOTSUPP; /* Not Support */
962}
963
964/*------------------------------------------------------------------*/
965/* Wireless Handler : get Retry limits */
966static int ks_wlan_get_retry(struct net_device *dev, struct iw_request_info *info,
967                 struct iw_param *vwrq, char *extra)
968{
969    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
970
971    /* Not Support */
972    vwrq->value = 0;
973    vwrq->disabled = (vwrq->value == 0);
974    vwrq->fixed = 1;
975    return 0;
976}
977#endif /* KSC_OPNOTSUPP */
978
979/*------------------------------------------------------------------*/
980/* Wireless Handler : get range info */
981static int ks_wlan_get_range(struct net_device *dev, struct iw_request_info *info,
982                 struct iw_point *dwrq, char *extra)
983{
984    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
985    struct iw_range *range = (struct iw_range *) extra;
986    int i,k;
987
988    DPRINTK(2,"\n");
989
990    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
991
992    dwrq->length = sizeof(struct iw_range);
993    memset(range, 0, sizeof(*range));
994    range->min_nwid = 0x0000;
995    range->max_nwid = 0x0000;
996    range->num_channels = 14;
997    /* Should be based on cap_rid.country to give only
998     * what the current card support */
999    k = 0;
1000    for(i = 0; i < 13; i++) { /* channel 1 -- 13*/
1001        range->freq[k].i = i + 1; /* List index */
1002        range->freq[k].m = frequency_list[i] * 100000;
1003        range->freq[k++].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
1004    }
1005    range->num_frequency = k;
1006    if(priv->reg.phy_type == D_11B_ONLY_MODE ||
1007       priv->reg.phy_type == D_11BG_COMPATIBLE_MODE){ /* channel 14 */
1008        range->freq[13].i = 14; /* List index */
1009        range->freq[13].m = frequency_list[13] * 100000;
1010        range->freq[13].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
1011        range->num_frequency = 14;
1012    }
1013
1014    /* Hum... Should put the right values there */
1015    range->max_qual.qual = 100;
1016    range->max_qual.level = 256 - 128; /* 0 dBm? */
1017    range->max_qual.noise = 256 - 128;
1018        range->sensitivity = 1;
1019
1020    if(priv->reg.phy_type == D_11B_ONLY_MODE){
1021        range->bitrate[0] = 1e6;
1022        range->bitrate[1] = 2e6;
1023        range->bitrate[2] = 5.5e6;
1024        range->bitrate[3] = 11e6;
1025        range->num_bitrates = 4;
1026    }
1027    else{ /* D_11G_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
1028        range->bitrate[0] = 1e6;
1029        range->bitrate[1] = 2e6;
1030        range->bitrate[2] = 5.5e6;
1031        range->bitrate[3] = 11e6;
1032
1033        range->bitrate[4] = 6e6;
1034        range->bitrate[5] = 9e6;
1035        range->bitrate[6] = 12e6;
1036        if(IW_MAX_BITRATES < 9){
1037            range->bitrate[7] = 54e6;
1038            range->num_bitrates = 8;
1039        }else{
1040            range->bitrate[7] = 18e6;
1041            range->bitrate[8] = 24e6;
1042            range->bitrate[9] = 36e6;
1043            range->bitrate[10] = 48e6;
1044            range->bitrate[11] = 54e6;
1045
1046            range->num_bitrates = 12;
1047        }
1048    }
1049
1050    /* Set an indication of the max TCP throughput
1051     * in bit/s that we can expect using this interface.
1052     * May be use for QoS stuff... Jean II */
1053    if(i > 2)
1054        range->throughput = 5000 * 1000;
1055    else
1056        range->throughput = 1500 * 1000;
1057
1058    range->min_rts = 0;
1059    range->max_rts = 2347;
1060    range->min_frag = 256;
1061    range->max_frag = 2346;
1062
1063        range->encoding_size[0] = 5; /* WEP: RC4 40 bits */
1064        range->encoding_size[1] = 13; /* WEP: RC4 ~128 bits */
1065        range->num_encoding_sizes = 2;
1066    range->max_encoding_tokens = 4;
1067
1068    /* power management not support */
1069    range->pmp_flags = IW_POWER_ON;
1070    range->pmt_flags = IW_POWER_ON;
1071    range->pm_capa = 0;
1072
1073    /* Transmit Power - values are in dBm( or mW) */
1074    range->txpower[0]=-256;
1075    range->num_txpower = 1;
1076    range->txpower_capa = IW_TXPOW_DBM;
1077    /* range->txpower_capa = IW_TXPOW_MWATT; */
1078
1079    range->we_version_source = 21;
1080    range->we_version_compiled = WIRELESS_EXT;
1081
1082    range->retry_capa = IW_RETRY_ON;
1083        range->retry_flags = IW_RETRY_ON;
1084        range->r_time_flags = IW_RETRY_ON;
1085
1086    /* Experimental measurements - boundary 11/5.5 Mb/s */
1087    /* Note : with or without the (local->rssi), results
1088     * are somewhat different. - Jean II */
1089    range->avg_qual.qual = 50;
1090    range->avg_qual.level = 186; /* -70 dBm */
1091    range->avg_qual.noise = 0;
1092
1093#if defined(WIRELESS_EXT)
1094    /* Event capability (kernel + driver) */
1095    range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
1096                IW_EVENT_CAPA_MASK(SIOCGIWAP) |
1097                IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
1098    range->event_capa[1] = IW_EVENT_CAPA_K_1;
1099    range->event_capa[4] = (IW_EVENT_CAPA_MASK(IWEVCUSTOM) |
1100                IW_EVENT_CAPA_MASK(IWEVMICHAELMICFAILURE));
1101
1102    /* encode extension (WPA) capability */
1103    range->enc_capa = (IW_ENC_CAPA_WPA |
1104               IW_ENC_CAPA_WPA2 |
1105               IW_ENC_CAPA_CIPHER_TKIP |
1106               IW_ENC_CAPA_CIPHER_CCMP);
1107#endif
1108    return 0;
1109}
1110
1111
1112/*------------------------------------------------------------------*/
1113/* Wireless Handler : set Power Management */
1114static int ks_wlan_set_power(struct net_device *dev, struct iw_request_info *info,
1115                 struct iw_param *vwrq, char *extra)
1116{
1117    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1118    short enabled;
1119
1120    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1121
1122    enabled = vwrq->disabled ? 0 : 1;
1123    if(enabled == 0 ){ /* 0 */
1124        priv->reg.powermgt = POWMGT_ACTIVE_MODE;
1125    }else if(enabled){ /* 1 */
1126        if(priv->reg.operation_mode == MODE_INFRASTRUCTURE)
1127             priv->reg.powermgt = POWMGT_SAVE1_MODE;
1128         else
1129             return -EINVAL;
1130    }else if(enabled){ /* 2 */
1131        if(priv->reg.operation_mode == MODE_INFRASTRUCTURE)
1132            priv->reg.powermgt = POWMGT_SAVE2_MODE;
1133        else
1134            return -EINVAL;
1135    }else
1136        return -EINVAL;
1137
1138    hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
1139
1140    return 0;
1141}
1142
1143/*------------------------------------------------------------------*/
1144/* Wireless Handler : get Power Management */
1145static int ks_wlan_get_power(struct net_device *dev, struct iw_request_info *info,
1146                 struct iw_param *vwrq, char *extra)
1147{
1148    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1149
1150    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1151
1152    if(priv->reg.powermgt > 0)
1153        vwrq->disabled = 0;
1154    else
1155        vwrq->disabled = 1;
1156
1157    return 0;
1158}
1159
1160/*------------------------------------------------------------------*/
1161/* Wireless Handler : get wirless statistics */
1162static int ks_wlan_get_iwstats(struct net_device *dev, struct iw_request_info *info,
1163                 struct iw_quality *vwrq, char *extra)
1164{
1165    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1166
1167    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1168
1169    vwrq->qual = 0; /* not supported */
1170    vwrq->level = priv->wstats.qual.level;
1171    vwrq->noise = 0; /* not supported */
1172    vwrq->updated = 0;
1173
1174    return 0;
1175}
1176
1177#ifndef KSC_OPNOTSUPP
1178/*------------------------------------------------------------------*/
1179/* Wireless Handler : set Sensitivity */
1180static int ks_wlan_set_sens(struct net_device *dev, struct iw_request_info *info,
1181                struct iw_param *vwrq, char *extra)
1182{
1183    return -EOPNOTSUPP; /* Not Support */
1184}
1185
1186/*------------------------------------------------------------------*/
1187/* Wireless Handler : get Sensitivity */
1188static int ks_wlan_get_sens(struct net_device *dev, struct iw_request_info *info,
1189                struct iw_param *vwrq, char *extra)
1190{
1191    /* Not Support */
1192    vwrq->value = 0;
1193    vwrq->disabled = (vwrq->value == 0);
1194    vwrq->fixed = 1;
1195    return 0;
1196}
1197#endif /* KSC_OPNOTSUPP */
1198
1199
1200/*------------------------------------------------------------------*/
1201/* Wireless Handler : get AP List */
1202/* Note : this is deprecated in favor of IWSCAN */
1203static int ks_wlan_get_aplist(struct net_device *dev, struct iw_request_info *info,
1204                  struct iw_point *dwrq, char *extra)
1205{
1206    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1207    struct sockaddr *address = (struct sockaddr *) extra;
1208    struct iw_quality qual[LOCAL_APLIST_MAX];
1209
1210    int i;
1211
1212    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1213
1214    for (i = 0; i < priv->aplist.size; i++) {
1215        memcpy(address[i].sa_data, &(priv->aplist.ap[i].bssid[0]), ETH_ALEN);
1216        address[i].sa_family = ARPHRD_ETHER;
1217        qual[i].level = 256 - priv->aplist.ap[i].rssi;
1218        qual[i].qual = priv->aplist.ap[i].sq;
1219        qual[i].noise = 0; /* invalid noise value */
1220        qual[i].updated = 7;
1221    }
1222    if (i){
1223        dwrq->flags = 1; /* Should be define'd */
1224        memcpy(extra + sizeof(struct sockaddr)*i,
1225               &qual, sizeof(struct iw_quality)*i);
1226    }
1227    dwrq->length = i;
1228
1229    return 0;
1230}
1231
1232#if defined(WIRELESS_EXT)
1233/*------------------------------------------------------------------*/
1234/* Wireless Handler : Initiate Scan */
1235static int ks_wlan_set_scan(struct net_device *dev, struct iw_request_info *info,
1236                union iwreq_data *wrqu, char *extra)
1237{
1238    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1239    struct iw_scan_req *req = NULL;
1240    DPRINTK(2,"\n");
1241
1242    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1243
1244    /* specified SSID SCAN */
1245    if(wrqu->data.length == sizeof(struct iw_scan_req) && wrqu->data.flags & IW_SCAN_THIS_ESSID){
1246        req = (struct iw_scan_req *) extra;
1247        priv->scan_ssid_len = req->essid_len;
1248        memcpy(priv->scan_ssid, req->essid, priv->scan_ssid_len);
1249    }else{
1250        priv->scan_ssid_len = 0;
1251    }
1252
1253
1254    priv->sme_i.sme_flag |= SME_AP_SCAN;
1255    hostif_sme_enqueue(priv, SME_BSS_SCAN_REQUEST);
1256
1257    /* At this point, just return to the user. */
1258
1259    return 0;
1260}
1261
1262/*------------------------------------------------------------------*/
1263/*
1264 * Translate scan data returned from the card to a card independent
1265 * format that the Wireless Tools will understand - Jean II
1266 */
1267static inline char *ks_wlan_translate_scan(struct net_device *dev, struct iw_request_info *info, char *current_ev,
1268                       char *end_buf, struct local_ap_t *ap)
1269{
1270    /* ks_wlan_private *priv = (ks_wlan_private *)dev->priv; */
1271    struct iw_event iwe; /* Temporary buffer */
1272    u16 capabilities;
1273    char *current_val; /* For rates */
1274    int i;
1275    static const char rsn_leader[] = "rsn_ie=";
1276    static const char wpa_leader[] = "wpa_ie=";
1277    char buf0[RSN_IE_BODY_MAX*2 + 30];
1278    char buf1[RSN_IE_BODY_MAX*2 + 30];
1279    char *pbuf;
1280    /* First entry *MUST* be the AP MAC address */
1281    iwe.cmd = SIOCGIWAP;
1282    iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1283    memcpy(iwe.u.ap_addr.sa_data, ap->bssid, ETH_ALEN);
1284    current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
1285
1286    /* Other entries will be displayed in the order we give them */
1287
1288    /* Add the ESSID */
1289    iwe.u.data.length = ap->ssid.size;
1290    if(iwe.u.data.length > 32)
1291        iwe.u.data.length = 32;
1292    iwe.cmd = SIOCGIWESSID;
1293    iwe.u.data.flags = 1;
1294    current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, &(ap->ssid.body[0]));
1295
1296    /* Add mode */
1297    iwe.cmd = SIOCGIWMODE;
1298    capabilities = le16_to_cpu(ap->capability);
1299    if(capabilities & (BSS_CAP_ESS | BSS_CAP_IBSS)) {
1300        if(capabilities & BSS_CAP_ESS)
1301            iwe.u.mode = IW_MODE_INFRA;
1302        else
1303            iwe.u.mode = IW_MODE_ADHOC;
1304        current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
1305    }
1306
1307    /* Add frequency */
1308    iwe.cmd = SIOCGIWFREQ;
1309    iwe.u.freq.m = ap->channel;
1310    iwe.u.freq.m = frequency_list[iwe.u.freq.m-1] * 100000;
1311    iwe.u.freq.e = 1;
1312    current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
1313
1314    /* Add quality statistics */
1315    iwe.cmd = IWEVQUAL;
1316    iwe.u.qual.level = 256 - ap->rssi;
1317    iwe.u.qual.qual = ap->sq;
1318    iwe.u.qual.noise = 0; /* invalid noise value */
1319    current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
1320
1321    /* Add encryption capability */
1322    iwe.cmd = SIOCGIWENCODE;
1323    if(capabilities & BSS_CAP_PRIVACY)
1324        iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1325    else
1326        iwe.u.data.flags = IW_ENCODE_DISABLED;
1327    iwe.u.data.length = 0;
1328    current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, &(ap->ssid.body[0]));
1329
1330    /* Rate : stuffing multiple values in a single event require a bit
1331     * more of magic - Jean II */
1332    current_val = current_ev + IW_EV_LCP_LEN;
1333
1334    iwe.cmd = SIOCGIWRATE;
1335    /* Those two flags are ignored... */
1336    iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
1337
1338    /* Max 16 values */
1339    for(i = 0 ; i < 16 ; i++) {
1340        /* NULL terminated */
1341        if(i >= ap->rate_set.size)
1342            break;
1343        /* Bit rate given in 500 kb/s units (+ 0x80) */
1344        iwe.u.bitrate.value = ((ap->rate_set.body[i] & 0x7f) * 500000);
1345        /* Add new value to event */
1346        current_val = iwe_stream_add_value(info, current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
1347    }
1348    /* Check if we added any event */
1349    if((current_val - current_ev) > IW_EV_LCP_LEN)
1350        current_ev = current_val;
1351
1352#define GENERIC_INFO_ELEM_ID 0xdd
1353#define RSN_INFO_ELEM_ID 0x30
1354        if (ap->rsn_ie.id == RSN_INFO_ELEM_ID && ap->rsn_ie.size != 0) {
1355            pbuf = &buf0[0];
1356            memset(&iwe, 0, sizeof(iwe));
1357            iwe.cmd = IWEVCUSTOM;
1358            memcpy(buf0,rsn_leader,sizeof(rsn_leader)-1);
1359            iwe.u.data.length += sizeof(rsn_leader)-1;
1360            pbuf += sizeof(rsn_leader)-1;
1361
1362            pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.id);
1363            pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.size);
1364            iwe.u.data.length += 4;
1365
1366            for (i = 0; i < ap->rsn_ie.size; i++)
1367                pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.body[i]);
1368            iwe.u.data.length += (ap->rsn_ie.size)*2;
1369
1370            DPRINTK(4,"ap->rsn.size=%d\n",ap->rsn_ie.size);
1371
1372            current_ev = iwe_stream_add_point(info, current_ev, end_buf,&iwe, &buf0[0]);
1373        }
1374        if (ap->wpa_ie.id == GENERIC_INFO_ELEM_ID && ap->wpa_ie.size != 0) {
1375            pbuf = &buf1[0];
1376            memset(&iwe, 0, sizeof(iwe));
1377            iwe.cmd = IWEVCUSTOM;
1378            memcpy(buf1,wpa_leader,sizeof(wpa_leader)-1);
1379            iwe.u.data.length += sizeof(wpa_leader)-1;
1380            pbuf += sizeof(wpa_leader)-1;
1381
1382            pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.id);
1383            pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.size);
1384            iwe.u.data.length += 4;
1385
1386            for (i = 0; i < ap->wpa_ie.size; i++)
1387                pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.body[i]);
1388            iwe.u.data.length += (ap->wpa_ie.size)*2;
1389
1390            DPRINTK(4,"ap->rsn.size=%d\n",ap->wpa_ie.size);
1391            DPRINTK(4,"iwe.u.data.length=%d\n",iwe.u.data.length);
1392
1393            current_ev = iwe_stream_add_point(info, current_ev, end_buf,&iwe, &buf1[0]);
1394        }
1395
1396    /* The other data in the scan result are not really
1397     * interesting, so for now drop it - Jean II */
1398    return current_ev;
1399}
1400
1401/*------------------------------------------------------------------*/
1402/* Wireless Handler : Read Scan Results */
1403static int ks_wlan_get_scan(struct net_device *dev, struct iw_request_info *info,
1404                struct iw_point *dwrq, char *extra)
1405{
1406    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1407    int i;
1408    char *current_ev = extra;
1409    DPRINTK(2,"\n");
1410
1411    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1412
1413    if(priv->sme_i.sme_flag & SME_AP_SCAN) {
1414DPRINTK(2,"flag AP_SCAN\n");
1415        return -EAGAIN;
1416    }
1417
1418    if(priv->aplist.size == 0) {
1419        /* Client error, no scan results...
1420         * The caller need to restart the scan. */
1421DPRINTK(2,"aplist 0\n");
1422        return -ENODATA;
1423    }
1424#if 0
1425    /* current connect ap */
1426    if((priv->connect_status & CONNECT_STATUS_MASK)== CONNECT_STATUS){
1427        if ((extra + dwrq->length) - current_ev <= IW_EV_ADDR_LEN) {
1428            dwrq->length = 0;
1429            return -E2BIG;
1430        }
1431        current_ev = ks_wlan_translate_scan(dev, current_ev,
1432// extra + IW_SCAN_MAX_DATA,
1433                            extra + dwrq->length,
1434                            &(priv->current_ap));
1435    }
1436#endif
1437    /* Read and parse all entries */
1438    for(i=0; i < priv->aplist.size; i++) {
1439        if ((extra + dwrq->length) - current_ev <= IW_EV_ADDR_LEN) {
1440            dwrq->length = 0;
1441            return -E2BIG;
1442        }
1443        /* Translate to WE format this entry */
1444        current_ev = ks_wlan_translate_scan(dev, info, current_ev,
1445// extra + IW_SCAN_MAX_DATA,
1446                            extra + dwrq->length,
1447                            &(priv->aplist.ap[i]));
1448    }
1449    /* Length of data */
1450    dwrq->length = (current_ev - extra);
1451    dwrq->flags = 0;
1452
1453    return 0;
1454}
1455#endif /* WIRELESS_EXT */
1456
1457/*------------------------------------------------------------------*/
1458/* Commit handler : called after a bunch of SET operations */
1459static int ks_wlan_config_commit(struct net_device *dev, struct iw_request_info *info,
1460                 void *zwrq, char *extra)
1461{
1462    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1463
1464    if (!priv->need_commit)
1465        return 0;
1466
1467    ks_wlan_setup_parameter(priv, priv->need_commit);
1468    priv->need_commit=0;
1469    return 0;
1470}
1471
1472#ifdef WIRELESS_EXT
1473/*------------------------------------------------------------------*/
1474/* Wireless handler : set association ie params */
1475static int ks_wlan_set_genie(struct net_device *dev, struct iw_request_info *info,
1476                 struct iw_point *dwrq, char *extra)
1477{
1478    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1479
1480    DPRINTK(2, "\n");
1481
1482    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1483
1484    return 0;
1485// return -EOPNOTSUPP;
1486}
1487
1488/*------------------------------------------------------------------*/
1489/* Wireless handler : set authentication mode params */
1490static int ks_wlan_set_auth_mode(struct net_device *dev, struct iw_request_info *info,
1491                 struct iw_param *vwrq, char *extra)
1492{
1493    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1494    int index = (vwrq->flags & IW_AUTH_INDEX);
1495    int value = vwrq->value;
1496
1497    DPRINTK(2,"index=%d:value=%08X\n",index,value);
1498
1499    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1500
1501    switch(index){
1502    case IW_AUTH_WPA_VERSION: /* 0 */
1503        switch(value){
1504        case IW_AUTH_WPA_VERSION_DISABLED:
1505            priv->wpa.version = value;
1506            if(priv->wpa.rsn_enabled){
1507                priv->wpa.rsn_enabled = 0;
1508            }
1509            priv->need_commit |= SME_RSN;
1510            break;
1511        case IW_AUTH_WPA_VERSION_WPA:
1512        case IW_AUTH_WPA_VERSION_WPA2:
1513            priv->wpa.version = value;
1514            if(!(priv->wpa.rsn_enabled)){
1515                priv->wpa.rsn_enabled = 1;
1516            }
1517            priv->need_commit |= SME_RSN;
1518            break;
1519        default:
1520            return -EOPNOTSUPP;
1521        }
1522        break;
1523    case IW_AUTH_CIPHER_PAIRWISE: /* 1 */
1524        switch(value){
1525        case IW_AUTH_CIPHER_NONE:
1526            if(priv->reg.privacy_invoked){
1527                priv->reg.privacy_invoked = 0x00;
1528                priv->need_commit |= SME_WEP_FLAG;
1529            }
1530            break;
1531        case IW_AUTH_CIPHER_WEP40:
1532        case IW_AUTH_CIPHER_TKIP:
1533        case IW_AUTH_CIPHER_CCMP:
1534        case IW_AUTH_CIPHER_WEP104:
1535            if(!priv->reg.privacy_invoked){
1536                priv->reg.privacy_invoked = 0x01;
1537                priv->need_commit |= SME_WEP_FLAG;
1538            }
1539            priv->wpa.pairwise_suite = value;
1540            priv->need_commit |= SME_RSN_UNICAST;
1541            break;
1542        default:
1543            return -EOPNOTSUPP;
1544        }
1545        break;
1546    case IW_AUTH_CIPHER_GROUP: /* 2 */
1547        switch(value){
1548        case IW_AUTH_CIPHER_NONE:
1549            if(priv->reg.privacy_invoked){
1550                priv->reg.privacy_invoked = 0x00;
1551                priv->need_commit |= SME_WEP_FLAG;
1552            }
1553            break;
1554        case IW_AUTH_CIPHER_WEP40:
1555        case IW_AUTH_CIPHER_TKIP:
1556        case IW_AUTH_CIPHER_CCMP:
1557        case IW_AUTH_CIPHER_WEP104:
1558            if(!priv->reg.privacy_invoked){
1559                priv->reg.privacy_invoked = 0x01;
1560                priv->need_commit |= SME_WEP_FLAG;
1561            }
1562            priv->wpa.group_suite = value;
1563            priv->need_commit |= SME_RSN_MULTICAST;
1564            break;
1565        default:
1566            return -EOPNOTSUPP;
1567        }
1568        break;
1569    case IW_AUTH_KEY_MGMT: /* 3 */
1570        switch(value){
1571        case IW_AUTH_KEY_MGMT_802_1X:
1572        case IW_AUTH_KEY_MGMT_PSK:
1573        case 0: /* NONE or 802_1X_NO_WPA */
1574        case 4: /* WPA_NONE */
1575            priv->wpa.key_mgmt_suite = value;
1576            priv->need_commit |= SME_RSN_AUTH;
1577            break;
1578        default:
1579            return -EOPNOTSUPP;
1580        }
1581        break;
1582    case IW_AUTH_80211_AUTH_ALG: /* 6 */
1583        switch(value){
1584        case IW_AUTH_ALG_OPEN_SYSTEM:
1585            priv->wpa.auth_alg = value;
1586            priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
1587            break;
1588        case IW_AUTH_ALG_SHARED_KEY:
1589            priv->wpa.auth_alg = value;
1590            priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
1591            break;
1592        case IW_AUTH_ALG_LEAP:
1593        default:
1594            return -EOPNOTSUPP;
1595        }
1596        priv->need_commit |= SME_MODE_SET;
1597        break;
1598    case IW_AUTH_WPA_ENABLED: /* 7 */
1599        priv->wpa.wpa_enabled = value;
1600        break;
1601    case IW_AUTH_PRIVACY_INVOKED: /* 10 */
1602        if((value && !priv->reg.privacy_invoked)||
1603           (!value && priv->reg.privacy_invoked)){
1604            priv->reg.privacy_invoked = value?0x01:0x00;
1605            priv->need_commit |= SME_WEP_FLAG;
1606        }
1607        break;
1608    case IW_AUTH_RX_UNENCRYPTED_EAPOL: /* 4 */
1609    case IW_AUTH_TKIP_COUNTERMEASURES: /* 5 */
1610    case IW_AUTH_DROP_UNENCRYPTED: /* 8 */
1611    case IW_AUTH_ROAMING_CONTROL: /* 9 */
1612    default:
1613        break;
1614    }
1615
1616    /* return -EINPROGRESS; */
1617    if(priv->need_commit){
1618        ks_wlan_setup_parameter(priv, priv->need_commit);
1619        priv->need_commit=0;
1620    }
1621    return 0;
1622}
1623
1624/*------------------------------------------------------------------*/
1625/* Wireless handler : get authentication mode params */
1626static int ks_wlan_get_auth_mode(struct net_device *dev, struct iw_request_info *info,
1627                 struct iw_param *vwrq, char *extra)
1628{
1629    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1630    int index = (vwrq->flags & IW_AUTH_INDEX);
1631    DPRINTK(2,"index=%d\n",index);
1632
1633    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1634
1635    /* WPA (not used ?? wpa_supplicant) */
1636    switch(index){
1637    case IW_AUTH_WPA_VERSION:
1638        vwrq->value = priv->wpa.version;
1639        break;
1640    case IW_AUTH_CIPHER_PAIRWISE:
1641        vwrq->value = priv->wpa.pairwise_suite;
1642        break;
1643    case IW_AUTH_CIPHER_GROUP:
1644        vwrq->value = priv->wpa.group_suite;
1645        break;
1646    case IW_AUTH_KEY_MGMT:
1647        vwrq->value = priv->wpa.key_mgmt_suite;
1648        break;
1649    case IW_AUTH_80211_AUTH_ALG:
1650        vwrq->value = priv->wpa.auth_alg;
1651        break;
1652    case IW_AUTH_WPA_ENABLED:
1653        vwrq->value = priv->wpa.rsn_enabled;
1654        break;
1655    case IW_AUTH_RX_UNENCRYPTED_EAPOL: /* OK??? */
1656    case IW_AUTH_TKIP_COUNTERMEASURES:
1657    case IW_AUTH_DROP_UNENCRYPTED:
1658    default:
1659        /* return -EOPNOTSUPP; */
1660        break;
1661    }
1662    return 0;
1663}
1664
1665/*------------------------------------------------------------------*/
1666/* Wireless Handler : set encoding token & mode (WPA)*/
1667static int ks_wlan_set_encode_ext(struct net_device *dev, struct iw_request_info *info,
1668                  struct iw_point *dwrq, char *extra)
1669{
1670    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1671    struct iw_encode_ext *enc;
1672    int index = dwrq->flags & IW_ENCODE_INDEX;
1673    unsigned int commit=0;
1674
1675    enc = (struct iw_encode_ext *)extra;
1676
1677    DPRINTK(2,"flags=%04X:: ext_flags=%08X\n",dwrq->flags, enc->ext_flags);
1678
1679    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1680
1681    if(index<1||index>4)
1682        return -EINVAL;
1683    else
1684        index--;
1685
1686    if(dwrq->flags & IW_ENCODE_DISABLED){
1687        priv->wpa.key[index].key_len=0;
1688    }
1689
1690    if(enc){
1691        priv->wpa.key[index].ext_flags=enc->ext_flags;
1692        if(enc->ext_flags&IW_ENCODE_EXT_SET_TX_KEY){
1693            priv->wpa.txkey=index;
1694            commit |= SME_WEP_INDEX;
1695        }else if(enc->ext_flags&IW_ENCODE_EXT_RX_SEQ_VALID){
1696            if(enc->rx_seq)
1697                memcpy(&priv->wpa.key[index].rx_seq[0],
1698                       enc->rx_seq, IW_ENCODE_SEQ_MAX_SIZE);
1699            else
1700                return -EINVAL;
1701        }
1702
1703        memcpy(&priv->wpa.key[index].addr.sa_data[0],
1704               &enc->addr.sa_data[0], ETH_ALEN);
1705
1706        switch (enc->alg) {
1707        case IW_ENCODE_ALG_NONE:
1708            if(priv->reg.privacy_invoked){
1709                priv->reg.privacy_invoked = 0x00;
1710                commit |= SME_WEP_FLAG;
1711            }
1712            priv->wpa.key[index].key_len = 0;
1713
1714            break;
1715        case IW_ENCODE_ALG_WEP:
1716        case IW_ENCODE_ALG_CCMP:
1717            if(!priv->reg.privacy_invoked){
1718                priv->reg.privacy_invoked = 0x01;
1719                commit |= SME_WEP_FLAG;
1720            }
1721            if(enc->key && enc->key_len){
1722                memcpy(&priv->wpa.key[index].key_val[0],
1723                       &enc->key[0], enc->key_len);
1724                priv->wpa.key[index].key_len = enc->key_len;
1725                commit |= (SME_WEP_VAL1 << index);
1726            }
1727            break;
1728        case IW_ENCODE_ALG_TKIP:
1729            if(!priv->reg.privacy_invoked){
1730                priv->reg.privacy_invoked = 0x01;
1731                commit |= SME_WEP_FLAG;
1732            }
1733            if(enc->key && enc->key_len == 32){
1734                memcpy(&priv->wpa.key[index].key_val[0],
1735                       &enc->key[0], enc->key_len-16);
1736                priv->wpa.key[index].key_len = enc->key_len-16;
1737                if(priv->wpa.key_mgmt_suite==4){ /* WPA_NONE */
1738                    memcpy(&priv->wpa.key[index].tx_mic_key[0],
1739                           &enc->key[16],8);
1740                    memcpy(&priv->wpa.key[index].rx_mic_key[0],
1741                           &enc->key[16],8);
1742                }else{
1743                    memcpy(&priv->wpa.key[index].tx_mic_key[0],
1744                           &enc->key[16],8);
1745                    memcpy(&priv->wpa.key[index].rx_mic_key[0],
1746                           &enc->key[24],8);
1747                }
1748                commit |= (SME_WEP_VAL1 << index);
1749            }
1750            break;
1751        default:
1752            return -EINVAL;
1753        }
1754        priv->wpa.key[index].alg=enc->alg;
1755    }
1756    else
1757        return -EINVAL;
1758
1759    if(commit){
1760        if(commit&SME_WEP_INDEX)
1761            hostif_sme_enqueue(priv, SME_SET_TXKEY);
1762        if(commit&SME_WEP_VAL_MASK)
1763            hostif_sme_enqueue(priv, SME_SET_KEY1+index);
1764        if(commit&SME_WEP_FLAG)
1765            hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
1766    }
1767
1768    return 0;
1769}
1770
1771/*------------------------------------------------------------------*/
1772/* Wireless Handler : get encoding token & mode (WPA)*/
1773static int ks_wlan_get_encode_ext(struct net_device *dev, struct iw_request_info *info,
1774                  struct iw_point *dwrq, char *extra)
1775{
1776    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1777
1778    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1779
1780    /* WPA (not used ?? wpa_supplicant)
1781    ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
1782    struct iw_encode_ext *enc;
1783    enc = (struct iw_encode_ext *)extra;
1784    int index = dwrq->flags & IW_ENCODE_INDEX;
1785     WPA (not used ?? wpa_supplicant) */
1786    return 0;
1787}
1788
1789/*------------------------------------------------------------------*/
1790/* Wireless Handler : PMKSA cache operation (WPA2) */
1791static int ks_wlan_set_pmksa(struct net_device *dev, struct iw_request_info *info,
1792                 struct iw_point *dwrq, char *extra)
1793{
1794    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1795    struct iw_pmksa *pmksa ;
1796    int i;
1797    struct pmk_t *pmk;
1798    struct list_head *ptr;
1799
1800    DPRINTK(2,"\n");
1801
1802    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1803
1804    if(!extra){
1805        return -EINVAL;
1806    }
1807    pmksa = (struct iw_pmksa *)extra;
1808    DPRINTK(2,"cmd=%d\n",pmksa->cmd);
1809
1810    switch(pmksa->cmd){
1811    case IW_PMKSA_ADD:
1812        if(list_empty(&priv->pmklist.head)){ /* new list */
1813            for(i=0;i<PMK_LIST_MAX;i++){
1814                pmk = &priv->pmklist.pmk[i];
1815                if(!memcmp("\x00\x00\x00\x00\x00\x00",pmk->bssid,ETH_ALEN))
1816                    break;
1817            }
1818            memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
1819            memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1820            list_add(&pmk->list,&priv->pmklist.head);
1821            priv->pmklist.size++;
1822        }
1823        else { /* search cache data */
1824            list_for_each(ptr, &priv->pmklist.head){
1825                pmk = list_entry(ptr, struct pmk_t, list);
1826                if(!memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN)){ /* match address! list move to head. */
1827                    memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1828                    list_move(&pmk->list, &priv->pmklist.head);
1829                    break;
1830                }
1831            }
1832            if(ptr == &priv->pmklist.head){ /* not find address. */
1833                if(PMK_LIST_MAX > priv->pmklist.size){ /* new cache data */
1834                    for(i=0;i<PMK_LIST_MAX;i++){
1835                        pmk = &priv->pmklist.pmk[i];
1836                        if(!memcmp("\x00\x00\x00\x00\x00\x00",pmk->bssid,ETH_ALEN))
1837                            break;
1838                    }
1839                    memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
1840                    memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1841                    list_add(&pmk->list,&priv->pmklist.head);
1842                    priv->pmklist.size++;
1843                }
1844                else{ /* overwrite old cache data */
1845                    pmk = list_entry(priv->pmklist.head.prev, struct pmk_t, list);
1846                    memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
1847                    memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1848                    list_move(&pmk->list,&priv->pmklist.head);
1849                }
1850            }
1851        }
1852        break;
1853    case IW_PMKSA_REMOVE:
1854        if(list_empty(&priv->pmklist.head)){ /* list empty */
1855            return -EINVAL;
1856        }
1857        else{ /* search cache data */
1858            list_for_each(ptr, &priv->pmklist.head){
1859                pmk = list_entry(ptr, struct pmk_t, list);
1860                if(!memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN)){ /* match address! list del. */
1861                    memset(pmk->bssid, 0, ETH_ALEN);
1862                    memset(pmk->pmkid, 0, IW_PMKID_LEN);
1863                    list_del_init(&pmk->list);
1864                    break;
1865                }
1866            }
1867            if(ptr == &priv->pmklist.head){ /* not find address. */
1868                return 0;
1869            }
1870        }
1871        break;
1872    case IW_PMKSA_FLUSH:
1873        memset(&(priv->pmklist), 0, sizeof(priv->pmklist));
1874        INIT_LIST_HEAD(&priv->pmklist.head);
1875        for(i=0;i<PMK_LIST_MAX;i++)
1876            INIT_LIST_HEAD(&priv->pmklist.pmk[i].list);
1877        break;
1878    default:
1879        return -EINVAL;
1880    }
1881
1882    hostif_sme_enqueue(priv, SME_SET_PMKSA);
1883    return 0;
1884}
1885
1886static struct iw_statistics *ks_get_wireless_stats(struct net_device *dev)
1887{
1888
1889    ks_wlan_private *priv = (ks_wlan_private *) netdev_priv(dev);
1890        struct iw_statistics *wstats = &priv->wstats;
1891
1892    if(!atomic_read(&update_phyinfo)){
1893        if (priv->dev_state < DEVICE_STATE_READY)
1894            return NULL; /* not finished initialize */
1895        else
1896            return wstats;
1897    }
1898
1899    /* Packets discarded in the wireless adapter due to wireless
1900     * specific problems */
1901    wstats->discard.nwid = 0; /* Rx invalid nwid */
1902    wstats->discard.code = 0; /* Rx invalid crypt */
1903    wstats->discard.fragment = 0; /* Rx invalid frag */
1904    wstats->discard.retries = 0; /* Tx excessive retries */
1905    wstats->discard.misc = 0; /* Invalid misc */
1906    wstats->miss.beacon = 0; /* Missed beacon */
1907
1908        return wstats;
1909}
1910
1911/*------------------------------------------------------------------*/
1912/* Private handler : set stop request */
1913static int ks_wlan_set_stop_request(struct net_device *dev, struct iw_request_info *info,
1914                    __u32 *uwrq, char *extra)
1915{
1916    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1917    DPRINTK(2,"\n");
1918
1919    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1920
1921    if(!(*uwrq))
1922        return -EINVAL;
1923
1924    hostif_sme_enqueue(priv, SME_STOP_REQUEST);
1925    return 0;
1926}
1927
1928/*------------------------------------------------------------------*/
1929/* Wireless Handler : set MLME */
1930#include <linux/ieee80211.h>
1931static int ks_wlan_set_mlme(struct net_device *dev, struct iw_request_info *info,
1932                  struct iw_point *dwrq, char *extra)
1933{
1934    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1935    struct iw_mlme *mlme = (struct iw_mlme *)extra;
1936    __u32 mode;
1937
1938    DPRINTK(2, ":%d :%d\n", mlme->cmd, mlme->reason_code);
1939
1940    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1941
1942    switch (mlme->cmd) {
1943    case IW_MLME_DEAUTH:
1944        if (mlme->reason_code == WLAN_REASON_MIC_FAILURE) {
1945            return 0;
1946        }
1947    case IW_MLME_DISASSOC:
1948        mode = 1;
1949        return ks_wlan_set_stop_request(dev, NULL, &mode, NULL);
1950    default:
1951        return -EOPNOTSUPP; /* Not Support */
1952    }
1953}
1954#endif /* WIRELESS_EXT */
1955
1956/*------------------------------------------------------------------*/
1957/* Private handler : get driver version */
1958static int ks_wlan_get_driver_version(struct net_device *dev, struct iw_request_info *info,
1959                      struct iw_point *dwrq, char *extra)
1960{
1961    strcpy(extra, KS_WLAN_DRIVER_VERSION_INFO);
1962    dwrq->length = strlen(KS_WLAN_DRIVER_VERSION_INFO)+1;
1963    return 0;
1964}
1965
1966/*------------------------------------------------------------------*/
1967/* Private handler : get firemware version */
1968static int ks_wlan_get_firmware_version(struct net_device *dev, struct iw_request_info *info,
1969                    struct iw_point *dwrq, char *extra)
1970{
1971    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1972    strcpy(extra, &(priv->firmware_version[0]));
1973    dwrq->length = priv->version_size+1;
1974    return 0;
1975}
1976
1977#if 0
1978/*------------------------------------------------------------------*/
1979/* Private handler : set force disconnect status */
1980static int ks_wlan_set_detach(struct net_device *dev, struct iw_request_info *info,
1981                  __u32 *uwrq, char *extra)
1982{
1983    ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
1984
1985    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1986
1987    if(*uwrq == CONNECT_STATUS){ /* 0 */
1988        priv->connect_status &= ~FORCE_DISCONNECT;
1989        if((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS)
1990            netif_carrier_on(dev);
1991    }else if(*uwrq == DISCONNECT_STATUS){ /* 1 */
1992        priv->connect_status |= FORCE_DISCONNECT;
1993        netif_carrier_off(dev);
1994    }else
1995        return -EINVAL;
1996    return 0;
1997}
1998
1999/*------------------------------------------------------------------*/
2000/* Private handler : get force disconnect status */
2001static int ks_wlan_get_detach(struct net_device *dev, struct iw_request_info *info,
2002                  __u32 *uwrq, char *extra)
2003{
2004    ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2005
2006    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2007
2008    *uwrq = ((priv->connect_status & FORCE_DISCONNECT) ? 1 : 0 );
2009    return 0;
2010}
2011
2012/*------------------------------------------------------------------*/
2013/* Private handler : get connect status */
2014static int ks_wlan_get_connect(struct net_device *dev, struct iw_request_info *info,
2015                   __u32 *uwrq, char *extra)
2016{
2017    ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2018
2019    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2020
2021    *uwrq = (priv->connect_status & CONNECT_STATUS_MASK);
2022    return 0;
2023}
2024#endif
2025
2026/*------------------------------------------------------------------*/
2027/* Private handler : set preamble */
2028static int ks_wlan_set_preamble(struct net_device *dev, struct iw_request_info *info,
2029                __u32 *uwrq, char *extra)
2030{
2031    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2032
2033    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2034
2035    if(*uwrq == LONG_PREAMBLE){ /* 0 */
2036        priv->reg.preamble = LONG_PREAMBLE;
2037    }else if(*uwrq == SHORT_PREAMBLE){ /* 1 */
2038        priv->reg.preamble = SHORT_PREAMBLE;
2039    }else
2040        return -EINVAL;
2041
2042    priv->need_commit |= SME_MODE_SET;
2043    return -EINPROGRESS; /* Call commit handler */
2044
2045}
2046
2047/*------------------------------------------------------------------*/
2048/* Private handler : get preamble */
2049static int ks_wlan_get_preamble(struct net_device *dev, struct iw_request_info *info,
2050                __u32 *uwrq, char *extra)
2051{
2052    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2053
2054    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2055
2056    *uwrq = priv->reg.preamble;
2057    return 0;
2058}
2059
2060/*------------------------------------------------------------------*/
2061/* Private handler : set power save mode */
2062static int ks_wlan_set_powermgt(struct net_device *dev, struct iw_request_info *info,
2063                __u32 *uwrq, char *extra)
2064{
2065    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2066
2067    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2068
2069    if(*uwrq == POWMGT_ACTIVE_MODE){ /* 0 */
2070        priv->reg.powermgt = POWMGT_ACTIVE_MODE;
2071    }else if(*uwrq == POWMGT_SAVE1_MODE){ /* 1 */
2072        if(priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2073             priv->reg.powermgt = POWMGT_SAVE1_MODE;
2074         else
2075             return -EINVAL;
2076    }else if(*uwrq == POWMGT_SAVE2_MODE){ /* 2 */
2077        if(priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2078            priv->reg.powermgt = POWMGT_SAVE2_MODE;
2079        else
2080            return -EINVAL;
2081    }else
2082        return -EINVAL;
2083
2084    hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
2085
2086    return 0;
2087}
2088
2089/*------------------------------------------------------------------*/
2090/* Private handler : get power save made */
2091static int ks_wlan_get_powermgt(struct net_device *dev, struct iw_request_info *info,
2092                __u32 *uwrq, char *extra)
2093{
2094    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2095
2096    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2097
2098    *uwrq = priv->reg.powermgt;
2099    return 0;
2100}
2101
2102/*------------------------------------------------------------------*/
2103/* Private handler : set scan type */
2104static int ks_wlan_set_scan_type(struct net_device *dev, struct iw_request_info *info,
2105                 __u32 *uwrq, char *extra)
2106{
2107    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2108
2109    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2110
2111    if(*uwrq == ACTIVE_SCAN){ /* 0 */
2112        priv->reg.scan_type = ACTIVE_SCAN;
2113    }else if(*uwrq == PASSIVE_SCAN){ /* 1 */
2114        priv->reg.scan_type = PASSIVE_SCAN;
2115    }else
2116        return -EINVAL;
2117
2118    return 0;
2119}
2120
2121/*------------------------------------------------------------------*/
2122/* Private handler : get scan type */
2123static int ks_wlan_get_scan_type(struct net_device *dev, struct iw_request_info *info,
2124                 __u32 *uwrq, char *extra)
2125{
2126    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2127
2128    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2129
2130    *uwrq = priv->reg.scan_type;
2131    return 0;
2132}
2133#if 0
2134/*------------------------------------------------------------------*/
2135/* Private handler : write raw data to device */
2136static int ks_wlan_data_write(struct net_device *dev, struct iw_request_info *info,
2137                  struct iw_point *dwrq, char *extra)
2138{
2139    ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2140    unsigned char *wbuff = NULL;
2141
2142    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2143
2144    wbuff = (unsigned char *)kmalloc(dwrq->length, GFP_ATOMIC);
2145    if(!wbuff)
2146            return -EFAULT;
2147    memcpy(wbuff, extra, dwrq->length);
2148
2149    /* write to device */
2150    ks_wlan_hw_tx( priv, wbuff, dwrq->length, NULL, NULL, NULL);
2151
2152    return 0;
2153}
2154
2155/*------------------------------------------------------------------*/
2156/* Private handler : read raw data form device */
2157static int ks_wlan_data_read(struct net_device *dev, struct iw_request_info *info,
2158                 struct iw_point *dwrq, char *extra)
2159{
2160    ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2161    unsigned short read_length;
2162
2163    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2164
2165    if(!atomic_read(&priv->event_count)){
2166        if (priv->dev_state < DEVICE_STATE_BOOT) { /* Remove device */
2167                read_length = 4;
2168            memset(extra,0xff,read_length);
2169            dwrq->length = read_length;
2170            return 0;
2171        }
2172        read_length = 0;
2173        memset(extra,0,1);
2174        dwrq->length = 0;
2175        return 0;
2176    }
2177
2178    if(atomic_read(&priv->event_count)>0)
2179            atomic_dec(&priv->event_count);
2180
2181    spin_lock(&priv->dev_read_lock); /* request spin lock */
2182
2183        /* Copy length max size 0x07ff */
2184    if(priv->dev_size[priv->dev_count] > 2047)
2185        read_length = 2047;
2186    else
2187        read_length = priv->dev_size[priv->dev_count];
2188
2189    /* Copy data */
2190    memcpy(extra, &(priv->dev_data[priv->dev_count][0]), read_length);
2191
2192    spin_unlock(&priv->dev_read_lock); /* release spin lock */
2193
2194    /* Initialize */
2195    priv->dev_data[priv->dev_count] = 0;
2196    priv->dev_size[priv->dev_count] = 0;
2197
2198    priv->dev_count++;
2199    if(priv->dev_count == DEVICE_STOCK_COUNT)
2200             priv->dev_count=0;
2201
2202    /* Set read size */
2203    dwrq->length = read_length;
2204
2205    return 0;
2206}
2207#endif
2208
2209#if 0
2210/*------------------------------------------------------------------*/
2211/* Private handler : get wep string */
2212#define WEP_ASCII_BUFF_SIZE (17+64*4+1)
2213static int ks_wlan_get_wep_ascii(struct net_device *dev, struct iw_request_info *info,
2214                 struct iw_point *dwrq, char *extra)
2215{
2216    ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2217    int i,j,len=0;
2218    char tmp[WEP_ASCII_BUFF_SIZE];
2219
2220    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2221
2222    strcpy(tmp," WEP keys ASCII \n");
2223    len+=strlen(" WEP keys ASCII \n");
2224
2225    for(i=0;i<4;i++){
2226        strcpy(tmp+len,"\t[");
2227        len+=strlen("\t[");
2228        tmp[len] = '1'+i;
2229        len++;
2230        strcpy(tmp+len,"] ");
2231        len+=strlen("] ");
2232        if(priv->reg.wep_key[i].size){
2233            strcpy(tmp+len,(priv->reg.wep_key[i].size < 6 ? "(40bits) [" : "(104bits) ["));
2234            len+=strlen((priv->reg.wep_key[i].size < 6 ? "(40bits) [" : "(104bits) ["));
2235            for(j=0;j<priv->reg.wep_key[i].size;j++,len++)
2236                tmp[len]=(isprint(priv->reg.wep_key[i].val[j]) ? priv->reg.wep_key[i].val[j] : ' ');
2237
2238            strcpy(tmp+len,"]\n");
2239            len+=strlen("]\n");
2240        }
2241        else{
2242            strcpy(tmp+len,"off\n");
2243            len+=strlen("off\n");
2244        }
2245    }
2246
2247    memcpy(extra, tmp, len);
2248    dwrq->length = len+1;
2249    return 0;
2250}
2251#endif
2252
2253/*------------------------------------------------------------------*/
2254/* Private handler : set beacon lost count */
2255static int ks_wlan_set_beacon_lost(struct net_device *dev, struct iw_request_info *info,
2256                   __u32 *uwrq, char *extra)
2257{
2258    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2259
2260    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2261
2262    if(*uwrq >= BEACON_LOST_COUNT_MIN &&
2263       *uwrq <= BEACON_LOST_COUNT_MAX){
2264        priv->reg.beacon_lost_count = *uwrq;
2265    }else
2266        return -EINVAL;
2267
2268    if(priv->reg.operation_mode == MODE_INFRASTRUCTURE){
2269        priv->need_commit |= SME_MODE_SET;
2270        return -EINPROGRESS; /* Call commit handler */
2271    }
2272    else
2273        return 0;
2274}
2275
2276/*------------------------------------------------------------------*/
2277/* Private handler : get beacon lost count */
2278static int ks_wlan_get_beacon_lost(struct net_device *dev, struct iw_request_info *info,
2279                   __u32 *uwrq, char *extra)
2280{
2281    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2282
2283    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2284
2285    *uwrq = priv->reg.beacon_lost_count;
2286    return 0;
2287}
2288
2289/*------------------------------------------------------------------*/
2290/* Private handler : set phy type */
2291static int ks_wlan_set_phy_type(struct net_device *dev, struct iw_request_info *info,
2292                __u32 *uwrq, char *extra)
2293{
2294    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2295
2296    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2297
2298    if(*uwrq == D_11B_ONLY_MODE){ /* 0 */
2299        priv->reg.phy_type = D_11B_ONLY_MODE;
2300    }else if(*uwrq == D_11G_ONLY_MODE){ /* 1 */
2301        priv->reg.phy_type = D_11G_ONLY_MODE;
2302    }else if(*uwrq == D_11BG_COMPATIBLE_MODE){ /* 2 */
2303        priv->reg.phy_type = D_11BG_COMPATIBLE_MODE;
2304    }else
2305        return -EINVAL;
2306
2307    priv->need_commit |= SME_MODE_SET;
2308    return -EINPROGRESS; /* Call commit handler */
2309}
2310
2311/*------------------------------------------------------------------*/
2312/* Private handler : get phy type */
2313static int ks_wlan_get_phy_type(struct net_device *dev, struct iw_request_info *info,
2314                __u32 *uwrq, char *extra)
2315{
2316    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2317
2318    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2319
2320    *uwrq = priv->reg.phy_type;
2321    return 0;
2322}
2323
2324/*------------------------------------------------------------------*/
2325/* Private handler : set cts mode */
2326static int ks_wlan_set_cts_mode(struct net_device *dev, struct iw_request_info *info,
2327                __u32 *uwrq, char *extra)
2328{
2329    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2330
2331    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2332
2333    if(*uwrq == CTS_MODE_FALSE){ /* 0 */
2334        priv->reg.cts_mode = CTS_MODE_FALSE;
2335    }else if(*uwrq == CTS_MODE_TRUE){ /* 1 */
2336        if(priv->reg.phy_type == D_11G_ONLY_MODE ||
2337           priv->reg.phy_type == D_11BG_COMPATIBLE_MODE)
2338            priv->reg.cts_mode = CTS_MODE_TRUE;
2339        else
2340            priv->reg.cts_mode = CTS_MODE_FALSE;
2341    }else
2342        return -EINVAL;
2343
2344    priv->need_commit |= SME_MODE_SET;
2345    return -EINPROGRESS; /* Call commit handler */
2346}
2347
2348/*------------------------------------------------------------------*/
2349/* Private handler : get cts mode */
2350static int ks_wlan_get_cts_mode(struct net_device *dev, struct iw_request_info *info,
2351                __u32 *uwrq, char *extra)
2352{
2353    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2354
2355    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2356
2357    *uwrq = priv->reg.cts_mode;
2358    return 0;
2359}
2360
2361/*------------------------------------------------------------------*/
2362/* Private handler : set sleep mode */
2363static int ks_wlan_set_sleep_mode(struct net_device *dev,
2364                     struct iw_request_info *info,
2365                     __u32 *uwrq, char *extra)
2366{
2367    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2368
2369    DPRINTK(2,"\n");
2370
2371    if(*uwrq == SLP_SLEEP){
2372        priv->sleep_mode = *uwrq;
2373        printk("SET_SLEEP_MODE %d\n", priv->sleep_mode);
2374
2375        hostif_sme_enqueue(priv, SME_STOP_REQUEST);
2376        hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2377
2378    }else if(*uwrq == SLP_ACTIVE) {
2379        priv->sleep_mode = *uwrq;
2380        printk("SET_SLEEP_MODE %d\n", priv->sleep_mode);
2381        hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2382    }else{
2383        printk("SET_SLEEP_MODE %d errror\n", *uwrq);
2384        return -EINVAL;
2385    }
2386
2387    return 0;
2388}
2389/*------------------------------------------------------------------*/
2390/* Private handler : get sleep mode */
2391static int ks_wlan_get_sleep_mode(struct net_device *dev,
2392                     struct iw_request_info *info,
2393                     __u32 *uwrq, char *extra)
2394{
2395    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2396
2397    DPRINTK(2, "GET_SLEEP_MODE %d\n", priv->sleep_mode);
2398    *uwrq = priv->sleep_mode;
2399
2400    return 0;
2401}
2402
2403#if 0
2404/*------------------------------------------------------------------*/
2405/* Private handler : set phy information timer */
2406static int ks_wlan_set_phy_information_timer(struct net_device *dev, struct iw_request_info *info,
2407                         __u32 *uwrq, char *extra)
2408{
2409    ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2410
2411    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2412
2413    if(*uwrq >= 0 && *uwrq <= 0xFFFF) /* 0-65535 */
2414        priv->reg.phy_info_timer = (uint16_t)*uwrq;
2415    else
2416        return -EINVAL;
2417
2418    hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST);
2419
2420    return 0;
2421}
2422
2423/*------------------------------------------------------------------*/
2424/* Private handler : get phy information timer */
2425static int ks_wlan_get_phy_information_timer(struct net_device *dev, struct iw_request_info *info,
2426                         __u32 *uwrq, char *extra)
2427{
2428    ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2429
2430    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2431
2432    *uwrq = priv->reg.phy_info_timer;
2433    return 0;
2434}
2435#endif
2436
2437#ifdef WPS
2438/*------------------------------------------------------------------*/
2439/* Private handler : set WPS enable */
2440static int ks_wlan_set_wps_enable(struct net_device *dev, struct iw_request_info *info,
2441                  __u32 *uwrq, char *extra)
2442{
2443    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2444    DPRINTK(2,"\n");
2445
2446    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2447
2448    if(*uwrq == 0 || *uwrq == 1)
2449        priv->wps.wps_enabled = *uwrq;
2450    else
2451        return -EINVAL;
2452
2453    hostif_sme_enqueue(priv, SME_WPS_ENABLE_REQUEST);
2454
2455    return 0;
2456}
2457/*------------------------------------------------------------------*/
2458/* Private handler : get WPS enable */
2459static int ks_wlan_get_wps_enable(struct net_device *dev, struct iw_request_info *info,
2460                  __u32 *uwrq, char *extra)
2461{
2462    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2463    DPRINTK(2,"\n");
2464
2465    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2466
2467    *uwrq = priv->wps.wps_enabled;
2468    printk("return=%d\n", *uwrq);
2469
2470    return 0;
2471}
2472/*------------------------------------------------------------------*/
2473/* Private handler : set WPS probe req */
2474static int ks_wlan_set_wps_probe_req(struct net_device *dev,
2475                     struct iw_request_info *info,
2476                     struct iw_point *dwrq, char *extra)
2477{
2478    uint8_t *p = extra;
2479    unsigned char len;
2480    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2481
2482    DPRINTK(2,"\n");
2483
2484    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2485
2486    DPRINTK(2,"dwrq->length=%d\n", dwrq->length);
2487
2488    /* length check */
2489    if(p[1] + 2 != dwrq->length || dwrq->length > 256 ){
2490        return -EINVAL;
2491    }
2492
2493    priv->wps.ielen = p[1] + 2 + 1; /* IE header + IE + sizeof(len) */
2494    len = p[1] + 2; /* IE header + IE */
2495
2496    memcpy(priv->wps.ie, &len, sizeof(len));
2497    p = memcpy(priv->wps.ie+1, p, len);
2498
2499    DPRINTK(2,"%d(%#x): %02X %02X %02X %02X ... %02X %02X %02X\n",
2500        priv->wps.ielen, priv->wps.ielen, p[0], p[1], p[2], p[3],
2501        p[priv->wps.ielen-3], p[priv->wps.ielen-2], p[priv->wps.ielen-1]);
2502
2503    hostif_sme_enqueue(priv, SME_WPS_PROBE_REQUEST);
2504
2505    return 0;
2506}
2507#if 0
2508/*------------------------------------------------------------------*/
2509/* Private handler : get WPS probe req */
2510static int ks_wlan_get_wps_probe_req(struct net_device *dev,
2511                     struct iw_request_info *info,
2512                     __u32 *uwrq, char *extra)
2513{
2514    ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2515    DPRINTK(2,"\n");
2516
2517    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2518
2519    return 0;
2520}
2521#endif
2522#endif /* WPS */
2523
2524/*------------------------------------------------------------------*/
2525/* Private handler : set tx gain control value */
2526static int ks_wlan_set_tx_gain(struct net_device *dev, struct iw_request_info *info,
2527                         __u32 *uwrq, char *extra)
2528{
2529    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2530
2531    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2532
2533    if(*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */
2534        priv->gain.TxGain = (uint8_t)*uwrq;
2535    else
2536        return -EINVAL;
2537
2538    if(priv->gain.TxGain < 0xFF)
2539        priv->gain.TxMode = 1;
2540    else
2541        priv->gain.TxMode = 0;
2542
2543
2544    hostif_sme_enqueue(priv, SME_SET_GAIN);
2545    return 0;
2546}
2547
2548/*------------------------------------------------------------------*/
2549/* Private handler : get tx gain control value */
2550static int ks_wlan_get_tx_gain(struct net_device *dev, struct iw_request_info *info,
2551                         __u32 *uwrq, char *extra)
2552{
2553    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2554
2555    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2556
2557    *uwrq = priv->gain.TxGain;
2558    hostif_sme_enqueue(priv, SME_GET_GAIN);
2559    return 0;
2560}
2561
2562/*------------------------------------------------------------------*/
2563/* Private handler : set rx gain control value */
2564static int ks_wlan_set_rx_gain(struct net_device *dev, struct iw_request_info *info,
2565                         __u32 *uwrq, char *extra)
2566{
2567    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2568
2569    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2570
2571    if(*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */
2572        priv->gain.RxGain = (uint8_t)*uwrq;
2573    else
2574        return -EINVAL;
2575
2576    if(priv->gain.RxGain < 0xFF)
2577        priv->gain.RxMode = 1;
2578    else
2579        priv->gain.RxMode = 0;
2580
2581    hostif_sme_enqueue(priv, SME_SET_GAIN);
2582    return 0;
2583}
2584
2585/*------------------------------------------------------------------*/
2586/* Private handler : get rx gain control value */
2587static int ks_wlan_get_rx_gain(struct net_device *dev, struct iw_request_info *info,
2588                         __u32 *uwrq, char *extra)
2589{
2590    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2591
2592    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2593
2594    *uwrq = priv->gain.RxGain;
2595    hostif_sme_enqueue(priv, SME_GET_GAIN);
2596    return 0;
2597}
2598#if 0
2599/*------------------------------------------------------------------*/
2600/* Private handler : set region value */
2601static int ks_wlan_set_region(struct net_device *dev, struct iw_request_info *info,
2602                         __u32 *uwrq, char *extra)
2603{
2604    ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2605
2606    if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2607
2608    if(*uwrq >= 0x9 && *uwrq <= 0xF) /* 0x9-0xf */
2609        priv->region = (uint8_t)*uwrq;
2610    else
2611        return -EINVAL;
2612
2613    hostif_sme_enqueue(priv, SME_SET_REGION);
2614    return 0;
2615}
2616#endif
2617
2618/*------------------------------------------------------------------*/
2619/* Private handler : get eeprom checksum result */
2620static int ks_wlan_get_eeprom_cksum(struct net_device *dev, struct iw_request_info *info,
2621                         __u32 *uwrq, char *extra)
2622{
2623    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2624
2625    *uwrq = priv->eeprom_checksum;
2626    return 0;
2627}
2628
2629static void print_hif_event(int event){
2630
2631    switch(event){
2632    case HIF_DATA_REQ :
2633        printk("HIF_DATA_REQ\n");
2634        break;
2635    case HIF_DATA_IND :
2636        printk("HIF_DATA_IND\n");
2637        break;
2638    case HIF_MIB_GET_REQ :
2639        printk("HIF_MIB_GET_REQ\n");
2640        break;
2641    case HIF_MIB_GET_CONF :
2642        printk("HIF_MIB_GET_CONF\n");
2643        break;
2644    case HIF_MIB_SET_REQ :
2645        printk("HIF_MIB_SET_REQ\n");
2646        break;
2647    case HIF_MIB_SET_CONF :
2648        printk("HIF_MIB_SET_CONF\n");
2649        break;
2650    case HIF_POWERMGT_REQ :
2651        printk("HIF_POWERMGT_REQ\n");
2652        break;
2653    case HIF_POWERMGT_CONF :
2654        printk("HIF_POWERMGT_CONF\n");
2655        break;
2656    case HIF_START_REQ :
2657        printk("HIF_START_REQ\n");
2658        break;
2659    case HIF_START_CONF :
2660        printk("HIF_START_CONF\n");
2661        break;
2662    case HIF_CONNECT_IND :
2663        printk("HIF_CONNECT_IND\n");
2664        break;
2665    case HIF_STOP_REQ :
2666        printk("HIF_STOP_REQ\n");
2667        break;
2668    case HIF_STOP_CONF :
2669        printk("HIF_STOP_CONF\n");
2670        break;
2671    case HIF_PS_ADH_SET_REQ :
2672        printk("HIF_PS_ADH_SET_REQ\n");
2673        break;
2674    case HIF_PS_ADH_SET_CONF:
2675        printk("HIF_PS_ADH_SET_CONF\n");
2676        break;
2677    case HIF_INFRA_SET_REQ :
2678        printk("HIF_INFRA_SET_REQ\n");
2679        break;
2680    case HIF_INFRA_SET_CONF :
2681        printk("HIF_INFRA_SET_CONF\n");
2682        break;
2683    case HIF_ADH_SET_REQ :
2684        printk("HIF_ADH_SET_REQ\n");
2685        break;
2686    case HIF_ADH_SET_CONF :
2687        printk("HIF_ADH_SET_CONF\n");
2688        break;
2689    case HIF_AP_SET_REQ :
2690        printk("HIF_AP_SET_REQ\n");
2691        break;
2692    case HIF_AP_SET_CONF :
2693        printk("HIF_AP_SET_CONF\n");
2694        break;
2695    case HIF_ASSOC_INFO_IND :
2696        printk("HIF_ASSOC_INFO_IND\n");
2697        break;
2698    case HIF_MIC_FAILURE_REQ:
2699        printk("HIF_MIC_FAILURE_REQ\n");
2700        break;
2701    case HIF_MIC_FAILURE_CONF :
2702        printk("HIF_MIC_FAILURE_CONF\n");
2703        break;
2704    case HIF_SCAN_REQ :
2705        printk("HIF_SCAN_REQ\n");
2706        break;
2707    case HIF_SCAN_CONF :
2708        printk("HIF_SCAN_CONF\n");
2709        break;
2710    case HIF_PHY_INFO_REQ :
2711        printk("HIF_PHY_INFO_REQ\n");
2712        break;
2713    case HIF_PHY_INFO_CONF :
2714        printk("HIF_PHY_INFO_CONF\n");
2715        break;
2716    case HIF_SLEEP_REQ :
2717        printk("HIF_SLEEP_REQ\n");
2718        break;
2719    case HIF_SLEEP_CONF :
2720        printk("HIF_SLEEP_CONF\n");
2721        break;
2722    case HIF_PHY_INFO_IND :
2723        printk("HIF_PHY_INFO_IND\n");
2724        break;
2725    case HIF_SCAN_IND :
2726        printk("HIF_SCAN_IND\n");
2727        break;
2728    case HIF_INFRA_SET2_REQ :
2729        printk("HIF_INFRA_SET2_REQ\n");
2730        break;
2731    case HIF_INFRA_SET2_CONF:
2732        printk("HIF_INFRA_SET2_CONF\n");
2733        break;
2734    case HIF_ADH_SET2_REQ :
2735        printk("HIF_ADH_SET2_REQ\n");
2736        break;
2737    case HIF_ADH_SET2_CONF :
2738        printk("HIF_ADH_SET2_CONF\n");
2739    }
2740}
2741
2742/*------------------------------------------------------------------*/
2743/* Private handler : get host command history */
2744static int ks_wlan_hostt(struct net_device *dev, struct iw_request_info *info,
2745                         __u32 *uwrq, char *extra)
2746{
2747    int i,event;
2748    ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2749
2750    for(i = 63; i >= 0; i--){
2751        event = priv->hostt.buff[(priv->hostt.qtail -1 -i)%SME_EVENT_BUFF_SIZE] ;
2752        print_hif_event(event);
2753    }
2754    return 0;
2755}
2756
2757/* Structures to export the Wireless Handlers */
2758
2759static const struct iw_priv_args ks_wlan_private_args[] = {
2760/*{ cmd, set_args, get_args, name[16] } */
2761  { KS_WLAN_GET_DRIVER_VERSION, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_CHAR | (128+1), "GetDriverVer" },
2762  { KS_WLAN_GET_FIRM_VERSION, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_CHAR | (128+1), "GetFirmwareVer" },
2763#ifdef WPS
2764  { KS_WLAN_SET_WPS_ENABLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE, "SetWPSEnable" },
2765  { KS_WLAN_GET_WPS_ENABLE, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetW" },
2766  { KS_WLAN_SET_WPS_PROBE_REQ, IW_PRIV_TYPE_BYTE | 2047, IW_PRIV_TYPE_NONE, "SetWPSProbeReq" },
2767#endif /* WPS */
2768  { KS_WLAN_SET_PREAMBLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE, "SetPreamble" },
2769  { KS_WLAN_GET_PREAMBLE, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPreamble" },
2770  { KS_WLAN_SET_POWER_SAVE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE, "SetPowerSave" },
2771  { KS_WLAN_GET_POWER_SAVE, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPowerSave" },
2772  { KS_WLAN_SET_SCAN_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE, "SetScanType" },
2773  { KS_WLAN_GET_SCAN_TYPE, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetScanType" },
2774  { KS_WLAN_SET_RX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE, "SetRxGain" },
2775  { KS_WLAN_GET_RX_GAIN, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetRxGain" },
2776  { KS_WLAN_HOSTT, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_CHAR | (128+1), "hostt" },
2777  { KS_WLAN_SET_BEACON_LOST, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE, "SetBeaconLost" },
2778  { KS_WLAN_GET_BEACON_LOST, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetBeaconLost" },
2779  { KS_WLAN_SET_SLEEP_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE, "SetSleepMode" },
2780  { KS_WLAN_GET_SLEEP_MODE, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetSleepMode" },
2781  { KS_WLAN_SET_TX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE, "SetTxGain" },
2782  { KS_WLAN_GET_TX_GAIN, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetTxGain" },
2783  { KS_WLAN_SET_PHY_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE, "SetPhyType" },
2784  { KS_WLAN_GET_PHY_TYPE, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPhyType" },
2785  { KS_WLAN_SET_CTS_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE, "SetCtsMode" },
2786  { KS_WLAN_GET_CTS_MODE, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetCtsMode" },
2787  { KS_WLAN_GET_EEPROM_CKSUM, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetChecksum" },
2788};
2789static const iw_handler ks_wlan_handler[] =
2790{
2791    (iw_handler) ks_wlan_config_commit, /* SIOCSIWCOMMIT */
2792    (iw_handler) ks_wlan_get_name, /* SIOCGIWNAME */
2793    (iw_handler) NULL, /* SIOCSIWNWID */
2794    (iw_handler) NULL, /* SIOCGIWNWID */
2795    (iw_handler) ks_wlan_set_freq, /* SIOCSIWFREQ */
2796    (iw_handler) ks_wlan_get_freq, /* SIOCGIWFREQ */
2797    (iw_handler) ks_wlan_set_mode, /* SIOCSIWMODE */
2798    (iw_handler) ks_wlan_get_mode, /* SIOCGIWMODE */
2799#ifndef KSC_OPNOTSUPP
2800    (iw_handler) ks_wlan_set_sens, /* SIOCSIWSENS */
2801    (iw_handler) ks_wlan_get_sens, /* SIOCGIWSENS */
2802#else /* KSC_OPNOTSUPP */
2803    (iw_handler) NULL, /* SIOCSIWSENS */
2804    (iw_handler) NULL, /* SIOCGIWSENS */
2805#endif /* KSC_OPNOTSUPP */
2806    (iw_handler) NULL, /* SIOCSIWRANGE */
2807    (iw_handler) ks_wlan_get_range, /* SIOCGIWRANGE */
2808    (iw_handler) NULL, /* SIOCSIWPRIV */
2809    (iw_handler) NULL, /* SIOCGIWPRIV */
2810    (iw_handler) NULL, /* SIOCSIWSTATS */
2811    (iw_handler) ks_wlan_get_iwstats, /* SIOCGIWSTATS */
2812    (iw_handler) NULL, /* SIOCSIWSPY */
2813    (iw_handler) NULL, /* SIOCGIWSPY */
2814    (iw_handler) NULL, /* SIOCSIWTHRSPY */
2815    (iw_handler) NULL, /* SIOCGIWTHRSPY */
2816    (iw_handler) ks_wlan_set_wap, /* SIOCSIWAP */
2817    (iw_handler) ks_wlan_get_wap, /* SIOCGIWAP */
2818// (iw_handler) NULL, /* SIOCSIWMLME */
2819    (iw_handler) ks_wlan_set_mlme, /* SIOCSIWMLME */
2820    (iw_handler) ks_wlan_get_aplist, /* SIOCGIWAPLIST */
2821    (iw_handler) ks_wlan_set_scan, /* SIOCSIWSCAN */
2822    (iw_handler) ks_wlan_get_scan, /* SIOCGIWSCAN */
2823    (iw_handler) ks_wlan_set_essid, /* SIOCSIWESSID */
2824    (iw_handler) ks_wlan_get_essid, /* SIOCGIWESSID */
2825    (iw_handler) ks_wlan_set_nick, /* SIOCSIWNICKN */
2826    (iw_handler) ks_wlan_get_nick, /* SIOCGIWNICKN */
2827    (iw_handler) NULL, /* -- hole -- */
2828    (iw_handler) NULL, /* -- hole -- */
2829    (iw_handler) ks_wlan_set_rate, /* SIOCSIWRATE */
2830    (iw_handler) ks_wlan_get_rate, /* SIOCGIWRATE */
2831    (iw_handler) ks_wlan_set_rts, /* SIOCSIWRTS */
2832    (iw_handler) ks_wlan_get_rts, /* SIOCGIWRTS */
2833    (iw_handler) ks_wlan_set_frag, /* SIOCSIWFRAG */
2834    (iw_handler) ks_wlan_get_frag, /* SIOCGIWFRAG */
2835#ifndef KSC_OPNOTSUPP
2836    (iw_handler) ks_wlan_set_txpow, /* SIOCSIWTXPOW */
2837    (iw_handler) ks_wlan_get_txpow, /* SIOCGIWTXPOW */
2838    (iw_handler) ks_wlan_set_retry, /* SIOCSIWRETRY */
2839    (iw_handler) ks_wlan_get_retry, /* SIOCGIWRETRY */
2840#else /* KSC_OPNOTSUPP */
2841    (iw_handler) NULL, /* SIOCSIWTXPOW */
2842    (iw_handler) NULL, /* SIOCGIWTXPOW */
2843    (iw_handler) NULL, /* SIOCSIWRETRY */
2844    (iw_handler) NULL, /* SIOCGIWRETRY */
2845#endif /* KSC_OPNOTSUPP */
2846    (iw_handler) ks_wlan_set_encode, /* SIOCSIWENCODE */
2847    (iw_handler) ks_wlan_get_encode, /* SIOCGIWENCODE */
2848    (iw_handler) ks_wlan_set_power, /* SIOCSIWPOWER */
2849    (iw_handler) ks_wlan_get_power, /* SIOCGIWPOWER */
2850    (iw_handler) NULL, /* -- hole -- */
2851    (iw_handler) NULL, /* -- hole -- */
2852// (iw_handler) NULL, /* SIOCSIWGENIE */
2853    (iw_handler) ks_wlan_set_genie, /* SIOCSIWGENIE */
2854    (iw_handler) NULL, /* SIOCGIWGENIE */
2855    (iw_handler) ks_wlan_set_auth_mode, /* SIOCSIWAUTH */
2856    (iw_handler) ks_wlan_get_auth_mode, /* SIOCGIWAUTH */
2857    (iw_handler) ks_wlan_set_encode_ext, /* SIOCSIWENCODEEXT */
2858    (iw_handler) ks_wlan_get_encode_ext, /* SIOCGIWENCODEEXT */
2859    (iw_handler) ks_wlan_set_pmksa, /* SIOCSIWPMKSA */
2860    (iw_handler) NULL, /* -- hole -- */
2861};
2862
2863/* private_handler */
2864static const iw_handler ks_wlan_private_handler[] =
2865{
2866    (iw_handler) NULL, /* 0 */
2867    (iw_handler) ks_wlan_get_driver_version, /* 1 KS_WLAN_GET_DRIVER_VERSION */
2868    (iw_handler) NULL, /* 2 */
2869    (iw_handler) ks_wlan_get_firmware_version, /* 3 KS_WLAN_GET_FIRM_VERSION */
2870#ifdef WPS
2871    (iw_handler) ks_wlan_set_wps_enable, /* 4 KS_WLAN_SET_WPS_ENABLE */
2872    (iw_handler) ks_wlan_get_wps_enable, /* 5 KS_WLAN_GET_WPS_ENABLE */
2873    (iw_handler) ks_wlan_set_wps_probe_req, /* 6 KS_WLAN_SET_WPS_PROBE_REQ */
2874#else
2875    (iw_handler) NULL, /* 4 */
2876    (iw_handler) NULL, /* 5 */
2877    (iw_handler) NULL, /* 6 */
2878#endif /* WPS */
2879
2880    (iw_handler) ks_wlan_get_eeprom_cksum, /* 7 KS_WLAN_GET_CONNECT */
2881    (iw_handler) ks_wlan_set_preamble, /* 8 KS_WLAN_SET_PREAMBLE */
2882    (iw_handler) ks_wlan_get_preamble, /* 9 KS_WLAN_GET_PREAMBLE */
2883    (iw_handler) ks_wlan_set_powermgt, /* 10 KS_WLAN_SET_POWER_SAVE */
2884    (iw_handler) ks_wlan_get_powermgt, /* 11 KS_WLAN_GET_POWER_SAVE */
2885    (iw_handler) ks_wlan_set_scan_type, /* 12 KS_WLAN_SET_SCAN_TYPE */
2886    (iw_handler) ks_wlan_get_scan_type, /* 13 KS_WLAN_GET_SCAN_TYPE */
2887    (iw_handler) ks_wlan_set_rx_gain, /* 14 KS_WLAN_SET_RX_GAIN */
2888    (iw_handler) ks_wlan_get_rx_gain, /* 15 KS_WLAN_GET_RX_GAIN */
2889    (iw_handler) ks_wlan_hostt, /* 16 KS_WLAN_HOSTT */
2890    (iw_handler) NULL, /* 17 */
2891    (iw_handler) ks_wlan_set_beacon_lost, /* 18 KS_WLAN_SET_BECAN_LOST */
2892    (iw_handler) ks_wlan_get_beacon_lost, /* 19 KS_WLAN_GET_BECAN_LOST */
2893    (iw_handler) ks_wlan_set_tx_gain, /* 20 KS_WLAN_SET_TX_GAIN */
2894    (iw_handler) ks_wlan_get_tx_gain, /* 21 KS_WLAN_GET_TX_GAIN */
2895    (iw_handler) ks_wlan_set_phy_type, /* 22 KS_WLAN_SET_PHY_TYPE */
2896    (iw_handler) ks_wlan_get_phy_type, /* 23 KS_WLAN_GET_PHY_TYPE */
2897    (iw_handler) ks_wlan_set_cts_mode, /* 24 KS_WLAN_SET_CTS_MODE */
2898    (iw_handler) ks_wlan_get_cts_mode, /* 25 KS_WLAN_GET_CTS_MODE */
2899    (iw_handler) NULL, /* 26 */
2900    (iw_handler) NULL, /* 27 */
2901     (iw_handler) ks_wlan_set_sleep_mode, /* 28 KS_WLAN_SET_SLEEP_MODE */
2902     (iw_handler) ks_wlan_get_sleep_mode, /* 29 KS_WLAN_GET_SLEEP_MODE */
2903    (iw_handler) NULL, /* 30 */
2904    (iw_handler) NULL, /* 31 */
2905};
2906
2907static const struct iw_handler_def ks_wlan_handler_def =
2908{
2909    .num_standard = sizeof(ks_wlan_handler)/sizeof(iw_handler),
2910    .num_private = sizeof(ks_wlan_private_handler)/sizeof(iw_handler),
2911    .num_private_args = sizeof(ks_wlan_private_args)/sizeof(struct iw_priv_args),
2912    .standard = (iw_handler *) ks_wlan_handler,
2913    .private = (iw_handler *) ks_wlan_private_handler,
2914    .private_args = (struct iw_priv_args *) ks_wlan_private_args,
2915    .get_wireless_stats = ks_get_wireless_stats,
2916};
2917
2918#endif /* WIRELESS_EXT */
2919
2920static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2921{
2922    int rc = 0;
2923#if defined(WIRELESS_EXT)
2924    struct iwreq *wrq = (struct iwreq *) rq;
2925#endif /* WIRELESS_EXT */
2926    switch (cmd) {
2927#if defined(WIRELESS_EXT)
2928    case SIOCIWFIRSTPRIV+20: /* KS_WLAN_SET_STOP_REQ */
2929        rc = ks_wlan_set_stop_request(dev, NULL, &(wrq->u.mode), NULL);
2930        break;
2931#endif /* WIRELESS_EXT >17 */
2932    // All other calls are currently unsupported
2933    default:
2934        rc = -EOPNOTSUPP;
2935    }
2936
2937    DPRINTK(5,"return=%d\n",rc);
2938    return rc;
2939}
2940
2941
2942static
2943struct net_device_stats *ks_wlan_get_stats(struct net_device *dev)
2944{
2945    ks_wlan_private *priv = netdev_priv(dev);
2946
2947    if (priv->dev_state < DEVICE_STATE_READY) {
2948                return NULL; /* not finished initialize */
2949        }
2950
2951    return &priv->nstats;
2952}
2953
2954static
2955int ks_wlan_set_mac_address(struct net_device *dev, void *addr)
2956{
2957    ks_wlan_private *priv = netdev_priv(dev);
2958    struct sockaddr *mac_addr=(struct sockaddr *)addr;
2959    if (netif_running(dev))
2960        return -EBUSY;
2961    memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
2962    memcpy(priv->eth_addr, mac_addr->sa_data, ETH_ALEN);
2963
2964    priv->mac_address_valid = 0;
2965    hostif_sme_enqueue(priv, SME_MACADDRESS_SET_REQUEST);
2966    printk(KERN_INFO "ks_wlan: MAC ADDRESS = %02x:%02x:%02x:%02x:%02x:%02x\n",
2967               priv->eth_addr[0],priv->eth_addr[1],priv->eth_addr[2],
2968               priv->eth_addr[3],priv->eth_addr[4],priv->eth_addr[5]);
2969    return 0;
2970}
2971
2972
2973static
2974void ks_wlan_tx_timeout(struct net_device *dev)
2975{
2976        ks_wlan_private *priv = netdev_priv(dev);
2977
2978    DPRINTK(1,"head(%d) tail(%d)!!\n",priv->tx_dev.qhead, priv->tx_dev.qtail);
2979    if(!netif_queue_stopped(dev)){
2980        netif_stop_queue(dev);
2981    }
2982    priv->nstats.tx_errors++;
2983    netif_wake_queue(dev);
2984
2985    return;
2986}
2987
2988static
2989int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev)
2990{
2991    ks_wlan_private *priv = netdev_priv(dev);
2992    int rc = 0;
2993
2994    DPRINTK(3,"in_interrupt()=%ld\n",in_interrupt());
2995
2996    if ( skb == NULL ) {
2997        printk( KERN_ERR "ks_wlan: skb == NULL!!!\n" );
2998        return 0;
2999    }
3000    if (priv->dev_state < DEVICE_STATE_READY) {
3001        dev_kfree_skb(skb);
3002        return 0; /* not finished initialize */
3003        }
3004
3005    if(netif_running(dev))
3006        netif_stop_queue(dev);
3007
3008    rc = hostif_data_request(priv, skb);
3009    dev->trans_start = jiffies;
3010
3011    DPRINTK(4,"rc=%d\n",rc);
3012    if (rc){
3013        rc=0;
3014    }
3015
3016    return rc;
3017}
3018
3019void send_packet_complete(void *arg1, void *arg2)
3020{
3021    ks_wlan_private *priv = (ks_wlan_private *)arg1;
3022    struct sk_buff *packet = (struct sk_buff *)arg2;
3023
3024        DPRINTK(3,"\n");
3025
3026        priv->nstats.tx_bytes += packet->len;
3027    priv->nstats.tx_packets++;
3028
3029    if(netif_queue_stopped(priv->net_dev))
3030            netif_wake_queue(priv->net_dev);
3031
3032    if(packet){
3033        dev_kfree_skb(packet);
3034        packet=NULL;
3035    }
3036
3037}
3038
3039/* Set or clear the multicast filter for this adaptor.
3040   This routine is not state sensitive and need not be SMP locked. */
3041static
3042void ks_wlan_set_multicast_list(struct net_device *dev)
3043{
3044    ks_wlan_private *priv = netdev_priv(dev);
3045
3046    DPRINTK(4,"\n");
3047    if (priv->dev_state < DEVICE_STATE_READY) {
3048                return ; /* not finished initialize */
3049    }
3050    hostif_sme_enqueue(priv, SME_MULTICAST_REQUEST);
3051
3052    return;
3053}
3054
3055static
3056int ks_wlan_open(struct net_device *dev)
3057{
3058    ks_wlan_private *priv = netdev_priv(dev);
3059
3060    priv->cur_rx = 0;
3061
3062    if(!priv->mac_address_valid){
3063        printk(KERN_ERR "ks_wlan : %s Not READY !!\n", dev->name);
3064        return -EBUSY;
3065    }
3066    else
3067        netif_start_queue (dev);
3068
3069    return 0;
3070}
3071
3072static
3073int ks_wlan_close(struct net_device *dev)
3074{
3075
3076    netif_stop_queue (dev);
3077
3078    DPRINTK(4, "%s: Shutting down ethercard, status was 0x%4.4x.\n",
3079        dev->name, 0x00);
3080
3081    return 0;
3082}
3083
3084
3085/* Operational parameters that usually are not changed. */
3086/* Time in jiffies before concluding the transmitter is hung. */
3087#define TX_TIMEOUT (3*HZ)
3088static const unsigned char dummy_addr[] = {0x00,0x0b,0xe3,0x00,0x00,0x00};
3089
3090static const struct net_device_ops ks_wlan_netdev_ops = {
3091    .ndo_start_xmit = ks_wlan_start_xmit,
3092    .ndo_open = ks_wlan_open,
3093    .ndo_stop = ks_wlan_close,
3094    .ndo_do_ioctl = ks_wlan_netdev_ioctl,
3095    .ndo_set_mac_address = ks_wlan_set_mac_address,
3096    .ndo_get_stats = ks_wlan_get_stats,
3097    .ndo_tx_timeout = ks_wlan_tx_timeout,
3098    .ndo_set_multicast_list = ks_wlan_set_multicast_list,
3099};
3100
3101int ks_wlan_net_start(struct net_device *dev)
3102{
3103    ks_wlan_private *priv;
3104    /* int rc; */
3105
3106    priv = netdev_priv(dev);
3107    priv->mac_address_valid = 0;
3108    priv->need_commit = 0;
3109
3110    priv->device_open_status = 1;
3111
3112    /* phy information update timer */
3113    atomic_set(&update_phyinfo,0);
3114    init_timer(&update_phyinfo_timer);
3115    update_phyinfo_timer.function=ks_wlan_update_phyinfo_timeout;
3116    update_phyinfo_timer.data = (unsigned long)priv;
3117
3118    /* dummy address set */
3119    memcpy(priv->eth_addr, dummy_addr, ETH_ALEN);
3120    dev->dev_addr[0] = priv->eth_addr[0];
3121    dev->dev_addr[1] = priv->eth_addr[1];
3122    dev->dev_addr[2] = priv->eth_addr[2];
3123    dev->dev_addr[3] = priv->eth_addr[3];
3124    dev->dev_addr[4] = priv->eth_addr[4];
3125    dev->dev_addr[5] = priv->eth_addr[5];
3126    dev->dev_addr[6] = 0x00;
3127    dev->dev_addr[7] = 0x00;
3128
3129    /* The ks_wlan-specific entries in the device structure. */
3130    dev->netdev_ops = &ks_wlan_netdev_ops;
3131    dev->wireless_handlers = (struct iw_handler_def *)&ks_wlan_handler_def;
3132    dev->watchdog_timeo = TX_TIMEOUT;
3133
3134    netif_carrier_off(dev);
3135
3136    return 0;
3137}
3138
3139
3140int ks_wlan_net_stop(struct net_device *dev)
3141{
3142    ks_wlan_private *priv = netdev_priv(dev);
3143
3144    int ret = 0;
3145    priv->device_open_status = 0;
3146    del_timer_sync(&update_phyinfo_timer);
3147
3148    if(netif_running(dev))
3149        netif_stop_queue(dev);
3150
3151    return ret;
3152}
3153
3154int ks_wlan_reset(struct net_device *dev)
3155{
3156    return 0;
3157}
package/ks7010/src/michael_mic.c
1/*
2 * Driver for KeyStream wireless LAN
3 *
4 * michael_mic.c
5 * $Id: michael_mic.c 991 2009-09-14 01:38:58Z 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 <linux/types.h>
16#include <linux/string.h>
17#include "michael_mic.h"
18
19// Rotation functions on 32 bit values
20#define ROL32( A, n ) ( ((A) << (n)) | ( ((A)>>(32-(n))) & ( (1UL << (n)) - 1 ) ) )
21#define ROR32( A, n ) ROL32( (A), 32-(n) )
22// Convert from Byte[] to UInt32 in a portable way
23#define getUInt32( A, B ) (uint32_t)(A[B+0] << 0) + (A[B+1] << 8) + (A[B+2] << 16) + (A[B+3] << 24)
24
25// Convert from UInt32 to Byte[] in a portable way
26#define putUInt32( A, B, C ) A[B+0] = (uint8_t) (C & 0xff); \
27                A[B+1] = (uint8_t) ((C>>8) & 0xff); \
28                A[B+2] = (uint8_t) ((C>>16) & 0xff); \
29                A[B+3] = (uint8_t) ((C>>24) & 0xff)
30
31// Reset the state to the empty message.
32#define MichaelClear( A ) A->L = A->K0; \
33                A->R = A->K1; \
34                A->nBytesInM = 0;
35
36static
37void MichaelInitializeFunction( struct michel_mic_t *Mic, uint8_t *key )
38{
39    // Set the key
40    Mic->K0 = getUInt32( key , 0 );
41    Mic->K1 = getUInt32( key , 4 );
42
43    //clear();
44    MichaelClear(Mic);
45}
46
47#define MichaelBlockFunction(L, R) \
48do{ \
49    R ^= ROL32( L, 17 ); \
50    L += R; \
51    R ^= ((L & 0xff00ff00) >> 8) | ((L & 0x00ff00ff) << 8); \
52    L += R; \
53    R ^= ROL32( L, 3 ); \
54    L += R; \
55    R ^= ROR32( L, 2 ); \
56    L += R; \
57}while(0)
58
59
60static
61void MichaelAppend( struct michel_mic_t *Mic, uint8_t *src, int nBytes )
62{
63    int addlen ;
64    if (Mic->nBytesInM) {
65        addlen = 4 - Mic->nBytesInM;
66        if (addlen > nBytes)
67            addlen = nBytes;
68        memcpy(&Mic->M[Mic->nBytesInM], src, addlen);
69        Mic->nBytesInM += addlen;
70        src += addlen;
71        nBytes -= addlen;
72
73        if (Mic->nBytesInM < 4)
74            return;
75
76        Mic->L ^= getUInt32(Mic->M,0);
77        MichaelBlockFunction(Mic->L, Mic->R);
78        Mic->nBytesInM = 0;
79    }
80
81    while(nBytes >= 4){
82        Mic->L ^= getUInt32(src,0);
83        MichaelBlockFunction(Mic->L, Mic->R);
84        src += 4;
85        nBytes -= 4;
86    }
87
88    if (nBytes > 0) {
89        Mic->nBytesInM = nBytes;
90        memcpy(Mic->M, src, nBytes);
91    }
92}
93
94static
95void MichaelGetMIC( struct michel_mic_t *Mic, uint8_t *dst )
96{
97    uint8_t *data = Mic->M;
98    switch (Mic->nBytesInM) {
99    case 0:
100        Mic->L ^= 0x5a;
101        break;
102    case 1:
103        Mic->L ^= data[0] | 0x5a00;
104        break;
105    case 2:
106        Mic->L ^= data[0] | (data[1] << 8) | 0x5a0000;
107        break;
108    case 3:
109        Mic->L ^= data[0] | (data[1] << 8) | (data[2] << 16) |
110            0x5a000000;
111        break;
112    }
113    MichaelBlockFunction(Mic->L, Mic->R);
114    MichaelBlockFunction(Mic->L, Mic->R);
115    // The appendByte function has already computed the result.
116    putUInt32( dst, 0, Mic->L );
117    putUInt32( dst, 4, Mic->R );
118
119    // Reset to the empty message.
120    MichaelClear(Mic);
121}
122
123void MichaelMICFunction( struct michel_mic_t *Mic, uint8_t *Key,
124             uint8_t *Data, int Len, uint8_t priority,
125             uint8_t *Result )
126{
127    uint8_t pad_data[4] = {priority,0,0,0};
128    // Compute the MIC value
129    /*
130     * IEEE802.11i page 47
131     * Figure 43g TKIP MIC processing format
132     * +--+--+--------+--+----+--+--+--+--+--+--+--+--+
133     * |6 |6 |1 |3 |M |1 |1 |1 |1 |1 |1 |1 |1 | Octet
134     * +--+--+--------+--+----+--+--+--+--+--+--+--+--+
135     * |DA|SA|Priority|0 |Data|M0|M1|M2|M3|M4|M5|M6|M7|
136     * +--+--+--------+--+----+--+--+--+--+--+--+--+--+
137     */
138    MichaelInitializeFunction( Mic, Key ) ;
139    MichaelAppend( Mic, (uint8_t*)Data, 12 ); /* |DA|SA| */
140    MichaelAppend( Mic, pad_data, 4 ); /* |Priority|0|0|0| */
141    MichaelAppend( Mic, (uint8_t*)(Data+12), Len -12 ); /* |Data| */
142    MichaelGetMIC( Mic, Result ) ;
143}
package/ks7010/src/michael_mic.h
1/*
2 * Driver for KeyStream wireless LAN
3 *
4 * michael_mic.h
5 * $Id: michael_mic.h 991 2009-09-14 01:38:58Z 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/* MichelMIC routine define */
16struct michel_mic_t {
17    uint32_t K0; // Key
18    uint32_t K1; // Key
19    uint32_t L; // Current state
20    uint32_t R; // Current state
21    uint8_t M[4]; // Message accumulator (single word)
22    int nBytesInM; // # bytes in M
23    uint8_t Result[8];
24};
25
26extern
27void MichaelMICFunction( struct michel_mic_t *Mic, uint8_t *Key,
28             uint8_t *Data, int Len, uint8_t priority,
29             uint8_t *Result );

Archive Download the corresponding diff file



interactive