utils_mlo.c 144 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691
  1. /*
  2. * Copyright (c) 2021, The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. /*
  18. * DOC: contains MLO manager util api's
  19. */
  20. #include <wlan_cmn.h>
  21. #include <wlan_mlo_mgr_sta.h>
  22. #include <wlan_cm_public_struct.h>
  23. #include <wlan_mlo_mgr_main.h>
  24. #include <wlan_cm_api.h>
  25. #include "wlan_scan_api.h"
  26. #include "qdf_types.h"
  27. #include "utils_mlo.h"
  28. #include "wlan_mlo_mgr_cmn.h"
  29. #include "wlan_utility.h"
  30. #ifdef WLAN_FEATURE_11BE_MLO
  31. static uint8_t *util_find_eid(uint8_t eid, uint8_t *frame, qdf_size_t len)
  32. {
  33. if (!frame)
  34. return NULL;
  35. while (len >= MIN_IE_LEN && len >= frame[TAG_LEN_POS] + MIN_IE_LEN) {
  36. if (frame[ID_POS] == eid)
  37. return frame;
  38. len -= frame[TAG_LEN_POS] + MIN_IE_LEN;
  39. frame += frame[TAG_LEN_POS] + MIN_IE_LEN;
  40. }
  41. return NULL;
  42. }
  43. static
  44. uint8_t *util_find_extn_eid(uint8_t eid, uint8_t extn_eid,
  45. uint8_t *frame, qdf_size_t len)
  46. {
  47. if (!frame)
  48. return NULL;
  49. while (len > MIN_IE_LEN && len >= frame[TAG_LEN_POS] + MIN_IE_LEN) {
  50. if ((frame[ID_POS] == eid) &&
  51. (frame[ELEM_ID_EXTN_POS] == extn_eid))
  52. return frame;
  53. len -= frame[TAG_LEN_POS] + MIN_IE_LEN;
  54. frame += frame[TAG_LEN_POS] + MIN_IE_LEN;
  55. }
  56. return NULL;
  57. }
  58. static QDF_STATUS
  59. util_parse_multi_link_ctrl(uint8_t *mlieseqpayload,
  60. qdf_size_t mlieseqpayloadlen,
  61. uint8_t **link_info,
  62. qdf_size_t *link_info_len)
  63. {
  64. qdf_size_t parsed_payload_len;
  65. uint16_t mlcontrol;
  66. uint16_t presence_bm;
  67. uint16_t cinfo_len = 0;
  68. uint16_t exp_cinfo_len = 0;
  69. /* This helper returns the location(s) and length(s) of (sub)field(s)
  70. * inferable after parsing the Multi Link element Control field. These
  71. * location(s) and length(s) is/are in reference to the payload section
  72. * of the Multi Link element (after defragmentation, if applicable).
  73. * Here, the payload is the point after the element ID extension of the
  74. * Multi Link element, and includes the payloads of all subsequent
  75. * fragments (if any) but not the headers of those fragments.
  76. *
  77. * Currently, the helper returns the location and length of the Link
  78. * Info field in the Multi Link element sequence. Other (sub)field(s)
  79. * can be added later as required.
  80. */
  81. if (!mlieseqpayload) {
  82. mlo_err("ML seq payload pointer is NULL");
  83. return QDF_STATUS_E_NULL_VALUE;
  84. }
  85. if (!mlieseqpayloadlen) {
  86. mlo_err("ML seq payload len is 0");
  87. return QDF_STATUS_E_INVAL;
  88. }
  89. if (mlieseqpayloadlen < WLAN_ML_CTRL_SIZE) {
  90. mlo_err_rl("ML seq payload len %zu < ML Control size %u",
  91. mlieseqpayloadlen, WLAN_ML_CTRL_SIZE);
  92. return QDF_STATUS_E_PROTO;
  93. }
  94. parsed_payload_len = 0;
  95. qdf_mem_copy(&mlcontrol, mlieseqpayload, WLAN_ML_CTRL_SIZE);
  96. mlcontrol = qdf_le16_to_cpu(mlcontrol);
  97. parsed_payload_len += WLAN_ML_CTRL_SIZE;
  98. presence_bm = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_PBM_IDX,
  99. WLAN_ML_CTRL_PBM_BITS);
  100. if (mlieseqpayloadlen <
  101. (parsed_payload_len + WLAN_ML_BV_CINFO_LENGTH_SIZE)) {
  102. mlo_err_rl("ML seq payload len %zu insufficient for common info length size %u after parsed payload len %zu.",
  103. mlieseqpayloadlen,
  104. WLAN_ML_BV_CINFO_LENGTH_SIZE,
  105. parsed_payload_len);
  106. return QDF_STATUS_E_PROTO;
  107. }
  108. cinfo_len = *(mlieseqpayload + parsed_payload_len);
  109. parsed_payload_len += WLAN_ML_BV_CINFO_LENGTH_SIZE;
  110. if (mlieseqpayloadlen <
  111. (parsed_payload_len + QDF_MAC_ADDR_SIZE)) {
  112. mlo_err_rl("ML seq payload len %zu insufficient for MAC address size %u after parsed payload len %zu.",
  113. mlieseqpayloadlen,
  114. QDF_MAC_ADDR_SIZE,
  115. parsed_payload_len);
  116. return QDF_STATUS_E_PROTO;
  117. }
  118. parsed_payload_len += QDF_MAC_ADDR_SIZE;
  119. /* Check if Link ID info is present */
  120. if (presence_bm & WLAN_ML_BV_CTRL_PBM_LINKIDINFO_P) {
  121. if (mlieseqpayloadlen <
  122. (parsed_payload_len +
  123. WLAN_ML_BV_CINFO_LINKIDINFO_SIZE)) {
  124. mlo_err_rl("ML seq payload len %zu insufficient for Link ID info size %u after parsed payload len %zu.",
  125. mlieseqpayloadlen,
  126. WLAN_ML_BV_CINFO_LINKIDINFO_SIZE,
  127. parsed_payload_len);
  128. return QDF_STATUS_E_PROTO;
  129. }
  130. parsed_payload_len += WLAN_ML_BV_CINFO_LINKIDINFO_SIZE;
  131. }
  132. /* Check if BSS parameter change count is present */
  133. if (presence_bm & WLAN_ML_BV_CTRL_PBM_BSSPARAMCHANGECNT_P) {
  134. if (mlieseqpayloadlen <
  135. (parsed_payload_len +
  136. WLAN_ML_BSSPARAMCHNGCNT_SIZE)) {
  137. mlo_err_rl("ML seq payload len %zu insufficient for BSS parameter change count size %u after parsed payload len %zu.",
  138. mlieseqpayloadlen,
  139. WLAN_ML_BSSPARAMCHNGCNT_SIZE,
  140. parsed_payload_len);
  141. return QDF_STATUS_E_PROTO;
  142. }
  143. parsed_payload_len += WLAN_ML_BSSPARAMCHNGCNT_SIZE;
  144. }
  145. /* Check if Medium Sync Delay Info is present */
  146. if (presence_bm & WLAN_ML_BV_CTRL_PBM_MEDIUMSYNCDELAYINFO_P) {
  147. if (mlieseqpayloadlen <
  148. (parsed_payload_len +
  149. WLAN_ML_BV_CINFO_MEDMSYNCDELAYINFO_SIZE)) {
  150. mlo_err_rl("ML seq payload len %zu insufficient for Medium Sync Delay Info size %u after parsed payload len %zu.",
  151. mlieseqpayloadlen,
  152. WLAN_ML_BV_CINFO_MEDMSYNCDELAYINFO_SIZE,
  153. parsed_payload_len);
  154. return QDF_STATUS_E_PROTO;
  155. }
  156. parsed_payload_len += WLAN_ML_BV_CINFO_MEDMSYNCDELAYINFO_SIZE;
  157. }
  158. /* Check if EML cap is present */
  159. if (presence_bm & WLAN_ML_BV_CTRL_PBM_EMLCAP_P) {
  160. if (mlieseqpayloadlen <
  161. (parsed_payload_len +
  162. WLAN_ML_BV_CINFO_EMLCAP_SIZE)) {
  163. mlo_err_rl("ML seq payload len %zu insufficient for EML cap size %u after parsed payload len %zu.",
  164. mlieseqpayloadlen,
  165. WLAN_ML_BV_CINFO_EMLCAP_SIZE,
  166. parsed_payload_len);
  167. return QDF_STATUS_E_PROTO;
  168. }
  169. parsed_payload_len += WLAN_ML_BV_CINFO_EMLCAP_SIZE;
  170. }
  171. /* Check if MLD cap is present */
  172. if (presence_bm & WLAN_ML_BV_CTRL_PBM_MLDCAPANDOP_P) {
  173. if (mlieseqpayloadlen <
  174. (parsed_payload_len +
  175. WLAN_ML_BV_CINFO_MLDCAPANDOP_SIZE)) {
  176. mlo_err_rl("ML seq payload len %zu insufficient for MLD cap size %u after parsed payload len %zu.",
  177. mlieseqpayloadlen,
  178. WLAN_ML_BV_CINFO_MLDCAPANDOP_SIZE,
  179. parsed_payload_len);
  180. return QDF_STATUS_E_PROTO;
  181. }
  182. parsed_payload_len += WLAN_ML_BV_CINFO_MLDCAPANDOP_SIZE;
  183. }
  184. /* Check if MLD ID is present */
  185. if (presence_bm & WLAN_ML_BV_CTRL_PBM_MLDID_P) {
  186. if (mlieseqpayloadlen <
  187. (parsed_payload_len +
  188. WLAN_ML_BV_CINFO_MLDID_SIZE)) {
  189. mlo_err_rl("ML seq payload len %zu insufficient for MLD ID size %u after parsed payload len %zu.",
  190. mlieseqpayloadlen,
  191. WLAN_ML_BV_CINFO_MLDID_SIZE,
  192. parsed_payload_len);
  193. return QDF_STATUS_E_PROTO;
  194. }
  195. parsed_payload_len += WLAN_ML_BV_CINFO_MLDID_SIZE;
  196. }
  197. exp_cinfo_len = parsed_payload_len - WLAN_ML_CTRL_SIZE;
  198. if (cinfo_len != exp_cinfo_len) {
  199. mlo_err_rl("ML seq common info len %u doesn't match with expected common info len %u",
  200. cinfo_len, exp_cinfo_len);
  201. return QDF_STATUS_E_PROTO;
  202. }
  203. if (link_info_len) {
  204. *link_info_len = mlieseqpayloadlen - parsed_payload_len;
  205. mlo_debug("link_info_len:%zu, parsed_payload_len:%zu",
  206. *link_info_len, parsed_payload_len);
  207. }
  208. if (mlieseqpayloadlen == parsed_payload_len) {
  209. mlo_debug("No Link Info field present");
  210. if (link_info)
  211. *link_info = NULL;
  212. return QDF_STATUS_SUCCESS;
  213. }
  214. if (link_info)
  215. *link_info = mlieseqpayload + parsed_payload_len;
  216. return QDF_STATUS_SUCCESS;
  217. }
  218. static QDF_STATUS
  219. util_parse_prv_multi_link_ctrl(uint8_t *mlieseqpayload,
  220. qdf_size_t mlieseqpayloadlen,
  221. uint8_t **link_info,
  222. qdf_size_t *link_info_len)
  223. {
  224. qdf_size_t parsed_payload_len;
  225. uint16_t mlcontrol;
  226. uint16_t presence_bm;
  227. uint16_t cinfo_len = 0;
  228. uint16_t exp_cinfo_len = 0;
  229. /* This helper returns the location(s) and length(s) of (sub)field(s)
  230. * inferable after parsing the Multi Link element Control field. These
  231. * location(s) and length(s) is/are in reference to the payload section
  232. * of the Multi Link element (after defragmentation, if applicable).
  233. * Here, the payload is the point after the element ID extension of the
  234. * Multi Link element, and includes the payloads of all subsequent
  235. * fragments (if any) but not the headers of those fragments.
  236. *
  237. * Currently, the helper returns the location and length of the Link
  238. * Info field in the Multi Link element sequence. Other (sub)field(s)
  239. * can be added later as required.
  240. */
  241. if (!mlieseqpayload) {
  242. mlo_err("ML seq payload pointer is NULL");
  243. return QDF_STATUS_E_NULL_VALUE;
  244. }
  245. if (!mlieseqpayloadlen) {
  246. mlo_err("ML seq payload len is 0");
  247. return QDF_STATUS_E_INVAL;
  248. }
  249. if (mlieseqpayloadlen < WLAN_ML_CTRL_SIZE) {
  250. mlo_err_rl("ML seq payload len %zu < ML Control size %u",
  251. mlieseqpayloadlen, WLAN_ML_CTRL_SIZE);
  252. return QDF_STATUS_E_PROTO;
  253. }
  254. parsed_payload_len = 0;
  255. qdf_mem_copy(&mlcontrol, mlieseqpayload, WLAN_ML_CTRL_SIZE);
  256. mlcontrol = qdf_le16_to_cpu(mlcontrol);
  257. parsed_payload_len += WLAN_ML_CTRL_SIZE;
  258. presence_bm = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_PBM_IDX,
  259. WLAN_ML_CTRL_PBM_BITS);
  260. if (mlieseqpayloadlen <
  261. (parsed_payload_len + WLAN_ML_PRV_CINFO_LENGTH_SIZE)) {
  262. mlo_err_rl("ML seq payload len %zu insufficient for common info length size %u after parsed payload len %zu.",
  263. mlieseqpayloadlen,
  264. WLAN_ML_PRV_CINFO_LENGTH_SIZE,
  265. parsed_payload_len);
  266. return QDF_STATUS_E_PROTO;
  267. }
  268. cinfo_len = *(mlieseqpayload + parsed_payload_len);
  269. parsed_payload_len += WLAN_ML_PRV_CINFO_LENGTH_SIZE;
  270. /* Check if MLD ID is present */
  271. if (presence_bm & WLAN_ML_PRV_CTRL_PBM_MLDID_P) {
  272. if (mlieseqpayloadlen <
  273. (parsed_payload_len +
  274. WLAN_ML_PRV_CINFO_MLDID_SIZE)) {
  275. mlo_err_rl("ML seq payload len %zu insufficient for MLD ID size %u after parsed payload len %zu.",
  276. mlieseqpayloadlen,
  277. WLAN_ML_PRV_CINFO_MLDID_SIZE,
  278. parsed_payload_len);
  279. return QDF_STATUS_E_PROTO;
  280. }
  281. parsed_payload_len += WLAN_ML_PRV_CINFO_MLDID_SIZE;
  282. }
  283. exp_cinfo_len = parsed_payload_len - WLAN_ML_CTRL_SIZE;
  284. if (cinfo_len != exp_cinfo_len) {
  285. mlo_err_rl("ML seq common info len %u doesn't match with expected common info len %u",
  286. cinfo_len, exp_cinfo_len);
  287. return QDF_STATUS_E_PROTO;
  288. }
  289. if (link_info_len) {
  290. *link_info_len = mlieseqpayloadlen - parsed_payload_len;
  291. mlo_debug("link_info_len:%zu, parsed_payload_len:%zu",
  292. *link_info_len, parsed_payload_len);
  293. }
  294. if (mlieseqpayloadlen == parsed_payload_len) {
  295. mlo_debug("No Link Info field present");
  296. if (link_info)
  297. *link_info = NULL;
  298. return QDF_STATUS_SUCCESS;
  299. }
  300. if (link_info)
  301. *link_info = mlieseqpayload + parsed_payload_len;
  302. return QDF_STATUS_SUCCESS;
  303. }
  304. static QDF_STATUS
  305. util_parse_bvmlie_perstaprofile_stactrl(uint8_t *subelempayload,
  306. qdf_size_t subelempayloadlen,
  307. uint8_t *linkid,
  308. uint16_t *beaconinterval,
  309. bool *is_beaconinterval_valid,
  310. uint64_t *tsfoffset,
  311. bool *is_tsfoffset_valid,
  312. bool *is_complete_profile,
  313. bool *is_macaddr_valid,
  314. struct qdf_mac_addr *macaddr,
  315. bool is_staprof_reqd,
  316. uint8_t **staprof,
  317. qdf_size_t *staprof_len)
  318. {
  319. qdf_size_t parsed_payload_len = 0;
  320. uint16_t stacontrol;
  321. uint8_t completeprofile;
  322. uint8_t nstrlppresent;
  323. enum wlan_ml_bv_linfo_perstaprof_stactrl_nstrbmsz nstrbmsz;
  324. /* This helper returns the location(s) and where required, the length(s)
  325. * of (sub)field(s) inferable after parsing the STA Control field in the
  326. * per-STA profile subelement. These location(s) and length(s) is/are in
  327. * reference to the payload section of the per-STA profile subelement
  328. * (after defragmentation, if applicable). Here, the payload is the
  329. * point after the subelement length in the subelement, and includes the
  330. * payloads of all subsequent fragments (if any) but not the headers of
  331. * those fragments.
  332. *
  333. * Currently, the helper returns the link ID, MAC address, and STA
  334. * profile. More (sub)fields can be added when required.
  335. */
  336. if (!subelempayload) {
  337. mlo_err("Pointer to subelement payload is NULL");
  338. return QDF_STATUS_E_NULL_VALUE;
  339. }
  340. if (!subelempayloadlen) {
  341. mlo_err("Length of subelement payload is zero");
  342. return QDF_STATUS_E_INVAL;
  343. }
  344. if (subelempayloadlen < WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_SIZE) {
  345. mlo_err_rl("Subelement payload length %zu octets is smaller than STA control field of per-STA profile subelement %u octets",
  346. subelempayloadlen,
  347. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_SIZE);
  348. return QDF_STATUS_E_PROTO;
  349. }
  350. parsed_payload_len = 0;
  351. qdf_mem_copy(&stacontrol,
  352. subelempayload,
  353. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_SIZE);
  354. stacontrol = le16toh(stacontrol);
  355. parsed_payload_len += WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_SIZE;
  356. if (linkid) {
  357. *linkid = QDF_GET_BITS(stacontrol,
  358. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_LINKID_IDX,
  359. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_LINKID_BITS);
  360. }
  361. /* Check if this a complete profile */
  362. completeprofile = QDF_GET_BITS(stacontrol,
  363. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_CMPLTPROF_IDX,
  364. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_CMPLTPROF_BITS);
  365. if (completeprofile && is_complete_profile)
  366. *is_complete_profile = true;
  367. /* Check STA Info Length */
  368. if (subelempayloadlen <
  369. parsed_payload_len + WLAN_ML_BV_LINFO_PERSTAPROF_STAINFO_LENGTH_SIZE) {
  370. mlo_err_rl("Length of subelement payload %zu octets not sufficient to contain STA Info Length of size %u octets after parsed payload length of %zu octets.",
  371. subelempayloadlen,
  372. WLAN_ML_BV_LINFO_PERSTAPROF_STAINFO_LENGTH_SIZE,
  373. parsed_payload_len);
  374. return QDF_STATUS_E_PROTO;
  375. }
  376. parsed_payload_len += WLAN_ML_BV_LINFO_PERSTAPROF_STAINFO_LENGTH_SIZE;
  377. if (is_macaddr_valid)
  378. *is_macaddr_valid = false;
  379. /* Check STA MAC address present bit */
  380. if (QDF_GET_BITS(stacontrol,
  381. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_MACADDRP_IDX,
  382. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_MACADDRP_BITS)) {
  383. if (subelempayloadlen <
  384. (parsed_payload_len + QDF_MAC_ADDR_SIZE)) {
  385. mlo_err_rl("Length of subelement payload %zu octets not sufficient to contain MAC address of size %u octets after parsed payload length of %zu octets.",
  386. subelempayloadlen,
  387. QDF_MAC_ADDR_SIZE,
  388. parsed_payload_len);
  389. return QDF_STATUS_E_PROTO;
  390. }
  391. if (macaddr) {
  392. qdf_mem_copy(macaddr->bytes,
  393. subelempayload + parsed_payload_len,
  394. QDF_MAC_ADDR_SIZE);
  395. mlo_nofl_debug("Copied MAC address: " QDF_MAC_ADDR_FMT,
  396. subelempayload + parsed_payload_len);
  397. if (is_macaddr_valid)
  398. *is_macaddr_valid = true;
  399. }
  400. parsed_payload_len += QDF_MAC_ADDR_SIZE;
  401. }
  402. /* Check Beacon Interval present bit */
  403. if (QDF_GET_BITS(stacontrol,
  404. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_BCNINTP_IDX,
  405. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_BCNINTP_BITS)) {
  406. if (subelempayloadlen <
  407. (parsed_payload_len +
  408. WLAN_BEACONINTERVAL_LEN)) {
  409. mlo_err_rl("Length of subelement payload %zu octets not sufficient to contain Beacon Interval of size %u octets after parsed payload length of %zu octets.",
  410. subelempayloadlen,
  411. WLAN_BEACONINTERVAL_LEN,
  412. parsed_payload_len);
  413. return QDF_STATUS_E_PROTO;
  414. }
  415. if (beaconinterval) {
  416. qdf_mem_copy(beaconinterval,
  417. subelempayload + parsed_payload_len,
  418. WLAN_BEACONINTERVAL_LEN);
  419. *beaconinterval = qdf_le16_to_cpu(*beaconinterval);
  420. if (is_beaconinterval_valid)
  421. *is_beaconinterval_valid = true;
  422. }
  423. parsed_payload_len += WLAN_BEACONINTERVAL_LEN;
  424. }
  425. /* Check TSF Offset present bit */
  426. if (QDF_GET_BITS(stacontrol,
  427. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_TSFOFFSETP_IDX,
  428. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_TSFOFFSETP_BITS)) {
  429. if (!completeprofile) {
  430. mlo_err_rl("TSF offset is expected only for complete profiles");
  431. return QDF_STATUS_E_PROTO;
  432. }
  433. if (subelempayloadlen <
  434. (parsed_payload_len +
  435. WLAN_ML_TSF_OFFSET_SIZE)) {
  436. mlo_err_rl("Length of subelement payload %zu octets not sufficient to contain TSF Offset of size %u octets after parsed payload length of %zu octets.",
  437. subelempayloadlen,
  438. WLAN_ML_TSF_OFFSET_SIZE,
  439. parsed_payload_len);
  440. return QDF_STATUS_E_PROTO;
  441. }
  442. if (tsfoffset) {
  443. qdf_mem_copy(tsfoffset,
  444. subelempayload + parsed_payload_len,
  445. WLAN_TIMESTAMP_LEN);
  446. *tsfoffset = qdf_le64_to_cpu(*tsfoffset);
  447. if (is_tsfoffset_valid)
  448. *is_tsfoffset_valid = true;
  449. }
  450. parsed_payload_len += WLAN_ML_TSF_OFFSET_SIZE;
  451. }
  452. /* Check DTIM Info present bit */
  453. if (QDF_GET_BITS(stacontrol,
  454. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_DTIMINFOP_IDX,
  455. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_DTIMINFOP_BITS)) {
  456. if (subelempayloadlen <
  457. (parsed_payload_len +
  458. sizeof(struct wlan_ml_bv_linfo_perstaprof_stainfo_dtiminfo))) {
  459. mlo_err_rl("Length of subelement payload %zu octets not sufficient to contain DTIM Info of size %zu octets after parsed payload length of %zu octets.",
  460. subelempayloadlen,
  461. sizeof(struct wlan_ml_bv_linfo_perstaprof_stainfo_dtiminfo),
  462. parsed_payload_len);
  463. return QDF_STATUS_E_PROTO;
  464. }
  465. parsed_payload_len +=
  466. sizeof(struct wlan_ml_bv_linfo_perstaprof_stainfo_dtiminfo);
  467. }
  468. /* Check NTSR Link pair present bit */
  469. nstrlppresent =
  470. QDF_GET_BITS(stacontrol,
  471. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_NSTRLINKPRP_IDX,
  472. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_NSTRLINKPRP_BITS);
  473. if (completeprofile && nstrlppresent) {
  474. /* Check NTSR Bitmap Size bit */
  475. nstrbmsz =
  476. QDF_GET_BITS(stacontrol,
  477. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_NSTRBMSZ_IDX,
  478. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_NSTRBMSZ_BITS);
  479. if (nstrbmsz == WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_NSTRBMSZ_1_OCTET) {
  480. if (subelempayloadlen <
  481. (parsed_payload_len + 1)) {
  482. mlo_err_rl("Length of subelement payload %zu octets not sufficient to contain NTSR Bitmap of size 1 octet after parsed payload length of %zu octets.",
  483. subelempayloadlen,
  484. parsed_payload_len);
  485. return QDF_STATUS_E_PROTO;
  486. }
  487. parsed_payload_len += 1;
  488. } else if (nstrbmsz == WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_NSTRBMSZ_2_OCTETS) {
  489. if (subelempayloadlen <
  490. (parsed_payload_len + 2)) {
  491. mlo_err_rl("Length of subelement payload %zu octets not sufficient to contain NTSR Bitmap of size 2 octets after parsed payload length of %zu octets.",
  492. subelempayloadlen,
  493. parsed_payload_len);
  494. return QDF_STATUS_E_PROTO;
  495. }
  496. parsed_payload_len += 2;
  497. } else {
  498. /* Though an invalid value cannot occur if only 1 bit is
  499. * used, we check for it in a generic manner in case the
  500. * number of bits is increased in the future.
  501. */
  502. mlo_err_rl("Invalid NSTR Bitmap size %u", nstrbmsz);
  503. return QDF_STATUS_E_PROTO;
  504. }
  505. }
  506. /* Check BSS Parameters Change Count Present bit */
  507. if (QDF_GET_BITS(stacontrol,
  508. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_BSSPARAMCHNGCNTP_IDX,
  509. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_BSSPARAMCHNGCNTP_BITS)) {
  510. if (subelempayloadlen <
  511. (parsed_payload_len +
  512. WLAN_ML_BSSPARAMCHNGCNT_SIZE)) {
  513. mlo_err_rl("Length of subelement payload %zu octets not sufficient to contain BSS Parameters Change Count of size %u octets after parsed payload length of %zu octets.",
  514. subelempayloadlen,
  515. WLAN_ML_BSSPARAMCHNGCNT_SIZE,
  516. parsed_payload_len);
  517. return QDF_STATUS_E_PROTO;
  518. }
  519. parsed_payload_len += WLAN_ML_BSSPARAMCHNGCNT_SIZE;
  520. }
  521. /* Note: Some implementation versions of hostapd/wpa_supplicant may
  522. * provide a per-STA profile without STA profile. Let the caller
  523. * indicate whether a STA profile is required to be found. This may be
  524. * revisited as upstreaming progresses.
  525. */
  526. if (!is_staprof_reqd)
  527. return QDF_STATUS_SUCCESS;
  528. if (subelempayloadlen == parsed_payload_len) {
  529. mlo_err_rl("Subelement payload length %zu == parsed payload length %zu. Unable to get STA profile.",
  530. subelempayloadlen,
  531. parsed_payload_len);
  532. return QDF_STATUS_E_PROTO;
  533. }
  534. if (staprof_len)
  535. *staprof_len = subelempayloadlen - parsed_payload_len;
  536. if (staprof)
  537. *staprof = subelempayload + parsed_payload_len;
  538. return QDF_STATUS_SUCCESS;
  539. }
  540. static QDF_STATUS
  541. util_parse_prvmlie_perstaprofile_stactrl(uint8_t *subelempayload,
  542. qdf_size_t subelempayloadlen,
  543. uint8_t *linkid,
  544. bool is_staprof_reqd,
  545. uint8_t **staprof,
  546. qdf_size_t *staprof_len)
  547. {
  548. qdf_size_t parsed_payload_len = 0;
  549. uint16_t stacontrol;
  550. uint8_t completeprofile;
  551. /* This helper returns the location(s) and where required, the length(s)
  552. * of (sub)field(s) inferable after parsing the STA Control field in the
  553. * per-STA profile subelement. These location(s) and length(s) is/are in
  554. * reference to the payload section of the per-STA profile subelement
  555. * (after defragmentation, if applicable). Here, the payload is the
  556. * point after the subelement length in the subelement, and includes the
  557. * payloads of all subsequent fragments (if any) but not the headers of
  558. * those fragments.
  559. *
  560. * Currently, the helper returns the link ID, MAC address, and STA
  561. * profile. More (sub)fields can be added when required.
  562. */
  563. if (!subelempayload) {
  564. mlo_err("Pointer to subelement payload is NULL");
  565. return QDF_STATUS_E_NULL_VALUE;
  566. }
  567. if (!subelempayloadlen) {
  568. mlo_err("Length of subelement payload is zero");
  569. return QDF_STATUS_E_INVAL;
  570. }
  571. if (subelempayloadlen < WLAN_ML_PRV_LINFO_PERSTAPROF_STACTRL_SIZE) {
  572. mlo_err_rl("Subelement payload length %zu octets is smaller than STA control field of per-STA profile subelement %u octets",
  573. subelempayloadlen,
  574. WLAN_ML_PRV_LINFO_PERSTAPROF_STACTRL_SIZE);
  575. return QDF_STATUS_E_PROTO;
  576. }
  577. parsed_payload_len = 0;
  578. qdf_mem_copy(&stacontrol,
  579. subelempayload,
  580. WLAN_ML_PRV_LINFO_PERSTAPROF_STACTRL_SIZE);
  581. stacontrol = qdf_le16_to_cpu(stacontrol);
  582. parsed_payload_len += WLAN_ML_PRV_LINFO_PERSTAPROF_STACTRL_SIZE;
  583. if (linkid) {
  584. *linkid = QDF_GET_BITS(stacontrol,
  585. WLAN_ML_PRV_LINFO_PERSTAPROF_STACTRL_LINKID_IDX,
  586. WLAN_ML_PRV_LINFO_PERSTAPROF_STACTRL_LINKID_BITS);
  587. }
  588. /* Check if this a complete profile */
  589. completeprofile = QDF_GET_BITS(stacontrol,
  590. WLAN_ML_PRV_LINFO_PERSTAPROF_STACTRL_CMPLTPROF_IDX,
  591. WLAN_ML_PRV_LINFO_PERSTAPROF_STACTRL_CMPLTPROF_BITS);
  592. /* Note: Some implementation versions of hostapd/wpa_supplicant may
  593. * provide a per-STA profile without STA profile. Let the caller
  594. * indicate whether a STA profile is required to be found. This may be
  595. * revisited as upstreaming progresses.
  596. */
  597. if (!is_staprof_reqd)
  598. return QDF_STATUS_SUCCESS;
  599. if (subelempayloadlen == parsed_payload_len) {
  600. mlo_err_rl("Subelement payload length %zu == parsed payload length %zu. Unable to get STA profile.",
  601. subelempayloadlen,
  602. parsed_payload_len);
  603. return QDF_STATUS_E_PROTO;
  604. }
  605. if (staprof_len)
  606. *staprof_len = subelempayloadlen - parsed_payload_len;
  607. if (staprof)
  608. *staprof = subelempayload + parsed_payload_len;
  609. return QDF_STATUS_SUCCESS;
  610. }
  611. static
  612. uint8_t *util_get_successorfrag(uint8_t *currie, uint8_t *frame, qdf_size_t len)
  613. {
  614. uint8_t *nextie;
  615. if (!currie || !frame || !len)
  616. return NULL;
  617. if ((currie + MIN_IE_LEN) > (frame + len))
  618. return NULL;
  619. /* Check whether there is sufficient space in the frame for the current
  620. * IE, plus at least another MIN_IE_LEN bytes for the IE header of a
  621. * fragment (if present) that would come just after the current IE.
  622. */
  623. if ((currie + MIN_IE_LEN + currie[TAG_LEN_POS] + MIN_IE_LEN) >
  624. (frame + len))
  625. return NULL;
  626. nextie = currie + currie[TAG_LEN_POS] + MIN_IE_LEN;
  627. /* Check whether there is sufficient space in the frame for the next IE
  628. */
  629. if ((nextie + MIN_IE_LEN + nextie[TAG_LEN_POS]) > (frame + len))
  630. return NULL;
  631. if (nextie[ID_POS] != WLAN_ELEMID_FRAGMENT)
  632. return NULL;
  633. return nextie;
  634. }
  635. static
  636. QDF_STATUS util_parse_partner_info_from_linkinfo(uint8_t *linkinfo,
  637. qdf_size_t linkinfo_len,
  638. struct mlo_partner_info *partner_info)
  639. {
  640. uint8_t linkid;
  641. struct qdf_mac_addr macaddr;
  642. bool is_macaddr_valid;
  643. uint8_t *linkinfo_currpos;
  644. qdf_size_t linkinfo_remlen;
  645. bool is_subelemfragseq;
  646. uint8_t subelemid;
  647. qdf_size_t subelemseqtotallen;
  648. qdf_size_t subelemseqpayloadlen;
  649. qdf_size_t defragpayload_len;
  650. QDF_STATUS ret;
  651. /* This helper function parses partner info from the per-STA profiles
  652. * present (if any) in the Link Info field in the payload of a Multi
  653. * Link element (after defragmentation if required). The caller should
  654. * pass a copy of the payload so that inline defragmentation of
  655. * subelements can be carried out if required. The subelement
  656. * defragmentation (if applicable) in this Control Path helper is
  657. * required for maintainability, accuracy and eliminating current and
  658. * future per-field-access multi-level fragment boundary checks and
  659. * adjustments, given the complex format of Multi Link elements. It is
  660. * also most likely to be required mainly at the client side.
  661. */
  662. if (!linkinfo) {
  663. mlo_err("linkinfo is NULL");
  664. return QDF_STATUS_E_NULL_VALUE;
  665. }
  666. if (!linkinfo_len) {
  667. mlo_err("linkinfo_len is zero");
  668. return QDF_STATUS_E_NULL_VALUE;
  669. }
  670. if (!partner_info) {
  671. mlo_err("ML partner info is NULL");
  672. return QDF_STATUS_E_NULL_VALUE;
  673. }
  674. partner_info->num_partner_links = 0;
  675. linkinfo_currpos = linkinfo;
  676. linkinfo_remlen = linkinfo_len;
  677. while (linkinfo_remlen) {
  678. if (linkinfo_remlen < sizeof(struct subelem_header)) {
  679. mlo_err_rl("Remaining length in link info %zu octets is smaller than subelement header length %zu octets",
  680. linkinfo_remlen,
  681. sizeof(struct subelem_header));
  682. return QDF_STATUS_E_PROTO;
  683. }
  684. subelemid = linkinfo_currpos[ID_POS];
  685. is_subelemfragseq = false;
  686. subelemseqtotallen = 0;
  687. subelemseqpayloadlen = 0;
  688. ret = wlan_get_subelem_fragseq_info(WLAN_ML_LINFO_SUBELEMID_FRAGMENT,
  689. linkinfo_currpos,
  690. linkinfo_remlen,
  691. &is_subelemfragseq,
  692. &subelemseqtotallen,
  693. &subelemseqpayloadlen);
  694. if (QDF_IS_STATUS_ERROR(ret))
  695. return ret;
  696. if (is_subelemfragseq) {
  697. if (!subelemseqpayloadlen) {
  698. mlo_err_rl("Subelement fragment sequence payload is reported as 0, investigate");
  699. return QDF_STATUS_E_FAILURE;
  700. }
  701. mlo_debug("Subelement fragment sequence found with payload len %zu",
  702. subelemseqpayloadlen);
  703. ret = wlan_defrag_subelem_fragseq(true,
  704. WLAN_ML_LINFO_SUBELEMID_FRAGMENT,
  705. linkinfo_currpos,
  706. linkinfo_remlen,
  707. NULL,
  708. 0,
  709. &defragpayload_len);
  710. if (QDF_IS_STATUS_ERROR(ret))
  711. return ret;
  712. if (defragpayload_len != subelemseqpayloadlen) {
  713. mlo_err_rl("Length of defragmented payload %zu octets is not equal to length of subelement fragment sequence payload %zu octets",
  714. defragpayload_len,
  715. subelemseqpayloadlen);
  716. return QDF_STATUS_E_FAILURE;
  717. }
  718. /* Adjust linkinfo_remlen to reflect removal of all
  719. * subelement headers except the header of the lead
  720. * subelement.
  721. */
  722. linkinfo_remlen -= (subelemseqtotallen -
  723. subelemseqpayloadlen -
  724. sizeof(struct subelem_header));
  725. } else {
  726. if (linkinfo_remlen <
  727. (sizeof(struct subelem_header) +
  728. linkinfo_currpos[TAG_LEN_POS])) {
  729. mlo_err_rl("Remaining length in link info %zu octets is smaller than total size of current subelement %zu octets",
  730. linkinfo_remlen,
  731. sizeof(struct subelem_header) +
  732. linkinfo_currpos[TAG_LEN_POS]);
  733. return QDF_STATUS_E_PROTO;
  734. }
  735. subelemseqpayloadlen = linkinfo_currpos[TAG_LEN_POS];
  736. }
  737. if (subelemid == WLAN_ML_LINFO_SUBELEMID_PERSTAPROFILE) {
  738. is_macaddr_valid = false;
  739. ret = util_parse_bvmlie_perstaprofile_stactrl(linkinfo_currpos +
  740. sizeof(struct subelem_header),
  741. subelemseqpayloadlen,
  742. &linkid,
  743. NULL,
  744. NULL,
  745. NULL,
  746. NULL,
  747. NULL,
  748. &is_macaddr_valid,
  749. &macaddr,
  750. false,
  751. NULL,
  752. NULL);
  753. if (QDF_IS_STATUS_ERROR(ret)) {
  754. return ret;
  755. }
  756. if (is_macaddr_valid) {
  757. if (partner_info->num_partner_links >=
  758. QDF_ARRAY_SIZE(partner_info->partner_link_info)) {
  759. mlo_err_rl("Insufficient size %zu of array for partner link info",
  760. QDF_ARRAY_SIZE(partner_info->partner_link_info));
  761. return QDF_STATUS_E_NOMEM;
  762. }
  763. partner_info->partner_link_info[partner_info->num_partner_links].link_id =
  764. linkid;
  765. qdf_mem_copy(&partner_info->partner_link_info[partner_info->num_partner_links].link_addr,
  766. &macaddr,
  767. sizeof(partner_info->partner_link_info[partner_info->num_partner_links].link_addr));
  768. partner_info->num_partner_links++;
  769. } else {
  770. mlo_warn_rl("MAC address not found in STA Info field of per-STA profile with link ID %u",
  771. linkid);
  772. }
  773. }
  774. linkinfo_remlen -= (sizeof(struct subelem_header) +
  775. subelemseqpayloadlen);
  776. linkinfo_currpos += (sizeof(struct subelem_header) +
  777. subelemseqpayloadlen);
  778. }
  779. mlo_debug("Number of ML partner links found=%u",
  780. partner_info->num_partner_links);
  781. return QDF_STATUS_SUCCESS;
  782. }
  783. static QDF_STATUS
  784. util_parse_probereq_info_from_linkinfo(uint8_t *linkinfo,
  785. qdf_size_t linkinfo_len,
  786. struct mlo_probereq_info *probereq_info)
  787. {
  788. uint8_t linkid;
  789. uint8_t *linkinfo_currpos;
  790. qdf_size_t linkinfo_remlen;
  791. bool is_subelemfragseq;
  792. uint8_t subelemid;
  793. qdf_size_t subelemseqtotallen;
  794. qdf_size_t subelemseqpayloadlen;
  795. qdf_size_t defragpayload_len;
  796. QDF_STATUS ret;
  797. /* This helper function parses probe request info from the per-STA prof
  798. * present (if any) in the Link Info field in the payload of a Multi
  799. * Link element (after defragmentation if required). The caller should
  800. * pass a copy of the payload so that inline defragmentation of
  801. * subelements can be carried out if required. The subelement
  802. * defragmentation (if applicable) in this Control Path helper is
  803. * required for maintainability, accuracy and eliminating current and
  804. * future per-field-access multi-level fragment boundary checks and
  805. * adjustments, given the complex format of Multi Link elements. It is
  806. * also most likely to be required mainly at the client side.
  807. */
  808. if (!linkinfo) {
  809. mlo_err("linkinfo is NULL");
  810. return QDF_STATUS_E_NULL_VALUE;
  811. }
  812. if (!linkinfo_len) {
  813. mlo_err("linkinfo_len is zero");
  814. return QDF_STATUS_E_NULL_VALUE;
  815. }
  816. if (!probereq_info) {
  817. mlo_err("ML probe req info is NULL");
  818. return QDF_STATUS_E_NULL_VALUE;
  819. }
  820. probereq_info->num_links = 0;
  821. linkinfo_currpos = linkinfo;
  822. linkinfo_remlen = linkinfo_len;
  823. while (linkinfo_remlen) {
  824. if (linkinfo_remlen < sizeof(struct subelem_header)) {
  825. mlo_err_rl("Remaining length in link info %zu octets is smaller than subelement header length %zu octets",
  826. linkinfo_remlen,
  827. sizeof(struct subelem_header));
  828. return QDF_STATUS_E_PROTO;
  829. }
  830. subelemid = linkinfo_currpos[ID_POS];
  831. is_subelemfragseq = false;
  832. subelemseqtotallen = 0;
  833. subelemseqpayloadlen = 0;
  834. ret = wlan_get_subelem_fragseq_info(WLAN_ML_LINFO_SUBELEMID_FRAGMENT,
  835. linkinfo_currpos,
  836. linkinfo_remlen,
  837. &is_subelemfragseq,
  838. &subelemseqtotallen,
  839. &subelemseqpayloadlen);
  840. if (QDF_IS_STATUS_ERROR(ret))
  841. return ret;
  842. if (is_subelemfragseq) {
  843. if (!subelemseqpayloadlen) {
  844. mlo_err_rl("Subelement fragment sequence payload is reported as 0, investigate");
  845. return QDF_STATUS_E_FAILURE;
  846. }
  847. mlo_debug("Subelement fragment sequence found with payload len %zu",
  848. subelemseqpayloadlen);
  849. ret = wlan_defrag_subelem_fragseq(true,
  850. WLAN_ML_LINFO_SUBELEMID_FRAGMENT,
  851. linkinfo_currpos,
  852. linkinfo_remlen,
  853. NULL,
  854. 0,
  855. &defragpayload_len);
  856. if (QDF_IS_STATUS_ERROR(ret))
  857. return ret;
  858. if (defragpayload_len != subelemseqpayloadlen) {
  859. mlo_err_rl("Length of defragmented payload %zu octets is not equal to length of subelement fragment sequence payload %zu octets",
  860. defragpayload_len,
  861. subelemseqpayloadlen);
  862. return QDF_STATUS_E_FAILURE;
  863. }
  864. /* Adjust linkinfo_remlen to reflect removal of all
  865. * subelement headers except the header of the lead
  866. * subelement.
  867. */
  868. linkinfo_remlen -= (subelemseqtotallen -
  869. subelemseqpayloadlen -
  870. sizeof(struct subelem_header));
  871. } else {
  872. if (linkinfo_remlen <
  873. (sizeof(struct subelem_header) +
  874. linkinfo_currpos[TAG_LEN_POS])) {
  875. mlo_err_rl("Remaining length in link info %zu octets is smaller than total size of current subelement %zu octets",
  876. linkinfo_remlen,
  877. sizeof(struct subelem_header) +
  878. linkinfo_currpos[TAG_LEN_POS]);
  879. return QDF_STATUS_E_PROTO;
  880. }
  881. subelemseqpayloadlen = linkinfo_currpos[TAG_LEN_POS];
  882. }
  883. if (subelemid == WLAN_ML_LINFO_SUBELEMID_PERSTAPROFILE) {
  884. ret = util_parse_prvmlie_perstaprofile_stactrl(linkinfo_currpos +
  885. sizeof(struct subelem_header),
  886. subelemseqpayloadlen,
  887. &linkid,
  888. false,
  889. NULL,
  890. NULL);
  891. if (QDF_IS_STATUS_ERROR(ret))
  892. return ret;
  893. if (probereq_info->num_links >=
  894. QDF_ARRAY_SIZE(probereq_info->link_id)) {
  895. mlo_err_rl("Insufficient size %zu of array for probe req link id",
  896. QDF_ARRAY_SIZE(probereq_info->link_id));
  897. return QDF_STATUS_E_NOMEM;
  898. }
  899. probereq_info->link_id[probereq_info->num_links] = linkid;
  900. probereq_info->num_links++;
  901. mlo_debug("LINK ID requested is = %u", linkid);
  902. }
  903. linkinfo_remlen -= (sizeof(struct subelem_header) +
  904. subelemseqpayloadlen);
  905. linkinfo_currpos += (sizeof(struct subelem_header) +
  906. subelemseqpayloadlen);
  907. }
  908. mlo_debug("Number of ML probe request links found=%u",
  909. probereq_info->num_links);
  910. return QDF_STATUS_SUCCESS;
  911. }
  912. static
  913. QDF_STATUS util_get_noninheritlists(uint8_t *buff, qdf_size_t buff_len,
  914. uint8_t **ninherit_elemlist,
  915. qdf_size_t *ninherit_elemlist_len,
  916. uint8_t **ninherit_elemextlist,
  917. qdf_size_t *ninherit_elemextlist_len)
  918. {
  919. uint8_t *ninherit_ie;
  920. qdf_size_t unparsed_len;
  921. /* Note: This functionality provided by this helper may be combined with
  922. * other, older non-inheritance parsing helper functionality and exposed
  923. * as a common API as part of future efforts once the older
  924. * functionality can be made generic.
  925. */
  926. if (!buff) {
  927. mlo_err("Pointer to buffer for IEs is NULL");
  928. return QDF_STATUS_E_NULL_VALUE;
  929. }
  930. if (!buff_len) {
  931. mlo_err("IE buffer length is zero");
  932. return QDF_STATUS_E_INVAL;
  933. }
  934. if (!ninherit_elemlist) {
  935. mlo_err("Pointer to Non-Inheritance element ID list array is NULL");
  936. return QDF_STATUS_E_NULL_VALUE;
  937. }
  938. if (!ninherit_elemlist_len) {
  939. mlo_err("Pointer to Non-Inheritance element ID list array length is NULL");
  940. return QDF_STATUS_E_NULL_VALUE;
  941. }
  942. if (!ninherit_elemextlist) {
  943. mlo_err("Pointer to Non-Inheritance element ID extension list array is NULL");
  944. return QDF_STATUS_E_NULL_VALUE;
  945. }
  946. if (!ninherit_elemextlist_len) {
  947. mlo_err("Pointer to Non-Inheritance element ID extension list array length is NULL");
  948. return QDF_STATUS_E_NULL_VALUE;
  949. }
  950. ninherit_ie = NULL;
  951. *ninherit_elemlist_len = 0;
  952. *ninherit_elemlist = NULL;
  953. *ninherit_elemextlist_len = 0;
  954. *ninherit_elemextlist = NULL;
  955. ninherit_ie =
  956. (uint8_t *)util_find_extn_eid(WLAN_ELEMID_EXTN_ELEM,
  957. WLAN_EXTN_ELEMID_NONINHERITANCE,
  958. buff,
  959. buff_len);
  960. if (ninherit_ie) {
  961. if ((ninherit_ie + TAG_LEN_POS) > (buff + buff_len - 1)) {
  962. mlo_err_rl("Position of length field of Non-Inheritance element would exceed IE buffer boundary");
  963. return QDF_STATUS_E_PROTO;
  964. }
  965. if ((ninherit_ie + ninherit_ie[TAG_LEN_POS] + MIN_IE_LEN) >
  966. (buff + buff_len)) {
  967. mlo_err_rl("Non-Inheritance element with total length %u would exceed IE buffer boundary",
  968. ninherit_ie[TAG_LEN_POS] + MIN_IE_LEN);
  969. return QDF_STATUS_E_PROTO;
  970. }
  971. if ((ninherit_ie[TAG_LEN_POS] + MIN_IE_LEN) <
  972. MIN_NONINHERITANCEELEM_LEN) {
  973. mlo_err_rl("Non-Inheritance element size %u is smaller than the minimum required %u",
  974. ninherit_ie[TAG_LEN_POS] + MIN_IE_LEN,
  975. MIN_NONINHERITANCEELEM_LEN);
  976. return QDF_STATUS_E_PROTO;
  977. }
  978. /* Track the number of unparsed octets, excluding the IE header.
  979. */
  980. unparsed_len = ninherit_ie[TAG_LEN_POS];
  981. /* Mark the element ID extension as parsed */
  982. unparsed_len--;
  983. *ninherit_elemlist_len = ninherit_ie[ELEM_ID_LIST_LEN_POS];
  984. unparsed_len--;
  985. /* While checking if the Non-Inheritance element ID list length
  986. * exceeds the remaining unparsed IE space, we factor in one
  987. * octet for the element extension ID list length and subtract
  988. * this from the unparsed IE space.
  989. */
  990. if (*ninherit_elemlist_len > (unparsed_len - 1)) {
  991. mlo_err_rl("Non-Inheritance element ID list length %zu exceeds remaining unparsed IE space, minus an octet for element extension ID list length %zu",
  992. *ninherit_elemlist_len, unparsed_len - 1);
  993. return QDF_STATUS_E_PROTO;
  994. }
  995. if (*ninherit_elemlist_len != 0) {
  996. *ninherit_elemlist = ninherit_ie + ELEM_ID_LIST_POS;
  997. unparsed_len -= *ninherit_elemlist_len;
  998. }
  999. *ninherit_elemextlist_len =
  1000. ninherit_ie[ELEM_ID_LIST_LEN_POS + *ninherit_elemlist_len + 1];
  1001. unparsed_len--;
  1002. if (*ninherit_elemextlist_len > unparsed_len) {
  1003. mlo_err_rl("Non-Inheritance element ID extension list length %zu exceeds remaining unparsed IE space %zu",
  1004. *ninherit_elemextlist_len, unparsed_len);
  1005. return QDF_STATUS_E_PROTO;
  1006. }
  1007. if (*ninherit_elemextlist_len != 0) {
  1008. *ninherit_elemextlist = ninherit_ie +
  1009. ELEM_ID_LIST_LEN_POS + (*ninherit_elemlist_len)
  1010. + 2;
  1011. unparsed_len -= *ninherit_elemextlist_len;
  1012. }
  1013. if (unparsed_len > 0) {
  1014. mlo_err_rl("Unparsed length is %zu, expected 0",
  1015. unparsed_len);
  1016. return QDF_STATUS_E_PROTO;
  1017. }
  1018. }
  1019. /* If Non-Inheritance element is not found, we still return success,
  1020. * with the list lengths kept at zero.
  1021. */
  1022. mlo_debug("Non-Inheritance element ID list array length=%zu",
  1023. *ninherit_elemlist_len);
  1024. mlo_debug("Non-Inheritance element ID extension list array length=%zu",
  1025. *ninherit_elemextlist_len);
  1026. return QDF_STATUS_SUCCESS;
  1027. }
  1028. static
  1029. QDF_STATUS util_eval_ie_in_noninheritlist(uint8_t *ie, qdf_size_t total_ie_len,
  1030. uint8_t *ninherit_elemlist,
  1031. qdf_size_t ninherit_elemlist_len,
  1032. uint8_t *ninherit_elemextlist,
  1033. qdf_size_t ninherit_elemextlist_len,
  1034. bool *is_in_noninheritlist)
  1035. {
  1036. int i;
  1037. /* Evaluate whether the given IE is in the given Non-Inheritance element
  1038. * ID list or Non-Inheritance element ID extension list, and update the
  1039. * result into is_in_noninheritlist. If any list is empty, then the IE
  1040. * is considered to not be present in that list. Both lists can be
  1041. * empty.
  1042. *
  1043. * If QDF_STATUS_SUCCESS is returned, it means that the evaluation is
  1044. * successful, and that is_in_noninheritlist contains a valid value
  1045. * (which could be true or false). If a QDF_STATUS error value is
  1046. * returned, the value in is_in_noninheritlist is invalid and the caller
  1047. * should ignore it.
  1048. */
  1049. /* Note: The functionality provided by this helper may be combined with
  1050. * other, older non-inheritance parsing helper functionality and exposed
  1051. * as a common API as part of future efforts once the older
  1052. * functionality can be made generic.
  1053. */
  1054. /* Except for is_in_noninheritlist and ie, other pointer arguments are
  1055. * permitted to be NULL if they are inapplicable. If they are
  1056. * applicable, they will be checked to ensure they are not NULL.
  1057. */
  1058. if (!is_in_noninheritlist) {
  1059. mlo_err("NULL pointer to flag that indicates if element is in a Non-Inheritance list");
  1060. return QDF_STATUS_E_NULL_VALUE;
  1061. }
  1062. /* If ninherit_elemlist_len and ninherit_elemextlist_len are both zero
  1063. * as checked soon in this function, we won't be accessing the IE.
  1064. * However, we still check right-away if the pointer to the IE is
  1065. * non-NULL and whether the total IE length is sane enough to access the
  1066. * element ID and if applicable, the element ID extension, since it
  1067. * doesn't make sense to set the flag in is_in_noninheritlist for a NULL
  1068. * IE pointer or an IE whose total length is not sane enough to
  1069. * distinguish the identity of the IE.
  1070. */
  1071. if (!ie) {
  1072. mlo_err("NULL pointer to IE");
  1073. return QDF_STATUS_E_NULL_VALUE;
  1074. }
  1075. if (total_ie_len < (ID_POS + 1)) {
  1076. mlo_err("Total IE length %zu is smaller than minimum required to access element ID %u",
  1077. total_ie_len, ID_POS + 1);
  1078. return QDF_STATUS_E_INVAL;
  1079. }
  1080. if ((ie[ID_POS] == WLAN_ELEMID_EXTN_ELEM) &&
  1081. (total_ie_len < (IDEXT_POS + 1))) {
  1082. mlo_err("Total IE length %zu is smaller than minimum required to access element ID extension %u",
  1083. total_ie_len, IDEXT_POS + 1);
  1084. return QDF_STATUS_E_INVAL;
  1085. }
  1086. *is_in_noninheritlist = false;
  1087. /* If both the Non-Inheritance element list and Non-Inheritance element
  1088. * ID extension list are empty, then return success since we can
  1089. * conclude immediately that the given element does not occur in any
  1090. * Non-Inheritance list. The is_in_noninheritlist remains set to false
  1091. * as required.
  1092. */
  1093. if (!ninherit_elemlist_len && !ninherit_elemextlist_len)
  1094. return QDF_STATUS_SUCCESS;
  1095. if (ie[ID_POS] != WLAN_ELEMID_EXTN_ELEM) {
  1096. if (!ninherit_elemlist_len)
  1097. return QDF_STATUS_SUCCESS;
  1098. if (!ninherit_elemlist) {
  1099. mlo_err("NULL pointer to Non-Inheritance element ID list though length of element ID list is %zu",
  1100. ninherit_elemlist_len);
  1101. return QDF_STATUS_E_NULL_VALUE;
  1102. }
  1103. for (i = 0; i < ninherit_elemlist_len; i++) {
  1104. if (ie[ID_POS] == ninherit_elemlist[i]) {
  1105. *is_in_noninheritlist = true;
  1106. return QDF_STATUS_SUCCESS;
  1107. }
  1108. }
  1109. } else {
  1110. if (!ninherit_elemextlist_len)
  1111. return QDF_STATUS_SUCCESS;
  1112. if (!ninherit_elemextlist) {
  1113. mlo_err("NULL pointer to Non-Inheritance element ID extension list though length of element ID extension list is %zu",
  1114. ninherit_elemextlist_len);
  1115. return QDF_STATUS_E_NULL_VALUE;
  1116. }
  1117. for (i = 0; i < ninherit_elemextlist_len; i++) {
  1118. if (ie[IDEXT_POS] == ninherit_elemextlist[i]) {
  1119. *is_in_noninheritlist = true;
  1120. return QDF_STATUS_SUCCESS;
  1121. }
  1122. }
  1123. }
  1124. return QDF_STATUS_SUCCESS;
  1125. }
  1126. static inline
  1127. QDF_STATUS util_validate_reportingsta_ie(const uint8_t *reportingsta_ie,
  1128. const uint8_t *frame_iesection,
  1129. const qdf_size_t frame_iesection_len)
  1130. {
  1131. qdf_size_t reportingsta_ie_size;
  1132. if (!reportingsta_ie) {
  1133. mlo_err("Pointer to reporting STA IE is NULL");
  1134. return QDF_STATUS_E_NULL_VALUE;
  1135. }
  1136. if (!frame_iesection) {
  1137. mlo_err("Pointer to start of IE section in reporting frame is NULL");
  1138. return QDF_STATUS_E_NULL_VALUE;
  1139. }
  1140. if (!frame_iesection_len) {
  1141. mlo_err("Length of IE section in reporting frame is zero");
  1142. return QDF_STATUS_E_INVAL;
  1143. }
  1144. if ((reportingsta_ie + ID_POS) > (frame_iesection +
  1145. frame_iesection_len - 1)) {
  1146. mlo_err_rl("Position of element ID field of element for reporting STA would exceed frame IE section boundary");
  1147. return QDF_STATUS_E_PROTO;
  1148. }
  1149. if ((reportingsta_ie + TAG_LEN_POS) > (frame_iesection +
  1150. frame_iesection_len - 1)) {
  1151. mlo_err_rl("Position of length field of element with element ID %u for reporting STA would exceed frame IE section boundary",
  1152. reportingsta_ie[ID_POS]);
  1153. return QDF_STATUS_E_PROTO;
  1154. }
  1155. if ((reportingsta_ie[ID_POS] == WLAN_ELEMID_EXTN_ELEM) &&
  1156. ((reportingsta_ie + IDEXT_POS) > (frame_iesection +
  1157. frame_iesection_len - 1))) {
  1158. mlo_err_rl("Position of element ID extension field of element would exceed frame IE section boundary");
  1159. return QDF_STATUS_E_PROTO;
  1160. }
  1161. reportingsta_ie_size = reportingsta_ie[TAG_LEN_POS] + MIN_IE_LEN;
  1162. if ((reportingsta_ie[ID_POS] == WLAN_ELEMID_EXTN_ELEM) &&
  1163. (reportingsta_ie_size < (IDEXT_POS + 1))) {
  1164. mlo_err_rl("Total length %zu of element for reporting STA is smaller than minimum required to access element ID extension %u",
  1165. reportingsta_ie_size, IDEXT_POS + 1);
  1166. return QDF_STATUS_E_PROTO;
  1167. }
  1168. if ((reportingsta_ie[ID_POS] == WLAN_ELEMID_VENDOR) &&
  1169. (reportingsta_ie_size < (PAYLOAD_START_POS + OUI_LEN))) {
  1170. mlo_err_rl("Total length %zu of element for reporting STA is smaller than minimum required to access vendor EID %u",
  1171. reportingsta_ie_size, PAYLOAD_START_POS + OUI_LEN);
  1172. return QDF_STATUS_E_PROTO;
  1173. }
  1174. if ((reportingsta_ie + reportingsta_ie_size) >
  1175. (frame_iesection + frame_iesection_len)) {
  1176. if (reportingsta_ie[ID_POS] == WLAN_ELEMID_EXTN_ELEM) {
  1177. mlo_err_rl("Total size %zu octets of element with element ID %u element ID extension %u for reporting STA would exceed frame IE section boundary",
  1178. reportingsta_ie_size,
  1179. reportingsta_ie[ID_POS],
  1180. reportingsta_ie[IDEXT_POS]);
  1181. } else {
  1182. mlo_err_rl("Total size %zu octets of element with element ID %u for reporting STA would exceed frame IE section boundary",
  1183. reportingsta_ie_size,
  1184. reportingsta_ie[ID_POS]);
  1185. }
  1186. return QDF_STATUS_E_PROTO;
  1187. }
  1188. return QDF_STATUS_SUCCESS;
  1189. }
  1190. static inline
  1191. QDF_STATUS util_validate_sta_prof_ie(const uint8_t *sta_prof_ie,
  1192. const uint8_t *sta_prof_iesection,
  1193. const qdf_size_t sta_prof_iesection_len)
  1194. {
  1195. qdf_size_t sta_prof_ie_size;
  1196. if (!sta_prof_ie) {
  1197. mlo_err("Pointer to STA profile IE is NULL");
  1198. return QDF_STATUS_E_NULL_VALUE;
  1199. }
  1200. if (!sta_prof_iesection) {
  1201. mlo_err("Pointer to start of IE section in STA profile is NULL");
  1202. return QDF_STATUS_E_NULL_VALUE;
  1203. }
  1204. if (!sta_prof_iesection_len) {
  1205. mlo_err("Length of IE section in STA profile is zero");
  1206. return QDF_STATUS_E_INVAL;
  1207. }
  1208. if ((sta_prof_ie + ID_POS) > (sta_prof_iesection +
  1209. sta_prof_iesection_len - 1)) {
  1210. mlo_err_rl("Position of element ID field of STA profile element would exceed STA profile IE section boundary");
  1211. return QDF_STATUS_E_PROTO;
  1212. }
  1213. if ((sta_prof_ie + TAG_LEN_POS) > (sta_prof_iesection +
  1214. sta_prof_iesection_len - 1)) {
  1215. mlo_err_rl("Position of length field of element with element ID %u in STA profile would exceed STA profile IE section boundary",
  1216. sta_prof_ie[ID_POS]);
  1217. return QDF_STATUS_E_PROTO;
  1218. }
  1219. if ((sta_prof_ie[ID_POS] == WLAN_ELEMID_EXTN_ELEM) &&
  1220. ((sta_prof_ie + IDEXT_POS) > (sta_prof_iesection +
  1221. sta_prof_iesection_len - 1))) {
  1222. mlo_err_rl("Position of element ID extension field of element would exceed STA profile IE section boundary");
  1223. return QDF_STATUS_E_PROTO;
  1224. }
  1225. sta_prof_ie_size = sta_prof_ie[TAG_LEN_POS] + MIN_IE_LEN;
  1226. if ((sta_prof_ie[ID_POS] == WLAN_ELEMID_EXTN_ELEM) &&
  1227. (sta_prof_ie_size < (IDEXT_POS + 1))) {
  1228. mlo_err_rl("Total length %zu of STA profile element is smaller than minimum required to access element ID extension %u",
  1229. sta_prof_ie_size, IDEXT_POS + 1);
  1230. return QDF_STATUS_E_PROTO;
  1231. }
  1232. if ((sta_prof_ie + sta_prof_ie_size) >
  1233. (sta_prof_iesection + sta_prof_iesection_len)) {
  1234. if (sta_prof_ie[ID_POS] == WLAN_ELEMID_EXTN_ELEM) {
  1235. mlo_err_rl("Total size %zu octets of element with element ID %u element ID extension %u in STA profile would exceed STA profile IE section boundary",
  1236. sta_prof_ie_size,
  1237. sta_prof_ie[ID_POS],
  1238. sta_prof_ie[IDEXT_POS]);
  1239. } else {
  1240. mlo_err_rl("Total size %zu octets of element with element ID %u in STA profile would exceed STA profile IE section boundary",
  1241. sta_prof_ie_size,
  1242. sta_prof_ie[ID_POS]);
  1243. }
  1244. return QDF_STATUS_E_PROTO;
  1245. }
  1246. return QDF_STATUS_SUCCESS;
  1247. }
  1248. #ifdef CONN_MGR_ADV_FEATURE
  1249. /**
  1250. * util_add_mlie_for_prb_rsp_gen - Add the basic variant Multi-Link element
  1251. * when generating link specific probe response.
  1252. * @reportingsta_ie: Pointer to the reportingsta ie
  1253. * @reportingsta_ie_len: Length for reporting sta ie
  1254. * @plink_frame_currpos: Pointer to Link frame current pos
  1255. * @plink_frame_currlen: Current length of link frame.
  1256. * @link_frame_maxsize: Maximum size of the frame to be generated
  1257. * @linkid: Link Id value
  1258. *
  1259. * Add the basic variant Multi-Link element when
  1260. * generating link specific probe response.
  1261. *
  1262. * Return: QDF_STATUS_SUCCESS in the case of success, QDF_STATUS value giving
  1263. * the reason for error in the case of failure
  1264. */
  1265. static QDF_STATUS
  1266. util_add_mlie_for_prb_rsp_gen(const uint8_t *reportingsta_ie,
  1267. qdf_size_t reportingsta_ie_len,
  1268. uint8_t **plink_frame_currpos,
  1269. qdf_size_t *plink_frame_currlen,
  1270. qdf_size_t link_frame_maxsize,
  1271. uint8_t linkid)
  1272. {
  1273. uint8_t mlie_len = 0;
  1274. uint8_t common_info_len = 0;
  1275. struct wlan_ie_multilink ml_ie_ff;
  1276. uint16_t mlcontrol;
  1277. uint16_t presencebm;
  1278. uint8_t *mlie_frame = NULL;
  1279. uint8_t link_id_offset = sizeof(struct wlan_ie_multilink) +
  1280. QDF_MAC_ADDR_SIZE +
  1281. WLAN_ML_BV_CINFO_LENGTH_SIZE;
  1282. uint8_t *link_frame_currpos = *plink_frame_currpos;
  1283. qdf_size_t link_frame_currlen = *plink_frame_currlen;
  1284. QDF_STATUS status = QDF_STATUS_SUCCESS;
  1285. status = util_get_mlie_common_info_len((uint8_t *)reportingsta_ie,
  1286. reportingsta_ie_len,
  1287. &common_info_len);
  1288. if (QDF_IS_STATUS_ERROR(status)) {
  1289. mlo_err("Failed while parsing the common info length");
  1290. return status;
  1291. }
  1292. /* common info len + bvmlie fixed fields */
  1293. mlie_len = common_info_len + sizeof(struct wlan_ie_multilink);
  1294. mlo_debug_rl("mlie_len %d, common_info_len %d, link_id_offset %d",
  1295. mlie_len,
  1296. common_info_len,
  1297. link_id_offset);
  1298. /*
  1299. * Validate the buffer available before copying ML IE.
  1300. * Incase if mlie_len is modified at later place, move this validation
  1301. * there to make sure no buffer overflow happens.
  1302. */
  1303. if ((link_frame_maxsize - link_frame_currlen) < mlie_len) {
  1304. mlo_err("Insufficient space in link specific frame for ML IE. Required: %u octets, available: %zu octets",
  1305. mlie_len, (link_frame_maxsize - link_frame_currlen));
  1306. return QDF_STATUS_E_NOMEM;
  1307. }
  1308. mlie_frame = qdf_mem_malloc(mlie_len);
  1309. if (!mlie_frame)
  1310. return QDF_STATUS_E_NOMEM;
  1311. /* Copy ml ie fixed fields */
  1312. qdf_mem_copy(&ml_ie_ff,
  1313. reportingsta_ie,
  1314. sizeof(struct wlan_ie_multilink));
  1315. ml_ie_ff.elem_len = mlie_len - sizeof(struct ie_header);
  1316. mlcontrol = qdf_le16_to_cpu(ml_ie_ff.mlcontrol);
  1317. presencebm = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_PBM_IDX,
  1318. WLAN_ML_CTRL_PBM_BITS);
  1319. qdf_set_bit(WLAN_ML_BV_CTRL_PBM_LINKIDINFO_P,
  1320. (unsigned long *)&presencebm);
  1321. QDF_SET_BITS(ml_ie_ff.mlcontrol,
  1322. WLAN_ML_CTRL_PBM_IDX,
  1323. WLAN_ML_CTRL_PBM_BITS,
  1324. presencebm);
  1325. qdf_mem_copy(mlie_frame,
  1326. &ml_ie_ff,
  1327. sizeof(struct wlan_ie_multilink));
  1328. qdf_mem_copy(mlie_frame + sizeof(struct wlan_ie_multilink),
  1329. reportingsta_ie + sizeof(struct wlan_ie_multilink),
  1330. mlie_len - sizeof(struct wlan_ie_multilink));
  1331. if (linkid == 0xFF) {
  1332. qdf_mem_free(mlie_frame);
  1333. mlo_err("Link id is invalid");
  1334. return QDF_STATUS_E_INVAL;
  1335. }
  1336. mlie_frame[link_id_offset] = (mlie_frame[link_id_offset] & ~0x0f) |
  1337. (linkid & 0x0f);
  1338. qdf_mem_copy(link_frame_currpos,
  1339. mlie_frame,
  1340. mlie_len);
  1341. mlo_debug("Add mlie for link id %d", linkid);
  1342. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_PE, QDF_TRACE_LEVEL_DEBUG,
  1343. mlie_frame, mlie_len);
  1344. link_frame_currpos += mlie_len;
  1345. link_frame_currlen += mlie_len;
  1346. *plink_frame_currpos = link_frame_currpos;
  1347. *plink_frame_currlen = link_frame_currlen;
  1348. qdf_mem_free(mlie_frame);
  1349. return QDF_STATUS_SUCCESS;
  1350. }
  1351. #else
  1352. static QDF_STATUS
  1353. util_add_mlie_for_prb_rsp_gen(const uint8_t *reportingsta_ie,
  1354. qdf_size_t reportingsta_ie_len,
  1355. uint8_t **plink_frame_currpos,
  1356. qdf_size_t *plink_frame_currlen,
  1357. qdf_size_t link_frame_maxsize,
  1358. uint8_t linkid)
  1359. {
  1360. return QDF_STATUS_SUCCESS;
  1361. }
  1362. #endif
  1363. /**
  1364. * util_find_bvmlie_persta_prof_for_linkid() - get per sta profile per link id
  1365. * @req_link_id: link id
  1366. * @linkinfo: the pointer of link info
  1367. * @linkinfo_len: the length of link info
  1368. * @persta_prof_frame: the pointer to store the address of sta profile
  1369. * @persta_prof_len: the sta profile length
  1370. *
  1371. * This helper function parses partner info from the per-STA profiles
  1372. * present (if any) in the Link Info field in the payload of a Multi
  1373. * Link element (after defragmentation if required). The caller should
  1374. * pass a copy of the payload so that inline defragmentation of
  1375. * subelements can be carried out if required. The subelement
  1376. * defragmentation (if applicable) in this Control Path helper is
  1377. * required for maintainability, accuracy and eliminating current and
  1378. * future per-field-access multi-level fragment boundary checks and
  1379. * adjustments, given the complex format of Multi Link elements. It is
  1380. * also most likely to be required mainly at the client side.
  1381. *
  1382. * Return: QDF_STATUS
  1383. */
  1384. static QDF_STATUS
  1385. util_find_bvmlie_persta_prof_for_linkid(uint8_t req_link_id,
  1386. uint8_t *linkinfo,
  1387. qdf_size_t linkinfo_len,
  1388. uint8_t **persta_prof_frame,
  1389. qdf_size_t *persta_prof_len)
  1390. {
  1391. uint8_t linkid;
  1392. struct qdf_mac_addr macaddr;
  1393. bool is_macaddr_valid;
  1394. uint8_t *linkinfo_currpos;
  1395. qdf_size_t linkinfo_remlen;
  1396. bool is_subelemfragseq;
  1397. uint8_t subelemid;
  1398. qdf_size_t subelemseqtotallen;
  1399. qdf_size_t subelemseqpayloadlen;
  1400. qdf_size_t defragpayload_len;
  1401. QDF_STATUS ret;
  1402. if (!linkinfo) {
  1403. mlo_err("linkinfo is NULL");
  1404. return QDF_STATUS_E_NULL_VALUE;
  1405. }
  1406. if (!linkinfo_len) {
  1407. mlo_err("linkinfo_len is zero");
  1408. return QDF_STATUS_E_NULL_VALUE;
  1409. }
  1410. if (!persta_prof_frame) {
  1411. mlo_err("Pointer to per-STA prof frame is NULL");
  1412. return QDF_STATUS_E_NULL_VALUE;
  1413. }
  1414. if (!persta_prof_len) {
  1415. mlo_err("Length to per-STA prof frame is 0");
  1416. return QDF_STATUS_E_NULL_VALUE;
  1417. }
  1418. linkinfo_currpos = linkinfo;
  1419. linkinfo_remlen = linkinfo_len;
  1420. while (linkinfo_remlen) {
  1421. if (linkinfo_remlen < sizeof(struct subelem_header)) {
  1422. mlo_err_rl("Remaining length in link info %zu octets is smaller than subelement header length %zu octets",
  1423. linkinfo_remlen,
  1424. sizeof(struct subelem_header));
  1425. return QDF_STATUS_E_PROTO;
  1426. }
  1427. subelemid = linkinfo_currpos[ID_POS];
  1428. is_subelemfragseq = false;
  1429. subelemseqtotallen = 0;
  1430. subelemseqpayloadlen = 0;
  1431. ret = wlan_get_subelem_fragseq_info(WLAN_ML_LINFO_SUBELEMID_FRAGMENT,
  1432. linkinfo_currpos,
  1433. linkinfo_remlen,
  1434. &is_subelemfragseq,
  1435. &subelemseqtotallen,
  1436. &subelemseqpayloadlen);
  1437. if (QDF_IS_STATUS_ERROR(ret))
  1438. return ret;
  1439. if (is_subelemfragseq) {
  1440. if (!subelemseqpayloadlen) {
  1441. mlo_err_rl("Subelement fragment sequence payload is reported as 0, investigate");
  1442. return QDF_STATUS_E_FAILURE;
  1443. }
  1444. mlo_debug("Subelement fragment sequence found with payload len %zu",
  1445. subelemseqpayloadlen);
  1446. ret = wlan_defrag_subelem_fragseq(true,
  1447. WLAN_ML_LINFO_SUBELEMID_FRAGMENT,
  1448. linkinfo_currpos,
  1449. linkinfo_remlen,
  1450. NULL,
  1451. 0,
  1452. &defragpayload_len);
  1453. if (QDF_IS_STATUS_ERROR(ret))
  1454. return ret;
  1455. if (defragpayload_len != subelemseqpayloadlen) {
  1456. mlo_err_rl("Length of defragmented payload %zu octets is not equal to length of subelement fragment sequence payload %zu octets",
  1457. defragpayload_len,
  1458. subelemseqpayloadlen);
  1459. return QDF_STATUS_E_FAILURE;
  1460. }
  1461. /* Adjust linkinfo_remlen to reflect removal of all
  1462. * subelement headers except the header of the lead
  1463. * subelement.
  1464. */
  1465. linkinfo_remlen -= (subelemseqtotallen -
  1466. subelemseqpayloadlen -
  1467. sizeof(struct subelem_header));
  1468. } else {
  1469. if (linkinfo_remlen <
  1470. (sizeof(struct subelem_header) +
  1471. linkinfo_currpos[TAG_LEN_POS])) {
  1472. mlo_err_rl("Remaining length in link info %zu octets is smaller than total size of current subelement %zu octets",
  1473. linkinfo_remlen,
  1474. sizeof(struct subelem_header) +
  1475. linkinfo_currpos[TAG_LEN_POS]);
  1476. return QDF_STATUS_E_PROTO;
  1477. }
  1478. subelemseqpayloadlen = linkinfo_currpos[TAG_LEN_POS];
  1479. }
  1480. if (subelemid == WLAN_ML_LINFO_SUBELEMID_PERSTAPROFILE) {
  1481. is_macaddr_valid = false;
  1482. ret = util_parse_bvmlie_perstaprofile_stactrl(linkinfo_currpos +
  1483. sizeof(struct subelem_header),
  1484. subelemseqpayloadlen,
  1485. &linkid,
  1486. NULL,
  1487. NULL,
  1488. NULL,
  1489. NULL,
  1490. NULL,
  1491. &is_macaddr_valid,
  1492. &macaddr,
  1493. false,
  1494. NULL,
  1495. NULL);
  1496. if (QDF_IS_STATUS_ERROR(ret))
  1497. return ret;
  1498. if (req_link_id == linkid) {
  1499. mlo_debug("Found requested per-STA prof for linkid %u, len %zu",
  1500. linkid, subelemseqpayloadlen);
  1501. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_MLO,
  1502. QDF_TRACE_LEVEL_DEBUG,
  1503. linkinfo_currpos,
  1504. subelemseqpayloadlen +
  1505. sizeof(struct subelem_header));
  1506. *persta_prof_frame = linkinfo_currpos;
  1507. *persta_prof_len = subelemseqpayloadlen;
  1508. return QDF_STATUS_SUCCESS;
  1509. }
  1510. }
  1511. linkinfo_remlen -= (sizeof(struct subelem_header) +
  1512. subelemseqpayloadlen);
  1513. linkinfo_currpos += (sizeof(struct subelem_header) +
  1514. subelemseqpayloadlen);
  1515. }
  1516. return QDF_STATUS_E_PROTO;
  1517. }
  1518. #define MLO_LINKSPECIFIC_ASSOC_REQ_FC0 0x00
  1519. #define MLO_LINKSPECIFIC_ASSOC_REQ_FC1 0x00
  1520. #define MLO_LINKSPECIFIC_ASSOC_RESP_FC0 0x10
  1521. #define MLO_LINKSPECIFIC_ASSOC_RESP_FC1 0x00
  1522. #define MLO_LINKSPECIFIC_PROBE_RESP_FC0 0x50
  1523. #define MLO_LINKSPECIFIC_PROBE_RESP_FC1 0x00
  1524. static
  1525. QDF_STATUS util_gen_link_reqrsp_cmn(uint8_t *frame, qdf_size_t frame_len,
  1526. uint8_t subtype,
  1527. uint8_t req_link_id,
  1528. struct qdf_mac_addr link_addr,
  1529. uint8_t *link_frame,
  1530. qdf_size_t link_frame_maxsize,
  1531. qdf_size_t *link_frame_len)
  1532. {
  1533. /* Please see documentation for util_gen_link_assoc_req() and
  1534. * util_gen_link_assoc_resp() for information on the inputs to and
  1535. * output from this helper, since those APIs are essentially wrappers
  1536. * over this helper.
  1537. */
  1538. /* Pointer to Multi-Link element/Multi-Link element fragment sequence */
  1539. uint8_t *mlieseq;
  1540. /* Total length of Multi-Link element sequence (including fragments if
  1541. * any)
  1542. */
  1543. qdf_size_t mlieseqlen;
  1544. /* Variant (i.e. type) of the Multi-Link element */
  1545. enum wlan_ml_variant variant;
  1546. /* Length of the payload of the Multi-Link element (inclusive of
  1547. * fragment payloads if any) without IE headers and element ID extension
  1548. */
  1549. qdf_size_t mlieseqpayloadlen;
  1550. /* Pointer to copy of the payload of the Multi-Link element (inclusive
  1551. * of fragment payloads if any) without IE headers and element ID
  1552. * extension
  1553. */
  1554. uint8_t *mlieseqpayload_copy;
  1555. /* Pointer to start of Link Info within the copy of the payload of the
  1556. * Multi-Link element
  1557. */
  1558. uint8_t *link_info;
  1559. /* Length of the Link Info */
  1560. qdf_size_t link_info_len;
  1561. /* Pointer to the IE section that occurs after the fixed fields in the
  1562. * original frame for the reporting STA.
  1563. */
  1564. uint8_t *frame_iesection;
  1565. /* Offset to the start of the IE section in the original frame for the
  1566. * reporting STA.
  1567. */
  1568. qdf_size_t frame_iesection_offset;
  1569. /* Total length of the IE section in the original frame for the
  1570. * reporting STA.
  1571. */
  1572. qdf_size_t frame_iesection_len;
  1573. /* Pointer to the IEEE802.11 frame header in the link specific frame
  1574. * being generated for the reported STA.
  1575. */
  1576. struct wlan_frame_hdr *link_frame_hdr;
  1577. /* Current position in the link specific frame being generated for the
  1578. * reported STA.
  1579. */
  1580. uint8_t *link_frame_currpos;
  1581. /* Current length of the link specific frame being generated for the
  1582. * reported STA.
  1583. */
  1584. qdf_size_t link_frame_currlen;
  1585. /* Pointer to IE for reporting STA */
  1586. const uint8_t *reportingsta_ie;
  1587. /* Total size of IE for reporting STA, inclusive of the element header
  1588. */
  1589. qdf_size_t reportingsta_ie_size;
  1590. /* Pointer to current position in STA profile */
  1591. uint8_t *sta_prof_currpos;
  1592. /* Remaining length of STA profile */
  1593. qdf_size_t sta_prof_remlen;
  1594. /* Pointer to start of IE section in STA profile that occurs after fixed
  1595. * fields.
  1596. */
  1597. uint8_t *sta_prof_iesection;
  1598. /* Total length of IE section in STA profile */
  1599. qdf_size_t sta_prof_iesection_len;
  1600. /* Pointer to current position being processed in IE section in STA
  1601. * profile.
  1602. */
  1603. uint8_t *sta_prof_iesection_currpos;
  1604. /* Remaining length of IE section in STA profile */
  1605. qdf_size_t sta_prof_iesection_remlen;
  1606. /* Pointer to IE in STA profile, that occurs within IE section */
  1607. uint8_t *sta_prof_ie;
  1608. /* Total size of IE in STA profile, inclusive of the element header */
  1609. qdf_size_t sta_prof_ie_size;
  1610. /* Pointer to element ID list in Non-Inheritance IE */
  1611. uint8_t *ninherit_elemlist;
  1612. /* Length of element ID list in Non-Inheritance IE */
  1613. qdf_size_t ninherit_elemlist_len;
  1614. /* Pointer to element ID extension list in Non-Inheritance IE */
  1615. uint8_t *ninherit_elemextlist;
  1616. /* Length of element ID extension list in Non-Inheritance IE */
  1617. qdf_size_t ninherit_elemextlist_len;
  1618. /* Whether a given IE is in a non-inheritance list */
  1619. bool is_in_noninheritlist;
  1620. /* Whether MAC address of reported STA is valid */
  1621. bool is_reportedmacaddr_valid;
  1622. /* MAC address of reported STA */
  1623. struct qdf_mac_addr reportedmacaddr;
  1624. /* Pointer to per-STA profile */
  1625. uint8_t *persta_prof;
  1626. /* Length of the containing buffer which starts with the per-STA profile
  1627. */
  1628. qdf_size_t persta_prof_bufflen;
  1629. /* Other variables for temporary purposes */
  1630. /* Variable into which API for determining fragment information will
  1631. * indicate whether the element is the start of a fragment sequence or
  1632. * not.
  1633. */
  1634. bool is_elemfragseq;
  1635. /* De-fragmented payload length returned by API for element
  1636. * defragmentation.
  1637. */
  1638. qdf_size_t defragpayload_len;
  1639. /* Pointer to Beacon interval in STA info field */
  1640. uint16_t beaconinterval;
  1641. /* Whether Beacon interval value valid */
  1642. bool is_beaconinterval_valid;
  1643. /* TSF timer of the reporting AP */
  1644. uint64_t tsf;
  1645. /* TSF offset of the reproted AP */
  1646. uint64_t tsfoffset;
  1647. /* TSF offset value valid */
  1648. bool is_tsfoffset_valid;
  1649. /* If Complete Profile or not*/
  1650. bool is_completeprofile;
  1651. qdf_size_t tmplen;
  1652. QDF_STATUS ret;
  1653. uint8_t linkid = 0xFF;
  1654. if (!frame) {
  1655. mlo_err("Pointer to original frame is NULL");
  1656. return QDF_STATUS_E_NULL_VALUE;
  1657. }
  1658. if (!frame_len) {
  1659. mlo_err("Length of original frame is zero");
  1660. return QDF_STATUS_E_INVAL;
  1661. }
  1662. if ((subtype != WLAN_FC0_STYPE_ASSOC_REQ) &&
  1663. (subtype != WLAN_FC0_STYPE_REASSOC_REQ) &&
  1664. (subtype != WLAN_FC0_STYPE_ASSOC_RESP) &&
  1665. (subtype != WLAN_FC0_STYPE_REASSOC_RESP) &&
  1666. (subtype != WLAN_FC0_STYPE_PROBE_RESP)) {
  1667. mlo_err("802.11 frame subtype %u is invalid", subtype);
  1668. return QDF_STATUS_E_INVAL;
  1669. }
  1670. if (!link_frame) {
  1671. mlo_err("Pointer to secondary link specific frame is NULL");
  1672. return QDF_STATUS_E_NULL_VALUE;
  1673. }
  1674. if (!link_frame_maxsize) {
  1675. mlo_err("Maximum size of secondary link specific frame is zero");
  1676. return QDF_STATUS_E_INVAL;
  1677. }
  1678. if (!link_frame_len) {
  1679. mlo_err("Pointer to populated length of secondary link specific frame is NULL");
  1680. return QDF_STATUS_E_NULL_VALUE;
  1681. }
  1682. frame_iesection_offset = 0;
  1683. if (subtype == WLAN_FC0_STYPE_ASSOC_REQ) {
  1684. frame_iesection_offset = WLAN_ASSOC_REQ_IES_OFFSET;
  1685. } else if (subtype == WLAN_FC0_STYPE_REASSOC_REQ) {
  1686. frame_iesection_offset = WLAN_REASSOC_REQ_IES_OFFSET;
  1687. } else if (subtype == WLAN_FC0_STYPE_PROBE_RESP) {
  1688. frame_iesection_offset = WLAN_PROBE_RESP_IES_OFFSET;
  1689. qdf_mem_copy(&tsf, frame, WLAN_TIMESTAMP_LEN);
  1690. tsf = qdf_le64_to_cpu(tsf);
  1691. } else {
  1692. /* This is a (re)association response */
  1693. frame_iesection_offset = WLAN_ASSOC_RSP_IES_OFFSET;
  1694. }
  1695. if (frame_len < frame_iesection_offset) {
  1696. /* The caller is supposed to have confirmed that this is a valid
  1697. * frame containing a Multi-Link element. Hence we treat this as
  1698. * a case of invalid argument being passed to us.
  1699. */
  1700. mlo_err("Frame length %zu is smaller than the IE section offset %zu for subtype %u",
  1701. frame_len, frame_iesection_offset, subtype);
  1702. return QDF_STATUS_E_INVAL;
  1703. }
  1704. frame_iesection_len = frame_len - frame_iesection_offset;
  1705. if (frame_iesection_len == 0) {
  1706. /* The caller is supposed to have confirmed that this is a valid
  1707. * frame containing a Multi-Link element. Hence we treat this as
  1708. * a case of invalid argument being passed to us.
  1709. */
  1710. mlo_err("No space left in frame for IE section");
  1711. return QDF_STATUS_E_INVAL;
  1712. }
  1713. frame_iesection = frame + frame_iesection_offset;
  1714. mlieseq = NULL;
  1715. mlieseqlen = 0;
  1716. ret = util_find_mlie(frame_iesection, frame_iesection_len, &mlieseq,
  1717. &mlieseqlen);
  1718. if (QDF_IS_STATUS_ERROR(ret))
  1719. return ret;
  1720. if (!mlieseq) {
  1721. /* The caller is supposed to have confirmed that a Multi-Link
  1722. * element is present in the frame. Hence we treat this as a
  1723. * case of invalid argument being passed to us.
  1724. */
  1725. mlo_err("Invalid original frame since no Multi-Link element found");
  1726. return QDF_STATUS_E_INVAL;
  1727. }
  1728. /* Sanity check the Multi-Link element sequence length */
  1729. if (!mlieseqlen) {
  1730. mlo_err("Length of Multi-Link element sequence is zero. Investigate.");
  1731. return QDF_STATUS_E_FAILURE;
  1732. }
  1733. if (mlieseqlen < sizeof(struct wlan_ie_multilink)) {
  1734. mlo_err_rl("Multi-Link element sequence length %zu octets is smaller than required for the fixed portion of Multi-Link element (%zu octets)",
  1735. mlieseqlen, sizeof(struct wlan_ie_multilink));
  1736. return QDF_STATUS_E_PROTO;
  1737. }
  1738. ret = util_get_mlie_variant(mlieseq, mlieseqlen, (int *)&variant);
  1739. if (QDF_IS_STATUS_ERROR(ret))
  1740. return ret;
  1741. if (variant != WLAN_ML_VARIANT_BASIC) {
  1742. mlo_err_rl("Unexpected variant %u of Multi-Link element.",
  1743. variant);
  1744. return QDF_STATUS_E_PROTO;
  1745. }
  1746. mlieseqpayloadlen = 0;
  1747. tmplen = 0;
  1748. is_elemfragseq = false;
  1749. ret = wlan_get_elem_fragseq_info(mlieseq,
  1750. mlieseqlen,
  1751. &is_elemfragseq,
  1752. &tmplen,
  1753. &mlieseqpayloadlen);
  1754. if (QDF_IS_STATUS_ERROR(ret))
  1755. return ret;
  1756. if (is_elemfragseq) {
  1757. if (tmplen != mlieseqlen) {
  1758. mlo_err_rl("Mismatch in values of element fragment sequence total length. Val per frag info determination: %zu octets, val per Multi-Link element search: %zu octets",
  1759. tmplen, mlieseqlen);
  1760. return QDF_STATUS_E_FAILURE;
  1761. }
  1762. if (!mlieseqpayloadlen) {
  1763. mlo_err_rl("Multi-Link element fragment sequence payload is reported as 0, investigate");
  1764. return QDF_STATUS_E_FAILURE;
  1765. }
  1766. mlo_debug("Multi-Link element fragment sequence found with payload len %zu",
  1767. mlieseqpayloadlen);
  1768. } else {
  1769. if (mlieseqlen > (sizeof(struct ie_header) + WLAN_MAX_IE_LEN)) {
  1770. mlo_err_rl("Expected presence of valid fragment sequence since Multi-Link element sequence length %zu octets is larger than frag threshold of %zu octets, however no valid fragment sequence found",
  1771. mlieseqlen,
  1772. sizeof(struct ie_header) + WLAN_MAX_IE_LEN);
  1773. return QDF_STATUS_E_FAILURE;
  1774. }
  1775. mlieseqpayloadlen = mlieseqlen - (sizeof(struct ie_header) + 1);
  1776. }
  1777. mlieseqpayload_copy = qdf_mem_malloc(mlieseqpayloadlen);
  1778. if (!mlieseqpayload_copy) {
  1779. mlo_err_rl("Could not allocate memory for Multi-Link element payload copy");
  1780. return QDF_STATUS_E_NOMEM;
  1781. }
  1782. if (is_elemfragseq) {
  1783. ret = wlan_defrag_elem_fragseq(false,
  1784. mlieseq,
  1785. mlieseqlen,
  1786. mlieseqpayload_copy,
  1787. mlieseqpayloadlen,
  1788. &defragpayload_len);
  1789. if (QDF_IS_STATUS_ERROR(ret)) {
  1790. qdf_mem_free(mlieseqpayload_copy);
  1791. return ret;
  1792. }
  1793. if (defragpayload_len != mlieseqpayloadlen) {
  1794. mlo_err_rl("Length of de-fragmented payload %zu octets is not equal to length of Multi-Link element fragment sequence payload %zu octets",
  1795. defragpayload_len, mlieseqpayloadlen);
  1796. qdf_mem_free(mlieseqpayload_copy);
  1797. return QDF_STATUS_E_FAILURE;
  1798. }
  1799. } else {
  1800. qdf_mem_copy(mlieseqpayload_copy,
  1801. mlieseq + sizeof(struct ie_header) + 1,
  1802. mlieseqpayloadlen);
  1803. }
  1804. link_info = NULL;
  1805. link_info_len = 0;
  1806. ret = util_parse_multi_link_ctrl(mlieseqpayload_copy,
  1807. mlieseqpayloadlen,
  1808. &link_info,
  1809. &link_info_len);
  1810. if (QDF_IS_STATUS_ERROR(ret)) {
  1811. qdf_mem_free(mlieseqpayload_copy);
  1812. return ret;
  1813. }
  1814. /* As per the standard, the sender must include Link Info for
  1815. * association request/response. Throw an error if we are unable to
  1816. * obtain this.
  1817. */
  1818. if (!link_info) {
  1819. mlo_err_rl("Unable to successfully obtain Link Info");
  1820. qdf_mem_free(mlieseqpayload_copy);
  1821. return QDF_STATUS_E_PROTO;
  1822. }
  1823. mlo_debug("Dumping hex of link info after parsing Multi-Link element control");
  1824. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_MLO, QDF_TRACE_LEVEL_DEBUG,
  1825. link_info, link_info_len);
  1826. /* Note: We may have a future change to skip subelements which are not
  1827. * Per-STA Profile, handle more than two links in MLO, handle cases
  1828. * where we unexpectedly find more Per-STA Profiles than expected, etc.
  1829. */
  1830. persta_prof = NULL;
  1831. persta_prof_bufflen = 0;
  1832. ret = util_find_bvmlie_persta_prof_for_linkid(req_link_id,
  1833. link_info,
  1834. link_info_len,
  1835. &persta_prof,
  1836. &persta_prof_bufflen);
  1837. if (QDF_IS_STATUS_ERROR(ret)) {
  1838. mlo_err_rl("Per STA profile not found for link id %d",
  1839. req_link_id);
  1840. qdf_mem_free(mlieseqpayload_copy);
  1841. return ret;
  1842. }
  1843. sta_prof_remlen = 0;
  1844. sta_prof_currpos = NULL;
  1845. is_reportedmacaddr_valid = false;
  1846. is_beaconinterval_valid = false;
  1847. is_completeprofile = false;
  1848. is_tsfoffset_valid = false;
  1849. /* Parse per-STA profile */
  1850. ret = util_parse_bvmlie_perstaprofile_stactrl(persta_prof +
  1851. sizeof(struct subelem_header),
  1852. persta_prof_bufflen,
  1853. &linkid,
  1854. &beaconinterval,
  1855. &is_beaconinterval_valid,
  1856. &tsfoffset,
  1857. &is_tsfoffset_valid,
  1858. &is_completeprofile,
  1859. &is_reportedmacaddr_valid,
  1860. &reportedmacaddr,
  1861. true,
  1862. &sta_prof_currpos,
  1863. &sta_prof_remlen);
  1864. if (QDF_IS_STATUS_ERROR(ret)) {
  1865. qdf_mem_free(mlieseqpayload_copy);
  1866. return ret;
  1867. }
  1868. if (subtype == WLAN_FC0_STYPE_PROBE_RESP && !is_completeprofile) {
  1869. mlo_err("Complete profile information is not present in per-STA profile of probe response frame");
  1870. return QDF_STATUS_E_NOSUPPORT;
  1871. }
  1872. /* We double check for a NULL STA Profile, though the helper function
  1873. * above would have taken care of this. We need to get a non-NULL STA
  1874. * profile, because we need to get at least the expected fixed fields,
  1875. * even if there is an (improbable) total inheritance.
  1876. */
  1877. if (!sta_prof_currpos) {
  1878. mlo_err_rl("STA profile is NULL");
  1879. qdf_mem_free(mlieseqpayload_copy);
  1880. return QDF_STATUS_E_PROTO;
  1881. }
  1882. /* As per the standard, the sender sets the MAC address in the per-STA
  1883. * profile in association request/response. Without this, we cannot
  1884. * generate the link specific frame.
  1885. */
  1886. if (!is_reportedmacaddr_valid) {
  1887. mlo_err_rl("Unable to get MAC address from per-STA profile");
  1888. qdf_mem_free(mlieseqpayload_copy);
  1889. return QDF_STATUS_E_PROTO;
  1890. }
  1891. link_frame_currpos = link_frame;
  1892. *link_frame_len = 0;
  1893. link_frame_currlen = 0;
  1894. if (link_frame_maxsize < WLAN_MAC_HDR_LEN_3A) {
  1895. mlo_err("Insufficient space in link specific frame for 802.11 header. Required: %u octets, available: %zu octets",
  1896. WLAN_MAC_HDR_LEN_3A, link_frame_maxsize);
  1897. qdf_mem_free(mlieseqpayload_copy);
  1898. return QDF_STATUS_E_NOMEM;
  1899. }
  1900. link_frame_currpos += WLAN_MAC_HDR_LEN_3A;
  1901. link_frame_currlen += WLAN_MAC_HDR_LEN_3A;
  1902. if ((subtype == WLAN_FC0_STYPE_ASSOC_REQ) ||
  1903. (subtype == WLAN_FC0_STYPE_REASSOC_REQ)) {
  1904. mlo_debug("Populating fixed fields for (re)assoc req in link specific frame");
  1905. if (sta_prof_remlen < WLAN_CAPABILITYINFO_LEN) {
  1906. mlo_err_rl("Remaining length of STA profile %zu octets is less than length of Capability Info %u",
  1907. sta_prof_remlen,
  1908. WLAN_CAPABILITYINFO_LEN);
  1909. qdf_mem_free(mlieseqpayload_copy);
  1910. return QDF_STATUS_E_PROTO;
  1911. }
  1912. /* Capability information is specific to the link. Copy this
  1913. * from the STA profile.
  1914. */
  1915. if ((link_frame_maxsize - link_frame_currlen) <
  1916. WLAN_CAPABILITYINFO_LEN) {
  1917. mlo_err("Insufficient space in link specific frame for Capability Info field. Required: %u octets, available: %zu octets",
  1918. WLAN_CAPABILITYINFO_LEN,
  1919. (link_frame_maxsize - link_frame_currlen));
  1920. qdf_mem_free(mlieseqpayload_copy);
  1921. return QDF_STATUS_E_NOMEM;
  1922. }
  1923. qdf_mem_copy(link_frame_currpos, sta_prof_currpos,
  1924. WLAN_CAPABILITYINFO_LEN);
  1925. link_frame_currpos += WLAN_CAPABILITYINFO_LEN;
  1926. link_frame_currlen += WLAN_CAPABILITYINFO_LEN;
  1927. mlo_debug("Added Capability Info field (%u octets) to link specific frame",
  1928. WLAN_CAPABILITYINFO_LEN);
  1929. sta_prof_currpos += WLAN_CAPABILITYINFO_LEN;
  1930. sta_prof_remlen -= WLAN_CAPABILITYINFO_LEN;
  1931. /* Listen Interval is common between all links. Copy this from
  1932. * the reporting section of the frame.
  1933. */
  1934. if ((link_frame_maxsize - link_frame_currlen) <
  1935. WLAN_LISTENINTERVAL_LEN) {
  1936. mlo_err("Insufficient space in link specific frame for Listen Interval field. Required: %u octets, available: %zu octets",
  1937. WLAN_LISTENINTERVAL_LEN,
  1938. (link_frame_maxsize - link_frame_currlen));
  1939. qdf_mem_free(mlieseqpayload_copy);
  1940. return QDF_STATUS_E_NOMEM;
  1941. }
  1942. qdf_mem_copy(link_frame_currpos,
  1943. frame + WLAN_CAPABILITYINFO_LEN,
  1944. WLAN_LISTENINTERVAL_LEN);
  1945. link_frame_currpos += WLAN_LISTENINTERVAL_LEN;
  1946. link_frame_currlen += WLAN_LISTENINTERVAL_LEN;
  1947. mlo_debug("Added Listen Interval field (%u octets) to link specific frame",
  1948. WLAN_LISTENINTERVAL_LEN);
  1949. if (subtype == WLAN_FC0_STYPE_REASSOC_REQ) {
  1950. /* Current AP address is common between all links. Copy
  1951. * this from the reporting section of the frame.
  1952. */
  1953. if ((link_frame_maxsize - link_frame_currlen) <
  1954. QDF_MAC_ADDR_SIZE) {
  1955. mlo_err("Insufficient space in link specific frame for current AP address. Required: %u octets, available: %zu octets",
  1956. QDF_MAC_ADDR_SIZE,
  1957. (link_frame_maxsize -
  1958. link_frame_currlen));
  1959. qdf_mem_free(mlieseqpayload_copy);
  1960. return QDF_STATUS_E_NOMEM;
  1961. }
  1962. qdf_mem_copy(link_frame_currpos,
  1963. frame + WLAN_CAPABILITYINFO_LEN +
  1964. WLAN_LISTENINTERVAL_LEN,
  1965. QDF_MAC_ADDR_SIZE);
  1966. link_frame_currpos += QDF_MAC_ADDR_SIZE;
  1967. link_frame_currlen += QDF_MAC_ADDR_SIZE;
  1968. mlo_debug("Reassoc req: Added Current AP address field (%u octets) to link specific frame",
  1969. QDF_MAC_ADDR_SIZE);
  1970. }
  1971. } else if (subtype == WLAN_FC0_STYPE_ASSOC_RESP ||
  1972. subtype == WLAN_FC0_STYPE_REASSOC_RESP) {
  1973. /* This is a (re)association response */
  1974. mlo_debug("Populating fixed fields for (re)assoc resp in link specific frame");
  1975. if (sta_prof_remlen <
  1976. (WLAN_CAPABILITYINFO_LEN + WLAN_STATUSCODE_LEN)) {
  1977. mlo_err_rl("Remaining length of STA profile %zu octets is less than length of Capability Info + length of Status Code %u",
  1978. sta_prof_remlen,
  1979. WLAN_CAPABILITYINFO_LEN +
  1980. WLAN_STATUSCODE_LEN);
  1981. qdf_mem_free(mlieseqpayload_copy);
  1982. return QDF_STATUS_E_PROTO;
  1983. }
  1984. /* Capability information and Status Code are specific to the
  1985. * link. Copy these from the STA profile.
  1986. */
  1987. if ((link_frame_maxsize - link_frame_currlen) <
  1988. (WLAN_CAPABILITYINFO_LEN + WLAN_STATUSCODE_LEN)) {
  1989. mlo_err("Insufficient space in link specific frame for Capability Info and Status Code fields. Required: %u octets, available: %zu octets",
  1990. WLAN_CAPABILITYINFO_LEN + WLAN_STATUSCODE_LEN,
  1991. (link_frame_maxsize - link_frame_currlen));
  1992. qdf_mem_free(mlieseqpayload_copy);
  1993. return QDF_STATUS_E_NOMEM;
  1994. }
  1995. qdf_mem_copy(link_frame_currpos, sta_prof_currpos,
  1996. (WLAN_CAPABILITYINFO_LEN + WLAN_STATUSCODE_LEN));
  1997. link_frame_currpos += (WLAN_CAPABILITYINFO_LEN +
  1998. WLAN_STATUSCODE_LEN);
  1999. link_frame_currlen += (WLAN_CAPABILITYINFO_LEN +
  2000. WLAN_STATUSCODE_LEN);
  2001. mlo_debug("Added Capability Info and Status Code fields (%u octets) to link specific frame",
  2002. WLAN_CAPABILITYINFO_LEN + WLAN_STATUSCODE_LEN);
  2003. sta_prof_currpos += (WLAN_CAPABILITYINFO_LEN +
  2004. WLAN_STATUSCODE_LEN);
  2005. sta_prof_remlen -= (WLAN_CAPABILITYINFO_LEN +
  2006. WLAN_STATUSCODE_LEN);
  2007. /* AID is common between all links. Copy this from the original
  2008. * frame.
  2009. */
  2010. if ((link_frame_maxsize - link_frame_currlen) < WLAN_AID_LEN) {
  2011. mlo_err("Insufficient space in link specific frame for AID field. Required: %u octets, available: %zu octets",
  2012. WLAN_AID_LEN,
  2013. (link_frame_maxsize - link_frame_currlen));
  2014. qdf_mem_free(mlieseqpayload_copy);
  2015. return QDF_STATUS_E_NOMEM;
  2016. }
  2017. qdf_mem_copy(link_frame_currpos,
  2018. frame + WLAN_CAPABILITYINFO_LEN +
  2019. WLAN_STATUSCODE_LEN,
  2020. WLAN_AID_LEN);
  2021. link_frame_currpos += WLAN_AID_LEN;
  2022. link_frame_currlen += WLAN_AID_LEN;
  2023. mlo_debug("Added AID field (%u octets) to link specific frame",
  2024. WLAN_AID_LEN);
  2025. } else if (subtype == WLAN_FC0_STYPE_PROBE_RESP) {
  2026. /* This is a probe response */
  2027. mlo_debug("Populating fixed fields for probe response in link specific frame");
  2028. if ((link_frame_maxsize - link_frame_currlen) <
  2029. WLAN_TIMESTAMP_LEN) {
  2030. mlo_err("Insufficient space in link specific frame for Timestamp Info field. Required: %u octets, available: %zu octets",
  2031. WLAN_TIMESTAMP_LEN,
  2032. (link_frame_maxsize - link_frame_currlen));
  2033. qdf_mem_free(mlieseqpayload_copy);
  2034. return QDF_STATUS_E_NOMEM;
  2035. }
  2036. /* Per spec 11be_D2.1.1, the TSF Offset subfield of the STA Info
  2037. * field indicates the offset (Toffset)between the TSF timer of
  2038. * the reported AP (TA) and the TSF timer of the reporting
  2039. * AP (TB) and is encoded as a 2s complement signed integer
  2040. * with units of 2 µs. Toffset is calculated as
  2041. * Toffset= Floor((TA – TB)/2).
  2042. */
  2043. if (is_tsfoffset_valid)
  2044. tsf += tsfoffset * 2;
  2045. qdf_mem_copy(link_frame_currpos, &tsf, WLAN_TIMESTAMP_LEN);
  2046. link_frame_currpos += WLAN_TIMESTAMP_LEN;
  2047. link_frame_currlen += WLAN_TIMESTAMP_LEN;
  2048. mlo_debug("Added Timestamp Info field (%u octets) to link specific frame",
  2049. WLAN_TIMESTAMP_LEN);
  2050. if (!is_beaconinterval_valid) {
  2051. mlo_err_rl("Beacon interval information not present in STA info field of per-STA profile");
  2052. qdf_mem_free(mlieseqpayload_copy);
  2053. return QDF_STATUS_E_PROTO;
  2054. }
  2055. /* Beacon Interval information copy this from
  2056. * the STA info field.
  2057. */
  2058. if ((link_frame_maxsize - link_frame_currlen) <
  2059. WLAN_BEACONINTERVAL_LEN) {
  2060. mlo_err("Insufficient space in link specific frame for Beacon Interval Info field. Required: %u octets, available: %zu octets",
  2061. WLAN_BEACONINTERVAL_LEN,
  2062. (link_frame_maxsize - link_frame_currlen));
  2063. qdf_mem_free(mlieseqpayload_copy);
  2064. return QDF_STATUS_E_NOMEM;
  2065. }
  2066. qdf_mem_copy(link_frame_currpos, &beaconinterval,
  2067. WLAN_BEACONINTERVAL_LEN);
  2068. link_frame_currpos += WLAN_BEACONINTERVAL_LEN;
  2069. link_frame_currlen += WLAN_BEACONINTERVAL_LEN;
  2070. mlo_debug("Added Beacon Interval Info field (%u octets) to link specific frame",
  2071. WLAN_BEACONINTERVAL_LEN);
  2072. if (sta_prof_remlen < WLAN_CAPABILITYINFO_LEN) {
  2073. mlo_err_rl("Remaining length of STA profile %zu octets is less than length of Capability Info %u",
  2074. sta_prof_remlen,
  2075. WLAN_CAPABILITYINFO_LEN);
  2076. qdf_mem_free(mlieseqpayload_copy);
  2077. return QDF_STATUS_E_PROTO;
  2078. }
  2079. /* Capability information is specific to the link. Copy this
  2080. * from the STA profile.
  2081. */
  2082. if ((link_frame_maxsize - link_frame_currlen) <
  2083. WLAN_CAPABILITYINFO_LEN) {
  2084. mlo_err("Insufficient space in link specific frame for Capability Info field. Required: %u octets, available: %zu octets",
  2085. WLAN_CAPABILITYINFO_LEN,
  2086. (link_frame_maxsize - link_frame_currlen));
  2087. qdf_mem_free(mlieseqpayload_copy);
  2088. return QDF_STATUS_E_NOMEM;
  2089. }
  2090. qdf_mem_copy(link_frame_currpos, sta_prof_currpos,
  2091. WLAN_CAPABILITYINFO_LEN);
  2092. link_frame_currpos += WLAN_CAPABILITYINFO_LEN;
  2093. link_frame_currlen += WLAN_CAPABILITYINFO_LEN;
  2094. mlo_debug("Added Capability Info field (%u octets) to link specific frame",
  2095. WLAN_CAPABILITYINFO_LEN);
  2096. sta_prof_currpos += WLAN_CAPABILITYINFO_LEN;
  2097. sta_prof_remlen -= WLAN_CAPABILITYINFO_LEN;
  2098. }
  2099. sta_prof_iesection = sta_prof_currpos;
  2100. sta_prof_iesection_len = sta_prof_remlen;
  2101. /* Populate non-inheritance lists if applicable */
  2102. ninherit_elemlist_len = 0;
  2103. ninherit_elemlist = NULL;
  2104. ninherit_elemextlist_len = 0;
  2105. ninherit_elemextlist = NULL;
  2106. ret = util_get_noninheritlists(sta_prof_iesection,
  2107. sta_prof_iesection_len,
  2108. &ninherit_elemlist,
  2109. &ninherit_elemlist_len,
  2110. &ninherit_elemextlist,
  2111. &ninherit_elemextlist_len);
  2112. if (QDF_IS_STATUS_ERROR(ret)) {
  2113. qdf_mem_free(mlieseqpayload_copy);
  2114. return ret;
  2115. }
  2116. /* Go through IEs of the reporting STA, and those in STA profile, merge
  2117. * them into link_frame (except for elements in the Non-Inheritance
  2118. * list).
  2119. *
  2120. * Note: Currently, only 2-link MLO is supported here. We may have a
  2121. * future change to expand to more links.
  2122. */
  2123. reportingsta_ie = util_find_eid(WLAN_ELEMID_SSID, frame_iesection,
  2124. frame_iesection_len);
  2125. if ((subtype == WLAN_FC0_STYPE_ASSOC_REQ) ||
  2126. (subtype == WLAN_FC0_STYPE_REASSOC_REQ) ||
  2127. (subtype == WLAN_FC0_STYPE_PROBE_RESP)) {
  2128. /* Sanity check that the SSID element is present for the
  2129. * reporting STA. There is no stipulation in the standard for
  2130. * the STA profile in this regard, so we do not check the STA
  2131. * profile for the SSID element.
  2132. */
  2133. if (!reportingsta_ie) {
  2134. mlo_err_rl("SSID element not found in reporting STA of the frame.");
  2135. qdf_mem_free(mlieseqpayload_copy);
  2136. return QDF_STATUS_E_PROTO;
  2137. }
  2138. } else {
  2139. /* This is a (re)association response. Sanity check that the
  2140. * SSID element is present neither for the reporting STA nor in
  2141. * the STA profile.
  2142. */
  2143. if (reportingsta_ie) {
  2144. mlo_err_rl("SSID element found for reporting STA for (re)association response. It should not be present.");
  2145. qdf_mem_free(mlieseqpayload_copy);
  2146. return QDF_STATUS_E_PROTO;
  2147. }
  2148. sta_prof_ie = util_find_eid(WLAN_ELEMID_SSID,
  2149. sta_prof_iesection,
  2150. sta_prof_iesection_len);
  2151. if (sta_prof_ie) {
  2152. mlo_err_rl("SSID element found in STA profile for (re)association response. It should not be present.");
  2153. qdf_mem_free(mlieseqpayload_copy);
  2154. return QDF_STATUS_E_PROTO;
  2155. }
  2156. }
  2157. reportingsta_ie = reportingsta_ie ? reportingsta_ie : frame_iesection;
  2158. ret = util_validate_reportingsta_ie(reportingsta_ie, frame_iesection,
  2159. frame_iesection_len);
  2160. if (QDF_IS_STATUS_ERROR(ret)) {
  2161. qdf_mem_free(mlieseqpayload_copy);
  2162. return ret;
  2163. }
  2164. reportingsta_ie_size = reportingsta_ie[TAG_LEN_POS] + MIN_IE_LEN;
  2165. while (((reportingsta_ie + reportingsta_ie_size) - frame_iesection)
  2166. <= frame_iesection_len) {
  2167. /* Skip Multi-Link element */
  2168. if ((reportingsta_ie[ID_POS] == WLAN_ELEMID_EXTN_ELEM) &&
  2169. (reportingsta_ie[IDEXT_POS] ==
  2170. WLAN_EXTN_ELEMID_MULTI_LINK)) {
  2171. if (((reportingsta_ie + reportingsta_ie_size) -
  2172. frame_iesection) == frame_iesection_len)
  2173. break;
  2174. /* Add BV ML IE for link specific probe response */
  2175. if (subtype == WLAN_FC0_STYPE_PROBE_RESP) {
  2176. ret = util_add_mlie_for_prb_rsp_gen(
  2177. reportingsta_ie,
  2178. reportingsta_ie[TAG_LEN_POS],
  2179. &link_frame_currpos,
  2180. &link_frame_currlen,
  2181. link_frame_maxsize,
  2182. linkid);
  2183. if (QDF_IS_STATUS_ERROR(ret)) {
  2184. qdf_mem_free(mlieseqpayload_copy);
  2185. return ret;
  2186. }
  2187. }
  2188. reportingsta_ie += reportingsta_ie_size;
  2189. ret = util_validate_reportingsta_ie(reportingsta_ie,
  2190. frame_iesection,
  2191. frame_iesection_len);
  2192. if (QDF_IS_STATUS_ERROR(ret)) {
  2193. qdf_mem_free(mlieseqpayload_copy);
  2194. return ret;
  2195. }
  2196. reportingsta_ie_size = reportingsta_ie[TAG_LEN_POS] +
  2197. MIN_IE_LEN;
  2198. continue;
  2199. }
  2200. sta_prof_ie = NULL;
  2201. sta_prof_ie_size = 0;
  2202. if (sta_prof_iesection_len) {
  2203. if (reportingsta_ie[ID_POS] == WLAN_ELEMID_EXTN_ELEM) {
  2204. sta_prof_ie = (uint8_t *)util_find_extn_eid(reportingsta_ie[ID_POS],
  2205. reportingsta_ie[IDEXT_POS],
  2206. sta_prof_iesection,
  2207. sta_prof_iesection_len);
  2208. } else {
  2209. sta_prof_ie = (uint8_t *)util_find_eid(reportingsta_ie[ID_POS],
  2210. sta_prof_iesection,
  2211. sta_prof_iesection_len);
  2212. }
  2213. }
  2214. if (!sta_prof_ie) {
  2215. /* IE is present for reporting STA, but not in STA
  2216. * profile.
  2217. */
  2218. is_in_noninheritlist = false;
  2219. ret = util_eval_ie_in_noninheritlist((uint8_t *)reportingsta_ie,
  2220. reportingsta_ie_size,
  2221. ninherit_elemlist,
  2222. ninherit_elemlist_len,
  2223. ninherit_elemextlist,
  2224. ninherit_elemextlist_len,
  2225. &is_in_noninheritlist);
  2226. if (QDF_IS_STATUS_ERROR(ret)) {
  2227. qdf_mem_free(mlieseqpayload_copy);
  2228. return ret;
  2229. }
  2230. if (!is_in_noninheritlist) {
  2231. if ((link_frame_currpos +
  2232. reportingsta_ie_size) <=
  2233. (link_frame + link_frame_maxsize)) {
  2234. qdf_mem_copy(link_frame_currpos,
  2235. reportingsta_ie,
  2236. reportingsta_ie_size);
  2237. link_frame_currpos +=
  2238. reportingsta_ie_size;
  2239. link_frame_currlen +=
  2240. reportingsta_ie_size;
  2241. if (reportingsta_ie[ID_POS] == WLAN_ELEMID_EXTN_ELEM) {
  2242. mlo_debug("IE with element ID : %u extension element ID : %u (%zu octets) present for reporting STA but not in STA profile. Copied IE from reporting frame to link specific frame",
  2243. reportingsta_ie[ID_POS],
  2244. reportingsta_ie[IDEXT_POS],
  2245. reportingsta_ie_size);
  2246. } else {
  2247. mlo_debug("IE with element ID : %u (%zu octets) present for reporting STA but not in STA profile. Copied IE from reporting frame to link specific frame",
  2248. reportingsta_ie[ID_POS],
  2249. reportingsta_ie_size);
  2250. }
  2251. } else {
  2252. if (reportingsta_ie[ID_POS] == WLAN_ELEMID_EXTN_ELEM) {
  2253. mlo_err_rl("Insufficient space in link specific frame for IE with element ID : %u extension element ID : %u. Required: %zu octets, available: %zu octets",
  2254. reportingsta_ie[ID_POS],
  2255. reportingsta_ie[IDEXT_POS],
  2256. reportingsta_ie_size,
  2257. link_frame_maxsize -
  2258. link_frame_currlen);
  2259. } else {
  2260. mlo_err_rl("Insufficient space in link specific frame for IE with element ID : %u. Required: %zu octets, available: %zu octets",
  2261. reportingsta_ie[ID_POS],
  2262. reportingsta_ie_size,
  2263. link_frame_maxsize -
  2264. link_frame_currlen);
  2265. }
  2266. qdf_mem_free(mlieseqpayload_copy);
  2267. return QDF_STATUS_E_NOMEM;
  2268. }
  2269. } else {
  2270. if (reportingsta_ie[ID_POS] == WLAN_ELEMID_EXTN_ELEM) {
  2271. mlo_debug("IE with element ID : %u extension element ID : %u (%zu octets) present for reporting STA but not in STA profile. However it is in Non-Inheritance list, hence ignoring.",
  2272. reportingsta_ie[ID_POS],
  2273. reportingsta_ie[IDEXT_POS],
  2274. reportingsta_ie_size);
  2275. } else {
  2276. mlo_debug("IE with element ID : %u (%zu octets) present for reporting STA but not in STA profile. However it is in Non-Inheritance list, hence ignoring.",
  2277. reportingsta_ie[ID_POS],
  2278. reportingsta_ie_size);
  2279. }
  2280. }
  2281. } else {
  2282. /* IE is present for reporting STA and also in STA
  2283. * profile, copy from STA profile and flag the IE in STA
  2284. * profile as copied (by setting EID field to 0). The
  2285. * SSID element (with EID 0) is processed first to
  2286. * enable this. For vendor IE, compare OUI + type +
  2287. * subType to determine if they are the same IE.
  2288. */
  2289. /* Note: This may be revisited in a future change, to
  2290. * adhere to provisions in the standard for multiple
  2291. * occurrences of a given element ID/extension element
  2292. * ID.
  2293. */
  2294. ret = util_validate_sta_prof_ie(sta_prof_ie,
  2295. sta_prof_iesection,
  2296. sta_prof_iesection_len);
  2297. if (QDF_IS_STATUS_ERROR(ret)) {
  2298. qdf_mem_free(mlieseqpayload_copy);
  2299. return ret;
  2300. }
  2301. sta_prof_ie_size = sta_prof_ie[TAG_LEN_POS] +
  2302. MIN_IE_LEN;
  2303. sta_prof_iesection_remlen =
  2304. sta_prof_iesection_len -
  2305. (sta_prof_ie - sta_prof_iesection);
  2306. if ((reportingsta_ie[ID_POS] == WLAN_ELEMID_VENDOR) &&
  2307. (sta_prof_iesection_remlen >= MIN_VENDOR_TAG_LEN)) {
  2308. /* If Vendor IE also presents in STA profile,
  2309. * then ignore the Vendor IE which is for
  2310. * reporting STA. It only needs to copy Vendor
  2311. * IE from STA profile to link specific frame.
  2312. * The copy happens when going through the
  2313. * remaining IEs.
  2314. */
  2315. ;
  2316. } else {
  2317. /* Copy IE from STA profile into link specific
  2318. * frame.
  2319. */
  2320. if ((link_frame_currpos + sta_prof_ie_size) <=
  2321. (link_frame + link_frame_maxsize)) {
  2322. qdf_mem_copy(link_frame_currpos,
  2323. sta_prof_ie,
  2324. sta_prof_ie_size);
  2325. link_frame_currpos += sta_prof_ie_size;
  2326. link_frame_currlen +=
  2327. sta_prof_ie_size;
  2328. if (reportingsta_ie[ID_POS] ==
  2329. WLAN_ELEMID_EXTN_ELEM) {
  2330. mlo_debug("IE with element ID : %u extension element ID : %u (%zu octets) for reporting STA also present in STA profile. Copied IE from STA profile to link specific frame",
  2331. sta_prof_ie[ID_POS],
  2332. sta_prof_ie[IDEXT_POS],
  2333. sta_prof_ie_size);
  2334. } else {
  2335. mlo_debug("IE with element ID : %u (%zu octets) for reporting STA also present in STA profile. Copied IE from STA profile to link specific frame",
  2336. sta_prof_ie[ID_POS],
  2337. sta_prof_ie_size);
  2338. }
  2339. sta_prof_ie[0] = 0;
  2340. } else {
  2341. if (sta_prof_ie[ID_POS] ==
  2342. WLAN_ELEMID_EXTN_ELEM) {
  2343. mlo_err_rl("Insufficient space in link specific frame for IE with element ID : %u extension element ID : %u. Required: %zu octets, available: %zu octets",
  2344. sta_prof_ie[ID_POS],
  2345. sta_prof_ie[IDEXT_POS],
  2346. sta_prof_ie_size,
  2347. link_frame_maxsize -
  2348. link_frame_currlen);
  2349. } else {
  2350. mlo_err_rl("Insufficient space in link specific frame for IE with element ID : %u. Required: %zu octets, available: %zu octets",
  2351. sta_prof_ie[ID_POS],
  2352. sta_prof_ie_size,
  2353. link_frame_maxsize -
  2354. link_frame_currlen);
  2355. }
  2356. qdf_mem_free(mlieseqpayload_copy);
  2357. return QDF_STATUS_E_NOMEM;
  2358. }
  2359. }
  2360. }
  2361. if (((reportingsta_ie + reportingsta_ie_size) -
  2362. frame_iesection) == frame_iesection_len)
  2363. break;
  2364. reportingsta_ie += reportingsta_ie_size;
  2365. ret = util_validate_reportingsta_ie(reportingsta_ie,
  2366. frame_iesection,
  2367. frame_iesection_len);
  2368. if (QDF_IS_STATUS_ERROR(ret)) {
  2369. qdf_mem_free(mlieseqpayload_copy);
  2370. return ret;
  2371. }
  2372. reportingsta_ie_size = reportingsta_ie[TAG_LEN_POS] +
  2373. MIN_IE_LEN;
  2374. }
  2375. /* Go through the remaining unprocessed IEs in STA profile and copy them
  2376. * to the link specific frame. The processed ones are marked with 0 in
  2377. * the first octet. The first octet corresponds to the element ID. In
  2378. * the case of (re)association request, the element with actual ID
  2379. * WLAN_ELEMID_SSID(0) has already been copied to the link specific
  2380. * frame. In the case of (re)association response, it has been verified
  2381. * that the element with actual ID WLAN_ELEMID_SSID(0) is present
  2382. * neither for the reporting STA nor in the STA profile.
  2383. */
  2384. sta_prof_iesection_currpos = sta_prof_iesection;
  2385. sta_prof_iesection_remlen = sta_prof_iesection_len;
  2386. while (sta_prof_iesection_remlen > 0) {
  2387. sta_prof_ie = sta_prof_iesection_currpos;
  2388. ret = util_validate_sta_prof_ie(sta_prof_ie,
  2389. sta_prof_iesection_currpos,
  2390. sta_prof_iesection_remlen);
  2391. if (QDF_IS_STATUS_ERROR(ret)) {
  2392. qdf_mem_free(mlieseqpayload_copy);
  2393. return ret;
  2394. }
  2395. sta_prof_ie_size = sta_prof_ie[TAG_LEN_POS] + MIN_IE_LEN;
  2396. if (!sta_prof_ie[0]) {
  2397. /* Skip this, since it has already been processed */
  2398. sta_prof_iesection_currpos += sta_prof_ie_size;
  2399. sta_prof_iesection_remlen -= sta_prof_ie_size;
  2400. continue;
  2401. }
  2402. /* Copy IE from STA profile into link specific frame. */
  2403. if ((link_frame_currpos + sta_prof_ie_size) <=
  2404. (link_frame + link_frame_maxsize)) {
  2405. qdf_mem_copy(link_frame_currpos,
  2406. sta_prof_ie,
  2407. sta_prof_ie_size);
  2408. link_frame_currpos += sta_prof_ie_size;
  2409. link_frame_currlen +=
  2410. sta_prof_ie_size;
  2411. if (reportingsta_ie[ID_POS] ==
  2412. WLAN_ELEMID_EXTN_ELEM) {
  2413. mlo_debug("IE with element ID : %u extension element ID : %u (%zu octets) is present only in STA profile. Copied IE from STA profile to link specific frame",
  2414. sta_prof_ie[ID_POS],
  2415. sta_prof_ie[IDEXT_POS],
  2416. sta_prof_ie_size);
  2417. } else {
  2418. mlo_debug("IE with element ID : %u (%zu octets) is present only in STA profile. Copied IE from STA profile to link specific frame",
  2419. sta_prof_ie[ID_POS],
  2420. sta_prof_ie_size);
  2421. }
  2422. sta_prof_ie[0] = 0;
  2423. } else {
  2424. if (sta_prof_ie[ID_POS] == WLAN_ELEMID_EXTN_ELEM) {
  2425. mlo_err_rl("Insufficient space in link specific frame for IE with element ID : %u extension element ID : %u. Required: %zu octets, available: %zu octets",
  2426. sta_prof_ie[ID_POS],
  2427. sta_prof_ie[IDEXT_POS],
  2428. sta_prof_ie_size,
  2429. link_frame_maxsize -
  2430. link_frame_currlen);
  2431. } else {
  2432. mlo_err_rl("Insufficient space in link specific frame for IE with element ID : %u. Required: %zu octets, available: %zu octets",
  2433. sta_prof_ie[ID_POS],
  2434. sta_prof_ie_size,
  2435. link_frame_maxsize -
  2436. link_frame_currlen);
  2437. }
  2438. qdf_mem_free(mlieseqpayload_copy);
  2439. return QDF_STATUS_E_NOMEM;
  2440. }
  2441. sta_prof_iesection_currpos += sta_prof_ie_size;
  2442. sta_prof_iesection_remlen -= sta_prof_ie_size;
  2443. }
  2444. /* Copy the link MAC addr */
  2445. link_frame_hdr = (struct wlan_frame_hdr *)link_frame;
  2446. if ((subtype == WLAN_FC0_STYPE_ASSOC_REQ) ||
  2447. (subtype == WLAN_FC0_STYPE_REASSOC_REQ)) {
  2448. qdf_mem_copy(link_frame_hdr->i_addr3, &link_addr,
  2449. QDF_MAC_ADDR_SIZE);
  2450. qdf_mem_copy(link_frame_hdr->i_addr2, reportedmacaddr.bytes,
  2451. QDF_MAC_ADDR_SIZE);
  2452. qdf_mem_copy(link_frame_hdr->i_addr1, &link_addr,
  2453. QDF_MAC_ADDR_SIZE);
  2454. link_frame_hdr->i_fc[0] = MLO_LINKSPECIFIC_ASSOC_REQ_FC0;
  2455. link_frame_hdr->i_fc[1] = MLO_LINKSPECIFIC_ASSOC_REQ_FC1;
  2456. } else if (subtype == WLAN_FC0_STYPE_PROBE_RESP) {
  2457. qdf_mem_copy(link_frame_hdr->i_addr3, reportedmacaddr.bytes,
  2458. QDF_MAC_ADDR_SIZE);
  2459. qdf_mem_copy(link_frame_hdr->i_addr2, reportedmacaddr.bytes,
  2460. QDF_MAC_ADDR_SIZE);
  2461. qdf_mem_copy(link_frame_hdr->i_addr1, &link_addr,
  2462. QDF_MAC_ADDR_SIZE);
  2463. link_frame_hdr->i_fc[0] = MLO_LINKSPECIFIC_PROBE_RESP_FC0;
  2464. link_frame_hdr->i_fc[1] = MLO_LINKSPECIFIC_PROBE_RESP_FC1;
  2465. } else {
  2466. /* This is a (re)association response */
  2467. qdf_mem_copy(link_frame_hdr->i_addr3, reportedmacaddr.bytes,
  2468. QDF_MAC_ADDR_SIZE);
  2469. qdf_mem_copy(link_frame_hdr->i_addr2, reportedmacaddr.bytes,
  2470. QDF_MAC_ADDR_SIZE);
  2471. qdf_mem_copy(link_frame_hdr->i_addr1, &link_addr,
  2472. QDF_MAC_ADDR_SIZE);
  2473. link_frame_hdr->i_fc[0] = MLO_LINKSPECIFIC_ASSOC_RESP_FC0;
  2474. link_frame_hdr->i_fc[1] = MLO_LINKSPECIFIC_ASSOC_RESP_FC1;
  2475. }
  2476. mlo_debug("subtype:%u addr3:" QDF_MAC_ADDR_FMT " addr2:"
  2477. QDF_MAC_ADDR_FMT " addr1:" QDF_MAC_ADDR_FMT,
  2478. subtype,
  2479. QDF_MAC_ADDR_REF(link_frame_hdr->i_addr3),
  2480. QDF_MAC_ADDR_REF(link_frame_hdr->i_addr2),
  2481. QDF_MAC_ADDR_REF(link_frame_hdr->i_addr1));
  2482. /* Seq num not used so not populated */
  2483. qdf_mem_free(mlieseqpayload_copy);
  2484. *link_frame_len = link_frame_currlen;
  2485. return QDF_STATUS_SUCCESS;
  2486. }
  2487. QDF_STATUS
  2488. util_gen_link_assoc_req(uint8_t *frame, qdf_size_t frame_len, bool isreassoc,
  2489. uint8_t link_id,
  2490. struct qdf_mac_addr link_addr,
  2491. uint8_t *link_frame,
  2492. qdf_size_t link_frame_maxsize,
  2493. qdf_size_t *link_frame_len)
  2494. {
  2495. return util_gen_link_reqrsp_cmn(frame, frame_len,
  2496. (isreassoc ? WLAN_FC0_STYPE_REASSOC_REQ :
  2497. WLAN_FC0_STYPE_ASSOC_REQ),
  2498. link_id, link_addr, link_frame,
  2499. link_frame_maxsize, link_frame_len);
  2500. }
  2501. QDF_STATUS
  2502. util_gen_link_assoc_rsp(uint8_t *frame, qdf_size_t frame_len, bool isreassoc,
  2503. uint8_t link_id,
  2504. struct qdf_mac_addr link_addr,
  2505. uint8_t *link_frame,
  2506. qdf_size_t link_frame_maxsize,
  2507. qdf_size_t *link_frame_len)
  2508. {
  2509. return util_gen_link_reqrsp_cmn(frame, frame_len,
  2510. (isreassoc ? WLAN_FC0_STYPE_REASSOC_RESP :
  2511. WLAN_FC0_STYPE_ASSOC_RESP),
  2512. link_id, link_addr, link_frame,
  2513. link_frame_maxsize, link_frame_len);
  2514. }
  2515. QDF_STATUS
  2516. util_gen_link_probe_rsp(uint8_t *frame, qdf_size_t frame_len,
  2517. uint8_t link_id,
  2518. struct qdf_mac_addr link_addr,
  2519. uint8_t *link_frame,
  2520. qdf_size_t link_frame_maxsize,
  2521. qdf_size_t *link_frame_len)
  2522. {
  2523. return util_gen_link_reqrsp_cmn(frame, frame_len,
  2524. WLAN_FC0_STYPE_PROBE_RESP, link_id,
  2525. link_addr, link_frame, link_frame_maxsize,
  2526. link_frame_len);
  2527. }
  2528. QDF_STATUS
  2529. util_find_mlie(uint8_t *buf, qdf_size_t buflen, uint8_t **mlieseq,
  2530. qdf_size_t *mlieseqlen)
  2531. {
  2532. uint8_t *bufboundary;
  2533. uint8_t *ieseq;
  2534. qdf_size_t ieseqlen;
  2535. uint8_t *currie;
  2536. uint8_t *successorfrag;
  2537. if (!buf || !buflen || !mlieseq || !mlieseqlen)
  2538. return QDF_STATUS_E_NULL_VALUE;
  2539. *mlieseq = NULL;
  2540. *mlieseqlen = 0;
  2541. /* Find Multi-Link element. In case a fragment sequence is present,
  2542. * this element will be the leading fragment.
  2543. */
  2544. ieseq = util_find_extn_eid(WLAN_ELEMID_EXTN_ELEM,
  2545. WLAN_EXTN_ELEMID_MULTI_LINK, buf,
  2546. buflen);
  2547. /* Even if the element is not found, we have successfully examined the
  2548. * buffer. The caller will be provided a NULL value for the starting of
  2549. * the Multi-Link element. Hence, we return success.
  2550. */
  2551. if (!ieseq)
  2552. return QDF_STATUS_SUCCESS;
  2553. bufboundary = buf + buflen;
  2554. if ((ieseq + MIN_IE_LEN) > bufboundary)
  2555. return QDF_STATUS_E_INVAL;
  2556. ieseqlen = MIN_IE_LEN + ieseq[TAG_LEN_POS];
  2557. if (ieseqlen < sizeof(struct wlan_ie_multilink))
  2558. return QDF_STATUS_E_PROTO;
  2559. if ((ieseq + ieseqlen) > bufboundary)
  2560. return QDF_STATUS_E_INVAL;
  2561. /* In the next sequence of checks, if there is no space in the buffer
  2562. * for another element after the Multi-Link element/element fragment
  2563. * sequence, it could indicate an issue since non-MLO EHT elements
  2564. * would be expected to follow the Multi-Link element/element fragment
  2565. * sequence. However, this is outside of the purview of this function,
  2566. * hence we ignore it.
  2567. */
  2568. currie = ieseq;
  2569. successorfrag = util_get_successorfrag(currie, buf, buflen);
  2570. /* Fragmentation definitions as of IEEE802.11be D1.0 and
  2571. * IEEE802.11REVme D0.2 are applied. Only the case where Multi-Link
  2572. * element is present in a buffer from the core frame is considered.
  2573. * Future changes to fragmentation, cases where the Multi-Link element
  2574. * is present in a subelement, etc. to be reflected here if applicable
  2575. * as and when the rules evolve.
  2576. */
  2577. while (successorfrag) {
  2578. /* We should not be seeing a successor fragment if the length
  2579. * of the current IE is lesser than the max.
  2580. */
  2581. if (currie[TAG_LEN_POS] != WLAN_MAX_IE_LEN)
  2582. return QDF_STATUS_E_PROTO;
  2583. if (successorfrag[TAG_LEN_POS] == 0)
  2584. return QDF_STATUS_E_PROTO;
  2585. ieseqlen += (MIN_IE_LEN + successorfrag[TAG_LEN_POS]);
  2586. currie = successorfrag;
  2587. successorfrag = util_get_successorfrag(currie, buf, buflen);
  2588. }
  2589. *mlieseq = ieseq;
  2590. *mlieseqlen = ieseqlen;
  2591. return QDF_STATUS_SUCCESS;
  2592. }
  2593. QDF_STATUS
  2594. util_find_mlie_by_variant(uint8_t *buf, qdf_size_t buflen, uint8_t **mlieseq,
  2595. qdf_size_t *mlieseqlen, int variant)
  2596. {
  2597. uint8_t *ieseq;
  2598. qdf_size_t ieseqlen;
  2599. QDF_STATUS status;
  2600. int ml_variant;
  2601. qdf_size_t buf_parsed_len;
  2602. if (!buf || !buflen || !mlieseq || !mlieseqlen)
  2603. return QDF_STATUS_E_NULL_VALUE;
  2604. if (variant >= WLAN_ML_VARIANT_INVALIDSTART)
  2605. return QDF_STATUS_E_PROTO;
  2606. ieseq = NULL;
  2607. ieseqlen = 0;
  2608. *mlieseq = NULL;
  2609. *mlieseqlen = 0;
  2610. buf_parsed_len = 0;
  2611. while (buflen > buf_parsed_len) {
  2612. status = util_find_mlie(buf + buf_parsed_len,
  2613. buflen - buf_parsed_len,
  2614. &ieseq, &ieseqlen);
  2615. if (QDF_IS_STATUS_ERROR(status))
  2616. return status;
  2617. /* Even if the element is not found, we have successfully
  2618. * examined the buffer. The caller will be provided a NULL value
  2619. * for the starting of the Multi-Link element. Hence, we return
  2620. * success.
  2621. */
  2622. if (!ieseq)
  2623. return QDF_STATUS_SUCCESS;
  2624. status = util_get_mlie_variant(ieseq, ieseqlen,
  2625. &ml_variant);
  2626. if (QDF_IS_STATUS_ERROR(status)) {
  2627. mlo_err("Unable to get Multi-link element variant");
  2628. return status;
  2629. }
  2630. if (ml_variant == variant) {
  2631. *mlieseq = ieseq;
  2632. *mlieseqlen = ieseqlen;
  2633. return QDF_STATUS_SUCCESS;
  2634. }
  2635. buf_parsed_len = ieseq + ieseqlen - buf;
  2636. }
  2637. return QDF_STATUS_E_INVAL;
  2638. }
  2639. QDF_STATUS
  2640. util_get_mlie_common_info_len(uint8_t *mlieseq, qdf_size_t mlieseqlen,
  2641. uint8_t *commoninfo_len)
  2642. {
  2643. struct wlan_ie_multilink *mlie_fixed;
  2644. enum wlan_ml_variant variant;
  2645. uint16_t mlcontrol;
  2646. if (!mlieseq || !mlieseqlen || !commoninfo_len)
  2647. return QDF_STATUS_E_NULL_VALUE;
  2648. if (mlieseqlen < sizeof(struct wlan_ie_multilink))
  2649. return QDF_STATUS_E_INVAL;
  2650. mlie_fixed = (struct wlan_ie_multilink *)mlieseq;
  2651. if (mlie_fixed->elem_id != WLAN_ELEMID_EXTN_ELEM ||
  2652. mlie_fixed->elem_id_ext != WLAN_EXTN_ELEMID_MULTI_LINK)
  2653. return QDF_STATUS_E_INVAL;
  2654. mlcontrol = qdf_le16_to_cpu(mlie_fixed->mlcontrol);
  2655. variant = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_TYPE_IDX,
  2656. WLAN_ML_CTRL_TYPE_BITS);
  2657. if (variant != WLAN_ML_VARIANT_BASIC)
  2658. return QDF_STATUS_E_INVAL;
  2659. /* Common Info starts at mlieseq + sizeof(struct wlan_ie_multilink).
  2660. * Check if there is sufficient space in the buffer for the Common Info
  2661. * Length and MLD MAC address.
  2662. */
  2663. if ((sizeof(struct wlan_ie_multilink) + WLAN_ML_BV_CINFO_LENGTH_SIZE +
  2664. QDF_MAC_ADDR_SIZE) > mlieseqlen)
  2665. return QDF_STATUS_E_PROTO;
  2666. *commoninfo_len = *(mlieseq + sizeof(struct wlan_ie_multilink));
  2667. return QDF_STATUS_SUCCESS;
  2668. }
  2669. QDF_STATUS
  2670. util_get_bvmlie_bssparamchangecnt(uint8_t *mlieseq, qdf_size_t mlieseqlen,
  2671. bool *bssparamchangecntfound,
  2672. uint8_t *bssparamchangecnt)
  2673. {
  2674. struct wlan_ie_multilink *mlie_fixed;
  2675. enum wlan_ml_variant variant;
  2676. uint16_t mlcontrol;
  2677. uint16_t presencebitmap;
  2678. uint8_t *commoninfo;
  2679. qdf_size_t commoninfolen;
  2680. if (!mlieseq || !mlieseqlen || !bssparamchangecntfound ||
  2681. !bssparamchangecnt)
  2682. return QDF_STATUS_E_NULL_VALUE;
  2683. *bssparamchangecntfound = false;
  2684. *bssparamchangecnt = 0;
  2685. if (mlieseqlen < sizeof(struct wlan_ie_multilink))
  2686. return QDF_STATUS_E_INVAL;
  2687. mlie_fixed = (struct wlan_ie_multilink *)mlieseq;
  2688. if (mlie_fixed->elem_id != WLAN_ELEMID_EXTN_ELEM ||
  2689. mlie_fixed->elem_id_ext != WLAN_EXTN_ELEMID_MULTI_LINK)
  2690. return QDF_STATUS_E_INVAL;
  2691. mlcontrol = qdf_le16_to_cpu(mlie_fixed->mlcontrol);
  2692. variant = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_TYPE_IDX,
  2693. WLAN_ML_CTRL_TYPE_BITS);
  2694. if (variant != WLAN_ML_VARIANT_BASIC)
  2695. return QDF_STATUS_E_NOSUPPORT;
  2696. presencebitmap = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_PBM_IDX,
  2697. WLAN_ML_CTRL_PBM_BITS);
  2698. commoninfo = mlieseq + sizeof(struct wlan_ie_multilink);
  2699. commoninfolen = WLAN_ML_BV_CINFO_LENGTH_SIZE;
  2700. commoninfolen += QDF_MAC_ADDR_SIZE;
  2701. if (presencebitmap & WLAN_ML_BV_CTRL_PBM_LINKIDINFO_P) {
  2702. commoninfolen += WLAN_ML_BV_CINFO_LINKIDINFO_SIZE;
  2703. if ((sizeof(struct wlan_ie_multilink) + commoninfolen) >
  2704. mlieseqlen)
  2705. return QDF_STATUS_E_PROTO;
  2706. }
  2707. if (presencebitmap & WLAN_ML_BV_CTRL_PBM_BSSPARAMCHANGECNT_P) {
  2708. *bssparamchangecntfound = true;
  2709. *bssparamchangecnt = *(commoninfo + commoninfolen);
  2710. }
  2711. return QDF_STATUS_SUCCESS;
  2712. }
  2713. QDF_STATUS
  2714. util_get_mlie_variant(uint8_t *mlieseq, qdf_size_t mlieseqlen,
  2715. int *variant)
  2716. {
  2717. struct wlan_ie_multilink *mlie_fixed;
  2718. enum wlan_ml_variant var;
  2719. uint16_t mlcontrol;
  2720. if (!mlieseq || !mlieseqlen || !variant)
  2721. return QDF_STATUS_E_NULL_VALUE;
  2722. if (mlieseqlen < sizeof(struct wlan_ie_multilink))
  2723. return QDF_STATUS_E_INVAL;
  2724. mlie_fixed = (struct wlan_ie_multilink *)mlieseq;
  2725. if ((mlie_fixed->elem_id != WLAN_ELEMID_EXTN_ELEM) ||
  2726. (mlie_fixed->elem_id_ext != WLAN_EXTN_ELEMID_MULTI_LINK))
  2727. return QDF_STATUS_E_INVAL;
  2728. mlcontrol = le16toh(mlie_fixed->mlcontrol);
  2729. var = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_TYPE_IDX,
  2730. WLAN_ML_CTRL_TYPE_BITS);
  2731. if (var >= WLAN_ML_VARIANT_INVALIDSTART)
  2732. return QDF_STATUS_E_PROTO;
  2733. *variant = var;
  2734. return QDF_STATUS_SUCCESS;
  2735. }
  2736. QDF_STATUS
  2737. util_get_bvmlie_eml_cap(uint8_t *mlieseq, qdf_size_t mlieseqlen,
  2738. bool *eml_cap_found,
  2739. uint16_t *eml_cap)
  2740. {
  2741. struct wlan_ie_multilink *mlie_fixed;
  2742. enum wlan_ml_variant variant;
  2743. uint16_t mlcontrol;
  2744. uint8_t eml_cap_offset;
  2745. uint8_t commoninfo_len;
  2746. uint16_t presencebitmap;
  2747. if (!mlieseq || !mlieseqlen || !eml_cap_found || !eml_cap)
  2748. return QDF_STATUS_E_NULL_VALUE;
  2749. *eml_cap = 0;
  2750. *eml_cap_found = false;
  2751. if (mlieseqlen < sizeof(struct wlan_ie_multilink))
  2752. return QDF_STATUS_E_INVAL;
  2753. mlie_fixed = (struct wlan_ie_multilink *)mlieseq;
  2754. if ((mlie_fixed->elem_id != WLAN_ELEMID_EXTN_ELEM) ||
  2755. (mlie_fixed->elem_id_ext != WLAN_EXTN_ELEMID_MULTI_LINK))
  2756. return QDF_STATUS_E_INVAL;
  2757. mlcontrol = qdf_le16_to_cpu(mlie_fixed->mlcontrol);
  2758. variant = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_TYPE_IDX,
  2759. WLAN_ML_CTRL_TYPE_BITS);
  2760. if (variant != WLAN_ML_VARIANT_BASIC)
  2761. return QDF_STATUS_E_INVAL;
  2762. presencebitmap = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_PBM_IDX,
  2763. WLAN_ML_CTRL_PBM_BITS);
  2764. /* eml_cap_offset stores the offset of EML Capabilities within
  2765. * Common Info
  2766. */
  2767. eml_cap_offset = WLAN_ML_BV_CINFO_LENGTH_SIZE + QDF_MAC_ADDR_SIZE;
  2768. if (presencebitmap & WLAN_ML_BV_CTRL_PBM_LINKIDINFO_P)
  2769. eml_cap_offset += WLAN_ML_BV_CINFO_LINKIDINFO_SIZE;
  2770. if (presencebitmap & WLAN_ML_BV_CTRL_PBM_BSSPARAMCHANGECNT_P)
  2771. eml_cap_offset += WLAN_ML_BSSPARAMCHNGCNT_SIZE;
  2772. if (presencebitmap & WLAN_ML_BV_CTRL_PBM_MEDIUMSYNCDELAYINFO_P)
  2773. eml_cap_offset += WLAN_ML_BV_CINFO_MEDMSYNCDELAYINFO_SIZE;
  2774. if (presencebitmap & WLAN_ML_BV_CTRL_PBM_EMLCAP_P) {
  2775. /* Common Info starts at
  2776. * mlieseq + sizeof(struct wlan_ie_multilink).
  2777. * Check if there is sufficient space in the buffer for
  2778. * the Common Info Length.
  2779. */
  2780. if (mlieseqlen < (sizeof(struct wlan_ie_multilink) +
  2781. WLAN_ML_BV_CINFO_LENGTH_SIZE))
  2782. return QDF_STATUS_E_PROTO;
  2783. /* Check if the value indicated in the Common Info Length
  2784. * subfield is sufficient to access the EML capabilities.
  2785. */
  2786. commoninfo_len = *(mlieseq + sizeof(struct wlan_ie_multilink));
  2787. if (commoninfo_len < (eml_cap_offset +
  2788. WLAN_ML_BV_CINFO_EMLCAP_SIZE))
  2789. return QDF_STATUS_E_PROTO;
  2790. /* Common Info starts at mlieseq + sizeof(struct
  2791. * wlan_ie_multilink). Check if there is sufficient space in
  2792. * Common Info for the EML capability.
  2793. */
  2794. if (mlieseqlen < (sizeof(struct wlan_ie_multilink) +
  2795. eml_cap_offset +
  2796. WLAN_ML_BV_CINFO_EMLCAP_SIZE))
  2797. return QDF_STATUS_E_PROTO;
  2798. *eml_cap_found = true;
  2799. *eml_cap = qdf_le16_to_cpu(*(uint16_t *)(mlieseq +
  2800. sizeof(struct wlan_ie_multilink) +
  2801. eml_cap_offset));
  2802. }
  2803. return QDF_STATUS_SUCCESS;
  2804. }
  2805. QDF_STATUS
  2806. util_get_bvmlie_msd_cap(uint8_t *mlieseq, qdf_size_t mlieseqlen,
  2807. bool *msd_cap_found,
  2808. uint16_t *msd_cap)
  2809. {
  2810. struct wlan_ie_multilink *mlie_fixed;
  2811. enum wlan_ml_variant variant;
  2812. uint16_t mlcontrol;
  2813. uint8_t msd_cap_offset;
  2814. uint8_t commoninfo_len;
  2815. uint16_t presencebitmap;
  2816. if (!mlieseq || !mlieseqlen || !msd_cap_found || !msd_cap)
  2817. return QDF_STATUS_E_NULL_VALUE;
  2818. *msd_cap = 0;
  2819. *msd_cap_found = false;
  2820. if (mlieseqlen < sizeof(struct wlan_ie_multilink))
  2821. return QDF_STATUS_E_INVAL;
  2822. mlie_fixed = (struct wlan_ie_multilink *)mlieseq;
  2823. if ((mlie_fixed->elem_id != WLAN_ELEMID_EXTN_ELEM) ||
  2824. (mlie_fixed->elem_id_ext != WLAN_EXTN_ELEMID_MULTI_LINK))
  2825. return QDF_STATUS_E_INVAL;
  2826. mlcontrol = qdf_le16_to_cpu(mlie_fixed->mlcontrol);
  2827. variant = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_TYPE_IDX,
  2828. WLAN_ML_CTRL_TYPE_BITS);
  2829. if (variant != WLAN_ML_VARIANT_BASIC)
  2830. return QDF_STATUS_E_INVAL;
  2831. presencebitmap = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_PBM_IDX,
  2832. WLAN_ML_CTRL_PBM_BITS);
  2833. /* msd_cap_offset stores the offset of MSD capabilities within
  2834. * Common Info
  2835. */
  2836. msd_cap_offset = WLAN_ML_BV_CINFO_LENGTH_SIZE + QDF_MAC_ADDR_SIZE;
  2837. if (presencebitmap & WLAN_ML_BV_CTRL_PBM_LINKIDINFO_P)
  2838. msd_cap_offset += WLAN_ML_BV_CINFO_LINKIDINFO_SIZE;
  2839. if (presencebitmap & WLAN_ML_BV_CTRL_PBM_BSSPARAMCHANGECNT_P)
  2840. msd_cap_offset += WLAN_ML_BSSPARAMCHNGCNT_SIZE;
  2841. if (presencebitmap & WLAN_ML_BV_CTRL_PBM_MEDIUMSYNCDELAYINFO_P) {
  2842. /* Common Info starts at
  2843. * mlieseq + sizeof(struct wlan_ie_multilink).
  2844. * Check if there is sufficient space in the buffer for
  2845. * the Common Info Length.
  2846. */
  2847. if (mlieseqlen < (sizeof(struct wlan_ie_multilink) +
  2848. WLAN_ML_BV_CINFO_LENGTH_SIZE))
  2849. return QDF_STATUS_E_PROTO;
  2850. /* Check if the value indicated in the Common Info Length
  2851. * subfield is sufficient to access the MSD capabilities.
  2852. */
  2853. commoninfo_len = *(mlieseq + sizeof(struct wlan_ie_multilink));
  2854. if (commoninfo_len < (msd_cap_offset +
  2855. WLAN_ML_BV_CINFO_MEDMSYNCDELAYINFO_SIZE))
  2856. return QDF_STATUS_E_PROTO;
  2857. /* Common Info starts at mlieseq + sizeof(struct
  2858. * wlan_ie_multilink). Check if there is sufficient space in
  2859. * Common Info for the MSD capability.
  2860. */
  2861. if (mlieseqlen < (sizeof(struct wlan_ie_multilink) +
  2862. msd_cap_offset +
  2863. WLAN_ML_BV_CINFO_MEDMSYNCDELAYINFO_SIZE))
  2864. return QDF_STATUS_E_PROTO;
  2865. *msd_cap_found = true;
  2866. *msd_cap = qdf_le16_to_cpu(*(uint16_t *)(mlieseq +
  2867. sizeof(struct wlan_ie_multilink) +
  2868. msd_cap_offset));
  2869. } else {
  2870. mlo_debug("MSD caps not found in assoc rsp");
  2871. }
  2872. return QDF_STATUS_SUCCESS;
  2873. }
  2874. QDF_STATUS
  2875. util_get_bvmlie_mldmacaddr(uint8_t *mlieseq, qdf_size_t mlieseqlen,
  2876. struct qdf_mac_addr *mldmacaddr)
  2877. {
  2878. struct wlan_ie_multilink *mlie_fixed;
  2879. enum wlan_ml_variant variant;
  2880. uint16_t mlcontrol;
  2881. uint8_t commoninfo_len;
  2882. if (!mlieseq || !mlieseqlen || !mldmacaddr)
  2883. return QDF_STATUS_E_NULL_VALUE;
  2884. qdf_mem_zero(mldmacaddr, sizeof(*mldmacaddr));
  2885. if (mlieseqlen < sizeof(struct wlan_ie_multilink))
  2886. return QDF_STATUS_E_INVAL;
  2887. mlie_fixed = (struct wlan_ie_multilink *)mlieseq;
  2888. if ((mlie_fixed->elem_id != WLAN_ELEMID_EXTN_ELEM) ||
  2889. (mlie_fixed->elem_id_ext != WLAN_EXTN_ELEMID_MULTI_LINK))
  2890. return QDF_STATUS_E_INVAL;
  2891. mlcontrol = qdf_le16_to_cpu(mlie_fixed->mlcontrol);
  2892. variant = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_TYPE_IDX,
  2893. WLAN_ML_CTRL_TYPE_BITS);
  2894. if (variant != WLAN_ML_VARIANT_BASIC)
  2895. return QDF_STATUS_E_INVAL;
  2896. /* Common Info starts at mlieseq + sizeof(struct wlan_ie_multilink).
  2897. * Check if there is sufficient space in the buffer for the Common Info
  2898. * Length and MLD MAC address.
  2899. */
  2900. if ((sizeof(struct wlan_ie_multilink) + WLAN_ML_BV_CINFO_LENGTH_SIZE +
  2901. QDF_MAC_ADDR_SIZE) > mlieseqlen)
  2902. return QDF_STATUS_E_PROTO;
  2903. /* Check if the value indicated in the Common Info Length subfield is
  2904. * sufficient to access the MLD MAC address.
  2905. */
  2906. commoninfo_len = *(mlieseq + sizeof(struct wlan_ie_multilink));
  2907. if (commoninfo_len < (WLAN_ML_BV_CINFO_LENGTH_SIZE + QDF_MAC_ADDR_SIZE))
  2908. return QDF_STATUS_E_PROTO;
  2909. qdf_mem_copy(mldmacaddr->bytes,
  2910. mlieseq + sizeof(struct wlan_ie_multilink) +
  2911. WLAN_ML_BV_CINFO_LENGTH_SIZE,
  2912. QDF_MAC_ADDR_SIZE);
  2913. return QDF_STATUS_SUCCESS;
  2914. }
  2915. QDF_STATUS
  2916. util_get_bvmlie_primary_linkid(uint8_t *mlieseq, qdf_size_t mlieseqlen,
  2917. bool *linkidfound, uint8_t *linkid)
  2918. {
  2919. struct wlan_ie_multilink *mlie_fixed;
  2920. enum wlan_ml_variant variant;
  2921. uint16_t mlcontrol;
  2922. uint16_t presencebitmap;
  2923. uint8_t *commoninfo;
  2924. qdf_size_t commoninfolen;
  2925. uint8_t *linkidinfo;
  2926. if (!mlieseq || !mlieseqlen || !linkidfound || !linkid)
  2927. return QDF_STATUS_E_NULL_VALUE;
  2928. *linkidfound = false;
  2929. *linkid = 0;
  2930. if (mlieseqlen < sizeof(struct wlan_ie_multilink))
  2931. return QDF_STATUS_E_INVAL;
  2932. mlie_fixed = (struct wlan_ie_multilink *)mlieseq;
  2933. if ((mlie_fixed->elem_id != WLAN_ELEMID_EXTN_ELEM) ||
  2934. (mlie_fixed->elem_id_ext != WLAN_EXTN_ELEMID_MULTI_LINK))
  2935. return QDF_STATUS_E_INVAL;
  2936. mlcontrol = le16toh(mlie_fixed->mlcontrol);
  2937. variant = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_TYPE_IDX,
  2938. WLAN_ML_CTRL_TYPE_BITS);
  2939. if (variant != WLAN_ML_VARIANT_BASIC)
  2940. return QDF_STATUS_E_INVAL;
  2941. presencebitmap = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_PBM_IDX,
  2942. WLAN_ML_CTRL_PBM_BITS);
  2943. commoninfo = mlieseq + sizeof(struct wlan_ie_multilink);
  2944. commoninfolen = 0;
  2945. commoninfolen += WLAN_ML_BV_CINFO_LENGTH_SIZE;
  2946. if ((sizeof(struct wlan_ie_multilink) + commoninfolen) >
  2947. mlieseqlen)
  2948. return QDF_STATUS_E_PROTO;
  2949. commoninfolen += QDF_MAC_ADDR_SIZE;
  2950. if ((sizeof(struct wlan_ie_multilink) + commoninfolen) >
  2951. mlieseqlen)
  2952. return QDF_STATUS_E_PROTO;
  2953. if (presencebitmap & WLAN_ML_BV_CTRL_PBM_LINKIDINFO_P) {
  2954. linkidinfo = commoninfo + commoninfolen;
  2955. commoninfolen += WLAN_ML_BV_CINFO_LINKIDINFO_SIZE;
  2956. if ((sizeof(struct wlan_ie_multilink) + commoninfolen) >
  2957. mlieseqlen)
  2958. return QDF_STATUS_E_PROTO;
  2959. *linkidfound = true;
  2960. *linkid = QDF_GET_BITS(linkidinfo[0],
  2961. WLAN_ML_BV_CINFO_LINKIDINFO_LINKID_IDX,
  2962. WLAN_ML_BV_CINFO_LINKIDINFO_LINKID_BITS);
  2963. }
  2964. return QDF_STATUS_SUCCESS;
  2965. }
  2966. QDF_STATUS
  2967. util_get_bvmlie_mldcap(uint8_t *mlieseq, qdf_size_t mlieseqlen,
  2968. bool *mldcapfound, uint16_t *mldcap)
  2969. {
  2970. struct wlan_ie_multilink *mlie_fixed;
  2971. enum wlan_ml_variant variant;
  2972. uint16_t mlcontrol;
  2973. uint16_t presencebitmap;
  2974. uint8_t *commoninfo;
  2975. uint8_t commoninfo_len;
  2976. qdf_size_t mldcap_offset;
  2977. if (!mlieseq || !mlieseqlen || !mldcapfound || !mldcap)
  2978. return QDF_STATUS_E_NULL_VALUE;
  2979. *mldcapfound = false;
  2980. *mldcap = 0;
  2981. if (mlieseqlen < sizeof(struct wlan_ie_multilink))
  2982. return QDF_STATUS_E_INVAL;
  2983. mlie_fixed = (struct wlan_ie_multilink *)mlieseq;
  2984. if (mlie_fixed->elem_id != WLAN_ELEMID_EXTN_ELEM ||
  2985. mlie_fixed->elem_id_ext != WLAN_EXTN_ELEMID_MULTI_LINK)
  2986. return QDF_STATUS_E_INVAL;
  2987. mlcontrol = qdf_le16_to_cpu(mlie_fixed->mlcontrol);
  2988. variant = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_TYPE_IDX,
  2989. WLAN_ML_CTRL_TYPE_BITS);
  2990. if (variant != WLAN_ML_VARIANT_BASIC)
  2991. return QDF_STATUS_E_NOSUPPORT;
  2992. presencebitmap = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_PBM_IDX,
  2993. WLAN_ML_CTRL_PBM_BITS);
  2994. commoninfo = mlieseq + sizeof(struct wlan_ie_multilink);
  2995. commoninfo_len = *(mlieseq + sizeof(struct wlan_ie_multilink));
  2996. /* mldcap_offset stores the offset of MLD Capabilities within
  2997. * Common Info
  2998. */
  2999. mldcap_offset = WLAN_ML_BV_CINFO_LENGTH_SIZE;
  3000. mldcap_offset += QDF_MAC_ADDR_SIZE;
  3001. if (presencebitmap & WLAN_ML_BV_CTRL_PBM_LINKIDINFO_P) {
  3002. mldcap_offset += WLAN_ML_BV_CINFO_LINKIDINFO_SIZE;
  3003. if ((sizeof(struct wlan_ie_multilink) + mldcap_offset) >
  3004. mlieseqlen)
  3005. return QDF_STATUS_E_PROTO;
  3006. }
  3007. if (presencebitmap & WLAN_ML_BV_CTRL_PBM_BSSPARAMCHANGECNT_P) {
  3008. mldcap_offset += WLAN_ML_BSSPARAMCHNGCNT_SIZE;
  3009. if ((sizeof(struct wlan_ie_multilink) + mldcap_offset) >
  3010. mlieseqlen)
  3011. return QDF_STATUS_E_PROTO;
  3012. }
  3013. if (presencebitmap & WLAN_ML_BV_CTRL_PBM_MEDIUMSYNCDELAYINFO_P) {
  3014. mldcap_offset += WLAN_ML_BV_CINFO_MEDMSYNCDELAYINFO_SIZE;
  3015. if ((sizeof(struct wlan_ie_multilink) + mldcap_offset) >
  3016. mlieseqlen)
  3017. return QDF_STATUS_E_PROTO;
  3018. }
  3019. if (presencebitmap & WLAN_ML_BV_CTRL_PBM_EMLCAP_P) {
  3020. mldcap_offset += WLAN_ML_BV_CINFO_EMLCAP_SIZE;
  3021. if ((sizeof(struct wlan_ie_multilink) + mldcap_offset) >
  3022. mlieseqlen)
  3023. return QDF_STATUS_E_PROTO;
  3024. }
  3025. if (presencebitmap & WLAN_ML_BV_CTRL_PBM_MLDCAPANDOP_P) {
  3026. /* Check if the value indicated in the Common Info Length
  3027. * subfield is sufficient to access the MLD capabilities.
  3028. */
  3029. if (commoninfo_len < (mldcap_offset +
  3030. WLAN_ML_BV_CINFO_MLDCAPANDOP_SIZE))
  3031. return QDF_STATUS_E_PROTO;
  3032. if ((sizeof(struct wlan_ie_multilink) + mldcap_offset +
  3033. WLAN_ML_BV_CINFO_MLDCAPANDOP_SIZE) >
  3034. mlieseqlen)
  3035. return QDF_STATUS_E_PROTO;
  3036. *mldcap = qdf_le16_to_cpu(*((uint16_t *)(commoninfo + mldcap_offset)));
  3037. *mldcapfound = true;
  3038. }
  3039. return QDF_STATUS_SUCCESS;
  3040. }
  3041. QDF_STATUS
  3042. util_get_bvmlie_persta_partner_info(uint8_t *mlieseq,
  3043. qdf_size_t mlieseqlen,
  3044. struct mlo_partner_info *partner_info)
  3045. {
  3046. struct wlan_ie_multilink *mlie_fixed;
  3047. uint16_t mlcontrol;
  3048. enum wlan_ml_variant variant;
  3049. uint8_t *linkinfo;
  3050. qdf_size_t linkinfo_len;
  3051. struct mlo_partner_info pinfo = {0};
  3052. qdf_size_t mlieseqpayloadlen;
  3053. uint8_t *mlieseqpayload_copy;
  3054. bool is_elemfragseq;
  3055. qdf_size_t defragpayload_len;
  3056. qdf_size_t tmplen;
  3057. QDF_STATUS ret;
  3058. if (!mlieseq) {
  3059. mlo_err("Pointer to Multi-Link element sequence is NULL");
  3060. return QDF_STATUS_E_NULL_VALUE;
  3061. }
  3062. if (!mlieseqlen) {
  3063. mlo_err("Length of Multi-Link element sequence is zero");
  3064. return QDF_STATUS_E_INVAL;
  3065. }
  3066. if (!partner_info) {
  3067. mlo_err("partner_info is NULL");
  3068. return QDF_STATUS_E_NULL_VALUE;
  3069. }
  3070. partner_info->num_partner_links = 0;
  3071. if (mlieseqlen < sizeof(struct wlan_ie_multilink)) {
  3072. mlo_err_rl("Multi-Link element sequence length %zu octets is smaller than required for the fixed portion of Multi-Link element (%zu octets)",
  3073. mlieseqlen, sizeof(struct wlan_ie_multilink));
  3074. return QDF_STATUS_E_INVAL;
  3075. }
  3076. mlie_fixed = (struct wlan_ie_multilink *)mlieseq;
  3077. if ((mlie_fixed->elem_id != WLAN_ELEMID_EXTN_ELEM) ||
  3078. (mlie_fixed->elem_id_ext != WLAN_EXTN_ELEMID_MULTI_LINK)) {
  3079. mlo_err("The element is not a Multi-Link element");
  3080. return QDF_STATUS_E_INVAL;
  3081. }
  3082. mlcontrol = le16toh(mlie_fixed->mlcontrol);
  3083. variant = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_TYPE_IDX,
  3084. WLAN_ML_CTRL_TYPE_BITS);
  3085. if (variant != WLAN_ML_VARIANT_BASIC) {
  3086. mlo_err("The variant value %u does not correspond to Basic Variant value %u",
  3087. variant, WLAN_ML_VARIANT_BASIC);
  3088. return QDF_STATUS_E_INVAL;
  3089. }
  3090. mlieseqpayloadlen = 0;
  3091. tmplen = 0;
  3092. is_elemfragseq = false;
  3093. ret = wlan_get_elem_fragseq_info(mlieseq,
  3094. mlieseqlen,
  3095. &is_elemfragseq,
  3096. &tmplen,
  3097. &mlieseqpayloadlen);
  3098. if (QDF_IS_STATUS_ERROR(ret))
  3099. return ret;
  3100. if (is_elemfragseq) {
  3101. if (tmplen != mlieseqlen) {
  3102. mlo_err_rl("Mismatch in values of element fragment sequence total length. Val per frag info determination: %zu octets, val passed as arg: %zu octets",
  3103. tmplen, mlieseqlen);
  3104. return QDF_STATUS_E_INVAL;
  3105. }
  3106. if (!mlieseqpayloadlen) {
  3107. mlo_err_rl("Multi-Link element fragment sequence payload is reported as 0, investigate");
  3108. return QDF_STATUS_E_FAILURE;
  3109. }
  3110. mlo_debug("Multi-Link element fragment sequence found with payload len %zu",
  3111. mlieseqpayloadlen);
  3112. } else {
  3113. if (mlieseqlen > (sizeof(struct ie_header) + WLAN_MAX_IE_LEN)) {
  3114. mlo_err_rl("Expected presence of valid fragment sequence since Multi-Link element sequence length %zu octets is larger than frag threshold of %zu octets, however no valid fragment sequence found",
  3115. mlieseqlen,
  3116. sizeof(struct ie_header) + WLAN_MAX_IE_LEN);
  3117. return QDF_STATUS_E_FAILURE;
  3118. }
  3119. mlieseqpayloadlen = mlieseqlen - (sizeof(struct ie_header) + 1);
  3120. }
  3121. mlieseqpayload_copy = qdf_mem_malloc(mlieseqpayloadlen);
  3122. if (!mlieseqpayload_copy) {
  3123. mlo_err_rl("Could not allocate memory for Multi-Link element payload copy");
  3124. return QDF_STATUS_E_NOMEM;
  3125. }
  3126. if (is_elemfragseq) {
  3127. ret = wlan_defrag_elem_fragseq(false,
  3128. mlieseq,
  3129. mlieseqlen,
  3130. mlieseqpayload_copy,
  3131. mlieseqpayloadlen,
  3132. &defragpayload_len);
  3133. if (QDF_IS_STATUS_ERROR(ret)) {
  3134. qdf_mem_free(mlieseqpayload_copy);
  3135. return ret;
  3136. }
  3137. if (defragpayload_len != mlieseqpayloadlen) {
  3138. mlo_err_rl("Length of de-fragmented payload %zu octets is not equal to length of Multi-Link element fragment sequence payload %zu octets",
  3139. defragpayload_len, mlieseqpayloadlen);
  3140. qdf_mem_free(mlieseqpayload_copy);
  3141. return QDF_STATUS_E_FAILURE;
  3142. }
  3143. } else {
  3144. qdf_mem_copy(mlieseqpayload_copy,
  3145. mlieseq + sizeof(struct ie_header) + 1,
  3146. mlieseqpayloadlen);
  3147. }
  3148. linkinfo = NULL;
  3149. linkinfo_len = 0;
  3150. ret = util_parse_multi_link_ctrl(mlieseqpayload_copy,
  3151. mlieseqpayloadlen,
  3152. &linkinfo,
  3153. &linkinfo_len);
  3154. if (QDF_IS_STATUS_ERROR(ret)) {
  3155. qdf_mem_free(mlieseqpayload_copy);
  3156. return ret;
  3157. }
  3158. /*
  3159. * If Probe Request variant Multi-Link element in the Multi-Link probe
  3160. * request does not include any per-STA profile, then all APs affiliated
  3161. * with the same AP MLD as the AP identified in the Addr 1 or Addr 3
  3162. * field or AP MLD ID of the Multi-Link probe request are requested
  3163. * APs return success here
  3164. */
  3165. if (!linkinfo) {
  3166. qdf_mem_free(mlieseqpayload_copy);
  3167. return QDF_STATUS_SUCCESS;
  3168. }
  3169. ret = util_parse_partner_info_from_linkinfo(linkinfo,
  3170. linkinfo_len,
  3171. &pinfo);
  3172. if (QDF_IS_STATUS_ERROR(ret)) {
  3173. qdf_mem_free(mlieseqpayload_copy);
  3174. return ret;
  3175. }
  3176. qdf_mem_copy(partner_info, &pinfo, sizeof(*partner_info));
  3177. qdf_mem_free(mlieseqpayload_copy);
  3178. return QDF_STATUS_SUCCESS;
  3179. }
  3180. QDF_STATUS
  3181. util_get_prvmlie_persta_link_id(uint8_t *mlieseq,
  3182. qdf_size_t mlieseqlen,
  3183. struct mlo_probereq_info *probereq_info)
  3184. {
  3185. struct wlan_ie_multilink *mlie_fixed;
  3186. uint16_t mlcontrol;
  3187. enum wlan_ml_variant variant;
  3188. uint8_t *linkinfo;
  3189. qdf_size_t linkinfo_len;
  3190. qdf_size_t mlieseqpayloadlen;
  3191. uint8_t *mlieseqpayload_copy;
  3192. bool is_elemfragseq;
  3193. qdf_size_t defragpayload_len;
  3194. qdf_size_t tmplen;
  3195. QDF_STATUS ret;
  3196. if (!mlieseq) {
  3197. mlo_err("Pointer to Multi-Link element sequence is NULL");
  3198. return QDF_STATUS_E_NULL_VALUE;
  3199. }
  3200. if (!mlieseqlen) {
  3201. mlo_err("Length of Multi-Link element sequence is zero");
  3202. return QDF_STATUS_E_INVAL;
  3203. }
  3204. if (!probereq_info) {
  3205. mlo_err("probe request_info is NULL");
  3206. return QDF_STATUS_E_NULL_VALUE;
  3207. }
  3208. probereq_info->num_links = 0;
  3209. if (mlieseqlen < sizeof(struct wlan_ie_multilink)) {
  3210. mlo_err_rl("Multi-Link element sequence length %zu octets is smaller than required for the fixed portion of Multi-Link element (%zu octets)",
  3211. mlieseqlen, sizeof(struct wlan_ie_multilink));
  3212. return QDF_STATUS_E_INVAL;
  3213. }
  3214. mlie_fixed = (struct wlan_ie_multilink *)mlieseq;
  3215. if ((mlie_fixed->elem_id != WLAN_ELEMID_EXTN_ELEM) ||
  3216. (mlie_fixed->elem_id_ext != WLAN_EXTN_ELEMID_MULTI_LINK)) {
  3217. mlo_err("The element is not a Multi-Link element");
  3218. return QDF_STATUS_E_INVAL;
  3219. }
  3220. mlcontrol = qdf_le16_to_cpu(mlie_fixed->mlcontrol);
  3221. variant = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_TYPE_IDX,
  3222. WLAN_ML_CTRL_TYPE_BITS);
  3223. if (variant != WLAN_ML_VARIANT_PROBEREQ) {
  3224. mlo_err("The variant value %u does not correspond to Probe Request Variant value %u",
  3225. variant, WLAN_ML_VARIANT_PROBEREQ);
  3226. return QDF_STATUS_E_INVAL;
  3227. }
  3228. mlieseqpayloadlen = 0;
  3229. tmplen = 0;
  3230. is_elemfragseq = false;
  3231. ret = wlan_get_elem_fragseq_info(mlieseq,
  3232. mlieseqlen,
  3233. &is_elemfragseq,
  3234. &tmplen,
  3235. &mlieseqpayloadlen);
  3236. if (QDF_IS_STATUS_ERROR(ret))
  3237. return ret;
  3238. if (is_elemfragseq) {
  3239. if (tmplen != mlieseqlen) {
  3240. mlo_err_rl("Mismatch in values of element fragment sequence total length. Val per frag info determination: %zu octets, val passed as arg: %zu octets",
  3241. tmplen, mlieseqlen);
  3242. return QDF_STATUS_E_INVAL;
  3243. }
  3244. if (!mlieseqpayloadlen) {
  3245. mlo_err_rl("Multi-Link element fragment sequence payload is reported as 0, investigate");
  3246. return QDF_STATUS_E_FAILURE;
  3247. }
  3248. mlo_debug("Multi-Link element fragment sequence found with payload len %zu",
  3249. mlieseqpayloadlen);
  3250. } else {
  3251. if (mlieseqlen > (sizeof(struct ie_header) + WLAN_MAX_IE_LEN)) {
  3252. mlo_err_rl("Expected presence of valid fragment sequence since Multi-Link element sequence length %zu octets is larger than frag threshold of %zu octets, however no valid fragment sequence found",
  3253. mlieseqlen,
  3254. sizeof(struct ie_header) + WLAN_MAX_IE_LEN);
  3255. return QDF_STATUS_E_FAILURE;
  3256. }
  3257. mlieseqpayloadlen = mlieseqlen - (sizeof(struct ie_header) + 1);
  3258. }
  3259. mlieseqpayload_copy = qdf_mem_malloc(mlieseqpayloadlen);
  3260. if (!mlieseqpayload_copy) {
  3261. mlo_err_rl("Could not allocate memory for Multi-Link element payload copy");
  3262. return QDF_STATUS_E_NOMEM;
  3263. }
  3264. if (is_elemfragseq) {
  3265. ret = wlan_defrag_elem_fragseq(false,
  3266. mlieseq,
  3267. mlieseqlen,
  3268. mlieseqpayload_copy,
  3269. mlieseqpayloadlen,
  3270. &defragpayload_len);
  3271. if (QDF_IS_STATUS_ERROR(ret)) {
  3272. qdf_mem_free(mlieseqpayload_copy);
  3273. return ret;
  3274. }
  3275. if (defragpayload_len != mlieseqpayloadlen) {
  3276. mlo_err_rl("Length of de-fragmented payload %zu octets is not equal to length of Multi-Link element fragment sequence payload %zu octets",
  3277. defragpayload_len, mlieseqpayloadlen);
  3278. qdf_mem_free(mlieseqpayload_copy);
  3279. return QDF_STATUS_E_FAILURE;
  3280. }
  3281. } else {
  3282. qdf_mem_copy(mlieseqpayload_copy,
  3283. mlieseq + sizeof(struct ie_header) + 1,
  3284. mlieseqpayloadlen);
  3285. }
  3286. linkinfo = NULL;
  3287. linkinfo_len = 0;
  3288. ret = util_parse_prv_multi_link_ctrl(mlieseqpayload_copy,
  3289. mlieseqpayloadlen,
  3290. &linkinfo,
  3291. &linkinfo_len);
  3292. if (QDF_IS_STATUS_ERROR(ret)) {
  3293. qdf_mem_free(mlieseqpayload_copy);
  3294. return ret;
  3295. }
  3296. /* In case Link Info is absent, the number of links will remain
  3297. * zero.
  3298. */
  3299. if (!linkinfo) {
  3300. mlo_debug("No link info present");
  3301. qdf_mem_free(mlieseqpayload_copy);
  3302. return QDF_STATUS_SUCCESS;
  3303. }
  3304. ret = util_parse_probereq_info_from_linkinfo(linkinfo,
  3305. linkinfo_len,
  3306. probereq_info);
  3307. if (QDF_IS_STATUS_ERROR(ret)) {
  3308. qdf_mem_free(mlieseqpayload_copy);
  3309. return ret;
  3310. }
  3311. qdf_mem_free(mlieseqpayload_copy);
  3312. return QDF_STATUS_SUCCESS;
  3313. }
  3314. QDF_STATUS
  3315. util_get_prvmlie_mldid(uint8_t *mlieseq, qdf_size_t mlieseqlen,
  3316. bool *mldidfound, uint8_t *mldid)
  3317. {
  3318. struct wlan_ie_multilink *mlie_fixed;
  3319. enum wlan_ml_variant variant;
  3320. uint16_t mlcontrol;
  3321. uint16_t presencebitmap;
  3322. uint8_t *commoninfo;
  3323. qdf_size_t commoninfolen;
  3324. if (!mlieseq || !mlieseqlen || !mldidfound || !mldid)
  3325. return QDF_STATUS_E_NULL_VALUE;
  3326. *mldidfound = false;
  3327. *mldid = 0;
  3328. if (mlieseqlen < sizeof(struct wlan_ie_multilink))
  3329. return QDF_STATUS_E_INVAL;
  3330. mlie_fixed = (struct wlan_ie_multilink *)mlieseq;
  3331. if (mlie_fixed->elem_id != WLAN_ELEMID_EXTN_ELEM ||
  3332. mlie_fixed->elem_id_ext != WLAN_EXTN_ELEMID_MULTI_LINK)
  3333. return QDF_STATUS_E_INVAL;
  3334. mlcontrol = qdf_le16_to_cpu(mlie_fixed->mlcontrol);
  3335. variant = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_TYPE_IDX,
  3336. WLAN_ML_CTRL_TYPE_BITS);
  3337. if (variant != WLAN_ML_VARIANT_PROBEREQ)
  3338. return QDF_STATUS_E_NOSUPPORT;
  3339. presencebitmap = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_PBM_IDX,
  3340. WLAN_ML_CTRL_PBM_BITS);
  3341. commoninfo = mlieseq + sizeof(struct wlan_ie_multilink);
  3342. commoninfolen = WLAN_ML_PRV_CINFO_LENGTH_SIZE;
  3343. if (presencebitmap & WLAN_ML_PRV_CTRL_PBM_MLDID_P) {
  3344. if ((sizeof(struct wlan_ie_multilink) + commoninfolen +
  3345. WLAN_ML_PRV_CINFO_MLDID_SIZE) >
  3346. mlieseqlen)
  3347. return QDF_STATUS_E_PROTO;
  3348. *mldid = *((uint8_t *)(commoninfo + commoninfolen));
  3349. commoninfolen += WLAN_ML_PRV_CINFO_MLDID_SIZE;
  3350. *mldidfound = true;
  3351. }
  3352. return QDF_STATUS_SUCCESS;
  3353. }
  3354. QDF_STATUS util_get_rvmlie_mldmacaddr(uint8_t *mlieseq, qdf_size_t mlieseqlen,
  3355. struct qdf_mac_addr *mldmacaddr)
  3356. {
  3357. struct wlan_ie_multilink *mlie_fixed;
  3358. enum wlan_ml_variant variant;
  3359. uint16_t mlcontrol;
  3360. uint16_t presencebitmap;
  3361. if (!mlieseq || !mlieseqlen || !mldmacaddr)
  3362. return QDF_STATUS_E_NULL_VALUE;
  3363. qdf_mem_zero(mldmacaddr, sizeof(*mldmacaddr));
  3364. if (mlieseqlen < sizeof(struct wlan_ie_multilink))
  3365. return QDF_STATUS_E_INVAL;
  3366. mlie_fixed = (struct wlan_ie_multilink *)mlieseq;
  3367. if (mlie_fixed->elem_id != WLAN_ELEMID_EXTN_ELEM ||
  3368. mlie_fixed->elem_id_ext != WLAN_EXTN_ELEMID_MULTI_LINK)
  3369. return QDF_STATUS_E_INVAL;
  3370. mlcontrol = qdf_le16_to_cpu(mlie_fixed->mlcontrol);
  3371. variant = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_TYPE_IDX,
  3372. WLAN_ML_CTRL_TYPE_BITS);
  3373. if (variant != WLAN_ML_VARIANT_RECONFIG)
  3374. return QDF_STATUS_E_INVAL;
  3375. presencebitmap = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_PBM_IDX,
  3376. WLAN_ML_CTRL_PBM_BITS);
  3377. /* Check if MLD mac address is present */
  3378. if (presencebitmap & WLAN_ML_RV_CTRL_PBM_MLDMACADDR_P) {
  3379. if ((sizeof(struct wlan_ie_multilink) + QDF_MAC_ADDR_SIZE) >
  3380. mlieseqlen)
  3381. return QDF_STATUS_E_PROTO;
  3382. qdf_mem_copy(mldmacaddr->bytes,
  3383. mlieseq + sizeof(struct wlan_ie_multilink),
  3384. QDF_MAC_ADDR_SIZE);
  3385. }
  3386. return QDF_STATUS_SUCCESS;
  3387. }
  3388. static QDF_STATUS
  3389. util_parse_rv_multi_link_ctrl(uint8_t *mlieseqpayload,
  3390. qdf_size_t mlieseqpayloadlen,
  3391. uint8_t **link_info,
  3392. qdf_size_t *link_info_len)
  3393. {
  3394. qdf_size_t parsed_payload_len;
  3395. uint16_t mlcontrol;
  3396. uint16_t presence_bm;
  3397. /* This helper returns the location(s) and length(s) of (sub)field(s)
  3398. * inferable after parsing the Multi Link element Control field. These
  3399. * location(s) and length(s) is/are in reference to the payload section
  3400. * of the Multi Link element (after defragmentation, if applicable).
  3401. * Here, the payload is the point after the element ID extension of the
  3402. * Multi Link element, and includes the payloads of all subsequent
  3403. * fragments (if any) but not the headers of those fragments.
  3404. *
  3405. * Currently, the helper returns the location and length of the Link
  3406. * Info field in the Multi Link element sequence. Other (sub)field(s)
  3407. * can be added later as required.
  3408. */
  3409. if (!mlieseqpayload) {
  3410. mlo_err("ML seq payload pointer is NULL");
  3411. return QDF_STATUS_E_NULL_VALUE;
  3412. }
  3413. if (!mlieseqpayloadlen) {
  3414. mlo_err("ML seq payload len is 0");
  3415. return QDF_STATUS_E_INVAL;
  3416. }
  3417. if (mlieseqpayloadlen < WLAN_ML_CTRL_SIZE) {
  3418. mlo_err_rl("ML seq payload len %zu < ML Control size %u",
  3419. mlieseqpayloadlen, WLAN_ML_CTRL_SIZE);
  3420. return QDF_STATUS_E_PROTO;
  3421. }
  3422. parsed_payload_len = 0;
  3423. qdf_mem_copy(&mlcontrol, mlieseqpayload, WLAN_ML_CTRL_SIZE);
  3424. mlcontrol = qdf_le16_to_cpu(mlcontrol);
  3425. parsed_payload_len += WLAN_ML_CTRL_SIZE;
  3426. presence_bm = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_PBM_IDX,
  3427. WLAN_ML_CTRL_PBM_BITS);
  3428. /* Check if MLD MAC address is present */
  3429. if (presence_bm & WLAN_ML_RV_CTRL_PBM_MLDMACADDR_P) {
  3430. if (mlieseqpayloadlen <
  3431. (parsed_payload_len +
  3432. QDF_MAC_ADDR_SIZE)) {
  3433. mlo_err_rl("ML seq payload len %zu insufficient for MLD ID size %u after parsed payload len %zu.",
  3434. mlieseqpayloadlen,
  3435. WLAN_ML_PRV_CINFO_MLDID_SIZE,
  3436. parsed_payload_len);
  3437. return QDF_STATUS_E_PROTO;
  3438. }
  3439. parsed_payload_len += QDF_MAC_ADDR_SIZE;
  3440. }
  3441. if (link_info_len) {
  3442. *link_info_len = mlieseqpayloadlen - parsed_payload_len;
  3443. mlo_debug("link_info_len:%zu, parsed_payload_len:%zu",
  3444. *link_info_len, parsed_payload_len);
  3445. }
  3446. if (mlieseqpayloadlen == parsed_payload_len) {
  3447. mlo_debug("No Link Info field present");
  3448. if (link_info)
  3449. *link_info = NULL;
  3450. return QDF_STATUS_SUCCESS;
  3451. }
  3452. if (link_info)
  3453. *link_info = mlieseqpayload + parsed_payload_len;
  3454. return QDF_STATUS_SUCCESS;
  3455. }
  3456. static QDF_STATUS
  3457. util_parse_rvmlie_perstaprofile_stactrl(uint8_t *subelempayload,
  3458. qdf_size_t subelempayloadlen,
  3459. uint8_t *linkid,
  3460. bool *is_macaddr_valid,
  3461. struct qdf_mac_addr *macaddr,
  3462. bool *is_delete_timer_valid,
  3463. uint16_t *delete_timer)
  3464. {
  3465. qdf_size_t parsed_payload_len = 0;
  3466. uint16_t stacontrol;
  3467. uint8_t completeprofile;
  3468. /* This helper returns the location(s) and where required, the length(s)
  3469. * of (sub)field(s) inferable after parsing the STA Control field in the
  3470. * per-STA profile subelement. These location(s) and length(s) is/are in
  3471. * reference to the payload section of the per-STA profile subelement
  3472. * (after defragmentation, if applicable). Here, the payload is the
  3473. * point after the subelement length in the subelement, and includes the
  3474. * payloads of all subsequent fragments (if any) but not the headers of
  3475. * those fragments.
  3476. *
  3477. * Currently, the helper returns the link ID, MAC address, Delete timer
  3478. * and STA profile. More (sub)fields can be added when required.
  3479. */
  3480. if (!subelempayload) {
  3481. mlo_err("Pointer to subelement payload is NULL");
  3482. return QDF_STATUS_E_NULL_VALUE;
  3483. }
  3484. if (!subelempayloadlen) {
  3485. mlo_err("Length of subelement payload is zero");
  3486. return QDF_STATUS_E_INVAL;
  3487. }
  3488. if (subelempayloadlen < WLAN_ML_RV_LINFO_PERSTAPROF_STACTRL_SIZE) {
  3489. mlo_err_rl("Subelement payload length %zu octets is smaller than STA control field of per-STA profile subelement %u octets",
  3490. subelempayloadlen,
  3491. WLAN_ML_RV_LINFO_PERSTAPROF_STACTRL_SIZE);
  3492. return QDF_STATUS_E_PROTO;
  3493. }
  3494. parsed_payload_len = 0;
  3495. qdf_mem_copy(&stacontrol,
  3496. subelempayload,
  3497. WLAN_ML_RV_LINFO_PERSTAPROF_STACTRL_SIZE);
  3498. stacontrol = qdf_le16_to_cpu(stacontrol);
  3499. parsed_payload_len += WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_SIZE;
  3500. if (linkid)
  3501. *linkid = QDF_GET_BITS(stacontrol,
  3502. WLAN_ML_RV_LINFO_PERSTAPROF_STACTRL_LINKID_IDX,
  3503. WLAN_ML_RV_LINFO_PERSTAPROF_STACTRL_LINKID_BITS);
  3504. /* Check if this a complete profile */
  3505. completeprofile = QDF_GET_BITS(stacontrol,
  3506. WLAN_ML_RV_LINFO_PERSTAPROF_STACTRL_CMPLTPROF_IDX,
  3507. WLAN_ML_RV_LINFO_PERSTAPROF_STACTRL_CMPLTPROF_BITS);
  3508. if (is_macaddr_valid)
  3509. *is_macaddr_valid = false;
  3510. /* Check STA MAC address present bit */
  3511. if (QDF_GET_BITS(stacontrol,
  3512. WLAN_ML_RV_LINFO_PERSTAPROF_STACTRL_MACADDRP_IDX,
  3513. WLAN_ML_RV_LINFO_PERSTAPROF_STACTRL_MACADDRP_BITS)) {
  3514. if (subelempayloadlen <
  3515. (parsed_payload_len + QDF_MAC_ADDR_SIZE)) {
  3516. mlo_err_rl("Length of subelement payload %zu octets not sufficient to contain MAC address of size %u octets after parsed payload length of %zu octets.",
  3517. subelempayloadlen, QDF_MAC_ADDR_SIZE,
  3518. parsed_payload_len);
  3519. return QDF_STATUS_E_PROTO;
  3520. }
  3521. if (macaddr) {
  3522. qdf_mem_copy(macaddr->bytes,
  3523. subelempayload + parsed_payload_len,
  3524. QDF_MAC_ADDR_SIZE);
  3525. mlo_nofl_debug("Copied MAC address: " QDF_MAC_ADDR_FMT,
  3526. subelempayload + parsed_payload_len);
  3527. if (is_macaddr_valid)
  3528. *is_macaddr_valid = true;
  3529. }
  3530. parsed_payload_len += QDF_MAC_ADDR_SIZE;
  3531. }
  3532. /* Check Delete timer present bit */
  3533. if (QDF_GET_BITS(stacontrol,
  3534. WLAN_ML_RV_LINFO_PERSTAPROF_STACTRL_DELTIMERP_IDX,
  3535. WLAN_ML_RV_LINFO_PERSTAPROF_STACTRL_DELTIMERP_BITS)) {
  3536. if (subelempayloadlen <
  3537. (parsed_payload_len +
  3538. WLAN_ML_RV_LINFO_PERSTAPROF_STAINFO_DELTIMER_SIZE)) {
  3539. mlo_err_rl("Length of subelement payload %zu octets not sufficient to contain Delete timer of size %u octets after parsed payload length of %zu octets.",
  3540. subelempayloadlen,
  3541. WLAN_ML_RV_LINFO_PERSTAPROF_STAINFO_DELTIMER_SIZE,
  3542. parsed_payload_len);
  3543. return QDF_STATUS_E_PROTO;
  3544. }
  3545. if (delete_timer) {
  3546. qdf_mem_copy(delete_timer,
  3547. subelempayload + parsed_payload_len,
  3548. WLAN_ML_RV_LINFO_PERSTAPROF_STAINFO_DELTIMER_SIZE);
  3549. if (is_delete_timer_valid)
  3550. *is_delete_timer_valid = true;
  3551. }
  3552. parsed_payload_len += WLAN_ML_RV_LINFO_PERSTAPROF_STAINFO_DELTIMER_SIZE;
  3553. }
  3554. return QDF_STATUS_SUCCESS;
  3555. }
  3556. static QDF_STATUS
  3557. util_parse_rv_info_from_linkinfo(uint8_t *linkinfo,
  3558. qdf_size_t linkinfo_len,
  3559. struct ml_rv_info *reconfig_info)
  3560. {
  3561. uint8_t linkid;
  3562. uint8_t *linkinfo_currpos;
  3563. qdf_size_t linkinfo_remlen;
  3564. bool is_subelemfragseq;
  3565. uint8_t subelemid;
  3566. qdf_size_t subelemseqtotallen;
  3567. qdf_size_t subelemseqpayloadlen;
  3568. qdf_size_t defragpayload_len;
  3569. QDF_STATUS ret;
  3570. struct qdf_mac_addr mac_addr;
  3571. bool is_macaddr_valid;
  3572. bool is_delete_timer_valid;
  3573. uint16_t delete_timer;
  3574. /* This helper function parses probe request info from the per-STA prof
  3575. * present (if any) in the Link Info field in the payload of a Multi
  3576. * Link element (after defragmentation if required). The caller should
  3577. * pass a copy of the payload so that inline defragmentation of
  3578. * subelements can be carried out if required. The subelement
  3579. * defragmentation (if applicable) in this Control Path helper is
  3580. * required for maintainability, accuracy and eliminating current and
  3581. * future per-field-access multi-level fragment boundary checks and
  3582. * adjustments, given the complex format of Multi Link elements. It is
  3583. * also most likely to be required mainly at the client side.
  3584. * Fragmentation is currently unlikely to be required for subelements
  3585. * in Reconfiguration variant Multi-Link elements, but it should be
  3586. * handled in order to be future ready.
  3587. */
  3588. if (!linkinfo) {
  3589. mlo_err("linkinfo is NULL");
  3590. return QDF_STATUS_E_NULL_VALUE;
  3591. }
  3592. if (!linkinfo_len) {
  3593. mlo_err("linkinfo_len is zero");
  3594. return QDF_STATUS_E_NULL_VALUE;
  3595. }
  3596. if (!reconfig_info) {
  3597. mlo_err("ML reconfig info is NULL");
  3598. return QDF_STATUS_E_NULL_VALUE;
  3599. }
  3600. reconfig_info->num_links = 0;
  3601. linkinfo_currpos = linkinfo;
  3602. linkinfo_remlen = linkinfo_len;
  3603. while (linkinfo_remlen) {
  3604. if (linkinfo_remlen < sizeof(struct subelem_header)) {
  3605. mlo_err_rl("Remaining length in link info %zu octets is smaller than subelement header length %zu octets",
  3606. linkinfo_remlen,
  3607. sizeof(struct subelem_header));
  3608. return QDF_STATUS_E_PROTO;
  3609. }
  3610. subelemid = linkinfo_currpos[ID_POS];
  3611. is_subelemfragseq = false;
  3612. subelemseqtotallen = 0;
  3613. subelemseqpayloadlen = 0;
  3614. ret = wlan_get_subelem_fragseq_info(WLAN_ML_LINFO_SUBELEMID_FRAGMENT,
  3615. linkinfo_currpos,
  3616. linkinfo_remlen,
  3617. &is_subelemfragseq,
  3618. &subelemseqtotallen,
  3619. &subelemseqpayloadlen);
  3620. if (QDF_IS_STATUS_ERROR(ret))
  3621. return ret;
  3622. if (qdf_unlikely(is_subelemfragseq)) {
  3623. if (!subelemseqpayloadlen) {
  3624. mlo_err_rl("Subelement fragment sequence payload is reported as 0, investigate");
  3625. return QDF_STATUS_E_FAILURE;
  3626. }
  3627. mlo_debug("Subelement fragment sequence found with payload len %zu",
  3628. subelemseqpayloadlen);
  3629. ret = wlan_defrag_subelem_fragseq(true,
  3630. WLAN_ML_LINFO_SUBELEMID_FRAGMENT,
  3631. linkinfo_currpos,
  3632. linkinfo_remlen,
  3633. NULL,
  3634. 0,
  3635. &defragpayload_len);
  3636. if (QDF_IS_STATUS_ERROR(ret))
  3637. return ret;
  3638. if (defragpayload_len != subelemseqpayloadlen) {
  3639. mlo_err_rl("Length of defragmented payload %zu octets is not equal to length of subelement fragment sequence payload %zu octets",
  3640. defragpayload_len,
  3641. subelemseqpayloadlen);
  3642. return QDF_STATUS_E_FAILURE;
  3643. }
  3644. /* Adjust linkinfo_remlen to reflect removal of all
  3645. * subelement headers except the header of the lead
  3646. * subelement.
  3647. */
  3648. linkinfo_remlen -= (subelemseqtotallen -
  3649. subelemseqpayloadlen -
  3650. sizeof(struct subelem_header));
  3651. } else {
  3652. if (linkinfo_remlen <
  3653. (sizeof(struct subelem_header) +
  3654. linkinfo_currpos[TAG_LEN_POS])) {
  3655. mlo_err_rl("Remaining length in link info %zu octets is smaller than total size of current subelement %zu octets",
  3656. linkinfo_remlen,
  3657. sizeof(struct subelem_header) +
  3658. linkinfo_currpos[TAG_LEN_POS]);
  3659. return QDF_STATUS_E_PROTO;
  3660. }
  3661. subelemseqpayloadlen = linkinfo_currpos[TAG_LEN_POS];
  3662. }
  3663. if (subelemid == WLAN_ML_LINFO_SUBELEMID_PERSTAPROFILE) {
  3664. is_macaddr_valid = false;
  3665. is_delete_timer_valid = false;
  3666. ret = util_parse_rvmlie_perstaprofile_stactrl(linkinfo_currpos +
  3667. sizeof(struct subelem_header),
  3668. subelemseqpayloadlen,
  3669. &linkid,
  3670. &is_macaddr_valid,
  3671. &mac_addr,
  3672. &is_delete_timer_valid,
  3673. &delete_timer);
  3674. if (QDF_IS_STATUS_ERROR(ret))
  3675. return ret;
  3676. reconfig_info->link_info[reconfig_info->num_links].link_id = linkid;
  3677. reconfig_info->link_info[reconfig_info->num_links].is_delete_timer_p = is_delete_timer_valid;
  3678. if (is_delete_timer_valid)
  3679. reconfig_info->link_info[reconfig_info->num_links].delete_timer = delete_timer;
  3680. else
  3681. mlo_warn_rl("Delete timer not found in STA Info field of per-STA profile with link ID %u",
  3682. linkid);
  3683. mlo_debug("Per-STA Profile Link ID: %u Delete timer present: %d Delete timer: %u",
  3684. reconfig_info->link_info[reconfig_info->num_links].link_id,
  3685. reconfig_info->link_info[reconfig_info->num_links].is_delete_timer_p,
  3686. reconfig_info->link_info[reconfig_info->num_links].delete_timer);
  3687. reconfig_info->num_links++;
  3688. }
  3689. linkinfo_remlen -= (sizeof(struct subelem_header) +
  3690. subelemseqpayloadlen);
  3691. linkinfo_currpos += (sizeof(struct subelem_header) +
  3692. subelemseqpayloadlen);
  3693. }
  3694. mlo_debug("Number of ML probe request links found=%u",
  3695. reconfig_info->num_links);
  3696. return QDF_STATUS_SUCCESS;
  3697. }
  3698. QDF_STATUS util_get_rvmlie_persta_link_info(uint8_t *mlieseq,
  3699. qdf_size_t mlieseqlen,
  3700. struct ml_rv_info *reconfig_info)
  3701. {
  3702. struct wlan_ie_multilink *mlie_fixed;
  3703. uint16_t mlcontrol;
  3704. enum wlan_ml_variant variant;
  3705. uint8_t *linkinfo;
  3706. qdf_size_t linkinfo_len;
  3707. struct ml_rv_info rinfo = {0};
  3708. qdf_size_t mlieseqpayloadlen;
  3709. uint8_t *mlieseqpayload_copy;
  3710. bool is_elemfragseq;
  3711. qdf_size_t defragpayload_len;
  3712. qdf_size_t tmplen;
  3713. QDF_STATUS ret;
  3714. if (!mlieseq) {
  3715. mlo_err("Pointer to Multi-Link element sequence is NULL");
  3716. return QDF_STATUS_E_NULL_VALUE;
  3717. }
  3718. if (!mlieseqlen) {
  3719. mlo_err("Length of Multi-Link element sequence is zero");
  3720. return QDF_STATUS_E_INVAL;
  3721. }
  3722. if (!reconfig_info) {
  3723. mlo_err("reconfig_info is NULL");
  3724. return QDF_STATUS_E_NULL_VALUE;
  3725. }
  3726. reconfig_info->num_links = 0;
  3727. if (mlieseqlen < sizeof(struct wlan_ie_multilink)) {
  3728. mlo_err_rl("Multi-Link element sequence length %zu octets is smaller than required for the fixed portion of Multi-Link element (%zu octets)",
  3729. mlieseqlen, sizeof(struct wlan_ie_multilink));
  3730. return QDF_STATUS_E_INVAL;
  3731. }
  3732. mlie_fixed = (struct wlan_ie_multilink *)mlieseq;
  3733. if (mlie_fixed->elem_id != WLAN_ELEMID_EXTN_ELEM ||
  3734. mlie_fixed->elem_id_ext != WLAN_EXTN_ELEMID_MULTI_LINK) {
  3735. mlo_err("The element is not a Multi-Link element");
  3736. return QDF_STATUS_E_INVAL;
  3737. }
  3738. mlcontrol = qdf_le16_to_cpu(mlie_fixed->mlcontrol);
  3739. variant = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_TYPE_IDX,
  3740. WLAN_ML_CTRL_TYPE_BITS);
  3741. if (variant != WLAN_ML_VARIANT_RECONFIG) {
  3742. mlo_err("The variant value %u does not correspond to Reconfig Variant value %u",
  3743. variant, WLAN_ML_VARIANT_RECONFIG);
  3744. return QDF_STATUS_E_INVAL;
  3745. }
  3746. mlieseqpayloadlen = 0;
  3747. tmplen = 0;
  3748. is_elemfragseq = false;
  3749. ret = wlan_get_elem_fragseq_info(mlieseq,
  3750. mlieseqlen,
  3751. &is_elemfragseq,
  3752. &tmplen,
  3753. &mlieseqpayloadlen);
  3754. if (QDF_IS_STATUS_ERROR(ret))
  3755. return ret;
  3756. if (qdf_unlikely(is_elemfragseq)) {
  3757. if (tmplen != mlieseqlen) {
  3758. mlo_err_rl("Mismatch in values of element fragment sequence total length. Val per frag info determination: %zu octets, val passed as arg: %zu octets",
  3759. tmplen, mlieseqlen);
  3760. return QDF_STATUS_E_INVAL;
  3761. }
  3762. if (!mlieseqpayloadlen) {
  3763. mlo_err_rl("Multi-Link element fragment sequence payload is reported as 0, investigate");
  3764. return QDF_STATUS_E_FAILURE;
  3765. }
  3766. mlo_debug("Multi-Link element fragment sequence found with payload len %zu",
  3767. mlieseqpayloadlen);
  3768. } else {
  3769. if (mlieseqlen > (sizeof(struct ie_header) + WLAN_MAX_IE_LEN)) {
  3770. mlo_err_rl("Expected presence of valid fragment sequence since Multi-Link element sequence length %zu octets is larger than frag threshold of %zu octets, however no valid fragment sequence found",
  3771. mlieseqlen,
  3772. sizeof(struct ie_header) + WLAN_MAX_IE_LEN);
  3773. return QDF_STATUS_E_FAILURE;
  3774. }
  3775. mlieseqpayloadlen = mlieseqlen - (sizeof(struct ie_header) + 1);
  3776. }
  3777. mlieseqpayload_copy = qdf_mem_malloc(mlieseqpayloadlen);
  3778. if (!mlieseqpayload_copy) {
  3779. mlo_err_rl("Could not allocate memory for Multi-Link element payload copy");
  3780. return QDF_STATUS_E_NOMEM;
  3781. }
  3782. if (qdf_unlikely(is_elemfragseq)) {
  3783. ret = wlan_defrag_elem_fragseq(false,
  3784. mlieseq,
  3785. mlieseqlen,
  3786. mlieseqpayload_copy,
  3787. mlieseqpayloadlen,
  3788. &defragpayload_len);
  3789. if (QDF_IS_STATUS_ERROR(ret)) {
  3790. qdf_mem_free(mlieseqpayload_copy);
  3791. return ret;
  3792. }
  3793. if (defragpayload_len != mlieseqpayloadlen) {
  3794. mlo_err_rl("Length of de-fragmented payload %zu octets is not equal to length of Multi-Link element fragment sequence payload %zu octets",
  3795. defragpayload_len, mlieseqpayloadlen);
  3796. qdf_mem_free(mlieseqpayload_copy);
  3797. return QDF_STATUS_E_FAILURE;
  3798. }
  3799. } else {
  3800. qdf_mem_copy(mlieseqpayload_copy,
  3801. mlieseq + sizeof(struct ie_header) + 1,
  3802. mlieseqpayloadlen);
  3803. }
  3804. linkinfo = NULL;
  3805. linkinfo_len = 0;
  3806. ret = util_parse_rv_multi_link_ctrl(mlieseqpayload_copy,
  3807. mlieseqpayloadlen,
  3808. &linkinfo,
  3809. &linkinfo_len);
  3810. if (QDF_IS_STATUS_ERROR(ret)) {
  3811. qdf_mem_free(mlieseqpayload_copy);
  3812. return ret;
  3813. }
  3814. /* In case Link Info is absent, the number of links will remain
  3815. * zero.
  3816. */
  3817. if (!linkinfo) {
  3818. qdf_mem_free(mlieseqpayload_copy);
  3819. return QDF_STATUS_SUCCESS;
  3820. }
  3821. ret = util_parse_rv_info_from_linkinfo(linkinfo, linkinfo_len, &rinfo);
  3822. if (QDF_IS_STATUS_ERROR(ret)) {
  3823. qdf_mem_free(mlieseqpayload_copy);
  3824. return ret;
  3825. }
  3826. qdf_mem_copy(reconfig_info, &rinfo, sizeof(*reconfig_info));
  3827. qdf_mem_free(mlieseqpayload_copy);
  3828. return QDF_STATUS_SUCCESS;
  3829. }
  3830. #endif
  3831. #ifdef WLAN_FEATURE_11BE
  3832. QDF_STATUS util_add_bw_ind(struct wlan_ie_bw_ind *bw_ind, uint8_t ccfs0,
  3833. uint8_t ccfs1, enum phy_ch_width ch_width,
  3834. uint16_t puncture_bitmap, int *bw_ind_len)
  3835. {
  3836. uint8_t bw_ind_width;
  3837. if (!bw_ind) {
  3838. mlo_err("Pointer to bandwidth indiaction element is NULL");
  3839. return QDF_STATUS_E_NULL_VALUE;
  3840. }
  3841. if (!bw_ind_len) {
  3842. mlo_err("Length of bandwidth indaication element is Zero");
  3843. return QDF_STATUS_E_INVAL;
  3844. }
  3845. switch (ch_width) {
  3846. case CH_WIDTH_20MHZ:
  3847. bw_ind_width = IEEE80211_11BEOP_CHWIDTH_20;
  3848. break;
  3849. case CH_WIDTH_40MHZ:
  3850. bw_ind_width = IEEE80211_11BEOP_CHWIDTH_40;
  3851. break;
  3852. case CH_WIDTH_80MHZ:
  3853. bw_ind_width = IEEE80211_11BEOP_CHWIDTH_80;
  3854. break;
  3855. case CH_WIDTH_160MHZ:
  3856. bw_ind_width = IEEE80211_11BEOP_CHWIDTH_160;
  3857. break;
  3858. case CH_WIDTH_320MHZ:
  3859. bw_ind_width = IEEE80211_11BEOP_CHWIDTH_320;
  3860. break;
  3861. default:
  3862. bw_ind_width = IEEE80211_11BEOP_CHWIDTH_20;
  3863. }
  3864. bw_ind->elem_id = WLAN_ELEMID_EXTN_ELEM;
  3865. *bw_ind_len = WLAN_BW_IND_IE_MAX_LEN;
  3866. bw_ind->elem_len = WLAN_BW_IND_IE_MAX_LEN - WLAN_IE_HDR_LEN;
  3867. bw_ind->elem_id_extn = WLAN_EXTN_ELEMID_BW_IND;
  3868. bw_ind->ccfs0 = ccfs0;
  3869. bw_ind->ccfs1 = ccfs1;
  3870. QDF_SET_BITS(bw_ind->control, BW_IND_CHAN_WIDTH_IDX,
  3871. BW_IND_CHAN_WIDTH_BITS, bw_ind_width);
  3872. if (puncture_bitmap) {
  3873. bw_ind->disabled_sub_chan_bitmap[0] =
  3874. QDF_GET_BITS(puncture_bitmap, 0, 8);
  3875. bw_ind->disabled_sub_chan_bitmap[1] =
  3876. QDF_GET_BITS(puncture_bitmap, 8, 8);
  3877. QDF_SET_BITS(bw_ind->bw_ind_param,
  3878. BW_IND_PARAM_DISABLED_SC_BITMAP_PRESENT_IDX,
  3879. BW_IND_PARAM_DISABLED_SC_BITMAP_PRESENT_BITS, 1);
  3880. } else {
  3881. QDF_SET_BITS(bw_ind->bw_ind_param,
  3882. BW_IND_PARAM_DISABLED_SC_BITMAP_PRESENT_IDX,
  3883. BW_IND_PARAM_DISABLED_SC_BITMAP_PRESENT_BITS, 0);
  3884. bw_ind->elem_len -=
  3885. QDF_ARRAY_SIZE(bw_ind->disabled_sub_chan_bitmap);
  3886. *bw_ind_len -=
  3887. QDF_ARRAY_SIZE(bw_ind->disabled_sub_chan_bitmap);
  3888. }
  3889. return QDF_STATUS_SUCCESS;
  3890. }
  3891. QDF_STATUS util_parse_bw_ind(struct wlan_ie_bw_ind *bw_ind, uint8_t *ccfs0,
  3892. uint8_t *ccfs1, enum phy_ch_width *ch_width,
  3893. uint16_t *puncture_bitmap)
  3894. {
  3895. uint8_t bw_ind_width;
  3896. if (!bw_ind) {
  3897. mlo_err("Pointer to bandwidth indiaction element is NULL");
  3898. return QDF_STATUS_E_NULL_VALUE;
  3899. }
  3900. *ccfs0 = bw_ind->ccfs0;
  3901. *ccfs1 = bw_ind->ccfs1;
  3902. bw_ind_width = QDF_GET_BITS(bw_ind->control, BW_IND_CHAN_WIDTH_IDX,
  3903. BW_IND_CHAN_WIDTH_BITS);
  3904. switch (bw_ind_width) {
  3905. case IEEE80211_11BEOP_CHWIDTH_20:
  3906. *ch_width = CH_WIDTH_20MHZ;
  3907. break;
  3908. case IEEE80211_11BEOP_CHWIDTH_40:
  3909. *ch_width = CH_WIDTH_40MHZ;
  3910. break;
  3911. case IEEE80211_11BEOP_CHWIDTH_80:
  3912. *ch_width = CH_WIDTH_80MHZ;
  3913. break;
  3914. case IEEE80211_11BEOP_CHWIDTH_160:
  3915. *ch_width = CH_WIDTH_160MHZ;
  3916. break;
  3917. case IEEE80211_11BEOP_CHWIDTH_320:
  3918. *ch_width = CH_WIDTH_320MHZ;
  3919. break;
  3920. default:
  3921. *ch_width = CH_WIDTH_20MHZ;
  3922. }
  3923. if (QDF_GET_BITS(bw_ind->bw_ind_param,
  3924. BW_IND_PARAM_DISABLED_SC_BITMAP_PRESENT_IDX,
  3925. BW_IND_PARAM_DISABLED_SC_BITMAP_PRESENT_BITS)) {
  3926. QDF_SET_BITS(*puncture_bitmap, 0, 8,
  3927. bw_ind->disabled_sub_chan_bitmap[0]);
  3928. QDF_SET_BITS(*puncture_bitmap, 8, 8,
  3929. bw_ind->disabled_sub_chan_bitmap[1]);
  3930. } else {
  3931. *puncture_bitmap = 0;
  3932. }
  3933. return QDF_STATUS_SUCCESS;
  3934. }
  3935. #endif