dbus_new.c 104 KB

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