dbus_new.c 102 KB

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