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