GNU Linux-libre 4.9-gnu1
[releases.git] / drivers / staging / rtl8188eu / include / rtw_cmd.h
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  ******************************************************************************/
15 #ifndef __RTW_CMD_H_
16 #define __RTW_CMD_H_
17
18 #include <wlan_bssdef.h>
19 #include <rtw_rf.h>
20 #include <rtw_led.h>
21
22 #include <osdep_service.h>
23 #include <ieee80211.h> /*  <ieee80211/ieee80211.h> */
24
25 #define MAX_CMDSZ       1024
26 #define MAX_RSPSZ       512
27
28 #define CMDBUFF_ALIGN_SZ 512
29
30 struct cmd_obj {
31         struct adapter *padapter;
32         u16     cmdcode;
33         u8      res;
34         u8      *parmbuf;
35         u32     cmdsz;
36         u8      *rsp;
37         u32     rspsz;
38         struct list_head list;
39 };
40
41 struct cmd_priv {
42         struct completion cmd_queue_comp;
43         struct completion terminate_cmdthread_comp;
44         struct __queue cmd_queue;
45         u8 cmdthd_running;
46         struct adapter *padapter;
47 };
48
49 #define init_h2fwcmd_w_parm_no_rsp(pcmd, pparm, code) \
50 do {\
51         INIT_LIST_HEAD(&pcmd->list);\
52         pcmd->cmdcode = code;\
53         pcmd->parmbuf = (u8 *)(pparm);\
54         pcmd->cmdsz = sizeof(*pparm);\
55         pcmd->rsp = NULL;\
56         pcmd->rspsz = 0;\
57 } while (0)
58
59 u32 rtw_enqueue_cmd(struct cmd_priv *pcmdpriv, struct cmd_obj *obj);
60 struct cmd_obj *rtw_dequeue_cmd(struct __queue *queue);
61 void rtw_free_cmd_obj(struct cmd_obj *pcmd);
62
63 int rtw_cmd_thread(void *context);
64
65 int rtw_init_cmd_priv(struct cmd_priv *pcmdpriv);
66
67 enum rtw_drvextra_cmd_id {
68         NONE_WK_CID,
69         DYNAMIC_CHK_WK_CID,
70         DM_CTRL_WK_CID,
71         PBC_POLLING_WK_CID,
72         POWER_SAVING_CTRL_WK_CID,/* IPS,AUTOSuspend */
73         LPS_CTRL_WK_CID,
74         ANT_SELECT_WK_CID,
75         P2P_PS_WK_CID,
76         P2P_PROTO_WK_CID,
77         CHECK_HIQ_WK_CID,/* for softap mode, check hi queue if empty */
78         INTEl_WIDI_WK_CID,
79         C2H_WK_CID,
80         RTP_TIMER_CFG_WK_CID,
81         MAX_WK_CID
82 };
83
84 enum LPS_CTRL_TYPE {
85         LPS_CTRL_SCAN = 0,
86         LPS_CTRL_JOINBSS = 1,
87         LPS_CTRL_CONNECT = 2,
88         LPS_CTRL_DISCONNECT = 3,
89         LPS_CTRL_SPECIAL_PACKET = 4,
90         LPS_CTRL_LEAVE = 5,
91 };
92
93 enum RFINTFS {
94         SWSI,
95         HWSI,
96         HWPI,
97 };
98
99 /*
100 Caller Mode: Infra, Ad-HoC(C)
101
102 Notes: To disconnect the current associated BSS
103
104 Command Mode
105
106 */
107 struct disconnect_parm {
108         u32 deauth_timeout_ms;
109 };
110
111 struct  setopmode_parm {
112         u8      mode;
113         u8      rsvd[3];
114 };
115
116 /*
117 Caller Mode: AP, Ad-HoC, Infra
118
119 Notes: To ask RTL8711 performing site-survey
120
121 Command-Event Mode
122
123 */
124
125 #define RTW_SSID_SCAN_AMOUNT 9 /*  for WEXT_CSCAN_AMOUNT 9 */
126 #define RTW_CHANNEL_SCAN_AMOUNT (14+37)
127 struct sitesurvey_parm {
128         int scan_mode;  /* active: 1, passive: 0 */
129         u8 ssid_num;
130         u8 ch_num;
131         struct ndis_802_11_ssid ssid[RTW_SSID_SCAN_AMOUNT];
132         struct rtw_ieee80211_channel ch[RTW_CHANNEL_SCAN_AMOUNT];
133 };
134
135 /*
136 Caller Mode: Any
137
138 Notes: To set the auth type of RTL8711. open/shared/802.1x
139
140 Command Mode
141
142 */
143 struct setauth_parm {
144         u8 mode;  /* 0: legacy open, 1: legacy shared 2: 802.1x */
145         u8 _1x;   /* 0: PSK, 1: TLS */
146         u8 rsvd[2];
147 };
148
149 /*
150 Caller Mode: Infra
151
152 a. algorithm: wep40, wep104, tkip & aes
153 b. keytype: grp key/unicast key
154 c. key contents
155
156 when shared key ==> keyid is the camid
157 when 802.1x ==> keyid [0:1] ==> grp key
158 when 802.1x ==> keyid > 2 ==> unicast key
159
160 */
161 struct setkey_parm {
162         u8      algorithm;      /* could be none, wep40, TKIP, CCMP, wep104 */
163         u8      keyid;
164         u8      grpkey;         /* 1: this is the grpkey for 802.1x.
165                                  * 0: this is the unicast key for 802.1x */
166         u8      set_tx;         /* 1: main tx key for wep. 0: other key. */
167         u8      key[16];        /* this could be 40 or 104 */
168 };
169
170 /*
171 When in AP or Ad-Hoc mode, this is used to
172 allocate an sw/hw entry for a newly associated sta.
173
174 Command
175
176 when shared key ==> algorithm/keyid
177
178 */
179 struct set_stakey_parm {
180         u8      addr[ETH_ALEN];
181         u8      algorithm;
182         u8      id;/* currently for erasing cam entry if
183                     * algorithm == _NO_PRIVACY_ */
184         u8      key[16];
185 };
186
187 struct set_stakey_rsp {
188         u8      addr[ETH_ALEN];
189         u8      keyid;
190         u8      rsvd;
191 };
192
193 /*
194 Caller Ad-Hoc/AP
195
196 Command -Rsp(AID == CAMID) mode
197
198 This is to force fw to add an sta_data entry per driver's request.
199
200 FW will write an cam entry associated with it.
201
202 */
203 struct set_assocsta_parm {
204         u8      addr[ETH_ALEN];
205 };
206
207 struct set_assocsta_rsp {
208         u8      cam_id;
209         u8      rsvd[3];
210 };
211
212 /*
213         Notes: This command is used for H2C/C2H loopback testing
214
215         mac[0] == 0
216         ==> CMD mode, return H2C_SUCCESS.
217         The following condition must be ture under CMD mode
218                 mac[1] == mac[4], mac[2] == mac[3], mac[0]=mac[5]= 0;
219                 s0 == 0x1234, s1 == 0xabcd, w0 == 0x78563412, w1 == 0x5aa5def7;
220                 s2 == (b1 << 8 | b0);
221
222         mac[0] == 1
223         ==> CMD_RSP mode, return H2C_SUCCESS_RSP
224
225         The rsp layout shall be:
226         rsp:                    parm:
227                 mac[0]  =   mac[5];
228                 mac[1]  =   mac[4];
229                 mac[2]  =   mac[3];
230                 mac[3]  =   mac[2];
231                 mac[4]  =   mac[1];
232                 mac[5]  =   mac[0];
233                 s0              =   s1;
234                 s1              =   swap16(s0);
235                 w0              =       swap32(w1);
236                 b0              =       b1
237                 s2              =       s0 + s1
238                 b1              =       b0
239                 w1              =       w0
240
241         mac[0] ==       2
242         ==> CMD_EVENT mode, return      H2C_SUCCESS
243         The event layout shall be:
244         event:                  parm:
245                 mac[0]  =   mac[5];
246                 mac[1]  =   mac[4];
247                 mac[2]  =   event's seq no, starting from 1 to parm's marc[3]
248                 mac[3]  =   mac[2];
249                 mac[4]  =   mac[1];
250                 mac[5]  =   mac[0];
251                 s0              =   swap16(s0) - event.mac[2];
252                 s1              =   s1 + event.mac[2];
253                 w0              =       swap32(w0);
254                 b0              =       b1
255                 s2              =       s0 + event.mac[2]
256                 b1              =       b0
257                 w1              =       swap32(w1) - event.mac[2];
258
259                 parm->mac[3] is the total event counts that host requested.
260         event will be the same with the cmd's param.
261 */
262
263 /*  CMD param Format for driver extra cmd handler */
264 struct drvextra_cmd_parm {
265         int ec_id; /* extra cmd id */
266         int type_size; /*  Can use this field as the type id or command size */
267         unsigned char *pbuf;
268 };
269
270 struct addBaReq_parm {
271         unsigned int tid;
272         u8      addr[ETH_ALEN];
273 };
274
275 /*H2C Handler index: 46 */
276 struct set_ch_parm {
277         u8 ch;
278         u8 bw;
279         u8 ch_offset;
280 };
281
282 /*H2C Handler index: 59 */
283 struct SetChannelPlan_param {
284         u8 channel_plan;
285 };
286
287 /*
288
289 Result:
290 0x00: success
291 0x01: success, and check Response.
292 0x02: cmd ignored due to duplicated sequcne number
293 0x03: cmd dropped due to invalid cmd code
294 0x04: reserved.
295
296 */
297
298 #define H2C_SUCCESS             0x00
299 #define H2C_SUCCESS_RSP         0x01
300 #define H2C_DROPPED             0x03
301 #define H2C_PARAMETERS_ERROR    0x04
302 #define H2C_REJECTED            0x05
303
304 u8 rtw_sitesurvey_cmd(struct adapter *padapter, struct ndis_802_11_ssid *ssid,
305                       int ssid_num, struct rtw_ieee80211_channel *ch,
306                       int ch_num);
307 u8 rtw_createbss_cmd(struct adapter *padapter);
308 u8 rtw_setstakey_cmd(struct adapter *padapter, u8 *psta, u8 unicast_key);
309 u8 rtw_clearstakey_cmd(struct adapter *padapter, u8 *psta, u8 entry,
310                        u8 enqueue);
311 u8 rtw_joinbss_cmd(struct adapter *padapter, struct wlan_network *pnetwork);
312 u8 rtw_disassoc_cmd(struct adapter *padapter, u32 deauth_timeout_ms,
313                     bool enqueue);
314 u8 rtw_setopmode_cmd(struct adapter *padapter,
315                      enum ndis_802_11_network_infra networktype);
316 u8 rtw_addbareq_cmd(struct adapter *padapter, u8 tid, u8 *addr);
317
318 u8 rtw_dynamic_chk_wk_cmd(struct adapter *adapter);
319
320 u8 rtw_lps_ctrl_wk_cmd(struct adapter *padapter, u8 lps_ctrl_type, u8 enqueue);
321 u8 rtw_rpt_timer_cfg_cmd(struct adapter *padapter, u16 minRptTime);
322
323 u8 rtw_antenna_select_cmd(struct adapter *padapter, u8 antenna, u8 enqueue);
324 u8 rtw_ps_cmd(struct adapter *padapter);
325
326 #ifdef CONFIG_88EU_AP_MODE
327 u8 rtw_chk_hi_queue_cmd(struct adapter *padapter);
328 #endif
329
330 u8 rtw_set_chplan_cmd(struct adapter *padapter, u8 chplan, u8 enqueue);
331 u8 rtw_drvextra_cmd_hdl(struct adapter *padapter, unsigned char *pbuf);
332
333 void rtw_survey_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd);
334 void rtw_disassoc_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd);
335 void rtw_joinbss_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd);
336 void rtw_createbss_cmd_callback(struct adapter *adapt, struct cmd_obj *pcmd);
337 void rtw_readtssi_cmdrsp_callback(struct adapter *adapt, struct cmd_obj *cmd);
338
339 void rtw_setstaKey_cmdrsp_callback(struct adapter *adapt, struct cmd_obj *cmd);
340 void rtw_setassocsta_cmdrsp_callback(struct adapter *adapt, struct cmd_obj *cm);
341 void rtw_getrttbl_cmdrsp_callback(struct adapter *adapt, struct cmd_obj *cmd);
342
343 struct _cmd_callback {
344         u32     cmd_code;
345         void (*callback)(struct adapter  *padapter, struct cmd_obj *cmd);
346 };
347
348 enum rtw_h2c_cmd {
349         _JoinBss_CMD_,
350         _DisConnect_CMD_,
351         _CreateBss_CMD_,
352         _SetOpMode_CMD_,
353         _SiteSurvey_CMD_,
354         _SetAuth_CMD_,
355         _SetKey_CMD_,
356         _SetStaKey_CMD_,
357         _SetAssocSta_CMD_,
358         _AddBAReq_CMD_,
359         _SetChannel_CMD_,
360         _TX_Beacon_CMD_,
361         _Set_MLME_EVT_CMD_,
362         _Set_Drv_Extra_CMD_,
363         _SetChannelPlan_CMD_,
364
365         MAX_H2CCMD
366 };
367
368 #ifdef _RTW_CMD_C_
369 static struct _cmd_callback     rtw_cmd_callback[] = {
370         {_JoinBss_CMD_, &rtw_joinbss_cmd_callback},
371         {_DisConnect_CMD_, &rtw_disassoc_cmd_callback},
372         {_CreateBss_CMD_, &rtw_createbss_cmd_callback},
373         {_SetOpMode_CMD_, NULL},
374         {_SiteSurvey_CMD_, &rtw_survey_cmd_callback},
375         {_SetAuth_CMD_, NULL},
376         {_SetKey_CMD_, NULL},
377         {_SetStaKey_CMD_, &rtw_setstaKey_cmdrsp_callback},
378         {_SetAssocSta_CMD_, &rtw_setassocsta_cmdrsp_callback},
379         {_AddBAReq_CMD_, NULL},
380         {_SetChannel_CMD_, NULL},
381         {_TX_Beacon_CMD_, NULL},
382         {_Set_MLME_EVT_CMD_, NULL},
383         {_Set_Drv_Extra_CMD_, NULL},
384         {_SetChannelPlan_CMD_, NULL},
385 };
386 #endif
387
388 #endif /*  _CMD_H_ */