dbus_new.c 100 KB

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