]>
Commit | Line | Data |
---|---|---|
7ef8ded0 LF |
1 | /****************************************************************************** |
2 | * | |
3 | * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify it | |
6 | * under the terms of version 2 of the GNU General Public License as | |
7 | * published by the Free Software Foundation. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
12 | * more details. | |
13 | * | |
7ef8ded0 LF |
14 | ******************************************************************************/ |
15 | #define _RTL8188E_CMD_C_ | |
16 | ||
17 | #include <osdep_service.h> | |
18 | #include <drv_types.h> | |
19 | #include <recv_osdep.h> | |
7ef8ded0 LF |
20 | #include <mlme_osdep.h> |
21 | #include <rtw_ioctl_set.h> | |
22 | ||
23 | #include <rtl8188e_hal.h> | |
24 | ||
25 | #define RTL88E_MAX_H2C_BOX_NUMS 4 | |
26 | #define RTL88E_MAX_CMD_LEN 7 | |
27 | #define RTL88E_MESSAGE_BOX_SIZE 4 | |
28 | #define RTL88E_EX_MESSAGE_BOX_SIZE 4 | |
29 | ||
30 | static u8 _is_fw_read_cmd_down(struct adapter *adapt, u8 msgbox_num) | |
31 | { | |
32 | u8 read_down = false; | |
33 | int retry_cnts = 100; | |
34 | ||
35 | u8 valid; | |
36 | ||
37 | do { | |
c7b2e995 | 38 | valid = usb_read8(adapt, REG_HMETFR) & BIT(msgbox_num); |
c41cd503 | 39 | if (valid == 0) |
7ef8ded0 LF |
40 | read_down = true; |
41 | } while ((!read_down) && (retry_cnts--)); | |
42 | ||
43 | return read_down; | |
44 | } | |
45 | ||
46 | /***************************************** | |
47 | * H2C Msg format : | |
48 | * 0x1DF - 0x1D0 | |
49 | *| 31 - 8 | 7-5 4 - 0 | | |
50 | *| h2c_msg |Class_ID CMD_ID | | |
51 | * | |
52 | * Extend 0x1FF - 0x1F0 | |
53 | *|31 - 0 | | |
54 | *|ext_msg| | |
55 | ******************************************/ | |
56 | static s32 FillH2CCmd_88E(struct adapter *adapt, u8 ElementID, u32 CmdLen, u8 *pCmdBuffer) | |
57 | { | |
58 | u8 bcmd_down = false; | |
59 | s32 retry_cnts = 100; | |
60 | u8 h2c_box_num; | |
61 | u32 msgbox_addr; | |
62 | u32 msgbox_ex_addr; | |
7ef8ded0 LF |
63 | u8 cmd_idx, ext_cmd_len; |
64 | u32 h2c_cmd = 0; | |
65 | u32 h2c_cmd_ex = 0; | |
66 | s32 ret = _FAIL; | |
67 | ||
7ef8ded0 LF |
68 | |
69 | if (!adapt->bFWReady) { | |
4fdd5368 DH |
70 | DBG_88E("%s(): return H2C cmd because fw is not ready\n", |
71 | __func__); | |
7ef8ded0 LF |
72 | return ret; |
73 | } | |
74 | ||
75 | if (!pCmdBuffer) | |
76 | goto exit; | |
77 | if (CmdLen > RTL88E_MAX_CMD_LEN) | |
78 | goto exit; | |
79 | if (adapt->bSurpriseRemoved) | |
80 | goto exit; | |
81 | ||
82 | /* pay attention to if race condition happened in H2C cmd setting. */ | |
83 | do { | |
177aa53a | 84 | h2c_box_num = adapt->HalData->LastHMEBoxNum; |
7ef8ded0 LF |
85 | |
86 | if (!_is_fw_read_cmd_down(adapt, h2c_box_num)) { | |
87 | DBG_88E(" fw read cmd failed...\n"); | |
88 | goto exit; | |
89 | } | |
90 | ||
91 | *(u8 *)(&h2c_cmd) = ElementID; | |
92 | ||
93 | if (CmdLen <= 3) { | |
94 | memcpy((u8 *)(&h2c_cmd)+1, pCmdBuffer, CmdLen); | |
95 | } else { | |
96 | memcpy((u8 *)(&h2c_cmd)+1, pCmdBuffer, 3); | |
97 | ext_cmd_len = CmdLen-3; | |
98 | memcpy((u8 *)(&h2c_cmd_ex), pCmdBuffer+3, ext_cmd_len); | |
99 | ||
100 | /* Write Ext command */ | |
101 | msgbox_ex_addr = REG_HMEBOX_EXT_0 + (h2c_box_num * RTL88E_EX_MESSAGE_BOX_SIZE); | |
102 | for (cmd_idx = 0; cmd_idx < ext_cmd_len; cmd_idx++) { | |
e76484d0 | 103 | usb_write8(adapt, msgbox_ex_addr+cmd_idx, *((u8 *)(&h2c_cmd_ex)+cmd_idx)); |
7ef8ded0 LF |
104 | } |
105 | } | |
106 | /* Write command */ | |
107 | msgbox_addr = REG_HMEBOX_0 + (h2c_box_num * RTL88E_MESSAGE_BOX_SIZE); | |
108 | for (cmd_idx = 0; cmd_idx < RTL88E_MESSAGE_BOX_SIZE; cmd_idx++) { | |
e76484d0 | 109 | usb_write8(adapt, msgbox_addr+cmd_idx, *((u8 *)(&h2c_cmd)+cmd_idx)); |
7ef8ded0 LF |
110 | } |
111 | bcmd_down = true; | |
112 | ||
177aa53a IS |
113 | adapt->HalData->LastHMEBoxNum = |
114 | (h2c_box_num+1) % RTL88E_MAX_H2C_BOX_NUMS; | |
7ef8ded0 LF |
115 | |
116 | } while ((!bcmd_down) && (retry_cnts--)); | |
117 | ||
118 | ret = _SUCCESS; | |
119 | ||
120 | exit: | |
121 | ||
7ef8ded0 LF |
122 | |
123 | return ret; | |
124 | } | |
125 | ||
7ef8ded0 LF |
126 | /* bitmap[0:27] = tx_rate_bitmap */ |
127 | /* bitmap[28:31]= Rate Adaptive id */ | |
128 | /* arg[0:4] = macid */ | |
129 | /* arg[5] = Short GI */ | |
c8059764 | 130 | void rtw_hal_add_ra_tid(struct adapter *pAdapter, u32 bitmap, u8 arg, u8 rssi_level) |
7ef8ded0 | 131 | { |
177aa53a | 132 | struct odm_dm_struct *odmpriv = &pAdapter->HalData->odmpriv; |
7ef8ded0 LF |
133 | |
134 | u8 macid, init_rate, raid, shortGIrate = false; | |
135 | ||
136 | macid = arg&0x1f; | |
137 | ||
138 | raid = (bitmap>>28) & 0x0f; | |
139 | bitmap &= 0x0fffffff; | |
140 | ||
141 | if (rssi_level != DM_RATR_STA_INIT) | |
177aa53a | 142 | bitmap = ODM_Get_Rate_Bitmap(odmpriv, macid, bitmap, rssi_level); |
7ef8ded0 LF |
143 | |
144 | bitmap |= ((raid<<28)&0xf0000000); | |
145 | ||
146 | init_rate = get_highest_rate_idx(bitmap&0x0fffffff)&0x3f; | |
147 | ||
9c68ed09 | 148 | shortGIrate = (arg & BIT(5)) ? true : false; |
7ef8ded0 LF |
149 | |
150 | if (shortGIrate) | |
151 | init_rate |= BIT(6); | |
152 | ||
153 | raid = (bitmap>>28) & 0x0f; | |
154 | ||
155 | bitmap &= 0x0fffffff; | |
156 | ||
157 | DBG_88E("%s=> mac_id:%d, raid:%d, ra_bitmap=0x%x, shortGIrate=0x%02x\n", | |
158 | __func__, macid, raid, bitmap, shortGIrate); | |
159 | ||
177aa53a | 160 | ODM_RA_UpdateRateInfo_8188E(odmpriv, macid, raid, bitmap, shortGIrate); |
7ef8ded0 LF |
161 | } |
162 | ||
163 | void rtl8188e_set_FwPwrMode_cmd(struct adapter *adapt, u8 Mode) | |
164 | { | |
165 | struct setpwrmode_parm H2CSetPwrMode; | |
166 | struct pwrctrl_priv *pwrpriv = &adapt->pwrctrlpriv; | |
167 | u8 RLBM = 0; /* 0:Min, 1:Max, 2:User define */ | |
7ef8ded0 LF |
168 | |
169 | DBG_88E("%s: Mode=%d SmartPS=%d UAPSD=%d\n", __func__, | |
170 | Mode, pwrpriv->smart_ps, adapt->registrypriv.uapsd_enable); | |
171 | ||
172 | switch (Mode) { | |
173 | case PS_MODE_ACTIVE: | |
174 | H2CSetPwrMode.Mode = 0; | |
175 | break; | |
176 | case PS_MODE_MIN: | |
177 | H2CSetPwrMode.Mode = 1; | |
178 | break; | |
179 | case PS_MODE_MAX: | |
180 | RLBM = 1; | |
181 | H2CSetPwrMode.Mode = 1; | |
182 | break; | |
183 | case PS_MODE_DTIM: | |
184 | RLBM = 2; | |
185 | H2CSetPwrMode.Mode = 1; | |
186 | break; | |
187 | case PS_MODE_UAPSD_WMM: | |
188 | H2CSetPwrMode.Mode = 2; | |
189 | break; | |
190 | default: | |
191 | H2CSetPwrMode.Mode = 0; | |
192 | break; | |
193 | } | |
194 | ||
195 | H2CSetPwrMode.SmartPS_RLBM = (((pwrpriv->smart_ps<<4)&0xf0) | (RLBM & 0x0f)); | |
196 | ||
197 | H2CSetPwrMode.AwakeInterval = 1; | |
198 | ||
199 | H2CSetPwrMode.bAllQueueUAPSD = adapt->registrypriv.uapsd_enable; | |
200 | ||
201 | if (Mode > 0) | |
202 | H2CSetPwrMode.PwrState = 0x00;/* AllON(0x0C), RFON(0x04), RFOFF(0x00) */ | |
203 | else | |
204 | H2CSetPwrMode.PwrState = 0x0C;/* AllON(0x0C), RFON(0x04), RFOFF(0x00) */ | |
205 | ||
206 | FillH2CCmd_88E(adapt, H2C_PS_PWR_MODE, sizeof(H2CSetPwrMode), (u8 *)&H2CSetPwrMode); | |
207 | ||
7ef8ded0 LF |
208 | } |
209 | ||
210 | void rtl8188e_set_FwMediaStatus_cmd(struct adapter *adapt, __le16 mstatus_rpt) | |
211 | { | |
212 | u8 opmode, macid; | |
213 | u16 mst_rpt = le16_to_cpu(mstatus_rpt); | |
fc988e14 | 214 | |
7be921a2 | 215 | opmode = (u8)mst_rpt; |
7ef8ded0 LF |
216 | macid = (u8)(mst_rpt >> 8); |
217 | ||
218 | DBG_88E("### %s: MStatus=%x MACID=%d\n", __func__, opmode, macid); | |
219 | FillH2CCmd_88E(adapt, H2C_COM_MEDIA_STATUS_RPT, sizeof(mst_rpt), (u8 *)&mst_rpt); | |
220 | } | |
221 | ||
222 | static void ConstructBeacon(struct adapter *adapt, u8 *pframe, u32 *pLength) | |
223 | { | |
d87f574d | 224 | struct ieee80211_hdr *pwlanhdr; |
c4af455f | 225 | __le16 *fctrl; |
7ef8ded0 LF |
226 | u32 rate_len, pktlen; |
227 | struct mlme_ext_priv *pmlmeext = &(adapt->mlmeextpriv); | |
228 | struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); | |
229 | struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network); | |
230 | u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; | |
231 | ||
d87f574d | 232 | pwlanhdr = (struct ieee80211_hdr *)pframe; |
7ef8ded0 | 233 | |
d87f574d | 234 | fctrl = &pwlanhdr->frame_control; |
7ef8ded0 LF |
235 | *(fctrl) = 0; |
236 | ||
b95300e8 GRC |
237 | ether_addr_copy(pwlanhdr->addr1, bc_addr); |
238 | ether_addr_copy(pwlanhdr->addr2, myid(&(adapt->eeprompriv))); | |
239 | ether_addr_copy(pwlanhdr->addr3, cur_network->MacAddress); | |
7ef8ded0 LF |
240 | |
241 | SetSeqNum(pwlanhdr, 0/*pmlmeext->mgnt_seq*/); | |
242 | SetFrameSubType(pframe, WIFI_BEACON); | |
243 | ||
bbfe286b IS |
244 | pframe += sizeof(struct ieee80211_hdr_3addr); |
245 | pktlen = sizeof(struct ieee80211_hdr_3addr); | |
7ef8ded0 LF |
246 | |
247 | /* timestamp will be inserted by hardware */ | |
248 | pframe += 8; | |
249 | pktlen += 8; | |
250 | ||
251 | /* beacon interval: 2 bytes */ | |
341f27d0 | 252 | memcpy(pframe, (unsigned char *)(rtw_get_beacon_interval_from_ie(cur_network->ies)), 2); |
7ef8ded0 LF |
253 | |
254 | pframe += 2; | |
255 | pktlen += 2; | |
256 | ||
257 | /* capability info: 2 bytes */ | |
341f27d0 | 258 | memcpy(pframe, (unsigned char *)(rtw_get_capability_from_ie(cur_network->ies)), 2); |
7ef8ded0 LF |
259 | |
260 | pframe += 2; | |
261 | pktlen += 2; | |
262 | ||
263 | if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE) { | |
341f27d0 JSB |
264 | pktlen += cur_network->ie_length - sizeof(struct ndis_802_11_fixed_ie); |
265 | memcpy(pframe, cur_network->ies+sizeof(struct ndis_802_11_fixed_ie), pktlen); | |
7ef8ded0 LF |
266 | |
267 | goto _ConstructBeacon; | |
268 | } | |
269 | ||
270 | /* below for ad-hoc mode */ | |
271 | ||
272 | /* SSID */ | |
273 | pframe = rtw_set_ie(pframe, _SSID_IE_, cur_network->Ssid.SsidLength, cur_network->Ssid.Ssid, &pktlen); | |
274 | ||
275 | /* supported rates... */ | |
276 | rate_len = rtw_get_rateset_len(cur_network->SupportedRates); | |
ad8d8cd3 | 277 | pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, min_t(u32, rate_len, 8), cur_network->SupportedRates, &pktlen); |
7ef8ded0 LF |
278 | |
279 | /* DS parameter set */ | |
280 | pframe = rtw_set_ie(pframe, _DSSET_IE_, 1, (unsigned char *)&(cur_network->Configuration.DSConfig), &pktlen); | |
281 | ||
282 | if ((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) { | |
283 | u32 ATIMWindow; | |
284 | /* IBSS Parameter Set... */ | |
285 | ATIMWindow = 0; | |
286 | pframe = rtw_set_ie(pframe, _IBSS_PARA_IE_, 2, (unsigned char *)(&ATIMWindow), &pktlen); | |
287 | } | |
288 | ||
289 | /* todo: ERP IE */ | |
290 | ||
291 | /* EXTERNDED SUPPORTED RATE */ | |
292 | if (rate_len > 8) | |
293 | pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_, (rate_len - 8), (cur_network->SupportedRates + 8), &pktlen); | |
294 | ||
295 | /* todo:HT for adhoc */ | |
296 | ||
297 | _ConstructBeacon: | |
298 | ||
299 | if ((pktlen + TXDESC_SIZE) > 512) { | |
300 | DBG_88E("beacon frame too large\n"); | |
301 | return; | |
302 | } | |
303 | ||
304 | *pLength = pktlen; | |
305 | } | |
306 | ||
307 | static void ConstructPSPoll(struct adapter *adapt, u8 *pframe, u32 *pLength) | |
308 | { | |
d87f574d | 309 | struct ieee80211_hdr *pwlanhdr; |
7ef8ded0 LF |
310 | struct mlme_ext_priv *pmlmeext = &(adapt->mlmeextpriv); |
311 | struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); | |
c4af455f | 312 | __le16 *fctrl; |
74df1cd7 | 313 | struct wlan_bssid_ex *pnetwork = &(pmlmeinfo->network); |
7ef8ded0 | 314 | |
d87f574d | 315 | pwlanhdr = (struct ieee80211_hdr *)pframe; |
7ef8ded0 LF |
316 | |
317 | /* Frame control. */ | |
d87f574d | 318 | fctrl = &pwlanhdr->frame_control; |
7ef8ded0 LF |
319 | *(fctrl) = 0; |
320 | SetPwrMgt(fctrl); | |
321 | SetFrameSubType(pframe, WIFI_PSPOLL); | |
322 | ||
323 | /* AID. */ | |
324 | SetDuration(pframe, (pmlmeinfo->aid | 0xc000)); | |
325 | ||
326 | /* BSSID. */ | |
b95300e8 | 327 | ether_addr_copy(pwlanhdr->addr1, pnetwork->MacAddress); |
7ef8ded0 LF |
328 | |
329 | /* TA. */ | |
b95300e8 | 330 | ether_addr_copy(pwlanhdr->addr2, myid(&(adapt->eeprompriv))); |
7ef8ded0 LF |
331 | |
332 | *pLength = 16; | |
333 | } | |
334 | ||
335 | static void ConstructNullFunctionData(struct adapter *adapt, u8 *pframe, | |
336 | u32 *pLength, | |
337 | u8 *StaAddr, | |
338 | u8 bQoS, | |
339 | u8 AC, | |
340 | u8 bEosp, | |
341 | u8 bForcePowerSave) | |
342 | { | |
d87f574d | 343 | struct ieee80211_hdr *pwlanhdr; |
c4af455f | 344 | __le16 *fctrl; |
7ef8ded0 LF |
345 | u32 pktlen; |
346 | struct mlme_priv *pmlmepriv = &adapt->mlmepriv; | |
347 | struct wlan_network *cur_network = &pmlmepriv->cur_network; | |
348 | struct mlme_ext_priv *pmlmeext = &(adapt->mlmeextpriv); | |
349 | struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); | |
74df1cd7 | 350 | struct wlan_bssid_ex *pnetwork = &(pmlmeinfo->network); |
7ef8ded0 | 351 | |
d87f574d | 352 | pwlanhdr = (struct ieee80211_hdr *)pframe; |
7ef8ded0 | 353 | |
d87f574d | 354 | fctrl = &pwlanhdr->frame_control; |
7ef8ded0 LF |
355 | *(fctrl) = 0; |
356 | if (bForcePowerSave) | |
357 | SetPwrMgt(fctrl); | |
358 | ||
359 | switch (cur_network->network.InfrastructureMode) { | |
360 | case Ndis802_11Infrastructure: | |
361 | SetToDs(fctrl); | |
b95300e8 GRC |
362 | ether_addr_copy(pwlanhdr->addr1, pnetwork->MacAddress); |
363 | ether_addr_copy(pwlanhdr->addr2, myid(&(adapt->eeprompriv))); | |
364 | ether_addr_copy(pwlanhdr->addr3, StaAddr); | |
7ef8ded0 LF |
365 | break; |
366 | case Ndis802_11APMode: | |
367 | SetFrDs(fctrl); | |
b95300e8 GRC |
368 | ether_addr_copy(pwlanhdr->addr1, StaAddr); |
369 | ether_addr_copy(pwlanhdr->addr2, pnetwork->MacAddress); | |
370 | ether_addr_copy(pwlanhdr->addr3, myid(&(adapt->eeprompriv))); | |
7ef8ded0 LF |
371 | break; |
372 | case Ndis802_11IBSS: | |
373 | default: | |
b95300e8 GRC |
374 | ether_addr_copy(pwlanhdr->addr1, StaAddr); |
375 | ether_addr_copy(pwlanhdr->addr2, myid(&(adapt->eeprompriv))); | |
376 | ether_addr_copy(pwlanhdr->addr3, pnetwork->MacAddress); | |
7ef8ded0 LF |
377 | break; |
378 | } | |
379 | ||
380 | SetSeqNum(pwlanhdr, 0); | |
381 | ||
382 | if (bQoS) { | |
5cd83965 | 383 | struct ieee80211_qos_hdr *pwlanqoshdr; |
7ef8ded0 LF |
384 | |
385 | SetFrameSubType(pframe, WIFI_QOS_DATA_NULL); | |
386 | ||
5cd83965 IS |
387 | pwlanqoshdr = (struct ieee80211_qos_hdr *)pframe; |
388 | SetPriority(&pwlanqoshdr->qos_ctrl, AC); | |
389 | SetEOSP(&pwlanqoshdr->qos_ctrl, bEosp); | |
7ef8ded0 | 390 | |
5cd83965 | 391 | pktlen = sizeof(struct ieee80211_qos_hdr); |
7ef8ded0 LF |
392 | } else { |
393 | SetFrameSubType(pframe, WIFI_DATA_NULL); | |
394 | ||
bbfe286b | 395 | pktlen = sizeof(struct ieee80211_hdr_3addr); |
7ef8ded0 LF |
396 | } |
397 | ||
398 | *pLength = pktlen; | |
399 | } | |
400 | ||
401 | static void ConstructProbeRsp(struct adapter *adapt, u8 *pframe, u32 *pLength, u8 *StaAddr, bool bHideSSID) | |
402 | { | |
d87f574d | 403 | struct ieee80211_hdr *pwlanhdr; |
c4af455f | 404 | __le16 *fctrl; |
7ef8ded0 LF |
405 | u8 *mac, *bssid; |
406 | u32 pktlen; | |
407 | struct mlme_ext_priv *pmlmeext = &(adapt->mlmeextpriv); | |
408 | struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); | |
409 | struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network); | |
410 | ||
d87f574d | 411 | pwlanhdr = (struct ieee80211_hdr *)pframe; |
7ef8ded0 LF |
412 | |
413 | mac = myid(&(adapt->eeprompriv)); | |
414 | bssid = cur_network->MacAddress; | |
415 | ||
d87f574d | 416 | fctrl = &pwlanhdr->frame_control; |
7ef8ded0 | 417 | *(fctrl) = 0; |
b95300e8 GRC |
418 | ether_addr_copy(pwlanhdr->addr1, StaAddr); |
419 | ether_addr_copy(pwlanhdr->addr2, mac); | |
420 | ether_addr_copy(pwlanhdr->addr3, bssid); | |
7ef8ded0 LF |
421 | |
422 | SetSeqNum(pwlanhdr, 0); | |
423 | SetFrameSubType(fctrl, WIFI_PROBERSP); | |
424 | ||
bbfe286b | 425 | pktlen = sizeof(struct ieee80211_hdr_3addr); |
7ef8ded0 LF |
426 | pframe += pktlen; |
427 | ||
341f27d0 | 428 | if (cur_network->ie_length > MAX_IE_SZ) |
7ef8ded0 LF |
429 | return; |
430 | ||
341f27d0 JSB |
431 | memcpy(pframe, cur_network->ies, cur_network->ie_length); |
432 | pframe += cur_network->ie_length; | |
433 | pktlen += cur_network->ie_length; | |
7ef8ded0 LF |
434 | |
435 | *pLength = pktlen; | |
436 | } | |
437 | ||
7ef8ded0 LF |
438 | /* */ |
439 | /* Description: Fill the reserved packets that FW will use to RSVD page. */ | |
440 | /* Now we just send 4 types packet to rsvd page. */ | |
441 | /* (1)Beacon, (2)Ps-poll, (3)Null data, (4)ProbeRsp. */ | |
442 | /* Input: */ | |
443 | /* bDLFinished - false: At the first time we will send all the packets as a large packet to Hw, */ | |
5e809e50 | 444 | /* so we need to set the packet length to total length. */ |
7ef8ded0 | 445 | /* true: At the second time, we should send the first packet (default:beacon) */ |
5e809e50 | 446 | /* to Hw again and set the length in descriptor to the real beacon length. */ |
7ef8ded0 LF |
447 | /* 2009.10.15 by tynli. */ |
448 | static void SetFwRsvdPagePkt(struct adapter *adapt, bool bDLFinished) | |
449 | { | |
7ef8ded0 LF |
450 | struct xmit_frame *pmgntframe; |
451 | struct pkt_attrib *pattrib; | |
452 | struct xmit_priv *pxmitpriv; | |
453 | struct mlme_ext_priv *pmlmeext; | |
454 | struct mlme_ext_info *pmlmeinfo; | |
455 | u32 BeaconLength = 0, ProbeRspLength = 0, PSPollLength; | |
456 | u32 NullDataLength, QosNullLength; | |
457 | u8 *ReservedPagePacket; | |
458 | u8 PageNum, PageNeed, TxDescLen; | |
459 | u16 BufIndex; | |
460 | u32 TotalPacketLen; | |
461 | struct rsvdpage_loc RsvdPageLoc; | |
74df1cd7 | 462 | struct wlan_bssid_ex *pnetwork; |
7ef8ded0 LF |
463 | |
464 | DBG_88E("%s\n", __func__); | |
fadbe0cd | 465 | ReservedPagePacket = kzalloc(1000, GFP_KERNEL); |
e3789b0c | 466 | if (!ReservedPagePacket) { |
7ef8ded0 LF |
467 | DBG_88E("%s: alloc ReservedPagePacket fail!\n", __func__); |
468 | return; | |
469 | } | |
470 | ||
7ef8ded0 LF |
471 | pxmitpriv = &adapt->xmitpriv; |
472 | pmlmeext = &adapt->mlmeextpriv; | |
473 | pmlmeinfo = &pmlmeext->mlmext_info; | |
74df1cd7 | 474 | pnetwork = &(pmlmeinfo->network); |
7ef8ded0 LF |
475 | |
476 | TxDescLen = TXDESC_SIZE; | |
477 | PageNum = 0; | |
478 | ||
479 | /* 3 (1) beacon * 2 pages */ | |
480 | BufIndex = TXDESC_OFFSET; | |
481 | ConstructBeacon(adapt, &ReservedPagePacket[BufIndex], &BeaconLength); | |
482 | ||
483 | /* When we count the first page size, we need to reserve description size for the RSVD */ | |
484 | /* packet, it will be filled in front of the packet in TXPKTBUF. */ | |
485 | PageNeed = (u8)PageNum_128(TxDescLen + BeaconLength); | |
486 | /* To reserved 2 pages for beacon buffer. 2010.06.24. */ | |
487 | if (PageNeed == 1) | |
488 | PageNeed += 1; | |
489 | PageNum += PageNeed; | |
177aa53a | 490 | adapt->HalData->FwRsvdPageStartOffset = PageNum; |
7ef8ded0 LF |
491 | |
492 | BufIndex += PageNeed*128; | |
493 | ||
494 | /* 3 (2) ps-poll *1 page */ | |
495 | RsvdPageLoc.LocPsPoll = PageNum; | |
496 | ConstructPSPoll(adapt, &ReservedPagePacket[BufIndex], &PSPollLength); | |
497 | rtl8188e_fill_fake_txdesc(adapt, &ReservedPagePacket[BufIndex-TxDescLen], PSPollLength, true, false); | |
498 | ||
499 | PageNeed = (u8)PageNum_128(TxDescLen + PSPollLength); | |
500 | PageNum += PageNeed; | |
501 | ||
502 | BufIndex += PageNeed*128; | |
503 | ||
504 | /* 3 (3) null data * 1 page */ | |
505 | RsvdPageLoc.LocNullData = PageNum; | |
74df1cd7 | 506 | ConstructNullFunctionData(adapt, &ReservedPagePacket[BufIndex], &NullDataLength, pnetwork->MacAddress, false, 0, 0, false); |
7ef8ded0 LF |
507 | rtl8188e_fill_fake_txdesc(adapt, &ReservedPagePacket[BufIndex-TxDescLen], NullDataLength, false, false); |
508 | ||
509 | PageNeed = (u8)PageNum_128(TxDescLen + NullDataLength); | |
510 | PageNum += PageNeed; | |
511 | ||
512 | BufIndex += PageNeed*128; | |
513 | ||
514 | /* 3 (4) probe response * 1page */ | |
515 | RsvdPageLoc.LocProbeRsp = PageNum; | |
74df1cd7 | 516 | ConstructProbeRsp(adapt, &ReservedPagePacket[BufIndex], &ProbeRspLength, pnetwork->MacAddress, false); |
7ef8ded0 LF |
517 | rtl8188e_fill_fake_txdesc(adapt, &ReservedPagePacket[BufIndex-TxDescLen], ProbeRspLength, false, false); |
518 | ||
519 | PageNeed = (u8)PageNum_128(TxDescLen + ProbeRspLength); | |
520 | PageNum += PageNeed; | |
521 | ||
522 | BufIndex += PageNeed*128; | |
523 | ||
524 | /* 3 (5) Qos null data */ | |
525 | RsvdPageLoc.LocQosNull = PageNum; | |
526 | ConstructNullFunctionData(adapt, &ReservedPagePacket[BufIndex], | |
74df1cd7 | 527 | &QosNullLength, pnetwork->MacAddress, true, 0, 0, false); |
7ef8ded0 LF |
528 | rtl8188e_fill_fake_txdesc(adapt, &ReservedPagePacket[BufIndex-TxDescLen], QosNullLength, false, false); |
529 | ||
530 | PageNeed = (u8)PageNum_128(TxDescLen + QosNullLength); | |
531 | PageNum += PageNeed; | |
532 | ||
533 | TotalPacketLen = BufIndex + QosNullLength; | |
534 | pmgntframe = alloc_mgtxmitframe(pxmitpriv); | |
e3789b0c | 535 | if (!pmgntframe) |
7ef8ded0 LF |
536 | goto exit; |
537 | ||
538 | /* update attribute */ | |
539 | pattrib = &pmgntframe->attrib; | |
540 | update_mgntframe_attrib(adapt, pattrib); | |
541 | pattrib->qsel = 0x10; | |
542 | pattrib->last_txcmdsz = TotalPacketLen - TXDESC_OFFSET; | |
543 | pattrib->pktlen = pattrib->last_txcmdsz; | |
544 | memcpy(pmgntframe->buf_addr, ReservedPagePacket, TotalPacketLen); | |
545 | ||
546 | rtw_hal_mgnt_xmit(adapt, pmgntframe); | |
547 | ||
548 | DBG_88E("%s: Set RSVD page location to Fw\n", __func__); | |
549 | FillH2CCmd_88E(adapt, H2C_COM_RSVD_PAGE, sizeof(RsvdPageLoc), (u8 *)&RsvdPageLoc); | |
550 | ||
551 | exit: | |
552 | kfree(ReservedPagePacket); | |
553 | } | |
554 | ||
555 | void rtl8188e_set_FwJoinBssReport_cmd(struct adapter *adapt, u8 mstatus) | |
556 | { | |
177aa53a | 557 | struct hal_data_8188e *haldata = adapt->HalData; |
7ef8ded0 LF |
558 | struct mlme_ext_priv *pmlmeext = &(adapt->mlmeextpriv); |
559 | struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); | |
560 | bool bSendBeacon = false; | |
561 | bool bcn_valid = false; | |
562 | u8 DLBcnCount = 0; | |
563 | u32 poll = 0; | |
564 | ||
7ef8ded0 LF |
565 | |
566 | DBG_88E("%s mstatus(%x)\n", __func__, mstatus); | |
567 | ||
568 | if (mstatus == 1) { | |
569 | /* We should set AID, correct TSF, HW seq enable before set JoinBssReport to Fw in 88/92C. */ | |
570 | /* Suggested by filen. Added by tynli. */ | |
9764ed04 | 571 | usb_write16(adapt, REG_BCN_PSR_RPT, (0xC000|pmlmeinfo->aid)); |
7ef8ded0 LF |
572 | /* Do not set TSF again here or vWiFi beacon DMA INT will not work. */ |
573 | ||
574 | /* Set REG_CR bit 8. DMA beacon by SW. */ | |
9c68ed09 | 575 | haldata->RegCR_1 |= BIT(0); |
e76484d0 | 576 | usb_write8(adapt, REG_CR+1, haldata->RegCR_1); |
7ef8ded0 LF |
577 | |
578 | /* Disable Hw protection for a time which revserd for Hw sending beacon. */ | |
579 | /* Fix download reserved page packet fail that access collision with the protection time. */ | |
580 | /* 2010.05.11. Added by tynli. */ | |
c7b2e995 | 581 | usb_write8(adapt, REG_BCN_CTRL, usb_read8(adapt, REG_BCN_CTRL)&(~BIT(3))); |
9c68ed09 | 582 | usb_write8(adapt, REG_BCN_CTRL, usb_read8(adapt, REG_BCN_CTRL) | BIT(4)); |
7ef8ded0 | 583 | |
9c68ed09 | 584 | if (haldata->RegFwHwTxQCtrl & BIT(6)) { |
7ef8ded0 LF |
585 | DBG_88E("HalDownloadRSVDPage(): There is an Adapter is sending beacon.\n"); |
586 | bSendBeacon = true; | |
587 | } | |
588 | ||
589 | /* Set FWHW_TXQ_CTRL 0x422[6]=0 to tell Hw the packet is not a real beacon frame. */ | |
9c68ed09 AB |
590 | usb_write8(adapt, REG_FWHW_TXQ_CTRL+2, (haldata->RegFwHwTxQCtrl&(~BIT(6)))); |
591 | haldata->RegFwHwTxQCtrl &= (~BIT(6)); | |
7ef8ded0 LF |
592 | |
593 | /* Clear beacon valid check bit. */ | |
594 | rtw_hal_set_hwreg(adapt, HW_VAR_BCN_VALID, NULL); | |
595 | DLBcnCount = 0; | |
596 | poll = 0; | |
597 | do { | |
598 | /* download rsvd page. */ | |
599 | SetFwRsvdPagePkt(adapt, false); | |
600 | DLBcnCount++; | |
601 | do { | |
e8ab621e | 602 | yield(); |
4063642b | 603 | /* mdelay(10); */ |
7ef8ded0 LF |
604 | /* check rsvd page download OK. */ |
605 | rtw_hal_get_hwreg(adapt, HW_VAR_BCN_VALID, (u8 *)(&bcn_valid)); | |
606 | poll++; | |
607 | } while (!bcn_valid && (poll%10) != 0 && !adapt->bSurpriseRemoved && !adapt->bDriverStopped); | |
608 | } while (!bcn_valid && DLBcnCount <= 100 && !adapt->bSurpriseRemoved && !adapt->bDriverStopped); | |
609 | ||
610 | if (adapt->bSurpriseRemoved || adapt->bDriverStopped) | |
611 | ; | |
612 | else if (!bcn_valid) | |
613 | DBG_88E("%s: 1 Download RSVD page failed! DLBcnCount:%u, poll:%u\n", __func__, DLBcnCount, poll); | |
614 | else | |
615 | DBG_88E("%s: 1 Download RSVD success! DLBcnCount:%u, poll:%u\n", __func__, DLBcnCount, poll); | |
616 | /* */ | |
617 | /* We just can send the reserved page twice during the time that Tx thread is stopped (e.g. pnpsetpower) */ | |
5e809e50 | 618 | /* because we need to free the Tx BCN Desc which is used by the first reserved page packet. */ |
7ef8ded0 LF |
619 | /* At run time, we cannot get the Tx Desc until it is released in TxHandleInterrupt() so we will return */ |
620 | /* the beacon TCB in the following code. 2011.11.23. by tynli. */ | |
621 | /* */ | |
622 | ||
623 | /* Enable Bcn */ | |
9c68ed09 | 624 | usb_write8(adapt, REG_BCN_CTRL, usb_read8(adapt, REG_BCN_CTRL) | BIT(3)); |
c7b2e995 | 625 | usb_write8(adapt, REG_BCN_CTRL, usb_read8(adapt, REG_BCN_CTRL)&(~BIT(4))); |
7ef8ded0 LF |
626 | |
627 | /* To make sure that if there exists an adapter which would like to send beacon. */ | |
628 | /* If exists, the origianl value of 0x422[6] will be 1, we should check this to */ | |
629 | /* prevent from setting 0x422[6] to 0 after download reserved page, or it will cause */ | |
630 | /* the beacon cannot be sent by HW. */ | |
631 | /* 2010.06.23. Added by tynli. */ | |
632 | if (bSendBeacon) { | |
9c68ed09 AB |
633 | usb_write8(adapt, REG_FWHW_TXQ_CTRL+2, (haldata->RegFwHwTxQCtrl | BIT(6))); |
634 | haldata->RegFwHwTxQCtrl |= BIT(6); | |
7ef8ded0 LF |
635 | } |
636 | ||
637 | /* Update RSVD page location H2C to Fw. */ | |
638 | if (bcn_valid) { | |
639 | rtw_hal_set_hwreg(adapt, HW_VAR_BCN_VALID, NULL); | |
640 | DBG_88E("Set RSVD page location to Fw.\n"); | |
641 | } | |
642 | ||
643 | /* Do not enable HW DMA BCN or it will cause Pcie interface hang by timing issue. 2011.11.24. by tynli. */ | |
644 | /* Clear CR[8] or beacon packet will not be send to TxBuf anymore. */ | |
9c68ed09 | 645 | haldata->RegCR_1 &= (~BIT(0)); |
e76484d0 | 646 | usb_write8(adapt, REG_CR+1, haldata->RegCR_1); |
7ef8ded0 | 647 | } |
7ef8ded0 | 648 | } |