dbus_new.c 113 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368
  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. * @client: this device is P2P client
  1043. * @persistent: 0 - non persistent group, 1 - persistent group
  1044. */
  1045. void wpas_dbus_signal_p2p_group_started(struct wpa_supplicant *wpa_s,
  1046. int client, int persistent)
  1047. {
  1048. DBusMessage *msg;
  1049. DBusMessageIter iter, dict_iter;
  1050. struct wpas_dbus_priv *iface;
  1051. struct wpa_supplicant *parent;
  1052. parent = wpa_s->parent;
  1053. if (parent->p2p_mgmt)
  1054. parent = parent->parent;
  1055. iface = parent->global->dbus;
  1056. /* Do nothing if the control interface is not turned on */
  1057. if (iface == NULL || !parent->dbus_new_path || !wpa_s->dbus_new_path)
  1058. return;
  1059. if (wpa_s->dbus_groupobj_path == NULL)
  1060. return;
  1061. /* New interface has been created for this group */
  1062. msg = dbus_message_new_signal(parent->dbus_new_path,
  1063. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1064. "GroupStarted");
  1065. if (msg == NULL)
  1066. return;
  1067. dbus_message_iter_init_append(msg, &iter);
  1068. /*
  1069. * In case the device supports creating a separate interface the
  1070. * DBus client will need to know the object path for the interface
  1071. * object this group was created on, so include it here.
  1072. */
  1073. if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  1074. !wpa_dbus_dict_append_object_path(&dict_iter,
  1075. "interface_object",
  1076. wpa_s->dbus_new_path) ||
  1077. !wpa_dbus_dict_append_string(&dict_iter, "role",
  1078. client ? "client" : "GO") ||
  1079. !wpa_dbus_dict_append_bool(&dict_iter, "persistent", persistent) ||
  1080. !wpa_dbus_dict_append_object_path(&dict_iter, "group_object",
  1081. wpa_s->dbus_groupobj_path) ||
  1082. !wpa_dbus_dict_close_write(&iter, &dict_iter)) {
  1083. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1084. } else {
  1085. dbus_connection_send(iface->con, msg, NULL);
  1086. if (client)
  1087. peer_groups_changed(wpa_s);
  1088. }
  1089. dbus_message_unref(msg);
  1090. }
  1091. /**
  1092. * wpas_dbus_signal_p2p_go_neg_resp - Emit GONegotiation Success/Failure signal
  1093. * @wpa_s: %wpa_supplicant network interface data
  1094. * @res: Result of the GO Neg Request
  1095. */
  1096. void wpas_dbus_signal_p2p_go_neg_resp(struct wpa_supplicant *wpa_s,
  1097. struct p2p_go_neg_results *res)
  1098. {
  1099. DBusMessage *msg;
  1100. DBusMessageIter iter, dict_iter;
  1101. DBusMessageIter iter_dict_entry, iter_dict_val, iter_dict_array;
  1102. struct wpas_dbus_priv *iface;
  1103. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  1104. dbus_int32_t freqs[P2P_MAX_CHANNELS];
  1105. dbus_int32_t *f_array = freqs;
  1106. iface = wpa_s->global->dbus;
  1107. if (wpa_s->p2p_mgmt)
  1108. wpa_s = wpa_s->parent;
  1109. os_memset(freqs, 0, sizeof(freqs));
  1110. /* Do nothing if the control interface is not turned on */
  1111. if (iface == NULL || !wpa_s->dbus_new_path)
  1112. return;
  1113. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1114. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  1115. wpa_s->dbus_new_path, MAC2STR(res->peer_device_addr));
  1116. path = peer_obj_path;
  1117. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1118. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1119. res->status ? "GONegotiationFailure" :
  1120. "GONegotiationSuccess");
  1121. if (msg == NULL)
  1122. return;
  1123. dbus_message_iter_init_append(msg, &iter);
  1124. if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  1125. !wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
  1126. path) ||
  1127. !wpa_dbus_dict_append_int32(&dict_iter, "status", res->status))
  1128. goto err;
  1129. if (!res->status) {
  1130. int i = 0;
  1131. int freq_list_num = 0;
  1132. if ((res->role_go &&
  1133. !wpa_dbus_dict_append_string(&dict_iter, "passphrase",
  1134. res->passphrase)) ||
  1135. !wpa_dbus_dict_append_string(&dict_iter, "role_go",
  1136. res->role_go ? "GO" :
  1137. "client") ||
  1138. !wpa_dbus_dict_append_int32(&dict_iter, "frequency",
  1139. res->freq) ||
  1140. !wpa_dbus_dict_append_byte_array(&dict_iter, "ssid",
  1141. (const char *) res->ssid,
  1142. res->ssid_len) ||
  1143. !wpa_dbus_dict_append_byte_array(&dict_iter,
  1144. "peer_device_addr",
  1145. (const char *)
  1146. res->peer_device_addr,
  1147. ETH_ALEN) ||
  1148. !wpa_dbus_dict_append_byte_array(&dict_iter,
  1149. "peer_interface_addr",
  1150. (const char *)
  1151. res->peer_interface_addr,
  1152. ETH_ALEN) ||
  1153. !wpa_dbus_dict_append_string(&dict_iter, "wps_method",
  1154. p2p_wps_method_text(
  1155. res->wps_method)))
  1156. goto err;
  1157. for (i = 0; i < P2P_MAX_CHANNELS; i++) {
  1158. if (res->freq_list[i]) {
  1159. freqs[i] = res->freq_list[i];
  1160. freq_list_num++;
  1161. }
  1162. }
  1163. if (!wpa_dbus_dict_begin_array(&dict_iter,
  1164. "frequency_list",
  1165. DBUS_TYPE_INT32_AS_STRING,
  1166. &iter_dict_entry,
  1167. &iter_dict_val,
  1168. &iter_dict_array) ||
  1169. !dbus_message_iter_append_fixed_array(&iter_dict_array,
  1170. DBUS_TYPE_INT32,
  1171. &f_array,
  1172. freq_list_num) ||
  1173. !wpa_dbus_dict_end_array(&dict_iter,
  1174. &iter_dict_entry,
  1175. &iter_dict_val,
  1176. &iter_dict_array) ||
  1177. !wpa_dbus_dict_append_int32(&dict_iter, "persistent_group",
  1178. res->persistent_group) ||
  1179. !wpa_dbus_dict_append_uint32(&dict_iter,
  1180. "peer_config_timeout",
  1181. res->peer_config_timeout))
  1182. goto err;
  1183. }
  1184. if (!wpa_dbus_dict_close_write(&iter, &dict_iter))
  1185. goto err;
  1186. dbus_connection_send(iface->con, msg, NULL);
  1187. err:
  1188. dbus_message_unref(msg);
  1189. }
  1190. /**
  1191. * wpas_dbus_signal_p2p_invitation_result - Emit InvitationResult signal
  1192. * @wpa_s: %wpa_supplicant network interface data
  1193. * @status: Status of invitation process
  1194. * @bssid: Basic Service Set Identifier
  1195. */
  1196. void wpas_dbus_signal_p2p_invitation_result(struct wpa_supplicant *wpa_s,
  1197. int status, const u8 *bssid)
  1198. {
  1199. DBusMessage *msg;
  1200. DBusMessageIter iter, dict_iter;
  1201. struct wpas_dbus_priv *iface;
  1202. wpa_printf(MSG_DEBUG, "%s", __func__);
  1203. iface = wpa_s->global->dbus;
  1204. /* Do nothing if the control interface is not turned on */
  1205. if (iface == NULL)
  1206. return;
  1207. if (wpa_s->p2p_mgmt)
  1208. wpa_s = wpa_s->parent;
  1209. if (!wpa_s->dbus_new_path)
  1210. return;
  1211. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1212. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1213. "InvitationResult");
  1214. if (msg == NULL)
  1215. return;
  1216. dbus_message_iter_init_append(msg, &iter);
  1217. if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  1218. !wpa_dbus_dict_append_int32(&dict_iter, "status", status) ||
  1219. (bssid &&
  1220. !wpa_dbus_dict_append_byte_array(&dict_iter, "BSSID",
  1221. (const char *) bssid,
  1222. ETH_ALEN)) ||
  1223. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  1224. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1225. else
  1226. dbus_connection_send(iface->con, msg, NULL);
  1227. dbus_message_unref(msg);
  1228. }
  1229. /**
  1230. *
  1231. * Method to emit a signal for a peer joining the group.
  1232. * The signal will carry path to the group member object
  1233. * constructed using p2p i/f addr used for connecting.
  1234. *
  1235. * @wpa_s: %wpa_supplicant network interface data
  1236. * @peer_addr: P2P Device Address of the peer joining the group
  1237. */
  1238. void wpas_dbus_signal_p2p_peer_joined(struct wpa_supplicant *wpa_s,
  1239. const u8 *peer_addr)
  1240. {
  1241. struct wpas_dbus_priv *iface;
  1242. DBusMessage *msg;
  1243. DBusMessageIter iter;
  1244. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  1245. struct wpa_supplicant *parent;
  1246. iface = wpa_s->global->dbus;
  1247. /* Do nothing if the control interface is not turned on */
  1248. if (iface == NULL)
  1249. return;
  1250. if (!wpa_s->dbus_groupobj_path)
  1251. return;
  1252. parent = wpa_s->parent;
  1253. if (parent->p2p_mgmt)
  1254. parent = parent->parent;
  1255. if (!parent->dbus_new_path)
  1256. return;
  1257. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1258. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
  1259. COMPACT_MACSTR,
  1260. parent->dbus_new_path, MAC2STR(peer_addr));
  1261. msg = dbus_message_new_signal(wpa_s->dbus_groupobj_path,
  1262. WPAS_DBUS_NEW_IFACE_P2P_GROUP,
  1263. "PeerJoined");
  1264. if (msg == NULL)
  1265. return;
  1266. dbus_message_iter_init_append(msg, &iter);
  1267. path = peer_obj_path;
  1268. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  1269. &path)) {
  1270. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1271. } else {
  1272. dbus_connection_send(iface->con, msg, NULL);
  1273. wpas_dbus_signal_peer_groups_changed(parent, peer_addr);
  1274. }
  1275. dbus_message_unref(msg);
  1276. }
  1277. /**
  1278. *
  1279. * Method to emit a signal for a peer disconnecting the group.
  1280. * The signal will carry path to the group member object
  1281. * constructed using the P2P Device Address of the peer.
  1282. *
  1283. * @wpa_s: %wpa_supplicant network interface data
  1284. * @peer_addr: P2P Device Address of the peer joining the group
  1285. */
  1286. void wpas_dbus_signal_p2p_peer_disconnected(struct wpa_supplicant *wpa_s,
  1287. const u8 *peer_addr)
  1288. {
  1289. struct wpas_dbus_priv *iface;
  1290. DBusMessage *msg;
  1291. DBusMessageIter iter;
  1292. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  1293. struct wpa_supplicant *parent;
  1294. iface = wpa_s->global->dbus;
  1295. /* Do nothing if the control interface is not turned on */
  1296. if (iface == NULL)
  1297. return;
  1298. if (!wpa_s->dbus_groupobj_path)
  1299. return;
  1300. parent = wpa_s->parent;
  1301. if (parent->p2p_mgmt)
  1302. parent = parent->parent;
  1303. if (!parent->dbus_new_path)
  1304. return;
  1305. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1306. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
  1307. COMPACT_MACSTR,
  1308. parent->dbus_new_path, MAC2STR(peer_addr));
  1309. msg = dbus_message_new_signal(wpa_s->dbus_groupobj_path,
  1310. WPAS_DBUS_NEW_IFACE_P2P_GROUP,
  1311. "PeerDisconnected");
  1312. if (msg == NULL)
  1313. return;
  1314. dbus_message_iter_init_append(msg, &iter);
  1315. path = peer_obj_path;
  1316. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  1317. &path)) {
  1318. wpa_printf(MSG_ERROR,
  1319. "dbus: Failed to construct PeerDisconnected signal");
  1320. } else {
  1321. dbus_connection_send(iface->con, msg, NULL);
  1322. wpas_dbus_signal_peer_groups_changed(parent, peer_addr);
  1323. }
  1324. dbus_message_unref(msg);
  1325. }
  1326. /**
  1327. *
  1328. * Method to emit a signal for a service discovery request.
  1329. * The signal will carry station address, frequency, dialog token,
  1330. * update indicator and it tlvs
  1331. *
  1332. * @wpa_s: %wpa_supplicant network interface data
  1333. * @sa: station addr (p2p i/f) of the peer
  1334. * @dialog_token: service discovery request dialog token
  1335. * @update_indic: service discovery request update indicator
  1336. * @tlvs: service discovery request genrated byte array of tlvs
  1337. * @tlvs_len: service discovery request tlvs length
  1338. */
  1339. void wpas_dbus_signal_p2p_sd_request(struct wpa_supplicant *wpa_s,
  1340. int freq, const u8 *sa, u8 dialog_token,
  1341. u16 update_indic, const u8 *tlvs,
  1342. size_t tlvs_len)
  1343. {
  1344. DBusMessage *msg;
  1345. DBusMessageIter iter, dict_iter;
  1346. struct wpas_dbus_priv *iface;
  1347. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  1348. iface = wpa_s->global->dbus;
  1349. /* Do nothing if the control interface is not turned on */
  1350. if (iface == NULL)
  1351. return;
  1352. if (wpa_s->p2p_mgmt)
  1353. wpa_s = wpa_s->parent;
  1354. if (!wpa_s->dbus_new_path)
  1355. return;
  1356. /* Check if this is a known peer */
  1357. if (!p2p_peer_known(wpa_s->global->p2p, sa))
  1358. return;
  1359. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1360. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1361. "ServiceDiscoveryRequest");
  1362. if (msg == NULL)
  1363. return;
  1364. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1365. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
  1366. COMPACT_MACSTR, wpa_s->dbus_new_path, MAC2STR(sa));
  1367. path = peer_obj_path;
  1368. dbus_message_iter_init_append(msg, &iter);
  1369. if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  1370. !wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
  1371. path) ||
  1372. !wpa_dbus_dict_append_int32(&dict_iter, "frequency", freq) ||
  1373. !wpa_dbus_dict_append_int32(&dict_iter, "dialog_token",
  1374. dialog_token) ||
  1375. !wpa_dbus_dict_append_uint16(&dict_iter, "update_indicator",
  1376. update_indic) ||
  1377. !wpa_dbus_dict_append_byte_array(&dict_iter, "tlvs",
  1378. (const char *) tlvs,
  1379. tlvs_len) ||
  1380. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  1381. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1382. else
  1383. dbus_connection_send(iface->con, msg, NULL);
  1384. dbus_message_unref(msg);
  1385. }
  1386. /**
  1387. *
  1388. * Method to emit a signal for a service discovery response.
  1389. * The signal will carry station address, update indicator and it
  1390. * tlvs
  1391. *
  1392. * @wpa_s: %wpa_supplicant network interface data
  1393. * @sa: station addr (p2p i/f) of the peer
  1394. * @update_indic: service discovery request update indicator
  1395. * @tlvs: service discovery request genrated byte array of tlvs
  1396. * @tlvs_len: service discovery request tlvs length
  1397. */
  1398. void wpas_dbus_signal_p2p_sd_response(struct wpa_supplicant *wpa_s,
  1399. const u8 *sa, u16 update_indic,
  1400. const u8 *tlvs, size_t tlvs_len)
  1401. {
  1402. DBusMessage *msg;
  1403. DBusMessageIter iter, dict_iter;
  1404. struct wpas_dbus_priv *iface;
  1405. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  1406. iface = wpa_s->global->dbus;
  1407. /* Do nothing if the control interface is not turned on */
  1408. if (iface == NULL)
  1409. return;
  1410. if (wpa_s->p2p_mgmt)
  1411. wpa_s = wpa_s->parent;
  1412. if (!wpa_s->dbus_new_path)
  1413. return;
  1414. /* Check if this is a known peer */
  1415. if (!p2p_peer_known(wpa_s->global->p2p, sa))
  1416. return;
  1417. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1418. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1419. "ServiceDiscoveryResponse");
  1420. if (msg == NULL)
  1421. return;
  1422. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1423. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
  1424. COMPACT_MACSTR, wpa_s->dbus_new_path, MAC2STR(sa));
  1425. path = peer_obj_path;
  1426. dbus_message_iter_init_append(msg, &iter);
  1427. if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  1428. !wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
  1429. path) ||
  1430. !wpa_dbus_dict_append_uint16(&dict_iter, "update_indicator",
  1431. update_indic) ||
  1432. !wpa_dbus_dict_append_byte_array(&dict_iter, "tlvs",
  1433. (const char *) tlvs,
  1434. tlvs_len) ||
  1435. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  1436. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1437. else
  1438. dbus_connection_send(iface->con, msg, NULL);
  1439. dbus_message_unref(msg);
  1440. }
  1441. /**
  1442. * wpas_dbus_signal_persistent_group - Send a persistent group related
  1443. * event signal
  1444. * @wpa_s: %wpa_supplicant network interface data
  1445. * @id: new persistent group id
  1446. * @sig_name: signal name - PersistentGroupAdded, PersistentGroupRemoved
  1447. * @properties: determines if add second argument with object properties
  1448. *
  1449. * Notify listeners about an event related to persistent groups.
  1450. */
  1451. static void wpas_dbus_signal_persistent_group(struct wpa_supplicant *wpa_s,
  1452. int id, const char *sig_name,
  1453. int properties)
  1454. {
  1455. struct wpas_dbus_priv *iface;
  1456. DBusMessage *msg;
  1457. DBusMessageIter iter;
  1458. char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  1459. iface = wpa_s->global->dbus;
  1460. /* Do nothing if the control interface is not turned on */
  1461. if (iface == NULL)
  1462. return;
  1463. if (wpa_s->p2p_mgmt)
  1464. wpa_s = wpa_s->parent;
  1465. if (!wpa_s->dbus_new_path)
  1466. return;
  1467. os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1468. "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
  1469. wpa_s->dbus_new_path, id);
  1470. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1471. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1472. sig_name);
  1473. if (msg == NULL)
  1474. return;
  1475. dbus_message_iter_init_append(msg, &iter);
  1476. path = pgrp_obj_path;
  1477. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  1478. &path) ||
  1479. (properties &&
  1480. !wpa_dbus_get_object_properties(
  1481. iface, pgrp_obj_path,
  1482. WPAS_DBUS_NEW_IFACE_PERSISTENT_GROUP, &iter)))
  1483. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1484. else
  1485. dbus_connection_send(iface->con, msg, NULL);
  1486. dbus_message_unref(msg);
  1487. }
  1488. /**
  1489. * wpas_dbus_signal_persistent_group_added - Send a persistent_group
  1490. * added signal
  1491. * @wpa_s: %wpa_supplicant network interface data
  1492. * @id: new persistent group id
  1493. *
  1494. * Notify listeners about addition of a new persistent group.
  1495. */
  1496. static void wpas_dbus_signal_persistent_group_added(
  1497. struct wpa_supplicant *wpa_s, int id)
  1498. {
  1499. wpas_dbus_signal_persistent_group(wpa_s, id, "PersistentGroupAdded",
  1500. TRUE);
  1501. }
  1502. /**
  1503. * wpas_dbus_signal_persistent_group_removed - Send a persistent_group
  1504. * removed signal
  1505. * @wpa_s: %wpa_supplicant network interface data
  1506. * @id: persistent group id
  1507. *
  1508. * Notify listeners about removal of a persistent group.
  1509. */
  1510. static void wpas_dbus_signal_persistent_group_removed(
  1511. struct wpa_supplicant *wpa_s, int id)
  1512. {
  1513. wpas_dbus_signal_persistent_group(wpa_s, id, "PersistentGroupRemoved",
  1514. FALSE);
  1515. }
  1516. /**
  1517. * wpas_dbus_signal_p2p_wps_failed - Signals WpsFailed event
  1518. * @wpa_s: %wpa_supplicant network interface data
  1519. * @fail: WPS failure information
  1520. *
  1521. * Sends Event dbus signal with name "fail" and dictionary containing
  1522. * "msg" field with fail message number (int32) as arguments
  1523. */
  1524. void wpas_dbus_signal_p2p_wps_failed(struct wpa_supplicant *wpa_s,
  1525. struct wps_event_fail *fail)
  1526. {
  1527. DBusMessage *msg;
  1528. DBusMessageIter iter, dict_iter;
  1529. struct wpas_dbus_priv *iface;
  1530. char *key = "fail";
  1531. iface = wpa_s->global->dbus;
  1532. /* Do nothing if the control interface is not turned on */
  1533. if (iface == NULL)
  1534. return;
  1535. if (wpa_s->p2p_mgmt)
  1536. wpa_s = wpa_s->parent;
  1537. if (!wpa_s->dbus_new_path)
  1538. return;
  1539. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1540. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1541. "WpsFailed");
  1542. if (msg == NULL)
  1543. return;
  1544. dbus_message_iter_init_append(msg, &iter);
  1545. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
  1546. !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  1547. !wpa_dbus_dict_append_int32(&dict_iter, "msg", fail->msg) ||
  1548. !wpa_dbus_dict_append_int16(&dict_iter, "config_error",
  1549. fail->config_error) ||
  1550. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  1551. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1552. else
  1553. dbus_connection_send(iface->con, msg, NULL);
  1554. dbus_message_unref(msg);
  1555. }
  1556. /**
  1557. * wpas_dbus_signal_p2p_group_formation_failure - Signals GroupFormationFailure event
  1558. * @wpa_s: %wpa_supplicant network interface data
  1559. * @reason: indicates the reason code for group formation failure
  1560. *
  1561. * Sends Event dbus signal and string reason code when available.
  1562. */
  1563. void wpas_dbus_signal_p2p_group_formation_failure(struct wpa_supplicant *wpa_s,
  1564. const char *reason)
  1565. {
  1566. DBusMessage *msg;
  1567. struct wpas_dbus_priv *iface;
  1568. iface = wpa_s->global->dbus;
  1569. /* Do nothing if the control interface is not turned on */
  1570. if (iface == NULL)
  1571. return;
  1572. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1573. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1574. "GroupFormationFailure");
  1575. if (msg == NULL)
  1576. return;
  1577. if (dbus_message_append_args(msg, DBUS_TYPE_STRING, &reason,
  1578. DBUS_TYPE_INVALID))
  1579. dbus_connection_send(iface->con, msg, NULL);
  1580. else
  1581. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1582. dbus_message_unref(msg);
  1583. }
  1584. /**
  1585. * wpas_dbus_signal_p2p_invitation_received - Emit InvitationReceived signal
  1586. * @wpa_s: %wpa_supplicant network interface data
  1587. * @sa: Source address of the Invitation Request
  1588. * @dev_add: GO Device Address
  1589. * @bssid: P2P Group BSSID or %NULL if not received
  1590. * @id: Persistent group id or %0 if not persistent group
  1591. * @op_freq: Operating frequency for the group
  1592. */
  1593. void wpas_dbus_signal_p2p_invitation_received(struct wpa_supplicant *wpa_s,
  1594. const u8 *sa, const u8 *dev_addr,
  1595. const u8 *bssid, int id,
  1596. int op_freq)
  1597. {
  1598. DBusMessage *msg;
  1599. DBusMessageIter iter, dict_iter;
  1600. struct wpas_dbus_priv *iface;
  1601. iface = wpa_s->global->dbus;
  1602. /* Do nothing if the control interface is not turned on */
  1603. if (iface == NULL)
  1604. return;
  1605. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1606. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1607. "InvitationReceived");
  1608. if (msg == NULL)
  1609. return;
  1610. dbus_message_iter_init_append(msg, &iter);
  1611. if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  1612. (sa &&
  1613. !wpa_dbus_dict_append_byte_array(&dict_iter, "sa",
  1614. (const char *) sa, ETH_ALEN)) ||
  1615. (dev_addr &&
  1616. !wpa_dbus_dict_append_byte_array(&dict_iter, "go_dev_addr",
  1617. (const char *) dev_addr,
  1618. ETH_ALEN)) ||
  1619. (bssid &&
  1620. !wpa_dbus_dict_append_byte_array(&dict_iter, "bssid",
  1621. (const char *) bssid,
  1622. ETH_ALEN)) ||
  1623. (id &&
  1624. !wpa_dbus_dict_append_int32(&dict_iter, "persistent_id", id)) ||
  1625. !wpa_dbus_dict_append_int32(&dict_iter, "op_freq", op_freq) ||
  1626. !wpa_dbus_dict_close_write(&iter, &dict_iter)) {
  1627. dbus_message_unref(msg);
  1628. return;
  1629. }
  1630. dbus_connection_send(iface->con, msg, NULL);
  1631. dbus_message_unref(msg);
  1632. }
  1633. #endif /* CONFIG_P2P */
  1634. /**
  1635. * wpas_dbus_signal_prop_changed - Signals change of property
  1636. * @wpa_s: %wpa_supplicant network interface data
  1637. * @property: indicates which property has changed
  1638. *
  1639. * Sends PropertyChanged signals with path, interface and arguments
  1640. * depending on which property has changed.
  1641. */
  1642. void wpas_dbus_signal_prop_changed(struct wpa_supplicant *wpa_s,
  1643. enum wpas_dbus_prop property)
  1644. {
  1645. char *prop;
  1646. dbus_bool_t flush;
  1647. if (wpa_s->dbus_new_path == NULL)
  1648. return; /* Skip signal since D-Bus setup is not yet ready */
  1649. flush = FALSE;
  1650. switch (property) {
  1651. case WPAS_DBUS_PROP_AP_SCAN:
  1652. prop = "ApScan";
  1653. break;
  1654. case WPAS_DBUS_PROP_SCANNING:
  1655. prop = "Scanning";
  1656. break;
  1657. case WPAS_DBUS_PROP_STATE:
  1658. prop = "State";
  1659. break;
  1660. case WPAS_DBUS_PROP_CURRENT_BSS:
  1661. prop = "CurrentBSS";
  1662. break;
  1663. case WPAS_DBUS_PROP_CURRENT_NETWORK:
  1664. prop = "CurrentNetwork";
  1665. break;
  1666. case WPAS_DBUS_PROP_BSSS:
  1667. prop = "BSSs";
  1668. break;
  1669. case WPAS_DBUS_PROP_CURRENT_AUTH_MODE:
  1670. prop = "CurrentAuthMode";
  1671. break;
  1672. case WPAS_DBUS_PROP_DISCONNECT_REASON:
  1673. prop = "DisconnectReason";
  1674. flush = TRUE;
  1675. break;
  1676. case WPAS_DBUS_PROP_ASSOC_STATUS_CODE:
  1677. prop = "AssocStatusCode";
  1678. flush = TRUE;
  1679. break;
  1680. default:
  1681. wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
  1682. __func__, property);
  1683. return;
  1684. }
  1685. wpa_dbus_mark_property_changed(wpa_s->global->dbus,
  1686. wpa_s->dbus_new_path,
  1687. WPAS_DBUS_NEW_IFACE_INTERFACE, prop);
  1688. if (flush) {
  1689. wpa_dbus_flush_object_changed_properties(
  1690. wpa_s->global->dbus->con, wpa_s->dbus_new_path);
  1691. }
  1692. }
  1693. /**
  1694. * wpas_dbus_bss_signal_prop_changed - Signals change of BSS property
  1695. * @wpa_s: %wpa_supplicant network interface data
  1696. * @property: indicates which property has changed
  1697. * @id: unique BSS identifier
  1698. *
  1699. * Sends PropertyChanged signals with path, interface, and arguments depending
  1700. * on which property has changed.
  1701. */
  1702. void wpas_dbus_bss_signal_prop_changed(struct wpa_supplicant *wpa_s,
  1703. enum wpas_dbus_bss_prop property,
  1704. unsigned int id)
  1705. {
  1706. char path[WPAS_DBUS_OBJECT_PATH_MAX];
  1707. char *prop;
  1708. if (!wpa_s->dbus_new_path)
  1709. return;
  1710. switch (property) {
  1711. case WPAS_DBUS_BSS_PROP_SIGNAL:
  1712. prop = "Signal";
  1713. break;
  1714. case WPAS_DBUS_BSS_PROP_FREQ:
  1715. prop = "Frequency";
  1716. break;
  1717. case WPAS_DBUS_BSS_PROP_MODE:
  1718. prop = "Mode";
  1719. break;
  1720. case WPAS_DBUS_BSS_PROP_PRIVACY:
  1721. prop = "Privacy";
  1722. break;
  1723. case WPAS_DBUS_BSS_PROP_RATES:
  1724. prop = "Rates";
  1725. break;
  1726. case WPAS_DBUS_BSS_PROP_WPA:
  1727. prop = "WPA";
  1728. break;
  1729. case WPAS_DBUS_BSS_PROP_RSN:
  1730. prop = "RSN";
  1731. break;
  1732. case WPAS_DBUS_BSS_PROP_WPS:
  1733. prop = "WPS";
  1734. break;
  1735. case WPAS_DBUS_BSS_PROP_IES:
  1736. prop = "IEs";
  1737. break;
  1738. case WPAS_DBUS_BSS_PROP_AGE:
  1739. prop = "Age";
  1740. break;
  1741. default:
  1742. wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
  1743. __func__, property);
  1744. return;
  1745. }
  1746. os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
  1747. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  1748. wpa_s->dbus_new_path, id);
  1749. wpa_dbus_mark_property_changed(wpa_s->global->dbus, path,
  1750. WPAS_DBUS_NEW_IFACE_BSS, prop);
  1751. }
  1752. /**
  1753. * wpas_dbus_signal_debug_level_changed - Signals change of debug param
  1754. * @global: wpa_global structure
  1755. *
  1756. * Sends PropertyChanged signals informing that debug level has changed.
  1757. */
  1758. void wpas_dbus_signal_debug_level_changed(struct wpa_global *global)
  1759. {
  1760. wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
  1761. WPAS_DBUS_NEW_INTERFACE,
  1762. "DebugLevel");
  1763. }
  1764. /**
  1765. * wpas_dbus_signal_debug_timestamp_changed - Signals change of debug param
  1766. * @global: wpa_global structure
  1767. *
  1768. * Sends PropertyChanged signals informing that debug timestamp has changed.
  1769. */
  1770. void wpas_dbus_signal_debug_timestamp_changed(struct wpa_global *global)
  1771. {
  1772. wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
  1773. WPAS_DBUS_NEW_INTERFACE,
  1774. "DebugTimestamp");
  1775. }
  1776. /**
  1777. * wpas_dbus_signal_debug_show_keys_changed - Signals change of debug param
  1778. * @global: wpa_global structure
  1779. *
  1780. * Sends PropertyChanged signals informing that debug show_keys has changed.
  1781. */
  1782. void wpas_dbus_signal_debug_show_keys_changed(struct wpa_global *global)
  1783. {
  1784. wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
  1785. WPAS_DBUS_NEW_INTERFACE,
  1786. "DebugShowKeys");
  1787. }
  1788. static void wpas_dbus_register(struct wpa_dbus_object_desc *obj_desc,
  1789. void *priv,
  1790. WPADBusArgumentFreeFunction priv_free,
  1791. const struct wpa_dbus_method_desc *methods,
  1792. const struct wpa_dbus_property_desc *properties,
  1793. const struct wpa_dbus_signal_desc *signals)
  1794. {
  1795. int n;
  1796. obj_desc->user_data = priv;
  1797. obj_desc->user_data_free_func = priv_free;
  1798. obj_desc->methods = methods;
  1799. obj_desc->properties = properties;
  1800. obj_desc->signals = signals;
  1801. for (n = 0; properties && properties->dbus_property; properties++)
  1802. n++;
  1803. obj_desc->prop_changed_flags = os_zalloc(n);
  1804. if (!obj_desc->prop_changed_flags)
  1805. wpa_printf(MSG_DEBUG, "dbus: %s: can't register handlers",
  1806. __func__);
  1807. }
  1808. static const struct wpa_dbus_method_desc wpas_dbus_global_methods[] = {
  1809. { "CreateInterface", WPAS_DBUS_NEW_INTERFACE,
  1810. (WPADBusMethodHandler) wpas_dbus_handler_create_interface,
  1811. {
  1812. { "args", "a{sv}", ARG_IN },
  1813. { "path", "o", ARG_OUT },
  1814. END_ARGS
  1815. }
  1816. },
  1817. { "RemoveInterface", WPAS_DBUS_NEW_INTERFACE,
  1818. (WPADBusMethodHandler) wpas_dbus_handler_remove_interface,
  1819. {
  1820. { "path", "o", ARG_IN },
  1821. END_ARGS
  1822. }
  1823. },
  1824. { "GetInterface", WPAS_DBUS_NEW_INTERFACE,
  1825. (WPADBusMethodHandler) wpas_dbus_handler_get_interface,
  1826. {
  1827. { "ifname", "s", ARG_IN },
  1828. { "path", "o", ARG_OUT },
  1829. END_ARGS
  1830. }
  1831. },
  1832. { "ExpectDisconnect", WPAS_DBUS_NEW_INTERFACE,
  1833. (WPADBusMethodHandler) wpas_dbus_handler_expect_disconnect,
  1834. {
  1835. END_ARGS
  1836. }
  1837. },
  1838. { NULL, NULL, NULL, { END_ARGS } }
  1839. };
  1840. static const struct wpa_dbus_property_desc wpas_dbus_global_properties[] = {
  1841. { "DebugLevel", WPAS_DBUS_NEW_INTERFACE, "s",
  1842. wpas_dbus_getter_debug_level,
  1843. wpas_dbus_setter_debug_level,
  1844. NULL
  1845. },
  1846. { "DebugTimestamp", WPAS_DBUS_NEW_INTERFACE, "b",
  1847. wpas_dbus_getter_debug_timestamp,
  1848. wpas_dbus_setter_debug_timestamp,
  1849. NULL
  1850. },
  1851. { "DebugShowKeys", WPAS_DBUS_NEW_INTERFACE, "b",
  1852. wpas_dbus_getter_debug_show_keys,
  1853. wpas_dbus_setter_debug_show_keys,
  1854. NULL
  1855. },
  1856. { "Interfaces", WPAS_DBUS_NEW_INTERFACE, "ao",
  1857. wpas_dbus_getter_interfaces,
  1858. NULL,
  1859. NULL
  1860. },
  1861. { "EapMethods", WPAS_DBUS_NEW_INTERFACE, "as",
  1862. wpas_dbus_getter_eap_methods,
  1863. NULL,
  1864. NULL
  1865. },
  1866. { "Capabilities", WPAS_DBUS_NEW_INTERFACE, "as",
  1867. wpas_dbus_getter_global_capabilities,
  1868. NULL,
  1869. NULL
  1870. },
  1871. #ifdef CONFIG_WIFI_DISPLAY
  1872. { "WFDIEs", WPAS_DBUS_NEW_INTERFACE, "ay",
  1873. wpas_dbus_getter_global_wfd_ies,
  1874. wpas_dbus_setter_global_wfd_ies,
  1875. NULL
  1876. },
  1877. #endif /* CONFIG_WIFI_DISPLAY */
  1878. { NULL, NULL, NULL, NULL, NULL, NULL }
  1879. };
  1880. static const struct wpa_dbus_signal_desc wpas_dbus_global_signals[] = {
  1881. { "InterfaceAdded", WPAS_DBUS_NEW_INTERFACE,
  1882. {
  1883. { "path", "o", ARG_OUT },
  1884. { "properties", "a{sv}", ARG_OUT },
  1885. END_ARGS
  1886. }
  1887. },
  1888. { "InterfaceRemoved", WPAS_DBUS_NEW_INTERFACE,
  1889. {
  1890. { "path", "o", ARG_OUT },
  1891. END_ARGS
  1892. }
  1893. },
  1894. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  1895. { "PropertiesChanged", WPAS_DBUS_NEW_INTERFACE,
  1896. {
  1897. { "properties", "a{sv}", ARG_OUT },
  1898. END_ARGS
  1899. }
  1900. },
  1901. { NULL, NULL, { END_ARGS } }
  1902. };
  1903. static char * uscore_to_dbus(const char *uscore)
  1904. {
  1905. const char *p = uscore;
  1906. char *str, *s;
  1907. dbus_bool_t last_was_uscore = TRUE;
  1908. s = str = os_zalloc(os_strlen(uscore) + 1);
  1909. if (!str)
  1910. return NULL;
  1911. while (p && *p) {
  1912. if (*p == '_') {
  1913. last_was_uscore = TRUE;
  1914. } else {
  1915. *s++ = last_was_uscore ? toupper(*p) : *p;
  1916. last_was_uscore = FALSE;
  1917. }
  1918. p++;
  1919. }
  1920. return str;
  1921. }
  1922. static int wpa_dbus_ctrl_iface_props_init(struct wpas_dbus_priv *priv);
  1923. static void wpa_dbus_ctrl_iface_props_deinit(struct wpas_dbus_priv *priv)
  1924. {
  1925. int idx = priv->globals_start;
  1926. /* Free all allocated property values */
  1927. while (priv->all_interface_properties[idx].dbus_property)
  1928. os_free((char *)
  1929. priv->all_interface_properties[idx++].dbus_property);
  1930. os_free((char *) priv->all_interface_properties);
  1931. }
  1932. /**
  1933. * wpas_dbus_ctrl_iface_init - Initialize dbus control interface
  1934. * @global: Pointer to global data from wpa_supplicant_init()
  1935. * Returns: 0 on success or -1 on failure
  1936. *
  1937. * Initialize the dbus control interface for wpa_supplicant and start
  1938. * receiving commands from external programs over the bus.
  1939. */
  1940. int wpas_dbus_ctrl_iface_init(struct wpas_dbus_priv *priv)
  1941. {
  1942. struct wpa_dbus_object_desc *obj_desc;
  1943. int ret;
  1944. ret = wpa_dbus_ctrl_iface_props_init(priv);
  1945. if (ret < 0) {
  1946. wpa_printf(MSG_ERROR,
  1947. "dbus: Not enough memory to init interface properties");
  1948. return -1;
  1949. }
  1950. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  1951. if (!obj_desc) {
  1952. wpa_printf(MSG_ERROR,
  1953. "Not enough memory to create object description");
  1954. goto error;
  1955. }
  1956. wpas_dbus_register(obj_desc, priv->global, NULL,
  1957. wpas_dbus_global_methods,
  1958. wpas_dbus_global_properties,
  1959. wpas_dbus_global_signals);
  1960. wpa_printf(MSG_DEBUG, "dbus: Register D-Bus object '%s'",
  1961. WPAS_DBUS_NEW_PATH);
  1962. ret = wpa_dbus_ctrl_iface_init(priv, WPAS_DBUS_NEW_PATH,
  1963. WPAS_DBUS_NEW_SERVICE,
  1964. obj_desc);
  1965. if (ret < 0) {
  1966. free_dbus_object_desc(obj_desc);
  1967. goto error;
  1968. }
  1969. priv->dbus_new_initialized = 1;
  1970. return 0;
  1971. error:
  1972. wpa_dbus_ctrl_iface_props_deinit(priv);
  1973. return -1;
  1974. }
  1975. /**
  1976. * wpas_dbus_ctrl_iface_deinit - Deinitialize dbus ctrl interface for
  1977. * wpa_supplicant
  1978. * @priv: Pointer to dbus private data from wpas_dbus_init()
  1979. *
  1980. * Deinitialize the dbus control interface that was initialized with
  1981. * wpas_dbus_ctrl_iface_init().
  1982. */
  1983. void wpas_dbus_ctrl_iface_deinit(struct wpas_dbus_priv *priv)
  1984. {
  1985. if (!priv->dbus_new_initialized)
  1986. return;
  1987. wpa_printf(MSG_DEBUG, "dbus: Unregister D-Bus object '%s'",
  1988. WPAS_DBUS_NEW_PATH);
  1989. dbus_connection_unregister_object_path(priv->con, WPAS_DBUS_NEW_PATH);
  1990. wpa_dbus_ctrl_iface_props_deinit(priv);
  1991. }
  1992. static void wpa_dbus_free(void *ptr)
  1993. {
  1994. os_free(ptr);
  1995. }
  1996. static const struct wpa_dbus_property_desc wpas_dbus_network_properties[] = {
  1997. { "Properties", WPAS_DBUS_NEW_IFACE_NETWORK, "a{sv}",
  1998. wpas_dbus_getter_network_properties,
  1999. wpas_dbus_setter_network_properties,
  2000. NULL
  2001. },
  2002. { "Enabled", WPAS_DBUS_NEW_IFACE_NETWORK, "b",
  2003. wpas_dbus_getter_enabled,
  2004. wpas_dbus_setter_enabled,
  2005. NULL
  2006. },
  2007. { NULL, NULL, NULL, NULL, NULL, NULL }
  2008. };
  2009. static const struct wpa_dbus_signal_desc wpas_dbus_network_signals[] = {
  2010. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  2011. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_NETWORK,
  2012. {
  2013. { "properties", "a{sv}", ARG_OUT },
  2014. END_ARGS
  2015. }
  2016. },
  2017. { NULL, NULL, { END_ARGS } }
  2018. };
  2019. /**
  2020. * wpas_dbus_register_network - Register a configured network with dbus
  2021. * @wpa_s: wpa_supplicant interface structure
  2022. * @ssid: network configuration data
  2023. * Returns: 0 on success, -1 on failure
  2024. *
  2025. * Registers network representing object with dbus
  2026. */
  2027. int wpas_dbus_register_network(struct wpa_supplicant *wpa_s,
  2028. struct wpa_ssid *ssid)
  2029. {
  2030. struct wpas_dbus_priv *ctrl_iface;
  2031. struct wpa_dbus_object_desc *obj_desc;
  2032. struct network_handler_args *arg;
  2033. char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2034. #ifdef CONFIG_P2P
  2035. /*
  2036. * If it is a persistent group register it as such.
  2037. * This is to handle cases where an interface is being initialized
  2038. * with a list of networks read from config.
  2039. */
  2040. if (network_is_persistent_group(ssid))
  2041. return wpas_dbus_register_persistent_group(wpa_s, ssid);
  2042. #endif /* CONFIG_P2P */
  2043. /* Do nothing if the control interface is not turned on */
  2044. if (wpa_s == NULL || wpa_s->global == NULL || !wpa_s->dbus_new_path)
  2045. return 0;
  2046. ctrl_iface = wpa_s->global->dbus;
  2047. if (ctrl_iface == NULL)
  2048. return 0;
  2049. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2050. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  2051. wpa_s->dbus_new_path, ssid->id);
  2052. wpa_printf(MSG_DEBUG, "dbus: Register network object '%s'",
  2053. net_obj_path);
  2054. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  2055. if (!obj_desc) {
  2056. wpa_printf(MSG_ERROR,
  2057. "Not enough memory to create object description");
  2058. goto err;
  2059. }
  2060. /* allocate memory for handlers arguments */
  2061. arg = os_zalloc(sizeof(struct network_handler_args));
  2062. if (!arg) {
  2063. wpa_printf(MSG_ERROR,
  2064. "Not enough memory to create arguments for method");
  2065. goto err;
  2066. }
  2067. arg->wpa_s = wpa_s;
  2068. arg->ssid = ssid;
  2069. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  2070. wpas_dbus_network_properties,
  2071. wpas_dbus_network_signals);
  2072. if (wpa_dbus_register_object_per_iface(ctrl_iface, net_obj_path,
  2073. wpa_s->ifname, obj_desc))
  2074. goto err;
  2075. wpas_dbus_signal_network_added(wpa_s, ssid->id);
  2076. return 0;
  2077. err:
  2078. free_dbus_object_desc(obj_desc);
  2079. return -1;
  2080. }
  2081. /**
  2082. * wpas_dbus_unregister_network - Unregister a configured network from dbus
  2083. * @wpa_s: wpa_supplicant interface structure
  2084. * @nid: network id
  2085. * Returns: 0 on success, -1 on failure
  2086. *
  2087. * Unregisters network representing object from dbus
  2088. */
  2089. int wpas_dbus_unregister_network(struct wpa_supplicant *wpa_s, int nid)
  2090. {
  2091. struct wpas_dbus_priv *ctrl_iface;
  2092. char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2093. int ret;
  2094. #ifdef CONFIG_P2P
  2095. struct wpa_ssid *ssid;
  2096. ssid = wpa_config_get_network(wpa_s->conf, nid);
  2097. /* If it is a persistent group unregister it as such */
  2098. if (ssid && network_is_persistent_group(ssid))
  2099. return wpas_dbus_unregister_persistent_group(wpa_s, nid);
  2100. #endif /* CONFIG_P2P */
  2101. /* Do nothing if the control interface is not turned on */
  2102. if (wpa_s->global == NULL || wpa_s->dbus_new_path == NULL)
  2103. return 0;
  2104. ctrl_iface = wpa_s->global->dbus;
  2105. if (ctrl_iface == NULL)
  2106. return 0;
  2107. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2108. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  2109. wpa_s->dbus_new_path, nid);
  2110. wpa_printf(MSG_DEBUG, "dbus: Unregister network object '%s'",
  2111. net_obj_path);
  2112. ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, net_obj_path);
  2113. if (!ret)
  2114. wpas_dbus_signal_network_removed(wpa_s, nid);
  2115. return ret;
  2116. }
  2117. static const struct wpa_dbus_property_desc wpas_dbus_bss_properties[] = {
  2118. { "SSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
  2119. wpas_dbus_getter_bss_ssid,
  2120. NULL,
  2121. NULL
  2122. },
  2123. { "BSSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
  2124. wpas_dbus_getter_bss_bssid,
  2125. NULL,
  2126. NULL
  2127. },
  2128. { "Privacy", WPAS_DBUS_NEW_IFACE_BSS, "b",
  2129. wpas_dbus_getter_bss_privacy,
  2130. NULL,
  2131. NULL
  2132. },
  2133. { "Mode", WPAS_DBUS_NEW_IFACE_BSS, "s",
  2134. wpas_dbus_getter_bss_mode,
  2135. NULL,
  2136. NULL
  2137. },
  2138. { "Signal", WPAS_DBUS_NEW_IFACE_BSS, "n",
  2139. wpas_dbus_getter_bss_signal,
  2140. NULL,
  2141. NULL
  2142. },
  2143. { "Frequency", WPAS_DBUS_NEW_IFACE_BSS, "q",
  2144. wpas_dbus_getter_bss_frequency,
  2145. NULL,
  2146. NULL
  2147. },
  2148. { "Rates", WPAS_DBUS_NEW_IFACE_BSS, "au",
  2149. wpas_dbus_getter_bss_rates,
  2150. NULL,
  2151. NULL
  2152. },
  2153. { "WPA", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
  2154. wpas_dbus_getter_bss_wpa,
  2155. NULL,
  2156. NULL
  2157. },
  2158. { "RSN", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
  2159. wpas_dbus_getter_bss_rsn,
  2160. NULL,
  2161. NULL
  2162. },
  2163. { "WPS", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
  2164. wpas_dbus_getter_bss_wps,
  2165. NULL,
  2166. NULL
  2167. },
  2168. { "IEs", WPAS_DBUS_NEW_IFACE_BSS, "ay",
  2169. wpas_dbus_getter_bss_ies,
  2170. NULL,
  2171. NULL
  2172. },
  2173. { "Age", WPAS_DBUS_NEW_IFACE_BSS, "u",
  2174. wpas_dbus_getter_bss_age,
  2175. NULL,
  2176. NULL
  2177. },
  2178. { NULL, NULL, NULL, NULL, NULL, NULL }
  2179. };
  2180. static const struct wpa_dbus_signal_desc wpas_dbus_bss_signals[] = {
  2181. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  2182. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_BSS,
  2183. {
  2184. { "properties", "a{sv}", ARG_OUT },
  2185. END_ARGS
  2186. }
  2187. },
  2188. { NULL, NULL, { END_ARGS } }
  2189. };
  2190. /**
  2191. * wpas_dbus_unregister_bss - Unregister a scanned BSS from dbus
  2192. * @wpa_s: wpa_supplicant interface structure
  2193. * @bssid: scanned network bssid
  2194. * @id: unique BSS identifier
  2195. * Returns: 0 on success, -1 on failure
  2196. *
  2197. * Unregisters BSS representing object from dbus
  2198. */
  2199. int wpas_dbus_unregister_bss(struct wpa_supplicant *wpa_s,
  2200. u8 bssid[ETH_ALEN], unsigned int id)
  2201. {
  2202. struct wpas_dbus_priv *ctrl_iface;
  2203. char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2204. /* Do nothing if the control interface is not turned on */
  2205. if (wpa_s == NULL || wpa_s->global == NULL || !wpa_s->dbus_new_path)
  2206. return 0;
  2207. ctrl_iface = wpa_s->global->dbus;
  2208. if (ctrl_iface == NULL)
  2209. return 0;
  2210. os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2211. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  2212. wpa_s->dbus_new_path, id);
  2213. wpa_printf(MSG_DEBUG, "dbus: Unregister BSS object '%s'",
  2214. bss_obj_path);
  2215. if (wpa_dbus_unregister_object_per_iface(ctrl_iface, bss_obj_path)) {
  2216. wpa_printf(MSG_ERROR, "dbus: Cannot unregister BSS object %s",
  2217. bss_obj_path);
  2218. return -1;
  2219. }
  2220. wpas_dbus_signal_bss_removed(wpa_s, bss_obj_path);
  2221. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSSS);
  2222. return 0;
  2223. }
  2224. /**
  2225. * wpas_dbus_register_bss - Register a scanned BSS with dbus
  2226. * @wpa_s: wpa_supplicant interface structure
  2227. * @bssid: scanned network bssid
  2228. * @id: unique BSS identifier
  2229. * Returns: 0 on success, -1 on failure
  2230. *
  2231. * Registers BSS representing object with dbus
  2232. */
  2233. int wpas_dbus_register_bss(struct wpa_supplicant *wpa_s,
  2234. u8 bssid[ETH_ALEN], unsigned int id)
  2235. {
  2236. struct wpas_dbus_priv *ctrl_iface;
  2237. struct wpa_dbus_object_desc *obj_desc;
  2238. char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2239. struct bss_handler_args *arg;
  2240. /* Do nothing if the control interface is not turned on */
  2241. if (wpa_s == NULL || wpa_s->global == NULL || !wpa_s->dbus_new_path)
  2242. return 0;
  2243. ctrl_iface = wpa_s->global->dbus;
  2244. if (ctrl_iface == NULL)
  2245. return 0;
  2246. os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2247. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  2248. wpa_s->dbus_new_path, id);
  2249. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  2250. if (!obj_desc) {
  2251. wpa_printf(MSG_ERROR,
  2252. "Not enough memory to create object description");
  2253. goto err;
  2254. }
  2255. arg = os_zalloc(sizeof(struct bss_handler_args));
  2256. if (!arg) {
  2257. wpa_printf(MSG_ERROR,
  2258. "Not enough memory to create arguments for handler");
  2259. goto err;
  2260. }
  2261. arg->wpa_s = wpa_s;
  2262. arg->id = id;
  2263. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  2264. wpas_dbus_bss_properties,
  2265. wpas_dbus_bss_signals);
  2266. wpa_printf(MSG_DEBUG, "dbus: Register BSS object '%s'",
  2267. bss_obj_path);
  2268. if (wpa_dbus_register_object_per_iface(ctrl_iface, bss_obj_path,
  2269. wpa_s->ifname, obj_desc)) {
  2270. wpa_printf(MSG_ERROR,
  2271. "Cannot register BSSID dbus object %s.",
  2272. bss_obj_path);
  2273. goto err;
  2274. }
  2275. wpas_dbus_signal_bss_added(wpa_s, bss_obj_path);
  2276. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSSS);
  2277. return 0;
  2278. err:
  2279. free_dbus_object_desc(obj_desc);
  2280. return -1;
  2281. }
  2282. static const struct wpa_dbus_method_desc wpas_dbus_interface_methods[] = {
  2283. { "Scan", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2284. (WPADBusMethodHandler) wpas_dbus_handler_scan,
  2285. {
  2286. { "args", "a{sv}", ARG_IN },
  2287. END_ARGS
  2288. }
  2289. },
  2290. { "SignalPoll", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2291. (WPADBusMethodHandler) wpas_dbus_handler_signal_poll,
  2292. {
  2293. { "args", "a{sv}", ARG_OUT },
  2294. END_ARGS
  2295. }
  2296. },
  2297. { "Disconnect", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2298. (WPADBusMethodHandler) wpas_dbus_handler_disconnect,
  2299. {
  2300. END_ARGS
  2301. }
  2302. },
  2303. { "AddNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2304. (WPADBusMethodHandler) wpas_dbus_handler_add_network,
  2305. {
  2306. { "args", "a{sv}", ARG_IN },
  2307. { "path", "o", ARG_OUT },
  2308. END_ARGS
  2309. }
  2310. },
  2311. { "Reassociate", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2312. (WPADBusMethodHandler) wpas_dbus_handler_reassociate,
  2313. {
  2314. END_ARGS
  2315. }
  2316. },
  2317. { "Reattach", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2318. (WPADBusMethodHandler) wpas_dbus_handler_reattach,
  2319. {
  2320. END_ARGS
  2321. }
  2322. },
  2323. { "Reconnect", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2324. (WPADBusMethodHandler) wpas_dbus_handler_reconnect,
  2325. {
  2326. END_ARGS
  2327. }
  2328. },
  2329. { "RemoveNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2330. (WPADBusMethodHandler) wpas_dbus_handler_remove_network,
  2331. {
  2332. { "path", "o", ARG_IN },
  2333. END_ARGS
  2334. }
  2335. },
  2336. { "RemoveAllNetworks", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2337. (WPADBusMethodHandler) wpas_dbus_handler_remove_all_networks,
  2338. {
  2339. END_ARGS
  2340. }
  2341. },
  2342. { "SelectNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2343. (WPADBusMethodHandler) wpas_dbus_handler_select_network,
  2344. {
  2345. { "path", "o", ARG_IN },
  2346. END_ARGS
  2347. }
  2348. },
  2349. { "NetworkReply", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2350. (WPADBusMethodHandler) wpas_dbus_handler_network_reply,
  2351. {
  2352. { "path", "o", ARG_IN },
  2353. { "field", "s", ARG_IN },
  2354. { "value", "s", ARG_IN },
  2355. END_ARGS
  2356. }
  2357. },
  2358. #ifndef CONFIG_NO_CONFIG_BLOBS
  2359. { "AddBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2360. (WPADBusMethodHandler) wpas_dbus_handler_add_blob,
  2361. {
  2362. { "name", "s", ARG_IN },
  2363. { "data", "ay", ARG_IN },
  2364. END_ARGS
  2365. }
  2366. },
  2367. { "GetBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2368. (WPADBusMethodHandler) wpas_dbus_handler_get_blob,
  2369. {
  2370. { "name", "s", ARG_IN },
  2371. { "data", "ay", ARG_OUT },
  2372. END_ARGS
  2373. }
  2374. },
  2375. { "RemoveBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2376. (WPADBusMethodHandler) wpas_dbus_handler_remove_blob,
  2377. {
  2378. { "name", "s", ARG_IN },
  2379. END_ARGS
  2380. }
  2381. },
  2382. #endif /* CONFIG_NO_CONFIG_BLOBS */
  2383. { "SetPKCS11EngineAndModulePath", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2384. (WPADBusMethodHandler)
  2385. wpas_dbus_handler_set_pkcs11_engine_and_module_path,
  2386. {
  2387. { "pkcs11_engine_path", "s", ARG_IN },
  2388. { "pkcs11_module_path", "s", ARG_IN },
  2389. END_ARGS
  2390. }
  2391. },
  2392. #ifdef CONFIG_WPS
  2393. { "Start", WPAS_DBUS_NEW_IFACE_WPS,
  2394. (WPADBusMethodHandler) wpas_dbus_handler_wps_start,
  2395. {
  2396. { "args", "a{sv}", ARG_IN },
  2397. { "output", "a{sv}", ARG_OUT },
  2398. END_ARGS
  2399. }
  2400. },
  2401. { "Cancel", WPAS_DBUS_NEW_IFACE_WPS,
  2402. (WPADBusMethodHandler) wpas_dbus_handler_wps_cancel,
  2403. {
  2404. END_ARGS
  2405. }
  2406. },
  2407. #endif /* CONFIG_WPS */
  2408. #ifdef CONFIG_P2P
  2409. { "Find", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2410. (WPADBusMethodHandler) wpas_dbus_handler_p2p_find,
  2411. {
  2412. { "args", "a{sv}", ARG_IN },
  2413. END_ARGS
  2414. }
  2415. },
  2416. { "StopFind", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2417. (WPADBusMethodHandler) wpas_dbus_handler_p2p_stop_find,
  2418. {
  2419. END_ARGS
  2420. }
  2421. },
  2422. { "Listen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2423. (WPADBusMethodHandler) wpas_dbus_handler_p2p_listen,
  2424. {
  2425. { "timeout", "i", ARG_IN },
  2426. END_ARGS
  2427. }
  2428. },
  2429. { "ExtendedListen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2430. (WPADBusMethodHandler) wpas_dbus_handler_p2p_extendedlisten,
  2431. {
  2432. { "args", "a{sv}", ARG_IN },
  2433. END_ARGS
  2434. }
  2435. },
  2436. { "PresenceRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2437. (WPADBusMethodHandler) wpas_dbus_handler_p2p_presence_request,
  2438. {
  2439. { "args", "a{sv}", ARG_IN },
  2440. END_ARGS
  2441. }
  2442. },
  2443. { "ProvisionDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2444. (WPADBusMethodHandler) wpas_dbus_handler_p2p_prov_disc_req,
  2445. {
  2446. { "peer", "o", ARG_IN },
  2447. { "config_method", "s", ARG_IN },
  2448. END_ARGS
  2449. }
  2450. },
  2451. { "Connect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2452. (WPADBusMethodHandler) wpas_dbus_handler_p2p_connect,
  2453. {
  2454. { "args", "a{sv}", ARG_IN },
  2455. { "generated_pin", "s", ARG_OUT },
  2456. END_ARGS
  2457. }
  2458. },
  2459. { "GroupAdd", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2460. (WPADBusMethodHandler) wpas_dbus_handler_p2p_group_add,
  2461. {
  2462. { "args", "a{sv}", ARG_IN },
  2463. END_ARGS
  2464. }
  2465. },
  2466. { "Cancel", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2467. (WPADBusMethodHandler) wpas_dbus_handler_p2p_cancel,
  2468. {
  2469. END_ARGS
  2470. }
  2471. },
  2472. { "Invite", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2473. (WPADBusMethodHandler) wpas_dbus_handler_p2p_invite,
  2474. {
  2475. { "args", "a{sv}", ARG_IN },
  2476. END_ARGS
  2477. }
  2478. },
  2479. { "Disconnect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2480. (WPADBusMethodHandler) wpas_dbus_handler_p2p_disconnect,
  2481. {
  2482. END_ARGS
  2483. }
  2484. },
  2485. { "RejectPeer", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2486. (WPADBusMethodHandler) wpas_dbus_handler_p2p_rejectpeer,
  2487. {
  2488. { "peer", "o", ARG_IN },
  2489. END_ARGS
  2490. }
  2491. },
  2492. { "RemoveClient", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2493. (WPADBusMethodHandler) wpas_dbus_handler_p2p_remove_client,
  2494. {
  2495. { "args", "a{sv}", ARG_IN },
  2496. END_ARGS
  2497. }
  2498. },
  2499. { "Flush", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2500. (WPADBusMethodHandler) wpas_dbus_handler_p2p_flush,
  2501. {
  2502. END_ARGS
  2503. }
  2504. },
  2505. { "AddService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2506. (WPADBusMethodHandler) wpas_dbus_handler_p2p_add_service,
  2507. {
  2508. { "args", "a{sv}", ARG_IN },
  2509. END_ARGS
  2510. }
  2511. },
  2512. { "DeleteService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2513. (WPADBusMethodHandler) wpas_dbus_handler_p2p_delete_service,
  2514. {
  2515. { "args", "a{sv}", ARG_IN },
  2516. END_ARGS
  2517. }
  2518. },
  2519. { "FlushService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2520. (WPADBusMethodHandler) wpas_dbus_handler_p2p_flush_service,
  2521. {
  2522. END_ARGS
  2523. }
  2524. },
  2525. { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2526. (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_sd_req,
  2527. {
  2528. { "args", "a{sv}", ARG_IN },
  2529. { "ref", "t", ARG_OUT },
  2530. END_ARGS
  2531. }
  2532. },
  2533. { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2534. (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_sd_res,
  2535. {
  2536. { "args", "a{sv}", ARG_IN },
  2537. END_ARGS
  2538. }
  2539. },
  2540. { "ServiceDiscoveryCancelRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2541. (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_sd_cancel_req,
  2542. {
  2543. { "args", "t", ARG_IN },
  2544. END_ARGS
  2545. }
  2546. },
  2547. { "ServiceUpdate", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2548. (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_update,
  2549. {
  2550. END_ARGS
  2551. }
  2552. },
  2553. { "ServiceDiscoveryExternal", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2554. (WPADBusMethodHandler) wpas_dbus_handler_p2p_serv_disc_external,
  2555. {
  2556. { "arg", "i", ARG_IN },
  2557. END_ARGS
  2558. }
  2559. },
  2560. { "AddPersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2561. (WPADBusMethodHandler) wpas_dbus_handler_add_persistent_group,
  2562. {
  2563. { "args", "a{sv}", ARG_IN },
  2564. { "path", "o", ARG_OUT },
  2565. END_ARGS
  2566. }
  2567. },
  2568. { "RemovePersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2569. (WPADBusMethodHandler) wpas_dbus_handler_remove_persistent_group,
  2570. {
  2571. { "path", "o", ARG_IN },
  2572. END_ARGS
  2573. }
  2574. },
  2575. { "RemoveAllPersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2576. (WPADBusMethodHandler)
  2577. wpas_dbus_handler_remove_all_persistent_groups,
  2578. {
  2579. END_ARGS
  2580. }
  2581. },
  2582. #endif /* CONFIG_P2P */
  2583. { "FlushBSS", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2584. (WPADBusMethodHandler) wpas_dbus_handler_flush_bss,
  2585. {
  2586. { "age", "u", ARG_IN },
  2587. END_ARGS
  2588. }
  2589. },
  2590. #ifdef CONFIG_AP
  2591. { "SubscribeProbeReq", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2592. (WPADBusMethodHandler) wpas_dbus_handler_subscribe_preq,
  2593. {
  2594. END_ARGS
  2595. }
  2596. },
  2597. { "UnsubscribeProbeReq", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2598. (WPADBusMethodHandler) wpas_dbus_handler_unsubscribe_preq,
  2599. {
  2600. END_ARGS
  2601. }
  2602. },
  2603. #endif /* CONFIG_AP */
  2604. { "EAPLogoff", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2605. (WPADBusMethodHandler) wpas_dbus_handler_eap_logoff,
  2606. {
  2607. END_ARGS
  2608. }
  2609. },
  2610. { "EAPLogon", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2611. (WPADBusMethodHandler) wpas_dbus_handler_eap_logon,
  2612. {
  2613. END_ARGS
  2614. }
  2615. },
  2616. #ifdef CONFIG_AUTOSCAN
  2617. { "AutoScan", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2618. (WPADBusMethodHandler) wpas_dbus_handler_autoscan,
  2619. {
  2620. { "arg", "s", ARG_IN },
  2621. END_ARGS
  2622. }
  2623. },
  2624. #endif /* CONFIG_AUTOSCAN */
  2625. #ifdef CONFIG_TDLS
  2626. { "TDLSDiscover", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2627. (WPADBusMethodHandler) wpas_dbus_handler_tdls_discover,
  2628. {
  2629. { "peer_address", "s", ARG_IN },
  2630. END_ARGS
  2631. }
  2632. },
  2633. { "TDLSSetup", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2634. (WPADBusMethodHandler) wpas_dbus_handler_tdls_setup,
  2635. {
  2636. { "peer_address", "s", ARG_IN },
  2637. END_ARGS
  2638. }
  2639. },
  2640. { "TDLSStatus", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2641. (WPADBusMethodHandler) wpas_dbus_handler_tdls_status,
  2642. {
  2643. { "peer_address", "s", ARG_IN },
  2644. { "status", "s", ARG_OUT },
  2645. END_ARGS
  2646. }
  2647. },
  2648. { "TDLSTeardown", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2649. (WPADBusMethodHandler) wpas_dbus_handler_tdls_teardown,
  2650. {
  2651. { "peer_address", "s", ARG_IN },
  2652. END_ARGS
  2653. }
  2654. },
  2655. #endif /* CONFIG_TDLS */
  2656. { "VendorElemAdd", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2657. (WPADBusMethodHandler) wpas_dbus_handler_vendor_elem_add,
  2658. {
  2659. { "frame_id", "i", ARG_IN },
  2660. { "ielems", "ay", ARG_IN },
  2661. END_ARGS
  2662. }
  2663. },
  2664. { "VendorElemGet", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2665. (WPADBusMethodHandler) wpas_dbus_handler_vendor_elem_get,
  2666. {
  2667. { "frame_id", "i", ARG_IN },
  2668. { "ielems", "ay", ARG_OUT },
  2669. END_ARGS
  2670. }
  2671. },
  2672. { "VendorElemRem", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2673. (WPADBusMethodHandler) wpas_dbus_handler_vendor_elem_remove,
  2674. {
  2675. { "frame_id", "i", ARG_IN },
  2676. { "ielems", "ay", ARG_IN },
  2677. END_ARGS
  2678. }
  2679. },
  2680. #ifndef CONFIG_NO_CONFIG_WRITE
  2681. { "SaveConfig", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2682. (WPADBusMethodHandler) wpas_dbus_handler_save_config,
  2683. {
  2684. END_ARGS
  2685. }
  2686. },
  2687. #endif /* CONFIG_NO_CONFIG_WRITE */
  2688. { NULL, NULL, NULL, { END_ARGS } }
  2689. };
  2690. static const struct wpa_dbus_property_desc wpas_dbus_interface_properties[] = {
  2691. { "Capabilities", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{sv}",
  2692. wpas_dbus_getter_capabilities,
  2693. NULL,
  2694. NULL
  2695. },
  2696. { "State", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2697. wpas_dbus_getter_state,
  2698. NULL,
  2699. NULL
  2700. },
  2701. { "Scanning", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
  2702. wpas_dbus_getter_scanning,
  2703. NULL,
  2704. NULL
  2705. },
  2706. { "ApScan", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  2707. wpas_dbus_getter_ap_scan,
  2708. wpas_dbus_setter_ap_scan,
  2709. NULL
  2710. },
  2711. { "BSSExpireAge", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  2712. wpas_dbus_getter_bss_expire_age,
  2713. wpas_dbus_setter_bss_expire_age,
  2714. NULL
  2715. },
  2716. { "BSSExpireCount", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  2717. wpas_dbus_getter_bss_expire_count,
  2718. wpas_dbus_setter_bss_expire_count,
  2719. NULL
  2720. },
  2721. { "Country", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2722. wpas_dbus_getter_country,
  2723. wpas_dbus_setter_country,
  2724. NULL
  2725. },
  2726. { "Ifname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2727. wpas_dbus_getter_ifname,
  2728. NULL,
  2729. NULL
  2730. },
  2731. { "Driver", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2732. wpas_dbus_getter_driver,
  2733. NULL,
  2734. NULL
  2735. },
  2736. { "BridgeIfname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2737. wpas_dbus_getter_bridge_ifname,
  2738. NULL,
  2739. NULL
  2740. },
  2741. { "ConfigFile", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2742. wpas_dbus_getter_config_file,
  2743. NULL,
  2744. NULL
  2745. },
  2746. { "CurrentBSS", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
  2747. wpas_dbus_getter_current_bss,
  2748. NULL,
  2749. NULL
  2750. },
  2751. { "CurrentNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
  2752. wpas_dbus_getter_current_network,
  2753. NULL,
  2754. NULL
  2755. },
  2756. { "CurrentAuthMode", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2757. wpas_dbus_getter_current_auth_mode,
  2758. NULL,
  2759. NULL
  2760. },
  2761. { "Blobs", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{say}",
  2762. wpas_dbus_getter_blobs,
  2763. NULL,
  2764. NULL
  2765. },
  2766. { "BSSs", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
  2767. wpas_dbus_getter_bsss,
  2768. NULL,
  2769. NULL
  2770. },
  2771. { "Networks", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
  2772. wpas_dbus_getter_networks,
  2773. NULL,
  2774. NULL
  2775. },
  2776. { "FastReauth", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
  2777. wpas_dbus_getter_fast_reauth,
  2778. wpas_dbus_setter_fast_reauth,
  2779. NULL
  2780. },
  2781. { "ScanInterval", WPAS_DBUS_NEW_IFACE_INTERFACE, "i",
  2782. wpas_dbus_getter_scan_interval,
  2783. wpas_dbus_setter_scan_interval,
  2784. NULL
  2785. },
  2786. { "PKCS11EnginePath", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2787. wpas_dbus_getter_pkcs11_engine_path,
  2788. NULL,
  2789. NULL
  2790. },
  2791. { "PKCS11ModulePath", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2792. wpas_dbus_getter_pkcs11_module_path,
  2793. NULL,
  2794. NULL
  2795. },
  2796. #ifdef CONFIG_WPS
  2797. { "ProcessCredentials", WPAS_DBUS_NEW_IFACE_WPS, "b",
  2798. wpas_dbus_getter_process_credentials,
  2799. wpas_dbus_setter_process_credentials,
  2800. NULL
  2801. },
  2802. { "ConfigMethods", WPAS_DBUS_NEW_IFACE_WPS, "s",
  2803. wpas_dbus_getter_config_methods,
  2804. wpas_dbus_setter_config_methods,
  2805. NULL
  2806. },
  2807. #endif /* CONFIG_WPS */
  2808. #ifdef CONFIG_P2P
  2809. { "P2PDeviceConfig", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "a{sv}",
  2810. wpas_dbus_getter_p2p_device_config,
  2811. wpas_dbus_setter_p2p_device_config,
  2812. NULL
  2813. },
  2814. { "Peers", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
  2815. wpas_dbus_getter_p2p_peers,
  2816. NULL,
  2817. NULL
  2818. },
  2819. { "Role", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "s",
  2820. wpas_dbus_getter_p2p_role,
  2821. NULL,
  2822. NULL
  2823. },
  2824. { "Group", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
  2825. wpas_dbus_getter_p2p_group,
  2826. NULL,
  2827. NULL
  2828. },
  2829. { "PeerGO", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
  2830. wpas_dbus_getter_p2p_peergo,
  2831. NULL,
  2832. NULL
  2833. },
  2834. { "PersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
  2835. wpas_dbus_getter_persistent_groups,
  2836. NULL,
  2837. NULL
  2838. },
  2839. #endif /* CONFIG_P2P */
  2840. { "DisconnectReason", WPAS_DBUS_NEW_IFACE_INTERFACE, "i",
  2841. wpas_dbus_getter_disconnect_reason,
  2842. NULL,
  2843. NULL
  2844. },
  2845. { "AssocStatusCode", WPAS_DBUS_NEW_IFACE_INTERFACE, "i",
  2846. wpas_dbus_getter_assoc_status_code,
  2847. NULL,
  2848. NULL
  2849. },
  2850. { NULL, NULL, NULL, NULL, NULL, NULL }
  2851. };
  2852. static const struct wpa_dbus_signal_desc wpas_dbus_interface_signals[] = {
  2853. { "ScanDone", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2854. {
  2855. { "success", "b", ARG_OUT },
  2856. END_ARGS
  2857. }
  2858. },
  2859. { "BSSAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2860. {
  2861. { "path", "o", ARG_OUT },
  2862. { "properties", "a{sv}", ARG_OUT },
  2863. END_ARGS
  2864. }
  2865. },
  2866. { "BSSRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2867. {
  2868. { "path", "o", ARG_OUT },
  2869. END_ARGS
  2870. }
  2871. },
  2872. { "BlobAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2873. {
  2874. { "name", "s", ARG_OUT },
  2875. END_ARGS
  2876. }
  2877. },
  2878. { "BlobRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2879. {
  2880. { "name", "s", ARG_OUT },
  2881. END_ARGS
  2882. }
  2883. },
  2884. { "NetworkAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2885. {
  2886. { "path", "o", ARG_OUT },
  2887. { "properties", "a{sv}", ARG_OUT },
  2888. END_ARGS
  2889. }
  2890. },
  2891. { "NetworkRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2892. {
  2893. { "path", "o", ARG_OUT },
  2894. END_ARGS
  2895. }
  2896. },
  2897. { "NetworkSelected", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2898. {
  2899. { "path", "o", ARG_OUT },
  2900. END_ARGS
  2901. }
  2902. },
  2903. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  2904. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2905. {
  2906. { "properties", "a{sv}", ARG_OUT },
  2907. END_ARGS
  2908. }
  2909. },
  2910. #ifdef CONFIG_WPS
  2911. { "Event", WPAS_DBUS_NEW_IFACE_WPS,
  2912. {
  2913. { "name", "s", ARG_OUT },
  2914. { "args", "a{sv}", ARG_OUT },
  2915. END_ARGS
  2916. }
  2917. },
  2918. { "Credentials", WPAS_DBUS_NEW_IFACE_WPS,
  2919. {
  2920. { "credentials", "a{sv}", ARG_OUT },
  2921. END_ARGS
  2922. }
  2923. },
  2924. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  2925. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_WPS,
  2926. {
  2927. { "properties", "a{sv}", ARG_OUT },
  2928. END_ARGS
  2929. }
  2930. },
  2931. #endif /* CONFIG_WPS */
  2932. #ifdef CONFIG_P2P
  2933. { "DeviceFound", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2934. {
  2935. { "path", "o", ARG_OUT },
  2936. END_ARGS
  2937. }
  2938. },
  2939. { "DeviceFoundProperties", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2940. {
  2941. { "path", "o", ARG_OUT },
  2942. { "properties", "a{sv}", ARG_OUT },
  2943. END_ARGS
  2944. }
  2945. },
  2946. { "DeviceLost", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2947. {
  2948. { "path", "o", ARG_OUT },
  2949. END_ARGS
  2950. }
  2951. },
  2952. { "FindStopped", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2953. {
  2954. END_ARGS
  2955. }
  2956. },
  2957. { "ProvisionDiscoveryRequestDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2958. {
  2959. { "peer_object", "o", ARG_OUT },
  2960. { "pin", "s", ARG_OUT },
  2961. END_ARGS
  2962. }
  2963. },
  2964. { "ProvisionDiscoveryResponseDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2965. {
  2966. { "peer_object", "o", ARG_OUT },
  2967. { "pin", "s", ARG_OUT },
  2968. END_ARGS
  2969. }
  2970. },
  2971. { "ProvisionDiscoveryRequestEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2972. {
  2973. { "peer_object", "o", ARG_OUT },
  2974. END_ARGS
  2975. }
  2976. },
  2977. { "ProvisionDiscoveryResponseEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2978. {
  2979. { "peer_object", "o", ARG_OUT },
  2980. END_ARGS
  2981. }
  2982. },
  2983. { "ProvisionDiscoveryPBCRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2984. {
  2985. { "peer_object", "o", ARG_OUT },
  2986. END_ARGS
  2987. }
  2988. },
  2989. { "ProvisionDiscoveryPBCResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2990. {
  2991. { "peer_object", "o", ARG_OUT },
  2992. END_ARGS
  2993. }
  2994. },
  2995. { "ProvisionDiscoveryFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2996. {
  2997. { "peer_object", "o", ARG_OUT },
  2998. { "status", "i", ARG_OUT },
  2999. END_ARGS
  3000. }
  3001. },
  3002. { "GroupStarted", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3003. {
  3004. { "properties", "a{sv}", ARG_OUT },
  3005. END_ARGS
  3006. }
  3007. },
  3008. { "GroupFormationFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3009. {
  3010. { "reason", "s", ARG_OUT },
  3011. END_ARGS
  3012. }
  3013. },
  3014. { "GONegotiationSuccess", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3015. {
  3016. { "properties", "a{sv}", ARG_OUT },
  3017. END_ARGS
  3018. }
  3019. },
  3020. { "GONegotiationFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3021. {
  3022. { "properties", "a{sv}", ARG_OUT },
  3023. END_ARGS
  3024. }
  3025. },
  3026. { "GONegotiationRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3027. {
  3028. { "path", "o", ARG_OUT },
  3029. { "dev_passwd_id", "q", ARG_OUT },
  3030. { "device_go_intent", "y", ARG_OUT },
  3031. END_ARGS
  3032. }
  3033. },
  3034. { "InvitationResult", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3035. {
  3036. { "invite_result", "a{sv}", ARG_OUT },
  3037. END_ARGS
  3038. }
  3039. },
  3040. { "GroupFinished", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3041. {
  3042. { "properties", "a{sv}", ARG_OUT },
  3043. END_ARGS
  3044. }
  3045. },
  3046. { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3047. {
  3048. { "sd_request", "a{sv}", ARG_OUT },
  3049. END_ARGS
  3050. }
  3051. },
  3052. { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3053. {
  3054. { "sd_response", "a{sv}", ARG_OUT },
  3055. END_ARGS
  3056. }
  3057. },
  3058. { "PersistentGroupAdded", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3059. {
  3060. { "path", "o", ARG_OUT },
  3061. { "properties", "a{sv}", ARG_OUT },
  3062. END_ARGS
  3063. }
  3064. },
  3065. { "PersistentGroupRemoved", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3066. {
  3067. { "path", "o", ARG_OUT },
  3068. END_ARGS
  3069. }
  3070. },
  3071. { "WpsFailed", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3072. {
  3073. { "name", "s", ARG_OUT },
  3074. { "args", "a{sv}", ARG_OUT },
  3075. END_ARGS
  3076. }
  3077. },
  3078. { "InvitationReceived", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3079. {
  3080. { "properties", "a{sv}", ARG_OUT },
  3081. END_ARGS
  3082. }
  3083. },
  3084. #endif /* CONFIG_P2P */
  3085. #ifdef CONFIG_AP
  3086. { "ProbeRequest", WPAS_DBUS_NEW_IFACE_INTERFACE,
  3087. {
  3088. { "args", "a{sv}", ARG_OUT },
  3089. END_ARGS
  3090. }
  3091. },
  3092. #endif /* CONFIG_AP */
  3093. { "Certification", WPAS_DBUS_NEW_IFACE_INTERFACE,
  3094. {
  3095. { "certification", "a{sv}", ARG_OUT },
  3096. END_ARGS
  3097. }
  3098. },
  3099. { "EAP", WPAS_DBUS_NEW_IFACE_INTERFACE,
  3100. {
  3101. { "status", "s", ARG_OUT },
  3102. { "parameter", "s", ARG_OUT },
  3103. END_ARGS
  3104. }
  3105. },
  3106. { "StaAuthorized", WPAS_DBUS_NEW_IFACE_INTERFACE,
  3107. {
  3108. { "name", "s", ARG_OUT },
  3109. END_ARGS
  3110. }
  3111. },
  3112. { "StaDeauthorized", WPAS_DBUS_NEW_IFACE_INTERFACE,
  3113. {
  3114. { "name", "s", ARG_OUT },
  3115. END_ARGS
  3116. }
  3117. },
  3118. { "NetworkRequest", WPAS_DBUS_NEW_IFACE_INTERFACE,
  3119. {
  3120. { "path", "o", ARG_OUT },
  3121. { "field", "s", ARG_OUT },
  3122. { "text", "s", ARG_OUT },
  3123. END_ARGS
  3124. }
  3125. },
  3126. { NULL, NULL, { END_ARGS } }
  3127. };
  3128. static int wpa_dbus_ctrl_iface_props_init(struct wpas_dbus_priv *priv)
  3129. {
  3130. size_t all_size;
  3131. unsigned int i, j, count, num_const, num_globals;
  3132. const char *global_name;
  3133. static const char * const ignored_globals[] = {
  3134. "bss_expiration_age", "bss_expiration_scan_count",
  3135. "ap_scan", "country", "fast_reauth",
  3136. "pkcs11_engine_path", "pkcs11_module_path"
  3137. };
  3138. /* wpas_dbus_interface_properties terminates with a NULL element */
  3139. num_const = ARRAY_SIZE(wpas_dbus_interface_properties) - 1;
  3140. num_globals = wpa_config_get_num_global_field_names();
  3141. priv->globals_start = num_const;
  3142. /* allocate enough for all properties + terminating NULL element */
  3143. all_size = (num_globals + num_const + 1) *
  3144. sizeof(wpas_dbus_interface_properties[0]);
  3145. priv->all_interface_properties = os_zalloc(all_size);
  3146. if (!priv->all_interface_properties) {
  3147. wpa_printf(MSG_ERROR,
  3148. "dbus: Not enough memory for interface properties");
  3149. return -1;
  3150. }
  3151. /* Copy constant interface properties to the start of the array */
  3152. os_memcpy(priv->all_interface_properties,
  3153. wpas_dbus_interface_properties,
  3154. sizeof(wpas_dbus_interface_properties));
  3155. /* Dynamically construct interface global properties */
  3156. for (i = 0, count = num_const; i < num_globals; i++) {
  3157. struct wpa_dbus_property_desc *desc;
  3158. int no_var = 0;
  3159. /* ignore globals that are actually just methods */
  3160. global_name = wpa_config_get_global_field_name(i, &no_var);
  3161. if (no_var)
  3162. continue;
  3163. /* Ignore fields already explicitly exposed */
  3164. for (j = 0; j < ARRAY_SIZE(ignored_globals); j++) {
  3165. if (os_strcmp(global_name, ignored_globals[j]) == 0)
  3166. break;
  3167. }
  3168. if (j < ARRAY_SIZE(ignored_globals))
  3169. continue;
  3170. desc = &priv->all_interface_properties[count++];
  3171. desc->dbus_property = uscore_to_dbus(global_name);
  3172. if (!desc->dbus_property) {
  3173. wpa_printf(MSG_ERROR,
  3174. "dbus: Not enough memory for D-Bus property name");
  3175. goto error;
  3176. }
  3177. desc->dbus_interface = WPAS_DBUS_NEW_IFACE_INTERFACE;
  3178. desc->type = "s";
  3179. desc->getter = wpas_dbus_getter_iface_global;
  3180. desc->setter = wpas_dbus_setter_iface_global;
  3181. desc->data = global_name;
  3182. }
  3183. return 0;
  3184. error:
  3185. wpa_dbus_ctrl_iface_props_deinit(priv);
  3186. return -1;
  3187. }
  3188. /**
  3189. * wpas_dbus_register_interface - Register an interface with D-Bus
  3190. * @wpa_s: wpa_supplicant interface structure
  3191. * Returns: 0 on success, -1 on failure
  3192. */
  3193. int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s)
  3194. {
  3195. struct wpa_dbus_object_desc *obj_desc = NULL;
  3196. struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus;
  3197. int next;
  3198. /* Do nothing if the control interface is not turned on */
  3199. if (ctrl_iface == NULL)
  3200. return 0;
  3201. /* Create and set the interface's object path */
  3202. wpa_s->dbus_new_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
  3203. if (wpa_s->dbus_new_path == NULL)
  3204. return -1;
  3205. next = ctrl_iface->next_objid++;
  3206. os_snprintf(wpa_s->dbus_new_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3207. WPAS_DBUS_NEW_PATH_INTERFACES "/%u",
  3208. next);
  3209. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  3210. if (!obj_desc) {
  3211. wpa_printf(MSG_ERROR,
  3212. "Not enough memory to create object description");
  3213. goto err;
  3214. }
  3215. wpas_dbus_register(obj_desc, wpa_s, NULL, wpas_dbus_interface_methods,
  3216. ctrl_iface->all_interface_properties,
  3217. wpas_dbus_interface_signals);
  3218. wpa_printf(MSG_DEBUG, "dbus: Register interface object '%s'",
  3219. wpa_s->dbus_new_path);
  3220. if (wpa_dbus_register_object_per_iface(ctrl_iface,
  3221. wpa_s->dbus_new_path,
  3222. wpa_s->ifname, obj_desc))
  3223. goto err;
  3224. wpas_dbus_signal_interface_added(wpa_s);
  3225. return 0;
  3226. err:
  3227. os_free(wpa_s->dbus_new_path);
  3228. wpa_s->dbus_new_path = NULL;
  3229. free_dbus_object_desc(obj_desc);
  3230. return -1;
  3231. }
  3232. /**
  3233. * wpas_dbus_unregister_interface - Unregister the interface from D-Bus
  3234. * @wpa_s: wpa_supplicant interface structure
  3235. * Returns: 0 on success, -1 on failure
  3236. */
  3237. int wpas_dbus_unregister_interface(struct wpa_supplicant *wpa_s)
  3238. {
  3239. struct wpas_dbus_priv *ctrl_iface;
  3240. /* Do nothing if the control interface is not turned on */
  3241. if (wpa_s == NULL || wpa_s->global == NULL)
  3242. return 0;
  3243. ctrl_iface = wpa_s->global->dbus;
  3244. if (ctrl_iface == NULL || wpa_s->dbus_new_path == NULL)
  3245. return 0;
  3246. wpa_printf(MSG_DEBUG, "dbus: Unregister interface object '%s'",
  3247. wpa_s->dbus_new_path);
  3248. #ifdef CONFIG_AP
  3249. if (wpa_s->preq_notify_peer) {
  3250. wpas_dbus_unsubscribe_noc(ctrl_iface);
  3251. os_free(wpa_s->preq_notify_peer);
  3252. wpa_s->preq_notify_peer = NULL;
  3253. }
  3254. #endif /* CONFIG_AP */
  3255. if (wpa_dbus_unregister_object_per_iface(ctrl_iface,
  3256. wpa_s->dbus_new_path))
  3257. return -1;
  3258. wpas_dbus_signal_interface_removed(wpa_s);
  3259. os_free(wpa_s->dbus_new_path);
  3260. wpa_s->dbus_new_path = NULL;
  3261. return 0;
  3262. }
  3263. #ifdef CONFIG_P2P
  3264. static const struct wpa_dbus_property_desc wpas_dbus_p2p_peer_properties[] = {
  3265. { "DeviceName", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
  3266. wpas_dbus_getter_p2p_peer_device_name,
  3267. NULL,
  3268. NULL
  3269. },
  3270. { "Manufacturer", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
  3271. wpas_dbus_getter_p2p_peer_manufacturer,
  3272. NULL,
  3273. NULL
  3274. },
  3275. { "ModelName", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
  3276. wpas_dbus_getter_p2p_peer_modelname,
  3277. NULL,
  3278. NULL
  3279. },
  3280. { "ModelNumber", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
  3281. wpas_dbus_getter_p2p_peer_modelnumber,
  3282. NULL,
  3283. NULL
  3284. },
  3285. { "SerialNumber", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
  3286. wpas_dbus_getter_p2p_peer_serialnumber,
  3287. NULL,
  3288. NULL
  3289. },
  3290. { "PrimaryDeviceType", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
  3291. wpas_dbus_getter_p2p_peer_primary_device_type,
  3292. NULL,
  3293. NULL
  3294. },
  3295. { "config_method", WPAS_DBUS_NEW_IFACE_P2P_PEER, "q",
  3296. wpas_dbus_getter_p2p_peer_config_method,
  3297. NULL,
  3298. NULL
  3299. },
  3300. { "level", WPAS_DBUS_NEW_IFACE_P2P_PEER, "i",
  3301. wpas_dbus_getter_p2p_peer_level,
  3302. NULL,
  3303. NULL
  3304. },
  3305. { "devicecapability", WPAS_DBUS_NEW_IFACE_P2P_PEER, "y",
  3306. wpas_dbus_getter_p2p_peer_device_capability,
  3307. NULL,
  3308. NULL
  3309. },
  3310. { "groupcapability", WPAS_DBUS_NEW_IFACE_P2P_PEER, "y",
  3311. wpas_dbus_getter_p2p_peer_group_capability,
  3312. NULL,
  3313. NULL
  3314. },
  3315. { "SecondaryDeviceTypes", WPAS_DBUS_NEW_IFACE_P2P_PEER, "aay",
  3316. wpas_dbus_getter_p2p_peer_secondary_device_types,
  3317. NULL,
  3318. NULL
  3319. },
  3320. { "VendorExtension", WPAS_DBUS_NEW_IFACE_P2P_PEER, "aay",
  3321. wpas_dbus_getter_p2p_peer_vendor_extension,
  3322. NULL,
  3323. NULL
  3324. },
  3325. { "IEs", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
  3326. wpas_dbus_getter_p2p_peer_ies,
  3327. NULL,
  3328. NULL
  3329. },
  3330. { "DeviceAddress", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
  3331. wpas_dbus_getter_p2p_peer_device_address,
  3332. NULL,
  3333. NULL
  3334. },
  3335. { "Groups", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ao",
  3336. wpas_dbus_getter_p2p_peer_groups,
  3337. NULL,
  3338. NULL
  3339. },
  3340. { NULL, NULL, NULL, NULL, NULL, NULL }
  3341. };
  3342. static const struct wpa_dbus_signal_desc wpas_dbus_p2p_peer_signals[] = {
  3343. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  3344. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_P2P_PEER,
  3345. {
  3346. { "properties", "a{sv}", ARG_OUT },
  3347. END_ARGS
  3348. }
  3349. },
  3350. { NULL, NULL, { END_ARGS } }
  3351. };
  3352. /**
  3353. * wpas_dbus_signal_peer - Send a peer related event signal
  3354. * @wpa_s: %wpa_supplicant network interface data
  3355. * @dev: peer device object
  3356. * @interface: name of the interface emitting this signal.
  3357. * In case of peer objects, it would be emitted by either
  3358. * the "interface object" or by "peer objects"
  3359. * @sig_name: signal name - DeviceFound
  3360. * @properties: Whether to add a second argument with object properties
  3361. *
  3362. * Notify listeners about event related with p2p peer device
  3363. */
  3364. static void wpas_dbus_signal_peer(struct wpa_supplicant *wpa_s,
  3365. const u8 *dev_addr, const char *interface,
  3366. const char *sig_name, int properties)
  3367. {
  3368. struct wpas_dbus_priv *iface;
  3369. DBusMessage *msg;
  3370. DBusMessageIter iter;
  3371. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  3372. if (wpa_s->p2p_mgmt)
  3373. wpa_s = wpa_s->parent;
  3374. iface = wpa_s->global->dbus;
  3375. /* Do nothing if the control interface is not turned on */
  3376. if (iface == NULL || !wpa_s->dbus_new_path)
  3377. return;
  3378. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3379. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  3380. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  3381. msg = dbus_message_new_signal(wpa_s->dbus_new_path, interface,
  3382. sig_name);
  3383. if (msg == NULL)
  3384. return;
  3385. dbus_message_iter_init_append(msg, &iter);
  3386. path = peer_obj_path;
  3387. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  3388. &path) ||
  3389. (properties && !wpa_dbus_get_object_properties(
  3390. iface, peer_obj_path, WPAS_DBUS_NEW_IFACE_P2P_PEER,
  3391. &iter)))
  3392. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  3393. else
  3394. dbus_connection_send(iface->con, msg, NULL);
  3395. dbus_message_unref(msg);
  3396. }
  3397. /**
  3398. * wpas_dbus_signal_peer_found - Send a peer found signal
  3399. * @wpa_s: %wpa_supplicant network interface data
  3400. * @dev_addr: Peer P2P Device Address
  3401. *
  3402. * Notify listeners about find a p2p peer device found
  3403. */
  3404. void wpas_dbus_signal_peer_device_found(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. "DeviceFound", FALSE);
  3410. wpas_dbus_signal_peer(wpa_s, dev_addr,
  3411. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3412. "DeviceFoundProperties", TRUE);
  3413. }
  3414. /**
  3415. * wpas_dbus_signal_peer_lost - Send a peer lost signal
  3416. * @wpa_s: %wpa_supplicant network interface data
  3417. * @dev_addr: Peer P2P Device Address
  3418. *
  3419. * Notify listeners about lost a p2p peer device
  3420. */
  3421. void wpas_dbus_signal_peer_device_lost(struct wpa_supplicant *wpa_s,
  3422. const u8 *dev_addr)
  3423. {
  3424. wpas_dbus_signal_peer(wpa_s, dev_addr,
  3425. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3426. "DeviceLost", FALSE);
  3427. }
  3428. /**
  3429. * wpas_dbus_register_peer - Register a discovered peer object with dbus
  3430. * @wpa_s: wpa_supplicant interface structure
  3431. * @dev_addr: P2P Device Address of the peer
  3432. * Returns: 0 on success, -1 on failure
  3433. *
  3434. * Registers network representing object with dbus
  3435. */
  3436. int wpas_dbus_register_peer(struct wpa_supplicant *wpa_s, const u8 *dev_addr)
  3437. {
  3438. struct wpas_dbus_priv *ctrl_iface;
  3439. struct wpa_dbus_object_desc *obj_desc;
  3440. struct peer_handler_args *arg;
  3441. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3442. /* Do nothing if the control interface is not turned on */
  3443. if (wpa_s == NULL || wpa_s->global == NULL)
  3444. return 0;
  3445. ctrl_iface = wpa_s->global->dbus;
  3446. if (ctrl_iface == NULL)
  3447. return 0;
  3448. wpa_s = wpa_s->parent->parent;
  3449. if (!wpa_s->dbus_new_path)
  3450. return 0;
  3451. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3452. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  3453. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  3454. wpa_printf(MSG_INFO, "dbus: Register peer object '%s'",
  3455. peer_obj_path);
  3456. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  3457. if (!obj_desc) {
  3458. wpa_printf(MSG_ERROR,
  3459. "Not enough memory to create object description");
  3460. goto err;
  3461. }
  3462. /* allocate memory for handlers arguments */
  3463. arg = os_zalloc(sizeof(struct peer_handler_args));
  3464. if (!arg) {
  3465. wpa_printf(MSG_ERROR,
  3466. "Not enough memory to create arguments for method");
  3467. goto err;
  3468. }
  3469. arg->wpa_s = wpa_s;
  3470. os_memcpy(arg->p2p_device_addr, dev_addr, ETH_ALEN);
  3471. wpas_dbus_register(obj_desc, arg, wpa_dbus_free,
  3472. NULL,
  3473. wpas_dbus_p2p_peer_properties,
  3474. wpas_dbus_p2p_peer_signals);
  3475. if (wpa_dbus_register_object_per_iface(ctrl_iface, peer_obj_path,
  3476. wpa_s->ifname, obj_desc))
  3477. goto err;
  3478. return 0;
  3479. err:
  3480. free_dbus_object_desc(obj_desc);
  3481. return -1;
  3482. }
  3483. /**
  3484. * wpas_dbus_unregister_peer - Unregister a peer object with dbus
  3485. * @wpa_s: wpa_supplicant interface structure
  3486. * @dev_addr: p2p device addr
  3487. * Returns: 0 on success, -1 on failure
  3488. *
  3489. * Registers network representing object with dbus
  3490. */
  3491. int wpas_dbus_unregister_peer(struct wpa_supplicant *wpa_s,
  3492. const u8 *dev_addr)
  3493. {
  3494. struct wpas_dbus_priv *ctrl_iface;
  3495. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3496. int ret;
  3497. /* Do nothing if the control interface is not turned on */
  3498. if (wpa_s == NULL || wpa_s->global == NULL)
  3499. return 0;
  3500. wpa_s = wpa_s->parent->parent;
  3501. if (!wpa_s->dbus_new_path)
  3502. return 0;
  3503. ctrl_iface = wpa_s->global->dbus;
  3504. if (ctrl_iface == NULL)
  3505. return 0;
  3506. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3507. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  3508. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  3509. wpa_printf(MSG_INFO, "dbus: Unregister peer object '%s'",
  3510. peer_obj_path);
  3511. ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, peer_obj_path);
  3512. return ret;
  3513. }
  3514. /**
  3515. * wpas_dbus_signal_p2p_find_stopped - Send P2P Find stopped signal
  3516. * @wpa_s: %wpa_supplicant network interface data
  3517. *
  3518. * Notify listeners about P2P Find stopped
  3519. */
  3520. void wpas_dbus_signal_p2p_find_stopped(struct wpa_supplicant *wpa_s)
  3521. {
  3522. struct wpas_dbus_priv *iface;
  3523. DBusMessage *msg;
  3524. iface = wpa_s->global->dbus;
  3525. /* Do nothing if the control interface is not turned on */
  3526. if (iface == NULL || !wpa_s->dbus_new_path)
  3527. return;
  3528. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  3529. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  3530. "FindStopped");
  3531. if (msg == NULL)
  3532. return;
  3533. dbus_connection_send(iface->con, msg, NULL);
  3534. dbus_message_unref(msg);
  3535. }
  3536. /**
  3537. * wpas_dbus_signal_peer_groups_changed - Send peer group change property signal
  3538. * @wpa_s: %wpa_supplicant network interface data
  3539. * @dev_addr: P2P Device Address
  3540. *
  3541. * Notify listeners about peer Groups property changes.
  3542. */
  3543. void wpas_dbus_signal_peer_groups_changed(struct wpa_supplicant *wpa_s,
  3544. const u8 *dev_addr)
  3545. {
  3546. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3547. if (wpa_s->p2p_mgmt)
  3548. wpa_s = wpa_s->parent;
  3549. if (!wpa_s->dbus_new_path)
  3550. return;
  3551. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3552. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  3553. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  3554. wpa_dbus_mark_property_changed(wpa_s->global->dbus, peer_obj_path,
  3555. WPAS_DBUS_NEW_IFACE_P2P_PEER, "Groups");
  3556. }
  3557. static const struct wpa_dbus_property_desc wpas_dbus_p2p_group_properties[] = {
  3558. { "Members", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ao",
  3559. wpas_dbus_getter_p2p_group_members,
  3560. NULL,
  3561. NULL
  3562. },
  3563. { "Group", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "o",
  3564. wpas_dbus_getter_p2p_group,
  3565. NULL,
  3566. NULL
  3567. },
  3568. { "Role", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "s",
  3569. wpas_dbus_getter_p2p_role,
  3570. NULL,
  3571. NULL
  3572. },
  3573. { "SSID", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
  3574. wpas_dbus_getter_p2p_group_ssid,
  3575. NULL,
  3576. NULL
  3577. },
  3578. { "BSSID", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
  3579. wpas_dbus_getter_p2p_group_bssid,
  3580. NULL,
  3581. NULL
  3582. },
  3583. { "Frequency", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "q",
  3584. wpas_dbus_getter_p2p_group_frequency,
  3585. NULL,
  3586. NULL
  3587. },
  3588. { "Passphrase", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "s",
  3589. wpas_dbus_getter_p2p_group_passphrase,
  3590. NULL,
  3591. NULL
  3592. },
  3593. { "PSK", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
  3594. wpas_dbus_getter_p2p_group_psk,
  3595. NULL,
  3596. NULL
  3597. },
  3598. { "WPSVendorExtensions", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "aay",
  3599. wpas_dbus_getter_p2p_group_vendor_ext,
  3600. wpas_dbus_setter_p2p_group_vendor_ext,
  3601. NULL
  3602. },
  3603. { NULL, NULL, NULL, NULL, NULL, NULL }
  3604. };
  3605. static const struct wpa_dbus_signal_desc wpas_dbus_p2p_group_signals[] = {
  3606. { "PeerJoined", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
  3607. {
  3608. { "peer", "o", ARG_OUT },
  3609. END_ARGS
  3610. }
  3611. },
  3612. { "PeerDisconnected", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
  3613. {
  3614. { "peer", "o", ARG_OUT },
  3615. END_ARGS
  3616. }
  3617. },
  3618. { NULL, NULL, { END_ARGS } }
  3619. };
  3620. /**
  3621. * wpas_dbus_register_p2p_group - Register a p2p group object with dbus
  3622. * @wpa_s: wpa_supplicant interface structure
  3623. * @ssid: SSID struct
  3624. * Returns: 0 on success, -1 on failure
  3625. *
  3626. * Registers p2p group representing object with dbus
  3627. */
  3628. void wpas_dbus_register_p2p_group(struct wpa_supplicant *wpa_s,
  3629. struct wpa_ssid *ssid)
  3630. {
  3631. struct wpas_dbus_priv *ctrl_iface;
  3632. struct wpa_dbus_object_desc *obj_desc;
  3633. char group_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3634. /* Do nothing if the control interface is not turned on */
  3635. if (wpa_s == NULL || wpa_s->global == NULL)
  3636. return;
  3637. ctrl_iface = wpa_s->global->dbus;
  3638. if (ctrl_iface == NULL)
  3639. return;
  3640. if (wpa_s->dbus_groupobj_path) {
  3641. wpa_printf(MSG_INFO, "%s: Group object '%s' already exists",
  3642. __func__, wpa_s->dbus_groupobj_path);
  3643. return;
  3644. }
  3645. if (wpas_dbus_get_group_obj_path(wpa_s, ssid, group_obj_path) < 0)
  3646. return;
  3647. wpa_s->dbus_groupobj_path = os_strdup(group_obj_path);
  3648. if (wpa_s->dbus_groupobj_path == NULL)
  3649. return;
  3650. wpa_printf(MSG_INFO, "dbus: Register group object '%s'",
  3651. group_obj_path);
  3652. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  3653. if (!obj_desc) {
  3654. wpa_printf(MSG_ERROR,
  3655. "Not enough memory to create object description");
  3656. goto err;
  3657. }
  3658. wpas_dbus_register(obj_desc, wpa_s, NULL, NULL,
  3659. wpas_dbus_p2p_group_properties,
  3660. wpas_dbus_p2p_group_signals);
  3661. if (wpa_dbus_register_object_per_iface(ctrl_iface, group_obj_path,
  3662. wpa_s->ifname, obj_desc))
  3663. goto err;
  3664. return;
  3665. err:
  3666. if (wpa_s->dbus_groupobj_path) {
  3667. os_free(wpa_s->dbus_groupobj_path);
  3668. wpa_s->dbus_groupobj_path = NULL;
  3669. }
  3670. free_dbus_object_desc(obj_desc);
  3671. }
  3672. /**
  3673. * wpas_dbus_unregister_p2p_group - Unregister a p2p group object from dbus
  3674. * @wpa_s: wpa_supplicant interface structure
  3675. * @ssid: network name of the p2p group started
  3676. */
  3677. void wpas_dbus_unregister_p2p_group(struct wpa_supplicant *wpa_s,
  3678. const struct wpa_ssid *ssid)
  3679. {
  3680. struct wpas_dbus_priv *ctrl_iface;
  3681. /* Do nothing if the control interface is not turned on */
  3682. if (wpa_s == NULL || wpa_s->global == NULL)
  3683. return;
  3684. if (wpa_s->p2p_mgmt)
  3685. wpa_s = wpa_s->parent;
  3686. ctrl_iface = wpa_s->global->dbus;
  3687. if (ctrl_iface == NULL)
  3688. return;
  3689. if (!wpa_s->dbus_groupobj_path) {
  3690. wpa_printf(MSG_DEBUG,
  3691. "%s: Group object '%s' already unregistered",
  3692. __func__, wpa_s->dbus_groupobj_path);
  3693. return;
  3694. }
  3695. peer_groups_changed(wpa_s);
  3696. wpa_printf(MSG_DEBUG, "dbus: Unregister group object '%s'",
  3697. wpa_s->dbus_groupobj_path);
  3698. wpa_dbus_unregister_object_per_iface(ctrl_iface,
  3699. wpa_s->dbus_groupobj_path);
  3700. os_free(wpa_s->dbus_groupobj_path);
  3701. wpa_s->dbus_groupobj_path = NULL;
  3702. }
  3703. static const struct wpa_dbus_property_desc
  3704. wpas_dbus_persistent_group_properties[] = {
  3705. { "Properties", WPAS_DBUS_NEW_IFACE_PERSISTENT_GROUP, "a{sv}",
  3706. wpas_dbus_getter_persistent_group_properties,
  3707. wpas_dbus_setter_persistent_group_properties,
  3708. NULL
  3709. },
  3710. { NULL, NULL, NULL, NULL, NULL, NULL }
  3711. };
  3712. /* No signals intended for persistent group objects */
  3713. /**
  3714. * wpas_dbus_register_persistent_group - Register a configured(saved)
  3715. * persistent group with dbus
  3716. * @wpa_s: wpa_supplicant interface structure
  3717. * @ssid: persistent group (still represented as a network within wpa)
  3718. * configuration data
  3719. * Returns: 0 on success, -1 on failure
  3720. *
  3721. * Registers a persistent group representing object with dbus.
  3722. */
  3723. int wpas_dbus_register_persistent_group(struct wpa_supplicant *wpa_s,
  3724. struct wpa_ssid *ssid)
  3725. {
  3726. struct wpas_dbus_priv *ctrl_iface;
  3727. struct wpa_dbus_object_desc *obj_desc;
  3728. struct network_handler_args *arg;
  3729. char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3730. /* Do nothing if the control interface is not turned on */
  3731. if (wpa_s == NULL || wpa_s->global == NULL)
  3732. return 0;
  3733. wpa_s = wpa_s->parent->parent;
  3734. if (!wpa_s->dbus_new_path)
  3735. return 0;
  3736. /* Make sure ssid is a persistent group */
  3737. if (ssid->disabled != 2 && !ssid->p2p_persistent_group)
  3738. return -1; /* should we return w/o complaining? */
  3739. if (wpa_s->p2p_mgmt)
  3740. wpa_s = wpa_s->parent;
  3741. ctrl_iface = wpa_s->global->dbus;
  3742. if (ctrl_iface == NULL)
  3743. return 0;
  3744. /*
  3745. * Intentionally not coming up with different numbering scheme
  3746. * for persistent groups.
  3747. */
  3748. os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3749. "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
  3750. wpa_s->dbus_new_path, ssid->id);
  3751. wpa_printf(MSG_DEBUG, "dbus: Register persistent group object '%s'",
  3752. pgrp_obj_path);
  3753. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  3754. if (!obj_desc) {
  3755. wpa_printf(MSG_ERROR,
  3756. "dbus: Not enough memory to create object description");
  3757. goto err;
  3758. }
  3759. /*
  3760. * Reusing the same context structure as that for networks
  3761. * since these are represented using same data structure.
  3762. */
  3763. /* allocate memory for handlers arguments */
  3764. arg = os_zalloc(sizeof(struct network_handler_args));
  3765. if (!arg) {
  3766. wpa_printf(MSG_ERROR,
  3767. "dbus: Not enough memory to create arguments for method");
  3768. goto err;
  3769. }
  3770. arg->wpa_s = wpa_s;
  3771. arg->ssid = ssid;
  3772. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  3773. wpas_dbus_persistent_group_properties,
  3774. NULL);
  3775. if (wpa_dbus_register_object_per_iface(ctrl_iface, pgrp_obj_path,
  3776. wpa_s->ifname, obj_desc))
  3777. goto err;
  3778. wpas_dbus_signal_persistent_group_added(wpa_s, ssid->id);
  3779. return 0;
  3780. err:
  3781. free_dbus_object_desc(obj_desc);
  3782. return -1;
  3783. }
  3784. /**
  3785. * wpas_dbus_unregister_persistent_group - Unregister a persistent_group
  3786. * from dbus
  3787. * @wpa_s: wpa_supplicant interface structure
  3788. * @nid: network id
  3789. * Returns: 0 on success, -1 on failure
  3790. *
  3791. * Unregisters persistent group representing object from dbus
  3792. *
  3793. * NOTE: There is a slight issue with the semantics here. While the
  3794. * implementation simply means the persistent group is unloaded from memory,
  3795. * it should not get interpreted as the group is actually being erased/removed
  3796. * from persistent storage as well.
  3797. */
  3798. int wpas_dbus_unregister_persistent_group(struct wpa_supplicant *wpa_s,
  3799. int nid)
  3800. {
  3801. struct wpas_dbus_priv *ctrl_iface;
  3802. char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3803. int ret;
  3804. /* Do nothing if the control interface is not turned on */
  3805. if (wpa_s == NULL || wpa_s->global == NULL)
  3806. return 0;
  3807. wpa_s = wpa_s->parent->parent;
  3808. ctrl_iface = wpa_s->global->dbus;
  3809. if (ctrl_iface == NULL || !wpa_s->dbus_new_path)
  3810. return 0;
  3811. os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3812. "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
  3813. wpa_s->dbus_new_path, nid);
  3814. wpa_printf(MSG_DEBUG, "dbus: Unregister persistent group object '%s'",
  3815. pgrp_obj_path);
  3816. ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, pgrp_obj_path);
  3817. if (!ret)
  3818. wpas_dbus_signal_persistent_group_removed(wpa_s, nid);
  3819. return ret;
  3820. }
  3821. #endif /* CONFIG_P2P */