dbus_new.c 85 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304
  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 succesfully 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. WPADBusPropertyAccessor getter;
  1207. char *prop;
  1208. if (wpa_s->dbus_new_path == NULL)
  1209. return; /* Skip signal since D-Bus setup is not yet ready */
  1210. switch (property) {
  1211. case WPAS_DBUS_PROP_AP_SCAN:
  1212. getter = wpas_dbus_getter_ap_scan;
  1213. prop = "ApScan";
  1214. break;
  1215. case WPAS_DBUS_PROP_SCANNING:
  1216. getter = wpas_dbus_getter_scanning;
  1217. prop = "Scanning";
  1218. break;
  1219. case WPAS_DBUS_PROP_STATE:
  1220. getter = wpas_dbus_getter_state;
  1221. prop = "State";
  1222. break;
  1223. case WPAS_DBUS_PROP_CURRENT_BSS:
  1224. getter = wpas_dbus_getter_current_bss;
  1225. prop = "CurrentBSS";
  1226. break;
  1227. case WPAS_DBUS_PROP_CURRENT_NETWORK:
  1228. getter = wpas_dbus_getter_current_network;
  1229. prop = "CurrentNetwork";
  1230. break;
  1231. case WPAS_DBUS_PROP_BSSS:
  1232. getter = wpas_dbus_getter_bsss;
  1233. prop = "BSSs";
  1234. break;
  1235. case WPAS_DBUS_PROP_CURRENT_AUTH_MODE:
  1236. getter = wpas_dbus_getter_current_auth_mode;
  1237. prop = "CurrentAuthMode";
  1238. break;
  1239. default:
  1240. wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
  1241. __func__, property);
  1242. return;
  1243. }
  1244. wpa_dbus_mark_property_changed(wpa_s->global->dbus,
  1245. wpa_s->dbus_new_path,
  1246. WPAS_DBUS_NEW_IFACE_INTERFACE, prop);
  1247. }
  1248. /**
  1249. * wpas_dbus_bss_signal_prop_changed - Signals change of BSS property
  1250. * @wpa_s: %wpa_supplicant network interface data
  1251. * @property: indicates which property has changed
  1252. * @id: unique BSS identifier
  1253. *
  1254. * Sends PropertyChanged signals with path, interface, and arguments depending
  1255. * on which property has changed.
  1256. */
  1257. void wpas_dbus_bss_signal_prop_changed(struct wpa_supplicant *wpa_s,
  1258. enum wpas_dbus_bss_prop property,
  1259. unsigned int id)
  1260. {
  1261. char path[WPAS_DBUS_OBJECT_PATH_MAX];
  1262. char *prop;
  1263. switch (property) {
  1264. case WPAS_DBUS_BSS_PROP_SIGNAL:
  1265. prop = "Signal";
  1266. break;
  1267. case WPAS_DBUS_BSS_PROP_FREQ:
  1268. prop = "Frequency";
  1269. break;
  1270. case WPAS_DBUS_BSS_PROP_MODE:
  1271. prop = "Mode";
  1272. break;
  1273. case WPAS_DBUS_BSS_PROP_PRIVACY:
  1274. prop = "Privacy";
  1275. break;
  1276. case WPAS_DBUS_BSS_PROP_RATES:
  1277. prop = "Rates";
  1278. break;
  1279. case WPAS_DBUS_BSS_PROP_WPA:
  1280. prop = "WPA";
  1281. break;
  1282. case WPAS_DBUS_BSS_PROP_RSN:
  1283. prop = "RSN";
  1284. break;
  1285. case WPAS_DBUS_BSS_PROP_IES:
  1286. prop = "IEs";
  1287. break;
  1288. default:
  1289. wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
  1290. __func__, property);
  1291. return;
  1292. }
  1293. os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
  1294. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  1295. wpa_s->dbus_new_path, id);
  1296. wpa_dbus_mark_property_changed(wpa_s->global->dbus, path,
  1297. WPAS_DBUS_NEW_IFACE_BSS, prop);
  1298. }
  1299. /**
  1300. * wpas_dbus_signal_debug_level_changed - Signals change of debug param
  1301. * @global: wpa_global structure
  1302. *
  1303. * Sends PropertyChanged signals informing that debug level has changed.
  1304. */
  1305. void wpas_dbus_signal_debug_level_changed(struct wpa_global *global)
  1306. {
  1307. wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
  1308. WPAS_DBUS_NEW_INTERFACE,
  1309. "DebugLevel");
  1310. }
  1311. /**
  1312. * wpas_dbus_signal_debug_timestamp_changed - Signals change of debug param
  1313. * @global: wpa_global structure
  1314. *
  1315. * Sends PropertyChanged signals informing that debug timestamp has changed.
  1316. */
  1317. void wpas_dbus_signal_debug_timestamp_changed(struct wpa_global *global)
  1318. {
  1319. wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
  1320. WPAS_DBUS_NEW_INTERFACE,
  1321. "DebugTimestamp");
  1322. }
  1323. /**
  1324. * wpas_dbus_signal_debug_show_keys_changed - Signals change of debug param
  1325. * @global: wpa_global structure
  1326. *
  1327. * Sends PropertyChanged signals informing that debug show_keys has changed.
  1328. */
  1329. void wpas_dbus_signal_debug_show_keys_changed(struct wpa_global *global)
  1330. {
  1331. wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
  1332. WPAS_DBUS_NEW_INTERFACE,
  1333. "DebugShowKeys");
  1334. }
  1335. static void wpas_dbus_register(struct wpa_dbus_object_desc *obj_desc,
  1336. void *priv,
  1337. WPADBusArgumentFreeFunction priv_free,
  1338. const struct wpa_dbus_method_desc *methods,
  1339. const struct wpa_dbus_property_desc *properties,
  1340. const struct wpa_dbus_signal_desc *signals)
  1341. {
  1342. int n;
  1343. obj_desc->user_data = priv;
  1344. obj_desc->user_data_free_func = priv_free;
  1345. obj_desc->methods = methods;
  1346. obj_desc->properties = properties;
  1347. obj_desc->signals = signals;
  1348. for (n = 0; properties && properties->dbus_property; properties++)
  1349. n++;
  1350. obj_desc->prop_changed_flags = os_zalloc(n);
  1351. if (!obj_desc->prop_changed_flags)
  1352. wpa_printf(MSG_DEBUG, "dbus: %s: can't register handlers",
  1353. __func__);
  1354. }
  1355. static const struct wpa_dbus_method_desc wpas_dbus_global_methods[] = {
  1356. { "CreateInterface", WPAS_DBUS_NEW_INTERFACE,
  1357. (WPADBusMethodHandler) &wpas_dbus_handler_create_interface,
  1358. {
  1359. { "args", "a{sv}", ARG_IN },
  1360. { "path", "o", ARG_OUT },
  1361. END_ARGS
  1362. }
  1363. },
  1364. { "RemoveInterface", WPAS_DBUS_NEW_INTERFACE,
  1365. (WPADBusMethodHandler) &wpas_dbus_handler_remove_interface,
  1366. {
  1367. { "path", "o", ARG_IN },
  1368. END_ARGS
  1369. }
  1370. },
  1371. { "GetInterface", WPAS_DBUS_NEW_INTERFACE,
  1372. (WPADBusMethodHandler) &wpas_dbus_handler_get_interface,
  1373. {
  1374. { "ifname", "s", ARG_IN },
  1375. { "path", "o", ARG_OUT },
  1376. END_ARGS
  1377. }
  1378. },
  1379. { NULL, NULL, NULL, { END_ARGS } }
  1380. };
  1381. static const struct wpa_dbus_property_desc wpas_dbus_global_properties[] = {
  1382. { "DebugLevel", WPAS_DBUS_NEW_INTERFACE, "s",
  1383. wpas_dbus_getter_debug_level,
  1384. wpas_dbus_setter_debug_level
  1385. },
  1386. { "DebugTimestamp", WPAS_DBUS_NEW_INTERFACE, "b",
  1387. wpas_dbus_getter_debug_timestamp,
  1388. wpas_dbus_setter_debug_timestamp
  1389. },
  1390. { "DebugShowKeys", WPAS_DBUS_NEW_INTERFACE, "b",
  1391. wpas_dbus_getter_debug_show_keys,
  1392. wpas_dbus_setter_debug_show_keys
  1393. },
  1394. { "Interfaces", WPAS_DBUS_NEW_INTERFACE, "ao",
  1395. wpas_dbus_getter_interfaces,
  1396. NULL
  1397. },
  1398. { "EapMethods", WPAS_DBUS_NEW_INTERFACE, "as",
  1399. wpas_dbus_getter_eap_methods,
  1400. NULL
  1401. },
  1402. { NULL, NULL, NULL, NULL, NULL }
  1403. };
  1404. static const struct wpa_dbus_signal_desc wpas_dbus_global_signals[] = {
  1405. { "InterfaceAdded", WPAS_DBUS_NEW_INTERFACE,
  1406. {
  1407. { "path", "o", ARG_OUT },
  1408. { "properties", "a{sv}", ARG_OUT },
  1409. END_ARGS
  1410. }
  1411. },
  1412. { "InterfaceRemoved", WPAS_DBUS_NEW_INTERFACE,
  1413. {
  1414. { "path", "o", ARG_OUT },
  1415. END_ARGS
  1416. }
  1417. },
  1418. { "PropertiesChanged", WPAS_DBUS_NEW_INTERFACE,
  1419. {
  1420. { "properties", "a{sv}", ARG_OUT },
  1421. END_ARGS
  1422. }
  1423. },
  1424. { NULL, NULL, { END_ARGS } }
  1425. };
  1426. /**
  1427. * wpas_dbus_ctrl_iface_init - Initialize dbus control interface
  1428. * @global: Pointer to global data from wpa_supplicant_init()
  1429. * Returns: 0 on success or -1 on failure
  1430. *
  1431. * Initialize the dbus control interface for wpa_supplicantand and start
  1432. * receiving commands from external programs over the bus.
  1433. */
  1434. int wpas_dbus_ctrl_iface_init(struct wpas_dbus_priv *priv)
  1435. {
  1436. struct wpa_dbus_object_desc *obj_desc;
  1437. int ret;
  1438. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  1439. if (!obj_desc) {
  1440. wpa_printf(MSG_ERROR, "Not enough memory "
  1441. "to create object description");
  1442. return -1;
  1443. }
  1444. wpas_dbus_register(obj_desc, priv->global, NULL,
  1445. wpas_dbus_global_methods,
  1446. wpas_dbus_global_properties,
  1447. wpas_dbus_global_signals);
  1448. wpa_printf(MSG_DEBUG, "dbus: Register D-Bus object '%s'",
  1449. WPAS_DBUS_NEW_PATH);
  1450. ret = wpa_dbus_ctrl_iface_init(priv, WPAS_DBUS_NEW_PATH,
  1451. WPAS_DBUS_NEW_SERVICE,
  1452. obj_desc);
  1453. if (ret < 0)
  1454. free_dbus_object_desc(obj_desc);
  1455. else
  1456. priv->dbus_new_initialized = 1;
  1457. return ret;
  1458. }
  1459. /**
  1460. * wpas_dbus_ctrl_iface_deinit - Deinitialize dbus ctrl interface for
  1461. * wpa_supplicant
  1462. * @iface: Pointer to dbus private data from wpas_dbus_init()
  1463. *
  1464. * Deinitialize the dbus control interface that was initialized with
  1465. * wpas_dbus_ctrl_iface_init().
  1466. */
  1467. void wpas_dbus_ctrl_iface_deinit(struct wpas_dbus_priv *iface)
  1468. {
  1469. if (!iface->dbus_new_initialized)
  1470. return;
  1471. wpa_printf(MSG_DEBUG, "dbus: Unregister D-Bus object '%s'",
  1472. WPAS_DBUS_NEW_PATH);
  1473. dbus_connection_unregister_object_path(iface->con,
  1474. WPAS_DBUS_NEW_PATH);
  1475. }
  1476. static void wpa_dbus_free(void *ptr)
  1477. {
  1478. os_free(ptr);
  1479. }
  1480. static const struct wpa_dbus_property_desc wpas_dbus_network_properties[] = {
  1481. { "Properties", WPAS_DBUS_NEW_IFACE_NETWORK, "a{sv}",
  1482. wpas_dbus_getter_network_properties,
  1483. wpas_dbus_setter_network_properties
  1484. },
  1485. { "Enabled", WPAS_DBUS_NEW_IFACE_NETWORK, "b",
  1486. wpas_dbus_getter_enabled,
  1487. wpas_dbus_setter_enabled
  1488. },
  1489. { NULL, NULL, NULL, NULL, NULL }
  1490. };
  1491. static const struct wpa_dbus_signal_desc wpas_dbus_network_signals[] = {
  1492. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_NETWORK,
  1493. {
  1494. { "properties", "a{sv}", ARG_OUT },
  1495. END_ARGS
  1496. }
  1497. },
  1498. { NULL, NULL, { END_ARGS } }
  1499. };
  1500. /**
  1501. * wpas_dbus_register_network - Register a configured network with dbus
  1502. * @wpa_s: wpa_supplicant interface structure
  1503. * @ssid: network configuration data
  1504. * Returns: 0 on success, -1 on failure
  1505. *
  1506. * Registers network representing object with dbus
  1507. */
  1508. int wpas_dbus_register_network(struct wpa_supplicant *wpa_s,
  1509. struct wpa_ssid *ssid)
  1510. {
  1511. struct wpas_dbus_priv *ctrl_iface;
  1512. struct wpa_dbus_object_desc *obj_desc;
  1513. struct network_handler_args *arg;
  1514. char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  1515. #ifdef CONFIG_P2P
  1516. /*
  1517. * If it is a persistent group register it as such.
  1518. * This is to handle cases where an interface is being initialized
  1519. * with a list of networks read from config.
  1520. */
  1521. if (network_is_persistent_group(ssid))
  1522. return wpas_dbus_register_persistent_group(wpa_s, ssid);
  1523. #endif /* CONFIG_P2P */
  1524. /* Do nothing if the control interface is not turned on */
  1525. if (wpa_s == NULL || wpa_s->global == NULL)
  1526. return 0;
  1527. ctrl_iface = wpa_s->global->dbus;
  1528. if (ctrl_iface == NULL)
  1529. return 0;
  1530. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1531. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  1532. wpa_s->dbus_new_path, ssid->id);
  1533. wpa_printf(MSG_DEBUG, "dbus: Register network object '%s'",
  1534. net_obj_path);
  1535. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  1536. if (!obj_desc) {
  1537. wpa_printf(MSG_ERROR, "Not enough memory "
  1538. "to create object description");
  1539. goto err;
  1540. }
  1541. /* allocate memory for handlers arguments */
  1542. arg = os_zalloc(sizeof(struct network_handler_args));
  1543. if (!arg) {
  1544. wpa_printf(MSG_ERROR, "Not enough memory "
  1545. "to create arguments for method");
  1546. goto err;
  1547. }
  1548. arg->wpa_s = wpa_s;
  1549. arg->ssid = ssid;
  1550. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  1551. wpas_dbus_network_properties,
  1552. wpas_dbus_network_signals);
  1553. if (wpa_dbus_register_object_per_iface(ctrl_iface, net_obj_path,
  1554. wpa_s->ifname, obj_desc))
  1555. goto err;
  1556. wpas_dbus_signal_network_added(wpa_s, ssid->id);
  1557. return 0;
  1558. err:
  1559. free_dbus_object_desc(obj_desc);
  1560. return -1;
  1561. }
  1562. /**
  1563. * wpas_dbus_unregister_network - Unregister a configured network from dbus
  1564. * @wpa_s: wpa_supplicant interface structure
  1565. * @nid: network id
  1566. * Returns: 0 on success, -1 on failure
  1567. *
  1568. * Unregisters network representing object from dbus
  1569. */
  1570. int wpas_dbus_unregister_network(struct wpa_supplicant *wpa_s, int nid)
  1571. {
  1572. struct wpas_dbus_priv *ctrl_iface;
  1573. char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  1574. int ret;
  1575. struct wpa_ssid *ssid;
  1576. ssid = wpa_config_get_network(wpa_s->conf, nid);
  1577. #ifdef CONFIG_P2P
  1578. /* If it is a persistent group unregister it as such */
  1579. if (ssid && network_is_persistent_group(ssid))
  1580. return wpas_dbus_unregister_persistent_group(wpa_s, nid);
  1581. #endif /* CONFIG_P2P */
  1582. /* Do nothing if the control interface is not turned on */
  1583. if (wpa_s == NULL || wpa_s->global == NULL ||
  1584. wpa_s->dbus_new_path == NULL)
  1585. return 0;
  1586. ctrl_iface = wpa_s->global->dbus;
  1587. if (ctrl_iface == NULL)
  1588. return 0;
  1589. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1590. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  1591. wpa_s->dbus_new_path, nid);
  1592. wpa_printf(MSG_DEBUG, "dbus: Unregister network object '%s'",
  1593. net_obj_path);
  1594. ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, net_obj_path);
  1595. if (!ret)
  1596. wpas_dbus_signal_network_removed(wpa_s, nid);
  1597. return ret;
  1598. }
  1599. static const struct wpa_dbus_property_desc wpas_dbus_bss_properties[] = {
  1600. { "SSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
  1601. wpas_dbus_getter_bss_ssid,
  1602. NULL
  1603. },
  1604. { "BSSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
  1605. wpas_dbus_getter_bss_bssid,
  1606. NULL
  1607. },
  1608. { "Privacy", WPAS_DBUS_NEW_IFACE_BSS, "b",
  1609. wpas_dbus_getter_bss_privacy,
  1610. NULL
  1611. },
  1612. { "Mode", WPAS_DBUS_NEW_IFACE_BSS, "s",
  1613. wpas_dbus_getter_bss_mode,
  1614. NULL
  1615. },
  1616. { "Signal", WPAS_DBUS_NEW_IFACE_BSS, "n",
  1617. wpas_dbus_getter_bss_signal,
  1618. NULL
  1619. },
  1620. { "Frequency", WPAS_DBUS_NEW_IFACE_BSS, "q",
  1621. wpas_dbus_getter_bss_frequency,
  1622. NULL
  1623. },
  1624. { "Rates", WPAS_DBUS_NEW_IFACE_BSS, "au",
  1625. wpas_dbus_getter_bss_rates,
  1626. NULL
  1627. },
  1628. { "WPA", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
  1629. wpas_dbus_getter_bss_wpa,
  1630. NULL
  1631. },
  1632. { "RSN", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
  1633. wpas_dbus_getter_bss_rsn,
  1634. NULL
  1635. },
  1636. { "IEs", WPAS_DBUS_NEW_IFACE_BSS, "ay",
  1637. wpas_dbus_getter_bss_ies,
  1638. NULL
  1639. },
  1640. { NULL, NULL, NULL, NULL, NULL }
  1641. };
  1642. static const struct wpa_dbus_signal_desc wpas_dbus_bss_signals[] = {
  1643. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_BSS,
  1644. {
  1645. { "properties", "a{sv}", ARG_OUT },
  1646. END_ARGS
  1647. }
  1648. },
  1649. { NULL, NULL, { END_ARGS } }
  1650. };
  1651. /**
  1652. * wpas_dbus_unregister_bss - Unregister a scanned BSS from dbus
  1653. * @wpa_s: wpa_supplicant interface structure
  1654. * @bssid: scanned network bssid
  1655. * @id: unique BSS identifier
  1656. * Returns: 0 on success, -1 on failure
  1657. *
  1658. * Unregisters BSS representing object from dbus
  1659. */
  1660. int wpas_dbus_unregister_bss(struct wpa_supplicant *wpa_s,
  1661. u8 bssid[ETH_ALEN], unsigned int id)
  1662. {
  1663. struct wpas_dbus_priv *ctrl_iface;
  1664. char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  1665. /* Do nothing if the control interface is not turned on */
  1666. if (wpa_s == NULL || wpa_s->global == NULL)
  1667. return 0;
  1668. ctrl_iface = wpa_s->global->dbus;
  1669. if (ctrl_iface == NULL)
  1670. return 0;
  1671. os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1672. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  1673. wpa_s->dbus_new_path, id);
  1674. wpa_printf(MSG_DEBUG, "dbus: Unregister BSS object '%s'",
  1675. bss_obj_path);
  1676. if (wpa_dbus_unregister_object_per_iface(ctrl_iface, bss_obj_path)) {
  1677. wpa_printf(MSG_ERROR, "dbus: Cannot unregister BSS object %s",
  1678. bss_obj_path);
  1679. return -1;
  1680. }
  1681. wpas_dbus_signal_bss_removed(wpa_s, bss_obj_path);
  1682. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSSS);
  1683. return 0;
  1684. }
  1685. /**
  1686. * wpas_dbus_register_bss - Register a scanned BSS with dbus
  1687. * @wpa_s: wpa_supplicant interface structure
  1688. * @bssid: scanned network bssid
  1689. * @id: unique BSS identifier
  1690. * Returns: 0 on success, -1 on failure
  1691. *
  1692. * Registers BSS representing object with dbus
  1693. */
  1694. int wpas_dbus_register_bss(struct wpa_supplicant *wpa_s,
  1695. u8 bssid[ETH_ALEN], unsigned int id)
  1696. {
  1697. struct wpas_dbus_priv *ctrl_iface;
  1698. struct wpa_dbus_object_desc *obj_desc;
  1699. char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  1700. struct bss_handler_args *arg;
  1701. /* Do nothing if the control interface is not turned on */
  1702. if (wpa_s == NULL || wpa_s->global == NULL)
  1703. return 0;
  1704. ctrl_iface = wpa_s->global->dbus;
  1705. if (ctrl_iface == NULL)
  1706. return 0;
  1707. os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1708. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  1709. wpa_s->dbus_new_path, id);
  1710. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  1711. if (!obj_desc) {
  1712. wpa_printf(MSG_ERROR, "Not enough memory "
  1713. "to create object description");
  1714. goto err;
  1715. }
  1716. arg = os_zalloc(sizeof(struct bss_handler_args));
  1717. if (!arg) {
  1718. wpa_printf(MSG_ERROR, "Not enough memory "
  1719. "to create arguments for handler");
  1720. goto err;
  1721. }
  1722. arg->wpa_s = wpa_s;
  1723. arg->id = id;
  1724. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  1725. wpas_dbus_bss_properties,
  1726. wpas_dbus_bss_signals);
  1727. wpa_printf(MSG_DEBUG, "dbus: Register BSS object '%s'",
  1728. bss_obj_path);
  1729. if (wpa_dbus_register_object_per_iface(ctrl_iface, bss_obj_path,
  1730. wpa_s->ifname, obj_desc)) {
  1731. wpa_printf(MSG_ERROR,
  1732. "Cannot register BSSID dbus object %s.",
  1733. bss_obj_path);
  1734. goto err;
  1735. }
  1736. wpas_dbus_signal_bss_added(wpa_s, bss_obj_path);
  1737. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSSS);
  1738. return 0;
  1739. err:
  1740. free_dbus_object_desc(obj_desc);
  1741. return -1;
  1742. }
  1743. static const struct wpa_dbus_method_desc wpas_dbus_interface_methods[] = {
  1744. { "Scan", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1745. (WPADBusMethodHandler) &wpas_dbus_handler_scan,
  1746. {
  1747. { "args", "a{sv}", ARG_IN },
  1748. END_ARGS
  1749. }
  1750. },
  1751. { "Disconnect", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1752. (WPADBusMethodHandler) &wpas_dbus_handler_disconnect,
  1753. {
  1754. END_ARGS
  1755. }
  1756. },
  1757. { "AddNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1758. (WPADBusMethodHandler) &wpas_dbus_handler_add_network,
  1759. {
  1760. { "args", "a{sv}", ARG_IN },
  1761. { "path", "o", ARG_OUT },
  1762. END_ARGS
  1763. }
  1764. },
  1765. { "RemoveNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1766. (WPADBusMethodHandler) &wpas_dbus_handler_remove_network,
  1767. {
  1768. { "path", "o", ARG_IN },
  1769. END_ARGS
  1770. }
  1771. },
  1772. { "RemoveAllNetworks", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1773. (WPADBusMethodHandler) &wpas_dbus_handler_remove_all_networks,
  1774. {
  1775. END_ARGS
  1776. }
  1777. },
  1778. { "SelectNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1779. (WPADBusMethodHandler) &wpas_dbus_handler_select_network,
  1780. {
  1781. { "path", "o", ARG_IN },
  1782. END_ARGS
  1783. }
  1784. },
  1785. { "AddBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1786. (WPADBusMethodHandler) &wpas_dbus_handler_add_blob,
  1787. {
  1788. { "name", "s", ARG_IN },
  1789. { "data", "ay", ARG_IN },
  1790. END_ARGS
  1791. }
  1792. },
  1793. { "GetBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1794. (WPADBusMethodHandler) &wpas_dbus_handler_get_blob,
  1795. {
  1796. { "name", "s", ARG_IN },
  1797. { "data", "ay", ARG_OUT },
  1798. END_ARGS
  1799. }
  1800. },
  1801. { "RemoveBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1802. (WPADBusMethodHandler) &wpas_dbus_handler_remove_blob,
  1803. {
  1804. { "name", "s", ARG_IN },
  1805. END_ARGS
  1806. }
  1807. },
  1808. #ifdef CONFIG_WPS
  1809. { "Start", WPAS_DBUS_NEW_IFACE_WPS,
  1810. (WPADBusMethodHandler) &wpas_dbus_handler_wps_start,
  1811. {
  1812. { "args", "a{sv}", ARG_IN },
  1813. { "output", "a{sv}", ARG_OUT },
  1814. END_ARGS
  1815. }
  1816. },
  1817. #endif /* CONFIG_WPS */
  1818. #ifdef CONFIG_P2P
  1819. { "Find", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1820. (WPADBusMethodHandler)wpas_dbus_handler_p2p_find,
  1821. {
  1822. { "args", "a{sv}", ARG_IN },
  1823. END_ARGS
  1824. }
  1825. },
  1826. { "StopFind", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1827. (WPADBusMethodHandler)wpas_dbus_handler_p2p_stop_find,
  1828. {
  1829. END_ARGS
  1830. }
  1831. },
  1832. { "Listen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1833. (WPADBusMethodHandler)wpas_dbus_handler_p2p_listen,
  1834. {
  1835. { "timeout", "i", ARG_IN },
  1836. END_ARGS
  1837. }
  1838. },
  1839. { "ExtendedListen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1840. (WPADBusMethodHandler)wpas_dbus_handler_p2p_extendedlisten,
  1841. {
  1842. { "args", "a{sv}", ARG_IN },
  1843. END_ARGS
  1844. }
  1845. },
  1846. { "PresenceRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1847. (WPADBusMethodHandler)wpas_dbus_handler_p2p_presence_request,
  1848. {
  1849. { "args", "a{sv}", ARG_IN },
  1850. END_ARGS
  1851. }
  1852. },
  1853. { "ProvisionDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1854. (WPADBusMethodHandler)wpas_dbus_handler_p2p_prov_disc_req,
  1855. {
  1856. { "peer", "o", ARG_IN },
  1857. { "config_method", "s", ARG_IN },
  1858. END_ARGS
  1859. }
  1860. },
  1861. { "Connect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1862. (WPADBusMethodHandler)wpas_dbus_handler_p2p_connect,
  1863. {
  1864. { "args", "a{sv}", ARG_IN },
  1865. { "generated_pin", "i", ARG_OUT },
  1866. END_ARGS
  1867. }
  1868. },
  1869. { "GroupAdd", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1870. (WPADBusMethodHandler)wpas_dbus_handler_p2p_group_add,
  1871. {
  1872. { "args", "a{sv}", ARG_IN },
  1873. END_ARGS
  1874. }
  1875. },
  1876. { "Invite", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1877. (WPADBusMethodHandler)wpas_dbus_handler_p2p_invite,
  1878. {
  1879. { "args", "a{sv}", ARG_IN },
  1880. END_ARGS
  1881. }
  1882. },
  1883. { "Disconnect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1884. (WPADBusMethodHandler)wpas_dbus_handler_p2p_disconnect,
  1885. {
  1886. END_ARGS
  1887. }
  1888. },
  1889. { "RejectPeer", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1890. (WPADBusMethodHandler)wpas_dbus_handler_p2p_rejectpeer,
  1891. {
  1892. { "peer", "o", ARG_IN },
  1893. END_ARGS
  1894. }
  1895. },
  1896. { "Flush", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1897. (WPADBusMethodHandler)wpas_dbus_handler_p2p_flush,
  1898. {
  1899. END_ARGS
  1900. }
  1901. },
  1902. { "AddService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1903. (WPADBusMethodHandler)wpas_dbus_handler_p2p_add_service,
  1904. {
  1905. { "args", "a{sv}", ARG_IN },
  1906. END_ARGS
  1907. }
  1908. },
  1909. { "DeleteService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1910. (WPADBusMethodHandler)wpas_dbus_handler_p2p_delete_service,
  1911. {
  1912. { "args", "a{sv}", ARG_IN },
  1913. END_ARGS
  1914. }
  1915. },
  1916. { "FlushService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1917. (WPADBusMethodHandler)wpas_dbus_handler_p2p_flush_service,
  1918. {
  1919. END_ARGS
  1920. }
  1921. },
  1922. { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1923. (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_sd_req,
  1924. {
  1925. { "args", "a{sv}", ARG_IN },
  1926. END_ARGS
  1927. }
  1928. },
  1929. { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1930. (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_sd_res,
  1931. {
  1932. { "args", "a{sv}", ARG_IN },
  1933. END_ARGS
  1934. }
  1935. },
  1936. { "ServiceDiscoveryCancelRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1937. (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_sd_cancel_req,
  1938. {
  1939. { "args", "t", ARG_IN },
  1940. END_ARGS
  1941. }
  1942. },
  1943. { "ServiceUpdate", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1944. (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_update,
  1945. {
  1946. END_ARGS
  1947. }
  1948. },
  1949. { "ServiceDiscoveryExternal", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1950. (WPADBusMethodHandler)wpas_dbus_handler_p2p_serv_disc_external,
  1951. {
  1952. { "arg", "i", ARG_IN },
  1953. END_ARGS
  1954. }
  1955. },
  1956. { "ServiceDiscoveryExternal", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1957. (WPADBusMethodHandler)wpas_dbus_handler_p2p_serv_disc_external,
  1958. {
  1959. { "arg", "i", ARG_IN },
  1960. END_ARGS
  1961. }
  1962. },
  1963. { "AddPersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1964. (WPADBusMethodHandler) wpas_dbus_handler_add_persistent_group,
  1965. {
  1966. { "args", "a{sv}", ARG_IN },
  1967. { "path", "o", ARG_OUT },
  1968. END_ARGS
  1969. }
  1970. },
  1971. { "RemovePersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1972. (WPADBusMethodHandler) wpas_dbus_handler_remove_persistent_group,
  1973. {
  1974. { "path", "o", ARG_IN },
  1975. END_ARGS
  1976. }
  1977. },
  1978. { "RemoveAllPersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1979. (WPADBusMethodHandler)
  1980. wpas_dbus_handler_remove_all_persistent_groups,
  1981. {
  1982. END_ARGS
  1983. }
  1984. },
  1985. #endif /* CONFIG_P2P */
  1986. { "FlushBSS", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1987. (WPADBusMethodHandler) &wpas_dbus_handler_flush_bss,
  1988. {
  1989. { "age", "u", ARG_IN },
  1990. END_ARGS
  1991. }
  1992. },
  1993. { NULL, NULL, NULL, { END_ARGS } }
  1994. };
  1995. static const struct wpa_dbus_property_desc wpas_dbus_interface_properties[] = {
  1996. { "Capabilities", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{sv}",
  1997. wpas_dbus_getter_capabilities,
  1998. NULL
  1999. },
  2000. { "State", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2001. wpas_dbus_getter_state,
  2002. NULL
  2003. },
  2004. { "Scanning", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
  2005. wpas_dbus_getter_scanning,
  2006. NULL
  2007. },
  2008. { "ApScan", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  2009. wpas_dbus_getter_ap_scan,
  2010. wpas_dbus_setter_ap_scan
  2011. },
  2012. { "BSSExpireAge", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  2013. wpas_dbus_getter_bss_expire_age,
  2014. wpas_dbus_setter_bss_expire_age
  2015. },
  2016. { "BSSExpireCount", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  2017. wpas_dbus_getter_bss_expire_count,
  2018. wpas_dbus_setter_bss_expire_count
  2019. },
  2020. { "Country", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2021. wpas_dbus_getter_country,
  2022. wpas_dbus_setter_country
  2023. },
  2024. { "Ifname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2025. wpas_dbus_getter_ifname,
  2026. NULL
  2027. },
  2028. { "Driver", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2029. wpas_dbus_getter_driver,
  2030. NULL
  2031. },
  2032. { "BridgeIfname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2033. wpas_dbus_getter_bridge_ifname,
  2034. NULL
  2035. },
  2036. { "CurrentBSS", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
  2037. wpas_dbus_getter_current_bss,
  2038. NULL
  2039. },
  2040. { "CurrentNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
  2041. wpas_dbus_getter_current_network,
  2042. NULL
  2043. },
  2044. { "CurrentAuthMode", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2045. wpas_dbus_getter_current_auth_mode,
  2046. NULL
  2047. },
  2048. { "Blobs", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{say}",
  2049. wpas_dbus_getter_blobs,
  2050. NULL
  2051. },
  2052. { "BSSs", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
  2053. wpas_dbus_getter_bsss,
  2054. NULL
  2055. },
  2056. { "Networks", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
  2057. wpas_dbus_getter_networks,
  2058. NULL
  2059. },
  2060. #ifdef CONFIG_WPS
  2061. { "ProcessCredentials", WPAS_DBUS_NEW_IFACE_WPS, "b",
  2062. wpas_dbus_getter_process_credentials,
  2063. wpas_dbus_setter_process_credentials
  2064. },
  2065. #endif /* CONFIG_WPS */
  2066. #ifdef CONFIG_P2P
  2067. { "P2PDeviceProperties", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "a{sv}",
  2068. wpas_dbus_getter_p2p_device_properties,
  2069. wpas_dbus_setter_p2p_device_properties
  2070. },
  2071. { "Peers", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
  2072. wpas_dbus_getter_p2p_peers,
  2073. NULL
  2074. },
  2075. { "Role", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "s",
  2076. wpas_dbus_getter_p2p_role,
  2077. NULL
  2078. },
  2079. { "Group", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
  2080. wpas_dbus_getter_p2p_group,
  2081. NULL
  2082. },
  2083. { "PeerGO", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
  2084. wpas_dbus_getter_p2p_peergo,
  2085. NULL
  2086. },
  2087. { "PersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
  2088. wpas_dbus_getter_persistent_groups,
  2089. NULL
  2090. },
  2091. #endif /* CONFIG_P2P */
  2092. { NULL, NULL, NULL, NULL, NULL }
  2093. };
  2094. static const struct wpa_dbus_signal_desc wpas_dbus_interface_signals[] = {
  2095. { "ScanDone", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2096. {
  2097. { "success", "b", ARG_OUT },
  2098. END_ARGS
  2099. }
  2100. },
  2101. { "BSSAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2102. {
  2103. { "path", "o", ARG_OUT },
  2104. { "properties", "a{sv}", ARG_OUT },
  2105. END_ARGS
  2106. }
  2107. },
  2108. { "BSSRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2109. {
  2110. { "path", "o", ARG_OUT },
  2111. END_ARGS
  2112. }
  2113. },
  2114. { "BlobAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2115. {
  2116. { "name", "s", ARG_OUT },
  2117. END_ARGS
  2118. }
  2119. },
  2120. { "BlobRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2121. {
  2122. { "name", "s", ARG_OUT },
  2123. END_ARGS
  2124. }
  2125. },
  2126. { "NetworkAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2127. {
  2128. { "path", "o", ARG_OUT },
  2129. { "properties", "a{sv}", ARG_OUT },
  2130. END_ARGS
  2131. }
  2132. },
  2133. { "NetworkRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2134. {
  2135. { "path", "o", ARG_OUT },
  2136. END_ARGS
  2137. }
  2138. },
  2139. { "NetworkSelected", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2140. {
  2141. { "path", "o", ARG_OUT },
  2142. END_ARGS
  2143. }
  2144. },
  2145. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2146. {
  2147. { "properties", "a{sv}", ARG_OUT },
  2148. END_ARGS
  2149. }
  2150. },
  2151. #ifdef CONFIG_WPS
  2152. { "Event", WPAS_DBUS_NEW_IFACE_WPS,
  2153. {
  2154. { "name", "s", ARG_OUT },
  2155. { "args", "a{sv}", ARG_OUT },
  2156. END_ARGS
  2157. }
  2158. },
  2159. { "Credentials", WPAS_DBUS_NEW_IFACE_WPS,
  2160. {
  2161. { "credentials", "a{sv}", ARG_OUT },
  2162. END_ARGS
  2163. }
  2164. },
  2165. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_WPS,
  2166. {
  2167. { "properties", "a{sv}", ARG_OUT },
  2168. END_ARGS
  2169. }
  2170. },
  2171. #endif /* CONFIG_WPS */
  2172. #ifdef CONFIG_P2P
  2173. { "P2PStateChanged", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2174. {
  2175. { "states", "a{ss}", ARG_OUT },
  2176. END_ARGS
  2177. }
  2178. },
  2179. { "DeviceFound", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2180. {
  2181. { "path", "o", ARG_OUT },
  2182. { "properties", "a{sv}", ARG_OUT },
  2183. END_ARGS
  2184. }
  2185. },
  2186. { "DeviceLost", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2187. {
  2188. { "path", "o", ARG_OUT },
  2189. END_ARGS
  2190. }
  2191. },
  2192. { "ProvisionDiscoveryRequestDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2193. {
  2194. { "peer_object", "o", ARG_OUT },
  2195. { "pin", "s", ARG_OUT },
  2196. END_ARGS
  2197. }
  2198. },
  2199. { "ProvisionDiscoveryResponseDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2200. {
  2201. { "peer_object", "o", ARG_OUT },
  2202. { "pin", "s", ARG_OUT },
  2203. END_ARGS
  2204. }
  2205. },
  2206. { "ProvisionDiscoveryRequestEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2207. {
  2208. { "peer_object", "o", ARG_OUT },
  2209. END_ARGS
  2210. }
  2211. },
  2212. { "ProvisionDiscoveryResponseEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2213. {
  2214. { "peer_object", "o", ARG_OUT },
  2215. END_ARGS
  2216. }
  2217. },
  2218. { "ProvisionDiscoveryPBCRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2219. {
  2220. { "peer_object", "o", ARG_OUT },
  2221. END_ARGS
  2222. }
  2223. },
  2224. { "ProvisionDiscoveryPBCResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2225. {
  2226. { "peer_object", "o", ARG_OUT },
  2227. END_ARGS
  2228. }
  2229. },
  2230. { "ProvisionDiscoveryFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2231. {
  2232. { "peer_object", "o", ARG_OUT },
  2233. { "status", "i", ARG_OUT },
  2234. END_ARGS
  2235. }
  2236. },
  2237. { "GroupStarted", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2238. {
  2239. { "properties", "a{sv}", ARG_OUT },
  2240. END_ARGS
  2241. }
  2242. },
  2243. { "GONegotiationSuccess", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2244. {
  2245. END_ARGS
  2246. }
  2247. },
  2248. { "GONegotiationFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2249. {
  2250. { "status", "i", ARG_OUT },
  2251. END_ARGS
  2252. }
  2253. },
  2254. { "GONegotiationRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2255. {
  2256. { "path", "o", ARG_OUT },
  2257. { "dev_passwd_id", "i", ARG_OUT },
  2258. END_ARGS
  2259. }
  2260. },
  2261. { "InvitationResult", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2262. {
  2263. { "invite_result", "a{sv}", ARG_OUT },
  2264. END_ARGS
  2265. }
  2266. },
  2267. { "GroupFinished", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2268. {
  2269. { "ifname", "s", ARG_OUT },
  2270. { "role", "s", ARG_OUT },
  2271. END_ARGS
  2272. }
  2273. },
  2274. { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2275. {
  2276. { "sd_request", "a{sv}", ARG_OUT },
  2277. END_ARGS
  2278. }
  2279. },
  2280. { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2281. {
  2282. { "sd_response", "a{sv}", ARG_OUT },
  2283. END_ARGS
  2284. }
  2285. },
  2286. { "PersistentGroupAdded", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2287. {
  2288. { "path", "o", ARG_OUT },
  2289. { "properties", "a{sv}", ARG_OUT },
  2290. END_ARGS
  2291. }
  2292. },
  2293. { "PersistentGroupRemoved", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2294. {
  2295. { "path", "o", ARG_OUT },
  2296. END_ARGS
  2297. }
  2298. },
  2299. { "WpsFailed", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2300. {
  2301. { "name", "s", ARG_OUT },
  2302. { "args", "a{sv}", ARG_OUT },
  2303. END_ARGS
  2304. }
  2305. },
  2306. #endif /* CONFIG_P2P */
  2307. { "Certification", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2308. {
  2309. { "certification", "a{sv}", ARG_OUT },
  2310. END_ARGS
  2311. }
  2312. },
  2313. { NULL, NULL, { END_ARGS } }
  2314. };
  2315. int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s)
  2316. {
  2317. struct wpa_dbus_object_desc *obj_desc = NULL;
  2318. struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus;
  2319. int next;
  2320. /* Do nothing if the control interface is not turned on */
  2321. if (ctrl_iface == NULL)
  2322. return 0;
  2323. /* Create and set the interface's object path */
  2324. wpa_s->dbus_new_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
  2325. if (wpa_s->dbus_new_path == NULL)
  2326. return -1;
  2327. next = ctrl_iface->next_objid++;
  2328. os_snprintf(wpa_s->dbus_new_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2329. WPAS_DBUS_NEW_PATH_INTERFACES "/%u",
  2330. next);
  2331. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  2332. if (!obj_desc) {
  2333. wpa_printf(MSG_ERROR, "Not enough memory "
  2334. "to create object description");
  2335. goto err;
  2336. }
  2337. wpas_dbus_register(obj_desc, wpa_s, NULL, wpas_dbus_interface_methods,
  2338. wpas_dbus_interface_properties,
  2339. wpas_dbus_interface_signals);
  2340. wpa_printf(MSG_DEBUG, "dbus: Register interface object '%s'",
  2341. wpa_s->dbus_new_path);
  2342. if (wpa_dbus_register_object_per_iface(ctrl_iface,
  2343. wpa_s->dbus_new_path,
  2344. wpa_s->ifname, obj_desc))
  2345. goto err;
  2346. wpas_dbus_signal_interface_added(wpa_s);
  2347. return 0;
  2348. err:
  2349. os_free(wpa_s->dbus_new_path);
  2350. wpa_s->dbus_new_path = NULL;
  2351. free_dbus_object_desc(obj_desc);
  2352. return -1;
  2353. }
  2354. int wpas_dbus_unregister_interface(struct wpa_supplicant *wpa_s)
  2355. {
  2356. struct wpas_dbus_priv *ctrl_iface;
  2357. /* Do nothing if the control interface is not turned on */
  2358. if (wpa_s == NULL || wpa_s->global == NULL)
  2359. return 0;
  2360. ctrl_iface = wpa_s->global->dbus;
  2361. if (ctrl_iface == NULL)
  2362. return 0;
  2363. wpa_printf(MSG_DEBUG, "dbus: Unregister interface object '%s'",
  2364. wpa_s->dbus_new_path);
  2365. if (wpa_dbus_unregister_object_per_iface(ctrl_iface,
  2366. wpa_s->dbus_new_path))
  2367. return -1;
  2368. wpas_dbus_signal_interface_removed(wpa_s);
  2369. os_free(wpa_s->dbus_new_path);
  2370. wpa_s->dbus_new_path = NULL;
  2371. return 0;
  2372. }
  2373. #ifdef CONFIG_P2P
  2374. static const struct wpa_dbus_property_desc wpas_dbus_p2p_peer_properties[] = {
  2375. { "Properties", WPAS_DBUS_NEW_IFACE_P2P_PEER, "a{sv}",
  2376. wpas_dbus_getter_p2p_peer_properties,
  2377. NULL
  2378. },
  2379. { "IEs", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
  2380. wpas_dbus_getter_p2p_peer_ies,
  2381. NULL
  2382. },
  2383. { NULL, NULL, NULL, NULL, NULL }
  2384. };
  2385. static const struct wpa_dbus_signal_desc wpas_dbus_p2p_peer_signals[] = {
  2386. { NULL, NULL, { END_ARGS } }
  2387. };
  2388. /**
  2389. * wpas_dbus_signal_peer - Send a peer related event signal
  2390. * @wpa_s: %wpa_supplicant network interface data
  2391. * @dev: peer device object
  2392. * @interface: name of the interface emitting this signal.
  2393. * In case of peer objects, it would be emitted by either
  2394. * the "interface object" or by "peer objects"
  2395. * @sig_name: signal name - DeviceFound
  2396. *
  2397. * Notify listeners about event related with newly found p2p peer device
  2398. */
  2399. static void wpas_dbus_signal_peer(struct wpa_supplicant *wpa_s,
  2400. const u8 *dev_addr, const char *interface,
  2401. const char *sig_name)
  2402. {
  2403. struct wpas_dbus_priv *iface;
  2404. DBusMessage *msg;
  2405. DBusMessageIter iter;
  2406. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  2407. iface = wpa_s->global->dbus;
  2408. /* Do nothing if the control interface is not turned on */
  2409. if (iface == NULL)
  2410. return;
  2411. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2412. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  2413. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  2414. msg = dbus_message_new_signal(wpa_s->dbus_new_path, interface,
  2415. sig_name);
  2416. if (msg == NULL)
  2417. return;
  2418. dbus_message_iter_init_append(msg, &iter);
  2419. path = peer_obj_path;
  2420. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  2421. &path))
  2422. goto err;
  2423. dbus_connection_send(iface->con, msg, NULL);
  2424. dbus_message_unref(msg);
  2425. return;
  2426. err:
  2427. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  2428. dbus_message_unref(msg);
  2429. }
  2430. /**
  2431. * wpas_dbus_signal_peer_found - Send a peer found signal
  2432. * @wpa_s: %wpa_supplicant network interface data
  2433. * @dev: peer device object
  2434. *
  2435. * Notify listeners about find a p2p peer device found
  2436. */
  2437. void wpas_dbus_signal_peer_device_found(struct wpa_supplicant *wpa_s,
  2438. const u8 *dev_addr)
  2439. {
  2440. wpas_dbus_signal_peer(wpa_s, dev_addr,
  2441. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2442. "DeviceFound");
  2443. }
  2444. /**
  2445. * wpas_dbus_signal_peer_lost - Send a peer lost signal
  2446. * @wpa_s: %wpa_supplicant network interface data
  2447. * @dev: peer device object
  2448. *
  2449. * Notify listeners about lost a p2p peer device
  2450. */
  2451. void wpas_dbus_signal_peer_device_lost(struct wpa_supplicant *wpa_s,
  2452. const u8 *dev_addr)
  2453. {
  2454. wpas_dbus_signal_peer(wpa_s, dev_addr,
  2455. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2456. "DeviceLost");
  2457. }
  2458. /**
  2459. * wpas_dbus_register_peer - Register a discovered peer object with dbus
  2460. * @wpa_s: wpa_supplicant interface structure
  2461. * @ssid: network configuration data
  2462. * Returns: 0 on success, -1 on failure
  2463. *
  2464. * Registers network representing object with dbus
  2465. */
  2466. int wpas_dbus_register_peer(struct wpa_supplicant *wpa_s, const u8 *dev_addr)
  2467. {
  2468. struct wpas_dbus_priv *ctrl_iface;
  2469. struct wpa_dbus_object_desc *obj_desc;
  2470. struct peer_handler_args *arg;
  2471. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2472. /* Do nothing if the control interface is not turned on */
  2473. if (wpa_s == NULL || wpa_s->global == NULL)
  2474. return 0;
  2475. ctrl_iface = wpa_s->global->dbus;
  2476. if (ctrl_iface == NULL)
  2477. return 0;
  2478. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2479. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  2480. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  2481. wpa_printf(MSG_INFO, "dbus: Register peer object '%s'",
  2482. peer_obj_path);
  2483. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  2484. if (!obj_desc) {
  2485. wpa_printf(MSG_ERROR, "Not enough memory "
  2486. "to create object description");
  2487. goto err;
  2488. }
  2489. /* allocate memory for handlers arguments */
  2490. arg = os_zalloc(sizeof(struct peer_handler_args));
  2491. if (!arg) {
  2492. wpa_printf(MSG_ERROR, "Not enough memory "
  2493. "to create arguments for method");
  2494. goto err;
  2495. }
  2496. arg->wpa_s = wpa_s;
  2497. os_memcpy(arg->p2p_device_addr, dev_addr, ETH_ALEN);
  2498. wpas_dbus_register(obj_desc, arg, wpa_dbus_free,
  2499. NULL,
  2500. wpas_dbus_p2p_peer_properties,
  2501. wpas_dbus_p2p_peer_signals);
  2502. if (wpa_dbus_register_object_per_iface(ctrl_iface, peer_obj_path,
  2503. wpa_s->ifname, obj_desc))
  2504. goto err;
  2505. return 0;
  2506. err:
  2507. free_dbus_object_desc(obj_desc);
  2508. return -1;
  2509. }
  2510. /**
  2511. * wpas_dbus_unregister_peer - Unregister a peer object with dbus
  2512. * @wpa_s: wpa_supplicant interface structure
  2513. * @dev_addr: p2p device addr
  2514. * Returns: 0 on success, -1 on failure
  2515. *
  2516. * Registers network representing object with dbus
  2517. */
  2518. int wpas_dbus_unregister_peer(struct wpa_supplicant *wpa_s,
  2519. const u8 *dev_addr)
  2520. {
  2521. struct wpas_dbus_priv *ctrl_iface;
  2522. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2523. int ret;
  2524. /* Do nothing if the control interface is not turned on */
  2525. if (wpa_s == NULL || wpa_s->global == NULL ||
  2526. wpa_s->dbus_new_path == NULL)
  2527. return 0;
  2528. ctrl_iface = wpa_s->global->dbus;
  2529. if (ctrl_iface == NULL)
  2530. return 0;
  2531. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2532. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  2533. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  2534. wpa_printf(MSG_INFO, "dbus: Unregister peer object '%s'",
  2535. peer_obj_path);
  2536. ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, peer_obj_path);
  2537. return ret;
  2538. }
  2539. static const struct wpa_dbus_property_desc wpas_dbus_p2p_group_properties[] = {
  2540. { "Members", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ao",
  2541. wpas_dbus_getter_p2p_group_members,
  2542. NULL
  2543. },
  2544. { "Properties",
  2545. WPAS_DBUS_NEW_IFACE_P2P_GROUP, "a{sv}",
  2546. wpas_dbus_getter_p2p_group_properties,
  2547. wpas_dbus_setter_p2p_group_properties
  2548. },
  2549. { NULL, NULL, NULL, NULL, NULL }
  2550. };
  2551. static const struct wpa_dbus_signal_desc wpas_dbus_p2p_group_signals[] = {
  2552. { "PeerJoined", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
  2553. {
  2554. { "peer", "o", ARG_OUT },
  2555. END_ARGS
  2556. }
  2557. },
  2558. { "PeerDisconnected", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
  2559. {
  2560. { "peer", "o", ARG_OUT },
  2561. END_ARGS
  2562. }
  2563. },
  2564. { NULL, NULL, { END_ARGS } }
  2565. };
  2566. /**
  2567. * wpas_dbus_register_p2p_group - Register a p2p group object with dbus
  2568. * @wpa_s: wpa_supplicant interface structure
  2569. * @ssid: SSID struct
  2570. * Returns: 0 on success, -1 on failure
  2571. *
  2572. * Registers p2p group representing object with dbus
  2573. */
  2574. void wpas_dbus_register_p2p_group(struct wpa_supplicant *wpa_s,
  2575. struct wpa_ssid *ssid)
  2576. {
  2577. struct wpas_dbus_priv *ctrl_iface;
  2578. struct wpa_dbus_object_desc *obj_desc;
  2579. char group_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2580. /* Do nothing if the control interface is not turned on */
  2581. if (wpa_s == NULL || wpa_s->global == NULL)
  2582. return;
  2583. ctrl_iface = wpa_s->global->dbus;
  2584. if (ctrl_iface == NULL)
  2585. return;
  2586. if (wpa_s->dbus_groupobj_path) {
  2587. wpa_printf(MSG_INFO, "%s: Group object '%s' already exists",
  2588. __func__, wpa_s->dbus_groupobj_path);
  2589. return;
  2590. }
  2591. if (wpas_dbus_get_group_obj_path(wpa_s, ssid, group_obj_path) < 0)
  2592. return;
  2593. wpa_s->dbus_groupobj_path = os_strdup(group_obj_path);
  2594. if (wpa_s->dbus_groupobj_path == NULL)
  2595. return;
  2596. wpa_printf(MSG_INFO, "dbus: Register group object '%s'",
  2597. group_obj_path);
  2598. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  2599. if (!obj_desc) {
  2600. wpa_printf(MSG_ERROR, "Not enough memory "
  2601. "to create object description");
  2602. goto err;
  2603. }
  2604. wpas_dbus_register(obj_desc, wpa_s, NULL, NULL,
  2605. wpas_dbus_p2p_group_properties,
  2606. wpas_dbus_p2p_group_signals);
  2607. if (wpa_dbus_register_object_per_iface(ctrl_iface, group_obj_path,
  2608. wpa_s->ifname, obj_desc))
  2609. goto err;
  2610. return;
  2611. err:
  2612. if (wpa_s->dbus_groupobj_path) {
  2613. os_free(wpa_s->dbus_groupobj_path);
  2614. wpa_s->dbus_groupobj_path = NULL;
  2615. }
  2616. free_dbus_object_desc(obj_desc);
  2617. }
  2618. /**
  2619. * wpas_dbus_unregister_p2p_group - Unregister a p2p group object from dbus
  2620. * @wpa_s: wpa_supplicant interface structure
  2621. * @ssid: network name of the p2p group started
  2622. */
  2623. void wpas_dbus_unregister_p2p_group(struct wpa_supplicant *wpa_s,
  2624. const struct wpa_ssid *ssid)
  2625. {
  2626. struct wpas_dbus_priv *ctrl_iface;
  2627. /* Do nothing if the control interface is not turned on */
  2628. if (wpa_s == NULL || wpa_s->global == NULL)
  2629. return;
  2630. ctrl_iface = wpa_s->global->dbus;
  2631. if (ctrl_iface == NULL)
  2632. return;
  2633. if (!wpa_s->dbus_groupobj_path) {
  2634. wpa_printf(MSG_DEBUG,
  2635. "%s: Group object '%s' already unregistered",
  2636. __func__, wpa_s->dbus_groupobj_path);
  2637. return;
  2638. }
  2639. wpa_printf(MSG_DEBUG, "dbus: Unregister group object '%s'",
  2640. wpa_s->dbus_groupobj_path);
  2641. wpa_dbus_unregister_object_per_iface(ctrl_iface,
  2642. wpa_s->dbus_groupobj_path);
  2643. os_free(wpa_s->dbus_groupobj_path);
  2644. wpa_s->dbus_groupobj_path = NULL;
  2645. }
  2646. static const struct wpa_dbus_property_desc
  2647. wpas_dbus_p2p_groupmember_properties[] = {
  2648. { "Properties", WPAS_DBUS_NEW_IFACE_P2P_GROUPMEMBER, "a{sv}",
  2649. wpas_dbus_getter_p2p_group_properties,
  2650. NULL
  2651. },
  2652. { NULL, NULL, NULL, NULL, NULL }
  2653. };
  2654. /**
  2655. * wpas_dbus_register_p2p_groupmember - Register a p2p groupmember
  2656. * object with dbus
  2657. * @wpa_s: wpa_supplicant interface structure
  2658. * @p2p_if_addr: i/f addr of the device joining this group
  2659. *
  2660. * Registers p2p groupmember representing object with dbus
  2661. */
  2662. void wpas_dbus_register_p2p_groupmember(struct wpa_supplicant *wpa_s,
  2663. const u8 *p2p_if_addr)
  2664. {
  2665. struct wpas_dbus_priv *ctrl_iface;
  2666. struct wpa_dbus_object_desc *obj_desc = NULL;
  2667. struct groupmember_handler_args *arg;
  2668. char groupmember_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2669. /* Do nothing if the control interface is not turned on */
  2670. if (wpa_s == NULL || wpa_s->global == NULL)
  2671. return;
  2672. ctrl_iface = wpa_s->global->dbus;
  2673. if (ctrl_iface == NULL)
  2674. return;
  2675. if (!wpa_s->dbus_groupobj_path)
  2676. return;
  2677. os_snprintf(groupmember_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2678. "%s/" WPAS_DBUS_NEW_P2P_GROUPMEMBERS_PART "/" COMPACT_MACSTR,
  2679. wpa_s->dbus_groupobj_path, MAC2STR(p2p_if_addr));
  2680. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  2681. if (!obj_desc) {
  2682. wpa_printf(MSG_ERROR, "Not enough memory "
  2683. "to create object description");
  2684. goto err;
  2685. }
  2686. /* allocate memory for handlers arguments */
  2687. arg = os_zalloc(sizeof(struct groupmember_handler_args));
  2688. if (!arg) {
  2689. wpa_printf(MSG_ERROR, "Not enough memory "
  2690. "to create arguments for method");
  2691. goto err;
  2692. }
  2693. arg->wpa_s = wpa_s;
  2694. os_memcpy(arg->member_addr, p2p_if_addr, ETH_ALEN);
  2695. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  2696. wpas_dbus_p2p_groupmember_properties, NULL);
  2697. if (wpa_dbus_register_object_per_iface(ctrl_iface, groupmember_obj_path,
  2698. wpa_s->ifname, obj_desc))
  2699. goto err;
  2700. wpa_printf(MSG_INFO,
  2701. "dbus: Registered group member object '%s' successfully",
  2702. groupmember_obj_path);
  2703. return;
  2704. err:
  2705. free_dbus_object_desc(obj_desc);
  2706. }
  2707. /**
  2708. * wpas_dbus_unregister_p2p_groupmember - Unregister a p2p groupmember
  2709. * object with dbus
  2710. * @wpa_s: wpa_supplicant interface structure
  2711. * @p2p_if_addr: i/f addr of the device joining this group
  2712. *
  2713. * Unregisters p2p groupmember representing object with dbus
  2714. */
  2715. void wpas_dbus_unregister_p2p_groupmember(struct wpa_supplicant *wpa_s,
  2716. const u8 *p2p_if_addr)
  2717. {
  2718. struct wpas_dbus_priv *ctrl_iface;
  2719. char groupmember_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2720. /* Do nothing if the control interface is not turned on */
  2721. if (wpa_s == NULL || wpa_s->global == NULL)
  2722. return;
  2723. ctrl_iface = wpa_s->global->dbus;
  2724. if (ctrl_iface == NULL)
  2725. return;
  2726. if (!wpa_s->dbus_groupobj_path)
  2727. return;
  2728. os_snprintf(groupmember_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2729. "%s/" WPAS_DBUS_NEW_P2P_GROUPMEMBERS_PART "/" COMPACT_MACSTR,
  2730. wpa_s->dbus_groupobj_path, MAC2STR(p2p_if_addr));
  2731. wpa_dbus_unregister_object_per_iface(ctrl_iface, groupmember_obj_path);
  2732. }
  2733. static const struct wpa_dbus_property_desc
  2734. wpas_dbus_persistent_group_properties[] = {
  2735. { "Properties", WPAS_DBUS_NEW_IFACE_PERSISTENT_GROUP, "a{sv}",
  2736. wpas_dbus_getter_persistent_group_properties,
  2737. wpas_dbus_setter_persistent_group_properties
  2738. },
  2739. { NULL, NULL, NULL, NULL, NULL }
  2740. };
  2741. /* No signals intended for persistent group objects */
  2742. /**
  2743. * wpas_dbus_register_persistent_group - Register a configured(saved)
  2744. * persistent group with dbus
  2745. * @wpa_s: wpa_supplicant interface structure
  2746. * @ssid: persistent group (still represented as a network within wpa)
  2747. * configuration data
  2748. * Returns: 0 on success, -1 on failure
  2749. *
  2750. * Registers a persistent group representing object with dbus.
  2751. */
  2752. int wpas_dbus_register_persistent_group(struct wpa_supplicant *wpa_s,
  2753. struct wpa_ssid *ssid)
  2754. {
  2755. struct wpas_dbus_priv *ctrl_iface;
  2756. struct wpa_dbus_object_desc *obj_desc;
  2757. struct network_handler_args *arg;
  2758. char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2759. /* Do nothing if the control interface is not turned on */
  2760. if (wpa_s == NULL || wpa_s->global == NULL)
  2761. return 0;
  2762. /* Make sure ssid is a persistent group */
  2763. if (ssid->disabled != 2 && !ssid->p2p_persistent_group)
  2764. return -1; /* should we return w/o complaining? */
  2765. ctrl_iface = wpa_s->global->dbus;
  2766. if (ctrl_iface == NULL)
  2767. return 0;
  2768. /*
  2769. * Intentionally not coming up with different numbering scheme
  2770. * for persistent groups.
  2771. */
  2772. os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2773. "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
  2774. wpa_s->dbus_new_path, ssid->id);
  2775. wpa_printf(MSG_DEBUG, "dbus: Register persistent group object '%s'",
  2776. pgrp_obj_path);
  2777. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  2778. if (!obj_desc) {
  2779. wpa_printf(MSG_ERROR, "dbus: Not enough memory to create "
  2780. "object description");
  2781. goto err;
  2782. }
  2783. /*
  2784. * Reusing the same context structure as that for networks
  2785. * since these are represented using same data structure.
  2786. */
  2787. /* allocate memory for handlers arguments */
  2788. arg = os_zalloc(sizeof(struct network_handler_args));
  2789. if (!arg) {
  2790. wpa_printf(MSG_ERROR, "dbus: Not enough memory to create "
  2791. "arguments for method");
  2792. goto err;
  2793. }
  2794. arg->wpa_s = wpa_s;
  2795. arg->ssid = ssid;
  2796. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  2797. wpas_dbus_persistent_group_properties,
  2798. NULL);
  2799. if (wpa_dbus_register_object_per_iface(ctrl_iface, pgrp_obj_path,
  2800. wpa_s->ifname, obj_desc))
  2801. goto err;
  2802. wpas_dbus_signal_persistent_group_added(wpa_s, ssid->id);
  2803. return 0;
  2804. err:
  2805. free_dbus_object_desc(obj_desc);
  2806. return -1;
  2807. }
  2808. /**
  2809. * wpas_dbus_unregister_persistent_group - Unregister a persistent_group
  2810. * from dbus
  2811. * @wpa_s: wpa_supplicant interface structure
  2812. * @nid: network id
  2813. * Returns: 0 on success, -1 on failure
  2814. *
  2815. * Unregisters persistent group representing object from dbus
  2816. *
  2817. * NOTE: There is a slight issue with the semantics here. While the
  2818. * implementation simply means the persistent group is unloaded from memory,
  2819. * it should not get interpreted as the group is actually being erased/removed
  2820. * from persistent storage as well.
  2821. */
  2822. int wpas_dbus_unregister_persistent_group(struct wpa_supplicant *wpa_s,
  2823. int nid)
  2824. {
  2825. struct wpas_dbus_priv *ctrl_iface;
  2826. char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2827. int ret;
  2828. /* Do nothing if the control interface is not turned on */
  2829. if (wpa_s == NULL || wpa_s->global == NULL ||
  2830. wpa_s->dbus_new_path == NULL)
  2831. return 0;
  2832. ctrl_iface = wpa_s->global->dbus;
  2833. if (ctrl_iface == NULL)
  2834. return 0;
  2835. os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2836. "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
  2837. wpa_s->dbus_new_path, nid);
  2838. wpa_printf(MSG_DEBUG, "dbus: Unregister persistent group object '%s'",
  2839. pgrp_obj_path);
  2840. ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, pgrp_obj_path);
  2841. if (!ret)
  2842. wpas_dbus_signal_persistent_group_removed(wpa_s, nid);
  2843. return ret;
  2844. }
  2845. #endif /* CONFIG_P2P */