dbus_new.c 99 KB

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