1*4882a593Smuzhiyun /****************************************************************************** 2*4882a593Smuzhiyun * 3*4882a593Smuzhiyun * Copyright(c) 2007 - 2019 Realtek Corporation. 4*4882a593Smuzhiyun * 5*4882a593Smuzhiyun * This program is free software; you can redistribute it and/or modify it 6*4882a593Smuzhiyun * under the terms of version 2 of the GNU General Public License as 7*4882a593Smuzhiyun * published by the Free Software Foundation. 8*4882a593Smuzhiyun * 9*4882a593Smuzhiyun * This program is distributed in the hope that it will be useful, but WITHOUT 10*4882a593Smuzhiyun * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11*4882a593Smuzhiyun * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12*4882a593Smuzhiyun * more details. 13*4882a593Smuzhiyun * 14*4882a593Smuzhiyun *****************************************************************************/ 15*4882a593Smuzhiyun #ifndef __RTW_TDLS_H_ 16*4882a593Smuzhiyun #define __RTW_TDLS_H_ 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun 19*4882a593Smuzhiyun #ifdef CONFIG_TDLS 20*4882a593Smuzhiyun /* TDLS STA state */ 21*4882a593Smuzhiyun 22*4882a593Smuzhiyun 23*4882a593Smuzhiyun /* TDLS Diect Link Establishment */ 24*4882a593Smuzhiyun #define TDLS_STATE_NONE 0x00000000 /* Default state */ 25*4882a593Smuzhiyun #define TDLS_INITIATOR_STATE BIT(28) /* 0x10000000 */ 26*4882a593Smuzhiyun #define TDLS_RESPONDER_STATE BIT(29) /* 0x20000000 */ 27*4882a593Smuzhiyun #define TDLS_LINKED_STATE BIT(30) /* 0x40000000 */ 28*4882a593Smuzhiyun /* TDLS PU Buffer STA */ 29*4882a593Smuzhiyun #define TDLS_WAIT_PTR_STATE BIT(24) /* 0x01000000 */ /* Waiting peer's TDLS_PEER_TRAFFIC_RESPONSE frame */ 30*4882a593Smuzhiyun /* TDLS Check ALive */ 31*4882a593Smuzhiyun #define TDLS_ALIVE_STATE BIT(20) /* 0x00100000 */ /* Check if peer sta is alived. */ 32*4882a593Smuzhiyun /* TDLS Channel Switch */ 33*4882a593Smuzhiyun #define TDLS_CH_SWITCH_PREPARE_STATE BIT(15) /* 0x00008000 */ 34*4882a593Smuzhiyun #define TDLS_CH_SWITCH_ON_STATE BIT(16) /* 0x00010000 */ 35*4882a593Smuzhiyun #define TDLS_PEER_AT_OFF_STATE BIT(17) /* 0x00020000 */ /* Could send pkt on target ch */ 36*4882a593Smuzhiyun #define TDLS_CH_SW_INITIATOR_STATE BIT(18) /* 0x00040000 */ /* Avoid duplicated or unconditional ch. switch rsp. */ 37*4882a593Smuzhiyun #define TDLS_WAIT_CH_RSP_STATE BIT(19) /* 0x00080000 */ /* Wait Ch. response as we are TDLS channel switch initiator */ 38*4882a593Smuzhiyun 39*4882a593Smuzhiyun 40*4882a593Smuzhiyun #define TDLS_TPK_RESEND_COUNT 86400 /*Unit: seconds */ 41*4882a593Smuzhiyun #define TDLS_CH_SWITCH_TIME 15 42*4882a593Smuzhiyun #define TDLS_CH_SWITCH_TIMEOUT 30 43*4882a593Smuzhiyun #define TDLS_CH_SWITCH_OPER_OFFLOAD_TIMEOUT 10 44*4882a593Smuzhiyun #define TDLS_SIGNAL_THRESH 0x20 45*4882a593Smuzhiyun #define TDLS_WATCHDOG_PERIOD 10 /* Periodically sending tdls discovery request in TDLS_WATCHDOG_PERIOD * 2 sec */ 46*4882a593Smuzhiyun #define TDLS_HANDSHAKE_TIME 3000 47*4882a593Smuzhiyun #define TDLS_PTI_TIME 7000 48*4882a593Smuzhiyun 49*4882a593Smuzhiyun #define TDLS_CH_SW_STAY_ON_BASE_CHNL_TIMEOUT 20 /* ms */ 50*4882a593Smuzhiyun #define TDLS_CH_SW_MONITOR_TIMEOUT 2000 /*ms */ 51*4882a593Smuzhiyun 52*4882a593Smuzhiyun #define TDLS_MIC_LEN 16 53*4882a593Smuzhiyun #define WPA_NONCE_LEN 32 54*4882a593Smuzhiyun #define TDLS_TIMEOUT_LEN 4 55*4882a593Smuzhiyun 56*4882a593Smuzhiyun enum TDLS_CH_SW_CHNL { 57*4882a593Smuzhiyun TDLS_CH_SW_BASE_CHNL = 0, 58*4882a593Smuzhiyun TDLS_CH_SW_OFF_CHNL 59*4882a593Smuzhiyun }; 60*4882a593Smuzhiyun 61*4882a593Smuzhiyun #define TDLS_MIC_CTRL_LEN 2 62*4882a593Smuzhiyun #define TDLS_FTIE_DATA_LEN (TDLS_MIC_CTRL_LEN + TDLS_MIC_LEN + \ 63*4882a593Smuzhiyun WPA_NONCE_LEN + WPA_NONCE_LEN) 64*4882a593Smuzhiyun struct wpa_tdls_ftie { 65*4882a593Smuzhiyun u8 ie_type; /* FTIE */ 66*4882a593Smuzhiyun u8 ie_len; 67*4882a593Smuzhiyun union { 68*4882a593Smuzhiyun struct { 69*4882a593Smuzhiyun u8 mic_ctrl[TDLS_MIC_CTRL_LEN]; 70*4882a593Smuzhiyun u8 mic[TDLS_MIC_LEN]; 71*4882a593Smuzhiyun u8 Anonce[WPA_NONCE_LEN]; /* Responder Nonce in TDLS */ 72*4882a593Smuzhiyun u8 Snonce[WPA_NONCE_LEN]; /* Initiator Nonce in TDLS */ 73*4882a593Smuzhiyun }; 74*4882a593Smuzhiyun struct { 75*4882a593Smuzhiyun u8 data[TDLS_FTIE_DATA_LEN]; 76*4882a593Smuzhiyun }; 77*4882a593Smuzhiyun }; 78*4882a593Smuzhiyun /* followed by optional elements */ 79*4882a593Smuzhiyun } ; 80*4882a593Smuzhiyun 81*4882a593Smuzhiyun struct wpa_tdls_lnkid { 82*4882a593Smuzhiyun u8 ie_type; /* Link Identifier IE */ 83*4882a593Smuzhiyun u8 ie_len; 84*4882a593Smuzhiyun u8 bssid[ETH_ALEN]; 85*4882a593Smuzhiyun u8 init_sta[ETH_ALEN]; 86*4882a593Smuzhiyun u8 resp_sta[ETH_ALEN]; 87*4882a593Smuzhiyun } ; 88*4882a593Smuzhiyun 89*4882a593Smuzhiyun static u8 TDLS_RSNIE[20] = { 0x01, 0x00, /* Version shall be set to 1 */ 90*4882a593Smuzhiyun 0x00, 0x0f, 0xac, 0x07, /* Group sipher suite */ 91*4882a593Smuzhiyun 0x01, 0x00, /* Pairwise cipher suite count */ 92*4882a593Smuzhiyun 0x00, 0x0f, 0xac, 0x04, /* Pairwise cipher suite list; CCMP only */ 93*4882a593Smuzhiyun 0x01, 0x00, /* AKM suite count */ 94*4882a593Smuzhiyun 0x00, 0x0f, 0xac, 0x07, /* TPK Handshake */ 95*4882a593Smuzhiyun 0x0c, 0x02, 96*4882a593Smuzhiyun /* PMKID shall not be present */ 97*4882a593Smuzhiyun }; 98*4882a593Smuzhiyun 99*4882a593Smuzhiyun static u8 TDLS_WMMIE[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01, 0x00}; /* Qos info all set zero */ 100*4882a593Smuzhiyun 101*4882a593Smuzhiyun static u8 TDLS_WMM_PARAM_IE[] = {0x00, 0x00, 0x03, 0xa4, 0x00, 0x00, 0x27, 0xa4, 0x00, 0x00, 0x42, 0x43, 0x5e, 0x00, 0x62, 0x32, 0x2f, 0x00}; 102*4882a593Smuzhiyun 103*4882a593Smuzhiyun static u8 TDLS_EXT_CAPIE[] = {0x00, 0x00, 0x00, 0x50, 0x20, 0x00, 0x00, 0x00}; /* bit(28), bit(30), bit(37) */ 104*4882a593Smuzhiyun 105*4882a593Smuzhiyun /* SRC: Supported Regulatory Classes */ 106*4882a593Smuzhiyun static u8 TDLS_SRC[] = { 0x01, 0x01, 0x02, 0x03, 0x04, 0x0c, 0x16, 0x17, 0x18, 0x19, 0x1b, 0x1c, 0x1d, 0x1e, 0x20, 0x21 }; 107*4882a593Smuzhiyun 108*4882a593Smuzhiyun int check_ap_tdls_prohibited(u8 *pframe, u8 pkt_len); 109*4882a593Smuzhiyun int check_ap_tdls_ch_switching_prohibited(u8 *pframe, u8 pkt_len); 110*4882a593Smuzhiyun 111*4882a593Smuzhiyun void rtw_set_tdls_enable(_adapter *padapter, u8 enable); 112*4882a593Smuzhiyun u8 rtw_is_tdls_enabled(_adapter *padapter); 113*4882a593Smuzhiyun u8 rtw_is_tdls_sta_existed(_adapter *padapter); 114*4882a593Smuzhiyun u8 rtw_tdls_is_setup_allowed(_adapter *padapter); 115*4882a593Smuzhiyun #ifdef CONFIG_TDLS_CH_SW 116*4882a593Smuzhiyun u8 rtw_tdls_is_chsw_allowed(_adapter *padapter); 117*4882a593Smuzhiyun #endif 118*4882a593Smuzhiyun 119*4882a593Smuzhiyun void rtw_tdls_set_link_established(_adapter *adapter, bool en); 120*4882a593Smuzhiyun void rtw_reset_tdls_info(_adapter *padapter); 121*4882a593Smuzhiyun int rtw_init_tdls_info(_adapter *padapter); 122*4882a593Smuzhiyun void rtw_free_tdls_info(struct tdls_info *ptdlsinfo); 123*4882a593Smuzhiyun void rtw_free_all_tdls_sta(_adapter *padapter, u8 enqueue_cmd); 124*4882a593Smuzhiyun void rtw_enable_tdls_func(_adapter *padapter); 125*4882a593Smuzhiyun void rtw_disable_tdls_func(_adapter *padapter, u8 enqueue_cmd); 126*4882a593Smuzhiyun int issue_nulldata_to_TDLS_peer_STA(_adapter *padapter, unsigned char *da, unsigned int power_mode, int try_cnt, int wait_ms); 127*4882a593Smuzhiyun void rtw_init_tdls_timer(_adapter *padapter, struct sta_info *psta); 128*4882a593Smuzhiyun void rtw_cancel_tdls_timer(struct sta_info *psta); 129*4882a593Smuzhiyun void rtw_tdls_teardown_pre_hdl(_adapter *padapter, struct sta_info *psta); 130*4882a593Smuzhiyun void rtw_tdls_teardown_post_hdl(_adapter *padapter, struct sta_info *psta, u8 enqueue_cmd); 131*4882a593Smuzhiyun 132*4882a593Smuzhiyun #ifdef CONFIG_TDLS_CH_SW 133*4882a593Smuzhiyun void rtw_tdls_set_ch_sw_oper_control(_adapter *padapter, u8 enable); 134*4882a593Smuzhiyun void rtw_tdls_ch_sw_back_to_base_chnl(_adapter *padapter); 135*4882a593Smuzhiyun s32 rtw_tdls_do_ch_sw(_adapter *padapter, struct sta_info *ptdls_sta, u8 chnl_type, u8 channel, u8 channel_offset, u16 bwmode, u16 ch_switch_time); 136*4882a593Smuzhiyun void rtw_tdls_chsw_oper_done(_adapter *padapter); 137*4882a593Smuzhiyun #endif 138*4882a593Smuzhiyun 139*4882a593Smuzhiyun #ifdef CONFIG_WFD 140*4882a593Smuzhiyun int issue_tunneled_probe_req(_adapter *padapter); 141*4882a593Smuzhiyun int issue_tunneled_probe_rsp(_adapter *padapter, union recv_frame *precv_frame); 142*4882a593Smuzhiyun #endif /* CONFIG_WFD */ 143*4882a593Smuzhiyun int issue_tdls_dis_req(_adapter *padapter, struct tdls_txmgmt *ptxmgmt); 144*4882a593Smuzhiyun int issue_tdls_setup_req(_adapter *padapter, struct tdls_txmgmt *ptxmgmt, int wait_ack); 145*4882a593Smuzhiyun int issue_tdls_setup_rsp(_adapter *padapter, struct tdls_txmgmt *ptxmgmt); 146*4882a593Smuzhiyun int issue_tdls_setup_cfm(_adapter *padapter, struct tdls_txmgmt *ptxmgmt); 147*4882a593Smuzhiyun int issue_tdls_dis_rsp(_adapter *padapter, struct tdls_txmgmt *ptxmgmt, u8 privacy); 148*4882a593Smuzhiyun int issue_tdls_teardown(_adapter *padapter, struct tdls_txmgmt *ptxmgmt, u8 wait_ack); 149*4882a593Smuzhiyun int issue_tdls_peer_traffic_rsp(_adapter *padapter, struct sta_info *psta, struct tdls_txmgmt *ptxmgmt); 150*4882a593Smuzhiyun int issue_tdls_peer_traffic_indication(_adapter *padapter, struct sta_info *psta); 151*4882a593Smuzhiyun #ifdef CONFIG_TDLS_CH_SW 152*4882a593Smuzhiyun int issue_tdls_ch_switch_req(_adapter *padapter, struct sta_info *ptdls_sta); 153*4882a593Smuzhiyun int issue_tdls_ch_switch_rsp(_adapter *padapter, struct tdls_txmgmt *ptxmgmt, int wait_ack); 154*4882a593Smuzhiyun #endif 155*4882a593Smuzhiyun sint On_TDLS_Dis_Rsp(_adapter *adapter, union recv_frame *precv_frame); 156*4882a593Smuzhiyun sint On_TDLS_Setup_Req(_adapter *adapter, union recv_frame *precv_frame, struct sta_info *ptdls_sta); 157*4882a593Smuzhiyun int On_TDLS_Setup_Rsp(_adapter *adapter, union recv_frame *precv_frame, struct sta_info *ptdls_sta); 158*4882a593Smuzhiyun int On_TDLS_Setup_Cfm(_adapter *adapter, union recv_frame *precv_frame, struct sta_info *ptdls_sta); 159*4882a593Smuzhiyun int On_TDLS_Dis_Req(_adapter *adapter, union recv_frame *precv_frame); 160*4882a593Smuzhiyun int On_TDLS_Teardown(_adapter *adapter, union recv_frame *precv_frame, struct sta_info *ptdls_sta); 161*4882a593Smuzhiyun int On_TDLS_Peer_Traffic_Indication(_adapter *adapter, union recv_frame *precv_frame, struct sta_info *ptdls_sta); 162*4882a593Smuzhiyun int On_TDLS_Peer_Traffic_Rsp(_adapter *adapter, union recv_frame *precv_frame, struct sta_info *ptdls_sta); 163*4882a593Smuzhiyun #ifdef CONFIG_TDLS_CH_SW 164*4882a593Smuzhiyun sint On_TDLS_Ch_Switch_Req(_adapter *adapter, union recv_frame *precv_frame, struct sta_info *ptdls_sta); 165*4882a593Smuzhiyun sint On_TDLS_Ch_Switch_Rsp(_adapter *adapter, union recv_frame *precv_frame, struct sta_info *ptdls_sta); 166*4882a593Smuzhiyun void rtw_build_tdls_ch_switch_req_ies(_adapter *padapter, struct xmit_frame *pxmitframe, u8 *pframe, struct tdls_txmgmt *ptxmgmt, struct sta_info *ptdls_sta); 167*4882a593Smuzhiyun void rtw_build_tdls_ch_switch_rsp_ies(_adapter *padapter, struct xmit_frame *pxmitframe, u8 *pframe, struct tdls_txmgmt *ptxmgmt, struct sta_info *ptdls_sta); 168*4882a593Smuzhiyun #endif 169*4882a593Smuzhiyun void rtw_build_tdls_setup_req_ies(_adapter *padapter, struct xmit_frame *pxmitframe, u8 *pframe, struct tdls_txmgmt *ptxmgmt, struct sta_info *ptdls_sta); 170*4882a593Smuzhiyun void rtw_build_tdls_setup_rsp_ies(_adapter *padapter, struct xmit_frame *pxmitframe, u8 *pframe, struct tdls_txmgmt *ptxmgmt, struct sta_info *ptdls_sta); 171*4882a593Smuzhiyun void rtw_build_tdls_setup_cfm_ies(_adapter *padapter, struct xmit_frame *pxmitframe, u8 *pframe, struct tdls_txmgmt *ptxmgmt, struct sta_info *ptdls_sta); 172*4882a593Smuzhiyun void rtw_build_tdls_teardown_ies(_adapter *padapter, struct xmit_frame *pxmitframe, u8 *pframe, struct tdls_txmgmt *ptxmgmt, struct sta_info *ptdls_sta); 173*4882a593Smuzhiyun void rtw_build_tdls_dis_req_ies(_adapter *padapter, struct xmit_frame *pxmitframe, u8 *pframe, struct tdls_txmgmt *ptxmgmt); 174*4882a593Smuzhiyun void rtw_build_tdls_dis_rsp_ies(_adapter *padapter, struct xmit_frame *pxmitframe, u8 *pframe, struct tdls_txmgmt *ptxmgmt, u8 privacy); 175*4882a593Smuzhiyun void rtw_build_tdls_peer_traffic_rsp_ies(_adapter *padapter, struct xmit_frame *pxmitframe, u8 *pframe, struct tdls_txmgmt *ptxmgmt, struct sta_info *ptdls_sta); 176*4882a593Smuzhiyun void rtw_build_tdls_peer_traffic_indication_ies(_adapter *padapter, struct xmit_frame *pxmitframe, u8 *pframe, struct tdls_txmgmt *ptxmgmt, struct sta_info *ptdls_sta); 177*4882a593Smuzhiyun void rtw_build_tunneled_probe_req_ies(_adapter *padapter, struct xmit_frame *pxmitframe, u8 *pframe); 178*4882a593Smuzhiyun void rtw_build_tunneled_probe_rsp_ies(_adapter *padapter, struct xmit_frame *pxmitframe, u8 *pframe); 179*4882a593Smuzhiyun 180*4882a593Smuzhiyun int rtw_tdls_is_driver_setup(_adapter *padapter); 181*4882a593Smuzhiyun void rtw_tdls_set_key(_adapter *padapter, struct sta_info *ptdls_sta); 182*4882a593Smuzhiyun const char *rtw_tdls_action_txt(enum TDLS_ACTION_FIELD action); 183*4882a593Smuzhiyun #endif /* CONFIG_TDLS */ 184*4882a593Smuzhiyun 185*4882a593Smuzhiyun #endif 186