rtw_p2p.c 159 KB

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