1 /******************************************************************************
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
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.
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
14 ******************************************************************************/
18 #include <wlan_bssdef.h>
21 #define C2H_MEM_SZ (16*1024)
23 #include <osdep_service.h>
24 #include <ieee80211.h> /* <ieee80211/ieee80211.h> */
27 #define MAX_CMDSZ 1024
29 #define MAX_EVTSZ 1024
31 #define CMDBUFF_ALIGN_SZ 512
34 struct work_struct work;
35 struct rtw_adapter *padapter;
45 struct workqueue_struct *wq;
49 struct rtw_adapter *padapter;
52 #define C2H_QUEUE_MAX_LEN 10
55 struct workqueue_struct *wq;
56 struct work_struct irq_wk;
59 #define init_h2fwcmd_w_parm_no_rsp(pcmd, pparm, code) \
61 pcmd->cmdcode = code;\
62 pcmd->parmbuf = (u8 *)(pparm);\
63 pcmd->cmdsz = sizeof (*pparm);\
76 * Do not reorder - this allows for struct evt_work to be passed on to
77 * rtw_c2h_wk_cmd23a() as a 'struct c2h_evt_hdr *' without making an
82 struct c2h_evt_hdr c2h_evt;
85 struct work_struct work;
86 struct rtw_adapter *adapter;
89 #define c2h_evt_exist(c2h_evt) ((c2h_evt)->id || (c2h_evt)->plen)
91 void rtw_evt_work(struct work_struct *work);
93 int rtw_enqueue_cmd23a(struct cmd_priv *pcmdpriv, struct cmd_obj *obj);
94 void rtw_free_cmd_obj23a(struct cmd_obj *pcmd);
96 int rtw_cmd_thread23a(void *context);
98 int rtw_init_cmd_priv23a(struct cmd_priv *pcmdpriv);
100 u32 rtw_init_evt_priv23a (struct evt_priv *pevtpriv);
101 void rtw_free_evt_priv23a (struct evt_priv *pevtpriv);
102 void rtw_evt_notify_isr(struct evt_priv *pevtpriv);
104 enum rtw_drvextra_cmd_id
110 POWER_SAVING_CTRL_WK_CID,/* IPS,AUTOSuspend */
115 CHECK_HIQ_WK_CID,/* for softap mode, check hi queue if empty */
117 RTP_TIMER_CFG_WK_CID,
126 LPS_CTRL_DISCONNECT=3,
127 LPS_CTRL_SPECIAL_PACKET=4,
138 Caller Mode: Infra, Ad-HoC(C)
140 Notes: To enter USB suspend mode
145 struct usb_suspend_parm {
146 u32 action;/* 1: sleep, 0:resume */
150 Caller Mode: Infra, Ad-HoC
152 Notes: To join a known BSS.
159 Caller Mode: Infra, Ad-HoC(C)
161 Notes: To disconnect the current associated BSS
166 struct disconnect_parm {
167 u32 deauth_timeout_ms;
170 struct setopmode_parm {
171 enum nl80211_iftype mode;
175 Caller Mode: AP, Ad-HoC, Infra
177 Notes: To ask RTL8711 performing site-survey
183 #define RTW_SSID_SCAN_AMOUNT 9 /* for WEXT_CSCAN_AMOUNT 9 */
184 #define RTW_CHANNEL_SCAN_AMOUNT (14+37)
185 struct sitesurvey_parm {
186 int scan_mode; /* active: 1, passive: 0 */
189 struct cfg80211_ssid ssid[RTW_SSID_SCAN_AMOUNT];
190 struct rtw_ieee80211_channel ch[RTW_CHANNEL_SCAN_AMOUNT];
196 Notes: To set the auth type of RTL8711. open/shared/802.1x
201 struct setauth_parm {
202 u8 mode; /* 0: legacy open, 1: legacy shared 2: 802.1x */
203 u8 _1x; /* 0: PSK, 1: TLS */
210 a. algorithm: wep40, wep104, tkip & aes
211 b. keytype: grp key/unicast key
214 when shared key ==> keyid is the camid
215 when 802.1x ==> keyid [0:1] ==> grp key
216 when 802.1x ==> keyid > 2 ==> unicast key
220 u32 algorithm; /* encryption algorithm, could be none, wep40, TKIP, CCMP, wep104 */
222 u8 grpkey; /* 1: this is the grpkey for 802.1x. 0: this is the unicast key for 802.1x */
223 u8 set_tx; /* 1: main tx key for wep. 0: other key. */
224 u8 key[16]; /* this could be 40 or 104 */
228 When in AP or Ad-Hoc mode, this is used to
229 allocate an sw/hw entry for a newly associated sta.
233 when shared key ==> algorithm/keyid
236 struct set_stakey_parm {
238 u8 id;/* currently for erasing cam entry if algorithm == _NO_PRIVACY_ */
243 struct set_stakey_rsp {
252 Command -Rsp(AID == CAMID) mode
254 This is to force fw to add an sta_data entry per driver's request.
256 FW will write an cam entry associated with it.
259 struct set_assocsta_parm {
263 struct set_assocsta_rsp {
273 This is to force fw to del an sta_data entry per driver's request
275 FW will invalidate the cam entry associated with it.
278 struct del_assocsta_parm {
283 Caller Mode: AP/Ad-HoC(M)
285 Notes: To notify fw that given staid has changed its power state
290 struct setstapwrstate_parm {
299 Notes: To setup the basic rate of RTL8711
304 struct setbasicrate_parm {
305 u8 basicrates[NumRates];
311 Notes: To read the current basic rate
316 struct getbasicrate_parm {
320 struct getbasicrate_rsp {
321 u8 basicrates[NumRates];
327 Notes: To setup the data rate of RTL8711
332 struct setdatarate_parm {
334 u8 datarates[NumRates];
340 Notes: To read the current data rate
345 struct getdatarate_parm {
349 struct getdatarate_rsp {
350 u8 datarates[NumRates];
356 AP: AP can use the info for the contents of beacon frame
357 Infra: STA can use the info when sitesurveying
362 Notes: To set the phy capability of the NIC
368 struct setphyinfo_parm {
369 struct regulatory_class class_sets[NUM_REGULATORYS];
373 struct getphyinfo_parm {
377 struct getphyinfo_rsp {
378 struct regulatory_class class_sets[NUM_REGULATORYS];
385 Notes: To set the channel/modem/band
386 This command will be used when channel/modem/band is changed.
399 Notes: To get the current setting of channel/modem/band
421 struct readTSSI_parm {
425 struct readTSSI_rsp {
429 struct writeBB_parm {
442 struct writeRF_parm {
447 struct getrfintfs_parm {
451 struct Tx_Beacon_param {
452 struct wlan_bssid_ex network;
455 /* CMD param Formart for driver extra cmd handler */
456 struct drvextra_cmd_parm {
457 int ec_id; /* extra cmd id */
458 int type_size; /* Can use this field as the type id or command size */
462 /*------------------- Below are used for RF/BB tunning ---------------------*/
464 struct setantenna_parm {
471 struct enrateadaptive_parm {
475 struct settxagctbl_parm {
476 u32 txagc[MAX_RATES_LENGTH];
479 struct gettxagctbl_parm {
483 struct gettxagctbl_rsp {
484 u32 txagc[MAX_RATES_LENGTH];
487 struct setagcctrl_parm {
488 u32 agcctrl; /* 0: pure hw, 1: fw */
491 struct setssup_parm {
492 u32 ss_ForceUp[MAX_RATES_LENGTH];
495 struct getssup_parm {
500 u8 ss_ForceUp[MAX_RATES_LENGTH];
503 struct setssdlevel_parm {
504 u8 ss_DLevel[MAX_RATES_LENGTH];
507 struct getssdlevel_parm {
511 struct getssdlevel_rsp {
512 u8 ss_DLevel[MAX_RATES_LENGTH];
515 struct setssulevel_parm {
516 u8 ss_ULevel[MAX_RATES_LENGTH];
519 struct getssulevel_parm {
523 struct getssulevel_rsp {
524 u8 ss_ULevel[MAX_RATES_LENGTH];
527 struct setcountjudge_parm {
528 u8 count_judge[MAX_RATES_LENGTH];
531 struct getcountjudge_parm {
535 struct getcountjudge_rsp {
536 u8 count_judge[MAX_RATES_LENGTH];
539 struct setratable_parm {
540 u8 ss_ForceUp[NumRates];
541 u8 ss_ULevel[NumRates];
542 u8 ss_DLevel[NumRates];
543 u8 count_judge[NumRates];
546 struct getratable_parm {
550 struct getratable_rsp {
551 u8 ss_ForceUp[NumRates];
552 u8 ss_ULevel[NumRates];
553 u8 ss_DLevel[NumRates];
554 u8 count_judge[NumRates];
557 /* to get TX,RX retry count */
558 struct gettxretrycnt_parm{
561 struct gettxretrycnt_rsp{
562 unsigned long tx_retrycnt;
565 struct getrxretrycnt_parm{
568 struct getrxretrycnt_rsp{
569 unsigned long rx_retrycnt;
572 /* to get BCNOK,BCNERR count */
573 struct getbcnokcnt_parm{
576 struct getbcnokcnt_rsp{
577 unsigned long bcnokcnt;
580 struct getbcnerrcnt_parm{
583 struct getbcnerrcnt_rsp{
584 unsigned long bcnerrcnt;
587 /* to get current TX power level */
588 struct getcurtxpwrlevel_parm{
592 struct getcurtxpwrlevel_rsp{
593 unsigned short tx_power;
596 struct setprobereqextraie_parm {
598 unsigned char ie_len;
602 struct setassocreqextraie_parm {
604 unsigned char ie_len;
608 struct setproberspextraie_parm {
610 unsigned char ie_len;
614 struct setassocrspextraie_parm {
616 unsigned char ie_len;
620 struct addBaReq_parm {
625 /*H2C Handler index: 46 */
632 /*H2C Handler index: 59 */
633 struct SetChannelPlan_param {
637 /*H2C Handler index: 60 */
638 struct LedBlink_param {
639 struct led_8723a *pLed;
642 /*H2C Handler index: 61 */
643 struct SetChannelSwitch_param {
647 /*H2C Handler index: 62 */
648 struct TDLSoption_param {
653 #define GEN_CMD_CODE(cmd) cmd ## _CMD_
660 0x01: sucess, and check Response.
661 0x02: cmd ignored due to duplicated sequcne number
662 0x03: cmd dropped due to invalid cmd code
667 #define H2C_RSP_OFFSET 512
669 #define H2C_SUCCESS 0x00
670 #define H2C_SUCCESS_RSP 0x01
671 #define H2C_DUPLICATED 0x02
672 #define H2C_DROPPED 0x03
673 #define H2C_PARAMETERS_ERROR 0x04
674 #define H2C_REJECTED 0x05
675 #define H2C_CMD_OVERFLOW 0x06
676 #define H2C_RESERVED 0x07
678 int rtw_setassocsta_cmd(struct rtw_adapter *padapter, u8 *mac_addr);
679 int rtw_setstandby_cmd(struct rtw_adapter *padapter, uint action);
680 int rtw_sitesurvey_cmd23a(struct rtw_adapter *padapter, struct cfg80211_ssid *ssid, int ssid_num, struct rtw_ieee80211_channel *ch, int ch_num);
681 int rtw_createbss_cmd23a(struct rtw_adapter *padapter);
682 int rtw_createbss_cmd23a_ex(struct rtw_adapter *padapter, unsigned char *pbss, unsigned int sz);
683 int rtw_setphy_cmd(struct rtw_adapter *padapter, u8 modem, u8 ch);
684 int rtw_setstakey_cmd23a(struct rtw_adapter *padapter, u8 *psta, u8 unicast_key);
685 int rtw_clearstakey_cmd23a(struct rtw_adapter *padapter, u8 *psta, u8 entry, u8 enqueue);
686 int rtw_joinbss_cmd23a(struct rtw_adapter *padapter, struct wlan_network* pnetwork);
687 int rtw_disassoc_cmd23a(struct rtw_adapter *padapter, u32 deauth_timeout_ms, bool enqueue);
688 int rtw_setopmode_cmd23a(struct rtw_adapter *padapter, enum nl80211_iftype ifmode);
689 int rtw_setdatarate_cmd(struct rtw_adapter *padapter, u8 *rateset);
690 int rtw_setbasicrate_cmd(struct rtw_adapter *padapter, u8 *rateset);
691 int rtw_setbbreg_cmd(struct rtw_adapter *padapter, u8 offset, u8 val);
692 int rtw_setrfreg_cmd(struct rtw_adapter *padapter, u8 offset, u32 val);
693 int rtw_getbbreg_cmd(struct rtw_adapter *padapter, u8 offset, u8 *pval);
694 int rtw_getrfreg_cmd(struct rtw_adapter *padapter, u8 offset, u8 *pval);
695 int rtw_setrfintfs_cmd(struct rtw_adapter *padapter, u8 mode);
696 int rtw_setrttbl_cmd(struct rtw_adapter *padapter, struct setratable_parm *prate_table);
697 int rtw_getrttbl_cmd(struct rtw_adapter *padapter, struct getratable_rsp *pval);
699 int rtw_gettssi_cmd(struct rtw_adapter *padapter, u8 offset, u8 *pval);
700 int rtw_setfwdig_cmd(struct rtw_adapter*padapter, u8 type);
701 int rtw_setfwra_cmd(struct rtw_adapter*padapter, u8 type);
703 int rtw_addbareq_cmd23a(struct rtw_adapter*padapter, u8 tid, u8 *addr);
705 int rtw_dynamic_chk_wk_cmd23a(struct rtw_adapter *adapter);
707 int rtw_lps_ctrl_wk_cmd23a(struct rtw_adapter*padapter, u8 lps_ctrl_type, u8 enqueue);
709 int rtw_ps_cmd23a(struct rtw_adapter*padapter);
711 #ifdef CONFIG_8723AU_AP_MODE
712 int rtw_chk_hi_queue_cmd23a(struct rtw_adapter*padapter);
715 int rtw_set_chplan_cmd(struct rtw_adapter*padapter, u8 chplan, u8 enqueue);
716 int rtw_led_blink_cmd(struct rtw_adapter*padapter, struct led_8723a *pLed);
717 int rtw_set_csa_cmd(struct rtw_adapter*padapter, u8 new_ch_no);
719 int rtw_c2h_wk_cmd23a(struct rtw_adapter *padapter, u8 *c2h_evt);
721 int rtw_drvextra_cmd_hdl23a(struct rtw_adapter *padapter, const u8 *pbuf);
723 void rtw_survey_cmd_callback23a(struct rtw_adapter *padapter, struct cmd_obj *pcmd);
724 void rtw_disassoc_cmd23a_callback(struct rtw_adapter *padapter, struct cmd_obj *pcmd);
725 void rtw_joinbss_cmd23a_callback(struct rtw_adapter *padapter, struct cmd_obj *pcmd);
726 void rtw_createbss_cmd23a_callback(struct rtw_adapter *padapter, struct cmd_obj *pcmd);
727 void rtw_getbbrfreg_cmdrsp_callback23a(struct rtw_adapter *padapter, struct cmd_obj *pcmd);
728 void rtw_readtssi_cmdrsp_callback(struct rtw_adapter* padapter, struct cmd_obj *pcmd);
730 void rtw_setstaKey_cmdrsp_callback23a(struct rtw_adapter *padapter, struct cmd_obj *pcmd);
731 void rtw_setassocsta_cmdrsp_callback23a(struct rtw_adapter *padapter, struct cmd_obj *pcmd);
732 void rtw_getrttbl_cmdrsp_callback(struct rtw_adapter *padapter, struct cmd_obj *pcmd);
734 struct _cmd_callback {
736 void (*callback)(struct rtw_adapter *padapter, struct cmd_obj *cmd);
740 GEN_CMD_CODE(_Read_MACREG) , /*0*/
741 GEN_CMD_CODE(_Write_MACREG) ,
742 GEN_CMD_CODE(_Read_BBREG) ,
743 GEN_CMD_CODE(_Write_BBREG) ,
744 GEN_CMD_CODE(_Read_RFREG) ,
745 GEN_CMD_CODE(_Write_RFREG) , /*5*/
746 GEN_CMD_CODE(_Read_EEPROM) ,
747 GEN_CMD_CODE(_Write_EEPROM) ,
748 GEN_CMD_CODE(_Read_EFUSE) ,
749 GEN_CMD_CODE(_Write_EFUSE) ,
751 GEN_CMD_CODE(_Read_CAM) , /*10*/
752 GEN_CMD_CODE(_Write_CAM) ,
753 GEN_CMD_CODE(_setBCNITV),
754 GEN_CMD_CODE(_setMBIDCFG),
755 GEN_CMD_CODE(_JoinBss), /*14*/
756 GEN_CMD_CODE(_DisConnect) , /*15*/
757 GEN_CMD_CODE(_CreateBss) ,
758 GEN_CMD_CODE(_SetOpMode) ,
759 GEN_CMD_CODE(_SiteSurvey), /*18*/
760 GEN_CMD_CODE(_SetAuth) ,
762 GEN_CMD_CODE(_SetKey) , /*20*/
763 GEN_CMD_CODE(_SetStaKey) ,
764 GEN_CMD_CODE(_SetAssocSta) ,
765 GEN_CMD_CODE(_DelAssocSta) ,
766 GEN_CMD_CODE(_SetStaPwrState) ,
767 GEN_CMD_CODE(_SetBasicRate) , /*25*/
768 GEN_CMD_CODE(_GetBasicRate) ,
769 GEN_CMD_CODE(_SetDataRate) ,
770 GEN_CMD_CODE(_GetDataRate) ,
771 GEN_CMD_CODE(_SetPhyInfo) ,
773 GEN_CMD_CODE(_GetPhyInfo) , /*30*/
774 GEN_CMD_CODE(_SetPhy) ,
775 GEN_CMD_CODE(_GetPhy) ,
776 GEN_CMD_CODE(_readRssi) ,
777 GEN_CMD_CODE(_readGain) ,
778 GEN_CMD_CODE(_SetAtim) , /*35*/
779 GEN_CMD_CODE(_SetPwrMode) ,
780 GEN_CMD_CODE(_JoinbssRpt),
781 GEN_CMD_CODE(_SetRaTable) ,
782 GEN_CMD_CODE(_GetRaTable) ,
784 GEN_CMD_CODE(_GetCCXReport), /*40*/
785 GEN_CMD_CODE(_GetDTMReport),
786 GEN_CMD_CODE(_GetTXRateStatistics),
787 GEN_CMD_CODE(_SetUsbSuspend),
788 GEN_CMD_CODE(_SetH2cLbk),
789 GEN_CMD_CODE(_AddBAReq) , /*45*/
790 GEN_CMD_CODE(_SetChannel), /*46*/
791 GEN_CMD_CODE(_SetTxPower),
792 GEN_CMD_CODE(_SwitchAntenna),
793 GEN_CMD_CODE(_SetCrystalCap),
794 GEN_CMD_CODE(_SetSingleCarrierTx), /*50*/
796 GEN_CMD_CODE(_SetSingleToneTx),/*51*/
797 GEN_CMD_CODE(_SetCarrierSuppressionTx),
798 GEN_CMD_CODE(_SetContinuousTx),
799 GEN_CMD_CODE(_SwitchBandwidth), /*54*/
800 GEN_CMD_CODE(_TX_Beacon), /*55*/
802 GEN_CMD_CODE(_Set_MLME_EVT), /*56*/
803 GEN_CMD_CODE(_Set_Drv_Extra), /*57*/
804 GEN_CMD_CODE(_Set_H2C_MSG), /*58*/
806 GEN_CMD_CODE(_SetChannelPlan), /*59*/
807 GEN_CMD_CODE(_LedBlink), /*60*/
809 GEN_CMD_CODE(_SetChannelSwitch), /*61*/
810 GEN_CMD_CODE(_TDLS), /*62*/
815 extern struct _cmd_callback rtw_cmd_callback[];