gl_p2p.c 145 KB

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