dbus_new.c 103 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964
  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. { "Reconnect", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2164. (WPADBusMethodHandler) wpas_dbus_handler_reconnect,
  2165. {
  2166. END_ARGS
  2167. }
  2168. },
  2169. { "RemoveNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2170. (WPADBusMethodHandler) wpas_dbus_handler_remove_network,
  2171. {
  2172. { "path", "o", ARG_IN },
  2173. END_ARGS
  2174. }
  2175. },
  2176. { "RemoveAllNetworks", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2177. (WPADBusMethodHandler) wpas_dbus_handler_remove_all_networks,
  2178. {
  2179. END_ARGS
  2180. }
  2181. },
  2182. { "SelectNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2183. (WPADBusMethodHandler) wpas_dbus_handler_select_network,
  2184. {
  2185. { "path", "o", ARG_IN },
  2186. END_ARGS
  2187. }
  2188. },
  2189. { "NetworkReply", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2190. (WPADBusMethodHandler) wpas_dbus_handler_network_reply,
  2191. {
  2192. { "path", "o", ARG_IN },
  2193. { "field", "s", ARG_IN },
  2194. { "value", "s", ARG_IN },
  2195. END_ARGS
  2196. }
  2197. },
  2198. #ifndef CONFIG_NO_CONFIG_BLOBS
  2199. { "AddBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2200. (WPADBusMethodHandler) wpas_dbus_handler_add_blob,
  2201. {
  2202. { "name", "s", ARG_IN },
  2203. { "data", "ay", ARG_IN },
  2204. END_ARGS
  2205. }
  2206. },
  2207. { "GetBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2208. (WPADBusMethodHandler) wpas_dbus_handler_get_blob,
  2209. {
  2210. { "name", "s", ARG_IN },
  2211. { "data", "ay", ARG_OUT },
  2212. END_ARGS
  2213. }
  2214. },
  2215. { "RemoveBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2216. (WPADBusMethodHandler) wpas_dbus_handler_remove_blob,
  2217. {
  2218. { "name", "s", ARG_IN },
  2219. END_ARGS
  2220. }
  2221. },
  2222. #endif /* CONFIG_NO_CONFIG_BLOBS */
  2223. { "SetPKCS11EngineAndModulePath", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2224. (WPADBusMethodHandler)
  2225. wpas_dbus_handler_set_pkcs11_engine_and_module_path,
  2226. {
  2227. { "pkcs11_engine_path", "s", ARG_IN },
  2228. { "pkcs11_module_path", "s", ARG_IN },
  2229. END_ARGS
  2230. }
  2231. },
  2232. #ifdef CONFIG_WPS
  2233. { "Start", WPAS_DBUS_NEW_IFACE_WPS,
  2234. (WPADBusMethodHandler) wpas_dbus_handler_wps_start,
  2235. {
  2236. { "args", "a{sv}", ARG_IN },
  2237. { "output", "a{sv}", ARG_OUT },
  2238. END_ARGS
  2239. }
  2240. },
  2241. { "Cancel", WPAS_DBUS_NEW_IFACE_WPS,
  2242. (WPADBusMethodHandler) wpas_dbus_handler_wps_cancel,
  2243. {
  2244. END_ARGS
  2245. }
  2246. },
  2247. #endif /* CONFIG_WPS */
  2248. #ifdef CONFIG_P2P
  2249. { "Find", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2250. (WPADBusMethodHandler) wpas_dbus_handler_p2p_find,
  2251. {
  2252. { "args", "a{sv}", ARG_IN },
  2253. END_ARGS
  2254. }
  2255. },
  2256. { "StopFind", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2257. (WPADBusMethodHandler) wpas_dbus_handler_p2p_stop_find,
  2258. {
  2259. END_ARGS
  2260. }
  2261. },
  2262. { "Listen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2263. (WPADBusMethodHandler) wpas_dbus_handler_p2p_listen,
  2264. {
  2265. { "timeout", "i", ARG_IN },
  2266. END_ARGS
  2267. }
  2268. },
  2269. { "ExtendedListen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2270. (WPADBusMethodHandler) wpas_dbus_handler_p2p_extendedlisten,
  2271. {
  2272. { "args", "a{sv}", ARG_IN },
  2273. END_ARGS
  2274. }
  2275. },
  2276. { "PresenceRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2277. (WPADBusMethodHandler) wpas_dbus_handler_p2p_presence_request,
  2278. {
  2279. { "args", "a{sv}", ARG_IN },
  2280. END_ARGS
  2281. }
  2282. },
  2283. { "ProvisionDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2284. (WPADBusMethodHandler) wpas_dbus_handler_p2p_prov_disc_req,
  2285. {
  2286. { "peer", "o", ARG_IN },
  2287. { "config_method", "s", ARG_IN },
  2288. END_ARGS
  2289. }
  2290. },
  2291. { "Connect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2292. (WPADBusMethodHandler) wpas_dbus_handler_p2p_connect,
  2293. {
  2294. { "args", "a{sv}", ARG_IN },
  2295. { "generated_pin", "s", ARG_OUT },
  2296. END_ARGS
  2297. }
  2298. },
  2299. { "GroupAdd", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2300. (WPADBusMethodHandler) wpas_dbus_handler_p2p_group_add,
  2301. {
  2302. { "args", "a{sv}", ARG_IN },
  2303. END_ARGS
  2304. }
  2305. },
  2306. { "Cancel", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2307. (WPADBusMethodHandler) wpas_dbus_handler_p2p_cancel,
  2308. {
  2309. END_ARGS
  2310. }
  2311. },
  2312. { "Invite", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2313. (WPADBusMethodHandler) wpas_dbus_handler_p2p_invite,
  2314. {
  2315. { "args", "a{sv}", ARG_IN },
  2316. END_ARGS
  2317. }
  2318. },
  2319. { "Disconnect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2320. (WPADBusMethodHandler) wpas_dbus_handler_p2p_disconnect,
  2321. {
  2322. END_ARGS
  2323. }
  2324. },
  2325. { "RejectPeer", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2326. (WPADBusMethodHandler) wpas_dbus_handler_p2p_rejectpeer,
  2327. {
  2328. { "peer", "o", ARG_IN },
  2329. END_ARGS
  2330. }
  2331. },
  2332. { "Flush", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2333. (WPADBusMethodHandler) wpas_dbus_handler_p2p_flush,
  2334. {
  2335. END_ARGS
  2336. }
  2337. },
  2338. { "AddService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2339. (WPADBusMethodHandler) wpas_dbus_handler_p2p_add_service,
  2340. {
  2341. { "args", "a{sv}", ARG_IN },
  2342. END_ARGS
  2343. }
  2344. },
  2345. { "DeleteService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2346. (WPADBusMethodHandler) wpas_dbus_handler_p2p_delete_service,
  2347. {
  2348. { "args", "a{sv}", ARG_IN },
  2349. END_ARGS
  2350. }
  2351. },
  2352. { "FlushService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2353. (WPADBusMethodHandler) wpas_dbus_handler_p2p_flush_service,
  2354. {
  2355. END_ARGS
  2356. }
  2357. },
  2358. { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2359. (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_sd_req,
  2360. {
  2361. { "args", "a{sv}", ARG_IN },
  2362. { "ref", "t", ARG_OUT },
  2363. END_ARGS
  2364. }
  2365. },
  2366. { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2367. (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_sd_res,
  2368. {
  2369. { "args", "a{sv}", ARG_IN },
  2370. END_ARGS
  2371. }
  2372. },
  2373. { "ServiceDiscoveryCancelRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2374. (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_sd_cancel_req,
  2375. {
  2376. { "args", "t", ARG_IN },
  2377. END_ARGS
  2378. }
  2379. },
  2380. { "ServiceUpdate", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2381. (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_update,
  2382. {
  2383. END_ARGS
  2384. }
  2385. },
  2386. { "ServiceDiscoveryExternal", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2387. (WPADBusMethodHandler) wpas_dbus_handler_p2p_serv_disc_external,
  2388. {
  2389. { "arg", "i", ARG_IN },
  2390. END_ARGS
  2391. }
  2392. },
  2393. { "AddPersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2394. (WPADBusMethodHandler) wpas_dbus_handler_add_persistent_group,
  2395. {
  2396. { "args", "a{sv}", ARG_IN },
  2397. { "path", "o", ARG_OUT },
  2398. END_ARGS
  2399. }
  2400. },
  2401. { "RemovePersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2402. (WPADBusMethodHandler) wpas_dbus_handler_remove_persistent_group,
  2403. {
  2404. { "path", "o", ARG_IN },
  2405. END_ARGS
  2406. }
  2407. },
  2408. { "RemoveAllPersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2409. (WPADBusMethodHandler)
  2410. wpas_dbus_handler_remove_all_persistent_groups,
  2411. {
  2412. END_ARGS
  2413. }
  2414. },
  2415. #endif /* CONFIG_P2P */
  2416. { "FlushBSS", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2417. (WPADBusMethodHandler) wpas_dbus_handler_flush_bss,
  2418. {
  2419. { "age", "u", ARG_IN },
  2420. END_ARGS
  2421. }
  2422. },
  2423. #ifdef CONFIG_AP
  2424. { "SubscribeProbeReq", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2425. (WPADBusMethodHandler) wpas_dbus_handler_subscribe_preq,
  2426. {
  2427. END_ARGS
  2428. }
  2429. },
  2430. { "UnsubscribeProbeReq", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2431. (WPADBusMethodHandler) wpas_dbus_handler_unsubscribe_preq,
  2432. {
  2433. END_ARGS
  2434. }
  2435. },
  2436. #endif /* CONFIG_AP */
  2437. { "EAPLogoff", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2438. (WPADBusMethodHandler) wpas_dbus_handler_eap_logoff,
  2439. {
  2440. END_ARGS
  2441. }
  2442. },
  2443. { "EAPLogon", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2444. (WPADBusMethodHandler) wpas_dbus_handler_eap_logon,
  2445. {
  2446. END_ARGS
  2447. }
  2448. },
  2449. #ifdef CONFIG_AUTOSCAN
  2450. { "AutoScan", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2451. (WPADBusMethodHandler) wpas_dbus_handler_autoscan,
  2452. {
  2453. { "arg", "s", ARG_IN },
  2454. END_ARGS
  2455. }
  2456. },
  2457. #endif /* CONFIG_AUTOSCAN */
  2458. #ifdef CONFIG_TDLS
  2459. { "TDLSDiscover", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2460. (WPADBusMethodHandler) wpas_dbus_handler_tdls_discover,
  2461. {
  2462. { "peer_address", "s", ARG_IN },
  2463. END_ARGS
  2464. }
  2465. },
  2466. { "TDLSSetup", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2467. (WPADBusMethodHandler) wpas_dbus_handler_tdls_setup,
  2468. {
  2469. { "peer_address", "s", ARG_IN },
  2470. END_ARGS
  2471. }
  2472. },
  2473. { "TDLSStatus", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2474. (WPADBusMethodHandler) wpas_dbus_handler_tdls_status,
  2475. {
  2476. { "peer_address", "s", ARG_IN },
  2477. { "status", "s", ARG_OUT },
  2478. END_ARGS
  2479. }
  2480. },
  2481. { "TDLSTeardown", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2482. (WPADBusMethodHandler) wpas_dbus_handler_tdls_teardown,
  2483. {
  2484. { "peer_address", "s", ARG_IN },
  2485. END_ARGS
  2486. }
  2487. },
  2488. #endif /* CONFIG_TDLS */
  2489. { NULL, NULL, NULL, { END_ARGS } }
  2490. };
  2491. static const struct wpa_dbus_property_desc wpas_dbus_interface_properties[] = {
  2492. { "Capabilities", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{sv}",
  2493. wpas_dbus_getter_capabilities,
  2494. NULL
  2495. },
  2496. { "State", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2497. wpas_dbus_getter_state,
  2498. NULL
  2499. },
  2500. { "Scanning", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
  2501. wpas_dbus_getter_scanning,
  2502. NULL
  2503. },
  2504. { "ApScan", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  2505. wpas_dbus_getter_ap_scan,
  2506. wpas_dbus_setter_ap_scan
  2507. },
  2508. { "BSSExpireAge", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  2509. wpas_dbus_getter_bss_expire_age,
  2510. wpas_dbus_setter_bss_expire_age
  2511. },
  2512. { "BSSExpireCount", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  2513. wpas_dbus_getter_bss_expire_count,
  2514. wpas_dbus_setter_bss_expire_count
  2515. },
  2516. { "Country", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2517. wpas_dbus_getter_country,
  2518. wpas_dbus_setter_country
  2519. },
  2520. { "Ifname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2521. wpas_dbus_getter_ifname,
  2522. NULL
  2523. },
  2524. { "Driver", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2525. wpas_dbus_getter_driver,
  2526. NULL
  2527. },
  2528. { "BridgeIfname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2529. wpas_dbus_getter_bridge_ifname,
  2530. NULL
  2531. },
  2532. { "CurrentBSS", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
  2533. wpas_dbus_getter_current_bss,
  2534. NULL
  2535. },
  2536. { "CurrentNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
  2537. wpas_dbus_getter_current_network,
  2538. NULL
  2539. },
  2540. { "CurrentAuthMode", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2541. wpas_dbus_getter_current_auth_mode,
  2542. NULL
  2543. },
  2544. { "Blobs", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{say}",
  2545. wpas_dbus_getter_blobs,
  2546. NULL
  2547. },
  2548. { "BSSs", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
  2549. wpas_dbus_getter_bsss,
  2550. NULL
  2551. },
  2552. { "Networks", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
  2553. wpas_dbus_getter_networks,
  2554. NULL
  2555. },
  2556. { "FastReauth", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
  2557. wpas_dbus_getter_fast_reauth,
  2558. wpas_dbus_setter_fast_reauth
  2559. },
  2560. { "ScanInterval", WPAS_DBUS_NEW_IFACE_INTERFACE, "i",
  2561. wpas_dbus_getter_scan_interval,
  2562. wpas_dbus_setter_scan_interval
  2563. },
  2564. { "PKCS11EnginePath", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2565. wpas_dbus_getter_pkcs11_engine_path,
  2566. NULL
  2567. },
  2568. { "PKCS11ModulePath", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2569. wpas_dbus_getter_pkcs11_module_path,
  2570. NULL
  2571. },
  2572. #ifdef CONFIG_WPS
  2573. { "ProcessCredentials", WPAS_DBUS_NEW_IFACE_WPS, "b",
  2574. wpas_dbus_getter_process_credentials,
  2575. wpas_dbus_setter_process_credentials
  2576. },
  2577. { "ConfigMethods", WPAS_DBUS_NEW_IFACE_WPS, "s",
  2578. wpas_dbus_getter_config_methods,
  2579. wpas_dbus_setter_config_methods
  2580. },
  2581. #endif /* CONFIG_WPS */
  2582. #ifdef CONFIG_P2P
  2583. { "P2PDeviceConfig", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "a{sv}",
  2584. wpas_dbus_getter_p2p_device_config,
  2585. wpas_dbus_setter_p2p_device_config
  2586. },
  2587. { "Peers", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
  2588. wpas_dbus_getter_p2p_peers,
  2589. NULL
  2590. },
  2591. { "Role", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "s",
  2592. wpas_dbus_getter_p2p_role,
  2593. NULL
  2594. },
  2595. { "Group", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
  2596. wpas_dbus_getter_p2p_group,
  2597. NULL
  2598. },
  2599. { "PeerGO", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
  2600. wpas_dbus_getter_p2p_peergo,
  2601. NULL
  2602. },
  2603. { "PersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
  2604. wpas_dbus_getter_persistent_groups,
  2605. NULL
  2606. },
  2607. #endif /* CONFIG_P2P */
  2608. { "DisconnectReason", WPAS_DBUS_NEW_IFACE_INTERFACE, "i",
  2609. wpas_dbus_getter_disconnect_reason,
  2610. NULL
  2611. },
  2612. { NULL, NULL, NULL, NULL, NULL }
  2613. };
  2614. static const struct wpa_dbus_signal_desc wpas_dbus_interface_signals[] = {
  2615. { "ScanDone", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2616. {
  2617. { "success", "b", ARG_OUT },
  2618. END_ARGS
  2619. }
  2620. },
  2621. { "BSSAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2622. {
  2623. { "path", "o", ARG_OUT },
  2624. { "properties", "a{sv}", ARG_OUT },
  2625. END_ARGS
  2626. }
  2627. },
  2628. { "BSSRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2629. {
  2630. { "path", "o", ARG_OUT },
  2631. END_ARGS
  2632. }
  2633. },
  2634. { "BlobAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2635. {
  2636. { "name", "s", ARG_OUT },
  2637. END_ARGS
  2638. }
  2639. },
  2640. { "BlobRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2641. {
  2642. { "name", "s", ARG_OUT },
  2643. END_ARGS
  2644. }
  2645. },
  2646. { "NetworkAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2647. {
  2648. { "path", "o", ARG_OUT },
  2649. { "properties", "a{sv}", ARG_OUT },
  2650. END_ARGS
  2651. }
  2652. },
  2653. { "NetworkRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2654. {
  2655. { "path", "o", ARG_OUT },
  2656. END_ARGS
  2657. }
  2658. },
  2659. { "NetworkSelected", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2660. {
  2661. { "path", "o", ARG_OUT },
  2662. END_ARGS
  2663. }
  2664. },
  2665. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  2666. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2667. {
  2668. { "properties", "a{sv}", ARG_OUT },
  2669. END_ARGS
  2670. }
  2671. },
  2672. #ifdef CONFIG_WPS
  2673. { "Event", WPAS_DBUS_NEW_IFACE_WPS,
  2674. {
  2675. { "name", "s", ARG_OUT },
  2676. { "args", "a{sv}", ARG_OUT },
  2677. END_ARGS
  2678. }
  2679. },
  2680. { "Credentials", WPAS_DBUS_NEW_IFACE_WPS,
  2681. {
  2682. { "credentials", "a{sv}", ARG_OUT },
  2683. END_ARGS
  2684. }
  2685. },
  2686. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  2687. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_WPS,
  2688. {
  2689. { "properties", "a{sv}", ARG_OUT },
  2690. END_ARGS
  2691. }
  2692. },
  2693. #endif /* CONFIG_WPS */
  2694. #ifdef CONFIG_P2P
  2695. { "DeviceFound", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2696. {
  2697. { "path", "o", ARG_OUT },
  2698. END_ARGS
  2699. }
  2700. },
  2701. { "DeviceLost", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2702. {
  2703. { "path", "o", ARG_OUT },
  2704. END_ARGS
  2705. }
  2706. },
  2707. { "FindStopped", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2708. {
  2709. END_ARGS
  2710. }
  2711. },
  2712. { "ProvisionDiscoveryRequestDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2713. {
  2714. { "peer_object", "o", ARG_OUT },
  2715. { "pin", "s", ARG_OUT },
  2716. END_ARGS
  2717. }
  2718. },
  2719. { "ProvisionDiscoveryResponseDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2720. {
  2721. { "peer_object", "o", ARG_OUT },
  2722. { "pin", "s", ARG_OUT },
  2723. END_ARGS
  2724. }
  2725. },
  2726. { "ProvisionDiscoveryRequestEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2727. {
  2728. { "peer_object", "o", ARG_OUT },
  2729. END_ARGS
  2730. }
  2731. },
  2732. { "ProvisionDiscoveryResponseEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2733. {
  2734. { "peer_object", "o", ARG_OUT },
  2735. END_ARGS
  2736. }
  2737. },
  2738. { "ProvisionDiscoveryPBCRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2739. {
  2740. { "peer_object", "o", ARG_OUT },
  2741. END_ARGS
  2742. }
  2743. },
  2744. { "ProvisionDiscoveryPBCResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2745. {
  2746. { "peer_object", "o", ARG_OUT },
  2747. END_ARGS
  2748. }
  2749. },
  2750. { "ProvisionDiscoveryFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2751. {
  2752. { "peer_object", "o", ARG_OUT },
  2753. { "status", "i", ARG_OUT },
  2754. END_ARGS
  2755. }
  2756. },
  2757. { "GroupStarted", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2758. {
  2759. { "properties", "a{sv}", ARG_OUT },
  2760. END_ARGS
  2761. }
  2762. },
  2763. { "GONegotiationSuccess", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2764. {
  2765. { "properties", "a{sv}", ARG_OUT },
  2766. END_ARGS
  2767. }
  2768. },
  2769. { "GONegotiationFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2770. {
  2771. { "properties", "a{sv}", ARG_OUT },
  2772. END_ARGS
  2773. }
  2774. },
  2775. { "GONegotiationRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2776. {
  2777. { "path", "o", ARG_OUT },
  2778. { "dev_passwd_id", "i", ARG_OUT },
  2779. { "device_go_intent", "y", ARG_OUT },
  2780. END_ARGS
  2781. }
  2782. },
  2783. { "InvitationResult", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2784. {
  2785. { "invite_result", "a{sv}", ARG_OUT },
  2786. END_ARGS
  2787. }
  2788. },
  2789. { "GroupFinished", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2790. {
  2791. { "properties", "a{sv}", ARG_OUT },
  2792. END_ARGS
  2793. }
  2794. },
  2795. { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2796. {
  2797. { "sd_request", "a{sv}", ARG_OUT },
  2798. END_ARGS
  2799. }
  2800. },
  2801. { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2802. {
  2803. { "sd_response", "a{sv}", ARG_OUT },
  2804. END_ARGS
  2805. }
  2806. },
  2807. { "PersistentGroupAdded", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2808. {
  2809. { "path", "o", ARG_OUT },
  2810. { "properties", "a{sv}", ARG_OUT },
  2811. END_ARGS
  2812. }
  2813. },
  2814. { "PersistentGroupRemoved", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2815. {
  2816. { "path", "o", ARG_OUT },
  2817. END_ARGS
  2818. }
  2819. },
  2820. { "WpsFailed", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2821. {
  2822. { "name", "s", ARG_OUT },
  2823. { "args", "a{sv}", ARG_OUT },
  2824. END_ARGS
  2825. }
  2826. },
  2827. #endif /* CONFIG_P2P */
  2828. #ifdef CONFIG_AP
  2829. { "ProbeRequest", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2830. {
  2831. { "args", "a{sv}", ARG_OUT },
  2832. END_ARGS
  2833. }
  2834. },
  2835. #endif /* CONFIG_AP */
  2836. { "Certification", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2837. {
  2838. { "certification", "a{sv}", ARG_OUT },
  2839. END_ARGS
  2840. }
  2841. },
  2842. { "EAP", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2843. {
  2844. { "status", "s", ARG_OUT },
  2845. { "parameter", "s", ARG_OUT },
  2846. END_ARGS
  2847. }
  2848. },
  2849. { "StaAuthorized", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2850. {
  2851. { "name", "s", ARG_OUT },
  2852. END_ARGS
  2853. }
  2854. },
  2855. { "StaDeauthorized", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2856. {
  2857. { "name", "s", ARG_OUT },
  2858. END_ARGS
  2859. }
  2860. },
  2861. { "NetworkRequest", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2862. {
  2863. { "path", "o", ARG_OUT },
  2864. { "field", "s", ARG_OUT },
  2865. { "text", "s", ARG_OUT },
  2866. END_ARGS
  2867. }
  2868. },
  2869. { NULL, NULL, { END_ARGS } }
  2870. };
  2871. int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s)
  2872. {
  2873. struct wpa_dbus_object_desc *obj_desc = NULL;
  2874. struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus;
  2875. int next;
  2876. /* Do nothing if the control interface is not turned on */
  2877. if (ctrl_iface == NULL)
  2878. return 0;
  2879. /* Create and set the interface's object path */
  2880. wpa_s->dbus_new_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
  2881. if (wpa_s->dbus_new_path == NULL)
  2882. return -1;
  2883. next = ctrl_iface->next_objid++;
  2884. os_snprintf(wpa_s->dbus_new_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2885. WPAS_DBUS_NEW_PATH_INTERFACES "/%u",
  2886. next);
  2887. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  2888. if (!obj_desc) {
  2889. wpa_printf(MSG_ERROR,
  2890. "Not enough memory to create object description");
  2891. goto err;
  2892. }
  2893. wpas_dbus_register(obj_desc, wpa_s, NULL, wpas_dbus_interface_methods,
  2894. wpas_dbus_interface_properties,
  2895. wpas_dbus_interface_signals);
  2896. wpa_printf(MSG_DEBUG, "dbus: Register interface object '%s'",
  2897. wpa_s->dbus_new_path);
  2898. if (wpa_dbus_register_object_per_iface(ctrl_iface,
  2899. wpa_s->dbus_new_path,
  2900. wpa_s->ifname, obj_desc))
  2901. goto err;
  2902. wpas_dbus_signal_interface_added(wpa_s);
  2903. return 0;
  2904. err:
  2905. os_free(wpa_s->dbus_new_path);
  2906. wpa_s->dbus_new_path = NULL;
  2907. free_dbus_object_desc(obj_desc);
  2908. return -1;
  2909. }
  2910. int wpas_dbus_unregister_interface(struct wpa_supplicant *wpa_s)
  2911. {
  2912. struct wpas_dbus_priv *ctrl_iface;
  2913. /* Do nothing if the control interface is not turned on */
  2914. if (wpa_s == NULL || wpa_s->global == NULL)
  2915. return 0;
  2916. ctrl_iface = wpa_s->global->dbus;
  2917. if (ctrl_iface == NULL || wpa_s->dbus_new_path == NULL)
  2918. return 0;
  2919. wpa_printf(MSG_DEBUG, "dbus: Unregister interface object '%s'",
  2920. wpa_s->dbus_new_path);
  2921. #ifdef CONFIG_AP
  2922. if (wpa_s->preq_notify_peer) {
  2923. wpas_dbus_unsubscribe_noc(ctrl_iface);
  2924. os_free(wpa_s->preq_notify_peer);
  2925. wpa_s->preq_notify_peer = NULL;
  2926. }
  2927. #endif /* CONFIG_AP */
  2928. if (wpa_dbus_unregister_object_per_iface(ctrl_iface,
  2929. wpa_s->dbus_new_path))
  2930. return -1;
  2931. wpas_dbus_signal_interface_removed(wpa_s);
  2932. os_free(wpa_s->dbus_new_path);
  2933. wpa_s->dbus_new_path = NULL;
  2934. return 0;
  2935. }
  2936. #ifdef CONFIG_P2P
  2937. static const struct wpa_dbus_property_desc wpas_dbus_p2p_peer_properties[] = {
  2938. { "DeviceName", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
  2939. wpas_dbus_getter_p2p_peer_device_name,
  2940. NULL
  2941. },
  2942. { "Manufacturer", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
  2943. wpas_dbus_getter_p2p_peer_manufacturer,
  2944. NULL
  2945. },
  2946. { "ModelName", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
  2947. wpas_dbus_getter_p2p_peer_modelname,
  2948. NULL
  2949. },
  2950. { "ModelNumber", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
  2951. wpas_dbus_getter_p2p_peer_modelnumber,
  2952. NULL
  2953. },
  2954. { "SerialNumber", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
  2955. wpas_dbus_getter_p2p_peer_serialnumber,
  2956. NULL
  2957. },
  2958. { "PrimaryDeviceType", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
  2959. wpas_dbus_getter_p2p_peer_primary_device_type,
  2960. NULL
  2961. },
  2962. { "config_method", WPAS_DBUS_NEW_IFACE_P2P_PEER, "q",
  2963. wpas_dbus_getter_p2p_peer_config_method,
  2964. NULL
  2965. },
  2966. { "level", WPAS_DBUS_NEW_IFACE_P2P_PEER, "i",
  2967. wpas_dbus_getter_p2p_peer_level,
  2968. NULL
  2969. },
  2970. { "devicecapability", WPAS_DBUS_NEW_IFACE_P2P_PEER, "y",
  2971. wpas_dbus_getter_p2p_peer_device_capability,
  2972. NULL
  2973. },
  2974. { "groupcapability", WPAS_DBUS_NEW_IFACE_P2P_PEER, "y",
  2975. wpas_dbus_getter_p2p_peer_group_capability,
  2976. NULL
  2977. },
  2978. { "SecondaryDeviceTypes", WPAS_DBUS_NEW_IFACE_P2P_PEER, "aay",
  2979. wpas_dbus_getter_p2p_peer_secondary_device_types,
  2980. NULL
  2981. },
  2982. { "VendorExtension", WPAS_DBUS_NEW_IFACE_P2P_PEER, "aay",
  2983. wpas_dbus_getter_p2p_peer_vendor_extension,
  2984. NULL
  2985. },
  2986. { "IEs", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
  2987. wpas_dbus_getter_p2p_peer_ies,
  2988. NULL
  2989. },
  2990. { "DeviceAddress", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
  2991. wpas_dbus_getter_p2p_peer_device_address,
  2992. NULL
  2993. },
  2994. { "Groups", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ao",
  2995. wpas_dbus_getter_p2p_peer_groups,
  2996. NULL
  2997. },
  2998. { NULL, NULL, NULL, NULL, NULL }
  2999. };
  3000. static const struct wpa_dbus_signal_desc wpas_dbus_p2p_peer_signals[] = {
  3001. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  3002. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_P2P_PEER,
  3003. {
  3004. { "properties", "a{sv}", ARG_OUT },
  3005. END_ARGS
  3006. }
  3007. },
  3008. { NULL, NULL, { END_ARGS } }
  3009. };
  3010. /**
  3011. * wpas_dbus_signal_peer - Send a peer related event signal
  3012. * @wpa_s: %wpa_supplicant network interface data
  3013. * @dev: peer device object
  3014. * @interface: name of the interface emitting this signal.
  3015. * In case of peer objects, it would be emitted by either
  3016. * the "interface object" or by "peer objects"
  3017. * @sig_name: signal name - DeviceFound
  3018. *
  3019. * Notify listeners about event related with newly found p2p peer device
  3020. */
  3021. static void wpas_dbus_signal_peer(struct wpa_supplicant *wpa_s,
  3022. const u8 *dev_addr, const char *interface,
  3023. const char *sig_name)
  3024. {
  3025. struct wpas_dbus_priv *iface;
  3026. DBusMessage *msg;
  3027. DBusMessageIter iter;
  3028. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  3029. if (wpa_s->p2p_mgmt)
  3030. wpa_s = wpa_s->parent;
  3031. iface = wpa_s->global->dbus;
  3032. /* Do nothing if the control interface is not turned on */
  3033. if (iface == NULL || !wpa_s->dbus_new_path)
  3034. return;
  3035. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3036. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  3037. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  3038. msg = dbus_message_new_signal(wpa_s->dbus_new_path, interface,
  3039. sig_name);
  3040. if (msg == NULL)
  3041. return;
  3042. dbus_message_iter_init_append(msg, &iter);
  3043. path = peer_obj_path;
  3044. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  3045. &path))
  3046. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  3047. else
  3048. dbus_connection_send(iface->con, msg, NULL);
  3049. dbus_message_unref(msg);
  3050. }
  3051. /**
  3052. * wpas_dbus_signal_peer_found - Send a peer found signal
  3053. * @wpa_s: %wpa_supplicant network interface data
  3054. * @dev: peer device object
  3055. *
  3056. * Notify listeners about find a p2p peer device found
  3057. */
  3058. void wpas_dbus_signal_peer_device_found(struct wpa_supplicant *wpa_s,
  3059. const u8 *dev_addr)
  3060. {
  3061. wpas_dbus_signal_peer(wpa_s, dev_addr,
  3062. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3063. "DeviceFound");
  3064. }
  3065. /**
  3066. * wpas_dbus_signal_peer_lost - Send a peer lost signal
  3067. * @wpa_s: %wpa_supplicant network interface data
  3068. * @dev: peer device object
  3069. *
  3070. * Notify listeners about lost a p2p peer device
  3071. */
  3072. void wpas_dbus_signal_peer_device_lost(struct wpa_supplicant *wpa_s,
  3073. const u8 *dev_addr)
  3074. {
  3075. wpas_dbus_signal_peer(wpa_s, dev_addr,
  3076. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3077. "DeviceLost");
  3078. }
  3079. /**
  3080. * wpas_dbus_register_peer - Register a discovered peer object with dbus
  3081. * @wpa_s: wpa_supplicant interface structure
  3082. * @ssid: network configuration data
  3083. * Returns: 0 on success, -1 on failure
  3084. *
  3085. * Registers network representing object with dbus
  3086. */
  3087. int wpas_dbus_register_peer(struct wpa_supplicant *wpa_s, const u8 *dev_addr)
  3088. {
  3089. struct wpas_dbus_priv *ctrl_iface;
  3090. struct wpa_dbus_object_desc *obj_desc;
  3091. struct peer_handler_args *arg;
  3092. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3093. /* Do nothing if the control interface is not turned on */
  3094. if (wpa_s == NULL || wpa_s->global == NULL)
  3095. return 0;
  3096. ctrl_iface = wpa_s->global->dbus;
  3097. if (ctrl_iface == NULL)
  3098. return 0;
  3099. wpa_s = wpa_s->parent->parent;
  3100. if (!wpa_s->dbus_new_path)
  3101. return 0;
  3102. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3103. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  3104. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  3105. wpa_printf(MSG_INFO, "dbus: Register peer object '%s'",
  3106. peer_obj_path);
  3107. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  3108. if (!obj_desc) {
  3109. wpa_printf(MSG_ERROR,
  3110. "Not enough memory to create object description");
  3111. goto err;
  3112. }
  3113. /* allocate memory for handlers arguments */
  3114. arg = os_zalloc(sizeof(struct peer_handler_args));
  3115. if (!arg) {
  3116. wpa_printf(MSG_ERROR,
  3117. "Not enough memory to create arguments for method");
  3118. goto err;
  3119. }
  3120. arg->wpa_s = wpa_s;
  3121. os_memcpy(arg->p2p_device_addr, dev_addr, ETH_ALEN);
  3122. wpas_dbus_register(obj_desc, arg, wpa_dbus_free,
  3123. NULL,
  3124. wpas_dbus_p2p_peer_properties,
  3125. wpas_dbus_p2p_peer_signals);
  3126. if (wpa_dbus_register_object_per_iface(ctrl_iface, peer_obj_path,
  3127. wpa_s->ifname, obj_desc))
  3128. goto err;
  3129. return 0;
  3130. err:
  3131. free_dbus_object_desc(obj_desc);
  3132. return -1;
  3133. }
  3134. /**
  3135. * wpas_dbus_unregister_peer - Unregister a peer object with dbus
  3136. * @wpa_s: wpa_supplicant interface structure
  3137. * @dev_addr: p2p device addr
  3138. * Returns: 0 on success, -1 on failure
  3139. *
  3140. * Registers network representing object with dbus
  3141. */
  3142. int wpas_dbus_unregister_peer(struct wpa_supplicant *wpa_s,
  3143. const u8 *dev_addr)
  3144. {
  3145. struct wpas_dbus_priv *ctrl_iface;
  3146. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3147. int ret;
  3148. /* Do nothing if the control interface is not turned on */
  3149. if (wpa_s == NULL || wpa_s->global == NULL)
  3150. return 0;
  3151. wpa_s = wpa_s->parent->parent;
  3152. if (!wpa_s->dbus_new_path)
  3153. return 0;
  3154. ctrl_iface = wpa_s->global->dbus;
  3155. if (ctrl_iface == NULL)
  3156. return 0;
  3157. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3158. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  3159. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  3160. wpa_printf(MSG_INFO, "dbus: Unregister peer object '%s'",
  3161. peer_obj_path);
  3162. ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, peer_obj_path);
  3163. return ret;
  3164. }
  3165. /**
  3166. * wpas_dbus_signal_p2p_find_stopped - Send P2P Find stopped signal
  3167. * @wpa_s: %wpa_supplicant network interface data
  3168. *
  3169. * Notify listeners about P2P Find stopped
  3170. */
  3171. void wpas_dbus_signal_p2p_find_stopped(struct wpa_supplicant *wpa_s)
  3172. {
  3173. struct wpas_dbus_priv *iface;
  3174. DBusMessage *msg;
  3175. iface = wpa_s->global->dbus;
  3176. /* Do nothing if the control interface is not turned on */
  3177. if (iface == NULL || !wpa_s->dbus_new_path)
  3178. return;
  3179. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  3180. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3181. "FindStopped");
  3182. if (msg == NULL)
  3183. return;
  3184. dbus_connection_send(iface->con, msg, NULL);
  3185. dbus_message_unref(msg);
  3186. }
  3187. void wpas_dbus_signal_peer_groups_changed(struct wpa_supplicant *wpa_s,
  3188. const u8 *dev_addr)
  3189. {
  3190. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3191. if (wpa_s->p2p_mgmt)
  3192. wpa_s = wpa_s->parent;
  3193. if (!wpa_s->dbus_new_path)
  3194. return;
  3195. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3196. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  3197. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  3198. wpa_dbus_mark_property_changed(wpa_s->global->dbus, peer_obj_path,
  3199. WPAS_DBUS_NEW_IFACE_P2P_PEER, "Groups");
  3200. }
  3201. static const struct wpa_dbus_property_desc wpas_dbus_p2p_group_properties[] = {
  3202. { "Members", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ao",
  3203. wpas_dbus_getter_p2p_group_members,
  3204. NULL
  3205. },
  3206. { "Group", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "o",
  3207. wpas_dbus_getter_p2p_group,
  3208. NULL
  3209. },
  3210. { "Role", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "s",
  3211. wpas_dbus_getter_p2p_role,
  3212. NULL
  3213. },
  3214. { "SSID", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
  3215. wpas_dbus_getter_p2p_group_ssid,
  3216. NULL
  3217. },
  3218. { "BSSID", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
  3219. wpas_dbus_getter_p2p_group_bssid,
  3220. NULL
  3221. },
  3222. { "Frequency", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "q",
  3223. wpas_dbus_getter_p2p_group_frequency,
  3224. NULL
  3225. },
  3226. { "Passphrase", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "s",
  3227. wpas_dbus_getter_p2p_group_passphrase,
  3228. NULL
  3229. },
  3230. { "PSK", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
  3231. wpas_dbus_getter_p2p_group_psk,
  3232. NULL
  3233. },
  3234. { "WPSVendorExtensions", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "aay",
  3235. wpas_dbus_getter_p2p_group_vendor_ext,
  3236. wpas_dbus_setter_p2p_group_vendor_ext
  3237. },
  3238. { NULL, NULL, NULL, NULL, NULL }
  3239. };
  3240. static const struct wpa_dbus_signal_desc wpas_dbus_p2p_group_signals[] = {
  3241. { "PeerJoined", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
  3242. {
  3243. { "peer", "o", ARG_OUT },
  3244. END_ARGS
  3245. }
  3246. },
  3247. { "PeerDisconnected", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
  3248. {
  3249. { "peer", "o", ARG_OUT },
  3250. END_ARGS
  3251. }
  3252. },
  3253. { NULL, NULL, { END_ARGS } }
  3254. };
  3255. /**
  3256. * wpas_dbus_register_p2p_group - Register a p2p group object with dbus
  3257. * @wpa_s: wpa_supplicant interface structure
  3258. * @ssid: SSID struct
  3259. * Returns: 0 on success, -1 on failure
  3260. *
  3261. * Registers p2p group representing object with dbus
  3262. */
  3263. void wpas_dbus_register_p2p_group(struct wpa_supplicant *wpa_s,
  3264. struct wpa_ssid *ssid)
  3265. {
  3266. struct wpas_dbus_priv *ctrl_iface;
  3267. struct wpa_dbus_object_desc *obj_desc;
  3268. char group_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3269. /* Do nothing if the control interface is not turned on */
  3270. if (wpa_s == NULL || wpa_s->global == NULL)
  3271. return;
  3272. ctrl_iface = wpa_s->global->dbus;
  3273. if (ctrl_iface == NULL)
  3274. return;
  3275. if (wpa_s->dbus_groupobj_path) {
  3276. wpa_printf(MSG_INFO, "%s: Group object '%s' already exists",
  3277. __func__, wpa_s->dbus_groupobj_path);
  3278. return;
  3279. }
  3280. if (wpas_dbus_get_group_obj_path(wpa_s, ssid, group_obj_path) < 0)
  3281. return;
  3282. wpa_s->dbus_groupobj_path = os_strdup(group_obj_path);
  3283. if (wpa_s->dbus_groupobj_path == NULL)
  3284. return;
  3285. wpa_printf(MSG_INFO, "dbus: Register group object '%s'",
  3286. group_obj_path);
  3287. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  3288. if (!obj_desc) {
  3289. wpa_printf(MSG_ERROR,
  3290. "Not enough memory to create object description");
  3291. goto err;
  3292. }
  3293. wpas_dbus_register(obj_desc, wpa_s, NULL, NULL,
  3294. wpas_dbus_p2p_group_properties,
  3295. wpas_dbus_p2p_group_signals);
  3296. if (wpa_dbus_register_object_per_iface(ctrl_iface, group_obj_path,
  3297. wpa_s->ifname, obj_desc))
  3298. goto err;
  3299. return;
  3300. err:
  3301. if (wpa_s->dbus_groupobj_path) {
  3302. os_free(wpa_s->dbus_groupobj_path);
  3303. wpa_s->dbus_groupobj_path = NULL;
  3304. }
  3305. free_dbus_object_desc(obj_desc);
  3306. }
  3307. /**
  3308. * wpas_dbus_unregister_p2p_group - Unregister a p2p group object from dbus
  3309. * @wpa_s: wpa_supplicant interface structure
  3310. * @ssid: network name of the p2p group started
  3311. */
  3312. void wpas_dbus_unregister_p2p_group(struct wpa_supplicant *wpa_s,
  3313. const struct wpa_ssid *ssid)
  3314. {
  3315. struct wpas_dbus_priv *ctrl_iface;
  3316. /* Do nothing if the control interface is not turned on */
  3317. if (wpa_s == NULL || wpa_s->global == NULL)
  3318. return;
  3319. if (wpa_s->p2p_mgmt)
  3320. wpa_s = wpa_s->parent;
  3321. ctrl_iface = wpa_s->global->dbus;
  3322. if (ctrl_iface == NULL)
  3323. return;
  3324. if (!wpa_s->dbus_groupobj_path) {
  3325. wpa_printf(MSG_DEBUG,
  3326. "%s: Group object '%s' already unregistered",
  3327. __func__, wpa_s->dbus_groupobj_path);
  3328. return;
  3329. }
  3330. peer_groups_changed(wpa_s);
  3331. wpa_printf(MSG_DEBUG, "dbus: Unregister group object '%s'",
  3332. wpa_s->dbus_groupobj_path);
  3333. wpa_dbus_unregister_object_per_iface(ctrl_iface,
  3334. wpa_s->dbus_groupobj_path);
  3335. os_free(wpa_s->dbus_groupobj_path);
  3336. wpa_s->dbus_groupobj_path = NULL;
  3337. }
  3338. static const struct wpa_dbus_property_desc
  3339. wpas_dbus_persistent_group_properties[] = {
  3340. { "Properties", WPAS_DBUS_NEW_IFACE_PERSISTENT_GROUP, "a{sv}",
  3341. wpas_dbus_getter_persistent_group_properties,
  3342. wpas_dbus_setter_persistent_group_properties
  3343. },
  3344. { NULL, NULL, NULL, NULL, NULL }
  3345. };
  3346. /* No signals intended for persistent group objects */
  3347. /**
  3348. * wpas_dbus_register_persistent_group - Register a configured(saved)
  3349. * persistent group with dbus
  3350. * @wpa_s: wpa_supplicant interface structure
  3351. * @ssid: persistent group (still represented as a network within wpa)
  3352. * configuration data
  3353. * Returns: 0 on success, -1 on failure
  3354. *
  3355. * Registers a persistent group representing object with dbus.
  3356. */
  3357. int wpas_dbus_register_persistent_group(struct wpa_supplicant *wpa_s,
  3358. struct wpa_ssid *ssid)
  3359. {
  3360. struct wpas_dbus_priv *ctrl_iface;
  3361. struct wpa_dbus_object_desc *obj_desc;
  3362. struct network_handler_args *arg;
  3363. char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3364. /* Do nothing if the control interface is not turned on */
  3365. if (wpa_s == NULL || wpa_s->global == NULL)
  3366. return 0;
  3367. wpa_s = wpa_s->parent->parent;
  3368. if (!wpa_s->dbus_new_path)
  3369. return 0;
  3370. /* Make sure ssid is a persistent group */
  3371. if (ssid->disabled != 2 && !ssid->p2p_persistent_group)
  3372. return -1; /* should we return w/o complaining? */
  3373. if (wpa_s->p2p_mgmt)
  3374. wpa_s = wpa_s->parent;
  3375. ctrl_iface = wpa_s->global->dbus;
  3376. if (ctrl_iface == NULL)
  3377. return 0;
  3378. /*
  3379. * Intentionally not coming up with different numbering scheme
  3380. * for persistent groups.
  3381. */
  3382. os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3383. "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
  3384. wpa_s->dbus_new_path, ssid->id);
  3385. wpa_printf(MSG_DEBUG, "dbus: Register persistent group object '%s'",
  3386. pgrp_obj_path);
  3387. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  3388. if (!obj_desc) {
  3389. wpa_printf(MSG_ERROR,
  3390. "dbus: Not enough memory to create object description");
  3391. goto err;
  3392. }
  3393. /*
  3394. * Reusing the same context structure as that for networks
  3395. * since these are represented using same data structure.
  3396. */
  3397. /* allocate memory for handlers arguments */
  3398. arg = os_zalloc(sizeof(struct network_handler_args));
  3399. if (!arg) {
  3400. wpa_printf(MSG_ERROR,
  3401. "dbus: Not enough memory to create arguments for method");
  3402. goto err;
  3403. }
  3404. arg->wpa_s = wpa_s;
  3405. arg->ssid = ssid;
  3406. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  3407. wpas_dbus_persistent_group_properties,
  3408. NULL);
  3409. if (wpa_dbus_register_object_per_iface(ctrl_iface, pgrp_obj_path,
  3410. wpa_s->ifname, obj_desc))
  3411. goto err;
  3412. wpas_dbus_signal_persistent_group_added(wpa_s, ssid->id);
  3413. return 0;
  3414. err:
  3415. free_dbus_object_desc(obj_desc);
  3416. return -1;
  3417. }
  3418. /**
  3419. * wpas_dbus_unregister_persistent_group - Unregister a persistent_group
  3420. * from dbus
  3421. * @wpa_s: wpa_supplicant interface structure
  3422. * @nid: network id
  3423. * Returns: 0 on success, -1 on failure
  3424. *
  3425. * Unregisters persistent group representing object from dbus
  3426. *
  3427. * NOTE: There is a slight issue with the semantics here. While the
  3428. * implementation simply means the persistent group is unloaded from memory,
  3429. * it should not get interpreted as the group is actually being erased/removed
  3430. * from persistent storage as well.
  3431. */
  3432. int wpas_dbus_unregister_persistent_group(struct wpa_supplicant *wpa_s,
  3433. int nid)
  3434. {
  3435. struct wpas_dbus_priv *ctrl_iface;
  3436. char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3437. int ret;
  3438. /* Do nothing if the control interface is not turned on */
  3439. if (wpa_s == NULL || wpa_s->global == NULL)
  3440. return 0;
  3441. wpa_s = wpa_s->parent->parent;
  3442. ctrl_iface = wpa_s->global->dbus;
  3443. if (ctrl_iface == NULL || !wpa_s->dbus_new_path)
  3444. return 0;
  3445. os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3446. "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
  3447. wpa_s->dbus_new_path, nid);
  3448. wpa_printf(MSG_DEBUG, "dbus: Unregister persistent group object '%s'",
  3449. pgrp_obj_path);
  3450. ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, pgrp_obj_path);
  3451. if (!ret)
  3452. wpas_dbus_signal_persistent_group_removed(wpa_s, nid);
  3453. return ret;
  3454. }
  3455. #endif /* CONFIG_P2P */