dbus_new.c 96 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709
  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 program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * Alternatively, this software may be distributed under the terms of BSD
  12. * license.
  13. *
  14. * See README and COPYING for more details.
  15. */
  16. #include "includes.h"
  17. #include "common.h"
  18. #include "common/ieee802_11_defs.h"
  19. #include "wps/wps.h"
  20. #include "../config.h"
  21. #include "../wpa_supplicant_i.h"
  22. #include "../bss.h"
  23. #include "../wpas_glue.h"
  24. #include "dbus_new_helpers.h"
  25. #include "dbus_dict_helpers.h"
  26. #include "dbus_new.h"
  27. #include "dbus_new_handlers.h"
  28. #include "dbus_common_i.h"
  29. #include "dbus_new_handlers_p2p.h"
  30. #include "p2p/p2p.h"
  31. #ifdef CONFIG_AP /* until needed by something else */
  32. /*
  33. * NameOwnerChanged handling
  34. *
  35. * Some services we provide allow an application to register for
  36. * a signal that it needs. While it can also unregister, we must
  37. * be prepared for the case where the application simply crashes
  38. * and thus doesn't clean up properly. The way to handle this in
  39. * DBus is to register for the NameOwnerChanged signal which will
  40. * signal an owner change to NULL if the peer closes the socket
  41. * for whatever reason.
  42. *
  43. * Handle this signal via a filter function whenever necessary.
  44. * The code below also handles refcounting in case in the future
  45. * there will be multiple instances of this subscription scheme.
  46. */
  47. static const char wpas_dbus_noc_filter_str[] =
  48. "interface=org.freedesktop.DBus,member=NameOwnerChanged";
  49. static DBusHandlerResult noc_filter(DBusConnection *conn,
  50. DBusMessage *message, void *data)
  51. {
  52. struct wpas_dbus_priv *priv = data;
  53. if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_SIGNAL)
  54. return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
  55. if (dbus_message_is_signal(message, DBUS_INTERFACE_DBUS,
  56. "NameOwnerChanged")) {
  57. const char *name;
  58. const char *prev_owner;
  59. const char *new_owner;
  60. DBusError derr;
  61. struct wpa_supplicant *wpa_s;
  62. dbus_error_init(&derr);
  63. if (!dbus_message_get_args(message, &derr,
  64. DBUS_TYPE_STRING, &name,
  65. DBUS_TYPE_STRING, &prev_owner,
  66. DBUS_TYPE_STRING, &new_owner,
  67. DBUS_TYPE_INVALID)) {
  68. /* Ignore this error */
  69. dbus_error_free(&derr);
  70. return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
  71. }
  72. for (wpa_s = priv->global->ifaces; wpa_s; wpa_s = wpa_s->next)
  73. {
  74. if (wpa_s->preq_notify_peer != NULL &&
  75. os_strcmp(name, wpa_s->preq_notify_peer) == 0 &&
  76. (new_owner == NULL || os_strlen(new_owner) == 0)) {
  77. /* probe request owner disconnected */
  78. os_free(wpa_s->preq_notify_peer);
  79. wpa_s->preq_notify_peer = NULL;
  80. wpas_dbus_unsubscribe_noc(priv);
  81. }
  82. }
  83. }
  84. return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
  85. }
  86. void wpas_dbus_subscribe_noc(struct wpas_dbus_priv *priv)
  87. {
  88. priv->dbus_noc_refcnt++;
  89. if (priv->dbus_noc_refcnt > 1)
  90. return;
  91. if (!dbus_connection_add_filter(priv->con, noc_filter, priv, NULL)) {
  92. wpa_printf(MSG_ERROR, "dbus: failed to add filter");
  93. return;
  94. }
  95. dbus_bus_add_match(priv->con, wpas_dbus_noc_filter_str, NULL);
  96. }
  97. void wpas_dbus_unsubscribe_noc(struct wpas_dbus_priv *priv)
  98. {
  99. priv->dbus_noc_refcnt--;
  100. if (priv->dbus_noc_refcnt > 0)
  101. return;
  102. dbus_bus_remove_match(priv->con, wpas_dbus_noc_filter_str, NULL);
  103. dbus_connection_remove_filter(priv->con, noc_filter, priv);
  104. }
  105. #endif /* CONFIG_AP */
  106. /**
  107. * wpas_dbus_signal_interface - Send a interface related event signal
  108. * @wpa_s: %wpa_supplicant network interface data
  109. * @sig_name: signal name - InterfaceAdded or InterfaceRemoved
  110. * @properties: Whether to add second argument with object properties
  111. *
  112. * Notify listeners about event related with interface
  113. */
  114. static void wpas_dbus_signal_interface(struct wpa_supplicant *wpa_s,
  115. const char *sig_name, int properties)
  116. {
  117. struct wpas_dbus_priv *iface;
  118. DBusMessage *msg;
  119. DBusMessageIter iter;
  120. iface = wpa_s->global->dbus;
  121. /* Do nothing if the control interface is not turned on */
  122. if (iface == NULL)
  123. return;
  124. msg = dbus_message_new_signal(WPAS_DBUS_NEW_PATH,
  125. WPAS_DBUS_NEW_INTERFACE, sig_name);
  126. if (msg == NULL)
  127. return;
  128. dbus_message_iter_init_append(msg, &iter);
  129. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  130. &wpa_s->dbus_new_path))
  131. goto err;
  132. if (properties) {
  133. if (!wpa_dbus_get_object_properties(
  134. iface, wpa_s->dbus_new_path,
  135. WPAS_DBUS_NEW_IFACE_INTERFACE, &iter))
  136. goto err;
  137. }
  138. dbus_connection_send(iface->con, msg, NULL);
  139. dbus_message_unref(msg);
  140. return;
  141. err:
  142. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  143. dbus_message_unref(msg);
  144. }
  145. /**
  146. * wpas_dbus_signal_interface_added - Send a interface created signal
  147. * @wpa_s: %wpa_supplicant network interface data
  148. *
  149. * Notify listeners about creating new interface
  150. */
  151. static void wpas_dbus_signal_interface_added(struct wpa_supplicant *wpa_s)
  152. {
  153. wpas_dbus_signal_interface(wpa_s, "InterfaceAdded", TRUE);
  154. }
  155. /**
  156. * wpas_dbus_signal_interface_removed - Send a interface removed signal
  157. * @wpa_s: %wpa_supplicant network interface data
  158. *
  159. * Notify listeners about removing interface
  160. */
  161. static void wpas_dbus_signal_interface_removed(struct wpa_supplicant *wpa_s)
  162. {
  163. wpas_dbus_signal_interface(wpa_s, "InterfaceRemoved", FALSE);
  164. }
  165. /**
  166. * wpas_dbus_signal_scan_done - send scan done signal
  167. * @wpa_s: %wpa_supplicant network interface data
  168. * @success: indicates if scanning succeed or failed
  169. *
  170. * Notify listeners about finishing a scan
  171. */
  172. void wpas_dbus_signal_scan_done(struct wpa_supplicant *wpa_s, int success)
  173. {
  174. struct wpas_dbus_priv *iface;
  175. DBusMessage *msg;
  176. dbus_bool_t succ;
  177. iface = wpa_s->global->dbus;
  178. /* Do nothing if the control interface is not turned on */
  179. if (iface == NULL)
  180. return;
  181. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  182. WPAS_DBUS_NEW_IFACE_INTERFACE,
  183. "ScanDone");
  184. if (msg == NULL)
  185. return;
  186. succ = success ? TRUE : FALSE;
  187. if (dbus_message_append_args(msg, DBUS_TYPE_BOOLEAN, &succ,
  188. DBUS_TYPE_INVALID))
  189. dbus_connection_send(iface->con, msg, NULL);
  190. else
  191. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  192. dbus_message_unref(msg);
  193. }
  194. /**
  195. * wpas_dbus_signal_blob - Send a BSS related event signal
  196. * @wpa_s: %wpa_supplicant network interface data
  197. * @bss_obj_path: BSS object path
  198. * @sig_name: signal name - BSSAdded or BSSRemoved
  199. * @properties: Whether to add second argument with object properties
  200. *
  201. * Notify listeners about event related with BSS
  202. */
  203. static void wpas_dbus_signal_bss(struct wpa_supplicant *wpa_s,
  204. const char *bss_obj_path,
  205. const char *sig_name, int properties)
  206. {
  207. struct wpas_dbus_priv *iface;
  208. DBusMessage *msg;
  209. DBusMessageIter iter;
  210. iface = wpa_s->global->dbus;
  211. /* Do nothing if the control interface is not turned on */
  212. if (iface == NULL)
  213. return;
  214. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  215. WPAS_DBUS_NEW_IFACE_INTERFACE,
  216. sig_name);
  217. if (msg == NULL)
  218. return;
  219. dbus_message_iter_init_append(msg, &iter);
  220. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  221. &bss_obj_path))
  222. goto err;
  223. if (properties) {
  224. if (!wpa_dbus_get_object_properties(iface, bss_obj_path,
  225. WPAS_DBUS_NEW_IFACE_BSS,
  226. &iter))
  227. goto err;
  228. }
  229. dbus_connection_send(iface->con, msg, NULL);
  230. dbus_message_unref(msg);
  231. return;
  232. err:
  233. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  234. dbus_message_unref(msg);
  235. }
  236. /**
  237. * wpas_dbus_signal_bss_added - Send a BSS added signal
  238. * @wpa_s: %wpa_supplicant network interface data
  239. * @bss_obj_path: new BSS object path
  240. *
  241. * Notify listeners about adding new BSS
  242. */
  243. static void wpas_dbus_signal_bss_added(struct wpa_supplicant *wpa_s,
  244. const char *bss_obj_path)
  245. {
  246. wpas_dbus_signal_bss(wpa_s, bss_obj_path, "BSSAdded", TRUE);
  247. }
  248. /**
  249. * wpas_dbus_signal_bss_removed - Send a BSS removed signal
  250. * @wpa_s: %wpa_supplicant network interface data
  251. * @bss_obj_path: BSS object path
  252. *
  253. * Notify listeners about removing BSS
  254. */
  255. static void wpas_dbus_signal_bss_removed(struct wpa_supplicant *wpa_s,
  256. const char *bss_obj_path)
  257. {
  258. wpas_dbus_signal_bss(wpa_s, bss_obj_path, "BSSRemoved", FALSE);
  259. }
  260. /**
  261. * wpas_dbus_signal_blob - Send a blob related event signal
  262. * @wpa_s: %wpa_supplicant network interface data
  263. * @name: blob name
  264. * @sig_name: signal name - BlobAdded or BlobRemoved
  265. *
  266. * Notify listeners about event related with blob
  267. */
  268. static void wpas_dbus_signal_blob(struct wpa_supplicant *wpa_s,
  269. const char *name, const char *sig_name)
  270. {
  271. struct wpas_dbus_priv *iface;
  272. DBusMessage *msg;
  273. iface = wpa_s->global->dbus;
  274. /* Do nothing if the control interface is not turned on */
  275. if (iface == NULL)
  276. return;
  277. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  278. WPAS_DBUS_NEW_IFACE_INTERFACE,
  279. sig_name);
  280. if (msg == NULL)
  281. return;
  282. if (dbus_message_append_args(msg, DBUS_TYPE_STRING, &name,
  283. DBUS_TYPE_INVALID))
  284. dbus_connection_send(iface->con, msg, NULL);
  285. else
  286. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  287. dbus_message_unref(msg);
  288. }
  289. /**
  290. * wpas_dbus_signal_blob_added - Send a blob added signal
  291. * @wpa_s: %wpa_supplicant network interface data
  292. * @name: blob name
  293. *
  294. * Notify listeners about adding a new blob
  295. */
  296. void wpas_dbus_signal_blob_added(struct wpa_supplicant *wpa_s,
  297. const char *name)
  298. {
  299. wpas_dbus_signal_blob(wpa_s, name, "BlobAdded");
  300. }
  301. /**
  302. * wpas_dbus_signal_blob_removed - Send a blob removed signal
  303. * @wpa_s: %wpa_supplicant network interface data
  304. * @name: blob name
  305. *
  306. * Notify listeners about removing blob
  307. */
  308. void wpas_dbus_signal_blob_removed(struct wpa_supplicant *wpa_s,
  309. const char *name)
  310. {
  311. wpas_dbus_signal_blob(wpa_s, name, "BlobRemoved");
  312. }
  313. /**
  314. * wpas_dbus_signal_network - Send a network related event signal
  315. * @wpa_s: %wpa_supplicant network interface data
  316. * @id: new network id
  317. * @sig_name: signal name - NetworkAdded, NetworkRemoved or NetworkSelected
  318. * @properties: determines if add second argument with object properties
  319. *
  320. * Notify listeners about event related with configured network
  321. */
  322. static void wpas_dbus_signal_network(struct wpa_supplicant *wpa_s,
  323. int id, const char *sig_name,
  324. int properties)
  325. {
  326. struct wpas_dbus_priv *iface;
  327. DBusMessage *msg;
  328. DBusMessageIter iter;
  329. char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  330. iface = wpa_s->global->dbus;
  331. /* Do nothing if the control interface is not turned on */
  332. if (iface == NULL)
  333. return;
  334. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  335. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  336. wpa_s->dbus_new_path, id);
  337. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  338. WPAS_DBUS_NEW_IFACE_INTERFACE,
  339. sig_name);
  340. if (msg == NULL)
  341. return;
  342. dbus_message_iter_init_append(msg, &iter);
  343. path = net_obj_path;
  344. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  345. &path))
  346. goto err;
  347. if (properties) {
  348. if (!wpa_dbus_get_object_properties(
  349. iface, net_obj_path, WPAS_DBUS_NEW_IFACE_NETWORK,
  350. &iter))
  351. goto err;
  352. }
  353. dbus_connection_send(iface->con, msg, NULL);
  354. dbus_message_unref(msg);
  355. return;
  356. err:
  357. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  358. dbus_message_unref(msg);
  359. }
  360. /**
  361. * wpas_dbus_signal_network_added - Send a network added signal
  362. * @wpa_s: %wpa_supplicant network interface data
  363. * @id: new network id
  364. *
  365. * Notify listeners about adding new network
  366. */
  367. static void wpas_dbus_signal_network_added(struct wpa_supplicant *wpa_s,
  368. int id)
  369. {
  370. wpas_dbus_signal_network(wpa_s, id, "NetworkAdded", TRUE);
  371. }
  372. /**
  373. * wpas_dbus_signal_network_removed - Send a network removed signal
  374. * @wpa_s: %wpa_supplicant network interface data
  375. * @id: network id
  376. *
  377. * Notify listeners about removing a network
  378. */
  379. static void wpas_dbus_signal_network_removed(struct wpa_supplicant *wpa_s,
  380. int id)
  381. {
  382. wpas_dbus_signal_network(wpa_s, id, "NetworkRemoved", FALSE);
  383. }
  384. /**
  385. * wpas_dbus_signal_network_selected - Send a network selected signal
  386. * @wpa_s: %wpa_supplicant network interface data
  387. * @id: network id
  388. *
  389. * Notify listeners about selecting a network
  390. */
  391. void wpas_dbus_signal_network_selected(struct wpa_supplicant *wpa_s, int id)
  392. {
  393. wpas_dbus_signal_network(wpa_s, id, "NetworkSelected", FALSE);
  394. }
  395. /**
  396. * wpas_dbus_signal_network_request - Indicate that additional information
  397. * (EAP password, etc.) is required to complete the association to this SSID
  398. * @wpa_s: %wpa_supplicant network interface data
  399. * @rtype: The specific additional information required
  400. * @default_text: Optional description of required information
  401. *
  402. * Request additional information or passwords to complete an association
  403. * request.
  404. */
  405. void wpas_dbus_signal_network_request(struct wpa_supplicant *wpa_s,
  406. struct wpa_ssid *ssid,
  407. enum wpa_ctrl_req_type rtype,
  408. const char *default_txt)
  409. {
  410. struct wpas_dbus_priv *iface;
  411. DBusMessage *msg;
  412. DBusMessageIter iter;
  413. char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  414. const char *field, *txt = NULL, *net_ptr;
  415. iface = wpa_s->global->dbus;
  416. /* Do nothing if the control interface is not turned on */
  417. if (iface == NULL)
  418. return;
  419. field = wpa_supplicant_ctrl_req_to_string(rtype, default_txt, &txt);
  420. if (field == NULL)
  421. return;
  422. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  423. WPAS_DBUS_NEW_IFACE_INTERFACE,
  424. "NetworkRequest");
  425. if (msg == NULL)
  426. return;
  427. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  428. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  429. wpa_s->dbus_new_path, ssid->id);
  430. net_ptr = &net_obj_path[0];
  431. dbus_message_iter_init_append(msg, &iter);
  432. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  433. &net_ptr))
  434. goto err;
  435. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &field))
  436. goto err;
  437. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &txt))
  438. goto err;
  439. dbus_connection_send(iface->con, msg, NULL);
  440. dbus_message_unref(msg);
  441. return;
  442. err:
  443. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  444. dbus_message_unref(msg);
  445. }
  446. /**
  447. * wpas_dbus_signal_network_enabled_changed - Signals Enabled property changes
  448. * @wpa_s: %wpa_supplicant network interface data
  449. * @ssid: configured network which Enabled property has changed
  450. *
  451. * Sends PropertyChanged signals containing new value of Enabled property
  452. * for specified network
  453. */
  454. void wpas_dbus_signal_network_enabled_changed(struct wpa_supplicant *wpa_s,
  455. struct wpa_ssid *ssid)
  456. {
  457. char path[WPAS_DBUS_OBJECT_PATH_MAX];
  458. os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
  459. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
  460. wpa_s->dbus_new_path, ssid->id);
  461. wpa_dbus_mark_property_changed(wpa_s->global->dbus, path,
  462. WPAS_DBUS_NEW_IFACE_NETWORK, "Enabled");
  463. }
  464. #ifdef CONFIG_WPS
  465. /**
  466. * wpas_dbus_signal_wps_event_success - Signals Success WPS event
  467. * @wpa_s: %wpa_supplicant network interface data
  468. *
  469. * Sends Event dbus signal with name "success" and empty dict as arguments
  470. */
  471. void wpas_dbus_signal_wps_event_success(struct wpa_supplicant *wpa_s)
  472. {
  473. DBusMessage *msg;
  474. DBusMessageIter iter, dict_iter;
  475. struct wpas_dbus_priv *iface;
  476. char *key = "success";
  477. iface = wpa_s->global->dbus;
  478. /* Do nothing if the control interface is not turned on */
  479. if (iface == NULL)
  480. return;
  481. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  482. WPAS_DBUS_NEW_IFACE_WPS, "Event");
  483. if (msg == NULL)
  484. return;
  485. dbus_message_iter_init_append(msg, &iter);
  486. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
  487. !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  488. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  489. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  490. else
  491. dbus_connection_send(iface->con, msg, NULL);
  492. dbus_message_unref(msg);
  493. }
  494. /**
  495. * wpas_dbus_signal_wps_event_fail - Signals Fail WPS event
  496. * @wpa_s: %wpa_supplicant network interface data
  497. *
  498. * Sends Event dbus signal with name "fail" and dictionary containing
  499. * "msg field with fail message number (int32) as arguments
  500. */
  501. void wpas_dbus_signal_wps_event_fail(struct wpa_supplicant *wpa_s,
  502. struct wps_event_fail *fail)
  503. {
  504. DBusMessage *msg;
  505. DBusMessageIter iter, dict_iter;
  506. struct wpas_dbus_priv *iface;
  507. char *key = "fail";
  508. iface = wpa_s->global->dbus;
  509. /* Do nothing if the control interface is not turned on */
  510. if (iface == NULL)
  511. return;
  512. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  513. WPAS_DBUS_NEW_IFACE_WPS, "Event");
  514. if (msg == NULL)
  515. return;
  516. dbus_message_iter_init_append(msg, &iter);
  517. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
  518. !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  519. !wpa_dbus_dict_append_int32(&dict_iter, "msg", fail->msg) ||
  520. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  521. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  522. else
  523. dbus_connection_send(iface->con, msg, NULL);
  524. dbus_message_unref(msg);
  525. }
  526. /**
  527. * wpas_dbus_signal_wps_event_m2d - Signals M2D WPS event
  528. * @wpa_s: %wpa_supplicant network interface data
  529. *
  530. * Sends Event dbus signal with name "m2d" and dictionary containing
  531. * fields of wps_event_m2d structure.
  532. */
  533. void wpas_dbus_signal_wps_event_m2d(struct wpa_supplicant *wpa_s,
  534. struct wps_event_m2d *m2d)
  535. {
  536. DBusMessage *msg;
  537. DBusMessageIter iter, dict_iter;
  538. struct wpas_dbus_priv *iface;
  539. char *key = "m2d";
  540. iface = wpa_s->global->dbus;
  541. /* Do nothing if the control interface is not turned on */
  542. if (iface == NULL)
  543. return;
  544. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  545. WPAS_DBUS_NEW_IFACE_WPS, "Event");
  546. if (msg == NULL)
  547. return;
  548. dbus_message_iter_init_append(msg, &iter);
  549. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
  550. !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  551. !wpa_dbus_dict_append_uint16(&dict_iter, "config_methods",
  552. m2d->config_methods) ||
  553. !wpa_dbus_dict_append_byte_array(&dict_iter, "manufacturer",
  554. (const char *) m2d->manufacturer,
  555. m2d->manufacturer_len) ||
  556. !wpa_dbus_dict_append_byte_array(&dict_iter, "model_name",
  557. (const char *) m2d->model_name,
  558. m2d->model_name_len) ||
  559. !wpa_dbus_dict_append_byte_array(&dict_iter, "model_number",
  560. (const char *) m2d->model_number,
  561. m2d->model_number_len) ||
  562. !wpa_dbus_dict_append_byte_array(&dict_iter, "serial_number",
  563. (const char *)
  564. m2d->serial_number,
  565. m2d->serial_number_len) ||
  566. !wpa_dbus_dict_append_byte_array(&dict_iter, "dev_name",
  567. (const char *) m2d->dev_name,
  568. m2d->dev_name_len) ||
  569. !wpa_dbus_dict_append_byte_array(&dict_iter, "primary_dev_type",
  570. (const char *)
  571. m2d->primary_dev_type, 8) ||
  572. !wpa_dbus_dict_append_uint16(&dict_iter, "config_error",
  573. m2d->config_error) ||
  574. !wpa_dbus_dict_append_uint16(&dict_iter, "dev_password_id",
  575. m2d->dev_password_id) ||
  576. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  577. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  578. else
  579. dbus_connection_send(iface->con, msg, NULL);
  580. dbus_message_unref(msg);
  581. }
  582. /**
  583. * wpas_dbus_signal_wps_cred - Signals new credentials
  584. * @wpa_s: %wpa_supplicant network interface data
  585. *
  586. * Sends signal with credentials in directory argument
  587. */
  588. void wpas_dbus_signal_wps_cred(struct wpa_supplicant *wpa_s,
  589. const struct wps_credential *cred)
  590. {
  591. DBusMessage *msg;
  592. DBusMessageIter iter, dict_iter;
  593. struct wpas_dbus_priv *iface;
  594. char *auth_type[6]; /* we have six possible authorization types */
  595. int at_num = 0;
  596. char *encr_type[4]; /* we have four possible encryption types */
  597. int et_num = 0;
  598. iface = wpa_s->global->dbus;
  599. /* Do nothing if the control interface is not turned on */
  600. if (iface == NULL)
  601. return;
  602. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  603. WPAS_DBUS_NEW_IFACE_WPS,
  604. "Credentials");
  605. if (msg == NULL)
  606. return;
  607. dbus_message_iter_init_append(msg, &iter);
  608. if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
  609. goto nomem;
  610. if (cred->auth_type & WPS_AUTH_OPEN)
  611. auth_type[at_num++] = "open";
  612. if (cred->auth_type & WPS_AUTH_WPAPSK)
  613. auth_type[at_num++] = "wpa-psk";
  614. if (cred->auth_type & WPS_AUTH_SHARED)
  615. auth_type[at_num++] = "shared";
  616. if (cred->auth_type & WPS_AUTH_WPA)
  617. auth_type[at_num++] = "wpa-eap";
  618. if (cred->auth_type & WPS_AUTH_WPA2)
  619. auth_type[at_num++] = "wpa2-eap";
  620. if (cred->auth_type & WPS_AUTH_WPA2PSK)
  621. auth_type[at_num++] =
  622. "wpa2-psk";
  623. if (cred->encr_type & WPS_ENCR_NONE)
  624. encr_type[et_num++] = "none";
  625. if (cred->encr_type & WPS_ENCR_WEP)
  626. encr_type[et_num++] = "wep";
  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. if (!wpa_dbus_dict_append_byte_array(
  633. &dict_iter, "BSSID",
  634. (const char *) wpa_s->current_ssid->bssid,
  635. ETH_ALEN))
  636. goto nomem;
  637. }
  638. if (!wpa_dbus_dict_append_byte_array(&dict_iter, "SSID",
  639. (const char *) cred->ssid,
  640. cred->ssid_len) ||
  641. !wpa_dbus_dict_append_string_array(&dict_iter, "AuthType",
  642. (const char **) auth_type,
  643. at_num) ||
  644. !wpa_dbus_dict_append_string_array(&dict_iter, "EncrType",
  645. (const char **) encr_type,
  646. et_num) ||
  647. !wpa_dbus_dict_append_byte_array(&dict_iter, "Key",
  648. (const char *) cred->key,
  649. cred->key_len) ||
  650. !wpa_dbus_dict_append_uint32(&dict_iter, "KeyIndex",
  651. cred->key_idx) ||
  652. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  653. goto nomem;
  654. dbus_connection_send(iface->con, msg, NULL);
  655. nomem:
  656. dbus_message_unref(msg);
  657. }
  658. #endif /* CONFIG_WPS */
  659. void wpas_dbus_signal_certification(struct wpa_supplicant *wpa_s,
  660. int depth, const char *subject,
  661. const char *cert_hash,
  662. const struct wpabuf *cert)
  663. {
  664. struct wpas_dbus_priv *iface;
  665. DBusMessage *msg;
  666. DBusMessageIter iter, dict_iter;
  667. iface = wpa_s->global->dbus;
  668. /* Do nothing if the control interface is not turned on */
  669. if (iface == NULL)
  670. return;
  671. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  672. WPAS_DBUS_NEW_IFACE_INTERFACE,
  673. "Certification");
  674. if (msg == NULL)
  675. return;
  676. dbus_message_iter_init_append(msg, &iter);
  677. if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
  678. goto nomem;
  679. if (!wpa_dbus_dict_append_uint32(&dict_iter, "depth", depth) ||
  680. !wpa_dbus_dict_append_string(&dict_iter, "subject", subject))
  681. goto nomem;
  682. if (cert_hash &&
  683. !wpa_dbus_dict_append_string(&dict_iter, "cert_hash", cert_hash))
  684. goto nomem;
  685. if (cert &&
  686. !wpa_dbus_dict_append_byte_array(&dict_iter, "cert",
  687. wpabuf_head(cert),
  688. wpabuf_len(cert)))
  689. goto nomem;
  690. if (!wpa_dbus_dict_close_write(&iter, &dict_iter))
  691. goto nomem;
  692. dbus_connection_send(iface->con, msg, NULL);
  693. nomem:
  694. dbus_message_unref(msg);
  695. }
  696. void wpas_dbus_signal_eap_status(struct wpa_supplicant *wpa_s,
  697. const char *status, const char *parameter)
  698. {
  699. struct wpas_dbus_priv *iface;
  700. DBusMessage *msg;
  701. DBusMessageIter iter;
  702. iface = wpa_s->global->dbus;
  703. /* Do nothing if the control interface is not turned on */
  704. if (iface == NULL)
  705. return;
  706. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  707. WPAS_DBUS_NEW_IFACE_INTERFACE,
  708. "EAP");
  709. if (msg == NULL)
  710. return;
  711. dbus_message_iter_init_append(msg, &iter);
  712. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &status)
  713. ||
  714. !dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING,
  715. &parameter))
  716. goto nomem;
  717. dbus_connection_send(iface->con, msg, NULL);
  718. nomem:
  719. dbus_message_unref(msg);
  720. }
  721. #ifdef CONFIG_P2P
  722. /**
  723. * wpas_dbus_signal_p2p_group_removed - Signals P2P group was removed
  724. * @wpa_s: %wpa_supplicant network interface data
  725. * @role: role of this device (client or GO)
  726. * Sends signal with i/f name and role as string arguments
  727. */
  728. void wpas_dbus_signal_p2p_group_removed(struct wpa_supplicant *wpa_s,
  729. const char *role)
  730. {
  731. DBusMessage *msg;
  732. DBusMessageIter iter;
  733. struct wpas_dbus_priv *iface = wpa_s->global->dbus;
  734. char *ifname = wpa_s->ifname;
  735. /* Do nothing if the control interface is not turned on */
  736. if (iface == NULL)
  737. return;
  738. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  739. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  740. "GroupFinished");
  741. if (msg == NULL)
  742. return;
  743. dbus_message_iter_init_append(msg, &iter);
  744. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &ifname)) {
  745. wpa_printf(MSG_ERROR, "dbus: Failed to construct GroupFinished"
  746. "signal -not enough memory for ifname ");
  747. goto err;
  748. }
  749. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &role))
  750. wpa_printf(MSG_ERROR, "dbus: Failed to construct GroupFinished"
  751. "signal -not enough memory for role ");
  752. else
  753. dbus_connection_send(iface->con, msg, NULL);
  754. err:
  755. dbus_message_unref(msg);
  756. }
  757. /**
  758. * wpas_dbus_signal_p2p_provision_discovery - Signals various PD events
  759. *
  760. * @dev_addr - who sent the request or responded to our request.
  761. * @request - Will be 1 if request, 0 for response.
  762. * @status - valid only in case of response
  763. * @config_methods - wps config methods
  764. * @generated_pin - pin to be displayed in case of WPS_CONFIG_DISPLAY method
  765. *
  766. * Sends following provision discovery related events:
  767. * ProvisionDiscoveryRequestDisplayPin
  768. * ProvisionDiscoveryResponseDisplayPin
  769. * ProvisionDiscoveryRequestEnterPin
  770. * ProvisionDiscoveryResponseEnterPin
  771. * ProvisionDiscoveryPBCRequest
  772. * ProvisionDiscoveryPBCResponse
  773. *
  774. * TODO::
  775. * ProvisionDiscoveryFailure (timeout case)
  776. */
  777. void wpas_dbus_signal_p2p_provision_discovery(struct wpa_supplicant *wpa_s,
  778. const u8 *dev_addr, int request,
  779. enum p2p_prov_disc_status status,
  780. u16 config_methods,
  781. unsigned int generated_pin)
  782. {
  783. DBusMessage *msg;
  784. DBusMessageIter iter;
  785. struct wpas_dbus_priv *iface;
  786. char *_signal;
  787. int add_pin = 0;
  788. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  789. int error_ret = 1;
  790. char pin[9], *p_pin = NULL;
  791. iface = wpa_s->global->dbus;
  792. /* Do nothing if the control interface is not turned on */
  793. if (iface == NULL)
  794. return;
  795. if (request || !status) {
  796. if (config_methods & WPS_CONFIG_DISPLAY)
  797. _signal = request ?
  798. "ProvisionDiscoveryRequestDisplayPin" :
  799. "ProvisionDiscoveryResponseEnterPin";
  800. else if (config_methods & WPS_CONFIG_KEYPAD)
  801. _signal = request ?
  802. "ProvisionDiscoveryRequestEnterPin" :
  803. "ProvisionDiscoveryResponseDisplayPin";
  804. else if (config_methods & WPS_CONFIG_PUSHBUTTON)
  805. _signal = request ? "ProvisionDiscoveryPBCRequest" :
  806. "ProvisionDiscoveryPBCResponse";
  807. else
  808. return; /* Unknown or un-supported method */
  809. } else if (!request && status)
  810. /* Explicit check for failure response */
  811. _signal = "ProvisionDiscoveryFailure";
  812. add_pin = ((request && (config_methods & WPS_CONFIG_DISPLAY)) ||
  813. (!request && !status &&
  814. (config_methods & WPS_CONFIG_KEYPAD)));
  815. if (add_pin) {
  816. os_snprintf(pin, sizeof(pin), "%08d", generated_pin);
  817. p_pin = pin;
  818. }
  819. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  820. WPAS_DBUS_NEW_IFACE_P2PDEVICE, _signal);
  821. if (msg == NULL)
  822. return;
  823. /* Check if this is a known peer */
  824. if (!p2p_peer_known(wpa_s->global->p2p, dev_addr))
  825. goto error;
  826. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  827. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
  828. COMPACT_MACSTR,
  829. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  830. path = peer_obj_path;
  831. dbus_message_iter_init_append(msg, &iter);
  832. if (!dbus_message_iter_append_basic(&iter,
  833. DBUS_TYPE_OBJECT_PATH,
  834. &path))
  835. goto error;
  836. if (!request && status)
  837. /* Attach status to ProvisionDiscoveryFailure */
  838. error_ret = !dbus_message_iter_append_basic(&iter,
  839. DBUS_TYPE_INT32,
  840. &status);
  841. else
  842. error_ret = (add_pin &&
  843. !dbus_message_iter_append_basic(&iter,
  844. DBUS_TYPE_STRING,
  845. &p_pin));
  846. error:
  847. if (!error_ret)
  848. dbus_connection_send(iface->con, msg, NULL);
  849. else
  850. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  851. dbus_message_unref(msg);
  852. }
  853. void wpas_dbus_signal_p2p_go_neg_req(struct wpa_supplicant *wpa_s,
  854. const u8 *src, u16 dev_passwd_id)
  855. {
  856. DBusMessage *msg;
  857. DBusMessageIter iter;
  858. struct wpas_dbus_priv *iface;
  859. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  860. iface = wpa_s->global->dbus;
  861. /* Do nothing if the control interface is not turned on */
  862. if (iface == NULL)
  863. return;
  864. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  865. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  866. wpa_s->dbus_new_path, MAC2STR(src));
  867. path = peer_obj_path;
  868. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  869. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  870. "GONegotiationRequest");
  871. if (msg == NULL)
  872. return;
  873. dbus_message_iter_init_append(msg, &iter);
  874. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  875. &path) ||
  876. !dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT16,
  877. &dev_passwd_id))
  878. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  879. else
  880. dbus_connection_send(iface->con, msg, NULL);
  881. dbus_message_unref(msg);
  882. }
  883. static int wpas_dbus_get_group_obj_path(struct wpa_supplicant *wpa_s,
  884. const struct wpa_ssid *ssid,
  885. char *group_obj_path)
  886. {
  887. char group_name[3];
  888. if (os_memcmp(ssid->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN))
  889. return -1;
  890. os_memcpy(group_name, ssid->ssid + P2P_WILDCARD_SSID_LEN, 2);
  891. group_name[2] = '\0';
  892. os_snprintf(group_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  893. "%s/" WPAS_DBUS_NEW_P2P_GROUPS_PART "/%s",
  894. wpa_s->dbus_new_path, group_name);
  895. return 0;
  896. }
  897. /**
  898. * wpas_dbus_signal_p2p_group_started - Signals P2P group has
  899. * started. Emitted when a group is successfully started
  900. * irrespective of the role (client/GO) of the current device
  901. *
  902. * @wpa_s: %wpa_supplicant network interface data
  903. * @ssid: SSID object
  904. * @client: this device is P2P client
  905. * @network_id: network id of the group started, use instead of ssid->id
  906. * to account for persistent groups
  907. */
  908. void wpas_dbus_signal_p2p_group_started(struct wpa_supplicant *wpa_s,
  909. const struct wpa_ssid *ssid,
  910. int client, int network_id)
  911. {
  912. DBusMessage *msg;
  913. DBusMessageIter iter, dict_iter;
  914. struct wpas_dbus_priv *iface;
  915. char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  916. char group_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  917. iface = wpa_s->parent->global->dbus;
  918. /* Do nothing if the control interface is not turned on */
  919. if (iface == NULL)
  920. return;
  921. if (wpas_dbus_get_group_obj_path(wpa_s, ssid, group_obj_path) < 0)
  922. return;
  923. /* New interface has been created for this group */
  924. msg = dbus_message_new_signal(wpa_s->parent->dbus_new_path,
  925. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  926. "GroupStarted");
  927. if (msg == NULL)
  928. return;
  929. dbus_message_iter_init_append(msg, &iter);
  930. if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
  931. goto nomem;
  932. /*
  933. * In case the device supports creating a separate interface the
  934. * DBus client will need to know the object path for the interface
  935. * object this group was created on, so include it here.
  936. */
  937. if (!wpa_dbus_dict_append_object_path(&dict_iter,
  938. "interface_object",
  939. wpa_s->dbus_new_path))
  940. goto nomem;
  941. if (!wpa_dbus_dict_append_string(&dict_iter, "role",
  942. client ? "client" : "GO"))
  943. goto nomem;
  944. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  945. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  946. wpa_s->parent->dbus_new_path, network_id);
  947. if (!wpa_dbus_dict_append_object_path(&dict_iter, "group_object",
  948. group_obj_path) ||
  949. !wpa_dbus_dict_append_object_path(&dict_iter, "network_object",
  950. net_obj_path) ||
  951. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  952. goto nomem;
  953. dbus_connection_send(iface->con, msg, NULL);
  954. nomem:
  955. dbus_message_unref(msg);
  956. }
  957. /**
  958. *
  959. * Method to emit GONeogtiation Success or Failure signals based
  960. * on status.
  961. * @status: Status of the GO neg request. 0 for success, other for errors.
  962. */
  963. void wpas_dbus_signal_p2p_go_neg_resp(struct wpa_supplicant *wpa_s,
  964. struct p2p_go_neg_results *res)
  965. {
  966. DBusMessage *msg;
  967. DBusMessageIter iter, dict_iter;
  968. DBusMessageIter iter_dict_entry, iter_dict_val, iter_dict_array;
  969. struct wpas_dbus_priv *iface;
  970. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  971. dbus_int32_t freqs[P2P_MAX_CHANNELS];
  972. dbus_int32_t *f_array = freqs;
  973. iface = wpa_s->global->dbus;
  974. os_memset(freqs, 0, sizeof(freqs));
  975. /* Do nothing if the control interface is not turned on */
  976. if (iface == NULL)
  977. return;
  978. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  979. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  980. wpa_s->dbus_new_path, MAC2STR(res->peer_device_addr));
  981. path = peer_obj_path;
  982. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  983. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  984. res->status ? "GONegotiationFailure" :
  985. "GONegotiationSuccess");
  986. if (msg == NULL)
  987. return;
  988. dbus_message_iter_init_append(msg, &iter);
  989. if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
  990. goto err;
  991. if (!wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
  992. path) ||
  993. !wpa_dbus_dict_append_int32(&dict_iter, "status", res->status))
  994. goto err;
  995. if (!res->status) {
  996. int i = 0;
  997. int freq_list_num = 0;
  998. if (res->role_go) {
  999. if (!wpa_dbus_dict_append_byte_array(
  1000. &dict_iter, "passphrase",
  1001. (const char *) res->passphrase,
  1002. sizeof(res->passphrase)))
  1003. goto err;
  1004. }
  1005. if (!wpa_dbus_dict_append_string(&dict_iter, "role_go",
  1006. res->role_go ? "GO" :
  1007. "client") ||
  1008. !wpa_dbus_dict_append_int32(&dict_iter, "frequency",
  1009. res->freq) ||
  1010. !wpa_dbus_dict_append_byte_array(&dict_iter, "ssid",
  1011. (const char *) res->ssid,
  1012. res->ssid_len) ||
  1013. !wpa_dbus_dict_append_byte_array(&dict_iter,
  1014. "peer_device_addr",
  1015. (const char *)
  1016. res->peer_device_addr,
  1017. ETH_ALEN) ||
  1018. !wpa_dbus_dict_append_byte_array(&dict_iter,
  1019. "peer_interface_addr",
  1020. (const char *)
  1021. res->peer_interface_addr,
  1022. ETH_ALEN) ||
  1023. !wpa_dbus_dict_append_string(&dict_iter, "wps_method",
  1024. p2p_wps_method_text(
  1025. res->wps_method)))
  1026. goto err;
  1027. for (i = 0; i < P2P_MAX_CHANNELS; i++) {
  1028. if (res->freq_list[i]) {
  1029. freqs[i] = res->freq_list[i];
  1030. freq_list_num++;
  1031. }
  1032. }
  1033. if (!wpa_dbus_dict_begin_array(&dict_iter,
  1034. "frequency_list",
  1035. DBUS_TYPE_INT32_AS_STRING,
  1036. &iter_dict_entry,
  1037. &iter_dict_val,
  1038. &iter_dict_array))
  1039. goto err;
  1040. if (!dbus_message_iter_append_fixed_array(&iter_dict_array,
  1041. DBUS_TYPE_INT32,
  1042. &f_array,
  1043. freq_list_num))
  1044. goto err;
  1045. if (!wpa_dbus_dict_end_array(&dict_iter,
  1046. &iter_dict_entry,
  1047. &iter_dict_val,
  1048. &iter_dict_array))
  1049. goto err;
  1050. if (!wpa_dbus_dict_append_int32(&dict_iter, "persistent_group",
  1051. res->persistent_group) ||
  1052. !wpa_dbus_dict_append_uint32(&dict_iter,
  1053. "peer_config_timeout",
  1054. res->peer_config_timeout))
  1055. goto err;
  1056. }
  1057. if (!wpa_dbus_dict_close_write(&iter, &dict_iter))
  1058. goto err;
  1059. dbus_connection_send(iface->con, msg, NULL);
  1060. err:
  1061. dbus_message_unref(msg);
  1062. }
  1063. /**
  1064. *
  1065. * Method to emit Invitation Result signal based on status and
  1066. * bssid
  1067. * @status: Status of the Invite request. 0 for success, other
  1068. * for errors
  1069. * @bssid : Basic Service Set Identifier
  1070. */
  1071. void wpas_dbus_signal_p2p_invitation_result(struct wpa_supplicant *wpa_s,
  1072. int status, const u8 *bssid)
  1073. {
  1074. DBusMessage *msg;
  1075. DBusMessageIter iter, dict_iter;
  1076. struct wpas_dbus_priv *iface;
  1077. wpa_printf(MSG_INFO, "%s\n", __func__);
  1078. iface = wpa_s->global->dbus;
  1079. /* Do nothing if the control interface is not turned on */
  1080. if (iface == NULL)
  1081. return;
  1082. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1083. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1084. "InvitationResult");
  1085. if (msg == NULL)
  1086. return;
  1087. dbus_message_iter_init_append(msg, &iter);
  1088. if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
  1089. goto nomem;
  1090. if (!wpa_dbus_dict_append_int32(&dict_iter, "status", status))
  1091. goto nomem;
  1092. if (bssid) {
  1093. if (!wpa_dbus_dict_append_byte_array(&dict_iter, "BSSID",
  1094. (const char *) bssid,
  1095. ETH_ALEN))
  1096. goto nomem;
  1097. }
  1098. if (!wpa_dbus_dict_close_write(&iter, &dict_iter))
  1099. goto nomem;
  1100. dbus_connection_send(iface->con, msg, NULL);
  1101. nomem:
  1102. dbus_message_unref(msg);
  1103. }
  1104. /**
  1105. *
  1106. * Method to emit a signal for a peer joining the group.
  1107. * The signal will carry path to the group member object
  1108. * constructed using p2p i/f addr used for connecting.
  1109. *
  1110. * @wpa_s: %wpa_supplicant network interface data
  1111. * @member_addr: addr (p2p i/f) of the peer joining the group
  1112. */
  1113. void wpas_dbus_signal_p2p_peer_joined(struct wpa_supplicant *wpa_s,
  1114. const u8 *member)
  1115. {
  1116. struct wpas_dbus_priv *iface;
  1117. DBusMessage *msg;
  1118. DBusMessageIter iter;
  1119. char groupmember_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  1120. iface = wpa_s->global->dbus;
  1121. /* Do nothing if the control interface is not turned on */
  1122. if (iface == NULL)
  1123. return;
  1124. if (!wpa_s->dbus_groupobj_path)
  1125. return;
  1126. os_snprintf(groupmember_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1127. "%s/" WPAS_DBUS_NEW_P2P_GROUPMEMBERS_PART "/"
  1128. COMPACT_MACSTR,
  1129. wpa_s->dbus_groupobj_path, MAC2STR(member));
  1130. msg = dbus_message_new_signal(wpa_s->dbus_groupobj_path,
  1131. WPAS_DBUS_NEW_IFACE_P2P_GROUP,
  1132. "PeerJoined");
  1133. if (msg == NULL)
  1134. return;
  1135. dbus_message_iter_init_append(msg, &iter);
  1136. path = groupmember_obj_path;
  1137. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  1138. &path))
  1139. goto err;
  1140. dbus_connection_send(iface->con, msg, NULL);
  1141. dbus_message_unref(msg);
  1142. return;
  1143. err:
  1144. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1145. dbus_message_unref(msg);
  1146. }
  1147. /**
  1148. *
  1149. * Method to emit a signal for a peer disconnecting the group.
  1150. * The signal will carry path to the group member object
  1151. * constructed using p2p i/f addr used for connecting.
  1152. *
  1153. * @wpa_s: %wpa_supplicant network interface data
  1154. * @member_addr: addr (p2p i/f) of the peer joining the group
  1155. */
  1156. void wpas_dbus_signal_p2p_peer_disconnected(struct wpa_supplicant *wpa_s,
  1157. const u8 *member)
  1158. {
  1159. struct wpas_dbus_priv *iface;
  1160. DBusMessage *msg;
  1161. DBusMessageIter iter;
  1162. char groupmember_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  1163. iface = wpa_s->global->dbus;
  1164. /* Do nothing if the control interface is not turned on */
  1165. if (iface == NULL)
  1166. return;
  1167. if (!wpa_s->dbus_groupobj_path)
  1168. return;
  1169. os_snprintf(groupmember_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1170. "%s/" WPAS_DBUS_NEW_P2P_GROUPMEMBERS_PART "/"
  1171. COMPACT_MACSTR,
  1172. wpa_s->dbus_groupobj_path, MAC2STR(member));
  1173. msg = dbus_message_new_signal(wpa_s->dbus_groupobj_path,
  1174. WPAS_DBUS_NEW_IFACE_P2P_GROUP,
  1175. "PeerDisconnected");
  1176. if (msg == NULL)
  1177. return;
  1178. dbus_message_iter_init_append(msg, &iter);
  1179. path = groupmember_obj_path;
  1180. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  1181. &path))
  1182. goto err;
  1183. dbus_connection_send(iface->con, msg, NULL);
  1184. dbus_message_unref(msg);
  1185. return;
  1186. err:
  1187. wpa_printf(MSG_ERROR, "dbus: Failed to construct PeerDisconnected "
  1188. "signal");
  1189. dbus_message_unref(msg);
  1190. }
  1191. /**
  1192. *
  1193. * Method to emit a signal for a service discovery request.
  1194. * The signal will carry station address, frequency, dialog token,
  1195. * update indicator and it tlvs
  1196. *
  1197. * @wpa_s: %wpa_supplicant network interface data
  1198. * @sa: station addr (p2p i/f) of the peer
  1199. * @dialog_token: service discovery request dialog token
  1200. * @update_indic: service discovery request update indicator
  1201. * @tlvs: service discovery request genrated byte array of tlvs
  1202. * @tlvs_len: service discovery request tlvs length
  1203. */
  1204. void wpas_dbus_signal_p2p_sd_request(struct wpa_supplicant *wpa_s,
  1205. int freq, const u8 *sa, u8 dialog_token,
  1206. u16 update_indic, const u8 *tlvs,
  1207. size_t tlvs_len)
  1208. {
  1209. DBusMessage *msg;
  1210. DBusMessageIter iter, dict_iter;
  1211. struct wpas_dbus_priv *iface;
  1212. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  1213. iface = wpa_s->global->dbus;
  1214. /* Do nothing if the control interface is not turned on */
  1215. if (iface == NULL)
  1216. return;
  1217. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1218. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1219. "ServiceDiscoveryRequest");
  1220. if (msg == NULL)
  1221. return;
  1222. /* Check if this is a known peer */
  1223. if (!p2p_peer_known(wpa_s->global->p2p, sa))
  1224. goto error;
  1225. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1226. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
  1227. COMPACT_MACSTR, wpa_s->dbus_new_path, MAC2STR(sa));
  1228. path = peer_obj_path;
  1229. dbus_message_iter_init_append(msg, &iter);
  1230. if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
  1231. goto error;
  1232. if (!wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
  1233. path) ||
  1234. !wpa_dbus_dict_append_int32(&dict_iter, "frequency", freq) ||
  1235. !wpa_dbus_dict_append_int32(&dict_iter, "dialog_token",
  1236. dialog_token) ||
  1237. !wpa_dbus_dict_append_uint16(&dict_iter, "update_indicator",
  1238. update_indic) ||
  1239. !wpa_dbus_dict_append_byte_array(&dict_iter, "tlvs",
  1240. (const char *) tlvs,
  1241. tlvs_len) ||
  1242. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  1243. goto error;
  1244. dbus_connection_send(iface->con, msg, NULL);
  1245. dbus_message_unref(msg);
  1246. return;
  1247. error:
  1248. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1249. dbus_message_unref(msg);
  1250. }
  1251. /**
  1252. *
  1253. * Method to emit a signal for a service discovery response.
  1254. * The signal will carry station address, update indicator and it
  1255. * tlvs
  1256. *
  1257. * @wpa_s: %wpa_supplicant network interface data
  1258. * @sa: station addr (p2p i/f) of the peer
  1259. * @update_indic: service discovery request update indicator
  1260. * @tlvs: service discovery request genrated byte array of tlvs
  1261. * @tlvs_len: service discovery request tlvs length
  1262. */
  1263. void wpas_dbus_signal_p2p_sd_response(struct wpa_supplicant *wpa_s,
  1264. const u8 *sa, u16 update_indic,
  1265. const u8 *tlvs, size_t tlvs_len)
  1266. {
  1267. DBusMessage *msg;
  1268. DBusMessageIter iter, dict_iter;
  1269. struct wpas_dbus_priv *iface;
  1270. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  1271. iface = wpa_s->global->dbus;
  1272. /* Do nothing if the control interface is not turned on */
  1273. if (iface == NULL)
  1274. return;
  1275. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1276. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1277. "ServiceDiscoveryResponse");
  1278. if (msg == NULL)
  1279. return;
  1280. /* Check if this is a known peer */
  1281. if (!p2p_peer_known(wpa_s->global->p2p, sa))
  1282. goto error;
  1283. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1284. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
  1285. COMPACT_MACSTR, wpa_s->dbus_new_path, MAC2STR(sa));
  1286. path = peer_obj_path;
  1287. dbus_message_iter_init_append(msg, &iter);
  1288. if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
  1289. goto error;
  1290. if (!wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
  1291. path) ||
  1292. !wpa_dbus_dict_append_uint16(&dict_iter, "update_indicator",
  1293. update_indic) ||
  1294. !wpa_dbus_dict_append_byte_array(&dict_iter, "tlvs",
  1295. (const char *) tlvs,
  1296. tlvs_len) ||
  1297. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  1298. goto error;
  1299. dbus_connection_send(iface->con, msg, NULL);
  1300. dbus_message_unref(msg);
  1301. return;
  1302. error:
  1303. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1304. dbus_message_unref(msg);
  1305. }
  1306. /**
  1307. * wpas_dbus_signal_persistent_group - Send a persistent group related
  1308. * event signal
  1309. * @wpa_s: %wpa_supplicant network interface data
  1310. * @id: new persistent group id
  1311. * @sig_name: signal name - PersistentGroupAdded, PersistentGroupRemoved
  1312. * @properties: determines if add second argument with object properties
  1313. *
  1314. * Notify listeners about an event related to persistent groups.
  1315. */
  1316. static void wpas_dbus_signal_persistent_group(struct wpa_supplicant *wpa_s,
  1317. int id, const char *sig_name,
  1318. int properties)
  1319. {
  1320. struct wpas_dbus_priv *iface;
  1321. DBusMessage *msg;
  1322. DBusMessageIter iter;
  1323. char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  1324. iface = wpa_s->global->dbus;
  1325. /* Do nothing if the control interface is not turned on */
  1326. if (iface == NULL)
  1327. return;
  1328. os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1329. "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
  1330. wpa_s->dbus_new_path, id);
  1331. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1332. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1333. sig_name);
  1334. if (msg == NULL)
  1335. return;
  1336. dbus_message_iter_init_append(msg, &iter);
  1337. path = pgrp_obj_path;
  1338. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  1339. &path))
  1340. goto err;
  1341. if (properties) {
  1342. if (!wpa_dbus_get_object_properties(
  1343. iface, pgrp_obj_path,
  1344. WPAS_DBUS_NEW_IFACE_PERSISTENT_GROUP, &iter))
  1345. goto err;
  1346. }
  1347. dbus_connection_send(iface->con, msg, NULL);
  1348. dbus_message_unref(msg);
  1349. return;
  1350. err:
  1351. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1352. dbus_message_unref(msg);
  1353. }
  1354. /**
  1355. * wpas_dbus_signal_persistent_group_added - Send a persistent_group
  1356. * added signal
  1357. * @wpa_s: %wpa_supplicant network interface data
  1358. * @id: new persistent group id
  1359. *
  1360. * Notify listeners about addition of a new persistent group.
  1361. */
  1362. static void wpas_dbus_signal_persistent_group_added(
  1363. struct wpa_supplicant *wpa_s, int id)
  1364. {
  1365. wpas_dbus_signal_persistent_group(wpa_s, id, "PersistentGroupAdded",
  1366. TRUE);
  1367. }
  1368. /**
  1369. * wpas_dbus_signal_persistent_group_removed - Send a persistent_group
  1370. * removed signal
  1371. * @wpa_s: %wpa_supplicant network interface data
  1372. * @id: persistent group id
  1373. *
  1374. * Notify listeners about removal of a persistent group.
  1375. */
  1376. static void wpas_dbus_signal_persistent_group_removed(
  1377. struct wpa_supplicant *wpa_s, int id)
  1378. {
  1379. wpas_dbus_signal_persistent_group(wpa_s, id, "PersistentGroupRemoved",
  1380. FALSE);
  1381. }
  1382. /**
  1383. * wpas_dbus_signal_p2p_wps_failed - Signals WpsFailed event
  1384. * @wpa_s: %wpa_supplicant network interface data
  1385. *
  1386. * Sends Event dbus signal with name "fail" and dictionary containing
  1387. * "msg" field with fail message number (int32) as arguments
  1388. */
  1389. void wpas_dbus_signal_p2p_wps_failed(struct wpa_supplicant *wpa_s,
  1390. struct wps_event_fail *fail)
  1391. {
  1392. DBusMessage *msg;
  1393. DBusMessageIter iter, dict_iter;
  1394. struct wpas_dbus_priv *iface;
  1395. char *key = "fail";
  1396. iface = wpa_s->global->dbus;
  1397. /* Do nothing if the control interface is not turned on */
  1398. if (iface == NULL)
  1399. return;
  1400. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1401. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1402. "WpsFailed");
  1403. if (msg == NULL)
  1404. return;
  1405. dbus_message_iter_init_append(msg, &iter);
  1406. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
  1407. !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  1408. !wpa_dbus_dict_append_int32(&dict_iter, "msg", fail->msg) ||
  1409. !wpa_dbus_dict_append_int16(&dict_iter, "config_error",
  1410. fail->config_error) ||
  1411. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  1412. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1413. else
  1414. dbus_connection_send(iface->con, msg, NULL);
  1415. dbus_message_unref(msg);
  1416. }
  1417. #endif /*CONFIG_P2P*/
  1418. /**
  1419. * wpas_dbus_signal_prop_changed - Signals change of property
  1420. * @wpa_s: %wpa_supplicant network interface data
  1421. * @property: indicates which property has changed
  1422. *
  1423. * Sends PropertyChanged signals with path, interface and arguments
  1424. * depending on which property has changed.
  1425. */
  1426. void wpas_dbus_signal_prop_changed(struct wpa_supplicant *wpa_s,
  1427. enum wpas_dbus_prop property)
  1428. {
  1429. char *prop;
  1430. dbus_bool_t flush;
  1431. if (wpa_s->dbus_new_path == NULL)
  1432. return; /* Skip signal since D-Bus setup is not yet ready */
  1433. flush = FALSE;
  1434. switch (property) {
  1435. case WPAS_DBUS_PROP_AP_SCAN:
  1436. prop = "ApScan";
  1437. break;
  1438. case WPAS_DBUS_PROP_SCANNING:
  1439. prop = "Scanning";
  1440. break;
  1441. case WPAS_DBUS_PROP_STATE:
  1442. prop = "State";
  1443. break;
  1444. case WPAS_DBUS_PROP_CURRENT_BSS:
  1445. prop = "CurrentBSS";
  1446. break;
  1447. case WPAS_DBUS_PROP_CURRENT_NETWORK:
  1448. prop = "CurrentNetwork";
  1449. break;
  1450. case WPAS_DBUS_PROP_BSSS:
  1451. prop = "BSSs";
  1452. break;
  1453. case WPAS_DBUS_PROP_CURRENT_AUTH_MODE:
  1454. prop = "CurrentAuthMode";
  1455. break;
  1456. case WPAS_DBUS_PROP_DISCONNECT_REASON:
  1457. prop = "DisconnectReason";
  1458. flush = TRUE;
  1459. break;
  1460. default:
  1461. wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
  1462. __func__, property);
  1463. return;
  1464. }
  1465. wpa_dbus_mark_property_changed(wpa_s->global->dbus,
  1466. wpa_s->dbus_new_path,
  1467. WPAS_DBUS_NEW_IFACE_INTERFACE, prop);
  1468. if (flush) {
  1469. wpa_dbus_flush_object_changed_properties(
  1470. wpa_s->global->dbus->con, wpa_s->dbus_new_path);
  1471. }
  1472. }
  1473. /**
  1474. * wpas_dbus_bss_signal_prop_changed - Signals change of BSS property
  1475. * @wpa_s: %wpa_supplicant network interface data
  1476. * @property: indicates which property has changed
  1477. * @id: unique BSS identifier
  1478. *
  1479. * Sends PropertyChanged signals with path, interface, and arguments depending
  1480. * on which property has changed.
  1481. */
  1482. void wpas_dbus_bss_signal_prop_changed(struct wpa_supplicant *wpa_s,
  1483. enum wpas_dbus_bss_prop property,
  1484. unsigned int id)
  1485. {
  1486. char path[WPAS_DBUS_OBJECT_PATH_MAX];
  1487. char *prop;
  1488. switch (property) {
  1489. case WPAS_DBUS_BSS_PROP_SIGNAL:
  1490. prop = "Signal";
  1491. break;
  1492. case WPAS_DBUS_BSS_PROP_FREQ:
  1493. prop = "Frequency";
  1494. break;
  1495. case WPAS_DBUS_BSS_PROP_MODE:
  1496. prop = "Mode";
  1497. break;
  1498. case WPAS_DBUS_BSS_PROP_PRIVACY:
  1499. prop = "Privacy";
  1500. break;
  1501. case WPAS_DBUS_BSS_PROP_RATES:
  1502. prop = "Rates";
  1503. break;
  1504. case WPAS_DBUS_BSS_PROP_WPA:
  1505. prop = "WPA";
  1506. break;
  1507. case WPAS_DBUS_BSS_PROP_RSN:
  1508. prop = "RSN";
  1509. break;
  1510. case WPAS_DBUS_BSS_PROP_IES:
  1511. prop = "IEs";
  1512. break;
  1513. default:
  1514. wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
  1515. __func__, property);
  1516. return;
  1517. }
  1518. os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
  1519. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  1520. wpa_s->dbus_new_path, id);
  1521. wpa_dbus_mark_property_changed(wpa_s->global->dbus, path,
  1522. WPAS_DBUS_NEW_IFACE_BSS, prop);
  1523. }
  1524. /**
  1525. * wpas_dbus_signal_debug_level_changed - Signals change of debug param
  1526. * @global: wpa_global structure
  1527. *
  1528. * Sends PropertyChanged signals informing that debug level has changed.
  1529. */
  1530. void wpas_dbus_signal_debug_level_changed(struct wpa_global *global)
  1531. {
  1532. wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
  1533. WPAS_DBUS_NEW_INTERFACE,
  1534. "DebugLevel");
  1535. }
  1536. /**
  1537. * wpas_dbus_signal_debug_timestamp_changed - Signals change of debug param
  1538. * @global: wpa_global structure
  1539. *
  1540. * Sends PropertyChanged signals informing that debug timestamp has changed.
  1541. */
  1542. void wpas_dbus_signal_debug_timestamp_changed(struct wpa_global *global)
  1543. {
  1544. wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
  1545. WPAS_DBUS_NEW_INTERFACE,
  1546. "DebugTimestamp");
  1547. }
  1548. /**
  1549. * wpas_dbus_signal_debug_show_keys_changed - Signals change of debug param
  1550. * @global: wpa_global structure
  1551. *
  1552. * Sends PropertyChanged signals informing that debug show_keys has changed.
  1553. */
  1554. void wpas_dbus_signal_debug_show_keys_changed(struct wpa_global *global)
  1555. {
  1556. wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
  1557. WPAS_DBUS_NEW_INTERFACE,
  1558. "DebugShowKeys");
  1559. }
  1560. static void wpas_dbus_register(struct wpa_dbus_object_desc *obj_desc,
  1561. void *priv,
  1562. WPADBusArgumentFreeFunction priv_free,
  1563. const struct wpa_dbus_method_desc *methods,
  1564. const struct wpa_dbus_property_desc *properties,
  1565. const struct wpa_dbus_signal_desc *signals)
  1566. {
  1567. int n;
  1568. obj_desc->user_data = priv;
  1569. obj_desc->user_data_free_func = priv_free;
  1570. obj_desc->methods = methods;
  1571. obj_desc->properties = properties;
  1572. obj_desc->signals = signals;
  1573. for (n = 0; properties && properties->dbus_property; properties++)
  1574. n++;
  1575. obj_desc->prop_changed_flags = os_zalloc(n);
  1576. if (!obj_desc->prop_changed_flags)
  1577. wpa_printf(MSG_DEBUG, "dbus: %s: can't register handlers",
  1578. __func__);
  1579. }
  1580. static const struct wpa_dbus_method_desc wpas_dbus_global_methods[] = {
  1581. { "CreateInterface", WPAS_DBUS_NEW_INTERFACE,
  1582. (WPADBusMethodHandler) &wpas_dbus_handler_create_interface,
  1583. {
  1584. { "args", "a{sv}", ARG_IN },
  1585. { "path", "o", ARG_OUT },
  1586. END_ARGS
  1587. }
  1588. },
  1589. { "RemoveInterface", WPAS_DBUS_NEW_INTERFACE,
  1590. (WPADBusMethodHandler) &wpas_dbus_handler_remove_interface,
  1591. {
  1592. { "path", "o", ARG_IN },
  1593. END_ARGS
  1594. }
  1595. },
  1596. { "GetInterface", WPAS_DBUS_NEW_INTERFACE,
  1597. (WPADBusMethodHandler) &wpas_dbus_handler_get_interface,
  1598. {
  1599. { "ifname", "s", ARG_IN },
  1600. { "path", "o", ARG_OUT },
  1601. END_ARGS
  1602. }
  1603. },
  1604. #ifdef CONFIG_AUTOSCAN
  1605. { "AutoScan", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1606. (WPADBusMethodHandler) &wpas_dbus_handler_autoscan,
  1607. {
  1608. { "arg", "s", ARG_IN },
  1609. END_ARGS
  1610. }
  1611. },
  1612. #endif /* CONFIG_AUTOSCAN */
  1613. { NULL, NULL, NULL, { END_ARGS } }
  1614. };
  1615. static const struct wpa_dbus_property_desc wpas_dbus_global_properties[] = {
  1616. { "DebugLevel", WPAS_DBUS_NEW_INTERFACE, "s",
  1617. wpas_dbus_getter_debug_level,
  1618. wpas_dbus_setter_debug_level
  1619. },
  1620. { "DebugTimestamp", WPAS_DBUS_NEW_INTERFACE, "b",
  1621. wpas_dbus_getter_debug_timestamp,
  1622. wpas_dbus_setter_debug_timestamp
  1623. },
  1624. { "DebugShowKeys", WPAS_DBUS_NEW_INTERFACE, "b",
  1625. wpas_dbus_getter_debug_show_keys,
  1626. wpas_dbus_setter_debug_show_keys
  1627. },
  1628. { "Interfaces", WPAS_DBUS_NEW_INTERFACE, "ao",
  1629. wpas_dbus_getter_interfaces,
  1630. NULL
  1631. },
  1632. { "EapMethods", WPAS_DBUS_NEW_INTERFACE, "as",
  1633. wpas_dbus_getter_eap_methods,
  1634. NULL
  1635. },
  1636. { NULL, NULL, NULL, NULL, NULL }
  1637. };
  1638. static const struct wpa_dbus_signal_desc wpas_dbus_global_signals[] = {
  1639. { "InterfaceAdded", WPAS_DBUS_NEW_INTERFACE,
  1640. {
  1641. { "path", "o", ARG_OUT },
  1642. { "properties", "a{sv}", ARG_OUT },
  1643. END_ARGS
  1644. }
  1645. },
  1646. { "InterfaceRemoved", WPAS_DBUS_NEW_INTERFACE,
  1647. {
  1648. { "path", "o", ARG_OUT },
  1649. END_ARGS
  1650. }
  1651. },
  1652. { "NetworkRequest", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1653. {
  1654. { "path", "o", ARG_OUT },
  1655. { "field", "s", ARG_OUT },
  1656. { "text", "s", ARG_OUT },
  1657. END_ARGS
  1658. }
  1659. },
  1660. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  1661. { "PropertiesChanged", WPAS_DBUS_NEW_INTERFACE,
  1662. {
  1663. { "properties", "a{sv}", ARG_OUT },
  1664. END_ARGS
  1665. }
  1666. },
  1667. { NULL, NULL, { END_ARGS } }
  1668. };
  1669. /**
  1670. * wpas_dbus_ctrl_iface_init - Initialize dbus control interface
  1671. * @global: Pointer to global data from wpa_supplicant_init()
  1672. * Returns: 0 on success or -1 on failure
  1673. *
  1674. * Initialize the dbus control interface for wpa_supplicantand and start
  1675. * receiving commands from external programs over the bus.
  1676. */
  1677. int wpas_dbus_ctrl_iface_init(struct wpas_dbus_priv *priv)
  1678. {
  1679. struct wpa_dbus_object_desc *obj_desc;
  1680. int ret;
  1681. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  1682. if (!obj_desc) {
  1683. wpa_printf(MSG_ERROR, "Not enough memory "
  1684. "to create object description");
  1685. return -1;
  1686. }
  1687. wpas_dbus_register(obj_desc, priv->global, NULL,
  1688. wpas_dbus_global_methods,
  1689. wpas_dbus_global_properties,
  1690. wpas_dbus_global_signals);
  1691. wpa_printf(MSG_DEBUG, "dbus: Register D-Bus object '%s'",
  1692. WPAS_DBUS_NEW_PATH);
  1693. ret = wpa_dbus_ctrl_iface_init(priv, WPAS_DBUS_NEW_PATH,
  1694. WPAS_DBUS_NEW_SERVICE,
  1695. obj_desc);
  1696. if (ret < 0)
  1697. free_dbus_object_desc(obj_desc);
  1698. else
  1699. priv->dbus_new_initialized = 1;
  1700. return ret;
  1701. }
  1702. /**
  1703. * wpas_dbus_ctrl_iface_deinit - Deinitialize dbus ctrl interface for
  1704. * wpa_supplicant
  1705. * @iface: Pointer to dbus private data from wpas_dbus_init()
  1706. *
  1707. * Deinitialize the dbus control interface that was initialized with
  1708. * wpas_dbus_ctrl_iface_init().
  1709. */
  1710. void wpas_dbus_ctrl_iface_deinit(struct wpas_dbus_priv *iface)
  1711. {
  1712. if (!iface->dbus_new_initialized)
  1713. return;
  1714. wpa_printf(MSG_DEBUG, "dbus: Unregister D-Bus object '%s'",
  1715. WPAS_DBUS_NEW_PATH);
  1716. dbus_connection_unregister_object_path(iface->con,
  1717. WPAS_DBUS_NEW_PATH);
  1718. }
  1719. static void wpa_dbus_free(void *ptr)
  1720. {
  1721. os_free(ptr);
  1722. }
  1723. static const struct wpa_dbus_property_desc wpas_dbus_network_properties[] = {
  1724. { "Properties", WPAS_DBUS_NEW_IFACE_NETWORK, "a{sv}",
  1725. wpas_dbus_getter_network_properties,
  1726. wpas_dbus_setter_network_properties
  1727. },
  1728. { "Enabled", WPAS_DBUS_NEW_IFACE_NETWORK, "b",
  1729. wpas_dbus_getter_enabled,
  1730. wpas_dbus_setter_enabled
  1731. },
  1732. { NULL, NULL, NULL, NULL, NULL }
  1733. };
  1734. static const struct wpa_dbus_signal_desc wpas_dbus_network_signals[] = {
  1735. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  1736. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_NETWORK,
  1737. {
  1738. { "properties", "a{sv}", ARG_OUT },
  1739. END_ARGS
  1740. }
  1741. },
  1742. { NULL, NULL, { END_ARGS } }
  1743. };
  1744. /**
  1745. * wpas_dbus_register_network - Register a configured network with dbus
  1746. * @wpa_s: wpa_supplicant interface structure
  1747. * @ssid: network configuration data
  1748. * Returns: 0 on success, -1 on failure
  1749. *
  1750. * Registers network representing object with dbus
  1751. */
  1752. int wpas_dbus_register_network(struct wpa_supplicant *wpa_s,
  1753. struct wpa_ssid *ssid)
  1754. {
  1755. struct wpas_dbus_priv *ctrl_iface;
  1756. struct wpa_dbus_object_desc *obj_desc;
  1757. struct network_handler_args *arg;
  1758. char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  1759. #ifdef CONFIG_P2P
  1760. /*
  1761. * If it is a persistent group register it as such.
  1762. * This is to handle cases where an interface is being initialized
  1763. * with a list of networks read from config.
  1764. */
  1765. if (network_is_persistent_group(ssid))
  1766. return wpas_dbus_register_persistent_group(wpa_s, ssid);
  1767. #endif /* CONFIG_P2P */
  1768. /* Do nothing if the control interface is not turned on */
  1769. if (wpa_s == NULL || wpa_s->global == NULL)
  1770. return 0;
  1771. ctrl_iface = wpa_s->global->dbus;
  1772. if (ctrl_iface == NULL)
  1773. return 0;
  1774. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1775. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  1776. wpa_s->dbus_new_path, ssid->id);
  1777. wpa_printf(MSG_DEBUG, "dbus: Register network object '%s'",
  1778. net_obj_path);
  1779. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  1780. if (!obj_desc) {
  1781. wpa_printf(MSG_ERROR, "Not enough memory "
  1782. "to create object description");
  1783. goto err;
  1784. }
  1785. /* allocate memory for handlers arguments */
  1786. arg = os_zalloc(sizeof(struct network_handler_args));
  1787. if (!arg) {
  1788. wpa_printf(MSG_ERROR, "Not enough memory "
  1789. "to create arguments for method");
  1790. goto err;
  1791. }
  1792. arg->wpa_s = wpa_s;
  1793. arg->ssid = ssid;
  1794. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  1795. wpas_dbus_network_properties,
  1796. wpas_dbus_network_signals);
  1797. if (wpa_dbus_register_object_per_iface(ctrl_iface, net_obj_path,
  1798. wpa_s->ifname, obj_desc))
  1799. goto err;
  1800. wpas_dbus_signal_network_added(wpa_s, ssid->id);
  1801. return 0;
  1802. err:
  1803. free_dbus_object_desc(obj_desc);
  1804. return -1;
  1805. }
  1806. /**
  1807. * wpas_dbus_unregister_network - Unregister a configured network from dbus
  1808. * @wpa_s: wpa_supplicant interface structure
  1809. * @nid: network id
  1810. * Returns: 0 on success, -1 on failure
  1811. *
  1812. * Unregisters network representing object from dbus
  1813. */
  1814. int wpas_dbus_unregister_network(struct wpa_supplicant *wpa_s, int nid)
  1815. {
  1816. struct wpas_dbus_priv *ctrl_iface;
  1817. char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  1818. int ret;
  1819. #ifdef CONFIG_P2P
  1820. struct wpa_ssid *ssid;
  1821. ssid = wpa_config_get_network(wpa_s->conf, nid);
  1822. /* If it is a persistent group unregister it as such */
  1823. if (ssid && network_is_persistent_group(ssid))
  1824. return wpas_dbus_unregister_persistent_group(wpa_s, nid);
  1825. #endif /* CONFIG_P2P */
  1826. /* Do nothing if the control interface is not turned on */
  1827. if (wpa_s->global == NULL || wpa_s->dbus_new_path == NULL)
  1828. return 0;
  1829. ctrl_iface = wpa_s->global->dbus;
  1830. if (ctrl_iface == NULL)
  1831. return 0;
  1832. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1833. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  1834. wpa_s->dbus_new_path, nid);
  1835. wpa_printf(MSG_DEBUG, "dbus: Unregister network object '%s'",
  1836. net_obj_path);
  1837. ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, net_obj_path);
  1838. if (!ret)
  1839. wpas_dbus_signal_network_removed(wpa_s, nid);
  1840. return ret;
  1841. }
  1842. static const struct wpa_dbus_property_desc wpas_dbus_bss_properties[] = {
  1843. { "SSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
  1844. wpas_dbus_getter_bss_ssid,
  1845. NULL
  1846. },
  1847. { "BSSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
  1848. wpas_dbus_getter_bss_bssid,
  1849. NULL
  1850. },
  1851. { "Privacy", WPAS_DBUS_NEW_IFACE_BSS, "b",
  1852. wpas_dbus_getter_bss_privacy,
  1853. NULL
  1854. },
  1855. { "Mode", WPAS_DBUS_NEW_IFACE_BSS, "s",
  1856. wpas_dbus_getter_bss_mode,
  1857. NULL
  1858. },
  1859. { "Signal", WPAS_DBUS_NEW_IFACE_BSS, "n",
  1860. wpas_dbus_getter_bss_signal,
  1861. NULL
  1862. },
  1863. { "Frequency", WPAS_DBUS_NEW_IFACE_BSS, "q",
  1864. wpas_dbus_getter_bss_frequency,
  1865. NULL
  1866. },
  1867. { "Rates", WPAS_DBUS_NEW_IFACE_BSS, "au",
  1868. wpas_dbus_getter_bss_rates,
  1869. NULL
  1870. },
  1871. { "WPA", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
  1872. wpas_dbus_getter_bss_wpa,
  1873. NULL
  1874. },
  1875. { "RSN", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
  1876. wpas_dbus_getter_bss_rsn,
  1877. NULL
  1878. },
  1879. { "IEs", WPAS_DBUS_NEW_IFACE_BSS, "ay",
  1880. wpas_dbus_getter_bss_ies,
  1881. NULL
  1882. },
  1883. { NULL, NULL, NULL, NULL, NULL }
  1884. };
  1885. static const struct wpa_dbus_signal_desc wpas_dbus_bss_signals[] = {
  1886. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  1887. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_BSS,
  1888. {
  1889. { "properties", "a{sv}", ARG_OUT },
  1890. END_ARGS
  1891. }
  1892. },
  1893. { NULL, NULL, { END_ARGS } }
  1894. };
  1895. /**
  1896. * wpas_dbus_unregister_bss - Unregister a scanned BSS from dbus
  1897. * @wpa_s: wpa_supplicant interface structure
  1898. * @bssid: scanned network bssid
  1899. * @id: unique BSS identifier
  1900. * Returns: 0 on success, -1 on failure
  1901. *
  1902. * Unregisters BSS representing object from dbus
  1903. */
  1904. int wpas_dbus_unregister_bss(struct wpa_supplicant *wpa_s,
  1905. u8 bssid[ETH_ALEN], unsigned int id)
  1906. {
  1907. struct wpas_dbus_priv *ctrl_iface;
  1908. char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  1909. /* Do nothing if the control interface is not turned on */
  1910. if (wpa_s == NULL || wpa_s->global == NULL)
  1911. return 0;
  1912. ctrl_iface = wpa_s->global->dbus;
  1913. if (ctrl_iface == NULL)
  1914. return 0;
  1915. os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1916. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  1917. wpa_s->dbus_new_path, id);
  1918. wpa_printf(MSG_DEBUG, "dbus: Unregister BSS object '%s'",
  1919. bss_obj_path);
  1920. if (wpa_dbus_unregister_object_per_iface(ctrl_iface, bss_obj_path)) {
  1921. wpa_printf(MSG_ERROR, "dbus: Cannot unregister BSS object %s",
  1922. bss_obj_path);
  1923. return -1;
  1924. }
  1925. wpas_dbus_signal_bss_removed(wpa_s, bss_obj_path);
  1926. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSSS);
  1927. return 0;
  1928. }
  1929. /**
  1930. * wpas_dbus_register_bss - Register a scanned BSS with dbus
  1931. * @wpa_s: wpa_supplicant interface structure
  1932. * @bssid: scanned network bssid
  1933. * @id: unique BSS identifier
  1934. * Returns: 0 on success, -1 on failure
  1935. *
  1936. * Registers BSS representing object with dbus
  1937. */
  1938. int wpas_dbus_register_bss(struct wpa_supplicant *wpa_s,
  1939. u8 bssid[ETH_ALEN], unsigned int id)
  1940. {
  1941. struct wpas_dbus_priv *ctrl_iface;
  1942. struct wpa_dbus_object_desc *obj_desc;
  1943. char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  1944. struct bss_handler_args *arg;
  1945. /* Do nothing if the control interface is not turned on */
  1946. if (wpa_s == NULL || wpa_s->global == NULL)
  1947. return 0;
  1948. ctrl_iface = wpa_s->global->dbus;
  1949. if (ctrl_iface == NULL)
  1950. return 0;
  1951. os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1952. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  1953. wpa_s->dbus_new_path, id);
  1954. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  1955. if (!obj_desc) {
  1956. wpa_printf(MSG_ERROR, "Not enough memory "
  1957. "to create object description");
  1958. goto err;
  1959. }
  1960. arg = os_zalloc(sizeof(struct bss_handler_args));
  1961. if (!arg) {
  1962. wpa_printf(MSG_ERROR, "Not enough memory "
  1963. "to create arguments for handler");
  1964. goto err;
  1965. }
  1966. arg->wpa_s = wpa_s;
  1967. arg->id = id;
  1968. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  1969. wpas_dbus_bss_properties,
  1970. wpas_dbus_bss_signals);
  1971. wpa_printf(MSG_DEBUG, "dbus: Register BSS object '%s'",
  1972. bss_obj_path);
  1973. if (wpa_dbus_register_object_per_iface(ctrl_iface, bss_obj_path,
  1974. wpa_s->ifname, obj_desc)) {
  1975. wpa_printf(MSG_ERROR,
  1976. "Cannot register BSSID dbus object %s.",
  1977. bss_obj_path);
  1978. goto err;
  1979. }
  1980. wpas_dbus_signal_bss_added(wpa_s, bss_obj_path);
  1981. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSSS);
  1982. return 0;
  1983. err:
  1984. free_dbus_object_desc(obj_desc);
  1985. return -1;
  1986. }
  1987. static const struct wpa_dbus_method_desc wpas_dbus_interface_methods[] = {
  1988. { "Scan", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1989. (WPADBusMethodHandler) &wpas_dbus_handler_scan,
  1990. {
  1991. { "args", "a{sv}", ARG_IN },
  1992. END_ARGS
  1993. }
  1994. },
  1995. { "Disconnect", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1996. (WPADBusMethodHandler) &wpas_dbus_handler_disconnect,
  1997. {
  1998. END_ARGS
  1999. }
  2000. },
  2001. { "AddNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2002. (WPADBusMethodHandler) &wpas_dbus_handler_add_network,
  2003. {
  2004. { "args", "a{sv}", ARG_IN },
  2005. { "path", "o", ARG_OUT },
  2006. END_ARGS
  2007. }
  2008. },
  2009. { "RemoveNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2010. (WPADBusMethodHandler) &wpas_dbus_handler_remove_network,
  2011. {
  2012. { "path", "o", ARG_IN },
  2013. END_ARGS
  2014. }
  2015. },
  2016. { "RemoveAllNetworks", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2017. (WPADBusMethodHandler) &wpas_dbus_handler_remove_all_networks,
  2018. {
  2019. END_ARGS
  2020. }
  2021. },
  2022. { "SelectNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2023. (WPADBusMethodHandler) &wpas_dbus_handler_select_network,
  2024. {
  2025. { "path", "o", ARG_IN },
  2026. END_ARGS
  2027. }
  2028. },
  2029. { "NetworkReply", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2030. (WPADBusMethodHandler) &wpas_dbus_handler_network_reply,
  2031. {
  2032. { "path", "o", ARG_IN },
  2033. { "field", "s", ARG_IN },
  2034. { "value", "s", ARG_IN },
  2035. END_ARGS
  2036. }
  2037. },
  2038. { "AddBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2039. (WPADBusMethodHandler) &wpas_dbus_handler_add_blob,
  2040. {
  2041. { "name", "s", ARG_IN },
  2042. { "data", "ay", ARG_IN },
  2043. END_ARGS
  2044. }
  2045. },
  2046. { "GetBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2047. (WPADBusMethodHandler) &wpas_dbus_handler_get_blob,
  2048. {
  2049. { "name", "s", ARG_IN },
  2050. { "data", "ay", ARG_OUT },
  2051. END_ARGS
  2052. }
  2053. },
  2054. { "RemoveBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2055. (WPADBusMethodHandler) &wpas_dbus_handler_remove_blob,
  2056. {
  2057. { "name", "s", ARG_IN },
  2058. END_ARGS
  2059. }
  2060. },
  2061. #ifdef CONFIG_WPS
  2062. { "Start", WPAS_DBUS_NEW_IFACE_WPS,
  2063. (WPADBusMethodHandler) &wpas_dbus_handler_wps_start,
  2064. {
  2065. { "args", "a{sv}", ARG_IN },
  2066. { "output", "a{sv}", ARG_OUT },
  2067. END_ARGS
  2068. }
  2069. },
  2070. #endif /* CONFIG_WPS */
  2071. #ifdef CONFIG_P2P
  2072. { "Find", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2073. (WPADBusMethodHandler)wpas_dbus_handler_p2p_find,
  2074. {
  2075. { "args", "a{sv}", ARG_IN },
  2076. END_ARGS
  2077. }
  2078. },
  2079. { "StopFind", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2080. (WPADBusMethodHandler)wpas_dbus_handler_p2p_stop_find,
  2081. {
  2082. END_ARGS
  2083. }
  2084. },
  2085. { "Listen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2086. (WPADBusMethodHandler)wpas_dbus_handler_p2p_listen,
  2087. {
  2088. { "timeout", "i", ARG_IN },
  2089. END_ARGS
  2090. }
  2091. },
  2092. { "ExtendedListen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2093. (WPADBusMethodHandler)wpas_dbus_handler_p2p_extendedlisten,
  2094. {
  2095. { "args", "a{sv}", ARG_IN },
  2096. END_ARGS
  2097. }
  2098. },
  2099. { "PresenceRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2100. (WPADBusMethodHandler)wpas_dbus_handler_p2p_presence_request,
  2101. {
  2102. { "args", "a{sv}", ARG_IN },
  2103. END_ARGS
  2104. }
  2105. },
  2106. { "ProvisionDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2107. (WPADBusMethodHandler)wpas_dbus_handler_p2p_prov_disc_req,
  2108. {
  2109. { "peer", "o", ARG_IN },
  2110. { "config_method", "s", ARG_IN },
  2111. END_ARGS
  2112. }
  2113. },
  2114. { "Connect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2115. (WPADBusMethodHandler)wpas_dbus_handler_p2p_connect,
  2116. {
  2117. { "args", "a{sv}", ARG_IN },
  2118. { "generated_pin", "s", ARG_OUT },
  2119. END_ARGS
  2120. }
  2121. },
  2122. { "GroupAdd", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2123. (WPADBusMethodHandler)wpas_dbus_handler_p2p_group_add,
  2124. {
  2125. { "args", "a{sv}", ARG_IN },
  2126. END_ARGS
  2127. }
  2128. },
  2129. { "Invite", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2130. (WPADBusMethodHandler)wpas_dbus_handler_p2p_invite,
  2131. {
  2132. { "args", "a{sv}", ARG_IN },
  2133. END_ARGS
  2134. }
  2135. },
  2136. { "Disconnect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2137. (WPADBusMethodHandler)wpas_dbus_handler_p2p_disconnect,
  2138. {
  2139. END_ARGS
  2140. }
  2141. },
  2142. { "RejectPeer", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2143. (WPADBusMethodHandler)wpas_dbus_handler_p2p_rejectpeer,
  2144. {
  2145. { "peer", "o", ARG_IN },
  2146. END_ARGS
  2147. }
  2148. },
  2149. { "Flush", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2150. (WPADBusMethodHandler)wpas_dbus_handler_p2p_flush,
  2151. {
  2152. END_ARGS
  2153. }
  2154. },
  2155. { "AddService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2156. (WPADBusMethodHandler)wpas_dbus_handler_p2p_add_service,
  2157. {
  2158. { "args", "a{sv}", ARG_IN },
  2159. END_ARGS
  2160. }
  2161. },
  2162. { "DeleteService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2163. (WPADBusMethodHandler)wpas_dbus_handler_p2p_delete_service,
  2164. {
  2165. { "args", "a{sv}", ARG_IN },
  2166. END_ARGS
  2167. }
  2168. },
  2169. { "FlushService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2170. (WPADBusMethodHandler)wpas_dbus_handler_p2p_flush_service,
  2171. {
  2172. END_ARGS
  2173. }
  2174. },
  2175. { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2176. (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_sd_req,
  2177. {
  2178. { "args", "a{sv}", ARG_IN },
  2179. END_ARGS
  2180. }
  2181. },
  2182. { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2183. (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_sd_res,
  2184. {
  2185. { "args", "a{sv}", ARG_IN },
  2186. END_ARGS
  2187. }
  2188. },
  2189. { "ServiceDiscoveryCancelRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2190. (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_sd_cancel_req,
  2191. {
  2192. { "args", "t", ARG_IN },
  2193. END_ARGS
  2194. }
  2195. },
  2196. { "ServiceUpdate", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2197. (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_update,
  2198. {
  2199. END_ARGS
  2200. }
  2201. },
  2202. { "ServiceDiscoveryExternal", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2203. (WPADBusMethodHandler)wpas_dbus_handler_p2p_serv_disc_external,
  2204. {
  2205. { "arg", "i", ARG_IN },
  2206. END_ARGS
  2207. }
  2208. },
  2209. { "ServiceDiscoveryExternal", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2210. (WPADBusMethodHandler)wpas_dbus_handler_p2p_serv_disc_external,
  2211. {
  2212. { "arg", "i", ARG_IN },
  2213. END_ARGS
  2214. }
  2215. },
  2216. { "AddPersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2217. (WPADBusMethodHandler) wpas_dbus_handler_add_persistent_group,
  2218. {
  2219. { "args", "a{sv}", ARG_IN },
  2220. { "path", "o", ARG_OUT },
  2221. END_ARGS
  2222. }
  2223. },
  2224. { "RemovePersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2225. (WPADBusMethodHandler) wpas_dbus_handler_remove_persistent_group,
  2226. {
  2227. { "path", "o", ARG_IN },
  2228. END_ARGS
  2229. }
  2230. },
  2231. { "RemoveAllPersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2232. (WPADBusMethodHandler)
  2233. wpas_dbus_handler_remove_all_persistent_groups,
  2234. {
  2235. END_ARGS
  2236. }
  2237. },
  2238. #endif /* CONFIG_P2P */
  2239. { "FlushBSS", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2240. (WPADBusMethodHandler) &wpas_dbus_handler_flush_bss,
  2241. {
  2242. { "age", "u", ARG_IN },
  2243. END_ARGS
  2244. }
  2245. },
  2246. #ifdef CONFIG_AP
  2247. { "SubscribeProbeReq", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2248. (WPADBusMethodHandler) wpas_dbus_handler_subscribe_preq,
  2249. {
  2250. END_ARGS
  2251. }
  2252. },
  2253. { "UnsubscribeProbeReq", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2254. (WPADBusMethodHandler) wpas_dbus_handler_unsubscribe_preq,
  2255. {
  2256. END_ARGS
  2257. }
  2258. },
  2259. #endif /* CONFIG_AP */
  2260. { NULL, NULL, NULL, { END_ARGS } }
  2261. };
  2262. static const struct wpa_dbus_property_desc wpas_dbus_interface_properties[] = {
  2263. { "Capabilities", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{sv}",
  2264. wpas_dbus_getter_capabilities,
  2265. NULL
  2266. },
  2267. { "State", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2268. wpas_dbus_getter_state,
  2269. NULL
  2270. },
  2271. { "Scanning", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
  2272. wpas_dbus_getter_scanning,
  2273. NULL
  2274. },
  2275. { "ApScan", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  2276. wpas_dbus_getter_ap_scan,
  2277. wpas_dbus_setter_ap_scan
  2278. },
  2279. { "BSSExpireAge", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  2280. wpas_dbus_getter_bss_expire_age,
  2281. wpas_dbus_setter_bss_expire_age
  2282. },
  2283. { "BSSExpireCount", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  2284. wpas_dbus_getter_bss_expire_count,
  2285. wpas_dbus_setter_bss_expire_count
  2286. },
  2287. { "Country", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2288. wpas_dbus_getter_country,
  2289. wpas_dbus_setter_country
  2290. },
  2291. { "Ifname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2292. wpas_dbus_getter_ifname,
  2293. NULL
  2294. },
  2295. { "Driver", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2296. wpas_dbus_getter_driver,
  2297. NULL
  2298. },
  2299. { "BridgeIfname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2300. wpas_dbus_getter_bridge_ifname,
  2301. NULL
  2302. },
  2303. { "CurrentBSS", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
  2304. wpas_dbus_getter_current_bss,
  2305. NULL
  2306. },
  2307. { "CurrentNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
  2308. wpas_dbus_getter_current_network,
  2309. NULL
  2310. },
  2311. { "CurrentAuthMode", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2312. wpas_dbus_getter_current_auth_mode,
  2313. NULL
  2314. },
  2315. { "Blobs", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{say}",
  2316. wpas_dbus_getter_blobs,
  2317. NULL
  2318. },
  2319. { "BSSs", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
  2320. wpas_dbus_getter_bsss,
  2321. NULL
  2322. },
  2323. { "Networks", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
  2324. wpas_dbus_getter_networks,
  2325. NULL
  2326. },
  2327. { "FastReauth", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
  2328. wpas_dbus_getter_fast_reauth,
  2329. wpas_dbus_setter_fast_reauth
  2330. },
  2331. { "ScanInterval", WPAS_DBUS_NEW_IFACE_INTERFACE, "i",
  2332. wpas_dbus_getter_scan_interval,
  2333. wpas_dbus_setter_scan_interval
  2334. },
  2335. #ifdef CONFIG_WPS
  2336. { "ProcessCredentials", WPAS_DBUS_NEW_IFACE_WPS, "b",
  2337. wpas_dbus_getter_process_credentials,
  2338. wpas_dbus_setter_process_credentials
  2339. },
  2340. #endif /* CONFIG_WPS */
  2341. #ifdef CONFIG_P2P
  2342. { "P2PDeviceConfig", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "a{sv}",
  2343. wpas_dbus_getter_p2p_device_config,
  2344. wpas_dbus_setter_p2p_device_config
  2345. },
  2346. { "Peers", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
  2347. wpas_dbus_getter_p2p_peers,
  2348. NULL
  2349. },
  2350. { "Role", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "s",
  2351. wpas_dbus_getter_p2p_role,
  2352. NULL
  2353. },
  2354. { "Group", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
  2355. wpas_dbus_getter_p2p_group,
  2356. NULL
  2357. },
  2358. { "PeerGO", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
  2359. wpas_dbus_getter_p2p_peergo,
  2360. NULL
  2361. },
  2362. { "PersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
  2363. wpas_dbus_getter_persistent_groups,
  2364. NULL
  2365. },
  2366. #endif /* CONFIG_P2P */
  2367. { "DisconnectReason", WPAS_DBUS_NEW_IFACE_INTERFACE, "i",
  2368. wpas_dbus_getter_disconnect_reason,
  2369. NULL
  2370. },
  2371. { NULL, NULL, NULL, NULL, NULL }
  2372. };
  2373. static const struct wpa_dbus_signal_desc wpas_dbus_interface_signals[] = {
  2374. { "ScanDone", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2375. {
  2376. { "success", "b", ARG_OUT },
  2377. END_ARGS
  2378. }
  2379. },
  2380. { "BSSAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2381. {
  2382. { "path", "o", ARG_OUT },
  2383. { "properties", "a{sv}", ARG_OUT },
  2384. END_ARGS
  2385. }
  2386. },
  2387. { "BSSRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2388. {
  2389. { "path", "o", ARG_OUT },
  2390. END_ARGS
  2391. }
  2392. },
  2393. { "BlobAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2394. {
  2395. { "name", "s", ARG_OUT },
  2396. END_ARGS
  2397. }
  2398. },
  2399. { "BlobRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2400. {
  2401. { "name", "s", ARG_OUT },
  2402. END_ARGS
  2403. }
  2404. },
  2405. { "NetworkAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2406. {
  2407. { "path", "o", ARG_OUT },
  2408. { "properties", "a{sv}", ARG_OUT },
  2409. END_ARGS
  2410. }
  2411. },
  2412. { "NetworkRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2413. {
  2414. { "path", "o", ARG_OUT },
  2415. END_ARGS
  2416. }
  2417. },
  2418. { "NetworkSelected", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2419. {
  2420. { "path", "o", ARG_OUT },
  2421. END_ARGS
  2422. }
  2423. },
  2424. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  2425. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2426. {
  2427. { "properties", "a{sv}", ARG_OUT },
  2428. END_ARGS
  2429. }
  2430. },
  2431. #ifdef CONFIG_WPS
  2432. { "Event", WPAS_DBUS_NEW_IFACE_WPS,
  2433. {
  2434. { "name", "s", ARG_OUT },
  2435. { "args", "a{sv}", ARG_OUT },
  2436. END_ARGS
  2437. }
  2438. },
  2439. { "Credentials", WPAS_DBUS_NEW_IFACE_WPS,
  2440. {
  2441. { "credentials", "a{sv}", ARG_OUT },
  2442. END_ARGS
  2443. }
  2444. },
  2445. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  2446. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_WPS,
  2447. {
  2448. { "properties", "a{sv}", ARG_OUT },
  2449. END_ARGS
  2450. }
  2451. },
  2452. #endif /* CONFIG_WPS */
  2453. #ifdef CONFIG_P2P
  2454. { "P2PStateChanged", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2455. {
  2456. { "states", "a{ss}", ARG_OUT },
  2457. END_ARGS
  2458. }
  2459. },
  2460. { "DeviceFound", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2461. {
  2462. { "path", "o", ARG_OUT },
  2463. { "properties", "a{sv}", ARG_OUT },
  2464. END_ARGS
  2465. }
  2466. },
  2467. { "DeviceLost", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2468. {
  2469. { "path", "o", ARG_OUT },
  2470. END_ARGS
  2471. }
  2472. },
  2473. { "ProvisionDiscoveryRequestDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2474. {
  2475. { "peer_object", "o", ARG_OUT },
  2476. { "pin", "s", ARG_OUT },
  2477. END_ARGS
  2478. }
  2479. },
  2480. { "ProvisionDiscoveryResponseDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2481. {
  2482. { "peer_object", "o", ARG_OUT },
  2483. { "pin", "s", ARG_OUT },
  2484. END_ARGS
  2485. }
  2486. },
  2487. { "ProvisionDiscoveryRequestEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2488. {
  2489. { "peer_object", "o", ARG_OUT },
  2490. END_ARGS
  2491. }
  2492. },
  2493. { "ProvisionDiscoveryResponseEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2494. {
  2495. { "peer_object", "o", ARG_OUT },
  2496. END_ARGS
  2497. }
  2498. },
  2499. { "ProvisionDiscoveryPBCRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2500. {
  2501. { "peer_object", "o", ARG_OUT },
  2502. END_ARGS
  2503. }
  2504. },
  2505. { "ProvisionDiscoveryPBCResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2506. {
  2507. { "peer_object", "o", ARG_OUT },
  2508. END_ARGS
  2509. }
  2510. },
  2511. { "ProvisionDiscoveryFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2512. {
  2513. { "peer_object", "o", ARG_OUT },
  2514. { "status", "i", ARG_OUT },
  2515. END_ARGS
  2516. }
  2517. },
  2518. { "GroupStarted", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2519. {
  2520. { "properties", "a{sv}", ARG_OUT },
  2521. END_ARGS
  2522. }
  2523. },
  2524. { "GONegotiationSuccess", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2525. {
  2526. END_ARGS
  2527. }
  2528. },
  2529. { "GONegotiationFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2530. {
  2531. { "status", "i", ARG_OUT },
  2532. END_ARGS
  2533. }
  2534. },
  2535. { "GONegotiationRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2536. {
  2537. { "path", "o", ARG_OUT },
  2538. { "dev_passwd_id", "i", ARG_OUT },
  2539. END_ARGS
  2540. }
  2541. },
  2542. { "InvitationResult", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2543. {
  2544. { "invite_result", "a{sv}", ARG_OUT },
  2545. END_ARGS
  2546. }
  2547. },
  2548. { "GroupFinished", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2549. {
  2550. { "ifname", "s", ARG_OUT },
  2551. { "role", "s", ARG_OUT },
  2552. END_ARGS
  2553. }
  2554. },
  2555. { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2556. {
  2557. { "sd_request", "a{sv}", ARG_OUT },
  2558. END_ARGS
  2559. }
  2560. },
  2561. { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2562. {
  2563. { "sd_response", "a{sv}", ARG_OUT },
  2564. END_ARGS
  2565. }
  2566. },
  2567. { "PersistentGroupAdded", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2568. {
  2569. { "path", "o", ARG_OUT },
  2570. { "properties", "a{sv}", ARG_OUT },
  2571. END_ARGS
  2572. }
  2573. },
  2574. { "PersistentGroupRemoved", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2575. {
  2576. { "path", "o", ARG_OUT },
  2577. END_ARGS
  2578. }
  2579. },
  2580. { "WpsFailed", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2581. {
  2582. { "name", "s", ARG_OUT },
  2583. { "args", "a{sv}", ARG_OUT },
  2584. END_ARGS
  2585. }
  2586. },
  2587. #endif /* CONFIG_P2P */
  2588. #ifdef CONFIG_AP
  2589. { "ProbeRequest", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2590. {
  2591. { "args", "a{sv}", ARG_OUT },
  2592. END_ARGS
  2593. }
  2594. },
  2595. #endif /* CONFIG_AP */
  2596. { "Certification", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2597. {
  2598. { "certification", "a{sv}", ARG_OUT },
  2599. END_ARGS
  2600. }
  2601. },
  2602. { "EAP", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2603. {
  2604. { "status", "s", ARG_OUT },
  2605. { "parameter", "s", ARG_OUT },
  2606. END_ARGS
  2607. }
  2608. },
  2609. { NULL, NULL, { END_ARGS } }
  2610. };
  2611. int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s)
  2612. {
  2613. struct wpa_dbus_object_desc *obj_desc = NULL;
  2614. struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus;
  2615. int next;
  2616. /* Do nothing if the control interface is not turned on */
  2617. if (ctrl_iface == NULL)
  2618. return 0;
  2619. /* Create and set the interface's object path */
  2620. wpa_s->dbus_new_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
  2621. if (wpa_s->dbus_new_path == NULL)
  2622. return -1;
  2623. next = ctrl_iface->next_objid++;
  2624. os_snprintf(wpa_s->dbus_new_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2625. WPAS_DBUS_NEW_PATH_INTERFACES "/%u",
  2626. next);
  2627. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  2628. if (!obj_desc) {
  2629. wpa_printf(MSG_ERROR, "Not enough memory "
  2630. "to create object description");
  2631. goto err;
  2632. }
  2633. wpas_dbus_register(obj_desc, wpa_s, NULL, wpas_dbus_interface_methods,
  2634. wpas_dbus_interface_properties,
  2635. wpas_dbus_interface_signals);
  2636. wpa_printf(MSG_DEBUG, "dbus: Register interface object '%s'",
  2637. wpa_s->dbus_new_path);
  2638. if (wpa_dbus_register_object_per_iface(ctrl_iface,
  2639. wpa_s->dbus_new_path,
  2640. wpa_s->ifname, obj_desc))
  2641. goto err;
  2642. wpas_dbus_signal_interface_added(wpa_s);
  2643. return 0;
  2644. err:
  2645. os_free(wpa_s->dbus_new_path);
  2646. wpa_s->dbus_new_path = NULL;
  2647. free_dbus_object_desc(obj_desc);
  2648. return -1;
  2649. }
  2650. int wpas_dbus_unregister_interface(struct wpa_supplicant *wpa_s)
  2651. {
  2652. struct wpas_dbus_priv *ctrl_iface;
  2653. /* Do nothing if the control interface is not turned on */
  2654. if (wpa_s == NULL || wpa_s->global == NULL)
  2655. return 0;
  2656. ctrl_iface = wpa_s->global->dbus;
  2657. if (ctrl_iface == NULL)
  2658. return 0;
  2659. wpa_printf(MSG_DEBUG, "dbus: Unregister interface object '%s'",
  2660. wpa_s->dbus_new_path);
  2661. #ifdef CONFIG_AP
  2662. if (wpa_s->preq_notify_peer) {
  2663. wpas_dbus_unsubscribe_noc(ctrl_iface);
  2664. os_free(wpa_s->preq_notify_peer);
  2665. wpa_s->preq_notify_peer = NULL;
  2666. }
  2667. #endif /* CONFIG_AP */
  2668. if (wpa_dbus_unregister_object_per_iface(ctrl_iface,
  2669. wpa_s->dbus_new_path))
  2670. return -1;
  2671. wpas_dbus_signal_interface_removed(wpa_s);
  2672. os_free(wpa_s->dbus_new_path);
  2673. wpa_s->dbus_new_path = NULL;
  2674. return 0;
  2675. }
  2676. #ifdef CONFIG_P2P
  2677. static const struct wpa_dbus_property_desc wpas_dbus_p2p_peer_properties[] = {
  2678. { "DeviceName", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
  2679. wpas_dbus_getter_p2p_peer_device_name,
  2680. NULL
  2681. },
  2682. { "PrimaryDeviceType", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
  2683. wpas_dbus_getter_p2p_peer_primary_device_type,
  2684. NULL
  2685. },
  2686. { "config_method", WPAS_DBUS_NEW_IFACE_P2P_PEER, "q",
  2687. wpas_dbus_getter_p2p_peer_config_method,
  2688. NULL
  2689. },
  2690. { "level", WPAS_DBUS_NEW_IFACE_P2P_PEER, "i",
  2691. wpas_dbus_getter_p2p_peer_level,
  2692. NULL
  2693. },
  2694. { "devicecapability", WPAS_DBUS_NEW_IFACE_P2P_PEER, "y",
  2695. wpas_dbus_getter_p2p_peer_device_capability,
  2696. NULL
  2697. },
  2698. { "groupcapability", WPAS_DBUS_NEW_IFACE_P2P_PEER, "y",
  2699. wpas_dbus_getter_p2p_peer_group_capability,
  2700. NULL
  2701. },
  2702. { "SecondaryDeviceTypes", WPAS_DBUS_NEW_IFACE_P2P_PEER, "aay",
  2703. wpas_dbus_getter_p2p_peer_secondary_device_types,
  2704. NULL
  2705. },
  2706. { "VendorExtension", WPAS_DBUS_NEW_IFACE_P2P_PEER, "aay",
  2707. wpas_dbus_getter_p2p_peer_vendor_extension,
  2708. NULL
  2709. },
  2710. { "IEs", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
  2711. wpas_dbus_getter_p2p_peer_ies,
  2712. NULL
  2713. },
  2714. { NULL, NULL, NULL, NULL, NULL }
  2715. };
  2716. static const struct wpa_dbus_signal_desc wpas_dbus_p2p_peer_signals[] = {
  2717. { NULL, NULL, { END_ARGS } }
  2718. };
  2719. /**
  2720. * wpas_dbus_signal_peer - Send a peer related event signal
  2721. * @wpa_s: %wpa_supplicant network interface data
  2722. * @dev: peer device object
  2723. * @interface: name of the interface emitting this signal.
  2724. * In case of peer objects, it would be emitted by either
  2725. * the "interface object" or by "peer objects"
  2726. * @sig_name: signal name - DeviceFound
  2727. *
  2728. * Notify listeners about event related with newly found p2p peer device
  2729. */
  2730. static void wpas_dbus_signal_peer(struct wpa_supplicant *wpa_s,
  2731. const u8 *dev_addr, const char *interface,
  2732. const char *sig_name)
  2733. {
  2734. struct wpas_dbus_priv *iface;
  2735. DBusMessage *msg;
  2736. DBusMessageIter iter;
  2737. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  2738. iface = wpa_s->global->dbus;
  2739. /* Do nothing if the control interface is not turned on */
  2740. if (iface == NULL)
  2741. return;
  2742. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2743. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  2744. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  2745. msg = dbus_message_new_signal(wpa_s->dbus_new_path, interface,
  2746. sig_name);
  2747. if (msg == NULL)
  2748. return;
  2749. dbus_message_iter_init_append(msg, &iter);
  2750. path = peer_obj_path;
  2751. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  2752. &path))
  2753. goto err;
  2754. dbus_connection_send(iface->con, msg, NULL);
  2755. dbus_message_unref(msg);
  2756. return;
  2757. err:
  2758. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  2759. dbus_message_unref(msg);
  2760. }
  2761. /**
  2762. * wpas_dbus_signal_peer_found - Send a peer found signal
  2763. * @wpa_s: %wpa_supplicant network interface data
  2764. * @dev: peer device object
  2765. *
  2766. * Notify listeners about find a p2p peer device found
  2767. */
  2768. void wpas_dbus_signal_peer_device_found(struct wpa_supplicant *wpa_s,
  2769. const u8 *dev_addr)
  2770. {
  2771. wpas_dbus_signal_peer(wpa_s, dev_addr,
  2772. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2773. "DeviceFound");
  2774. }
  2775. /**
  2776. * wpas_dbus_signal_peer_lost - Send a peer lost signal
  2777. * @wpa_s: %wpa_supplicant network interface data
  2778. * @dev: peer device object
  2779. *
  2780. * Notify listeners about lost a p2p peer device
  2781. */
  2782. void wpas_dbus_signal_peer_device_lost(struct wpa_supplicant *wpa_s,
  2783. const u8 *dev_addr)
  2784. {
  2785. wpas_dbus_signal_peer(wpa_s, dev_addr,
  2786. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2787. "DeviceLost");
  2788. }
  2789. /**
  2790. * wpas_dbus_register_peer - Register a discovered peer object with dbus
  2791. * @wpa_s: wpa_supplicant interface structure
  2792. * @ssid: network configuration data
  2793. * Returns: 0 on success, -1 on failure
  2794. *
  2795. * Registers network representing object with dbus
  2796. */
  2797. int wpas_dbus_register_peer(struct wpa_supplicant *wpa_s, const u8 *dev_addr)
  2798. {
  2799. struct wpas_dbus_priv *ctrl_iface;
  2800. struct wpa_dbus_object_desc *obj_desc;
  2801. struct peer_handler_args *arg;
  2802. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2803. /* Do nothing if the control interface is not turned on */
  2804. if (wpa_s == NULL || wpa_s->global == NULL)
  2805. return 0;
  2806. ctrl_iface = wpa_s->global->dbus;
  2807. if (ctrl_iface == NULL)
  2808. return 0;
  2809. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2810. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  2811. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  2812. wpa_printf(MSG_INFO, "dbus: Register peer object '%s'",
  2813. peer_obj_path);
  2814. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  2815. if (!obj_desc) {
  2816. wpa_printf(MSG_ERROR, "Not enough memory "
  2817. "to create object description");
  2818. goto err;
  2819. }
  2820. /* allocate memory for handlers arguments */
  2821. arg = os_zalloc(sizeof(struct peer_handler_args));
  2822. if (!arg) {
  2823. wpa_printf(MSG_ERROR, "Not enough memory "
  2824. "to create arguments for method");
  2825. goto err;
  2826. }
  2827. arg->wpa_s = wpa_s;
  2828. os_memcpy(arg->p2p_device_addr, dev_addr, ETH_ALEN);
  2829. wpas_dbus_register(obj_desc, arg, wpa_dbus_free,
  2830. NULL,
  2831. wpas_dbus_p2p_peer_properties,
  2832. wpas_dbus_p2p_peer_signals);
  2833. if (wpa_dbus_register_object_per_iface(ctrl_iface, peer_obj_path,
  2834. wpa_s->ifname, obj_desc))
  2835. goto err;
  2836. return 0;
  2837. err:
  2838. free_dbus_object_desc(obj_desc);
  2839. return -1;
  2840. }
  2841. /**
  2842. * wpas_dbus_unregister_peer - Unregister a peer object with dbus
  2843. * @wpa_s: wpa_supplicant interface structure
  2844. * @dev_addr: p2p device addr
  2845. * Returns: 0 on success, -1 on failure
  2846. *
  2847. * Registers network representing object with dbus
  2848. */
  2849. int wpas_dbus_unregister_peer(struct wpa_supplicant *wpa_s,
  2850. const u8 *dev_addr)
  2851. {
  2852. struct wpas_dbus_priv *ctrl_iface;
  2853. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2854. int ret;
  2855. /* Do nothing if the control interface is not turned on */
  2856. if (wpa_s == NULL || wpa_s->global == NULL ||
  2857. wpa_s->dbus_new_path == NULL)
  2858. return 0;
  2859. ctrl_iface = wpa_s->global->dbus;
  2860. if (ctrl_iface == NULL)
  2861. return 0;
  2862. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2863. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  2864. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  2865. wpa_printf(MSG_INFO, "dbus: Unregister peer object '%s'",
  2866. peer_obj_path);
  2867. ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, peer_obj_path);
  2868. return ret;
  2869. }
  2870. static const struct wpa_dbus_property_desc wpas_dbus_p2p_group_properties[] = {
  2871. { "Members", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ao",
  2872. wpas_dbus_getter_p2p_group_members,
  2873. NULL
  2874. },
  2875. { "Group", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "o",
  2876. wpas_dbus_getter_p2p_group,
  2877. NULL
  2878. },
  2879. { "Role", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "s",
  2880. wpas_dbus_getter_p2p_role,
  2881. NULL
  2882. },
  2883. { "SSID", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
  2884. wpas_dbus_getter_p2p_group_ssid,
  2885. NULL
  2886. },
  2887. { "BSSID", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
  2888. wpas_dbus_getter_p2p_group_bssid,
  2889. NULL
  2890. },
  2891. { "Frequency", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "q",
  2892. wpas_dbus_getter_p2p_group_frequency,
  2893. NULL
  2894. },
  2895. { "Passphrase", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "s",
  2896. wpas_dbus_getter_p2p_group_passphrase,
  2897. NULL
  2898. },
  2899. { "PSK", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
  2900. wpas_dbus_getter_p2p_group_psk,
  2901. NULL
  2902. },
  2903. { "WPSVendorExtensions", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "aay",
  2904. wpas_dbus_getter_p2p_group_vendor_ext,
  2905. wpas_dbus_setter_p2p_group_vendor_ext
  2906. },
  2907. { NULL, NULL, NULL, NULL, NULL }
  2908. };
  2909. static const struct wpa_dbus_signal_desc wpas_dbus_p2p_group_signals[] = {
  2910. { "PeerJoined", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
  2911. {
  2912. { "peer", "o", ARG_OUT },
  2913. END_ARGS
  2914. }
  2915. },
  2916. { "PeerDisconnected", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
  2917. {
  2918. { "peer", "o", ARG_OUT },
  2919. END_ARGS
  2920. }
  2921. },
  2922. { NULL, NULL, { END_ARGS } }
  2923. };
  2924. /**
  2925. * wpas_dbus_register_p2p_group - Register a p2p group object with dbus
  2926. * @wpa_s: wpa_supplicant interface structure
  2927. * @ssid: SSID struct
  2928. * Returns: 0 on success, -1 on failure
  2929. *
  2930. * Registers p2p group representing object with dbus
  2931. */
  2932. void wpas_dbus_register_p2p_group(struct wpa_supplicant *wpa_s,
  2933. struct wpa_ssid *ssid)
  2934. {
  2935. struct wpas_dbus_priv *ctrl_iface;
  2936. struct wpa_dbus_object_desc *obj_desc;
  2937. char group_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2938. /* Do nothing if the control interface is not turned on */
  2939. if (wpa_s == NULL || wpa_s->global == NULL)
  2940. return;
  2941. ctrl_iface = wpa_s->global->dbus;
  2942. if (ctrl_iface == NULL)
  2943. return;
  2944. if (wpa_s->dbus_groupobj_path) {
  2945. wpa_printf(MSG_INFO, "%s: Group object '%s' already exists",
  2946. __func__, wpa_s->dbus_groupobj_path);
  2947. return;
  2948. }
  2949. if (wpas_dbus_get_group_obj_path(wpa_s, ssid, group_obj_path) < 0)
  2950. return;
  2951. wpa_s->dbus_groupobj_path = os_strdup(group_obj_path);
  2952. if (wpa_s->dbus_groupobj_path == NULL)
  2953. return;
  2954. wpa_printf(MSG_INFO, "dbus: Register group object '%s'",
  2955. group_obj_path);
  2956. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  2957. if (!obj_desc) {
  2958. wpa_printf(MSG_ERROR, "Not enough memory "
  2959. "to create object description");
  2960. goto err;
  2961. }
  2962. wpas_dbus_register(obj_desc, wpa_s, NULL, NULL,
  2963. wpas_dbus_p2p_group_properties,
  2964. wpas_dbus_p2p_group_signals);
  2965. if (wpa_dbus_register_object_per_iface(ctrl_iface, group_obj_path,
  2966. wpa_s->ifname, obj_desc))
  2967. goto err;
  2968. return;
  2969. err:
  2970. if (wpa_s->dbus_groupobj_path) {
  2971. os_free(wpa_s->dbus_groupobj_path);
  2972. wpa_s->dbus_groupobj_path = NULL;
  2973. }
  2974. free_dbus_object_desc(obj_desc);
  2975. }
  2976. /**
  2977. * wpas_dbus_unregister_p2p_group - Unregister a p2p group object from dbus
  2978. * @wpa_s: wpa_supplicant interface structure
  2979. * @ssid: network name of the p2p group started
  2980. */
  2981. void wpas_dbus_unregister_p2p_group(struct wpa_supplicant *wpa_s,
  2982. const struct wpa_ssid *ssid)
  2983. {
  2984. struct wpas_dbus_priv *ctrl_iface;
  2985. /* Do nothing if the control interface is not turned on */
  2986. if (wpa_s == NULL || wpa_s->global == NULL)
  2987. return;
  2988. ctrl_iface = wpa_s->global->dbus;
  2989. if (ctrl_iface == NULL)
  2990. return;
  2991. if (!wpa_s->dbus_groupobj_path) {
  2992. wpa_printf(MSG_DEBUG,
  2993. "%s: Group object '%s' already unregistered",
  2994. __func__, wpa_s->dbus_groupobj_path);
  2995. return;
  2996. }
  2997. wpa_printf(MSG_DEBUG, "dbus: Unregister group object '%s'",
  2998. wpa_s->dbus_groupobj_path);
  2999. wpa_dbus_unregister_object_per_iface(ctrl_iface,
  3000. wpa_s->dbus_groupobj_path);
  3001. os_free(wpa_s->dbus_groupobj_path);
  3002. wpa_s->dbus_groupobj_path = NULL;
  3003. }
  3004. static const struct wpa_dbus_property_desc
  3005. wpas_dbus_p2p_groupmember_properties[] = {
  3006. { NULL, NULL, NULL, NULL, NULL }
  3007. };
  3008. /**
  3009. * wpas_dbus_register_p2p_groupmember - Register a p2p groupmember
  3010. * object with dbus
  3011. * @wpa_s: wpa_supplicant interface structure
  3012. * @p2p_if_addr: i/f addr of the device joining this group
  3013. *
  3014. * Registers p2p groupmember representing object with dbus
  3015. */
  3016. void wpas_dbus_register_p2p_groupmember(struct wpa_supplicant *wpa_s,
  3017. const u8 *p2p_if_addr)
  3018. {
  3019. struct wpas_dbus_priv *ctrl_iface;
  3020. struct wpa_dbus_object_desc *obj_desc = NULL;
  3021. struct groupmember_handler_args *arg;
  3022. char groupmember_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3023. /* Do nothing if the control interface is not turned on */
  3024. if (wpa_s == NULL || wpa_s->global == NULL)
  3025. return;
  3026. ctrl_iface = wpa_s->global->dbus;
  3027. if (ctrl_iface == NULL)
  3028. return;
  3029. if (!wpa_s->dbus_groupobj_path)
  3030. return;
  3031. os_snprintf(groupmember_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3032. "%s/" WPAS_DBUS_NEW_P2P_GROUPMEMBERS_PART "/" COMPACT_MACSTR,
  3033. wpa_s->dbus_groupobj_path, MAC2STR(p2p_if_addr));
  3034. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  3035. if (!obj_desc) {
  3036. wpa_printf(MSG_ERROR, "Not enough memory "
  3037. "to create object description");
  3038. goto err;
  3039. }
  3040. /* allocate memory for handlers arguments */
  3041. arg = os_zalloc(sizeof(struct groupmember_handler_args));
  3042. if (!arg) {
  3043. wpa_printf(MSG_ERROR, "Not enough memory "
  3044. "to create arguments for method");
  3045. goto err;
  3046. }
  3047. arg->wpa_s = wpa_s;
  3048. os_memcpy(arg->member_addr, p2p_if_addr, ETH_ALEN);
  3049. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  3050. wpas_dbus_p2p_groupmember_properties, NULL);
  3051. if (wpa_dbus_register_object_per_iface(ctrl_iface, groupmember_obj_path,
  3052. wpa_s->ifname, obj_desc))
  3053. goto err;
  3054. wpa_printf(MSG_INFO,
  3055. "dbus: Registered group member object '%s' successfully",
  3056. groupmember_obj_path);
  3057. return;
  3058. err:
  3059. free_dbus_object_desc(obj_desc);
  3060. }
  3061. /**
  3062. * wpas_dbus_unregister_p2p_groupmember - Unregister a p2p groupmember
  3063. * object with dbus
  3064. * @wpa_s: wpa_supplicant interface structure
  3065. * @p2p_if_addr: i/f addr of the device joining this group
  3066. *
  3067. * Unregisters p2p groupmember representing object with dbus
  3068. */
  3069. void wpas_dbus_unregister_p2p_groupmember(struct wpa_supplicant *wpa_s,
  3070. const u8 *p2p_if_addr)
  3071. {
  3072. struct wpas_dbus_priv *ctrl_iface;
  3073. char groupmember_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3074. /* Do nothing if the control interface is not turned on */
  3075. if (wpa_s == NULL || wpa_s->global == NULL)
  3076. return;
  3077. ctrl_iface = wpa_s->global->dbus;
  3078. if (ctrl_iface == NULL)
  3079. return;
  3080. if (!wpa_s->dbus_groupobj_path)
  3081. return;
  3082. os_snprintf(groupmember_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3083. "%s/" WPAS_DBUS_NEW_P2P_GROUPMEMBERS_PART "/" COMPACT_MACSTR,
  3084. wpa_s->dbus_groupobj_path, MAC2STR(p2p_if_addr));
  3085. wpa_dbus_unregister_object_per_iface(ctrl_iface, groupmember_obj_path);
  3086. }
  3087. static const struct wpa_dbus_property_desc
  3088. wpas_dbus_persistent_group_properties[] = {
  3089. { "Properties", WPAS_DBUS_NEW_IFACE_PERSISTENT_GROUP, "a{sv}",
  3090. wpas_dbus_getter_persistent_group_properties,
  3091. wpas_dbus_setter_persistent_group_properties
  3092. },
  3093. { NULL, NULL, NULL, NULL, NULL }
  3094. };
  3095. /* No signals intended for persistent group objects */
  3096. /**
  3097. * wpas_dbus_register_persistent_group - Register a configured(saved)
  3098. * persistent group with dbus
  3099. * @wpa_s: wpa_supplicant interface structure
  3100. * @ssid: persistent group (still represented as a network within wpa)
  3101. * configuration data
  3102. * Returns: 0 on success, -1 on failure
  3103. *
  3104. * Registers a persistent group representing object with dbus.
  3105. */
  3106. int wpas_dbus_register_persistent_group(struct wpa_supplicant *wpa_s,
  3107. struct wpa_ssid *ssid)
  3108. {
  3109. struct wpas_dbus_priv *ctrl_iface;
  3110. struct wpa_dbus_object_desc *obj_desc;
  3111. struct network_handler_args *arg;
  3112. char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3113. /* Do nothing if the control interface is not turned on */
  3114. if (wpa_s == NULL || wpa_s->global == NULL)
  3115. return 0;
  3116. /* Make sure ssid is a persistent group */
  3117. if (ssid->disabled != 2 && !ssid->p2p_persistent_group)
  3118. return -1; /* should we return w/o complaining? */
  3119. ctrl_iface = wpa_s->global->dbus;
  3120. if (ctrl_iface == NULL)
  3121. return 0;
  3122. /*
  3123. * Intentionally not coming up with different numbering scheme
  3124. * for persistent groups.
  3125. */
  3126. os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3127. "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
  3128. wpa_s->dbus_new_path, ssid->id);
  3129. wpa_printf(MSG_DEBUG, "dbus: Register persistent group object '%s'",
  3130. pgrp_obj_path);
  3131. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  3132. if (!obj_desc) {
  3133. wpa_printf(MSG_ERROR, "dbus: Not enough memory to create "
  3134. "object description");
  3135. goto err;
  3136. }
  3137. /*
  3138. * Reusing the same context structure as that for networks
  3139. * since these are represented using same data structure.
  3140. */
  3141. /* allocate memory for handlers arguments */
  3142. arg = os_zalloc(sizeof(struct network_handler_args));
  3143. if (!arg) {
  3144. wpa_printf(MSG_ERROR, "dbus: Not enough memory to create "
  3145. "arguments for method");
  3146. goto err;
  3147. }
  3148. arg->wpa_s = wpa_s;
  3149. arg->ssid = ssid;
  3150. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  3151. wpas_dbus_persistent_group_properties,
  3152. NULL);
  3153. if (wpa_dbus_register_object_per_iface(ctrl_iface, pgrp_obj_path,
  3154. wpa_s->ifname, obj_desc))
  3155. goto err;
  3156. wpas_dbus_signal_persistent_group_added(wpa_s, ssid->id);
  3157. return 0;
  3158. err:
  3159. free_dbus_object_desc(obj_desc);
  3160. return -1;
  3161. }
  3162. /**
  3163. * wpas_dbus_unregister_persistent_group - Unregister a persistent_group
  3164. * from dbus
  3165. * @wpa_s: wpa_supplicant interface structure
  3166. * @nid: network id
  3167. * Returns: 0 on success, -1 on failure
  3168. *
  3169. * Unregisters persistent group representing object from dbus
  3170. *
  3171. * NOTE: There is a slight issue with the semantics here. While the
  3172. * implementation simply means the persistent group is unloaded from memory,
  3173. * it should not get interpreted as the group is actually being erased/removed
  3174. * from persistent storage as well.
  3175. */
  3176. int wpas_dbus_unregister_persistent_group(struct wpa_supplicant *wpa_s,
  3177. int nid)
  3178. {
  3179. struct wpas_dbus_priv *ctrl_iface;
  3180. char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3181. int ret;
  3182. /* Do nothing if the control interface is not turned on */
  3183. if (wpa_s == NULL || wpa_s->global == NULL ||
  3184. wpa_s->dbus_new_path == NULL)
  3185. return 0;
  3186. ctrl_iface = wpa_s->global->dbus;
  3187. if (ctrl_iface == NULL)
  3188. return 0;
  3189. os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3190. "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
  3191. wpa_s->dbus_new_path, nid);
  3192. wpa_printf(MSG_DEBUG, "dbus: Unregister persistent group object '%s'",
  3193. pgrp_obj_path);
  3194. ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, pgrp_obj_path);
  3195. if (!ret)
  3196. wpas_dbus_signal_persistent_group_removed(wpa_s, nid);
  3197. return ret;
  3198. }
  3199. #endif /* CONFIG_P2P */