dbus_new.c 103 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958
  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. *
  503. * Sends Event dbus signal with name "fail" and dictionary containing
  504. * "msg field with fail message number (int32) as arguments
  505. */
  506. void wpas_dbus_signal_wps_event_fail(struct wpa_supplicant *wpa_s,
  507. struct wps_event_fail *fail)
  508. {
  509. DBusMessage *msg;
  510. DBusMessageIter iter, dict_iter;
  511. struct wpas_dbus_priv *iface;
  512. char *key = "fail";
  513. iface = wpa_s->global->dbus;
  514. /* Do nothing if the control interface is not turned on */
  515. if (iface == NULL || !wpa_s->dbus_new_path)
  516. return;
  517. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  518. WPAS_DBUS_NEW_IFACE_WPS, "Event");
  519. if (msg == NULL)
  520. return;
  521. dbus_message_iter_init_append(msg, &iter);
  522. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
  523. !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  524. !wpa_dbus_dict_append_int32(&dict_iter, "msg", fail->msg) ||
  525. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  526. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  527. else
  528. dbus_connection_send(iface->con, msg, NULL);
  529. dbus_message_unref(msg);
  530. }
  531. /**
  532. * wpas_dbus_signal_wps_event_m2d - Signals M2D WPS event
  533. * @wpa_s: %wpa_supplicant network interface data
  534. *
  535. * Sends Event dbus signal with name "m2d" and dictionary containing
  536. * fields of wps_event_m2d structure.
  537. */
  538. void wpas_dbus_signal_wps_event_m2d(struct wpa_supplicant *wpa_s,
  539. struct wps_event_m2d *m2d)
  540. {
  541. DBusMessage *msg;
  542. DBusMessageIter iter, dict_iter;
  543. struct wpas_dbus_priv *iface;
  544. char *key = "m2d";
  545. iface = wpa_s->global->dbus;
  546. /* Do nothing if the control interface is not turned on */
  547. if (iface == NULL || !wpa_s->dbus_new_path)
  548. return;
  549. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  550. WPAS_DBUS_NEW_IFACE_WPS, "Event");
  551. if (msg == NULL)
  552. return;
  553. dbus_message_iter_init_append(msg, &iter);
  554. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
  555. !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  556. !wpa_dbus_dict_append_uint16(&dict_iter, "config_methods",
  557. m2d->config_methods) ||
  558. !wpa_dbus_dict_append_byte_array(&dict_iter, "manufacturer",
  559. (const char *) m2d->manufacturer,
  560. m2d->manufacturer_len) ||
  561. !wpa_dbus_dict_append_byte_array(&dict_iter, "model_name",
  562. (const char *) m2d->model_name,
  563. m2d->model_name_len) ||
  564. !wpa_dbus_dict_append_byte_array(&dict_iter, "model_number",
  565. (const char *) m2d->model_number,
  566. m2d->model_number_len) ||
  567. !wpa_dbus_dict_append_byte_array(&dict_iter, "serial_number",
  568. (const char *)
  569. m2d->serial_number,
  570. m2d->serial_number_len) ||
  571. !wpa_dbus_dict_append_byte_array(&dict_iter, "dev_name",
  572. (const char *) m2d->dev_name,
  573. m2d->dev_name_len) ||
  574. !wpa_dbus_dict_append_byte_array(&dict_iter, "primary_dev_type",
  575. (const char *)
  576. m2d->primary_dev_type, 8) ||
  577. !wpa_dbus_dict_append_uint16(&dict_iter, "config_error",
  578. m2d->config_error) ||
  579. !wpa_dbus_dict_append_uint16(&dict_iter, "dev_password_id",
  580. m2d->dev_password_id) ||
  581. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  582. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  583. else
  584. dbus_connection_send(iface->con, msg, NULL);
  585. dbus_message_unref(msg);
  586. }
  587. /**
  588. * wpas_dbus_signal_wps_cred - Signals new credentials
  589. * @wpa_s: %wpa_supplicant network interface data
  590. *
  591. * Sends signal with credentials in directory argument
  592. */
  593. void wpas_dbus_signal_wps_cred(struct wpa_supplicant *wpa_s,
  594. const struct wps_credential *cred)
  595. {
  596. DBusMessage *msg;
  597. DBusMessageIter iter, dict_iter;
  598. struct wpas_dbus_priv *iface;
  599. char *auth_type[5]; /* we have five possible authentication types */
  600. int at_num = 0;
  601. char *encr_type[3]; /* we have three possible encryption types */
  602. int et_num = 0;
  603. iface = wpa_s->global->dbus;
  604. /* Do nothing if the control interface is not turned on */
  605. if (iface == NULL || !wpa_s->dbus_new_path)
  606. return;
  607. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  608. WPAS_DBUS_NEW_IFACE_WPS,
  609. "Credentials");
  610. if (msg == NULL)
  611. return;
  612. dbus_message_iter_init_append(msg, &iter);
  613. if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
  614. goto nomem;
  615. if (cred->auth_type & WPS_AUTH_OPEN)
  616. auth_type[at_num++] = "open";
  617. if (cred->auth_type & WPS_AUTH_WPAPSK)
  618. auth_type[at_num++] = "wpa-psk";
  619. if (cred->auth_type & WPS_AUTH_WPA)
  620. auth_type[at_num++] = "wpa-eap";
  621. if (cred->auth_type & WPS_AUTH_WPA2)
  622. auth_type[at_num++] = "wpa2-eap";
  623. if (cred->auth_type & WPS_AUTH_WPA2PSK)
  624. auth_type[at_num++] = "wpa2-psk";
  625. if (cred->encr_type & WPS_ENCR_NONE)
  626. encr_type[et_num++] = "none";
  627. if (cred->encr_type & WPS_ENCR_TKIP)
  628. encr_type[et_num++] = "tkip";
  629. if (cred->encr_type & WPS_ENCR_AES)
  630. encr_type[et_num++] = "aes";
  631. if ((wpa_s->current_ssid &&
  632. !wpa_dbus_dict_append_byte_array(
  633. &dict_iter, "BSSID",
  634. (const char *) wpa_s->current_ssid->bssid, ETH_ALEN)) ||
  635. !wpa_dbus_dict_append_byte_array(&dict_iter, "SSID",
  636. (const char *) cred->ssid,
  637. cred->ssid_len) ||
  638. !wpa_dbus_dict_append_string_array(&dict_iter, "AuthType",
  639. (const char **) auth_type,
  640. at_num) ||
  641. !wpa_dbus_dict_append_string_array(&dict_iter, "EncrType",
  642. (const char **) encr_type,
  643. et_num) ||
  644. !wpa_dbus_dict_append_byte_array(&dict_iter, "Key",
  645. (const char *) cred->key,
  646. cred->key_len) ||
  647. !wpa_dbus_dict_append_uint32(&dict_iter, "KeyIndex",
  648. cred->key_idx) ||
  649. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  650. goto nomem;
  651. dbus_connection_send(iface->con, msg, NULL);
  652. nomem:
  653. dbus_message_unref(msg);
  654. }
  655. #endif /* CONFIG_WPS */
  656. void wpas_dbus_signal_certification(struct wpa_supplicant *wpa_s,
  657. int depth, const char *subject,
  658. const char *altsubject[],
  659. int num_altsubject,
  660. const char *cert_hash,
  661. const struct wpabuf *cert)
  662. {
  663. struct wpas_dbus_priv *iface;
  664. DBusMessage *msg;
  665. DBusMessageIter iter, dict_iter;
  666. iface = wpa_s->global->dbus;
  667. /* Do nothing if the control interface is not turned on */
  668. if (iface == NULL || !wpa_s->dbus_new_path)
  669. return;
  670. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  671. WPAS_DBUS_NEW_IFACE_INTERFACE,
  672. "Certification");
  673. if (msg == NULL)
  674. return;
  675. dbus_message_iter_init_append(msg, &iter);
  676. if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  677. !wpa_dbus_dict_append_uint32(&dict_iter, "depth", depth) ||
  678. !wpa_dbus_dict_append_string(&dict_iter, "subject", subject) ||
  679. (altsubject && num_altsubject &&
  680. !wpa_dbus_dict_append_string_array(&dict_iter, "altsubject",
  681. altsubject, num_altsubject)) ||
  682. (cert_hash &&
  683. !wpa_dbus_dict_append_string(&dict_iter, "cert_hash",
  684. cert_hash)) ||
  685. (cert &&
  686. !wpa_dbus_dict_append_byte_array(&dict_iter, "cert",
  687. wpabuf_head(cert),
  688. wpabuf_len(cert))) ||
  689. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  690. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  691. else
  692. dbus_connection_send(iface->con, msg, NULL);
  693. dbus_message_unref(msg);
  694. }
  695. void wpas_dbus_signal_eap_status(struct wpa_supplicant *wpa_s,
  696. const char *status, const char *parameter)
  697. {
  698. struct wpas_dbus_priv *iface;
  699. DBusMessage *msg;
  700. DBusMessageIter iter;
  701. iface = wpa_s->global->dbus;
  702. /* Do nothing if the control interface is not turned on */
  703. if (iface == NULL || !wpa_s->dbus_new_path)
  704. return;
  705. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  706. WPAS_DBUS_NEW_IFACE_INTERFACE,
  707. "EAP");
  708. if (msg == NULL)
  709. return;
  710. dbus_message_iter_init_append(msg, &iter);
  711. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &status) ||
  712. !dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING,
  713. &parameter))
  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. /**
  720. * wpas_dbus_signal_sta - Send a station related event signal
  721. * @wpa_s: %wpa_supplicant network interface data
  722. * @sta: station mac address
  723. * @sig_name: signal name - StaAuthorized or StaDeauthorized
  724. *
  725. * Notify listeners about event related with station
  726. */
  727. static void wpas_dbus_signal_sta(struct wpa_supplicant *wpa_s,
  728. const u8 *sta, const char *sig_name)
  729. {
  730. struct wpas_dbus_priv *iface;
  731. DBusMessage *msg;
  732. char sta_mac[WPAS_DBUS_OBJECT_PATH_MAX];
  733. char *dev_mac;
  734. os_snprintf(sta_mac, WPAS_DBUS_OBJECT_PATH_MAX, MACSTR, MAC2STR(sta));
  735. dev_mac = sta_mac;
  736. iface = wpa_s->global->dbus;
  737. /* Do nothing if the control interface is not turned on */
  738. if (iface == NULL || !wpa_s->dbus_new_path)
  739. return;
  740. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  741. WPAS_DBUS_NEW_IFACE_INTERFACE, sig_name);
  742. if (msg == NULL)
  743. return;
  744. if (dbus_message_append_args(msg, DBUS_TYPE_STRING, &dev_mac,
  745. DBUS_TYPE_INVALID))
  746. dbus_connection_send(iface->con, msg, NULL);
  747. else
  748. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  749. dbus_message_unref(msg);
  750. wpa_printf(MSG_DEBUG, "dbus: Station MAC address '%s' '%s'",
  751. sta_mac, sig_name);
  752. }
  753. /**
  754. * wpas_dbus_signal_sta_authorized - Send a STA authorized signal
  755. * @wpa_s: %wpa_supplicant network interface data
  756. * @sta: station mac address
  757. *
  758. * Notify listeners a new station has been authorized
  759. */
  760. void wpas_dbus_signal_sta_authorized(struct wpa_supplicant *wpa_s,
  761. const u8 *sta)
  762. {
  763. wpas_dbus_signal_sta(wpa_s, sta, "StaAuthorized");
  764. }
  765. /**
  766. * wpas_dbus_signal_sta_deauthorized - Send a STA deauthorized signal
  767. * @wpa_s: %wpa_supplicant network interface data
  768. * @sta: station mac address
  769. *
  770. * Notify listeners a station has been deauthorized
  771. */
  772. void wpas_dbus_signal_sta_deauthorized(struct wpa_supplicant *wpa_s,
  773. const u8 *sta)
  774. {
  775. wpas_dbus_signal_sta(wpa_s, sta, "StaDeauthorized");
  776. }
  777. #ifdef CONFIG_P2P
  778. /**
  779. * wpas_dbus_signal_p2p_group_removed - Signals P2P group was removed
  780. * @wpa_s: %wpa_supplicant network interface data
  781. * @role: role of this device (client or GO)
  782. * Sends signal with i/f name and role as string arguments
  783. */
  784. void wpas_dbus_signal_p2p_group_removed(struct wpa_supplicant *wpa_s,
  785. const char *role)
  786. {
  787. DBusMessage *msg;
  788. DBusMessageIter iter, dict_iter;
  789. struct wpas_dbus_priv *iface = wpa_s->global->dbus;
  790. struct wpa_supplicant *parent;
  791. /* Do nothing if the control interface is not turned on */
  792. if (iface == NULL)
  793. return;
  794. parent = wpa_s->parent;
  795. if (parent->p2p_mgmt)
  796. parent = parent->parent;
  797. if (!wpa_s->dbus_groupobj_path || !wpa_s->dbus_new_path ||
  798. !parent->dbus_new_path)
  799. return;
  800. msg = dbus_message_new_signal(parent->dbus_new_path,
  801. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  802. "GroupFinished");
  803. if (msg == NULL)
  804. return;
  805. dbus_message_iter_init_append(msg, &iter);
  806. if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  807. !wpa_dbus_dict_append_object_path(&dict_iter,
  808. "interface_object",
  809. wpa_s->dbus_new_path) ||
  810. !wpa_dbus_dict_append_string(&dict_iter, "role", role) ||
  811. !wpa_dbus_dict_append_object_path(&dict_iter, "group_object",
  812. wpa_s->dbus_groupobj_path) ||
  813. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  814. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  815. else
  816. dbus_connection_send(iface->con, msg, NULL);
  817. dbus_message_unref(msg);
  818. }
  819. /**
  820. * wpas_dbus_signal_p2p_provision_discovery - Signals various PD events
  821. *
  822. * @dev_addr - who sent the request or responded to our request.
  823. * @request - Will be 1 if request, 0 for response.
  824. * @status - valid only in case of response
  825. * @config_methods - wps config methods
  826. * @generated_pin - pin to be displayed in case of WPS_CONFIG_DISPLAY method
  827. *
  828. * Sends following provision discovery related events:
  829. * ProvisionDiscoveryRequestDisplayPin
  830. * ProvisionDiscoveryResponseDisplayPin
  831. * ProvisionDiscoveryRequestEnterPin
  832. * ProvisionDiscoveryResponseEnterPin
  833. * ProvisionDiscoveryPBCRequest
  834. * ProvisionDiscoveryPBCResponse
  835. *
  836. * TODO::
  837. * ProvisionDiscoveryFailure (timeout case)
  838. */
  839. void wpas_dbus_signal_p2p_provision_discovery(struct wpa_supplicant *wpa_s,
  840. const u8 *dev_addr, int request,
  841. enum p2p_prov_disc_status status,
  842. u16 config_methods,
  843. unsigned int generated_pin)
  844. {
  845. DBusMessage *msg;
  846. DBusMessageIter iter;
  847. struct wpas_dbus_priv *iface;
  848. char *_signal;
  849. int add_pin = 0;
  850. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  851. int error_ret = 1;
  852. char pin[9], *p_pin = NULL;
  853. iface = wpa_s->global->dbus;
  854. /* Do nothing if the control interface is not turned on */
  855. if (iface == NULL)
  856. return;
  857. if (wpa_s->p2p_mgmt)
  858. wpa_s = wpa_s->parent;
  859. if (!wpa_s->dbus_new_path)
  860. return;
  861. if (request || !status) {
  862. if (config_methods & WPS_CONFIG_DISPLAY)
  863. _signal = request ?
  864. "ProvisionDiscoveryRequestDisplayPin" :
  865. "ProvisionDiscoveryResponseEnterPin";
  866. else if (config_methods & WPS_CONFIG_KEYPAD)
  867. _signal = request ?
  868. "ProvisionDiscoveryRequestEnterPin" :
  869. "ProvisionDiscoveryResponseDisplayPin";
  870. else if (config_methods & WPS_CONFIG_PUSHBUTTON)
  871. _signal = request ? "ProvisionDiscoveryPBCRequest" :
  872. "ProvisionDiscoveryPBCResponse";
  873. else
  874. return; /* Unknown or un-supported method */
  875. } else {
  876. /* Explicit check for failure response */
  877. _signal = "ProvisionDiscoveryFailure";
  878. }
  879. add_pin = ((request && (config_methods & WPS_CONFIG_DISPLAY)) ||
  880. (!request && !status &&
  881. (config_methods & WPS_CONFIG_KEYPAD)));
  882. if (add_pin) {
  883. os_snprintf(pin, sizeof(pin), "%08d", generated_pin);
  884. p_pin = pin;
  885. }
  886. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  887. WPAS_DBUS_NEW_IFACE_P2PDEVICE, _signal);
  888. if (msg == NULL)
  889. return;
  890. /* Check if this is a known peer */
  891. if (!p2p_peer_known(wpa_s->global->p2p, dev_addr))
  892. goto error;
  893. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  894. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
  895. COMPACT_MACSTR,
  896. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  897. path = peer_obj_path;
  898. dbus_message_iter_init_append(msg, &iter);
  899. if (!dbus_message_iter_append_basic(&iter,
  900. DBUS_TYPE_OBJECT_PATH,
  901. &path))
  902. goto error;
  903. if (!request && status)
  904. /* Attach status to ProvisionDiscoveryFailure */
  905. error_ret = !dbus_message_iter_append_basic(&iter,
  906. DBUS_TYPE_INT32,
  907. &status);
  908. else
  909. error_ret = (add_pin &&
  910. !dbus_message_iter_append_basic(&iter,
  911. DBUS_TYPE_STRING,
  912. &p_pin));
  913. error:
  914. if (!error_ret)
  915. dbus_connection_send(iface->con, msg, NULL);
  916. else
  917. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  918. dbus_message_unref(msg);
  919. }
  920. void wpas_dbus_signal_p2p_go_neg_req(struct wpa_supplicant *wpa_s,
  921. const u8 *src, u16 dev_passwd_id,
  922. u8 go_intent)
  923. {
  924. DBusMessage *msg;
  925. DBusMessageIter iter;
  926. struct wpas_dbus_priv *iface;
  927. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  928. iface = wpa_s->global->dbus;
  929. /* Do nothing if the control interface is not turned on */
  930. if (iface == NULL)
  931. return;
  932. if (wpa_s->p2p_mgmt)
  933. wpa_s = wpa_s->parent;
  934. if (!wpa_s->dbus_new_path)
  935. return;
  936. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  937. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  938. wpa_s->dbus_new_path, MAC2STR(src));
  939. path = peer_obj_path;
  940. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  941. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  942. "GONegotiationRequest");
  943. if (msg == NULL)
  944. return;
  945. dbus_message_iter_init_append(msg, &iter);
  946. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  947. &path) ||
  948. !dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT16,
  949. &dev_passwd_id) ||
  950. !dbus_message_iter_append_basic(&iter, DBUS_TYPE_BYTE,
  951. &go_intent))
  952. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  953. else
  954. dbus_connection_send(iface->con, msg, NULL);
  955. dbus_message_unref(msg);
  956. }
  957. static int wpas_dbus_get_group_obj_path(struct wpa_supplicant *wpa_s,
  958. const struct wpa_ssid *ssid,
  959. char *group_obj_path)
  960. {
  961. char group_name[3];
  962. if (!wpa_s->dbus_new_path ||
  963. os_memcmp(ssid->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN))
  964. return -1;
  965. os_memcpy(group_name, ssid->ssid + P2P_WILDCARD_SSID_LEN, 2);
  966. group_name[2] = '\0';
  967. os_snprintf(group_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  968. "%s/" WPAS_DBUS_NEW_P2P_GROUPS_PART "/%s",
  969. wpa_s->dbus_new_path, group_name);
  970. return 0;
  971. }
  972. struct group_changed_data {
  973. struct wpa_supplicant *wpa_s;
  974. struct p2p_peer_info *info;
  975. };
  976. static int match_group_where_peer_is_client(struct p2p_group *group,
  977. void *user_data)
  978. {
  979. struct group_changed_data *data = user_data;
  980. const struct p2p_group_config *cfg;
  981. struct wpa_supplicant *wpa_s_go;
  982. if (!p2p_group_is_client_connected(group, data->info->p2p_device_addr))
  983. return 1;
  984. cfg = p2p_group_get_config(group);
  985. wpa_s_go = wpas_get_p2p_go_iface(data->wpa_s, cfg->ssid,
  986. cfg->ssid_len);
  987. if (wpa_s_go != NULL && wpa_s_go == data->wpa_s) {
  988. wpas_dbus_signal_peer_groups_changed(
  989. data->wpa_s->parent, data->info->p2p_device_addr);
  990. return 0;
  991. }
  992. return 1;
  993. }
  994. static void signal_peer_groups_changed(struct p2p_peer_info *info,
  995. void *user_data)
  996. {
  997. struct group_changed_data *data = user_data;
  998. struct wpa_supplicant *wpa_s_go;
  999. wpa_s_go = wpas_get_p2p_client_iface(data->wpa_s,
  1000. info->p2p_device_addr);
  1001. if (wpa_s_go != NULL && wpa_s_go == data->wpa_s) {
  1002. wpas_dbus_signal_peer_groups_changed(data->wpa_s->parent,
  1003. info->p2p_device_addr);
  1004. return;
  1005. }
  1006. data->info = info;
  1007. p2p_loop_on_all_groups(data->wpa_s->global->p2p,
  1008. match_group_where_peer_is_client, data);
  1009. data->info = NULL;
  1010. }
  1011. static void peer_groups_changed(struct wpa_supplicant *wpa_s)
  1012. {
  1013. struct group_changed_data data;
  1014. os_memset(&data, 0, sizeof(data));
  1015. data.wpa_s = wpa_s;
  1016. p2p_loop_on_known_peers(wpa_s->global->p2p,
  1017. signal_peer_groups_changed, &data);
  1018. }
  1019. /**
  1020. * wpas_dbus_signal_p2p_group_started - Signals P2P group has
  1021. * started. Emitted when a group is successfully started
  1022. * irrespective of the role (client/GO) of the current device
  1023. *
  1024. * @wpa_s: %wpa_supplicant network interface data
  1025. * @ssid: SSID object
  1026. * @client: this device is P2P client
  1027. * @network_id: network id of the group started, use instead of ssid->id
  1028. * to account for persistent groups
  1029. */
  1030. void wpas_dbus_signal_p2p_group_started(struct wpa_supplicant *wpa_s,
  1031. const struct wpa_ssid *ssid,
  1032. int client, int network_id)
  1033. {
  1034. DBusMessage *msg;
  1035. DBusMessageIter iter, dict_iter;
  1036. struct wpas_dbus_priv *iface;
  1037. struct wpa_supplicant *parent;
  1038. parent = wpa_s->parent;
  1039. if (parent->p2p_mgmt)
  1040. parent = parent->parent;
  1041. iface = parent->global->dbus;
  1042. /* Do nothing if the control interface is not turned on */
  1043. if (iface == NULL || !parent->dbus_new_path || !wpa_s->dbus_new_path)
  1044. return;
  1045. if (wpa_s->dbus_groupobj_path == NULL)
  1046. return;
  1047. /* New interface has been created for this group */
  1048. msg = dbus_message_new_signal(parent->dbus_new_path,
  1049. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1050. "GroupStarted");
  1051. if (msg == NULL)
  1052. return;
  1053. dbus_message_iter_init_append(msg, &iter);
  1054. /*
  1055. * In case the device supports creating a separate interface the
  1056. * DBus client will need to know the object path for the interface
  1057. * object this group was created on, so include it here.
  1058. */
  1059. if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  1060. !wpa_dbus_dict_append_object_path(&dict_iter,
  1061. "interface_object",
  1062. wpa_s->dbus_new_path) ||
  1063. !wpa_dbus_dict_append_string(&dict_iter, "role",
  1064. client ? "client" : "GO") ||
  1065. !wpa_dbus_dict_append_object_path(&dict_iter, "group_object",
  1066. wpa_s->dbus_groupobj_path) ||
  1067. !wpa_dbus_dict_close_write(&iter, &dict_iter)) {
  1068. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1069. } else {
  1070. dbus_connection_send(iface->con, msg, NULL);
  1071. if (client)
  1072. peer_groups_changed(wpa_s);
  1073. }
  1074. dbus_message_unref(msg);
  1075. }
  1076. /**
  1077. *
  1078. * Method to emit GONegotiation Success or Failure signals based
  1079. * on status.
  1080. * @status: Status of the GO neg request. 0 for success, other for errors.
  1081. */
  1082. void wpas_dbus_signal_p2p_go_neg_resp(struct wpa_supplicant *wpa_s,
  1083. struct p2p_go_neg_results *res)
  1084. {
  1085. DBusMessage *msg;
  1086. DBusMessageIter iter, dict_iter;
  1087. DBusMessageIter iter_dict_entry, iter_dict_val, iter_dict_array;
  1088. struct wpas_dbus_priv *iface;
  1089. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  1090. dbus_int32_t freqs[P2P_MAX_CHANNELS];
  1091. dbus_int32_t *f_array = freqs;
  1092. iface = wpa_s->global->dbus;
  1093. if (wpa_s->p2p_mgmt)
  1094. wpa_s = wpa_s->parent;
  1095. os_memset(freqs, 0, sizeof(freqs));
  1096. /* Do nothing if the control interface is not turned on */
  1097. if (iface == NULL || !wpa_s->dbus_new_path)
  1098. return;
  1099. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1100. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  1101. wpa_s->dbus_new_path, MAC2STR(res->peer_device_addr));
  1102. path = peer_obj_path;
  1103. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1104. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1105. res->status ? "GONegotiationFailure" :
  1106. "GONegotiationSuccess");
  1107. if (msg == NULL)
  1108. return;
  1109. dbus_message_iter_init_append(msg, &iter);
  1110. if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  1111. !wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
  1112. path) ||
  1113. !wpa_dbus_dict_append_int32(&dict_iter, "status", res->status))
  1114. goto err;
  1115. if (!res->status) {
  1116. int i = 0;
  1117. int freq_list_num = 0;
  1118. if ((res->role_go &&
  1119. !wpa_dbus_dict_append_string(&dict_iter, "passphrase",
  1120. res->passphrase)) ||
  1121. !wpa_dbus_dict_append_string(&dict_iter, "role_go",
  1122. res->role_go ? "GO" :
  1123. "client") ||
  1124. !wpa_dbus_dict_append_int32(&dict_iter, "frequency",
  1125. res->freq) ||
  1126. !wpa_dbus_dict_append_byte_array(&dict_iter, "ssid",
  1127. (const char *) res->ssid,
  1128. res->ssid_len) ||
  1129. !wpa_dbus_dict_append_byte_array(&dict_iter,
  1130. "peer_device_addr",
  1131. (const char *)
  1132. res->peer_device_addr,
  1133. ETH_ALEN) ||
  1134. !wpa_dbus_dict_append_byte_array(&dict_iter,
  1135. "peer_interface_addr",
  1136. (const char *)
  1137. res->peer_interface_addr,
  1138. ETH_ALEN) ||
  1139. !wpa_dbus_dict_append_string(&dict_iter, "wps_method",
  1140. p2p_wps_method_text(
  1141. res->wps_method)))
  1142. goto err;
  1143. for (i = 0; i < P2P_MAX_CHANNELS; i++) {
  1144. if (res->freq_list[i]) {
  1145. freqs[i] = res->freq_list[i];
  1146. freq_list_num++;
  1147. }
  1148. }
  1149. if (!wpa_dbus_dict_begin_array(&dict_iter,
  1150. "frequency_list",
  1151. DBUS_TYPE_INT32_AS_STRING,
  1152. &iter_dict_entry,
  1153. &iter_dict_val,
  1154. &iter_dict_array) ||
  1155. !dbus_message_iter_append_fixed_array(&iter_dict_array,
  1156. DBUS_TYPE_INT32,
  1157. &f_array,
  1158. freq_list_num) ||
  1159. !wpa_dbus_dict_end_array(&dict_iter,
  1160. &iter_dict_entry,
  1161. &iter_dict_val,
  1162. &iter_dict_array) ||
  1163. !wpa_dbus_dict_append_int32(&dict_iter, "persistent_group",
  1164. res->persistent_group) ||
  1165. !wpa_dbus_dict_append_uint32(&dict_iter,
  1166. "peer_config_timeout",
  1167. res->peer_config_timeout))
  1168. goto err;
  1169. }
  1170. if (!wpa_dbus_dict_close_write(&iter, &dict_iter))
  1171. goto err;
  1172. dbus_connection_send(iface->con, msg, NULL);
  1173. err:
  1174. dbus_message_unref(msg);
  1175. }
  1176. /**
  1177. *
  1178. * Method to emit Invitation Result signal based on status and
  1179. * bssid
  1180. * @status: Status of the Invite request. 0 for success, other
  1181. * for errors
  1182. * @bssid : Basic Service Set Identifier
  1183. */
  1184. void wpas_dbus_signal_p2p_invitation_result(struct wpa_supplicant *wpa_s,
  1185. int status, const u8 *bssid)
  1186. {
  1187. DBusMessage *msg;
  1188. DBusMessageIter iter, dict_iter;
  1189. struct wpas_dbus_priv *iface;
  1190. wpa_printf(MSG_DEBUG, "%s", __func__);
  1191. iface = wpa_s->global->dbus;
  1192. /* Do nothing if the control interface is not turned on */
  1193. if (iface == NULL)
  1194. return;
  1195. if (wpa_s->p2p_mgmt)
  1196. wpa_s = wpa_s->parent;
  1197. if (!wpa_s->dbus_new_path)
  1198. return;
  1199. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1200. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1201. "InvitationResult");
  1202. if (msg == NULL)
  1203. return;
  1204. dbus_message_iter_init_append(msg, &iter);
  1205. if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  1206. !wpa_dbus_dict_append_int32(&dict_iter, "status", status) ||
  1207. (bssid &&
  1208. !wpa_dbus_dict_append_byte_array(&dict_iter, "BSSID",
  1209. (const char *) bssid,
  1210. ETH_ALEN)) ||
  1211. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  1212. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1213. else
  1214. dbus_connection_send(iface->con, msg, NULL);
  1215. dbus_message_unref(msg);
  1216. }
  1217. /**
  1218. *
  1219. * Method to emit a signal for a peer joining the group.
  1220. * The signal will carry path to the group member object
  1221. * constructed using p2p i/f addr used for connecting.
  1222. *
  1223. * @wpa_s: %wpa_supplicant network interface data
  1224. * @peer_addr: P2P Device Address of the peer joining the group
  1225. */
  1226. void wpas_dbus_signal_p2p_peer_joined(struct wpa_supplicant *wpa_s,
  1227. const u8 *peer_addr)
  1228. {
  1229. struct wpas_dbus_priv *iface;
  1230. DBusMessage *msg;
  1231. DBusMessageIter iter;
  1232. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  1233. struct wpa_supplicant *parent;
  1234. iface = wpa_s->global->dbus;
  1235. /* Do nothing if the control interface is not turned on */
  1236. if (iface == NULL)
  1237. return;
  1238. if (!wpa_s->dbus_groupobj_path)
  1239. return;
  1240. parent = wpa_s->parent;
  1241. if (parent->p2p_mgmt)
  1242. parent = parent->parent;
  1243. if (!parent->dbus_new_path)
  1244. return;
  1245. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1246. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
  1247. COMPACT_MACSTR,
  1248. parent->dbus_new_path, MAC2STR(peer_addr));
  1249. msg = dbus_message_new_signal(wpa_s->dbus_groupobj_path,
  1250. WPAS_DBUS_NEW_IFACE_P2P_GROUP,
  1251. "PeerJoined");
  1252. if (msg == NULL)
  1253. return;
  1254. dbus_message_iter_init_append(msg, &iter);
  1255. path = peer_obj_path;
  1256. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  1257. &path)) {
  1258. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1259. } else {
  1260. dbus_connection_send(iface->con, msg, NULL);
  1261. wpas_dbus_signal_peer_groups_changed(parent, peer_addr);
  1262. }
  1263. dbus_message_unref(msg);
  1264. }
  1265. /**
  1266. *
  1267. * Method to emit a signal for a peer disconnecting the group.
  1268. * The signal will carry path to the group member object
  1269. * constructed using the P2P Device Address of the peer.
  1270. *
  1271. * @wpa_s: %wpa_supplicant network interface data
  1272. * @peer_addr: P2P Device Address of the peer joining the group
  1273. */
  1274. void wpas_dbus_signal_p2p_peer_disconnected(struct wpa_supplicant *wpa_s,
  1275. const u8 *peer_addr)
  1276. {
  1277. struct wpas_dbus_priv *iface;
  1278. DBusMessage *msg;
  1279. DBusMessageIter iter;
  1280. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  1281. struct wpa_supplicant *parent;
  1282. iface = wpa_s->global->dbus;
  1283. /* Do nothing if the control interface is not turned on */
  1284. if (iface == NULL)
  1285. return;
  1286. if (!wpa_s->dbus_groupobj_path)
  1287. return;
  1288. parent = wpa_s->parent;
  1289. if (parent->p2p_mgmt)
  1290. parent = parent->parent;
  1291. if (!parent->dbus_new_path)
  1292. return;
  1293. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1294. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
  1295. COMPACT_MACSTR,
  1296. parent->dbus_new_path, MAC2STR(peer_addr));
  1297. msg = dbus_message_new_signal(wpa_s->dbus_groupobj_path,
  1298. WPAS_DBUS_NEW_IFACE_P2P_GROUP,
  1299. "PeerDisconnected");
  1300. if (msg == NULL)
  1301. return;
  1302. dbus_message_iter_init_append(msg, &iter);
  1303. path = peer_obj_path;
  1304. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  1305. &path)) {
  1306. wpa_printf(MSG_ERROR,
  1307. "dbus: Failed to construct PeerDisconnected signal");
  1308. } else {
  1309. dbus_connection_send(iface->con, msg, NULL);
  1310. wpas_dbus_signal_peer_groups_changed(parent, peer_addr);
  1311. }
  1312. dbus_message_unref(msg);
  1313. }
  1314. /**
  1315. *
  1316. * Method to emit a signal for a service discovery request.
  1317. * The signal will carry station address, frequency, dialog token,
  1318. * update indicator and it tlvs
  1319. *
  1320. * @wpa_s: %wpa_supplicant network interface data
  1321. * @sa: station addr (p2p i/f) of the peer
  1322. * @dialog_token: service discovery request dialog token
  1323. * @update_indic: service discovery request update indicator
  1324. * @tlvs: service discovery request genrated byte array of tlvs
  1325. * @tlvs_len: service discovery request tlvs length
  1326. */
  1327. void wpas_dbus_signal_p2p_sd_request(struct wpa_supplicant *wpa_s,
  1328. int freq, const u8 *sa, u8 dialog_token,
  1329. u16 update_indic, const u8 *tlvs,
  1330. size_t tlvs_len)
  1331. {
  1332. DBusMessage *msg;
  1333. DBusMessageIter iter, dict_iter;
  1334. struct wpas_dbus_priv *iface;
  1335. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  1336. iface = wpa_s->global->dbus;
  1337. /* Do nothing if the control interface is not turned on */
  1338. if (iface == NULL)
  1339. return;
  1340. if (wpa_s->p2p_mgmt)
  1341. wpa_s = wpa_s->parent;
  1342. if (!wpa_s->dbus_new_path)
  1343. return;
  1344. /* Check if this is a known peer */
  1345. if (!p2p_peer_known(wpa_s->global->p2p, sa))
  1346. return;
  1347. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1348. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1349. "ServiceDiscoveryRequest");
  1350. if (msg == NULL)
  1351. return;
  1352. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1353. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
  1354. COMPACT_MACSTR, wpa_s->dbus_new_path, MAC2STR(sa));
  1355. path = peer_obj_path;
  1356. dbus_message_iter_init_append(msg, &iter);
  1357. if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  1358. !wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
  1359. path) ||
  1360. !wpa_dbus_dict_append_int32(&dict_iter, "frequency", freq) ||
  1361. !wpa_dbus_dict_append_int32(&dict_iter, "dialog_token",
  1362. dialog_token) ||
  1363. !wpa_dbus_dict_append_uint16(&dict_iter, "update_indicator",
  1364. update_indic) ||
  1365. !wpa_dbus_dict_append_byte_array(&dict_iter, "tlvs",
  1366. (const char *) tlvs,
  1367. tlvs_len) ||
  1368. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  1369. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1370. else
  1371. dbus_connection_send(iface->con, msg, NULL);
  1372. dbus_message_unref(msg);
  1373. }
  1374. /**
  1375. *
  1376. * Method to emit a signal for a service discovery response.
  1377. * The signal will carry station address, update indicator and it
  1378. * tlvs
  1379. *
  1380. * @wpa_s: %wpa_supplicant network interface data
  1381. * @sa: station addr (p2p i/f) of the peer
  1382. * @update_indic: service discovery request update indicator
  1383. * @tlvs: service discovery request genrated byte array of tlvs
  1384. * @tlvs_len: service discovery request tlvs length
  1385. */
  1386. void wpas_dbus_signal_p2p_sd_response(struct wpa_supplicant *wpa_s,
  1387. const u8 *sa, u16 update_indic,
  1388. const u8 *tlvs, size_t tlvs_len)
  1389. {
  1390. DBusMessage *msg;
  1391. DBusMessageIter iter, dict_iter;
  1392. struct wpas_dbus_priv *iface;
  1393. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  1394. iface = wpa_s->global->dbus;
  1395. /* Do nothing if the control interface is not turned on */
  1396. if (iface == NULL)
  1397. return;
  1398. if (wpa_s->p2p_mgmt)
  1399. wpa_s = wpa_s->parent;
  1400. if (!wpa_s->dbus_new_path)
  1401. return;
  1402. /* Check if this is a known peer */
  1403. if (!p2p_peer_known(wpa_s->global->p2p, sa))
  1404. return;
  1405. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1406. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1407. "ServiceDiscoveryResponse");
  1408. if (msg == NULL)
  1409. return;
  1410. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1411. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
  1412. COMPACT_MACSTR, wpa_s->dbus_new_path, MAC2STR(sa));
  1413. path = peer_obj_path;
  1414. dbus_message_iter_init_append(msg, &iter);
  1415. if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  1416. !wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
  1417. path) ||
  1418. !wpa_dbus_dict_append_uint16(&dict_iter, "update_indicator",
  1419. update_indic) ||
  1420. !wpa_dbus_dict_append_byte_array(&dict_iter, "tlvs",
  1421. (const char *) tlvs,
  1422. tlvs_len) ||
  1423. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  1424. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1425. else
  1426. dbus_connection_send(iface->con, msg, NULL);
  1427. dbus_message_unref(msg);
  1428. }
  1429. /**
  1430. * wpas_dbus_signal_persistent_group - Send a persistent group related
  1431. * event signal
  1432. * @wpa_s: %wpa_supplicant network interface data
  1433. * @id: new persistent group id
  1434. * @sig_name: signal name - PersistentGroupAdded, PersistentGroupRemoved
  1435. * @properties: determines if add second argument with object properties
  1436. *
  1437. * Notify listeners about an event related to persistent groups.
  1438. */
  1439. static void wpas_dbus_signal_persistent_group(struct wpa_supplicant *wpa_s,
  1440. int id, const char *sig_name,
  1441. int properties)
  1442. {
  1443. struct wpas_dbus_priv *iface;
  1444. DBusMessage *msg;
  1445. DBusMessageIter iter;
  1446. char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  1447. iface = wpa_s->global->dbus;
  1448. /* Do nothing if the control interface is not turned on */
  1449. if (iface == NULL)
  1450. return;
  1451. if (wpa_s->p2p_mgmt)
  1452. wpa_s = wpa_s->parent;
  1453. if (!wpa_s->dbus_new_path)
  1454. return;
  1455. os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1456. "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
  1457. wpa_s->dbus_new_path, id);
  1458. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1459. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1460. sig_name);
  1461. if (msg == NULL)
  1462. return;
  1463. dbus_message_iter_init_append(msg, &iter);
  1464. path = pgrp_obj_path;
  1465. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  1466. &path) ||
  1467. (properties &&
  1468. !wpa_dbus_get_object_properties(
  1469. iface, pgrp_obj_path,
  1470. WPAS_DBUS_NEW_IFACE_PERSISTENT_GROUP, &iter)))
  1471. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1472. else
  1473. dbus_connection_send(iface->con, msg, NULL);
  1474. dbus_message_unref(msg);
  1475. }
  1476. /**
  1477. * wpas_dbus_signal_persistent_group_added - Send a persistent_group
  1478. * added signal
  1479. * @wpa_s: %wpa_supplicant network interface data
  1480. * @id: new persistent group id
  1481. *
  1482. * Notify listeners about addition of a new persistent group.
  1483. */
  1484. static void wpas_dbus_signal_persistent_group_added(
  1485. struct wpa_supplicant *wpa_s, int id)
  1486. {
  1487. wpas_dbus_signal_persistent_group(wpa_s, id, "PersistentGroupAdded",
  1488. TRUE);
  1489. }
  1490. /**
  1491. * wpas_dbus_signal_persistent_group_removed - Send a persistent_group
  1492. * removed signal
  1493. * @wpa_s: %wpa_supplicant network interface data
  1494. * @id: persistent group id
  1495. *
  1496. * Notify listeners about removal of a persistent group.
  1497. */
  1498. static void wpas_dbus_signal_persistent_group_removed(
  1499. struct wpa_supplicant *wpa_s, int id)
  1500. {
  1501. wpas_dbus_signal_persistent_group(wpa_s, id, "PersistentGroupRemoved",
  1502. FALSE);
  1503. }
  1504. /**
  1505. * wpas_dbus_signal_p2p_wps_failed - Signals WpsFailed event
  1506. * @wpa_s: %wpa_supplicant network interface data
  1507. *
  1508. * Sends Event dbus signal with name "fail" and dictionary containing
  1509. * "msg" field with fail message number (int32) as arguments
  1510. */
  1511. void wpas_dbus_signal_p2p_wps_failed(struct wpa_supplicant *wpa_s,
  1512. struct wps_event_fail *fail)
  1513. {
  1514. DBusMessage *msg;
  1515. DBusMessageIter iter, dict_iter;
  1516. struct wpas_dbus_priv *iface;
  1517. char *key = "fail";
  1518. iface = wpa_s->global->dbus;
  1519. /* Do nothing if the control interface is not turned on */
  1520. if (iface == NULL)
  1521. return;
  1522. if (wpa_s->p2p_mgmt)
  1523. wpa_s = wpa_s->parent;
  1524. if (!wpa_s->dbus_new_path)
  1525. return;
  1526. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1527. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1528. "WpsFailed");
  1529. if (msg == NULL)
  1530. return;
  1531. dbus_message_iter_init_append(msg, &iter);
  1532. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
  1533. !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  1534. !wpa_dbus_dict_append_int32(&dict_iter, "msg", fail->msg) ||
  1535. !wpa_dbus_dict_append_int16(&dict_iter, "config_error",
  1536. fail->config_error) ||
  1537. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  1538. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1539. else
  1540. dbus_connection_send(iface->con, msg, NULL);
  1541. dbus_message_unref(msg);
  1542. }
  1543. #endif /* CONFIG_P2P */
  1544. /**
  1545. * wpas_dbus_signal_prop_changed - Signals change of property
  1546. * @wpa_s: %wpa_supplicant network interface data
  1547. * @property: indicates which property has changed
  1548. *
  1549. * Sends PropertyChanged signals with path, interface and arguments
  1550. * depending on which property has changed.
  1551. */
  1552. void wpas_dbus_signal_prop_changed(struct wpa_supplicant *wpa_s,
  1553. enum wpas_dbus_prop property)
  1554. {
  1555. char *prop;
  1556. dbus_bool_t flush;
  1557. if (wpa_s->dbus_new_path == NULL)
  1558. return; /* Skip signal since D-Bus setup is not yet ready */
  1559. flush = FALSE;
  1560. switch (property) {
  1561. case WPAS_DBUS_PROP_AP_SCAN:
  1562. prop = "ApScan";
  1563. break;
  1564. case WPAS_DBUS_PROP_SCANNING:
  1565. prop = "Scanning";
  1566. break;
  1567. case WPAS_DBUS_PROP_STATE:
  1568. prop = "State";
  1569. break;
  1570. case WPAS_DBUS_PROP_CURRENT_BSS:
  1571. prop = "CurrentBSS";
  1572. break;
  1573. case WPAS_DBUS_PROP_CURRENT_NETWORK:
  1574. prop = "CurrentNetwork";
  1575. break;
  1576. case WPAS_DBUS_PROP_BSSS:
  1577. prop = "BSSs";
  1578. break;
  1579. case WPAS_DBUS_PROP_CURRENT_AUTH_MODE:
  1580. prop = "CurrentAuthMode";
  1581. break;
  1582. case WPAS_DBUS_PROP_DISCONNECT_REASON:
  1583. prop = "DisconnectReason";
  1584. flush = TRUE;
  1585. break;
  1586. default:
  1587. wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
  1588. __func__, property);
  1589. return;
  1590. }
  1591. wpa_dbus_mark_property_changed(wpa_s->global->dbus,
  1592. wpa_s->dbus_new_path,
  1593. WPAS_DBUS_NEW_IFACE_INTERFACE, prop);
  1594. if (flush) {
  1595. wpa_dbus_flush_object_changed_properties(
  1596. wpa_s->global->dbus->con, wpa_s->dbus_new_path);
  1597. }
  1598. }
  1599. /**
  1600. * wpas_dbus_bss_signal_prop_changed - Signals change of BSS property
  1601. * @wpa_s: %wpa_supplicant network interface data
  1602. * @property: indicates which property has changed
  1603. * @id: unique BSS identifier
  1604. *
  1605. * Sends PropertyChanged signals with path, interface, and arguments depending
  1606. * on which property has changed.
  1607. */
  1608. void wpas_dbus_bss_signal_prop_changed(struct wpa_supplicant *wpa_s,
  1609. enum wpas_dbus_bss_prop property,
  1610. unsigned int id)
  1611. {
  1612. char path[WPAS_DBUS_OBJECT_PATH_MAX];
  1613. char *prop;
  1614. if (!wpa_s->dbus_new_path)
  1615. return;
  1616. switch (property) {
  1617. case WPAS_DBUS_BSS_PROP_SIGNAL:
  1618. prop = "Signal";
  1619. break;
  1620. case WPAS_DBUS_BSS_PROP_FREQ:
  1621. prop = "Frequency";
  1622. break;
  1623. case WPAS_DBUS_BSS_PROP_MODE:
  1624. prop = "Mode";
  1625. break;
  1626. case WPAS_DBUS_BSS_PROP_PRIVACY:
  1627. prop = "Privacy";
  1628. break;
  1629. case WPAS_DBUS_BSS_PROP_RATES:
  1630. prop = "Rates";
  1631. break;
  1632. case WPAS_DBUS_BSS_PROP_WPA:
  1633. prop = "WPA";
  1634. break;
  1635. case WPAS_DBUS_BSS_PROP_RSN:
  1636. prop = "RSN";
  1637. break;
  1638. case WPAS_DBUS_BSS_PROP_WPS:
  1639. prop = "WPS";
  1640. break;
  1641. case WPAS_DBUS_BSS_PROP_IES:
  1642. prop = "IEs";
  1643. break;
  1644. case WPAS_DBUS_BSS_PROP_AGE:
  1645. prop = "Age";
  1646. break;
  1647. default:
  1648. wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
  1649. __func__, property);
  1650. return;
  1651. }
  1652. os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
  1653. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  1654. wpa_s->dbus_new_path, id);
  1655. wpa_dbus_mark_property_changed(wpa_s->global->dbus, path,
  1656. WPAS_DBUS_NEW_IFACE_BSS, prop);
  1657. }
  1658. /**
  1659. * wpas_dbus_signal_debug_level_changed - Signals change of debug param
  1660. * @global: wpa_global structure
  1661. *
  1662. * Sends PropertyChanged signals informing that debug level has changed.
  1663. */
  1664. void wpas_dbus_signal_debug_level_changed(struct wpa_global *global)
  1665. {
  1666. wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
  1667. WPAS_DBUS_NEW_INTERFACE,
  1668. "DebugLevel");
  1669. }
  1670. /**
  1671. * wpas_dbus_signal_debug_timestamp_changed - Signals change of debug param
  1672. * @global: wpa_global structure
  1673. *
  1674. * Sends PropertyChanged signals informing that debug timestamp has changed.
  1675. */
  1676. void wpas_dbus_signal_debug_timestamp_changed(struct wpa_global *global)
  1677. {
  1678. wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
  1679. WPAS_DBUS_NEW_INTERFACE,
  1680. "DebugTimestamp");
  1681. }
  1682. /**
  1683. * wpas_dbus_signal_debug_show_keys_changed - Signals change of debug param
  1684. * @global: wpa_global structure
  1685. *
  1686. * Sends PropertyChanged signals informing that debug show_keys has changed.
  1687. */
  1688. void wpas_dbus_signal_debug_show_keys_changed(struct wpa_global *global)
  1689. {
  1690. wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
  1691. WPAS_DBUS_NEW_INTERFACE,
  1692. "DebugShowKeys");
  1693. }
  1694. static void wpas_dbus_register(struct wpa_dbus_object_desc *obj_desc,
  1695. void *priv,
  1696. WPADBusArgumentFreeFunction priv_free,
  1697. const struct wpa_dbus_method_desc *methods,
  1698. const struct wpa_dbus_property_desc *properties,
  1699. const struct wpa_dbus_signal_desc *signals)
  1700. {
  1701. int n;
  1702. obj_desc->user_data = priv;
  1703. obj_desc->user_data_free_func = priv_free;
  1704. obj_desc->methods = methods;
  1705. obj_desc->properties = properties;
  1706. obj_desc->signals = signals;
  1707. for (n = 0; properties && properties->dbus_property; properties++)
  1708. n++;
  1709. obj_desc->prop_changed_flags = os_zalloc(n);
  1710. if (!obj_desc->prop_changed_flags)
  1711. wpa_printf(MSG_DEBUG, "dbus: %s: can't register handlers",
  1712. __func__);
  1713. }
  1714. static const struct wpa_dbus_method_desc wpas_dbus_global_methods[] = {
  1715. { "CreateInterface", WPAS_DBUS_NEW_INTERFACE,
  1716. (WPADBusMethodHandler) wpas_dbus_handler_create_interface,
  1717. {
  1718. { "args", "a{sv}", ARG_IN },
  1719. { "path", "o", ARG_OUT },
  1720. END_ARGS
  1721. }
  1722. },
  1723. { "RemoveInterface", WPAS_DBUS_NEW_INTERFACE,
  1724. (WPADBusMethodHandler) wpas_dbus_handler_remove_interface,
  1725. {
  1726. { "path", "o", ARG_IN },
  1727. END_ARGS
  1728. }
  1729. },
  1730. { "GetInterface", WPAS_DBUS_NEW_INTERFACE,
  1731. (WPADBusMethodHandler) wpas_dbus_handler_get_interface,
  1732. {
  1733. { "ifname", "s", ARG_IN },
  1734. { "path", "o", ARG_OUT },
  1735. END_ARGS
  1736. }
  1737. },
  1738. { NULL, NULL, NULL, { END_ARGS } }
  1739. };
  1740. static const struct wpa_dbus_property_desc wpas_dbus_global_properties[] = {
  1741. { "DebugLevel", WPAS_DBUS_NEW_INTERFACE, "s",
  1742. wpas_dbus_getter_debug_level,
  1743. wpas_dbus_setter_debug_level
  1744. },
  1745. { "DebugTimestamp", WPAS_DBUS_NEW_INTERFACE, "b",
  1746. wpas_dbus_getter_debug_timestamp,
  1747. wpas_dbus_setter_debug_timestamp
  1748. },
  1749. { "DebugShowKeys", WPAS_DBUS_NEW_INTERFACE, "b",
  1750. wpas_dbus_getter_debug_show_keys,
  1751. wpas_dbus_setter_debug_show_keys
  1752. },
  1753. { "Interfaces", WPAS_DBUS_NEW_INTERFACE, "ao",
  1754. wpas_dbus_getter_interfaces,
  1755. NULL
  1756. },
  1757. { "EapMethods", WPAS_DBUS_NEW_INTERFACE, "as",
  1758. wpas_dbus_getter_eap_methods,
  1759. NULL
  1760. },
  1761. { "Capabilities", WPAS_DBUS_NEW_INTERFACE, "as",
  1762. wpas_dbus_getter_global_capabilities,
  1763. NULL
  1764. },
  1765. #ifdef CONFIG_WIFI_DISPLAY
  1766. { "WFDIEs", WPAS_DBUS_NEW_INTERFACE, "ay",
  1767. wpas_dbus_getter_global_wfd_ies,
  1768. wpas_dbus_setter_global_wfd_ies
  1769. },
  1770. #endif /* CONFIG_WIFI_DISPLAY */
  1771. { NULL, NULL, NULL, NULL, NULL }
  1772. };
  1773. static const struct wpa_dbus_signal_desc wpas_dbus_global_signals[] = {
  1774. { "InterfaceAdded", WPAS_DBUS_NEW_INTERFACE,
  1775. {
  1776. { "path", "o", ARG_OUT },
  1777. { "properties", "a{sv}", ARG_OUT },
  1778. END_ARGS
  1779. }
  1780. },
  1781. { "InterfaceRemoved", WPAS_DBUS_NEW_INTERFACE,
  1782. {
  1783. { "path", "o", ARG_OUT },
  1784. END_ARGS
  1785. }
  1786. },
  1787. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  1788. { "PropertiesChanged", WPAS_DBUS_NEW_INTERFACE,
  1789. {
  1790. { "properties", "a{sv}", ARG_OUT },
  1791. END_ARGS
  1792. }
  1793. },
  1794. { NULL, NULL, { END_ARGS } }
  1795. };
  1796. /**
  1797. * wpas_dbus_ctrl_iface_init - Initialize dbus control interface
  1798. * @global: Pointer to global data from wpa_supplicant_init()
  1799. * Returns: 0 on success or -1 on failure
  1800. *
  1801. * Initialize the dbus control interface for wpa_supplicantand and start
  1802. * receiving commands from external programs over the bus.
  1803. */
  1804. int wpas_dbus_ctrl_iface_init(struct wpas_dbus_priv *priv)
  1805. {
  1806. struct wpa_dbus_object_desc *obj_desc;
  1807. int ret;
  1808. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  1809. if (!obj_desc) {
  1810. wpa_printf(MSG_ERROR,
  1811. "Not enough memory to create object description");
  1812. return -1;
  1813. }
  1814. wpas_dbus_register(obj_desc, priv->global, NULL,
  1815. wpas_dbus_global_methods,
  1816. wpas_dbus_global_properties,
  1817. wpas_dbus_global_signals);
  1818. wpa_printf(MSG_DEBUG, "dbus: Register D-Bus object '%s'",
  1819. WPAS_DBUS_NEW_PATH);
  1820. ret = wpa_dbus_ctrl_iface_init(priv, WPAS_DBUS_NEW_PATH,
  1821. WPAS_DBUS_NEW_SERVICE,
  1822. obj_desc);
  1823. if (ret < 0)
  1824. free_dbus_object_desc(obj_desc);
  1825. else
  1826. priv->dbus_new_initialized = 1;
  1827. return ret;
  1828. }
  1829. /**
  1830. * wpas_dbus_ctrl_iface_deinit - Deinitialize dbus ctrl interface for
  1831. * wpa_supplicant
  1832. * @iface: Pointer to dbus private data from wpas_dbus_init()
  1833. *
  1834. * Deinitialize the dbus control interface that was initialized with
  1835. * wpas_dbus_ctrl_iface_init().
  1836. */
  1837. void wpas_dbus_ctrl_iface_deinit(struct wpas_dbus_priv *iface)
  1838. {
  1839. if (!iface->dbus_new_initialized)
  1840. return;
  1841. wpa_printf(MSG_DEBUG, "dbus: Unregister D-Bus object '%s'",
  1842. WPAS_DBUS_NEW_PATH);
  1843. dbus_connection_unregister_object_path(iface->con,
  1844. WPAS_DBUS_NEW_PATH);
  1845. }
  1846. static void wpa_dbus_free(void *ptr)
  1847. {
  1848. os_free(ptr);
  1849. }
  1850. static const struct wpa_dbus_property_desc wpas_dbus_network_properties[] = {
  1851. { "Properties", WPAS_DBUS_NEW_IFACE_NETWORK, "a{sv}",
  1852. wpas_dbus_getter_network_properties,
  1853. wpas_dbus_setter_network_properties
  1854. },
  1855. { "Enabled", WPAS_DBUS_NEW_IFACE_NETWORK, "b",
  1856. wpas_dbus_getter_enabled,
  1857. wpas_dbus_setter_enabled
  1858. },
  1859. { NULL, NULL, NULL, NULL, NULL }
  1860. };
  1861. static const struct wpa_dbus_signal_desc wpas_dbus_network_signals[] = {
  1862. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  1863. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_NETWORK,
  1864. {
  1865. { "properties", "a{sv}", ARG_OUT },
  1866. END_ARGS
  1867. }
  1868. },
  1869. { NULL, NULL, { END_ARGS } }
  1870. };
  1871. /**
  1872. * wpas_dbus_register_network - Register a configured network with dbus
  1873. * @wpa_s: wpa_supplicant interface structure
  1874. * @ssid: network configuration data
  1875. * Returns: 0 on success, -1 on failure
  1876. *
  1877. * Registers network representing object with dbus
  1878. */
  1879. int wpas_dbus_register_network(struct wpa_supplicant *wpa_s,
  1880. struct wpa_ssid *ssid)
  1881. {
  1882. struct wpas_dbus_priv *ctrl_iface;
  1883. struct wpa_dbus_object_desc *obj_desc;
  1884. struct network_handler_args *arg;
  1885. char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  1886. #ifdef CONFIG_P2P
  1887. /*
  1888. * If it is a persistent group register it as such.
  1889. * This is to handle cases where an interface is being initialized
  1890. * with a list of networks read from config.
  1891. */
  1892. if (network_is_persistent_group(ssid))
  1893. return wpas_dbus_register_persistent_group(wpa_s, ssid);
  1894. #endif /* CONFIG_P2P */
  1895. /* Do nothing if the control interface is not turned on */
  1896. if (wpa_s == NULL || wpa_s->global == NULL || !wpa_s->dbus_new_path)
  1897. return 0;
  1898. ctrl_iface = wpa_s->global->dbus;
  1899. if (ctrl_iface == NULL)
  1900. return 0;
  1901. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1902. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  1903. wpa_s->dbus_new_path, ssid->id);
  1904. wpa_printf(MSG_DEBUG, "dbus: Register network object '%s'",
  1905. net_obj_path);
  1906. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  1907. if (!obj_desc) {
  1908. wpa_printf(MSG_ERROR,
  1909. "Not enough memory to create object description");
  1910. goto err;
  1911. }
  1912. /* allocate memory for handlers arguments */
  1913. arg = os_zalloc(sizeof(struct network_handler_args));
  1914. if (!arg) {
  1915. wpa_printf(MSG_ERROR,
  1916. "Not enough memory to create arguments for method");
  1917. goto err;
  1918. }
  1919. arg->wpa_s = wpa_s;
  1920. arg->ssid = ssid;
  1921. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  1922. wpas_dbus_network_properties,
  1923. wpas_dbus_network_signals);
  1924. if (wpa_dbus_register_object_per_iface(ctrl_iface, net_obj_path,
  1925. wpa_s->ifname, obj_desc))
  1926. goto err;
  1927. wpas_dbus_signal_network_added(wpa_s, ssid->id);
  1928. return 0;
  1929. err:
  1930. free_dbus_object_desc(obj_desc);
  1931. return -1;
  1932. }
  1933. /**
  1934. * wpas_dbus_unregister_network - Unregister a configured network from dbus
  1935. * @wpa_s: wpa_supplicant interface structure
  1936. * @nid: network id
  1937. * Returns: 0 on success, -1 on failure
  1938. *
  1939. * Unregisters network representing object from dbus
  1940. */
  1941. int wpas_dbus_unregister_network(struct wpa_supplicant *wpa_s, int nid)
  1942. {
  1943. struct wpas_dbus_priv *ctrl_iface;
  1944. char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  1945. int ret;
  1946. #ifdef CONFIG_P2P
  1947. struct wpa_ssid *ssid;
  1948. ssid = wpa_config_get_network(wpa_s->conf, nid);
  1949. /* If it is a persistent group unregister it as such */
  1950. if (ssid && network_is_persistent_group(ssid))
  1951. return wpas_dbus_unregister_persistent_group(wpa_s, nid);
  1952. #endif /* CONFIG_P2P */
  1953. /* Do nothing if the control interface is not turned on */
  1954. if (wpa_s->global == NULL || wpa_s->dbus_new_path == NULL)
  1955. return 0;
  1956. ctrl_iface = wpa_s->global->dbus;
  1957. if (ctrl_iface == NULL)
  1958. return 0;
  1959. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1960. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  1961. wpa_s->dbus_new_path, nid);
  1962. wpa_printf(MSG_DEBUG, "dbus: Unregister network object '%s'",
  1963. net_obj_path);
  1964. ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, net_obj_path);
  1965. if (!ret)
  1966. wpas_dbus_signal_network_removed(wpa_s, nid);
  1967. return ret;
  1968. }
  1969. static const struct wpa_dbus_property_desc wpas_dbus_bss_properties[] = {
  1970. { "SSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
  1971. wpas_dbus_getter_bss_ssid,
  1972. NULL
  1973. },
  1974. { "BSSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
  1975. wpas_dbus_getter_bss_bssid,
  1976. NULL
  1977. },
  1978. { "Privacy", WPAS_DBUS_NEW_IFACE_BSS, "b",
  1979. wpas_dbus_getter_bss_privacy,
  1980. NULL
  1981. },
  1982. { "Mode", WPAS_DBUS_NEW_IFACE_BSS, "s",
  1983. wpas_dbus_getter_bss_mode,
  1984. NULL
  1985. },
  1986. { "Signal", WPAS_DBUS_NEW_IFACE_BSS, "n",
  1987. wpas_dbus_getter_bss_signal,
  1988. NULL
  1989. },
  1990. { "Frequency", WPAS_DBUS_NEW_IFACE_BSS, "q",
  1991. wpas_dbus_getter_bss_frequency,
  1992. NULL
  1993. },
  1994. { "Rates", WPAS_DBUS_NEW_IFACE_BSS, "au",
  1995. wpas_dbus_getter_bss_rates,
  1996. NULL
  1997. },
  1998. { "WPA", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
  1999. wpas_dbus_getter_bss_wpa,
  2000. NULL
  2001. },
  2002. { "RSN", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
  2003. wpas_dbus_getter_bss_rsn,
  2004. NULL
  2005. },
  2006. { "WPS", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
  2007. wpas_dbus_getter_bss_wps,
  2008. NULL
  2009. },
  2010. { "IEs", WPAS_DBUS_NEW_IFACE_BSS, "ay",
  2011. wpas_dbus_getter_bss_ies,
  2012. NULL
  2013. },
  2014. { "Age", WPAS_DBUS_NEW_IFACE_BSS, "u",
  2015. wpas_dbus_getter_bss_age,
  2016. NULL
  2017. },
  2018. { NULL, NULL, NULL, NULL, NULL }
  2019. };
  2020. static const struct wpa_dbus_signal_desc wpas_dbus_bss_signals[] = {
  2021. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  2022. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_BSS,
  2023. {
  2024. { "properties", "a{sv}", ARG_OUT },
  2025. END_ARGS
  2026. }
  2027. },
  2028. { NULL, NULL, { END_ARGS } }
  2029. };
  2030. /**
  2031. * wpas_dbus_unregister_bss - Unregister a scanned BSS from dbus
  2032. * @wpa_s: wpa_supplicant interface structure
  2033. * @bssid: scanned network bssid
  2034. * @id: unique BSS identifier
  2035. * Returns: 0 on success, -1 on failure
  2036. *
  2037. * Unregisters BSS representing object from dbus
  2038. */
  2039. int wpas_dbus_unregister_bss(struct wpa_supplicant *wpa_s,
  2040. u8 bssid[ETH_ALEN], unsigned int id)
  2041. {
  2042. struct wpas_dbus_priv *ctrl_iface;
  2043. char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2044. /* Do nothing if the control interface is not turned on */
  2045. if (wpa_s == NULL || wpa_s->global == NULL || !wpa_s->dbus_new_path)
  2046. return 0;
  2047. ctrl_iface = wpa_s->global->dbus;
  2048. if (ctrl_iface == NULL)
  2049. return 0;
  2050. os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2051. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  2052. wpa_s->dbus_new_path, id);
  2053. wpa_printf(MSG_DEBUG, "dbus: Unregister BSS object '%s'",
  2054. bss_obj_path);
  2055. if (wpa_dbus_unregister_object_per_iface(ctrl_iface, bss_obj_path)) {
  2056. wpa_printf(MSG_ERROR, "dbus: Cannot unregister BSS object %s",
  2057. bss_obj_path);
  2058. return -1;
  2059. }
  2060. wpas_dbus_signal_bss_removed(wpa_s, bss_obj_path);
  2061. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSSS);
  2062. return 0;
  2063. }
  2064. /**
  2065. * wpas_dbus_register_bss - Register a scanned BSS with dbus
  2066. * @wpa_s: wpa_supplicant interface structure
  2067. * @bssid: scanned network bssid
  2068. * @id: unique BSS identifier
  2069. * Returns: 0 on success, -1 on failure
  2070. *
  2071. * Registers BSS representing object with dbus
  2072. */
  2073. int wpas_dbus_register_bss(struct wpa_supplicant *wpa_s,
  2074. u8 bssid[ETH_ALEN], unsigned int id)
  2075. {
  2076. struct wpas_dbus_priv *ctrl_iface;
  2077. struct wpa_dbus_object_desc *obj_desc;
  2078. char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2079. struct bss_handler_args *arg;
  2080. /* Do nothing if the control interface is not turned on */
  2081. if (wpa_s == NULL || wpa_s->global == NULL || !wpa_s->dbus_new_path)
  2082. return 0;
  2083. ctrl_iface = wpa_s->global->dbus;
  2084. if (ctrl_iface == NULL)
  2085. return 0;
  2086. os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2087. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  2088. wpa_s->dbus_new_path, id);
  2089. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  2090. if (!obj_desc) {
  2091. wpa_printf(MSG_ERROR,
  2092. "Not enough memory to create object description");
  2093. goto err;
  2094. }
  2095. arg = os_zalloc(sizeof(struct bss_handler_args));
  2096. if (!arg) {
  2097. wpa_printf(MSG_ERROR,
  2098. "Not enough memory to create arguments for handler");
  2099. goto err;
  2100. }
  2101. arg->wpa_s = wpa_s;
  2102. arg->id = id;
  2103. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  2104. wpas_dbus_bss_properties,
  2105. wpas_dbus_bss_signals);
  2106. wpa_printf(MSG_DEBUG, "dbus: Register BSS object '%s'",
  2107. bss_obj_path);
  2108. if (wpa_dbus_register_object_per_iface(ctrl_iface, bss_obj_path,
  2109. wpa_s->ifname, obj_desc)) {
  2110. wpa_printf(MSG_ERROR,
  2111. "Cannot register BSSID dbus object %s.",
  2112. bss_obj_path);
  2113. goto err;
  2114. }
  2115. wpas_dbus_signal_bss_added(wpa_s, bss_obj_path);
  2116. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSSS);
  2117. return 0;
  2118. err:
  2119. free_dbus_object_desc(obj_desc);
  2120. return -1;
  2121. }
  2122. static const struct wpa_dbus_method_desc wpas_dbus_interface_methods[] = {
  2123. { "Scan", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2124. (WPADBusMethodHandler) wpas_dbus_handler_scan,
  2125. {
  2126. { "args", "a{sv}", ARG_IN },
  2127. END_ARGS
  2128. }
  2129. },
  2130. { "SignalPoll", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2131. (WPADBusMethodHandler) wpas_dbus_handler_signal_poll,
  2132. {
  2133. { "args", "a{sv}", ARG_OUT },
  2134. END_ARGS
  2135. }
  2136. },
  2137. { "Disconnect", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2138. (WPADBusMethodHandler) wpas_dbus_handler_disconnect,
  2139. {
  2140. END_ARGS
  2141. }
  2142. },
  2143. { "AddNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2144. (WPADBusMethodHandler) wpas_dbus_handler_add_network,
  2145. {
  2146. { "args", "a{sv}", ARG_IN },
  2147. { "path", "o", ARG_OUT },
  2148. END_ARGS
  2149. }
  2150. },
  2151. { "Reassociate", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2152. (WPADBusMethodHandler) wpas_dbus_handler_reassociate,
  2153. {
  2154. END_ARGS
  2155. }
  2156. },
  2157. { "Reattach", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2158. (WPADBusMethodHandler) wpas_dbus_handler_reattach,
  2159. {
  2160. END_ARGS
  2161. }
  2162. },
  2163. { "RemoveNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2164. (WPADBusMethodHandler) wpas_dbus_handler_remove_network,
  2165. {
  2166. { "path", "o", ARG_IN },
  2167. END_ARGS
  2168. }
  2169. },
  2170. { "RemoveAllNetworks", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2171. (WPADBusMethodHandler) wpas_dbus_handler_remove_all_networks,
  2172. {
  2173. END_ARGS
  2174. }
  2175. },
  2176. { "SelectNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2177. (WPADBusMethodHandler) wpas_dbus_handler_select_network,
  2178. {
  2179. { "path", "o", ARG_IN },
  2180. END_ARGS
  2181. }
  2182. },
  2183. { "NetworkReply", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2184. (WPADBusMethodHandler) wpas_dbus_handler_network_reply,
  2185. {
  2186. { "path", "o", ARG_IN },
  2187. { "field", "s", ARG_IN },
  2188. { "value", "s", ARG_IN },
  2189. END_ARGS
  2190. }
  2191. },
  2192. #ifndef CONFIG_NO_CONFIG_BLOBS
  2193. { "AddBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2194. (WPADBusMethodHandler) wpas_dbus_handler_add_blob,
  2195. {
  2196. { "name", "s", ARG_IN },
  2197. { "data", "ay", ARG_IN },
  2198. END_ARGS
  2199. }
  2200. },
  2201. { "GetBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2202. (WPADBusMethodHandler) wpas_dbus_handler_get_blob,
  2203. {
  2204. { "name", "s", ARG_IN },
  2205. { "data", "ay", ARG_OUT },
  2206. END_ARGS
  2207. }
  2208. },
  2209. { "RemoveBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2210. (WPADBusMethodHandler) wpas_dbus_handler_remove_blob,
  2211. {
  2212. { "name", "s", ARG_IN },
  2213. END_ARGS
  2214. }
  2215. },
  2216. #endif /* CONFIG_NO_CONFIG_BLOBS */
  2217. { "SetPKCS11EngineAndModulePath", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2218. (WPADBusMethodHandler)
  2219. wpas_dbus_handler_set_pkcs11_engine_and_module_path,
  2220. {
  2221. { "pkcs11_engine_path", "s", ARG_IN },
  2222. { "pkcs11_module_path", "s", ARG_IN },
  2223. END_ARGS
  2224. }
  2225. },
  2226. #ifdef CONFIG_WPS
  2227. { "Start", WPAS_DBUS_NEW_IFACE_WPS,
  2228. (WPADBusMethodHandler) wpas_dbus_handler_wps_start,
  2229. {
  2230. { "args", "a{sv}", ARG_IN },
  2231. { "output", "a{sv}", ARG_OUT },
  2232. END_ARGS
  2233. }
  2234. },
  2235. { "Cancel", WPAS_DBUS_NEW_IFACE_WPS,
  2236. (WPADBusMethodHandler) wpas_dbus_handler_wps_cancel,
  2237. {
  2238. END_ARGS
  2239. }
  2240. },
  2241. #endif /* CONFIG_WPS */
  2242. #ifdef CONFIG_P2P
  2243. { "Find", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2244. (WPADBusMethodHandler) wpas_dbus_handler_p2p_find,
  2245. {
  2246. { "args", "a{sv}", ARG_IN },
  2247. END_ARGS
  2248. }
  2249. },
  2250. { "StopFind", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2251. (WPADBusMethodHandler) wpas_dbus_handler_p2p_stop_find,
  2252. {
  2253. END_ARGS
  2254. }
  2255. },
  2256. { "Listen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2257. (WPADBusMethodHandler) wpas_dbus_handler_p2p_listen,
  2258. {
  2259. { "timeout", "i", ARG_IN },
  2260. END_ARGS
  2261. }
  2262. },
  2263. { "ExtendedListen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2264. (WPADBusMethodHandler) wpas_dbus_handler_p2p_extendedlisten,
  2265. {
  2266. { "args", "a{sv}", ARG_IN },
  2267. END_ARGS
  2268. }
  2269. },
  2270. { "PresenceRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2271. (WPADBusMethodHandler) wpas_dbus_handler_p2p_presence_request,
  2272. {
  2273. { "args", "a{sv}", ARG_IN },
  2274. END_ARGS
  2275. }
  2276. },
  2277. { "ProvisionDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2278. (WPADBusMethodHandler) wpas_dbus_handler_p2p_prov_disc_req,
  2279. {
  2280. { "peer", "o", ARG_IN },
  2281. { "config_method", "s", ARG_IN },
  2282. END_ARGS
  2283. }
  2284. },
  2285. { "Connect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2286. (WPADBusMethodHandler) wpas_dbus_handler_p2p_connect,
  2287. {
  2288. { "args", "a{sv}", ARG_IN },
  2289. { "generated_pin", "s", ARG_OUT },
  2290. END_ARGS
  2291. }
  2292. },
  2293. { "GroupAdd", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2294. (WPADBusMethodHandler) wpas_dbus_handler_p2p_group_add,
  2295. {
  2296. { "args", "a{sv}", ARG_IN },
  2297. END_ARGS
  2298. }
  2299. },
  2300. { "Cancel", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2301. (WPADBusMethodHandler) wpas_dbus_handler_p2p_cancel,
  2302. {
  2303. END_ARGS
  2304. }
  2305. },
  2306. { "Invite", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2307. (WPADBusMethodHandler) wpas_dbus_handler_p2p_invite,
  2308. {
  2309. { "args", "a{sv}", ARG_IN },
  2310. END_ARGS
  2311. }
  2312. },
  2313. { "Disconnect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2314. (WPADBusMethodHandler) wpas_dbus_handler_p2p_disconnect,
  2315. {
  2316. END_ARGS
  2317. }
  2318. },
  2319. { "RejectPeer", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2320. (WPADBusMethodHandler) wpas_dbus_handler_p2p_rejectpeer,
  2321. {
  2322. { "peer", "o", ARG_IN },
  2323. END_ARGS
  2324. }
  2325. },
  2326. { "Flush", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2327. (WPADBusMethodHandler) wpas_dbus_handler_p2p_flush,
  2328. {
  2329. END_ARGS
  2330. }
  2331. },
  2332. { "AddService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2333. (WPADBusMethodHandler) wpas_dbus_handler_p2p_add_service,
  2334. {
  2335. { "args", "a{sv}", ARG_IN },
  2336. END_ARGS
  2337. }
  2338. },
  2339. { "DeleteService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2340. (WPADBusMethodHandler) wpas_dbus_handler_p2p_delete_service,
  2341. {
  2342. { "args", "a{sv}", ARG_IN },
  2343. END_ARGS
  2344. }
  2345. },
  2346. { "FlushService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2347. (WPADBusMethodHandler) wpas_dbus_handler_p2p_flush_service,
  2348. {
  2349. END_ARGS
  2350. }
  2351. },
  2352. { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2353. (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_sd_req,
  2354. {
  2355. { "args", "a{sv}", ARG_IN },
  2356. { "ref", "t", ARG_OUT },
  2357. END_ARGS
  2358. }
  2359. },
  2360. { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2361. (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_sd_res,
  2362. {
  2363. { "args", "a{sv}", ARG_IN },
  2364. END_ARGS
  2365. }
  2366. },
  2367. { "ServiceDiscoveryCancelRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2368. (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_sd_cancel_req,
  2369. {
  2370. { "args", "t", ARG_IN },
  2371. END_ARGS
  2372. }
  2373. },
  2374. { "ServiceUpdate", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2375. (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_update,
  2376. {
  2377. END_ARGS
  2378. }
  2379. },
  2380. { "ServiceDiscoveryExternal", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2381. (WPADBusMethodHandler) wpas_dbus_handler_p2p_serv_disc_external,
  2382. {
  2383. { "arg", "i", ARG_IN },
  2384. END_ARGS
  2385. }
  2386. },
  2387. { "AddPersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2388. (WPADBusMethodHandler) wpas_dbus_handler_add_persistent_group,
  2389. {
  2390. { "args", "a{sv}", ARG_IN },
  2391. { "path", "o", ARG_OUT },
  2392. END_ARGS
  2393. }
  2394. },
  2395. { "RemovePersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2396. (WPADBusMethodHandler) wpas_dbus_handler_remove_persistent_group,
  2397. {
  2398. { "path", "o", ARG_IN },
  2399. END_ARGS
  2400. }
  2401. },
  2402. { "RemoveAllPersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2403. (WPADBusMethodHandler)
  2404. wpas_dbus_handler_remove_all_persistent_groups,
  2405. {
  2406. END_ARGS
  2407. }
  2408. },
  2409. #endif /* CONFIG_P2P */
  2410. { "FlushBSS", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2411. (WPADBusMethodHandler) wpas_dbus_handler_flush_bss,
  2412. {
  2413. { "age", "u", ARG_IN },
  2414. END_ARGS
  2415. }
  2416. },
  2417. #ifdef CONFIG_AP
  2418. { "SubscribeProbeReq", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2419. (WPADBusMethodHandler) wpas_dbus_handler_subscribe_preq,
  2420. {
  2421. END_ARGS
  2422. }
  2423. },
  2424. { "UnsubscribeProbeReq", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2425. (WPADBusMethodHandler) wpas_dbus_handler_unsubscribe_preq,
  2426. {
  2427. END_ARGS
  2428. }
  2429. },
  2430. #endif /* CONFIG_AP */
  2431. { "EAPLogoff", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2432. (WPADBusMethodHandler) wpas_dbus_handler_eap_logoff,
  2433. {
  2434. END_ARGS
  2435. }
  2436. },
  2437. { "EAPLogon", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2438. (WPADBusMethodHandler) wpas_dbus_handler_eap_logon,
  2439. {
  2440. END_ARGS
  2441. }
  2442. },
  2443. #ifdef CONFIG_AUTOSCAN
  2444. { "AutoScan", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2445. (WPADBusMethodHandler) wpas_dbus_handler_autoscan,
  2446. {
  2447. { "arg", "s", ARG_IN },
  2448. END_ARGS
  2449. }
  2450. },
  2451. #endif /* CONFIG_AUTOSCAN */
  2452. #ifdef CONFIG_TDLS
  2453. { "TDLSDiscover", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2454. (WPADBusMethodHandler) wpas_dbus_handler_tdls_discover,
  2455. {
  2456. { "peer_address", "s", ARG_IN },
  2457. END_ARGS
  2458. }
  2459. },
  2460. { "TDLSSetup", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2461. (WPADBusMethodHandler) wpas_dbus_handler_tdls_setup,
  2462. {
  2463. { "peer_address", "s", ARG_IN },
  2464. END_ARGS
  2465. }
  2466. },
  2467. { "TDLSStatus", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2468. (WPADBusMethodHandler) wpas_dbus_handler_tdls_status,
  2469. {
  2470. { "peer_address", "s", ARG_IN },
  2471. { "status", "s", ARG_OUT },
  2472. END_ARGS
  2473. }
  2474. },
  2475. { "TDLSTeardown", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2476. (WPADBusMethodHandler) wpas_dbus_handler_tdls_teardown,
  2477. {
  2478. { "peer_address", "s", ARG_IN },
  2479. END_ARGS
  2480. }
  2481. },
  2482. #endif /* CONFIG_TDLS */
  2483. { NULL, NULL, NULL, { END_ARGS } }
  2484. };
  2485. static const struct wpa_dbus_property_desc wpas_dbus_interface_properties[] = {
  2486. { "Capabilities", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{sv}",
  2487. wpas_dbus_getter_capabilities,
  2488. NULL
  2489. },
  2490. { "State", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2491. wpas_dbus_getter_state,
  2492. NULL
  2493. },
  2494. { "Scanning", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
  2495. wpas_dbus_getter_scanning,
  2496. NULL
  2497. },
  2498. { "ApScan", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  2499. wpas_dbus_getter_ap_scan,
  2500. wpas_dbus_setter_ap_scan
  2501. },
  2502. { "BSSExpireAge", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  2503. wpas_dbus_getter_bss_expire_age,
  2504. wpas_dbus_setter_bss_expire_age
  2505. },
  2506. { "BSSExpireCount", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  2507. wpas_dbus_getter_bss_expire_count,
  2508. wpas_dbus_setter_bss_expire_count
  2509. },
  2510. { "Country", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2511. wpas_dbus_getter_country,
  2512. wpas_dbus_setter_country
  2513. },
  2514. { "Ifname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2515. wpas_dbus_getter_ifname,
  2516. NULL
  2517. },
  2518. { "Driver", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2519. wpas_dbus_getter_driver,
  2520. NULL
  2521. },
  2522. { "BridgeIfname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2523. wpas_dbus_getter_bridge_ifname,
  2524. NULL
  2525. },
  2526. { "CurrentBSS", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
  2527. wpas_dbus_getter_current_bss,
  2528. NULL
  2529. },
  2530. { "CurrentNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
  2531. wpas_dbus_getter_current_network,
  2532. NULL
  2533. },
  2534. { "CurrentAuthMode", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2535. wpas_dbus_getter_current_auth_mode,
  2536. NULL
  2537. },
  2538. { "Blobs", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{say}",
  2539. wpas_dbus_getter_blobs,
  2540. NULL
  2541. },
  2542. { "BSSs", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
  2543. wpas_dbus_getter_bsss,
  2544. NULL
  2545. },
  2546. { "Networks", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
  2547. wpas_dbus_getter_networks,
  2548. NULL
  2549. },
  2550. { "FastReauth", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
  2551. wpas_dbus_getter_fast_reauth,
  2552. wpas_dbus_setter_fast_reauth
  2553. },
  2554. { "ScanInterval", WPAS_DBUS_NEW_IFACE_INTERFACE, "i",
  2555. wpas_dbus_getter_scan_interval,
  2556. wpas_dbus_setter_scan_interval
  2557. },
  2558. { "PKCS11EnginePath", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2559. wpas_dbus_getter_pkcs11_engine_path,
  2560. NULL
  2561. },
  2562. { "PKCS11ModulePath", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2563. wpas_dbus_getter_pkcs11_module_path,
  2564. NULL
  2565. },
  2566. #ifdef CONFIG_WPS
  2567. { "ProcessCredentials", WPAS_DBUS_NEW_IFACE_WPS, "b",
  2568. wpas_dbus_getter_process_credentials,
  2569. wpas_dbus_setter_process_credentials
  2570. },
  2571. { "ConfigMethods", WPAS_DBUS_NEW_IFACE_WPS, "s",
  2572. wpas_dbus_getter_config_methods,
  2573. wpas_dbus_setter_config_methods
  2574. },
  2575. #endif /* CONFIG_WPS */
  2576. #ifdef CONFIG_P2P
  2577. { "P2PDeviceConfig", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "a{sv}",
  2578. wpas_dbus_getter_p2p_device_config,
  2579. wpas_dbus_setter_p2p_device_config
  2580. },
  2581. { "Peers", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
  2582. wpas_dbus_getter_p2p_peers,
  2583. NULL
  2584. },
  2585. { "Role", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "s",
  2586. wpas_dbus_getter_p2p_role,
  2587. NULL
  2588. },
  2589. { "Group", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
  2590. wpas_dbus_getter_p2p_group,
  2591. NULL
  2592. },
  2593. { "PeerGO", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
  2594. wpas_dbus_getter_p2p_peergo,
  2595. NULL
  2596. },
  2597. { "PersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
  2598. wpas_dbus_getter_persistent_groups,
  2599. NULL
  2600. },
  2601. #endif /* CONFIG_P2P */
  2602. { "DisconnectReason", WPAS_DBUS_NEW_IFACE_INTERFACE, "i",
  2603. wpas_dbus_getter_disconnect_reason,
  2604. NULL
  2605. },
  2606. { NULL, NULL, NULL, NULL, NULL }
  2607. };
  2608. static const struct wpa_dbus_signal_desc wpas_dbus_interface_signals[] = {
  2609. { "ScanDone", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2610. {
  2611. { "success", "b", ARG_OUT },
  2612. END_ARGS
  2613. }
  2614. },
  2615. { "BSSAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2616. {
  2617. { "path", "o", ARG_OUT },
  2618. { "properties", "a{sv}", ARG_OUT },
  2619. END_ARGS
  2620. }
  2621. },
  2622. { "BSSRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2623. {
  2624. { "path", "o", ARG_OUT },
  2625. END_ARGS
  2626. }
  2627. },
  2628. { "BlobAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2629. {
  2630. { "name", "s", ARG_OUT },
  2631. END_ARGS
  2632. }
  2633. },
  2634. { "BlobRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2635. {
  2636. { "name", "s", ARG_OUT },
  2637. END_ARGS
  2638. }
  2639. },
  2640. { "NetworkAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2641. {
  2642. { "path", "o", ARG_OUT },
  2643. { "properties", "a{sv}", ARG_OUT },
  2644. END_ARGS
  2645. }
  2646. },
  2647. { "NetworkRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2648. {
  2649. { "path", "o", ARG_OUT },
  2650. END_ARGS
  2651. }
  2652. },
  2653. { "NetworkSelected", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2654. {
  2655. { "path", "o", ARG_OUT },
  2656. END_ARGS
  2657. }
  2658. },
  2659. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  2660. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2661. {
  2662. { "properties", "a{sv}", ARG_OUT },
  2663. END_ARGS
  2664. }
  2665. },
  2666. #ifdef CONFIG_WPS
  2667. { "Event", WPAS_DBUS_NEW_IFACE_WPS,
  2668. {
  2669. { "name", "s", ARG_OUT },
  2670. { "args", "a{sv}", ARG_OUT },
  2671. END_ARGS
  2672. }
  2673. },
  2674. { "Credentials", WPAS_DBUS_NEW_IFACE_WPS,
  2675. {
  2676. { "credentials", "a{sv}", ARG_OUT },
  2677. END_ARGS
  2678. }
  2679. },
  2680. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  2681. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_WPS,
  2682. {
  2683. { "properties", "a{sv}", ARG_OUT },
  2684. END_ARGS
  2685. }
  2686. },
  2687. #endif /* CONFIG_WPS */
  2688. #ifdef CONFIG_P2P
  2689. { "DeviceFound", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2690. {
  2691. { "path", "o", ARG_OUT },
  2692. END_ARGS
  2693. }
  2694. },
  2695. { "DeviceLost", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2696. {
  2697. { "path", "o", ARG_OUT },
  2698. END_ARGS
  2699. }
  2700. },
  2701. { "FindStopped", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2702. {
  2703. END_ARGS
  2704. }
  2705. },
  2706. { "ProvisionDiscoveryRequestDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2707. {
  2708. { "peer_object", "o", ARG_OUT },
  2709. { "pin", "s", ARG_OUT },
  2710. END_ARGS
  2711. }
  2712. },
  2713. { "ProvisionDiscoveryResponseDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2714. {
  2715. { "peer_object", "o", ARG_OUT },
  2716. { "pin", "s", ARG_OUT },
  2717. END_ARGS
  2718. }
  2719. },
  2720. { "ProvisionDiscoveryRequestEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2721. {
  2722. { "peer_object", "o", ARG_OUT },
  2723. END_ARGS
  2724. }
  2725. },
  2726. { "ProvisionDiscoveryResponseEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2727. {
  2728. { "peer_object", "o", ARG_OUT },
  2729. END_ARGS
  2730. }
  2731. },
  2732. { "ProvisionDiscoveryPBCRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2733. {
  2734. { "peer_object", "o", ARG_OUT },
  2735. END_ARGS
  2736. }
  2737. },
  2738. { "ProvisionDiscoveryPBCResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2739. {
  2740. { "peer_object", "o", ARG_OUT },
  2741. END_ARGS
  2742. }
  2743. },
  2744. { "ProvisionDiscoveryFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2745. {
  2746. { "peer_object", "o", ARG_OUT },
  2747. { "status", "i", ARG_OUT },
  2748. END_ARGS
  2749. }
  2750. },
  2751. { "GroupStarted", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2752. {
  2753. { "properties", "a{sv}", ARG_OUT },
  2754. END_ARGS
  2755. }
  2756. },
  2757. { "GONegotiationSuccess", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2758. {
  2759. { "properties", "a{sv}", ARG_OUT },
  2760. END_ARGS
  2761. }
  2762. },
  2763. { "GONegotiationFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2764. {
  2765. { "properties", "a{sv}", ARG_OUT },
  2766. END_ARGS
  2767. }
  2768. },
  2769. { "GONegotiationRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2770. {
  2771. { "path", "o", ARG_OUT },
  2772. { "dev_passwd_id", "i", ARG_OUT },
  2773. { "device_go_intent", "y", ARG_OUT },
  2774. END_ARGS
  2775. }
  2776. },
  2777. { "InvitationResult", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2778. {
  2779. { "invite_result", "a{sv}", ARG_OUT },
  2780. END_ARGS
  2781. }
  2782. },
  2783. { "GroupFinished", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2784. {
  2785. { "properties", "a{sv}", ARG_OUT },
  2786. END_ARGS
  2787. }
  2788. },
  2789. { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2790. {
  2791. { "sd_request", "a{sv}", ARG_OUT },
  2792. END_ARGS
  2793. }
  2794. },
  2795. { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2796. {
  2797. { "sd_response", "a{sv}", ARG_OUT },
  2798. END_ARGS
  2799. }
  2800. },
  2801. { "PersistentGroupAdded", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2802. {
  2803. { "path", "o", ARG_OUT },
  2804. { "properties", "a{sv}", ARG_OUT },
  2805. END_ARGS
  2806. }
  2807. },
  2808. { "PersistentGroupRemoved", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2809. {
  2810. { "path", "o", ARG_OUT },
  2811. END_ARGS
  2812. }
  2813. },
  2814. { "WpsFailed", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2815. {
  2816. { "name", "s", ARG_OUT },
  2817. { "args", "a{sv}", ARG_OUT },
  2818. END_ARGS
  2819. }
  2820. },
  2821. #endif /* CONFIG_P2P */
  2822. #ifdef CONFIG_AP
  2823. { "ProbeRequest", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2824. {
  2825. { "args", "a{sv}", ARG_OUT },
  2826. END_ARGS
  2827. }
  2828. },
  2829. #endif /* CONFIG_AP */
  2830. { "Certification", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2831. {
  2832. { "certification", "a{sv}", ARG_OUT },
  2833. END_ARGS
  2834. }
  2835. },
  2836. { "EAP", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2837. {
  2838. { "status", "s", ARG_OUT },
  2839. { "parameter", "s", ARG_OUT },
  2840. END_ARGS
  2841. }
  2842. },
  2843. { "StaAuthorized", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2844. {
  2845. { "name", "s", ARG_OUT },
  2846. END_ARGS
  2847. }
  2848. },
  2849. { "StaDeauthorized", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2850. {
  2851. { "name", "s", ARG_OUT },
  2852. END_ARGS
  2853. }
  2854. },
  2855. { "NetworkRequest", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2856. {
  2857. { "path", "o", ARG_OUT },
  2858. { "field", "s", ARG_OUT },
  2859. { "text", "s", ARG_OUT },
  2860. END_ARGS
  2861. }
  2862. },
  2863. { NULL, NULL, { END_ARGS } }
  2864. };
  2865. int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s)
  2866. {
  2867. struct wpa_dbus_object_desc *obj_desc = NULL;
  2868. struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus;
  2869. int next;
  2870. /* Do nothing if the control interface is not turned on */
  2871. if (ctrl_iface == NULL)
  2872. return 0;
  2873. /* Create and set the interface's object path */
  2874. wpa_s->dbus_new_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
  2875. if (wpa_s->dbus_new_path == NULL)
  2876. return -1;
  2877. next = ctrl_iface->next_objid++;
  2878. os_snprintf(wpa_s->dbus_new_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2879. WPAS_DBUS_NEW_PATH_INTERFACES "/%u",
  2880. next);
  2881. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  2882. if (!obj_desc) {
  2883. wpa_printf(MSG_ERROR,
  2884. "Not enough memory to create object description");
  2885. goto err;
  2886. }
  2887. wpas_dbus_register(obj_desc, wpa_s, NULL, wpas_dbus_interface_methods,
  2888. wpas_dbus_interface_properties,
  2889. wpas_dbus_interface_signals);
  2890. wpa_printf(MSG_DEBUG, "dbus: Register interface object '%s'",
  2891. wpa_s->dbus_new_path);
  2892. if (wpa_dbus_register_object_per_iface(ctrl_iface,
  2893. wpa_s->dbus_new_path,
  2894. wpa_s->ifname, obj_desc))
  2895. goto err;
  2896. wpas_dbus_signal_interface_added(wpa_s);
  2897. return 0;
  2898. err:
  2899. os_free(wpa_s->dbus_new_path);
  2900. wpa_s->dbus_new_path = NULL;
  2901. free_dbus_object_desc(obj_desc);
  2902. return -1;
  2903. }
  2904. int wpas_dbus_unregister_interface(struct wpa_supplicant *wpa_s)
  2905. {
  2906. struct wpas_dbus_priv *ctrl_iface;
  2907. /* Do nothing if the control interface is not turned on */
  2908. if (wpa_s == NULL || wpa_s->global == NULL)
  2909. return 0;
  2910. ctrl_iface = wpa_s->global->dbus;
  2911. if (ctrl_iface == NULL || wpa_s->dbus_new_path == NULL)
  2912. return 0;
  2913. wpa_printf(MSG_DEBUG, "dbus: Unregister interface object '%s'",
  2914. wpa_s->dbus_new_path);
  2915. #ifdef CONFIG_AP
  2916. if (wpa_s->preq_notify_peer) {
  2917. wpas_dbus_unsubscribe_noc(ctrl_iface);
  2918. os_free(wpa_s->preq_notify_peer);
  2919. wpa_s->preq_notify_peer = NULL;
  2920. }
  2921. #endif /* CONFIG_AP */
  2922. if (wpa_dbus_unregister_object_per_iface(ctrl_iface,
  2923. wpa_s->dbus_new_path))
  2924. return -1;
  2925. wpas_dbus_signal_interface_removed(wpa_s);
  2926. os_free(wpa_s->dbus_new_path);
  2927. wpa_s->dbus_new_path = NULL;
  2928. return 0;
  2929. }
  2930. #ifdef CONFIG_P2P
  2931. static const struct wpa_dbus_property_desc wpas_dbus_p2p_peer_properties[] = {
  2932. { "DeviceName", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
  2933. wpas_dbus_getter_p2p_peer_device_name,
  2934. NULL
  2935. },
  2936. { "Manufacturer", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
  2937. wpas_dbus_getter_p2p_peer_manufacturer,
  2938. NULL
  2939. },
  2940. { "ModelName", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
  2941. wpas_dbus_getter_p2p_peer_modelname,
  2942. NULL
  2943. },
  2944. { "ModelNumber", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
  2945. wpas_dbus_getter_p2p_peer_modelnumber,
  2946. NULL
  2947. },
  2948. { "SerialNumber", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
  2949. wpas_dbus_getter_p2p_peer_serialnumber,
  2950. NULL
  2951. },
  2952. { "PrimaryDeviceType", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
  2953. wpas_dbus_getter_p2p_peer_primary_device_type,
  2954. NULL
  2955. },
  2956. { "config_method", WPAS_DBUS_NEW_IFACE_P2P_PEER, "q",
  2957. wpas_dbus_getter_p2p_peer_config_method,
  2958. NULL
  2959. },
  2960. { "level", WPAS_DBUS_NEW_IFACE_P2P_PEER, "i",
  2961. wpas_dbus_getter_p2p_peer_level,
  2962. NULL
  2963. },
  2964. { "devicecapability", WPAS_DBUS_NEW_IFACE_P2P_PEER, "y",
  2965. wpas_dbus_getter_p2p_peer_device_capability,
  2966. NULL
  2967. },
  2968. { "groupcapability", WPAS_DBUS_NEW_IFACE_P2P_PEER, "y",
  2969. wpas_dbus_getter_p2p_peer_group_capability,
  2970. NULL
  2971. },
  2972. { "SecondaryDeviceTypes", WPAS_DBUS_NEW_IFACE_P2P_PEER, "aay",
  2973. wpas_dbus_getter_p2p_peer_secondary_device_types,
  2974. NULL
  2975. },
  2976. { "VendorExtension", WPAS_DBUS_NEW_IFACE_P2P_PEER, "aay",
  2977. wpas_dbus_getter_p2p_peer_vendor_extension,
  2978. NULL
  2979. },
  2980. { "IEs", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
  2981. wpas_dbus_getter_p2p_peer_ies,
  2982. NULL
  2983. },
  2984. { "DeviceAddress", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
  2985. wpas_dbus_getter_p2p_peer_device_address,
  2986. NULL
  2987. },
  2988. { "Groups", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ao",
  2989. wpas_dbus_getter_p2p_peer_groups,
  2990. NULL
  2991. },
  2992. { NULL, NULL, NULL, NULL, NULL }
  2993. };
  2994. static const struct wpa_dbus_signal_desc wpas_dbus_p2p_peer_signals[] = {
  2995. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  2996. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_P2P_PEER,
  2997. {
  2998. { "properties", "a{sv}", ARG_OUT },
  2999. END_ARGS
  3000. }
  3001. },
  3002. { NULL, NULL, { END_ARGS } }
  3003. };
  3004. /**
  3005. * wpas_dbus_signal_peer - Send a peer related event signal
  3006. * @wpa_s: %wpa_supplicant network interface data
  3007. * @dev: peer device object
  3008. * @interface: name of the interface emitting this signal.
  3009. * In case of peer objects, it would be emitted by either
  3010. * the "interface object" or by "peer objects"
  3011. * @sig_name: signal name - DeviceFound
  3012. *
  3013. * Notify listeners about event related with newly found p2p peer device
  3014. */
  3015. static void wpas_dbus_signal_peer(struct wpa_supplicant *wpa_s,
  3016. const u8 *dev_addr, const char *interface,
  3017. const char *sig_name)
  3018. {
  3019. struct wpas_dbus_priv *iface;
  3020. DBusMessage *msg;
  3021. DBusMessageIter iter;
  3022. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  3023. if (wpa_s->p2p_mgmt)
  3024. wpa_s = wpa_s->parent;
  3025. iface = wpa_s->global->dbus;
  3026. /* Do nothing if the control interface is not turned on */
  3027. if (iface == NULL || !wpa_s->dbus_new_path)
  3028. return;
  3029. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3030. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  3031. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  3032. msg = dbus_message_new_signal(wpa_s->dbus_new_path, interface,
  3033. sig_name);
  3034. if (msg == NULL)
  3035. return;
  3036. dbus_message_iter_init_append(msg, &iter);
  3037. path = peer_obj_path;
  3038. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  3039. &path))
  3040. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  3041. else
  3042. dbus_connection_send(iface->con, msg, NULL);
  3043. dbus_message_unref(msg);
  3044. }
  3045. /**
  3046. * wpas_dbus_signal_peer_found - Send a peer found signal
  3047. * @wpa_s: %wpa_supplicant network interface data
  3048. * @dev: peer device object
  3049. *
  3050. * Notify listeners about find a p2p peer device found
  3051. */
  3052. void wpas_dbus_signal_peer_device_found(struct wpa_supplicant *wpa_s,
  3053. const u8 *dev_addr)
  3054. {
  3055. wpas_dbus_signal_peer(wpa_s, dev_addr,
  3056. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3057. "DeviceFound");
  3058. }
  3059. /**
  3060. * wpas_dbus_signal_peer_lost - Send a peer lost signal
  3061. * @wpa_s: %wpa_supplicant network interface data
  3062. * @dev: peer device object
  3063. *
  3064. * Notify listeners about lost a p2p peer device
  3065. */
  3066. void wpas_dbus_signal_peer_device_lost(struct wpa_supplicant *wpa_s,
  3067. const u8 *dev_addr)
  3068. {
  3069. wpas_dbus_signal_peer(wpa_s, dev_addr,
  3070. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3071. "DeviceLost");
  3072. }
  3073. /**
  3074. * wpas_dbus_register_peer - Register a discovered peer object with dbus
  3075. * @wpa_s: wpa_supplicant interface structure
  3076. * @ssid: network configuration data
  3077. * Returns: 0 on success, -1 on failure
  3078. *
  3079. * Registers network representing object with dbus
  3080. */
  3081. int wpas_dbus_register_peer(struct wpa_supplicant *wpa_s, const u8 *dev_addr)
  3082. {
  3083. struct wpas_dbus_priv *ctrl_iface;
  3084. struct wpa_dbus_object_desc *obj_desc;
  3085. struct peer_handler_args *arg;
  3086. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3087. /* Do nothing if the control interface is not turned on */
  3088. if (wpa_s == NULL || wpa_s->global == NULL)
  3089. return 0;
  3090. ctrl_iface = wpa_s->global->dbus;
  3091. if (ctrl_iface == NULL)
  3092. return 0;
  3093. wpa_s = wpa_s->parent->parent;
  3094. if (!wpa_s->dbus_new_path)
  3095. return 0;
  3096. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3097. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  3098. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  3099. wpa_printf(MSG_INFO, "dbus: Register peer object '%s'",
  3100. peer_obj_path);
  3101. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  3102. if (!obj_desc) {
  3103. wpa_printf(MSG_ERROR,
  3104. "Not enough memory to create object description");
  3105. goto err;
  3106. }
  3107. /* allocate memory for handlers arguments */
  3108. arg = os_zalloc(sizeof(struct peer_handler_args));
  3109. if (!arg) {
  3110. wpa_printf(MSG_ERROR,
  3111. "Not enough memory to create arguments for method");
  3112. goto err;
  3113. }
  3114. arg->wpa_s = wpa_s;
  3115. os_memcpy(arg->p2p_device_addr, dev_addr, ETH_ALEN);
  3116. wpas_dbus_register(obj_desc, arg, wpa_dbus_free,
  3117. NULL,
  3118. wpas_dbus_p2p_peer_properties,
  3119. wpas_dbus_p2p_peer_signals);
  3120. if (wpa_dbus_register_object_per_iface(ctrl_iface, peer_obj_path,
  3121. wpa_s->ifname, obj_desc))
  3122. goto err;
  3123. return 0;
  3124. err:
  3125. free_dbus_object_desc(obj_desc);
  3126. return -1;
  3127. }
  3128. /**
  3129. * wpas_dbus_unregister_peer - Unregister a peer object with dbus
  3130. * @wpa_s: wpa_supplicant interface structure
  3131. * @dev_addr: p2p device addr
  3132. * Returns: 0 on success, -1 on failure
  3133. *
  3134. * Registers network representing object with dbus
  3135. */
  3136. int wpas_dbus_unregister_peer(struct wpa_supplicant *wpa_s,
  3137. const u8 *dev_addr)
  3138. {
  3139. struct wpas_dbus_priv *ctrl_iface;
  3140. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3141. int ret;
  3142. /* Do nothing if the control interface is not turned on */
  3143. if (wpa_s == NULL || wpa_s->global == NULL)
  3144. return 0;
  3145. wpa_s = wpa_s->parent->parent;
  3146. if (!wpa_s->dbus_new_path)
  3147. return 0;
  3148. ctrl_iface = wpa_s->global->dbus;
  3149. if (ctrl_iface == NULL)
  3150. return 0;
  3151. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3152. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  3153. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  3154. wpa_printf(MSG_INFO, "dbus: Unregister peer object '%s'",
  3155. peer_obj_path);
  3156. ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, peer_obj_path);
  3157. return ret;
  3158. }
  3159. /**
  3160. * wpas_dbus_signal_p2p_find_stopped - Send P2P Find stopped signal
  3161. * @wpa_s: %wpa_supplicant network interface data
  3162. *
  3163. * Notify listeners about P2P Find stopped
  3164. */
  3165. void wpas_dbus_signal_p2p_find_stopped(struct wpa_supplicant *wpa_s)
  3166. {
  3167. struct wpas_dbus_priv *iface;
  3168. DBusMessage *msg;
  3169. iface = wpa_s->global->dbus;
  3170. /* Do nothing if the control interface is not turned on */
  3171. if (iface == NULL || !wpa_s->dbus_new_path)
  3172. return;
  3173. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  3174. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3175. "FindStopped");
  3176. if (msg == NULL)
  3177. return;
  3178. dbus_connection_send(iface->con, msg, NULL);
  3179. dbus_message_unref(msg);
  3180. }
  3181. void wpas_dbus_signal_peer_groups_changed(struct wpa_supplicant *wpa_s,
  3182. const u8 *dev_addr)
  3183. {
  3184. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3185. if (wpa_s->p2p_mgmt)
  3186. wpa_s = wpa_s->parent;
  3187. if (!wpa_s->dbus_new_path)
  3188. return;
  3189. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3190. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  3191. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  3192. wpa_dbus_mark_property_changed(wpa_s->global->dbus, peer_obj_path,
  3193. WPAS_DBUS_NEW_IFACE_P2P_PEER, "Groups");
  3194. }
  3195. static const struct wpa_dbus_property_desc wpas_dbus_p2p_group_properties[] = {
  3196. { "Members", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ao",
  3197. wpas_dbus_getter_p2p_group_members,
  3198. NULL
  3199. },
  3200. { "Group", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "o",
  3201. wpas_dbus_getter_p2p_group,
  3202. NULL
  3203. },
  3204. { "Role", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "s",
  3205. wpas_dbus_getter_p2p_role,
  3206. NULL
  3207. },
  3208. { "SSID", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
  3209. wpas_dbus_getter_p2p_group_ssid,
  3210. NULL
  3211. },
  3212. { "BSSID", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
  3213. wpas_dbus_getter_p2p_group_bssid,
  3214. NULL
  3215. },
  3216. { "Frequency", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "q",
  3217. wpas_dbus_getter_p2p_group_frequency,
  3218. NULL
  3219. },
  3220. { "Passphrase", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "s",
  3221. wpas_dbus_getter_p2p_group_passphrase,
  3222. NULL
  3223. },
  3224. { "PSK", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
  3225. wpas_dbus_getter_p2p_group_psk,
  3226. NULL
  3227. },
  3228. { "WPSVendorExtensions", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "aay",
  3229. wpas_dbus_getter_p2p_group_vendor_ext,
  3230. wpas_dbus_setter_p2p_group_vendor_ext
  3231. },
  3232. { NULL, NULL, NULL, NULL, NULL }
  3233. };
  3234. static const struct wpa_dbus_signal_desc wpas_dbus_p2p_group_signals[] = {
  3235. { "PeerJoined", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
  3236. {
  3237. { "peer", "o", ARG_OUT },
  3238. END_ARGS
  3239. }
  3240. },
  3241. { "PeerDisconnected", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
  3242. {
  3243. { "peer", "o", ARG_OUT },
  3244. END_ARGS
  3245. }
  3246. },
  3247. { NULL, NULL, { END_ARGS } }
  3248. };
  3249. /**
  3250. * wpas_dbus_register_p2p_group - Register a p2p group object with dbus
  3251. * @wpa_s: wpa_supplicant interface structure
  3252. * @ssid: SSID struct
  3253. * Returns: 0 on success, -1 on failure
  3254. *
  3255. * Registers p2p group representing object with dbus
  3256. */
  3257. void wpas_dbus_register_p2p_group(struct wpa_supplicant *wpa_s,
  3258. struct wpa_ssid *ssid)
  3259. {
  3260. struct wpas_dbus_priv *ctrl_iface;
  3261. struct wpa_dbus_object_desc *obj_desc;
  3262. char group_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3263. /* Do nothing if the control interface is not turned on */
  3264. if (wpa_s == NULL || wpa_s->global == NULL)
  3265. return;
  3266. ctrl_iface = wpa_s->global->dbus;
  3267. if (ctrl_iface == NULL)
  3268. return;
  3269. if (wpa_s->dbus_groupobj_path) {
  3270. wpa_printf(MSG_INFO, "%s: Group object '%s' already exists",
  3271. __func__, wpa_s->dbus_groupobj_path);
  3272. return;
  3273. }
  3274. if (wpas_dbus_get_group_obj_path(wpa_s, ssid, group_obj_path) < 0)
  3275. return;
  3276. wpa_s->dbus_groupobj_path = os_strdup(group_obj_path);
  3277. if (wpa_s->dbus_groupobj_path == NULL)
  3278. return;
  3279. wpa_printf(MSG_INFO, "dbus: Register group object '%s'",
  3280. group_obj_path);
  3281. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  3282. if (!obj_desc) {
  3283. wpa_printf(MSG_ERROR,
  3284. "Not enough memory to create object description");
  3285. goto err;
  3286. }
  3287. wpas_dbus_register(obj_desc, wpa_s, NULL, NULL,
  3288. wpas_dbus_p2p_group_properties,
  3289. wpas_dbus_p2p_group_signals);
  3290. if (wpa_dbus_register_object_per_iface(ctrl_iface, group_obj_path,
  3291. wpa_s->ifname, obj_desc))
  3292. goto err;
  3293. return;
  3294. err:
  3295. if (wpa_s->dbus_groupobj_path) {
  3296. os_free(wpa_s->dbus_groupobj_path);
  3297. wpa_s->dbus_groupobj_path = NULL;
  3298. }
  3299. free_dbus_object_desc(obj_desc);
  3300. }
  3301. /**
  3302. * wpas_dbus_unregister_p2p_group - Unregister a p2p group object from dbus
  3303. * @wpa_s: wpa_supplicant interface structure
  3304. * @ssid: network name of the p2p group started
  3305. */
  3306. void wpas_dbus_unregister_p2p_group(struct wpa_supplicant *wpa_s,
  3307. const struct wpa_ssid *ssid)
  3308. {
  3309. struct wpas_dbus_priv *ctrl_iface;
  3310. /* Do nothing if the control interface is not turned on */
  3311. if (wpa_s == NULL || wpa_s->global == NULL)
  3312. return;
  3313. if (wpa_s->p2p_mgmt)
  3314. wpa_s = wpa_s->parent;
  3315. ctrl_iface = wpa_s->global->dbus;
  3316. if (ctrl_iface == NULL)
  3317. return;
  3318. if (!wpa_s->dbus_groupobj_path) {
  3319. wpa_printf(MSG_DEBUG,
  3320. "%s: Group object '%s' already unregistered",
  3321. __func__, wpa_s->dbus_groupobj_path);
  3322. return;
  3323. }
  3324. peer_groups_changed(wpa_s);
  3325. wpa_printf(MSG_DEBUG, "dbus: Unregister group object '%s'",
  3326. wpa_s->dbus_groupobj_path);
  3327. wpa_dbus_unregister_object_per_iface(ctrl_iface,
  3328. wpa_s->dbus_groupobj_path);
  3329. os_free(wpa_s->dbus_groupobj_path);
  3330. wpa_s->dbus_groupobj_path = NULL;
  3331. }
  3332. static const struct wpa_dbus_property_desc
  3333. wpas_dbus_persistent_group_properties[] = {
  3334. { "Properties", WPAS_DBUS_NEW_IFACE_PERSISTENT_GROUP, "a{sv}",
  3335. wpas_dbus_getter_persistent_group_properties,
  3336. wpas_dbus_setter_persistent_group_properties
  3337. },
  3338. { NULL, NULL, NULL, NULL, NULL }
  3339. };
  3340. /* No signals intended for persistent group objects */
  3341. /**
  3342. * wpas_dbus_register_persistent_group - Register a configured(saved)
  3343. * persistent group with dbus
  3344. * @wpa_s: wpa_supplicant interface structure
  3345. * @ssid: persistent group (still represented as a network within wpa)
  3346. * configuration data
  3347. * Returns: 0 on success, -1 on failure
  3348. *
  3349. * Registers a persistent group representing object with dbus.
  3350. */
  3351. int wpas_dbus_register_persistent_group(struct wpa_supplicant *wpa_s,
  3352. struct wpa_ssid *ssid)
  3353. {
  3354. struct wpas_dbus_priv *ctrl_iface;
  3355. struct wpa_dbus_object_desc *obj_desc;
  3356. struct network_handler_args *arg;
  3357. char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3358. /* Do nothing if the control interface is not turned on */
  3359. if (wpa_s == NULL || wpa_s->global == NULL)
  3360. return 0;
  3361. wpa_s = wpa_s->parent->parent;
  3362. if (!wpa_s->dbus_new_path)
  3363. return 0;
  3364. /* Make sure ssid is a persistent group */
  3365. if (ssid->disabled != 2 && !ssid->p2p_persistent_group)
  3366. return -1; /* should we return w/o complaining? */
  3367. if (wpa_s->p2p_mgmt)
  3368. wpa_s = wpa_s->parent;
  3369. ctrl_iface = wpa_s->global->dbus;
  3370. if (ctrl_iface == NULL)
  3371. return 0;
  3372. /*
  3373. * Intentionally not coming up with different numbering scheme
  3374. * for persistent groups.
  3375. */
  3376. os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3377. "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
  3378. wpa_s->dbus_new_path, ssid->id);
  3379. wpa_printf(MSG_DEBUG, "dbus: Register persistent group object '%s'",
  3380. pgrp_obj_path);
  3381. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  3382. if (!obj_desc) {
  3383. wpa_printf(MSG_ERROR,
  3384. "dbus: Not enough memory to create object description");
  3385. goto err;
  3386. }
  3387. /*
  3388. * Reusing the same context structure as that for networks
  3389. * since these are represented using same data structure.
  3390. */
  3391. /* allocate memory for handlers arguments */
  3392. arg = os_zalloc(sizeof(struct network_handler_args));
  3393. if (!arg) {
  3394. wpa_printf(MSG_ERROR,
  3395. "dbus: Not enough memory to create arguments for method");
  3396. goto err;
  3397. }
  3398. arg->wpa_s = wpa_s;
  3399. arg->ssid = ssid;
  3400. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  3401. wpas_dbus_persistent_group_properties,
  3402. NULL);
  3403. if (wpa_dbus_register_object_per_iface(ctrl_iface, pgrp_obj_path,
  3404. wpa_s->ifname, obj_desc))
  3405. goto err;
  3406. wpas_dbus_signal_persistent_group_added(wpa_s, ssid->id);
  3407. return 0;
  3408. err:
  3409. free_dbus_object_desc(obj_desc);
  3410. return -1;
  3411. }
  3412. /**
  3413. * wpas_dbus_unregister_persistent_group - Unregister a persistent_group
  3414. * from dbus
  3415. * @wpa_s: wpa_supplicant interface structure
  3416. * @nid: network id
  3417. * Returns: 0 on success, -1 on failure
  3418. *
  3419. * Unregisters persistent group representing object from dbus
  3420. *
  3421. * NOTE: There is a slight issue with the semantics here. While the
  3422. * implementation simply means the persistent group is unloaded from memory,
  3423. * it should not get interpreted as the group is actually being erased/removed
  3424. * from persistent storage as well.
  3425. */
  3426. int wpas_dbus_unregister_persistent_group(struct wpa_supplicant *wpa_s,
  3427. int nid)
  3428. {
  3429. struct wpas_dbus_priv *ctrl_iface;
  3430. char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3431. int ret;
  3432. /* Do nothing if the control interface is not turned on */
  3433. if (wpa_s == NULL || wpa_s->global == NULL)
  3434. return 0;
  3435. wpa_s = wpa_s->parent->parent;
  3436. ctrl_iface = wpa_s->global->dbus;
  3437. if (ctrl_iface == NULL || !wpa_s->dbus_new_path)
  3438. return 0;
  3439. os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3440. "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
  3441. wpa_s->dbus_new_path, nid);
  3442. wpa_printf(MSG_DEBUG, "dbus: Unregister persistent group object '%s'",
  3443. pgrp_obj_path);
  3444. ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, pgrp_obj_path);
  3445. if (!ret)
  3446. wpas_dbus_signal_persistent_group_removed(wpa_s, nid);
  3447. return ret;
  3448. }
  3449. #endif /* CONFIG_P2P */