dbus_new.c 113 KB

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