rtw_wlan_util.c 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822
  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_WLAN_UTIL_C_
  21. #include <drv_types.h>
  22. unsigned char ARTHEROS_OUI1[] = {0x00, 0x03, 0x7f};
  23. unsigned char ARTHEROS_OUI2[] = {0x00, 0x13, 0x74};
  24. unsigned char BROADCOM_OUI1[] = {0x00, 0x10, 0x18};
  25. unsigned char BROADCOM_OUI2[] = {0x00, 0x0a, 0xf7};
  26. unsigned char BROADCOM_OUI3[] = {0x00, 0x05, 0xb5};
  27. unsigned char CISCO_OUI[] = {0x00, 0x40, 0x96};
  28. unsigned char MARVELL_OUI[] = {0x00, 0x50, 0x43};
  29. unsigned char RALINK_OUI[] = {0x00, 0x0c, 0x43};
  30. unsigned char REALTEK_OUI[] = {0x00, 0xe0, 0x4c};
  31. unsigned char AIRGOCAP_OUI[] = {0x00, 0x0a, 0xf5};
  32. unsigned char REALTEK_96B_IE[] = {0x00, 0xe0, 0x4c, 0x02, 0x01, 0x20};
  33. extern unsigned char MCS_rate_2R[16];
  34. #ifdef CONFIG_DISABLE_MCS13TO15
  35. extern unsigned char MCS_rate_2R_MCS13TO15_OFF[16];
  36. #endif //CONFIG_DISABLE_MCS13TO15
  37. extern unsigned char MCS_rate_1R[16];
  38. extern unsigned char RTW_WPA_OUI[];
  39. extern unsigned char WPA_TKIP_CIPHER[4];
  40. extern unsigned char RSN_TKIP_CIPHER[4];
  41. #define R2T_PHY_DELAY (0)
  42. //#define WAIT_FOR_BCN_TO_MIN (3000)
  43. #define WAIT_FOR_BCN_TO_MIN (6000)
  44. #define WAIT_FOR_BCN_TO_MAX (20000)
  45. static u8 rtw_basic_rate_cck[4] = {
  46. IEEE80211_CCK_RATE_1MB|IEEE80211_BASIC_RATE_MASK, IEEE80211_CCK_RATE_2MB|IEEE80211_BASIC_RATE_MASK,
  47. IEEE80211_CCK_RATE_5MB|IEEE80211_BASIC_RATE_MASK, IEEE80211_CCK_RATE_11MB|IEEE80211_BASIC_RATE_MASK
  48. };
  49. static u8 rtw_basic_rate_ofdm[3] = {
  50. IEEE80211_OFDM_RATE_6MB|IEEE80211_BASIC_RATE_MASK, IEEE80211_OFDM_RATE_12MB|IEEE80211_BASIC_RATE_MASK,
  51. IEEE80211_OFDM_RATE_24MB|IEEE80211_BASIC_RATE_MASK
  52. };
  53. static u8 rtw_basic_rate_mix[7] = {
  54. IEEE80211_CCK_RATE_1MB|IEEE80211_BASIC_RATE_MASK, IEEE80211_CCK_RATE_2MB|IEEE80211_BASIC_RATE_MASK,
  55. IEEE80211_CCK_RATE_5MB|IEEE80211_BASIC_RATE_MASK, IEEE80211_CCK_RATE_11MB|IEEE80211_BASIC_RATE_MASK,
  56. IEEE80211_OFDM_RATE_6MB|IEEE80211_BASIC_RATE_MASK, IEEE80211_OFDM_RATE_12MB|IEEE80211_BASIC_RATE_MASK,
  57. IEEE80211_OFDM_RATE_24MB|IEEE80211_BASIC_RATE_MASK
  58. };
  59. int cckrates_included(unsigned char *rate, int ratelen)
  60. {
  61. int i;
  62. for(i = 0; i < ratelen; i++)
  63. {
  64. if ( (((rate[i]) & 0x7f) == 2) || (((rate[i]) & 0x7f) == 4) ||
  65. (((rate[i]) & 0x7f) == 11) || (((rate[i]) & 0x7f) == 22) )
  66. return _TRUE;
  67. }
  68. return _FALSE;
  69. }
  70. int cckratesonly_included(unsigned char *rate, int ratelen)
  71. {
  72. int i;
  73. for(i = 0; i < ratelen; i++)
  74. {
  75. if ( (((rate[i]) & 0x7f) != 2) && (((rate[i]) & 0x7f) != 4) &&
  76. (((rate[i]) & 0x7f) != 11) && (((rate[i]) & 0x7f) != 22) )
  77. return _FALSE;
  78. }
  79. return _TRUE;
  80. }
  81. u8 networktype_to_raid(_adapter *adapter,unsigned char network_type)
  82. {
  83. unsigned char raid;
  84. switch(network_type)
  85. {
  86. case WIRELESS_11B:
  87. raid = RATR_INX_WIRELESS_B;
  88. break;
  89. case WIRELESS_11A:
  90. case WIRELESS_11G:
  91. raid = RATR_INX_WIRELESS_G;
  92. break;
  93. case WIRELESS_11BG:
  94. raid = RATR_INX_WIRELESS_GB;
  95. break;
  96. case WIRELESS_11_24N:
  97. case WIRELESS_11_5N:
  98. raid = RATR_INX_WIRELESS_N;
  99. break;
  100. case WIRELESS_11A_5N:
  101. case WIRELESS_11G_24N:
  102. raid = RATR_INX_WIRELESS_NG;
  103. break;
  104. case WIRELESS_11BG_24N:
  105. raid = RATR_INX_WIRELESS_NGB;
  106. break;
  107. default:
  108. raid = RATR_INX_WIRELESS_GB;
  109. break;
  110. }
  111. return raid;
  112. }
  113. u8 networktype_to_raid_ex(_adapter *adapter,unsigned char network_type)
  114. {
  115. struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
  116. u8 raid, rf_type;
  117. rtw_hal_get_hwreg(adapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
  118. switch(network_type)
  119. {
  120. case WIRELESS_11B:
  121. raid = RATEID_IDX_B;
  122. break;
  123. case WIRELESS_11A:
  124. case WIRELESS_11G:
  125. raid = RATEID_IDX_G;
  126. break;
  127. case WIRELESS_11BG:
  128. raid = RATEID_IDX_BG;
  129. break;
  130. case WIRELESS_11_24N:
  131. case WIRELESS_11_5N:
  132. case WIRELESS_11A_5N:
  133. case WIRELESS_11G_24N:
  134. if (rf_type == 2)
  135. raid = RATEID_IDX_GN_N2SS;
  136. else
  137. raid = RATEID_IDX_GN_N1SS;
  138. break;
  139. case WIRELESS_11B_24N:
  140. case WIRELESS_11BG_24N:
  141. if (pmlmeext->cur_bwmode == CHANNEL_WIDTH_20) {
  142. if (rf_type == RF_2T2R)
  143. raid = RATEID_IDX_BGN_20M_2SS_BN;
  144. else
  145. raid = RATEID_IDX_BGN_20M_1SS_BN;
  146. } else {
  147. if (rf_type == RF_2T2R)
  148. raid = RATEID_IDX_BGN_40M_2SS;
  149. else
  150. raid = RATEID_IDX_BGN_40M_1SS;
  151. }
  152. break;
  153. #ifdef CONFIG_80211AC_VHT
  154. case WIRELESS_11_5AC:
  155. case WIRELESS_11_24AC:
  156. if ((rf_type == RF_1T1R) || (adapter->mlmepriv.vhtpriv.vht_highest_rate <= MGN_VHT1SS_MCS9))
  157. raid = RATEID_IDX_VHT_1SS;
  158. else
  159. raid = RATEID_IDX_VHT_2SS;
  160. break;
  161. #endif
  162. default:
  163. raid = RATEID_IDX_BGN_40M_2SS;
  164. break;
  165. }
  166. return raid;
  167. }
  168. u8 judge_network_type(_adapter *padapter, unsigned char *rate, int ratelen)
  169. {
  170. u8 network_type = 0;
  171. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  172. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  173. if(pmlmeext->cur_channel > 14)
  174. {
  175. if (pmlmeinfo->VHT_enable)
  176. network_type = WIRELESS_11AC;
  177. else if (pmlmeinfo->HT_enable)
  178. network_type = WIRELESS_11_5N;
  179. network_type |= WIRELESS_11A;
  180. }
  181. else
  182. {
  183. if (pmlmeinfo->HT_enable)
  184. {
  185. network_type = WIRELESS_11_24N;
  186. }
  187. if ((cckratesonly_included(rate, ratelen)) == _TRUE)
  188. {
  189. network_type |= WIRELESS_11B;
  190. }
  191. else if((cckrates_included(rate, ratelen)) == _TRUE)
  192. {
  193. network_type |= WIRELESS_11BG;
  194. }
  195. else
  196. {
  197. network_type |= WIRELESS_11G;
  198. }
  199. }
  200. return network_type;
  201. }
  202. unsigned char ratetbl_val_2wifirate(unsigned char rate);
  203. unsigned char ratetbl_val_2wifirate(unsigned char rate)
  204. {
  205. unsigned char val = 0;
  206. switch (rate & 0x7f)
  207. {
  208. case 0:
  209. val = IEEE80211_CCK_RATE_1MB;
  210. break;
  211. case 1:
  212. val = IEEE80211_CCK_RATE_2MB;
  213. break;
  214. case 2:
  215. val = IEEE80211_CCK_RATE_5MB;
  216. break;
  217. case 3:
  218. val = IEEE80211_CCK_RATE_11MB;
  219. break;
  220. case 4:
  221. val = IEEE80211_OFDM_RATE_6MB;
  222. break;
  223. case 5:
  224. val = IEEE80211_OFDM_RATE_9MB;
  225. break;
  226. case 6:
  227. val = IEEE80211_OFDM_RATE_12MB;
  228. break;
  229. case 7:
  230. val = IEEE80211_OFDM_RATE_18MB;
  231. break;
  232. case 8:
  233. val = IEEE80211_OFDM_RATE_24MB;
  234. break;
  235. case 9:
  236. val = IEEE80211_OFDM_RATE_36MB;
  237. break;
  238. case 10:
  239. val = IEEE80211_OFDM_RATE_48MB;
  240. break;
  241. case 11:
  242. val = IEEE80211_OFDM_RATE_54MB;
  243. break;
  244. }
  245. return val;
  246. }
  247. int is_basicrate(_adapter *padapter, unsigned char rate);
  248. int is_basicrate(_adapter *padapter, unsigned char rate)
  249. {
  250. int i;
  251. unsigned char val;
  252. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  253. for(i = 0; i < NumRates; i++)
  254. {
  255. val = pmlmeext->basicrate[i];
  256. if ((val != 0xff) && (val != 0xfe))
  257. {
  258. if (rate == ratetbl_val_2wifirate(val))
  259. {
  260. return _TRUE;
  261. }
  262. }
  263. }
  264. return _FALSE;
  265. }
  266. unsigned int ratetbl2rateset(_adapter *padapter, unsigned char *rateset);
  267. unsigned int ratetbl2rateset(_adapter *padapter, unsigned char *rateset)
  268. {
  269. int i;
  270. unsigned char rate;
  271. unsigned int len = 0;
  272. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  273. for (i = 0; i < NumRates; i++)
  274. {
  275. rate = pmlmeext->datarate[i];
  276. switch (rate)
  277. {
  278. case 0xff:
  279. return len;
  280. case 0xfe:
  281. continue;
  282. default:
  283. rate = ratetbl_val_2wifirate(rate);
  284. if (is_basicrate(padapter, rate) == _TRUE)
  285. {
  286. rate |= IEEE80211_BASIC_RATE_MASK;
  287. }
  288. rateset[len] = rate;
  289. len++;
  290. break;
  291. }
  292. }
  293. return len;
  294. }
  295. void get_rate_set(_adapter *padapter, unsigned char *pbssrate, int *bssrate_len)
  296. {
  297. unsigned char supportedrates[NumRates];
  298. _rtw_memset(supportedrates, 0, NumRates);
  299. *bssrate_len = ratetbl2rateset(padapter, supportedrates);
  300. _rtw_memcpy(pbssrate, supportedrates, *bssrate_len);
  301. }
  302. void UpdateBrateTbl(
  303. IN PADAPTER Adapter,
  304. IN u8 *mBratesOS
  305. )
  306. {
  307. u8 i;
  308. u8 rate;
  309. // 1M, 2M, 5.5M, 11M, 6M, 12M, 24M are mandatory.
  310. for(i=0;i<NDIS_802_11_LENGTH_RATES_EX;i++)
  311. {
  312. rate = mBratesOS[i] & 0x7f;
  313. switch(rate)
  314. {
  315. case IEEE80211_CCK_RATE_1MB:
  316. case IEEE80211_CCK_RATE_2MB:
  317. case IEEE80211_CCK_RATE_5MB:
  318. case IEEE80211_CCK_RATE_11MB:
  319. case IEEE80211_OFDM_RATE_6MB:
  320. case IEEE80211_OFDM_RATE_12MB:
  321. case IEEE80211_OFDM_RATE_24MB:
  322. mBratesOS[i] |= IEEE80211_BASIC_RATE_MASK;
  323. break;
  324. }
  325. }
  326. }
  327. void UpdateBrateTblForSoftAP(u8 *bssrateset, u32 bssratelen)
  328. {
  329. u8 i;
  330. u8 rate;
  331. for(i=0;i<bssratelen;i++)
  332. {
  333. rate = bssrateset[i] & 0x7f;
  334. switch(rate)
  335. {
  336. case IEEE80211_CCK_RATE_1MB:
  337. case IEEE80211_CCK_RATE_2MB:
  338. case IEEE80211_CCK_RATE_5MB:
  339. case IEEE80211_CCK_RATE_11MB:
  340. bssrateset[i] |= IEEE80211_BASIC_RATE_MASK;
  341. break;
  342. }
  343. }
  344. }
  345. void Save_DM_Func_Flag(_adapter *padapter)
  346. {
  347. u8 bSaveFlag = _TRUE;
  348. #ifdef CONFIG_CONCURRENT_MODE
  349. _adapter *pbuddy_adapter = padapter->pbuddy_adapter;
  350. if(pbuddy_adapter)
  351. rtw_hal_set_hwreg(pbuddy_adapter, HW_VAR_DM_FUNC_OP, (u8 *)(&bSaveFlag));
  352. #endif
  353. rtw_hal_set_hwreg(padapter, HW_VAR_DM_FUNC_OP, (u8 *)(&bSaveFlag));
  354. }
  355. void Restore_DM_Func_Flag(_adapter *padapter)
  356. {
  357. u8 bSaveFlag = _FALSE;
  358. #ifdef CONFIG_CONCURRENT_MODE
  359. _adapter *pbuddy_adapter = padapter->pbuddy_adapter;
  360. if(pbuddy_adapter)
  361. rtw_hal_set_hwreg(pbuddy_adapter, HW_VAR_DM_FUNC_OP, (u8 *)(&bSaveFlag));
  362. #endif
  363. rtw_hal_set_hwreg(padapter, HW_VAR_DM_FUNC_OP, (u8 *)(&bSaveFlag));
  364. }
  365. void Switch_DM_Func(_adapter *padapter, u32 mode, u8 enable)
  366. {
  367. #ifdef CONFIG_CONCURRENT_MODE
  368. _adapter *pbuddy_adapter = padapter->pbuddy_adapter;
  369. #endif
  370. if(enable == _TRUE)
  371. {
  372. #ifdef CONFIG_CONCURRENT_MODE
  373. if(pbuddy_adapter)
  374. rtw_hal_set_hwreg(pbuddy_adapter, HW_VAR_DM_FUNC_SET, (u8 *)(&mode));
  375. #endif
  376. rtw_hal_set_hwreg(padapter, HW_VAR_DM_FUNC_SET, (u8 *)(&mode));
  377. }
  378. else
  379. {
  380. #ifdef CONFIG_CONCURRENT_MODE
  381. if(pbuddy_adapter)
  382. rtw_hal_set_hwreg(pbuddy_adapter, HW_VAR_DM_FUNC_CLR, (u8 *)(&mode));
  383. #endif
  384. rtw_hal_set_hwreg(padapter, HW_VAR_DM_FUNC_CLR, (u8 *)(&mode));
  385. }
  386. #if 0
  387. u8 val8;
  388. val8 = rtw_read8(padapter, FW_DYNAMIC_FUN_SWITCH);
  389. if(enable == _TRUE)
  390. {
  391. rtw_write8(padapter, FW_DYNAMIC_FUN_SWITCH, (val8 | mode));
  392. }
  393. else
  394. {
  395. rtw_write8(padapter, FW_DYNAMIC_FUN_SWITCH, (val8 & mode));
  396. }
  397. #endif
  398. }
  399. static void Set_NETYPE1_MSR(_adapter *padapter, u8 type)
  400. {
  401. rtw_hal_set_hwreg(padapter, HW_VAR_MEDIA_STATUS1, (u8 *)(&type));
  402. }
  403. static void Set_NETYPE0_MSR(_adapter *padapter, u8 type)
  404. {
  405. rtw_hal_set_hwreg(padapter, HW_VAR_MEDIA_STATUS, (u8 *)(&type));
  406. }
  407. void Set_MSR(_adapter *padapter, u8 type)
  408. {
  409. #ifdef CONFIG_CONCURRENT_MODE
  410. if(padapter->iface_type == IFACE_PORT1)
  411. {
  412. Set_NETYPE1_MSR(padapter, type);
  413. }
  414. else
  415. #endif
  416. {
  417. Set_NETYPE0_MSR(padapter, type);
  418. }
  419. }
  420. inline u8 rtw_get_oper_ch(_adapter *adapter)
  421. {
  422. return adapter_to_dvobj(adapter)->oper_channel;
  423. }
  424. inline void rtw_set_oper_ch(_adapter *adapter, u8 ch)
  425. {
  426. adapter_to_dvobj(adapter)->oper_channel = ch;
  427. }
  428. inline u8 rtw_get_oper_bw(_adapter *adapter)
  429. {
  430. return adapter_to_dvobj(adapter)->oper_bwmode;
  431. }
  432. inline void rtw_set_oper_bw(_adapter *adapter, u8 bw)
  433. {
  434. adapter_to_dvobj(adapter)->oper_bwmode = bw;
  435. }
  436. inline u8 rtw_get_oper_choffset(_adapter *adapter)
  437. {
  438. return adapter_to_dvobj(adapter)->oper_ch_offset;
  439. }
  440. inline void rtw_set_oper_choffset(_adapter *adapter, u8 offset)
  441. {
  442. adapter_to_dvobj(adapter)->oper_ch_offset = offset;
  443. }
  444. u8 rtw_get_center_ch(u8 channel, u8 chnl_bw, u8 chnl_offset)
  445. {
  446. u8 center_ch = channel;
  447. if(chnl_bw == CHANNEL_WIDTH_80)
  448. {
  449. if((channel == 36) || (channel == 40) || (channel == 44) || (channel == 48) )
  450. center_ch = 42;
  451. if((channel == 52) || (channel == 56) || (channel == 60) || (channel == 64) )
  452. center_ch = 58;
  453. if((channel == 100) || (channel == 104) || (channel == 108) || (channel == 112) )
  454. center_ch = 106;
  455. if((channel == 116) || (channel == 120) || (channel == 124) || (channel == 128) )
  456. center_ch = 122;
  457. if((channel == 132) || (channel == 136) || (channel == 140) || (channel == 144) )
  458. center_ch = 138;
  459. if((channel == 149) || (channel == 153) || (channel == 157) || (channel == 161) )
  460. center_ch = 155;
  461. else if(channel <= 14)
  462. center_ch = 7;
  463. }
  464. else if(chnl_bw == CHANNEL_WIDTH_40)
  465. {
  466. if (chnl_offset == HAL_PRIME_CHNL_OFFSET_LOWER)
  467. center_ch = channel + 2;
  468. else
  469. center_ch = channel - 2;
  470. }
  471. return center_ch;
  472. }
  473. void SelectChannel(_adapter *padapter, unsigned char channel)
  474. {
  475. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  476. #ifdef CONFIG_DUALMAC_CONCURRENT
  477. //saved channel info
  478. rtw_set_oper_ch(padapter, channel);
  479. dc_SelectChannel(padapter, channel);
  480. #else //CONFIG_DUALMAC_CONCURRENT
  481. _enter_critical_mutex(&(adapter_to_dvobj(padapter)->setch_mutex), NULL);
  482. //saved channel info
  483. rtw_set_oper_ch(padapter, channel);
  484. rtw_hal_set_chan(padapter, channel);
  485. _exit_critical_mutex(&(adapter_to_dvobj(padapter)->setch_mutex), NULL);
  486. #endif // CONFIG_DUALMAC_CONCURRENT
  487. }
  488. void SetBWMode(_adapter *padapter, unsigned short bwmode, unsigned char channel_offset)
  489. {
  490. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  491. #ifdef CONFIG_DUALMAC_CONCURRENT
  492. //saved bw info
  493. rtw_set_oper_bw(padapter, bwmode);
  494. rtw_set_oper_choffset(padapter, channel_offset);
  495. dc_SetBWMode(padapter, bwmode, channel_offset);
  496. #else //CONFIG_DUALMAC_CONCURRENT
  497. _enter_critical_mutex(&(adapter_to_dvobj(padapter)->setbw_mutex), NULL);
  498. //saved bw info
  499. rtw_set_oper_bw(padapter, bwmode);
  500. rtw_set_oper_choffset(padapter, channel_offset);
  501. rtw_hal_set_bwmode(padapter, (CHANNEL_WIDTH)bwmode, channel_offset);
  502. _exit_critical_mutex(&(adapter_to_dvobj(padapter)->setbw_mutex), NULL);
  503. #endif // CONFIG_DUALMAC_CONCURRENT
  504. }
  505. void set_channel_bwmode(_adapter *padapter, unsigned char channel, unsigned char channel_offset, unsigned short bwmode)
  506. {
  507. u8 center_ch, chnl_offset80 = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  508. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  509. if ( padapter->bNotifyChannelChange )
  510. {
  511. DBG_871X( "[%s] ch = %d, offset = %d, bwmode = %d\n", __FUNCTION__, channel, channel_offset, bwmode );
  512. }
  513. center_ch = rtw_get_center_ch(channel, bwmode, channel_offset);
  514. if(bwmode == CHANNEL_WIDTH_80)
  515. {
  516. if(center_ch > channel)
  517. chnl_offset80 = HAL_PRIME_CHNL_OFFSET_LOWER;
  518. else if(center_ch < channel)
  519. chnl_offset80 = HAL_PRIME_CHNL_OFFSET_UPPER;
  520. else
  521. chnl_offset80 = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  522. }
  523. //set Channel
  524. #ifdef CONFIG_DUALMAC_CONCURRENT
  525. //saved channel/bw info
  526. rtw_set_oper_ch(padapter, channel);
  527. rtw_set_oper_bw(padapter, bwmode);
  528. rtw_set_oper_choffset(padapter, channel_offset);
  529. SelectChannel(padapter, channel);
  530. SetBWMode(padapter, bwmode, channel_offset);
  531. #else //CONFIG_DUALMAC_CONCURRENT
  532. _enter_critical_mutex(&(adapter_to_dvobj(padapter)->setch_mutex), NULL);
  533. //saved channel/bw info
  534. rtw_set_oper_ch(padapter, channel);
  535. rtw_set_oper_bw(padapter, bwmode);
  536. rtw_set_oper_choffset(padapter, channel_offset);
  537. rtw_hal_set_chnl_bw(padapter, center_ch, bwmode, channel_offset, chnl_offset80); // set center channel
  538. _exit_critical_mutex(&(adapter_to_dvobj(padapter)->setch_mutex), NULL);
  539. #endif // CONFIG_DUALMAC_CONCURRENT
  540. }
  541. int get_bsstype(unsigned short capability)
  542. {
  543. if (capability & BIT(0))
  544. {
  545. return WIFI_FW_AP_STATE;
  546. }
  547. else if (capability & BIT(1))
  548. {
  549. return WIFI_FW_ADHOC_STATE;
  550. }
  551. else
  552. {
  553. return 0;
  554. }
  555. }
  556. __inline u8 *get_my_bssid(WLAN_BSSID_EX *pnetwork)
  557. {
  558. return (pnetwork->MacAddress);
  559. }
  560. u16 get_beacon_interval(WLAN_BSSID_EX *bss)
  561. {
  562. unsigned short val;
  563. _rtw_memcpy((unsigned char *)&val, rtw_get_beacon_interval_from_ie(bss->IEs), 2);
  564. return le16_to_cpu(val);
  565. }
  566. int is_client_associated_to_ap(_adapter *padapter)
  567. {
  568. struct mlme_ext_priv *pmlmeext;
  569. struct mlme_ext_info *pmlmeinfo;
  570. if(!padapter)
  571. return _FAIL;
  572. pmlmeext = &padapter->mlmeextpriv;
  573. pmlmeinfo = &(pmlmeext->mlmext_info);
  574. if ((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && ((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE))
  575. {
  576. return _TRUE;
  577. }
  578. else
  579. {
  580. return _FAIL;
  581. }
  582. }
  583. int is_client_associated_to_ibss(_adapter *padapter)
  584. {
  585. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  586. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  587. if ((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && ((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE))
  588. {
  589. return _TRUE;
  590. }
  591. else
  592. {
  593. return _FAIL;
  594. }
  595. }
  596. int is_IBSS_empty(_adapter *padapter)
  597. {
  598. unsigned int i;
  599. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  600. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  601. for (i = IBSS_START_MAC_ID; i < NUM_STA; i++)
  602. {
  603. if (pmlmeinfo->FW_sta_info[i].status == 1)
  604. {
  605. return _FAIL;
  606. }
  607. }
  608. return _TRUE;
  609. }
  610. unsigned int decide_wait_for_beacon_timeout(unsigned int bcn_interval)
  611. {
  612. if ((bcn_interval << 2) < WAIT_FOR_BCN_TO_MIN)
  613. {
  614. return WAIT_FOR_BCN_TO_MIN;
  615. }
  616. else if ((bcn_interval << 2) > WAIT_FOR_BCN_TO_MAX)
  617. {
  618. return WAIT_FOR_BCN_TO_MAX;
  619. }
  620. else
  621. {
  622. return ((bcn_interval << 2));
  623. }
  624. }
  625. void CAM_empty_entry(
  626. PADAPTER Adapter,
  627. u8 ucIndex
  628. )
  629. {
  630. rtw_hal_set_hwreg(Adapter, HW_VAR_CAM_EMPTY_ENTRY, (u8 *)(&ucIndex));
  631. }
  632. void invalidate_cam_all(_adapter *padapter)
  633. {
  634. rtw_hal_set_hwreg(padapter, HW_VAR_CAM_INVALID_ALL, 0);
  635. }
  636. #if 0
  637. static u32 _ReadCAM(_adapter *padapter ,u32 addr)
  638. {
  639. u32 count = 0, cmd;
  640. cmd = CAM_POLLINIG |addr ;
  641. rtw_write32(padapter, RWCAM, cmd);
  642. do{
  643. if(0 == (rtw_read32(padapter,REG_CAMCMD) & CAM_POLLINIG)){
  644. break;
  645. }
  646. }while(count++ < 100);
  647. return rtw_read32(padapter,REG_CAMREAD);
  648. }
  649. void read_cam(_adapter *padapter ,u8 entry)
  650. {
  651. u32 j,count = 0, addr, cmd;
  652. addr = entry << 3;
  653. DBG_8192C("********* DUMP CAM Entry_#%02d***************\n",entry);
  654. for (j = 0; j < 6; j++)
  655. {
  656. cmd = _ReadCAM(padapter ,addr+j);
  657. DBG_8192C("offset:0x%02x => 0x%08x \n",addr+j,cmd);
  658. }
  659. DBG_8192C("*********************************\n");
  660. }
  661. #endif
  662. void write_cam(_adapter *padapter, u8 entry, u16 ctrl, u8 *mac, u8 *key)
  663. {
  664. unsigned int i, val, addr;
  665. //unsigned int cmd;
  666. int j;
  667. u32 cam_val[2];
  668. addr = entry << 3;
  669. for (j = 5; j >= 0; j--)
  670. {
  671. switch (j)
  672. {
  673. case 0:
  674. val = (ctrl | (mac[0] << 16) | (mac[1] << 24) );
  675. break;
  676. case 1:
  677. val = (mac[2] | ( mac[3] << 8) | (mac[4] << 16) | (mac[5] << 24));
  678. break;
  679. default:
  680. i = (j - 2) << 2;
  681. val = (key[i] | (key[i+1] << 8) | (key[i+2] << 16) | (key[i+3] << 24));
  682. break;
  683. }
  684. cam_val[0] = val;
  685. cam_val[1] = addr + (unsigned int)j;
  686. rtw_hal_set_hwreg(padapter, HW_VAR_CAM_WRITE, (u8 *)cam_val);
  687. //rtw_write32(padapter, WCAMI, val);
  688. //cmd = CAM_POLLINIG | CAM_WRITE | (addr + j);
  689. //rtw_write32(padapter, RWCAM, cmd);
  690. //DBG_871X("%s=> cam write: %x, %x\n",__FUNCTION__, cmd, val);
  691. }
  692. }
  693. void clear_cam_entry(_adapter *padapter, u8 entry)
  694. {
  695. #if 0
  696. u32 addr, val=0;
  697. u32 cam_val[2];
  698. addr = entry << 3;
  699. cam_val[0] = val;
  700. cam_val[1] = addr + (unsigned int)0;
  701. rtw_hal_set_hwreg(padapter, HW_VAR_CAM_WRITE, (u8 *)cam_val);
  702. cam_val[0] = val;
  703. cam_val[1] = addr + (unsigned int)1;
  704. rtw_hal_set_hwreg(padapter, HW_VAR_CAM_WRITE, (u8 *)cam_val);
  705. #else
  706. unsigned char null_sta[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  707. unsigned char null_key[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00};
  708. write_cam(padapter, entry, 0, null_sta, null_key);
  709. #endif
  710. }
  711. int allocate_fw_sta_entry(_adapter *padapter)
  712. {
  713. unsigned int mac_id;
  714. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  715. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  716. for (mac_id = IBSS_START_MAC_ID; mac_id < NUM_STA; mac_id++)
  717. {
  718. if (pmlmeinfo->FW_sta_info[mac_id].status == 0)
  719. {
  720. pmlmeinfo->FW_sta_info[mac_id].status = 1;
  721. pmlmeinfo->FW_sta_info[mac_id].retry = 0;
  722. break;
  723. }
  724. }
  725. return mac_id;
  726. }
  727. void flush_all_cam_entry(_adapter *padapter)
  728. {
  729. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  730. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  731. #ifdef CONFIG_CONCURRENT_MODE
  732. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  733. //if(check_buddy_mlmeinfo_state(padapter, _HW_STATE_NOLINK_))
  734. if(check_buddy_fwstate(padapter, _FW_LINKED) == _FALSE)
  735. {
  736. rtw_hal_set_hwreg(padapter, HW_VAR_CAM_INVALID_ALL, 0);
  737. }
  738. else
  739. {
  740. if(check_fwstate(pmlmepriv, WIFI_STATION_STATE))
  741. {
  742. struct sta_priv *pstapriv = &padapter->stapriv;
  743. struct sta_info *psta;
  744. u8 cam_id;//cam_entry
  745. psta = rtw_get_stainfo(pstapriv, pmlmeinfo->network.MacAddress);
  746. if(psta) {
  747. if(psta->state & WIFI_AP_STATE)
  748. {} //clear cam when ap free per sta_info
  749. else {
  750. cam_id = (u8)rtw_get_camid(psta->mac_id);
  751. //clear_cam_entry(padapter, cam_id);
  752. rtw_clearstakey_cmd(padapter, (u8*)psta, cam_id, _FALSE);
  753. }
  754. }
  755. }
  756. else if(check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
  757. {
  758. //clear cam when ap free per sta_info
  759. }
  760. }
  761. #else //CONFIG_CONCURRENT_MODE
  762. rtw_hal_set_hwreg(padapter, HW_VAR_CAM_INVALID_ALL, 0);
  763. #endif //CONFIG_CONCURRENT_MODE
  764. _rtw_memset((u8 *)(pmlmeinfo->FW_sta_info), 0, sizeof(pmlmeinfo->FW_sta_info));
  765. }
  766. #if defined(CONFIG_P2P) && defined(CONFIG_WFD)
  767. int WFD_info_handler(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE)
  768. {
  769. struct registry_priv *pregpriv = &padapter->registrypriv;
  770. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  771. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  772. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  773. struct wifidirect_info *pwdinfo;
  774. u8 wfd_ie[ 128 ] = { 0x00 };
  775. u32 wfd_ielen = 0;
  776. pwdinfo = &padapter->wdinfo;
  777. if ( rtw_get_wfd_ie( ( u8* ) pIE, pIE->Length, wfd_ie, &wfd_ielen ) )
  778. {
  779. u8 attr_content[ 10 ] = { 0x00 };
  780. u32 attr_contentlen = 0;
  781. DBG_871X( "[%s] Found WFD IE\n", __FUNCTION__ );
  782. rtw_get_wfd_attr_content( wfd_ie, wfd_ielen, WFD_ATTR_DEVICE_INFO, attr_content, &attr_contentlen);
  783. if ( attr_contentlen )
  784. {
  785. pwdinfo->wfd_info->peer_rtsp_ctrlport = RTW_GET_BE16( attr_content + 2 );
  786. DBG_8192C( "[%s] Peer PORT NUM = %d\n", __FUNCTION__, pwdinfo->wfd_info->peer_rtsp_ctrlport );
  787. return( _TRUE );
  788. }
  789. }
  790. else
  791. {
  792. DBG_871X( "[%s] NO WFD IE\n", __FUNCTION__ );
  793. }
  794. return( _FAIL );
  795. }
  796. #endif
  797. int WMM_param_handler(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE)
  798. {
  799. //struct registry_priv *pregpriv = &padapter->registrypriv;
  800. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  801. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  802. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  803. if(pmlmepriv->qospriv.qos_option==0)
  804. {
  805. pmlmeinfo->WMM_enable = 0;
  806. return _FAIL;
  807. }
  808. pmlmeinfo->WMM_enable = 1;
  809. _rtw_memcpy(&(pmlmeinfo->WMM_param), (pIE->data + 6), sizeof(struct WMM_para_element));
  810. return _TRUE;
  811. /*if (pregpriv->wifi_spec == 1)
  812. {
  813. if (pmlmeinfo->WMM_enable == 1)
  814. {
  815. //todo: compare the parameter set count & decide wheher to update or not
  816. return _FAIL;
  817. }
  818. else
  819. {
  820. pmlmeinfo->WMM_enable = 1;
  821. _rtw_rtw_memcpy(&(pmlmeinfo->WMM_param), (pIE->data + 6), sizeof(struct WMM_para_element));
  822. return _TRUE;
  823. }
  824. }
  825. else
  826. {
  827. pmlmeinfo->WMM_enable = 0;
  828. return _FAIL;
  829. }*/
  830. }
  831. void WMMOnAssocRsp(_adapter *padapter)
  832. {
  833. u8 ACI, ACM, AIFS, ECWMin, ECWMax, aSifsTime;
  834. u8 acm_mask;
  835. u16 TXOP;
  836. u32 acParm, i;
  837. u32 edca[4], inx[4];
  838. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  839. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  840. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  841. struct registry_priv *pregpriv = &padapter->registrypriv;
  842. acm_mask = 0;
  843. if (IsSupported5G(pmlmeext->cur_wireless_mode) ||
  844. (pmlmeext->cur_wireless_mode & WIRELESS_11_24N) )
  845. aSifsTime = 16;
  846. else
  847. aSifsTime = 10;
  848. if (pmlmeinfo->WMM_enable == 0)
  849. {
  850. padapter->mlmepriv.acm_mask = 0;
  851. AIFS = aSifsTime + (2 * pmlmeinfo->slotTime);
  852. if (pmlmeext->cur_wireless_mode & (WIRELESS_11G |WIRELESS_11A)) {
  853. ECWMin = 4;
  854. ECWMax = 10;
  855. } else if (pmlmeext->cur_wireless_mode & WIRELESS_11B) {
  856. ECWMin = 5;
  857. ECWMax = 10;
  858. }
  859. TXOP = 0;
  860. acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
  861. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acParm));
  862. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acParm));
  863. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acParm));
  864. ECWMin = 2;
  865. ECWMax = 3;
  866. TXOP = 0x2f;
  867. acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
  868. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acParm));
  869. }
  870. else
  871. {
  872. for (i = 0; i < 4; i++)
  873. {
  874. ACI = (pmlmeinfo->WMM_param.ac_param[i].ACI_AIFSN >> 5) & 0x03;
  875. ACM = (pmlmeinfo->WMM_param.ac_param[i].ACI_AIFSN >> 4) & 0x01;
  876. //AIFS = AIFSN * slot time + SIFS - r2t phy delay
  877. AIFS = (pmlmeinfo->WMM_param.ac_param[i].ACI_AIFSN & 0x0f) * pmlmeinfo->slotTime + aSifsTime;
  878. ECWMin = (pmlmeinfo->WMM_param.ac_param[i].CW & 0x0f);
  879. ECWMax = (pmlmeinfo->WMM_param.ac_param[i].CW & 0xf0) >> 4;
  880. TXOP = le16_to_cpu(pmlmeinfo->WMM_param.ac_param[i].TXOP_limit);
  881. acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
  882. switch (ACI)
  883. {
  884. case 0x0:
  885. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acParm));
  886. acm_mask |= (ACM? BIT(1):0);
  887. edca[XMIT_BE_QUEUE] = acParm;
  888. break;
  889. case 0x1:
  890. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acParm));
  891. //acm_mask |= (ACM? BIT(0):0);
  892. edca[XMIT_BK_QUEUE] = acParm;
  893. break;
  894. case 0x2:
  895. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acParm));
  896. acm_mask |= (ACM? BIT(2):0);
  897. edca[XMIT_VI_QUEUE] = acParm;
  898. break;
  899. case 0x3:
  900. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acParm));
  901. acm_mask |= (ACM? BIT(3):0);
  902. edca[XMIT_VO_QUEUE] = acParm;
  903. break;
  904. }
  905. DBG_871X("WMM(%x): %x, %x\n", ACI, ACM, acParm);
  906. }
  907. if(padapter->registrypriv.acm_method == 1)
  908. rtw_hal_set_hwreg(padapter, HW_VAR_ACM_CTRL, (u8 *)(&acm_mask));
  909. else
  910. padapter->mlmepriv.acm_mask = acm_mask;
  911. inx[0] = 0; inx[1] = 1; inx[2] = 2; inx[3] = 3;
  912. if(pregpriv->wifi_spec==1)
  913. {
  914. u32 j, tmp, change_inx;
  915. //entry indx: 0->vo, 1->vi, 2->be, 3->bk.
  916. for(i=0; i<4; i++)
  917. {
  918. for(j=i+1; j<4; j++)
  919. {
  920. //compare CW and AIFS
  921. if((edca[j] & 0xFFFF) < (edca[i] & 0xFFFF))
  922. {
  923. change_inx = _TRUE;
  924. }
  925. else if((edca[j] & 0xFFFF) == (edca[i] & 0xFFFF))
  926. {
  927. //compare TXOP
  928. if((edca[j] >> 16) > (edca[i] >> 16))
  929. change_inx = _TRUE;
  930. }
  931. if(change_inx)
  932. {
  933. tmp = edca[i];
  934. edca[i] = edca[j];
  935. edca[j] = tmp;
  936. tmp = inx[i];
  937. inx[i] = inx[j];
  938. inx[j] = tmp;
  939. change_inx = _FALSE;
  940. }
  941. }
  942. }
  943. }
  944. for(i=0; i<4; i++) {
  945. pxmitpriv->wmm_para_seq[i] = inx[i];
  946. DBG_871X("wmm_para_seq(%d): %d\n", i, pxmitpriv->wmm_para_seq[i]);
  947. }
  948. }
  949. }
  950. static void bwmode_update_check(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE)
  951. {
  952. #ifdef CONFIG_80211N_HT
  953. unsigned char new_bwmode;
  954. unsigned char new_ch_offset;
  955. struct HT_info_element *pHT_info;
  956. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  957. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  958. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  959. struct registry_priv *pregistrypriv = &padapter->registrypriv;
  960. struct ht_priv *phtpriv = &pmlmepriv->htpriv;
  961. u8 cbw40_enable=0;
  962. if(!pIE)
  963. return;
  964. if(phtpriv->ht_option == _FALSE) return;
  965. if(pmlmeext->cur_bwmode >= CHANNEL_WIDTH_80) return;
  966. if(pIE->Length > sizeof(struct HT_info_element))
  967. return;
  968. pHT_info = (struct HT_info_element *)pIE->data;
  969. if (pmlmeext->cur_channel > 14) {
  970. if ((pregistrypriv->bw_mode & 0xf0) > 0)
  971. cbw40_enable = 1;
  972. } else {
  973. if ((pregistrypriv->bw_mode & 0x0f) > 0)
  974. cbw40_enable = 1;
  975. }
  976. if((pHT_info->infos[0] & BIT(2)) && cbw40_enable)
  977. {
  978. new_bwmode = CHANNEL_WIDTH_40;
  979. switch (pHT_info->infos[0] & 0x3)
  980. {
  981. case 1:
  982. new_ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
  983. break;
  984. case 3:
  985. new_ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
  986. break;
  987. default:
  988. new_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  989. break;
  990. }
  991. }
  992. else
  993. {
  994. new_bwmode = CHANNEL_WIDTH_20;
  995. new_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  996. }
  997. if((new_bwmode!= pmlmeext->cur_bwmode) || (new_ch_offset!=pmlmeext->cur_ch_offset))
  998. {
  999. pmlmeinfo->bwmode_updated = _TRUE;
  1000. pmlmeext->cur_bwmode = new_bwmode;
  1001. pmlmeext->cur_ch_offset = new_ch_offset;
  1002. //update HT info also
  1003. HT_info_handler(padapter, pIE);
  1004. }
  1005. else
  1006. {
  1007. pmlmeinfo->bwmode_updated = _FALSE;
  1008. }
  1009. if(_TRUE == pmlmeinfo->bwmode_updated)
  1010. {
  1011. struct sta_info *psta;
  1012. WLAN_BSSID_EX *cur_network = &(pmlmeinfo->network);
  1013. struct sta_priv *pstapriv = &padapter->stapriv;
  1014. //set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
  1015. //update ap's stainfo
  1016. psta = rtw_get_stainfo(pstapriv, cur_network->MacAddress);
  1017. if(psta)
  1018. {
  1019. struct ht_priv *phtpriv_sta = &psta->htpriv;
  1020. if(phtpriv_sta->ht_option)
  1021. {
  1022. // bwmode
  1023. phtpriv_sta->bwmode = pmlmeext->cur_bwmode;
  1024. phtpriv_sta->ch_offset = pmlmeext->cur_ch_offset;
  1025. }
  1026. else
  1027. {
  1028. phtpriv_sta->bwmode = CHANNEL_WIDTH_20;
  1029. phtpriv_sta->ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  1030. }
  1031. }
  1032. //pmlmeinfo->bwmode_updated = _FALSE;//bwmode_updated done, reset it!
  1033. }
  1034. #endif //CONFIG_80211N_HT
  1035. }
  1036. void HT_caps_handler(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE)
  1037. {
  1038. #ifdef CONFIG_80211N_HT
  1039. unsigned int i;
  1040. u8 rf_type;
  1041. u8 max_AMPDU_len, min_MPDU_spacing;
  1042. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1043. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1044. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1045. struct ht_priv *phtpriv = &pmlmepriv->htpriv;
  1046. struct registry_priv *pregistrypriv = &padapter->registrypriv;
  1047. if(pIE==NULL) return;
  1048. if(phtpriv->ht_option == _FALSE) return;
  1049. pmlmeinfo->HT_caps_enable = 1;
  1050. for (i = 0; i < (pIE->Length); i++)
  1051. {
  1052. if (i != 2)
  1053. {
  1054. // Commented by Albert 2010/07/12
  1055. // Got the endian issue here.
  1056. pmlmeinfo->HT_caps.u.HT_cap[i] &= (pIE->data[i]);
  1057. }
  1058. else
  1059. {
  1060. //modify from fw by Thomas 2010/11/17
  1061. if ((pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x3) > (pIE->data[i] & 0x3))
  1062. {
  1063. max_AMPDU_len = (pIE->data[i] & 0x3);
  1064. }
  1065. else
  1066. {
  1067. max_AMPDU_len = (pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x3);
  1068. }
  1069. if ((pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x1c) > (pIE->data[i] & 0x1c))
  1070. {
  1071. min_MPDU_spacing = (pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x1c);
  1072. }
  1073. else
  1074. {
  1075. min_MPDU_spacing = (pIE->data[i] & 0x1c);
  1076. }
  1077. pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para = max_AMPDU_len | min_MPDU_spacing;
  1078. }
  1079. }
  1080. // Commented by Albert 2010/07/12
  1081. // Have to handle the endian issue after copying.
  1082. // HT_ext_caps didn't be used yet.
  1083. pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info = le16_to_cpu( pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info );
  1084. pmlmeinfo->HT_caps.u.HT_cap_element.HT_ext_caps = le16_to_cpu( pmlmeinfo->HT_caps.u.HT_cap_element.HT_ext_caps );
  1085. rtw_hal_get_hwreg(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
  1086. //update the MCS rates
  1087. for (i = 0; i < 16; i++)
  1088. {
  1089. if((rf_type == RF_1T1R) || (rf_type == RF_1T2R))
  1090. {
  1091. pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate[i] &= MCS_rate_1R[i];
  1092. }
  1093. else
  1094. {
  1095. #ifdef CONFIG_DISABLE_MCS13TO15
  1096. if(pmlmeext->cur_bwmode == CHANNEL_WIDTH_40 && (pregistrypriv->wifi_spec!=1))
  1097. pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate[i] &= MCS_rate_2R_MCS13TO15_OFF[i];
  1098. else
  1099. pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate[i] &= MCS_rate_2R[i];
  1100. #else
  1101. pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate[i] &= MCS_rate_2R[i];
  1102. #endif //CONFIG_DISABLE_MCS13TO15
  1103. }
  1104. #ifdef RTL8192C_RECONFIG_TO_1T1R
  1105. {
  1106. pmlmeinfo->HT_caps.HT_cap_element.MCS_rate[i] &= MCS_rate_1R[i];
  1107. }
  1108. #endif
  1109. }
  1110. #endif //CONFIG_80211N_HT
  1111. return;
  1112. }
  1113. void HT_info_handler(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE)
  1114. {
  1115. #ifdef CONFIG_80211N_HT
  1116. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1117. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1118. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1119. struct ht_priv *phtpriv = &pmlmepriv->htpriv;
  1120. if(pIE==NULL) return;
  1121. if(phtpriv->ht_option == _FALSE) return;
  1122. if(pIE->Length > sizeof(struct HT_info_element))
  1123. return;
  1124. pmlmeinfo->HT_info_enable = 1;
  1125. _rtw_memcpy(&(pmlmeinfo->HT_info), pIE->data, pIE->Length);
  1126. #endif //CONFIG_80211N_HT
  1127. return;
  1128. }
  1129. void HTOnAssocRsp(_adapter *padapter)
  1130. {
  1131. unsigned char max_AMPDU_len;
  1132. unsigned char min_MPDU_spacing;
  1133. //struct registry_priv *pregpriv = &padapter->registrypriv;
  1134. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1135. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1136. DBG_871X("%s\n", __FUNCTION__);
  1137. if ((pmlmeinfo->HT_info_enable) && (pmlmeinfo->HT_caps_enable))
  1138. {
  1139. pmlmeinfo->HT_enable = 1;
  1140. }
  1141. else
  1142. {
  1143. pmlmeinfo->HT_enable = 0;
  1144. //set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
  1145. return;
  1146. }
  1147. //handle A-MPDU parameter field
  1148. /*
  1149. AMPDU_para [1:0]:Max AMPDU Len => 0:8k , 1:16k, 2:32k, 3:64k
  1150. AMPDU_para [4:2]:Min MPDU Start Spacing
  1151. */
  1152. max_AMPDU_len = pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x03;
  1153. min_MPDU_spacing = (pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x1c) >> 2;
  1154. rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_MIN_SPACE, (u8 *)(&min_MPDU_spacing));
  1155. rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_FACTOR, (u8 *)(&max_AMPDU_len));
  1156. #if 0 //move to rtw_update_ht_cap()
  1157. if ((pregpriv->bw_mode > 0) &&
  1158. (pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info & BIT(1)) &&
  1159. (pmlmeinfo->HT_info.infos[0] & BIT(2)))
  1160. {
  1161. //switch to the 40M Hz mode accoring to the AP
  1162. pmlmeext->cur_bwmode = CHANNEL_WIDTH_40;
  1163. switch ((pmlmeinfo->HT_info.infos[0] & 0x3))
  1164. {
  1165. case EXTCHNL_OFFSET_UPPER:
  1166. pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
  1167. break;
  1168. case EXTCHNL_OFFSET_LOWER:
  1169. pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
  1170. break;
  1171. default:
  1172. pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  1173. break;
  1174. }
  1175. //SelectChannel(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset);
  1176. }
  1177. #endif
  1178. //set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
  1179. #if 0 //move to rtw_update_ht_cap()
  1180. //
  1181. // Config SM Power Save setting
  1182. //
  1183. pmlmeinfo->SM_PS = (pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info & 0x0C) >> 2;
  1184. if(pmlmeinfo->SM_PS == WLAN_HT_CAP_SM_PS_STATIC)
  1185. {
  1186. /*u8 i;
  1187. //update the MCS rates
  1188. for (i = 0; i < 16; i++)
  1189. {
  1190. pmlmeinfo->HT_caps.HT_cap_element.MCS_rate[i] &= MCS_rate_1R[i];
  1191. }*/
  1192. DBG_871X("%s(): WLAN_HT_CAP_SM_PS_STATIC\n",__FUNCTION__);
  1193. }
  1194. //
  1195. // Config current HT Protection mode.
  1196. //
  1197. pmlmeinfo->HT_protection = pmlmeinfo->HT_info.infos[1] & 0x3;
  1198. #endif
  1199. }
  1200. void ERP_IE_handler(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE)
  1201. {
  1202. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1203. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1204. if(pIE->Length>1)
  1205. return;
  1206. pmlmeinfo->ERP_enable = 1;
  1207. _rtw_memcpy(&(pmlmeinfo->ERP_IE), pIE->data, pIE->Length);
  1208. }
  1209. void VCS_update(_adapter *padapter, struct sta_info *psta)
  1210. {
  1211. struct registry_priv *pregpriv = &padapter->registrypriv;
  1212. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1213. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1214. switch (pregpriv->vrtl_carrier_sense)/* 0:off 1:on 2:auto */
  1215. {
  1216. case 0: //off
  1217. psta->rtsen = 0;
  1218. psta->cts2self = 0;
  1219. break;
  1220. case 1: //on
  1221. if (pregpriv->vcs_type == 1) /* 1:RTS/CTS 2:CTS to self */
  1222. {
  1223. psta->rtsen = 1;
  1224. psta->cts2self = 0;
  1225. }
  1226. else
  1227. {
  1228. psta->rtsen = 0;
  1229. psta->cts2self = 1;
  1230. }
  1231. break;
  1232. case 2: //auto
  1233. default:
  1234. if ((pmlmeinfo->ERP_enable) && (pmlmeinfo->ERP_IE & BIT(1)))
  1235. {
  1236. if (pregpriv->vcs_type == 1)
  1237. {
  1238. psta->rtsen = 1;
  1239. psta->cts2self = 0;
  1240. }
  1241. else
  1242. {
  1243. psta->rtsen = 0;
  1244. psta->cts2self = 1;
  1245. }
  1246. }
  1247. else
  1248. {
  1249. psta->rtsen = 0;
  1250. psta->cts2self = 0;
  1251. }
  1252. break;
  1253. }
  1254. }
  1255. #ifdef CONFIG_TDLS
  1256. int check_ap_tdls_prohibited(u8 *pframe, u8 pkt_len)
  1257. {
  1258. u8 tdls_prohibited_bit = 0x40; //bit(38); TDLS_prohibited
  1259. if(pkt_len < 5)
  1260. {
  1261. return _FALSE;
  1262. }
  1263. pframe += 4;
  1264. if( (*pframe) & tdls_prohibited_bit )
  1265. return _TRUE;
  1266. return _FALSE;
  1267. }
  1268. #endif //CONFIG_TDLS
  1269. int rtw_check_bcn_info(ADAPTER *Adapter, u8 *pframe, u32 packet_len)
  1270. {
  1271. unsigned int len;
  1272. unsigned char *p;
  1273. unsigned short val16, subtype;
  1274. struct wlan_network *cur_network = &(Adapter->mlmepriv.cur_network);
  1275. //u8 wpa_ie[255],rsn_ie[255];
  1276. u16 wpa_len=0,rsn_len=0;
  1277. u8 encryp_protocol = 0;
  1278. WLAN_BSSID_EX *bssid;
  1279. int group_cipher = 0, pairwise_cipher = 0, is_8021x = 0;
  1280. unsigned char *pbuf;
  1281. u32 wpa_ielen = 0;
  1282. u8 *pbssid = GetAddr3Ptr(pframe);
  1283. u32 hidden_ssid = 0;
  1284. u8 cur_network_type, network_type=0;
  1285. struct HT_info_element *pht_info = NULL;
  1286. struct rtw_ieee80211_ht_cap *pht_cap = NULL;
  1287. u32 bcn_channel;
  1288. unsigned short ht_cap_info;
  1289. unsigned char ht_info_infos_0;
  1290. if (is_client_associated_to_ap(Adapter) == _FALSE)
  1291. return _TRUE;
  1292. len = packet_len - sizeof(struct rtw_ieee80211_hdr_3addr);
  1293. if (len > MAX_IE_SZ) {
  1294. DBG_871X("%s IE too long for survey event\n", __func__);
  1295. return _FAIL;
  1296. }
  1297. if (_rtw_memcmp(cur_network->network.MacAddress, pbssid, 6) == _FALSE) {
  1298. DBG_871X("Oops: rtw_check_network_encrypt linked but recv other bssid bcn\n" MAC_FMT MAC_FMT,
  1299. MAC_ARG(pbssid), MAC_ARG(cur_network->network.MacAddress));
  1300. return _TRUE;
  1301. }
  1302. bssid = (WLAN_BSSID_EX *)rtw_zmalloc(sizeof(WLAN_BSSID_EX));
  1303. subtype = GetFrameSubType(pframe) >> 4;
  1304. if(subtype==WIFI_BEACON)
  1305. bssid->Reserved[0] = 1;
  1306. bssid->Length = sizeof(WLAN_BSSID_EX) - MAX_IE_SZ + len;
  1307. /* below is to copy the information element */
  1308. bssid->IELength = len;
  1309. _rtw_memcpy(bssid->IEs, (pframe + sizeof(struct rtw_ieee80211_hdr_3addr)), bssid->IELength);
  1310. /* check bw and channel offset */
  1311. /* parsing HT_CAP_IE */
  1312. p = rtw_get_ie(bssid->IEs + _FIXED_IE_LENGTH_, _HT_CAPABILITY_IE_, &len, bssid->IELength - _FIXED_IE_LENGTH_);
  1313. if(p && len>0) {
  1314. pht_cap = (struct rtw_ieee80211_ht_cap *)(p + 2);
  1315. ht_cap_info = pht_cap->cap_info;
  1316. } else {
  1317. ht_cap_info = 0;
  1318. }
  1319. /* parsing HT_INFO_IE */
  1320. p = rtw_get_ie(bssid->IEs + _FIXED_IE_LENGTH_, _HT_ADD_INFO_IE_, &len, bssid->IELength - _FIXED_IE_LENGTH_);
  1321. if(p && len>0) {
  1322. pht_info = (struct HT_info_element *)(p + 2);
  1323. ht_info_infos_0 = pht_info->infos[0];
  1324. } else {
  1325. ht_info_infos_0 = 0;
  1326. }
  1327. if (ht_cap_info != cur_network->BcnInfo.ht_cap_info ||
  1328. ((ht_info_infos_0&0x03) != (cur_network->BcnInfo.ht_info_infos_0&0x03))) {
  1329. DBG_871X("%s bcn now: ht_cap_info:%x ht_info_infos_0:%x\n", __func__,
  1330. ht_cap_info, ht_info_infos_0);
  1331. DBG_871X("%s bcn link: ht_cap_info:%x ht_info_infos_0:%x\n", __func__,
  1332. cur_network->BcnInfo.ht_cap_info, cur_network->BcnInfo.ht_info_infos_0);
  1333. DBG_871X("%s bw mode change, disconnect\n", __func__);
  1334. {
  1335. //bcn_info_update
  1336. cur_network->BcnInfo.ht_cap_info = ht_cap_info;
  1337. cur_network->BcnInfo.ht_info_infos_0 = ht_info_infos_0;
  1338. //to do : need to check that whether modify related register of BB or not
  1339. }
  1340. //goto _mismatch;
  1341. }
  1342. /* Checking for channel */
  1343. p = rtw_get_ie(bssid->IEs + _FIXED_IE_LENGTH_, _DSSET_IE_, &len, bssid->IELength - _FIXED_IE_LENGTH_);
  1344. if (p) {
  1345. bcn_channel = *(p + 2);
  1346. } else {/* In 5G, some ap do not have DSSET IE checking HT info for channel */
  1347. p = rtw_get_ie(bssid->IEs + _FIXED_IE_LENGTH_, _HT_ADD_INFO_IE_, &len, bssid->IELength - _FIXED_IE_LENGTH_);
  1348. if(pht_info) {
  1349. bcn_channel = pht_info->primary_channel;
  1350. } else { /* we don't find channel IE, so don't check it */
  1351. //DBG_871X("Oops: %s we don't find channel IE, so don't check it \n", __func__);
  1352. bcn_channel = Adapter->mlmeextpriv.cur_channel;
  1353. }
  1354. }
  1355. if (bcn_channel != Adapter->mlmeextpriv.cur_channel) {
  1356. DBG_871X("%s beacon channel:%d cur channel:%d disconnect\n", __func__,
  1357. bcn_channel, Adapter->mlmeextpriv.cur_channel);
  1358. goto _mismatch;
  1359. }
  1360. /* checking SSID */
  1361. if ((p = rtw_get_ie(bssid->IEs + _FIXED_IE_LENGTH_, _SSID_IE_, &len, bssid->IELength - _FIXED_IE_LENGTH_)) == NULL) {
  1362. DBG_871X("%s marc: cannot find SSID for survey event\n", __func__);
  1363. hidden_ssid = _TRUE;
  1364. } else {
  1365. hidden_ssid = _FALSE;
  1366. }
  1367. if((NULL != p) && (_FALSE == hidden_ssid && (*(p + 1)))) {
  1368. _rtw_memcpy(bssid->Ssid.Ssid, (p + 2), *(p + 1));
  1369. bssid->Ssid.SsidLength = *(p + 1);
  1370. } else {
  1371. bssid->Ssid.SsidLength = 0;
  1372. bssid->Ssid.Ssid[0] = '\0';
  1373. }
  1374. RT_TRACE(_module_rtl871x_mlme_c_,_drv_info_,("%s bssid.Ssid.Ssid:%s bssid.Ssid.SsidLength:%d "
  1375. "cur_network->network.Ssid.Ssid:%s len:%d\n", __func__, bssid->Ssid.Ssid,
  1376. bssid->Ssid.SsidLength, cur_network->network.Ssid.Ssid,
  1377. cur_network->network.Ssid.SsidLength));
  1378. if (_rtw_memcmp(bssid->Ssid.Ssid, cur_network->network.Ssid.Ssid, 32) == _FALSE ||
  1379. bssid->Ssid.SsidLength != cur_network->network.Ssid.SsidLength) {
  1380. if (bssid->Ssid.Ssid[0] != '\0' && bssid->Ssid.SsidLength != 0) { /* not hidden ssid */
  1381. DBG_871X("%s(), SSID is not match return FAIL\n", __func__);
  1382. goto _mismatch;
  1383. }
  1384. }
  1385. /* check encryption info */
  1386. val16 = rtw_get_capability((WLAN_BSSID_EX *)bssid);
  1387. if (val16 & BIT(4))
  1388. bssid->Privacy = 1;
  1389. else
  1390. bssid->Privacy = 0;
  1391. RT_TRACE(_module_rtl871x_mlme_c_,_drv_info_,
  1392. ("%s(): cur_network->network.Privacy is %d, bssid.Privacy is %d\n",
  1393. __func__, cur_network->network.Privacy,bssid->Privacy));
  1394. if (cur_network->network.Privacy != bssid->Privacy) {
  1395. DBG_871X("%s(), privacy is not match return FAIL\n",__func__);
  1396. goto _mismatch;
  1397. }
  1398. rtw_get_sec_ie(bssid->IEs, bssid->IELength, NULL,&rsn_len,NULL,&wpa_len);
  1399. if (rsn_len > 0) {
  1400. encryp_protocol = ENCRYP_PROTOCOL_WPA2;
  1401. } else if (wpa_len > 0) {
  1402. encryp_protocol = ENCRYP_PROTOCOL_WPA;
  1403. } else {
  1404. if (bssid->Privacy)
  1405. encryp_protocol = ENCRYP_PROTOCOL_WEP;
  1406. }
  1407. if (cur_network->BcnInfo.encryp_protocol != encryp_protocol) {
  1408. DBG_871X("%s(): enctyp is not match ,return FAIL\n",__func__);
  1409. goto _mismatch;
  1410. }
  1411. if (encryp_protocol == ENCRYP_PROTOCOL_WPA || encryp_protocol == ENCRYP_PROTOCOL_WPA2) {
  1412. pbuf = rtw_get_wpa_ie(&bssid->IEs[12], &wpa_ielen, bssid->IELength-12);
  1413. if(pbuf && (wpa_ielen>0)) {
  1414. if (_SUCCESS == rtw_parse_wpa_ie(pbuf, wpa_ielen+2, &group_cipher, &pairwise_cipher, &is_8021x)) {
  1415. RT_TRACE(_module_rtl871x_mlme_c_,_drv_info_,
  1416. ("%s pnetwork->pairwise_cipher: %d, group_cipher is %d, is_8021x is %d\n", __func__,
  1417. pairwise_cipher, group_cipher, is_8021x));
  1418. }
  1419. } else {
  1420. pbuf = rtw_get_wpa2_ie(&bssid->IEs[12], &wpa_ielen, bssid->IELength-12);
  1421. if(pbuf && (wpa_ielen>0)) {
  1422. if (_SUCCESS == rtw_parse_wpa2_ie(pbuf, wpa_ielen+2, &group_cipher, &pairwise_cipher, &is_8021x)) {
  1423. RT_TRACE(_module_rtl871x_mlme_c_,_drv_info_,
  1424. ("%s pnetwork->pairwise_cipher: %d, pnetwork->group_cipher is %d, is_802x is %d\n",
  1425. __func__, pairwise_cipher, group_cipher, is_8021x));
  1426. }
  1427. }
  1428. }
  1429. RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,
  1430. ("%s cur_network->group_cipher is %d: %d\n",__func__, cur_network->BcnInfo.group_cipher, group_cipher));
  1431. if (pairwise_cipher != cur_network->BcnInfo.pairwise_cipher || group_cipher != cur_network->BcnInfo.group_cipher) {
  1432. DBG_871X("%s pairwise_cipher(%x:%x) or group_cipher(%x:%x) is not match ,return FAIL\n",__func__,
  1433. pairwise_cipher, cur_network->BcnInfo.pairwise_cipher,
  1434. group_cipher, cur_network->BcnInfo.group_cipher);
  1435. goto _mismatch;
  1436. }
  1437. if (is_8021x != cur_network->BcnInfo.is_8021x) {
  1438. DBG_871X("%s authentication is not match ,return FAIL\n", __func__);
  1439. goto _mismatch;
  1440. }
  1441. }
  1442. rtw_mfree((u8 *)bssid, sizeof(WLAN_BSSID_EX));
  1443. return _SUCCESS;
  1444. _mismatch:
  1445. rtw_mfree((u8 *)bssid, sizeof(WLAN_BSSID_EX));
  1446. return _FAIL;
  1447. _func_exit_;
  1448. }
  1449. void update_beacon_info(_adapter *padapter, u8 *pframe, uint pkt_len, struct sta_info *psta)
  1450. {
  1451. unsigned int i;
  1452. unsigned int len;
  1453. PNDIS_802_11_VARIABLE_IEs pIE;
  1454. #ifdef CONFIG_TDLS
  1455. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  1456. u8 tdls_prohibited[] = { 0x00, 0x00, 0x00, 0x00, 0x10 }; //bit(38): TDLS_prohibited
  1457. #endif //CONFIG_TDLS
  1458. len = pkt_len - (_BEACON_IE_OFFSET_ + WLAN_HDR_A3_LEN);
  1459. for (i = 0; i < len;)
  1460. {
  1461. pIE = (PNDIS_802_11_VARIABLE_IEs)(pframe + (_BEACON_IE_OFFSET_ + WLAN_HDR_A3_LEN) + i);
  1462. switch (pIE->ElementID)
  1463. {
  1464. #if 0
  1465. case _VENDOR_SPECIFIC_IE_:
  1466. //todo: to update WMM paramter set while receiving beacon
  1467. if (_rtw_memcmp(pIE->data, WMM_PARA_OUI, 6)) //WMM
  1468. {
  1469. (WMM_param_handler(padapter, pIE))? WMMOnAssocRsp(padapter): 0;
  1470. }
  1471. break;
  1472. #endif
  1473. case _HT_EXTRA_INFO_IE_: //HT info
  1474. //HT_info_handler(padapter, pIE);
  1475. bwmode_update_check(padapter, pIE);
  1476. break;
  1477. case _ERPINFO_IE_:
  1478. ERP_IE_handler(padapter, pIE);
  1479. VCS_update(padapter, psta);
  1480. break;
  1481. #ifdef CONFIG_TDLS
  1482. case _EXT_CAP_IE_:
  1483. if( check_ap_tdls_prohibited(pIE->data, pIE->Length) == _TRUE )
  1484. ptdlsinfo->ap_prohibited = _TRUE;
  1485. break;
  1486. #endif //CONFIG_TDLS
  1487. default:
  1488. break;
  1489. }
  1490. i += (pIE->Length + 2);
  1491. }
  1492. }
  1493. #ifdef CONFIG_DFS
  1494. void process_csa_ie(_adapter *padapter, u8 *pframe, uint pkt_len)
  1495. {
  1496. unsigned int i;
  1497. unsigned int len;
  1498. PNDIS_802_11_VARIABLE_IEs pIE;
  1499. u8 new_ch_no = 0;
  1500. len = pkt_len - (_BEACON_IE_OFFSET_ + WLAN_HDR_A3_LEN);
  1501. for (i = 0; i < len;)
  1502. {
  1503. pIE = (PNDIS_802_11_VARIABLE_IEs)(pframe + (_BEACON_IE_OFFSET_ + WLAN_HDR_A3_LEN) + i);
  1504. switch (pIE->ElementID)
  1505. {
  1506. case _CH_SWTICH_ANNOUNCE_:
  1507. _rtw_memcpy(&new_ch_no, pIE->data+1, 1);
  1508. rtw_set_csa_cmd(padapter, new_ch_no);
  1509. break;
  1510. default:
  1511. break;
  1512. }
  1513. i += (pIE->Length + 2);
  1514. }
  1515. }
  1516. #endif //CONFIG_DFS
  1517. unsigned int is_ap_in_tkip(_adapter *padapter)
  1518. {
  1519. u32 i;
  1520. PNDIS_802_11_VARIABLE_IEs pIE;
  1521. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1522. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1523. WLAN_BSSID_EX *cur_network = &(pmlmeinfo->network);
  1524. if (rtw_get_capability((WLAN_BSSID_EX *)cur_network) & WLAN_CAPABILITY_PRIVACY)
  1525. {
  1526. for (i = sizeof(NDIS_802_11_FIXED_IEs); i < pmlmeinfo->network.IELength;)
  1527. {
  1528. pIE = (PNDIS_802_11_VARIABLE_IEs)(pmlmeinfo->network.IEs + i);
  1529. switch (pIE->ElementID)
  1530. {
  1531. case _VENDOR_SPECIFIC_IE_:
  1532. if ((_rtw_memcmp(pIE->data, RTW_WPA_OUI, 4)) && (_rtw_memcmp((pIE->data + 12), WPA_TKIP_CIPHER, 4)))
  1533. {
  1534. return _TRUE;
  1535. }
  1536. break;
  1537. case _RSN_IE_2_:
  1538. if (_rtw_memcmp((pIE->data + 8), RSN_TKIP_CIPHER, 4))
  1539. {
  1540. return _TRUE;
  1541. }
  1542. default:
  1543. break;
  1544. }
  1545. i += (pIE->Length + 2);
  1546. }
  1547. return _FALSE;
  1548. }
  1549. else
  1550. {
  1551. return _FALSE;
  1552. }
  1553. }
  1554. unsigned int should_forbid_n_rate(_adapter * padapter)
  1555. {
  1556. u32 i;
  1557. PNDIS_802_11_VARIABLE_IEs pIE;
  1558. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1559. WLAN_BSSID_EX *cur_network = &pmlmepriv->cur_network.network;
  1560. if (rtw_get_capability((WLAN_BSSID_EX *)cur_network) & WLAN_CAPABILITY_PRIVACY)
  1561. {
  1562. for (i = sizeof(NDIS_802_11_FIXED_IEs); i < cur_network->IELength;)
  1563. {
  1564. pIE = (PNDIS_802_11_VARIABLE_IEs)(cur_network->IEs + i);
  1565. switch (pIE->ElementID)
  1566. {
  1567. case _VENDOR_SPECIFIC_IE_:
  1568. if (_rtw_memcmp(pIE->data, RTW_WPA_OUI, 4) &&
  1569. ((_rtw_memcmp((pIE->data + 12), WPA_CIPHER_SUITE_CCMP, 4)) ||
  1570. (_rtw_memcmp((pIE->data + 16), WPA_CIPHER_SUITE_CCMP, 4))))
  1571. return _FALSE;
  1572. break;
  1573. case _RSN_IE_2_:
  1574. if ((_rtw_memcmp((pIE->data + 8), RSN_CIPHER_SUITE_CCMP, 4)) ||
  1575. (_rtw_memcmp((pIE->data + 12), RSN_CIPHER_SUITE_CCMP, 4)))
  1576. return _FALSE;
  1577. default:
  1578. break;
  1579. }
  1580. i += (pIE->Length + 2);
  1581. }
  1582. return _TRUE;
  1583. }
  1584. else
  1585. {
  1586. return _FALSE;
  1587. }
  1588. }
  1589. unsigned int is_ap_in_wep(_adapter *padapter)
  1590. {
  1591. u32 i;
  1592. PNDIS_802_11_VARIABLE_IEs pIE;
  1593. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1594. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1595. WLAN_BSSID_EX *cur_network = &(pmlmeinfo->network);
  1596. if (rtw_get_capability((WLAN_BSSID_EX *)cur_network) & WLAN_CAPABILITY_PRIVACY)
  1597. {
  1598. for (i = sizeof(NDIS_802_11_FIXED_IEs); i < pmlmeinfo->network.IELength;)
  1599. {
  1600. pIE = (PNDIS_802_11_VARIABLE_IEs)(pmlmeinfo->network.IEs + i);
  1601. switch (pIE->ElementID)
  1602. {
  1603. case _VENDOR_SPECIFIC_IE_:
  1604. if (_rtw_memcmp(pIE->data, RTW_WPA_OUI, 4))
  1605. return _FALSE;
  1606. break;
  1607. case _RSN_IE_2_:
  1608. return _FALSE;
  1609. default:
  1610. break;
  1611. }
  1612. i += (pIE->Length + 2);
  1613. }
  1614. return _TRUE;
  1615. }
  1616. else
  1617. {
  1618. return _FALSE;
  1619. }
  1620. }
  1621. int wifirate2_ratetbl_inx(unsigned char rate);
  1622. int wifirate2_ratetbl_inx(unsigned char rate)
  1623. {
  1624. int inx = 0;
  1625. rate = rate & 0x7f;
  1626. switch (rate)
  1627. {
  1628. case 54*2:
  1629. inx = 11;
  1630. break;
  1631. case 48*2:
  1632. inx = 10;
  1633. break;
  1634. case 36*2:
  1635. inx = 9;
  1636. break;
  1637. case 24*2:
  1638. inx = 8;
  1639. break;
  1640. case 18*2:
  1641. inx = 7;
  1642. break;
  1643. case 12*2:
  1644. inx = 6;
  1645. break;
  1646. case 9*2:
  1647. inx = 5;
  1648. break;
  1649. case 6*2:
  1650. inx = 4;
  1651. break;
  1652. case 11*2:
  1653. inx = 3;
  1654. break;
  1655. case 11:
  1656. inx = 2;
  1657. break;
  1658. case 2*2:
  1659. inx = 1;
  1660. break;
  1661. case 1*2:
  1662. inx = 0;
  1663. break;
  1664. }
  1665. return inx;
  1666. }
  1667. unsigned int update_basic_rate(unsigned char *ptn, unsigned int ptn_sz)
  1668. {
  1669. unsigned int i, num_of_rate;
  1670. unsigned int mask = 0;
  1671. num_of_rate = (ptn_sz > NumRates)? NumRates: ptn_sz;
  1672. for (i = 0; i < num_of_rate; i++)
  1673. {
  1674. if ((*(ptn + i)) & 0x80)
  1675. {
  1676. mask |= 0x1 << wifirate2_ratetbl_inx(*(ptn + i));
  1677. }
  1678. }
  1679. return mask;
  1680. }
  1681. unsigned int update_supported_rate(unsigned char *ptn, unsigned int ptn_sz)
  1682. {
  1683. unsigned int i, num_of_rate;
  1684. unsigned int mask = 0;
  1685. num_of_rate = (ptn_sz > NumRates)? NumRates: ptn_sz;
  1686. for (i = 0; i < num_of_rate; i++)
  1687. {
  1688. mask |= 0x1 << wifirate2_ratetbl_inx(*(ptn + i));
  1689. }
  1690. return mask;
  1691. }
  1692. unsigned int update_MCS_rate(struct HT_caps_element *pHT_caps)
  1693. {
  1694. unsigned int mask = 0;
  1695. mask = ((pHT_caps->u.HT_cap_element.MCS_rate[0] << 12) | (pHT_caps->u.HT_cap_element.MCS_rate[1] << 20));
  1696. return mask;
  1697. }
  1698. int support_short_GI(_adapter *padapter, struct HT_caps_element *pHT_caps)
  1699. {
  1700. unsigned char bit_offset;
  1701. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1702. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1703. if (!(pmlmeinfo->HT_enable))
  1704. return _FAIL;
  1705. if ((pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_RALINK))
  1706. return _FAIL;
  1707. bit_offset = (pmlmeext->cur_bwmode & CHANNEL_WIDTH_40)? 6: 5;
  1708. if (pHT_caps->u.HT_cap_element.HT_caps_info & (0x1 << bit_offset))
  1709. {
  1710. return _SUCCESS;
  1711. }
  1712. else
  1713. {
  1714. return _FAIL;
  1715. }
  1716. }
  1717. unsigned char get_highest_rate_idx(u32 mask)
  1718. {
  1719. int i;
  1720. unsigned char rate_idx=0;
  1721. for(i=31; i>=0; i--)
  1722. {
  1723. if(mask & BIT(i))
  1724. {
  1725. rate_idx = i;
  1726. break;
  1727. }
  1728. }
  1729. return rate_idx;
  1730. }
  1731. unsigned char get_highest_mcs_rate(struct HT_caps_element *pHT_caps);
  1732. unsigned char get_highest_mcs_rate(struct HT_caps_element *pHT_caps)
  1733. {
  1734. int i, mcs_rate;
  1735. mcs_rate = (pHT_caps->u.HT_cap_element.MCS_rate[0] | (pHT_caps->u.HT_cap_element.MCS_rate[1] << 8));
  1736. for (i = 15; i >= 0; i--)
  1737. {
  1738. if (mcs_rate & (0x1 << i))
  1739. {
  1740. break;
  1741. }
  1742. }
  1743. return i;
  1744. }
  1745. void Update_RA_Entry(_adapter *padapter, struct sta_info *psta)
  1746. {
  1747. rtw_hal_update_ra_mask(psta, 0);
  1748. }
  1749. void enable_rate_adaptive(_adapter *padapter, struct sta_info *psta);
  1750. void enable_rate_adaptive(_adapter *padapter, struct sta_info *psta)
  1751. {
  1752. Update_RA_Entry(padapter, psta);
  1753. }
  1754. void set_sta_rate(_adapter *padapter, struct sta_info *psta)
  1755. {
  1756. //rate adaptive
  1757. enable_rate_adaptive(padapter, psta);
  1758. }
  1759. // Update RRSR and Rate for USERATE
  1760. void update_tx_basic_rate(_adapter *padapter, u8 wirelessmode)
  1761. {
  1762. NDIS_802_11_RATES_EX supported_rates;
  1763. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1764. #ifdef CONFIG_P2P
  1765. struct wifidirect_info* pwdinfo = &padapter->wdinfo;
  1766. // Added by Albert 2011/03/22
  1767. // In the P2P mode, the driver should not support the b mode.
  1768. // So, the Tx packet shouldn't use the CCK rate
  1769. if(!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  1770. return;
  1771. #endif //CONFIG_P2P
  1772. #ifdef CONFIG_INTEL_WIDI
  1773. if (padapter->mlmepriv.widi_state != INTEL_WIDI_STATE_NONE)
  1774. return;
  1775. #endif //CONFIG_INTEL_WIDI
  1776. _rtw_memset(supported_rates, 0, NDIS_802_11_LENGTH_RATES_EX);
  1777. //clear B mod if current channel is in 5G band, avoid tx cck rate in 5G band.
  1778. if(pmlmeext->cur_channel > 14)
  1779. wirelessmode &= ~(WIRELESS_11B);
  1780. if ((wirelessmode & WIRELESS_11B) && (wirelessmode == WIRELESS_11B)) {
  1781. _rtw_memcpy(supported_rates, rtw_basic_rate_cck, 4);
  1782. } else if (wirelessmode & WIRELESS_11B) {
  1783. _rtw_memcpy(supported_rates, rtw_basic_rate_mix, 7);
  1784. } else {
  1785. _rtw_memcpy(supported_rates, rtw_basic_rate_ofdm, 3);
  1786. }
  1787. if (wirelessmode & WIRELESS_11B)
  1788. update_mgnt_tx_rate(padapter, IEEE80211_CCK_RATE_1MB);
  1789. else
  1790. update_mgnt_tx_rate(padapter, IEEE80211_OFDM_RATE_6MB);
  1791. rtw_hal_set_hwreg(padapter, HW_VAR_BASIC_RATE, supported_rates);
  1792. }
  1793. unsigned char check_assoc_AP(u8 *pframe, uint len)
  1794. {
  1795. unsigned int i;
  1796. PNDIS_802_11_VARIABLE_IEs pIE;
  1797. for (i = sizeof(NDIS_802_11_FIXED_IEs); i < len;)
  1798. {
  1799. pIE = (PNDIS_802_11_VARIABLE_IEs)(pframe + i);
  1800. switch (pIE->ElementID)
  1801. {
  1802. case _VENDOR_SPECIFIC_IE_:
  1803. if ((_rtw_memcmp(pIE->data, ARTHEROS_OUI1, 3)) || (_rtw_memcmp(pIE->data, ARTHEROS_OUI2, 3)))
  1804. {
  1805. DBG_871X("link to Artheros AP\n");
  1806. return HT_IOT_PEER_ATHEROS;
  1807. }
  1808. else if ((_rtw_memcmp(pIE->data, BROADCOM_OUI1, 3))
  1809. || (_rtw_memcmp(pIE->data, BROADCOM_OUI2, 3))
  1810. || (_rtw_memcmp(pIE->data, BROADCOM_OUI2, 3)))
  1811. {
  1812. DBG_871X("link to Broadcom AP\n");
  1813. return HT_IOT_PEER_BROADCOM;
  1814. }
  1815. else if (_rtw_memcmp(pIE->data, MARVELL_OUI, 3))
  1816. {
  1817. DBG_871X("link to Marvell AP\n");
  1818. return HT_IOT_PEER_MARVELL;
  1819. }
  1820. else if (_rtw_memcmp(pIE->data, RALINK_OUI, 3))
  1821. {
  1822. DBG_871X("link to Ralink AP\n");
  1823. return HT_IOT_PEER_RALINK;
  1824. }
  1825. else if (_rtw_memcmp(pIE->data, CISCO_OUI, 3))
  1826. {
  1827. DBG_871X("link to Cisco AP\n");
  1828. return HT_IOT_PEER_CISCO;
  1829. }
  1830. else if (_rtw_memcmp(pIE->data, REALTEK_OUI, 3))
  1831. {
  1832. u32 Vender = HT_IOT_PEER_REALTEK;
  1833. if(pIE->Length >= 5) {
  1834. if(pIE->data[4]==1)
  1835. {
  1836. //if(pIE->data[5] & RT_HT_CAP_USE_LONG_PREAMBLE)
  1837. // bssDesc->BssHT.RT2RT_HT_Mode |= RT_HT_CAP_USE_LONG_PREAMBLE;
  1838. if(pIE->data[5] & RT_HT_CAP_USE_92SE)
  1839. {
  1840. //bssDesc->BssHT.RT2RT_HT_Mode |= RT_HT_CAP_USE_92SE;
  1841. Vender = HT_IOT_PEER_REALTEK_92SE;
  1842. }
  1843. }
  1844. if(pIE->data[5] & RT_HT_CAP_USE_SOFTAP)
  1845. Vender = HT_IOT_PEER_REALTEK_SOFTAP;
  1846. if(pIE->data[4] == 2)
  1847. {
  1848. if(pIE->data[6] & RT_HT_CAP_USE_JAGUAR_BCUT) {
  1849. Vender = HT_IOT_PEER_REALTEK_JAGUAR_BCUTAP;
  1850. DBG_871X("link to Realtek JAGUAR_BCUTAP\n");
  1851. }
  1852. if(pIE->data[6] & RT_HT_CAP_USE_JAGUAR_CCUT) {
  1853. Vender = HT_IOT_PEER_REALTEK_JAGUAR_CCUTAP;
  1854. DBG_871X("link to Realtek JAGUAR_CCUTAP\n");
  1855. }
  1856. }
  1857. }
  1858. DBG_871X("link to Realtek AP\n");
  1859. return Vender;
  1860. }
  1861. else if (_rtw_memcmp(pIE->data, AIRGOCAP_OUI,3))
  1862. {
  1863. DBG_871X("link to Airgo Cap\n");
  1864. return HT_IOT_PEER_AIRGO;
  1865. }
  1866. else
  1867. {
  1868. break;
  1869. }
  1870. default:
  1871. break;
  1872. }
  1873. i += (pIE->Length + 2);
  1874. }
  1875. DBG_871X("link to new AP\n");
  1876. return HT_IOT_PEER_UNKNOWN;
  1877. }
  1878. void update_IOT_info(_adapter *padapter)
  1879. {
  1880. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1881. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1882. switch (pmlmeinfo->assoc_AP_vendor)
  1883. {
  1884. case HT_IOT_PEER_MARVELL:
  1885. pmlmeinfo->turboMode_cts2self = 1;
  1886. pmlmeinfo->turboMode_rtsen = 0;
  1887. break;
  1888. case HT_IOT_PEER_RALINK:
  1889. pmlmeinfo->turboMode_cts2self = 0;
  1890. pmlmeinfo->turboMode_rtsen = 1;
  1891. //disable high power
  1892. Switch_DM_Func(padapter, (~DYNAMIC_BB_DYNAMIC_TXPWR), _FALSE);
  1893. break;
  1894. case HT_IOT_PEER_REALTEK:
  1895. //rtw_write16(padapter, 0x4cc, 0xffff);
  1896. //rtw_write16(padapter, 0x546, 0x01c0);
  1897. //disable high power
  1898. Switch_DM_Func(padapter, (~DYNAMIC_BB_DYNAMIC_TXPWR), _FALSE);
  1899. break;
  1900. default:
  1901. pmlmeinfo->turboMode_cts2self = 0;
  1902. pmlmeinfo->turboMode_rtsen = 1;
  1903. break;
  1904. }
  1905. }
  1906. void update_capinfo(PADAPTER Adapter, u16 updateCap)
  1907. {
  1908. struct mlme_ext_priv *pmlmeext = &Adapter->mlmeextpriv;
  1909. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1910. BOOLEAN ShortPreamble;
  1911. // Check preamble mode, 2005.01.06, by rcnjko.
  1912. // Mark to update preamble value forever, 2008.03.18 by lanhsin
  1913. //if( pMgntInfo->RegPreambleMode == PREAMBLE_AUTO )
  1914. {
  1915. if(updateCap & cShortPreamble)
  1916. { // Short Preamble
  1917. if(pmlmeinfo->preamble_mode != PREAMBLE_SHORT) // PREAMBLE_LONG or PREAMBLE_AUTO
  1918. {
  1919. ShortPreamble = _TRUE;
  1920. pmlmeinfo->preamble_mode = PREAMBLE_SHORT;
  1921. rtw_hal_set_hwreg( Adapter, HW_VAR_ACK_PREAMBLE, (u8 *)&ShortPreamble );
  1922. }
  1923. }
  1924. else
  1925. { // Long Preamble
  1926. if(pmlmeinfo->preamble_mode != PREAMBLE_LONG) // PREAMBLE_SHORT or PREAMBLE_AUTO
  1927. {
  1928. ShortPreamble = _FALSE;
  1929. pmlmeinfo->preamble_mode = PREAMBLE_LONG;
  1930. rtw_hal_set_hwreg( Adapter, HW_VAR_ACK_PREAMBLE, (u8 *)&ShortPreamble );
  1931. }
  1932. }
  1933. }
  1934. if ( updateCap & cIBSS ) {
  1935. //Filen: See 802.11-2007 p.91
  1936. pmlmeinfo->slotTime = NON_SHORT_SLOT_TIME;
  1937. }
  1938. else
  1939. {
  1940. //Filen: See 802.11-2007 p.90
  1941. if( pmlmeext->cur_wireless_mode & (WIRELESS_11G))
  1942. {
  1943. if( (updateCap & cShortSlotTime) /* && (!(pMgntInfo->pHTInfo->RT2RT_HT_Mode & RT_HT_CAP_USE_LONG_PREAMBLE)) */)
  1944. { // Short Slot Time
  1945. pmlmeinfo->slotTime = SHORT_SLOT_TIME;
  1946. }
  1947. else
  1948. { // Long Slot Time
  1949. pmlmeinfo->slotTime = NON_SHORT_SLOT_TIME;
  1950. }
  1951. }
  1952. else if( pmlmeext->cur_wireless_mode & (WIRELESS_11_24N | WIRELESS_11A | WIRELESS_11_5N | WIRELESS_11AC))
  1953. {
  1954. pmlmeinfo->slotTime = SHORT_SLOT_TIME;
  1955. }
  1956. else
  1957. {
  1958. //B Mode
  1959. pmlmeinfo->slotTime = NON_SHORT_SLOT_TIME;
  1960. }
  1961. }
  1962. rtw_hal_set_hwreg( Adapter, HW_VAR_SLOT_TIME, &pmlmeinfo->slotTime );
  1963. }
  1964. void update_wireless_mode(_adapter *padapter)
  1965. {
  1966. int ratelen, network_type = 0;
  1967. u32 SIFS_Timer;
  1968. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1969. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1970. WLAN_BSSID_EX *cur_network = &(pmlmeinfo->network);
  1971. unsigned char *rate = cur_network->SupportedRates;
  1972. ratelen = rtw_get_rateset_len(cur_network->SupportedRates);
  1973. if ((pmlmeinfo->HT_info_enable) && (pmlmeinfo->HT_caps_enable))
  1974. {
  1975. pmlmeinfo->HT_enable = 1;
  1976. }
  1977. if(pmlmeext->cur_channel > 14)
  1978. {
  1979. if (pmlmeinfo->VHT_enable)
  1980. network_type = WIRELESS_11AC;
  1981. else if (pmlmeinfo->HT_enable)
  1982. network_type = WIRELESS_11_5N;
  1983. network_type |= WIRELESS_11A;
  1984. }
  1985. else
  1986. {
  1987. if (pmlmeinfo->VHT_enable)
  1988. network_type = WIRELESS_11AC;
  1989. else if (pmlmeinfo->HT_enable)
  1990. network_type = WIRELESS_11_24N;
  1991. if ((cckratesonly_included(rate, ratelen)) == _TRUE)
  1992. {
  1993. network_type |= WIRELESS_11B;
  1994. }
  1995. else if((cckrates_included(rate, ratelen)) == _TRUE)
  1996. {
  1997. network_type |= WIRELESS_11BG;
  1998. }
  1999. else
  2000. {
  2001. network_type |= WIRELESS_11G;
  2002. }
  2003. }
  2004. pmlmeext->cur_wireless_mode = network_type & padapter->registrypriv.wireless_mode;
  2005. /*
  2006. if((pmlmeext->cur_wireless_mode==WIRELESS_11G) ||
  2007. (pmlmeext->cur_wireless_mode==WIRELESS_11BG))//WIRELESS_MODE_G)
  2008. SIFS_Timer = 0x0a0a;//CCK
  2009. else
  2010. SIFS_Timer = 0x0e0e;//pHalData->SifsTime; //OFDM
  2011. */
  2012. SIFS_Timer = 0x0a0a0808; //0x0808 -> for CCK, 0x0a0a -> for OFDM
  2013. //change this value if having IOT issues.
  2014. padapter->HalFunc.SetHwRegHandler( padapter, HW_VAR_RESP_SIFS, (u8 *)&SIFS_Timer);
  2015. padapter->HalFunc.SetHwRegHandler( padapter, HW_VAR_WIRELESS_MODE, (u8 *)&(pmlmeext->cur_wireless_mode));
  2016. if (pmlmeext->cur_wireless_mode & WIRELESS_11B)
  2017. update_mgnt_tx_rate(padapter, IEEE80211_CCK_RATE_1MB);
  2018. else
  2019. update_mgnt_tx_rate(padapter, IEEE80211_OFDM_RATE_6MB);
  2020. }
  2021. void fire_write_MAC_cmd(_adapter *padapter, unsigned int addr, unsigned int value);
  2022. void fire_write_MAC_cmd(_adapter *padapter, unsigned int addr, unsigned int value)
  2023. {
  2024. #if 0
  2025. struct cmd_obj *ph2c;
  2026. struct reg_rw_parm *pwriteMacPara;
  2027. struct cmd_priv *pcmdpriv = &(padapter->cmdpriv);
  2028. if ((ph2c = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj))) == NULL)
  2029. {
  2030. return;
  2031. }
  2032. if ((pwriteMacPara = (struct reg_rw_parm*)rtw_malloc(sizeof(struct reg_rw_parm))) == NULL)
  2033. {
  2034. rtw_mfree((unsigned char *)ph2c, sizeof(struct cmd_obj));
  2035. return;
  2036. }
  2037. pwriteMacPara->rw = 1;
  2038. pwriteMacPara->addr = addr;
  2039. pwriteMacPara->value = value;
  2040. init_h2fwcmd_w_parm_no_rsp(ph2c, pwriteMacPara, GEN_CMD_CODE(_Write_MACREG));
  2041. rtw_enqueue_cmd(pcmdpriv, ph2c);
  2042. #endif
  2043. }
  2044. void update_bmc_sta_support_rate(_adapter *padapter, u32 mac_id)
  2045. {
  2046. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  2047. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2048. if(pmlmeext->cur_wireless_mode & WIRELESS_11B)
  2049. {
  2050. // Only B, B/G, and B/G/N AP could use CCK rate
  2051. _rtw_memcpy((pmlmeinfo->FW_sta_info[mac_id].SupportedRates), rtw_basic_rate_cck, 4);
  2052. }
  2053. else
  2054. {
  2055. _rtw_memcpy((pmlmeinfo->FW_sta_info[mac_id].SupportedRates), rtw_basic_rate_ofdm, 4);
  2056. }
  2057. }
  2058. int update_sta_support_rate(_adapter *padapter, u8* pvar_ie, uint var_ie_len, int cam_idx)
  2059. {
  2060. unsigned int ie_len;
  2061. PNDIS_802_11_VARIABLE_IEs pIE;
  2062. int supportRateNum = 0;
  2063. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  2064. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2065. pIE = (PNDIS_802_11_VARIABLE_IEs)rtw_get_ie(pvar_ie, _SUPPORTEDRATES_IE_, &ie_len, var_ie_len);
  2066. if (pIE == NULL)
  2067. {
  2068. return _FAIL;
  2069. }
  2070. _rtw_memcpy(pmlmeinfo->FW_sta_info[cam_idx].SupportedRates, pIE->data, ie_len);
  2071. supportRateNum = ie_len;
  2072. pIE = (PNDIS_802_11_VARIABLE_IEs)rtw_get_ie(pvar_ie, _EXT_SUPPORTEDRATES_IE_, &ie_len, var_ie_len);
  2073. if (pIE)
  2074. {
  2075. _rtw_memcpy((pmlmeinfo->FW_sta_info[cam_idx].SupportedRates + supportRateNum), pIE->data, ie_len);
  2076. }
  2077. return _SUCCESS;
  2078. }
  2079. void process_addba_req(_adapter *padapter, u8 *paddba_req, u8 *addr)
  2080. {
  2081. struct sta_info *psta;
  2082. u16 tid, start_seq, param;
  2083. struct recv_reorder_ctrl *preorder_ctrl;
  2084. struct sta_priv *pstapriv = &padapter->stapriv;
  2085. struct ADDBA_request *preq = (struct ADDBA_request*)paddba_req;
  2086. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  2087. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2088. psta = rtw_get_stainfo(pstapriv, addr);
  2089. if(psta)
  2090. {
  2091. start_seq = le16_to_cpu(preq->BA_starting_seqctrl) >> 4;
  2092. param = le16_to_cpu(preq->BA_para_set);
  2093. tid = (param>>2)&0x0f;
  2094. preorder_ctrl = &psta->recvreorder_ctrl[tid];
  2095. #ifdef CONFIG_UPDATE_INDICATE_SEQ_WHILE_PROCESS_ADDBA_REQ
  2096. preorder_ctrl->indicate_seq = start_seq;
  2097. #ifdef DBG_RX_SEQ
  2098. DBG_871X("DBG_RX_SEQ %s:%d IndicateSeq: %d, start_seq: %d\n", __FUNCTION__, __LINE__,
  2099. preorder_ctrl->indicate_seq, start_seq);
  2100. #endif
  2101. #else
  2102. preorder_ctrl->indicate_seq = 0xffff;
  2103. #endif
  2104. preorder_ctrl->enable =(pmlmeinfo->bAcceptAddbaReq == _TRUE)? _TRUE :_FALSE;
  2105. }
  2106. }
  2107. void update_TSF(struct mlme_ext_priv *pmlmeext, u8 *pframe, uint len)
  2108. {
  2109. u8* pIE;
  2110. u32 *pbuf;
  2111. pIE = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
  2112. pbuf = (u32*)pIE;
  2113. pmlmeext->TSFValue = le32_to_cpu(*(pbuf+1));
  2114. pmlmeext->TSFValue = pmlmeext->TSFValue << 32;
  2115. pmlmeext->TSFValue |= le32_to_cpu(*pbuf);
  2116. }
  2117. void correct_TSF(_adapter *padapter, struct mlme_ext_priv *pmlmeext)
  2118. {
  2119. rtw_hal_set_hwreg(padapter, HW_VAR_CORRECT_TSF, 0);
  2120. }
  2121. void beacon_timing_control(_adapter *padapter)
  2122. {
  2123. rtw_hal_bcn_related_reg_setting(padapter);
  2124. }
  2125. uint rtw_get_camid(uint macid)
  2126. {
  2127. uint camid;
  2128. //camid 0, 1, 2, 3 is default entry for default key/group key
  2129. //macid = 1 is for bc/mc stainfo, no mapping to camid
  2130. //macid = 0 mapping to camid 4
  2131. //for macid >=2, camid = macid+3;
  2132. if(macid==0)
  2133. camid = 4;
  2134. else if(macid >=2)
  2135. camid = macid + 3;
  2136. else
  2137. camid = 4;
  2138. return camid;
  2139. }
  2140. void rtw_alloc_macid(_adapter *padapter, struct sta_info *psta)
  2141. {
  2142. int i;
  2143. _irqL irqL;
  2144. u8 bc_addr[ETH_ALEN] = {0xff,0xff,0xff,0xff,0xff,0xff};
  2145. struct dvobj_priv *pdvobj = adapter_to_dvobj(padapter);
  2146. if(_rtw_memcmp(psta->hwaddr, bc_addr, ETH_ALEN))
  2147. return;
  2148. if(_rtw_memcmp(psta->hwaddr, myid(&padapter->eeprompriv), ETH_ALEN))
  2149. {
  2150. psta->mac_id = NUM_STA;
  2151. return;
  2152. }
  2153. _enter_critical_bh(&pdvobj->lock, &irqL);
  2154. for(i=0; i<NUM_STA; i++)
  2155. {
  2156. if(pdvobj->macid[i] == _FALSE)
  2157. {
  2158. pdvobj->macid[i] = _TRUE;
  2159. break;
  2160. }
  2161. }
  2162. _exit_critical_bh(&pdvobj->lock, &irqL);
  2163. if( i > (NUM_STA-1))
  2164. {
  2165. psta->mac_id = NUM_STA;
  2166. DBG_871X(" no room for more MACIDs\n");
  2167. }
  2168. else
  2169. {
  2170. psta->mac_id = i;
  2171. DBG_871X("%s = %d\n", __FUNCTION__, psta->mac_id);
  2172. }
  2173. }
  2174. void rtw_release_macid(_adapter *padapter, struct sta_info *psta)
  2175. {
  2176. int i;
  2177. _irqL irqL;
  2178. u8 bc_addr[ETH_ALEN] = {0xff,0xff,0xff,0xff,0xff,0xff};
  2179. struct dvobj_priv *pdvobj = adapter_to_dvobj(padapter);
  2180. if(_rtw_memcmp(psta->hwaddr, bc_addr, ETH_ALEN))
  2181. return;
  2182. if(_rtw_memcmp(psta->hwaddr, myid(&padapter->eeprompriv), ETH_ALEN))
  2183. {
  2184. return;
  2185. }
  2186. _enter_critical_bh(&pdvobj->lock, &irqL);
  2187. if(psta->mac_id<NUM_STA && psta->mac_id !=1 )
  2188. {
  2189. if(pdvobj->macid[psta->mac_id] == _TRUE)
  2190. {
  2191. DBG_871X("%s = %d\n", __FUNCTION__, psta->mac_id);
  2192. pdvobj->macid[psta->mac_id] = _FALSE;
  2193. psta->mac_id = NUM_STA;
  2194. }
  2195. }
  2196. _exit_critical_bh(&pdvobj->lock, &irqL);
  2197. }
  2198. #if 0
  2199. unsigned int setup_beacon_frame(_adapter *padapter, unsigned char *beacon_frame)
  2200. {
  2201. unsigned short ATIMWindow;
  2202. unsigned char *pframe;
  2203. struct tx_desc *ptxdesc;
  2204. struct rtw_ieee80211_hdr *pwlanhdr;
  2205. unsigned short *fctrl;
  2206. unsigned int rate_len, len = 0;
  2207. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  2208. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  2209. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2210. WLAN_BSSID_EX *cur_network = &(pmlmeinfo->network);
  2211. u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  2212. _rtw_memset(beacon_frame, 0, 256);
  2213. pframe = beacon_frame + TXDESC_SIZE;
  2214. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  2215. fctrl = &(pwlanhdr->frame_ctl);
  2216. *(fctrl) = 0;
  2217. _rtw_memcpy(pwlanhdr->addr1, bc_addr, ETH_ALEN);
  2218. _rtw_memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
  2219. _rtw_memcpy(pwlanhdr->addr3, get_my_bssid(cur_network), ETH_ALEN);
  2220. SetFrameSubType(pframe, WIFI_BEACON);
  2221. pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
  2222. len = sizeof(struct rtw_ieee80211_hdr_3addr);
  2223. //timestamp will be inserted by hardware
  2224. pframe += 8;
  2225. len += 8;
  2226. // beacon interval: 2 bytes
  2227. _rtw_memcpy(pframe, (unsigned char *)(rtw_get_beacon_interval_from_ie(cur_network->IEs)), 2);
  2228. pframe += 2;
  2229. len += 2;
  2230. // capability info: 2 bytes
  2231. _rtw_memcpy(pframe, (unsigned char *)(rtw_get_capability_from_ie(cur_network->IEs)), 2);
  2232. pframe += 2;
  2233. len += 2;
  2234. // SSID
  2235. pframe = rtw_set_ie(pframe, _SSID_IE_, cur_network->Ssid.SsidLength, cur_network->Ssid.Ssid, &len);
  2236. // supported rates...
  2237. rate_len = rtw_get_rateset_len(cur_network->SupportedRates);
  2238. pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, ((rate_len > 8)? 8: rate_len), cur_network->SupportedRates, &len);
  2239. // DS parameter set
  2240. pframe = rtw_set_ie(pframe, _DSSET_IE_, 1, (unsigned char *)&(cur_network->Configuration.DSConfig), &len);
  2241. // IBSS Parameter Set...
  2242. //ATIMWindow = cur->Configuration.ATIMWindow;
  2243. ATIMWindow = 0;
  2244. pframe = rtw_set_ie(pframe, _IBSS_PARA_IE_, 2, (unsigned char *)(&ATIMWindow), &len);
  2245. //todo: ERP IE
  2246. // EXTERNDED SUPPORTED RATE
  2247. if (rate_len > 8)
  2248. {
  2249. pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_, (rate_len - 8), (cur_network->SupportedRates + 8), &len);
  2250. }
  2251. if ((len + TXDESC_SIZE) > 256)
  2252. {
  2253. //DBG_871X("marc: beacon frame too large\n");
  2254. return 0;
  2255. }
  2256. //fill the tx descriptor
  2257. ptxdesc = (struct tx_desc *)beacon_frame;
  2258. //offset 0
  2259. ptxdesc->txdw0 |= cpu_to_le32(len & 0x0000ffff);
  2260. ptxdesc->txdw0 |= cpu_to_le32(((TXDESC_SIZE + OFFSET_SZ) << OFFSET_SHT) & 0x00ff0000); //default = 32 bytes for TX Desc
  2261. //offset 4
  2262. ptxdesc->txdw1 |= cpu_to_le32((0x10 << QSEL_SHT) & 0x00001f00);
  2263. //offset 8
  2264. ptxdesc->txdw2 |= cpu_to_le32(BMC);
  2265. ptxdesc->txdw2 |= cpu_to_le32(BK);
  2266. //offset 16
  2267. ptxdesc->txdw4 = 0x80000000;
  2268. //offset 20
  2269. ptxdesc->txdw5 = 0x00000000; //1M
  2270. return (len + TXDESC_SIZE);
  2271. }
  2272. #endif
  2273. static _adapter *pbuddy_padapter = NULL;
  2274. int rtw_handle_dualmac(_adapter *adapter, bool init)
  2275. {
  2276. int status = _SUCCESS;
  2277. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  2278. if(adapter->chip_type != RTL8192D)
  2279. goto exit;
  2280. if (init) {
  2281. #if 0
  2282. /* For SMSP on 92DU-VC, driver do not probe another Interface. */
  2283. if(dvobj->NumInterfaces == 2 && dvobj->InterfaceNumber != 0 &&
  2284. adapter->registrypriv.mac_phy_mode == 1) {
  2285. DBG_871X("%s(): Do not init another USB Interface because SMSP\n",__FUNCTION__);
  2286. status = _FAIL;
  2287. goto exit;
  2288. }
  2289. #endif
  2290. if (pbuddy_padapter == NULL) {
  2291. pbuddy_padapter = adapter;
  2292. DBG_871X("%s(): pbuddy_padapter == NULL, Set pbuddy_padapter\n",__FUNCTION__);
  2293. } else {
  2294. adapter->pbuddy_adapter = pbuddy_padapter;
  2295. pbuddy_padapter->pbuddy_adapter = adapter;
  2296. // clear global value
  2297. pbuddy_padapter = NULL;
  2298. DBG_871X("%s(): pbuddy_padapter exist, Exchange Information\n",__FUNCTION__);
  2299. }
  2300. #ifdef CONFIG_DUALMAC_CONCURRENT
  2301. if (dvobj->InterfaceNumber == 0) {
  2302. //set adapter_type/iface type
  2303. adapter->isprimary = _TRUE;
  2304. adapter->adapter_type = PRIMARY_ADAPTER;
  2305. adapter->iface_type = IFACE_PORT0;
  2306. DBG_871X("%s(): PRIMARY_ADAPTER\n",__FUNCTION__);
  2307. } else {
  2308. //set adapter_type/iface type
  2309. adapter->isprimary = _FALSE;
  2310. adapter->adapter_type = SECONDARY_ADAPTER;
  2311. adapter->iface_type = IFACE_PORT1;
  2312. DBG_871X("%s(): SECONDARY_ADAPTER\n",__FUNCTION__);
  2313. }
  2314. #endif
  2315. }else {
  2316. pbuddy_padapter = NULL;
  2317. }
  2318. exit:
  2319. return status;
  2320. }