1 /******************************************************************************
3 * Copyright(c) 2007 - 2012 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 * 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
19 ******************************************************************************/
20 #define _RTW_MLME_EXT_C_
22 #include <drv_types.h>
23 #ifdef CONFIG_IOCTL_CFG80211
24 #include <rtw_wifi_regd.h>
25 #endif //CONFIG_IOCTL_CFG80211
28 struct mlme_handler mlme_sta_tbl[]={
29 {WIFI_ASSOCREQ, "OnAssocReq", &OnAssocReq},
30 {WIFI_ASSOCRSP, "OnAssocRsp", &OnAssocRsp},
31 {WIFI_REASSOCREQ, "OnReAssocReq", &OnAssocReq},
32 {WIFI_REASSOCRSP, "OnReAssocRsp", &OnAssocRsp},
33 {WIFI_PROBEREQ, "OnProbeReq", &OnProbeReq},
34 {WIFI_PROBERSP, "OnProbeRsp", &OnProbeRsp},
36 /*----------------------------------------------------------
38 -----------------------------------------------------------*/
39 {0, "DoReserved", &DoReserved},
40 {0, "DoReserved", &DoReserved},
41 {WIFI_BEACON, "OnBeacon", &OnBeacon},
42 {WIFI_ATIM, "OnATIM", &OnAtim},
43 {WIFI_DISASSOC, "OnDisassoc", &OnDisassoc},
44 {WIFI_AUTH, "OnAuth", &OnAuthClient},
45 {WIFI_DEAUTH, "OnDeAuth", &OnDeAuth},
46 {WIFI_ACTION, "OnAction", &OnAction},
47 {WIFI_ACTION_NOACK,"OnActionNoAck", &OnAction},
50 #ifdef _CONFIG_NATIVEAP_MLME_
51 struct mlme_handler mlme_ap_tbl[]={
52 {WIFI_ASSOCREQ, "OnAssocReq", &OnAssocReq},
53 {WIFI_ASSOCRSP, "OnAssocRsp", &OnAssocRsp},
54 {WIFI_REASSOCREQ, "OnReAssocReq", &OnAssocReq},
55 {WIFI_REASSOCRSP, "OnReAssocRsp", &OnAssocRsp},
56 {WIFI_PROBEREQ, "OnProbeReq", &OnProbeReq},
57 {WIFI_PROBERSP, "OnProbeRsp", &OnProbeRsp},
59 /*----------------------------------------------------------
61 -----------------------------------------------------------*/
62 {0, "DoReserved", &DoReserved},
63 {0, "DoReserved", &DoReserved},
64 {WIFI_BEACON, "OnBeacon", &OnBeacon},
65 {WIFI_ATIM, "OnATIM", &OnAtim},
66 {WIFI_DISASSOC, "OnDisassoc", &OnDisassoc},
67 {WIFI_AUTH, "OnAuth", &OnAuth},
68 {WIFI_DEAUTH, "OnDeAuth", &OnDeAuth},
69 {WIFI_ACTION, "OnAction", &OnAction},
70 {WIFI_ACTION_NOACK,"OnActionNoAck", &OnAction},
74 struct action_handler OnAction_tbl[]={
75 {RTW_WLAN_CATEGORY_SPECTRUM_MGMT, "ACTION_SPECTRUM_MGMT", on_action_spct},
76 {RTW_WLAN_CATEGORY_QOS, "ACTION_QOS", &OnAction_qos},
77 {RTW_WLAN_CATEGORY_DLS, "ACTION_DLS", &OnAction_dls},
78 {RTW_WLAN_CATEGORY_BACK, "ACTION_BACK", &OnAction_back},
79 {RTW_WLAN_CATEGORY_PUBLIC, "ACTION_PUBLIC", on_action_public},
80 {RTW_WLAN_CATEGORY_RADIO_MEASUREMENT, "ACTION_RADIO_MEASUREMENT", &DoReserved},
81 {RTW_WLAN_CATEGORY_FT, "ACTION_FT", &DoReserved},
82 {RTW_WLAN_CATEGORY_HT, "ACTION_HT", &OnAction_ht},
83 #ifdef CONFIG_IEEE80211W
84 {RTW_WLAN_CATEGORY_SA_QUERY, "ACTION_SA_QUERY", &OnAction_sa_query},
86 {RTW_WLAN_CATEGORY_SA_QUERY, "ACTION_SA_QUERY", &DoReserved},
87 #endif //CONFIG_IEEE80211W
88 //add for CONFIG_IEEE80211W
89 {RTW_WLAN_CATEGORY_UNPROTECTED_WNM, "ACTION_UNPROTECTED_WNM", &DoReserved},
90 {RTW_WLAN_CATEGORY_SELF_PROTECTED, "ACTION_SELF_PROTECTED", &DoReserved},
91 {RTW_WLAN_CATEGORY_WMM, "ACTION_WMM", &OnAction_wmm},
92 {RTW_WLAN_CATEGORY_VHT, "ACTION_VHT", &OnAction_vht},
93 {RTW_WLAN_CATEGORY_P2P, "ACTION_P2P", &OnAction_p2p},
97 u8 null_addr[ETH_ALEN]= {0,0,0,0,0,0};
99 /**************************************************
100 OUI definitions for the vendor specific IE
101 ***************************************************/
102 unsigned char RTW_WPA_OUI[] = {0x00, 0x50, 0xf2, 0x01};
103 unsigned char WMM_OUI[] = {0x00, 0x50, 0xf2, 0x02};
104 unsigned char WPS_OUI[] = {0x00, 0x50, 0xf2, 0x04};
105 unsigned char P2P_OUI[] = {0x50,0x6F,0x9A,0x09};
106 unsigned char WFD_OUI[] = {0x50,0x6F,0x9A,0x0A};
108 unsigned char WMM_INFO_OUI[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01};
109 unsigned char WMM_PARA_OUI[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01};
111 unsigned char WPA_TKIP_CIPHER[4] = {0x00, 0x50, 0xf2, 0x02};
112 unsigned char RSN_TKIP_CIPHER[4] = {0x00, 0x0f, 0xac, 0x02};
114 extern unsigned char REALTEK_96B_IE[];
116 /********************************************************
118 *********************************************************/
119 #ifdef CONFIG_DISABLE_MCS13TO15
120 unsigned char MCS_rate_2R_MCS13TO15_OFF[16] = {0xff, 0x1f, 0x0, 0x0, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
121 unsigned char MCS_rate_2R[16] = {0xff, 0xff, 0x0, 0x0, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
122 #else //CONFIG_DISABLE_MCS13TO15
123 unsigned char MCS_rate_2R[16] = {0xff, 0xff, 0x0, 0x0, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
124 #endif //CONFIG_DISABLE_MCS13TO15
125 unsigned char MCS_rate_1R[16] = {0xff, 0x00, 0x0, 0x0, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
127 /********************************************************
128 ChannelPlan definitions
129 *********************************************************/
130 /*static RT_CHANNEL_PLAN DefaultChannelPlan[RT_CHANNEL_DOMAIN_MAX] = {
131 {{1,2,3,4,5,6,7,8,9,10,11,36,40,44,48,52,56,60,64,100,104,108,112,116,132,136,140,149,153,157,161,165},32}, // 0x00, RT_CHANNEL_DOMAIN_FCC
132 {{1,2,3,4,5,6,7,8,9,10,11,36,40,44,48,52,56,60,64,100,104,108,112,116,136,140,149,153,157,161,165},31}, // 0x01, RT_CHANNEL_DOMAIN_IC
133 {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64,100,104,108,112,116,120,124,128,132,136,140},32}, // 0x02, RT_CHANNEL_DOMAIN_ETSI
134 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, // 0x03, RT_CHANNEL_DOMAIN_SPAIN
135 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, // 0x04, RT_CHANNEL_DOMAIN_FRANCE
136 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, // 0x05, RT_CHANNEL_DOMAIN_MKK
137 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, // 0x06, RT_CHANNEL_DOMAIN_MKK1
138 {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21}, // 0x07, RT_CHANNEL_DOMAIN_ISRAEL
139 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,44,48,52,56,60,64},22}, // 0x08, RT_CHANNEL_DOMAIN_TELEC
140 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14},14}, // 0x09, RT_CHANNEL_DOMAIN_GLOBAL_DOAMIN
141 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, // 0x0A, RT_CHANNEL_DOMAIN_WORLD_WIDE_13
142 {{1,2,3,4,5,6,7,8,9,10,11,56,60,64,100,104,108,112,116,136,140,149,153,157,161,165},26}, // 0x0B, RT_CHANNEL_DOMAIN_TAIWAN
143 {{1,2,3,4,5,6,7,8,9,10,11,12,13,149,153,157,161,165},18}, // 0x0C, RT_CHANNEL_DOMAIN_CHINA
144 {{1,2,3,4,5,6,7,8,9,10,11,36,40,44,48,52,56,60,64,149,153,157,161,165},24}, // 0x0D, RT_CHANNEL_DOMAIN_SINGAPORE_INDIA_MEXICO
145 {{1,2,3,4,5,6,7,8,9,10,11,36,40,44,48,52,56,60,64,100,104,108,112,116,120,124,149,153,157,161,165},31}, // 0x0E, RT_CHANNEL_DOMAIN_KOREA
146 {{1,2,3,4,5,6,7,8,9,10,11,36,40,44,48,52,56,60,64},19}, // 0x0F, RT_CHANNEL_DOMAIN_TURKEY
147 {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64,100,104,108,112,116,120,124,128,132,136,140},32}, // 0x10, RT_CHANNEL_DOMAIN_JAPAN
148 {{1,2,3,4,5,6,7,8,9,10,11,36,40,44,48,149,153,157,161,165},20}, // 0x11, RT_CHANNEL_DOMAIN_FCC_NO_DFS
149 {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48},17}, // 0x12, RT_CHANNEL_DOMAIN_JAPAN_NO_DFS
150 {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64,100,104,108,112,116,120,124,128,132,136,140,149,153,157,161,165},37}, // 0x13, RT_CHANNEL_DOMAIN_WORLD_WIDE_5G
151 {{1,2,3,4,5,6,7,8,9,10,11,56,60,64,149,153,157,161,165},19}, // 0x14, RT_CHANNEL_DOMAIN_TAIWAN_NO_DFS
154 static RT_CHANNEL_PLAN_2G RTW_ChannelPlan2G[RT_CHANNEL_DOMAIN_2G_MAX] = {
155 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, // 0x00, RT_CHANNEL_DOMAIN_2G_WORLD , Passive scan CH 12, 13
156 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, // 0x01, RT_CHANNEL_DOMAIN_2G_ETSI1
157 {{1,2,3,4,5,6,7,8,9,10,11},11}, // 0x02, RT_CHANNEL_DOMAIN_2G_FCC1
158 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14},14}, // 0x03, RT_CHANNEL_DOMAIN_2G_MIKK1
159 {{10,11,12,13},4}, // 0x04, RT_CHANNEL_DOMAIN_2G_ETSI2
160 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14},14}, // 0x05, RT_CHANNEL_DOMAIN_2G_GLOBAL , Passive scan CH 12, 13, 14
161 {{},0}, // 0x06, RT_CHANNEL_DOMAIN_2G_NULL
164 static RT_CHANNEL_PLAN_5G RTW_ChannelPlan5G[RT_CHANNEL_DOMAIN_5G_MAX] = {
165 {{},0}, // 0x00, RT_CHANNEL_DOMAIN_5G_NULL
166 {{36,40,44,48,52,56,60,64,100,104,108,112,116,120,124,128,132,136,140},19}, // 0x01, RT_CHANNEL_DOMAIN_5G_ETSI1
167 {{36,40,44,48,52,56,60,64,100,104,108,112,116,120,124,128,132,136,140,149,153,157,161,165},24}, // 0x02, RT_CHANNEL_DOMAIN_5G_ETSI2
168 {{36,40,44,48,52,56,60,64,100,104,108,112,116,120,124,128,132,149,153,157,161,165},22}, // 0x03, RT_CHANNEL_DOMAIN_5G_ETSI3
169 {{36,40,44,48,52,56,60,64,100,104,108,112,116,120,124,128,132,136,140,149,153,157,161,165},24}, // 0x04, RT_CHANNEL_DOMAIN_5G_FCC1
170 {{36,40,44,48,149,153,157,161,165},9}, // 0x05, RT_CHANNEL_DOMAIN_5G_FCC2
171 {{36,40,44,48,52,56,60,64,149,153,157,161,165},13}, // 0x06, RT_CHANNEL_DOMAIN_5G_FCC3
172 {{36,40,44,48,52,56,60,64,149,153,157,161},12}, // 0x07, RT_CHANNEL_DOMAIN_5G_FCC4
173 {{149,153,157,161,165},5}, // 0x08, RT_CHANNEL_DOMAIN_5G_FCC5
174 {{36,40,44,48,52,56,60,64},8}, // 0x09, RT_CHANNEL_DOMAIN_5G_FCC6
175 {{36,40,44,48,52,56,60,64,100,104,108,112,116,136,140,149,153,157,161,165},20}, // 0x0A, RT_CHANNEL_DOMAIN_5G_FCC7_IC1
176 {{36,40,44,48,52,56,60,64,100,104,108,112,116,120,124,149,153,157,161,165},20}, // 0x0B, RT_CHANNEL_DOMAIN_5G_KCC1
177 {{36,40,44,48,52,56,60,64,100,104,108,112,116,120,124,128,132,136,140},19}, // 0x0C, RT_CHANNEL_DOMAIN_5G_MKK1
178 {{36,40,44,48,52,56,60,64},8}, // 0x0D, RT_CHANNEL_DOMAIN_5G_MKK2
179 {{100,104,108,112,116,120,124,128,132,136,140},11}, // 0x0E, RT_CHANNEL_DOMAIN_5G_MKK3
180 {{56,60,64,100,104,108,112,116,136,140,149,153,157,161,165},15}, // 0x0F, RT_CHANNEL_DOMAIN_5G_NCC1
181 {{56,60,64,149,153,157,161,165},8}, // 0x10, RT_CHANNEL_DOMAIN_5G_NCC2
182 {{149,153,157,161,165},5}, // 0x11, RT_CHANNEL_DOMAIN_5G_NCC3
183 {{36,40,44,48},4}, // 0x12, RT_CHANNEL_DOMAIN_5G_ETSI4
184 {{36,40,44,48,52,56,60,64,100,104,108,112,116,136,140,149,153,157,161,165},20}, // 0x13, RT_CHANNEL_DOMAIN_5G_ETSI5
185 {{149,153,157,161},4}, // 0x14, RT_CHANNEL_DOMAIN_5G_FCC8
186 {{36,40,44,48,52,56,60,64},8}, // 0x15, RT_CHANNEL_DOMAIN_5G_ETSI6
187 {{36,40,44,48,52,56,60,64,149,153,157,161,165},13}, // 0x16, RT_CHANNEL_DOMAIN_5G_ETSI7
188 {{36,40,44,48,149,153,157,161,165},9}, // 0x17, RT_CHANNEL_DOMAIN_5G_ETSI8
189 {{100,104,108,112,116,120,124,128,132,136,140},11}, // 0x18, RT_CHANNEL_DOMAIN_5G_ETSI9
190 {{149,153,157,161,165},5}, // 0x19, RT_CHANNEL_DOMAIN_5G_ETSI10
191 {{36,40,44,48,52,56,60,64,132,136,140,149,153,157,161,165},16}, // 0x1A, RT_CHANNEL_DOMAIN_5G_ETSI11
192 {{52,56,60,64,100,104,108,112,116,132,136,140,149,153,157,161,165},17}, // 0x1B, RT_CHANNEL_DOMAIN_5G_NCC4
193 {{149,153,157,161},4}, // 0x1C, RT_CHANNEL_DOMAIN_5G_ETSI12
194 {{36,40,44,48,100,104,108,112,116,132,136,140,149,153,157,161,165},17}, // 0x1D, RT_CHANNEL_DOMAIN_5G_FCC9
195 {{36,40,44,48,100,104,108,112,116,132,136,140},12}, // 0x1E, RT_CHANNEL_DOMAIN_5G_ETSI13
196 {{36,40,44,48,52,56,60,64,100,104,108,112,116,132,136,140,149,153,157,161},20}, // 0x1F, RT_CHANNEL_DOMAIN_5G_FCC10
198 //===== Driver self defined for old channel plan Compatible ,Remember to modify if have new channel plan definition =====
199 {{36,40,44,48,52,56,60,64,100,104,108,112,116,132,136,140,149,153,157,161,165},21}, // 0x20, RT_CHANNEL_DOMAIN_5G_FCC
200 {{36,40,44,48},4}, // 0x21, RT_CHANNEL_DOMAIN_5G_JAPAN_NO_DFS
201 {{36,40,44,48,149,153,157,161},8}, // 0x22, RT_CHANNEL_DOMAIN_5G_FCC4_NO_DFS
204 static RT_CHANNEL_PLAN_MAP RTW_ChannelPlanMap[RT_CHANNEL_DOMAIN_MAX] = {
205 //===== 0x00 ~ 0x1F , Old Define =====
206 {0x02,0x20}, //0x00, RT_CHANNEL_DOMAIN_FCC
207 {0x02,0x0A}, //0x01, RT_CHANNEL_DOMAIN_IC
208 {0x01,0x01}, //0x02, RT_CHANNEL_DOMAIN_ETSI
209 {0x01,0x00}, //0x03, RT_CHANNEL_DOMAIN_SPAIN
210 {0x01,0x00}, //0x04, RT_CHANNEL_DOMAIN_FRANCE
211 {0x03,0x00}, //0x05, RT_CHANNEL_DOMAIN_MKK
212 {0x03,0x00}, //0x06, RT_CHANNEL_DOMAIN_MKK1
213 {0x01,0x09}, //0x07, RT_CHANNEL_DOMAIN_ISRAEL
214 {0x03,0x09}, //0x08, RT_CHANNEL_DOMAIN_TELEC
215 {0x03,0x00}, //0x09, RT_CHANNEL_DOMAIN_GLOBAL_DOAMIN
216 {0x00,0x00}, //0x0A, RT_CHANNEL_DOMAIN_WORLD_WIDE_13
217 {0x02,0x0F}, //0x0B, RT_CHANNEL_DOMAIN_TAIWAN
218 {0x01,0x08}, //0x0C, RT_CHANNEL_DOMAIN_CHINA
219 {0x02,0x06}, //0x0D, RT_CHANNEL_DOMAIN_SINGAPORE_INDIA_MEXICO
220 {0x02,0x0B}, //0x0E, RT_CHANNEL_DOMAIN_KOREA
221 {0x02,0x09}, //0x0F, RT_CHANNEL_DOMAIN_TURKEY
222 {0x01,0x01}, //0x10, RT_CHANNEL_DOMAIN_JAPAN
223 {0x02,0x05}, //0x11, RT_CHANNEL_DOMAIN_FCC_NO_DFS
224 {0x01,0x21}, //0x12, RT_CHANNEL_DOMAIN_JAPAN_NO_DFS
225 {0x00,0x04}, //0x13, RT_CHANNEL_DOMAIN_WORLD_WIDE_5G
226 {0x02,0x10}, //0x14, RT_CHANNEL_DOMAIN_TAIWAN_NO_DFS
227 {0x00,0x21}, //0x15, RT_CHANNEL_DOMAIN_ETSI_NO_DFS
228 {0x00,0x22}, //0x16, RT_CHANNEL_DOMAIN_KOREA_NO_DFS
229 {0x03,0x21}, //0x17, RT_CHANNEL_DOMAIN_JAPAN_NO_DFS
230 {0x06,0x08}, //0x18, RT_CHANNEL_DOMAIN_PAKISTAN_NO_DFS
231 {0x02,0x08}, //0x19, RT_CHANNEL_DOMAIN_TAIWAN2_NO_DFS
237 {0x06,0x04}, //0x1F, RT_CHANNEL_DOMAIN_WORLD_WIDE_ONLY_5G
238 //===== 0x20 ~ 0x7F ,New Define =====
239 {0x00,0x00}, //0x20, RT_CHANNEL_DOMAIN_WORLD_NULL
240 {0x01,0x00}, //0x21, RT_CHANNEL_DOMAIN_ETSI1_NULL
241 {0x02,0x00}, //0x22, RT_CHANNEL_DOMAIN_FCC1_NULL
242 {0x03,0x00}, //0x23, RT_CHANNEL_DOMAIN_MKK1_NULL
243 {0x04,0x00}, //0x24, RT_CHANNEL_DOMAIN_ETSI2_NULL
244 {0x02,0x04}, //0x25, RT_CHANNEL_DOMAIN_FCC1_FCC1
245 {0x00,0x01}, //0x26, RT_CHANNEL_DOMAIN_WORLD_ETSI1
246 {0x03,0x0C}, //0x27, RT_CHANNEL_DOMAIN_MKK1_MKK1
247 {0x00,0x0B}, //0x28, RT_CHANNEL_DOMAIN_WORLD_KCC1
248 {0x00,0x05}, //0x29, RT_CHANNEL_DOMAIN_WORLD_FCC2
255 {0x00,0x06}, //0x30, RT_CHANNEL_DOMAIN_WORLD_FCC3
256 {0x00,0x07}, //0x31, RT_CHANNEL_DOMAIN_WORLD_FCC4
257 {0x00,0x08}, //0x32, RT_CHANNEL_DOMAIN_WORLD_FCC5
258 {0x00,0x09}, //0x33, RT_CHANNEL_DOMAIN_WORLD_FCC6
259 {0x02,0x0A}, //0x34, RT_CHANNEL_DOMAIN_FCC1_FCC7
260 {0x00,0x02}, //0x35, RT_CHANNEL_DOMAIN_WORLD_ETSI2
261 {0x00,0x03}, //0x36, RT_CHANNEL_DOMAIN_WORLD_ETSI3
262 {0x03,0x0D}, //0x37, RT_CHANNEL_DOMAIN_MKK1_MKK2
263 {0x03,0x0E}, //0x38, RT_CHANNEL_DOMAIN_MKK1_MKK3
264 {0x02,0x0F}, //0x39, RT_CHANNEL_DOMAIN_FCC1_NCC1
271 {0x02,0x10}, //0x40, RT_CHANNEL_DOMAIN_FCC1_NCC2
272 {0x05,0x00}, //0x41, RT_CHANNEL_DOMAIN_GLOBAL_NULL
273 {0x01,0x12}, //0x42, RT_CHANNEL_DOMAIN_ETSI1_ETSI4
274 {0x02,0x05}, //0x43, RT_CHANNEL_DOMAIN_FCC1_FCC2
275 {0x02,0x11}, //0x44, RT_CHANNEL_DOMAIN_FCC1_NCC3
276 {0x00,0x13}, //0x45, RT_CHANNEL_DOMAIN_WORLD_ETSI5
277 {0x02,0x14}, //0x46, RT_CHANNEL_DOMAIN_FCC1_FCC8
278 {0x00,0x15}, //0x47, RT_CHANNEL_DOMAIN_WORLD_ETSI6
279 {0x00,0x16}, //0x48, RT_CHANNEL_DOMAIN_WORLD_ETSI7
280 {0x00,0x17}, //0x49, RT_CHANNEL_DOMAIN_WORLD_ETSI8
281 {0x00,0x18}, //0x50, RT_CHANNEL_DOMAIN_WORLD_ETSI9
282 {0x00,0x19}, //0x51, RT_CHANNEL_DOMAIN_WORLD_ETSI10
283 {0x00,0x1A}, //0x52, RT_CHANNEL_DOMAIN_WORLD_ETSI11
284 {0x02,0x1B}, //0x53, RT_CHANNEL_DOMAIN_FCC1_NCC4
285 {0x00,0x1C}, //0x54, RT_CHANNEL_DOMAIN_WORLD_ETSI12
286 {0x02,0x1D}, //0x55, RT_CHANNEL_DOMAIN_FCC1_FCC9
287 {0x00,0x1E}, //0x56, RT_CHANNEL_DOMAIN_WORLD_ETSI13
288 {0x02,0x1F}, //0x57, RT_CHANNEL_DOMAIN_FCC1_FCC10
291 static RT_CHANNEL_PLAN_MAP RTW_CHANNEL_PLAN_MAP_REALTEK_DEFINE = {0x03,0x02}; //use the conbination for max channel numbers
294 * Search the @param ch in given @param ch_set
295 * @ch_set: the given channel set
296 * @ch: the given channel number
298 * return the index of channel_num in channel_set, -1 if not found
300 int rtw_ch_set_search_ch(RT_CHANNEL_INFO *ch_set, const u32 ch)
303 for(i=0;ch_set[i].ChannelNum!=0;i++){
304 if(ch == ch_set[i].ChannelNum)
308 if(i >= ch_set[i].ChannelNum)
314 * Check the @param ch is fit with setband setting of @param adapter
315 * @adapter: the given adapter
316 * @ch: the given channel number
318 * return _TRUE when check valid, _FALSE not valid
320 bool rtw_mlme_band_check(_adapter *adapter, const u32 ch)
322 if (adapter->setband == GHZ24_50 /* 2.4G and 5G */
323 || (adapter->setband == GHZ_24 && ch < 35) /* 2.4G only */
324 || (adapter->setband == GHZ_50 && ch > 35) /* 5G only */
331 /****************************************************************************
333 Following are the initialization functions for WiFi MLME
335 *****************************************************************************/
337 int init_hw_mlme_ext(_adapter *padapter)
339 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
341 //set_opmode_cmd(padapter, infra_client_with_mlme);//removed
343 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
348 static void init_mlme_ext_priv_value(_adapter* padapter)
350 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
351 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
357 //unsigned char default_channel_set[MAX_CHANNEL_NUM] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 0, 0};
358 unsigned char mixed_datarate[NumRates] = {_1M_RATE_, _2M_RATE_, _5M_RATE_, _11M_RATE_, _6M_RATE_,_9M_RATE_, _12M_RATE_, _18M_RATE_, _24M_RATE_, _36M_RATE_, _48M_RATE_, _54M_RATE_, 0xff};
359 unsigned char mixed_basicrate[NumRates] ={_1M_RATE_, _2M_RATE_, _5M_RATE_, _11M_RATE_, _6M_RATE_, _12M_RATE_, _24M_RATE_, 0xff,};
361 ATOMIC_SET(&pmlmeext->event_seq, 0);
362 pmlmeext->mgnt_seq = 0;//reset to zero when disconnect at client mode
363 #ifdef CONFIG_IEEE80211W
364 pmlmeext->sa_query_seq = 0;
365 pmlmeext->mgnt_80211w_IPN=0;
366 pmlmeext->mgnt_80211w_IPN_rx=0;
367 #endif //CONFIG_IEEE80211W
368 pmlmeext->cur_channel = padapter->registrypriv.channel;
369 pmlmeext->cur_bwmode = CHANNEL_WIDTH_20;
370 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
374 pmlmeext->cur_wireless_mode = padapter->registrypriv.wireless_mode;
376 //_rtw_memcpy(pmlmeext->channel_set, DefaultChannelPlan[padapter->mlmepriv.ChannelPlan].Channel, DefaultChannelPlan[padapter->mlmepriv.ChannelPlan].Len);
377 //_rtw_memcpy(pmlmeext->channel_set, default_channel_set, MAX_CHANNEL_NUM);
378 _rtw_memcpy(pmlmeext->datarate, mixed_datarate, NumRates);
379 _rtw_memcpy(pmlmeext->basicrate, mixed_basicrate, NumRates);
381 if(pmlmeext->cur_channel > 14)
382 pmlmeext->tx_rate = IEEE80211_OFDM_RATE_6MB;
384 pmlmeext->tx_rate = IEEE80211_CCK_RATE_1MB;
386 pmlmeext->sitesurvey_res.state = SCAN_DISABLE;
387 pmlmeext->sitesurvey_res.channel_idx = 0;
388 pmlmeext->sitesurvey_res.bss_cnt = 0;
389 pmlmeext->scan_abort = _FALSE;
391 pmlmeinfo->state = WIFI_FW_NULL_STATE;
392 pmlmeinfo->reauth_count = 0;
393 pmlmeinfo->reassoc_count = 0;
394 pmlmeinfo->link_count = 0;
395 pmlmeinfo->auth_seq = 0;
396 pmlmeinfo->auth_algo = dot11AuthAlgrthm_Open;
397 pmlmeinfo->key_index = 0;
400 pmlmeinfo->enc_algo = _NO_PRIVACY_;
401 pmlmeinfo->authModeToggle = 0;
403 _rtw_memset(pmlmeinfo->chg_txt, 0, 128);
405 pmlmeinfo->slotTime = SHORT_SLOT_TIME;
406 pmlmeinfo->preamble_mode = PREAMBLE_AUTO;
408 pmlmeinfo->dialogToken = 0;
410 pmlmeext->action_public_rxseq = 0xffff;
411 pmlmeext->action_public_dialog_token = 0xff;
414 static int has_channel(RT_CHANNEL_INFO *channel_set,
419 for (i = 0; i < chanset_size; i++) {
420 if (channel_set[i].ChannelNum == chan) {
428 static void init_channel_list(_adapter *padapter, RT_CHANNEL_INFO *channel_set,
430 struct p2p_channels *channel_list) {
432 struct p2p_oper_class_map op_class[] = {
433 { IEEE80211G, 81, 1, 13, 1, BW20 },
434 { IEEE80211G, 82, 14, 14, 1, BW20 },
435 #if 0 /* Do not enable HT40 on 2 GHz */
436 { IEEE80211G, 83, 1, 9, 1, BW40PLUS },
437 { IEEE80211G, 84, 5, 13, 1, BW40MINUS },
439 { IEEE80211A, 115, 36, 48, 4, BW20 },
440 { IEEE80211A, 116, 36, 44, 8, BW40PLUS },
441 { IEEE80211A, 117, 40, 48, 8, BW40MINUS },
442 { IEEE80211A, 124, 149, 161, 4, BW20 },
443 { IEEE80211A, 125, 149, 169, 4, BW20 },
444 { IEEE80211A, 126, 149, 157, 8, BW40PLUS },
445 { IEEE80211A, 127, 153, 161, 8, BW40MINUS },
446 { -1, 0, 0, 0, 0, BW20 }
453 for (op = 0; op_class[op].op_class; op++) {
455 struct p2p_oper_class_map *o = &op_class[op];
456 struct p2p_reg_class *reg = NULL;
458 for (ch = o->min_chan; ch <= o->max_chan; ch += o->inc) {
459 if (!has_channel(channel_set, chanset_size, ch)) {
463 if ((0 == padapter->registrypriv.ht_enable) && (8 == o->inc))
466 if ((0 < (padapter->registrypriv.bw_mode & 0xf0)) &&
467 ((BW40MINUS == o->bw) || (BW40PLUS == o->bw)))
471 reg = &channel_list->reg_class[cla];
473 reg->reg_class = o->op_class;
476 reg->channel[reg->channels] = ch;
480 channel_list->reg_classes = cla;
484 static u8 init_channel_set(_adapter* padapter, u8 ChannelPlan, RT_CHANNEL_INFO *channel_set)
486 u8 index,chanset_size = 0;
487 u8 b5GBand = _FALSE, b2_4GBand = _FALSE;
488 u8 Index2G = 0, Index5G=0;
490 _rtw_memset(channel_set, 0, sizeof(RT_CHANNEL_INFO)*MAX_CHANNEL_NUM);
492 if(ChannelPlan >= RT_CHANNEL_DOMAIN_MAX && ChannelPlan != RT_CHANNEL_DOMAIN_REALTEK_DEFINE)
494 DBG_871X("ChannelPlan ID %x error !!!!!\n",ChannelPlan);
498 if(IsSupported24G(padapter->registrypriv.wireless_mode))
501 if(RT_CHANNEL_DOMAIN_REALTEK_DEFINE == ChannelPlan)
502 Index2G = RTW_CHANNEL_PLAN_MAP_REALTEK_DEFINE.Index2G;
504 Index2G = RTW_ChannelPlanMap[ChannelPlan].Index2G;
507 if(IsSupported5G(padapter->registrypriv.wireless_mode))
510 if(RT_CHANNEL_DOMAIN_REALTEK_DEFINE == ChannelPlan)
511 Index5G = RTW_CHANNEL_PLAN_MAP_REALTEK_DEFINE.Index5G;
513 Index5G = RTW_ChannelPlanMap[ChannelPlan].Index5G;
518 for(index=0;index<RTW_ChannelPlan2G[Index2G].Len;index++)
520 channel_set[chanset_size].ChannelNum = RTW_ChannelPlan2G[Index2G].Channel[index];
522 if( (RT_CHANNEL_DOMAIN_GLOBAL_DOAMIN == ChannelPlan) ||//Channel 1~11 is active, and 12~14 is passive
523 (RT_CHANNEL_DOMAIN_GLOBAL_NULL == ChannelPlan) )
525 if(channel_set[chanset_size].ChannelNum >= 1 && channel_set[chanset_size].ChannelNum <= 11)
526 channel_set[chanset_size].ScanType = SCAN_ACTIVE;
527 else if((channel_set[chanset_size].ChannelNum >= 12 && channel_set[chanset_size].ChannelNum <= 14))
528 channel_set[chanset_size].ScanType = SCAN_PASSIVE;
530 else if(RT_CHANNEL_DOMAIN_WORLD_WIDE_13 == ChannelPlan ||
531 RT_CHANNEL_DOMAIN_WORLD_WIDE_5G == ChannelPlan ||
532 RT_CHANNEL_DOMAIN_2G_WORLD == Index2G)// channel 12~13, passive scan
534 if(channel_set[chanset_size].ChannelNum <= 11)
535 channel_set[chanset_size].ScanType = SCAN_ACTIVE;
537 channel_set[chanset_size].ScanType = SCAN_PASSIVE;
541 channel_set[chanset_size].ScanType = SCAN_ACTIVE;
550 for(index=0;index<RTW_ChannelPlan5G[Index5G].Len;index++)
553 channel_set[chanset_size].ChannelNum = RTW_ChannelPlan5G[Index5G].Channel[index];
554 if ( channel_set[chanset_size].ChannelNum <= 48
555 || channel_set[chanset_size].ChannelNum >= 149 )
557 if(RT_CHANNEL_DOMAIN_WORLD_WIDE_5G == ChannelPlan)//passive scan for all 5G channels
558 channel_set[chanset_size].ScanType = SCAN_PASSIVE;
560 channel_set[chanset_size].ScanType = SCAN_ACTIVE;
564 channel_set[chanset_size].ScanType = SCAN_PASSIVE;
567 #else /* CONFIG_DFS */
568 if ( RTW_ChannelPlan5G[Index5G].Channel[index] <= 48
569 || RTW_ChannelPlan5G[Index5G].Channel[index] >= 149 ) {
570 channel_set[chanset_size].ChannelNum = RTW_ChannelPlan5G[Index5G].Channel[index];
571 if(RT_CHANNEL_DOMAIN_WORLD_WIDE_5G == ChannelPlan)//passive scan for all 5G channels
572 channel_set[chanset_size].ScanType = SCAN_PASSIVE;
574 channel_set[chanset_size].ScanType = SCAN_ACTIVE;
575 DBG_871X("%s(): channel_set[%d].ChannelNum = %d\n", __FUNCTION__, chanset_size, channel_set[chanset_size].ChannelNum);
578 #endif /* CONFIG_DFS */
582 DBG_871X("%s ChannelPlan ID %x Chan num:%d \n",__FUNCTION__,ChannelPlan,chanset_size);
586 int init_mlme_ext_priv(_adapter* padapter)
589 struct registry_priv* pregistrypriv = &padapter->registrypriv;
590 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
591 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
592 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
594 // We don't need to memset padapter->XXX to zero, because adapter is allocated by rtw_zvmalloc().
595 //_rtw_memset((u8 *)pmlmeext, 0, sizeof(struct mlme_ext_priv));
597 pmlmeext->padapter = padapter;
599 //fill_fwpriv(padapter, &(pmlmeext->fwpriv));
601 init_mlme_ext_priv_value(padapter);
602 pmlmeinfo->bAcceptAddbaReq = pregistrypriv->bAcceptAddbaReq;
604 init_mlme_ext_timer(padapter);
606 #ifdef CONFIG_AP_MODE
607 init_mlme_ap_info(padapter);
610 pmlmeext->max_chan_nums = init_channel_set(padapter, pmlmepriv->ChannelPlan,pmlmeext->channel_set);
611 init_channel_list(padapter, pmlmeext->channel_set, pmlmeext->max_chan_nums, &pmlmeext->channel_list);
612 pmlmeext->last_scan_time = 0;
613 pmlmeext->chan_scan_time = SURVEY_TO;
614 pmlmeext->mlmeext_init = _TRUE;
617 #ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
618 pmlmeext->active_keep_alive_check = _TRUE;
620 pmlmeext->active_keep_alive_check = _FALSE;
623 #ifdef DBG_FIXED_CHAN
624 pmlmeext->fixed_chan = 0xFF;
631 void free_mlme_ext_priv (struct mlme_ext_priv *pmlmeext)
633 _adapter *padapter = pmlmeext->padapter;
638 if (padapter->bDriverStopped == _TRUE)
640 _cancel_timer_ex(&pmlmeext->survey_timer);
641 _cancel_timer_ex(&pmlmeext->link_timer);
642 //_cancel_timer_ex(&pmlmeext->ADDBA_timer);
646 static u8 cmp_pkt_chnl_diff(_adapter *padapter,u8* pframe,uint packet_len)
647 { // if the channel is same, return 0. else return channel differential
651 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + _BEACON_IE_OFFSET_, _DSSET_IE_, &len, packet_len - _BEACON_IE_OFFSET_);
655 if(padapter->mlmeextpriv.cur_channel >= channel)
657 return (padapter->mlmeextpriv.cur_channel - channel);
661 return (channel-padapter->mlmeextpriv.cur_channel);
670 static void _mgt_dispatcher(_adapter *padapter, struct mlme_handler *ptable, union recv_frame *precv_frame)
672 u8 bc_addr[ETH_ALEN] = {0xff,0xff,0xff,0xff,0xff,0xff};
673 u8 *pframe = precv_frame->u.hdr.rx_data;
677 //receive the frames that ra(a1) is my address or ra(a1) is bc address.
678 if (!_rtw_memcmp(GetAddr1Ptr(pframe), myid(&padapter->eeprompriv), ETH_ALEN) &&
679 !_rtw_memcmp(GetAddr1Ptr(pframe), bc_addr, ETH_ALEN))
684 ptable->func(padapter, precv_frame);
689 void mgt_dispatcher(_adapter *padapter, union recv_frame *precv_frame)
692 struct mlme_handler *ptable;
693 #ifdef CONFIG_AP_MODE
694 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
695 #endif //CONFIG_AP_MODE
696 u8 bc_addr[ETH_ALEN] = {0xff,0xff,0xff,0xff,0xff,0xff};
697 u8 *pframe = precv_frame->u.hdr.rx_data;
698 struct sta_info *psta = rtw_get_stainfo(&padapter->stapriv, GetAddr2Ptr(pframe));
699 struct dvobj_priv *psdpriv = padapter->dvobj;
700 struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;
702 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
703 ("+mgt_dispatcher: type(0x%x) subtype(0x%x)\n",
704 GetFrameType(pframe), GetFrameSubType(pframe)));
709 pbuf = GetAddr1Ptr(pframe);
710 DBG_871X("A1-%x:%x:%x:%x:%x:%x\n", *pbuf, *(pbuf+1), *(pbuf+2), *(pbuf+3), *(pbuf+4), *(pbuf+5));
711 pbuf = GetAddr2Ptr(pframe);
712 DBG_871X("A2-%x:%x:%x:%x:%x:%x\n", *pbuf, *(pbuf+1), *(pbuf+2), *(pbuf+3), *(pbuf+4), *(pbuf+5));
713 pbuf = GetAddr3Ptr(pframe);
714 DBG_871X("A3-%x:%x:%x:%x:%x:%x\n", *pbuf, *(pbuf+1), *(pbuf+2), *(pbuf+3), *(pbuf+4), *(pbuf+5));
718 if (GetFrameType(pframe) != WIFI_MGT_TYPE)
720 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("mgt_dispatcher: type(0x%x) error!\n", GetFrameType(pframe)));
724 //receive the frames that ra(a1) is my address or ra(a1) is bc address.
725 if (!_rtw_memcmp(GetAddr1Ptr(pframe), myid(&padapter->eeprompriv), ETH_ALEN) &&
726 !_rtw_memcmp(GetAddr1Ptr(pframe), bc_addr, ETH_ALEN))
731 ptable = mlme_sta_tbl;
733 index = GetFrameSubType(pframe) >> 4;
736 if((index << 4)==WIFI_ACTION){
737 //category==public (4), action==TDLS_DISCOVERY_RESPONSE
738 if(*(pframe+24)==0x04 && *(pframe+25)==TDLS_DISCOVERY_RESPONSE){
739 DBG_871X("recv tdls discovery response frame from "MAC_FMT"\n", MAC_ARG(GetAddr2Ptr(pframe)));
740 On_TDLS_Dis_Rsp(padapter, precv_frame);
745 if (index >= (sizeof(mlme_sta_tbl) /sizeof(struct mlme_handler)))
747 RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("Currently we do not support reserved sub-fr-type=%d\n", index));
755 if (GetRetry(pframe))
757 if (precv_frame->u.hdr.attrib.seq_num == psta->RxMgmtFrameSeqNum)
759 /* drop the duplicate management frame */
760 pdbgpriv->dbg_rx_dup_mgt_frame_drop_count++;
761 DBG_871X("Drop duplicate management frame with seq_num = %d.\n", precv_frame->u.hdr.attrib.seq_num);
765 psta->RxMgmtFrameSeqNum = precv_frame->u.hdr.attrib.seq_num;
771 //RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("drop due to decache!\n"));
776 #ifdef CONFIG_AP_MODE
777 switch (GetFrameSubType(pframe))
780 if(check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
781 ptable->func = &OnAuth;
783 ptable->func = &OnAuthClient;
786 case WIFI_REASSOCREQ:
787 _mgt_dispatcher(padapter, ptable, precv_frame);
788 #ifdef CONFIG_HOSTAPD_MLME
789 if(check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
790 rtw_hostapd_mlme_rx(padapter, precv_frame);
794 if(check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
796 #ifdef CONFIG_HOSTAPD_MLME
797 rtw_hostapd_mlme_rx(padapter, precv_frame);
799 _mgt_dispatcher(padapter, ptable, precv_frame);
803 _mgt_dispatcher(padapter, ptable, precv_frame);
806 _mgt_dispatcher(padapter, ptable, precv_frame);
809 //if(check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
810 _mgt_dispatcher(padapter, ptable, precv_frame);
813 _mgt_dispatcher(padapter, ptable, precv_frame);
814 if(check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
815 rtw_hostapd_mlme_rx(padapter, precv_frame);
820 _mgt_dispatcher(padapter, ptable, precv_frame);
827 u32 p2p_listen_state_process(_adapter *padapter, unsigned char *da)
829 bool response = _TRUE;
831 #ifdef CONFIG_IOCTL_CFG80211
832 if( padapter->wdinfo.driver_interface == DRIVER_CFG80211 )
834 if(padapter->cfg80211_wdinfo.is_ro_ch == _FALSE
835 || rtw_get_oper_ch(padapter) != padapter->wdinfo.listen_channel
836 || adapter_wdev_data(padapter)->p2p_enabled == _FALSE
837 || padapter->mlmepriv.wps_probe_resp_ie == NULL
838 || padapter->mlmepriv.p2p_probe_resp_ie == NULL
841 #ifdef CONFIG_DEBUG_CFG80211
842 DBG_871X("DON'T issue_probersp_p2p: p2p_enabled:%d, wps_probe_resp_ie:%p, p2p_probe_resp_ie:%p, ",
843 adapter_wdev_data(padapter)->p2p_enabled,
844 padapter->mlmepriv.wps_probe_resp_ie,
845 padapter->mlmepriv.p2p_probe_resp_ie);
846 DBG_871X("is_ro_ch:%d, op_ch:%d, p2p_listen_channel:%d\n",
847 padapter->cfg80211_wdinfo.is_ro_ch,
848 rtw_get_oper_ch(padapter),
849 padapter->wdinfo.listen_channel);
855 #endif //CONFIG_IOCTL_CFG80211
856 if( padapter->wdinfo.driver_interface == DRIVER_WEXT )
858 // do nothing if the device name is empty
859 if ( !padapter->wdinfo.device_name_len )
865 if (response == _TRUE)
866 issue_probersp_p2p( padapter, da);
873 /****************************************************************************
875 Following are the callback functions for each subtype of the management frames
877 *****************************************************************************/
879 unsigned int OnProbeReq(_adapter *padapter, union recv_frame *precv_frame)
883 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
884 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
885 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
886 WLAN_BSSID_EX *cur = &(pmlmeinfo->network);
887 u8 *pframe = precv_frame->u.hdr.rx_data;
888 uint len = precv_frame->u.hdr.len;
889 u8 is_valid_p2p_probereq = _FALSE;
891 #ifdef CONFIG_ATMEL_RC_PATCH
892 u8 *target_ie=NULL, *wps_ie=NULL;
894 uint search_len = 0, wps_ielen = 0, target_ielen = 0;
895 struct sta_info *psta;
896 struct sta_priv *pstapriv = &padapter->stapriv;
901 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
902 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
903 u8 wifi_test_chk_rate = 1;
905 if ( !rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE) &&
906 !rtw_p2p_chk_state(pwdinfo, P2P_STATE_IDLE) &&
907 !rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT) &&
908 !rtw_p2p_chk_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH) &&
909 !rtw_p2p_chk_state(pwdinfo, P2P_STATE_SCAN)
912 // Commented by Albert 2011/03/17
913 // mcs_rate = 0 -> CCK 1M rate
914 // mcs_rate = 1 -> CCK 2M rate
915 // mcs_rate = 2 -> CCK 5.5M rate
916 // mcs_rate = 3 -> CCK 11M rate
917 // In the P2P mode, the driver should not support the CCK rate
919 // Commented by Kurt 2012/10/16
920 // IOT issue: Google Nexus7 use 1M rate to send p2p_probe_req after GO nego completed and Nexus7 is client
921 #ifdef CONFIG_WIFI_TEST
922 if ( pattrib->data_rate <= 3 )
924 wifi_test_chk_rate = 0;
926 #endif //CONFIG_WIFI_TEST
928 if( wifi_test_chk_rate == 1 )
930 if((is_valid_p2p_probereq = process_probe_req_p2p_ie(pwdinfo, pframe, len)) == _TRUE)
932 if(rtw_p2p_chk_role(pwdinfo, P2P_ROLE_DEVICE))
935 if( padapter->wdinfo.driver_interface == DRIVER_WEXT )
936 report_survey_event(padapter, precv_frame);
938 p2p_listen_state_process( padapter, get_sa(pframe));
943 if(rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO))
954 if(check_fwstate(pmlmepriv, WIFI_STATION_STATE))
959 if(check_fwstate(pmlmepriv, _FW_LINKED) == _FALSE &&
960 check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE|WIFI_AP_STATE)==_FALSE)
966 //DBG_871X("+OnProbeReq\n");
969 #ifdef CONFIG_ATMEL_RC_PATCH
970 if ((wps_ie = rtw_get_wps_ie(
971 pframe + WLAN_HDR_A3_LEN + _PROBEREQ_IE_OFFSET_,
972 len - WLAN_HDR_A3_LEN - _PROBEREQ_IE_OFFSET_,
973 NULL, &wps_ielen))) {
975 target_ie = rtw_get_wps_attr_content( wps_ie, wps_ielen, WPS_ATTR_MANUFACTURER, NULL, &target_ielen);
977 if ((target_ie && (target_ielen == 4)) && (_TRUE ==_rtw_memcmp((void *)target_ie, "Ozmo",4 ))) {
978 //psta->flag_atmel_rc = 1;
979 unsigned char *sa_addr = get_sa(pframe);
980 printk("%s: Find Ozmo RC -- %02x:%02x:%02x:%02x:%02x:%02x \n\n",
981 __func__, *sa_addr, *(sa_addr+1), *(sa_addr+2), *(sa_addr+3), *(sa_addr+4), *(sa_addr+5));
982 _rtw_memcpy( pstapriv->atmel_rc_pattern, get_sa(pframe), ETH_ALEN);
987 #ifdef CONFIG_AUTO_AP_MODE
988 if(check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE &&
989 pmlmepriv->cur_network.join_res == _TRUE)
992 struct sta_info *psta;
993 u8 *mac_addr, *peer_addr;
994 struct sta_priv *pstapriv = &padapter->stapriv;
995 u8 RC_OUI[4]={0x00,0xE0,0x4C,0x0A};
996 //EID[1] + EID_LEN[1] + RC_OUI[4] + MAC[6] + PairingID[2] + ChannelNum[2]
998 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + _PROBEREQ_IE_OFFSET_, _VENDOR_SPECIFIC_IE_, (int *)&ielen,
999 len - WLAN_HDR_A3_LEN - _PROBEREQ_IE_OFFSET_);
1001 if(!p || ielen !=14)
1002 goto _non_rc_device;
1004 if(!_rtw_memcmp(p+2, RC_OUI, sizeof(RC_OUI)))
1005 goto _non_rc_device;
1007 if(!_rtw_memcmp(p+6, get_sa(pframe), ETH_ALEN))
1009 DBG_871X("%s, do rc pairing ("MAC_FMT"), but mac addr mismatch!("MAC_FMT")\n", __FUNCTION__,
1010 MAC_ARG(get_sa(pframe)), MAC_ARG(p+6));
1012 goto _non_rc_device;
1015 DBG_871X("%s, got the pairing device("MAC_FMT")\n", __FUNCTION__, MAC_ARG(get_sa(pframe)));
1018 psta = rtw_get_stainfo(pstapriv, get_sa(pframe));
1021 // allocate a new one
1022 DBG_871X("going to alloc stainfo for rc="MAC_FMT"\n", MAC_ARG(get_sa(pframe)));
1023 psta = rtw_alloc_stainfo(pstapriv, get_sa(pframe));
1027 DBG_871X(" Exceed the upper limit of supported clients...\n");
1031 _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
1032 if (rtw_is_list_empty(&psta->asoc_list))
1034 psta->expire_to = pstapriv->expire_to;
1035 rtw_list_insert_tail(&psta->asoc_list, &pstapriv->asoc_list);
1036 pstapriv->asoc_list_cnt++;
1038 _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
1040 //generate pairing ID
1041 mac_addr = myid(&(padapter->eeprompriv));
1042 peer_addr = psta->hwaddr;
1043 psta->pid = (u16)(((mac_addr[4]<<8) + mac_addr[5]) + ((peer_addr[4]<<8) + peer_addr[5]));
1045 //update peer stainfo
1050 /* get a unique AID */
1051 if (psta->aid > 0) {
1052 DBG_871X("old AID %d\n", psta->aid);
1054 for (psta->aid = 1; psta->aid <= NUM_STA; psta->aid++)
1055 if (pstapriv->sta_aid[psta->aid - 1] == NULL)
1058 if (psta->aid > pstapriv->max_num_sta) {
1060 DBG_871X("no room for more AIDs\n");
1063 pstapriv->sta_aid[psta->aid - 1] = psta;
1064 DBG_871X("allocate new AID = (%d)\n", psta->aid);
1068 psta->qos_option = 1;
1069 psta->bw_mode = CHANNEL_WIDTH_20;
1070 psta->ieee8021x_blocked = _FALSE;
1071 #ifdef CONFIG_80211N_HT
1072 psta->htpriv.ht_option = _TRUE;
1073 psta->htpriv.ampdu_enable = _FALSE;
1074 psta->htpriv.sgi_20m = _FALSE;
1075 psta->htpriv.sgi_40m = _FALSE;
1076 psta->htpriv.ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
1077 psta->htpriv.agg_enable_bitmap = 0x0;//reset
1078 psta->htpriv.candidate_tid_bitmap = 0x0;//reset
1081 rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, _TRUE);
1083 _rtw_memset((void*)&psta->sta_stats, 0, sizeof(struct stainfo_stats));
1085 _enter_critical_bh(&psta->lock, &irqL);
1086 psta->state |= _FW_LINKED;
1087 _exit_critical_bh(&psta->lock, &irqL);
1089 report_add_sta_event(padapter, psta->hwaddr, psta->aid);
1093 issue_probersp(padapter, get_sa(pframe), _FALSE);
1103 #endif //CONFIG_AUTO_AP_MODE
1106 #ifdef CONFIG_CONCURRENT_MODE
1107 if(((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE) &&
1108 check_buddy_fwstate(padapter, _FW_UNDER_LINKING|_FW_UNDER_SURVEY))
1110 //don't process probe req
1115 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + _PROBEREQ_IE_OFFSET_, _SSID_IE_, (int *)&ielen,
1116 len - WLAN_HDR_A3_LEN - _PROBEREQ_IE_OFFSET_);
1119 //check (wildcard) SSID
1122 if(is_valid_p2p_probereq == _TRUE)
1124 goto _issue_probersp;
1127 if ( (ielen != 0 && _FALSE ==_rtw_memcmp((void *)(p+2), (void *)cur->Ssid.Ssid, cur->Ssid.SsidLength))
1128 || (ielen == 0 && pmlmeinfo->hidden_ssid_mode)
1135 if(((check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE &&
1136 pmlmepriv->cur_network.join_res == _TRUE)) || check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE))
1138 //DBG_871X("+issue_probersp during ap mode\n");
1139 issue_probersp(padapter, get_sa(pframe), is_valid_p2p_probereq);
1148 unsigned int OnProbeRsp(_adapter *padapter, union recv_frame *precv_frame)
1150 struct sta_info *psta;
1151 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1152 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1153 struct sta_priv *pstapriv = &padapter->stapriv;
1154 u8 *pframe = precv_frame->u.hdr.rx_data;
1156 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
1161 if(rtw_p2p_chk_state(pwdinfo, P2P_STATE_TX_PROVISION_DIS_REQ))
1163 if ( _TRUE == pwdinfo->tx_prov_disc_info.benable )
1165 if( _rtw_memcmp( pwdinfo->tx_prov_disc_info.peerIFAddr, GetAddr2Ptr(pframe), ETH_ALEN ) )
1167 if(rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT))
1169 pwdinfo->tx_prov_disc_info.benable = _FALSE;
1170 issue_p2p_provision_request( padapter,
1171 pwdinfo->tx_prov_disc_info.ssid.Ssid,
1172 pwdinfo->tx_prov_disc_info.ssid.SsidLength,
1173 pwdinfo->tx_prov_disc_info.peerDevAddr );
1175 else if ( rtw_p2p_chk_role(pwdinfo, P2P_ROLE_DEVICE) || rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO) )
1177 pwdinfo->tx_prov_disc_info.benable = _FALSE;
1178 issue_p2p_provision_request( padapter,
1181 pwdinfo->tx_prov_disc_info.peerDevAddr );
1187 else if(rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_ING))
1189 if ( _TRUE == pwdinfo->nego_req_info.benable )
1191 DBG_871X( "[%s] P2P State is GONEGO ING!\n", __FUNCTION__ );
1192 if( _rtw_memcmp( pwdinfo->nego_req_info.peerDevAddr, GetAddr2Ptr(pframe), ETH_ALEN ) )
1194 pwdinfo->nego_req_info.benable = _FALSE;
1195 issue_p2p_GO_request( padapter, pwdinfo->nego_req_info.peerDevAddr);
1199 else if( rtw_p2p_chk_state(pwdinfo, P2P_STATE_TX_INVITE_REQ ) )
1201 if ( _TRUE == pwdinfo->invitereq_info.benable )
1203 DBG_871X( "[%s] P2P_STATE_TX_INVITE_REQ!\n", __FUNCTION__ );
1204 if( _rtw_memcmp( pwdinfo->invitereq_info.peer_macaddr, GetAddr2Ptr(pframe), ETH_ALEN ) )
1206 pwdinfo->invitereq_info.benable = _FALSE;
1207 issue_p2p_invitation_request( padapter, pwdinfo->invitereq_info.peer_macaddr );
1214 if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS)
1216 report_survey_event(padapter, precv_frame);
1217 #ifdef CONFIG_CONCURRENT_MODE
1218 report_survey_event(padapter->pbuddy_adapter, precv_frame);
1220 #ifdef CONFIG_DUALMAC_CONCURRENT
1221 dc_report_survey_event(padapter, precv_frame);
1226 #if 0 //move to validate_recv_mgnt_frame
1227 if (_rtw_memcmp(GetAddr3Ptr(pframe), get_my_bssid(&pmlmeinfo->network), ETH_ALEN))
1229 if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS)
1231 if ((psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe))) != NULL)
1233 psta->sta_stats.rx_mgnt_pkts++;
1243 unsigned int OnBeacon(_adapter *padapter, union recv_frame *precv_frame)
1246 struct sta_info *psta;
1247 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1248 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1249 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1250 struct sta_priv *pstapriv = &padapter->stapriv;
1251 u8 *pframe = precv_frame->u.hdr.rx_data;
1252 uint len = precv_frame->u.hdr.len;
1253 WLAN_BSSID_EX *pbss;
1258 #ifdef CONFIG_ATTEMPT_TO_FIX_AP_BEACON_ERROR
1259 p = rtw_get_ie(pframe + sizeof(struct rtw_ieee80211_hdr_3addr) + _BEACON_IE_OFFSET_, _EXT_SUPPORTEDRATES_IE_, &ielen, precv_frame->u.hdr.len -sizeof(struct rtw_ieee80211_hdr_3addr) - _BEACON_IE_OFFSET_);
1260 if ((p != NULL) && (ielen > 0))
1262 if ((*(p + 1 + ielen) == 0x2D) && (*(p + 2 + ielen) != 0x2D))
1264 /* Invalid value 0x2D is detected in Extended Supported Rates (ESR) IE. Try to fix the IE length to avoid failed Beacon parsing. */
1265 DBG_871X("[WIFIDBG] Error in ESR IE is detected in Beacon of BSSID:"MAC_FMT". Fix the length of ESR IE to avoid failed Beacon parsing.\n", MAC_ARG(GetAddr3Ptr(pframe)));
1266 *(p + 1) = ielen - 1;
1271 if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS)
1273 report_survey_event(padapter, precv_frame);
1274 #ifdef CONFIG_CONCURRENT_MODE
1275 report_survey_event(padapter->pbuddy_adapter, precv_frame);
1278 #ifdef CONFIG_DUALMAC_CONCURRENT
1279 dc_report_survey_event(padapter, precv_frame);
1285 if (_rtw_memcmp(GetAddr3Ptr(pframe), get_my_bssid(&pmlmeinfo->network), ETH_ALEN))
1287 if (pmlmeinfo->state & WIFI_FW_AUTH_NULL)
1289 //we should update current network before auth, or some IE is wrong
1290 pbss = (WLAN_BSSID_EX*)rtw_malloc(sizeof(WLAN_BSSID_EX));
1292 if (collect_bss_info(padapter, precv_frame, pbss) == _SUCCESS) {
1293 update_network(&(pmlmepriv->cur_network.network), pbss, padapter, _TRUE);
1294 rtw_get_bcn_info(&(pmlmepriv->cur_network));
1296 rtw_mfree((u8*)pbss, sizeof(WLAN_BSSID_EX));
1299 //check the vendor of the assoc AP
1300 pmlmeinfo->assoc_AP_vendor = check_assoc_AP(pframe+sizeof(struct rtw_ieee80211_hdr_3addr), len-sizeof(struct rtw_ieee80211_hdr_3addr));
1303 update_TSF(pmlmeext, pframe, len);
1305 //reset for adaptive_early_32k
1306 pmlmeext->adaptive_tsf_done = _FALSE;
1307 pmlmeext->DrvBcnEarly = 0xff;
1308 pmlmeext->DrvBcnTimeOut = 0xff;
1309 pmlmeext->bcn_cnt = 0;
1310 _rtw_memset(pmlmeext->bcn_delay_cnt, 0, sizeof(pmlmeext->bcn_delay_cnt));
1311 _rtw_memset(pmlmeext->bcn_delay_ratio, 0, sizeof(pmlmeext->bcn_delay_ratio));
1313 #ifdef CONFIG_P2P_PS
1314 process_p2p_ps_ie(padapter, (pframe + WLAN_HDR_A3_LEN), (len - WLAN_HDR_A3_LEN));
1315 #endif //CONFIG_P2P_PS
1318 start_clnt_auth(padapter);
1323 if(((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE) && (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS))
1325 if ((psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe))) != NULL)
1327 #ifdef CONFIG_PATCH_JOIN_WRONG_CHANNEL
1328 //Merge from 8712 FW code
1329 if (cmp_pkt_chnl_diff(padapter,pframe,len) != 0)
1330 { // join wrong channel, deauth and reconnect
1331 issue_deauth(padapter, (&(pmlmeinfo->network))->MacAddress, WLAN_REASON_DEAUTH_LEAVING);
1333 report_del_sta_event(padapter,(&(pmlmeinfo->network))->MacAddress, WLAN_REASON_JOIN_WRONG_CHANNEL);
1334 pmlmeinfo->state &= (~WIFI_FW_ASSOC_SUCCESS);
1337 #endif //CONFIG_PATCH_JOIN_WRONG_CHANNEL
1339 ret = rtw_check_bcn_info(padapter, pframe, len);
1341 DBG_871X_LEVEL(_drv_always_, "ap has changed, disconnect now\n ");
1342 receive_disconnect(padapter, pmlmeinfo->network.MacAddress , 0);
1345 //update WMM, ERP in the beacon
1346 //todo: the timer is used instead of the number of the beacon received
1347 if ((sta_rx_pkts(psta) & 0xf) == 0)
1349 //DBG_871X("update_bcn_info\n");
1350 update_beacon_info(padapter, pframe, len, psta);
1353 adaptive_early_32k(pmlmeext, pframe, len);
1356 process_csa_ie(padapter, pframe, len); //channel switch announcement
1359 #ifdef CONFIG_P2P_PS
1360 process_p2p_ps_ie(padapter, (pframe + WLAN_HDR_A3_LEN), (len - WLAN_HDR_A3_LEN));
1361 #endif //CONFIG_P2P_PS
1363 #if 0 //move to validate_recv_mgnt_frame
1364 psta->sta_stats.rx_mgnt_pkts++;
1368 else if((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE)
1370 if ((psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe))) != NULL)
1372 //update WMM, ERP in the beacon
1373 //todo: the timer is used instead of the number of the beacon received
1374 if ((sta_rx_pkts(psta) & 0xf) == 0)
1376 //DBG_871X("update_bcn_info\n");
1377 update_beacon_info(padapter, pframe, len, psta);
1380 #if 0 //move to validate_recv_mgnt_frame
1381 psta->sta_stats.rx_mgnt_pkts++;
1386 //allocate a new CAM entry for IBSS station
1387 if ((cam_idx = allocate_fw_sta_entry(padapter)) == NUM_STA)
1389 goto _END_ONBEACON_;
1392 //get supported rate
1393 if (update_sta_support_rate(padapter, (pframe + WLAN_HDR_A3_LEN + _BEACON_IE_OFFSET_), (len - WLAN_HDR_A3_LEN - _BEACON_IE_OFFSET_), cam_idx) == _FAIL)
1395 pmlmeinfo->FW_sta_info[cam_idx].status = 0;
1396 goto _END_ONBEACON_;
1400 update_TSF(pmlmeext, pframe, len);
1402 //report sta add event
1403 report_add_sta_event(padapter, GetAddr2Ptr(pframe), cam_idx);
1414 unsigned int OnAuth(_adapter *padapter, union recv_frame *precv_frame)
1416 #ifdef CONFIG_AP_MODE
1418 unsigned int auth_mode, seq, ie_len;
1419 unsigned char *sa, *p;
1422 static struct sta_info stat;
1423 struct sta_info *pstat=NULL;
1424 struct sta_priv *pstapriv = &padapter->stapriv;
1425 struct security_priv *psecuritypriv = &padapter->securitypriv;
1426 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1427 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1428 u8 *pframe = precv_frame->u.hdr.rx_data;
1429 uint len = precv_frame->u.hdr.len;
1433 #ifdef CONFIG_CONCURRENT_MODE
1434 if(((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE) &&
1435 check_buddy_fwstate(padapter, _FW_UNDER_LINKING|_FW_UNDER_SURVEY))
1437 //don't process auth request;
1440 #endif //CONFIG_CONCURRENT_MODE
1442 if((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE)
1445 DBG_871X("+OnAuth\n");
1447 sa = GetAddr2Ptr(pframe);
1449 auth_mode = psecuritypriv->dot11AuthAlgrthm;
1451 if (GetPrivacy(pframe))
1454 struct rx_pkt_attrib *prxattrib = &(precv_frame->u.hdr.attrib);
1456 prxattrib->hdrlen = WLAN_HDR_A3_LEN;
1457 prxattrib->encrypt = _WEP40_;
1459 iv = pframe+prxattrib->hdrlen;
1460 prxattrib->key_index = ((iv[3]>>6)&0x3);
1462 prxattrib->iv_len = 4;
1463 prxattrib->icv_len = 4;
1465 rtw_wep_decrypt(padapter, (u8 *)precv_frame);
1470 algorithm = le16_to_cpu(*(u16*)((SIZE_PTR)pframe + WLAN_HDR_A3_LEN + offset));
1471 seq = le16_to_cpu(*(u16*)((SIZE_PTR)pframe + WLAN_HDR_A3_LEN + offset + 2));
1473 DBG_871X("auth alg=%x, seq=%X\n", algorithm, seq);
1475 if (auth_mode == 2 &&
1476 psecuritypriv->dot11PrivacyAlgrthm != _WEP40_ &&
1477 psecuritypriv->dot11PrivacyAlgrthm != _WEP104_)
1480 if ((algorithm > 0 && auth_mode == 0) || // rx a shared-key auth but shared not enabled
1481 (algorithm == 0 && auth_mode == 1) ) // rx a open-system auth but shared-key is enabled
1483 DBG_871X("auth rejected due to bad alg [alg=%d, auth_mib=%d] %02X%02X%02X%02X%02X%02X\n",
1484 algorithm, auth_mode, sa[0], sa[1], sa[2], sa[3], sa[4], sa[5]);
1486 status = _STATS_NO_SUPP_ALG_;
1492 phead = &priv->wlan_acl_list;
1493 plist = phead->next;
1495 if (acl_mode == 1) // 1: positive check, only those on acl_list can be connected.
1500 while(plist != phead)
1502 paclnode = list_entry(plist, struct rtw_wlan_acl_node, list);
1503 plist = plist->next;
1504 if (!memcmp((void *)sa, paclnode->addr, 6)) {
1505 if (paclnode->mode & 2) { // deny
1516 if (res != SUCCESS) {
1517 RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,"auth abort because ACL!\n");
1521 if(rtw_access_ctrl(padapter, sa) == _FALSE)
1523 status = _STATS_UNABLE_HANDLE_STA_;
1528 pstat = rtw_get_stainfo(pstapriv, sa);
1532 // allocate a new one
1533 DBG_871X("going to alloc stainfo for sa="MAC_FMT"\n", MAC_ARG(sa));
1534 pstat = rtw_alloc_stainfo(pstapriv, sa);
1537 DBG_871X(" Exceed the upper limit of supported clients...\n");
1538 status = _STATS_UNABLE_HANDLE_STA_;
1542 pstat->state = WIFI_FW_AUTH_NULL;
1543 pstat->auth_seq = 0;
1546 //pstat->capability = 0;
1551 _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
1552 if(rtw_is_list_empty(&pstat->asoc_list)==_FALSE)
1554 rtw_list_delete(&pstat->asoc_list);
1555 pstapriv->asoc_list_cnt--;
1556 if (pstat->expire_to > 0)
1558 //TODO: STA re_auth within expire_to
1561 _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
1564 //TODO: STA re_auth and auth timeout
1568 _enter_critical_bh(&pstapriv->auth_list_lock, &irqL);
1569 if (rtw_is_list_empty(&pstat->auth_list))
1572 rtw_list_insert_tail(&pstat->auth_list, &pstapriv->auth_list);
1573 pstapriv->auth_list_cnt++;
1575 _exit_critical_bh(&pstapriv->auth_list_lock, &irqL);
1577 if (pstat->auth_seq == 0)
1578 pstat->expire_to = pstapriv->auth_to;
1581 if ((pstat->auth_seq + 1) != seq)
1583 DBG_871X("(1)auth rejected because out of seq [rx_seq=%d, exp_seq=%d]!\n",
1584 seq, pstat->auth_seq+1);
1585 status = _STATS_OUT_OF_AUTH_SEQ_;
1589 if (algorithm==0 && (auth_mode == 0 || auth_mode == 2 || auth_mode == 3))
1593 pstat->state &= ~WIFI_FW_AUTH_NULL;
1594 pstat->state |= WIFI_FW_AUTH_SUCCESS;
1595 pstat->expire_to = pstapriv->assoc_to;
1596 pstat->authalg = algorithm;
1600 DBG_871X("(2)auth rejected because out of seq [rx_seq=%d, exp_seq=%d]!\n",
1601 seq, pstat->auth_seq+1);
1602 status = _STATS_OUT_OF_AUTH_SEQ_;
1606 else // shared system or auto authentication
1610 //prepare for the challenging txt...
1612 //get_random_bytes((void *)pstat->chg_txt, 128);//TODO:
1613 _rtw_memset((void *)pstat->chg_txt, 78, 128);
1615 pstat->state &= ~WIFI_FW_AUTH_NULL;
1616 pstat->state |= WIFI_FW_AUTH_STATE;
1617 pstat->authalg = algorithm;
1618 pstat->auth_seq = 2;
1622 //checking for challenging txt...
1623 DBG_871X("checking for challenging txt...\n");
1625 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + 4 + _AUTH_IE_OFFSET_ , _CHLGETXT_IE_, (int *)&ie_len,
1626 len - WLAN_HDR_A3_LEN - _AUTH_IE_OFFSET_ - 4);
1628 if((p==NULL) || (ie_len<=0))
1630 DBG_871X("auth rejected because challenge failure!(1)\n");
1631 status = _STATS_CHALLENGE_FAIL_;
1635 if (_rtw_memcmp((void *)(p + 2), pstat->chg_txt, 128))
1637 pstat->state &= (~WIFI_FW_AUTH_STATE);
1638 pstat->state |= WIFI_FW_AUTH_SUCCESS;
1639 // challenging txt is correct...
1640 pstat->expire_to = pstapriv->assoc_to;
1644 DBG_871X("auth rejected because challenge failure!\n");
1645 status = _STATS_CHALLENGE_FAIL_;
1651 DBG_871X("(3)auth rejected because out of seq [rx_seq=%d, exp_seq=%d]!\n",
1652 seq, pstat->auth_seq+1);
1653 status = _STATS_OUT_OF_AUTH_SEQ_;
1659 // Now, we are going to issue_auth...
1660 pstat->auth_seq = seq + 1;
1662 #ifdef CONFIG_NATIVEAP_MLME
1663 issue_auth(padapter, pstat, (unsigned short)(_STATS_SUCCESSFUL_));
1666 if (pstat->state & WIFI_FW_AUTH_SUCCESS)
1667 pstat->auth_seq = 0;
1675 rtw_free_stainfo(padapter , pstat);
1678 _rtw_memset((char *)pstat, '\0', sizeof(stat));
1679 pstat->auth_seq = 2;
1680 _rtw_memcpy(pstat->hwaddr, sa, 6);
1682 #ifdef CONFIG_NATIVEAP_MLME
1683 issue_auth(padapter, pstat, (unsigned short)status);
1691 unsigned int OnAuthClient(_adapter *padapter, union recv_frame *precv_frame)
1693 unsigned int seq, len, status, algthm, offset;
1695 unsigned int go2asoc = 0;
1696 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1697 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1698 u8 *pframe = precv_frame->u.hdr.rx_data;
1699 uint pkt_len = precv_frame->u.hdr.len;
1701 DBG_871X("%s\n", __FUNCTION__);
1703 //check A1 matches or not
1704 if (!_rtw_memcmp(myid(&(padapter->eeprompriv)), get_da(pframe), ETH_ALEN))
1707 if (!(pmlmeinfo->state & WIFI_FW_AUTH_STATE))
1710 offset = (GetPrivacy(pframe))? 4: 0;
1712 algthm = le16_to_cpu(*(unsigned short *)((SIZE_PTR)pframe + WLAN_HDR_A3_LEN + offset));
1713 seq = le16_to_cpu(*(unsigned short *)((SIZE_PTR)pframe + WLAN_HDR_A3_LEN + offset + 2));
1714 status = le16_to_cpu(*(unsigned short *)((SIZE_PTR)pframe + WLAN_HDR_A3_LEN + offset + 4));
1718 DBG_871X("clnt auth fail, status: %d\n", status);
1719 if(status == 13)//&& pmlmeinfo->auth_algo == dot11AuthAlgrthm_Auto)
1721 if(pmlmeinfo->auth_algo == dot11AuthAlgrthm_Shared)
1722 pmlmeinfo->auth_algo = dot11AuthAlgrthm_Open;
1724 pmlmeinfo->auth_algo = dot11AuthAlgrthm_Shared;
1725 //pmlmeinfo->reauth_count = 0;
1728 set_link_timer(pmlmeext, 1);
1734 if (pmlmeinfo->auth_algo == dot11AuthAlgrthm_Shared)
1736 // legendary shared system
1737 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + _AUTH_IE_OFFSET_, _CHLGETXT_IE_, (int *)&len,
1738 pkt_len - WLAN_HDR_A3_LEN - _AUTH_IE_OFFSET_);
1742 //DBG_871X("marc: no challenge text?\n");
1746 _rtw_memcpy((void *)(pmlmeinfo->chg_txt), (void *)(p + 2), len);
1747 pmlmeinfo->auth_seq = 3;
1748 issue_auth(padapter, NULL, 0);
1749 set_link_timer(pmlmeext, REAUTH_TO);
1761 if (pmlmeinfo->auth_algo == dot11AuthAlgrthm_Shared)
1772 // this is also illegal
1773 //DBG_871X("marc: clnt auth failed due to illegal seq=%x\n", seq);
1779 DBG_871X_LEVEL(_drv_always_, "auth success, start assoc\n");
1780 start_clnt_assoc(padapter);
1786 //pmlmeinfo->state &= ~(WIFI_FW_AUTH_STATE);
1792 unsigned int OnAssocReq(_adapter *padapter, union recv_frame *precv_frame)
1794 #ifdef CONFIG_AP_MODE
1796 u16 capab_info, listen_interval;
1797 struct rtw_ieee802_11_elems elems;
1798 struct sta_info *pstat;
1799 unsigned char reassoc, *p, *pos, *wpa_ie;
1800 unsigned char WMM_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01};
1801 int i, ie_len, wpa_ie_len, left;
1802 unsigned char supportRate[16];
1804 unsigned short status = _STATS_SUCCESSFUL_;
1805 unsigned short frame_type, ie_offset=0;
1806 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1807 struct security_priv *psecuritypriv = &padapter->securitypriv;
1808 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1809 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1810 WLAN_BSSID_EX *cur = &(pmlmeinfo->network);
1811 struct sta_priv *pstapriv = &padapter->stapriv;
1812 u8 *pframe = precv_frame->u.hdr.rx_data;
1813 uint pkt_len = precv_frame->u.hdr.len;
1815 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
1816 u8 p2p_status_code = P2P_STATUS_SUCCESS;
1820 u8 wfd_ie[ 128 ] = { 0x00 };
1822 #endif // CONFIG_WFD
1825 #ifdef CONFIG_CONCURRENT_MODE
1826 if(((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE) &&
1827 check_buddy_fwstate(padapter, _FW_UNDER_LINKING|_FW_UNDER_SURVEY))
1829 //don't process assoc request;
1832 #endif //CONFIG_CONCURRENT_MODE
1834 if((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE)
1837 frame_type = GetFrameSubType(pframe);
1838 if (frame_type == WIFI_ASSOCREQ)
1841 ie_offset = _ASOCREQ_IE_OFFSET_;
1843 else // WIFI_REASSOCREQ
1846 ie_offset = _REASOCREQ_IE_OFFSET_;
1850 if (pkt_len < IEEE80211_3ADDR_LEN + ie_offset) {
1851 DBG_871X("handle_assoc(reassoc=%d) - too short payload (len=%lu)"
1852 "\n", reassoc, (unsigned long)pkt_len);
1856 pstat = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
1857 if (pstat == (struct sta_info *)NULL)
1859 status = _RSON_CLS2_;
1860 goto asoc_class2_error;
1863 capab_info = RTW_GET_LE16(pframe + WLAN_HDR_A3_LEN);
1864 //capab_info = le16_to_cpu(*(unsigned short *)(pframe + WLAN_HDR_A3_LEN));
1865 //listen_interval = le16_to_cpu(*(unsigned short *)(pframe + WLAN_HDR_A3_LEN+2));
1866 listen_interval = RTW_GET_LE16(pframe + WLAN_HDR_A3_LEN+2);
1868 left = pkt_len - (IEEE80211_3ADDR_LEN + ie_offset);
1869 pos = pframe + (IEEE80211_3ADDR_LEN + ie_offset);
1872 DBG_871X("%s\n", __FUNCTION__);
1874 // check if this stat has been successfully authenticated/assocated
1875 if (!((pstat->state) & WIFI_FW_AUTH_SUCCESS))
1877 if (!((pstat->state) & WIFI_FW_ASSOC_SUCCESS))
1879 status = _RSON_CLS2_;
1880 goto asoc_class2_error;
1884 pstat->state &= (~WIFI_FW_ASSOC_SUCCESS);
1885 pstat->state |= WIFI_FW_ASSOC_STATE;
1890 pstat->state &= (~WIFI_FW_AUTH_SUCCESS);
1891 pstat->state |= WIFI_FW_ASSOC_STATE;
1895 #if 0// todo:tkip_countermeasures
1896 if (hapd->tkip_countermeasures) {
1897 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
1902 pstat->capability = capab_info;
1905 //check listen_interval
1906 if (listen_interval > hapd->conf->max_listen_interval) {
1907 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1908 HOSTAPD_LEVEL_DEBUG,
1909 "Too large Listen Interval (%d)",
1911 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
1915 pstat->listen_interval = listen_interval;
1918 //now parse all ieee802_11 ie to point to elems
1919 if (rtw_ieee802_11_parse_elems(pos, left, &elems, 1) == ParseFailed ||
1921 DBG_871X("STA " MAC_FMT " sent invalid association request\n",
1922 MAC_ARG(pstat->hwaddr));
1923 status = _STATS_FAILURE_;
1924 goto OnAssocReqFail;
1928 // now we should check all the fields...
1930 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + ie_offset, _SSID_IE_, &ie_len,
1931 pkt_len - WLAN_HDR_A3_LEN - ie_offset);
1934 status = _STATS_FAILURE_;
1937 if (ie_len == 0) // broadcast ssid, however it is not allowed in assocreq
1938 status = _STATS_FAILURE_;
1941 // check if ssid match
1942 if (!_rtw_memcmp((void *)(p+2), cur->Ssid.Ssid, cur->Ssid.SsidLength))
1943 status = _STATS_FAILURE_;
1945 if (ie_len != cur->Ssid.SsidLength)
1946 status = _STATS_FAILURE_;
1949 if(_STATS_SUCCESSFUL_ != status)
1950 goto OnAssocReqFail;
1952 // check if the supported rate is ok
1953 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + ie_offset, _SUPPORTEDRATES_IE_, &ie_len, pkt_len - WLAN_HDR_A3_LEN - ie_offset);
1955 DBG_871X("Rx a sta assoc-req which supported rate is empty!\n");
1956 // use our own rate set as statoin used
1957 //_rtw_memcpy(supportRate, AP_BSSRATE, AP_BSSRATE_LEN);
1958 //supportRateNum = AP_BSSRATE_LEN;
1960 status = _STATS_FAILURE_;
1961 goto OnAssocReqFail;
1964 _rtw_memcpy(supportRate, p+2, ie_len);
1965 supportRateNum = ie_len;
1967 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + ie_offset, _EXT_SUPPORTEDRATES_IE_ , &ie_len,
1968 pkt_len - WLAN_HDR_A3_LEN - ie_offset);
1971 if(supportRateNum<=sizeof(supportRate))
1973 _rtw_memcpy(supportRate+supportRateNum, p+2, ie_len);
1974 supportRateNum += ie_len;
1979 //todo: mask supportRate between AP & STA -> move to update raid
1980 //get_matched_rate(pmlmeext, supportRate, &supportRateNum, 0);
1982 //update station supportRate
1983 pstat->bssratelen = supportRateNum;
1984 _rtw_memcpy(pstat->bssrateset, supportRate, supportRateNum);
1985 UpdateBrateTblForSoftAP(pstat->bssrateset, pstat->bssratelen);
1988 pstat->dot8021xalg = 0;
1990 pstat->wpa_group_cipher = 0;
1991 pstat->wpa2_group_cipher = 0;
1992 pstat->wpa_pairwise_cipher = 0;
1993 pstat->wpa2_pairwise_cipher = 0;
1994 _rtw_memset(pstat->wpa_ie, 0, sizeof(pstat->wpa_ie));
1995 if((psecuritypriv->wpa_psk & BIT(1)) && elems.rsn_ie) {
1997 int group_cipher=0, pairwise_cipher=0;
1999 wpa_ie = elems.rsn_ie;
2000 wpa_ie_len = elems.rsn_ie_len;
2002 if(rtw_parse_wpa2_ie(wpa_ie-2, wpa_ie_len+2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS)
2004 pstat->dot8021xalg = 1;//psk, todo:802.1x
2005 pstat->wpa_psk |= BIT(1);
2007 pstat->wpa2_group_cipher = group_cipher&psecuritypriv->wpa2_group_cipher;
2008 pstat->wpa2_pairwise_cipher = pairwise_cipher&psecuritypriv->wpa2_pairwise_cipher;
2010 if(!pstat->wpa2_group_cipher)
2011 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
2013 if(!pstat->wpa2_pairwise_cipher)
2014 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
2018 status = WLAN_STATUS_INVALID_IE;
2021 } else if ((psecuritypriv->wpa_psk & BIT(0)) && elems.wpa_ie) {
2023 int group_cipher=0, pairwise_cipher=0;
2025 wpa_ie = elems.wpa_ie;
2026 wpa_ie_len = elems.wpa_ie_len;
2028 if(rtw_parse_wpa_ie(wpa_ie-2, wpa_ie_len+2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS)
2030 pstat->dot8021xalg = 1;//psk, todo:802.1x
2031 pstat->wpa_psk |= BIT(0);
2033 pstat->wpa_group_cipher = group_cipher&psecuritypriv->wpa_group_cipher;
2034 pstat->wpa_pairwise_cipher = pairwise_cipher&psecuritypriv->wpa_pairwise_cipher;
2036 if(!pstat->wpa_group_cipher)
2037 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
2039 if(!pstat->wpa_pairwise_cipher)
2040 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
2045 status = WLAN_STATUS_INVALID_IE;
2053 if(_STATS_SUCCESSFUL_ != status)
2054 goto OnAssocReqFail;
2056 pstat->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS);
2057 //if (hapd->conf->wps_state && wpa_ie == NULL) { //todo: to check ap if supporting WPS
2058 if(wpa_ie == NULL) {
2060 DBG_871X("STA included WPS IE in "
2061 "(Re)Association Request - assume WPS is "
2063 pstat->flags |= WLAN_STA_WPS;
2064 //wpabuf_free(sta->wps_ie);
2065 //sta->wps_ie = wpabuf_alloc_copy(elems.wps_ie + 4,
2066 // elems.wps_ie_len - 4);
2068 DBG_871X("STA did not include WPA/RSN IE "
2069 "in (Re)Association Request - possible WPS "
2071 pstat->flags |= WLAN_STA_MAYBE_WPS;
2075 // AP support WPA/RSN, and sta is going to do WPS, but AP is not ready
2076 // that the selected registrar of AP is _FLASE
2077 if((psecuritypriv->wpa_psk >0)
2078 && (pstat->flags & (WLAN_STA_WPS|WLAN_STA_MAYBE_WPS)))
2080 if(pmlmepriv->wps_beacon_ie)
2082 u8 selected_registrar = 0;
2084 rtw_get_wps_attr_content(pmlmepriv->wps_beacon_ie, pmlmepriv->wps_beacon_ie_len, WPS_ATTR_SELECTED_REGISTRAR , &selected_registrar, NULL);
2086 if(!selected_registrar)
2088 DBG_871X("selected_registrar is _FALSE , or AP is not ready to do WPS\n");
2090 status = _STATS_UNABLE_HANDLE_STA_;
2092 goto OnAssocReqFail;
2102 if(psecuritypriv->wpa_psk == 0)
2104 DBG_871X("STA " MAC_FMT ": WPA/RSN IE in association "
2105 "request, but AP don't support WPA/RSN\n", MAC_ARG(pstat->hwaddr));
2107 status = WLAN_STATUS_INVALID_IE;
2109 goto OnAssocReqFail;
2114 DBG_871X("STA included WPS IE in "
2115 "(Re)Association Request - WPS is "
2117 pstat->flags |= WLAN_STA_WPS;
2122 copy_len = ((wpa_ie_len+2) > sizeof(pstat->wpa_ie)) ? (sizeof(pstat->wpa_ie)):(wpa_ie_len+2);
2127 _rtw_memcpy(pstat->wpa_ie, wpa_ie-2, copy_len);
2132 // check if there is WMM IE & support WWM-PS
2133 pstat->flags &= ~WLAN_STA_WME;
2134 pstat->qos_option = 0;
2135 pstat->qos_info = 0;
2136 pstat->has_legacy_ac = _TRUE;
2137 pstat->uapsd_vo = 0;
2138 pstat->uapsd_vi = 0;
2139 pstat->uapsd_be = 0;
2140 pstat->uapsd_bk = 0;
2141 if (pmlmepriv->qospriv.qos_option)
2143 p = pframe + WLAN_HDR_A3_LEN + ie_offset; ie_len = 0;
2146 p = rtw_get_ie(p, _VENDOR_SPECIFIC_IE_, &ie_len, pkt_len - WLAN_HDR_A3_LEN - ie_offset);
2148 if (_rtw_memcmp(p+2, WMM_IE, 6)) {
2150 pstat->flags |= WLAN_STA_WME;
2152 pstat->qos_option = 1;
2153 pstat->qos_info = *(p+8);
2155 pstat->max_sp_len = (pstat->qos_info>>5)&0x3;
2157 if((pstat->qos_info&0xf) !=0xf)
2158 pstat->has_legacy_ac = _TRUE;
2160 pstat->has_legacy_ac = _FALSE;
2162 if(pstat->qos_info&0xf)
2164 if(pstat->qos_info&BIT(0))
2165 pstat->uapsd_vo = BIT(0)|BIT(1);
2167 pstat->uapsd_vo = 0;
2169 if(pstat->qos_info&BIT(1))
2170 pstat->uapsd_vi = BIT(0)|BIT(1);
2172 pstat->uapsd_vi = 0;
2174 if(pstat->qos_info&BIT(2))
2175 pstat->uapsd_bk = BIT(0)|BIT(1);
2177 pstat->uapsd_bk = 0;
2179 if(pstat->qos_info&BIT(3))
2180 pstat->uapsd_be = BIT(0)|BIT(1);
2182 pstat->uapsd_be = 0;
2197 #ifdef CONFIG_80211N_HT
2198 /* save HT capabilities in the sta object */
2199 _rtw_memset(&pstat->htpriv.ht_cap, 0, sizeof(struct rtw_ieee80211_ht_cap));
2200 if (elems.ht_capabilities && elems.ht_capabilities_len >= sizeof(struct rtw_ieee80211_ht_cap))
2202 pstat->flags |= WLAN_STA_HT;
2204 pstat->flags |= WLAN_STA_WME;
2206 _rtw_memcpy(&pstat->htpriv.ht_cap, elems.ht_capabilities, sizeof(struct rtw_ieee80211_ht_cap));
2209 pstat->flags &= ~WLAN_STA_HT;
2212 if((pmlmepriv->htpriv.ht_option == _FALSE) && (pstat->flags&WLAN_STA_HT))
2214 status = _STATS_FAILURE_;
2215 goto OnAssocReqFail;
2219 if ((pstat->flags & WLAN_STA_HT) &&
2220 ((pstat->wpa2_pairwise_cipher&WPA_CIPHER_TKIP) ||
2221 (pstat->wpa_pairwise_cipher&WPA_CIPHER_TKIP)))
2223 DBG_871X("HT: " MAC_FMT " tried to "
2224 "use TKIP with HT association\n", MAC_ARG(pstat->hwaddr));
2226 //status = WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
2227 //goto OnAssocReqFail;
2229 #endif /* CONFIG_80211N_HT */
2231 #ifdef CONFIG_80211AC_VHT
2232 _rtw_memset(&pstat->vhtpriv, 0, sizeof(struct vht_priv));
2233 if (elems.vht_capabilities && elems.vht_capabilities_len == 12) {
2234 pstat->flags |= WLAN_STA_VHT;
2236 _rtw_memcpy(pstat->vhtpriv.vht_cap, elems.vht_capabilities, 12);
2238 if (elems.vht_op_mode_notify && elems.vht_op_mode_notify_len == 1) {
2239 _rtw_memcpy(&pstat->vhtpriv.vht_op_mode_notify, elems.vht_op_mode_notify, 1);
2243 pstat->flags &= ~WLAN_STA_VHT;
2246 if((pmlmepriv->vhtpriv.vht_option == _FALSE) && (pstat->flags&WLAN_STA_VHT))
2248 status = _STATS_FAILURE_;
2249 goto OnAssocReqFail;
2251 #endif /* CONFIG_80211AC_VHT */
2254 //if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)//?
2255 pstat->flags |= WLAN_STA_NONERP;
2256 for (i = 0; i < pstat->bssratelen; i++) {
2257 if ((pstat->bssrateset[i] & 0x7f) > 22) {
2258 pstat->flags &= ~WLAN_STA_NONERP;
2263 if (pstat->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2264 pstat->flags |= WLAN_STA_SHORT_PREAMBLE;
2266 pstat->flags &= ~WLAN_STA_SHORT_PREAMBLE;
2270 if (status != _STATS_SUCCESSFUL_)
2271 goto OnAssocReqFail;
2274 pstat->is_p2p_device = _FALSE;
2275 if(rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO))
2277 if( (p2pie=rtw_get_p2p_ie(pframe + WLAN_HDR_A3_LEN + ie_offset , pkt_len - WLAN_HDR_A3_LEN - ie_offset , NULL, &p2pielen)))
2279 pstat->is_p2p_device = _TRUE;
2280 if((p2p_status_code=(u8)process_assoc_req_p2p_ie(pwdinfo, pframe, pkt_len, pstat))>0)
2282 pstat->p2p_status_code = p2p_status_code;
2283 status = _STATS_CAP_FAIL_;
2284 goto OnAssocReqFail;
2288 if(rtw_get_wfd_ie(pframe + WLAN_HDR_A3_LEN + ie_offset , pkt_len - WLAN_HDR_A3_LEN - ie_offset , wfd_ie, &wfd_ielen ))
2290 u8 attr_content[ 10 ] = { 0x00 };
2291 u32 attr_contentlen = 0;
2293 DBG_8192C( "[%s] WFD IE Found!!\n", __FUNCTION__ );
2294 rtw_get_wfd_attr_content( wfd_ie, wfd_ielen, WFD_ATTR_DEVICE_INFO, attr_content, &attr_contentlen);
2295 if ( attr_contentlen )
2297 pwdinfo->wfd_info->peer_rtsp_ctrlport = RTW_GET_BE16( attr_content + 2 );
2298 DBG_8192C( "[%s] Peer PORT NUM = %d\n", __FUNCTION__, pwdinfo->wfd_info->peer_rtsp_ctrlport );
2303 pstat->p2p_status_code = p2p_status_code;
2306 //TODO: identify_proprietary_vendor_ie();
2307 // Realtek proprietary IE
2308 // identify if this is Broadcom sta
2309 // identify if this is ralink sta
2310 // Customer proprietary IE
2314 /* get a unique AID */
2315 if (pstat->aid > 0) {
2316 DBG_871X(" old AID %d\n", pstat->aid);
2318 for (pstat->aid = 1; pstat->aid <= NUM_STA; pstat->aid++)
2319 if (pstapriv->sta_aid[pstat->aid - 1] == NULL)
2322 //if (pstat->aid > NUM_STA) {
2323 if (pstat->aid > pstapriv->max_num_sta) {
2327 DBG_871X(" no room for more AIDs\n");
2329 status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
2331 goto OnAssocReqFail;
2335 pstapriv->sta_aid[pstat->aid - 1] = pstat;
2336 DBG_871X("allocate new AID = (%d)\n", pstat->aid);
2341 pstat->state &= (~WIFI_FW_ASSOC_STATE);
2342 pstat->state |= WIFI_FW_ASSOC_SUCCESS;
2344 _enter_critical_bh(&pstapriv->auth_list_lock, &irqL);
2345 if (!rtw_is_list_empty(&pstat->auth_list))
2347 rtw_list_delete(&pstat->auth_list);
2348 pstapriv->auth_list_cnt--;
2350 _exit_critical_bh(&pstapriv->auth_list_lock, &irqL);
2352 _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
2353 if (rtw_is_list_empty(&pstat->asoc_list))
2355 pstat->expire_to = pstapriv->expire_to;
2356 rtw_list_insert_tail(&pstat->asoc_list, &pstapriv->asoc_list);
2357 pstapriv->asoc_list_cnt++;
2359 _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
2361 // now the station is qualified to join our BSS...
2362 if(pstat && (pstat->state & WIFI_FW_ASSOC_SUCCESS) && (_STATS_SUCCESSFUL_==status))
2364 #ifdef CONFIG_NATIVEAP_MLME
2365 //.1 bss_cap_update & sta_info_update
2366 bss_cap_update_on_sta_join(padapter, pstat);
2367 sta_info_update(padapter, pstat);
2369 //.2 issue assoc rsp before notify station join event.
2370 if (frame_type == WIFI_ASSOCREQ)
2371 issue_asocrsp(padapter, status, pstat, WIFI_ASSOCRSP);
2373 issue_asocrsp(padapter, status, pstat, WIFI_REASSOCRSP);
2375 #ifdef CONFIG_IOCTL_CFG80211
2376 _enter_critical_bh(&pstat->lock, &irqL);
2377 if(pstat->passoc_req)
2379 rtw_mfree(pstat->passoc_req, pstat->assoc_req_len);
2380 pstat->passoc_req = NULL;
2381 pstat->assoc_req_len = 0;
2384 pstat->passoc_req = rtw_zmalloc(pkt_len);
2385 if(pstat->passoc_req)
2387 _rtw_memcpy(pstat->passoc_req, pframe, pkt_len);
2388 pstat->assoc_req_len = pkt_len;
2390 _exit_critical_bh(&pstat->lock, &irqL);
2391 #endif //CONFIG_IOCTL_CFG80211
2393 //.3-(1) report sta add event
2394 report_add_sta_event(padapter, pstat->hwaddr, pstat->aid);
2396 #endif //CONFIG_NATIVEAP_MLME
2403 #ifdef CONFIG_NATIVEAP_MLME
2404 issue_deauth(padapter, (void *)GetAddr2Ptr(pframe), status);
2412 #ifdef CONFIG_NATIVEAP_MLME
2414 if (frame_type == WIFI_ASSOCREQ)
2415 issue_asocrsp(padapter, status, pstat, WIFI_ASSOCRSP);
2417 issue_asocrsp(padapter, status, pstat, WIFI_REASSOCRSP);
2421 #endif /* CONFIG_AP_MODE */
2427 unsigned int OnAssocRsp(_adapter *padapter, union recv_frame *precv_frame)
2431 unsigned short status;
2432 PNDIS_802_11_VARIABLE_IEs pIE;
2433 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2434 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2435 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2436 //WLAN_BSSID_EX *cur_network = &(pmlmeinfo->network);
2437 u8 *pframe = precv_frame->u.hdr.rx_data;
2438 uint pkt_len = precv_frame->u.hdr.len;
2439 PNDIS_802_11_VARIABLE_IEs pWapiIE = NULL;
2441 DBG_871X("%s\n", __FUNCTION__);
2443 //check A1 matches or not
2444 if (!_rtw_memcmp(myid(&(padapter->eeprompriv)), get_da(pframe), ETH_ALEN))
2447 if (!(pmlmeinfo->state & (WIFI_FW_AUTH_SUCCESS | WIFI_FW_ASSOC_STATE)))
2450 if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS)
2453 _cancel_timer_ex(&pmlmeext->link_timer);
2456 if ((status = le16_to_cpu(*(unsigned short *)(pframe + WLAN_HDR_A3_LEN + 2))) > 0)
2458 DBG_871X("assoc reject, status code: %d\n", status);
2459 pmlmeinfo->state = WIFI_FW_NULL_STATE;
2461 goto report_assoc_result;
2465 pmlmeinfo->capability = le16_to_cpu(*(unsigned short *)(pframe + WLAN_HDR_A3_LEN));
2468 pmlmeinfo->slotTime = (pmlmeinfo->capability & BIT(10))? 9: 20;
2471 res = pmlmeinfo->aid = (int)(le16_to_cpu(*(unsigned short *)(pframe + WLAN_HDR_A3_LEN + 4))&0x3fff);
2473 //following are moved to join event callback function
2474 //to handle HT, WMM, rate adaptive, update MAC reg
2475 //for not to handle the synchronous IO in the tasklet
2476 for (i = (6 + WLAN_HDR_A3_LEN); i < pkt_len;)
2478 pIE = (PNDIS_802_11_VARIABLE_IEs)(pframe + i);
2480 switch (pIE->ElementID)
2482 case _VENDOR_SPECIFIC_IE_:
2483 if (_rtw_memcmp(pIE->data, WMM_PARA_OUI, 6)) //WMM
2485 WMM_param_handler(padapter, pIE);
2487 #if defined(CONFIG_P2P) && defined(CONFIG_WFD)
2488 else if ( _rtw_memcmp(pIE->data, WFD_OUI, 4)) //WFD
2490 DBG_871X( "[%s] Found WFD IE\n", __FUNCTION__ );
2491 WFD_info_handler( padapter, pIE );
2496 #ifdef CONFIG_WAPI_SUPPORT
2502 case _HT_CAPABILITY_IE_: //HT caps
2503 HT_caps_handler(padapter, pIE);
2506 case _HT_EXTRA_INFO_IE_: //HT info
2507 HT_info_handler(padapter, pIE);
2510 #ifdef CONFIG_80211AC_VHT
2511 case EID_VHTCapability:
2512 VHT_caps_handler(padapter, pIE);
2515 case EID_VHTOperation:
2516 VHT_operation_handler(padapter, pIE);
2521 ERP_IE_handler(padapter, pIE);
2527 i += (pIE->Length + 2);
2530 #ifdef CONFIG_WAPI_SUPPORT
2531 rtw_wapi_on_assoc_ok(padapter, pIE);
2534 pmlmeinfo->state &= (~WIFI_FW_ASSOC_STATE);
2535 pmlmeinfo->state |= WIFI_FW_ASSOC_SUCCESS;
2537 //Update Basic Rate Table for spec, 2010-12-28 , by thomas
2538 UpdateBrateTbl(padapter, pmlmeinfo->network.SupportedRates);
2540 report_assoc_result:
2542 rtw_buf_update(&pmlmepriv->assoc_rsp, &pmlmepriv->assoc_rsp_len, pframe, pkt_len);
2544 rtw_buf_free(&pmlmepriv->assoc_rsp, &pmlmepriv->assoc_rsp_len);
2547 report_join_res(padapter, res);
2552 unsigned int OnDeAuth(_adapter *padapter, union recv_frame *precv_frame)
2554 unsigned short reason;
2555 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2556 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2557 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2558 u8 *pframe = precv_frame->u.hdr.rx_data;
2560 struct wifidirect_info *pwdinfo= &(padapter->wdinfo);
2564 if (!(_rtw_memcmp(GetAddr3Ptr(pframe), get_my_bssid(&pmlmeinfo->network), ETH_ALEN)))
2568 if ( pwdinfo->rx_invitereq_info.scan_op_ch_only )
2570 _cancel_timer_ex( &pwdinfo->reset_ch_sitesurvey );
2571 _set_timer( &pwdinfo->reset_ch_sitesurvey, 10 );
2575 reason = le16_to_cpu(*(unsigned short *)(pframe + WLAN_HDR_A3_LEN));
2577 rtw_lock_rx_suspend_timeout(8000);
2579 #ifdef CONFIG_AP_MODE
2580 if(check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
2583 struct sta_info *psta;
2584 struct sta_priv *pstapriv = &padapter->stapriv;
2586 //_enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL);
2587 //rtw_free_stainfo(padapter, psta);
2588 //_exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL);
2590 DBG_871X_LEVEL(_drv_always_, FUNC_ADPT_FMT" reason=%u, ta=%pM\n"
2591 , FUNC_ADPT_ARG(padapter), reason, GetAddr2Ptr(pframe));
2593 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
2596 u8 updated = _FALSE;
2598 _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
2599 if(rtw_is_list_empty(&psta->asoc_list)==_FALSE)
2601 rtw_list_delete(&psta->asoc_list);
2602 pstapriv->asoc_list_cnt--;
2603 updated = ap_free_sta(padapter, psta, _FALSE, reason);
2606 _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
2608 associated_clients_update(padapter, updated);
2617 int ignore_received_deauth = 0;
2619 // Commented by Albert 20130604
2620 // Before sending the auth frame to start the STA/GC mode connection with AP/GO,
2621 // we will send the deauth first.
2622 // However, the Win8.1 with BRCM Wi-Fi will send the deauth with reason code 6 to us after receieving our deauth.
2623 // Added the following code to avoid this case.
2624 if ( ( pmlmeinfo->state & WIFI_FW_AUTH_STATE ) ||
2625 ( pmlmeinfo->state & WIFI_FW_ASSOC_STATE ) )
2627 if ( reason == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA )
2629 ignore_received_deauth = 1;
2630 } else if (WLAN_REASON_PREV_AUTH_NOT_VALID == reason) {
2632 ignore_received_deauth = 1;
2636 DBG_871X_LEVEL(_drv_always_, FUNC_ADPT_FMT" reason=%u, ta=%pM, ignore=%d\n"
2637 , FUNC_ADPT_ARG(padapter), reason, GetAddr2Ptr(pframe), ignore_received_deauth);
2639 if ( 0 == ignore_received_deauth )
2641 receive_disconnect(padapter, GetAddr2Ptr(pframe), reason);
2644 pmlmepriv->LinkDetectInfo.bBusyTraffic = _FALSE;
2649 unsigned int OnDisassoc(_adapter *padapter, union recv_frame *precv_frame)
2651 unsigned short reason;
2652 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2653 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2654 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2655 u8 *pframe = precv_frame->u.hdr.rx_data;
2657 struct wifidirect_info *pwdinfo= &(padapter->wdinfo);
2661 if (!(_rtw_memcmp(GetAddr3Ptr(pframe), get_my_bssid(&pmlmeinfo->network), ETH_ALEN)))
2665 if ( pwdinfo->rx_invitereq_info.scan_op_ch_only )
2667 _cancel_timer_ex( &pwdinfo->reset_ch_sitesurvey );
2668 _set_timer( &pwdinfo->reset_ch_sitesurvey, 10 );
2672 reason = le16_to_cpu(*(unsigned short *)(pframe + WLAN_HDR_A3_LEN));
2674 rtw_lock_rx_suspend_timeout(8000);
2676 #ifdef CONFIG_AP_MODE
2677 if(check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
2680 struct sta_info *psta;
2681 struct sta_priv *pstapriv = &padapter->stapriv;
2683 //_enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL);
2684 //rtw_free_stainfo(padapter, psta);
2685 //_exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL);
2687 DBG_871X_LEVEL(_drv_always_, FUNC_ADPT_FMT" reason=%u, ta=%pM\n"
2688 , FUNC_ADPT_ARG(padapter), reason, GetAddr2Ptr(pframe));
2690 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
2693 u8 updated = _FALSE;
2695 _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
2696 if(rtw_is_list_empty(&psta->asoc_list)==_FALSE)
2698 rtw_list_delete(&psta->asoc_list);
2699 pstapriv->asoc_list_cnt--;
2700 updated = ap_free_sta(padapter, psta, _FALSE, reason);
2703 _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
2705 associated_clients_update(padapter, updated);
2713 DBG_871X_LEVEL(_drv_always_, FUNC_ADPT_FMT" reason=%u, ta=%pM\n"
2714 , FUNC_ADPT_ARG(padapter), reason, GetAddr2Ptr(pframe));
2716 receive_disconnect(padapter, GetAddr2Ptr(pframe), reason);
2718 pmlmepriv->LinkDetectInfo.bBusyTraffic = _FALSE;
2723 unsigned int OnAtim(_adapter *padapter, union recv_frame *precv_frame)
2725 DBG_871X("%s\n", __FUNCTION__);
2729 unsigned int on_action_spct_ch_switch(_adapter *padapter, struct sta_info *psta, u8 *ies, uint ies_len)
2731 unsigned int ret = _FAIL;
2732 struct mlme_ext_priv *mlmeext = &padapter->mlmeextpriv;
2733 struct mlme_ext_info *pmlmeinfo = &(mlmeext->mlmext_info);
2735 if (!(pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS)) {
2740 if ((pmlmeinfo->state & 0x03) == WIFI_FW_STATION_STATE) {
2742 int ch_switch_mode = -1, ch = -1, ch_switch_cnt = -1;
2745 struct ieee80211_info_element *ie;
2747 DBG_871X(FUNC_NDEV_FMT" from "MAC_FMT"\n",
2748 FUNC_NDEV_ARG(padapter->pnetdev), MAC_ARG(psta->hwaddr));
2750 for_each_ie(ie, ies, ies_len) {
2751 if (ie->id == WLAN_EID_CHANNEL_SWITCH) {
2752 ch_switch_mode = ie->data[0];
2754 ch_switch_cnt = ie->data[2];
2755 DBG_871X("ch_switch_mode:%d, ch:%d, ch_switch_cnt:%d\n",
2756 ch_switch_mode, ch, ch_switch_cnt);
2758 else if (ie->id == WLAN_EID_SECONDARY_CHANNEL_OFFSET) {
2759 ch_offset = secondary_ch_offset_to_hal_ch_offset(ie->data[0]);
2760 DBG_871X("ch_offset:%d\n", ch_offset);
2767 if (ch_offset == -1)
2768 bwmode = mlmeext->cur_bwmode;
2770 bwmode = (ch_offset == HAL_PRIME_CHNL_OFFSET_DONT_CARE) ?
2771 CHANNEL_WIDTH_20 : CHANNEL_WIDTH_40;
2773 ch_offset = (ch_offset == -1) ? mlmeext->cur_ch_offset : ch_offset;
2776 * 1. the decision of channel switching
2777 * 2. things after channel switching
2780 ret = rtw_set_ch_cmd(padapter, ch, bwmode, ch_offset, _TRUE);
2787 unsigned int on_action_spct(_adapter *padapter, union recv_frame *precv_frame)
2789 unsigned int ret = _FAIL;
2790 struct sta_info *psta = NULL;
2791 struct sta_priv *pstapriv = &padapter->stapriv;
2792 u8 *pframe = precv_frame->u.hdr.rx_data;
2793 uint frame_len = precv_frame->u.hdr.len;
2794 u8 *frame_body = (u8 *)(pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
2798 DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(padapter->pnetdev));
2800 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
2805 category = frame_body[0];
2806 if(category != RTW_WLAN_CATEGORY_SPECTRUM_MGMT)
2809 action = frame_body[1];
2811 case RTW_WLAN_ACTION_SPCT_MSR_REQ:
2812 case RTW_WLAN_ACTION_SPCT_MSR_RPRT:
2813 case RTW_WLAN_ACTION_SPCT_TPC_REQ:
2814 case RTW_WLAN_ACTION_SPCT_TPC_RPRT:
2816 case RTW_WLAN_ACTION_SPCT_CHL_SWITCH:
2817 #ifdef CONFIG_SPCT_CH_SWITCH
2818 ret = on_action_spct_ch_switch(padapter, psta, &frame_body[2],
2819 frame_len-(frame_body-pframe)-2);
2830 unsigned int OnAction_qos(_adapter *padapter, union recv_frame *precv_frame)
2835 unsigned int OnAction_dls(_adapter *padapter, union recv_frame *precv_frame)
2840 unsigned int OnAction_back(_adapter *padapter, union recv_frame *precv_frame)
2843 struct sta_info *psta=NULL;
2844 struct recv_reorder_ctrl *preorder_ctrl;
2845 unsigned char *frame_body;
2846 unsigned char category, action;
2847 unsigned short tid, status, reason_code = 0;
2848 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2849 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2850 u8 *pframe = precv_frame->u.hdr.rx_data;
2851 struct sta_priv *pstapriv = &padapter->stapriv;
2852 #ifdef CONFIG_80211N_HT
2854 DBG_871X("%s\n", __FUNCTION__);
2856 //check RA matches or not
2857 if (!_rtw_memcmp(myid(&(padapter->eeprompriv)), GetAddr1Ptr(pframe), ETH_ALEN))//for if1, sta/ap mode
2861 //check A1 matches or not
2862 if (!_rtw_memcmp(myid(&(padapter->eeprompriv)), get_da(pframe), ETH_ALEN))
2866 if((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE)
2867 if (!(pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS))
2870 addr = GetAddr2Ptr(pframe);
2871 psta = rtw_get_stainfo(pstapriv, addr);
2876 frame_body = (unsigned char *)(pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
2878 category = frame_body[0];
2879 if (category == RTW_WLAN_CATEGORY_BACK)// representing Block Ack
2882 if((psta->tdls_sta_state & TDLS_LINKED_STATE) &&
2883 (psta->htpriv.ht_option==_TRUE) &&
2884 (psta->htpriv.ampdu_enable==_TRUE))
2886 DBG_871X("Recv [%s] from direc link\n", __FUNCTION__);
2889 #endif //CONFIG_TDLS
2890 if (!pmlmeinfo->HT_enable)
2895 action = frame_body[1];
2896 DBG_871X("%s, action=%d\n", __FUNCTION__, action);
2899 case RTW_WLAN_ACTION_ADDBA_REQ: //ADDBA request
2901 _rtw_memcpy(&(pmlmeinfo->ADDBA_req), &(frame_body[2]), sizeof(struct ADDBA_request));
2902 //process_addba_req(padapter, (u8*)&(pmlmeinfo->ADDBA_req), GetAddr3Ptr(pframe));
2903 process_addba_req(padapter, (u8*)&(pmlmeinfo->ADDBA_req), addr);
2905 if(pmlmeinfo->bAcceptAddbaReq == _TRUE)
2907 issue_action_BA(padapter, addr, RTW_WLAN_ACTION_ADDBA_RESP, 0);
2911 issue_action_BA(padapter, addr, RTW_WLAN_ACTION_ADDBA_RESP, 37);//reject ADDBA Req
2916 case RTW_WLAN_ACTION_ADDBA_RESP: //ADDBA response
2918 //status = frame_body[3] | (frame_body[4] << 8); //endian issue
2919 status = RTW_GET_LE16(&frame_body[3]);
2920 tid = ((frame_body[5] >> 2) & 0x7);
2924 DBG_871X("agg_enable for TID=%d\n", tid);
2925 psta->htpriv.agg_enable_bitmap |= 1 << tid;
2926 psta->htpriv.candidate_tid_bitmap &= ~BIT(tid);
2930 psta->htpriv.agg_enable_bitmap &= ~BIT(tid);
2933 if(psta->state & WIFI_STA_ALIVE_CHK_STATE)
2935 DBG_871X("%s alive check - rx ADDBA response\n", __func__);
2936 psta->htpriv.agg_enable_bitmap &= ~BIT(tid);
2937 psta->expire_to = pstapriv->expire_to;
2938 psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
2941 //DBG_871X("marc: ADDBA RSP: %x\n", pmlmeinfo->agg_enable_bitmap);
2944 case RTW_WLAN_ACTION_DELBA: //DELBA
2945 if ((frame_body[3] & BIT(3)) == 0)
2947 psta->htpriv.agg_enable_bitmap &= ~(1 << ((frame_body[3] >> 4) & 0xf));
2948 psta->htpriv.candidate_tid_bitmap &= ~(1 << ((frame_body[3] >> 4) & 0xf));
2950 //reason_code = frame_body[4] | (frame_body[5] << 8);
2951 reason_code = RTW_GET_LE16(&frame_body[4]);
2953 else if((frame_body[3] & BIT(3)) == BIT(3))
2955 tid = (frame_body[3] >> 4) & 0x0F;
2957 preorder_ctrl = &psta->recvreorder_ctrl[tid];
2958 preorder_ctrl->enable = _FALSE;
2959 preorder_ctrl->indicate_seq = 0xffff;
2961 DBG_871X("DBG_RX_SEQ %s:%d indicate_seq:%u \n", __FUNCTION__, __LINE__,
2962 preorder_ctrl->indicate_seq);
2966 DBG_871X("%s(): DELBA: %x(%x)\n", __FUNCTION__,pmlmeinfo->agg_enable_bitmap, reason_code);
2967 //todo: how to notify the host while receiving DELETE BA
2974 #endif //CONFIG_80211N_HT
2980 static int get_reg_classes_full_count(struct p2p_channels channel_list) {
2984 for (i = 0; i < channel_list.reg_classes; i++) {
2985 cnt += channel_list.reg_class[i].channels;
2991 static void get_channel_cnt_24g_5gl_5gh( struct mlme_ext_priv *pmlmeext, u8* p24g_cnt, u8* p5gl_cnt, u8* p5gh_cnt )
2999 for( i = 0; i < pmlmeext->max_chan_nums; i++ )
3001 if ( pmlmeext->channel_set[ i ].ChannelNum <= 14 )
3005 else if ( ( pmlmeext->channel_set[ i ].ChannelNum > 14 ) && ( pmlmeext->channel_set[ i ].ChannelNum <= 48 ) )
3007 // Just include the channel 36, 40, 44, 48 channels for 5G low
3010 else if ( ( pmlmeext->channel_set[ i ].ChannelNum >= 149 ) && ( pmlmeext->channel_set[ i ].ChannelNum <= 161 ) )
3012 // Just include the channel 149, 153, 157, 161 channels for 5G high
3018 void issue_p2p_GO_request(_adapter *padapter, u8* raddr)
3021 unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
3022 u8 action = P2P_PUB_ACTION_ACTION;
3023 u32 p2poui = cpu_to_be32(P2POUI);
3024 u8 oui_subtype = P2P_GO_NEGO_REQ;
3025 u8 wpsie[ 255 ] = { 0x00 }, p2pie[ 255 ] = { 0x00 };
3026 u8 wpsielen = 0, p2pielen = 0, i;
3027 u8 channel_cnt_24g = 0, channel_cnt_5gl = 0, channel_cnt_5gh = 0;
3028 u16 len_channellist_attr = 0;
3033 struct xmit_frame *pmgntframe;
3034 struct pkt_attrib *pattrib;
3035 unsigned char *pframe;
3036 struct rtw_ieee80211_hdr *pwlanhdr;
3037 unsigned short *fctrl;
3038 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
3039 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
3040 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
3041 struct wifidirect_info *pwdinfo = &( padapter->wdinfo);
3044 if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
3049 DBG_871X( "[%s] In\n", __FUNCTION__ );
3051 pattrib = &pmgntframe->attrib;
3052 update_mgntframe_attrib(padapter, pattrib);
3054 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
3056 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
3057 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
3059 fctrl = &(pwlanhdr->frame_ctl);
3062 _rtw_memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
3063 _rtw_memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
3064 _rtw_memcpy(pwlanhdr->addr3, myid(&(padapter->eeprompriv)), ETH_ALEN);
3066 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
3067 pmlmeext->mgnt_seq++;
3068 SetFrameSubType(pframe, WIFI_ACTION);
3070 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
3071 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
3073 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
3074 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
3075 pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *) &(p2poui), &(pattrib->pktlen));
3076 pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
3077 pwdinfo->negotiation_dialog_token = 1; // Initialize the dialog value
3078 pframe = rtw_set_fixed_ie(pframe, 1, &pwdinfo->negotiation_dialog_token, &(pattrib->pktlen));
3085 *(u32*) ( wpsie ) = cpu_to_be32( WPSOUI );
3090 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_ATTR_VER1 );
3094 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( 0x0001 );
3098 wpsie[wpsielen++] = WPS_VERSION_1; // Version 1.0
3100 // Device Password ID
3102 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_ATTR_DEVICE_PWID );
3106 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( 0x0002 );
3111 if ( pwdinfo->ui_got_wps_info == P2P_GOT_WPSINFO_PEER_DISPLAY_PIN )
3113 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_DPID_USER_SPEC );
3115 else if ( pwdinfo->ui_got_wps_info == P2P_GOT_WPSINFO_SELF_DISPLAY_PIN )
3117 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_DPID_REGISTRAR_SPEC );
3119 else if ( pwdinfo->ui_got_wps_info == P2P_GOT_WPSINFO_PBC )
3121 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_DPID_PBC );
3126 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wpsielen, (unsigned char *) wpsie, &pattrib->pktlen );
3133 p2pie[ p2pielen++ ] = 0x50;
3134 p2pie[ p2pielen++ ] = 0x6F;
3135 p2pie[ p2pielen++ ] = 0x9A;
3136 p2pie[ p2pielen++ ] = 0x09; // WFA P2P v1.0
3138 // Commented by Albert 20110306
3139 // According to the P2P Specification, the group negoitation request frame should contain 9 P2P attributes
3140 // 1. P2P Capability
3141 // 2. Group Owner Intent
3142 // 3. Configuration Timeout
3143 // 4. Listen Channel
3144 // 5. Extended Listen Timing
3145 // 6. Intended P2P Interface Address
3147 // 8. P2P Device Info
3148 // 9. Operating Channel
3153 p2pie[ p2pielen++ ] = P2P_ATTR_CAPABILITY;
3156 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0002 );
3160 // Device Capability Bitmap, 1 byte
3161 p2pie[ p2pielen++ ] = DMP_P2P_DEVCAP_SUPPORT;
3163 // Group Capability Bitmap, 1 byte
3164 if ( pwdinfo->persistent_supported )
3166 p2pie[ p2pielen++ ] = P2P_GRPCAP_CROSS_CONN | P2P_GRPCAP_PERSISTENT_GROUP;
3170 p2pie[ p2pielen++ ] = P2P_GRPCAP_CROSS_CONN;
3174 // Group Owner Intent
3176 p2pie[ p2pielen++ ] = P2P_ATTR_GO_INTENT;
3179 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0001 );
3183 // Todo the tie breaker bit.
3184 p2pie[ p2pielen++ ] = ( ( pwdinfo->intent << 1 ) | BIT(0) );
3186 // Configuration Timeout
3188 p2pie[ p2pielen++ ] = P2P_ATTR_CONF_TIMEOUT;
3191 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0002 );
3195 p2pie[ p2pielen++ ] = 200; // 2 seconds needed to be the P2P GO
3196 p2pie[ p2pielen++ ] = 200; // 2 seconds needed to be the P2P Client
3201 p2pie[ p2pielen++ ] = P2P_ATTR_LISTEN_CH;
3204 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0005 );
3209 p2pie[ p2pielen++ ] = 'X';
3210 p2pie[ p2pielen++ ] = 'X';
3212 // The third byte should be set to 0x04.
3213 // Described in the "Operating Channel Attribute" section.
3214 p2pie[ p2pielen++ ] = 0x04;
3217 p2pie[ p2pielen++ ] = 0x51; // Copy from SD7
3220 p2pie[ p2pielen++ ] = pwdinfo->listen_channel; // listening channel number
3223 // Extended Listen Timing ATTR
3225 p2pie[ p2pielen++ ] = P2P_ATTR_EX_LISTEN_TIMING;
3228 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0004 );
3232 // Availability Period
3233 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0xFFFF );
3236 // Availability Interval
3237 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0xFFFF );
3241 // Intended P2P Interface Address
3243 p2pie[ p2pielen++ ] = P2P_ATTR_INTENTED_IF_ADDR;
3246 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( ETH_ALEN );
3250 _rtw_memcpy( p2pie + p2pielen, myid( &padapter->eeprompriv ), ETH_ALEN );
3251 p2pielen += ETH_ALEN;
3256 p2pie[ p2pielen++ ] = P2P_ATTR_CH_LIST;
3259 // Country String(3)
3260 // + ( Operating Class (1) + Number of Channels(1) ) * Operation Classes (?)
3261 // + number of channels in all classes
3262 len_channellist_attr = 3
3263 + (1 + 1) * (u16)(pmlmeext->channel_list.reg_classes)
3264 + get_reg_classes_full_count(pmlmeext->channel_list);
3266 #ifdef CONFIG_CONCURRENT_MODE
3267 if ( check_buddy_fwstate(padapter, _FW_LINKED ) )
3269 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 5 + 1 );
3273 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( len_channellist_attr );
3277 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( len_channellist_attr );
3284 p2pie[ p2pielen++ ] = 'X';
3285 p2pie[ p2pielen++ ] = 'X';
3287 // The third byte should be set to 0x04.
3288 // Described in the "Operating Channel Attribute" section.
3289 p2pie[ p2pielen++ ] = 0x04;
3291 // Channel Entry List
3293 #ifdef CONFIG_CONCURRENT_MODE
3294 if ( check_buddy_fwstate(padapter, _FW_LINKED ) )
3296 _adapter *pbuddy_adapter = padapter->pbuddy_adapter;
3297 struct mlme_ext_priv *pbuddy_mlmeext = &pbuddy_adapter->mlmeextpriv;
3300 if ( pbuddy_mlmeext->cur_channel > 14 )
3302 if ( pbuddy_mlmeext->cur_channel >= 149 )
3304 p2pie[ p2pielen++ ] = 0x7c;
3308 p2pie[ p2pielen++ ] = 0x73;
3313 p2pie[ p2pielen++ ] = 0x51;
3316 // Number of Channels
3317 // Just support 1 channel and this channel is AP's channel
3318 p2pie[ p2pielen++ ] = 1;
3321 p2pie[ p2pielen++ ] = pbuddy_mlmeext->cur_channel;
3326 for (j = 0; j < pmlmeext->channel_list.reg_classes; j++) {
3328 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].reg_class;
3330 // Number of Channels
3331 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channels;
3334 for (i = 0; i < pmlmeext->channel_list.reg_class[j].channels; i++) {
3335 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channel[i];
3339 #else // CONFIG_CONCURRENT_MODE
3342 for (j = 0; j < pmlmeext->channel_list.reg_classes; j++) {
3344 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].reg_class;
3346 // Number of Channels
3347 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channels;
3350 for (i = 0; i < pmlmeext->channel_list.reg_class[j].channels; i++) {
3351 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channel[i];
3355 #endif // CONFIG_CONCURRENT_MODE
3359 p2pie[ p2pielen++ ] = P2P_ATTR_DEVICE_INFO;
3362 // 21 -> P2P Device Address (6bytes) + Config Methods (2bytes) + Primary Device Type (8bytes)
3363 // + NumofSecondDevType (1byte) + WPS Device Name ID field (2bytes) + WPS Device Name Len field (2bytes)
3364 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 21 + pwdinfo->device_name_len );
3368 // P2P Device Address
3369 _rtw_memcpy( p2pie + p2pielen, myid( &padapter->eeprompriv ), ETH_ALEN );
3370 p2pielen += ETH_ALEN;
3373 // This field should be big endian. Noted by P2P specification.
3375 *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( pwdinfo->supported_wps_cm );
3379 // Primary Device Type
3381 *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( WPS_PDT_CID_MULIT_MEDIA );
3385 *(u32*) ( p2pie + p2pielen ) = cpu_to_be32( WPSOUI );
3389 *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( WPS_PDT_SCID_MEDIA_SERVER );
3392 // Number of Secondary Device Types
3393 p2pie[ p2pielen++ ] = 0x00; // No Secondary Device Type List
3397 *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( WPS_ATTR_DEVICE_NAME );
3401 *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( pwdinfo->device_name_len );
3405 _rtw_memcpy( p2pie + p2pielen, pwdinfo->device_name , pwdinfo->device_name_len );
3406 p2pielen += pwdinfo->device_name_len;
3409 // Operating Channel
3411 p2pie[ p2pielen++ ] = P2P_ATTR_OPERATING_CH;
3414 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0005 );
3419 p2pie[ p2pielen++ ] = 'X';
3420 p2pie[ p2pielen++ ] = 'X';
3422 // The third byte should be set to 0x04.
3423 // Described in the "Operating Channel Attribute" section.
3424 p2pie[ p2pielen++ ] = 0x04;
3427 if ( pwdinfo->operating_channel <= 14 )
3430 p2pie[ p2pielen++ ] = 0x51;
3432 else if ( ( pwdinfo->operating_channel >= 36 ) && ( pwdinfo->operating_channel <= 48 ) )
3435 p2pie[ p2pielen++ ] = 0x73;
3440 p2pie[ p2pielen++ ] = 0x7c;
3444 p2pie[ p2pielen++ ] = pwdinfo->operating_channel; // operating channel number
3446 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *) p2pie, &pattrib->pktlen );
3449 wfdielen = build_nego_req_wfd_ie(pwdinfo, pframe);
3451 pattrib->pktlen += wfdielen;
3454 pattrib->last_txcmdsz = pattrib->pktlen;
3456 dump_mgntframe(padapter, pmgntframe);
3463 void issue_p2p_GO_response(_adapter *padapter, u8* raddr, u8* frame_body,uint len, u8 result)
3466 unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
3467 u8 action = P2P_PUB_ACTION_ACTION;
3468 u32 p2poui = cpu_to_be32(P2POUI);
3469 u8 oui_subtype = P2P_GO_NEGO_RESP;
3470 u8 wpsie[ 255 ] = { 0x00 }, p2pie[ 255 ] = { 0x00 };
3473 u16 wps_devicepassword_id = 0x0000;
3474 uint wps_devicepassword_id_len = 0;
3475 u8 channel_cnt_24g = 0, channel_cnt_5gl = 0, channel_cnt_5gh;
3476 u16 len_channellist_attr = 0;
3478 struct xmit_frame *pmgntframe;
3479 struct pkt_attrib *pattrib;
3480 unsigned char *pframe;
3481 struct rtw_ieee80211_hdr *pwlanhdr;
3482 unsigned short *fctrl;
3483 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
3484 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
3485 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
3486 struct wifidirect_info *pwdinfo = &( padapter->wdinfo);
3492 if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
3497 DBG_871X( "[%s] In, result = %d\n", __FUNCTION__, result );
3499 pattrib = &pmgntframe->attrib;
3500 update_mgntframe_attrib(padapter, pattrib);
3502 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
3504 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
3505 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
3507 fctrl = &(pwlanhdr->frame_ctl);
3510 _rtw_memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
3511 _rtw_memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
3512 _rtw_memcpy(pwlanhdr->addr3, myid(&(padapter->eeprompriv)), ETH_ALEN);
3514 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
3515 pmlmeext->mgnt_seq++;
3516 SetFrameSubType(pframe, WIFI_ACTION);
3518 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
3519 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
3521 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
3522 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
3523 pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *) &(p2poui), &(pattrib->pktlen));
3524 pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
3525 pwdinfo->negotiation_dialog_token = frame_body[7]; // The Dialog Token of provisioning discovery request frame.
3526 pframe = rtw_set_fixed_ie(pframe, 1, &(pwdinfo->negotiation_dialog_token), &(pattrib->pktlen));
3528 // Commented by Albert 20110328
3529 // Try to get the device password ID from the WPS IE of group negotiation request frame
3530 // WiFi Direct test plan 5.1.15
3531 rtw_get_wps_ie( frame_body + _PUBLIC_ACTION_IE_OFFSET_, len - _PUBLIC_ACTION_IE_OFFSET_, wpsie, &wpsielen);
3532 rtw_get_wps_attr_content( wpsie, wpsielen, WPS_ATTR_DEVICE_PWID, (u8*) &wps_devicepassword_id, &wps_devicepassword_id_len);
3533 wps_devicepassword_id = be16_to_cpu( wps_devicepassword_id );
3535 _rtw_memset( wpsie, 0x00, 255 );
3541 *(u32*) ( wpsie ) = cpu_to_be32( WPSOUI );
3546 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_ATTR_VER1 );
3550 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( 0x0001 );
3554 wpsie[wpsielen++] = WPS_VERSION_1; // Version 1.0
3556 // Device Password ID
3558 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_ATTR_DEVICE_PWID );
3562 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( 0x0002 );
3566 if ( wps_devicepassword_id == WPS_DPID_USER_SPEC )
3568 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_DPID_REGISTRAR_SPEC );
3570 else if ( wps_devicepassword_id == WPS_DPID_REGISTRAR_SPEC )
3572 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_DPID_USER_SPEC );
3576 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_DPID_PBC );
3580 // Commented by Kurt 20120113
3581 // If some device wants to do p2p handshake without sending prov_disc_req
3582 // We have to get peer_req_cm from here.
3583 if(_rtw_memcmp( pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req, "000", 3) )
3585 if ( wps_devicepassword_id == WPS_DPID_USER_SPEC )
3587 _rtw_memcpy( pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req, "dis", 3 );
3589 else if ( wps_devicepassword_id == WPS_DPID_REGISTRAR_SPEC )
3591 _rtw_memcpy( pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req, "pad", 3 );
3595 _rtw_memcpy( pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req, "pbc", 3 );
3599 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wpsielen, (unsigned char *) wpsie, &pattrib->pktlen );
3606 p2pie[ p2pielen++ ] = 0x50;
3607 p2pie[ p2pielen++ ] = 0x6F;
3608 p2pie[ p2pielen++ ] = 0x9A;
3609 p2pie[ p2pielen++ ] = 0x09; // WFA P2P v1.0
3611 // Commented by Albert 20100908
3612 // According to the P2P Specification, the group negoitation response frame should contain 9 P2P attributes
3614 // 2. P2P Capability
3615 // 3. Group Owner Intent
3616 // 4. Configuration Timeout
3617 // 5. Operating Channel
3618 // 6. Intended P2P Interface Address
3621 // 9. Group ID ( Only GO )
3628 p2pie[ p2pielen++ ] = P2P_ATTR_STATUS;
3631 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0001 );
3635 p2pie[ p2pielen++ ] = result;
3639 p2pie[ p2pielen++ ] = P2P_ATTR_CAPABILITY;
3642 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0002 );
3646 // Device Capability Bitmap, 1 byte
3648 if ( rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT) )
3650 // Commented by Albert 2011/03/08
3651 // According to the P2P specification
3652 // if the sending device will be client, the P2P Capability should be reserved of group negotation response frame
3653 p2pie[ p2pielen++ ] = 0;
3657 // Be group owner or meet the error case
3658 p2pie[ p2pielen++ ] = DMP_P2P_DEVCAP_SUPPORT;
3661 // Group Capability Bitmap, 1 byte
3662 if ( pwdinfo->persistent_supported )
3664 p2pie[ p2pielen++ ] = P2P_GRPCAP_CROSS_CONN | P2P_GRPCAP_PERSISTENT_GROUP;
3668 p2pie[ p2pielen++ ] = P2P_GRPCAP_CROSS_CONN;
3671 // Group Owner Intent
3673 p2pie[ p2pielen++ ] = P2P_ATTR_GO_INTENT;
3676 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0001 );
3680 if ( pwdinfo->peer_intent & 0x01 )
3682 // Peer's tie breaker bit is 1, our tie breaker bit should be 0
3683 p2pie[ p2pielen++ ] = ( pwdinfo->intent << 1 );
3687 // Peer's tie breaker bit is 0, our tie breaker bit should be 1
3688 p2pie[ p2pielen++ ] = ( ( pwdinfo->intent << 1 ) | BIT(0) );
3692 // Configuration Timeout
3694 p2pie[ p2pielen++ ] = P2P_ATTR_CONF_TIMEOUT;
3697 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0002 );
3701 p2pie[ p2pielen++ ] = 200; // 2 seconds needed to be the P2P GO
3702 p2pie[ p2pielen++ ] = 200; // 2 seconds needed to be the P2P Client
3704 // Operating Channel
3706 p2pie[ p2pielen++ ] = P2P_ATTR_OPERATING_CH;
3709 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0005 );
3714 p2pie[ p2pielen++ ] = 'X';
3715 p2pie[ p2pielen++ ] = 'X';
3717 // The third byte should be set to 0x04.
3718 // Described in the "Operating Channel Attribute" section.
3719 p2pie[ p2pielen++ ] = 0x04;
3722 if ( pwdinfo->operating_channel <= 14 )
3725 p2pie[ p2pielen++ ] = 0x51;
3727 else if ( ( pwdinfo->operating_channel >= 36 ) && ( pwdinfo->operating_channel <= 48 ) )
3730 p2pie[ p2pielen++ ] = 0x73;
3735 p2pie[ p2pielen++ ] = 0x7c;
3739 p2pie[ p2pielen++ ] = pwdinfo->operating_channel; // operating channel number
3741 // Intended P2P Interface Address
3743 p2pie[ p2pielen++ ] = P2P_ATTR_INTENTED_IF_ADDR;
3746 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( ETH_ALEN );
3750 _rtw_memcpy( p2pie + p2pielen, myid( &padapter->eeprompriv ), ETH_ALEN );
3751 p2pielen += ETH_ALEN;
3755 p2pie[ p2pielen++ ] = P2P_ATTR_CH_LIST;
3757 // Country String(3)
3758 // + ( Operating Class (1) + Number of Channels(1) ) * Operation Classes (?)
3759 // + number of channels in all classes
3760 len_channellist_attr = 3
3761 + (1 + 1) * (u16)pmlmeext->channel_list.reg_classes
3762 + get_reg_classes_full_count(pmlmeext->channel_list);
3764 #ifdef CONFIG_CONCURRENT_MODE
3765 if ( check_buddy_fwstate(padapter, _FW_LINKED ) )
3767 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 5 + 1 );
3771 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( len_channellist_attr );
3775 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( len_channellist_attr );
3782 p2pie[ p2pielen++ ] = 'X';
3783 p2pie[ p2pielen++ ] = 'X';
3785 // The third byte should be set to 0x04.
3786 // Described in the "Operating Channel Attribute" section.
3787 p2pie[ p2pielen++ ] = 0x04;
3789 // Channel Entry List
3791 #ifdef CONFIG_CONCURRENT_MODE
3792 if ( check_buddy_fwstate(padapter, _FW_LINKED ) )
3794 _adapter *pbuddy_adapter = padapter->pbuddy_adapter;
3795 struct mlme_ext_priv *pbuddy_mlmeext = &pbuddy_adapter->mlmeextpriv;
3798 if ( pbuddy_mlmeext->cur_channel > 14 )
3800 if ( pbuddy_mlmeext->cur_channel >= 149 )
3802 p2pie[ p2pielen++ ] = 0x7c;
3806 p2pie[ p2pielen++ ] = 0x73;
3811 p2pie[ p2pielen++ ] = 0x51;
3814 // Number of Channels
3815 // Just support 1 channel and this channel is AP's channel
3816 p2pie[ p2pielen++ ] = 1;
3819 p2pie[ p2pielen++ ] = pbuddy_mlmeext->cur_channel;
3824 for (j = 0; j < pmlmeext->channel_list.reg_classes; j++) {
3826 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].reg_class;
3828 // Number of Channels
3829 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channels;
3832 for (i = 0; i < pmlmeext->channel_list.reg_class[j].channels; i++) {
3833 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channel[i];
3837 #else // CONFIG_CONCURRENT_MODE
3840 for (j = 0; j < pmlmeext->channel_list.reg_classes; j++) {
3842 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].reg_class;
3844 // Number of Channels
3845 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channels;
3848 for (i = 0; i < pmlmeext->channel_list.reg_class[j].channels; i++) {
3849 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channel[i];
3853 #endif // CONFIG_CONCURRENT_MODE
3858 p2pie[ p2pielen++ ] = P2P_ATTR_DEVICE_INFO;
3861 // 21 -> P2P Device Address (6bytes) + Config Methods (2bytes) + Primary Device Type (8bytes)
3862 // + NumofSecondDevType (1byte) + WPS Device Name ID field (2bytes) + WPS Device Name Len field (2bytes)
3863 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 21 + pwdinfo->device_name_len );
3867 // P2P Device Address
3868 _rtw_memcpy( p2pie + p2pielen, myid( &padapter->eeprompriv ), ETH_ALEN );
3869 p2pielen += ETH_ALEN;
3872 // This field should be big endian. Noted by P2P specification.
3874 *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( pwdinfo->supported_wps_cm );
3878 // Primary Device Type
3880 *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( WPS_PDT_CID_MULIT_MEDIA );
3884 *(u32*) ( p2pie + p2pielen ) = cpu_to_be32( WPSOUI );
3888 *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( WPS_PDT_SCID_MEDIA_SERVER );
3891 // Number of Secondary Device Types
3892 p2pie[ p2pielen++ ] = 0x00; // No Secondary Device Type List
3896 *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( WPS_ATTR_DEVICE_NAME );
3900 *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( pwdinfo->device_name_len );
3904 _rtw_memcpy( p2pie + p2pielen, pwdinfo->device_name , pwdinfo->device_name_len );
3905 p2pielen += pwdinfo->device_name_len;
3907 if ( rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO) )
3909 // Group ID Attribute
3911 p2pie[ p2pielen++ ] = P2P_ATTR_GROUP_ID;
3914 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( ETH_ALEN + pwdinfo->nego_ssidlen );
3918 // p2P Device Address
3919 _rtw_memcpy( p2pie + p2pielen , pwdinfo->device_addr, ETH_ALEN );
3920 p2pielen += ETH_ALEN;
3923 _rtw_memcpy( p2pie + p2pielen, pwdinfo->nego_ssid, pwdinfo->nego_ssidlen );
3924 p2pielen += pwdinfo->nego_ssidlen;
3928 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *) p2pie, &pattrib->pktlen );
3931 wfdielen = build_nego_resp_wfd_ie(pwdinfo, pframe);
3933 pattrib->pktlen += wfdielen;
3936 pattrib->last_txcmdsz = pattrib->pktlen;
3938 dump_mgntframe(padapter, pmgntframe);
3944 void issue_p2p_GO_confirm(_adapter *padapter, u8* raddr, u8 result)
3947 unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
3948 u8 action = P2P_PUB_ACTION_ACTION;
3949 u32 p2poui = cpu_to_be32(P2POUI);
3950 u8 oui_subtype = P2P_GO_NEGO_CONF;
3951 u8 wpsie[ 255 ] = { 0x00 }, p2pie[ 255 ] = { 0x00 };
3952 u8 wpsielen = 0, p2pielen = 0;
3954 struct xmit_frame *pmgntframe;
3955 struct pkt_attrib *pattrib;
3956 unsigned char *pframe;
3957 struct rtw_ieee80211_hdr *pwlanhdr;
3958 unsigned short *fctrl;
3959 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
3960 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
3961 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
3962 struct wifidirect_info *pwdinfo = &( padapter->wdinfo);
3967 if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
3972 DBG_871X( "[%s] In\n", __FUNCTION__ );
3974 pattrib = &pmgntframe->attrib;
3975 update_mgntframe_attrib(padapter, pattrib);
3977 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
3979 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
3980 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
3982 fctrl = &(pwlanhdr->frame_ctl);
3985 _rtw_memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
3986 _rtw_memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
3987 _rtw_memcpy(pwlanhdr->addr3, myid(&(padapter->eeprompriv)), ETH_ALEN);
3989 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
3990 pmlmeext->mgnt_seq++;
3991 SetFrameSubType(pframe, WIFI_ACTION);
3993 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
3994 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
3996 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
3997 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
3998 pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *) &(p2poui), &(pattrib->pktlen));
3999 pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
4000 pframe = rtw_set_fixed_ie(pframe, 1, &(pwdinfo->negotiation_dialog_token), &(pattrib->pktlen));
4008 p2pie[ p2pielen++ ] = 0x50;
4009 p2pie[ p2pielen++ ] = 0x6F;
4010 p2pie[ p2pielen++ ] = 0x9A;
4011 p2pie[ p2pielen++ ] = 0x09; // WFA P2P v1.0
4013 // Commented by Albert 20110306
4014 // According to the P2P Specification, the group negoitation request frame should contain 5 P2P attributes
4016 // 2. P2P Capability
4017 // 3. Operating Channel
4019 // 5. Group ID ( if this WiFi is GO )
4023 p2pie[ p2pielen++ ] = P2P_ATTR_STATUS;
4026 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0001 );
4030 p2pie[ p2pielen++ ] = result;
4034 p2pie[ p2pielen++ ] = P2P_ATTR_CAPABILITY;
4037 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0002 );
4041 // Device Capability Bitmap, 1 byte
4042 p2pie[ p2pielen++ ] = DMP_P2P_DEVCAP_SUPPORT;
4044 // Group Capability Bitmap, 1 byte
4045 if ( pwdinfo->persistent_supported )
4047 p2pie[ p2pielen++ ] = P2P_GRPCAP_CROSS_CONN | P2P_GRPCAP_PERSISTENT_GROUP;
4051 p2pie[ p2pielen++ ] = P2P_GRPCAP_CROSS_CONN;
4055 // Operating Channel
4057 p2pie[ p2pielen++ ] = P2P_ATTR_OPERATING_CH;
4060 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0005 );
4065 p2pie[ p2pielen++ ] = 'X';
4066 p2pie[ p2pielen++ ] = 'X';
4068 // The third byte should be set to 0x04.
4069 // Described in the "Operating Channel Attribute" section.
4070 p2pie[ p2pielen++ ] = 0x04;
4073 if ( rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT) )
4075 if ( pwdinfo->peer_operating_ch <= 14 )
4078 p2pie[ p2pielen++ ] = 0x51;
4080 else if ( ( pwdinfo->peer_operating_ch >= 36 ) && ( pwdinfo->peer_operating_ch <= 48 ) )
4083 p2pie[ p2pielen++ ] = 0x73;
4088 p2pie[ p2pielen++ ] = 0x7c;
4091 p2pie[ p2pielen++ ] = pwdinfo->peer_operating_ch;
4095 if ( pwdinfo->operating_channel <= 14 )
4098 p2pie[ p2pielen++ ] = 0x51;
4100 else if ( ( pwdinfo->operating_channel >= 36 ) && ( pwdinfo->operating_channel <= 48 ) )
4103 p2pie[ p2pielen++ ] = 0x73;
4108 p2pie[ p2pielen++ ] = 0x7c;
4112 p2pie[ p2pielen++ ] = pwdinfo->operating_channel; // Use the listen channel as the operating channel
4118 p2pie[ p2pielen++ ] = P2P_ATTR_CH_LIST;
4120 *(u16*) ( p2pie + p2pielen ) = 6;
4124 p2pie[ p2pielen++ ] = 'X';
4125 p2pie[ p2pielen++ ] = 'X';
4127 // The third byte should be set to 0x04.
4128 // Described in the "Operating Channel Attribute" section.
4129 p2pie[ p2pielen++ ] = 0x04;
4132 if ( rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT) )
4134 if ( pwdinfo->peer_operating_ch <= 14 )
4137 p2pie[ p2pielen++ ] = 0x51;
4139 else if ( ( pwdinfo->peer_operating_ch >= 36 ) && ( pwdinfo->peer_operating_ch <= 48 ) )
4142 p2pie[ p2pielen++ ] = 0x73;
4147 p2pie[ p2pielen++ ] = 0x7c;
4149 p2pie[ p2pielen++ ] = 1;
4150 p2pie[ p2pielen++ ] = pwdinfo->peer_operating_ch;
4154 if ( pwdinfo->operating_channel <= 14 )
4157 p2pie[ p2pielen++ ] = 0x51;
4159 else if ( ( pwdinfo->operating_channel >= 36 ) && ( pwdinfo->operating_channel <= 48 ) )
4162 p2pie[ p2pielen++ ] = 0x73;
4167 p2pie[ p2pielen++ ] = 0x7c;
4171 p2pie[ p2pielen++ ] = 1;
4172 p2pie[ p2pielen++ ] = pwdinfo->operating_channel; // Use the listen channel as the operating channel
4175 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO) )
4177 // Group ID Attribute
4179 p2pie[ p2pielen++ ] = P2P_ATTR_GROUP_ID;
4182 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( ETH_ALEN + pwdinfo->nego_ssidlen );
4186 // p2P Device Address
4187 _rtw_memcpy( p2pie + p2pielen , pwdinfo->device_addr, ETH_ALEN );
4188 p2pielen += ETH_ALEN;
4191 _rtw_memcpy( p2pie + p2pielen, pwdinfo->nego_ssid, pwdinfo->nego_ssidlen );
4192 p2pielen += pwdinfo->nego_ssidlen;
4195 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *) p2pie, &pattrib->pktlen );
4198 wfdielen = build_nego_confirm_wfd_ie(pwdinfo, pframe);
4200 pattrib->pktlen += wfdielen;
4203 pattrib->last_txcmdsz = pattrib->pktlen;
4205 dump_mgntframe(padapter, pmgntframe);
4211 void issue_p2p_invitation_request(_adapter *padapter, u8* raddr )
4214 unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
4215 u8 action = P2P_PUB_ACTION_ACTION;
4216 u32 p2poui = cpu_to_be32(P2POUI);
4217 u8 oui_subtype = P2P_INVIT_REQ;
4218 u8 p2pie[ 255 ] = { 0x00 };
4221 u8 channel_cnt_24g = 0, channel_cnt_5gl = 0, channel_cnt_5gh = 0;
4222 u16 len_channellist_attr = 0;
4226 #ifdef CONFIG_CONCURRENT_MODE
4227 _adapter *pbuddy_adapter = padapter->pbuddy_adapter;
4228 struct wifidirect_info *pbuddy_wdinfo = &pbuddy_adapter->wdinfo;
4229 struct mlme_priv *pbuddy_mlmepriv = &pbuddy_adapter->mlmepriv;
4230 struct mlme_ext_priv *pbuddy_mlmeext = &pbuddy_adapter->mlmeextpriv;
4233 struct xmit_frame *pmgntframe;
4234 struct pkt_attrib *pattrib;
4235 unsigned char *pframe;
4236 struct rtw_ieee80211_hdr *pwlanhdr;
4237 unsigned short *fctrl;
4238 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
4239 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
4240 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
4241 struct wifidirect_info *pwdinfo = &( padapter->wdinfo);
4244 if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
4250 pattrib = &pmgntframe->attrib;
4251 update_mgntframe_attrib(padapter, pattrib);
4253 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
4255 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
4256 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
4258 fctrl = &(pwlanhdr->frame_ctl);
4261 _rtw_memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
4262 _rtw_memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
4263 _rtw_memcpy(pwlanhdr->addr3, raddr, ETH_ALEN);
4265 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
4266 pmlmeext->mgnt_seq++;
4267 SetFrameSubType(pframe, WIFI_ACTION);
4269 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
4270 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
4272 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
4273 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
4274 pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *) &(p2poui), &(pattrib->pktlen));
4275 pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
4276 pframe = rtw_set_fixed_ie(pframe, 1, &(dialogToken), &(pattrib->pktlen));
4282 p2pie[ p2pielen++ ] = 0x50;
4283 p2pie[ p2pielen++ ] = 0x6F;
4284 p2pie[ p2pielen++ ] = 0x9A;
4285 p2pie[ p2pielen++ ] = 0x09; // WFA P2P v1.0
4287 // Commented by Albert 20101011
4288 // According to the P2P Specification, the P2P Invitation request frame should contain 7 P2P attributes
4289 // 1. Configuration Timeout
4290 // 2. Invitation Flags
4291 // 3. Operating Channel ( Only GO )
4292 // 4. P2P Group BSSID ( Should be included if I am the GO )
4295 // 7. P2P Device Info
4297 // Configuration Timeout
4299 p2pie[ p2pielen++ ] = P2P_ATTR_CONF_TIMEOUT;
4302 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0002 );
4306 p2pie[ p2pielen++ ] = 200; // 2 seconds needed to be the P2P GO
4307 p2pie[ p2pielen++ ] = 200; // 2 seconds needed to be the P2P Client
4311 p2pie[ p2pielen++ ] = P2P_ATTR_INVITATION_FLAGS;
4314 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0001 );
4318 p2pie[ p2pielen++ ] = P2P_INVITATION_FLAGS_PERSISTENT;
4321 // Operating Channel
4323 p2pie[ p2pielen++ ] = P2P_ATTR_OPERATING_CH;
4326 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0005 );
4331 p2pie[ p2pielen++ ] = 'X';
4332 p2pie[ p2pielen++ ] = 'X';
4334 // The third byte should be set to 0x04.
4335 // Described in the "Operating Channel Attribute" section.
4336 p2pie[ p2pielen++ ] = 0x04;
4339 if ( pwdinfo->invitereq_info.operating_ch <= 14 )
4340 p2pie[ p2pielen++ ] = 0x51;
4341 else if ( ( pwdinfo->invitereq_info.operating_ch >= 36 ) && ( pwdinfo->invitereq_info.operating_ch <= 48 ) )
4342 p2pie[ p2pielen++ ] = 0x73;
4344 p2pie[ p2pielen++ ] = 0x7c;
4347 p2pie[ p2pielen++ ] = pwdinfo->invitereq_info.operating_ch; // operating channel number
4349 if ( _rtw_memcmp( myid( &padapter->eeprompriv ), pwdinfo->invitereq_info.go_bssid, ETH_ALEN ) )
4353 p2pie[ p2pielen++ ] = P2P_ATTR_GROUP_BSSID;
4356 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( ETH_ALEN );
4360 // P2P Device Address for GO
4361 _rtw_memcpy( p2pie + p2pielen, pwdinfo->invitereq_info.go_bssid, ETH_ALEN );
4362 p2pielen += ETH_ALEN;
4367 p2pie[ p2pielen++ ] = P2P_ATTR_CH_LIST;
4371 // Country String(3)
4372 // + ( Operating Class (1) + Number of Channels(1) ) * Operation Classes (?)
4373 // + number of channels in all classes
4374 len_channellist_attr = 3
4375 + (1 + 1) * (u16)pmlmeext->channel_list.reg_classes
4376 + get_reg_classes_full_count(pmlmeext->channel_list);
4378 #ifdef CONFIG_CONCURRENT_MODE
4379 if ( check_buddy_fwstate(padapter, _FW_LINKED ) )
4381 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 5 + 1 );
4385 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( len_channellist_attr );
4389 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( len_channellist_attr );
4396 p2pie[ p2pielen++ ] = 'X';
4397 p2pie[ p2pielen++ ] = 'X';
4399 // The third byte should be set to 0x04.
4400 // Described in the "Operating Channel Attribute" section.
4401 p2pie[ p2pielen++ ] = 0x04;
4403 // Channel Entry List
4404 #ifdef CONFIG_CONCURRENT_MODE
4405 if ( check_buddy_fwstate(padapter, _FW_LINKED ) )
4407 _adapter *pbuddy_adapter = padapter->pbuddy_adapter;
4408 struct mlme_ext_priv *pbuddy_mlmeext = &pbuddy_adapter->mlmeextpriv;
4411 if ( pbuddy_mlmeext->cur_channel > 14 )
4413 if ( pbuddy_mlmeext->cur_channel >= 149 )
4415 p2pie[ p2pielen++ ] = 0x7c;
4419 p2pie[ p2pielen++ ] = 0x73;
4424 p2pie[ p2pielen++ ] = 0x51;
4427 // Number of Channels
4428 // Just support 1 channel and this channel is AP's channel
4429 p2pie[ p2pielen++ ] = 1;
4432 p2pie[ p2pielen++ ] = pbuddy_mlmeext->cur_channel;
4437 for (j = 0; j < pmlmeext->channel_list.reg_classes; j++) {
4439 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].reg_class;
4441 // Number of Channels
4442 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channels;
4445 for (i = 0; i < pmlmeext->channel_list.reg_class[j].channels; i++) {
4446 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channel[i];
4450 #else // CONFIG_CONCURRENT_MODE
4453 for (j = 0; j < pmlmeext->channel_list.reg_classes; j++) {
4455 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].reg_class;
4457 // Number of Channels
4458 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channels;
4461 for (i = 0; i < pmlmeext->channel_list.reg_class[j].channels; i++) {
4462 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channel[i];
4466 #endif // CONFIG_CONCURRENT_MODE
4471 p2pie[ p2pielen++ ] = P2P_ATTR_GROUP_ID;
4474 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 6 + pwdinfo->invitereq_info.ssidlen );
4478 // P2P Device Address for GO
4479 _rtw_memcpy( p2pie + p2pielen, pwdinfo->invitereq_info.go_bssid, ETH_ALEN );
4480 p2pielen += ETH_ALEN;
4483 _rtw_memcpy( p2pie + p2pielen, pwdinfo->invitereq_info.go_ssid, pwdinfo->invitereq_info.ssidlen );
4484 p2pielen += pwdinfo->invitereq_info.ssidlen;
4489 p2pie[ p2pielen++ ] = P2P_ATTR_DEVICE_INFO;
4492 // 21 -> P2P Device Address (6bytes) + Config Methods (2bytes) + Primary Device Type (8bytes)
4493 // + NumofSecondDevType (1byte) + WPS Device Name ID field (2bytes) + WPS Device Name Len field (2bytes)
4494 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 21 + pwdinfo->device_name_len );
4498 // P2P Device Address
4499 _rtw_memcpy( p2pie + p2pielen, myid( &padapter->eeprompriv ), ETH_ALEN );
4500 p2pielen += ETH_ALEN;
4503 // This field should be big endian. Noted by P2P specification.
4504 *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( WPS_CONFIG_METHOD_DISPLAY );
4507 // Primary Device Type
4509 *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( WPS_PDT_CID_MULIT_MEDIA );
4513 *(u32*) ( p2pie + p2pielen ) = cpu_to_be32( WPSOUI );
4517 *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( WPS_PDT_SCID_MEDIA_SERVER );
4520 // Number of Secondary Device Types
4521 p2pie[ p2pielen++ ] = 0x00; // No Secondary Device Type List
4525 *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( WPS_ATTR_DEVICE_NAME );
4529 *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( pwdinfo->device_name_len );
4533 _rtw_memcpy( p2pie + p2pielen, pwdinfo->device_name, pwdinfo->device_name_len );
4534 p2pielen += pwdinfo->device_name_len;
4536 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *) p2pie, &pattrib->pktlen );
4539 wfdielen = build_invitation_req_wfd_ie(pwdinfo, pframe);
4541 pattrib->pktlen += wfdielen;
4544 pattrib->last_txcmdsz = pattrib->pktlen;
4546 dump_mgntframe(padapter, pmgntframe);
4552 void issue_p2p_invitation_response(_adapter *padapter, u8* raddr, u8 dialogToken, u8 status_code)
4555 unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
4556 u8 action = P2P_PUB_ACTION_ACTION;
4557 u32 p2poui = cpu_to_be32(P2POUI);
4558 u8 oui_subtype = P2P_INVIT_RESP;
4559 u8 p2pie[ 255 ] = { 0x00 };
4561 u8 channel_cnt_24g = 0, channel_cnt_5gl = 0, channel_cnt_5gh = 0;
4562 u16 len_channellist_attr = 0;
4563 #ifdef CONFIG_CONCURRENT_MODE
4564 _adapter *pbuddy_adapter = padapter->pbuddy_adapter;
4565 struct wifidirect_info *pbuddy_wdinfo = &pbuddy_adapter->wdinfo;
4566 struct mlme_priv *pbuddy_mlmepriv = &pbuddy_adapter->mlmepriv;
4567 struct mlme_ext_priv *pbuddy_mlmeext = &pbuddy_adapter->mlmeextpriv;
4573 struct xmit_frame *pmgntframe;
4574 struct pkt_attrib *pattrib;
4575 unsigned char *pframe;
4576 struct rtw_ieee80211_hdr *pwlanhdr;
4577 unsigned short *fctrl;
4578 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
4579 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
4580 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
4581 struct wifidirect_info *pwdinfo = &( padapter->wdinfo);
4584 if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
4590 pattrib = &pmgntframe->attrib;
4591 update_mgntframe_attrib(padapter, pattrib);
4593 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
4595 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
4596 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
4598 fctrl = &(pwlanhdr->frame_ctl);
4601 _rtw_memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
4602 _rtw_memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
4603 _rtw_memcpy(pwlanhdr->addr3, raddr, ETH_ALEN);
4605 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
4606 pmlmeext->mgnt_seq++;
4607 SetFrameSubType(pframe, WIFI_ACTION);
4609 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
4610 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
4612 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
4613 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
4614 pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *) &(p2poui), &(pattrib->pktlen));
4615 pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
4616 pframe = rtw_set_fixed_ie(pframe, 1, &(dialogToken), &(pattrib->pktlen));
4622 p2pie[ p2pielen++ ] = 0x50;
4623 p2pie[ p2pielen++ ] = 0x6F;
4624 p2pie[ p2pielen++ ] = 0x9A;
4625 p2pie[ p2pielen++ ] = 0x09; // WFA P2P v1.0
4627 // Commented by Albert 20101005
4628 // According to the P2P Specification, the P2P Invitation response frame should contain 5 P2P attributes
4630 // 2. Configuration Timeout
4631 // 3. Operating Channel ( Only GO )
4632 // 4. P2P Group BSSID ( Only GO )
4637 p2pie[ p2pielen++ ] = P2P_ATTR_STATUS;
4640 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0001 );
4644 // When status code is P2P_STATUS_FAIL_INFO_UNAVAILABLE.
4645 // Sent the event receiving the P2P Invitation Req frame to DMP UI.
4646 // DMP had to compare the MAC address to find out the profile.
4647 // So, the WiFi driver will send the P2P_STATUS_FAIL_INFO_UNAVAILABLE to NB.
4648 // If the UI found the corresponding profile, the WiFi driver sends the P2P Invitation Req
4649 // to NB to rebuild the persistent group.
4650 p2pie[ p2pielen++ ] = status_code;
4652 // Configuration Timeout
4654 p2pie[ p2pielen++ ] = P2P_ATTR_CONF_TIMEOUT;
4657 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0002 );
4661 p2pie[ p2pielen++ ] = 200; // 2 seconds needed to be the P2P GO
4662 p2pie[ p2pielen++ ] = 200; // 2 seconds needed to be the P2P Client
4664 if( status_code == P2P_STATUS_SUCCESS )
4666 if( rtw_p2p_chk_role( pwdinfo, P2P_ROLE_GO ) )
4668 // The P2P Invitation request frame asks this Wi-Fi device to be the P2P GO
4669 // In this case, the P2P Invitation response frame should carry the two more P2P attributes.
4670 // First one is operating channel attribute.
4671 // Second one is P2P Group BSSID attribute.
4673 // Operating Channel
4675 p2pie[ p2pielen++ ] = P2P_ATTR_OPERATING_CH;
4678 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0005 );
4683 p2pie[ p2pielen++ ] = 'X';
4684 p2pie[ p2pielen++ ] = 'X';
4686 // The third byte should be set to 0x04.
4687 // Described in the "Operating Channel Attribute" section.
4688 p2pie[ p2pielen++ ] = 0x04;
4691 p2pie[ p2pielen++ ] = 0x51; // Copy from SD7
4694 p2pie[ p2pielen++ ] = pwdinfo->operating_channel; // operating channel number
4699 p2pie[ p2pielen++ ] = P2P_ATTR_GROUP_BSSID;
4702 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( ETH_ALEN );
4706 // P2P Device Address for GO
4707 _rtw_memcpy( p2pie + p2pielen, myid( &padapter->eeprompriv ), ETH_ALEN );
4708 p2pielen += ETH_ALEN;
4714 p2pie[ p2pielen++ ] = P2P_ATTR_CH_LIST;
4717 // Country String(3)
4718 // + ( Operating Class (1) + Number of Channels(1) ) * Operation Classes (?)
4719 // + number of channels in all classes
4720 len_channellist_attr = 3
4721 + (1 + 1) * (u16)pmlmeext->channel_list.reg_classes
4722 + get_reg_classes_full_count(pmlmeext->channel_list);
4724 #ifdef CONFIG_CONCURRENT_MODE
4725 if ( check_buddy_fwstate(padapter, _FW_LINKED ) )
4727 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 5 + 1 );
4731 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( len_channellist_attr );
4735 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( len_channellist_attr );
4742 p2pie[ p2pielen++ ] = 'X';
4743 p2pie[ p2pielen++ ] = 'X';
4745 // The third byte should be set to 0x04.
4746 // Described in the "Operating Channel Attribute" section.
4747 p2pie[ p2pielen++ ] = 0x04;
4749 // Channel Entry List
4750 #ifdef CONFIG_CONCURRENT_MODE
4751 if ( check_buddy_fwstate(padapter, _FW_LINKED ) )
4753 _adapter *pbuddy_adapter = padapter->pbuddy_adapter;
4754 struct mlme_ext_priv *pbuddy_mlmeext = &pbuddy_adapter->mlmeextpriv;
4757 if ( pbuddy_mlmeext->cur_channel > 14 )
4759 if ( pbuddy_mlmeext->cur_channel >= 149 )
4761 p2pie[ p2pielen++ ] = 0x7c;
4765 p2pie[ p2pielen++ ] = 0x73;
4770 p2pie[ p2pielen++ ] = 0x51;
4773 // Number of Channels
4774 // Just support 1 channel and this channel is AP's channel
4775 p2pie[ p2pielen++ ] = 1;
4778 p2pie[ p2pielen++ ] = pbuddy_mlmeext->cur_channel;
4783 for (j = 0; j < pmlmeext->channel_list.reg_classes; j++) {
4785 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].reg_class;
4787 // Number of Channels
4788 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channels;
4791 for (i = 0; i < pmlmeext->channel_list.reg_class[j].channels; i++) {
4792 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channel[i];
4796 #else // CONFIG_CONCURRENT_MODE
4799 for (j = 0; j < pmlmeext->channel_list.reg_classes; j++) {
4801 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].reg_class;
4803 // Number of Channels
4804 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channels;
4807 for (i = 0; i < pmlmeext->channel_list.reg_class[j].channels; i++) {
4808 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channel[i];
4812 #endif // CONFIG_CONCURRENT_MODE
4815 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *) p2pie, &pattrib->pktlen );
4818 wfdielen = build_invitation_resp_wfd_ie(pwdinfo, pframe);
4820 pattrib->pktlen += wfdielen;
4823 pattrib->last_txcmdsz = pattrib->pktlen;
4825 dump_mgntframe(padapter, pmgntframe);
4831 void issue_p2p_provision_request(_adapter *padapter, u8* pssid, u8 ussidlen, u8* pdev_raddr )
4833 unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
4834 u8 action = P2P_PUB_ACTION_ACTION;
4836 u32 p2poui = cpu_to_be32(P2POUI);
4837 u8 oui_subtype = P2P_PROVISION_DISC_REQ;
4838 u8 wpsie[ 100 ] = { 0x00 };
4845 struct xmit_frame *pmgntframe;
4846 struct pkt_attrib *pattrib;
4847 unsigned char *pframe;
4848 struct rtw_ieee80211_hdr *pwlanhdr;
4849 unsigned short *fctrl;
4850 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
4851 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
4852 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
4853 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
4856 if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
4861 DBG_871X( "[%s] In\n", __FUNCTION__ );
4863 pattrib = &pmgntframe->attrib;
4864 update_mgntframe_attrib(padapter, pattrib);
4866 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
4868 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
4869 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
4871 fctrl = &(pwlanhdr->frame_ctl);
4874 _rtw_memcpy(pwlanhdr->addr1, pdev_raddr, ETH_ALEN);
4875 _rtw_memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
4876 _rtw_memcpy(pwlanhdr->addr3, pdev_raddr, ETH_ALEN);
4878 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
4879 pmlmeext->mgnt_seq++;
4880 SetFrameSubType(pframe, WIFI_ACTION);
4882 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
4883 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
4885 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
4886 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
4887 pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *) &(p2poui), &(pattrib->pktlen));
4888 pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
4889 pframe = rtw_set_fixed_ie(pframe, 1, &(dialogToken), &(pattrib->pktlen));
4891 p2pielen = build_prov_disc_request_p2p_ie( pwdinfo, pframe, pssid, ussidlen, pdev_raddr );
4894 pattrib->pktlen += p2pielen;
4898 *(u32*) ( wpsie ) = cpu_to_be32( WPSOUI );
4903 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_ATTR_VER1 );
4907 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( 0x0001 );
4911 wpsie[wpsielen++] = WPS_VERSION_1; // Version 1.0
4915 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_ATTR_CONF_METHOD );
4919 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( 0x0002 );
4923 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( pwdinfo->tx_prov_disc_info.wps_config_method_request );
4926 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wpsielen, (unsigned char *) wpsie, &pattrib->pktlen );
4930 wfdielen = build_provdisc_req_wfd_ie(pwdinfo, pframe);
4932 pattrib->pktlen += wfdielen;
4935 pattrib->last_txcmdsz = pattrib->pktlen;
4937 dump_mgntframe(padapter, pmgntframe);
4944 u8 is_matched_in_profilelist( u8* peermacaddr, struct profile_info* profileinfo )
4946 u8 i, match_result = 0;
4948 DBG_871X( "[%s] peermac = %.2X %.2X %.2X %.2X %.2X %.2X\n", __FUNCTION__,
4949 peermacaddr[0], peermacaddr[1],peermacaddr[2],peermacaddr[3],peermacaddr[4],peermacaddr[5]);
4951 for( i = 0; i < P2P_MAX_PERSISTENT_GROUP_NUM; i++, profileinfo++ )
4953 DBG_871X( "[%s] profileinfo_mac = %.2X %.2X %.2X %.2X %.2X %.2X\n", __FUNCTION__,
4954 profileinfo->peermac[0], profileinfo->peermac[1],profileinfo->peermac[2],profileinfo->peermac[3],profileinfo->peermac[4],profileinfo->peermac[5]);
4955 if ( _rtw_memcmp( peermacaddr, profileinfo->peermac, ETH_ALEN ) )
4958 DBG_871X( "[%s] Match!\n", __FUNCTION__ );
4963 return (match_result );
4966 void issue_probersp_p2p(_adapter *padapter, unsigned char *da)
4968 struct xmit_frame *pmgntframe;
4969 struct pkt_attrib *pattrib;
4970 unsigned char *pframe;
4971 struct rtw_ieee80211_hdr *pwlanhdr;
4972 unsigned short *fctrl;
4974 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
4975 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
4976 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
4977 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
4978 //WLAN_BSSID_EX *cur_network = &(pmlmeinfo->network);
4979 u16 beacon_interval = 100;
4981 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
4982 u8 wpsie[255] = { 0x00 };
4983 u32 wpsielen = 0, p2pielen = 0;
4987 #ifdef CONFIG_INTEL_WIDI
4988 u8 zero_array_check[L2SDTA_SERVICE_VE_LEN] = { 0x00 };
4989 #endif //CONFIG_INTEL_WIDI
4991 //DBG_871X("%s\n", __FUNCTION__);
4993 if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
4999 pattrib = &pmgntframe->attrib;
5000 update_mgntframe_attrib(padapter, pattrib);
5002 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
5004 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
5005 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
5007 mac = myid(&(padapter->eeprompriv));
5009 fctrl = &(pwlanhdr->frame_ctl);
5011 _rtw_memcpy(pwlanhdr->addr1, da, ETH_ALEN);
5012 _rtw_memcpy(pwlanhdr->addr2, mac, ETH_ALEN);
5014 // Use the device address for BSSID field.
5015 _rtw_memcpy(pwlanhdr->addr3, mac, ETH_ALEN);
5017 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
5018 pmlmeext->mgnt_seq++;
5019 SetFrameSubType(fctrl, WIFI_PROBERSP);
5021 pattrib->hdrlen = sizeof(struct rtw_ieee80211_hdr_3addr);
5022 pattrib->pktlen = pattrib->hdrlen;
5023 pframe += pattrib->hdrlen;
5025 //timestamp will be inserted by hardware
5027 pattrib->pktlen += 8;
5029 // beacon interval: 2 bytes
5030 _rtw_memcpy(pframe, (unsigned char *) &beacon_interval, 2);
5032 pattrib->pktlen += 2;
5034 // capability info: 2 bytes
5035 // ESS and IBSS bits must be 0 (defined in the 3.1.2.1.1 of WiFi Direct Spec)
5036 capInfo |= cap_ShortPremble;
5037 capInfo |= cap_ShortSlot;
5039 _rtw_memcpy(pframe, (unsigned char *) &capInfo, 2);
5041 pattrib->pktlen += 2;
5045 pframe = rtw_set_ie(pframe, _SSID_IE_, 7, pwdinfo->p2p_wildcard_ssid, &pattrib->pktlen);
5047 // supported rates...
5048 // Use the OFDM rate in the P2P probe response frame. ( 6(B), 9(B), 12, 18, 24, 36, 48, 54 )
5049 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, 8, pwdinfo->support_rate, &pattrib->pktlen);
5052 pframe = rtw_set_ie(pframe, _DSSET_IE_, 1, (unsigned char *)&pwdinfo->listen_channel, &pattrib->pktlen);
5054 #ifdef CONFIG_IOCTL_CFG80211
5055 if(adapter_wdev_data(padapter)->p2p_enabled && pwdinfo->driver_interface == DRIVER_CFG80211 )
5057 if( pmlmepriv->wps_probe_resp_ie != NULL && pmlmepriv->p2p_probe_resp_ie != NULL )
5060 _rtw_memcpy(pframe, pmlmepriv->wps_probe_resp_ie, pmlmepriv->wps_probe_resp_ie_len);
5061 pattrib->pktlen += pmlmepriv->wps_probe_resp_ie_len;
5062 pframe += pmlmepriv->wps_probe_resp_ie_len;
5065 _rtw_memcpy(pframe, pmlmepriv->p2p_probe_resp_ie, pmlmepriv->p2p_probe_resp_ie_len);
5066 pattrib->pktlen += pmlmepriv->p2p_probe_resp_ie_len;
5067 pframe += pmlmepriv->p2p_probe_resp_ie_len;
5071 #endif //CONFIG_IOCTL_CFG80211
5075 // Noted by Albert 20100907
5076 // According to the WPS specification, all the WPS attribute is presented by Big Endian.
5080 *(u32*) ( wpsie ) = cpu_to_be32( WPSOUI );
5085 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_ATTR_VER1 );
5089 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( 0x0001 );
5093 wpsie[wpsielen++] = WPS_VERSION_1; // Version 1.0
5095 #ifdef CONFIG_INTEL_WIDI
5096 // Commented by Kurt
5097 // Appended WiDi info. only if we did issued_probereq_widi(), and then we saved ven. ext. in pmlmepriv->sa_ext.
5098 if( _rtw_memcmp(pmlmepriv->sa_ext, zero_array_check, L2SDTA_SERVICE_VE_LEN) == _FALSE
5099 || pmlmepriv->num_p2p_sdt != 0 )
5102 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_ATTR_SEC_DEV_TYPE_LIST );
5106 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( 0x0008 );
5111 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_PDT_CID_DISPLAYS );
5115 *(u32*) ( wpsie + wpsielen ) = cpu_to_be32( INTEL_DEV_TYPE_OUI );
5118 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_PDT_SCID_WIDI_CONSUMER_SINK );
5121 if( _rtw_memcmp(pmlmepriv->sa_ext, zero_array_check, L2SDTA_SERVICE_VE_LEN) == _FALSE )
5124 _rtw_memcpy( wpsie + wpsielen, pmlmepriv->sa_ext, L2SDTA_SERVICE_VE_LEN );
5125 wpsielen += L2SDTA_SERVICE_VE_LEN;
5128 #endif //CONFIG_INTEL_WIDI
5130 // WiFi Simple Config State
5132 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_ATTR_SIMPLE_CONF_STATE );
5136 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( 0x0001 );
5140 wpsie[wpsielen++] = WPS_WSC_STATE_NOT_CONFIG; // Not Configured.
5144 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_ATTR_RESP_TYPE );
5148 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( 0x0001 );
5152 wpsie[wpsielen++] = WPS_RESPONSE_TYPE_8021X;
5156 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_ATTR_UUID_E );
5160 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( 0x0010 );
5164 if (pwdinfo->external_uuid == 0) {
5165 _rtw_memset( wpsie + wpsielen, 0x0, 16 );
5166 _rtw_memcpy( wpsie + wpsielen, myid( &padapter->eeprompriv ), ETH_ALEN );
5168 _rtw_memcpy( wpsie + wpsielen, pwdinfo->uuid, 0x10 );
5174 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_ATTR_MANUFACTURER );
5178 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( 0x0007 );
5182 _rtw_memcpy( wpsie + wpsielen, "Realtek", 7 );
5187 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_ATTR_MODEL_NAME );
5191 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( 0x0006 );
5195 _rtw_memcpy( wpsie + wpsielen, "8192CU", 6 );
5200 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_ATTR_MODEL_NUMBER );
5204 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( 0x0001 );
5208 wpsie[ wpsielen++ ] = 0x31; // character 1
5212 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_ATTR_SERIAL_NUMBER );
5216 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( ETH_ALEN );
5220 _rtw_memcpy( wpsie + wpsielen, "123456" , ETH_ALEN );
5221 wpsielen += ETH_ALEN;
5223 // Primary Device Type
5225 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_ATTR_PRIMARY_DEV_TYPE );
5229 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( 0x0008 );
5234 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_PDT_CID_MULIT_MEDIA );
5238 *(u32*) ( wpsie + wpsielen ) = cpu_to_be32( WPSOUI );
5242 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_PDT_SCID_MEDIA_SERVER );
5247 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_ATTR_DEVICE_NAME );
5251 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( pwdinfo->device_name_len );
5255 _rtw_memcpy( wpsie + wpsielen, pwdinfo->device_name, pwdinfo->device_name_len );
5256 wpsielen += pwdinfo->device_name_len;
5260 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_ATTR_CONF_METHOD );
5264 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( 0x0002 );
5268 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( pwdinfo->supported_wps_cm );
5272 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wpsielen, (unsigned char *) wpsie, &pattrib->pktlen );
5275 p2pielen = build_probe_resp_p2p_ie(pwdinfo, pframe);
5277 pattrib->pktlen += p2pielen;
5281 #ifdef CONFIG_IOCTL_CFG80211
5282 if ( _TRUE == pwdinfo->wfd_info->wfd_enable )
5283 #endif //CONFIG_IOCTL_CFG80211
5285 wfdielen = build_probe_resp_wfd_ie(pwdinfo, pframe, 0);
5287 pattrib->pktlen += wfdielen;
5289 #ifdef CONFIG_IOCTL_CFG80211
5290 else if (pmlmepriv->wfd_probe_resp_ie != NULL && pmlmepriv->wfd_probe_resp_ie_len>0)
5293 _rtw_memcpy(pframe, pmlmepriv->wfd_probe_resp_ie, pmlmepriv->wfd_probe_resp_ie_len);
5294 pattrib->pktlen += pmlmepriv->wfd_probe_resp_ie_len;
5295 pframe += pmlmepriv->wfd_probe_resp_ie_len;
5297 #endif //CONFIG_IOCTL_CFG80211
5300 pattrib->last_txcmdsz = pattrib->pktlen;
5303 dump_mgntframe(padapter, pmgntframe);
5309 int _issue_probereq_p2p(_adapter *padapter, u8 *da, int wait_ack)
5312 struct xmit_frame *pmgntframe;
5313 struct pkt_attrib *pattrib;
5314 unsigned char *pframe;
5315 struct rtw_ieee80211_hdr *pwlanhdr;
5316 unsigned short *fctrl;
5318 unsigned char bssrate[NumRates];
5319 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
5320 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
5321 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
5322 int bssrate_len = 0;
5323 u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
5324 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
5325 u8 wpsie[255] = { 0x00 }, p2pie[ 255 ] = { 0x00 };
5326 u16 wpsielen = 0, p2pielen = 0;
5331 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
5334 if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
5340 pattrib = &pmgntframe->attrib;
5341 update_mgntframe_attrib(padapter, pattrib);
5344 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
5346 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
5347 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
5349 mac = myid(&(padapter->eeprompriv));
5351 fctrl = &(pwlanhdr->frame_ctl);
5355 _rtw_memcpy(pwlanhdr->addr1, da, ETH_ALEN);
5356 _rtw_memcpy(pwlanhdr->addr3, da, ETH_ALEN);
5358 if ( ( pwdinfo->p2p_info.scan_op_ch_only ) || ( pwdinfo->rx_invitereq_info.scan_op_ch_only ) )
5360 // This two flags will be set when this is only the P2P client mode.
5361 _rtw_memcpy(pwlanhdr->addr1, pwdinfo->p2p_peer_interface_addr, ETH_ALEN);
5362 _rtw_memcpy(pwlanhdr->addr3, pwdinfo->p2p_peer_interface_addr, ETH_ALEN);
5366 // broadcast probe request frame
5367 _rtw_memcpy(pwlanhdr->addr1, bc_addr, ETH_ALEN);
5368 _rtw_memcpy(pwlanhdr->addr3, bc_addr, ETH_ALEN);
5371 _rtw_memcpy(pwlanhdr->addr2, mac, ETH_ALEN);
5373 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
5374 pmlmeext->mgnt_seq++;
5375 SetFrameSubType(pframe, WIFI_PROBEREQ);
5377 pframe += sizeof (struct rtw_ieee80211_hdr_3addr);
5378 pattrib->pktlen = sizeof (struct rtw_ieee80211_hdr_3addr);
5380 if(rtw_p2p_chk_state(pwdinfo, P2P_STATE_TX_PROVISION_DIS_REQ))
5382 pframe = rtw_set_ie(pframe, _SSID_IE_, pwdinfo->tx_prov_disc_info.ssid.SsidLength, pwdinfo->tx_prov_disc_info.ssid.Ssid, &(pattrib->pktlen));
5386 pframe = rtw_set_ie(pframe, _SSID_IE_, P2P_WILDCARD_SSID_LEN, pwdinfo->p2p_wildcard_ssid, &(pattrib->pktlen));
5388 // Use the OFDM rate in the P2P probe request frame. ( 6(B), 9(B), 12(B), 24(B), 36, 48, 54 )
5389 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, 8, pwdinfo->support_rate, &pattrib->pktlen);
5391 #ifdef CONFIG_IOCTL_CFG80211
5392 if(adapter_wdev_data(padapter)->p2p_enabled && pwdinfo->driver_interface == DRIVER_CFG80211 )
5394 if( pmlmepriv->wps_probe_req_ie != NULL && pmlmepriv->p2p_probe_req_ie != NULL )
5397 _rtw_memcpy(pframe, pmlmepriv->wps_probe_req_ie, pmlmepriv->wps_probe_req_ie_len);
5398 pattrib->pktlen += pmlmepriv->wps_probe_req_ie_len;
5399 pframe += pmlmepriv->wps_probe_req_ie_len;
5402 _rtw_memcpy(pframe, pmlmepriv->p2p_probe_req_ie, pmlmepriv->p2p_probe_req_ie_len);
5403 pattrib->pktlen += pmlmepriv->p2p_probe_req_ie_len;
5404 pframe += pmlmepriv->p2p_probe_req_ie_len;
5408 #endif //CONFIG_IOCTL_CFG80211
5412 // Noted by Albert 20110221
5413 // According to the WPS specification, all the WPS attribute is presented by Big Endian.
5417 *(u32*) ( wpsie ) = cpu_to_be32( WPSOUI );
5422 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_ATTR_VER1 );
5426 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( 0x0001 );
5430 wpsie[wpsielen++] = WPS_VERSION_1; // Version 1.0
5432 if( pmlmepriv->wps_probe_req_ie == NULL )
5436 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_ATTR_UUID_E );
5440 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( 0x0010 );
5444 if (pwdinfo->external_uuid == 0) {
5445 _rtw_memset( wpsie + wpsielen, 0x0, 16 );
5446 _rtw_memcpy( wpsie + wpsielen, myid( &padapter->eeprompriv ), ETH_ALEN );
5448 _rtw_memcpy( wpsie + wpsielen, pwdinfo->uuid, 0x10 );
5454 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_ATTR_CONF_METHOD );
5458 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( 0x0002 );
5462 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( pwdinfo->supported_wps_cm );
5468 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_ATTR_DEVICE_NAME );
5472 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( pwdinfo->device_name_len );
5476 _rtw_memcpy( wpsie + wpsielen, pwdinfo->device_name, pwdinfo->device_name_len );
5477 wpsielen += pwdinfo->device_name_len;
5479 // Primary Device Type
5481 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_ATTR_PRIMARY_DEV_TYPE );
5485 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( 0x0008 );
5490 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_PDT_CID_RTK_WIDI );
5494 *(u32*) ( wpsie + wpsielen ) = cpu_to_be32( WPSOUI );
5498 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_PDT_SCID_RTK_DMP );
5501 // Device Password ID
5503 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_ATTR_DEVICE_PWID );
5507 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( 0x0002 );
5511 *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_DPID_REGISTRAR_SPEC ); // Registrar-specified
5514 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wpsielen, (unsigned char *) wpsie, &pattrib->pktlen );
5518 p2pie[ p2pielen++ ] = 0x50;
5519 p2pie[ p2pielen++ ] = 0x6F;
5520 p2pie[ p2pielen++ ] = 0x9A;
5521 p2pie[ p2pielen++ ] = 0x09; // WFA P2P v1.0
5523 // Commented by Albert 20110221
5524 // According to the P2P Specification, the probe request frame should contain 5 P2P attributes
5525 // 1. P2P Capability
5526 // 2. P2P Device ID if this probe request wants to find the specific P2P device
5527 // 3. Listen Channel
5528 // 4. Extended Listen Timing
5529 // 5. Operating Channel if this WiFi is working as the group owner now
5533 p2pie[ p2pielen++ ] = P2P_ATTR_CAPABILITY;
5536 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0002 );
5540 // Device Capability Bitmap, 1 byte
5541 p2pie[ p2pielen++ ] = DMP_P2P_DEVCAP_SUPPORT;
5543 // Group Capability Bitmap, 1 byte
5544 if ( pwdinfo->persistent_supported )
5545 p2pie[ p2pielen++ ] = P2P_GRPCAP_PERSISTENT_GROUP | DMP_P2P_GRPCAP_SUPPORT;
5547 p2pie[ p2pielen++ ] = DMP_P2P_GRPCAP_SUPPORT;
5551 p2pie[ p2pielen++ ] = P2P_ATTR_LISTEN_CH;
5554 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0005 );
5559 p2pie[ p2pielen++ ] = 'X';
5560 p2pie[ p2pielen++ ] = 'X';
5562 // The third byte should be set to 0x04.
5563 // Described in the "Operating Channel Attribute" section.
5564 p2pie[ p2pielen++ ] = 0x04;
5567 p2pie[ p2pielen++ ] = 0x51; // Copy from SD7
5570 p2pie[ p2pielen++ ] = pwdinfo->listen_channel; // listen channel
5573 // Extended Listen Timing
5575 p2pie[ p2pielen++ ] = P2P_ATTR_EX_LISTEN_TIMING;
5578 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0004 );
5582 // Availability Period
5583 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0xFFFF );
5586 // Availability Interval
5587 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0xFFFF );
5590 if ( rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO) )
5592 // Operating Channel (if this WiFi is working as the group owner now)
5594 p2pie[ p2pielen++ ] = P2P_ATTR_OPERATING_CH;
5597 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0005 );
5602 p2pie[ p2pielen++ ] = 'X';
5603 p2pie[ p2pielen++ ] = 'X';
5605 // The third byte should be set to 0x04.
5606 // Described in the "Operating Channel Attribute" section.
5607 p2pie[ p2pielen++ ] = 0x04;
5610 p2pie[ p2pielen++ ] = 0x51; // Copy from SD7
5613 p2pie[ p2pielen++ ] = pwdinfo->operating_channel; // operating channel number
5617 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *) p2pie, &pattrib->pktlen );
5622 #ifdef CONFIG_IOCTL_CFG80211
5623 if ( _TRUE == pwdinfo->wfd_info->wfd_enable )
5626 wfdielen = build_probe_req_wfd_ie(pwdinfo, pframe);
5628 pattrib->pktlen += wfdielen;
5630 #ifdef CONFIG_IOCTL_CFG80211
5631 else if (pmlmepriv->wfd_probe_req_ie != NULL && pmlmepriv->wfd_probe_req_ie_len>0)
5634 _rtw_memcpy(pframe, pmlmepriv->wfd_probe_req_ie, pmlmepriv->wfd_probe_req_ie_len);
5635 pattrib->pktlen += pmlmepriv->wfd_probe_req_ie_len;
5636 pframe += pmlmepriv->wfd_probe_req_ie_len;
5638 #endif //CONFIG_IOCTL_CFG80211
5641 pattrib->last_txcmdsz = pattrib->pktlen;
5643 RT_TRACE(_module_rtl871x_mlme_c_,_drv_info_,("issuing probe_req, tx_len=%d\n", pattrib->last_txcmdsz));
5646 ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
5648 dump_mgntframe(padapter, pmgntframe);
5656 inline void issue_probereq_p2p(_adapter *adapter, u8 *da)
5658 _issue_probereq_p2p(adapter, da, _FALSE);
5661 int issue_probereq_p2p_ex(_adapter *adapter, u8 *da, int try_cnt, int wait_ms)
5665 u32 start = rtw_get_current_time();
5669 ret = _issue_probereq_p2p(adapter, da, wait_ms>0?_TRUE:_FALSE);
5673 if (adapter->bDriverStopped || adapter->bSurpriseRemoved)
5676 if(i < try_cnt && wait_ms > 0 && ret==_FAIL)
5677 rtw_msleep_os(wait_ms);
5679 }while((i<try_cnt) && ((ret==_FAIL)||(wait_ms==0)));
5683 #ifndef DBG_XMIT_ACK
5688 if (try_cnt && wait_ms) {
5690 DBG_871X(FUNC_ADPT_FMT" to "MAC_FMT", ch:%u%s, %d/%d in %u ms\n",
5691 FUNC_ADPT_ARG(adapter), MAC_ARG(da), rtw_get_oper_ch(adapter),
5692 ret==_SUCCESS?", acked":"", i, try_cnt, rtw_get_passing_time_ms(start));
5694 DBG_871X(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n",
5695 FUNC_ADPT_ARG(adapter), rtw_get_oper_ch(adapter),
5696 ret==_SUCCESS?", acked":"", i, try_cnt, rtw_get_passing_time_ms(start));
5704 s32 rtw_action_public_decache(union recv_frame *recv_frame, s32 token)
5706 _adapter *adapter = recv_frame->u.hdr.adapter;
5707 struct mlme_ext_priv *mlmeext = &(adapter->mlmeextpriv);
5708 u8 *frame = recv_frame->u.hdr.rx_data;
5709 u16 seq_ctrl = ( (recv_frame->u.hdr.attrib.seq_num&0xffff) << 4) |
5710 (recv_frame->u.hdr.attrib.frag_num & 0xf);
5712 if (GetRetry(frame)) {
5714 if ((seq_ctrl == mlmeext->action_public_rxseq)
5715 && (token == mlmeext->action_public_dialog_token))
5717 DBG_871X(FUNC_ADPT_FMT" seq_ctrl=0x%x, rxseq=0x%x, token:%d\n",
5718 FUNC_ADPT_ARG(adapter), seq_ctrl, mlmeext->action_public_rxseq, token);
5722 if (seq_ctrl == mlmeext->action_public_rxseq) {
5723 DBG_871X(FUNC_ADPT_FMT" seq_ctrl=0x%x, rxseq=0x%x\n",
5724 FUNC_ADPT_ARG(adapter), seq_ctrl, mlmeext->action_public_rxseq);
5730 mlmeext->action_public_rxseq = seq_ctrl;
5733 mlmeext->action_public_dialog_token = token;
5738 unsigned int on_action_public_p2p(union recv_frame *precv_frame)
5740 _adapter *padapter = precv_frame->u.hdr.adapter;
5741 u8 *pframe = precv_frame->u.hdr.rx_data;
5742 uint len = precv_frame->u.hdr.len;
5747 u32 p2p_ielen, wps_ielen;
5748 struct wifidirect_info *pwdinfo = &( padapter->wdinfo );
5749 u8 result = P2P_STATUS_SUCCESS;
5750 u8 empty_addr[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
5751 u8 *merged_p2pie = NULL;
5752 u32 merged_p2p_ielen= 0;
5755 frame_body = (unsigned char *)(pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
5757 dialogToken = frame_body[7];
5759 if (rtw_action_public_decache(precv_frame, dialogToken) == _FAIL)
5763 _cancel_timer_ex( &pwdinfo->reset_ch_sitesurvey );
5764 #ifdef CONFIG_IOCTL_CFG80211
5765 if(adapter_wdev_data(padapter)->p2p_enabled && pwdinfo->driver_interface == DRIVER_CFG80211)
5767 rtw_cfg80211_rx_p2p_action_public(padapter, pframe, len);
5770 #endif //CONFIG_IOCTL_CFG80211
5772 // Do nothing if the driver doesn't enable the P2P function.
5773 if(rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE) || rtw_p2p_chk_state(pwdinfo, P2P_STATE_IDLE))
5776 len -= sizeof(struct rtw_ieee80211_hdr_3addr);
5778 switch( frame_body[ 6 ] )//OUI Subtype
5780 case P2P_GO_NEGO_REQ:
5782 DBG_871X( "[%s] Got GO Nego Req Frame\n", __FUNCTION__);
5783 _rtw_memset( &pwdinfo->groupid_info, 0x00, sizeof( struct group_id_info ) );
5785 if(rtw_p2p_chk_state(pwdinfo, P2P_STATE_RX_PROVISION_DIS_REQ))
5787 rtw_p2p_set_state(pwdinfo, rtw_p2p_pre_state(pwdinfo));
5790 if(rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_FAIL))
5792 // Commented by Albert 20110526
5793 // In this case, this means the previous nego fail doesn't be reset yet.
5794 _cancel_timer_ex( &pwdinfo->restore_p2p_state_timer );
5795 // Restore the previous p2p state
5796 rtw_p2p_set_state(pwdinfo, rtw_p2p_pre_state(pwdinfo));
5797 DBG_871X( "[%s] Restore the previous p2p state to %d\n", __FUNCTION__, rtw_p2p_state(pwdinfo) );
5799 #ifdef CONFIG_CONCURRENT_MODE
5800 if ( check_buddy_fwstate(padapter, _FW_LINKED ) )
5802 _cancel_timer_ex( &pwdinfo->ap_p2p_switch_timer );
5804 #endif // CONFIG_CONCURRENT_MODE
5806 // Commented by Kurt 20110902
5807 //Add if statement to avoid receiving duplicate prov disc req. such that pre_p2p_state would be covered.
5808 if(!rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_ING))
5809 rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
5811 // Commented by Kurt 20120113
5812 // Get peer_dev_addr here if peer doesn't issue prov_disc frame.
5813 if( _rtw_memcmp(pwdinfo->rx_prov_disc_info.peerDevAddr, empty_addr, ETH_ALEN) )
5814 _rtw_memcpy(pwdinfo->rx_prov_disc_info.peerDevAddr, GetAddr2Ptr(pframe), ETH_ALEN);
5816 result = process_p2p_group_negotation_req( pwdinfo, frame_body, len );
5817 issue_p2p_GO_response( padapter, GetAddr2Ptr(pframe), frame_body, len, result );
5818 #ifdef CONFIG_INTEL_WIDI
5819 if( (padapter->mlmepriv.widi_state == INTEL_WIDI_STATE_LISTEN) && (padapter->mlmepriv.widi_state != INTEL_WIDI_STATE_WFD_CONNECTION) )
5821 padapter->mlmepriv.widi_state = INTEL_WIDI_STATE_WFD_CONNECTION;
5822 _cancel_timer_ex(&(padapter->mlmepriv.listen_timer));
5823 intel_widi_wk_cmd(padapter, INTEL_WIDI_LISTEN_STOP_WK, NULL, 0);
5825 #endif //CONFIG_INTEL_WIDI
5827 // Commented by Albert 20110718
5828 // No matter negotiating or negotiation failure, the driver should set up the restore P2P state timer.
5829 #ifdef CONFIG_CONCURRENT_MODE
5830 // Commented by Albert 20120107
5831 _set_timer( &pwdinfo->restore_p2p_state_timer, 3000 );
5832 #else // CONFIG_CONCURRENT_MODE
5833 _set_timer( &pwdinfo->restore_p2p_state_timer, 5000 );
5834 #endif // CONFIG_CONCURRENT_MODE
5837 case P2P_GO_NEGO_RESP:
5839 DBG_871X( "[%s] Got GO Nego Resp Frame\n", __FUNCTION__);
5841 if(rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_ING))
5843 // Commented by Albert 20110425
5844 // The restore timer is enabled when issuing the nego request frame of rtw_p2p_connect function.
5845 _cancel_timer_ex( &pwdinfo->restore_p2p_state_timer );
5846 pwdinfo->nego_req_info.benable = _FALSE;
5847 result = process_p2p_group_negotation_resp( pwdinfo, frame_body, len);
5848 issue_p2p_GO_confirm( pwdinfo->padapter, GetAddr2Ptr(pframe), result);
5849 if ( P2P_STATUS_SUCCESS == result )
5851 if ( rtw_p2p_role(pwdinfo) == P2P_ROLE_CLIENT )
5853 pwdinfo->p2p_info.operation_ch[ 0 ] = pwdinfo->peer_operating_ch;
5854 #ifdef CONFIG_P2P_OP_CHK_SOCIAL_CH
5855 pwdinfo->p2p_info.operation_ch[ 1 ] = 1; //Check whether GO is operating in channel 1;
5856 pwdinfo->p2p_info.operation_ch[ 2 ] = 6; //Check whether GO is operating in channel 6;
5857 pwdinfo->p2p_info.operation_ch[ 3 ] = 11; //Check whether GO is operating in channel 11;
5858 #endif //CONFIG_P2P_OP_CHK_SOCIAL_CH
5859 pwdinfo->p2p_info.scan_op_ch_only = 1;
5860 _set_timer( &pwdinfo->reset_ch_sitesurvey2, P2P_RESET_SCAN_CH );
5864 // Reset the dialog token for group negotiation frames.
5865 pwdinfo->negotiation_dialog_token = 1;
5867 if(rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_FAIL))
5869 _set_timer( &pwdinfo->restore_p2p_state_timer, 5000 );
5874 DBG_871X( "[%s] Skipped GO Nego Resp Frame (p2p_state != P2P_STATE_GONEGO_ING)\n", __FUNCTION__);
5879 case P2P_GO_NEGO_CONF:
5881 DBG_871X( "[%s] Got GO Nego Confirm Frame\n", __FUNCTION__);
5882 result = process_p2p_group_negotation_confirm( pwdinfo, frame_body, len);
5883 if ( P2P_STATUS_SUCCESS == result )
5885 if ( rtw_p2p_role(pwdinfo) == P2P_ROLE_CLIENT )
5887 pwdinfo->p2p_info.operation_ch[ 0 ] = pwdinfo->peer_operating_ch;
5888 #ifdef CONFIG_P2P_OP_CHK_SOCIAL_CH
5889 pwdinfo->p2p_info.operation_ch[ 1 ] = 1; //Check whether GO is operating in channel 1;
5890 pwdinfo->p2p_info.operation_ch[ 2 ] = 6; //Check whether GO is operating in channel 6;
5891 pwdinfo->p2p_info.operation_ch[ 3 ] = 11; //Check whether GO is operating in channel 11;
5892 #endif //CONFIG_P2P_OP_CHK_SOCIAL_CH
5893 pwdinfo->p2p_info.scan_op_ch_only = 1;
5894 _set_timer( &pwdinfo->reset_ch_sitesurvey2, P2P_RESET_SCAN_CH );
5901 // Added by Albert 2010/10/05
5902 // Received the P2P Invite Request frame.
5904 DBG_871X( "[%s] Got invite request frame!\n", __FUNCTION__ );
5905 if ( (p2p_ie=rtw_get_p2p_ie( frame_body + _PUBLIC_ACTION_IE_OFFSET_, len - _PUBLIC_ACTION_IE_OFFSET_, NULL, &p2p_ielen)) )
5907 // Parse the necessary information from the P2P Invitation Request frame.
5908 // For example: The MAC address of sending this P2P Invitation Request frame.
5909 u32 attr_contentlen = 0;
5910 u8 status_code = P2P_STATUS_FAIL_INFO_UNAVAILABLE;
5911 struct group_id_info group_id;
5912 u8 invitation_flag = 0;
5915 merged_p2p_ielen = rtw_get_p2p_merged_ies_len(frame_body + _PUBLIC_ACTION_IE_OFFSET_, len - _PUBLIC_ACTION_IE_OFFSET_);
5917 merged_p2pie = rtw_zmalloc(merged_p2p_ielen + 2); // 2 is for EID and Length
5918 if (merged_p2pie == NULL)
5920 DBG_871X( "[%s] Malloc p2p ie fail\n", __FUNCTION__);
5923 _rtw_memset(merged_p2pie, 0x00, merged_p2p_ielen);
5925 merged_p2p_ielen = rtw_p2p_merge_ies(frame_body + _PUBLIC_ACTION_IE_OFFSET_, len - _PUBLIC_ACTION_IE_OFFSET_, merged_p2pie);
5927 rtw_get_p2p_attr_content( merged_p2pie, merged_p2p_ielen, P2P_ATTR_INVITATION_FLAGS, &invitation_flag, &attr_contentlen);
5928 if ( attr_contentlen )
5931 rtw_get_p2p_attr_content( merged_p2pie, merged_p2p_ielen, P2P_ATTR_GROUP_BSSID, pwdinfo->p2p_peer_interface_addr, &attr_contentlen);
5932 // Commented by Albert 20120510
5933 // Copy to the pwdinfo->p2p_peer_interface_addr.
5934 // So that the WFD UI ( or Sigma ) can get the peer interface address by using the following command.
5935 // #> iwpriv wlan0 p2p_get peer_ifa
5936 // After having the peer interface address, the sigma can find the correct conf file for wpa_supplicant.
5938 if ( attr_contentlen )
5940 DBG_871X( "[%s] GO's BSSID = %.2X %.2X %.2X %.2X %.2X %.2X\n", __FUNCTION__,
5941 pwdinfo->p2p_peer_interface_addr[0], pwdinfo->p2p_peer_interface_addr[1],
5942 pwdinfo->p2p_peer_interface_addr[2], pwdinfo->p2p_peer_interface_addr[3],
5943 pwdinfo->p2p_peer_interface_addr[4], pwdinfo->p2p_peer_interface_addr[5] );
5946 if ( invitation_flag & P2P_INVITATION_FLAGS_PERSISTENT )
5948 // Re-invoke the persistent group.
5950 _rtw_memset( &group_id, 0x00, sizeof( struct group_id_info ) );
5951 rtw_get_p2p_attr_content( merged_p2pie, merged_p2p_ielen, P2P_ATTR_GROUP_ID, ( u8* ) &group_id, &attr_contentlen);
5952 if ( attr_contentlen )
5954 if ( _rtw_memcmp( group_id.go_device_addr, myid( &padapter->eeprompriv ), ETH_ALEN ) )
5956 // The p2p device sending this p2p invitation request wants this Wi-Fi device to be the persistent GO.
5957 rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_GO );
5958 rtw_p2p_set_role( pwdinfo, P2P_ROLE_GO );
5959 status_code = P2P_STATUS_SUCCESS;
5963 // The p2p device sending this p2p invitation request wants to be the persistent GO.
5964 if ( is_matched_in_profilelist( pwdinfo->p2p_peer_interface_addr, &pwdinfo->profileinfo[ 0 ] ) )
5966 u8 operatingch_info[5] = { 0x00 };
5967 if ( rtw_get_p2p_attr_content(merged_p2pie, merged_p2p_ielen, P2P_ATTR_OPERATING_CH, operatingch_info, &attr_contentlen) )
5969 if( rtw_ch_set_search_ch(padapter->mlmeextpriv.channel_set, (u32)operatingch_info[4] ) >= 0 )
5971 // The operating channel is acceptable for this device.
5972 pwdinfo->rx_invitereq_info.operation_ch[0]= operatingch_info[4];
5973 #ifdef CONFIG_P2P_OP_CHK_SOCIAL_CH
5974 pwdinfo->rx_invitereq_info.operation_ch[1]= 1; //Check whether GO is operating in channel 1;
5975 pwdinfo->rx_invitereq_info.operation_ch[2]= 6; //Check whether GO is operating in channel 6;
5976 pwdinfo->rx_invitereq_info.operation_ch[3]= 11; //Check whether GO is operating in channel 11;
5977 #endif //CONFIG_P2P_OP_CHK_SOCIAL_CH
5978 pwdinfo->rx_invitereq_info.scan_op_ch_only = 1;
5979 _set_timer( &pwdinfo->reset_ch_sitesurvey, P2P_RESET_SCAN_CH );
5980 rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_MATCH );
5981 rtw_p2p_set_role( pwdinfo, P2P_ROLE_CLIENT );
5982 status_code = P2P_STATUS_SUCCESS;
5986 // The operating channel isn't supported by this device.
5987 rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_DISMATCH );
5988 rtw_p2p_set_role( pwdinfo, P2P_ROLE_DEVICE );
5989 status_code = P2P_STATUS_FAIL_NO_COMMON_CH;
5990 _set_timer( &pwdinfo->restore_p2p_state_timer, 3000 );
5995 // Commented by Albert 20121130
5996 // Intel will use the different P2P IE to store the operating channel information
5997 // Workaround for Intel WiDi 3.5
5998 rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_MATCH );
5999 rtw_p2p_set_role( pwdinfo, P2P_ROLE_CLIENT );
6000 status_code = P2P_STATUS_SUCCESS;
6005 rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_DISMATCH );
6006 #ifdef CONFIG_INTEL_WIDI
6007 _rtw_memcpy( pwdinfo->p2p_peer_device_addr, group_id.go_device_addr , ETH_ALEN );
6008 rtw_p2p_set_role( pwdinfo, P2P_ROLE_CLIENT );
6009 #endif //CONFIG_INTEL_WIDI
6011 status_code = P2P_STATUS_FAIL_UNKNOWN_P2PGROUP;
6017 DBG_871X( "[%s] P2P Group ID Attribute NOT FOUND!\n", __FUNCTION__ );
6018 status_code = P2P_STATUS_FAIL_INFO_UNAVAILABLE;
6023 // Received the invitation to join a P2P group.
6025 _rtw_memset( &group_id, 0x00, sizeof( struct group_id_info ) );
6026 rtw_get_p2p_attr_content( merged_p2pie, merged_p2p_ielen, P2P_ATTR_GROUP_ID, ( u8* ) &group_id, &attr_contentlen);
6027 if ( attr_contentlen )
6029 if ( _rtw_memcmp( group_id.go_device_addr, myid( &padapter->eeprompriv ), ETH_ALEN ) )
6031 // In this case, the GO can't be myself.
6032 rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_DISMATCH );
6033 status_code = P2P_STATUS_FAIL_INFO_UNAVAILABLE;
6037 // The p2p device sending this p2p invitation request wants to join an existing P2P group
6038 // Commented by Albert 2012/06/28
6039 // In this case, this Wi-Fi device should use the iwpriv command to get the peer device address.
6040 // The peer device address should be the destination address for the provisioning discovery request.
6041 // Then, this Wi-Fi device should use the iwpriv command to get the peer interface address.
6042 // The peer interface address should be the address for WPS mac address
6043 _rtw_memcpy( pwdinfo->p2p_peer_device_addr, group_id.go_device_addr , ETH_ALEN );
6044 rtw_p2p_set_role( pwdinfo, P2P_ROLE_CLIENT );
6045 rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_JOIN );
6046 status_code = P2P_STATUS_SUCCESS;
6051 DBG_871X( "[%s] P2P Group ID Attribute NOT FOUND!\n", __FUNCTION__ );
6052 status_code = P2P_STATUS_FAIL_INFO_UNAVAILABLE;
6058 DBG_871X( "[%s] P2P Invitation Flags Attribute NOT FOUND!\n", __FUNCTION__ );
6059 status_code = P2P_STATUS_FAIL_INFO_UNAVAILABLE;
6062 DBG_871X( "[%s] status_code = %d\n", __FUNCTION__, status_code );
6064 pwdinfo->inviteresp_info.token = frame_body[ 7 ];
6065 issue_p2p_invitation_response( padapter, GetAddr2Ptr(pframe), pwdinfo->inviteresp_info.token, status_code );
6066 _set_timer( &pwdinfo->restore_p2p_state_timer, 3000 );
6068 #ifdef CONFIG_INTEL_WIDI
6069 if( (padapter->mlmepriv.widi_state == INTEL_WIDI_STATE_LISTEN) && (padapter->mlmepriv.widi_state != INTEL_WIDI_STATE_WFD_CONNECTION) )
6071 padapter->mlmepriv.widi_state = INTEL_WIDI_STATE_WFD_CONNECTION;
6072 _cancel_timer_ex(&(padapter->mlmepriv.listen_timer));
6073 intel_widi_wk_cmd(padapter, INTEL_WIDI_LISTEN_STOP_WK, NULL, 0);
6075 #endif //CONFIG_INTEL_WIDI
6078 case P2P_INVIT_RESP:
6080 u8 attr_content = 0x00;
6081 u32 attr_contentlen = 0;
6083 DBG_871X( "[%s] Got invite response frame!\n", __FUNCTION__ );
6084 _cancel_timer_ex( &pwdinfo->restore_p2p_state_timer );
6085 if ( (p2p_ie=rtw_get_p2p_ie( frame_body + _PUBLIC_ACTION_IE_OFFSET_, len - _PUBLIC_ACTION_IE_OFFSET_, NULL, &p2p_ielen)) )
6087 rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_STATUS, &attr_content, &attr_contentlen);
6089 if ( attr_contentlen == 1 )
6091 DBG_871X( "[%s] Status = %d\n", __FUNCTION__, attr_content );
6092 pwdinfo->invitereq_info.benable = _FALSE;
6094 if ( attr_content == P2P_STATUS_SUCCESS )
6096 if ( _rtw_memcmp( pwdinfo->invitereq_info.go_bssid, myid( &padapter->eeprompriv ), ETH_ALEN ))
6098 rtw_p2p_set_role(pwdinfo, P2P_ROLE_GO );
6102 rtw_p2p_set_role(pwdinfo, P2P_ROLE_CLIENT);
6104 rtw_p2p_set_state( pwdinfo, P2P_STATE_RX_INVITE_RESP_OK );
6108 rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
6109 rtw_p2p_set_state( pwdinfo, P2P_STATE_RX_INVITE_RESP_FAIL );
6114 rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
6115 rtw_p2p_set_state( pwdinfo, P2P_STATE_RX_INVITE_RESP_FAIL );
6120 rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
6121 rtw_p2p_set_state( pwdinfo, P2P_STATE_RX_INVITE_RESP_FAIL );
6124 if ( rtw_p2p_chk_state( pwdinfo, P2P_STATE_RX_INVITE_RESP_FAIL ) )
6126 _set_timer( &pwdinfo->restore_p2p_state_timer, 5000 );
6130 case P2P_DEVDISC_REQ:
6132 process_p2p_devdisc_req(pwdinfo, pframe, len);
6136 case P2P_DEVDISC_RESP:
6138 process_p2p_devdisc_resp(pwdinfo, pframe, len);
6142 case P2P_PROVISION_DISC_REQ:
6143 DBG_871X( "[%s] Got Provisioning Discovery Request Frame\n", __FUNCTION__ );
6144 process_p2p_provdisc_req(pwdinfo, pframe, len);
6145 _rtw_memcpy(pwdinfo->rx_prov_disc_info.peerDevAddr, GetAddr2Ptr(pframe), ETH_ALEN);
6148 //Add the following statement to avoid receiving duplicate prov disc req. such that pre_p2p_state would be covered.
6149 if(!rtw_p2p_chk_state(pwdinfo, P2P_STATE_RX_PROVISION_DIS_REQ))
6150 rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
6152 rtw_p2p_set_state(pwdinfo, P2P_STATE_RX_PROVISION_DIS_REQ);
6153 _set_timer( &pwdinfo->restore_p2p_state_timer, P2P_PROVISION_TIMEOUT );
6154 #ifdef CONFIG_INTEL_WIDI
6155 if( (padapter->mlmepriv.widi_state == INTEL_WIDI_STATE_LISTEN) && (padapter->mlmepriv.widi_state != INTEL_WIDI_STATE_WFD_CONNECTION) )
6157 padapter->mlmepriv.widi_state = INTEL_WIDI_STATE_WFD_CONNECTION;
6158 _cancel_timer_ex(&(padapter->mlmepriv.listen_timer));
6159 intel_widi_wk_cmd(padapter, INTEL_WIDI_LISTEN_STOP_WK, NULL, 0);
6161 #endif //CONFIG_INTEL_WIDI
6164 case P2P_PROVISION_DISC_RESP:
6165 // Commented by Albert 20110707
6166 // Should we check the pwdinfo->tx_prov_disc_info.bsent flag here??
6167 DBG_871X( "[%s] Got Provisioning Discovery Response Frame\n", __FUNCTION__ );
6168 // Commented by Albert 20110426
6169 // The restore timer is enabled when issuing the provisioing request frame in rtw_p2p_prov_disc function.
6170 _cancel_timer_ex( &pwdinfo->restore_p2p_state_timer );
6171 rtw_p2p_set_state(pwdinfo, P2P_STATE_RX_PROVISION_DIS_RSP);
6172 process_p2p_provdisc_resp(pwdinfo, pframe);
6173 _set_timer( &pwdinfo->restore_p2p_state_timer, P2P_PROVISION_TIMEOUT );
6184 rtw_mfree(merged_p2pie, merged_p2p_ielen + 2);
6190 unsigned int on_action_public_vendor(union recv_frame *precv_frame)
6192 unsigned int ret = _FAIL;
6193 u8 *pframe = precv_frame->u.hdr.rx_data;
6194 uint frame_len = precv_frame->u.hdr.len;
6195 u8 *frame_body = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
6197 if (_rtw_memcmp(frame_body + 2, P2P_OUI, 4) == _TRUE) {
6198 ret = on_action_public_p2p(precv_frame);
6204 unsigned int on_action_public_default(union recv_frame *precv_frame, u8 action)
6206 unsigned int ret = _FAIL;
6207 u8 *pframe = precv_frame->u.hdr.rx_data;
6208 uint frame_len = precv_frame->u.hdr.len;
6209 u8 *frame_body = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
6211 _adapter *adapter = precv_frame->u.hdr.adapter;
6215 token = frame_body[2];
6217 if (rtw_action_public_decache(precv_frame, token) == _FAIL)
6220 #ifdef CONFIG_IOCTL_CFG80211
6221 cnt += sprintf((msg+cnt), "%s(token:%u)", action_public_str(action), token);
6222 rtw_cfg80211_rx_action(adapter, pframe, frame_len, msg);
6231 unsigned int on_action_public(_adapter *padapter, union recv_frame *precv_frame)
6233 unsigned int ret = _FAIL;
6234 u8 *pframe = precv_frame->u.hdr.rx_data;
6235 uint frame_len = precv_frame->u.hdr.len;
6236 u8 *frame_body = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
6237 u8 category, action;
6239 /* check RA matches or not */
6240 if (!_rtw_memcmp(myid(&(padapter->eeprompriv)), GetAddr1Ptr(pframe), ETH_ALEN))
6243 category = frame_body[0];
6244 if(category != RTW_WLAN_CATEGORY_PUBLIC)
6247 action = frame_body[1];
6249 case ACT_PUBLIC_VENDOR:
6250 ret = on_action_public_vendor(precv_frame);
6253 ret = on_action_public_default(precv_frame, action);
6261 unsigned int OnAction_ht(_adapter *padapter, union recv_frame *precv_frame)
6263 u8 *pframe = precv_frame->u.hdr.rx_data;
6264 uint frame_len = precv_frame->u.hdr.len;
6265 u8 *frame_body = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
6266 u8 category, action;
6268 /* check RA matches or not */
6269 if (!_rtw_memcmp(myid(&(padapter->eeprompriv)), GetAddr1Ptr(pframe), ETH_ALEN))
6272 category = frame_body[0];
6273 if(category != RTW_WLAN_CATEGORY_HT)
6276 action = frame_body[1];
6278 case RTW_WLAN_ACTION_HT_COMPRESS_BEAMFORMING:
6279 #ifdef CONFIG_BEAMFORMING
6280 //DBG_871X("RTW_WLAN_ACTION_HT_COMPRESS_BEAMFORMING\n");
6281 beamforming_get_report_frame(padapter, precv_frame);
6282 #endif //CONFIG_BEAMFORMING
6293 #ifdef CONFIG_IEEE80211W
6294 unsigned int OnAction_sa_query(_adapter *padapter, union recv_frame *precv_frame)
6296 u8 *pframe = precv_frame->u.hdr.rx_data;
6297 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
6298 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
6302 DBG_871X("OnAction_sa_query\n");
6304 switch (pframe[WLAN_HDR_A3_LEN+1])
6306 case 0: //SA Query req
6307 _rtw_memcpy(&tid, &pframe[WLAN_HDR_A3_LEN+2], sizeof(unsigned short));
6308 DBG_871X("OnAction_sa_query request,action=%d, tid=%04x\n", pframe[WLAN_HDR_A3_LEN+1], tid);
6309 issue_action_SA_Query(padapter, GetAddr2Ptr(pframe), 1, tid);
6312 case 1: //SA Query rsp
6313 _cancel_timer_ex(&pmlmeext->sa_query_timer);
6314 DBG_871X("OnAction_sa_query response,action=%d, tid=%04x, cancel timer\n", pframe[WLAN_HDR_A3_LEN+1], pframe[WLAN_HDR_A3_LEN+2]);
6322 printk("pattrib->pktlen = %d =>", pattrib->pkt_len);
6323 for(pp=0;pp< pattrib->pkt_len; pp++)
6324 printk(" %02x ", pframe[pp]);
6330 #endif //CONFIG_IEEE80211W
6332 unsigned int OnAction_wmm(_adapter *padapter, union recv_frame *precv_frame)
6337 unsigned int OnAction_vht(_adapter *padapter, union recv_frame *precv_frame)
6339 #ifdef CONFIG_80211AC_VHT
6340 struct rx_pkt_attrib *prxattrib = &precv_frame->u.hdr.attrib;
6341 u8 *pframe = precv_frame->u.hdr.rx_data;
6342 uint frame_len = precv_frame->u.hdr.len;
6343 u8 *frame_body = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
6344 u8 category, action;
6345 struct sta_info *psta = NULL;
6347 /* check RA matches or not */
6348 if (!_rtw_memcmp(myid(&(padapter->eeprompriv)), GetAddr1Ptr(pframe), ETH_ALEN))
6351 category = frame_body[0];
6352 if(category != RTW_WLAN_CATEGORY_VHT)
6355 action = frame_body[1];
6357 case RTW_WLAN_ACTION_VHT_COMPRESSED_BEAMFORMING:
6358 #ifdef CONFIG_BEAMFORMING
6359 //DBG_871X("RTW_WLAN_ACTION_VHT_COMPRESSED_BEAMFORMING\n");
6360 beamforming_get_report_frame(padapter, precv_frame);
6361 #endif //CONFIG_BEAMFORMING
6363 case RTW_WLAN_ACTION_VHT_OPMODE_NOTIFICATION:
6364 // CategoryCode(1) + ActionCode(1) + OpModeNotification(1)
6365 //DBG_871X("RTW_WLAN_ACTION_VHT_OPMODE_NOTIFICATION\n");
6366 psta = rtw_get_stainfo(&padapter->stapriv, prxattrib->ta);
6368 rtw_process_vht_op_mode_notify(padapter, &frame_body[2], psta);
6375 #endif //CONFIG_80211AC_VHT
6380 unsigned int OnAction_p2p(_adapter *padapter, union recv_frame *precv_frame)
6384 u8 category, OUI_Subtype, dialogToken=0;
6385 u8 *pframe = precv_frame->u.hdr.rx_data;
6386 uint len = precv_frame->u.hdr.len;
6387 struct wifidirect_info *pwdinfo = &( padapter->wdinfo );
6389 //check RA matches or not
6390 if (!_rtw_memcmp(myid(&(padapter->eeprompriv)), GetAddr1Ptr(pframe), ETH_ALEN))//for if1, sta/ap mode
6393 frame_body = (unsigned char *)(pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
6395 category = frame_body[0];
6396 if(category != RTW_WLAN_CATEGORY_P2P)
6399 if ( cpu_to_be32( *( ( u32* ) ( frame_body + 1 ) ) ) != P2POUI )
6402 #ifdef CONFIG_IOCTL_CFG80211
6403 if(adapter_wdev_data(padapter)->p2p_enabled && pwdinfo->driver_interface == DRIVER_CFG80211 )
6405 rtw_cfg80211_rx_action_p2p(padapter, pframe, len);
6409 #endif //CONFIG_IOCTL_CFG80211
6411 len -= sizeof(struct rtw_ieee80211_hdr_3addr);
6412 OUI_Subtype = frame_body[5];
6413 dialogToken = frame_body[6];
6417 case P2P_NOTICE_OF_ABSENCE:
6421 case P2P_PRESENCE_REQUEST:
6423 process_p2p_presence_req(pwdinfo, pframe, len);
6427 case P2P_PRESENCE_RESPONSE:
6431 case P2P_GO_DISC_REQUEST:
6446 unsigned int OnAction(_adapter *padapter, union recv_frame *precv_frame)
6449 unsigned char category;
6450 struct action_handler *ptable;
6451 unsigned char *frame_body;
6452 u8 *pframe = precv_frame->u.hdr.rx_data;
6454 frame_body = (unsigned char *)(pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
6456 category = frame_body[0];
6458 for(i = 0; i < sizeof(OnAction_tbl)/sizeof(struct action_handler); i++)
6460 ptable = &OnAction_tbl[i];
6462 if(category == ptable->num)
6463 ptable->func(padapter, precv_frame);
6471 unsigned int DoReserved(_adapter *padapter, union recv_frame *precv_frame)
6474 //DBG_871X("rcvd mgt frame(%x, %x)\n", (GetFrameSubType(pframe) >> 4), *(unsigned int *)GetAddr1Ptr(pframe));
6478 struct xmit_frame *_alloc_mgtxmitframe(struct xmit_priv *pxmitpriv, bool once)
6480 struct xmit_frame *pmgntframe;
6481 struct xmit_buf *pxmitbuf;
6484 pmgntframe = rtw_alloc_xmitframe_once(pxmitpriv);
6486 pmgntframe = rtw_alloc_xmitframe_ext(pxmitpriv);
6488 if (pmgntframe == NULL) {
6489 DBG_871X(FUNC_ADPT_FMT" alloc xmitframe fail, once:%d\n", FUNC_ADPT_ARG(pxmitpriv->adapter), once);
6493 if ((pxmitbuf = rtw_alloc_xmitbuf_ext(pxmitpriv)) == NULL) {
6494 DBG_871X(FUNC_ADPT_FMT" alloc xmitbuf fail\n", FUNC_ADPT_ARG(pxmitpriv->adapter));
6495 rtw_free_xmitframe(pxmitpriv, pmgntframe);
6500 pmgntframe->frame_tag = MGNT_FRAMETAG;
6501 pmgntframe->pxmitbuf = pxmitbuf;
6502 pmgntframe->buf_addr = pxmitbuf->pbuf;
6503 pxmitbuf->priv_data = pmgntframe;
6510 inline struct xmit_frame *alloc_mgtxmitframe(struct xmit_priv *pxmitpriv)
6512 return _alloc_mgtxmitframe(pxmitpriv, _FALSE);
6515 inline struct xmit_frame *alloc_mgtxmitframe_once(struct xmit_priv *pxmitpriv)
6517 return _alloc_mgtxmitframe(pxmitpriv, _TRUE);
6521 /****************************************************************************
6523 Following are some TX fuctions for WiFi MLME
6525 *****************************************************************************/
6527 void update_mgnt_tx_rate(_adapter *padapter, u8 rate)
6529 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
6531 pmlmeext->tx_rate = rate;
6532 //DBG_871X("%s(): rate = %x\n",__FUNCTION__, rate);
6535 void update_mgntframe_attrib(_adapter *padapter, struct pkt_attrib *pattrib)
6538 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
6540 //_rtw_memset((u8 *)(pattrib), 0, sizeof(struct pkt_attrib));
6542 pattrib->hdrlen = 24;
6543 pattrib->nr_frags = 1;
6544 pattrib->priority = 7;
6545 pattrib->mac_id = 0;
6546 pattrib->qsel = 0x12;
6548 pattrib->pktlen = 0;
6550 if (pmlmeext->tx_rate == IEEE80211_CCK_RATE_1MB)
6551 wireless_mode = WIRELESS_11B;
6553 wireless_mode = WIRELESS_11G;
6554 pattrib->raid = rtw_get_mgntframe_raid(padapter, wireless_mode);
6555 pattrib->rate = pmlmeext->tx_rate;
6557 pattrib->encrypt = _NO_PRIVACY_;
6558 pattrib->bswenc = _FALSE;
6560 pattrib->qos_en = _FALSE;
6561 pattrib->ht_en = _FALSE;
6562 pattrib->bwmode = CHANNEL_WIDTH_20;
6563 pattrib->ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
6564 pattrib->sgi = _FALSE;
6566 pattrib->seqnum = pmlmeext->mgnt_seq;
6568 pattrib->retry_ctrl = _TRUE;
6570 pattrib->mbssid = 0;
6574 void update_mgntframe_attrib_addr(_adapter *padapter, struct xmit_frame *pmgntframe)
6577 struct pkt_attrib *pattrib = &pmgntframe->attrib;
6579 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
6581 _rtw_memcpy(pattrib->ra, GetAddr1Ptr(pframe), ETH_ALEN);
6582 _rtw_memcpy(pattrib->ta, GetAddr2Ptr(pframe), ETH_ALEN);
6585 void dump_mgntframe(_adapter *padapter, struct xmit_frame *pmgntframe)
6587 if(padapter->bSurpriseRemoved == _TRUE ||
6588 padapter->bDriverStopped == _TRUE)
6590 rtw_free_xmitbuf(&padapter->xmitpriv, pmgntframe->pxmitbuf);
6591 rtw_free_xmitframe(&padapter->xmitpriv, pmgntframe);
6595 rtw_hal_mgnt_xmit(padapter, pmgntframe);
6598 s32 dump_mgntframe_and_wait(_adapter *padapter, struct xmit_frame *pmgntframe, int timeout_ms)
6602 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
6603 struct xmit_buf *pxmitbuf = pmgntframe->pxmitbuf;
6604 struct submit_ctx sctx;
6606 if(padapter->bSurpriseRemoved == _TRUE ||
6607 padapter->bDriverStopped == _TRUE)
6609 rtw_free_xmitbuf(&padapter->xmitpriv, pmgntframe->pxmitbuf);
6610 rtw_free_xmitframe(&padapter->xmitpriv, pmgntframe);
6614 rtw_sctx_init(&sctx, timeout_ms);
6615 pxmitbuf->sctx = &sctx;
6617 ret = rtw_hal_mgnt_xmit(padapter, pmgntframe);
6619 if (ret == _SUCCESS)
6620 ret = rtw_sctx_wait(&sctx, __func__);
6622 _enter_critical(&pxmitpriv->lock_sctx, &irqL);
6623 pxmitbuf->sctx = NULL;
6624 _exit_critical(&pxmitpriv->lock_sctx, &irqL);
6629 s32 dump_mgntframe_and_wait_ack(_adapter *padapter, struct xmit_frame *pmgntframe)
6631 #ifdef CONFIG_XMIT_ACK
6632 static u8 seq_no = 0;
6634 u32 timeout_ms = 500;// 500ms
6635 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
6636 #ifdef CONFIG_CONCURRENT_MODE
6637 if (padapter->pbuddy_adapter && !padapter->isprimary)
6638 pxmitpriv = &(padapter->pbuddy_adapter->xmitpriv);
6641 if(padapter->bSurpriseRemoved == _TRUE ||
6642 padapter->bDriverStopped == _TRUE)
6644 rtw_free_xmitbuf(&padapter->xmitpriv, pmgntframe->pxmitbuf);
6645 rtw_free_xmitframe(&padapter->xmitpriv, pmgntframe);
6649 _enter_critical_mutex(&pxmitpriv->ack_tx_mutex, NULL);
6650 pxmitpriv->ack_tx = _TRUE;
6651 pxmitpriv->seq_no = seq_no++;
6652 pmgntframe->ack_report = 1;
6653 if (rtw_hal_mgnt_xmit(padapter, pmgntframe) == _SUCCESS) {
6654 ret = rtw_ack_tx_wait(pxmitpriv, timeout_ms);
6657 pxmitpriv->ack_tx = _FALSE;
6658 _exit_critical_mutex(&pxmitpriv->ack_tx_mutex, NULL);
6661 #else //!CONFIG_XMIT_ACK
6662 dump_mgntframe(padapter, pmgntframe);
6665 #endif //!CONFIG_XMIT_ACK
6668 int update_hidden_ssid(u8 *ies, u32 ies_len, u8 hidden_ssid_mode)
6674 ssid_ie = rtw_get_ie(ies, WLAN_EID_SSID, &ssid_len_ori, ies_len);
6676 //DBG_871X("%s hidden_ssid_mode:%u, ssid_ie:%p, ssid_len_ori:%d\n", __FUNCTION__, hidden_ssid_mode, ssid_ie, ssid_len_ori);
6678 if(ssid_ie && ssid_len_ori>0)
6680 switch(hidden_ssid_mode)
6684 u8 *next_ie = ssid_ie + 2 + ssid_len_ori;
6687 remain_len = ies_len -(next_ie-ies);
6690 _rtw_memcpy(ssid_ie+2, next_ie, remain_len);
6691 len_diff -= ssid_len_ori;
6696 _rtw_memset(&ssid_ie[2], 0, ssid_len_ori);
6706 void issue_beacon(_adapter *padapter, int timeout_ms)
6708 struct xmit_frame *pmgntframe;
6709 struct pkt_attrib *pattrib;
6710 unsigned char *pframe;
6711 struct rtw_ieee80211_hdr *pwlanhdr;
6712 unsigned short *fctrl;
6713 unsigned int rate_len;
6714 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
6715 #if defined (CONFIG_AP_MODE) && defined (CONFIG_NATIVEAP_MLME)
6717 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
6718 #endif //#if defined (CONFIG_AP_MODE) && defined (CONFIG_NATIVEAP_MLME)
6719 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
6720 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
6721 WLAN_BSSID_EX *cur_network = &(pmlmeinfo->network);
6722 u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
6724 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
6728 //DBG_871X("%s\n", __FUNCTION__);
6730 if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
6732 DBG_871X("%s, alloc mgnt frame fail\n", __FUNCTION__);
6735 #if defined (CONFIG_AP_MODE) && defined (CONFIG_NATIVEAP_MLME)
6736 _enter_critical_bh(&pmlmepriv->bcn_update_lock, &irqL);
6737 #endif //#if defined (CONFIG_AP_MODE) && defined (CONFIG_NATIVEAP_MLME)
6740 pattrib = &pmgntframe->attrib;
6741 update_mgntframe_attrib(padapter, pattrib);
6742 pattrib->qsel = 0x10;
6743 #ifdef CONFIG_CONCURRENT_MODE
6744 if(padapter->iface_type == IFACE_PORT1)
6745 pattrib->mbssid = 1;
6748 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
6750 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
6751 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
6754 fctrl = &(pwlanhdr->frame_ctl);
6757 _rtw_memcpy(pwlanhdr->addr1, bc_addr, ETH_ALEN);
6758 _rtw_memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
6759 _rtw_memcpy(pwlanhdr->addr3, get_my_bssid(cur_network), ETH_ALEN);
6761 SetSeqNum(pwlanhdr, 0/*pmlmeext->mgnt_seq*/);
6762 //pmlmeext->mgnt_seq++;
6763 SetFrameSubType(pframe, WIFI_BEACON);
6765 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
6766 pattrib->pktlen = sizeof (struct rtw_ieee80211_hdr_3addr);
6768 if( (pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE)
6770 //DBG_871X("ie len=%d\n", cur_network->IELength);
6772 // for P2P : Primary Device Type & Device Name
6773 u32 wpsielen=0, insert_len=0;
6775 wpsie = rtw_get_wps_ie(cur_network->IEs+_FIXED_IE_LENGTH_, cur_network->IELength-_FIXED_IE_LENGTH_, NULL, &wpsielen);
6777 if(rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO) && wpsie && wpsielen>0)
6779 uint wps_offset, remainder_ielen;
6780 u8 *premainder_ie, *pframe_wscie;
6782 wps_offset = (uint)(wpsie - cur_network->IEs);
6784 premainder_ie = wpsie + wpsielen;
6786 remainder_ielen = cur_network->IELength - wps_offset - wpsielen;
6788 #ifdef CONFIG_IOCTL_CFG80211
6789 if(adapter_wdev_data(padapter)->p2p_enabled && pwdinfo->driver_interface == DRIVER_CFG80211 )
6791 if(pmlmepriv->wps_beacon_ie && pmlmepriv->wps_beacon_ie_len>0)
6793 _rtw_memcpy(pframe, cur_network->IEs, wps_offset);
6794 pframe += wps_offset;
6795 pattrib->pktlen += wps_offset;
6797 _rtw_memcpy(pframe, pmlmepriv->wps_beacon_ie, pmlmepriv->wps_beacon_ie_len);
6798 pframe += pmlmepriv->wps_beacon_ie_len;
6799 pattrib->pktlen += pmlmepriv->wps_beacon_ie_len;
6801 //copy remainder_ie to pframe
6802 _rtw_memcpy(pframe, premainder_ie, remainder_ielen);
6803 pframe += remainder_ielen;
6804 pattrib->pktlen += remainder_ielen;
6808 _rtw_memcpy(pframe, cur_network->IEs, cur_network->IELength);
6809 pframe += cur_network->IELength;
6810 pattrib->pktlen += cur_network->IELength;
6814 #endif //CONFIG_IOCTL_CFG80211
6816 pframe_wscie = pframe + wps_offset;
6817 _rtw_memcpy(pframe, cur_network->IEs, wps_offset+wpsielen);
6818 pframe += (wps_offset + wpsielen);
6819 pattrib->pktlen += (wps_offset + wpsielen);
6821 //now pframe is end of wsc ie, insert Primary Device Type & Device Name
6822 // Primary Device Type
6824 *(u16*) ( pframe + insert_len) = cpu_to_be16( WPS_ATTR_PRIMARY_DEV_TYPE );
6828 *(u16*) ( pframe + insert_len ) = cpu_to_be16( 0x0008 );
6833 *(u16*) ( pframe + insert_len ) = cpu_to_be16( WPS_PDT_CID_MULIT_MEDIA );
6837 *(u32*) ( pframe + insert_len ) = cpu_to_be32( WPSOUI );
6841 *(u16*) ( pframe + insert_len ) = cpu_to_be16( WPS_PDT_SCID_MEDIA_SERVER );
6847 *(u16*) ( pframe + insert_len ) = cpu_to_be16( WPS_ATTR_DEVICE_NAME );
6851 *(u16*) ( pframe + insert_len ) = cpu_to_be16( pwdinfo->device_name_len );
6855 _rtw_memcpy( pframe + insert_len, pwdinfo->device_name, pwdinfo->device_name_len );
6856 insert_len += pwdinfo->device_name_len;
6859 //update wsc ie length
6860 *(pframe_wscie+1) = (wpsielen -2) + insert_len;
6862 //pframe move to end
6864 pattrib->pktlen += insert_len;
6866 //copy remainder_ie to pframe
6867 _rtw_memcpy(pframe, premainder_ie, remainder_ielen);
6868 pframe += remainder_ielen;
6869 pattrib->pktlen += remainder_ielen;
6876 _rtw_memcpy(pframe, cur_network->IEs, cur_network->IELength);
6877 len_diff = update_hidden_ssid(
6878 pframe+_BEACON_IE_OFFSET_
6879 , cur_network->IELength-_BEACON_IE_OFFSET_
6880 , pmlmeinfo->hidden_ssid_mode
6882 pframe += (cur_network->IELength+len_diff);
6883 pattrib->pktlen += (cur_network->IELength+len_diff);
6890 wps_ie = rtw_get_wps_ie(pmgntframe->buf_addr+TXDESC_OFFSET+sizeof (struct rtw_ieee80211_hdr_3addr)+_BEACON_IE_OFFSET_,
6891 pattrib->pktlen-sizeof (struct rtw_ieee80211_hdr_3addr)-_BEACON_IE_OFFSET_, NULL, &wps_ielen);
6892 if (wps_ie && wps_ielen>0) {
6893 rtw_get_wps_attr_content(wps_ie, wps_ielen, WPS_ATTR_SELECTED_REGISTRAR, (u8*)(&sr), NULL);
6896 set_fwstate(pmlmepriv, WIFI_UNDER_WPS);
6898 _clr_fwstate_(pmlmepriv, WIFI_UNDER_WPS);
6902 if(rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO))
6905 #ifdef CONFIG_IOCTL_CFG80211
6906 if(adapter_wdev_data(padapter)->p2p_enabled && pwdinfo->driver_interface == DRIVER_CFG80211 )
6908 len = pmlmepriv->p2p_beacon_ie_len;
6909 if(pmlmepriv->p2p_beacon_ie && len>0)
6910 _rtw_memcpy(pframe, pmlmepriv->p2p_beacon_ie, len);
6913 #endif //CONFIG_IOCTL_CFG80211
6915 len = build_beacon_p2p_ie(pwdinfo, pframe);
6919 pattrib->pktlen += len;
6921 #ifdef CONFIG_IOCTL_CFG80211
6922 if(_TRUE == pwdinfo->wfd_info->wfd_enable)
6923 #endif //CONFIG_IOCTL_CFG80211
6925 len = build_beacon_wfd_ie( pwdinfo, pframe );
6927 #ifdef CONFIG_IOCTL_CFG80211
6931 if(pmlmepriv->wfd_beacon_ie && pmlmepriv->wfd_beacon_ie_len>0)
6933 len = pmlmepriv->wfd_beacon_ie_len;
6934 _rtw_memcpy(pframe, pmlmepriv->wfd_beacon_ie, len);
6937 #endif //CONFIG_IOCTL_CFG80211
6939 pattrib->pktlen += len;
6948 //below for ad-hoc mode
6950 //timestamp will be inserted by hardware
6952 pattrib->pktlen += 8;
6954 // beacon interval: 2 bytes
6956 _rtw_memcpy(pframe, (unsigned char *)(rtw_get_beacon_interval_from_ie(cur_network->IEs)), 2);
6959 pattrib->pktlen += 2;
6961 // capability info: 2 bytes
6963 _rtw_memcpy(pframe, (unsigned char *)(rtw_get_capability_from_ie(cur_network->IEs)), 2);
6966 pattrib->pktlen += 2;
6969 pframe = rtw_set_ie(pframe, _SSID_IE_, cur_network->Ssid.SsidLength, cur_network->Ssid.Ssid, &pattrib->pktlen);
6971 // supported rates...
6972 rate_len = rtw_get_rateset_len(cur_network->SupportedRates);
6973 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, ((rate_len > 8)? 8: rate_len), cur_network->SupportedRates, &pattrib->pktlen);
6976 pframe = rtw_set_ie(pframe, _DSSET_IE_, 1, (unsigned char *)&(cur_network->Configuration.DSConfig), &pattrib->pktlen);
6978 //if( (pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE)
6982 // IBSS Parameter Set...
6983 //ATIMWindow = cur->Configuration.ATIMWindow;
6985 pframe = rtw_set_ie(pframe, _IBSS_PARA_IE_, 2, (unsigned char *)(&ATIMWindow), &pattrib->pktlen);
6988 pframe = rtw_set_ie(pframe, _ERPINFO_IE_, 1, &erpinfo, &pattrib->pktlen);
6992 // EXTERNDED SUPPORTED RATE
6995 pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_, (rate_len - 8), (cur_network->SupportedRates + 8), &pattrib->pktlen);
7003 #if defined (CONFIG_AP_MODE) && defined (CONFIG_NATIVEAP_MLME)
7004 pmlmepriv->update_bcn = _FALSE;
7006 _exit_critical_bh(&pmlmepriv->bcn_update_lock, &irqL);
7007 #endif //#if defined (CONFIG_AP_MODE) && defined (CONFIG_NATIVEAP_MLME)
7009 if ((pattrib->pktlen + TXDESC_SIZE) > 512)
7011 DBG_871X("beacon frame too large\n");
7015 pattrib->last_txcmdsz = pattrib->pktlen;
7017 //DBG_871X("issue bcn_sz=%d\n", pattrib->last_txcmdsz);
7019 dump_mgntframe_and_wait(padapter, pmgntframe, timeout_ms);
7021 dump_mgntframe(padapter, pmgntframe);
7025 void issue_probersp(_adapter *padapter, unsigned char *da, u8 is_valid_p2p_probereq)
7027 struct xmit_frame *pmgntframe;
7028 struct pkt_attrib *pattrib;
7029 unsigned char *pframe;
7030 struct rtw_ieee80211_hdr *pwlanhdr;
7031 unsigned short *fctrl;
7032 unsigned char *mac, *bssid;
7033 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
7034 #if defined (CONFIG_AP_MODE) && defined (CONFIG_NATIVEAP_MLME)
7037 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
7038 #endif //#if defined (CONFIG_AP_MODE) && defined (CONFIG_NATIVEAP_MLME)
7039 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
7040 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7041 WLAN_BSSID_EX *cur_network = &(pmlmeinfo->network);
7042 unsigned int rate_len;
7044 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
7050 //DBG_871X("%s\n", __FUNCTION__);
7055 if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
7057 DBG_871X("%s, alloc mgnt frame fail\n", __FUNCTION__);
7063 pattrib = &pmgntframe->attrib;
7064 update_mgntframe_attrib(padapter, pattrib);
7066 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
7068 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
7069 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
7071 mac = myid(&(padapter->eeprompriv));
7072 bssid = cur_network->MacAddress;
7074 fctrl = &(pwlanhdr->frame_ctl);
7076 _rtw_memcpy(pwlanhdr->addr1, da, ETH_ALEN);
7077 _rtw_memcpy(pwlanhdr->addr2, mac, ETH_ALEN);
7078 _rtw_memcpy(pwlanhdr->addr3, bssid, ETH_ALEN);
7080 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
7081 pmlmeext->mgnt_seq++;
7082 SetFrameSubType(fctrl, WIFI_PROBERSP);
7084 pattrib->hdrlen = sizeof(struct rtw_ieee80211_hdr_3addr);
7085 pattrib->pktlen = pattrib->hdrlen;
7086 pframe += pattrib->hdrlen;
7089 if(cur_network->IELength>MAX_IE_SZ)
7092 #if defined (CONFIG_AP_MODE) && defined (CONFIG_NATIVEAP_MLME)
7093 if( (pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE)
7095 pwps_ie = rtw_get_wps_ie(cur_network->IEs+_FIXED_IE_LENGTH_, cur_network->IELength-_FIXED_IE_LENGTH_, NULL, &wps_ielen);
7097 //inerset & update wps_probe_resp_ie
7098 if((pmlmepriv->wps_probe_resp_ie!=NULL) && pwps_ie && (wps_ielen>0))
7100 uint wps_offset, remainder_ielen;
7103 wps_offset = (uint)(pwps_ie - cur_network->IEs);
7105 premainder_ie = pwps_ie + wps_ielen;
7107 remainder_ielen = cur_network->IELength - wps_offset - wps_ielen;
7109 _rtw_memcpy(pframe, cur_network->IEs, wps_offset);
7110 pframe += wps_offset;
7111 pattrib->pktlen += wps_offset;
7113 wps_ielen = (uint)pmlmepriv->wps_probe_resp_ie[1];//to get ie data len
7114 if((wps_offset+wps_ielen+2)<=MAX_IE_SZ)
7116 _rtw_memcpy(pframe, pmlmepriv->wps_probe_resp_ie, wps_ielen+2);
7117 pframe += wps_ielen+2;
7118 pattrib->pktlen += wps_ielen+2;
7121 if((wps_offset+wps_ielen+2+remainder_ielen)<=MAX_IE_SZ)
7123 _rtw_memcpy(pframe, premainder_ie, remainder_ielen);
7124 pframe += remainder_ielen;
7125 pattrib->pktlen += remainder_ielen;
7130 _rtw_memcpy(pframe, cur_network->IEs, cur_network->IELength);
7131 pframe += cur_network->IELength;
7132 pattrib->pktlen += cur_network->IELength;
7135 /* retrieve SSID IE from cur_network->Ssid */
7139 sint ssid_ielen_diff;
7141 u8 *ies = pmgntframe->buf_addr+TXDESC_OFFSET+sizeof(struct rtw_ieee80211_hdr_3addr);
7143 ssid_ie = rtw_get_ie(ies+_FIXED_IE_LENGTH_, _SSID_IE_, &ssid_ielen,
7144 (pframe-ies)-_FIXED_IE_LENGTH_);
7146 ssid_ielen_diff = cur_network->Ssid.SsidLength - ssid_ielen;
7148 if (ssid_ie && cur_network->Ssid.SsidLength) {
7149 uint remainder_ielen;
7151 remainder_ie = ssid_ie+2;
7152 remainder_ielen = (pframe-remainder_ie);
7154 if (remainder_ielen > MAX_IE_SZ) {
7155 DBG_871X_LEVEL(_drv_warning_, FUNC_ADPT_FMT" remainder_ielen > MAX_IE_SZ\n", FUNC_ADPT_ARG(padapter));
7156 remainder_ielen = MAX_IE_SZ;
7159 _rtw_memcpy(buf, remainder_ie, remainder_ielen);
7160 _rtw_memcpy(remainder_ie+ssid_ielen_diff, buf, remainder_ielen);
7161 *(ssid_ie+1) = cur_network->Ssid.SsidLength;
7162 _rtw_memcpy(ssid_ie+2, cur_network->Ssid.Ssid, cur_network->Ssid.SsidLength);
7164 pframe += ssid_ielen_diff;
7165 pattrib->pktlen += ssid_ielen_diff;
7173 //timestamp will be inserted by hardware
7175 pattrib->pktlen += 8;
7177 // beacon interval: 2 bytes
7179 _rtw_memcpy(pframe, (unsigned char *)(rtw_get_beacon_interval_from_ie(cur_network->IEs)), 2);
7182 pattrib->pktlen += 2;
7184 // capability info: 2 bytes
7186 _rtw_memcpy(pframe, (unsigned char *)(rtw_get_capability_from_ie(cur_network->IEs)), 2);
7189 pattrib->pktlen += 2;
7191 //below for ad-hoc mode
7194 pframe = rtw_set_ie(pframe, _SSID_IE_, cur_network->Ssid.SsidLength, cur_network->Ssid.Ssid, &pattrib->pktlen);
7196 // supported rates...
7197 rate_len = rtw_get_rateset_len(cur_network->SupportedRates);
7198 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, ((rate_len > 8)? 8: rate_len), cur_network->SupportedRates, &pattrib->pktlen);
7201 pframe =rtw_set_ie(pframe, _DSSET_IE_, 1, (unsigned char *)&(cur_network->Configuration.DSConfig), &pattrib->pktlen);
7203 if( (pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE)
7207 // IBSS Parameter Set...
7208 //ATIMWindow = cur->Configuration.ATIMWindow;
7210 pframe = rtw_set_ie(pframe, _IBSS_PARA_IE_, 2, (unsigned char *)(&ATIMWindow), &pattrib->pktlen);
7213 pframe = rtw_set_ie(pframe, _ERPINFO_IE_, 1, &erpinfo, &pattrib->pktlen);
7217 // EXTERNDED SUPPORTED RATE
7220 pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_, (rate_len - 8), (cur_network->SupportedRates + 8), &pattrib->pktlen);
7229 if(rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)
7230 /* IOT issue, When wifi_spec is not set, send probe_resp with P2P IE even if probe_req has no P2P IE */
7231 && (is_valid_p2p_probereq || !padapter->registrypriv.wifi_spec))
7234 #ifdef CONFIG_IOCTL_CFG80211
7235 if(adapter_wdev_data(padapter)->p2p_enabled && pwdinfo->driver_interface == DRIVER_CFG80211 )
7237 //if pwdinfo->role == P2P_ROLE_DEVICE will call issue_probersp_p2p()
7238 len = pmlmepriv->p2p_go_probe_resp_ie_len;
7239 if(pmlmepriv->p2p_go_probe_resp_ie && len>0)
7240 _rtw_memcpy(pframe, pmlmepriv->p2p_go_probe_resp_ie, len);
7243 #endif //CONFIG_IOCTL_CFG80211
7245 len = build_probe_resp_p2p_ie(pwdinfo, pframe);
7249 pattrib->pktlen += len;
7252 #ifdef CONFIG_IOCTL_CFG80211
7253 if(_TRUE == pwdinfo->wfd_info->wfd_enable)
7254 #endif //CONFIG_IOCTL_CFG80211
7256 len = build_probe_resp_wfd_ie(pwdinfo, pframe, 0);
7258 #ifdef CONFIG_IOCTL_CFG80211
7262 if(pmlmepriv->wfd_probe_resp_ie && pmlmepriv->wfd_probe_resp_ie_len>0)
7264 len = pmlmepriv->wfd_probe_resp_ie_len;
7265 _rtw_memcpy(pframe, pmlmepriv->wfd_probe_resp_ie, len);
7268 #endif //CONFIG_IOCTL_CFG80211
7270 pattrib->pktlen += len;
7277 #ifdef CONFIG_AUTO_AP_MODE
7279 struct sta_info *psta;
7280 struct sta_priv *pstapriv = &padapter->stapriv;
7282 DBG_871X("(%s)\n", __FUNCTION__);
7285 psta = rtw_get_stainfo(pstapriv, da);
7286 if (psta && psta->isrc && psta->pid>0)
7288 u8 RC_OUI[4]={0x00,0xE0,0x4C,0x0A};
7289 u8 RC_INFO[14] = {0};
7290 //EID[1] + EID_LEN[1] + RC_OUI[4] + MAC[6] + PairingID[2] + ChannelNum[2]
7291 u16 cu_ch = (u16)cur_network->Configuration.DSConfig;
7293 DBG_871X("%s, reply rc(pid=0x%x) device "MAC_FMT" in ch=%d\n", __FUNCTION__,
7294 psta->pid, MAC_ARG(psta->hwaddr), cu_ch);
7296 //append vendor specific ie
7297 _rtw_memcpy(RC_INFO, RC_OUI, sizeof(RC_OUI));
7298 _rtw_memcpy(&RC_INFO[4], mac, ETH_ALEN);
7299 _rtw_memcpy(&RC_INFO[10], (u8*)&psta->pid, 2);
7300 _rtw_memcpy(&RC_INFO[12], (u8*)&cu_ch, 2);
7302 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, sizeof(RC_INFO), RC_INFO, &pattrib->pktlen);
7305 #endif //CONFIG_AUTO_AP_MODE
7308 pattrib->last_txcmdsz = pattrib->pktlen;
7311 dump_mgntframe(padapter, pmgntframe);
7317 int _issue_probereq(_adapter *padapter, NDIS_802_11_SSID *pssid, u8 *da, u8 ch, bool append_wps, int wait_ack)
7320 struct xmit_frame *pmgntframe;
7321 struct pkt_attrib *pattrib;
7322 unsigned char *pframe;
7323 struct rtw_ieee80211_hdr *pwlanhdr;
7324 unsigned short *fctrl;
7326 unsigned char bssrate[NumRates];
7327 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
7328 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
7329 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
7330 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7331 int bssrate_len = 0;
7332 u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
7334 RT_TRACE(_module_rtl871x_mlme_c_,_drv_notice_,("+issue_probereq\n"));
7336 if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
7342 pattrib = &pmgntframe->attrib;
7343 update_mgntframe_attrib(padapter, pattrib);
7346 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
7348 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
7349 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
7351 mac = myid(&(padapter->eeprompriv));
7353 fctrl = &(pwlanhdr->frame_ctl);
7358 // unicast probe request frame
7359 _rtw_memcpy(pwlanhdr->addr1, da, ETH_ALEN);
7360 _rtw_memcpy(pwlanhdr->addr3, da, ETH_ALEN);
7364 // broadcast probe request frame
7365 _rtw_memcpy(pwlanhdr->addr1, bc_addr, ETH_ALEN);
7366 _rtw_memcpy(pwlanhdr->addr3, bc_addr, ETH_ALEN);
7369 _rtw_memcpy(pwlanhdr->addr2, mac, ETH_ALEN);
7371 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
7372 pmlmeext->mgnt_seq++;
7373 SetFrameSubType(pframe, WIFI_PROBEREQ);
7375 pframe += sizeof (struct rtw_ieee80211_hdr_3addr);
7376 pattrib->pktlen = sizeof (struct rtw_ieee80211_hdr_3addr);
7379 pframe = rtw_set_ie(pframe, _SSID_IE_, pssid->SsidLength, pssid->Ssid, &(pattrib->pktlen));
7381 pframe = rtw_set_ie(pframe, _SSID_IE_, 0, NULL, &(pattrib->pktlen));
7383 get_rate_set(padapter, bssrate, &bssrate_len);
7385 if (bssrate_len > 8)
7387 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_ , 8, bssrate, &(pattrib->pktlen));
7388 pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_ , (bssrate_len - 8), (bssrate + 8), &(pattrib->pktlen));
7392 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_ , bssrate_len , bssrate, &(pattrib->pktlen));
7396 pframe = rtw_set_ie(pframe, _DSSET_IE_, 1, &ch, &pattrib->pktlen);
7399 //add wps_ie for wps2.0
7400 if(pmlmepriv->wps_probe_req_ie_len>0 && pmlmepriv->wps_probe_req_ie)
7402 _rtw_memcpy(pframe, pmlmepriv->wps_probe_req_ie, pmlmepriv->wps_probe_req_ie_len);
7403 pframe += pmlmepriv->wps_probe_req_ie_len;
7404 pattrib->pktlen += pmlmepriv->wps_probe_req_ie_len;
7405 //pmlmepriv->wps_probe_req_ie_len = 0 ;//reset to zero
7409 pattrib->last_txcmdsz = pattrib->pktlen;
7411 RT_TRACE(_module_rtl871x_mlme_c_,_drv_notice_,("issuing probe_req, tx_len=%d\n", pattrib->last_txcmdsz));
7414 ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
7416 dump_mgntframe(padapter, pmgntframe);
7424 inline void issue_probereq(_adapter *padapter, NDIS_802_11_SSID *pssid, u8 *da)
7426 _issue_probereq(padapter, pssid, da, 0, 1, _FALSE);
7429 int issue_probereq_ex(_adapter *padapter, NDIS_802_11_SSID *pssid, u8 *da, u8 ch, bool append_wps,
7430 int try_cnt, int wait_ms)
7434 u32 start = rtw_get_current_time();
7438 ret = _issue_probereq(padapter, pssid, da, ch, append_wps, wait_ms>0?_TRUE:_FALSE);
7442 if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
7445 if(i < try_cnt && wait_ms > 0 && ret==_FAIL)
7446 rtw_msleep_os(wait_ms);
7448 }while((i<try_cnt) && ((ret==_FAIL)||(wait_ms==0)));
7452 #ifndef DBG_XMIT_ACK
7457 if (try_cnt && wait_ms) {
7459 DBG_871X(FUNC_ADPT_FMT" to "MAC_FMT", ch:%u%s, %d/%d in %u ms\n",
7460 FUNC_ADPT_ARG(padapter), MAC_ARG(da), rtw_get_oper_ch(padapter),
7461 ret==_SUCCESS?", acked":"", i, try_cnt, rtw_get_passing_time_ms(start));
7463 DBG_871X(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n",
7464 FUNC_ADPT_ARG(padapter), rtw_get_oper_ch(padapter),
7465 ret==_SUCCESS?", acked":"", i, try_cnt, rtw_get_passing_time_ms(start));
7471 // if psta == NULL, indiate we are station(client) now...
7472 void issue_auth(_adapter *padapter, struct sta_info *psta, unsigned short status)
7474 struct xmit_frame *pmgntframe;
7475 struct pkt_attrib *pattrib;
7476 unsigned char *pframe;
7477 struct rtw_ieee80211_hdr *pwlanhdr;
7478 unsigned short *fctrl;
7480 unsigned short val16;
7481 int use_shared_key = 0;
7482 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
7483 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
7484 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7486 if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
7492 pattrib = &pmgntframe->attrib;
7493 update_mgntframe_attrib(padapter, pattrib);
7495 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
7497 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
7498 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
7500 fctrl = &(pwlanhdr->frame_ctl);
7503 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
7504 pmlmeext->mgnt_seq++;
7505 SetFrameSubType(pframe, WIFI_AUTH);
7507 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
7508 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
7511 if(psta)// for AP mode
7513 #ifdef CONFIG_NATIVEAP_MLME
7515 _rtw_memcpy(pwlanhdr->addr1, psta->hwaddr, ETH_ALEN);
7516 _rtw_memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
7517 _rtw_memcpy(pwlanhdr->addr3, myid(&(padapter->eeprompriv)), ETH_ALEN);
7520 // setting auth algo number
7521 val16 = (u16)psta->authalg;
7523 if(status != _STATS_SUCCESSFUL_)
7527 val16 = cpu_to_le16(val16);
7531 pframe = rtw_set_fixed_ie(pframe, _AUTH_ALGM_NUM_, (unsigned char *)&val16, &(pattrib->pktlen));
7533 // setting auth seq number
7534 val16 =(u16)psta->auth_seq;
7535 val16 = cpu_to_le16(val16);
7536 pframe = rtw_set_fixed_ie(pframe, _AUTH_SEQ_NUM_, (unsigned char *)&val16, &(pattrib->pktlen));
7538 // setting status code...
7540 val16 = cpu_to_le16(val16);
7541 pframe = rtw_set_fixed_ie(pframe, _STATUS_CODE_, (unsigned char *)&val16, &(pattrib->pktlen));
7543 // added challenging text...
7544 if ((psta->auth_seq == 2) && (psta->state & WIFI_FW_AUTH_STATE) && (use_shared_key==1))
7546 pframe = rtw_set_ie(pframe, _CHLGETXT_IE_, 128, psta->chg_txt, &(pattrib->pktlen));
7552 _rtw_memcpy(pwlanhdr->addr1, get_my_bssid(&pmlmeinfo->network), ETH_ALEN);
7553 _rtw_memcpy(pwlanhdr->addr2, myid(&padapter->eeprompriv), ETH_ALEN);
7554 _rtw_memcpy(pwlanhdr->addr3, get_my_bssid(&pmlmeinfo->network), ETH_ALEN);
7556 // setting auth algo number
7557 val16 = (pmlmeinfo->auth_algo == dot11AuthAlgrthm_Shared)? 1: 0;// 0:OPEN System, 1:Shared key
7559 val16 = cpu_to_le16(val16);
7562 //DBG_871X("%s auth_algo= %s auth_seq=%d\n",__FUNCTION__,(pmlmeinfo->auth_algo==0)?"OPEN":"SHARED",pmlmeinfo->auth_seq);
7564 //setting IV for auth seq #3
7565 if ((pmlmeinfo->auth_seq == 3) && (pmlmeinfo->state & WIFI_FW_AUTH_STATE) && (use_shared_key==1))
7567 //DBG_871X("==> iv(%d),key_index(%d)\n",pmlmeinfo->iv,pmlmeinfo->key_index);
7568 val32 = ((pmlmeinfo->iv++) | (pmlmeinfo->key_index << 30));
7569 val32 = cpu_to_le32(val32);
7570 pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *)&val32, &(pattrib->pktlen));
7572 pattrib->iv_len = 4;
7575 pframe = rtw_set_fixed_ie(pframe, _AUTH_ALGM_NUM_, (unsigned char *)&val16, &(pattrib->pktlen));
7577 // setting auth seq number
7578 val16 = pmlmeinfo->auth_seq;
7579 val16 = cpu_to_le16(val16);
7580 pframe = rtw_set_fixed_ie(pframe, _AUTH_SEQ_NUM_, (unsigned char *)&val16, &(pattrib->pktlen));
7583 // setting status code...
7585 val16 = cpu_to_le16(val16);
7586 pframe = rtw_set_fixed_ie(pframe, _STATUS_CODE_, (unsigned char *)&val16, &(pattrib->pktlen));
7588 // then checking to see if sending challenging text...
7589 if ((pmlmeinfo->auth_seq == 3) && (pmlmeinfo->state & WIFI_FW_AUTH_STATE) && (use_shared_key==1))
7591 pframe = rtw_set_ie(pframe, _CHLGETXT_IE_, 128, pmlmeinfo->chg_txt, &(pattrib->pktlen));
7595 pattrib->hdrlen = sizeof(struct rtw_ieee80211_hdr_3addr);
7597 pattrib->encrypt = _WEP40_;
7599 pattrib->icv_len = 4;
7601 pattrib->pktlen += pattrib->icv_len;
7607 pattrib->last_txcmdsz = pattrib->pktlen;
7609 rtw_wep_encrypt(padapter, (u8 *)pmgntframe);
7610 DBG_871X("%s\n", __FUNCTION__);
7611 dump_mgntframe(padapter, pmgntframe);
7617 void issue_asocrsp(_adapter *padapter, unsigned short status, struct sta_info *pstat, int pkt_type)
7619 #ifdef CONFIG_AP_MODE
7620 struct xmit_frame *pmgntframe;
7621 struct rtw_ieee80211_hdr *pwlanhdr;
7622 struct pkt_attrib *pattrib;
7623 unsigned char *pbuf, *pframe;
7625 unsigned short *fctrl;
7626 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
7627 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
7628 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7629 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7630 WLAN_BSSID_EX *pnetwork = &(pmlmeinfo->network);
7631 u8 *ie = pnetwork->IEs;
7633 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
7640 DBG_871X("%s\n", __FUNCTION__);
7642 if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
7648 pattrib = &pmgntframe->attrib;
7649 update_mgntframe_attrib(padapter, pattrib);
7652 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
7654 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
7655 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
7657 fctrl = &(pwlanhdr->frame_ctl);
7660 _rtw_memcpy((void *)GetAddr1Ptr(pwlanhdr), pstat->hwaddr, ETH_ALEN);
7661 _rtw_memcpy((void *)GetAddr2Ptr(pwlanhdr), myid(&(padapter->eeprompriv)), ETH_ALEN);
7662 _rtw_memcpy((void *)GetAddr3Ptr(pwlanhdr), get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
7665 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
7666 pmlmeext->mgnt_seq++;
7667 if ((pkt_type == WIFI_ASSOCRSP) || (pkt_type == WIFI_REASSOCRSP))
7668 SetFrameSubType(pwlanhdr, pkt_type);
7672 pattrib->hdrlen = sizeof(struct rtw_ieee80211_hdr_3addr);
7673 pattrib->pktlen += pattrib->hdrlen;
7674 pframe += pattrib->hdrlen;
7677 val = *(unsigned short *)rtw_get_capability_from_ie(ie);
7679 pframe = rtw_set_fixed_ie(pframe, _CAPABILITY_ , (unsigned char *)&val, &(pattrib->pktlen));
7681 status = cpu_to_le16(status);
7682 pframe = rtw_set_fixed_ie(pframe , _STATUS_CODE_ , (unsigned char *)&status, &(pattrib->pktlen));
7684 val = cpu_to_le16(pstat->aid | BIT(14) | BIT(15));
7685 pframe = rtw_set_fixed_ie(pframe, _ASOC_ID_ , (unsigned char *)&val, &(pattrib->pktlen));
7687 if (pstat->bssratelen <= 8)
7689 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, pstat->bssratelen, pstat->bssrateset, &(pattrib->pktlen));
7693 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, 8, pstat->bssrateset, &(pattrib->pktlen));
7694 pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_, (pstat->bssratelen-8), pstat->bssrateset+8, &(pattrib->pktlen));
7697 #ifdef CONFIG_80211N_HT
7698 if ((pstat->flags & WLAN_STA_HT) && (pmlmepriv->htpriv.ht_option))
7702 //FILL HT CAP INFO IE
7703 //p = hostapd_eid_ht_capabilities_info(hapd, p);
7704 pbuf = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_CAPABILITY_IE_, &ie_len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
7705 if(pbuf && ie_len>0)
7707 _rtw_memcpy(pframe, pbuf, ie_len+2);
7708 pframe += (ie_len+2);
7709 pattrib->pktlen +=(ie_len+2);
7712 //FILL HT ADD INFO IE
7713 //p = hostapd_eid_ht_operation(hapd, p);
7714 pbuf = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_ADD_INFO_IE_, &ie_len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
7715 if(pbuf && ie_len>0)
7717 _rtw_memcpy(pframe, pbuf, ie_len+2);
7718 pframe += (ie_len+2);
7719 pattrib->pktlen +=(ie_len+2);
7725 #ifdef CONFIG_80211AC_VHT
7726 if ((pstat->flags & WLAN_STA_VHT) && (pmlmepriv->vhtpriv.vht_option))
7731 pbuf = rtw_get_ie(ie + _BEACON_IE_OFFSET_, EID_VHTCapability, &ie_len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
7732 if(pbuf && ie_len>0)
7734 _rtw_memcpy(pframe, pbuf, ie_len+2);
7735 pframe += (ie_len+2);
7736 pattrib->pktlen +=(ie_len+2);
7739 //FILL VHT OPERATION IE
7740 pbuf = rtw_get_ie(ie + _BEACON_IE_OFFSET_, EID_VHTOperation, &ie_len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
7741 if(pbuf && ie_len>0)
7743 _rtw_memcpy(pframe, pbuf, ie_len+2);
7744 pframe += (ie_len+2);
7745 pattrib->pktlen +=(ie_len+2);
7748 #endif //CONFIG_80211AC_VHT
7751 if ((pstat->flags & WLAN_STA_WME) && (pmlmepriv->qospriv.qos_option))
7754 unsigned char WMM_PARA_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01};
7756 for (pbuf = ie + _BEACON_IE_OFFSET_; ;pbuf+= (ie_len + 2))
7758 pbuf = rtw_get_ie(pbuf, _VENDOR_SPECIFIC_IE_, &ie_len, (pnetwork->IELength - _BEACON_IE_OFFSET_ - (ie_len + 2)));
7759 if(pbuf && _rtw_memcmp(pbuf+2, WMM_PARA_IE, 6))
7761 _rtw_memcpy(pframe, pbuf, ie_len+2);
7762 pframe += (ie_len+2);
7763 pattrib->pktlen +=(ie_len+2);
7768 if ((pbuf == NULL) || (ie_len == 0))
7777 if (pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_REALTEK)
7779 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, 6 , REALTEK_96B_IE, &(pattrib->pktlen));
7782 //add WPS IE ie for wps 2.0
7783 if(pmlmepriv->wps_assoc_resp_ie && pmlmepriv->wps_assoc_resp_ie_len>0)
7785 _rtw_memcpy(pframe, pmlmepriv->wps_assoc_resp_ie, pmlmepriv->wps_assoc_resp_ie_len);
7787 pframe += pmlmepriv->wps_assoc_resp_ie_len;
7788 pattrib->pktlen += pmlmepriv->wps_assoc_resp_ie_len;
7792 if( padapter->wdinfo.driver_interface == DRIVER_WEXT )
7794 if(rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO) && (pstat->is_p2p_device == _TRUE))
7798 len = build_assoc_resp_p2p_ie(pwdinfo, pframe, pstat->p2p_status_code);
7801 pattrib->pktlen += len;
7805 if(rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)
7806 #ifdef CONFIG_IOCTL_CFG80211
7807 && (_TRUE == pwdinfo->wfd_info->wfd_enable)
7808 #endif //CONFIG_IOCTL_CFG80211
7811 wfdielen = build_assoc_resp_wfd_ie(pwdinfo, pframe);
7813 pattrib->pktlen += wfdielen;
7818 pattrib->last_txcmdsz = pattrib->pktlen;
7820 dump_mgntframe(padapter, pmgntframe);
7825 void issue_assocreq(_adapter *padapter)
7828 struct xmit_frame *pmgntframe;
7829 struct pkt_attrib *pattrib;
7830 unsigned char *pframe, *p;
7831 struct rtw_ieee80211_hdr *pwlanhdr;
7832 unsigned short *fctrl;
7833 unsigned short val16;
7834 unsigned int i, j, ie_len, index=0;
7835 unsigned char rf_type, bssrate[NumRates], sta_bssrate[NumRates];
7836 PNDIS_802_11_VARIABLE_IEs pIE;
7837 struct registry_priv *pregpriv = &padapter->registrypriv;
7838 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
7839 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
7840 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
7841 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7842 int bssrate_len = 0, sta_bssrate_len = 0;
7843 u8 vs_ie_length = 0;
7845 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
7846 u8 p2pie[ 255 ] = { 0x00 };
7857 u8 pow_cap_ele[2] = { 0x00 };
7858 u8 sup_ch[ 30 * 2 ] = {0x00 }, sup_ch_idx = 0, idx_5g = 2; //For supported channel
7861 if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
7865 pattrib = &pmgntframe->attrib;
7866 update_mgntframe_attrib(padapter, pattrib);
7869 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
7871 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
7872 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
7874 fctrl = &(pwlanhdr->frame_ctl);
7876 _rtw_memcpy(pwlanhdr->addr1, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
7877 _rtw_memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
7878 _rtw_memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
7880 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
7881 pmlmeext->mgnt_seq++;
7882 SetFrameSubType(pframe, WIFI_ASSOCREQ);
7884 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
7885 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
7890 _rtw_memcpy(&cap, rtw_get_capability_from_ie(pmlmeinfo->network.IEs), 2);
7891 cap |= cap_SpecMgmt;
7892 _rtw_memcpy(pframe, &cap, 2);
7894 _rtw_memcpy(pframe, rtw_get_capability_from_ie(pmlmeinfo->network.IEs), 2);
7898 pattrib->pktlen += 2;
7901 //todo: listen interval for power saving
7902 val16 = cpu_to_le16(3);
7903 _rtw_memcpy(pframe ,(unsigned char *)&val16, 2);
7905 pattrib->pktlen += 2;
7908 pframe = rtw_set_ie(pframe, _SSID_IE_, pmlmeinfo->network.Ssid.SsidLength, pmlmeinfo->network.Ssid.Ssid, &(pattrib->pktlen));
7912 if(pmlmeext->cur_channel > 14)
7914 pow_cap_ele[0] = 13; // Minimum transmit power capability
7915 pow_cap_ele[1] = 21; // Maximum transmit power capability
7916 pframe = rtw_set_ie(pframe, EID_PowerCap, 2, pow_cap_ele, &(pattrib->pktlen));
7918 //supported channels
7920 if( pmlmeext->channel_set[sup_ch_idx].ChannelNum <= 14 )
7922 sup_ch[0] = 1; //First channel number
7923 sup_ch[1] = pmlmeext->channel_set[sup_ch_idx].ChannelNum; //Number of channel
7927 sup_ch[idx_5g++] = pmlmeext->channel_set[sup_ch_idx].ChannelNum;
7928 sup_ch[idx_5g++] = 1;
7932 while( pmlmeext->channel_set[sup_ch_idx].ChannelNum != 0 );
7933 pframe = rtw_set_ie(pframe, EID_SupportedChannels, idx_5g, sup_ch, &(pattrib->pktlen));
7937 //supported rate & extended supported rate
7939 #if 1 // Check if the AP's supported rates are also supported by STA.
7940 get_rate_set(padapter, sta_bssrate, &sta_bssrate_len);
7941 //DBG_871X("sta_bssrate_len=%d\n", sta_bssrate_len);
7943 if(pmlmeext->cur_channel == 14)// for JAPAN, channel 14 can only uses B Mode(CCK)
7945 sta_bssrate_len = 4;
7949 //for (i = 0; i < sta_bssrate_len; i++) {
7950 // DBG_871X("sta_bssrate[%d]=%02X\n", i, sta_bssrate[i]);
7953 for (i = 0; i < NDIS_802_11_LENGTH_RATES_EX; i++) {
7954 if (pmlmeinfo->network.SupportedRates[i] == 0) break;
7955 DBG_871X("network.SupportedRates[%d]=%02X\n", i, pmlmeinfo->network.SupportedRates[i]);
7959 for (i = 0; i < NDIS_802_11_LENGTH_RATES_EX; i++) {
7960 if (pmlmeinfo->network.SupportedRates[i] == 0) break;
7963 // Check if the AP's supported rates are also supported by STA.
7964 for (j=0; j < sta_bssrate_len; j++) {
7965 // Avoid the proprietary data rate (22Mbps) of Handlink WSG-4000 AP
7966 if ( (pmlmeinfo->network.SupportedRates[i]|IEEE80211_BASIC_RATE_MASK)
7967 == (sta_bssrate[j]|IEEE80211_BASIC_RATE_MASK)) {
7968 //DBG_871X("match i = %d, j=%d\n", i, j);
7971 //DBG_871X("not match: %02X != %02X\n", (pmlmeinfo->network.SupportedRates[i]|IEEE80211_BASIC_RATE_MASK), (sta_bssrate[j]|IEEE80211_BASIC_RATE_MASK));
7975 if (j == sta_bssrate_len) {
7976 // the rate is not supported by STA
7977 DBG_871X("%s(): the rate[%d]=%02X is not supported by STA!\n",__FUNCTION__, i, pmlmeinfo->network.SupportedRates[i]);
7979 // the rate is supported by STA
7980 bssrate[index++] = pmlmeinfo->network.SupportedRates[i];
7984 bssrate_len = index;
7985 DBG_871X("bssrate_len = %d\n", bssrate_len);
7987 #else // Check if the AP's supported rates are also supported by STA.
7989 get_rate_set(padapter, bssrate, &bssrate_len);
7991 for (bssrate_len = 0; bssrate_len < NumRates; bssrate_len++) {
7992 if (pmlmeinfo->network.SupportedRates[bssrate_len] == 0) break;
7994 if (pmlmeinfo->network.SupportedRates[bssrate_len] == 0x2C) // Avoid the proprietary data rate (22Mbps) of Handlink WSG-4000 AP
7997 bssrate[bssrate_len] = pmlmeinfo->network.SupportedRates[bssrate_len];
8000 #endif // Check if the AP's supported rates are also supported by STA.
8002 if (bssrate_len == 0) {
8003 rtw_free_xmitbuf(pxmitpriv, pmgntframe->pxmitbuf);
8004 rtw_free_xmitframe(pxmitpriv, pmgntframe);
8005 goto exit; //don't connect to AP if no joint supported rate
8009 if (bssrate_len > 8)
8011 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_ , 8, bssrate, &(pattrib->pktlen));
8012 pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_ , (bssrate_len - 8), (bssrate + 8), &(pattrib->pktlen));
8016 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_ , bssrate_len , bssrate, &(pattrib->pktlen));
8019 //vendor specific IE, such as WPA, WMM, WPS
8020 for (i = sizeof(NDIS_802_11_FIXED_IEs); i < pmlmeinfo->network.IELength;)
8022 pIE = (PNDIS_802_11_VARIABLE_IEs)(pmlmeinfo->network.IEs + i);
8024 switch (pIE->ElementID)
8026 case _VENDOR_SPECIFIC_IE_:
8027 if ((_rtw_memcmp(pIE->data, RTW_WPA_OUI, 4)) ||
8028 (_rtw_memcmp(pIE->data, WMM_OUI, 4)) ||
8029 (_rtw_memcmp(pIE->data, WPS_OUI, 4)))
8031 vs_ie_length = pIE->Length;
8032 if((!padapter->registrypriv.wifi_spec) && (_rtw_memcmp(pIE->data, WPS_OUI, 4)))
8034 //Commented by Kurt 20110629
8035 //In some older APs, WPS handshake
8036 //would be fail if we append vender extensions informations to AP
8041 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, vs_ie_length, pIE->data, &(pattrib->pktlen));
8046 pframe = rtw_set_ie(pframe, EID_WPA2, pIE->Length, pIE->data, &(pattrib->pktlen));
8048 #ifdef CONFIG_80211N_HT
8049 case EID_HTCapability:
8050 if(padapter->mlmepriv.htpriv.ht_option==_TRUE) {
8051 if (!(is_ap_in_tkip(padapter)))
8053 _rtw_memcpy(&(pmlmeinfo->HT_caps), pIE->data, sizeof(struct HT_caps_element));
8055 pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info = cpu_to_le16(pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info);
8057 pframe = rtw_set_ie(pframe, EID_HTCapability, pIE->Length , (u8 *)(&(pmlmeinfo->HT_caps)), &(pattrib->pktlen));
8062 case EID_EXTCapability:
8063 if(padapter->mlmepriv.htpriv.ht_option==_TRUE) {
8064 pframe = rtw_set_ie(pframe, EID_EXTCapability, pIE->Length, pIE->data, &(pattrib->pktlen));
8067 #endif //CONFIG_80211N_HT
8068 #ifdef CONFIG_80211AC_VHT
8069 case EID_VHTCapability:
8070 if (padapter->mlmepriv.vhtpriv.vht_option ==_TRUE) {
8071 pframe = rtw_set_ie(pframe, EID_VHTCapability, pIE->Length, pIE->data, &(pattrib->pktlen));
8075 case EID_OpModeNotification:
8076 if (padapter->mlmepriv.vhtpriv.vht_option ==_TRUE) {
8077 pframe = rtw_set_ie(pframe, EID_OpModeNotification, pIE->Length, pIE->data, &(pattrib->pktlen));
8080 #endif // CONFIG_80211AC_VHT
8085 i += (pIE->Length + 2);
8088 if (pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_REALTEK)
8090 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, 6 , REALTEK_96B_IE, &(pattrib->pktlen));
8094 #ifdef CONFIG_WAPI_SUPPORT
8095 rtw_build_assoc_req_wapi_ie(padapter, pframe, pattrib);
8101 #ifdef CONFIG_IOCTL_CFG80211
8102 if(adapter_wdev_data(padapter)->p2p_enabled && pwdinfo->driver_interface == DRIVER_CFG80211 )
8104 if(pmlmepriv->p2p_assoc_req_ie && pmlmepriv->p2p_assoc_req_ie_len>0)
8106 _rtw_memcpy(pframe, pmlmepriv->p2p_assoc_req_ie, pmlmepriv->p2p_assoc_req_ie_len);
8107 pframe += pmlmepriv->p2p_assoc_req_ie_len;
8108 pattrib->pktlen += pmlmepriv->p2p_assoc_req_ie_len;
8112 #endif //CONFIG_IOCTL_CFG80211
8114 if(!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE) && !rtw_p2p_chk_state(pwdinfo, P2P_STATE_IDLE))
8116 // Should add the P2P IE in the association request frame.
8120 p2pie[ p2pielen++ ] = 0x50;
8121 p2pie[ p2pielen++ ] = 0x6F;
8122 p2pie[ p2pielen++ ] = 0x9A;
8123 p2pie[ p2pielen++ ] = 0x09; // WFA P2P v1.0
8125 // Commented by Albert 20101109
8126 // According to the P2P Specification, the association request frame should contain 3 P2P attributes
8127 // 1. P2P Capability
8128 // 2. Extended Listen Timing
8130 // Commented by Albert 20110516
8135 p2pie[ p2pielen++ ] = P2P_ATTR_CAPABILITY;
8138 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0002 );
8142 // Device Capability Bitmap, 1 byte
8143 p2pie[ p2pielen++ ] = DMP_P2P_DEVCAP_SUPPORT;
8145 // Group Capability Bitmap, 1 byte
8146 if ( pwdinfo->persistent_supported )
8147 p2pie[ p2pielen++ ] = P2P_GRPCAP_PERSISTENT_GROUP | DMP_P2P_GRPCAP_SUPPORT;
8149 p2pie[ p2pielen++ ] = DMP_P2P_GRPCAP_SUPPORT;
8151 // Extended Listen Timing
8153 p2pie[ p2pielen++ ] = P2P_ATTR_EX_LISTEN_TIMING;
8156 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0004 );
8160 // Availability Period
8161 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0xFFFF );
8164 // Availability Interval
8165 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0xFFFF );
8170 p2pie[ p2pielen++ ] = P2P_ATTR_DEVICE_INFO;
8173 // 21 -> P2P Device Address (6bytes) + Config Methods (2bytes) + Primary Device Type (8bytes)
8174 // + NumofSecondDevType (1byte) + WPS Device Name ID field (2bytes) + WPS Device Name Len field (2bytes)
8175 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 21 + pwdinfo->device_name_len );
8179 // P2P Device Address
8180 _rtw_memcpy( p2pie + p2pielen, myid( &padapter->eeprompriv ), ETH_ALEN );
8181 p2pielen += ETH_ALEN;
8184 // This field should be big endian. Noted by P2P specification.
8185 if ( ( pwdinfo->ui_got_wps_info == P2P_GOT_WPSINFO_PEER_DISPLAY_PIN ) ||
8186 ( pwdinfo->ui_got_wps_info == P2P_GOT_WPSINFO_SELF_DISPLAY_PIN ) )
8188 *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( WPS_CONFIG_METHOD_DISPLAY );
8192 *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( WPS_CONFIG_METHOD_PBC );
8197 // Primary Device Type
8199 *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( WPS_PDT_CID_MULIT_MEDIA );
8203 *(u32*) ( p2pie + p2pielen ) = cpu_to_be32( WPSOUI );
8207 *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( WPS_PDT_SCID_MEDIA_SERVER );
8210 // Number of Secondary Device Types
8211 p2pie[ p2pielen++ ] = 0x00; // No Secondary Device Type List
8215 *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( WPS_ATTR_DEVICE_NAME );
8219 *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( pwdinfo->device_name_len );
8223 _rtw_memcpy( p2pie + p2pielen, pwdinfo->device_name, pwdinfo->device_name_len );
8224 p2pielen += pwdinfo->device_name_len;
8228 p2pie[ p2pielen++ ] = P2P_ATTR_INTERFACE;
8231 *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x000D );
8235 _rtw_memcpy( p2pie + p2pielen, pwdinfo->device_addr, ETH_ALEN ); // P2P Device Address
8236 p2pielen += ETH_ALEN;
8238 p2pie[ p2pielen++ ] = 1; // P2P Interface Address Count
8240 _rtw_memcpy( p2pie + p2pielen, pwdinfo->device_addr, ETH_ALEN ); // P2P Interface Address List
8241 p2pielen += ETH_ALEN;
8243 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *) p2pie, &pattrib->pktlen );
8246 //wfdielen = build_assoc_req_wfd_ie(pwdinfo, pframe);
8247 //pframe += wfdielen;
8248 //pattrib->pktlen += wfdielen;
8256 #ifdef CONFIG_IOCTL_CFG80211
8257 if ( _TRUE == pwdinfo->wfd_info->wfd_enable )
8258 #endif //CONFIG_IOCTL_CFG80211
8260 wfdielen = build_assoc_req_wfd_ie(pwdinfo, pframe);
8262 pattrib->pktlen += wfdielen;
8264 #ifdef CONFIG_IOCTL_CFG80211
8265 else if (pmlmepriv->wfd_assoc_req_ie != NULL && pmlmepriv->wfd_assoc_req_ie_len>0)
8268 _rtw_memcpy(pframe, pmlmepriv->wfd_assoc_req_ie, pmlmepriv->wfd_assoc_req_ie_len);
8269 pattrib->pktlen += pmlmepriv->wfd_assoc_req_ie_len;
8270 pframe += pmlmepriv->wfd_assoc_req_ie_len;
8272 #endif //CONFIG_IOCTL_CFG80211
8275 pattrib->last_txcmdsz = pattrib->pktlen;
8276 dump_mgntframe(padapter, pmgntframe);
8281 if (ret == _SUCCESS)
8282 rtw_buf_update(&pmlmepriv->assoc_req, &pmlmepriv->assoc_req_len, (u8 *)pwlanhdr, pattrib->pktlen);
8284 rtw_buf_free(&pmlmepriv->assoc_req, &pmlmepriv->assoc_req_len);
8289 //when wait_ack is ture, this function shoule be called at process context
8290 static int _issue_nulldata(_adapter *padapter, unsigned char *da, unsigned int power_mode, int wait_ack)
8293 struct xmit_frame *pmgntframe;
8294 struct pkt_attrib *pattrib;
8295 unsigned char *pframe;
8296 struct rtw_ieee80211_hdr *pwlanhdr;
8297 unsigned short *fctrl;
8298 struct xmit_priv *pxmitpriv;
8299 struct mlme_ext_priv *pmlmeext;
8300 struct mlme_ext_info *pmlmeinfo;
8302 //DBG_871X("%s:%d\n", __FUNCTION__, power_mode);
8307 pxmitpriv = &(padapter->xmitpriv);
8308 pmlmeext = &(padapter->mlmeextpriv);
8309 pmlmeinfo = &(pmlmeext->mlmext_info);
8311 if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
8317 pattrib = &pmgntframe->attrib;
8318 update_mgntframe_attrib(padapter, pattrib);
8319 pattrib->retry_ctrl = _FALSE;
8321 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
8323 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
8324 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
8326 fctrl = &(pwlanhdr->frame_ctl);
8329 if((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE)
8333 else if((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE)
8343 _rtw_memcpy(pwlanhdr->addr1, da, ETH_ALEN);
8344 _rtw_memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
8345 _rtw_memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
8347 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
8348 pmlmeext->mgnt_seq++;
8349 SetFrameSubType(pframe, WIFI_DATA_NULL);
8351 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
8352 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
8354 pattrib->last_txcmdsz = pattrib->pktlen;
8358 ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
8362 dump_mgntframe(padapter, pmgntframe);
8371 * [IMPORTANT] Don't call this function in interrupt context
8373 * When wait_ms > 0, this function shoule be called at process context
8374 * da == NULL for station mode
8376 int issue_nulldata(_adapter *padapter, unsigned char *da, unsigned int power_mode, int try_cnt, int wait_ms)
8380 u32 start = rtw_get_current_time();
8381 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
8382 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
8383 struct sta_info *psta;
8386 /* da == NULL, assum it's null data for sta to ap*/
8388 da = get_my_bssid(&(pmlmeinfo->network));
8390 psta = rtw_get_stainfo(&padapter->stapriv, da);
8393 rtw_hal_macid_sleep(padapter, psta->mac_id);
8395 rtw_hal_macid_wakeup(padapter, psta->mac_id);
8397 DBG_871X(FUNC_ADPT_FMT ": Can't find sta info for " MAC_FMT ", skip macid %s!!\n",
8398 FUNC_ADPT_ARG(padapter), MAC_ARG(da), power_mode?"sleep":"wakeup");
8403 ret = _issue_nulldata(padapter, da, power_mode, wait_ms>0?_TRUE:_FALSE);
8407 if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
8410 if(i < try_cnt && wait_ms > 0 && ret==_FAIL)
8411 rtw_msleep_os(wait_ms);
8413 }while((i<try_cnt) && ((ret==_FAIL)||(wait_ms==0)));
8417 #ifndef DBG_XMIT_ACK
8422 if (try_cnt && wait_ms) {
8424 DBG_871X(FUNC_ADPT_FMT" to "MAC_FMT", ch:%u%s, %d/%d in %u ms\n",
8425 FUNC_ADPT_ARG(padapter), MAC_ARG(da), rtw_get_oper_ch(padapter),
8426 ret==_SUCCESS?", acked":"", i, try_cnt, rtw_get_passing_time_ms(start));
8428 DBG_871X(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n",
8429 FUNC_ADPT_ARG(padapter), rtw_get_oper_ch(padapter),
8430 ret==_SUCCESS?", acked":"", i, try_cnt, rtw_get_passing_time_ms(start));
8437 * [IMPORTANT] This function run in interrupt context
8439 * The null data packet would be sent without power bit,
8440 * and not guarantee success.
8442 s32 issue_nulldata_in_interrupt(PADAPTER padapter, u8 *da)
8445 struct mlme_ext_priv *pmlmeext;
8446 struct mlme_ext_info *pmlmeinfo;
8449 pmlmeext = &padapter->mlmeextpriv;
8450 pmlmeinfo = &pmlmeext->mlmext_info;
8452 /* da == NULL, assum it's null data for sta to ap*/
8454 da = get_my_bssid(&(pmlmeinfo->network));
8456 ret = _issue_nulldata(padapter, da, 0, _FALSE);
8461 //when wait_ack is ture, this function shoule be called at process context
8462 static int _issue_qos_nulldata(_adapter *padapter, unsigned char *da, u16 tid, int wait_ack)
8465 struct xmit_frame *pmgntframe;
8466 struct pkt_attrib *pattrib;
8467 unsigned char *pframe;
8468 struct rtw_ieee80211_hdr *pwlanhdr;
8469 unsigned short *fctrl, *qc;
8470 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
8471 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
8472 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
8474 DBG_871X("%s\n", __FUNCTION__);
8476 if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
8482 pattrib = &pmgntframe->attrib;
8483 update_mgntframe_attrib(padapter, pattrib);
8485 pattrib->hdrlen +=2;
8486 pattrib->qos_en = _TRUE;
8488 pattrib->ack_policy = 0;
8491 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
8493 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
8494 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
8496 fctrl = &(pwlanhdr->frame_ctl);
8499 if((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE)
8503 else if((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE)
8511 qc = (unsigned short *)(pframe + pattrib->hdrlen - 2);
8513 SetPriority(qc, tid);
8515 SetEOSP(qc, pattrib->eosp);
8517 SetAckpolicy(qc, pattrib->ack_policy);
8519 _rtw_memcpy(pwlanhdr->addr1, da, ETH_ALEN);
8520 _rtw_memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
8521 _rtw_memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
8523 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
8524 pmlmeext->mgnt_seq++;
8525 SetFrameSubType(pframe, WIFI_QOS_DATA_NULL);
8527 pframe += sizeof(struct rtw_ieee80211_hdr_3addr_qos);
8528 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr_qos);
8530 pattrib->last_txcmdsz = pattrib->pktlen;
8534 ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
8538 dump_mgntframe(padapter, pmgntframe);
8546 //when wait_ms >0 , this function shoule be called at process context
8547 //da == NULL for station mode
8548 int issue_qos_nulldata(_adapter *padapter, unsigned char *da, u16 tid, int try_cnt, int wait_ms)
8552 u32 start = rtw_get_current_time();
8553 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
8554 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
8556 /* da == NULL, assum it's null data for sta to ap*/
8558 da = get_my_bssid(&(pmlmeinfo->network));
8562 ret = _issue_qos_nulldata(padapter, da, tid, wait_ms>0?_TRUE:_FALSE);
8566 if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
8569 if(i < try_cnt && wait_ms > 0 && ret==_FAIL)
8570 rtw_msleep_os(wait_ms);
8572 }while((i<try_cnt) && ((ret==_FAIL)||(wait_ms==0)));
8576 #ifndef DBG_XMIT_ACK
8581 if (try_cnt && wait_ms) {
8583 DBG_871X(FUNC_ADPT_FMT" to "MAC_FMT", ch:%u%s, %d/%d in %u ms\n",
8584 FUNC_ADPT_ARG(padapter), MAC_ARG(da), rtw_get_oper_ch(padapter),
8585 ret==_SUCCESS?", acked":"", i, try_cnt, rtw_get_passing_time_ms(start));
8587 DBG_871X(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n",
8588 FUNC_ADPT_ARG(padapter), rtw_get_oper_ch(padapter),
8589 ret==_SUCCESS?", acked":"", i, try_cnt, rtw_get_passing_time_ms(start));
8595 static int _issue_deauth(_adapter *padapter, unsigned char *da, unsigned short reason, u8 wait_ack)
8597 struct xmit_frame *pmgntframe;
8598 struct pkt_attrib *pattrib;
8599 unsigned char *pframe;
8600 struct rtw_ieee80211_hdr *pwlanhdr;
8601 unsigned short *fctrl;
8602 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
8603 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
8604 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
8607 struct wifidirect_info *pwdinfo= &(padapter->wdinfo);
8610 //DBG_871X("%s to "MAC_FMT"\n", __func__, MAC_ARG(da));
8613 if ( !( rtw_p2p_chk_state( pwdinfo, P2P_STATE_NONE ) ) && ( pwdinfo->rx_invitereq_info.scan_op_ch_only ) )
8615 _cancel_timer_ex( &pwdinfo->reset_ch_sitesurvey );
8616 _set_timer( &pwdinfo->reset_ch_sitesurvey, 10 );
8620 if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
8626 pattrib = &pmgntframe->attrib;
8627 update_mgntframe_attrib(padapter, pattrib);
8628 pattrib->retry_ctrl = _FALSE;
8630 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
8632 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
8633 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
8635 fctrl = &(pwlanhdr->frame_ctl);
8638 _rtw_memcpy(pwlanhdr->addr1, da, ETH_ALEN);
8639 _rtw_memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
8640 _rtw_memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
8642 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
8643 pmlmeext->mgnt_seq++;
8644 SetFrameSubType(pframe, WIFI_DEAUTH);
8646 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
8647 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
8649 reason = cpu_to_le16(reason);
8650 pframe = rtw_set_fixed_ie(pframe, _RSON_CODE_ , (unsigned char *)&reason, &(pattrib->pktlen));
8652 pattrib->last_txcmdsz = pattrib->pktlen;
8657 ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
8661 dump_mgntframe(padapter, pmgntframe);
8669 int issue_deauth(_adapter *padapter, unsigned char *da, unsigned short reason)
8671 DBG_871X("%s to "MAC_FMT"\n", __func__, MAC_ARG(da));
8672 return _issue_deauth(padapter, da, reason, _FALSE);
8675 int issue_deauth_ex(_adapter *padapter, u8 *da, unsigned short reason, int try_cnt,
8680 u32 start = rtw_get_current_time();
8684 ret = _issue_deauth(padapter, da, reason, wait_ms>0?_TRUE:_FALSE);
8688 if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
8691 if(i < try_cnt && wait_ms > 0 && ret==_FAIL)
8692 rtw_msleep_os(wait_ms);
8694 }while((i<try_cnt) && ((ret==_FAIL)||(wait_ms==0)));
8698 #ifndef DBG_XMIT_ACK
8703 if (try_cnt && wait_ms) {
8705 DBG_871X(FUNC_ADPT_FMT" to "MAC_FMT", ch:%u%s, %d/%d in %u ms\n",
8706 FUNC_ADPT_ARG(padapter), MAC_ARG(da), rtw_get_oper_ch(padapter),
8707 ret==_SUCCESS?", acked":"", i, try_cnt, rtw_get_passing_time_ms(start));
8709 DBG_871X(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n",
8710 FUNC_ADPT_ARG(padapter), rtw_get_oper_ch(padapter),
8711 ret==_SUCCESS?", acked":"", i, try_cnt, rtw_get_passing_time_ms(start));
8717 void issue_action_spct_ch_switch(_adapter *padapter, u8 *ra, u8 new_ch, u8 ch_offset)
8720 _list *plist, *phead;
8721 struct xmit_frame *pmgntframe;
8722 struct pkt_attrib *pattrib;
8723 unsigned char *pframe;
8724 struct rtw_ieee80211_hdr *pwlanhdr;
8725 unsigned short *fctrl;
8726 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
8727 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
8728 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
8729 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
8732 DBG_871X(FUNC_NDEV_FMT" ra="MAC_FMT", ch:%u, offset:%u\n",
8733 FUNC_NDEV_ARG(padapter->pnetdev), MAC_ARG(ra), new_ch, ch_offset);
8735 if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
8739 pattrib = &pmgntframe->attrib;
8740 update_mgntframe_attrib(padapter, pattrib);
8742 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
8744 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
8745 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
8747 fctrl = &(pwlanhdr->frame_ctl);
8750 _rtw_memcpy(pwlanhdr->addr1, ra, ETH_ALEN); /* RA */
8751 _rtw_memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN); /* TA */
8752 _rtw_memcpy(pwlanhdr->addr3, ra, ETH_ALEN); /* DA = RA */
8754 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
8755 pmlmeext->mgnt_seq++;
8756 SetFrameSubType(pframe, WIFI_ACTION);
8758 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
8759 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
8761 /* category, action */
8763 u8 category, action;
8764 category = RTW_WLAN_CATEGORY_SPECTRUM_MGMT;
8765 action = RTW_WLAN_ACTION_SPCT_CHL_SWITCH;
8767 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
8768 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
8771 pframe = rtw_set_ie_ch_switch(pframe, &(pattrib->pktlen), 0, new_ch, 0);
8772 pframe = rtw_set_ie_secondary_ch_offset(pframe, &(pattrib->pktlen),
8773 hal_ch_offset_to_secondary_ch_offset(ch_offset));
8775 pattrib->last_txcmdsz = pattrib->pktlen;
8777 dump_mgntframe(padapter, pmgntframe);
8781 #ifdef CONFIG_IEEE80211W
8782 void issue_action_SA_Query(_adapter *padapter, unsigned char *raddr, unsigned char action, unsigned short tid)
8784 u8 category = RTW_WLAN_CATEGORY_SA_QUERY;
8786 struct xmit_frame *pmgntframe;
8787 struct pkt_attrib *pattrib;
8789 struct rtw_ieee80211_hdr *pwlanhdr;
8791 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
8792 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
8793 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
8794 struct sta_info *psta;
8795 struct sta_priv *pstapriv = &padapter->stapriv;
8796 struct registry_priv *pregpriv = &padapter->registrypriv;
8799 DBG_871X("%s\n", __FUNCTION__);
8801 if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
8803 DBG_871X("%s: alloc_mgtxmitframe fail\n", __FUNCTION__);
8808 pattrib = &pmgntframe->attrib;
8809 update_mgntframe_attrib(padapter, pattrib);
8811 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
8813 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
8814 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
8816 fctrl = &(pwlanhdr->frame_ctl);
8820 _rtw_memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
8822 _rtw_memcpy(pwlanhdr->addr1, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
8823 _rtw_memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
8824 _rtw_memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
8826 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
8827 pmlmeext->mgnt_seq++;
8828 SetFrameSubType(pframe, WIFI_ACTION);
8830 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
8831 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
8833 pframe = rtw_set_fixed_ie(pframe, 1, &category, &pattrib->pktlen);
8834 pframe = rtw_set_fixed_ie(pframe, 1, &action, &pattrib->pktlen);
8838 case 0: //SA Query req
8839 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)&pmlmeext->sa_query_seq, &pattrib->pktlen);
8840 pmlmeext->sa_query_seq++;
8841 //send sa query request to AP, AP should reply sa query response in 1 second
8842 set_sa_query_timer(pmlmeext, 1000);
8845 case 1: //SA Query rsp
8846 tid = cpu_to_le16(tid);
8847 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)&tid, &pattrib->pktlen);
8853 pattrib->last_txcmdsz = pattrib->pktlen;
8855 dump_mgntframe(padapter, pmgntframe);
8857 #endif //CONFIG_IEEE80211W
8859 void issue_action_BA(_adapter *padapter, unsigned char *raddr, unsigned char action, unsigned short status)
8861 u8 category = RTW_WLAN_CATEGORY_BACK;
8865 u16 BA_timeout_value;
8866 u16 BA_starting_seqctrl;
8867 u32 max_rx_ampdu_factor;
8868 struct xmit_frame *pmgntframe;
8869 struct pkt_attrib *pattrib;
8871 struct rtw_ieee80211_hdr *pwlanhdr;
8873 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
8874 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
8875 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
8876 struct sta_info *psta;
8877 struct sta_priv *pstapriv = &padapter->stapriv;
8878 struct registry_priv *pregpriv = &padapter->registrypriv;
8880 #ifdef CONFIG_80211N_HT
8881 DBG_871X("%s, category=%d, action=%d, status=%d\n", __FUNCTION__, category, action, status);
8883 if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
8889 pattrib = &pmgntframe->attrib;
8890 update_mgntframe_attrib(padapter, pattrib);
8892 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
8894 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
8895 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
8897 fctrl = &(pwlanhdr->frame_ctl);
8900 //_rtw_memcpy(pwlanhdr->addr1, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
8901 _rtw_memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
8902 _rtw_memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
8903 _rtw_memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
8905 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
8906 pmlmeext->mgnt_seq++;
8907 SetFrameSubType(pframe, WIFI_ACTION);
8909 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
8910 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
8912 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
8913 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
8915 status = cpu_to_le16(status);
8924 pmlmeinfo->dialogToken++;
8925 } while (pmlmeinfo->dialogToken == 0);
8926 pframe = rtw_set_fixed_ie(pframe, 1, &(pmlmeinfo->dialogToken), &(pattrib->pktlen));
8928 #ifdef CONFIG_BT_COEXIST
8929 if (rtw_btcoex_IsBTCoexCtrlAMPDUSize(padapter) == _TRUE)
8931 // A-MSDU NOT Supported
8933 // immediate Block Ack
8934 BA_para_set |= (1 << 1) & IEEE80211_ADDBA_PARAM_POLICY_MASK;
8936 BA_para_set |= (status << 2) & IEEE80211_ADDBA_PARAM_TID_MASK;
8937 // max buffer size is 8 MSDU
8938 BA_para_set |= (8 << 6) & RTW_IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK;
8943 #if defined(CONFIG_RTL8188E) && defined(CONFIG_SDIO_HCI)
8944 BA_para_set = (0x0802 | ((status & 0xf) << 2)); //immediate ack & 16 buffer size
8946 BA_para_set = (0x1002 | ((status & 0xf) << 2)); //immediate ack & 64 buffer size
8949 //sys_mib.BA_para_set = 0x0802; //immediate ack & 32 buffer size
8950 BA_para_set = cpu_to_le16(BA_para_set);
8951 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(BA_para_set)), &(pattrib->pktlen));
8953 //BA_timeout_value = 0xffff;//max: 65535 TUs(~ 65 ms)
8954 BA_timeout_value = 5000;//~ 5ms
8955 BA_timeout_value = cpu_to_le16(BA_timeout_value);
8956 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(BA_timeout_value)), &(pattrib->pktlen));
8958 //if ((psta = rtw_get_stainfo(pstapriv, pmlmeinfo->network.MacAddress)) != NULL)
8959 if ((psta = rtw_get_stainfo(pstapriv, raddr)) != NULL)
8961 start_seq = (psta->sta_xmitpriv.txseq_tid[status & 0x07]&0xfff) + 1;
8963 DBG_871X("BA_starting_seqctrl = %d for TID=%d\n", start_seq, status & 0x07);
8965 psta->BA_starting_seqctrl[status & 0x07] = start_seq;
8967 BA_starting_seqctrl = start_seq << 4;
8970 BA_starting_seqctrl = cpu_to_le16(BA_starting_seqctrl);
8971 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(BA_starting_seqctrl)), &(pattrib->pktlen));
8975 pframe = rtw_set_fixed_ie(pframe, 1, &(pmlmeinfo->ADDBA_req.dialog_token), &(pattrib->pktlen));
8976 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&status), &(pattrib->pktlen));
8978 //BA_para_set = cpu_to_le16((le16_to_cpu(pmlmeinfo->ADDBA_req.BA_para_set) & 0x3f) | 0x1000); //64 buffer size
8979 #if defined(CONFIG_RTL8188E )&& defined (CONFIG_SDIO_HCI)
8980 BA_para_set = ((le16_to_cpu(pmlmeinfo->ADDBA_req.BA_para_set) & 0x3f) | 0x0800); //32buffer size
8982 BA_para_set = ((le16_to_cpu(pmlmeinfo->ADDBA_req.BA_para_set) & 0x3f) | 0x1000); //64 buffer size
8985 rtw_hal_get_def_var(padapter, HW_VAR_MAX_RX_AMPDU_FACTOR, &max_rx_ampdu_factor);
8986 if(MAX_AMPDU_FACTOR_64K == max_rx_ampdu_factor)
8987 BA_para_set = ((le16_to_cpu(pmlmeinfo->ADDBA_req.BA_para_set) & 0x3f) | 0x1000); //64 buffer size
8988 else if(MAX_AMPDU_FACTOR_32K == max_rx_ampdu_factor)
8989 BA_para_set = ((le16_to_cpu(pmlmeinfo->ADDBA_req.BA_para_set) & 0x3f) | 0x0800); //32 buffer size
8990 else if(MAX_AMPDU_FACTOR_16K == max_rx_ampdu_factor)
8991 BA_para_set = ((le16_to_cpu(pmlmeinfo->ADDBA_req.BA_para_set) & 0x3f) | 0x0400); //16 buffer size
8992 else if(MAX_AMPDU_FACTOR_8K == max_rx_ampdu_factor)
8993 BA_para_set = ((le16_to_cpu(pmlmeinfo->ADDBA_req.BA_para_set) & 0x3f) | 0x0200); //8 buffer size
8995 BA_para_set = ((le16_to_cpu(pmlmeinfo->ADDBA_req.BA_para_set) & 0x3f) | 0x1000); //64 buffer size
8997 #ifdef CONFIG_BT_COEXIST
8998 if (rtw_btcoex_IsBTCoexCtrlAMPDUSize(padapter) == _TRUE)
9000 // max buffer size is 8 MSDU
9001 BA_para_set &= ~RTW_IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK;
9002 BA_para_set |= (8 << 6) & RTW_IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK;
9006 if(pregpriv->ampdu_amsdu==0)//disabled
9007 BA_para_set = cpu_to_le16(BA_para_set & ~BIT(0));
9008 else if(pregpriv->ampdu_amsdu==1)//enabled
9009 BA_para_set = cpu_to_le16(BA_para_set | BIT(0));
9011 BA_para_set = cpu_to_le16(BA_para_set);
9013 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(BA_para_set)), &(pattrib->pktlen));
9014 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(pmlmeinfo->ADDBA_req.BA_timeout_value)), &(pattrib->pktlen));
9017 BA_para_set = (status & 0x1F) << 3;
9018 BA_para_set = cpu_to_le16(BA_para_set);
9019 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(BA_para_set)), &(pattrib->pktlen));
9021 reason_code = 37;//Requested from peer STA as it does not want to use the mechanism
9022 reason_code = cpu_to_le16(reason_code);
9023 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(reason_code)), &(pattrib->pktlen));
9030 pattrib->last_txcmdsz = pattrib->pktlen;
9032 dump_mgntframe(padapter, pmgntframe);
9033 #endif //CONFIG_80211N_HT
9036 static void issue_action_BSSCoexistPacket(_adapter *padapter)
9039 _list *plist, *phead;
9040 unsigned char category, action;
9041 struct xmit_frame *pmgntframe;
9042 struct pkt_attrib *pattrib;
9043 unsigned char *pframe;
9044 struct rtw_ieee80211_hdr *pwlanhdr;
9045 unsigned short *fctrl;
9046 struct wlan_network *pnetwork = NULL;
9047 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
9048 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
9049 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
9050 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
9051 _queue *queue = &(pmlmepriv->scanned_queue);
9052 u8 InfoContent[16] = {0};
9054 #ifdef CONFIG_80211N_HT
9055 if((pmlmepriv->num_FortyMHzIntolerant==0) || (pmlmepriv->num_sta_no_ht==0))
9058 if(_TRUE == pmlmeinfo->bwmode_updated)
9062 DBG_871X("%s\n", __FUNCTION__);
9065 category = RTW_WLAN_CATEGORY_PUBLIC;
9066 action = ACT_PUBLIC_BSSCOEXIST;
9068 if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
9074 pattrib = &pmgntframe->attrib;
9075 update_mgntframe_attrib(padapter, pattrib);
9077 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
9079 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
9080 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
9082 fctrl = &(pwlanhdr->frame_ctl);
9085 _rtw_memcpy(pwlanhdr->addr1, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
9086 _rtw_memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
9087 _rtw_memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
9089 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
9090 pmlmeext->mgnt_seq++;
9091 SetFrameSubType(pframe, WIFI_ACTION);
9093 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
9094 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
9096 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
9097 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
9101 if(pmlmepriv->num_FortyMHzIntolerant>0)
9105 iedata |= BIT(2);//20 MHz BSS Width Request
9107 pframe = rtw_set_ie(pframe, EID_BSSCoexistence, 1, &iedata, &(pattrib->pktlen));
9113 _rtw_memset(ICS, 0, sizeof(ICS));
9114 if(pmlmepriv->num_sta_no_ht>0)
9118 _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
9120 phead = get_list_head(queue);
9121 plist = get_next(phead);
9127 WLAN_BSSID_EX *pbss_network;
9129 if (rtw_end_of_queue_search(phead,plist)== _TRUE)
9132 pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
9134 plist = get_next(plist);
9136 pbss_network = (WLAN_BSSID_EX *)&pnetwork->network;
9138 p = rtw_get_ie(pbss_network->IEs + _FIXED_IE_LENGTH_, _HT_CAPABILITY_IE_, &len, pbss_network->IELength - _FIXED_IE_LENGTH_);
9139 if((p==NULL) || (len==0))//non-HT
9141 if((pbss_network->Configuration.DSConfig<=0) || (pbss_network->Configuration.DSConfig>14))
9144 ICS[0][pbss_network->Configuration.DSConfig]=1;
9152 _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
9162 //SET_BSS_INTOLERANT_ELE_REG_CLASS(InfoContent,i);
9171 InfoContent[k] = j; //channel number
9172 //SET_BSS_INTOLERANT_ELE_CHANNEL(InfoContent+k, j);
9178 pframe = rtw_set_ie(pframe, EID_BSSIntolerantChlReport, k, InfoContent, &(pattrib->pktlen));
9188 pattrib->last_txcmdsz = pattrib->pktlen;
9190 dump_mgntframe(padapter, pmgntframe);
9191 #endif //CONFIG_80211N_HT
9194 unsigned int send_delba(_adapter *padapter, u8 initiator, u8 *addr)
9196 struct sta_priv *pstapriv = &padapter->stapriv;
9197 struct sta_info *psta = NULL;
9198 //struct recv_reorder_ctrl *preorder_ctrl;
9199 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
9200 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
9203 if((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE)
9204 if (!(pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS))
9207 psta = rtw_get_stainfo(pstapriv, addr);
9211 //DBG_871X("%s:%s\n", __FUNCTION__, (initiator==0)?"RX_DIR":"TX_DIR");
9213 if(initiator==0) // recipient
9215 for(tid = 0;tid<MAXTID;tid++)
9217 if(psta->recvreorder_ctrl[tid].enable == _TRUE)
9219 DBG_871X("rx agg disable tid(%d)\n",tid);
9220 issue_action_BA(padapter, addr, RTW_WLAN_ACTION_DELBA, (((tid <<1) |initiator)&0x1F));
9221 psta->recvreorder_ctrl[tid].enable = _FALSE;
9222 psta->recvreorder_ctrl[tid].indicate_seq = 0xffff;
9224 DBG_871X("DBG_RX_SEQ %s:%d indicate_seq:%u \n", __FUNCTION__, __LINE__,
9225 psta->recvreorder_ctrl[tid].indicate_seq);
9230 else if(initiator == 1)// originator
9232 #ifdef CONFIG_80211N_HT
9233 //DBG_871X("tx agg_enable_bitmap(0x%08x)\n", psta->htpriv.agg_enable_bitmap);
9234 for(tid = 0;tid<MAXTID;tid++)
9236 if(psta->htpriv.agg_enable_bitmap & BIT(tid))
9238 DBG_871X("tx agg disable tid(%d)\n",tid);
9239 issue_action_BA(padapter, addr, RTW_WLAN_ACTION_DELBA, (((tid <<1) |initiator)&0x1F) );
9240 psta->htpriv.agg_enable_bitmap &= ~BIT(tid);
9241 psta->htpriv.candidate_tid_bitmap &= ~BIT(tid);
9245 #endif //CONFIG_80211N_HT
9252 unsigned int send_beacon(_adapter *padapter)
9254 u8 bxmitok = _FALSE;
9257 //#ifdef CONFIG_CONCURRENT_MODE
9258 //struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
9259 //struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
9260 //_adapter *pbuddy_adapter = padapter->pbuddy_adapter;
9261 //struct mlme_priv *pbuddy_mlmepriv = &(pbuddy_adapter->mlmepriv);
9264 #ifdef CONFIG_PCI_HCI
9266 //DBG_871X("%s\n", __FUNCTION__);
9268 issue_beacon(padapter, 0);
9274 #if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
9275 u32 start = rtw_get_current_time();
9277 rtw_hal_set_hwreg(padapter, HW_VAR_BCN_VALID, NULL);
9278 rtw_hal_set_hwreg(padapter, HW_VAR_DL_BCN_SEL, NULL);
9280 issue_beacon(padapter, 100);
9284 rtw_hal_get_hwreg(padapter, HW_VAR_BCN_VALID, (u8 *)(&bxmitok));
9286 }while((poll%10)!=0 && _FALSE == bxmitok && !padapter->bSurpriseRemoved && !padapter->bDriverStopped);
9288 }while(_FALSE == bxmitok && issue<100 && !padapter->bSurpriseRemoved && !padapter->bDriverStopped);
9290 if(padapter->bSurpriseRemoved || padapter->bDriverStopped)
9296 if(_FALSE == bxmitok)
9298 DBG_871X("%s fail! %u ms\n", __FUNCTION__, rtw_get_passing_time_ms(start));
9303 u32 passing_time = rtw_get_passing_time_ms(start);
9305 if(passing_time > 100 || issue > 3)
9306 DBG_871X("%s success, issue:%d, poll:%d, %u ms\n", __FUNCTION__, issue, poll, rtw_get_passing_time_ms(start));
9308 // DBG_871X("%s success, issue:%d, poll:%d, %u ms\n", __FUNCTION__, issue, poll, rtw_get_passing_time_ms(start));
9317 /****************************************************************************
9319 Following are some utitity fuctions for WiFi MLME
9321 *****************************************************************************/
9323 BOOLEAN IsLegal5GChannel(
9324 IN PADAPTER Adapter,
9329 u8 Channel_5G[45] = {36,38,40,42,44,46,48,50,52,54,56,58,
9330 60,62,64,100,102,104,106,108,110,112,114,116,118,120,122,
9331 124,126,128,130,132,134,136,138,140,149,151,153,155,157,159,
9333 for(i=0;i<sizeof(Channel_5G);i++)
9334 if(channel == Channel_5G[i])
9339 void site_survey(_adapter *padapter)
9341 unsigned char survey_channel = 0, val8;
9342 RT_SCAN_TYPE ScanType = SCAN_PASSIVE;
9343 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
9344 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
9345 u32 initialgain = 0;
9349 #ifdef CONFIG_CONCURRENT_MODE
9351 #if defined(CONFIG_STA_MODE_SCAN_UNDER_AP_MODE) || defined(CONFIG_ATMEL_RC_PATCH)
9352 u8 stay_buddy_ch = 0;
9354 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
9355 PADAPTER pbuddy_adapter = padapter->pbuddy_adapter;
9356 struct mlme_ext_priv *pbuddy_mlmeext = &pbuddy_adapter->mlmeextpriv;
9358 #endif //CONFIG_CONCURRENT_MODE
9359 struct wifidirect_info *pwdinfo= &(padapter->wdinfo);
9360 static unsigned char prev_survey_channel = 0;
9361 static unsigned int p2p_scan_count = 0;
9363 if ( ( pwdinfo->rx_invitereq_info.scan_op_ch_only ) || ( pwdinfo->p2p_info.scan_op_ch_only ) )
9365 if ( pwdinfo->rx_invitereq_info.scan_op_ch_only )
9367 survey_channel = pwdinfo->rx_invitereq_info.operation_ch[pmlmeext->sitesurvey_res.channel_idx];
9371 survey_channel = pwdinfo->p2p_info.operation_ch[pmlmeext->sitesurvey_res.channel_idx];
9373 ScanType = SCAN_ACTIVE;
9375 else if(rtw_p2p_findphase_ex_is_social(pwdinfo))
9377 // Commented by Albert 2011/06/03
9378 // The driver is in the find phase, it should go through the social channel.
9380 survey_channel = pwdinfo->social_chan[pmlmeext->sitesurvey_res.channel_idx];
9381 ch_set_idx = rtw_ch_set_search_ch(pmlmeext->channel_set, survey_channel);
9382 if (ch_set_idx >= 0)
9383 ScanType = pmlmeext->channel_set[ch_set_idx].ScanType;
9385 ScanType = SCAN_ACTIVE;
9390 struct rtw_ieee80211_channel *ch;
9391 if (pmlmeext->sitesurvey_res.channel_idx < pmlmeext->sitesurvey_res.ch_num) {
9392 ch = &pmlmeext->sitesurvey_res.ch[pmlmeext->sitesurvey_res.channel_idx];
9393 survey_channel = ch->hw_value;
9394 ScanType = (ch->flags & RTW_IEEE80211_CHAN_PASSIVE_SCAN) ? SCAN_PASSIVE : SCAN_ACTIVE;
9400 DBG_871X(FUNC_ADPT_FMT" ch:%u (cnt:%u,idx:%d) at %dms, %c%c%c\n"
9401 , FUNC_ADPT_ARG(padapter)
9403 , pwdinfo->find_phase_state_exchange_cnt, pmlmeext->sitesurvey_res.channel_idx
9404 , rtw_get_passing_time_ms(padapter->mlmepriv.scan_start_time)
9405 , ScanType?'A':'P', pmlmeext->sitesurvey_res.scan_mode?'A':'P'
9406 , pmlmeext->sitesurvey_res.ssid[0].SsidLength?'S':' '
9409 DBG_871X(FUNC_ADPT_FMT" ch:%u (cnt:%u) at %dms, %c%c%c\n"
9410 , FUNC_ADPT_ARG(padapter)
9412 , pmlmeext->sitesurvey_res.channel_idx
9413 , rtw_get_passing_time_ms(padapter->mlmepriv.scan_start_time)
9414 , ScanType?'A':'P', pmlmeext->sitesurvey_res.scan_mode?'A':'P'
9415 , pmlmeext->sitesurvey_res.ssid[0].SsidLength?'S':' '
9417 #endif // CONFIG_P2P
9418 #ifdef DBG_FIXED_CHAN
9419 DBG_871X(FUNC_ADPT_FMT" fixed_chan:%u\n", pmlmeext->fixed_chan);
9423 if(survey_channel != 0)
9425 //PAUSE 4-AC Queue when site_survey
9426 //rtw_hal_get_hwreg(padapter, HW_VAR_TXPAUSE, (u8 *)(&val8));
9428 //rtw_hal_set_hwreg(padapter, HW_VAR_TXPAUSE, (u8 *)(&val8));
9429 #if defined(CONFIG_STA_MODE_SCAN_UNDER_AP_MODE) || defined(CONFIG_ATMEL_RC_PATCH)
9430 if ((padapter->pbuddy_adapter->mlmeextpriv.mlmext_info.state&0x03) == WIFI_FW_AP_STATE) {
9431 if (pmlmeinfo->scan_cnt == RTW_SCAN_NUM_OF_CH) {
9432 if (pmlmeinfo->backop_cnt == 0)
9434 else if (pmlmeinfo->backop_cnt == RTW_STAY_AP_CH_MILLISECOND)
9437 if (stay_buddy_ch == 2) {
9438 pmlmeinfo->scan_cnt = 1;
9439 pmlmeinfo->backop_cnt = 0;
9440 } else if (stay_buddy_ch == 1) {
9441 pmlmeinfo->backop_cnt++;
9442 survey_channel = pbuddy_mlmeext->cur_channel;
9444 pmlmeinfo->backop_cnt++;
9445 set_survey_timer(pmlmeext, pmlmeext->chan_scan_time);
9449 pmlmeinfo->scan_cnt++;
9453 if(pmlmeext->sitesurvey_res.channel_idx == 0)
9455 #ifdef DBG_FIXED_CHAN
9456 if(pmlmeext->fixed_chan !=0xff)
9457 set_channel_bwmode(padapter, pmlmeext->fixed_chan, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
9460 set_channel_bwmode(padapter, survey_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
9464 #ifdef DBG_FIXED_CHAN
9465 if(pmlmeext->fixed_chan!=0xff)
9466 SelectChannel(padapter, pmlmeext->fixed_chan);
9469 SelectChannel(padapter, survey_channel);
9472 #if defined(CONFIG_STA_MODE_SCAN_UNDER_AP_MODE) || defined(CONFIG_ATMEL_RC_PATCH)
9473 if( stay_buddy_ch == 1 )
9475 val8 = 0; //survey done
9476 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_SITESURVEY, (u8 *)(&val8));
9478 if(check_buddy_mlmeinfo_state(padapter, WIFI_FW_AP_STATE) &&
9479 check_buddy_fwstate(padapter, _FW_LINKED))
9481 update_beacon(padapter->pbuddy_adapter, 0, NULL, _TRUE);
9484 else if( stay_buddy_ch == 2 )
9486 val8 = 1; //under site survey
9487 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_SITESURVEY, (u8 *)(&val8));
9491 if(ScanType == SCAN_ACTIVE) //obey the channel plan setting...
9494 if(rtw_p2p_chk_state(pwdinfo, P2P_STATE_SCAN) ||
9495 rtw_p2p_chk_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH)
9498 issue_probereq_p2p(padapter, NULL);
9499 issue_probereq_p2p(padapter, NULL);
9500 issue_probereq_p2p(padapter, NULL);
9506 for(i=0;i<RTW_SSID_SCAN_AMOUNT;i++){
9507 if(pmlmeext->sitesurvey_res.ssid[i].SsidLength) {
9508 /* IOT issue, When wifi_spec is not set, send one probe req without WPS IE. */
9509 if (padapter->registrypriv.wifi_spec)
9510 issue_probereq(padapter, &(pmlmeext->sitesurvey_res.ssid[i]), NULL);
9512 issue_probereq_ex(padapter, &(pmlmeext->sitesurvey_res.ssid[i]), NULL, 0, 0, 0, 0);
9513 issue_probereq(padapter, &(pmlmeext->sitesurvey_res.ssid[i]), NULL);
9517 if(pmlmeext->sitesurvey_res.scan_mode == SCAN_ACTIVE) {
9518 /* IOT issue, When wifi_spec is not set, send one probe req without WPS IE. */
9519 if (padapter->registrypriv.wifi_spec)
9520 issue_probereq(padapter, NULL, NULL);
9522 issue_probereq_ex(padapter, NULL, NULL, 0, 0, 0, 0);
9523 issue_probereq(padapter, NULL, NULL);
9527 #if defined(CONFIG_ATMEL_RC_PATCH)
9528 // treat wlan0 & p2p0 in same way, may be changed in near feature.
9529 // assume home channel is 6, channel switch sequence will be
9530 // 1,2-6-3,4-6-5,6-6-7,8-6-9,10-6-11,12-6-13,14
9531 //if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)==_TRUE)
9533 if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
9534 set_survey_timer(pmlmeext, 20);
9536 set_survey_timer(pmlmeext, 40);
9538 set_survey_timer(pmlmeext, pmlmeext->chan_scan_time);
9544 // channel number is 0 or this channel is not valid.
9546 #ifdef CONFIG_CONCURRENT_MODE
9551 if (rtw_get_ch_setting_union(padapter, &cur_channel, &cur_bwmode, &cur_ch_offset) != 0)
9554 DBG_871X(FUNC_ADPT_FMT" back to linked/linking union - ch:%u, bw:%u, offset:%u\n",
9555 FUNC_ADPT_ARG(padapter), cur_channel, cur_bwmode, cur_ch_offset);
9557 #ifdef CONFIG_IOCTL_CFG80211
9558 else if(padapter->pbuddy_adapter
9559 && pbuddy_adapter->wdinfo.driver_interface == DRIVER_CFG80211
9560 && adapter_wdev_data(pbuddy_adapter)->p2p_enabled
9561 && rtw_p2p_chk_state(&pbuddy_adapter->wdinfo, P2P_STATE_LISTEN)
9564 cur_channel = pbuddy_adapter->wdinfo.listen_channel;
9565 cur_bwmode = pbuddy_mlmeext->cur_bwmode;
9566 cur_ch_offset = pbuddy_mlmeext->cur_ch_offset;
9571 cur_channel = pmlmeext->cur_channel;
9572 cur_bwmode = pmlmeext->cur_bwmode;
9573 cur_ch_offset = pmlmeext->cur_ch_offset;
9579 if(rtw_p2p_chk_state(pwdinfo, P2P_STATE_SCAN) || rtw_p2p_chk_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH))
9581 if( ( pwdinfo->rx_invitereq_info.scan_op_ch_only ) || ( pwdinfo->p2p_info.scan_op_ch_only ) )
9583 // Set the find_phase_state_exchange_cnt to P2P_FINDPHASE_EX_CNT.
9584 // This will let the following flow to run the scanning end.
9585 rtw_p2p_findphase_ex_set(pwdinfo, P2P_FINDPHASE_EX_MAX);
9587 #ifdef CONFIG_DBG_P2P
9588 DBG_871X( "[%s] find phase exchange cnt = %d\n", __FUNCTION__, pwdinfo->find_phase_state_exchange_cnt );
9592 if(rtw_p2p_findphase_ex_is_needed(pwdinfo))
9594 // Set the P2P State to the listen state of find phase and set the current channel to the listen channel
9595 set_channel_bwmode(padapter, pwdinfo->listen_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
9596 rtw_p2p_set_state(pwdinfo, P2P_STATE_FIND_PHASE_LISTEN);
9597 pmlmeext->sitesurvey_res.state = SCAN_DISABLE;
9599 initialgain = 0xff; //restore RX GAIN
9600 rtw_hal_set_hwreg(padapter, HW_VAR_INITIAL_GAIN, (u8 *)(&initialgain));
9601 //turn on dynamic functions
9602 Restore_DM_Func_Flag(padapter);
9603 //Switch_DM_Func(padapter, DYNAMIC_FUNC_DIG|DYNAMIC_FUNC_HP|DYNAMIC_FUNC_SS, _TRUE);
9605 _set_timer( &pwdinfo->find_phase_timer, ( u32 ) ( ( u32 ) ( pwdinfo->listen_dwell ) * 100 ) );
9611 #if defined(CONFIG_STA_MODE_SCAN_UNDER_AP_MODE) || defined(CONFIG_ATMEL_RC_PATCH)
9612 pmlmeinfo->scan_cnt = 0;
9613 pmlmeinfo->backop_cnt = 0;
9616 #ifdef CONFIG_ANTENNA_DIVERSITY
9617 // 20100721:Interrupt scan operation here.
9618 // For SW antenna diversity before link, it needs to switch to another antenna and scan again.
9619 // It compares the scan result and select beter one to do connection.
9620 if(rtw_hal_antdiv_before_linked(padapter))
9622 pmlmeext->sitesurvey_res.bss_cnt = 0;
9623 pmlmeext->sitesurvey_res.channel_idx = -1;
9624 pmlmeext->chan_scan_time = SURVEY_TO /2;
9625 set_survey_timer(pmlmeext, pmlmeext->chan_scan_time);
9631 if(rtw_p2p_chk_state(pwdinfo, P2P_STATE_SCAN) || rtw_p2p_chk_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH))
9633 #ifdef CONFIG_CONCURRENT_MODE
9634 if( pwdinfo->driver_interface == DRIVER_WEXT )
9636 if ( check_buddy_fwstate(padapter, _FW_LINKED ) )
9638 _set_timer( &pwdinfo->ap_p2p_switch_timer, 500 );
9641 rtw_p2p_set_state(pwdinfo, rtw_p2p_pre_state(pwdinfo));
9643 rtw_p2p_set_state(pwdinfo, rtw_p2p_pre_state(pwdinfo));
9646 rtw_p2p_findphase_ex_set(pwdinfo, P2P_FINDPHASE_EX_NONE);
9649 pmlmeext->sitesurvey_res.state = SCAN_COMPLETE;
9651 //switch back to the original channel
9652 //SelectChannel(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset);
9655 #ifdef CONFIG_CONCURRENT_MODE
9656 set_channel_bwmode(padapter, cur_channel, cur_ch_offset, cur_bwmode);
9658 #ifdef CONFIG_DUALMAC_CONCURRENT
9659 dc_set_channel_bwmode_survey_done(padapter);
9663 if( (pwdinfo->driver_interface == DRIVER_WEXT) && (rtw_p2p_chk_state(pwdinfo, P2P_STATE_LISTEN)) )
9664 set_channel_bwmode(padapter, pwdinfo->listen_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
9667 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
9669 #endif //CONFIG_DUALMAC_CONCURRENT
9670 #endif //CONFIG_CONCURRENT_MODE
9673 //flush 4-AC Queue after site_survey
9675 //rtw_hal_set_hwreg(padapter, HW_VAR_TXPAUSE, (u8 *)(&val8));
9678 Set_MSR(padapter, (pmlmeinfo->state & 0x3));
9680 initialgain = 0xff; //restore RX GAIN
9681 rtw_hal_set_hwreg(padapter, HW_VAR_INITIAL_GAIN, (u8 *)(&initialgain));
9682 //turn on dynamic functions
9683 Restore_DM_Func_Flag(padapter);
9684 //Switch_DM_Func(padapter, DYNAMIC_ALL_FUNC_ENABLE, _TRUE);
9686 if (is_client_associated_to_ap(padapter) == _TRUE)
9688 issue_nulldata(padapter, NULL, 0, 3, 500);
9690 #ifdef CONFIG_CONCURRENT_MODE
9691 if(is_client_associated_to_ap(padapter->pbuddy_adapter) == _TRUE)
9693 DBG_871X("adapter is surveydone(buddy_adapter is linked), issue nulldata(pwrbit=0)\n");
9695 issue_nulldata(padapter->pbuddy_adapter, NULL, 0, 3, 500);
9699 #ifdef CONFIG_CONCURRENT_MODE
9700 else if(is_client_associated_to_ap(padapter->pbuddy_adapter) == _TRUE)
9702 issue_nulldata(padapter->pbuddy_adapter, NULL, 0, 3, 500);
9706 val8 = 0; //survey done
9707 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_SITESURVEY, (u8 *)(&val8));
9709 report_surveydone_event(padapter);
9711 pmlmeext->chan_scan_time = SURVEY_TO;
9712 pmlmeext->sitesurvey_res.state = SCAN_DISABLE;
9714 issue_action_BSSCoexistPacket(padapter);
9715 issue_action_BSSCoexistPacket(padapter);
9716 issue_action_BSSCoexistPacket(padapter);
9720 #ifdef CONFIG_CONCURRENT_MODE
9721 if(check_buddy_mlmeinfo_state(padapter, WIFI_FW_AP_STATE) &&
9722 check_buddy_fwstate(padapter, _FW_LINKED))
9725 DBG_871X("survey done, current CH=%d, BW=%d, offset=%d\n", cur_channel, cur_bwmode, cur_ch_offset);
9727 DBG_871X("restart pbuddy_adapter's beacon\n");
9729 update_beacon(padapter->pbuddy_adapter, 0, NULL, _TRUE);
9739 //collect bss info from Beacon and Probe request/response frames.
9740 u8 collect_bss_info(_adapter *padapter, union recv_frame *precv_frame, WLAN_BSSID_EX *bssid)
9746 u8 *pframe = precv_frame->u.hdr.rx_data;
9747 u32 packet_len = precv_frame->u.hdr.len;
9749 struct registry_priv *pregistrypriv = &padapter->registrypriv;
9750 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
9751 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
9753 len = packet_len - sizeof(struct rtw_ieee80211_hdr_3addr);
9755 if (len > MAX_IE_SZ)
9757 //DBG_871X("IE too long for survey event\n");
9761 _rtw_memset(bssid, 0, sizeof(WLAN_BSSID_EX));
9763 subtype = GetFrameSubType(pframe);
9765 if(subtype==WIFI_BEACON) {
9766 bssid->Reserved[0] = 1;
9767 ie_offset = _BEACON_IE_OFFSET_;
9769 // FIXME : more type
9770 if (subtype == WIFI_PROBERSP) {
9771 ie_offset = _PROBERSP_IE_OFFSET_;
9772 bssid->Reserved[0] = 3;
9774 else if (subtype == WIFI_PROBEREQ) {
9775 ie_offset = _PROBEREQ_IE_OFFSET_;
9776 bssid->Reserved[0] = 2;
9779 bssid->Reserved[0] = 0;
9780 ie_offset = _FIXED_IE_LENGTH_;
9784 bssid->Length = sizeof(WLAN_BSSID_EX) - MAX_IE_SZ + len;
9786 //below is to copy the information element
9787 bssid->IELength = len;
9788 _rtw_memcpy(bssid->IEs, (pframe + sizeof(struct rtw_ieee80211_hdr_3addr)), bssid->IELength);
9790 //get the signal strength
9791 //bssid->Rssi = precv_frame->u.hdr.attrib.SignalStrength; // 0-100 index.
9792 bssid->Rssi = precv_frame->u.hdr.attrib.phy_info.RecvSignalPower; // in dBM.raw data
9793 bssid->PhyInfo.SignalQuality = precv_frame->u.hdr.attrib.phy_info.SignalQuality;//in percentage
9794 bssid->PhyInfo.SignalStrength = precv_frame->u.hdr.attrib.phy_info.SignalStrength;//in percentage
9795 #ifdef CONFIG_ANTENNA_DIVERSITY
9796 //rtw_hal_get_hwreg(padapter, HW_VAR_CURRENT_ANTENNA, (u8 *)(&bssid->PhyInfo.Optimum_antenna));
9797 rtw_hal_get_def_var(padapter, HAL_DEF_CURRENT_ANTENNA, &bssid->PhyInfo.Optimum_antenna);
9801 if ((p = rtw_get_ie(bssid->IEs + ie_offset, _SSID_IE_, &len, bssid->IELength - ie_offset)) == NULL)
9803 DBG_871X("marc: cannot find SSID for survey event\n");
9809 if (len > NDIS_802_11_LENGTH_SSID)
9811 DBG_871X("%s()-%d: IE too long (%d) for survey event\n", __FUNCTION__, __LINE__, len);
9814 _rtw_memcpy(bssid->Ssid.Ssid, (p + 2), *(p + 1));
9815 bssid->Ssid.SsidLength = *(p + 1);
9819 bssid->Ssid.SsidLength = 0;
9822 _rtw_memset(bssid->SupportedRates, 0, NDIS_802_11_LENGTH_RATES_EX);
9824 //checking rate info...
9826 p = rtw_get_ie(bssid->IEs + ie_offset, _SUPPORTEDRATES_IE_, &len, bssid->IELength - ie_offset);
9829 if (len > NDIS_802_11_LENGTH_RATES_EX)
9831 DBG_871X("%s()-%d: IE too long (%d) for survey event\n", __FUNCTION__, __LINE__, len);
9834 _rtw_memcpy(bssid->SupportedRates, (p + 2), len);
9838 p = rtw_get_ie(bssid->IEs + ie_offset, _EXT_SUPPORTEDRATES_IE_, &len, bssid->IELength - ie_offset);
9841 if (len > (NDIS_802_11_LENGTH_RATES_EX-i))
9843 DBG_871X("%s()-%d: IE too long (%d) for survey event\n", __FUNCTION__, __LINE__, len);
9846 _rtw_memcpy(bssid->SupportedRates + i, (p + 2), len);
9851 if (judge_network_type(bssid->SupportedRates, (len + i)) == WIRELESS_11B)
9853 bssid->NetworkTypeInUse = Ndis802_11DS;
9858 bssid->NetworkTypeInUse = Ndis802_11OFDM24;
9862 if (subtype == WIFI_PROBEREQ)
9866 // Set Listion Channel
9867 if ((p2p_ie = rtw_get_p2p_ie(bssid->IEs, bssid->IELength, NULL, &p2p_ielen)))
9869 u32 attr_contentlen = 0;
9870 u8 listen_ch[5] = { 0x00 };
9872 if (rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_LISTEN_CH, listen_ch, &attr_contentlen) != NULL)
9873 bssid->Configuration.DSConfig = listen_ch[4];
9875 return _FALSE; // Intel device maybe no bring Listen Channel
9877 { // use current channel
9878 bssid->Configuration.DSConfig = padapter->mlmeextpriv.cur_channel;
9879 DBG_871X("%s()-%d: Cannot get p2p_ie. set DSconfig to op_ch(%d)\n", __FUNCTION__, __LINE__, bssid->Configuration.DSConfig);
9883 bssid->InfrastructureMode = Ndis802_11Infrastructure;
9884 _rtw_memcpy(bssid->MacAddress, GetAddr2Ptr(pframe), ETH_ALEN);
9890 if (bssid->IELength < 12)
9893 // Checking for DSConfig
9894 p = rtw_get_ie(bssid->IEs + ie_offset, _DSSET_IE_, &len, bssid->IELength - ie_offset);
9896 bssid->Configuration.DSConfig = 0;
9897 bssid->Configuration.Length = 0;
9901 bssid->Configuration.DSConfig = *(p + 2);
9904 {// In 5G, some ap do not have DSSET IE
9905 // checking HT info for channel
9906 p = rtw_get_ie(bssid->IEs + ie_offset, _HT_ADD_INFO_IE_, &len, bssid->IELength - ie_offset);
9909 struct HT_info_element *HT_info = (struct HT_info_element *)(p + 2);
9910 bssid->Configuration.DSConfig = HT_info->primary_channel;
9913 { // use current channel
9914 bssid->Configuration.DSConfig = rtw_get_oper_ch(padapter);
9918 _rtw_memcpy(&bssid->Configuration.BeaconPeriod, rtw_get_beacon_interval_from_ie(bssid->IEs), 2);
9919 bssid->Configuration.BeaconPeriod = le32_to_cpu(bssid->Configuration.BeaconPeriod);
9921 val16 = rtw_get_capability((WLAN_BSSID_EX *)bssid);
9925 bssid->InfrastructureMode = Ndis802_11Infrastructure;
9926 _rtw_memcpy(bssid->MacAddress, GetAddr2Ptr(pframe), ETH_ALEN);
9930 bssid->InfrastructureMode = Ndis802_11IBSS;
9931 _rtw_memcpy(bssid->MacAddress, GetAddr3Ptr(pframe), ETH_ALEN);
9939 bssid->Configuration.ATIMWindow = 0;
9941 //20/40 BSS Coexistence check
9942 if((pregistrypriv->wifi_spec==1) && (_FALSE == pmlmeinfo->bwmode_updated))
9944 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
9945 #ifdef CONFIG_80211N_HT
9946 p = rtw_get_ie(bssid->IEs + ie_offset, _HT_CAPABILITY_IE_, &len, bssid->IELength - ie_offset);
9949 struct HT_caps_element *pHT_caps;
9950 pHT_caps = (struct HT_caps_element *)(p + 2);
9952 if(pHT_caps->u.HT_cap_element.HT_caps_info&BIT(14))
9954 pmlmepriv->num_FortyMHzIntolerant++;
9959 pmlmepriv->num_sta_no_ht++;
9961 #endif //CONFIG_80211N_HT
9965 #ifdef CONFIG_INTEL_WIDI
9966 //process_intel_widi_query_or_tigger(padapter, bssid);
9967 if(process_intel_widi_query_or_tigger(padapter, bssid))
9971 #endif // CONFIG_INTEL_WIDI
9973 #if defined(DBG_RX_SIGNAL_DISPLAY_SSID_MONITORED) & 1
9974 if(strcmp(bssid->Ssid.Ssid, DBG_RX_SIGNAL_DISPLAY_SSID_MONITORED) == 0) {
9975 DBG_871X("Receiving %s("MAC_FMT", DSConfig:%u) from ch%u with ss:%3u, sq:%3u, RawRSSI:%3ld\n"
9976 , bssid->Ssid.Ssid, MAC_ARG(bssid->MacAddress), bssid->Configuration.DSConfig
9977 , rtw_get_oper_ch(padapter)
9978 , bssid->PhyInfo.SignalStrength, bssid->PhyInfo.SignalQuality, bssid->Rssi
9983 // mark bss info receving from nearby channel as SignalQuality 101
9984 if(bssid->Configuration.DSConfig != rtw_get_oper_ch(padapter))
9986 bssid->PhyInfo.SignalQuality= 101;
9992 void start_create_ibss(_adapter* padapter)
9994 unsigned short caps;
9997 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
9998 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
9999 WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX*)(&(pmlmeinfo->network));
10000 pmlmeext->cur_channel = (u8)pnetwork->Configuration.DSConfig;
10001 pmlmeinfo->bcn_interval = get_beacon_interval(pnetwork);
10003 //update wireless mode
10004 update_wireless_mode(padapter);
10006 //udpate capability
10007 caps = rtw_get_capability((WLAN_BSSID_EX *)pnetwork);
10008 update_capinfo(padapter, caps);
10009 if(caps&cap_IBSS)//adhoc master
10011 //set_opmode_cmd(padapter, adhoc);//removed
10014 rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8));
10016 rtw_hal_set_hwreg(padapter, HW_VAR_DO_IQK, NULL);
10019 //SelectChannel(padapter, pmlmeext->cur_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE);
10020 set_channel_bwmode(padapter, pmlmeext->cur_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
10022 beacon_timing_control(padapter);
10024 //set msr to WIFI_FW_ADHOC_STATE
10025 pmlmeinfo->state = WIFI_FW_ADHOC_STATE;
10026 Set_MSR(padapter, (pmlmeinfo->state & 0x3));
10029 if(send_beacon(padapter)==_FAIL)
10031 RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("issuing beacon frame fail....\n"));
10033 report_join_res(padapter, -1);
10034 pmlmeinfo->state = WIFI_FW_NULL_STATE;
10038 rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, padapter->registrypriv.dev_network.MacAddress);
10040 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type));
10042 report_join_res(padapter, 1);
10043 pmlmeinfo->state |= WIFI_FW_ASSOC_SUCCESS;
10044 rtw_indicate_connect(padapter);
10049 DBG_871X("start_create_ibss, invalid cap:%x\n", caps);
10052 //update bc/mc sta_info
10053 update_bmc_sta(padapter);
10057 void start_clnt_join(_adapter* padapter)
10059 unsigned short caps;
10061 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
10062 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
10063 WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX*)(&(pmlmeinfo->network));
10064 int beacon_timeout;
10066 //update wireless mode
10067 update_wireless_mode(padapter);
10069 //udpate capability
10070 caps = rtw_get_capability((WLAN_BSSID_EX *)pnetwork);
10071 update_capinfo(padapter, caps);
10074 Set_MSR(padapter, WIFI_FW_STATION_STATE);
10076 val8 = (pmlmeinfo->auth_algo == dot11AuthAlgrthm_8021X)? 0xcc: 0xcf;
10078 #ifdef CONFIG_WAPI_SUPPORT
10079 if (padapter->wapiInfo.bWapiEnable && pmlmeinfo->auth_algo == dot11AuthAlgrthm_WAPI)
10081 //Disable TxUseDefaultKey, RxUseDefaultKey, RxBroadcastUseDefaultKey.
10085 rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8));
10087 #ifdef CONFIG_DEAUTH_BEFORE_CONNECT
10088 // Because of AP's not receiving deauth before
10089 // AP may: 1)not response auth or 2)deauth us after link is complete
10090 // issue deauth before issuing auth to deal with the situation
10092 // Commented by Albert 2012/07/21
10093 // For the Win8 P2P connection, it will be hard to have a successful connection if this Wi-Fi doesn't connect to it.
10096 _queue *queue = &(padapter->mlmepriv.scanned_queue);
10097 _list *head = get_list_head(queue);
10098 _list *pos = get_next(head);
10099 struct wlan_network *scanned = NULL;
10102 bool has_p2p_ie = _FALSE;
10104 _enter_critical_bh(&(padapter->mlmepriv.scanned_queue.lock), &irqL);
10106 for (pos = get_next(head);!rtw_end_of_queue_search(head, pos); pos = get_next(pos)) {
10108 scanned = LIST_CONTAINOR(pos, struct wlan_network, list);
10112 if (_rtw_memcmp(&(scanned->network.Ssid), &(pnetwork->Ssid), sizeof(NDIS_802_11_SSID)) == _TRUE
10113 && _rtw_memcmp(scanned->network.MacAddress, pnetwork->MacAddress, sizeof(NDIS_802_11_MAC_ADDRESS)) == _TRUE
10115 ie_offset = (scanned->network.Reserved[0] == 2? 0:12);
10116 if (rtw_get_p2p_ie(scanned->network.IEs+ie_offset, scanned->network.IELength-ie_offset, NULL, NULL))
10117 has_p2p_ie = _TRUE;
10122 _exit_critical_bh(&(padapter->mlmepriv.scanned_queue.lock), &irqL);
10124 if (scanned == NULL || rtw_end_of_queue_search(head, pos) || has_p2p_ie == _FALSE)
10125 #endif /* CONFIG_P2P */
10126 //To avoid connecting to AP fail during resume process, change retry count from 5 to 1
10127 issue_deauth_ex(padapter, pnetwork->MacAddress, WLAN_REASON_DEAUTH_LEAVING, 1, 100);
10129 #endif /* CONFIG_DEAUTH_BEFORE_CONNECT */
10131 //here wait for receiving the beacon to start auth
10132 //and enable a timer
10133 beacon_timeout = decide_wait_for_beacon_timeout(pmlmeinfo->bcn_interval);
10134 set_link_timer(pmlmeext, beacon_timeout);
10135 _set_timer( &padapter->mlmepriv.assoc_timer,
10136 (REAUTH_TO * REAUTH_LIMIT) + (REASSOC_TO*REASSOC_LIMIT) +beacon_timeout);
10138 pmlmeinfo->state = WIFI_FW_AUTH_NULL | WIFI_FW_STATION_STATE;
10140 else if (caps&cap_IBSS) //adhoc client
10142 Set_MSR(padapter, WIFI_FW_ADHOC_STATE);
10145 rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8));
10147 beacon_timing_control(padapter);
10149 pmlmeinfo->state = WIFI_FW_ADHOC_STATE;
10151 report_join_res(padapter, 1);
10155 //DBG_871X("marc: invalid cap:%x\n", caps);
10161 void start_clnt_auth(_adapter* padapter)
10163 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
10164 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
10166 _cancel_timer_ex(&pmlmeext->link_timer);
10168 pmlmeinfo->state &= (~WIFI_FW_AUTH_NULL);
10169 pmlmeinfo->state |= WIFI_FW_AUTH_STATE;
10171 pmlmeinfo->auth_seq = 1;
10172 pmlmeinfo->reauth_count = 0;
10173 pmlmeinfo->reassoc_count = 0;
10174 pmlmeinfo->link_count = 0;
10175 pmlmeext->retry = 0;
10178 DBG_871X_LEVEL(_drv_always_, "start auth\n");
10179 issue_auth(padapter, NULL, 0);
10181 set_link_timer(pmlmeext, REAUTH_TO);
10186 void start_clnt_assoc(_adapter* padapter)
10188 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
10189 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
10191 _cancel_timer_ex(&pmlmeext->link_timer);
10193 pmlmeinfo->state &= (~(WIFI_FW_AUTH_NULL | WIFI_FW_AUTH_STATE));
10194 pmlmeinfo->state |= (WIFI_FW_AUTH_SUCCESS | WIFI_FW_ASSOC_STATE);
10196 issue_assocreq(padapter);
10198 set_link_timer(pmlmeext, REASSOC_TO);
10201 unsigned int receive_disconnect(_adapter *padapter, unsigned char *MacAddr, unsigned short reason)
10203 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
10204 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
10206 if (!(_rtw_memcmp(MacAddr, get_my_bssid(&pmlmeinfo->network), ETH_ALEN)))
10209 DBG_871X("%s\n", __FUNCTION__);
10211 if((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE)
10213 if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS)
10215 pmlmeinfo->state = WIFI_FW_NULL_STATE;
10216 report_del_sta_event(padapter, MacAddr, reason);
10219 else if (pmlmeinfo->state & WIFI_FW_LINKING_STATE)
10221 pmlmeinfo->state = WIFI_FW_NULL_STATE;
10222 report_join_res(padapter, -2);
10229 #ifdef CONFIG_80211D
10230 static void process_80211d(PADAPTER padapter, WLAN_BSSID_EX *bssid)
10232 struct registry_priv *pregistrypriv;
10233 struct mlme_ext_priv *pmlmeext;
10234 RT_CHANNEL_INFO *chplan_new;
10239 pregistrypriv = &padapter->registrypriv;
10240 pmlmeext = &padapter->mlmeextpriv;
10242 // Adjust channel plan by AP Country IE
10243 if (pregistrypriv->enable80211d &&
10244 (!pmlmeext->update_channel_plan_by_ap_done))
10248 RT_CHANNEL_PLAN chplan_ap;
10249 RT_CHANNEL_INFO chplan_sta[MAX_CHANNEL_NUM];
10251 u8 fcn; // first channel number
10252 u8 noc; // number of channel
10255 ie = rtw_get_ie(bssid->IEs + _FIXED_IE_LENGTH_, _COUNTRY_IE_, &len, bssid->IELength - _FIXED_IE_LENGTH_);
10257 if (len < 6) return;
10263 _rtw_memset(country, 0, 4);
10264 _rtw_memcpy(country, p, 3);
10266 RT_TRACE(_module_rtl871x_mlme_c_, _drv_notice_,
10267 ("%s: 802.11d country=%s\n", __FUNCTION__, country));
10270 while ((ie - p) >= 3)
10276 for (j = 0; j < noc; j++)
10278 if (fcn <= 14) channel = fcn + j; // 2.4 GHz
10279 else channel = fcn + j*4; // 5 GHz
10281 chplan_ap.Channel[i++] = channel;
10286 #ifdef CONFIG_DEBUG_RTL871X
10288 DBG_871X("%s: AP[%s] channel plan {", __FUNCTION__, bssid->Ssid.Ssid);
10289 while ((i < chplan_ap.Len) && (chplan_ap.Channel[i] != 0))
10291 DBG_8192C("%02d,", chplan_ap.Channel[i]);
10297 _rtw_memcpy(chplan_sta, pmlmeext->channel_set, sizeof(chplan_sta));
10298 #ifdef CONFIG_DEBUG_RTL871X
10300 DBG_871X("%s: STA channel plan {", __FUNCTION__);
10301 while ((i < MAX_CHANNEL_NUM) && (chplan_sta[i].ChannelNum != 0))
10303 DBG_871X("%02d(%c),", chplan_sta[i].ChannelNum, chplan_sta[i].ScanType==SCAN_PASSIVE?'p':'a');
10309 _rtw_memset(pmlmeext->channel_set, 0, sizeof(pmlmeext->channel_set));
10310 chplan_new = pmlmeext->channel_set;
10313 if (pregistrypriv->wireless_mode & WIRELESS_11G)
10316 if ((i == MAX_CHANNEL_NUM) ||
10317 (chplan_sta[i].ChannelNum == 0) ||
10318 (chplan_sta[i].ChannelNum > 14))
10321 if ((j == chplan_ap.Len) || (chplan_ap.Channel[j] > 14))
10324 if (chplan_sta[i].ChannelNum == chplan_ap.Channel[j])
10326 chplan_new[k].ChannelNum = chplan_ap.Channel[j];
10327 chplan_new[k].ScanType = SCAN_ACTIVE;
10332 else if (chplan_sta[i].ChannelNum < chplan_ap.Channel[j])
10334 chplan_new[k].ChannelNum = chplan_sta[i].ChannelNum;
10335 // chplan_new[k].ScanType = chplan_sta[i].ScanType;
10336 chplan_new[k].ScanType = SCAN_PASSIVE;
10340 else if (chplan_sta[i].ChannelNum > chplan_ap.Channel[j])
10342 chplan_new[k].ChannelNum = chplan_ap.Channel[j];
10343 chplan_new[k].ScanType = SCAN_ACTIVE;
10349 // change AP not support channel to Passive scan
10350 while ((i < MAX_CHANNEL_NUM) &&
10351 (chplan_sta[i].ChannelNum != 0) &&
10352 (chplan_sta[i].ChannelNum <= 14))
10354 chplan_new[k].ChannelNum = chplan_sta[i].ChannelNum;
10355 // chplan_new[k].ScanType = chplan_sta[i].ScanType;
10356 chplan_new[k].ScanType = SCAN_PASSIVE;
10361 // add channel AP supported
10362 while ((j < chplan_ap.Len) && (chplan_ap.Channel[j] <= 14))
10364 chplan_new[k].ChannelNum = chplan_ap.Channel[j];
10365 chplan_new[k].ScanType = SCAN_ACTIVE;
10372 // keep original STA 2.4G channel plan
10373 while ((i < MAX_CHANNEL_NUM) &&
10374 (chplan_sta[i].ChannelNum != 0) &&
10375 (chplan_sta[i].ChannelNum <= 14))
10377 chplan_new[k].ChannelNum = chplan_sta[i].ChannelNum;
10378 chplan_new[k].ScanType = chplan_sta[i].ScanType;
10383 // skip AP 2.4G channel plan
10384 while ((j < chplan_ap.Len) && (chplan_ap.Channel[j] <= 14))
10390 if (pregistrypriv->wireless_mode & WIRELESS_11A)
10393 if ((i == MAX_CHANNEL_NUM) ||
10394 (chplan_sta[i].ChannelNum == 0))
10397 if ((j == chplan_ap.Len) || (chplan_ap.Channel[j] == 0))
10400 if (chplan_sta[i].ChannelNum == chplan_ap.Channel[j])
10402 chplan_new[k].ChannelNum = chplan_ap.Channel[j];
10403 chplan_new[k].ScanType = SCAN_ACTIVE;
10408 else if (chplan_sta[i].ChannelNum < chplan_ap.Channel[j])
10410 chplan_new[k].ChannelNum = chplan_sta[i].ChannelNum;
10411 // chplan_new[k].ScanType = chplan_sta[i].ScanType;
10412 chplan_new[k].ScanType = SCAN_PASSIVE;
10416 else if (chplan_sta[i].ChannelNum > chplan_ap.Channel[j])
10418 chplan_new[k].ChannelNum = chplan_ap.Channel[j];
10419 chplan_new[k].ScanType = SCAN_ACTIVE;
10425 // change AP not support channel to Passive scan
10426 while ((i < MAX_CHANNEL_NUM) && (chplan_sta[i].ChannelNum != 0))
10428 chplan_new[k].ChannelNum = chplan_sta[i].ChannelNum;
10429 // chplan_new[k].ScanType = chplan_sta[i].ScanType;
10430 chplan_new[k].ScanType = SCAN_PASSIVE;
10435 // add channel AP supported
10436 while ((j < chplan_ap.Len) && (chplan_ap.Channel[j] != 0))
10438 chplan_new[k].ChannelNum = chplan_ap.Channel[j];
10439 chplan_new[k].ScanType = SCAN_ACTIVE;
10446 // keep original STA 5G channel plan
10447 while ((i < MAX_CHANNEL_NUM) && (chplan_sta[i].ChannelNum != 0))
10449 chplan_new[k].ChannelNum = chplan_sta[i].ChannelNum;
10450 chplan_new[k].ScanType = chplan_sta[i].ScanType;
10456 pmlmeext->update_channel_plan_by_ap_done = 1;
10458 #ifdef CONFIG_DEBUG_RTL871X
10460 DBG_871X("%s: new STA channel plan {", __FUNCTION__);
10461 while ((k < MAX_CHANNEL_NUM) && (chplan_new[k].ChannelNum != 0))
10463 DBG_871X("%02d(%c),", chplan_new[k].ChannelNum, chplan_new[k].ScanType==SCAN_PASSIVE?'p':'c');
10470 // recover the right channel index
10471 channel = chplan_sta[pmlmeext->sitesurvey_res.channel_idx].ChannelNum;
10473 while ((k < MAX_CHANNEL_NUM) && (chplan_new[k].ChannelNum != 0))
10475 if (chplan_new[k].ChannelNum == channel) {
10476 RT_TRACE(_module_rtl871x_mlme_c_, _drv_notice_,
10477 ("%s: change mlme_ext sitesurvey channel index from %d to %d\n",
10478 __FUNCTION__, pmlmeext->sitesurvey_res.channel_idx, k));
10479 pmlmeext->sitesurvey_res.channel_idx = k;
10487 // If channel is used by AP, set channel scan type to active
10488 channel = bssid->Configuration.DSConfig;
10489 chplan_new = pmlmeext->channel_set;
10491 while ((i < MAX_CHANNEL_NUM) && (chplan_new[i].ChannelNum != 0))
10493 if (chplan_new[i].ChannelNum == channel)
10495 if (chplan_new[i].ScanType == SCAN_PASSIVE)
10497 //5G Bnad 2, 3 (DFS) doesn't change to active scan
10498 if(channel >= 52 && channel <= 144)
10501 chplan_new[i].ScanType = SCAN_ACTIVE;
10502 RT_TRACE(_module_rtl871x_mlme_c_, _drv_notice_,
10503 ("%s: change channel %d scan type from passive to active\n",
10504 __FUNCTION__, channel));
10513 /****************************************************************************
10515 Following are the functions to report events
10517 *****************************************************************************/
10519 void report_survey_event(_adapter *padapter, union recv_frame *precv_frame)
10521 struct cmd_obj *pcmd_obj;
10524 struct survey_event *psurvey_evt;
10525 struct C2HEvent_Header *pc2h_evt_hdr;
10526 struct mlme_ext_priv *pmlmeext;
10527 struct cmd_priv *pcmdpriv;
10528 //u8 *pframe = precv_frame->u.hdr.rx_data;
10529 //uint len = precv_frame->u.hdr.len;
10534 pmlmeext = &padapter->mlmeextpriv;
10535 pcmdpriv = &padapter->cmdpriv;
10538 if ((pcmd_obj = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj))) == NULL)
10543 cmdsz = (sizeof(struct survey_event) + sizeof(struct C2HEvent_Header));
10544 if ((pevtcmd = (u8*)rtw_zmalloc(cmdsz)) == NULL)
10546 rtw_mfree((u8 *)pcmd_obj, sizeof(struct cmd_obj));
10550 _rtw_init_listhead(&pcmd_obj->list);
10552 pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
10553 pcmd_obj->cmdsz = cmdsz;
10554 pcmd_obj->parmbuf = pevtcmd;
10556 pcmd_obj->rsp = NULL;
10557 pcmd_obj->rspsz = 0;
10559 pc2h_evt_hdr = (struct C2HEvent_Header*)(pevtcmd);
10560 pc2h_evt_hdr->len = sizeof(struct survey_event);
10561 pc2h_evt_hdr->ID = GEN_EVT_CODE(_Survey);
10562 pc2h_evt_hdr->seq = ATOMIC_INC_RETURN(&pmlmeext->event_seq);
10564 psurvey_evt = (struct survey_event*)(pevtcmd + sizeof(struct C2HEvent_Header));
10566 if (collect_bss_info(padapter, precv_frame, (WLAN_BSSID_EX *)&psurvey_evt->bss) == _FAIL)
10568 rtw_mfree((u8 *)pcmd_obj, sizeof(struct cmd_obj));
10569 rtw_mfree((u8 *)pevtcmd, cmdsz);
10573 #ifdef CONFIG_80211D
10574 process_80211d(padapter, &psurvey_evt->bss);
10577 rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
10579 pmlmeext->sitesurvey_res.bss_cnt++;
10585 void report_surveydone_event(_adapter *padapter)
10587 struct cmd_obj *pcmd_obj;
10590 struct surveydone_event *psurveydone_evt;
10591 struct C2HEvent_Header *pc2h_evt_hdr;
10592 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
10593 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
10595 if ((pcmd_obj = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj))) == NULL)
10600 cmdsz = (sizeof(struct surveydone_event) + sizeof(struct C2HEvent_Header));
10601 if ((pevtcmd = (u8*)rtw_zmalloc(cmdsz)) == NULL)
10603 rtw_mfree((u8 *)pcmd_obj, sizeof(struct cmd_obj));
10607 _rtw_init_listhead(&pcmd_obj->list);
10609 pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
10610 pcmd_obj->cmdsz = cmdsz;
10611 pcmd_obj->parmbuf = pevtcmd;
10613 pcmd_obj->rsp = NULL;
10614 pcmd_obj->rspsz = 0;
10616 pc2h_evt_hdr = (struct C2HEvent_Header*)(pevtcmd);
10617 pc2h_evt_hdr->len = sizeof(struct surveydone_event);
10618 pc2h_evt_hdr->ID = GEN_EVT_CODE(_SurveyDone);
10619 pc2h_evt_hdr->seq = ATOMIC_INC_RETURN(&pmlmeext->event_seq);
10621 psurveydone_evt = (struct surveydone_event*)(pevtcmd + sizeof(struct C2HEvent_Header));
10622 psurveydone_evt->bss_cnt = pmlmeext->sitesurvey_res.bss_cnt;
10624 DBG_871X("survey done event(%x) band:%d for "ADPT_FMT"\n", psurveydone_evt->bss_cnt, padapter->setband, ADPT_ARG(padapter));
10626 rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
10632 void report_join_res(_adapter *padapter, int res)
10634 struct cmd_obj *pcmd_obj;
10637 struct joinbss_event *pjoinbss_evt;
10638 struct C2HEvent_Header *pc2h_evt_hdr;
10639 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
10640 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
10641 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
10643 if ((pcmd_obj = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj))) == NULL)
10648 cmdsz = (sizeof(struct joinbss_event) + sizeof(struct C2HEvent_Header));
10649 if ((pevtcmd = (u8*)rtw_zmalloc(cmdsz)) == NULL)
10651 rtw_mfree((u8 *)pcmd_obj, sizeof(struct cmd_obj));
10655 _rtw_init_listhead(&pcmd_obj->list);
10657 pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
10658 pcmd_obj->cmdsz = cmdsz;
10659 pcmd_obj->parmbuf = pevtcmd;
10661 pcmd_obj->rsp = NULL;
10662 pcmd_obj->rspsz = 0;
10664 pc2h_evt_hdr = (struct C2HEvent_Header*)(pevtcmd);
10665 pc2h_evt_hdr->len = sizeof(struct joinbss_event);
10666 pc2h_evt_hdr->ID = GEN_EVT_CODE(_JoinBss);
10667 pc2h_evt_hdr->seq = ATOMIC_INC_RETURN(&pmlmeext->event_seq);
10669 pjoinbss_evt = (struct joinbss_event*)(pevtcmd + sizeof(struct C2HEvent_Header));
10670 _rtw_memcpy((unsigned char *)(&(pjoinbss_evt->network.network)), &(pmlmeinfo->network), sizeof(WLAN_BSSID_EX));
10671 pjoinbss_evt->network.join_res = pjoinbss_evt->network.aid = res;
10673 DBG_871X("report_join_res(%d)\n", res);
10676 rtw_joinbss_event_prehandle(padapter, (u8 *)&pjoinbss_evt->network);
10679 rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
10685 void report_del_sta_event(_adapter *padapter, unsigned char* MacAddr, unsigned short reason)
10687 struct cmd_obj *pcmd_obj;
10690 struct sta_info *psta;
10692 struct stadel_event *pdel_sta_evt;
10693 struct C2HEvent_Header *pc2h_evt_hdr;
10694 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
10695 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
10697 if ((pcmd_obj = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj))) == NULL)
10702 cmdsz = (sizeof(struct stadel_event) + sizeof(struct C2HEvent_Header));
10703 if ((pevtcmd = (u8*)rtw_zmalloc(cmdsz)) == NULL)
10705 rtw_mfree((u8 *)pcmd_obj, sizeof(struct cmd_obj));
10709 _rtw_init_listhead(&pcmd_obj->list);
10711 pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
10712 pcmd_obj->cmdsz = cmdsz;
10713 pcmd_obj->parmbuf = pevtcmd;
10715 pcmd_obj->rsp = NULL;
10716 pcmd_obj->rspsz = 0;
10718 pc2h_evt_hdr = (struct C2HEvent_Header*)(pevtcmd);
10719 pc2h_evt_hdr->len = sizeof(struct stadel_event);
10720 pc2h_evt_hdr->ID = GEN_EVT_CODE(_DelSTA);
10721 pc2h_evt_hdr->seq = ATOMIC_INC_RETURN(&pmlmeext->event_seq);
10723 pdel_sta_evt = (struct stadel_event*)(pevtcmd + sizeof(struct C2HEvent_Header));
10724 _rtw_memcpy((unsigned char *)(&(pdel_sta_evt->macaddr)), MacAddr, ETH_ALEN);
10725 _rtw_memcpy((unsigned char *)(pdel_sta_evt->rsvd),(unsigned char *)(&reason),2);
10728 psta = rtw_get_stainfo(&padapter->stapriv, MacAddr);
10730 mac_id = (int)psta->mac_id;
10734 pdel_sta_evt->mac_id = mac_id;
10736 DBG_871X("report_del_sta_event: delete STA, mac_id=%d\n", mac_id);
10738 rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
10743 void report_add_sta_event(_adapter *padapter, unsigned char* MacAddr, int cam_idx)
10745 struct cmd_obj *pcmd_obj;
10748 struct stassoc_event *padd_sta_evt;
10749 struct C2HEvent_Header *pc2h_evt_hdr;
10750 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
10751 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
10753 if ((pcmd_obj = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj))) == NULL)
10758 cmdsz = (sizeof(struct stassoc_event) + sizeof(struct C2HEvent_Header));
10759 if ((pevtcmd = (u8*)rtw_zmalloc(cmdsz)) == NULL)
10761 rtw_mfree((u8 *)pcmd_obj, sizeof(struct cmd_obj));
10765 _rtw_init_listhead(&pcmd_obj->list);
10767 pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
10768 pcmd_obj->cmdsz = cmdsz;
10769 pcmd_obj->parmbuf = pevtcmd;
10771 pcmd_obj->rsp = NULL;
10772 pcmd_obj->rspsz = 0;
10774 pc2h_evt_hdr = (struct C2HEvent_Header*)(pevtcmd);
10775 pc2h_evt_hdr->len = sizeof(struct stassoc_event);
10776 pc2h_evt_hdr->ID = GEN_EVT_CODE(_AddSTA);
10777 pc2h_evt_hdr->seq = ATOMIC_INC_RETURN(&pmlmeext->event_seq);
10779 padd_sta_evt = (struct stassoc_event*)(pevtcmd + sizeof(struct C2HEvent_Header));
10780 _rtw_memcpy((unsigned char *)(&(padd_sta_evt->macaddr)), MacAddr, ETH_ALEN);
10781 padd_sta_evt->cam_id = cam_idx;
10783 DBG_871X("report_add_sta_event: add STA\n");
10785 rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
10791 bool rtw_port_switch_chk(_adapter *adapter)
10793 bool switch_needed = _FALSE;
10794 #ifdef CONFIG_CONCURRENT_MODE
10795 #ifdef CONFIG_RUNTIME_PORT_SWITCH
10796 struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
10797 struct pwrctrl_priv *pwrctl = dvobj_to_pwrctl(dvobj);
10798 _adapter *if_port0 = NULL;
10799 _adapter *if_port1 = NULL;
10800 struct mlme_ext_info *if_port0_mlmeinfo = NULL;
10801 struct mlme_ext_info *if_port1_mlmeinfo = NULL;
10804 for (i = 0; i < dvobj->iface_nums; i++) {
10805 if (get_iface_type(dvobj->padapters[i]) == IFACE_PORT0) {
10806 if_port0 = dvobj->padapters[i];
10807 if_port0_mlmeinfo = &(if_port0->mlmeextpriv.mlmext_info);
10809 else if (get_iface_type(dvobj->padapters[i]) == IFACE_PORT1) {
10810 if_port1 = dvobj->padapters[i];
10811 if_port1_mlmeinfo = &(if_port1->mlmeextpriv.mlmext_info);
10815 if (if_port0 == NULL) {
10820 if (if_port1 == NULL) {
10825 #ifdef DBG_RUNTIME_PORT_SWITCH
10826 DBG_871X(FUNC_ADPT_FMT" wowlan_mode:%u\n"
10827 ADPT_FMT", port0, mlmeinfo->state:0x%08x, p2p_state:%d, %d\n"
10828 ADPT_FMT", port1, mlmeinfo->state:0x%08x, p2p_state:%d, %d\n",
10829 FUNC_ADPT_ARG(adapter), pwrctl->wowlan_mode,
10830 ADPT_ARG(if_port0), if_port0_mlmeinfo->state, rtw_p2p_state(&if_port0->wdinfo), rtw_p2p_chk_state(&if_port0->wdinfo, P2P_STATE_NONE),
10831 ADPT_ARG(if_port1), if_port1_mlmeinfo->state, rtw_p2p_state(&if_port1->wdinfo), rtw_p2p_chk_state(&if_port1->wdinfo, P2P_STATE_NONE));
10832 #endif /* DBG_RUNTIME_PORT_SWITCH */
10834 #ifdef CONFIG_WOWLAN
10835 /* WOWLAN interface(primary, for now) should be port0 */
10836 if (pwrctl->wowlan_mode == _TRUE) {
10837 if(!is_primary_adapter(if_port0)) {
10838 DBG_871X("%s "ADPT_FMT" enable WOWLAN\n", __func__, ADPT_ARG(if_port1));
10839 switch_needed = _TRUE;
10843 #endif /* CONFIG_WOWLAN */
10845 /* AP should use port0 for ctl frame's ack */
10846 if ((if_port1_mlmeinfo->state & 0x03) == WIFI_FW_AP_STATE) {
10847 DBG_871X("%s "ADPT_FMT" is AP/GO\n", __func__, ADPT_ARG(if_port1));
10848 switch_needed = _TRUE;
10852 /* GC should use port0 for p2p ps */
10853 if (((if_port1_mlmeinfo->state & 0x03) == WIFI_FW_STATION_STATE)
10854 && (if_port1_mlmeinfo->state & WIFI_FW_ASSOC_SUCCESS)
10855 && !rtw_p2p_chk_state(&if_port1->wdinfo, P2P_STATE_NONE)
10856 && !check_fwstate(&if_port1->mlmepriv, WIFI_UNDER_WPS)
10858 DBG_871X("%s "ADPT_FMT" is GC\n", __func__, ADPT_ARG(if_port1));
10859 switch_needed = _TRUE;
10863 /* port1 linked, but port0 not linked */
10864 if ((if_port1_mlmeinfo->state & WIFI_FW_ASSOC_SUCCESS)
10865 && !(if_port0_mlmeinfo->state & WIFI_FW_ASSOC_SUCCESS)
10866 && ((if_port0_mlmeinfo->state & 0x03) != WIFI_FW_AP_STATE)
10868 DBG_871X("%s "ADPT_FMT" is SINGLE_LINK\n", __func__, ADPT_ARG(if_port1));
10869 switch_needed = _TRUE;
10874 #ifdef DBG_RUNTIME_PORT_SWITCH
10875 DBG_871X(FUNC_ADPT_FMT" ret:%d\n", FUNC_ADPT_ARG(adapter), switch_needed);
10876 #endif /* DBG_RUNTIME_PORT_SWITCH */
10877 #endif /* CONFIG_RUNTIME_PORT_SWITCH */
10878 #endif /* CONFIG_CONCURRENT_MODE */
10879 return switch_needed;
10882 /****************************************************************************
10884 Following are the event callback functions
10886 *****************************************************************************/
10888 //for sta/adhoc mode
10889 void update_sta_info(_adapter *padapter, struct sta_info *psta)
10892 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
10893 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
10894 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
10897 VCS_update(padapter, psta);
10899 #ifdef CONFIG_80211N_HT
10901 if(pmlmepriv->htpriv.ht_option)
10903 psta->htpriv.ht_option = _TRUE;
10905 psta->htpriv.ampdu_enable = pmlmepriv->htpriv.ampdu_enable;
10907 if (support_short_GI(padapter, &(pmlmeinfo->HT_caps), CHANNEL_WIDTH_20))
10908 psta->htpriv.sgi_20m = _TRUE;
10910 if (support_short_GI(padapter, &(pmlmeinfo->HT_caps), CHANNEL_WIDTH_40))
10911 psta->htpriv.sgi_40m = _TRUE;
10913 psta->qos_option = _TRUE;
10915 psta->htpriv.ldpc_cap = pmlmepriv->htpriv.ldpc_cap;
10916 psta->htpriv.stbc_cap = pmlmepriv->htpriv.stbc_cap;
10917 psta->htpriv.beamform_cap = pmlmepriv->htpriv.beamform_cap;
10919 _rtw_memcpy(&psta->htpriv.ht_cap, &pmlmeinfo->HT_caps, sizeof(struct rtw_ieee80211_ht_cap));
10922 #endif //CONFIG_80211N_HT
10924 #ifdef CONFIG_80211N_HT
10925 psta->htpriv.ht_option = _FALSE;
10927 psta->htpriv.ampdu_enable = _FALSE;
10929 psta->htpriv.sgi_20m = _FALSE;
10930 psta->htpriv.sgi_40m = _FALSE;
10931 #endif //CONFIG_80211N_HT
10932 psta->qos_option = _FALSE;
10936 #ifdef CONFIG_80211N_HT
10937 psta->htpriv.ch_offset = pmlmeext->cur_ch_offset;
10939 psta->htpriv.agg_enable_bitmap = 0x0;//reset
10940 psta->htpriv.candidate_tid_bitmap = 0x0;//reset
10941 #endif //CONFIG_80211N_HT
10943 psta->bw_mode = pmlmeext->cur_bwmode;
10946 if(pmlmepriv->qospriv.qos_option)
10947 psta->qos_option = _TRUE;
10949 #ifdef CONFIG_80211AC_VHT
10950 _rtw_memcpy(&psta->vhtpriv, &pmlmepriv->vhtpriv, sizeof(struct vht_priv));
10951 #endif //CONFIG_80211AC_VHT
10953 update_ldpc_stbc_cap(psta);
10955 _enter_critical_bh(&psta->lock, &irqL);
10956 psta->state = _FW_LINKED;
10957 _exit_critical_bh(&psta->lock, &irqL);
10961 static void rtw_mlmeext_disconnect(_adapter *padapter)
10963 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
10964 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
10965 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
10966 WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX*)(&(pmlmeinfo->network));
10967 u8 state_backup = (pmlmeinfo->state&0x03);
10969 //set_opmode_cmd(padapter, infra_client_with_mlme);
10973 * For safety, prevent from keeping macid sleep.
10974 * If we can sure all power mode enter/leave are paired,
10975 * this check can be removed.
10978 /* wakeup macid after disconnect. */
10980 struct sta_info *psta;
10981 psta = rtw_get_stainfo(&padapter->stapriv, get_my_bssid(pnetwork));
10983 rtw_hal_macid_wakeup(padapter, psta->mac_id);
10987 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_DISCONNECT, 0);
10988 rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, null_addr);
10990 //set MSR to no link state -> infra. mode
10991 Set_MSR(padapter, _HW_STATE_STATION_);
10993 pmlmeinfo->state = WIFI_FW_NULL_STATE;
10995 if(state_backup == WIFI_FW_STATION_STATE)
10997 if (rtw_port_switch_chk(padapter) == _TRUE) {
10998 rtw_hal_set_hwreg(padapter, HW_VAR_PORT_SWITCH, NULL);
11001 _adapter *port0_iface = dvobj_get_port0_adapter(adapter_to_dvobj(padapter));
11003 rtw_lps_ctrl_wk_cmd(port0_iface, LPS_CTRL_CONNECT, 0);
11009 #ifdef CONFIG_DUALMAC_CONCURRENT
11010 dc_set_channel_bwmode_disconnect(padapter);
11011 #else //!CONFIG_DUALMAC_CONCURRENT
11012 #ifdef CONFIG_CONCURRENT_MODE
11013 if((check_buddy_fwstate(padapter, _FW_LINKED)) != _TRUE)
11015 #endif //CONFIG_CONCURRENT_MODE
11016 //switch to the 20M Hz mode after disconnect
11017 pmlmeext->cur_bwmode = CHANNEL_WIDTH_20;
11018 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
11020 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
11021 #ifdef CONFIG_CONCURRENT_MODE
11023 #endif //CONFIG_CONCURRENT_MODE
11024 #ifdef CONFIG_FCS_MODE
11027 PADAPTER pbuddy_adapter;
11028 struct mlme_ext_priv *pbuddy_mlmeext;
11030 if(EN_FCS(padapter))
11032 pbuddy_adapter = padapter->pbuddy_adapter;
11033 pbuddy_mlmeext = &pbuddy_adapter->mlmeextpriv;
11035 rtw_hal_set_hwreg(padapter, HW_VAR_STOP_FCS_MODE, NULL);
11037 //switch to buddy's channel setting if buddy is linked
11038 set_channel_bwmode(padapter, pbuddy_mlmeext->cur_channel, pbuddy_mlmeext->cur_ch_offset, pbuddy_mlmeext->cur_bwmode);
11041 #endif //!CONFIG_FCS_MODE
11042 #endif //!CONFIG_DUALMAC_CONCURRENT
11045 flush_all_cam_entry(padapter);
11047 _cancel_timer_ex(&pmlmeext->link_timer);
11049 //pmlmepriv->LinkDetectInfo.TrafficBusyState = _FALSE;
11050 pmlmepriv->LinkDetectInfo.TrafficTransitionCount = 0;
11051 pmlmepriv->LinkDetectInfo.LowPowerTransitionCount = 0;
11055 void mlmeext_joinbss_event_callback(_adapter *padapter, int join_res)
11057 struct sta_info *psta, *psta_bmc;
11058 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
11059 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
11060 WLAN_BSSID_EX *cur_network = &(pmlmeinfo->network);
11061 struct sta_priv *pstapriv = &padapter->stapriv;
11067 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type));
11068 rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, null_addr);
11070 goto exit_mlmeext_joinbss_event_callback;
11073 if((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE)
11075 //update bc/mc sta_info
11076 update_bmc_sta(padapter);
11080 //turn on dynamic functions
11081 Switch_DM_Func(padapter, DYNAMIC_ALL_FUNC_ENABLE, _TRUE);
11083 // update IOT-releated issue
11084 update_IOT_info(padapter);
11086 rtw_hal_set_hwreg(padapter, HW_VAR_BASIC_RATE, cur_network->SupportedRates);
11089 rtw_hal_set_hwreg(padapter, HW_VAR_BEACON_INTERVAL, (u8 *)(&pmlmeinfo->bcn_interval));
11091 //udpate capability
11092 update_capinfo(padapter, pmlmeinfo->capability);
11094 //WMM, Update EDCA param
11095 WMMOnAssocRsp(padapter);
11098 HTOnAssocRsp(padapter);
11100 #ifdef CONFIG_80211AC_VHT
11102 VHTOnAssocRsp(padapter);
11105 #ifndef CONFIG_CONCURRENT_MODE
11106 // Call set_channel_bwmode when the CONFIG_CONCURRENT_MODE doesn't be defined.
11107 //Set cur_channel&cur_bwmode&cur_ch_offset
11108 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
11111 psta = rtw_get_stainfo(pstapriv, cur_network->MacAddress);
11112 if (psta) //only for infra. mode
11114 pmlmeinfo->FW_sta_info[psta->mac_id].psta = psta;
11116 //DBG_871X("set_sta_rate\n");
11118 psta->wireless_mode = pmlmeext->cur_wireless_mode;
11120 //set per sta rate after updating HT cap.
11121 set_sta_rate(padapter, psta);
11123 rtw_sta_media_status_rpt(padapter, psta, 1);
11125 /* wakeup macid after join bss successfully to ensure
11126 the subsequent data frames can be sent out normally */
11127 rtw_hal_macid_wakeup(padapter, psta->mac_id);
11130 if (rtw_port_switch_chk(padapter) == _TRUE)
11131 rtw_hal_set_hwreg(padapter, HW_VAR_PORT_SWITCH, NULL);
11134 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type));
11136 if((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE)
11139 correct_TSF(padapter, pmlmeext);
11141 //set_link_timer(pmlmeext, DISCONNECT_TO);
11145 if(get_iface_type(padapter) == IFACE_PORT0)
11146 rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_CONNECT, 0);
11149 #ifdef CONFIG_BEAMFORMING
11151 beamforming_wk_cmd(padapter, BEAMFORMING_CTRL_ENTER, (u8 *)psta, sizeof(struct sta_info), 0);
11154 exit_mlmeext_joinbss_event_callback:
11156 #ifdef CONFIG_DUALMAC_CONCURRENT
11157 dc_handle_join_done(padapter, join_res);
11159 #ifdef CONFIG_CONCURRENT_MODE
11160 concurrent_chk_joinbss_done(padapter, join_res);
11163 DBG_871X("=>%s\n", __FUNCTION__);
11167 //currently only adhoc mode will go here
11168 void mlmeext_sta_add_event_callback(_adapter *padapter, struct sta_info *psta)
11170 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
11171 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
11174 DBG_871X("%s\n", __FUNCTION__);
11176 if((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE)
11178 if(pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS)//adhoc master or sta_count>1
11185 //update_TSF(pmlmeext, pframe, len);
11188 correct_TSF(padapter, pmlmeext);
11191 if(send_beacon(padapter)==_FAIL)
11193 pmlmeinfo->FW_sta_info[psta->mac_id].status = 0;
11195 pmlmeinfo->state ^= WIFI_FW_ADHOC_STATE;
11200 pmlmeinfo->state |= WIFI_FW_ASSOC_SUCCESS;
11205 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type));
11208 pmlmeinfo->FW_sta_info[psta->mac_id].psta = psta;
11210 psta->bssratelen = rtw_get_rateset_len(pmlmeinfo->FW_sta_info[psta->mac_id].SupportedRates);
11211 _rtw_memcpy(psta->bssrateset, pmlmeinfo->FW_sta_info[psta->mac_id].SupportedRates, psta->bssratelen);
11213 //update adhoc sta_info
11214 update_sta_info(padapter, psta);
11216 rtw_hal_update_sta_rate_mask(padapter, psta);
11218 // ToDo: HT for Ad-hoc
11219 psta->wireless_mode = rtw_check_network_type(psta->bssrateset, psta->bssratelen, pmlmeext->cur_channel);
11220 psta->raid = rtw_hal_networktype_to_raid(padapter, psta);
11223 Update_RA_Entry(padapter, psta);
11226 void mlmeext_sta_del_event_callback(_adapter *padapter)
11228 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
11229 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
11231 if (is_client_associated_to_ap(padapter) || is_IBSS_empty(padapter))
11233 rtw_mlmeext_disconnect(padapter);
11238 /****************************************************************************
11240 Following are the functions for the timer handlers
11242 *****************************************************************************/
11243 void _linked_info_dump(_adapter *padapter)
11246 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
11247 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
11249 int UndecoratedSmoothedPWDB;
11250 struct dvobj_priv *pdvobj = adapter_to_dvobj(padapter);
11252 if(padapter->bLinkInfoDump){
11254 DBG_871X("\n============["ADPT_FMT"] linked status check ===================\n",ADPT_ARG(padapter));
11256 if((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE)
11258 rtw_hal_get_def_var(padapter, HAL_DEF_UNDERCORATEDSMOOTHEDPWDB, &UndecoratedSmoothedPWDB);
11260 DBG_871X("AP[" MAC_FMT "] - UndecoratedSmoothedPWDB:%d\n",
11261 MAC_ARG(padapter->mlmepriv.cur_network.network.MacAddress),UndecoratedSmoothedPWDB);
11263 else if((pmlmeinfo->state&0x03) == _HW_STATE_AP_)
11266 _list *phead, *plist;
11268 struct sta_info *psta=NULL;
11269 struct sta_priv *pstapriv = &padapter->stapriv;
11271 _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
11272 phead = &pstapriv->asoc_list;
11273 plist = get_next(phead);
11274 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE)
11276 psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
11277 plist = get_next(plist);
11279 DBG_871X("STA[" MAC_FMT "]:UndecoratedSmoothedPWDB:%d\n",
11280 MAC_ARG(psta->hwaddr),psta->rssi_stat.UndecoratedSmoothedPWDB);
11282 _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
11285 for(i=0; i<NUM_STA; i++)
11287 if(pdvobj->macid[i] == _TRUE)
11289 if(i !=1) //skip bc/mc sta
11290 //============ tx info ============
11291 rtw_hal_get_def_var(padapter, HW_DEF_RA_INFO_DUMP, &i);
11294 rtw_hal_set_def_var(padapter, HAL_DEF_DBG_RX_INFO_DUMP, NULL);
11302 u8 chk_ap_is_alive(_adapter *padapter, struct sta_info *psta)
11305 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
11306 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
11308 #ifdef DBG_EXPIRATION_CHK
11309 DBG_871X(FUNC_ADPT_FMT" rx:"STA_PKTS_FMT", beacon:%llu, probersp_to_self:%llu"
11310 /*", probersp_bm:%llu, probersp_uo:%llu, probereq:%llu, BI:%u"*/
11312 , FUNC_ADPT_ARG(padapter)
11313 , STA_RX_PKTS_DIFF_ARG(psta)
11314 , psta->sta_stats.rx_beacon_pkts - psta->sta_stats.last_rx_beacon_pkts
11315 , psta->sta_stats.rx_probersp_pkts - psta->sta_stats.last_rx_probersp_pkts
11316 /*, psta->sta_stats.rx_probersp_bm_pkts - psta->sta_stats.last_rx_probersp_bm_pkts
11317 , psta->sta_stats.rx_probersp_uo_pkts - psta->sta_stats.last_rx_probersp_uo_pkts
11318 , psta->sta_stats.rx_probereq_pkts - psta->sta_stats.last_rx_probereq_pkts
11319 , pmlmeinfo->bcn_interval*/
11323 DBG_871X(FUNC_ADPT_FMT" tx_pkts:%llu, link_count:%u\n", FUNC_ADPT_ARG(padapter)
11324 , padapter->xmitpriv.tx_pkts
11325 , pmlmeinfo->link_count
11329 if((sta_rx_data_pkts(psta) == sta_last_rx_data_pkts(psta))
11330 && sta_rx_beacon_pkts(psta) == sta_last_rx_beacon_pkts(psta)
11331 && sta_rx_probersp_pkts(psta) == sta_last_rx_probersp_pkts(psta)
11341 sta_update_last_rx_pkts(psta);
11347 void linked_status_chk_tdls(_adapter *padapter)
11349 struct candidate_pool{
11350 struct sta_info *psta;
11353 struct sta_priv *pstapriv = &padapter->stapriv;
11356 struct sta_info *psta;
11357 int i, num_teardown=0, num_checkalive=0;
11358 _list *plist, *phead;
11359 struct tdls_txmgmt txmgmt;
11360 struct candidate_pool checkalive[NUM_STA];
11361 struct candidate_pool teardown[NUM_STA];
11362 #define ALIVE_MIN 2
11363 #define ALIVE_MAX 5
11365 _rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
11366 _rtw_memset(checkalive, 0x00, sizeof(checkalive));
11367 _rtw_memset(teardown, 0x00, sizeof(teardown));
11369 if((padapter->tdlsinfo.link_established == _TRUE)){
11370 _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
11371 for(i=0; i< NUM_STA; i++)
11373 phead = &(pstapriv->sta_hash[i]);
11374 plist = get_next(phead);
11376 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE)
11378 psta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
11379 plist = get_next(plist);
11381 if(psta->tdls_sta_state & TDLS_LINKED_STATE)
11383 psta->alive_count++;
11384 if(psta->alive_count >= ALIVE_MIN)
11386 #ifdef CONFIG_XMIT_ACK
11387 if(psta->sta_stats.last_rx_data_pkts >= psta->sta_stats.rx_data_pkts)
11389 if((psta->sta_stats.last_rx_data_pkts >= psta->sta_stats.rx_data_pkts) &&
11390 (!(psta->tdls_sta_state & TDLS_ALIVE_STATE)) )
11393 if(psta->alive_count < ALIVE_MAX)
11395 _rtw_memcpy(checkalive[num_checkalive].addr, psta->hwaddr, ETH_ALEN);
11396 checkalive[num_checkalive].psta = psta;
11401 _rtw_memcpy(teardown[num_teardown].addr, psta->hwaddr, ETH_ALEN);
11402 teardown[num_teardown].psta = psta;
11408 psta->tdls_sta_state &= (~TDLS_ALIVE_STATE);
11409 psta->alive_count = 0;
11412 psta->sta_stats.last_rx_data_pkts = psta->sta_stats.rx_data_pkts;
11416 _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
11418 if(num_checkalive > 0)
11420 for(i=0; i< num_checkalive; i++)
11422 #ifdef CONFIG_XMIT_ACK
11423 //TDLS: Should we set wait_ms to 300 for keeping alive?
11424 ack_chk = issue_nulldata_to_TDLS_peer_STA(padapter, checkalive[i].addr, 0, 3, 300);
11426 if(ack_chk == _SUCCESS)
11428 checkalive[i].psta->alive_count = 0;
11431 checkalive[i].psta->tdls_sta_state &= (~TDLS_ALIVE_STATE);
11432 _rtw_memcpy(txmgmt.peer, checkalive[i].addr, ETH_ALEN);
11433 issue_tdls_dis_req(padapter, &txmgmt);
11434 issue_tdls_dis_req(padapter, &txmgmt);
11435 issue_tdls_dis_req(padapter, &txmgmt);
11436 #endif //CONFIG_XMIT_ACK
11440 if(num_teardown > 0)
11442 for(i=0; i< num_teardown; i++)
11444 DBG_871X("[%s %d] Send teardown to "MAC_FMT" \n", __FUNCTION__, __LINE__, MAC_ARG(teardown[i].addr));
11445 txmgmt.status_code = _RSON_TDLS_TEAR_TOOFAR_;
11446 _rtw_memcpy(txmgmt.peer, teardown[i].addr, ETH_ALEN);
11447 issue_tdls_teardown(padapter, &txmgmt, _FALSE);
11453 #endif //CONFIG_TDLS
11455 void linked_status_chk(_adapter *padapter)
11458 struct sta_info *psta;
11459 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
11460 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
11461 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
11462 struct sta_priv *pstapriv = &padapter->stapriv;
11465 if (is_client_associated_to_ap(padapter))
11467 //linked infrastructure client mode
11469 int tx_chk = _SUCCESS, rx_chk = _SUCCESS;
11471 int link_count_limit;
11473 #if defined(DBG_ROAMING_TEST)
11475 #elif defined(CONFIG_ACTIVE_KEEP_ALIVE_CHECK) && !defined(CONFIG_LPS_LCLK_WD_TIMER)
11481 if (!rtw_p2p_chk_state(&padapter->wdinfo, P2P_STATE_NONE))
11482 link_count_limit = 3; // 8 sec
11484 #endif // CONFIG_P2P
11485 link_count_limit = 7; // 16 sec
11487 // Marked by Kurt 20130715
11488 // For WiDi 3.5 and latered on, they don't ask WiDi sink to do roaming, so we could not check rx limit that strictly.
11489 // todo: To check why we under miracast session, rx_chk would be _FALSE
11490 //#ifdef CONFIG_INTEL_WIDI
11491 //if (padapter->mlmepriv.widi_state != INTEL_WIDI_STATE_NONE)
11492 // rx_chk_limit = 1;
11495 if ((psta = rtw_get_stainfo(pstapriv, pmlmeinfo->network.MacAddress)) != NULL)
11497 bool is_p2p_enable = _FALSE;
11499 is_p2p_enable = !rtw_p2p_chk_state(&padapter->wdinfo, P2P_STATE_NONE);
11502 if (chk_ap_is_alive(padapter, psta) == _FALSE)
11505 if (pxmitpriv->last_tx_pkts == pxmitpriv->tx_pkts)
11508 #if defined(CONFIG_ACTIVE_KEEP_ALIVE_CHECK) && !defined(CONFIG_LPS_LCLK_WD_TIMER)
11509 if (pmlmeext->active_keep_alive_check && (rx_chk == _FAIL || tx_chk == _FAIL)) {
11510 u8 backup_oper_channel=0;
11512 /* switch to correct channel of current network before issue keep-alive frames */
11513 if (rtw_get_oper_ch(padapter) != pmlmeext->cur_channel) {
11514 backup_oper_channel = rtw_get_oper_ch(padapter);
11515 SelectChannel(padapter, pmlmeext->cur_channel);
11518 if (rx_chk != _SUCCESS)
11519 issue_probereq_ex(padapter, &pmlmeinfo->network.Ssid, psta->hwaddr, 0, 0, 3, 1);
11521 if ((tx_chk != _SUCCESS && pmlmeinfo->link_count++ == link_count_limit) || rx_chk != _SUCCESS) {
11522 tx_chk = issue_nulldata(padapter, psta->hwaddr, 0, 3, 1);
11523 /* if tx acked and p2p disabled, set rx_chk _SUCCESS to reset retry count */
11524 if (tx_chk == _SUCCESS && !is_p2p_enable)
11528 /* back to the original operation channel */
11529 if(backup_oper_channel>0)
11530 SelectChannel(padapter, backup_oper_channel);
11534 #endif /* CONFIG_ACTIVE_KEEP_ALIVE_CHECK */
11536 if (rx_chk != _SUCCESS) {
11537 if (pmlmeext->retry == 0) {
11538 #ifdef DBG_EXPIRATION_CHK
11539 DBG_871X("issue_probereq to trigger probersp, retry=%d\n", pmlmeext->retry);
11541 issue_probereq_ex(padapter, &pmlmeinfo->network.Ssid, pmlmeinfo->network.MacAddress, 0, 0, 0, 0);
11542 issue_probereq_ex(padapter, &pmlmeinfo->network.Ssid, pmlmeinfo->network.MacAddress, 0, 0, 0, 0);
11543 issue_probereq_ex(padapter, &pmlmeinfo->network.Ssid, pmlmeinfo->network.MacAddress, 0, 0, 0, 0);
11547 if (tx_chk != _SUCCESS && pmlmeinfo->link_count++ == link_count_limit) {
11548 #ifdef DBG_EXPIRATION_CHK
11549 DBG_871X("%s issue_nulldata 0\n", __FUNCTION__);
11551 tx_chk = issue_nulldata_in_interrupt(padapter, NULL);
11555 if (rx_chk == _FAIL) {
11557 if (pmlmeext->retry > rx_chk_limit) {
11558 DBG_871X_LEVEL(_drv_always_, FUNC_ADPT_FMT" disconnect or roaming\n",
11559 FUNC_ADPT_ARG(padapter));
11560 receive_disconnect(padapter, pmlmeinfo->network.MacAddress
11561 , WLAN_REASON_EXPIRATION_CHK);
11565 pmlmeext->retry = 0;
11568 if (tx_chk == _FAIL) {
11569 pmlmeinfo->link_count %= (link_count_limit+1);
11571 pxmitpriv->last_tx_pkts = pxmitpriv->tx_pkts;
11572 pmlmeinfo->link_count = 0;
11575 } //end of if ((psta = rtw_get_stainfo(pstapriv, passoc_res->network.MacAddress)) != NULL)
11577 #if defined (CONFIG_TDLS) && defined (CONFIG_TDLS_AUTOCHECKALIVE)
11578 linked_status_chk_tdls(padapter);
11579 #endif //CONFIG_TDLS
11582 else if (is_client_associated_to_ibss(padapter))
11585 //for each assoc list entry to check the rx pkt counter
11586 for (i = IBSS_START_MAC_ID; i < NUM_STA; i++)
11588 if (pmlmeinfo->FW_sta_info[i].status == 1)
11590 psta = pmlmeinfo->FW_sta_info[i].psta;
11592 if(NULL==psta) continue;
11594 if (pmlmeinfo->FW_sta_info[i].rx_pkt == sta_rx_pkts(psta))
11597 if(pmlmeinfo->FW_sta_info[i].retry<3)
11599 pmlmeinfo->FW_sta_info[i].retry++;
11603 pmlmeinfo->FW_sta_info[i].retry = 0;
11604 pmlmeinfo->FW_sta_info[i].status = 0;
11605 report_del_sta_event(padapter, psta->hwaddr
11606 , 65535// indicate disconnect caused by no rx
11612 pmlmeinfo->FW_sta_info[i].retry = 0;
11613 pmlmeinfo->FW_sta_info[i].rx_pkt = (u32)sta_rx_pkts(psta);
11618 //set_link_timer(pmlmeext, DISCONNECT_TO);
11624 void survey_timer_hdl(_adapter *padapter)
11626 struct cmd_obj *ph2c;
11627 struct sitesurvey_parm *psurveyPara;
11628 struct cmd_priv *pcmdpriv=&padapter->cmdpriv;
11629 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
11631 struct wifidirect_info *pwdinfo= &(padapter->wdinfo);
11634 //DBG_871X("marc: survey timer\n");
11636 //issue rtw_sitesurvey_cmd
11637 if (pmlmeext->sitesurvey_res.state > SCAN_START)
11639 if(pmlmeext->sitesurvey_res.state == SCAN_PROCESS)
11641 #if defined(CONFIG_STA_MODE_SCAN_UNDER_AP_MODE) || defined(CONFIG_ATMEL_RC_PATCH)
11642 if (padapter->mlmeextpriv.mlmext_info.scan_cnt != RTW_SCAN_NUM_OF_CH
11643 || padapter->mlmeextpriv.mlmext_info.backop_cnt == RTW_STAY_AP_CH_MILLISECOND)
11645 pmlmeext->sitesurvey_res.channel_idx++;
11648 if(pmlmeext->scan_abort == _TRUE)
11651 if(!rtw_p2p_chk_state(&padapter->wdinfo, P2P_STATE_NONE))
11653 rtw_p2p_findphase_ex_set(pwdinfo, P2P_FINDPHASE_EX_MAX);
11654 pmlmeext->sitesurvey_res.channel_idx = 3;
11655 DBG_871X("%s idx:%d, cnt:%u\n", __FUNCTION__
11656 , pmlmeext->sitesurvey_res.channel_idx
11657 , pwdinfo->find_phase_state_exchange_cnt
11663 pmlmeext->sitesurvey_res.channel_idx = pmlmeext->sitesurvey_res.ch_num;
11664 DBG_871X("%s idx:%d\n", __FUNCTION__
11665 , pmlmeext->sitesurvey_res.channel_idx
11669 pmlmeext->scan_abort = _FALSE;//reset
11672 if ((ph2c = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj))) == NULL)
11674 goto exit_survey_timer_hdl;
11677 if ((psurveyPara = (struct sitesurvey_parm*)rtw_zmalloc(sizeof(struct sitesurvey_parm))) == NULL)
11679 rtw_mfree((unsigned char *)ph2c, sizeof(struct cmd_obj));
11680 goto exit_survey_timer_hdl;
11683 init_h2fwcmd_w_parm_no_rsp(ph2c, psurveyPara, GEN_CMD_CODE(_SiteSurvey));
11684 rtw_enqueue_cmd(pcmdpriv, ph2c);
11688 exit_survey_timer_hdl:
11693 void link_timer_hdl(_adapter *padapter)
11695 //static unsigned int rx_pkt = 0;
11696 //static u64 tx_cnt = 0;
11697 //struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
11698 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
11699 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
11700 //struct sta_priv *pstapriv = &padapter->stapriv;
11703 if (pmlmeinfo->state & WIFI_FW_AUTH_NULL)
11705 DBG_871X("link_timer_hdl:no beacon while connecting\n");
11706 pmlmeinfo->state = WIFI_FW_NULL_STATE;
11707 report_join_res(padapter, -3);
11709 else if (pmlmeinfo->state & WIFI_FW_AUTH_STATE)
11712 if (++pmlmeinfo->reauth_count > REAUTH_LIMIT)
11714 //if (pmlmeinfo->auth_algo != dot11AuthAlgrthm_Auto)
11716 pmlmeinfo->state = 0;
11717 report_join_res(padapter, -1);
11722 // pmlmeinfo->auth_algo = dot11AuthAlgrthm_Shared;
11723 // pmlmeinfo->reauth_count = 0;
11727 DBG_871X("link_timer_hdl: auth timeout and try again\n");
11728 pmlmeinfo->auth_seq = 1;
11729 issue_auth(padapter, NULL, 0);
11730 set_link_timer(pmlmeext, REAUTH_TO);
11732 else if (pmlmeinfo->state & WIFI_FW_ASSOC_STATE)
11735 if (++pmlmeinfo->reassoc_count > REASSOC_LIMIT)
11737 pmlmeinfo->state = WIFI_FW_NULL_STATE;
11738 report_join_res(padapter, -2);
11742 DBG_871X("link_timer_hdl: assoc timeout and try again\n");
11743 issue_assocreq(padapter);
11744 set_link_timer(pmlmeext, REASSOC_TO);
11747 else if (is_client_associated_to_ap(padapter))
11749 //linked infrastructure client mode
11750 if ((psta = rtw_get_stainfo(pstapriv, pmlmeinfo->network.MacAddress)) != NULL)
11752 /*to monitor whether the AP is alive or not*/
11753 if (rx_pkt == psta->sta_stats.rx_pkts)
11755 receive_disconnect(padapter, pmlmeinfo->network.MacAddress);
11760 rx_pkt = psta->sta_stats.rx_pkts;
11761 set_link_timer(pmlmeext, DISCONNECT_TO);
11764 //update the EDCA paramter according to the Tx/RX mode
11765 update_EDCA_param(padapter);
11767 /*to send the AP a nulldata if no frame is xmitted in order to keep alive*/
11768 if (pmlmeinfo->link_count++ == 0)
11770 tx_cnt = pxmitpriv->tx_pkts;
11772 else if ((pmlmeinfo->link_count & 0xf) == 0)
11774 if (tx_cnt == pxmitpriv->tx_pkts)
11776 issue_nulldata_in_interrupt(padapter, NULL);
11779 tx_cnt = pxmitpriv->tx_pkts;
11781 } //end of if ((psta = rtw_get_stainfo(pstapriv, passoc_res->network.MacAddress)) != NULL)
11783 else if (is_client_associated_to_ibss(padapter))
11786 //for each assoc list entry to check the rx pkt counter
11787 for (i = IBSS_START_MAC_ID; i < NUM_STA; i++)
11789 if (pmlmeinfo->FW_sta_info[i].status == 1)
11791 psta = pmlmeinfo->FW_sta_info[i].psta;
11793 if (pmlmeinfo->FW_sta_info[i].rx_pkt == psta->sta_stats.rx_pkts)
11795 pmlmeinfo->FW_sta_info[i].status = 0;
11796 report_del_sta_event(padapter, psta->hwaddr);
11800 pmlmeinfo->FW_sta_info[i].rx_pkt = psta->sta_stats.rx_pkts;
11805 set_link_timer(pmlmeext, DISCONNECT_TO);
11812 void addba_timer_hdl(struct sta_info *psta)
11814 #ifdef CONFIG_80211N_HT
11815 struct ht_priv *phtpriv;
11820 phtpriv = &psta->htpriv;
11822 if((phtpriv->ht_option==_TRUE) && (phtpriv->ampdu_enable==_TRUE))
11824 if(phtpriv->candidate_tid_bitmap)
11825 phtpriv->candidate_tid_bitmap=0x0;
11828 #endif //CONFIG_80211N_HT
11831 #ifdef CONFIG_IEEE80211W
11832 void sa_query_timer_hdl(_adapter *padapter)
11834 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
11835 struct mlme_priv * pmlmepriv = &padapter->mlmepriv;
11838 _enter_critical_bh(&pmlmepriv->lock, &irqL);
11840 if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
11842 rtw_disassoc_cmd(padapter, 0, _TRUE);
11843 rtw_indicate_disconnect(padapter);
11844 rtw_free_assoc_resources(padapter, 1);
11847 _exit_critical_bh(&pmlmepriv->lock, &irqL);
11848 DBG_871X("SA query timeout disconnect\n");
11850 #endif //CONFIG_IEEE80211W
11852 u8 NULL_hdl(_adapter *padapter, u8 *pbuf)
11854 return H2C_SUCCESS;
11857 #ifdef CONFIG_AUTO_AP_MODE
11858 void rtw_start_auto_ap(_adapter *adapter)
11860 DBG_871X("%s\n", __FUNCTION__);
11862 rtw_set_802_11_infrastructure_mode(adapter, Ndis802_11APMode);
11864 rtw_setopmode_cmd(adapter, Ndis802_11APMode,_TRUE);
11867 static int rtw_auto_ap_start_beacon(_adapter *adapter)
11872 u8 supportRate[16];
11873 int sz = 0, rateLen;
11875 u8 wireless_mode, oper_channel;
11876 u8 ssid[3] = {0}; //hidden ssid
11877 u32 ssid_len = sizeof(ssid);
11878 struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
11881 if(check_fwstate(pmlmepriv, WIFI_AP_STATE) != _TRUE)
11886 pbuf = rtw_zmalloc(len);
11894 //timestamp will be inserted by hardware
11898 //beacon interval : 2bytes
11899 *(u16*)ie = cpu_to_le16((u16)100);//BCN_INTERVAL=100;
11905 *(u16*)ie |= cpu_to_le16(cap_ESS);
11906 *(u16*)ie |= cpu_to_le16(cap_ShortPremble);
11907 //*(u16*)ie |= cpu_to_le16(cap_Privacy);
11912 ie = rtw_set_ie(ie, _SSID_IE_, ssid_len, ssid, &sz);
11915 wireless_mode = WIRELESS_11BG_24N;
11916 rtw_set_supported_rate(supportRate, wireless_mode) ;
11917 rateLen = rtw_get_rateset_len(supportRate);
11920 ie = rtw_set_ie(ie, _SUPPORTEDRATES_IE_, 8, supportRate, &sz);
11924 ie = rtw_set_ie(ie, _SUPPORTEDRATES_IE_, rateLen, supportRate, &sz);
11929 if(check_buddy_fwstate(adapter, _FW_LINKED) &&
11930 check_buddy_fwstate(adapter, WIFI_STATION_STATE))
11932 PADAPTER pbuddy_adapter = adapter->pbuddy_adapter;
11933 struct mlme_ext_priv *pbuddy_mlmeext = &pbuddy_adapter->mlmeextpriv;
11935 oper_channel = pbuddy_mlmeext->cur_channel;
11939 oper_channel = adapter_to_dvobj(adapter)->oper_channel;
11941 ie = rtw_set_ie(ie, _DSSET_IE_, 1, &oper_channel, &sz);
11943 //ext supported rates
11946 ie = rtw_set_ie(ie, _EXT_SUPPORTEDRATES_IE_, (rateLen - 8), (supportRate + 8), &sz);
11949 DBG_871X("%s, start auto ap beacon sz=%d\n", __FUNCTION__, sz);
11951 //lunch ap mode & start to issue beacon
11952 if(rtw_check_beacon_data(adapter, pbuf, sz) == _SUCCESS)
11962 rtw_mfree(pbuf, len);
11967 #endif//CONFIG_AUTO_AP_MODE
11969 u8 setopmode_hdl(_adapter *padapter, u8 *pbuf)
11972 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
11973 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
11974 struct setopmode_parm *psetop = (struct setopmode_parm *)pbuf;
11976 if(psetop->mode == Ndis802_11APMode)
11978 pmlmeinfo->state = WIFI_FW_AP_STATE;
11979 type = _HW_STATE_AP_;
11980 #ifdef CONFIG_NATIVEAP_MLME
11981 //start_ap_mode(padapter);
11984 else if(psetop->mode == Ndis802_11Infrastructure)
11986 pmlmeinfo->state &= ~(BIT(0)|BIT(1));// clear state
11987 pmlmeinfo->state |= WIFI_FW_STATION_STATE;//set to STATION_STATE
11988 type = _HW_STATE_STATION_;
11990 else if(psetop->mode == Ndis802_11IBSS)
11992 type = _HW_STATE_ADHOC_;
11996 type = _HW_STATE_NOLINK_;
11999 rtw_hal_set_hwreg(padapter, HW_VAR_SET_OPMODE, (u8 *)(&type));
12000 //Set_NETYPE0_MSR(padapter, type);
12003 #ifdef CONFIG_AUTO_AP_MODE
12004 if(psetop->mode == Ndis802_11APMode)
12005 rtw_auto_ap_start_beacon(padapter);
12008 if (rtw_port_switch_chk(padapter) == _TRUE)
12010 rtw_hal_set_hwreg(padapter, HW_VAR_PORT_SWITCH, NULL);
12012 if(psetop->mode == Ndis802_11APMode)
12013 adapter_to_pwrctl(padapter)->fw_psmode_iface_id = 0xff; //ap mode won't dowload rsvd pages
12014 else if (psetop->mode == Ndis802_11Infrastructure) {
12016 _adapter *port0_iface = dvobj_get_port0_adapter(adapter_to_dvobj(padapter));
12018 rtw_lps_ctrl_wk_cmd(port0_iface, LPS_CTRL_CONNECT, 0);
12023 #ifdef CONFIG_BT_COEXIST
12024 if (psetop->mode == Ndis802_11APMode)
12026 // Do this after port switch to
12027 // prevent from downloading rsvd page to wrong port
12028 rtw_btcoex_MediaStatusNotify(padapter, 1); //connect
12030 #endif // CONFIG_BT_COEXIST
12032 return H2C_SUCCESS;
12036 u8 createbss_hdl(_adapter *padapter, u8 *pbuf)
12038 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
12039 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
12040 WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX*)(&(pmlmeinfo->network));
12041 struct joinbss_parm *pparm = (struct joinbss_parm *)pbuf;
12044 #ifdef CONFIG_AP_MODE
12045 if (pmlmeinfo->state == WIFI_FW_AP_STATE) {
12046 WLAN_BSSID_EX *network = &padapter->mlmepriv.cur_network.network;
12047 start_bss_network(padapter, (u8*)network);
12048 return H2C_SUCCESS;
12052 //below is for ad-hoc master
12053 if(pparm->network.InfrastructureMode == Ndis802_11IBSS)
12055 rtw_joinbss_reset(padapter);
12057 pmlmeext->cur_bwmode = CHANNEL_WIDTH_20;
12058 pmlmeext->cur_ch_offset= HAL_PRIME_CHNL_OFFSET_DONT_CARE;
12059 pmlmeinfo->ERP_enable = 0;
12060 pmlmeinfo->WMM_enable = 0;
12061 pmlmeinfo->HT_enable = 0;
12062 pmlmeinfo->HT_caps_enable = 0;
12063 pmlmeinfo->HT_info_enable = 0;
12064 pmlmeinfo->agg_enable_bitmap = 0;
12065 pmlmeinfo->candidate_tid_bitmap = 0;
12067 //disable dynamic functions, such as high power, DIG
12068 Save_DM_Func_Flag(padapter);
12069 Switch_DM_Func(padapter, DYNAMIC_FUNC_DISABLE, _FALSE);
12071 //config the initial gain under linking, need to write the BB registers
12072 //initialgain = 0x1E;
12073 //rtw_hal_set_hwreg(padapter, HW_VAR_INITIAL_GAIN, (u8 *)(&initialgain));
12075 //cancel link timer
12076 _cancel_timer_ex(&pmlmeext->link_timer);
12079 flush_all_cam_entry(padapter);
12081 _rtw_memcpy(pnetwork, pbuf, FIELD_OFFSET(WLAN_BSSID_EX, IELength));
12082 pnetwork->IELength = ((WLAN_BSSID_EX *)pbuf)->IELength;
12084 if(pnetwork->IELength>MAX_IE_SZ)//Check pbuf->IELength
12085 return H2C_PARAMETERS_ERROR;
12087 _rtw_memcpy(pnetwork->IEs, ((WLAN_BSSID_EX *)pbuf)->IEs, pnetwork->IELength);
12089 start_create_ibss(padapter);
12093 return H2C_SUCCESS;
12097 u8 join_cmd_hdl(_adapter *padapter, u8 *pbuf)
12100 PNDIS_802_11_VARIABLE_IEs pIE;
12101 struct registry_priv *pregpriv = &padapter->registrypriv;
12102 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
12103 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
12104 WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX*)(&(pmlmeinfo->network));
12105 #ifdef CONFIG_ANTENNA_DIVERSITY
12106 struct joinbss_parm *pparm = (struct joinbss_parm *)pbuf;
12107 #endif //CONFIG_ANTENNA_DIVERSITY
12116 * For safety, prevent from keeping macid sleep.
12117 * If we can sure all power mode enter/leave are paired,
12118 * this check can be removed.
12122 struct sta_info *psta;
12123 psta = rtw_get_stainfo(&padapter->stapriv, get_my_bssid(pnetwork));
12125 rtw_hal_macid_wakeup(padapter, psta->mac_id);
12129 #ifdef CONFIG_BT_COEXIST
12131 static u8 bw_mode = 0;
12135 bw_mode = pregpriv->bw_mode; // keep original bw_mode
12136 DBG_871X(FUNC_ADPT_FMT ": [BTCOEX] Save bw_mode(0x%02x)\n",
12137 FUNC_ADPT_ARG(padapter), pregpriv->bw_mode);
12140 if ((rtw_btcoex_1Ant(padapter) == _TRUE)
12141 && (rtw_btcoex_IsBtLinkExist(padapter) == _TRUE))
12143 pregpriv->bw_mode = 0x00;
12144 DBG_871X(FUNC_ADPT_FMT ": [BTCOEX] Change bw_mode to 20MHz(0x%02x)\n",
12145 FUNC_ADPT_ARG(padapter), pregpriv->bw_mode);
12149 pregpriv->bw_mode = bw_mode;
12150 DBG_871X(FUNC_ADPT_FMT ": [BTCOEX] Restore bw_mode(0x%02x)\n",
12151 FUNC_ADPT_ARG(padapter), pregpriv->bw_mode);
12154 #endif // CONFIG_BT_COEXIST
12156 //check already connecting to AP or not
12157 if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS)
12159 if (pmlmeinfo->state & WIFI_FW_STATION_STATE)
12161 issue_deauth_ex(padapter, pnetwork->MacAddress, WLAN_REASON_DEAUTH_LEAVING, 1, 100);
12163 pmlmeinfo->state = WIFI_FW_NULL_STATE;
12166 flush_all_cam_entry(padapter);
12168 _cancel_timer_ex(&pmlmeext->link_timer);
12170 //set MSR to nolink -> infra. mode
12171 //Set_MSR(padapter, _HW_STATE_NOLINK_);
12172 Set_MSR(padapter, _HW_STATE_STATION_);
12175 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_DISCONNECT, 0);
12178 #ifdef CONFIG_ANTENNA_DIVERSITY
12179 rtw_antenna_select_cmd(padapter, pparm->network.PhyInfo.Optimum_antenna, _FALSE);
12182 #ifdef CONFIG_WAPI_SUPPORT
12183 rtw_wapi_clear_all_cam_entry(padapter);
12186 rtw_joinbss_reset(padapter);
12188 pmlmeext->cur_bwmode = CHANNEL_WIDTH_20;
12189 pmlmeext->cur_ch_offset= HAL_PRIME_CHNL_OFFSET_DONT_CARE;
12190 pmlmeinfo->ERP_enable = 0;
12191 pmlmeinfo->WMM_enable = 0;
12192 pmlmeinfo->HT_enable = 0;
12193 pmlmeinfo->HT_caps_enable = 0;
12194 pmlmeinfo->HT_info_enable = 0;
12195 pmlmeinfo->agg_enable_bitmap = 0;
12196 pmlmeinfo->candidate_tid_bitmap = 0;
12197 pmlmeinfo->bwmode_updated = _FALSE;
12198 //pmlmeinfo->assoc_AP_vendor = HT_IOT_PEER_MAX;
12199 pmlmeinfo->VHT_enable = 0;
12201 _rtw_memcpy(pnetwork, pbuf, FIELD_OFFSET(WLAN_BSSID_EX, IELength));
12202 pnetwork->IELength = ((WLAN_BSSID_EX *)pbuf)->IELength;
12204 if(pnetwork->IELength>MAX_IE_SZ)//Check pbuf->IELength
12205 return H2C_PARAMETERS_ERROR;
12207 _rtw_memcpy(pnetwork->IEs, ((WLAN_BSSID_EX *)pbuf)->IEs, pnetwork->IELength);
12209 pmlmeext->cur_channel = (u8)pnetwork->Configuration.DSConfig;
12210 pmlmeinfo->bcn_interval = get_beacon_interval(pnetwork);
12212 //Check AP vendor to move rtw_joinbss_cmd()
12213 //pmlmeinfo->assoc_AP_vendor = check_assoc_AP(pnetwork->IEs, pnetwork->IELength);
12215 //sizeof(NDIS_802_11_FIXED_IEs)
12216 for (i = _FIXED_IE_LENGTH_; i < pnetwork->IELength;)
12218 pIE = (PNDIS_802_11_VARIABLE_IEs)(pnetwork->IEs + i);
12220 switch (pIE->ElementID)
12222 case _VENDOR_SPECIFIC_IE_://Get WMM IE.
12223 if ( _rtw_memcmp(pIE->data, WMM_OUI, 4) )
12225 WMM_param_handler(padapter, pIE);
12229 case _HT_CAPABILITY_IE_: //Get HT Cap IE.
12230 pmlmeinfo->HT_caps_enable = 1;
12233 case _HT_EXTRA_INFO_IE_: //Get HT Info IE.
12234 #ifdef CONFIG_80211N_HT
12235 pmlmeinfo->HT_info_enable = 1;
12237 //spec case only for cisco's ap because cisco's ap issue assoc rsp using mcs rate @40MHz or @20MHz
12238 //#if !defined(CONFIG_CONCURRENT_MODE) && !defined(CONFIG_DUALMAC_CONCURRENT)
12239 // if(pmlmeinfo->assoc_AP_vendor == ciscoAP)
12242 struct HT_info_element *pht_info = (struct HT_info_element *)(pIE->data);
12244 if (pnetwork->Configuration.DSConfig > 14) {
12245 if ((pregpriv->bw_mode >> 4) > CHANNEL_WIDTH_20)
12248 if ((pregpriv->bw_mode & 0x0f) > CHANNEL_WIDTH_20)
12252 if ((cbw40_enable) && (pht_info->infos[0] & BIT(2)))
12254 //switch to the 40M Hz mode according to the AP
12255 pmlmeext->cur_bwmode = CHANNEL_WIDTH_40;
12256 switch (pht_info->infos[0] & 0x3)
12259 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
12263 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
12267 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
12268 pmlmeext->cur_bwmode = CHANNEL_WIDTH_20;
12272 DBG_871X("set HT ch/bw before connected\n");
12275 #endif //CONFIG_80211N_HT
12277 #ifdef CONFIG_80211AC_VHT
12278 case EID_VHTCapability://Get VHT Cap IE.
12279 pmlmeinfo->VHT_enable = 1;
12282 case EID_VHTOperation://Get VHT Operation IE.
12283 if((GET_VHT_OPERATION_ELE_CHL_WIDTH(pIE->data) >= 1)
12284 && ((pregpriv->bw_mode >> 4) >= CHANNEL_WIDTH_80)) {
12285 pmlmeext->cur_bwmode = CHANNEL_WIDTH_80;
12286 DBG_871X("VHT center ch = %d\n", GET_VHT_OPERATION_ELE_CENTER_FREQ1(pIE->data));
12287 DBG_871X("set VHT ch/bw before connected\n");
12295 i += (pIE->Length + 2);
12298 if (padapter->registrypriv.wifi_spec) {
12299 // for WiFi test, follow WMM test plan spec
12300 acparm = 0x002F431C; // VO
12301 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acparm));
12302 acparm = 0x005E541C; // VI
12303 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acparm));
12304 acparm = 0x0000A525; // BE
12305 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acparm));
12306 acparm = 0x0000A549; // BK
12307 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acparm));
12309 // for WiFi test, mixed mode with intel STA under bg mode throughput issue
12310 if (padapter->mlmepriv.htpriv.ht_option == _FALSE){
12311 acparm = 0x00004320;
12312 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acparm));
12316 acparm = 0x002F3217; // VO
12317 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acparm));
12318 acparm = 0x005E4317; // VI
12319 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acparm));
12320 acparm = 0x00105320; // BE
12321 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acparm));
12322 acparm = 0x0000A444; // BK
12323 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acparm));
12327 /* check channel, bandwidth, offset and switch */
12328 #ifdef CONFIG_DUALMAC_CONCURRENT
12329 if(dc_handle_join_request(padapter, &ch, &bw, &offset) == _FAIL) {
12330 DBG_871X("dc_handle_join_request fail !!!\n");
12331 return H2C_SUCCESS;
12333 #else //NON CONFIG_DUALMAC_CONCURRENT
12334 if(rtw_chk_start_clnt_join(padapter, &ch, &bw, &offset) == _FAIL) {
12335 report_join_res(padapter, (-4));
12336 return H2C_SUCCESS;
12340 //disable dynamic functions, such as high power, DIG
12341 //Switch_DM_Func(padapter, DYNAMIC_FUNC_DISABLE, _FALSE);
12343 //config the initial gain under linking, need to write the BB registers
12344 //initialgain = 0x1E;
12345 //rtw_hal_set_hwreg(padapter, HW_VAR_INITIAL_GAIN, (u8 *)(&initialgain));
12347 rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, pmlmeinfo->network.MacAddress);
12349 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type));
12350 rtw_hal_set_hwreg(padapter, HW_VAR_DO_IQK, NULL);
12352 set_channel_bwmode(padapter, ch, offset, bw);
12354 //cancel link timer
12355 _cancel_timer_ex(&pmlmeext->link_timer);
12357 start_clnt_join(padapter);
12359 return H2C_SUCCESS;
12363 u8 disconnect_hdl(_adapter *padapter, unsigned char *pbuf)
12365 struct disconnect_parm *param = (struct disconnect_parm *)pbuf;
12366 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
12367 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
12368 WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX*)(&(pmlmeinfo->network));
12374 * For safety, prevent from keeping macid sleep.
12375 * If we can sure all power mode enter/leave are paired,
12376 * this check can be removed.
12380 struct sta_info *psta;
12381 psta = rtw_get_stainfo(&padapter->stapriv, get_my_bssid(pnetwork));
12383 rtw_hal_macid_wakeup(padapter, psta->mac_id);
12387 if (is_client_associated_to_ap(padapter))
12390 if(padapter->mlmepriv.handle_dfs == _FALSE)
12391 #endif //CONFIG_DFS
12392 #ifdef CONFIG_PLATFORM_ROCKCHIPS
12393 //To avoid connecting to AP fail during resume process, change retry count from 5 to 1
12394 issue_deauth_ex(padapter, pnetwork->MacAddress, WLAN_REASON_DEAUTH_LEAVING, 1, 100);
12396 issue_deauth_ex(padapter, pnetwork->MacAddress, WLAN_REASON_DEAUTH_LEAVING, param->deauth_timeout_ms/100, 100);
12397 #endif //CONFIG_PLATFORM_ROCKCHIPS
12401 if( padapter->mlmepriv.handle_dfs == _TRUE )
12402 padapter->mlmepriv.handle_dfs = _FALSE;
12403 #endif //CONFIG_DFS
12405 if(((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) || ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE))
12409 rtw_hal_set_hwreg(padapter, HW_VAR_BCN_FUNC, (u8 *)(&val8));
12412 rtw_mlmeext_disconnect(padapter);
12414 rtw_free_uc_swdec_pending_queue(padapter);
12416 return H2C_SUCCESS;
12419 u8 rtw_scan_sparse(_adapter *adapter, struct rtw_ieee80211_channel *ch, u8 ch_num)
12421 /* interval larger than this is treated as backgroud scan */
12422 #ifndef RTW_SCAN_SPARSE_BG_INTERVAL_MS
12423 #define RTW_SCAN_SPARSE_BG_INTERVAL_MS 12000
12426 #ifndef RTW_SCAN_SPARSE_CH_NUM_MIRACAST
12427 #define RTW_SCAN_SPARSE_CH_NUM_MIRACAST 1
12429 #ifndef RTW_SCAN_SPARSE_CH_NUM_BG
12430 #define RTW_SCAN_SPARSE_CH_NUM_BG 4
12433 #define SCAN_SPARSE_CH_NUM_INVALID 255
12435 static u8 token = 255;
12437 bool busy_traffic = _FALSE;
12438 bool miracast_enabled = _FALSE;
12439 bool bg_scan = _FALSE;
12440 u8 max_allow_ch = SCAN_SPARSE_CH_NUM_INVALID;
12441 u8 scan_division_num;
12442 u8 ret_num = ch_num;
12443 struct registry_priv *regsty = dvobj_to_regsty(adapter_to_dvobj(adapter));
12444 struct mlme_ext_priv *mlmeext = &adapter->mlmeextpriv;
12446 if (regsty->wifi_spec)
12449 /* assume ch_num > 6 is normal scan */
12453 if (mlmeext->last_scan_time == 0)
12454 mlmeext->last_scan_time = rtw_get_current_time();
12456 interval = rtw_get_passing_time_ms(mlmeext->last_scan_time);
12458 if (adapter->mlmepriv.LinkDetectInfo.bBusyTraffic == _TRUE
12459 #ifdef CONFIG_CONCURRENT_MODE
12460 || (adapter->pbuddy_adapter && adapter->pbuddy_adapter->mlmepriv.LinkDetectInfo.bBusyTraffic == _TRUE)
12463 busy_traffic = _TRUE;
12466 if (is_miracast_enabled(adapter->wfd_info.stack_wfd_mode)
12467 #ifdef CONFIG_CONCURRENT_MODE
12468 || (adapter->pbuddy_adapter && is_miracast_enabled(adapter->pbuddy_adapter->wfd_info.stack_wfd_mode))
12471 miracast_enabled = _TRUE;
12474 if (interval > RTW_SCAN_SPARSE_BG_INTERVAL_MS)
12477 /* max_allow_ch by conditions*/
12479 #if RTW_SCAN_SPARSE_MIRACAST
12480 if (miracast_enabled == _TRUE && busy_traffic == _TRUE)
12481 max_allow_ch = rtw_min(max_allow_ch, RTW_SCAN_SPARSE_CH_NUM_MIRACAST);
12484 #if RTW_SCAN_SPARSE_BG
12485 if (bg_scan == _TRUE)
12486 max_allow_ch = rtw_min(max_allow_ch, RTW_SCAN_SPARSE_CH_NUM_BG);
12490 if (max_allow_ch != SCAN_SPARSE_CH_NUM_INVALID) {
12494 scan_division_num = (ch_num / max_allow_ch) + ((ch_num % max_allow_ch)?1:0);
12495 token = (token + 1) % scan_division_num;
12498 DBG_871X("scan_division_num:%u, token:%u\n", scan_division_num, token);
12500 for (i = 0; i < ch_num; i++) {
12501 if (ch[i].hw_value && (i % scan_division_num) == token
12504 _rtw_memcpy(&ch[k], &ch[i], sizeof(struct rtw_ieee80211_channel));
12509 _rtw_memset(&ch[k], 0, sizeof(struct rtw_ieee80211_channel));
12512 mlmeext->last_scan_time = rtw_get_current_time();
12519 static int rtw_scan_ch_decision(_adapter *padapter, struct rtw_ieee80211_channel *out,
12520 u32 out_num, struct rtw_ieee80211_channel *in, u32 in_num)
12523 int scan_ch_num = 0;
12525 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
12528 _rtw_memset(out, 0, sizeof(struct rtw_ieee80211_channel)*out_num);
12530 /* acquire channels from in */
12532 for (i=0;i<in_num;i++) {
12535 DBG_871X(FUNC_ADPT_FMT" "CHAN_FMT"\n", FUNC_ADPT_ARG(padapter), CHAN_ARG(&in[i]));
12537 if(in[i].hw_value && !(in[i].flags & RTW_IEEE80211_CHAN_DISABLED)
12538 && (set_idx=rtw_ch_set_search_ch(pmlmeext->channel_set, in[i].hw_value)) >=0
12539 && rtw_mlme_band_check(padapter, in[i].hw_value) == _TRUE
12542 if (j >= out_num) {
12543 DBG_871X_LEVEL(_drv_always_, FUNC_ADPT_FMT" out_num:%u not enough\n",
12544 FUNC_ADPT_ARG(padapter), out_num);
12548 _rtw_memcpy(&out[j], &in[i], sizeof(struct rtw_ieee80211_channel));
12550 if(pmlmeext->channel_set[set_idx].ScanType == SCAN_PASSIVE)
12551 out[j].flags |= RTW_IEEE80211_CHAN_PASSIVE_SCAN;
12559 /* if out is empty, use channel_set as default */
12561 for (i=0;i<pmlmeext->max_chan_nums;i++) {
12564 DBG_871X(FUNC_ADPT_FMT" ch:%u\n", FUNC_ADPT_ARG(padapter), pmlmeext->channel_set[i].ChannelNum);
12566 if (rtw_mlme_band_check(padapter, pmlmeext->channel_set[i].ChannelNum) == _TRUE) {
12568 if (j >= out_num) {
12569 DBG_871X_LEVEL(_drv_always_, FUNC_ADPT_FMT" out_num:%u not enough\n",
12570 FUNC_ADPT_ARG(padapter), out_num);
12574 out[j].hw_value = pmlmeext->channel_set[i].ChannelNum;
12576 if(pmlmeext->channel_set[i].ScanType == SCAN_PASSIVE)
12577 out[j].flags |= RTW_IEEE80211_CHAN_PASSIVE_SCAN;
12585 j = rtw_scan_sparse(padapter, out, j);
12590 u8 sitesurvey_cmd_hdl(_adapter *padapter, u8 *pbuf)
12592 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
12593 struct sitesurvey_parm *pparm = (struct sitesurvey_parm *)pbuf;
12594 u8 bdelayscan = _FALSE;
12598 struct dvobj_priv *psdpriv = padapter->dvobj;
12599 struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;
12602 struct wifidirect_info* pwdinfo = &padapter->wdinfo;
12604 #ifdef DBG_CHECK_FW_PS_STATE
12605 if(rtw_fw_ps_state(padapter) == _FAIL)
12607 DBG_871X("scan without leave 32k\n");
12608 pdbgpriv->dbg_scan_pwr_state_cnt++;
12610 #endif //DBG_CHECK_FW_PS_STATE
12612 if (pmlmeext->sitesurvey_res.state == SCAN_DISABLE)
12614 #ifdef CONFIG_CONCURRENT_MODE
12615 //for first time sitesurvey_cmd
12616 rtw_hal_set_hwreg(padapter, HW_VAR_CHECK_TXBUF, 0);
12617 #endif //CONFIG_CONCURRENT_MODE
12619 pmlmeext->sitesurvey_res.state = SCAN_START;
12620 pmlmeext->sitesurvey_res.bss_cnt = 0;
12621 pmlmeext->sitesurvey_res.channel_idx = 0;
12623 for(i=0;i<RTW_SSID_SCAN_AMOUNT;i++){
12624 if(pparm->ssid[i].SsidLength) {
12625 _rtw_memcpy(pmlmeext->sitesurvey_res.ssid[i].Ssid, pparm->ssid[i].Ssid, IW_ESSID_MAX_SIZE);
12626 pmlmeext->sitesurvey_res.ssid[i].SsidLength= pparm->ssid[i].SsidLength;
12628 pmlmeext->sitesurvey_res.ssid[i].SsidLength= 0;
12632 pmlmeext->sitesurvey_res.ch_num = rtw_scan_ch_decision(padapter
12633 , pmlmeext->sitesurvey_res.ch, RTW_CHANNEL_SCAN_AMOUNT
12634 , pparm->ch, pparm->ch_num
12637 pmlmeext->sitesurvey_res.scan_mode = pparm->scan_mode;
12639 #ifdef CONFIG_DUALMAC_CONCURRENT
12640 bdelayscan = dc_handle_site_survey(padapter);
12643 //issue null data if associating to the AP
12644 if (is_client_associated_to_ap(padapter) == _TRUE)
12646 pmlmeext->sitesurvey_res.state = SCAN_TXNULL;
12648 issue_nulldata(padapter, NULL, 1, 3, 500);
12650 #ifdef CONFIG_CONCURRENT_MODE
12651 if(is_client_associated_to_ap(padapter->pbuddy_adapter) == _TRUE)
12653 DBG_871X("adapter is scanning(buddy_adapter is linked), issue nulldata(pwrbit=1)\n");
12655 issue_nulldata(padapter->pbuddy_adapter, NULL, 1, 3, 500);
12658 bdelayscan = _TRUE;
12660 #ifdef CONFIG_CONCURRENT_MODE
12661 else if(is_client_associated_to_ap(padapter->pbuddy_adapter) == _TRUE)
12664 if(padapter->pbuddy_adapter->wdinfo.wfd_tdls_enable == 1)
12666 issue_tunneled_probe_req(padapter->pbuddy_adapter);
12668 #endif //CONFIG_TDLS
12670 pmlmeext->sitesurvey_res.state = SCAN_TXNULL;
12672 issue_nulldata(padapter->pbuddy_adapter, NULL, 1, 3, 500);
12674 bdelayscan = _TRUE;
12679 //delay 50ms to protect nulldata(1).
12680 set_survey_timer(pmlmeext, 50);
12681 return H2C_SUCCESS;
12685 if ((pmlmeext->sitesurvey_res.state == SCAN_START) || (pmlmeext->sitesurvey_res.state == SCAN_TXNULL))
12687 #ifdef CONFIG_FIND_BEST_CHANNEL
12689 for (i=0; pmlmeext->channel_set[i].ChannelNum !=0; i++) {
12690 pmlmeext->channel_set[i].rx_count = 0;
12693 #endif /* CONFIG_FIND_BEST_CHANNEL */
12695 //disable dynamic functions, such as high power, DIG
12696 Save_DM_Func_Flag(padapter);
12697 Switch_DM_Func(padapter, DYNAMIC_FUNC_DISABLE, _FALSE);
12699 //config the initial gain under scaning, need to write the BB registers
12701 #ifdef CONFIG_IOCTL_CFG80211
12702 if(adapter_wdev_data(padapter)->p2p_enabled == _TRUE && pwdinfo->driver_interface == DRIVER_CFG80211 )
12703 initialgain = 0x30;
12705 #endif //CONFIG_IOCTL_CFG80211
12706 if ( !rtw_p2p_chk_state( pwdinfo, P2P_STATE_NONE ) )
12707 initialgain = 0x28;
12709 #endif //CONFIG_P2P
12710 initialgain = 0x1e;
12712 rtw_hal_set_hwreg(padapter, HW_VAR_INITIAL_GAIN, (u8 *)(&initialgain));
12714 //set MSR to no link state
12715 Set_MSR(padapter, _HW_STATE_NOLINK_);
12717 val8 = 1; //under site survey
12718 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_SITESURVEY, (u8 *)(&val8));
12720 pmlmeext->sitesurvey_res.state = SCAN_PROCESS;
12723 site_survey(padapter);
12725 return H2C_SUCCESS;
12729 u8 setauth_hdl(_adapter *padapter, unsigned char *pbuf)
12731 struct setauth_parm *pparm = (struct setauth_parm *)pbuf;
12732 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
12733 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
12735 if (pparm->mode < 4)
12737 pmlmeinfo->auth_algo = pparm->mode;
12740 return H2C_SUCCESS;
12743 u8 setkey_hdl(_adapter *padapter, u8 *pbuf)
12747 struct setkey_parm *pparm = (struct setkey_parm *)pbuf;
12748 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
12749 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
12750 unsigned char null_addr[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
12753 //main tx key for wep.
12755 pmlmeinfo->key_index = pparm->keyid;
12757 cam_id = rtw_camid_alloc(padapter, NULL, pparm->keyid);
12761 if (cam_id > 3) /* not default key, searched by A2 */
12762 addr = get_bssid(&padapter->mlmepriv);
12766 ctrl = BIT(15) | BIT6 |((pparm->algorithm) << 2) | pparm->keyid;
12767 write_cam(padapter, cam_id, ctrl, addr, pparm->key);
12768 DBG_871X_LEVEL(_drv_always_, "set group key camid:%d, addr:"MAC_FMT", kid:%d, type:%s\n"
12769 ,cam_id, MAC_ARG(addr), pparm->keyid, security_type_str(pparm->algorithm));
12772 #ifdef DYNAMIC_CAMID_ALLOC
12773 if (cam_id >=0 && cam_id <=3)
12774 rtw_hal_set_hwreg(padapter, HW_VAR_SEC_DK_CFG, (u8*)_TRUE);
12777 //allow multicast packets to driver
12778 padapter->HalFunc.SetHwRegHandler(padapter, HW_VAR_ON_RCR_AM, null_addr);
12780 return H2C_SUCCESS;
12783 u8 set_stakey_hdl(_adapter *padapter, u8 *pbuf)
12787 u8 ret = H2C_SUCCESS;
12788 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
12789 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
12790 struct set_stakey_parm *pparm = (struct set_stakey_parm *)pbuf;
12791 struct sta_priv *pstapriv = &padapter->stapriv;
12792 struct sta_info *psta;
12794 struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
12795 #endif //CONFIG_TDLS
12797 if(pparm->algorithm == _NO_PRIVACY_)
12800 psta = rtw_get_stainfo(pstapriv, pparm->addr);
12802 DBG_871X_LEVEL(_drv_always_, "%s sta:"MAC_FMT" not found\n", __func__, MAC_ARG(pparm->addr));
12803 ret = H2C_REJECTED;
12807 pmlmeinfo->enc_algo = pparm->algorithm;
12808 cam_id = rtw_camid_alloc(padapter, psta, 0);
12813 if(pparm->algorithm == _NO_PRIVACY_) {
12814 while((cam_id = rtw_camid_search(padapter, pparm->addr, -1)) >= 0) {
12815 DBG_871X_LEVEL(_drv_always_, "clear key for addr:"MAC_FMT", camid:%d\n", MAC_ARG(pparm->addr), cam_id);
12816 clear_cam_entry(padapter, cam_id);
12817 rtw_camid_free(padapter,cam_id);
12820 DBG_871X_LEVEL(_drv_always_, "set pairwise key camid:%d, addr:"MAC_FMT", kid:%d, type:%s\n",
12821 cam_id, MAC_ARG(pparm->addr), pparm->keyid, security_type_str(pparm->algorithm));
12822 ctrl = BIT(15) | ((pparm->algorithm) << 2) | pparm->keyid;
12823 write_cam(padapter, cam_id, ctrl, pparm->addr, pparm->key);
12825 ret = H2C_SUCCESS_RSP;
12831 u8 add_ba_hdl(_adapter *padapter, unsigned char *pbuf)
12833 struct addBaReq_parm *pparm = (struct addBaReq_parm *)pbuf;
12834 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
12835 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
12837 struct sta_info *psta = rtw_get_stainfo(&padapter->stapriv, pparm->addr);
12840 return H2C_SUCCESS;
12842 #ifdef CONFIG_80211N_HT
12843 if (((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && (pmlmeinfo->HT_enable)) ||
12844 ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE))
12846 //pmlmeinfo->ADDBA_retry_count = 0;
12847 //pmlmeinfo->candidate_tid_bitmap |= (0x1 << pparm->tid);
12848 //psta->htpriv.candidate_tid_bitmap |= BIT(pparm->tid);
12849 issue_action_BA(padapter, pparm->addr, RTW_WLAN_ACTION_ADDBA_REQ, (u16)pparm->tid);
12850 //_set_timer(&pmlmeext->ADDBA_timer, ADDBA_TO);
12851 _set_timer(&psta->addba_retry_timer, ADDBA_TO);
12854 else if((psta->tdls_sta_state & TDLS_LINKED_STATE)&&
12855 (psta->htpriv.ht_option==_TRUE) &&
12856 (psta->htpriv.ampdu_enable==_TRUE) )
12858 issue_action_BA(padapter, pparm->addr, RTW_WLAN_ACTION_ADDBA_REQ, (u16)pparm->tid);
12859 //_set_timer(&pmlmeext->ADDBA_timer, ADDBA_TO);
12860 _set_timer(&psta->addba_retry_timer, ADDBA_TO);
12865 psta->htpriv.candidate_tid_bitmap &= ~BIT(pparm->tid);
12867 #endif //CONFIG_80211N_HT
12868 return H2C_SUCCESS;
12872 u8 chk_bmc_sleepq_cmd(_adapter* padapter)
12874 struct cmd_obj *ph2c;
12875 struct cmd_priv *pcmdpriv = &(padapter->cmdpriv);
12880 if ((ph2c = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj))) == NULL)
12886 init_h2fwcmd_w_parm_no_parm_rsp(ph2c, GEN_CMD_CODE(_ChkBMCSleepq));
12888 res = rtw_enqueue_cmd(pcmdpriv, ph2c);
12897 u8 set_tx_beacon_cmd(_adapter* padapter)
12899 struct cmd_obj *ph2c;
12900 struct Tx_Beacon_param *ptxBeacon_parm;
12901 struct cmd_priv *pcmdpriv = &(padapter->cmdpriv);
12902 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
12903 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
12909 if ((ph2c = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj))) == NULL)
12915 if ((ptxBeacon_parm = (struct Tx_Beacon_param *)rtw_zmalloc(sizeof(struct Tx_Beacon_param))) == NULL)
12917 rtw_mfree((unsigned char *)ph2c, sizeof(struct cmd_obj));
12922 _rtw_memcpy(&(ptxBeacon_parm->network), &(pmlmeinfo->network), sizeof(WLAN_BSSID_EX));
12924 len_diff = update_hidden_ssid(
12925 ptxBeacon_parm->network.IEs+_BEACON_IE_OFFSET_
12926 , ptxBeacon_parm->network.IELength-_BEACON_IE_OFFSET_
12927 , pmlmeinfo->hidden_ssid_mode
12929 ptxBeacon_parm->network.IELength += len_diff;
12931 init_h2fwcmd_w_parm_no_rsp(ph2c, ptxBeacon_parm, GEN_CMD_CODE(_TX_Beacon));
12933 res = rtw_enqueue_cmd(pcmdpriv, ph2c);
12944 u8 mlme_evt_hdl(_adapter *padapter, unsigned char *pbuf)
12946 u8 evt_code, evt_seq;
12949 void (*event_callback)(_adapter *dev, u8 *pbuf);
12950 struct evt_priv *pevt_priv = &(padapter->evtpriv);
12953 goto _abort_event_;
12955 peventbuf = (uint*)pbuf;
12956 evt_sz = (u16)(*peventbuf&0xffff);
12957 evt_seq = (u8)((*peventbuf>>24)&0x7f);
12958 evt_code = (u8)((*peventbuf>>16)&0xff);
12961 #ifdef CHECK_EVENT_SEQ
12962 // checking event sequence...
12963 if (evt_seq != (ATOMIC_READ(&pevt_priv->event_seq) & 0x7f) )
12965 RT_TRACE(_module_rtl871x_cmd_c_,_drv_info_,("Evetn Seq Error! %d vs %d\n", (evt_seq & 0x7f), (ATOMIC_READ(&pevt_priv->event_seq) & 0x7f)));
12967 pevt_priv->event_seq = (evt_seq+1)&0x7f;
12969 goto _abort_event_;
12973 // checking if event code is valid
12974 if (evt_code >= MAX_C2HEVT)
12976 RT_TRACE(_module_rtl871x_cmd_c_,_drv_err_,("\nEvent Code(%d) mismatch!\n", evt_code));
12977 goto _abort_event_;
12980 // checking if event size match the event parm size
12981 if ((wlanevents[evt_code].parmsize != 0) &&
12982 (wlanevents[evt_code].parmsize != evt_sz))
12985 RT_TRACE(_module_rtl871x_cmd_c_,_drv_err_,("\nEvent(%d) Parm Size mismatch (%d vs %d)!\n",
12986 evt_code, wlanevents[evt_code].parmsize, evt_sz));
12987 goto _abort_event_;
12991 ATOMIC_INC(&pevt_priv->event_seq);
12997 event_callback = wlanevents[evt_code].event_callback;
12998 event_callback(padapter, (u8*)peventbuf);
13000 pevt_priv->evt_done_cnt++;
13007 return H2C_SUCCESS;
13011 u8 h2c_msg_hdl(_adapter *padapter, unsigned char *pbuf)
13014 return H2C_PARAMETERS_ERROR;
13016 return H2C_SUCCESS;
13019 u8 chk_bmc_sleepq_hdl(_adapter *padapter, unsigned char *pbuf)
13021 #ifdef CONFIG_AP_MODE
13023 struct sta_info *psta_bmc;
13024 _list *xmitframe_plist, *xmitframe_phead;
13025 struct xmit_frame *pxmitframe=NULL;
13026 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
13027 struct sta_priv *pstapriv = &padapter->stapriv;
13030 psta_bmc = rtw_get_bcmc_stainfo(padapter);
13032 return H2C_SUCCESS;
13034 if((pstapriv->tim_bitmap&BIT(0)) && (psta_bmc->sleepq_len>0))
13036 #ifndef CONFIG_PCI_HCI
13037 rtw_msleep_os(10);// 10ms, ATIM(HIQ) Windows
13039 //_enter_critical_bh(&psta_bmc->sleep_q.lock, &irqL);
13040 _enter_critical_bh(&pxmitpriv->lock, &irqL);
13042 xmitframe_phead = get_list_head(&psta_bmc->sleep_q);
13043 xmitframe_plist = get_next(xmitframe_phead);
13045 while ((rtw_end_of_queue_search(xmitframe_phead, xmitframe_plist)) == _FALSE)
13047 pxmitframe = LIST_CONTAINOR(xmitframe_plist, struct xmit_frame, list);
13049 xmitframe_plist = get_next(xmitframe_plist);
13051 rtw_list_delete(&pxmitframe->list);
13053 psta_bmc->sleepq_len--;
13054 if(psta_bmc->sleepq_len>0)
13055 pxmitframe->attrib.mdata = 1;
13057 pxmitframe->attrib.mdata = 0;
13059 pxmitframe->attrib.triggered=1;
13061 if (xmitframe_hiq_filter(pxmitframe) == _TRUE)
13062 pxmitframe->attrib.qsel = 0x11;//HIQ
13065 _exit_critical_bh(&psta_bmc->sleep_q.lock, &irqL);
13066 if(rtw_hal_xmit(padapter, pxmitframe) == _TRUE)
13068 rtw_os_xmit_complete(padapter, pxmitframe);
13070 _enter_critical_bh(&psta_bmc->sleep_q.lock, &irqL);
13072 rtw_hal_xmitframe_enqueue(padapter, pxmitframe);
13075 //_exit_critical_bh(&psta_bmc->sleep_q.lock, &irqL);
13076 _exit_critical_bh(&pxmitpriv->lock, &irqL);
13078 if (padapter->interface_type != RTW_PCIE) {
13079 /* check hi queue and bmc_sleepq */
13080 rtw_chk_hi_queue_cmd(padapter);
13085 return H2C_SUCCESS;
13088 u8 tx_beacon_hdl(_adapter *padapter, unsigned char *pbuf)
13090 if(send_beacon(padapter)==_FAIL)
13092 DBG_871X("issue_beacon, fail!\n");
13093 return H2C_PARAMETERS_ERROR;
13096 /* tx bc/mc frames after update TIM */
13097 chk_bmc_sleepq_hdl(padapter, NULL);
13099 return H2C_SUCCESS;
13102 void change_band_update_ie(_adapter *padapter, WLAN_BSSID_EX *pnetwork)
13104 u8 network_type,rate_len, total_rate_len,remainder_rate_len;
13105 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
13106 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
13109 //DBG_871X("%s\n", __FUNCTION__);
13111 if(pmlmeext->cur_channel >= 36)
13113 network_type = WIRELESS_11A;
13114 total_rate_len = IEEE80211_NUM_OFDM_RATESLEN;
13115 DBG_871X("%s(): change to 5G Band\n",__FUNCTION__);
13116 rtw_remove_bcn_ie(padapter, pnetwork, _ERPINFO_IE_);
13120 network_type = WIRELESS_11BG;
13121 total_rate_len = IEEE80211_CCK_RATE_LEN+IEEE80211_NUM_OFDM_RATESLEN;
13122 DBG_871X("%s(): change to 2.4G Band\n",__FUNCTION__);
13123 rtw_add_bcn_ie(padapter, pnetwork, _ERPINFO_IE_, &erpinfo, 1);
13126 rtw_set_supported_rate(pnetwork->SupportedRates, network_type);
13128 UpdateBrateTbl(padapter, pnetwork->SupportedRates);
13129 rtw_hal_set_hwreg(padapter, HW_VAR_BASIC_RATE, pnetwork->SupportedRates);
13131 if(total_rate_len > 8)
13134 remainder_rate_len = total_rate_len - 8;
13138 rate_len = total_rate_len;
13139 remainder_rate_len = 0;
13142 rtw_add_bcn_ie(padapter, pnetwork, _SUPPORTEDRATES_IE_, pnetwork->SupportedRates, rate_len);
13144 if(remainder_rate_len)
13146 rtw_add_bcn_ie(padapter, pnetwork, _EXT_SUPPORTEDRATES_IE_, (pnetwork->SupportedRates+8), remainder_rate_len);
13150 rtw_remove_bcn_ie(padapter, pnetwork, _EXT_SUPPORTEDRATES_IE_);
13154 #ifdef CONFIG_DUALMAC_CONCURRENT
13155 void dc_SelectChannel(_adapter *padapter, unsigned char channel)
13157 PADAPTER ptarget_adapter;
13159 if( (padapter->pbuddy_adapter != NULL) &&
13160 (padapter->DualMacConcurrent == _TRUE) &&
13161 (padapter->adapter_type == SECONDARY_ADAPTER))
13163 // only mac0 could control BB&RF
13164 ptarget_adapter = padapter->pbuddy_adapter;
13168 ptarget_adapter = padapter;
13171 _enter_critical_mutex(&(adapter_to_dvobj(ptarget_adapter)->setch_mutex), NULL);
13173 rtw_hal_set_chan(ptarget_adapter, channel);
13175 _exit_critical_mutex(&(adapter_to_dvobj(ptarget_adapter)->setch_mutex), NULL);
13178 void dc_SetBWMode(_adapter *padapter, unsigned short bwmode, unsigned char channel_offset)
13180 PADAPTER ptarget_adapter;
13182 if( (padapter->pbuddy_adapter != NULL) &&
13183 (padapter->DualMacConcurrent == _TRUE) &&
13184 (padapter->adapter_type == SECONDARY_ADAPTER))
13186 // only mac0 could control BB&RF
13187 ptarget_adapter = padapter->pbuddy_adapter;
13191 ptarget_adapter = padapter;
13194 _enter_critical_mutex(&(adapter_to_dvobj(ptarget_adapter)->setbw_mutex), NULL);
13196 rtw_hal_set_bwmode(ptarget_adapter, (CHANNEL_WIDTH)bwmode, channel_offset);
13198 _exit_critical_mutex(&(adapter_to_dvobj(ptarget_adapter)->setbw_mutex), NULL);
13201 void dc_set_channel_bwmode_disconnect(_adapter *padapter)
13203 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
13204 PADAPTER pbuddy_adapter = padapter->pbuddy_adapter;
13205 struct mlme_priv *pbuddy_mlmepriv = NULL;
13207 if(pbuddy_adapter != NULL &&
13208 padapter->DualMacConcurrent == _TRUE)
13210 pbuddy_mlmepriv = &(pbuddy_adapter->mlmepriv);
13211 if((check_fwstate(pbuddy_mlmepriv, _FW_LINKED)) != _TRUE)
13213 //switch to the 20M Hz mode after disconnect
13214 pmlmeext->cur_bwmode = CHANNEL_WIDTH_20;
13215 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
13217 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
13222 //switch to the 20M Hz mode after disconnect
13223 pmlmeext->cur_bwmode = CHANNEL_WIDTH_20;
13224 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
13226 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
13230 u8 dc_handle_join_request(_adapter *padapter, u8 *ch, u8 *bw, u8 *offset)
13232 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
13233 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
13234 WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX*)(&(pmlmeinfo->network));
13235 PADAPTER pbuddy_adapter = padapter->pbuddy_adapter;
13236 struct mlme_ext_priv *pbuddy_mlmeext = NULL;
13237 struct mlme_priv *pbuddy_mlmepriv = NULL;
13240 if(pbuddy_adapter != NULL &&
13241 padapter->DualMacConcurrent == _TRUE)
13243 pbuddy_mlmeext = &pbuddy_adapter->mlmeextpriv;
13244 pbuddy_mlmepriv = &(pbuddy_adapter->mlmepriv);
13246 if(pmlmeext->cur_channel != pbuddy_mlmeext->cur_channel ||
13247 pmlmeext->cur_bwmode != pbuddy_mlmeext->cur_bwmode ||
13248 pmlmeext->cur_ch_offset != pbuddy_mlmeext->cur_ch_offset)
13250 if((check_fwstate(pbuddy_mlmepriv, WIFI_AP_STATE)) == _TRUE)
13252 //issue deauth to all stas if if2 is at ap mode
13253 rtw_sta_flush(pbuddy_adapter);
13255 //rtw_hal_set_hwreg(padapter, HW_VAR_CHECK_TXBUF, 0);
13256 rtw_hal_set_hwreg(pbuddy_adapter, HW_VAR_CHECK_TXBUF, 0);
13258 else if(check_fwstate(pbuddy_mlmepriv, _FW_LINKED) == _TRUE)
13260 if(pmlmeext->cur_channel == pbuddy_mlmeext->cur_channel)
13262 // CHANNEL_WIDTH_40 or CHANNEL_WIDTH_20 but channel offset is different
13263 if((pmlmeext->cur_bwmode == pbuddy_mlmeext->cur_bwmode) &&
13264 (pmlmeext->cur_ch_offset != pbuddy_mlmeext->cur_ch_offset) )
13266 report_join_res(padapter, -4);
13272 report_join_res(padapter, -4);
13277 else if (is_client_associated_to_ap(pbuddy_adapter) == _TRUE)
13279 issue_nulldata(pbuddy_adapter, NULL, 1, 0, 0);
13283 if (!ch || !bw || !offset) {
13288 if (ret == _SUCCESS) {
13289 *ch = pmlmeext->cur_channel;
13290 *bw = pmlmeext->cur_bwmode;
13291 *offset = pmlmeext->cur_ch_offset;
13298 void dc_handle_join_done(_adapter *padapter, u8 join_res)
13300 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
13301 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
13302 PADAPTER pbuddy_adapter = padapter->pbuddy_adapter;
13303 struct mlme_priv *pbuddy_mlmepriv = NULL;
13304 struct mlme_ext_priv *pbuddy_mlmeext = NULL;
13305 struct mlme_ext_info *pbuddy_mlmeinfo = NULL;
13306 WLAN_BSSID_EX *pbuddy_network_mlmeext = NULL;
13307 u8 change_band = _FALSE;
13310 if(pbuddy_adapter != NULL &&
13311 padapter->DualMacConcurrent == _TRUE)
13313 pbuddy_mlmepriv = &(pbuddy_adapter->mlmepriv);
13314 pbuddy_mlmeext = &pbuddy_adapter->mlmeextpriv;
13315 pbuddy_mlmeinfo = &(pbuddy_mlmeext->mlmext_info);
13316 pbuddy_network_mlmeext = &(pbuddy_mlmeinfo->network);
13318 if(((pbuddy_mlmeinfo->state&0x03) == WIFI_FW_AP_STATE) &&
13319 check_fwstate(pbuddy_mlmepriv, _FW_LINKED))
13321 //restart and update beacon
13322 DBG_871X("after join, current adapter, CH=%d, BW=%d, offset=%d\n", pmlmeext->cur_channel, pmlmeext->cur_bwmode, pmlmeext->cur_ch_offset);
13328 struct HT_info_element *pht_info=NULL;
13330 if((pbuddy_mlmeext->cur_channel <= 14 && pmlmeext->cur_channel >= 36) ||
13331 (pbuddy_mlmeext->cur_channel >= 36 && pmlmeext->cur_channel <= 14))
13333 change_band = _TRUE;
13336 //sync channel/bwmode/ch_offset with another adapter
13337 pbuddy_mlmeext->cur_channel = pmlmeext->cur_channel;
13339 if(pbuddy_mlmeext->cur_bwmode == CHANNEL_WIDTH_40)
13341 p = rtw_get_ie((pbuddy_network_mlmeext->IEs + sizeof(NDIS_802_11_FIXED_IEs)), _HT_ADD_INFO_IE_, &ie_len, (pbuddy_network_mlmeext->IELength - sizeof(NDIS_802_11_FIXED_IEs)));
13344 pht_info = (struct HT_info_element *)(p+2);
13345 pht_info->infos[0] &= ~(BIT(0)|BIT(1)); //no secondary channel is present
13348 if(pmlmeext->cur_bwmode == CHANNEL_WIDTH_40)
13350 pbuddy_mlmeext->cur_ch_offset = pmlmeext->cur_ch_offset;
13352 //to update cur_ch_offset value in beacon
13355 switch(pmlmeext->cur_ch_offset)
13357 case HAL_PRIME_CHNL_OFFSET_LOWER:
13358 pht_info->infos[0] |= 0x1;
13360 case HAL_PRIME_CHNL_OFFSET_UPPER:
13361 pht_info->infos[0] |= 0x3;
13363 case HAL_PRIME_CHNL_OFFSET_DONT_CARE:
13369 else if(pmlmeext->cur_bwmode == CHANNEL_WIDTH_20)
13371 pbuddy_mlmeext->cur_bwmode = CHANNEL_WIDTH_20;
13372 pbuddy_mlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
13374 if(pmlmeext->cur_channel>0 && pmlmeext->cur_channel<5)
13377 pht_info->infos[0] |= 0x1;
13379 pbuddy_mlmeext->cur_bwmode = CHANNEL_WIDTH_40;
13380 pbuddy_mlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
13383 if(pmlmeext->cur_channel>7 && pmlmeext->cur_channel<(14+1))
13386 pht_info->infos[0] |= 0x3;
13388 pbuddy_mlmeext->cur_bwmode = CHANNEL_WIDTH_40;
13389 pbuddy_mlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
13392 set_channel_bwmode(padapter, pbuddy_mlmeext->cur_channel, pbuddy_mlmeext->cur_ch_offset, pbuddy_mlmeext->cur_bwmode);
13396 // to update channel value in beacon
13397 pbuddy_network_mlmeext->Configuration.DSConfig = pmlmeext->cur_channel;
13398 p = rtw_get_ie((pbuddy_network_mlmeext->IEs + sizeof(NDIS_802_11_FIXED_IEs)), _DSSET_IE_, &ie_len, (pbuddy_network_mlmeext->IELength - sizeof(NDIS_802_11_FIXED_IEs)));
13400 *(p + 2) = pmlmeext->cur_channel;
13402 p = rtw_get_ie((pbuddy_network_mlmeext->IEs + sizeof(NDIS_802_11_FIXED_IEs)), _HT_ADD_INFO_IE_, &ie_len, (pbuddy_network_mlmeext->IELength - sizeof(NDIS_802_11_FIXED_IEs)));
13405 pht_info = (struct HT_info_element *)(p+2);
13406 pht_info->primary_channel = pmlmeext->cur_channel;
13409 // update mlmepriv's cur_network
13410 _rtw_memcpy(&pbuddy_mlmepriv->cur_network.network, pbuddy_network_mlmeext, pbuddy_network_mlmeext->Length);
13414 // switch back to original channel/bwmode/ch_offset;
13415 set_channel_bwmode(padapter, pbuddy_mlmeext->cur_channel, pbuddy_mlmeext->cur_ch_offset, pbuddy_mlmeext->cur_bwmode);
13418 DBG_871X("after join, another adapter, CH=%d, BW=%d, offset=%d\n", pbuddy_mlmeext->cur_channel, pbuddy_mlmeext->cur_bwmode, pbuddy_mlmeext->cur_ch_offset);
13420 if(change_band == _TRUE)
13421 change_band_update_ie(pbuddy_adapter, pbuddy_network_mlmeext);
13423 DBG_871X("update pbuddy_adapter's beacon\n");
13425 update_beacon(pbuddy_adapter, 0, NULL, _TRUE);
13427 else if (is_client_associated_to_ap(pbuddy_adapter) == _TRUE)
13429 if((pbuddy_mlmeext->cur_bwmode == CHANNEL_WIDTH_40) &&
13430 (pmlmeext->cur_bwmode == CHANNEL_WIDTH_20))
13432 set_channel_bwmode(padapter, pbuddy_mlmeext->cur_channel, pbuddy_mlmeext->cur_ch_offset, pbuddy_mlmeext->cur_bwmode);
13435 issue_nulldata(pbuddy_adapter, NULL, 0, 0, 0);
13440 sint dc_check_fwstate(_adapter *padapter, sint fw_state)
13442 PADAPTER pbuddy_adapter = padapter->pbuddy_adapter;
13443 struct mlme_priv *pbuddy_mlmepriv = NULL;
13445 if(padapter->pbuddy_adapter != NULL &&
13446 padapter->DualMacConcurrent == _TRUE)
13449 pbuddy_mlmepriv = &(pbuddy_adapter->mlmepriv);
13451 return check_fwstate(pbuddy_mlmepriv, fw_state);
13457 u8 dc_handle_site_survey(_adapter *padapter)
13459 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
13460 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
13461 PADAPTER pbuddy_adapter = padapter->pbuddy_adapter;
13463 // only mac0 can do scan request, help issue nulldata(1) for mac1
13464 if(pbuddy_adapter != NULL &&
13465 padapter->DualMacConcurrent == _TRUE)
13467 if (is_client_associated_to_ap(pbuddy_adapter) == _TRUE)
13469 pmlmeext->sitesurvey_res.state = SCAN_TXNULL;
13471 issue_nulldata(pbuddy_adapter, NULL, 1, 2, 0);
13480 void dc_report_survey_event(_adapter *padapter, union recv_frame *precv_frame)
13482 if(padapter->pbuddy_adapter != NULL &&
13483 padapter->DualMacConcurrent == _TRUE)
13485 report_survey_event(padapter->pbuddy_adapter, precv_frame);
13489 void dc_set_channel_bwmode_survey_done(_adapter *padapter)
13491 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
13492 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
13493 PADAPTER pbuddy_adapter = padapter->pbuddy_adapter;
13494 struct mlme_priv *pbuddy_mlmepriv = NULL;
13495 struct mlme_ext_priv *pbuddy_mlmeext = NULL;
13496 struct mlme_ext_info *pbuddy_mlmeinfo = NULL;
13501 if(pbuddy_adapter != NULL &&
13502 padapter->DualMacConcurrent == _TRUE)
13504 pbuddy_mlmepriv = &(pbuddy_adapter->mlmepriv);
13505 pbuddy_mlmeext = &pbuddy_adapter->mlmeextpriv;
13506 pbuddy_mlmeinfo = &(pbuddy_mlmeext->mlmext_info);
13508 if(check_fwstate(pbuddy_mlmepriv, _FW_LINKED))
13510 if(check_fwstate(pmlmepriv, _FW_LINKED) &&
13511 (pmlmeext->cur_bwmode == CHANNEL_WIDTH_40))
13513 cur_channel = pmlmeext->cur_channel;
13514 cur_bwmode = pmlmeext->cur_bwmode;
13515 cur_ch_offset = pmlmeext->cur_ch_offset;
13519 cur_channel = pbuddy_mlmeext->cur_channel;
13520 cur_bwmode = pbuddy_mlmeext->cur_bwmode;
13521 cur_ch_offset = pbuddy_mlmeext->cur_ch_offset;
13526 cur_channel = pmlmeext->cur_channel;
13527 cur_bwmode = pmlmeext->cur_bwmode;
13528 cur_ch_offset = pmlmeext->cur_ch_offset;
13531 set_channel_bwmode(padapter, cur_channel, cur_ch_offset, cur_bwmode);
13533 if (is_client_associated_to_ap(pbuddy_adapter) == _TRUE)
13536 issue_nulldata(pbuddy_adapter, NULL, 0, 0, 0);
13539 if(((pbuddy_mlmeinfo->state&0x03) == WIFI_FW_AP_STATE) &&
13540 check_fwstate(pbuddy_mlmepriv, _FW_LINKED))
13543 DBG_871X("survey done, current CH=%d, BW=%d, offset=%d\n", cur_channel, cur_bwmode, cur_ch_offset);
13545 DBG_871X("restart pbuddy_adapter's beacon\n");
13547 update_beacon(pbuddy_adapter, 0, NULL, _TRUE);
13552 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
13556 void dc_set_ap_channel_bandwidth(_adapter *padapter, u8 channel, u8 channel_offset, u8 bwmode)
13559 u8 val8, cur_channel, cur_bwmode, cur_ch_offset, change_band;
13561 struct registry_priv *pregpriv = &padapter->registrypriv;
13562 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
13563 WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network;
13564 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
13565 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
13566 struct HT_info_element *pht_info=NULL;
13567 _adapter *pbuddy_adapter = padapter->pbuddy_adapter;
13568 struct mlme_priv *pbuddy_mlmepriv = NULL;
13569 struct mlme_ext_priv *pbuddy_mlmeext = NULL;
13571 DBG_871X("dualmac_concurrent_ap_set_channel_bwmode ==>\n");
13573 cur_channel = channel;
13574 cur_bwmode = bwmode;
13575 cur_ch_offset = channel_offset;
13576 change_band = _FALSE;
13578 p = rtw_get_ie((pnetwork->IEs + sizeof(NDIS_802_11_FIXED_IEs)), _HT_ADD_INFO_IE_, &ie_len, (pnetwork->IELength - sizeof(NDIS_802_11_FIXED_IEs)));
13581 pht_info = (struct HT_info_element *)(p+2);
13584 if(pbuddy_adapter != NULL &&
13585 padapter->DualMacConcurrent == _TRUE)
13587 pbuddy_mlmepriv = &(pbuddy_adapter->mlmepriv);
13588 pbuddy_mlmeext = &pbuddy_adapter->mlmeextpriv;
13590 if(!check_fwstate(pbuddy_mlmepriv, _FW_LINKED|_FW_UNDER_LINKING|_FW_UNDER_SURVEY))
13592 set_channel_bwmode(padapter, cur_channel, cur_ch_offset, cur_bwmode);
13594 else if(check_fwstate(pbuddy_mlmepriv, _FW_LINKED)==_TRUE)
13596 //To sync cur_channel/cur_bwmode/cur_ch_offset with another adapter
13597 DBG_871X("Another iface is at linked state, sync cur_channel/cur_bwmode/cur_ch_offset\n");
13598 DBG_871X("Another adapter, CH=%d, BW=%d, offset=%d\n", pbuddy_mlmeext->cur_channel, pbuddy_mlmeext->cur_bwmode, pbuddy_mlmeext->cur_ch_offset);
13599 DBG_871X("Current adapter, CH=%d, BW=%d, offset=%d\n", cur_channel, cur_bwmode, cur_ch_offset);
13601 cur_channel = pbuddy_mlmeext->cur_channel;
13602 if(cur_bwmode == CHANNEL_WIDTH_40)
13605 pht_info->infos[0] &= ~(BIT(0)|BIT(1));
13607 if(pbuddy_mlmeext->cur_bwmode == CHANNEL_WIDTH_40)
13609 cur_ch_offset = pbuddy_mlmeext->cur_ch_offset;
13611 //to update cur_ch_offset value in beacon
13614 switch(cur_ch_offset)
13616 case HAL_PRIME_CHNL_OFFSET_LOWER:
13617 pht_info->infos[0] |= 0x1;
13619 case HAL_PRIME_CHNL_OFFSET_UPPER:
13620 pht_info->infos[0] |= 0x3;
13622 case HAL_PRIME_CHNL_OFFSET_DONT_CARE:
13628 else if(pbuddy_mlmeext->cur_bwmode == CHANNEL_WIDTH_20)
13630 cur_bwmode = CHANNEL_WIDTH_20;
13631 cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
13633 if(cur_channel>0 && cur_channel<5)
13636 pht_info->infos[0] |= 0x1;
13638 cur_bwmode = CHANNEL_WIDTH_40;
13639 cur_ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
13642 if(cur_channel>7 && cur_channel<(14+1))
13645 pht_info->infos[0] |= 0x3;
13647 cur_bwmode = CHANNEL_WIDTH_40;
13648 cur_ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
13651 set_channel_bwmode(padapter, cur_channel, cur_ch_offset, cur_bwmode);
13655 // to update channel value in beacon
13656 pnetwork->Configuration.DSConfig = cur_channel;
13657 p = rtw_get_ie((pnetwork->IEs + sizeof(NDIS_802_11_FIXED_IEs)), _DSSET_IE_, &ie_len, (pnetwork->IELength - sizeof(NDIS_802_11_FIXED_IEs)));
13659 *(p + 2) = cur_channel;
13662 pht_info->primary_channel = cur_channel;
13667 set_channel_bwmode(padapter, cur_channel, cur_ch_offset, cur_bwmode);
13670 DBG_871X("CH=%d, BW=%d, offset=%d\n", cur_channel, cur_bwmode, cur_ch_offset);
13672 if((channel <= 14 && cur_channel >= 36) ||
13673 (channel >= 36 && cur_channel <= 14))
13675 change_band = _TRUE;
13678 pmlmeext->cur_channel = cur_channel;
13679 pmlmeext->cur_bwmode = cur_bwmode;
13680 pmlmeext->cur_ch_offset = cur_ch_offset;
13682 if(change_band == _TRUE)
13683 change_band_update_ie(padapter, pnetwork);
13685 DBG_871X("dualmac_concurrent_ap_set_channel_bwmode <==\n");
13688 void dc_resume_xmit(_adapter *padapter)
13690 PADAPTER pbuddy_adapter = padapter->pbuddy_adapter;
13692 if(pbuddy_adapter != NULL &&
13693 padapter->DualMacConcurrent == _TRUE)
13695 DBG_871X("dc_resume_xmit, resume pbuddy_adapter Tx\n");
13696 rtw_os_xmit_schedule(pbuddy_adapter);
13700 u8 dc_check_xmit(_adapter *padapter)
13702 PADAPTER pbuddy_adapter = padapter->pbuddy_adapter;
13703 struct mlme_priv *pbuddy_mlmepriv = NULL;
13705 if(pbuddy_adapter != NULL &&
13706 padapter->DualMacConcurrent == _TRUE)
13708 pbuddy_mlmepriv = &(pbuddy_adapter->mlmepriv);
13709 if (check_fwstate(pbuddy_mlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING) == _TRUE)
13711 DBG_871X("dc_check_xmit pbuddy_adapter is under survey or under linking\n");
13720 #ifdef CONFIG_CONCURRENT_MODE
13721 sint check_buddy_mlmeinfo_state(_adapter *padapter, u32 state)
13723 PADAPTER pbuddy_adapter;
13724 struct mlme_ext_priv *pbuddy_mlmeext;
13725 struct mlme_ext_info *pbuddy_mlmeinfo;
13727 if(padapter == NULL)
13730 pbuddy_adapter = padapter->pbuddy_adapter;
13732 if(pbuddy_adapter == NULL)
13736 pbuddy_mlmeext = &pbuddy_adapter->mlmeextpriv;
13737 pbuddy_mlmeinfo = &(pbuddy_mlmeext->mlmext_info);
13739 if((pbuddy_mlmeinfo->state&0x03) == state)
13746 void concurrent_chk_joinbss_done(_adapter *padapter, int join_res)
13748 struct mlme_ext_priv *pmlmeext;
13749 struct mlme_ext_info *pmlmeinfo;
13750 PADAPTER pbuddy_adapter;
13751 struct mlme_priv *pbuddy_mlmepriv;
13752 struct mlme_ext_priv *pbuddy_mlmeext;
13753 struct mlme_ext_info *pbuddy_mlmeinfo;
13754 WLAN_BSSID_EX *pbuddy_network_mlmeext;
13755 WLAN_BSSID_EX *pnetwork;
13757 pmlmeext = &padapter->mlmeextpriv;
13758 pmlmeinfo = &(pmlmeext->mlmext_info);
13761 if(!rtw_buddy_adapter_up(padapter))
13763 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
13767 pbuddy_adapter = padapter->pbuddy_adapter;
13768 pbuddy_mlmepriv = &(pbuddy_adapter->mlmepriv);
13769 pnetwork = (WLAN_BSSID_EX *)&pbuddy_mlmepriv->cur_network.network;
13770 pbuddy_mlmeext = &pbuddy_adapter->mlmeextpriv;
13771 pbuddy_mlmeinfo = &(pbuddy_mlmeext->mlmext_info);
13772 pbuddy_network_mlmeext = &(pbuddy_mlmeinfo->network);
13774 if(((pbuddy_mlmeinfo->state&0x03) == WIFI_FW_AP_STATE) &&
13775 check_fwstate(pbuddy_mlmepriv, _FW_LINKED))
13777 //restart and update beacon
13779 DBG_871X("after join,primary adapter, CH=%d, BW=%d, offset=%d\n"
13780 , pmlmeext->cur_channel, pmlmeext->cur_bwmode, pmlmeext->cur_ch_offset);
13787 u8 change_band = _FALSE;
13788 struct HT_info_element *pht_info=NULL;
13790 if((pmlmeext->cur_channel <= 14 && pbuddy_mlmeext->cur_channel >= 36) ||
13791 (pmlmeext->cur_channel >= 36 && pbuddy_mlmeext->cur_channel <= 14))
13792 change_band = _TRUE;
13794 p = rtw_get_ie((pbuddy_network_mlmeext->IEs + sizeof(NDIS_802_11_FIXED_IEs)), _HT_ADD_INFO_IE_, &ie_len, (pbuddy_network_mlmeext->IELength - sizeof(NDIS_802_11_FIXED_IEs)));
13797 pht_info = (struct HT_info_element *)(p+2);
13798 pht_info->infos[0] &= ~HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK; //no secondary channel is present
13801 pbuddy_mlmeext->cur_channel = pmlmeext->cur_channel;
13802 #ifdef CONFIG_80211AC_VHT
13803 if(pbuddy_mlmeext->cur_bwmode == CHANNEL_WIDTH_80)
13805 u8 *pvht_cap_ie, *pvht_op_ie;
13806 int vht_cap_ielen, vht_op_ielen;
13808 pvht_cap_ie = rtw_get_ie((pbuddy_network_mlmeext->IEs + sizeof(NDIS_802_11_FIXED_IEs)), EID_VHTCapability, &vht_cap_ielen, (pbuddy_network_mlmeext->IELength - sizeof(NDIS_802_11_FIXED_IEs)));
13809 pvht_op_ie = rtw_get_ie((pbuddy_network_mlmeext->IEs + sizeof(NDIS_802_11_FIXED_IEs)), EID_VHTOperation, &vht_op_ielen, (pbuddy_network_mlmeext->IELength - sizeof(NDIS_802_11_FIXED_IEs)));
13811 if(pmlmeext->cur_channel <= 14) // downgrade to 20/40Mhz
13813 //modify vht cap ie
13814 if( pvht_cap_ie && vht_cap_ielen)
13816 SET_VHT_CAPABILITY_ELE_SHORT_GI80M(pvht_cap_ie+2, 0);
13820 if( pvht_op_ie && vht_op_ielen)
13822 SET_VHT_OPERATION_ELE_CHL_WIDTH(pvht_op_ie+2, 0); //change to 20/40Mhz
13823 SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ1(pvht_op_ie+2, 0);
13824 SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ2(pvht_op_ie+2, 0);
13825 //SET_VHT_OPERATION_ELE_BASIC_MCS_SET(p+2, 0xFFFF);
13826 pbuddy_mlmeext->cur_bwmode = CHANNEL_WIDTH_40;
13833 pbuddy_mlmeext->cur_bwmode = CHANNEL_WIDTH_80;
13835 if(pmlmeext->cur_bwmode == CHANNEL_WIDTH_40 ||
13836 pmlmeext->cur_bwmode == CHANNEL_WIDTH_80)
13838 pbuddy_mlmeext->cur_ch_offset = pmlmeext->cur_ch_offset;
13840 else if(pmlmeext->cur_bwmode == CHANNEL_WIDTH_20)
13842 pbuddy_mlmeext->cur_ch_offset = rtw_get_offset_by_ch(pmlmeext->cur_channel);
13845 //modify ht info ie
13847 pht_info->infos[0] &= ~HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK;
13849 switch(pbuddy_mlmeext->cur_ch_offset)
13851 case HAL_PRIME_CHNL_OFFSET_LOWER:
13853 pht_info->infos[0] |= HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE;
13854 //cur_bwmode = CHANNEL_WIDTH_40;
13856 case HAL_PRIME_CHNL_OFFSET_UPPER:
13858 pht_info->infos[0] |= HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW;
13859 //cur_bwmode = CHANNEL_WIDTH_40;
13861 case HAL_PRIME_CHNL_OFFSET_DONT_CARE:
13864 pht_info->infos[0] &= ~HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK;
13865 pbuddy_mlmeext->cur_bwmode = CHANNEL_WIDTH_20;
13866 pbuddy_mlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
13871 center_freq = rtw_get_center_ch(pbuddy_mlmeext->cur_channel, pbuddy_mlmeext->cur_bwmode, HAL_PRIME_CHNL_OFFSET_LOWER);
13872 if( pvht_op_ie && vht_op_ielen)
13873 SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ1(pvht_op_ie+2, center_freq);
13875 set_channel_bwmode(padapter, pbuddy_mlmeext->cur_channel, pbuddy_mlmeext->cur_ch_offset, pbuddy_mlmeext->cur_bwmode);
13880 #endif //CONFIG_80211AC_VHT
13882 if(pbuddy_mlmeext->cur_bwmode == CHANNEL_WIDTH_40)
13884 p = rtw_get_ie((pbuddy_network_mlmeext->IEs + sizeof(NDIS_802_11_FIXED_IEs)), _HT_ADD_INFO_IE_, &ie_len, (pbuddy_network_mlmeext->IELength - sizeof(NDIS_802_11_FIXED_IEs)));
13887 pht_info = (struct HT_info_element *)(p+2);
13888 pht_info->infos[0] &= ~HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK; //no secondary channel is present
13891 if(pmlmeext->cur_bwmode == CHANNEL_WIDTH_40 ||
13892 pmlmeext->cur_bwmode == CHANNEL_WIDTH_80)
13894 pbuddy_mlmeext->cur_ch_offset = pmlmeext->cur_ch_offset;
13896 //to update cur_ch_offset value in beacon
13899 switch(pmlmeext->cur_ch_offset)
13901 case HAL_PRIME_CHNL_OFFSET_LOWER:
13902 pht_info->infos[0] |= HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE;
13904 case HAL_PRIME_CHNL_OFFSET_UPPER:
13905 pht_info->infos[0] |= HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW;
13907 case HAL_PRIME_CHNL_OFFSET_DONT_CARE:
13915 else if(pmlmeext->cur_bwmode == CHANNEL_WIDTH_20)
13917 pbuddy_mlmeext->cur_ch_offset = rtw_get_offset_by_ch(pmlmeext->cur_channel);
13919 switch(pbuddy_mlmeext->cur_ch_offset)
13921 case HAL_PRIME_CHNL_OFFSET_LOWER:
13923 pht_info->infos[0] |= HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE;
13924 pbuddy_mlmeext->cur_bwmode = CHANNEL_WIDTH_40;
13926 case HAL_PRIME_CHNL_OFFSET_UPPER:
13928 pht_info->infos[0] |= HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW;
13929 pbuddy_mlmeext->cur_bwmode = CHANNEL_WIDTH_40;
13931 case HAL_PRIME_CHNL_OFFSET_DONT_CARE:
13934 pht_info->infos[0] &= ~HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK;
13935 pbuddy_mlmeext->cur_bwmode = CHANNEL_WIDTH_20;
13936 pbuddy_mlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
13942 set_channel_bwmode(padapter, pbuddy_mlmeext->cur_channel, pbuddy_mlmeext->cur_ch_offset, pbuddy_mlmeext->cur_bwmode);
13947 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
13951 // to update channel value in beacon
13952 pbuddy_network_mlmeext->Configuration.DSConfig = pmlmeext->cur_channel;
13953 p = rtw_get_ie((pbuddy_network_mlmeext->IEs + sizeof(NDIS_802_11_FIXED_IEs)), _DSSET_IE_, &ie_len, (pbuddy_network_mlmeext->IELength - sizeof(NDIS_802_11_FIXED_IEs)));
13955 *(p + 2) = pmlmeext->cur_channel;
13957 p = rtw_get_ie((pbuddy_network_mlmeext->IEs + sizeof(NDIS_802_11_FIXED_IEs)), _HT_ADD_INFO_IE_, &ie_len, (pbuddy_network_mlmeext->IELength - sizeof(NDIS_802_11_FIXED_IEs)));
13960 pht_info = (struct HT_info_element *)(p+2);
13961 pht_info->primary_channel = pmlmeext->cur_channel;
13964 //buddy interface band is different from current interface, update ERP, support rate, ext support rate IE
13965 if(change_band == _TRUE)
13966 change_band_update_ie(pbuddy_adapter, pbuddy_network_mlmeext);
13970 // switch back to original channel/bwmode/ch_offset;
13971 set_channel_bwmode(padapter, pbuddy_mlmeext->cur_channel, pbuddy_mlmeext->cur_ch_offset, pbuddy_mlmeext->cur_bwmode);
13974 DBG_871X("after join, second adapter, CH=%d, BW=%d, offset=%d\n", pbuddy_mlmeext->cur_channel, pbuddy_mlmeext->cur_bwmode, pbuddy_mlmeext->cur_ch_offset);
13976 DBG_871X("update pbuddy_adapter's beacon\n");
13978 _rtw_memcpy(pnetwork, pbuddy_network_mlmeext, sizeof(WLAN_BSSID_EX));
13979 //update bmc rate to avoid bb cck hang
13980 update_bmc_sta(pbuddy_adapter);
13981 update_beacon(pbuddy_adapter, 0, NULL, _TRUE);
13984 else if(((pbuddy_mlmeinfo->state&0x03) == WIFI_FW_STATION_STATE) &&
13985 check_fwstate(pbuddy_mlmepriv, _FW_LINKED))
13989 pbuddy_mlmeext->cur_channel = pmlmeext->cur_channel;
13990 if(pbuddy_mlmeext->cur_bwmode == CHANNEL_WIDTH_40 ||
13991 pbuddy_mlmeext->cur_bwmode == CHANNEL_WIDTH_80)
13992 set_channel_bwmode(padapter, pbuddy_mlmeext->cur_channel, pbuddy_mlmeext->cur_ch_offset, pbuddy_mlmeext->cur_bwmode);
13993 else if(pmlmeext->cur_bwmode == CHANNEL_WIDTH_40 ||
13994 pmlmeext->cur_bwmode == CHANNEL_WIDTH_80)
13995 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
13997 set_channel_bwmode(padapter, pmlmeext->cur_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
14001 // switch back to original channel/bwmode/ch_offset;
14002 set_channel_bwmode(padapter, pbuddy_mlmeext->cur_channel, pbuddy_mlmeext->cur_ch_offset, pbuddy_mlmeext->cur_bwmode);
14007 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
14011 #endif //CONFIG_CONCURRENT_MODE
14013 int rtw_chk_start_clnt_join(_adapter *padapter, u8 *ch, u8 *bw, u8 *offset)
14015 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
14016 unsigned char cur_ch = pmlmeext->cur_channel;
14017 unsigned char cur_bw = pmlmeext->cur_bwmode;
14018 unsigned char cur_ch_offset = pmlmeext->cur_ch_offset;
14019 bool chbw_allow = _TRUE;
14020 bool connect_allow = _TRUE;
14022 #ifdef CONFIG_CONCURRENT_MODE
14023 PADAPTER pbuddy_adapter;
14024 struct mlme_ext_priv *pbuddy_mlmeext;
14025 struct mlme_ext_info *pbuddy_pmlmeinfo;
14026 struct mlme_priv *pbuddy_mlmepriv;
14029 if (!ch || !bw || !offset) {
14030 connect_allow = _FALSE;
14036 connect_allow = _FALSE;
14037 DBG_871X_LEVEL(_drv_err_, FUNC_ADPT_FMT" cur_ch:%u\n"
14038 , FUNC_ADPT_ARG(padapter), cur_ch);
14043 #ifdef CONFIG_CONCURRENT_MODE
14044 if (!rtw_buddy_adapter_up(padapter)) {
14048 pbuddy_adapter = padapter->pbuddy_adapter;
14049 pbuddy_mlmeext = &pbuddy_adapter->mlmeextpriv;
14050 pbuddy_pmlmeinfo = &(pbuddy_mlmeext->mlmext_info);
14051 pbuddy_mlmepriv = &(pbuddy_adapter->mlmepriv);
14053 if((pbuddy_pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE)//for AP MODE
14055 DBG_871X("start_clnt_join: "ADPT_FMT"(ch=%d, bw=%d, ch_offset=%d)"
14056 ", "ADPT_FMT" AP mode(ch=%d, bw=%d, ch_offset=%d)\n",
14057 ADPT_ARG(padapter), pmlmeext->cur_channel, pmlmeext->cur_bwmode, pmlmeext->cur_ch_offset,
14058 ADPT_ARG(pbuddy_adapter), pbuddy_mlmeext->cur_channel, pbuddy_mlmeext->cur_bwmode, pbuddy_mlmeext->cur_ch_offset);
14060 if(pmlmeext->cur_channel != pbuddy_mlmeext->cur_channel)
14062 chbw_allow = _FALSE;
14064 else if((pmlmeext->cur_bwmode == CHANNEL_WIDTH_40) &&
14065 (pbuddy_mlmeext->cur_bwmode == CHANNEL_WIDTH_40) &&
14066 (pmlmeext->cur_ch_offset != pbuddy_mlmeext->cur_ch_offset))
14068 chbw_allow = _FALSE;
14070 else if((pmlmeext->cur_bwmode == CHANNEL_WIDTH_20) &&
14071 ((pbuddy_mlmeext->cur_bwmode == CHANNEL_WIDTH_40)||
14072 (pbuddy_mlmeext->cur_bwmode == CHANNEL_WIDTH_80)) )
14074 cur_ch = pmlmeext->cur_channel;
14075 cur_bw = pbuddy_mlmeext->cur_bwmode;
14076 cur_ch_offset = pbuddy_mlmeext->cur_ch_offset;
14079 DBG_871X("start_clnt_join: connect_allow:%d, chbw_allow:%d\n", connect_allow, chbw_allow);
14080 if (chbw_allow == _FALSE) {
14081 #ifdef CONFIG_SPCT_CH_SWITCH
14083 rtw_ap_inform_ch_switch(pbuddy_adapter, pmlmeext->cur_channel , pmlmeext->cur_ch_offset);
14087 //issue deauth to all stas if if2 is at ap mode
14088 rtw_sta_flush(pbuddy_adapter);
14090 rtw_hal_set_hwreg(padapter, HW_VAR_CHECK_TXBUF, 0);
14093 else if(check_fwstate(pbuddy_mlmepriv, _FW_LINKED) == _TRUE &&
14094 check_fwstate(pbuddy_mlmepriv, WIFI_STATION_STATE) == _TRUE) //for Client Mode/p2p client
14096 DBG_871X("start_clnt_join: "ADPT_FMT"(ch=%d, bw=%d, ch_offset=%d)"
14097 ", "ADPT_FMT" STA mode(ch=%d, bw=%d, ch_offset=%d)\n",
14098 ADPT_ARG(padapter), pmlmeext->cur_channel, pmlmeext->cur_bwmode, pmlmeext->cur_ch_offset,
14099 ADPT_ARG(pbuddy_adapter), pbuddy_mlmeext->cur_channel, pbuddy_mlmeext->cur_bwmode, pbuddy_mlmeext->cur_ch_offset);
14101 if(pmlmeext->cur_channel != pbuddy_mlmeext->cur_channel)
14103 chbw_allow = _FALSE;
14105 else if((pmlmeext->cur_bwmode == CHANNEL_WIDTH_20) &&
14106 (pbuddy_mlmeext->cur_bwmode == CHANNEL_WIDTH_40))
14108 cur_bw = CHANNEL_WIDTH_40;
14109 cur_ch_offset = pbuddy_mlmeext->cur_ch_offset;
14111 else if((pmlmeext->cur_bwmode == CHANNEL_WIDTH_20) &&
14112 (pbuddy_mlmeext->cur_bwmode == CHANNEL_WIDTH_80))
14114 cur_bw = CHANNEL_WIDTH_80;
14115 cur_ch_offset = pbuddy_mlmeext->cur_ch_offset;
14117 else if((pmlmeext->cur_bwmode == CHANNEL_WIDTH_40) &&
14118 (pbuddy_mlmeext->cur_bwmode == CHANNEL_WIDTH_40) &&
14119 (pmlmeext->cur_ch_offset != pbuddy_mlmeext->cur_ch_offset))
14121 chbw_allow = _FALSE;
14123 else if((pmlmeext->cur_bwmode == CHANNEL_WIDTH_40) &&
14124 (pbuddy_mlmeext->cur_bwmode == CHANNEL_WIDTH_80))
14126 if(pmlmeext->cur_ch_offset != pbuddy_mlmeext->cur_ch_offset)
14128 chbw_allow = _FALSE;
14132 cur_bw = CHANNEL_WIDTH_80;
14135 else if((pmlmeext->cur_bwmode == CHANNEL_WIDTH_80) &&
14136 (pbuddy_mlmeext->cur_bwmode == CHANNEL_WIDTH_40))
14138 if(pmlmeext->cur_ch_offset != pbuddy_mlmeext->cur_ch_offset)
14140 chbw_allow = _FALSE;
14143 else if((pmlmeext->cur_bwmode == CHANNEL_WIDTH_80) &&
14144 (pbuddy_mlmeext->cur_bwmode == CHANNEL_WIDTH_80))
14146 if(pmlmeext->cur_ch_offset != pbuddy_mlmeext->cur_ch_offset)
14148 chbw_allow = _FALSE;
14153 connect_allow = chbw_allow;
14155 #ifdef CONFIG_CFG80211_ONECHANNEL_UNDER_CONCURRENT
14156 #if defined(CONFIG_P2P) && defined(CONFIG_IOCTL_CFG80211)
14157 /* wlan0-sta mode has higher priority than p2p0-p2p client */
14158 if (!rtw_p2p_chk_state(&(pbuddy_adapter->wdinfo), P2P_STATE_NONE)
14159 && pbuddy_adapter->wdinfo.driver_interface == DRIVER_CFG80211)
14161 connect_allow = _TRUE;
14163 #endif /* CONFIG_P2P && CONFIG_IOCTL_CFG80211 */
14165 connect_allow = _TRUE;
14166 #endif /* CONFIG_CFG80211_ONECHANNEL_UNDER_CONCURRENT */
14168 DBG_871X("start_clnt_join: connect_allow:%d, chbw_allow:%d\n", connect_allow, chbw_allow);
14169 if (connect_allow == _TRUE && chbw_allow == _FALSE) {
14170 /* disconnect buddy's connection */
14171 rtw_disassoc_cmd(pbuddy_adapter, 500, _FALSE);
14172 rtw_indicate_disconnect(pbuddy_adapter);
14173 rtw_free_assoc_resources(pbuddy_adapter, 1);
14177 #endif /* CONFIG_CONCURRENT_MODE */
14181 if (connect_allow == _TRUE) {
14182 DBG_871X("start_join_set_ch_bw: ch=%d, bwmode=%d, ch_offset=%d\n", cur_ch, cur_bw, cur_ch_offset);
14185 *offset = cur_ch_offset;
14188 return connect_allow == _TRUE ? _SUCCESS : _FAIL;
14191 /* Find union about ch, bw, ch_offset of all linked/linking interfaces */
14192 int rtw_get_ch_setting_union(_adapter *adapter, u8 *ch, u8 *bw, u8 *offset)
14194 struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
14196 struct mlme_ext_priv *mlmeext;
14199 u8 bw_ret = CHANNEL_WIDTH_20;
14200 u8 offset_ret = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
14204 if (bw) *bw = CHANNEL_WIDTH_20;
14205 if (offset) *offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
14207 for (i = 0; i<dvobj->iface_nums; i++) {
14208 iface = dvobj->padapters[i];
14209 mlmeext = &iface->mlmeextpriv;
14211 if (!check_fwstate(&iface->mlmepriv, _FW_LINKED|_FW_UNDER_LINKING))
14215 ch_ret = mlmeext->cur_channel;
14216 bw_ret = mlmeext->cur_bwmode;
14217 offset_ret = mlmeext->cur_ch_offset;
14222 if (ch_ret != mlmeext->cur_channel) {
14227 if (bw_ret < mlmeext->cur_bwmode) {
14228 bw_ret = mlmeext->cur_bwmode;
14229 offset_ret = mlmeext->cur_ch_offset;
14230 } else if (bw_ret == mlmeext->cur_bwmode && offset_ret != mlmeext->cur_ch_offset) {
14239 if (ch) *ch = ch_ret;
14240 if (bw) *bw = bw_ret;
14241 if (offset) *offset = offset_ret;
14247 u8 set_ch_hdl(_adapter *padapter, u8 *pbuf)
14249 struct set_ch_parm *set_ch_parm;
14250 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
14251 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
14254 return H2C_PARAMETERS_ERROR;
14256 set_ch_parm = (struct set_ch_parm *)pbuf;
14258 DBG_871X(FUNC_NDEV_FMT" ch:%u, bw:%u, ch_offset:%u\n",
14259 FUNC_NDEV_ARG(padapter->pnetdev),
14260 set_ch_parm->ch, set_ch_parm->bw, set_ch_parm->ch_offset);
14262 pmlmeext->cur_channel = set_ch_parm->ch;
14263 pmlmeext->cur_ch_offset = set_ch_parm->ch_offset;
14264 pmlmeext->cur_bwmode = set_ch_parm->bw;
14266 set_channel_bwmode(padapter, set_ch_parm->ch, set_ch_parm->ch_offset, set_ch_parm->bw);
14268 return H2C_SUCCESS;
14271 u8 set_chplan_hdl(_adapter *padapter, unsigned char *pbuf)
14273 struct SetChannelPlan_param *setChannelPlan_param;
14274 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
14275 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
14278 return H2C_PARAMETERS_ERROR;
14280 setChannelPlan_param = (struct SetChannelPlan_param *)pbuf;
14282 pmlmeext->max_chan_nums = init_channel_set(padapter, setChannelPlan_param->channel_plan, pmlmeext->channel_set);
14283 init_channel_list(padapter, pmlmeext->channel_set, pmlmeext->max_chan_nums, &pmlmeext->channel_list);
14285 #ifdef CONFIG_IOCTL_CFG80211
14286 rtw_reg_notify_by_driver(padapter);
14287 #endif //CONFIG_IOCTL_CFG80211
14289 return H2C_SUCCESS;
14292 u8 led_blink_hdl(_adapter *padapter, unsigned char *pbuf)
14294 struct LedBlink_param *ledBlink_param;
14297 return H2C_PARAMETERS_ERROR;
14299 ledBlink_param = (struct LedBlink_param *)pbuf;
14301 #ifdef CONFIG_LED_HANDLED_BY_CMD_THREAD
14302 BlinkHandler((PLED_DATA)ledBlink_param->pLed);
14305 return H2C_SUCCESS;
14308 u8 set_csa_hdl(_adapter *padapter, unsigned char *pbuf)
14311 struct SetChannelSwitch_param *setChannelSwitch_param;
14313 u8 gval8 = 0x00, sval8 = 0xff;
14316 return H2C_PARAMETERS_ERROR;
14318 setChannelSwitch_param = (struct SetChannelSwitch_param *)pbuf;
14319 new_ch_no = setChannelSwitch_param->new_ch_no;
14321 rtw_hal_get_hwreg(padapter, HW_VAR_TXPAUSE, &gval8);
14323 rtw_hal_set_hwreg(padapter, HW_VAR_TXPAUSE, &sval8);
14325 DBG_871X("DFS detected! Swiching channel to %d!\n", new_ch_no);
14326 SelectChannel(padapter, new_ch_no);
14328 rtw_hal_set_hwreg(padapter, HW_VAR_TXPAUSE, &gval8);
14330 rtw_disassoc_cmd(padapter, 0, _FALSE);
14331 rtw_indicate_disconnect(padapter);
14332 rtw_free_assoc_resources(padapter, 1);
14333 rtw_free_network_queue(padapter, _TRUE);
14335 if ( ((new_ch_no >= 52) && (new_ch_no <= 64)) ||((new_ch_no >= 100) && (new_ch_no <= 140)) ) {
14336 DBG_871X("Switched to DFS band (ch %02x) again!!\n", new_ch_no);
14339 return H2C_SUCCESS;
14341 return H2C_REJECTED;
14342 #endif //CONFIG_DFS
14346 // TDLS_ESTABLISHED : write RCR DATA BIT
14347 // TDLS_CS_OFF : go back to the channel linked with AP, terminating channel switch procedure
14348 // TDLS_INIT_CH_SEN : init channel sensing, receive all data and mgnt frame
14349 // TDLS_DONE_CH_SEN: channel sensing and report candidate channel
14350 // TDLS_OFF_CH : first time set channel to off channel
14351 // TDLS_BASE_CH : go back tp the channel linked with AP when set base channel as target channel
14352 // TDLS_P_OFF_CH : periodically go to off channel
14353 // TDLS_P_BASE_CH : periodically go back to base channel
14354 // TDLS_RS_RCR : restore RCR
14355 // TDLS_TEAR_STA : free tdls sta
14356 u8 tdls_hdl(_adapter *padapter, unsigned char *pbuf)
14360 struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
14361 struct TDLSoption_param *TDLSoption;
14362 struct sta_info *ptdls_sta;
14363 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
14364 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
14365 u8 survey_channel, i, min, option;
14368 return H2C_PARAMETERS_ERROR;
14370 TDLSoption = (struct TDLSoption_param *)pbuf;
14372 ptdls_sta = rtw_get_stainfo( &(padapter->stapriv), TDLSoption->addr );
14373 option = TDLSoption->option;
14375 if( ptdls_sta == NULL )
14377 if( option != TDLS_RS_RCR )
14378 return H2C_REJECTED;
14381 //_enter_critical_bh(&(ptdlsinfo->hdl_lock), &irqL);
14382 DBG_871X("[%s] option:%d\n", __FUNCTION__, option);
14385 case TDLS_ESTABLISHED:
14389 //leave ALL PS when TDLS is established
14390 rtw_pwr_wakeup(padapter);
14392 //As long as TDLS handshake success, we should set RCR_CBSSID_DATA bit to 0
14393 //so we can receive all kinds of data frames.
14394 rtw_hal_set_hwreg(padapter, HW_VAR_TDLS_WRCR, 0);
14395 DBG_871X("Created Direct Link with "MAC_FMT"\n", MAC_ARG(ptdls_sta->hwaddr));
14397 pmlmeinfo->FW_sta_info[ptdls_sta->mac_id].psta = ptdls_sta;
14398 //set TDLS sta rate.
14399 //update station supportRate
14400 rtw_hal_update_sta_rate_mask(padapter, ptdls_sta);
14401 if(padapter->mlmeextpriv.cur_channel > 14) {
14402 if (ptdls_sta->ra_mask & 0xffff000)
14403 sta_band |= WIRELESS_11_5N ;
14405 if (ptdls_sta->ra_mask & 0xff0)
14406 sta_band |= WIRELESS_11A;
14409 #ifdef CONFIG_80211AC_VHT
14410 if (ptdls_sta->vhtpriv.vht_option) {
14411 sta_band = WIRELESS_11_5AC;
14416 if (ptdls_sta->ra_mask & 0xffff000)
14417 sta_band |= WIRELESS_11_24N;
14419 if (ptdls_sta->ra_mask & 0xff0)
14420 sta_band |= WIRELESS_11G;
14422 if (ptdls_sta->ra_mask & 0x0f)
14423 sta_band |= WIRELESS_11B;
14425 ptdls_sta->wireless_mode = sta_band;
14426 ptdls_sta->raid = rtw_hal_networktype_to_raid(padapter,ptdls_sta);
14427 set_sta_rate(padapter, ptdls_sta);
14429 rtw_hal_set_odm_var(padapter,HAL_ODM_STA_INFO,ptdls_sta,_TRUE);
14433 ptdls_sta->tdls_sta_state |= TDLS_WAIT_PTR_STATE;
14434 issue_tdls_peer_traffic_indication(padapter, ptdls_sta);
14435 _set_timer(&ptdls_sta->pti_timer, TDLS_PTI_TIME);
14438 _cancel_timer_ex(&ptdls_sta->base_ch_timer);
14439 _cancel_timer_ex(&ptdls_sta->off_ch_timer);
14440 SelectChannel(padapter, pmlmeext->cur_channel);
14441 ptdls_sta->tdls_sta_state &= ~(TDLS_CH_SWITCH_ON_STATE |
14442 TDLS_PEER_AT_OFF_STATE |
14443 TDLS_AT_OFF_CH_STATE);
14444 DBG_871X("go back to base channel\n ");
14445 issue_nulldata(padapter, NULL, 0, 0, 0);
14447 case TDLS_INIT_CH_SEN:
14448 rtw_hal_set_hwreg(padapter, HW_VAR_TDLS_INIT_CH_SEN, 0);
14449 pmlmeext->sitesurvey_res.channel_idx = 0;
14450 ptdls_sta->option = TDLS_DONE_CH_SEN;
14451 rtw_tdls_cmd(padapter, ptdls_sta->hwaddr, TDLS_DONE_CH_SEN);
14453 case TDLS_DONE_CH_SEN:
14454 survey_channel = pmlmeext->channel_set[pmlmeext->sitesurvey_res.channel_idx].ChannelNum;
14455 if(survey_channel){
14456 SelectChannel(padapter, survey_channel);
14457 ptdlsinfo->cur_channel = survey_channel;
14458 pmlmeext->sitesurvey_res.channel_idx++;
14459 _set_timer(&ptdls_sta->option_timer, SURVEY_TO);
14461 SelectChannel(padapter, pmlmeext->cur_channel);
14463 rtw_hal_set_hwreg(padapter, HW_VAR_TDLS_DONE_CH_SEN, 0);
14465 if(ptdlsinfo->ch_sensing==1){
14466 ptdlsinfo->ch_sensing=0;
14467 ptdlsinfo->cur_channel=1;
14468 min=ptdlsinfo->collect_pkt_num[0];
14469 for(i=1; i<MAX_CHANNEL_NUM-1; i++){
14470 if(min > ptdlsinfo->collect_pkt_num[i]){
14471 ptdlsinfo->cur_channel=i+1;
14472 min=ptdlsinfo->collect_pkt_num[i];
14474 ptdlsinfo->collect_pkt_num[i]=0;
14476 ptdlsinfo->collect_pkt_num[0]=0;
14477 ptdlsinfo->candidate_ch=ptdlsinfo->cur_channel;
14478 DBG_871X("TDLS channel sensing done, candidate channel: %02x\n", ptdlsinfo->candidate_ch);
14479 ptdlsinfo->cur_channel=0;
14483 if(ptdls_sta->tdls_sta_state & TDLS_PEER_SLEEP_STATE){
14484 ptdls_sta->tdls_sta_state |= TDLS_APSD_CHSW_STATE;
14486 //send null data with pwrbit==1 before send ch_switching_req to peer STA.
14487 issue_nulldata(padapter, NULL, 1, 0, 0);
14489 ptdls_sta->tdls_sta_state |= TDLS_CH_SW_INITIATOR_STATE;
14491 issue_tdls_ch_switch_req(padapter, ptdls_sta->hwaddr);
14492 DBG_871X("issue tdls ch switch req\n");
14497 issue_nulldata(padapter, NULL, 1, 0, 0);
14498 SelectChannel(padapter, ptdls_sta->off_ch);
14500 DBG_871X("change channel to tar ch:%02x\n", ptdls_sta->off_ch);
14501 ptdls_sta->tdls_sta_state |= TDLS_AT_OFF_CH_STATE;
14502 ptdls_sta->tdls_sta_state &= ~(TDLS_PEER_AT_OFF_STATE);
14503 _set_timer(&ptdls_sta->option_timer, (u32)ptdls_sta->ch_switch_time);
14506 _cancel_timer_ex(&ptdls_sta->base_ch_timer);
14507 _cancel_timer_ex(&ptdls_sta->off_ch_timer);
14508 SelectChannel(padapter, pmlmeext->cur_channel);
14509 ptdls_sta->tdls_sta_state &= ~(TDLS_CH_SWITCH_ON_STATE |
14510 TDLS_PEER_AT_OFF_STATE |
14511 TDLS_AT_OFF_CH_STATE);
14512 DBG_871X("go back to base channel\n ");
14513 issue_nulldata(padapter, NULL, 0, 0, 0);
14514 _set_timer(&ptdls_sta->option_timer, (u32)ptdls_sta->ch_switch_time);
14516 case TDLS_P_OFF_CH:
14517 SelectChannel(padapter, pmlmeext->cur_channel);
14518 issue_nulldata(padapter, NULL, 0, 0, 0);
14519 DBG_871X("change channel to base ch:%02x\n", pmlmeext->cur_channel);
14520 ptdls_sta->tdls_sta_state &= ~(TDLS_PEER_AT_OFF_STATE| TDLS_AT_OFF_CH_STATE);
14521 _set_timer(&ptdls_sta->off_ch_timer, TDLS_STAY_TIME);
14523 case TDLS_P_BASE_CH:
14524 issue_nulldata(ptdls_sta->padapter, NULL, 1, 0, 0);
14525 SelectChannel(padapter, ptdls_sta->off_ch);
14526 DBG_871X("change channel to off ch:%02x\n", ptdls_sta->off_ch);
14527 ptdls_sta->tdls_sta_state |= TDLS_AT_OFF_CH_STATE;
14528 if((ptdls_sta->tdls_sta_state & TDLS_PEER_AT_OFF_STATE) != TDLS_PEER_AT_OFF_STATE){
14529 issue_nulldata_to_TDLS_peer_STA(padapter, ptdls_sta->hwaddr, 0, 3, 300);
14531 _set_timer(&ptdls_sta->base_ch_timer, TDLS_STAY_TIME);
14534 rtw_hal_set_hwreg(padapter, HW_VAR_TDLS_RS_RCR, 0);
14535 DBG_871X("wirte REG_RCR, set bit6 on\n");
14537 case TDLS_TEAR_STA:
14538 free_tdls_sta(padapter, ptdls_sta);
14543 //_exit_critical_bh(&(ptdlsinfo->hdl_lock), &irqL);
14545 return H2C_SUCCESS;
14547 return H2C_REJECTED;
14548 #endif //CONFIG_TDLS