dbus_new.c 87 KB

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