rtl8812a_rxdesc.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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 _RTL8812A_RXDESC_C_
  21. //#include <drv_types.h>
  22. #include <rtl8812a_hal.h>
  23. static s32 translate2dbm(u8 signal_strength_idx)
  24. {
  25. s32 signal_power; // in dBm.
  26. // Translate to dBm (x=0.5y-95).
  27. signal_power = (s32)((signal_strength_idx + 1) >> 1);
  28. signal_power -= 95;
  29. return signal_power;
  30. }
  31. static void process_rssi(_adapter *padapter,union recv_frame *prframe)
  32. {
  33. u32 last_rssi, tmp_val;
  34. struct rx_pkt_attrib *pattrib = &prframe->u.hdr.attrib;
  35. #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
  36. struct signal_stat * signal_stat = &padapter->recvpriv.signal_strength_data;
  37. #endif //CONFIG_NEW_SIGNAL_STAT_PROCESS
  38. //DBG_8192C("process_rssi=> pattrib->rssil(%d) signal_strength(%d)\n ",pattrib->RecvSignalPower,pattrib->signal_strength);
  39. //if(pRfd->Status.bPacketToSelf || pRfd->Status.bPacketBeacon)
  40. {
  41. #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
  42. if(signal_stat->update_req) {
  43. signal_stat->total_num = 0;
  44. signal_stat->total_val = 0;
  45. signal_stat->update_req = 0;
  46. }
  47. signal_stat->total_num++;
  48. signal_stat->total_val += pattrib->phy_info.SignalStrength;
  49. signal_stat->avg_val = signal_stat->total_val / signal_stat->total_num;
  50. #else //CONFIG_NEW_SIGNAL_STAT_PROCESS
  51. //Adapter->RxStats.RssiCalculateCnt++; //For antenna Test
  52. if(padapter->recvpriv.signal_strength_data.total_num++ >= PHY_RSSI_SLID_WIN_MAX)
  53. {
  54. padapter->recvpriv.signal_strength_data.total_num = PHY_RSSI_SLID_WIN_MAX;
  55. last_rssi = padapter->recvpriv.signal_strength_data.elements[padapter->recvpriv.signal_strength_data.index];
  56. padapter->recvpriv.signal_strength_data.total_val -= last_rssi;
  57. }
  58. padapter->recvpriv.signal_strength_data.total_val +=pattrib->phy_info.SignalStrength;
  59. padapter->recvpriv.signal_strength_data.elements[padapter->recvpriv.signal_strength_data.index++] = pattrib->phy_info.SignalStrength;
  60. if(padapter->recvpriv.signal_strength_data.index >= PHY_RSSI_SLID_WIN_MAX)
  61. padapter->recvpriv.signal_strength_data.index = 0;
  62. tmp_val = padapter->recvpriv.signal_strength_data.total_val/padapter->recvpriv.signal_strength_data.total_num;
  63. if(padapter->recvpriv.is_signal_dbg) {
  64. padapter->recvpriv.signal_strength= padapter->recvpriv.signal_strength_dbg;
  65. padapter->recvpriv.rssi=(s8)translate2dbm((u8)padapter->recvpriv.signal_strength_dbg);
  66. } else {
  67. padapter->recvpriv.signal_strength= tmp_val;
  68. padapter->recvpriv.rssi=(s8)translate2dbm((u8)tmp_val);
  69. }
  70. RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("UI RSSI = %d, ui_rssi.TotalVal = %d, ui_rssi.TotalNum = %d\n", tmp_val, padapter->recvpriv.signal_strength_data.total_val,padapter->recvpriv.signal_strength_data.total_num));
  71. #endif //CONFIG_NEW_SIGNAL_STAT_PROCESS
  72. }
  73. }// Process_UI_RSSI_8192C
  74. static void process_link_qual(_adapter *padapter,union recv_frame *prframe)
  75. {
  76. u32 last_evm=0, tmpVal;
  77. struct rx_pkt_attrib *pattrib;
  78. #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
  79. struct signal_stat * signal_stat;
  80. #endif //CONFIG_NEW_SIGNAL_STAT_PROCESS
  81. if(prframe == NULL || padapter==NULL){
  82. return;
  83. }
  84. pattrib = &prframe->u.hdr.attrib;
  85. #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
  86. signal_stat = &padapter->recvpriv.signal_qual_data;
  87. #endif //CONFIG_NEW_SIGNAL_STAT_PROCESS
  88. //DBG_8192C("process_link_qual=> pattrib->signal_qual(%d)\n ",pattrib->signal_qual);
  89. #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
  90. if(signal_stat->update_req) {
  91. signal_stat->total_num = 0;
  92. signal_stat->total_val = 0;
  93. signal_stat->update_req = 0;
  94. }
  95. signal_stat->total_num++;
  96. signal_stat->total_val += pattrib->phy_info.SignalQuality;
  97. signal_stat->avg_val = signal_stat->total_val / signal_stat->total_num;
  98. #else //CONFIG_NEW_SIGNAL_STAT_PROCESS
  99. if(pattrib->phy_info.SignalQuality != 0)
  100. {
  101. //
  102. // 1. Record the general EVM to the sliding window.
  103. //
  104. if(padapter->recvpriv.signal_qual_data.total_num++ >= PHY_LINKQUALITY_SLID_WIN_MAX)
  105. {
  106. padapter->recvpriv.signal_qual_data.total_num = PHY_LINKQUALITY_SLID_WIN_MAX;
  107. last_evm = padapter->recvpriv.signal_qual_data.elements[padapter->recvpriv.signal_qual_data.index];
  108. padapter->recvpriv.signal_qual_data.total_val -= last_evm;
  109. }
  110. padapter->recvpriv.signal_qual_data.total_val += pattrib->phy_info.SignalQuality;
  111. padapter->recvpriv.signal_qual_data.elements[padapter->recvpriv.signal_qual_data.index++] = pattrib->phy_info.SignalQuality;
  112. if(padapter->recvpriv.signal_qual_data.index >= PHY_LINKQUALITY_SLID_WIN_MAX)
  113. padapter->recvpriv.signal_qual_data.index = 0;
  114. RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("Total SQ=%d pattrib->signal_qual= %d\n", padapter->recvpriv.signal_qual_data.total_val, pattrib->phy_info.SignalQuality));
  115. // <1> Showed on UI for user, in percentage.
  116. tmpVal = padapter->recvpriv.signal_qual_data.total_val/padapter->recvpriv.signal_qual_data.total_num;
  117. padapter->recvpriv.signal_qual=(u8)tmpVal;
  118. }
  119. else
  120. {
  121. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,(" pattrib->signal_qual =%d\n", pattrib->phy_info.SignalQuality));
  122. }
  123. #endif //CONFIG_NEW_SIGNAL_STAT_PROCESS
  124. }
  125. static void process_phy_info(_adapter *padapter, void *prframe)
  126. {
  127. union recv_frame *precvframe = (union recv_frame *)prframe;
  128. //
  129. // Check RSSI
  130. //
  131. process_rssi(padapter, precvframe);
  132. //
  133. // Check PWDB.
  134. //
  135. //process_PWDB(padapter, precvframe);
  136. //UpdateRxSignalStatistics8192C(Adapter, pRfd);
  137. //
  138. // Check EVM
  139. //
  140. process_link_qual(padapter, precvframe);
  141. }
  142. void rtl8812_query_rx_desc_status(union recv_frame *precvframe, u8 *pdesc)
  143. {
  144. struct rx_pkt_attrib *pattrib = &precvframe->u.hdr.attrib;
  145. _rtw_memset(pattrib, 0, sizeof(struct rx_pkt_attrib));
  146. //Offset 0
  147. pattrib->pkt_len = (u16)GET_RX_STATUS_DESC_PKT_LEN_8812(pdesc);//(le32_to_cpu(pdesc->rxdw0)&0x00003fff)
  148. pattrib->crc_err = (u8)GET_RX_STATUS_DESC_CRC32_8812(pdesc);//((le32_to_cpu(pdesc->rxdw0) >> 14) & 0x1);
  149. pattrib->icv_err = (u8)GET_RX_STATUS_DESC_ICV_8812(pdesc);//((le32_to_cpu(pdesc->rxdw0) >> 15) & 0x1);
  150. pattrib->drvinfo_sz = (u8)GET_RX_STATUS_DESC_DRVINFO_SIZE_8812(pdesc) * 8;//((le32_to_cpu(pdesc->rxdw0) >> 16) & 0xf) * 8;//uint 2^3 = 8 bytes
  151. pattrib->encrypt = (u8)GET_RX_STATUS_DESC_SECURITY_8812(pdesc);//((le32_to_cpu(pdesc->rxdw0) >> 20) & 0x7);
  152. pattrib->qos = (u8)GET_RX_STATUS_DESC_QOS_8812(pdesc);//(( le32_to_cpu( pdesc->rxdw0 ) >> 23) & 0x1);// Qos data, wireless lan header length is 26
  153. pattrib->shift_sz = (u8)GET_RX_STATUS_DESC_SHIFT_8812(pdesc);//((le32_to_cpu(pdesc->rxdw0) >> 24) & 0x3);
  154. pattrib->physt = (u8)GET_RX_STATUS_DESC_PHY_STATUS_8812(pdesc);//((le32_to_cpu(pdesc->rxdw0) >> 26) & 0x1);
  155. pattrib->bdecrypted = !GET_RX_STATUS_DESC_SWDEC_8812(pdesc);//(le32_to_cpu(pdesc->rxdw0) & BIT(27))? 0:1;
  156. //Offset 4
  157. pattrib->priority = (u8)GET_RX_STATUS_DESC_TID_8812(pdesc);//((le32_to_cpu(pdesc->rxdw1) >> 8) & 0xf);
  158. pattrib->mdata = (u8)GET_RX_STATUS_DESC_MORE_DATA_8812(pdesc);//((le32_to_cpu(pdesc->rxdw1) >> 26) & 0x1);
  159. pattrib->mfrag = (u8)GET_RX_STATUS_DESC_MORE_FRAG_8812(pdesc);//((le32_to_cpu(pdesc->rxdw1) >> 27) & 0x1);//more fragment bit
  160. //Offset 8
  161. pattrib->seq_num = (u16)GET_RX_STATUS_DESC_SEQ_8812(pdesc);//(le32_to_cpu(pdesc->rxdw2) & 0x00000fff);
  162. pattrib->frag_num = (u8)GET_RX_STATUS_DESC_FRAG_8812(pdesc);//((le32_to_cpu(pdesc->rxdw2) >> 12) & 0xf);//fragmentation number
  163. if (GET_RX_STATUS_DESC_RPT_SEL_8812(pdesc))
  164. pattrib->pkt_rpt_type = C2H_PACKET;
  165. else
  166. pattrib->pkt_rpt_type = NORMAL_RX;
  167. //Offset 12
  168. pattrib->data_rate=(u8)GET_RX_STATUS_DESC_RX_RATE_8812(pdesc);//((le32_to_cpu(pdesc->rxdw3))&0x7f);
  169. //Offset 16
  170. //Offset 20
  171. }
  172. /*
  173. * Notice:
  174. * Before calling this function,
  175. * precvframe->u.hdr.rx_data should be ready!
  176. */
  177. void rtl8812_query_rx_phy_status(
  178. union recv_frame *precvframe,
  179. u8 *pphy_status)
  180. {
  181. PADAPTER padapter = precvframe->u.hdr.adapter;
  182. struct rx_pkt_attrib *pattrib = &precvframe->u.hdr.attrib;
  183. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  184. PODM_PHY_INFO_T pPHYInfo = (PODM_PHY_INFO_T)(&pattrib->phy_info);
  185. u8 *wlanhdr;
  186. ODM_PACKET_INFO_T pkt_info;
  187. u8 *sa;
  188. struct sta_priv *pstapriv;
  189. struct sta_info *psta;
  190. //_irqL irqL;
  191. pkt_info.bPacketMatchBSSID =_FALSE;
  192. pkt_info.bPacketToSelf = _FALSE;
  193. pkt_info.bPacketBeacon = _FALSE;
  194. wlanhdr = get_recvframe_data(precvframe);
  195. pkt_info.bPacketMatchBSSID = ((!IsFrameTypeCtrl(wlanhdr)) &&
  196. !pattrib->icv_err && !pattrib->crc_err &&
  197. _rtw_memcmp(get_hdr_bssid(wlanhdr), get_bssid(&padapter->mlmepriv), ETH_ALEN));
  198. pkt_info.bPacketToSelf = pkt_info.bPacketMatchBSSID && (_rtw_memcmp(get_da(wlanhdr), myid(&padapter->eeprompriv), ETH_ALEN));
  199. pkt_info.bPacketBeacon = pkt_info.bPacketMatchBSSID && (GetFrameSubType(wlanhdr) == WIFI_BEACON);
  200. if(pkt_info.bPacketBeacon){
  201. if(check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE) == _TRUE){
  202. sa = padapter->mlmepriv.cur_network.network.MacAddress;
  203. #if 0
  204. {
  205. DBG_8192C("==> rx beacon from AP[%02x:%02x:%02x:%02x:%02x:%02x]\n",
  206. sa[0],sa[1],sa[2],sa[3],sa[4],sa[5]);
  207. }
  208. #endif
  209. }
  210. //to do Ad-hoc
  211. }
  212. else{
  213. sa = get_sa(wlanhdr);
  214. }
  215. pstapriv = &padapter->stapriv;
  216. pkt_info.StationID = 0xFF;
  217. psta = rtw_get_stainfo(pstapriv, sa);
  218. if (psta)
  219. {
  220. pkt_info.StationID = psta->mac_id;
  221. //DBG_8192C("%s ==> StationID(%d)\n",__FUNCTION__,pkt_info.StationID);
  222. }
  223. pkt_info.DataRate = pattrib->data_rate;
  224. //rtl8188e_query_rx_phy_status(precvframe, pphy_status);
  225. //_enter_critical_bh(&pHalData->odm_stainfo_lock, &irqL);
  226. ODM_PhyStatusQuery(&pHalData->odmpriv,pPHYInfo,pphy_status,&(pkt_info));
  227. //_exit_critical_bh(&pHalData->odm_stainfo_lock, &irqL);
  228. precvframe->u.hdr.psta = NULL;
  229. if (pkt_info.bPacketMatchBSSID &&
  230. (check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE) == _TRUE))
  231. {
  232. if (psta)
  233. {
  234. precvframe->u.hdr.psta = psta;
  235. process_phy_info(padapter, precvframe);
  236. }
  237. }
  238. else if (pkt_info.bPacketToSelf || pkt_info.bPacketBeacon)
  239. {
  240. if (check_fwstate(&padapter->mlmepriv, WIFI_ADHOC_STATE|WIFI_ADHOC_MASTER_STATE) == _TRUE)
  241. {
  242. if (psta)
  243. {
  244. precvframe->u.hdr.psta = psta;
  245. }
  246. }
  247. process_phy_info(padapter, precvframe);
  248. }
  249. }