dbus_new.c 95 KB

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