utils_mlo.c 86 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774
  1. /*
  2. * Copyright (c) 2021, The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2021-2022 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_BV_CINFO_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_BV_CINFO_BSSPARAMCHNGCNT_SIZE,
  140. parsed_payload_len);
  141. return QDF_STATUS_E_PROTO;
  142. }
  143. parsed_payload_len += WLAN_ML_BV_CINFO_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_MLDCAP_P) {
  173. if (mlieseqpayloadlen <
  174. (parsed_payload_len +
  175. WLAN_ML_BV_CINFO_MLDCAP_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_MLDCAP_SIZE,
  179. parsed_payload_len);
  180. return QDF_STATUS_E_PROTO;
  181. }
  182. parsed_payload_len += WLAN_ML_BV_CINFO_MLDCAP_SIZE;
  183. }
  184. exp_cinfo_len = parsed_payload_len - WLAN_ML_CTRL_SIZE;
  185. if (cinfo_len != exp_cinfo_len) {
  186. mlo_err_rl("ML seq common info len %u doesn't match with expected common info len %u",
  187. cinfo_len, exp_cinfo_len);
  188. return QDF_STATUS_E_PROTO;
  189. }
  190. if (link_info_len) {
  191. *link_info_len = mlieseqpayloadlen - parsed_payload_len;
  192. mlo_debug("link_info_len:%zu, parsed_payload_len:%zu",
  193. *link_info_len, parsed_payload_len);
  194. }
  195. if (mlieseqpayloadlen == parsed_payload_len) {
  196. mlo_debug("No Link Info field present");
  197. if (link_info)
  198. *link_info = NULL;
  199. return QDF_STATUS_SUCCESS;
  200. }
  201. if (link_info)
  202. *link_info = mlieseqpayload + parsed_payload_len;
  203. return QDF_STATUS_SUCCESS;
  204. }
  205. static QDF_STATUS
  206. util_parse_bvmlie_perstaprofile_stactrl(uint8_t *subelempayload,
  207. qdf_size_t subelempayloadlen,
  208. uint8_t *linkid,
  209. bool *is_macaddr_valid,
  210. struct qdf_mac_addr *macaddr,
  211. bool is_staprof_reqd,
  212. uint8_t **staprof,
  213. qdf_size_t *staprof_len)
  214. {
  215. qdf_size_t parsed_payload_len = 0;
  216. uint16_t stacontrol;
  217. uint8_t completeprofile;
  218. uint8_t nstrlppresent;
  219. enum wlan_ml_bv_linfo_perstaprof_stactrl_nstrbmsz nstrbmsz;
  220. /* This helper returns the location(s) and where required, the length(s)
  221. * of (sub)field(s) inferable after parsing the STA Control field in the
  222. * per-STA profile subelement. These location(s) and length(s) is/are in
  223. * reference to the payload section of the per-STA profile subelement
  224. * (after defragmentation, if applicable). Here, the payload is the
  225. * point after the subelement length in the subelement, and includes the
  226. * payloads of all subsequent fragments (if any) but not the headers of
  227. * those fragments.
  228. *
  229. * Currently, the helper returns the link ID, MAC address, and STA
  230. * profile. More (sub)fields can be added when required.
  231. */
  232. if (!subelempayload) {
  233. mlo_err("Pointer to subelement payload is NULL");
  234. return QDF_STATUS_E_NULL_VALUE;
  235. }
  236. if (!subelempayloadlen) {
  237. mlo_err("Length of subelement payload is zero");
  238. return QDF_STATUS_E_INVAL;
  239. }
  240. if (subelempayloadlen < WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_SIZE) {
  241. mlo_err_rl("Subelement payload length %zu octets is smaller than STA control field of per-STA profile subelement %u octets",
  242. subelempayloadlen,
  243. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_SIZE);
  244. return QDF_STATUS_E_PROTO;
  245. }
  246. parsed_payload_len = 0;
  247. qdf_mem_copy(&stacontrol,
  248. subelempayload,
  249. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_SIZE);
  250. stacontrol = le16toh(stacontrol);
  251. parsed_payload_len += WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_SIZE;
  252. if (linkid) {
  253. *linkid = QDF_GET_BITS(stacontrol,
  254. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_LINKID_IDX,
  255. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_LINKID_BITS);
  256. }
  257. /* Check if this a complete profile */
  258. completeprofile = QDF_GET_BITS(stacontrol,
  259. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_CMPLTPROF_IDX,
  260. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_CMPLTPROF_BITS);
  261. /* Check STA Info Length */
  262. if (subelempayloadlen <
  263. parsed_payload_len + WLAN_ML_BV_LINFO_PERSTAPROF_STAINFO_LENGTH_SIZE) {
  264. 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.",
  265. subelempayloadlen,
  266. WLAN_ML_BV_LINFO_PERSTAPROF_STAINFO_LENGTH_SIZE,
  267. parsed_payload_len);
  268. return QDF_STATUS_E_PROTO;
  269. }
  270. parsed_payload_len += WLAN_ML_BV_LINFO_PERSTAPROF_STAINFO_LENGTH_SIZE;
  271. if (is_macaddr_valid)
  272. *is_macaddr_valid = false;
  273. /* Check STA MAC address present bit */
  274. if (QDF_GET_BITS(stacontrol,
  275. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_MACADDRP_IDX,
  276. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_MACADDRP_BITS)) {
  277. if (subelempayloadlen <
  278. (parsed_payload_len + QDF_MAC_ADDR_SIZE)) {
  279. 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.",
  280. subelempayloadlen,
  281. QDF_MAC_ADDR_SIZE,
  282. parsed_payload_len);
  283. return QDF_STATUS_E_PROTO;
  284. }
  285. if (macaddr) {
  286. qdf_mem_copy(macaddr->bytes,
  287. subelempayload + parsed_payload_len,
  288. QDF_MAC_ADDR_SIZE);
  289. mlo_nofl_debug("Copied MAC address: " QDF_MAC_ADDR_FMT,
  290. subelempayload + parsed_payload_len);
  291. if (is_macaddr_valid)
  292. *is_macaddr_valid = true;
  293. }
  294. parsed_payload_len += QDF_MAC_ADDR_SIZE;
  295. }
  296. /* Check Beacon Interval present bit */
  297. if (QDF_GET_BITS(stacontrol,
  298. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_BCNINTP_IDX,
  299. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_BCNINTP_BITS)) {
  300. if (subelempayloadlen <
  301. (parsed_payload_len +
  302. WLAN_BEACONINTERVAL_LEN)) {
  303. 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.",
  304. subelempayloadlen,
  305. WLAN_BEACONINTERVAL_LEN,
  306. parsed_payload_len);
  307. return QDF_STATUS_E_PROTO;
  308. }
  309. parsed_payload_len += WLAN_BEACONINTERVAL_LEN;
  310. }
  311. /* Check DTIM Info present bit */
  312. if (QDF_GET_BITS(stacontrol,
  313. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_DTIMINFOP_IDX,
  314. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_DTIMINFOP_BITS)) {
  315. if (subelempayloadlen <
  316. (parsed_payload_len +
  317. sizeof(struct wlan_ml_bv_linfo_perstaprof_stainfo_dtiminfo))) {
  318. 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.",
  319. subelempayloadlen,
  320. sizeof(struct wlan_ml_bv_linfo_perstaprof_stainfo_dtiminfo),
  321. parsed_payload_len);
  322. return QDF_STATUS_E_PROTO;
  323. }
  324. parsed_payload_len +=
  325. sizeof(struct wlan_ml_bv_linfo_perstaprof_stainfo_dtiminfo);
  326. }
  327. /* Check NTSR Link pair present bit */
  328. nstrlppresent =
  329. QDF_GET_BITS(stacontrol,
  330. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_NSTRLINKPRP_IDX,
  331. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_NSTRLINKPRP_BITS);
  332. if (completeprofile && nstrlppresent) {
  333. /* Check NTSR Bitmap Size bit */
  334. nstrbmsz =
  335. QDF_GET_BITS(stacontrol,
  336. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_NSTRBMSZ_IDX,
  337. WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_NSTRBMSZ_BITS);
  338. if (nstrbmsz == WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_NSTRBMSZ_1_OCTET) {
  339. if (subelempayloadlen <
  340. (parsed_payload_len + 1)) {
  341. 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.",
  342. subelempayloadlen,
  343. parsed_payload_len);
  344. return QDF_STATUS_E_PROTO;
  345. }
  346. parsed_payload_len += 1;
  347. } else if (nstrbmsz == WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_NSTRBMSZ_2_OCTETS) {
  348. if (subelempayloadlen <
  349. (parsed_payload_len + 2)) {
  350. 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.",
  351. subelempayloadlen,
  352. parsed_payload_len);
  353. return QDF_STATUS_E_PROTO;
  354. }
  355. parsed_payload_len += 2;
  356. } else {
  357. /* Though an invalid value cannot occur if only 1 bit is
  358. * used, we check for it in a generic manner in case the
  359. * number of bits is increased in the future.
  360. */
  361. mlo_err_rl("Invalid NSTR Bitmap size %u", nstrbmsz);
  362. return QDF_STATUS_E_PROTO;
  363. }
  364. }
  365. /* Note: Some implementation versions of hostapd/wpa_supplicant may
  366. * provide a per-STA profile without STA profile. Let the caller
  367. * indicate whether a STA profile is required to be found. This may be
  368. * revisited as upstreaming progresses.
  369. */
  370. if (!is_staprof_reqd)
  371. return QDF_STATUS_SUCCESS;
  372. if (subelempayloadlen == parsed_payload_len) {
  373. mlo_err_rl("Subelement payload length %zu == parsed payload length %zu. Unable to get STA profile.",
  374. subelempayloadlen,
  375. parsed_payload_len);
  376. return QDF_STATUS_E_PROTO;
  377. }
  378. if (staprof_len)
  379. *staprof_len = subelempayloadlen - parsed_payload_len;
  380. if (staprof)
  381. *staprof = subelempayload + parsed_payload_len;
  382. return QDF_STATUS_SUCCESS;
  383. }
  384. static
  385. uint8_t *util_get_successorfrag(uint8_t *currie, uint8_t *frame, qdf_size_t len)
  386. {
  387. uint8_t *nextie;
  388. if (!currie || !frame || !len)
  389. return NULL;
  390. if ((currie + MIN_IE_LEN) > (frame + len))
  391. return NULL;
  392. /* Check whether there is sufficient space in the frame for the current
  393. * IE, plus at least another MIN_IE_LEN bytes for the IE header of a
  394. * fragment (if present) that would come just after the current IE.
  395. */
  396. if ((currie + MIN_IE_LEN + currie[TAG_LEN_POS] + MIN_IE_LEN) >
  397. (frame + len))
  398. return NULL;
  399. nextie = currie + currie[TAG_LEN_POS] + MIN_IE_LEN;
  400. if (nextie[ID_POS] != WLAN_ELEMID_FRAGMENT)
  401. return NULL;
  402. return nextie;
  403. }
  404. static
  405. QDF_STATUS util_parse_partner_info_from_linkinfo(uint8_t *linkinfo,
  406. qdf_size_t linkinfo_len,
  407. struct mlo_partner_info *partner_info)
  408. {
  409. uint8_t linkid;
  410. struct qdf_mac_addr macaddr;
  411. bool is_macaddr_valid;
  412. uint8_t *linkinfo_currpos;
  413. qdf_size_t linkinfo_remlen;
  414. bool is_subelemfragseq;
  415. uint8_t subelemid;
  416. qdf_size_t subelemseqtotallen;
  417. qdf_size_t subelemseqpayloadlen;
  418. qdf_size_t defragpayload_len;
  419. QDF_STATUS ret;
  420. /* This helper function parses partner info from the per-STA profiles
  421. * present (if any) in the Link Info field in the payload of a Multi
  422. * Link element (after defragmentation if required). The caller should
  423. * pass a copy of the payload so that inline defragmentation of
  424. * subelements can be carried out if required. The subelement
  425. * defragmentation (if applicable) in this Control Path helper is
  426. * required for maintainability, accuracy and eliminating current and
  427. * future per-field-access multi-level fragment boundary checks and
  428. * adjustments, given the complex format of Multi Link elements. It is
  429. * also most likely to be required mainly at the client side.
  430. */
  431. if (!linkinfo) {
  432. mlo_err("linkinfo is NULL");
  433. return QDF_STATUS_E_NULL_VALUE;
  434. }
  435. if (!linkinfo_len) {
  436. mlo_err("linkinfo_len is zero");
  437. return QDF_STATUS_E_NULL_VALUE;
  438. }
  439. if (!partner_info) {
  440. mlo_err("ML partner info is NULL");
  441. return QDF_STATUS_E_NULL_VALUE;
  442. }
  443. partner_info->num_partner_links = 0;
  444. linkinfo_currpos = linkinfo;
  445. linkinfo_remlen = linkinfo_len;
  446. while (linkinfo_remlen) {
  447. if (linkinfo_remlen < sizeof(struct subelem_header)) {
  448. mlo_err_rl("Remaining length in link info %zu octets is smaller than subelement header length %zu octets",
  449. linkinfo_remlen,
  450. sizeof(struct subelem_header));
  451. return QDF_STATUS_E_PROTO;
  452. }
  453. subelemid = linkinfo_currpos[ID_POS];
  454. is_subelemfragseq = false;
  455. subelemseqtotallen = 0;
  456. subelemseqpayloadlen = 0;
  457. ret = wlan_get_subelem_fragseq_info(WLAN_ML_BV_LINFO_SUBELEMID_FRAGMENT,
  458. linkinfo_currpos,
  459. linkinfo_remlen,
  460. &is_subelemfragseq,
  461. &subelemseqtotallen,
  462. &subelemseqpayloadlen);
  463. if (QDF_IS_STATUS_ERROR(ret))
  464. return ret;
  465. if (is_subelemfragseq) {
  466. if (!subelemseqpayloadlen) {
  467. mlo_err_rl("Subelement fragment sequence payload is reported as 0, investigate");
  468. return QDF_STATUS_E_FAILURE;
  469. }
  470. mlo_debug("Subelement fragment sequence found with payload len %zu",
  471. subelemseqpayloadlen);
  472. ret = wlan_defrag_subelem_fragseq(true,
  473. WLAN_ML_BV_LINFO_SUBELEMID_FRAGMENT,
  474. linkinfo_currpos,
  475. linkinfo_remlen,
  476. NULL,
  477. 0,
  478. &defragpayload_len);
  479. if (QDF_IS_STATUS_ERROR(ret))
  480. return ret;
  481. if (defragpayload_len != subelemseqpayloadlen) {
  482. mlo_err_rl("Length of defragmented payload %zu octets is not equal to length of subelement fragment sequence payload %zu octets",
  483. defragpayload_len,
  484. subelemseqpayloadlen);
  485. return QDF_STATUS_E_FAILURE;
  486. }
  487. /* Adjust linkinfo_remlen to reflect removal of all
  488. * subelement headers except the header of the lead
  489. * subelement.
  490. */
  491. linkinfo_remlen -= (subelemseqtotallen -
  492. subelemseqpayloadlen -
  493. sizeof(struct subelem_header));
  494. } else {
  495. if (linkinfo_remlen <
  496. (sizeof(struct subelem_header) +
  497. linkinfo_currpos[TAG_LEN_POS])) {
  498. mlo_err_rl("Remaining length in link info %zu octets is smaller than total size of current subelement %zu octets",
  499. linkinfo_remlen,
  500. sizeof(struct subelem_header) +
  501. linkinfo_currpos[TAG_LEN_POS]);
  502. return QDF_STATUS_E_PROTO;
  503. }
  504. subelemseqpayloadlen = linkinfo_currpos[TAG_LEN_POS];
  505. }
  506. if (subelemid == WLAN_ML_BV_LINFO_SUBELEMID_PERSTAPROFILE) {
  507. is_macaddr_valid = false;
  508. ret = util_parse_bvmlie_perstaprofile_stactrl(linkinfo_currpos +
  509. sizeof(struct subelem_header),
  510. subelemseqpayloadlen,
  511. &linkid,
  512. &is_macaddr_valid,
  513. &macaddr,
  514. false,
  515. NULL,
  516. NULL);
  517. if (QDF_IS_STATUS_ERROR(ret)) {
  518. return ret;
  519. }
  520. if (is_macaddr_valid) {
  521. if (partner_info->num_partner_links >=
  522. QDF_ARRAY_SIZE(partner_info->partner_link_info)) {
  523. mlo_err_rl("Insufficient size %zu of array for partner link info",
  524. QDF_ARRAY_SIZE(partner_info->partner_link_info));
  525. return QDF_STATUS_E_NOMEM;
  526. }
  527. partner_info->partner_link_info[partner_info->num_partner_links].link_id =
  528. linkid;
  529. qdf_mem_copy(&partner_info->partner_link_info[partner_info->num_partner_links].link_addr,
  530. &macaddr,
  531. sizeof(partner_info->partner_link_info[partner_info->num_partner_links].link_addr));
  532. partner_info->num_partner_links++;
  533. } else {
  534. mlo_warn_rl("MAC address not found in STA Info field of per-STA profile with link ID %u",
  535. linkid);
  536. }
  537. }
  538. linkinfo_remlen -= (sizeof(struct subelem_header) +
  539. subelemseqpayloadlen);
  540. linkinfo_currpos += (sizeof(struct subelem_header) +
  541. subelemseqpayloadlen);
  542. }
  543. mlo_debug("Number of ML partner links found=%u",
  544. partner_info->num_partner_links);
  545. return QDF_STATUS_SUCCESS;
  546. }
  547. static
  548. QDF_STATUS util_get_noninheritlists(uint8_t *buff, qdf_size_t buff_len,
  549. uint8_t **ninherit_elemlist,
  550. qdf_size_t *ninherit_elemlist_len,
  551. uint8_t **ninherit_elemextlist,
  552. qdf_size_t *ninherit_elemextlist_len)
  553. {
  554. uint8_t *ninherit_ie;
  555. qdf_size_t unparsed_len;
  556. /* Note: This funtionality provided by this helper may be combined with
  557. * other, older non-inheritance parsing helper functionality and exposed
  558. * as a common API as part of future efforts once the older
  559. * functionality can be made generic.
  560. */
  561. if (!buff) {
  562. mlo_err("Pointer to buffer for IEs is NULL");
  563. return QDF_STATUS_E_NULL_VALUE;
  564. }
  565. if (!buff_len) {
  566. mlo_err("IE buffer length is zero");
  567. return QDF_STATUS_E_INVAL;
  568. }
  569. if (!ninherit_elemlist) {
  570. mlo_err("Pointer to Non-Inheritance element ID list array is NULL");
  571. return QDF_STATUS_E_NULL_VALUE;
  572. }
  573. if (!ninherit_elemlist_len) {
  574. mlo_err("Pointer to Non-Inheritance element ID list array length is NULL");
  575. return QDF_STATUS_E_NULL_VALUE;
  576. }
  577. if (!ninherit_elemextlist) {
  578. mlo_err("Pointer to Non-Inheritance element ID extension list array is NULL");
  579. return QDF_STATUS_E_NULL_VALUE;
  580. }
  581. if (!ninherit_elemextlist_len) {
  582. mlo_err("Pointer to Non-Inheritance element ID extension list array length is NULL");
  583. return QDF_STATUS_E_NULL_VALUE;
  584. }
  585. ninherit_ie = NULL;
  586. *ninherit_elemlist_len = 0;
  587. *ninherit_elemlist = NULL;
  588. *ninherit_elemextlist_len = 0;
  589. *ninherit_elemextlist = NULL;
  590. ninherit_ie =
  591. (uint8_t *)util_find_extn_eid(WLAN_ELEMID_EXTN_ELEM,
  592. WLAN_EXTN_ELEMID_NONINHERITANCE,
  593. buff,
  594. buff_len);
  595. if (ninherit_ie) {
  596. if ((ninherit_ie + TAG_LEN_POS) > (buff + buff_len - 1)) {
  597. mlo_err_rl("Position of length field of Non-Inheritance element would exceed IE buffer boundary");
  598. return QDF_STATUS_E_PROTO;
  599. }
  600. if ((ninherit_ie + ninherit_ie[TAG_LEN_POS] + MIN_IE_LEN) >
  601. (buff + buff_len)) {
  602. mlo_err_rl("Non-Inheritance element with total length %u would exceed IE buffer boundary",
  603. ninherit_ie[TAG_LEN_POS] + MIN_IE_LEN);
  604. return QDF_STATUS_E_PROTO;
  605. }
  606. if ((ninherit_ie[TAG_LEN_POS] + MIN_IE_LEN) <
  607. MIN_NONINHERITANCEELEM_LEN) {
  608. mlo_err_rl("Non-Inheritance element size %u is smaller than the minimum required %u",
  609. ninherit_ie[TAG_LEN_POS] + MIN_IE_LEN,
  610. MIN_NONINHERITANCEELEM_LEN);
  611. return QDF_STATUS_E_PROTO;
  612. }
  613. /* Track the number of unparsed octets, excluding the IE header.
  614. */
  615. unparsed_len = ninherit_ie[TAG_LEN_POS];
  616. /* Mark the element ID extension as parsed */
  617. unparsed_len--;
  618. *ninherit_elemlist_len = ninherit_ie[ELEM_ID_LIST_LEN_POS];
  619. unparsed_len--;
  620. /* While checking if the Non-Inheritance element ID list length
  621. * exceeds the remaining unparsed IE space, we factor in one
  622. * octet for the element extension ID list length and subtract
  623. * this from the unparsed IE space.
  624. */
  625. if (*ninherit_elemlist_len > (unparsed_len - 1)) {
  626. 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",
  627. *ninherit_elemlist_len, unparsed_len - 1);
  628. return QDF_STATUS_E_PROTO;
  629. }
  630. if (*ninherit_elemlist_len != 0) {
  631. *ninherit_elemlist = ninherit_ie + ELEM_ID_LIST_POS;
  632. unparsed_len -= *ninherit_elemlist_len;
  633. }
  634. *ninherit_elemextlist_len =
  635. ninherit_ie[ELEM_ID_LIST_LEN_POS + *ninherit_elemlist_len + 1];
  636. unparsed_len--;
  637. if (*ninherit_elemextlist_len > unparsed_len) {
  638. mlo_err_rl("Non-Inheritance element ID extension list length %zu exceeds remaining unparsed IE space %zu",
  639. *ninherit_elemextlist_len, unparsed_len);
  640. return QDF_STATUS_E_PROTO;
  641. }
  642. if (*ninherit_elemextlist_len != 0) {
  643. *ninherit_elemextlist = ninherit_ie +
  644. ELEM_ID_LIST_LEN_POS + (*ninherit_elemlist_len)
  645. + 2;
  646. unparsed_len -= *ninherit_elemextlist_len;
  647. }
  648. if (unparsed_len > 0) {
  649. mlo_err_rl("Unparsed length is %zu, expected 0",
  650. unparsed_len);
  651. return QDF_STATUS_E_PROTO;
  652. }
  653. }
  654. /* If Non-Inheritance element is not found, we still return success,
  655. * with the list lengths kept at zero.
  656. */
  657. mlo_debug("Non-Inheritance element ID list array length=%zu",
  658. *ninherit_elemlist_len);
  659. mlo_debug("Non-Inheritance element ID extension list array length=%zu",
  660. *ninherit_elemextlist_len);
  661. return QDF_STATUS_SUCCESS;
  662. }
  663. static
  664. QDF_STATUS util_eval_ie_in_noninheritlist(uint8_t *ie, qdf_size_t total_ie_len,
  665. uint8_t *ninherit_elemlist,
  666. qdf_size_t ninherit_elemlist_len,
  667. uint8_t *ninherit_elemextlist,
  668. qdf_size_t ninherit_elemextlist_len,
  669. bool *is_in_noninheritlist)
  670. {
  671. int i;
  672. /* Evaluate whether the given IE is in the given Non-Inheritance element
  673. * ID list or Non-Inheritance element ID extension list, and update the
  674. * result into is_in_noninheritlist. If any list is empty, then the IE
  675. * is considered to not be present in that list. Both lists can be
  676. * empty.
  677. *
  678. * If QDF_STATUS_SUCCESS is returned, it means that the evaluation is
  679. * successful, and that is_in_noninheritlist contains a valid value
  680. * (which could be true or false). If a QDF_STATUS error value is
  681. * returned, the value in is_in_noninheritlist is invalid and the caller
  682. * should ignore it.
  683. */
  684. /* Note: The funtionality provided by this helper may be combined with
  685. * other, older non-inheritance parsing helper functionality and exposed
  686. * as a common API as part of future efforts once the older
  687. * functionality can be made generic.
  688. */
  689. /* Except for is_in_noninheritlist and ie, other pointer arguments are
  690. * permitted to be NULL if they are inapplicable. If they are
  691. * applicable, they will be checked to ensure they are not NULL.
  692. */
  693. if (!is_in_noninheritlist) {
  694. mlo_err("NULL pointer to flag that indicates if element is in a Non-Inheritance list");
  695. return QDF_STATUS_E_NULL_VALUE;
  696. }
  697. /* If ninherit_elemlist_len and ninherit_elemextlist_len are both zero
  698. * as checked soon in this function, we won't be accessing the IE.
  699. * However, we still check right-away if the pointer to the IE is
  700. * non-NULL and whether the total IE length is sane enough to access the
  701. * element ID and if applicable, the element ID extension, since it
  702. * doesn't make sense to set the flag in is_in_noninheritlist for a NULL
  703. * IE pointer or an IE whose total length is not sane enough to
  704. * distinguish the identity of the IE.
  705. */
  706. if (!ie) {
  707. mlo_err("NULL pointer to IE");
  708. return QDF_STATUS_E_NULL_VALUE;
  709. }
  710. if (total_ie_len < (ID_POS + 1)) {
  711. mlo_err("Total IE length %zu is smaller than minimum required to access element ID %u",
  712. total_ie_len, ID_POS + 1);
  713. return QDF_STATUS_E_INVAL;
  714. }
  715. if ((ie[ID_POS] == WLAN_ELEMID_EXTN_ELEM) &&
  716. (total_ie_len < (IDEXT_POS + 1))) {
  717. mlo_err("Total IE length %zu is smaller than minimum required to access element ID extension %u",
  718. total_ie_len, IDEXT_POS + 1);
  719. return QDF_STATUS_E_INVAL;
  720. }
  721. *is_in_noninheritlist = false;
  722. /* If both the Non-Inheritance element list and Non-Inheritance element
  723. * ID extension list are empty, then return success since we can
  724. * conclude immediately that the given element does not occur in any
  725. * Non-Inheritance list. The is_in_noninheritlist remains set to false
  726. * as required.
  727. */
  728. if (!ninherit_elemlist_len && !ninherit_elemextlist_len)
  729. return QDF_STATUS_SUCCESS;
  730. if (ie[ID_POS] != WLAN_ELEMID_EXTN_ELEM) {
  731. if (!ninherit_elemlist_len)
  732. return QDF_STATUS_SUCCESS;
  733. if (!ninherit_elemlist) {
  734. mlo_err("NULL pointer to Non-Inheritance element ID list though length of element ID list is %zu",
  735. ninherit_elemlist_len);
  736. return QDF_STATUS_E_NULL_VALUE;
  737. }
  738. for (i = 0; i < ninherit_elemlist_len; i++) {
  739. if (ie[ID_POS] == ninherit_elemlist[i]) {
  740. *is_in_noninheritlist = true;
  741. return QDF_STATUS_SUCCESS;
  742. }
  743. }
  744. } else {
  745. if (!ninherit_elemextlist_len)
  746. return QDF_STATUS_SUCCESS;
  747. if (!ninherit_elemextlist) {
  748. mlo_err("NULL pointer to Non-Inheritance element ID extension list though length of element ID extension list is %zu",
  749. ninherit_elemextlist_len);
  750. return QDF_STATUS_E_NULL_VALUE;
  751. }
  752. for (i = 0; i < ninherit_elemextlist_len; i++) {
  753. if (ie[IDEXT_POS] == ninherit_elemextlist[i]) {
  754. *is_in_noninheritlist = true;
  755. return QDF_STATUS_SUCCESS;
  756. }
  757. }
  758. }
  759. return QDF_STATUS_SUCCESS;
  760. }
  761. static inline
  762. QDF_STATUS util_validate_reportingsta_ie(const uint8_t *reportingsta_ie,
  763. const uint8_t *frame_iesection,
  764. const qdf_size_t frame_iesection_len)
  765. {
  766. qdf_size_t reportingsta_ie_size;
  767. if (!reportingsta_ie) {
  768. mlo_err("Pointer to reporting STA IE is NULL");
  769. return QDF_STATUS_E_NULL_VALUE;
  770. }
  771. if (!frame_iesection) {
  772. mlo_err("Pointer to start of IE section in reporting frame is NULL");
  773. return QDF_STATUS_E_NULL_VALUE;
  774. }
  775. if (!frame_iesection_len) {
  776. mlo_err("Length of IE section in reporting frame is zero");
  777. return QDF_STATUS_E_INVAL;
  778. }
  779. if ((reportingsta_ie + ID_POS) > (frame_iesection +
  780. frame_iesection_len - 1)) {
  781. mlo_err_rl("Position of element ID field of element for reporting STA would exceed frame IE section boundary");
  782. return QDF_STATUS_E_PROTO;
  783. }
  784. if ((reportingsta_ie + TAG_LEN_POS) > (frame_iesection +
  785. frame_iesection_len - 1)) {
  786. mlo_err_rl("Position of length field of element with element ID %u for reporting STA would exceed frame IE section boundary",
  787. reportingsta_ie[ID_POS]);
  788. return QDF_STATUS_E_PROTO;
  789. }
  790. if ((reportingsta_ie[ID_POS] == WLAN_ELEMID_EXTN_ELEM) &&
  791. ((reportingsta_ie + IDEXT_POS) > (frame_iesection +
  792. frame_iesection_len - 1))) {
  793. mlo_err_rl("Position of element ID extension field of element would exceed frame IE section boundary");
  794. return QDF_STATUS_E_PROTO;
  795. }
  796. reportingsta_ie_size = reportingsta_ie[TAG_LEN_POS] + MIN_IE_LEN;
  797. if ((reportingsta_ie[ID_POS] == WLAN_ELEMID_EXTN_ELEM) &&
  798. (reportingsta_ie_size < (IDEXT_POS + 1))) {
  799. mlo_err_rl("Total length %zu of element for reporting STA is smaller than minimum required to access element ID extension %u",
  800. reportingsta_ie_size, IDEXT_POS + 1);
  801. return QDF_STATUS_E_PROTO;
  802. }
  803. if ((reportingsta_ie + reportingsta_ie_size) >
  804. (frame_iesection + frame_iesection_len)) {
  805. if (reportingsta_ie[ID_POS] == WLAN_ELEMID_EXTN_ELEM) {
  806. 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",
  807. reportingsta_ie_size,
  808. reportingsta_ie[ID_POS],
  809. reportingsta_ie[IDEXT_POS]);
  810. } else {
  811. mlo_err_rl("Total size %zu octets of element with element ID %u for reporting STA would exceed frame IE section boundary",
  812. reportingsta_ie_size,
  813. reportingsta_ie[ID_POS]);
  814. }
  815. return QDF_STATUS_E_PROTO;
  816. }
  817. return QDF_STATUS_SUCCESS;
  818. }
  819. static inline
  820. QDF_STATUS util_validate_sta_prof_ie(const uint8_t *sta_prof_ie,
  821. const uint8_t *sta_prof_iesection,
  822. const qdf_size_t sta_prof_iesection_len)
  823. {
  824. qdf_size_t sta_prof_ie_size;
  825. if (!sta_prof_ie) {
  826. mlo_err("Pointer to STA profile IE is NULL");
  827. return QDF_STATUS_E_NULL_VALUE;
  828. }
  829. if (!sta_prof_iesection) {
  830. mlo_err("Pointer to start of IE section in STA profile is NULL");
  831. return QDF_STATUS_E_NULL_VALUE;
  832. }
  833. if (!sta_prof_iesection_len) {
  834. mlo_err("Length of IE section in STA profile is zero");
  835. return QDF_STATUS_E_INVAL;
  836. }
  837. if ((sta_prof_ie + ID_POS) > (sta_prof_iesection +
  838. sta_prof_iesection_len - 1)) {
  839. mlo_err_rl("Position of element ID field of STA profile element would exceed STA profile IE section boundary");
  840. return QDF_STATUS_E_PROTO;
  841. }
  842. if ((sta_prof_ie + TAG_LEN_POS) > (sta_prof_iesection +
  843. sta_prof_iesection_len - 1)) {
  844. mlo_err_rl("Position of length field of element with element ID %u in STA profile would exceed STA profile IE section boundary",
  845. sta_prof_ie[ID_POS]);
  846. return QDF_STATUS_E_PROTO;
  847. }
  848. if ((sta_prof_ie[ID_POS] == WLAN_ELEMID_EXTN_ELEM) &&
  849. ((sta_prof_ie + IDEXT_POS) > (sta_prof_iesection +
  850. sta_prof_iesection_len - 1))) {
  851. mlo_err_rl("Position of element ID extension field of element would exceed STA profile IE section boundary");
  852. return QDF_STATUS_E_PROTO;
  853. }
  854. sta_prof_ie_size = sta_prof_ie[TAG_LEN_POS] + MIN_IE_LEN;
  855. if ((sta_prof_ie[ID_POS] == WLAN_ELEMID_EXTN_ELEM) &&
  856. (sta_prof_ie_size < (IDEXT_POS + 1))) {
  857. mlo_err_rl("Total length %zu of STA profile element is smaller than minimum required to access element ID extension %u",
  858. sta_prof_ie_size, IDEXT_POS + 1);
  859. return QDF_STATUS_E_PROTO;
  860. }
  861. if ((sta_prof_ie + sta_prof_ie_size) >
  862. (sta_prof_iesection + sta_prof_iesection_len)) {
  863. if (sta_prof_ie[ID_POS] == WLAN_ELEMID_EXTN_ELEM) {
  864. 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",
  865. sta_prof_ie_size,
  866. sta_prof_ie[ID_POS],
  867. sta_prof_ie[IDEXT_POS]);
  868. } else {
  869. mlo_err_rl("Total size %zu octets of element with element ID %u in STA profile would exceed STA profile IE section boundary",
  870. sta_prof_ie_size,
  871. sta_prof_ie[ID_POS]);
  872. }
  873. return QDF_STATUS_E_PROTO;
  874. }
  875. return QDF_STATUS_SUCCESS;
  876. }
  877. #define MLO_LINKSPECIFIC_ASSOC_REQ_FC0 0x00
  878. #define MLO_LINKSPECIFIC_ASSOC_REQ_FC1 0x00
  879. #define MLO_LINKSPECIFIC_ASSOC_RESP_FC0 0x10
  880. #define MLO_LINKSPECIFIC_ASSOC_RESP_FC1 0x00
  881. static
  882. QDF_STATUS util_gen_link_assoc_reqrsp_cmn(uint8_t *frame, qdf_size_t frame_len,
  883. uint8_t subtype,
  884. struct qdf_mac_addr link_addr,
  885. uint8_t *link_frame,
  886. qdf_size_t link_frame_maxsize,
  887. qdf_size_t *link_frame_len)
  888. {
  889. /* Please see documentation for util_gen_link_assoc_req() and
  890. * util_gen_link_assoc_resp() for information on the inputs to and
  891. * output from this helper, since those APIs are essentially wrappers
  892. * over this helper.
  893. */
  894. /* Pointer to Multi-Link element/Multi-Link element fragment sequence */
  895. uint8_t *mlieseq;
  896. /* Total length of Multi-Link element sequence (including fragements if
  897. * any)
  898. */
  899. qdf_size_t mlieseqlen;
  900. /* Variant (i.e. type) of the Multi-Link element */
  901. enum wlan_ml_variant variant;
  902. /* Length of the payload of the Multi-Link element (inclusive of
  903. * fragment payloads if any) without IE headers and element ID extension
  904. */
  905. qdf_size_t mlieseqpayloadlen;
  906. /* Pointer to copy of the payload of the Multi-Link element (inclusive
  907. * of fragment payloads if any) without IE headers and element ID
  908. * extension
  909. */
  910. uint8_t *mlieseqpayload_copy;
  911. /* Pointer to start of Link Info within the copy of the payload of the
  912. * Multi-Link element
  913. */
  914. uint8_t *link_info;
  915. /* Length of the Link Info */
  916. qdf_size_t link_info_len;
  917. /* Pointer to the IE section that occurs after the fixed fields in the
  918. * original frame for the reporting STA.
  919. */
  920. uint8_t *frame_iesection;
  921. /* Offset to the start of the IE section in the original frame for the
  922. * reporting STA.
  923. */
  924. qdf_size_t frame_iesection_offset;
  925. /* Total length of the IE section in the original frame for the
  926. * reporting STA.
  927. */
  928. qdf_size_t frame_iesection_len;
  929. /* Pointer to the IEEE802.11 frame header in the link specific frame
  930. * being generated for the reported STA.
  931. */
  932. struct wlan_frame_hdr *link_frame_hdr;
  933. /* Current position in the link specific frame being generated for the
  934. * reported STA.
  935. */
  936. uint8_t *link_frame_currpos;
  937. /* Current length of the link specific frame being generated for the
  938. * reported STA.
  939. */
  940. qdf_size_t link_frame_currlen;
  941. /* Pointer to IE for reporting STA */
  942. const uint8_t *reportingsta_ie;
  943. /* Total size of IE for reporting STA, inclusive of the element header
  944. */
  945. qdf_size_t reportingsta_ie_size;
  946. /* Pointer to current position in STA profile */
  947. uint8_t *sta_prof_currpos;
  948. /* Remaining length of STA profile */
  949. qdf_size_t sta_prof_remlen;
  950. /* Pointer to start of IE section in STA profile that occurs after fixed
  951. * fields.
  952. */
  953. uint8_t *sta_prof_iesection;
  954. /* Total length of IE section in STA profile */
  955. qdf_size_t sta_prof_iesection_len;
  956. /* Pointer to current position being processed in IE section in STA
  957. * profile.
  958. */
  959. uint8_t *sta_prof_iesection_currpos;
  960. /* Remaining length of IE section in STA profile */
  961. qdf_size_t sta_prof_iesection_remlen;
  962. /* Pointer to IE in STA profile, that occurs within IE section */
  963. uint8_t *sta_prof_ie;
  964. /* Total size of IE in STA profile, inclusive of the element header */
  965. qdf_size_t sta_prof_ie_size;
  966. /* Pointer to element ID list in Non-Inheritance IE */
  967. uint8_t *ninherit_elemlist;
  968. /* Length of element ID list in Non-Inheritance IE */
  969. qdf_size_t ninherit_elemlist_len;
  970. /* Pointer to element ID extension list in Non-Inheritance IE */
  971. uint8_t *ninherit_elemextlist;
  972. /* Length of element ID extension list in Non-Inheritance IE */
  973. qdf_size_t ninherit_elemextlist_len;
  974. /* Whether a given IE is in a non-inheritance list */
  975. bool is_in_noninheritlist;
  976. /* Whether MAC address of reported STA is valid */
  977. bool is_reportedmacaddr_valid;
  978. /* MAC address of reported STA */
  979. struct qdf_mac_addr reportedmacaddr;
  980. /* Pointer to per-STA profile */
  981. uint8_t *persta_prof;
  982. /* Length of the containing buffer which starts with the per-STA profile
  983. */
  984. qdf_size_t persta_prof_bufflen;
  985. /* Other variables for temporary purposes */
  986. /* Variable into which API for determining fragment information will
  987. * indicate whether the element is the start of a fragment sequence or
  988. * not.
  989. */
  990. bool is_elemfragseq;
  991. /* De-fragmented payload length returned by API for element
  992. * defragmentation.
  993. */
  994. qdf_size_t defragpayload_len;
  995. /* Variable into which API for determining fragment information will
  996. * indicate whether the subelement is the start of a fragment sequence
  997. * or not.
  998. */
  999. bool is_subelemfragseq;
  1000. /* Total length of the subelement fragment sequence, inclusive of
  1001. * subelement header and the headers of fragments if any.
  1002. */
  1003. qdf_size_t subelemseqtotallen;
  1004. /* Total length of the subelement fragment sequence payload, excluding
  1005. * subelement header and fragment headers if any.
  1006. */
  1007. qdf_size_t subelemseqpayloadlen;
  1008. qdf_size_t tmplen;
  1009. QDF_STATUS ret;
  1010. if (!frame) {
  1011. mlo_err("Pointer to original frame is NULL");
  1012. return QDF_STATUS_E_NULL_VALUE;
  1013. }
  1014. if (!frame_len) {
  1015. mlo_err("Length of original frame is zero");
  1016. return QDF_STATUS_E_INVAL;
  1017. }
  1018. if ((subtype != WLAN_FC0_STYPE_ASSOC_REQ) &&
  1019. (subtype != WLAN_FC0_STYPE_REASSOC_REQ) &&
  1020. (subtype != WLAN_FC0_STYPE_ASSOC_RESP) &&
  1021. (subtype != WLAN_FC0_STYPE_REASSOC_RESP)) {
  1022. mlo_err("802.11 frame subtype %u is invalid", subtype);
  1023. return QDF_STATUS_E_INVAL;
  1024. }
  1025. if (!link_frame) {
  1026. mlo_err("Pointer to secondary link specific frame is NULL");
  1027. return QDF_STATUS_E_NULL_VALUE;
  1028. }
  1029. if (!link_frame_maxsize) {
  1030. mlo_err("Maximum size of secondary link specific frame is zero");
  1031. return QDF_STATUS_E_INVAL;
  1032. }
  1033. if (!link_frame_len) {
  1034. mlo_err("Pointer to populated length of secondary link specific frame is NULL");
  1035. return QDF_STATUS_E_NULL_VALUE;
  1036. }
  1037. frame_iesection_offset = 0;
  1038. if (subtype == WLAN_FC0_STYPE_ASSOC_REQ) {
  1039. frame_iesection_offset = WLAN_ASSOC_REQ_IES_OFFSET;
  1040. } else if (subtype == WLAN_FC0_STYPE_REASSOC_REQ) {
  1041. frame_iesection_offset = WLAN_REASSOC_REQ_IES_OFFSET;
  1042. } else {
  1043. /* This is a (re)association response */
  1044. frame_iesection_offset = WLAN_ASSOC_RSP_IES_OFFSET;
  1045. }
  1046. if (frame_len < frame_iesection_offset) {
  1047. /* The caller is supposed to have confirmed that this is a valid
  1048. * frame containing a Multi-Link element. Hence we treat this as
  1049. * a case of invalid argument being passed to us.
  1050. */
  1051. mlo_err("Frame length %zu is smaller than the IE section offset %zu for subtype %u",
  1052. frame_len, frame_iesection_offset, subtype);
  1053. return QDF_STATUS_E_INVAL;
  1054. }
  1055. frame_iesection_len = frame_len - frame_iesection_offset;
  1056. if (frame_iesection_len == 0) {
  1057. /* The caller is supposed to have confirmed that this is a valid
  1058. * frame containing a Multi-Link element. Hence we treat this as
  1059. * a case of invalid argument being passed to us.
  1060. */
  1061. mlo_err("No space left in frame for IE section");
  1062. return QDF_STATUS_E_INVAL;
  1063. }
  1064. frame_iesection = frame + frame_iesection_offset;
  1065. mlieseq = NULL;
  1066. mlieseqlen = 0;
  1067. ret = util_find_mlie(frame_iesection, frame_iesection_len, &mlieseq,
  1068. &mlieseqlen);
  1069. if (QDF_IS_STATUS_ERROR(ret))
  1070. return ret;
  1071. if (!mlieseq) {
  1072. /* The caller is supposed to have confirmed that a Multi-Link
  1073. * element is present in the frame. Hence we treat this as a
  1074. * case of invalid argument being passed to us.
  1075. */
  1076. mlo_err("Invalid original frame since no Multi-Link element found");
  1077. return QDF_STATUS_E_INVAL;
  1078. }
  1079. /* Sanity check the Multi-Link element sequence length */
  1080. if (!mlieseqlen) {
  1081. mlo_err("Length of Multi-Link element sequence is zero. Investigate.");
  1082. return QDF_STATUS_E_FAILURE;
  1083. }
  1084. if (mlieseqlen < sizeof(struct wlan_ie_multilink)) {
  1085. mlo_err_rl("Multi-Link element sequence length %zu octets is smaller than required for the fixed portion of Multi-Link element (%zu octets)",
  1086. mlieseqlen, sizeof(struct wlan_ie_multilink));
  1087. return QDF_STATUS_E_PROTO;
  1088. }
  1089. ret = util_get_mlie_variant(mlieseq, mlieseqlen, (int *)&variant);
  1090. if (QDF_IS_STATUS_ERROR(ret))
  1091. return ret;
  1092. if (variant != WLAN_ML_VARIANT_BASIC) {
  1093. mlo_err_rl("Unexpected variant %u of Multi-Link element.",
  1094. variant);
  1095. return QDF_STATUS_E_PROTO;
  1096. }
  1097. mlieseqpayloadlen = 0;
  1098. tmplen = 0;
  1099. is_elemfragseq = false;
  1100. ret = wlan_get_elem_fragseq_info(mlieseq,
  1101. mlieseqlen,
  1102. &is_elemfragseq,
  1103. &tmplen,
  1104. &mlieseqpayloadlen);
  1105. if (QDF_IS_STATUS_ERROR(ret))
  1106. return ret;
  1107. if (is_elemfragseq) {
  1108. if (tmplen != mlieseqlen) {
  1109. 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",
  1110. tmplen, mlieseqlen);
  1111. return QDF_STATUS_E_FAILURE;
  1112. }
  1113. if (!mlieseqpayloadlen) {
  1114. mlo_err_rl("Multi-Link element fragment sequence payload is reported as 0, investigate");
  1115. return QDF_STATUS_E_FAILURE;
  1116. }
  1117. mlo_debug("Multi-Link element fragment sequence found with payload len %zu",
  1118. mlieseqpayloadlen);
  1119. } else {
  1120. if (mlieseqlen > (sizeof(struct ie_header) + WLAN_MAX_IE_LEN)) {
  1121. 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",
  1122. mlieseqlen,
  1123. sizeof(struct ie_header) + WLAN_MAX_IE_LEN);
  1124. return QDF_STATUS_E_FAILURE;
  1125. }
  1126. mlieseqpayloadlen = mlieseqlen - (sizeof(struct ie_header) + 1);
  1127. }
  1128. mlieseqpayload_copy = qdf_mem_malloc(mlieseqpayloadlen);
  1129. if (!mlieseqpayload_copy) {
  1130. mlo_err_rl("Could not allocate memory for Multi-Link element payload copy");
  1131. return QDF_STATUS_E_NOMEM;
  1132. }
  1133. if (is_elemfragseq) {
  1134. ret = wlan_defrag_elem_fragseq(false,
  1135. mlieseq,
  1136. mlieseqlen,
  1137. mlieseqpayload_copy,
  1138. mlieseqpayloadlen,
  1139. &defragpayload_len);
  1140. if (QDF_IS_STATUS_ERROR(ret)) {
  1141. qdf_mem_free(mlieseqpayload_copy);
  1142. return ret;
  1143. }
  1144. if (defragpayload_len != mlieseqpayloadlen) {
  1145. mlo_err_rl("Length of de-fragmented payload %zu octets is not equal to length of Multi-Link element fragment sequence payload %zu octets",
  1146. defragpayload_len, mlieseqpayloadlen);
  1147. qdf_mem_free(mlieseqpayload_copy);
  1148. return QDF_STATUS_E_FAILURE;
  1149. }
  1150. } else {
  1151. qdf_mem_copy(mlieseqpayload_copy,
  1152. mlieseq + sizeof(struct ie_header) + 1,
  1153. mlieseqpayloadlen);
  1154. }
  1155. link_info = NULL;
  1156. link_info_len = 0;
  1157. ret = util_parse_multi_link_ctrl(mlieseqpayload_copy,
  1158. mlieseqpayloadlen,
  1159. &link_info,
  1160. &link_info_len);
  1161. if (QDF_IS_STATUS_ERROR(ret)) {
  1162. qdf_mem_free(mlieseqpayload_copy);
  1163. return ret;
  1164. }
  1165. /* As per the standard, the sender must include Link Info for
  1166. * association request/response. Throw an error if we are unable to
  1167. * obtain this.
  1168. */
  1169. if (!link_info) {
  1170. mlo_err_rl("Unable to successfully obtain Link Info");
  1171. qdf_mem_free(mlieseqpayload_copy);
  1172. return QDF_STATUS_E_PROTO;
  1173. }
  1174. mlo_debug("Dumping hex of link info after parsing Multi-Link element control");
  1175. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_MLO, QDF_TRACE_LEVEL_DEBUG,
  1176. link_info, link_info_len);
  1177. /* Note: We may have a future change to skip subelements which are not
  1178. * Per-STA Profile, handle more than two links in MLO, handle cases
  1179. * where we unexpectedly find more Per-STA Profiles than expected, etc.
  1180. */
  1181. persta_prof = link_info;
  1182. persta_prof_bufflen = link_info_len;
  1183. is_subelemfragseq = false;
  1184. subelemseqtotallen = 0;
  1185. subelemseqpayloadlen = 0;
  1186. ret = wlan_get_subelem_fragseq_info(WLAN_ML_BV_LINFO_SUBELEMID_FRAGMENT,
  1187. persta_prof,
  1188. persta_prof_bufflen,
  1189. &is_subelemfragseq,
  1190. &subelemseqtotallen,
  1191. &subelemseqpayloadlen);
  1192. if (QDF_IS_STATUS_ERROR(ret)) {
  1193. qdf_mem_free(mlieseqpayload_copy);
  1194. return ret;
  1195. }
  1196. if (is_subelemfragseq) {
  1197. if (!subelemseqpayloadlen) {
  1198. mlo_err_rl("Subelement fragment sequence payload is reported as 0, investigate");
  1199. qdf_mem_free(mlieseqpayload_copy);
  1200. return QDF_STATUS_E_FAILURE;
  1201. }
  1202. mlo_debug("Subelement fragment sequence found with payload len %zu",
  1203. subelemseqpayloadlen);
  1204. ret = wlan_defrag_subelem_fragseq(true,
  1205. WLAN_ML_BV_LINFO_SUBELEMID_FRAGMENT,
  1206. persta_prof,
  1207. persta_prof_bufflen,
  1208. NULL,
  1209. 0,
  1210. &defragpayload_len);
  1211. if (QDF_IS_STATUS_ERROR(ret)) {
  1212. qdf_mem_free(mlieseqpayload_copy);
  1213. return ret;
  1214. }
  1215. if (defragpayload_len != subelemseqpayloadlen) {
  1216. mlo_err_rl("Length of defragmented payload %zu octets is not equal to length of subelement fragment sequence payload %zu octets",
  1217. defragpayload_len,
  1218. subelemseqpayloadlen);
  1219. qdf_mem_free(mlieseqpayload_copy);
  1220. return QDF_STATUS_E_FAILURE;
  1221. }
  1222. } else {
  1223. if (persta_prof_bufflen <
  1224. (sizeof(struct subelem_header) +
  1225. persta_prof[TAG_LEN_POS])) {
  1226. mlo_err_rl("Length of buffer containing per-STA profile %zu octets is smaller than total size of current subelement %zu octets",
  1227. persta_prof_bufflen,
  1228. sizeof(struct subelem_header) +
  1229. persta_prof[TAG_LEN_POS]);
  1230. return QDF_STATUS_E_PROTO;
  1231. }
  1232. subelemseqpayloadlen = persta_prof[TAG_LEN_POS];
  1233. }
  1234. sta_prof_remlen = 0;
  1235. sta_prof_currpos = NULL;
  1236. is_reportedmacaddr_valid = false;
  1237. /* Parse per-STA profile */
  1238. ret = util_parse_bvmlie_perstaprofile_stactrl(persta_prof +
  1239. sizeof(struct subelem_header),
  1240. subelemseqpayloadlen,
  1241. NULL,
  1242. &is_reportedmacaddr_valid,
  1243. &reportedmacaddr,
  1244. true,
  1245. &sta_prof_currpos,
  1246. &sta_prof_remlen);
  1247. if (QDF_IS_STATUS_ERROR(ret)) {
  1248. qdf_mem_free(mlieseqpayload_copy);
  1249. return ret;
  1250. }
  1251. /* We double check for a NULL STA Profile, though the helper function
  1252. * above would have taken care of this. We need to get a non-NULL STA
  1253. * profile, because we need to get at least the expected fixed fields,
  1254. * even if there is an (improbable) total inheritance.
  1255. */
  1256. if (!sta_prof_currpos) {
  1257. mlo_err_rl("STA profile is NULL");
  1258. qdf_mem_free(mlieseqpayload_copy);
  1259. return QDF_STATUS_E_PROTO;
  1260. }
  1261. /* As per the standard, the sender sets the MAC address in the per-STA
  1262. * profile in association request/response. Without this, we cannot
  1263. * generate the link specific frame.
  1264. */
  1265. if (!is_reportedmacaddr_valid) {
  1266. mlo_err_rl("Unable to get MAC address from per-STA profile");
  1267. qdf_mem_free(mlieseqpayload_copy);
  1268. return QDF_STATUS_E_PROTO;
  1269. }
  1270. link_frame_currpos = link_frame;
  1271. *link_frame_len = 0;
  1272. link_frame_currlen = 0;
  1273. if (link_frame_maxsize < WLAN_MAC_HDR_LEN_3A) {
  1274. mlo_err("Insufficent space in link specific frame for 802.11 header. Required: %u octets, available: %zu octets",
  1275. WLAN_MAC_HDR_LEN_3A, link_frame_maxsize);
  1276. qdf_mem_free(mlieseqpayload_copy);
  1277. return QDF_STATUS_E_NOMEM;
  1278. }
  1279. link_frame_currpos += WLAN_MAC_HDR_LEN_3A;
  1280. link_frame_currlen += WLAN_MAC_HDR_LEN_3A;
  1281. if ((subtype == WLAN_FC0_STYPE_ASSOC_REQ) ||
  1282. (subtype == WLAN_FC0_STYPE_REASSOC_REQ)) {
  1283. mlo_debug("Populating fixed fields for (re)assoc req in link specific frame");
  1284. if (sta_prof_remlen < WLAN_CAPABILITYINFO_LEN) {
  1285. mlo_err_rl("Remaining length of STA profile %zu octets is less than length of Capability Info %u",
  1286. sta_prof_remlen,
  1287. WLAN_CAPABILITYINFO_LEN);
  1288. qdf_mem_free(mlieseqpayload_copy);
  1289. return QDF_STATUS_E_PROTO;
  1290. }
  1291. /* Capability information is specific to the link. Copy this
  1292. * from the STA profile.
  1293. */
  1294. if ((link_frame_maxsize - link_frame_currlen) <
  1295. WLAN_CAPABILITYINFO_LEN) {
  1296. mlo_err("Insufficent space in link specific frame for Capability Info field. Required: %u octets, available: %zu octets",
  1297. WLAN_CAPABILITYINFO_LEN,
  1298. (link_frame_maxsize - link_frame_currlen));
  1299. qdf_mem_free(mlieseqpayload_copy);
  1300. return QDF_STATUS_E_NOMEM;
  1301. }
  1302. qdf_mem_copy(link_frame_currpos, sta_prof_currpos,
  1303. WLAN_CAPABILITYINFO_LEN);
  1304. link_frame_currpos += WLAN_CAPABILITYINFO_LEN;
  1305. link_frame_currlen += WLAN_CAPABILITYINFO_LEN;
  1306. mlo_debug("Added Capablity Info field (%u octets) to link specific frame",
  1307. WLAN_CAPABILITYINFO_LEN);
  1308. sta_prof_currpos += WLAN_CAPABILITYINFO_LEN;
  1309. sta_prof_remlen -= WLAN_CAPABILITYINFO_LEN;
  1310. /* Listen Interval is common between all links. Copy this from
  1311. * the reporting section of the frame.
  1312. */
  1313. if ((link_frame_maxsize - link_frame_currlen) <
  1314. WLAN_LISTENINTERVAL_LEN) {
  1315. mlo_err("Insufficent space in link specific frame for Listen Interval field. Required: %u octets, available: %zu octets",
  1316. WLAN_LISTENINTERVAL_LEN,
  1317. (link_frame_maxsize - link_frame_currlen));
  1318. qdf_mem_free(mlieseqpayload_copy);
  1319. return QDF_STATUS_E_NOMEM;
  1320. }
  1321. qdf_mem_copy(link_frame_currpos,
  1322. frame + WLAN_CAPABILITYINFO_LEN,
  1323. WLAN_LISTENINTERVAL_LEN);
  1324. link_frame_currpos += WLAN_LISTENINTERVAL_LEN;
  1325. link_frame_currlen += WLAN_LISTENINTERVAL_LEN;
  1326. mlo_debug("Added Listen Interval field (%u octets) to link specific frame",
  1327. WLAN_LISTENINTERVAL_LEN);
  1328. if (subtype == WLAN_FC0_STYPE_REASSOC_REQ) {
  1329. /* Current AP address is common between all links. Copy
  1330. * this from the reporting section of the frame.
  1331. */
  1332. if ((link_frame_maxsize - link_frame_currlen) <
  1333. QDF_MAC_ADDR_SIZE) {
  1334. mlo_err("Insufficent space in link specific frame for current AP address. Required: %u octets, available: %zu octets",
  1335. QDF_MAC_ADDR_SIZE,
  1336. (link_frame_maxsize -
  1337. link_frame_currlen));
  1338. qdf_mem_free(mlieseqpayload_copy);
  1339. return QDF_STATUS_E_NOMEM;
  1340. }
  1341. qdf_mem_copy(link_frame_currpos,
  1342. frame + WLAN_CAPABILITYINFO_LEN +
  1343. WLAN_LISTENINTERVAL_LEN,
  1344. QDF_MAC_ADDR_SIZE);
  1345. link_frame_currpos += QDF_MAC_ADDR_SIZE;
  1346. link_frame_currlen += QDF_MAC_ADDR_SIZE;
  1347. mlo_debug("Reassoc req: Added Current AP address field (%u octets) to link specific frame",
  1348. QDF_MAC_ADDR_SIZE);
  1349. }
  1350. } else {
  1351. /* This is a (re)association response */
  1352. mlo_debug("Populating fixed fields for (re)assoc resp in link specific frame");
  1353. if (sta_prof_remlen <
  1354. (WLAN_CAPABILITYINFO_LEN + WLAN_STATUSCODE_LEN)) {
  1355. mlo_err_rl("Remaining length of STA profile %zu octets is less than length of Capability Info + length of Status Code %u",
  1356. sta_prof_remlen,
  1357. WLAN_CAPABILITYINFO_LEN +
  1358. WLAN_STATUSCODE_LEN);
  1359. qdf_mem_free(mlieseqpayload_copy);
  1360. return QDF_STATUS_E_PROTO;
  1361. }
  1362. /* Capability information and Status Code are specific to the
  1363. * link. Copy these from the STA profile.
  1364. */
  1365. if ((link_frame_maxsize - link_frame_currlen) <
  1366. (WLAN_CAPABILITYINFO_LEN + WLAN_STATUSCODE_LEN)) {
  1367. mlo_err("Insufficent space in link specific frame for Capability Info and Status Code fields. Required: %u octets, available: %zu octets",
  1368. WLAN_CAPABILITYINFO_LEN + WLAN_STATUSCODE_LEN,
  1369. (link_frame_maxsize - link_frame_currlen));
  1370. qdf_mem_free(mlieseqpayload_copy);
  1371. return QDF_STATUS_E_NOMEM;
  1372. }
  1373. qdf_mem_copy(link_frame_currpos, sta_prof_currpos,
  1374. (WLAN_CAPABILITYINFO_LEN + WLAN_STATUSCODE_LEN));
  1375. link_frame_currpos += (WLAN_CAPABILITYINFO_LEN +
  1376. WLAN_STATUSCODE_LEN);
  1377. link_frame_currlen += (WLAN_CAPABILITYINFO_LEN +
  1378. WLAN_STATUSCODE_LEN);
  1379. mlo_debug("Added Capability Info and Status Code fields (%u octets) to link specific frame",
  1380. WLAN_CAPABILITYINFO_LEN + WLAN_STATUSCODE_LEN);
  1381. sta_prof_currpos += (WLAN_CAPABILITYINFO_LEN +
  1382. WLAN_STATUSCODE_LEN);
  1383. sta_prof_remlen -= (WLAN_CAPABILITYINFO_LEN +
  1384. WLAN_STATUSCODE_LEN);
  1385. /* AID is common between all links. Copy this from the original
  1386. * frame.
  1387. */
  1388. if ((link_frame_maxsize - link_frame_currlen) < WLAN_AID_LEN) {
  1389. mlo_err("Insufficent space in link specific frame for AID field. Required: %u octets, available: %zu octets",
  1390. WLAN_AID_LEN,
  1391. (link_frame_maxsize - link_frame_currlen));
  1392. qdf_mem_free(mlieseqpayload_copy);
  1393. return QDF_STATUS_E_NOMEM;
  1394. }
  1395. qdf_mem_copy(link_frame_currpos,
  1396. frame + WLAN_CAPABILITYINFO_LEN +
  1397. WLAN_STATUSCODE_LEN,
  1398. WLAN_AID_LEN);
  1399. link_frame_currpos += WLAN_AID_LEN;
  1400. link_frame_currlen += WLAN_AID_LEN;
  1401. mlo_debug("Added AID field (%u octets) to link specific frame",
  1402. WLAN_AID_LEN);
  1403. }
  1404. sta_prof_iesection = sta_prof_currpos;
  1405. sta_prof_iesection_len = sta_prof_remlen;
  1406. /* Populate non-inheritance lists if applicable */
  1407. ninherit_elemlist_len = 0;
  1408. ninherit_elemlist = NULL;
  1409. ninherit_elemextlist_len = 0;
  1410. ninherit_elemextlist = NULL;
  1411. ret = util_get_noninheritlists(sta_prof_iesection,
  1412. sta_prof_iesection_len,
  1413. &ninherit_elemlist,
  1414. &ninherit_elemlist_len,
  1415. &ninherit_elemextlist,
  1416. &ninherit_elemextlist_len);
  1417. if (QDF_IS_STATUS_ERROR(ret)) {
  1418. qdf_mem_free(mlieseqpayload_copy);
  1419. return ret;
  1420. }
  1421. /* Go through IEs of the reporting STA, and those in STA profile, merge
  1422. * them into link_frame (except for elements in the Non-Inheritance
  1423. * list).
  1424. *
  1425. * Note: Currently, only 2-link MLO is supported here. We may have a
  1426. * future change to expand to more links.
  1427. */
  1428. reportingsta_ie = util_find_eid(WLAN_ELEMID_SSID, frame_iesection,
  1429. frame_iesection_len);
  1430. if ((subtype == WLAN_FC0_STYPE_ASSOC_REQ) ||
  1431. (subtype == WLAN_FC0_STYPE_REASSOC_REQ)) {
  1432. /* Sanity check that the SSID element is present for the
  1433. * reporting STA. There is no stipulation in the standard for
  1434. * the STA profile in this regard, so we do not check the STA
  1435. * profile for the SSID element.
  1436. */
  1437. if (!reportingsta_ie) {
  1438. mlo_err_rl("SSID element not found for reporting STA for (re)association request.");
  1439. qdf_mem_free(mlieseqpayload_copy);
  1440. return QDF_STATUS_E_PROTO;
  1441. }
  1442. } else {
  1443. /* This is a (re)association response. Sanity check that the
  1444. * SSID element is present neither for the reporting STA nor in
  1445. * the STA profile.
  1446. */
  1447. if (reportingsta_ie) {
  1448. mlo_err_rl("SSID element found for reporting STA for (re)association response. It should not be present.");
  1449. qdf_mem_free(mlieseqpayload_copy);
  1450. return QDF_STATUS_E_PROTO;
  1451. }
  1452. sta_prof_ie = util_find_eid(WLAN_ELEMID_SSID,
  1453. sta_prof_iesection,
  1454. sta_prof_iesection_len);
  1455. if (sta_prof_ie) {
  1456. mlo_err_rl("SSID element found in STA profile for (re)association response. It should not be present.");
  1457. qdf_mem_free(mlieseqpayload_copy);
  1458. return QDF_STATUS_E_PROTO;
  1459. }
  1460. }
  1461. reportingsta_ie = reportingsta_ie ? reportingsta_ie : frame_iesection;
  1462. ret = util_validate_reportingsta_ie(reportingsta_ie, frame_iesection,
  1463. frame_iesection_len);
  1464. if (QDF_IS_STATUS_ERROR(ret)) {
  1465. qdf_mem_free(mlieseqpayload_copy);
  1466. return ret;
  1467. }
  1468. reportingsta_ie_size = reportingsta_ie[TAG_LEN_POS] + MIN_IE_LEN;
  1469. while (((reportingsta_ie + reportingsta_ie_size) - frame_iesection)
  1470. <= frame_iesection_len) {
  1471. /* Skip Multi-Link element */
  1472. if ((reportingsta_ie[ID_POS] == WLAN_ELEMID_EXTN_ELEM) &&
  1473. (reportingsta_ie[IDEXT_POS] ==
  1474. WLAN_EXTN_ELEMID_MULTI_LINK)) {
  1475. if (((reportingsta_ie + reportingsta_ie_size) -
  1476. frame_iesection) == frame_iesection_len)
  1477. break;
  1478. reportingsta_ie += reportingsta_ie_size;
  1479. ret = util_validate_reportingsta_ie(reportingsta_ie,
  1480. frame_iesection,
  1481. frame_iesection_len);
  1482. if (QDF_IS_STATUS_ERROR(ret)) {
  1483. qdf_mem_free(mlieseqpayload_copy);
  1484. return ret;
  1485. }
  1486. reportingsta_ie_size = reportingsta_ie[TAG_LEN_POS] +
  1487. MIN_IE_LEN;
  1488. continue;
  1489. }
  1490. sta_prof_ie = NULL;
  1491. sta_prof_ie_size = 0;
  1492. if (sta_prof_iesection_len) {
  1493. if (reportingsta_ie[ID_POS] == WLAN_ELEMID_EXTN_ELEM) {
  1494. sta_prof_ie = (uint8_t *)util_find_extn_eid(reportingsta_ie[ID_POS],
  1495. reportingsta_ie[IDEXT_POS],
  1496. sta_prof_iesection,
  1497. sta_prof_iesection_len);
  1498. } else {
  1499. sta_prof_ie = (uint8_t *)util_find_eid(reportingsta_ie[ID_POS],
  1500. sta_prof_iesection,
  1501. sta_prof_iesection_len);
  1502. }
  1503. }
  1504. if (!sta_prof_ie) {
  1505. /* IE is present for reporting STA, but not in STA
  1506. * profile.
  1507. */
  1508. is_in_noninheritlist = false;
  1509. ret = util_eval_ie_in_noninheritlist((uint8_t *)reportingsta_ie,
  1510. reportingsta_ie_size,
  1511. ninherit_elemlist,
  1512. ninherit_elemlist_len,
  1513. ninherit_elemextlist,
  1514. ninherit_elemextlist_len,
  1515. &is_in_noninheritlist);
  1516. if (QDF_IS_STATUS_ERROR(ret)) {
  1517. qdf_mem_free(mlieseqpayload_copy);
  1518. return ret;
  1519. }
  1520. if (!is_in_noninheritlist) {
  1521. if ((link_frame_currpos +
  1522. reportingsta_ie_size) <=
  1523. (link_frame + link_frame_maxsize)) {
  1524. qdf_mem_copy(link_frame_currpos,
  1525. reportingsta_ie,
  1526. reportingsta_ie_size);
  1527. link_frame_currpos +=
  1528. reportingsta_ie_size;
  1529. link_frame_currlen +=
  1530. reportingsta_ie_size;
  1531. if (reportingsta_ie[ID_POS] == WLAN_ELEMID_EXTN_ELEM) {
  1532. 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",
  1533. reportingsta_ie[ID_POS],
  1534. reportingsta_ie[IDEXT_POS],
  1535. reportingsta_ie_size);
  1536. } else {
  1537. 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",
  1538. reportingsta_ie[ID_POS],
  1539. reportingsta_ie_size);
  1540. }
  1541. } else {
  1542. if (reportingsta_ie[ID_POS] == WLAN_ELEMID_EXTN_ELEM) {
  1543. mlo_err_rl("Insufficent space in link specific frame for IE with element ID : %u extension element ID : %u. Required: %zu octets, available: %zu octets",
  1544. reportingsta_ie[ID_POS],
  1545. reportingsta_ie[IDEXT_POS],
  1546. reportingsta_ie_size,
  1547. link_frame_maxsize -
  1548. link_frame_currlen);
  1549. } else {
  1550. mlo_err_rl("Insufficent space in link specific frame for IE with element ID : %u. Required: %zu octets, available: %zu octets",
  1551. reportingsta_ie[ID_POS],
  1552. reportingsta_ie_size,
  1553. link_frame_maxsize -
  1554. link_frame_currlen);
  1555. }
  1556. qdf_mem_free(mlieseqpayload_copy);
  1557. return QDF_STATUS_E_NOMEM;
  1558. }
  1559. } else {
  1560. if (reportingsta_ie[ID_POS] == WLAN_ELEMID_EXTN_ELEM) {
  1561. 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.",
  1562. reportingsta_ie[ID_POS],
  1563. reportingsta_ie[IDEXT_POS],
  1564. reportingsta_ie_size);
  1565. } else {
  1566. 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.",
  1567. reportingsta_ie[ID_POS],
  1568. reportingsta_ie_size);
  1569. }
  1570. }
  1571. } else {
  1572. /* IE is present for reporting STA and also in STA
  1573. * profile, copy from STA profile and flag the IE in STA
  1574. * profile as copied (by setting EID field to 0). The
  1575. * SSID element (with EID 0) is processed first to
  1576. * enable this. For vendor IE, compare OUI + type +
  1577. * subType to determine if they are the same IE.
  1578. */
  1579. /* Note: This may be revisited in a future change, to
  1580. * adhere to provisions in the standard for multiple
  1581. * occurrences of a given element ID/extension element
  1582. * ID.
  1583. */
  1584. ret = util_validate_sta_prof_ie(sta_prof_ie,
  1585. sta_prof_iesection,
  1586. sta_prof_iesection_len);
  1587. if (QDF_IS_STATUS_ERROR(ret)) {
  1588. qdf_mem_free(mlieseqpayload_copy);
  1589. return ret;
  1590. }
  1591. sta_prof_ie_size = sta_prof_ie[TAG_LEN_POS] +
  1592. MIN_IE_LEN;
  1593. sta_prof_iesection_remlen =
  1594. sta_prof_iesection_len -
  1595. (sta_prof_ie - sta_prof_iesection);
  1596. if ((reportingsta_ie[ID_POS] == WLAN_ELEMID_VENDOR) &&
  1597. (sta_prof_iesection_remlen >= MIN_VENDOR_TAG_LEN)) {
  1598. /* If Vendor IE also presents in STA profile,
  1599. * then ignore the Vendor IE which is for
  1600. * reporting STA. It only needs to copy Vendor
  1601. * IE from STA profile to link specific frame.
  1602. * The copy happens when going through the
  1603. * remaining IEs.
  1604. */
  1605. ;
  1606. } else {
  1607. /* Copy IE from STA profile into link specific
  1608. * frame.
  1609. */
  1610. if ((link_frame_currpos + sta_prof_ie_size) <=
  1611. (link_frame + link_frame_maxsize)) {
  1612. qdf_mem_copy(link_frame_currpos,
  1613. sta_prof_ie,
  1614. sta_prof_ie_size);
  1615. link_frame_currpos += sta_prof_ie_size;
  1616. link_frame_currlen +=
  1617. sta_prof_ie_size;
  1618. if (reportingsta_ie[ID_POS] ==
  1619. WLAN_ELEMID_EXTN_ELEM) {
  1620. 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",
  1621. sta_prof_ie[ID_POS],
  1622. sta_prof_ie[IDEXT_POS],
  1623. sta_prof_ie_size);
  1624. } else {
  1625. 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",
  1626. sta_prof_ie[ID_POS],
  1627. sta_prof_ie_size);
  1628. }
  1629. sta_prof_ie[0] = 0;
  1630. } else {
  1631. if (sta_prof_ie[ID_POS] ==
  1632. WLAN_ELEMID_EXTN_ELEM) {
  1633. mlo_err_rl("Insufficent space in link specific frame for IE with element ID : %u extension element ID : %u. Required: %zu octets, available: %zu octets",
  1634. sta_prof_ie[ID_POS],
  1635. sta_prof_ie[IDEXT_POS],
  1636. sta_prof_ie_size,
  1637. link_frame_maxsize -
  1638. link_frame_currlen);
  1639. } else {
  1640. mlo_err_rl("Insufficent space in link specific frame for IE with element ID : %u. Required: %zu octets, available: %zu octets",
  1641. sta_prof_ie[ID_POS],
  1642. sta_prof_ie_size,
  1643. link_frame_maxsize -
  1644. link_frame_currlen);
  1645. }
  1646. qdf_mem_free(mlieseqpayload_copy);
  1647. return QDF_STATUS_E_NOMEM;
  1648. }
  1649. }
  1650. }
  1651. if (((reportingsta_ie + reportingsta_ie_size) -
  1652. frame_iesection) == frame_iesection_len)
  1653. break;
  1654. reportingsta_ie += reportingsta_ie_size;
  1655. ret = util_validate_reportingsta_ie(reportingsta_ie,
  1656. frame_iesection,
  1657. frame_iesection_len);
  1658. if (QDF_IS_STATUS_ERROR(ret)) {
  1659. qdf_mem_free(mlieseqpayload_copy);
  1660. return ret;
  1661. }
  1662. reportingsta_ie_size = reportingsta_ie[TAG_LEN_POS] +
  1663. MIN_IE_LEN;
  1664. }
  1665. /* Go through the remaining unprocessed IEs in STA profile and copy them
  1666. * to the link specific frame. The processed ones are marked with 0 in
  1667. * the first octet. The first octet corresponds to the element ID. In
  1668. * the case of (re)association request, the element with actual ID
  1669. * WLAN_ELEMID_SSID(0) has already been copied to the link specific
  1670. * frame. In the case of (re)association response, it has been verified
  1671. * that the element with actual ID WLAN_ELEMID_SSID(0) is present
  1672. * neither for the reporting STA nor in the STA profile.
  1673. */
  1674. sta_prof_iesection_currpos = sta_prof_iesection;
  1675. sta_prof_iesection_remlen = sta_prof_iesection_len;
  1676. while (sta_prof_iesection_remlen > 0) {
  1677. sta_prof_ie = sta_prof_iesection_currpos;
  1678. ret = util_validate_sta_prof_ie(sta_prof_ie,
  1679. sta_prof_iesection_currpos,
  1680. sta_prof_iesection_remlen);
  1681. if (QDF_IS_STATUS_ERROR(ret)) {
  1682. qdf_mem_free(mlieseqpayload_copy);
  1683. return ret;
  1684. }
  1685. sta_prof_ie_size = sta_prof_ie[TAG_LEN_POS] + MIN_IE_LEN;
  1686. if (!sta_prof_ie[0]) {
  1687. /* Skip this, since it has already been processed */
  1688. sta_prof_iesection_currpos += sta_prof_ie_size;
  1689. sta_prof_iesection_remlen -= sta_prof_ie_size;
  1690. continue;
  1691. }
  1692. /* Copy IE from STA profile into link specific frame. */
  1693. if ((link_frame_currpos + sta_prof_ie_size) <=
  1694. (link_frame + link_frame_maxsize)) {
  1695. qdf_mem_copy(link_frame_currpos,
  1696. sta_prof_ie,
  1697. sta_prof_ie_size);
  1698. link_frame_currpos += sta_prof_ie_size;
  1699. link_frame_currlen +=
  1700. sta_prof_ie_size;
  1701. if (reportingsta_ie[ID_POS] ==
  1702. WLAN_ELEMID_EXTN_ELEM) {
  1703. 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",
  1704. sta_prof_ie[ID_POS],
  1705. sta_prof_ie[IDEXT_POS],
  1706. sta_prof_ie_size);
  1707. } else {
  1708. mlo_debug("IE with element ID : %u (%zu octets) is present only in STA profile. Copied IE from STA profile to link specific frame",
  1709. sta_prof_ie[ID_POS],
  1710. sta_prof_ie_size);
  1711. }
  1712. sta_prof_ie[0] = 0;
  1713. } else {
  1714. if (sta_prof_ie[ID_POS] == WLAN_ELEMID_EXTN_ELEM) {
  1715. mlo_err_rl("Insufficent space in link specific frame for IE with element ID : %u extension element ID : %u. Required: %zu octets, available: %zu octets",
  1716. sta_prof_ie[ID_POS],
  1717. sta_prof_ie[IDEXT_POS],
  1718. sta_prof_ie_size,
  1719. link_frame_maxsize -
  1720. link_frame_currlen);
  1721. } else {
  1722. mlo_err_rl("Insufficent space in link specific frame for IE with element ID : %u. Required: %zu octets, available: %zu octets",
  1723. sta_prof_ie[ID_POS],
  1724. sta_prof_ie_size,
  1725. link_frame_maxsize -
  1726. link_frame_currlen);
  1727. }
  1728. qdf_mem_free(mlieseqpayload_copy);
  1729. return QDF_STATUS_E_NOMEM;
  1730. }
  1731. sta_prof_iesection_currpos += sta_prof_ie_size;
  1732. sta_prof_iesection_remlen -= sta_prof_ie_size;
  1733. }
  1734. /* Copy the link MAC addr */
  1735. link_frame_hdr = (struct wlan_frame_hdr *)link_frame;
  1736. if ((subtype == WLAN_FC0_STYPE_ASSOC_REQ) ||
  1737. (subtype == WLAN_FC0_STYPE_REASSOC_REQ)) {
  1738. qdf_mem_copy(link_frame_hdr->i_addr3, &link_addr,
  1739. QDF_MAC_ADDR_SIZE);
  1740. qdf_mem_copy(link_frame_hdr->i_addr2, reportedmacaddr.bytes,
  1741. QDF_MAC_ADDR_SIZE);
  1742. qdf_mem_copy(link_frame_hdr->i_addr1, &link_addr,
  1743. QDF_MAC_ADDR_SIZE);
  1744. link_frame_hdr->i_fc[0] = MLO_LINKSPECIFIC_ASSOC_REQ_FC0;
  1745. link_frame_hdr->i_fc[1] = MLO_LINKSPECIFIC_ASSOC_REQ_FC1;
  1746. } else {
  1747. /* This is a (re)association response */
  1748. qdf_mem_copy(link_frame_hdr->i_addr3, reportedmacaddr.bytes,
  1749. QDF_MAC_ADDR_SIZE);
  1750. qdf_mem_copy(link_frame_hdr->i_addr2, reportedmacaddr.bytes,
  1751. QDF_MAC_ADDR_SIZE);
  1752. qdf_mem_copy(link_frame_hdr->i_addr1, &link_addr,
  1753. QDF_MAC_ADDR_SIZE);
  1754. link_frame_hdr->i_fc[0] = MLO_LINKSPECIFIC_ASSOC_RESP_FC0;
  1755. link_frame_hdr->i_fc[1] = MLO_LINKSPECIFIC_ASSOC_RESP_FC1;
  1756. }
  1757. /* Seq num not used so not populated */
  1758. qdf_mem_free(mlieseqpayload_copy);
  1759. *link_frame_len = link_frame_currlen;
  1760. return QDF_STATUS_SUCCESS;
  1761. }
  1762. QDF_STATUS
  1763. util_gen_link_assoc_req(uint8_t *frame, qdf_size_t frame_len, bool isreassoc,
  1764. struct qdf_mac_addr link_addr,
  1765. uint8_t *link_frame,
  1766. qdf_size_t link_frame_maxsize,
  1767. qdf_size_t *link_frame_len)
  1768. {
  1769. return util_gen_link_assoc_reqrsp_cmn(frame, frame_len,
  1770. (isreassoc ? WLAN_FC0_STYPE_REASSOC_REQ :
  1771. WLAN_FC0_STYPE_ASSOC_REQ),
  1772. link_addr, link_frame, link_frame_maxsize,
  1773. link_frame_len);
  1774. }
  1775. QDF_STATUS
  1776. util_gen_link_assoc_rsp(uint8_t *frame, qdf_size_t frame_len, bool isreassoc,
  1777. struct qdf_mac_addr link_addr,
  1778. uint8_t *link_frame,
  1779. qdf_size_t link_frame_maxsize,
  1780. qdf_size_t *link_frame_len)
  1781. {
  1782. return util_gen_link_assoc_reqrsp_cmn(frame, frame_len,
  1783. (isreassoc ? WLAN_FC0_STYPE_REASSOC_RESP :
  1784. WLAN_FC0_STYPE_ASSOC_RESP),
  1785. link_addr, link_frame, link_frame_maxsize,
  1786. link_frame_len);
  1787. }
  1788. QDF_STATUS
  1789. util_find_mlie(uint8_t *buf, qdf_size_t buflen, uint8_t **mlieseq,
  1790. qdf_size_t *mlieseqlen)
  1791. {
  1792. uint8_t *bufboundary;
  1793. uint8_t *ieseq;
  1794. qdf_size_t ieseqlen;
  1795. uint8_t *currie;
  1796. uint8_t *successorfrag;
  1797. if (!buf || !buflen || !mlieseq || !mlieseqlen)
  1798. return QDF_STATUS_E_NULL_VALUE;
  1799. *mlieseq = NULL;
  1800. *mlieseqlen = 0;
  1801. /* Find Multi-Link element. In case a fragment sequence is present,
  1802. * this element will be the leading fragment.
  1803. */
  1804. ieseq = util_find_extn_eid(WLAN_ELEMID_EXTN_ELEM,
  1805. WLAN_EXTN_ELEMID_MULTI_LINK, buf,
  1806. buflen);
  1807. /* Even if the element is not found, we have successfully examined the
  1808. * buffer. The caller will be provided a NULL value for the starting of
  1809. * the Multi-Link element. Hence, we return success.
  1810. */
  1811. if (!ieseq)
  1812. return QDF_STATUS_SUCCESS;
  1813. bufboundary = buf + buflen;
  1814. if ((ieseq + MIN_IE_LEN) > bufboundary)
  1815. return QDF_STATUS_E_INVAL;
  1816. ieseqlen = MIN_IE_LEN + ieseq[TAG_LEN_POS];
  1817. if (ieseqlen < sizeof(struct wlan_ie_multilink))
  1818. return QDF_STATUS_E_PROTO;
  1819. if ((ieseq + ieseqlen) > bufboundary)
  1820. return QDF_STATUS_E_INVAL;
  1821. /* In the next sequence of checks, if there is no space in the buffer
  1822. * for another element after the Multi-Link element/element fragment
  1823. * sequence, it could indicate an issue since non-MLO EHT elements
  1824. * would be expected to follow the Multi-Link element/element fragment
  1825. * sequence. However, this is outside of the purview of this function,
  1826. * hence we ignore it.
  1827. */
  1828. currie = ieseq;
  1829. successorfrag = util_get_successorfrag(currie, buf, buflen);
  1830. /* Fragmentation definitions as of IEEE802.11be D1.0 and
  1831. * IEEE802.11REVme D0.2 are applied. Only the case where Multi-Link
  1832. * element is present in a buffer from the core frame is considered.
  1833. * Future changes to fragmentation, cases where the Multi-Link element
  1834. * is present in a subelement, etc. to be reflected here if applicable
  1835. * as and when the rules evolve.
  1836. */
  1837. while (successorfrag) {
  1838. /* We should not be seeing a successor fragment if the length
  1839. * of the current IE is lesser than the max.
  1840. */
  1841. if (currie[TAG_LEN_POS] != WLAN_MAX_IE_LEN)
  1842. return QDF_STATUS_E_PROTO;
  1843. if (successorfrag[TAG_LEN_POS] == 0)
  1844. return QDF_STATUS_E_PROTO;
  1845. ieseqlen += (MIN_IE_LEN + successorfrag[TAG_LEN_POS]);
  1846. currie = successorfrag;
  1847. successorfrag = util_get_successorfrag(currie, buf, buflen);
  1848. }
  1849. *mlieseq = ieseq;
  1850. *mlieseqlen = ieseqlen;
  1851. return QDF_STATUS_SUCCESS;
  1852. }
  1853. QDF_STATUS
  1854. util_get_mlie_common_info_len(uint8_t *mlieseq, qdf_size_t mlieseqlen,
  1855. uint8_t *commoninfo_len)
  1856. {
  1857. struct wlan_ie_multilink *mlie_fixed;
  1858. enum wlan_ml_variant variant;
  1859. uint16_t mlcontrol;
  1860. if (!mlieseq || !mlieseqlen || !commoninfo_len)
  1861. return QDF_STATUS_E_NULL_VALUE;
  1862. if (mlieseqlen < sizeof(struct wlan_ie_multilink))
  1863. return QDF_STATUS_E_INVAL;
  1864. mlie_fixed = (struct wlan_ie_multilink *)mlieseq;
  1865. if (mlie_fixed->elem_id != WLAN_ELEMID_EXTN_ELEM ||
  1866. mlie_fixed->elem_id_ext != WLAN_EXTN_ELEMID_MULTI_LINK)
  1867. return QDF_STATUS_E_INVAL;
  1868. mlcontrol = qdf_le16_to_cpu(mlie_fixed->mlcontrol);
  1869. variant = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_TYPE_IDX,
  1870. WLAN_ML_CTRL_TYPE_BITS);
  1871. if (variant != WLAN_ML_VARIANT_BASIC)
  1872. return QDF_STATUS_E_INVAL;
  1873. /* Common Info starts at mlieseq + sizeof(struct wlan_ie_multilink).
  1874. * Check if there is sufficient space in the buffer for the Common Info
  1875. * Length and MLD MAC address.
  1876. */
  1877. if ((sizeof(struct wlan_ie_multilink) + WLAN_ML_BV_CINFO_LENGTH_SIZE +
  1878. QDF_MAC_ADDR_SIZE) > mlieseqlen)
  1879. return QDF_STATUS_E_PROTO;
  1880. *commoninfo_len = *(mlieseq + sizeof(struct wlan_ie_multilink));
  1881. return QDF_STATUS_SUCCESS;
  1882. }
  1883. QDF_STATUS
  1884. util_get_bvmlie_bssparamchangecnt(uint8_t *mlieseq, qdf_size_t mlieseqlen,
  1885. bool *bssparamchangecntfound,
  1886. uint8_t *bssparamchangecnt)
  1887. {
  1888. struct wlan_ie_multilink *mlie_fixed;
  1889. enum wlan_ml_variant variant;
  1890. uint16_t mlcontrol;
  1891. uint16_t presencebitmap;
  1892. uint8_t *commoninfo;
  1893. qdf_size_t commoninfolen;
  1894. if (!mlieseq || !mlieseqlen || !bssparamchangecntfound ||
  1895. !bssparamchangecnt)
  1896. return QDF_STATUS_E_NULL_VALUE;
  1897. *bssparamchangecntfound = false;
  1898. *bssparamchangecnt = 0;
  1899. if (mlieseqlen < sizeof(struct wlan_ie_multilink))
  1900. return QDF_STATUS_E_INVAL;
  1901. mlie_fixed = (struct wlan_ie_multilink *)mlieseq;
  1902. if (mlie_fixed->elem_id != WLAN_ELEMID_EXTN_ELEM ||
  1903. mlie_fixed->elem_id_ext != WLAN_EXTN_ELEMID_MULTI_LINK)
  1904. return QDF_STATUS_E_INVAL;
  1905. mlcontrol = qdf_le16_to_cpu(mlie_fixed->mlcontrol);
  1906. variant = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_TYPE_IDX,
  1907. WLAN_ML_CTRL_TYPE_BITS);
  1908. if (variant != WLAN_ML_VARIANT_BASIC)
  1909. return QDF_STATUS_E_NOSUPPORT;
  1910. presencebitmap = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_PBM_IDX,
  1911. WLAN_ML_CTRL_PBM_BITS);
  1912. commoninfo = mlieseq + sizeof(struct wlan_ie_multilink);
  1913. commoninfolen = WLAN_ML_BV_CINFO_LENGTH_SIZE;
  1914. commoninfolen += QDF_MAC_ADDR_SIZE;
  1915. if (presencebitmap & WLAN_ML_BV_CTRL_PBM_LINKIDINFO_P) {
  1916. commoninfolen += WLAN_ML_BV_CINFO_LINKIDINFO_SIZE;
  1917. if ((sizeof(struct wlan_ie_multilink) + commoninfolen) >
  1918. mlieseqlen)
  1919. return QDF_STATUS_E_PROTO;
  1920. }
  1921. if (presencebitmap & WLAN_ML_BV_CTRL_PBM_BSSPARAMCHANGECNT_P) {
  1922. *bssparamchangecntfound = true;
  1923. *bssparamchangecnt = *(commoninfo + commoninfolen);
  1924. }
  1925. return QDF_STATUS_SUCCESS;
  1926. }
  1927. QDF_STATUS
  1928. util_get_mlie_variant(uint8_t *mlieseq, qdf_size_t mlieseqlen,
  1929. int *variant)
  1930. {
  1931. struct wlan_ie_multilink *mlie_fixed;
  1932. enum wlan_ml_variant var;
  1933. uint16_t mlcontrol;
  1934. if (!mlieseq || !mlieseqlen || !variant)
  1935. return QDF_STATUS_E_NULL_VALUE;
  1936. if (mlieseqlen < sizeof(struct wlan_ie_multilink))
  1937. return QDF_STATUS_E_INVAL;
  1938. mlie_fixed = (struct wlan_ie_multilink *)mlieseq;
  1939. if ((mlie_fixed->elem_id != WLAN_ELEMID_EXTN_ELEM) ||
  1940. (mlie_fixed->elem_id_ext != WLAN_EXTN_ELEMID_MULTI_LINK))
  1941. return QDF_STATUS_E_INVAL;
  1942. mlcontrol = le16toh(mlie_fixed->mlcontrol);
  1943. var = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_TYPE_IDX,
  1944. WLAN_ML_CTRL_TYPE_BITS);
  1945. if (var >= WLAN_ML_VARIANT_INVALIDSTART)
  1946. return QDF_STATUS_E_PROTO;
  1947. *variant = var;
  1948. return QDF_STATUS_SUCCESS;
  1949. }
  1950. QDF_STATUS
  1951. util_get_bvmlie_eml_cap(uint8_t *mlieseq, qdf_size_t mlieseqlen,
  1952. bool *eml_cap_found,
  1953. uint16_t *eml_cap)
  1954. {
  1955. struct wlan_ie_multilink *mlie_fixed;
  1956. enum wlan_ml_variant variant;
  1957. uint16_t mlcontrol;
  1958. uint8_t eml_cap_offset;
  1959. uint8_t commoninfo_len;
  1960. uint16_t presencebitmap;
  1961. if (!mlieseq || !mlieseqlen || !eml_cap_found || !eml_cap)
  1962. return QDF_STATUS_E_NULL_VALUE;
  1963. *eml_cap = 0;
  1964. *eml_cap_found = false;
  1965. if (mlieseqlen < sizeof(struct wlan_ie_multilink))
  1966. return QDF_STATUS_E_INVAL;
  1967. mlie_fixed = (struct wlan_ie_multilink *)mlieseq;
  1968. if ((mlie_fixed->elem_id != WLAN_ELEMID_EXTN_ELEM) ||
  1969. (mlie_fixed->elem_id_ext != WLAN_EXTN_ELEMID_MULTI_LINK))
  1970. return QDF_STATUS_E_INVAL;
  1971. mlcontrol = qdf_le16_to_cpu(mlie_fixed->mlcontrol);
  1972. variant = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_TYPE_IDX,
  1973. WLAN_ML_CTRL_TYPE_BITS);
  1974. if (variant != WLAN_ML_VARIANT_BASIC)
  1975. return QDF_STATUS_E_INVAL;
  1976. presencebitmap = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_PBM_IDX,
  1977. WLAN_ML_CTRL_PBM_BITS);
  1978. /* eml_cap_offset stores the offset of EML Capabilities within
  1979. * Common Info
  1980. */
  1981. eml_cap_offset = WLAN_ML_BV_CINFO_LENGTH_SIZE + QDF_MAC_ADDR_SIZE;
  1982. if (presencebitmap & WLAN_ML_BV_CTRL_PBM_LINKIDINFO_P)
  1983. eml_cap_offset += WLAN_ML_BV_CINFO_LINKIDINFO_SIZE;
  1984. if (presencebitmap & WLAN_ML_BV_CTRL_PBM_BSSPARAMCHANGECNT_P)
  1985. eml_cap_offset += WLAN_ML_BV_CINFO_BSSPARAMCHNGCNT_SIZE;
  1986. if (presencebitmap & WLAN_ML_BV_CTRL_PBM_MEDIUMSYNCDELAYINFO_P)
  1987. eml_cap_offset += WLAN_ML_BV_CINFO_MEDMSYNCDELAYINFO_SIZE;
  1988. if (presencebitmap & WLAN_ML_BV_CTRL_PBM_EMLCAP_P) {
  1989. /* Common Info starts at
  1990. * mlieseq + sizeof(struct wlan_ie_multilink).
  1991. * Check if there is sufficient space in the buffer for
  1992. * the Common Info Length.
  1993. */
  1994. if (mlieseqlen < (sizeof(struct wlan_ie_multilink) +
  1995. WLAN_ML_BV_CINFO_LENGTH_SIZE))
  1996. return QDF_STATUS_E_PROTO;
  1997. /* Check if the value indicated in the Common Info Length
  1998. * subfield is sufficient to access the EML capabilities.
  1999. */
  2000. commoninfo_len = *(mlieseq + sizeof(struct wlan_ie_multilink));
  2001. if (commoninfo_len < (eml_cap_offset +
  2002. WLAN_ML_BV_CINFO_EMLCAP_SIZE))
  2003. return QDF_STATUS_E_PROTO;
  2004. /* Common Info starts at mlieseq + sizeof(struct
  2005. * wlan_ie_multilink). Check if there is sufficient space in
  2006. * Common Info for the EML capability.
  2007. */
  2008. if (mlieseqlen < (sizeof(struct wlan_ie_multilink) +
  2009. eml_cap_offset +
  2010. WLAN_ML_BV_CINFO_EMLCAP_SIZE))
  2011. return QDF_STATUS_E_PROTO;
  2012. *eml_cap_found = true;
  2013. *eml_cap = qdf_le16_to_cpu(*(uint16_t *)(mlieseq +
  2014. sizeof(struct wlan_ie_multilink) +
  2015. eml_cap_offset));
  2016. }
  2017. return QDF_STATUS_SUCCESS;
  2018. }
  2019. QDF_STATUS
  2020. util_get_bvmlie_mldmacaddr(uint8_t *mlieseq, qdf_size_t mlieseqlen,
  2021. struct qdf_mac_addr *mldmacaddr)
  2022. {
  2023. struct wlan_ie_multilink *mlie_fixed;
  2024. enum wlan_ml_variant variant;
  2025. uint16_t mlcontrol;
  2026. uint8_t commoninfo_len;
  2027. if (!mlieseq || !mlieseqlen || !mldmacaddr)
  2028. return QDF_STATUS_E_NULL_VALUE;
  2029. qdf_mem_zero(mldmacaddr, sizeof(*mldmacaddr));
  2030. if (mlieseqlen < sizeof(struct wlan_ie_multilink))
  2031. return QDF_STATUS_E_INVAL;
  2032. mlie_fixed = (struct wlan_ie_multilink *)mlieseq;
  2033. if ((mlie_fixed->elem_id != WLAN_ELEMID_EXTN_ELEM) ||
  2034. (mlie_fixed->elem_id_ext != WLAN_EXTN_ELEMID_MULTI_LINK))
  2035. return QDF_STATUS_E_INVAL;
  2036. mlcontrol = qdf_le16_to_cpu(mlie_fixed->mlcontrol);
  2037. variant = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_TYPE_IDX,
  2038. WLAN_ML_CTRL_TYPE_BITS);
  2039. if (variant != WLAN_ML_VARIANT_BASIC)
  2040. return QDF_STATUS_E_INVAL;
  2041. /* Common Info starts at mlieseq + sizeof(struct wlan_ie_multilink).
  2042. * Check if there is sufficient space in the buffer for the Common Info
  2043. * Length and MLD MAC address.
  2044. */
  2045. if ((sizeof(struct wlan_ie_multilink) + WLAN_ML_BV_CINFO_LENGTH_SIZE +
  2046. QDF_MAC_ADDR_SIZE) > mlieseqlen)
  2047. return QDF_STATUS_E_PROTO;
  2048. /* Check if the value indicated in the Common Info Length subfield is
  2049. * sufficient to access the MLD MAC address.
  2050. */
  2051. commoninfo_len = *(mlieseq + sizeof(struct wlan_ie_multilink));
  2052. if (commoninfo_len < (WLAN_ML_BV_CINFO_LENGTH_SIZE + QDF_MAC_ADDR_SIZE))
  2053. return QDF_STATUS_E_PROTO;
  2054. qdf_mem_copy(mldmacaddr->bytes,
  2055. mlieseq + sizeof(struct wlan_ie_multilink) +
  2056. WLAN_ML_BV_CINFO_LENGTH_SIZE,
  2057. QDF_MAC_ADDR_SIZE);
  2058. return QDF_STATUS_SUCCESS;
  2059. }
  2060. QDF_STATUS
  2061. util_get_bvmlie_primary_linkid(uint8_t *mlieseq, qdf_size_t mlieseqlen,
  2062. bool *linkidfound, uint8_t *linkid)
  2063. {
  2064. struct wlan_ie_multilink *mlie_fixed;
  2065. enum wlan_ml_variant variant;
  2066. uint16_t mlcontrol;
  2067. uint16_t presencebitmap;
  2068. uint8_t *commoninfo;
  2069. qdf_size_t commoninfolen;
  2070. uint8_t *linkidinfo;
  2071. if (!mlieseq || !mlieseqlen || !linkidfound || !linkid)
  2072. return QDF_STATUS_E_NULL_VALUE;
  2073. *linkidfound = false;
  2074. *linkid = 0;
  2075. if (mlieseqlen < sizeof(struct wlan_ie_multilink))
  2076. return QDF_STATUS_E_INVAL;
  2077. mlie_fixed = (struct wlan_ie_multilink *)mlieseq;
  2078. if ((mlie_fixed->elem_id != WLAN_ELEMID_EXTN_ELEM) ||
  2079. (mlie_fixed->elem_id_ext != WLAN_EXTN_ELEMID_MULTI_LINK))
  2080. return QDF_STATUS_E_INVAL;
  2081. mlcontrol = le16toh(mlie_fixed->mlcontrol);
  2082. variant = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_TYPE_IDX,
  2083. WLAN_ML_CTRL_TYPE_BITS);
  2084. if (variant != WLAN_ML_VARIANT_BASIC)
  2085. return QDF_STATUS_E_INVAL;
  2086. presencebitmap = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_PBM_IDX,
  2087. WLAN_ML_CTRL_PBM_BITS);
  2088. commoninfo = mlieseq + sizeof(struct wlan_ie_multilink);
  2089. commoninfolen = 0;
  2090. commoninfolen += WLAN_ML_BV_CINFO_LENGTH_SIZE;
  2091. if ((sizeof(struct wlan_ie_multilink) + commoninfolen) >
  2092. mlieseqlen)
  2093. return QDF_STATUS_E_PROTO;
  2094. commoninfolen += QDF_MAC_ADDR_SIZE;
  2095. if ((sizeof(struct wlan_ie_multilink) + commoninfolen) >
  2096. mlieseqlen)
  2097. return QDF_STATUS_E_PROTO;
  2098. if (presencebitmap & WLAN_ML_BV_CTRL_PBM_LINKIDINFO_P) {
  2099. linkidinfo = commoninfo + commoninfolen;
  2100. commoninfolen += WLAN_ML_BV_CINFO_LINKIDINFO_SIZE;
  2101. if ((sizeof(struct wlan_ie_multilink) + commoninfolen) >
  2102. mlieseqlen)
  2103. return QDF_STATUS_E_PROTO;
  2104. *linkidfound = true;
  2105. *linkid = QDF_GET_BITS(linkidinfo[0],
  2106. WLAN_ML_BV_CINFO_LINKIDINFO_LINKID_IDX,
  2107. WLAN_ML_BV_CINFO_LINKIDINFO_LINKID_BITS);
  2108. }
  2109. return QDF_STATUS_SUCCESS;
  2110. }
  2111. QDF_STATUS
  2112. util_get_bvmlie_mldcap(uint8_t *mlieseq, qdf_size_t mlieseqlen,
  2113. bool *mldcapfound, uint16_t *mldcap)
  2114. {
  2115. struct wlan_ie_multilink *mlie_fixed;
  2116. enum wlan_ml_variant variant;
  2117. uint16_t mlcontrol;
  2118. uint16_t presencebitmap;
  2119. uint8_t *commoninfo;
  2120. qdf_size_t commoninfolen;
  2121. if (!mlieseq || !mlieseqlen || !mldcapfound || !mldcap)
  2122. return QDF_STATUS_E_NULL_VALUE;
  2123. *mldcapfound = false;
  2124. *mldcap = 0;
  2125. if (mlieseqlen < sizeof(struct wlan_ie_multilink))
  2126. return QDF_STATUS_E_INVAL;
  2127. mlie_fixed = (struct wlan_ie_multilink *)mlieseq;
  2128. if (mlie_fixed->elem_id != WLAN_ELEMID_EXTN_ELEM ||
  2129. mlie_fixed->elem_id_ext != WLAN_EXTN_ELEMID_MULTI_LINK)
  2130. return QDF_STATUS_E_INVAL;
  2131. mlcontrol = qdf_le16_to_cpu(mlie_fixed->mlcontrol);
  2132. variant = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_TYPE_IDX,
  2133. WLAN_ML_CTRL_TYPE_BITS);
  2134. if (variant != WLAN_ML_VARIANT_BASIC)
  2135. return QDF_STATUS_E_NOSUPPORT;
  2136. presencebitmap = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_PBM_IDX,
  2137. WLAN_ML_CTRL_PBM_BITS);
  2138. commoninfo = mlieseq + sizeof(struct wlan_ie_multilink);
  2139. commoninfolen = WLAN_ML_BV_CINFO_LENGTH_SIZE;
  2140. commoninfolen += QDF_MAC_ADDR_SIZE;
  2141. if (presencebitmap & WLAN_ML_BV_CTRL_PBM_LINKIDINFO_P) {
  2142. commoninfolen += WLAN_ML_BV_CINFO_LINKIDINFO_SIZE;
  2143. if ((sizeof(struct wlan_ie_multilink) + commoninfolen) >
  2144. mlieseqlen)
  2145. return QDF_STATUS_E_PROTO;
  2146. }
  2147. if (presencebitmap & WLAN_ML_BV_CTRL_PBM_BSSPARAMCHANGECNT_P) {
  2148. commoninfolen += WLAN_ML_BV_CINFO_BSSPARAMCHNGCNT_SIZE;
  2149. if ((sizeof(struct wlan_ie_multilink) + commoninfolen) >
  2150. mlieseqlen)
  2151. return QDF_STATUS_E_PROTO;
  2152. }
  2153. if (presencebitmap & WLAN_ML_BV_CTRL_PBM_MEDIUMSYNCDELAYINFO_P) {
  2154. commoninfolen += WLAN_ML_BV_CINFO_MEDMSYNCDELAYINFO_SIZE;
  2155. if ((sizeof(struct wlan_ie_multilink) + commoninfolen) >
  2156. mlieseqlen)
  2157. return QDF_STATUS_E_PROTO;
  2158. }
  2159. if (presencebitmap & WLAN_ML_BV_CTRL_PBM_EMLCAP_P) {
  2160. commoninfolen += WLAN_ML_BV_CINFO_EMLCAP_SIZE;
  2161. if ((sizeof(struct wlan_ie_multilink) + commoninfolen) >
  2162. mlieseqlen)
  2163. return QDF_STATUS_E_PROTO;
  2164. }
  2165. if (presencebitmap & WLAN_ML_BV_CTRL_PBM_MLDCAP_P) {
  2166. if ((sizeof(struct wlan_ie_multilink) + commoninfolen +
  2167. WLAN_ML_BV_CINFO_MLDCAP_SIZE) >
  2168. mlieseqlen)
  2169. return QDF_STATUS_E_PROTO;
  2170. *mldcap = *((uint16_t *)(commoninfo + commoninfolen));
  2171. commoninfolen += WLAN_ML_BV_CINFO_MLDCAP_SIZE;
  2172. *mldcapfound = true;
  2173. }
  2174. return QDF_STATUS_SUCCESS;
  2175. }
  2176. QDF_STATUS
  2177. util_get_bvmlie_persta_partner_info(uint8_t *mlieseq,
  2178. qdf_size_t mlieseqlen,
  2179. struct mlo_partner_info *partner_info)
  2180. {
  2181. struct wlan_ie_multilink *mlie_fixed;
  2182. uint16_t mlcontrol;
  2183. enum wlan_ml_variant variant;
  2184. uint8_t *linkinfo;
  2185. qdf_size_t linkinfo_len;
  2186. struct mlo_partner_info pinfo = {0};
  2187. qdf_size_t mlieseqpayloadlen;
  2188. uint8_t *mlieseqpayload_copy;
  2189. bool is_elemfragseq;
  2190. qdf_size_t defragpayload_len;
  2191. qdf_size_t tmplen;
  2192. QDF_STATUS ret;
  2193. if (!mlieseq) {
  2194. mlo_err("Pointer to Multi-Link element sequence is NULL");
  2195. return QDF_STATUS_E_NULL_VALUE;
  2196. }
  2197. if (!mlieseqlen) {
  2198. mlo_err("Length of Multi-Link element sequence is zero");
  2199. return QDF_STATUS_E_INVAL;
  2200. }
  2201. if (!partner_info) {
  2202. mlo_err("partner_info is NULL");
  2203. return QDF_STATUS_E_NULL_VALUE;
  2204. }
  2205. partner_info->num_partner_links = 0;
  2206. if (mlieseqlen < sizeof(struct wlan_ie_multilink)) {
  2207. mlo_err_rl("Multi-Link element sequence length %zu octets is smaller than required for the fixed portion of Multi-Link element (%zu octets)",
  2208. mlieseqlen, sizeof(struct wlan_ie_multilink));
  2209. return QDF_STATUS_E_INVAL;
  2210. }
  2211. mlie_fixed = (struct wlan_ie_multilink *)mlieseq;
  2212. if ((mlie_fixed->elem_id != WLAN_ELEMID_EXTN_ELEM) ||
  2213. (mlie_fixed->elem_id_ext != WLAN_EXTN_ELEMID_MULTI_LINK)) {
  2214. mlo_err("The element is not a Multi-Link element");
  2215. return QDF_STATUS_E_INVAL;
  2216. }
  2217. mlcontrol = le16toh(mlie_fixed->mlcontrol);
  2218. variant = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_TYPE_IDX,
  2219. WLAN_ML_CTRL_TYPE_BITS);
  2220. if (variant != WLAN_ML_VARIANT_BASIC) {
  2221. mlo_err("The variant value %u does not correspond to Basic Variant value %u",
  2222. variant, WLAN_ML_VARIANT_BASIC);
  2223. return QDF_STATUS_E_INVAL;
  2224. }
  2225. mlieseqpayloadlen = 0;
  2226. tmplen = 0;
  2227. is_elemfragseq = false;
  2228. ret = wlan_get_elem_fragseq_info(mlieseq,
  2229. mlieseqlen,
  2230. &is_elemfragseq,
  2231. &tmplen,
  2232. &mlieseqpayloadlen);
  2233. if (QDF_IS_STATUS_ERROR(ret))
  2234. return ret;
  2235. if (is_elemfragseq) {
  2236. if (tmplen != mlieseqlen) {
  2237. 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",
  2238. tmplen, mlieseqlen);
  2239. return QDF_STATUS_E_INVAL;
  2240. }
  2241. if (!mlieseqpayloadlen) {
  2242. mlo_err_rl("Multi-Link element fragment sequence payload is reported as 0, investigate");
  2243. return QDF_STATUS_E_FAILURE;
  2244. }
  2245. mlo_debug("Multi-Link element fragment sequence found with payload len %zu",
  2246. mlieseqpayloadlen);
  2247. } else {
  2248. if (mlieseqlen > (sizeof(struct ie_header) + WLAN_MAX_IE_LEN)) {
  2249. 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",
  2250. mlieseqlen,
  2251. sizeof(struct ie_header) + WLAN_MAX_IE_LEN);
  2252. return QDF_STATUS_E_FAILURE;
  2253. }
  2254. mlieseqpayloadlen = mlieseqlen - (sizeof(struct ie_header) + 1);
  2255. }
  2256. mlieseqpayload_copy = qdf_mem_malloc(mlieseqpayloadlen);
  2257. if (!mlieseqpayload_copy) {
  2258. mlo_err_rl("Could not allocate memory for Multi-Link element payload copy");
  2259. return QDF_STATUS_E_NOMEM;
  2260. }
  2261. if (is_elemfragseq) {
  2262. ret = wlan_defrag_elem_fragseq(false,
  2263. mlieseq,
  2264. mlieseqlen,
  2265. mlieseqpayload_copy,
  2266. mlieseqpayloadlen,
  2267. &defragpayload_len);
  2268. if (QDF_IS_STATUS_ERROR(ret)) {
  2269. qdf_mem_free(mlieseqpayload_copy);
  2270. return ret;
  2271. }
  2272. if (defragpayload_len != mlieseqpayloadlen) {
  2273. mlo_err_rl("Length of de-fragmented payload %zu octets is not equal to length of Multi-Link element fragment sequence payload %zu octets",
  2274. defragpayload_len, mlieseqpayloadlen);
  2275. qdf_mem_free(mlieseqpayload_copy);
  2276. return QDF_STATUS_E_FAILURE;
  2277. }
  2278. } else {
  2279. qdf_mem_copy(mlieseqpayload_copy,
  2280. mlieseq + sizeof(struct ie_header) + 1,
  2281. mlieseqpayloadlen);
  2282. }
  2283. linkinfo = NULL;
  2284. linkinfo_len = 0;
  2285. ret = util_parse_multi_link_ctrl(mlieseqpayload_copy,
  2286. mlieseqpayloadlen,
  2287. &linkinfo,
  2288. &linkinfo_len);
  2289. if (QDF_IS_STATUS_ERROR(ret)) {
  2290. qdf_mem_free(mlieseqpayload_copy);
  2291. return ret;
  2292. }
  2293. /* In case Link Info is absent, the number of partner links will remain
  2294. * zero.
  2295. */
  2296. if (!linkinfo) {
  2297. qdf_mem_free(mlieseqpayload_copy);
  2298. return QDF_STATUS_SUCCESS;
  2299. }
  2300. ret = util_parse_partner_info_from_linkinfo(linkinfo,
  2301. linkinfo_len,
  2302. &pinfo);
  2303. if (QDF_IS_STATUS_ERROR(ret)) {
  2304. qdf_mem_free(mlieseqpayload_copy);
  2305. return ret;
  2306. }
  2307. qdf_mem_copy(partner_info, &pinfo, sizeof(*partner_info));
  2308. qdf_mem_free(mlieseqpayload_copy);
  2309. return QDF_STATUS_SUCCESS;
  2310. }
  2311. #endif