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