Date:2011-04-26 05:06:33 (3 years 6 months ago)
Author:Xiangfu Liu
Commit:159a6770f50420cbfd05c2069a6e5c3d5cefa238
Message:new package: move kmod-ks7010 from openwrt to here

Files: ks7010/Makefile (1 diff)
ks7010/files/ks7010sd.rom (0 diffs)
ks7010/files/ks79xx.cfg (1 diff)
ks7010/src/Kconfig (1 diff)
ks7010/src/Makefile (1 diff)
ks7010/src/eap_packet.h (1 diff)
ks7010/src/ks7010_config.c (1 diff)
ks7010/src/ks7010_sdio.c (1 diff)
ks7010/src/ks7010_sdio.h (1 diff)
ks7010/src/ks_debug.c (1 diff)
ks7010/src/ks_debug.h (1 diff)
ks7010/src/ks_hostif.c (1 diff)
ks7010/src/ks_hostif.h (1 diff)
ks7010/src/ks_wlan.h (1 diff)
ks7010/src/ks_wlan_ioctl.h (1 diff)
ks7010/src/ks_wlan_net.c (1 diff)
ks7010/src/michael_mic.c (1 diff)
ks7010/src/michael_mic.h (1 diff)

Change Details

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
40define KernelPackage/ks7010/install
41    $(INSTALL_DIR) $(1)/lib/firmware/
42    $(CP) ./files/* $(1)/lib/firmware/
43endef
44
45$(eval $(call KernelPackage,ks7010))
ks7010/files/ks7010sd.rom
ks7010/files/ks79xx.cfg
1#ks79xx.cfg
2#KS79xx configuration file
3#
4
5#
6#BeaconLostCount default 20
7BeaconLostCount=20
8#
9
10#
11#Ap List Scan Type default ACTIVE_SCAN ACTIVE_SCAN or PASSIVE_SCAN
12ScanType=ACTIVE_SCAN
13#
14
15#
16#Channel default 10 min 1 max 14
17Channel=10
18#
19
20#
21#FragmentThreshold default 2346 min 256 max 2346
22FragmentThreshold=2346
23#
24
25#
26#OperationMode default Infrastructure Pseudo-Ad-Hoc or 802.11-Ad-Hoc or Infrastructure
27OperationMode=Infrastructure
28#
29
30#
31#PowerManagementMode default ACTIVE ACTIVE or SAVE1 or SAVE2
32PowerManagementMode=ACTIVE
33#
34
35#
36#RTSThreshold default 2347 min 0 max 2347
37RTSThreshold=2347
38#
39
40#
41#SSID default "" max 32 character
42SSID="default"
43#
44
45#
46#TxRate default Auto 1, 2, 5.5, 11 ex. TxRate=1,2 TxRate=11 TxRate=Auto ...
47TxRate=Auto
48#
49
50#
51#Wep default OFF OFF or 64bit or 128bit
52Wep=OFF
53#
54
55#
56#WepType default STRING STRING or HEX
57WepType=STRING
58#
59
60#
61#WepIndex=1
62#
63
64#
65#WepKeyValue1
66# character_wep_key:64bit key_length = 5; 128bit key_length = 13
67# hex_wep_key:64bit key_length = 10; 128bit key_length = 26
68#
69
70#
71#WepKeyValue2
72# character_wep_key:64bit key_length = 5; 128bit key_length = 13
73# hex_wep_key:64bit key_length = 10; 128bit key_length = 26
74#
75
76#
77#WepKeyValue3
78# character_wep_key:64bit key_length = 5; 128bit key_length = 13
79# hex_wep_key:64bit key_length = 10; 128bit key_length = 26
80#
81
82#
83#WepKeyValue4
84# character_wep_key:64bit key_length = 5; 128bit key_length = 13
85# hex_wep_key:64bit key_length = 10; 128bit key_length = 26
86#
87
88#
89#AuthenticationAlgorithm default OPEN_SYSTEM OPEN_SYSTEM or SHARED_KEY
90AuthenticationAlgorithm=OPEN_SYSTEM
91#
92
93#
94#PREAMBLE_TYPE default LONG LONG or SHORT
95PREAMBLE_TYPE=SHORT
96#
97
98#
99# PhyType default BG_MODE B_MODE, G_MODE or BG_MODE
100PhyType=BG_MODE
101#
102
103#
104# CtsMode defalut FALSE TURE or FALSE
105CtsMode=FALSE
106#
107
108#
109# PhyInformationTimer defalut 0 uint 100msec
110PhyInformationTimer=0
111#
112
113#
114#ROM_FILE default "ks7010sd.rom"
115ROM_FILE="ks7010sd.rom"
116#
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!
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
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 */
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
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
574    if(priv->dev_state >= DEVICE_STATE_BOOT){
575        retval = ks7010_sdio_read(priv, INT_PENDING, &status, sizeof(status));
576        if(retval){
577            DPRINTK(1, "read INT_PENDING Failed!!(%d)\n",retval);
578            goto intr_out;
579        }
580        DPRINTK(4, "INT_PENDING=%02X\n", rw_data);
581
582        /* schedule task for interrupt status */
583        /* bit7 -> Write General Communication B register */
584        /* read (General Communication B register) */
585        /* bit5 -> Write Status Idle */
586        /* bit2 -> Read Status Busy */
587        if(status&INT_GCR_B || atomic_read(&priv->psstatus.status)==PS_SNOOZE){
588            retval = ks7010_sdio_read(priv, GCR_B, &rw_data, sizeof(rw_data));
589            if(retval){
590                DPRINTK(1, " error : GCR_B=%02X\n", rw_data);
591                goto intr_out;
592            }
593            /* DPRINTK(1, "GCR_B=%02X\n", rw_data); */
594            if(rw_data == GCR_B_ACTIVE){
595                if(atomic_read(&priv->psstatus.status)==PS_SNOOZE){
596                    atomic_set(&priv->psstatus.status, PS_WAKEUP);
597                    priv->wakeup_count=0;
598                }
599                complete(&priv->psstatus.wakeup_wait);
600            }
601
602
603        }
604
605        do{
606            /* read (WriteStatus/ReadDataSize FN1:00_0014) */
607            retval = ks7010_sdio_read(priv, WSTATUS_RSIZE, &rw_data, sizeof(rw_data));
608            if(retval){
609                DPRINTK(1, " error : WSTATUS_RSIZE=%02X\n", rw_data);
610                goto intr_out;
611            }
612            DPRINTK(4, "WSTATUS_RSIZE=%02X\n", rw_data);
613            rsize=rw_data&RSIZE_MASK;
614            if(rsize){ /* Read schedule */
615                ks_wlan_hw_rx((void *)priv, (uint16_t)(((rsize)<<4)));
616            }
617            if(rw_data&WSTATUS_MASK){
618#if 0
619                if(status&INT_WRITE_STATUS && !cnt_txqbody(priv)){
620                    /* dummy write for interrupt clear */
621                    rw_data =0;
622                    retval = ks7010_sdio_write(priv, DATA_WINDOW, &rw_data, sizeof(rw_data));
623                    if (retval) {
624                        DPRINTK(1, "write DATA_WINDOW Failed!!(%d)\n",retval);
625                    }
626                    status &= ~INT_WRITE_STATUS;
627                }
628                else{
629#endif
630                    if(atomic_read(&priv->psstatus.status)==PS_SNOOZE){
631                        if(cnt_txqbody(priv)){
632                            ks_wlan_hw_wakeup_request(priv);
633                            queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq, &priv->ks_wlan_hw.rw_wq, 1);
634                            return;
635                        }
636                    }
637                    else{
638                        tx_device_task((void *)priv);
639                    }
640// }
641            }
642        }while(rsize);
643    }
644
645intr_out:
646    queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq,&priv->ks_wlan_hw.rw_wq, 0);
647    return;
648}
649
650static int trx_device_init( ks_wlan_private *priv )
651{
652    /* initialize values (tx) */
653    priv->tx_dev.qtail = priv->tx_dev.qhead = 0;
654
655    /* initialize values (rx) */
656    priv->rx_dev.qtail = priv->rx_dev.qhead = 0;
657
658    /* initialize spinLock (tx,rx) */
659    spin_lock_init(&priv->tx_dev.tx_dev_lock);
660    spin_lock_init(&priv->rx_dev.rx_dev_lock);
661
662    tasklet_init(&priv->ks_wlan_hw.rx_bh_task, rx_event_task, (unsigned long)priv);
663
664    return 0;
665}
666
667static void trx_device_exit( ks_wlan_private *priv )
668{
669    struct tx_device_buffer *sp;
670
671    /* tx buffer clear */
672    while (cnt_txqbody(priv)>0) {
673        sp = &priv->tx_dev.tx_dev_buff[priv->tx_dev.qhead];
674        kfree(sp->sendp); /* allocated memory free */
675        if (sp->complete_handler != NULL) /* TX Complete */
676            (*sp->complete_handler)(sp->arg1, sp->arg2);
677        inc_txqhead(priv);
678    }
679
680    tasklet_kill(&priv->ks_wlan_hw.rx_bh_task);
681
682    return;
683}
684static int ks7010_sdio_update_index(ks_wlan_private *priv, u32 index)
685{
686    int rc=0;
687    int retval;
688    unsigned char *data_buf;
689    data_buf = NULL;
690
691    data_buf = kmalloc(sizeof(u32), GFP_KERNEL);
692    if(!data_buf){ rc = 1; goto error_out; }
693
694    memcpy(data_buf, &index, sizeof(index));
695    retval = ks7010_sdio_write(priv, WRITE_INDEX, data_buf, sizeof(index));
696    if(retval){ rc = 2; goto error_out; }
697
698    retval = ks7010_sdio_write(priv, READ_INDEX, data_buf, sizeof(index));
699    if(retval){ rc = 3; goto error_out; }
700error_out:
701    if(data_buf) kfree(data_buf);
702    return rc;
703}
704
705#define ROM_BUFF_SIZE (64*1024)
706static int ks7010_sdio_data_compare(ks_wlan_private *priv, u32 address,
707                    unsigned char *data, unsigned int size)
708{
709    int rc=0;
710    int retval;
711    unsigned char *read_buf;
712    read_buf = NULL;
713    read_buf = kmalloc(ROM_BUFF_SIZE, GFP_KERNEL);
714    if(!read_buf){ rc = 1; goto error_out; }
715    retval = ks7010_sdio_read(priv, address, read_buf, size);
716    if(retval){ rc = 2; goto error_out; }
717    retval = memcmp(data, read_buf, size);
718
719    if(retval){
720        DPRINTK(0, "data compare error (%d) \n",retval); rc = 3; goto error_out;
721    }
722error_out:
723    if(read_buf) kfree(read_buf);
724    return rc;
725}
726#ifndef NO_FIRMWARE_CLASS
727#include <linux/firmware.h>
728#endif
729static int ks79xx_upload_firmware(ks_wlan_private *priv, struct ks_sdio_card *card)
730{
731    unsigned int size, offset, n = 0;
732    unsigned char *rom_buf;
733    unsigned char rw_data =0;
734    int retval, rc=0;
735#ifndef NO_FIRMWARE_CLASS
736    int length;
737    const struct firmware *fw_entry = NULL;
738#else
739    int orgfsuid, orgfsgid;
740    struct file *srcf;
741    mm_segment_t orgfs;
742#endif
743
744    rom_buf = NULL;
745
746    /* buffer allocate */
747    rom_buf = kmalloc(ROM_BUFF_SIZE, GFP_KERNEL);
748    if(!rom_buf){ rc = 3; goto error_out0; }
749
750
751    sdio_claim_host(card->func);
752
753    /* Firmware running ? */
754    retval = ks7010_sdio_read(priv, GCR_A, &rw_data, sizeof(rw_data));
755    if(rw_data == GCR_A_RUN){
756        DPRINTK( 0, "MAC firmware running ...\n");
757        rc = 0;
758        goto error_out0;
759    }
760
761#ifndef NO_FIRMWARE_CLASS
762    if(request_firmware(&fw_entry, priv->reg.rom_file, &priv->ks_wlan_hw.sdio_card->func->dev)!=0){
763        DPRINTK(1,"error request_firmware() file=%s\n", priv->reg.rom_file);
764        return 1;
765    }
766    DPRINTK(4,"success request_firmware() file=%s size=%d\n", priv->reg.rom_file, fw_entry->size);
767    length = fw_entry->size;
768#else
769    orgfsuid=current->fsuid;
770    orgfsgid=current->fsgid;
771    current->fsuid=current->fsgid=0;
772    orgfs=get_fs();
773    set_fs(KERNEL_DS);
774
775    srcf = filp_open(romfile, O_RDONLY, 0);
776    if (IS_ERR(srcf)) {
777        DPRINTK(1, "error %ld opening %s\n", -PTR_ERR(srcf),romfile);
778        rc = 1;
779        goto error_out1;
780    }
781
782        if (!(srcf->f_op && srcf->f_op->read)) {
783                DPRINTK(1, "%s does not have a read method\n", romfile);
784                rc = 2;
785                goto error_out2;
786        }
787#endif
788
789    /* Load Program */
790    n = 0;
791        do {
792#ifndef NO_FIRMWARE_CLASS
793        if(length >= ROM_BUFF_SIZE){
794            size = ROM_BUFF_SIZE;
795            length = length - ROM_BUFF_SIZE;
796        }
797        else{
798            size=length;
799            length=0;
800        }
801        DPRINTK(4, "size = %d\n",size);
802        if(size == 0) break;
803        memcpy(rom_buf,fw_entry->data+n,size);
804#else
805        /* The object must have a read method */
806        size = srcf->f_op->read(srcf, rom_buf, ROM_BUFF_SIZE, &srcf->f_pos);
807        if (size < 0) {
808            DPRINTK(1, "Read %s error %d\n", priv->reg.rom_file, -retval);
809            rc = 5;
810            goto error_out2;
811        }
812        else if (size == 0) break;
813#endif
814        /* Update write index */
815        offset = n;
816        retval = ks7010_sdio_update_index(priv, KS7010_IRAM_ADDRESS+offset);
817        if(retval){ rc = 6; goto error_out1; }
818
819        /* Write data */
820        retval = ks7010_sdio_write(priv, DATA_WINDOW, rom_buf, size);
821        if(retval){ rc = 8; goto error_out1; }
822
823        /* compare */
824        retval = ks7010_sdio_data_compare(priv, DATA_WINDOW, rom_buf, size);
825        if(retval){ rc = 9; goto error_out1; }
826        n += size;
827
828       }while(size);
829
830    /* Remap request */
831    rw_data = GCR_A_REMAP;
832    retval = ks7010_sdio_write(priv, GCR_A, &rw_data, sizeof(rw_data));
833    if(retval){
834        rc = 11;
835        goto error_out1;
836    }
837    DPRINTK( 4, " REMAP Request : GCR_A=%02X\n", rw_data);
838
839    /* Firmware running check */
840    for (n = 0; n < 50; ++n) {
841        mdelay(10);/* wait_ms(10); */
842        retval = ks7010_sdio_read(priv, GCR_A, &rw_data, sizeof(rw_data));
843        if(retval){ rc = 11; goto error_out1; }
844        if(rw_data == GCR_A_RUN) break;
845    }
846    DPRINTK(4, "firmware wakeup (%d)!!!!\n",n);
847    if ((50) <= n) {
848        DPRINTK(1, "firmware can't start\n");
849                rc = 12;
850        goto error_out1;
851    }
852
853    rc = 0;
854
855#ifdef NO_FIRMWARE_CLASS
856 error_out2:
857    retval=filp_close(srcf ,NULL);
858    if (retval)
859        DPRINTK(1, "error %d closing %s\n", -retval,priv->reg.rom_file);
860
861 error_out1:
862    set_fs(orgfs);
863    current->fsuid=orgfsuid;
864    current->fsgid=orgfsgid;
865#else
866 error_out1:
867    release_firmware(fw_entry);
868#endif
869 error_out0:
870    sdio_release_host(card->func);
871    if(rom_buf)
872        kfree(rom_buf);
873    return rc;
874}
875
876static void card_init_task(struct work_struct *work)
877{
878    struct hw_info_t *hw;
879    struct ks_wlan_private *priv;
880
881    hw = container_of(work, struct hw_info_t, init_task);
882    priv = container_of(hw, struct ks_wlan_private, ks_wlan_hw);
883
884    DPRINTK(5,"\ncard_init_task()\n");
885
886    /* init_waitqueue_head(&priv->confirm_wait); */
887    init_completion(&priv->confirm_wait);
888
889    DPRINTK(5,"init_completion()\n");
890
891    /* get mac address & firmware version */
892    hostif_sme_enqueue(priv, SME_START);
893
894    DPRINTK(5,"hostif_sme_enqueu()\n");
895
896    if(!wait_for_completion_interruptible_timeout(&priv->confirm_wait,5*HZ)){
897        DPRINTK(1,"wait time out!! SME_START\n");
898    }
899
900    if(priv->mac_address_valid && priv->version_size){
901        priv->dev_state = DEVICE_STATE_PREINIT;
902    }
903
904    hostif_sme_enqueue(priv, SME_GET_EEPROM_CKSUM);
905
906    /* load initial wireless parameter */
907    hostif_sme_enqueue(priv, SME_STOP_REQUEST);
908
909    hostif_sme_enqueue(priv, SME_RTS_THRESHOLD_REQUEST);
910    hostif_sme_enqueue(priv, SME_FRAGMENTATION_THRESHOLD_REQUEST);
911
912    hostif_sme_enqueue(priv, SME_WEP_INDEX_REQUEST);
913    hostif_sme_enqueue(priv, SME_WEP_KEY1_REQUEST);
914    hostif_sme_enqueue(priv, SME_WEP_KEY2_REQUEST);
915    hostif_sme_enqueue(priv, SME_WEP_KEY3_REQUEST);
916    hostif_sme_enqueue(priv, SME_WEP_KEY4_REQUEST);
917
918    hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
919    hostif_sme_enqueue(priv, SME_RSN_ENABLED_REQUEST);
920    hostif_sme_enqueue(priv, SME_MODE_SET_REQUEST);
921    hostif_sme_enqueue(priv, SME_START_REQUEST);
922
923    if(!wait_for_completion_interruptible_timeout(&priv->confirm_wait,5*HZ)){
924        DPRINTK(1,"wait time out!! wireless parameter set\n");
925    }
926
927    if(priv->dev_state >= DEVICE_STATE_PREINIT){
928        DPRINTK(1, "DEVICE READY!!\n");
929        priv->dev_state = DEVICE_STATE_READY;
930        reg_net = register_netdev (priv->net_dev);
931        DPRINTK(3, "register_netdev=%d\n",reg_net);
932    }
933    else {
934        DPRINTK(1, "dev_state=%d\n",priv->dev_state);
935    }
936}
937
938static struct sdio_driver ks7010_sdio_driver = {
939    .name = "ks7910_sdio",
940    .id_table = if_sdio_ids,
941    .probe = ks7910_sdio_probe,
942    .remove = ks7910_sdio_remove,
943};
944
945
946extern int ks_wlan_net_start(struct net_device *dev);
947extern int ks_wlan_net_stop(struct net_device *dev);
948
949static int ks7910_sdio_probe(struct sdio_func *func, const struct sdio_device_id *device)
950{
951    ks_wlan_private *priv;
952    struct ks_sdio_card *card;
953    struct net_device *netdev;
954    unsigned char rw_data;
955    int i=0, ret;
956
957    DPRINTK(5, "ks7910_sdio_probe()\n");
958
959    priv = NULL;
960    netdev=NULL;
961
962
963    /* initilize ks_sdio_card */
964    card = kzalloc(sizeof(struct ks_sdio_card), GFP_KERNEL);
965    if (!card)
966        return -ENOMEM;
967
968    card->func = func;
969    card->model = 0x10;
970    spin_lock_init(&card->lock);
971
972    /* select model */
973    for (i = 0;i < ARRAY_SIZE(ks_sdio_models);i++) {
974        if (card->model == ks_sdio_models[i].model)
975            break;
976    }
977
978    if (i == ARRAY_SIZE(ks_sdio_models)) {
979        DPRINTK(5, "unkown card model 0x%x\n", card->model);
980        goto error;
981    }
982
983    card->firmware = ks_sdio_models[i].firmware;
984
985
986    /*** Initialize SDIO ***/
987    sdio_claim_host(func);
988
989    /* bus setting */
990    /* Issue config request to override clock rate */
991
992    /* function blocksize set */
993    ret = sdio_set_block_size(func, KS7010_IO_BLOCK_SIZE);
994    DPRINTK(5, "multi_block=%d sdio_set_block_size()=%d %d\n", func->card->cccr.multi_block, func->cur_blksize, ret);
995
996    /* Allocate the slot current */
997
998    /* function enable */
999    ret = sdio_enable_func(func);
1000    DPRINTK(5, "sdio_enable_func() %d\n", ret);
1001    if (ret)
1002        goto error_free_card;
1003
1004    /* interrupt disable */
1005    sdio_writeb(func, 0, INT_ENABLE, &ret);
1006    if (ret)
1007        goto error_free_card;
1008    sdio_writeb(func, 0xff, INT_PENDING, &ret);
1009    if (ret)
1010        goto error_disable_func;
1011
1012    /* setup interrupt handler */
1013    ret = sdio_claim_irq(func, ks_sdio_interrupt);
1014    if (ret)
1015        goto error_disable_func;
1016
1017    sdio_release_host(func);
1018
1019    sdio_set_drvdata(func, card);
1020
1021    DPRINTK(5, "class = 0x%X, vendor = 0x%X, "
1022        "device = 0x%X\n",
1023        func->class, func->vendor, func->device);
1024
1025
1026    /* private memory allocate */
1027    netdev = alloc_etherdev(sizeof(*priv));
1028    if (netdev == NULL) {
1029        printk (KERN_ERR "ks79xx : Unable to alloc new net device\n");
1030        goto error_release_irq;
1031    }
1032    if (dev_alloc_name(netdev, netdev->name) < 0) {
1033        printk (KERN_ERR "ks79xx : Couldn't get name!\n");
1034        goto error_free_netdev;
1035    }
1036
1037    priv = netdev_priv(netdev);
1038
1039    card->priv = priv;
1040    SET_NETDEV_DEV(netdev, &card->func->dev); /* for create sysfs symlinks */
1041
1042    /* private memory initialize */
1043    priv->ks_wlan_hw.sdio_card = card;
1044    init_completion(&priv->ks_wlan_hw.ks7010_sdio_wait);
1045    priv->ks_wlan_hw.read_buf = NULL;
1046    priv->ks_wlan_hw.read_buf = kmalloc(RX_DATA_SIZE, GFP_KERNEL);
1047    if(!priv->ks_wlan_hw.read_buf){
1048        goto error_free_netdev;
1049    }
1050    priv->dev_state = DEVICE_STATE_PREBOOT;
1051    priv->net_dev = netdev;
1052    priv->firmware_version[0] = '\0';
1053    priv->version_size = 0;
1054    priv->last_doze = jiffies; /* set current jiffies */
1055    priv->last_wakeup = jiffies;
1056    memset(&priv->nstats, 0, sizeof(priv->nstats));
1057    memset(&priv->wstats, 0, sizeof(priv->wstats));
1058
1059    /* sleep mode */
1060    atomic_set(&priv->sleepstatus.doze_request,0);
1061    atomic_set(&priv->sleepstatus.wakeup_request,0);
1062    atomic_set(&priv->sleepstatus.wakeup_request,0);
1063
1064    trx_device_init(priv);
1065    hostif_init(priv);
1066        ks_wlan_net_start(netdev);
1067
1068    /* Read config file */
1069    ret = ks_wlan_read_config_file(priv);
1070    if (ret) {
1071        printk(KERN_ERR "ks79xx: read configuration file failed !! retern code = %d\n", ret);
1072        goto error_free_read_buf;
1073    }
1074
1075    /* Upload firmware */
1076    ret = ks79xx_upload_firmware(priv, card); /* firmware load */
1077    if(ret){
1078        printk(KERN_ERR "ks79xx: firmware load failed !! retern code = %d\n", ret);
1079        goto error_free_read_buf;
1080    }
1081
1082    /* interrupt setting */
1083    /* clear Interrupt status write (ARMtoSD_InterruptPending FN1:00_0024) */
1084    rw_data = 0xff;
1085    sdio_claim_host(func);
1086    ret = ks7010_sdio_write(priv, INT_PENDING, &rw_data, sizeof(rw_data));
1087    sdio_release_host(func);
1088    if(ret){
1089        DPRINTK(1, " error : INT_PENDING=%02X\n", rw_data);
1090    }
1091    DPRINTK(4, " clear Interrupt : INT_PENDING=%02X\n", rw_data);
1092
1093
1094    /* enable ks7010sdio interrupt (INT_GCR_B|INT_READ_STATUS|INT_WRITE_STATUS) */
1095    rw_data = (INT_GCR_B|INT_READ_STATUS|INT_WRITE_STATUS);
1096    sdio_claim_host(func);
1097    ret = ks7010_sdio_write(priv, INT_ENABLE, &rw_data, sizeof(rw_data));
1098    sdio_release_host(func);
1099    if(ret){
1100        DPRINTK(1, " error : INT_ENABLE=%02X\n", rw_data);
1101    }
1102    DPRINTK(4, " enable Interrupt : INT_ENABLE=%02X\n", rw_data);
1103    priv->dev_state = DEVICE_STATE_BOOT;
1104
1105    priv->ks_wlan_hw.ks7010sdio_wq = create_workqueue("ks7010sdio_wq");
1106    if(!priv->ks_wlan_hw.ks7010sdio_wq){
1107        DPRINTK(1, "create_workqueue failed !!\n");
1108        goto error_free_read_buf;
1109    }
1110
1111    priv->ks_wlan_hw.ks7010sdio_init = create_singlethread_workqueue("ks7010sdio_init");
1112    if(!priv->ks_wlan_hw.ks7010sdio_init){
1113        DPRINTK(1, "create_workqueue failed !!\n");
1114        goto error_free_sdio_wq;
1115    }
1116
1117    INIT_WORK(&priv->ks_wlan_hw.init_task, card_init_task);
1118    INIT_DELAYED_WORK(&priv->ks_wlan_hw.rw_wq, ks7010_rw_function);
1119
1120    queue_work(priv->ks_wlan_hw.ks7010sdio_init, &priv->ks_wlan_hw.init_task);
1121
1122    return 0;
1123
1124error_free_sdio_wq:
1125    flush_workqueue(priv->ks_wlan_hw.ks7010sdio_wq);
1126    destroy_workqueue(priv->ks_wlan_hw.ks7010sdio_wq);
1127    priv->ks_wlan_hw.ks7010sdio_wq = NULL;
1128error_free_read_buf:
1129    kfree(priv->ks_wlan_hw.read_buf);
1130    priv->ks_wlan_hw.read_buf = NULL;
1131error_free_netdev:
1132    free_netdev(priv->net_dev);
1133    card->priv = NULL;
1134error_release_irq:
1135    sdio_claim_host(func);
1136    sdio_release_irq(func);
1137error_disable_func:
1138    sdio_disable_func(func);
1139error_free_card:
1140    sdio_release_host(func);
1141    sdio_set_drvdata(func, NULL);
1142    kfree(card);
1143error:
1144    return -ENODEV;
1145}
1146
1147static void ks7910_sdio_remove(struct sdio_func *func)
1148{
1149    int ret;
1150    struct ks_sdio_card *card;
1151    struct ks_wlan_private *priv;
1152    struct net_device *netdev;
1153    DPRINTK(1, "ks7910_sdio_remove()\n");
1154
1155    card = sdio_get_drvdata(func);
1156
1157    if(card == NULL)
1158        return;
1159
1160    DPRINTK(1, "priv = card->priv\n");
1161    priv = card->priv;
1162    netdev = priv->net_dev;
1163    if(priv){
1164        ks_wlan_net_stop(netdev);
1165        DPRINTK(1, "ks_wlan_net_stop\n");
1166
1167        /* interrupt disable */
1168        sdio_claim_host(func);
1169        sdio_writeb(func, 0, INT_ENABLE, &ret);
1170        sdio_writeb(func, 0xff, INT_PENDING, &ret);
1171        sdio_release_host(func);
1172        DPRINTK(1, "interrupt disable\n");
1173
1174        /* send stop request to MAC */
1175        {
1176            struct hostif_stop_request_t *pp;
1177            pp = (struct hostif_stop_request_t *)kzalloc(hif_align_size(sizeof(*pp)), GFP_KERNEL );
1178            if (pp==NULL) {
1179                DPRINTK(3,"allocate memory failed..\n");
1180                return; /* to do goto ni suru*/
1181            }
1182            pp->header.size = cpu_to_le16((uint16_t)(sizeof(*pp)-sizeof(pp->header.size)));
1183            pp->header.event = cpu_to_le16((uint16_t)HIF_STOP_REQ);
1184
1185            sdio_claim_host(func);
1186            write_to_device(priv, (unsigned char *) pp, hif_align_size(sizeof(*pp)));
1187            sdio_release_host(func);
1188            kfree(pp);
1189        }
1190        DPRINTK(1, "STOP Req\n");
1191
1192        if(priv->ks_wlan_hw.ks7010sdio_wq){
1193            flush_workqueue(priv->ks_wlan_hw.ks7010sdio_wq);
1194            destroy_workqueue(priv->ks_wlan_hw.ks7010sdio_wq);
1195        }
1196        DPRINTK(1, "destroy_workqueue(priv->ks_wlan_hw.ks7010sdio_wq);\n");
1197
1198        if(priv->ks_wlan_hw.ks7010sdio_init){
1199            flush_workqueue(priv->ks_wlan_hw.ks7010sdio_init);
1200            destroy_workqueue(priv->ks_wlan_hw.ks7010sdio_init);
1201        }
1202        DPRINTK(1, "destroy_workqueue(priv->ks_wlan_hw.ks7010sdio_init);\n");
1203
1204        hostif_exit(priv);
1205        DPRINTK(1, "hostif_exit\n");
1206
1207        if(!reg_net)
1208            unregister_netdev(netdev);
1209        DPRINTK(1, "unregister_netdev\n");
1210
1211        trx_device_exit(priv);
1212        if(priv->ks_wlan_hw.read_buf){
1213            kfree(priv->ks_wlan_hw.read_buf);
1214        }
1215        free_netdev(priv->net_dev);
1216        card->priv = NULL;
1217    }
1218
1219    sdio_claim_host(func);
1220    sdio_release_irq(func);
1221    DPRINTK(1, "sdio_release_irq()\n");
1222    sdio_disable_func(func);
1223    DPRINTK(1, "sdio_disable_func()\n");
1224    sdio_release_host(func);
1225
1226    sdio_set_drvdata(func, NULL);
1227
1228    kfree(card);
1229    DPRINTK(1, "kfree()\n");
1230
1231
1232    DPRINTK(5," Bye !!\n");
1233    return;
1234}
1235
1236static int __init ks7010_sdio_init( void )
1237{
1238    int status;
1239    printk(KERN_INFO "ks7010_sdio : %s %s\n" ,__DATE__,__TIME__);
1240
1241    /* register with bus driver core */
1242    status = sdio_register_driver(&ks7010_sdio_driver);
1243    if(status != 0){
1244        DPRINTK(1,"ks79xx_sdio : failed to register with bus driver, %d\n", status );
1245    }
1246    return status;
1247}
1248
1249static void __exit ks7010_sdio_exit( void )
1250{
1251    DPRINTK(5," \n");
1252    sdio_unregister_driver(&ks7010_sdio_driver);
1253    return;
1254}
1255
1256module_init(ks7010_sdio_init);
1257module_exit(ks7010_sdio_exit);
1258
1259MODULE_AUTHOR("Qi-Hardware based on KeyStream driver");
1260MODULE_DESCRIPTION("Driver for KeyStream, KS7010 based SDIO cards. ");
1261#ifdef MODULE_LICENSE
1262MODULE_LICENSE("GPL");
1263#endif
1264MODULE_SUPPORTED_DEVICE("KS7910");
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 */
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}
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 */
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
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_ */
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,