rtw_cmd.c 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025
  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. #define _RTW_CMD_C_
  21. #include <drv_types.h>
  22. /*
  23. Caller and the rtw_cmd_thread can protect cmd_q by spin_lock.
  24. No irqsave is necessary.
  25. */
  26. sint _rtw_init_cmd_priv (struct cmd_priv *pcmdpriv)
  27. {
  28. sint res=_SUCCESS;
  29. _func_enter_;
  30. _rtw_init_sema(&(pcmdpriv->cmd_queue_sema), 0);
  31. //_rtw_init_sema(&(pcmdpriv->cmd_done_sema), 0);
  32. _rtw_init_sema(&(pcmdpriv->terminate_cmdthread_sema), 0);
  33. _rtw_init_queue(&(pcmdpriv->cmd_queue));
  34. //allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf
  35. pcmdpriv->cmd_seq = 1;
  36. pcmdpriv->cmd_allocated_buf = rtw_zmalloc(MAX_CMDSZ + CMDBUFF_ALIGN_SZ);
  37. if (pcmdpriv->cmd_allocated_buf == NULL){
  38. res= _FAIL;
  39. goto exit;
  40. }
  41. pcmdpriv->cmd_buf = pcmdpriv->cmd_allocated_buf + CMDBUFF_ALIGN_SZ - ( (SIZE_PTR)(pcmdpriv->cmd_allocated_buf) & (CMDBUFF_ALIGN_SZ-1));
  42. pcmdpriv->rsp_allocated_buf = rtw_zmalloc(MAX_RSPSZ + 4);
  43. if (pcmdpriv->rsp_allocated_buf == NULL){
  44. res= _FAIL;
  45. goto exit;
  46. }
  47. pcmdpriv->rsp_buf = pcmdpriv->rsp_allocated_buf + 4 - ( (SIZE_PTR)(pcmdpriv->rsp_allocated_buf) & 3);
  48. pcmdpriv->cmd_issued_cnt = pcmdpriv->cmd_done_cnt = pcmdpriv->rsp_cnt = 0;
  49. exit:
  50. _func_exit_;
  51. return res;
  52. }
  53. #ifdef CONFIG_C2H_WK
  54. static void c2h_wk_callback(_workitem *work);
  55. #endif
  56. sint _rtw_init_evt_priv(struct evt_priv *pevtpriv)
  57. {
  58. sint res=_SUCCESS;
  59. _func_enter_;
  60. #ifdef CONFIG_H2CLBK
  61. _rtw_init_sema(&(pevtpriv->lbkevt_done), 0);
  62. pevtpriv->lbkevt_limit = 0;
  63. pevtpriv->lbkevt_num = 0;
  64. pevtpriv->cmdevt_parm = NULL;
  65. #endif
  66. //allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf
  67. ATOMIC_SET(&pevtpriv->event_seq, 0);
  68. pevtpriv->evt_done_cnt = 0;
  69. #ifdef CONFIG_EVENT_THREAD_MODE
  70. _rtw_init_sema(&(pevtpriv->evt_notify), 0);
  71. _rtw_init_sema(&(pevtpriv->terminate_evtthread_sema), 0);
  72. pevtpriv->evt_allocated_buf = rtw_zmalloc(MAX_EVTSZ + 4);
  73. if (pevtpriv->evt_allocated_buf == NULL){
  74. res= _FAIL;
  75. goto exit;
  76. }
  77. pevtpriv->evt_buf = pevtpriv->evt_allocated_buf + 4 - ((unsigned int)(pevtpriv->evt_allocated_buf) & 3);
  78. #if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
  79. pevtpriv->allocated_c2h_mem = rtw_zmalloc(C2H_MEM_SZ +4);
  80. if (pevtpriv->allocated_c2h_mem == NULL){
  81. res= _FAIL;
  82. goto exit;
  83. }
  84. pevtpriv->c2h_mem = pevtpriv->allocated_c2h_mem + 4\
  85. - ( (u32)(pevtpriv->allocated_c2h_mem) & 3);
  86. #ifdef PLATFORM_OS_XP
  87. pevtpriv->pc2h_mdl= IoAllocateMdl((u8 *)pevtpriv->c2h_mem, C2H_MEM_SZ , FALSE, FALSE, NULL);
  88. if(pevtpriv->pc2h_mdl == NULL){
  89. res= _FAIL;
  90. goto exit;
  91. }
  92. MmBuildMdlForNonPagedPool(pevtpriv->pc2h_mdl);
  93. #endif
  94. #endif //end of CONFIG_SDIO_HCI
  95. _rtw_init_queue(&(pevtpriv->evt_queue));
  96. exit:
  97. #endif //end of CONFIG_EVENT_THREAD_MODE
  98. #ifdef CONFIG_C2H_WK
  99. _init_workitem(&pevtpriv->c2h_wk, c2h_wk_callback, NULL);
  100. pevtpriv->c2h_wk_alive = _FALSE;
  101. pevtpriv->c2h_queue = rtw_cbuf_alloc(C2H_QUEUE_MAX_LEN+1);
  102. #endif
  103. _func_exit_;
  104. return res;
  105. }
  106. void _rtw_free_evt_priv (struct evt_priv *pevtpriv)
  107. {
  108. _func_enter_;
  109. RT_TRACE(_module_rtl871x_cmd_c_,_drv_info_,("+_rtw_free_evt_priv \n"));
  110. #ifdef CONFIG_EVENT_THREAD_MODE
  111. _rtw_free_sema(&(pevtpriv->evt_notify));
  112. _rtw_free_sema(&(pevtpriv->terminate_evtthread_sema));
  113. if (pevtpriv->evt_allocated_buf)
  114. rtw_mfree(pevtpriv->evt_allocated_buf, MAX_EVTSZ + 4);
  115. #endif
  116. #ifdef CONFIG_C2H_WK
  117. _cancel_workitem_sync(&pevtpriv->c2h_wk);
  118. while(pevtpriv->c2h_wk_alive)
  119. rtw_msleep_os(10);
  120. while (!rtw_cbuf_empty(pevtpriv->c2h_queue)) {
  121. void *c2h;
  122. if ((c2h = rtw_cbuf_pop(pevtpriv->c2h_queue)) != NULL
  123. && c2h != (void *)pevtpriv) {
  124. rtw_mfree(c2h, 16);
  125. }
  126. }
  127. #endif
  128. RT_TRACE(_module_rtl871x_cmd_c_,_drv_info_,("-_rtw_free_evt_priv \n"));
  129. _func_exit_;
  130. }
  131. void _rtw_free_cmd_priv (struct cmd_priv *pcmdpriv)
  132. {
  133. _func_enter_;
  134. if(pcmdpriv){
  135. _rtw_spinlock_free(&(pcmdpriv->cmd_queue.lock));
  136. _rtw_free_sema(&(pcmdpriv->cmd_queue_sema));
  137. //_rtw_free_sema(&(pcmdpriv->cmd_done_sema));
  138. _rtw_free_sema(&(pcmdpriv->terminate_cmdthread_sema));
  139. if (pcmdpriv->cmd_allocated_buf)
  140. rtw_mfree(pcmdpriv->cmd_allocated_buf, MAX_CMDSZ + CMDBUFF_ALIGN_SZ);
  141. if (pcmdpriv->rsp_allocated_buf)
  142. rtw_mfree(pcmdpriv->rsp_allocated_buf, MAX_RSPSZ + 4);
  143. }
  144. _func_exit_;
  145. }
  146. /*
  147. Calling Context:
  148. rtw_enqueue_cmd can only be called between kernel thread,
  149. since only spin_lock is used.
  150. ISR/Call-Back functions can't call this sub-function.
  151. */
  152. sint _rtw_enqueue_cmd(_queue *queue, struct cmd_obj *obj)
  153. {
  154. _irqL irqL;
  155. _func_enter_;
  156. if (obj == NULL)
  157. goto exit;
  158. //_enter_critical_bh(&queue->lock, &irqL);
  159. _enter_critical(&queue->lock, &irqL);
  160. rtw_list_insert_tail(&obj->list, &queue->queue);
  161. //_exit_critical_bh(&queue->lock, &irqL);
  162. _exit_critical(&queue->lock, &irqL);
  163. exit:
  164. _func_exit_;
  165. return _SUCCESS;
  166. }
  167. struct cmd_obj *_rtw_dequeue_cmd(_queue *queue)
  168. {
  169. _irqL irqL;
  170. struct cmd_obj *obj;
  171. _func_enter_;
  172. //_enter_critical_bh(&(queue->lock), &irqL);
  173. _enter_critical(&queue->lock, &irqL);
  174. if (rtw_is_list_empty(&(queue->queue)))
  175. obj = NULL;
  176. else
  177. {
  178. obj = LIST_CONTAINOR(get_next(&(queue->queue)), struct cmd_obj, list);
  179. rtw_list_delete(&obj->list);
  180. }
  181. //_exit_critical_bh(&(queue->lock), &irqL);
  182. _exit_critical(&queue->lock, &irqL);
  183. _func_exit_;
  184. return obj;
  185. }
  186. u32 rtw_init_cmd_priv(struct cmd_priv *pcmdpriv)
  187. {
  188. u32 res;
  189. _func_enter_;
  190. res = _rtw_init_cmd_priv (pcmdpriv);
  191. _func_exit_;
  192. return res;
  193. }
  194. u32 rtw_init_evt_priv (struct evt_priv *pevtpriv)
  195. {
  196. int res;
  197. _func_enter_;
  198. res = _rtw_init_evt_priv(pevtpriv);
  199. _func_exit_;
  200. return res;
  201. }
  202. void rtw_free_evt_priv (struct evt_priv *pevtpriv)
  203. {
  204. _func_enter_;
  205. RT_TRACE(_module_rtl871x_cmd_c_,_drv_info_,("rtw_free_evt_priv\n"));
  206. _rtw_free_evt_priv(pevtpriv);
  207. _func_exit_;
  208. }
  209. void rtw_free_cmd_priv (struct cmd_priv *pcmdpriv)
  210. {
  211. _func_enter_;
  212. RT_TRACE(_module_rtl871x_cmd_c_,_drv_info_,("rtw_free_cmd_priv\n"));
  213. _rtw_free_cmd_priv(pcmdpriv);
  214. _func_exit_;
  215. }
  216. int rtw_cmd_filter(struct cmd_priv *pcmdpriv, struct cmd_obj *cmd_obj);
  217. int rtw_cmd_filter(struct cmd_priv *pcmdpriv, struct cmd_obj *cmd_obj)
  218. {
  219. u8 bAllow = _FALSE; //set to _TRUE to allow enqueuing cmd when hw_init_completed is _FALSE
  220. #ifdef SUPPORT_HW_RFOFF_DETECTED
  221. //To decide allow or not
  222. if( (pcmdpriv->padapter->pwrctrlpriv.bHWPwrPindetect)
  223. &&(!pcmdpriv->padapter->registrypriv.usbss_enable)
  224. )
  225. {
  226. if(cmd_obj->cmdcode == GEN_CMD_CODE(_Set_Drv_Extra) )
  227. {
  228. struct drvextra_cmd_parm *pdrvextra_cmd_parm = (struct drvextra_cmd_parm *)cmd_obj->parmbuf;
  229. if(pdrvextra_cmd_parm->ec_id == POWER_SAVING_CTRL_WK_CID)
  230. {
  231. //DBG_871X("==>enqueue POWER_SAVING_CTRL_WK_CID\n");
  232. bAllow = _TRUE;
  233. }
  234. }
  235. }
  236. #endif
  237. if(cmd_obj->cmdcode == GEN_CMD_CODE(_SetChannelPlan))
  238. bAllow = _TRUE;
  239. if( (pcmdpriv->padapter->hw_init_completed ==_FALSE && bAllow == _FALSE)
  240. || pcmdpriv->cmdthd_running== _FALSE //com_thread not running
  241. )
  242. {
  243. //DBG_871X("%s:%s: drop cmdcode:%u, hw_init_completed:%u, cmdthd_running:%u\n", caller_func, __FUNCTION__,
  244. // cmd_obj->cmdcode,
  245. // pcmdpriv->padapter->hw_init_completed,
  246. // pcmdpriv->cmdthd_running
  247. //);
  248. return _FAIL;
  249. }
  250. return _SUCCESS;
  251. }
  252. u32 rtw_enqueue_cmd(struct cmd_priv *pcmdpriv, struct cmd_obj *cmd_obj)
  253. {
  254. int res = _FAIL;
  255. PADAPTER padapter = pcmdpriv->padapter;
  256. _func_enter_;
  257. if (cmd_obj == NULL) {
  258. goto exit;
  259. }
  260. cmd_obj->padapter = padapter;
  261. #ifdef CONFIG_CONCURRENT_MODE
  262. //change pcmdpriv to primary's pcmdpriv
  263. if (padapter->adapter_type != PRIMARY_ADAPTER && padapter->pbuddy_adapter)
  264. pcmdpriv = &(padapter->pbuddy_adapter->cmdpriv);
  265. #endif
  266. if( _FAIL == (res=rtw_cmd_filter(pcmdpriv, cmd_obj)) ) {
  267. rtw_free_cmd_obj(cmd_obj);
  268. goto exit;
  269. }
  270. res = _rtw_enqueue_cmd(&pcmdpriv->cmd_queue, cmd_obj);
  271. if(res == _SUCCESS)
  272. _rtw_up_sema(&pcmdpriv->cmd_queue_sema);
  273. exit:
  274. _func_exit_;
  275. return res;
  276. }
  277. struct cmd_obj *rtw_dequeue_cmd(struct cmd_priv *pcmdpriv)
  278. {
  279. struct cmd_obj *cmd_obj;
  280. _func_enter_;
  281. cmd_obj = _rtw_dequeue_cmd(&pcmdpriv->cmd_queue);
  282. _func_exit_;
  283. return cmd_obj;
  284. }
  285. void rtw_cmd_clr_isr(struct cmd_priv *pcmdpriv)
  286. {
  287. _func_enter_;
  288. pcmdpriv->cmd_done_cnt++;
  289. //_rtw_up_sema(&(pcmdpriv->cmd_done_sema));
  290. _func_exit_;
  291. }
  292. void rtw_free_cmd_obj(struct cmd_obj *pcmd)
  293. {
  294. _func_enter_;
  295. if((pcmd->cmdcode!=_JoinBss_CMD_) &&(pcmd->cmdcode!= _CreateBss_CMD_))
  296. {
  297. //free parmbuf in cmd_obj
  298. rtw_mfree((unsigned char*)pcmd->parmbuf, pcmd->cmdsz);
  299. }
  300. if(pcmd->rsp!=NULL)
  301. {
  302. if(pcmd->rspsz!= 0)
  303. {
  304. //free rsp in cmd_obj
  305. rtw_mfree((unsigned char*)pcmd->rsp, pcmd->rspsz);
  306. }
  307. }
  308. //free cmd_obj
  309. rtw_mfree((unsigned char*)pcmd, sizeof(struct cmd_obj));
  310. _func_exit_;
  311. }
  312. thread_return rtw_cmd_thread(thread_context context)
  313. {
  314. u8 ret;
  315. struct cmd_obj *pcmd;
  316. u8 *pcmdbuf, *prspbuf;
  317. u8 (*cmd_hdl)(_adapter *padapter, u8* pbuf);
  318. void (*pcmd_callback)(_adapter *dev, struct cmd_obj *pcmd);
  319. PADAPTER padapter = (PADAPTER)context;
  320. struct cmd_priv *pcmdpriv = &(padapter->cmdpriv);
  321. _func_enter_;
  322. thread_enter("RTW_CMD_THREAD");
  323. pcmdbuf = pcmdpriv->cmd_buf;
  324. prspbuf = pcmdpriv->rsp_buf;
  325. pcmdpriv->cmdthd_running=_TRUE;
  326. _rtw_up_sema(&pcmdpriv->terminate_cmdthread_sema);
  327. RT_TRACE(_module_rtl871x_cmd_c_,_drv_info_,("start r871x rtw_cmd_thread !!!!\n"));
  328. while(1)
  329. {
  330. if (_rtw_down_sema(&pcmdpriv->cmd_queue_sema) == _FAIL)
  331. break;
  332. if ((padapter->bDriverStopped == _TRUE)||(padapter->bSurpriseRemoved == _TRUE))
  333. {
  334. DBG_871X("%s: DriverStopped(%d) SurpriseRemoved(%d) break at line %d\n",
  335. __FUNCTION__, padapter->bDriverStopped, padapter->bSurpriseRemoved, __LINE__);
  336. break;
  337. }
  338. #ifdef CONFIG_LPS_LCLK
  339. if (rtw_register_cmd_alive(padapter) != _SUCCESS)
  340. {
  341. RT_TRACE(_module_hal_xmit_c_, _drv_notice_,
  342. ("%s: wait to leave LPS_LCLK\n", __FUNCTION__));
  343. continue;
  344. }
  345. #endif
  346. _next:
  347. if ((padapter->bDriverStopped == _TRUE)||(padapter->bSurpriseRemoved== _TRUE))
  348. {
  349. DBG_871X("%s: DriverStopped(%d) SurpriseRemoved(%d) break at line %d\n",
  350. __FUNCTION__, padapter->bDriverStopped, padapter->bSurpriseRemoved, __LINE__);
  351. break;
  352. }
  353. if(!(pcmd = rtw_dequeue_cmd(pcmdpriv))) {
  354. #ifdef CONFIG_LPS_LCLK
  355. rtw_unregister_cmd_alive(padapter);
  356. #endif
  357. continue;
  358. }
  359. if( _FAIL == rtw_cmd_filter(pcmdpriv, pcmd) )
  360. {
  361. pcmd->res = H2C_DROPPED;
  362. goto post_process;
  363. }
  364. pcmdpriv->cmd_issued_cnt++;
  365. pcmd->cmdsz = _RND4((pcmd->cmdsz));//_RND4
  366. _rtw_memcpy(pcmdbuf, pcmd->parmbuf, pcmd->cmdsz);
  367. if(pcmd->cmdcode <= (sizeof(wlancmds) /sizeof(struct cmd_hdl)))
  368. {
  369. cmd_hdl = wlancmds[pcmd->cmdcode].h2cfuns;
  370. if (cmd_hdl)
  371. {
  372. ret = cmd_hdl(pcmd->padapter, pcmdbuf);
  373. pcmd->res = ret;
  374. }
  375. pcmdpriv->cmd_seq++;
  376. }
  377. else
  378. {
  379. pcmd->res = H2C_PARAMETERS_ERROR;
  380. }
  381. cmd_hdl = NULL;
  382. post_process:
  383. //call callback function for post-processed
  384. if(pcmd->cmdcode <= (sizeof(rtw_cmd_callback) /sizeof(struct _cmd_callback)))
  385. {
  386. pcmd_callback = rtw_cmd_callback[pcmd->cmdcode].callback;
  387. if(pcmd_callback == NULL)
  388. {
  389. RT_TRACE(_module_rtl871x_cmd_c_,_drv_info_,("mlme_cmd_hdl(): pcmd_callback=0x%p, cmdcode=0x%x\n", pcmd_callback, pcmd->cmdcode));
  390. rtw_free_cmd_obj(pcmd);
  391. }
  392. else
  393. {
  394. //todo: !!! fill rsp_buf to pcmd->rsp if (pcmd->rsp!=NULL)
  395. pcmd_callback(pcmd->padapter, pcmd);//need conider that free cmd_obj in rtw_cmd_callback
  396. }
  397. }
  398. else
  399. {
  400. RT_TRACE(_module_rtl871x_cmd_c_,_drv_err_,("%s: cmdcode=0x%x callback not defined!\n", __FUNCTION__, pcmd->cmdcode));
  401. rtw_free_cmd_obj(pcmd);
  402. }
  403. flush_signals_thread();
  404. goto _next;
  405. }
  406. pcmdpriv->cmdthd_running=_FALSE;
  407. // free all cmd_obj resources
  408. do{
  409. pcmd = rtw_dequeue_cmd(pcmdpriv);
  410. if(pcmd==NULL){
  411. #ifdef CONFIG_LPS_LCLK
  412. rtw_unregister_cmd_alive(padapter);
  413. #endif
  414. break;
  415. }
  416. //DBG_871X("%s: leaving... drop cmdcode:%u\n", __FUNCTION__, pcmd->cmdcode);
  417. rtw_free_cmd_obj(pcmd);
  418. }while(1);
  419. _rtw_up_sema(&pcmdpriv->terminate_cmdthread_sema);
  420. _func_exit_;
  421. thread_exit();
  422. }
  423. #ifdef CONFIG_EVENT_THREAD_MODE
  424. u32 rtw_enqueue_evt(struct evt_priv *pevtpriv, struct evt_obj *obj)
  425. {
  426. _irqL irqL;
  427. int res;
  428. _queue *queue = &pevtpriv->evt_queue;
  429. _func_enter_;
  430. res = _SUCCESS;
  431. if (obj == NULL) {
  432. res = _FAIL;
  433. goto exit;
  434. }
  435. _enter_critical_bh(&queue->lock, &irqL);
  436. rtw_list_insert_tail(&obj->list, &queue->queue);
  437. _exit_critical_bh(&queue->lock, &irqL);
  438. //rtw_evt_notify_isr(pevtpriv);
  439. exit:
  440. _func_exit_;
  441. return res;
  442. }
  443. struct evt_obj *rtw_dequeue_evt(_queue *queue)
  444. {
  445. _irqL irqL;
  446. struct evt_obj *pevtobj;
  447. _func_enter_;
  448. _enter_critical_bh(&queue->lock, &irqL);
  449. if (rtw_is_list_empty(&(queue->queue)))
  450. pevtobj = NULL;
  451. else
  452. {
  453. pevtobj = LIST_CONTAINOR(get_next(&(queue->queue)), struct evt_obj, list);
  454. rtw_list_delete(&pevtobj->list);
  455. }
  456. _exit_critical_bh(&queue->lock, &irqL);
  457. _func_exit_;
  458. return pevtobj;
  459. }
  460. void rtw_free_evt_obj(struct evt_obj *pevtobj)
  461. {
  462. _func_enter_;
  463. if(pevtobj->parmbuf)
  464. rtw_mfree((unsigned char*)pevtobj->parmbuf, pevtobj->evtsz);
  465. rtw_mfree((unsigned char*)pevtobj, sizeof(struct evt_obj));
  466. _func_exit_;
  467. }
  468. void rtw_evt_notify_isr(struct evt_priv *pevtpriv)
  469. {
  470. _func_enter_;
  471. pevtpriv->evt_done_cnt++;
  472. _rtw_up_sema(&(pevtpriv->evt_notify));
  473. _func_exit_;
  474. }
  475. #endif
  476. /*
  477. u8 rtw_setstandby_cmd(unsigned char *adapter)
  478. */
  479. u8 rtw_setstandby_cmd(_adapter *padapter, uint action)
  480. {
  481. struct cmd_obj* ph2c;
  482. struct usb_suspend_parm* psetusbsuspend;
  483. struct cmd_priv *pcmdpriv=&padapter->cmdpriv;
  484. u8 ret = _SUCCESS;
  485. _func_enter_;
  486. ph2c = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  487. if (ph2c == NULL) {
  488. ret = _FAIL;
  489. goto exit;
  490. }
  491. psetusbsuspend = (struct usb_suspend_parm*)rtw_zmalloc(sizeof(struct usb_suspend_parm));
  492. if (psetusbsuspend == NULL) {
  493. rtw_mfree((u8 *) ph2c, sizeof(struct cmd_obj));
  494. ret = _FAIL;
  495. goto exit;
  496. }
  497. psetusbsuspend->action = action;
  498. init_h2fwcmd_w_parm_no_rsp(ph2c, psetusbsuspend, GEN_CMD_CODE(_SetUsbSuspend));
  499. ret = rtw_enqueue_cmd(pcmdpriv, ph2c);
  500. exit:
  501. _func_exit_;
  502. return ret;
  503. }
  504. /*
  505. rtw_sitesurvey_cmd(~)
  506. ### NOTE:#### (!!!!)
  507. MUST TAKE CARE THAT BEFORE CALLING THIS FUNC, YOU SHOULD HAVE LOCKED pmlmepriv->lock
  508. */
  509. u8 rtw_sitesurvey_cmd(_adapter *padapter, NDIS_802_11_SSID *ssid, int ssid_num,
  510. struct rtw_ieee80211_channel *ch, int ch_num)
  511. {
  512. u8 res = _FAIL;
  513. struct cmd_obj *ph2c;
  514. struct sitesurvey_parm *psurveyPara;
  515. struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
  516. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  517. #ifdef CONFIG_P2P
  518. struct wifidirect_info *pwdinfo= &(padapter->wdinfo);
  519. #endif //CONFIG_P2P
  520. _func_enter_;
  521. #ifdef CONFIG_LPS
  522. if(check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE){
  523. rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_SCAN, 1);
  524. }
  525. #endif
  526. #ifdef CONFIG_P2P_PS
  527. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) {
  528. p2p_ps_wk_cmd(padapter, P2P_PS_SCAN, 1);
  529. }
  530. #endif //CONFIG_P2P_PS
  531. ph2c = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  532. if (ph2c == NULL)
  533. return _FAIL;
  534. psurveyPara = (struct sitesurvey_parm*)rtw_zmalloc(sizeof(struct sitesurvey_parm));
  535. if (psurveyPara == NULL) {
  536. rtw_mfree((unsigned char*) ph2c, sizeof(struct cmd_obj));
  537. return _FAIL;
  538. }
  539. rtw_free_network_queue(padapter, _FALSE);
  540. RT_TRACE(_module_rtl871x_cmd_c_, _drv_info_, ("%s: flush network queue\n", __FUNCTION__));
  541. init_h2fwcmd_w_parm_no_rsp(ph2c, psurveyPara, GEN_CMD_CODE(_SiteSurvey));
  542. /* psurveyPara->bsslimit = 48; */
  543. psurveyPara->scan_mode = pmlmepriv->scan_mode;
  544. /* prepare ssid list */
  545. if (ssid) {
  546. int i;
  547. for (i=0; i<ssid_num && i< RTW_SSID_SCAN_AMOUNT; i++) {
  548. if (ssid[i].SsidLength) {
  549. _rtw_memcpy(&psurveyPara->ssid[i], &ssid[i], sizeof(NDIS_802_11_SSID));
  550. psurveyPara->ssid_num++;
  551. if (0)
  552. DBG_871X(FUNC_ADPT_FMT" ssid:(%s, %d)\n", FUNC_ADPT_ARG(padapter),
  553. psurveyPara->ssid[i].Ssid, psurveyPara->ssid[i].SsidLength);
  554. }
  555. }
  556. }
  557. /* prepare channel list */
  558. if (ch) {
  559. int i;
  560. for (i=0; i<ch_num && i< RTW_CHANNEL_SCAN_AMOUNT; i++) {
  561. if (ch[i].hw_value && !(ch[i].flags & RTW_IEEE80211_CHAN_DISABLED)) {
  562. _rtw_memcpy(&psurveyPara->ch[i], &ch[i], sizeof(struct rtw_ieee80211_channel));
  563. psurveyPara->ch_num++;
  564. if (0)
  565. DBG_871X(FUNC_ADPT_FMT" ch:%u\n", FUNC_ADPT_ARG(padapter),
  566. psurveyPara->ch[i].hw_value);
  567. }
  568. }
  569. }
  570. set_fwstate(pmlmepriv, _FW_UNDER_SURVEY);
  571. res = rtw_enqueue_cmd(pcmdpriv, ph2c);
  572. if(res == _SUCCESS) {
  573. pmlmepriv->scan_start_time = rtw_get_current_time();
  574. #ifdef CONFIG_STA_MODE_SCAN_UNDER_AP_MODE
  575. if((padapter->pbuddy_adapter->mlmeextpriv.mlmext_info.state&0x03) == WIFI_FW_AP_STATE)
  576. _set_timer(&pmlmepriv->scan_to_timer, SURVEY_TO * ( 38 + ( 38 / RTW_SCAN_NUM_OF_CH ) * RTW_STAY_AP_CH_MILLISECOND ) + 1000 );
  577. else
  578. #endif //CONFIG_STA_MODE_SCAN_UNDER_AP_MODE
  579. _set_timer(&pmlmepriv->scan_to_timer, SCANNING_TIMEOUT);
  580. rtw_led_control(padapter, LED_CTL_SITE_SURVEY);
  581. pmlmepriv->scan_interval = SCAN_INTERVAL;// 30*2 sec = 60sec
  582. } else {
  583. _clr_fwstate_(pmlmepriv, _FW_UNDER_SURVEY);
  584. }
  585. _func_exit_;
  586. return res;
  587. }
  588. u8 rtw_setdatarate_cmd(_adapter *padapter, u8 *rateset)
  589. {
  590. struct cmd_obj* ph2c;
  591. struct setdatarate_parm* pbsetdataratepara;
  592. struct cmd_priv* pcmdpriv = &padapter->cmdpriv;
  593. u8 res = _SUCCESS;
  594. _func_enter_;
  595. ph2c = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  596. if (ph2c == NULL) {
  597. res = _FAIL;
  598. goto exit;
  599. }
  600. pbsetdataratepara = (struct setdatarate_parm*)rtw_zmalloc(sizeof(struct setdatarate_parm));
  601. if (pbsetdataratepara == NULL) {
  602. rtw_mfree((u8 *) ph2c, sizeof(struct cmd_obj));
  603. res = _FAIL;
  604. goto exit;
  605. }
  606. init_h2fwcmd_w_parm_no_rsp(ph2c, pbsetdataratepara, GEN_CMD_CODE(_SetDataRate));
  607. #ifdef MP_FIRMWARE_OFFLOAD
  608. pbsetdataratepara->curr_rateidx = *(u32*)rateset;
  609. // _rtw_memcpy(pbsetdataratepara, rateset, sizeof(u32));
  610. #else
  611. pbsetdataratepara->mac_id = 5;
  612. _rtw_memcpy(pbsetdataratepara->datarates, rateset, NumRates);
  613. #endif
  614. res = rtw_enqueue_cmd(pcmdpriv, ph2c);
  615. exit:
  616. _func_exit_;
  617. return res;
  618. }
  619. u8 rtw_setbasicrate_cmd(_adapter *padapter, u8 *rateset)
  620. {
  621. struct cmd_obj* ph2c;
  622. struct setbasicrate_parm* pssetbasicratepara;
  623. struct cmd_priv* pcmdpriv=&padapter->cmdpriv;
  624. u8 res = _SUCCESS;
  625. _func_enter_;
  626. ph2c = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  627. if (ph2c == NULL) {
  628. res= _FAIL;
  629. goto exit;
  630. }
  631. pssetbasicratepara = (struct setbasicrate_parm*)rtw_zmalloc(sizeof(struct setbasicrate_parm));
  632. if (pssetbasicratepara == NULL) {
  633. rtw_mfree((u8*) ph2c, sizeof(struct cmd_obj));
  634. res = _FAIL;
  635. goto exit;
  636. }
  637. init_h2fwcmd_w_parm_no_rsp(ph2c, pssetbasicratepara, _SetBasicRate_CMD_);
  638. _rtw_memcpy(pssetbasicratepara->basicrates, rateset, NumRates);
  639. res = rtw_enqueue_cmd(pcmdpriv, ph2c);
  640. exit:
  641. _func_exit_;
  642. return res;
  643. }
  644. /*
  645. unsigned char rtw_setphy_cmd(unsigned char *adapter)
  646. 1. be called only after rtw_update_registrypriv_dev_network( ~) or mp testing program
  647. 2. for AdHoc/Ap mode or mp mode?
  648. */
  649. u8 rtw_setphy_cmd(_adapter *padapter, u8 modem, u8 ch)
  650. {
  651. struct cmd_obj* ph2c;
  652. struct setphy_parm* psetphypara;
  653. struct cmd_priv *pcmdpriv=&padapter->cmdpriv;
  654. // struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  655. // struct registry_priv* pregistry_priv = &padapter->registrypriv;
  656. u8 res=_SUCCESS;
  657. _func_enter_;
  658. ph2c = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  659. if(ph2c==NULL){
  660. res= _FAIL;
  661. goto exit;
  662. }
  663. psetphypara = (struct setphy_parm*)rtw_zmalloc(sizeof(struct setphy_parm));
  664. if(psetphypara==NULL){
  665. rtw_mfree((u8 *) ph2c, sizeof(struct cmd_obj));
  666. res= _FAIL;
  667. goto exit;
  668. }
  669. init_h2fwcmd_w_parm_no_rsp(ph2c, psetphypara, _SetPhy_CMD_);
  670. RT_TRACE(_module_rtl871x_cmd_c_,_drv_info_,("CH=%d, modem=%d", ch, modem));
  671. psetphypara->modem = modem;
  672. psetphypara->rfchannel = ch;
  673. res = rtw_enqueue_cmd(pcmdpriv, ph2c);
  674. exit:
  675. _func_exit_;
  676. return res;
  677. }
  678. u8 rtw_setbbreg_cmd(_adapter*padapter, u8 offset, u8 val)
  679. {
  680. struct cmd_obj* ph2c;
  681. struct writeBB_parm* pwritebbparm;
  682. struct cmd_priv *pcmdpriv=&padapter->cmdpriv;
  683. u8 res=_SUCCESS;
  684. _func_enter_;
  685. ph2c = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  686. if(ph2c==NULL){
  687. res= _FAIL;
  688. goto exit;
  689. }
  690. pwritebbparm = (struct writeBB_parm*)rtw_zmalloc(sizeof(struct writeBB_parm));
  691. if(pwritebbparm==NULL){
  692. rtw_mfree((u8 *) ph2c, sizeof(struct cmd_obj));
  693. res= _FAIL;
  694. goto exit;
  695. }
  696. init_h2fwcmd_w_parm_no_rsp(ph2c, pwritebbparm, GEN_CMD_CODE(_SetBBReg));
  697. pwritebbparm->offset = offset;
  698. pwritebbparm->value = val;
  699. res = rtw_enqueue_cmd(pcmdpriv, ph2c);
  700. exit:
  701. _func_exit_;
  702. return res;
  703. }
  704. u8 rtw_getbbreg_cmd(_adapter *padapter, u8 offset, u8 *pval)
  705. {
  706. struct cmd_obj* ph2c;
  707. struct readBB_parm* prdbbparm;
  708. struct cmd_priv *pcmdpriv=&padapter->cmdpriv;
  709. u8 res=_SUCCESS;
  710. _func_enter_;
  711. ph2c = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  712. if(ph2c==NULL){
  713. res=_FAIL;
  714. goto exit;
  715. }
  716. prdbbparm = (struct readBB_parm*)rtw_zmalloc(sizeof(struct readBB_parm));
  717. if(prdbbparm ==NULL){
  718. rtw_mfree((unsigned char *) ph2c, sizeof(struct cmd_obj));
  719. return _FAIL;
  720. }
  721. _rtw_init_listhead(&ph2c->list);
  722. ph2c->cmdcode =GEN_CMD_CODE(_GetBBReg);
  723. ph2c->parmbuf = (unsigned char *)prdbbparm;
  724. ph2c->cmdsz = sizeof(struct readBB_parm);
  725. ph2c->rsp = pval;
  726. ph2c->rspsz = sizeof(struct readBB_rsp);
  727. prdbbparm ->offset = offset;
  728. res = rtw_enqueue_cmd(pcmdpriv, ph2c);
  729. exit:
  730. _func_exit_;
  731. return res;
  732. }
  733. u8 rtw_setrfreg_cmd(_adapter *padapter, u8 offset, u32 val)
  734. {
  735. struct cmd_obj* ph2c;
  736. struct writeRF_parm* pwriterfparm;
  737. struct cmd_priv *pcmdpriv=&padapter->cmdpriv;
  738. u8 res=_SUCCESS;
  739. _func_enter_;
  740. ph2c = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  741. if(ph2c==NULL){
  742. res= _FAIL;
  743. goto exit;
  744. }
  745. pwriterfparm = (struct writeRF_parm*)rtw_zmalloc(sizeof(struct writeRF_parm));
  746. if(pwriterfparm==NULL){
  747. rtw_mfree((u8 *) ph2c, sizeof(struct cmd_obj));
  748. res= _FAIL;
  749. goto exit;
  750. }
  751. init_h2fwcmd_w_parm_no_rsp(ph2c, pwriterfparm, GEN_CMD_CODE(_SetRFReg));
  752. pwriterfparm->offset = offset;
  753. pwriterfparm->value = val;
  754. res = rtw_enqueue_cmd(pcmdpriv, ph2c);
  755. exit:
  756. _func_exit_;
  757. return res;
  758. }
  759. u8 rtw_getrfreg_cmd(_adapter *padapter, u8 offset, u8 *pval)
  760. {
  761. struct cmd_obj* ph2c;
  762. struct readRF_parm* prdrfparm;
  763. struct cmd_priv *pcmdpriv=&padapter->cmdpriv;
  764. u8 res=_SUCCESS;
  765. _func_enter_;
  766. ph2c = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  767. if(ph2c==NULL){
  768. res= _FAIL;
  769. goto exit;
  770. }
  771. prdrfparm = (struct readRF_parm*)rtw_zmalloc(sizeof(struct readRF_parm));
  772. if(prdrfparm ==NULL){
  773. rtw_mfree((u8 *) ph2c, sizeof(struct cmd_obj));
  774. res= _FAIL;
  775. goto exit;
  776. }
  777. _rtw_init_listhead(&ph2c->list);
  778. ph2c->cmdcode =GEN_CMD_CODE(_GetRFReg);
  779. ph2c->parmbuf = (unsigned char *)prdrfparm;
  780. ph2c->cmdsz = sizeof(struct readRF_parm);
  781. ph2c->rsp = pval;
  782. ph2c->rspsz = sizeof(struct readRF_rsp);
  783. prdrfparm ->offset = offset;
  784. res = rtw_enqueue_cmd(pcmdpriv, ph2c);
  785. exit:
  786. _func_exit_;
  787. return res;
  788. }
  789. void rtw_getbbrfreg_cmdrsp_callback(_adapter* padapter, struct cmd_obj *pcmd)
  790. {
  791. _func_enter_;
  792. //rtw_free_cmd_obj(pcmd);
  793. rtw_mfree((unsigned char*) pcmd->parmbuf, pcmd->cmdsz);
  794. rtw_mfree((unsigned char*) pcmd, sizeof(struct cmd_obj));
  795. #ifdef CONFIG_MP_INCLUDED
  796. if (padapter->registrypriv.mp_mode == 1)
  797. padapter->mppriv.workparam.bcompleted= _TRUE;
  798. #endif
  799. _func_exit_;
  800. }
  801. void rtw_readtssi_cmdrsp_callback(_adapter* padapter, struct cmd_obj *pcmd)
  802. {
  803. _func_enter_;
  804. rtw_mfree((unsigned char*) pcmd->parmbuf, pcmd->cmdsz);
  805. rtw_mfree((unsigned char*) pcmd, sizeof(struct cmd_obj));
  806. #ifdef CONFIG_MP_INCLUDED
  807. if (padapter->registrypriv.mp_mode == 1)
  808. padapter->mppriv.workparam.bcompleted= _TRUE;
  809. #endif
  810. _func_exit_;
  811. }
  812. u8 rtw_createbss_cmd(_adapter *padapter)
  813. {
  814. struct cmd_obj* pcmd;
  815. struct cmd_priv *pcmdpriv=&padapter->cmdpriv;
  816. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  817. WLAN_BSSID_EX *pdev_network = &padapter->registrypriv.dev_network;
  818. u8 res=_SUCCESS;
  819. _func_enter_;
  820. rtw_led_control(padapter, LED_CTL_START_TO_LINK);
  821. if (pmlmepriv->assoc_ssid.SsidLength == 0){
  822. RT_TRACE(_module_rtl871x_cmd_c_,_drv_info_,(" createbss for Any SSid:%s\n",pmlmepriv->assoc_ssid.Ssid));
  823. } else {
  824. RT_TRACE(_module_rtl871x_cmd_c_,_drv_info_,(" createbss for SSid:%s\n", pmlmepriv->assoc_ssid.Ssid));
  825. }
  826. pcmd = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  827. if(pcmd==NULL){
  828. res= _FAIL;
  829. goto exit;
  830. }
  831. _rtw_init_listhead(&pcmd->list);
  832. pcmd->cmdcode = _CreateBss_CMD_;
  833. pcmd->parmbuf = (unsigned char *)pdev_network;
  834. pcmd->cmdsz = get_WLAN_BSSID_EX_sz((WLAN_BSSID_EX*)pdev_network);
  835. pcmd->rsp = NULL;
  836. pcmd->rspsz = 0;
  837. pdev_network->Length = pcmd->cmdsz;
  838. #ifdef CONFIG_RTL8712
  839. //notes: translate IELength & Length after assign the Length to cmdsz;
  840. pdev_network->Length = cpu_to_le32(pcmd->cmdsz);
  841. pdev_network->IELength = cpu_to_le32(pdev_network->IELength);
  842. pdev_network->Ssid.SsidLength = cpu_to_le32(pdev_network->Ssid.SsidLength);
  843. #endif
  844. res = rtw_enqueue_cmd(pcmdpriv, pcmd);
  845. exit:
  846. _func_exit_;
  847. return res;
  848. }
  849. u8 rtw_createbss_cmd_ex(_adapter *padapter, unsigned char *pbss, unsigned int sz)
  850. {
  851. struct cmd_obj* pcmd;
  852. struct cmd_priv *pcmdpriv=&padapter->cmdpriv;
  853. u8 res=_SUCCESS;
  854. _func_enter_;
  855. pcmd = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  856. if(pcmd==NULL){
  857. res= _FAIL;
  858. goto exit;
  859. }
  860. _rtw_init_listhead(&pcmd->list);
  861. pcmd->cmdcode = GEN_CMD_CODE(_CreateBss);
  862. pcmd->parmbuf = pbss;
  863. pcmd->cmdsz = sz;
  864. pcmd->rsp = NULL;
  865. pcmd->rspsz = 0;
  866. res = rtw_enqueue_cmd(pcmdpriv, pcmd);
  867. exit:
  868. _func_exit_;
  869. return res;
  870. }
  871. u8 rtw_joinbss_cmd(_adapter *padapter, struct wlan_network* pnetwork)
  872. {
  873. u8 *auth, res = _SUCCESS;
  874. uint t_len = 0;
  875. WLAN_BSSID_EX *psecnetwork;
  876. struct cmd_obj *pcmd;
  877. struct cmd_priv *pcmdpriv=&padapter->cmdpriv;
  878. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  879. struct qos_priv *pqospriv= &pmlmepriv->qospriv;
  880. struct security_priv *psecuritypriv=&padapter->securitypriv;
  881. struct registry_priv *pregistrypriv = &padapter->registrypriv;
  882. #ifdef CONFIG_80211N_HT
  883. struct ht_priv *phtpriv = &pmlmepriv->htpriv;
  884. #endif //CONFIG_80211N_HT
  885. #ifdef CONFIG_80211AC_VHT
  886. struct vht_priv *pvhtpriv = &pmlmepriv->vhtpriv;
  887. #endif //CONFIG_80211AC_VHT
  888. NDIS_802_11_NETWORK_INFRASTRUCTURE ndis_network_mode = pnetwork->network.InfrastructureMode;
  889. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  890. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  891. _func_enter_;
  892. rtw_led_control(padapter, LED_CTL_START_TO_LINK);
  893. if (pmlmepriv->assoc_ssid.SsidLength == 0){
  894. RT_TRACE(_module_rtl871x_cmd_c_, _drv_info_, ("+Join cmd: Any SSid\n"));
  895. } else {
  896. RT_TRACE(_module_rtl871x_cmd_c_, _drv_notice_, ("+Join cmd: SSid=[%s]\n", pmlmepriv->assoc_ssid.Ssid));
  897. }
  898. pcmd = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  899. if(pcmd==NULL){
  900. res=_FAIL;
  901. RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_, ("rtw_joinbss_cmd: memory allocate for cmd_obj fail!!!\n"));
  902. goto exit;
  903. }
  904. /* // for IEs is pointer
  905. t_len = sizeof (ULONG) + sizeof (NDIS_802_11_MAC_ADDRESS) + 2 +
  906. sizeof (NDIS_802_11_SSID) + sizeof (ULONG) +
  907. sizeof (NDIS_802_11_RSSI) + sizeof (NDIS_802_11_NETWORK_TYPE) +
  908. sizeof (NDIS_802_11_CONFIGURATION) +
  909. sizeof (NDIS_802_11_NETWORK_INFRASTRUCTURE) +
  910. sizeof (NDIS_802_11_RATES_EX)+ sizeof(WLAN_PHY_INFO)+ sizeof (ULONG) + MAX_IE_SZ;
  911. */
  912. //for IEs is fix buf size
  913. t_len = sizeof(WLAN_BSSID_EX);
  914. //for hidden ap to set fw_state here
  915. if (check_fwstate(pmlmepriv, WIFI_STATION_STATE|WIFI_ADHOC_STATE) != _TRUE)
  916. {
  917. switch(ndis_network_mode)
  918. {
  919. case Ndis802_11IBSS:
  920. set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
  921. break;
  922. case Ndis802_11Infrastructure:
  923. set_fwstate(pmlmepriv, WIFI_STATION_STATE);
  924. break;
  925. case Ndis802_11APMode:
  926. case Ndis802_11AutoUnknown:
  927. case Ndis802_11InfrastructureMax:
  928. break;
  929. }
  930. }
  931. psecnetwork=(WLAN_BSSID_EX *)&psecuritypriv->sec_bss;
  932. if(psecnetwork==NULL)
  933. {
  934. if(pcmd !=NULL)
  935. rtw_mfree((unsigned char *)pcmd, sizeof(struct cmd_obj));
  936. res=_FAIL;
  937. RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_, ("rtw_joinbss_cmd :psecnetwork==NULL!!!\n"));
  938. goto exit;
  939. }
  940. _rtw_memset(psecnetwork, 0, t_len);
  941. _rtw_memcpy(psecnetwork, &pnetwork->network, get_WLAN_BSSID_EX_sz(&pnetwork->network));
  942. auth=&psecuritypriv->authenticator_ie[0];
  943. psecuritypriv->authenticator_ie[0]=(unsigned char)psecnetwork->IELength;
  944. if((psecnetwork->IELength-12) < (256-1)) {
  945. _rtw_memcpy(&psecuritypriv->authenticator_ie[1], &psecnetwork->IEs[12], psecnetwork->IELength-12);
  946. } else {
  947. _rtw_memcpy(&psecuritypriv->authenticator_ie[1], &psecnetwork->IEs[12], (256-1));
  948. }
  949. psecnetwork->IELength = 0;
  950. // Added by Albert 2009/02/18
  951. // If the the driver wants to use the bssid to create the connection.
  952. // If not, we have to copy the connecting AP's MAC address to it so that
  953. // the driver just has the bssid information for PMKIDList searching.
  954. if ( pmlmepriv->assoc_by_bssid == _FALSE )
  955. {
  956. _rtw_memcpy( &pmlmepriv->assoc_bssid[ 0 ], &pnetwork->network.MacAddress[ 0 ], ETH_ALEN );
  957. }
  958. psecnetwork->IELength = rtw_restruct_sec_ie(padapter, &pnetwork->network.IEs[0], &psecnetwork->IEs[0], pnetwork->network.IELength);
  959. pqospriv->qos_option = 0;
  960. if(pregistrypriv->wmm_enable)
  961. {
  962. u32 tmp_len;
  963. tmp_len = rtw_restruct_wmm_ie(padapter, &pnetwork->network.IEs[0], &psecnetwork->IEs[0], pnetwork->network.IELength, psecnetwork->IELength);
  964. if (psecnetwork->IELength != tmp_len)
  965. {
  966. psecnetwork->IELength = tmp_len;
  967. pqospriv->qos_option = 1; //There is WMM IE in this corresp. beacon
  968. }
  969. else
  970. {
  971. pqospriv->qos_option = 0;//There is no WMM IE in this corresp. beacon
  972. }
  973. }
  974. #ifdef CONFIG_80211N_HT
  975. phtpriv->ht_option = _FALSE;
  976. if(pregistrypriv->ht_enable)
  977. {
  978. // Added by Albert 2010/06/23
  979. // For the WEP mode, we will use the bg mode to do the connection to avoid some IOT issue.
  980. // Especially for Realtek 8192u SoftAP.
  981. if ( ( padapter->securitypriv.dot11PrivacyAlgrthm != _WEP40_ ) &&
  982. ( padapter->securitypriv.dot11PrivacyAlgrthm != _WEP104_ ) &&
  983. ( padapter->securitypriv.dot11PrivacyAlgrthm != _TKIP_ ))
  984. {
  985. //rtw_restructure_ht_ie
  986. rtw_restructure_ht_ie(padapter, &pnetwork->network.IEs[0], &psecnetwork->IEs[0],
  987. pnetwork->network.IELength, &psecnetwork->IELength);
  988. }
  989. }
  990. #endif
  991. #ifdef CONFIG_80211AC_VHT
  992. pvhtpriv->vht_option = _FALSE;
  993. if (phtpriv->ht_option && pregistrypriv->vht_enable) {
  994. rtw_restructure_vht_ie(padapter, &pnetwork->network.IEs[0], &psecnetwork->IEs[0],
  995. pnetwork->network.IELength, &psecnetwork->IELength);
  996. }
  997. #endif
  998. pmlmeinfo->assoc_AP_vendor = check_assoc_AP(pnetwork->network.IEs, pnetwork->network.IELength);
  999. #if 0
  1000. psecuritypriv->supplicant_ie[0]=(u8)psecnetwork->IELength;
  1001. if(psecnetwork->IELength < (256-1))
  1002. {
  1003. _rtw_memcpy(&psecuritypriv->supplicant_ie[1], &psecnetwork->IEs[0], psecnetwork->IELength);
  1004. }
  1005. else
  1006. {
  1007. _rtw_memcpy(&psecuritypriv->supplicant_ie[1], &psecnetwork->IEs[0], (256-1));
  1008. }
  1009. #endif
  1010. pcmd->cmdsz = get_WLAN_BSSID_EX_sz(psecnetwork);//get cmdsz before endian conversion
  1011. #ifdef CONFIG_RTL8712
  1012. //wlan_network endian conversion
  1013. psecnetwork->Length = cpu_to_le32(psecnetwork->Length);
  1014. psecnetwork->Ssid.SsidLength= cpu_to_le32(psecnetwork->Ssid.SsidLength);
  1015. psecnetwork->Privacy = cpu_to_le32(psecnetwork->Privacy);
  1016. psecnetwork->Rssi = cpu_to_le32(psecnetwork->Rssi);
  1017. psecnetwork->NetworkTypeInUse = cpu_to_le32(psecnetwork->NetworkTypeInUse);
  1018. psecnetwork->Configuration.ATIMWindow = cpu_to_le32(psecnetwork->Configuration.ATIMWindow);
  1019. psecnetwork->Configuration.BeaconPeriod = cpu_to_le32(psecnetwork->Configuration.BeaconPeriod);
  1020. psecnetwork->Configuration.DSConfig = cpu_to_le32(psecnetwork->Configuration.DSConfig);
  1021. psecnetwork->Configuration.FHConfig.DwellTime=cpu_to_le32(psecnetwork->Configuration.FHConfig.DwellTime);
  1022. psecnetwork->Configuration.FHConfig.HopPattern=cpu_to_le32(psecnetwork->Configuration.FHConfig.HopPattern);
  1023. psecnetwork->Configuration.FHConfig.HopSet=cpu_to_le32(psecnetwork->Configuration.FHConfig.HopSet);
  1024. psecnetwork->Configuration.FHConfig.Length=cpu_to_le32(psecnetwork->Configuration.FHConfig.Length);
  1025. psecnetwork->Configuration.Length = cpu_to_le32(psecnetwork->Configuration.Length);
  1026. psecnetwork->InfrastructureMode = cpu_to_le32(psecnetwork->InfrastructureMode);
  1027. psecnetwork->IELength = cpu_to_le32(psecnetwork->IELength);
  1028. #endif
  1029. _rtw_init_listhead(&pcmd->list);
  1030. pcmd->cmdcode = _JoinBss_CMD_;//GEN_CMD_CODE(_JoinBss)
  1031. pcmd->parmbuf = (unsigned char *)psecnetwork;
  1032. pcmd->rsp = NULL;
  1033. pcmd->rspsz = 0;
  1034. res = rtw_enqueue_cmd(pcmdpriv, pcmd);
  1035. exit:
  1036. _func_exit_;
  1037. return res;
  1038. }
  1039. u8 rtw_disassoc_cmd(_adapter*padapter, u32 deauth_timeout_ms, bool enqueue) /* for sta_mode */
  1040. {
  1041. struct cmd_obj *cmdobj = NULL;
  1042. struct disconnect_parm *param = NULL;
  1043. struct cmd_priv *cmdpriv = &padapter->cmdpriv;
  1044. u8 res = _SUCCESS;
  1045. _func_enter_;
  1046. RT_TRACE(_module_rtl871x_cmd_c_, _drv_notice_, ("+rtw_disassoc_cmd\n"));
  1047. /* prepare cmd parameter */
  1048. param = (struct disconnect_parm *)rtw_zmalloc(sizeof(*param));
  1049. if (param == NULL) {
  1050. res = _FAIL;
  1051. goto exit;
  1052. }
  1053. param->deauth_timeout_ms = deauth_timeout_ms;
  1054. if (enqueue) {
  1055. /* need enqueue, prepare cmd_obj and enqueue */
  1056. cmdobj = (struct cmd_obj *)rtw_zmalloc(sizeof(*cmdobj));
  1057. if (cmdobj == NULL) {
  1058. res = _FAIL;
  1059. rtw_mfree((u8 *)param, sizeof(*param));
  1060. goto exit;
  1061. }
  1062. init_h2fwcmd_w_parm_no_rsp(cmdobj, param, _DisConnect_CMD_);
  1063. res = rtw_enqueue_cmd(cmdpriv, cmdobj);
  1064. } else {
  1065. /* no need to enqueue, do the cmd hdl directly and free cmd parameter */
  1066. if (H2C_SUCCESS != disconnect_hdl(padapter, (u8 *)param))
  1067. res = _FAIL;
  1068. rtw_mfree((u8 *)param, sizeof(*param));
  1069. }
  1070. exit:
  1071. _func_exit_;
  1072. return res;
  1073. }
  1074. u8 rtw_setopmode_cmd(_adapter *padapter, NDIS_802_11_NETWORK_INFRASTRUCTURE networktype)
  1075. {
  1076. struct cmd_obj* ph2c;
  1077. struct setopmode_parm* psetop;
  1078. struct cmd_priv *pcmdpriv= &padapter->cmdpriv;
  1079. u8 res=_SUCCESS;
  1080. _func_enter_;
  1081. ph2c = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  1082. if(ph2c==NULL){
  1083. res= _FALSE;
  1084. goto exit;
  1085. }
  1086. psetop = (struct setopmode_parm*)rtw_zmalloc(sizeof(struct setopmode_parm));
  1087. if(psetop==NULL){
  1088. rtw_mfree((u8 *) ph2c, sizeof(struct cmd_obj));
  1089. res=_FALSE;
  1090. goto exit;
  1091. }
  1092. init_h2fwcmd_w_parm_no_rsp(ph2c, psetop, _SetOpMode_CMD_);
  1093. psetop->mode = (u8)networktype;
  1094. res = rtw_enqueue_cmd(pcmdpriv, ph2c);
  1095. exit:
  1096. _func_exit_;
  1097. return res;
  1098. }
  1099. u8 rtw_setstakey_cmd(_adapter *padapter, u8 *psta, u8 unicast_key)
  1100. {
  1101. struct cmd_obj* ph2c;
  1102. struct set_stakey_parm *psetstakey_para;
  1103. struct cmd_priv *pcmdpriv=&padapter->cmdpriv;
  1104. struct set_stakey_rsp *psetstakey_rsp = NULL;
  1105. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1106. struct security_priv *psecuritypriv = &padapter->securitypriv;
  1107. struct sta_info* sta = (struct sta_info* )psta;
  1108. u8 res=_SUCCESS;
  1109. _func_enter_;
  1110. ph2c = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  1111. if ( ph2c == NULL){
  1112. res= _FAIL;
  1113. goto exit;
  1114. }
  1115. psetstakey_para = (struct set_stakey_parm*)rtw_zmalloc(sizeof(struct set_stakey_parm));
  1116. if(psetstakey_para==NULL){
  1117. rtw_mfree((u8 *) ph2c, sizeof(struct cmd_obj));
  1118. res=_FAIL;
  1119. goto exit;
  1120. }
  1121. psetstakey_rsp = (struct set_stakey_rsp*)rtw_zmalloc(sizeof(struct set_stakey_rsp));
  1122. if(psetstakey_rsp == NULL){
  1123. rtw_mfree((u8 *) ph2c, sizeof(struct cmd_obj));
  1124. rtw_mfree((u8 *) psetstakey_para, sizeof(struct set_stakey_parm));
  1125. res=_FAIL;
  1126. goto exit;
  1127. }
  1128. init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para, _SetStaKey_CMD_);
  1129. ph2c->rsp = (u8 *) psetstakey_rsp;
  1130. ph2c->rspsz = sizeof(struct set_stakey_rsp);
  1131. _rtw_memcpy(psetstakey_para->addr, sta->hwaddr,ETH_ALEN);
  1132. if(check_fwstate(pmlmepriv, WIFI_STATION_STATE)){
  1133. #ifdef CONFIG_TDLS
  1134. if(sta->tdls_sta_state&TDLS_LINKED_STATE)
  1135. psetstakey_para->algorithm=(u8)sta->dot118021XPrivacy;
  1136. else
  1137. #endif //CONFIG_TDLS
  1138. psetstakey_para->algorithm =(unsigned char) psecuritypriv->dot11PrivacyAlgrthm;
  1139. }else{
  1140. GET_ENCRY_ALGO(psecuritypriv, sta, psetstakey_para->algorithm, _FALSE);
  1141. }
  1142. if (unicast_key == _TRUE) {
  1143. #ifdef CONFIG_TDLS
  1144. if((sta->tdls_sta_state&TDLS_LINKED_STATE)==TDLS_LINKED_STATE)
  1145. _rtw_memcpy(&psetstakey_para->key, sta->tpk.tk, 16);
  1146. else
  1147. #endif //CONFIG_TDLS
  1148. _rtw_memcpy(&psetstakey_para->key, &sta->dot118021x_UncstKey, 16);
  1149. } else {
  1150. _rtw_memcpy(&psetstakey_para->key, &psecuritypriv->dot118021XGrpKey[psecuritypriv->dot118021XGrpKeyid].skey, 16);
  1151. }
  1152. //jeff: set this becasue at least sw key is ready
  1153. padapter->securitypriv.busetkipkey=_TRUE;
  1154. res = rtw_enqueue_cmd(pcmdpriv, ph2c);
  1155. exit:
  1156. _func_exit_;
  1157. return res;
  1158. }
  1159. u8 rtw_clearstakey_cmd(_adapter *padapter, u8 *psta, u8 entry, u8 enqueue)
  1160. {
  1161. struct cmd_obj* ph2c;
  1162. struct set_stakey_parm *psetstakey_para;
  1163. struct cmd_priv *pcmdpriv=&padapter->cmdpriv;
  1164. struct set_stakey_rsp *psetstakey_rsp = NULL;
  1165. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1166. struct security_priv *psecuritypriv = &padapter->securitypriv;
  1167. struct sta_info* sta = (struct sta_info* )psta;
  1168. u8 res=_SUCCESS;
  1169. _func_enter_;
  1170. if(!enqueue)
  1171. {
  1172. clear_cam_entry(padapter, entry);
  1173. }
  1174. else
  1175. {
  1176. ph2c = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  1177. if ( ph2c == NULL){
  1178. res= _FAIL;
  1179. goto exit;
  1180. }
  1181. psetstakey_para = (struct set_stakey_parm*)rtw_zmalloc(sizeof(struct set_stakey_parm));
  1182. if(psetstakey_para==NULL){
  1183. rtw_mfree((u8 *) ph2c, sizeof(struct cmd_obj));
  1184. res=_FAIL;
  1185. goto exit;
  1186. }
  1187. psetstakey_rsp = (struct set_stakey_rsp*)rtw_zmalloc(sizeof(struct set_stakey_rsp));
  1188. if(psetstakey_rsp == NULL){
  1189. rtw_mfree((u8 *) ph2c, sizeof(struct cmd_obj));
  1190. rtw_mfree((u8 *) psetstakey_para, sizeof(struct set_stakey_parm));
  1191. res=_FAIL;
  1192. goto exit;
  1193. }
  1194. init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para, _SetStaKey_CMD_);
  1195. ph2c->rsp = (u8 *) psetstakey_rsp;
  1196. ph2c->rspsz = sizeof(struct set_stakey_rsp);
  1197. _rtw_memcpy(psetstakey_para->addr, sta->hwaddr, ETH_ALEN);
  1198. psetstakey_para->algorithm = _NO_PRIVACY_;
  1199. psetstakey_para->id = entry;
  1200. res = rtw_enqueue_cmd(pcmdpriv, ph2c);
  1201. }
  1202. exit:
  1203. _func_exit_;
  1204. return res;
  1205. }
  1206. u8 rtw_setrttbl_cmd(_adapter *padapter, struct setratable_parm *prate_table)
  1207. {
  1208. struct cmd_obj* ph2c;
  1209. struct setratable_parm * psetrttblparm;
  1210. struct cmd_priv *pcmdpriv=&padapter->cmdpriv;
  1211. u8 res=_SUCCESS;
  1212. _func_enter_;
  1213. ph2c = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  1214. if(ph2c==NULL){
  1215. res= _FAIL;
  1216. goto exit;
  1217. }
  1218. psetrttblparm = (struct setratable_parm*)rtw_zmalloc(sizeof(struct setratable_parm));
  1219. if(psetrttblparm==NULL){
  1220. rtw_mfree((unsigned char *) ph2c, sizeof(struct cmd_obj));
  1221. res= _FAIL;
  1222. goto exit;
  1223. }
  1224. init_h2fwcmd_w_parm_no_rsp(ph2c, psetrttblparm, GEN_CMD_CODE(_SetRaTable));
  1225. _rtw_memcpy(psetrttblparm,prate_table,sizeof(struct setratable_parm));
  1226. res = rtw_enqueue_cmd(pcmdpriv, ph2c);
  1227. exit:
  1228. _func_exit_;
  1229. return res;
  1230. }
  1231. u8 rtw_getrttbl_cmd(_adapter *padapter, struct getratable_rsp *pval)
  1232. {
  1233. struct cmd_obj* ph2c;
  1234. struct getratable_parm * pgetrttblparm;
  1235. struct cmd_priv *pcmdpriv=&padapter->cmdpriv;
  1236. u8 res=_SUCCESS;
  1237. _func_enter_;
  1238. ph2c = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  1239. if(ph2c==NULL){
  1240. res= _FAIL;
  1241. goto exit;
  1242. }
  1243. pgetrttblparm = (struct getratable_parm*)rtw_zmalloc(sizeof(struct getratable_parm));
  1244. if(pgetrttblparm==NULL){
  1245. rtw_mfree((unsigned char *) ph2c, sizeof(struct cmd_obj));
  1246. res= _FAIL;
  1247. goto exit;
  1248. }
  1249. // init_h2fwcmd_w_parm_no_rsp(ph2c, psetrttblparm, GEN_CMD_CODE(_SetRaTable));
  1250. _rtw_init_listhead(&ph2c->list);
  1251. ph2c->cmdcode =GEN_CMD_CODE(_GetRaTable);
  1252. ph2c->parmbuf = (unsigned char *)pgetrttblparm;
  1253. ph2c->cmdsz = sizeof(struct getratable_parm);
  1254. ph2c->rsp = (u8*)pval;
  1255. ph2c->rspsz = sizeof(struct getratable_rsp);
  1256. pgetrttblparm ->rsvd = 0x0;
  1257. res = rtw_enqueue_cmd(pcmdpriv, ph2c);
  1258. exit:
  1259. _func_exit_;
  1260. return res;
  1261. }
  1262. u8 rtw_setassocsta_cmd(_adapter *padapter, u8 *mac_addr)
  1263. {
  1264. struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
  1265. struct cmd_obj* ph2c;
  1266. struct set_assocsta_parm *psetassocsta_para;
  1267. struct set_stakey_rsp *psetassocsta_rsp = NULL;
  1268. u8 res=_SUCCESS;
  1269. _func_enter_;
  1270. ph2c = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  1271. if(ph2c==NULL){
  1272. res= _FAIL;
  1273. goto exit;
  1274. }
  1275. psetassocsta_para = (struct set_assocsta_parm*)rtw_zmalloc(sizeof(struct set_assocsta_parm));
  1276. if(psetassocsta_para==NULL){
  1277. rtw_mfree((u8 *) ph2c, sizeof(struct cmd_obj));
  1278. res=_FAIL;
  1279. goto exit;
  1280. }
  1281. psetassocsta_rsp = (struct set_stakey_rsp*)rtw_zmalloc(sizeof(struct set_assocsta_rsp));
  1282. if(psetassocsta_rsp==NULL){
  1283. rtw_mfree((u8 *) ph2c, sizeof(struct cmd_obj));
  1284. rtw_mfree((u8 *) psetassocsta_para, sizeof(struct set_assocsta_parm));
  1285. return _FAIL;
  1286. }
  1287. init_h2fwcmd_w_parm_no_rsp(ph2c, psetassocsta_para, _SetAssocSta_CMD_);
  1288. ph2c->rsp = (u8 *) psetassocsta_rsp;
  1289. ph2c->rspsz = sizeof(struct set_assocsta_rsp);
  1290. _rtw_memcpy(psetassocsta_para->addr, mac_addr,ETH_ALEN);
  1291. res = rtw_enqueue_cmd(pcmdpriv, ph2c);
  1292. exit:
  1293. _func_exit_;
  1294. return res;
  1295. }
  1296. u8 rtw_addbareq_cmd(_adapter*padapter, u8 tid, u8 *addr)
  1297. {
  1298. struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
  1299. struct cmd_obj* ph2c;
  1300. struct addBaReq_parm *paddbareq_parm;
  1301. u8 res=_SUCCESS;
  1302. _func_enter_;
  1303. ph2c = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  1304. if(ph2c==NULL){
  1305. res= _FAIL;
  1306. goto exit;
  1307. }
  1308. paddbareq_parm = (struct addBaReq_parm*)rtw_zmalloc(sizeof(struct addBaReq_parm));
  1309. if(paddbareq_parm==NULL){
  1310. rtw_mfree((unsigned char *)ph2c, sizeof(struct cmd_obj));
  1311. res= _FAIL;
  1312. goto exit;
  1313. }
  1314. paddbareq_parm->tid = tid;
  1315. _rtw_memcpy(paddbareq_parm->addr, addr, ETH_ALEN);
  1316. init_h2fwcmd_w_parm_no_rsp(ph2c, paddbareq_parm, GEN_CMD_CODE(_AddBAReq));
  1317. //DBG_871X("rtw_addbareq_cmd, tid=%d\n", tid);
  1318. //rtw_enqueue_cmd(pcmdpriv, ph2c);
  1319. res = rtw_enqueue_cmd(pcmdpriv, ph2c);
  1320. exit:
  1321. _func_exit_;
  1322. return res;
  1323. }
  1324. u8 rtw_dynamic_chk_wk_cmd(_adapter*padapter)
  1325. {
  1326. struct cmd_obj* ph2c;
  1327. struct drvextra_cmd_parm *pdrvextra_cmd_parm;
  1328. struct cmd_priv *pcmdpriv=&padapter->cmdpriv;
  1329. u8 res=_SUCCESS;
  1330. _func_enter_;
  1331. #ifdef CONFIG_CONCURRENT_MODE
  1332. if (padapter->adapter_type != PRIMARY_ADAPTER && padapter->pbuddy_adapter)
  1333. pcmdpriv = &(padapter->pbuddy_adapter->cmdpriv);
  1334. #endif
  1335. ph2c = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  1336. if(ph2c==NULL){
  1337. res= _FAIL;
  1338. goto exit;
  1339. }
  1340. pdrvextra_cmd_parm = (struct drvextra_cmd_parm*)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
  1341. if(pdrvextra_cmd_parm==NULL){
  1342. rtw_mfree((unsigned char *)ph2c, sizeof(struct cmd_obj));
  1343. res= _FAIL;
  1344. goto exit;
  1345. }
  1346. pdrvextra_cmd_parm->ec_id = DYNAMIC_CHK_WK_CID;
  1347. pdrvextra_cmd_parm->type_size = 0;
  1348. pdrvextra_cmd_parm->pbuf = (u8 *)padapter;
  1349. init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
  1350. //rtw_enqueue_cmd(pcmdpriv, ph2c);
  1351. res = rtw_enqueue_cmd(pcmdpriv, ph2c);
  1352. exit:
  1353. _func_exit_;
  1354. return res;
  1355. }
  1356. u8 rtw_set_ch_cmd(_adapter*padapter, u8 ch, u8 bw, u8 ch_offset, u8 enqueue)
  1357. {
  1358. struct cmd_obj *pcmdobj;
  1359. struct set_ch_parm *set_ch_parm;
  1360. struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
  1361. u8 res=_SUCCESS;
  1362. _func_enter_;
  1363. DBG_871X(FUNC_NDEV_FMT" ch:%u, bw:%u, ch_offset:%u\n",
  1364. FUNC_NDEV_ARG(padapter->pnetdev), ch, bw, ch_offset);
  1365. /* check input parameter */
  1366. /* prepare cmd parameter */
  1367. set_ch_parm = (struct set_ch_parm *)rtw_zmalloc(sizeof(*set_ch_parm));
  1368. if (set_ch_parm == NULL) {
  1369. res= _FAIL;
  1370. goto exit;
  1371. }
  1372. set_ch_parm->ch = ch;
  1373. set_ch_parm->bw = bw;
  1374. set_ch_parm->ch_offset = ch_offset;
  1375. if (enqueue) {
  1376. /* need enqueue, prepare cmd_obj and enqueue */
  1377. pcmdobj = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  1378. if(pcmdobj == NULL){
  1379. rtw_mfree((u8 *)set_ch_parm, sizeof(*set_ch_parm));
  1380. res=_FAIL;
  1381. goto exit;
  1382. }
  1383. init_h2fwcmd_w_parm_no_rsp(pcmdobj, set_ch_parm, GEN_CMD_CODE(_SetChannel));
  1384. res = rtw_enqueue_cmd(pcmdpriv, pcmdobj);
  1385. } else {
  1386. /* no need to enqueue, do the cmd hdl directly and free cmd parameter */
  1387. if( H2C_SUCCESS !=set_ch_hdl(padapter, (u8 *)set_ch_parm) )
  1388. res = _FAIL;
  1389. rtw_mfree((u8 *)set_ch_parm, sizeof(*set_ch_parm));
  1390. }
  1391. /* do something based on res... */
  1392. exit:
  1393. DBG_871X(FUNC_NDEV_FMT" res:%u\n", FUNC_NDEV_ARG(padapter->pnetdev), res);
  1394. _func_exit_;
  1395. return res;
  1396. }
  1397. u8 rtw_set_chplan_cmd(_adapter*padapter, u8 chplan, u8 enqueue)
  1398. {
  1399. struct cmd_obj* pcmdobj;
  1400. struct SetChannelPlan_param *setChannelPlan_param;
  1401. struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
  1402. u8 res=_SUCCESS;
  1403. _func_enter_;
  1404. RT_TRACE(_module_rtl871x_cmd_c_, _drv_notice_, ("+rtw_set_chplan_cmd\n"));
  1405. //check input parameter
  1406. if(!rtw_is_channel_plan_valid(chplan)) {
  1407. res = _FAIL;
  1408. goto exit;
  1409. }
  1410. //prepare cmd parameter
  1411. setChannelPlan_param = (struct SetChannelPlan_param *)rtw_zmalloc(sizeof(struct SetChannelPlan_param));
  1412. if(setChannelPlan_param == NULL) {
  1413. res= _FAIL;
  1414. goto exit;
  1415. }
  1416. setChannelPlan_param->channel_plan=chplan;
  1417. if(enqueue)
  1418. {
  1419. //need enqueue, prepare cmd_obj and enqueue
  1420. pcmdobj = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  1421. if(pcmdobj == NULL){
  1422. rtw_mfree((u8 *)setChannelPlan_param, sizeof(struct SetChannelPlan_param));
  1423. res=_FAIL;
  1424. goto exit;
  1425. }
  1426. init_h2fwcmd_w_parm_no_rsp(pcmdobj, setChannelPlan_param, GEN_CMD_CODE(_SetChannelPlan));
  1427. res = rtw_enqueue_cmd(pcmdpriv, pcmdobj);
  1428. }
  1429. else
  1430. {
  1431. //no need to enqueue, do the cmd hdl directly and free cmd parameter
  1432. if( H2C_SUCCESS !=set_chplan_hdl(padapter, (unsigned char *)setChannelPlan_param) )
  1433. res = _FAIL;
  1434. rtw_mfree((u8 *)setChannelPlan_param, sizeof(struct SetChannelPlan_param));
  1435. }
  1436. //do something based on res...
  1437. if(res == _SUCCESS)
  1438. padapter->mlmepriv.ChannelPlan = chplan;
  1439. exit:
  1440. _func_exit_;
  1441. return res;
  1442. }
  1443. u8 rtw_led_blink_cmd(_adapter*padapter, PVOID pLed)
  1444. {
  1445. struct cmd_obj* pcmdobj;
  1446. struct LedBlink_param *ledBlink_param;
  1447. struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
  1448. u8 res=_SUCCESS;
  1449. _func_enter_;
  1450. RT_TRACE(_module_rtl871x_cmd_c_, _drv_notice_, ("+rtw_led_blink_cmd\n"));
  1451. pcmdobj = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  1452. if(pcmdobj == NULL){
  1453. res=_FAIL;
  1454. goto exit;
  1455. }
  1456. ledBlink_param = (struct LedBlink_param *)rtw_zmalloc(sizeof(struct LedBlink_param));
  1457. if(ledBlink_param == NULL) {
  1458. rtw_mfree((u8 *)pcmdobj, sizeof(struct cmd_obj));
  1459. res= _FAIL;
  1460. goto exit;
  1461. }
  1462. ledBlink_param->pLed=pLed;
  1463. init_h2fwcmd_w_parm_no_rsp(pcmdobj, ledBlink_param, GEN_CMD_CODE(_LedBlink));
  1464. res = rtw_enqueue_cmd(pcmdpriv, pcmdobj);
  1465. exit:
  1466. _func_exit_;
  1467. return res;
  1468. }
  1469. u8 rtw_set_csa_cmd(_adapter*padapter, u8 new_ch_no)
  1470. {
  1471. struct cmd_obj* pcmdobj;
  1472. struct SetChannelSwitch_param*setChannelSwitch_param;
  1473. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1474. struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
  1475. u8 res=_SUCCESS;
  1476. _func_enter_;
  1477. RT_TRACE(_module_rtl871x_cmd_c_, _drv_notice_, ("+rtw_set_csa_cmd\n"));
  1478. pcmdobj = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  1479. if(pcmdobj == NULL){
  1480. res=_FAIL;
  1481. goto exit;
  1482. }
  1483. setChannelSwitch_param = (struct SetChannelSwitch_param *)rtw_zmalloc(sizeof(struct SetChannelSwitch_param));
  1484. if(setChannelSwitch_param == NULL) {
  1485. rtw_mfree((u8 *)pcmdobj, sizeof(struct cmd_obj));
  1486. res= _FAIL;
  1487. goto exit;
  1488. }
  1489. setChannelSwitch_param->new_ch_no=new_ch_no;
  1490. init_h2fwcmd_w_parm_no_rsp(pcmdobj, setChannelSwitch_param, GEN_CMD_CODE(_SetChannelSwitch));
  1491. res = rtw_enqueue_cmd(pcmdpriv, pcmdobj);
  1492. exit:
  1493. _func_exit_;
  1494. return res;
  1495. }
  1496. u8 rtw_tdls_cmd(_adapter *padapter, u8 *addr, u8 option)
  1497. {
  1498. struct cmd_obj* pcmdobj;
  1499. struct TDLSoption_param *TDLSoption;
  1500. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1501. struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
  1502. u8 res=_SUCCESS;
  1503. _func_enter_;
  1504. #ifdef CONFIG_TDLS
  1505. RT_TRACE(_module_rtl871x_cmd_c_, _drv_notice_, ("+rtw_set_tdls_cmd\n"));
  1506. pcmdobj = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  1507. if(pcmdobj == NULL){
  1508. res=_FAIL;
  1509. goto exit;
  1510. }
  1511. TDLSoption= (struct TDLSoption_param *)rtw_zmalloc(sizeof(struct TDLSoption_param));
  1512. if(TDLSoption == NULL) {
  1513. rtw_mfree((u8 *)pcmdobj, sizeof(struct cmd_obj));
  1514. res= _FAIL;
  1515. goto exit;
  1516. }
  1517. _rtw_spinlock(&(padapter->tdlsinfo.cmd_lock));
  1518. _rtw_memcpy(TDLSoption->addr, addr, 6);
  1519. TDLSoption->option = option;
  1520. _rtw_spinunlock(&(padapter->tdlsinfo.cmd_lock));
  1521. init_h2fwcmd_w_parm_no_rsp(pcmdobj, TDLSoption, GEN_CMD_CODE(_TDLS));
  1522. res = rtw_enqueue_cmd(pcmdpriv, pcmdobj);
  1523. #endif //CONFIG_TDLS
  1524. exit:
  1525. _func_exit_;
  1526. return res;
  1527. }
  1528. static void traffic_status_watchdog(_adapter *padapter)
  1529. {
  1530. #ifdef CONFIG_LPS
  1531. u8 bEnterPS;
  1532. #endif
  1533. u16 BusyThreshold = 100;
  1534. u8 bBusyTraffic = _FALSE, bTxBusyTraffic = _FALSE, bRxBusyTraffic = _FALSE;
  1535. u8 bHigherBusyTraffic = _FALSE, bHigherBusyRxTraffic = _FALSE, bHigherBusyTxTraffic = _FALSE;
  1536. #ifdef CONFIG_FTP_PROTECT
  1537. u16 bPktCount = 0;
  1538. #endif
  1539. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1540. #ifdef CONFIG_TDLS
  1541. struct tdls_info *ptdlsinfo = &(padapter->tdlsinfo);
  1542. #endif //CONFIG_TDLS
  1543. //
  1544. // Determine if our traffic is busy now
  1545. //
  1546. if((check_fwstate(pmlmepriv, _FW_LINKED)== _TRUE)
  1547. /*&& !MgntInitAdapterInProgress(pMgntInfo)*/)
  1548. {
  1549. #ifdef CONFIG_BT_COEXIST
  1550. if( pmlmepriv->LinkDetectInfo.NumRxOkInPeriod > 50 ||
  1551. pmlmepriv->LinkDetectInfo.NumTxOkInPeriod > 50 )
  1552. #else // !CONFIG_BT_COEXIST
  1553. // if we raise bBusyTraffic in last watchdog, using lower threshold.
  1554. if (pmlmepriv->LinkDetectInfo.bBusyTraffic)
  1555. BusyThreshold = 75;
  1556. if( pmlmepriv->LinkDetectInfo.NumRxOkInPeriod > BusyThreshold ||
  1557. pmlmepriv->LinkDetectInfo.NumTxOkInPeriod > BusyThreshold )
  1558. #endif // !CONFIG_BT_COEXIST
  1559. {
  1560. bBusyTraffic = _TRUE;
  1561. if (pmlmepriv->LinkDetectInfo.NumRxOkInPeriod > pmlmepriv->LinkDetectInfo.NumTxOkInPeriod)
  1562. bRxBusyTraffic = _TRUE;
  1563. else
  1564. bTxBusyTraffic = _TRUE;
  1565. }
  1566. // Higher Tx/Rx data.
  1567. if( pmlmepriv->LinkDetectInfo.NumRxOkInPeriod > 4000 ||
  1568. pmlmepriv->LinkDetectInfo.NumTxOkInPeriod > 4000 )
  1569. {
  1570. bHigherBusyTraffic = _TRUE;
  1571. if (pmlmepriv->LinkDetectInfo.NumRxOkInPeriod > pmlmepriv->LinkDetectInfo.NumTxOkInPeriod)
  1572. bHigherBusyRxTraffic = _TRUE;
  1573. else
  1574. bHigherBusyTxTraffic = _TRUE;
  1575. }
  1576. #ifdef CONFIG_FTP_PROTECT
  1577. DBG_871X("RX in period:%d, TX in period:%d, ftp_lock_flag:%d\n",
  1578. pmlmepriv->LinkDetectInfo.NumRxOkInPeriod,
  1579. pmlmepriv->LinkDetectInfo.NumTxOkInPeriod,
  1580. pmlmepriv->ftp_lock_flag);
  1581. bPktCount = pmlmepriv->LinkDetectInfo.NumRxOkInPeriod + pmlmepriv->LinkDetectInfo.NumTxOkInPeriod;
  1582. if (bPktCount > 20 && !pmlmepriv->ftp_lock_flag) {
  1583. pmlmepriv->ftp_lock_flag = 1;
  1584. rtw_lock_suspend();
  1585. } else if(bPktCount == 0 && pmlmepriv->ftp_lock_flag) {
  1586. pmlmepriv->ftp_lock_flag = 0;
  1587. rtw_unlock_suspend();
  1588. }
  1589. #endif //CONFIG_KEEP_FTP_TRANSMIT
  1590. #ifdef CONFIG_TDLS
  1591. #ifdef CONFIG_TDLS_AUTOSETUP
  1592. if( ( ptdlsinfo->watchdog_count % TDLS_WATCHDOG_PERIOD ) == 0 ) //10 * 2sec, periodically sending
  1593. issue_tdls_dis_req( padapter, NULL );
  1594. ptdlsinfo->watchdog_count++;
  1595. #endif //CONFIG_TDLS_AUTOSETUP
  1596. #endif //CONFIG_TDLS
  1597. #ifdef CONFIG_LPS
  1598. #ifdef CONFIG_BT_COEXIST
  1599. if (BT_1Ant(padapter) == _FALSE)
  1600. #endif
  1601. {
  1602. // check traffic for powersaving.
  1603. if( ((pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod + pmlmepriv->LinkDetectInfo.NumTxOkInPeriod) > 8 ) ||
  1604. (pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod > 2) )
  1605. {
  1606. //DBG_871X("Tx = %d, Rx = %d \n",pmlmepriv->LinkDetectInfo.NumTxOkInPeriod,pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod);
  1607. bEnterPS= _FALSE;
  1608. }
  1609. else
  1610. {
  1611. bEnterPS= _TRUE;
  1612. }
  1613. // LeisurePS only work in infra mode.
  1614. if(bEnterPS)
  1615. {
  1616. LPS_Enter(padapter);
  1617. }
  1618. else
  1619. {
  1620. LPS_Leave(padapter);
  1621. }
  1622. }
  1623. #endif // CONFIG_LPS
  1624. }
  1625. else
  1626. {
  1627. #ifdef CONFIG_LPS
  1628. LPS_Leave(padapter);
  1629. #endif
  1630. }
  1631. pmlmepriv->LinkDetectInfo.NumRxOkInPeriod = 0;
  1632. pmlmepriv->LinkDetectInfo.NumTxOkInPeriod = 0;
  1633. pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod = 0;
  1634. pmlmepriv->LinkDetectInfo.bBusyTraffic = bBusyTraffic;
  1635. pmlmepriv->LinkDetectInfo.bTxBusyTraffic = bTxBusyTraffic;
  1636. pmlmepriv->LinkDetectInfo.bRxBusyTraffic = bRxBusyTraffic;
  1637. pmlmepriv->LinkDetectInfo.bHigherBusyTraffic = bHigherBusyTraffic;
  1638. pmlmepriv->LinkDetectInfo.bHigherBusyRxTraffic = bHigherBusyRxTraffic;
  1639. pmlmepriv->LinkDetectInfo.bHigherBusyTxTraffic = bHigherBusyTxTraffic;
  1640. }
  1641. void dynamic_chk_wk_hdl(_adapter *padapter, u8 *pbuf, int sz);
  1642. void dynamic_chk_wk_hdl(_adapter *padapter, u8 *pbuf, int sz)
  1643. {
  1644. struct mlme_priv *pmlmepriv;
  1645. padapter = (_adapter *)pbuf;
  1646. pmlmepriv = &(padapter->mlmepriv);
  1647. #ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
  1648. #ifdef CONFIG_AP_MODE
  1649. if(check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
  1650. {
  1651. expire_timeout_chk(padapter);
  1652. }
  1653. #endif
  1654. #endif //CONFIG_ACTIVE_KEEP_ALIVE_CHECK
  1655. #ifdef DBG_CONFIG_ERROR_DETECT
  1656. rtw_hal_sreset_xmit_status_check(padapter);
  1657. #endif
  1658. //if(check_fwstate(pmlmepriv, _FW_UNDER_LINKING|_FW_UNDER_SURVEY)==_FALSE)
  1659. {
  1660. linked_status_chk(padapter);
  1661. traffic_status_watchdog(padapter);
  1662. }
  1663. rtw_hal_dm_watchdog(padapter);
  1664. //check_hw_pbc(padapter, pdrvextra_cmd->pbuf, pdrvextra_cmd->type_size);
  1665. #ifdef CONFIG_BT_COEXIST
  1666. //
  1667. // BT-Coexist
  1668. //
  1669. BT_CoexistMechanism(padapter);
  1670. #endif
  1671. }
  1672. #ifdef CONFIG_LPS
  1673. void lps_ctrl_wk_hdl(_adapter *padapter, u8 lps_ctrl_type);
  1674. void lps_ctrl_wk_hdl(_adapter *padapter, u8 lps_ctrl_type)
  1675. {
  1676. struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
  1677. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1678. u8 mstatus;
  1679. _func_enter_;
  1680. if((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE)
  1681. || (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == _TRUE))
  1682. {
  1683. return;
  1684. }
  1685. switch(lps_ctrl_type)
  1686. {
  1687. case LPS_CTRL_SCAN:
  1688. //DBG_871X("LPS_CTRL_SCAN \n");
  1689. #ifdef CONFIG_BT_COEXIST
  1690. BT_WifiScanNotify(padapter, _TRUE);
  1691. if (BT_1Ant(padapter) == _FALSE)
  1692. #endif
  1693. {
  1694. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  1695. { //connect
  1696. LPS_Leave(padapter);
  1697. }
  1698. }
  1699. break;
  1700. case LPS_CTRL_JOINBSS:
  1701. //DBG_871X("LPS_CTRL_JOINBSS \n");
  1702. LPS_Leave(padapter);
  1703. break;
  1704. case LPS_CTRL_CONNECT:
  1705. //DBG_871X("LPS_CTRL_CONNECT \n");
  1706. mstatus = 1;//connect
  1707. // Reset LPS Setting
  1708. padapter->pwrctrlpriv.LpsIdleCount = 0;
  1709. rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_JOINBSSRPT, (u8 *)(&mstatus));
  1710. #ifdef CONFIG_BT_COEXIST
  1711. BT_WifiMediaStatusNotify(padapter, mstatus);
  1712. #endif
  1713. break;
  1714. case LPS_CTRL_DISCONNECT:
  1715. //DBG_871X("LPS_CTRL_DISCONNECT \n");
  1716. mstatus = 0;//disconnect
  1717. #ifdef CONFIG_BT_COEXIST
  1718. BT_WifiMediaStatusNotify(padapter, mstatus);
  1719. if (BT_1Ant(padapter) == _FALSE)
  1720. #endif
  1721. {
  1722. LPS_Leave(padapter);
  1723. }
  1724. rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_JOINBSSRPT, (u8 *)(&mstatus));
  1725. break;
  1726. case LPS_CTRL_SPECIAL_PACKET:
  1727. //DBG_871X("LPS_CTRL_SPECIAL_PACKET \n");
  1728. pwrpriv->DelayLPSLastTimeStamp = rtw_get_current_time();
  1729. #ifdef CONFIG_BT_COEXIST
  1730. BT_SpecialPacketNotify(padapter);
  1731. if (BT_1Ant(padapter) == _FALSE)
  1732. #endif
  1733. {
  1734. LPS_Leave(padapter);
  1735. }
  1736. break;
  1737. case LPS_CTRL_LEAVE:
  1738. //DBG_871X("LPS_CTRL_LEAVE \n");
  1739. #ifdef CONFIG_BT_COEXIST
  1740. BT_LpsLeave(padapter);
  1741. if (BT_1Ant(padapter) == _FALSE)
  1742. #endif
  1743. {
  1744. LPS_Leave(padapter);
  1745. }
  1746. break;
  1747. default:
  1748. break;
  1749. }
  1750. _func_exit_;
  1751. }
  1752. u8 rtw_lps_ctrl_wk_cmd(_adapter*padapter, u8 lps_ctrl_type, u8 enqueue)
  1753. {
  1754. struct cmd_obj *ph2c;
  1755. struct drvextra_cmd_parm *pdrvextra_cmd_parm;
  1756. struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
  1757. //struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv;
  1758. u8 res = _SUCCESS;
  1759. _func_enter_;
  1760. //if(!pwrctrlpriv->bLeisurePs)
  1761. // return res;
  1762. #ifdef CONFIG_CONCURRENT_MODE
  1763. if (padapter->iface_type != IFACE_PORT0)
  1764. return res;
  1765. #endif
  1766. if(enqueue)
  1767. {
  1768. ph2c = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  1769. if(ph2c==NULL){
  1770. res= _FAIL;
  1771. goto exit;
  1772. }
  1773. pdrvextra_cmd_parm = (struct drvextra_cmd_parm*)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
  1774. if(pdrvextra_cmd_parm==NULL){
  1775. rtw_mfree((unsigned char *)ph2c, sizeof(struct cmd_obj));
  1776. res= _FAIL;
  1777. goto exit;
  1778. }
  1779. pdrvextra_cmd_parm->ec_id = LPS_CTRL_WK_CID;
  1780. pdrvextra_cmd_parm->type_size = lps_ctrl_type;
  1781. pdrvextra_cmd_parm->pbuf = NULL;
  1782. init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
  1783. res = rtw_enqueue_cmd(pcmdpriv, ph2c);
  1784. }
  1785. else
  1786. {
  1787. lps_ctrl_wk_hdl(padapter, lps_ctrl_type);
  1788. }
  1789. exit:
  1790. _func_exit_;
  1791. return res;
  1792. }
  1793. #endif
  1794. #if (RATE_ADAPTIVE_SUPPORT==1)
  1795. void rpt_timer_setting_wk_hdl(_adapter *padapter, u16 minRptTime)
  1796. {
  1797. rtw_hal_set_hwreg(padapter, HW_VAR_RPT_TIMER_SETTING, (u8 *)(&minRptTime));
  1798. }
  1799. u8 rtw_rpt_timer_cfg_cmd(_adapter*padapter, u16 minRptTime)
  1800. {
  1801. struct cmd_obj *ph2c;
  1802. struct drvextra_cmd_parm *pdrvextra_cmd_parm;
  1803. struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
  1804. u8 res = _SUCCESS;
  1805. _func_enter_;
  1806. ph2c = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  1807. if(ph2c==NULL){
  1808. res= _FAIL;
  1809. goto exit;
  1810. }
  1811. pdrvextra_cmd_parm = (struct drvextra_cmd_parm*)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
  1812. if(pdrvextra_cmd_parm==NULL){
  1813. rtw_mfree((unsigned char *)ph2c, sizeof(struct cmd_obj));
  1814. res= _FAIL;
  1815. goto exit;
  1816. }
  1817. pdrvextra_cmd_parm->ec_id = RTP_TIMER_CFG_WK_CID;
  1818. pdrvextra_cmd_parm->type_size = minRptTime;
  1819. pdrvextra_cmd_parm->pbuf = NULL;
  1820. init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
  1821. res = rtw_enqueue_cmd(pcmdpriv, ph2c);
  1822. exit:
  1823. _func_exit_;
  1824. return res;
  1825. }
  1826. #endif
  1827. #ifdef CONFIG_ANTENNA_DIVERSITY
  1828. void antenna_select_wk_hdl(_adapter *padapter, u8 antenna)
  1829. {
  1830. rtw_hal_set_hwreg(padapter, HW_VAR_ANTENNA_DIVERSITY_SELECT, (u8 *)(&antenna));
  1831. }
  1832. u8 rtw_antenna_select_cmd(_adapter*padapter, u8 antenna,u8 enqueue)
  1833. {
  1834. struct cmd_obj *ph2c;
  1835. struct drvextra_cmd_parm *pdrvextra_cmd_parm;
  1836. struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
  1837. u8 bSupportAntDiv = _FALSE;
  1838. u8 res = _SUCCESS;
  1839. _func_enter_;
  1840. rtw_hal_get_def_var(padapter, HAL_DEF_IS_SUPPORT_ANT_DIV, &(bSupportAntDiv));
  1841. if(_FALSE == bSupportAntDiv ) return res;
  1842. if(_TRUE == enqueue)
  1843. {
  1844. ph2c = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  1845. if(ph2c==NULL){
  1846. res= _FAIL;
  1847. goto exit;
  1848. }
  1849. pdrvextra_cmd_parm = (struct drvextra_cmd_parm*)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
  1850. if(pdrvextra_cmd_parm==NULL){
  1851. rtw_mfree((unsigned char *)ph2c, sizeof(struct cmd_obj));
  1852. res= _FAIL;
  1853. goto exit;
  1854. }
  1855. pdrvextra_cmd_parm->ec_id = ANT_SELECT_WK_CID;
  1856. pdrvextra_cmd_parm->type_size = antenna;
  1857. pdrvextra_cmd_parm->pbuf = NULL;
  1858. init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
  1859. res = rtw_enqueue_cmd(pcmdpriv, ph2c);
  1860. }
  1861. else{
  1862. antenna_select_wk_hdl(padapter,antenna );
  1863. }
  1864. exit:
  1865. _func_exit_;
  1866. return res;
  1867. }
  1868. #endif
  1869. void power_saving_wk_hdl(_adapter *padapter, u8 *pbuf, int sz);
  1870. void power_saving_wk_hdl(_adapter *padapter, u8 *pbuf, int sz)
  1871. {
  1872. rtw_ps_processor(padapter);
  1873. }
  1874. #ifdef CONFIG_P2P
  1875. u8 p2p_protocol_wk_cmd(_adapter*padapter, int intCmdType )
  1876. {
  1877. struct cmd_obj *ph2c;
  1878. struct drvextra_cmd_parm *pdrvextra_cmd_parm;
  1879. struct wifidirect_info *pwdinfo= &(padapter->wdinfo);
  1880. struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
  1881. u8 res = _SUCCESS;
  1882. _func_enter_;
  1883. if(rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  1884. {
  1885. return res;
  1886. }
  1887. ph2c = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  1888. if(ph2c==NULL){
  1889. res= _FAIL;
  1890. goto exit;
  1891. }
  1892. pdrvextra_cmd_parm = (struct drvextra_cmd_parm*)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
  1893. if(pdrvextra_cmd_parm==NULL){
  1894. rtw_mfree((unsigned char *)ph2c, sizeof(struct cmd_obj));
  1895. res= _FAIL;
  1896. goto exit;
  1897. }
  1898. pdrvextra_cmd_parm->ec_id = P2P_PROTO_WK_CID;
  1899. pdrvextra_cmd_parm->type_size = intCmdType; // As the command tppe.
  1900. pdrvextra_cmd_parm->pbuf = NULL; // Must be NULL here
  1901. init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
  1902. res = rtw_enqueue_cmd(pcmdpriv, ph2c);
  1903. exit:
  1904. _func_exit_;
  1905. return res;
  1906. }
  1907. #endif //CONFIG_P2P
  1908. u8 rtw_ps_cmd(_adapter*padapter)
  1909. {
  1910. struct cmd_obj *ppscmd;
  1911. struct drvextra_cmd_parm *pdrvextra_cmd_parm;
  1912. struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
  1913. u8 res = _SUCCESS;
  1914. _func_enter_;
  1915. #ifdef CONFIG_CONCURRENT_MODE
  1916. if (padapter->adapter_type != PRIMARY_ADAPTER)
  1917. goto exit;
  1918. #endif
  1919. ppscmd = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  1920. if(ppscmd==NULL){
  1921. res= _FAIL;
  1922. goto exit;
  1923. }
  1924. pdrvextra_cmd_parm = (struct drvextra_cmd_parm*)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
  1925. if(pdrvextra_cmd_parm==NULL){
  1926. rtw_mfree((unsigned char *)ppscmd, sizeof(struct cmd_obj));
  1927. res= _FAIL;
  1928. goto exit;
  1929. }
  1930. pdrvextra_cmd_parm->ec_id = POWER_SAVING_CTRL_WK_CID;
  1931. pdrvextra_cmd_parm->pbuf = NULL;
  1932. init_h2fwcmd_w_parm_no_rsp(ppscmd, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
  1933. res = rtw_enqueue_cmd(pcmdpriv, ppscmd);
  1934. exit:
  1935. _func_exit_;
  1936. return res;
  1937. }
  1938. #ifdef CONFIG_AP_MODE
  1939. static void rtw_chk_hi_queue_hdl(_adapter *padapter)
  1940. {
  1941. int cnt=0;
  1942. struct sta_info *psta_bmc;
  1943. struct sta_priv *pstapriv = &padapter->stapriv;
  1944. psta_bmc = rtw_get_bcmc_stainfo(padapter);
  1945. if(!psta_bmc)
  1946. return;
  1947. if(psta_bmc->sleepq_len==0)
  1948. {
  1949. u8 val = 0;
  1950. //while((rtw_read32(padapter, 0x414)&0x00ffff00)!=0)
  1951. //while((rtw_read32(padapter, 0x414)&0x0000ff00)!=0)
  1952. rtw_hal_get_hwreg(padapter, HW_VAR_CHK_HI_QUEUE_EMPTY, &val);
  1953. while(_FALSE == val)
  1954. {
  1955. rtw_msleep_os(100);
  1956. cnt++;
  1957. if(cnt>10)
  1958. break;
  1959. rtw_hal_get_hwreg(padapter, HW_VAR_CHK_HI_QUEUE_EMPTY, &val);
  1960. }
  1961. if(cnt<=10)
  1962. {
  1963. pstapriv->tim_bitmap &= ~BIT(0);
  1964. pstapriv->sta_dz_bitmap &= ~BIT(0);
  1965. update_beacon(padapter, _TIM_IE_, NULL, _FALSE);
  1966. }
  1967. else //re check again
  1968. {
  1969. rtw_chk_hi_queue_cmd(padapter);
  1970. }
  1971. }
  1972. }
  1973. u8 rtw_chk_hi_queue_cmd(_adapter*padapter)
  1974. {
  1975. struct cmd_obj *ph2c;
  1976. struct drvextra_cmd_parm *pdrvextra_cmd_parm;
  1977. struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
  1978. u8 res = _SUCCESS;
  1979. ph2c = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  1980. if(ph2c==NULL){
  1981. res= _FAIL;
  1982. goto exit;
  1983. }
  1984. pdrvextra_cmd_parm = (struct drvextra_cmd_parm*)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
  1985. if(pdrvextra_cmd_parm==NULL){
  1986. rtw_mfree((unsigned char *)ph2c, sizeof(struct cmd_obj));
  1987. res= _FAIL;
  1988. goto exit;
  1989. }
  1990. pdrvextra_cmd_parm->ec_id = CHECK_HIQ_WK_CID;
  1991. pdrvextra_cmd_parm->type_size = 0;
  1992. pdrvextra_cmd_parm->pbuf = NULL;
  1993. init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
  1994. res = rtw_enqueue_cmd(pcmdpriv, ph2c);
  1995. exit:
  1996. return res;
  1997. }
  1998. #endif
  1999. u8 rtw_c2h_wk_cmd(PADAPTER padapter, u8 *c2h_evt)
  2000. {
  2001. struct cmd_obj *ph2c;
  2002. struct drvextra_cmd_parm *pdrvextra_cmd_parm;
  2003. struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
  2004. u8 res = _SUCCESS;
  2005. ph2c = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  2006. if (ph2c == NULL) {
  2007. res = _FAIL;
  2008. goto exit;
  2009. }
  2010. pdrvextra_cmd_parm = (struct drvextra_cmd_parm*)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
  2011. if (pdrvextra_cmd_parm == NULL) {
  2012. rtw_mfree((u8*)ph2c, sizeof(struct cmd_obj));
  2013. res = _FAIL;
  2014. goto exit;
  2015. }
  2016. pdrvextra_cmd_parm->ec_id = C2H_WK_CID;
  2017. pdrvextra_cmd_parm->type_size = c2h_evt?16:0;
  2018. pdrvextra_cmd_parm->pbuf = c2h_evt;
  2019. init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
  2020. res = rtw_enqueue_cmd(pcmdpriv, ph2c);
  2021. exit:
  2022. return res;
  2023. }
  2024. s32 c2h_evt_hdl(_adapter *adapter, struct c2h_evt_hdr *c2h_evt, c2h_id_filter filter)
  2025. {
  2026. s32 ret = _FAIL;
  2027. u8 buf[16];
  2028. if (!c2h_evt) {
  2029. /* No c2h event in cmd_obj, read c2h event before handling*/
  2030. if (c2h_evt_read(adapter, buf) == _SUCCESS) {
  2031. c2h_evt = (struct c2h_evt_hdr *)buf;
  2032. if (filter && filter(c2h_evt->id) == _FALSE)
  2033. goto exit;
  2034. ret = rtw_hal_c2h_handler(adapter, c2h_evt);
  2035. }
  2036. } else {
  2037. if (filter && filter(c2h_evt->id) == _FALSE)
  2038. goto exit;
  2039. ret = rtw_hal_c2h_handler(adapter, c2h_evt);
  2040. }
  2041. exit:
  2042. return ret;
  2043. }
  2044. #ifdef CONFIG_C2H_WK
  2045. static void c2h_wk_callback(_workitem *work)
  2046. {
  2047. struct evt_priv *evtpriv = container_of(work, struct evt_priv, c2h_wk);
  2048. _adapter *adapter = container_of(evtpriv, _adapter, evtpriv);
  2049. struct c2h_evt_hdr *c2h_evt;
  2050. c2h_id_filter ccx_id_filter = rtw_hal_c2h_id_filter_ccx(adapter);
  2051. evtpriv->c2h_wk_alive = _TRUE;
  2052. while (!rtw_cbuf_empty(evtpriv->c2h_queue)) {
  2053. if ((c2h_evt = (struct c2h_evt_hdr *)rtw_cbuf_pop(evtpriv->c2h_queue)) != NULL) {
  2054. /* This C2H event is read, clear it */
  2055. c2h_evt_clear(adapter);
  2056. } else if ((c2h_evt = (struct c2h_evt_hdr *)rtw_malloc(16)) != NULL) {
  2057. /* This C2H event is not read, read & clear now */
  2058. if (c2h_evt_read(adapter, (u8*)c2h_evt) != _SUCCESS)
  2059. continue;
  2060. }
  2061. /* Special pointer to trigger c2h_evt_clear only */
  2062. if ((void *)c2h_evt == (void *)evtpriv)
  2063. continue;
  2064. if (!c2h_evt_exist(c2h_evt)) {
  2065. rtw_mfree((u8*)c2h_evt, 16);
  2066. continue;
  2067. }
  2068. if (ccx_id_filter(c2h_evt->id) == _TRUE) {
  2069. /* Handle CCX report here */
  2070. rtw_hal_c2h_handler(adapter, c2h_evt);
  2071. rtw_mfree((u8*)c2h_evt, 16);
  2072. } else {
  2073. /* Enqueue into cmd_thread for others */
  2074. rtw_c2h_wk_cmd(adapter, (u8 *)c2h_evt);
  2075. }
  2076. }
  2077. evtpriv->c2h_wk_alive = _FALSE;
  2078. }
  2079. #endif
  2080. u8 rtw_drvextra_cmd_hdl(_adapter *padapter, unsigned char *pbuf)
  2081. {
  2082. struct drvextra_cmd_parm *pdrvextra_cmd;
  2083. if(!pbuf)
  2084. return H2C_PARAMETERS_ERROR;
  2085. pdrvextra_cmd = (struct drvextra_cmd_parm*)pbuf;
  2086. switch(pdrvextra_cmd->ec_id)
  2087. {
  2088. case DYNAMIC_CHK_WK_CID:
  2089. dynamic_chk_wk_hdl(padapter, pdrvextra_cmd->pbuf, pdrvextra_cmd->type_size);
  2090. break;
  2091. case POWER_SAVING_CTRL_WK_CID:
  2092. power_saving_wk_hdl(padapter, pdrvextra_cmd->pbuf, pdrvextra_cmd->type_size);
  2093. break;
  2094. #ifdef CONFIG_LPS
  2095. case LPS_CTRL_WK_CID:
  2096. lps_ctrl_wk_hdl(padapter, (u8)pdrvextra_cmd->type_size);
  2097. break;
  2098. #endif
  2099. #if (RATE_ADAPTIVE_SUPPORT==1)
  2100. case RTP_TIMER_CFG_WK_CID:
  2101. rpt_timer_setting_wk_hdl(padapter, pdrvextra_cmd->type_size);
  2102. break;
  2103. #endif
  2104. #ifdef CONFIG_ANTENNA_DIVERSITY
  2105. case ANT_SELECT_WK_CID:
  2106. antenna_select_wk_hdl(padapter, pdrvextra_cmd->type_size);
  2107. break;
  2108. #endif
  2109. #ifdef CONFIG_P2P_PS
  2110. case P2P_PS_WK_CID:
  2111. p2p_ps_wk_hdl(padapter, pdrvextra_cmd->type_size);
  2112. break;
  2113. #endif // CONFIG_P2P_PS
  2114. case P2P_PROTO_WK_CID:
  2115. // Commented by Albert 2011/07/01
  2116. // I used the type_size as the type command
  2117. p2p_protocol_wk_hdl( padapter, pdrvextra_cmd->type_size );
  2118. break;
  2119. #ifdef CONFIG_AP_MODE
  2120. case CHECK_HIQ_WK_CID:
  2121. rtw_chk_hi_queue_hdl(padapter);
  2122. break;
  2123. #endif //CONFIG_AP_MODE
  2124. #ifdef CONFIG_INTEL_WIDI
  2125. case INTEl_WIDI_WK_CID:
  2126. intel_widi_wk_hdl(padapter, pdrvextra_cmd->type_size, pdrvextra_cmd->pbuf);
  2127. break;
  2128. #endif //CONFIG_INTEL_WIDI
  2129. case C2H_WK_CID:
  2130. c2h_evt_hdl(padapter, (struct c2h_evt_hdr *)pdrvextra_cmd->pbuf, NULL);
  2131. break;
  2132. default:
  2133. break;
  2134. }
  2135. if (pdrvextra_cmd->pbuf && pdrvextra_cmd->type_size>0)
  2136. {
  2137. rtw_mfree(pdrvextra_cmd->pbuf, pdrvextra_cmd->type_size);
  2138. }
  2139. return H2C_SUCCESS;
  2140. }
  2141. void rtw_survey_cmd_callback(_adapter* padapter , struct cmd_obj *pcmd)
  2142. {
  2143. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  2144. _func_enter_;
  2145. if(pcmd->res == H2C_DROPPED)
  2146. {
  2147. //TODO: cancel timer and do timeout handler directly...
  2148. //need to make timeout handlerOS independent
  2149. _set_timer(&pmlmepriv->scan_to_timer, 1);
  2150. }
  2151. else if (pcmd->res != H2C_SUCCESS) {
  2152. _set_timer(&pmlmepriv->scan_to_timer, 1);
  2153. RT_TRACE(_module_rtl871x_cmd_c_,_drv_err_,("\n ********Error: MgntActrtw_set_802_11_bssid_LIST_SCAN Fail ************\n\n."));
  2154. }
  2155. // free cmd
  2156. rtw_free_cmd_obj(pcmd);
  2157. _func_exit_;
  2158. }
  2159. void rtw_disassoc_cmd_callback(_adapter* padapter, struct cmd_obj *pcmd)
  2160. {
  2161. _irqL irqL;
  2162. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  2163. _func_enter_;
  2164. if (pcmd->res != H2C_SUCCESS)
  2165. {
  2166. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  2167. set_fwstate(pmlmepriv, _FW_LINKED);
  2168. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  2169. RT_TRACE(_module_rtl871x_cmd_c_,_drv_err_,("\n ***Error: disconnect_cmd_callback Fail ***\n."));
  2170. goto exit;
  2171. }
  2172. #ifdef CONFIG_BR_EXT
  2173. else //clear bridge database
  2174. nat25_db_cleanup(padapter);
  2175. #endif //CONFIG_BR_EXT
  2176. // free cmd
  2177. rtw_free_cmd_obj(pcmd);
  2178. exit:
  2179. _func_exit_;
  2180. }
  2181. void rtw_joinbss_cmd_callback(_adapter* padapter, struct cmd_obj *pcmd)
  2182. {
  2183. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  2184. _func_enter_;
  2185. if(pcmd->res == H2C_DROPPED)
  2186. {
  2187. //TODO: cancel timer and do timeout handler directly...
  2188. //need to make timeout handlerOS independent
  2189. _set_timer(&pmlmepriv->assoc_timer, 1);
  2190. }
  2191. else if(pcmd->res != H2C_SUCCESS)
  2192. {
  2193. RT_TRACE(_module_rtl871x_cmd_c_,_drv_err_,("********Error:rtw_select_and_join_from_scanned_queue Wait Sema Fail ************\n"));
  2194. _set_timer(&pmlmepriv->assoc_timer, 1);
  2195. }
  2196. rtw_free_cmd_obj(pcmd);
  2197. _func_exit_;
  2198. }
  2199. void rtw_createbss_cmd_callback(_adapter *padapter, struct cmd_obj *pcmd)
  2200. {
  2201. _irqL irqL;
  2202. u8 timer_cancelled;
  2203. struct sta_info *psta = NULL;
  2204. struct wlan_network *pwlan = NULL;
  2205. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  2206. WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX *)pcmd->parmbuf;
  2207. struct wlan_network *tgt_network = &(pmlmepriv->cur_network);
  2208. _func_enter_;
  2209. if((pcmd->res != H2C_SUCCESS))
  2210. {
  2211. RT_TRACE(_module_rtl871x_cmd_c_,_drv_err_,("\n ********Error: rtw_createbss_cmd_callback Fail ************\n\n."));
  2212. _set_timer(&pmlmepriv->assoc_timer, 1 );
  2213. }
  2214. _cancel_timer(&pmlmepriv->assoc_timer, &timer_cancelled);
  2215. #ifdef CONFIG_FW_MLMLE
  2216. //endian_convert
  2217. pnetwork->Length = le32_to_cpu(pnetwork->Length);
  2218. pnetwork->Ssid.SsidLength = le32_to_cpu(pnetwork->Ssid.SsidLength);
  2219. pnetwork->Privacy =le32_to_cpu(pnetwork->Privacy);
  2220. pnetwork->Rssi = le32_to_cpu(pnetwork->Rssi);
  2221. pnetwork->NetworkTypeInUse =le32_to_cpu(pnetwork->NetworkTypeInUse);
  2222. pnetwork->Configuration.ATIMWindow = le32_to_cpu(pnetwork->Configuration.ATIMWindow);
  2223. //pnetwork->Configuration.BeaconPeriod = le32_to_cpu(pnetwork->Configuration.BeaconPeriod);
  2224. pnetwork->Configuration.DSConfig =le32_to_cpu(pnetwork->Configuration.DSConfig);
  2225. pnetwork->Configuration.FHConfig.DwellTime=le32_to_cpu(pnetwork->Configuration.FHConfig.DwellTime);
  2226. pnetwork->Configuration.FHConfig.HopPattern=le32_to_cpu(pnetwork->Configuration.FHConfig.HopPattern);
  2227. pnetwork->Configuration.FHConfig.HopSet=le32_to_cpu(pnetwork->Configuration.FHConfig.HopSet);
  2228. pnetwork->Configuration.FHConfig.Length=le32_to_cpu(pnetwork->Configuration.FHConfig.Length);
  2229. pnetwork->Configuration.Length = le32_to_cpu(pnetwork->Configuration.Length);
  2230. pnetwork->InfrastructureMode = le32_to_cpu(pnetwork->InfrastructureMode);
  2231. pnetwork->IELength = le32_to_cpu(pnetwork->IELength);
  2232. #endif
  2233. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  2234. if(check_fwstate(pmlmepriv, WIFI_AP_STATE) )
  2235. {
  2236. psta = rtw_get_stainfo(&padapter->stapriv, pnetwork->MacAddress);
  2237. if(!psta)
  2238. {
  2239. psta = rtw_alloc_stainfo(&padapter->stapriv, pnetwork->MacAddress);
  2240. if (psta == NULL)
  2241. {
  2242. RT_TRACE(_module_rtl871x_cmd_c_,_drv_err_,("\nCan't alloc sta_info when createbss_cmd_callback\n"));
  2243. goto createbss_cmd_fail ;
  2244. }
  2245. }
  2246. rtw_indicate_connect( padapter);
  2247. }
  2248. else
  2249. {
  2250. _irqL irqL;
  2251. pwlan = _rtw_alloc_network(pmlmepriv);
  2252. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  2253. if ( pwlan == NULL)
  2254. {
  2255. pwlan = rtw_get_oldest_wlan_network(&pmlmepriv->scanned_queue);
  2256. if( pwlan == NULL)
  2257. {
  2258. RT_TRACE(_module_rtl871x_cmd_c_,_drv_err_,("\n Error: can't get pwlan in rtw_joinbss_event_callback \n"));
  2259. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  2260. goto createbss_cmd_fail;
  2261. }
  2262. pwlan->last_scanned = rtw_get_current_time();
  2263. }
  2264. else
  2265. {
  2266. rtw_list_insert_tail(&(pwlan->list), &pmlmepriv->scanned_queue.queue);
  2267. }
  2268. pnetwork->Length = get_WLAN_BSSID_EX_sz(pnetwork);
  2269. _rtw_memcpy(&(pwlan->network), pnetwork, pnetwork->Length);
  2270. //pwlan->fixed = _TRUE;
  2271. //rtw_list_insert_tail(&(pwlan->list), &pmlmepriv->scanned_queue.queue);
  2272. // copy pdev_network information to pmlmepriv->cur_network
  2273. _rtw_memcpy(&tgt_network->network, pnetwork, (get_WLAN_BSSID_EX_sz(pnetwork)));
  2274. // reset DSConfig
  2275. //tgt_network->network.Configuration.DSConfig = (u32)rtw_ch2freq(pnetwork->Configuration.DSConfig);
  2276. _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
  2277. #if 0
  2278. if((pmlmepriv->fw_state) & WIFI_AP_STATE)
  2279. {
  2280. psta = rtw_alloc_stainfo(&padapter->stapriv, pnetwork->MacAddress);
  2281. if (psta == NULL) { // for AP Mode & Adhoc Master Mode
  2282. RT_TRACE(_module_rtl871x_cmd_c_,_drv_err_,("\nCan't alloc sta_info when createbss_cmd_callback\n"));
  2283. goto createbss_cmd_fail ;
  2284. }
  2285. rtw_indicate_connect( padapter);
  2286. }
  2287. else {
  2288. //rtw_indicate_disconnect(dev);
  2289. }
  2290. #endif
  2291. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  2292. // we will set _FW_LINKED when there is one more sat to join us (rtw_stassoc_event_callback)
  2293. }
  2294. createbss_cmd_fail:
  2295. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  2296. rtw_free_cmd_obj(pcmd);
  2297. _func_exit_;
  2298. }
  2299. void rtw_setstaKey_cmdrsp_callback(_adapter* padapter , struct cmd_obj *pcmd)
  2300. {
  2301. struct sta_priv * pstapriv = &padapter->stapriv;
  2302. struct set_stakey_rsp* psetstakey_rsp = (struct set_stakey_rsp*) (pcmd->rsp);
  2303. struct sta_info* psta = rtw_get_stainfo(pstapriv, psetstakey_rsp->addr);
  2304. _func_enter_;
  2305. if(psta==NULL)
  2306. {
  2307. RT_TRACE(_module_rtl871x_cmd_c_,_drv_err_,("\nERROR: rtw_setstaKey_cmdrsp_callback => can't get sta_info \n\n"));
  2308. goto exit;
  2309. }
  2310. //psta->aid = psta->mac_id = psetstakey_rsp->keyid; //CAM_ID(CAM_ENTRY)
  2311. exit:
  2312. rtw_free_cmd_obj(pcmd);
  2313. _func_exit_;
  2314. }
  2315. void rtw_setassocsta_cmdrsp_callback(_adapter* padapter, struct cmd_obj *pcmd)
  2316. {
  2317. _irqL irqL;
  2318. struct sta_priv * pstapriv = &padapter->stapriv;
  2319. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  2320. struct set_assocsta_parm* passocsta_parm = (struct set_assocsta_parm*)(pcmd->parmbuf);
  2321. struct set_assocsta_rsp* passocsta_rsp = (struct set_assocsta_rsp*) (pcmd->rsp);
  2322. struct sta_info* psta = rtw_get_stainfo(pstapriv, passocsta_parm->addr);
  2323. _func_enter_;
  2324. if(psta==NULL)
  2325. {
  2326. RT_TRACE(_module_rtl871x_cmd_c_,_drv_err_,("\nERROR: setassocsta_cmdrsp_callbac => can't get sta_info \n\n"));
  2327. goto exit;
  2328. }
  2329. psta->aid = psta->mac_id = passocsta_rsp->cam_id;
  2330. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  2331. if ((check_fwstate(pmlmepriv, WIFI_MP_STATE) == _TRUE) && (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == _TRUE))
  2332. _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
  2333. set_fwstate(pmlmepriv, _FW_LINKED);
  2334. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  2335. exit:
  2336. rtw_free_cmd_obj(pcmd);
  2337. _func_exit_;
  2338. }
  2339. void rtw_getrttbl_cmd_cmdrsp_callback(_adapter* padapter, struct cmd_obj *pcmd);
  2340. void rtw_getrttbl_cmd_cmdrsp_callback(_adapter* padapter, struct cmd_obj *pcmd)
  2341. {
  2342. _func_enter_;
  2343. rtw_free_cmd_obj(pcmd);
  2344. #ifdef CONFIG_MP_INCLUDED
  2345. if (padapter->registrypriv.mp_mode == 1)
  2346. padapter->mppriv.workparam.bcompleted=_TRUE;
  2347. #endif
  2348. _func_exit_;
  2349. }