ctrl_iface.c 112 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771
  1. /*
  2. * WPA Supplicant / Control interface (shared code for all backends)
  3. * Copyright (c) 2004-2012, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #include "utils/includes.h"
  9. #include "utils/common.h"
  10. #include "utils/eloop.h"
  11. #include "common/version.h"
  12. #include "common/ieee802_11_defs.h"
  13. #include "common/wpa_ctrl.h"
  14. #include "eap_peer/eap.h"
  15. #include "eapol_supp/eapol_supp_sm.h"
  16. #include "rsn_supp/wpa.h"
  17. #include "rsn_supp/preauth.h"
  18. #include "rsn_supp/pmksa_cache.h"
  19. #include "l2_packet/l2_packet.h"
  20. #include "wps/wps.h"
  21. #include "config.h"
  22. #include "wpa_supplicant_i.h"
  23. #include "driver_i.h"
  24. #include "wps_supplicant.h"
  25. #include "ibss_rsn.h"
  26. #include "ap.h"
  27. #include "p2p_supplicant.h"
  28. #include "p2p/p2p.h"
  29. #include "hs20_supplicant.h"
  30. #include "notify.h"
  31. #include "bss.h"
  32. #include "scan.h"
  33. #include "ctrl_iface.h"
  34. #include "interworking.h"
  35. #include "blacklist.h"
  36. #include "wpas_glue.h"
  37. #include "autoscan.h"
  38. extern struct wpa_driver_ops *wpa_drivers[];
  39. static int wpa_supplicant_global_iface_list(struct wpa_global *global,
  40. char *buf, int len);
  41. static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
  42. char *buf, int len);
  43. static int pno_start(struct wpa_supplicant *wpa_s)
  44. {
  45. int ret;
  46. size_t i, num_ssid;
  47. struct wpa_ssid *ssid;
  48. struct wpa_driver_scan_params params;
  49. if (wpa_s->pno)
  50. return 0;
  51. os_memset(&params, 0, sizeof(params));
  52. num_ssid = 0;
  53. ssid = wpa_s->conf->ssid;
  54. while (ssid) {
  55. if (!wpas_network_disabled(wpa_s, ssid))
  56. num_ssid++;
  57. ssid = ssid->next;
  58. }
  59. if (num_ssid > WPAS_MAX_SCAN_SSIDS) {
  60. wpa_printf(MSG_DEBUG, "PNO: Use only the first %u SSIDs from "
  61. "%u", WPAS_MAX_SCAN_SSIDS, (unsigned int) num_ssid);
  62. num_ssid = WPAS_MAX_SCAN_SSIDS;
  63. }
  64. if (num_ssid == 0) {
  65. wpa_printf(MSG_DEBUG, "PNO: No configured SSIDs");
  66. return -1;
  67. }
  68. params.filter_ssids = os_malloc(sizeof(struct wpa_driver_scan_filter) *
  69. num_ssid);
  70. if (params.filter_ssids == NULL)
  71. return -1;
  72. i = 0;
  73. ssid = wpa_s->conf->ssid;
  74. while (ssid) {
  75. if (!wpas_network_disabled(wpa_s, ssid)) {
  76. params.ssids[i].ssid = ssid->ssid;
  77. params.ssids[i].ssid_len = ssid->ssid_len;
  78. params.num_ssids++;
  79. os_memcpy(params.filter_ssids[i].ssid, ssid->ssid,
  80. ssid->ssid_len);
  81. params.filter_ssids[i].ssid_len = ssid->ssid_len;
  82. params.num_filter_ssids++;
  83. i++;
  84. if (i == num_ssid)
  85. break;
  86. }
  87. ssid = ssid->next;
  88. }
  89. ret = wpa_drv_sched_scan(wpa_s, &params, 10 * 1000);
  90. os_free(params.filter_ssids);
  91. if (ret == 0)
  92. wpa_s->pno = 1;
  93. return ret;
  94. }
  95. static int pno_stop(struct wpa_supplicant *wpa_s)
  96. {
  97. if (wpa_s->pno) {
  98. wpa_s->pno = 0;
  99. return wpa_drv_stop_sched_scan(wpa_s);
  100. }
  101. return 0;
  102. }
  103. static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
  104. {
  105. char *pos;
  106. u8 addr[ETH_ALEN], *filter = NULL, *n;
  107. size_t count = 0;
  108. pos = val;
  109. while (pos) {
  110. if (*pos == '\0')
  111. break;
  112. if (hwaddr_aton(pos, addr)) {
  113. os_free(filter);
  114. return -1;
  115. }
  116. n = os_realloc(filter, (count + 1) * ETH_ALEN);
  117. if (n == NULL) {
  118. os_free(filter);
  119. return -1;
  120. }
  121. filter = n;
  122. os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
  123. count++;
  124. pos = os_strchr(pos, ' ');
  125. if (pos)
  126. pos++;
  127. }
  128. wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
  129. os_free(wpa_s->bssid_filter);
  130. wpa_s->bssid_filter = filter;
  131. wpa_s->bssid_filter_count = count;
  132. return 0;
  133. }
  134. static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
  135. char *cmd)
  136. {
  137. char *value;
  138. int ret = 0;
  139. value = os_strchr(cmd, ' ');
  140. if (value == NULL)
  141. return -1;
  142. *value++ = '\0';
  143. wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
  144. if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
  145. eapol_sm_configure(wpa_s->eapol,
  146. atoi(value), -1, -1, -1);
  147. } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
  148. eapol_sm_configure(wpa_s->eapol,
  149. -1, atoi(value), -1, -1);
  150. } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
  151. eapol_sm_configure(wpa_s->eapol,
  152. -1, -1, atoi(value), -1);
  153. } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
  154. eapol_sm_configure(wpa_s->eapol,
  155. -1, -1, -1, atoi(value));
  156. } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
  157. if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
  158. atoi(value)))
  159. ret = -1;
  160. } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
  161. 0) {
  162. if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
  163. atoi(value)))
  164. ret = -1;
  165. } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
  166. if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
  167. ret = -1;
  168. } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
  169. wpa_s->wps_fragment_size = atoi(value);
  170. #ifdef CONFIG_WPS_TESTING
  171. } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
  172. long int val;
  173. val = strtol(value, NULL, 0);
  174. if (val < 0 || val > 0xff) {
  175. ret = -1;
  176. wpa_printf(MSG_DEBUG, "WPS: Invalid "
  177. "wps_version_number %ld", val);
  178. } else {
  179. wps_version_number = val;
  180. wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
  181. "version %u.%u",
  182. (wps_version_number & 0xf0) >> 4,
  183. wps_version_number & 0x0f);
  184. }
  185. } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
  186. wps_testing_dummy_cred = atoi(value);
  187. wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
  188. wps_testing_dummy_cred);
  189. #endif /* CONFIG_WPS_TESTING */
  190. } else if (os_strcasecmp(cmd, "ampdu") == 0) {
  191. if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
  192. ret = -1;
  193. #ifdef CONFIG_TDLS_TESTING
  194. } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
  195. extern unsigned int tdls_testing;
  196. tdls_testing = strtol(value, NULL, 0);
  197. wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
  198. #endif /* CONFIG_TDLS_TESTING */
  199. #ifdef CONFIG_TDLS
  200. } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
  201. int disabled = atoi(value);
  202. wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
  203. if (disabled) {
  204. if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
  205. ret = -1;
  206. } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
  207. ret = -1;
  208. wpa_tdls_enable(wpa_s->wpa, !disabled);
  209. #endif /* CONFIG_TDLS */
  210. } else if (os_strcasecmp(cmd, "pno") == 0) {
  211. if (atoi(value))
  212. ret = pno_start(wpa_s);
  213. else
  214. ret = pno_stop(wpa_s);
  215. } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
  216. int disabled = atoi(value);
  217. if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
  218. ret = -1;
  219. else if (disabled)
  220. wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
  221. } else if (os_strcasecmp(cmd, "uapsd") == 0) {
  222. if (os_strcmp(value, "disable") == 0)
  223. wpa_s->set_sta_uapsd = 0;
  224. else {
  225. int be, bk, vi, vo;
  226. char *pos;
  227. /* format: BE,BK,VI,VO;max SP Length */
  228. be = atoi(value);
  229. pos = os_strchr(value, ',');
  230. if (pos == NULL)
  231. return -1;
  232. pos++;
  233. bk = atoi(pos);
  234. pos = os_strchr(pos, ',');
  235. if (pos == NULL)
  236. return -1;
  237. pos++;
  238. vi = atoi(pos);
  239. pos = os_strchr(pos, ',');
  240. if (pos == NULL)
  241. return -1;
  242. pos++;
  243. vo = atoi(pos);
  244. /* ignore max SP Length for now */
  245. wpa_s->set_sta_uapsd = 1;
  246. wpa_s->sta_uapsd = 0;
  247. if (be)
  248. wpa_s->sta_uapsd |= BIT(0);
  249. if (bk)
  250. wpa_s->sta_uapsd |= BIT(1);
  251. if (vi)
  252. wpa_s->sta_uapsd |= BIT(2);
  253. if (vo)
  254. wpa_s->sta_uapsd |= BIT(3);
  255. }
  256. } else if (os_strcasecmp(cmd, "ps") == 0) {
  257. ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
  258. } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
  259. ret = set_bssid_filter(wpa_s, value);
  260. } else {
  261. value[-1] = '=';
  262. ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
  263. if (ret == 0)
  264. wpa_supplicant_update_config(wpa_s);
  265. }
  266. return ret;
  267. }
  268. static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
  269. char *cmd, char *buf, size_t buflen)
  270. {
  271. int res = -1;
  272. wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
  273. if (os_strcmp(cmd, "version") == 0) {
  274. res = os_snprintf(buf, buflen, "%s", VERSION_STR);
  275. } else if (os_strcasecmp(cmd, "country") == 0) {
  276. if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
  277. res = os_snprintf(buf, buflen, "%c%c",
  278. wpa_s->conf->country[0],
  279. wpa_s->conf->country[1]);
  280. }
  281. if (res < 0 || (unsigned int) res >= buflen)
  282. return -1;
  283. return res;
  284. }
  285. #ifdef IEEE8021X_EAPOL
  286. static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
  287. char *addr)
  288. {
  289. u8 bssid[ETH_ALEN];
  290. struct wpa_ssid *ssid = wpa_s->current_ssid;
  291. if (hwaddr_aton(addr, bssid)) {
  292. wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
  293. "'%s'", addr);
  294. return -1;
  295. }
  296. wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
  297. rsn_preauth_deinit(wpa_s->wpa);
  298. if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
  299. return -1;
  300. return 0;
  301. }
  302. #endif /* IEEE8021X_EAPOL */
  303. #ifdef CONFIG_PEERKEY
  304. /* MLME-STKSTART.request(peer) */
  305. static int wpa_supplicant_ctrl_iface_stkstart(
  306. struct wpa_supplicant *wpa_s, char *addr)
  307. {
  308. u8 peer[ETH_ALEN];
  309. if (hwaddr_aton(addr, peer)) {
  310. wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
  311. "address '%s'", addr);
  312. return -1;
  313. }
  314. wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
  315. MAC2STR(peer));
  316. return wpa_sm_stkstart(wpa_s->wpa, peer);
  317. }
  318. #endif /* CONFIG_PEERKEY */
  319. #ifdef CONFIG_TDLS
  320. static int wpa_supplicant_ctrl_iface_tdls_discover(
  321. struct wpa_supplicant *wpa_s, char *addr)
  322. {
  323. u8 peer[ETH_ALEN];
  324. int ret;
  325. if (hwaddr_aton(addr, peer)) {
  326. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
  327. "address '%s'", addr);
  328. return -1;
  329. }
  330. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
  331. MAC2STR(peer));
  332. if (wpa_tdls_is_external_setup(wpa_s->wpa))
  333. ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
  334. else
  335. ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
  336. return ret;
  337. }
  338. static int wpa_supplicant_ctrl_iface_tdls_setup(
  339. struct wpa_supplicant *wpa_s, char *addr)
  340. {
  341. u8 peer[ETH_ALEN];
  342. int ret;
  343. if (hwaddr_aton(addr, peer)) {
  344. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
  345. "address '%s'", addr);
  346. return -1;
  347. }
  348. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
  349. MAC2STR(peer));
  350. ret = wpa_tdls_reneg(wpa_s->wpa, peer);
  351. if (ret) {
  352. if (wpa_tdls_is_external_setup(wpa_s->wpa))
  353. ret = wpa_tdls_start(wpa_s->wpa, peer);
  354. else
  355. ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
  356. }
  357. return ret;
  358. }
  359. static int wpa_supplicant_ctrl_iface_tdls_teardown(
  360. struct wpa_supplicant *wpa_s, char *addr)
  361. {
  362. u8 peer[ETH_ALEN];
  363. if (hwaddr_aton(addr, peer)) {
  364. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
  365. "address '%s'", addr);
  366. return -1;
  367. }
  368. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
  369. MAC2STR(peer));
  370. return wpa_tdls_teardown_link(wpa_s->wpa, peer,
  371. WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
  372. }
  373. #endif /* CONFIG_TDLS */
  374. #ifdef CONFIG_IEEE80211R
  375. static int wpa_supplicant_ctrl_iface_ft_ds(
  376. struct wpa_supplicant *wpa_s, char *addr)
  377. {
  378. u8 target_ap[ETH_ALEN];
  379. struct wpa_bss *bss;
  380. const u8 *mdie;
  381. if (hwaddr_aton(addr, target_ap)) {
  382. wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
  383. "address '%s'", addr);
  384. return -1;
  385. }
  386. wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
  387. bss = wpa_bss_get_bssid(wpa_s, target_ap);
  388. if (bss)
  389. mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
  390. else
  391. mdie = NULL;
  392. return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
  393. }
  394. #endif /* CONFIG_IEEE80211R */
  395. #ifdef CONFIG_WPS
  396. static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
  397. char *cmd)
  398. {
  399. u8 bssid[ETH_ALEN], *_bssid = bssid;
  400. #ifdef CONFIG_P2P
  401. u8 p2p_dev_addr[ETH_ALEN];
  402. #endif /* CONFIG_P2P */
  403. #ifdef CONFIG_AP
  404. u8 *_p2p_dev_addr = NULL;
  405. #endif /* CONFIG_AP */
  406. if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
  407. _bssid = NULL;
  408. #ifdef CONFIG_P2P
  409. } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
  410. if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
  411. wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
  412. "P2P Device Address '%s'",
  413. cmd + 13);
  414. return -1;
  415. }
  416. _p2p_dev_addr = p2p_dev_addr;
  417. #endif /* CONFIG_P2P */
  418. } else if (hwaddr_aton(cmd, bssid)) {
  419. wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
  420. cmd);
  421. return -1;
  422. }
  423. #ifdef CONFIG_AP
  424. if (wpa_s->ap_iface)
  425. return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
  426. #endif /* CONFIG_AP */
  427. return wpas_wps_start_pbc(wpa_s, _bssid, 0);
  428. }
  429. static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
  430. char *cmd, char *buf,
  431. size_t buflen)
  432. {
  433. u8 bssid[ETH_ALEN], *_bssid = bssid;
  434. char *pin;
  435. int ret;
  436. pin = os_strchr(cmd, ' ');
  437. if (pin)
  438. *pin++ = '\0';
  439. if (os_strcmp(cmd, "any") == 0)
  440. _bssid = NULL;
  441. else if (os_strcmp(cmd, "get") == 0) {
  442. ret = wps_generate_pin();
  443. goto done;
  444. } else if (hwaddr_aton(cmd, bssid)) {
  445. wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
  446. cmd);
  447. return -1;
  448. }
  449. #ifdef CONFIG_AP
  450. if (wpa_s->ap_iface)
  451. return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
  452. buf, buflen);
  453. #endif /* CONFIG_AP */
  454. if (pin) {
  455. ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
  456. DEV_PW_DEFAULT);
  457. if (ret < 0)
  458. return -1;
  459. ret = os_snprintf(buf, buflen, "%s", pin);
  460. if (ret < 0 || (size_t) ret >= buflen)
  461. return -1;
  462. return ret;
  463. }
  464. ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
  465. if (ret < 0)
  466. return -1;
  467. done:
  468. /* Return the generated PIN */
  469. ret = os_snprintf(buf, buflen, "%08d", ret);
  470. if (ret < 0 || (size_t) ret >= buflen)
  471. return -1;
  472. return ret;
  473. }
  474. static int wpa_supplicant_ctrl_iface_wps_check_pin(
  475. struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
  476. {
  477. char pin[9];
  478. size_t len;
  479. char *pos;
  480. int ret;
  481. wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
  482. (u8 *) cmd, os_strlen(cmd));
  483. for (pos = cmd, len = 0; *pos != '\0'; pos++) {
  484. if (*pos < '0' || *pos > '9')
  485. continue;
  486. pin[len++] = *pos;
  487. if (len == 9) {
  488. wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
  489. return -1;
  490. }
  491. }
  492. if (len != 4 && len != 8) {
  493. wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
  494. return -1;
  495. }
  496. pin[len] = '\0';
  497. if (len == 8) {
  498. unsigned int pin_val;
  499. pin_val = atoi(pin);
  500. if (!wps_pin_valid(pin_val)) {
  501. wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
  502. ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
  503. if (ret < 0 || (size_t) ret >= buflen)
  504. return -1;
  505. return ret;
  506. }
  507. }
  508. ret = os_snprintf(buf, buflen, "%s", pin);
  509. if (ret < 0 || (size_t) ret >= buflen)
  510. return -1;
  511. return ret;
  512. }
  513. #ifdef CONFIG_WPS_OOB
  514. static int wpa_supplicant_ctrl_iface_wps_oob(struct wpa_supplicant *wpa_s,
  515. char *cmd)
  516. {
  517. char *path, *method, *name;
  518. path = os_strchr(cmd, ' ');
  519. if (path == NULL)
  520. return -1;
  521. *path++ = '\0';
  522. method = os_strchr(path, ' ');
  523. if (method == NULL)
  524. return -1;
  525. *method++ = '\0';
  526. name = os_strchr(method, ' ');
  527. if (name != NULL)
  528. *name++ = '\0';
  529. return wpas_wps_start_oob(wpa_s, cmd, path, method, name);
  530. }
  531. #endif /* CONFIG_WPS_OOB */
  532. #ifdef CONFIG_WPS_NFC
  533. static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
  534. char *cmd)
  535. {
  536. u8 bssid[ETH_ALEN], *_bssid = bssid;
  537. if (cmd == NULL || cmd[0] == '\0')
  538. _bssid = NULL;
  539. else if (hwaddr_aton(cmd, bssid))
  540. return -1;
  541. return wpas_wps_start_nfc(wpa_s, _bssid);
  542. }
  543. static int wpa_supplicant_ctrl_iface_wps_nfc_token(
  544. struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
  545. {
  546. int ndef;
  547. struct wpabuf *buf;
  548. int res;
  549. if (os_strcmp(cmd, "WPS") == 0)
  550. ndef = 0;
  551. else if (os_strcmp(cmd, "NDEF") == 0)
  552. ndef = 1;
  553. else
  554. return -1;
  555. buf = wpas_wps_nfc_token(wpa_s, ndef);
  556. if (buf == NULL)
  557. return -1;
  558. res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
  559. wpabuf_len(buf));
  560. reply[res++] = '\n';
  561. reply[res] = '\0';
  562. wpabuf_free(buf);
  563. return res;
  564. }
  565. static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
  566. struct wpa_supplicant *wpa_s, char *pos)
  567. {
  568. size_t len;
  569. struct wpabuf *buf;
  570. int ret;
  571. len = os_strlen(pos);
  572. if (len & 0x01)
  573. return -1;
  574. len /= 2;
  575. buf = wpabuf_alloc(len);
  576. if (buf == NULL)
  577. return -1;
  578. if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
  579. wpabuf_free(buf);
  580. return -1;
  581. }
  582. ret = wpas_wps_nfc_tag_read(wpa_s, buf);
  583. wpabuf_free(buf);
  584. return ret;
  585. }
  586. #endif /* CONFIG_WPS_NFC */
  587. static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
  588. char *cmd)
  589. {
  590. u8 bssid[ETH_ALEN];
  591. char *pin;
  592. char *new_ssid;
  593. char *new_auth;
  594. char *new_encr;
  595. char *new_key;
  596. struct wps_new_ap_settings ap;
  597. pin = os_strchr(cmd, ' ');
  598. if (pin == NULL)
  599. return -1;
  600. *pin++ = '\0';
  601. if (hwaddr_aton(cmd, bssid)) {
  602. wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
  603. cmd);
  604. return -1;
  605. }
  606. new_ssid = os_strchr(pin, ' ');
  607. if (new_ssid == NULL)
  608. return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
  609. *new_ssid++ = '\0';
  610. new_auth = os_strchr(new_ssid, ' ');
  611. if (new_auth == NULL)
  612. return -1;
  613. *new_auth++ = '\0';
  614. new_encr = os_strchr(new_auth, ' ');
  615. if (new_encr == NULL)
  616. return -1;
  617. *new_encr++ = '\0';
  618. new_key = os_strchr(new_encr, ' ');
  619. if (new_key == NULL)
  620. return -1;
  621. *new_key++ = '\0';
  622. os_memset(&ap, 0, sizeof(ap));
  623. ap.ssid_hex = new_ssid;
  624. ap.auth = new_auth;
  625. ap.encr = new_encr;
  626. ap.key_hex = new_key;
  627. return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
  628. }
  629. #ifdef CONFIG_AP
  630. static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
  631. char *cmd, char *buf,
  632. size_t buflen)
  633. {
  634. int timeout = 300;
  635. char *pos;
  636. const char *pin_txt;
  637. if (!wpa_s->ap_iface)
  638. return -1;
  639. pos = os_strchr(cmd, ' ');
  640. if (pos)
  641. *pos++ = '\0';
  642. if (os_strcmp(cmd, "disable") == 0) {
  643. wpas_wps_ap_pin_disable(wpa_s);
  644. return os_snprintf(buf, buflen, "OK\n");
  645. }
  646. if (os_strcmp(cmd, "random") == 0) {
  647. if (pos)
  648. timeout = atoi(pos);
  649. pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
  650. if (pin_txt == NULL)
  651. return -1;
  652. return os_snprintf(buf, buflen, "%s", pin_txt);
  653. }
  654. if (os_strcmp(cmd, "get") == 0) {
  655. pin_txt = wpas_wps_ap_pin_get(wpa_s);
  656. if (pin_txt == NULL)
  657. return -1;
  658. return os_snprintf(buf, buflen, "%s", pin_txt);
  659. }
  660. if (os_strcmp(cmd, "set") == 0) {
  661. char *pin;
  662. if (pos == NULL)
  663. return -1;
  664. pin = pos;
  665. pos = os_strchr(pos, ' ');
  666. if (pos) {
  667. *pos++ = '\0';
  668. timeout = atoi(pos);
  669. }
  670. if (os_strlen(pin) > buflen)
  671. return -1;
  672. if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
  673. return -1;
  674. return os_snprintf(buf, buflen, "%s", pin);
  675. }
  676. return -1;
  677. }
  678. #endif /* CONFIG_AP */
  679. #ifdef CONFIG_WPS_ER
  680. static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
  681. char *cmd)
  682. {
  683. char *uuid = cmd, *pin, *pos;
  684. u8 addr_buf[ETH_ALEN], *addr = NULL;
  685. pin = os_strchr(uuid, ' ');
  686. if (pin == NULL)
  687. return -1;
  688. *pin++ = '\0';
  689. pos = os_strchr(pin, ' ');
  690. if (pos) {
  691. *pos++ = '\0';
  692. if (hwaddr_aton(pos, addr_buf) == 0)
  693. addr = addr_buf;
  694. }
  695. return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
  696. }
  697. static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
  698. char *cmd)
  699. {
  700. char *uuid = cmd, *pin;
  701. pin = os_strchr(uuid, ' ');
  702. if (pin == NULL)
  703. return -1;
  704. *pin++ = '\0';
  705. return wpas_wps_er_learn(wpa_s, uuid, pin);
  706. }
  707. static int wpa_supplicant_ctrl_iface_wps_er_set_config(
  708. struct wpa_supplicant *wpa_s, char *cmd)
  709. {
  710. char *uuid = cmd, *id;
  711. id = os_strchr(uuid, ' ');
  712. if (id == NULL)
  713. return -1;
  714. *id++ = '\0';
  715. return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
  716. }
  717. static int wpa_supplicant_ctrl_iface_wps_er_config(
  718. struct wpa_supplicant *wpa_s, char *cmd)
  719. {
  720. char *pin;
  721. char *new_ssid;
  722. char *new_auth;
  723. char *new_encr;
  724. char *new_key;
  725. struct wps_new_ap_settings ap;
  726. pin = os_strchr(cmd, ' ');
  727. if (pin == NULL)
  728. return -1;
  729. *pin++ = '\0';
  730. new_ssid = os_strchr(pin, ' ');
  731. if (new_ssid == NULL)
  732. return -1;
  733. *new_ssid++ = '\0';
  734. new_auth = os_strchr(new_ssid, ' ');
  735. if (new_auth == NULL)
  736. return -1;
  737. *new_auth++ = '\0';
  738. new_encr = os_strchr(new_auth, ' ');
  739. if (new_encr == NULL)
  740. return -1;
  741. *new_encr++ = '\0';
  742. new_key = os_strchr(new_encr, ' ');
  743. if (new_key == NULL)
  744. return -1;
  745. *new_key++ = '\0';
  746. os_memset(&ap, 0, sizeof(ap));
  747. ap.ssid_hex = new_ssid;
  748. ap.auth = new_auth;
  749. ap.encr = new_encr;
  750. ap.key_hex = new_key;
  751. return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
  752. }
  753. #ifdef CONFIG_WPS_NFC
  754. static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
  755. struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
  756. {
  757. int ndef;
  758. struct wpabuf *buf;
  759. int res;
  760. char *uuid;
  761. uuid = os_strchr(cmd, ' ');
  762. if (uuid == NULL)
  763. return -1;
  764. *uuid++ = '\0';
  765. if (os_strcmp(cmd, "WPS") == 0)
  766. ndef = 0;
  767. else if (os_strcmp(cmd, "NDEF") == 0)
  768. ndef = 1;
  769. else
  770. return -1;
  771. buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
  772. if (buf == NULL)
  773. return -1;
  774. res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
  775. wpabuf_len(buf));
  776. reply[res++] = '\n';
  777. reply[res] = '\0';
  778. wpabuf_free(buf);
  779. return res;
  780. }
  781. #endif /* CONFIG_WPS_NFC */
  782. #endif /* CONFIG_WPS_ER */
  783. #endif /* CONFIG_WPS */
  784. #ifdef CONFIG_IBSS_RSN
  785. static int wpa_supplicant_ctrl_iface_ibss_rsn(
  786. struct wpa_supplicant *wpa_s, char *addr)
  787. {
  788. u8 peer[ETH_ALEN];
  789. if (hwaddr_aton(addr, peer)) {
  790. wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
  791. "address '%s'", addr);
  792. return -1;
  793. }
  794. wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
  795. MAC2STR(peer));
  796. return ibss_rsn_start(wpa_s->ibss_rsn, peer);
  797. }
  798. #endif /* CONFIG_IBSS_RSN */
  799. static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
  800. char *rsp)
  801. {
  802. #ifdef IEEE8021X_EAPOL
  803. char *pos, *id_pos;
  804. int id;
  805. struct wpa_ssid *ssid;
  806. pos = os_strchr(rsp, '-');
  807. if (pos == NULL)
  808. return -1;
  809. *pos++ = '\0';
  810. id_pos = pos;
  811. pos = os_strchr(pos, ':');
  812. if (pos == NULL)
  813. return -1;
  814. *pos++ = '\0';
  815. id = atoi(id_pos);
  816. wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
  817. wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
  818. (u8 *) pos, os_strlen(pos));
  819. ssid = wpa_config_get_network(wpa_s->conf, id);
  820. if (ssid == NULL) {
  821. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
  822. "to update", id);
  823. return -1;
  824. }
  825. return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
  826. pos);
  827. #else /* IEEE8021X_EAPOL */
  828. wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
  829. return -1;
  830. #endif /* IEEE8021X_EAPOL */
  831. }
  832. static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
  833. const char *params,
  834. char *buf, size_t buflen)
  835. {
  836. char *pos, *end, tmp[30];
  837. int res, verbose, wps, ret;
  838. verbose = os_strcmp(params, "-VERBOSE") == 0;
  839. wps = os_strcmp(params, "-WPS") == 0;
  840. pos = buf;
  841. end = buf + buflen;
  842. if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
  843. struct wpa_ssid *ssid = wpa_s->current_ssid;
  844. ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
  845. MAC2STR(wpa_s->bssid));
  846. if (ret < 0 || ret >= end - pos)
  847. return pos - buf;
  848. pos += ret;
  849. if (ssid) {
  850. u8 *_ssid = ssid->ssid;
  851. size_t ssid_len = ssid->ssid_len;
  852. u8 ssid_buf[MAX_SSID_LEN];
  853. if (ssid_len == 0) {
  854. int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
  855. if (_res < 0)
  856. ssid_len = 0;
  857. else
  858. ssid_len = _res;
  859. _ssid = ssid_buf;
  860. }
  861. ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
  862. wpa_ssid_txt(_ssid, ssid_len),
  863. ssid->id);
  864. if (ret < 0 || ret >= end - pos)
  865. return pos - buf;
  866. pos += ret;
  867. if (wps && ssid->passphrase &&
  868. wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
  869. (ssid->mode == WPAS_MODE_AP ||
  870. ssid->mode == WPAS_MODE_P2P_GO)) {
  871. ret = os_snprintf(pos, end - pos,
  872. "passphrase=%s\n",
  873. ssid->passphrase);
  874. if (ret < 0 || ret >= end - pos)
  875. return pos - buf;
  876. pos += ret;
  877. }
  878. if (ssid->id_str) {
  879. ret = os_snprintf(pos, end - pos,
  880. "id_str=%s\n",
  881. ssid->id_str);
  882. if (ret < 0 || ret >= end - pos)
  883. return pos - buf;
  884. pos += ret;
  885. }
  886. switch (ssid->mode) {
  887. case WPAS_MODE_INFRA:
  888. ret = os_snprintf(pos, end - pos,
  889. "mode=station\n");
  890. break;
  891. case WPAS_MODE_IBSS:
  892. ret = os_snprintf(pos, end - pos,
  893. "mode=IBSS\n");
  894. break;
  895. case WPAS_MODE_AP:
  896. ret = os_snprintf(pos, end - pos,
  897. "mode=AP\n");
  898. break;
  899. case WPAS_MODE_P2P_GO:
  900. ret = os_snprintf(pos, end - pos,
  901. "mode=P2P GO\n");
  902. break;
  903. case WPAS_MODE_P2P_GROUP_FORMATION:
  904. ret = os_snprintf(pos, end - pos,
  905. "mode=P2P GO - group "
  906. "formation\n");
  907. break;
  908. default:
  909. ret = 0;
  910. break;
  911. }
  912. if (ret < 0 || ret >= end - pos)
  913. return pos - buf;
  914. pos += ret;
  915. }
  916. #ifdef CONFIG_AP
  917. if (wpa_s->ap_iface) {
  918. pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
  919. end - pos,
  920. verbose);
  921. } else
  922. #endif /* CONFIG_AP */
  923. pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
  924. }
  925. ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
  926. wpa_supplicant_state_txt(wpa_s->wpa_state));
  927. if (ret < 0 || ret >= end - pos)
  928. return pos - buf;
  929. pos += ret;
  930. if (wpa_s->l2 &&
  931. l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
  932. ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
  933. if (ret < 0 || ret >= end - pos)
  934. return pos - buf;
  935. pos += ret;
  936. }
  937. #ifdef CONFIG_P2P
  938. if (wpa_s->global->p2p) {
  939. ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
  940. "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
  941. if (ret < 0 || ret >= end - pos)
  942. return pos - buf;
  943. pos += ret;
  944. }
  945. #endif /* CONFIG_P2P */
  946. ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
  947. MAC2STR(wpa_s->own_addr));
  948. if (ret < 0 || ret >= end - pos)
  949. return pos - buf;
  950. pos += ret;
  951. #ifdef CONFIG_HS20
  952. if (wpa_s->current_bss &&
  953. wpa_bss_get_vendor_ie(wpa_s->current_bss, HS20_IE_VENDOR_TYPE)) {
  954. ret = os_snprintf(pos, end - pos, "hs20=1\n");
  955. if (ret < 0 || ret >= end - pos)
  956. return pos - buf;
  957. pos += ret;
  958. }
  959. #endif /* CONFIG_HS20 */
  960. if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
  961. wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
  962. res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
  963. verbose);
  964. if (res >= 0)
  965. pos += res;
  966. }
  967. res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
  968. if (res >= 0)
  969. pos += res;
  970. return pos - buf;
  971. }
  972. static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
  973. char *cmd)
  974. {
  975. char *pos;
  976. int id;
  977. struct wpa_ssid *ssid;
  978. u8 bssid[ETH_ALEN];
  979. /* cmd: "<network id> <BSSID>" */
  980. pos = os_strchr(cmd, ' ');
  981. if (pos == NULL)
  982. return -1;
  983. *pos++ = '\0';
  984. id = atoi(cmd);
  985. wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
  986. if (hwaddr_aton(pos, bssid)) {
  987. wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
  988. return -1;
  989. }
  990. ssid = wpa_config_get_network(wpa_s->conf, id);
  991. if (ssid == NULL) {
  992. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
  993. "to update", id);
  994. return -1;
  995. }
  996. os_memcpy(ssid->bssid, bssid, ETH_ALEN);
  997. ssid->bssid_set = !is_zero_ether_addr(bssid);
  998. return 0;
  999. }
  1000. static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
  1001. char *cmd, char *buf,
  1002. size_t buflen)
  1003. {
  1004. u8 bssid[ETH_ALEN];
  1005. struct wpa_blacklist *e;
  1006. char *pos, *end;
  1007. int ret;
  1008. /* cmd: "BLACKLIST [<BSSID>]" */
  1009. if (*cmd == '\0') {
  1010. pos = buf;
  1011. end = buf + buflen;
  1012. e = wpa_s->blacklist;
  1013. while (e) {
  1014. ret = os_snprintf(pos, end - pos, MACSTR "\n",
  1015. MAC2STR(e->bssid));
  1016. if (ret < 0 || ret >= end - pos)
  1017. return pos - buf;
  1018. pos += ret;
  1019. e = e->next;
  1020. }
  1021. return pos - buf;
  1022. }
  1023. cmd++;
  1024. if (os_strncmp(cmd, "clear", 5) == 0) {
  1025. wpa_blacklist_clear(wpa_s);
  1026. os_memcpy(buf, "OK\n", 3);
  1027. return 3;
  1028. }
  1029. wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
  1030. if (hwaddr_aton(cmd, bssid)) {
  1031. wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
  1032. return -1;
  1033. }
  1034. /*
  1035. * Add the BSSID twice, so its count will be 2, causing it to be
  1036. * skipped when processing scan results.
  1037. */
  1038. ret = wpa_blacklist_add(wpa_s, bssid);
  1039. if (ret != 0)
  1040. return -1;
  1041. ret = wpa_blacklist_add(wpa_s, bssid);
  1042. if (ret != 0)
  1043. return -1;
  1044. os_memcpy(buf, "OK\n", 3);
  1045. return 3;
  1046. }
  1047. extern int wpa_debug_level;
  1048. extern int wpa_debug_timestamp;
  1049. static const char * debug_level_str(int level)
  1050. {
  1051. switch (level) {
  1052. case MSG_EXCESSIVE:
  1053. return "EXCESSIVE";
  1054. case MSG_MSGDUMP:
  1055. return "MSGDUMP";
  1056. case MSG_DEBUG:
  1057. return "DEBUG";
  1058. case MSG_INFO:
  1059. return "INFO";
  1060. case MSG_WARNING:
  1061. return "WARNING";
  1062. case MSG_ERROR:
  1063. return "ERROR";
  1064. default:
  1065. return "?";
  1066. }
  1067. }
  1068. static int str_to_debug_level(const char *s)
  1069. {
  1070. if (os_strcasecmp(s, "EXCESSIVE") == 0)
  1071. return MSG_EXCESSIVE;
  1072. if (os_strcasecmp(s, "MSGDUMP") == 0)
  1073. return MSG_MSGDUMP;
  1074. if (os_strcasecmp(s, "DEBUG") == 0)
  1075. return MSG_DEBUG;
  1076. if (os_strcasecmp(s, "INFO") == 0)
  1077. return MSG_INFO;
  1078. if (os_strcasecmp(s, "WARNING") == 0)
  1079. return MSG_WARNING;
  1080. if (os_strcasecmp(s, "ERROR") == 0)
  1081. return MSG_ERROR;
  1082. return -1;
  1083. }
  1084. static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
  1085. char *cmd, char *buf,
  1086. size_t buflen)
  1087. {
  1088. char *pos, *end, *stamp;
  1089. int ret;
  1090. if (cmd == NULL) {
  1091. return -1;
  1092. }
  1093. /* cmd: "LOG_LEVEL [<level>]" */
  1094. if (*cmd == '\0') {
  1095. pos = buf;
  1096. end = buf + buflen;
  1097. ret = os_snprintf(pos, end - pos, "Current level: %s\n"
  1098. "Timestamp: %d\n",
  1099. debug_level_str(wpa_debug_level),
  1100. wpa_debug_timestamp);
  1101. if (ret < 0 || ret >= end - pos)
  1102. ret = 0;
  1103. return ret;
  1104. }
  1105. while (*cmd == ' ')
  1106. cmd++;
  1107. stamp = os_strchr(cmd, ' ');
  1108. if (stamp) {
  1109. *stamp++ = '\0';
  1110. while (*stamp == ' ') {
  1111. stamp++;
  1112. }
  1113. }
  1114. if (cmd && os_strlen(cmd)) {
  1115. int level = str_to_debug_level(cmd);
  1116. if (level < 0)
  1117. return -1;
  1118. wpa_debug_level = level;
  1119. }
  1120. if (stamp && os_strlen(stamp))
  1121. wpa_debug_timestamp = atoi(stamp);
  1122. os_memcpy(buf, "OK\n", 3);
  1123. return 3;
  1124. }
  1125. static int wpa_supplicant_ctrl_iface_list_networks(
  1126. struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
  1127. {
  1128. char *pos, *end;
  1129. struct wpa_ssid *ssid;
  1130. int ret;
  1131. pos = buf;
  1132. end = buf + buflen;
  1133. ret = os_snprintf(pos, end - pos,
  1134. "network id / ssid / bssid / flags\n");
  1135. if (ret < 0 || ret >= end - pos)
  1136. return pos - buf;
  1137. pos += ret;
  1138. ssid = wpa_s->conf->ssid;
  1139. while (ssid) {
  1140. ret = os_snprintf(pos, end - pos, "%d\t%s",
  1141. ssid->id,
  1142. wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
  1143. if (ret < 0 || ret >= end - pos)
  1144. return pos - buf;
  1145. pos += ret;
  1146. if (ssid->bssid_set) {
  1147. ret = os_snprintf(pos, end - pos, "\t" MACSTR,
  1148. MAC2STR(ssid->bssid));
  1149. } else {
  1150. ret = os_snprintf(pos, end - pos, "\tany");
  1151. }
  1152. if (ret < 0 || ret >= end - pos)
  1153. return pos - buf;
  1154. pos += ret;
  1155. ret = os_snprintf(pos, end - pos, "\t%s%s%s",
  1156. ssid == wpa_s->current_ssid ?
  1157. "[CURRENT]" : "",
  1158. ssid->disabled ? "[DISABLED]" : "",
  1159. ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
  1160. "");
  1161. if (ret < 0 || ret >= end - pos)
  1162. return pos - buf;
  1163. pos += ret;
  1164. ret = os_snprintf(pos, end - pos, "\n");
  1165. if (ret < 0 || ret >= end - pos)
  1166. return pos - buf;
  1167. pos += ret;
  1168. ssid = ssid->next;
  1169. }
  1170. return pos - buf;
  1171. }
  1172. static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
  1173. {
  1174. int first = 1, ret;
  1175. ret = os_snprintf(pos, end - pos, "-");
  1176. if (ret < 0 || ret >= end - pos)
  1177. return pos;
  1178. pos += ret;
  1179. if (cipher & WPA_CIPHER_NONE) {
  1180. ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : "+");
  1181. if (ret < 0 || ret >= end - pos)
  1182. return pos;
  1183. pos += ret;
  1184. first = 0;
  1185. }
  1186. if (cipher & WPA_CIPHER_WEP40) {
  1187. ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : "+");
  1188. if (ret < 0 || ret >= end - pos)
  1189. return pos;
  1190. pos += ret;
  1191. first = 0;
  1192. }
  1193. if (cipher & WPA_CIPHER_WEP104) {
  1194. ret = os_snprintf(pos, end - pos, "%sWEP104",
  1195. first ? "" : "+");
  1196. if (ret < 0 || ret >= end - pos)
  1197. return pos;
  1198. pos += ret;
  1199. first = 0;
  1200. }
  1201. if (cipher & WPA_CIPHER_TKIP) {
  1202. ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : "+");
  1203. if (ret < 0 || ret >= end - pos)
  1204. return pos;
  1205. pos += ret;
  1206. first = 0;
  1207. }
  1208. if (cipher & WPA_CIPHER_CCMP) {
  1209. ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : "+");
  1210. if (ret < 0 || ret >= end - pos)
  1211. return pos;
  1212. pos += ret;
  1213. first = 0;
  1214. }
  1215. return pos;
  1216. }
  1217. static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
  1218. const u8 *ie, size_t ie_len)
  1219. {
  1220. struct wpa_ie_data data;
  1221. int first, ret;
  1222. ret = os_snprintf(pos, end - pos, "[%s-", proto);
  1223. if (ret < 0 || ret >= end - pos)
  1224. return pos;
  1225. pos += ret;
  1226. if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
  1227. ret = os_snprintf(pos, end - pos, "?]");
  1228. if (ret < 0 || ret >= end - pos)
  1229. return pos;
  1230. pos += ret;
  1231. return pos;
  1232. }
  1233. first = 1;
  1234. if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
  1235. ret = os_snprintf(pos, end - pos, "%sEAP", first ? "" : "+");
  1236. if (ret < 0 || ret >= end - pos)
  1237. return pos;
  1238. pos += ret;
  1239. first = 0;
  1240. }
  1241. if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
  1242. ret = os_snprintf(pos, end - pos, "%sPSK", first ? "" : "+");
  1243. if (ret < 0 || ret >= end - pos)
  1244. return pos;
  1245. pos += ret;
  1246. first = 0;
  1247. }
  1248. if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
  1249. ret = os_snprintf(pos, end - pos, "%sNone", first ? "" : "+");
  1250. if (ret < 0 || ret >= end - pos)
  1251. return pos;
  1252. pos += ret;
  1253. first = 0;
  1254. }
  1255. #ifdef CONFIG_IEEE80211R
  1256. if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
  1257. ret = os_snprintf(pos, end - pos, "%sFT/EAP",
  1258. first ? "" : "+");
  1259. if (ret < 0 || ret >= end - pos)
  1260. return pos;
  1261. pos += ret;
  1262. first = 0;
  1263. }
  1264. if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
  1265. ret = os_snprintf(pos, end - pos, "%sFT/PSK",
  1266. first ? "" : "+");
  1267. if (ret < 0 || ret >= end - pos)
  1268. return pos;
  1269. pos += ret;
  1270. first = 0;
  1271. }
  1272. #endif /* CONFIG_IEEE80211R */
  1273. #ifdef CONFIG_IEEE80211W
  1274. if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
  1275. ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
  1276. first ? "" : "+");
  1277. if (ret < 0 || ret >= end - pos)
  1278. return pos;
  1279. pos += ret;
  1280. first = 0;
  1281. }
  1282. if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
  1283. ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
  1284. first ? "" : "+");
  1285. if (ret < 0 || ret >= end - pos)
  1286. return pos;
  1287. pos += ret;
  1288. first = 0;
  1289. }
  1290. #endif /* CONFIG_IEEE80211W */
  1291. pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
  1292. if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
  1293. ret = os_snprintf(pos, end - pos, "-preauth");
  1294. if (ret < 0 || ret >= end - pos)
  1295. return pos;
  1296. pos += ret;
  1297. }
  1298. ret = os_snprintf(pos, end - pos, "]");
  1299. if (ret < 0 || ret >= end - pos)
  1300. return pos;
  1301. pos += ret;
  1302. return pos;
  1303. }
  1304. #ifdef CONFIG_WPS
  1305. static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
  1306. char *pos, char *end,
  1307. struct wpabuf *wps_ie)
  1308. {
  1309. int ret;
  1310. const char *txt;
  1311. if (wps_ie == NULL)
  1312. return pos;
  1313. if (wps_is_selected_pbc_registrar(wps_ie))
  1314. txt = "[WPS-PBC]";
  1315. #ifdef CONFIG_WPS2
  1316. else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
  1317. txt = "[WPS-AUTH]";
  1318. #endif /* CONFIG_WPS2 */
  1319. else if (wps_is_selected_pin_registrar(wps_ie))
  1320. txt = "[WPS-PIN]";
  1321. else
  1322. txt = "[WPS]";
  1323. ret = os_snprintf(pos, end - pos, "%s", txt);
  1324. if (ret >= 0 && ret < end - pos)
  1325. pos += ret;
  1326. wpabuf_free(wps_ie);
  1327. return pos;
  1328. }
  1329. #endif /* CONFIG_WPS */
  1330. static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
  1331. char *pos, char *end,
  1332. const struct wpa_bss *bss)
  1333. {
  1334. #ifdef CONFIG_WPS
  1335. struct wpabuf *wps_ie;
  1336. wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
  1337. return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
  1338. #else /* CONFIG_WPS */
  1339. return pos;
  1340. #endif /* CONFIG_WPS */
  1341. }
  1342. /* Format one result on one text line into a buffer. */
  1343. static int wpa_supplicant_ctrl_iface_scan_result(
  1344. struct wpa_supplicant *wpa_s,
  1345. const struct wpa_bss *bss, char *buf, size_t buflen)
  1346. {
  1347. char *pos, *end;
  1348. int ret;
  1349. const u8 *ie, *ie2, *p2p;
  1350. p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
  1351. if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
  1352. os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
  1353. 0)
  1354. return 0; /* Do not show P2P listen discovery results here */
  1355. pos = buf;
  1356. end = buf + buflen;
  1357. ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
  1358. MAC2STR(bss->bssid), bss->freq, bss->level);
  1359. if (ret < 0 || ret >= end - pos)
  1360. return -1;
  1361. pos += ret;
  1362. ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  1363. if (ie)
  1364. pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
  1365. ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
  1366. if (ie2)
  1367. pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
  1368. pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
  1369. if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
  1370. ret = os_snprintf(pos, end - pos, "[WEP]");
  1371. if (ret < 0 || ret >= end - pos)
  1372. return -1;
  1373. pos += ret;
  1374. }
  1375. if (bss->caps & IEEE80211_CAP_IBSS) {
  1376. ret = os_snprintf(pos, end - pos, "[IBSS]");
  1377. if (ret < 0 || ret >= end - pos)
  1378. return -1;
  1379. pos += ret;
  1380. }
  1381. if (bss->caps & IEEE80211_CAP_ESS) {
  1382. ret = os_snprintf(pos, end - pos, "[ESS]");
  1383. if (ret < 0 || ret >= end - pos)
  1384. return -1;
  1385. pos += ret;
  1386. }
  1387. if (p2p) {
  1388. ret = os_snprintf(pos, end - pos, "[P2P]");
  1389. if (ret < 0 || ret >= end - pos)
  1390. return -1;
  1391. pos += ret;
  1392. }
  1393. #ifdef CONFIG_HS20
  1394. if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
  1395. ret = os_snprintf(pos, end - pos, "[HS20]");
  1396. if (ret < 0 || ret >= end - pos)
  1397. return -1;
  1398. pos += ret;
  1399. }
  1400. #endif /* CONFIG_HS20 */
  1401. ret = os_snprintf(pos, end - pos, "\t%s",
  1402. wpa_ssid_txt(bss->ssid, bss->ssid_len));
  1403. if (ret < 0 || ret >= end - pos)
  1404. return -1;
  1405. pos += ret;
  1406. ret = os_snprintf(pos, end - pos, "\n");
  1407. if (ret < 0 || ret >= end - pos)
  1408. return -1;
  1409. pos += ret;
  1410. return pos - buf;
  1411. }
  1412. static int wpa_supplicant_ctrl_iface_scan_results(
  1413. struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
  1414. {
  1415. char *pos, *end;
  1416. struct wpa_bss *bss;
  1417. int ret;
  1418. pos = buf;
  1419. end = buf + buflen;
  1420. ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
  1421. "flags / ssid\n");
  1422. if (ret < 0 || ret >= end - pos)
  1423. return pos - buf;
  1424. pos += ret;
  1425. dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
  1426. ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
  1427. end - pos);
  1428. if (ret < 0 || ret >= end - pos)
  1429. return pos - buf;
  1430. pos += ret;
  1431. }
  1432. return pos - buf;
  1433. }
  1434. static int wpa_supplicant_ctrl_iface_select_network(
  1435. struct wpa_supplicant *wpa_s, char *cmd)
  1436. {
  1437. int id;
  1438. struct wpa_ssid *ssid;
  1439. /* cmd: "<network id>" or "any" */
  1440. if (os_strcmp(cmd, "any") == 0) {
  1441. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
  1442. ssid = NULL;
  1443. } else {
  1444. id = atoi(cmd);
  1445. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
  1446. ssid = wpa_config_get_network(wpa_s->conf, id);
  1447. if (ssid == NULL) {
  1448. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
  1449. "network id=%d", id);
  1450. return -1;
  1451. }
  1452. if (ssid->disabled == 2) {
  1453. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
  1454. "SELECT_NETWORK with persistent P2P group");
  1455. return -1;
  1456. }
  1457. }
  1458. wpa_supplicant_select_network(wpa_s, ssid);
  1459. return 0;
  1460. }
  1461. static int wpa_supplicant_ctrl_iface_enable_network(
  1462. struct wpa_supplicant *wpa_s, char *cmd)
  1463. {
  1464. int id;
  1465. struct wpa_ssid *ssid;
  1466. /* cmd: "<network id>" or "all" */
  1467. if (os_strcmp(cmd, "all") == 0) {
  1468. wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
  1469. ssid = NULL;
  1470. } else {
  1471. id = atoi(cmd);
  1472. wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
  1473. ssid = wpa_config_get_network(wpa_s->conf, id);
  1474. if (ssid == NULL) {
  1475. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
  1476. "network id=%d", id);
  1477. return -1;
  1478. }
  1479. if (ssid->disabled == 2) {
  1480. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
  1481. "ENABLE_NETWORK with persistent P2P group");
  1482. return -1;
  1483. }
  1484. if (os_strstr(cmd, " no-connect")) {
  1485. ssid->disabled = 0;
  1486. return 0;
  1487. }
  1488. }
  1489. wpa_supplicant_enable_network(wpa_s, ssid);
  1490. return 0;
  1491. }
  1492. static int wpa_supplicant_ctrl_iface_disable_network(
  1493. struct wpa_supplicant *wpa_s, char *cmd)
  1494. {
  1495. int id;
  1496. struct wpa_ssid *ssid;
  1497. /* cmd: "<network id>" or "all" */
  1498. if (os_strcmp(cmd, "all") == 0) {
  1499. wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
  1500. ssid = NULL;
  1501. } else {
  1502. id = atoi(cmd);
  1503. wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
  1504. ssid = wpa_config_get_network(wpa_s->conf, id);
  1505. if (ssid == NULL) {
  1506. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
  1507. "network id=%d", id);
  1508. return -1;
  1509. }
  1510. if (ssid->disabled == 2) {
  1511. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
  1512. "DISABLE_NETWORK with persistent P2P "
  1513. "group");
  1514. return -1;
  1515. }
  1516. }
  1517. wpa_supplicant_disable_network(wpa_s, ssid);
  1518. return 0;
  1519. }
  1520. static int wpa_supplicant_ctrl_iface_add_network(
  1521. struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
  1522. {
  1523. struct wpa_ssid *ssid;
  1524. int ret;
  1525. wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
  1526. ssid = wpa_config_add_network(wpa_s->conf);
  1527. if (ssid == NULL)
  1528. return -1;
  1529. wpas_notify_network_added(wpa_s, ssid);
  1530. ssid->disabled = 1;
  1531. wpa_config_set_network_defaults(ssid);
  1532. ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
  1533. if (ret < 0 || (size_t) ret >= buflen)
  1534. return -1;
  1535. return ret;
  1536. }
  1537. static int wpa_supplicant_ctrl_iface_remove_network(
  1538. struct wpa_supplicant *wpa_s, char *cmd)
  1539. {
  1540. int id;
  1541. struct wpa_ssid *ssid;
  1542. /* cmd: "<network id>" or "all" */
  1543. if (os_strcmp(cmd, "all") == 0) {
  1544. wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
  1545. ssid = wpa_s->conf->ssid;
  1546. while (ssid) {
  1547. struct wpa_ssid *remove_ssid = ssid;
  1548. id = ssid->id;
  1549. ssid = ssid->next;
  1550. wpas_notify_network_removed(wpa_s, remove_ssid);
  1551. wpa_config_remove_network(wpa_s->conf, id);
  1552. }
  1553. eapol_sm_invalidate_cached_session(wpa_s->eapol);
  1554. if (wpa_s->current_ssid) {
  1555. #ifdef CONFIG_SME
  1556. wpa_s->sme.prev_bssid_set = 0;
  1557. #endif /* CONFIG_SME */
  1558. wpa_sm_set_config(wpa_s->wpa, NULL);
  1559. eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
  1560. wpa_supplicant_disassociate(wpa_s,
  1561. WLAN_REASON_DEAUTH_LEAVING);
  1562. }
  1563. return 0;
  1564. }
  1565. id = atoi(cmd);
  1566. wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
  1567. ssid = wpa_config_get_network(wpa_s->conf, id);
  1568. if (ssid)
  1569. wpas_notify_network_removed(wpa_s, ssid);
  1570. if (ssid == NULL ||
  1571. wpa_config_remove_network(wpa_s->conf, id) < 0) {
  1572. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
  1573. "id=%d", id);
  1574. return -1;
  1575. }
  1576. if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) {
  1577. #ifdef CONFIG_SME
  1578. wpa_s->sme.prev_bssid_set = 0;
  1579. #endif /* CONFIG_SME */
  1580. /*
  1581. * Invalidate the EAP session cache if the current or
  1582. * previously used network is removed.
  1583. */
  1584. eapol_sm_invalidate_cached_session(wpa_s->eapol);
  1585. }
  1586. if (ssid == wpa_s->current_ssid) {
  1587. wpa_sm_set_config(wpa_s->wpa, NULL);
  1588. eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
  1589. wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1590. }
  1591. return 0;
  1592. }
  1593. static int wpa_supplicant_ctrl_iface_set_network(
  1594. struct wpa_supplicant *wpa_s, char *cmd)
  1595. {
  1596. int id;
  1597. struct wpa_ssid *ssid;
  1598. char *name, *value;
  1599. /* cmd: "<network id> <variable name> <value>" */
  1600. name = os_strchr(cmd, ' ');
  1601. if (name == NULL)
  1602. return -1;
  1603. *name++ = '\0';
  1604. value = os_strchr(name, ' ');
  1605. if (value == NULL)
  1606. return -1;
  1607. *value++ = '\0';
  1608. id = atoi(cmd);
  1609. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
  1610. id, name);
  1611. wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
  1612. (u8 *) value, os_strlen(value));
  1613. ssid = wpa_config_get_network(wpa_s->conf, id);
  1614. if (ssid == NULL) {
  1615. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
  1616. "id=%d", id);
  1617. return -1;
  1618. }
  1619. if (wpa_config_set(ssid, name, value, 0) < 0) {
  1620. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
  1621. "variable '%s'", name);
  1622. return -1;
  1623. }
  1624. wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
  1625. if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) {
  1626. /*
  1627. * Invalidate the EAP session cache if anything in the current
  1628. * or previously used configuration changes.
  1629. */
  1630. eapol_sm_invalidate_cached_session(wpa_s->eapol);
  1631. }
  1632. if ((os_strcmp(name, "psk") == 0 &&
  1633. value[0] == '"' && ssid->ssid_len) ||
  1634. (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
  1635. wpa_config_update_psk(ssid);
  1636. else if (os_strcmp(name, "priority") == 0)
  1637. wpa_config_update_prio_list(wpa_s->conf);
  1638. return 0;
  1639. }
  1640. static int wpa_supplicant_ctrl_iface_get_network(
  1641. struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
  1642. {
  1643. int id;
  1644. size_t res;
  1645. struct wpa_ssid *ssid;
  1646. char *name, *value;
  1647. /* cmd: "<network id> <variable name>" */
  1648. name = os_strchr(cmd, ' ');
  1649. if (name == NULL || buflen == 0)
  1650. return -1;
  1651. *name++ = '\0';
  1652. id = atoi(cmd);
  1653. wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
  1654. id, name);
  1655. ssid = wpa_config_get_network(wpa_s->conf, id);
  1656. if (ssid == NULL) {
  1657. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
  1658. "id=%d", id);
  1659. return -1;
  1660. }
  1661. value = wpa_config_get_no_key(ssid, name);
  1662. if (value == NULL) {
  1663. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
  1664. "variable '%s'", name);
  1665. return -1;
  1666. }
  1667. res = os_strlcpy(buf, value, buflen);
  1668. if (res >= buflen) {
  1669. os_free(value);
  1670. return -1;
  1671. }
  1672. os_free(value);
  1673. return res;
  1674. }
  1675. static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
  1676. char *buf, size_t buflen)
  1677. {
  1678. char *pos, *end;
  1679. struct wpa_cred *cred;
  1680. int ret;
  1681. pos = buf;
  1682. end = buf + buflen;
  1683. ret = os_snprintf(pos, end - pos,
  1684. "cred id / realm / username / domain / imsi\n");
  1685. if (ret < 0 || ret >= end - pos)
  1686. return pos - buf;
  1687. pos += ret;
  1688. cred = wpa_s->conf->cred;
  1689. while (cred) {
  1690. ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
  1691. cred->id, cred->realm ? cred->realm : "",
  1692. cred->username ? cred->username : "",
  1693. cred->domain ? cred->domain : "",
  1694. cred->imsi ? cred->imsi : "");
  1695. if (ret < 0 || ret >= end - pos)
  1696. return pos - buf;
  1697. pos += ret;
  1698. cred = cred->next;
  1699. }
  1700. return pos - buf;
  1701. }
  1702. static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
  1703. char *buf, size_t buflen)
  1704. {
  1705. struct wpa_cred *cred;
  1706. int ret;
  1707. wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
  1708. cred = wpa_config_add_cred(wpa_s->conf);
  1709. if (cred == NULL)
  1710. return -1;
  1711. ret = os_snprintf(buf, buflen, "%d\n", cred->id);
  1712. if (ret < 0 || (size_t) ret >= buflen)
  1713. return -1;
  1714. return ret;
  1715. }
  1716. static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
  1717. char *cmd)
  1718. {
  1719. int id;
  1720. struct wpa_cred *cred;
  1721. /* cmd: "<cred id>" or "all" */
  1722. if (os_strcmp(cmd, "all") == 0) {
  1723. wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
  1724. cred = wpa_s->conf->cred;
  1725. while (cred) {
  1726. id = cred->id;
  1727. cred = cred->next;
  1728. wpa_config_remove_cred(wpa_s->conf, id);
  1729. }
  1730. return 0;
  1731. }
  1732. id = atoi(cmd);
  1733. wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
  1734. cred = wpa_config_get_cred(wpa_s->conf, id);
  1735. if (cred == NULL ||
  1736. wpa_config_remove_cred(wpa_s->conf, id) < 0) {
  1737. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
  1738. id);
  1739. return -1;
  1740. }
  1741. return 0;
  1742. }
  1743. static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
  1744. char *cmd)
  1745. {
  1746. int id;
  1747. struct wpa_cred *cred;
  1748. char *name, *value;
  1749. /* cmd: "<cred id> <variable name> <value>" */
  1750. name = os_strchr(cmd, ' ');
  1751. if (name == NULL)
  1752. return -1;
  1753. *name++ = '\0';
  1754. value = os_strchr(name, ' ');
  1755. if (value == NULL)
  1756. return -1;
  1757. *value++ = '\0';
  1758. id = atoi(cmd);
  1759. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
  1760. id, name);
  1761. wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
  1762. (u8 *) value, os_strlen(value));
  1763. cred = wpa_config_get_cred(wpa_s->conf, id);
  1764. if (cred == NULL) {
  1765. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
  1766. id);
  1767. return -1;
  1768. }
  1769. if (wpa_config_set_cred(cred, name, value, 0) < 0) {
  1770. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
  1771. "variable '%s'", name);
  1772. return -1;
  1773. }
  1774. return 0;
  1775. }
  1776. #ifndef CONFIG_NO_CONFIG_WRITE
  1777. static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
  1778. {
  1779. int ret;
  1780. if (!wpa_s->conf->update_config) {
  1781. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
  1782. "to update configuration (update_config=0)");
  1783. return -1;
  1784. }
  1785. ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
  1786. if (ret) {
  1787. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
  1788. "update configuration");
  1789. } else {
  1790. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
  1791. " updated");
  1792. }
  1793. return ret;
  1794. }
  1795. #endif /* CONFIG_NO_CONFIG_WRITE */
  1796. static int ctrl_iface_get_capability_pairwise(int res, char *strict,
  1797. struct wpa_driver_capa *capa,
  1798. char *buf, size_t buflen)
  1799. {
  1800. int ret, first = 1;
  1801. char *pos, *end;
  1802. size_t len;
  1803. pos = buf;
  1804. end = pos + buflen;
  1805. if (res < 0) {
  1806. if (strict)
  1807. return 0;
  1808. len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
  1809. if (len >= buflen)
  1810. return -1;
  1811. return len;
  1812. }
  1813. if (capa->enc & WPA_DRIVER_CAPA_ENC_CCMP) {
  1814. ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " ");
  1815. if (ret < 0 || ret >= end - pos)
  1816. return pos - buf;
  1817. pos += ret;
  1818. first = 0;
  1819. }
  1820. if (capa->enc & WPA_DRIVER_CAPA_ENC_TKIP) {
  1821. ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " ");
  1822. if (ret < 0 || ret >= end - pos)
  1823. return pos - buf;
  1824. pos += ret;
  1825. first = 0;
  1826. }
  1827. if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
  1828. ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : " ");
  1829. if (ret < 0 || ret >= end - pos)
  1830. return pos - buf;
  1831. pos += ret;
  1832. first = 0;
  1833. }
  1834. return pos - buf;
  1835. }
  1836. static int ctrl_iface_get_capability_group(int res, char *strict,
  1837. struct wpa_driver_capa *capa,
  1838. char *buf, size_t buflen)
  1839. {
  1840. int ret, first = 1;
  1841. char *pos, *end;
  1842. size_t len;
  1843. pos = buf;
  1844. end = pos + buflen;
  1845. if (res < 0) {
  1846. if (strict)
  1847. return 0;
  1848. len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
  1849. if (len >= buflen)
  1850. return -1;
  1851. return len;
  1852. }
  1853. if (capa->enc & WPA_DRIVER_CAPA_ENC_CCMP) {
  1854. ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " ");
  1855. if (ret < 0 || ret >= end - pos)
  1856. return pos - buf;
  1857. pos += ret;
  1858. first = 0;
  1859. }
  1860. if (capa->enc & WPA_DRIVER_CAPA_ENC_TKIP) {
  1861. ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " ");
  1862. if (ret < 0 || ret >= end - pos)
  1863. return pos - buf;
  1864. pos += ret;
  1865. first = 0;
  1866. }
  1867. if (capa->enc & WPA_DRIVER_CAPA_ENC_WEP104) {
  1868. ret = os_snprintf(pos, end - pos, "%sWEP104",
  1869. first ? "" : " ");
  1870. if (ret < 0 || ret >= end - pos)
  1871. return pos - buf;
  1872. pos += ret;
  1873. first = 0;
  1874. }
  1875. if (capa->enc & WPA_DRIVER_CAPA_ENC_WEP40) {
  1876. ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : " ");
  1877. if (ret < 0 || ret >= end - pos)
  1878. return pos - buf;
  1879. pos += ret;
  1880. first = 0;
  1881. }
  1882. return pos - buf;
  1883. }
  1884. static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
  1885. struct wpa_driver_capa *capa,
  1886. char *buf, size_t buflen)
  1887. {
  1888. int ret;
  1889. char *pos, *end;
  1890. size_t len;
  1891. pos = buf;
  1892. end = pos + buflen;
  1893. if (res < 0) {
  1894. if (strict)
  1895. return 0;
  1896. len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
  1897. "NONE", buflen);
  1898. if (len >= buflen)
  1899. return -1;
  1900. return len;
  1901. }
  1902. ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
  1903. if (ret < 0 || ret >= end - pos)
  1904. return pos - buf;
  1905. pos += ret;
  1906. if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
  1907. WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
  1908. ret = os_snprintf(pos, end - pos, " WPA-EAP");
  1909. if (ret < 0 || ret >= end - pos)
  1910. return pos - buf;
  1911. pos += ret;
  1912. }
  1913. if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
  1914. WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
  1915. ret = os_snprintf(pos, end - pos, " WPA-PSK");
  1916. if (ret < 0 || ret >= end - pos)
  1917. return pos - buf;
  1918. pos += ret;
  1919. }
  1920. if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
  1921. ret = os_snprintf(pos, end - pos, " WPA-NONE");
  1922. if (ret < 0 || ret >= end - pos)
  1923. return pos - buf;
  1924. pos += ret;
  1925. }
  1926. return pos - buf;
  1927. }
  1928. static int ctrl_iface_get_capability_proto(int res, char *strict,
  1929. struct wpa_driver_capa *capa,
  1930. char *buf, size_t buflen)
  1931. {
  1932. int ret, first = 1;
  1933. char *pos, *end;
  1934. size_t len;
  1935. pos = buf;
  1936. end = pos + buflen;
  1937. if (res < 0) {
  1938. if (strict)
  1939. return 0;
  1940. len = os_strlcpy(buf, "RSN WPA", buflen);
  1941. if (len >= buflen)
  1942. return -1;
  1943. return len;
  1944. }
  1945. if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
  1946. WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
  1947. ret = os_snprintf(pos, end - pos, "%sRSN", first ? "" : " ");
  1948. if (ret < 0 || ret >= end - pos)
  1949. return pos - buf;
  1950. pos += ret;
  1951. first = 0;
  1952. }
  1953. if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
  1954. WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
  1955. ret = os_snprintf(pos, end - pos, "%sWPA", first ? "" : " ");
  1956. if (ret < 0 || ret >= end - pos)
  1957. return pos - buf;
  1958. pos += ret;
  1959. first = 0;
  1960. }
  1961. return pos - buf;
  1962. }
  1963. static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
  1964. struct wpa_driver_capa *capa,
  1965. char *buf, size_t buflen)
  1966. {
  1967. int ret, first = 1;
  1968. char *pos, *end;
  1969. size_t len;
  1970. pos = buf;
  1971. end = pos + buflen;
  1972. if (res < 0) {
  1973. if (strict)
  1974. return 0;
  1975. len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
  1976. if (len >= buflen)
  1977. return -1;
  1978. return len;
  1979. }
  1980. if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
  1981. ret = os_snprintf(pos, end - pos, "%sOPEN", first ? "" : " ");
  1982. if (ret < 0 || ret >= end - pos)
  1983. return pos - buf;
  1984. pos += ret;
  1985. first = 0;
  1986. }
  1987. if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
  1988. ret = os_snprintf(pos, end - pos, "%sSHARED",
  1989. first ? "" : " ");
  1990. if (ret < 0 || ret >= end - pos)
  1991. return pos - buf;
  1992. pos += ret;
  1993. first = 0;
  1994. }
  1995. if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
  1996. ret = os_snprintf(pos, end - pos, "%sLEAP", first ? "" : " ");
  1997. if (ret < 0 || ret >= end - pos)
  1998. return pos - buf;
  1999. pos += ret;
  2000. first = 0;
  2001. }
  2002. return pos - buf;
  2003. }
  2004. static int wpa_supplicant_ctrl_iface_get_capability(
  2005. struct wpa_supplicant *wpa_s, const char *_field, char *buf,
  2006. size_t buflen)
  2007. {
  2008. struct wpa_driver_capa capa;
  2009. int res;
  2010. char *strict;
  2011. char field[30];
  2012. size_t len;
  2013. /* Determine whether or not strict checking was requested */
  2014. len = os_strlcpy(field, _field, sizeof(field));
  2015. if (len >= sizeof(field))
  2016. return -1;
  2017. strict = os_strchr(field, ' ');
  2018. if (strict != NULL) {
  2019. *strict++ = '\0';
  2020. if (os_strcmp(strict, "strict") != 0)
  2021. return -1;
  2022. }
  2023. wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
  2024. field, strict ? strict : "");
  2025. if (os_strcmp(field, "eap") == 0) {
  2026. return eap_get_names(buf, buflen);
  2027. }
  2028. res = wpa_drv_get_capa(wpa_s, &capa);
  2029. if (os_strcmp(field, "pairwise") == 0)
  2030. return ctrl_iface_get_capability_pairwise(res, strict, &capa,
  2031. buf, buflen);
  2032. if (os_strcmp(field, "group") == 0)
  2033. return ctrl_iface_get_capability_group(res, strict, &capa,
  2034. buf, buflen);
  2035. if (os_strcmp(field, "key_mgmt") == 0)
  2036. return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
  2037. buf, buflen);
  2038. if (os_strcmp(field, "proto") == 0)
  2039. return ctrl_iface_get_capability_proto(res, strict, &capa,
  2040. buf, buflen);
  2041. if (os_strcmp(field, "auth_alg") == 0)
  2042. return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
  2043. buf, buflen);
  2044. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
  2045. field);
  2046. return -1;
  2047. }
  2048. #ifdef CONFIG_INTERWORKING
  2049. static char * anqp_add_hex(char *pos, char *end, const char *title,
  2050. struct wpabuf *data)
  2051. {
  2052. char *start = pos;
  2053. size_t i;
  2054. int ret;
  2055. const u8 *d;
  2056. if (data == NULL)
  2057. return start;
  2058. ret = os_snprintf(pos, end - pos, "%s=", title);
  2059. if (ret < 0 || ret >= end - pos)
  2060. return start;
  2061. pos += ret;
  2062. d = wpabuf_head_u8(data);
  2063. for (i = 0; i < wpabuf_len(data); i++) {
  2064. ret = os_snprintf(pos, end - pos, "%02x", *d++);
  2065. if (ret < 0 || ret >= end - pos)
  2066. return start;
  2067. pos += ret;
  2068. }
  2069. ret = os_snprintf(pos, end - pos, "\n");
  2070. if (ret < 0 || ret >= end - pos)
  2071. return start;
  2072. pos += ret;
  2073. return pos;
  2074. }
  2075. #endif /* CONFIG_INTERWORKING */
  2076. static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
  2077. unsigned long mask, char *buf, size_t buflen)
  2078. {
  2079. size_t i;
  2080. int ret;
  2081. char *pos, *end;
  2082. const u8 *ie, *ie2;
  2083. pos = buf;
  2084. end = buf + buflen;
  2085. if (mask & WPA_BSS_MASK_ID) {
  2086. ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
  2087. if (ret < 0 || ret >= end - pos)
  2088. return 0;
  2089. pos += ret;
  2090. }
  2091. if (mask & WPA_BSS_MASK_BSSID) {
  2092. ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
  2093. MAC2STR(bss->bssid));
  2094. if (ret < 0 || ret >= end - pos)
  2095. return 0;
  2096. pos += ret;
  2097. }
  2098. if (mask & WPA_BSS_MASK_FREQ) {
  2099. ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
  2100. if (ret < 0 || ret >= end - pos)
  2101. return 0;
  2102. pos += ret;
  2103. }
  2104. if (mask & WPA_BSS_MASK_BEACON_INT) {
  2105. ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
  2106. bss->beacon_int);
  2107. if (ret < 0 || ret >= end - pos)
  2108. return 0;
  2109. pos += ret;
  2110. }
  2111. if (mask & WPA_BSS_MASK_CAPABILITIES) {
  2112. ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
  2113. bss->caps);
  2114. if (ret < 0 || ret >= end - pos)
  2115. return 0;
  2116. pos += ret;
  2117. }
  2118. if (mask & WPA_BSS_MASK_QUAL) {
  2119. ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
  2120. if (ret < 0 || ret >= end - pos)
  2121. return 0;
  2122. pos += ret;
  2123. }
  2124. if (mask & WPA_BSS_MASK_NOISE) {
  2125. ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
  2126. if (ret < 0 || ret >= end - pos)
  2127. return 0;
  2128. pos += ret;
  2129. }
  2130. if (mask & WPA_BSS_MASK_LEVEL) {
  2131. ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
  2132. if (ret < 0 || ret >= end - pos)
  2133. return 0;
  2134. pos += ret;
  2135. }
  2136. if (mask & WPA_BSS_MASK_TSF) {
  2137. ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
  2138. (unsigned long long) bss->tsf);
  2139. if (ret < 0 || ret >= end - pos)
  2140. return 0;
  2141. pos += ret;
  2142. }
  2143. if (mask & WPA_BSS_MASK_AGE) {
  2144. struct os_time now;
  2145. os_get_time(&now);
  2146. ret = os_snprintf(pos, end - pos, "age=%d\n",
  2147. (int) (now.sec - bss->last_update.sec));
  2148. if (ret < 0 || ret >= end - pos)
  2149. return 0;
  2150. pos += ret;
  2151. }
  2152. if (mask & WPA_BSS_MASK_IE) {
  2153. ret = os_snprintf(pos, end - pos, "ie=");
  2154. if (ret < 0 || ret >= end - pos)
  2155. return 0;
  2156. pos += ret;
  2157. ie = (const u8 *) (bss + 1);
  2158. for (i = 0; i < bss->ie_len; i++) {
  2159. ret = os_snprintf(pos, end - pos, "%02x", *ie++);
  2160. if (ret < 0 || ret >= end - pos)
  2161. return 0;
  2162. pos += ret;
  2163. }
  2164. ret = os_snprintf(pos, end - pos, "\n");
  2165. if (ret < 0 || ret >= end - pos)
  2166. return 0;
  2167. pos += ret;
  2168. }
  2169. if (mask & WPA_BSS_MASK_FLAGS) {
  2170. ret = os_snprintf(pos, end - pos, "flags=");
  2171. if (ret < 0 || ret >= end - pos)
  2172. return 0;
  2173. pos += ret;
  2174. ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  2175. if (ie)
  2176. pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
  2177. 2 + ie[1]);
  2178. ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
  2179. if (ie2)
  2180. pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2,
  2181. 2 + ie2[1]);
  2182. pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
  2183. if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
  2184. ret = os_snprintf(pos, end - pos, "[WEP]");
  2185. if (ret < 0 || ret >= end - pos)
  2186. return 0;
  2187. pos += ret;
  2188. }
  2189. if (bss->caps & IEEE80211_CAP_IBSS) {
  2190. ret = os_snprintf(pos, end - pos, "[IBSS]");
  2191. if (ret < 0 || ret >= end - pos)
  2192. return 0;
  2193. pos += ret;
  2194. }
  2195. if (bss->caps & IEEE80211_CAP_ESS) {
  2196. ret = os_snprintf(pos, end - pos, "[ESS]");
  2197. if (ret < 0 || ret >= end - pos)
  2198. return 0;
  2199. pos += ret;
  2200. }
  2201. if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE)) {
  2202. ret = os_snprintf(pos, end - pos, "[P2P]");
  2203. if (ret < 0 || ret >= end - pos)
  2204. return 0;
  2205. pos += ret;
  2206. }
  2207. #ifdef CONFIG_HS20
  2208. if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
  2209. ret = os_snprintf(pos, end - pos, "[HS20]");
  2210. if (ret < 0 || ret >= end - pos)
  2211. return -1;
  2212. pos += ret;
  2213. }
  2214. #endif /* CONFIG_HS20 */
  2215. ret = os_snprintf(pos, end - pos, "\n");
  2216. if (ret < 0 || ret >= end - pos)
  2217. return 0;
  2218. pos += ret;
  2219. }
  2220. if (mask & WPA_BSS_MASK_SSID) {
  2221. ret = os_snprintf(pos, end - pos, "ssid=%s\n",
  2222. wpa_ssid_txt(bss->ssid, bss->ssid_len));
  2223. if (ret < 0 || ret >= end - pos)
  2224. return 0;
  2225. pos += ret;
  2226. }
  2227. #ifdef CONFIG_WPS
  2228. if (mask & WPA_BSS_MASK_WPS_SCAN) {
  2229. ie = (const u8 *) (bss + 1);
  2230. ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
  2231. if (ret < 0 || ret >= end - pos)
  2232. return 0;
  2233. pos += ret;
  2234. }
  2235. #endif /* CONFIG_WPS */
  2236. #ifdef CONFIG_P2P
  2237. if (mask & WPA_BSS_MASK_P2P_SCAN) {
  2238. ie = (const u8 *) (bss + 1);
  2239. ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
  2240. if (ret < 0 || ret >= end - pos)
  2241. return 0;
  2242. pos += ret;
  2243. }
  2244. #endif /* CONFIG_P2P */
  2245. #ifdef CONFIG_INTERWORKING
  2246. if (mask & WPA_BSS_MASK_INTERNETW) {
  2247. pos = anqp_add_hex(pos, end, "anqp_venue_name",
  2248. bss->anqp_venue_name);
  2249. pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
  2250. bss->anqp_network_auth_type);
  2251. pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
  2252. bss->anqp_roaming_consortium);
  2253. pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
  2254. bss->anqp_ip_addr_type_availability);
  2255. pos = anqp_add_hex(pos, end, "anqp_nai_realm",
  2256. bss->anqp_nai_realm);
  2257. pos = anqp_add_hex(pos, end, "anqp_3gpp", bss->anqp_3gpp);
  2258. pos = anqp_add_hex(pos, end, "anqp_domain_name",
  2259. bss->anqp_domain_name);
  2260. #ifdef CONFIG_HS20
  2261. pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
  2262. bss->hs20_operator_friendly_name);
  2263. pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
  2264. bss->hs20_wan_metrics);
  2265. pos = anqp_add_hex(pos, end, "hs20_connection_capability",
  2266. bss->hs20_connection_capability);
  2267. #endif /* CONFIG_HS20 */
  2268. }
  2269. #endif /* CONFIG_INTERWORKING */
  2270. return pos - buf;
  2271. }
  2272. static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
  2273. const char *cmd, char *buf,
  2274. size_t buflen)
  2275. {
  2276. u8 bssid[ETH_ALEN];
  2277. size_t i;
  2278. struct wpa_bss *bss;
  2279. struct wpa_bss *bsslast = NULL;
  2280. struct dl_list *next;
  2281. int ret = 0;
  2282. int len;
  2283. char *ctmp;
  2284. unsigned long mask = WPA_BSS_MASK_ALL;
  2285. if (os_strncmp(cmd, "RANGE=", 6) == 0) {
  2286. if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
  2287. bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
  2288. list_id);
  2289. bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
  2290. list_id);
  2291. } else { /* N1-N2 */
  2292. unsigned int id1, id2;
  2293. if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
  2294. wpa_printf(MSG_INFO, "Wrong BSS range "
  2295. "format");
  2296. return 0;
  2297. }
  2298. id1 = atoi(cmd + 6);
  2299. bss = wpa_bss_get_id(wpa_s, id1);
  2300. id2 = atoi(ctmp + 1);
  2301. if (id2 == 0)
  2302. bsslast = dl_list_last(&wpa_s->bss_id,
  2303. struct wpa_bss,
  2304. list_id);
  2305. else {
  2306. bsslast = wpa_bss_get_id(wpa_s, id2);
  2307. if (bsslast == NULL && bss && id2 > id1) {
  2308. struct wpa_bss *tmp = bss;
  2309. for (;;) {
  2310. next = tmp->list_id.next;
  2311. if (next == &wpa_s->bss_id)
  2312. break;
  2313. tmp = dl_list_entry(
  2314. next, struct wpa_bss,
  2315. list_id);
  2316. if (tmp->id > id2)
  2317. break;
  2318. bsslast = tmp;
  2319. }
  2320. }
  2321. }
  2322. }
  2323. } else if (os_strcmp(cmd, "FIRST") == 0)
  2324. bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
  2325. else if (os_strncmp(cmd, "ID-", 3) == 0) {
  2326. i = atoi(cmd + 3);
  2327. bss = wpa_bss_get_id(wpa_s, i);
  2328. } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
  2329. i = atoi(cmd + 5);
  2330. bss = wpa_bss_get_id(wpa_s, i);
  2331. if (bss) {
  2332. next = bss->list_id.next;
  2333. if (next == &wpa_s->bss_id)
  2334. bss = NULL;
  2335. else
  2336. bss = dl_list_entry(next, struct wpa_bss,
  2337. list_id);
  2338. }
  2339. #ifdef CONFIG_P2P
  2340. } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
  2341. if (hwaddr_aton(cmd + 13, bssid) == 0)
  2342. bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
  2343. else
  2344. bss = NULL;
  2345. #endif /* CONFIG_P2P */
  2346. } else if (hwaddr_aton(cmd, bssid) == 0)
  2347. bss = wpa_bss_get_bssid(wpa_s, bssid);
  2348. else {
  2349. struct wpa_bss *tmp;
  2350. i = atoi(cmd);
  2351. bss = NULL;
  2352. dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
  2353. {
  2354. if (i-- == 0) {
  2355. bss = tmp;
  2356. break;
  2357. }
  2358. }
  2359. }
  2360. if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
  2361. mask = strtoul(ctmp + 5, NULL, 0x10);
  2362. if (mask == 0)
  2363. mask = WPA_BSS_MASK_ALL;
  2364. }
  2365. if (bss == NULL)
  2366. return 0;
  2367. if (bsslast == NULL)
  2368. bsslast = bss;
  2369. do {
  2370. len = print_bss_info(wpa_s, bss, mask, buf, buflen);
  2371. ret += len;
  2372. buf += len;
  2373. buflen -= len;
  2374. if (bss == bsslast)
  2375. break;
  2376. next = bss->list_id.next;
  2377. if (next == &wpa_s->bss_id)
  2378. break;
  2379. bss = dl_list_entry(next, struct wpa_bss, list_id);
  2380. } while (bss && len);
  2381. return ret;
  2382. }
  2383. static int wpa_supplicant_ctrl_iface_ap_scan(
  2384. struct wpa_supplicant *wpa_s, char *cmd)
  2385. {
  2386. int ap_scan = atoi(cmd);
  2387. return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
  2388. }
  2389. static int wpa_supplicant_ctrl_iface_scan_interval(
  2390. struct wpa_supplicant *wpa_s, char *cmd)
  2391. {
  2392. int scan_int = atoi(cmd);
  2393. return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
  2394. }
  2395. static int wpa_supplicant_ctrl_iface_bss_expire_age(
  2396. struct wpa_supplicant *wpa_s, char *cmd)
  2397. {
  2398. int expire_age = atoi(cmd);
  2399. return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
  2400. }
  2401. static int wpa_supplicant_ctrl_iface_bss_expire_count(
  2402. struct wpa_supplicant *wpa_s, char *cmd)
  2403. {
  2404. int expire_count = atoi(cmd);
  2405. return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
  2406. }
  2407. static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
  2408. {
  2409. wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
  2410. /* MLME-DELETEKEYS.request */
  2411. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
  2412. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
  2413. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
  2414. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
  2415. #ifdef CONFIG_IEEE80211W
  2416. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
  2417. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
  2418. #endif /* CONFIG_IEEE80211W */
  2419. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
  2420. 0);
  2421. /* MLME-SETPROTECTION.request(None) */
  2422. wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
  2423. MLME_SETPROTECTION_PROTECT_TYPE_NONE,
  2424. MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
  2425. wpa_sm_drop_sa(wpa_s->wpa);
  2426. }
  2427. static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
  2428. char *addr)
  2429. {
  2430. #ifdef CONFIG_NO_SCAN_PROCESSING
  2431. return -1;
  2432. #else /* CONFIG_NO_SCAN_PROCESSING */
  2433. u8 bssid[ETH_ALEN];
  2434. struct wpa_bss *bss;
  2435. struct wpa_ssid *ssid = wpa_s->current_ssid;
  2436. if (hwaddr_aton(addr, bssid)) {
  2437. wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
  2438. "address '%s'", addr);
  2439. return -1;
  2440. }
  2441. wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
  2442. bss = wpa_bss_get_bssid(wpa_s, bssid);
  2443. if (!bss) {
  2444. wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
  2445. "from BSS table");
  2446. return -1;
  2447. }
  2448. /*
  2449. * TODO: Find best network configuration block from configuration to
  2450. * allow roaming to other networks
  2451. */
  2452. if (!ssid) {
  2453. wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
  2454. "configuration known for the target AP");
  2455. return -1;
  2456. }
  2457. wpa_s->reassociate = 1;
  2458. wpa_supplicant_connect(wpa_s, bss, ssid);
  2459. return 0;
  2460. #endif /* CONFIG_NO_SCAN_PROCESSING */
  2461. }
  2462. #ifdef CONFIG_P2P
  2463. static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
  2464. {
  2465. unsigned int timeout = atoi(cmd);
  2466. enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
  2467. u8 dev_id[ETH_ALEN], *_dev_id = NULL;
  2468. char *pos;
  2469. if (os_strstr(cmd, "type=social"))
  2470. type = P2P_FIND_ONLY_SOCIAL;
  2471. else if (os_strstr(cmd, "type=progressive"))
  2472. type = P2P_FIND_PROGRESSIVE;
  2473. pos = os_strstr(cmd, "dev_id=");
  2474. if (pos) {
  2475. pos += 7;
  2476. if (hwaddr_aton(pos, dev_id))
  2477. return -1;
  2478. _dev_id = dev_id;
  2479. }
  2480. return wpas_p2p_find(wpa_s, timeout, type, 0, NULL, _dev_id);
  2481. }
  2482. static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
  2483. char *buf, size_t buflen)
  2484. {
  2485. u8 addr[ETH_ALEN];
  2486. char *pos, *pos2;
  2487. char *pin = NULL;
  2488. enum p2p_wps_method wps_method;
  2489. int new_pin;
  2490. int ret;
  2491. int persistent_group, persistent_id = -1;
  2492. int join;
  2493. int auth;
  2494. int automatic;
  2495. int go_intent = -1;
  2496. int freq = 0;
  2497. int pd;
  2498. /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
  2499. * [persistent|persistent=<network id>]
  2500. * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc] */
  2501. if (hwaddr_aton(cmd, addr))
  2502. return -1;
  2503. pos = cmd + 17;
  2504. if (*pos != ' ')
  2505. return -1;
  2506. pos++;
  2507. persistent_group = os_strstr(pos, " persistent") != NULL;
  2508. pos2 = os_strstr(pos, " persistent=");
  2509. if (pos2) {
  2510. struct wpa_ssid *ssid;
  2511. persistent_id = atoi(pos2 + 12);
  2512. ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
  2513. if (ssid == NULL || ssid->disabled != 2 ||
  2514. ssid->mode != WPAS_MODE_P2P_GO) {
  2515. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
  2516. "SSID id=%d for persistent P2P group (GO)",
  2517. persistent_id);
  2518. return -1;
  2519. }
  2520. }
  2521. join = os_strstr(pos, " join") != NULL;
  2522. auth = os_strstr(pos, " auth") != NULL;
  2523. automatic = os_strstr(pos, " auto") != NULL;
  2524. pd = os_strstr(pos, " provdisc") != NULL;
  2525. pos2 = os_strstr(pos, " go_intent=");
  2526. if (pos2) {
  2527. pos2 += 11;
  2528. go_intent = atoi(pos2);
  2529. if (go_intent < 0 || go_intent > 15)
  2530. return -1;
  2531. }
  2532. pos2 = os_strstr(pos, " freq=");
  2533. if (pos2) {
  2534. pos2 += 6;
  2535. freq = atoi(pos2);
  2536. if (freq <= 0)
  2537. return -1;
  2538. }
  2539. if (os_strncmp(pos, "pin", 3) == 0) {
  2540. /* Request random PIN (to be displayed) and enable the PIN */
  2541. wps_method = WPS_PIN_DISPLAY;
  2542. } else if (os_strncmp(pos, "pbc", 3) == 0) {
  2543. wps_method = WPS_PBC;
  2544. } else {
  2545. pin = pos;
  2546. pos = os_strchr(pin, ' ');
  2547. wps_method = WPS_PIN_KEYPAD;
  2548. if (pos) {
  2549. *pos++ = '\0';
  2550. if (os_strncmp(pos, "display", 7) == 0)
  2551. wps_method = WPS_PIN_DISPLAY;
  2552. }
  2553. if (!wps_pin_str_valid(pin)) {
  2554. os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
  2555. return 17;
  2556. }
  2557. }
  2558. new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
  2559. persistent_group, automatic, join,
  2560. auth, go_intent, freq, persistent_id, pd);
  2561. if (new_pin == -2) {
  2562. os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
  2563. return 25;
  2564. }
  2565. if (new_pin == -3) {
  2566. os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
  2567. return 25;
  2568. }
  2569. if (new_pin < 0)
  2570. return -1;
  2571. if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
  2572. ret = os_snprintf(buf, buflen, "%08d", new_pin);
  2573. if (ret < 0 || (size_t) ret >= buflen)
  2574. return -1;
  2575. return ret;
  2576. }
  2577. os_memcpy(buf, "OK\n", 3);
  2578. return 3;
  2579. }
  2580. static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
  2581. {
  2582. unsigned int timeout = atoi(cmd);
  2583. return wpas_p2p_listen(wpa_s, timeout);
  2584. }
  2585. static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
  2586. {
  2587. u8 addr[ETH_ALEN];
  2588. char *pos;
  2589. enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
  2590. /* <addr> <config method> [join|auto] */
  2591. if (hwaddr_aton(cmd, addr))
  2592. return -1;
  2593. pos = cmd + 17;
  2594. if (*pos != ' ')
  2595. return -1;
  2596. pos++;
  2597. if (os_strstr(pos, " join") != NULL)
  2598. use = WPAS_P2P_PD_FOR_JOIN;
  2599. else if (os_strstr(pos, " auto") != NULL)
  2600. use = WPAS_P2P_PD_AUTO;
  2601. return wpas_p2p_prov_disc(wpa_s, addr, pos, use);
  2602. }
  2603. static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
  2604. size_t buflen)
  2605. {
  2606. struct wpa_ssid *ssid = wpa_s->current_ssid;
  2607. if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
  2608. ssid->passphrase == NULL)
  2609. return -1;
  2610. os_strlcpy(buf, ssid->passphrase, buflen);
  2611. return os_strlen(buf);
  2612. }
  2613. static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
  2614. char *buf, size_t buflen)
  2615. {
  2616. u64 ref;
  2617. int res;
  2618. u8 dst_buf[ETH_ALEN], *dst;
  2619. struct wpabuf *tlvs;
  2620. char *pos;
  2621. size_t len;
  2622. if (hwaddr_aton(cmd, dst_buf))
  2623. return -1;
  2624. dst = dst_buf;
  2625. if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
  2626. dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
  2627. dst = NULL;
  2628. pos = cmd + 17;
  2629. if (*pos != ' ')
  2630. return -1;
  2631. pos++;
  2632. if (os_strncmp(pos, "upnp ", 5) == 0) {
  2633. u8 version;
  2634. pos += 5;
  2635. if (hexstr2bin(pos, &version, 1) < 0)
  2636. return -1;
  2637. pos += 2;
  2638. if (*pos != ' ')
  2639. return -1;
  2640. pos++;
  2641. ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
  2642. } else {
  2643. len = os_strlen(pos);
  2644. if (len & 1)
  2645. return -1;
  2646. len /= 2;
  2647. tlvs = wpabuf_alloc(len);
  2648. if (tlvs == NULL)
  2649. return -1;
  2650. if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
  2651. wpabuf_free(tlvs);
  2652. return -1;
  2653. }
  2654. ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
  2655. wpabuf_free(tlvs);
  2656. }
  2657. if (ref == 0)
  2658. return -1;
  2659. res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
  2660. if (res < 0 || (unsigned) res >= buflen)
  2661. return -1;
  2662. return res;
  2663. }
  2664. static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
  2665. char *cmd)
  2666. {
  2667. long long unsigned val;
  2668. u64 req;
  2669. if (sscanf(cmd, "%llx", &val) != 1)
  2670. return -1;
  2671. req = val;
  2672. return wpas_p2p_sd_cancel_request(wpa_s, req);
  2673. }
  2674. static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
  2675. {
  2676. int freq;
  2677. u8 dst[ETH_ALEN];
  2678. u8 dialog_token;
  2679. struct wpabuf *resp_tlvs;
  2680. char *pos, *pos2;
  2681. size_t len;
  2682. pos = os_strchr(cmd, ' ');
  2683. if (pos == NULL)
  2684. return -1;
  2685. *pos++ = '\0';
  2686. freq = atoi(cmd);
  2687. if (freq == 0)
  2688. return -1;
  2689. if (hwaddr_aton(pos, dst))
  2690. return -1;
  2691. pos += 17;
  2692. if (*pos != ' ')
  2693. return -1;
  2694. pos++;
  2695. pos2 = os_strchr(pos, ' ');
  2696. if (pos2 == NULL)
  2697. return -1;
  2698. *pos2++ = '\0';
  2699. dialog_token = atoi(pos);
  2700. len = os_strlen(pos2);
  2701. if (len & 1)
  2702. return -1;
  2703. len /= 2;
  2704. resp_tlvs = wpabuf_alloc(len);
  2705. if (resp_tlvs == NULL)
  2706. return -1;
  2707. if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
  2708. wpabuf_free(resp_tlvs);
  2709. return -1;
  2710. }
  2711. wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
  2712. wpabuf_free(resp_tlvs);
  2713. return 0;
  2714. }
  2715. static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
  2716. char *cmd)
  2717. {
  2718. if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
  2719. return -1;
  2720. wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
  2721. return 0;
  2722. }
  2723. static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
  2724. char *cmd)
  2725. {
  2726. char *pos;
  2727. size_t len;
  2728. struct wpabuf *query, *resp;
  2729. pos = os_strchr(cmd, ' ');
  2730. if (pos == NULL)
  2731. return -1;
  2732. *pos++ = '\0';
  2733. len = os_strlen(cmd);
  2734. if (len & 1)
  2735. return -1;
  2736. len /= 2;
  2737. query = wpabuf_alloc(len);
  2738. if (query == NULL)
  2739. return -1;
  2740. if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
  2741. wpabuf_free(query);
  2742. return -1;
  2743. }
  2744. len = os_strlen(pos);
  2745. if (len & 1) {
  2746. wpabuf_free(query);
  2747. return -1;
  2748. }
  2749. len /= 2;
  2750. resp = wpabuf_alloc(len);
  2751. if (resp == NULL) {
  2752. wpabuf_free(query);
  2753. return -1;
  2754. }
  2755. if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
  2756. wpabuf_free(query);
  2757. wpabuf_free(resp);
  2758. return -1;
  2759. }
  2760. if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
  2761. wpabuf_free(query);
  2762. wpabuf_free(resp);
  2763. return -1;
  2764. }
  2765. return 0;
  2766. }
  2767. static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
  2768. {
  2769. char *pos;
  2770. u8 version;
  2771. pos = os_strchr(cmd, ' ');
  2772. if (pos == NULL)
  2773. return -1;
  2774. *pos++ = '\0';
  2775. if (hexstr2bin(cmd, &version, 1) < 0)
  2776. return -1;
  2777. return wpas_p2p_service_add_upnp(wpa_s, version, pos);
  2778. }
  2779. static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
  2780. {
  2781. char *pos;
  2782. pos = os_strchr(cmd, ' ');
  2783. if (pos == NULL)
  2784. return -1;
  2785. *pos++ = '\0';
  2786. if (os_strcmp(cmd, "bonjour") == 0)
  2787. return p2p_ctrl_service_add_bonjour(wpa_s, pos);
  2788. if (os_strcmp(cmd, "upnp") == 0)
  2789. return p2p_ctrl_service_add_upnp(wpa_s, pos);
  2790. wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
  2791. return -1;
  2792. }
  2793. static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
  2794. char *cmd)
  2795. {
  2796. size_t len;
  2797. struct wpabuf *query;
  2798. int ret;
  2799. len = os_strlen(cmd);
  2800. if (len & 1)
  2801. return -1;
  2802. len /= 2;
  2803. query = wpabuf_alloc(len);
  2804. if (query == NULL)
  2805. return -1;
  2806. if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
  2807. wpabuf_free(query);
  2808. return -1;
  2809. }
  2810. ret = wpas_p2p_service_del_bonjour(wpa_s, query);
  2811. wpabuf_free(query);
  2812. return ret;
  2813. }
  2814. static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
  2815. {
  2816. char *pos;
  2817. u8 version;
  2818. pos = os_strchr(cmd, ' ');
  2819. if (pos == NULL)
  2820. return -1;
  2821. *pos++ = '\0';
  2822. if (hexstr2bin(cmd, &version, 1) < 0)
  2823. return -1;
  2824. return wpas_p2p_service_del_upnp(wpa_s, version, pos);
  2825. }
  2826. static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
  2827. {
  2828. char *pos;
  2829. pos = os_strchr(cmd, ' ');
  2830. if (pos == NULL)
  2831. return -1;
  2832. *pos++ = '\0';
  2833. if (os_strcmp(cmd, "bonjour") == 0)
  2834. return p2p_ctrl_service_del_bonjour(wpa_s, pos);
  2835. if (os_strcmp(cmd, "upnp") == 0)
  2836. return p2p_ctrl_service_del_upnp(wpa_s, pos);
  2837. wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
  2838. return -1;
  2839. }
  2840. static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
  2841. {
  2842. u8 addr[ETH_ALEN];
  2843. /* <addr> */
  2844. if (hwaddr_aton(cmd, addr))
  2845. return -1;
  2846. return wpas_p2p_reject(wpa_s, addr);
  2847. }
  2848. static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
  2849. {
  2850. char *pos;
  2851. int id;
  2852. struct wpa_ssid *ssid;
  2853. u8 peer[ETH_ALEN];
  2854. id = atoi(cmd);
  2855. pos = os_strstr(cmd, " peer=");
  2856. if (pos) {
  2857. pos += 6;
  2858. if (hwaddr_aton(pos, peer))
  2859. return -1;
  2860. }
  2861. ssid = wpa_config_get_network(wpa_s->conf, id);
  2862. if (ssid == NULL || ssid->disabled != 2) {
  2863. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
  2864. "for persistent P2P group",
  2865. id);
  2866. return -1;
  2867. }
  2868. return wpas_p2p_invite(wpa_s, pos ? peer : NULL, ssid, NULL);
  2869. }
  2870. static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
  2871. {
  2872. char *pos;
  2873. u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
  2874. pos = os_strstr(cmd, " peer=");
  2875. if (!pos)
  2876. return -1;
  2877. *pos = '\0';
  2878. pos += 6;
  2879. if (hwaddr_aton(pos, peer)) {
  2880. wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
  2881. return -1;
  2882. }
  2883. pos = os_strstr(pos, " go_dev_addr=");
  2884. if (pos) {
  2885. pos += 13;
  2886. if (hwaddr_aton(pos, go_dev_addr)) {
  2887. wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
  2888. pos);
  2889. return -1;
  2890. }
  2891. go_dev = go_dev_addr;
  2892. }
  2893. return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
  2894. }
  2895. static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
  2896. {
  2897. if (os_strncmp(cmd, "persistent=", 11) == 0)
  2898. return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
  2899. if (os_strncmp(cmd, "group=", 6) == 0)
  2900. return p2p_ctrl_invite_group(wpa_s, cmd + 6);
  2901. return -1;
  2902. }
  2903. static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
  2904. char *cmd, int freq)
  2905. {
  2906. int id;
  2907. struct wpa_ssid *ssid;
  2908. id = atoi(cmd);
  2909. ssid = wpa_config_get_network(wpa_s->conf, id);
  2910. if (ssid == NULL || ssid->disabled != 2) {
  2911. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
  2912. "for persistent P2P group",
  2913. id);
  2914. return -1;
  2915. }
  2916. return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq);
  2917. }
  2918. static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
  2919. {
  2920. int freq = 0;
  2921. char *pos;
  2922. pos = os_strstr(cmd, "freq=");
  2923. if (pos)
  2924. freq = atoi(pos + 5);
  2925. if (os_strncmp(cmd, "persistent=", 11) == 0)
  2926. return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq);
  2927. if (os_strcmp(cmd, "persistent") == 0 ||
  2928. os_strncmp(cmd, "persistent ", 11) == 0)
  2929. return wpas_p2p_group_add(wpa_s, 1, freq);
  2930. if (os_strncmp(cmd, "freq=", 5) == 0)
  2931. return wpas_p2p_group_add(wpa_s, 0, freq);
  2932. wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
  2933. cmd);
  2934. return -1;
  2935. }
  2936. static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
  2937. char *buf, size_t buflen)
  2938. {
  2939. u8 addr[ETH_ALEN], *addr_ptr;
  2940. int next, res;
  2941. const struct p2p_peer_info *info;
  2942. char *pos, *end;
  2943. char devtype[WPS_DEV_TYPE_BUFSIZE];
  2944. struct wpa_ssid *ssid;
  2945. if (!wpa_s->global->p2p)
  2946. return -1;
  2947. if (os_strcmp(cmd, "FIRST") == 0) {
  2948. addr_ptr = NULL;
  2949. next = 0;
  2950. } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
  2951. if (hwaddr_aton(cmd + 5, addr) < 0)
  2952. return -1;
  2953. addr_ptr = addr;
  2954. next = 1;
  2955. } else {
  2956. if (hwaddr_aton(cmd, addr) < 0)
  2957. return -1;
  2958. addr_ptr = addr;
  2959. next = 0;
  2960. }
  2961. info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
  2962. if (info == NULL)
  2963. return -1;
  2964. pos = buf;
  2965. end = buf + buflen;
  2966. res = os_snprintf(pos, end - pos, MACSTR "\n"
  2967. "pri_dev_type=%s\n"
  2968. "device_name=%s\n"
  2969. "manufacturer=%s\n"
  2970. "model_name=%s\n"
  2971. "model_number=%s\n"
  2972. "serial_number=%s\n"
  2973. "config_methods=0x%x\n"
  2974. "dev_capab=0x%x\n"
  2975. "group_capab=0x%x\n"
  2976. "level=%d\n",
  2977. MAC2STR(info->p2p_device_addr),
  2978. wps_dev_type_bin2str(info->pri_dev_type,
  2979. devtype, sizeof(devtype)),
  2980. info->device_name,
  2981. info->manufacturer,
  2982. info->model_name,
  2983. info->model_number,
  2984. info->serial_number,
  2985. info->config_methods,
  2986. info->dev_capab,
  2987. info->group_capab,
  2988. info->level);
  2989. if (res < 0 || res >= end - pos)
  2990. return pos - buf;
  2991. pos += res;
  2992. ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
  2993. if (ssid) {
  2994. res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
  2995. if (res < 0 || res >= end - pos)
  2996. return pos - buf;
  2997. pos += res;
  2998. }
  2999. res = p2p_get_peer_info_txt(info, pos, end - pos);
  3000. if (res < 0)
  3001. return pos - buf;
  3002. pos += res;
  3003. return pos - buf;
  3004. }
  3005. static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
  3006. const char *param)
  3007. {
  3008. struct wpa_freq_range *freq = NULL, *n;
  3009. unsigned int count = 0, i;
  3010. const char *pos, *pos2, *pos3;
  3011. if (wpa_s->global->p2p == NULL)
  3012. return -1;
  3013. /*
  3014. * param includes comma separated frequency range.
  3015. * For example: 2412-2432,2462,5000-6000
  3016. */
  3017. pos = param;
  3018. while (pos && pos[0]) {
  3019. n = os_realloc(freq,
  3020. (count + 1) * sizeof(struct wpa_freq_range));
  3021. if (n == NULL) {
  3022. os_free(freq);
  3023. return -1;
  3024. }
  3025. freq = n;
  3026. freq[count].min = atoi(pos);
  3027. pos2 = os_strchr(pos, '-');
  3028. pos3 = os_strchr(pos, ',');
  3029. if (pos2 && (!pos3 || pos2 < pos3)) {
  3030. pos2++;
  3031. freq[count].max = atoi(pos2);
  3032. } else
  3033. freq[count].max = freq[count].min;
  3034. pos = pos3;
  3035. if (pos)
  3036. pos++;
  3037. count++;
  3038. }
  3039. for (i = 0; i < count; i++) {
  3040. wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
  3041. freq[i].min, freq[i].max);
  3042. }
  3043. os_free(wpa_s->global->p2p_disallow_freq);
  3044. wpa_s->global->p2p_disallow_freq = freq;
  3045. wpa_s->global->num_p2p_disallow_freq = count;
  3046. wpas_p2p_update_channel_list(wpa_s);
  3047. return 0;
  3048. }
  3049. static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
  3050. {
  3051. char *param;
  3052. if (wpa_s->global->p2p == NULL)
  3053. return -1;
  3054. param = os_strchr(cmd, ' ');
  3055. if (param == NULL)
  3056. return -1;
  3057. *param++ = '\0';
  3058. if (os_strcmp(cmd, "discoverability") == 0) {
  3059. p2p_set_client_discoverability(wpa_s->global->p2p,
  3060. atoi(param));
  3061. return 0;
  3062. }
  3063. if (os_strcmp(cmd, "managed") == 0) {
  3064. p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
  3065. return 0;
  3066. }
  3067. if (os_strcmp(cmd, "listen_channel") == 0) {
  3068. return p2p_set_listen_channel(wpa_s->global->p2p, 81,
  3069. atoi(param));
  3070. }
  3071. if (os_strcmp(cmd, "ssid_postfix") == 0) {
  3072. return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
  3073. os_strlen(param));
  3074. }
  3075. if (os_strcmp(cmd, "noa") == 0) {
  3076. char *pos;
  3077. int count, start, duration;
  3078. /* GO NoA parameters: count,start_offset(ms),duration(ms) */
  3079. count = atoi(param);
  3080. pos = os_strchr(param, ',');
  3081. if (pos == NULL)
  3082. return -1;
  3083. pos++;
  3084. start = atoi(pos);
  3085. pos = os_strchr(pos, ',');
  3086. if (pos == NULL)
  3087. return -1;
  3088. pos++;
  3089. duration = atoi(pos);
  3090. if (count < 0 || count > 255 || start < 0 || duration < 0)
  3091. return -1;
  3092. if (count == 0 && duration > 0)
  3093. return -1;
  3094. wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
  3095. "start=%d duration=%d", count, start, duration);
  3096. return wpas_p2p_set_noa(wpa_s, count, start, duration);
  3097. }
  3098. if (os_strcmp(cmd, "ps") == 0)
  3099. return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
  3100. if (os_strcmp(cmd, "oppps") == 0)
  3101. return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
  3102. if (os_strcmp(cmd, "ctwindow") == 0)
  3103. return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
  3104. if (os_strcmp(cmd, "disabled") == 0) {
  3105. wpa_s->global->p2p_disabled = atoi(param);
  3106. wpa_printf(MSG_DEBUG, "P2P functionality %s",
  3107. wpa_s->global->p2p_disabled ?
  3108. "disabled" : "enabled");
  3109. if (wpa_s->global->p2p_disabled) {
  3110. wpas_p2p_stop_find(wpa_s);
  3111. os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
  3112. p2p_flush(wpa_s->global->p2p);
  3113. }
  3114. return 0;
  3115. }
  3116. if (os_strcmp(cmd, "conc_pref") == 0) {
  3117. if (os_strcmp(param, "sta") == 0)
  3118. wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
  3119. else if (os_strcmp(param, "p2p") == 0)
  3120. wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
  3121. else {
  3122. wpa_printf(MSG_INFO, "Invalid conc_pref value");
  3123. return -1;
  3124. }
  3125. wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
  3126. "%s", param);
  3127. return 0;
  3128. }
  3129. if (os_strcmp(cmd, "force_long_sd") == 0) {
  3130. wpa_s->force_long_sd = atoi(param);
  3131. return 0;
  3132. }
  3133. if (os_strcmp(cmd, "peer_filter") == 0) {
  3134. u8 addr[ETH_ALEN];
  3135. if (hwaddr_aton(param, addr))
  3136. return -1;
  3137. p2p_set_peer_filter(wpa_s->global->p2p, addr);
  3138. return 0;
  3139. }
  3140. if (os_strcmp(cmd, "cross_connect") == 0)
  3141. return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
  3142. if (os_strcmp(cmd, "go_apsd") == 0) {
  3143. if (os_strcmp(param, "disable") == 0)
  3144. wpa_s->set_ap_uapsd = 0;
  3145. else {
  3146. wpa_s->set_ap_uapsd = 1;
  3147. wpa_s->ap_uapsd = atoi(param);
  3148. }
  3149. return 0;
  3150. }
  3151. if (os_strcmp(cmd, "client_apsd") == 0) {
  3152. if (os_strcmp(param, "disable") == 0)
  3153. wpa_s->set_sta_uapsd = 0;
  3154. else {
  3155. int be, bk, vi, vo;
  3156. char *pos;
  3157. /* format: BE,BK,VI,VO;max SP Length */
  3158. be = atoi(param);
  3159. pos = os_strchr(param, ',');
  3160. if (pos == NULL)
  3161. return -1;
  3162. pos++;
  3163. bk = atoi(pos);
  3164. pos = os_strchr(pos, ',');
  3165. if (pos == NULL)
  3166. return -1;
  3167. pos++;
  3168. vi = atoi(pos);
  3169. pos = os_strchr(pos, ',');
  3170. if (pos == NULL)
  3171. return -1;
  3172. pos++;
  3173. vo = atoi(pos);
  3174. /* ignore max SP Length for now */
  3175. wpa_s->set_sta_uapsd = 1;
  3176. wpa_s->sta_uapsd = 0;
  3177. if (be)
  3178. wpa_s->sta_uapsd |= BIT(0);
  3179. if (bk)
  3180. wpa_s->sta_uapsd |= BIT(1);
  3181. if (vi)
  3182. wpa_s->sta_uapsd |= BIT(2);
  3183. if (vo)
  3184. wpa_s->sta_uapsd |= BIT(3);
  3185. }
  3186. return 0;
  3187. }
  3188. if (os_strcmp(cmd, "disallow_freq") == 0)
  3189. return p2p_ctrl_disallow_freq(wpa_s, param);
  3190. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
  3191. cmd);
  3192. return -1;
  3193. }
  3194. static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
  3195. {
  3196. char *pos, *pos2;
  3197. unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
  3198. if (cmd[0]) {
  3199. pos = os_strchr(cmd, ' ');
  3200. if (pos == NULL)
  3201. return -1;
  3202. *pos++ = '\0';
  3203. dur1 = atoi(cmd);
  3204. pos2 = os_strchr(pos, ' ');
  3205. if (pos2)
  3206. *pos2++ = '\0';
  3207. int1 = atoi(pos);
  3208. } else
  3209. pos2 = NULL;
  3210. if (pos2) {
  3211. pos = os_strchr(pos2, ' ');
  3212. if (pos == NULL)
  3213. return -1;
  3214. *pos++ = '\0';
  3215. dur2 = atoi(pos2);
  3216. int2 = atoi(pos);
  3217. }
  3218. return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
  3219. }
  3220. static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
  3221. {
  3222. char *pos;
  3223. unsigned int period = 0, interval = 0;
  3224. if (cmd[0]) {
  3225. pos = os_strchr(cmd, ' ');
  3226. if (pos == NULL)
  3227. return -1;
  3228. *pos++ = '\0';
  3229. period = atoi(cmd);
  3230. interval = atoi(pos);
  3231. }
  3232. return wpas_p2p_ext_listen(wpa_s, period, interval);
  3233. }
  3234. #endif /* CONFIG_P2P */
  3235. #ifdef CONFIG_INTERWORKING
  3236. static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst)
  3237. {
  3238. u8 bssid[ETH_ALEN];
  3239. struct wpa_bss *bss;
  3240. if (hwaddr_aton(dst, bssid)) {
  3241. wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
  3242. return -1;
  3243. }
  3244. bss = wpa_bss_get_bssid(wpa_s, bssid);
  3245. if (bss == NULL) {
  3246. wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
  3247. MAC2STR(bssid));
  3248. return -1;
  3249. }
  3250. return interworking_connect(wpa_s, bss);
  3251. }
  3252. static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
  3253. {
  3254. u8 dst_addr[ETH_ALEN];
  3255. int used;
  3256. char *pos;
  3257. #define MAX_ANQP_INFO_ID 100
  3258. u16 id[MAX_ANQP_INFO_ID];
  3259. size_t num_id = 0;
  3260. used = hwaddr_aton2(dst, dst_addr);
  3261. if (used < 0)
  3262. return -1;
  3263. pos = dst + used;
  3264. while (num_id < MAX_ANQP_INFO_ID) {
  3265. id[num_id] = atoi(pos);
  3266. if (id[num_id])
  3267. num_id++;
  3268. pos = os_strchr(pos + 1, ',');
  3269. if (pos == NULL)
  3270. break;
  3271. pos++;
  3272. }
  3273. if (num_id == 0)
  3274. return -1;
  3275. return anqp_send_req(wpa_s, dst_addr, id, num_id);
  3276. }
  3277. #endif /* CONFIG_INTERWORKING */
  3278. #ifdef CONFIG_HS20
  3279. static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
  3280. {
  3281. u8 dst_addr[ETH_ALEN];
  3282. int used;
  3283. char *pos;
  3284. u32 subtypes = 0;
  3285. used = hwaddr_aton2(dst, dst_addr);
  3286. if (used < 0)
  3287. return -1;
  3288. pos = dst + used;
  3289. for (;;) {
  3290. int num = atoi(pos);
  3291. if (num <= 0 || num > 31)
  3292. return -1;
  3293. subtypes |= BIT(num);
  3294. pos = os_strchr(pos + 1, ',');
  3295. if (pos == NULL)
  3296. break;
  3297. pos++;
  3298. }
  3299. if (subtypes == 0)
  3300. return -1;
  3301. return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0);
  3302. }
  3303. static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
  3304. const u8 *addr, const char *realm)
  3305. {
  3306. u8 *buf;
  3307. size_t rlen, len;
  3308. int ret;
  3309. rlen = os_strlen(realm);
  3310. len = 3 + rlen;
  3311. buf = os_malloc(len);
  3312. if (buf == NULL)
  3313. return -1;
  3314. buf[0] = 1; /* NAI Home Realm Count */
  3315. buf[1] = 0; /* Formatted in accordance with RFC 4282 */
  3316. buf[2] = rlen;
  3317. os_memcpy(buf + 3, realm, rlen);
  3318. ret = hs20_anqp_send_req(wpa_s, addr,
  3319. BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
  3320. buf, len);
  3321. os_free(buf);
  3322. return ret;
  3323. }
  3324. static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
  3325. char *dst)
  3326. {
  3327. struct wpa_cred *cred = wpa_s->conf->cred;
  3328. u8 dst_addr[ETH_ALEN];
  3329. int used;
  3330. u8 *buf;
  3331. size_t len;
  3332. int ret;
  3333. used = hwaddr_aton2(dst, dst_addr);
  3334. if (used < 0)
  3335. return -1;
  3336. while (dst[used] == ' ')
  3337. used++;
  3338. if (os_strncmp(dst + used, "realm=", 6) == 0)
  3339. return hs20_nai_home_realm_list(wpa_s, dst_addr,
  3340. dst + used + 6);
  3341. len = os_strlen(dst + used);
  3342. if (len == 0 && cred && cred->realm)
  3343. return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
  3344. if (len % 1)
  3345. return -1;
  3346. len /= 2;
  3347. buf = os_malloc(len);
  3348. if (buf == NULL)
  3349. return -1;
  3350. if (hexstr2bin(dst + used, buf, len) < 0) {
  3351. os_free(buf);
  3352. return -1;
  3353. }
  3354. ret = hs20_anqp_send_req(wpa_s, dst_addr,
  3355. BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
  3356. buf, len);
  3357. os_free(buf);
  3358. return ret;
  3359. }
  3360. #endif /* CONFIG_HS20 */
  3361. static int wpa_supplicant_ctrl_iface_sta_autoconnect(
  3362. struct wpa_supplicant *wpa_s, char *cmd)
  3363. {
  3364. wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0;
  3365. return 0;
  3366. }
  3367. #ifdef CONFIG_AUTOSCAN
  3368. static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
  3369. char *cmd)
  3370. {
  3371. enum wpa_states state = wpa_s->wpa_state;
  3372. char *new_params = NULL;
  3373. if (os_strlen(cmd) > 0) {
  3374. new_params = os_strdup(cmd);
  3375. if (new_params == NULL)
  3376. return -1;
  3377. }
  3378. os_free(wpa_s->conf->autoscan);
  3379. wpa_s->conf->autoscan = new_params;
  3380. if (wpa_s->conf->autoscan == NULL)
  3381. autoscan_deinit(wpa_s);
  3382. else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
  3383. autoscan_init(wpa_s, 1);
  3384. else if (state == WPA_SCANNING)
  3385. wpa_supplicant_reinit_autoscan(wpa_s);
  3386. return 0;
  3387. }
  3388. #endif /* CONFIG_AUTOSCAN */
  3389. static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
  3390. size_t buflen)
  3391. {
  3392. struct wpa_signal_info si;
  3393. int ret;
  3394. ret = wpa_drv_signal_poll(wpa_s, &si);
  3395. if (ret)
  3396. return -1;
  3397. ret = os_snprintf(buf, buflen, "RSSI=%d\nLINKSPEED=%d\n"
  3398. "NOISE=%d\nFREQUENCY=%u\n",
  3399. si.current_signal, si.current_txrate / 1000,
  3400. si.current_noise, si.frequency);
  3401. if (ret < 0 || (unsigned int) ret > buflen)
  3402. return -1;
  3403. return ret;
  3404. }
  3405. char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
  3406. char *buf, size_t *resp_len)
  3407. {
  3408. char *reply;
  3409. const int reply_size = 4096;
  3410. int ctrl_rsp = 0;
  3411. int reply_len;
  3412. if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
  3413. os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
  3414. wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
  3415. (const u8 *) buf, os_strlen(buf));
  3416. } else {
  3417. int level = MSG_DEBUG;
  3418. if (os_strcmp(buf, "PING") == 0)
  3419. level = MSG_EXCESSIVE;
  3420. wpa_hexdump_ascii(level, "RX ctrl_iface",
  3421. (const u8 *) buf, os_strlen(buf));
  3422. }
  3423. reply = os_malloc(reply_size);
  3424. if (reply == NULL) {
  3425. *resp_len = 1;
  3426. return NULL;
  3427. }
  3428. os_memcpy(reply, "OK\n", 3);
  3429. reply_len = 3;
  3430. if (os_strcmp(buf, "PING") == 0) {
  3431. os_memcpy(reply, "PONG\n", 5);
  3432. reply_len = 5;
  3433. } else if (os_strncmp(buf, "RELOG", 5) == 0) {
  3434. if (wpa_debug_reopen_file() < 0)
  3435. reply_len = -1;
  3436. } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
  3437. wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
  3438. } else if (os_strcmp(buf, "MIB") == 0) {
  3439. reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
  3440. if (reply_len >= 0) {
  3441. int res;
  3442. res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
  3443. reply_size - reply_len);
  3444. if (res < 0)
  3445. reply_len = -1;
  3446. else
  3447. reply_len += res;
  3448. }
  3449. } else if (os_strncmp(buf, "STATUS", 6) == 0) {
  3450. reply_len = wpa_supplicant_ctrl_iface_status(
  3451. wpa_s, buf + 6, reply, reply_size);
  3452. } else if (os_strcmp(buf, "PMKSA") == 0) {
  3453. reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
  3454. reply_size);
  3455. } else if (os_strncmp(buf, "SET ", 4) == 0) {
  3456. if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
  3457. reply_len = -1;
  3458. } else if (os_strncmp(buf, "GET ", 4) == 0) {
  3459. reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
  3460. reply, reply_size);
  3461. } else if (os_strcmp(buf, "LOGON") == 0) {
  3462. eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
  3463. } else if (os_strcmp(buf, "LOGOFF") == 0) {
  3464. eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
  3465. } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
  3466. wpa_s->normal_scans = 0;
  3467. wpa_supplicant_reinit_autoscan(wpa_s);
  3468. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  3469. reply_len = -1;
  3470. else {
  3471. wpa_s->disconnected = 0;
  3472. wpa_s->reassociate = 1;
  3473. wpa_supplicant_req_scan(wpa_s, 0, 0);
  3474. }
  3475. } else if (os_strcmp(buf, "RECONNECT") == 0) {
  3476. wpa_s->normal_scans = 0;
  3477. wpa_supplicant_reinit_autoscan(wpa_s);
  3478. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  3479. reply_len = -1;
  3480. else if (wpa_s->disconnected) {
  3481. wpa_s->disconnected = 0;
  3482. wpa_s->reassociate = 1;
  3483. wpa_supplicant_req_scan(wpa_s, 0, 0);
  3484. }
  3485. #ifdef IEEE8021X_EAPOL
  3486. } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
  3487. if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
  3488. reply_len = -1;
  3489. #endif /* IEEE8021X_EAPOL */
  3490. #ifdef CONFIG_PEERKEY
  3491. } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
  3492. if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
  3493. reply_len = -1;
  3494. #endif /* CONFIG_PEERKEY */
  3495. #ifdef CONFIG_IEEE80211R
  3496. } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
  3497. if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
  3498. reply_len = -1;
  3499. #endif /* CONFIG_IEEE80211R */
  3500. #ifdef CONFIG_WPS
  3501. } else if (os_strcmp(buf, "WPS_PBC") == 0) {
  3502. int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
  3503. if (res == -2) {
  3504. os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
  3505. reply_len = 17;
  3506. } else if (res)
  3507. reply_len = -1;
  3508. } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
  3509. int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
  3510. if (res == -2) {
  3511. os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
  3512. reply_len = 17;
  3513. } else if (res)
  3514. reply_len = -1;
  3515. } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
  3516. reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
  3517. reply,
  3518. reply_size);
  3519. } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
  3520. reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
  3521. wpa_s, buf + 14, reply, reply_size);
  3522. } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
  3523. if (wpas_wps_cancel(wpa_s))
  3524. reply_len = -1;
  3525. #ifdef CONFIG_WPS_OOB
  3526. } else if (os_strncmp(buf, "WPS_OOB ", 8) == 0) {
  3527. if (wpa_supplicant_ctrl_iface_wps_oob(wpa_s, buf + 8))
  3528. reply_len = -1;
  3529. #endif /* CONFIG_WPS_OOB */
  3530. #ifdef CONFIG_WPS_NFC
  3531. } else if (os_strcmp(buf, "WPS_NFC") == 0) {
  3532. if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
  3533. reply_len = -1;
  3534. } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
  3535. if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
  3536. reply_len = -1;
  3537. } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
  3538. reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
  3539. wpa_s, buf + 14, reply, reply_size);
  3540. } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
  3541. if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
  3542. buf + 17))
  3543. reply_len = -1;
  3544. #endif /* CONFIG_WPS_NFC */
  3545. } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
  3546. if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
  3547. reply_len = -1;
  3548. #ifdef CONFIG_AP
  3549. } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
  3550. reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
  3551. wpa_s, buf + 11, reply, reply_size);
  3552. #endif /* CONFIG_AP */
  3553. #ifdef CONFIG_WPS_ER
  3554. } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
  3555. if (wpas_wps_er_start(wpa_s, NULL))
  3556. reply_len = -1;
  3557. } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
  3558. if (wpas_wps_er_start(wpa_s, buf + 13))
  3559. reply_len = -1;
  3560. } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
  3561. if (wpas_wps_er_stop(wpa_s))
  3562. reply_len = -1;
  3563. } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
  3564. if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
  3565. reply_len = -1;
  3566. } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
  3567. int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
  3568. if (ret == -2) {
  3569. os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
  3570. reply_len = 17;
  3571. } else if (ret == -3) {
  3572. os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
  3573. reply_len = 18;
  3574. } else if (ret == -4) {
  3575. os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
  3576. reply_len = 20;
  3577. } else if (ret)
  3578. reply_len = -1;
  3579. } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
  3580. if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
  3581. reply_len = -1;
  3582. } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
  3583. if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
  3584. buf + 18))
  3585. reply_len = -1;
  3586. } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
  3587. if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
  3588. reply_len = -1;
  3589. #ifdef CONFIG_WPS_NFC
  3590. } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
  3591. reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
  3592. wpa_s, buf + 24, reply, reply_size);
  3593. #endif /* CONFIG_WPS_NFC */
  3594. #endif /* CONFIG_WPS_ER */
  3595. #endif /* CONFIG_WPS */
  3596. #ifdef CONFIG_IBSS_RSN
  3597. } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
  3598. if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
  3599. reply_len = -1;
  3600. #endif /* CONFIG_IBSS_RSN */
  3601. #ifdef CONFIG_P2P
  3602. } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
  3603. if (p2p_ctrl_find(wpa_s, buf + 9))
  3604. reply_len = -1;
  3605. } else if (os_strcmp(buf, "P2P_FIND") == 0) {
  3606. if (p2p_ctrl_find(wpa_s, ""))
  3607. reply_len = -1;
  3608. } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
  3609. wpas_p2p_stop_find(wpa_s);
  3610. } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
  3611. reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
  3612. reply_size);
  3613. } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
  3614. if (p2p_ctrl_listen(wpa_s, buf + 11))
  3615. reply_len = -1;
  3616. } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
  3617. if (p2p_ctrl_listen(wpa_s, ""))
  3618. reply_len = -1;
  3619. } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
  3620. if (wpas_p2p_group_remove(wpa_s, buf + 17))
  3621. reply_len = -1;
  3622. } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
  3623. if (wpas_p2p_group_add(wpa_s, 0, 0))
  3624. reply_len = -1;
  3625. } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
  3626. if (p2p_ctrl_group_add(wpa_s, buf + 14))
  3627. reply_len = -1;
  3628. } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
  3629. if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
  3630. reply_len = -1;
  3631. } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
  3632. reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
  3633. } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
  3634. reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
  3635. reply_size);
  3636. } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
  3637. if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
  3638. reply_len = -1;
  3639. } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
  3640. if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
  3641. reply_len = -1;
  3642. } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
  3643. wpas_p2p_sd_service_update(wpa_s);
  3644. } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
  3645. if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
  3646. reply_len = -1;
  3647. } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
  3648. wpas_p2p_service_flush(wpa_s);
  3649. } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
  3650. if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
  3651. reply_len = -1;
  3652. } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
  3653. if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
  3654. reply_len = -1;
  3655. } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
  3656. if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
  3657. reply_len = -1;
  3658. } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
  3659. if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
  3660. reply_len = -1;
  3661. } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
  3662. reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
  3663. reply_size);
  3664. } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
  3665. if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
  3666. reply_len = -1;
  3667. } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
  3668. os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
  3669. wpa_s->force_long_sd = 0;
  3670. if (wpa_s->global->p2p)
  3671. p2p_flush(wpa_s->global->p2p);
  3672. } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
  3673. if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
  3674. reply_len = -1;
  3675. } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
  3676. if (wpas_p2p_cancel(wpa_s))
  3677. reply_len = -1;
  3678. } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
  3679. if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
  3680. reply_len = -1;
  3681. } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
  3682. if (p2p_ctrl_presence_req(wpa_s, "") < 0)
  3683. reply_len = -1;
  3684. } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
  3685. if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
  3686. reply_len = -1;
  3687. } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
  3688. if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
  3689. reply_len = -1;
  3690. #endif /* CONFIG_P2P */
  3691. #ifdef CONFIG_INTERWORKING
  3692. } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
  3693. if (interworking_fetch_anqp(wpa_s) < 0)
  3694. reply_len = -1;
  3695. } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
  3696. interworking_stop_fetch_anqp(wpa_s);
  3697. } else if (os_strncmp(buf, "INTERWORKING_SELECT", 19) == 0) {
  3698. if (interworking_select(wpa_s, os_strstr(buf + 19, "auto") !=
  3699. NULL) < 0)
  3700. reply_len = -1;
  3701. } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
  3702. if (ctrl_interworking_connect(wpa_s, buf + 21) < 0)
  3703. reply_len = -1;
  3704. } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
  3705. if (get_anqp(wpa_s, buf + 9) < 0)
  3706. reply_len = -1;
  3707. #endif /* CONFIG_INTERWORKING */
  3708. #ifdef CONFIG_HS20
  3709. } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
  3710. if (get_hs20_anqp(wpa_s, buf + 14) < 0)
  3711. reply_len = -1;
  3712. } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
  3713. if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
  3714. reply_len = -1;
  3715. #endif /* CONFIG_HS20 */
  3716. } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
  3717. {
  3718. if (wpa_supplicant_ctrl_iface_ctrl_rsp(
  3719. wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
  3720. reply_len = -1;
  3721. else
  3722. ctrl_rsp = 1;
  3723. } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
  3724. if (wpa_supplicant_reload_configuration(wpa_s))
  3725. reply_len = -1;
  3726. } else if (os_strcmp(buf, "TERMINATE") == 0) {
  3727. wpa_supplicant_terminate_proc(wpa_s->global);
  3728. } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
  3729. if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
  3730. reply_len = -1;
  3731. } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
  3732. reply_len = wpa_supplicant_ctrl_iface_blacklist(
  3733. wpa_s, buf + 9, reply, reply_size);
  3734. } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
  3735. reply_len = wpa_supplicant_ctrl_iface_log_level(
  3736. wpa_s, buf + 9, reply, reply_size);
  3737. } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
  3738. reply_len = wpa_supplicant_ctrl_iface_list_networks(
  3739. wpa_s, reply, reply_size);
  3740. } else if (os_strcmp(buf, "DISCONNECT") == 0) {
  3741. #ifdef CONFIG_SME
  3742. wpa_s->sme.prev_bssid_set = 0;
  3743. #endif /* CONFIG_SME */
  3744. wpa_s->reassociate = 0;
  3745. wpa_s->disconnected = 1;
  3746. wpa_supplicant_cancel_sched_scan(wpa_s);
  3747. wpa_supplicant_cancel_scan(wpa_s);
  3748. wpa_supplicant_deauthenticate(wpa_s,
  3749. WLAN_REASON_DEAUTH_LEAVING);
  3750. } else if (os_strcmp(buf, "SCAN") == 0) {
  3751. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  3752. reply_len = -1;
  3753. else {
  3754. if (!wpa_s->scanning &&
  3755. ((wpa_s->wpa_state <= WPA_SCANNING) ||
  3756. (wpa_s->wpa_state == WPA_COMPLETED))) {
  3757. wpa_s->normal_scans = 0;
  3758. wpa_s->scan_req = 2;
  3759. wpa_supplicant_req_scan(wpa_s, 0, 0);
  3760. } else if (wpa_s->sched_scanning) {
  3761. wpa_printf(MSG_DEBUG, "Stop ongoing "
  3762. "sched_scan to allow requested "
  3763. "full scan to proceed");
  3764. wpa_supplicant_cancel_sched_scan(wpa_s);
  3765. wpa_s->scan_req = 2;
  3766. wpa_supplicant_req_scan(wpa_s, 0, 0);
  3767. } else {
  3768. wpa_printf(MSG_DEBUG, "Ongoing scan action - "
  3769. "reject new request");
  3770. reply_len = os_snprintf(reply, reply_size,
  3771. "FAIL-BUSY\n");
  3772. }
  3773. }
  3774. } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
  3775. reply_len = wpa_supplicant_ctrl_iface_scan_results(
  3776. wpa_s, reply, reply_size);
  3777. } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
  3778. if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
  3779. reply_len = -1;
  3780. } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
  3781. if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
  3782. reply_len = -1;
  3783. } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
  3784. if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
  3785. reply_len = -1;
  3786. } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
  3787. reply_len = wpa_supplicant_ctrl_iface_add_network(
  3788. wpa_s, reply, reply_size);
  3789. } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
  3790. if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
  3791. reply_len = -1;
  3792. } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
  3793. if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
  3794. reply_len = -1;
  3795. } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
  3796. reply_len = wpa_supplicant_ctrl_iface_get_network(
  3797. wpa_s, buf + 12, reply, reply_size);
  3798. } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
  3799. reply_len = wpa_supplicant_ctrl_iface_list_creds(
  3800. wpa_s, reply, reply_size);
  3801. } else if (os_strcmp(buf, "ADD_CRED") == 0) {
  3802. reply_len = wpa_supplicant_ctrl_iface_add_cred(
  3803. wpa_s, reply, reply_size);
  3804. } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
  3805. if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
  3806. reply_len = -1;
  3807. } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
  3808. if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
  3809. reply_len = -1;
  3810. #ifndef CONFIG_NO_CONFIG_WRITE
  3811. } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
  3812. if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
  3813. reply_len = -1;
  3814. #endif /* CONFIG_NO_CONFIG_WRITE */
  3815. } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
  3816. reply_len = wpa_supplicant_ctrl_iface_get_capability(
  3817. wpa_s, buf + 15, reply, reply_size);
  3818. } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
  3819. if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
  3820. reply_len = -1;
  3821. } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
  3822. if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
  3823. reply_len = -1;
  3824. } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
  3825. reply_len = wpa_supplicant_global_iface_list(
  3826. wpa_s->global, reply, reply_size);
  3827. } else if (os_strcmp(buf, "INTERFACES") == 0) {
  3828. reply_len = wpa_supplicant_global_iface_interfaces(
  3829. wpa_s->global, reply, reply_size);
  3830. } else if (os_strncmp(buf, "BSS ", 4) == 0) {
  3831. reply_len = wpa_supplicant_ctrl_iface_bss(
  3832. wpa_s, buf + 4, reply, reply_size);
  3833. #ifdef CONFIG_AP
  3834. } else if (os_strcmp(buf, "STA-FIRST") == 0) {
  3835. reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
  3836. } else if (os_strncmp(buf, "STA ", 4) == 0) {
  3837. reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
  3838. reply_size);
  3839. } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
  3840. reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
  3841. reply_size);
  3842. } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
  3843. if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
  3844. reply_len = -1;
  3845. } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
  3846. if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
  3847. reply_len = -1;
  3848. #endif /* CONFIG_AP */
  3849. } else if (os_strcmp(buf, "SUSPEND") == 0) {
  3850. wpas_notify_suspend(wpa_s->global);
  3851. } else if (os_strcmp(buf, "RESUME") == 0) {
  3852. wpas_notify_resume(wpa_s->global);
  3853. } else if (os_strcmp(buf, "DROP_SA") == 0) {
  3854. wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
  3855. } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
  3856. if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
  3857. reply_len = -1;
  3858. } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
  3859. if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16))
  3860. reply_len = -1;
  3861. } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
  3862. if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
  3863. reply_len = -1;
  3864. } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
  3865. if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
  3866. buf + 17))
  3867. reply_len = -1;
  3868. #ifdef CONFIG_TDLS
  3869. } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
  3870. if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
  3871. reply_len = -1;
  3872. } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
  3873. if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
  3874. reply_len = -1;
  3875. } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
  3876. if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
  3877. reply_len = -1;
  3878. #endif /* CONFIG_TDLS */
  3879. } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
  3880. reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
  3881. reply_size);
  3882. #ifdef CONFIG_AUTOSCAN
  3883. } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
  3884. if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
  3885. reply_len = -1;
  3886. #endif /* CONFIG_AUTOSCAN */
  3887. } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
  3888. eapol_sm_request_reauth(wpa_s->eapol);
  3889. } else {
  3890. os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
  3891. reply_len = 16;
  3892. }
  3893. if (reply_len < 0) {
  3894. os_memcpy(reply, "FAIL\n", 5);
  3895. reply_len = 5;
  3896. }
  3897. if (ctrl_rsp)
  3898. eapol_sm_notify_ctrl_response(wpa_s->eapol);
  3899. *resp_len = reply_len;
  3900. return reply;
  3901. }
  3902. static int wpa_supplicant_global_iface_add(struct wpa_global *global,
  3903. char *cmd)
  3904. {
  3905. struct wpa_interface iface;
  3906. char *pos;
  3907. /*
  3908. * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
  3909. * TAB<bridge_ifname>
  3910. */
  3911. wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
  3912. os_memset(&iface, 0, sizeof(iface));
  3913. do {
  3914. iface.ifname = pos = cmd;
  3915. pos = os_strchr(pos, '\t');
  3916. if (pos)
  3917. *pos++ = '\0';
  3918. if (iface.ifname[0] == '\0')
  3919. return -1;
  3920. if (pos == NULL)
  3921. break;
  3922. iface.confname = pos;
  3923. pos = os_strchr(pos, '\t');
  3924. if (pos)
  3925. *pos++ = '\0';
  3926. if (iface.confname[0] == '\0')
  3927. iface.confname = NULL;
  3928. if (pos == NULL)
  3929. break;
  3930. iface.driver = pos;
  3931. pos = os_strchr(pos, '\t');
  3932. if (pos)
  3933. *pos++ = '\0';
  3934. if (iface.driver[0] == '\0')
  3935. iface.driver = NULL;
  3936. if (pos == NULL)
  3937. break;
  3938. iface.ctrl_interface = pos;
  3939. pos = os_strchr(pos, '\t');
  3940. if (pos)
  3941. *pos++ = '\0';
  3942. if (iface.ctrl_interface[0] == '\0')
  3943. iface.ctrl_interface = NULL;
  3944. if (pos == NULL)
  3945. break;
  3946. iface.driver_param = pos;
  3947. pos = os_strchr(pos, '\t');
  3948. if (pos)
  3949. *pos++ = '\0';
  3950. if (iface.driver_param[0] == '\0')
  3951. iface.driver_param = NULL;
  3952. if (pos == NULL)
  3953. break;
  3954. iface.bridge_ifname = pos;
  3955. pos = os_strchr(pos, '\t');
  3956. if (pos)
  3957. *pos++ = '\0';
  3958. if (iface.bridge_ifname[0] == '\0')
  3959. iface.bridge_ifname = NULL;
  3960. if (pos == NULL)
  3961. break;
  3962. } while (0);
  3963. if (wpa_supplicant_get_iface(global, iface.ifname))
  3964. return -1;
  3965. return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
  3966. }
  3967. static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
  3968. char *cmd)
  3969. {
  3970. struct wpa_supplicant *wpa_s;
  3971. wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
  3972. wpa_s = wpa_supplicant_get_iface(global, cmd);
  3973. if (wpa_s == NULL)
  3974. return -1;
  3975. return wpa_supplicant_remove_iface(global, wpa_s, 0);
  3976. }
  3977. static void wpa_free_iface_info(struct wpa_interface_info *iface)
  3978. {
  3979. struct wpa_interface_info *prev;
  3980. while (iface) {
  3981. prev = iface;
  3982. iface = iface->next;
  3983. os_free(prev->ifname);
  3984. os_free(prev->desc);
  3985. os_free(prev);
  3986. }
  3987. }
  3988. static int wpa_supplicant_global_iface_list(struct wpa_global *global,
  3989. char *buf, int len)
  3990. {
  3991. int i, res;
  3992. struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
  3993. char *pos, *end;
  3994. for (i = 0; wpa_drivers[i]; i++) {
  3995. struct wpa_driver_ops *drv = wpa_drivers[i];
  3996. if (drv->get_interfaces == NULL)
  3997. continue;
  3998. tmp = drv->get_interfaces(global->drv_priv[i]);
  3999. if (tmp == NULL)
  4000. continue;
  4001. if (last == NULL)
  4002. iface = last = tmp;
  4003. else
  4004. last->next = tmp;
  4005. while (last->next)
  4006. last = last->next;
  4007. }
  4008. pos = buf;
  4009. end = buf + len;
  4010. for (tmp = iface; tmp; tmp = tmp->next) {
  4011. res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
  4012. tmp->drv_name, tmp->ifname,
  4013. tmp->desc ? tmp->desc : "");
  4014. if (res < 0 || res >= end - pos) {
  4015. *pos = '\0';
  4016. break;
  4017. }
  4018. pos += res;
  4019. }
  4020. wpa_free_iface_info(iface);
  4021. return pos - buf;
  4022. }
  4023. static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
  4024. char *buf, int len)
  4025. {
  4026. int res;
  4027. char *pos, *end;
  4028. struct wpa_supplicant *wpa_s;
  4029. wpa_s = global->ifaces;
  4030. pos = buf;
  4031. end = buf + len;
  4032. while (wpa_s) {
  4033. res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
  4034. if (res < 0 || res >= end - pos) {
  4035. *pos = '\0';
  4036. break;
  4037. }
  4038. pos += res;
  4039. wpa_s = wpa_s->next;
  4040. }
  4041. return pos - buf;
  4042. }
  4043. char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
  4044. char *buf, size_t *resp_len)
  4045. {
  4046. char *reply;
  4047. const int reply_size = 2048;
  4048. int reply_len;
  4049. int level = MSG_DEBUG;
  4050. if (os_strcmp(buf, "PING") == 0)
  4051. level = MSG_EXCESSIVE;
  4052. wpa_hexdump_ascii(level, "RX global ctrl_iface",
  4053. (const u8 *) buf, os_strlen(buf));
  4054. reply = os_malloc(reply_size);
  4055. if (reply == NULL) {
  4056. *resp_len = 1;
  4057. return NULL;
  4058. }
  4059. os_memcpy(reply, "OK\n", 3);
  4060. reply_len = 3;
  4061. if (os_strcmp(buf, "PING") == 0) {
  4062. os_memcpy(reply, "PONG\n", 5);
  4063. reply_len = 5;
  4064. } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
  4065. if (wpa_supplicant_global_iface_add(global, buf + 14))
  4066. reply_len = -1;
  4067. } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
  4068. if (wpa_supplicant_global_iface_remove(global, buf + 17))
  4069. reply_len = -1;
  4070. } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
  4071. reply_len = wpa_supplicant_global_iface_list(
  4072. global, reply, reply_size);
  4073. } else if (os_strcmp(buf, "INTERFACES") == 0) {
  4074. reply_len = wpa_supplicant_global_iface_interfaces(
  4075. global, reply, reply_size);
  4076. } else if (os_strcmp(buf, "TERMINATE") == 0) {
  4077. wpa_supplicant_terminate_proc(global);
  4078. } else if (os_strcmp(buf, "SUSPEND") == 0) {
  4079. wpas_notify_suspend(global);
  4080. } else if (os_strcmp(buf, "RESUME") == 0) {
  4081. wpas_notify_resume(global);
  4082. } else {
  4083. os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
  4084. reply_len = 16;
  4085. }
  4086. if (reply_len < 0) {
  4087. os_memcpy(reply, "FAIL\n", 5);
  4088. reply_len = 5;
  4089. }
  4090. *resp_len = reply_len;
  4091. return reply;
  4092. }