dbus_new.c 99 KB

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