dbus_new.c 86 KB

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