rtw_sreset.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2012 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. #include <drv_types.h>
  21. #include <hal_data.h>
  22. #include <rtw_sreset.h>
  23. void sreset_init_value(_adapter *padapter)
  24. {
  25. #if defined(DBG_CONFIG_ERROR_DETECT)
  26. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  27. struct sreset_priv *psrtpriv = &pHalData->srestpriv;
  28. _rtw_mutex_init(&psrtpriv->silentreset_mutex);
  29. psrtpriv->silent_reset_inprogress = _FALSE;
  30. psrtpriv->Wifi_Error_Status = WIFI_STATUS_SUCCESS;
  31. psrtpriv->last_tx_time =0;
  32. psrtpriv->last_tx_complete_time =0;
  33. #endif
  34. }
  35. void sreset_reset_value(_adapter *padapter)
  36. {
  37. #if defined(DBG_CONFIG_ERROR_DETECT)
  38. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  39. struct sreset_priv *psrtpriv = &pHalData->srestpriv;
  40. psrtpriv->silent_reset_inprogress = _FALSE;
  41. psrtpriv->Wifi_Error_Status = WIFI_STATUS_SUCCESS;
  42. psrtpriv->last_tx_time =0;
  43. psrtpriv->last_tx_complete_time =0;
  44. #endif
  45. }
  46. u8 sreset_get_wifi_status(_adapter *padapter)
  47. {
  48. #if defined(DBG_CONFIG_ERROR_DETECT)
  49. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  50. struct sreset_priv *psrtpriv = &pHalData->srestpriv;
  51. u8 status = WIFI_STATUS_SUCCESS;
  52. u32 val32 = 0;
  53. _irqL irqL;
  54. if(psrtpriv->silent_reset_inprogress == _TRUE)
  55. {
  56. return status;
  57. }
  58. val32 =rtw_read32(padapter,REG_TXDMA_STATUS);
  59. if(val32==0xeaeaeaea){
  60. psrtpriv->Wifi_Error_Status = WIFI_IF_NOT_EXIST;
  61. }
  62. else if(val32!=0){
  63. DBG_8192C("txdmastatu(%x)\n",val32);
  64. psrtpriv->Wifi_Error_Status = WIFI_MAC_TXDMA_ERROR;
  65. }
  66. if(WIFI_STATUS_SUCCESS !=psrtpriv->Wifi_Error_Status)
  67. {
  68. DBG_8192C("==>%s error_status(0x%x) \n",__FUNCTION__,psrtpriv->Wifi_Error_Status);
  69. status = (psrtpriv->Wifi_Error_Status &( ~(USB_READ_PORT_FAIL|USB_WRITE_PORT_FAIL)));
  70. }
  71. DBG_8192C("==> %s wifi_status(0x%x)\n",__FUNCTION__,status);
  72. //status restore
  73. psrtpriv->Wifi_Error_Status = WIFI_STATUS_SUCCESS;
  74. return status;
  75. #else
  76. return WIFI_STATUS_SUCCESS;
  77. #endif
  78. }
  79. void sreset_set_wifi_error_status(_adapter *padapter, u32 status)
  80. {
  81. #if defined(DBG_CONFIG_ERROR_DETECT)
  82. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  83. pHalData->srestpriv.Wifi_Error_Status = status;
  84. #endif
  85. }
  86. void sreset_set_trigger_point(_adapter *padapter, s32 tgp)
  87. {
  88. #if defined(DBG_CONFIG_ERROR_DETECT)
  89. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  90. pHalData->srestpriv.dbg_trigger_point = tgp;
  91. #endif
  92. }
  93. bool sreset_inprogress(_adapter *padapter)
  94. {
  95. #if defined(DBG_CONFIG_ERROR_RESET)
  96. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  97. return pHalData->srestpriv.silent_reset_inprogress;
  98. #else
  99. return _FALSE;
  100. #endif
  101. }
  102. void sreset_restore_security_station(_adapter *padapter)
  103. {
  104. u8 EntryId = 0;
  105. struct mlme_priv *mlmepriv = &padapter->mlmepriv;
  106. struct sta_priv * pstapriv = &padapter->stapriv;
  107. struct sta_info *psta;
  108. struct security_priv* psecuritypriv=&(padapter->securitypriv);
  109. struct mlme_ext_info *pmlmeinfo = &padapter->mlmeextpriv.mlmext_info;
  110. {
  111. u8 val8;
  112. if (pmlmeinfo->auth_algo == dot11AuthAlgrthm_8021X) {
  113. val8 = 0xcc;
  114. #ifdef CONFIG_WAPI_SUPPORT
  115. } else if (padapter->wapiInfo.bWapiEnable && pmlmeinfo->auth_algo == dot11AuthAlgrthm_WAPI) {
  116. //Disable TxUseDefaultKey, RxUseDefaultKey, RxBroadcastUseDefaultKey.
  117. val8 = 0x4c;
  118. #endif
  119. } else {
  120. val8 = 0xcf;
  121. }
  122. rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8));
  123. }
  124. #if 0
  125. if ( ( padapter->securitypriv.dot11PrivacyAlgrthm == _WEP40_ ) ||
  126. ( padapter->securitypriv.dot11PrivacyAlgrthm == _WEP104_ ))
  127. {
  128. for(EntryId=0; EntryId<4; EntryId++)
  129. {
  130. if(EntryId == psecuritypriv->dot11PrivacyKeyIndex)
  131. rtw_set_key(padapter,&padapter->securitypriv, EntryId, 1);
  132. else
  133. rtw_set_key(padapter,&padapter->securitypriv, EntryId, 0);
  134. }
  135. }
  136. else
  137. #endif
  138. if((padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_) ||
  139. (padapter->securitypriv.dot11PrivacyAlgrthm == _AES_))
  140. {
  141. psta = rtw_get_stainfo(pstapriv, get_bssid(mlmepriv));
  142. if (psta == NULL) {
  143. //DEBUG_ERR( ("Set wpa_set_encryption: Obtain Sta_info fail \n"));
  144. }
  145. else
  146. {
  147. //pairwise key
  148. rtw_setstakey_cmd(padapter, (unsigned char *)psta, _TRUE);
  149. //group key
  150. rtw_set_key(padapter,&padapter->securitypriv,padapter->securitypriv.dot118021XGrpKeyid, 0);
  151. }
  152. }
  153. }
  154. void sreset_restore_network_station(_adapter *padapter)
  155. {
  156. struct mlme_priv *mlmepriv = &padapter->mlmepriv;
  157. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  158. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  159. #if 0
  160. {
  161. //=======================================================
  162. // reset related register of Beacon control
  163. //set MSR to nolink
  164. Set_MSR(padapter, _HW_STATE_NOLINK_);
  165. // reject all data frame
  166. rtw_write16(padapter, REG_RXFLTMAP2,0x00);
  167. //reset TSF
  168. rtw_write8(padapter, REG_DUAL_TSF_RST, (BIT(0)|BIT(1)));
  169. // disable update TSF
  170. SetBcnCtrlReg(padapter, BIT(4), 0);
  171. //=======================================================
  172. }
  173. #endif
  174. rtw_setopmode_cmd(padapter, Ndis802_11Infrastructure);
  175. {
  176. u8 threshold;
  177. #ifdef CONFIG_USB_HCI
  178. // TH=1 => means that invalidate usb rx aggregation
  179. // TH=0 => means that validate usb rx aggregation, use init value.
  180. if(mlmepriv->htpriv.ht_option) {
  181. if(padapter->registrypriv.wifi_spec==1)
  182. threshold = 1;
  183. else
  184. threshold = 0;
  185. rtw_hal_set_hwreg(padapter, HW_VAR_RXDMA_AGG_PG_TH, (u8 *)(&threshold));
  186. } else {
  187. threshold = 1;
  188. rtw_hal_set_hwreg(padapter, HW_VAR_RXDMA_AGG_PG_TH, (u8 *)(&threshold));
  189. }
  190. #endif
  191. }
  192. set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
  193. //disable dynamic functions, such as high power, DIG
  194. //Switch_DM_Func(padapter, DYNAMIC_FUNC_DISABLE, _FALSE);
  195. rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, pmlmeinfo->network.MacAddress);
  196. {
  197. u8 join_type = 0;
  198. rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type));
  199. }
  200. Set_MSR(padapter, (pmlmeinfo->state & 0x3));
  201. mlmeext_joinbss_event_callback(padapter, 1);
  202. //restore Sequence No.
  203. rtw_write8(padapter,0x4dc,padapter->xmitpriv.nqos_ssn);
  204. sreset_restore_security_station(padapter);
  205. }
  206. void sreset_restore_network_status(_adapter *padapter)
  207. {
  208. struct mlme_priv *mlmepriv = &padapter->mlmepriv;
  209. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  210. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  211. if (check_fwstate(mlmepriv, WIFI_STATION_STATE)) {
  212. DBG_871X(FUNC_ADPT_FMT" fwstate:0x%08x - WIFI_STATION_STATE\n", FUNC_ADPT_ARG(padapter), get_fwstate(mlmepriv));
  213. sreset_restore_network_station(padapter);
  214. } else if (check_fwstate(mlmepriv, WIFI_AP_STATE)) {
  215. DBG_871X(FUNC_ADPT_FMT" fwstate:0x%08x - WIFI_AP_STATE\n", FUNC_ADPT_ARG(padapter), get_fwstate(mlmepriv));
  216. rtw_ap_restore_network(padapter);
  217. } else if (check_fwstate(mlmepriv, WIFI_ADHOC_STATE)) {
  218. DBG_871X(FUNC_ADPT_FMT" fwstate:0x%08x - WIFI_ADHOC_STATE\n", FUNC_ADPT_ARG(padapter), get_fwstate(mlmepriv));
  219. } else {
  220. DBG_871X(FUNC_ADPT_FMT" fwstate:0x%08x - ???\n", FUNC_ADPT_ARG(padapter), get_fwstate(mlmepriv));
  221. }
  222. }
  223. void sreset_stop_adapter(_adapter *padapter)
  224. {
  225. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  226. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  227. if (padapter == NULL)
  228. return;
  229. DBG_871X(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(padapter));
  230. if (!rtw_netif_queue_stopped(padapter->pnetdev))
  231. rtw_netif_stop_queue(padapter->pnetdev);
  232. rtw_cancel_all_timer(padapter);
  233. /* TODO: OS and HCI independent */
  234. #if defined(PLATFORM_LINUX) && defined(CONFIG_USB_HCI)
  235. tasklet_kill(&pxmitpriv->xmit_tasklet);
  236. #endif
  237. if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY))
  238. rtw_scan_abort(padapter);
  239. if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING))
  240. _rtw_join_timeout_handler(padapter);
  241. }
  242. void sreset_start_adapter(_adapter *padapter)
  243. {
  244. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  245. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  246. if (padapter == NULL)
  247. return;
  248. DBG_871X(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(padapter));
  249. if (check_fwstate(pmlmepriv, _FW_LINKED)) {
  250. sreset_restore_network_status(padapter);
  251. }
  252. /* TODO: OS and HCI independent */
  253. #if defined(PLATFORM_LINUX) && defined(CONFIG_USB_HCI)
  254. tasklet_hi_schedule(&pxmitpriv->xmit_tasklet);
  255. #endif
  256. _set_timer(&padapter->mlmepriv.dynamic_chk_timer, 2000);
  257. if (rtw_netif_queue_stopped(padapter->pnetdev))
  258. rtw_netif_wake_queue(padapter->pnetdev);
  259. }
  260. void sreset_reset(_adapter *padapter)
  261. {
  262. #ifdef DBG_CONFIG_ERROR_RESET
  263. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  264. struct sreset_priv *psrtpriv = &pHalData->srestpriv;
  265. struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
  266. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  267. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  268. _irqL irqL;
  269. u32 start = rtw_get_current_time();
  270. DBG_871X("%s\n", __FUNCTION__);
  271. psrtpriv->Wifi_Error_Status = WIFI_STATUS_SUCCESS;
  272. _enter_critical_mutex(&psrtpriv->silentreset_mutex, &irqL);
  273. psrtpriv->silent_reset_inprogress = _TRUE;
  274. pwrpriv->change_rfpwrstate = rf_off;
  275. sreset_stop_adapter(padapter);
  276. #ifdef CONFIG_CONCURRENT_MODE
  277. sreset_stop_adapter(padapter->pbuddy_adapter);
  278. #endif
  279. #ifdef CONFIG_IPS
  280. ips_enter(padapter);
  281. ips_leave(padapter);
  282. #endif
  283. sreset_start_adapter(padapter);
  284. #ifdef CONFIG_CONCURRENT_MODE
  285. sreset_start_adapter(padapter->pbuddy_adapter);
  286. #endif
  287. psrtpriv->silent_reset_inprogress = _FALSE;
  288. _exit_critical_mutex(&psrtpriv->silentreset_mutex, &irqL);
  289. DBG_871X("%s done in %d ms\n", __FUNCTION__, rtw_get_passing_time_ms(start));
  290. #endif
  291. }