dbus_new.c 87 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370
  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. { "AddBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1840. (WPADBusMethodHandler) &wpas_dbus_handler_add_blob,
  1841. {
  1842. { "name", "s", ARG_IN },
  1843. { "data", "ay", ARG_IN },
  1844. END_ARGS
  1845. }
  1846. },
  1847. { "GetBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1848. (WPADBusMethodHandler) &wpas_dbus_handler_get_blob,
  1849. {
  1850. { "name", "s", ARG_IN },
  1851. { "data", "ay", ARG_OUT },
  1852. END_ARGS
  1853. }
  1854. },
  1855. { "RemoveBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1856. (WPADBusMethodHandler) &wpas_dbus_handler_remove_blob,
  1857. {
  1858. { "name", "s", ARG_IN },
  1859. END_ARGS
  1860. }
  1861. },
  1862. #ifdef CONFIG_WPS
  1863. { "Start", WPAS_DBUS_NEW_IFACE_WPS,
  1864. (WPADBusMethodHandler) &wpas_dbus_handler_wps_start,
  1865. {
  1866. { "args", "a{sv}", ARG_IN },
  1867. { "output", "a{sv}", ARG_OUT },
  1868. END_ARGS
  1869. }
  1870. },
  1871. #endif /* CONFIG_WPS */
  1872. #ifdef CONFIG_P2P
  1873. { "Find", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1874. (WPADBusMethodHandler)wpas_dbus_handler_p2p_find,
  1875. {
  1876. { "args", "a{sv}", ARG_IN },
  1877. END_ARGS
  1878. }
  1879. },
  1880. { "StopFind", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1881. (WPADBusMethodHandler)wpas_dbus_handler_p2p_stop_find,
  1882. {
  1883. END_ARGS
  1884. }
  1885. },
  1886. { "Listen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1887. (WPADBusMethodHandler)wpas_dbus_handler_p2p_listen,
  1888. {
  1889. { "timeout", "i", ARG_IN },
  1890. END_ARGS
  1891. }
  1892. },
  1893. { "ExtendedListen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1894. (WPADBusMethodHandler)wpas_dbus_handler_p2p_extendedlisten,
  1895. {
  1896. { "args", "a{sv}", ARG_IN },
  1897. END_ARGS
  1898. }
  1899. },
  1900. { "PresenceRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1901. (WPADBusMethodHandler)wpas_dbus_handler_p2p_presence_request,
  1902. {
  1903. { "args", "a{sv}", ARG_IN },
  1904. END_ARGS
  1905. }
  1906. },
  1907. { "ProvisionDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1908. (WPADBusMethodHandler)wpas_dbus_handler_p2p_prov_disc_req,
  1909. {
  1910. { "peer", "o", ARG_IN },
  1911. { "config_method", "s", ARG_IN },
  1912. END_ARGS
  1913. }
  1914. },
  1915. { "Connect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1916. (WPADBusMethodHandler)wpas_dbus_handler_p2p_connect,
  1917. {
  1918. { "args", "a{sv}", ARG_IN },
  1919. { "generated_pin", "s", ARG_OUT },
  1920. END_ARGS
  1921. }
  1922. },
  1923. { "GroupAdd", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1924. (WPADBusMethodHandler)wpas_dbus_handler_p2p_group_add,
  1925. {
  1926. { "args", "a{sv}", ARG_IN },
  1927. END_ARGS
  1928. }
  1929. },
  1930. { "Invite", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1931. (WPADBusMethodHandler)wpas_dbus_handler_p2p_invite,
  1932. {
  1933. { "args", "a{sv}", ARG_IN },
  1934. END_ARGS
  1935. }
  1936. },
  1937. { "Disconnect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1938. (WPADBusMethodHandler)wpas_dbus_handler_p2p_disconnect,
  1939. {
  1940. END_ARGS
  1941. }
  1942. },
  1943. { "RejectPeer", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1944. (WPADBusMethodHandler)wpas_dbus_handler_p2p_rejectpeer,
  1945. {
  1946. { "peer", "o", ARG_IN },
  1947. END_ARGS
  1948. }
  1949. },
  1950. { "Flush", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1951. (WPADBusMethodHandler)wpas_dbus_handler_p2p_flush,
  1952. {
  1953. END_ARGS
  1954. }
  1955. },
  1956. { "AddService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1957. (WPADBusMethodHandler)wpas_dbus_handler_p2p_add_service,
  1958. {
  1959. { "args", "a{sv}", ARG_IN },
  1960. END_ARGS
  1961. }
  1962. },
  1963. { "DeleteService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1964. (WPADBusMethodHandler)wpas_dbus_handler_p2p_delete_service,
  1965. {
  1966. { "args", "a{sv}", ARG_IN },
  1967. END_ARGS
  1968. }
  1969. },
  1970. { "FlushService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1971. (WPADBusMethodHandler)wpas_dbus_handler_p2p_flush_service,
  1972. {
  1973. END_ARGS
  1974. }
  1975. },
  1976. { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1977. (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_sd_req,
  1978. {
  1979. { "args", "a{sv}", ARG_IN },
  1980. END_ARGS
  1981. }
  1982. },
  1983. { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1984. (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_sd_res,
  1985. {
  1986. { "args", "a{sv}", ARG_IN },
  1987. END_ARGS
  1988. }
  1989. },
  1990. { "ServiceDiscoveryCancelRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1991. (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_sd_cancel_req,
  1992. {
  1993. { "args", "t", ARG_IN },
  1994. END_ARGS
  1995. }
  1996. },
  1997. { "ServiceUpdate", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1998. (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_update,
  1999. {
  2000. END_ARGS
  2001. }
  2002. },
  2003. { "ServiceDiscoveryExternal", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2004. (WPADBusMethodHandler)wpas_dbus_handler_p2p_serv_disc_external,
  2005. {
  2006. { "arg", "i", ARG_IN },
  2007. END_ARGS
  2008. }
  2009. },
  2010. { "ServiceDiscoveryExternal", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2011. (WPADBusMethodHandler)wpas_dbus_handler_p2p_serv_disc_external,
  2012. {
  2013. { "arg", "i", ARG_IN },
  2014. END_ARGS
  2015. }
  2016. },
  2017. { "AddPersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2018. (WPADBusMethodHandler) wpas_dbus_handler_add_persistent_group,
  2019. {
  2020. { "args", "a{sv}", ARG_IN },
  2021. { "path", "o", ARG_OUT },
  2022. END_ARGS
  2023. }
  2024. },
  2025. { "RemovePersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2026. (WPADBusMethodHandler) wpas_dbus_handler_remove_persistent_group,
  2027. {
  2028. { "path", "o", ARG_IN },
  2029. END_ARGS
  2030. }
  2031. },
  2032. { "RemoveAllPersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2033. (WPADBusMethodHandler)
  2034. wpas_dbus_handler_remove_all_persistent_groups,
  2035. {
  2036. END_ARGS
  2037. }
  2038. },
  2039. #endif /* CONFIG_P2P */
  2040. { "FlushBSS", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2041. (WPADBusMethodHandler) &wpas_dbus_handler_flush_bss,
  2042. {
  2043. { "age", "u", ARG_IN },
  2044. END_ARGS
  2045. }
  2046. },
  2047. { NULL, NULL, NULL, { END_ARGS } }
  2048. };
  2049. static const struct wpa_dbus_property_desc wpas_dbus_interface_properties[] = {
  2050. { "Capabilities", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{sv}",
  2051. wpas_dbus_getter_capabilities,
  2052. NULL
  2053. },
  2054. { "State", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2055. wpas_dbus_getter_state,
  2056. NULL
  2057. },
  2058. { "Scanning", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
  2059. wpas_dbus_getter_scanning,
  2060. NULL
  2061. },
  2062. { "ApScan", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  2063. wpas_dbus_getter_ap_scan,
  2064. wpas_dbus_setter_ap_scan
  2065. },
  2066. { "BSSExpireAge", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  2067. wpas_dbus_getter_bss_expire_age,
  2068. wpas_dbus_setter_bss_expire_age
  2069. },
  2070. { "BSSExpireCount", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  2071. wpas_dbus_getter_bss_expire_count,
  2072. wpas_dbus_setter_bss_expire_count
  2073. },
  2074. { "Country", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2075. wpas_dbus_getter_country,
  2076. wpas_dbus_setter_country
  2077. },
  2078. { "Ifname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2079. wpas_dbus_getter_ifname,
  2080. NULL
  2081. },
  2082. { "Driver", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2083. wpas_dbus_getter_driver,
  2084. NULL
  2085. },
  2086. { "BridgeIfname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2087. wpas_dbus_getter_bridge_ifname,
  2088. NULL
  2089. },
  2090. { "CurrentBSS", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
  2091. wpas_dbus_getter_current_bss,
  2092. NULL
  2093. },
  2094. { "CurrentNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
  2095. wpas_dbus_getter_current_network,
  2096. NULL
  2097. },
  2098. { "CurrentAuthMode", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2099. wpas_dbus_getter_current_auth_mode,
  2100. NULL
  2101. },
  2102. { "Blobs", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{say}",
  2103. wpas_dbus_getter_blobs,
  2104. NULL
  2105. },
  2106. { "BSSs", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
  2107. wpas_dbus_getter_bsss,
  2108. NULL
  2109. },
  2110. { "Networks", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
  2111. wpas_dbus_getter_networks,
  2112. NULL
  2113. },
  2114. #ifdef CONFIG_WPS
  2115. { "ProcessCredentials", WPAS_DBUS_NEW_IFACE_WPS, "b",
  2116. wpas_dbus_getter_process_credentials,
  2117. wpas_dbus_setter_process_credentials
  2118. },
  2119. #endif /* CONFIG_WPS */
  2120. #ifdef CONFIG_P2P
  2121. { "P2PDeviceProperties", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "a{sv}",
  2122. wpas_dbus_getter_p2p_device_properties,
  2123. wpas_dbus_setter_p2p_device_properties
  2124. },
  2125. { "Peers", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
  2126. wpas_dbus_getter_p2p_peers,
  2127. NULL
  2128. },
  2129. { "Role", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "s",
  2130. wpas_dbus_getter_p2p_role,
  2131. NULL
  2132. },
  2133. { "Group", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
  2134. wpas_dbus_getter_p2p_group,
  2135. NULL
  2136. },
  2137. { "PeerGO", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
  2138. wpas_dbus_getter_p2p_peergo,
  2139. NULL
  2140. },
  2141. { "PersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
  2142. wpas_dbus_getter_persistent_groups,
  2143. NULL
  2144. },
  2145. #endif /* CONFIG_P2P */
  2146. { NULL, NULL, NULL, NULL, NULL }
  2147. };
  2148. static const struct wpa_dbus_signal_desc wpas_dbus_interface_signals[] = {
  2149. { "ScanDone", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2150. {
  2151. { "success", "b", ARG_OUT },
  2152. END_ARGS
  2153. }
  2154. },
  2155. { "BSSAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2156. {
  2157. { "path", "o", ARG_OUT },
  2158. { "properties", "a{sv}", ARG_OUT },
  2159. END_ARGS
  2160. }
  2161. },
  2162. { "BSSRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2163. {
  2164. { "path", "o", ARG_OUT },
  2165. END_ARGS
  2166. }
  2167. },
  2168. { "BlobAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2169. {
  2170. { "name", "s", ARG_OUT },
  2171. END_ARGS
  2172. }
  2173. },
  2174. { "BlobRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2175. {
  2176. { "name", "s", ARG_OUT },
  2177. END_ARGS
  2178. }
  2179. },
  2180. { "NetworkAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2181. {
  2182. { "path", "o", ARG_OUT },
  2183. { "properties", "a{sv}", ARG_OUT },
  2184. END_ARGS
  2185. }
  2186. },
  2187. { "NetworkRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2188. {
  2189. { "path", "o", ARG_OUT },
  2190. END_ARGS
  2191. }
  2192. },
  2193. { "NetworkSelected", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2194. {
  2195. { "path", "o", ARG_OUT },
  2196. END_ARGS
  2197. }
  2198. },
  2199. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  2200. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2201. {
  2202. { "properties", "a{sv}", ARG_OUT },
  2203. END_ARGS
  2204. }
  2205. },
  2206. #ifdef CONFIG_WPS
  2207. { "Event", WPAS_DBUS_NEW_IFACE_WPS,
  2208. {
  2209. { "name", "s", ARG_OUT },
  2210. { "args", "a{sv}", ARG_OUT },
  2211. END_ARGS
  2212. }
  2213. },
  2214. { "Credentials", WPAS_DBUS_NEW_IFACE_WPS,
  2215. {
  2216. { "credentials", "a{sv}", ARG_OUT },
  2217. END_ARGS
  2218. }
  2219. },
  2220. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  2221. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_WPS,
  2222. {
  2223. { "properties", "a{sv}", ARG_OUT },
  2224. END_ARGS
  2225. }
  2226. },
  2227. #endif /* CONFIG_WPS */
  2228. #ifdef CONFIG_P2P
  2229. { "P2PStateChanged", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2230. {
  2231. { "states", "a{ss}", ARG_OUT },
  2232. END_ARGS
  2233. }
  2234. },
  2235. { "DeviceFound", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2236. {
  2237. { "path", "o", ARG_OUT },
  2238. { "properties", "a{sv}", ARG_OUT },
  2239. END_ARGS
  2240. }
  2241. },
  2242. { "DeviceLost", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2243. {
  2244. { "path", "o", ARG_OUT },
  2245. END_ARGS
  2246. }
  2247. },
  2248. { "ProvisionDiscoveryRequestDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2249. {
  2250. { "peer_object", "o", ARG_OUT },
  2251. { "pin", "s", ARG_OUT },
  2252. END_ARGS
  2253. }
  2254. },
  2255. { "ProvisionDiscoveryResponseDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2256. {
  2257. { "peer_object", "o", ARG_OUT },
  2258. { "pin", "s", ARG_OUT },
  2259. END_ARGS
  2260. }
  2261. },
  2262. { "ProvisionDiscoveryRequestEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2263. {
  2264. { "peer_object", "o", ARG_OUT },
  2265. END_ARGS
  2266. }
  2267. },
  2268. { "ProvisionDiscoveryResponseEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2269. {
  2270. { "peer_object", "o", ARG_OUT },
  2271. END_ARGS
  2272. }
  2273. },
  2274. { "ProvisionDiscoveryPBCRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2275. {
  2276. { "peer_object", "o", ARG_OUT },
  2277. END_ARGS
  2278. }
  2279. },
  2280. { "ProvisionDiscoveryPBCResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2281. {
  2282. { "peer_object", "o", ARG_OUT },
  2283. END_ARGS
  2284. }
  2285. },
  2286. { "ProvisionDiscoveryFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2287. {
  2288. { "peer_object", "o", ARG_OUT },
  2289. { "status", "i", ARG_OUT },
  2290. END_ARGS
  2291. }
  2292. },
  2293. { "GroupStarted", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2294. {
  2295. { "properties", "a{sv}", ARG_OUT },
  2296. END_ARGS
  2297. }
  2298. },
  2299. { "GONegotiationSuccess", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2300. {
  2301. END_ARGS
  2302. }
  2303. },
  2304. { "GONegotiationFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2305. {
  2306. { "status", "i", ARG_OUT },
  2307. END_ARGS
  2308. }
  2309. },
  2310. { "GONegotiationRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2311. {
  2312. { "path", "o", ARG_OUT },
  2313. { "dev_passwd_id", "i", ARG_OUT },
  2314. END_ARGS
  2315. }
  2316. },
  2317. { "InvitationResult", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2318. {
  2319. { "invite_result", "a{sv}", ARG_OUT },
  2320. END_ARGS
  2321. }
  2322. },
  2323. { "GroupFinished", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2324. {
  2325. { "ifname", "s", ARG_OUT },
  2326. { "role", "s", ARG_OUT },
  2327. END_ARGS
  2328. }
  2329. },
  2330. { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2331. {
  2332. { "sd_request", "a{sv}", ARG_OUT },
  2333. END_ARGS
  2334. }
  2335. },
  2336. { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2337. {
  2338. { "sd_response", "a{sv}", ARG_OUT },
  2339. END_ARGS
  2340. }
  2341. },
  2342. { "PersistentGroupAdded", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2343. {
  2344. { "path", "o", ARG_OUT },
  2345. { "properties", "a{sv}", ARG_OUT },
  2346. END_ARGS
  2347. }
  2348. },
  2349. { "PersistentGroupRemoved", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2350. {
  2351. { "path", "o", ARG_OUT },
  2352. END_ARGS
  2353. }
  2354. },
  2355. { "WpsFailed", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2356. {
  2357. { "name", "s", ARG_OUT },
  2358. { "args", "a{sv}", ARG_OUT },
  2359. END_ARGS
  2360. }
  2361. },
  2362. #endif /* CONFIG_P2P */
  2363. { "Certification", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2364. {
  2365. { "certification", "a{sv}", ARG_OUT },
  2366. END_ARGS
  2367. }
  2368. },
  2369. { NULL, NULL, { END_ARGS } }
  2370. };
  2371. int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s)
  2372. {
  2373. struct wpa_dbus_object_desc *obj_desc = NULL;
  2374. struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus;
  2375. int next;
  2376. /* Do nothing if the control interface is not turned on */
  2377. if (ctrl_iface == NULL)
  2378. return 0;
  2379. /* Create and set the interface's object path */
  2380. wpa_s->dbus_new_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
  2381. if (wpa_s->dbus_new_path == NULL)
  2382. return -1;
  2383. next = ctrl_iface->next_objid++;
  2384. os_snprintf(wpa_s->dbus_new_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2385. WPAS_DBUS_NEW_PATH_INTERFACES "/%u",
  2386. next);
  2387. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  2388. if (!obj_desc) {
  2389. wpa_printf(MSG_ERROR, "Not enough memory "
  2390. "to create object description");
  2391. goto err;
  2392. }
  2393. wpas_dbus_register(obj_desc, wpa_s, NULL, wpas_dbus_interface_methods,
  2394. wpas_dbus_interface_properties,
  2395. wpas_dbus_interface_signals);
  2396. wpa_printf(MSG_DEBUG, "dbus: Register interface object '%s'",
  2397. wpa_s->dbus_new_path);
  2398. if (wpa_dbus_register_object_per_iface(ctrl_iface,
  2399. wpa_s->dbus_new_path,
  2400. wpa_s->ifname, obj_desc))
  2401. goto err;
  2402. wpas_dbus_signal_interface_added(wpa_s);
  2403. return 0;
  2404. err:
  2405. os_free(wpa_s->dbus_new_path);
  2406. wpa_s->dbus_new_path = NULL;
  2407. free_dbus_object_desc(obj_desc);
  2408. return -1;
  2409. }
  2410. int wpas_dbus_unregister_interface(struct wpa_supplicant *wpa_s)
  2411. {
  2412. struct wpas_dbus_priv *ctrl_iface;
  2413. /* Do nothing if the control interface is not turned on */
  2414. if (wpa_s == NULL || wpa_s->global == NULL)
  2415. return 0;
  2416. ctrl_iface = wpa_s->global->dbus;
  2417. if (ctrl_iface == NULL)
  2418. return 0;
  2419. wpa_printf(MSG_DEBUG, "dbus: Unregister interface object '%s'",
  2420. wpa_s->dbus_new_path);
  2421. if (wpa_dbus_unregister_object_per_iface(ctrl_iface,
  2422. wpa_s->dbus_new_path))
  2423. return -1;
  2424. wpas_dbus_signal_interface_removed(wpa_s);
  2425. os_free(wpa_s->dbus_new_path);
  2426. wpa_s->dbus_new_path = NULL;
  2427. return 0;
  2428. }
  2429. #ifdef CONFIG_P2P
  2430. static const struct wpa_dbus_property_desc wpas_dbus_p2p_peer_properties[] = {
  2431. { "Properties", WPAS_DBUS_NEW_IFACE_P2P_PEER, "a{sv}",
  2432. wpas_dbus_getter_p2p_peer_properties,
  2433. NULL
  2434. },
  2435. { "IEs", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
  2436. wpas_dbus_getter_p2p_peer_ies,
  2437. NULL
  2438. },
  2439. { NULL, NULL, NULL, NULL, NULL }
  2440. };
  2441. static const struct wpa_dbus_signal_desc wpas_dbus_p2p_peer_signals[] = {
  2442. { NULL, NULL, { END_ARGS } }
  2443. };
  2444. /**
  2445. * wpas_dbus_signal_peer - Send a peer related event signal
  2446. * @wpa_s: %wpa_supplicant network interface data
  2447. * @dev: peer device object
  2448. * @interface: name of the interface emitting this signal.
  2449. * In case of peer objects, it would be emitted by either
  2450. * the "interface object" or by "peer objects"
  2451. * @sig_name: signal name - DeviceFound
  2452. *
  2453. * Notify listeners about event related with newly found p2p peer device
  2454. */
  2455. static void wpas_dbus_signal_peer(struct wpa_supplicant *wpa_s,
  2456. const u8 *dev_addr, const char *interface,
  2457. const char *sig_name)
  2458. {
  2459. struct wpas_dbus_priv *iface;
  2460. DBusMessage *msg;
  2461. DBusMessageIter iter;
  2462. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  2463. iface = wpa_s->global->dbus;
  2464. /* Do nothing if the control interface is not turned on */
  2465. if (iface == NULL)
  2466. return;
  2467. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2468. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  2469. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  2470. msg = dbus_message_new_signal(wpa_s->dbus_new_path, interface,
  2471. sig_name);
  2472. if (msg == NULL)
  2473. return;
  2474. dbus_message_iter_init_append(msg, &iter);
  2475. path = peer_obj_path;
  2476. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  2477. &path))
  2478. goto err;
  2479. dbus_connection_send(iface->con, msg, NULL);
  2480. dbus_message_unref(msg);
  2481. return;
  2482. err:
  2483. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  2484. dbus_message_unref(msg);
  2485. }
  2486. /**
  2487. * wpas_dbus_signal_peer_found - Send a peer found signal
  2488. * @wpa_s: %wpa_supplicant network interface data
  2489. * @dev: peer device object
  2490. *
  2491. * Notify listeners about find a p2p peer device found
  2492. */
  2493. void wpas_dbus_signal_peer_device_found(struct wpa_supplicant *wpa_s,
  2494. const u8 *dev_addr)
  2495. {
  2496. wpas_dbus_signal_peer(wpa_s, dev_addr,
  2497. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2498. "DeviceFound");
  2499. }
  2500. /**
  2501. * wpas_dbus_signal_peer_lost - Send a peer lost signal
  2502. * @wpa_s: %wpa_supplicant network interface data
  2503. * @dev: peer device object
  2504. *
  2505. * Notify listeners about lost a p2p peer device
  2506. */
  2507. void wpas_dbus_signal_peer_device_lost(struct wpa_supplicant *wpa_s,
  2508. const u8 *dev_addr)
  2509. {
  2510. wpas_dbus_signal_peer(wpa_s, dev_addr,
  2511. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2512. "DeviceLost");
  2513. }
  2514. /**
  2515. * wpas_dbus_register_peer - Register a discovered peer object with dbus
  2516. * @wpa_s: wpa_supplicant interface structure
  2517. * @ssid: network configuration data
  2518. * Returns: 0 on success, -1 on failure
  2519. *
  2520. * Registers network representing object with dbus
  2521. */
  2522. int wpas_dbus_register_peer(struct wpa_supplicant *wpa_s, const u8 *dev_addr)
  2523. {
  2524. struct wpas_dbus_priv *ctrl_iface;
  2525. struct wpa_dbus_object_desc *obj_desc;
  2526. struct peer_handler_args *arg;
  2527. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2528. /* Do nothing if the control interface is not turned on */
  2529. if (wpa_s == NULL || wpa_s->global == NULL)
  2530. return 0;
  2531. ctrl_iface = wpa_s->global->dbus;
  2532. if (ctrl_iface == NULL)
  2533. return 0;
  2534. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2535. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  2536. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  2537. wpa_printf(MSG_INFO, "dbus: Register peer object '%s'",
  2538. peer_obj_path);
  2539. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  2540. if (!obj_desc) {
  2541. wpa_printf(MSG_ERROR, "Not enough memory "
  2542. "to create object description");
  2543. goto err;
  2544. }
  2545. /* allocate memory for handlers arguments */
  2546. arg = os_zalloc(sizeof(struct peer_handler_args));
  2547. if (!arg) {
  2548. wpa_printf(MSG_ERROR, "Not enough memory "
  2549. "to create arguments for method");
  2550. goto err;
  2551. }
  2552. arg->wpa_s = wpa_s;
  2553. os_memcpy(arg->p2p_device_addr, dev_addr, ETH_ALEN);
  2554. wpas_dbus_register(obj_desc, arg, wpa_dbus_free,
  2555. NULL,
  2556. wpas_dbus_p2p_peer_properties,
  2557. wpas_dbus_p2p_peer_signals);
  2558. if (wpa_dbus_register_object_per_iface(ctrl_iface, peer_obj_path,
  2559. wpa_s->ifname, obj_desc))
  2560. goto err;
  2561. return 0;
  2562. err:
  2563. free_dbus_object_desc(obj_desc);
  2564. return -1;
  2565. }
  2566. /**
  2567. * wpas_dbus_unregister_peer - Unregister a peer object with dbus
  2568. * @wpa_s: wpa_supplicant interface structure
  2569. * @dev_addr: p2p device addr
  2570. * Returns: 0 on success, -1 on failure
  2571. *
  2572. * Registers network representing object with dbus
  2573. */
  2574. int wpas_dbus_unregister_peer(struct wpa_supplicant *wpa_s,
  2575. const u8 *dev_addr)
  2576. {
  2577. struct wpas_dbus_priv *ctrl_iface;
  2578. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2579. int ret;
  2580. /* Do nothing if the control interface is not turned on */
  2581. if (wpa_s == NULL || wpa_s->global == NULL ||
  2582. wpa_s->dbus_new_path == NULL)
  2583. return 0;
  2584. ctrl_iface = wpa_s->global->dbus;
  2585. if (ctrl_iface == NULL)
  2586. return 0;
  2587. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2588. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  2589. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  2590. wpa_printf(MSG_INFO, "dbus: Unregister peer object '%s'",
  2591. peer_obj_path);
  2592. ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, peer_obj_path);
  2593. return ret;
  2594. }
  2595. static const struct wpa_dbus_property_desc wpas_dbus_p2p_group_properties[] = {
  2596. { "Members", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ao",
  2597. wpas_dbus_getter_p2p_group_members,
  2598. NULL
  2599. },
  2600. { "Properties",
  2601. WPAS_DBUS_NEW_IFACE_P2P_GROUP, "a{sv}",
  2602. wpas_dbus_getter_p2p_group_properties,
  2603. wpas_dbus_setter_p2p_group_properties
  2604. },
  2605. { NULL, NULL, NULL, NULL, NULL }
  2606. };
  2607. static const struct wpa_dbus_signal_desc wpas_dbus_p2p_group_signals[] = {
  2608. { "PeerJoined", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
  2609. {
  2610. { "peer", "o", ARG_OUT },
  2611. END_ARGS
  2612. }
  2613. },
  2614. { "PeerDisconnected", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
  2615. {
  2616. { "peer", "o", ARG_OUT },
  2617. END_ARGS
  2618. }
  2619. },
  2620. { NULL, NULL, { END_ARGS } }
  2621. };
  2622. /**
  2623. * wpas_dbus_register_p2p_group - Register a p2p group object with dbus
  2624. * @wpa_s: wpa_supplicant interface structure
  2625. * @ssid: SSID struct
  2626. * Returns: 0 on success, -1 on failure
  2627. *
  2628. * Registers p2p group representing object with dbus
  2629. */
  2630. void wpas_dbus_register_p2p_group(struct wpa_supplicant *wpa_s,
  2631. struct wpa_ssid *ssid)
  2632. {
  2633. struct wpas_dbus_priv *ctrl_iface;
  2634. struct wpa_dbus_object_desc *obj_desc;
  2635. char group_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2636. /* Do nothing if the control interface is not turned on */
  2637. if (wpa_s == NULL || wpa_s->global == NULL)
  2638. return;
  2639. ctrl_iface = wpa_s->global->dbus;
  2640. if (ctrl_iface == NULL)
  2641. return;
  2642. if (wpa_s->dbus_groupobj_path) {
  2643. wpa_printf(MSG_INFO, "%s: Group object '%s' already exists",
  2644. __func__, wpa_s->dbus_groupobj_path);
  2645. return;
  2646. }
  2647. if (wpas_dbus_get_group_obj_path(wpa_s, ssid, group_obj_path) < 0)
  2648. return;
  2649. wpa_s->dbus_groupobj_path = os_strdup(group_obj_path);
  2650. if (wpa_s->dbus_groupobj_path == NULL)
  2651. return;
  2652. wpa_printf(MSG_INFO, "dbus: Register group object '%s'",
  2653. group_obj_path);
  2654. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  2655. if (!obj_desc) {
  2656. wpa_printf(MSG_ERROR, "Not enough memory "
  2657. "to create object description");
  2658. goto err;
  2659. }
  2660. wpas_dbus_register(obj_desc, wpa_s, NULL, NULL,
  2661. wpas_dbus_p2p_group_properties,
  2662. wpas_dbus_p2p_group_signals);
  2663. if (wpa_dbus_register_object_per_iface(ctrl_iface, group_obj_path,
  2664. wpa_s->ifname, obj_desc))
  2665. goto err;
  2666. return;
  2667. err:
  2668. if (wpa_s->dbus_groupobj_path) {
  2669. os_free(wpa_s->dbus_groupobj_path);
  2670. wpa_s->dbus_groupobj_path = NULL;
  2671. }
  2672. free_dbus_object_desc(obj_desc);
  2673. }
  2674. /**
  2675. * wpas_dbus_unregister_p2p_group - Unregister a p2p group object from dbus
  2676. * @wpa_s: wpa_supplicant interface structure
  2677. * @ssid: network name of the p2p group started
  2678. */
  2679. void wpas_dbus_unregister_p2p_group(struct wpa_supplicant *wpa_s,
  2680. const struct wpa_ssid *ssid)
  2681. {
  2682. struct wpas_dbus_priv *ctrl_iface;
  2683. /* Do nothing if the control interface is not turned on */
  2684. if (wpa_s == NULL || wpa_s->global == NULL)
  2685. return;
  2686. ctrl_iface = wpa_s->global->dbus;
  2687. if (ctrl_iface == NULL)
  2688. return;
  2689. if (!wpa_s->dbus_groupobj_path) {
  2690. wpa_printf(MSG_DEBUG,
  2691. "%s: Group object '%s' already unregistered",
  2692. __func__, wpa_s->dbus_groupobj_path);
  2693. return;
  2694. }
  2695. wpa_printf(MSG_DEBUG, "dbus: Unregister group object '%s'",
  2696. wpa_s->dbus_groupobj_path);
  2697. wpa_dbus_unregister_object_per_iface(ctrl_iface,
  2698. wpa_s->dbus_groupobj_path);
  2699. os_free(wpa_s->dbus_groupobj_path);
  2700. wpa_s->dbus_groupobj_path = NULL;
  2701. }
  2702. static const struct wpa_dbus_property_desc
  2703. wpas_dbus_p2p_groupmember_properties[] = {
  2704. { "Properties", WPAS_DBUS_NEW_IFACE_P2P_GROUPMEMBER, "a{sv}",
  2705. wpas_dbus_getter_p2p_group_properties,
  2706. NULL
  2707. },
  2708. { NULL, NULL, NULL, NULL, NULL }
  2709. };
  2710. /**
  2711. * wpas_dbus_register_p2p_groupmember - Register a p2p groupmember
  2712. * object with dbus
  2713. * @wpa_s: wpa_supplicant interface structure
  2714. * @p2p_if_addr: i/f addr of the device joining this group
  2715. *
  2716. * Registers p2p groupmember representing object with dbus
  2717. */
  2718. void wpas_dbus_register_p2p_groupmember(struct wpa_supplicant *wpa_s,
  2719. const u8 *p2p_if_addr)
  2720. {
  2721. struct wpas_dbus_priv *ctrl_iface;
  2722. struct wpa_dbus_object_desc *obj_desc = NULL;
  2723. struct groupmember_handler_args *arg;
  2724. char groupmember_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2725. /* Do nothing if the control interface is not turned on */
  2726. if (wpa_s == NULL || wpa_s->global == NULL)
  2727. return;
  2728. ctrl_iface = wpa_s->global->dbus;
  2729. if (ctrl_iface == NULL)
  2730. return;
  2731. if (!wpa_s->dbus_groupobj_path)
  2732. return;
  2733. os_snprintf(groupmember_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2734. "%s/" WPAS_DBUS_NEW_P2P_GROUPMEMBERS_PART "/" COMPACT_MACSTR,
  2735. wpa_s->dbus_groupobj_path, MAC2STR(p2p_if_addr));
  2736. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  2737. if (!obj_desc) {
  2738. wpa_printf(MSG_ERROR, "Not enough memory "
  2739. "to create object description");
  2740. goto err;
  2741. }
  2742. /* allocate memory for handlers arguments */
  2743. arg = os_zalloc(sizeof(struct groupmember_handler_args));
  2744. if (!arg) {
  2745. wpa_printf(MSG_ERROR, "Not enough memory "
  2746. "to create arguments for method");
  2747. goto err;
  2748. }
  2749. arg->wpa_s = wpa_s;
  2750. os_memcpy(arg->member_addr, p2p_if_addr, ETH_ALEN);
  2751. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  2752. wpas_dbus_p2p_groupmember_properties, NULL);
  2753. if (wpa_dbus_register_object_per_iface(ctrl_iface, groupmember_obj_path,
  2754. wpa_s->ifname, obj_desc))
  2755. goto err;
  2756. wpa_printf(MSG_INFO,
  2757. "dbus: Registered group member object '%s' successfully",
  2758. groupmember_obj_path);
  2759. return;
  2760. err:
  2761. free_dbus_object_desc(obj_desc);
  2762. }
  2763. /**
  2764. * wpas_dbus_unregister_p2p_groupmember - Unregister a p2p groupmember
  2765. * object with dbus
  2766. * @wpa_s: wpa_supplicant interface structure
  2767. * @p2p_if_addr: i/f addr of the device joining this group
  2768. *
  2769. * Unregisters p2p groupmember representing object with dbus
  2770. */
  2771. void wpas_dbus_unregister_p2p_groupmember(struct wpa_supplicant *wpa_s,
  2772. const u8 *p2p_if_addr)
  2773. {
  2774. struct wpas_dbus_priv *ctrl_iface;
  2775. char groupmember_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2776. /* Do nothing if the control interface is not turned on */
  2777. if (wpa_s == NULL || wpa_s->global == NULL)
  2778. return;
  2779. ctrl_iface = wpa_s->global->dbus;
  2780. if (ctrl_iface == NULL)
  2781. return;
  2782. if (!wpa_s->dbus_groupobj_path)
  2783. return;
  2784. os_snprintf(groupmember_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2785. "%s/" WPAS_DBUS_NEW_P2P_GROUPMEMBERS_PART "/" COMPACT_MACSTR,
  2786. wpa_s->dbus_groupobj_path, MAC2STR(p2p_if_addr));
  2787. wpa_dbus_unregister_object_per_iface(ctrl_iface, groupmember_obj_path);
  2788. }
  2789. static const struct wpa_dbus_property_desc
  2790. wpas_dbus_persistent_group_properties[] = {
  2791. { "Properties", WPAS_DBUS_NEW_IFACE_PERSISTENT_GROUP, "a{sv}",
  2792. wpas_dbus_getter_persistent_group_properties,
  2793. wpas_dbus_setter_persistent_group_properties
  2794. },
  2795. { NULL, NULL, NULL, NULL, NULL }
  2796. };
  2797. /* No signals intended for persistent group objects */
  2798. /**
  2799. * wpas_dbus_register_persistent_group - Register a configured(saved)
  2800. * persistent group with dbus
  2801. * @wpa_s: wpa_supplicant interface structure
  2802. * @ssid: persistent group (still represented as a network within wpa)
  2803. * configuration data
  2804. * Returns: 0 on success, -1 on failure
  2805. *
  2806. * Registers a persistent group representing object with dbus.
  2807. */
  2808. int wpas_dbus_register_persistent_group(struct wpa_supplicant *wpa_s,
  2809. struct wpa_ssid *ssid)
  2810. {
  2811. struct wpas_dbus_priv *ctrl_iface;
  2812. struct wpa_dbus_object_desc *obj_desc;
  2813. struct network_handler_args *arg;
  2814. char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2815. /* Do nothing if the control interface is not turned on */
  2816. if (wpa_s == NULL || wpa_s->global == NULL)
  2817. return 0;
  2818. /* Make sure ssid is a persistent group */
  2819. if (ssid->disabled != 2 && !ssid->p2p_persistent_group)
  2820. return -1; /* should we return w/o complaining? */
  2821. ctrl_iface = wpa_s->global->dbus;
  2822. if (ctrl_iface == NULL)
  2823. return 0;
  2824. /*
  2825. * Intentionally not coming up with different numbering scheme
  2826. * for persistent groups.
  2827. */
  2828. os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2829. "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
  2830. wpa_s->dbus_new_path, ssid->id);
  2831. wpa_printf(MSG_DEBUG, "dbus: Register persistent group object '%s'",
  2832. pgrp_obj_path);
  2833. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  2834. if (!obj_desc) {
  2835. wpa_printf(MSG_ERROR, "dbus: Not enough memory to create "
  2836. "object description");
  2837. goto err;
  2838. }
  2839. /*
  2840. * Reusing the same context structure as that for networks
  2841. * since these are represented using same data structure.
  2842. */
  2843. /* allocate memory for handlers arguments */
  2844. arg = os_zalloc(sizeof(struct network_handler_args));
  2845. if (!arg) {
  2846. wpa_printf(MSG_ERROR, "dbus: Not enough memory to create "
  2847. "arguments for method");
  2848. goto err;
  2849. }
  2850. arg->wpa_s = wpa_s;
  2851. arg->ssid = ssid;
  2852. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  2853. wpas_dbus_persistent_group_properties,
  2854. NULL);
  2855. if (wpa_dbus_register_object_per_iface(ctrl_iface, pgrp_obj_path,
  2856. wpa_s->ifname, obj_desc))
  2857. goto err;
  2858. wpas_dbus_signal_persistent_group_added(wpa_s, ssid->id);
  2859. return 0;
  2860. err:
  2861. free_dbus_object_desc(obj_desc);
  2862. return -1;
  2863. }
  2864. /**
  2865. * wpas_dbus_unregister_persistent_group - Unregister a persistent_group
  2866. * from dbus
  2867. * @wpa_s: wpa_supplicant interface structure
  2868. * @nid: network id
  2869. * Returns: 0 on success, -1 on failure
  2870. *
  2871. * Unregisters persistent group representing object from dbus
  2872. *
  2873. * NOTE: There is a slight issue with the semantics here. While the
  2874. * implementation simply means the persistent group is unloaded from memory,
  2875. * it should not get interpreted as the group is actually being erased/removed
  2876. * from persistent storage as well.
  2877. */
  2878. int wpas_dbus_unregister_persistent_group(struct wpa_supplicant *wpa_s,
  2879. int nid)
  2880. {
  2881. struct wpas_dbus_priv *ctrl_iface;
  2882. char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2883. int ret;
  2884. /* Do nothing if the control interface is not turned on */
  2885. if (wpa_s == NULL || wpa_s->global == NULL ||
  2886. wpa_s->dbus_new_path == NULL)
  2887. return 0;
  2888. ctrl_iface = wpa_s->global->dbus;
  2889. if (ctrl_iface == NULL)
  2890. return 0;
  2891. os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2892. "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
  2893. wpa_s->dbus_new_path, nid);
  2894. wpa_printf(MSG_DEBUG, "dbus: Unregister persistent group object '%s'",
  2895. pgrp_obj_path);
  2896. ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, pgrp_obj_path);
  2897. if (!ret)
  2898. wpas_dbus_signal_persistent_group_removed(wpa_s, nid);
  2899. return ret;
  2900. }
  2901. #endif /* CONFIG_P2P */