dbus_new.c 100 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826
  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. { "NetworkRequest", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1727. {
  1728. { "path", "o", ARG_OUT },
  1729. { "field", "s", ARG_OUT },
  1730. { "text", "s", ARG_OUT },
  1731. END_ARGS
  1732. }
  1733. },
  1734. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  1735. { "PropertiesChanged", WPAS_DBUS_NEW_INTERFACE,
  1736. {
  1737. { "properties", "a{sv}", ARG_OUT },
  1738. END_ARGS
  1739. }
  1740. },
  1741. { NULL, NULL, { END_ARGS } }
  1742. };
  1743. /**
  1744. * wpas_dbus_ctrl_iface_init - Initialize dbus control interface
  1745. * @global: Pointer to global data from wpa_supplicant_init()
  1746. * Returns: 0 on success or -1 on failure
  1747. *
  1748. * Initialize the dbus control interface for wpa_supplicantand and start
  1749. * receiving commands from external programs over the bus.
  1750. */
  1751. int wpas_dbus_ctrl_iface_init(struct wpas_dbus_priv *priv)
  1752. {
  1753. struct wpa_dbus_object_desc *obj_desc;
  1754. int ret;
  1755. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  1756. if (!obj_desc) {
  1757. wpa_printf(MSG_ERROR,
  1758. "Not enough memory to create object description");
  1759. return -1;
  1760. }
  1761. wpas_dbus_register(obj_desc, priv->global, NULL,
  1762. wpas_dbus_global_methods,
  1763. wpas_dbus_global_properties,
  1764. wpas_dbus_global_signals);
  1765. wpa_printf(MSG_DEBUG, "dbus: Register D-Bus object '%s'",
  1766. WPAS_DBUS_NEW_PATH);
  1767. ret = wpa_dbus_ctrl_iface_init(priv, WPAS_DBUS_NEW_PATH,
  1768. WPAS_DBUS_NEW_SERVICE,
  1769. obj_desc);
  1770. if (ret < 0)
  1771. free_dbus_object_desc(obj_desc);
  1772. else
  1773. priv->dbus_new_initialized = 1;
  1774. return ret;
  1775. }
  1776. /**
  1777. * wpas_dbus_ctrl_iface_deinit - Deinitialize dbus ctrl interface for
  1778. * wpa_supplicant
  1779. * @iface: Pointer to dbus private data from wpas_dbus_init()
  1780. *
  1781. * Deinitialize the dbus control interface that was initialized with
  1782. * wpas_dbus_ctrl_iface_init().
  1783. */
  1784. void wpas_dbus_ctrl_iface_deinit(struct wpas_dbus_priv *iface)
  1785. {
  1786. if (!iface->dbus_new_initialized)
  1787. return;
  1788. wpa_printf(MSG_DEBUG, "dbus: Unregister D-Bus object '%s'",
  1789. WPAS_DBUS_NEW_PATH);
  1790. dbus_connection_unregister_object_path(iface->con,
  1791. WPAS_DBUS_NEW_PATH);
  1792. }
  1793. static void wpa_dbus_free(void *ptr)
  1794. {
  1795. os_free(ptr);
  1796. }
  1797. static const struct wpa_dbus_property_desc wpas_dbus_network_properties[] = {
  1798. { "Properties", WPAS_DBUS_NEW_IFACE_NETWORK, "a{sv}",
  1799. wpas_dbus_getter_network_properties,
  1800. wpas_dbus_setter_network_properties
  1801. },
  1802. { "Enabled", WPAS_DBUS_NEW_IFACE_NETWORK, "b",
  1803. wpas_dbus_getter_enabled,
  1804. wpas_dbus_setter_enabled
  1805. },
  1806. { NULL, NULL, NULL, NULL, NULL }
  1807. };
  1808. static const struct wpa_dbus_signal_desc wpas_dbus_network_signals[] = {
  1809. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  1810. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_NETWORK,
  1811. {
  1812. { "properties", "a{sv}", ARG_OUT },
  1813. END_ARGS
  1814. }
  1815. },
  1816. { NULL, NULL, { END_ARGS } }
  1817. };
  1818. /**
  1819. * wpas_dbus_register_network - Register a configured network with dbus
  1820. * @wpa_s: wpa_supplicant interface structure
  1821. * @ssid: network configuration data
  1822. * Returns: 0 on success, -1 on failure
  1823. *
  1824. * Registers network representing object with dbus
  1825. */
  1826. int wpas_dbus_register_network(struct wpa_supplicant *wpa_s,
  1827. struct wpa_ssid *ssid)
  1828. {
  1829. struct wpas_dbus_priv *ctrl_iface;
  1830. struct wpa_dbus_object_desc *obj_desc;
  1831. struct network_handler_args *arg;
  1832. char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  1833. #ifdef CONFIG_P2P
  1834. /*
  1835. * If it is a persistent group register it as such.
  1836. * This is to handle cases where an interface is being initialized
  1837. * with a list of networks read from config.
  1838. */
  1839. if (network_is_persistent_group(ssid))
  1840. return wpas_dbus_register_persistent_group(wpa_s, ssid);
  1841. #endif /* CONFIG_P2P */
  1842. /* Do nothing if the control interface is not turned on */
  1843. if (wpa_s == NULL || wpa_s->global == NULL)
  1844. return 0;
  1845. ctrl_iface = wpa_s->global->dbus;
  1846. if (ctrl_iface == NULL)
  1847. return 0;
  1848. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1849. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  1850. wpa_s->dbus_new_path, ssid->id);
  1851. wpa_printf(MSG_DEBUG, "dbus: Register network object '%s'",
  1852. net_obj_path);
  1853. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  1854. if (!obj_desc) {
  1855. wpa_printf(MSG_ERROR,
  1856. "Not enough memory to create object description");
  1857. goto err;
  1858. }
  1859. /* allocate memory for handlers arguments */
  1860. arg = os_zalloc(sizeof(struct network_handler_args));
  1861. if (!arg) {
  1862. wpa_printf(MSG_ERROR,
  1863. "Not enough memory to create arguments for method");
  1864. goto err;
  1865. }
  1866. arg->wpa_s = wpa_s;
  1867. arg->ssid = ssid;
  1868. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  1869. wpas_dbus_network_properties,
  1870. wpas_dbus_network_signals);
  1871. if (wpa_dbus_register_object_per_iface(ctrl_iface, net_obj_path,
  1872. wpa_s->ifname, obj_desc))
  1873. goto err;
  1874. wpas_dbus_signal_network_added(wpa_s, ssid->id);
  1875. return 0;
  1876. err:
  1877. free_dbus_object_desc(obj_desc);
  1878. return -1;
  1879. }
  1880. /**
  1881. * wpas_dbus_unregister_network - Unregister a configured network from dbus
  1882. * @wpa_s: wpa_supplicant interface structure
  1883. * @nid: network id
  1884. * Returns: 0 on success, -1 on failure
  1885. *
  1886. * Unregisters network representing object from dbus
  1887. */
  1888. int wpas_dbus_unregister_network(struct wpa_supplicant *wpa_s, int nid)
  1889. {
  1890. struct wpas_dbus_priv *ctrl_iface;
  1891. char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  1892. int ret;
  1893. #ifdef CONFIG_P2P
  1894. struct wpa_ssid *ssid;
  1895. ssid = wpa_config_get_network(wpa_s->conf, nid);
  1896. /* If it is a persistent group unregister it as such */
  1897. if (ssid && network_is_persistent_group(ssid))
  1898. return wpas_dbus_unregister_persistent_group(wpa_s, nid);
  1899. #endif /* CONFIG_P2P */
  1900. /* Do nothing if the control interface is not turned on */
  1901. if (wpa_s->global == NULL || wpa_s->dbus_new_path == NULL)
  1902. return 0;
  1903. ctrl_iface = wpa_s->global->dbus;
  1904. if (ctrl_iface == NULL)
  1905. return 0;
  1906. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1907. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  1908. wpa_s->dbus_new_path, nid);
  1909. wpa_printf(MSG_DEBUG, "dbus: Unregister network object '%s'",
  1910. net_obj_path);
  1911. ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, net_obj_path);
  1912. if (!ret)
  1913. wpas_dbus_signal_network_removed(wpa_s, nid);
  1914. return ret;
  1915. }
  1916. static const struct wpa_dbus_property_desc wpas_dbus_bss_properties[] = {
  1917. { "SSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
  1918. wpas_dbus_getter_bss_ssid,
  1919. NULL
  1920. },
  1921. { "BSSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
  1922. wpas_dbus_getter_bss_bssid,
  1923. NULL
  1924. },
  1925. { "Privacy", WPAS_DBUS_NEW_IFACE_BSS, "b",
  1926. wpas_dbus_getter_bss_privacy,
  1927. NULL
  1928. },
  1929. { "Mode", WPAS_DBUS_NEW_IFACE_BSS, "s",
  1930. wpas_dbus_getter_bss_mode,
  1931. NULL
  1932. },
  1933. { "Signal", WPAS_DBUS_NEW_IFACE_BSS, "n",
  1934. wpas_dbus_getter_bss_signal,
  1935. NULL
  1936. },
  1937. { "Frequency", WPAS_DBUS_NEW_IFACE_BSS, "q",
  1938. wpas_dbus_getter_bss_frequency,
  1939. NULL
  1940. },
  1941. { "Rates", WPAS_DBUS_NEW_IFACE_BSS, "au",
  1942. wpas_dbus_getter_bss_rates,
  1943. NULL
  1944. },
  1945. { "WPA", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
  1946. wpas_dbus_getter_bss_wpa,
  1947. NULL
  1948. },
  1949. { "RSN", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
  1950. wpas_dbus_getter_bss_rsn,
  1951. NULL
  1952. },
  1953. { "WPS", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
  1954. wpas_dbus_getter_bss_wps,
  1955. NULL
  1956. },
  1957. { "IEs", WPAS_DBUS_NEW_IFACE_BSS, "ay",
  1958. wpas_dbus_getter_bss_ies,
  1959. NULL
  1960. },
  1961. { "Age", WPAS_DBUS_NEW_IFACE_BSS, "u",
  1962. wpas_dbus_getter_bss_age,
  1963. NULL
  1964. },
  1965. { NULL, NULL, NULL, NULL, NULL }
  1966. };
  1967. static const struct wpa_dbus_signal_desc wpas_dbus_bss_signals[] = {
  1968. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  1969. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_BSS,
  1970. {
  1971. { "properties", "a{sv}", ARG_OUT },
  1972. END_ARGS
  1973. }
  1974. },
  1975. { NULL, NULL, { END_ARGS } }
  1976. };
  1977. /**
  1978. * wpas_dbus_unregister_bss - Unregister a scanned BSS from dbus
  1979. * @wpa_s: wpa_supplicant interface structure
  1980. * @bssid: scanned network bssid
  1981. * @id: unique BSS identifier
  1982. * Returns: 0 on success, -1 on failure
  1983. *
  1984. * Unregisters BSS representing object from dbus
  1985. */
  1986. int wpas_dbus_unregister_bss(struct wpa_supplicant *wpa_s,
  1987. u8 bssid[ETH_ALEN], unsigned int id)
  1988. {
  1989. struct wpas_dbus_priv *ctrl_iface;
  1990. char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  1991. /* Do nothing if the control interface is not turned on */
  1992. if (wpa_s == NULL || wpa_s->global == NULL)
  1993. return 0;
  1994. ctrl_iface = wpa_s->global->dbus;
  1995. if (ctrl_iface == NULL)
  1996. return 0;
  1997. os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1998. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  1999. wpa_s->dbus_new_path, id);
  2000. wpa_printf(MSG_DEBUG, "dbus: Unregister BSS object '%s'",
  2001. bss_obj_path);
  2002. if (wpa_dbus_unregister_object_per_iface(ctrl_iface, bss_obj_path)) {
  2003. wpa_printf(MSG_ERROR, "dbus: Cannot unregister BSS object %s",
  2004. bss_obj_path);
  2005. return -1;
  2006. }
  2007. wpas_dbus_signal_bss_removed(wpa_s, bss_obj_path);
  2008. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSSS);
  2009. return 0;
  2010. }
  2011. /**
  2012. * wpas_dbus_register_bss - Register a scanned BSS with dbus
  2013. * @wpa_s: wpa_supplicant interface structure
  2014. * @bssid: scanned network bssid
  2015. * @id: unique BSS identifier
  2016. * Returns: 0 on success, -1 on failure
  2017. *
  2018. * Registers BSS representing object with dbus
  2019. */
  2020. int wpas_dbus_register_bss(struct wpa_supplicant *wpa_s,
  2021. u8 bssid[ETH_ALEN], unsigned int id)
  2022. {
  2023. struct wpas_dbus_priv *ctrl_iface;
  2024. struct wpa_dbus_object_desc *obj_desc;
  2025. char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2026. struct bss_handler_args *arg;
  2027. /* Do nothing if the control interface is not turned on */
  2028. if (wpa_s == NULL || wpa_s->global == NULL)
  2029. return 0;
  2030. ctrl_iface = wpa_s->global->dbus;
  2031. if (ctrl_iface == NULL)
  2032. return 0;
  2033. os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2034. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  2035. wpa_s->dbus_new_path, id);
  2036. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  2037. if (!obj_desc) {
  2038. wpa_printf(MSG_ERROR,
  2039. "Not enough memory to create object description");
  2040. goto err;
  2041. }
  2042. arg = os_zalloc(sizeof(struct bss_handler_args));
  2043. if (!arg) {
  2044. wpa_printf(MSG_ERROR,
  2045. "Not enough memory to create arguments for handler");
  2046. goto err;
  2047. }
  2048. arg->wpa_s = wpa_s;
  2049. arg->id = id;
  2050. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  2051. wpas_dbus_bss_properties,
  2052. wpas_dbus_bss_signals);
  2053. wpa_printf(MSG_DEBUG, "dbus: Register BSS object '%s'",
  2054. bss_obj_path);
  2055. if (wpa_dbus_register_object_per_iface(ctrl_iface, bss_obj_path,
  2056. wpa_s->ifname, obj_desc)) {
  2057. wpa_printf(MSG_ERROR,
  2058. "Cannot register BSSID dbus object %s.",
  2059. bss_obj_path);
  2060. goto err;
  2061. }
  2062. wpas_dbus_signal_bss_added(wpa_s, bss_obj_path);
  2063. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSSS);
  2064. return 0;
  2065. err:
  2066. free_dbus_object_desc(obj_desc);
  2067. return -1;
  2068. }
  2069. static const struct wpa_dbus_method_desc wpas_dbus_interface_methods[] = {
  2070. { "Scan", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2071. (WPADBusMethodHandler) wpas_dbus_handler_scan,
  2072. {
  2073. { "args", "a{sv}", ARG_IN },
  2074. END_ARGS
  2075. }
  2076. },
  2077. { "SignalPoll", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2078. (WPADBusMethodHandler) wpas_dbus_handler_signal_poll,
  2079. {
  2080. { "args", "a{sv}", ARG_OUT },
  2081. END_ARGS
  2082. }
  2083. },
  2084. { "Disconnect", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2085. (WPADBusMethodHandler) wpas_dbus_handler_disconnect,
  2086. {
  2087. END_ARGS
  2088. }
  2089. },
  2090. { "AddNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2091. (WPADBusMethodHandler) wpas_dbus_handler_add_network,
  2092. {
  2093. { "args", "a{sv}", ARG_IN },
  2094. { "path", "o", ARG_OUT },
  2095. END_ARGS
  2096. }
  2097. },
  2098. { "Reassociate", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2099. (WPADBusMethodHandler) wpas_dbus_handler_reassociate,
  2100. {
  2101. END_ARGS
  2102. }
  2103. },
  2104. { "Reattach", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2105. (WPADBusMethodHandler) wpas_dbus_handler_reattach,
  2106. {
  2107. END_ARGS
  2108. }
  2109. },
  2110. { "RemoveNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2111. (WPADBusMethodHandler) wpas_dbus_handler_remove_network,
  2112. {
  2113. { "path", "o", ARG_IN },
  2114. END_ARGS
  2115. }
  2116. },
  2117. { "RemoveAllNetworks", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2118. (WPADBusMethodHandler) wpas_dbus_handler_remove_all_networks,
  2119. {
  2120. END_ARGS
  2121. }
  2122. },
  2123. { "SelectNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2124. (WPADBusMethodHandler) wpas_dbus_handler_select_network,
  2125. {
  2126. { "path", "o", ARG_IN },
  2127. END_ARGS
  2128. }
  2129. },
  2130. { "NetworkReply", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2131. (WPADBusMethodHandler) wpas_dbus_handler_network_reply,
  2132. {
  2133. { "path", "o", ARG_IN },
  2134. { "field", "s", ARG_IN },
  2135. { "value", "s", ARG_IN },
  2136. END_ARGS
  2137. }
  2138. },
  2139. #ifndef CONFIG_NO_CONFIG_BLOBS
  2140. { "AddBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2141. (WPADBusMethodHandler) wpas_dbus_handler_add_blob,
  2142. {
  2143. { "name", "s", ARG_IN },
  2144. { "data", "ay", ARG_IN },
  2145. END_ARGS
  2146. }
  2147. },
  2148. { "GetBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2149. (WPADBusMethodHandler) wpas_dbus_handler_get_blob,
  2150. {
  2151. { "name", "s", ARG_IN },
  2152. { "data", "ay", ARG_OUT },
  2153. END_ARGS
  2154. }
  2155. },
  2156. { "RemoveBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2157. (WPADBusMethodHandler) wpas_dbus_handler_remove_blob,
  2158. {
  2159. { "name", "s", ARG_IN },
  2160. END_ARGS
  2161. }
  2162. },
  2163. #endif /* CONFIG_NO_CONFIG_BLOBS */
  2164. { "SetPKCS11EngineAndModulePath", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2165. (WPADBusMethodHandler)
  2166. wpas_dbus_handler_set_pkcs11_engine_and_module_path,
  2167. {
  2168. { "pkcs11_engine_path", "s", ARG_IN },
  2169. { "pkcs11_module_path", "s", ARG_IN },
  2170. END_ARGS
  2171. }
  2172. },
  2173. #ifdef CONFIG_WPS
  2174. { "Start", WPAS_DBUS_NEW_IFACE_WPS,
  2175. (WPADBusMethodHandler) wpas_dbus_handler_wps_start,
  2176. {
  2177. { "args", "a{sv}", ARG_IN },
  2178. { "output", "a{sv}", ARG_OUT },
  2179. END_ARGS
  2180. }
  2181. },
  2182. #endif /* CONFIG_WPS */
  2183. #ifdef CONFIG_P2P
  2184. { "Find", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2185. (WPADBusMethodHandler) wpas_dbus_handler_p2p_find,
  2186. {
  2187. { "args", "a{sv}", ARG_IN },
  2188. END_ARGS
  2189. }
  2190. },
  2191. { "StopFind", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2192. (WPADBusMethodHandler) wpas_dbus_handler_p2p_stop_find,
  2193. {
  2194. END_ARGS
  2195. }
  2196. },
  2197. { "Listen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2198. (WPADBusMethodHandler) wpas_dbus_handler_p2p_listen,
  2199. {
  2200. { "timeout", "i", ARG_IN },
  2201. END_ARGS
  2202. }
  2203. },
  2204. { "ExtendedListen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2205. (WPADBusMethodHandler) wpas_dbus_handler_p2p_extendedlisten,
  2206. {
  2207. { "args", "a{sv}", ARG_IN },
  2208. END_ARGS
  2209. }
  2210. },
  2211. { "PresenceRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2212. (WPADBusMethodHandler) wpas_dbus_handler_p2p_presence_request,
  2213. {
  2214. { "args", "a{sv}", ARG_IN },
  2215. END_ARGS
  2216. }
  2217. },
  2218. { "ProvisionDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2219. (WPADBusMethodHandler) wpas_dbus_handler_p2p_prov_disc_req,
  2220. {
  2221. { "peer", "o", ARG_IN },
  2222. { "config_method", "s", ARG_IN },
  2223. END_ARGS
  2224. }
  2225. },
  2226. { "Connect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2227. (WPADBusMethodHandler) wpas_dbus_handler_p2p_connect,
  2228. {
  2229. { "args", "a{sv}", ARG_IN },
  2230. { "generated_pin", "s", ARG_OUT },
  2231. END_ARGS
  2232. }
  2233. },
  2234. { "GroupAdd", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2235. (WPADBusMethodHandler) wpas_dbus_handler_p2p_group_add,
  2236. {
  2237. { "args", "a{sv}", ARG_IN },
  2238. END_ARGS
  2239. }
  2240. },
  2241. { "Invite", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2242. (WPADBusMethodHandler) wpas_dbus_handler_p2p_invite,
  2243. {
  2244. { "args", "a{sv}", ARG_IN },
  2245. END_ARGS
  2246. }
  2247. },
  2248. { "Disconnect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2249. (WPADBusMethodHandler) wpas_dbus_handler_p2p_disconnect,
  2250. {
  2251. END_ARGS
  2252. }
  2253. },
  2254. { "RejectPeer", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2255. (WPADBusMethodHandler) wpas_dbus_handler_p2p_rejectpeer,
  2256. {
  2257. { "peer", "o", ARG_IN },
  2258. END_ARGS
  2259. }
  2260. },
  2261. { "Flush", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2262. (WPADBusMethodHandler) wpas_dbus_handler_p2p_flush,
  2263. {
  2264. END_ARGS
  2265. }
  2266. },
  2267. { "AddService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2268. (WPADBusMethodHandler) wpas_dbus_handler_p2p_add_service,
  2269. {
  2270. { "args", "a{sv}", ARG_IN },
  2271. END_ARGS
  2272. }
  2273. },
  2274. { "DeleteService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2275. (WPADBusMethodHandler) wpas_dbus_handler_p2p_delete_service,
  2276. {
  2277. { "args", "a{sv}", ARG_IN },
  2278. END_ARGS
  2279. }
  2280. },
  2281. { "FlushService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2282. (WPADBusMethodHandler) wpas_dbus_handler_p2p_flush_service,
  2283. {
  2284. END_ARGS
  2285. }
  2286. },
  2287. { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2288. (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_sd_req,
  2289. {
  2290. { "args", "a{sv}", ARG_IN },
  2291. { "ref", "t", ARG_OUT },
  2292. END_ARGS
  2293. }
  2294. },
  2295. { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2296. (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_sd_res,
  2297. {
  2298. { "args", "a{sv}", ARG_IN },
  2299. END_ARGS
  2300. }
  2301. },
  2302. { "ServiceDiscoveryCancelRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2303. (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_sd_cancel_req,
  2304. {
  2305. { "args", "t", ARG_IN },
  2306. END_ARGS
  2307. }
  2308. },
  2309. { "ServiceUpdate", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2310. (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_update,
  2311. {
  2312. END_ARGS
  2313. }
  2314. },
  2315. { "ServiceDiscoveryExternal", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2316. (WPADBusMethodHandler) wpas_dbus_handler_p2p_serv_disc_external,
  2317. {
  2318. { "arg", "i", ARG_IN },
  2319. END_ARGS
  2320. }
  2321. },
  2322. { "AddPersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2323. (WPADBusMethodHandler) wpas_dbus_handler_add_persistent_group,
  2324. {
  2325. { "args", "a{sv}", ARG_IN },
  2326. { "path", "o", ARG_OUT },
  2327. END_ARGS
  2328. }
  2329. },
  2330. { "RemovePersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2331. (WPADBusMethodHandler) wpas_dbus_handler_remove_persistent_group,
  2332. {
  2333. { "path", "o", ARG_IN },
  2334. END_ARGS
  2335. }
  2336. },
  2337. { "RemoveAllPersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2338. (WPADBusMethodHandler)
  2339. wpas_dbus_handler_remove_all_persistent_groups,
  2340. {
  2341. END_ARGS
  2342. }
  2343. },
  2344. #endif /* CONFIG_P2P */
  2345. { "FlushBSS", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2346. (WPADBusMethodHandler) wpas_dbus_handler_flush_bss,
  2347. {
  2348. { "age", "u", ARG_IN },
  2349. END_ARGS
  2350. }
  2351. },
  2352. #ifdef CONFIG_AP
  2353. { "SubscribeProbeReq", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2354. (WPADBusMethodHandler) wpas_dbus_handler_subscribe_preq,
  2355. {
  2356. END_ARGS
  2357. }
  2358. },
  2359. { "UnsubscribeProbeReq", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2360. (WPADBusMethodHandler) wpas_dbus_handler_unsubscribe_preq,
  2361. {
  2362. END_ARGS
  2363. }
  2364. },
  2365. #endif /* CONFIG_AP */
  2366. { "EAPLogoff", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2367. (WPADBusMethodHandler) wpas_dbus_handler_eap_logoff,
  2368. {
  2369. END_ARGS
  2370. }
  2371. },
  2372. { "EAPLogon", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2373. (WPADBusMethodHandler) wpas_dbus_handler_eap_logon,
  2374. {
  2375. END_ARGS
  2376. }
  2377. },
  2378. #ifdef CONFIG_AUTOSCAN
  2379. { "AutoScan", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2380. (WPADBusMethodHandler) wpas_dbus_handler_autoscan,
  2381. {
  2382. { "arg", "s", ARG_IN },
  2383. END_ARGS
  2384. }
  2385. },
  2386. #endif /* CONFIG_AUTOSCAN */
  2387. #ifdef CONFIG_TDLS
  2388. { "TDLSDiscover", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2389. (WPADBusMethodHandler) wpas_dbus_handler_tdls_discover,
  2390. {
  2391. { "peer_address", "s", ARG_IN },
  2392. END_ARGS
  2393. }
  2394. },
  2395. { "TDLSSetup", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2396. (WPADBusMethodHandler) wpas_dbus_handler_tdls_setup,
  2397. {
  2398. { "peer_address", "s", ARG_IN },
  2399. END_ARGS
  2400. }
  2401. },
  2402. { "TDLSStatus", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2403. (WPADBusMethodHandler) wpas_dbus_handler_tdls_status,
  2404. {
  2405. { "peer_address", "s", ARG_IN },
  2406. { "status", "s", ARG_OUT },
  2407. END_ARGS
  2408. }
  2409. },
  2410. { "TDLSTeardown", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2411. (WPADBusMethodHandler) wpas_dbus_handler_tdls_teardown,
  2412. {
  2413. { "peer_address", "s", ARG_IN },
  2414. END_ARGS
  2415. }
  2416. },
  2417. #endif /* CONFIG_TDLS */
  2418. { NULL, NULL, NULL, { END_ARGS } }
  2419. };
  2420. static const struct wpa_dbus_property_desc wpas_dbus_interface_properties[] = {
  2421. { "Capabilities", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{sv}",
  2422. wpas_dbus_getter_capabilities,
  2423. NULL
  2424. },
  2425. { "State", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2426. wpas_dbus_getter_state,
  2427. NULL
  2428. },
  2429. { "Scanning", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
  2430. wpas_dbus_getter_scanning,
  2431. NULL
  2432. },
  2433. { "ApScan", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  2434. wpas_dbus_getter_ap_scan,
  2435. wpas_dbus_setter_ap_scan
  2436. },
  2437. { "BSSExpireAge", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  2438. wpas_dbus_getter_bss_expire_age,
  2439. wpas_dbus_setter_bss_expire_age
  2440. },
  2441. { "BSSExpireCount", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  2442. wpas_dbus_getter_bss_expire_count,
  2443. wpas_dbus_setter_bss_expire_count
  2444. },
  2445. { "Country", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2446. wpas_dbus_getter_country,
  2447. wpas_dbus_setter_country
  2448. },
  2449. { "Ifname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2450. wpas_dbus_getter_ifname,
  2451. NULL
  2452. },
  2453. { "Driver", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2454. wpas_dbus_getter_driver,
  2455. NULL
  2456. },
  2457. { "BridgeIfname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2458. wpas_dbus_getter_bridge_ifname,
  2459. NULL
  2460. },
  2461. { "CurrentBSS", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
  2462. wpas_dbus_getter_current_bss,
  2463. NULL
  2464. },
  2465. { "CurrentNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
  2466. wpas_dbus_getter_current_network,
  2467. NULL
  2468. },
  2469. { "CurrentAuthMode", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2470. wpas_dbus_getter_current_auth_mode,
  2471. NULL
  2472. },
  2473. { "Blobs", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{say}",
  2474. wpas_dbus_getter_blobs,
  2475. NULL
  2476. },
  2477. { "BSSs", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
  2478. wpas_dbus_getter_bsss,
  2479. NULL
  2480. },
  2481. { "Networks", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
  2482. wpas_dbus_getter_networks,
  2483. NULL
  2484. },
  2485. { "FastReauth", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
  2486. wpas_dbus_getter_fast_reauth,
  2487. wpas_dbus_setter_fast_reauth
  2488. },
  2489. { "ScanInterval", WPAS_DBUS_NEW_IFACE_INTERFACE, "i",
  2490. wpas_dbus_getter_scan_interval,
  2491. wpas_dbus_setter_scan_interval
  2492. },
  2493. { "PKCS11EnginePath", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2494. wpas_dbus_getter_pkcs11_engine_path,
  2495. NULL
  2496. },
  2497. { "PKCS11ModulePath", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2498. wpas_dbus_getter_pkcs11_module_path,
  2499. NULL
  2500. },
  2501. #ifdef CONFIG_WPS
  2502. { "ProcessCredentials", WPAS_DBUS_NEW_IFACE_WPS, "b",
  2503. wpas_dbus_getter_process_credentials,
  2504. wpas_dbus_setter_process_credentials
  2505. },
  2506. { "ConfigMethods", WPAS_DBUS_NEW_IFACE_WPS, "s",
  2507. wpas_dbus_getter_config_methods,
  2508. wpas_dbus_setter_config_methods
  2509. },
  2510. #endif /* CONFIG_WPS */
  2511. #ifdef CONFIG_P2P
  2512. { "P2PDeviceConfig", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "a{sv}",
  2513. wpas_dbus_getter_p2p_device_config,
  2514. wpas_dbus_setter_p2p_device_config
  2515. },
  2516. { "Peers", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
  2517. wpas_dbus_getter_p2p_peers,
  2518. NULL
  2519. },
  2520. { "Role", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "s",
  2521. wpas_dbus_getter_p2p_role,
  2522. NULL
  2523. },
  2524. { "Group", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
  2525. wpas_dbus_getter_p2p_group,
  2526. NULL
  2527. },
  2528. { "PeerGO", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
  2529. wpas_dbus_getter_p2p_peergo,
  2530. NULL
  2531. },
  2532. { "PersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
  2533. wpas_dbus_getter_persistent_groups,
  2534. NULL
  2535. },
  2536. #endif /* CONFIG_P2P */
  2537. { "DisconnectReason", WPAS_DBUS_NEW_IFACE_INTERFACE, "i",
  2538. wpas_dbus_getter_disconnect_reason,
  2539. NULL
  2540. },
  2541. { NULL, NULL, NULL, NULL, NULL }
  2542. };
  2543. static const struct wpa_dbus_signal_desc wpas_dbus_interface_signals[] = {
  2544. { "ScanDone", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2545. {
  2546. { "success", "b", ARG_OUT },
  2547. END_ARGS
  2548. }
  2549. },
  2550. { "BSSAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2551. {
  2552. { "path", "o", ARG_OUT },
  2553. { "properties", "a{sv}", ARG_OUT },
  2554. END_ARGS
  2555. }
  2556. },
  2557. { "BSSRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2558. {
  2559. { "path", "o", ARG_OUT },
  2560. END_ARGS
  2561. }
  2562. },
  2563. { "BlobAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2564. {
  2565. { "name", "s", ARG_OUT },
  2566. END_ARGS
  2567. }
  2568. },
  2569. { "BlobRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2570. {
  2571. { "name", "s", ARG_OUT },
  2572. END_ARGS
  2573. }
  2574. },
  2575. { "NetworkAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2576. {
  2577. { "path", "o", ARG_OUT },
  2578. { "properties", "a{sv}", ARG_OUT },
  2579. END_ARGS
  2580. }
  2581. },
  2582. { "NetworkRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2583. {
  2584. { "path", "o", ARG_OUT },
  2585. END_ARGS
  2586. }
  2587. },
  2588. { "NetworkSelected", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2589. {
  2590. { "path", "o", ARG_OUT },
  2591. END_ARGS
  2592. }
  2593. },
  2594. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  2595. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2596. {
  2597. { "properties", "a{sv}", ARG_OUT },
  2598. END_ARGS
  2599. }
  2600. },
  2601. #ifdef CONFIG_WPS
  2602. { "Event", WPAS_DBUS_NEW_IFACE_WPS,
  2603. {
  2604. { "name", "s", ARG_OUT },
  2605. { "args", "a{sv}", ARG_OUT },
  2606. END_ARGS
  2607. }
  2608. },
  2609. { "Credentials", WPAS_DBUS_NEW_IFACE_WPS,
  2610. {
  2611. { "credentials", "a{sv}", ARG_OUT },
  2612. END_ARGS
  2613. }
  2614. },
  2615. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  2616. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_WPS,
  2617. {
  2618. { "properties", "a{sv}", ARG_OUT },
  2619. END_ARGS
  2620. }
  2621. },
  2622. #endif /* CONFIG_WPS */
  2623. #ifdef CONFIG_P2P
  2624. { "P2PStateChanged", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2625. {
  2626. { "states", "a{ss}", ARG_OUT },
  2627. END_ARGS
  2628. }
  2629. },
  2630. { "DeviceFound", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2631. {
  2632. { "path", "o", ARG_OUT },
  2633. END_ARGS
  2634. }
  2635. },
  2636. { "DeviceLost", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2637. {
  2638. { "path", "o", ARG_OUT },
  2639. END_ARGS
  2640. }
  2641. },
  2642. { "ProvisionDiscoveryRequestDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2643. {
  2644. { "peer_object", "o", ARG_OUT },
  2645. { "pin", "s", ARG_OUT },
  2646. END_ARGS
  2647. }
  2648. },
  2649. { "ProvisionDiscoveryResponseDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2650. {
  2651. { "peer_object", "o", ARG_OUT },
  2652. { "pin", "s", ARG_OUT },
  2653. END_ARGS
  2654. }
  2655. },
  2656. { "ProvisionDiscoveryRequestEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2657. {
  2658. { "peer_object", "o", ARG_OUT },
  2659. END_ARGS
  2660. }
  2661. },
  2662. { "ProvisionDiscoveryResponseEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2663. {
  2664. { "peer_object", "o", ARG_OUT },
  2665. END_ARGS
  2666. }
  2667. },
  2668. { "ProvisionDiscoveryPBCRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2669. {
  2670. { "peer_object", "o", ARG_OUT },
  2671. END_ARGS
  2672. }
  2673. },
  2674. { "ProvisionDiscoveryPBCResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2675. {
  2676. { "peer_object", "o", ARG_OUT },
  2677. END_ARGS
  2678. }
  2679. },
  2680. { "ProvisionDiscoveryFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2681. {
  2682. { "peer_object", "o", ARG_OUT },
  2683. { "status", "i", ARG_OUT },
  2684. END_ARGS
  2685. }
  2686. },
  2687. { "GroupStarted", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2688. {
  2689. { "properties", "a{sv}", ARG_OUT },
  2690. END_ARGS
  2691. }
  2692. },
  2693. { "GONegotiationSuccess", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2694. {
  2695. { "properties", "a{sv}", ARG_OUT },
  2696. END_ARGS
  2697. }
  2698. },
  2699. { "GONegotiationFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2700. {
  2701. { "properties", "a{sv}", ARG_OUT },
  2702. END_ARGS
  2703. }
  2704. },
  2705. { "GONegotiationRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2706. {
  2707. { "path", "o", ARG_OUT },
  2708. { "dev_passwd_id", "i", ARG_OUT },
  2709. END_ARGS
  2710. }
  2711. },
  2712. { "InvitationResult", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2713. {
  2714. { "invite_result", "a{sv}", ARG_OUT },
  2715. END_ARGS
  2716. }
  2717. },
  2718. { "GroupFinished", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2719. {
  2720. { "properties", "a{sv}", ARG_OUT },
  2721. END_ARGS
  2722. }
  2723. },
  2724. { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2725. {
  2726. { "sd_request", "a{sv}", ARG_OUT },
  2727. END_ARGS
  2728. }
  2729. },
  2730. { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2731. {
  2732. { "sd_response", "a{sv}", ARG_OUT },
  2733. END_ARGS
  2734. }
  2735. },
  2736. { "PersistentGroupAdded", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2737. {
  2738. { "path", "o", ARG_OUT },
  2739. { "properties", "a{sv}", ARG_OUT },
  2740. END_ARGS
  2741. }
  2742. },
  2743. { "PersistentGroupRemoved", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2744. {
  2745. { "path", "o", ARG_OUT },
  2746. END_ARGS
  2747. }
  2748. },
  2749. { "WpsFailed", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2750. {
  2751. { "name", "s", ARG_OUT },
  2752. { "args", "a{sv}", ARG_OUT },
  2753. END_ARGS
  2754. }
  2755. },
  2756. #endif /* CONFIG_P2P */
  2757. #ifdef CONFIG_AP
  2758. { "ProbeRequest", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2759. {
  2760. { "args", "a{sv}", ARG_OUT },
  2761. END_ARGS
  2762. }
  2763. },
  2764. #endif /* CONFIG_AP */
  2765. { "Certification", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2766. {
  2767. { "certification", "a{sv}", ARG_OUT },
  2768. END_ARGS
  2769. }
  2770. },
  2771. { "EAP", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2772. {
  2773. { "status", "s", ARG_OUT },
  2774. { "parameter", "s", ARG_OUT },
  2775. END_ARGS
  2776. }
  2777. },
  2778. { "StaAuthorized", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2779. {
  2780. { "name", "s", ARG_OUT },
  2781. END_ARGS
  2782. }
  2783. },
  2784. { "StaDeauthorized", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2785. {
  2786. { "name", "s", ARG_OUT },
  2787. END_ARGS
  2788. }
  2789. },
  2790. { NULL, NULL, { END_ARGS } }
  2791. };
  2792. int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s)
  2793. {
  2794. struct wpa_dbus_object_desc *obj_desc = NULL;
  2795. struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus;
  2796. int next;
  2797. /* Do nothing if the control interface is not turned on */
  2798. if (ctrl_iface == NULL)
  2799. return 0;
  2800. /* Create and set the interface's object path */
  2801. wpa_s->dbus_new_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
  2802. if (wpa_s->dbus_new_path == NULL)
  2803. return -1;
  2804. next = ctrl_iface->next_objid++;
  2805. os_snprintf(wpa_s->dbus_new_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2806. WPAS_DBUS_NEW_PATH_INTERFACES "/%u",
  2807. next);
  2808. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  2809. if (!obj_desc) {
  2810. wpa_printf(MSG_ERROR,
  2811. "Not enough memory to create object description");
  2812. goto err;
  2813. }
  2814. wpas_dbus_register(obj_desc, wpa_s, NULL, wpas_dbus_interface_methods,
  2815. wpas_dbus_interface_properties,
  2816. wpas_dbus_interface_signals);
  2817. wpa_printf(MSG_DEBUG, "dbus: Register interface object '%s'",
  2818. wpa_s->dbus_new_path);
  2819. if (wpa_dbus_register_object_per_iface(ctrl_iface,
  2820. wpa_s->dbus_new_path,
  2821. wpa_s->ifname, obj_desc))
  2822. goto err;
  2823. wpas_dbus_signal_interface_added(wpa_s);
  2824. return 0;
  2825. err:
  2826. os_free(wpa_s->dbus_new_path);
  2827. wpa_s->dbus_new_path = NULL;
  2828. free_dbus_object_desc(obj_desc);
  2829. return -1;
  2830. }
  2831. int wpas_dbus_unregister_interface(struct wpa_supplicant *wpa_s)
  2832. {
  2833. struct wpas_dbus_priv *ctrl_iface;
  2834. /* Do nothing if the control interface is not turned on */
  2835. if (wpa_s == NULL || wpa_s->global == NULL)
  2836. return 0;
  2837. ctrl_iface = wpa_s->global->dbus;
  2838. if (ctrl_iface == NULL)
  2839. return 0;
  2840. wpa_printf(MSG_DEBUG, "dbus: Unregister interface object '%s'",
  2841. wpa_s->dbus_new_path);
  2842. #ifdef CONFIG_AP
  2843. if (wpa_s->preq_notify_peer) {
  2844. wpas_dbus_unsubscribe_noc(ctrl_iface);
  2845. os_free(wpa_s->preq_notify_peer);
  2846. wpa_s->preq_notify_peer = NULL;
  2847. }
  2848. #endif /* CONFIG_AP */
  2849. if (wpa_dbus_unregister_object_per_iface(ctrl_iface,
  2850. wpa_s->dbus_new_path))
  2851. return -1;
  2852. wpas_dbus_signal_interface_removed(wpa_s);
  2853. os_free(wpa_s->dbus_new_path);
  2854. wpa_s->dbus_new_path = NULL;
  2855. return 0;
  2856. }
  2857. #ifdef CONFIG_P2P
  2858. static const struct wpa_dbus_property_desc wpas_dbus_p2p_peer_properties[] = {
  2859. { "DeviceName", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
  2860. wpas_dbus_getter_p2p_peer_device_name,
  2861. NULL
  2862. },
  2863. { "PrimaryDeviceType", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
  2864. wpas_dbus_getter_p2p_peer_primary_device_type,
  2865. NULL
  2866. },
  2867. { "config_method", WPAS_DBUS_NEW_IFACE_P2P_PEER, "q",
  2868. wpas_dbus_getter_p2p_peer_config_method,
  2869. NULL
  2870. },
  2871. { "level", WPAS_DBUS_NEW_IFACE_P2P_PEER, "i",
  2872. wpas_dbus_getter_p2p_peer_level,
  2873. NULL
  2874. },
  2875. { "devicecapability", WPAS_DBUS_NEW_IFACE_P2P_PEER, "y",
  2876. wpas_dbus_getter_p2p_peer_device_capability,
  2877. NULL
  2878. },
  2879. { "groupcapability", WPAS_DBUS_NEW_IFACE_P2P_PEER, "y",
  2880. wpas_dbus_getter_p2p_peer_group_capability,
  2881. NULL
  2882. },
  2883. { "SecondaryDeviceTypes", WPAS_DBUS_NEW_IFACE_P2P_PEER, "aay",
  2884. wpas_dbus_getter_p2p_peer_secondary_device_types,
  2885. NULL
  2886. },
  2887. { "VendorExtension", WPAS_DBUS_NEW_IFACE_P2P_PEER, "aay",
  2888. wpas_dbus_getter_p2p_peer_vendor_extension,
  2889. NULL
  2890. },
  2891. { "IEs", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
  2892. wpas_dbus_getter_p2p_peer_ies,
  2893. NULL
  2894. },
  2895. { "DeviceAddress", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
  2896. wpas_dbus_getter_p2p_peer_device_address,
  2897. NULL
  2898. },
  2899. { "Groups", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ao",
  2900. wpas_dbus_getter_p2p_peer_groups,
  2901. NULL
  2902. },
  2903. { NULL, NULL, NULL, NULL, NULL }
  2904. };
  2905. static const struct wpa_dbus_signal_desc wpas_dbus_p2p_peer_signals[] = {
  2906. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  2907. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_P2P_PEER,
  2908. {
  2909. { "properties", "a{sv}", ARG_OUT },
  2910. END_ARGS
  2911. }
  2912. },
  2913. { NULL, NULL, { END_ARGS } }
  2914. };
  2915. /**
  2916. * wpas_dbus_signal_peer - Send a peer related event signal
  2917. * @wpa_s: %wpa_supplicant network interface data
  2918. * @dev: peer device object
  2919. * @interface: name of the interface emitting this signal.
  2920. * In case of peer objects, it would be emitted by either
  2921. * the "interface object" or by "peer objects"
  2922. * @sig_name: signal name - DeviceFound
  2923. *
  2924. * Notify listeners about event related with newly found p2p peer device
  2925. */
  2926. static void wpas_dbus_signal_peer(struct wpa_supplicant *wpa_s,
  2927. const u8 *dev_addr, const char *interface,
  2928. const char *sig_name)
  2929. {
  2930. struct wpas_dbus_priv *iface;
  2931. DBusMessage *msg;
  2932. DBusMessageIter iter;
  2933. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  2934. if (wpa_s->p2p_mgmt)
  2935. wpa_s = wpa_s->parent;
  2936. iface = wpa_s->global->dbus;
  2937. /* Do nothing if the control interface is not turned on */
  2938. if (iface == NULL)
  2939. return;
  2940. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2941. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  2942. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  2943. msg = dbus_message_new_signal(wpa_s->dbus_new_path, interface,
  2944. sig_name);
  2945. if (msg == NULL)
  2946. return;
  2947. dbus_message_iter_init_append(msg, &iter);
  2948. path = peer_obj_path;
  2949. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  2950. &path))
  2951. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  2952. else
  2953. dbus_connection_send(iface->con, msg, NULL);
  2954. dbus_message_unref(msg);
  2955. }
  2956. /**
  2957. * wpas_dbus_signal_peer_found - Send a peer found signal
  2958. * @wpa_s: %wpa_supplicant network interface data
  2959. * @dev: peer device object
  2960. *
  2961. * Notify listeners about find a p2p peer device found
  2962. */
  2963. void wpas_dbus_signal_peer_device_found(struct wpa_supplicant *wpa_s,
  2964. const u8 *dev_addr)
  2965. {
  2966. wpas_dbus_signal_peer(wpa_s, dev_addr,
  2967. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2968. "DeviceFound");
  2969. }
  2970. /**
  2971. * wpas_dbus_signal_peer_lost - Send a peer lost signal
  2972. * @wpa_s: %wpa_supplicant network interface data
  2973. * @dev: peer device object
  2974. *
  2975. * Notify listeners about lost a p2p peer device
  2976. */
  2977. void wpas_dbus_signal_peer_device_lost(struct wpa_supplicant *wpa_s,
  2978. const u8 *dev_addr)
  2979. {
  2980. wpas_dbus_signal_peer(wpa_s, dev_addr,
  2981. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2982. "DeviceLost");
  2983. }
  2984. /**
  2985. * wpas_dbus_register_peer - Register a discovered peer object with dbus
  2986. * @wpa_s: wpa_supplicant interface structure
  2987. * @ssid: network configuration data
  2988. * Returns: 0 on success, -1 on failure
  2989. *
  2990. * Registers network representing object with dbus
  2991. */
  2992. int wpas_dbus_register_peer(struct wpa_supplicant *wpa_s, const u8 *dev_addr)
  2993. {
  2994. struct wpas_dbus_priv *ctrl_iface;
  2995. struct wpa_dbus_object_desc *obj_desc;
  2996. struct peer_handler_args *arg;
  2997. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2998. /* Do nothing if the control interface is not turned on */
  2999. if (wpa_s == NULL || wpa_s->global == NULL)
  3000. return 0;
  3001. ctrl_iface = wpa_s->global->dbus;
  3002. if (ctrl_iface == NULL)
  3003. return 0;
  3004. if (wpa_s->p2p_mgmt)
  3005. wpa_s = wpa_s->parent;
  3006. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3007. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  3008. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  3009. wpa_printf(MSG_INFO, "dbus: Register peer object '%s'",
  3010. peer_obj_path);
  3011. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  3012. if (!obj_desc) {
  3013. wpa_printf(MSG_ERROR,
  3014. "Not enough memory to create object description");
  3015. goto err;
  3016. }
  3017. /* allocate memory for handlers arguments */
  3018. arg = os_zalloc(sizeof(struct peer_handler_args));
  3019. if (!arg) {
  3020. wpa_printf(MSG_ERROR,
  3021. "Not enough memory to create arguments for method");
  3022. goto err;
  3023. }
  3024. arg->wpa_s = wpa_s;
  3025. os_memcpy(arg->p2p_device_addr, dev_addr, ETH_ALEN);
  3026. wpas_dbus_register(obj_desc, arg, wpa_dbus_free,
  3027. NULL,
  3028. wpas_dbus_p2p_peer_properties,
  3029. wpas_dbus_p2p_peer_signals);
  3030. if (wpa_dbus_register_object_per_iface(ctrl_iface, peer_obj_path,
  3031. wpa_s->ifname, obj_desc))
  3032. goto err;
  3033. return 0;
  3034. err:
  3035. free_dbus_object_desc(obj_desc);
  3036. return -1;
  3037. }
  3038. /**
  3039. * wpas_dbus_unregister_peer - Unregister a peer object with dbus
  3040. * @wpa_s: wpa_supplicant interface structure
  3041. * @dev_addr: p2p device addr
  3042. * Returns: 0 on success, -1 on failure
  3043. *
  3044. * Registers network representing object with dbus
  3045. */
  3046. int wpas_dbus_unregister_peer(struct wpa_supplicant *wpa_s,
  3047. const u8 *dev_addr)
  3048. {
  3049. struct wpas_dbus_priv *ctrl_iface;
  3050. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3051. int ret;
  3052. /* Do nothing if the control interface is not turned on */
  3053. if (wpa_s == NULL || wpa_s->global == NULL ||
  3054. wpa_s->dbus_new_path == NULL)
  3055. return 0;
  3056. if (wpa_s->p2p_mgmt)
  3057. wpa_s = wpa_s->parent;
  3058. ctrl_iface = wpa_s->global->dbus;
  3059. if (ctrl_iface == NULL)
  3060. return 0;
  3061. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3062. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  3063. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  3064. wpa_printf(MSG_INFO, "dbus: Unregister peer object '%s'",
  3065. peer_obj_path);
  3066. ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, peer_obj_path);
  3067. return ret;
  3068. }
  3069. void wpas_dbus_signal_peer_groups_changed(struct wpa_supplicant *wpa_s,
  3070. const u8 *dev_addr)
  3071. {
  3072. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3073. if (wpa_s->p2p_mgmt)
  3074. wpa_s = wpa_s->parent;
  3075. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3076. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  3077. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  3078. wpa_dbus_mark_property_changed(wpa_s->global->dbus, peer_obj_path,
  3079. WPAS_DBUS_NEW_IFACE_P2P_PEER, "Groups");
  3080. }
  3081. static const struct wpa_dbus_property_desc wpas_dbus_p2p_group_properties[] = {
  3082. { "Members", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ao",
  3083. wpas_dbus_getter_p2p_group_members,
  3084. NULL
  3085. },
  3086. { "Group", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "o",
  3087. wpas_dbus_getter_p2p_group,
  3088. NULL
  3089. },
  3090. { "Role", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "s",
  3091. wpas_dbus_getter_p2p_role,
  3092. NULL
  3093. },
  3094. { "SSID", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
  3095. wpas_dbus_getter_p2p_group_ssid,
  3096. NULL
  3097. },
  3098. { "BSSID", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
  3099. wpas_dbus_getter_p2p_group_bssid,
  3100. NULL
  3101. },
  3102. { "Frequency", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "q",
  3103. wpas_dbus_getter_p2p_group_frequency,
  3104. NULL
  3105. },
  3106. { "Passphrase", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "s",
  3107. wpas_dbus_getter_p2p_group_passphrase,
  3108. NULL
  3109. },
  3110. { "PSK", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
  3111. wpas_dbus_getter_p2p_group_psk,
  3112. NULL
  3113. },
  3114. { "WPSVendorExtensions", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "aay",
  3115. wpas_dbus_getter_p2p_group_vendor_ext,
  3116. wpas_dbus_setter_p2p_group_vendor_ext
  3117. },
  3118. { NULL, NULL, NULL, NULL, NULL }
  3119. };
  3120. static const struct wpa_dbus_signal_desc wpas_dbus_p2p_group_signals[] = {
  3121. { "PeerJoined", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
  3122. {
  3123. { "peer", "o", ARG_OUT },
  3124. END_ARGS
  3125. }
  3126. },
  3127. { "PeerDisconnected", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
  3128. {
  3129. { "peer", "o", ARG_OUT },
  3130. END_ARGS
  3131. }
  3132. },
  3133. { NULL, NULL, { END_ARGS } }
  3134. };
  3135. /**
  3136. * wpas_dbus_register_p2p_group - Register a p2p group object with dbus
  3137. * @wpa_s: wpa_supplicant interface structure
  3138. * @ssid: SSID struct
  3139. * Returns: 0 on success, -1 on failure
  3140. *
  3141. * Registers p2p group representing object with dbus
  3142. */
  3143. void wpas_dbus_register_p2p_group(struct wpa_supplicant *wpa_s,
  3144. struct wpa_ssid *ssid)
  3145. {
  3146. struct wpas_dbus_priv *ctrl_iface;
  3147. struct wpa_dbus_object_desc *obj_desc;
  3148. char group_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3149. /* Do nothing if the control interface is not turned on */
  3150. if (wpa_s == NULL || wpa_s->global == NULL)
  3151. return;
  3152. ctrl_iface = wpa_s->global->dbus;
  3153. if (ctrl_iface == NULL)
  3154. return;
  3155. if (wpa_s->dbus_groupobj_path) {
  3156. wpa_printf(MSG_INFO, "%s: Group object '%s' already exists",
  3157. __func__, wpa_s->dbus_groupobj_path);
  3158. return;
  3159. }
  3160. if (wpas_dbus_get_group_obj_path(wpa_s, ssid, group_obj_path) < 0)
  3161. return;
  3162. wpa_s->dbus_groupobj_path = os_strdup(group_obj_path);
  3163. if (wpa_s->dbus_groupobj_path == NULL)
  3164. return;
  3165. wpa_printf(MSG_INFO, "dbus: Register group object '%s'",
  3166. group_obj_path);
  3167. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  3168. if (!obj_desc) {
  3169. wpa_printf(MSG_ERROR,
  3170. "Not enough memory to create object description");
  3171. goto err;
  3172. }
  3173. wpas_dbus_register(obj_desc, wpa_s, NULL, NULL,
  3174. wpas_dbus_p2p_group_properties,
  3175. wpas_dbus_p2p_group_signals);
  3176. if (wpa_dbus_register_object_per_iface(ctrl_iface, group_obj_path,
  3177. wpa_s->ifname, obj_desc))
  3178. goto err;
  3179. return;
  3180. err:
  3181. if (wpa_s->dbus_groupobj_path) {
  3182. os_free(wpa_s->dbus_groupobj_path);
  3183. wpa_s->dbus_groupobj_path = NULL;
  3184. }
  3185. free_dbus_object_desc(obj_desc);
  3186. }
  3187. /**
  3188. * wpas_dbus_unregister_p2p_group - Unregister a p2p group object from dbus
  3189. * @wpa_s: wpa_supplicant interface structure
  3190. * @ssid: network name of the p2p group started
  3191. */
  3192. void wpas_dbus_unregister_p2p_group(struct wpa_supplicant *wpa_s,
  3193. const struct wpa_ssid *ssid)
  3194. {
  3195. struct wpas_dbus_priv *ctrl_iface;
  3196. /* Do nothing if the control interface is not turned on */
  3197. if (wpa_s == NULL || wpa_s->global == NULL)
  3198. return;
  3199. if (wpa_s->p2p_mgmt)
  3200. wpa_s = wpa_s->parent;
  3201. ctrl_iface = wpa_s->global->dbus;
  3202. if (ctrl_iface == NULL)
  3203. return;
  3204. if (!wpa_s->dbus_groupobj_path) {
  3205. wpa_printf(MSG_DEBUG,
  3206. "%s: Group object '%s' already unregistered",
  3207. __func__, wpa_s->dbus_groupobj_path);
  3208. return;
  3209. }
  3210. peer_groups_changed(wpa_s);
  3211. wpa_printf(MSG_DEBUG, "dbus: Unregister group object '%s'",
  3212. wpa_s->dbus_groupobj_path);
  3213. wpa_dbus_unregister_object_per_iface(ctrl_iface,
  3214. wpa_s->dbus_groupobj_path);
  3215. os_free(wpa_s->dbus_groupobj_path);
  3216. wpa_s->dbus_groupobj_path = NULL;
  3217. }
  3218. static const struct wpa_dbus_property_desc
  3219. wpas_dbus_persistent_group_properties[] = {
  3220. { "Properties", WPAS_DBUS_NEW_IFACE_PERSISTENT_GROUP, "a{sv}",
  3221. wpas_dbus_getter_persistent_group_properties,
  3222. wpas_dbus_setter_persistent_group_properties
  3223. },
  3224. { NULL, NULL, NULL, NULL, NULL }
  3225. };
  3226. /* No signals intended for persistent group objects */
  3227. /**
  3228. * wpas_dbus_register_persistent_group - Register a configured(saved)
  3229. * persistent group with dbus
  3230. * @wpa_s: wpa_supplicant interface structure
  3231. * @ssid: persistent group (still represented as a network within wpa)
  3232. * configuration data
  3233. * Returns: 0 on success, -1 on failure
  3234. *
  3235. * Registers a persistent group representing object with dbus.
  3236. */
  3237. int wpas_dbus_register_persistent_group(struct wpa_supplicant *wpa_s,
  3238. struct wpa_ssid *ssid)
  3239. {
  3240. struct wpas_dbus_priv *ctrl_iface;
  3241. struct wpa_dbus_object_desc *obj_desc;
  3242. struct network_handler_args *arg;
  3243. char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3244. /* Do nothing if the control interface is not turned on */
  3245. if (wpa_s == NULL || wpa_s->global == NULL)
  3246. return 0;
  3247. /* Make sure ssid is a persistent group */
  3248. if (ssid->disabled != 2 && !ssid->p2p_persistent_group)
  3249. return -1; /* should we return w/o complaining? */
  3250. if (wpa_s->p2p_mgmt)
  3251. wpa_s = wpa_s->parent;
  3252. ctrl_iface = wpa_s->global->dbus;
  3253. if (ctrl_iface == NULL)
  3254. return 0;
  3255. /*
  3256. * Intentionally not coming up with different numbering scheme
  3257. * for persistent groups.
  3258. */
  3259. os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3260. "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
  3261. wpa_s->dbus_new_path, ssid->id);
  3262. wpa_printf(MSG_DEBUG, "dbus: Register persistent group object '%s'",
  3263. pgrp_obj_path);
  3264. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  3265. if (!obj_desc) {
  3266. wpa_printf(MSG_ERROR,
  3267. "dbus: Not enough memory to create object description");
  3268. goto err;
  3269. }
  3270. /*
  3271. * Reusing the same context structure as that for networks
  3272. * since these are represented using same data structure.
  3273. */
  3274. /* allocate memory for handlers arguments */
  3275. arg = os_zalloc(sizeof(struct network_handler_args));
  3276. if (!arg) {
  3277. wpa_printf(MSG_ERROR,
  3278. "dbus: Not enough memory to create arguments for method");
  3279. goto err;
  3280. }
  3281. arg->wpa_s = wpa_s;
  3282. arg->ssid = ssid;
  3283. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  3284. wpas_dbus_persistent_group_properties,
  3285. NULL);
  3286. if (wpa_dbus_register_object_per_iface(ctrl_iface, pgrp_obj_path,
  3287. wpa_s->ifname, obj_desc))
  3288. goto err;
  3289. wpas_dbus_signal_persistent_group_added(wpa_s, ssid->id);
  3290. return 0;
  3291. err:
  3292. free_dbus_object_desc(obj_desc);
  3293. return -1;
  3294. }
  3295. /**
  3296. * wpas_dbus_unregister_persistent_group - Unregister a persistent_group
  3297. * from dbus
  3298. * @wpa_s: wpa_supplicant interface structure
  3299. * @nid: network id
  3300. * Returns: 0 on success, -1 on failure
  3301. *
  3302. * Unregisters persistent group representing object from dbus
  3303. *
  3304. * NOTE: There is a slight issue with the semantics here. While the
  3305. * implementation simply means the persistent group is unloaded from memory,
  3306. * it should not get interpreted as the group is actually being erased/removed
  3307. * from persistent storage as well.
  3308. */
  3309. int wpas_dbus_unregister_persistent_group(struct wpa_supplicant *wpa_s,
  3310. int nid)
  3311. {
  3312. struct wpas_dbus_priv *ctrl_iface;
  3313. char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3314. int ret;
  3315. /* Do nothing if the control interface is not turned on */
  3316. if (wpa_s == NULL || wpa_s->global == NULL ||
  3317. wpa_s->dbus_new_path == NULL)
  3318. return 0;
  3319. if (wpa_s->p2p_mgmt)
  3320. wpa_s = wpa_s->parent;
  3321. ctrl_iface = wpa_s->global->dbus;
  3322. if (ctrl_iface == NULL)
  3323. return 0;
  3324. os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3325. "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
  3326. wpa_s->dbus_new_path, nid);
  3327. wpa_printf(MSG_DEBUG, "dbus: Unregister persistent group object '%s'",
  3328. pgrp_obj_path);
  3329. ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, pgrp_obj_path);
  3330. if (!ret)
  3331. wpas_dbus_signal_persistent_group_removed(wpa_s, nid);
  3332. return ret;
  3333. }
  3334. #endif /* CONFIG_P2P */