rtw_cmd.c 74 KB

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