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