rtw_ap.c 84 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180
  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_AP_C_
  21. #include <drv_types.h>
  22. #ifdef CONFIG_AP_MODE
  23. extern unsigned char RTW_WPA_OUI[];
  24. extern unsigned char WMM_OUI[];
  25. extern unsigned char WPS_OUI[];
  26. extern unsigned char P2P_OUI[];
  27. extern unsigned char WFD_OUI[];
  28. void init_mlme_ap_info(_adapter *padapter)
  29. {
  30. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  31. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  32. struct sta_priv *pstapriv = &padapter->stapriv;
  33. struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
  34. _rtw_spinlock_init(&pmlmepriv->bcn_update_lock);
  35. //for ACL
  36. _rtw_init_queue(&pacl_list->acl_node_q);
  37. //pmlmeext->bstart_bss = _FALSE;
  38. start_ap_mode(padapter);
  39. }
  40. void free_mlme_ap_info(_adapter *padapter)
  41. {
  42. _irqL irqL;
  43. struct sta_info *psta=NULL;
  44. struct sta_priv *pstapriv = &padapter->stapriv;
  45. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  46. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  47. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  48. //stop_ap_mode(padapter);
  49. pmlmepriv->update_bcn = _FALSE;
  50. pmlmeext->bstart_bss = _FALSE;
  51. rtw_sta_flush(padapter);
  52. pmlmeinfo->state = _HW_STATE_NOLINK_;
  53. //free_assoc_sta_resources
  54. rtw_free_all_stainfo(padapter);
  55. //free bc/mc sta_info
  56. psta = rtw_get_bcmc_stainfo(padapter);
  57. _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL);
  58. rtw_free_stainfo(padapter, psta);
  59. _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL);
  60. _rtw_spinlock_free(&pmlmepriv->bcn_update_lock);
  61. }
  62. static void update_BCNTIM(_adapter *padapter)
  63. {
  64. struct sta_priv *pstapriv = &padapter->stapriv;
  65. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  66. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  67. WLAN_BSSID_EX *pnetwork_mlmeext = &(pmlmeinfo->network);
  68. unsigned char *pie = pnetwork_mlmeext->IEs;
  69. //DBG_871X("%s\n", __FUNCTION__);
  70. //update TIM IE
  71. //if(pstapriv->tim_bitmap)
  72. if(_TRUE)
  73. {
  74. u8 *p, *dst_ie, *premainder_ie=NULL, *pbackup_remainder_ie=NULL;
  75. u16 tim_bitmap_le;
  76. uint offset, tmp_len, tim_ielen, tim_ie_offset, remainder_ielen;
  77. tim_bitmap_le = cpu_to_le16(pstapriv->tim_bitmap);
  78. p = rtw_get_ie(pie + _FIXED_IE_LENGTH_, _TIM_IE_, &tim_ielen, pnetwork_mlmeext->IELength - _FIXED_IE_LENGTH_);
  79. if (p != NULL && tim_ielen>0)
  80. {
  81. tim_ielen += 2;
  82. premainder_ie = p+tim_ielen;
  83. tim_ie_offset = (sint)(p -pie);
  84. remainder_ielen = pnetwork_mlmeext->IELength - tim_ie_offset - tim_ielen;
  85. //append TIM IE from dst_ie offset
  86. dst_ie = p;
  87. }
  88. else
  89. {
  90. tim_ielen = 0;
  91. //calucate head_len
  92. offset = _FIXED_IE_LENGTH_;
  93. /* get ssid_ie len */
  94. p = rtw_get_ie(pie + _BEACON_IE_OFFSET_, _SSID_IE_, &tmp_len, (pnetwork_mlmeext->IELength - _BEACON_IE_OFFSET_));
  95. if (p != NULL)
  96. offset += tmp_len+2;
  97. // get supported rates len
  98. p = rtw_get_ie(pie + _BEACON_IE_OFFSET_, _SUPPORTEDRATES_IE_, &tmp_len, (pnetwork_mlmeext->IELength - _BEACON_IE_OFFSET_));
  99. if (p != NULL)
  100. {
  101. offset += tmp_len+2;
  102. }
  103. //DS Parameter Set IE, len=3
  104. offset += 3;
  105. premainder_ie = pie + offset;
  106. remainder_ielen = pnetwork_mlmeext->IELength - offset - tim_ielen;
  107. //append TIM IE from offset
  108. dst_ie = pie + offset;
  109. }
  110. if(remainder_ielen>0)
  111. {
  112. pbackup_remainder_ie = rtw_malloc(remainder_ielen);
  113. if(pbackup_remainder_ie && premainder_ie)
  114. _rtw_memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
  115. }
  116. *dst_ie++=_TIM_IE_;
  117. if((pstapriv->tim_bitmap&0xff00) && (pstapriv->tim_bitmap&0x00fe))
  118. tim_ielen = 5;
  119. else
  120. tim_ielen = 4;
  121. *dst_ie++= tim_ielen;
  122. *dst_ie++=0;//DTIM count
  123. *dst_ie++=1;//DTIM peroid
  124. if(pstapriv->tim_bitmap&BIT(0))//for bc/mc frames
  125. *dst_ie++ = BIT(0);//bitmap ctrl
  126. else
  127. *dst_ie++ = 0;
  128. if(tim_ielen==4)
  129. {
  130. u8 pvb=0;
  131. if(pstapriv->tim_bitmap&0x00fe)
  132. pvb = (u8)tim_bitmap_le;
  133. else if(pstapriv->tim_bitmap&0xff00)
  134. pvb = (u8)(tim_bitmap_le>>8);
  135. else
  136. pvb = (u8)tim_bitmap_le;
  137. *dst_ie++ = pvb;
  138. }
  139. else if(tim_ielen==5)
  140. {
  141. _rtw_memcpy(dst_ie, &tim_bitmap_le, 2);
  142. dst_ie+=2;
  143. }
  144. //copy remainder IE
  145. if(pbackup_remainder_ie)
  146. {
  147. _rtw_memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
  148. rtw_mfree(pbackup_remainder_ie, remainder_ielen);
  149. }
  150. offset = (uint)(dst_ie - pie);
  151. pnetwork_mlmeext->IELength = offset + remainder_ielen;
  152. }
  153. #ifndef CONFIG_INTERRUPT_BASED_TXBCN
  154. #if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
  155. set_tx_beacon_cmd(padapter);
  156. #endif
  157. #endif //!CONFIG_INTERRUPT_BASED_TXBCN
  158. }
  159. void rtw_add_bcn_ie(_adapter *padapter, WLAN_BSSID_EX *pnetwork, u8 index, u8 *data, u8 len)
  160. {
  161. PNDIS_802_11_VARIABLE_IEs pIE;
  162. u8 bmatch = _FALSE;
  163. u8 *pie = pnetwork->IEs;
  164. u8 *p, *dst_ie, *premainder_ie=NULL, *pbackup_remainder_ie=NULL;
  165. u32 i, offset, ielen, ie_offset, remainder_ielen = 0;
  166. for (i = sizeof(NDIS_802_11_FIXED_IEs); i < pnetwork->IELength;)
  167. {
  168. pIE = (PNDIS_802_11_VARIABLE_IEs)(pnetwork->IEs + i);
  169. if (pIE->ElementID > index)
  170. {
  171. break;
  172. }
  173. else if(pIE->ElementID == index) // already exist the same IE
  174. {
  175. p = (u8 *)pIE;
  176. ielen = pIE->Length;
  177. bmatch = _TRUE;
  178. break;
  179. }
  180. p = (u8 *)pIE;
  181. ielen = pIE->Length;
  182. i += (pIE->Length + 2);
  183. }
  184. if (p != NULL && ielen>0)
  185. {
  186. ielen += 2;
  187. premainder_ie = p+ielen;
  188. ie_offset = (sint)(p -pie);
  189. remainder_ielen = pnetwork->IELength - ie_offset - ielen;
  190. if(bmatch)
  191. dst_ie = p;
  192. else
  193. dst_ie = (p+ielen);
  194. }
  195. if(remainder_ielen>0)
  196. {
  197. pbackup_remainder_ie = rtw_malloc(remainder_ielen);
  198. if(pbackup_remainder_ie && premainder_ie)
  199. _rtw_memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
  200. }
  201. *dst_ie++=index;
  202. *dst_ie++=len;
  203. _rtw_memcpy(dst_ie, data, len);
  204. dst_ie+=len;
  205. //copy remainder IE
  206. if(pbackup_remainder_ie)
  207. {
  208. _rtw_memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
  209. rtw_mfree(pbackup_remainder_ie, remainder_ielen);
  210. }
  211. offset = (uint)(dst_ie - pie);
  212. pnetwork->IELength = offset + remainder_ielen;
  213. }
  214. void rtw_remove_bcn_ie(_adapter *padapter, WLAN_BSSID_EX *pnetwork, u8 index)
  215. {
  216. u8 *p, *dst_ie, *premainder_ie=NULL, *pbackup_remainder_ie=NULL;
  217. uint offset, ielen, ie_offset, remainder_ielen = 0;
  218. u8 *pie = pnetwork->IEs;
  219. p = rtw_get_ie(pie + _FIXED_IE_LENGTH_, index, &ielen, pnetwork->IELength - _FIXED_IE_LENGTH_);
  220. if (p != NULL && ielen>0)
  221. {
  222. ielen += 2;
  223. premainder_ie = p+ielen;
  224. ie_offset = (sint)(p -pie);
  225. remainder_ielen = pnetwork->IELength - ie_offset - ielen;
  226. dst_ie = p;
  227. }
  228. if(remainder_ielen>0)
  229. {
  230. pbackup_remainder_ie = rtw_malloc(remainder_ielen);
  231. if(pbackup_remainder_ie && premainder_ie)
  232. _rtw_memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
  233. }
  234. //copy remainder IE
  235. if(pbackup_remainder_ie)
  236. {
  237. _rtw_memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
  238. rtw_mfree(pbackup_remainder_ie, remainder_ielen);
  239. }
  240. offset = (uint)(dst_ie - pie);
  241. pnetwork->IELength = offset + remainder_ielen;
  242. }
  243. u8 chk_sta_is_alive(struct sta_info *psta);
  244. u8 chk_sta_is_alive(struct sta_info *psta)
  245. {
  246. u8 ret = _FALSE;
  247. #ifdef DBG_EXPIRATION_CHK
  248. DBG_871X("sta:"MAC_FMT", rssi:%d, rx:"STA_PKTS_FMT", expire_to:%u, %s%ssq_len:%u\n"
  249. , MAC_ARG(psta->hwaddr)
  250. , psta->rssi_stat.UndecoratedSmoothedPWDB
  251. //, STA_RX_PKTS_ARG(psta)
  252. , STA_RX_PKTS_DIFF_ARG(psta)
  253. , psta->expire_to
  254. , psta->state&WIFI_SLEEP_STATE?"PS, ":""
  255. , psta->state&WIFI_STA_ALIVE_CHK_STATE?"SAC, ":""
  256. , psta->sleepq_len
  257. );
  258. #endif
  259. //if(sta_last_rx_pkts(psta) == sta_rx_pkts(psta))
  260. if((psta->sta_stats.last_rx_data_pkts + psta->sta_stats.last_rx_ctrl_pkts) == (psta->sta_stats.rx_data_pkts + psta->sta_stats.rx_ctrl_pkts))
  261. {
  262. #if 0
  263. if(psta->state&WIFI_SLEEP_STATE)
  264. ret = _TRUE;
  265. #endif
  266. }
  267. else
  268. {
  269. ret = _TRUE;
  270. }
  271. sta_update_last_rx_pkts(psta);
  272. return ret;
  273. }
  274. void expire_timeout_chk(_adapter *padapter)
  275. {
  276. _irqL irqL;
  277. _list *phead, *plist;
  278. u8 updated;
  279. struct sta_info *psta=NULL;
  280. struct sta_priv *pstapriv = &padapter->stapriv;
  281. u8 chk_alive_num = 0;
  282. char chk_alive_list[NUM_STA];
  283. int i;
  284. _enter_critical_bh(&pstapriv->auth_list_lock, &irqL);
  285. phead = &pstapriv->auth_list;
  286. plist = get_next(phead);
  287. //check auth_queue
  288. #ifdef DBG_EXPIRATION_CHK
  289. if (rtw_end_of_queue_search(phead, plist) == _FALSE) {
  290. DBG_871X(FUNC_NDEV_FMT" auth_list, cnt:%u\n"
  291. , FUNC_NDEV_ARG(padapter->pnetdev), pstapriv->auth_list_cnt);
  292. }
  293. #endif
  294. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE)
  295. {
  296. psta = LIST_CONTAINOR(plist, struct sta_info, auth_list);
  297. plist = get_next(plist);
  298. if(psta->expire_to>0)
  299. {
  300. psta->expire_to--;
  301. if (psta->expire_to == 0)
  302. {
  303. rtw_list_delete(&psta->auth_list);
  304. pstapriv->auth_list_cnt--;
  305. DBG_871X("auth expire %02X%02X%02X%02X%02X%02X\n",
  306. psta->hwaddr[0],psta->hwaddr[1],psta->hwaddr[2],psta->hwaddr[3],psta->hwaddr[4],psta->hwaddr[5]);
  307. _exit_critical_bh(&pstapriv->auth_list_lock, &irqL);
  308. _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL);
  309. rtw_free_stainfo(padapter, psta);
  310. _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL);
  311. _enter_critical_bh(&pstapriv->auth_list_lock, &irqL);
  312. }
  313. }
  314. }
  315. _exit_critical_bh(&pstapriv->auth_list_lock, &irqL);
  316. psta = NULL;
  317. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  318. phead = &pstapriv->asoc_list;
  319. plist = get_next(phead);
  320. //check asoc_queue
  321. #ifdef DBG_EXPIRATION_CHK
  322. if (rtw_end_of_queue_search(phead, plist) == _FALSE) {
  323. DBG_871X(FUNC_NDEV_FMT" asoc_list, cnt:%u\n"
  324. , FUNC_NDEV_ARG(padapter->pnetdev), pstapriv->asoc_list_cnt);
  325. }
  326. #endif
  327. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE)
  328. {
  329. psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
  330. plist = get_next(plist);
  331. #ifdef CONFIG_AUTO_AP_MODE
  332. if(psta->isrc)
  333. continue;
  334. #endif
  335. if (chk_sta_is_alive(psta) || !psta->expire_to) {
  336. psta->expire_to = pstapriv->expire_to;
  337. psta->keep_alive_trycnt = 0;
  338. #ifdef CONFIG_TX_MCAST2UNI
  339. psta->under_exist_checking = 0;
  340. #endif // CONFIG_TX_MCAST2UNI
  341. } else {
  342. psta->expire_to--;
  343. }
  344. #ifndef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
  345. #ifdef CONFIG_TX_MCAST2UNI
  346. #ifdef CONFIG_80211N_HT
  347. if ( (psta->flags & WLAN_STA_HT) && (psta->htpriv.agg_enable_bitmap || psta->under_exist_checking) ) {
  348. // check sta by delba(addba) for 11n STA
  349. // ToDo: use CCX report to check for all STAs
  350. //DBG_871X("asoc check by DELBA/ADDBA! (pstapriv->expire_to=%d s)(psta->expire_to=%d s), [%02x, %d]\n", pstapriv->expire_to*2, psta->expire_to*2, psta->htpriv.agg_enable_bitmap, psta->under_exist_checking);
  351. if ( psta->expire_to <= (pstapriv->expire_to - 50 ) ) {
  352. DBG_871X("asoc expire by DELBA/ADDBA! (%d s)\n", (pstapriv->expire_to-psta->expire_to)*2);
  353. psta->under_exist_checking = 0;
  354. psta->expire_to = 0;
  355. } else if ( psta->expire_to <= (pstapriv->expire_to - 3) && (psta->under_exist_checking==0)) {
  356. DBG_871X("asoc check by DELBA/ADDBA! (%d s)\n", (pstapriv->expire_to-psta->expire_to)*2);
  357. psta->under_exist_checking = 1;
  358. //tear down TX AMPDU
  359. send_delba(padapter, 1, psta->hwaddr);// // originator
  360. psta->htpriv.agg_enable_bitmap = 0x0;//reset
  361. psta->htpriv.candidate_tid_bitmap = 0x0;//reset
  362. }
  363. }
  364. #endif //CONFIG_80211N_HT
  365. #endif // CONFIG_TX_MCAST2UNI
  366. #endif //CONFIG_ACTIVE_KEEP_ALIVE_CHECK
  367. if (psta->expire_to <= 0)
  368. {
  369. #ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
  370. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  371. if (padapter->registrypriv.wifi_spec == 1)
  372. {
  373. psta->expire_to = pstapriv->expire_to;
  374. continue;
  375. }
  376. if (psta->state & WIFI_SLEEP_STATE) {
  377. if (!(psta->state & WIFI_STA_ALIVE_CHK_STATE)) {
  378. //to check if alive by another methods if staion is at ps mode.
  379. psta->expire_to = pstapriv->expire_to;
  380. psta->state |= WIFI_STA_ALIVE_CHK_STATE;
  381. //DBG_871X("alive chk, sta:" MAC_FMT " is at ps mode!\n", MAC_ARG(psta->hwaddr));
  382. //to update bcn with tim_bitmap for this station
  383. pstapriv->tim_bitmap |= BIT(psta->aid);
  384. update_beacon(padapter, _TIM_IE_, NULL, _FALSE);
  385. if(!pmlmeext->active_keep_alive_check)
  386. continue;
  387. }
  388. }
  389. if (pmlmeext->active_keep_alive_check) {
  390. int stainfo_offset;
  391. stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
  392. if (stainfo_offset_valid(stainfo_offset)) {
  393. chk_alive_list[chk_alive_num++] = stainfo_offset;
  394. }
  395. continue;
  396. }
  397. #endif /* CONFIG_ACTIVE_KEEP_ALIVE_CHECK */
  398. rtw_list_delete(&psta->asoc_list);
  399. pstapriv->asoc_list_cnt--;
  400. DBG_871X("asoc expire "MAC_FMT", state=0x%x\n", MAC_ARG(psta->hwaddr), psta->state);
  401. updated = ap_free_sta(padapter, psta, _FALSE, WLAN_REASON_DEAUTH_LEAVING);
  402. }
  403. else
  404. {
  405. /* TODO: Aging mechanism to digest frames in sleep_q to avoid running out of xmitframe */
  406. if (psta->sleepq_len > (NR_XMITFRAME/pstapriv->asoc_list_cnt)
  407. && padapter->xmitpriv.free_xmitframe_cnt < ((NR_XMITFRAME/pstapriv->asoc_list_cnt)/2)
  408. ){
  409. DBG_871X("%s sta:"MAC_FMT", sleepq_len:%u, free_xmitframe_cnt:%u, asoc_list_cnt:%u, clear sleep_q\n", __func__
  410. , MAC_ARG(psta->hwaddr)
  411. , psta->sleepq_len, padapter->xmitpriv.free_xmitframe_cnt, pstapriv->asoc_list_cnt);
  412. wakeup_sta_to_xmit(padapter, psta);
  413. }
  414. }
  415. }
  416. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  417. #ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
  418. if (chk_alive_num) {
  419. u8 backup_oper_channel=0;
  420. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  421. /* switch to correct channel of current network before issue keep-alive frames */
  422. if (rtw_get_oper_ch(padapter) != pmlmeext->cur_channel) {
  423. backup_oper_channel = rtw_get_oper_ch(padapter);
  424. SelectChannel(padapter, pmlmeext->cur_channel);
  425. }
  426. /* issue null data to check sta alive*/
  427. for (i = 0; i < chk_alive_num; i++) {
  428. int ret = _FAIL;
  429. psta = rtw_get_stainfo_by_offset(pstapriv, chk_alive_list[i]);
  430. if(!(psta->state &_FW_LINKED))
  431. continue;
  432. if (psta->state & WIFI_SLEEP_STATE)
  433. ret = issue_nulldata(padapter, psta->hwaddr, 0, 1, 50);
  434. else
  435. ret = issue_nulldata(padapter, psta->hwaddr, 0, 3, 50);
  436. psta->keep_alive_trycnt++;
  437. if (ret == _SUCCESS)
  438. {
  439. DBG_871X("asoc check, sta(" MAC_FMT ") is alive\n", MAC_ARG(psta->hwaddr));
  440. psta->expire_to = pstapriv->expire_to;
  441. psta->keep_alive_trycnt = 0;
  442. continue;
  443. }
  444. else if (psta->keep_alive_trycnt <= 3)
  445. {
  446. DBG_871X("ack check for asoc expire, keep_alive_trycnt=%d\n", psta->keep_alive_trycnt);
  447. psta->expire_to = 1;
  448. continue;
  449. }
  450. psta->keep_alive_trycnt = 0;
  451. DBG_871X("asoc expire "MAC_FMT", state=0x%x\n", MAC_ARG(psta->hwaddr), psta->state);
  452. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  453. if (rtw_is_list_empty(&psta->asoc_list)==_FALSE) {
  454. rtw_list_delete(&psta->asoc_list);
  455. pstapriv->asoc_list_cnt--;
  456. updated = ap_free_sta(padapter, psta, _FALSE, WLAN_REASON_DEAUTH_LEAVING);
  457. }
  458. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  459. }
  460. if (backup_oper_channel>0) /* back to the original operation channel */
  461. SelectChannel(padapter, backup_oper_channel);
  462. }
  463. #endif /* CONFIG_ACTIVE_KEEP_ALIVE_CHECK */
  464. associated_clients_update(padapter, updated);
  465. }
  466. void add_RATid(_adapter *padapter, struct sta_info *psta, u8 rssi_level)
  467. {
  468. int i;
  469. u8 rf_type;
  470. u32 init_rate=0;
  471. unsigned char sta_band = 0, raid, shortGIrate = _FALSE;
  472. unsigned char limit;
  473. unsigned int tx_ra_bitmap=0;
  474. struct ht_priv *psta_ht = NULL;
  475. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  476. WLAN_BSSID_EX *pcur_network = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network;
  477. #ifdef CONFIG_80211N_HT
  478. if(psta)
  479. psta_ht = &psta->htpriv;
  480. else
  481. return;
  482. #endif //CONFIG_80211N_HT
  483. if(!(psta->state & _FW_LINKED))
  484. return;
  485. //b/g mode ra_bitmap
  486. for (i=0; i<sizeof(psta->bssrateset); i++)
  487. {
  488. if (psta->bssrateset[i])
  489. tx_ra_bitmap |= rtw_get_bit_value_from_ieee_value(psta->bssrateset[i]&0x7f);
  490. }
  491. #ifdef CONFIG_80211N_HT
  492. #ifdef CONFIG_80211AC_VHT
  493. //AC mode ra_bitmap
  494. if(psta->vhtpriv.vht_option)
  495. {
  496. u32 vht_bitmap = 0;
  497. vht_bitmap = rtw_vht_rate_to_bitmap(psta->vhtpriv.vht_mcs_map);
  498. tx_ra_bitmap |= (vht_bitmap << 12);
  499. //max short GI rate
  500. shortGIrate = psta->vhtpriv.sgi;
  501. }
  502. else
  503. #endif //CONFIG_80211AC_VHT
  504. {
  505. //n mode ra_bitmap
  506. if(psta_ht->ht_option)
  507. {
  508. rtw_hal_get_hwreg(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
  509. if(rf_type == RF_2T2R)
  510. limit=16;// 2R
  511. else
  512. limit=8;// 1R
  513. for (i=0; i<limit; i++) {
  514. if (psta_ht->ht_cap.supp_mcs_set[i/8] & BIT(i%8))
  515. tx_ra_bitmap |= BIT(i+12);
  516. }
  517. //max short GI rate
  518. shortGIrate = psta_ht->sgi;
  519. }
  520. }
  521. #endif //CONFIG_80211N_HT
  522. #if 0//gtest
  523. if(get_rf_mimo_mode(padapter) == RTL8712_RF_2T2R)
  524. {
  525. //is this a 2r STA?
  526. if((pstat->tx_ra_bitmap & 0x0ff00000) != 0 && !(priv->pshare->has_2r_sta & BIT(pstat->aid)))
  527. {
  528. priv->pshare->has_2r_sta |= BIT(pstat->aid);
  529. if(rtw_read16(padapter, 0x102501f6) != 0xffff)
  530. {
  531. rtw_write16(padapter, 0x102501f6, 0xffff);
  532. reset_1r_sta_RA(priv, 0xffff);
  533. Switch_1SS_Antenna(priv, 3);
  534. }
  535. }
  536. else// bg or 1R STA?
  537. {
  538. if((priv->pmib->dot11BssType.net_work_type & WIRELESS_11N) && pstat->ht_cap_len && priv->pshare->has_2r_sta == 0)
  539. {
  540. if(rtw_read16(padapter, 0x102501f6) != 0x7777)
  541. { // MCS7 SGI
  542. rtw_write16(padapter, 0x102501f6,0x7777);
  543. reset_1r_sta_RA(priv, 0x7777);
  544. Switch_1SS_Antenna(priv, 2);
  545. }
  546. }
  547. }
  548. }
  549. if ((pstat->rssi_level < 1) || (pstat->rssi_level > 3))
  550. {
  551. if (pstat->rssi >= priv->pshare->rf_ft_var.raGoDownUpper)
  552. pstat->rssi_level = 1;
  553. else if ((pstat->rssi >= priv->pshare->rf_ft_var.raGoDown20MLower) ||
  554. ((priv->pshare->is_40m_bw) && (pstat->ht_cap_len) &&
  555. (pstat->rssi >= priv->pshare->rf_ft_var.raGoDown40MLower) &&
  556. (pstat->ht_cap_buf.ht_cap_info & cpu_to_le16(_HTCAP_SUPPORT_CH_WDTH_))))
  557. pstat->rssi_level = 2;
  558. else
  559. pstat->rssi_level = 3;
  560. }
  561. // rate adaptive by rssi
  562. if ((priv->pmib->dot11BssType.net_work_type & WIRELESS_11N) && pstat->ht_cap_len)
  563. {
  564. if ((get_rf_mimo_mode(priv) == MIMO_1T2R) || (get_rf_mimo_mode(priv) == MIMO_1T1R))
  565. {
  566. switch (pstat->rssi_level) {
  567. case 1:
  568. pstat->tx_ra_bitmap &= 0x100f0000;
  569. break;
  570. case 2:
  571. pstat->tx_ra_bitmap &= 0x100ff000;
  572. break;
  573. case 3:
  574. if (priv->pshare->is_40m_bw)
  575. pstat->tx_ra_bitmap &= 0x100ff005;
  576. else
  577. pstat->tx_ra_bitmap &= 0x100ff001;
  578. break;
  579. }
  580. }
  581. else
  582. {
  583. switch (pstat->rssi_level) {
  584. case 1:
  585. pstat->tx_ra_bitmap &= 0x1f0f0000;
  586. break;
  587. case 2:
  588. pstat->tx_ra_bitmap &= 0x1f0ff000;
  589. break;
  590. case 3:
  591. if (priv->pshare->is_40m_bw)
  592. pstat->tx_ra_bitmap &= 0x000ff005;
  593. else
  594. pstat->tx_ra_bitmap &= 0x000ff001;
  595. break;
  596. }
  597. // Don't need to mask high rates due to new rate adaptive parameters
  598. //if (pstat->is_broadcom_sta) // use MCS12 as the highest rate vs. Broadcom sta
  599. // pstat->tx_ra_bitmap &= 0x81ffffff;
  600. // NIC driver will report not supporting MCS15 and MCS14 in asoc req
  601. //if (pstat->is_rtl8190_sta && !pstat->is_2t_mimo_sta)
  602. // pstat->tx_ra_bitmap &= 0x83ffffff; // if Realtek 1x2 sta, don't use MCS15 and MCS14
  603. }
  604. }
  605. else if ((priv->pmib->dot11BssType.net_work_type & WIRELESS_11G) && isErpSta(pstat))
  606. {
  607. switch (pstat->rssi_level) {
  608. case 1:
  609. pstat->tx_ra_bitmap &= 0x00000f00;
  610. break;
  611. case 2:
  612. pstat->tx_ra_bitmap &= 0x00000ff0;
  613. break;
  614. case 3:
  615. pstat->tx_ra_bitmap &= 0x00000ff5;
  616. break;
  617. }
  618. }
  619. else
  620. {
  621. pstat->tx_ra_bitmap &= 0x0000000d;
  622. }
  623. // disable tx short GI when station cannot rx MCS15(AP is 2T2R)
  624. // disable tx short GI when station cannot rx MCS7 (AP is 1T2R or 1T1R)
  625. // if there is only 1r STA and we are 2T2R, DO NOT mask SGI rate
  626. if ((!(pstat->tx_ra_bitmap & 0x8000000) && (priv->pshare->has_2r_sta > 0) && (get_rf_mimo_mode(padapter) == RTL8712_RF_2T2R)) ||
  627. (!(pstat->tx_ra_bitmap & 0x80000) && (get_rf_mimo_mode(padapter) != RTL8712_RF_2T2R)))
  628. {
  629. pstat->tx_ra_bitmap &= ~BIT(28);
  630. }
  631. #endif
  632. if ( pcur_network->Configuration.DSConfig > 14 ) {
  633. // 5G band
  634. #ifdef CONFIG_80211AC_VHT
  635. if (psta->vhtpriv.vht_option) {
  636. sta_band = WIRELESS_11_5AC;
  637. }
  638. else
  639. #endif
  640. {
  641. if (tx_ra_bitmap & 0xffff000)
  642. sta_band |= WIRELESS_11_5N | WIRELESS_11A;
  643. else
  644. sta_band |= WIRELESS_11A;
  645. }
  646. } else {
  647. if (tx_ra_bitmap & 0xffff000)
  648. sta_band |= WIRELESS_11_24N | WIRELESS_11G | WIRELESS_11B;
  649. else if (tx_ra_bitmap & 0xff0)
  650. sta_band |= WIRELESS_11G |WIRELESS_11B;
  651. else
  652. sta_band |= WIRELESS_11B;
  653. }
  654. psta->wireless_mode = sta_band;
  655. //raid = networktype_to_raid(sta_band);
  656. raid = rtw_hal_networktype_to_raid(padapter,sta_band);
  657. init_rate = get_highest_rate_idx(tx_ra_bitmap)&0x3f;
  658. if (psta->aid < NUM_STA)
  659. {
  660. u8 arg[4] = {0};
  661. //arg[0] = macid
  662. //arg[1] = raid
  663. //arg[2] = shortGIrate
  664. //arg[3] = init_rate
  665. arg[0] = psta->mac_id;
  666. arg[1] = raid;
  667. arg[2] = shortGIrate;
  668. arg[3] = init_rate;
  669. DBG_871X("%s=> mac_id:%d , raid:%d , shortGIrate=%d, bitmap=0x%x\n",
  670. __FUNCTION__ , psta->mac_id, raid ,shortGIrate, tx_ra_bitmap);
  671. rtw_hal_add_ra_tid(padapter, tx_ra_bitmap, arg, rssi_level);
  672. if (shortGIrate==_TRUE)
  673. init_rate |= BIT(6);
  674. //set ra_id, init_rate
  675. psta->raid = raid;
  676. psta->init_rate = init_rate;
  677. }
  678. else
  679. {
  680. DBG_871X("station aid %d exceed the max number\n", psta->aid);
  681. }
  682. }
  683. static void update_bmc_sta(_adapter *padapter)
  684. {
  685. _irqL irqL;
  686. u32 init_rate=0;
  687. unsigned char network_type, raid;
  688. int i, supportRateNum = 0;
  689. unsigned int tx_ra_bitmap=0;
  690. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  691. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  692. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  693. WLAN_BSSID_EX *pcur_network = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network;
  694. struct sta_info *psta = rtw_get_bcmc_stainfo(padapter);
  695. if(psta)
  696. {
  697. psta->aid = 0;//default set to 0
  698. //psta->mac_id = psta->aid+4;
  699. psta->mac_id = psta->aid + 1;//mac_id=1 for bc/mc stainfo
  700. pmlmeinfo->FW_sta_info[psta->mac_id].psta = psta;
  701. psta->qos_option = 0;
  702. #ifdef CONFIG_80211N_HT
  703. psta->htpriv.ht_option = _FALSE;
  704. #endif //CONFIG_80211N_HT
  705. psta->ieee8021x_blocked = 0;
  706. _rtw_memset((void*)&psta->sta_stats, 0, sizeof(struct stainfo_stats));
  707. //psta->dot118021XPrivacy = _NO_PRIVACY_;//!!! remove it, because it has been set before this.
  708. //prepare for add_RATid
  709. supportRateNum = rtw_get_rateset_len((u8*)&pcur_network->SupportedRates);
  710. network_type = rtw_check_network_type((u8*)&pcur_network->SupportedRates, supportRateNum, 1);
  711. _rtw_memcpy(psta->bssrateset, &pcur_network->SupportedRates, supportRateNum);
  712. psta->bssratelen = supportRateNum;
  713. //b/g mode ra_bitmap
  714. for (i=0; i<supportRateNum; i++)
  715. {
  716. if (psta->bssrateset[i])
  717. tx_ra_bitmap |= rtw_get_bit_value_from_ieee_value(psta->bssrateset[i]&0x7f);
  718. }
  719. if ( pcur_network->Configuration.DSConfig > 14 ) {
  720. //force to A mode. 5G doesn't support CCK rates
  721. network_type = WIRELESS_11A;
  722. tx_ra_bitmap = 0x150; // 6, 12, 24 Mbps
  723. } else {
  724. //force to b mode
  725. network_type = WIRELESS_11B;
  726. tx_ra_bitmap = 0xf;
  727. }
  728. //tx_ra_bitmap = update_basic_rate(pcur_network->SupportedRates, supportRateNum);
  729. //raid = networktype_to_raid(network_type);
  730. raid = rtw_hal_networktype_to_raid(padapter,network_type);
  731. init_rate = get_highest_rate_idx(tx_ra_bitmap&0x0fffffff)&0x3f;
  732. //DBG_871X("Add id %d val %08x to ratr for bmc sta\n", psta->aid, tx_ra_bitmap);
  733. //ap mode
  734. rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, _TRUE);
  735. //if(pHalData->fw_ractrl == _TRUE)
  736. {
  737. u8 arg[4] = {0};
  738. //arg[0] = macid
  739. //arg[1] = raid
  740. //arg[2] = shortGIrate
  741. //arg[3] = init_rate
  742. arg[0] = psta->mac_id;
  743. arg[1] = raid;
  744. arg[2] = 0;
  745. arg[3] = init_rate;
  746. DBG_871X("%s=> mac_id:%d , raid:%d , bitmap=0x%x\n",
  747. __FUNCTION__ , psta->mac_id, raid , tx_ra_bitmap);
  748. rtw_hal_add_ra_tid(padapter, tx_ra_bitmap, arg, 0);
  749. }
  750. //set ra_id, init_rate
  751. psta->raid = raid;
  752. psta->init_rate = init_rate;
  753. rtw_stassoc_hw_rpt(padapter, psta);
  754. _enter_critical_bh(&psta->lock, &irqL);
  755. psta->state = _FW_LINKED;
  756. _exit_critical_bh(&psta->lock, &irqL);
  757. }
  758. else
  759. {
  760. DBG_871X("add_RATid_bmc_sta error!\n");
  761. }
  762. }
  763. //notes:
  764. //AID: 1~MAX for sta and 0 for bc/mc in ap/adhoc mode
  765. //MAC_ID = AID+1 for sta in ap/adhoc mode
  766. //MAC_ID = 1 for bc/mc for sta/ap/adhoc
  767. //MAC_ID = 0 for bssid for sta/ap/adhoc
  768. //CAM_ID = //0~3 for default key, cmd_id=macid + 3, macid=aid+1;
  769. void update_sta_info_apmode(_adapter *padapter, struct sta_info *psta)
  770. {
  771. _irqL irqL;
  772. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  773. struct security_priv *psecuritypriv = &padapter->securitypriv;
  774. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  775. #ifdef CONFIG_80211N_HT
  776. struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
  777. struct ht_priv *phtpriv_sta = &psta->htpriv;
  778. #endif //CONFIG_80211N_HT
  779. //set intf_tag to if1
  780. //psta->intf_tag = 0;
  781. DBG_871X("%s\n",__FUNCTION__);
  782. //psta->mac_id = psta->aid+4;
  783. //psta->mac_id = psta->aid+1;//alloc macid when call rtw_alloc_stainfo(),
  784. //release macid when call rtw_free_stainfo()
  785. //ap mode
  786. rtw_hal_set_odm_var(padapter,HAL_ODM_STA_INFO,psta,_TRUE);
  787. if(psecuritypriv->dot11AuthAlgrthm==dot11AuthAlgrthm_8021X)
  788. psta->ieee8021x_blocked = _TRUE;
  789. else
  790. psta->ieee8021x_blocked = _FALSE;
  791. //update sta's cap
  792. //ERP
  793. VCS_update(padapter, psta);
  794. #ifdef CONFIG_80211N_HT
  795. //HT related cap
  796. if(phtpriv_sta->ht_option)
  797. {
  798. //check if sta supports rx ampdu
  799. phtpriv_sta->ampdu_enable = phtpriv_ap->ampdu_enable;
  800. //check if sta support s Short GI
  801. if((phtpriv_sta->ht_cap.cap_info & phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SGI_20|IEEE80211_HT_CAP_SGI_40))
  802. {
  803. phtpriv_sta->sgi = _TRUE;
  804. }
  805. // bwmode
  806. if((phtpriv_sta->ht_cap.cap_info & phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH))
  807. {
  808. //phtpriv_sta->bwmode = CHANNEL_WIDTH_40;
  809. phtpriv_sta->bwmode = pmlmeext->cur_bwmode;
  810. phtpriv_sta->ch_offset = pmlmeext->cur_ch_offset;
  811. }
  812. psta->qos_option = _TRUE;
  813. }
  814. else
  815. {
  816. phtpriv_sta->ampdu_enable = _FALSE;
  817. phtpriv_sta->sgi = _FALSE;
  818. phtpriv_sta->bwmode = CHANNEL_WIDTH_20;
  819. phtpriv_sta->ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  820. }
  821. //Rx AMPDU
  822. send_delba(padapter, 0, psta->hwaddr);// recipient
  823. //TX AMPDU
  824. send_delba(padapter, 1, psta->hwaddr);// // originator
  825. phtpriv_sta->agg_enable_bitmap = 0x0;//reset
  826. phtpriv_sta->candidate_tid_bitmap = 0x0;//reset
  827. #endif //CONFIG_80211N_HT
  828. #ifdef CONFIG_80211AC_VHT
  829. update_sta_vht_info_apmode(padapter, psta);
  830. #endif
  831. //todo: init other variables
  832. _rtw_memset((void*)&psta->sta_stats, 0, sizeof(struct stainfo_stats));
  833. //add ratid
  834. //add_RATid(padapter, psta);//move to ap_sta_info_defer_update()
  835. _enter_critical_bh(&psta->lock, &irqL);
  836. psta->state |= _FW_LINKED;
  837. _exit_critical_bh(&psta->lock, &irqL);
  838. }
  839. static void update_hw_ht_param(_adapter *padapter)
  840. {
  841. unsigned char max_AMPDU_len;
  842. unsigned char min_MPDU_spacing;
  843. struct registry_priv *pregpriv = &padapter->registrypriv;
  844. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  845. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  846. DBG_871X("%s\n", __FUNCTION__);
  847. //handle A-MPDU parameter field
  848. /*
  849. AMPDU_para [1:0]:Max AMPDU Len => 0:8k , 1:16k, 2:32k, 3:64k
  850. AMPDU_para [4:2]:Min MPDU Start Spacing
  851. */
  852. max_AMPDU_len = pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x03;
  853. min_MPDU_spacing = (pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x1c) >> 2;
  854. rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_MIN_SPACE, (u8 *)(&min_MPDU_spacing));
  855. rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_FACTOR, (u8 *)(&max_AMPDU_len));
  856. //
  857. // Config SM Power Save setting
  858. //
  859. pmlmeinfo->SM_PS = (pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info & 0x0C) >> 2;
  860. if(pmlmeinfo->SM_PS == WLAN_HT_CAP_SM_PS_STATIC)
  861. {
  862. /*u8 i;
  863. //update the MCS rates
  864. for (i = 0; i < 16; i++)
  865. {
  866. pmlmeinfo->HT_caps.HT_cap_element.MCS_rate[i] &= MCS_rate_1R[i];
  867. }*/
  868. DBG_871X("%s(): WLAN_HT_CAP_SM_PS_STATIC\n",__FUNCTION__);
  869. }
  870. //
  871. // Config current HT Protection mode.
  872. //
  873. //pmlmeinfo->HT_protection = pmlmeinfo->HT_info.infos[1] & 0x3;
  874. }
  875. static void start_bss_network(_adapter *padapter, u8 *pbuf)
  876. {
  877. u8 *p;
  878. u8 val8, cur_channel, cur_bwmode, cur_ch_offset;
  879. u16 bcn_interval;
  880. u32 acparm;
  881. int ie_len;
  882. struct registry_priv *pregpriv = &padapter->registrypriv;
  883. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  884. struct security_priv* psecuritypriv=&(padapter->securitypriv);
  885. WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network;
  886. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  887. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  888. WLAN_BSSID_EX *pnetwork_mlmeext = &(pmlmeinfo->network);
  889. struct HT_info_element *pht_info=NULL;
  890. #ifdef CONFIG_P2P
  891. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  892. #endif //CONFIG_P2P
  893. u8 cbw40_enable=0;
  894. u8 change_band = _FALSE;
  895. //DBG_871X("%s\n", __FUNCTION__);
  896. bcn_interval = (u16)pnetwork->Configuration.BeaconPeriod;
  897. cur_channel = pnetwork->Configuration.DSConfig;
  898. cur_bwmode = CHANNEL_WIDTH_20;
  899. cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  900. //check if there is wps ie,
  901. //if there is wpsie in beacon, the hostapd will update beacon twice when stating hostapd,
  902. //and at first time the security ie ( RSN/WPA IE) will not include in beacon.
  903. if(NULL == rtw_get_wps_ie(pnetwork->IEs+_FIXED_IE_LENGTH_, pnetwork->IELength-_FIXED_IE_LENGTH_, NULL, NULL))
  904. {
  905. pmlmeext->bstart_bss = _TRUE;
  906. }
  907. //todo: update wmm, ht cap
  908. //pmlmeinfo->WMM_enable;
  909. //pmlmeinfo->HT_enable;
  910. if(pmlmepriv->qospriv.qos_option)
  911. pmlmeinfo->WMM_enable = _TRUE;
  912. #ifdef CONFIG_80211N_HT
  913. if(pmlmepriv->htpriv.ht_option)
  914. {
  915. pmlmeinfo->WMM_enable = _TRUE;
  916. pmlmeinfo->HT_enable = _TRUE;
  917. //pmlmeinfo->HT_info_enable = _TRUE;
  918. //pmlmeinfo->HT_caps_enable = _TRUE;
  919. update_hw_ht_param(padapter);
  920. }
  921. #endif //#CONFIG_80211N_HT
  922. #ifdef CONFIG_80211AC_VHT
  923. if(pmlmepriv->vhtpriv.vht_option) {
  924. pmlmeinfo->VHT_enable = _TRUE;
  925. update_hw_vht_param(padapter);
  926. }
  927. #endif //CONFIG_80211AC_VHT
  928. if(pmlmepriv->cur_network.join_res != _TRUE) //setting only at first time
  929. {
  930. //WEP Key will be set before this function, do not clear CAM.
  931. if ((psecuritypriv->dot11PrivacyAlgrthm != _WEP40_) && (psecuritypriv->dot11PrivacyAlgrthm != _WEP104_))
  932. flush_all_cam_entry(padapter); //clear CAM
  933. }
  934. //set MSR to AP_Mode
  935. Set_MSR(padapter, _HW_STATE_AP_);
  936. //Set BSSID REG
  937. rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, pnetwork->MacAddress);
  938. //Set EDCA param reg
  939. #ifdef CONFIG_CONCURRENT_MODE
  940. acparm = 0x005ea42b;
  941. #else
  942. acparm = 0x002F3217; // VO
  943. #endif
  944. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acparm));
  945. acparm = 0x005E4317; // VI
  946. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acparm));
  947. //acparm = 0x00105320; // BE
  948. acparm = 0x005ea42b;
  949. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acparm));
  950. acparm = 0x0000A444; // BK
  951. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acparm));
  952. //Set Security
  953. val8 = (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X)? 0xcc: 0xcf;
  954. rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8));
  955. //Beacon Control related register
  956. rtw_hal_set_hwreg(padapter, HW_VAR_BEACON_INTERVAL, (u8 *)(&bcn_interval));
  957. if(pmlmepriv->cur_network.join_res != _TRUE) //setting only at first time
  958. {
  959. //u32 initialgain;
  960. //initialgain = 0x1e;
  961. //disable dynamic functions, such as high power, DIG
  962. //Save_DM_Func_Flag(padapter);
  963. //Switch_DM_Func(padapter, DYNAMIC_FUNC_DISABLE, _FALSE);
  964. #ifdef CONFIG_CONCURRENT_MODE
  965. if(padapter->adapter_type > PRIMARY_ADAPTER)
  966. {
  967. if(rtw_buddy_adapter_up(padapter))
  968. {
  969. _adapter *pbuddy_adapter = padapter->pbuddy_adapter;
  970. //turn on all dynamic functions on PRIMARY_ADAPTER, dynamic functions only runs at PRIMARY_ADAPTER
  971. Switch_DM_Func(pbuddy_adapter, DYNAMIC_ALL_FUNC_ENABLE, _TRUE);
  972. //rtw_hal_set_hwreg(pbuddy_adapter, HW_VAR_INITIAL_GAIN, (u8 *)(&initialgain));
  973. }
  974. }
  975. else
  976. #endif
  977. {
  978. //turn on all dynamic functions
  979. Switch_DM_Func(padapter, DYNAMIC_ALL_FUNC_ENABLE, _TRUE);
  980. //rtw_hal_set_hwreg(padapter, HW_VAR_INITIAL_GAIN, (u8 *)(&initialgain));
  981. }
  982. }
  983. #ifdef CONFIG_80211N_HT
  984. //set channel, bwmode
  985. p = rtw_get_ie((pnetwork->IEs + sizeof(NDIS_802_11_FIXED_IEs)), _HT_ADD_INFO_IE_, &ie_len, (pnetwork->IELength - sizeof(NDIS_802_11_FIXED_IEs)));
  986. if( p && ie_len)
  987. {
  988. pht_info = (struct HT_info_element *)(p+2);
  989. if (cur_channel > 14) {
  990. if ((pregpriv->bw_mode & 0xf0) > 0)
  991. cbw40_enable = 1;
  992. } else {
  993. if ((pregpriv->bw_mode & 0x0f) > 0)
  994. cbw40_enable = 1;
  995. }
  996. if ((cbw40_enable) && (pht_info->infos[0] & BIT(2)))
  997. {
  998. //switch to the 40M Hz mode
  999. //pmlmeext->cur_bwmode = CHANNEL_WIDTH_40;
  1000. cur_bwmode = CHANNEL_WIDTH_40;
  1001. switch (pht_info->infos[0] & 0x3)
  1002. {
  1003. case 1:
  1004. //pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
  1005. cur_ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
  1006. break;
  1007. case 3:
  1008. //pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
  1009. cur_ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
  1010. break;
  1011. default:
  1012. //pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  1013. cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  1014. break;
  1015. }
  1016. }
  1017. }
  1018. #endif //CONFIG_80211N_HT
  1019. #ifdef CONFIG_80211AC_VHT
  1020. p = rtw_get_ie((pnetwork->IEs + sizeof(NDIS_802_11_FIXED_IEs)), EID_VHTOperation, &ie_len, (pnetwork->IELength - sizeof(NDIS_802_11_FIXED_IEs)));
  1021. if( p && ie_len)
  1022. {
  1023. if(GET_VHT_OPERATION_ELE_CHL_WIDTH(p+2) >= 1) {
  1024. cur_bwmode = CHANNEL_WIDTH_80;
  1025. }
  1026. }
  1027. #endif
  1028. #ifdef CONFIG_DUALMAC_CONCURRENT
  1029. dc_set_ap_channel_bandwidth(padapter, cur_channel, cur_ch_offset, cur_bwmode);
  1030. #else
  1031. //TODO: need to judge the phy parameters on concurrent mode for single phy
  1032. //set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
  1033. #ifdef CONFIG_CONCURRENT_MODE
  1034. if(!check_buddy_fwstate(padapter, _FW_LINKED|_FW_UNDER_LINKING|_FW_UNDER_SURVEY))
  1035. {
  1036. set_channel_bwmode(padapter, cur_channel, cur_ch_offset, cur_bwmode);
  1037. }
  1038. else if(check_buddy_fwstate(padapter, _FW_LINKED)==_TRUE)//only second adapter can enter AP Mode
  1039. {
  1040. _adapter *pbuddy_adapter = padapter->pbuddy_adapter;
  1041. struct mlme_ext_priv *pbuddy_mlmeext = &pbuddy_adapter->mlmeextpriv;
  1042. //To sync cur_channel/cur_bwmode/cur_ch_offset with primary adapter
  1043. DBG_871X("primary iface is at linked state, sync cur_channel/cur_bwmode/cur_ch_offset\n");
  1044. DBG_871X("primary adapter, CH=%d, BW=%d, offset=%d\n", pbuddy_mlmeext->cur_channel, pbuddy_mlmeext->cur_bwmode, pbuddy_mlmeext->cur_ch_offset);
  1045. DBG_871X("second adapter, CH=%d, BW=%d, offset=%d\n", cur_channel, cur_bwmode, cur_ch_offset);
  1046. if((cur_channel <= 14 && pbuddy_mlmeext->cur_channel >= 36) ||
  1047. (cur_channel >= 36 && pbuddy_mlmeext->cur_channel <= 14))
  1048. change_band = _TRUE;
  1049. cur_channel = pbuddy_mlmeext->cur_channel;
  1050. if(cur_bwmode == CHANNEL_WIDTH_40)
  1051. {
  1052. if(pht_info)
  1053. pht_info->infos[0] &= ~(BIT(0)|BIT(1));
  1054. if(pbuddy_mlmeext->cur_bwmode == CHANNEL_WIDTH_40)
  1055. {
  1056. cur_ch_offset = pbuddy_mlmeext->cur_ch_offset;
  1057. //to update cur_ch_offset value in beacon
  1058. if(pht_info)
  1059. {
  1060. switch(cur_ch_offset)
  1061. {
  1062. case HAL_PRIME_CHNL_OFFSET_LOWER:
  1063. pht_info->infos[0] |= 0x1;
  1064. break;
  1065. case HAL_PRIME_CHNL_OFFSET_UPPER:
  1066. pht_info->infos[0] |= 0x3;
  1067. break;
  1068. case HAL_PRIME_CHNL_OFFSET_DONT_CARE:
  1069. default:
  1070. break;
  1071. }
  1072. }
  1073. }
  1074. else if(pbuddy_mlmeext->cur_bwmode == CHANNEL_WIDTH_20)
  1075. {
  1076. cur_bwmode = CHANNEL_WIDTH_20;
  1077. cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  1078. if(cur_channel>0 && cur_channel<5)
  1079. {
  1080. if(pht_info)
  1081. pht_info->infos[0] |= 0x1;
  1082. cur_bwmode = CHANNEL_WIDTH_40;
  1083. cur_ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
  1084. }
  1085. if(cur_channel>7 && cur_channel<(14+1))
  1086. {
  1087. if(pht_info)
  1088. pht_info->infos[0] |= 0x3;
  1089. cur_bwmode = CHANNEL_WIDTH_40;
  1090. cur_ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
  1091. }
  1092. }
  1093. set_channel_bwmode(padapter, cur_channel, cur_ch_offset, cur_bwmode);
  1094. }
  1095. else
  1096. {
  1097. //follow buddy's ch/bw/ch_offset setting, needn't set ch_bw again.
  1098. //set_channel_bwmode(padapter, cur_channel, pbuddy_mlmeext->cur_ch_offset, pbuddy_mlmeext->cur_bwmode);
  1099. }
  1100. // to update channel value in beacon
  1101. pnetwork->Configuration.DSConfig = cur_channel;
  1102. p = rtw_get_ie((pnetwork->IEs + sizeof(NDIS_802_11_FIXED_IEs)), _DSSET_IE_, &ie_len, (pnetwork->IELength - sizeof(NDIS_802_11_FIXED_IEs)));
  1103. if(p && ie_len>0)
  1104. *(p + 2) = cur_channel;
  1105. if(pht_info)
  1106. pht_info->primary_channel = cur_channel;
  1107. }
  1108. #else
  1109. set_channel_bwmode(padapter, cur_channel, cur_ch_offset, cur_bwmode);
  1110. #endif //CONFIG_CONCURRENT_MODE
  1111. DBG_871X("CH=%d, BW=%d, offset=%d\n", cur_channel, cur_bwmode, cur_ch_offset);
  1112. pmlmeext->cur_channel = cur_channel;
  1113. pmlmeext->cur_bwmode = cur_bwmode;
  1114. pmlmeext->cur_ch_offset = cur_ch_offset;
  1115. //buddy interface band is different from current interface, update ERP, support rate, ext support rate IE
  1116. if(change_band == _TRUE)
  1117. change_band_update_ie(padapter, pnetwork);
  1118. #endif //CONFIG_DUALMAC_CONCURRENT
  1119. pmlmeext->cur_wireless_mode = pmlmepriv->cur_network.network_type;
  1120. //update cur_wireless_mode
  1121. update_wireless_mode(padapter);
  1122. //update RRSR after set channel and bandwidth
  1123. UpdateBrateTbl(padapter, pnetwork->SupportedRates);
  1124. rtw_hal_set_hwreg(padapter, HW_VAR_BASIC_RATE, pnetwork->SupportedRates);
  1125. //udpate capability after cur_wireless_mode updated
  1126. update_capinfo(padapter, rtw_get_capability((WLAN_BSSID_EX *)pnetwork));
  1127. //let pnetwork_mlmeext == pnetwork_mlme.
  1128. _rtw_memcpy(pnetwork_mlmeext, pnetwork, pnetwork->Length);
  1129. #ifdef CONFIG_P2P
  1130. _rtw_memcpy(pwdinfo->p2p_group_ssid, pnetwork->Ssid.Ssid, pnetwork->Ssid.SsidLength);
  1131. pwdinfo->p2p_group_ssid_len = pnetwork->Ssid.SsidLength;
  1132. #endif //CONFIG_P2P
  1133. if(_TRUE == pmlmeext->bstart_bss)
  1134. {
  1135. update_beacon(padapter, _TIM_IE_, NULL, _FALSE);
  1136. #ifndef CONFIG_INTERRUPT_BASED_TXBCN //other case will tx beacon when bcn interrupt coming in.
  1137. #if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
  1138. //issue beacon frame
  1139. if(send_beacon(padapter)==_FAIL)
  1140. {
  1141. DBG_871X("issue_beacon, fail!\n");
  1142. }
  1143. #endif
  1144. #endif //!CONFIG_INTERRUPT_BASED_TXBCN
  1145. }
  1146. //update bc/mc sta_info
  1147. update_bmc_sta(padapter);
  1148. //pmlmeext->bstart_bss = _TRUE;
  1149. }
  1150. int rtw_check_beacon_data(_adapter *padapter, u8 *pbuf, int len)
  1151. {
  1152. int ret=_SUCCESS;
  1153. u8 *p;
  1154. u8 *pHT_caps_ie=NULL;
  1155. u8 *pHT_info_ie=NULL;
  1156. struct sta_info *psta = NULL;
  1157. u16 cap, ht_cap=_FALSE;
  1158. uint ie_len = 0;
  1159. int group_cipher, pairwise_cipher;
  1160. u8 channel, network_type, supportRate[NDIS_802_11_LENGTH_RATES_EX];
  1161. int supportRateNum = 0;
  1162. u8 OUI1[] = {0x00, 0x50, 0xf2,0x01};
  1163. u8 wps_oui[4]={0x0,0x50,0xf2,0x04};
  1164. u8 WMM_PARA_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01};
  1165. struct registry_priv *pregistrypriv = &padapter->registrypriv;
  1166. struct security_priv *psecuritypriv = &padapter->securitypriv;
  1167. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1168. WLAN_BSSID_EX *pbss_network = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network;
  1169. struct sta_priv *pstapriv = &padapter->stapriv;
  1170. u8 *ie = pbss_network->IEs;
  1171. /* SSID */
  1172. /* Supported rates */
  1173. /* DS Params */
  1174. /* WLAN_EID_COUNTRY */
  1175. /* ERP Information element */
  1176. /* Extended supported rates */
  1177. /* WPA/WPA2 */
  1178. /* Wi-Fi Wireless Multimedia Extensions */
  1179. /* ht_capab, ht_oper */
  1180. /* WPS IE */
  1181. DBG_871X("%s, len=%d\n", __FUNCTION__, len);
  1182. if(check_fwstate(pmlmepriv, WIFI_AP_STATE) != _TRUE)
  1183. return _FAIL;
  1184. if(len>MAX_IE_SZ)
  1185. return _FAIL;
  1186. pbss_network->IELength = len;
  1187. _rtw_memset(ie, 0, MAX_IE_SZ);
  1188. _rtw_memcpy(ie, pbuf, pbss_network->IELength);
  1189. if(pbss_network->InfrastructureMode!=Ndis802_11APMode)
  1190. return _FAIL;
  1191. pbss_network->Rssi = 0;
  1192. _rtw_memcpy(pbss_network->MacAddress, myid(&(padapter->eeprompriv)), ETH_ALEN);
  1193. //beacon interval
  1194. p = rtw_get_beacon_interval_from_ie(ie);//ie + 8; // 8: TimeStamp, 2: Beacon Interval 2:Capability
  1195. //pbss_network->Configuration.BeaconPeriod = le16_to_cpu(*(unsigned short*)p);
  1196. pbss_network->Configuration.BeaconPeriod = RTW_GET_LE16(p);
  1197. //capability
  1198. //cap = *(unsigned short *)rtw_get_capability_from_ie(ie);
  1199. //cap = le16_to_cpu(cap);
  1200. cap = RTW_GET_LE16(ie);
  1201. //SSID
  1202. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _SSID_IE_, &ie_len, (pbss_network->IELength -_BEACON_IE_OFFSET_));
  1203. if(p && ie_len>0)
  1204. {
  1205. _rtw_memset(&pbss_network->Ssid, 0, sizeof(NDIS_802_11_SSID));
  1206. _rtw_memcpy(pbss_network->Ssid.Ssid, (p + 2), ie_len);
  1207. pbss_network->Ssid.SsidLength = ie_len;
  1208. }
  1209. //chnnel
  1210. channel = 0;
  1211. pbss_network->Configuration.Length = 0;
  1212. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _DSSET_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
  1213. if(p && ie_len>0)
  1214. channel = *(p + 2);
  1215. pbss_network->Configuration.DSConfig = channel;
  1216. _rtw_memset(supportRate, 0, NDIS_802_11_LENGTH_RATES_EX);
  1217. // get supported rates
  1218. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _SUPPORTEDRATES_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
  1219. if (p != NULL)
  1220. {
  1221. _rtw_memcpy(supportRate, p+2, ie_len);
  1222. supportRateNum = ie_len;
  1223. }
  1224. //get ext_supported rates
  1225. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _EXT_SUPPORTEDRATES_IE_, &ie_len, pbss_network->IELength - _BEACON_IE_OFFSET_);
  1226. if (p != NULL)
  1227. {
  1228. _rtw_memcpy(supportRate+supportRateNum, p+2, ie_len);
  1229. supportRateNum += ie_len;
  1230. }
  1231. network_type = rtw_check_network_type(supportRate, supportRateNum, channel);
  1232. rtw_set_supported_rate(pbss_network->SupportedRates, network_type);
  1233. //parsing ERP_IE
  1234. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _ERPINFO_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
  1235. if(p && ie_len>0)
  1236. {
  1237. ERP_IE_handler(padapter, (PNDIS_802_11_VARIABLE_IEs)p);
  1238. }
  1239. //update privacy/security
  1240. if (cap & BIT(4))
  1241. pbss_network->Privacy = 1;
  1242. else
  1243. pbss_network->Privacy = 0;
  1244. psecuritypriv->wpa_psk = 0;
  1245. //wpa2
  1246. group_cipher = 0; pairwise_cipher = 0;
  1247. psecuritypriv->wpa2_group_cipher = _NO_PRIVACY_;
  1248. psecuritypriv->wpa2_pairwise_cipher = _NO_PRIVACY_;
  1249. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _RSN_IE_2_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
  1250. if(p && ie_len>0)
  1251. {
  1252. if(rtw_parse_wpa2_ie(p, ie_len+2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS)
  1253. {
  1254. psecuritypriv->dot11AuthAlgrthm= dot11AuthAlgrthm_8021X;
  1255. psecuritypriv->dot8021xalg = 1;//psk, todo:802.1x
  1256. psecuritypriv->wpa_psk |= BIT(1);
  1257. psecuritypriv->wpa2_group_cipher = group_cipher;
  1258. psecuritypriv->wpa2_pairwise_cipher = pairwise_cipher;
  1259. #if 0
  1260. switch(group_cipher)
  1261. {
  1262. case WPA_CIPHER_NONE:
  1263. psecuritypriv->wpa2_group_cipher = _NO_PRIVACY_;
  1264. break;
  1265. case WPA_CIPHER_WEP40:
  1266. psecuritypriv->wpa2_group_cipher = _WEP40_;
  1267. break;
  1268. case WPA_CIPHER_TKIP:
  1269. psecuritypriv->wpa2_group_cipher = _TKIP_;
  1270. break;
  1271. case WPA_CIPHER_CCMP:
  1272. psecuritypriv->wpa2_group_cipher = _AES_;
  1273. break;
  1274. case WPA_CIPHER_WEP104:
  1275. psecuritypriv->wpa2_group_cipher = _WEP104_;
  1276. break;
  1277. }
  1278. switch(pairwise_cipher)
  1279. {
  1280. case WPA_CIPHER_NONE:
  1281. psecuritypriv->wpa2_pairwise_cipher = _NO_PRIVACY_;
  1282. break;
  1283. case WPA_CIPHER_WEP40:
  1284. psecuritypriv->wpa2_pairwise_cipher = _WEP40_;
  1285. break;
  1286. case WPA_CIPHER_TKIP:
  1287. psecuritypriv->wpa2_pairwise_cipher = _TKIP_;
  1288. break;
  1289. case WPA_CIPHER_CCMP:
  1290. psecuritypriv->wpa2_pairwise_cipher = _AES_;
  1291. break;
  1292. case WPA_CIPHER_WEP104:
  1293. psecuritypriv->wpa2_pairwise_cipher = _WEP104_;
  1294. break;
  1295. }
  1296. #endif
  1297. }
  1298. }
  1299. //wpa
  1300. ie_len = 0;
  1301. group_cipher = 0; pairwise_cipher = 0;
  1302. psecuritypriv->wpa_group_cipher = _NO_PRIVACY_;
  1303. psecuritypriv->wpa_pairwise_cipher = _NO_PRIVACY_;
  1304. for (p = ie + _BEACON_IE_OFFSET_; ;p += (ie_len + 2))
  1305. {
  1306. p = rtw_get_ie(p, _SSN_IE_1_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_ - (ie_len + 2)));
  1307. if ((p) && (_rtw_memcmp(p+2, OUI1, 4)))
  1308. {
  1309. if(rtw_parse_wpa_ie(p, ie_len+2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS)
  1310. {
  1311. psecuritypriv->dot11AuthAlgrthm= dot11AuthAlgrthm_8021X;
  1312. psecuritypriv->dot8021xalg = 1;//psk, todo:802.1x
  1313. psecuritypriv->wpa_psk |= BIT(0);
  1314. psecuritypriv->wpa_group_cipher = group_cipher;
  1315. psecuritypriv->wpa_pairwise_cipher = pairwise_cipher;
  1316. #if 0
  1317. switch(group_cipher)
  1318. {
  1319. case WPA_CIPHER_NONE:
  1320. psecuritypriv->wpa_group_cipher = _NO_PRIVACY_;
  1321. break;
  1322. case WPA_CIPHER_WEP40:
  1323. psecuritypriv->wpa_group_cipher = _WEP40_;
  1324. break;
  1325. case WPA_CIPHER_TKIP:
  1326. psecuritypriv->wpa_group_cipher = _TKIP_;
  1327. break;
  1328. case WPA_CIPHER_CCMP:
  1329. psecuritypriv->wpa_group_cipher = _AES_;
  1330. break;
  1331. case WPA_CIPHER_WEP104:
  1332. psecuritypriv->wpa_group_cipher = _WEP104_;
  1333. break;
  1334. }
  1335. switch(pairwise_cipher)
  1336. {
  1337. case WPA_CIPHER_NONE:
  1338. psecuritypriv->wpa_pairwise_cipher = _NO_PRIVACY_;
  1339. break;
  1340. case WPA_CIPHER_WEP40:
  1341. psecuritypriv->wpa_pairwise_cipher = _WEP40_;
  1342. break;
  1343. case WPA_CIPHER_TKIP:
  1344. psecuritypriv->wpa_pairwise_cipher = _TKIP_;
  1345. break;
  1346. case WPA_CIPHER_CCMP:
  1347. psecuritypriv->wpa_pairwise_cipher = _AES_;
  1348. break;
  1349. case WPA_CIPHER_WEP104:
  1350. psecuritypriv->wpa_pairwise_cipher = _WEP104_;
  1351. break;
  1352. }
  1353. #endif
  1354. }
  1355. break;
  1356. }
  1357. if ((p == NULL) || (ie_len == 0))
  1358. {
  1359. break;
  1360. }
  1361. }
  1362. //wmm
  1363. ie_len = 0;
  1364. pmlmepriv->qospriv.qos_option = 0;
  1365. if(pregistrypriv->wmm_enable)
  1366. {
  1367. for (p = ie + _BEACON_IE_OFFSET_; ;p += (ie_len + 2))
  1368. {
  1369. p = rtw_get_ie(p, _VENDOR_SPECIFIC_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_ - (ie_len + 2)));
  1370. if((p) && _rtw_memcmp(p+2, WMM_PARA_IE, 6))
  1371. {
  1372. pmlmepriv->qospriv.qos_option = 1;
  1373. *(p+8) |= BIT(7);//QoS Info, support U-APSD
  1374. /* disable all ACM bits since the WMM admission control is not supported */
  1375. *(p + 10) &= ~BIT(4); /* BE */
  1376. *(p + 14) &= ~BIT(4); /* BK */
  1377. *(p + 18) &= ~BIT(4); /* VI */
  1378. *(p + 22) &= ~BIT(4); /* VO */
  1379. break;
  1380. }
  1381. if ((p == NULL) || (ie_len == 0))
  1382. {
  1383. break;
  1384. }
  1385. }
  1386. }
  1387. #ifdef CONFIG_80211N_HT
  1388. //parsing HT_CAP_IE
  1389. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_CAPABILITY_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
  1390. if(p && ie_len>0)
  1391. {
  1392. u8 rf_type;
  1393. struct rtw_ieee80211_ht_cap *pht_cap = (struct rtw_ieee80211_ht_cap *)(p+2);
  1394. pHT_caps_ie=p;
  1395. ht_cap = _TRUE;
  1396. network_type |= WIRELESS_11_24N;
  1397. rtw_hal_get_hwreg(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
  1398. if((psecuritypriv->wpa_pairwise_cipher & WPA_CIPHER_CCMP) ||
  1399. (psecuritypriv->wpa2_pairwise_cipher & WPA_CIPHER_CCMP))
  1400. {
  1401. pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_DENSITY&(0x07<<2));
  1402. }
  1403. else
  1404. {
  1405. pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_DENSITY&0x00);
  1406. }
  1407. pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_FACTOR & 0x03); //set Max Rx AMPDU size to 64K
  1408. if(rf_type == RF_1T1R)
  1409. {
  1410. pht_cap->supp_mcs_set[0] = 0xff;
  1411. pht_cap->supp_mcs_set[1] = 0x0;
  1412. }
  1413. _rtw_memcpy(&pmlmepriv->htpriv.ht_cap, p+2, ie_len);
  1414. }
  1415. //parsing HT_INFO_IE
  1416. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_ADD_INFO_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
  1417. if(p && ie_len>0)
  1418. {
  1419. pHT_info_ie=p;
  1420. }
  1421. #endif //CONFIG_80211N_HT
  1422. switch(network_type)
  1423. {
  1424. case WIRELESS_11B:
  1425. pbss_network->NetworkTypeInUse = Ndis802_11DS;
  1426. break;
  1427. case WIRELESS_11G:
  1428. case WIRELESS_11BG:
  1429. case WIRELESS_11G_24N:
  1430. case WIRELESS_11BG_24N:
  1431. pbss_network->NetworkTypeInUse = Ndis802_11OFDM24;
  1432. break;
  1433. case WIRELESS_11A:
  1434. pbss_network->NetworkTypeInUse = Ndis802_11OFDM5;
  1435. break;
  1436. default :
  1437. pbss_network->NetworkTypeInUse = Ndis802_11OFDM24;
  1438. break;
  1439. }
  1440. pmlmepriv->cur_network.network_type = network_type;
  1441. #ifdef CONFIG_80211N_HT
  1442. pmlmepriv->htpriv.ht_option = _FALSE;
  1443. if( (psecuritypriv->wpa2_pairwise_cipher&WPA_CIPHER_TKIP) ||
  1444. (psecuritypriv->wpa_pairwise_cipher&WPA_CIPHER_TKIP))
  1445. {
  1446. //todo:
  1447. //ht_cap = _FALSE;
  1448. }
  1449. //ht_cap
  1450. if(pregistrypriv->ht_enable && ht_cap==_TRUE)
  1451. {
  1452. pmlmepriv->htpriv.ht_option = _TRUE;
  1453. pmlmepriv->qospriv.qos_option = 1;
  1454. if(pregistrypriv->ampdu_enable==1)
  1455. {
  1456. pmlmepriv->htpriv.ampdu_enable = _TRUE;
  1457. }
  1458. HT_caps_handler(padapter, (PNDIS_802_11_VARIABLE_IEs)pHT_caps_ie);
  1459. HT_info_handler(padapter, (PNDIS_802_11_VARIABLE_IEs)pHT_info_ie);
  1460. }
  1461. #endif
  1462. //#ifdef CONFIG_80211AC_VHT
  1463. #if 0
  1464. // if channel in 5G band, then add vht ie .
  1465. if ((pbss_network->Configuration.DSConfig > 14) &&
  1466. (pmlmepriv->htpriv.ht_option == _TRUE) &&
  1467. (pregistrypriv->vht_enable)) {
  1468. u8 cap_len, operation_len;
  1469. rtw_vht_use_default_setting(padapter);
  1470. // VHT Capabilities element
  1471. cap_len = rtw_build_vht_cap_ie(padapter, pbss_network->IEs + pbss_network->IELength);
  1472. pbss_network->IELength += cap_len;
  1473. // VHT Operation element
  1474. operation_len = rtw_build_vht_operation_ie(padapter, pbss_network->IEs + pbss_network->IELength, pbss_network->Configuration.DSConfig);
  1475. pbss_network->IELength += operation_len;
  1476. pmlmepriv->vhtpriv.vht_option = _TRUE;
  1477. }
  1478. #endif //CONFIG_80211AC_VHT
  1479. pbss_network->Length = get_WLAN_BSSID_EX_sz((WLAN_BSSID_EX *)pbss_network);
  1480. //issue beacon to start bss network
  1481. start_bss_network(padapter, (u8*)pbss_network);
  1482. //alloc sta_info for ap itself
  1483. psta = rtw_get_stainfo(&padapter->stapriv, pbss_network->MacAddress);
  1484. if(!psta)
  1485. {
  1486. psta = rtw_alloc_stainfo(&padapter->stapriv, pbss_network->MacAddress);
  1487. if (psta == NULL)
  1488. {
  1489. return _FAIL;
  1490. }
  1491. }
  1492. psta->state |= WIFI_AP_STATE; //Aries, add,fix bug of flush_cam_entry at STOP AP mode , 0724
  1493. rtw_indicate_connect( padapter);
  1494. pmlmepriv->cur_network.join_res = _TRUE;//for check if already set beacon
  1495. //update bc/mc sta_info
  1496. //update_bmc_sta(padapter);
  1497. return ret;
  1498. }
  1499. void rtw_set_macaddr_acl(_adapter *padapter, int mode)
  1500. {
  1501. struct sta_priv *pstapriv = &padapter->stapriv;
  1502. struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
  1503. DBG_871X("%s, mode=%d\n", __func__, mode);
  1504. pacl_list->mode = mode;
  1505. }
  1506. int rtw_acl_add_sta(_adapter *padapter, u8 *addr)
  1507. {
  1508. _irqL irqL;
  1509. _list *plist, *phead;
  1510. u8 added = _FALSE;
  1511. int i, ret=0;
  1512. struct rtw_wlan_acl_node *paclnode;
  1513. struct sta_priv *pstapriv = &padapter->stapriv;
  1514. struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
  1515. _queue *pacl_node_q =&pacl_list->acl_node_q;
  1516. DBG_871X("%s(acl_num=%d)=" MAC_FMT "\n", __func__, pacl_list->num, MAC_ARG(addr));
  1517. if((NUM_ACL-1) < pacl_list->num)
  1518. return (-1);
  1519. _enter_critical_bh(&(pacl_node_q->lock), &irqL);
  1520. phead = get_list_head(pacl_node_q);
  1521. plist = get_next(phead);
  1522. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE)
  1523. {
  1524. paclnode = LIST_CONTAINOR(plist, struct rtw_wlan_acl_node, list);
  1525. plist = get_next(plist);
  1526. if(_rtw_memcmp(paclnode->addr, addr, ETH_ALEN))
  1527. {
  1528. if(paclnode->valid == _TRUE)
  1529. {
  1530. added = _TRUE;
  1531. DBG_871X("%s, sta has been added\n", __func__);
  1532. break;
  1533. }
  1534. }
  1535. }
  1536. _exit_critical_bh(&(pacl_node_q->lock), &irqL);
  1537. if(added == _TRUE)
  1538. return ret;
  1539. _enter_critical_bh(&(pacl_node_q->lock), &irqL);
  1540. for(i=0; i< NUM_ACL; i++)
  1541. {
  1542. paclnode = &pacl_list->aclnode[i];
  1543. if(paclnode->valid == _FALSE)
  1544. {
  1545. _rtw_init_listhead(&paclnode->list);
  1546. _rtw_memcpy(paclnode->addr, addr, ETH_ALEN);
  1547. paclnode->valid = _TRUE;
  1548. rtw_list_insert_tail(&paclnode->list, get_list_head(pacl_node_q));
  1549. pacl_list->num++;
  1550. break;
  1551. }
  1552. }
  1553. DBG_871X("%s, acl_num=%d\n", __func__, pacl_list->num);
  1554. _exit_critical_bh(&(pacl_node_q->lock), &irqL);
  1555. return ret;
  1556. }
  1557. int rtw_acl_remove_sta(_adapter *padapter, u8 *addr)
  1558. {
  1559. _irqL irqL;
  1560. _list *plist, *phead;
  1561. int i, ret=0;
  1562. struct rtw_wlan_acl_node *paclnode;
  1563. struct sta_priv *pstapriv = &padapter->stapriv;
  1564. struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
  1565. _queue *pacl_node_q =&pacl_list->acl_node_q;
  1566. DBG_871X("%s(acl_num=%d)=" MAC_FMT "\n", __func__, pacl_list->num, MAC_ARG(addr));
  1567. _enter_critical_bh(&(pacl_node_q->lock), &irqL);
  1568. phead = get_list_head(pacl_node_q);
  1569. plist = get_next(phead);
  1570. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE)
  1571. {
  1572. paclnode = LIST_CONTAINOR(plist, struct rtw_wlan_acl_node, list);
  1573. plist = get_next(plist);
  1574. if(_rtw_memcmp(paclnode->addr, addr, ETH_ALEN))
  1575. {
  1576. if(paclnode->valid == _TRUE)
  1577. {
  1578. paclnode->valid = _FALSE;
  1579. rtw_list_delete(&paclnode->list);
  1580. pacl_list->num--;
  1581. }
  1582. }
  1583. }
  1584. _exit_critical_bh(&(pacl_node_q->lock), &irqL);
  1585. DBG_871X("%s, acl_num=%d\n", __func__, pacl_list->num);
  1586. return ret;
  1587. }
  1588. u8 rtw_ap_set_pairwise_key(_adapter *padapter, struct sta_info *psta)
  1589. {
  1590. struct cmd_obj* ph2c;
  1591. struct set_stakey_parm *psetstakey_para;
  1592. struct cmd_priv *pcmdpriv=&padapter->cmdpriv;
  1593. u8 res=_SUCCESS;
  1594. ph2c = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  1595. if ( ph2c == NULL){
  1596. res= _FAIL;
  1597. goto exit;
  1598. }
  1599. psetstakey_para = (struct set_stakey_parm*)rtw_zmalloc(sizeof(struct set_stakey_parm));
  1600. if(psetstakey_para==NULL){
  1601. rtw_mfree((u8 *) ph2c, sizeof(struct cmd_obj));
  1602. res=_FAIL;
  1603. goto exit;
  1604. }
  1605. init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para, _SetStaKey_CMD_);
  1606. psetstakey_para->algorithm = (u8)psta->dot118021XPrivacy;
  1607. _rtw_memcpy(psetstakey_para->addr, psta->hwaddr, ETH_ALEN);
  1608. _rtw_memcpy(psetstakey_para->key, &psta->dot118021x_UncstKey, 16);
  1609. res = rtw_enqueue_cmd(pcmdpriv, ph2c);
  1610. exit:
  1611. return res;
  1612. }
  1613. static int rtw_ap_set_key(_adapter *padapter, u8 *key, u8 alg, int keyid, u8 set_tx)
  1614. {
  1615. u8 keylen;
  1616. struct cmd_obj* pcmd;
  1617. struct setkey_parm *psetkeyparm;
  1618. struct cmd_priv *pcmdpriv=&(padapter->cmdpriv);
  1619. int res=_SUCCESS;
  1620. //DBG_871X("%s\n", __FUNCTION__);
  1621. pcmd = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  1622. if(pcmd==NULL){
  1623. res= _FAIL;
  1624. goto exit;
  1625. }
  1626. psetkeyparm=(struct setkey_parm*)rtw_zmalloc(sizeof(struct setkey_parm));
  1627. if(psetkeyparm==NULL){
  1628. rtw_mfree((unsigned char *)pcmd, sizeof(struct cmd_obj));
  1629. res= _FAIL;
  1630. goto exit;
  1631. }
  1632. _rtw_memset(psetkeyparm, 0, sizeof(struct setkey_parm));
  1633. psetkeyparm->keyid=(u8)keyid;
  1634. if (is_wep_enc(alg))
  1635. padapter->mlmepriv.key_mask |= BIT(psetkeyparm->keyid);
  1636. psetkeyparm->algorithm = alg;
  1637. psetkeyparm->set_tx = set_tx;
  1638. switch(alg)
  1639. {
  1640. case _WEP40_:
  1641. keylen = 5;
  1642. break;
  1643. case _WEP104_:
  1644. keylen = 13;
  1645. break;
  1646. case _TKIP_:
  1647. case _TKIP_WTMIC_:
  1648. case _AES_:
  1649. keylen = 16;
  1650. break;
  1651. default:
  1652. keylen = 16;
  1653. }
  1654. _rtw_memcpy(&(psetkeyparm->key[0]), key, keylen);
  1655. pcmd->cmdcode = _SetKey_CMD_;
  1656. pcmd->parmbuf = (u8 *)psetkeyparm;
  1657. pcmd->cmdsz = (sizeof(struct setkey_parm));
  1658. pcmd->rsp = NULL;
  1659. pcmd->rspsz = 0;
  1660. _rtw_init_listhead(&pcmd->list);
  1661. res = rtw_enqueue_cmd(pcmdpriv, pcmd);
  1662. exit:
  1663. return res;
  1664. }
  1665. int rtw_ap_set_group_key(_adapter *padapter, u8 *key, u8 alg, int keyid)
  1666. {
  1667. DBG_871X("%s\n", __FUNCTION__);
  1668. return rtw_ap_set_key(padapter, key, alg, keyid, 1);
  1669. }
  1670. int rtw_ap_set_wep_key(_adapter *padapter, u8 *key, u8 keylen, int keyid, u8 set_tx)
  1671. {
  1672. u8 alg;
  1673. switch(keylen)
  1674. {
  1675. case 5:
  1676. alg =_WEP40_;
  1677. break;
  1678. case 13:
  1679. alg =_WEP104_;
  1680. break;
  1681. default:
  1682. alg =_NO_PRIVACY_;
  1683. }
  1684. DBG_871X("%s\n", __FUNCTION__);
  1685. return rtw_ap_set_key(padapter, key, alg, keyid, set_tx);
  1686. }
  1687. #ifdef CONFIG_NATIVEAP_MLME
  1688. static void update_bcn_fixed_ie(_adapter *padapter)
  1689. {
  1690. DBG_871X("%s\n", __FUNCTION__);
  1691. }
  1692. static void update_bcn_erpinfo_ie(_adapter *padapter)
  1693. {
  1694. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1695. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  1696. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1697. WLAN_BSSID_EX *pnetwork = &(pmlmeinfo->network);
  1698. unsigned char *p, *ie = pnetwork->IEs;
  1699. u32 len = 0;
  1700. DBG_871X("%s, ERP_enable=%d\n", __FUNCTION__, pmlmeinfo->ERP_enable);
  1701. if(!pmlmeinfo->ERP_enable)
  1702. return;
  1703. //parsing ERP_IE
  1704. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _ERPINFO_IE_, &len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
  1705. if(p && len>0)
  1706. {
  1707. PNDIS_802_11_VARIABLE_IEs pIE = (PNDIS_802_11_VARIABLE_IEs)p;
  1708. if (pmlmepriv->num_sta_non_erp == 1)
  1709. pIE->data[0] |= RTW_ERP_INFO_NON_ERP_PRESENT|RTW_ERP_INFO_USE_PROTECTION;
  1710. else
  1711. pIE->data[0] &= ~(RTW_ERP_INFO_NON_ERP_PRESENT|RTW_ERP_INFO_USE_PROTECTION);
  1712. if(pmlmepriv->num_sta_no_short_preamble > 0)
  1713. pIE->data[0] |= RTW_ERP_INFO_BARKER_PREAMBLE_MODE;
  1714. else
  1715. pIE->data[0] &= ~(RTW_ERP_INFO_BARKER_PREAMBLE_MODE);
  1716. ERP_IE_handler(padapter, pIE);
  1717. }
  1718. }
  1719. static void update_bcn_htcap_ie(_adapter *padapter)
  1720. {
  1721. DBG_871X("%s\n", __FUNCTION__);
  1722. }
  1723. static void update_bcn_htinfo_ie(_adapter *padapter)
  1724. {
  1725. DBG_871X("%s\n", __FUNCTION__);
  1726. }
  1727. static void update_bcn_rsn_ie(_adapter *padapter)
  1728. {
  1729. DBG_871X("%s\n", __FUNCTION__);
  1730. }
  1731. static void update_bcn_wpa_ie(_adapter *padapter)
  1732. {
  1733. DBG_871X("%s\n", __FUNCTION__);
  1734. }
  1735. static void update_bcn_wmm_ie(_adapter *padapter)
  1736. {
  1737. DBG_871X("%s\n", __FUNCTION__);
  1738. }
  1739. static void update_bcn_wps_ie(_adapter *padapter)
  1740. {
  1741. u8 *pwps_ie=NULL, *pwps_ie_src, *premainder_ie, *pbackup_remainder_ie=NULL;
  1742. uint wps_ielen=0, wps_offset, remainder_ielen;
  1743. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1744. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  1745. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1746. WLAN_BSSID_EX *pnetwork = &(pmlmeinfo->network);
  1747. unsigned char *ie = pnetwork->IEs;
  1748. u32 ielen = pnetwork->IELength;
  1749. DBG_871X("%s\n", __FUNCTION__);
  1750. pwps_ie = rtw_get_wps_ie(ie+_FIXED_IE_LENGTH_, ielen-_FIXED_IE_LENGTH_, NULL, &wps_ielen);
  1751. if(pwps_ie==NULL || wps_ielen==0)
  1752. return;
  1753. wps_offset = (uint)(pwps_ie-ie);
  1754. premainder_ie = pwps_ie + wps_ielen;
  1755. remainder_ielen = ielen - wps_offset - wps_ielen;
  1756. if(remainder_ielen>0)
  1757. {
  1758. pbackup_remainder_ie = rtw_malloc(remainder_ielen);
  1759. if(pbackup_remainder_ie)
  1760. _rtw_memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
  1761. }
  1762. pwps_ie_src = pmlmepriv->wps_beacon_ie;
  1763. if(pwps_ie_src == NULL)
  1764. return;
  1765. wps_ielen = (uint)pwps_ie_src[1];//to get ie data len
  1766. if((wps_offset+wps_ielen+2+remainder_ielen)<=MAX_IE_SZ)
  1767. {
  1768. _rtw_memcpy(pwps_ie, pwps_ie_src, wps_ielen+2);
  1769. pwps_ie += (wps_ielen+2);
  1770. if(pbackup_remainder_ie)
  1771. _rtw_memcpy(pwps_ie, pbackup_remainder_ie, remainder_ielen);
  1772. //update IELength
  1773. pnetwork->IELength = wps_offset + (wps_ielen+2) + remainder_ielen;
  1774. }
  1775. if(pbackup_remainder_ie)
  1776. rtw_mfree(pbackup_remainder_ie, remainder_ielen);
  1777. }
  1778. static void update_bcn_p2p_ie(_adapter *padapter)
  1779. {
  1780. }
  1781. static void update_bcn_vendor_spec_ie(_adapter *padapter, u8*oui)
  1782. {
  1783. DBG_871X("%s\n", __FUNCTION__);
  1784. if(_rtw_memcmp(RTW_WPA_OUI, oui, 4))
  1785. {
  1786. update_bcn_wpa_ie(padapter);
  1787. }
  1788. else if(_rtw_memcmp(WMM_OUI, oui, 4))
  1789. {
  1790. update_bcn_wmm_ie(padapter);
  1791. }
  1792. else if(_rtw_memcmp(WPS_OUI, oui, 4))
  1793. {
  1794. update_bcn_wps_ie(padapter);
  1795. }
  1796. else if(_rtw_memcmp(P2P_OUI, oui, 4))
  1797. {
  1798. update_bcn_p2p_ie(padapter);
  1799. }
  1800. else
  1801. {
  1802. DBG_871X("unknown OUI type!\n");
  1803. }
  1804. }
  1805. void update_beacon(_adapter *padapter, u8 ie_id, u8 *oui, u8 tx)
  1806. {
  1807. _irqL irqL;
  1808. struct mlme_priv *pmlmepriv;
  1809. struct mlme_ext_priv *pmlmeext;
  1810. //struct mlme_ext_info *pmlmeinfo;
  1811. //DBG_871X("%s\n", __FUNCTION__);
  1812. if(!padapter)
  1813. return;
  1814. pmlmepriv = &(padapter->mlmepriv);
  1815. pmlmeext = &(padapter->mlmeextpriv);
  1816. //pmlmeinfo = &(pmlmeext->mlmext_info);
  1817. if(_FALSE == pmlmeext->bstart_bss)
  1818. return;
  1819. _enter_critical_bh(&pmlmepriv->bcn_update_lock, &irqL);
  1820. switch(ie_id)
  1821. {
  1822. case 0xFF:
  1823. update_bcn_fixed_ie(padapter);//8: TimeStamp, 2: Beacon Interval 2:Capability
  1824. break;
  1825. case _TIM_IE_:
  1826. update_BCNTIM(padapter);
  1827. break;
  1828. case _ERPINFO_IE_:
  1829. update_bcn_erpinfo_ie(padapter);
  1830. break;
  1831. case _HT_CAPABILITY_IE_:
  1832. update_bcn_htcap_ie(padapter);
  1833. break;
  1834. case _RSN_IE_2_:
  1835. update_bcn_rsn_ie(padapter);
  1836. break;
  1837. case _HT_ADD_INFO_IE_:
  1838. update_bcn_htinfo_ie(padapter);
  1839. break;
  1840. case _VENDOR_SPECIFIC_IE_:
  1841. update_bcn_vendor_spec_ie(padapter, oui);
  1842. break;
  1843. default:
  1844. break;
  1845. }
  1846. pmlmepriv->update_bcn = _TRUE;
  1847. _exit_critical_bh(&pmlmepriv->bcn_update_lock, &irqL);
  1848. #ifndef CONFIG_INTERRUPT_BASED_TXBCN
  1849. #if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
  1850. if(tx)
  1851. {
  1852. //send_beacon(padapter);//send_beacon must execute on TSR level
  1853. set_tx_beacon_cmd(padapter);
  1854. }
  1855. #else
  1856. {
  1857. //PCI will issue beacon when BCN interrupt occurs.
  1858. }
  1859. #endif
  1860. #endif //!CONFIG_INTERRUPT_BASED_TXBCN
  1861. }
  1862. #ifdef CONFIG_80211N_HT
  1863. /*
  1864. op_mode
  1865. Set to 0 (HT pure) under the followign conditions
  1866. - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or
  1867. - all STAs in the BSS are 20 MHz HT in 20 MHz BSS
  1868. Set to 1 (HT non-member protection) if there may be non-HT STAs
  1869. in both the primary and the secondary channel
  1870. Set to 2 if only HT STAs are associated in BSS,
  1871. however and at least one 20 MHz HT STA is associated
  1872. Set to 3 (HT mixed mode) when one or more non-HT STAs are associated
  1873. (currently non-GF HT station is considered as non-HT STA also)
  1874. */
  1875. static int rtw_ht_operation_update(_adapter *padapter)
  1876. {
  1877. u16 cur_op_mode, new_op_mode;
  1878. int op_mode_changes = 0;
  1879. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1880. struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
  1881. if(pmlmepriv->htpriv.ht_option == _TRUE)
  1882. return 0;
  1883. //if (!iface->conf->ieee80211n || iface->conf->ht_op_mode_fixed)
  1884. // return 0;
  1885. DBG_871X("%s current operation mode=0x%X\n",
  1886. __FUNCTION__, pmlmepriv->ht_op_mode);
  1887. if (!(pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT)
  1888. && pmlmepriv->num_sta_ht_no_gf) {
  1889. pmlmepriv->ht_op_mode |=
  1890. HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
  1891. op_mode_changes++;
  1892. } else if ((pmlmepriv->ht_op_mode &
  1893. HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT) &&
  1894. pmlmepriv->num_sta_ht_no_gf == 0) {
  1895. pmlmepriv->ht_op_mode &=
  1896. ~HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
  1897. op_mode_changes++;
  1898. }
  1899. if (!(pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
  1900. (pmlmepriv->num_sta_no_ht || pmlmepriv->olbc_ht)) {
  1901. pmlmepriv->ht_op_mode |= HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
  1902. op_mode_changes++;
  1903. } else if ((pmlmepriv->ht_op_mode &
  1904. HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
  1905. (pmlmepriv->num_sta_no_ht == 0 && !pmlmepriv->olbc_ht)) {
  1906. pmlmepriv->ht_op_mode &=
  1907. ~HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
  1908. op_mode_changes++;
  1909. }
  1910. /* Note: currently we switch to the MIXED op mode if HT non-greenfield
  1911. * station is associated. Probably it's a theoretical case, since
  1912. * it looks like all known HT STAs support greenfield.
  1913. */
  1914. new_op_mode = 0;
  1915. if (pmlmepriv->num_sta_no_ht ||
  1916. (pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT))
  1917. new_op_mode = OP_MODE_MIXED;
  1918. else if ((phtpriv_ap->ht_cap.cap_info & IEEE80211_HT_CAP_SUP_WIDTH)
  1919. && pmlmepriv->num_sta_ht_20mhz)
  1920. new_op_mode = OP_MODE_20MHZ_HT_STA_ASSOCED;
  1921. else if (pmlmepriv->olbc_ht)
  1922. new_op_mode = OP_MODE_MAY_BE_LEGACY_STAS;
  1923. else
  1924. new_op_mode = OP_MODE_PURE;
  1925. cur_op_mode = pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_OP_MODE_MASK;
  1926. if (cur_op_mode != new_op_mode) {
  1927. pmlmepriv->ht_op_mode &= ~HT_INFO_OPERATION_MODE_OP_MODE_MASK;
  1928. pmlmepriv->ht_op_mode |= new_op_mode;
  1929. op_mode_changes++;
  1930. }
  1931. DBG_871X("%s new operation mode=0x%X changes=%d\n",
  1932. __FUNCTION__, pmlmepriv->ht_op_mode, op_mode_changes);
  1933. return op_mode_changes;
  1934. }
  1935. #endif /* CONFIG_80211N_HT */
  1936. void associated_clients_update(_adapter *padapter, u8 updated)
  1937. {
  1938. //update associcated stations cap.
  1939. if(updated == _TRUE)
  1940. {
  1941. _irqL irqL;
  1942. _list *phead, *plist;
  1943. struct sta_info *psta=NULL;
  1944. struct sta_priv *pstapriv = &padapter->stapriv;
  1945. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  1946. phead = &pstapriv->asoc_list;
  1947. plist = get_next(phead);
  1948. //check asoc_queue
  1949. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE)
  1950. {
  1951. psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
  1952. plist = get_next(plist);
  1953. VCS_update(padapter, psta);
  1954. }
  1955. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  1956. }
  1957. }
  1958. /* called > TSR LEVEL for USB or SDIO Interface*/
  1959. void bss_cap_update_on_sta_join(_adapter *padapter, struct sta_info *psta)
  1960. {
  1961. u8 beacon_updated = _FALSE;
  1962. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1963. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  1964. #if 0
  1965. if (!(psta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
  1966. !psta->no_short_preamble_set) {
  1967. psta->no_short_preamble_set = 1;
  1968. pmlmepriv->num_sta_no_short_preamble++;
  1969. if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
  1970. (pmlmepriv->num_sta_no_short_preamble == 1))
  1971. ieee802_11_set_beacons(hapd->iface);
  1972. }
  1973. #endif
  1974. if(!(psta->flags & WLAN_STA_SHORT_PREAMBLE))
  1975. {
  1976. if(!psta->no_short_preamble_set)
  1977. {
  1978. psta->no_short_preamble_set = 1;
  1979. pmlmepriv->num_sta_no_short_preamble++;
  1980. if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
  1981. (pmlmepriv->num_sta_no_short_preamble == 1))
  1982. {
  1983. beacon_updated = _TRUE;
  1984. update_beacon(padapter, 0xFF, NULL, _TRUE);
  1985. }
  1986. }
  1987. }
  1988. else
  1989. {
  1990. if(psta->no_short_preamble_set)
  1991. {
  1992. psta->no_short_preamble_set = 0;
  1993. pmlmepriv->num_sta_no_short_preamble--;
  1994. if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
  1995. (pmlmepriv->num_sta_no_short_preamble == 0))
  1996. {
  1997. beacon_updated = _TRUE;
  1998. update_beacon(padapter, 0xFF, NULL, _TRUE);
  1999. }
  2000. }
  2001. }
  2002. #if 0
  2003. if (psta->flags & WLAN_STA_NONERP && !psta->nonerp_set) {
  2004. psta->nonerp_set = 1;
  2005. pmlmepriv->num_sta_non_erp++;
  2006. if (pmlmepriv->num_sta_non_erp == 1)
  2007. ieee802_11_set_beacons(hapd->iface);
  2008. }
  2009. #endif
  2010. if(psta->flags & WLAN_STA_NONERP)
  2011. {
  2012. if(!psta->nonerp_set)
  2013. {
  2014. psta->nonerp_set = 1;
  2015. pmlmepriv->num_sta_non_erp++;
  2016. if (pmlmepriv->num_sta_non_erp == 1)
  2017. {
  2018. beacon_updated = _TRUE;
  2019. update_beacon(padapter, _ERPINFO_IE_, NULL, _TRUE);
  2020. }
  2021. }
  2022. }
  2023. else
  2024. {
  2025. if(psta->nonerp_set)
  2026. {
  2027. psta->nonerp_set = 0;
  2028. pmlmepriv->num_sta_non_erp--;
  2029. if (pmlmepriv->num_sta_non_erp == 0)
  2030. {
  2031. beacon_updated = _TRUE;
  2032. update_beacon(padapter, _ERPINFO_IE_, NULL, _TRUE);
  2033. }
  2034. }
  2035. }
  2036. #if 0
  2037. if (!(psta->capability & WLAN_CAPABILITY_SHORT_SLOT) &&
  2038. !psta->no_short_slot_time_set) {
  2039. psta->no_short_slot_time_set = 1;
  2040. pmlmepriv->num_sta_no_short_slot_time++;
  2041. if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
  2042. (pmlmepriv->num_sta_no_short_slot_time == 1))
  2043. ieee802_11_set_beacons(hapd->iface);
  2044. }
  2045. #endif
  2046. if(!(psta->capability & WLAN_CAPABILITY_SHORT_SLOT))
  2047. {
  2048. if(!psta->no_short_slot_time_set)
  2049. {
  2050. psta->no_short_slot_time_set = 1;
  2051. pmlmepriv->num_sta_no_short_slot_time++;
  2052. if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
  2053. (pmlmepriv->num_sta_no_short_slot_time == 1))
  2054. {
  2055. beacon_updated = _TRUE;
  2056. update_beacon(padapter, 0xFF, NULL, _TRUE);
  2057. }
  2058. }
  2059. }
  2060. else
  2061. {
  2062. if(psta->no_short_slot_time_set)
  2063. {
  2064. psta->no_short_slot_time_set = 0;
  2065. pmlmepriv->num_sta_no_short_slot_time--;
  2066. if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
  2067. (pmlmepriv->num_sta_no_short_slot_time == 0))
  2068. {
  2069. beacon_updated = _TRUE;
  2070. update_beacon(padapter, 0xFF, NULL, _TRUE);
  2071. }
  2072. }
  2073. }
  2074. #ifdef CONFIG_80211N_HT
  2075. if (psta->flags & WLAN_STA_HT)
  2076. {
  2077. u16 ht_capab = le16_to_cpu(psta->htpriv.ht_cap.cap_info);
  2078. DBG_871X("HT: STA " MAC_FMT " HT Capabilities "
  2079. "Info: 0x%04x\n", MAC_ARG(psta->hwaddr), ht_capab);
  2080. if (psta->no_ht_set) {
  2081. psta->no_ht_set = 0;
  2082. pmlmepriv->num_sta_no_ht--;
  2083. }
  2084. if ((ht_capab & IEEE80211_HT_CAP_GRN_FLD) == 0) {
  2085. if (!psta->no_ht_gf_set) {
  2086. psta->no_ht_gf_set = 1;
  2087. pmlmepriv->num_sta_ht_no_gf++;
  2088. }
  2089. DBG_871X("%s STA " MAC_FMT " - no "
  2090. "greenfield, num of non-gf stations %d\n",
  2091. __FUNCTION__, MAC_ARG(psta->hwaddr),
  2092. pmlmepriv->num_sta_ht_no_gf);
  2093. }
  2094. if ((ht_capab & IEEE80211_HT_CAP_SUP_WIDTH) == 0) {
  2095. if (!psta->ht_20mhz_set) {
  2096. psta->ht_20mhz_set = 1;
  2097. pmlmepriv->num_sta_ht_20mhz++;
  2098. }
  2099. DBG_871X("%s STA " MAC_FMT " - 20 MHz HT, "
  2100. "num of 20MHz HT STAs %d\n",
  2101. __FUNCTION__, MAC_ARG(psta->hwaddr),
  2102. pmlmepriv->num_sta_ht_20mhz);
  2103. }
  2104. }
  2105. else
  2106. {
  2107. if (!psta->no_ht_set) {
  2108. psta->no_ht_set = 1;
  2109. pmlmepriv->num_sta_no_ht++;
  2110. }
  2111. if(pmlmepriv->htpriv.ht_option == _TRUE) {
  2112. DBG_871X("%s STA " MAC_FMT
  2113. " - no HT, num of non-HT stations %d\n",
  2114. __FUNCTION__, MAC_ARG(psta->hwaddr),
  2115. pmlmepriv->num_sta_no_ht);
  2116. }
  2117. }
  2118. if (rtw_ht_operation_update(padapter) > 0)
  2119. {
  2120. update_beacon(padapter, _HT_CAPABILITY_IE_, NULL, _FALSE);
  2121. update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, _TRUE);
  2122. }
  2123. #endif /* CONFIG_80211N_HT */
  2124. //update associcated stations cap.
  2125. associated_clients_update(padapter, beacon_updated);
  2126. DBG_871X("%s, updated=%d\n", __func__, beacon_updated);
  2127. }
  2128. u8 bss_cap_update_on_sta_leave(_adapter *padapter, struct sta_info *psta)
  2129. {
  2130. u8 beacon_updated = _FALSE;
  2131. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2132. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  2133. if(!psta)
  2134. return beacon_updated;
  2135. if (psta->no_short_preamble_set) {
  2136. psta->no_short_preamble_set = 0;
  2137. pmlmepriv->num_sta_no_short_preamble--;
  2138. if (pmlmeext->cur_wireless_mode > WIRELESS_11B
  2139. && pmlmepriv->num_sta_no_short_preamble == 0)
  2140. {
  2141. beacon_updated = _TRUE;
  2142. update_beacon(padapter, 0xFF, NULL, _TRUE);
  2143. }
  2144. }
  2145. if (psta->nonerp_set) {
  2146. psta->nonerp_set = 0;
  2147. pmlmepriv->num_sta_non_erp--;
  2148. if (pmlmepriv->num_sta_non_erp == 0)
  2149. {
  2150. beacon_updated = _TRUE;
  2151. update_beacon(padapter, _ERPINFO_IE_, NULL, _TRUE);
  2152. }
  2153. }
  2154. if (psta->no_short_slot_time_set) {
  2155. psta->no_short_slot_time_set = 0;
  2156. pmlmepriv->num_sta_no_short_slot_time--;
  2157. if (pmlmeext->cur_wireless_mode > WIRELESS_11B
  2158. && pmlmepriv->num_sta_no_short_slot_time == 0)
  2159. {
  2160. beacon_updated = _TRUE;
  2161. update_beacon(padapter, 0xFF, NULL, _TRUE);
  2162. }
  2163. }
  2164. #ifdef CONFIG_80211N_HT
  2165. if (psta->no_ht_gf_set) {
  2166. psta->no_ht_gf_set = 0;
  2167. pmlmepriv->num_sta_ht_no_gf--;
  2168. }
  2169. if (psta->no_ht_set) {
  2170. psta->no_ht_set = 0;
  2171. pmlmepriv->num_sta_no_ht--;
  2172. }
  2173. if (psta->ht_20mhz_set) {
  2174. psta->ht_20mhz_set = 0;
  2175. pmlmepriv->num_sta_ht_20mhz--;
  2176. }
  2177. if (rtw_ht_operation_update(padapter) > 0)
  2178. {
  2179. update_beacon(padapter, _HT_CAPABILITY_IE_, NULL, _FALSE);
  2180. update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, _TRUE);
  2181. }
  2182. #endif /* CONFIG_80211N_HT */
  2183. //update associcated stations cap.
  2184. //associated_clients_update(padapter, beacon_updated); //move it to avoid deadlock
  2185. DBG_871X("%s, updated=%d\n", __func__, beacon_updated);
  2186. return beacon_updated;
  2187. }
  2188. u8 ap_free_sta(_adapter *padapter, struct sta_info *psta, bool active, u16 reason)
  2189. {
  2190. _irqL irqL;
  2191. u8 beacon_updated = _FALSE;
  2192. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2193. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  2194. struct sta_priv *pstapriv = &padapter->stapriv;
  2195. if(!psta)
  2196. return beacon_updated;
  2197. if (active == _TRUE)
  2198. {
  2199. #ifdef CONFIG_80211N_HT
  2200. //tear down Rx AMPDU
  2201. send_delba(padapter, 0, psta->hwaddr);// recipient
  2202. //tear down TX AMPDU
  2203. send_delba(padapter, 1, psta->hwaddr);// // originator
  2204. #endif //CONFIG_80211N_HT
  2205. issue_deauth(padapter, psta->hwaddr, reason);
  2206. }
  2207. psta->htpriv.agg_enable_bitmap = 0x0;//reset
  2208. psta->htpriv.candidate_tid_bitmap = 0x0;//reset
  2209. //report_del_sta_event(padapter, psta->hwaddr, reason);
  2210. //clear cam entry / key
  2211. //clear_cam_entry(padapter, (psta->mac_id + 3));
  2212. rtw_clearstakey_cmd(padapter, (u8*)psta, (u8)rtw_get_camid(psta->mac_id), _TRUE);
  2213. _enter_critical_bh(&psta->lock, &irqL);
  2214. psta->state &= ~_FW_LINKED;
  2215. _exit_critical_bh(&psta->lock, &irqL);
  2216. #ifdef CONFIG_IOCTL_CFG80211
  2217. if (1) {
  2218. #ifdef COMPAT_KERNEL_RELEASE
  2219. rtw_cfg80211_indicate_sta_disassoc(padapter, psta->hwaddr, reason);
  2220. #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) && !defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER)
  2221. rtw_cfg80211_indicate_sta_disassoc(padapter, psta->hwaddr, reason);
  2222. #else //(LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) && !defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER)
  2223. /* will call rtw_cfg80211_indicate_sta_disassoc() in cmd_thread for old API context */
  2224. #endif //(LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) && !defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER)
  2225. } else
  2226. #endif //CONFIG_IOCTL_CFG80211
  2227. {
  2228. rtw_indicate_sta_disassoc_event(padapter, psta);
  2229. }
  2230. report_del_sta_event(padapter, psta->hwaddr, reason);
  2231. beacon_updated = bss_cap_update_on_sta_leave(padapter, psta);
  2232. _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL);
  2233. rtw_free_stainfo(padapter, psta);
  2234. _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL);
  2235. return beacon_updated;
  2236. }
  2237. int rtw_ap_inform_ch_switch(_adapter *padapter, u8 new_ch, u8 ch_offset)
  2238. {
  2239. _irqL irqL;
  2240. _list *phead, *plist;
  2241. int ret=0;
  2242. struct sta_info *psta = NULL;
  2243. struct sta_priv *pstapriv = &padapter->stapriv;
  2244. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  2245. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2246. u8 bc_addr[ETH_ALEN] = {0xff,0xff,0xff,0xff,0xff,0xff};
  2247. if((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE)
  2248. return ret;
  2249. DBG_871X(FUNC_NDEV_FMT" with ch:%u, offset:%u\n",
  2250. FUNC_NDEV_ARG(padapter->pnetdev), new_ch, ch_offset);
  2251. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  2252. phead = &pstapriv->asoc_list;
  2253. plist = get_next(phead);
  2254. /* for each sta in asoc_queue */
  2255. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE)
  2256. {
  2257. psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
  2258. plist = get_next(plist);
  2259. issue_action_spct_ch_switch(padapter, psta->hwaddr, new_ch, ch_offset);
  2260. psta->expire_to = ((pstapriv->expire_to * 2) > 5) ? 5 : (pstapriv->expire_to * 2);
  2261. }
  2262. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  2263. issue_action_spct_ch_switch(padapter, bc_addr, new_ch, ch_offset);
  2264. return ret;
  2265. }
  2266. int rtw_sta_flush(_adapter *padapter)
  2267. {
  2268. _irqL irqL;
  2269. _list *phead, *plist;
  2270. int ret=0;
  2271. struct sta_info *psta = NULL;
  2272. struct sta_priv *pstapriv = &padapter->stapriv;
  2273. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  2274. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2275. u8 bc_addr[ETH_ALEN] = {0xff,0xff,0xff,0xff,0xff,0xff};
  2276. DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(padapter->pnetdev));
  2277. if((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE)
  2278. return ret;
  2279. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  2280. phead = &pstapriv->asoc_list;
  2281. plist = get_next(phead);
  2282. //free sta asoc_queue
  2283. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE)
  2284. {
  2285. psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
  2286. plist = get_next(plist);
  2287. rtw_list_delete(&psta->asoc_list);
  2288. pstapriv->asoc_list_cnt--;
  2289. //_exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  2290. ap_free_sta(padapter, psta, _TRUE, WLAN_REASON_DEAUTH_LEAVING);
  2291. //_enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  2292. }
  2293. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  2294. issue_deauth(padapter, bc_addr, WLAN_REASON_DEAUTH_LEAVING);
  2295. associated_clients_update(padapter, _TRUE);
  2296. return ret;
  2297. }
  2298. /* called > TSR LEVEL for USB or SDIO Interface*/
  2299. void sta_info_update(_adapter *padapter, struct sta_info *psta)
  2300. {
  2301. int flags = psta->flags;
  2302. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2303. //update wmm cap.
  2304. if(WLAN_STA_WME&flags)
  2305. psta->qos_option = 1;
  2306. else
  2307. psta->qos_option = 0;
  2308. if(pmlmepriv->qospriv.qos_option == 0)
  2309. psta->qos_option = 0;
  2310. #ifdef CONFIG_80211N_HT
  2311. //update 802.11n ht cap.
  2312. if(WLAN_STA_HT&flags)
  2313. {
  2314. psta->htpriv.ht_option = _TRUE;
  2315. psta->qos_option = 1;
  2316. }
  2317. else
  2318. {
  2319. psta->htpriv.ht_option = _FALSE;
  2320. }
  2321. if(pmlmepriv->htpriv.ht_option == _FALSE)
  2322. psta->htpriv.ht_option = _FALSE;
  2323. #endif
  2324. #ifdef CONFIG_80211AC_VHT
  2325. //update 802.11AC vht cap.
  2326. if(WLAN_STA_VHT&flags)
  2327. {
  2328. psta->vhtpriv.vht_option = _TRUE;
  2329. }
  2330. else
  2331. {
  2332. psta->vhtpriv.vht_option = _FALSE;
  2333. }
  2334. if(pmlmepriv->vhtpriv.vht_option == _FALSE)
  2335. psta->vhtpriv.vht_option = _FALSE;
  2336. #endif
  2337. update_sta_info_apmode(padapter, psta);
  2338. }
  2339. /* called >= TSR LEVEL for USB or SDIO Interface*/
  2340. void ap_sta_info_defer_update(_adapter *padapter, struct sta_info *psta)
  2341. {
  2342. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  2343. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2344. if(psta->state & _FW_LINKED)
  2345. {
  2346. pmlmeinfo->FW_sta_info[psta->mac_id].psta = psta;
  2347. //add ratid
  2348. add_RATid(padapter, psta, 0);//DM_RATR_STA_INIT
  2349. }
  2350. }
  2351. /* restore hw setting from sw data structures */
  2352. void rtw_ap_restore_network(_adapter *padapter)
  2353. {
  2354. struct mlme_priv *mlmepriv = &padapter->mlmepriv;
  2355. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  2356. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2357. struct sta_priv * pstapriv = &padapter->stapriv;
  2358. struct sta_info *psta;
  2359. struct security_priv* psecuritypriv=&(padapter->securitypriv);
  2360. _irqL irqL;
  2361. _list *phead, *plist;
  2362. u8 chk_alive_num = 0;
  2363. char chk_alive_list[NUM_STA];
  2364. int i;
  2365. rtw_setopmode_cmd(padapter, Ndis802_11APMode);
  2366. set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
  2367. start_bss_network(padapter, (u8*)&mlmepriv->cur_network.network);
  2368. if((padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_) ||
  2369. (padapter->securitypriv.dot11PrivacyAlgrthm == _AES_))
  2370. {
  2371. /* restore group key, WEP keys is restored in ips_leave() */
  2372. rtw_set_key(padapter, psecuritypriv, psecuritypriv->dot118021XGrpKeyid, 0);
  2373. }
  2374. /* per sta pairwise key and settings */
  2375. if((padapter->securitypriv.dot11PrivacyAlgrthm != _TKIP_) &&
  2376. (padapter->securitypriv.dot11PrivacyAlgrthm != _AES_)) {
  2377. return;
  2378. }
  2379. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  2380. phead = &pstapriv->asoc_list;
  2381. plist = get_next(phead);
  2382. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  2383. int stainfo_offset;
  2384. psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
  2385. plist = get_next(plist);
  2386. stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
  2387. if (stainfo_offset_valid(stainfo_offset)) {
  2388. chk_alive_list[chk_alive_num++] = stainfo_offset;
  2389. }
  2390. }
  2391. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  2392. for (i = 0; i < chk_alive_num; i++) {
  2393. psta = rtw_get_stainfo_by_offset(pstapriv, chk_alive_list[i]);
  2394. if (psta == NULL) {
  2395. DBG_871X(FUNC_ADPT_FMT" sta_info is null\n", FUNC_ADPT_ARG(padapter));
  2396. } else if (psta->state &_FW_LINKED) {
  2397. Update_RA_Entry(padapter, psta);
  2398. //pairwise key
  2399. rtw_setstakey_cmd(padapter, (unsigned char *)psta, _TRUE);
  2400. }
  2401. }
  2402. }
  2403. void start_ap_mode(_adapter *padapter)
  2404. {
  2405. int i;
  2406. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2407. struct sta_priv *pstapriv = &padapter->stapriv;
  2408. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  2409. struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
  2410. pmlmepriv->update_bcn = _FALSE;
  2411. //init_mlme_ap_info(padapter);
  2412. pmlmeext->bstart_bss = _FALSE;
  2413. pmlmepriv->num_sta_non_erp = 0;
  2414. pmlmepriv->num_sta_no_short_slot_time = 0;
  2415. pmlmepriv->num_sta_no_short_preamble = 0;
  2416. pmlmepriv->num_sta_ht_no_gf = 0;
  2417. #ifdef CONFIG_80211N_HT
  2418. pmlmepriv->num_sta_no_ht = 0;
  2419. #endif //CONFIG_80211N_HT
  2420. pmlmepriv->num_sta_ht_20mhz = 0;
  2421. pmlmepriv->olbc = _FALSE;
  2422. pmlmepriv->olbc_ht = _FALSE;
  2423. #ifdef CONFIG_80211N_HT
  2424. pmlmepriv->ht_op_mode = 0;
  2425. #endif
  2426. for(i=0; i<NUM_STA; i++)
  2427. pstapriv->sta_aid[i] = NULL;
  2428. pmlmepriv->wps_beacon_ie = NULL;
  2429. pmlmepriv->wps_probe_resp_ie = NULL;
  2430. pmlmepriv->wps_assoc_resp_ie = NULL;
  2431. pmlmepriv->p2p_beacon_ie = NULL;
  2432. pmlmepriv->p2p_probe_resp_ie = NULL;
  2433. //for ACL
  2434. _rtw_init_listhead(&(pacl_list->acl_node_q.queue));
  2435. pacl_list->num = 0;
  2436. pacl_list->mode = 0;
  2437. for(i = 0; i < NUM_ACL; i++)
  2438. {
  2439. _rtw_init_listhead(&pacl_list->aclnode[i].list);
  2440. pacl_list->aclnode[i].valid = _FALSE;
  2441. }
  2442. }
  2443. void stop_ap_mode(_adapter *padapter)
  2444. {
  2445. _irqL irqL;
  2446. _list *phead, *plist;
  2447. struct rtw_wlan_acl_node *paclnode;
  2448. struct sta_info *psta=NULL;
  2449. struct sta_priv *pstapriv = &padapter->stapriv;
  2450. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2451. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  2452. struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
  2453. _queue *pacl_node_q =&pacl_list->acl_node_q;
  2454. pmlmepriv->update_bcn = _FALSE;
  2455. pmlmeext->bstart_bss = _FALSE;
  2456. //_rtw_spinlock_free(&pmlmepriv->bcn_update_lock);
  2457. //reset and init security priv , this can refine with rtw_reset_securitypriv
  2458. _rtw_memset((unsigned char *)&padapter->securitypriv, 0, sizeof (struct security_priv));
  2459. padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
  2460. padapter->securitypriv.ndisencryptstatus = Ndis802_11WEPDisabled;
  2461. //for ACL
  2462. _enter_critical_bh(&(pacl_node_q->lock), &irqL);
  2463. phead = get_list_head(pacl_node_q);
  2464. plist = get_next(phead);
  2465. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE)
  2466. {
  2467. paclnode = LIST_CONTAINOR(plist, struct rtw_wlan_acl_node, list);
  2468. plist = get_next(plist);
  2469. if(paclnode->valid == _TRUE)
  2470. {
  2471. paclnode->valid = _FALSE;
  2472. rtw_list_delete(&paclnode->list);
  2473. pacl_list->num--;
  2474. }
  2475. }
  2476. _exit_critical_bh(&(pacl_node_q->lock), &irqL);
  2477. DBG_871X("%s, free acl_node_queue, num=%d\n", __func__, pacl_list->num);
  2478. rtw_sta_flush(padapter);
  2479. //free_assoc_sta_resources
  2480. rtw_free_all_stainfo(padapter);
  2481. psta = rtw_get_bcmc_stainfo(padapter);
  2482. _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL);
  2483. rtw_free_stainfo(padapter, psta);
  2484. _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL);
  2485. rtw_init_bcmc_stainfo(padapter);
  2486. rtw_free_mlme_priv_ie_data(pmlmepriv);
  2487. }
  2488. #endif //CONFIG_NATIVEAP_MLME
  2489. #endif //CONFIG_AP_MODE