haltxbfinterface.c 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2016 - 2017 Realtek Corporation.
  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. *****************************************************************************/
  15. /*************************************************************
  16. * Description:
  17. *
  18. * This file is for TXBF interface mechanism
  19. *
  20. ************************************************************/
  21. #include "mp_precomp.h"
  22. #include "../phydm_precomp.h"
  23. #if (BEAMFORMING_SUPPORT == 1)
  24. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  25. void beamforming_gid_paid(
  26. void *adapter,
  27. PRT_TCB tcb)
  28. {
  29. u8 RA[6] = {0};
  30. u8 *p_header = GET_FRAME_OF_FIRST_FRAG(adapter, tcb);
  31. HAL_DATA_TYPE *hal_data = GET_HAL_DATA(((PADAPTER)adapter));
  32. struct dm_struct *dm = &hal_data->DM_OutSrc;
  33. struct _RT_BEAMFORMING_INFO *beam_info = &(dm->beamforming_info);
  34. if (((PADAPTER)adapter)->HardwareType < HARDWARE_TYPE_RTL8192EE)
  35. return;
  36. else if (IS_WIRELESS_MODE_N((PADAPTER)adapter) == false)
  37. return;
  38. #if (SUPPORT_MU_BF == 1)
  39. if (tcb->tx_bf_pkt_type == RT_BF_PKT_TYPE_BROADCAST_NDPA) { /* @MU NDPA */
  40. #else
  41. if (0) {
  42. #endif
  43. /* @Fill G_ID and P_AID */
  44. tcb->G_ID = 63;
  45. if (beam_info->first_mu_bfee_index < BEAMFORMEE_ENTRY_NUM) {
  46. tcb->P_AID = beam_info->beamformee_entry[beam_info->first_mu_bfee_index].p_aid;
  47. RT_DISP(FBEAM, FBEAM_FUN, ("[David]@%s End, G_ID=0x%X, P_AID=0x%X\n", __func__, tcb->G_ID, tcb->P_AID));
  48. }
  49. } else {
  50. GET_80211_HDR_ADDRESS1(p_header, &RA);
  51. /* VHT SU PPDU carrying one or more group addressed MPDUs or */
  52. /* Transmitting a VHT NDP intended for multiple recipients */
  53. if (MacAddr_isBcst(RA) || MacAddr_isMulticast(RA) || tcb->macId == MAC_ID_STATIC_FOR_BROADCAST_MULTICAST) {
  54. tcb->G_ID = 63;
  55. tcb->P_AID = 0;
  56. } else if (ACTING_AS_AP(adapter)) {
  57. u16 AID = (u16)(MacIdGetOwnerAssociatedClientAID(adapter, tcb->macId) & 0x1ff); /*@AID[0:8]*/
  58. /*RT_DISP(FBEAM, FBEAM_FUN, ("@%s tcb->mac_id=0x%X, AID=0x%X\n", __func__, tcb->mac_id, AID));*/
  59. tcb->G_ID = 63;
  60. if (AID == 0) /*@A PPDU sent by an AP to a non associated STA*/
  61. tcb->P_AID = 0;
  62. else { /*Sent by an AP and addressed to a STA associated with that AP*/
  63. u16 BSSID = 0;
  64. GET_80211_HDR_ADDRESS2(p_header, &RA);
  65. BSSID = ((RA[5] & 0xf0) >> 4) ^ (RA[5] & 0xf); /*@BSSID[44:47] xor BSSID[40:43]*/
  66. tcb->P_AID = (AID + BSSID * 32) & 0x1ff; /*@(dec(A) + dec(B)*32) mod 512*/
  67. }
  68. } else if (ACTING_AS_IBSS(((PADAPTER)adapter))) {
  69. tcb->G_ID = 63;
  70. /*P_AID for infrasturcture mode; MACID for ad-hoc mode. */
  71. tcb->P_AID = tcb->macId;
  72. } else if (MgntLinkStatusQuery(adapter)) { /*@Addressed to AP*/
  73. tcb->G_ID = 0;
  74. GET_80211_HDR_ADDRESS1(p_header, &RA);
  75. tcb->P_AID = RA[5]; /*RA[39:47]*/
  76. tcb->P_AID = (tcb->P_AID << 1) | (RA[4] >> 7);
  77. } else {
  78. tcb->G_ID = 63;
  79. tcb->P_AID = 0;
  80. }
  81. /*RT_DISP(FBEAM, FBEAM_FUN, ("[David]@%s End, G_ID=0x%X, P_AID=0x%X\n", __func__, tcb->G_ID, tcb->P_AID));*/
  82. }
  83. }
  84. enum rt_status
  85. beamforming_get_report_frame(
  86. void *adapter,
  87. PRT_RFD rfd,
  88. POCTET_STRING p_pdu_os)
  89. {
  90. HAL_DATA_TYPE *hal_data = GET_HAL_DATA((PADAPTER)adapter);
  91. struct dm_struct *dm = &hal_data->DM_OutSrc;
  92. struct _RT_BEAMFORMEE_ENTRY *beamform_entry = NULL;
  93. u8 *p_mimo_ctrl_field, p_csi_matrix;
  94. u8 idx, nc, nr, CH_W;
  95. u16 csi_matrix_len = 0;
  96. ACT_PKT_TYPE pkt_type = ACT_PKT_TYPE_UNKNOWN;
  97. /* @Memory comparison to see if CSI report is the same with previous one */
  98. beamform_entry = phydm_beamforming_get_bfee_entry_by_addr(dm, Frame_Addr2(*p_pdu_os), &idx);
  99. if (beamform_entry == NULL) {
  100. PHYDM_DBG(dm, DBG_TXBF, "%s: Cannot find entry by addr\n",
  101. __func__);
  102. return RT_STATUS_FAILURE;
  103. }
  104. pkt_type = PacketGetActionFrameType(p_pdu_os);
  105. /* @-@ Modified by David */
  106. if (pkt_type == ACT_PKT_VHT_COMPRESSED_BEAMFORMING) {
  107. p_mimo_ctrl_field = p_pdu_os->Octet + 26;
  108. nc = ((*p_mimo_ctrl_field) & 0x7) + 1;
  109. nr = (((*p_mimo_ctrl_field) & 0x38) >> 3) + 1;
  110. CH_W = (((*p_mimo_ctrl_field) & 0xC0) >> 6);
  111. /*p_csi_matrix = p_mimo_ctrl_field + 3 + nc;*/ /* 24+(1+1+3)+2 MAC header+(Category+ActionCode+MIMOControlField) +SNR(nc=2) */
  112. csi_matrix_len = p_pdu_os->Length - 26 - 3 - nc;
  113. } else if (pkt_type == ACT_PKT_HT_COMPRESSED_BEAMFORMING) {
  114. p_mimo_ctrl_field = p_pdu_os->Octet + 26;
  115. nc = ((*p_mimo_ctrl_field) & 0x3) + 1;
  116. nr = (((*p_mimo_ctrl_field) & 0xC) >> 2) + 1;
  117. CH_W = (((*p_mimo_ctrl_field) & 0x10) >> 4);
  118. /*p_csi_matrix = p_mimo_ctrl_field + 6 + nr;*/ /* 24+(1+1+6)+2 MAC header+(Category+ActionCode+MIMOControlField) +SNR(nc=2) */
  119. csi_matrix_len = p_pdu_os->Length - 26 - 6 - nr;
  120. } else
  121. return RT_STATUS_SUCCESS;
  122. PHYDM_DBG(dm, DBG_TXBF,
  123. "[%s] idx=%d, pkt type=%d, nc=%d, nr=%d, CH_W=%d\n", __func__,
  124. idx, pkt_type, nc, nr, CH_W);
  125. return RT_STATUS_SUCCESS;
  126. }
  127. void construct_ht_ndpa_packet(
  128. // 2017/11 MH PHYDM compile. But why need to use windows maco?
  129. // For all linux code, it should be useless?
  130. //void *adapter = dm->adapter;
  131. ADAPTER * adapter,
  132. //void *adapter,
  133. u8 *RA,
  134. u8 *buffer,
  135. u32 *p_length,
  136. enum channel_width BW)
  137. {
  138. u16 duration = 0;
  139. PMGNT_INFO mgnt_info = &(((PADAPTER)adapter)->MgntInfo);
  140. //PMGNT_INFO mgnt_info = &((MGNT_INFO)(((PADAPTER)adapter)->MgntInfo));
  141. OCTET_STRING p_ndpa_frame, action_content;
  142. u8 action_hdr[4] = {ACT_CAT_VENDOR, 0x00, 0xe0, 0x4c};
  143. PlatformZeroMemory(buffer, 32);
  144. SET_80211_HDR_FRAME_CONTROL(buffer, 0);
  145. SET_80211_HDR_ORDER(buffer, 1);
  146. SET_80211_HDR_TYPE_AND_SUBTYPE(buffer, Type_Action_No_Ack);
  147. SET_80211_HDR_ADDRESS1(buffer, RA);
  148. SET_80211_HDR_ADDRESS2(buffer, ((PADAPTER)adapter)->CurrentAddress);
  149. SET_80211_HDR_ADDRESS3(buffer, ((PMGNT_INFO)mgnt_info)->Bssid);
  150. duration = 2 * a_SifsTime + 40;
  151. if (BW == CHANNEL_WIDTH_40)
  152. duration += 87;
  153. else
  154. duration += 180;
  155. SET_80211_HDR_DURATION(buffer, duration);
  156. /* @HT control field */
  157. SET_HT_CTRL_CSI_STEERING(buffer + sMacHdrLng, 3);
  158. SET_HT_CTRL_NDP_ANNOUNCEMENT(buffer + sMacHdrLng, 1);
  159. FillOctetString(p_ndpa_frame, buffer, sMacHdrLng + sHTCLng);
  160. FillOctetString(action_content, action_hdr, 4);
  161. PacketAppendData(&p_ndpa_frame, action_content);
  162. *p_length = 32;
  163. }
  164. boolean
  165. send_fw_ht_ndpa_packet(
  166. void *dm_void,
  167. u8 *RA,
  168. enum channel_width BW)
  169. {
  170. struct dm_struct *dm = (struct dm_struct *)dm_void;
  171. void *adapter = dm->adapter;
  172. PRT_TCB tcb;
  173. PRT_TX_LOCAL_BUFFER p_buf;
  174. boolean ret = true;
  175. u32 buf_len;
  176. u8 *buf_addr;
  177. u8 desc_len = 0, idx = 0, ndp_tx_rate;
  178. void *p_def_adapter = GetDefaultAdapter(((PADAPTER)adapter));
  179. HAL_DATA_TYPE *hal_data = GET_HAL_DATA(((PADAPTER)adapter));
  180. struct _RT_BEAMFORMEE_ENTRY *beamform_entry = phydm_beamforming_get_bfee_entry_by_addr(dm, RA, &idx);
  181. PHYDM_DBG(dm, DBG_TXBF, "[%s] Start!\n", __func__);
  182. if (beamform_entry == NULL)
  183. return false;
  184. ndp_tx_rate = beamforming_get_htndp_tx_rate(dm, beamform_entry->comp_steering_num_of_bfer);
  185. PHYDM_DBG(dm, DBG_TXBF, "[%s] ndp_tx_rate =%d\n", __func__,
  186. ndp_tx_rate);
  187. PlatformAcquireSpinLock(adapter, RT_TX_SPINLOCK);
  188. if (MgntGetFWBuffer(p_def_adapter, &tcb, &p_buf)) {
  189. #if (DEV_BUS_TYPE != RT_PCI_INTERFACE)
  190. desc_len = ((PADAPTER)adapter)->HWDescHeadLength - hal_data->USBALLDummyLength;
  191. #endif
  192. buf_addr = p_buf->Buffer.VirtualAddress + desc_len;
  193. construct_ht_ndpa_packet(
  194. adapter,
  195. RA,
  196. buf_addr,
  197. &buf_len,
  198. BW);
  199. tcb->PacketLength = buf_len + desc_len;
  200. tcb->bTxEnableSwCalcDur = true;
  201. tcb->BWOfPacket = BW;
  202. if (ACTING_AS_IBSS(((PADAPTER)adapter)) || ACTING_AS_AP(((PADAPTER)adapter)))
  203. tcb->G_ID = 63;
  204. tcb->P_AID = beamform_entry->p_aid;
  205. tcb->DataRate = ndp_tx_rate; /*rate of NDP decide by nr*/
  206. ((PADAPTER)adapter)->HalFunc.CmdSendPacketHandler(((PADAPTER)adapter), tcb, p_buf, tcb->PacketLength, DESC_PACKET_TYPE_NORMAL, false);
  207. } else
  208. ret = false;
  209. PlatformReleaseSpinLock(adapter, RT_TX_SPINLOCK);
  210. if (ret)
  211. RT_DISP_DATA(FBEAM, FBEAM_DATA, "", p_buf->Buffer.VirtualAddress, tcb->PacketLength);
  212. return ret;
  213. }
  214. boolean
  215. send_sw_ht_ndpa_packet(
  216. void *dm_void,
  217. u8 *RA,
  218. enum channel_width BW)
  219. {
  220. struct dm_struct *dm = (struct dm_struct *)dm_void;
  221. void *adapter = dm->adapter;
  222. PRT_TCB tcb;
  223. PRT_TX_LOCAL_BUFFER p_buf;
  224. boolean ret = true;
  225. u8 idx = 0, ndp_tx_rate = 0;
  226. struct _RT_BEAMFORMEE_ENTRY *beamform_entry = phydm_beamforming_get_bfee_entry_by_addr(dm, RA, &idx);
  227. PHYDM_DBG(dm, DBG_TXBF, "[%s] Start!\n", __func__);
  228. ndp_tx_rate = beamforming_get_htndp_tx_rate(dm, beamform_entry->comp_steering_num_of_bfer);
  229. PHYDM_DBG(dm, DBG_TXBF, "[%s] ndp_tx_rate =%d\n", __func__,
  230. ndp_tx_rate);
  231. PlatformAcquireSpinLock(adapter, RT_TX_SPINLOCK);
  232. if (MgntGetBuffer(adapter, &tcb, &p_buf)) {
  233. construct_ht_ndpa_packet(
  234. adapter,
  235. RA,
  236. p_buf->Buffer.VirtualAddress,
  237. &tcb->PacketLength,
  238. BW);
  239. tcb->bTxEnableSwCalcDur = true;
  240. tcb->BWOfPacket = BW;
  241. MgntSendPacket(adapter, tcb, p_buf, tcb->PacketLength, NORMAL_QUEUE, ndp_tx_rate);
  242. } else
  243. ret = false;
  244. PlatformReleaseSpinLock(adapter, RT_TX_SPINLOCK);
  245. if (ret)
  246. RT_DISP_DATA(FBEAM, FBEAM_DATA, "", p_buf->Buffer.VirtualAddress, tcb->PacketLength);
  247. return ret;
  248. }
  249. void construct_vht_ndpa_packet(
  250. struct dm_struct *dm,
  251. u8 *RA,
  252. u16 AID,
  253. u8 *buffer,
  254. u32 *p_length,
  255. enum channel_width BW)
  256. {
  257. u16 duration = 0;
  258. u8 sequence = 0;
  259. u8 *p_ndpa_frame = buffer;
  260. struct _RT_NDPA_STA_INFO sta_info;
  261. // 2017/11 MH PHYDM compile. But why need to use windows maco?
  262. // For all linux code, it should be useless?
  263. //void *adapter = dm->adapter;
  264. ADAPTER * adapter = (PADAPTER)(dm->adapter);
  265. u8 idx = 0;
  266. struct _RT_BEAMFORMEE_ENTRY *beamform_entry = phydm_beamforming_get_bfee_entry_by_addr(dm, RA, &idx);
  267. /* @Frame control. */
  268. SET_80211_HDR_FRAME_CONTROL(p_ndpa_frame, 0);
  269. SET_80211_HDR_TYPE_AND_SUBTYPE(p_ndpa_frame, Type_NDPA);
  270. SET_80211_HDR_ADDRESS1(p_ndpa_frame, RA);
  271. SET_80211_HDR_ADDRESS2(p_ndpa_frame, beamform_entry->my_mac_addr);
  272. // 2017/11 MH PHYDM compile. But why need to use windows maco?
  273. // For all linux code, it should be useless?
  274. duration = 2 * a_SifsTime + 44;
  275. if (BW == CHANNEL_WIDTH_80)
  276. duration += 40;
  277. else if (BW == CHANNEL_WIDTH_40)
  278. duration += 87;
  279. else
  280. duration += 180;
  281. SET_80211_HDR_DURATION(p_ndpa_frame, duration);
  282. sequence = *(dm->sounding_seq) << 2;
  283. odm_move_memory(dm, p_ndpa_frame + 16, &sequence, 1);
  284. if (phydm_acting_determine(dm, phydm_acting_as_ibss) || phydm_acting_determine(dm, phydm_acting_as_ap) == false)
  285. AID = 0;
  286. sta_info.aid = AID;
  287. sta_info.feedback_type = 0;
  288. sta_info.nc_index = 0;
  289. odm_move_memory(dm, p_ndpa_frame + 17, (u8 *)&sta_info, 2);
  290. *p_length = 19;
  291. }
  292. boolean
  293. send_fw_vht_ndpa_packet(
  294. void *dm_void,
  295. u8 *RA,
  296. u16 AID,
  297. enum channel_width BW)
  298. {
  299. struct dm_struct *dm = (struct dm_struct *)dm_void;
  300. void *adapter = dm->adapter;
  301. PRT_TCB tcb;
  302. PRT_TX_LOCAL_BUFFER p_buf;
  303. boolean ret = true;
  304. u32 buf_len;
  305. u8 *buf_addr;
  306. u8 desc_len = 0, idx = 0, ndp_tx_rate = 0;
  307. void *p_def_adapter = GetDefaultAdapter(((PADAPTER)adapter));
  308. HAL_DATA_TYPE *hal_data = GET_HAL_DATA(((PADAPTER)adapter));
  309. struct _RT_BEAMFORMEE_ENTRY *beamform_entry = phydm_beamforming_get_bfee_entry_by_addr(dm, RA, &idx);
  310. PHYDM_DBG(dm, DBG_TXBF, "[%s] Start!\n", __func__);
  311. if (beamform_entry == NULL)
  312. return false;
  313. ndp_tx_rate = beamforming_get_vht_ndp_tx_rate(dm, beamform_entry->comp_steering_num_of_bfer);
  314. PHYDM_DBG(dm, DBG_TXBF, "[%s] ndp_tx_rate =%d\n", __func__,
  315. ndp_tx_rate);
  316. PlatformAcquireSpinLock(adapter, RT_TX_SPINLOCK);
  317. if (MgntGetFWBuffer(p_def_adapter, &tcb, &p_buf)) {
  318. #if (DEV_BUS_TYPE != RT_PCI_INTERFACE)
  319. desc_len = ((PADAPTER)adapter)->HWDescHeadLength - hal_data->USBALLDummyLength;
  320. #endif
  321. buf_addr = p_buf->Buffer.VirtualAddress + desc_len;
  322. construct_vht_ndpa_packet(
  323. dm,
  324. RA,
  325. AID,
  326. buf_addr,
  327. &buf_len,
  328. BW);
  329. tcb->PacketLength = buf_len + desc_len;
  330. tcb->bTxEnableSwCalcDur = true;
  331. tcb->BWOfPacket = BW;
  332. if (phydm_acting_determine(dm, phydm_acting_as_ibss) || phydm_acting_determine(dm, phydm_acting_as_ap))
  333. tcb->G_ID = 63;
  334. tcb->P_AID = beamform_entry->p_aid;
  335. tcb->DataRate = ndp_tx_rate; /*@decide by nr*/
  336. ((PADAPTER)adapter)->HalFunc.CmdSendPacketHandler(adapter, tcb, p_buf, tcb->PacketLength, DESC_PACKET_TYPE_NORMAL, false);
  337. } else
  338. ret = false;
  339. PlatformReleaseSpinLock(adapter, RT_TX_SPINLOCK);
  340. PHYDM_DBG(dm, DBG_TXBF, "[%s] End, ret=%d\n", __func__, ret);
  341. if (ret)
  342. RT_DISP_DATA(FBEAM, FBEAM_DATA, "", p_buf->Buffer.VirtualAddress, tcb->PacketLength);
  343. return ret;
  344. }
  345. boolean
  346. send_sw_vht_ndpa_packet(
  347. void *dm_void,
  348. u8 *RA,
  349. u16 AID,
  350. enum channel_width BW)
  351. {
  352. struct dm_struct *dm = (struct dm_struct *)dm_void;
  353. void *adapter = dm->adapter;
  354. PRT_TCB tcb;
  355. PRT_TX_LOCAL_BUFFER p_buf;
  356. boolean ret = true;
  357. u8 idx = 0, ndp_tx_rate = 0;
  358. struct _RT_BEAMFORMEE_ENTRY *beamform_entry = phydm_beamforming_get_bfee_entry_by_addr(dm, RA, &idx);
  359. ndp_tx_rate = beamforming_get_vht_ndp_tx_rate(dm, beamform_entry->comp_steering_num_of_bfer);
  360. PHYDM_DBG(dm, DBG_TXBF, "[%s] ndp_tx_rate =%d\n", __func__,
  361. ndp_tx_rate);
  362. PlatformAcquireSpinLock(adapter, RT_TX_SPINLOCK);
  363. if (MgntGetBuffer(adapter, &tcb, &p_buf)) {
  364. construct_vht_ndpa_packet(
  365. dm,
  366. RA,
  367. AID,
  368. p_buf->Buffer.VirtualAddress,
  369. &tcb->PacketLength,
  370. BW);
  371. tcb->bTxEnableSwCalcDur = true;
  372. tcb->BWOfPacket = BW;
  373. /*rate of NDP decide by nr*/
  374. MgntSendPacket(adapter, tcb, p_buf, tcb->PacketLength, NORMAL_QUEUE, ndp_tx_rate);
  375. } else
  376. ret = false;
  377. PlatformReleaseSpinLock(adapter, RT_TX_SPINLOCK);
  378. if (ret)
  379. RT_DISP_DATA(FBEAM, FBEAM_DATA, "", p_buf->Buffer.VirtualAddress, tcb->PacketLength);
  380. return ret;
  381. }
  382. #ifdef SUPPORT_MU_BF
  383. #if (SUPPORT_MU_BF == 1)
  384. /*@
  385. * Description: On VHT GID management frame by an MU beamformee.
  386. *
  387. * 2015.05.20. Created by tynli.
  388. */
  389. enum rt_status
  390. beamforming_get_vht_gid_mgnt_frame(
  391. void *adapter,
  392. PRT_RFD rfd,
  393. POCTET_STRING p_pdu_os)
  394. {
  395. HAL_DATA_TYPE *hal_data = GET_HAL_DATA(((PADAPTER)adapter));
  396. struct dm_struct *dm = &hal_data->DM_OutSrc;
  397. enum rt_status rt_status = RT_STATUS_SUCCESS;
  398. u8 *p_buffer = NULL;
  399. u8 *p_raddr = NULL;
  400. u8 mem_status[8] = {0}, user_pos[16] = {0};
  401. u8 idx;
  402. struct _RT_BEAMFORMING_INFO *beam_info = &(dm->beamforming_info);
  403. struct _RT_BEAMFORMER_ENTRY *beamform_entry = &beam_info->beamformer_entry[beam_info->mu_ap_index];
  404. PHYDM_DBG(dm, DBG_TXBF, "[%s] On VHT GID mgnt frame!\n", __func__);
  405. /* @Check length*/
  406. if (p_pdu_os->length < (FRAME_OFFSET_VHT_GID_MGNT_USER_POSITION_ARRAY + 16)) {
  407. PHYDM_DBG(dm, DBG_TXBF, "%s: Invalid length (%d)\n", __func__,
  408. p_pdu_os->length);
  409. return RT_STATUS_INVALID_LENGTH;
  410. }
  411. /* @Check RA*/
  412. p_raddr = (u8 *)(p_pdu_os->Octet) + 4;
  413. if (!eq_mac_addr(p_raddr, adapter->CurrentAddress)) {
  414. PHYDM_DBG(dm, DBG_TXBF, "%s: Drop because of RA error.\n",
  415. __func__);
  416. return RT_STATUS_PKT_DROP;
  417. }
  418. RT_DISP_DATA(FBEAM, FBEAM_DATA, "On VHT GID Mgnt Frame ==>:\n", p_pdu_os->Octet, p_pdu_os->length);
  419. /*Parsing Membership status array*/
  420. p_buffer = p_pdu_os->Octet + FRAME_OFFSET_VHT_GID_MGNT_MEMBERSHIP_STATUS_ARRAY;
  421. for (idx = 0; idx < 8; idx++) {
  422. mem_status[idx] = GET_VHT_GID_MGNT_INFO_MEMBERSHIP_STATUS(p_buffer + idx);
  423. beamform_entry->gid_valid[idx] = GET_VHT_GID_MGNT_INFO_MEMBERSHIP_STATUS(p_buffer + idx);
  424. }
  425. RT_DISP_DATA(FBEAM, FBEAM_DATA, "mem_status: ", mem_status, 8);
  426. /* Parsing User Position array*/
  427. p_buffer = p_pdu_os->Octet + FRAME_OFFSET_VHT_GID_MGNT_USER_POSITION_ARRAY;
  428. for (idx = 0; idx < 16; idx++) {
  429. user_pos[idx] = GET_VHT_GID_MGNT_INFO_USER_POSITION(p_buffer + idx);
  430. beamform_entry->user_position[idx] = GET_VHT_GID_MGNT_INFO_USER_POSITION(p_buffer + idx);
  431. }
  432. RT_DISP_DATA(FBEAM, FBEAM_DATA, "user_pos: ", user_pos, 16);
  433. /* @Group ID detail printed*/
  434. {
  435. u8 i, j;
  436. u8 tmp_val;
  437. u16 tmp_val2;
  438. for (i = 0; i < 8; i++) {
  439. tmp_val = mem_status[i];
  440. tmp_val2 = ((user_pos[i * 2 + 1] << 8) & 0xFF00) + (user_pos[i * 2] & 0xFF);
  441. for (j = 0; j < 8; j++) {
  442. if ((tmp_val >> j) & BIT(0)) {
  443. PHYDM_DBG(dm, DBG_TXBF, "Use Group ID (%d), User Position (%d)\n",
  444. (i * 8 + j), (tmp_val2 >> 2 * j) & 0x3);
  445. }
  446. }
  447. }
  448. }
  449. /* @Indicate GID frame to IHV service. */
  450. {
  451. u8 indibuffer[24] = {0};
  452. u8 indioffset = 0;
  453. PlatformMoveMemory(indibuffer + indioffset, beamform_entry->gid_valid, 8);
  454. indioffset += 8;
  455. PlatformMoveMemory(indibuffer + indioffset, beamform_entry->user_position, 16);
  456. indioffset += 16;
  457. PlatformIndicateCustomStatus(
  458. adapter,
  459. RT_CUSTOM_EVENT_VHT_RECV_GID_MGNT_FRAME,
  460. RT_CUSTOM_INDI_TARGET_IHV,
  461. indibuffer,
  462. indioffset);
  463. }
  464. /* @Config HW GID table */
  465. hal_com_txbf_config_gtab(dm);
  466. return rt_status;
  467. }
  468. /*@
  469. * Description: Construct VHT Group ID (GID) management frame.
  470. *
  471. * 2015.05.20. Created by tynli.
  472. */
  473. void construct_vht_gid_mgnt_frame(
  474. struct dm_struct *dm,
  475. u8 *RA,
  476. struct _RT_BEAMFORMEE_ENTRY *beamform_entry,
  477. u8 *buffer,
  478. u32 *p_length
  479. )
  480. {
  481. struct _RT_BEAMFORMING_INFO *beam_info = &(dm->beamforming_info);
  482. void *adapter = beam_info->source_adapter;
  483. OCTET_STRING os_ftm_frame, tmp;
  484. FillOctetString(os_ftm_frame, buffer, 0);
  485. *p_length = 0;
  486. ConstructMaFrameHdr(
  487. adapter,
  488. RA,
  489. ACT_CAT_VHT,
  490. ACT_VHT_GROUPID_MANAGEMENT,
  491. &os_ftm_frame);
  492. /* @Membership status array*/
  493. FillOctetString(tmp, beamform_entry->gid_valid, 8);
  494. PacketAppendData(&os_ftm_frame, tmp);
  495. /* User Position array*/
  496. FillOctetString(tmp, beamform_entry->user_position, 16);
  497. PacketAppendData(&os_ftm_frame, tmp);
  498. *p_length = os_ftm_frame.length;
  499. RT_DISP_DATA(FBEAM, FBEAM_DATA, "construct_vht_gid_mgnt_frame():\n", buffer, *p_length);
  500. }
  501. boolean
  502. send_sw_vht_gid_mgnt_frame(
  503. void *dm_void,
  504. u8 *RA,
  505. u8 idx)
  506. {
  507. struct dm_struct *dm = (struct dm_struct *)dm_void;
  508. PRT_TCB tcb;
  509. PRT_TX_LOCAL_BUFFER p_buf;
  510. boolean ret = true;
  511. u8 data_rate = 0;
  512. struct _RT_BEAMFORMING_INFO *beam_info = &(dm->beamforming_info);
  513. struct _RT_BEAMFORMEE_ENTRY *beamform_entry = &beam_info->beamformee_entry[idx];
  514. void *adapter = beam_info->source_adapter;
  515. PHYDM_DBG(dm, DBG_TXBF, "[%s] Start!\n", __func__);
  516. PlatformAcquireSpinLock(adapter, RT_TX_SPINLOCK);
  517. if (MgntGetBuffer(adapter, &tcb, &p_buf)) {
  518. construct_vht_gid_mgnt_frame(
  519. dm,
  520. RA,
  521. beamform_entry,
  522. p_buf->Buffer.VirtualAddress,
  523. &tcb->PacketLength);
  524. tcb->bw_of_packet = CHANNEL_WIDTH_20;
  525. data_rate = MGN_6M;
  526. MgntSendPacket(adapter, tcb, p_buf, tcb->PacketLength, NORMAL_QUEUE, data_rate);
  527. } else
  528. ret = false;
  529. PlatformReleaseSpinLock(adapter, RT_TX_SPINLOCK);
  530. if (ret)
  531. RT_DISP_DATA(FBEAM, FBEAM_DATA, "", p_buf->Buffer.VirtualAddress, tcb->PacketLength);
  532. return ret;
  533. }
  534. /*@
  535. * Description: Construct VHT beamforming report poll.
  536. *
  537. * 2015.05.20. Created by tynli.
  538. */
  539. void construct_vht_bf_report_poll(
  540. struct dm_struct *dm,
  541. u8 *RA,
  542. u8 *buffer,
  543. u32 *p_length)
  544. {
  545. struct _RT_BEAMFORMING_INFO *beam_info = &(dm->beamforming_info);
  546. void *adapter = beam_info->source_adapter;
  547. u8 *p_bf_rpt_poll = buffer;
  548. /* @Frame control*/
  549. SET_80211_HDR_FRAME_CONTROL(p_bf_rpt_poll, 0);
  550. SET_80211_HDR_TYPE_AND_SUBTYPE(p_bf_rpt_poll, Type_Beamforming_Report_Poll);
  551. /* @duration*/
  552. SET_80211_HDR_DURATION(p_bf_rpt_poll, 100);
  553. /* RA*/
  554. SET_VHT_BF_REPORT_POLL_RA(p_bf_rpt_poll, RA);
  555. /* TA*/
  556. SET_VHT_BF_REPORT_POLL_TA(p_bf_rpt_poll, adapter->CurrentAddress);
  557. /* @Feedback Segment Retransmission Bitmap*/
  558. SET_VHT_BF_REPORT_POLL_FEEDBACK_SEG_RETRAN_BITMAP(p_bf_rpt_poll, 0xFF);
  559. *p_length = 17;
  560. RT_DISP_DATA(FBEAM, FBEAM_DATA, "construct_vht_bf_report_poll():\n", buffer, *p_length);
  561. }
  562. boolean
  563. send_sw_vht_bf_report_poll(
  564. void *dm_void,
  565. u8 *RA,
  566. boolean is_final_poll)
  567. {
  568. struct dm_struct *dm = (struct dm_struct *)dm_void;
  569. PRT_TCB tcb;
  570. PRT_TX_LOCAL_BUFFER p_buf;
  571. boolean ret = true;
  572. u8 idx = 0, data_rate = 0;
  573. struct _RT_BEAMFORMING_INFO *beam_info = &(dm->beamforming_info);
  574. struct _RT_BEAMFORMEE_ENTRY *beamform_entry = phydm_beamforming_get_bfee_entry_by_addr(dm, RA, &idx);
  575. void *adapter = beam_info->source_adapter;
  576. PHYDM_DBG(dm, DBG_TXBF, "[%s] Start!\n", __func__);
  577. PlatformAcquireSpinLock(adapter, RT_TX_SPINLOCK);
  578. if (MgntGetBuffer(adapter, &tcb, &p_buf)) {
  579. construct_vht_bf_report_poll(
  580. dm,
  581. RA,
  582. p_buf->Buffer.VirtualAddress,
  583. &tcb->PacketLength);
  584. tcb->bTxEnableSwCalcDur = true; /* @<tynli_note> need?*/
  585. tcb->BWOfPacket = CHANNEL_WIDTH_20;
  586. if (is_final_poll)
  587. tcb->TxBFPktType = RT_BF_PKT_TYPE_FINAL_BF_REPORT_POLL;
  588. else
  589. tcb->TxBFPktType = RT_BF_PKT_TYPE_BF_REPORT_POLL;
  590. data_rate = MGN_6M; /* @Legacy OFDM rate*/
  591. MgntSendPacket(adapter, tcb, p_buf, tcb->PacketLength, NORMAL_QUEUE, data_rate);
  592. } else
  593. ret = false;
  594. PlatformReleaseSpinLock(adapter, RT_TX_SPINLOCK);
  595. if (ret)
  596. RT_DISP_DATA(FBEAM, FBEAM_DATA, "send_sw_vht_bf_report_poll:\n",
  597. p_buf->Buffer.VirtualAddress, tcb->PacketLength);
  598. return ret;
  599. }
  600. /*@
  601. * Description: Construct VHT MU NDPA packet.
  602. * <Note> We should combine this function with construct_vht_ndpa_packet() in the future.
  603. *
  604. * 2015.05.21. Created by tynli.
  605. */
  606. void construct_vht_mu_ndpa_packet(
  607. struct dm_struct *dm,
  608. enum channel_width BW,
  609. u8 *buffer,
  610. u32 *p_length)
  611. {
  612. struct _RT_BEAMFORMING_INFO *beam_info = &(dm->beamforming_info);
  613. void *adapter = beam_info->source_adapter;
  614. u16 duration = 0;
  615. u8 sequence = 0;
  616. u8 *p_ndpa_frame = buffer;
  617. struct _RT_NDPA_STA_INFO sta_info;
  618. u8 idx;
  619. u8 dest_addr[6] = {0};
  620. struct _RT_BEAMFORMEE_ENTRY *entry = NULL;
  621. /* @Fill the first MU BFee entry (STA1) MAC addr to destination address then
  622. HW will change A1 to broadcast addr. 2015.05.28. Suggested by SD1 Chunchu. */
  623. for (idx = 0; idx < BEAMFORMEE_ENTRY_NUM; idx++) {
  624. entry = &(beam_info->beamformee_entry[idx]);
  625. if (entry->is_mu_sta) {
  626. cp_mac_addr(dest_addr, entry->mac_addr);
  627. break;
  628. }
  629. }
  630. if (entry == NULL)
  631. return;
  632. /* @Frame control.*/
  633. SET_80211_HDR_FRAME_CONTROL(p_ndpa_frame, 0);
  634. SET_80211_HDR_TYPE_AND_SUBTYPE(p_ndpa_frame, Type_NDPA);
  635. SET_80211_HDR_ADDRESS1(p_ndpa_frame, dest_addr);
  636. SET_80211_HDR_ADDRESS2(p_ndpa_frame, entry->my_mac_addr);
  637. /*@--------------------------------------------*/
  638. /* @<Note> Need to modify "duration" to MU consideration. */
  639. duration = 2 * a_SifsTime + 44;
  640. if (BW == CHANNEL_WIDTH_80)
  641. duration += 40;
  642. else if (BW == CHANNEL_WIDTH_40)
  643. duration += 87;
  644. else
  645. duration += 180;
  646. /*@--------------------------------------------*/
  647. SET_80211_HDR_DURATION(p_ndpa_frame, duration);
  648. sequence = *(dm->sounding_seq) << 2;
  649. odm_move_memory(dm, p_ndpa_frame + 16, &sequence, 1);
  650. *p_length = 17;
  651. /* @Construct STA info. for multiple STAs*/
  652. for (idx = 0; idx < BEAMFORMEE_ENTRY_NUM; idx++) {
  653. entry = &(beam_info->beamformee_entry[idx]);
  654. if (entry->is_mu_sta) {
  655. sta_info.aid = entry->AID;
  656. sta_info.feedback_type = 1; /* @1'b1: MU*/
  657. sta_info.nc_index = 0;
  658. PHYDM_DBG(dm, DBG_TXBF,
  659. "[%s] Get beamformee_entry idx(%d), AID =%d\n",
  660. __func__, idx, entry->AID);
  661. odm_move_memory(dm, p_ndpa_frame + (*p_length), (u8 *)&sta_info, 2);
  662. *p_length += 2;
  663. }
  664. }
  665. }
  666. boolean
  667. send_sw_vht_mu_ndpa_packet(
  668. void *dm_void,
  669. enum channel_width BW)
  670. {
  671. struct dm_struct *dm = (struct dm_struct *)dm_void;
  672. PRT_TCB tcb;
  673. PRT_TX_LOCAL_BUFFER p_buf;
  674. boolean ret = true;
  675. u8 ndp_tx_rate = 0;
  676. struct _RT_BEAMFORMING_INFO *beam_info = &(dm->beamforming_info);
  677. void *adapter = beam_info->source_adapter;
  678. ndp_tx_rate = MGN_VHT2SS_MCS0;
  679. PHYDM_DBG(dm, DBG_TXBF, "[%s] ndp_tx_rate =%d\n", __func__,
  680. ndp_tx_rate);
  681. PlatformAcquireSpinLock(adapter, RT_TX_SPINLOCK);
  682. if (MgntGetBuffer(adapter, &tcb, &p_buf)) {
  683. construct_vht_mu_ndpa_packet(
  684. dm,
  685. BW,
  686. p_buf->Buffer.VirtualAddress,
  687. &tcb->PacketLength);
  688. tcb->bTxEnableSwCalcDur = true;
  689. tcb->BWOfPacket = BW;
  690. tcb->TxBFPktType = RT_BF_PKT_TYPE_BROADCAST_NDPA;
  691. /*rate of NDP decide by nr*/
  692. MgntSendPacket(adapter, tcb, p_buf, tcb->PacketLength, NORMAL_QUEUE, ndp_tx_rate);
  693. } else
  694. ret = false;
  695. PlatformReleaseSpinLock(adapter, RT_TX_SPINLOCK);
  696. if (ret)
  697. RT_DISP_DATA(FBEAM, FBEAM_DATA, "", p_buf->Buffer.VirtualAddress, tcb->PacketLength);
  698. return ret;
  699. }
  700. void dbg_construct_vht_mundpa_packet(
  701. struct dm_struct *dm,
  702. enum channel_width BW,
  703. u8 *buffer,
  704. u32 *p_length)
  705. {
  706. struct _RT_BEAMFORMING_INFO *beam_info = &(dm->beamforming_info);
  707. void *adapter = beam_info->source_adapter;
  708. u16 duration = 0;
  709. u8 sequence = 0;
  710. u8 *p_ndpa_frame = buffer;
  711. struct _RT_NDPA_STA_INFO sta_info;
  712. u8 idx;
  713. u8 dest_addr[6] = {0};
  714. struct _RT_BEAMFORMEE_ENTRY *entry = NULL;
  715. boolean is_STA1 = false;
  716. /* @Fill the first MU BFee entry (STA1) MAC addr to destination address then
  717. HW will change A1 to broadcast addr. 2015.05.28. Suggested by SD1 Chunchu. */
  718. for (idx = 0; idx < BEAMFORMEE_ENTRY_NUM; idx++) {
  719. entry = &(beam_info->beamformee_entry[idx]);
  720. if (entry->is_mu_sta) {
  721. if (is_STA1 == false) {
  722. is_STA1 = true;
  723. continue;
  724. } else {
  725. cp_mac_addr(dest_addr, entry->mac_addr);
  726. break;
  727. }
  728. }
  729. }
  730. /* @Frame control.*/
  731. SET_80211_HDR_FRAME_CONTROL(p_ndpa_frame, 0);
  732. SET_80211_HDR_TYPE_AND_SUBTYPE(p_ndpa_frame, Type_NDPA);
  733. SET_80211_HDR_ADDRESS1(p_ndpa_frame, dest_addr);
  734. SET_80211_HDR_ADDRESS2(p_ndpa_frame, dm->CurrentAddress);
  735. /*@--------------------------------------------*/
  736. /* @<Note> Need to modify "duration" to MU consideration. */
  737. duration = 2 * a_SifsTime + 44;
  738. if (BW == CHANNEL_WIDTH_80)
  739. duration += 40;
  740. else if (BW == CHANNEL_WIDTH_40)
  741. duration += 87;
  742. else
  743. duration += 180;
  744. /*@--------------------------------------------*/
  745. SET_80211_HDR_DURATION(p_ndpa_frame, duration);
  746. sequence = *(dm->sounding_seq) << 2;
  747. odm_move_memory(dm, p_ndpa_frame + 16, &sequence, 1);
  748. *p_length = 17;
  749. /*STA2's STA Info*/
  750. sta_info.aid = entry->aid;
  751. sta_info.feedback_type = 1; /* @1'b1: MU */
  752. sta_info.nc_index = 0;
  753. PHYDM_DBG(dm, DBG_TXBF, "[%s] Get beamformee_entry idx(%d), AID =%d\n",
  754. __func__, idx, entry->aid);
  755. odm_move_memory(dm, p_ndpa_frame + (*p_length), (u8 *)&sta_info, 2);
  756. *p_length += 2;
  757. }
  758. boolean
  759. dbg_send_sw_vht_mundpa_packet(
  760. void *dm_void,
  761. enum channel_width BW)
  762. {
  763. struct dm_struct *dm = (struct dm_struct *)dm_void;
  764. PRT_TCB tcb;
  765. PRT_TX_LOCAL_BUFFER p_buf;
  766. boolean ret = true;
  767. u8 ndp_tx_rate = 0;
  768. struct _RT_BEAMFORMING_INFO *beam_info = &(dm->beamforming_info);
  769. void *adapter = beam_info->source_adapter;
  770. ndp_tx_rate = MGN_VHT2SS_MCS0;
  771. PHYDM_DBG(dm, DBG_TXBF, "[%s] ndp_tx_rate =%d\n", __func__,
  772. ndp_tx_rate);
  773. PlatformAcquireSpinLock(adapter, RT_TX_SPINLOCK);
  774. if (MgntGetBuffer(adapter, &tcb, &p_buf)) {
  775. dbg_construct_vht_mundpa_packet(
  776. dm,
  777. BW,
  778. p_buf->Buffer.VirtualAddress,
  779. &tcb->PacketLength);
  780. tcb->bTxEnableSwCalcDur = true;
  781. tcb->BWOfPacket = BW;
  782. tcb->TxBFPktType = RT_BF_PKT_TYPE_UNICAST_NDPA;
  783. /*rate of NDP decide by nr*/
  784. MgntSendPacket(adapter, tcb, p_buf, tcb->PacketLength, NORMAL_QUEUE, ndp_tx_rate);
  785. } else
  786. ret = false;
  787. PlatformReleaseSpinLock(adapter, RT_TX_SPINLOCK);
  788. if (ret)
  789. RT_DISP_DATA(FBEAM, FBEAM_DATA, "", p_buf->Buffer.VirtualAddress, tcb->PacketLength);
  790. return ret;
  791. }
  792. #endif /*@#if (SUPPORT_MU_BF == 1)*/
  793. #endif /*@#ifdef SUPPORT_MU_BF*/
  794. #elif (DM_ODM_SUPPORT_TYPE == ODM_CE)
  795. u32 beamforming_get_report_frame(
  796. void *dm_void,
  797. union recv_frame *precv_frame)
  798. {
  799. struct dm_struct *dm = (struct dm_struct *)dm_void;
  800. u32 ret = _SUCCESS;
  801. struct _RT_BEAMFORMEE_ENTRY *beamform_entry = NULL;
  802. u8 *pframe = precv_frame->u.hdr.rx_data;
  803. u32 frame_len = precv_frame->u.hdr.len;
  804. u8 *TA;
  805. u8 idx, offset;
  806. /*@Memory comparison to see if CSI report is the same with previous one*/
  807. TA = get_addr2_ptr(pframe);
  808. beamform_entry = phydm_beamforming_get_bfee_entry_by_addr(dm, TA, &idx);
  809. if (beamform_entry->beamform_entry_cap & BEAMFORMER_CAP_VHT_SU)
  810. offset = 31; /*@24+(1+1+3)+2 MAC header+(Category+ActionCode+MIMOControlField)+SNR(nc=2)*/
  811. else if (beamform_entry->beamform_entry_cap & BEAMFORMER_CAP_HT_EXPLICIT)
  812. offset = 34; /*@24+(1+1+6)+2 MAC header+(Category+ActionCode+MIMOControlField)+SNR(nc=2)*/
  813. else
  814. return ret;
  815. return ret;
  816. }
  817. boolean
  818. send_fw_ht_ndpa_packet(
  819. void *dm_void,
  820. u8 *RA,
  821. enum channel_width BW)
  822. {
  823. struct dm_struct *dm = (struct dm_struct *)dm_void;
  824. struct _ADAPTER *adapter = dm->adapter;
  825. struct xmit_frame *pmgntframe;
  826. struct pkt_attrib *pattrib;
  827. struct rtw_ieee80211_hdr *pwlanhdr;
  828. struct xmit_priv *pxmitpriv = &(adapter->xmitpriv);
  829. struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
  830. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  831. u8 action_hdr[4] = {ACT_CAT_VENDOR, 0x00, 0xe0, 0x4c};
  832. u8 *pframe;
  833. u16 *fctrl;
  834. u16 duration = 0;
  835. u8 a_sifs_time = 0, ndp_tx_rate = 0, idx = 0;
  836. struct _RT_BEAMFORMING_INFO *beam_info = &(dm->beamforming_info);
  837. struct _RT_BEAMFORMEE_ENTRY *beamform_entry = phydm_beamforming_get_bfee_entry_by_addr(dm, RA, &idx);
  838. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  839. if (pmgntframe == NULL) {
  840. PHYDM_DBG(dm, DBG_TXBF, "%s, alloc mgnt frame fail\n",
  841. __func__);
  842. return false;
  843. }
  844. /* update attribute */
  845. pattrib = &pmgntframe->attrib;
  846. update_mgntframe_attrib(adapter, pattrib);
  847. pattrib->qsel = QSLT_BEACON;
  848. ndp_tx_rate = beamforming_get_htndp_tx_rate(dm, beamform_entry->comp_steering_num_of_bfer);
  849. PHYDM_DBG(dm, DBG_TXBF, "[%s] ndp_tx_rate =%d\n", __func__,
  850. ndp_tx_rate);
  851. pattrib->rate = ndp_tx_rate;
  852. pattrib->bwmode = BW;
  853. pattrib->order = 1;
  854. pattrib->subtype = WIFI_ACTION_NOACK;
  855. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  856. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  857. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  858. fctrl = &pwlanhdr->frame_ctl;
  859. *(fctrl) = 0;
  860. set_order_bit(pframe);
  861. set_frame_sub_type(pframe, WIFI_ACTION_NOACK);
  862. _rtw_memcpy(pwlanhdr->addr1, RA, ETH_ALEN);
  863. _rtw_memcpy(pwlanhdr->addr2, beamform_entry->my_mac_addr, ETH_ALEN);
  864. _rtw_memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
  865. if (pmlmeext->cur_wireless_mode == WIRELESS_11B)
  866. a_sifs_time = 10;
  867. else
  868. a_sifs_time = 16;
  869. duration = 2 * a_sifs_time + 40;
  870. if (BW == CHANNEL_WIDTH_40)
  871. duration += 87;
  872. else
  873. duration += 180;
  874. set_duration(pframe, duration);
  875. /* @HT control field */
  876. SET_HT_CTRL_CSI_STEERING(pframe + 24, 3);
  877. SET_HT_CTRL_NDP_ANNOUNCEMENT(pframe + 24, 1);
  878. _rtw_memcpy(pframe + 28, action_hdr, 4);
  879. pattrib->pktlen = 32;
  880. pattrib->last_txcmdsz = pattrib->pktlen;
  881. dump_mgntframe(adapter, pmgntframe);
  882. return true;
  883. }
  884. boolean
  885. send_sw_ht_ndpa_packet(
  886. void *dm_void,
  887. u8 *RA,
  888. enum channel_width BW)
  889. {
  890. struct dm_struct *dm = (struct dm_struct *)dm_void;
  891. struct _ADAPTER *adapter = dm->adapter;
  892. struct xmit_frame *pmgntframe;
  893. struct pkt_attrib *pattrib;
  894. struct rtw_ieee80211_hdr *pwlanhdr;
  895. struct xmit_priv *pxmitpriv = &(adapter->xmitpriv);
  896. struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
  897. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  898. u8 action_hdr[4] = {ACT_CAT_VENDOR, 0x00, 0xe0, 0x4c};
  899. u8 *pframe;
  900. u16 *fctrl;
  901. u16 duration = 0;
  902. u8 a_sifs_time = 0, ndp_tx_rate = 0, idx = 0;
  903. struct _RT_BEAMFORMING_INFO *beam_info = &(dm->beamforming_info);
  904. struct _RT_BEAMFORMEE_ENTRY *beamform_entry = phydm_beamforming_get_bfee_entry_by_addr(dm, RA, &idx);
  905. ndp_tx_rate = beamforming_get_htndp_tx_rate(dm, beamform_entry->comp_steering_num_of_bfer);
  906. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  907. if (pmgntframe == NULL) {
  908. PHYDM_DBG(dm, DBG_TXBF, "%s, alloc mgnt frame fail\n",
  909. __func__);
  910. return false;
  911. }
  912. /*update attribute*/
  913. pattrib = &pmgntframe->attrib;
  914. update_mgntframe_attrib(adapter, pattrib);
  915. pattrib->qsel = QSLT_MGNT;
  916. pattrib->rate = ndp_tx_rate;
  917. pattrib->bwmode = BW;
  918. pattrib->order = 1;
  919. pattrib->subtype = WIFI_ACTION_NOACK;
  920. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  921. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  922. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  923. fctrl = &pwlanhdr->frame_ctl;
  924. *(fctrl) = 0;
  925. set_order_bit(pframe);
  926. set_frame_sub_type(pframe, WIFI_ACTION_NOACK);
  927. _rtw_memcpy(pwlanhdr->addr1, RA, ETH_ALEN);
  928. _rtw_memcpy(pwlanhdr->addr2, beamform_entry->my_mac_addr, ETH_ALEN);
  929. _rtw_memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
  930. if (pmlmeext->cur_wireless_mode == WIRELESS_11B)
  931. a_sifs_time = 10;
  932. else
  933. a_sifs_time = 16;
  934. duration = 2 * a_sifs_time + 40;
  935. if (BW == CHANNEL_WIDTH_40)
  936. duration += 87;
  937. else
  938. duration += 180;
  939. set_duration(pframe, duration);
  940. /*@HT control field*/
  941. SET_HT_CTRL_CSI_STEERING(pframe + 24, 3);
  942. SET_HT_CTRL_NDP_ANNOUNCEMENT(pframe + 24, 1);
  943. _rtw_memcpy(pframe + 28, action_hdr, 4);
  944. pattrib->pktlen = 32;
  945. pattrib->last_txcmdsz = pattrib->pktlen;
  946. dump_mgntframe(adapter, pmgntframe);
  947. return true;
  948. }
  949. boolean
  950. send_fw_vht_ndpa_packet(
  951. void *dm_void,
  952. u8 *RA,
  953. u16 AID,
  954. enum channel_width BW)
  955. {
  956. struct dm_struct *dm = (struct dm_struct *)dm_void;
  957. struct _ADAPTER *adapter = dm->adapter;
  958. struct xmit_frame *pmgntframe;
  959. struct pkt_attrib *pattrib;
  960. struct rtw_ieee80211_hdr *pwlanhdr;
  961. struct xmit_priv *pxmitpriv = &(adapter->xmitpriv);
  962. struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
  963. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  964. struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
  965. u8 *pframe;
  966. u16 *fctrl;
  967. u16 duration = 0;
  968. u8 sequence = 0, a_sifs_time = 0, ndp_tx_rate = 0, idx = 0;
  969. struct _RT_BEAMFORMING_INFO *beam_info = &(dm->beamforming_info);
  970. struct _RT_BEAMFORMEE_ENTRY *beamform_entry = phydm_beamforming_get_bfee_entry_by_addr(dm, RA, &idx);
  971. struct _RT_NDPA_STA_INFO sta_info;
  972. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  973. if (pmgntframe == NULL) {
  974. PHYDM_DBG(dm, DBG_TXBF, "%s, alloc mgnt frame fail\n",
  975. __func__);
  976. return false;
  977. }
  978. /* update attribute */
  979. pattrib = &pmgntframe->attrib;
  980. _rtw_memcpy(pattrib->ra, RA, ETH_ALEN);
  981. update_mgntframe_attrib(adapter, pattrib);
  982. pattrib->qsel = QSLT_BEACON;
  983. ndp_tx_rate = beamforming_get_vht_ndp_tx_rate(dm, beamform_entry->comp_steering_num_of_bfer);
  984. PHYDM_DBG(dm, DBG_TXBF, "[%s] ndp_tx_rate =%d\n", __func__,
  985. ndp_tx_rate);
  986. pattrib->rate = ndp_tx_rate;
  987. pattrib->bwmode = BW;
  988. pattrib->subtype = WIFI_NDPA;
  989. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  990. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  991. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  992. fctrl = &pwlanhdr->frame_ctl;
  993. *(fctrl) = 0;
  994. set_frame_sub_type(pframe, WIFI_NDPA);
  995. _rtw_memcpy(pwlanhdr->addr1, RA, ETH_ALEN);
  996. _rtw_memcpy(pwlanhdr->addr2, beamform_entry->my_mac_addr, ETH_ALEN);
  997. if (is_supported_5g(pmlmeext->cur_wireless_mode) || is_supported_ht(pmlmeext->cur_wireless_mode))
  998. a_sifs_time = 16;
  999. else
  1000. a_sifs_time = 10;
  1001. duration = 2 * a_sifs_time + 44;
  1002. if (BW == CHANNEL_WIDTH_80)
  1003. duration += 40;
  1004. else if (BW == CHANNEL_WIDTH_40)
  1005. duration += 87;
  1006. else
  1007. duration += 180;
  1008. set_duration(pframe, duration);
  1009. sequence = beam_info->sounding_sequence << 2;
  1010. if (beam_info->sounding_sequence >= 0x3f)
  1011. beam_info->sounding_sequence = 0;
  1012. else
  1013. beam_info->sounding_sequence++;
  1014. _rtw_memcpy(pframe + 16, &sequence, 1);
  1015. if (((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE) || ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE))
  1016. AID = 0;
  1017. sta_info.aid = AID;
  1018. sta_info.feedback_type = 0;
  1019. sta_info.nc_index = 0;
  1020. _rtw_memcpy(pframe + 17, (u8 *)&sta_info, 2);
  1021. pattrib->pktlen = 19;
  1022. pattrib->last_txcmdsz = pattrib->pktlen;
  1023. dump_mgntframe(adapter, pmgntframe);
  1024. return true;
  1025. }
  1026. boolean
  1027. send_sw_vht_ndpa_packet(
  1028. void *dm_void,
  1029. u8 *RA,
  1030. u16 AID,
  1031. enum channel_width BW)
  1032. {
  1033. struct dm_struct *dm = (struct dm_struct *)dm_void;
  1034. struct _ADAPTER *adapter = dm->adapter;
  1035. struct xmit_frame *pmgntframe;
  1036. struct pkt_attrib *pattrib;
  1037. struct rtw_ieee80211_hdr *pwlanhdr;
  1038. struct xmit_priv *pxmitpriv = &(adapter->xmitpriv);
  1039. struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
  1040. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1041. struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
  1042. struct _RT_NDPA_STA_INFO ndpa_sta_info;
  1043. u8 ndp_tx_rate = 0, sequence = 0, a_sifs_time = 0, idx = 0;
  1044. u8 *pframe;
  1045. u16 *fctrl;
  1046. u16 duration = 0;
  1047. struct _RT_BEAMFORMING_INFO *beam_info = &(dm->beamforming_info);
  1048. struct _RT_BEAMFORMEE_ENTRY *beamform_entry = phydm_beamforming_get_bfee_entry_by_addr(dm, RA, &idx);
  1049. ndp_tx_rate = beamforming_get_vht_ndp_tx_rate(dm, beamform_entry->comp_steering_num_of_bfer);
  1050. PHYDM_DBG(dm, DBG_TXBF, "[%s] ndp_tx_rate =%d\n", __func__,
  1051. ndp_tx_rate);
  1052. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  1053. if (pmgntframe == NULL) {
  1054. PHYDM_DBG(dm, DBG_TXBF, "%s, alloc mgnt frame fail\n",
  1055. __func__);
  1056. return false;
  1057. }
  1058. /*update attribute*/
  1059. pattrib = &pmgntframe->attrib;
  1060. _rtw_memcpy(pattrib->ra, RA, ETH_ALEN);
  1061. update_mgntframe_attrib(adapter, pattrib);
  1062. pattrib->qsel = QSLT_MGNT;
  1063. pattrib->rate = ndp_tx_rate;
  1064. pattrib->bwmode = BW;
  1065. pattrib->subtype = WIFI_NDPA;
  1066. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  1067. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  1068. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  1069. fctrl = &pwlanhdr->frame_ctl;
  1070. *(fctrl) = 0;
  1071. set_frame_sub_type(pframe, WIFI_NDPA);
  1072. _rtw_memcpy(pwlanhdr->addr1, RA, ETH_ALEN);
  1073. _rtw_memcpy(pwlanhdr->addr2, beamform_entry->my_mac_addr, ETH_ALEN);
  1074. if (is_supported_5g(pmlmeext->cur_wireless_mode) || is_supported_ht(pmlmeext->cur_wireless_mode))
  1075. a_sifs_time = 16;
  1076. else
  1077. a_sifs_time = 10;
  1078. duration = 2 * a_sifs_time + 44;
  1079. if (BW == CHANNEL_WIDTH_80)
  1080. duration += 40;
  1081. else if (BW == CHANNEL_WIDTH_40)
  1082. duration += 87;
  1083. else
  1084. duration += 180;
  1085. set_duration(pframe, duration);
  1086. sequence = beam_info->sounding_sequence << 2;
  1087. if (beam_info->sounding_sequence >= 0x3f)
  1088. beam_info->sounding_sequence = 0;
  1089. else
  1090. beam_info->sounding_sequence++;
  1091. _rtw_memcpy(pframe + 16, &sequence, 1);
  1092. if (((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE) || ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE))
  1093. AID = 0;
  1094. ndpa_sta_info.aid = AID;
  1095. ndpa_sta_info.feedback_type = 0;
  1096. ndpa_sta_info.nc_index = 0;
  1097. _rtw_memcpy(pframe + 17, (u8 *)&ndpa_sta_info, 2);
  1098. pattrib->pktlen = 19;
  1099. pattrib->last_txcmdsz = pattrib->pktlen;
  1100. dump_mgntframe(adapter, pmgntframe);
  1101. PHYDM_DBG(dm, DBG_TXBF, "[%s] [%d]\n", __func__, __LINE__);
  1102. return true;
  1103. }
  1104. #endif
  1105. void beamforming_get_ndpa_frame(
  1106. void *dm_void,
  1107. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  1108. OCTET_STRING pdu_os
  1109. #elif (DM_ODM_SUPPORT_TYPE == ODM_CE)
  1110. union recv_frame *precv_frame
  1111. #endif
  1112. )
  1113. {
  1114. struct dm_struct *dm = (struct dm_struct *)dm_void;
  1115. u8 *TA;
  1116. u8 idx, sequence;
  1117. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  1118. u8 *p_ndpa_frame = pdu_os.Octet;
  1119. #elif (DM_ODM_SUPPORT_TYPE == ODM_CE)
  1120. u8 *p_ndpa_frame = precv_frame->u.hdr.rx_data;
  1121. #endif
  1122. struct _RT_BEAMFORMER_ENTRY *beamformer_entry = NULL; /*@Modified By Jeffery @2014-10-29*/
  1123. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  1124. RT_DISP_DATA(FBEAM, FBEAM_DATA, "beamforming_get_ndpa_frame\n",
  1125. pdu_os.Octet, pdu_os.Length);
  1126. if (IsCtrlNDPA(p_ndpa_frame) == false)
  1127. #elif (DM_ODM_SUPPORT_TYPE == ODM_CE)
  1128. if (get_frame_sub_type(p_ndpa_frame) != WIFI_NDPA)
  1129. #endif
  1130. return;
  1131. else if (!(dm->support_ic_type & (ODM_RTL8812 | ODM_RTL8821))) {
  1132. PHYDM_DBG(dm, DBG_TXBF, "[%s] not 8812 or 8821A, return\n",
  1133. __func__);
  1134. return;
  1135. }
  1136. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  1137. TA = Frame_Addr2(pdu_os);
  1138. #elif (DM_ODM_SUPPORT_TYPE == ODM_CE)
  1139. TA = get_addr2_ptr(p_ndpa_frame);
  1140. #endif
  1141. /*Remove signaling TA. */
  1142. TA[0] = TA[0] & 0xFE;
  1143. beamformer_entry = phydm_beamforming_get_bfer_entry_by_addr(dm, TA, &idx); /* @Modified By Jeffery @2014-10-29 */
  1144. /*@Break options for Clock Reset*/
  1145. if (beamformer_entry == NULL)
  1146. return;
  1147. else if (!(beamformer_entry->beamform_entry_cap & BEAMFORMEE_CAP_VHT_SU))
  1148. return;
  1149. /*@log_success: As long as 8812A receive NDPA and feedback CSI succeed once, clock reset is NO LONGER needed !2015-04-10, Jeffery*/
  1150. /*@clock_reset_times: While BFer entry always doesn't receive our CSI, clock will reset again and again.So clock_reset_times is limited to 5 times.2015-04-13, Jeffery*/
  1151. else if ((beamformer_entry->log_success == 1) || (beamformer_entry->clock_reset_times == 5)) {
  1152. PHYDM_DBG(dm, DBG_TXBF,
  1153. "[%s] log_seq=%d, pre_log_seq=%d, log_retry_cnt=%d, log_success=%d, clock_reset_times=%d, clock reset is no longer needed.\n",
  1154. __func__, beamformer_entry->log_seq,
  1155. beamformer_entry->pre_log_seq,
  1156. beamformer_entry->log_retry_cnt,
  1157. beamformer_entry->log_success,
  1158. beamformer_entry->clock_reset_times);
  1159. return;
  1160. }
  1161. sequence = (p_ndpa_frame[16]) >> 2;
  1162. PHYDM_DBG(dm, DBG_TXBF,
  1163. "[%s] Start, sequence=%d, log_seq=%d, pre_log_seq=%d, log_retry_cnt=%d, clock_reset_times=%d, log_success=%d\n",
  1164. __func__, sequence, beamformer_entry->log_seq,
  1165. beamformer_entry->pre_log_seq,
  1166. beamformer_entry->log_retry_cnt,
  1167. beamformer_entry->clock_reset_times,
  1168. beamformer_entry->log_success);
  1169. if (beamformer_entry->log_seq != 0 && beamformer_entry->pre_log_seq != 0) {
  1170. /*Success condition*/
  1171. if (beamformer_entry->log_seq != sequence && beamformer_entry->pre_log_seq != beamformer_entry->log_seq) {
  1172. /* @break option for clcok reset, 2015-03-30, Jeffery */
  1173. beamformer_entry->log_retry_cnt = 0;
  1174. /*@As long as 8812A receive NDPA and feedback CSI succeed once, clock reset is no longer needed.*/
  1175. /*That is, log_success is NOT needed to be reset to zero, 2015-04-13, Jeffery*/
  1176. beamformer_entry->log_success = 1;
  1177. } else { /*@Fail condition*/
  1178. if (beamformer_entry->log_retry_cnt == 5) {
  1179. beamformer_entry->clock_reset_times++;
  1180. beamformer_entry->log_retry_cnt = 0;
  1181. PHYDM_DBG(dm, DBG_TXBF,
  1182. "[%s] Clock Reset!!! clock_reset_times=%d\n",
  1183. __func__,
  1184. beamformer_entry->clock_reset_times);
  1185. hal_com_txbf_set(dm, TXBF_SET_SOUNDING_CLK, NULL);
  1186. } else
  1187. beamformer_entry->log_retry_cnt++;
  1188. }
  1189. }
  1190. /*Update log_seq & pre_log_seq*/
  1191. beamformer_entry->pre_log_seq = beamformer_entry->log_seq;
  1192. beamformer_entry->log_seq = sequence;
  1193. }
  1194. #endif