dbus_new.c 119 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570
  1. /*
  2. * WPA Supplicant / dbus-based control interface
  3. * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
  4. * Copyright (c) 2009-2010, Witold Sowa <witold.sowa@gmail.com>
  5. * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
  6. *
  7. * This software may be distributed under the terms of the BSD license.
  8. * See README for more details.
  9. */
  10. #include "includes.h"
  11. #include "common.h"
  12. #include "common/ieee802_11_defs.h"
  13. #include "wps/wps.h"
  14. #include "../config.h"
  15. #include "../wpa_supplicant_i.h"
  16. #include "../bss.h"
  17. #include "../wpas_glue.h"
  18. #include "dbus_new_helpers.h"
  19. #include "dbus_dict_helpers.h"
  20. #include "dbus_new.h"
  21. #include "dbus_new_handlers.h"
  22. #include "dbus_common_i.h"
  23. #include "dbus_new_handlers_p2p.h"
  24. #include "p2p/p2p.h"
  25. #include "../p2p_supplicant.h"
  26. #ifdef CONFIG_AP /* until needed by something else */
  27. /*
  28. * NameOwnerChanged handling
  29. *
  30. * Some services we provide allow an application to register for
  31. * a signal that it needs. While it can also unregister, we must
  32. * be prepared for the case where the application simply crashes
  33. * and thus doesn't clean up properly. The way to handle this in
  34. * DBus is to register for the NameOwnerChanged signal which will
  35. * signal an owner change to NULL if the peer closes the socket
  36. * for whatever reason.
  37. *
  38. * Handle this signal via a filter function whenever necessary.
  39. * The code below also handles refcounting in case in the future
  40. * there will be multiple instances of this subscription scheme.
  41. */
  42. static const char wpas_dbus_noc_filter_str[] =
  43. "interface=org.freedesktop.DBus,member=NameOwnerChanged";
  44. static DBusHandlerResult noc_filter(DBusConnection *conn,
  45. DBusMessage *message, void *data)
  46. {
  47. struct wpas_dbus_priv *priv = data;
  48. if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_SIGNAL)
  49. return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
  50. if (dbus_message_is_signal(message, DBUS_INTERFACE_DBUS,
  51. "NameOwnerChanged")) {
  52. const char *name;
  53. const char *prev_owner;
  54. const char *new_owner;
  55. DBusError derr;
  56. struct wpa_supplicant *wpa_s;
  57. dbus_error_init(&derr);
  58. if (!dbus_message_get_args(message, &derr,
  59. DBUS_TYPE_STRING, &name,
  60. DBUS_TYPE_STRING, &prev_owner,
  61. DBUS_TYPE_STRING, &new_owner,
  62. DBUS_TYPE_INVALID)) {
  63. /* Ignore this error */
  64. dbus_error_free(&derr);
  65. return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
  66. }
  67. for (wpa_s = priv->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
  68. if (wpa_s->preq_notify_peer != NULL &&
  69. os_strcmp(name, wpa_s->preq_notify_peer) == 0 &&
  70. (new_owner == NULL || os_strlen(new_owner) == 0)) {
  71. /* probe request owner disconnected */
  72. os_free(wpa_s->preq_notify_peer);
  73. wpa_s->preq_notify_peer = NULL;
  74. wpas_dbus_unsubscribe_noc(priv);
  75. }
  76. }
  77. }
  78. return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
  79. }
  80. void wpas_dbus_subscribe_noc(struct wpas_dbus_priv *priv)
  81. {
  82. priv->dbus_noc_refcnt++;
  83. if (priv->dbus_noc_refcnt > 1)
  84. return;
  85. if (!dbus_connection_add_filter(priv->con, noc_filter, priv, NULL)) {
  86. wpa_printf(MSG_ERROR, "dbus: failed to add filter");
  87. return;
  88. }
  89. dbus_bus_add_match(priv->con, wpas_dbus_noc_filter_str, NULL);
  90. }
  91. void wpas_dbus_unsubscribe_noc(struct wpas_dbus_priv *priv)
  92. {
  93. priv->dbus_noc_refcnt--;
  94. if (priv->dbus_noc_refcnt > 0)
  95. return;
  96. dbus_bus_remove_match(priv->con, wpas_dbus_noc_filter_str, NULL);
  97. dbus_connection_remove_filter(priv->con, noc_filter, priv);
  98. }
  99. #endif /* CONFIG_AP */
  100. /**
  101. * wpas_dbus_signal_interface - Send a interface related event signal
  102. * @wpa_s: %wpa_supplicant network interface data
  103. * @sig_name: signal name - InterfaceAdded or InterfaceRemoved
  104. * @properties: Whether to add second argument with object properties
  105. *
  106. * Notify listeners about event related with interface
  107. */
  108. static void wpas_dbus_signal_interface(struct wpa_supplicant *wpa_s,
  109. const char *sig_name, int properties)
  110. {
  111. struct wpas_dbus_priv *iface;
  112. DBusMessage *msg;
  113. DBusMessageIter iter;
  114. iface = wpa_s->global->dbus;
  115. /* Do nothing if the control interface is not turned on */
  116. if (iface == NULL || !wpa_s->dbus_new_path)
  117. return;
  118. msg = dbus_message_new_signal(WPAS_DBUS_NEW_PATH,
  119. WPAS_DBUS_NEW_INTERFACE, sig_name);
  120. if (msg == NULL)
  121. return;
  122. dbus_message_iter_init_append(msg, &iter);
  123. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  124. &wpa_s->dbus_new_path) ||
  125. (properties &&
  126. !wpa_dbus_get_object_properties(
  127. iface, wpa_s->dbus_new_path,
  128. WPAS_DBUS_NEW_IFACE_INTERFACE, &iter)))
  129. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  130. else
  131. dbus_connection_send(iface->con, msg, NULL);
  132. dbus_message_unref(msg);
  133. }
  134. /**
  135. * wpas_dbus_signal_interface_added - Send a interface created signal
  136. * @wpa_s: %wpa_supplicant network interface data
  137. *
  138. * Notify listeners about creating new interface
  139. */
  140. static void wpas_dbus_signal_interface_added(struct wpa_supplicant *wpa_s)
  141. {
  142. wpas_dbus_signal_interface(wpa_s, "InterfaceAdded", TRUE);
  143. }
  144. /**
  145. * wpas_dbus_signal_interface_removed - Send a interface removed signal
  146. * @wpa_s: %wpa_supplicant network interface data
  147. *
  148. * Notify listeners about removing interface
  149. */
  150. static void wpas_dbus_signal_interface_removed(struct wpa_supplicant *wpa_s)
  151. {
  152. wpas_dbus_signal_interface(wpa_s, "InterfaceRemoved", FALSE);
  153. }
  154. /**
  155. * wpas_dbus_signal_scan_done - send scan done signal
  156. * @wpa_s: %wpa_supplicant network interface data
  157. * @success: indicates if scanning succeed or failed
  158. *
  159. * Notify listeners about finishing a scan
  160. */
  161. void wpas_dbus_signal_scan_done(struct wpa_supplicant *wpa_s, int success)
  162. {
  163. struct wpas_dbus_priv *iface;
  164. DBusMessage *msg;
  165. dbus_bool_t succ;
  166. iface = wpa_s->global->dbus;
  167. /* Do nothing if the control interface is not turned on */
  168. if (iface == NULL || !wpa_s->dbus_new_path)
  169. return;
  170. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  171. WPAS_DBUS_NEW_IFACE_INTERFACE,
  172. "ScanDone");
  173. if (msg == NULL)
  174. return;
  175. succ = success ? TRUE : FALSE;
  176. if (dbus_message_append_args(msg, DBUS_TYPE_BOOLEAN, &succ,
  177. DBUS_TYPE_INVALID))
  178. dbus_connection_send(iface->con, msg, NULL);
  179. else
  180. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  181. dbus_message_unref(msg);
  182. }
  183. /**
  184. * wpas_dbus_signal_bss - Send a BSS related event signal
  185. * @wpa_s: %wpa_supplicant network interface data
  186. * @bss_obj_path: BSS object path
  187. * @sig_name: signal name - BSSAdded or BSSRemoved
  188. * @properties: Whether to add second argument with object properties
  189. *
  190. * Notify listeners about event related with BSS
  191. */
  192. static void wpas_dbus_signal_bss(struct wpa_supplicant *wpa_s,
  193. const char *bss_obj_path,
  194. const char *sig_name, int properties)
  195. {
  196. struct wpas_dbus_priv *iface;
  197. DBusMessage *msg;
  198. DBusMessageIter iter;
  199. iface = wpa_s->global->dbus;
  200. /* Do nothing if the control interface is not turned on */
  201. if (iface == NULL || !wpa_s->dbus_new_path)
  202. return;
  203. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  204. WPAS_DBUS_NEW_IFACE_INTERFACE,
  205. sig_name);
  206. if (msg == NULL)
  207. return;
  208. dbus_message_iter_init_append(msg, &iter);
  209. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  210. &bss_obj_path) ||
  211. (properties &&
  212. !wpa_dbus_get_object_properties(iface, bss_obj_path,
  213. WPAS_DBUS_NEW_IFACE_BSS,
  214. &iter)))
  215. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  216. else
  217. dbus_connection_send(iface->con, msg, NULL);
  218. dbus_message_unref(msg);
  219. }
  220. /**
  221. * wpas_dbus_signal_bss_added - Send a BSS added signal
  222. * @wpa_s: %wpa_supplicant network interface data
  223. * @bss_obj_path: new BSS object path
  224. *
  225. * Notify listeners about adding new BSS
  226. */
  227. static void wpas_dbus_signal_bss_added(struct wpa_supplicant *wpa_s,
  228. const char *bss_obj_path)
  229. {
  230. wpas_dbus_signal_bss(wpa_s, bss_obj_path, "BSSAdded", TRUE);
  231. }
  232. /**
  233. * wpas_dbus_signal_bss_removed - Send a BSS removed signal
  234. * @wpa_s: %wpa_supplicant network interface data
  235. * @bss_obj_path: BSS object path
  236. *
  237. * Notify listeners about removing BSS
  238. */
  239. static void wpas_dbus_signal_bss_removed(struct wpa_supplicant *wpa_s,
  240. const char *bss_obj_path)
  241. {
  242. wpas_dbus_signal_bss(wpa_s, bss_obj_path, "BSSRemoved", FALSE);
  243. }
  244. /**
  245. * wpas_dbus_signal_blob - Send a blob related event signal
  246. * @wpa_s: %wpa_supplicant network interface data
  247. * @name: blob name
  248. * @sig_name: signal name - BlobAdded or BlobRemoved
  249. *
  250. * Notify listeners about event related with blob
  251. */
  252. static void wpas_dbus_signal_blob(struct wpa_supplicant *wpa_s,
  253. const char *name, const char *sig_name)
  254. {
  255. struct wpas_dbus_priv *iface;
  256. DBusMessage *msg;
  257. iface = wpa_s->global->dbus;
  258. /* Do nothing if the control interface is not turned on */
  259. if (iface == NULL || !wpa_s->dbus_new_path)
  260. return;
  261. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  262. WPAS_DBUS_NEW_IFACE_INTERFACE,
  263. sig_name);
  264. if (msg == NULL)
  265. return;
  266. if (dbus_message_append_args(msg, DBUS_TYPE_STRING, &name,
  267. DBUS_TYPE_INVALID))
  268. dbus_connection_send(iface->con, msg, NULL);
  269. else
  270. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  271. dbus_message_unref(msg);
  272. }
  273. /**
  274. * wpas_dbus_signal_blob_added - Send a blob added signal
  275. * @wpa_s: %wpa_supplicant network interface data
  276. * @name: blob name
  277. *
  278. * Notify listeners about adding a new blob
  279. */
  280. void wpas_dbus_signal_blob_added(struct wpa_supplicant *wpa_s,
  281. const char *name)
  282. {
  283. wpas_dbus_signal_blob(wpa_s, name, "BlobAdded");
  284. }
  285. /**
  286. * wpas_dbus_signal_blob_removed - Send a blob removed signal
  287. * @wpa_s: %wpa_supplicant network interface data
  288. * @name: blob name
  289. *
  290. * Notify listeners about removing blob
  291. */
  292. void wpas_dbus_signal_blob_removed(struct wpa_supplicant *wpa_s,
  293. const char *name)
  294. {
  295. wpas_dbus_signal_blob(wpa_s, name, "BlobRemoved");
  296. }
  297. /**
  298. * wpas_dbus_signal_network - Send a network related event signal
  299. * @wpa_s: %wpa_supplicant network interface data
  300. * @id: new network id
  301. * @sig_name: signal name - NetworkAdded, NetworkRemoved or NetworkSelected
  302. * @properties: determines if add second argument with object properties
  303. *
  304. * Notify listeners about event related with configured network
  305. */
  306. static void wpas_dbus_signal_network(struct wpa_supplicant *wpa_s,
  307. int id, const char *sig_name,
  308. int properties)
  309. {
  310. struct wpas_dbus_priv *iface;
  311. DBusMessage *msg;
  312. DBusMessageIter iter;
  313. char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  314. iface = wpa_s->global->dbus;
  315. /* Do nothing if the control interface is not turned on */
  316. if (iface == NULL || !wpa_s->dbus_new_path)
  317. return;
  318. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  319. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  320. wpa_s->dbus_new_path, id);
  321. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  322. WPAS_DBUS_NEW_IFACE_INTERFACE,
  323. sig_name);
  324. if (msg == NULL)
  325. return;
  326. dbus_message_iter_init_append(msg, &iter);
  327. path = net_obj_path;
  328. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  329. &path) ||
  330. (properties &&
  331. !wpa_dbus_get_object_properties(
  332. iface, net_obj_path, WPAS_DBUS_NEW_IFACE_NETWORK,
  333. &iter)))
  334. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  335. else
  336. dbus_connection_send(iface->con, msg, NULL);
  337. dbus_message_unref(msg);
  338. }
  339. /**
  340. * wpas_dbus_signal_network_added - Send a network added signal
  341. * @wpa_s: %wpa_supplicant network interface data
  342. * @id: new network id
  343. *
  344. * Notify listeners about adding new network
  345. */
  346. static void wpas_dbus_signal_network_added(struct wpa_supplicant *wpa_s,
  347. int id)
  348. {
  349. wpas_dbus_signal_network(wpa_s, id, "NetworkAdded", TRUE);
  350. }
  351. /**
  352. * wpas_dbus_signal_network_removed - Send a network removed signal
  353. * @wpa_s: %wpa_supplicant network interface data
  354. * @id: network id
  355. *
  356. * Notify listeners about removing a network
  357. */
  358. static void wpas_dbus_signal_network_removed(struct wpa_supplicant *wpa_s,
  359. int id)
  360. {
  361. wpas_dbus_signal_network(wpa_s, id, "NetworkRemoved", FALSE);
  362. }
  363. /**
  364. * wpas_dbus_signal_network_selected - Send a network selected signal
  365. * @wpa_s: %wpa_supplicant network interface data
  366. * @id: network id
  367. *
  368. * Notify listeners about selecting a network
  369. */
  370. void wpas_dbus_signal_network_selected(struct wpa_supplicant *wpa_s, int id)
  371. {
  372. wpas_dbus_signal_network(wpa_s, id, "NetworkSelected", FALSE);
  373. }
  374. /**
  375. * wpas_dbus_signal_network_request - Indicate that additional information
  376. * (EAP password, etc.) is required to complete the association to this SSID
  377. * @wpa_s: %wpa_supplicant network interface data
  378. * @rtype: The specific additional information required
  379. * @default_text: Optional description of required information
  380. *
  381. * Request additional information or passwords to complete an association
  382. * request.
  383. */
  384. void wpas_dbus_signal_network_request(struct wpa_supplicant *wpa_s,
  385. struct wpa_ssid *ssid,
  386. enum wpa_ctrl_req_type rtype,
  387. const char *default_txt)
  388. {
  389. struct wpas_dbus_priv *iface;
  390. DBusMessage *msg;
  391. DBusMessageIter iter;
  392. char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  393. const char *field, *txt = NULL, *net_ptr;
  394. iface = wpa_s->global->dbus;
  395. /* Do nothing if the control interface is not turned on */
  396. if (iface == NULL || !wpa_s->dbus_new_path)
  397. return;
  398. field = wpa_supplicant_ctrl_req_to_string(rtype, default_txt, &txt);
  399. if (field == NULL)
  400. return;
  401. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  402. WPAS_DBUS_NEW_IFACE_INTERFACE,
  403. "NetworkRequest");
  404. if (msg == NULL)
  405. return;
  406. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  407. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  408. wpa_s->dbus_new_path, ssid->id);
  409. net_ptr = &net_obj_path[0];
  410. dbus_message_iter_init_append(msg, &iter);
  411. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  412. &net_ptr) ||
  413. !dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &field) ||
  414. !dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &txt))
  415. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  416. else
  417. dbus_connection_send(iface->con, msg, NULL);
  418. dbus_message_unref(msg);
  419. }
  420. /**
  421. * wpas_dbus_signal_network_enabled_changed - Signals Enabled property changes
  422. * @wpa_s: %wpa_supplicant network interface data
  423. * @ssid: configured network which Enabled property has changed
  424. *
  425. * Sends PropertyChanged signals containing new value of Enabled property
  426. * for specified network
  427. */
  428. void wpas_dbus_signal_network_enabled_changed(struct wpa_supplicant *wpa_s,
  429. struct wpa_ssid *ssid)
  430. {
  431. char path[WPAS_DBUS_OBJECT_PATH_MAX];
  432. if (!wpa_s->dbus_new_path)
  433. return;
  434. os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
  435. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
  436. wpa_s->dbus_new_path, ssid->id);
  437. wpa_dbus_mark_property_changed(wpa_s->global->dbus, path,
  438. WPAS_DBUS_NEW_IFACE_NETWORK, "Enabled");
  439. }
  440. #ifdef CONFIG_WPS
  441. /**
  442. * wpas_dbus_signal_wps_event_pbc_overlap - Signals PBC overlap WPS event
  443. * @wpa_s: %wpa_supplicant network interface data
  444. *
  445. * Sends Event dbus signal with name "pbc-overlap" and empty dict as arguments
  446. */
  447. void wpas_dbus_signal_wps_event_pbc_overlap(struct wpa_supplicant *wpa_s)
  448. {
  449. DBusMessage *msg;
  450. DBusMessageIter iter, dict_iter;
  451. struct wpas_dbus_priv *iface;
  452. char *key = "pbc-overlap";
  453. iface = wpa_s->global->dbus;
  454. /* Do nothing if the control interface is not turned on */
  455. if (iface == NULL || !wpa_s->dbus_new_path)
  456. return;
  457. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  458. WPAS_DBUS_NEW_IFACE_WPS, "Event");
  459. if (msg == NULL)
  460. return;
  461. dbus_message_iter_init_append(msg, &iter);
  462. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
  463. !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  464. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  465. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  466. else
  467. dbus_connection_send(iface->con, msg, NULL);
  468. dbus_message_unref(msg);
  469. }
  470. /**
  471. * wpas_dbus_signal_wps_event_success - Signals Success WPS event
  472. * @wpa_s: %wpa_supplicant network interface data
  473. *
  474. * Sends Event dbus signal with name "success" and empty dict as arguments
  475. */
  476. void wpas_dbus_signal_wps_event_success(struct wpa_supplicant *wpa_s)
  477. {
  478. DBusMessage *msg;
  479. DBusMessageIter iter, dict_iter;
  480. struct wpas_dbus_priv *iface;
  481. char *key = "success";
  482. iface = wpa_s->global->dbus;
  483. /* Do nothing if the control interface is not turned on */
  484. if (iface == NULL || !wpa_s->dbus_new_path)
  485. return;
  486. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  487. WPAS_DBUS_NEW_IFACE_WPS, "Event");
  488. if (msg == NULL)
  489. return;
  490. dbus_message_iter_init_append(msg, &iter);
  491. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
  492. !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  493. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  494. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  495. else
  496. dbus_connection_send(iface->con, msg, NULL);
  497. dbus_message_unref(msg);
  498. }
  499. /**
  500. * wpas_dbus_signal_wps_event_fail - Signals Fail WPS event
  501. * @wpa_s: %wpa_supplicant network interface data
  502. * @fail: WPS failure information
  503. *
  504. * Sends Event dbus signal with name "fail" and dictionary containing
  505. * "msg field with fail message number (int32) as arguments
  506. */
  507. void wpas_dbus_signal_wps_event_fail(struct wpa_supplicant *wpa_s,
  508. struct wps_event_fail *fail)
  509. {
  510. DBusMessage *msg;
  511. DBusMessageIter iter, dict_iter;
  512. struct wpas_dbus_priv *iface;
  513. char *key = "fail";
  514. iface = wpa_s->global->dbus;
  515. /* Do nothing if the control interface is not turned on */
  516. if (iface == NULL || !wpa_s->dbus_new_path)
  517. return;
  518. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  519. WPAS_DBUS_NEW_IFACE_WPS, "Event");
  520. if (msg == NULL)
  521. return;
  522. dbus_message_iter_init_append(msg, &iter);
  523. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
  524. !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  525. !wpa_dbus_dict_append_int32(&dict_iter, "msg", fail->msg) ||
  526. !wpa_dbus_dict_append_int32(&dict_iter, "config_error",
  527. fail->config_error) ||
  528. !wpa_dbus_dict_append_int32(&dict_iter, "error_indication",
  529. fail->error_indication) ||
  530. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  531. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  532. else
  533. dbus_connection_send(iface->con, msg, NULL);
  534. dbus_message_unref(msg);
  535. }
  536. /**
  537. * wpas_dbus_signal_wps_event_m2d - Signals M2D WPS event
  538. * @wpa_s: %wpa_supplicant network interface data
  539. * @m2d: M2D event data information
  540. *
  541. * Sends Event dbus signal with name "m2d" and dictionary containing
  542. * fields of wps_event_m2d structure.
  543. */
  544. void wpas_dbus_signal_wps_event_m2d(struct wpa_supplicant *wpa_s,
  545. struct wps_event_m2d *m2d)
  546. {
  547. DBusMessage *msg;
  548. DBusMessageIter iter, dict_iter;
  549. struct wpas_dbus_priv *iface;
  550. char *key = "m2d";
  551. iface = wpa_s->global->dbus;
  552. /* Do nothing if the control interface is not turned on */
  553. if (iface == NULL || !wpa_s->dbus_new_path)
  554. return;
  555. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  556. WPAS_DBUS_NEW_IFACE_WPS, "Event");
  557. if (msg == NULL)
  558. return;
  559. dbus_message_iter_init_append(msg, &iter);
  560. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
  561. !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  562. !wpa_dbus_dict_append_uint16(&dict_iter, "config_methods",
  563. m2d->config_methods) ||
  564. !wpa_dbus_dict_append_byte_array(&dict_iter, "manufacturer",
  565. (const char *) m2d->manufacturer,
  566. m2d->manufacturer_len) ||
  567. !wpa_dbus_dict_append_byte_array(&dict_iter, "model_name",
  568. (const char *) m2d->model_name,
  569. m2d->model_name_len) ||
  570. !wpa_dbus_dict_append_byte_array(&dict_iter, "model_number",
  571. (const char *) m2d->model_number,
  572. m2d->model_number_len) ||
  573. !wpa_dbus_dict_append_byte_array(&dict_iter, "serial_number",
  574. (const char *)
  575. m2d->serial_number,
  576. m2d->serial_number_len) ||
  577. !wpa_dbus_dict_append_byte_array(&dict_iter, "dev_name",
  578. (const char *) m2d->dev_name,
  579. m2d->dev_name_len) ||
  580. !wpa_dbus_dict_append_byte_array(&dict_iter, "primary_dev_type",
  581. (const char *)
  582. m2d->primary_dev_type, 8) ||
  583. !wpa_dbus_dict_append_uint16(&dict_iter, "config_error",
  584. m2d->config_error) ||
  585. !wpa_dbus_dict_append_uint16(&dict_iter, "dev_password_id",
  586. m2d->dev_password_id) ||
  587. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  588. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  589. else
  590. dbus_connection_send(iface->con, msg, NULL);
  591. dbus_message_unref(msg);
  592. }
  593. /**
  594. * wpas_dbus_signal_wps_cred - Signals new credentials
  595. * @wpa_s: %wpa_supplicant network interface data
  596. * @cred: WPS Credential information
  597. *
  598. * Sends signal with credentials in directory argument
  599. */
  600. void wpas_dbus_signal_wps_cred(struct wpa_supplicant *wpa_s,
  601. const struct wps_credential *cred)
  602. {
  603. DBusMessage *msg;
  604. DBusMessageIter iter, dict_iter;
  605. struct wpas_dbus_priv *iface;
  606. char *auth_type[5]; /* we have five possible authentication types */
  607. int at_num = 0;
  608. char *encr_type[3]; /* we have three possible encryption types */
  609. int et_num = 0;
  610. iface = wpa_s->global->dbus;
  611. /* Do nothing if the control interface is not turned on */
  612. if (iface == NULL || !wpa_s->dbus_new_path)
  613. return;
  614. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  615. WPAS_DBUS_NEW_IFACE_WPS,
  616. "Credentials");
  617. if (msg == NULL)
  618. return;
  619. dbus_message_iter_init_append(msg, &iter);
  620. if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
  621. goto nomem;
  622. if (cred->auth_type & WPS_AUTH_OPEN)
  623. auth_type[at_num++] = "open";
  624. if (cred->auth_type & WPS_AUTH_WPAPSK)
  625. auth_type[at_num++] = "wpa-psk";
  626. if (cred->auth_type & WPS_AUTH_WPA)
  627. auth_type[at_num++] = "wpa-eap";
  628. if (cred->auth_type & WPS_AUTH_WPA2)
  629. auth_type[at_num++] = "wpa2-eap";
  630. if (cred->auth_type & WPS_AUTH_WPA2PSK)
  631. auth_type[at_num++] = "wpa2-psk";
  632. if (cred->encr_type & WPS_ENCR_NONE)
  633. encr_type[et_num++] = "none";
  634. if (cred->encr_type & WPS_ENCR_TKIP)
  635. encr_type[et_num++] = "tkip";
  636. if (cred->encr_type & WPS_ENCR_AES)
  637. encr_type[et_num++] = "aes";
  638. if ((wpa_s->current_ssid &&
  639. !wpa_dbus_dict_append_byte_array(
  640. &dict_iter, "BSSID",
  641. (const char *) wpa_s->current_ssid->bssid, ETH_ALEN)) ||
  642. !wpa_dbus_dict_append_byte_array(&dict_iter, "SSID",
  643. (const char *) cred->ssid,
  644. cred->ssid_len) ||
  645. !wpa_dbus_dict_append_string_array(&dict_iter, "AuthType",
  646. (const char **) auth_type,
  647. at_num) ||
  648. !wpa_dbus_dict_append_string_array(&dict_iter, "EncrType",
  649. (const char **) encr_type,
  650. et_num) ||
  651. !wpa_dbus_dict_append_byte_array(&dict_iter, "Key",
  652. (const char *) cred->key,
  653. cred->key_len) ||
  654. !wpa_dbus_dict_append_uint32(&dict_iter, "KeyIndex",
  655. cred->key_idx) ||
  656. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  657. goto nomem;
  658. dbus_connection_send(iface->con, msg, NULL);
  659. nomem:
  660. dbus_message_unref(msg);
  661. }
  662. #endif /* CONFIG_WPS */
  663. #ifdef CONFIG_MESH
  664. void wpas_dbus_signal_mesh_group_started(struct wpa_supplicant *wpa_s,
  665. struct wpa_ssid *ssid)
  666. {
  667. struct wpas_dbus_priv *iface;
  668. DBusMessage *msg;
  669. DBusMessageIter iter, dict_iter;
  670. iface = wpa_s->global->dbus;
  671. /* Do nothing if the control interface is not turned on */
  672. if (!iface || !wpa_s->dbus_new_path)
  673. return;
  674. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  675. WPAS_DBUS_NEW_IFACE_MESH,
  676. "MeshGroupStarted");
  677. if (!msg)
  678. return;
  679. dbus_message_iter_init_append(msg, &iter);
  680. if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  681. !wpa_dbus_dict_append_byte_array(&dict_iter, "SSID",
  682. (const char *) ssid->ssid,
  683. ssid->ssid_len) ||
  684. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  685. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  686. else
  687. dbus_connection_send(iface->con, msg, NULL);
  688. dbus_message_unref(msg);
  689. }
  690. void wpas_dbus_signal_mesh_group_removed(struct wpa_supplicant *wpa_s,
  691. const u8 *meshid, u8 meshid_len,
  692. int reason)
  693. {
  694. struct wpas_dbus_priv *iface;
  695. DBusMessage *msg;
  696. DBusMessageIter iter, dict_iter;
  697. iface = wpa_s->global->dbus;
  698. /* Do nothing if the control interface is not turned on */
  699. if (!iface || !wpa_s->dbus_new_path)
  700. return;
  701. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  702. WPAS_DBUS_NEW_IFACE_MESH,
  703. "MeshGroupRemoved");
  704. if (!msg)
  705. return;
  706. dbus_message_iter_init_append(msg, &iter);
  707. if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  708. !wpa_dbus_dict_append_byte_array(&dict_iter, "SSID",
  709. (const char *) meshid,
  710. meshid_len) ||
  711. !wpa_dbus_dict_append_int32(&dict_iter, "DisconnectReason",
  712. reason) ||
  713. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  714. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  715. else
  716. dbus_connection_send(iface->con, msg, NULL);
  717. dbus_message_unref(msg);
  718. }
  719. void wpas_dbus_signal_mesh_peer_connected(struct wpa_supplicant *wpa_s,
  720. const u8 *peer_addr)
  721. {
  722. struct wpas_dbus_priv *iface;
  723. DBusMessage *msg;
  724. DBusMessageIter iter, dict_iter;
  725. iface = wpa_s->global->dbus;
  726. /* Do nothing if the control interface is not turned on */
  727. if (!iface || !wpa_s->dbus_new_path)
  728. return;
  729. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  730. WPAS_DBUS_NEW_IFACE_MESH,
  731. "MeshPeerConnected");
  732. if (!msg)
  733. return;
  734. dbus_message_iter_init_append(msg, &iter);
  735. if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  736. !wpa_dbus_dict_append_byte_array(&dict_iter, "PeerAddress",
  737. (const char *) peer_addr,
  738. ETH_ALEN) ||
  739. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  740. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  741. else
  742. dbus_connection_send(iface->con, msg, NULL);
  743. dbus_message_unref(msg);
  744. }
  745. #endif /* CONFIG_MESH */
  746. void wpas_dbus_signal_certification(struct wpa_supplicant *wpa_s,
  747. int depth, const char *subject,
  748. const char *altsubject[],
  749. int num_altsubject,
  750. const char *cert_hash,
  751. const struct wpabuf *cert)
  752. {
  753. struct wpas_dbus_priv *iface;
  754. DBusMessage *msg;
  755. DBusMessageIter iter, dict_iter;
  756. iface = wpa_s->global->dbus;
  757. /* Do nothing if the control interface is not turned on */
  758. if (iface == NULL || !wpa_s->dbus_new_path)
  759. return;
  760. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  761. WPAS_DBUS_NEW_IFACE_INTERFACE,
  762. "Certification");
  763. if (msg == NULL)
  764. return;
  765. dbus_message_iter_init_append(msg, &iter);
  766. if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  767. !wpa_dbus_dict_append_uint32(&dict_iter, "depth", depth) ||
  768. !wpa_dbus_dict_append_string(&dict_iter, "subject", subject) ||
  769. (altsubject && num_altsubject &&
  770. !wpa_dbus_dict_append_string_array(&dict_iter, "altsubject",
  771. altsubject, num_altsubject)) ||
  772. (cert_hash &&
  773. !wpa_dbus_dict_append_string(&dict_iter, "cert_hash",
  774. cert_hash)) ||
  775. (cert &&
  776. !wpa_dbus_dict_append_byte_array(&dict_iter, "cert",
  777. wpabuf_head(cert),
  778. wpabuf_len(cert))) ||
  779. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  780. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  781. else
  782. dbus_connection_send(iface->con, msg, NULL);
  783. dbus_message_unref(msg);
  784. }
  785. void wpas_dbus_signal_eap_status(struct wpa_supplicant *wpa_s,
  786. const char *status, const char *parameter)
  787. {
  788. struct wpas_dbus_priv *iface;
  789. DBusMessage *msg;
  790. DBusMessageIter iter;
  791. iface = wpa_s->global->dbus;
  792. /* Do nothing if the control interface is not turned on */
  793. if (iface == NULL || !wpa_s->dbus_new_path)
  794. return;
  795. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  796. WPAS_DBUS_NEW_IFACE_INTERFACE,
  797. "EAP");
  798. if (msg == NULL)
  799. return;
  800. dbus_message_iter_init_append(msg, &iter);
  801. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &status) ||
  802. !dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING,
  803. &parameter))
  804. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  805. else
  806. dbus_connection_send(iface->con, msg, NULL);
  807. dbus_message_unref(msg);
  808. }
  809. /**
  810. * wpas_dbus_signal_sta - Send a station related event signal
  811. * @wpa_s: %wpa_supplicant network interface data
  812. * @sta: station mac address
  813. * @sig_name: signal name - StaAuthorized or StaDeauthorized
  814. *
  815. * Notify listeners about event related with station
  816. */
  817. static void wpas_dbus_signal_sta(struct wpa_supplicant *wpa_s,
  818. const u8 *sta, const char *sig_name)
  819. {
  820. struct wpas_dbus_priv *iface;
  821. DBusMessage *msg;
  822. char sta_mac[WPAS_DBUS_OBJECT_PATH_MAX];
  823. char *dev_mac;
  824. os_snprintf(sta_mac, WPAS_DBUS_OBJECT_PATH_MAX, MACSTR, MAC2STR(sta));
  825. dev_mac = sta_mac;
  826. iface = wpa_s->global->dbus;
  827. /* Do nothing if the control interface is not turned on */
  828. if (iface == NULL || !wpa_s->dbus_new_path)
  829. return;
  830. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  831. WPAS_DBUS_NEW_IFACE_INTERFACE, sig_name);
  832. if (msg == NULL)
  833. return;
  834. if (dbus_message_append_args(msg, DBUS_TYPE_STRING, &dev_mac,
  835. DBUS_TYPE_INVALID))
  836. dbus_connection_send(iface->con, msg, NULL);
  837. else
  838. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  839. dbus_message_unref(msg);
  840. wpa_printf(MSG_DEBUG, "dbus: Station MAC address '%s' '%s'",
  841. sta_mac, sig_name);
  842. }
  843. /**
  844. * wpas_dbus_signal_sta_authorized - Send a STA authorized signal
  845. * @wpa_s: %wpa_supplicant network interface data
  846. * @sta: station mac address
  847. *
  848. * Notify listeners a new station has been authorized
  849. */
  850. void wpas_dbus_signal_sta_authorized(struct wpa_supplicant *wpa_s,
  851. const u8 *sta)
  852. {
  853. wpas_dbus_signal_sta(wpa_s, sta, "StaAuthorized");
  854. }
  855. /**
  856. * wpas_dbus_signal_sta_deauthorized - Send a STA deauthorized signal
  857. * @wpa_s: %wpa_supplicant network interface data
  858. * @sta: station mac address
  859. *
  860. * Notify listeners a station has been deauthorized
  861. */
  862. void wpas_dbus_signal_sta_deauthorized(struct wpa_supplicant *wpa_s,
  863. const u8 *sta)
  864. {
  865. wpas_dbus_signal_sta(wpa_s, sta, "StaDeauthorized");
  866. }
  867. #ifdef CONFIG_P2P
  868. /**
  869. * wpas_dbus_signal_p2p_group_removed - Signals P2P group was removed
  870. * @wpa_s: %wpa_supplicant network interface data
  871. * @role: role of this device (client or GO)
  872. * Sends signal with i/f name and role as string arguments
  873. */
  874. void wpas_dbus_signal_p2p_group_removed(struct wpa_supplicant *wpa_s,
  875. const char *role)
  876. {
  877. DBusMessage *msg;
  878. DBusMessageIter iter, dict_iter;
  879. struct wpas_dbus_priv *iface = wpa_s->global->dbus;
  880. struct wpa_supplicant *parent;
  881. /* Do nothing if the control interface is not turned on */
  882. if (iface == NULL)
  883. return;
  884. parent = wpa_s->parent;
  885. if (parent->p2p_mgmt)
  886. parent = parent->parent;
  887. if (!wpa_s->dbus_groupobj_path || !wpa_s->dbus_new_path ||
  888. !parent->dbus_new_path)
  889. return;
  890. msg = dbus_message_new_signal(parent->dbus_new_path,
  891. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  892. "GroupFinished");
  893. if (msg == NULL)
  894. return;
  895. dbus_message_iter_init_append(msg, &iter);
  896. if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  897. !wpa_dbus_dict_append_object_path(&dict_iter,
  898. "interface_object",
  899. wpa_s->dbus_new_path) ||
  900. !wpa_dbus_dict_append_string(&dict_iter, "role", role) ||
  901. !wpa_dbus_dict_append_object_path(&dict_iter, "group_object",
  902. wpa_s->dbus_groupobj_path) ||
  903. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  904. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  905. else
  906. dbus_connection_send(iface->con, msg, NULL);
  907. dbus_message_unref(msg);
  908. }
  909. /**
  910. * wpas_dbus_signal_p2p_provision_discovery - Signals various PD events
  911. *
  912. * @dev_addr - who sent the request or responded to our request.
  913. * @request - Will be 1 if request, 0 for response.
  914. * @status - valid only in case of response
  915. * @config_methods - wps config methods
  916. * @generated_pin - pin to be displayed in case of WPS_CONFIG_DISPLAY method
  917. *
  918. * Sends following provision discovery related events:
  919. * ProvisionDiscoveryRequestDisplayPin
  920. * ProvisionDiscoveryResponseDisplayPin
  921. * ProvisionDiscoveryRequestEnterPin
  922. * ProvisionDiscoveryResponseEnterPin
  923. * ProvisionDiscoveryPBCRequest
  924. * ProvisionDiscoveryPBCResponse
  925. *
  926. * TODO::
  927. * ProvisionDiscoveryFailure (timeout case)
  928. */
  929. void wpas_dbus_signal_p2p_provision_discovery(struct wpa_supplicant *wpa_s,
  930. const u8 *dev_addr, int request,
  931. enum p2p_prov_disc_status status,
  932. u16 config_methods,
  933. unsigned int generated_pin)
  934. {
  935. DBusMessage *msg;
  936. DBusMessageIter iter;
  937. struct wpas_dbus_priv *iface;
  938. char *_signal;
  939. int add_pin = 0;
  940. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  941. int error_ret = 1;
  942. char pin[9], *p_pin = NULL;
  943. iface = wpa_s->global->dbus;
  944. /* Do nothing if the control interface is not turned on */
  945. if (iface == NULL)
  946. return;
  947. if (wpa_s->p2p_mgmt)
  948. wpa_s = wpa_s->parent;
  949. if (!wpa_s->dbus_new_path)
  950. return;
  951. if (request || !status) {
  952. if (config_methods & WPS_CONFIG_DISPLAY)
  953. _signal = request ?
  954. "ProvisionDiscoveryRequestDisplayPin" :
  955. "ProvisionDiscoveryResponseEnterPin";
  956. else if (config_methods & WPS_CONFIG_KEYPAD)
  957. _signal = request ?
  958. "ProvisionDiscoveryRequestEnterPin" :
  959. "ProvisionDiscoveryResponseDisplayPin";
  960. else if (config_methods & WPS_CONFIG_PUSHBUTTON)
  961. _signal = request ? "ProvisionDiscoveryPBCRequest" :
  962. "ProvisionDiscoveryPBCResponse";
  963. else
  964. return; /* Unknown or un-supported method */
  965. } else {
  966. /* Explicit check for failure response */
  967. _signal = "ProvisionDiscoveryFailure";
  968. }
  969. add_pin = ((request && (config_methods & WPS_CONFIG_DISPLAY)) ||
  970. (!request && !status &&
  971. (config_methods & WPS_CONFIG_KEYPAD)));
  972. if (add_pin) {
  973. os_snprintf(pin, sizeof(pin), "%08d", generated_pin);
  974. p_pin = pin;
  975. }
  976. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  977. WPAS_DBUS_NEW_IFACE_P2PDEVICE, _signal);
  978. if (msg == NULL)
  979. return;
  980. /* Check if this is a known peer */
  981. if (!p2p_peer_known(wpa_s->global->p2p, dev_addr))
  982. goto error;
  983. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  984. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
  985. COMPACT_MACSTR,
  986. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  987. path = peer_obj_path;
  988. dbus_message_iter_init_append(msg, &iter);
  989. if (!dbus_message_iter_append_basic(&iter,
  990. DBUS_TYPE_OBJECT_PATH,
  991. &path))
  992. goto error;
  993. if (!request && status)
  994. /* Attach status to ProvisionDiscoveryFailure */
  995. error_ret = !dbus_message_iter_append_basic(&iter,
  996. DBUS_TYPE_INT32,
  997. &status);
  998. else
  999. error_ret = (add_pin &&
  1000. !dbus_message_iter_append_basic(&iter,
  1001. DBUS_TYPE_STRING,
  1002. &p_pin));
  1003. error:
  1004. if (!error_ret)
  1005. dbus_connection_send(iface->con, msg, NULL);
  1006. else
  1007. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1008. dbus_message_unref(msg);
  1009. }
  1010. /**
  1011. * wpas_dbus_signal_p2p_go_neg_req - Signal P2P GO Negotiation Request RX
  1012. * @wpa_s: %wpa_supplicant network interface data
  1013. * @src: Source address of the message triggering this notification
  1014. * @dev_passwd_id: WPS Device Password Id
  1015. * @go_intent: Peer's GO Intent value
  1016. *
  1017. * Sends signal to notify that a peer P2P Device is requesting group owner
  1018. * negotiation with us.
  1019. */
  1020. void wpas_dbus_signal_p2p_go_neg_req(struct wpa_supplicant *wpa_s,
  1021. const u8 *src, u16 dev_passwd_id,
  1022. u8 go_intent)
  1023. {
  1024. DBusMessage *msg;
  1025. DBusMessageIter iter;
  1026. struct wpas_dbus_priv *iface;
  1027. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  1028. iface = wpa_s->global->dbus;
  1029. /* Do nothing if the control interface is not turned on */
  1030. if (iface == NULL)
  1031. return;
  1032. if (wpa_s->p2p_mgmt)
  1033. wpa_s = wpa_s->parent;
  1034. if (!wpa_s->dbus_new_path)
  1035. return;
  1036. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1037. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  1038. wpa_s->dbus_new_path, MAC2STR(src));
  1039. path = peer_obj_path;
  1040. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1041. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1042. "GONegotiationRequest");
  1043. if (msg == NULL)
  1044. return;
  1045. dbus_message_iter_init_append(msg, &iter);
  1046. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  1047. &path) ||
  1048. !dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT16,
  1049. &dev_passwd_id) ||
  1050. !dbus_message_iter_append_basic(&iter, DBUS_TYPE_BYTE,
  1051. &go_intent))
  1052. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1053. else
  1054. dbus_connection_send(iface->con, msg, NULL);
  1055. dbus_message_unref(msg);
  1056. }
  1057. static int wpas_dbus_get_group_obj_path(struct wpa_supplicant *wpa_s,
  1058. const struct wpa_ssid *ssid,
  1059. char *group_obj_path)
  1060. {
  1061. char group_name[3];
  1062. if (!wpa_s->dbus_new_path ||
  1063. os_memcmp(ssid->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN))
  1064. return -1;
  1065. os_memcpy(group_name, ssid->ssid + P2P_WILDCARD_SSID_LEN, 2);
  1066. group_name[2] = '\0';
  1067. os_snprintf(group_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1068. "%s/" WPAS_DBUS_NEW_P2P_GROUPS_PART "/%s",
  1069. wpa_s->dbus_new_path, group_name);
  1070. return 0;
  1071. }
  1072. struct group_changed_data {
  1073. struct wpa_supplicant *wpa_s;
  1074. struct p2p_peer_info *info;
  1075. };
  1076. static int match_group_where_peer_is_client(struct p2p_group *group,
  1077. void *user_data)
  1078. {
  1079. struct group_changed_data *data = user_data;
  1080. const struct p2p_group_config *cfg;
  1081. struct wpa_supplicant *wpa_s_go;
  1082. if (!p2p_group_is_client_connected(group, data->info->p2p_device_addr))
  1083. return 1;
  1084. cfg = p2p_group_get_config(group);
  1085. wpa_s_go = wpas_get_p2p_go_iface(data->wpa_s, cfg->ssid,
  1086. cfg->ssid_len);
  1087. if (wpa_s_go != NULL && wpa_s_go == data->wpa_s) {
  1088. wpas_dbus_signal_peer_groups_changed(
  1089. data->wpa_s->p2pdev, data->info->p2p_device_addr);
  1090. return 0;
  1091. }
  1092. return 1;
  1093. }
  1094. static void signal_peer_groups_changed(struct p2p_peer_info *info,
  1095. void *user_data)
  1096. {
  1097. struct group_changed_data *data = user_data;
  1098. struct wpa_supplicant *wpa_s_go;
  1099. wpa_s_go = wpas_get_p2p_client_iface(data->wpa_s,
  1100. info->p2p_device_addr);
  1101. if (wpa_s_go != NULL && wpa_s_go == data->wpa_s) {
  1102. wpas_dbus_signal_peer_groups_changed(data->wpa_s->p2pdev,
  1103. info->p2p_device_addr);
  1104. return;
  1105. }
  1106. data->info = info;
  1107. p2p_loop_on_all_groups(data->wpa_s->global->p2p,
  1108. match_group_where_peer_is_client, data);
  1109. data->info = NULL;
  1110. }
  1111. static void peer_groups_changed(struct wpa_supplicant *wpa_s)
  1112. {
  1113. struct group_changed_data data;
  1114. os_memset(&data, 0, sizeof(data));
  1115. data.wpa_s = wpa_s;
  1116. p2p_loop_on_known_peers(wpa_s->global->p2p,
  1117. signal_peer_groups_changed, &data);
  1118. }
  1119. /**
  1120. * wpas_dbus_signal_p2p_group_started - Signals P2P group has
  1121. * started. Emitted when a group is successfully started
  1122. * irrespective of the role (client/GO) of the current device
  1123. *
  1124. * @wpa_s: %wpa_supplicant network interface data
  1125. * @client: this device is P2P client
  1126. * @persistent: 0 - non persistent group, 1 - persistent group
  1127. * @ip: When group role is client, it contains local IP address, netmask, and
  1128. * GO's IP address, if assigned; otherwise, NULL
  1129. */
  1130. void wpas_dbus_signal_p2p_group_started(struct wpa_supplicant *wpa_s,
  1131. int client, int persistent,
  1132. const u8 *ip)
  1133. {
  1134. DBusMessage *msg;
  1135. DBusMessageIter iter, dict_iter;
  1136. struct wpas_dbus_priv *iface;
  1137. struct wpa_supplicant *parent;
  1138. parent = wpa_s->parent;
  1139. if (parent->p2p_mgmt)
  1140. parent = parent->parent;
  1141. iface = parent->global->dbus;
  1142. /* Do nothing if the control interface is not turned on */
  1143. if (iface == NULL || !parent->dbus_new_path || !wpa_s->dbus_new_path)
  1144. return;
  1145. if (wpa_s->dbus_groupobj_path == NULL)
  1146. return;
  1147. /* New interface has been created for this group */
  1148. msg = dbus_message_new_signal(parent->dbus_new_path,
  1149. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1150. "GroupStarted");
  1151. if (msg == NULL)
  1152. return;
  1153. dbus_message_iter_init_append(msg, &iter);
  1154. /*
  1155. * In case the device supports creating a separate interface the
  1156. * DBus client will need to know the object path for the interface
  1157. * object this group was created on, so include it here.
  1158. */
  1159. if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  1160. !wpa_dbus_dict_append_object_path(&dict_iter,
  1161. "interface_object",
  1162. wpa_s->dbus_new_path) ||
  1163. !wpa_dbus_dict_append_string(&dict_iter, "role",
  1164. client ? "client" : "GO") ||
  1165. !wpa_dbus_dict_append_bool(&dict_iter, "persistent", persistent) ||
  1166. !wpa_dbus_dict_append_object_path(&dict_iter, "group_object",
  1167. wpa_s->dbus_groupobj_path) ||
  1168. (ip &&
  1169. (!wpa_dbus_dict_append_byte_array(&dict_iter, "IpAddr",
  1170. (char *) ip, 4) ||
  1171. !wpa_dbus_dict_append_byte_array(&dict_iter, "IpAddrMask",
  1172. (char *) ip + 4, 4) ||
  1173. !wpa_dbus_dict_append_byte_array(&dict_iter, "IpAddrGo",
  1174. (char *) ip + 8, 4))) ||
  1175. !wpa_dbus_dict_close_write(&iter, &dict_iter)) {
  1176. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1177. } else {
  1178. dbus_connection_send(iface->con, msg, NULL);
  1179. if (client)
  1180. peer_groups_changed(wpa_s);
  1181. }
  1182. dbus_message_unref(msg);
  1183. }
  1184. /**
  1185. * wpas_dbus_signal_p2p_go_neg_resp - Emit GONegotiation Success/Failure signal
  1186. * @wpa_s: %wpa_supplicant network interface data
  1187. * @res: Result of the GO Neg Request
  1188. */
  1189. void wpas_dbus_signal_p2p_go_neg_resp(struct wpa_supplicant *wpa_s,
  1190. struct p2p_go_neg_results *res)
  1191. {
  1192. DBusMessage *msg;
  1193. DBusMessageIter iter, dict_iter;
  1194. DBusMessageIter iter_dict_entry, iter_dict_val, iter_dict_array;
  1195. struct wpas_dbus_priv *iface;
  1196. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  1197. dbus_int32_t freqs[P2P_MAX_CHANNELS];
  1198. dbus_int32_t *f_array = freqs;
  1199. iface = wpa_s->global->dbus;
  1200. if (wpa_s->p2p_mgmt)
  1201. wpa_s = wpa_s->parent;
  1202. os_memset(freqs, 0, sizeof(freqs));
  1203. /* Do nothing if the control interface is not turned on */
  1204. if (iface == NULL || !wpa_s->dbus_new_path)
  1205. return;
  1206. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1207. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  1208. wpa_s->dbus_new_path, MAC2STR(res->peer_device_addr));
  1209. path = peer_obj_path;
  1210. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1211. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1212. res->status ? "GONegotiationFailure" :
  1213. "GONegotiationSuccess");
  1214. if (msg == NULL)
  1215. return;
  1216. dbus_message_iter_init_append(msg, &iter);
  1217. if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  1218. !wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
  1219. path) ||
  1220. !wpa_dbus_dict_append_int32(&dict_iter, "status", res->status))
  1221. goto err;
  1222. if (!res->status) {
  1223. int i = 0;
  1224. int freq_list_num = 0;
  1225. if ((res->role_go &&
  1226. !wpa_dbus_dict_append_string(&dict_iter, "passphrase",
  1227. res->passphrase)) ||
  1228. !wpa_dbus_dict_append_string(&dict_iter, "role_go",
  1229. res->role_go ? "GO" :
  1230. "client") ||
  1231. !wpa_dbus_dict_append_int32(&dict_iter, "frequency",
  1232. res->freq) ||
  1233. !wpa_dbus_dict_append_byte_array(&dict_iter, "ssid",
  1234. (const char *) res->ssid,
  1235. res->ssid_len) ||
  1236. !wpa_dbus_dict_append_byte_array(&dict_iter,
  1237. "peer_device_addr",
  1238. (const char *)
  1239. res->peer_device_addr,
  1240. ETH_ALEN) ||
  1241. !wpa_dbus_dict_append_byte_array(&dict_iter,
  1242. "peer_interface_addr",
  1243. (const char *)
  1244. res->peer_interface_addr,
  1245. ETH_ALEN) ||
  1246. !wpa_dbus_dict_append_string(&dict_iter, "wps_method",
  1247. p2p_wps_method_text(
  1248. res->wps_method)))
  1249. goto err;
  1250. for (i = 0; i < P2P_MAX_CHANNELS; i++) {
  1251. if (res->freq_list[i]) {
  1252. freqs[i] = res->freq_list[i];
  1253. freq_list_num++;
  1254. }
  1255. }
  1256. if (!wpa_dbus_dict_begin_array(&dict_iter,
  1257. "frequency_list",
  1258. DBUS_TYPE_INT32_AS_STRING,
  1259. &iter_dict_entry,
  1260. &iter_dict_val,
  1261. &iter_dict_array) ||
  1262. !dbus_message_iter_append_fixed_array(&iter_dict_array,
  1263. DBUS_TYPE_INT32,
  1264. &f_array,
  1265. freq_list_num) ||
  1266. !wpa_dbus_dict_end_array(&dict_iter,
  1267. &iter_dict_entry,
  1268. &iter_dict_val,
  1269. &iter_dict_array) ||
  1270. !wpa_dbus_dict_append_int32(&dict_iter, "persistent_group",
  1271. res->persistent_group) ||
  1272. !wpa_dbus_dict_append_uint32(&dict_iter,
  1273. "peer_config_timeout",
  1274. res->peer_config_timeout))
  1275. goto err;
  1276. }
  1277. if (!wpa_dbus_dict_close_write(&iter, &dict_iter))
  1278. goto err;
  1279. dbus_connection_send(iface->con, msg, NULL);
  1280. err:
  1281. dbus_message_unref(msg);
  1282. }
  1283. /**
  1284. * wpas_dbus_signal_p2p_invitation_result - Emit InvitationResult signal
  1285. * @wpa_s: %wpa_supplicant network interface data
  1286. * @status: Status of invitation process
  1287. * @bssid: Basic Service Set Identifier
  1288. */
  1289. void wpas_dbus_signal_p2p_invitation_result(struct wpa_supplicant *wpa_s,
  1290. int status, const u8 *bssid)
  1291. {
  1292. DBusMessage *msg;
  1293. DBusMessageIter iter, dict_iter;
  1294. struct wpas_dbus_priv *iface;
  1295. wpa_printf(MSG_DEBUG, "%s", __func__);
  1296. iface = wpa_s->global->dbus;
  1297. /* Do nothing if the control interface is not turned on */
  1298. if (iface == NULL)
  1299. return;
  1300. if (wpa_s->p2p_mgmt)
  1301. wpa_s = wpa_s->parent;
  1302. if (!wpa_s->dbus_new_path)
  1303. return;
  1304. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1305. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1306. "InvitationResult");
  1307. if (msg == NULL)
  1308. return;
  1309. dbus_message_iter_init_append(msg, &iter);
  1310. if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  1311. !wpa_dbus_dict_append_int32(&dict_iter, "status", status) ||
  1312. (bssid &&
  1313. !wpa_dbus_dict_append_byte_array(&dict_iter, "BSSID",
  1314. (const char *) bssid,
  1315. ETH_ALEN)) ||
  1316. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  1317. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1318. else
  1319. dbus_connection_send(iface->con, msg, NULL);
  1320. dbus_message_unref(msg);
  1321. }
  1322. /**
  1323. *
  1324. * Method to emit a signal for a peer joining the group.
  1325. * The signal will carry path to the group member object
  1326. * constructed using p2p i/f addr used for connecting.
  1327. *
  1328. * @wpa_s: %wpa_supplicant network interface data
  1329. * @peer_addr: P2P Device Address of the peer joining the group
  1330. */
  1331. void wpas_dbus_signal_p2p_peer_joined(struct wpa_supplicant *wpa_s,
  1332. const u8 *peer_addr)
  1333. {
  1334. struct wpas_dbus_priv *iface;
  1335. DBusMessage *msg;
  1336. DBusMessageIter iter;
  1337. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  1338. struct wpa_supplicant *parent;
  1339. iface = wpa_s->global->dbus;
  1340. /* Do nothing if the control interface is not turned on */
  1341. if (iface == NULL)
  1342. return;
  1343. if (!wpa_s->dbus_groupobj_path)
  1344. return;
  1345. parent = wpa_s->parent;
  1346. if (parent->p2p_mgmt)
  1347. parent = parent->parent;
  1348. if (!parent->dbus_new_path)
  1349. return;
  1350. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1351. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
  1352. COMPACT_MACSTR,
  1353. parent->dbus_new_path, MAC2STR(peer_addr));
  1354. msg = dbus_message_new_signal(wpa_s->dbus_groupobj_path,
  1355. WPAS_DBUS_NEW_IFACE_P2P_GROUP,
  1356. "PeerJoined");
  1357. if (msg == NULL)
  1358. return;
  1359. dbus_message_iter_init_append(msg, &iter);
  1360. path = peer_obj_path;
  1361. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  1362. &path)) {
  1363. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1364. } else {
  1365. dbus_connection_send(iface->con, msg, NULL);
  1366. wpas_dbus_signal_peer_groups_changed(parent, peer_addr);
  1367. }
  1368. dbus_message_unref(msg);
  1369. }
  1370. /**
  1371. *
  1372. * Method to emit a signal for a peer disconnecting the group.
  1373. * The signal will carry path to the group member object
  1374. * constructed using the P2P Device Address of the peer.
  1375. *
  1376. * @wpa_s: %wpa_supplicant network interface data
  1377. * @peer_addr: P2P Device Address of the peer joining the group
  1378. */
  1379. void wpas_dbus_signal_p2p_peer_disconnected(struct wpa_supplicant *wpa_s,
  1380. const u8 *peer_addr)
  1381. {
  1382. struct wpas_dbus_priv *iface;
  1383. DBusMessage *msg;
  1384. DBusMessageIter iter;
  1385. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  1386. struct wpa_supplicant *parent;
  1387. iface = wpa_s->global->dbus;
  1388. /* Do nothing if the control interface is not turned on */
  1389. if (iface == NULL)
  1390. return;
  1391. if (!wpa_s->dbus_groupobj_path)
  1392. return;
  1393. parent = wpa_s->parent;
  1394. if (parent->p2p_mgmt)
  1395. parent = parent->parent;
  1396. if (!parent->dbus_new_path)
  1397. return;
  1398. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1399. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
  1400. COMPACT_MACSTR,
  1401. parent->dbus_new_path, MAC2STR(peer_addr));
  1402. msg = dbus_message_new_signal(wpa_s->dbus_groupobj_path,
  1403. WPAS_DBUS_NEW_IFACE_P2P_GROUP,
  1404. "PeerDisconnected");
  1405. if (msg == NULL)
  1406. return;
  1407. dbus_message_iter_init_append(msg, &iter);
  1408. path = peer_obj_path;
  1409. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  1410. &path)) {
  1411. wpa_printf(MSG_ERROR,
  1412. "dbus: Failed to construct PeerDisconnected signal");
  1413. } else {
  1414. dbus_connection_send(iface->con, msg, NULL);
  1415. wpas_dbus_signal_peer_groups_changed(parent, peer_addr);
  1416. }
  1417. dbus_message_unref(msg);
  1418. }
  1419. /**
  1420. *
  1421. * Method to emit a signal for a service discovery request.
  1422. * The signal will carry station address, frequency, dialog token,
  1423. * update indicator and it tlvs
  1424. *
  1425. * @wpa_s: %wpa_supplicant network interface data
  1426. * @sa: station addr (p2p i/f) of the peer
  1427. * @dialog_token: service discovery request dialog token
  1428. * @update_indic: service discovery request update indicator
  1429. * @tlvs: service discovery request genrated byte array of tlvs
  1430. * @tlvs_len: service discovery request tlvs length
  1431. */
  1432. void wpas_dbus_signal_p2p_sd_request(struct wpa_supplicant *wpa_s,
  1433. int freq, const u8 *sa, u8 dialog_token,
  1434. u16 update_indic, const u8 *tlvs,
  1435. size_t tlvs_len)
  1436. {
  1437. DBusMessage *msg;
  1438. DBusMessageIter iter, dict_iter;
  1439. struct wpas_dbus_priv *iface;
  1440. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  1441. iface = wpa_s->global->dbus;
  1442. /* Do nothing if the control interface is not turned on */
  1443. if (iface == NULL)
  1444. return;
  1445. if (wpa_s->p2p_mgmt)
  1446. wpa_s = wpa_s->parent;
  1447. if (!wpa_s->dbus_new_path)
  1448. return;
  1449. /* Check if this is a known peer */
  1450. if (!p2p_peer_known(wpa_s->global->p2p, sa))
  1451. return;
  1452. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1453. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1454. "ServiceDiscoveryRequest");
  1455. if (msg == NULL)
  1456. return;
  1457. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1458. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
  1459. COMPACT_MACSTR, wpa_s->dbus_new_path, MAC2STR(sa));
  1460. path = peer_obj_path;
  1461. dbus_message_iter_init_append(msg, &iter);
  1462. if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  1463. !wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
  1464. path) ||
  1465. !wpa_dbus_dict_append_int32(&dict_iter, "frequency", freq) ||
  1466. !wpa_dbus_dict_append_int32(&dict_iter, "dialog_token",
  1467. dialog_token) ||
  1468. !wpa_dbus_dict_append_uint16(&dict_iter, "update_indicator",
  1469. update_indic) ||
  1470. !wpa_dbus_dict_append_byte_array(&dict_iter, "tlvs",
  1471. (const char *) tlvs,
  1472. tlvs_len) ||
  1473. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  1474. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1475. else
  1476. dbus_connection_send(iface->con, msg, NULL);
  1477. dbus_message_unref(msg);
  1478. }
  1479. /**
  1480. *
  1481. * Method to emit a signal for a service discovery response.
  1482. * The signal will carry station address, update indicator and it
  1483. * tlvs
  1484. *
  1485. * @wpa_s: %wpa_supplicant network interface data
  1486. * @sa: station addr (p2p i/f) of the peer
  1487. * @update_indic: service discovery request update indicator
  1488. * @tlvs: service discovery request genrated byte array of tlvs
  1489. * @tlvs_len: service discovery request tlvs length
  1490. */
  1491. void wpas_dbus_signal_p2p_sd_response(struct wpa_supplicant *wpa_s,
  1492. const u8 *sa, u16 update_indic,
  1493. const u8 *tlvs, size_t tlvs_len)
  1494. {
  1495. DBusMessage *msg;
  1496. DBusMessageIter iter, dict_iter;
  1497. struct wpas_dbus_priv *iface;
  1498. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  1499. iface = wpa_s->global->dbus;
  1500. /* Do nothing if the control interface is not turned on */
  1501. if (iface == NULL)
  1502. return;
  1503. if (wpa_s->p2p_mgmt)
  1504. wpa_s = wpa_s->parent;
  1505. if (!wpa_s->dbus_new_path)
  1506. return;
  1507. /* Check if this is a known peer */
  1508. if (!p2p_peer_known(wpa_s->global->p2p, sa))
  1509. return;
  1510. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1511. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1512. "ServiceDiscoveryResponse");
  1513. if (msg == NULL)
  1514. return;
  1515. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1516. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
  1517. COMPACT_MACSTR, wpa_s->dbus_new_path, MAC2STR(sa));
  1518. path = peer_obj_path;
  1519. dbus_message_iter_init_append(msg, &iter);
  1520. if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  1521. !wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
  1522. path) ||
  1523. !wpa_dbus_dict_append_uint16(&dict_iter, "update_indicator",
  1524. update_indic) ||
  1525. !wpa_dbus_dict_append_byte_array(&dict_iter, "tlvs",
  1526. (const char *) tlvs,
  1527. tlvs_len) ||
  1528. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  1529. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1530. else
  1531. dbus_connection_send(iface->con, msg, NULL);
  1532. dbus_message_unref(msg);
  1533. }
  1534. /**
  1535. * wpas_dbus_signal_persistent_group - Send a persistent group related
  1536. * event signal
  1537. * @wpa_s: %wpa_supplicant network interface data
  1538. * @id: new persistent group id
  1539. * @sig_name: signal name - PersistentGroupAdded, PersistentGroupRemoved
  1540. * @properties: determines if add second argument with object properties
  1541. *
  1542. * Notify listeners about an event related to persistent groups.
  1543. */
  1544. static void wpas_dbus_signal_persistent_group(struct wpa_supplicant *wpa_s,
  1545. int id, const char *sig_name,
  1546. int properties)
  1547. {
  1548. struct wpas_dbus_priv *iface;
  1549. DBusMessage *msg;
  1550. DBusMessageIter iter;
  1551. char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  1552. iface = wpa_s->global->dbus;
  1553. /* Do nothing if the control interface is not turned on */
  1554. if (iface == NULL)
  1555. return;
  1556. if (wpa_s->p2p_mgmt)
  1557. wpa_s = wpa_s->parent;
  1558. if (!wpa_s->dbus_new_path)
  1559. return;
  1560. os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1561. "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
  1562. wpa_s->dbus_new_path, id);
  1563. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1564. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1565. sig_name);
  1566. if (msg == NULL)
  1567. return;
  1568. dbus_message_iter_init_append(msg, &iter);
  1569. path = pgrp_obj_path;
  1570. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  1571. &path) ||
  1572. (properties &&
  1573. !wpa_dbus_get_object_properties(
  1574. iface, pgrp_obj_path,
  1575. WPAS_DBUS_NEW_IFACE_PERSISTENT_GROUP, &iter)))
  1576. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1577. else
  1578. dbus_connection_send(iface->con, msg, NULL);
  1579. dbus_message_unref(msg);
  1580. }
  1581. /**
  1582. * wpas_dbus_signal_persistent_group_added - Send a persistent_group
  1583. * added signal
  1584. * @wpa_s: %wpa_supplicant network interface data
  1585. * @id: new persistent group id
  1586. *
  1587. * Notify listeners about addition of a new persistent group.
  1588. */
  1589. static void wpas_dbus_signal_persistent_group_added(
  1590. struct wpa_supplicant *wpa_s, int id)
  1591. {
  1592. wpas_dbus_signal_persistent_group(wpa_s, id, "PersistentGroupAdded",
  1593. TRUE);
  1594. }
  1595. /**
  1596. * wpas_dbus_signal_persistent_group_removed - Send a persistent_group
  1597. * removed signal
  1598. * @wpa_s: %wpa_supplicant network interface data
  1599. * @id: persistent group id
  1600. *
  1601. * Notify listeners about removal of a persistent group.
  1602. */
  1603. static void wpas_dbus_signal_persistent_group_removed(
  1604. struct wpa_supplicant *wpa_s, int id)
  1605. {
  1606. wpas_dbus_signal_persistent_group(wpa_s, id, "PersistentGroupRemoved",
  1607. FALSE);
  1608. }
  1609. /**
  1610. * wpas_dbus_signal_p2p_wps_failed - Signals WpsFailed event
  1611. * @wpa_s: %wpa_supplicant network interface data
  1612. * @fail: WPS failure information
  1613. *
  1614. * Sends Event dbus signal with name "fail" and dictionary containing
  1615. * "msg" field with fail message number (int32) as arguments
  1616. */
  1617. void wpas_dbus_signal_p2p_wps_failed(struct wpa_supplicant *wpa_s,
  1618. struct wps_event_fail *fail)
  1619. {
  1620. DBusMessage *msg;
  1621. DBusMessageIter iter, dict_iter;
  1622. struct wpas_dbus_priv *iface;
  1623. char *key = "fail";
  1624. iface = wpa_s->global->dbus;
  1625. /* Do nothing if the control interface is not turned on */
  1626. if (iface == NULL)
  1627. return;
  1628. if (wpa_s->p2p_mgmt)
  1629. wpa_s = wpa_s->parent;
  1630. if (!wpa_s->dbus_new_path)
  1631. return;
  1632. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1633. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1634. "WpsFailed");
  1635. if (msg == NULL)
  1636. return;
  1637. dbus_message_iter_init_append(msg, &iter);
  1638. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
  1639. !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  1640. !wpa_dbus_dict_append_int32(&dict_iter, "msg", fail->msg) ||
  1641. !wpa_dbus_dict_append_int16(&dict_iter, "config_error",
  1642. fail->config_error) ||
  1643. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  1644. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1645. else
  1646. dbus_connection_send(iface->con, msg, NULL);
  1647. dbus_message_unref(msg);
  1648. }
  1649. /**
  1650. * wpas_dbus_signal_p2p_group_formation_failure - Signals GroupFormationFailure event
  1651. * @wpa_s: %wpa_supplicant network interface data
  1652. * @reason: indicates the reason code for group formation failure
  1653. *
  1654. * Sends Event dbus signal and string reason code when available.
  1655. */
  1656. void wpas_dbus_signal_p2p_group_formation_failure(struct wpa_supplicant *wpa_s,
  1657. const char *reason)
  1658. {
  1659. DBusMessage *msg;
  1660. struct wpas_dbus_priv *iface;
  1661. iface = wpa_s->global->dbus;
  1662. /* Do nothing if the control interface is not turned on */
  1663. if (iface == NULL)
  1664. return;
  1665. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1666. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1667. "GroupFormationFailure");
  1668. if (msg == NULL)
  1669. return;
  1670. if (dbus_message_append_args(msg, DBUS_TYPE_STRING, &reason,
  1671. DBUS_TYPE_INVALID))
  1672. dbus_connection_send(iface->con, msg, NULL);
  1673. else
  1674. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1675. dbus_message_unref(msg);
  1676. }
  1677. /**
  1678. * wpas_dbus_signal_p2p_invitation_received - Emit InvitationReceived signal
  1679. * @wpa_s: %wpa_supplicant network interface data
  1680. * @sa: Source address of the Invitation Request
  1681. * @dev_add: GO Device Address
  1682. * @bssid: P2P Group BSSID or %NULL if not received
  1683. * @id: Persistent group id or %0 if not persistent group
  1684. * @op_freq: Operating frequency for the group
  1685. */
  1686. void wpas_dbus_signal_p2p_invitation_received(struct wpa_supplicant *wpa_s,
  1687. const u8 *sa, const u8 *dev_addr,
  1688. const u8 *bssid, int id,
  1689. int op_freq)
  1690. {
  1691. DBusMessage *msg;
  1692. DBusMessageIter iter, dict_iter;
  1693. struct wpas_dbus_priv *iface;
  1694. iface = wpa_s->global->dbus;
  1695. /* Do nothing if the control interface is not turned on */
  1696. if (iface == NULL)
  1697. return;
  1698. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1699. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1700. "InvitationReceived");
  1701. if (msg == NULL)
  1702. return;
  1703. dbus_message_iter_init_append(msg, &iter);
  1704. if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  1705. (sa &&
  1706. !wpa_dbus_dict_append_byte_array(&dict_iter, "sa",
  1707. (const char *) sa, ETH_ALEN)) ||
  1708. (dev_addr &&
  1709. !wpa_dbus_dict_append_byte_array(&dict_iter, "go_dev_addr",
  1710. (const char *) dev_addr,
  1711. ETH_ALEN)) ||
  1712. (bssid &&
  1713. !wpa_dbus_dict_append_byte_array(&dict_iter, "bssid",
  1714. (const char *) bssid,
  1715. ETH_ALEN)) ||
  1716. (id &&
  1717. !wpa_dbus_dict_append_int32(&dict_iter, "persistent_id", id)) ||
  1718. !wpa_dbus_dict_append_int32(&dict_iter, "op_freq", op_freq) ||
  1719. !wpa_dbus_dict_close_write(&iter, &dict_iter)) {
  1720. dbus_message_unref(msg);
  1721. return;
  1722. }
  1723. dbus_connection_send(iface->con, msg, NULL);
  1724. dbus_message_unref(msg);
  1725. }
  1726. #endif /* CONFIG_P2P */
  1727. /**
  1728. * wpas_dbus_signal_prop_changed - Signals change of property
  1729. * @wpa_s: %wpa_supplicant network interface data
  1730. * @property: indicates which property has changed
  1731. *
  1732. * Sends PropertyChanged signals with path, interface and arguments
  1733. * depending on which property has changed.
  1734. */
  1735. void wpas_dbus_signal_prop_changed(struct wpa_supplicant *wpa_s,
  1736. enum wpas_dbus_prop property)
  1737. {
  1738. char *prop;
  1739. dbus_bool_t flush;
  1740. if (wpa_s->dbus_new_path == NULL)
  1741. return; /* Skip signal since D-Bus setup is not yet ready */
  1742. flush = FALSE;
  1743. switch (property) {
  1744. case WPAS_DBUS_PROP_AP_SCAN:
  1745. prop = "ApScan";
  1746. break;
  1747. #ifdef CONFIG_IEEE80211W
  1748. case WPAS_DBUS_PROP_PMF:
  1749. prop = "Pmf";
  1750. break;
  1751. #endif /* CONFIG_IEEE80211W */
  1752. case WPAS_DBUS_PROP_SCANNING:
  1753. prop = "Scanning";
  1754. break;
  1755. case WPAS_DBUS_PROP_STATE:
  1756. prop = "State";
  1757. break;
  1758. case WPAS_DBUS_PROP_CURRENT_BSS:
  1759. prop = "CurrentBSS";
  1760. break;
  1761. case WPAS_DBUS_PROP_CURRENT_NETWORK:
  1762. prop = "CurrentNetwork";
  1763. break;
  1764. case WPAS_DBUS_PROP_BSSS:
  1765. prop = "BSSs";
  1766. break;
  1767. case WPAS_DBUS_PROP_CURRENT_AUTH_MODE:
  1768. prop = "CurrentAuthMode";
  1769. break;
  1770. case WPAS_DBUS_PROP_DISCONNECT_REASON:
  1771. prop = "DisconnectReason";
  1772. flush = TRUE;
  1773. break;
  1774. case WPAS_DBUS_PROP_ASSOC_STATUS_CODE:
  1775. prop = "AssocStatusCode";
  1776. flush = TRUE;
  1777. break;
  1778. default:
  1779. wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
  1780. __func__, property);
  1781. return;
  1782. }
  1783. wpa_dbus_mark_property_changed(wpa_s->global->dbus,
  1784. wpa_s->dbus_new_path,
  1785. WPAS_DBUS_NEW_IFACE_INTERFACE, prop);
  1786. if (flush) {
  1787. wpa_dbus_flush_object_changed_properties(
  1788. wpa_s->global->dbus->con, wpa_s->dbus_new_path);
  1789. }
  1790. }
  1791. /**
  1792. * wpas_dbus_bss_signal_prop_changed - Signals change of BSS property
  1793. * @wpa_s: %wpa_supplicant network interface data
  1794. * @property: indicates which property has changed
  1795. * @id: unique BSS identifier
  1796. *
  1797. * Sends PropertyChanged signals with path, interface, and arguments depending
  1798. * on which property has changed.
  1799. */
  1800. void wpas_dbus_bss_signal_prop_changed(struct wpa_supplicant *wpa_s,
  1801. enum wpas_dbus_bss_prop property,
  1802. unsigned int id)
  1803. {
  1804. char path[WPAS_DBUS_OBJECT_PATH_MAX];
  1805. char *prop;
  1806. if (!wpa_s->dbus_new_path)
  1807. return;
  1808. switch (property) {
  1809. case WPAS_DBUS_BSS_PROP_SIGNAL:
  1810. prop = "Signal";
  1811. break;
  1812. case WPAS_DBUS_BSS_PROP_FREQ:
  1813. prop = "Frequency";
  1814. break;
  1815. case WPAS_DBUS_BSS_PROP_MODE:
  1816. prop = "Mode";
  1817. break;
  1818. case WPAS_DBUS_BSS_PROP_PRIVACY:
  1819. prop = "Privacy";
  1820. break;
  1821. case WPAS_DBUS_BSS_PROP_RATES:
  1822. prop = "Rates";
  1823. break;
  1824. case WPAS_DBUS_BSS_PROP_WPA:
  1825. prop = "WPA";
  1826. break;
  1827. case WPAS_DBUS_BSS_PROP_RSN:
  1828. prop = "RSN";
  1829. break;
  1830. case WPAS_DBUS_BSS_PROP_WPS:
  1831. prop = "WPS";
  1832. break;
  1833. case WPAS_DBUS_BSS_PROP_IES:
  1834. prop = "IEs";
  1835. break;
  1836. case WPAS_DBUS_BSS_PROP_AGE:
  1837. prop = "Age";
  1838. break;
  1839. default:
  1840. wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
  1841. __func__, property);
  1842. return;
  1843. }
  1844. os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
  1845. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  1846. wpa_s->dbus_new_path, id);
  1847. wpa_dbus_mark_property_changed(wpa_s->global->dbus, path,
  1848. WPAS_DBUS_NEW_IFACE_BSS, prop);
  1849. }
  1850. /**
  1851. * wpas_dbus_signal_debug_level_changed - Signals change of debug param
  1852. * @global: wpa_global structure
  1853. *
  1854. * Sends PropertyChanged signals informing that debug level has changed.
  1855. */
  1856. void wpas_dbus_signal_debug_level_changed(struct wpa_global *global)
  1857. {
  1858. wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
  1859. WPAS_DBUS_NEW_INTERFACE,
  1860. "DebugLevel");
  1861. }
  1862. /**
  1863. * wpas_dbus_signal_debug_timestamp_changed - Signals change of debug param
  1864. * @global: wpa_global structure
  1865. *
  1866. * Sends PropertyChanged signals informing that debug timestamp has changed.
  1867. */
  1868. void wpas_dbus_signal_debug_timestamp_changed(struct wpa_global *global)
  1869. {
  1870. wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
  1871. WPAS_DBUS_NEW_INTERFACE,
  1872. "DebugTimestamp");
  1873. }
  1874. /**
  1875. * wpas_dbus_signal_debug_show_keys_changed - Signals change of debug param
  1876. * @global: wpa_global structure
  1877. *
  1878. * Sends PropertyChanged signals informing that debug show_keys has changed.
  1879. */
  1880. void wpas_dbus_signal_debug_show_keys_changed(struct wpa_global *global)
  1881. {
  1882. wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
  1883. WPAS_DBUS_NEW_INTERFACE,
  1884. "DebugShowKeys");
  1885. }
  1886. static void wpas_dbus_register(struct wpa_dbus_object_desc *obj_desc,
  1887. void *priv,
  1888. WPADBusArgumentFreeFunction priv_free,
  1889. const struct wpa_dbus_method_desc *methods,
  1890. const struct wpa_dbus_property_desc *properties,
  1891. const struct wpa_dbus_signal_desc *signals)
  1892. {
  1893. int n;
  1894. obj_desc->user_data = priv;
  1895. obj_desc->user_data_free_func = priv_free;
  1896. obj_desc->methods = methods;
  1897. obj_desc->properties = properties;
  1898. obj_desc->signals = signals;
  1899. for (n = 0; properties && properties->dbus_property; properties++)
  1900. n++;
  1901. obj_desc->prop_changed_flags = os_zalloc(n);
  1902. if (!obj_desc->prop_changed_flags)
  1903. wpa_printf(MSG_DEBUG, "dbus: %s: can't register handlers",
  1904. __func__);
  1905. }
  1906. static const struct wpa_dbus_method_desc wpas_dbus_global_methods[] = {
  1907. { "CreateInterface", WPAS_DBUS_NEW_INTERFACE,
  1908. (WPADBusMethodHandler) wpas_dbus_handler_create_interface,
  1909. {
  1910. { "args", "a{sv}", ARG_IN },
  1911. { "path", "o", ARG_OUT },
  1912. END_ARGS
  1913. }
  1914. },
  1915. { "RemoveInterface", WPAS_DBUS_NEW_INTERFACE,
  1916. (WPADBusMethodHandler) wpas_dbus_handler_remove_interface,
  1917. {
  1918. { "path", "o", ARG_IN },
  1919. END_ARGS
  1920. }
  1921. },
  1922. { "GetInterface", WPAS_DBUS_NEW_INTERFACE,
  1923. (WPADBusMethodHandler) wpas_dbus_handler_get_interface,
  1924. {
  1925. { "ifname", "s", ARG_IN },
  1926. { "path", "o", ARG_OUT },
  1927. END_ARGS
  1928. }
  1929. },
  1930. { "ExpectDisconnect", WPAS_DBUS_NEW_INTERFACE,
  1931. (WPADBusMethodHandler) wpas_dbus_handler_expect_disconnect,
  1932. {
  1933. END_ARGS
  1934. }
  1935. },
  1936. { NULL, NULL, NULL, { END_ARGS } }
  1937. };
  1938. static const struct wpa_dbus_property_desc wpas_dbus_global_properties[] = {
  1939. { "DebugLevel", WPAS_DBUS_NEW_INTERFACE, "s",
  1940. wpas_dbus_getter_debug_level,
  1941. wpas_dbus_setter_debug_level,
  1942. NULL
  1943. },
  1944. { "DebugTimestamp", WPAS_DBUS_NEW_INTERFACE, "b",
  1945. wpas_dbus_getter_debug_timestamp,
  1946. wpas_dbus_setter_debug_timestamp,
  1947. NULL
  1948. },
  1949. { "DebugShowKeys", WPAS_DBUS_NEW_INTERFACE, "b",
  1950. wpas_dbus_getter_debug_show_keys,
  1951. wpas_dbus_setter_debug_show_keys,
  1952. NULL
  1953. },
  1954. { "Interfaces", WPAS_DBUS_NEW_INTERFACE, "ao",
  1955. wpas_dbus_getter_interfaces,
  1956. NULL,
  1957. NULL
  1958. },
  1959. { "EapMethods", WPAS_DBUS_NEW_INTERFACE, "as",
  1960. wpas_dbus_getter_eap_methods,
  1961. NULL,
  1962. NULL
  1963. },
  1964. { "Capabilities", WPAS_DBUS_NEW_INTERFACE, "as",
  1965. wpas_dbus_getter_global_capabilities,
  1966. NULL,
  1967. NULL
  1968. },
  1969. #ifdef CONFIG_WIFI_DISPLAY
  1970. { "WFDIEs", WPAS_DBUS_NEW_INTERFACE, "ay",
  1971. wpas_dbus_getter_global_wfd_ies,
  1972. wpas_dbus_setter_global_wfd_ies,
  1973. NULL
  1974. },
  1975. #endif /* CONFIG_WIFI_DISPLAY */
  1976. { NULL, NULL, NULL, NULL, NULL, NULL }
  1977. };
  1978. static const struct wpa_dbus_signal_desc wpas_dbus_global_signals[] = {
  1979. { "InterfaceAdded", WPAS_DBUS_NEW_INTERFACE,
  1980. {
  1981. { "path", "o", ARG_OUT },
  1982. { "properties", "a{sv}", ARG_OUT },
  1983. END_ARGS
  1984. }
  1985. },
  1986. { "InterfaceRemoved", WPAS_DBUS_NEW_INTERFACE,
  1987. {
  1988. { "path", "o", ARG_OUT },
  1989. END_ARGS
  1990. }
  1991. },
  1992. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  1993. { "PropertiesChanged", WPAS_DBUS_NEW_INTERFACE,
  1994. {
  1995. { "properties", "a{sv}", ARG_OUT },
  1996. END_ARGS
  1997. }
  1998. },
  1999. { NULL, NULL, { END_ARGS } }
  2000. };
  2001. static char * uscore_to_dbus(const char *uscore)
  2002. {
  2003. const char *p = uscore;
  2004. char *str, *s;
  2005. dbus_bool_t last_was_uscore = TRUE;
  2006. s = str = os_zalloc(os_strlen(uscore) + 1);
  2007. if (!str)
  2008. return NULL;
  2009. while (p && *p) {
  2010. if (*p == '_') {
  2011. last_was_uscore = TRUE;
  2012. } else {
  2013. *s++ = last_was_uscore ? toupper(*p) : *p;
  2014. last_was_uscore = FALSE;
  2015. }
  2016. p++;
  2017. }
  2018. return str;
  2019. }
  2020. static int wpa_dbus_ctrl_iface_props_init(struct wpas_dbus_priv *priv);
  2021. static void wpa_dbus_ctrl_iface_props_deinit(struct wpas_dbus_priv *priv)
  2022. {
  2023. int idx = priv->globals_start;
  2024. /* Free all allocated property values */
  2025. while (priv->all_interface_properties[idx].dbus_property)
  2026. os_free((char *)
  2027. priv->all_interface_properties[idx++].dbus_property);
  2028. os_free((char *) priv->all_interface_properties);
  2029. }
  2030. /**
  2031. * wpas_dbus_ctrl_iface_init - Initialize dbus control interface
  2032. * @global: Pointer to global data from wpa_supplicant_init()
  2033. * Returns: 0 on success or -1 on failure
  2034. *
  2035. * Initialize the dbus control interface for wpa_supplicant and start
  2036. * receiving commands from external programs over the bus.
  2037. */
  2038. int wpas_dbus_ctrl_iface_init(struct wpas_dbus_priv *priv)
  2039. {
  2040. struct wpa_dbus_object_desc *obj_desc;
  2041. int ret;
  2042. ret = wpa_dbus_ctrl_iface_props_init(priv);
  2043. if (ret < 0) {
  2044. wpa_printf(MSG_ERROR,
  2045. "dbus: Not enough memory to init interface properties");
  2046. return -1;
  2047. }
  2048. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  2049. if (!obj_desc) {
  2050. wpa_printf(MSG_ERROR,
  2051. "Not enough memory to create object description");
  2052. goto error;
  2053. }
  2054. wpas_dbus_register(obj_desc, priv->global, NULL,
  2055. wpas_dbus_global_methods,
  2056. wpas_dbus_global_properties,
  2057. wpas_dbus_global_signals);
  2058. wpa_printf(MSG_DEBUG, "dbus: Register D-Bus object '%s'",
  2059. WPAS_DBUS_NEW_PATH);
  2060. ret = wpa_dbus_ctrl_iface_init(priv, WPAS_DBUS_NEW_PATH,
  2061. WPAS_DBUS_NEW_SERVICE,
  2062. obj_desc);
  2063. if (ret < 0) {
  2064. free_dbus_object_desc(obj_desc);
  2065. goto error;
  2066. }
  2067. priv->dbus_new_initialized = 1;
  2068. return 0;
  2069. error:
  2070. wpa_dbus_ctrl_iface_props_deinit(priv);
  2071. return -1;
  2072. }
  2073. /**
  2074. * wpas_dbus_ctrl_iface_deinit - Deinitialize dbus ctrl interface for
  2075. * wpa_supplicant
  2076. * @priv: Pointer to dbus private data from wpas_dbus_init()
  2077. *
  2078. * Deinitialize the dbus control interface that was initialized with
  2079. * wpas_dbus_ctrl_iface_init().
  2080. */
  2081. void wpas_dbus_ctrl_iface_deinit(struct wpas_dbus_priv *priv)
  2082. {
  2083. if (!priv->dbus_new_initialized)
  2084. return;
  2085. wpa_printf(MSG_DEBUG, "dbus: Unregister D-Bus object '%s'",
  2086. WPAS_DBUS_NEW_PATH);
  2087. dbus_connection_unregister_object_path(priv->con, WPAS_DBUS_NEW_PATH);
  2088. wpa_dbus_ctrl_iface_props_deinit(priv);
  2089. }
  2090. static void wpa_dbus_free(void *ptr)
  2091. {
  2092. os_free(ptr);
  2093. }
  2094. static const struct wpa_dbus_property_desc wpas_dbus_network_properties[] = {
  2095. { "Properties", WPAS_DBUS_NEW_IFACE_NETWORK, "a{sv}",
  2096. wpas_dbus_getter_network_properties,
  2097. wpas_dbus_setter_network_properties,
  2098. NULL
  2099. },
  2100. { "Enabled", WPAS_DBUS_NEW_IFACE_NETWORK, "b",
  2101. wpas_dbus_getter_enabled,
  2102. wpas_dbus_setter_enabled,
  2103. NULL
  2104. },
  2105. { NULL, NULL, NULL, NULL, NULL, NULL }
  2106. };
  2107. static const struct wpa_dbus_signal_desc wpas_dbus_network_signals[] = {
  2108. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  2109. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_NETWORK,
  2110. {
  2111. { "properties", "a{sv}", ARG_OUT },
  2112. END_ARGS
  2113. }
  2114. },
  2115. { NULL, NULL, { END_ARGS } }
  2116. };
  2117. /**
  2118. * wpas_dbus_register_network - Register a configured network with dbus
  2119. * @wpa_s: wpa_supplicant interface structure
  2120. * @ssid: network configuration data
  2121. * Returns: 0 on success, -1 on failure
  2122. *
  2123. * Registers network representing object with dbus
  2124. */
  2125. int wpas_dbus_register_network(struct wpa_supplicant *wpa_s,
  2126. struct wpa_ssid *ssid)
  2127. {
  2128. struct wpas_dbus_priv *ctrl_iface;
  2129. struct wpa_dbus_object_desc *obj_desc;
  2130. struct network_handler_args *arg;
  2131. char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2132. #ifdef CONFIG_P2P
  2133. /*
  2134. * If it is a persistent group register it as such.
  2135. * This is to handle cases where an interface is being initialized
  2136. * with a list of networks read from config.
  2137. */
  2138. if (network_is_persistent_group(ssid))
  2139. return wpas_dbus_register_persistent_group(wpa_s, ssid);
  2140. #endif /* CONFIG_P2P */
  2141. /* Do nothing if the control interface is not turned on */
  2142. if (wpa_s == NULL || wpa_s->global == NULL || !wpa_s->dbus_new_path)
  2143. return 0;
  2144. ctrl_iface = wpa_s->global->dbus;
  2145. if (ctrl_iface == NULL)
  2146. return 0;
  2147. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2148. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  2149. wpa_s->dbus_new_path, ssid->id);
  2150. wpa_printf(MSG_DEBUG, "dbus: Register network object '%s'",
  2151. net_obj_path);
  2152. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  2153. if (!obj_desc) {
  2154. wpa_printf(MSG_ERROR,
  2155. "Not enough memory to create object description");
  2156. goto err;
  2157. }
  2158. /* allocate memory for handlers arguments */
  2159. arg = os_zalloc(sizeof(struct network_handler_args));
  2160. if (!arg) {
  2161. wpa_printf(MSG_ERROR,
  2162. "Not enough memory to create arguments for method");
  2163. goto err;
  2164. }
  2165. arg->wpa_s = wpa_s;
  2166. arg->ssid = ssid;
  2167. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  2168. wpas_dbus_network_properties,
  2169. wpas_dbus_network_signals);
  2170. if (wpa_dbus_register_object_per_iface(ctrl_iface, net_obj_path,
  2171. wpa_s->ifname, obj_desc))
  2172. goto err;
  2173. wpas_dbus_signal_network_added(wpa_s, ssid->id);
  2174. return 0;
  2175. err:
  2176. free_dbus_object_desc(obj_desc);
  2177. return -1;
  2178. }
  2179. /**
  2180. * wpas_dbus_unregister_network - Unregister a configured network from dbus
  2181. * @wpa_s: wpa_supplicant interface structure
  2182. * @nid: network id
  2183. * Returns: 0 on success, -1 on failure
  2184. *
  2185. * Unregisters network representing object from dbus
  2186. */
  2187. int wpas_dbus_unregister_network(struct wpa_supplicant *wpa_s, int nid)
  2188. {
  2189. struct wpas_dbus_priv *ctrl_iface;
  2190. char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2191. int ret;
  2192. #ifdef CONFIG_P2P
  2193. struct wpa_ssid *ssid;
  2194. ssid = wpa_config_get_network(wpa_s->conf, nid);
  2195. /* If it is a persistent group unregister it as such */
  2196. if (ssid && network_is_persistent_group(ssid))
  2197. return wpas_dbus_unregister_persistent_group(wpa_s, nid);
  2198. #endif /* CONFIG_P2P */
  2199. /* Do nothing if the control interface is not turned on */
  2200. if (wpa_s->global == NULL || wpa_s->dbus_new_path == NULL)
  2201. return 0;
  2202. ctrl_iface = wpa_s->global->dbus;
  2203. if (ctrl_iface == NULL)
  2204. return 0;
  2205. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2206. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  2207. wpa_s->dbus_new_path, nid);
  2208. wpa_printf(MSG_DEBUG, "dbus: Unregister network object '%s'",
  2209. net_obj_path);
  2210. ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, net_obj_path);
  2211. if (!ret)
  2212. wpas_dbus_signal_network_removed(wpa_s, nid);
  2213. return ret;
  2214. }
  2215. static const struct wpa_dbus_property_desc wpas_dbus_bss_properties[] = {
  2216. { "SSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
  2217. wpas_dbus_getter_bss_ssid,
  2218. NULL,
  2219. NULL
  2220. },
  2221. { "BSSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
  2222. wpas_dbus_getter_bss_bssid,
  2223. NULL,
  2224. NULL
  2225. },
  2226. { "Privacy", WPAS_DBUS_NEW_IFACE_BSS, "b",
  2227. wpas_dbus_getter_bss_privacy,
  2228. NULL,
  2229. NULL
  2230. },
  2231. { "Mode", WPAS_DBUS_NEW_IFACE_BSS, "s",
  2232. wpas_dbus_getter_bss_mode,
  2233. NULL,
  2234. NULL
  2235. },
  2236. { "Signal", WPAS_DBUS_NEW_IFACE_BSS, "n",
  2237. wpas_dbus_getter_bss_signal,
  2238. NULL,
  2239. NULL
  2240. },
  2241. { "Frequency", WPAS_DBUS_NEW_IFACE_BSS, "q",
  2242. wpas_dbus_getter_bss_frequency,
  2243. NULL,
  2244. NULL
  2245. },
  2246. { "Rates", WPAS_DBUS_NEW_IFACE_BSS, "au",
  2247. wpas_dbus_getter_bss_rates,
  2248. NULL,
  2249. NULL
  2250. },
  2251. { "WPA", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
  2252. wpas_dbus_getter_bss_wpa,
  2253. NULL,
  2254. NULL
  2255. },
  2256. { "RSN", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
  2257. wpas_dbus_getter_bss_rsn,
  2258. NULL,
  2259. NULL
  2260. },
  2261. { "WPS", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
  2262. wpas_dbus_getter_bss_wps,
  2263. NULL,
  2264. NULL
  2265. },
  2266. { "IEs", WPAS_DBUS_NEW_IFACE_BSS, "ay",
  2267. wpas_dbus_getter_bss_ies,
  2268. NULL,
  2269. NULL
  2270. },
  2271. { "Age", WPAS_DBUS_NEW_IFACE_BSS, "u",
  2272. wpas_dbus_getter_bss_age,
  2273. NULL,
  2274. NULL
  2275. },
  2276. { NULL, NULL, NULL, NULL, NULL, NULL }
  2277. };
  2278. static const struct wpa_dbus_signal_desc wpas_dbus_bss_signals[] = {
  2279. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  2280. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_BSS,
  2281. {
  2282. { "properties", "a{sv}", ARG_OUT },
  2283. END_ARGS
  2284. }
  2285. },
  2286. { NULL, NULL, { END_ARGS } }
  2287. };
  2288. /**
  2289. * wpas_dbus_unregister_bss - Unregister a scanned BSS from dbus
  2290. * @wpa_s: wpa_supplicant interface structure
  2291. * @bssid: scanned network bssid
  2292. * @id: unique BSS identifier
  2293. * Returns: 0 on success, -1 on failure
  2294. *
  2295. * Unregisters BSS representing object from dbus
  2296. */
  2297. int wpas_dbus_unregister_bss(struct wpa_supplicant *wpa_s,
  2298. u8 bssid[ETH_ALEN], unsigned int id)
  2299. {
  2300. struct wpas_dbus_priv *ctrl_iface;
  2301. char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2302. /* Do nothing if the control interface is not turned on */
  2303. if (wpa_s == NULL || wpa_s->global == NULL || !wpa_s->dbus_new_path)
  2304. return 0;
  2305. ctrl_iface = wpa_s->global->dbus;
  2306. if (ctrl_iface == NULL)
  2307. return 0;
  2308. os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2309. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  2310. wpa_s->dbus_new_path, id);
  2311. wpa_printf(MSG_DEBUG, "dbus: Unregister BSS object '%s'",
  2312. bss_obj_path);
  2313. if (wpa_dbus_unregister_object_per_iface(ctrl_iface, bss_obj_path)) {
  2314. wpa_printf(MSG_ERROR, "dbus: Cannot unregister BSS object %s",
  2315. bss_obj_path);
  2316. return -1;
  2317. }
  2318. wpas_dbus_signal_bss_removed(wpa_s, bss_obj_path);
  2319. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSSS);
  2320. return 0;
  2321. }
  2322. /**
  2323. * wpas_dbus_register_bss - Register a scanned BSS with dbus
  2324. * @wpa_s: wpa_supplicant interface structure
  2325. * @bssid: scanned network bssid
  2326. * @id: unique BSS identifier
  2327. * Returns: 0 on success, -1 on failure
  2328. *
  2329. * Registers BSS representing object with dbus
  2330. */
  2331. int wpas_dbus_register_bss(struct wpa_supplicant *wpa_s,
  2332. u8 bssid[ETH_ALEN], unsigned int id)
  2333. {
  2334. struct wpas_dbus_priv *ctrl_iface;
  2335. struct wpa_dbus_object_desc *obj_desc;
  2336. char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2337. struct bss_handler_args *arg;
  2338. /* Do nothing if the control interface is not turned on */
  2339. if (wpa_s == NULL || wpa_s->global == NULL || !wpa_s->dbus_new_path)
  2340. return 0;
  2341. ctrl_iface = wpa_s->global->dbus;
  2342. if (ctrl_iface == NULL)
  2343. return 0;
  2344. os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2345. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  2346. wpa_s->dbus_new_path, id);
  2347. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  2348. if (!obj_desc) {
  2349. wpa_printf(MSG_ERROR,
  2350. "Not enough memory to create object description");
  2351. goto err;
  2352. }
  2353. arg = os_zalloc(sizeof(struct bss_handler_args));
  2354. if (!arg) {
  2355. wpa_printf(MSG_ERROR,
  2356. "Not enough memory to create arguments for handler");
  2357. goto err;
  2358. }
  2359. arg->wpa_s = wpa_s;
  2360. arg->id = id;
  2361. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  2362. wpas_dbus_bss_properties,
  2363. wpas_dbus_bss_signals);
  2364. wpa_printf(MSG_DEBUG, "dbus: Register BSS object '%s'",
  2365. bss_obj_path);
  2366. if (wpa_dbus_register_object_per_iface(ctrl_iface, bss_obj_path,
  2367. wpa_s->ifname, obj_desc)) {
  2368. wpa_printf(MSG_ERROR,
  2369. "Cannot register BSSID dbus object %s.",
  2370. bss_obj_path);
  2371. goto err;
  2372. }
  2373. wpas_dbus_signal_bss_added(wpa_s, bss_obj_path);
  2374. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSSS);
  2375. return 0;
  2376. err:
  2377. free_dbus_object_desc(obj_desc);
  2378. return -1;
  2379. }
  2380. static const struct wpa_dbus_method_desc wpas_dbus_interface_methods[] = {
  2381. { "Scan", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2382. (WPADBusMethodHandler) wpas_dbus_handler_scan,
  2383. {
  2384. { "args", "a{sv}", ARG_IN },
  2385. END_ARGS
  2386. }
  2387. },
  2388. { "SignalPoll", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2389. (WPADBusMethodHandler) wpas_dbus_handler_signal_poll,
  2390. {
  2391. { "args", "a{sv}", ARG_OUT },
  2392. END_ARGS
  2393. }
  2394. },
  2395. { "Disconnect", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2396. (WPADBusMethodHandler) wpas_dbus_handler_disconnect,
  2397. {
  2398. END_ARGS
  2399. }
  2400. },
  2401. { "AddNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2402. (WPADBusMethodHandler) wpas_dbus_handler_add_network,
  2403. {
  2404. { "args", "a{sv}", ARG_IN },
  2405. { "path", "o", ARG_OUT },
  2406. END_ARGS
  2407. }
  2408. },
  2409. { "Reassociate", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2410. (WPADBusMethodHandler) wpas_dbus_handler_reassociate,
  2411. {
  2412. END_ARGS
  2413. }
  2414. },
  2415. { "Reattach", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2416. (WPADBusMethodHandler) wpas_dbus_handler_reattach,
  2417. {
  2418. END_ARGS
  2419. }
  2420. },
  2421. { "Reconnect", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2422. (WPADBusMethodHandler) wpas_dbus_handler_reconnect,
  2423. {
  2424. END_ARGS
  2425. }
  2426. },
  2427. { "RemoveNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2428. (WPADBusMethodHandler) wpas_dbus_handler_remove_network,
  2429. {
  2430. { "path", "o", ARG_IN },
  2431. END_ARGS
  2432. }
  2433. },
  2434. { "RemoveAllNetworks", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2435. (WPADBusMethodHandler) wpas_dbus_handler_remove_all_networks,
  2436. {
  2437. END_ARGS
  2438. }
  2439. },
  2440. { "SelectNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2441. (WPADBusMethodHandler) wpas_dbus_handler_select_network,
  2442. {
  2443. { "path", "o", ARG_IN },
  2444. END_ARGS
  2445. }
  2446. },
  2447. { "NetworkReply", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2448. (WPADBusMethodHandler) wpas_dbus_handler_network_reply,
  2449. {
  2450. { "path", "o", ARG_IN },
  2451. { "field", "s", ARG_IN },
  2452. { "value", "s", ARG_IN },
  2453. END_ARGS
  2454. }
  2455. },
  2456. #ifndef CONFIG_NO_CONFIG_BLOBS
  2457. { "AddBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2458. (WPADBusMethodHandler) wpas_dbus_handler_add_blob,
  2459. {
  2460. { "name", "s", ARG_IN },
  2461. { "data", "ay", ARG_IN },
  2462. END_ARGS
  2463. }
  2464. },
  2465. { "GetBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2466. (WPADBusMethodHandler) wpas_dbus_handler_get_blob,
  2467. {
  2468. { "name", "s", ARG_IN },
  2469. { "data", "ay", ARG_OUT },
  2470. END_ARGS
  2471. }
  2472. },
  2473. { "RemoveBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2474. (WPADBusMethodHandler) wpas_dbus_handler_remove_blob,
  2475. {
  2476. { "name", "s", ARG_IN },
  2477. END_ARGS
  2478. }
  2479. },
  2480. #endif /* CONFIG_NO_CONFIG_BLOBS */
  2481. { "SetPKCS11EngineAndModulePath", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2482. (WPADBusMethodHandler)
  2483. wpas_dbus_handler_set_pkcs11_engine_and_module_path,
  2484. {
  2485. { "pkcs11_engine_path", "s", ARG_IN },
  2486. { "pkcs11_module_path", "s", ARG_IN },
  2487. END_ARGS
  2488. }
  2489. },
  2490. #ifdef CONFIG_WPS
  2491. { "Start", WPAS_DBUS_NEW_IFACE_WPS,
  2492. (WPADBusMethodHandler) wpas_dbus_handler_wps_start,
  2493. {
  2494. { "args", "a{sv}", ARG_IN },
  2495. { "output", "a{sv}", ARG_OUT },
  2496. END_ARGS
  2497. }
  2498. },
  2499. { "Cancel", WPAS_DBUS_NEW_IFACE_WPS,
  2500. (WPADBusMethodHandler) wpas_dbus_handler_wps_cancel,
  2501. {
  2502. END_ARGS
  2503. }
  2504. },
  2505. #endif /* CONFIG_WPS */
  2506. #ifdef CONFIG_P2P
  2507. { "Find", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2508. (WPADBusMethodHandler) wpas_dbus_handler_p2p_find,
  2509. {
  2510. { "args", "a{sv}", ARG_IN },
  2511. END_ARGS
  2512. }
  2513. },
  2514. { "StopFind", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2515. (WPADBusMethodHandler) wpas_dbus_handler_p2p_stop_find,
  2516. {
  2517. END_ARGS
  2518. }
  2519. },
  2520. { "Listen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2521. (WPADBusMethodHandler) wpas_dbus_handler_p2p_listen,
  2522. {
  2523. { "timeout", "i", ARG_IN },
  2524. END_ARGS
  2525. }
  2526. },
  2527. { "ExtendedListen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2528. (WPADBusMethodHandler) wpas_dbus_handler_p2p_extendedlisten,
  2529. {
  2530. { "args", "a{sv}", ARG_IN },
  2531. END_ARGS
  2532. }
  2533. },
  2534. { "PresenceRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2535. (WPADBusMethodHandler) wpas_dbus_handler_p2p_presence_request,
  2536. {
  2537. { "args", "a{sv}", ARG_IN },
  2538. END_ARGS
  2539. }
  2540. },
  2541. { "ProvisionDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2542. (WPADBusMethodHandler) wpas_dbus_handler_p2p_prov_disc_req,
  2543. {
  2544. { "peer", "o", ARG_IN },
  2545. { "config_method", "s", ARG_IN },
  2546. END_ARGS
  2547. }
  2548. },
  2549. { "Connect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2550. (WPADBusMethodHandler) wpas_dbus_handler_p2p_connect,
  2551. {
  2552. { "args", "a{sv}", ARG_IN },
  2553. { "generated_pin", "s", ARG_OUT },
  2554. END_ARGS
  2555. }
  2556. },
  2557. { "GroupAdd", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2558. (WPADBusMethodHandler) wpas_dbus_handler_p2p_group_add,
  2559. {
  2560. { "args", "a{sv}", ARG_IN },
  2561. END_ARGS
  2562. }
  2563. },
  2564. { "Cancel", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2565. (WPADBusMethodHandler) wpas_dbus_handler_p2p_cancel,
  2566. {
  2567. END_ARGS
  2568. }
  2569. },
  2570. { "Invite", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2571. (WPADBusMethodHandler) wpas_dbus_handler_p2p_invite,
  2572. {
  2573. { "args", "a{sv}", ARG_IN },
  2574. END_ARGS
  2575. }
  2576. },
  2577. { "Disconnect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2578. (WPADBusMethodHandler) wpas_dbus_handler_p2p_disconnect,
  2579. {
  2580. END_ARGS
  2581. }
  2582. },
  2583. { "RejectPeer", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2584. (WPADBusMethodHandler) wpas_dbus_handler_p2p_rejectpeer,
  2585. {
  2586. { "peer", "o", ARG_IN },
  2587. END_ARGS
  2588. }
  2589. },
  2590. { "RemoveClient", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2591. (WPADBusMethodHandler) wpas_dbus_handler_p2p_remove_client,
  2592. {
  2593. { "args", "a{sv}", ARG_IN },
  2594. END_ARGS
  2595. }
  2596. },
  2597. { "Flush", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2598. (WPADBusMethodHandler) wpas_dbus_handler_p2p_flush,
  2599. {
  2600. END_ARGS
  2601. }
  2602. },
  2603. { "AddService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2604. (WPADBusMethodHandler) wpas_dbus_handler_p2p_add_service,
  2605. {
  2606. { "args", "a{sv}", ARG_IN },
  2607. END_ARGS
  2608. }
  2609. },
  2610. { "DeleteService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2611. (WPADBusMethodHandler) wpas_dbus_handler_p2p_delete_service,
  2612. {
  2613. { "args", "a{sv}", ARG_IN },
  2614. END_ARGS
  2615. }
  2616. },
  2617. { "FlushService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2618. (WPADBusMethodHandler) wpas_dbus_handler_p2p_flush_service,
  2619. {
  2620. END_ARGS
  2621. }
  2622. },
  2623. { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2624. (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_sd_req,
  2625. {
  2626. { "args", "a{sv}", ARG_IN },
  2627. { "ref", "t", ARG_OUT },
  2628. END_ARGS
  2629. }
  2630. },
  2631. { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2632. (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_sd_res,
  2633. {
  2634. { "args", "a{sv}", ARG_IN },
  2635. END_ARGS
  2636. }
  2637. },
  2638. { "ServiceDiscoveryCancelRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2639. (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_sd_cancel_req,
  2640. {
  2641. { "args", "t", ARG_IN },
  2642. END_ARGS
  2643. }
  2644. },
  2645. { "ServiceUpdate", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2646. (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_update,
  2647. {
  2648. END_ARGS
  2649. }
  2650. },
  2651. { "ServiceDiscoveryExternal", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2652. (WPADBusMethodHandler) wpas_dbus_handler_p2p_serv_disc_external,
  2653. {
  2654. { "arg", "i", ARG_IN },
  2655. END_ARGS
  2656. }
  2657. },
  2658. { "AddPersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2659. (WPADBusMethodHandler) wpas_dbus_handler_add_persistent_group,
  2660. {
  2661. { "args", "a{sv}", ARG_IN },
  2662. { "path", "o", ARG_OUT },
  2663. END_ARGS
  2664. }
  2665. },
  2666. { "RemovePersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2667. (WPADBusMethodHandler) wpas_dbus_handler_remove_persistent_group,
  2668. {
  2669. { "path", "o", ARG_IN },
  2670. END_ARGS
  2671. }
  2672. },
  2673. { "RemoveAllPersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2674. (WPADBusMethodHandler)
  2675. wpas_dbus_handler_remove_all_persistent_groups,
  2676. {
  2677. END_ARGS
  2678. }
  2679. },
  2680. #endif /* CONFIG_P2P */
  2681. { "FlushBSS", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2682. (WPADBusMethodHandler) wpas_dbus_handler_flush_bss,
  2683. {
  2684. { "age", "u", ARG_IN },
  2685. END_ARGS
  2686. }
  2687. },
  2688. #ifdef CONFIG_AP
  2689. { "SubscribeProbeReq", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2690. (WPADBusMethodHandler) wpas_dbus_handler_subscribe_preq,
  2691. {
  2692. END_ARGS
  2693. }
  2694. },
  2695. { "UnsubscribeProbeReq", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2696. (WPADBusMethodHandler) wpas_dbus_handler_unsubscribe_preq,
  2697. {
  2698. END_ARGS
  2699. }
  2700. },
  2701. #endif /* CONFIG_AP */
  2702. { "EAPLogoff", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2703. (WPADBusMethodHandler) wpas_dbus_handler_eap_logoff,
  2704. {
  2705. END_ARGS
  2706. }
  2707. },
  2708. { "EAPLogon", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2709. (WPADBusMethodHandler) wpas_dbus_handler_eap_logon,
  2710. {
  2711. END_ARGS
  2712. }
  2713. },
  2714. #ifdef CONFIG_AUTOSCAN
  2715. { "AutoScan", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2716. (WPADBusMethodHandler) wpas_dbus_handler_autoscan,
  2717. {
  2718. { "arg", "s", ARG_IN },
  2719. END_ARGS
  2720. }
  2721. },
  2722. #endif /* CONFIG_AUTOSCAN */
  2723. #ifdef CONFIG_TDLS
  2724. { "TDLSDiscover", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2725. (WPADBusMethodHandler) wpas_dbus_handler_tdls_discover,
  2726. {
  2727. { "peer_address", "s", ARG_IN },
  2728. END_ARGS
  2729. }
  2730. },
  2731. { "TDLSSetup", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2732. (WPADBusMethodHandler) wpas_dbus_handler_tdls_setup,
  2733. {
  2734. { "peer_address", "s", ARG_IN },
  2735. END_ARGS
  2736. }
  2737. },
  2738. { "TDLSStatus", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2739. (WPADBusMethodHandler) wpas_dbus_handler_tdls_status,
  2740. {
  2741. { "peer_address", "s", ARG_IN },
  2742. { "status", "s", ARG_OUT },
  2743. END_ARGS
  2744. }
  2745. },
  2746. { "TDLSTeardown", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2747. (WPADBusMethodHandler) wpas_dbus_handler_tdls_teardown,
  2748. {
  2749. { "peer_address", "s", ARG_IN },
  2750. END_ARGS
  2751. }
  2752. },
  2753. { "TDLSChannelSwitch", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2754. (WPADBusMethodHandler) wpas_dbus_handler_tdls_channel_switch,
  2755. {
  2756. { "args", "a{sv}", ARG_IN },
  2757. END_ARGS
  2758. }
  2759. },
  2760. { "TDLSCancelChannelSwitch", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2761. (WPADBusMethodHandler) wpas_dbus_handler_tdls_cancel_channel_switch,
  2762. {
  2763. { "peer_address", "s", ARG_IN },
  2764. END_ARGS
  2765. }
  2766. },
  2767. #endif /* CONFIG_TDLS */
  2768. { "VendorElemAdd", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2769. (WPADBusMethodHandler) wpas_dbus_handler_vendor_elem_add,
  2770. {
  2771. { "frame_id", "i", ARG_IN },
  2772. { "ielems", "ay", ARG_IN },
  2773. END_ARGS
  2774. }
  2775. },
  2776. { "VendorElemGet", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2777. (WPADBusMethodHandler) wpas_dbus_handler_vendor_elem_get,
  2778. {
  2779. { "frame_id", "i", ARG_IN },
  2780. { "ielems", "ay", ARG_OUT },
  2781. END_ARGS
  2782. }
  2783. },
  2784. { "VendorElemRem", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2785. (WPADBusMethodHandler) wpas_dbus_handler_vendor_elem_remove,
  2786. {
  2787. { "frame_id", "i", ARG_IN },
  2788. { "ielems", "ay", ARG_IN },
  2789. END_ARGS
  2790. }
  2791. },
  2792. #ifndef CONFIG_NO_CONFIG_WRITE
  2793. { "SaveConfig", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2794. (WPADBusMethodHandler) wpas_dbus_handler_save_config,
  2795. {
  2796. END_ARGS
  2797. }
  2798. },
  2799. #endif /* CONFIG_NO_CONFIG_WRITE */
  2800. { "AbortScan", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2801. (WPADBusMethodHandler) wpas_dbus_handler_abort_scan,
  2802. {
  2803. END_ARGS
  2804. }
  2805. },
  2806. { NULL, NULL, NULL, { END_ARGS } }
  2807. };
  2808. static const struct wpa_dbus_property_desc wpas_dbus_interface_properties[] = {
  2809. { "Capabilities", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{sv}",
  2810. wpas_dbus_getter_capabilities,
  2811. NULL,
  2812. NULL
  2813. },
  2814. { "State", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2815. wpas_dbus_getter_state,
  2816. NULL,
  2817. NULL
  2818. },
  2819. { "Scanning", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
  2820. wpas_dbus_getter_scanning,
  2821. NULL,
  2822. NULL
  2823. },
  2824. { "ApScan", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  2825. wpas_dbus_getter_ap_scan,
  2826. wpas_dbus_setter_ap_scan,
  2827. NULL
  2828. },
  2829. #ifdef CONFIG_IEEE80211W
  2830. { "Pmf", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  2831. wpas_dbus_getter_pmf,
  2832. wpas_dbus_setter_pmf,
  2833. NULL
  2834. },
  2835. #endif /* CONFIG_IEEE80211W */
  2836. { "BSSExpireAge", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  2837. wpas_dbus_getter_bss_expire_age,
  2838. wpas_dbus_setter_bss_expire_age,
  2839. NULL
  2840. },
  2841. { "BSSExpireCount", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  2842. wpas_dbus_getter_bss_expire_count,
  2843. wpas_dbus_setter_bss_expire_count,
  2844. NULL
  2845. },
  2846. { "Country", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2847. wpas_dbus_getter_country,
  2848. wpas_dbus_setter_country,
  2849. NULL
  2850. },
  2851. { "Ifname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2852. wpas_dbus_getter_ifname,
  2853. NULL,
  2854. NULL
  2855. },
  2856. { "Driver", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2857. wpas_dbus_getter_driver,
  2858. NULL,
  2859. NULL
  2860. },
  2861. { "BridgeIfname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2862. wpas_dbus_getter_bridge_ifname,
  2863. NULL,
  2864. NULL
  2865. },
  2866. { "ConfigFile", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2867. wpas_dbus_getter_config_file,
  2868. NULL,
  2869. NULL
  2870. },
  2871. { "CurrentBSS", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
  2872. wpas_dbus_getter_current_bss,
  2873. NULL,
  2874. NULL
  2875. },
  2876. { "CurrentNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
  2877. wpas_dbus_getter_current_network,
  2878. NULL,
  2879. NULL
  2880. },
  2881. { "CurrentAuthMode", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2882. wpas_dbus_getter_current_auth_mode,
  2883. NULL,
  2884. NULL
  2885. },
  2886. { "Blobs", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{say}",
  2887. wpas_dbus_getter_blobs,
  2888. NULL,
  2889. NULL
  2890. },
  2891. { "BSSs", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
  2892. wpas_dbus_getter_bsss,
  2893. NULL,
  2894. NULL
  2895. },
  2896. { "Networks", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
  2897. wpas_dbus_getter_networks,
  2898. NULL,
  2899. NULL
  2900. },
  2901. { "FastReauth", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
  2902. wpas_dbus_getter_fast_reauth,
  2903. wpas_dbus_setter_fast_reauth,
  2904. NULL
  2905. },
  2906. { "ScanInterval", WPAS_DBUS_NEW_IFACE_INTERFACE, "i",
  2907. wpas_dbus_getter_scan_interval,
  2908. wpas_dbus_setter_scan_interval,
  2909. NULL
  2910. },
  2911. { "PKCS11EnginePath", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2912. wpas_dbus_getter_pkcs11_engine_path,
  2913. NULL,
  2914. NULL
  2915. },
  2916. { "PKCS11ModulePath", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2917. wpas_dbus_getter_pkcs11_module_path,
  2918. NULL,
  2919. NULL
  2920. },
  2921. #ifdef CONFIG_WPS
  2922. { "ProcessCredentials", WPAS_DBUS_NEW_IFACE_WPS, "b",
  2923. wpas_dbus_getter_process_credentials,
  2924. wpas_dbus_setter_process_credentials,
  2925. NULL
  2926. },
  2927. { "ConfigMethods", WPAS_DBUS_NEW_IFACE_WPS, "s",
  2928. wpas_dbus_getter_config_methods,
  2929. wpas_dbus_setter_config_methods,
  2930. NULL
  2931. },
  2932. {
  2933. "DeviceName", WPAS_DBUS_NEW_IFACE_WPS, "s",
  2934. wpas_dbus_getter_wps_device_name,
  2935. wpas_dbus_setter_wps_device_name,
  2936. NULL
  2937. },
  2938. {
  2939. "Manufacturer", WPAS_DBUS_NEW_IFACE_WPS, "s",
  2940. wpas_dbus_getter_wps_manufacturer,
  2941. wpas_dbus_setter_wps_manufacturer,
  2942. NULL
  2943. },
  2944. {
  2945. "ModelName", WPAS_DBUS_NEW_IFACE_WPS, "s",
  2946. wpas_dbus_getter_wps_device_model_name,
  2947. wpas_dbus_setter_wps_device_model_name,
  2948. NULL
  2949. },
  2950. {
  2951. "ModelNumber", WPAS_DBUS_NEW_IFACE_WPS, "s",
  2952. wpas_dbus_getter_wps_device_model_number,
  2953. wpas_dbus_setter_wps_device_model_number,
  2954. NULL
  2955. },
  2956. {
  2957. "SerialNumber", WPAS_DBUS_NEW_IFACE_WPS, "s",
  2958. wpas_dbus_getter_wps_device_serial_number,
  2959. wpas_dbus_setter_wps_device_serial_number,
  2960. NULL
  2961. },
  2962. {
  2963. "DeviceType", WPAS_DBUS_NEW_IFACE_WPS, "ay",
  2964. wpas_dbus_getter_wps_device_device_type,
  2965. wpas_dbus_setter_wps_device_device_type,
  2966. NULL
  2967. },
  2968. #endif /* CONFIG_WPS */
  2969. #ifdef CONFIG_P2P
  2970. { "P2PDeviceConfig", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "a{sv}",
  2971. wpas_dbus_getter_p2p_device_config,
  2972. wpas_dbus_setter_p2p_device_config,
  2973. NULL
  2974. },
  2975. { "Peers", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
  2976. wpas_dbus_getter_p2p_peers,
  2977. NULL,
  2978. NULL
  2979. },
  2980. { "Role", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "s",
  2981. wpas_dbus_getter_p2p_role,
  2982. NULL,
  2983. NULL
  2984. },
  2985. { "Group", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
  2986. wpas_dbus_getter_p2p_group,
  2987. NULL,
  2988. NULL
  2989. },
  2990. { "PeerGO", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
  2991. wpas_dbus_getter_p2p_peergo,
  2992. NULL,
  2993. NULL
  2994. },
  2995. { "PersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
  2996. wpas_dbus_getter_persistent_groups,
  2997. NULL,
  2998. NULL
  2999. },
  3000. #endif /* CONFIG_P2P */
  3001. { "DisconnectReason", WPAS_DBUS_NEW_IFACE_INTERFACE, "i",
  3002. wpas_dbus_getter_disconnect_reason,
  3003. NULL,
  3004. NULL
  3005. },
  3006. { "AssocStatusCode", WPAS_DBUS_NEW_IFACE_INTERFACE, "i",
  3007. wpas_dbus_getter_assoc_status_code,
  3008. NULL,
  3009. NULL
  3010. },
  3011. { NULL, NULL, NULL, NULL, NULL, NULL }
  3012. };
  3013. static const struct wpa_dbus_signal_desc wpas_dbus_interface_signals[] = {
  3014. { "ScanDone", WPAS_DBUS_NEW_IFACE_INTERFACE,
  3015. {
  3016. { "success", "b", ARG_OUT },
  3017. END_ARGS
  3018. }
  3019. },
  3020. { "BSSAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  3021. {
  3022. { "path", "o", ARG_OUT },
  3023. { "properties", "a{sv}", ARG_OUT },
  3024. END_ARGS
  3025. }
  3026. },
  3027. { "BSSRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  3028. {
  3029. { "path", "o", ARG_OUT },
  3030. END_ARGS
  3031. }
  3032. },
  3033. { "BlobAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  3034. {
  3035. { "name", "s", ARG_OUT },
  3036. END_ARGS
  3037. }
  3038. },
  3039. { "BlobRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  3040. {
  3041. { "name", "s", ARG_OUT },
  3042. END_ARGS
  3043. }
  3044. },
  3045. { "NetworkAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  3046. {
  3047. { "path", "o", ARG_OUT },
  3048. { "properties", "a{sv}", ARG_OUT },
  3049. END_ARGS
  3050. }
  3051. },
  3052. { "NetworkRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  3053. {
  3054. { "path", "o", ARG_OUT },
  3055. END_ARGS
  3056. }
  3057. },
  3058. { "NetworkSelected", WPAS_DBUS_NEW_IFACE_INTERFACE,
  3059. {
  3060. { "path", "o", ARG_OUT },
  3061. END_ARGS
  3062. }
  3063. },
  3064. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  3065. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_INTERFACE,
  3066. {
  3067. { "properties", "a{sv}", ARG_OUT },
  3068. END_ARGS
  3069. }
  3070. },
  3071. #ifdef CONFIG_WPS
  3072. { "Event", WPAS_DBUS_NEW_IFACE_WPS,
  3073. {
  3074. { "name", "s", ARG_OUT },
  3075. { "args", "a{sv}", ARG_OUT },
  3076. END_ARGS
  3077. }
  3078. },
  3079. { "Credentials", WPAS_DBUS_NEW_IFACE_WPS,
  3080. {
  3081. { "credentials", "a{sv}", ARG_OUT },
  3082. END_ARGS
  3083. }
  3084. },
  3085. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  3086. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_WPS,
  3087. {
  3088. { "properties", "a{sv}", ARG_OUT },
  3089. END_ARGS
  3090. }
  3091. },
  3092. #endif /* CONFIG_WPS */
  3093. #ifdef CONFIG_P2P
  3094. { "DeviceFound", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3095. {
  3096. { "path", "o", ARG_OUT },
  3097. END_ARGS
  3098. }
  3099. },
  3100. { "DeviceFoundProperties", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3101. {
  3102. { "path", "o", ARG_OUT },
  3103. { "properties", "a{sv}", ARG_OUT },
  3104. END_ARGS
  3105. }
  3106. },
  3107. { "DeviceLost", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3108. {
  3109. { "path", "o", ARG_OUT },
  3110. END_ARGS
  3111. }
  3112. },
  3113. { "FindStopped", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3114. {
  3115. END_ARGS
  3116. }
  3117. },
  3118. { "ProvisionDiscoveryRequestDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3119. {
  3120. { "peer_object", "o", ARG_OUT },
  3121. { "pin", "s", ARG_OUT },
  3122. END_ARGS
  3123. }
  3124. },
  3125. { "ProvisionDiscoveryResponseDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3126. {
  3127. { "peer_object", "o", ARG_OUT },
  3128. { "pin", "s", ARG_OUT },
  3129. END_ARGS
  3130. }
  3131. },
  3132. { "ProvisionDiscoveryRequestEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3133. {
  3134. { "peer_object", "o", ARG_OUT },
  3135. END_ARGS
  3136. }
  3137. },
  3138. { "ProvisionDiscoveryResponseEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3139. {
  3140. { "peer_object", "o", ARG_OUT },
  3141. END_ARGS
  3142. }
  3143. },
  3144. { "ProvisionDiscoveryPBCRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3145. {
  3146. { "peer_object", "o", ARG_OUT },
  3147. END_ARGS
  3148. }
  3149. },
  3150. { "ProvisionDiscoveryPBCResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3151. {
  3152. { "peer_object", "o", ARG_OUT },
  3153. END_ARGS
  3154. }
  3155. },
  3156. { "ProvisionDiscoveryFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3157. {
  3158. { "peer_object", "o", ARG_OUT },
  3159. { "status", "i", ARG_OUT },
  3160. END_ARGS
  3161. }
  3162. },
  3163. { "GroupStarted", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3164. {
  3165. { "properties", "a{sv}", ARG_OUT },
  3166. END_ARGS
  3167. }
  3168. },
  3169. { "GroupFormationFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3170. {
  3171. { "reason", "s", ARG_OUT },
  3172. END_ARGS
  3173. }
  3174. },
  3175. { "GONegotiationSuccess", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3176. {
  3177. { "properties", "a{sv}", ARG_OUT },
  3178. END_ARGS
  3179. }
  3180. },
  3181. { "GONegotiationFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3182. {
  3183. { "properties", "a{sv}", ARG_OUT },
  3184. END_ARGS
  3185. }
  3186. },
  3187. { "GONegotiationRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3188. {
  3189. { "path", "o", ARG_OUT },
  3190. { "dev_passwd_id", "q", ARG_OUT },
  3191. { "device_go_intent", "y", ARG_OUT },
  3192. END_ARGS
  3193. }
  3194. },
  3195. { "InvitationResult", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3196. {
  3197. { "invite_result", "a{sv}", ARG_OUT },
  3198. END_ARGS
  3199. }
  3200. },
  3201. { "GroupFinished", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3202. {
  3203. { "properties", "a{sv}", ARG_OUT },
  3204. END_ARGS
  3205. }
  3206. },
  3207. { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3208. {
  3209. { "sd_request", "a{sv}", ARG_OUT },
  3210. END_ARGS
  3211. }
  3212. },
  3213. { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3214. {
  3215. { "sd_response", "a{sv}", ARG_OUT },
  3216. END_ARGS
  3217. }
  3218. },
  3219. { "PersistentGroupAdded", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3220. {
  3221. { "path", "o", ARG_OUT },
  3222. { "properties", "a{sv}", ARG_OUT },
  3223. END_ARGS
  3224. }
  3225. },
  3226. { "PersistentGroupRemoved", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3227. {
  3228. { "path", "o", ARG_OUT },
  3229. END_ARGS
  3230. }
  3231. },
  3232. { "WpsFailed", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3233. {
  3234. { "name", "s", ARG_OUT },
  3235. { "args", "a{sv}", ARG_OUT },
  3236. END_ARGS
  3237. }
  3238. },
  3239. { "InvitationReceived", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3240. {
  3241. { "properties", "a{sv}", ARG_OUT },
  3242. END_ARGS
  3243. }
  3244. },
  3245. #endif /* CONFIG_P2P */
  3246. #ifdef CONFIG_AP
  3247. { "ProbeRequest", WPAS_DBUS_NEW_IFACE_INTERFACE,
  3248. {
  3249. { "args", "a{sv}", ARG_OUT },
  3250. END_ARGS
  3251. }
  3252. },
  3253. #endif /* CONFIG_AP */
  3254. { "Certification", WPAS_DBUS_NEW_IFACE_INTERFACE,
  3255. {
  3256. { "certification", "a{sv}", ARG_OUT },
  3257. END_ARGS
  3258. }
  3259. },
  3260. { "EAP", WPAS_DBUS_NEW_IFACE_INTERFACE,
  3261. {
  3262. { "status", "s", ARG_OUT },
  3263. { "parameter", "s", ARG_OUT },
  3264. END_ARGS
  3265. }
  3266. },
  3267. { "StaAuthorized", WPAS_DBUS_NEW_IFACE_INTERFACE,
  3268. {
  3269. { "name", "s", ARG_OUT },
  3270. END_ARGS
  3271. }
  3272. },
  3273. { "StaDeauthorized", WPAS_DBUS_NEW_IFACE_INTERFACE,
  3274. {
  3275. { "name", "s", ARG_OUT },
  3276. END_ARGS
  3277. }
  3278. },
  3279. { "NetworkRequest", WPAS_DBUS_NEW_IFACE_INTERFACE,
  3280. {
  3281. { "path", "o", ARG_OUT },
  3282. { "field", "s", ARG_OUT },
  3283. { "text", "s", ARG_OUT },
  3284. END_ARGS
  3285. }
  3286. },
  3287. #ifdef CONFIG_MESH
  3288. { "MeshGroupStarted", WPAS_DBUS_NEW_IFACE_MESH,
  3289. {
  3290. { "args", "a{sv}", ARG_OUT },
  3291. END_ARGS
  3292. }
  3293. },
  3294. { "MeshGroupRemoved", WPAS_DBUS_NEW_IFACE_MESH,
  3295. {
  3296. { "args", "a{sv}", ARG_OUT },
  3297. END_ARGS
  3298. }
  3299. },
  3300. { "MeshPeerConnected", WPAS_DBUS_NEW_IFACE_MESH,
  3301. {
  3302. { "args", "a{sv}", ARG_OUT },
  3303. END_ARGS
  3304. }
  3305. },
  3306. #endif /* CONFIG_MESH */
  3307. { NULL, NULL, { END_ARGS } }
  3308. };
  3309. static int wpa_dbus_ctrl_iface_props_init(struct wpas_dbus_priv *priv)
  3310. {
  3311. size_t all_size;
  3312. unsigned int i, j, count, num_const, num_globals;
  3313. const char *global_name;
  3314. static const char * const ignored_globals[] = {
  3315. "bss_expiration_age", "bss_expiration_scan_count",
  3316. "ap_scan", "country", "fast_reauth",
  3317. "pkcs11_engine_path", "pkcs11_module_path"
  3318. };
  3319. /* wpas_dbus_interface_properties terminates with a NULL element */
  3320. num_const = ARRAY_SIZE(wpas_dbus_interface_properties) - 1;
  3321. num_globals = wpa_config_get_num_global_field_names();
  3322. priv->globals_start = num_const;
  3323. /* allocate enough for all properties + terminating NULL element */
  3324. all_size = (num_globals + num_const + 1) *
  3325. sizeof(wpas_dbus_interface_properties[0]);
  3326. priv->all_interface_properties = os_zalloc(all_size);
  3327. if (!priv->all_interface_properties) {
  3328. wpa_printf(MSG_ERROR,
  3329. "dbus: Not enough memory for interface properties");
  3330. return -1;
  3331. }
  3332. /* Copy constant interface properties to the start of the array */
  3333. os_memcpy(priv->all_interface_properties,
  3334. wpas_dbus_interface_properties,
  3335. sizeof(wpas_dbus_interface_properties));
  3336. /* Dynamically construct interface global properties */
  3337. for (i = 0, count = num_const; i < num_globals; i++) {
  3338. struct wpa_dbus_property_desc *desc;
  3339. int no_var = 0;
  3340. /* ignore globals that are actually just methods */
  3341. global_name = wpa_config_get_global_field_name(i, &no_var);
  3342. if (no_var)
  3343. continue;
  3344. /* Ignore fields already explicitly exposed */
  3345. for (j = 0; j < ARRAY_SIZE(ignored_globals); j++) {
  3346. if (os_strcmp(global_name, ignored_globals[j]) == 0)
  3347. break;
  3348. }
  3349. if (j < ARRAY_SIZE(ignored_globals))
  3350. continue;
  3351. desc = &priv->all_interface_properties[count++];
  3352. desc->dbus_property = uscore_to_dbus(global_name);
  3353. if (!desc->dbus_property) {
  3354. wpa_printf(MSG_ERROR,
  3355. "dbus: Not enough memory for D-Bus property name");
  3356. goto error;
  3357. }
  3358. desc->dbus_interface = WPAS_DBUS_NEW_IFACE_INTERFACE;
  3359. desc->type = "s";
  3360. desc->getter = wpas_dbus_getter_iface_global;
  3361. desc->setter = wpas_dbus_setter_iface_global;
  3362. desc->data = global_name;
  3363. }
  3364. return 0;
  3365. error:
  3366. wpa_dbus_ctrl_iface_props_deinit(priv);
  3367. return -1;
  3368. }
  3369. /**
  3370. * wpas_dbus_register_interface - Register an interface with D-Bus
  3371. * @wpa_s: wpa_supplicant interface structure
  3372. * Returns: 0 on success, -1 on failure
  3373. */
  3374. int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s)
  3375. {
  3376. struct wpa_dbus_object_desc *obj_desc = NULL;
  3377. struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus;
  3378. int next;
  3379. /* Do nothing if the control interface is not turned on */
  3380. if (ctrl_iface == NULL)
  3381. return 0;
  3382. /* Create and set the interface's object path */
  3383. wpa_s->dbus_new_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
  3384. if (wpa_s->dbus_new_path == NULL)
  3385. return -1;
  3386. next = ctrl_iface->next_objid++;
  3387. os_snprintf(wpa_s->dbus_new_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3388. WPAS_DBUS_NEW_PATH_INTERFACES "/%u",
  3389. next);
  3390. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  3391. if (!obj_desc) {
  3392. wpa_printf(MSG_ERROR,
  3393. "Not enough memory to create object description");
  3394. goto err;
  3395. }
  3396. wpas_dbus_register(obj_desc, wpa_s, NULL, wpas_dbus_interface_methods,
  3397. ctrl_iface->all_interface_properties,
  3398. wpas_dbus_interface_signals);
  3399. wpa_printf(MSG_DEBUG, "dbus: Register interface object '%s'",
  3400. wpa_s->dbus_new_path);
  3401. if (wpa_dbus_register_object_per_iface(ctrl_iface,
  3402. wpa_s->dbus_new_path,
  3403. wpa_s->ifname, obj_desc))
  3404. goto err;
  3405. wpas_dbus_signal_interface_added(wpa_s);
  3406. return 0;
  3407. err:
  3408. os_free(wpa_s->dbus_new_path);
  3409. wpa_s->dbus_new_path = NULL;
  3410. free_dbus_object_desc(obj_desc);
  3411. return -1;
  3412. }
  3413. /**
  3414. * wpas_dbus_unregister_interface - Unregister the interface from D-Bus
  3415. * @wpa_s: wpa_supplicant interface structure
  3416. * Returns: 0 on success, -1 on failure
  3417. */
  3418. int wpas_dbus_unregister_interface(struct wpa_supplicant *wpa_s)
  3419. {
  3420. struct wpas_dbus_priv *ctrl_iface;
  3421. /* Do nothing if the control interface is not turned on */
  3422. if (wpa_s == NULL || wpa_s->global == NULL)
  3423. return 0;
  3424. ctrl_iface = wpa_s->global->dbus;
  3425. if (ctrl_iface == NULL || wpa_s->dbus_new_path == NULL)
  3426. return 0;
  3427. wpa_printf(MSG_DEBUG, "dbus: Unregister interface object '%s'",
  3428. wpa_s->dbus_new_path);
  3429. #ifdef CONFIG_AP
  3430. if (wpa_s->preq_notify_peer) {
  3431. wpas_dbus_unsubscribe_noc(ctrl_iface);
  3432. os_free(wpa_s->preq_notify_peer);
  3433. wpa_s->preq_notify_peer = NULL;
  3434. }
  3435. #endif /* CONFIG_AP */
  3436. if (wpa_dbus_unregister_object_per_iface(ctrl_iface,
  3437. wpa_s->dbus_new_path))
  3438. return -1;
  3439. wpas_dbus_signal_interface_removed(wpa_s);
  3440. os_free(wpa_s->dbus_new_path);
  3441. wpa_s->dbus_new_path = NULL;
  3442. return 0;
  3443. }
  3444. #ifdef CONFIG_P2P
  3445. static const struct wpa_dbus_property_desc wpas_dbus_p2p_peer_properties[] = {
  3446. { "DeviceName", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
  3447. wpas_dbus_getter_p2p_peer_device_name,
  3448. NULL,
  3449. NULL
  3450. },
  3451. { "Manufacturer", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
  3452. wpas_dbus_getter_p2p_peer_manufacturer,
  3453. NULL,
  3454. NULL
  3455. },
  3456. { "ModelName", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
  3457. wpas_dbus_getter_p2p_peer_modelname,
  3458. NULL,
  3459. NULL
  3460. },
  3461. { "ModelNumber", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
  3462. wpas_dbus_getter_p2p_peer_modelnumber,
  3463. NULL,
  3464. NULL
  3465. },
  3466. { "SerialNumber", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
  3467. wpas_dbus_getter_p2p_peer_serialnumber,
  3468. NULL,
  3469. NULL
  3470. },
  3471. { "PrimaryDeviceType", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
  3472. wpas_dbus_getter_p2p_peer_primary_device_type,
  3473. NULL,
  3474. NULL
  3475. },
  3476. { "config_method", WPAS_DBUS_NEW_IFACE_P2P_PEER, "q",
  3477. wpas_dbus_getter_p2p_peer_config_method,
  3478. NULL,
  3479. NULL
  3480. },
  3481. { "level", WPAS_DBUS_NEW_IFACE_P2P_PEER, "i",
  3482. wpas_dbus_getter_p2p_peer_level,
  3483. NULL,
  3484. NULL
  3485. },
  3486. { "devicecapability", WPAS_DBUS_NEW_IFACE_P2P_PEER, "y",
  3487. wpas_dbus_getter_p2p_peer_device_capability,
  3488. NULL,
  3489. NULL
  3490. },
  3491. { "groupcapability", WPAS_DBUS_NEW_IFACE_P2P_PEER, "y",
  3492. wpas_dbus_getter_p2p_peer_group_capability,
  3493. NULL,
  3494. NULL
  3495. },
  3496. { "SecondaryDeviceTypes", WPAS_DBUS_NEW_IFACE_P2P_PEER, "aay",
  3497. wpas_dbus_getter_p2p_peer_secondary_device_types,
  3498. NULL,
  3499. NULL
  3500. },
  3501. { "VendorExtension", WPAS_DBUS_NEW_IFACE_P2P_PEER, "aay",
  3502. wpas_dbus_getter_p2p_peer_vendor_extension,
  3503. NULL,
  3504. NULL
  3505. },
  3506. { "IEs", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
  3507. wpas_dbus_getter_p2p_peer_ies,
  3508. NULL,
  3509. NULL
  3510. },
  3511. { "DeviceAddress", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
  3512. wpas_dbus_getter_p2p_peer_device_address,
  3513. NULL,
  3514. NULL
  3515. },
  3516. { "Groups", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ao",
  3517. wpas_dbus_getter_p2p_peer_groups,
  3518. NULL,
  3519. NULL
  3520. },
  3521. { NULL, NULL, NULL, NULL, NULL, NULL }
  3522. };
  3523. static const struct wpa_dbus_signal_desc wpas_dbus_p2p_peer_signals[] = {
  3524. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  3525. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_P2P_PEER,
  3526. {
  3527. { "properties", "a{sv}", ARG_OUT },
  3528. END_ARGS
  3529. }
  3530. },
  3531. { NULL, NULL, { END_ARGS } }
  3532. };
  3533. /**
  3534. * wpas_dbus_signal_peer - Send a peer related event signal
  3535. * @wpa_s: %wpa_supplicant network interface data
  3536. * @dev: peer device object
  3537. * @interface: name of the interface emitting this signal.
  3538. * In case of peer objects, it would be emitted by either
  3539. * the "interface object" or by "peer objects"
  3540. * @sig_name: signal name - DeviceFound
  3541. * @properties: Whether to add a second argument with object properties
  3542. *
  3543. * Notify listeners about event related with p2p peer device
  3544. */
  3545. static void wpas_dbus_signal_peer(struct wpa_supplicant *wpa_s,
  3546. const u8 *dev_addr, const char *interface,
  3547. const char *sig_name, int properties)
  3548. {
  3549. struct wpas_dbus_priv *iface;
  3550. DBusMessage *msg;
  3551. DBusMessageIter iter;
  3552. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  3553. if (wpa_s->p2p_mgmt)
  3554. wpa_s = wpa_s->parent;
  3555. iface = wpa_s->global->dbus;
  3556. /* Do nothing if the control interface is not turned on */
  3557. if (iface == NULL || !wpa_s->dbus_new_path)
  3558. return;
  3559. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3560. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  3561. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  3562. msg = dbus_message_new_signal(wpa_s->dbus_new_path, interface,
  3563. sig_name);
  3564. if (msg == NULL)
  3565. return;
  3566. dbus_message_iter_init_append(msg, &iter);
  3567. path = peer_obj_path;
  3568. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  3569. &path) ||
  3570. (properties && !wpa_dbus_get_object_properties(
  3571. iface, peer_obj_path, WPAS_DBUS_NEW_IFACE_P2P_PEER,
  3572. &iter)))
  3573. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  3574. else
  3575. dbus_connection_send(iface->con, msg, NULL);
  3576. dbus_message_unref(msg);
  3577. }
  3578. /**
  3579. * wpas_dbus_signal_peer_found - Send a peer found signal
  3580. * @wpa_s: %wpa_supplicant network interface data
  3581. * @dev_addr: Peer P2P Device Address
  3582. *
  3583. * Notify listeners about find a p2p peer device found
  3584. */
  3585. void wpas_dbus_signal_peer_device_found(struct wpa_supplicant *wpa_s,
  3586. const u8 *dev_addr)
  3587. {
  3588. wpas_dbus_signal_peer(wpa_s, dev_addr,
  3589. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3590. "DeviceFound", FALSE);
  3591. wpas_dbus_signal_peer(wpa_s, dev_addr,
  3592. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3593. "DeviceFoundProperties", TRUE);
  3594. }
  3595. /**
  3596. * wpas_dbus_signal_peer_lost - Send a peer lost signal
  3597. * @wpa_s: %wpa_supplicant network interface data
  3598. * @dev_addr: Peer P2P Device Address
  3599. *
  3600. * Notify listeners about lost a p2p peer device
  3601. */
  3602. void wpas_dbus_signal_peer_device_lost(struct wpa_supplicant *wpa_s,
  3603. const u8 *dev_addr)
  3604. {
  3605. wpas_dbus_signal_peer(wpa_s, dev_addr,
  3606. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3607. "DeviceLost", FALSE);
  3608. }
  3609. /**
  3610. * wpas_dbus_register_peer - Register a discovered peer object with dbus
  3611. * @wpa_s: wpa_supplicant interface structure
  3612. * @dev_addr: P2P Device Address of the peer
  3613. * Returns: 0 on success, -1 on failure
  3614. *
  3615. * Registers network representing object with dbus
  3616. */
  3617. int wpas_dbus_register_peer(struct wpa_supplicant *wpa_s, const u8 *dev_addr)
  3618. {
  3619. struct wpas_dbus_priv *ctrl_iface;
  3620. struct wpa_dbus_object_desc *obj_desc;
  3621. struct peer_handler_args *arg;
  3622. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3623. /* Do nothing if the control interface is not turned on */
  3624. if (wpa_s == NULL || wpa_s->global == NULL)
  3625. return 0;
  3626. ctrl_iface = wpa_s->global->dbus;
  3627. if (ctrl_iface == NULL)
  3628. return 0;
  3629. wpa_s = wpa_s->parent->parent;
  3630. if (!wpa_s->dbus_new_path)
  3631. return 0;
  3632. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3633. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  3634. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  3635. wpa_printf(MSG_INFO, "dbus: Register peer object '%s'",
  3636. peer_obj_path);
  3637. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  3638. if (!obj_desc) {
  3639. wpa_printf(MSG_ERROR,
  3640. "Not enough memory to create object description");
  3641. goto err;
  3642. }
  3643. /* allocate memory for handlers arguments */
  3644. arg = os_zalloc(sizeof(struct peer_handler_args));
  3645. if (!arg) {
  3646. wpa_printf(MSG_ERROR,
  3647. "Not enough memory to create arguments for method");
  3648. goto err;
  3649. }
  3650. arg->wpa_s = wpa_s;
  3651. os_memcpy(arg->p2p_device_addr, dev_addr, ETH_ALEN);
  3652. wpas_dbus_register(obj_desc, arg, wpa_dbus_free,
  3653. NULL,
  3654. wpas_dbus_p2p_peer_properties,
  3655. wpas_dbus_p2p_peer_signals);
  3656. if (wpa_dbus_register_object_per_iface(ctrl_iface, peer_obj_path,
  3657. wpa_s->ifname, obj_desc))
  3658. goto err;
  3659. return 0;
  3660. err:
  3661. free_dbus_object_desc(obj_desc);
  3662. return -1;
  3663. }
  3664. /**
  3665. * wpas_dbus_unregister_peer - Unregister a peer object with dbus
  3666. * @wpa_s: wpa_supplicant interface structure
  3667. * @dev_addr: p2p device addr
  3668. * Returns: 0 on success, -1 on failure
  3669. *
  3670. * Registers network representing object with dbus
  3671. */
  3672. int wpas_dbus_unregister_peer(struct wpa_supplicant *wpa_s,
  3673. const u8 *dev_addr)
  3674. {
  3675. struct wpas_dbus_priv *ctrl_iface;
  3676. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3677. int ret;
  3678. /* Do nothing if the control interface is not turned on */
  3679. if (wpa_s == NULL || wpa_s->global == NULL)
  3680. return 0;
  3681. wpa_s = wpa_s->parent->parent;
  3682. if (!wpa_s->dbus_new_path)
  3683. return 0;
  3684. ctrl_iface = wpa_s->global->dbus;
  3685. if (ctrl_iface == NULL)
  3686. return 0;
  3687. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3688. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  3689. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  3690. wpa_printf(MSG_INFO, "dbus: Unregister peer object '%s'",
  3691. peer_obj_path);
  3692. ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, peer_obj_path);
  3693. return ret;
  3694. }
  3695. /**
  3696. * wpas_dbus_signal_p2p_find_stopped - Send P2P Find stopped signal
  3697. * @wpa_s: %wpa_supplicant network interface data
  3698. *
  3699. * Notify listeners about P2P Find stopped
  3700. */
  3701. void wpas_dbus_signal_p2p_find_stopped(struct wpa_supplicant *wpa_s)
  3702. {
  3703. struct wpas_dbus_priv *iface;
  3704. DBusMessage *msg;
  3705. iface = wpa_s->global->dbus;
  3706. /* Do nothing if the control interface is not turned on */
  3707. if (iface == NULL || !wpa_s->dbus_new_path)
  3708. return;
  3709. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  3710. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3711. "FindStopped");
  3712. if (msg == NULL)
  3713. return;
  3714. dbus_connection_send(iface->con, msg, NULL);
  3715. dbus_message_unref(msg);
  3716. }
  3717. /**
  3718. * wpas_dbus_signal_peer_groups_changed - Send peer group change property signal
  3719. * @wpa_s: %wpa_supplicant network interface data
  3720. * @dev_addr: P2P Device Address
  3721. *
  3722. * Notify listeners about peer Groups property changes.
  3723. */
  3724. void wpas_dbus_signal_peer_groups_changed(struct wpa_supplicant *wpa_s,
  3725. const u8 *dev_addr)
  3726. {
  3727. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3728. if (wpa_s->p2p_mgmt)
  3729. wpa_s = wpa_s->parent;
  3730. if (!wpa_s->dbus_new_path)
  3731. return;
  3732. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3733. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  3734. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  3735. wpa_dbus_mark_property_changed(wpa_s->global->dbus, peer_obj_path,
  3736. WPAS_DBUS_NEW_IFACE_P2P_PEER, "Groups");
  3737. }
  3738. static const struct wpa_dbus_property_desc wpas_dbus_p2p_group_properties[] = {
  3739. { "Members", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ao",
  3740. wpas_dbus_getter_p2p_group_members,
  3741. NULL,
  3742. NULL
  3743. },
  3744. { "Group", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "o",
  3745. wpas_dbus_getter_p2p_group,
  3746. NULL,
  3747. NULL
  3748. },
  3749. { "Role", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "s",
  3750. wpas_dbus_getter_p2p_role,
  3751. NULL,
  3752. NULL
  3753. },
  3754. { "SSID", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
  3755. wpas_dbus_getter_p2p_group_ssid,
  3756. NULL,
  3757. NULL
  3758. },
  3759. { "BSSID", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
  3760. wpas_dbus_getter_p2p_group_bssid,
  3761. NULL,
  3762. NULL
  3763. },
  3764. { "Frequency", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "q",
  3765. wpas_dbus_getter_p2p_group_frequency,
  3766. NULL,
  3767. NULL
  3768. },
  3769. { "Passphrase", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "s",
  3770. wpas_dbus_getter_p2p_group_passphrase,
  3771. NULL,
  3772. NULL
  3773. },
  3774. { "PSK", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
  3775. wpas_dbus_getter_p2p_group_psk,
  3776. NULL,
  3777. NULL
  3778. },
  3779. { "WPSVendorExtensions", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "aay",
  3780. wpas_dbus_getter_p2p_group_vendor_ext,
  3781. wpas_dbus_setter_p2p_group_vendor_ext,
  3782. NULL
  3783. },
  3784. { NULL, NULL, NULL, NULL, NULL, NULL }
  3785. };
  3786. static const struct wpa_dbus_signal_desc wpas_dbus_p2p_group_signals[] = {
  3787. { "PeerJoined", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
  3788. {
  3789. { "peer", "o", ARG_OUT },
  3790. END_ARGS
  3791. }
  3792. },
  3793. { "PeerDisconnected", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
  3794. {
  3795. { "peer", "o", ARG_OUT },
  3796. END_ARGS
  3797. }
  3798. },
  3799. { NULL, NULL, { END_ARGS } }
  3800. };
  3801. /**
  3802. * wpas_dbus_register_p2p_group - Register a p2p group object with dbus
  3803. * @wpa_s: wpa_supplicant interface structure
  3804. * @ssid: SSID struct
  3805. * Returns: 0 on success, -1 on failure
  3806. *
  3807. * Registers p2p group representing object with dbus
  3808. */
  3809. void wpas_dbus_register_p2p_group(struct wpa_supplicant *wpa_s,
  3810. struct wpa_ssid *ssid)
  3811. {
  3812. struct wpas_dbus_priv *ctrl_iface;
  3813. struct wpa_dbus_object_desc *obj_desc;
  3814. char group_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3815. /* Do nothing if the control interface is not turned on */
  3816. if (wpa_s == NULL || wpa_s->global == NULL)
  3817. return;
  3818. ctrl_iface = wpa_s->global->dbus;
  3819. if (ctrl_iface == NULL)
  3820. return;
  3821. if (wpa_s->dbus_groupobj_path) {
  3822. wpa_printf(MSG_INFO, "%s: Group object '%s' already exists",
  3823. __func__, wpa_s->dbus_groupobj_path);
  3824. return;
  3825. }
  3826. if (wpas_dbus_get_group_obj_path(wpa_s, ssid, group_obj_path) < 0)
  3827. return;
  3828. wpa_s->dbus_groupobj_path = os_strdup(group_obj_path);
  3829. if (wpa_s->dbus_groupobj_path == NULL)
  3830. return;
  3831. wpa_printf(MSG_INFO, "dbus: Register group object '%s'",
  3832. group_obj_path);
  3833. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  3834. if (!obj_desc) {
  3835. wpa_printf(MSG_ERROR,
  3836. "Not enough memory to create object description");
  3837. goto err;
  3838. }
  3839. wpas_dbus_register(obj_desc, wpa_s, NULL, NULL,
  3840. wpas_dbus_p2p_group_properties,
  3841. wpas_dbus_p2p_group_signals);
  3842. if (wpa_dbus_register_object_per_iface(ctrl_iface, group_obj_path,
  3843. wpa_s->ifname, obj_desc))
  3844. goto err;
  3845. return;
  3846. err:
  3847. if (wpa_s->dbus_groupobj_path) {
  3848. os_free(wpa_s->dbus_groupobj_path);
  3849. wpa_s->dbus_groupobj_path = NULL;
  3850. }
  3851. free_dbus_object_desc(obj_desc);
  3852. }
  3853. /**
  3854. * wpas_dbus_unregister_p2p_group - Unregister a p2p group object from dbus
  3855. * @wpa_s: wpa_supplicant interface structure
  3856. * @ssid: network name of the p2p group started
  3857. */
  3858. void wpas_dbus_unregister_p2p_group(struct wpa_supplicant *wpa_s,
  3859. const struct wpa_ssid *ssid)
  3860. {
  3861. struct wpas_dbus_priv *ctrl_iface;
  3862. /* Do nothing if the control interface is not turned on */
  3863. if (wpa_s == NULL || wpa_s->global == NULL)
  3864. return;
  3865. if (wpa_s->p2p_mgmt)
  3866. wpa_s = wpa_s->parent;
  3867. ctrl_iface = wpa_s->global->dbus;
  3868. if (ctrl_iface == NULL)
  3869. return;
  3870. if (!wpa_s->dbus_groupobj_path) {
  3871. wpa_printf(MSG_DEBUG,
  3872. "%s: Group object '%s' already unregistered",
  3873. __func__, wpa_s->dbus_groupobj_path);
  3874. return;
  3875. }
  3876. peer_groups_changed(wpa_s);
  3877. wpa_printf(MSG_DEBUG, "dbus: Unregister group object '%s'",
  3878. wpa_s->dbus_groupobj_path);
  3879. wpa_dbus_unregister_object_per_iface(ctrl_iface,
  3880. wpa_s->dbus_groupobj_path);
  3881. os_free(wpa_s->dbus_groupobj_path);
  3882. wpa_s->dbus_groupobj_path = NULL;
  3883. }
  3884. static const struct wpa_dbus_property_desc
  3885. wpas_dbus_persistent_group_properties[] = {
  3886. { "Properties", WPAS_DBUS_NEW_IFACE_PERSISTENT_GROUP, "a{sv}",
  3887. wpas_dbus_getter_persistent_group_properties,
  3888. wpas_dbus_setter_persistent_group_properties,
  3889. NULL
  3890. },
  3891. { NULL, NULL, NULL, NULL, NULL, NULL }
  3892. };
  3893. /* No signals intended for persistent group objects */
  3894. /**
  3895. * wpas_dbus_register_persistent_group - Register a configured(saved)
  3896. * persistent group with dbus
  3897. * @wpa_s: wpa_supplicant interface structure
  3898. * @ssid: persistent group (still represented as a network within wpa)
  3899. * configuration data
  3900. * Returns: 0 on success, -1 on failure
  3901. *
  3902. * Registers a persistent group representing object with dbus.
  3903. */
  3904. int wpas_dbus_register_persistent_group(struct wpa_supplicant *wpa_s,
  3905. struct wpa_ssid *ssid)
  3906. {
  3907. struct wpas_dbus_priv *ctrl_iface;
  3908. struct wpa_dbus_object_desc *obj_desc;
  3909. struct network_handler_args *arg;
  3910. char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3911. /* Do nothing if the control interface is not turned on */
  3912. if (wpa_s == NULL || wpa_s->global == NULL)
  3913. return 0;
  3914. wpa_s = wpa_s->parent->parent;
  3915. if (!wpa_s->dbus_new_path)
  3916. return 0;
  3917. /* Make sure ssid is a persistent group */
  3918. if (ssid->disabled != 2 && !ssid->p2p_persistent_group)
  3919. return -1; /* should we return w/o complaining? */
  3920. if (wpa_s->p2p_mgmt)
  3921. wpa_s = wpa_s->parent;
  3922. ctrl_iface = wpa_s->global->dbus;
  3923. if (ctrl_iface == NULL)
  3924. return 0;
  3925. /*
  3926. * Intentionally not coming up with different numbering scheme
  3927. * for persistent groups.
  3928. */
  3929. os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3930. "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
  3931. wpa_s->dbus_new_path, ssid->id);
  3932. wpa_printf(MSG_DEBUG, "dbus: Register persistent group object '%s'",
  3933. pgrp_obj_path);
  3934. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  3935. if (!obj_desc) {
  3936. wpa_printf(MSG_ERROR,
  3937. "dbus: Not enough memory to create object description");
  3938. goto err;
  3939. }
  3940. /*
  3941. * Reusing the same context structure as that for networks
  3942. * since these are represented using same data structure.
  3943. */
  3944. /* allocate memory for handlers arguments */
  3945. arg = os_zalloc(sizeof(struct network_handler_args));
  3946. if (!arg) {
  3947. wpa_printf(MSG_ERROR,
  3948. "dbus: Not enough memory to create arguments for method");
  3949. goto err;
  3950. }
  3951. arg->wpa_s = wpa_s;
  3952. arg->ssid = ssid;
  3953. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  3954. wpas_dbus_persistent_group_properties,
  3955. NULL);
  3956. if (wpa_dbus_register_object_per_iface(ctrl_iface, pgrp_obj_path,
  3957. wpa_s->ifname, obj_desc))
  3958. goto err;
  3959. wpas_dbus_signal_persistent_group_added(wpa_s, ssid->id);
  3960. return 0;
  3961. err:
  3962. free_dbus_object_desc(obj_desc);
  3963. return -1;
  3964. }
  3965. /**
  3966. * wpas_dbus_unregister_persistent_group - Unregister a persistent_group
  3967. * from dbus
  3968. * @wpa_s: wpa_supplicant interface structure
  3969. * @nid: network id
  3970. * Returns: 0 on success, -1 on failure
  3971. *
  3972. * Unregisters persistent group representing object from dbus
  3973. *
  3974. * NOTE: There is a slight issue with the semantics here. While the
  3975. * implementation simply means the persistent group is unloaded from memory,
  3976. * it should not get interpreted as the group is actually being erased/removed
  3977. * from persistent storage as well.
  3978. */
  3979. int wpas_dbus_unregister_persistent_group(struct wpa_supplicant *wpa_s,
  3980. int nid)
  3981. {
  3982. struct wpas_dbus_priv *ctrl_iface;
  3983. char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3984. int ret;
  3985. /* Do nothing if the control interface is not turned on */
  3986. if (wpa_s == NULL || wpa_s->global == NULL)
  3987. return 0;
  3988. wpa_s = wpa_s->parent->parent;
  3989. ctrl_iface = wpa_s->global->dbus;
  3990. if (ctrl_iface == NULL || !wpa_s->dbus_new_path)
  3991. return 0;
  3992. os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3993. "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
  3994. wpa_s->dbus_new_path, nid);
  3995. wpa_printf(MSG_DEBUG, "dbus: Unregister persistent group object '%s'",
  3996. pgrp_obj_path);
  3997. ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, pgrp_obj_path);
  3998. if (!ret)
  3999. wpas_dbus_signal_persistent_group_removed(wpa_s, nid);
  4000. return ret;
  4001. }
  4002. #endif /* CONFIG_P2P */