dbus_new.c 84 KB

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