rtw_p2p.c 163 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2017 Realtek Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. *****************************************************************************/
  15. #define _RTW_P2P_C_
  16. #include <drv_types.h>
  17. #ifdef CONFIG_P2P
  18. int rtw_p2p_is_channel_list_ok(u8 desired_ch, u8 *ch_list, u8 ch_cnt)
  19. {
  20. int found = 0, i = 0;
  21. for (i = 0; i < ch_cnt; i++) {
  22. if (ch_list[i] == desired_ch) {
  23. found = 1;
  24. break;
  25. }
  26. }
  27. return found ;
  28. }
  29. int is_any_client_associated(_adapter *padapter)
  30. {
  31. return padapter->stapriv.asoc_list_cnt ? _TRUE : _FALSE;
  32. }
  33. static u32 go_add_group_info_attr(struct wifidirect_info *pwdinfo, u8 *pbuf)
  34. {
  35. _irqL irqL;
  36. _list *phead, *plist;
  37. u32 len = 0;
  38. u16 attr_len = 0;
  39. u8 tmplen, *pdata_attr, *pstart, *pcur;
  40. struct sta_info *psta = NULL;
  41. _adapter *padapter = pwdinfo->padapter;
  42. struct sta_priv *pstapriv = &padapter->stapriv;
  43. RTW_INFO(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(padapter));
  44. pdata_attr = rtw_zmalloc(MAX_P2P_IE_LEN);
  45. if (NULL == pdata_attr) {
  46. RTW_INFO("%s pdata_attr malloc failed\n", __FUNCTION__);
  47. goto _exit;
  48. }
  49. pstart = pdata_attr;
  50. pcur = pdata_attr;
  51. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  52. phead = &pstapriv->asoc_list;
  53. plist = get_next(phead);
  54. /* look up sta asoc_queue */
  55. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  56. psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
  57. plist = get_next(plist);
  58. if (psta->is_p2p_device) {
  59. tmplen = 0;
  60. pcur++;
  61. /* P2P device address */
  62. _rtw_memcpy(pcur, psta->dev_addr, ETH_ALEN);
  63. pcur += ETH_ALEN;
  64. /* P2P interface address */
  65. _rtw_memcpy(pcur, psta->cmn.mac_addr, ETH_ALEN);
  66. pcur += ETH_ALEN;
  67. *pcur = psta->dev_cap;
  68. pcur++;
  69. /* *(u16*)(pcur) = cpu_to_be16(psta->config_methods); */
  70. RTW_PUT_BE16(pcur, psta->config_methods);
  71. pcur += 2;
  72. _rtw_memcpy(pcur, psta->primary_dev_type, 8);
  73. pcur += 8;
  74. *pcur = psta->num_of_secdev_type;
  75. pcur++;
  76. _rtw_memcpy(pcur, psta->secdev_types_list, psta->num_of_secdev_type * 8);
  77. pcur += psta->num_of_secdev_type * 8;
  78. if (psta->dev_name_len > 0) {
  79. /* *(u16*)(pcur) = cpu_to_be16( WPS_ATTR_DEVICE_NAME ); */
  80. RTW_PUT_BE16(pcur, WPS_ATTR_DEVICE_NAME);
  81. pcur += 2;
  82. /* *(u16*)(pcur) = cpu_to_be16( psta->dev_name_len ); */
  83. RTW_PUT_BE16(pcur, psta->dev_name_len);
  84. pcur += 2;
  85. _rtw_memcpy(pcur, psta->dev_name, psta->dev_name_len);
  86. pcur += psta->dev_name_len;
  87. }
  88. tmplen = (u8)(pcur - pstart);
  89. *pstart = (tmplen - 1);
  90. attr_len += tmplen;
  91. /* pstart += tmplen; */
  92. pstart = pcur;
  93. }
  94. }
  95. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  96. if (attr_len > 0)
  97. len = rtw_set_p2p_attr_content(pbuf, P2P_ATTR_GROUP_INFO, attr_len, pdata_attr);
  98. rtw_mfree(pdata_attr, MAX_P2P_IE_LEN);
  99. _exit:
  100. return len;
  101. }
  102. static void issue_group_disc_req(struct wifidirect_info *pwdinfo, u8 *da)
  103. {
  104. struct xmit_frame *pmgntframe;
  105. struct pkt_attrib *pattrib;
  106. unsigned char *pframe;
  107. struct rtw_ieee80211_hdr *pwlanhdr;
  108. unsigned short *fctrl;
  109. _adapter *padapter = pwdinfo->padapter;
  110. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  111. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  112. unsigned char category = RTW_WLAN_CATEGORY_P2P;/* P2P action frame */
  113. u32 p2poui = cpu_to_be32(P2POUI);
  114. u8 oui_subtype = P2P_GO_DISC_REQUEST;
  115. u8 dialogToken = 0;
  116. RTW_INFO("[%s]\n", __FUNCTION__);
  117. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  118. if (pmgntframe == NULL)
  119. return;
  120. /* update attribute */
  121. pattrib = &pmgntframe->attrib;
  122. update_mgntframe_attrib(padapter, pattrib);
  123. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  124. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  125. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  126. fctrl = &(pwlanhdr->frame_ctl);
  127. *(fctrl) = 0;
  128. _rtw_memcpy(pwlanhdr->addr1, da, ETH_ALEN);
  129. _rtw_memcpy(pwlanhdr->addr2, pwdinfo->interface_addr, ETH_ALEN);
  130. _rtw_memcpy(pwlanhdr->addr3, pwdinfo->interface_addr, ETH_ALEN);
  131. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  132. pmlmeext->mgnt_seq++;
  133. set_frame_sub_type(pframe, WIFI_ACTION);
  134. pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
  135. pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
  136. /* Build P2P action frame header */
  137. pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
  138. pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *) &(p2poui), &(pattrib->pktlen));
  139. pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
  140. pframe = rtw_set_fixed_ie(pframe, 1, &(dialogToken), &(pattrib->pktlen));
  141. /* there is no IE in this P2P action frame */
  142. pattrib->last_txcmdsz = pattrib->pktlen;
  143. dump_mgntframe(padapter, pmgntframe);
  144. }
  145. static void issue_p2p_devdisc_resp(struct wifidirect_info *pwdinfo, u8 *da, u8 status, u8 dialogToken)
  146. {
  147. struct xmit_frame *pmgntframe;
  148. struct pkt_attrib *pattrib;
  149. unsigned char *pframe;
  150. struct rtw_ieee80211_hdr *pwlanhdr;
  151. unsigned short *fctrl;
  152. _adapter *padapter = pwdinfo->padapter;
  153. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  154. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  155. unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
  156. u8 action = P2P_PUB_ACTION_ACTION;
  157. u32 p2poui = cpu_to_be32(P2POUI);
  158. u8 oui_subtype = P2P_DEVDISC_RESP;
  159. u8 p2pie[8] = { 0x00 };
  160. u32 p2pielen = 0;
  161. RTW_INFO("[%s]\n", __FUNCTION__);
  162. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  163. if (pmgntframe == NULL)
  164. return;
  165. /* update attribute */
  166. pattrib = &pmgntframe->attrib;
  167. update_mgntframe_attrib(padapter, pattrib);
  168. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  169. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  170. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  171. fctrl = &(pwlanhdr->frame_ctl);
  172. *(fctrl) = 0;
  173. _rtw_memcpy(pwlanhdr->addr1, da, ETH_ALEN);
  174. _rtw_memcpy(pwlanhdr->addr2, pwdinfo->device_addr, ETH_ALEN);
  175. _rtw_memcpy(pwlanhdr->addr3, pwdinfo->device_addr, ETH_ALEN);
  176. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  177. pmlmeext->mgnt_seq++;
  178. set_frame_sub_type(pframe, WIFI_ACTION);
  179. pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
  180. pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
  181. /* Build P2P public action frame header */
  182. pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
  183. pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
  184. pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *) &(p2poui), &(pattrib->pktlen));
  185. pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
  186. pframe = rtw_set_fixed_ie(pframe, 1, &(dialogToken), &(pattrib->pktlen));
  187. /* Build P2P IE */
  188. /* P2P OUI */
  189. p2pielen = 0;
  190. p2pie[p2pielen++] = 0x50;
  191. p2pie[p2pielen++] = 0x6F;
  192. p2pie[p2pielen++] = 0x9A;
  193. p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
  194. /* P2P_ATTR_STATUS */
  195. p2pielen += rtw_set_p2p_attr_content(&p2pie[p2pielen], P2P_ATTR_STATUS, 1, &status);
  196. pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, p2pie, &pattrib->pktlen);
  197. pattrib->last_txcmdsz = pattrib->pktlen;
  198. dump_mgntframe(padapter, pmgntframe);
  199. }
  200. static void issue_p2p_provision_resp(struct wifidirect_info *pwdinfo, u8 *raddr, u8 *frame_body, u16 config_method)
  201. {
  202. _adapter *padapter = pwdinfo->padapter;
  203. unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
  204. u8 action = P2P_PUB_ACTION_ACTION;
  205. u8 dialogToken = frame_body[7]; /* The Dialog Token of provisioning discovery request frame. */
  206. u32 p2poui = cpu_to_be32(P2POUI);
  207. u8 oui_subtype = P2P_PROVISION_DISC_RESP;
  208. u8 wpsie[100] = { 0x00 };
  209. u8 wpsielen = 0;
  210. #ifdef CONFIG_WFD
  211. u32 wfdielen = 0;
  212. #endif
  213. struct xmit_frame *pmgntframe;
  214. struct pkt_attrib *pattrib;
  215. unsigned char *pframe;
  216. struct rtw_ieee80211_hdr *pwlanhdr;
  217. unsigned short *fctrl;
  218. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  219. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  220. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  221. if (pmgntframe == NULL)
  222. return;
  223. /* update attribute */
  224. pattrib = &pmgntframe->attrib;
  225. update_mgntframe_attrib(padapter, pattrib);
  226. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  227. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  228. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  229. fctrl = &(pwlanhdr->frame_ctl);
  230. *(fctrl) = 0;
  231. _rtw_memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
  232. _rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(padapter), ETH_ALEN);
  233. _rtw_memcpy(pwlanhdr->addr3, adapter_mac_addr(padapter), ETH_ALEN);
  234. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  235. pmlmeext->mgnt_seq++;
  236. set_frame_sub_type(pframe, WIFI_ACTION);
  237. pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
  238. pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
  239. pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
  240. pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
  241. pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *) &(p2poui), &(pattrib->pktlen));
  242. pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
  243. pframe = rtw_set_fixed_ie(pframe, 1, &(dialogToken), &(pattrib->pktlen));
  244. wpsielen = 0;
  245. /* WPS OUI */
  246. /* *(u32*) ( wpsie ) = cpu_to_be32( WPSOUI ); */
  247. RTW_PUT_BE32(wpsie, WPSOUI);
  248. wpsielen += 4;
  249. #if 0
  250. /* WPS version */
  251. /* Type: */
  252. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_VER1);
  253. wpsielen += 2;
  254. /* Length: */
  255. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
  256. wpsielen += 2;
  257. /* Value: */
  258. wpsie[wpsielen++] = WPS_VERSION_1; /* Version 1.0 */
  259. #endif
  260. /* Config Method */
  261. /* Type: */
  262. /* *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_ATTR_CONF_METHOD ); */
  263. RTW_PUT_BE16(wpsie + wpsielen, WPS_ATTR_CONF_METHOD);
  264. wpsielen += 2;
  265. /* Length: */
  266. /* *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( 0x0002 ); */
  267. RTW_PUT_BE16(wpsie + wpsielen, 0x0002);
  268. wpsielen += 2;
  269. /* Value: */
  270. /* *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( config_method ); */
  271. RTW_PUT_BE16(wpsie + wpsielen, config_method);
  272. wpsielen += 2;
  273. pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wpsielen, (unsigned char *) wpsie, &pattrib->pktlen);
  274. #ifdef CONFIG_WFD
  275. wfdielen = build_provdisc_resp_wfd_ie(pwdinfo, pframe);
  276. pframe += wfdielen;
  277. pattrib->pktlen += wfdielen;
  278. #endif
  279. pattrib->last_txcmdsz = pattrib->pktlen;
  280. dump_mgntframe(padapter, pmgntframe);
  281. return;
  282. }
  283. static void issue_p2p_presence_resp(struct wifidirect_info *pwdinfo, u8 *da, u8 status, u8 dialogToken)
  284. {
  285. struct xmit_frame *pmgntframe;
  286. struct pkt_attrib *pattrib;
  287. unsigned char *pframe;
  288. struct rtw_ieee80211_hdr *pwlanhdr;
  289. unsigned short *fctrl;
  290. _adapter *padapter = pwdinfo->padapter;
  291. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  292. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  293. unsigned char category = RTW_WLAN_CATEGORY_P2P;/* P2P action frame */
  294. u32 p2poui = cpu_to_be32(P2POUI);
  295. u8 oui_subtype = P2P_PRESENCE_RESPONSE;
  296. u8 p2pie[MAX_P2P_IE_LEN] = { 0x00 };
  297. u8 noa_attr_content[32] = { 0x00 };
  298. u32 p2pielen = 0;
  299. RTW_INFO("[%s]\n", __FUNCTION__);
  300. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  301. if (pmgntframe == NULL)
  302. return;
  303. /* update attribute */
  304. pattrib = &pmgntframe->attrib;
  305. update_mgntframe_attrib(padapter, pattrib);
  306. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  307. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  308. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  309. fctrl = &(pwlanhdr->frame_ctl);
  310. *(fctrl) = 0;
  311. _rtw_memcpy(pwlanhdr->addr1, da, ETH_ALEN);
  312. _rtw_memcpy(pwlanhdr->addr2, pwdinfo->interface_addr, ETH_ALEN);
  313. _rtw_memcpy(pwlanhdr->addr3, pwdinfo->interface_addr, ETH_ALEN);
  314. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  315. pmlmeext->mgnt_seq++;
  316. set_frame_sub_type(pframe, WIFI_ACTION);
  317. pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
  318. pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
  319. /* Build P2P action frame header */
  320. pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
  321. pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *) &(p2poui), &(pattrib->pktlen));
  322. pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
  323. pframe = rtw_set_fixed_ie(pframe, 1, &(dialogToken), &(pattrib->pktlen));
  324. /* Add P2P IE header */
  325. /* P2P OUI */
  326. p2pielen = 0;
  327. p2pie[p2pielen++] = 0x50;
  328. p2pie[p2pielen++] = 0x6F;
  329. p2pie[p2pielen++] = 0x9A;
  330. p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
  331. /* Add Status attribute in P2P IE */
  332. p2pielen += rtw_set_p2p_attr_content(&p2pie[p2pielen], P2P_ATTR_STATUS, 1, &status);
  333. /* Add NoA attribute in P2P IE */
  334. noa_attr_content[0] = 0x1;/* index */
  335. noa_attr_content[1] = 0x0;/* CTWindow and OppPS Parameters */
  336. /* todo: Notice of Absence Descriptor(s) */
  337. p2pielen += rtw_set_p2p_attr_content(&p2pie[p2pielen], P2P_ATTR_NOA, 2, noa_attr_content);
  338. pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, p2pie, &(pattrib->pktlen));
  339. pattrib->last_txcmdsz = pattrib->pktlen;
  340. dump_mgntframe(padapter, pmgntframe);
  341. }
  342. u32 build_beacon_p2p_ie(struct wifidirect_info *pwdinfo, u8 *pbuf)
  343. {
  344. u8 p2pie[MAX_P2P_IE_LEN] = { 0x00 };
  345. u16 capability = 0;
  346. u32 len = 0, p2pielen = 0;
  347. /* P2P OUI */
  348. p2pielen = 0;
  349. p2pie[p2pielen++] = 0x50;
  350. p2pie[p2pielen++] = 0x6F;
  351. p2pie[p2pielen++] = 0x9A;
  352. p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
  353. /* According to the P2P Specification, the beacon frame should contain 3 P2P attributes */
  354. /* 1. P2P Capability */
  355. /* 2. P2P Device ID */
  356. /* 3. Notice of Absence ( NOA ) */
  357. /* P2P Capability ATTR */
  358. /* Type: */
  359. /* Length: */
  360. /* Value: */
  361. /* Device Capability Bitmap, 1 byte */
  362. /* Be able to participate in additional P2P Groups and */
  363. /* support the P2P Invitation Procedure */
  364. /* Group Capability Bitmap, 1 byte */
  365. capability = P2P_DEVCAP_INVITATION_PROC | P2P_DEVCAP_CLIENT_DISCOVERABILITY;
  366. capability |= ((P2P_GRPCAP_GO | P2P_GRPCAP_INTRABSS) << 8);
  367. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_PROVISIONING_ING))
  368. capability |= (P2P_GRPCAP_GROUP_FORMATION << 8);
  369. capability = cpu_to_le16(capability);
  370. p2pielen += rtw_set_p2p_attr_content(&p2pie[p2pielen], P2P_ATTR_CAPABILITY, 2, (u8 *)&capability);
  371. /* P2P Device ID ATTR */
  372. p2pielen += rtw_set_p2p_attr_content(&p2pie[p2pielen], P2P_ATTR_DEVICE_ID, ETH_ALEN, pwdinfo->device_addr);
  373. /* Notice of Absence ATTR */
  374. /* Type: */
  375. /* Length: */
  376. /* Value: */
  377. /* go_add_noa_attr(pwdinfo); */
  378. pbuf = rtw_set_ie(pbuf, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *) p2pie, &len);
  379. return len;
  380. }
  381. #ifdef CONFIG_WFD
  382. u32 build_beacon_wfd_ie(struct wifidirect_info *pwdinfo, u8 *pbuf)
  383. {
  384. u8 wfdie[MAX_WFD_IE_LEN] = { 0x00 };
  385. u16 val16 = 0;
  386. u32 len = 0, wfdielen = 0;
  387. _adapter *padapter = pwdinfo->padapter;
  388. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  389. struct wifi_display_info *pwfd_info = padapter->wdinfo.wfd_info;
  390. if (!hal_chk_wl_func(padapter, WL_FUNC_MIRACAST))
  391. goto exit;
  392. /* WFD OUI */
  393. wfdielen = 0;
  394. wfdie[wfdielen++] = 0x50;
  395. wfdie[wfdielen++] = 0x6F;
  396. wfdie[wfdielen++] = 0x9A;
  397. wfdie[wfdielen++] = 0x0A; /* WFA WFD v1.0 */
  398. /* Commented by Albert 20110812 */
  399. /* According to the WFD Specification, the beacon frame should contain 4 WFD attributes */
  400. /* 1. WFD Device Information */
  401. /* 2. Associated BSSID */
  402. /* 3. Coupled Sink Information */
  403. /* WFD Device Information ATTR */
  404. /* Type: */
  405. wfdie[wfdielen++] = WFD_ATTR_DEVICE_INFO;
  406. /* Length: */
  407. /* Note: In the WFD specification, the size of length field is 2. */
  408. RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
  409. wfdielen += 2;
  410. /* Value1: */
  411. /* WFD device information */
  412. if (P2P_ROLE_GO == pwdinfo->role) {
  413. if (is_any_client_associated(pwdinfo->padapter)) {
  414. /* WFD primary sink + WiFi Direct mode + WSD (WFD Service Discovery) */
  415. val16 = pwfd_info->wfd_device_type | WFD_DEVINFO_WSD;
  416. RTW_PUT_BE16(wfdie + wfdielen, val16);
  417. } else {
  418. /* WFD primary sink + available for WFD session + WiFi Direct mode + WSD (WFD Service Discovery) */
  419. val16 = pwfd_info->wfd_device_type | WFD_DEVINFO_SESSION_AVAIL | WFD_DEVINFO_WSD;
  420. RTW_PUT_BE16(wfdie + wfdielen, val16);
  421. }
  422. } else {
  423. /* WFD primary sink + available for WFD session + WiFi Direct mode + WSD ( WFD Service Discovery ) */
  424. val16 = pwfd_info->wfd_device_type | WFD_DEVINFO_SESSION_AVAIL | WFD_DEVINFO_WSD;
  425. RTW_PUT_BE16(wfdie + wfdielen, val16);
  426. }
  427. wfdielen += 2;
  428. /* Value2: */
  429. /* Session Management Control Port */
  430. /* Default TCP port for RTSP messages is 554 */
  431. RTW_PUT_BE16(wfdie + wfdielen, pwfd_info->rtsp_ctrlport);
  432. wfdielen += 2;
  433. /* Value3: */
  434. /* WFD Device Maximum Throughput */
  435. /* 300Mbps is the maximum throughput */
  436. RTW_PUT_BE16(wfdie + wfdielen, 300);
  437. wfdielen += 2;
  438. /* Associated BSSID ATTR */
  439. /* Type: */
  440. wfdie[wfdielen++] = WFD_ATTR_ASSOC_BSSID;
  441. /* Length: */
  442. /* Note: In the WFD specification, the size of length field is 2. */
  443. RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
  444. wfdielen += 2;
  445. /* Value: */
  446. /* Associated BSSID */
  447. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  448. _rtw_memcpy(wfdie + wfdielen, &pmlmepriv->assoc_bssid[0], ETH_ALEN);
  449. else
  450. _rtw_memset(wfdie + wfdielen, 0x00, ETH_ALEN);
  451. wfdielen += ETH_ALEN;
  452. /* Coupled Sink Information ATTR */
  453. /* Type: */
  454. wfdie[wfdielen++] = WFD_ATTR_COUPLED_SINK_INFO;
  455. /* Length: */
  456. /* Note: In the WFD specification, the size of length field is 2. */
  457. RTW_PUT_BE16(wfdie + wfdielen, 0x0007);
  458. wfdielen += 2;
  459. /* Value: */
  460. /* Coupled Sink Status bitmap */
  461. /* Not coupled/available for Coupling */
  462. wfdie[wfdielen++] = 0;
  463. /* MAC Addr. */
  464. wfdie[wfdielen++] = 0;
  465. wfdie[wfdielen++] = 0;
  466. wfdie[wfdielen++] = 0;
  467. wfdie[wfdielen++] = 0;
  468. wfdie[wfdielen++] = 0;
  469. wfdie[wfdielen++] = 0;
  470. rtw_set_ie(pbuf, _VENDOR_SPECIFIC_IE_, wfdielen, (unsigned char *) wfdie, &len);
  471. exit:
  472. return len;
  473. }
  474. u32 build_probe_req_wfd_ie(struct wifidirect_info *pwdinfo, u8 *pbuf)
  475. {
  476. u8 wfdie[MAX_WFD_IE_LEN] = { 0x00 };
  477. u16 val16 = 0;
  478. u32 len = 0, wfdielen = 0;
  479. _adapter *padapter = pwdinfo->padapter;
  480. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  481. struct wifi_display_info *pwfd_info = padapter->wdinfo.wfd_info;
  482. if (!hal_chk_wl_func(padapter, WL_FUNC_MIRACAST))
  483. goto exit;
  484. /* WFD OUI */
  485. wfdielen = 0;
  486. wfdie[wfdielen++] = 0x50;
  487. wfdie[wfdielen++] = 0x6F;
  488. wfdie[wfdielen++] = 0x9A;
  489. wfdie[wfdielen++] = 0x0A; /* WFA WFD v1.0 */
  490. /* Commented by Albert 20110812 */
  491. /* According to the WFD Specification, the probe request frame should contain 4 WFD attributes */
  492. /* 1. WFD Device Information */
  493. /* 2. Associated BSSID */
  494. /* 3. Coupled Sink Information */
  495. /* WFD Device Information ATTR */
  496. /* Type: */
  497. wfdie[wfdielen++] = WFD_ATTR_DEVICE_INFO;
  498. /* Length: */
  499. /* Note: In the WFD specification, the size of length field is 2. */
  500. RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
  501. wfdielen += 2;
  502. /* Value1: */
  503. /* WFD device information */
  504. if (1 == pwdinfo->wfd_tdls_enable) {
  505. /* WFD primary sink + available for WFD session + WiFi TDLS mode + WSC ( WFD Service Discovery ) */
  506. val16 = pwfd_info->wfd_device_type |
  507. WFD_DEVINFO_SESSION_AVAIL |
  508. WFD_DEVINFO_WSD |
  509. WFD_DEVINFO_PC_TDLS;
  510. RTW_PUT_BE16(wfdie + wfdielen, val16);
  511. } else {
  512. /* WFD primary sink + available for WFD session + WiFi Direct mode + WSC ( WFD Service Discovery ) */
  513. val16 = pwfd_info->wfd_device_type |
  514. WFD_DEVINFO_SESSION_AVAIL |
  515. WFD_DEVINFO_WSD;
  516. RTW_PUT_BE16(wfdie + wfdielen, val16);
  517. }
  518. wfdielen += 2;
  519. /* Value2: */
  520. /* Session Management Control Port */
  521. /* Default TCP port for RTSP messages is 554 */
  522. RTW_PUT_BE16(wfdie + wfdielen, pwfd_info->rtsp_ctrlport);
  523. wfdielen += 2;
  524. /* Value3: */
  525. /* WFD Device Maximum Throughput */
  526. /* 300Mbps is the maximum throughput */
  527. RTW_PUT_BE16(wfdie + wfdielen, 300);
  528. wfdielen += 2;
  529. /* Associated BSSID ATTR */
  530. /* Type: */
  531. wfdie[wfdielen++] = WFD_ATTR_ASSOC_BSSID;
  532. /* Length: */
  533. /* Note: In the WFD specification, the size of length field is 2. */
  534. RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
  535. wfdielen += 2;
  536. /* Value: */
  537. /* Associated BSSID */
  538. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  539. _rtw_memcpy(wfdie + wfdielen, &pmlmepriv->assoc_bssid[0], ETH_ALEN);
  540. else
  541. _rtw_memset(wfdie + wfdielen, 0x00, ETH_ALEN);
  542. wfdielen += ETH_ALEN;
  543. /* Coupled Sink Information ATTR */
  544. /* Type: */
  545. wfdie[wfdielen++] = WFD_ATTR_COUPLED_SINK_INFO;
  546. /* Length: */
  547. /* Note: In the WFD specification, the size of length field is 2. */
  548. RTW_PUT_BE16(wfdie + wfdielen, 0x0007);
  549. wfdielen += 2;
  550. /* Value: */
  551. /* Coupled Sink Status bitmap */
  552. /* Not coupled/available for Coupling */
  553. wfdie[wfdielen++] = 0;
  554. /* MAC Addr. */
  555. wfdie[wfdielen++] = 0;
  556. wfdie[wfdielen++] = 0;
  557. wfdie[wfdielen++] = 0;
  558. wfdie[wfdielen++] = 0;
  559. wfdie[wfdielen++] = 0;
  560. wfdie[wfdielen++] = 0;
  561. rtw_set_ie(pbuf, _VENDOR_SPECIFIC_IE_, wfdielen, (unsigned char *) wfdie, &len);
  562. exit:
  563. return len;
  564. }
  565. u32 build_probe_resp_wfd_ie(struct wifidirect_info *pwdinfo, u8 *pbuf, u8 tunneled)
  566. {
  567. u8 wfdie[MAX_WFD_IE_LEN] = { 0x00 };
  568. u32 len = 0, wfdielen = 0;
  569. _adapter *padapter = pwdinfo->padapter;
  570. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  571. struct wifi_display_info *pwfd_info = padapter->wdinfo.wfd_info;
  572. u16 v16 = 0;
  573. if (!hal_chk_wl_func(padapter, WL_FUNC_MIRACAST))
  574. goto exit;
  575. /* WFD OUI */
  576. wfdielen = 0;
  577. wfdie[wfdielen++] = 0x50;
  578. wfdie[wfdielen++] = 0x6F;
  579. wfdie[wfdielen++] = 0x9A;
  580. wfdie[wfdielen++] = 0x0A; /* WFA WFD v1.0 */
  581. /* Commented by Albert 20110812 */
  582. /* According to the WFD Specification, the probe response frame should contain 4 WFD attributes */
  583. /* 1. WFD Device Information */
  584. /* 2. Associated BSSID */
  585. /* 3. Coupled Sink Information */
  586. /* 4. WFD Session Information */
  587. /* WFD Device Information ATTR */
  588. /* Type: */
  589. wfdie[wfdielen++] = WFD_ATTR_DEVICE_INFO;
  590. /* Length: */
  591. /* Note: In the WFD specification, the size of length field is 2. */
  592. RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
  593. wfdielen += 2;
  594. /* Value1: */
  595. /* WFD device information */
  596. /* WFD primary sink + available for WFD session + WiFi Direct mode */
  597. if (_TRUE == pwdinfo->session_available) {
  598. if (P2P_ROLE_GO == pwdinfo->role) {
  599. if (is_any_client_associated(pwdinfo->padapter)) {
  600. if (pwdinfo->wfd_tdls_enable) {
  601. /* TDLS mode + WSD ( WFD Service Discovery ) */
  602. v16 = pwfd_info->wfd_device_type | WFD_DEVINFO_WSD | WFD_DEVINFO_PC_TDLS | WFD_DEVINFO_HDCP_SUPPORT;
  603. RTW_PUT_BE16(wfdie + wfdielen, v16);
  604. } else {
  605. /* WiFi Direct mode + WSD ( WFD Service Discovery ) */
  606. v16 = pwfd_info->wfd_device_type | WFD_DEVINFO_WSD | WFD_DEVINFO_HDCP_SUPPORT;
  607. RTW_PUT_BE16(wfdie + wfdielen, v16);
  608. }
  609. } else {
  610. if (pwdinfo->wfd_tdls_enable) {
  611. /* available for WFD session + TDLS mode + WSD ( WFD Service Discovery ) */
  612. v16 = pwfd_info->wfd_device_type | WFD_DEVINFO_SESSION_AVAIL | WFD_DEVINFO_WSD | WFD_DEVINFO_PC_TDLS | WFD_DEVINFO_HDCP_SUPPORT;
  613. RTW_PUT_BE16(wfdie + wfdielen, v16);
  614. } else {
  615. /* available for WFD session + WiFi Direct mode + WSD ( WFD Service Discovery ) */
  616. v16 = pwfd_info->wfd_device_type | WFD_DEVINFO_SESSION_AVAIL | WFD_DEVINFO_WSD | WFD_DEVINFO_HDCP_SUPPORT;
  617. RTW_PUT_BE16(wfdie + wfdielen, v16);
  618. }
  619. }
  620. } else {
  621. if (pwdinfo->wfd_tdls_enable) {
  622. /* available for WFD session + WiFi Direct mode + WSD ( WFD Service Discovery ) */
  623. v16 = pwfd_info->wfd_device_type | WFD_DEVINFO_SESSION_AVAIL | WFD_DEVINFO_WSD | WFD_DEVINFO_PC_TDLS | WFD_DEVINFO_HDCP_SUPPORT;
  624. RTW_PUT_BE16(wfdie + wfdielen, v16);
  625. } else {
  626. /* available for WFD session + WiFi Direct mode + WSD ( WFD Service Discovery ) */
  627. v16 = pwfd_info->wfd_device_type | WFD_DEVINFO_SESSION_AVAIL | WFD_DEVINFO_WSD | WFD_DEVINFO_HDCP_SUPPORT;
  628. RTW_PUT_BE16(wfdie + wfdielen, v16);
  629. }
  630. }
  631. } else {
  632. if (pwdinfo->wfd_tdls_enable) {
  633. v16 = pwfd_info->wfd_device_type | WFD_DEVINFO_WSD | WFD_DEVINFO_PC_TDLS | WFD_DEVINFO_HDCP_SUPPORT;
  634. RTW_PUT_BE16(wfdie + wfdielen, v16);
  635. } else {
  636. v16 = pwfd_info->wfd_device_type | WFD_DEVINFO_WSD | WFD_DEVINFO_HDCP_SUPPORT;
  637. RTW_PUT_BE16(wfdie + wfdielen, v16);
  638. }
  639. }
  640. wfdielen += 2;
  641. /* Value2: */
  642. /* Session Management Control Port */
  643. /* Default TCP port for RTSP messages is 554 */
  644. RTW_PUT_BE16(wfdie + wfdielen, pwfd_info->rtsp_ctrlport);
  645. wfdielen += 2;
  646. /* Value3: */
  647. /* WFD Device Maximum Throughput */
  648. /* 300Mbps is the maximum throughput */
  649. RTW_PUT_BE16(wfdie + wfdielen, 300);
  650. wfdielen += 2;
  651. /* Associated BSSID ATTR */
  652. /* Type: */
  653. wfdie[wfdielen++] = WFD_ATTR_ASSOC_BSSID;
  654. /* Length: */
  655. /* Note: In the WFD specification, the size of length field is 2. */
  656. RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
  657. wfdielen += 2;
  658. /* Value: */
  659. /* Associated BSSID */
  660. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  661. _rtw_memcpy(wfdie + wfdielen, &pmlmepriv->assoc_bssid[0], ETH_ALEN);
  662. else
  663. _rtw_memset(wfdie + wfdielen, 0x00, ETH_ALEN);
  664. wfdielen += ETH_ALEN;
  665. /* Coupled Sink Information ATTR */
  666. /* Type: */
  667. wfdie[wfdielen++] = WFD_ATTR_COUPLED_SINK_INFO;
  668. /* Length: */
  669. /* Note: In the WFD specification, the size of length field is 2. */
  670. RTW_PUT_BE16(wfdie + wfdielen, 0x0007);
  671. wfdielen += 2;
  672. /* Value: */
  673. /* Coupled Sink Status bitmap */
  674. /* Not coupled/available for Coupling */
  675. wfdie[wfdielen++] = 0;
  676. /* MAC Addr. */
  677. wfdie[wfdielen++] = 0;
  678. wfdie[wfdielen++] = 0;
  679. wfdie[wfdielen++] = 0;
  680. wfdie[wfdielen++] = 0;
  681. wfdie[wfdielen++] = 0;
  682. wfdie[wfdielen++] = 0;
  683. if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
  684. /* WFD Session Information ATTR */
  685. /* Type: */
  686. wfdie[wfdielen++] = WFD_ATTR_SESSION_INFO;
  687. /* Length: */
  688. /* Note: In the WFD specification, the size of length field is 2. */
  689. RTW_PUT_BE16(wfdie + wfdielen, 0x0000);
  690. wfdielen += 2;
  691. /* Todo: to add the list of WFD device info descriptor in WFD group. */
  692. }
  693. #ifdef CONFIG_CONCURRENT_MODE
  694. #ifdef CONFIG_TDLS
  695. {
  696. int i;
  697. _adapter *iface = NULL;
  698. struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
  699. for (i = 0; i < dvobj->iface_nums; i++) {
  700. iface = dvobj->padapters[i];
  701. if ((iface) && rtw_is_adapter_up(iface)) {
  702. if (iface == padapter)
  703. continue;
  704. if ((tunneled == 0) && (iface->wdinfo.wfd_tdls_enable == 1)) {
  705. /* Alternative MAC Address ATTR
  706. Type: */
  707. wfdie[wfdielen++] = WFD_ATTR_ALTER_MAC;
  708. /* Length:
  709. Note: In the WFD specification, the size of length field is 2.*/
  710. RTW_PUT_BE16(wfdie + wfdielen, ETH_ALEN);
  711. wfdielen += 2;
  712. /* Value:
  713. Alternative MAC Address*/
  714. _rtw_memcpy(wfdie + wfdielen, adapter_mac_addr(iface), ETH_ALEN);
  715. wfdielen += ETH_ALEN;
  716. }
  717. }
  718. }
  719. }
  720. #endif /* CONFIG_TDLS*/
  721. #endif /* CONFIG_CONCURRENT_MODE */
  722. pbuf = rtw_set_ie(pbuf, _VENDOR_SPECIFIC_IE_, wfdielen, (unsigned char *) wfdie, &len);
  723. exit:
  724. return len;
  725. }
  726. u32 build_assoc_req_wfd_ie(struct wifidirect_info *pwdinfo, u8 *pbuf)
  727. {
  728. u8 wfdie[MAX_WFD_IE_LEN] = { 0x00 };
  729. u16 val16 = 0;
  730. u32 len = 0, wfdielen = 0;
  731. _adapter *padapter = NULL;
  732. struct mlme_priv *pmlmepriv = NULL;
  733. struct wifi_display_info *pwfd_info = NULL;
  734. padapter = pwdinfo->padapter;
  735. pmlmepriv = &padapter->mlmepriv;
  736. pwfd_info = padapter->wdinfo.wfd_info;
  737. if (!hal_chk_wl_func(padapter, WL_FUNC_MIRACAST))
  738. goto exit;
  739. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE) || rtw_p2p_chk_state(pwdinfo, P2P_STATE_IDLE))
  740. goto exit;
  741. /* WFD OUI */
  742. wfdielen = 0;
  743. wfdie[wfdielen++] = 0x50;
  744. wfdie[wfdielen++] = 0x6F;
  745. wfdie[wfdielen++] = 0x9A;
  746. wfdie[wfdielen++] = 0x0A; /* WFA WFD v1.0 */
  747. /* Commented by Albert 20110812 */
  748. /* According to the WFD Specification, the probe request frame should contain 4 WFD attributes */
  749. /* 1. WFD Device Information */
  750. /* 2. Associated BSSID */
  751. /* 3. Coupled Sink Information */
  752. /* WFD Device Information ATTR */
  753. /* Type: */
  754. wfdie[wfdielen++] = WFD_ATTR_DEVICE_INFO;
  755. /* Length: */
  756. /* Note: In the WFD specification, the size of length field is 2. */
  757. RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
  758. wfdielen += 2;
  759. /* Value1: */
  760. /* WFD device information */
  761. /* WFD primary sink + available for WFD session + WiFi Direct mode + WSD ( WFD Service Discovery ) */
  762. val16 = pwfd_info->wfd_device_type | WFD_DEVINFO_SESSION_AVAIL | WFD_DEVINFO_WSD;
  763. RTW_PUT_BE16(wfdie + wfdielen, val16);
  764. wfdielen += 2;
  765. /* Value2: */
  766. /* Session Management Control Port */
  767. /* Default TCP port for RTSP messages is 554 */
  768. RTW_PUT_BE16(wfdie + wfdielen, pwfd_info->rtsp_ctrlport);
  769. wfdielen += 2;
  770. /* Value3: */
  771. /* WFD Device Maximum Throughput */
  772. /* 300Mbps is the maximum throughput */
  773. RTW_PUT_BE16(wfdie + wfdielen, 300);
  774. wfdielen += 2;
  775. /* Associated BSSID ATTR */
  776. /* Type: */
  777. wfdie[wfdielen++] = WFD_ATTR_ASSOC_BSSID;
  778. /* Length: */
  779. /* Note: In the WFD specification, the size of length field is 2. */
  780. RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
  781. wfdielen += 2;
  782. /* Value: */
  783. /* Associated BSSID */
  784. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  785. _rtw_memcpy(wfdie + wfdielen, &pmlmepriv->assoc_bssid[0], ETH_ALEN);
  786. else
  787. _rtw_memset(wfdie + wfdielen, 0x00, ETH_ALEN);
  788. wfdielen += ETH_ALEN;
  789. /* Coupled Sink Information ATTR */
  790. /* Type: */
  791. wfdie[wfdielen++] = WFD_ATTR_COUPLED_SINK_INFO;
  792. /* Length: */
  793. /* Note: In the WFD specification, the size of length field is 2. */
  794. RTW_PUT_BE16(wfdie + wfdielen, 0x0007);
  795. wfdielen += 2;
  796. /* Value: */
  797. /* Coupled Sink Status bitmap */
  798. /* Not coupled/available for Coupling */
  799. wfdie[wfdielen++] = 0;
  800. /* MAC Addr. */
  801. wfdie[wfdielen++] = 0;
  802. wfdie[wfdielen++] = 0;
  803. wfdie[wfdielen++] = 0;
  804. wfdie[wfdielen++] = 0;
  805. wfdie[wfdielen++] = 0;
  806. wfdie[wfdielen++] = 0;
  807. rtw_set_ie(pbuf, _VENDOR_SPECIFIC_IE_, wfdielen, (unsigned char *) wfdie, &len);
  808. exit:
  809. return len;
  810. }
  811. u32 build_assoc_resp_wfd_ie(struct wifidirect_info *pwdinfo, u8 *pbuf)
  812. {
  813. u8 wfdie[MAX_WFD_IE_LEN] = { 0x00 };
  814. u32 len = 0, wfdielen = 0;
  815. u16 val16 = 0;
  816. _adapter *padapter = pwdinfo->padapter;
  817. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  818. struct wifi_display_info *pwfd_info = padapter->wdinfo.wfd_info;
  819. if (!hal_chk_wl_func(padapter, WL_FUNC_MIRACAST))
  820. goto exit;
  821. /* WFD OUI */
  822. wfdielen = 0;
  823. wfdie[wfdielen++] = 0x50;
  824. wfdie[wfdielen++] = 0x6F;
  825. wfdie[wfdielen++] = 0x9A;
  826. wfdie[wfdielen++] = 0x0A; /* WFA WFD v1.0 */
  827. /* Commented by Albert 20110812 */
  828. /* According to the WFD Specification, the probe request frame should contain 4 WFD attributes */
  829. /* 1. WFD Device Information */
  830. /* 2. Associated BSSID */
  831. /* 3. Coupled Sink Information */
  832. /* WFD Device Information ATTR */
  833. /* Type: */
  834. wfdie[wfdielen++] = WFD_ATTR_DEVICE_INFO;
  835. /* Length: */
  836. /* Note: In the WFD specification, the size of length field is 2. */
  837. RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
  838. wfdielen += 2;
  839. /* Value1: */
  840. /* WFD device information */
  841. /* WFD primary sink + available for WFD session + WiFi Direct mode + WSD ( WFD Service Discovery ) */
  842. val16 = pwfd_info->wfd_device_type | WFD_DEVINFO_SESSION_AVAIL | WFD_DEVINFO_WSD;
  843. RTW_PUT_BE16(wfdie + wfdielen, val16);
  844. wfdielen += 2;
  845. /* Value2: */
  846. /* Session Management Control Port */
  847. /* Default TCP port for RTSP messages is 554 */
  848. RTW_PUT_BE16(wfdie + wfdielen, pwfd_info->rtsp_ctrlport);
  849. wfdielen += 2;
  850. /* Value3: */
  851. /* WFD Device Maximum Throughput */
  852. /* 300Mbps is the maximum throughput */
  853. RTW_PUT_BE16(wfdie + wfdielen, 300);
  854. wfdielen += 2;
  855. /* Associated BSSID ATTR */
  856. /* Type: */
  857. wfdie[wfdielen++] = WFD_ATTR_ASSOC_BSSID;
  858. /* Length: */
  859. /* Note: In the WFD specification, the size of length field is 2. */
  860. RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
  861. wfdielen += 2;
  862. /* Value: */
  863. /* Associated BSSID */
  864. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  865. _rtw_memcpy(wfdie + wfdielen, &pmlmepriv->assoc_bssid[0], ETH_ALEN);
  866. else
  867. _rtw_memset(wfdie + wfdielen, 0x00, ETH_ALEN);
  868. wfdielen += ETH_ALEN;
  869. /* Coupled Sink Information ATTR */
  870. /* Type: */
  871. wfdie[wfdielen++] = WFD_ATTR_COUPLED_SINK_INFO;
  872. /* Length: */
  873. /* Note: In the WFD specification, the size of length field is 2. */
  874. RTW_PUT_BE16(wfdie + wfdielen, 0x0007);
  875. wfdielen += 2;
  876. /* Value: */
  877. /* Coupled Sink Status bitmap */
  878. /* Not coupled/available for Coupling */
  879. wfdie[wfdielen++] = 0;
  880. /* MAC Addr. */
  881. wfdie[wfdielen++] = 0;
  882. wfdie[wfdielen++] = 0;
  883. wfdie[wfdielen++] = 0;
  884. wfdie[wfdielen++] = 0;
  885. wfdie[wfdielen++] = 0;
  886. wfdie[wfdielen++] = 0;
  887. rtw_set_ie(pbuf, _VENDOR_SPECIFIC_IE_, wfdielen, (unsigned char *) wfdie, &len);
  888. exit:
  889. return len;
  890. }
  891. u32 build_nego_req_wfd_ie(struct wifidirect_info *pwdinfo, u8 *pbuf)
  892. {
  893. u8 wfdie[MAX_WFD_IE_LEN] = { 0x00 };
  894. u32 len = 0, wfdielen = 0;
  895. u16 val16 = 0;
  896. _adapter *padapter = pwdinfo->padapter;
  897. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  898. struct wifi_display_info *pwfd_info = padapter->wdinfo.wfd_info;
  899. if (!hal_chk_wl_func(padapter, WL_FUNC_MIRACAST))
  900. goto exit;
  901. /* WFD OUI */
  902. wfdielen = 0;
  903. wfdie[wfdielen++] = 0x50;
  904. wfdie[wfdielen++] = 0x6F;
  905. wfdie[wfdielen++] = 0x9A;
  906. wfdie[wfdielen++] = 0x0A; /* WFA WFD v1.0 */
  907. /* Commented by Albert 20110825 */
  908. /* According to the WFD Specification, the negotiation request frame should contain 3 WFD attributes */
  909. /* 1. WFD Device Information */
  910. /* 2. Associated BSSID ( Optional ) */
  911. /* 3. Local IP Adress ( Optional ) */
  912. /* WFD Device Information ATTR */
  913. /* Type: */
  914. wfdie[wfdielen++] = WFD_ATTR_DEVICE_INFO;
  915. /* Length: */
  916. /* Note: In the WFD specification, the size of length field is 2. */
  917. RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
  918. wfdielen += 2;
  919. /* Value1: */
  920. /* WFD device information */
  921. /* WFD primary sink + WiFi Direct mode + WSD ( WFD Service Discovery ) + WFD Session Available */
  922. val16 = pwfd_info->wfd_device_type | WFD_DEVINFO_WSD | WFD_DEVINFO_SESSION_AVAIL;
  923. RTW_PUT_BE16(wfdie + wfdielen, val16);
  924. wfdielen += 2;
  925. /* Value2: */
  926. /* Session Management Control Port */
  927. /* Default TCP port for RTSP messages is 554 */
  928. RTW_PUT_BE16(wfdie + wfdielen, pwfd_info->rtsp_ctrlport);
  929. wfdielen += 2;
  930. /* Value3: */
  931. /* WFD Device Maximum Throughput */
  932. /* 300Mbps is the maximum throughput */
  933. RTW_PUT_BE16(wfdie + wfdielen, 300);
  934. wfdielen += 2;
  935. /* Associated BSSID ATTR */
  936. /* Type: */
  937. wfdie[wfdielen++] = WFD_ATTR_ASSOC_BSSID;
  938. /* Length: */
  939. /* Note: In the WFD specification, the size of length field is 2. */
  940. RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
  941. wfdielen += 2;
  942. /* Value: */
  943. /* Associated BSSID */
  944. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  945. _rtw_memcpy(wfdie + wfdielen, &pmlmepriv->assoc_bssid[0], ETH_ALEN);
  946. else
  947. _rtw_memset(wfdie + wfdielen, 0x00, ETH_ALEN);
  948. wfdielen += ETH_ALEN;
  949. /* Coupled Sink Information ATTR */
  950. /* Type: */
  951. wfdie[wfdielen++] = WFD_ATTR_COUPLED_SINK_INFO;
  952. /* Length: */
  953. /* Note: In the WFD specification, the size of length field is 2. */
  954. RTW_PUT_BE16(wfdie + wfdielen, 0x0007);
  955. wfdielen += 2;
  956. /* Value: */
  957. /* Coupled Sink Status bitmap */
  958. /* Not coupled/available for Coupling */
  959. wfdie[wfdielen++] = 0;
  960. /* MAC Addr. */
  961. wfdie[wfdielen++] = 0;
  962. wfdie[wfdielen++] = 0;
  963. wfdie[wfdielen++] = 0;
  964. wfdie[wfdielen++] = 0;
  965. wfdie[wfdielen++] = 0;
  966. wfdie[wfdielen++] = 0;
  967. rtw_set_ie(pbuf, _VENDOR_SPECIFIC_IE_, wfdielen, (unsigned char *) wfdie, &len);
  968. exit:
  969. return len;
  970. }
  971. u32 build_nego_resp_wfd_ie(struct wifidirect_info *pwdinfo, u8 *pbuf)
  972. {
  973. u8 wfdie[MAX_WFD_IE_LEN] = { 0x00 };
  974. u32 len = 0, wfdielen = 0;
  975. u16 val16 = 0;
  976. _adapter *padapter = pwdinfo->padapter;
  977. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  978. struct wifi_display_info *pwfd_info = padapter->wdinfo.wfd_info;
  979. if (!hal_chk_wl_func(padapter, WL_FUNC_MIRACAST))
  980. goto exit;
  981. /* WFD OUI */
  982. wfdielen = 0;
  983. wfdie[wfdielen++] = 0x50;
  984. wfdie[wfdielen++] = 0x6F;
  985. wfdie[wfdielen++] = 0x9A;
  986. wfdie[wfdielen++] = 0x0A; /* WFA WFD v1.0 */
  987. /* Commented by Albert 20110825 */
  988. /* According to the WFD Specification, the negotiation request frame should contain 3 WFD attributes */
  989. /* 1. WFD Device Information */
  990. /* 2. Associated BSSID ( Optional ) */
  991. /* 3. Local IP Adress ( Optional ) */
  992. /* WFD Device Information ATTR */
  993. /* Type: */
  994. wfdie[wfdielen++] = WFD_ATTR_DEVICE_INFO;
  995. /* Length: */
  996. /* Note: In the WFD specification, the size of length field is 2. */
  997. RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
  998. wfdielen += 2;
  999. /* Value1: */
  1000. /* WFD device information */
  1001. /* WFD primary sink + WiFi Direct mode + WSD ( WFD Service Discovery ) + WFD Session Available */
  1002. val16 = pwfd_info->wfd_device_type | WFD_DEVINFO_WSD | WFD_DEVINFO_SESSION_AVAIL;
  1003. RTW_PUT_BE16(wfdie + wfdielen, val16);
  1004. wfdielen += 2;
  1005. /* Value2: */
  1006. /* Session Management Control Port */
  1007. /* Default TCP port for RTSP messages is 554 */
  1008. RTW_PUT_BE16(wfdie + wfdielen, pwfd_info->rtsp_ctrlport);
  1009. wfdielen += 2;
  1010. /* Value3: */
  1011. /* WFD Device Maximum Throughput */
  1012. /* 300Mbps is the maximum throughput */
  1013. RTW_PUT_BE16(wfdie + wfdielen, 300);
  1014. wfdielen += 2;
  1015. /* Associated BSSID ATTR */
  1016. /* Type: */
  1017. wfdie[wfdielen++] = WFD_ATTR_ASSOC_BSSID;
  1018. /* Length: */
  1019. /* Note: In the WFD specification, the size of length field is 2. */
  1020. RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
  1021. wfdielen += 2;
  1022. /* Value: */
  1023. /* Associated BSSID */
  1024. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  1025. _rtw_memcpy(wfdie + wfdielen, &pmlmepriv->assoc_bssid[0], ETH_ALEN);
  1026. else
  1027. _rtw_memset(wfdie + wfdielen, 0x00, ETH_ALEN);
  1028. wfdielen += ETH_ALEN;
  1029. /* Coupled Sink Information ATTR */
  1030. /* Type: */
  1031. wfdie[wfdielen++] = WFD_ATTR_COUPLED_SINK_INFO;
  1032. /* Length: */
  1033. /* Note: In the WFD specification, the size of length field is 2. */
  1034. RTW_PUT_BE16(wfdie + wfdielen, 0x0007);
  1035. wfdielen += 2;
  1036. /* Value: */
  1037. /* Coupled Sink Status bitmap */
  1038. /* Not coupled/available for Coupling */
  1039. wfdie[wfdielen++] = 0;
  1040. /* MAC Addr. */
  1041. wfdie[wfdielen++] = 0;
  1042. wfdie[wfdielen++] = 0;
  1043. wfdie[wfdielen++] = 0;
  1044. wfdie[wfdielen++] = 0;
  1045. wfdie[wfdielen++] = 0;
  1046. wfdie[wfdielen++] = 0;
  1047. rtw_set_ie(pbuf, _VENDOR_SPECIFIC_IE_, wfdielen, (unsigned char *) wfdie, &len);
  1048. exit:
  1049. return len;
  1050. }
  1051. u32 build_nego_confirm_wfd_ie(struct wifidirect_info *pwdinfo, u8 *pbuf)
  1052. {
  1053. u8 wfdie[MAX_WFD_IE_LEN] = { 0x00 };
  1054. u32 len = 0, wfdielen = 0;
  1055. u16 val16 = 0;
  1056. _adapter *padapter = pwdinfo->padapter;
  1057. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1058. struct wifi_display_info *pwfd_info = padapter->wdinfo.wfd_info;
  1059. if (!hal_chk_wl_func(padapter, WL_FUNC_MIRACAST))
  1060. goto exit;
  1061. /* WFD OUI */
  1062. wfdielen = 0;
  1063. wfdie[wfdielen++] = 0x50;
  1064. wfdie[wfdielen++] = 0x6F;
  1065. wfdie[wfdielen++] = 0x9A;
  1066. wfdie[wfdielen++] = 0x0A; /* WFA WFD v1.0 */
  1067. /* Commented by Albert 20110825 */
  1068. /* According to the WFD Specification, the negotiation request frame should contain 3 WFD attributes */
  1069. /* 1. WFD Device Information */
  1070. /* 2. Associated BSSID ( Optional ) */
  1071. /* 3. Local IP Adress ( Optional ) */
  1072. /* WFD Device Information ATTR */
  1073. /* Type: */
  1074. wfdie[wfdielen++] = WFD_ATTR_DEVICE_INFO;
  1075. /* Length: */
  1076. /* Note: In the WFD specification, the size of length field is 2. */
  1077. RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
  1078. wfdielen += 2;
  1079. /* Value1: */
  1080. /* WFD device information */
  1081. /* WFD primary sink + WiFi Direct mode + WSD ( WFD Service Discovery ) + WFD Session Available */
  1082. val16 = pwfd_info->wfd_device_type | WFD_DEVINFO_WSD | WFD_DEVINFO_SESSION_AVAIL;
  1083. RTW_PUT_BE16(wfdie + wfdielen, val16);
  1084. wfdielen += 2;
  1085. /* Value2: */
  1086. /* Session Management Control Port */
  1087. /* Default TCP port for RTSP messages is 554 */
  1088. RTW_PUT_BE16(wfdie + wfdielen, pwfd_info->rtsp_ctrlport);
  1089. wfdielen += 2;
  1090. /* Value3: */
  1091. /* WFD Device Maximum Throughput */
  1092. /* 300Mbps is the maximum throughput */
  1093. RTW_PUT_BE16(wfdie + wfdielen, 300);
  1094. wfdielen += 2;
  1095. /* Associated BSSID ATTR */
  1096. /* Type: */
  1097. wfdie[wfdielen++] = WFD_ATTR_ASSOC_BSSID;
  1098. /* Length: */
  1099. /* Note: In the WFD specification, the size of length field is 2. */
  1100. RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
  1101. wfdielen += 2;
  1102. /* Value: */
  1103. /* Associated BSSID */
  1104. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  1105. _rtw_memcpy(wfdie + wfdielen, &pmlmepriv->assoc_bssid[0], ETH_ALEN);
  1106. else
  1107. _rtw_memset(wfdie + wfdielen, 0x00, ETH_ALEN);
  1108. wfdielen += ETH_ALEN;
  1109. /* Coupled Sink Information ATTR */
  1110. /* Type: */
  1111. wfdie[wfdielen++] = WFD_ATTR_COUPLED_SINK_INFO;
  1112. /* Length: */
  1113. /* Note: In the WFD specification, the size of length field is 2. */
  1114. RTW_PUT_BE16(wfdie + wfdielen, 0x0007);
  1115. wfdielen += 2;
  1116. /* Value: */
  1117. /* Coupled Sink Status bitmap */
  1118. /* Not coupled/available for Coupling */
  1119. wfdie[wfdielen++] = 0;
  1120. /* MAC Addr. */
  1121. wfdie[wfdielen++] = 0;
  1122. wfdie[wfdielen++] = 0;
  1123. wfdie[wfdielen++] = 0;
  1124. wfdie[wfdielen++] = 0;
  1125. wfdie[wfdielen++] = 0;
  1126. wfdie[wfdielen++] = 0;
  1127. pbuf = rtw_set_ie(pbuf, _VENDOR_SPECIFIC_IE_, wfdielen, (unsigned char *) wfdie, &len);
  1128. exit:
  1129. return len;
  1130. }
  1131. u32 build_invitation_req_wfd_ie(struct wifidirect_info *pwdinfo, u8 *pbuf)
  1132. {
  1133. u8 wfdie[MAX_WFD_IE_LEN] = { 0x00 };
  1134. u32 len = 0, wfdielen = 0;
  1135. u16 val16 = 0;
  1136. _adapter *padapter = pwdinfo->padapter;
  1137. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1138. struct wifi_display_info *pwfd_info = padapter->wdinfo.wfd_info;
  1139. if (!hal_chk_wl_func(padapter, WL_FUNC_MIRACAST))
  1140. goto exit;
  1141. /* WFD OUI */
  1142. wfdielen = 0;
  1143. wfdie[wfdielen++] = 0x50;
  1144. wfdie[wfdielen++] = 0x6F;
  1145. wfdie[wfdielen++] = 0x9A;
  1146. wfdie[wfdielen++] = 0x0A; /* WFA WFD v1.0 */
  1147. /* Commented by Albert 20110825 */
  1148. /* According to the WFD Specification, the provision discovery request frame should contain 3 WFD attributes */
  1149. /* 1. WFD Device Information */
  1150. /* 2. Associated BSSID ( Optional ) */
  1151. /* 3. Local IP Adress ( Optional ) */
  1152. /* WFD Device Information ATTR */
  1153. /* Type: */
  1154. wfdie[wfdielen++] = WFD_ATTR_DEVICE_INFO;
  1155. /* Length: */
  1156. /* Note: In the WFD specification, the size of length field is 2. */
  1157. RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
  1158. wfdielen += 2;
  1159. /* Value1: */
  1160. /* WFD device information */
  1161. /* WFD primary sink + available for WFD session + WiFi Direct mode + WSD ( WFD Service Discovery ) */
  1162. val16 = pwfd_info->wfd_device_type | WFD_DEVINFO_SESSION_AVAIL | WFD_DEVINFO_WSD;
  1163. RTW_PUT_BE16(wfdie + wfdielen, val16);
  1164. wfdielen += 2;
  1165. /* Value2: */
  1166. /* Session Management Control Port */
  1167. /* Default TCP port for RTSP messages is 554 */
  1168. RTW_PUT_BE16(wfdie + wfdielen, pwfd_info->rtsp_ctrlport);
  1169. wfdielen += 2;
  1170. /* Value3: */
  1171. /* WFD Device Maximum Throughput */
  1172. /* 300Mbps is the maximum throughput */
  1173. RTW_PUT_BE16(wfdie + wfdielen, 300);
  1174. wfdielen += 2;
  1175. /* Associated BSSID ATTR */
  1176. /* Type: */
  1177. wfdie[wfdielen++] = WFD_ATTR_ASSOC_BSSID;
  1178. /* Length: */
  1179. /* Note: In the WFD specification, the size of length field is 2. */
  1180. RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
  1181. wfdielen += 2;
  1182. /* Value: */
  1183. /* Associated BSSID */
  1184. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  1185. _rtw_memcpy(wfdie + wfdielen, &pmlmepriv->assoc_bssid[0], ETH_ALEN);
  1186. else
  1187. _rtw_memset(wfdie + wfdielen, 0x00, ETH_ALEN);
  1188. wfdielen += ETH_ALEN;
  1189. /* Coupled Sink Information ATTR */
  1190. /* Type: */
  1191. wfdie[wfdielen++] = WFD_ATTR_COUPLED_SINK_INFO;
  1192. /* Length: */
  1193. /* Note: In the WFD specification, the size of length field is 2. */
  1194. RTW_PUT_BE16(wfdie + wfdielen, 0x0007);
  1195. wfdielen += 2;
  1196. /* Value: */
  1197. /* Coupled Sink Status bitmap */
  1198. /* Not coupled/available for Coupling */
  1199. wfdie[wfdielen++] = 0;
  1200. /* MAC Addr. */
  1201. wfdie[wfdielen++] = 0;
  1202. wfdie[wfdielen++] = 0;
  1203. wfdie[wfdielen++] = 0;
  1204. wfdie[wfdielen++] = 0;
  1205. wfdie[wfdielen++] = 0;
  1206. wfdie[wfdielen++] = 0;
  1207. if (P2P_ROLE_GO == pwdinfo->role) {
  1208. /* WFD Session Information ATTR */
  1209. /* Type: */
  1210. wfdie[wfdielen++] = WFD_ATTR_SESSION_INFO;
  1211. /* Length: */
  1212. /* Note: In the WFD specification, the size of length field is 2. */
  1213. RTW_PUT_BE16(wfdie + wfdielen, 0x0000);
  1214. wfdielen += 2;
  1215. /* Todo: to add the list of WFD device info descriptor in WFD group. */
  1216. }
  1217. rtw_set_ie(pbuf, _VENDOR_SPECIFIC_IE_, wfdielen, (unsigned char *) wfdie, &len);
  1218. exit:
  1219. return len;
  1220. }
  1221. u32 build_invitation_resp_wfd_ie(struct wifidirect_info *pwdinfo, u8 *pbuf)
  1222. {
  1223. u8 wfdie[MAX_WFD_IE_LEN] = { 0x00 };
  1224. u16 val16 = 0;
  1225. u32 len = 0, wfdielen = 0;
  1226. _adapter *padapter = pwdinfo->padapter;
  1227. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1228. struct wifi_display_info *pwfd_info = padapter->wdinfo.wfd_info;
  1229. if (!hal_chk_wl_func(padapter, WL_FUNC_MIRACAST))
  1230. goto exit;
  1231. /* WFD OUI */
  1232. wfdielen = 0;
  1233. wfdie[wfdielen++] = 0x50;
  1234. wfdie[wfdielen++] = 0x6F;
  1235. wfdie[wfdielen++] = 0x9A;
  1236. wfdie[wfdielen++] = 0x0A; /* WFA WFD v1.0 */
  1237. /* Commented by Albert 20110825 */
  1238. /* According to the WFD Specification, the provision discovery request frame should contain 3 WFD attributes */
  1239. /* 1. WFD Device Information */
  1240. /* 2. Associated BSSID ( Optional ) */
  1241. /* 3. Local IP Adress ( Optional ) */
  1242. /* WFD Device Information ATTR */
  1243. /* Type: */
  1244. wfdie[wfdielen++] = WFD_ATTR_DEVICE_INFO;
  1245. /* Length: */
  1246. /* Note: In the WFD specification, the size of length field is 2. */
  1247. RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
  1248. wfdielen += 2;
  1249. /* Value1: */
  1250. /* WFD device information */
  1251. /* WFD primary sink + available for WFD session + WiFi Direct mode + WSD ( WFD Service Discovery ) */
  1252. val16 = pwfd_info->wfd_device_type | WFD_DEVINFO_SESSION_AVAIL | WFD_DEVINFO_WSD;
  1253. RTW_PUT_BE16(wfdie + wfdielen, val16);
  1254. wfdielen += 2;
  1255. /* Value2: */
  1256. /* Session Management Control Port */
  1257. /* Default TCP port for RTSP messages is 554 */
  1258. RTW_PUT_BE16(wfdie + wfdielen, pwfd_info->rtsp_ctrlport);
  1259. wfdielen += 2;
  1260. /* Value3: */
  1261. /* WFD Device Maximum Throughput */
  1262. /* 300Mbps is the maximum throughput */
  1263. RTW_PUT_BE16(wfdie + wfdielen, 300);
  1264. wfdielen += 2;
  1265. /* Associated BSSID ATTR */
  1266. /* Type: */
  1267. wfdie[wfdielen++] = WFD_ATTR_ASSOC_BSSID;
  1268. /* Length: */
  1269. /* Note: In the WFD specification, the size of length field is 2. */
  1270. RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
  1271. wfdielen += 2;
  1272. /* Value: */
  1273. /* Associated BSSID */
  1274. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  1275. _rtw_memcpy(wfdie + wfdielen, &pmlmepriv->assoc_bssid[0], ETH_ALEN);
  1276. else
  1277. _rtw_memset(wfdie + wfdielen, 0x00, ETH_ALEN);
  1278. wfdielen += ETH_ALEN;
  1279. /* Coupled Sink Information ATTR */
  1280. /* Type: */
  1281. wfdie[wfdielen++] = WFD_ATTR_COUPLED_SINK_INFO;
  1282. /* Length: */
  1283. /* Note: In the WFD specification, the size of length field is 2. */
  1284. RTW_PUT_BE16(wfdie + wfdielen, 0x0007);
  1285. wfdielen += 2;
  1286. /* Value: */
  1287. /* Coupled Sink Status bitmap */
  1288. /* Not coupled/available for Coupling */
  1289. wfdie[wfdielen++] = 0;
  1290. /* MAC Addr. */
  1291. wfdie[wfdielen++] = 0;
  1292. wfdie[wfdielen++] = 0;
  1293. wfdie[wfdielen++] = 0;
  1294. wfdie[wfdielen++] = 0;
  1295. wfdie[wfdielen++] = 0;
  1296. wfdie[wfdielen++] = 0;
  1297. if (P2P_ROLE_GO == pwdinfo->role) {
  1298. /* WFD Session Information ATTR */
  1299. /* Type: */
  1300. wfdie[wfdielen++] = WFD_ATTR_SESSION_INFO;
  1301. /* Length: */
  1302. /* Note: In the WFD specification, the size of length field is 2. */
  1303. RTW_PUT_BE16(wfdie + wfdielen, 0x0000);
  1304. wfdielen += 2;
  1305. /* Todo: to add the list of WFD device info descriptor in WFD group. */
  1306. }
  1307. rtw_set_ie(pbuf, _VENDOR_SPECIFIC_IE_, wfdielen, (unsigned char *) wfdie, &len);
  1308. exit:
  1309. return len;
  1310. }
  1311. u32 build_provdisc_req_wfd_ie(struct wifidirect_info *pwdinfo, u8 *pbuf)
  1312. {
  1313. u8 wfdie[MAX_WFD_IE_LEN] = { 0x00 };
  1314. u32 len = 0, wfdielen = 0;
  1315. u16 val16 = 0;
  1316. _adapter *padapter = pwdinfo->padapter;
  1317. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1318. struct wifi_display_info *pwfd_info = padapter->wdinfo.wfd_info;
  1319. if (!hal_chk_wl_func(padapter, WL_FUNC_MIRACAST))
  1320. goto exit;
  1321. /* WFD OUI */
  1322. wfdielen = 0;
  1323. wfdie[wfdielen++] = 0x50;
  1324. wfdie[wfdielen++] = 0x6F;
  1325. wfdie[wfdielen++] = 0x9A;
  1326. wfdie[wfdielen++] = 0x0A; /* WFA WFD v1.0 */
  1327. /* Commented by Albert 20110825 */
  1328. /* According to the WFD Specification, the provision discovery request frame should contain 3 WFD attributes */
  1329. /* 1. WFD Device Information */
  1330. /* 2. Associated BSSID ( Optional ) */
  1331. /* 3. Local IP Adress ( Optional ) */
  1332. /* WFD Device Information ATTR */
  1333. /* Type: */
  1334. wfdie[wfdielen++] = WFD_ATTR_DEVICE_INFO;
  1335. /* Length: */
  1336. /* Note: In the WFD specification, the size of length field is 2. */
  1337. RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
  1338. wfdielen += 2;
  1339. /* Value1: */
  1340. /* WFD device information */
  1341. /* WFD primary sink + available for WFD session + WiFi Direct mode + WSD ( WFD Service Discovery ) */
  1342. val16 = pwfd_info->wfd_device_type | WFD_DEVINFO_SESSION_AVAIL | WFD_DEVINFO_WSD;
  1343. RTW_PUT_BE16(wfdie + wfdielen, val16);
  1344. wfdielen += 2;
  1345. /* Value2: */
  1346. /* Session Management Control Port */
  1347. /* Default TCP port for RTSP messages is 554 */
  1348. RTW_PUT_BE16(wfdie + wfdielen, pwfd_info->rtsp_ctrlport);
  1349. wfdielen += 2;
  1350. /* Value3: */
  1351. /* WFD Device Maximum Throughput */
  1352. /* 300Mbps is the maximum throughput */
  1353. RTW_PUT_BE16(wfdie + wfdielen, 300);
  1354. wfdielen += 2;
  1355. /* Associated BSSID ATTR */
  1356. /* Type: */
  1357. wfdie[wfdielen++] = WFD_ATTR_ASSOC_BSSID;
  1358. /* Length: */
  1359. /* Note: In the WFD specification, the size of length field is 2. */
  1360. RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
  1361. wfdielen += 2;
  1362. /* Value: */
  1363. /* Associated BSSID */
  1364. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  1365. _rtw_memcpy(wfdie + wfdielen, &pmlmepriv->assoc_bssid[0], ETH_ALEN);
  1366. else
  1367. _rtw_memset(wfdie + wfdielen, 0x00, ETH_ALEN);
  1368. wfdielen += ETH_ALEN;
  1369. /* Coupled Sink Information ATTR */
  1370. /* Type: */
  1371. wfdie[wfdielen++] = WFD_ATTR_COUPLED_SINK_INFO;
  1372. /* Length: */
  1373. /* Note: In the WFD specification, the size of length field is 2. */
  1374. RTW_PUT_BE16(wfdie + wfdielen, 0x0007);
  1375. wfdielen += 2;
  1376. /* Value: */
  1377. /* Coupled Sink Status bitmap */
  1378. /* Not coupled/available for Coupling */
  1379. wfdie[wfdielen++] = 0;
  1380. /* MAC Addr. */
  1381. wfdie[wfdielen++] = 0;
  1382. wfdie[wfdielen++] = 0;
  1383. wfdie[wfdielen++] = 0;
  1384. wfdie[wfdielen++] = 0;
  1385. wfdie[wfdielen++] = 0;
  1386. wfdie[wfdielen++] = 0;
  1387. rtw_set_ie(pbuf, _VENDOR_SPECIFIC_IE_, wfdielen, (unsigned char *) wfdie, &len);
  1388. exit:
  1389. return len;
  1390. }
  1391. u32 build_provdisc_resp_wfd_ie(struct wifidirect_info *pwdinfo, u8 *pbuf)
  1392. {
  1393. u8 wfdie[MAX_WFD_IE_LEN] = { 0x00 };
  1394. u32 len = 0, wfdielen = 0;
  1395. u16 val16 = 0;
  1396. _adapter *padapter = pwdinfo->padapter;
  1397. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1398. struct wifi_display_info *pwfd_info = padapter->wdinfo.wfd_info;
  1399. if (!hal_chk_wl_func(padapter, WL_FUNC_MIRACAST))
  1400. goto exit;
  1401. /* WFD OUI */
  1402. wfdielen = 0;
  1403. wfdie[wfdielen++] = 0x50;
  1404. wfdie[wfdielen++] = 0x6F;
  1405. wfdie[wfdielen++] = 0x9A;
  1406. wfdie[wfdielen++] = 0x0A; /* WFA WFD v1.0 */
  1407. /* Commented by Albert 20110825 */
  1408. /* According to the WFD Specification, the provision discovery response frame should contain 3 WFD attributes */
  1409. /* 1. WFD Device Information */
  1410. /* 2. Associated BSSID ( Optional ) */
  1411. /* 3. Local IP Adress ( Optional ) */
  1412. /* WFD Device Information ATTR */
  1413. /* Type: */
  1414. wfdie[wfdielen++] = WFD_ATTR_DEVICE_INFO;
  1415. /* Length: */
  1416. /* Note: In the WFD specification, the size of length field is 2. */
  1417. RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
  1418. wfdielen += 2;
  1419. /* Value1: */
  1420. /* WFD device information */
  1421. /* WFD primary sink + available for WFD session + WiFi Direct mode + WSD ( WFD Service Discovery ) */
  1422. val16 = pwfd_info->wfd_device_type | WFD_DEVINFO_SESSION_AVAIL | WFD_DEVINFO_WSD;
  1423. RTW_PUT_BE16(wfdie + wfdielen, val16);
  1424. wfdielen += 2;
  1425. /* Value2: */
  1426. /* Session Management Control Port */
  1427. /* Default TCP port for RTSP messages is 554 */
  1428. RTW_PUT_BE16(wfdie + wfdielen, pwfd_info->rtsp_ctrlport);
  1429. wfdielen += 2;
  1430. /* Value3: */
  1431. /* WFD Device Maximum Throughput */
  1432. /* 300Mbps is the maximum throughput */
  1433. RTW_PUT_BE16(wfdie + wfdielen, 300);
  1434. wfdielen += 2;
  1435. /* Associated BSSID ATTR */
  1436. /* Type: */
  1437. wfdie[wfdielen++] = WFD_ATTR_ASSOC_BSSID;
  1438. /* Length: */
  1439. /* Note: In the WFD specification, the size of length field is 2. */
  1440. RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
  1441. wfdielen += 2;
  1442. /* Value: */
  1443. /* Associated BSSID */
  1444. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  1445. _rtw_memcpy(wfdie + wfdielen, &pmlmepriv->assoc_bssid[0], ETH_ALEN);
  1446. else
  1447. _rtw_memset(wfdie + wfdielen, 0x00, ETH_ALEN);
  1448. wfdielen += ETH_ALEN;
  1449. /* Coupled Sink Information ATTR */
  1450. /* Type: */
  1451. wfdie[wfdielen++] = WFD_ATTR_COUPLED_SINK_INFO;
  1452. /* Length: */
  1453. /* Note: In the WFD specification, the size of length field is 2. */
  1454. RTW_PUT_BE16(wfdie + wfdielen, 0x0007);
  1455. wfdielen += 2;
  1456. /* Value: */
  1457. /* Coupled Sink Status bitmap */
  1458. /* Not coupled/available for Coupling */
  1459. wfdie[wfdielen++] = 0;
  1460. /* MAC Addr. */
  1461. wfdie[wfdielen++] = 0;
  1462. wfdie[wfdielen++] = 0;
  1463. wfdie[wfdielen++] = 0;
  1464. wfdie[wfdielen++] = 0;
  1465. wfdie[wfdielen++] = 0;
  1466. wfdie[wfdielen++] = 0;
  1467. rtw_set_ie(pbuf, _VENDOR_SPECIFIC_IE_, wfdielen, (unsigned char *) wfdie, &len);
  1468. exit:
  1469. return len;
  1470. }
  1471. #endif /* CONFIG_WFD */
  1472. u32 build_probe_resp_p2p_ie(struct wifidirect_info *pwdinfo, u8 *pbuf)
  1473. {
  1474. u8 p2pie[MAX_P2P_IE_LEN] = { 0x00 };
  1475. u32 len = 0, p2pielen = 0;
  1476. #ifdef CONFIG_INTEL_WIDI
  1477. struct mlme_priv *pmlmepriv = &(pwdinfo->padapter->mlmepriv);
  1478. u8 zero_array_check[L2SDTA_SERVICE_VE_LEN] = { 0x00 };
  1479. u8 widi_version = 0, i = 0;
  1480. if (_rtw_memcmp(pmlmepriv->sa_ext, zero_array_check, L2SDTA_SERVICE_VE_LEN) == _FALSE)
  1481. widi_version = 35;
  1482. else if (pmlmepriv->num_p2p_sdt != 0)
  1483. widi_version = 40;
  1484. #endif /* CONFIG_INTEL_WIDI */
  1485. /* P2P OUI */
  1486. p2pielen = 0;
  1487. p2pie[p2pielen++] = 0x50;
  1488. p2pie[p2pielen++] = 0x6F;
  1489. p2pie[p2pielen++] = 0x9A;
  1490. p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
  1491. /* Commented by Albert 20100907 */
  1492. /* According to the P2P Specification, the probe response frame should contain 5 P2P attributes */
  1493. /* 1. P2P Capability */
  1494. /* 2. Extended Listen Timing */
  1495. /* 3. Notice of Absence ( NOA ) ( Only GO needs this ) */
  1496. /* 4. Device Info */
  1497. /* 5. Group Info ( Only GO need this ) */
  1498. /* P2P Capability ATTR */
  1499. /* Type: */
  1500. p2pie[p2pielen++] = P2P_ATTR_CAPABILITY;
  1501. /* Length: */
  1502. /* *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0002 ); */
  1503. RTW_PUT_LE16(p2pie + p2pielen, 0x0002);
  1504. p2pielen += 2;
  1505. /* Value: */
  1506. /* Device Capability Bitmap, 1 byte */
  1507. p2pie[p2pielen++] = DMP_P2P_DEVCAP_SUPPORT;
  1508. /* Group Capability Bitmap, 1 byte */
  1509. if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
  1510. p2pie[p2pielen] = (P2P_GRPCAP_GO | P2P_GRPCAP_INTRABSS);
  1511. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_PROVISIONING_ING))
  1512. p2pie[p2pielen] |= P2P_GRPCAP_GROUP_FORMATION;
  1513. p2pielen++;
  1514. } else if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_DEVICE)) {
  1515. /* Group Capability Bitmap, 1 byte */
  1516. if (pwdinfo->persistent_supported)
  1517. p2pie[p2pielen++] = P2P_GRPCAP_PERSISTENT_GROUP | DMP_P2P_GRPCAP_SUPPORT;
  1518. else
  1519. p2pie[p2pielen++] = DMP_P2P_GRPCAP_SUPPORT;
  1520. }
  1521. /* Extended Listen Timing ATTR */
  1522. /* Type: */
  1523. p2pie[p2pielen++] = P2P_ATTR_EX_LISTEN_TIMING;
  1524. /* Length: */
  1525. /* *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0004 ); */
  1526. RTW_PUT_LE16(p2pie + p2pielen, 0x0004);
  1527. p2pielen += 2;
  1528. /* Value: */
  1529. /* Availability Period */
  1530. /* *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0xFFFF ); */
  1531. RTW_PUT_LE16(p2pie + p2pielen, 0xFFFF);
  1532. p2pielen += 2;
  1533. /* Availability Interval */
  1534. /* *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0xFFFF ); */
  1535. RTW_PUT_LE16(p2pie + p2pielen, 0xFFFF);
  1536. p2pielen += 2;
  1537. /* Notice of Absence ATTR */
  1538. /* Type: */
  1539. /* Length: */
  1540. /* Value: */
  1541. if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
  1542. /* go_add_noa_attr(pwdinfo); */
  1543. }
  1544. /* Device Info ATTR */
  1545. /* Type: */
  1546. p2pie[p2pielen++] = P2P_ATTR_DEVICE_INFO;
  1547. /* Length: */
  1548. /* 21->P2P Device Address (6bytes) + Config Methods (2bytes) + Primary Device Type (8bytes) */
  1549. /* + NumofSecondDevType (1byte) + WPS Device Name ID field (2bytes) + WPS Device Name Len field (2bytes) */
  1550. /* *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 21 + pwdinfo->device_name_len ); */
  1551. #ifdef CONFIG_INTEL_WIDI
  1552. if (widi_version == 35)
  1553. RTW_PUT_LE16(p2pie + p2pielen, 21 + 8 + pwdinfo->device_name_len);
  1554. else if (widi_version == 40)
  1555. RTW_PUT_LE16(p2pie + p2pielen, 21 + 8 * pmlmepriv->num_p2p_sdt + pwdinfo->device_name_len);
  1556. else
  1557. #endif /* CONFIG_INTEL_WIDI */
  1558. RTW_PUT_LE16(p2pie + p2pielen, 21 + pwdinfo->device_name_len);
  1559. p2pielen += 2;
  1560. /* Value: */
  1561. /* P2P Device Address */
  1562. _rtw_memcpy(p2pie + p2pielen, pwdinfo->device_addr, ETH_ALEN);
  1563. p2pielen += ETH_ALEN;
  1564. /* Config Method */
  1565. /* This field should be big endian. Noted by P2P specification. */
  1566. /* *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( pwdinfo->supported_wps_cm ); */
  1567. RTW_PUT_BE16(p2pie + p2pielen, pwdinfo->supported_wps_cm);
  1568. p2pielen += 2;
  1569. #ifdef CONFIG_INTEL_WIDI
  1570. if (widi_version == 40) {
  1571. /* Primary Device Type */
  1572. /* Category ID */
  1573. /* *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( WPS_PDT_CID_MULIT_MEDIA ); */
  1574. RTW_PUT_BE16(p2pie + p2pielen, pmlmepriv->p2p_pdt_cid);
  1575. p2pielen += 2;
  1576. /* OUI */
  1577. /* *(u32*) ( p2pie + p2pielen ) = cpu_to_be32( WPSOUI ); */
  1578. RTW_PUT_BE32(p2pie + p2pielen, WPSOUI);
  1579. p2pielen += 4;
  1580. /* Sub Category ID */
  1581. /* *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( WPS_PDT_SCID_MEDIA_SERVER ); */
  1582. RTW_PUT_BE16(p2pie + p2pielen, pmlmepriv->p2p_pdt_scid);
  1583. p2pielen += 2;
  1584. } else
  1585. #endif /* CONFIG_INTEL_WIDI */
  1586. {
  1587. /* Primary Device Type */
  1588. /* Category ID */
  1589. /* *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( WPS_PDT_CID_MULIT_MEDIA ); */
  1590. RTW_PUT_BE16(p2pie + p2pielen, WPS_PDT_CID_MULIT_MEDIA);
  1591. p2pielen += 2;
  1592. /* OUI */
  1593. /* *(u32*) ( p2pie + p2pielen ) = cpu_to_be32( WPSOUI ); */
  1594. RTW_PUT_BE32(p2pie + p2pielen, WPSOUI);
  1595. p2pielen += 4;
  1596. /* Sub Category ID */
  1597. /* *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( WPS_PDT_SCID_MEDIA_SERVER ); */
  1598. RTW_PUT_BE16(p2pie + p2pielen, WPS_PDT_SCID_MEDIA_SERVER);
  1599. p2pielen += 2;
  1600. }
  1601. /* Number of Secondary Device Types */
  1602. #ifdef CONFIG_INTEL_WIDI
  1603. if (widi_version == 35) {
  1604. p2pie[p2pielen++] = 0x01;
  1605. RTW_PUT_BE16(p2pie + p2pielen, WPS_PDT_CID_DISPLAYS);
  1606. p2pielen += 2;
  1607. RTW_PUT_BE32(p2pie + p2pielen, INTEL_DEV_TYPE_OUI);
  1608. p2pielen += 4;
  1609. RTW_PUT_BE16(p2pie + p2pielen, P2P_SCID_WIDI_CONSUMER_SINK);
  1610. p2pielen += 2;
  1611. } else if (widi_version == 40) {
  1612. p2pie[p2pielen++] = pmlmepriv->num_p2p_sdt;
  1613. for (; i < pmlmepriv->num_p2p_sdt; i++) {
  1614. RTW_PUT_BE16(p2pie + p2pielen, pmlmepriv->p2p_sdt_cid[i]);
  1615. p2pielen += 2;
  1616. RTW_PUT_BE32(p2pie + p2pielen, INTEL_DEV_TYPE_OUI);
  1617. p2pielen += 4;
  1618. RTW_PUT_BE16(p2pie + p2pielen, pmlmepriv->p2p_sdt_scid[i]);
  1619. p2pielen += 2;
  1620. }
  1621. } else
  1622. #endif /* CONFIG_INTEL_WIDI */
  1623. p2pie[p2pielen++] = 0x00; /* No Secondary Device Type List */
  1624. /* Device Name */
  1625. /* Type: */
  1626. /* *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( WPS_ATTR_DEVICE_NAME ); */
  1627. RTW_PUT_BE16(p2pie + p2pielen, WPS_ATTR_DEVICE_NAME);
  1628. p2pielen += 2;
  1629. /* Length: */
  1630. /* *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( pwdinfo->device_name_len ); */
  1631. RTW_PUT_BE16(p2pie + p2pielen, pwdinfo->device_name_len);
  1632. p2pielen += 2;
  1633. /* Value: */
  1634. _rtw_memcpy(p2pie + p2pielen, pwdinfo->device_name, pwdinfo->device_name_len);
  1635. p2pielen += pwdinfo->device_name_len;
  1636. /* Group Info ATTR */
  1637. /* Type: */
  1638. /* Length: */
  1639. /* Value: */
  1640. if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO))
  1641. p2pielen += go_add_group_info_attr(pwdinfo, p2pie + p2pielen);
  1642. pbuf = rtw_set_ie(pbuf, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *) p2pie, &len);
  1643. return len;
  1644. }
  1645. u32 build_prov_disc_request_p2p_ie(struct wifidirect_info *pwdinfo, u8 *pbuf, u8 *pssid, u8 ussidlen, u8 *pdev_raddr)
  1646. {
  1647. u8 p2pie[MAX_P2P_IE_LEN] = { 0x00 };
  1648. u32 len = 0, p2pielen = 0;
  1649. /* P2P OUI */
  1650. p2pielen = 0;
  1651. p2pie[p2pielen++] = 0x50;
  1652. p2pie[p2pielen++] = 0x6F;
  1653. p2pie[p2pielen++] = 0x9A;
  1654. p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
  1655. /* Commented by Albert 20110301 */
  1656. /* According to the P2P Specification, the provision discovery request frame should contain 3 P2P attributes */
  1657. /* 1. P2P Capability */
  1658. /* 2. Device Info */
  1659. /* 3. Group ID ( When joining an operating P2P Group ) */
  1660. /* P2P Capability ATTR */
  1661. /* Type: */
  1662. p2pie[p2pielen++] = P2P_ATTR_CAPABILITY;
  1663. /* Length: */
  1664. /* *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0002 ); */
  1665. RTW_PUT_LE16(p2pie + p2pielen, 0x0002);
  1666. p2pielen += 2;
  1667. /* Value: */
  1668. /* Device Capability Bitmap, 1 byte */
  1669. p2pie[p2pielen++] = DMP_P2P_DEVCAP_SUPPORT;
  1670. /* Group Capability Bitmap, 1 byte */
  1671. if (pwdinfo->persistent_supported)
  1672. p2pie[p2pielen++] = P2P_GRPCAP_PERSISTENT_GROUP | DMP_P2P_GRPCAP_SUPPORT;
  1673. else
  1674. p2pie[p2pielen++] = DMP_P2P_GRPCAP_SUPPORT;
  1675. /* Device Info ATTR */
  1676. /* Type: */
  1677. p2pie[p2pielen++] = P2P_ATTR_DEVICE_INFO;
  1678. /* Length: */
  1679. /* 21->P2P Device Address (6bytes) + Config Methods (2bytes) + Primary Device Type (8bytes) */
  1680. /* + NumofSecondDevType (1byte) + WPS Device Name ID field (2bytes) + WPS Device Name Len field (2bytes) */
  1681. /* *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 21 + pwdinfo->device_name_len ); */
  1682. RTW_PUT_LE16(p2pie + p2pielen, 21 + pwdinfo->device_name_len);
  1683. p2pielen += 2;
  1684. /* Value: */
  1685. /* P2P Device Address */
  1686. _rtw_memcpy(p2pie + p2pielen, pwdinfo->device_addr, ETH_ALEN);
  1687. p2pielen += ETH_ALEN;
  1688. /* Config Method */
  1689. /* This field should be big endian. Noted by P2P specification. */
  1690. if (pwdinfo->ui_got_wps_info == P2P_GOT_WPSINFO_PBC) {
  1691. /* *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( WPS_CONFIG_METHOD_PBC ); */
  1692. RTW_PUT_BE16(p2pie + p2pielen, WPS_CONFIG_METHOD_PBC);
  1693. } else {
  1694. /* *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( WPS_CONFIG_METHOD_DISPLAY ); */
  1695. RTW_PUT_BE16(p2pie + p2pielen, WPS_CONFIG_METHOD_DISPLAY);
  1696. }
  1697. p2pielen += 2;
  1698. /* Primary Device Type */
  1699. /* Category ID */
  1700. /* *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( WPS_PDT_CID_MULIT_MEDIA ); */
  1701. RTW_PUT_BE16(p2pie + p2pielen, WPS_PDT_CID_MULIT_MEDIA);
  1702. p2pielen += 2;
  1703. /* OUI */
  1704. /* *(u32*) ( p2pie + p2pielen ) = cpu_to_be32( WPSOUI ); */
  1705. RTW_PUT_BE32(p2pie + p2pielen, WPSOUI);
  1706. p2pielen += 4;
  1707. /* Sub Category ID */
  1708. /* *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( WPS_PDT_SCID_MEDIA_SERVER ); */
  1709. RTW_PUT_BE16(p2pie + p2pielen, WPS_PDT_SCID_MEDIA_SERVER);
  1710. p2pielen += 2;
  1711. /* Number of Secondary Device Types */
  1712. p2pie[p2pielen++] = 0x00; /* No Secondary Device Type List */
  1713. /* Device Name */
  1714. /* Type: */
  1715. /* *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( WPS_ATTR_DEVICE_NAME ); */
  1716. RTW_PUT_BE16(p2pie + p2pielen, WPS_ATTR_DEVICE_NAME);
  1717. p2pielen += 2;
  1718. /* Length: */
  1719. /* *(u16*) ( p2pie + p2pielen ) = cpu_to_be16( pwdinfo->device_name_len ); */
  1720. RTW_PUT_BE16(p2pie + p2pielen, pwdinfo->device_name_len);
  1721. p2pielen += 2;
  1722. /* Value: */
  1723. _rtw_memcpy(p2pie + p2pielen, pwdinfo->device_name, pwdinfo->device_name_len);
  1724. p2pielen += pwdinfo->device_name_len;
  1725. if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT)) {
  1726. /* Added by Albert 2011/05/19 */
  1727. /* In this case, the pdev_raddr is the device address of the group owner. */
  1728. /* P2P Group ID ATTR */
  1729. /* Type: */
  1730. p2pie[p2pielen++] = P2P_ATTR_GROUP_ID;
  1731. /* Length: */
  1732. /* *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( ETH_ALEN + ussidlen ); */
  1733. RTW_PUT_LE16(p2pie + p2pielen, ETH_ALEN + ussidlen);
  1734. p2pielen += 2;
  1735. /* Value: */
  1736. _rtw_memcpy(p2pie + p2pielen, pdev_raddr, ETH_ALEN);
  1737. p2pielen += ETH_ALEN;
  1738. _rtw_memcpy(p2pie + p2pielen, pssid, ussidlen);
  1739. p2pielen += ussidlen;
  1740. }
  1741. pbuf = rtw_set_ie(pbuf, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *) p2pie, &len);
  1742. return len;
  1743. }
  1744. u32 build_assoc_resp_p2p_ie(struct wifidirect_info *pwdinfo, u8 *pbuf, u8 status_code)
  1745. {
  1746. u8 p2pie[MAX_P2P_IE_LEN] = { 0x00 };
  1747. u32 len = 0, p2pielen = 0;
  1748. /* P2P OUI */
  1749. p2pielen = 0;
  1750. p2pie[p2pielen++] = 0x50;
  1751. p2pie[p2pielen++] = 0x6F;
  1752. p2pie[p2pielen++] = 0x9A;
  1753. p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
  1754. /* According to the P2P Specification, the Association response frame should contain 2 P2P attributes */
  1755. /* 1. Status */
  1756. /* 2. Extended Listen Timing (optional) */
  1757. /* Status ATTR */
  1758. p2pielen += rtw_set_p2p_attr_content(&p2pie[p2pielen], P2P_ATTR_STATUS, 1, &status_code);
  1759. /* Extended Listen Timing ATTR */
  1760. /* Type: */
  1761. /* Length: */
  1762. /* Value: */
  1763. pbuf = rtw_set_ie(pbuf, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *) p2pie, &len);
  1764. return len;
  1765. }
  1766. u32 build_deauth_p2p_ie(struct wifidirect_info *pwdinfo, u8 *pbuf)
  1767. {
  1768. u32 len = 0;
  1769. return len;
  1770. }
  1771. u32 process_probe_req_p2p_ie(struct wifidirect_info *pwdinfo, u8 *pframe, uint len)
  1772. {
  1773. u8 *p;
  1774. u32 ret = _FALSE;
  1775. u8 *p2pie;
  1776. u32 p2pielen = 0;
  1777. int ssid_len = 0, rate_cnt = 0;
  1778. p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + _PROBEREQ_IE_OFFSET_, _SUPPORTEDRATES_IE_, (int *)&rate_cnt,
  1779. len - WLAN_HDR_A3_LEN - _PROBEREQ_IE_OFFSET_);
  1780. if (rate_cnt <= 4) {
  1781. int i, g_rate = 0;
  1782. for (i = 0; i < rate_cnt; i++) {
  1783. if (((*(p + 2 + i) & 0xff) != 0x02) &&
  1784. ((*(p + 2 + i) & 0xff) != 0x04) &&
  1785. ((*(p + 2 + i) & 0xff) != 0x0B) &&
  1786. ((*(p + 2 + i) & 0xff) != 0x16))
  1787. g_rate = 1;
  1788. }
  1789. if (g_rate == 0) {
  1790. /* There is no OFDM rate included in SupportedRates IE of this probe request frame */
  1791. /* The driver should response this probe request. */
  1792. return ret;
  1793. }
  1794. } else {
  1795. /* rate_cnt > 4 means the SupportRates IE contains the OFDM rate because the count of CCK rates are 4. */
  1796. /* We should proceed the following check for this probe request. */
  1797. }
  1798. /* Added comments by Albert 20100906 */
  1799. /* There are several items we should check here. */
  1800. /* 1. This probe request frame must contain the P2P IE. (Done) */
  1801. /* 2. This probe request frame must contain the wildcard SSID. (Done) */
  1802. /* 3. Wildcard BSSID. (Todo) */
  1803. /* 4. Destination Address. ( Done in mgt_dispatcher function ) */
  1804. /* 5. Requested Device Type in WSC IE. (Todo) */
  1805. /* 6. Device ID attribute in P2P IE. (Todo) */
  1806. p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + _PROBEREQ_IE_OFFSET_, _SSID_IE_, (int *)&ssid_len,
  1807. len - WLAN_HDR_A3_LEN - _PROBEREQ_IE_OFFSET_);
  1808. ssid_len &= 0xff; /* Just last 1 byte is valid for ssid len of the probe request */
  1809. if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_DEVICE) || rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
  1810. p2pie = rtw_get_p2p_ie(pframe + WLAN_HDR_A3_LEN + _PROBEREQ_IE_OFFSET_ , len - WLAN_HDR_A3_LEN - _PROBEREQ_IE_OFFSET_ , NULL, &p2pielen);
  1811. if (p2pie) {
  1812. if ((p != NULL) && _rtw_memcmp((void *)(p + 2), (void *) pwdinfo->p2p_wildcard_ssid , 7)) {
  1813. /* todo: */
  1814. /* Check Requested Device Type attributes in WSC IE. */
  1815. /* Check Device ID attribute in P2P IE */
  1816. ret = _TRUE;
  1817. } else if ((p != NULL) && (ssid_len == 0))
  1818. ret = _TRUE;
  1819. } else {
  1820. /* non -p2p device */
  1821. }
  1822. }
  1823. return ret;
  1824. }
  1825. u32 process_assoc_req_p2p_ie(struct wifidirect_info *pwdinfo, u8 *pframe, uint len, struct sta_info *psta)
  1826. {
  1827. u8 status_code = P2P_STATUS_SUCCESS;
  1828. u8 *pbuf, *pattr_content = NULL;
  1829. u32 attr_contentlen = 0;
  1830. u16 cap_attr = 0;
  1831. unsigned short frame_type, ie_offset = 0;
  1832. u8 *ies;
  1833. u32 ies_len;
  1834. u8 *p2p_ie;
  1835. u32 p2p_ielen = 0;
  1836. if (!rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO))
  1837. return P2P_STATUS_FAIL_REQUEST_UNABLE;
  1838. frame_type = get_frame_sub_type(pframe);
  1839. if (frame_type == WIFI_ASSOCREQ)
  1840. ie_offset = _ASOCREQ_IE_OFFSET_;
  1841. else /* WIFI_REASSOCREQ */
  1842. ie_offset = _REASOCREQ_IE_OFFSET_;
  1843. ies = pframe + WLAN_HDR_A3_LEN + ie_offset;
  1844. ies_len = len - WLAN_HDR_A3_LEN - ie_offset;
  1845. p2p_ie = rtw_get_p2p_ie(ies , ies_len , NULL, &p2p_ielen);
  1846. if (!p2p_ie) {
  1847. RTW_INFO("[%s] P2P IE not Found!!\n", __FUNCTION__);
  1848. status_code = P2P_STATUS_FAIL_INVALID_PARAM;
  1849. } else
  1850. RTW_INFO("[%s] P2P IE Found!!\n", __FUNCTION__);
  1851. while (p2p_ie) {
  1852. /* Check P2P Capability ATTR */
  1853. if (rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_CAPABILITY, (u8 *)&cap_attr, (uint *) &attr_contentlen)) {
  1854. RTW_INFO("[%s] Got P2P Capability Attr!!\n", __FUNCTION__);
  1855. cap_attr = le16_to_cpu(cap_attr);
  1856. psta->dev_cap = cap_attr & 0xff;
  1857. }
  1858. /* Check Extended Listen Timing ATTR */
  1859. /* Check P2P Device Info ATTR */
  1860. if (rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_DEVICE_INFO, NULL, (uint *)&attr_contentlen)) {
  1861. RTW_INFO("[%s] Got P2P DEVICE INFO Attr!!\n", __FUNCTION__);
  1862. pattr_content = pbuf = rtw_zmalloc(attr_contentlen);
  1863. if (pattr_content) {
  1864. u8 num_of_secdev_type;
  1865. u16 dev_name_len;
  1866. rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_DEVICE_INFO , pattr_content, (uint *)&attr_contentlen);
  1867. _rtw_memcpy(psta->dev_addr, pattr_content, ETH_ALEN);/* P2P Device Address */
  1868. pattr_content += ETH_ALEN;
  1869. _rtw_memcpy(&psta->config_methods, pattr_content, 2);/* Config Methods */
  1870. psta->config_methods = be16_to_cpu(psta->config_methods);
  1871. pattr_content += 2;
  1872. _rtw_memcpy(psta->primary_dev_type, pattr_content, 8);
  1873. pattr_content += 8;
  1874. num_of_secdev_type = *pattr_content;
  1875. pattr_content += 1;
  1876. if (num_of_secdev_type == 0)
  1877. psta->num_of_secdev_type = 0;
  1878. else {
  1879. u32 len;
  1880. psta->num_of_secdev_type = num_of_secdev_type;
  1881. len = (sizeof(psta->secdev_types_list) < (num_of_secdev_type * 8)) ? (sizeof(psta->secdev_types_list)) : (num_of_secdev_type * 8);
  1882. _rtw_memcpy(psta->secdev_types_list, pattr_content, len);
  1883. pattr_content += (num_of_secdev_type * 8);
  1884. }
  1885. /* dev_name_len = attr_contentlen - ETH_ALEN - 2 - 8 - 1 - (num_of_secdev_type*8); */
  1886. psta->dev_name_len = 0;
  1887. if (WPS_ATTR_DEVICE_NAME == be16_to_cpu(*(u16 *)pattr_content)) {
  1888. dev_name_len = be16_to_cpu(*(u16 *)(pattr_content + 2));
  1889. psta->dev_name_len = (sizeof(psta->dev_name) < dev_name_len) ? sizeof(psta->dev_name) : dev_name_len;
  1890. _rtw_memcpy(psta->dev_name, pattr_content + 4, psta->dev_name_len);
  1891. }
  1892. rtw_mfree(pbuf, attr_contentlen);
  1893. }
  1894. }
  1895. /* Get the next P2P IE */
  1896. p2p_ie = rtw_get_p2p_ie(p2p_ie + p2p_ielen, ies_len - (p2p_ie - ies + p2p_ielen), NULL, &p2p_ielen);
  1897. }
  1898. return status_code;
  1899. }
  1900. u32 process_p2p_devdisc_req(struct wifidirect_info *pwdinfo, u8 *pframe, uint len)
  1901. {
  1902. u8 *frame_body;
  1903. u8 status, dialogToken;
  1904. struct sta_info *psta = NULL;
  1905. _adapter *padapter = pwdinfo->padapter;
  1906. struct sta_priv *pstapriv = &padapter->stapriv;
  1907. u8 *p2p_ie;
  1908. u32 p2p_ielen = 0;
  1909. frame_body = (unsigned char *)(pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
  1910. dialogToken = frame_body[7];
  1911. status = P2P_STATUS_FAIL_UNKNOWN_P2PGROUP;
  1912. p2p_ie = rtw_get_p2p_ie(frame_body + _PUBLIC_ACTION_IE_OFFSET_, len - _PUBLIC_ACTION_IE_OFFSET_, NULL, &p2p_ielen);
  1913. if (p2p_ie) {
  1914. u8 groupid[38] = { 0x00 };
  1915. u8 dev_addr[ETH_ALEN] = { 0x00 };
  1916. u32 attr_contentlen = 0;
  1917. if (rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_GROUP_ID, groupid, &attr_contentlen)) {
  1918. if (_rtw_memcmp(pwdinfo->device_addr, groupid, ETH_ALEN) &&
  1919. _rtw_memcmp(pwdinfo->p2p_group_ssid, groupid + ETH_ALEN, pwdinfo->p2p_group_ssid_len)) {
  1920. attr_contentlen = 0;
  1921. if (rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_DEVICE_ID, dev_addr, &attr_contentlen)) {
  1922. _irqL irqL;
  1923. _list *phead, *plist;
  1924. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  1925. phead = &pstapriv->asoc_list;
  1926. plist = get_next(phead);
  1927. /* look up sta asoc_queue */
  1928. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  1929. psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
  1930. plist = get_next(plist);
  1931. if (psta->is_p2p_device && (psta->dev_cap & P2P_DEVCAP_CLIENT_DISCOVERABILITY) &&
  1932. _rtw_memcmp(psta->dev_addr, dev_addr, ETH_ALEN)) {
  1933. /* _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL); */
  1934. /* issue GO Discoverability Request */
  1935. issue_group_disc_req(pwdinfo, psta->cmn.mac_addr);
  1936. /* _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL); */
  1937. status = P2P_STATUS_SUCCESS;
  1938. break;
  1939. } else
  1940. status = P2P_STATUS_FAIL_INFO_UNAVAILABLE;
  1941. }
  1942. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  1943. } else
  1944. status = P2P_STATUS_FAIL_INVALID_PARAM;
  1945. } else
  1946. status = P2P_STATUS_FAIL_INVALID_PARAM;
  1947. }
  1948. }
  1949. /* issue Device Discoverability Response */
  1950. issue_p2p_devdisc_resp(pwdinfo, get_addr2_ptr(pframe), status, dialogToken);
  1951. return (status == P2P_STATUS_SUCCESS) ? _TRUE : _FALSE;
  1952. }
  1953. u32 process_p2p_devdisc_resp(struct wifidirect_info *pwdinfo, u8 *pframe, uint len)
  1954. {
  1955. return _TRUE;
  1956. }
  1957. u8 process_p2p_provdisc_req(struct wifidirect_info *pwdinfo, u8 *pframe, uint len)
  1958. {
  1959. u8 *frame_body;
  1960. u8 *wpsie;
  1961. uint wps_ielen = 0, attr_contentlen = 0;
  1962. u16 uconfig_method = 0;
  1963. frame_body = (pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
  1964. wpsie = rtw_get_wps_ie(frame_body + _PUBLIC_ACTION_IE_OFFSET_, len - _PUBLIC_ACTION_IE_OFFSET_, NULL, &wps_ielen);
  1965. if (wpsie) {
  1966. if (rtw_get_wps_attr_content(wpsie, wps_ielen, WPS_ATTR_CONF_METHOD , (u8 *) &uconfig_method, &attr_contentlen)) {
  1967. uconfig_method = be16_to_cpu(uconfig_method);
  1968. switch (uconfig_method) {
  1969. case WPS_CM_DISPLYA: {
  1970. _rtw_memcpy(pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req, "dis", 3);
  1971. break;
  1972. }
  1973. case WPS_CM_LABEL: {
  1974. _rtw_memcpy(pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req, "lab", 3);
  1975. break;
  1976. }
  1977. case WPS_CM_PUSH_BUTTON: {
  1978. _rtw_memcpy(pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req, "pbc", 3);
  1979. break;
  1980. }
  1981. case WPS_CM_KEYPAD: {
  1982. _rtw_memcpy(pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req, "pad", 3);
  1983. break;
  1984. }
  1985. }
  1986. issue_p2p_provision_resp(pwdinfo, get_addr2_ptr(pframe), frame_body, uconfig_method);
  1987. }
  1988. }
  1989. RTW_INFO("[%s] config method = %s\n", __FUNCTION__, pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req);
  1990. return _TRUE;
  1991. }
  1992. u8 process_p2p_provdisc_resp(struct wifidirect_info *pwdinfo, u8 *pframe)
  1993. {
  1994. return _TRUE;
  1995. }
  1996. u8 rtw_p2p_get_peer_ch_list(struct wifidirect_info *pwdinfo, u8 *ch_content, u8 ch_cnt, u8 *peer_ch_list)
  1997. {
  1998. u8 i = 0, j = 0;
  1999. u8 temp = 0;
  2000. u8 ch_no = 0;
  2001. ch_content += 3;
  2002. ch_cnt -= 3;
  2003. while (ch_cnt > 0) {
  2004. ch_content += 1;
  2005. ch_cnt -= 1;
  2006. temp = *ch_content;
  2007. for (i = 0 ; i < temp ; i++, j++)
  2008. peer_ch_list[j] = *(ch_content + 1 + i);
  2009. ch_content += (temp + 1);
  2010. ch_cnt -= (temp + 1);
  2011. ch_no += temp ;
  2012. }
  2013. return ch_no;
  2014. }
  2015. u8 rtw_p2p_ch_inclusion(_adapter *adapter, u8 *peer_ch_list, u8 peer_ch_num, u8 *ch_list_inclusioned)
  2016. {
  2017. struct rf_ctl_t *rfctl = adapter_to_rfctl(adapter);
  2018. int i = 0, j = 0, temp = 0;
  2019. u8 ch_no = 0;
  2020. for (i = 0; i < peer_ch_num; i++) {
  2021. for (j = temp; j < rfctl->max_chan_nums; j++) {
  2022. if (*(peer_ch_list + i) == rfctl->channel_set[j].ChannelNum) {
  2023. ch_list_inclusioned[ch_no++] = *(peer_ch_list + i);
  2024. temp = j;
  2025. break;
  2026. }
  2027. }
  2028. }
  2029. return ch_no;
  2030. }
  2031. u8 process_p2p_group_negotation_req(struct wifidirect_info *pwdinfo, u8 *pframe, uint len)
  2032. {
  2033. _adapter *padapter = pwdinfo->padapter;
  2034. u8 result = P2P_STATUS_SUCCESS;
  2035. u32 p2p_ielen = 0, wps_ielen = 0;
  2036. u8 *ies;
  2037. u32 ies_len;
  2038. u8 *p2p_ie;
  2039. u8 *wpsie;
  2040. u16 wps_devicepassword_id = 0x0000;
  2041. uint wps_devicepassword_id_len = 0;
  2042. #ifdef CONFIG_WFD
  2043. #ifdef CONFIG_TDLS
  2044. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  2045. #endif /* CONFIG_TDLS */
  2046. #endif /* CONFIG_WFD */
  2047. wpsie = rtw_get_wps_ie(pframe + _PUBLIC_ACTION_IE_OFFSET_, len - _PUBLIC_ACTION_IE_OFFSET_, NULL, &wps_ielen);
  2048. if (wpsie) {
  2049. /* Commented by Kurt 20120113 */
  2050. /* If some device wants to do p2p handshake without sending prov_disc_req */
  2051. /* We have to get peer_req_cm from here. */
  2052. if (_rtw_memcmp(pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req, "000", 3)) {
  2053. rtw_get_wps_attr_content(wpsie, wps_ielen, WPS_ATTR_DEVICE_PWID, (u8 *) &wps_devicepassword_id, &wps_devicepassword_id_len);
  2054. wps_devicepassword_id = be16_to_cpu(wps_devicepassword_id);
  2055. if (wps_devicepassword_id == WPS_DPID_USER_SPEC)
  2056. _rtw_memcpy(pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req, "dis", 3);
  2057. else if (wps_devicepassword_id == WPS_DPID_REGISTRAR_SPEC)
  2058. _rtw_memcpy(pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req, "pad", 3);
  2059. else
  2060. _rtw_memcpy(pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req, "pbc", 3);
  2061. }
  2062. } else {
  2063. RTW_INFO("[%s] WPS IE not Found!!\n", __FUNCTION__);
  2064. result = P2P_STATUS_FAIL_INCOMPATIBLE_PARAM;
  2065. rtw_p2p_set_state(pwdinfo, P2P_STATE_GONEGO_FAIL);
  2066. return result ;
  2067. }
  2068. ies = pframe + _PUBLIC_ACTION_IE_OFFSET_;
  2069. ies_len = len - _PUBLIC_ACTION_IE_OFFSET_;
  2070. p2p_ie = rtw_get_p2p_ie(ies, ies_len, NULL, &p2p_ielen);
  2071. if (!p2p_ie) {
  2072. RTW_INFO("[%s] P2P IE not Found!!\n", __FUNCTION__);
  2073. result = P2P_STATUS_FAIL_INCOMPATIBLE_PARAM;
  2074. rtw_p2p_set_state(pwdinfo, P2P_STATE_GONEGO_FAIL);
  2075. }
  2076. while (p2p_ie) {
  2077. u8 attr_content = 0x00;
  2078. u32 attr_contentlen = 0;
  2079. u8 ch_content[100] = { 0x00 };
  2080. uint ch_cnt = 0;
  2081. u8 peer_ch_list[100] = { 0x00 };
  2082. u8 peer_ch_num = 0;
  2083. u8 ch_list_inclusioned[100] = { 0x00 };
  2084. u8 ch_num_inclusioned = 0;
  2085. u16 cap_attr;
  2086. u8 listen_ch_attr[5] = { 0x00 };
  2087. rtw_p2p_set_state(pwdinfo, P2P_STATE_GONEGO_ING);
  2088. /* Check P2P Capability ATTR */
  2089. if (rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_CAPABILITY, (u8 *)&cap_attr, (uint *)&attr_contentlen)) {
  2090. cap_attr = le16_to_cpu(cap_attr);
  2091. #if defined(CONFIG_WFD) && defined(CONFIG_TDLS)
  2092. if (!(cap_attr & P2P_GRPCAP_INTRABSS))
  2093. ptdlsinfo->ap_prohibited = _TRUE;
  2094. #endif /* defined(CONFIG_WFD) && defined(CONFIG_TDLS) */
  2095. }
  2096. if (rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_GO_INTENT , &attr_content, &attr_contentlen)) {
  2097. RTW_INFO("[%s] GO Intent = %d, tie = %d\n", __FUNCTION__, attr_content >> 1, attr_content & 0x01);
  2098. pwdinfo->peer_intent = attr_content; /* include both intent and tie breaker values. */
  2099. if (pwdinfo->intent == (pwdinfo->peer_intent >> 1)) {
  2100. /* Try to match the tie breaker value */
  2101. if (pwdinfo->intent == P2P_MAX_INTENT) {
  2102. rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
  2103. result = P2P_STATUS_FAIL_BOTH_GOINTENT_15;
  2104. } else {
  2105. if (attr_content & 0x01)
  2106. rtw_p2p_set_role(pwdinfo, P2P_ROLE_CLIENT);
  2107. else
  2108. rtw_p2p_set_role(pwdinfo, P2P_ROLE_GO);
  2109. }
  2110. } else if (pwdinfo->intent > (pwdinfo->peer_intent >> 1))
  2111. rtw_p2p_set_role(pwdinfo, P2P_ROLE_GO);
  2112. else
  2113. rtw_p2p_set_role(pwdinfo, P2P_ROLE_CLIENT);
  2114. if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
  2115. /* Store the group id information. */
  2116. _rtw_memcpy(pwdinfo->groupid_info.go_device_addr, pwdinfo->device_addr, ETH_ALEN);
  2117. _rtw_memcpy(pwdinfo->groupid_info.ssid, pwdinfo->nego_ssid, pwdinfo->nego_ssidlen);
  2118. }
  2119. }
  2120. if (rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_LISTEN_CH, (u8 *)listen_ch_attr, (uint *) &attr_contentlen) && attr_contentlen == 5)
  2121. pwdinfo->nego_req_info.peer_ch = listen_ch_attr[4];
  2122. RTW_INFO(FUNC_ADPT_FMT" listen channel :%u\n", FUNC_ADPT_ARG(padapter), pwdinfo->nego_req_info.peer_ch);
  2123. attr_contentlen = 0;
  2124. if (rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_INTENDED_IF_ADDR, pwdinfo->p2p_peer_interface_addr, &attr_contentlen)) {
  2125. if (attr_contentlen != ETH_ALEN)
  2126. _rtw_memset(pwdinfo->p2p_peer_interface_addr, 0x00, ETH_ALEN);
  2127. }
  2128. if (rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_CH_LIST, ch_content, &ch_cnt)) {
  2129. peer_ch_num = rtw_p2p_get_peer_ch_list(pwdinfo, ch_content, ch_cnt, peer_ch_list);
  2130. ch_num_inclusioned = rtw_p2p_ch_inclusion(padapter, peer_ch_list, peer_ch_num, ch_list_inclusioned);
  2131. if (ch_num_inclusioned == 0) {
  2132. RTW_INFO("[%s] No common channel in channel list!\n", __FUNCTION__);
  2133. result = P2P_STATUS_FAIL_NO_COMMON_CH;
  2134. rtw_p2p_set_state(pwdinfo, P2P_STATE_GONEGO_FAIL);
  2135. break;
  2136. }
  2137. if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
  2138. if (!rtw_p2p_is_channel_list_ok(pwdinfo->operating_channel,
  2139. ch_list_inclusioned, ch_num_inclusioned)) {
  2140. #ifdef CONFIG_CONCURRENT_MODE
  2141. if (rtw_mi_check_status(padapter, MI_LINKED)
  2142. && padapter->registrypriv.full_ch_in_p2p_handshake == 0) {
  2143. RTW_INFO("[%s] desired channel NOT Found!\n", __FUNCTION__);
  2144. result = P2P_STATUS_FAIL_NO_COMMON_CH;
  2145. rtw_p2p_set_state(pwdinfo, P2P_STATE_GONEGO_FAIL);
  2146. break;
  2147. } else
  2148. #endif /* CONFIG_CONCURRENT_MODE */
  2149. {
  2150. u8 operatingch_info[5] = { 0x00 }, peer_operating_ch = 0;
  2151. attr_contentlen = 0;
  2152. if (rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_OPERATING_CH, operatingch_info, &attr_contentlen))
  2153. peer_operating_ch = operatingch_info[4];
  2154. if (rtw_p2p_is_channel_list_ok(peer_operating_ch,
  2155. ch_list_inclusioned, ch_num_inclusioned)) {
  2156. /**
  2157. * Change our operating channel as peer's for compatibility.
  2158. */
  2159. pwdinfo->operating_channel = peer_operating_ch;
  2160. RTW_INFO("[%s] Change op ch to %02x as peer's\n", __FUNCTION__, pwdinfo->operating_channel);
  2161. } else {
  2162. /* Take first channel of ch_list_inclusioned as operating channel */
  2163. pwdinfo->operating_channel = ch_list_inclusioned[0];
  2164. RTW_INFO("[%s] Change op ch to %02x\n", __FUNCTION__, pwdinfo->operating_channel);
  2165. }
  2166. }
  2167. }
  2168. }
  2169. }
  2170. /* Get the next P2P IE */
  2171. p2p_ie = rtw_get_p2p_ie(p2p_ie + p2p_ielen, ies_len - (p2p_ie - ies + p2p_ielen), NULL, &p2p_ielen);
  2172. }
  2173. if (pwdinfo->ui_got_wps_info == P2P_NO_WPSINFO) {
  2174. result = P2P_STATUS_FAIL_INFO_UNAVAILABLE;
  2175. rtw_p2p_set_state(pwdinfo, P2P_STATE_TX_INFOR_NOREADY);
  2176. return result;
  2177. }
  2178. #ifdef CONFIG_WFD
  2179. rtw_process_wfd_ies(padapter, pframe + _PUBLIC_ACTION_IE_OFFSET_, len - _PUBLIC_ACTION_IE_OFFSET_, __func__);
  2180. #endif
  2181. return result ;
  2182. }
  2183. u8 process_p2p_group_negotation_resp(struct wifidirect_info *pwdinfo, u8 *pframe, uint len)
  2184. {
  2185. _adapter *padapter = pwdinfo->padapter;
  2186. u8 result = P2P_STATUS_SUCCESS;
  2187. u32 p2p_ielen, wps_ielen;
  2188. u8 *ies;
  2189. u32 ies_len;
  2190. u8 *p2p_ie;
  2191. #ifdef CONFIG_WFD
  2192. #ifdef CONFIG_TDLS
  2193. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  2194. #endif /* CONFIG_TDLS */
  2195. #endif /* CONFIG_WFD */
  2196. ies = pframe + _PUBLIC_ACTION_IE_OFFSET_;
  2197. ies_len = len - _PUBLIC_ACTION_IE_OFFSET_;
  2198. /* Be able to know which one is the P2P GO and which one is P2P client. */
  2199. if (rtw_get_wps_ie(ies, ies_len, NULL, &wps_ielen)) {
  2200. } else {
  2201. RTW_INFO("[%s] WPS IE not Found!!\n", __FUNCTION__);
  2202. result = P2P_STATUS_FAIL_INCOMPATIBLE_PARAM;
  2203. rtw_p2p_set_state(pwdinfo, P2P_STATE_GONEGO_FAIL);
  2204. }
  2205. p2p_ie = rtw_get_p2p_ie(ies, ies_len, NULL, &p2p_ielen);
  2206. if (!p2p_ie) {
  2207. rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
  2208. rtw_p2p_set_state(pwdinfo, P2P_STATE_GONEGO_FAIL);
  2209. result = P2P_STATUS_FAIL_INCOMPATIBLE_PARAM;
  2210. } else {
  2211. u8 attr_content = 0x00;
  2212. u32 attr_contentlen = 0;
  2213. u8 operatingch_info[5] = { 0x00 };
  2214. u8 groupid[38];
  2215. u16 cap_attr;
  2216. u8 peer_ch_list[100] = { 0x00 };
  2217. u8 peer_ch_num = 0;
  2218. u8 ch_list_inclusioned[100] = { 0x00 };
  2219. u8 ch_num_inclusioned = 0;
  2220. while (p2p_ie) { /* Found the P2P IE. */
  2221. /* Check P2P Capability ATTR */
  2222. if (rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_CAPABILITY, (u8 *)&cap_attr, (uint *)&attr_contentlen)) {
  2223. cap_attr = le16_to_cpu(cap_attr);
  2224. #ifdef CONFIG_TDLS
  2225. if (!(cap_attr & P2P_GRPCAP_INTRABSS))
  2226. ptdlsinfo->ap_prohibited = _TRUE;
  2227. #endif /* CONFIG_TDLS */
  2228. }
  2229. rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_STATUS, &attr_content, &attr_contentlen);
  2230. if (attr_contentlen == 1) {
  2231. RTW_INFO("[%s] Status = %d\n", __FUNCTION__, attr_content);
  2232. if (attr_content == P2P_STATUS_SUCCESS) {
  2233. /* Do nothing. */
  2234. } else {
  2235. if (P2P_STATUS_FAIL_INFO_UNAVAILABLE == attr_content)
  2236. rtw_p2p_set_state(pwdinfo, P2P_STATE_RX_INFOR_NOREADY);
  2237. else
  2238. rtw_p2p_set_state(pwdinfo, P2P_STATE_GONEGO_FAIL);
  2239. rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
  2240. result = attr_content;
  2241. break;
  2242. }
  2243. }
  2244. /* Try to get the peer's interface address */
  2245. attr_contentlen = 0;
  2246. if (rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_INTENDED_IF_ADDR, pwdinfo->p2p_peer_interface_addr, &attr_contentlen)) {
  2247. if (attr_contentlen != ETH_ALEN)
  2248. _rtw_memset(pwdinfo->p2p_peer_interface_addr, 0x00, ETH_ALEN);
  2249. }
  2250. /* Try to get the peer's intent and tie breaker value. */
  2251. attr_content = 0x00;
  2252. attr_contentlen = 0;
  2253. if (rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_GO_INTENT , &attr_content, &attr_contentlen)) {
  2254. RTW_INFO("[%s] GO Intent = %d, tie = %d\n", __FUNCTION__, attr_content >> 1, attr_content & 0x01);
  2255. pwdinfo->peer_intent = attr_content; /* include both intent and tie breaker values. */
  2256. if (pwdinfo->intent == (pwdinfo->peer_intent >> 1)) {
  2257. /* Try to match the tie breaker value */
  2258. if (pwdinfo->intent == P2P_MAX_INTENT) {
  2259. rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
  2260. result = P2P_STATUS_FAIL_BOTH_GOINTENT_15;
  2261. rtw_p2p_set_state(pwdinfo, P2P_STATE_GONEGO_FAIL);
  2262. } else {
  2263. rtw_p2p_set_state(pwdinfo, P2P_STATE_GONEGO_OK);
  2264. rtw_p2p_set_pre_state(pwdinfo, P2P_STATE_GONEGO_OK);
  2265. if (attr_content & 0x01)
  2266. rtw_p2p_set_role(pwdinfo, P2P_ROLE_CLIENT);
  2267. else
  2268. rtw_p2p_set_role(pwdinfo, P2P_ROLE_GO);
  2269. }
  2270. } else if (pwdinfo->intent > (pwdinfo->peer_intent >> 1)) {
  2271. rtw_p2p_set_state(pwdinfo, P2P_STATE_GONEGO_OK);
  2272. rtw_p2p_set_pre_state(pwdinfo, P2P_STATE_GONEGO_OK);
  2273. rtw_p2p_set_role(pwdinfo, P2P_ROLE_GO);
  2274. } else {
  2275. rtw_p2p_set_state(pwdinfo, P2P_STATE_GONEGO_OK);
  2276. rtw_p2p_set_pre_state(pwdinfo, P2P_STATE_GONEGO_OK);
  2277. rtw_p2p_set_role(pwdinfo, P2P_ROLE_CLIENT);
  2278. }
  2279. if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
  2280. /* Store the group id information. */
  2281. _rtw_memcpy(pwdinfo->groupid_info.go_device_addr, pwdinfo->device_addr, ETH_ALEN);
  2282. _rtw_memcpy(pwdinfo->groupid_info.ssid, pwdinfo->nego_ssid, pwdinfo->nego_ssidlen);
  2283. }
  2284. }
  2285. /* Try to get the operation channel information */
  2286. attr_contentlen = 0;
  2287. if (rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_OPERATING_CH, operatingch_info, &attr_contentlen)) {
  2288. RTW_INFO("[%s] Peer's operating channel = %d\n", __FUNCTION__, operatingch_info[4]);
  2289. pwdinfo->peer_operating_ch = operatingch_info[4];
  2290. }
  2291. /* Try to get the channel list information */
  2292. if (rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_CH_LIST, pwdinfo->channel_list_attr, &pwdinfo->channel_list_attr_len)) {
  2293. RTW_INFO("[%s] channel list attribute found, len = %d\n", __FUNCTION__, pwdinfo->channel_list_attr_len);
  2294. peer_ch_num = rtw_p2p_get_peer_ch_list(pwdinfo, pwdinfo->channel_list_attr, pwdinfo->channel_list_attr_len, peer_ch_list);
  2295. ch_num_inclusioned = rtw_p2p_ch_inclusion(padapter, peer_ch_list, peer_ch_num, ch_list_inclusioned);
  2296. if (ch_num_inclusioned == 0) {
  2297. RTW_INFO("[%s] No common channel in channel list!\n", __FUNCTION__);
  2298. result = P2P_STATUS_FAIL_NO_COMMON_CH;
  2299. rtw_p2p_set_state(pwdinfo, P2P_STATE_GONEGO_FAIL);
  2300. break;
  2301. }
  2302. if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
  2303. if (!rtw_p2p_is_channel_list_ok(pwdinfo->operating_channel,
  2304. ch_list_inclusioned, ch_num_inclusioned)) {
  2305. #ifdef CONFIG_CONCURRENT_MODE
  2306. if (rtw_mi_check_status(padapter, MI_LINKED)
  2307. && padapter->registrypriv.full_ch_in_p2p_handshake == 0) {
  2308. RTW_INFO("[%s] desired channel NOT Found!\n", __FUNCTION__);
  2309. result = P2P_STATUS_FAIL_NO_COMMON_CH;
  2310. rtw_p2p_set_state(pwdinfo, P2P_STATE_GONEGO_FAIL);
  2311. break;
  2312. } else
  2313. #endif /* CONFIG_CONCURRENT_MODE */
  2314. {
  2315. u8 operatingch_info[5] = { 0x00 }, peer_operating_ch = 0;
  2316. attr_contentlen = 0;
  2317. if (rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_OPERATING_CH, operatingch_info, &attr_contentlen))
  2318. peer_operating_ch = operatingch_info[4];
  2319. if (rtw_p2p_is_channel_list_ok(peer_operating_ch,
  2320. ch_list_inclusioned, ch_num_inclusioned)) {
  2321. /**
  2322. * Change our operating channel as peer's for compatibility.
  2323. */
  2324. pwdinfo->operating_channel = peer_operating_ch;
  2325. RTW_INFO("[%s] Change op ch to %02x as peer's\n", __FUNCTION__, pwdinfo->operating_channel);
  2326. } else {
  2327. /* Take first channel of ch_list_inclusioned as operating channel */
  2328. pwdinfo->operating_channel = ch_list_inclusioned[0];
  2329. RTW_INFO("[%s] Change op ch to %02x\n", __FUNCTION__, pwdinfo->operating_channel);
  2330. }
  2331. }
  2332. }
  2333. }
  2334. } else
  2335. RTW_INFO("[%s] channel list attribute not found!\n", __FUNCTION__);
  2336. /* Try to get the group id information if peer is GO */
  2337. attr_contentlen = 0;
  2338. _rtw_memset(groupid, 0x00, 38);
  2339. if (rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_GROUP_ID, groupid, &attr_contentlen)) {
  2340. _rtw_memcpy(pwdinfo->groupid_info.go_device_addr, &groupid[0], ETH_ALEN);
  2341. _rtw_memcpy(pwdinfo->groupid_info.ssid, &groupid[6], attr_contentlen - ETH_ALEN);
  2342. }
  2343. /* Get the next P2P IE */
  2344. p2p_ie = rtw_get_p2p_ie(p2p_ie + p2p_ielen, ies_len - (p2p_ie - ies + p2p_ielen), NULL, &p2p_ielen);
  2345. }
  2346. }
  2347. #ifdef CONFIG_WFD
  2348. rtw_process_wfd_ies(padapter, pframe + _PUBLIC_ACTION_IE_OFFSET_, len - _PUBLIC_ACTION_IE_OFFSET_, __func__);
  2349. #endif
  2350. return result ;
  2351. }
  2352. u8 process_p2p_group_negotation_confirm(struct wifidirect_info *pwdinfo, u8 *pframe, uint len)
  2353. {
  2354. #ifdef CONFIG_CONCURRENT_MODE
  2355. _adapter *padapter = pwdinfo->padapter;
  2356. #endif
  2357. u8 *ies;
  2358. u32 ies_len;
  2359. u8 *p2p_ie;
  2360. u32 p2p_ielen = 0;
  2361. u8 result = P2P_STATUS_SUCCESS;
  2362. ies = pframe + _PUBLIC_ACTION_IE_OFFSET_;
  2363. ies_len = len - _PUBLIC_ACTION_IE_OFFSET_;
  2364. p2p_ie = rtw_get_p2p_ie(ies, ies_len, NULL, &p2p_ielen);
  2365. while (p2p_ie) { /* Found the P2P IE. */
  2366. u8 attr_content = 0x00, operatingch_info[5] = { 0x00 };
  2367. u8 groupid[38] = { 0x00 };
  2368. u32 attr_contentlen = 0;
  2369. pwdinfo->negotiation_dialog_token = 1;
  2370. rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_STATUS, &attr_content, &attr_contentlen);
  2371. if (attr_contentlen == 1) {
  2372. RTW_INFO("[%s] Status = %d\n", __FUNCTION__, attr_content);
  2373. result = attr_content;
  2374. if (attr_content == P2P_STATUS_SUCCESS) {
  2375. _cancel_timer_ex(&pwdinfo->restore_p2p_state_timer);
  2376. /* Commented by Albert 20100911 */
  2377. /* Todo: Need to handle the case which both Intents are the same. */
  2378. rtw_p2p_set_state(pwdinfo, P2P_STATE_GONEGO_OK);
  2379. rtw_p2p_set_pre_state(pwdinfo, P2P_STATE_GONEGO_OK);
  2380. if ((pwdinfo->intent) > (pwdinfo->peer_intent >> 1))
  2381. rtw_p2p_set_role(pwdinfo, P2P_ROLE_GO);
  2382. else if ((pwdinfo->intent) < (pwdinfo->peer_intent >> 1))
  2383. rtw_p2p_set_role(pwdinfo, P2P_ROLE_CLIENT);
  2384. else {
  2385. /* Have to compare the Tie Breaker */
  2386. if (pwdinfo->peer_intent & 0x01)
  2387. rtw_p2p_set_role(pwdinfo, P2P_ROLE_CLIENT);
  2388. else
  2389. rtw_p2p_set_role(pwdinfo, P2P_ROLE_GO);
  2390. }
  2391. #ifdef CONFIG_CONCURRENT_MODE
  2392. if (rtw_mi_check_status(padapter, MI_LINKED)
  2393. && padapter->registrypriv.full_ch_in_p2p_handshake == 0) {
  2394. /* Switch back to the AP channel soon. */
  2395. _set_timer(&pwdinfo->ap_p2p_switch_timer, 100);
  2396. }
  2397. #endif
  2398. } else {
  2399. rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
  2400. rtw_p2p_set_state(pwdinfo, P2P_STATE_GONEGO_FAIL);
  2401. break;
  2402. }
  2403. }
  2404. /* Try to get the group id information */
  2405. attr_contentlen = 0;
  2406. _rtw_memset(groupid, 0x00, 38);
  2407. if (rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_GROUP_ID, groupid, &attr_contentlen)) {
  2408. RTW_INFO("[%s] Ssid = %s, ssidlen = %zu\n", __FUNCTION__, &groupid[ETH_ALEN], strlen(&groupid[ETH_ALEN]));
  2409. _rtw_memcpy(pwdinfo->groupid_info.go_device_addr, &groupid[0], ETH_ALEN);
  2410. _rtw_memcpy(pwdinfo->groupid_info.ssid, &groupid[6], attr_contentlen - ETH_ALEN);
  2411. }
  2412. attr_contentlen = 0;
  2413. if (rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_OPERATING_CH, operatingch_info, &attr_contentlen)) {
  2414. RTW_INFO("[%s] Peer's operating channel = %d\n", __FUNCTION__, operatingch_info[4]);
  2415. pwdinfo->peer_operating_ch = operatingch_info[4];
  2416. }
  2417. /* Get the next P2P IE */
  2418. p2p_ie = rtw_get_p2p_ie(p2p_ie + p2p_ielen, ies_len - (p2p_ie - ies + p2p_ielen), NULL, &p2p_ielen);
  2419. }
  2420. return result ;
  2421. }
  2422. u8 process_p2p_presence_req(struct wifidirect_info *pwdinfo, u8 *pframe, uint len)
  2423. {
  2424. u8 *frame_body;
  2425. u8 dialogToken = 0;
  2426. u8 status = P2P_STATUS_SUCCESS;
  2427. frame_body = (unsigned char *)(pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
  2428. dialogToken = frame_body[6];
  2429. /* todo: check NoA attribute */
  2430. issue_p2p_presence_resp(pwdinfo, get_addr2_ptr(pframe), status, dialogToken);
  2431. return _TRUE;
  2432. }
  2433. void find_phase_handler(_adapter *padapter)
  2434. {
  2435. struct wifidirect_info *pwdinfo = &padapter->wdinfo;
  2436. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  2437. struct sitesurvey_parm parm;
  2438. _irqL irqL;
  2439. u8 _status = 0;
  2440. rtw_init_sitesurvey_parm(padapter, &parm);
  2441. _rtw_memcpy(&parm.ssid[0].Ssid, pwdinfo->p2p_wildcard_ssid, P2P_WILDCARD_SSID_LEN);
  2442. parm.ssid[0].SsidLength = P2P_WILDCARD_SSID_LEN;
  2443. parm.ssid_num = 1;
  2444. rtw_p2p_set_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH);
  2445. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  2446. _status = rtw_sitesurvey_cmd(padapter, &parm);
  2447. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  2448. }
  2449. void p2p_concurrent_handler(_adapter *padapter);
  2450. void restore_p2p_state_handler(_adapter *padapter)
  2451. {
  2452. struct wifidirect_info *pwdinfo = &padapter->wdinfo;
  2453. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_ING) || rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_FAIL))
  2454. rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
  2455. #ifdef CONFIG_CONCURRENT_MODE
  2456. if (rtw_mi_check_status(padapter, MI_LINKED)) {
  2457. u8 union_ch = rtw_mi_get_union_chan(padapter);
  2458. u8 union_bw = rtw_mi_get_union_bw(padapter);
  2459. u8 union_offset = rtw_mi_get_union_offset(padapter);
  2460. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_TX_PROVISION_DIS_REQ) || rtw_p2p_chk_state(pwdinfo, P2P_STATE_RX_PROVISION_DIS_RSP)) {
  2461. set_channel_bwmode(padapter, union_ch, union_offset, union_bw);
  2462. rtw_back_opch(padapter);
  2463. }
  2464. }
  2465. #endif
  2466. rtw_p2p_set_state(pwdinfo, rtw_p2p_pre_state(pwdinfo));
  2467. if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_DEVICE)) {
  2468. #ifdef CONFIG_CONCURRENT_MODE
  2469. p2p_concurrent_handler(padapter);
  2470. #else
  2471. /* In the P2P client mode, the driver should not switch back to its listen channel */
  2472. /* because this P2P client should stay at the operating channel of P2P GO. */
  2473. set_channel_bwmode(padapter, pwdinfo->listen_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  2474. #endif
  2475. }
  2476. }
  2477. void pre_tx_invitereq_handler(_adapter *padapter)
  2478. {
  2479. struct wifidirect_info *pwdinfo = &padapter->wdinfo;
  2480. u8 val8 = 1;
  2481. set_channel_bwmode(padapter, pwdinfo->invitereq_info.peer_ch, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  2482. rtw_hal_set_hwreg(padapter, HW_VAR_MLME_SITESURVEY, (u8 *)(&val8));
  2483. issue_probereq_p2p(padapter, NULL);
  2484. _set_timer(&pwdinfo->pre_tx_scan_timer, P2P_TX_PRESCAN_TIMEOUT);
  2485. }
  2486. void pre_tx_provdisc_handler(_adapter *padapter)
  2487. {
  2488. struct wifidirect_info *pwdinfo = &padapter->wdinfo;
  2489. u8 val8 = 1;
  2490. set_channel_bwmode(padapter, pwdinfo->tx_prov_disc_info.peer_channel_num[0], HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  2491. rtw_hal_set_hwreg(padapter, HW_VAR_MLME_SITESURVEY, (u8 *)(&val8));
  2492. issue_probereq_p2p(padapter, NULL);
  2493. _set_timer(&pwdinfo->pre_tx_scan_timer, P2P_TX_PRESCAN_TIMEOUT);
  2494. }
  2495. void pre_tx_negoreq_handler(_adapter *padapter)
  2496. {
  2497. struct wifidirect_info *pwdinfo = &padapter->wdinfo;
  2498. u8 val8 = 1;
  2499. set_channel_bwmode(padapter, pwdinfo->nego_req_info.peer_channel_num[0], HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  2500. rtw_hal_set_hwreg(padapter, HW_VAR_MLME_SITESURVEY, (u8 *)(&val8));
  2501. issue_probereq_p2p(padapter , NULL);
  2502. /* WIN Phone only accept unicast probe request when nego back */
  2503. issue_probereq_p2p(padapter , pwdinfo->nego_req_info.peerDevAddr);
  2504. _set_timer(&pwdinfo->pre_tx_scan_timer, P2P_TX_PRESCAN_TIMEOUT);
  2505. }
  2506. #ifdef CONFIG_CONCURRENT_MODE
  2507. void p2p_concurrent_handler(_adapter *padapter)
  2508. {
  2509. struct wifidirect_info *pwdinfo = &padapter->wdinfo;
  2510. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  2511. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2512. u8 val8;
  2513. #ifdef CONFIG_IOCTL_CFG80211
  2514. if (pwdinfo->driver_interface == DRIVER_CFG80211
  2515. && !rtw_cfg80211_get_is_roch(padapter))
  2516. return;
  2517. #endif
  2518. if (rtw_mi_check_status(padapter, MI_LINKED)) {
  2519. u8 union_ch = rtw_mi_get_union_chan(padapter);
  2520. u8 union_bw = rtw_mi_get_union_bw(padapter);
  2521. u8 union_offset = rtw_mi_get_union_offset(padapter);
  2522. pwdinfo->operating_channel = union_ch;
  2523. if (pwdinfo->driver_interface == DRIVER_CFG80211) {
  2524. RTW_INFO("%s, switch ch back to union=%u,%u, %u\n"
  2525. , __func__, union_ch, union_bw, union_offset);
  2526. set_channel_bwmode(padapter, union_ch, union_offset, union_bw);
  2527. rtw_back_opch(padapter);
  2528. } else if (pwdinfo->driver_interface == DRIVER_WEXT) {
  2529. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_IDLE)) {
  2530. /* Now, the driver stays on the AP's channel. */
  2531. /* If the pwdinfo->ext_listen_period = 0, that means the P2P listen state is not available on listen channel. */
  2532. if (pwdinfo->ext_listen_period > 0) {
  2533. RTW_INFO("[%s] P2P_STATE_IDLE, ext_listen_period = %d\n", __FUNCTION__, pwdinfo->ext_listen_period);
  2534. if (union_ch != pwdinfo->listen_channel) {
  2535. rtw_leave_opch(padapter);
  2536. set_channel_bwmode(padapter, pwdinfo->listen_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  2537. }
  2538. rtw_p2p_set_state(pwdinfo, P2P_STATE_LISTEN);
  2539. if (!rtw_mi_check_mlmeinfo_state(padapter, WIFI_FW_AP_STATE)) {
  2540. val8 = 1;
  2541. rtw_hal_set_hwreg(padapter, HW_VAR_MLME_SITESURVEY, (u8 *)(&val8));
  2542. }
  2543. /* Todo: To check the value of pwdinfo->ext_listen_period is equal to 0 or not. */
  2544. _set_timer(&pwdinfo->ap_p2p_switch_timer, pwdinfo->ext_listen_period);
  2545. }
  2546. } else if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_LISTEN) ||
  2547. rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_FAIL) ||
  2548. (rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_ING) && pwdinfo->nego_req_info.benable == _FALSE) ||
  2549. rtw_p2p_chk_state(pwdinfo, P2P_STATE_RX_PROVISION_DIS_REQ)) {
  2550. /* Now, the driver is in the listen state of P2P mode. */
  2551. RTW_INFO("[%s] P2P_STATE_IDLE, ext_listen_interval = %d\n", __FUNCTION__, pwdinfo->ext_listen_interval);
  2552. /* Commented by Albert 2012/11/01 */
  2553. /* If the AP's channel is the same as the listen channel, we should still be in the listen state */
  2554. /* Other P2P device is still able to find this device out even this device is in the AP's channel. */
  2555. /* So, configure this device to be able to receive the probe request frame and set it to listen state. */
  2556. if (union_ch != pwdinfo->listen_channel) {
  2557. set_channel_bwmode(padapter, union_ch, union_offset, union_bw);
  2558. if (!rtw_mi_check_status(padapter, MI_AP_MODE)) {
  2559. val8 = 0;
  2560. rtw_hal_set_hwreg(padapter, HW_VAR_MLME_SITESURVEY, (u8 *)(&val8));
  2561. }
  2562. rtw_p2p_set_state(pwdinfo, P2P_STATE_IDLE);
  2563. rtw_back_opch(padapter);
  2564. }
  2565. /* Todo: To check the value of pwdinfo->ext_listen_interval is equal to 0 or not. */
  2566. _set_timer(&pwdinfo->ap_p2p_switch_timer, pwdinfo->ext_listen_interval);
  2567. } else if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_OK)) {
  2568. /* The driver had finished the P2P handshake successfully. */
  2569. val8 = 0;
  2570. rtw_hal_set_hwreg(padapter, HW_VAR_MLME_SITESURVEY, (u8 *)(&val8));
  2571. set_channel_bwmode(padapter, union_ch, union_offset, union_bw);
  2572. rtw_back_opch(padapter);
  2573. } else if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_TX_PROVISION_DIS_REQ)) {
  2574. val8 = 1;
  2575. set_channel_bwmode(padapter, pwdinfo->tx_prov_disc_info.peer_channel_num[0], HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  2576. rtw_hal_set_hwreg(padapter, HW_VAR_MLME_SITESURVEY, (u8 *)(&val8));
  2577. issue_probereq_p2p(padapter, NULL);
  2578. _set_timer(&pwdinfo->pre_tx_scan_timer, P2P_TX_PRESCAN_TIMEOUT);
  2579. } else if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_ING) && pwdinfo->nego_req_info.benable == _TRUE) {
  2580. val8 = 1;
  2581. set_channel_bwmode(padapter, pwdinfo->nego_req_info.peer_channel_num[0], HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  2582. rtw_hal_set_hwreg(padapter, HW_VAR_MLME_SITESURVEY, (u8 *)(&val8));
  2583. issue_probereq_p2p(padapter, NULL);
  2584. _set_timer(&pwdinfo->pre_tx_scan_timer, P2P_TX_PRESCAN_TIMEOUT);
  2585. } else if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_TX_INVITE_REQ) && pwdinfo->invitereq_info.benable == _TRUE) {
  2586. /*
  2587. val8 = 1;
  2588. set_channel_bwmode(padapter, , HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  2589. rtw_hal_set_hwreg(padapter, HW_VAR_MLME_SITESURVEY, (u8 *)(&val8));
  2590. issue_probereq_p2p(padapter, NULL);
  2591. _set_timer( &pwdinfo->pre_tx_scan_timer, P2P_TX_PRESCAN_TIMEOUT );
  2592. */
  2593. }
  2594. }
  2595. } else {
  2596. /* In p2p+softap. When in P2P_STATE_GONEGO_OK, not back to listen channel.*/
  2597. if (!rtw_p2p_chk_state(pwdinfo , P2P_STATE_GONEGO_OK) || padapter->registrypriv.full_ch_in_p2p_handshake == 0)
  2598. set_channel_bwmode(padapter, pwdinfo->listen_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  2599. else
  2600. RTW_INFO("%s, buddy not linked, go nego ok, not back to listen channel\n", __func__);
  2601. }
  2602. }
  2603. #endif
  2604. #ifdef CONFIG_IOCTL_CFG80211
  2605. u8 roch_stay_in_cur_chan(_adapter *padapter)
  2606. {
  2607. int i;
  2608. _adapter *iface;
  2609. struct mlme_priv *pmlmepriv;
  2610. struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
  2611. u8 rst = _FALSE;
  2612. for (i = 0; i < dvobj->iface_nums; i++) {
  2613. iface = dvobj->padapters[i];
  2614. if (iface) {
  2615. pmlmepriv = &iface->mlmepriv;
  2616. if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING | WIFI_UNDER_WPS | WIFI_UNDER_KEY_HANDSHAKE) == _TRUE) {
  2617. RTW_INFO(ADPT_FMT"- _FW_UNDER_LINKING |WIFI_UNDER_WPS | WIFI_UNDER_KEY_HANDSHAKE (mlme state:0x%x)\n",
  2618. ADPT_ARG(iface), get_fwstate(&iface->mlmepriv));
  2619. rst = _TRUE;
  2620. break;
  2621. }
  2622. #ifdef CONFIG_AP_MODE
  2623. if (MLME_IS_AP(iface) || MLME_IS_MESH(iface)) {
  2624. if (rtw_ap_sta_states_check(iface) == _TRUE) {
  2625. rst = _TRUE;
  2626. break;
  2627. }
  2628. }
  2629. #endif
  2630. }
  2631. }
  2632. return rst;
  2633. }
  2634. static int ro_ch_handler(_adapter *adapter, u8 *buf)
  2635. {
  2636. int ret = H2C_SUCCESS;
  2637. struct p2p_roch_parm *roch_parm = (struct p2p_roch_parm *)buf;
  2638. struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(adapter);
  2639. struct cfg80211_wifidirect_info *pcfg80211_wdinfo = &adapter->cfg80211_wdinfo;
  2640. #ifdef CONFIG_CONCURRENT_MODE
  2641. struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
  2642. #ifdef RTW_ROCH_BACK_OP
  2643. struct wifidirect_info *pwdinfo = &adapter->wdinfo;
  2644. #endif
  2645. #endif
  2646. u8 ready_on_channel = _FALSE;
  2647. u8 remain_ch;
  2648. unsigned int duration;
  2649. _enter_critical_mutex(&pwdev_priv->roch_mutex, NULL);
  2650. if (rtw_cfg80211_get_is_roch(adapter) != _TRUE)
  2651. goto exit;
  2652. remain_ch = (u8)ieee80211_frequency_to_channel(roch_parm->ch.center_freq);
  2653. duration = roch_parm->duration;
  2654. RTW_INFO(FUNC_ADPT_FMT" ch:%u duration:%d, cookie:0x%llx\n"
  2655. , FUNC_ADPT_ARG(adapter), remain_ch, roch_parm->duration, roch_parm->cookie);
  2656. if (roch_parm->wdev && roch_parm->cookie) {
  2657. if (pcfg80211_wdinfo->ro_ch_wdev != roch_parm->wdev) {
  2658. RTW_WARN(FUNC_ADPT_FMT" ongoing wdev:%p, wdev:%p\n"
  2659. , FUNC_ADPT_ARG(adapter), pcfg80211_wdinfo->ro_ch_wdev, roch_parm->wdev);
  2660. rtw_warn_on(1);
  2661. }
  2662. if (pcfg80211_wdinfo->remain_on_ch_cookie != roch_parm->cookie) {
  2663. RTW_WARN(FUNC_ADPT_FMT" ongoing cookie:0x%llx, cookie:0x%llx\n"
  2664. , FUNC_ADPT_ARG(adapter), pcfg80211_wdinfo->remain_on_ch_cookie, roch_parm->cookie);
  2665. rtw_warn_on(1);
  2666. }
  2667. }
  2668. if (roch_stay_in_cur_chan(adapter) == _TRUE) {
  2669. remain_ch = rtw_mi_get_union_chan(adapter);
  2670. RTW_INFO(FUNC_ADPT_FMT" stay in union ch:%d\n", FUNC_ADPT_ARG(adapter), remain_ch);
  2671. }
  2672. #ifdef CONFIG_CONCURRENT_MODE
  2673. if (rtw_mi_check_status(adapter, MI_LINKED) && (0 != rtw_mi_get_union_chan(adapter))) {
  2674. if ((remain_ch != rtw_mi_get_union_chan(adapter)) && !check_fwstate(&adapter->mlmepriv, _FW_LINKED)) {
  2675. if (remain_ch != pmlmeext->cur_channel
  2676. #ifdef RTW_ROCH_BACK_OP
  2677. || ATOMIC_READ(&pwdev_priv->switch_ch_to) == 1
  2678. #endif
  2679. ) {
  2680. rtw_leave_opch(adapter);
  2681. #ifdef RTW_ROCH_BACK_OP
  2682. RTW_INFO("%s, set switch ch timer, duration=%d\n", __func__, duration - pwdinfo->ext_listen_interval);
  2683. ATOMIC_SET(&pwdev_priv->switch_ch_to, 0);
  2684. _set_timer(&pwdinfo->ap_p2p_switch_timer, duration - pwdinfo->ext_listen_interval);
  2685. #endif
  2686. }
  2687. }
  2688. ready_on_channel = _TRUE;
  2689. } else
  2690. #endif /* CONFIG_CONCURRENT_MODE */
  2691. {
  2692. if (remain_ch != rtw_get_oper_ch(adapter))
  2693. ready_on_channel = _TRUE;
  2694. }
  2695. if (ready_on_channel == _TRUE) {
  2696. #ifndef RTW_SINGLE_WIPHY
  2697. if (!check_fwstate(&adapter->mlmepriv, _FW_LINKED))
  2698. #endif
  2699. {
  2700. #ifdef CONFIG_CONCURRENT_MODE
  2701. if (rtw_get_oper_ch(adapter) != remain_ch)
  2702. #endif
  2703. {
  2704. /* if (!padapter->mlmepriv.LinkDetectInfo.bBusyTraffic) */
  2705. set_channel_bwmode(adapter, remain_ch, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  2706. }
  2707. }
  2708. }
  2709. #ifdef CONFIG_BT_COEXIST
  2710. rtw_btcoex_ScanNotify(adapter, _TRUE);
  2711. #endif
  2712. RTW_INFO("%s, set ro ch timer, duration=%d\n", __func__, duration);
  2713. _set_timer(&pcfg80211_wdinfo->remain_on_ch_timer, duration);
  2714. exit:
  2715. _exit_critical_mutex(&pwdev_priv->roch_mutex, NULL);
  2716. return ret;
  2717. }
  2718. static int cancel_ro_ch_handler(_adapter *padapter, u8 *buf)
  2719. {
  2720. int ret = H2C_SUCCESS;
  2721. struct p2p_roch_parm *roch_parm = (struct p2p_roch_parm *)buf;
  2722. struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(padapter);
  2723. struct cfg80211_wifidirect_info *pcfg80211_wdinfo = &padapter->cfg80211_wdinfo;
  2724. struct wireless_dev *wdev;
  2725. struct wifidirect_info *pwdinfo = &padapter->wdinfo;
  2726. u8 ch, bw, offset;
  2727. _enter_critical_mutex(&pwdev_priv->roch_mutex, NULL);
  2728. if (rtw_cfg80211_get_is_roch(padapter) != _TRUE)
  2729. goto exit;
  2730. if (roch_parm->wdev && roch_parm->cookie) {
  2731. if (pcfg80211_wdinfo->ro_ch_wdev != roch_parm->wdev) {
  2732. RTW_WARN(FUNC_ADPT_FMT" ongoing wdev:%p, wdev:%p\n"
  2733. , FUNC_ADPT_ARG(padapter), pcfg80211_wdinfo->ro_ch_wdev, roch_parm->wdev);
  2734. rtw_warn_on(1);
  2735. }
  2736. if (pcfg80211_wdinfo->remain_on_ch_cookie != roch_parm->cookie) {
  2737. RTW_WARN(FUNC_ADPT_FMT" ongoing cookie:0x%llx, cookie:0x%llx\n"
  2738. , FUNC_ADPT_ARG(padapter), pcfg80211_wdinfo->remain_on_ch_cookie, roch_parm->cookie);
  2739. rtw_warn_on(1);
  2740. }
  2741. }
  2742. #if defined(RTW_ROCH_BACK_OP) && defined(CONFIG_CONCURRENT_MODE)
  2743. _cancel_timer_ex(&pwdinfo->ap_p2p_switch_timer);
  2744. ATOMIC_SET(&pwdev_priv->switch_ch_to, 1);
  2745. #endif
  2746. if (rtw_mi_get_ch_setting_union(padapter, &ch, &bw, &offset) != 0) {
  2747. if (0)
  2748. RTW_INFO(FUNC_ADPT_FMT" back to linked/linking union - ch:%u, bw:%u, offset:%u\n",
  2749. FUNC_ADPT_ARG(padapter), ch, bw, offset);
  2750. } else if (adapter_wdev_data(padapter)->p2p_enabled && pwdinfo->listen_channel) {
  2751. ch = pwdinfo->listen_channel;
  2752. bw = CHANNEL_WIDTH_20;
  2753. offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  2754. if (0)
  2755. RTW_INFO(FUNC_ADPT_FMT" back to listen ch - ch:%u, bw:%u, offset:%u\n",
  2756. FUNC_ADPT_ARG(padapter), ch, bw, offset);
  2757. } else {
  2758. ch = pcfg80211_wdinfo->restore_channel;
  2759. bw = CHANNEL_WIDTH_20;
  2760. offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  2761. if (0)
  2762. RTW_INFO(FUNC_ADPT_FMT" back to restore ch - ch:%u, bw:%u, offset:%u\n",
  2763. FUNC_ADPT_ARG(padapter), ch, bw, offset);
  2764. }
  2765. set_channel_bwmode(padapter, ch, offset, bw);
  2766. rtw_back_opch(padapter);
  2767. rtw_p2p_set_state(pwdinfo, rtw_p2p_pre_state(pwdinfo));
  2768. #ifdef CONFIG_DEBUG_CFG80211
  2769. RTW_INFO("%s, role=%d, p2p_state=%d\n", __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo));
  2770. #endif
  2771. wdev = pcfg80211_wdinfo->ro_ch_wdev;
  2772. rtw_cfg80211_set_is_roch(padapter, _FALSE);
  2773. pcfg80211_wdinfo->ro_ch_wdev = NULL;
  2774. rtw_cfg80211_set_last_ro_ch_time(padapter);
  2775. rtw_cfg80211_remain_on_channel_expired(wdev
  2776. , pcfg80211_wdinfo->remain_on_ch_cookie
  2777. , &pcfg80211_wdinfo->remain_on_ch_channel
  2778. , pcfg80211_wdinfo->remain_on_ch_type, GFP_KERNEL);
  2779. RTW_INFO("cfg80211_remain_on_channel_expired cookie:0x%llx\n"
  2780. , pcfg80211_wdinfo->remain_on_ch_cookie);
  2781. #ifdef CONFIG_BT_COEXIST
  2782. rtw_btcoex_ScanNotify(padapter, _FALSE);
  2783. #endif
  2784. exit:
  2785. _exit_critical_mutex(&pwdev_priv->roch_mutex, NULL);
  2786. return ret;
  2787. }
  2788. static void ro_ch_timer_process(void *FunctionContext)
  2789. {
  2790. _adapter *adapter = (_adapter *)FunctionContext;
  2791. p2p_cancel_roch_cmd(adapter, 0, NULL, 0);
  2792. }
  2793. #if 0
  2794. static void rtw_change_p2pie_op_ch(_adapter *padapter, const u8 *frame_body, u32 len, u8 ch)
  2795. {
  2796. u8 *ies, *p2p_ie;
  2797. u32 ies_len, p2p_ielen;
  2798. #ifdef CONFIG_MCC_MODE
  2799. if (MCC_EN(padapter))
  2800. return;
  2801. #endif /* CONFIG_MCC_MODE */
  2802. ies = (u8 *)(frame_body + _PUBLIC_ACTION_IE_OFFSET_);
  2803. ies_len = len - _PUBLIC_ACTION_IE_OFFSET_;
  2804. p2p_ie = rtw_get_p2p_ie(ies, ies_len, NULL, &p2p_ielen);
  2805. while (p2p_ie) {
  2806. u32 attr_contentlen = 0;
  2807. u8 *pattr = NULL;
  2808. /* Check P2P_ATTR_OPERATING_CH */
  2809. attr_contentlen = 0;
  2810. pattr = NULL;
  2811. pattr = rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_OPERATING_CH, NULL, (uint *)&attr_contentlen);
  2812. if (pattr != NULL)
  2813. *(pattr + 4) = ch;
  2814. /* Get the next P2P IE */
  2815. p2p_ie = rtw_get_p2p_ie(p2p_ie + p2p_ielen, ies_len - (p2p_ie - ies + p2p_ielen), NULL, &p2p_ielen);
  2816. }
  2817. }
  2818. #endif
  2819. #if defined(CONFIG_CONCURRENT_MODE) && defined(CONFIG_CFG80211_ONECHANNEL_UNDER_CONCURRENT)
  2820. static void rtw_change_p2pie_ch_list(_adapter *padapter, const u8 *frame_body, u32 len, u8 ch)
  2821. {
  2822. u8 *ies, *p2p_ie;
  2823. u32 ies_len, p2p_ielen;
  2824. #ifdef CONFIG_MCC_MODE
  2825. if (MCC_EN(padapter))
  2826. return;
  2827. #endif /* CONFIG_MCC_MODE */
  2828. ies = (u8 *)(frame_body + _PUBLIC_ACTION_IE_OFFSET_);
  2829. ies_len = len - _PUBLIC_ACTION_IE_OFFSET_;
  2830. p2p_ie = rtw_get_p2p_ie(ies, ies_len, NULL, &p2p_ielen);
  2831. while (p2p_ie) {
  2832. u32 attr_contentlen = 0;
  2833. u8 *pattr = NULL;
  2834. /* Check P2P_ATTR_CH_LIST */
  2835. pattr = rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_CH_LIST, NULL, (uint *)&attr_contentlen);
  2836. if (pattr != NULL) {
  2837. int i;
  2838. u32 num_of_ch;
  2839. u8 *pattr_temp = pattr + 3 ;
  2840. attr_contentlen -= 3;
  2841. while (attr_contentlen > 0) {
  2842. num_of_ch = *(pattr_temp + 1);
  2843. for (i = 0; i < num_of_ch; i++)
  2844. *(pattr_temp + 2 + i) = ch;
  2845. pattr_temp += (2 + num_of_ch);
  2846. attr_contentlen -= (2 + num_of_ch);
  2847. }
  2848. }
  2849. /* Get the next P2P IE */
  2850. p2p_ie = rtw_get_p2p_ie(p2p_ie + p2p_ielen, ies_len - (p2p_ie - ies + p2p_ielen), NULL, &p2p_ielen);
  2851. }
  2852. }
  2853. #endif
  2854. #if defined(CONFIG_CONCURRENT_MODE) && defined(CONFIG_CFG80211_ONECHANNEL_UNDER_CONCURRENT)
  2855. static bool rtw_chk_p2pie_ch_list_with_buddy(_adapter *padapter, const u8 *frame_body, u32 len)
  2856. {
  2857. bool fit = _FALSE;
  2858. u8 *ies, *p2p_ie;
  2859. u32 ies_len, p2p_ielen;
  2860. u8 union_ch = rtw_mi_get_union_chan(padapter);
  2861. ies = (u8 *)(frame_body + _PUBLIC_ACTION_IE_OFFSET_);
  2862. ies_len = len - _PUBLIC_ACTION_IE_OFFSET_;
  2863. p2p_ie = rtw_get_p2p_ie(ies, ies_len, NULL, &p2p_ielen);
  2864. while (p2p_ie) {
  2865. u32 attr_contentlen = 0;
  2866. u8 *pattr = NULL;
  2867. /* Check P2P_ATTR_CH_LIST */
  2868. pattr = rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_CH_LIST, NULL, (uint *)&attr_contentlen);
  2869. if (pattr != NULL) {
  2870. int i;
  2871. u32 num_of_ch;
  2872. u8 *pattr_temp = pattr + 3 ;
  2873. attr_contentlen -= 3;
  2874. while (attr_contentlen > 0) {
  2875. num_of_ch = *(pattr_temp + 1);
  2876. for (i = 0; i < num_of_ch; i++) {
  2877. if (*(pattr_temp + 2 + i) == union_ch) {
  2878. RTW_INFO(FUNC_ADPT_FMT" ch_list fit buddy_ch:%u\n", FUNC_ADPT_ARG(padapter), union_ch);
  2879. fit = _TRUE;
  2880. break;
  2881. }
  2882. }
  2883. pattr_temp += (2 + num_of_ch);
  2884. attr_contentlen -= (2 + num_of_ch);
  2885. }
  2886. }
  2887. /* Get the next P2P IE */
  2888. p2p_ie = rtw_get_p2p_ie(p2p_ie + p2p_ielen, ies_len - (p2p_ie - ies + p2p_ielen), NULL, &p2p_ielen);
  2889. }
  2890. return fit;
  2891. }
  2892. #if defined(CONFIG_P2P_INVITE_IOT)
  2893. static bool rtw_chk_p2pie_op_ch_with_buddy(_adapter *padapter, const u8 *frame_body, u32 len)
  2894. {
  2895. bool fit = _FALSE;
  2896. u8 *ies, *p2p_ie;
  2897. u32 ies_len, p2p_ielen;
  2898. u8 union_ch = rtw_mi_get_union_chan(padapter);
  2899. ies = (u8 *)(frame_body + _PUBLIC_ACTION_IE_OFFSET_);
  2900. ies_len = len - _PUBLIC_ACTION_IE_OFFSET_;
  2901. p2p_ie = rtw_get_p2p_ie(ies, ies_len, NULL, &p2p_ielen);
  2902. while (p2p_ie) {
  2903. u32 attr_contentlen = 0;
  2904. u8 *pattr = NULL;
  2905. /* Check P2P_ATTR_OPERATING_CH */
  2906. attr_contentlen = 0;
  2907. pattr = NULL;
  2908. pattr = rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_OPERATING_CH, NULL, (uint *)&attr_contentlen);
  2909. if (pattr != NULL) {
  2910. if (*(pattr + 4) == union_ch) {
  2911. RTW_INFO(FUNC_ADPT_FMT" op_ch fit buddy_ch:%u\n", FUNC_ADPT_ARG(padapter), union_ch);
  2912. fit = _TRUE;
  2913. break;
  2914. }
  2915. }
  2916. /* Get the next P2P IE */
  2917. p2p_ie = rtw_get_p2p_ie(p2p_ie + p2p_ielen, ies_len - (p2p_ie - ies + p2p_ielen), NULL, &p2p_ielen);
  2918. }
  2919. return fit;
  2920. }
  2921. #endif
  2922. static void rtw_cfg80211_adjust_p2pie_channel(_adapter *padapter, const u8 *frame_body, u32 len)
  2923. {
  2924. u8 *ies, *p2p_ie;
  2925. u32 ies_len, p2p_ielen;
  2926. u8 union_ch = rtw_mi_get_union_chan(padapter);
  2927. #ifdef CONFIG_MCC_MODE
  2928. if (MCC_EN(padapter))
  2929. return;
  2930. #endif /* CONFIG_MCC_MODE */
  2931. ies = (u8 *)(frame_body + _PUBLIC_ACTION_IE_OFFSET_);
  2932. ies_len = len - _PUBLIC_ACTION_IE_OFFSET_;
  2933. p2p_ie = rtw_get_p2p_ie(ies, ies_len, NULL, &p2p_ielen);
  2934. while (p2p_ie) {
  2935. u32 attr_contentlen = 0;
  2936. u8 *pattr = NULL;
  2937. /* Check P2P_ATTR_CH_LIST */
  2938. pattr = rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_CH_LIST, NULL, (uint *)&attr_contentlen);
  2939. if (pattr != NULL) {
  2940. int i;
  2941. u32 num_of_ch;
  2942. u8 *pattr_temp = pattr + 3 ;
  2943. attr_contentlen -= 3;
  2944. while (attr_contentlen > 0) {
  2945. num_of_ch = *(pattr_temp + 1);
  2946. for (i = 0; i < num_of_ch; i++) {
  2947. if (*(pattr_temp + 2 + i) && *(pattr_temp + 2 + i) != union_ch) {
  2948. #ifdef RTW_SINGLE_WIPHY
  2949. RTW_ERR("replace ch_list:%u with:%u\n", *(pattr_temp + 2 + i), union_ch);
  2950. #endif
  2951. *(pattr_temp + 2 + i) = union_ch; /*forcing to the same channel*/
  2952. }
  2953. }
  2954. pattr_temp += (2 + num_of_ch);
  2955. attr_contentlen -= (2 + num_of_ch);
  2956. }
  2957. }
  2958. /* Check P2P_ATTR_OPERATING_CH */
  2959. attr_contentlen = 0;
  2960. pattr = NULL;
  2961. pattr = rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_OPERATING_CH, NULL, (uint *)&attr_contentlen);
  2962. if (pattr != NULL) {
  2963. if (*(pattr + 4) && *(pattr + 4) != union_ch) {
  2964. #ifdef RTW_SINGLE_WIPHY
  2965. RTW_ERR("replace op_ch:%u with:%u\n", *(pattr + 4), union_ch);
  2966. #endif
  2967. *(pattr + 4) = union_ch; /*forcing to the same channel */
  2968. }
  2969. }
  2970. /* Get the next P2P IE */
  2971. p2p_ie = rtw_get_p2p_ie(p2p_ie + p2p_ielen, ies_len - (p2p_ie - ies + p2p_ielen), NULL, &p2p_ielen);
  2972. }
  2973. }
  2974. #endif
  2975. #ifdef CONFIG_WFD
  2976. u32 rtw_xframe_build_wfd_ie(struct xmit_frame *xframe)
  2977. {
  2978. _adapter *adapter = xframe->padapter;
  2979. struct wifidirect_info *wdinfo = &adapter->wdinfo;
  2980. u8 *frame = xframe->buf_addr + TXDESC_OFFSET;
  2981. u8 *frame_body = frame + sizeof(struct rtw_ieee80211_hdr_3addr);
  2982. u8 *frame_tail = frame + xframe->attrib.pktlen;
  2983. u8 category, action, OUI_Subtype, dialogToken = 0;
  2984. u32 wfdielen = 0;
  2985. category = frame_body[0];
  2986. if (category == RTW_WLAN_CATEGORY_PUBLIC) {
  2987. action = frame_body[1];
  2988. if (action == ACT_PUBLIC_VENDOR
  2989. && _rtw_memcmp(frame_body + 2, P2P_OUI, 4) == _TRUE
  2990. ) {
  2991. OUI_Subtype = frame_body[6];
  2992. dialogToken = frame_body[7];
  2993. switch (OUI_Subtype) {
  2994. case P2P_GO_NEGO_REQ:
  2995. wfdielen = build_nego_req_wfd_ie(wdinfo, frame_tail);
  2996. break;
  2997. case P2P_GO_NEGO_RESP:
  2998. wfdielen = build_nego_resp_wfd_ie(wdinfo, frame_tail);
  2999. break;
  3000. case P2P_GO_NEGO_CONF:
  3001. wfdielen = build_nego_confirm_wfd_ie(wdinfo, frame_tail);
  3002. break;
  3003. case P2P_INVIT_REQ:
  3004. wfdielen = build_invitation_req_wfd_ie(wdinfo, frame_tail);
  3005. break;
  3006. case P2P_INVIT_RESP:
  3007. wfdielen = build_invitation_resp_wfd_ie(wdinfo, frame_tail);
  3008. break;
  3009. case P2P_PROVISION_DISC_REQ:
  3010. wfdielen = build_provdisc_req_wfd_ie(wdinfo, frame_tail);
  3011. break;
  3012. case P2P_PROVISION_DISC_RESP:
  3013. wfdielen = build_provdisc_resp_wfd_ie(wdinfo, frame_tail);
  3014. break;
  3015. case P2P_DEVDISC_REQ:
  3016. case P2P_DEVDISC_RESP:
  3017. default:
  3018. break;
  3019. }
  3020. }
  3021. } else if (category == RTW_WLAN_CATEGORY_P2P) {
  3022. OUI_Subtype = frame_body[5];
  3023. dialogToken = frame_body[6];
  3024. #ifdef CONFIG_DEBUG_CFG80211
  3025. RTW_INFO("ACTION_CATEGORY_P2P: OUI=0x%x, OUI_Subtype=%d, dialogToken=%d\n"
  3026. , cpu_to_be32(*((u32 *)(frame_body + 1))), OUI_Subtype, dialogToken);
  3027. #endif
  3028. switch (OUI_Subtype) {
  3029. case P2P_NOTICE_OF_ABSENCE:
  3030. break;
  3031. case P2P_PRESENCE_REQUEST:
  3032. break;
  3033. case P2P_PRESENCE_RESPONSE:
  3034. break;
  3035. case P2P_GO_DISC_REQUEST:
  3036. break;
  3037. default:
  3038. break;
  3039. }
  3040. } else
  3041. RTW_INFO("%s, action frame category=%d\n", __func__, category);
  3042. xframe->attrib.pktlen += wfdielen;
  3043. return wfdielen;
  3044. }
  3045. #endif /* CONFIG_WFD */
  3046. bool rtw_xframe_del_wfd_ie(struct xmit_frame *xframe)
  3047. {
  3048. #define DBG_XFRAME_DEL_WFD_IE 0
  3049. u8 *frame = xframe->buf_addr + TXDESC_OFFSET;
  3050. u8 *frame_body = frame + sizeof(struct rtw_ieee80211_hdr_3addr);
  3051. u8 *frame_tail = frame + xframe->attrib.pktlen;
  3052. u8 category, action, OUI_Subtype;
  3053. u8 *ies = NULL;
  3054. uint ies_len_ori = 0;
  3055. uint ies_len = 0;
  3056. category = frame_body[0];
  3057. if (category == RTW_WLAN_CATEGORY_PUBLIC) {
  3058. action = frame_body[1];
  3059. if (action == ACT_PUBLIC_VENDOR
  3060. && _rtw_memcmp(frame_body + 2, P2P_OUI, 4) == _TRUE
  3061. ) {
  3062. OUI_Subtype = frame_body[6];
  3063. switch (OUI_Subtype) {
  3064. case P2P_GO_NEGO_REQ:
  3065. case P2P_GO_NEGO_RESP:
  3066. case P2P_GO_NEGO_CONF:
  3067. case P2P_INVIT_REQ:
  3068. case P2P_INVIT_RESP:
  3069. case P2P_PROVISION_DISC_REQ:
  3070. case P2P_PROVISION_DISC_RESP:
  3071. ies = frame_body + 8;
  3072. ies_len_ori = frame_tail - (frame_body + 8);
  3073. break;
  3074. }
  3075. }
  3076. }
  3077. if (ies && ies_len_ori) {
  3078. ies_len = rtw_del_wfd_ie(ies, ies_len_ori, DBG_XFRAME_DEL_WFD_IE ? __func__ : NULL);
  3079. xframe->attrib.pktlen -= (ies_len_ori - ies_len);
  3080. }
  3081. return ies_len_ori != ies_len;
  3082. }
  3083. /*
  3084. * rtw_xframe_chk_wfd_ie -
  3085. *
  3086. */
  3087. void rtw_xframe_chk_wfd_ie(struct xmit_frame *xframe)
  3088. {
  3089. _adapter *adapter = xframe->padapter;
  3090. #ifdef CONFIG_IOCTL_CFG80211
  3091. struct wifidirect_info *wdinfo = &adapter->wdinfo;
  3092. #endif
  3093. u8 build = 0;
  3094. u8 del = 0;
  3095. if (!hal_chk_wl_func(adapter, WL_FUNC_MIRACAST))
  3096. del = 1;
  3097. #ifdef CONFIG_IOCTL_CFG80211
  3098. if (wdinfo->wfd_info->wfd_enable == _TRUE)
  3099. #endif
  3100. del = build = 1;
  3101. if (del)
  3102. rtw_xframe_del_wfd_ie(xframe);
  3103. #ifdef CONFIG_WFD
  3104. if (build)
  3105. rtw_xframe_build_wfd_ie(xframe);
  3106. #endif
  3107. }
  3108. u8 *dump_p2p_attr_ch_list(u8 *p2p_ie, uint p2p_ielen, u8 *buf, u32 buf_len)
  3109. {
  3110. uint attr_contentlen = 0;
  3111. u8 *pattr = NULL;
  3112. int w_sz = 0;
  3113. u8 ch_cnt = 0;
  3114. u8 ch_list[40];
  3115. pattr = rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_CH_LIST, NULL, &attr_contentlen);
  3116. if (pattr != NULL) {
  3117. int i, j;
  3118. u32 num_of_ch;
  3119. u8 *pattr_temp = pattr + 3 ;
  3120. attr_contentlen -= 3;
  3121. _rtw_memset(ch_list, 0, 40);
  3122. while (attr_contentlen > 0) {
  3123. num_of_ch = *(pattr_temp + 1);
  3124. for (i = 0; i < num_of_ch; i++) {
  3125. for (j = 0; j < ch_cnt; j++) {
  3126. if (ch_list[j] == *(pattr_temp + 2 + i))
  3127. break;
  3128. }
  3129. if (j >= ch_cnt)
  3130. ch_list[ch_cnt++] = *(pattr_temp + 2 + i);
  3131. }
  3132. pattr_temp += (2 + num_of_ch);
  3133. attr_contentlen -= (2 + num_of_ch);
  3134. }
  3135. for (j = 0; j < ch_cnt; j++) {
  3136. if (j == 0)
  3137. w_sz += snprintf(buf + w_sz, buf_len - w_sz, "%u", ch_list[j]);
  3138. else if (ch_list[j] - ch_list[j - 1] != 1)
  3139. w_sz += snprintf(buf + w_sz, buf_len - w_sz, ", %u", ch_list[j]);
  3140. else if (j != ch_cnt - 1 && ch_list[j + 1] - ch_list[j] == 1) {
  3141. /* empty */
  3142. } else
  3143. w_sz += snprintf(buf + w_sz, buf_len - w_sz, "-%u", ch_list[j]);
  3144. }
  3145. }
  3146. return buf;
  3147. }
  3148. /*
  3149. * return _TRUE if requester is GO, _FALSE if responder is GO
  3150. */
  3151. bool rtw_p2p_nego_intent_compare(u8 req, u8 resp)
  3152. {
  3153. if (req >> 1 == resp >> 1)
  3154. return req & 0x01 ? _TRUE : _FALSE;
  3155. else if (req >> 1 > resp >> 1)
  3156. return _TRUE;
  3157. else
  3158. return _FALSE;
  3159. }
  3160. int rtw_p2p_check_frames(_adapter *padapter, const u8 *buf, u32 len, u8 tx)
  3161. {
  3162. int is_p2p_frame = (-1);
  3163. unsigned char *frame_body;
  3164. u8 category, action, OUI_Subtype, dialogToken = 0;
  3165. u8 *p2p_ie = NULL;
  3166. uint p2p_ielen = 0;
  3167. struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(padapter);
  3168. int status = -1;
  3169. u8 ch_list_buf[128] = {'\0'};
  3170. int op_ch = -1;
  3171. int listen_ch = -1;
  3172. u8 intent = 0;
  3173. u8 *iaddr = NULL;
  3174. u8 *gbssid = NULL;
  3175. frame_body = (unsigned char *)(buf + sizeof(struct rtw_ieee80211_hdr_3addr));
  3176. category = frame_body[0];
  3177. /* just for check */
  3178. if (category == RTW_WLAN_CATEGORY_PUBLIC) {
  3179. action = frame_body[1];
  3180. if (action == ACT_PUBLIC_VENDOR
  3181. && _rtw_memcmp(frame_body + 2, P2P_OUI, 4) == _TRUE
  3182. ) {
  3183. OUI_Subtype = frame_body[6];
  3184. dialogToken = frame_body[7];
  3185. is_p2p_frame = OUI_Subtype;
  3186. #ifdef CONFIG_DEBUG_CFG80211
  3187. RTW_INFO("ACTION_CATEGORY_PUBLIC: ACT_PUBLIC_VENDOR, OUI=0x%x, OUI_Subtype=%d, dialogToken=%d\n",
  3188. cpu_to_be32(*((u32 *)(frame_body + 2))), OUI_Subtype, dialogToken);
  3189. #endif
  3190. p2p_ie = rtw_get_p2p_ie(
  3191. (u8 *)buf + sizeof(struct rtw_ieee80211_hdr_3addr) + _PUBLIC_ACTION_IE_OFFSET_
  3192. , len - sizeof(struct rtw_ieee80211_hdr_3addr) - _PUBLIC_ACTION_IE_OFFSET_
  3193. , NULL, &p2p_ielen);
  3194. switch (OUI_Subtype) { /* OUI Subtype */
  3195. u8 *cont;
  3196. uint cont_len;
  3197. case P2P_GO_NEGO_REQ: {
  3198. struct rtw_wdev_nego_info *nego_info = &pwdev_priv->nego_info;
  3199. if (tx) {
  3200. #ifdef CONFIG_DRV_ISSUE_PROV_REQ /* IOT FOR S2 */
  3201. if (pwdev_priv->provdisc_req_issued == _FALSE)
  3202. rtw_cfg80211_issue_p2p_provision_request(padapter, buf, len);
  3203. #endif /* CONFIG_DRV_ISSUE_PROV_REQ */
  3204. /* pwdev_priv->provdisc_req_issued = _FALSE; */
  3205. #if defined(CONFIG_CONCURRENT_MODE) && defined(CONFIG_CFG80211_ONECHANNEL_UNDER_CONCURRENT)
  3206. if (rtw_mi_check_status(padapter, MI_LINKED) && padapter->registrypriv.full_ch_in_p2p_handshake == 0)
  3207. rtw_cfg80211_adjust_p2pie_channel(padapter, frame_body, len - sizeof(struct rtw_ieee80211_hdr_3addr));
  3208. #endif
  3209. }
  3210. cont = rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_OPERATING_CH, NULL, &cont_len);
  3211. if (cont)
  3212. op_ch = *(cont + 4);
  3213. cont = rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_LISTEN_CH, NULL, &cont_len);
  3214. if (cont)
  3215. listen_ch = *(cont + 4);
  3216. cont = rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_GO_INTENT, NULL, &cont_len);
  3217. if (cont)
  3218. intent = *cont;
  3219. cont = rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_INTENDED_IF_ADDR, NULL, &cont_len);
  3220. if (cont && cont_len == 6)
  3221. iaddr = cont;
  3222. if (nego_info->token != dialogToken)
  3223. rtw_wdev_nego_info_init(nego_info);
  3224. _rtw_memcpy(nego_info->peer_mac, tx ? GetAddr1Ptr(buf) : get_addr2_ptr(buf), ETH_ALEN);
  3225. if (iaddr)
  3226. _rtw_memcpy(tx ? nego_info->iface_addr : nego_info->peer_iface_addr, iaddr, ETH_ALEN);
  3227. nego_info->active = tx ? 1 : 0;
  3228. nego_info->token = dialogToken;
  3229. nego_info->req_op_ch = op_ch;
  3230. nego_info->req_listen_ch = listen_ch;
  3231. nego_info->req_intent = intent;
  3232. nego_info->state = 0;
  3233. dump_p2p_attr_ch_list(p2p_ie, p2p_ielen, ch_list_buf, 128);
  3234. RTW_INFO("RTW_%s:P2P_GO_NEGO_REQ, dialogToken=%d, intent:%u%s, listen_ch:%d, op_ch:%d, ch_list:%s"
  3235. , (tx == _TRUE) ? "Tx" : "Rx" , dialogToken , (intent >> 1) , intent & 0x1 ? "+" : "-" , listen_ch , op_ch , ch_list_buf);
  3236. if (iaddr)
  3237. _RTW_INFO(", iaddr:"MAC_FMT, MAC_ARG(iaddr));
  3238. _RTW_INFO("\n");
  3239. if (!tx) {
  3240. #if defined(CONFIG_CONCURRENT_MODE) && defined(CONFIG_CFG80211_ONECHANNEL_UNDER_CONCURRENT)
  3241. if (rtw_mi_check_status(padapter, MI_LINKED)
  3242. && rtw_chk_p2pie_ch_list_with_buddy(padapter, frame_body, len - sizeof(struct rtw_ieee80211_hdr_3addr)) == _FALSE
  3243. && padapter->registrypriv.full_ch_in_p2p_handshake == 0) {
  3244. RTW_INFO(FUNC_ADPT_FMT" ch_list has no intersect with buddy\n", FUNC_ADPT_ARG(padapter));
  3245. rtw_change_p2pie_ch_list(padapter, frame_body, len - sizeof(struct rtw_ieee80211_hdr_3addr), 0);
  3246. }
  3247. #endif
  3248. }
  3249. break;
  3250. }
  3251. case P2P_GO_NEGO_RESP: {
  3252. struct rtw_wdev_nego_info *nego_info = &pwdev_priv->nego_info;
  3253. if (tx) {
  3254. #if defined(CONFIG_CONCURRENT_MODE) && defined(CONFIG_CFG80211_ONECHANNEL_UNDER_CONCURRENT)
  3255. if (rtw_mi_check_status(padapter, MI_LINKED) && padapter->registrypriv.full_ch_in_p2p_handshake == 0)
  3256. rtw_cfg80211_adjust_p2pie_channel(padapter, frame_body, len - sizeof(struct rtw_ieee80211_hdr_3addr));
  3257. #endif
  3258. }
  3259. cont = rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_OPERATING_CH, NULL, &cont_len);
  3260. if (cont)
  3261. op_ch = *(cont + 4);
  3262. cont = rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_GO_INTENT, NULL, &cont_len);
  3263. if (cont)
  3264. intent = *cont;
  3265. cont = rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_STATUS, NULL, &cont_len);
  3266. if (cont)
  3267. status = *cont;
  3268. cont = rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_INTENDED_IF_ADDR, NULL, &cont_len);
  3269. if (cont && cont_len == 6)
  3270. iaddr = cont;
  3271. if (nego_info->token == dialogToken && nego_info->state == 0
  3272. && _rtw_memcmp(nego_info->peer_mac, tx ? GetAddr1Ptr(buf) : get_addr2_ptr(buf), ETH_ALEN) == _TRUE
  3273. ) {
  3274. if (iaddr)
  3275. _rtw_memcpy(tx ? nego_info->iface_addr : nego_info->peer_iface_addr, iaddr, ETH_ALEN);
  3276. nego_info->status = (status == -1) ? 0xff : status;
  3277. nego_info->rsp_op_ch = op_ch;
  3278. nego_info->rsp_intent = intent;
  3279. nego_info->state = 1;
  3280. if (status != 0)
  3281. nego_info->token = 0; /* init */
  3282. }
  3283. dump_p2p_attr_ch_list(p2p_ie, p2p_ielen, ch_list_buf, 128);
  3284. RTW_INFO("RTW_%s:P2P_GO_NEGO_RESP, dialogToken=%d, intent:%u%s, status:%d, op_ch:%d, ch_list:%s"
  3285. , (tx == _TRUE) ? "Tx" : "Rx", dialogToken, (intent >> 1), intent & 0x1 ? "+" : "-", status, op_ch, ch_list_buf);
  3286. if (iaddr)
  3287. _RTW_INFO(", iaddr:"MAC_FMT, MAC_ARG(iaddr));
  3288. _RTW_INFO("\n");
  3289. if (!tx) {
  3290. pwdev_priv->provdisc_req_issued = _FALSE;
  3291. #if defined(CONFIG_CONCURRENT_MODE) && defined(CONFIG_CFG80211_ONECHANNEL_UNDER_CONCURRENT)
  3292. if (rtw_mi_check_status(padapter, MI_LINKED)
  3293. && rtw_chk_p2pie_ch_list_with_buddy(padapter, frame_body, len - sizeof(struct rtw_ieee80211_hdr_3addr)) == _FALSE
  3294. && padapter->registrypriv.full_ch_in_p2p_handshake == 0) {
  3295. RTW_INFO(FUNC_ADPT_FMT" ch_list has no intersect with buddy\n", FUNC_ADPT_ARG(padapter));
  3296. rtw_change_p2pie_ch_list(padapter, frame_body, len - sizeof(struct rtw_ieee80211_hdr_3addr), 0);
  3297. }
  3298. #endif
  3299. }
  3300. break;
  3301. }
  3302. case P2P_GO_NEGO_CONF: {
  3303. struct rtw_wdev_nego_info *nego_info = &pwdev_priv->nego_info;
  3304. bool is_go = _FALSE;
  3305. if (tx) {
  3306. #if defined(CONFIG_CONCURRENT_MODE) && defined(CONFIG_CFG80211_ONECHANNEL_UNDER_CONCURRENT)
  3307. if (rtw_mi_check_status(padapter, MI_LINKED) && padapter->registrypriv.full_ch_in_p2p_handshake == 0)
  3308. rtw_cfg80211_adjust_p2pie_channel(padapter, frame_body, len - sizeof(struct rtw_ieee80211_hdr_3addr));
  3309. #endif
  3310. }
  3311. cont = rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_OPERATING_CH, NULL, &cont_len);
  3312. if (cont)
  3313. op_ch = *(cont + 4);
  3314. cont = rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_STATUS, NULL, &cont_len);
  3315. if (cont)
  3316. status = *cont;
  3317. if (nego_info->token == dialogToken && nego_info->state == 1
  3318. && _rtw_memcmp(nego_info->peer_mac, tx ? GetAddr1Ptr(buf) : get_addr2_ptr(buf), ETH_ALEN) == _TRUE
  3319. ) {
  3320. nego_info->status = (status == -1) ? 0xff : status;
  3321. nego_info->conf_op_ch = (op_ch == -1) ? 0 : op_ch;
  3322. nego_info->state = 2;
  3323. if (status == 0) {
  3324. if (rtw_p2p_nego_intent_compare(nego_info->req_intent, nego_info->rsp_intent) ^ !tx)
  3325. is_go = _TRUE;
  3326. }
  3327. nego_info->token = 0; /* init */
  3328. }
  3329. dump_p2p_attr_ch_list(p2p_ie, p2p_ielen, ch_list_buf, 128);
  3330. RTW_INFO("RTW_%s:P2P_GO_NEGO_CONF, dialogToken=%d, status:%d, op_ch:%d, ch_list:%s\n"
  3331. , (tx == _TRUE) ? "Tx" : "Rx", dialogToken, status, op_ch, ch_list_buf);
  3332. if (!tx) {
  3333. }
  3334. break;
  3335. }
  3336. case P2P_INVIT_REQ: {
  3337. struct rtw_wdev_invit_info *invit_info = &pwdev_priv->invit_info;
  3338. int flags = -1;
  3339. if (tx) {
  3340. #if defined(CONFIG_CONCURRENT_MODE) && defined(CONFIG_CFG80211_ONECHANNEL_UNDER_CONCURRENT)
  3341. if (rtw_mi_check_status(padapter, MI_LINKED)
  3342. && padapter->registrypriv.full_ch_in_p2p_handshake == 0)
  3343. rtw_cfg80211_adjust_p2pie_channel(padapter, frame_body, len - sizeof(struct rtw_ieee80211_hdr_3addr));
  3344. #endif
  3345. }
  3346. cont = rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_INVITATION_FLAGS, NULL, &cont_len);
  3347. if (cont)
  3348. flags = *cont;
  3349. cont = rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_OPERATING_CH, NULL, &cont_len);
  3350. if (cont)
  3351. op_ch = *(cont + 4);
  3352. cont = rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_GROUP_BSSID, NULL, &cont_len);
  3353. if (cont && cont_len == 6)
  3354. gbssid = cont;
  3355. if (invit_info->token != dialogToken)
  3356. rtw_wdev_invit_info_init(invit_info);
  3357. _rtw_memcpy(invit_info->peer_mac, tx ? GetAddr1Ptr(buf) : get_addr2_ptr(buf), ETH_ALEN);
  3358. if (gbssid)
  3359. _rtw_memcpy(invit_info->group_bssid, gbssid, ETH_ALEN);
  3360. invit_info->active = tx ? 1 : 0;
  3361. invit_info->token = dialogToken;
  3362. invit_info->flags = (flags == -1) ? 0x0 : flags;
  3363. invit_info->req_op_ch = op_ch;
  3364. invit_info->state = 0;
  3365. dump_p2p_attr_ch_list(p2p_ie, p2p_ielen, ch_list_buf, 128);
  3366. RTW_INFO("RTW_%s:P2P_INVIT_REQ, dialogToken=%d, flags:0x%02x, op_ch:%d, ch_list:%s"
  3367. , (tx == _TRUE) ? "Tx" : "Rx", dialogToken, flags, op_ch, ch_list_buf);
  3368. if (gbssid)
  3369. _RTW_INFO(", gbssid:"MAC_FMT, MAC_ARG(gbssid));
  3370. _RTW_INFO("\n");
  3371. if (!tx) {
  3372. #if defined(CONFIG_CONCURRENT_MODE) && defined(CONFIG_CFG80211_ONECHANNEL_UNDER_CONCURRENT)
  3373. if (rtw_mi_check_status(padapter, MI_LINKED) && padapter->registrypriv.full_ch_in_p2p_handshake == 0) {
  3374. #if defined(CONFIG_P2P_INVITE_IOT)
  3375. if (op_ch != -1 && rtw_chk_p2pie_op_ch_with_buddy(padapter, frame_body, len - sizeof(struct rtw_ieee80211_hdr_3addr)) == _FALSE) {
  3376. RTW_INFO(FUNC_ADPT_FMT" op_ch:%u has no intersect with buddy\n", FUNC_ADPT_ARG(padapter), op_ch);
  3377. rtw_change_p2pie_ch_list(padapter, frame_body, len - sizeof(struct rtw_ieee80211_hdr_3addr), 0);
  3378. } else
  3379. #endif
  3380. if (rtw_chk_p2pie_ch_list_with_buddy(padapter, frame_body, len - sizeof(struct rtw_ieee80211_hdr_3addr)) == _FALSE) {
  3381. RTW_INFO(FUNC_ADPT_FMT" ch_list has no intersect with buddy\n", FUNC_ADPT_ARG(padapter));
  3382. rtw_change_p2pie_ch_list(padapter, frame_body, len - sizeof(struct rtw_ieee80211_hdr_3addr), 0);
  3383. }
  3384. }
  3385. #endif
  3386. }
  3387. break;
  3388. }
  3389. case P2P_INVIT_RESP: {
  3390. struct rtw_wdev_invit_info *invit_info = &pwdev_priv->invit_info;
  3391. if (tx) {
  3392. #if defined(CONFIG_CONCURRENT_MODE) && defined(CONFIG_CFG80211_ONECHANNEL_UNDER_CONCURRENT)
  3393. if (rtw_mi_check_status(padapter, MI_LINKED) && padapter->registrypriv.full_ch_in_p2p_handshake == 0)
  3394. rtw_cfg80211_adjust_p2pie_channel(padapter, frame_body, len - sizeof(struct rtw_ieee80211_hdr_3addr));
  3395. #endif
  3396. }
  3397. cont = rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_STATUS, NULL, &cont_len);
  3398. if (cont) {
  3399. #ifdef CONFIG_P2P_INVITE_IOT
  3400. if (tx && *cont == 7) {
  3401. RTW_INFO("TX_P2P_INVITE_RESP, status is no common channel, change to unknown group\n");
  3402. *cont = 8; /* unknow group status */
  3403. }
  3404. #endif /* CONFIG_P2P_INVITE_IOT */
  3405. status = *cont;
  3406. }
  3407. cont = rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_OPERATING_CH, NULL, &cont_len);
  3408. if (cont)
  3409. op_ch = *(cont + 4);
  3410. cont = rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_GROUP_BSSID, NULL, &cont_len);
  3411. if (cont && cont_len == 6)
  3412. gbssid = cont;
  3413. if (invit_info->token == dialogToken && invit_info->state == 0
  3414. && _rtw_memcmp(invit_info->peer_mac, tx ? GetAddr1Ptr(buf) : get_addr2_ptr(buf), ETH_ALEN) == _TRUE
  3415. ) {
  3416. invit_info->status = (status == -1) ? 0xff : status;
  3417. invit_info->rsp_op_ch = op_ch;
  3418. invit_info->state = 1;
  3419. invit_info->token = 0; /* init */
  3420. }
  3421. dump_p2p_attr_ch_list(p2p_ie, p2p_ielen, ch_list_buf, 128);
  3422. RTW_INFO("RTW_%s:P2P_INVIT_RESP, dialogToken=%d, status:%d, op_ch:%d, ch_list:%s"
  3423. , (tx == _TRUE) ? "Tx" : "Rx", dialogToken, status, op_ch, ch_list_buf);
  3424. if (gbssid)
  3425. _RTW_INFO(", gbssid:"MAC_FMT, MAC_ARG(gbssid));
  3426. _RTW_INFO("\n");
  3427. if (!tx) {
  3428. }
  3429. break;
  3430. }
  3431. case P2P_DEVDISC_REQ:
  3432. RTW_INFO("RTW_%s:P2P_DEVDISC_REQ, dialogToken=%d\n", (tx == _TRUE) ? "Tx" : "Rx", dialogToken);
  3433. break;
  3434. case P2P_DEVDISC_RESP:
  3435. cont = rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_STATUS, NULL, &cont_len);
  3436. RTW_INFO("RTW_%s:P2P_DEVDISC_RESP, dialogToken=%d, status:%d\n", (tx == _TRUE) ? "Tx" : "Rx", dialogToken, cont ? *cont : -1);
  3437. break;
  3438. case P2P_PROVISION_DISC_REQ: {
  3439. size_t frame_body_len = len - sizeof(struct rtw_ieee80211_hdr_3addr);
  3440. u8 *p2p_ie;
  3441. uint p2p_ielen = 0;
  3442. uint contentlen = 0;
  3443. RTW_INFO("RTW_%s:P2P_PROVISION_DISC_REQ, dialogToken=%d\n", (tx == _TRUE) ? "Tx" : "Rx", dialogToken);
  3444. /* if(tx) */
  3445. {
  3446. pwdev_priv->provdisc_req_issued = _FALSE;
  3447. p2p_ie = rtw_get_p2p_ie(frame_body + _PUBLIC_ACTION_IE_OFFSET_, frame_body_len - _PUBLIC_ACTION_IE_OFFSET_, NULL, &p2p_ielen);
  3448. if (p2p_ie) {
  3449. if (rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_GROUP_ID, NULL, &contentlen)) {
  3450. pwdev_priv->provdisc_req_issued = _FALSE;/* case: p2p_client join p2p GO */
  3451. } else {
  3452. #ifdef CONFIG_DEBUG_CFG80211
  3453. RTW_INFO("provdisc_req_issued is _TRUE\n");
  3454. #endif /*CONFIG_DEBUG_CFG80211*/
  3455. pwdev_priv->provdisc_req_issued = _TRUE;/* case: p2p_devices connection before Nego req. */
  3456. }
  3457. }
  3458. }
  3459. }
  3460. break;
  3461. case P2P_PROVISION_DISC_RESP:
  3462. RTW_INFO("RTW_%s:P2P_PROVISION_DISC_RESP, dialogToken=%d\n", (tx == _TRUE) ? "Tx" : "Rx", dialogToken);
  3463. break;
  3464. default:
  3465. RTW_INFO("RTW_%s:OUI_Subtype=%d, dialogToken=%d\n", (tx == _TRUE) ? "Tx" : "Rx", OUI_Subtype, dialogToken);
  3466. break;
  3467. }
  3468. }
  3469. } else if (category == RTW_WLAN_CATEGORY_P2P) {
  3470. OUI_Subtype = frame_body[5];
  3471. dialogToken = frame_body[6];
  3472. #ifdef CONFIG_DEBUG_CFG80211
  3473. RTW_INFO("ACTION_CATEGORY_P2P: OUI=0x%x, OUI_Subtype=%d, dialogToken=%d\n",
  3474. cpu_to_be32(*((u32 *)(frame_body + 1))), OUI_Subtype, dialogToken);
  3475. #endif
  3476. is_p2p_frame = OUI_Subtype;
  3477. switch (OUI_Subtype) {
  3478. case P2P_NOTICE_OF_ABSENCE:
  3479. RTW_INFO("RTW_%s:P2P_NOTICE_OF_ABSENCE, dialogToken=%d\n", (tx == _TRUE) ? "Tx" : "Rx", dialogToken);
  3480. break;
  3481. case P2P_PRESENCE_REQUEST:
  3482. RTW_INFO("RTW_%s:P2P_PRESENCE_REQUEST, dialogToken=%d\n", (tx == _TRUE) ? "Tx" : "Rx", dialogToken);
  3483. break;
  3484. case P2P_PRESENCE_RESPONSE:
  3485. RTW_INFO("RTW_%s:P2P_PRESENCE_RESPONSE, dialogToken=%d\n", (tx == _TRUE) ? "Tx" : "Rx", dialogToken);
  3486. break;
  3487. case P2P_GO_DISC_REQUEST:
  3488. RTW_INFO("RTW_%s:P2P_GO_DISC_REQUEST, dialogToken=%d\n", (tx == _TRUE) ? "Tx" : "Rx", dialogToken);
  3489. break;
  3490. default:
  3491. RTW_INFO("RTW_%s:OUI_Subtype=%d, dialogToken=%d\n", (tx == _TRUE) ? "Tx" : "Rx", OUI_Subtype, dialogToken);
  3492. break;
  3493. }
  3494. }
  3495. return is_p2p_frame;
  3496. }
  3497. void rtw_init_cfg80211_wifidirect_info(_adapter *padapter)
  3498. {
  3499. struct cfg80211_wifidirect_info *pcfg80211_wdinfo = &padapter->cfg80211_wdinfo;
  3500. _rtw_memset(pcfg80211_wdinfo, 0x00, sizeof(struct cfg80211_wifidirect_info));
  3501. rtw_init_timer(&pcfg80211_wdinfo->remain_on_ch_timer, padapter, ro_ch_timer_process, padapter);
  3502. }
  3503. #endif /* CONFIG_IOCTL_CFG80211 */
  3504. s32 p2p_protocol_wk_hdl(_adapter *padapter, int intCmdType, u8 *buf)
  3505. {
  3506. int ret = H2C_SUCCESS;
  3507. switch (intCmdType) {
  3508. case P2P_FIND_PHASE_WK:
  3509. find_phase_handler(padapter);
  3510. break;
  3511. case P2P_RESTORE_STATE_WK:
  3512. restore_p2p_state_handler(padapter);
  3513. break;
  3514. case P2P_PRE_TX_PROVDISC_PROCESS_WK:
  3515. #ifdef CONFIG_CONCURRENT_MODE
  3516. if (rtw_mi_check_status(padapter, MI_LINKED))
  3517. p2p_concurrent_handler(padapter);
  3518. else
  3519. pre_tx_provdisc_handler(padapter);
  3520. #else
  3521. pre_tx_provdisc_handler(padapter);
  3522. #endif
  3523. break;
  3524. case P2P_PRE_TX_INVITEREQ_PROCESS_WK:
  3525. #ifdef CONFIG_CONCURRENT_MODE
  3526. if (rtw_mi_check_status(padapter, MI_LINKED))
  3527. p2p_concurrent_handler(padapter);
  3528. else
  3529. pre_tx_invitereq_handler(padapter);
  3530. #else
  3531. pre_tx_invitereq_handler(padapter);
  3532. #endif
  3533. break;
  3534. case P2P_PRE_TX_NEGOREQ_PROCESS_WK:
  3535. #ifdef CONFIG_CONCURRENT_MODE
  3536. if (rtw_mi_check_status(padapter, MI_LINKED))
  3537. p2p_concurrent_handler(padapter);
  3538. else
  3539. pre_tx_negoreq_handler(padapter);
  3540. #else
  3541. pre_tx_negoreq_handler(padapter);
  3542. #endif
  3543. break;
  3544. #ifdef CONFIG_CONCURRENT_MODE
  3545. case P2P_AP_P2P_CH_SWITCH_PROCESS_WK:
  3546. p2p_concurrent_handler(padapter);
  3547. break;
  3548. #endif
  3549. #ifdef CONFIG_IOCTL_CFG80211
  3550. case P2P_RO_CH_WK:
  3551. ret = ro_ch_handler(padapter, buf);
  3552. break;
  3553. case P2P_CANCEL_RO_CH_WK:
  3554. ret = cancel_ro_ch_handler(padapter, buf);
  3555. break;
  3556. #endif
  3557. default:
  3558. rtw_warn_on(1);
  3559. break;
  3560. }
  3561. return ret;
  3562. }
  3563. int process_p2p_cross_connect_ie(PADAPTER padapter, u8 *IEs, u32 IELength)
  3564. {
  3565. int ret = _TRUE;
  3566. u8 *ies;
  3567. u32 ies_len;
  3568. u8 *p2p_ie;
  3569. u32 p2p_ielen = 0;
  3570. u8 p2p_attr[MAX_P2P_IE_LEN] = { 0x00 };/* NoA length should be n*(13) + 2 */
  3571. u32 attr_contentlen = 0;
  3572. if (IELength <= _BEACON_IE_OFFSET_)
  3573. return ret;
  3574. ies = IEs + _BEACON_IE_OFFSET_;
  3575. ies_len = IELength - _BEACON_IE_OFFSET_;
  3576. p2p_ie = rtw_get_p2p_ie(ies, ies_len, NULL, &p2p_ielen);
  3577. while (p2p_ie) {
  3578. /* Get P2P Manageability IE. */
  3579. if (rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_MANAGEABILITY, p2p_attr, &attr_contentlen)) {
  3580. if ((p2p_attr[0] & (BIT(0) | BIT(1))) == 0x01)
  3581. ret = _FALSE;
  3582. break;
  3583. }
  3584. /* Get the next P2P IE */
  3585. p2p_ie = rtw_get_p2p_ie(p2p_ie + p2p_ielen, ies_len - (p2p_ie - ies + p2p_ielen), NULL, &p2p_ielen);
  3586. }
  3587. return ret;
  3588. }
  3589. #ifdef CONFIG_P2P_PS
  3590. void process_p2p_ps_ie(PADAPTER padapter, u8 *IEs, u32 IELength)
  3591. {
  3592. u8 *ies;
  3593. u32 ies_len;
  3594. u8 *p2p_ie;
  3595. u32 p2p_ielen = 0;
  3596. u8 noa_attr[MAX_P2P_IE_LEN] = { 0x00 };/* NoA length should be n*(13) + 2 */
  3597. u32 attr_contentlen = 0;
  3598. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  3599. u8 find_p2p = _FALSE, find_p2p_ps = _FALSE;
  3600. u8 noa_offset, noa_num, noa_index;
  3601. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  3602. return;
  3603. #ifdef CONFIG_CONCURRENT_MODE
  3604. #ifndef CONFIG_FW_MULTI_PORT_SUPPORT
  3605. if (padapter->hw_port != HW_PORT0)
  3606. return;
  3607. #endif
  3608. #endif
  3609. if (IELength <= _BEACON_IE_OFFSET_)
  3610. return;
  3611. ies = IEs + _BEACON_IE_OFFSET_;
  3612. ies_len = IELength - _BEACON_IE_OFFSET_;
  3613. p2p_ie = rtw_get_p2p_ie(ies, ies_len, NULL, &p2p_ielen);
  3614. while (p2p_ie) {
  3615. find_p2p = _TRUE;
  3616. /* Get Notice of Absence IE. */
  3617. if (rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_NOA, noa_attr, &attr_contentlen)) {
  3618. find_p2p_ps = _TRUE;
  3619. noa_index = noa_attr[0];
  3620. if ((pwdinfo->p2p_ps_mode == P2P_PS_NONE) ||
  3621. (noa_index != pwdinfo->noa_index)) { /* if index change, driver should reconfigure related setting. */
  3622. pwdinfo->noa_index = noa_index;
  3623. pwdinfo->opp_ps = noa_attr[1] >> 7;
  3624. pwdinfo->ctwindow = noa_attr[1] & 0x7F;
  3625. noa_offset = 2;
  3626. noa_num = 0;
  3627. /* NoA length should be n*(13) + 2 */
  3628. if (attr_contentlen > 2) {
  3629. while (noa_offset < attr_contentlen) {
  3630. /* _rtw_memcpy(&wifidirect_info->noa_count[noa_num], &noa_attr[noa_offset], 1); */
  3631. pwdinfo->noa_count[noa_num] = noa_attr[noa_offset];
  3632. noa_offset += 1;
  3633. _rtw_memcpy(&pwdinfo->noa_duration[noa_num], &noa_attr[noa_offset], 4);
  3634. noa_offset += 4;
  3635. _rtw_memcpy(&pwdinfo->noa_interval[noa_num], &noa_attr[noa_offset], 4);
  3636. noa_offset += 4;
  3637. _rtw_memcpy(&pwdinfo->noa_start_time[noa_num], &noa_attr[noa_offset], 4);
  3638. noa_offset += 4;
  3639. noa_num++;
  3640. }
  3641. }
  3642. pwdinfo->noa_num = noa_num;
  3643. if (pwdinfo->opp_ps == 1) {
  3644. pwdinfo->p2p_ps_mode = P2P_PS_CTWINDOW;
  3645. /* driver should wait LPS for entering CTWindow */
  3646. if (adapter_to_pwrctl(padapter)->bFwCurrentInPSMode == _TRUE)
  3647. p2p_ps_wk_cmd(padapter, P2P_PS_ENABLE, 1);
  3648. } else if (pwdinfo->noa_num > 0) {
  3649. pwdinfo->p2p_ps_mode = P2P_PS_NOA;
  3650. p2p_ps_wk_cmd(padapter, P2P_PS_ENABLE, 1);
  3651. } else if (pwdinfo->p2p_ps_mode > P2P_PS_NONE)
  3652. p2p_ps_wk_cmd(padapter, P2P_PS_DISABLE, 1);
  3653. }
  3654. break; /* find target, just break. */
  3655. }
  3656. /* Get the next P2P IE */
  3657. p2p_ie = rtw_get_p2p_ie(p2p_ie + p2p_ielen, ies_len - (p2p_ie - ies + p2p_ielen), NULL, &p2p_ielen);
  3658. }
  3659. if (find_p2p == _TRUE) {
  3660. if ((pwdinfo->p2p_ps_mode > P2P_PS_NONE) && (find_p2p_ps == _FALSE))
  3661. p2p_ps_wk_cmd(padapter, P2P_PS_DISABLE, 1);
  3662. }
  3663. }
  3664. void p2p_ps_wk_hdl(_adapter *padapter, u8 p2p_ps_state)
  3665. {
  3666. struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
  3667. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  3668. u32 ps_deny = 0;
  3669. /* Pre action for p2p state */
  3670. switch (p2p_ps_state) {
  3671. case P2P_PS_DISABLE:
  3672. pwdinfo->p2p_ps_state = p2p_ps_state;
  3673. rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_P2P_PS_OFFLOAD, (u8 *)(&p2p_ps_state));
  3674. pwdinfo->noa_index = 0;
  3675. pwdinfo->ctwindow = 0;
  3676. pwdinfo->opp_ps = 0;
  3677. pwdinfo->noa_num = 0;
  3678. pwdinfo->p2p_ps_mode = P2P_PS_NONE;
  3679. if (pwrpriv->bFwCurrentInPSMode == _TRUE) {
  3680. if (pwrpriv->smart_ps == 0) {
  3681. pwrpriv->smart_ps = 2;
  3682. rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_PWRMODE, (u8 *)(&(pwrpriv->pwr_mode)));
  3683. }
  3684. }
  3685. break;
  3686. case P2P_PS_ENABLE:
  3687. _enter_pwrlock(&adapter_to_pwrctl(padapter)->lock);
  3688. ps_deny = rtw_ps_deny_get(padapter);
  3689. _exit_pwrlock(&adapter_to_pwrctl(padapter)->lock);
  3690. if ((ps_deny & (PS_DENY_SCAN | PS_DENY_JOIN))
  3691. || rtw_mi_check_fwstate(padapter, (_FW_UNDER_SURVEY | _FW_UNDER_LINKING))) {
  3692. pwdinfo->p2p_ps_mode = P2P_PS_NONE;
  3693. RTW_DBG(FUNC_ADPT_FMT" Block P2P PS under site survey or LINKING\n", FUNC_ADPT_ARG(padapter));
  3694. return;
  3695. }
  3696. if (pwdinfo->p2p_ps_mode > P2P_PS_NONE) {
  3697. #ifdef CONFIG_MCC_MODE
  3698. if (MCC_EN(padapter)) {
  3699. if (rtw_hal_check_mcc_status(padapter, MCC_STATUS_DOING_MCC)) {
  3700. RTW_INFO("P2P PS enble under MCC\n");
  3701. rtw_warn_on(1);
  3702. }
  3703. }
  3704. #endif /* CONFIG_MCC_MODE */
  3705. pwdinfo->p2p_ps_state = p2p_ps_state;
  3706. if (pwdinfo->ctwindow > 0) {
  3707. if (pwrpriv->smart_ps != 0) {
  3708. pwrpriv->smart_ps = 0;
  3709. RTW_INFO("%s(): Enter CTW, change SmartPS\n", __FUNCTION__);
  3710. rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_PWRMODE, (u8 *)(&(pwrpriv->pwr_mode)));
  3711. }
  3712. }
  3713. rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_P2P_PS_OFFLOAD, (u8 *)(&p2p_ps_state));
  3714. }
  3715. break;
  3716. case P2P_PS_SCAN:
  3717. case P2P_PS_SCAN_DONE:
  3718. case P2P_PS_ALLSTASLEEP:
  3719. if (pwdinfo->p2p_ps_mode > P2P_PS_NONE) {
  3720. pwdinfo->p2p_ps_state = p2p_ps_state;
  3721. rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_P2P_PS_OFFLOAD, (u8 *)(&p2p_ps_state));
  3722. }
  3723. break;
  3724. default:
  3725. break;
  3726. }
  3727. #ifdef CONFIG_MCC_MODE
  3728. rtw_hal_mcc_process_noa(padapter);
  3729. #endif /* CONFIG_MCC_MODE */
  3730. }
  3731. u8 p2p_ps_wk_cmd(_adapter *padapter, u8 p2p_ps_state, u8 enqueue)
  3732. {
  3733. struct cmd_obj *ph2c;
  3734. struct drvextra_cmd_parm *pdrvextra_cmd_parm;
  3735. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  3736. struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
  3737. u8 res = _SUCCESS;
  3738. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)
  3739. #ifdef CONFIG_CONCURRENT_MODE
  3740. #ifndef CONFIG_FW_MULTI_PORT_SUPPORT
  3741. || (padapter->hw_port != HW_PORT0)
  3742. #endif
  3743. #endif
  3744. )
  3745. return res;
  3746. if (enqueue) {
  3747. ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
  3748. if (ph2c == NULL) {
  3749. res = _FAIL;
  3750. goto exit;
  3751. }
  3752. pdrvextra_cmd_parm = (struct drvextra_cmd_parm *)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
  3753. if (pdrvextra_cmd_parm == NULL) {
  3754. rtw_mfree((unsigned char *)ph2c, sizeof(struct cmd_obj));
  3755. res = _FAIL;
  3756. goto exit;
  3757. }
  3758. pdrvextra_cmd_parm->ec_id = P2P_PS_WK_CID;
  3759. pdrvextra_cmd_parm->type = p2p_ps_state;
  3760. pdrvextra_cmd_parm->size = 0;
  3761. pdrvextra_cmd_parm->pbuf = NULL;
  3762. init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
  3763. res = rtw_enqueue_cmd(pcmdpriv, ph2c);
  3764. } else
  3765. p2p_ps_wk_hdl(padapter, p2p_ps_state);
  3766. exit:
  3767. return res;
  3768. }
  3769. #endif /* CONFIG_P2P_PS */
  3770. static void reset_ch_sitesurvey_timer_process(void *FunctionContext)
  3771. {
  3772. _adapter *adapter = (_adapter *)FunctionContext;
  3773. struct wifidirect_info *pwdinfo = &adapter->wdinfo;
  3774. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  3775. return;
  3776. RTW_INFO("[%s] In\n", __FUNCTION__);
  3777. /* Reset the operation channel information */
  3778. pwdinfo->rx_invitereq_info.operation_ch[0] = 0;
  3779. #ifdef CONFIG_P2P_OP_CHK_SOCIAL_CH
  3780. pwdinfo->rx_invitereq_info.operation_ch[1] = 0;
  3781. pwdinfo->rx_invitereq_info.operation_ch[2] = 0;
  3782. pwdinfo->rx_invitereq_info.operation_ch[3] = 0;
  3783. #endif /* CONFIG_P2P_OP_CHK_SOCIAL_CH */
  3784. pwdinfo->rx_invitereq_info.scan_op_ch_only = 0;
  3785. }
  3786. static void reset_ch_sitesurvey_timer_process2(void *FunctionContext)
  3787. {
  3788. _adapter *adapter = (_adapter *)FunctionContext;
  3789. struct wifidirect_info *pwdinfo = &adapter->wdinfo;
  3790. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  3791. return;
  3792. RTW_INFO("[%s] In\n", __FUNCTION__);
  3793. /* Reset the operation channel information */
  3794. pwdinfo->p2p_info.operation_ch[0] = 0;
  3795. #ifdef CONFIG_P2P_OP_CHK_SOCIAL_CH
  3796. pwdinfo->p2p_info.operation_ch[1] = 0;
  3797. pwdinfo->p2p_info.operation_ch[2] = 0;
  3798. pwdinfo->p2p_info.operation_ch[3] = 0;
  3799. #endif /* CONFIG_P2P_OP_CHK_SOCIAL_CH */
  3800. pwdinfo->p2p_info.scan_op_ch_only = 0;
  3801. }
  3802. static void restore_p2p_state_timer_process(void *FunctionContext)
  3803. {
  3804. _adapter *adapter = (_adapter *)FunctionContext;
  3805. struct wifidirect_info *pwdinfo = &adapter->wdinfo;
  3806. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  3807. return;
  3808. p2p_protocol_wk_cmd(adapter, P2P_RESTORE_STATE_WK);
  3809. }
  3810. static void pre_tx_scan_timer_process(void *FunctionContext)
  3811. {
  3812. _adapter *adapter = (_adapter *) FunctionContext;
  3813. struct wifidirect_info *pwdinfo = &adapter->wdinfo;
  3814. _irqL irqL;
  3815. struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
  3816. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  3817. return;
  3818. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  3819. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_TX_PROVISION_DIS_REQ)) {
  3820. if (_TRUE == pwdinfo->tx_prov_disc_info.benable) { /* the provision discovery request frame is trigger to send or not */
  3821. p2p_protocol_wk_cmd(adapter, P2P_PRE_TX_PROVDISC_PROCESS_WK);
  3822. /* issue_probereq_p2p(adapter, NULL); */
  3823. /* _set_timer( &pwdinfo->pre_tx_scan_timer, P2P_TX_PRESCAN_TIMEOUT ); */
  3824. }
  3825. } else if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_ING)) {
  3826. if (_TRUE == pwdinfo->nego_req_info.benable)
  3827. p2p_protocol_wk_cmd(adapter, P2P_PRE_TX_NEGOREQ_PROCESS_WK);
  3828. } else if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_TX_INVITE_REQ)) {
  3829. if (_TRUE == pwdinfo->invitereq_info.benable)
  3830. p2p_protocol_wk_cmd(adapter, P2P_PRE_TX_INVITEREQ_PROCESS_WK);
  3831. } else
  3832. RTW_INFO("[%s] p2p_state is %d, ignore!!\n", __FUNCTION__, rtw_p2p_state(pwdinfo));
  3833. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  3834. }
  3835. static void find_phase_timer_process(void *FunctionContext)
  3836. {
  3837. _adapter *adapter = (_adapter *)FunctionContext;
  3838. struct wifidirect_info *pwdinfo = &adapter->wdinfo;
  3839. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  3840. return;
  3841. adapter->wdinfo.find_phase_state_exchange_cnt++;
  3842. p2p_protocol_wk_cmd(adapter, P2P_FIND_PHASE_WK);
  3843. }
  3844. #ifdef CONFIG_CONCURRENT_MODE
  3845. void ap_p2p_switch_timer_process(void *FunctionContext)
  3846. {
  3847. _adapter *adapter = (_adapter *)FunctionContext;
  3848. struct wifidirect_info *pwdinfo = &adapter->wdinfo;
  3849. #ifdef CONFIG_IOCTL_CFG80211
  3850. struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(adapter);
  3851. #endif
  3852. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  3853. return;
  3854. #ifdef CONFIG_IOCTL_CFG80211
  3855. ATOMIC_SET(&pwdev_priv->switch_ch_to, 1);
  3856. #endif
  3857. p2p_protocol_wk_cmd(adapter, P2P_AP_P2P_CH_SWITCH_PROCESS_WK);
  3858. }
  3859. #endif
  3860. void reset_global_wifidirect_info(_adapter *padapter)
  3861. {
  3862. struct wifidirect_info *pwdinfo;
  3863. pwdinfo = &padapter->wdinfo;
  3864. pwdinfo->persistent_supported = 0;
  3865. pwdinfo->session_available = _TRUE;
  3866. rtw_tdls_wfd_enable(padapter, 0);
  3867. pwdinfo->wfd_tdls_weaksec = _TRUE;
  3868. }
  3869. #ifdef CONFIG_WFD
  3870. int rtw_init_wifi_display_info(_adapter *padapter)
  3871. {
  3872. int res = _SUCCESS;
  3873. struct wifi_display_info *pwfd_info = &padapter->wfd_info;
  3874. /* Used in P2P and TDLS */
  3875. pwfd_info->init_rtsp_ctrlport = 554;
  3876. #ifdef CONFIG_IOCTL_CFG80211
  3877. pwfd_info->rtsp_ctrlport = 0;
  3878. #else
  3879. pwfd_info->rtsp_ctrlport = pwfd_info->init_rtsp_ctrlport; /* set non-zero value for legacy wfd */
  3880. #endif
  3881. pwfd_info->tdls_rtsp_ctrlport = 0;
  3882. pwfd_info->peer_rtsp_ctrlport = 0; /* Reset to 0 */
  3883. pwfd_info->wfd_enable = _FALSE;
  3884. pwfd_info->wfd_device_type = WFD_DEVINFO_PSINK;
  3885. pwfd_info->scan_result_type = SCAN_RESULT_P2P_ONLY;
  3886. /* Used in P2P */
  3887. pwfd_info->peer_session_avail = _TRUE;
  3888. pwfd_info->wfd_pc = _FALSE;
  3889. /* Used in TDLS */
  3890. _rtw_memset(pwfd_info->ip_address, 0x00, 4);
  3891. _rtw_memset(pwfd_info->peer_ip_address, 0x00, 4);
  3892. return res;
  3893. }
  3894. inline void rtw_wfd_enable(_adapter *adapter, bool on)
  3895. {
  3896. struct wifi_display_info *wfdinfo = &adapter->wfd_info;
  3897. if (on) {
  3898. wfdinfo->rtsp_ctrlport = wfdinfo->init_rtsp_ctrlport;
  3899. wfdinfo->wfd_enable = _TRUE;
  3900. } else {
  3901. wfdinfo->wfd_enable = _FALSE;
  3902. wfdinfo->rtsp_ctrlport = 0;
  3903. }
  3904. }
  3905. inline void rtw_wfd_set_ctrl_port(_adapter *adapter, u16 port)
  3906. {
  3907. struct wifi_display_info *wfdinfo = &adapter->wfd_info;
  3908. wfdinfo->init_rtsp_ctrlport = port;
  3909. if (wfdinfo->wfd_enable == _TRUE)
  3910. wfdinfo->rtsp_ctrlport = port;
  3911. if (adapter->wdinfo.wfd_tdls_enable == 1)
  3912. wfdinfo->tdls_rtsp_ctrlport = port;
  3913. }
  3914. inline void rtw_tdls_wfd_enable(_adapter *adapter, bool on)
  3915. {
  3916. struct wifi_display_info *wfdinfo = &adapter->wfd_info;
  3917. if (on) {
  3918. wfdinfo->tdls_rtsp_ctrlport = wfdinfo->init_rtsp_ctrlport;
  3919. adapter->wdinfo.wfd_tdls_enable = 1;
  3920. } else {
  3921. adapter->wdinfo.wfd_tdls_enable = 0;
  3922. wfdinfo->tdls_rtsp_ctrlport = 0;
  3923. }
  3924. }
  3925. u32 rtw_append_beacon_wfd_ie(_adapter *adapter, u8 *pbuf)
  3926. {
  3927. struct wifidirect_info *wdinfo = &adapter->wdinfo;
  3928. struct mlme_priv *mlme = &adapter->mlmepriv;
  3929. u8 build_ie_by_self = 0;
  3930. u32 len = 0;
  3931. if (!hal_chk_wl_func(adapter, WL_FUNC_MIRACAST))
  3932. goto exit;
  3933. #ifdef CONFIG_IOCTL_CFG80211
  3934. if (_TRUE == wdinfo->wfd_info->wfd_enable)
  3935. #endif
  3936. build_ie_by_self = 1;
  3937. if (build_ie_by_self)
  3938. len = build_beacon_wfd_ie(wdinfo, pbuf);
  3939. #ifdef CONFIG_IOCTL_CFG80211
  3940. else if (mlme->wfd_beacon_ie && mlme->wfd_beacon_ie_len > 0) {
  3941. len = mlme->wfd_beacon_ie_len;
  3942. _rtw_memcpy(pbuf, mlme->wfd_beacon_ie, len);
  3943. }
  3944. #endif
  3945. exit:
  3946. return len;
  3947. }
  3948. u32 rtw_append_probe_req_wfd_ie(_adapter *adapter, u8 *pbuf)
  3949. {
  3950. struct wifidirect_info *wdinfo = &adapter->wdinfo;
  3951. struct mlme_priv *mlme = &adapter->mlmepriv;
  3952. u8 build_ie_by_self = 0;
  3953. u32 len = 0;
  3954. if (!hal_chk_wl_func(adapter, WL_FUNC_MIRACAST))
  3955. goto exit;
  3956. #ifdef CONFIG_IOCTL_CFG80211
  3957. if (_TRUE == wdinfo->wfd_info->wfd_enable)
  3958. #endif
  3959. build_ie_by_self = 1;
  3960. if (build_ie_by_self)
  3961. len = build_probe_req_wfd_ie(wdinfo, pbuf);
  3962. #ifdef CONFIG_IOCTL_CFG80211
  3963. else if (mlme->wfd_probe_req_ie && mlme->wfd_probe_req_ie_len > 0) {
  3964. len = mlme->wfd_probe_req_ie_len;
  3965. _rtw_memcpy(pbuf, mlme->wfd_probe_req_ie, len);
  3966. }
  3967. #endif
  3968. exit:
  3969. return len;
  3970. }
  3971. u32 rtw_append_probe_resp_wfd_ie(_adapter *adapter, u8 *pbuf)
  3972. {
  3973. struct wifidirect_info *wdinfo = &adapter->wdinfo;
  3974. struct mlme_priv *mlme = &adapter->mlmepriv;
  3975. u8 build_ie_by_self = 0;
  3976. u32 len = 0;
  3977. if (!hal_chk_wl_func(adapter, WL_FUNC_MIRACAST))
  3978. goto exit;
  3979. #ifdef CONFIG_IOCTL_CFG80211
  3980. if (_TRUE == wdinfo->wfd_info->wfd_enable)
  3981. #endif
  3982. build_ie_by_self = 1;
  3983. if (build_ie_by_self)
  3984. len = build_probe_resp_wfd_ie(wdinfo, pbuf, 0);
  3985. #ifdef CONFIG_IOCTL_CFG80211
  3986. else if (mlme->wfd_probe_resp_ie && mlme->wfd_probe_resp_ie_len > 0) {
  3987. len = mlme->wfd_probe_resp_ie_len;
  3988. _rtw_memcpy(pbuf, mlme->wfd_probe_resp_ie, len);
  3989. }
  3990. #endif
  3991. exit:
  3992. return len;
  3993. }
  3994. u32 rtw_append_assoc_req_wfd_ie(_adapter *adapter, u8 *pbuf)
  3995. {
  3996. struct wifidirect_info *wdinfo = &adapter->wdinfo;
  3997. struct mlme_priv *mlme = &adapter->mlmepriv;
  3998. u8 build_ie_by_self = 0;
  3999. u32 len = 0;
  4000. if (!hal_chk_wl_func(adapter, WL_FUNC_MIRACAST))
  4001. goto exit;
  4002. #ifdef CONFIG_IOCTL_CFG80211
  4003. if (_TRUE == wdinfo->wfd_info->wfd_enable)
  4004. #endif
  4005. build_ie_by_self = 1;
  4006. if (build_ie_by_self)
  4007. len = build_assoc_req_wfd_ie(wdinfo, pbuf);
  4008. #ifdef CONFIG_IOCTL_CFG80211
  4009. else if (mlme->wfd_assoc_req_ie && mlme->wfd_assoc_req_ie_len > 0) {
  4010. len = mlme->wfd_assoc_req_ie_len;
  4011. _rtw_memcpy(pbuf, mlme->wfd_assoc_req_ie, len);
  4012. }
  4013. #endif
  4014. exit:
  4015. return len;
  4016. }
  4017. u32 rtw_append_assoc_resp_wfd_ie(_adapter *adapter, u8 *pbuf)
  4018. {
  4019. struct wifidirect_info *wdinfo = &adapter->wdinfo;
  4020. struct mlme_priv *mlme = &adapter->mlmepriv;
  4021. u8 build_ie_by_self = 0;
  4022. u32 len = 0;
  4023. if (!hal_chk_wl_func(adapter, WL_FUNC_MIRACAST))
  4024. goto exit;
  4025. #ifdef CONFIG_IOCTL_CFG80211
  4026. if (_TRUE == wdinfo->wfd_info->wfd_enable)
  4027. #endif
  4028. build_ie_by_self = 1;
  4029. if (build_ie_by_self)
  4030. len = build_assoc_resp_wfd_ie(wdinfo, pbuf);
  4031. #ifdef CONFIG_IOCTL_CFG80211
  4032. else if (mlme->wfd_assoc_resp_ie && mlme->wfd_assoc_resp_ie_len > 0) {
  4033. len = mlme->wfd_assoc_resp_ie_len;
  4034. _rtw_memcpy(pbuf, mlme->wfd_assoc_resp_ie, len);
  4035. }
  4036. #endif
  4037. exit:
  4038. return len;
  4039. }
  4040. #endif /* CONFIG_WFD */
  4041. void rtw_init_wifidirect_timers(_adapter *padapter)
  4042. {
  4043. struct wifidirect_info *pwdinfo = &padapter->wdinfo;
  4044. rtw_init_timer(&pwdinfo->find_phase_timer, padapter, find_phase_timer_process, padapter);
  4045. rtw_init_timer(&pwdinfo->restore_p2p_state_timer, padapter, restore_p2p_state_timer_process, padapter);
  4046. rtw_init_timer(&pwdinfo->pre_tx_scan_timer, padapter, pre_tx_scan_timer_process, padapter);
  4047. rtw_init_timer(&pwdinfo->reset_ch_sitesurvey, padapter, reset_ch_sitesurvey_timer_process, padapter);
  4048. rtw_init_timer(&pwdinfo->reset_ch_sitesurvey2, padapter, reset_ch_sitesurvey_timer_process2, padapter);
  4049. #ifdef CONFIG_CONCURRENT_MODE
  4050. rtw_init_timer(&pwdinfo->ap_p2p_switch_timer, padapter, ap_p2p_switch_timer_process, padapter);
  4051. #endif
  4052. }
  4053. void rtw_init_wifidirect_addrs(_adapter *padapter, u8 *dev_addr, u8 *iface_addr)
  4054. {
  4055. #ifdef CONFIG_P2P
  4056. struct wifidirect_info *pwdinfo = &padapter->wdinfo;
  4057. /*init device&interface address */
  4058. if (dev_addr)
  4059. _rtw_memcpy(pwdinfo->device_addr, dev_addr, ETH_ALEN);
  4060. if (iface_addr)
  4061. _rtw_memcpy(pwdinfo->interface_addr, iface_addr, ETH_ALEN);
  4062. #endif
  4063. }
  4064. void init_wifidirect_info(_adapter *padapter, enum P2P_ROLE role)
  4065. {
  4066. struct wifidirect_info *pwdinfo;
  4067. #ifdef CONFIG_WFD
  4068. struct wifi_display_info *pwfd_info = &padapter->wfd_info;
  4069. #endif
  4070. pwdinfo = &padapter->wdinfo;
  4071. pwdinfo->padapter = padapter;
  4072. /* 1, 6, 11 are the social channel defined in the WiFi Direct specification. */
  4073. pwdinfo->social_chan[0] = 1;
  4074. pwdinfo->social_chan[1] = 6;
  4075. pwdinfo->social_chan[2] = 11;
  4076. pwdinfo->social_chan[3] = 0; /* channel 0 for scanning ending in site survey function. */
  4077. if (role != P2P_ROLE_DISABLE
  4078. && pwdinfo->driver_interface != DRIVER_CFG80211
  4079. ) {
  4080. #ifdef CONFIG_CONCURRENT_MODE
  4081. u8 union_ch = 0;
  4082. if (rtw_mi_check_status(padapter, MI_LINKED))
  4083. union_ch = rtw_mi_get_union_chan(padapter);
  4084. if (union_ch != 0 &&
  4085. (union_ch == 1 || union_ch == 6 || union_ch == 11)
  4086. ) {
  4087. /* Use the AP's channel as the listen channel */
  4088. /* This will avoid the channel switch between AP's channel and listen channel */
  4089. pwdinfo->listen_channel = union_ch;
  4090. } else
  4091. #endif /* CONFIG_CONCURRENT_MODE */
  4092. {
  4093. /* Use the channel 11 as the listen channel */
  4094. pwdinfo->listen_channel = 11;
  4095. }
  4096. }
  4097. if (role == P2P_ROLE_DEVICE) {
  4098. rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
  4099. #ifdef CONFIG_CONCURRENT_MODE
  4100. if (rtw_mi_check_status(padapter, MI_LINKED))
  4101. rtw_p2p_set_state(pwdinfo, P2P_STATE_IDLE);
  4102. else
  4103. #endif
  4104. rtw_p2p_set_state(pwdinfo, P2P_STATE_LISTEN);
  4105. pwdinfo->intent = 1;
  4106. rtw_p2p_set_pre_state(pwdinfo, P2P_STATE_LISTEN);
  4107. } else if (role == P2P_ROLE_CLIENT) {
  4108. rtw_p2p_set_role(pwdinfo, P2P_ROLE_CLIENT);
  4109. rtw_p2p_set_state(pwdinfo, P2P_STATE_GONEGO_OK);
  4110. pwdinfo->intent = 1;
  4111. rtw_p2p_set_pre_state(pwdinfo, P2P_STATE_GONEGO_OK);
  4112. } else if (role == P2P_ROLE_GO) {
  4113. rtw_p2p_set_role(pwdinfo, P2P_ROLE_GO);
  4114. rtw_p2p_set_state(pwdinfo, P2P_STATE_GONEGO_OK);
  4115. pwdinfo->intent = 15;
  4116. rtw_p2p_set_pre_state(pwdinfo, P2P_STATE_GONEGO_OK);
  4117. }
  4118. /* Use the OFDM rate in the P2P probe response frame. ( 6(B), 9(B), 12, 18, 24, 36, 48, 54 ) */
  4119. pwdinfo->support_rate[0] = 0x8c; /* 6(B) */
  4120. pwdinfo->support_rate[1] = 0x92; /* 9(B) */
  4121. pwdinfo->support_rate[2] = 0x18; /* 12 */
  4122. pwdinfo->support_rate[3] = 0x24; /* 18 */
  4123. pwdinfo->support_rate[4] = 0x30; /* 24 */
  4124. pwdinfo->support_rate[5] = 0x48; /* 36 */
  4125. pwdinfo->support_rate[6] = 0x60; /* 48 */
  4126. pwdinfo->support_rate[7] = 0x6c; /* 54 */
  4127. _rtw_memcpy((void *) pwdinfo->p2p_wildcard_ssid, "DIRECT-", 7);
  4128. _rtw_memset(pwdinfo->device_name, 0x00, WPS_MAX_DEVICE_NAME_LEN);
  4129. pwdinfo->device_name_len = 0;
  4130. _rtw_memset(&pwdinfo->invitereq_info, 0x00, sizeof(struct tx_invite_req_info));
  4131. pwdinfo->invitereq_info.token = 3; /* Token used for P2P invitation request frame. */
  4132. _rtw_memset(&pwdinfo->inviteresp_info, 0x00, sizeof(struct tx_invite_resp_info));
  4133. pwdinfo->inviteresp_info.token = 0;
  4134. pwdinfo->profileindex = 0;
  4135. _rtw_memset(&pwdinfo->profileinfo[0], 0x00, sizeof(struct profile_info) * P2P_MAX_PERSISTENT_GROUP_NUM);
  4136. rtw_p2p_findphase_ex_set(pwdinfo, P2P_FINDPHASE_EX_NONE);
  4137. pwdinfo->listen_dwell = (u8)((rtw_get_current_time() % 3) + 1);
  4138. /* RTW_INFO( "[%s] listen_dwell time is %d00ms\n", __FUNCTION__, pwdinfo->listen_dwell ); */
  4139. _rtw_memset(&pwdinfo->tx_prov_disc_info, 0x00, sizeof(struct tx_provdisc_req_info));
  4140. pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_NONE;
  4141. _rtw_memset(&pwdinfo->nego_req_info, 0x00, sizeof(struct tx_nego_req_info));
  4142. pwdinfo->device_password_id_for_nego = WPS_DPID_PBC;
  4143. pwdinfo->negotiation_dialog_token = 1;
  4144. _rtw_memset(pwdinfo->nego_ssid, 0x00, WLAN_SSID_MAXLEN);
  4145. pwdinfo->nego_ssidlen = 0;
  4146. pwdinfo->ui_got_wps_info = P2P_NO_WPSINFO;
  4147. #ifdef CONFIG_WFD
  4148. pwdinfo->supported_wps_cm = WPS_CONFIG_METHOD_DISPLAY | WPS_CONFIG_METHOD_PBC;
  4149. pwdinfo->wfd_info = pwfd_info;
  4150. #else
  4151. pwdinfo->supported_wps_cm = WPS_CONFIG_METHOD_DISPLAY | WPS_CONFIG_METHOD_PBC | WPS_CONFIG_METHOD_KEYPAD;
  4152. #endif /* CONFIG_WFD */
  4153. pwdinfo->channel_list_attr_len = 0;
  4154. _rtw_memset(pwdinfo->channel_list_attr, 0x00, 100);
  4155. _rtw_memset(pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req, 0x00, 4);
  4156. _rtw_memset(pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req, '0', 3);
  4157. _rtw_memset(&pwdinfo->groupid_info, 0x00, sizeof(struct group_id_info));
  4158. #ifdef CONFIG_CONCURRENT_MODE
  4159. #ifdef CONFIG_IOCTL_CFG80211
  4160. pwdinfo->ext_listen_interval = 1000; /* The interval to be available with legacy AP during p2p0-find/scan */
  4161. pwdinfo->ext_listen_period = 3000; /* The time period to be available for P2P during nego */
  4162. #else /* !CONFIG_IOCTL_CFG80211 */
  4163. /* pwdinfo->ext_listen_interval = 3000; */
  4164. /* pwdinfo->ext_listen_period = 400; */
  4165. pwdinfo->ext_listen_interval = 1000;
  4166. pwdinfo->ext_listen_period = 1000;
  4167. #endif /* !CONFIG_IOCTL_CFG80211 */
  4168. #endif
  4169. /* Commented by Kurt 20130319
  4170. * For WiDi purpose: Use CFG80211 interface but controled WFD/RDS frame by driver itself. */
  4171. #ifdef CONFIG_IOCTL_CFG80211
  4172. pwdinfo->driver_interface = DRIVER_CFG80211;
  4173. #else
  4174. pwdinfo->driver_interface = DRIVER_WEXT;
  4175. #endif /* CONFIG_IOCTL_CFG80211 */
  4176. pwdinfo->wfd_tdls_enable = 0;
  4177. _rtw_memset(pwdinfo->p2p_peer_interface_addr, 0x00, ETH_ALEN);
  4178. _rtw_memset(pwdinfo->p2p_peer_device_addr, 0x00, ETH_ALEN);
  4179. pwdinfo->rx_invitereq_info.operation_ch[0] = 0;
  4180. pwdinfo->rx_invitereq_info.operation_ch[1] = 0; /* Used to indicate the scan end in site survey function */
  4181. #ifdef CONFIG_P2P_OP_CHK_SOCIAL_CH
  4182. pwdinfo->rx_invitereq_info.operation_ch[2] = 0;
  4183. pwdinfo->rx_invitereq_info.operation_ch[3] = 0;
  4184. pwdinfo->rx_invitereq_info.operation_ch[4] = 0;
  4185. #endif /* CONFIG_P2P_OP_CHK_SOCIAL_CH */
  4186. pwdinfo->rx_invitereq_info.scan_op_ch_only = 0;
  4187. pwdinfo->p2p_info.operation_ch[0] = 0;
  4188. pwdinfo->p2p_info.operation_ch[1] = 0; /* Used to indicate the scan end in site survey function */
  4189. #ifdef CONFIG_P2P_OP_CHK_SOCIAL_CH
  4190. pwdinfo->p2p_info.operation_ch[2] = 0;
  4191. pwdinfo->p2p_info.operation_ch[3] = 0;
  4192. pwdinfo->p2p_info.operation_ch[4] = 0;
  4193. #endif /* CONFIG_P2P_OP_CHK_SOCIAL_CH */
  4194. pwdinfo->p2p_info.scan_op_ch_only = 0;
  4195. }
  4196. void _rtw_p2p_set_role(struct wifidirect_info *wdinfo, enum P2P_ROLE role)
  4197. {
  4198. if (wdinfo->role != role) {
  4199. wdinfo->role = role;
  4200. rtw_mi_update_iface_status(&(wdinfo->padapter->mlmepriv), 0);
  4201. }
  4202. }
  4203. #ifdef CONFIG_DBG_P2P
  4204. /**
  4205. * rtw_p2p_role_txt - Get the p2p role name as a text string
  4206. * @role: P2P role
  4207. * Returns: The state name as a printable text string
  4208. */
  4209. const char *rtw_p2p_role_txt(enum P2P_ROLE role)
  4210. {
  4211. switch (role) {
  4212. case P2P_ROLE_DISABLE:
  4213. return "P2P_ROLE_DISABLE";
  4214. case P2P_ROLE_DEVICE:
  4215. return "P2P_ROLE_DEVICE";
  4216. case P2P_ROLE_CLIENT:
  4217. return "P2P_ROLE_CLIENT";
  4218. case P2P_ROLE_GO:
  4219. return "P2P_ROLE_GO";
  4220. default:
  4221. return "UNKNOWN";
  4222. }
  4223. }
  4224. /**
  4225. * rtw_p2p_state_txt - Get the p2p state name as a text string
  4226. * @state: P2P state
  4227. * Returns: The state name as a printable text string
  4228. */
  4229. const char *rtw_p2p_state_txt(enum P2P_STATE state)
  4230. {
  4231. switch (state) {
  4232. case P2P_STATE_NONE:
  4233. return "P2P_STATE_NONE";
  4234. case P2P_STATE_IDLE:
  4235. return "P2P_STATE_IDLE";
  4236. case P2P_STATE_LISTEN:
  4237. return "P2P_STATE_LISTEN";
  4238. case P2P_STATE_SCAN:
  4239. return "P2P_STATE_SCAN";
  4240. case P2P_STATE_FIND_PHASE_LISTEN:
  4241. return "P2P_STATE_FIND_PHASE_LISTEN";
  4242. case P2P_STATE_FIND_PHASE_SEARCH:
  4243. return "P2P_STATE_FIND_PHASE_SEARCH";
  4244. case P2P_STATE_TX_PROVISION_DIS_REQ:
  4245. return "P2P_STATE_TX_PROVISION_DIS_REQ";
  4246. case P2P_STATE_RX_PROVISION_DIS_RSP:
  4247. return "P2P_STATE_RX_PROVISION_DIS_RSP";
  4248. case P2P_STATE_RX_PROVISION_DIS_REQ:
  4249. return "P2P_STATE_RX_PROVISION_DIS_REQ";
  4250. case P2P_STATE_GONEGO_ING:
  4251. return "P2P_STATE_GONEGO_ING";
  4252. case P2P_STATE_GONEGO_OK:
  4253. return "P2P_STATE_GONEGO_OK";
  4254. case P2P_STATE_GONEGO_FAIL:
  4255. return "P2P_STATE_GONEGO_FAIL";
  4256. case P2P_STATE_RECV_INVITE_REQ_MATCH:
  4257. return "P2P_STATE_RECV_INVITE_REQ_MATCH";
  4258. case P2P_STATE_PROVISIONING_ING:
  4259. return "P2P_STATE_PROVISIONING_ING";
  4260. case P2P_STATE_PROVISIONING_DONE:
  4261. return "P2P_STATE_PROVISIONING_DONE";
  4262. case P2P_STATE_TX_INVITE_REQ:
  4263. return "P2P_STATE_TX_INVITE_REQ";
  4264. case P2P_STATE_RX_INVITE_RESP_OK:
  4265. return "P2P_STATE_RX_INVITE_RESP_OK";
  4266. case P2P_STATE_RECV_INVITE_REQ_DISMATCH:
  4267. return "P2P_STATE_RECV_INVITE_REQ_DISMATCH";
  4268. case P2P_STATE_RECV_INVITE_REQ_GO:
  4269. return "P2P_STATE_RECV_INVITE_REQ_GO";
  4270. case P2P_STATE_RECV_INVITE_REQ_JOIN:
  4271. return "P2P_STATE_RECV_INVITE_REQ_JOIN";
  4272. case P2P_STATE_RX_INVITE_RESP_FAIL:
  4273. return "P2P_STATE_RX_INVITE_RESP_FAIL";
  4274. case P2P_STATE_RX_INFOR_NOREADY:
  4275. return "P2P_STATE_RX_INFOR_NOREADY";
  4276. case P2P_STATE_TX_INFOR_NOREADY:
  4277. return "P2P_STATE_TX_INFOR_NOREADY";
  4278. default:
  4279. return "UNKNOWN";
  4280. }
  4281. }
  4282. void dbg_rtw_p2p_set_state(struct wifidirect_info *wdinfo, enum P2P_STATE state, const char *caller, int line)
  4283. {
  4284. if (!_rtw_p2p_chk_state(wdinfo, state)) {
  4285. enum P2P_STATE old_state = _rtw_p2p_state(wdinfo);
  4286. _rtw_p2p_set_state(wdinfo, state);
  4287. RTW_INFO("[CONFIG_DBG_P2P]%s:%d set_state from %s to %s\n", caller, line
  4288. , rtw_p2p_state_txt(old_state), rtw_p2p_state_txt(_rtw_p2p_state(wdinfo))
  4289. );
  4290. } else {
  4291. RTW_INFO("[CONFIG_DBG_P2P]%s:%d set_state to same state %s\n", caller, line
  4292. , rtw_p2p_state_txt(_rtw_p2p_state(wdinfo))
  4293. );
  4294. }
  4295. }
  4296. void dbg_rtw_p2p_set_pre_state(struct wifidirect_info *wdinfo, enum P2P_STATE state, const char *caller, int line)
  4297. {
  4298. if (_rtw_p2p_pre_state(wdinfo) != state) {
  4299. enum P2P_STATE old_state = _rtw_p2p_pre_state(wdinfo);
  4300. _rtw_p2p_set_pre_state(wdinfo, state);
  4301. RTW_INFO("[CONFIG_DBG_P2P]%s:%d set_pre_state from %s to %s\n", caller, line
  4302. , rtw_p2p_state_txt(old_state), rtw_p2p_state_txt(_rtw_p2p_pre_state(wdinfo))
  4303. );
  4304. } else {
  4305. RTW_INFO("[CONFIG_DBG_P2P]%s:%d set_pre_state to same state %s\n", caller, line
  4306. , rtw_p2p_state_txt(_rtw_p2p_pre_state(wdinfo))
  4307. );
  4308. }
  4309. }
  4310. #if 0
  4311. void dbg_rtw_p2p_restore_state(struct wifidirect_info *wdinfo, const char *caller, int line)
  4312. {
  4313. if (wdinfo->pre_p2p_state != -1) {
  4314. RTW_INFO("[CONFIG_DBG_P2P]%s:%d restore from %s to %s\n", caller, line
  4315. , p2p_state_str[wdinfo->p2p_state], p2p_state_str[wdinfo->pre_p2p_state]
  4316. );
  4317. _rtw_p2p_restore_state(wdinfo);
  4318. } else {
  4319. RTW_INFO("[CONFIG_DBG_P2P]%s:%d restore no pre state, cur state %s\n", caller, line
  4320. , p2p_state_str[wdinfo->p2p_state]
  4321. );
  4322. }
  4323. }
  4324. #endif
  4325. void dbg_rtw_p2p_set_role(struct wifidirect_info *wdinfo, enum P2P_ROLE role, const char *caller, int line)
  4326. {
  4327. if (wdinfo->role != role) {
  4328. enum P2P_ROLE old_role = wdinfo->role;
  4329. _rtw_p2p_set_role(wdinfo, role);
  4330. RTW_INFO("[CONFIG_DBG_P2P]%s:%d set_role from %s to %s\n", caller, line
  4331. , rtw_p2p_role_txt(old_role), rtw_p2p_role_txt(wdinfo->role)
  4332. );
  4333. } else {
  4334. RTW_INFO("[CONFIG_DBG_P2P]%s:%d set_role to same role %s\n", caller, line
  4335. , rtw_p2p_role_txt(wdinfo->role)
  4336. );
  4337. }
  4338. }
  4339. #endif /* CONFIG_DBG_P2P */
  4340. int rtw_p2p_enable(_adapter *padapter, enum P2P_ROLE role)
  4341. {
  4342. int ret = _SUCCESS;
  4343. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  4344. if (role == P2P_ROLE_DEVICE || role == P2P_ROLE_CLIENT || role == P2P_ROLE_GO) {
  4345. #if defined(CONFIG_CONCURRENT_MODE) && (!defined(RTW_P2P_GROUP_INTERFACE) || !RTW_P2P_GROUP_INTERFACE)
  4346. /* Commented by Albert 2011/12/30 */
  4347. /* The driver just supports 1 P2P group operation. */
  4348. /* So, this function will do nothing if the buddy adapter had enabled the P2P function. */
  4349. /*if(!rtw_p2p_chk_state(pbuddy_wdinfo, P2P_STATE_NONE))
  4350. return ret;*/
  4351. /*The buddy adapter had enabled the P2P function.*/
  4352. if (rtw_mi_buddy_stay_in_p2p_mode(padapter))
  4353. return ret;
  4354. #endif /* CONFIG_CONCURRENT_MODE */
  4355. /* leave IPS/Autosuspend */
  4356. if (_FAIL == rtw_pwr_wakeup(padapter)) {
  4357. ret = _FAIL;
  4358. goto exit;
  4359. }
  4360. /* Added by Albert 2011/03/22 */
  4361. /* In the P2P mode, the driver should not support the b mode. */
  4362. /* So, the Tx packet shouldn't use the CCK rate */
  4363. #ifdef CONFIG_IOCTL_CFG80211
  4364. if (rtw_cfg80211_iface_has_p2p_group_cap(padapter))
  4365. #endif
  4366. update_tx_basic_rate(padapter, WIRELESS_11AGN);
  4367. /* Enable P2P function */
  4368. init_wifidirect_info(padapter, role);
  4369. #ifdef CONFIG_IOCTL_CFG80211
  4370. if (padapter->wdinfo.driver_interface == DRIVER_CFG80211)
  4371. adapter_wdev_data(padapter)->p2p_enabled = _TRUE;
  4372. #endif
  4373. rtw_hal_set_odm_var(padapter, HAL_ODM_P2P_STATE, NULL, _TRUE);
  4374. #ifdef CONFIG_WFD
  4375. if (hal_chk_wl_func(padapter, WL_FUNC_MIRACAST))
  4376. rtw_hal_set_odm_var(padapter, HAL_ODM_WIFI_DISPLAY_STATE, NULL, _TRUE);
  4377. #endif
  4378. } else if (role == P2P_ROLE_DISABLE) {
  4379. #ifdef CONFIG_INTEL_WIDI
  4380. if (padapter->mlmepriv.p2p_reject_disable == _TRUE)
  4381. return ret;
  4382. #endif /* CONFIG_INTEL_WIDI */
  4383. #ifdef CONFIG_IOCTL_CFG80211
  4384. if (padapter->wdinfo.driver_interface == DRIVER_CFG80211)
  4385. adapter_wdev_data(padapter)->p2p_enabled = _FALSE;
  4386. #endif
  4387. pwdinfo->listen_channel = 0;
  4388. /* Disable P2P function */
  4389. if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
  4390. _cancel_timer_ex(&pwdinfo->find_phase_timer);
  4391. _cancel_timer_ex(&pwdinfo->restore_p2p_state_timer);
  4392. _cancel_timer_ex(&pwdinfo->pre_tx_scan_timer);
  4393. _cancel_timer_ex(&pwdinfo->reset_ch_sitesurvey);
  4394. _cancel_timer_ex(&pwdinfo->reset_ch_sitesurvey2);
  4395. reset_ch_sitesurvey_timer_process(padapter);
  4396. reset_ch_sitesurvey_timer_process2(padapter);
  4397. #ifdef CONFIG_CONCURRENT_MODE
  4398. _cancel_timer_ex(&pwdinfo->ap_p2p_switch_timer);
  4399. #endif
  4400. rtw_p2p_set_state(pwdinfo, P2P_STATE_NONE);
  4401. rtw_p2p_set_pre_state(pwdinfo, P2P_STATE_NONE);
  4402. rtw_p2p_set_role(pwdinfo, P2P_ROLE_DISABLE);
  4403. _rtw_memset(&pwdinfo->rx_prov_disc_info, 0x00, sizeof(struct rx_provdisc_req_info));
  4404. /* Remove profiles in wifidirect_info structure. */
  4405. _rtw_memset(&pwdinfo->profileinfo[0], 0x00, sizeof(struct profile_info) * P2P_MAX_PERSISTENT_GROUP_NUM);
  4406. pwdinfo->profileindex = 0;
  4407. }
  4408. rtw_hal_set_odm_var(padapter, HAL_ODM_P2P_STATE, NULL, _FALSE);
  4409. #ifdef CONFIG_WFD
  4410. if (hal_chk_wl_func(padapter, WL_FUNC_MIRACAST))
  4411. rtw_hal_set_odm_var(padapter, HAL_ODM_WIFI_DISPLAY_STATE, NULL, _FALSE);
  4412. #endif
  4413. if (_FAIL == rtw_pwr_wakeup(padapter)) {
  4414. ret = _FAIL;
  4415. goto exit;
  4416. }
  4417. /* Restore to initial setting. */
  4418. update_tx_basic_rate(padapter, padapter->registrypriv.wireless_mode);
  4419. #ifdef CONFIG_INTEL_WIDI
  4420. rtw_reset_widi_info(padapter);
  4421. #endif /* CONFIG_INTEL_WIDI */
  4422. /* For WiDi purpose. */
  4423. #ifdef CONFIG_IOCTL_CFG80211
  4424. pwdinfo->driver_interface = DRIVER_CFG80211;
  4425. #else
  4426. pwdinfo->driver_interface = DRIVER_WEXT;
  4427. #endif /* CONFIG_IOCTL_CFG80211 */
  4428. }
  4429. exit:
  4430. return ret;
  4431. }
  4432. #endif /* CONFIG_P2P */