dbus_new.c 91 KB

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