dbus_new.c 87 KB

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