dbus_new.c 86 KB

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