gl_p2p.c 137 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654
  1. /*
  2. ** Id: @(#) gl_p2p.c@@
  3. */
  4. /*! \file gl_p2p.c
  5. \brief Main routines of Linux driver interface for Wi-Fi Direct
  6. This file contains the main routines of Linux driver for MediaTek Inc. 802.11
  7. Wireless LAN Adapters.
  8. */
  9. /*
  10. ** Log: gl_p2p.c
  11. **
  12. ** 04 14 2014 eason.tsai
  13. ** [ALPS01510349] [6595][KK][HotKnot][Reboot][KE][p2pDevFsmRunEventScanDone]Sender
  14. ** reboot automatically with KE about p2pDevFsmRunEventScanDone.
  15. ** fix KE
  16. **
  17. ** 01 23 2014 eason.tsai
  18. ** [ALPS01070904] [Need Patch] [Volunteer Patch][MT6630][Driver]MT6630 Wi-Fi Patch
  19. ** fix ap mode
  20. **
  21. ** 07 31 2013 yuche.tsai
  22. ** [BORA00002398] [MT6630][Volunteer Patch] P2P Driver Re-Design for Multiple BSS support
  23. ** Change private data of net device.
  24. **
  25. ** 07 30 2013 yuche.tsai
  26. ** [BORA00002398] [MT6630][Volunteer Patch] P2P Driver Re-Design for Multiple BSS support
  27. ** Temp fix Hot-spot data path issue.
  28. **
  29. ** 07 30 2013 yuche.tsai
  30. ** [BORA00002398] [MT6630][Volunteer Patch] P2P Driver Re-Design for Multiple BSS support
  31. ** MT6630 Driver Update for Hot-Spot.
  32. **
  33. ** 07 29 2013 cp.wu
  34. ** [BORA00002725] [MT6630][Wi-Fi] Add MGMT TX/RX support for Linux port
  35. ** Preparation for porting remain_on_channel support
  36. **
  37. ** 07 26 2013 terry.wu
  38. ** [BORA00002207] [MT6630 Wi-Fi] TXM & MQM Implementation
  39. ** 1. Reduce extra Tx frame header parsing
  40. ** 2. Add TX port control
  41. ** 3. Add net interface to BSS binding
  42. **
  43. ** 07 19 2013 yuche.tsai
  44. ** [BORA00002398] [MT6630][Volunteer Patch] P2P Driver Re-Design for Multiple BSS support
  45. ** Code update for P2P.
  46. **
  47. ** 07 17 2013 yuche.tsai
  48. ** [BORA00002398] [MT6630][Volunteer Patch] P2P Driver Re-Design for Multiple BSS support
  49. ** MT6630 P2P first connection check point 1.
  50. **
  51. ** 02 27 2013 yuche.tsai
  52. ** [BORA00002398] [MT6630][Volunteer Patch] P2P Driver Re-Design for Multiple BSS support
  53. ** Add new code, fix compile warning.
  54. **
  55. ** 01 23 2013 terry.wu
  56. ** [BORA00002207] [MT6630 Wi-Fi] TXM & MQM Implementation
  57. ** Refine net dev implementation
  58. **
  59. ** 01 21 2013 terry.wu
  60. ** [BORA00002207] [MT6630 Wi-Fi] TXM & MQM Implementation
  61. ** Update TX path based on new ucBssIndex modifications.
  62. **
  63. ** 01 17 2013 cm.chang
  64. ** [BORA00002149] [MT6630 Wi-Fi] Initial software development
  65. ** Use ucBssIndex to replace eNetworkTypeIndex
  66. **
  67. ** 09 17 2012 cm.chang
  68. ** [BORA00002149] [MT6630 Wi-Fi] Initial software development
  69. ** Duplicate source from MT6620 v2.3 driver branch
  70. ** (Davinci label: MT6620_WIFI_Driver_V2_3_120913_1942_As_MT6630_Base)
  71. **
  72. ** 08 24 2012 yuche.tsai
  73. ** NULL
  74. ** Fix bug of invitation request.
  75. **
  76. ** 08 17 2012 yuche.tsai
  77. ** NULL
  78. ** Fix compile warning.
  79. **
  80. ** 08 16 2012 yuche.tsai
  81. ** NULL
  82. ** Fix compile warning.
  83. **
  84. ** 08 15 2012 yuche.tsai
  85. ** NULL
  86. ** Fix compile warning.
  87. **
  88. ** 07 31 2012 yuche.tsai
  89. ** NULL
  90. ** Update Active/Deactive network policy for P2P network.
  91. ** Highly related to power saving.
  92. **
  93. ** 07 24 2012 yuche.tsai
  94. ** NULL
  95. ** Bug fix for JB.
  96. **
  97. ** 07 20 2012 yuche.tsai
  98. ** [WCXRP00001119] [Volunteer Patch][WiFi Direct][Driver] Connection Policy Set for WFD SIGMA test
  99. ** Support remain on channel.
  100. **
  101. ** 07 19 2012 yuche.tsai
  102. ** NULL
  103. ** Update code for net device register.
  104. **
  105. ** 07 19 2012 yuche.tsai
  106. ** NULL
  107. ** Code update for JB.
  108. *
  109. * 07 17 2012 yuche.tsai
  110. * NULL
  111. * Fix compile error for JB.
  112. *
  113. * 07 17 2012 yuche.tsai
  114. * NULL
  115. * Let netdev bring up.
  116. *
  117. * 07 17 2012 yuche.tsai
  118. * NULL
  119. * Compile no error before trial run.
  120. *
  121. * 01 09 2012 terry.wu
  122. * [WCXRP00001166] [Wi-Fi] [Driver] cfg80211 integration for p2p newtork
  123. * cfg80211 integration for p2p network.
  124. *
  125. * 12 19 2011 terry.wu
  126. * [WCXRP00001142] [Wi-Fi] [P2P Driver] XOR local admin bit to generate p2p net device MAC
  127. * XOR local administrated bit to generate net device MAC of p2p network.
  128. *
  129. * 12 02 2011 yuche.tsai
  130. * NULL
  131. * Fix possible KE when unload p2p.
  132. *
  133. * 11 24 2011 yuche.tsai
  134. * NULL
  135. * Fix P2P IOCTL of multicast address bug, add low power driver stop control.
  136. *
  137. * 11 22 2011 yuche.tsai
  138. * NULL
  139. * Update RSSI link quality of P2P Network query method. (Bug fix)
  140. *
  141. * 11 19 2011 yuche.tsai
  142. * NULL
  143. * Add RSSI support for P2P network.
  144. *
  145. * 11 16 2011 yuche.tsai
  146. * [WCXRP00001107] [Volunteer Patch][Driver] Large Network Type index assert in FW issue.
  147. * Avoid using work thread in set p2p multicast address callback.
  148. *
  149. * 11 11 2011 yuche.tsai
  150. * NULL
  151. * Fix work thread cancel issue.
  152. *
  153. * 11 11 2011 yuche.tsai
  154. * NULL
  155. * Fix default device name issue.
  156. *
  157. * 11 08 2011 yuche.tsai
  158. * [WCXRP00001094] [Volunteer Patch][Driver] Driver version & supplicant version query & set support for service
  159. * discovery version check.
  160. * Add support for driver version query & p2p supplicant verseion set.
  161. * For new service discovery mechanism sync.
  162. *
  163. * 11 07 2011 yuche.tsai
  164. * NULL
  165. * [ALPS 00087243] KE in worker thread.
  166. * The multicast address list is scheduled in worker thread.
  167. * Before the worker thread is excuted, if P2P is unloaded, a KE may occur.
  168. *
  169. * 10 26 2011 terry.wu
  170. * [WCXRP00001066] [MT6620 Wi-Fi] [P2P Driver] Fix P2P Oid Issue
  171. * Fix some P2P OID functions didn't raise its flag "fgIsP2pOid" issue.
  172. *
  173. * 10 25 2011 cm.chang
  174. * [WCXRP00001058] [All Wi-Fi][Driver] Fix sta_rec's phyTypeSet and OBSS scan in AP mode
  175. * .
  176. *
  177. * 10 18 2011 yuche.tsai
  178. * [WCXRP00001045] [WiFi Direct][Driver] Check 2.1 branch.
  179. * Support Channel Query.
  180. *
  181. * 10 18 2011 yuche.tsai
  182. * [WCXRP00001045] [WiFi Direct][Driver] Check 2.1 branch.
  183. * New 2.1 branch
  184. *
  185. * 08 26 2011 yuche.tsai
  186. * NULL
  187. * Fix bug of parsing secondary device list type issue.
  188. *
  189. * 08 24 2011 yuche.tsai
  190. * [WCXRP00000919] [Volunteer Patch][WiFi Direct][Driver] Invitation New Feature.
  191. * Invitation Abort.
  192. *
  193. * 08 23 2011 yuche.tsai
  194. * NULL
  195. * Fix multicast address list issue of P2P.
  196. *
  197. * 08 22 2011 chinglan.wang
  198. * NULL
  199. * Fix invitation indication bug..
  200. *
  201. * 08 16 2011 cp.wu
  202. * [WCXRP00000934] [MT6620 Wi-Fi][Driver][P2P] Wi-Fi hot spot with auto sparse channel residence
  203. * auto channel decision for 2.4GHz hot spot mode
  204. *
  205. * 08 16 2011 chinglan.wang
  206. * NULL
  207. * Add the group id information in the invitation indication.
  208. *
  209. * 08 09 2011 yuche.tsai
  210. * [WCXRP00000919] [Volunteer Patch][WiFi Direct][Driver] Invitation New Feature.
  211. * Invitation Feature add on.
  212. *
  213. * 08 05 2011 yuche.tsai
  214. * [WCXRP00000856] [Volunteer Patch][WiFi Direct][Driver] MT6620 WiFi Direct IOT Issue with BCM solution.
  215. * Add Password ID check for quick connection.
  216. * Also modify some connection policy.
  217. *
  218. * 07 18 2011 chinglan.wang
  219. * NULL
  220. * Add IOC_P2P_GO_WSC_IE (p2p capability).
  221. *
  222. * 06 14 2011 yuche.tsai
  223. * NULL
  224. * Add compile flag to disable persistent group support.
  225. *
  226. * 05 04 2011 chinglan.wang
  227. * [WCXRP00000698] [MT6620 Wi-Fi][P2P][Driver] Add p2p invitation command for the p2p driver
  228. * .
  229. *
  230. * 05 02 2011 yuche.tsai
  231. * [WCXRP00000693] [Volunteer Patch][MT6620][Driver] Clear Formation Flag after TX lifetime timeout.
  232. * Clear formation flag after formation timeout.
  233. *
  234. * 04 22 2011 george.huang
  235. * [WCXRP00000621] [MT6620 Wi-Fi][Driver] Support P2P supplicant to set power mode
  236. * .
  237. *
  238. * 04 21 2011 george.huang
  239. * [WCXRP00000621] [MT6620 Wi-Fi][Driver] Support P2P supplicant to set power mode
  240. * 1. Revise P2P power mode setting.
  241. * 2. Revise fast-PS for concurrent
  242. *
  243. * 04 19 2011 wh.su
  244. * NULL
  245. * Adding length check before doing WPA RSN IE parsing for scan results indicate.
  246. *
  247. * 04 14 2011 yuche.tsai
  248. * [WCXRP00000646] [Volunteer Patch][MT6620][FW/Driver] Sigma Test Modification for some test case.
  249. * Connection flow refine for Sigma test.
  250. *
  251. * 04 08 2011 yuche.tsai
  252. * [WCXRP00000624] [Volunteer Patch][MT6620][Driver] Add device discoverability support for GO.
  253. * Add device discoverability support.
  254. *
  255. * 04 08 2011 george.huang
  256. * [WCXRP00000621] [MT6620 Wi-Fi][Driver] Support P2P supplicant to set power mode
  257. * separate settings of P2P and AIS
  258. *
  259. * 04 07 2011 terry.wu
  260. * [WCXRP00000619] [MT6620 Wi-Fi][Driver] fix kernel panic may occur when removing wlan
  261. * Fix kernel panic may occur when removing wlan driver.
  262. *
  263. * 03 31 2011 wh.su
  264. * [WCXRP00000614] [MT6620 Wi-Fi][Driver] P2P: Update beacon content while setting WSC IE
  265. * Update the wsc ie to beacon content.
  266. *
  267. * 03 25 2011 wh.su
  268. * NULL
  269. * add the sample code for set power mode and get power mode.
  270. *
  271. * 03 25 2011 yuche.tsai
  272. * NULL
  273. * Improve some error handleing.
  274. *
  275. * 03 22 2011 george.huang
  276. * [WCXRP00000504] [MT6620 Wi-Fi][FW] Support Sigma CAPI for power saving related command
  277. * link with supplicant commands
  278. *
  279. * 03 22 2011 yuche.tsai
  280. * [WCXRP00000584] [Volunteer Patch][MT6620][Driver] Add beacon timeout support for WiFi Direct.
  281. * Modify formation policy.
  282. *
  283. * 03 22 2011 yuche.tsai
  284. * NULL
  285. * Modify formation policy setting.
  286. *
  287. * 03 18 2011 yuche.tsai
  288. * [WCXRP00000574] [Volunteer Patch][MT6620][Driver] Modify P2P FSM Connection Flow
  289. * Modify connection flow after Group Formation Complete, or device connect to a GO.
  290. * Instead of request channel & connect directly, we use scan to allocate channel bandwidth & connect after RX BCN.
  291. *
  292. * 03 15 2011 wh.su
  293. * [WCXRP00000563] [MT6620 Wi-Fi] [P2P] Set local config method while set password Id ready
  294. * set lccal config method method while set password Id ready.
  295. *
  296. * 03 15 2011 yuche.tsai
  297. * [WCXRP00000560] [Volunteer Patch][MT6620][Driver] P2P Connection from UI using KEY/DISPLAY issue
  298. * Fix some configure method issue.
  299. *
  300. * 03 15 2011 jeffrey.chang
  301. * [WCXRP00000558] [MT6620 Wi-Fi][MT6620 Wi-Fi][Driver] refine the queue selection algorithm for WMM
  302. * refine queue_select function
  303. *
  304. * 03 13 2011 wh.su
  305. * [WCXRP00000530] [MT6620 Wi-Fi] [Driver] skip doing p2pRunEventAAAComplete after send assoc response Tx Done
  306. * add code for avoid compiling warning.
  307. *
  308. * 03 10 2011 yuche.tsai
  309. * NULL
  310. * Add P2P API.
  311. *
  312. * 03 10 2011 terry.wu
  313. * [WCXRP00000505] [MT6620 Wi-Fi][Driver/FW] WiFi Direct Integration
  314. * Remove unnecessary assert and message.
  315. *
  316. * 03 08 2011 wh.su
  317. * [WCXRP00000488] [MT6620 Wi-Fi][Driver] Support the SIGMA set p2p parameter to driver
  318. * support the power save related p2p setting.
  319. *
  320. * 03 07 2011 wh.su
  321. * [WCXRP00000506] [MT6620 Wi-Fi][Driver][FW] Add Security check related code
  322. * rename the define to anti_pviracy.
  323. *
  324. * 03 05 2011 wh.su
  325. * [WCXRP00000506] [MT6620 Wi-Fi][Driver][FW] Add Security check related code
  326. * add the code to get the check rsponse and indicate to app.
  327. *
  328. * 03 03 2011 jeffrey.chang
  329. * [WCXRP00000512] [MT6620 Wi-Fi][Driver] modify the net device relative functions to support the H/W multiple queue
  330. * support concurrent network
  331. *
  332. * 03 03 2011 jeffrey.chang
  333. * [WCXRP00000512] [MT6620 Wi-Fi][Driver] modify the net device relative functions to support the H/W multiple queue
  334. * modify P2P's netdevice functions to support multiple H/W queues
  335. *
  336. * 03 03 2011 cp.wu
  337. * [WCXRP00000283] [MT6620 Wi-Fi][Driver][Wi-Fi Direct] Implementation of interface for supporting Wi-Fi Direct Service
  338. * Discovery
  339. * for get request, the buffer length to be copied is header + payload.
  340. *
  341. * 03 02 2011 wh.su
  342. * [WCXRP00000506] [MT6620 Wi-Fi][Driver][FW] Add Security check related code
  343. * add code to let the beacon and probe response for Auto GO WSC .
  344. *
  345. * 03 02 2011 cp.wu
  346. * [WCXRP00000283] [MT6620 Wi-Fi][Driver][Wi-Fi Direct] Implementation of interface for supporting Wi-Fi Direct Service
  347. * Discovery
  348. * add a missed break.
  349. *
  350. * 03 01 2011 yuche.tsai
  351. * [WCXRP00000501] [Volunteer Patch][MT6620][Driver] No common channel issue when doing GO formation
  352. * Update channel issue when doing GO formation..
  353. *
  354. * 02 25 2011 wh.su
  355. * [WCXRP00000488] [MT6620 Wi-Fi][Driver] Support the SIGMA set p2p parameter to driver
  356. * add the Operation channel setting.
  357. *
  358. * 02 23 2011 wh.su
  359. * [WCXRP00000488] [MT6620 Wi-Fi][Driver] Support the SIGMA set p2p parameter to driver
  360. * fixed the set int ioctl set index and value map to driver issue.
  361. *
  362. * 02 22 2011 wh.su
  363. * [WCXRP00000488] [MT6620 Wi-Fi][Driver] Support the SIGMA set p2p parameter to driver
  364. * adding the ioctl set int from supplicant, and can used to set the p2p parameters
  365. *
  366. * 02 21 2011 terry.wu
  367. * [WCXRP00000476] [MT6620 Wi-Fi][Driver] Clean P2P scan list while removing P2P
  368. * Clean P2P scan list while removing P2P.
  369. *
  370. * 02 18 2011 wh.su
  371. * [WCXRP00000471] [MT6620 Wi-Fi][Driver] Add P2P Provison discovery append Config Method attribute at WSC IE
  372. * fixed the ioctl setting that index not map to spec defined config method.
  373. *
  374. * 02 17 2011 wh.su
  375. * [WCXRP00000471] [MT6620 Wi-Fi][Driver] Add P2P Provison discovery append Config Method attribute at WSC IE
  376. * append the WSC IE config method attribute at provision discovery request.
  377. *
  378. * 02 17 2011 wh.su
  379. * [WCXRP00000448] [MT6620 Wi-Fi][Driver] Fixed WSC IE not send out at probe request
  380. * modify the structure pointer for set WSC IE.
  381. *
  382. * 02 16 2011 wh.su
  383. * [WCXRP00000448] [MT6620 Wi-Fi][Driver] Fixed WSC IE not send out at probe request
  384. * fixed the probe request send out without WSC IE issue (at P2P).
  385. *
  386. * 02 09 2011 cp.wu
  387. * [WCXRP00000283] [MT6620 Wi-Fi][Driver][Wi-Fi Direct] Implementation of interface for supporting Wi-Fi Direct Service
  388. * Discovery
  389. * fix typo
  390. *
  391. * 02 09 2011 yuche.tsai
  392. * [WCXRP00000431] [Volunteer Patch][MT6620][Driver] Add MLME support for deauthentication under AP(Hot-Spot) mode.
  393. * Add Support for MLME deauthentication for Hot-Spot.
  394. *
  395. * 01 25 2011 terry.wu
  396. * [WCXRP00000393] [MT6620 Wi-Fi][Driver] Add new module insert parameter
  397. * Add a new module parameter to indicate current runnig mode, P2P or AP.
  398. *
  399. * 01 12 2011 yuche.tsai
  400. * [WCXRP00000352] [Volunteer Patch][MT6620][Driver] P2P Statsion Record Client List Issue
  401. * 1. Modify Channel Acquire Time of AP mode from 5s to 1s.
  402. * 2. Call cnmP2pIsPermit() before active P2P network.
  403. * 3. Add channel selection support for AP mode.
  404. *
  405. * 01 05 2011 cp.wu
  406. * [WCXRP00000283] [MT6620 Wi-Fi][Driver][Wi-Fi Direct] Implementation of interface for supporting Wi-Fi Direct Service
  407. * Discovery
  408. * ioctl implementations for P2P Service Discovery
  409. *
  410. * 01 04 2011 cp.wu
  411. * [WCXRP00000338] [MT6620 Wi-Fi][Driver] Separate kalMemAlloc into kmalloc and vmalloc implementations to ease
  412. * physically continuous memory demands
  413. * separate kalMemAlloc() into virtually-continuous and physically-continuous type to ease slab system pressure
  414. *
  415. * 12 22 2010 cp.wu
  416. * [WCXRP00000283] [MT6620 Wi-Fi][Driver][Wi-Fi Direct] Implementation of interface for supporting Wi-Fi Direct Service
  417. * Discovery
  418. * 1. header file restructure for more clear module isolation
  419. * 2. add function interface definition for implementing Service Discovery callbacks
  420. *
  421. * 12 15 2010 cp.wu
  422. * NULL
  423. * invoke nicEnableInterrupt() before leaving from wlanAdapterStart()
  424. *
  425. * 12 08 2010 yuche.tsai
  426. * [WCXRP00000245] [MT6620][Driver] Invitation & Provision Discovery Feature Check-in
  427. * [WCXRP000000245][MT6620][Driver] Invitation Request Feature Add
  428. *
  429. * 11 30 2010 yuche.tsai
  430. * NULL
  431. * Invitation & Provision Discovery Indication.
  432. *
  433. * 11 17 2010 wh.su
  434. * [WCXRP00000164] [MT6620 Wi-Fi][Driver] Support the p2p random SSID[WCXRP00000179] [MT6620 Wi-Fi][FW] Set the Tx
  435. * lowest rate at wlan table for normal operation
  436. * fixed some ASSERT check.
  437. *
  438. * 11 04 2010 wh.su
  439. * [WCXRP00000164] [MT6620 Wi-Fi][Driver] Support the p2p random SSID
  440. * adding the p2p random ssid support.
  441. *
  442. * 10 20 2010 wh.su
  443. * [WCXRP00000124] [MT6620 Wi-Fi] [Driver] Support the dissolve P2P Group
  444. * Add the code to support disconnect p2p group
  445. *
  446. * 10 04 2010 wh.su
  447. * [WCXRP00000081] [MT6620][Driver] Fix the compiling error at WinXP while enable P2P
  448. * add a kal function for set cipher.
  449. *
  450. * 10 04 2010 wh.su
  451. * [WCXRP00000081] [MT6620][Driver] Fix the compiling error at WinXP while enable P2P
  452. * fixed compiling error while enable p2p.
  453. *
  454. * 09 28 2010 wh.su
  455. * NULL
  456. * [WCXRP00000069][MT6620 Wi-Fi][Driver] Fix some code for phase 1 P2P Demo.
  457. *
  458. * 09 21 2010 kevin.huang
  459. * [WCXRP00000054] [MT6620 Wi-Fi][Driver] Restructure driver for second Interface
  460. * Isolate P2P related function for Hardware Software Bundle
  461. *
  462. * 09 21 2010 kevin.huang
  463. * [WCXRP00000052] [MT6620 Wi-Fi][Driver] Eliminate Linux Compile Warning
  464. * Eliminate Linux Compile Warning
  465. *
  466. * 09 10 2010 george.huang
  467. * NULL
  468. * update iwpriv LP related
  469. *
  470. * 09 10 2010 wh.su
  471. * NULL
  472. * fixed the compiling error at win XP.
  473. *
  474. * 09 09 2010 cp.wu
  475. * NULL
  476. * add WPS/WPA/RSN IE for Wi-Fi Direct scanning result.
  477. *
  478. * 09 07 2010 wh.su
  479. * NULL
  480. * adding the code for beacon/probe req/ probe rsp wsc ie at p2p.
  481. *
  482. * 09 06 2010 wh.su
  483. * NULL
  484. * let the p2p can set the privacy bit at beacon and rsn ie at assoc req at key handshake state.
  485. *
  486. * 08 25 2010 cp.wu
  487. * NULL
  488. * add netdev_ops(NDO) for linux kernel 2.6.31 or greater
  489. *
  490. * 08 23 2010 cp.wu
  491. * NULL
  492. * revise constant definitions to be matched with implementation (original cmd-event definition is deprecated)
  493. *
  494. * 08 20 2010 cp.wu
  495. * NULL
  496. * correct typo.
  497. *
  498. * 08 20 2010 yuche.tsai
  499. * NULL
  500. * Invert Connection request provision status parameter.
  501. *
  502. * 08 19 2010 cp.wu
  503. * NULL
  504. * add set mac address interface for further possibilities of wpa_supplicant overriding interface address.
  505. *
  506. * 08 18 2010 cp.wu
  507. * NULL
  508. * modify pwp ioctls attribution by removing FIXED_SIZE.
  509. *
  510. * 08 18 2010 jeffrey.chang
  511. * NULL
  512. * support multi-function sdio
  513. *
  514. * 08 17 2010 cp.wu
  515. * NULL
  516. * correct p2p net device registration with NULL pointer access issue.
  517. *
  518. * 08 16 2010 cp.wu
  519. * NULL
  520. * P2P packets are now marked when being queued into driver, and identified later without checking MAC address
  521. *
  522. * 08 16 2010 cp.wu
  523. * NULL
  524. * add subroutines for P2P to set multicast list.
  525. *
  526. * 08 16 2010 george.huang
  527. * NULL
  528. * add wext handlers to link P2P set PS profile/ network address function (TBD)
  529. *
  530. * 08 16 2010 cp.wu
  531. * NULL
  532. * revised implementation of Wi-Fi Direct io controls.
  533. *
  534. * 08 12 2010 cp.wu
  535. * NULL
  536. * follow-up with ioctl interface update for Wi-Fi Direct application
  537. *
  538. * 08 06 2010 cp.wu
  539. * NULL
  540. * driver hook modifications corresponding to ioctl interface change.
  541. *
  542. * 08 03 2010 cp.wu
  543. * NULL
  544. * add basic support for ioctl of getting scan result. (only address and SSID are reporterd though)
  545. *
  546. * 08 03 2010 cp.wu
  547. * NULL
  548. * [Wi-Fi Direct Driver Hook] change event indication API to be consistent with supplicant
  549. *
  550. * 08 03 2010 cp.wu
  551. * NULL
  552. * surpress compilation warning.
  553. *
  554. * 08 03 2010 cp.wu
  555. * NULL
  556. * [Wi-Fi Direct] add framework for driver hooks
  557. *
  558. * 07 08 2010 cp.wu
  559. *
  560. * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
  561. *
  562. * 06 23 2010 cp.wu
  563. * [WPD00003833][MT6620 and MT5931] Driver migration
  564. * p2p interface revised to be sync. with HAL
  565. *
  566. * 06 06 2010 kevin.huang
  567. * [WPD00003832][MT6620 5931] Create driver base
  568. * [MT6620 5931] Create driver base
  569. *
  570. * 06 01 2010 cp.wu
  571. * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
  572. * add ioctl to configure scan mode for p2p connection
  573. *
  574. * 05 31 2010 cp.wu
  575. * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
  576. * add cfg80211 interface, which is to replace WE, for further extension
  577. *
  578. * 05 17 2010 cp.wu
  579. * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
  580. * implement private io controls for Wi-Fi Direct
  581. *
  582. * 05 17 2010 cp.wu
  583. * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
  584. * implement get scan result.
  585. *
  586. * 05 17 2010 cp.wu
  587. * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
  588. * add basic handling framework for wireless extension ioctls.
  589. *
  590. * 05 17 2010 cp.wu
  591. * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
  592. * 1) add timeout handler mechanism for pending command packets
  593. * 2) add p2p add/removal key
  594. *
  595. * 05 14 2010 cp.wu
  596. * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
  597. * implement wireless extension ioctls in iw_handler form.
  598. *
  599. * 05 14 2010 cp.wu
  600. * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
  601. * add ioctl framework for Wi-Fi Direct by reusing wireless extension ioctls as well
  602. *
  603. * 05 11 2010 cp.wu
  604. * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
  605. * p2p ioctls revised.
  606. *
  607. * 05 11 2010 cp.wu
  608. * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
  609. * add ioctl for controlling p2p scan phase parameters
  610. *
  611. * 05 10 2010 cp.wu
  612. * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
  613. * implement basic wi-fi direct framework
  614. *
  615. * 05 07 2010 cp.wu
  616. * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
  617. * add basic framework for implementating P2P driver hook.
  618. *
  619. **
  620. */
  621. /*******************************************************************************
  622. * C O M P I L E R F L A G S
  623. ********************************************************************************
  624. */
  625. /*******************************************************************************
  626. * E X T E R N A L R E F E R E N C E S
  627. ********************************************************************************
  628. */
  629. #include <linux/poll.h>
  630. #include <linux/kmod.h>
  631. #include "gl_os.h"
  632. #include "wlan_lib.h"
  633. #include "gl_wext.h"
  634. #include "gl_p2p_os.h"
  635. #include "gl_p2p_ioctl.h"
  636. #include "gl_vendor.h"
  637. #include "precomp.h"
  638. /*******************************************************************************
  639. * C O N S T A N T S
  640. ********************************************************************************
  641. */
  642. #define ARGV_MAX_NUM (4)
  643. /*For CFG80211 - wiphy parameters*/
  644. #define MAX_SCAN_LIST_NUM (1)
  645. #define MAX_SCAN_IE_LEN (512)
  646. /*******************************************************************************
  647. * D A T A T Y P E S
  648. ********************************************************************************
  649. */
  650. /*******************************************************************************
  651. * P U B L I C D A T A
  652. ********************************************************************************
  653. */
  654. /*******************************************************************************
  655. * P R I V A T E D A T A
  656. ********************************************************************************
  657. */
  658. static struct net_device *g_P2pPrDev;
  659. static struct wireless_dev *gprP2pWdev;
  660. #if CFG_ENABLE_WIFI_DIRECT_CFG_80211
  661. static struct cfg80211_ops mtk_p2p_ops = {
  662. .add_virtual_intf = mtk_p2p_cfg80211_add_iface,
  663. .change_virtual_intf = mtk_p2p_cfg80211_change_iface, /* 1 st */
  664. .del_virtual_intf = mtk_p2p_cfg80211_del_iface,
  665. .change_bss = mtk_p2p_cfg80211_change_bss,
  666. .scan = mtk_p2p_cfg80211_scan,
  667. .remain_on_channel = mtk_p2p_cfg80211_remain_on_channel,
  668. .cancel_remain_on_channel = mtk_p2p_cfg80211_cancel_remain_on_channel,
  669. .mgmt_tx = mtk_p2p_cfg80211_mgmt_tx,
  670. .mgmt_tx_cancel_wait = mtk_p2p_cfg80211_mgmt_tx_cancel_wait,
  671. .connect = mtk_p2p_cfg80211_connect,
  672. .disconnect = mtk_p2p_cfg80211_disconnect,
  673. .deauth = mtk_p2p_cfg80211_deauth,
  674. .disassoc = mtk_p2p_cfg80211_disassoc,
  675. .start_ap = mtk_p2p_cfg80211_start_ap,
  676. .change_beacon = mtk_p2p_cfg80211_change_beacon,
  677. .stop_ap = mtk_p2p_cfg80211_stop_ap,
  678. .set_wiphy_params = mtk_p2p_cfg80211_set_wiphy_params,
  679. .del_station = mtk_p2p_cfg80211_del_station,
  680. .set_bitrate_mask = mtk_p2p_cfg80211_set_bitrate_mask,
  681. .mgmt_frame_register = mtk_p2p_cfg80211_mgmt_frame_register,
  682. .get_station = mtk_p2p_cfg80211_get_station,
  683. .add_key = mtk_p2p_cfg80211_add_key,
  684. .get_key = mtk_p2p_cfg80211_get_key,
  685. .del_key = mtk_p2p_cfg80211_del_key,
  686. .set_default_key = mtk_p2p_cfg80211_set_default_key,
  687. .join_ibss = mtk_p2p_cfg80211_join_ibss,
  688. .leave_ibss = mtk_p2p_cfg80211_leave_ibss,
  689. .set_tx_power = mtk_p2p_cfg80211_set_txpower,
  690. .get_tx_power = mtk_p2p_cfg80211_get_txpower,
  691. .set_power_mgmt = mtk_p2p_cfg80211_set_power_mgmt,
  692. #ifdef CONFIG_NL80211_TESTMODE
  693. .testmode_cmd = mtk_p2p_cfg80211_testmode_cmd,
  694. #endif
  695. };
  696. static const struct wiphy_vendor_command mtk_p2p_vendor_ops[] = {
  697. {
  698. {
  699. .vendor_id = GOOGLE_OUI,
  700. .subcmd = WIFI_SUBCMD_GET_CHANNEL_LIST
  701. },
  702. .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
  703. .doit = mtk_cfg80211_vendor_get_channel_list
  704. },
  705. {
  706. {
  707. .vendor_id = GOOGLE_OUI,
  708. .subcmd = WIFI_SUBCMD_SET_COUNTRY_CODE
  709. },
  710. .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
  711. .doit = mtk_cfg80211_vendor_set_country_code
  712. },
  713. };
  714. /* There isn't a lot of sense in it, but you can transmit anything you like */
  715. static const struct ieee80211_txrx_stypes
  716. mtk_cfg80211_default_mgmt_stypes[NUM_NL80211_IFTYPES] = {
  717. [NL80211_IFTYPE_ADHOC] = {
  718. .tx = 0xffff,
  719. .rx = BIT(IEEE80211_STYPE_ACTION >> 4)
  720. },
  721. [NL80211_IFTYPE_STATION] = {
  722. .tx = 0xffff,
  723. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  724. },
  725. [NL80211_IFTYPE_AP] = {
  726. .tx = 0xffff,
  727. .rx = BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | BIT(IEEE80211_STYPE_ACTION >> 4)
  728. },
  729. [NL80211_IFTYPE_AP_VLAN] = {
  730. /* copy AP */
  731. .tx = 0xffff,
  732. .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
  733. BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
  734. BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
  735. BIT(IEEE80211_STYPE_DISASSOC >> 4) |
  736. BIT(IEEE80211_STYPE_AUTH >> 4) |
  737. BIT(IEEE80211_STYPE_DEAUTH >> 4) | BIT(IEEE80211_STYPE_ACTION >> 4)
  738. },
  739. [NL80211_IFTYPE_P2P_CLIENT] = {
  740. .tx = 0xffff,
  741. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  742. },
  743. [NL80211_IFTYPE_P2P_GO] = {
  744. .tx = 0xffff,
  745. .rx = BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | BIT(IEEE80211_STYPE_ACTION >> 4)
  746. }
  747. };
  748. #endif
  749. #if 0
  750. /* the legacy wireless extension stuff */
  751. static const iw_handler rP2PIwStandardHandler[] = {
  752. [SIOCGIWPRIV - SIOCIWFIRST] = mtk_p2p_wext_get_priv,
  753. [SIOCGIWSCAN - SIOCIWFIRST] = mtk_p2p_wext_discovery_results,
  754. [SIOCSIWESSID - SIOCIWFIRST] = mtk_p2p_wext_reconnect,
  755. [SIOCSIWAUTH - SIOCIWFIRST] = mtk_p2p_wext_set_auth,
  756. [SIOCSIWENCODEEXT - SIOCIWFIRST] = mtk_p2p_wext_set_key,
  757. [SIOCSIWPOWER - SIOCIWFIRST] = mtk_p2p_wext_set_powermode,
  758. [SIOCGIWPOWER - SIOCIWFIRST] = mtk_p2p_wext_get_powermode,
  759. [SIOCSIWTXPOW - SIOCIWFIRST] = mtk_p2p_wext_set_txpow,
  760. #if CFG_SUPPORT_P2P_RSSI_QUERY
  761. [SIOCGIWSTATS - SIOCIWFIRST] = mtk_p2p_wext_get_rssi,
  762. #endif
  763. [SIOCSIWMLME - SIOCIWFIRST] = mtk_p2p_wext_mlme_handler,
  764. };
  765. #endif
  766. #if 0
  767. static const iw_handler rP2PIwPrivHandler[] = {
  768. [IOC_P2P_CFG_DEVICE - SIOCIWFIRSTPRIV] = mtk_p2p_wext_set_local_dev_info,
  769. [IOC_P2P_PROVISION_COMPLETE - SIOCIWFIRSTPRIV] = mtk_p2p_wext_set_provision_complete,
  770. [IOC_P2P_START_STOP_DISCOVERY - SIOCIWFIRSTPRIV] = mtk_p2p_wext_start_stop_discovery,
  771. [IOC_P2P_DISCOVERY_RESULTS - SIOCIWFIRSTPRIV] = mtk_p2p_wext_discovery_results,
  772. [IOC_P2P_WSC_BEACON_PROBE_RSP_IE - SIOCIWFIRSTPRIV] = mtk_p2p_wext_wsc_ie,
  773. [IOC_P2P_CONNECT_DISCONNECT - SIOCIWFIRSTPRIV] = mtk_p2p_wext_connect_disconnect,
  774. [IOC_P2P_PASSWORD_READY - SIOCIWFIRSTPRIV] = mtk_p2p_wext_password_ready,
  775. /* [IOC_P2P_SET_PWR_MGMT_PARAM - SIOCIWFIRSTPRIV] = mtk_p2p_wext_set_pm_param, */
  776. [IOC_P2P_SET_INT - SIOCIWFIRSTPRIV] = mtk_p2p_wext_set_int,
  777. [IOC_P2P_GET_STRUCT - SIOCIWFIRSTPRIV] = mtk_p2p_wext_get_struct,
  778. [IOC_P2P_SET_STRUCT - SIOCIWFIRSTPRIV] = mtk_p2p_wext_set_struct,
  779. [IOC_P2P_GET_REQ_DEVICE_INFO - SIOCIWFIRSTPRIV] = mtk_p2p_wext_request_dev_info,
  780. };
  781. #endif
  782. static const struct iw_priv_args rP2PIwPrivTable[] = {
  783. {
  784. .cmd = IOC_P2P_CFG_DEVICE,
  785. .set_args = IW_PRIV_TYPE_BYTE | (__u16) sizeof(IW_P2P_CFG_DEVICE_TYPE),
  786. .get_args = IW_PRIV_TYPE_NONE,
  787. .name = "P2P_CFG_DEVICE"}
  788. ,
  789. {
  790. .cmd = IOC_P2P_START_STOP_DISCOVERY,
  791. .set_args = IW_PRIV_TYPE_BYTE | (__u16) sizeof(IW_P2P_REQ_DEVICE_TYPE),
  792. .get_args = IW_PRIV_TYPE_NONE,
  793. .name = "P2P_DISCOVERY"}
  794. ,
  795. {
  796. .cmd = IOC_P2P_DISCOVERY_RESULTS,
  797. .set_args = IW_PRIV_TYPE_NONE,
  798. .get_args = IW_PRIV_TYPE_NONE,
  799. .name = "P2P_RESULT"}
  800. ,
  801. {
  802. .cmd = IOC_P2P_WSC_BEACON_PROBE_RSP_IE,
  803. .set_args = IW_PRIV_TYPE_BYTE | (__u16) sizeof(IW_P2P_HOSTAPD_PARAM),
  804. .get_args = IW_PRIV_TYPE_NONE,
  805. .name = "P2P_WSC_IE"}
  806. ,
  807. {
  808. .cmd = IOC_P2P_CONNECT_DISCONNECT,
  809. .set_args = IW_PRIV_TYPE_BYTE | (__u16) sizeof(IW_P2P_CONNECT_DEVICE),
  810. .get_args = IW_PRIV_TYPE_NONE,
  811. .name = "P2P_CONNECT"}
  812. ,
  813. {
  814. .cmd = IOC_P2P_PASSWORD_READY,
  815. .set_args = IW_PRIV_TYPE_BYTE | (__u16) sizeof(IW_P2P_PASSWORD_READY),
  816. .get_args = IW_PRIV_TYPE_NONE,
  817. .name = "P2P_PASSWD_RDY"}
  818. ,
  819. {
  820. .cmd = IOC_P2P_GET_STRUCT,
  821. .set_args = IW_PRIV_TYPE_NONE,
  822. .get_args = 256,
  823. .name = "P2P_GET_STRUCT"}
  824. ,
  825. {
  826. .cmd = IOC_P2P_SET_STRUCT,
  827. .set_args = 256,
  828. .get_args = IW_PRIV_TYPE_NONE,
  829. .name = "P2P_SET_STRUCT"}
  830. ,
  831. {
  832. .cmd = IOC_P2P_GET_REQ_DEVICE_INFO,
  833. .set_args = IW_PRIV_TYPE_NONE,
  834. .get_args = IW_PRIV_TYPE_BYTE | (__u16) sizeof(IW_P2P_DEVICE_REQ),
  835. .name = "P2P_GET_REQDEV"}
  836. ,
  837. {
  838. /* SET STRUCT sub-ioctls commands */
  839. .cmd = PRIV_CMD_OID,
  840. .set_args = 256,
  841. .get_args = IW_PRIV_TYPE_NONE,
  842. .name = "set_oid"}
  843. ,
  844. {
  845. /* GET STRUCT sub-ioctls commands */
  846. .cmd = PRIV_CMD_OID,
  847. .set_args = IW_PRIV_TYPE_NONE,
  848. .get_args = 256,
  849. .name = "get_oid"}
  850. };
  851. #if 0
  852. const struct iw_handler_def mtk_p2p_wext_handler_def = {
  853. .num_standard = (__u16) sizeof(rP2PIwStandardHandler) / sizeof(iw_handler),
  854. /* .num_private = (__u16)sizeof(rP2PIwPrivHandler)/sizeof(iw_handler), */
  855. .num_private_args = (__u16) sizeof(rP2PIwPrivTable) / sizeof(struct iw_priv_args),
  856. .standard = rP2PIwStandardHandler,
  857. /* .private = rP2PIwPrivHandler, */
  858. .private_args = rP2PIwPrivTable,
  859. #if CFG_SUPPORT_P2P_RSSI_QUERY
  860. .get_wireless_stats = mtk_p2p_wext_get_wireless_stats,
  861. #else
  862. .get_wireless_stats = NULL,
  863. #endif
  864. };
  865. #endif
  866. #ifdef CONFIG_PM
  867. static const struct wiphy_wowlan_support mtk_p2p_wowlan_support = {
  868. .flags = WIPHY_WOWLAN_DISCONNECT | WIPHY_WOWLAN_ANY,
  869. };
  870. #endif
  871. /*******************************************************************************
  872. * M A C R O S
  873. ********************************************************************************
  874. */
  875. /*******************************************************************************
  876. * F U N C T I O N D E C L A R A T I O N S
  877. ********************************************************************************
  878. */
  879. /* Net Device Hooks */
  880. static int p2pOpen(IN struct net_device *prDev);
  881. static int p2pStop(IN struct net_device *prDev);
  882. static struct net_device_stats *p2pGetStats(IN struct net_device *prDev);
  883. static void p2pSetMulticastList(IN struct net_device *prDev);
  884. static int p2pHardStartXmit(IN struct sk_buff *prSkb, IN struct net_device *prDev);
  885. static int p2pSetMACAddress(IN struct net_device *prDev, void *addr);
  886. static int p2pDoIOCTL(struct net_device *prDev, struct ifreq *prIfReq, int i4Cmd);
  887. #if 0
  888. /*----------------------------------------------------------------------------*/
  889. /*!
  890. * \brief Override the implementation of select queue
  891. *
  892. * \param[in] dev Pointer to struct net_device
  893. * \param[in] skb Pointer to struct skb_buff
  894. *
  895. * \return (none)
  896. */
  897. /*----------------------------------------------------------------------------*/
  898. unsigned int _p2p_cfg80211_classify8021d(struct sk_buff *skb)
  899. {
  900. unsigned int dscp = 0;
  901. /* skb->priority values from 256->263 are magic values
  902. * directly indicate a specific 802.1d priority. This is
  903. * to allow 802.1d priority to be passed directly in from
  904. * tags
  905. */
  906. if (skb->priority >= 256 && skb->priority <= 263)
  907. return skb->priority - 256;
  908. switch (skb->protocol) {
  909. case htons(ETH_P_IP):
  910. dscp = ip_hdr(skb)->tos & 0xfc;
  911. break;
  912. }
  913. return dscp >> 5;
  914. }
  915. static const UINT_16 au16Wlan1dToQueueIdx[8] = { 1, 0, 0, 1, 2, 2, 3, 3 };
  916. static UINT_16 p2pSelectQueue(struct net_device *dev, struct sk_buff *skb)
  917. {
  918. skb->priority = _p2p_cfg80211_classify8021d(skb);
  919. return au16Wlan1dToQueueIdx[skb->priority];
  920. }
  921. #endif
  922. /*----------------------------------------------------------------------------*/
  923. /*!
  924. * \brief A function for prDev->init
  925. *
  926. * \param[in] prDev Pointer to struct net_device.
  927. *
  928. * \retval 0 The execution of wlanInit succeeds.
  929. * \retval -ENXIO No such device.
  930. */
  931. /*----------------------------------------------------------------------------*/
  932. static int p2pInit(struct net_device *prDev)
  933. {
  934. if (!prDev)
  935. return -ENXIO;
  936. return 0; /* success */
  937. } /* end of p2pInit() */
  938. /*----------------------------------------------------------------------------*/
  939. /*!
  940. * \brief A function for prDev->uninit
  941. *
  942. * \param[in] prDev Pointer to struct net_device.
  943. *
  944. * \return (none)
  945. */
  946. /*----------------------------------------------------------------------------*/
  947. static void p2pUninit(IN struct net_device *prDev)
  948. {
  949. } /* end of p2pUninit() */
  950. const struct net_device_ops p2p_netdev_ops = {
  951. .ndo_open = p2pOpen,
  952. .ndo_stop = p2pStop,
  953. .ndo_set_mac_address = p2pSetMACAddress,
  954. .ndo_set_rx_mode = p2pSetMulticastList,
  955. .ndo_get_stats = p2pGetStats,
  956. .ndo_do_ioctl = p2pDoIOCTL,
  957. .ndo_start_xmit = p2pHardStartXmit,
  958. /* .ndo_select_queue = p2pSelectQueue, */
  959. .ndo_select_queue = wlanSelectQueue,
  960. .ndo_init = p2pInit,
  961. .ndo_uninit = p2pUninit,
  962. };
  963. /*******************************************************************************
  964. * F U N C T I O N S
  965. ********************************************************************************
  966. */
  967. /*----------------------------------------------------------------------------*/
  968. /*!
  969. * \brief Allocate memory for P2P_INFO, GL_P2P_INFO, P2P_CONNECTION_SETTINGS
  970. * P2P_SPECIFIC_BSS_INFO, P2P_FSM_INFO
  971. *
  972. * \param[in] prGlueInfo Pointer to glue info
  973. *
  974. * \return TRUE
  975. * FALSE
  976. */
  977. /*----------------------------------------------------------------------------*/
  978. BOOLEAN p2PAllocInfo(IN P_GLUE_INFO_T prGlueInfo)
  979. {
  980. P_ADAPTER_T prAdapter = NULL;
  981. P_WIFI_VAR_T prWifiVar = NULL;
  982. /* UINT_32 u4Idx = 0; */
  983. ASSERT(prGlueInfo);
  984. prAdapter = prGlueInfo->prAdapter;
  985. prWifiVar = &(prAdapter->rWifiVar);
  986. ASSERT(prAdapter);
  987. ASSERT(prWifiVar);
  988. do {
  989. if (prGlueInfo->prP2PInfo == NULL) {
  990. /*alloc memory for p2p info */
  991. prGlueInfo->prP2PInfo = kalMemAlloc(sizeof(GL_P2P_INFO_T), VIR_MEM_TYPE);
  992. prAdapter->prP2pInfo = kalMemAlloc(sizeof(P2P_INFO_T), VIR_MEM_TYPE);
  993. prWifiVar->prP2PConnSettings = kalMemAlloc(sizeof(P2P_CONNECTION_SETTINGS_T), VIR_MEM_TYPE);
  994. prWifiVar->prP2pDevFsmInfo = kalMemAlloc(sizeof(P2P_DEV_FSM_INFO_T), VIR_MEM_TYPE);
  995. /* TODO: It can be moved to the interface been created. */
  996. /*
  997. for (u4Idx = 0; u4Idx < BSS_P2P_NUM; u4Idx++) {
  998. prWifiVar->aprP2pRoleFsmInfo[u4Idx] = kalMemAlloc(sizeof(P2P_ROLE_FSM_INFO_T),VIR_MEM_TYPE);
  999. }
  1000. */
  1001. prWifiVar->prP2pSpecificBssInfo = kalMemAlloc(sizeof(P2P_SPECIFIC_BSS_INFO_T), VIR_MEM_TYPE);
  1002. } else {
  1003. ASSERT(prAdapter->prP2pInfo != NULL);
  1004. ASSERT(prWifiVar->prP2PConnSettings != NULL);
  1005. /* ASSERT(prWifiVar->prP2pFsmInfo != NULL); */
  1006. ASSERT(prWifiVar->prP2pSpecificBssInfo != NULL);
  1007. }
  1008. /*MUST set memory to 0 */
  1009. if (prGlueInfo->prP2PInfo)
  1010. kalMemZero(prGlueInfo->prP2PInfo, sizeof(GL_P2P_INFO_T));
  1011. if (prAdapter->prP2pInfo)
  1012. kalMemZero(prAdapter->prP2pInfo, sizeof(P2P_INFO_T));
  1013. if (prWifiVar->prP2PConnSettings)
  1014. kalMemZero(prWifiVar->prP2PConnSettings, sizeof(P2P_CONNECTION_SETTINGS_T));
  1015. /* kalMemZero(prWifiVar->prP2pFsmInfo, sizeof(P2P_FSM_INFO_T)); */
  1016. if (prWifiVar->prP2pSpecificBssInfo)
  1017. kalMemZero(prWifiVar->prP2pSpecificBssInfo, sizeof(P2P_SPECIFIC_BSS_INFO_T));
  1018. } while (FALSE);
  1019. /* chk if alloc successful or not */
  1020. if (prGlueInfo->prP2PInfo && prAdapter->prP2pInfo && prWifiVar->prP2PConnSettings &&
  1021. /* prWifiVar->prP2pFsmInfo && */
  1022. prWifiVar->prP2pSpecificBssInfo) {
  1023. return TRUE;
  1024. }
  1025. if (prWifiVar->prP2pSpecificBssInfo) {
  1026. kalMemFree(prWifiVar->prP2pSpecificBssInfo, VIR_MEM_TYPE, sizeof(P2P_SPECIFIC_BSS_INFO_T));
  1027. prWifiVar->prP2pSpecificBssInfo = NULL;
  1028. }
  1029. /* if (prWifiVar->prP2pFsmInfo) { */
  1030. /* kalMemFree(prWifiVar->prP2pFsmInfo, VIR_MEM_TYPE, sizeof(P2P_FSM_INFO_T)); */
  1031. /* prWifiVar->prP2pFsmInfo = NULL; */
  1032. /* } */
  1033. if (prWifiVar->prP2PConnSettings) {
  1034. kalMemFree(prWifiVar->prP2PConnSettings, VIR_MEM_TYPE, sizeof(P2P_CONNECTION_SETTINGS_T));
  1035. prWifiVar->prP2PConnSettings = NULL;
  1036. }
  1037. if (prGlueInfo->prP2PInfo) {
  1038. kalMemFree(prGlueInfo->prP2PInfo, VIR_MEM_TYPE, sizeof(GL_P2P_INFO_T));
  1039. prGlueInfo->prP2PInfo = NULL;
  1040. }
  1041. if (prAdapter->prP2pInfo) {
  1042. kalMemFree(prAdapter->prP2pInfo, VIR_MEM_TYPE, sizeof(P2P_INFO_T));
  1043. prAdapter->prP2pInfo = NULL;
  1044. }
  1045. return FALSE;
  1046. }
  1047. /*----------------------------------------------------------------------------*/
  1048. /*!
  1049. * \brief Free memory for P2P_INFO, GL_P2P_INFO, P2P_CONNECTION_SETTINGS
  1050. * P2P_SPECIFIC_BSS_INFO, P2P_FSM_INFO
  1051. *
  1052. * \param[in] prGlueInfo Pointer to glue info
  1053. *
  1054. * \return TRUE
  1055. * FALSE
  1056. */
  1057. /*----------------------------------------------------------------------------*/
  1058. BOOLEAN p2PFreeInfo(P_GLUE_INFO_T prGlueInfo)
  1059. {
  1060. ASSERT(prGlueInfo);
  1061. /* free memory after p2p module is ALREADY unregistered */
  1062. if (prGlueInfo->prAdapter->fgIsP2PRegistered == FALSE) {
  1063. kalMemFree(prGlueInfo->prAdapter->prP2pInfo, VIR_MEM_TYPE, sizeof(P2P_INFO_T));
  1064. kalMemFree(prGlueInfo->prP2PInfo, VIR_MEM_TYPE, sizeof(GL_P2P_INFO_T));
  1065. kalMemFree(prGlueInfo->prAdapter->rWifiVar.prP2PConnSettings, VIR_MEM_TYPE,
  1066. sizeof(P2P_CONNECTION_SETTINGS_T));
  1067. /* kalMemFree(prGlueInfo->prAdapter->rWifiVar.prP2pFsmInfo, VIR_MEM_TYPE, sizeof(P2P_FSM_INFO_T)); */
  1068. kalMemFree(prGlueInfo->prAdapter->rWifiVar.prP2pSpecificBssInfo, VIR_MEM_TYPE,
  1069. sizeof(P2P_SPECIFIC_BSS_INFO_T));
  1070. kalMemFree(prGlueInfo->prAdapter->rWifiVar.prP2pDevFsmInfo, VIR_MEM_TYPE, sizeof(P2P_DEV_FSM_INFO_T));
  1071. /*Reomve p2p bss scan list */
  1072. scanRemoveAllP2pBssDesc(prGlueInfo->prAdapter);
  1073. /*reset all pointer to NULL */
  1074. prGlueInfo->prP2PInfo = NULL;
  1075. prGlueInfo->prAdapter->prP2pInfo = NULL;
  1076. prGlueInfo->prAdapter->rWifiVar.prP2PConnSettings = NULL;
  1077. /* prGlueInfo->prAdapter->rWifiVar.prP2pFsmInfo = NULL; */
  1078. prGlueInfo->prAdapter->rWifiVar.prP2pSpecificBssInfo = NULL;
  1079. prGlueInfo->prAdapter->rWifiVar.prP2pDevFsmInfo = NULL;
  1080. return TRUE;
  1081. } else {
  1082. return FALSE;
  1083. }
  1084. }
  1085. BOOLEAN p2pNetRegister(P_GLUE_INFO_T prGlueInfo, BOOLEAN fgIsRtnlLockAcquired)
  1086. {
  1087. BOOLEAN fgDoRegister = FALSE;
  1088. BOOLEAN fgRollbackRtnlLock = FALSE;
  1089. BOOLEAN ret;
  1090. GLUE_SPIN_LOCK_DECLARATION();
  1091. ASSERT(prGlueInfo);
  1092. ASSERT(prGlueInfo->prAdapter);
  1093. GLUE_ACQUIRE_SPIN_LOCK(prGlueInfo, SPIN_LOCK_NET_DEV);
  1094. if (prGlueInfo->prAdapter->rP2PNetRegState == ENUM_NET_REG_STATE_UNREGISTERED) {
  1095. prGlueInfo->prAdapter->rP2PNetRegState = ENUM_NET_REG_STATE_REGISTERING;
  1096. fgDoRegister = TRUE;
  1097. }
  1098. GLUE_RELEASE_SPIN_LOCK(prGlueInfo, SPIN_LOCK_NET_DEV);
  1099. if (!fgDoRegister)
  1100. return TRUE;
  1101. if (fgIsRtnlLockAcquired && rtnl_is_locked()) {
  1102. fgRollbackRtnlLock = TRUE;
  1103. rtnl_unlock();
  1104. }
  1105. /* net device initialize */
  1106. netif_carrier_off(prGlueInfo->prP2PInfo->prDevHandler);
  1107. netif_tx_stop_all_queues(prGlueInfo->prP2PInfo->prDevHandler);
  1108. /* register for net device */
  1109. if (register_netdev(prGlueInfo->prP2PInfo->prDevHandler) < 0) {
  1110. DBGLOG(INIT, WARN, "unable to register netdevice for p2p\n");
  1111. free_netdev(prGlueInfo->prP2PInfo->prDevHandler);
  1112. ret = FALSE;
  1113. } else {
  1114. prGlueInfo->prAdapter->rP2PNetRegState = ENUM_NET_REG_STATE_REGISTERED;
  1115. ret = TRUE;
  1116. }
  1117. if (fgRollbackRtnlLock)
  1118. rtnl_lock();
  1119. return ret;
  1120. }
  1121. BOOLEAN p2pNetUnregister(P_GLUE_INFO_T prGlueInfo, BOOLEAN fgIsRtnlLockAcquired)
  1122. {
  1123. BOOLEAN fgDoUnregister = FALSE;
  1124. BOOLEAN fgRollbackRtnlLock = FALSE;
  1125. GLUE_SPIN_LOCK_DECLARATION();
  1126. ASSERT(prGlueInfo);
  1127. ASSERT(prGlueInfo->prAdapter);
  1128. GLUE_ACQUIRE_SPIN_LOCK(prGlueInfo, SPIN_LOCK_NET_DEV);
  1129. if (prGlueInfo->prAdapter->rP2PNetRegState == ENUM_NET_REG_STATE_REGISTERED) {
  1130. prGlueInfo->prAdapter->rP2PNetRegState = ENUM_NET_REG_STATE_UNREGISTERING;
  1131. fgDoUnregister = TRUE;
  1132. }
  1133. GLUE_RELEASE_SPIN_LOCK(prGlueInfo, SPIN_LOCK_NET_DEV);
  1134. if (!fgDoUnregister)
  1135. return TRUE;
  1136. /* prepare for removal */
  1137. if (netif_carrier_ok(prGlueInfo->prP2PInfo->prDevHandler))
  1138. netif_carrier_off(prGlueInfo->prP2PInfo->prDevHandler);
  1139. netif_tx_stop_all_queues(prGlueInfo->prP2PInfo->prDevHandler);
  1140. if (fgIsRtnlLockAcquired && rtnl_is_locked()) {
  1141. fgRollbackRtnlLock = TRUE;
  1142. rtnl_unlock();
  1143. }
  1144. /* Here are functions which need rtnl_lock */
  1145. unregister_netdev(prGlueInfo->prP2PInfo->prDevHandler);
  1146. if (fgRollbackRtnlLock)
  1147. rtnl_lock();
  1148. prGlueInfo->prAdapter->rP2PNetRegState = ENUM_NET_REG_STATE_UNREGISTERED;
  1149. return TRUE;
  1150. }
  1151. /*----------------------------------------------------------------------------*/
  1152. /*!
  1153. * \brief Register for cfg80211 for Wi-Fi Direct
  1154. *
  1155. * \param[in] prGlueInfo Pointer to glue info
  1156. *
  1157. * \return TRUE
  1158. * FALSE
  1159. */
  1160. /*----------------------------------------------------------------------------*/
  1161. BOOLEAN glRegisterP2P(P_GLUE_INFO_T prGlueInfo, const char *prDevName, BOOLEAN fgIsApMode)
  1162. {
  1163. P_ADAPTER_T prAdapter = NULL;
  1164. P_GL_HIF_INFO_T prHif = NULL;
  1165. PARAM_MAC_ADDRESS rMacAddr;
  1166. P_NETDEV_PRIVATE_GLUE_INFO prNetDevPriv = (P_NETDEV_PRIVATE_GLUE_INFO) NULL;
  1167. #if CFG_ENABLE_WIFI_DIRECT_CFG_80211
  1168. struct device *prDev;
  1169. #endif
  1170. ASSERT(prGlueInfo);
  1171. prAdapter = prGlueInfo->prAdapter;
  1172. ASSERT(prAdapter);
  1173. prHif = &prGlueInfo->rHifInfo;
  1174. ASSERT(prHif);
  1175. #if CFG_ENABLE_WIFI_DIRECT_CFG_80211
  1176. if (!gprP2pWdev) {
  1177. DBGLOG(P2P, ERROR, "gl_p2p, wireless device is not exist\n");
  1178. return FALSE;
  1179. }
  1180. #endif
  1181. DBGLOG(INIT, INFO, "glRegisterP2P\n");
  1182. /*0. allocate p2pinfo */
  1183. if (!p2PAllocInfo(prGlueInfo)) {
  1184. DBGLOG(INIT, WARN, "Allocate memory for p2p FAILED\n");
  1185. ASSERT(0);
  1186. return FALSE;
  1187. }
  1188. #if CFG_ENABLE_WIFI_DIRECT_CFG_80211
  1189. /* 1.1 fill wiphy parameters */
  1190. #if MTK_WCN_HIF_SDIO
  1191. mtk_wcn_hif_sdio_get_dev(prHif->cltCtx, &prDev);
  1192. if (!prDev) {
  1193. DBGLOG(INIT, INFO,
  1194. "unable to get struct dev for p2p\n");
  1195. }
  1196. #else
  1197. prDev = &(prHif->func->dev);
  1198. #endif
  1199. prGlueInfo->prP2PInfo->prWdev = gprP2pWdev;
  1200. /*set_wiphy_dev(gprP2pWdev->wiphy, prDev);*/
  1201. if (!prGlueInfo->prAdapter->fgEnable5GBand)
  1202. gprP2pWdev->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
  1203. /* 2.2 wdev initialization */
  1204. if (fgIsApMode)
  1205. gprP2pWdev->iftype = NL80211_IFTYPE_AP;
  1206. else
  1207. gprP2pWdev->iftype = NL80211_IFTYPE_P2P_CLIENT;
  1208. #endif /* CFG_ENABLE_WIFI_DIRECT_CFG_80211 */
  1209. /* 3. allocate netdev */
  1210. prGlueInfo->prP2PInfo->prDevHandler =
  1211. alloc_netdev_mq(sizeof(NETDEV_PRIVATE_GLUE_INFO), prDevName,
  1212. NET_NAME_PREDICTABLE, ether_setup, CFG_MAX_TXQ_NUM);
  1213. if (!prGlueInfo->prP2PInfo->prDevHandler) {
  1214. DBGLOG(INIT, WARN, "unable to allocate netdevice for p2p\n");
  1215. goto err_alloc_netdev;
  1216. }
  1217. /* 4. setup netdev */
  1218. /* 4.1 Point to shared glue structure */
  1219. /* *((P_GLUE_INFO_T *) netdev_priv(prGlueInfo->prP2PInfo->prDevHandler)) = prGlueInfo; */
  1220. prNetDevPriv = (P_NETDEV_PRIVATE_GLUE_INFO) netdev_priv(prGlueInfo->prP2PInfo->prDevHandler);
  1221. prNetDevPriv->prGlueInfo = prGlueInfo;
  1222. /* 4.2 fill hardware address */
  1223. COPY_MAC_ADDR(rMacAddr, prAdapter->rMyMacAddr);
  1224. rMacAddr[0] ^= 0x2; /* change to local administrated address */
  1225. ether_addr_copy(prGlueInfo->prP2PInfo->prDevHandler->dev_addr, rMacAddr);
  1226. ether_addr_copy(prGlueInfo->prP2PInfo->prDevHandler->perm_addr, prGlueInfo->prP2PInfo->prDevHandler->dev_addr);
  1227. /* 4.3 register callback functions */
  1228. prGlueInfo->prP2PInfo->prDevHandler->netdev_ops = &p2p_netdev_ops;
  1229. /* prGlueInfo->prP2PInfo->prDevHandler->wireless_handlers = &mtk_p2p_wext_handler_def; */
  1230. #if (MTK_WCN_HIF_SDIO == 0)
  1231. SET_NETDEV_DEV(prGlueInfo->prP2PInfo->prDevHandler, &(prHif->func->dev));
  1232. #endif
  1233. #if CFG_ENABLE_WIFI_DIRECT_CFG_80211
  1234. prGlueInfo->prP2PInfo->prDevHandler->ieee80211_ptr = gprP2pWdev;
  1235. gprP2pWdev->netdev = prGlueInfo->prP2PInfo->prDevHandler;
  1236. #endif
  1237. #if CFG_TCP_IP_CHKSUM_OFFLOAD
  1238. prGlueInfo->prP2PInfo->prDevHandler->features = NETIF_F_IP_CSUM;
  1239. #endif /* CFG_TCP_IP_CHKSUM_OFFLOAD */
  1240. kalResetStats(prGlueInfo->prP2PInfo->prDevHandler);
  1241. #if 0
  1242. /* 7. net device initialize */
  1243. netif_carrier_off(prGlueInfo->prP2PInfo->prDevHandler);
  1244. netif_tx_stop_all_queues(prGlueInfo->prP2PInfo->prDevHandler);
  1245. /* 8. register for net device */
  1246. if (register_netdev(prGlueInfo->prP2PInfo->prDevHandler) < 0) {
  1247. DBGLOG(INIT, WARN, "unable to register netdevice for p2p\n");
  1248. goto err_reg_netdev;
  1249. }
  1250. #endif
  1251. /* 8. set p2p net device register state */
  1252. prGlueInfo->prAdapter->rP2PNetRegState = ENUM_NET_REG_STATE_UNREGISTERED;
  1253. /* 9. setup running mode */
  1254. /* prGlueInfo->prAdapter->rWifiVar.prP2pFsmInfo->fgIsApMode = fgIsApMode; */
  1255. /* 10. finish */
  1256. /* 13. bind netdev pointer to netdev index */
  1257. wlanBindBssIdxToNetInterface(prGlueInfo, p2pDevFsmInit(prAdapter), (PVOID) prGlueInfo->prP2PInfo->prDevHandler);
  1258. prGlueInfo->prP2PInfo->aprRoleHandler[0] = prGlueInfo->prP2PInfo->prDevHandler;
  1259. prNetDevPriv->ucBssIdx = p2pRoleFsmInit(prAdapter, 0);
  1260. /* 11. Currently wpasupplicant can't support create interface. */
  1261. /* so initial the corresponding data structure here. */
  1262. wlanBindBssIdxToNetInterface(prGlueInfo, prNetDevPriv->ucBssIdx,
  1263. (PVOID) prGlueInfo->prP2PInfo->aprRoleHandler[0]);
  1264. /* 13. bind netdev pointer to netdev index */
  1265. /* wlanBindNetInterface(prGlueInfo, NET_DEV_P2P_IDX, (PVOID)prGlueInfo->prP2PInfo->prDevHandler); */
  1266. /* 12. setup running mode */
  1267. p2pFuncInitConnectionSettings(prAdapter, prAdapter->rWifiVar.prP2PConnSettings, fgIsApMode);
  1268. /* Active network too early would cause HW not able to sleep.
  1269. * Defer the network active time.
  1270. */
  1271. /* nicActivateNetwork(prAdapter, NETWORK_TYPE_P2P_INDEX); */
  1272. return TRUE;
  1273. #if 0
  1274. err_reg_netdev:
  1275. free_netdev(prGlueInfo->prP2PInfo->prDevHandler);
  1276. #endif
  1277. err_alloc_netdev:
  1278. return FALSE;
  1279. } /* end of glRegisterP2P() */
  1280. BOOLEAN glP2pCreateWirelessDevice(P_GLUE_INFO_T prGlueInfo)
  1281. {
  1282. struct wiphy *prWiphy = NULL;
  1283. struct wireless_dev *prWdev = NULL;
  1284. #if CFG_ENABLE_WIFI_DIRECT_CFG_80211
  1285. prWdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
  1286. if (!prWdev) {
  1287. DBGLOG(P2P, ERROR, "allocate p2p wireless device fail, no memory\n");
  1288. return FALSE;
  1289. }
  1290. /* 1. allocate WIPHY */
  1291. prWiphy = wiphy_new(&mtk_p2p_ops, sizeof(P_GLUE_INFO_T));
  1292. if (!prWiphy) {
  1293. DBGLOG(P2P, ERROR, "unable to allocate wiphy for p2p\n");
  1294. goto free_wdev;
  1295. }
  1296. prWiphy->interface_modes = BIT(NL80211_IFTYPE_AP)
  1297. | BIT(NL80211_IFTYPE_P2P_CLIENT)
  1298. | BIT(NL80211_IFTYPE_P2P_GO)
  1299. | BIT(NL80211_IFTYPE_STATION);
  1300. prWiphy->bands[IEEE80211_BAND_2GHZ] = &mtk_band_2ghz;
  1301. prWiphy->bands[IEEE80211_BAND_5GHZ] = &mtk_band_5ghz;
  1302. prWiphy->mgmt_stypes = mtk_cfg80211_default_mgmt_stypes;
  1303. prWiphy->max_remain_on_channel_duration = 5000;
  1304. prWiphy->cipher_suites = mtk_cipher_suites;
  1305. prWiphy->n_cipher_suites = ARRAY_SIZE(mtk_cipher_suites);
  1306. prWiphy->flags = WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL | WIPHY_FLAG_HAVE_AP_SME;
  1307. prWiphy->regulatory_flags = REGULATORY_CUSTOM_REG;
  1308. prWiphy->ap_sme_capa = 1;
  1309. prWiphy->max_scan_ssids = MAX_SCAN_LIST_NUM;
  1310. prWiphy->max_scan_ie_len = MAX_SCAN_IE_LEN;
  1311. prWiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  1312. prWiphy->vendor_commands = mtk_p2p_vendor_ops;
  1313. prWiphy->n_vendor_commands = sizeof(mtk_p2p_vendor_ops) / sizeof(struct wiphy_vendor_command);
  1314. #ifdef CONFIG_PM
  1315. prWiphy->wowlan = &mtk_p2p_wowlan_support;
  1316. #endif
  1317. /* 2.1 set priv as pointer to glue structure */
  1318. *((P_GLUE_INFO_T *) wiphy_priv(prWiphy)) = prGlueInfo;
  1319. /* Here are functions which need rtnl_lock */
  1320. if (wiphy_register(prWiphy) < 0) {
  1321. DBGLOG(INIT, WARN, "fail to register wiphy for p2p\n");
  1322. goto free_wiphy;
  1323. }
  1324. prWdev->wiphy = prWiphy;
  1325. gprP2pWdev = prWdev;
  1326. return TRUE;
  1327. free_wiphy:
  1328. wiphy_free(prWiphy);
  1329. free_wdev:
  1330. kfree(prWdev);
  1331. #endif
  1332. return FALSE;
  1333. }
  1334. void glP2pDestroyWirelessDevice(void)
  1335. {
  1336. #if CFG_ENABLE_WIFI_DIRECT_CFG_80211
  1337. wiphy_unregister(gprP2pWdev->wiphy);
  1338. wiphy_free(gprP2pWdev->wiphy);
  1339. kfree(gprP2pWdev);
  1340. gprP2pWdev = NULL;
  1341. #endif
  1342. }
  1343. /*----------------------------------------------------------------------------*/
  1344. /*!
  1345. * \brief Unregister Net Device for Wi-Fi Direct
  1346. *
  1347. * \param[in] prGlueInfo Pointer to glue info
  1348. *
  1349. * \return TRUE
  1350. * FALSE
  1351. */
  1352. /*----------------------------------------------------------------------------*/
  1353. BOOLEAN glUnregisterP2P(P_GLUE_INFO_T prGlueInfo)
  1354. {
  1355. UINT_8 ucRoleIdx;
  1356. P_ADAPTER_T prAdapter;
  1357. ASSERT(prGlueInfo);
  1358. prAdapter = prGlueInfo->prAdapter;
  1359. /* 4 <1> Uninit P2P dev FSM */
  1360. /* Uninit P2P device FSM */
  1361. p2pDevFsmUninit(prAdapter);
  1362. /* 4 <2> Uninit P2P role FSM */
  1363. for (ucRoleIdx = 0; ucRoleIdx < BSS_P2P_NUM; ucRoleIdx++) {
  1364. if (P2P_ROLE_INDEX_2_ROLE_FSM_INFO(prAdapter, ucRoleIdx))
  1365. p2pRoleFsmUninit(prGlueInfo->prAdapter, ucRoleIdx);
  1366. }
  1367. /* 4 <3> Free Wiphy & netdev */
  1368. free_netdev(prGlueInfo->prP2PInfo->prDevHandler);
  1369. prGlueInfo->prP2PInfo->prDevHandler = NULL;
  1370. /* 4 <4> Free P2P internal memory */
  1371. if (!p2PFreeInfo(prGlueInfo)) {
  1372. DBGLOG(INIT, WARN, "Free memory for p2p FAILED\n");
  1373. ASSERT(0);
  1374. return FALSE;
  1375. }
  1376. return TRUE;
  1377. #if 0
  1378. p2pFsmUninit(prGlueInfo->prAdapter);
  1379. nicDeactivateNetwork(prGlueInfo->prAdapter, NETWORK_TYPE_P2P_INDEX);
  1380. #if 0
  1381. /* Release command, mgmt and security frame belong to P2P network in
  1382. * prGlueInfo->prCmdQue
  1383. * prAdapter->rPendingCmdQueue
  1384. * prAdapter->rTxCtrl.rTxMgmtTxingQueue
  1385. * To ensure there is no pending CmdDone/TxDone handler to be executed after p2p module is removed.
  1386. */
  1387. /* Clear CmdQue */
  1388. kalClearMgmtFramesByBssIdx(prGlueInfo, NETWORK_TYPE_P2P_INDEX);
  1389. kalClearSecurityFramesByBssIdx(prGlueInfo, NETWORK_TYPE_P2P_INDEX);
  1390. /* Clear PendingCmdQue */
  1391. wlanReleasePendingCMDbyBssIdx(prGlueInfo->prAdapter, NETWORK_TYPE_P2P_INDEX);
  1392. /* Clear PendingTxMsdu */
  1393. nicFreePendingTxMsduInfoByBssIdx(prGlueInfo->prAdapter, NETWORK_TYPE_P2P_INDEX);
  1394. #endif
  1395. #if 0
  1396. /* prepare for removal */
  1397. if (netif_carrier_ok(prGlueInfo->prP2PInfo->prDevHandler))
  1398. netif_carrier_off(prGlueInfo->prP2PInfo->prDevHandler);
  1399. netif_tx_stop_all_queues(prGlueInfo->prP2PInfo->prDevHandler);
  1400. /* netdevice unregistration & free */
  1401. unregister_netdev(prGlueInfo->prP2PInfo->prDevHandler);
  1402. #endif
  1403. free_netdev(prGlueInfo->prP2PInfo->prDevHandler);
  1404. prGlueInfo->prP2PInfo->prDevHandler = NULL;
  1405. #if CFG_ENABLE_WIFI_DIRECT_CFG_80211
  1406. #if 0
  1407. wiphy_unregister(prGlueInfo->prP2PInfo->wdev.wiphy);
  1408. #endif
  1409. wiphy_free(prGlueInfo->prP2PInfo->wdev.wiphy);
  1410. prGlueInfo->prP2PInfo->wdev.wiphy = NULL;
  1411. #endif
  1412. /* Free p2p memory */
  1413. #if 1
  1414. if (!p2PFreeInfo(prGlueInfo)) {
  1415. DBGLOG(INIT, WARN, "Free memory for p2p FAILED\n");
  1416. ASSERT(0);
  1417. return FALSE;
  1418. }
  1419. #endif
  1420. return TRUE;
  1421. #else
  1422. return 0;
  1423. #endif
  1424. } /* end of glUnregisterP2P() */
  1425. /* Net Device Hooks */
  1426. /*----------------------------------------------------------------------------*/
  1427. /*!
  1428. * \brief A function for net_device open (ifup)
  1429. *
  1430. * \param[in] prDev Pointer to struct net_device.
  1431. *
  1432. * \retval 0 The execution succeeds.
  1433. * \retval < 0 The execution failed.
  1434. */
  1435. /*----------------------------------------------------------------------------*/
  1436. static int p2pOpen(IN struct net_device *prDev)
  1437. {
  1438. /* P_GLUE_INFO_T prGlueInfo = NULL; */
  1439. /* P_ADAPTER_T prAdapter = NULL; */
  1440. /* P_MSG_P2P_FUNCTION_SWITCH_T prFuncSwitch; */
  1441. ASSERT(prDev);
  1442. #if 0 /* Move after device name set. (mtk_p2p_set_local_dev_info) */
  1443. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  1444. ASSERT(prGlueInfo);
  1445. prAdapter = prGlueInfo->prAdapter;
  1446. ASSERT(prAdapter);
  1447. /* 1. switch P2P-FSM on */
  1448. /* 1.1 allocate for message */
  1449. prFuncSwitch = (P_MSG_P2P_FUNCTION_SWITCH_T) cnmMemAlloc(prAdapter,
  1450. RAM_TYPE_MSG, sizeof(MSG_P2P_FUNCTION_SWITCH_T));
  1451. if (!prFuncSwitch) {
  1452. ASSERT(0); /* Can't trigger P2P FSM */
  1453. return -ENOMEM;
  1454. }
  1455. /* 1.2 fill message */
  1456. prFuncSwitch->rMsgHdr.eMsgId = MID_MNY_P2P_FUN_SWITCH;
  1457. prFuncSwitch->fgIsFuncOn = TRUE;
  1458. /* 1.3 send message */
  1459. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prFuncSwitch, MSG_SEND_METHOD_BUF);
  1460. #endif
  1461. /* 2. carrier on & start TX queue */
  1462. netif_carrier_on(prDev);
  1463. netif_tx_start_all_queues(prDev);
  1464. return 0; /* success */
  1465. } /* end of p2pOpen() */
  1466. /*----------------------------------------------------------------------------*/
  1467. /*!
  1468. * \brief A function for net_device stop (ifdown)
  1469. *
  1470. * \param[in] prDev Pointer to struct net_device.
  1471. *
  1472. * \retval 0 The execution succeeds.
  1473. * \retval < 0 The execution failed.
  1474. */
  1475. /*----------------------------------------------------------------------------*/
  1476. static int p2pStop(IN struct net_device *prDev)
  1477. {
  1478. P_GLUE_INFO_T prGlueInfo = NULL;
  1479. P_ADAPTER_T prAdapter = NULL;
  1480. struct cfg80211_scan_request *prScanRequest = NULL;
  1481. P_GL_P2P_INFO_T prGlueP2pInfo = (P_GL_P2P_INFO_T) NULL;
  1482. /* P_MSG_P2P_FUNCTION_SWITCH_T prFuncSwitch; */
  1483. GLUE_SPIN_LOCK_DECLARATION();
  1484. ASSERT(prDev);
  1485. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  1486. ASSERT(prGlueInfo);
  1487. prAdapter = prGlueInfo->prAdapter;
  1488. ASSERT(prAdapter);
  1489. prGlueP2pInfo = prGlueInfo->prP2PInfo;
  1490. /* CFG80211 down */
  1491. GLUE_ACQUIRE_SPIN_LOCK(prGlueInfo, SPIN_LOCK_NET_DEV);
  1492. if (prGlueP2pInfo->prScanRequest != NULL) {
  1493. prScanRequest = prGlueP2pInfo->prScanRequest;
  1494. prGlueP2pInfo->prScanRequest = NULL;
  1495. } else
  1496. DBGLOG(P2P, WARN, "[p2p] scan complete but cfg80211 scan request is NULL\n");
  1497. GLUE_RELEASE_SPIN_LOCK(prGlueInfo, SPIN_LOCK_NET_DEV);
  1498. if (prScanRequest)
  1499. cfg80211_scan_done(prScanRequest, TRUE);
  1500. /* 1. stop TX queue */
  1501. netif_tx_stop_all_queues(prDev);
  1502. #if 0
  1503. /* 2. switch P2P-FSM off */
  1504. /* 2.1 allocate for message */
  1505. prFuncSwitch = (P_MSG_P2P_FUNCTION_SWITCH_T) cnmMemAlloc(prAdapter,
  1506. RAM_TYPE_MSG, sizeof(MSG_P2P_FUNCTION_SWITCH_T));
  1507. if (!prFuncSwitch) {
  1508. ASSERT(0); /* Can't trigger P2P FSM */
  1509. return -ENOMEM;
  1510. }
  1511. /* 2.2 fill message */
  1512. prFuncSwitch->rMsgHdr.eMsgId = MID_MNY_P2P_FUN_SWITCH;
  1513. prFuncSwitch->fgIsFuncOn = FALSE;
  1514. /* 2.3 send message */
  1515. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prFuncSwitch, MSG_SEND_METHOD_BUF);
  1516. #endif
  1517. /* 3. stop queue and turn off carrier */
  1518. prGlueInfo->prP2PInfo->eState = PARAM_MEDIA_STATE_DISCONNECTED;
  1519. netif_tx_stop_all_queues(prDev);
  1520. if (netif_carrier_ok(prDev))
  1521. netif_carrier_off(prDev);
  1522. return 0;
  1523. } /* end of p2pStop() */
  1524. /*----------------------------------------------------------------------------*/
  1525. /*!
  1526. * \brief A method of struct net_device, to get the network interface statistical
  1527. * information.
  1528. *
  1529. * Whenever an application needs to get statistics for the interface, this method
  1530. * is called. This happens, for example, when ifconfig or netstat -i is run.
  1531. *
  1532. * \param[in] prDev Pointer to struct net_device.
  1533. *
  1534. * \return net_device_stats buffer pointer.
  1535. */
  1536. /*----------------------------------------------------------------------------*/
  1537. struct net_device_stats *p2pGetStats(IN struct net_device *prDev)
  1538. {
  1539. return (struct net_device_stats *)kalGetStats(prDev);
  1540. } /* end of p2pGetStats() */
  1541. static void p2pSetMulticastList(IN struct net_device *prDev)
  1542. {
  1543. P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T) NULL;
  1544. prGlueInfo = (NULL != prDev) ? *((P_GLUE_INFO_T *) netdev_priv(prDev)) : NULL;
  1545. ASSERT(prDev);
  1546. ASSERT(prGlueInfo);
  1547. if (!prDev || !prGlueInfo) {
  1548. DBGLOG(INIT, WARN,
  1549. " abnormal dev or skb: prDev(0x%p), prGlueInfo(0x%p)\n", prDev, prGlueInfo);
  1550. return;
  1551. }
  1552. g_P2pPrDev = prDev;
  1553. /* 4 Mark HALT, notify main thread to finish current job */
  1554. set_bit(GLUE_FLAG_SUB_MOD_MULTICAST_BIT, &prGlueInfo->ulFlag);
  1555. /* wake up main thread */
  1556. wake_up_interruptible(&prGlueInfo->waitq);
  1557. } /* p2pSetMulticastList */
  1558. /* FIXME: Since we cannot sleep in the wlanSetMulticastList, we arrange
  1559. * another workqueue for sleeping. We don't want to block
  1560. * tx_thread, so we can't let tx_thread to do this */
  1561. void p2pSetMulticastListWorkQueueWrapper(P_GLUE_INFO_T prGlueInfo)
  1562. {
  1563. if (!prGlueInfo) {
  1564. DBGLOG(INIT, ERROR, "prGlueInfo is NULL\n");
  1565. return;
  1566. }
  1567. #if CFG_ENABLE_WIFI_DIRECT
  1568. if (prGlueInfo->prAdapter->fgIsP2PRegistered)
  1569. mtk_p2p_wext_set_Multicastlist(prGlueInfo);
  1570. #endif
  1571. } /* end of p2pSetMulticastListWorkQueueWrapper() */
  1572. /*----------------------------------------------------------------------------*/
  1573. /*!
  1574. * \brief This function is to set multicast list and set rx mode.
  1575. *
  1576. * \param[in] prDev Pointer to struct net_device
  1577. *
  1578. * \return (none)
  1579. */
  1580. /*----------------------------------------------------------------------------*/
  1581. void mtk_p2p_wext_set_Multicastlist(P_GLUE_INFO_T prGlueInfo)
  1582. {
  1583. UINT_32 u4SetInfoLen = 0;
  1584. UINT_32 u4McCount;
  1585. struct net_device *prDev = g_P2pPrDev;
  1586. prGlueInfo = (NULL != prDev) ? *((P_GLUE_INFO_T *) netdev_priv(prDev)) : NULL;
  1587. ASSERT(prDev);
  1588. ASSERT(prGlueInfo);
  1589. if (!prDev || !prGlueInfo) {
  1590. DBGLOG(INIT, WARN,
  1591. " abnormal dev or skb: prDev(0x%p), prGlueInfo(0x%p)\n", prDev, prGlueInfo);
  1592. return;
  1593. }
  1594. if (prDev->flags & IFF_PROMISC)
  1595. prGlueInfo->prP2PInfo->u4PacketFilter |= PARAM_PACKET_FILTER_PROMISCUOUS;
  1596. if (prDev->flags & IFF_BROADCAST)
  1597. prGlueInfo->prP2PInfo->u4PacketFilter |= PARAM_PACKET_FILTER_BROADCAST;
  1598. u4McCount = netdev_mc_count(prDev);
  1599. if (prDev->flags & IFF_MULTICAST) {
  1600. if ((prDev->flags & IFF_ALLMULTI) || (u4McCount > MAX_NUM_GROUP_ADDR))
  1601. prGlueInfo->prP2PInfo->u4PacketFilter |= PARAM_PACKET_FILTER_ALL_MULTICAST;
  1602. else
  1603. prGlueInfo->prP2PInfo->u4PacketFilter |= PARAM_PACKET_FILTER_MULTICAST;
  1604. }
  1605. if (prGlueInfo->prP2PInfo->u4PacketFilter & PARAM_PACKET_FILTER_MULTICAST) {
  1606. /* Prepare multicast address list */
  1607. struct netdev_hw_addr *ha;
  1608. UINT_32 i = 0;
  1609. netdev_for_each_mc_addr(ha, prDev) {
  1610. if (i < MAX_NUM_GROUP_ADDR) {
  1611. COPY_MAC_ADDR(&(prGlueInfo->prP2PInfo->aucMCAddrList[i]), ha->addr);
  1612. i++;
  1613. }
  1614. }
  1615. DBGLOG(P2P, TRACE, "SEt Multicast Address List\n");
  1616. if (i >= MAX_NUM_GROUP_ADDR)
  1617. return;
  1618. wlanoidSetP2PMulticastList(prGlueInfo->prAdapter,
  1619. &(prGlueInfo->prP2PInfo->aucMCAddrList[0]), (i * ETH_ALEN), &u4SetInfoLen);
  1620. }
  1621. } /* end of mtk_p2p_wext_set_Multicastlist() */
  1622. /*----------------------------------------------------------------------------*/
  1623. /*!
  1624. * * \brief This function is TX entry point of NET DEVICE.
  1625. * *
  1626. * * \param[in] prSkb Pointer of the sk_buff to be sent
  1627. * * \param[in] prDev Pointer to struct net_device
  1628. * *
  1629. * * \retval NETDEV_TX_OK - on success.
  1630. * * \retval NETDEV_TX_BUSY - on failure, packet will be discarded by upper layer.
  1631. * */
  1632. /*----------------------------------------------------------------------------*/
  1633. int p2pHardStartXmit(IN struct sk_buff *prSkb, IN struct net_device *prDev)
  1634. {
  1635. P_NETDEV_PRIVATE_GLUE_INFO prNetDevPrivate = (P_NETDEV_PRIVATE_GLUE_INFO) NULL;
  1636. P_GLUE_INFO_T prGlueInfo = NULL;
  1637. UINT_8 ucBssIndex;
  1638. ASSERT(prSkb);
  1639. ASSERT(prDev);
  1640. prNetDevPrivate = (P_NETDEV_PRIVATE_GLUE_INFO) netdev_priv(prDev);
  1641. prGlueInfo = prNetDevPrivate->prGlueInfo;
  1642. ucBssIndex = prNetDevPrivate->ucBssIdx;
  1643. kalResetPacket(prGlueInfo, (P_NATIVE_PACKET) prSkb);
  1644. kalHardStartXmit(prSkb, prDev, prGlueInfo, ucBssIndex);
  1645. return NETDEV_TX_OK;
  1646. } /* end of p2pHardStartXmit() */
  1647. /*----------------------------------------------------------------------------*/
  1648. /*!
  1649. * \brief A method of struct net_device, a primary SOCKET interface to configure
  1650. * the interface lively. Handle an ioctl call on one of our devices.
  1651. * Everything Linux ioctl specific is done here. Then we pass the contents
  1652. * of the ifr->data to the request message handler.
  1653. *
  1654. * \param[in] prDev Linux kernel netdevice
  1655. *
  1656. * \param[in] prIfReq Our private ioctl request structure, typed for the generic
  1657. * struct ifreq so we can use ptr to function
  1658. *
  1659. * \param[in] cmd Command ID
  1660. *
  1661. * \retval 0 The IOCTL command is executed successfully.
  1662. * \retval <0 The execution of IOCTL command is failed.
  1663. */
  1664. /*----------------------------------------------------------------------------*/
  1665. int p2pDoIOCTL(struct net_device *prDev, struct ifreq *prIfReq, int i4Cmd)
  1666. {
  1667. P_GLUE_INFO_T prGlueInfo = NULL;
  1668. int ret = 0;
  1669. /* char *prExtraBuf = NULL; */
  1670. /* UINT_32 u4ExtraSize = 0; */
  1671. /* struct iwreq *prIwReq = (struct iwreq *)prIfReq; */
  1672. /* struct iw_request_info rIwReqInfo; */
  1673. ASSERT(prDev && prIfReq);
  1674. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  1675. if (!prGlueInfo) {
  1676. DBGLOG(P2P, ERROR, "prGlueInfo is NULL\n");
  1677. return -EFAULT;
  1678. }
  1679. if (prGlueInfo->u4ReadyFlag == 0) {
  1680. DBGLOG(P2P, ERROR, "Adapter is not ready\n");
  1681. return -EINVAL;
  1682. }
  1683. if (i4Cmd == SIOCDEVPRIVATE + 1) {
  1684. ret = priv_support_driver_cmd(prDev, prIfReq, i4Cmd);
  1685. } else {
  1686. DBGLOG(INIT, WARN, "Unexpected ioctl command: 0x%04x\n", i4Cmd);
  1687. ret = -1;
  1688. }
  1689. #if 0
  1690. /* fill rIwReqInfo */
  1691. rIwReqInfo.cmd = (__u16) i4Cmd;
  1692. rIwReqInfo.flags = 0;
  1693. switch (i4Cmd) {
  1694. case SIOCSIWENCODEEXT:
  1695. /* Set Encryption Material after 4-way handshaking is done */
  1696. if (prIwReq->u.encoding.pointer) {
  1697. u4ExtraSize = prIwReq->u.encoding.length;
  1698. prExtraBuf = kalMemAlloc(u4ExtraSize, VIR_MEM_TYPE);
  1699. if (!prExtraBuf) {
  1700. ret = -ENOMEM;
  1701. break;
  1702. }
  1703. if (copy_from_user(prExtraBuf, prIwReq->u.encoding.pointer, prIwReq->u.encoding.length))
  1704. ret = -EFAULT;
  1705. } else if (prIwReq->u.encoding.length != 0) {
  1706. ret = -EINVAL;
  1707. break;
  1708. }
  1709. if (ret == 0)
  1710. ret = mtk_p2p_wext_set_key(prDev, &rIwReqInfo, &(prIwReq->u), prExtraBuf);
  1711. kalMemFree(prExtraBuf, VIR_MEM_TYPE, u4ExtraSize);
  1712. prExtraBuf = NULL;
  1713. break;
  1714. case SIOCSIWMLME:
  1715. /* IW_MLME_DISASSOC used for disconnection */
  1716. if (prIwReq->u.data.length != sizeof(struct iw_mlme)) {
  1717. DBGLOG(INIT, INFO, "MLME buffer strange:%d\n", prIwReq->u.data.length);
  1718. ret = -EINVAL;
  1719. break;
  1720. }
  1721. if (!prIwReq->u.data.pointer) {
  1722. ret = -EINVAL;
  1723. break;
  1724. }
  1725. prExtraBuf = kalMemAlloc(sizeof(struct iw_mlme), VIR_MEM_TYPE);
  1726. if (!prExtraBuf) {
  1727. ret = -ENOMEM;
  1728. break;
  1729. }
  1730. if (copy_from_user(prExtraBuf, prIwReq->u.data.pointer, sizeof(struct iw_mlme)))
  1731. ret = -EFAULT;
  1732. else
  1733. ret = mtk_p2p_wext_mlme_handler(prDev, &rIwReqInfo, &(prIwReq->u), prExtraBuf);
  1734. kalMemFree(prExtraBuf, VIR_MEM_TYPE, sizeof(struct iw_mlme));
  1735. prExtraBuf = NULL;
  1736. break;
  1737. case SIOCGIWPRIV:
  1738. /* This ioctl is used to list all IW privilege ioctls */
  1739. ret = mtk_p2p_wext_get_priv(prDev, &rIwReqInfo, &(prIwReq->u), NULL);
  1740. break;
  1741. case SIOCGIWSCAN:
  1742. ret = mtk_p2p_wext_discovery_results(prDev, &rIwReqInfo, &(prIwReq->u), NULL);
  1743. break;
  1744. case SIOCSIWAUTH:
  1745. ret = mtk_p2p_wext_set_auth(prDev, &rIwReqInfo, &(prIwReq->u), NULL);
  1746. break;
  1747. case IOC_P2P_CFG_DEVICE:
  1748. case IOC_P2P_PROVISION_COMPLETE:
  1749. case IOC_P2P_START_STOP_DISCOVERY:
  1750. case IOC_P2P_DISCOVERY_RESULTS:
  1751. case IOC_P2P_WSC_BEACON_PROBE_RSP_IE:
  1752. case IOC_P2P_CONNECT_DISCONNECT:
  1753. case IOC_P2P_PASSWORD_READY:
  1754. case IOC_P2P_GET_STRUCT:
  1755. case IOC_P2P_SET_STRUCT:
  1756. case IOC_P2P_GET_REQ_DEVICE_INFO:
  1757. /* ret = rP2PIwPrivHandler[i4Cmd - SIOCIWFIRSTPRIV](prDev,
  1758. &rIwReqInfo,
  1759. &(prIwReq->u),
  1760. (char *)&(prIwReq->u)); */
  1761. break;
  1762. #if CFG_SUPPORT_P2P_RSSI_QUERY
  1763. case SIOCGIWSTATS:
  1764. ret = mtk_p2p_wext_get_rssi(prDev, &rIwReqInfo, &(prIwReq->u), NULL);
  1765. break;
  1766. #endif
  1767. default:
  1768. ret = -ENOTTY;
  1769. }
  1770. #endif /* 0 */
  1771. return ret;
  1772. } /* end of p2pDoIOCTL() */
  1773. /*----------------------------------------------------------------------------*/
  1774. /*!
  1775. * \brief To override p2p interface address
  1776. *
  1777. * \param[in] prDev Net device requested.
  1778. * \param[in] addr Pointer to address
  1779. *
  1780. * \retval 0 For success.
  1781. * \retval -E2BIG For user's buffer size is too small.
  1782. * \retval -EFAULT For fail.
  1783. *
  1784. */
  1785. /*----------------------------------------------------------------------------*/
  1786. int p2pSetMACAddress(IN struct net_device *prDev, void *addr)
  1787. {
  1788. P_ADAPTER_T prAdapter = NULL;
  1789. P_GLUE_INFO_T prGlueInfo = NULL;
  1790. ASSERT(prDev);
  1791. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  1792. ASSERT(prGlueInfo);
  1793. prAdapter = prGlueInfo->prAdapter;
  1794. ASSERT(prAdapter);
  1795. /* @FIXME */
  1796. return eth_mac_addr(prDev, addr);
  1797. }
  1798. #if 0
  1799. /*----------------------------------------------------------------------------*/
  1800. /*!
  1801. * \brief To report the iw private args table to user space.
  1802. *
  1803. * \param[in] prDev Net device requested.
  1804. * \param[in] info Pointer to iw_request_info.
  1805. * \param[inout] wrqu Pointer to iwreq_data.
  1806. * \param[inout] extra
  1807. *
  1808. * \retval 0 For success.
  1809. * \retval -E2BIG For user's buffer size is too small.
  1810. * \retval -EFAULT For fail.
  1811. *
  1812. */
  1813. /*----------------------------------------------------------------------------*/
  1814. int
  1815. mtk_p2p_wext_get_priv(IN struct net_device *prDev,
  1816. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  1817. {
  1818. struct iw_point *prData = (struct iw_point *)&wrqu->data;
  1819. UINT_16 u2BufferSize = prData->length;
  1820. /* Update our private args table size */
  1821. prData->length = (__u16)sizeof(rP2PIwPrivTable);
  1822. if (u2BufferSize < prData->length)
  1823. return -E2BIG;
  1824. if (prData->length) {
  1825. if (copy_to_user(prData->pointer, rP2PIwPrivTable, sizeof(rP2PIwPrivTable)))
  1826. return -EFAULT;
  1827. }
  1828. return 0;
  1829. } /* end of mtk_p2p_wext_get_priv() */
  1830. /*----------------------------------------------------------------------------*/
  1831. /*!
  1832. * \brief To indicate P2P-FSM for re-associate to the connecting device
  1833. *
  1834. * \param[in] prDev Net device requested.
  1835. * \param[inout] wrqu Pointer to iwreq_data
  1836. *
  1837. * \retval 0 For success.
  1838. * \retval -EFAULT For fail.
  1839. *
  1840. */
  1841. /*----------------------------------------------------------------------------*/
  1842. int
  1843. mtk_p2p_wext_reconnect(IN struct net_device *prDev,
  1844. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  1845. {
  1846. #if 0
  1847. P_ADAPTER_T prAdapter = NULL;
  1848. P_GLUE_INFO_T prGlueInfo = NULL;
  1849. P_MSG_HDR_T prMsgHdr;
  1850. ASSERT(prDev);
  1851. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  1852. ASSERT(prGlueInfo);
  1853. prAdapter = prGlueInfo->prAdapter;
  1854. ASSERT(prAdapter);
  1855. prMsgHdr = (P_MSG_HDR_T) cnmMemAlloc(prAdapter, RAM_TYPE_MSG, sizeof(MSG_HDR_T));
  1856. if (!prMsgHdr) {
  1857. ASSERT(0); /* Can't trigger P2P FSM */
  1858. return -ENOMEM;
  1859. }
  1860. /* 1.2 fill message */
  1861. DBGLOG(P2P, TRACE, "mtk_p2p_wext_reconnect: P2P Reconnect\n");
  1862. /* 1.3 send message */
  1863. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prMsgHdr, MSG_SEND_METHOD_BUF);
  1864. #endif
  1865. return 0;
  1866. } /* end of mtk_p2p_wext_reconnect() */
  1867. /*----------------------------------------------------------------------------*/
  1868. /*!
  1869. * \brief MLME command handler
  1870. *
  1871. * \param[in] prDev Net device requested.
  1872. * \param[inout] wrqu Pointer to iwreq_data
  1873. *
  1874. * \retval 0 Success.
  1875. * \retval -EFAULT Setting parameters to driver fail.
  1876. * \retval -EOPNOTSUPP Key size not supported.
  1877. *
  1878. * \note
  1879. */
  1880. /*----------------------------------------------------------------------------*/
  1881. int
  1882. mtk_p2p_wext_mlme_handler(IN struct net_device *prDev,
  1883. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  1884. {
  1885. #if 0
  1886. P_ADAPTER_T prAdapter = NULL;
  1887. P_GLUE_INFO_T prGlueInfo = NULL;
  1888. struct iw_mlme *mlme = (struct iw_mlme *)extra;
  1889. P_MSG_P2P_CONNECTION_ABORT_T prMsgP2PConnAbt = (P_MSG_P2P_CONNECTION_ABORT_T) NULL;
  1890. P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T) NULL;
  1891. ASSERT(prDev);
  1892. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  1893. ASSERT(prGlueInfo);
  1894. prAdapter = prGlueInfo->prAdapter;
  1895. ASSERT(prAdapter);
  1896. prP2pBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
  1897. DBGLOG(P2P, TRACE, "mtk_p2p_wext_mlme_handler:\n");
  1898. switch (mlme->cmd) {
  1899. case IW_MLME_DISASSOC:
  1900. prMsgP2PConnAbt =
  1901. (P_MSG_HDR_T) cnmMemAlloc(prAdapter, RAM_TYPE_MSG, sizeof(MSG_P2P_CONNECTION_ABORT_T));
  1902. if (!prMsgP2PConnAbt) {
  1903. ASSERT(0); /* Can't trigger P2P FSM */
  1904. return -ENOMEM;
  1905. }
  1906. COPY_MAC_ADDR(prMsgP2PConnAbt->aucTargetID, mlme->addr.sa_data);
  1907. prMsgP2PConnAbt->u2ReasonCode = mlme->reason_code;
  1908. if (EQUAL_MAC_ADDR(prMsgP2PConnAbt->aucTargetID, prP2pBssInfo->aucOwnMacAddr)) {
  1909. DBGLOG(P2P, TRACE, "P2P Connection Abort:\n");
  1910. /* 1.2 fill message */
  1911. prMsgP2PConnAbt->rMsgHdr.eMsgId = MID_MNY_P2P_CONNECTION_ABORT;
  1912. } else {
  1913. DBGLOG(P2P, TRACE, "P2P Connection Pause:\n");
  1914. /* 1.2 fill message */
  1915. }
  1916. /* 1.3 send message */
  1917. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prMsgP2PConnAbt, MSG_SEND_METHOD_BUF);
  1918. break;
  1919. default:
  1920. return -EOPNOTSUPP;
  1921. }
  1922. #endif
  1923. return 0;
  1924. } /* end of mtk_p2p_wext_mlme_handler() */
  1925. /*----------------------------------------------------------------------------*/
  1926. /*!
  1927. * \brief P2P Private I/O Control handler (IOC_P2P_PROVISION_COMPLETE)
  1928. *
  1929. * \param[in] prDev Net device requested.
  1930. * \param[inout] wrqu Pointer to iwreq_data
  1931. *
  1932. * \retval 0 Success.
  1933. * \retval -EFAULT Setting parameters to driver fail.
  1934. * \retval -EOPNOTSUPP Key size not supported.
  1935. *
  1936. * \note
  1937. */
  1938. /*----------------------------------------------------------------------------*/
  1939. int
  1940. mtk_p2p_wext_set_provision_complete(IN struct net_device *prDev,
  1941. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  1942. {
  1943. #if 0
  1944. P_ADAPTER_T prAdapter = NULL;
  1945. P_GLUE_INFO_T prGlueInfo = NULL;
  1946. struct iw_point *prData = (struct iw_point *)&wrqu->data;
  1947. P_MSG_HDR_T prMsgHdr;
  1948. ASSERT(prDev);
  1949. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  1950. ASSERT(prGlueInfo);
  1951. prAdapter = prGlueInfo->prAdapter;
  1952. ASSERT(prAdapter);
  1953. switch (prData->flags) {
  1954. case P2P_PROVISIONING_SUCCESS:
  1955. prMsgHdr = (P_MSG_HDR_T) cnmMemAlloc(prAdapter, RAM_TYPE_MSG, sizeof(MSG_HDR_T));
  1956. if (!prMsgHdr) {
  1957. ASSERT(0); /* Can't trigger P2P FSM */
  1958. return -ENOMEM;
  1959. }
  1960. /* 1.2 fill message */
  1961. prGlueInfo->prP2PInfo->u4CipherPairwise = IW_AUTH_CIPHER_CCMP;
  1962. /* 1.3 send message */
  1963. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prMsgHdr, MSG_SEND_METHOD_BUF);
  1964. break;
  1965. case P2P_PROVISIONING_FAIL:
  1966. break;
  1967. default:
  1968. return -EOPNOTSUPP;
  1969. }
  1970. #endif
  1971. return 0;
  1972. } /* end of mtk_p2p_wext_set_provision_complete() */
  1973. /*----------------------------------------------------------------------------*/
  1974. /*!
  1975. * \brief P2P Private I/O Control handler (IOC_P2P_START_STOP_DISCOVERY)
  1976. *
  1977. * \param[in] prDev Net device requested.
  1978. * \param[inout] wrqu Pointer to iwreq_data
  1979. *
  1980. * \retval 0 Success.
  1981. * \retval -EFAULT Setting parameters to driver fail.
  1982. * \retval -EOPNOTSUPP Key size not supported.
  1983. *
  1984. * \note
  1985. */
  1986. /*----------------------------------------------------------------------------*/
  1987. int
  1988. mtk_p2p_wext_start_stop_discovery(IN struct net_device *prDev,
  1989. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  1990. {
  1991. #if 0
  1992. P_ADAPTER_T prAdapter = NULL;
  1993. P_GLUE_INFO_T prGlueInfo = NULL;
  1994. struct iw_point *prData = (struct iw_point *)&wrqu->data;
  1995. P_IW_P2P_REQ_DEVICE_TYPE prReqDeviceType = (P_IW_P2P_REQ_DEVICE_TYPE) extra;
  1996. UINT_8 au4IeBuf[MAX_IE_LENGTH];
  1997. P_MSG_HDR_T prMsgHdr;
  1998. P_MSG_P2P_DEVICE_DISCOVER_T prDiscoverMsg;
  1999. P_P2P_CONNECTION_SETTINGS_T prConnSettings;
  2000. UINT_8 aucNullAddr[] = NULL_MAC_ADDR;
  2001. ASSERT(prDev);
  2002. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  2003. ASSERT(prGlueInfo);
  2004. prAdapter = prGlueInfo->prAdapter;
  2005. ASSERT(prAdapter);
  2006. prConnSettings = prAdapter->rWifiVar.prP2PConnSettings;
  2007. if (prData->flags == P2P_STOP_DISCOVERY) {
  2008. prMsgHdr = (P_MSG_HDR_T) cnmMemAlloc(prAdapter, RAM_TYPE_MSG, sizeof(MSG_HDR_T));
  2009. if (!prMsgHdr) {
  2010. ASSERT(0); /* Can't trigger P2P FSM */
  2011. return -ENOMEM;
  2012. }
  2013. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prMsgHdr, MSG_SEND_METHOD_BUF);
  2014. } else if (prData->flags == P2P_START_DISCOVERY) {
  2015. /* retrieve IE for Probe Response */
  2016. if (prReqDeviceType->probe_rsp_len > 0) {
  2017. if (prReqDeviceType->probe_rsp_len <= MAX_IE_LENGTH) {
  2018. if (copy_from_user
  2019. (prGlueInfo->prP2PInfo->aucWSCIE[2],
  2020. prReqDeviceType->probe_rsp_ie, prReqDeviceType->probe_rsp_len)) {
  2021. return -EFAULT;
  2022. }
  2023. prGlueInfo->prP2PInfo->u2WSCIELen[2] = prReqDeviceType->probe_rsp_len;
  2024. } else {
  2025. return -E2BIG;
  2026. }
  2027. }
  2028. /* retrieve IE for Probe Request */
  2029. if (prReqDeviceType->probe_req_len > 0) {
  2030. if (prReqDeviceType->probe_req_len <= MAX_IE_LENGTH) {
  2031. if (copy_from_user
  2032. (prGlueInfo->prP2PInfo->aucWSCIE[1],
  2033. prReqDeviceType->probe_req_ie, prReqDeviceType->probe_req_len)) {
  2034. return -EFAULT;
  2035. }
  2036. prGlueInfo->prP2PInfo->u2WSCIELen[1] = prReqDeviceType->probe_req_len;
  2037. } else {
  2038. return -E2BIG;
  2039. }
  2040. }
  2041. /* update IE for Probe Request */
  2042. if (prReqDeviceType->scan_type == P2P_LISTEN) {
  2043. /* update listening parameter */
  2044. /* @TODO: update prConnSettings for Probe Response IE */
  2045. } else {
  2046. /* indicate P2P-FSM with MID_MNY_P2P_DEVICE_DISCOVERY */
  2047. prDiscoverMsg = (P_MSG_P2P_DEVICE_DISCOVER_T) cnmMemAlloc(prAdapter,
  2048. RAM_TYPE_MSG,
  2049. sizeof(MSG_P2P_DEVICE_DISCOVER_T));
  2050. if (!prDiscoverMsg) {
  2051. ASSERT(0); /* Can't trigger P2P FSM */
  2052. return -ENOMEM;
  2053. }
  2054. prDiscoverMsg->rMsgHdr.eMsgId = MID_MNY_P2P_DEVICE_DISCOVERY;
  2055. prDiscoverMsg->u4DevDiscoverTime = 0; /* unlimited */
  2056. prDiscoverMsg->fgIsSpecificType = TRUE;
  2057. prDiscoverMsg->rTargetDeviceType.u2CategoryID =
  2058. *(PUINT_16) (&(prReqDeviceType->pri_device_type[0]));
  2059. prDiscoverMsg->rTargetDeviceType.u2SubCategoryID =
  2060. *(PUINT_16) (&(prReqDeviceType->pri_device_type[6]));
  2061. COPY_MAC_ADDR(prDiscoverMsg->aucTargetDeviceID, aucNullAddr);
  2062. /* @FIXME: parameter to be refined, where to pass IE buffer ? */
  2063. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prDiscoverMsg, MSG_SEND_METHOD_BUF);
  2064. }
  2065. } else {
  2066. return -EINVAL;
  2067. }
  2068. #endif
  2069. return 0;
  2070. } /* end of mtk_p2p_wext_start_stop_discovery() */
  2071. /*----------------------------------------------------------------------------*/
  2072. /*!
  2073. * \brief P2P Private I/O Control handler (IOC_P2P_SET_INT)
  2074. *
  2075. * \param[in] prDev Net device requested.
  2076. * \param[inout] wrqu Pointer to iwreq_data
  2077. *
  2078. * \retval 0 Success.
  2079. * \retval -EFAULT Setting parameters to driver fail.
  2080. * \retval -EOPNOTSUPP Setting parameters not support.
  2081. *
  2082. * \note
  2083. */
  2084. /*----------------------------------------------------------------------------*/
  2085. int
  2086. mtk_p2p_wext_invitation_request(IN struct net_device *prDev,
  2087. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  2088. {
  2089. int i4Status = 0;
  2090. #if 0
  2091. P_ADAPTER_T prAdapter = (P_ADAPTER_T) NULL;
  2092. P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T) NULL;
  2093. struct iw_point *prData = (struct iw_point *)&wrqu->data;
  2094. P_IW_P2P_IOCTL_INVITATION_STRUCT prIoctlInvitation = (P_IW_P2P_IOCTL_INVITATION_STRUCT) NULL;
  2095. do {
  2096. if ((prDev == NULL) || (extra == NULL)) {
  2097. ASSERT(FALSE);
  2098. i4Status = -EINVAL;
  2099. break;
  2100. }
  2101. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  2102. prIoctlInvitation = (P_IW_P2P_IOCTL_INVITATION_STRUCT) extra;
  2103. if (prGlueInfo == NULL) {
  2104. i4Status = -EINVAL;
  2105. break;
  2106. }
  2107. prAdapter = prGlueInfo->prAdapter;
  2108. if (prAdapter == NULL) {
  2109. i4Status = -EINVAL;
  2110. break;
  2111. }
  2112. if (prIoctlInvitation->ucReinvoke == 1) {
  2113. /* TODO: Set Group ID */
  2114. p2pFuncSetGroupID(prAdapter, prIoctlInvitation->aucGroupID,
  2115. prIoctlInvitation->aucSsid, prIoctlInvitation->u4SsidLen);
  2116. }
  2117. else {
  2118. P_MSG_P2P_INVITATION_REQUEST_T prMsgP2PInvitationReq = (P_MSG_P2P_INVITATION_REQUEST_T) NULL;
  2119. /* TODO: Do Invitation. */
  2120. prMsgP2PInvitationReq =
  2121. (P_MSG_P2P_INVITATION_REQUEST_T) cnmMemAlloc(prAdapter, RAM_TYPE_MSG,
  2122. sizeof(MSG_P2P_INVITATION_REQUEST_T));
  2123. if (!prMsgP2PInvitationReq) {
  2124. ASSERT(0); /* Can't trigger P2P FSM */
  2125. i4Status = -ENOMEM;
  2126. break;
  2127. }
  2128. /* 1.2 fill message */
  2129. kalMemCopy(prMsgP2PInvitationReq->aucDeviceID, prIoctlInvitation->aucDeviceID, MAC_ADDR_LEN);
  2130. DBGLOG(P2P, TRACE, "mtk_p2p_wext_invitation_request: P2P Invitation Req\n");
  2131. /* 1.3 send message */
  2132. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prMsgP2PInvitationReq, MSG_SEND_METHOD_BUF);
  2133. }
  2134. } while (FALSE);
  2135. #endif
  2136. return i4Status;
  2137. }
  2138. /* mtk_p2p_wext_invitation_request */
  2139. /*----------------------------------------------------------------------------*/
  2140. /*!
  2141. * \brief P2P Private I/O Control handler (IOC_P2P_SET_INT)
  2142. *
  2143. * \param[in] prDev Net device requested.
  2144. * \param[inout] wrqu Pointer to iwreq_data
  2145. *
  2146. * \retval 0 Success.
  2147. * \retval -EFAULT Setting parameters to driver fail.
  2148. * \retval -EOPNOTSUPP Setting parameters not support.
  2149. *
  2150. * \note
  2151. */
  2152. /*----------------------------------------------------------------------------*/
  2153. int
  2154. mtk_p2p_wext_invitation_abort(IN struct net_device *prDev,
  2155. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  2156. {
  2157. int i4Status = 0;
  2158. #if 0
  2159. P_ADAPTER_T prAdapter = (P_ADAPTER_T) NULL;
  2160. P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T) NULL;
  2161. struct iw_point *prData = (struct iw_point *)&wrqu->data;
  2162. P_IW_P2P_IOCTL_ABORT_INVITATION prIoctlInvitationAbort = (P_IW_P2P_IOCTL_ABORT_INVITATION) NULL;
  2163. UINT_8 bssid[MAC_ADDR_LEN];
  2164. do {
  2165. if ((prDev == NULL) || (extra == NULL)) {
  2166. ASSERT(FALSE);
  2167. i4Status = -EINVAL;
  2168. break;
  2169. }
  2170. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  2171. prIoctlInvitationAbort = (P_IW_P2P_IOCTL_ABORT_INVITATION) extra;
  2172. if (prGlueInfo == NULL) {
  2173. i4Status = -EINVAL;
  2174. break;
  2175. }
  2176. prAdapter = prGlueInfo->prAdapter;
  2177. if (prAdapter == NULL) {
  2178. i4Status = -EINVAL;
  2179. } else {
  2180. P_MSG_P2P_INVITATION_REQUEST_T prMsgP2PInvitationAbort = (P_MSG_P2P_INVITATION_REQUEST_T) NULL;
  2181. prMsgP2PInvitationAbort =
  2182. (P_MSG_P2P_INVITATION_REQUEST_T) cnmMemAlloc(prAdapter, RAM_TYPE_MSG,
  2183. sizeof(MSG_P2P_INVITATION_REQUEST_T));
  2184. if (!prMsgP2PInvitationAbort) {
  2185. ASSERT(0); /* Can't trigger P2P FSM */
  2186. i4Status = -ENOMEM;
  2187. break;
  2188. }
  2189. /* 1.2 fill message */
  2190. kalMemCopy(prMsgP2PInvitationAbort->aucDeviceID,
  2191. prIoctlInvitationAbort->dev_addr, MAC_ADDR_LEN);
  2192. DBGLOG(P2P, TRACE, "mtk_p2p_wext_invitation_request: P2P Invitation Req\n");
  2193. /* 1.3 send message */
  2194. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prMsgP2PInvitationAbort, MSG_SEND_METHOD_BUF);
  2195. }
  2196. } while (FALSE);
  2197. #endif
  2198. return i4Status;
  2199. }
  2200. /* mtk_p2p_wext_invitation_abort */
  2201. /*----------------------------------------------------------------------------*/
  2202. /*!
  2203. * \brief To set encryption cipher suite
  2204. *
  2205. * \param[in] prDev Net device requested.
  2206. * \param[out]
  2207. *
  2208. * \retval 0 Success.
  2209. * \retval -EINVAL Invalid parameter
  2210. * \retval -EOPNOTSUPP Key size not supported.
  2211. *
  2212. * \note
  2213. */
  2214. /*----------------------------------------------------------------------------*/
  2215. int
  2216. mtk_p2p_wext_set_auth(IN struct net_device *prDev,
  2217. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  2218. {
  2219. P_GLUE_INFO_T prGlueInfo = NULL;
  2220. struct iw_param *prAuth = (struct iw_param *)wrqu;
  2221. ASSERT(prDev);
  2222. ASSERT(prAuth);
  2223. if (FALSE == GLUE_CHK_PR2(prDev, prAuth))
  2224. return -EINVAL;
  2225. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  2226. /* Save information to glue info and process later when ssid is set. */
  2227. switch (prAuth->flags & IW_AUTH_INDEX) {
  2228. case IW_AUTH_WPA_VERSION:
  2229. break;
  2230. case IW_AUTH_CIPHER_PAIRWISE:
  2231. prGlueInfo->prP2PInfo->u4CipherPairwise = prAuth->value;
  2232. break;
  2233. case IW_AUTH_CIPHER_GROUP:
  2234. case IW_AUTH_KEY_MGMT:
  2235. case IW_AUTH_TKIP_COUNTERMEASURES:
  2236. case IW_AUTH_DROP_UNENCRYPTED:
  2237. case IW_AUTH_80211_AUTH_ALG:
  2238. case IW_AUTH_WPA_ENABLED:
  2239. case IW_AUTH_RX_UNENCRYPTED_EAPOL:
  2240. case IW_AUTH_ROAMING_CONTROL:
  2241. case IW_AUTH_PRIVACY_INVOKED:
  2242. default:
  2243. /* @TODO */
  2244. break;
  2245. }
  2246. return 0;
  2247. } /* end of mtk_p2p_wext_set_auth() */
  2248. /*----------------------------------------------------------------------------*/
  2249. /*!
  2250. * \brief To set encryption cipher and key.
  2251. *
  2252. * \param[in] prDev Net device requested.
  2253. * \param[out] prIfReq Pointer to ifreq structure, content is copied back to
  2254. * user space buffer in gl_iwpriv_table.
  2255. *
  2256. * \retval 0 Success.
  2257. * \retval -EFAULT Setting parameters to driver fail.
  2258. * \retval -EOPNOTSUPP Key size not supported.
  2259. *
  2260. * \note Securiry information is stored in pEnc.
  2261. */
  2262. /*----------------------------------------------------------------------------*/
  2263. int
  2264. mtk_p2p_wext_set_key(IN struct net_device *prDev,
  2265. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  2266. {
  2267. int ret = 0;
  2268. struct iw_encode_ext *prIWEncExt;
  2269. struct iw_point *prEnc;
  2270. char *prExtraBuf = NULL;
  2271. UINT_32 u4ExtraSize = 0;
  2272. UINT_8 keyStructBuf[100];
  2273. P_PARAM_REMOVE_KEY_T prRemoveKey = (P_PARAM_REMOVE_KEY_T) keyStructBuf;
  2274. P_PARAM_KEY_T prKey = (P_PARAM_KEY_T) keyStructBuf;
  2275. P_GLUE_INFO_T prGlueInfo;
  2276. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  2277. UINT_32 u4BufLen = 0;
  2278. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  2279. do {
  2280. if (wrqu->encoding.pointer) {
  2281. u4ExtraSize = wrqu->encoding.length;
  2282. prExtraBuf = kalMemAlloc(u4ExtraSize, VIR_MEM_TYPE);
  2283. if (!prExtraBuf) {
  2284. ret = -ENOMEM;
  2285. break;
  2286. }
  2287. if (copy_from_user(prExtraBuf, wrqu->encoding.pointer, wrqu->encoding.length)) {
  2288. ret = -EFAULT;
  2289. break;
  2290. }
  2291. } else if (wrqu->encoding.length != 0) {
  2292. ret = -EINVAL;
  2293. break;
  2294. }
  2295. prEnc = &wrqu->encoding;
  2296. prIWEncExt = (struct iw_encode_ext *)prExtraBuf;
  2297. if (GLUE_CHK_PR3(prDev, prEnc, prExtraBuf) == TRUE) {
  2298. memset(keyStructBuf, 0, sizeof(keyStructBuf));
  2299. if ((prEnc->flags & IW_ENCODE_MODE) == IW_ENCODE_DISABLED) { /* Key Removal */
  2300. prRemoveKey->u4Length = sizeof(*prRemoveKey);
  2301. memcpy(prRemoveKey->arBSSID, prIWEncExt->addr.sa_data, 6);
  2302. rStatus = kalIoctl(prGlueInfo,
  2303. wlanoidSetRemoveP2PKey,
  2304. prRemoveKey,
  2305. prRemoveKey->u4Length, FALSE, FALSE, TRUE, TRUE, &u4BufLen);
  2306. if (rStatus != WLAN_STATUS_SUCCESS)
  2307. ret = -EFAULT;
  2308. } else {
  2309. if (prIWEncExt->alg == IW_ENCODE_ALG_CCMP) {
  2310. /* KeyID */
  2311. prKey->u4KeyIndex = (prEnc->flags & IW_ENCODE_INDEX) ?
  2312. ((prEnc->flags & IW_ENCODE_INDEX) - 1) : 0;
  2313. if (prKey->u4KeyIndex <= 3) {
  2314. /* bit(31) and bit(30) are shared by pKey and pRemoveKey */
  2315. /* Tx Key Bit(31) */
  2316. mtk_p2p_wext_set_key_prkit();
  2317. } else {
  2318. ret = -EINVAL;
  2319. }
  2320. } else {
  2321. ret = -EINVAL;
  2322. }
  2323. }
  2324. } else
  2325. ret = -EINVAL;
  2326. } while (FALSE);
  2327. if (prExtraBuf) {
  2328. kalMemFree(prExtraBuf, VIR_MEM_TYPE, u4ExtraSize);
  2329. prExtraBuf = NULL;
  2330. }
  2331. return ret;
  2332. } /* end of mtk_p2p_wext_set_key() */
  2333. /* For resolve error and warning of AOSP coding style check */
  2334. /* To be fixed */
  2335. void mtk_p2p_wext_set_key_prkit(void)
  2336. {
  2337. if (prIWEncExt->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
  2338. prKey->u4KeyIndex |= 0x1UL << 31;
  2339. /* Pairwise Key Bit(30) */
  2340. if (prIWEncExt->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
  2341. /* group key */
  2342. } else {
  2343. /* pairwise key */
  2344. prKey->u4KeyIndex |= 0x1UL << 30;
  2345. }
  2346. /* Rx SC Bit(29) */
  2347. if (prIWEncExt->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
  2348. prKey->u4KeyIndex |= 0x1UL << 29;
  2349. memcpy(&prKey->rKeyRSC, prIWEncExt->rx_seq, IW_ENCODE_SEQ_MAX_SIZE);
  2350. }
  2351. /* BSSID */
  2352. memcpy(prKey->arBSSID, prIWEncExt->addr.sa_data, 6);
  2353. memcpy(prKey->aucKeyMaterial, prIWEncExt->key, prIWEncExt->key_len);
  2354. prKey->u4KeyLength = prIWEncExt->key_len;
  2355. prKey->u4Length = ((UINT_32) &(((P_PARAM_KEY_T) 0)->aucKeyMaterial)) + prKey->u4KeyLength;
  2356. rStatus = kalIoctl(prGlueInfo,
  2357. wlanoidSetAddP2PKey, prKey, prKey->u4Length, FALSE, FALSE, TRUE, TRUE, &u4BufLen);
  2358. if (rStatus != WLAN_STATUS_SUCCESS)
  2359. ret = -EFAULT;
  2360. }
  2361. /*----------------------------------------------------------------------------*/
  2362. /*!
  2363. * \brief set the p2p gc power mode
  2364. *
  2365. * \param[in] prDev Net device requested.
  2366. * \param[inout] wrqu Pointer to iwreq_data
  2367. *
  2368. * \retval 0 Success.
  2369. * \retval -EFAULT Setting parameters to driver fail.
  2370. * \retval -EOPNOTSUPP Key size not supported.
  2371. *
  2372. * \note
  2373. */
  2374. /*----------------------------------------------------------------------------*/
  2375. int
  2376. mtk_p2p_wext_set_powermode(IN struct net_device *prNetDev,
  2377. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  2378. {
  2379. struct iw_param *prPower = (struct iw_param *)&wrqu->power;
  2380. #if 1
  2381. PARAM_POWER_MODE ePowerMode;
  2382. INT_32 i4PowerValue;
  2383. P_GLUE_INFO_T prGlueInfo = NULL;
  2384. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  2385. UINT_32 u4BufLen = 0;
  2386. ASSERT(prNetDev);
  2387. ASSERT(prPower);
  2388. if (FALSE == GLUE_CHK_PR2(prNetDev, prPower))
  2389. return -EINVAL;
  2390. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prNetDev));
  2391. /* prPower->value, prPower->disabled, prPower->flags); */
  2392. if (prPower->disabled) {
  2393. ePowerMode = Param_PowerModeCAM;
  2394. } else {
  2395. i4PowerValue = prPower->value;
  2396. #if WIRELESS_EXT < 21
  2397. i4PowerValue /= 1000000;
  2398. #endif
  2399. if (i4PowerValue == 0) {
  2400. ePowerMode = Param_PowerModeCAM;
  2401. } else if (i4PowerValue == 1) {
  2402. ePowerMode = Param_PowerModeMAX_PSP;
  2403. } else if (i4PowerValue == 2) {
  2404. ePowerMode = Param_PowerModeFast_PSP;
  2405. } else {
  2406. DBGLOG(INIT, WARN, "%s(): unsupported power management mode value = %d.\n",
  2407. __func__, prPower->value;
  2408. return -EINVAL;
  2409. }
  2410. }
  2411. rStatus = kalIoctl(prGlueInfo,
  2412. wlanoidSetP2pPowerSaveProfile,
  2413. &ePowerMode, sizeof(ePowerMode), FALSE, FALSE, TRUE, TRUE, &u4BufLen);
  2414. if (rStatus != WLAN_STATUS_SUCCESS) {
  2415. /* DBGLOG(INIT, INFO, ("wlanoidSet802dot11PowerSaveProfile fail 0x%lx\n", rStatus)); */
  2416. return -EFAULT;
  2417. }
  2418. #endif
  2419. return 0;
  2420. }
  2421. /*----------------------------------------------------------------------------*/
  2422. /*!
  2423. * \brief get the p2p gc power mode
  2424. *
  2425. * \param[in] prDev Net device requested.
  2426. * \param[inout] wrqu Pointer to iwreq_data
  2427. *
  2428. * \retval 0 Success.
  2429. * \retval -EFAULT Setting parameters to driver fail.
  2430. * \retval -EOPNOTSUPP Key size not supported.
  2431. *
  2432. * \note
  2433. */
  2434. /*----------------------------------------------------------------------------*/
  2435. int
  2436. mtk_p2p_wext_get_powermode(IN struct net_device *prNetDev,
  2437. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  2438. {
  2439. /* wrqu->power.disabled = 0; */
  2440. /* wrqu->power.value = 1; */
  2441. struct iw_param *prPower = (struct iw_param *)&wrqu->power;
  2442. PARAM_POWER_MODE ePowerMode;
  2443. P_GLUE_INFO_T prGlueInfo = NULL;
  2444. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  2445. UINT_32 u4BufLen = 0;
  2446. ASSERT(prNetDev);
  2447. ASSERT(prPower);
  2448. if (FALSE == GLUE_CHK_PR2(prNetDev, prPower))
  2449. return -EINVAL;
  2450. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prNetDev));
  2451. ASSERT(prGlueInfo);
  2452. #if 1
  2453. rStatus = kalIoctl(prGlueInfo,
  2454. wlanoidQueryP2pPowerSaveProfile,
  2455. &ePowerMode, sizeof(ePowerMode), TRUE, FALSE, FALSE, TRUE, &u4BufLen);
  2456. #else
  2457. rStatus = wlanQueryInformation(prGlueInfo->prAdapter,
  2458. wlanoidQueryP2pPowerSaveProfile, &ePowerMode, sizeof(ePowerMode), &u4BufLen);
  2459. #endif
  2460. prPower->value = 0;
  2461. prPower->disabled = 1;
  2462. if (Param_PowerModeCAM == ePowerMode) {
  2463. prPower->value = 0;
  2464. prPower->disabled = 1;
  2465. } else if (Param_PowerModeMAX_PSP == ePowerMode) {
  2466. prPower->value = 1;
  2467. prPower->disabled = 0;
  2468. } else if (Param_PowerModeFast_PSP == ePowerMode) {
  2469. prPower->value = 2;
  2470. prPower->disabled = 0;
  2471. }
  2472. prPower->flags = IW_POWER_PERIOD | IW_POWER_RELATIVE;
  2473. #if WIRELESS_EXT < 21
  2474. prPower->value *= 1000000;
  2475. #endif
  2476. return 0;
  2477. }
  2478. /*----------------------------------------------------------------------------*/
  2479. /*!
  2480. * \brief P2P Private I/O Control handler (IOC_P2P_CFG_DEVICE)
  2481. *
  2482. * \param[in] prDev Net device requested.
  2483. * \param[inout] wrqu Pointer to iwreq_data
  2484. *
  2485. * \retval 0 Success.
  2486. * \retval -EFAULT Setting parameters to driver fail.
  2487. * \retval -EOPNOTSUPP Key size not supported.
  2488. *
  2489. * \note
  2490. */
  2491. /*----------------------------------------------------------------------------*/
  2492. int
  2493. mtk_p2p_wext_set_local_dev_info(IN struct net_device *prDev,
  2494. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  2495. {
  2496. P_ADAPTER_T prAdapter = NULL;
  2497. P_GLUE_INFO_T prGlueInfo = NULL;
  2498. P_IW_P2P_CFG_DEVICE_TYPE prDeviceCfg = (P_IW_P2P_CFG_DEVICE_TYPE) extra;
  2499. P_P2P_CONNECTION_SETTINGS_T prConnSettings;
  2500. P_P2P_SPECIFIC_BSS_INFO_T prP2pSpecificBssInfo = (P_P2P_SPECIFIC_BSS_INFO_T) NULL;
  2501. /* P_MSG_P2P_FUNCTION_SWITCH_T prFuncSwitch = (P_MSG_P2P_FUNCTION_SWITCH_T)NULL; */
  2502. ASSERT(prDev);
  2503. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  2504. ASSERT(prGlueInfo);
  2505. prAdapter = prGlueInfo->prAdapter;
  2506. ASSERT(prAdapter);
  2507. prConnSettings = prAdapter->rWifiVar.prP2PConnSettings;
  2508. prP2pSpecificBssInfo = prAdapter->rWifiVar.prP2pSpecificBssInfo;
  2509. /* update connection settings for P2P-FSM */
  2510. /* 1. update SSID */
  2511. if (prDeviceCfg->ssid_len > ELEM_MAX_LEN_SSID)
  2512. prConnSettings->ucSSIDLen = ELEM_MAX_LEN_SSID;
  2513. else
  2514. prConnSettings->ucSSIDLen = prDeviceCfg->ssid_len;
  2515. if (copy_from_user(prConnSettings->aucSSID, prDeviceCfg->ssid, prConnSettings->ucSSIDLen))
  2516. return -EFAULT;
  2517. /* 2. update device type (WPS IE) */
  2518. kalMemCopy(&(prConnSettings->rPrimaryDevTypeBE), &(prDeviceCfg->pri_device_type), sizeof(DEVICE_TYPE_T));
  2519. #if P2P_MAX_SUPPORTED_SEC_DEV_TYPE_COUNT
  2520. kalMemCopy(&(prConnSettings->arSecondaryDevTypeBE[0]), &(prDeviceCfg->snd_device_type), sizeof(DEVICE_TYPE_T));
  2521. #endif
  2522. /* 3. update device name */
  2523. if (prDeviceCfg->device_name_len > WPS_ATTRI_MAX_LEN_DEVICE_NAME)
  2524. prConnSettings->ucDevNameLen = WPS_ATTRI_MAX_LEN_DEVICE_NAME;
  2525. else
  2526. prConnSettings->ucDevNameLen = prDeviceCfg->device_name_len;
  2527. if (copy_from_user(prConnSettings->aucDevName, prDeviceCfg->device_name, prConnSettings->ucDevNameLen))
  2528. return -EFAULT;
  2529. /* 4. update GO intent */
  2530. prConnSettings->ucGoIntent = prDeviceCfg->intend;
  2531. /* Preferred channel bandwidth */
  2532. prAdapter->rWifiVar.rConnSettings.uc2G4BandwidthMode = prDeviceCfg->ch_width ? CONFIG_BW_20_40M : CONFIG_BW_20M;
  2533. prAdapter->rWifiVar.rConnSettings.uc5GBandwidthMode = prDeviceCfg->ch_width ? CONFIG_BW_20_40M : CONFIG_BW_20M;
  2534. #if 0
  2535. /* 1. switch P2P-FSM on */
  2536. /* 1.1 allocate for message */
  2537. prFuncSwitch = (P_MSG_P2P_FUNCTION_SWITCH_T) cnmMemAlloc(prAdapter,
  2538. RAM_TYPE_MSG, sizeof(MSG_P2P_FUNCTION_SWITCH_T));
  2539. if (!prFuncSwitch) {
  2540. ASSERT(0); /* Can't trigger P2P FSM */
  2541. return -ENOMEM;
  2542. }
  2543. /* 1.2 fill message */
  2544. prFuncSwitch->rMsgHdr.eMsgId = MID_MNY_P2P_FUN_SWITCH;
  2545. prFuncSwitch->fgIsFuncOn = TRUE;
  2546. /* 1.3 send message */
  2547. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prFuncSwitch, MSG_SEND_METHOD_BUF);
  2548. #endif
  2549. return 0;
  2550. } /* end of mtk_p2p_wext_set_local_dev_info() */
  2551. /*----------------------------------------------------------------------------*/
  2552. /*!
  2553. * \brief I/O Control handler for both
  2554. * IOC_P2P_START_STOP_DISCOVERY & SIOCGIWSCAN
  2555. *
  2556. * \param[in] prDev Net device requested.
  2557. * \param[inout] wrqu Pointer to iwreq_data
  2558. *
  2559. * \retval 0 Success.
  2560. * \retval -EFAULT Setting parameters to driver fail.
  2561. * \retval -EOPNOTSUPP Key size not supported.
  2562. *
  2563. * \note
  2564. */
  2565. /*----------------------------------------------------------------------------*/
  2566. int
  2567. mtk_p2p_wext_discovery_results(IN struct net_device *prDev,
  2568. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  2569. {
  2570. struct iw_event iwe;
  2571. char *current_ev = extra;
  2572. UINT_32 i;
  2573. P_GLUE_INFO_T prGlueInfo = NULL;
  2574. P_ADAPTER_T prAdapter = NULL;
  2575. P_P2P_INFO_T prP2PInfo = (P_P2P_INFO_T) NULL;
  2576. P_EVENT_P2P_DEV_DISCOVER_RESULT_T prTargetResult = (P_EVENT_P2P_DEV_DISCOVER_RESULT_T) NULL;
  2577. P_PARAM_VARIABLE_IE_T prDesiredIE = NULL;
  2578. ASSERT(prDev);
  2579. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  2580. ASSERT(prGlueInfo);
  2581. prAdapter = prGlueInfo->prAdapter;
  2582. ASSERT(prAdapter);
  2583. prP2PInfo = prAdapter->prP2pInfo;
  2584. for (i = 0; i < prP2PInfo->u4DeviceNum; i++) {
  2585. prTargetResult = &prP2PInfo->arP2pDiscoverResult[i];
  2586. /* SIOCGIWAP */
  2587. iwe.cmd = SIOCGIWAP;
  2588. iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
  2589. memcpy(iwe.u.ap_addr.sa_data, prTargetResult->aucInterfaceAddr, 6);
  2590. current_ev = iwe_stream_add_event(info, current_ev, extra + IW_SCAN_MAX_DATA, &iwe, IW_EV_ADDR_LEN);
  2591. /* SIOCGIWESSID */
  2592. iwe.cmd = SIOCGIWESSID;
  2593. iwe.u.data.flags = 1;
  2594. iwe.u.data.length = prTargetResult->u2NameLength;
  2595. current_ev = iwe_stream_add_point(info, current_ev,
  2596. extra + IW_SCAN_MAX_DATA, &iwe, prTargetResult->aucName);
  2597. /* IWEVGENIE for WPA IE */
  2598. if (prTargetResult->u2IELength <= 600
  2599. && wextSrchDesiredWPAIE(prTargetResult->pucIeBuf, prTargetResult->u2IELength,
  2600. 0xDD, (PUINT_8 *) &prDesiredIE)) {
  2601. iwe.cmd = IWEVGENIE;
  2602. iwe.u.data.flags = 1;
  2603. iwe.u.data.length = 2 + (__u16) prDesiredIE->ucLength;
  2604. current_ev = iwe_stream_add_point(info, current_ev,
  2605. extra + IW_SCAN_MAX_DATA, &iwe, (char *)prDesiredIE);
  2606. }
  2607. #if CFG_SUPPORT_WPS
  2608. /* IWEVGENIE for WPS IE */
  2609. if ((prTargetResult->u2IELength <= 600)
  2610. && wextSrchDesiredWPSIE(prTargetResult->pucIeBuf, prTargetResult->u2IELength,
  2611. 0xDD, (PUINT_8 *) &prDesiredIE)) {
  2612. iwe.cmd = IWEVGENIE;
  2613. iwe.u.data.flags = 1;
  2614. iwe.u.data.length = 2 + (__u16) prDesiredIE->ucLength;
  2615. current_ev = iwe_stream_add_point(info, current_ev,
  2616. extra + IW_SCAN_MAX_DATA, &iwe, (char *)prDesiredIE);
  2617. }
  2618. #endif
  2619. /* IWEVGENIE for RSN IE */
  2620. if ((prTargetResult->u2IELength <= 600)
  2621. && wextSrchDesiredWPAIE(prTargetResult->pucIeBuf, prTargetResult->u2IELength,
  2622. 0x30, (PUINT_8 *) &prDesiredIE)) {
  2623. iwe.cmd = IWEVGENIE;
  2624. iwe.u.data.flags = 1;
  2625. iwe.u.data.length = 2 + (__u16) prDesiredIE->ucLength;
  2626. current_ev = iwe_stream_add_point(info, current_ev,
  2627. extra + IW_SCAN_MAX_DATA, &iwe, (char *)prDesiredIE);
  2628. }
  2629. /* IOC_P2P_GO_WSC_IE */
  2630. #if 1
  2631. /* device capability */
  2632. if (1) {
  2633. UINT_8 data[40];
  2634. iwe.cmd = IWEVCUSTOM;
  2635. iwe.u.data.flags = 0;
  2636. iwe.u.data.length = 8 + sizeof("p2p_cap=");
  2637. snprintf(data, iwe.u.data.length, "p2p_cap=%02x%02x%02x%02x%c",
  2638. prTargetResult->ucDeviceCapabilityBitmap,
  2639. prTargetResult->ucGroupCapabilityBitmap,
  2640. (UINT_8) prTargetResult->u2ConfigMethod,
  2641. (UINT_8) (prTargetResult->u2ConfigMethod >> 8), '\0');
  2642. current_ev =
  2643. iwe_stream_add_point(info, current_ev, extra + IW_SCAN_MAX_DATA, &iwe, (char *)data);
  2644. kalMemZero(data, 40);
  2645. iwe.cmd = IWEVCUSTOM;
  2646. iwe.u.data.flags = 0;
  2647. iwe.u.data.length = 12 + sizeof("p2p_dev_type=");
  2648. snprintf(data, iwe.u.data.length, "p2p_dev_type=%02x%02x%02x%02x%02x%02x%c",
  2649. (UINT_8) prTargetResult->rPriDevType.u2CategoryID,
  2650. (UINT_8) prTargetResult->rPriDevType.u2SubCategoryID,
  2651. (UINT_8) prTargetResult->arSecDevType[0].u2CategoryID,
  2652. (UINT_8) prTargetResult->arSecDevType[0].u2SubCategoryID,
  2653. (UINT_8) prTargetResult->arSecDevType[1].u2CategoryID,
  2654. (UINT_8) prTargetResult->arSecDevType[1].u2SubCategoryID, '\0');
  2655. current_ev =
  2656. iwe_stream_add_point(info, current_ev, extra + IW_SCAN_MAX_DATA, &iwe, (char *)data);
  2657. kalMemZero(data, 40);
  2658. iwe.cmd = IWEVCUSTOM;
  2659. iwe.u.data.flags = 0;
  2660. iwe.u.data.length = 17 + sizeof("p2p_grp_bssid=");
  2661. snprintf(data, iwe.u.data.length, "p2p_grp_bssid=" MACSTR "%c",
  2662. MAC2STR(prTargetResult->aucBSSID), '\0');
  2663. current_ev = iwe_stream_add_point(info, current_ev,
  2664. extra + IW_SCAN_MAX_DATA, &iwe, (char *)data);
  2665. }
  2666. #endif
  2667. }
  2668. /* Length of data */
  2669. wrqu->data.length = (current_ev - extra);
  2670. wrqu->data.flags = 0;
  2671. return 0;
  2672. } /* end of mtk_p2p_wext_discovery_results() */
  2673. /*----------------------------------------------------------------------------*/
  2674. /*!
  2675. * \brief P2P Private I/O Control handler (IOC_P2P_WSC_BEACON_PROBE_RSP_IE)
  2676. *
  2677. * \param[in] prDev Net device requested.
  2678. * \param[inout] wrqu Pointer to iwreq_data
  2679. *
  2680. * \retval 0 Success.
  2681. * \retval -EFAULT Setting parameters to driver fail.
  2682. * \retval -EOPNOTSUPP Key size not supported.
  2683. *
  2684. * \note
  2685. */
  2686. /*----------------------------------------------------------------------------*/
  2687. int
  2688. mtk_p2p_wext_wsc_ie(IN struct net_device *prDev,
  2689. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  2690. {
  2691. #if 0 /* Marked for MT6630 (New ucBssIndex) */
  2692. P_ADAPTER_T prAdapter = NULL;
  2693. P_GLUE_INFO_T prGlueInfo = NULL;
  2694. P_IW_P2P_HOSTAPD_PARAM prHostapdParam = (P_IW_P2P_HOSTAPD_PARAM) extra;
  2695. ASSERT(prDev);
  2696. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  2697. ASSERT(prGlueInfo);
  2698. if (prHostapdParam->len > 0) {
  2699. if (prHostapdParam->len <= MAX_WSC_IE_LENGTH) {
  2700. if (copy_from_user
  2701. (prGlueInfo->prP2PInfo->aucWSCIE[0], prHostapdParam->data, prHostapdParam->len)) {
  2702. return -EFAULT;
  2703. }
  2704. if (copy_from_user
  2705. (prGlueInfo->prP2PInfo->aucWSCIE[2], prHostapdParam->data, prHostapdParam->len)) {
  2706. return -EFAULT;
  2707. }
  2708. } else {
  2709. return -E2BIG;
  2710. }
  2711. }
  2712. prGlueInfo->prP2PInfo->u2WSCIELen[0] = prHostapdParam->len;
  2713. prGlueInfo->prP2PInfo->u2WSCIELen[2] = prHostapdParam->len;
  2714. prAdapter = prGlueInfo->prAdapter;
  2715. ASSERT(prAdapter);
  2716. bssUpdateBeaconContent(prAdapter, NETWORK_TYPE_P2P_INDEX);
  2717. /* @TODO: send message to P2P-FSM */
  2718. #endif
  2719. return 0;
  2720. } /* end of mtk_p2p_wext_wsc_ie() */
  2721. /*----------------------------------------------------------------------------*/
  2722. /*!
  2723. * \brief P2P Private I/O Control handler (IOC_P2P_CONNECT_DISCONNECT)
  2724. *
  2725. * \param[in] prDev Net device requested.
  2726. * \param[inout] wrqu Pointer to iwreq_data
  2727. *
  2728. * \retval 0 Success.
  2729. * \retval -EFAULT Setting parameters to driver fail.
  2730. * \retval -EOPNOTSUPP Key size not supported.
  2731. *
  2732. * \note
  2733. */
  2734. /*----------------------------------------------------------------------------*/
  2735. int
  2736. mtk_p2p_wext_connect_disconnect(IN struct net_device *prDev,
  2737. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  2738. {
  2739. P_ADAPTER_T prAdapter = NULL;
  2740. P_GLUE_INFO_T prGlueInfo = NULL;
  2741. struct iw_point *prData = (struct iw_point *)&wrqu->data;
  2742. /* P_IW_P2P_CONNECT_DEVICE prConnectDevice = (P_IW_P2P_CONNECT_DEVICE)extra; */
  2743. /* P_MSG_HDR_T prMsgHdr; */
  2744. /* P_MSG_P2P_CONNECTION_REQUEST_T prMsgP2PConnReq; */
  2745. /* P_MSG_P2P_CONNECTION_ABORT_T prMsgP2PConnAbt; */
  2746. /* UINT_8 aucBCAddr[] = BC_MAC_ADDR; */
  2747. ASSERT(prDev);
  2748. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  2749. ASSERT(prGlueInfo);
  2750. prAdapter = prGlueInfo->prAdapter;
  2751. ASSERT(prAdapter);
  2752. if (prData->flags == P2P_CONNECT) {
  2753. #if 0
  2754. /* indicate P2P-FSM with MID_MNY_P2P_CONNECTION_REQ */
  2755. prMsgP2PConnReq = (P_MSG_P2P_CONNECTION_REQUEST_T) cnmMemAlloc(prAdapter,
  2756. RAM_TYPE_MSG,
  2757. sizeof(MSG_P2P_CONNECTION_REQUEST_T));
  2758. if (!prMsgP2PConnReq) {
  2759. ASSERT(0); /* Can't trigger P2P FSM */
  2760. return -ENOMEM;
  2761. }
  2762. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prMsgP2PConnReq, MSG_SEND_METHOD_BUF);
  2763. #endif
  2764. } else if (prData->flags == P2P_DISCONNECT) {
  2765. #if 0
  2766. /* indicate P2P-FSM with MID_MNY_P2P_CONNECTION_ABORT */
  2767. prMsgP2PConnAbt = (P_MSG_HDR_T) cnmMemAlloc(prAdapter,
  2768. RAM_TYPE_MSG, sizeof(MSG_P2P_CONNECTION_ABORT_T));
  2769. if (!prMsgP2PConnAbt) {
  2770. ASSERT(0); /* Can't trigger P2P FSM */
  2771. return -ENOMEM;
  2772. }
  2773. COPY_MAC_ADDR(prMsgP2PConnAbt->aucTargetID, prConnectDevice->sta_addr);
  2774. prMsgP2PConnAbt->rMsgHdr.eMsgId = MID_MNY_P2P_CONNECTION_ABORT;
  2775. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prMsgP2PConnAbt, MSG_SEND_METHOD_BUF);
  2776. #endif
  2777. } else {
  2778. return -EINVAL;
  2779. }
  2780. return 0;
  2781. } /* end of mtk_p2p_wext_connect_disconnect() */
  2782. /*----------------------------------------------------------------------------*/
  2783. /*!
  2784. * \brief P2P Private I/O Control handler (IOC_P2P_PASSWORD_READY)
  2785. *
  2786. * \param[in] prDev Net device requested.
  2787. * \param[inout] wrqu Pointer to iwreq_data
  2788. *
  2789. * \retval 0 Success.
  2790. * \retval -EFAULT Setting parameters to driver fail.
  2791. * \retval -EOPNOTSUPP Key size not supported.
  2792. *
  2793. * \note
  2794. */
  2795. /*----------------------------------------------------------------------------*/
  2796. int
  2797. mtk_p2p_wext_password_ready(IN struct net_device *prDev,
  2798. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  2799. {
  2800. P_ADAPTER_T prAdapter = NULL;
  2801. P_GLUE_INFO_T prGlueInfo = NULL;
  2802. P_IW_P2P_PASSWORD_READY prPasswordReady = (P_IW_P2P_PASSWORD_READY) extra;
  2803. P_P2P_CONNECTION_SETTINGS_T prConnSettings;
  2804. ASSERT(prDev);
  2805. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  2806. ASSERT(prGlueInfo);
  2807. prAdapter = prGlueInfo->prAdapter;
  2808. ASSERT(prAdapter);
  2809. prConnSettings = prAdapter->rWifiVar.prP2PConnSettings;
  2810. /* retrieve IE for Probe Request */
  2811. if (prPasswordReady->probe_req_len > 0) {
  2812. if (prPasswordReady->probe_req_len <= MAX_WSC_IE_LENGTH) {
  2813. if (copy_from_user
  2814. (prGlueInfo->prP2PInfo->aucWSCIE[1], prPasswordReady->probe_req_ie,
  2815. prPasswordReady->probe_req_len)) {
  2816. return -EFAULT;
  2817. }
  2818. } else {
  2819. return -E2BIG;
  2820. }
  2821. }
  2822. prGlueInfo->prP2PInfo->u2WSCIELen[1] = prPasswordReady->probe_req_len;
  2823. /* retrieve IE for Probe Response */
  2824. if (prPasswordReady->probe_rsp_len > 0) {
  2825. if (prPasswordReady->probe_rsp_len <= MAX_WSC_IE_LENGTH) {
  2826. if (copy_from_user
  2827. (prGlueInfo->prP2PInfo->aucWSCIE[2], prPasswordReady->probe_rsp_ie,
  2828. prPasswordReady->probe_rsp_len)) {
  2829. return -EFAULT;
  2830. }
  2831. } else {
  2832. return -E2BIG;
  2833. }
  2834. }
  2835. prGlueInfo->prP2PInfo->u2WSCIELen[2] = prPasswordReady->probe_rsp_len;
  2836. switch (prPasswordReady->active_config_method) {
  2837. case 1:
  2838. prConnSettings->u2LocalConfigMethod = WPS_ATTRI_CFG_METHOD_PUSH_BUTTON;
  2839. break;
  2840. case 2:
  2841. prConnSettings->u2LocalConfigMethod = WPS_ATTRI_CFG_METHOD_KEYPAD;
  2842. break;
  2843. case 3:
  2844. prConnSettings->u2LocalConfigMethod = WPS_ATTRI_CFG_METHOD_DISPLAY;
  2845. break;
  2846. default:
  2847. break;
  2848. }
  2849. prConnSettings->fgIsPasswordIDRdy = TRUE;
  2850. return 0;
  2851. } /* end of mtk_p2p_wext_password_ready() */
  2852. /*----------------------------------------------------------------------------*/
  2853. /*!
  2854. * \brief P2P Private I/O Control handler (IOC_P2P_GET_REQ_DEVICE_INFO)
  2855. *
  2856. * \param[in] prDev Net device requested.
  2857. * \param[inout] wrqu Pointer to iwreq_data
  2858. *
  2859. * \retval 0 Success.
  2860. * \retval -EFAULT Setting parameters to driver fail.
  2861. * \retval -EOPNOTSUPP Key size not supported.
  2862. *
  2863. * \note
  2864. */
  2865. /*----------------------------------------------------------------------------*/
  2866. int
  2867. mtk_p2p_wext_request_dev_info(IN struct net_device *prDev,
  2868. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  2869. {
  2870. P_ADAPTER_T prAdapter = NULL;
  2871. P_GLUE_INFO_T prGlueInfo = NULL;
  2872. P_IW_P2P_DEVICE_REQ prDeviceReq = (P_IW_P2P_DEVICE_REQ) extra;
  2873. ASSERT(prDev);
  2874. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  2875. ASSERT(prGlueInfo);
  2876. prAdapter = prGlueInfo->prAdapter;
  2877. ASSERT(prAdapter);
  2878. /* specify data length */
  2879. wrqu->data.length = sizeof(IW_P2P_DEVICE_REQ);
  2880. /* copy to upper-layer supplied buffer */
  2881. kalMemCopy(prDeviceReq->name, prGlueInfo->prP2PInfo->aucConnReqDevName,
  2882. prGlueInfo->prP2PInfo->u4ConnReqNameLength);
  2883. prDeviceReq->name_len = prGlueInfo->prP2PInfo->u4ConnReqNameLength;
  2884. prDeviceReq->name[prDeviceReq->name_len] = '\0';
  2885. COPY_MAC_ADDR(prDeviceReq->device_addr, prGlueInfo->prP2PInfo->rConnReqPeerAddr);
  2886. prDeviceReq->device_type = prGlueInfo->prP2PInfo->ucConnReqDevType;
  2887. prDeviceReq->config_method = prGlueInfo->prP2PInfo->i4ConnReqConfigMethod;
  2888. prDeviceReq->active_config_method = prGlueInfo->prP2PInfo->i4ConnReqActiveConfigMethod;
  2889. return 0;
  2890. } /* end of mtk_p2p_wext_request_dev_info() */
  2891. /*----------------------------------------------------------------------------*/
  2892. /*!
  2893. * \brief P2P Private I/O Control handler (IOC_P2P_GET_STRUCT)
  2894. *
  2895. * \param[in] prDev Net device requested.
  2896. * \param[inout] wrqu Pointer to iwreq_data
  2897. *
  2898. * \retval 0 Success.
  2899. * \retval -EFAULT Setting parameters to driver fail.
  2900. * \retval -EOPNOTSUPP Key size not supported.
  2901. *
  2902. * \note
  2903. */
  2904. /*----------------------------------------------------------------------------*/
  2905. int
  2906. mtk_p2p_wext_invitation_indicate(IN struct net_device *prDev,
  2907. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  2908. {
  2909. P_ADAPTER_T prAdapter = NULL;
  2910. P_GLUE_INFO_T prGlueInfo = NULL;
  2911. P_IW_P2P_IOCTL_INVITATION_INDICATE prInvIndicate = (P_IW_P2P_IOCTL_INVITATION_INDICATE) extra;
  2912. ASSERT(prDev);
  2913. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  2914. ASSERT(prGlueInfo);
  2915. prAdapter = prGlueInfo->prAdapter;
  2916. ASSERT(prAdapter);
  2917. /* specify data length */
  2918. wrqu->data.length = sizeof(IW_P2P_IOCTL_INVITATION_INDICATE);
  2919. /* copy to upper-layer supplied buffer */
  2920. kalMemCopy(prInvIndicate->dev_name, prGlueInfo->prP2PInfo->aucConnReqDevName,
  2921. prGlueInfo->prP2PInfo->u4ConnReqNameLength);
  2922. kalMemCopy(prInvIndicate->group_bssid, prGlueInfo->prP2PInfo->rConnReqGroupAddr, MAC_ADDR_LEN);
  2923. prInvIndicate->name_len = prGlueInfo->prP2PInfo->u4ConnReqNameLength;
  2924. prInvIndicate->dev_name[prInvIndicate->name_len] = '\0';
  2925. COPY_MAC_ADDR(prInvIndicate->dev_addr, prGlueInfo->prP2PInfo->rConnReqPeerAddr);
  2926. prInvIndicate->config_method = prGlueInfo->prP2PInfo->i4ConnReqConfigMethod;
  2927. prInvIndicate->operating_channel = prGlueInfo->prP2PInfo->ucOperatingChnl;
  2928. prInvIndicate->invitation_type = prGlueInfo->prP2PInfo->ucInvitationType;
  2929. return 0;
  2930. } /* end of mtk_p2p_wext_invitation_indicate() */
  2931. /*----------------------------------------------------------------------------*/
  2932. /*!
  2933. * \brief P2P Private I/O Control handler (IOC_P2P_GET_STRUCT)
  2934. *
  2935. * \param[in] prDev Net device requested.
  2936. * \param[inout] wrqu Pointer to iwreq_data
  2937. *
  2938. * \retval 0 Success.
  2939. * \retval -EFAULT Setting parameters to driver fail.
  2940. * \retval -EOPNOTSUPP Key size not supported.
  2941. *
  2942. * \note
  2943. */
  2944. /*----------------------------------------------------------------------------*/
  2945. int
  2946. mtk_p2p_wext_invitation_status(IN struct net_device *prDev,
  2947. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  2948. {
  2949. P_ADAPTER_T prAdapter = NULL;
  2950. P_GLUE_INFO_T prGlueInfo = NULL;
  2951. P_IW_P2P_IOCTL_INVITATION_STATUS prInvStatus = (P_IW_P2P_IOCTL_INVITATION_STATUS) extra;
  2952. ASSERT(prDev);
  2953. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  2954. ASSERT(prGlueInfo);
  2955. prAdapter = prGlueInfo->prAdapter;
  2956. ASSERT(prAdapter);
  2957. /* specify data length */
  2958. wrqu->data.length = sizeof(IW_P2P_IOCTL_INVITATION_STATUS);
  2959. /* copy to upper-layer supplied buffer */
  2960. prInvStatus->status_code = prGlueInfo->prP2PInfo->u4InvStatus;
  2961. return 0;
  2962. } /* end of mtk_p2p_wext_invitation_status() */
  2963. /*----------------------------------------------------------------------------*/
  2964. /*!
  2965. * \brief indicate an event to supplicant for device found
  2966. *
  2967. * \param[in] prGlueInfo Pointer of GLUE_INFO_T
  2968. *
  2969. * \retval TRUE Success.
  2970. * \retval FALSE Failure
  2971. */
  2972. /*----------------------------------------------------------------------------*/
  2973. BOOLEAN kalP2PIndicateFound(IN P_GLUE_INFO_T prGlueInfo)
  2974. {
  2975. union iwreq_data evt;
  2976. UINT_8 aucBuffer[IW_CUSTOM_MAX];
  2977. ASSERT(prGlueInfo);
  2978. memset(&evt, 0, sizeof(evt));
  2979. snprintf(aucBuffer, IW_CUSTOM_MAX - 1, "P2P_DVC_FND");
  2980. evt.data.length = strlen(aucBuffer);
  2981. /* indicate IWEVP2PDVCFND event */
  2982. wireless_send_event(prGlueInfo->prP2PInfo->prDevHandler, IWEVCUSTOM, &evt, aucBuffer);
  2983. return FALSE;
  2984. } /* end of kalP2PIndicateFound() */
  2985. int
  2986. mtk_p2p_wext_set_network_address(IN struct net_device *prDev,
  2987. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  2988. {
  2989. P_ADAPTER_T prAdapter = NULL;
  2990. P_GLUE_INFO_T prGlueInfo = NULL;
  2991. ASSERT(prDev);
  2992. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  2993. ASSERT(prGlueInfo);
  2994. prAdapter = prGlueInfo->prAdapter;
  2995. ASSERT(prAdapter);
  2996. /* @TODO: invoke wlan_p2p functions */
  2997. #if 0
  2998. rStatus = kalIoctl(prGlueInfo,
  2999. (PFN_OID_HANDLER_FUNC_REQ) wlanoidSetP2pNetworkAddress,
  3000. prKey, prKey->u4Length, FALSE, FALSE, TRUE, &u4BufLen);
  3001. #endif
  3002. return 0;
  3003. }
  3004. int
  3005. mtk_p2p_wext_set_ps_profile(IN struct net_device *prDev,
  3006. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3007. {
  3008. P_ADAPTER_T prAdapter = NULL;
  3009. P_GLUE_INFO_T prGlueInfo = NULL;
  3010. ASSERT(prDev);
  3011. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3012. ASSERT(prGlueInfo);
  3013. prAdapter = prGlueInfo->prAdapter;
  3014. ASSERT(prAdapter);
  3015. /* @TODO: invoke wlan_p2p functions */
  3016. #if 0
  3017. rStatus = kalIoctl(prGlueInfo,
  3018. (PFN_OID_HANDLER_FUNC_REQ) wlanoidSetP2pPowerSaveProfile,
  3019. prKey, prKey->u4Length, FALSE, FALSE, TRUE, &u4BufLen);
  3020. #endif
  3021. return 0;
  3022. }
  3023. int
  3024. mtk_p2p_wext_set_pm_param(IN struct net_device *prDev,
  3025. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3026. {
  3027. P_ADAPTER_T prAdapter = NULL;
  3028. P_GLUE_INFO_T prGlueInfo = NULL;
  3029. ASSERT(prDev);
  3030. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3031. ASSERT(prGlueInfo);
  3032. prAdapter = prGlueInfo->prAdapter;
  3033. ASSERT(prAdapter);
  3034. /* @TODO: invoke wlan_p2p functions */
  3035. #if 0
  3036. rStatus = kalIoctl(prGlueInfo,
  3037. (PFN_OID_HANDLER_FUNC_REQ) wlanoidSetP2pPowerSaveProfile,
  3038. prKey, prKey->u4Length, FALSE, FALSE, TRUE, &u4BufLen);
  3039. #endif
  3040. return 0;
  3041. }
  3042. /*----------------------------------------------------------------------------*/
  3043. /*!
  3044. * \brief P2P Private I/O Control handler (IOC_P2P_SET_INT)
  3045. *
  3046. * \param[in] prDev Net device requested.
  3047. * \param[inout] wrqu Pointer to iwreq_data
  3048. *
  3049. * \retval 0 Success.
  3050. * \retval -EFAULT Setting parameters to driver fail.
  3051. * \retval -EOPNOTSUPP Setting parameters not support.
  3052. *
  3053. * \note
  3054. */
  3055. /*----------------------------------------------------------------------------*/
  3056. int
  3057. mtk_p2p_wext_start_formation(IN struct net_device *prDev,
  3058. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3059. {
  3060. int i4Status = 0;
  3061. P_ADAPTER_T prAdapter = (P_ADAPTER_T) NULL;
  3062. P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T) NULL;
  3063. /* struct iw_point *prData = (struct iw_point*)&wrqu->data; */
  3064. P_IW_P2P_IOCTL_START_FORMATION prIoctlStartFormation = (P_IW_P2P_IOCTL_START_FORMATION) NULL;
  3065. do {
  3066. if ((prDev == NULL) || (extra == NULL)) {
  3067. ASSERT(FALSE);
  3068. i4Status = -EINVAL;
  3069. break;
  3070. }
  3071. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3072. prIoctlStartFormation = (P_IW_P2P_IOCTL_START_FORMATION) extra;
  3073. if (prGlueInfo == NULL) {
  3074. i4Status = -EINVAL;
  3075. break;
  3076. }
  3077. prAdapter = prGlueInfo->prAdapter;
  3078. if (prAdapter == NULL) {
  3079. i4Status = -EINVAL;
  3080. break;
  3081. }
  3082. } while (FALSE);
  3083. return i4Status;
  3084. }
  3085. /* mtk_p2p_wext_start_formation */
  3086. /*----------------------------------------------------------------------------*/
  3087. /*!
  3088. * \brief P2P Private I/O Control handler (IOC_P2P_SET_INT)
  3089. *
  3090. * \param[in] prDev Net device requested.
  3091. * \param[inout] wrqu Pointer to iwreq_data
  3092. *
  3093. * \retval 0 Success.
  3094. * \retval -EFAULT Setting parameters to driver fail.
  3095. * \retval -EOPNOTSUPP Setting parameters not support.
  3096. *
  3097. * \note
  3098. */
  3099. /*----------------------------------------------------------------------------*/
  3100. int
  3101. mtk_p2p_wext_set_int(IN struct net_device *prDev,
  3102. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3103. {
  3104. int status = 0;
  3105. UINT_32 u4SubCmd = 0;
  3106. P_GLUE_INFO_T prGlueInfo = NULL;
  3107. UINT_32 index;
  3108. INT_32 value;
  3109. PUINT_32 pu4IntBuf;
  3110. P_P2P_SPECIFIC_BSS_INFO_T prP2pSpecificBssInfo = (P_P2P_SPECIFIC_BSS_INFO_T) NULL;
  3111. P_P2P_CONNECTION_SETTINGS_T prP2pConnSettings = (P_P2P_CONNECTION_SETTINGS_T) NULL;
  3112. P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T) NULL;
  3113. UINT_32 u4Leng;
  3114. ASSERT(prDev);
  3115. ASSERT(wrqu);
  3116. pu4IntBuf = (PUINT_32) extra;
  3117. if (FALSE == GLUE_CHK_PR2(prDev, wrqu))
  3118. return -EINVAL;
  3119. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3120. ASSERT(prGlueInfo);
  3121. prP2pSpecificBssInfo = prGlueInfo->prAdapter->rWifiVar.prP2pSpecificBssInfo;
  3122. prP2pConnSettings = prGlueInfo->prAdapter->rWifiVar.prP2PConnSettings;
  3123. prP2pFsmInfo = prGlueInfo->prAdapter->rWifiVar.prP2pFsmInfo;
  3124. u4SubCmd = (UINT_32) wrqu->mode;
  3125. index = pu4IntBuf[1];
  3126. value = pu4IntBuf[2];
  3127. DBGLOG(INIT, WARN,
  3128. "set parameter, u4SubCmd=%d idx=%d value=%lu\n", (INT_16) u4SubCmd, (INT_16) index, value);
  3129. switch (u4SubCmd) {
  3130. case PRIV_CMD_INT_P2P_SET:
  3131. switch (index) {
  3132. case 0: /* Listen CH */
  3133. {
  3134. UINT_8 ucSuggestChnl = 0;
  3135. prP2pConnSettings->ucListenChnl = value;
  3136. /* 20110920 - frog: User configurations are placed in ConnSettings. */
  3137. if (rlmFuncFindAvailableChannel
  3138. (prGlueInfo->prAdapter, value, &ucSuggestChnl, TRUE, TRUE)) {
  3139. prP2pSpecificBssInfo->ucListenChannel = value;
  3140. } else {
  3141. prP2pSpecificBssInfo->ucListenChannel = ucSuggestChnl;
  3142. }
  3143. break;
  3144. }
  3145. case 1: /* P2p mode */
  3146. break;
  3147. case 4: /* Noa duration */
  3148. prP2pSpecificBssInfo->rNoaParam.u4NoaDurationMs = value;
  3149. /* only to apply setting when setting NOA count */
  3150. /* status = mtk_p2p_wext_set_noa_param(prDev,
  3151. info,
  3152. wrqu,
  3153. (char *)&prP2pSpecificBssInfo->rNoaParam); */
  3154. break;
  3155. case 5: /* Noa interval */
  3156. prP2pSpecificBssInfo->rNoaParam.u4NoaIntervalMs = value;
  3157. /* only to apply setting when setting NOA count */
  3158. /* status = mtk_p2p_wext_set_noa_param(prDev,
  3159. info,
  3160. wrqu,
  3161. (char *)&prP2pSpecificBssInfo->rNoaParam); */
  3162. break;
  3163. case 6: /* Noa count */
  3164. prP2pSpecificBssInfo->rNoaParam.u4NoaCount = value;
  3165. status =
  3166. mtk_p2p_wext_set_noa_param(prDev, info, wrqu, (char *)&prP2pSpecificBssInfo->rNoaParam);
  3167. break;
  3168. case 100: /* Oper CH */
  3169. /* 20110920 - frog: User configurations are placed in ConnSettings. */
  3170. prP2pConnSettings->ucOperatingChnl = value;
  3171. break;
  3172. case 101: /* Local config Method, for P2P SDK */
  3173. /* prP2pConnSettings->u2LocalConfigMethod; */
  3174. break;
  3175. case 102: /* Sigma P2p reset */
  3176. kalMemZero(prP2pConnSettings->aucTargetDevAddr, MAC_ADDR_LEN);
  3177. /* prP2pConnSettings->eConnectionPolicy = ENUM_P2P_CONNECTION_POLICY_AUTO; */
  3178. break;
  3179. case 103: /* WPS MODE */
  3180. kalP2PSetWscMode(prGlueInfo, value);
  3181. break;
  3182. case 104: /* P2p send persence, duration */
  3183. break;
  3184. case 105: /* P2p send persence, interval */
  3185. break;
  3186. case 106: /* P2P set sleep */
  3187. value = 1;
  3188. kalIoctl(prGlueInfo,
  3189. wlanoidSetP2pPowerSaveProfile,
  3190. &value, sizeof(value), FALSE, FALSE, TRUE, TRUE, &u4Leng);
  3191. break;
  3192. case 107: /* P2P set opps, CTWindowl */
  3193. prP2pSpecificBssInfo->rOppPsParam.u4CTwindowMs = value;
  3194. status =
  3195. mtk_p2p_wext_set_oppps_param(prDev, info, wrqu, (char *)&prP2pSpecificBssInfo->rOppPsParam);
  3196. break;
  3197. case 108: /* p2p_set_power_save */
  3198. kalIoctl(prGlueInfo,
  3199. wlanoidSetP2pPowerSaveProfile,
  3200. &value, sizeof(value), FALSE, FALSE, TRUE, TRUE, &u4Leng);
  3201. break;
  3202. default:
  3203. break;
  3204. }
  3205. break;
  3206. default:
  3207. break;
  3208. }
  3209. return status;
  3210. }
  3211. /*----------------------------------------------------------------------------*/
  3212. /*!
  3213. * \brief P2P Private I/O Control handler (IOC_P2P_SET_STRUCT)
  3214. *
  3215. * \param[in] prDev Net device requested.
  3216. * \param[inout] wrqu Pointer to iwreq_data
  3217. *
  3218. * \retval 0 Success.
  3219. * \retval -EFAULT Setting parameters to driver fail.
  3220. * \retval -EOPNOTSUPP Key size not supported.
  3221. *
  3222. * \note
  3223. */
  3224. /*----------------------------------------------------------------------------*/
  3225. int
  3226. mtk_p2p_wext_set_struct(IN struct net_device *prDev,
  3227. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3228. {
  3229. int status = 0;
  3230. UINT_32 u4SubCmd = 0;
  3231. P_GLUE_INFO_T prGlueInfo = NULL;
  3232. P_IW_P2P_TRANSPORT_STRUCT prP2PReq = NULL;
  3233. ASSERT(prDev);
  3234. ASSERT(wrqu);
  3235. if (FALSE == GLUE_CHK_PR2(prDev, wrqu))
  3236. return -EINVAL;
  3237. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3238. ASSERT(prGlueInfo);
  3239. u4SubCmd = (UINT_32) wrqu->data.flags;
  3240. kalMemZero(&prGlueInfo->prP2PInfo->aucOidBuf[0], sizeof(prGlueInfo->prP2PInfo->aucOidBuf));
  3241. switch (u4SubCmd) {
  3242. case PRIV_CMD_OID:
  3243. if (copy_from_user(&(prGlueInfo->prP2PInfo->aucOidBuf[0]), wrqu->data.pointer, wrqu->data.length)) {
  3244. status = -EFAULT;
  3245. break;
  3246. }
  3247. if (!kalMemCmp(&(prGlueInfo->prP2PInfo->aucOidBuf[0]), extra, wrqu->data.length))
  3248. DBGLOG(INIT, WARN, "extra buffer is valid\n");
  3249. else
  3250. DBGLOG(INIT, WARN, "extra 0x%p\n", extra);
  3251. prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT) (&(prGlueInfo->prP2PInfo->aucOidBuf[0]));
  3252. switch (prP2PReq->u4CmdId) {
  3253. case P2P_CMD_ID_SEND_SD_RESPONSE:
  3254. status = mtk_p2p_wext_send_service_discovery_response(prDev, info, wrqu, (char *)prP2PReq);
  3255. break;
  3256. case P2P_CMD_ID_SEND_SD_REQUEST:
  3257. status = mtk_p2p_wext_send_service_discovery_request(prDev, info, wrqu, (char *)prP2PReq);
  3258. break;
  3259. case P2P_CMD_ID_TERMINATE_SD_PHASE:
  3260. status = mtk_p2p_wext_terminate_service_discovery_phase(prDev, info, wrqu, (char *)prP2PReq);
  3261. break;
  3262. case P2P_CMD_ID_INVITATION:
  3263. if (prP2PReq->inBufferLength == sizeof(IW_P2P_IOCTL_INVITATION_STRUCT)) {
  3264. /* status = mtk_p2p_wext_invitation_request(prDev,
  3265. info,
  3266. wrqu,
  3267. (char *)(prP2PReq->aucBuffer)); */
  3268. }
  3269. break;
  3270. case P2P_CMD_ID_INVITATION_ABORT:
  3271. if (prP2PReq->inBufferLength == sizeof(IW_P2P_IOCTL_ABORT_INVITATION)) {
  3272. /* status = mtk_p2p_wext_invitation_abort(prDev,
  3273. info,
  3274. wrqu,
  3275. (char *)(prP2PReq->aucBuffer)); */
  3276. }
  3277. break;
  3278. case P2P_CMD_ID_START_FORMATION:
  3279. if (prP2PReq->inBufferLength == sizeof(IW_P2P_IOCTL_START_FORMATION))
  3280. status = mtk_p2p_wext_start_formation(prDev, info, wrqu, (char *)(prP2PReq->aucBuffer));
  3281. break;
  3282. default:
  3283. status = -EOPNOTSUPP;
  3284. }
  3285. break;
  3286. #if CFG_SUPPORT_ANTI_PIRACY
  3287. case PRIV_SEC_CHECK_OID:
  3288. if (wrqu->data.length > 256) {
  3289. status = -EOPNOTSUPP;
  3290. break;
  3291. }
  3292. if (copy_from_user(&(prGlueInfo->prP2PInfo->aucSecCheck[0]), wrqu->data.pointer, wrqu->data.length)) {
  3293. status = -EFAULT;
  3294. break;
  3295. }
  3296. if (!kalMemCmp(&(prGlueInfo->prP2PInfo->aucSecCheck[0]), extra, wrqu->data.length))
  3297. DBGLOG(INIT, WARN, "extra buffer is valid\n");
  3298. else
  3299. DBGLOG(INIT, WARN, "extra 0x%p\n", extra);
  3300. prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT) (&(prGlueInfo->prP2PInfo->aucSecCheck[0]));
  3301. switch (prP2PReq->u4CmdId) {
  3302. case P2P_CMD_ID_SEC_CHECK:
  3303. status = mtk_p2p_wext_set_sec_check_request(prDev, info, wrqu, (char *)prP2PReq);
  3304. break;
  3305. default:
  3306. status = -EOPNOTSUPP;
  3307. }
  3308. break;
  3309. #endif
  3310. case PRIV_CMD_P2P_VERSION:
  3311. if (copy_from_user(&(prGlueInfo->prP2PInfo->aucOidBuf[0]), wrqu->data.pointer, wrqu->data.length)) {
  3312. status = -EFAULT;
  3313. break;
  3314. }
  3315. if (!kalMemCmp(&(prGlueInfo->prP2PInfo->aucOidBuf[0]), extra, wrqu->data.length))
  3316. DBGLOG(INIT, WARN, "extra buffer is valid\n");
  3317. else
  3318. DBGLOG(INIT, WARN, "extra 0x%p\n", extra);
  3319. prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT) (&(prGlueInfo->prP2PInfo->aucOidBuf[0]));
  3320. switch (prP2PReq->u4CmdId) {
  3321. case P2P_CMD_ID_P2P_VERSION:
  3322. status = mtk_p2p_wext_set_p2p_version(prDev, info, wrqu, (char *)prP2PReq);
  3323. break;
  3324. default:
  3325. status = -EOPNOTSUPP;
  3326. break;
  3327. }
  3328. break;
  3329. default:
  3330. status = -EOPNOTSUPP;
  3331. break;
  3332. }
  3333. return status;
  3334. }
  3335. /*----------------------------------------------------------------------------*/
  3336. /*!
  3337. * \brief P2P Private I/O Control handler (IOC_P2P_GET_STRUCT)
  3338. *
  3339. * \param[in] prDev Net device requested.
  3340. * \param[inout] wrqu Pointer to iwreq_data
  3341. *
  3342. * \retval 0 Success.
  3343. * \retval -EFAULT Setting parameters to driver fail.
  3344. * \retval -EOPNOTSUPP Key size not supported.
  3345. *
  3346. * \note
  3347. */
  3348. /*----------------------------------------------------------------------------*/
  3349. int
  3350. mtk_p2p_wext_get_struct(IN struct net_device *prDev,
  3351. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3352. {
  3353. int status = 0;
  3354. UINT_32 u4SubCmd = 0;
  3355. P_GLUE_INFO_T prGlueInfo = NULL;
  3356. P_IW_P2P_TRANSPORT_STRUCT prP2PReq = NULL;
  3357. ASSERT(prDev);
  3358. ASSERT(wrqu);
  3359. if (!prDev || !wrqu) {
  3360. DBGLOG(INIT, WARN, "%s(): invalid param(0x%p, 0x%p)\n", __func__, prDev, wrqu);
  3361. return -EINVAL;
  3362. }
  3363. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3364. ASSERT(prGlueInfo);
  3365. u4SubCmd = (UINT_32) wrqu->data.flags;
  3366. kalMemZero(&(prGlueInfo->prP2PInfo->aucOidBuf[0]), sizeof(prGlueInfo->prP2PInfo->aucOidBuf));
  3367. switch (u4SubCmd) {
  3368. case PRIV_CMD_OID:
  3369. if (copy_from_user(&(prGlueInfo->prP2PInfo->aucOidBuf[0]),
  3370. wrqu->data.pointer, sizeof(IW_P2P_TRANSPORT_STRUCT))) {
  3371. DBGLOG(INIT, WARN, "%s() copy_from_user oidBuf fail\n", __func__);
  3372. return -EFAULT;
  3373. }
  3374. prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT) (&(prGlueInfo->prP2PInfo->aucOidBuf[0]));
  3375. switch (prP2PReq->u4CmdId) {
  3376. case P2P_CMD_ID_GET_SD_REQUEST:
  3377. status = mtk_p2p_wext_get_service_discovery_request(prDev, info, wrqu, (char *)prP2PReq);
  3378. break;
  3379. case P2P_CMD_ID_GET_SD_RESPONSE:
  3380. status = mtk_p2p_wext_get_service_discovery_response(prDev, info, wrqu, (char *)prP2PReq);
  3381. break;
  3382. case P2P_CMD_ID_INVITATION_INDICATE:
  3383. {
  3384. status =
  3385. mtk_p2p_wext_invitation_indicate(prDev, info, wrqu, (char *)(prP2PReq->aucBuffer));
  3386. prP2PReq->outBufferLength = wrqu->data.length;
  3387. if (copy_to_user(wrqu->data.pointer,
  3388. &(prGlueInfo->prP2PInfo->aucOidBuf[0]),
  3389. wrqu->data.length + OFFSET_OF(IW_P2P_TRANSPORT_STRUCT, aucBuffer))) {
  3390. DBGLOG(INIT, WARN, "%s() copy_to_user() fail\n", __func__);
  3391. return -EIO;
  3392. } else {
  3393. return 0;
  3394. }
  3395. break;
  3396. }
  3397. case P2P_CMD_ID_INVITATION_STATUS:
  3398. {
  3399. status =
  3400. mtk_p2p_wext_invitation_status(prDev, info, wrqu, (char *)(prP2PReq->aucBuffer));
  3401. prP2PReq->outBufferLength = wrqu->data.length;
  3402. if (copy_to_user(wrqu->data.pointer,
  3403. &(prGlueInfo->prP2PInfo->aucOidBuf[0]),
  3404. wrqu->data.length + OFFSET_OF(IW_P2P_TRANSPORT_STRUCT, aucBuffer))) {
  3405. DBGLOG(INIT, WARN, "%s() copy_to_user() fail\n", __func__);
  3406. return -EIO;
  3407. } else {
  3408. return 0;
  3409. }
  3410. break;
  3411. }
  3412. case P2P_CMD_ID_GET_CH_LIST:
  3413. {
  3414. UINT_16 i;
  3415. UINT_8 NumOfChannel = 50;
  3416. RF_CHANNEL_INFO_T aucChannelList[50];
  3417. UINT_8 ucMaxChannelNum = 50;
  3418. PUINT_8 pucChnlList = (PUINT_8) prP2PReq->aucBuffer;
  3419. kalGetChnlList(prGlueInfo, BAND_NULL, ucMaxChannelNum, &NumOfChannel, aucChannelList);
  3420. if (NumOfChannel > 50)
  3421. NumOfChannel = 50;
  3422. prP2PReq->outBufferLength = NumOfChannel;
  3423. for (i = 0; i < NumOfChannel; i++) {
  3424. #if 0
  3425. /* 20120208 frog: modify to avoid clockwork warning. */
  3426. prP2PReq->aucBuffer[i] = aucChannelList[i].ucChannelNum;
  3427. #else
  3428. *pucChnlList = aucChannelList[i].ucChannelNum;
  3429. pucChnlList++;
  3430. #endif
  3431. }
  3432. if (copy_to_user(wrqu->data.pointer,
  3433. &(prGlueInfo->prP2PInfo->aucOidBuf[0]),
  3434. NumOfChannel + OFFSET_OF(IW_P2P_TRANSPORT_STRUCT, aucBuffer))) {
  3435. DBGLOG(INIT, WARN, "%s() copy_to_user() fail\n", __func__);
  3436. return -EIO;
  3437. } else {
  3438. return 0;
  3439. }
  3440. break;
  3441. }
  3442. case P2P_CMD_ID_GET_OP_CH:
  3443. {
  3444. prP2PReq->inBufferLength = 4;
  3445. status = wlanoidQueryP2pOpChannel(prGlueInfo->prAdapter,
  3446. prP2PReq->aucBuffer,
  3447. prP2PReq->inBufferLength, &prP2PReq->outBufferLength);
  3448. if (status == 0) { /* WLAN_STATUS_SUCCESS */
  3449. if (copy_to_user(wrqu->data.pointer,
  3450. &(prGlueInfo->prP2PInfo->aucOidBuf[0]),
  3451. prP2PReq->outBufferLength +
  3452. OFFSET_OF(IW_P2P_TRANSPORT_STRUCT, aucBuffer))) {
  3453. DBGLOG(INIT, WARN, "%s() copy_to_user() fail\n", __func__);
  3454. return -EIO;
  3455. }
  3456. } else {
  3457. if (copy_to_user(wrqu->data.pointer,
  3458. &(prGlueInfo->prP2PInfo->aucOidBuf[0]),
  3459. OFFSET_OF(IW_P2P_TRANSPORT_STRUCT, aucBuffer))) {
  3460. DBGLOG(INIT, WARN, "%s() copy_to_user() fail\n", __func__);
  3461. return -EIO;
  3462. }
  3463. }
  3464. break;
  3465. }
  3466. default:
  3467. status = -EOPNOTSUPP;
  3468. }
  3469. break;
  3470. #if CFG_SUPPORT_ANTI_PIRACY
  3471. case PRIV_SEC_CHECK_OID:
  3472. if (wrqu->data.length > 256) {
  3473. status = -EOPNOTSUPP;
  3474. break;
  3475. }
  3476. if (copy_from_user(&(prGlueInfo->prP2PInfo->aucSecCheck[0]),
  3477. wrqu->data.pointer, sizeof(IW_P2P_TRANSPORT_STRUCT))) {
  3478. DBGLOG(INIT, WARN, "%s() copy_from_user oidBuf fail\n", __func__);
  3479. return -EFAULT;
  3480. }
  3481. prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT) (&(prGlueInfo->prP2PInfo->aucSecCheck[0]));
  3482. switch (prP2PReq->u4CmdId) {
  3483. case P2P_CMD_ID_SEC_CHECK:
  3484. status = mtk_p2p_wext_get_sec_check_response(prDev, info, wrqu, (char *)prP2PReq);
  3485. break;
  3486. default:
  3487. status = -EOPNOTSUPP;
  3488. }
  3489. break;
  3490. #endif
  3491. case PRIV_CMD_P2P_VERSION:
  3492. if (copy_from_user(&(prGlueInfo->prP2PInfo->aucOidBuf[0]),
  3493. wrqu->data.pointer, sizeof(IW_P2P_TRANSPORT_STRUCT))) {
  3494. DBGLOG(INIT, WARN, "%s() copy_from_user oidBuf fail\n", __func__);
  3495. return -EFAULT;
  3496. }
  3497. prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT) (&(prGlueInfo->prP2PInfo->aucOidBuf[0]));
  3498. switch (prP2PReq->u4CmdId) {
  3499. case P2P_CMD_ID_P2P_VERSION:
  3500. status = mtk_p2p_wext_get_p2p_version(prDev, info, wrqu, (char *)prP2PReq);
  3501. break;
  3502. default:
  3503. status = -EOPNOTSUPP;
  3504. break;
  3505. }
  3506. /* Copy queried data to user. */
  3507. if (status == 0) { /* WLAN_STATUS_SUCCESS */
  3508. if (copy_to_user(wrqu->data.pointer,
  3509. &(prGlueInfo->prP2PInfo->aucOidBuf[0]),
  3510. prP2PReq->outBufferLength + OFFSET_OF(IW_P2P_TRANSPORT_STRUCT, aucBuffer))) {
  3511. DBGLOG(INIT, WARN, "%s() copy_to_user() fail\n", __func__);
  3512. return -EIO;
  3513. }
  3514. }
  3515. else {
  3516. if (copy_to_user(wrqu->data.pointer,
  3517. &(prGlueInfo->prP2PInfo->aucOidBuf[0]),
  3518. OFFSET_OF(IW_P2P_TRANSPORT_STRUCT, aucBuffer))) {
  3519. DBGLOG(INIT, WARN, "%s() copy_to_user() fail\n", __func__);
  3520. return -EIO;
  3521. }
  3522. }
  3523. break;
  3524. default:
  3525. return -EOPNOTSUPP;
  3526. }
  3527. return status;
  3528. }
  3529. /*----------------------------------------------------------------------------*/
  3530. /*!
  3531. * \brief P2P Private I/O Control handler for
  3532. * getting service discovery request frame from driver
  3533. *
  3534. * \param[in] prDev Net device requested.
  3535. * \param[inout] wrqu Pointer to iwreq_data
  3536. *
  3537. * \retval 0 Success.
  3538. * \retval -EFAULT Setting parameters to driver fail.
  3539. * \retval -EOPNOTSUPP Key size not supported.
  3540. *
  3541. * \note
  3542. */
  3543. /*----------------------------------------------------------------------------*/
  3544. int
  3545. mtk_p2p_wext_get_service_discovery_request(IN struct net_device *prDev,
  3546. IN struct iw_request_info *info,
  3547. IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3548. {
  3549. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  3550. UINT_32 u4QueryInfoLen;
  3551. P_IW_P2P_TRANSPORT_STRUCT prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT) extra;
  3552. P_GLUE_INFO_T prGlueInfo = NULL;
  3553. ASSERT(prDev);
  3554. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3555. ASSERT(prGlueInfo);
  3556. rStatus = kalIoctl(prGlueInfo,
  3557. wlanoidGetP2PSDRequest,
  3558. prP2PReq->aucBuffer, prP2PReq->outBufferLength, TRUE, FALSE, TRUE, TRUE, &u4QueryInfoLen);
  3559. if (rStatus != WLAN_STATUS_SUCCESS)
  3560. return -EFAULT;
  3561. prP2PReq->outBufferLength = u4QueryInfoLen;
  3562. if (copy_to_user(wrqu->data.pointer,
  3563. &(prGlueInfo->prP2PInfo->aucOidBuf[0]),
  3564. u4QueryInfoLen + OFFSET_OF(IW_P2P_TRANSPORT_STRUCT, aucBuffer))) {
  3565. DBGLOG(INIT, WARN, "%s() copy_to_user() fail\n", __func__);
  3566. return -EIO;
  3567. } else {
  3568. return 0;
  3569. }
  3570. }
  3571. /*----------------------------------------------------------------------------*/
  3572. /*!
  3573. * \brief P2P Private I/O Control handler for
  3574. * getting service discovery response frame from driver
  3575. *
  3576. * \param[in] prDev Net device requested.
  3577. * \param[inout] wrqu Pointer to iwreq_data
  3578. *
  3579. * \retval 0 Success.
  3580. * \retval -EFAULT Setting parameters to driver fail.
  3581. * \retval -EOPNOTSUPP Key size not supported.
  3582. *
  3583. * \note
  3584. */
  3585. /*----------------------------------------------------------------------------*/
  3586. int
  3587. mtk_p2p_wext_get_service_discovery_response(IN struct net_device *prDev,
  3588. IN struct iw_request_info *info,
  3589. IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3590. {
  3591. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  3592. UINT_32 u4QueryInfoLen;
  3593. P_IW_P2P_TRANSPORT_STRUCT prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT) extra;
  3594. P_GLUE_INFO_T prGlueInfo = NULL;
  3595. ASSERT(prDev);
  3596. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3597. ASSERT(prGlueInfo);
  3598. rStatus = kalIoctl(prGlueInfo,
  3599. wlanoidGetP2PSDResponse,
  3600. prP2PReq->aucBuffer, prP2PReq->outBufferLength, TRUE, FALSE, TRUE, TRUE, &u4QueryInfoLen);
  3601. if (rStatus != WLAN_STATUS_SUCCESS)
  3602. return -EFAULT;
  3603. prP2PReq->outBufferLength = u4QueryInfoLen;
  3604. if (copy_to_user(wrqu->data.pointer,
  3605. &(prGlueInfo->prP2PInfo->aucOidBuf[0]),
  3606. u4QueryInfoLen + OFFSET_OF(IW_P2P_TRANSPORT_STRUCT, aucBuffer))) {
  3607. DBGLOG(INIT, WARN, "%s() copy_to_user() fail\n", __func__);
  3608. return -EIO;
  3609. } else {
  3610. return 0;
  3611. }
  3612. }
  3613. /*----------------------------------------------------------------------------*/
  3614. /*!
  3615. * \brief P2P Private I/O Control handler for
  3616. * sending service discovery request frame
  3617. *
  3618. * \param[in] prDev Net device requested.
  3619. * \param[inout] wrqu Pointer to iwreq_data
  3620. *
  3621. * \retval 0 Success.
  3622. * \retval -EFAULT Setting parameters to driver fail.
  3623. * \retval -EOPNOTSUPP Key size not supported.
  3624. *
  3625. * \note
  3626. */
  3627. /*----------------------------------------------------------------------------*/
  3628. int
  3629. mtk_p2p_wext_send_service_discovery_request(IN struct net_device *prDev,
  3630. IN struct iw_request_info *info,
  3631. IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3632. {
  3633. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  3634. UINT_32 u4SetInfoLen;
  3635. P_IW_P2P_TRANSPORT_STRUCT prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT) extra;
  3636. P_GLUE_INFO_T prGlueInfo = NULL;
  3637. ASSERT(prDev);
  3638. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3639. ASSERT(prGlueInfo);
  3640. rStatus = kalIoctl(prGlueInfo,
  3641. wlanoidSendP2PSDRequest,
  3642. prP2PReq->aucBuffer, prP2PReq->inBufferLength, FALSE, FALSE, TRUE, TRUE, &u4SetInfoLen);
  3643. if (rStatus != WLAN_STATUS_SUCCESS)
  3644. return -EFAULT;
  3645. else
  3646. return 0;
  3647. }
  3648. /*----------------------------------------------------------------------------*/
  3649. /*!
  3650. * \brief P2P Private I/O Control handler for
  3651. * sending service discovery response frame
  3652. *
  3653. * \param[in] prDev Net device requested.
  3654. * \param[inout] wrqu Pointer to iwreq_data
  3655. *
  3656. * \retval 0 Success.
  3657. * \retval -EFAULT Setting parameters to driver fail.
  3658. * \retval -EOPNOTSUPP Key size not supported.
  3659. *
  3660. * \note
  3661. */
  3662. /*----------------------------------------------------------------------------*/
  3663. int
  3664. mtk_p2p_wext_send_service_discovery_response(IN struct net_device *prDev,
  3665. IN struct iw_request_info *info,
  3666. IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3667. {
  3668. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  3669. UINT_32 u4SetInfoLen;
  3670. P_IW_P2P_TRANSPORT_STRUCT prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT) extra;
  3671. P_GLUE_INFO_T prGlueInfo = NULL;
  3672. ASSERT(prDev);
  3673. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3674. ASSERT(prGlueInfo);
  3675. rStatus = kalIoctl(prGlueInfo,
  3676. wlanoidSendP2PSDResponse,
  3677. prP2PReq->aucBuffer, prP2PReq->inBufferLength, FALSE, FALSE, TRUE, TRUE, &u4SetInfoLen);
  3678. if (rStatus != WLAN_STATUS_SUCCESS)
  3679. return -EFAULT;
  3680. else
  3681. return 0;
  3682. }
  3683. #if CFG_SUPPORT_ANTI_PIRACY
  3684. /*----------------------------------------------------------------------------*/
  3685. /*!
  3686. * \brief P2P Private I/O Control handler for
  3687. *
  3688. * \param[in] prDev Net device requested.
  3689. * \param[inout] wrqu Pointer to iwreq_data
  3690. *
  3691. * \retval 0 Success.
  3692. * \retval -EFAULT Setting parameters to driver fail.
  3693. * \retval -EOPNOTSUPP Key size not supported.
  3694. *
  3695. * \note
  3696. */
  3697. /*----------------------------------------------------------------------------*/
  3698. int
  3699. mtk_p2p_wext_set_sec_check_request(IN struct net_device *prDev,
  3700. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3701. {
  3702. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  3703. UINT_32 u4SetInfoLen;
  3704. P_IW_P2P_TRANSPORT_STRUCT prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT) extra;
  3705. P_GLUE_INFO_T prGlueInfo = NULL;
  3706. ASSERT(prDev);
  3707. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3708. ASSERT(prGlueInfo);
  3709. rStatus = kalIoctl(prGlueInfo,
  3710. wlanoidSetSecCheckRequest,
  3711. prP2PReq->aucBuffer, prP2PReq->inBufferLength, FALSE, FALSE, TRUE, TRUE, &u4SetInfoLen);
  3712. if (rStatus != WLAN_STATUS_SUCCESS)
  3713. return -EFAULT;
  3714. else
  3715. return 0;
  3716. }
  3717. /*----------------------------------------------------------------------------*/
  3718. /*!
  3719. * \brief P2P Private I/O Control handler for
  3720. *
  3721. * \param[in] prDev Net device requested.
  3722. * \param[inout] wrqu Pointer to iwreq_data
  3723. *
  3724. * \retval 0 Success.
  3725. * \retval -EFAULT Setting parameters to driver fail.
  3726. * \retval -EOPNOTSUPP Key size not supported.
  3727. *
  3728. * \note
  3729. */
  3730. /*----------------------------------------------------------------------------*/
  3731. int
  3732. mtk_p2p_wext_get_sec_check_response(IN struct net_device *prDev,
  3733. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3734. {
  3735. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  3736. UINT_32 u4QueryInfoLen;
  3737. P_IW_P2P_TRANSPORT_STRUCT prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT) extra;
  3738. P_GLUE_INFO_T prGlueInfo = NULL;
  3739. ASSERT(prDev);
  3740. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3741. ASSERT(prGlueInfo);
  3742. DBGLOG(INIT, INFO, "mtk_p2p_wext_get_sec_check_response\n");
  3743. rStatus = kalIoctl(prGlueInfo,
  3744. wlanoidGetSecCheckResponse,
  3745. prP2PReq->aucBuffer, prP2PReq->outBufferLength, TRUE, FALSE, TRUE, TRUE, &u4QueryInfoLen);
  3746. if (rStatus != WLAN_STATUS_SUCCESS)
  3747. return -EFAULT;
  3748. prP2PReq->outBufferLength = u4QueryInfoLen;
  3749. if (copy_to_user(wrqu->data.pointer,
  3750. prP2PReq->aucBuffer, u4QueryInfoLen + OFFSET_OF(IW_P2P_TRANSPORT_STRUCT, aucBuffer))) {
  3751. DBGLOG(INIT, WARN, "%s() copy_to_user() fail\n", __func__);
  3752. return -EIO;
  3753. } else {
  3754. return 0;
  3755. }
  3756. }
  3757. #endif
  3758. /*----------------------------------------------------------------------------*/
  3759. /*!
  3760. * \brief P2P Private I/O Control handler for
  3761. * terminating service discovery phase
  3762. *
  3763. * \param[in] prDev Net device requested.
  3764. * \param[inout] wrqu Pointer to iwreq_data
  3765. *
  3766. * \retval 0 Success.
  3767. * \retval -EFAULT Setting parameters to driver fail.
  3768. * \retval -EOPNOTSUPP Key size not supported.
  3769. *
  3770. * \note
  3771. */
  3772. /*----------------------------------------------------------------------------*/
  3773. int
  3774. mtk_p2p_wext_terminate_service_discovery_phase(IN struct net_device *prDev,
  3775. IN struct iw_request_info *info,
  3776. IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3777. {
  3778. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  3779. UINT_32 u4SetInfoLen;
  3780. P_IW_P2P_TRANSPORT_STRUCT prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT) extra;
  3781. P_GLUE_INFO_T prGlueInfo = NULL;
  3782. ASSERT(prDev);
  3783. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3784. ASSERT(prGlueInfo);
  3785. rStatus = kalIoctl(prGlueInfo,
  3786. wlanoidSetP2PTerminateSDPhase,
  3787. prP2PReq->aucBuffer, prP2PReq->inBufferLength, FALSE, FALSE, TRUE, TRUE, &u4SetInfoLen);
  3788. if (rStatus != WLAN_STATUS_SUCCESS)
  3789. return -EFAULT;
  3790. else
  3791. return 0;
  3792. }
  3793. /*----------------------------------------------------------------------------*/
  3794. /*!
  3795. * \brief P2P Private I/O Control handler for
  3796. *
  3797. * \param[in] prDev Net device requested.
  3798. * \param[inout] wrqu Pointer to iwreq_data
  3799. *
  3800. * \retval 0 Success.
  3801. * \retval -EFAULT Setting parameters to driver fail.
  3802. * \retval -EOPNOTSUPP Key size not supported.
  3803. *
  3804. * \note
  3805. */
  3806. /*----------------------------------------------------------------------------*/
  3807. int
  3808. mtk_p2p_wext_set_noa_param(IN struct net_device *prDev,
  3809. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3810. {
  3811. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  3812. UINT_32 u4SetInfoLen;
  3813. /* P_IW_P2P_TRANSPORT_STRUCT prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT)extra; */
  3814. P_PARAM_CUSTOM_NOA_PARAM_STRUCT_T prNoaParam = (P_PARAM_CUSTOM_NOA_PARAM_STRUCT_T) extra;
  3815. P_GLUE_INFO_T prGlueInfo = NULL;
  3816. ASSERT(prDev);
  3817. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3818. ASSERT(prGlueInfo);
  3819. DBGLOG(INIT, INFO, "mtk_p2p_wext_set_noa_param\n");
  3820. rStatus = kalIoctl(prGlueInfo, wlanoidSetNoaParam, prNoaParam, /* prP2PReq->aucBuffer, */
  3821. sizeof(PARAM_CUSTOM_NOA_PARAM_STRUCT_T), /* prP2PReq->inBufferLength, */
  3822. FALSE, FALSE, TRUE, TRUE, &u4SetInfoLen);
  3823. if (rStatus != WLAN_STATUS_SUCCESS)
  3824. return -EFAULT;
  3825. else
  3826. return 0;
  3827. }
  3828. /*----------------------------------------------------------------------------*/
  3829. /*!
  3830. * \brief P2P Private I/O Control handler for
  3831. *
  3832. * \param[in] prDev Net device requested.
  3833. * \param[inout] wrqu Pointer to iwreq_data
  3834. *
  3835. * \retval 0 Success.
  3836. * \retval -EFAULT Setting parameters to driver fail.
  3837. * \retval -EOPNOTSUPP Key size not supported.
  3838. *
  3839. * \note
  3840. */
  3841. /*----------------------------------------------------------------------------*/
  3842. int
  3843. mtk_p2p_wext_set_oppps_param(IN struct net_device *prDev,
  3844. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3845. {
  3846. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  3847. UINT_32 u4SetInfoLen;
  3848. /* P_IW_P2P_TRANSPORT_STRUCT prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT)extra; */
  3849. P_PARAM_CUSTOM_OPPPS_PARAM_STRUCT_T prOppPsParam = (P_PARAM_CUSTOM_OPPPS_PARAM_STRUCT_T) extra;
  3850. P_GLUE_INFO_T prGlueInfo = NULL;
  3851. ASSERT(prDev);
  3852. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3853. ASSERT(prGlueInfo);
  3854. DBGLOG(INIT, INFO, "mtk_p2p_wext_set_oppps_param\n");
  3855. rStatus = kalIoctl(prGlueInfo, wlanoidSetOppPsParam, prOppPsParam, /* prP2PReq->aucBuffer, */
  3856. sizeof(PARAM_CUSTOM_OPPPS_PARAM_STRUCT_T), /* prP2PReq->inBufferLength, */
  3857. FALSE, FALSE, TRUE, TRUE, &u4SetInfoLen);
  3858. if (rStatus != WLAN_STATUS_SUCCESS)
  3859. return -EFAULT;
  3860. else
  3861. return 0;
  3862. }
  3863. int
  3864. mtk_p2p_wext_set_p2p_version(IN struct net_device *prDev,
  3865. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3866. {
  3867. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  3868. P_GLUE_INFO_T prGlueInfo = NULL;
  3869. P_IW_P2P_TRANSPORT_STRUCT prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT) extra;
  3870. UINT_32 u4SetInfoLen;
  3871. ASSERT(prDev);
  3872. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3873. ASSERT(prGlueInfo);
  3874. rStatus = kalIoctl(prGlueInfo,
  3875. wlanoidSetP2pSupplicantVersion,
  3876. prP2PReq->aucBuffer, prP2PReq->inBufferLength, FALSE, FALSE, TRUE, TRUE, &u4SetInfoLen);
  3877. if (rStatus != WLAN_STATUS_SUCCESS)
  3878. return -EFAULT;
  3879. else
  3880. return rStatus;
  3881. }
  3882. /* mtk_p2p_wext_set_p2p_version */
  3883. int
  3884. mtk_p2p_wext_get_p2p_version(IN struct net_device *prDev,
  3885. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3886. {
  3887. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  3888. UINT_32 u4QueryInfoLen;
  3889. P_IW_P2P_TRANSPORT_STRUCT prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT) extra;
  3890. P_GLUE_INFO_T prGlueInfo = NULL;
  3891. ASSERT(prDev);
  3892. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3893. ASSERT(prGlueInfo);
  3894. rStatus = kalIoctl(prGlueInfo,
  3895. wlanoidQueryP2pVersion,
  3896. prP2PReq->aucBuffer, prP2PReq->outBufferLength, TRUE, FALSE, TRUE, TRUE, &u4QueryInfoLen);
  3897. if (rStatus != WLAN_STATUS_SUCCESS)
  3898. return -EFAULT;
  3899. else
  3900. return rStatus;
  3901. } /* mtk_p2p_wext_get_p2p_version */
  3902. #if CFG_SUPPORT_P2P_RSSI_QUERY
  3903. int
  3904. mtk_p2p_wext_get_rssi(IN struct net_device *prDev,
  3905. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3906. {
  3907. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  3908. UINT_32 u4QueryInfoLen;
  3909. struct iw_point *prData = (struct iw_point *)&wrqu->data;
  3910. UINT_16 u2BufferSize = 0;
  3911. P_GLUE_INFO_T prGlueInfo = NULL;
  3912. INT_32 i4Rssi;
  3913. struct iw_statistics *pStats = NULL;
  3914. ASSERT(prDev);
  3915. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3916. ASSERT(prGlueInfo);
  3917. if (!prGlueInfo) {
  3918. rStatus = WLAN_STATUS_FAILURE;
  3919. goto stat_out;
  3920. }
  3921. pStats = (struct iw_statistics *)(&(prGlueInfo->rP2pIwStats));
  3922. rStatus = kalIoctl(prGlueInfo,
  3923. wlanoidQueryP2pRssi, &i4Rssi, sizeof(i4Rssi), TRUE, TRUE, TRUE, TRUE, &u4QueryInfoLen);
  3924. u2BufferSize = prData->length;
  3925. if (u2BufferSize < sizeof(struct iw_statistics))
  3926. return -E2BIG;
  3927. if (copy_to_user(prData->pointer, pStats, sizeof(struct iw_statistics)))
  3928. rStatus = WLAN_STATUS_FAILURE;
  3929. stat_out:
  3930. if (rStatus != WLAN_STATUS_SUCCESS)
  3931. return -EFAULT;
  3932. else
  3933. return rStatus;
  3934. } /* mtk_p2p_wext_get_rssi */
  3935. struct iw_statistics *mtk_p2p_wext_get_wireless_stats(struct net_device *prDev)
  3936. {
  3937. WLAN_STATUS rStatus = WLAN_STATUS_FAILURE;
  3938. P_GLUE_INFO_T prGlueInfo = NULL;
  3939. struct iw_statistics *pStats = NULL;
  3940. INT_32 i4Rssi;
  3941. UINT_32 bufLen = 0;
  3942. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3943. ASSERT(prGlueInfo);
  3944. if (!prGlueInfo)
  3945. goto stat_out;
  3946. pStats = (struct iw_statistics *)(&(prGlueInfo->rP2pIwStats));
  3947. if (!prDev || !netif_carrier_ok(prDev)) {
  3948. /* network not connected */
  3949. goto stat_out;
  3950. }
  3951. rStatus = kalIoctl(prGlueInfo, wlanoidQueryP2pRssi, &i4Rssi, sizeof(i4Rssi), TRUE, TRUE, TRUE, TRUE, &bufLen);
  3952. stat_out:
  3953. return pStats;
  3954. } /* mtk_p2p_wext_get_wireless_stats */
  3955. #endif /* CFG_SUPPORT_P2P_RSSI_QUERY */
  3956. int
  3957. mtk_p2p_wext_set_txpow(IN struct net_device *prDev,
  3958. IN struct iw_request_info *prIwrInfo, IN OUT union iwreq_data *prTxPow, IN char *pcExtra)
  3959. {
  3960. P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T) NULL;
  3961. P_ADAPTER_T prAdapter = (P_ADAPTER_T) NULL;
  3962. #if 0
  3963. P_MSG_P2P_FUNCTION_SWITCH_T prMsgFuncSwitch = (P_MSG_P2P_FUNCTION_SWITCH_T) NULL;
  3964. #endif
  3965. int i4Ret = 0;
  3966. ASSERT(prDev);
  3967. ASSERT(prTxPow);
  3968. do {
  3969. if ((!prDev) || (!prTxPow)) {
  3970. i4Ret = -EINVAL;
  3971. break;
  3972. }
  3973. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3974. if (!prGlueInfo) {
  3975. i4Ret = -EINVAL;
  3976. break;
  3977. }
  3978. prAdapter = prGlueInfo->prAdapter;
  3979. #if 0
  3980. prMsgFuncSwitch =
  3981. (P_MSG_P2P_FUNCTION_SWITCH_T) cnmMemAlloc(prAdapter, RAM_TYPE_MSG,
  3982. sizeof(MSG_P2P_FUNCTION_SWITCH_T));
  3983. if (!prMsgFuncSwitch) {
  3984. ASSERT(0);
  3985. return -ENOMEM;
  3986. }
  3987. prMsgFuncSwitch->rMsgHdr.eMsgId = MID_MNY_P2P_FUN_SWITCH;
  3988. if (prTxPow->disabled) {
  3989. /* Dissolve. */
  3990. prMsgFuncSwitch->fgIsFuncOn = FALSE;
  3991. } else {
  3992. /* Re-enable function. */
  3993. prMsgFuncSwitch->fgIsFuncOn = TRUE;
  3994. }
  3995. /* 1.3 send message */
  3996. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prMsgFuncSwitch, MSG_SEND_METHOD_BUF);
  3997. #endif
  3998. } while (FALSE);
  3999. return i4Ret;
  4000. } /* mtk_p2p_wext_set_txpow */
  4001. #endif