dbus_new.c 99 KB

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