dbus_new.c 100 KB

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