dbus_new.c 104 KB

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