123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999 |
- /*
- * WPA Supplicant / dbus-based control interface
- * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
- * Copyright (c) 2009-2010, Witold Sowa <witold.sowa@gmail.com>
- * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
- *
- * This software may be distributed under the terms of the BSD license.
- * See README for more details.
- */
- #include "includes.h"
- #include "common.h"
- #include "common/ieee802_11_defs.h"
- #include "wps/wps.h"
- #include "../config.h"
- #include "../wpa_supplicant_i.h"
- #include "../bss.h"
- #include "../wpas_glue.h"
- #include "dbus_new_helpers.h"
- #include "dbus_dict_helpers.h"
- #include "dbus_new.h"
- #include "dbus_new_handlers.h"
- #include "dbus_common_i.h"
- #include "dbus_new_handlers_p2p.h"
- #include "p2p/p2p.h"
- #include "../p2p_supplicant.h"
- #ifdef CONFIG_AP /* until needed by something else */
- /*
- * NameOwnerChanged handling
- *
- * Some services we provide allow an application to register for
- * a signal that it needs. While it can also unregister, we must
- * be prepared for the case where the application simply crashes
- * and thus doesn't clean up properly. The way to handle this in
- * DBus is to register for the NameOwnerChanged signal which will
- * signal an owner change to NULL if the peer closes the socket
- * for whatever reason.
- *
- * Handle this signal via a filter function whenever necessary.
- * The code below also handles refcounting in case in the future
- * there will be multiple instances of this subscription scheme.
- */
- static const char wpas_dbus_noc_filter_str[] =
- "interface=org.freedesktop.DBus,member=NameOwnerChanged";
- static DBusHandlerResult noc_filter(DBusConnection *conn,
- DBusMessage *message, void *data)
- {
- struct wpas_dbus_priv *priv = data;
- if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_SIGNAL)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- if (dbus_message_is_signal(message, DBUS_INTERFACE_DBUS,
- "NameOwnerChanged")) {
- const char *name;
- const char *prev_owner;
- const char *new_owner;
- DBusError derr;
- struct wpa_supplicant *wpa_s;
- dbus_error_init(&derr);
- if (!dbus_message_get_args(message, &derr,
- DBUS_TYPE_STRING, &name,
- DBUS_TYPE_STRING, &prev_owner,
- DBUS_TYPE_STRING, &new_owner,
- DBUS_TYPE_INVALID)) {
- /* Ignore this error */
- dbus_error_free(&derr);
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
- for (wpa_s = priv->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
- if (wpa_s->preq_notify_peer != NULL &&
- os_strcmp(name, wpa_s->preq_notify_peer) == 0 &&
- (new_owner == NULL || os_strlen(new_owner) == 0)) {
- /* probe request owner disconnected */
- os_free(wpa_s->preq_notify_peer);
- wpa_s->preq_notify_peer = NULL;
- wpas_dbus_unsubscribe_noc(priv);
- }
- }
- }
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
- void wpas_dbus_subscribe_noc(struct wpas_dbus_priv *priv)
- {
- priv->dbus_noc_refcnt++;
- if (priv->dbus_noc_refcnt > 1)
- return;
- if (!dbus_connection_add_filter(priv->con, noc_filter, priv, NULL)) {
- wpa_printf(MSG_ERROR, "dbus: failed to add filter");
- return;
- }
- dbus_bus_add_match(priv->con, wpas_dbus_noc_filter_str, NULL);
- }
- void wpas_dbus_unsubscribe_noc(struct wpas_dbus_priv *priv)
- {
- priv->dbus_noc_refcnt--;
- if (priv->dbus_noc_refcnt > 0)
- return;
- dbus_bus_remove_match(priv->con, wpas_dbus_noc_filter_str, NULL);
- dbus_connection_remove_filter(priv->con, noc_filter, priv);
- }
- #endif /* CONFIG_AP */
- /**
- * wpas_dbus_signal_interface - Send a interface related event signal
- * @wpa_s: %wpa_supplicant network interface data
- * @sig_name: signal name - InterfaceAdded or InterfaceRemoved
- * @properties: Whether to add second argument with object properties
- *
- * Notify listeners about event related with interface
- */
- static void wpas_dbus_signal_interface(struct wpa_supplicant *wpa_s,
- const char *sig_name, int properties)
- {
- struct wpas_dbus_priv *iface;
- DBusMessage *msg;
- DBusMessageIter iter;
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL || !wpa_s->dbus_new_path)
- return;
- msg = dbus_message_new_signal(WPAS_DBUS_NEW_PATH,
- WPAS_DBUS_NEW_INTERFACE, sig_name);
- if (msg == NULL)
- return;
- dbus_message_iter_init_append(msg, &iter);
- if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
- &wpa_s->dbus_new_path) ||
- (properties &&
- !wpa_dbus_get_object_properties(
- iface, wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_INTERFACE, &iter)))
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- else
- dbus_connection_send(iface->con, msg, NULL);
- dbus_message_unref(msg);
- }
- /**
- * wpas_dbus_signal_interface_added - Send a interface created signal
- * @wpa_s: %wpa_supplicant network interface data
- *
- * Notify listeners about creating new interface
- */
- static void wpas_dbus_signal_interface_added(struct wpa_supplicant *wpa_s)
- {
- wpas_dbus_signal_interface(wpa_s, "InterfaceAdded", TRUE);
- }
- /**
- * wpas_dbus_signal_interface_removed - Send a interface removed signal
- * @wpa_s: %wpa_supplicant network interface data
- *
- * Notify listeners about removing interface
- */
- static void wpas_dbus_signal_interface_removed(struct wpa_supplicant *wpa_s)
- {
- wpas_dbus_signal_interface(wpa_s, "InterfaceRemoved", FALSE);
- }
- /**
- * wpas_dbus_signal_scan_done - send scan done signal
- * @wpa_s: %wpa_supplicant network interface data
- * @success: indicates if scanning succeed or failed
- *
- * Notify listeners about finishing a scan
- */
- void wpas_dbus_signal_scan_done(struct wpa_supplicant *wpa_s, int success)
- {
- struct wpas_dbus_priv *iface;
- DBusMessage *msg;
- dbus_bool_t succ;
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL || !wpa_s->dbus_new_path)
- return;
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_INTERFACE,
- "ScanDone");
- if (msg == NULL)
- return;
- succ = success ? TRUE : FALSE;
- if (dbus_message_append_args(msg, DBUS_TYPE_BOOLEAN, &succ,
- DBUS_TYPE_INVALID))
- dbus_connection_send(iface->con, msg, NULL);
- else
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- dbus_message_unref(msg);
- }
- /**
- * wpas_dbus_signal_bss - Send a BSS related event signal
- * @wpa_s: %wpa_supplicant network interface data
- * @bss_obj_path: BSS object path
- * @sig_name: signal name - BSSAdded or BSSRemoved
- * @properties: Whether to add second argument with object properties
- *
- * Notify listeners about event related with BSS
- */
- static void wpas_dbus_signal_bss(struct wpa_supplicant *wpa_s,
- const char *bss_obj_path,
- const char *sig_name, int properties)
- {
- struct wpas_dbus_priv *iface;
- DBusMessage *msg;
- DBusMessageIter iter;
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL || !wpa_s->dbus_new_path)
- return;
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_INTERFACE,
- sig_name);
- if (msg == NULL)
- return;
- dbus_message_iter_init_append(msg, &iter);
- if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
- &bss_obj_path) ||
- (properties &&
- !wpa_dbus_get_object_properties(iface, bss_obj_path,
- WPAS_DBUS_NEW_IFACE_BSS,
- &iter)))
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- else
- dbus_connection_send(iface->con, msg, NULL);
- dbus_message_unref(msg);
- }
- /**
- * wpas_dbus_signal_bss_added - Send a BSS added signal
- * @wpa_s: %wpa_supplicant network interface data
- * @bss_obj_path: new BSS object path
- *
- * Notify listeners about adding new BSS
- */
- static void wpas_dbus_signal_bss_added(struct wpa_supplicant *wpa_s,
- const char *bss_obj_path)
- {
- wpas_dbus_signal_bss(wpa_s, bss_obj_path, "BSSAdded", TRUE);
- }
- /**
- * wpas_dbus_signal_bss_removed - Send a BSS removed signal
- * @wpa_s: %wpa_supplicant network interface data
- * @bss_obj_path: BSS object path
- *
- * Notify listeners about removing BSS
- */
- static void wpas_dbus_signal_bss_removed(struct wpa_supplicant *wpa_s,
- const char *bss_obj_path)
- {
- wpas_dbus_signal_bss(wpa_s, bss_obj_path, "BSSRemoved", FALSE);
- }
- /**
- * wpas_dbus_signal_blob - Send a blob related event signal
- * @wpa_s: %wpa_supplicant network interface data
- * @name: blob name
- * @sig_name: signal name - BlobAdded or BlobRemoved
- *
- * Notify listeners about event related with blob
- */
- static void wpas_dbus_signal_blob(struct wpa_supplicant *wpa_s,
- const char *name, const char *sig_name)
- {
- struct wpas_dbus_priv *iface;
- DBusMessage *msg;
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL || !wpa_s->dbus_new_path)
- return;
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_INTERFACE,
- sig_name);
- if (msg == NULL)
- return;
- if (dbus_message_append_args(msg, DBUS_TYPE_STRING, &name,
- DBUS_TYPE_INVALID))
- dbus_connection_send(iface->con, msg, NULL);
- else
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- dbus_message_unref(msg);
- }
- /**
- * wpas_dbus_signal_blob_added - Send a blob added signal
- * @wpa_s: %wpa_supplicant network interface data
- * @name: blob name
- *
- * Notify listeners about adding a new blob
- */
- void wpas_dbus_signal_blob_added(struct wpa_supplicant *wpa_s,
- const char *name)
- {
- wpas_dbus_signal_blob(wpa_s, name, "BlobAdded");
- }
- /**
- * wpas_dbus_signal_blob_removed - Send a blob removed signal
- * @wpa_s: %wpa_supplicant network interface data
- * @name: blob name
- *
- * Notify listeners about removing blob
- */
- void wpas_dbus_signal_blob_removed(struct wpa_supplicant *wpa_s,
- const char *name)
- {
- wpas_dbus_signal_blob(wpa_s, name, "BlobRemoved");
- }
- /**
- * wpas_dbus_signal_network - Send a network related event signal
- * @wpa_s: %wpa_supplicant network interface data
- * @id: new network id
- * @sig_name: signal name - NetworkAdded, NetworkRemoved or NetworkSelected
- * @properties: determines if add second argument with object properties
- *
- * Notify listeners about event related with configured network
- */
- static void wpas_dbus_signal_network(struct wpa_supplicant *wpa_s,
- int id, const char *sig_name,
- int properties)
- {
- struct wpas_dbus_priv *iface;
- DBusMessage *msg;
- DBusMessageIter iter;
- char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL || !wpa_s->dbus_new_path)
- return;
- os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
- "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
- wpa_s->dbus_new_path, id);
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_INTERFACE,
- sig_name);
- if (msg == NULL)
- return;
- dbus_message_iter_init_append(msg, &iter);
- path = net_obj_path;
- if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
- &path) ||
- (properties &&
- !wpa_dbus_get_object_properties(
- iface, net_obj_path, WPAS_DBUS_NEW_IFACE_NETWORK,
- &iter)))
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- else
- dbus_connection_send(iface->con, msg, NULL);
- dbus_message_unref(msg);
- }
- /**
- * wpas_dbus_signal_network_added - Send a network added signal
- * @wpa_s: %wpa_supplicant network interface data
- * @id: new network id
- *
- * Notify listeners about adding new network
- */
- static void wpas_dbus_signal_network_added(struct wpa_supplicant *wpa_s,
- int id)
- {
- wpas_dbus_signal_network(wpa_s, id, "NetworkAdded", TRUE);
- }
- /**
- * wpas_dbus_signal_network_removed - Send a network removed signal
- * @wpa_s: %wpa_supplicant network interface data
- * @id: network id
- *
- * Notify listeners about removing a network
- */
- static void wpas_dbus_signal_network_removed(struct wpa_supplicant *wpa_s,
- int id)
- {
- wpas_dbus_signal_network(wpa_s, id, "NetworkRemoved", FALSE);
- }
- /**
- * wpas_dbus_signal_network_selected - Send a network selected signal
- * @wpa_s: %wpa_supplicant network interface data
- * @id: network id
- *
- * Notify listeners about selecting a network
- */
- void wpas_dbus_signal_network_selected(struct wpa_supplicant *wpa_s, int id)
- {
- wpas_dbus_signal_network(wpa_s, id, "NetworkSelected", FALSE);
- }
- /**
- * wpas_dbus_signal_network_request - Indicate that additional information
- * (EAP password, etc.) is required to complete the association to this SSID
- * @wpa_s: %wpa_supplicant network interface data
- * @rtype: The specific additional information required
- * @default_text: Optional description of required information
- *
- * Request additional information or passwords to complete an association
- * request.
- */
- void wpas_dbus_signal_network_request(struct wpa_supplicant *wpa_s,
- struct wpa_ssid *ssid,
- enum wpa_ctrl_req_type rtype,
- const char *default_txt)
- {
- struct wpas_dbus_priv *iface;
- DBusMessage *msg;
- DBusMessageIter iter;
- char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
- const char *field, *txt = NULL, *net_ptr;
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL || !wpa_s->dbus_new_path)
- return;
- field = wpa_supplicant_ctrl_req_to_string(rtype, default_txt, &txt);
- if (field == NULL)
- return;
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_INTERFACE,
- "NetworkRequest");
- if (msg == NULL)
- return;
- os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
- "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
- wpa_s->dbus_new_path, ssid->id);
- net_ptr = &net_obj_path[0];
- dbus_message_iter_init_append(msg, &iter);
- if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
- &net_ptr) ||
- !dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &field) ||
- !dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &txt))
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- else
- dbus_connection_send(iface->con, msg, NULL);
- dbus_message_unref(msg);
- }
- /**
- * wpas_dbus_signal_network_enabled_changed - Signals Enabled property changes
- * @wpa_s: %wpa_supplicant network interface data
- * @ssid: configured network which Enabled property has changed
- *
- * Sends PropertyChanged signals containing new value of Enabled property
- * for specified network
- */
- void wpas_dbus_signal_network_enabled_changed(struct wpa_supplicant *wpa_s,
- struct wpa_ssid *ssid)
- {
- char path[WPAS_DBUS_OBJECT_PATH_MAX];
- if (!wpa_s->dbus_new_path)
- return;
- os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
- "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
- wpa_s->dbus_new_path, ssid->id);
- wpa_dbus_mark_property_changed(wpa_s->global->dbus, path,
- WPAS_DBUS_NEW_IFACE_NETWORK, "Enabled");
- }
- #ifdef CONFIG_WPS
- /**
- * wpas_dbus_signal_wps_event_pbc_overlap - Signals PBC overlap WPS event
- * @wpa_s: %wpa_supplicant network interface data
- *
- * Sends Event dbus signal with name "pbc-overlap" and empty dict as arguments
- */
- void wpas_dbus_signal_wps_event_pbc_overlap(struct wpa_supplicant *wpa_s)
- {
- DBusMessage *msg;
- DBusMessageIter iter, dict_iter;
- struct wpas_dbus_priv *iface;
- char *key = "pbc-overlap";
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL || !wpa_s->dbus_new_path)
- return;
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_WPS, "Event");
- if (msg == NULL)
- return;
- dbus_message_iter_init_append(msg, &iter);
- if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
- !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
- !wpa_dbus_dict_close_write(&iter, &dict_iter))
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- else
- dbus_connection_send(iface->con, msg, NULL);
- dbus_message_unref(msg);
- }
- /**
- * wpas_dbus_signal_wps_event_success - Signals Success WPS event
- * @wpa_s: %wpa_supplicant network interface data
- *
- * Sends Event dbus signal with name "success" and empty dict as arguments
- */
- void wpas_dbus_signal_wps_event_success(struct wpa_supplicant *wpa_s)
- {
- DBusMessage *msg;
- DBusMessageIter iter, dict_iter;
- struct wpas_dbus_priv *iface;
- char *key = "success";
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL || !wpa_s->dbus_new_path)
- return;
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_WPS, "Event");
- if (msg == NULL)
- return;
- dbus_message_iter_init_append(msg, &iter);
- if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
- !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
- !wpa_dbus_dict_close_write(&iter, &dict_iter))
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- else
- dbus_connection_send(iface->con, msg, NULL);
- dbus_message_unref(msg);
- }
- /**
- * wpas_dbus_signal_wps_event_fail - Signals Fail WPS event
- * @wpa_s: %wpa_supplicant network interface data
- * @fail: WPS failure information
- *
- * Sends Event dbus signal with name "fail" and dictionary containing
- * "msg field with fail message number (int32) as arguments
- */
- void wpas_dbus_signal_wps_event_fail(struct wpa_supplicant *wpa_s,
- struct wps_event_fail *fail)
- {
- DBusMessage *msg;
- DBusMessageIter iter, dict_iter;
- struct wpas_dbus_priv *iface;
- char *key = "fail";
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL || !wpa_s->dbus_new_path)
- return;
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_WPS, "Event");
- if (msg == NULL)
- return;
- dbus_message_iter_init_append(msg, &iter);
- if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
- !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
- !wpa_dbus_dict_append_int32(&dict_iter, "msg", fail->msg) ||
- !wpa_dbus_dict_close_write(&iter, &dict_iter))
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- else
- dbus_connection_send(iface->con, msg, NULL);
- dbus_message_unref(msg);
- }
- /**
- * wpas_dbus_signal_wps_event_m2d - Signals M2D WPS event
- * @wpa_s: %wpa_supplicant network interface data
- * @m2d: M2D event data information
- *
- * Sends Event dbus signal with name "m2d" and dictionary containing
- * fields of wps_event_m2d structure.
- */
- void wpas_dbus_signal_wps_event_m2d(struct wpa_supplicant *wpa_s,
- struct wps_event_m2d *m2d)
- {
- DBusMessage *msg;
- DBusMessageIter iter, dict_iter;
- struct wpas_dbus_priv *iface;
- char *key = "m2d";
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL || !wpa_s->dbus_new_path)
- return;
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_WPS, "Event");
- if (msg == NULL)
- return;
- dbus_message_iter_init_append(msg, &iter);
- if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
- !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
- !wpa_dbus_dict_append_uint16(&dict_iter, "config_methods",
- m2d->config_methods) ||
- !wpa_dbus_dict_append_byte_array(&dict_iter, "manufacturer",
- (const char *) m2d->manufacturer,
- m2d->manufacturer_len) ||
- !wpa_dbus_dict_append_byte_array(&dict_iter, "model_name",
- (const char *) m2d->model_name,
- m2d->model_name_len) ||
- !wpa_dbus_dict_append_byte_array(&dict_iter, "model_number",
- (const char *) m2d->model_number,
- m2d->model_number_len) ||
- !wpa_dbus_dict_append_byte_array(&dict_iter, "serial_number",
- (const char *)
- m2d->serial_number,
- m2d->serial_number_len) ||
- !wpa_dbus_dict_append_byte_array(&dict_iter, "dev_name",
- (const char *) m2d->dev_name,
- m2d->dev_name_len) ||
- !wpa_dbus_dict_append_byte_array(&dict_iter, "primary_dev_type",
- (const char *)
- m2d->primary_dev_type, 8) ||
- !wpa_dbus_dict_append_uint16(&dict_iter, "config_error",
- m2d->config_error) ||
- !wpa_dbus_dict_append_uint16(&dict_iter, "dev_password_id",
- m2d->dev_password_id) ||
- !wpa_dbus_dict_close_write(&iter, &dict_iter))
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- else
- dbus_connection_send(iface->con, msg, NULL);
- dbus_message_unref(msg);
- }
- /**
- * wpas_dbus_signal_wps_cred - Signals new credentials
- * @wpa_s: %wpa_supplicant network interface data
- * @cred: WPS Credential information
- *
- * Sends signal with credentials in directory argument
- */
- void wpas_dbus_signal_wps_cred(struct wpa_supplicant *wpa_s,
- const struct wps_credential *cred)
- {
- DBusMessage *msg;
- DBusMessageIter iter, dict_iter;
- struct wpas_dbus_priv *iface;
- char *auth_type[5]; /* we have five possible authentication types */
- int at_num = 0;
- char *encr_type[3]; /* we have three possible encryption types */
- int et_num = 0;
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL || !wpa_s->dbus_new_path)
- return;
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_WPS,
- "Credentials");
- if (msg == NULL)
- return;
- dbus_message_iter_init_append(msg, &iter);
- if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
- goto nomem;
- if (cred->auth_type & WPS_AUTH_OPEN)
- auth_type[at_num++] = "open";
- if (cred->auth_type & WPS_AUTH_WPAPSK)
- auth_type[at_num++] = "wpa-psk";
- if (cred->auth_type & WPS_AUTH_WPA)
- auth_type[at_num++] = "wpa-eap";
- if (cred->auth_type & WPS_AUTH_WPA2)
- auth_type[at_num++] = "wpa2-eap";
- if (cred->auth_type & WPS_AUTH_WPA2PSK)
- auth_type[at_num++] = "wpa2-psk";
- if (cred->encr_type & WPS_ENCR_NONE)
- encr_type[et_num++] = "none";
- if (cred->encr_type & WPS_ENCR_TKIP)
- encr_type[et_num++] = "tkip";
- if (cred->encr_type & WPS_ENCR_AES)
- encr_type[et_num++] = "aes";
- if ((wpa_s->current_ssid &&
- !wpa_dbus_dict_append_byte_array(
- &dict_iter, "BSSID",
- (const char *) wpa_s->current_ssid->bssid, ETH_ALEN)) ||
- !wpa_dbus_dict_append_byte_array(&dict_iter, "SSID",
- (const char *) cred->ssid,
- cred->ssid_len) ||
- !wpa_dbus_dict_append_string_array(&dict_iter, "AuthType",
- (const char **) auth_type,
- at_num) ||
- !wpa_dbus_dict_append_string_array(&dict_iter, "EncrType",
- (const char **) encr_type,
- et_num) ||
- !wpa_dbus_dict_append_byte_array(&dict_iter, "Key",
- (const char *) cred->key,
- cred->key_len) ||
- !wpa_dbus_dict_append_uint32(&dict_iter, "KeyIndex",
- cred->key_idx) ||
- !wpa_dbus_dict_close_write(&iter, &dict_iter))
- goto nomem;
- dbus_connection_send(iface->con, msg, NULL);
- nomem:
- dbus_message_unref(msg);
- }
- #endif /* CONFIG_WPS */
- void wpas_dbus_signal_certification(struct wpa_supplicant *wpa_s,
- int depth, const char *subject,
- const char *altsubject[],
- int num_altsubject,
- const char *cert_hash,
- const struct wpabuf *cert)
- {
- struct wpas_dbus_priv *iface;
- DBusMessage *msg;
- DBusMessageIter iter, dict_iter;
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL || !wpa_s->dbus_new_path)
- return;
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_INTERFACE,
- "Certification");
- if (msg == NULL)
- return;
- dbus_message_iter_init_append(msg, &iter);
- if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
- !wpa_dbus_dict_append_uint32(&dict_iter, "depth", depth) ||
- !wpa_dbus_dict_append_string(&dict_iter, "subject", subject) ||
- (altsubject && num_altsubject &&
- !wpa_dbus_dict_append_string_array(&dict_iter, "altsubject",
- altsubject, num_altsubject)) ||
- (cert_hash &&
- !wpa_dbus_dict_append_string(&dict_iter, "cert_hash",
- cert_hash)) ||
- (cert &&
- !wpa_dbus_dict_append_byte_array(&dict_iter, "cert",
- wpabuf_head(cert),
- wpabuf_len(cert))) ||
- !wpa_dbus_dict_close_write(&iter, &dict_iter))
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- else
- dbus_connection_send(iface->con, msg, NULL);
- dbus_message_unref(msg);
- }
- void wpas_dbus_signal_eap_status(struct wpa_supplicant *wpa_s,
- const char *status, const char *parameter)
- {
- struct wpas_dbus_priv *iface;
- DBusMessage *msg;
- DBusMessageIter iter;
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL || !wpa_s->dbus_new_path)
- return;
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_INTERFACE,
- "EAP");
- if (msg == NULL)
- return;
- dbus_message_iter_init_append(msg, &iter);
- if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &status) ||
- !dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING,
- ¶meter))
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- else
- dbus_connection_send(iface->con, msg, NULL);
- dbus_message_unref(msg);
- }
- /**
- * wpas_dbus_signal_sta - Send a station related event signal
- * @wpa_s: %wpa_supplicant network interface data
- * @sta: station mac address
- * @sig_name: signal name - StaAuthorized or StaDeauthorized
- *
- * Notify listeners about event related with station
- */
- static void wpas_dbus_signal_sta(struct wpa_supplicant *wpa_s,
- const u8 *sta, const char *sig_name)
- {
- struct wpas_dbus_priv *iface;
- DBusMessage *msg;
- char sta_mac[WPAS_DBUS_OBJECT_PATH_MAX];
- char *dev_mac;
- os_snprintf(sta_mac, WPAS_DBUS_OBJECT_PATH_MAX, MACSTR, MAC2STR(sta));
- dev_mac = sta_mac;
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL || !wpa_s->dbus_new_path)
- return;
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_INTERFACE, sig_name);
- if (msg == NULL)
- return;
- if (dbus_message_append_args(msg, DBUS_TYPE_STRING, &dev_mac,
- DBUS_TYPE_INVALID))
- dbus_connection_send(iface->con, msg, NULL);
- else
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- dbus_message_unref(msg);
- wpa_printf(MSG_DEBUG, "dbus: Station MAC address '%s' '%s'",
- sta_mac, sig_name);
- }
- /**
- * wpas_dbus_signal_sta_authorized - Send a STA authorized signal
- * @wpa_s: %wpa_supplicant network interface data
- * @sta: station mac address
- *
- * Notify listeners a new station has been authorized
- */
- void wpas_dbus_signal_sta_authorized(struct wpa_supplicant *wpa_s,
- const u8 *sta)
- {
- wpas_dbus_signal_sta(wpa_s, sta, "StaAuthorized");
- }
- /**
- * wpas_dbus_signal_sta_deauthorized - Send a STA deauthorized signal
- * @wpa_s: %wpa_supplicant network interface data
- * @sta: station mac address
- *
- * Notify listeners a station has been deauthorized
- */
- void wpas_dbus_signal_sta_deauthorized(struct wpa_supplicant *wpa_s,
- const u8 *sta)
- {
- wpas_dbus_signal_sta(wpa_s, sta, "StaDeauthorized");
- }
- #ifdef CONFIG_P2P
- /**
- * wpas_dbus_signal_p2p_group_removed - Signals P2P group was removed
- * @wpa_s: %wpa_supplicant network interface data
- * @role: role of this device (client or GO)
- * Sends signal with i/f name and role as string arguments
- */
- void wpas_dbus_signal_p2p_group_removed(struct wpa_supplicant *wpa_s,
- const char *role)
- {
- DBusMessage *msg;
- DBusMessageIter iter, dict_iter;
- struct wpas_dbus_priv *iface = wpa_s->global->dbus;
- struct wpa_supplicant *parent;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL)
- return;
- parent = wpa_s->parent;
- if (parent->p2p_mgmt)
- parent = parent->parent;
- if (!wpa_s->dbus_groupobj_path || !wpa_s->dbus_new_path ||
- !parent->dbus_new_path)
- return;
- msg = dbus_message_new_signal(parent->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- "GroupFinished");
- if (msg == NULL)
- return;
- dbus_message_iter_init_append(msg, &iter);
- if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
- !wpa_dbus_dict_append_object_path(&dict_iter,
- "interface_object",
- wpa_s->dbus_new_path) ||
- !wpa_dbus_dict_append_string(&dict_iter, "role", role) ||
- !wpa_dbus_dict_append_object_path(&dict_iter, "group_object",
- wpa_s->dbus_groupobj_path) ||
- !wpa_dbus_dict_close_write(&iter, &dict_iter))
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- else
- dbus_connection_send(iface->con, msg, NULL);
- dbus_message_unref(msg);
- }
- /**
- * wpas_dbus_signal_p2p_provision_discovery - Signals various PD events
- *
- * @dev_addr - who sent the request or responded to our request.
- * @request - Will be 1 if request, 0 for response.
- * @status - valid only in case of response
- * @config_methods - wps config methods
- * @generated_pin - pin to be displayed in case of WPS_CONFIG_DISPLAY method
- *
- * Sends following provision discovery related events:
- * ProvisionDiscoveryRequestDisplayPin
- * ProvisionDiscoveryResponseDisplayPin
- * ProvisionDiscoveryRequestEnterPin
- * ProvisionDiscoveryResponseEnterPin
- * ProvisionDiscoveryPBCRequest
- * ProvisionDiscoveryPBCResponse
- *
- * TODO::
- * ProvisionDiscoveryFailure (timeout case)
- */
- void wpas_dbus_signal_p2p_provision_discovery(struct wpa_supplicant *wpa_s,
- const u8 *dev_addr, int request,
- enum p2p_prov_disc_status status,
- u16 config_methods,
- unsigned int generated_pin)
- {
- DBusMessage *msg;
- DBusMessageIter iter;
- struct wpas_dbus_priv *iface;
- char *_signal;
- int add_pin = 0;
- char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
- int error_ret = 1;
- char pin[9], *p_pin = NULL;
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL)
- return;
- if (wpa_s->p2p_mgmt)
- wpa_s = wpa_s->parent;
- if (!wpa_s->dbus_new_path)
- return;
- if (request || !status) {
- if (config_methods & WPS_CONFIG_DISPLAY)
- _signal = request ?
- "ProvisionDiscoveryRequestDisplayPin" :
- "ProvisionDiscoveryResponseEnterPin";
- else if (config_methods & WPS_CONFIG_KEYPAD)
- _signal = request ?
- "ProvisionDiscoveryRequestEnterPin" :
- "ProvisionDiscoveryResponseDisplayPin";
- else if (config_methods & WPS_CONFIG_PUSHBUTTON)
- _signal = request ? "ProvisionDiscoveryPBCRequest" :
- "ProvisionDiscoveryPBCResponse";
- else
- return; /* Unknown or un-supported method */
- } else {
- /* Explicit check for failure response */
- _signal = "ProvisionDiscoveryFailure";
- }
- add_pin = ((request && (config_methods & WPS_CONFIG_DISPLAY)) ||
- (!request && !status &&
- (config_methods & WPS_CONFIG_KEYPAD)));
- if (add_pin) {
- os_snprintf(pin, sizeof(pin), "%08d", generated_pin);
- p_pin = pin;
- }
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_P2PDEVICE, _signal);
- if (msg == NULL)
- return;
- /* Check if this is a known peer */
- if (!p2p_peer_known(wpa_s->global->p2p, dev_addr))
- goto error;
- os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
- "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
- COMPACT_MACSTR,
- wpa_s->dbus_new_path, MAC2STR(dev_addr));
- path = peer_obj_path;
- dbus_message_iter_init_append(msg, &iter);
- if (!dbus_message_iter_append_basic(&iter,
- DBUS_TYPE_OBJECT_PATH,
- &path))
- goto error;
- if (!request && status)
- /* Attach status to ProvisionDiscoveryFailure */
- error_ret = !dbus_message_iter_append_basic(&iter,
- DBUS_TYPE_INT32,
- &status);
- else
- error_ret = (add_pin &&
- !dbus_message_iter_append_basic(&iter,
- DBUS_TYPE_STRING,
- &p_pin));
- error:
- if (!error_ret)
- dbus_connection_send(iface->con, msg, NULL);
- else
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- dbus_message_unref(msg);
- }
- /**
- * wpas_dbus_signal_p2p_go_neg_req - Signal P2P GO Negotiation Request RX
- * @wpa_s: %wpa_supplicant network interface data
- * @src: Source address of the message triggering this notification
- * @dev_passwd_id: WPS Device Password Id
- * @go_intent: Peer's GO Intent value
- *
- * Sends signal to notify that a peer P2P Device is requesting group owner
- * negotiation with us.
- */
- void wpas_dbus_signal_p2p_go_neg_req(struct wpa_supplicant *wpa_s,
- const u8 *src, u16 dev_passwd_id,
- u8 go_intent)
- {
- DBusMessage *msg;
- DBusMessageIter iter;
- struct wpas_dbus_priv *iface;
- char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL)
- return;
- if (wpa_s->p2p_mgmt)
- wpa_s = wpa_s->parent;
- if (!wpa_s->dbus_new_path)
- return;
- os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
- "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
- wpa_s->dbus_new_path, MAC2STR(src));
- path = peer_obj_path;
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- "GONegotiationRequest");
- if (msg == NULL)
- return;
- dbus_message_iter_init_append(msg, &iter);
- if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
- &path) ||
- !dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT16,
- &dev_passwd_id) ||
- !dbus_message_iter_append_basic(&iter, DBUS_TYPE_BYTE,
- &go_intent))
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- else
- dbus_connection_send(iface->con, msg, NULL);
- dbus_message_unref(msg);
- }
- static int wpas_dbus_get_group_obj_path(struct wpa_supplicant *wpa_s,
- const struct wpa_ssid *ssid,
- char *group_obj_path)
- {
- char group_name[3];
- if (!wpa_s->dbus_new_path ||
- os_memcmp(ssid->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN))
- return -1;
- os_memcpy(group_name, ssid->ssid + P2P_WILDCARD_SSID_LEN, 2);
- group_name[2] = '\0';
- os_snprintf(group_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
- "%s/" WPAS_DBUS_NEW_P2P_GROUPS_PART "/%s",
- wpa_s->dbus_new_path, group_name);
- return 0;
- }
- struct group_changed_data {
- struct wpa_supplicant *wpa_s;
- struct p2p_peer_info *info;
- };
- static int match_group_where_peer_is_client(struct p2p_group *group,
- void *user_data)
- {
- struct group_changed_data *data = user_data;
- const struct p2p_group_config *cfg;
- struct wpa_supplicant *wpa_s_go;
- if (!p2p_group_is_client_connected(group, data->info->p2p_device_addr))
- return 1;
- cfg = p2p_group_get_config(group);
- wpa_s_go = wpas_get_p2p_go_iface(data->wpa_s, cfg->ssid,
- cfg->ssid_len);
- if (wpa_s_go != NULL && wpa_s_go == data->wpa_s) {
- wpas_dbus_signal_peer_groups_changed(
- data->wpa_s->parent, data->info->p2p_device_addr);
- return 0;
- }
- return 1;
- }
- static void signal_peer_groups_changed(struct p2p_peer_info *info,
- void *user_data)
- {
- struct group_changed_data *data = user_data;
- struct wpa_supplicant *wpa_s_go;
- wpa_s_go = wpas_get_p2p_client_iface(data->wpa_s,
- info->p2p_device_addr);
- if (wpa_s_go != NULL && wpa_s_go == data->wpa_s) {
- wpas_dbus_signal_peer_groups_changed(data->wpa_s->parent,
- info->p2p_device_addr);
- return;
- }
- data->info = info;
- p2p_loop_on_all_groups(data->wpa_s->global->p2p,
- match_group_where_peer_is_client, data);
- data->info = NULL;
- }
- static void peer_groups_changed(struct wpa_supplicant *wpa_s)
- {
- struct group_changed_data data;
- os_memset(&data, 0, sizeof(data));
- data.wpa_s = wpa_s;
- p2p_loop_on_known_peers(wpa_s->global->p2p,
- signal_peer_groups_changed, &data);
- }
- /**
- * wpas_dbus_signal_p2p_group_started - Signals P2P group has
- * started. Emitted when a group is successfully started
- * irrespective of the role (client/GO) of the current device
- *
- * @wpa_s: %wpa_supplicant network interface data
- * @ssid: SSID object
- * @client: this device is P2P client
- * @network_id: network id of the group started, use instead of ssid->id
- * to account for persistent groups
- */
- void wpas_dbus_signal_p2p_group_started(struct wpa_supplicant *wpa_s,
- const struct wpa_ssid *ssid,
- int client, int network_id)
- {
- DBusMessage *msg;
- DBusMessageIter iter, dict_iter;
- struct wpas_dbus_priv *iface;
- struct wpa_supplicant *parent;
- parent = wpa_s->parent;
- if (parent->p2p_mgmt)
- parent = parent->parent;
- iface = parent->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL || !parent->dbus_new_path || !wpa_s->dbus_new_path)
- return;
- if (wpa_s->dbus_groupobj_path == NULL)
- return;
- /* New interface has been created for this group */
- msg = dbus_message_new_signal(parent->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- "GroupStarted");
- if (msg == NULL)
- return;
- dbus_message_iter_init_append(msg, &iter);
- /*
- * In case the device supports creating a separate interface the
- * DBus client will need to know the object path for the interface
- * object this group was created on, so include it here.
- */
- if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
- !wpa_dbus_dict_append_object_path(&dict_iter,
- "interface_object",
- wpa_s->dbus_new_path) ||
- !wpa_dbus_dict_append_string(&dict_iter, "role",
- client ? "client" : "GO") ||
- !wpa_dbus_dict_append_object_path(&dict_iter, "group_object",
- wpa_s->dbus_groupobj_path) ||
- !wpa_dbus_dict_close_write(&iter, &dict_iter)) {
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- } else {
- dbus_connection_send(iface->con, msg, NULL);
- if (client)
- peer_groups_changed(wpa_s);
- }
- dbus_message_unref(msg);
- }
- /**
- * wpas_dbus_signal_p2p_go_neg_resp - Emit GONegotiation Success/Failure signal
- * @wpa_s: %wpa_supplicant network interface data
- * @res: Result of the GO Neg Request
- */
- void wpas_dbus_signal_p2p_go_neg_resp(struct wpa_supplicant *wpa_s,
- struct p2p_go_neg_results *res)
- {
- DBusMessage *msg;
- DBusMessageIter iter, dict_iter;
- DBusMessageIter iter_dict_entry, iter_dict_val, iter_dict_array;
- struct wpas_dbus_priv *iface;
- char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
- dbus_int32_t freqs[P2P_MAX_CHANNELS];
- dbus_int32_t *f_array = freqs;
- iface = wpa_s->global->dbus;
- if (wpa_s->p2p_mgmt)
- wpa_s = wpa_s->parent;
- os_memset(freqs, 0, sizeof(freqs));
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL || !wpa_s->dbus_new_path)
- return;
- os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
- "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
- wpa_s->dbus_new_path, MAC2STR(res->peer_device_addr));
- path = peer_obj_path;
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- res->status ? "GONegotiationFailure" :
- "GONegotiationSuccess");
- if (msg == NULL)
- return;
- dbus_message_iter_init_append(msg, &iter);
- if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
- !wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
- path) ||
- !wpa_dbus_dict_append_int32(&dict_iter, "status", res->status))
- goto err;
- if (!res->status) {
- int i = 0;
- int freq_list_num = 0;
- if ((res->role_go &&
- !wpa_dbus_dict_append_string(&dict_iter, "passphrase",
- res->passphrase)) ||
- !wpa_dbus_dict_append_string(&dict_iter, "role_go",
- res->role_go ? "GO" :
- "client") ||
- !wpa_dbus_dict_append_int32(&dict_iter, "frequency",
- res->freq) ||
- !wpa_dbus_dict_append_byte_array(&dict_iter, "ssid",
- (const char *) res->ssid,
- res->ssid_len) ||
- !wpa_dbus_dict_append_byte_array(&dict_iter,
- "peer_device_addr",
- (const char *)
- res->peer_device_addr,
- ETH_ALEN) ||
- !wpa_dbus_dict_append_byte_array(&dict_iter,
- "peer_interface_addr",
- (const char *)
- res->peer_interface_addr,
- ETH_ALEN) ||
- !wpa_dbus_dict_append_string(&dict_iter, "wps_method",
- p2p_wps_method_text(
- res->wps_method)))
- goto err;
- for (i = 0; i < P2P_MAX_CHANNELS; i++) {
- if (res->freq_list[i]) {
- freqs[i] = res->freq_list[i];
- freq_list_num++;
- }
- }
- if (!wpa_dbus_dict_begin_array(&dict_iter,
- "frequency_list",
- DBUS_TYPE_INT32_AS_STRING,
- &iter_dict_entry,
- &iter_dict_val,
- &iter_dict_array) ||
- !dbus_message_iter_append_fixed_array(&iter_dict_array,
- DBUS_TYPE_INT32,
- &f_array,
- freq_list_num) ||
- !wpa_dbus_dict_end_array(&dict_iter,
- &iter_dict_entry,
- &iter_dict_val,
- &iter_dict_array) ||
- !wpa_dbus_dict_append_int32(&dict_iter, "persistent_group",
- res->persistent_group) ||
- !wpa_dbus_dict_append_uint32(&dict_iter,
- "peer_config_timeout",
- res->peer_config_timeout))
- goto err;
- }
- if (!wpa_dbus_dict_close_write(&iter, &dict_iter))
- goto err;
- dbus_connection_send(iface->con, msg, NULL);
- err:
- dbus_message_unref(msg);
- }
- /**
- * wpas_dbus_signal_p2p_invitation_result - Emit InvitationResult signal
- * @wpa_s: %wpa_supplicant network interface data
- * @status: Status of invitation process
- * @bssid: Basic Service Set Identifier
- */
- void wpas_dbus_signal_p2p_invitation_result(struct wpa_supplicant *wpa_s,
- int status, const u8 *bssid)
- {
- DBusMessage *msg;
- DBusMessageIter iter, dict_iter;
- struct wpas_dbus_priv *iface;
- wpa_printf(MSG_DEBUG, "%s", __func__);
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL)
- return;
- if (wpa_s->p2p_mgmt)
- wpa_s = wpa_s->parent;
- if (!wpa_s->dbus_new_path)
- return;
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- "InvitationResult");
- if (msg == NULL)
- return;
- dbus_message_iter_init_append(msg, &iter);
- if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
- !wpa_dbus_dict_append_int32(&dict_iter, "status", status) ||
- (bssid &&
- !wpa_dbus_dict_append_byte_array(&dict_iter, "BSSID",
- (const char *) bssid,
- ETH_ALEN)) ||
- !wpa_dbus_dict_close_write(&iter, &dict_iter))
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- else
- dbus_connection_send(iface->con, msg, NULL);
- dbus_message_unref(msg);
- }
- /**
- *
- * Method to emit a signal for a peer joining the group.
- * The signal will carry path to the group member object
- * constructed using p2p i/f addr used for connecting.
- *
- * @wpa_s: %wpa_supplicant network interface data
- * @peer_addr: P2P Device Address of the peer joining the group
- */
- void wpas_dbus_signal_p2p_peer_joined(struct wpa_supplicant *wpa_s,
- const u8 *peer_addr)
- {
- struct wpas_dbus_priv *iface;
- DBusMessage *msg;
- DBusMessageIter iter;
- char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
- struct wpa_supplicant *parent;
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL)
- return;
- if (!wpa_s->dbus_groupobj_path)
- return;
- parent = wpa_s->parent;
- if (parent->p2p_mgmt)
- parent = parent->parent;
- if (!parent->dbus_new_path)
- return;
- os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
- "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
- COMPACT_MACSTR,
- parent->dbus_new_path, MAC2STR(peer_addr));
- msg = dbus_message_new_signal(wpa_s->dbus_groupobj_path,
- WPAS_DBUS_NEW_IFACE_P2P_GROUP,
- "PeerJoined");
- if (msg == NULL)
- return;
- dbus_message_iter_init_append(msg, &iter);
- path = peer_obj_path;
- if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
- &path)) {
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- } else {
- dbus_connection_send(iface->con, msg, NULL);
- wpas_dbus_signal_peer_groups_changed(parent, peer_addr);
- }
- dbus_message_unref(msg);
- }
- /**
- *
- * Method to emit a signal for a peer disconnecting the group.
- * The signal will carry path to the group member object
- * constructed using the P2P Device Address of the peer.
- *
- * @wpa_s: %wpa_supplicant network interface data
- * @peer_addr: P2P Device Address of the peer joining the group
- */
- void wpas_dbus_signal_p2p_peer_disconnected(struct wpa_supplicant *wpa_s,
- const u8 *peer_addr)
- {
- struct wpas_dbus_priv *iface;
- DBusMessage *msg;
- DBusMessageIter iter;
- char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
- struct wpa_supplicant *parent;
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL)
- return;
- if (!wpa_s->dbus_groupobj_path)
- return;
- parent = wpa_s->parent;
- if (parent->p2p_mgmt)
- parent = parent->parent;
- if (!parent->dbus_new_path)
- return;
- os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
- "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
- COMPACT_MACSTR,
- parent->dbus_new_path, MAC2STR(peer_addr));
- msg = dbus_message_new_signal(wpa_s->dbus_groupobj_path,
- WPAS_DBUS_NEW_IFACE_P2P_GROUP,
- "PeerDisconnected");
- if (msg == NULL)
- return;
- dbus_message_iter_init_append(msg, &iter);
- path = peer_obj_path;
- if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
- &path)) {
- wpa_printf(MSG_ERROR,
- "dbus: Failed to construct PeerDisconnected signal");
- } else {
- dbus_connection_send(iface->con, msg, NULL);
- wpas_dbus_signal_peer_groups_changed(parent, peer_addr);
- }
- dbus_message_unref(msg);
- }
- /**
- *
- * Method to emit a signal for a service discovery request.
- * The signal will carry station address, frequency, dialog token,
- * update indicator and it tlvs
- *
- * @wpa_s: %wpa_supplicant network interface data
- * @sa: station addr (p2p i/f) of the peer
- * @dialog_token: service discovery request dialog token
- * @update_indic: service discovery request update indicator
- * @tlvs: service discovery request genrated byte array of tlvs
- * @tlvs_len: service discovery request tlvs length
- */
- void wpas_dbus_signal_p2p_sd_request(struct wpa_supplicant *wpa_s,
- int freq, const u8 *sa, u8 dialog_token,
- u16 update_indic, const u8 *tlvs,
- size_t tlvs_len)
- {
- DBusMessage *msg;
- DBusMessageIter iter, dict_iter;
- struct wpas_dbus_priv *iface;
- char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL)
- return;
- if (wpa_s->p2p_mgmt)
- wpa_s = wpa_s->parent;
- if (!wpa_s->dbus_new_path)
- return;
- /* Check if this is a known peer */
- if (!p2p_peer_known(wpa_s->global->p2p, sa))
- return;
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- "ServiceDiscoveryRequest");
- if (msg == NULL)
- return;
- os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
- "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
- COMPACT_MACSTR, wpa_s->dbus_new_path, MAC2STR(sa));
- path = peer_obj_path;
- dbus_message_iter_init_append(msg, &iter);
- if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
- !wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
- path) ||
- !wpa_dbus_dict_append_int32(&dict_iter, "frequency", freq) ||
- !wpa_dbus_dict_append_int32(&dict_iter, "dialog_token",
- dialog_token) ||
- !wpa_dbus_dict_append_uint16(&dict_iter, "update_indicator",
- update_indic) ||
- !wpa_dbus_dict_append_byte_array(&dict_iter, "tlvs",
- (const char *) tlvs,
- tlvs_len) ||
- !wpa_dbus_dict_close_write(&iter, &dict_iter))
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- else
- dbus_connection_send(iface->con, msg, NULL);
- dbus_message_unref(msg);
- }
- /**
- *
- * Method to emit a signal for a service discovery response.
- * The signal will carry station address, update indicator and it
- * tlvs
- *
- * @wpa_s: %wpa_supplicant network interface data
- * @sa: station addr (p2p i/f) of the peer
- * @update_indic: service discovery request update indicator
- * @tlvs: service discovery request genrated byte array of tlvs
- * @tlvs_len: service discovery request tlvs length
- */
- void wpas_dbus_signal_p2p_sd_response(struct wpa_supplicant *wpa_s,
- const u8 *sa, u16 update_indic,
- const u8 *tlvs, size_t tlvs_len)
- {
- DBusMessage *msg;
- DBusMessageIter iter, dict_iter;
- struct wpas_dbus_priv *iface;
- char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL)
- return;
- if (wpa_s->p2p_mgmt)
- wpa_s = wpa_s->parent;
- if (!wpa_s->dbus_new_path)
- return;
- /* Check if this is a known peer */
- if (!p2p_peer_known(wpa_s->global->p2p, sa))
- return;
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- "ServiceDiscoveryResponse");
- if (msg == NULL)
- return;
- os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
- "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
- COMPACT_MACSTR, wpa_s->dbus_new_path, MAC2STR(sa));
- path = peer_obj_path;
- dbus_message_iter_init_append(msg, &iter);
- if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
- !wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
- path) ||
- !wpa_dbus_dict_append_uint16(&dict_iter, "update_indicator",
- update_indic) ||
- !wpa_dbus_dict_append_byte_array(&dict_iter, "tlvs",
- (const char *) tlvs,
- tlvs_len) ||
- !wpa_dbus_dict_close_write(&iter, &dict_iter))
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- else
- dbus_connection_send(iface->con, msg, NULL);
- dbus_message_unref(msg);
- }
- /**
- * wpas_dbus_signal_persistent_group - Send a persistent group related
- * event signal
- * @wpa_s: %wpa_supplicant network interface data
- * @id: new persistent group id
- * @sig_name: signal name - PersistentGroupAdded, PersistentGroupRemoved
- * @properties: determines if add second argument with object properties
- *
- * Notify listeners about an event related to persistent groups.
- */
- static void wpas_dbus_signal_persistent_group(struct wpa_supplicant *wpa_s,
- int id, const char *sig_name,
- int properties)
- {
- struct wpas_dbus_priv *iface;
- DBusMessage *msg;
- DBusMessageIter iter;
- char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL)
- return;
- if (wpa_s->p2p_mgmt)
- wpa_s = wpa_s->parent;
- if (!wpa_s->dbus_new_path)
- return;
- os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
- "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
- wpa_s->dbus_new_path, id);
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- sig_name);
- if (msg == NULL)
- return;
- dbus_message_iter_init_append(msg, &iter);
- path = pgrp_obj_path;
- if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
- &path) ||
- (properties &&
- !wpa_dbus_get_object_properties(
- iface, pgrp_obj_path,
- WPAS_DBUS_NEW_IFACE_PERSISTENT_GROUP, &iter)))
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- else
- dbus_connection_send(iface->con, msg, NULL);
- dbus_message_unref(msg);
- }
- /**
- * wpas_dbus_signal_persistent_group_added - Send a persistent_group
- * added signal
- * @wpa_s: %wpa_supplicant network interface data
- * @id: new persistent group id
- *
- * Notify listeners about addition of a new persistent group.
- */
- static void wpas_dbus_signal_persistent_group_added(
- struct wpa_supplicant *wpa_s, int id)
- {
- wpas_dbus_signal_persistent_group(wpa_s, id, "PersistentGroupAdded",
- TRUE);
- }
- /**
- * wpas_dbus_signal_persistent_group_removed - Send a persistent_group
- * removed signal
- * @wpa_s: %wpa_supplicant network interface data
- * @id: persistent group id
- *
- * Notify listeners about removal of a persistent group.
- */
- static void wpas_dbus_signal_persistent_group_removed(
- struct wpa_supplicant *wpa_s, int id)
- {
- wpas_dbus_signal_persistent_group(wpa_s, id, "PersistentGroupRemoved",
- FALSE);
- }
- /**
- * wpas_dbus_signal_p2p_wps_failed - Signals WpsFailed event
- * @wpa_s: %wpa_supplicant network interface data
- * @fail: WPS failure information
- *
- * Sends Event dbus signal with name "fail" and dictionary containing
- * "msg" field with fail message number (int32) as arguments
- */
- void wpas_dbus_signal_p2p_wps_failed(struct wpa_supplicant *wpa_s,
- struct wps_event_fail *fail)
- {
- DBusMessage *msg;
- DBusMessageIter iter, dict_iter;
- struct wpas_dbus_priv *iface;
- char *key = "fail";
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL)
- return;
- if (wpa_s->p2p_mgmt)
- wpa_s = wpa_s->parent;
- if (!wpa_s->dbus_new_path)
- return;
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- "WpsFailed");
- if (msg == NULL)
- return;
- dbus_message_iter_init_append(msg, &iter);
- if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
- !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
- !wpa_dbus_dict_append_int32(&dict_iter, "msg", fail->msg) ||
- !wpa_dbus_dict_append_int16(&dict_iter, "config_error",
- fail->config_error) ||
- !wpa_dbus_dict_close_write(&iter, &dict_iter))
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- else
- dbus_connection_send(iface->con, msg, NULL);
- dbus_message_unref(msg);
- }
- #endif /* CONFIG_P2P */
- /**
- * wpas_dbus_signal_prop_changed - Signals change of property
- * @wpa_s: %wpa_supplicant network interface data
- * @property: indicates which property has changed
- *
- * Sends PropertyChanged signals with path, interface and arguments
- * depending on which property has changed.
- */
- void wpas_dbus_signal_prop_changed(struct wpa_supplicant *wpa_s,
- enum wpas_dbus_prop property)
- {
- char *prop;
- dbus_bool_t flush;
- if (wpa_s->dbus_new_path == NULL)
- return; /* Skip signal since D-Bus setup is not yet ready */
- flush = FALSE;
- switch (property) {
- case WPAS_DBUS_PROP_AP_SCAN:
- prop = "ApScan";
- break;
- case WPAS_DBUS_PROP_SCANNING:
- prop = "Scanning";
- break;
- case WPAS_DBUS_PROP_STATE:
- prop = "State";
- break;
- case WPAS_DBUS_PROP_CURRENT_BSS:
- prop = "CurrentBSS";
- break;
- case WPAS_DBUS_PROP_CURRENT_NETWORK:
- prop = "CurrentNetwork";
- break;
- case WPAS_DBUS_PROP_BSSS:
- prop = "BSSs";
- break;
- case WPAS_DBUS_PROP_CURRENT_AUTH_MODE:
- prop = "CurrentAuthMode";
- break;
- case WPAS_DBUS_PROP_DISCONNECT_REASON:
- prop = "DisconnectReason";
- flush = TRUE;
- break;
- default:
- wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
- __func__, property);
- return;
- }
- wpa_dbus_mark_property_changed(wpa_s->global->dbus,
- wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_INTERFACE, prop);
- if (flush) {
- wpa_dbus_flush_object_changed_properties(
- wpa_s->global->dbus->con, wpa_s->dbus_new_path);
- }
- }
- /**
- * wpas_dbus_bss_signal_prop_changed - Signals change of BSS property
- * @wpa_s: %wpa_supplicant network interface data
- * @property: indicates which property has changed
- * @id: unique BSS identifier
- *
- * Sends PropertyChanged signals with path, interface, and arguments depending
- * on which property has changed.
- */
- void wpas_dbus_bss_signal_prop_changed(struct wpa_supplicant *wpa_s,
- enum wpas_dbus_bss_prop property,
- unsigned int id)
- {
- char path[WPAS_DBUS_OBJECT_PATH_MAX];
- char *prop;
- if (!wpa_s->dbus_new_path)
- return;
- switch (property) {
- case WPAS_DBUS_BSS_PROP_SIGNAL:
- prop = "Signal";
- break;
- case WPAS_DBUS_BSS_PROP_FREQ:
- prop = "Frequency";
- break;
- case WPAS_DBUS_BSS_PROP_MODE:
- prop = "Mode";
- break;
- case WPAS_DBUS_BSS_PROP_PRIVACY:
- prop = "Privacy";
- break;
- case WPAS_DBUS_BSS_PROP_RATES:
- prop = "Rates";
- break;
- case WPAS_DBUS_BSS_PROP_WPA:
- prop = "WPA";
- break;
- case WPAS_DBUS_BSS_PROP_RSN:
- prop = "RSN";
- break;
- case WPAS_DBUS_BSS_PROP_WPS:
- prop = "WPS";
- break;
- case WPAS_DBUS_BSS_PROP_IES:
- prop = "IEs";
- break;
- case WPAS_DBUS_BSS_PROP_AGE:
- prop = "Age";
- break;
- default:
- wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
- __func__, property);
- return;
- }
- os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
- "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
- wpa_s->dbus_new_path, id);
- wpa_dbus_mark_property_changed(wpa_s->global->dbus, path,
- WPAS_DBUS_NEW_IFACE_BSS, prop);
- }
- /**
- * wpas_dbus_signal_debug_level_changed - Signals change of debug param
- * @global: wpa_global structure
- *
- * Sends PropertyChanged signals informing that debug level has changed.
- */
- void wpas_dbus_signal_debug_level_changed(struct wpa_global *global)
- {
- wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
- WPAS_DBUS_NEW_INTERFACE,
- "DebugLevel");
- }
- /**
- * wpas_dbus_signal_debug_timestamp_changed - Signals change of debug param
- * @global: wpa_global structure
- *
- * Sends PropertyChanged signals informing that debug timestamp has changed.
- */
- void wpas_dbus_signal_debug_timestamp_changed(struct wpa_global *global)
- {
- wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
- WPAS_DBUS_NEW_INTERFACE,
- "DebugTimestamp");
- }
- /**
- * wpas_dbus_signal_debug_show_keys_changed - Signals change of debug param
- * @global: wpa_global structure
- *
- * Sends PropertyChanged signals informing that debug show_keys has changed.
- */
- void wpas_dbus_signal_debug_show_keys_changed(struct wpa_global *global)
- {
- wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
- WPAS_DBUS_NEW_INTERFACE,
- "DebugShowKeys");
- }
- static void wpas_dbus_register(struct wpa_dbus_object_desc *obj_desc,
- void *priv,
- WPADBusArgumentFreeFunction priv_free,
- const struct wpa_dbus_method_desc *methods,
- const struct wpa_dbus_property_desc *properties,
- const struct wpa_dbus_signal_desc *signals)
- {
- int n;
- obj_desc->user_data = priv;
- obj_desc->user_data_free_func = priv_free;
- obj_desc->methods = methods;
- obj_desc->properties = properties;
- obj_desc->signals = signals;
- for (n = 0; properties && properties->dbus_property; properties++)
- n++;
- obj_desc->prop_changed_flags = os_zalloc(n);
- if (!obj_desc->prop_changed_flags)
- wpa_printf(MSG_DEBUG, "dbus: %s: can't register handlers",
- __func__);
- }
- static const struct wpa_dbus_method_desc wpas_dbus_global_methods[] = {
- { "CreateInterface", WPAS_DBUS_NEW_INTERFACE,
- (WPADBusMethodHandler) wpas_dbus_handler_create_interface,
- {
- { "args", "a{sv}", ARG_IN },
- { "path", "o", ARG_OUT },
- END_ARGS
- }
- },
- { "RemoveInterface", WPAS_DBUS_NEW_INTERFACE,
- (WPADBusMethodHandler) wpas_dbus_handler_remove_interface,
- {
- { "path", "o", ARG_IN },
- END_ARGS
- }
- },
- { "GetInterface", WPAS_DBUS_NEW_INTERFACE,
- (WPADBusMethodHandler) wpas_dbus_handler_get_interface,
- {
- { "ifname", "s", ARG_IN },
- { "path", "o", ARG_OUT },
- END_ARGS
- }
- },
- { NULL, NULL, NULL, { END_ARGS } }
- };
- static const struct wpa_dbus_property_desc wpas_dbus_global_properties[] = {
- { "DebugLevel", WPAS_DBUS_NEW_INTERFACE, "s",
- wpas_dbus_getter_debug_level,
- wpas_dbus_setter_debug_level
- },
- { "DebugTimestamp", WPAS_DBUS_NEW_INTERFACE, "b",
- wpas_dbus_getter_debug_timestamp,
- wpas_dbus_setter_debug_timestamp
- },
- { "DebugShowKeys", WPAS_DBUS_NEW_INTERFACE, "b",
- wpas_dbus_getter_debug_show_keys,
- wpas_dbus_setter_debug_show_keys
- },
- { "Interfaces", WPAS_DBUS_NEW_INTERFACE, "ao",
- wpas_dbus_getter_interfaces,
- NULL
- },
- { "EapMethods", WPAS_DBUS_NEW_INTERFACE, "as",
- wpas_dbus_getter_eap_methods,
- NULL
- },
- { "Capabilities", WPAS_DBUS_NEW_INTERFACE, "as",
- wpas_dbus_getter_global_capabilities,
- NULL
- },
- #ifdef CONFIG_WIFI_DISPLAY
- { "WFDIEs", WPAS_DBUS_NEW_INTERFACE, "ay",
- wpas_dbus_getter_global_wfd_ies,
- wpas_dbus_setter_global_wfd_ies
- },
- #endif /* CONFIG_WIFI_DISPLAY */
- { NULL, NULL, NULL, NULL, NULL }
- };
- static const struct wpa_dbus_signal_desc wpas_dbus_global_signals[] = {
- { "InterfaceAdded", WPAS_DBUS_NEW_INTERFACE,
- {
- { "path", "o", ARG_OUT },
- { "properties", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- { "InterfaceRemoved", WPAS_DBUS_NEW_INTERFACE,
- {
- { "path", "o", ARG_OUT },
- END_ARGS
- }
- },
- /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
- { "PropertiesChanged", WPAS_DBUS_NEW_INTERFACE,
- {
- { "properties", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- { NULL, NULL, { END_ARGS } }
- };
- /**
- * wpas_dbus_ctrl_iface_init - Initialize dbus control interface
- * @global: Pointer to global data from wpa_supplicant_init()
- * Returns: 0 on success or -1 on failure
- *
- * Initialize the dbus control interface for wpa_supplicantand and start
- * receiving commands from external programs over the bus.
- */
- int wpas_dbus_ctrl_iface_init(struct wpas_dbus_priv *priv)
- {
- struct wpa_dbus_object_desc *obj_desc;
- int ret;
- obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
- if (!obj_desc) {
- wpa_printf(MSG_ERROR,
- "Not enough memory to create object description");
- return -1;
- }
- wpas_dbus_register(obj_desc, priv->global, NULL,
- wpas_dbus_global_methods,
- wpas_dbus_global_properties,
- wpas_dbus_global_signals);
- wpa_printf(MSG_DEBUG, "dbus: Register D-Bus object '%s'",
- WPAS_DBUS_NEW_PATH);
- ret = wpa_dbus_ctrl_iface_init(priv, WPAS_DBUS_NEW_PATH,
- WPAS_DBUS_NEW_SERVICE,
- obj_desc);
- if (ret < 0)
- free_dbus_object_desc(obj_desc);
- else
- priv->dbus_new_initialized = 1;
- return ret;
- }
- /**
- * wpas_dbus_ctrl_iface_deinit - Deinitialize dbus ctrl interface for
- * wpa_supplicant
- * @iface: Pointer to dbus private data from wpas_dbus_init()
- *
- * Deinitialize the dbus control interface that was initialized with
- * wpas_dbus_ctrl_iface_init().
- */
- void wpas_dbus_ctrl_iface_deinit(struct wpas_dbus_priv *iface)
- {
- if (!iface->dbus_new_initialized)
- return;
- wpa_printf(MSG_DEBUG, "dbus: Unregister D-Bus object '%s'",
- WPAS_DBUS_NEW_PATH);
- dbus_connection_unregister_object_path(iface->con,
- WPAS_DBUS_NEW_PATH);
- }
- static void wpa_dbus_free(void *ptr)
- {
- os_free(ptr);
- }
- static const struct wpa_dbus_property_desc wpas_dbus_network_properties[] = {
- { "Properties", WPAS_DBUS_NEW_IFACE_NETWORK, "a{sv}",
- wpas_dbus_getter_network_properties,
- wpas_dbus_setter_network_properties
- },
- { "Enabled", WPAS_DBUS_NEW_IFACE_NETWORK, "b",
- wpas_dbus_getter_enabled,
- wpas_dbus_setter_enabled
- },
- { NULL, NULL, NULL, NULL, NULL }
- };
- static const struct wpa_dbus_signal_desc wpas_dbus_network_signals[] = {
- /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
- { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_NETWORK,
- {
- { "properties", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- { NULL, NULL, { END_ARGS } }
- };
- /**
- * wpas_dbus_register_network - Register a configured network with dbus
- * @wpa_s: wpa_supplicant interface structure
- * @ssid: network configuration data
- * Returns: 0 on success, -1 on failure
- *
- * Registers network representing object with dbus
- */
- int wpas_dbus_register_network(struct wpa_supplicant *wpa_s,
- struct wpa_ssid *ssid)
- {
- struct wpas_dbus_priv *ctrl_iface;
- struct wpa_dbus_object_desc *obj_desc;
- struct network_handler_args *arg;
- char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
- #ifdef CONFIG_P2P
- /*
- * If it is a persistent group register it as such.
- * This is to handle cases where an interface is being initialized
- * with a list of networks read from config.
- */
- if (network_is_persistent_group(ssid))
- return wpas_dbus_register_persistent_group(wpa_s, ssid);
- #endif /* CONFIG_P2P */
- /* Do nothing if the control interface is not turned on */
- if (wpa_s == NULL || wpa_s->global == NULL || !wpa_s->dbus_new_path)
- return 0;
- ctrl_iface = wpa_s->global->dbus;
- if (ctrl_iface == NULL)
- return 0;
- os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
- "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
- wpa_s->dbus_new_path, ssid->id);
- wpa_printf(MSG_DEBUG, "dbus: Register network object '%s'",
- net_obj_path);
- obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
- if (!obj_desc) {
- wpa_printf(MSG_ERROR,
- "Not enough memory to create object description");
- goto err;
- }
- /* allocate memory for handlers arguments */
- arg = os_zalloc(sizeof(struct network_handler_args));
- if (!arg) {
- wpa_printf(MSG_ERROR,
- "Not enough memory to create arguments for method");
- goto err;
- }
- arg->wpa_s = wpa_s;
- arg->ssid = ssid;
- wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
- wpas_dbus_network_properties,
- wpas_dbus_network_signals);
- if (wpa_dbus_register_object_per_iface(ctrl_iface, net_obj_path,
- wpa_s->ifname, obj_desc))
- goto err;
- wpas_dbus_signal_network_added(wpa_s, ssid->id);
- return 0;
- err:
- free_dbus_object_desc(obj_desc);
- return -1;
- }
- /**
- * wpas_dbus_unregister_network - Unregister a configured network from dbus
- * @wpa_s: wpa_supplicant interface structure
- * @nid: network id
- * Returns: 0 on success, -1 on failure
- *
- * Unregisters network representing object from dbus
- */
- int wpas_dbus_unregister_network(struct wpa_supplicant *wpa_s, int nid)
- {
- struct wpas_dbus_priv *ctrl_iface;
- char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
- int ret;
- #ifdef CONFIG_P2P
- struct wpa_ssid *ssid;
- ssid = wpa_config_get_network(wpa_s->conf, nid);
- /* If it is a persistent group unregister it as such */
- if (ssid && network_is_persistent_group(ssid))
- return wpas_dbus_unregister_persistent_group(wpa_s, nid);
- #endif /* CONFIG_P2P */
- /* Do nothing if the control interface is not turned on */
- if (wpa_s->global == NULL || wpa_s->dbus_new_path == NULL)
- return 0;
- ctrl_iface = wpa_s->global->dbus;
- if (ctrl_iface == NULL)
- return 0;
- os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
- "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
- wpa_s->dbus_new_path, nid);
- wpa_printf(MSG_DEBUG, "dbus: Unregister network object '%s'",
- net_obj_path);
- ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, net_obj_path);
- if (!ret)
- wpas_dbus_signal_network_removed(wpa_s, nid);
- return ret;
- }
- static const struct wpa_dbus_property_desc wpas_dbus_bss_properties[] = {
- { "SSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
- wpas_dbus_getter_bss_ssid,
- NULL
- },
- { "BSSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
- wpas_dbus_getter_bss_bssid,
- NULL
- },
- { "Privacy", WPAS_DBUS_NEW_IFACE_BSS, "b",
- wpas_dbus_getter_bss_privacy,
- NULL
- },
- { "Mode", WPAS_DBUS_NEW_IFACE_BSS, "s",
- wpas_dbus_getter_bss_mode,
- NULL
- },
- { "Signal", WPAS_DBUS_NEW_IFACE_BSS, "n",
- wpas_dbus_getter_bss_signal,
- NULL
- },
- { "Frequency", WPAS_DBUS_NEW_IFACE_BSS, "q",
- wpas_dbus_getter_bss_frequency,
- NULL
- },
- { "Rates", WPAS_DBUS_NEW_IFACE_BSS, "au",
- wpas_dbus_getter_bss_rates,
- NULL
- },
- { "WPA", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
- wpas_dbus_getter_bss_wpa,
- NULL
- },
- { "RSN", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
- wpas_dbus_getter_bss_rsn,
- NULL
- },
- { "WPS", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
- wpas_dbus_getter_bss_wps,
- NULL
- },
- { "IEs", WPAS_DBUS_NEW_IFACE_BSS, "ay",
- wpas_dbus_getter_bss_ies,
- NULL
- },
- { "Age", WPAS_DBUS_NEW_IFACE_BSS, "u",
- wpas_dbus_getter_bss_age,
- NULL
- },
- { NULL, NULL, NULL, NULL, NULL }
- };
- static const struct wpa_dbus_signal_desc wpas_dbus_bss_signals[] = {
- /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
- { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_BSS,
- {
- { "properties", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- { NULL, NULL, { END_ARGS } }
- };
- /**
- * wpas_dbus_unregister_bss - Unregister a scanned BSS from dbus
- * @wpa_s: wpa_supplicant interface structure
- * @bssid: scanned network bssid
- * @id: unique BSS identifier
- * Returns: 0 on success, -1 on failure
- *
- * Unregisters BSS representing object from dbus
- */
- int wpas_dbus_unregister_bss(struct wpa_supplicant *wpa_s,
- u8 bssid[ETH_ALEN], unsigned int id)
- {
- struct wpas_dbus_priv *ctrl_iface;
- char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
- /* Do nothing if the control interface is not turned on */
- if (wpa_s == NULL || wpa_s->global == NULL || !wpa_s->dbus_new_path)
- return 0;
- ctrl_iface = wpa_s->global->dbus;
- if (ctrl_iface == NULL)
- return 0;
- os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
- "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
- wpa_s->dbus_new_path, id);
- wpa_printf(MSG_DEBUG, "dbus: Unregister BSS object '%s'",
- bss_obj_path);
- if (wpa_dbus_unregister_object_per_iface(ctrl_iface, bss_obj_path)) {
- wpa_printf(MSG_ERROR, "dbus: Cannot unregister BSS object %s",
- bss_obj_path);
- return -1;
- }
- wpas_dbus_signal_bss_removed(wpa_s, bss_obj_path);
- wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSSS);
- return 0;
- }
- /**
- * wpas_dbus_register_bss - Register a scanned BSS with dbus
- * @wpa_s: wpa_supplicant interface structure
- * @bssid: scanned network bssid
- * @id: unique BSS identifier
- * Returns: 0 on success, -1 on failure
- *
- * Registers BSS representing object with dbus
- */
- int wpas_dbus_register_bss(struct wpa_supplicant *wpa_s,
- u8 bssid[ETH_ALEN], unsigned int id)
- {
- struct wpas_dbus_priv *ctrl_iface;
- struct wpa_dbus_object_desc *obj_desc;
- char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
- struct bss_handler_args *arg;
- /* Do nothing if the control interface is not turned on */
- if (wpa_s == NULL || wpa_s->global == NULL || !wpa_s->dbus_new_path)
- return 0;
- ctrl_iface = wpa_s->global->dbus;
- if (ctrl_iface == NULL)
- return 0;
- os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
- "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
- wpa_s->dbus_new_path, id);
- obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
- if (!obj_desc) {
- wpa_printf(MSG_ERROR,
- "Not enough memory to create object description");
- goto err;
- }
- arg = os_zalloc(sizeof(struct bss_handler_args));
- if (!arg) {
- wpa_printf(MSG_ERROR,
- "Not enough memory to create arguments for handler");
- goto err;
- }
- arg->wpa_s = wpa_s;
- arg->id = id;
- wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
- wpas_dbus_bss_properties,
- wpas_dbus_bss_signals);
- wpa_printf(MSG_DEBUG, "dbus: Register BSS object '%s'",
- bss_obj_path);
- if (wpa_dbus_register_object_per_iface(ctrl_iface, bss_obj_path,
- wpa_s->ifname, obj_desc)) {
- wpa_printf(MSG_ERROR,
- "Cannot register BSSID dbus object %s.",
- bss_obj_path);
- goto err;
- }
- wpas_dbus_signal_bss_added(wpa_s, bss_obj_path);
- wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSSS);
- return 0;
- err:
- free_dbus_object_desc(obj_desc);
- return -1;
- }
- static const struct wpa_dbus_method_desc wpas_dbus_interface_methods[] = {
- { "Scan", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) wpas_dbus_handler_scan,
- {
- { "args", "a{sv}", ARG_IN },
- END_ARGS
- }
- },
- { "SignalPoll", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) wpas_dbus_handler_signal_poll,
- {
- { "args", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- { "Disconnect", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) wpas_dbus_handler_disconnect,
- {
- END_ARGS
- }
- },
- { "AddNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) wpas_dbus_handler_add_network,
- {
- { "args", "a{sv}", ARG_IN },
- { "path", "o", ARG_OUT },
- END_ARGS
- }
- },
- { "Reassociate", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) wpas_dbus_handler_reassociate,
- {
- END_ARGS
- }
- },
- { "Reattach", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) wpas_dbus_handler_reattach,
- {
- END_ARGS
- }
- },
- { "Reconnect", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) wpas_dbus_handler_reconnect,
- {
- END_ARGS
- }
- },
- { "RemoveNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) wpas_dbus_handler_remove_network,
- {
- { "path", "o", ARG_IN },
- END_ARGS
- }
- },
- { "RemoveAllNetworks", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) wpas_dbus_handler_remove_all_networks,
- {
- END_ARGS
- }
- },
- { "SelectNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) wpas_dbus_handler_select_network,
- {
- { "path", "o", ARG_IN },
- END_ARGS
- }
- },
- { "NetworkReply", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) wpas_dbus_handler_network_reply,
- {
- { "path", "o", ARG_IN },
- { "field", "s", ARG_IN },
- { "value", "s", ARG_IN },
- END_ARGS
- }
- },
- #ifndef CONFIG_NO_CONFIG_BLOBS
- { "AddBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) wpas_dbus_handler_add_blob,
- {
- { "name", "s", ARG_IN },
- { "data", "ay", ARG_IN },
- END_ARGS
- }
- },
- { "GetBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) wpas_dbus_handler_get_blob,
- {
- { "name", "s", ARG_IN },
- { "data", "ay", ARG_OUT },
- END_ARGS
- }
- },
- { "RemoveBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) wpas_dbus_handler_remove_blob,
- {
- { "name", "s", ARG_IN },
- END_ARGS
- }
- },
- #endif /* CONFIG_NO_CONFIG_BLOBS */
- { "SetPKCS11EngineAndModulePath", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler)
- wpas_dbus_handler_set_pkcs11_engine_and_module_path,
- {
- { "pkcs11_engine_path", "s", ARG_IN },
- { "pkcs11_module_path", "s", ARG_IN },
- END_ARGS
- }
- },
- #ifdef CONFIG_WPS
- { "Start", WPAS_DBUS_NEW_IFACE_WPS,
- (WPADBusMethodHandler) wpas_dbus_handler_wps_start,
- {
- { "args", "a{sv}", ARG_IN },
- { "output", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- { "Cancel", WPAS_DBUS_NEW_IFACE_WPS,
- (WPADBusMethodHandler) wpas_dbus_handler_wps_cancel,
- {
- END_ARGS
- }
- },
- #endif /* CONFIG_WPS */
- #ifdef CONFIG_P2P
- { "Find", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- (WPADBusMethodHandler) wpas_dbus_handler_p2p_find,
- {
- { "args", "a{sv}", ARG_IN },
- END_ARGS
- }
- },
- { "StopFind", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- (WPADBusMethodHandler) wpas_dbus_handler_p2p_stop_find,
- {
- END_ARGS
- }
- },
- { "Listen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- (WPADBusMethodHandler) wpas_dbus_handler_p2p_listen,
- {
- { "timeout", "i", ARG_IN },
- END_ARGS
- }
- },
- { "ExtendedListen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- (WPADBusMethodHandler) wpas_dbus_handler_p2p_extendedlisten,
- {
- { "args", "a{sv}", ARG_IN },
- END_ARGS
- }
- },
- { "PresenceRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- (WPADBusMethodHandler) wpas_dbus_handler_p2p_presence_request,
- {
- { "args", "a{sv}", ARG_IN },
- END_ARGS
- }
- },
- { "ProvisionDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- (WPADBusMethodHandler) wpas_dbus_handler_p2p_prov_disc_req,
- {
- { "peer", "o", ARG_IN },
- { "config_method", "s", ARG_IN },
- END_ARGS
- }
- },
- { "Connect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- (WPADBusMethodHandler) wpas_dbus_handler_p2p_connect,
- {
- { "args", "a{sv}", ARG_IN },
- { "generated_pin", "s", ARG_OUT },
- END_ARGS
- }
- },
- { "GroupAdd", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- (WPADBusMethodHandler) wpas_dbus_handler_p2p_group_add,
- {
- { "args", "a{sv}", ARG_IN },
- END_ARGS
- }
- },
- { "Cancel", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- (WPADBusMethodHandler) wpas_dbus_handler_p2p_cancel,
- {
- END_ARGS
- }
- },
- { "Invite", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- (WPADBusMethodHandler) wpas_dbus_handler_p2p_invite,
- {
- { "args", "a{sv}", ARG_IN },
- END_ARGS
- }
- },
- { "Disconnect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- (WPADBusMethodHandler) wpas_dbus_handler_p2p_disconnect,
- {
- END_ARGS
- }
- },
- { "RejectPeer", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- (WPADBusMethodHandler) wpas_dbus_handler_p2p_rejectpeer,
- {
- { "peer", "o", ARG_IN },
- END_ARGS
- }
- },
- { "RemoveClient", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- (WPADBusMethodHandler) wpas_dbus_handler_p2p_remove_client,
- {
- { "args", "a{sv}", ARG_IN },
- END_ARGS
- }
- },
- { "Flush", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- (WPADBusMethodHandler) wpas_dbus_handler_p2p_flush,
- {
- END_ARGS
- }
- },
- { "AddService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- (WPADBusMethodHandler) wpas_dbus_handler_p2p_add_service,
- {
- { "args", "a{sv}", ARG_IN },
- END_ARGS
- }
- },
- { "DeleteService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- (WPADBusMethodHandler) wpas_dbus_handler_p2p_delete_service,
- {
- { "args", "a{sv}", ARG_IN },
- END_ARGS
- }
- },
- { "FlushService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- (WPADBusMethodHandler) wpas_dbus_handler_p2p_flush_service,
- {
- END_ARGS
- }
- },
- { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_sd_req,
- {
- { "args", "a{sv}", ARG_IN },
- { "ref", "t", ARG_OUT },
- END_ARGS
- }
- },
- { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_sd_res,
- {
- { "args", "a{sv}", ARG_IN },
- END_ARGS
- }
- },
- { "ServiceDiscoveryCancelRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_sd_cancel_req,
- {
- { "args", "t", ARG_IN },
- END_ARGS
- }
- },
- { "ServiceUpdate", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_update,
- {
- END_ARGS
- }
- },
- { "ServiceDiscoveryExternal", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- (WPADBusMethodHandler) wpas_dbus_handler_p2p_serv_disc_external,
- {
- { "arg", "i", ARG_IN },
- END_ARGS
- }
- },
- { "AddPersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- (WPADBusMethodHandler) wpas_dbus_handler_add_persistent_group,
- {
- { "args", "a{sv}", ARG_IN },
- { "path", "o", ARG_OUT },
- END_ARGS
- }
- },
- { "RemovePersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- (WPADBusMethodHandler) wpas_dbus_handler_remove_persistent_group,
- {
- { "path", "o", ARG_IN },
- END_ARGS
- }
- },
- { "RemoveAllPersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- (WPADBusMethodHandler)
- wpas_dbus_handler_remove_all_persistent_groups,
- {
- END_ARGS
- }
- },
- #endif /* CONFIG_P2P */
- { "FlushBSS", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) wpas_dbus_handler_flush_bss,
- {
- { "age", "u", ARG_IN },
- END_ARGS
- }
- },
- #ifdef CONFIG_AP
- { "SubscribeProbeReq", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) wpas_dbus_handler_subscribe_preq,
- {
- END_ARGS
- }
- },
- { "UnsubscribeProbeReq", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) wpas_dbus_handler_unsubscribe_preq,
- {
- END_ARGS
- }
- },
- #endif /* CONFIG_AP */
- { "EAPLogoff", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) wpas_dbus_handler_eap_logoff,
- {
- END_ARGS
- }
- },
- { "EAPLogon", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) wpas_dbus_handler_eap_logon,
- {
- END_ARGS
- }
- },
- #ifdef CONFIG_AUTOSCAN
- { "AutoScan", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) wpas_dbus_handler_autoscan,
- {
- { "arg", "s", ARG_IN },
- END_ARGS
- }
- },
- #endif /* CONFIG_AUTOSCAN */
- #ifdef CONFIG_TDLS
- { "TDLSDiscover", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) wpas_dbus_handler_tdls_discover,
- {
- { "peer_address", "s", ARG_IN },
- END_ARGS
- }
- },
- { "TDLSSetup", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) wpas_dbus_handler_tdls_setup,
- {
- { "peer_address", "s", ARG_IN },
- END_ARGS
- }
- },
- { "TDLSStatus", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) wpas_dbus_handler_tdls_status,
- {
- { "peer_address", "s", ARG_IN },
- { "status", "s", ARG_OUT },
- END_ARGS
- }
- },
- { "TDLSTeardown", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) wpas_dbus_handler_tdls_teardown,
- {
- { "peer_address", "s", ARG_IN },
- END_ARGS
- }
- },
- #endif /* CONFIG_TDLS */
- { NULL, NULL, NULL, { END_ARGS } }
- };
- static const struct wpa_dbus_property_desc wpas_dbus_interface_properties[] = {
- { "Capabilities", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{sv}",
- wpas_dbus_getter_capabilities,
- NULL
- },
- { "State", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
- wpas_dbus_getter_state,
- NULL
- },
- { "Scanning", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
- wpas_dbus_getter_scanning,
- NULL
- },
- { "ApScan", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
- wpas_dbus_getter_ap_scan,
- wpas_dbus_setter_ap_scan
- },
- { "BSSExpireAge", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
- wpas_dbus_getter_bss_expire_age,
- wpas_dbus_setter_bss_expire_age
- },
- { "BSSExpireCount", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
- wpas_dbus_getter_bss_expire_count,
- wpas_dbus_setter_bss_expire_count
- },
- { "Country", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
- wpas_dbus_getter_country,
- wpas_dbus_setter_country
- },
- { "Ifname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
- wpas_dbus_getter_ifname,
- NULL
- },
- { "Driver", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
- wpas_dbus_getter_driver,
- NULL
- },
- { "BridgeIfname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
- wpas_dbus_getter_bridge_ifname,
- NULL
- },
- { "CurrentBSS", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
- wpas_dbus_getter_current_bss,
- NULL
- },
- { "CurrentNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
- wpas_dbus_getter_current_network,
- NULL
- },
- { "CurrentAuthMode", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
- wpas_dbus_getter_current_auth_mode,
- NULL
- },
- { "Blobs", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{say}",
- wpas_dbus_getter_blobs,
- NULL
- },
- { "BSSs", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
- wpas_dbus_getter_bsss,
- NULL
- },
- { "Networks", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
- wpas_dbus_getter_networks,
- NULL
- },
- { "FastReauth", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
- wpas_dbus_getter_fast_reauth,
- wpas_dbus_setter_fast_reauth
- },
- { "ScanInterval", WPAS_DBUS_NEW_IFACE_INTERFACE, "i",
- wpas_dbus_getter_scan_interval,
- wpas_dbus_setter_scan_interval
- },
- { "PKCS11EnginePath", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
- wpas_dbus_getter_pkcs11_engine_path,
- NULL
- },
- { "PKCS11ModulePath", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
- wpas_dbus_getter_pkcs11_module_path,
- NULL
- },
- #ifdef CONFIG_WPS
- { "ProcessCredentials", WPAS_DBUS_NEW_IFACE_WPS, "b",
- wpas_dbus_getter_process_credentials,
- wpas_dbus_setter_process_credentials
- },
- { "ConfigMethods", WPAS_DBUS_NEW_IFACE_WPS, "s",
- wpas_dbus_getter_config_methods,
- wpas_dbus_setter_config_methods
- },
- #endif /* CONFIG_WPS */
- #ifdef CONFIG_P2P
- { "P2PDeviceConfig", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "a{sv}",
- wpas_dbus_getter_p2p_device_config,
- wpas_dbus_setter_p2p_device_config
- },
- { "Peers", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
- wpas_dbus_getter_p2p_peers,
- NULL
- },
- { "Role", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "s",
- wpas_dbus_getter_p2p_role,
- NULL
- },
- { "Group", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
- wpas_dbus_getter_p2p_group,
- NULL
- },
- { "PeerGO", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
- wpas_dbus_getter_p2p_peergo,
- NULL
- },
- { "PersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
- wpas_dbus_getter_persistent_groups,
- NULL
- },
- #endif /* CONFIG_P2P */
- { "DisconnectReason", WPAS_DBUS_NEW_IFACE_INTERFACE, "i",
- wpas_dbus_getter_disconnect_reason,
- NULL
- },
- { NULL, NULL, NULL, NULL, NULL }
- };
- static const struct wpa_dbus_signal_desc wpas_dbus_interface_signals[] = {
- { "ScanDone", WPAS_DBUS_NEW_IFACE_INTERFACE,
- {
- { "success", "b", ARG_OUT },
- END_ARGS
- }
- },
- { "BSSAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
- {
- { "path", "o", ARG_OUT },
- { "properties", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- { "BSSRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
- {
- { "path", "o", ARG_OUT },
- END_ARGS
- }
- },
- { "BlobAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
- {
- { "name", "s", ARG_OUT },
- END_ARGS
- }
- },
- { "BlobRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
- {
- { "name", "s", ARG_OUT },
- END_ARGS
- }
- },
- { "NetworkAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
- {
- { "path", "o", ARG_OUT },
- { "properties", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- { "NetworkRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
- {
- { "path", "o", ARG_OUT },
- END_ARGS
- }
- },
- { "NetworkSelected", WPAS_DBUS_NEW_IFACE_INTERFACE,
- {
- { "path", "o", ARG_OUT },
- END_ARGS
- }
- },
- /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
- { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_INTERFACE,
- {
- { "properties", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- #ifdef CONFIG_WPS
- { "Event", WPAS_DBUS_NEW_IFACE_WPS,
- {
- { "name", "s", ARG_OUT },
- { "args", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- { "Credentials", WPAS_DBUS_NEW_IFACE_WPS,
- {
- { "credentials", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
- { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_WPS,
- {
- { "properties", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- #endif /* CONFIG_WPS */
- #ifdef CONFIG_P2P
- { "DeviceFound", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- {
- { "path", "o", ARG_OUT },
- END_ARGS
- }
- },
- { "DeviceLost", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- {
- { "path", "o", ARG_OUT },
- END_ARGS
- }
- },
- { "FindStopped", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- {
- END_ARGS
- }
- },
- { "ProvisionDiscoveryRequestDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- {
- { "peer_object", "o", ARG_OUT },
- { "pin", "s", ARG_OUT },
- END_ARGS
- }
- },
- { "ProvisionDiscoveryResponseDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- {
- { "peer_object", "o", ARG_OUT },
- { "pin", "s", ARG_OUT },
- END_ARGS
- }
- },
- { "ProvisionDiscoveryRequestEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- {
- { "peer_object", "o", ARG_OUT },
- END_ARGS
- }
- },
- { "ProvisionDiscoveryResponseEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- {
- { "peer_object", "o", ARG_OUT },
- END_ARGS
- }
- },
- { "ProvisionDiscoveryPBCRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- {
- { "peer_object", "o", ARG_OUT },
- END_ARGS
- }
- },
- { "ProvisionDiscoveryPBCResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- {
- { "peer_object", "o", ARG_OUT },
- END_ARGS
- }
- },
- { "ProvisionDiscoveryFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- {
- { "peer_object", "o", ARG_OUT },
- { "status", "i", ARG_OUT },
- END_ARGS
- }
- },
- { "GroupStarted", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- {
- { "properties", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- { "GONegotiationSuccess", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- {
- { "properties", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- { "GONegotiationFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- {
- { "properties", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- { "GONegotiationRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- {
- { "path", "o", ARG_OUT },
- { "dev_passwd_id", "i", ARG_OUT },
- { "device_go_intent", "y", ARG_OUT },
- END_ARGS
- }
- },
- { "InvitationResult", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- {
- { "invite_result", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- { "GroupFinished", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- {
- { "properties", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- {
- { "sd_request", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- {
- { "sd_response", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- { "PersistentGroupAdded", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- {
- { "path", "o", ARG_OUT },
- { "properties", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- { "PersistentGroupRemoved", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- {
- { "path", "o", ARG_OUT },
- END_ARGS
- }
- },
- { "WpsFailed", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- {
- { "name", "s", ARG_OUT },
- { "args", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- #endif /* CONFIG_P2P */
- #ifdef CONFIG_AP
- { "ProbeRequest", WPAS_DBUS_NEW_IFACE_INTERFACE,
- {
- { "args", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- #endif /* CONFIG_AP */
- { "Certification", WPAS_DBUS_NEW_IFACE_INTERFACE,
- {
- { "certification", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- { "EAP", WPAS_DBUS_NEW_IFACE_INTERFACE,
- {
- { "status", "s", ARG_OUT },
- { "parameter", "s", ARG_OUT },
- END_ARGS
- }
- },
- { "StaAuthorized", WPAS_DBUS_NEW_IFACE_INTERFACE,
- {
- { "name", "s", ARG_OUT },
- END_ARGS
- }
- },
- { "StaDeauthorized", WPAS_DBUS_NEW_IFACE_INTERFACE,
- {
- { "name", "s", ARG_OUT },
- END_ARGS
- }
- },
- { "NetworkRequest", WPAS_DBUS_NEW_IFACE_INTERFACE,
- {
- { "path", "o", ARG_OUT },
- { "field", "s", ARG_OUT },
- { "text", "s", ARG_OUT },
- END_ARGS
- }
- },
- { NULL, NULL, { END_ARGS } }
- };
- /**
- * wpas_dbus_register_interface - Register an interface with D-Bus
- * @wpa_s: wpa_supplicant interface structure
- * Returns: 0 on success, -1 on failure
- */
- int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s)
- {
- struct wpa_dbus_object_desc *obj_desc = NULL;
- struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus;
- int next;
- /* Do nothing if the control interface is not turned on */
- if (ctrl_iface == NULL)
- return 0;
- /* Create and set the interface's object path */
- wpa_s->dbus_new_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
- if (wpa_s->dbus_new_path == NULL)
- return -1;
- next = ctrl_iface->next_objid++;
- os_snprintf(wpa_s->dbus_new_path, WPAS_DBUS_OBJECT_PATH_MAX,
- WPAS_DBUS_NEW_PATH_INTERFACES "/%u",
- next);
- obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
- if (!obj_desc) {
- wpa_printf(MSG_ERROR,
- "Not enough memory to create object description");
- goto err;
- }
- wpas_dbus_register(obj_desc, wpa_s, NULL, wpas_dbus_interface_methods,
- wpas_dbus_interface_properties,
- wpas_dbus_interface_signals);
- wpa_printf(MSG_DEBUG, "dbus: Register interface object '%s'",
- wpa_s->dbus_new_path);
- if (wpa_dbus_register_object_per_iface(ctrl_iface,
- wpa_s->dbus_new_path,
- wpa_s->ifname, obj_desc))
- goto err;
- wpas_dbus_signal_interface_added(wpa_s);
- return 0;
- err:
- os_free(wpa_s->dbus_new_path);
- wpa_s->dbus_new_path = NULL;
- free_dbus_object_desc(obj_desc);
- return -1;
- }
- /**
- * wpas_dbus_unregister_interface - Unregister the interface from D-Bus
- * @wpa_s: wpa_supplicant interface structure
- * Returns: 0 on success, -1 on failure
- */
- int wpas_dbus_unregister_interface(struct wpa_supplicant *wpa_s)
- {
- struct wpas_dbus_priv *ctrl_iface;
- /* Do nothing if the control interface is not turned on */
- if (wpa_s == NULL || wpa_s->global == NULL)
- return 0;
- ctrl_iface = wpa_s->global->dbus;
- if (ctrl_iface == NULL || wpa_s->dbus_new_path == NULL)
- return 0;
- wpa_printf(MSG_DEBUG, "dbus: Unregister interface object '%s'",
- wpa_s->dbus_new_path);
- #ifdef CONFIG_AP
- if (wpa_s->preq_notify_peer) {
- wpas_dbus_unsubscribe_noc(ctrl_iface);
- os_free(wpa_s->preq_notify_peer);
- wpa_s->preq_notify_peer = NULL;
- }
- #endif /* CONFIG_AP */
- if (wpa_dbus_unregister_object_per_iface(ctrl_iface,
- wpa_s->dbus_new_path))
- return -1;
- wpas_dbus_signal_interface_removed(wpa_s);
- os_free(wpa_s->dbus_new_path);
- wpa_s->dbus_new_path = NULL;
- return 0;
- }
- #ifdef CONFIG_P2P
- static const struct wpa_dbus_property_desc wpas_dbus_p2p_peer_properties[] = {
- { "DeviceName", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
- wpas_dbus_getter_p2p_peer_device_name,
- NULL
- },
- { "Manufacturer", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
- wpas_dbus_getter_p2p_peer_manufacturer,
- NULL
- },
- { "ModelName", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
- wpas_dbus_getter_p2p_peer_modelname,
- NULL
- },
- { "ModelNumber", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
- wpas_dbus_getter_p2p_peer_modelnumber,
- NULL
- },
- { "SerialNumber", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
- wpas_dbus_getter_p2p_peer_serialnumber,
- NULL
- },
- { "PrimaryDeviceType", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
- wpas_dbus_getter_p2p_peer_primary_device_type,
- NULL
- },
- { "config_method", WPAS_DBUS_NEW_IFACE_P2P_PEER, "q",
- wpas_dbus_getter_p2p_peer_config_method,
- NULL
- },
- { "level", WPAS_DBUS_NEW_IFACE_P2P_PEER, "i",
- wpas_dbus_getter_p2p_peer_level,
- NULL
- },
- { "devicecapability", WPAS_DBUS_NEW_IFACE_P2P_PEER, "y",
- wpas_dbus_getter_p2p_peer_device_capability,
- NULL
- },
- { "groupcapability", WPAS_DBUS_NEW_IFACE_P2P_PEER, "y",
- wpas_dbus_getter_p2p_peer_group_capability,
- NULL
- },
- { "SecondaryDeviceTypes", WPAS_DBUS_NEW_IFACE_P2P_PEER, "aay",
- wpas_dbus_getter_p2p_peer_secondary_device_types,
- NULL
- },
- { "VendorExtension", WPAS_DBUS_NEW_IFACE_P2P_PEER, "aay",
- wpas_dbus_getter_p2p_peer_vendor_extension,
- NULL
- },
- { "IEs", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
- wpas_dbus_getter_p2p_peer_ies,
- NULL
- },
- { "DeviceAddress", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
- wpas_dbus_getter_p2p_peer_device_address,
- NULL
- },
- { "Groups", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ao",
- wpas_dbus_getter_p2p_peer_groups,
- NULL
- },
- { NULL, NULL, NULL, NULL, NULL }
- };
- static const struct wpa_dbus_signal_desc wpas_dbus_p2p_peer_signals[] = {
- /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
- { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_P2P_PEER,
- {
- { "properties", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- { NULL, NULL, { END_ARGS } }
- };
- /**
- * wpas_dbus_signal_peer - Send a peer related event signal
- * @wpa_s: %wpa_supplicant network interface data
- * @dev: peer device object
- * @interface: name of the interface emitting this signal.
- * In case of peer objects, it would be emitted by either
- * the "interface object" or by "peer objects"
- * @sig_name: signal name - DeviceFound
- *
- * Notify listeners about event related with newly found p2p peer device
- */
- static void wpas_dbus_signal_peer(struct wpa_supplicant *wpa_s,
- const u8 *dev_addr, const char *interface,
- const char *sig_name)
- {
- struct wpas_dbus_priv *iface;
- DBusMessage *msg;
- DBusMessageIter iter;
- char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
- if (wpa_s->p2p_mgmt)
- wpa_s = wpa_s->parent;
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL || !wpa_s->dbus_new_path)
- return;
- os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
- "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
- wpa_s->dbus_new_path, MAC2STR(dev_addr));
- msg = dbus_message_new_signal(wpa_s->dbus_new_path, interface,
- sig_name);
- if (msg == NULL)
- return;
- dbus_message_iter_init_append(msg, &iter);
- path = peer_obj_path;
- if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
- &path))
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- else
- dbus_connection_send(iface->con, msg, NULL);
- dbus_message_unref(msg);
- }
- /**
- * wpas_dbus_signal_peer_found - Send a peer found signal
- * @wpa_s: %wpa_supplicant network interface data
- * @dev_addr: Peer P2P Device Address
- *
- * Notify listeners about find a p2p peer device found
- */
- void wpas_dbus_signal_peer_device_found(struct wpa_supplicant *wpa_s,
- const u8 *dev_addr)
- {
- wpas_dbus_signal_peer(wpa_s, dev_addr,
- WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- "DeviceFound");
- }
- /**
- * wpas_dbus_signal_peer_lost - Send a peer lost signal
- * @wpa_s: %wpa_supplicant network interface data
- * @dev_addr: Peer P2P Device Address
- *
- * Notify listeners about lost a p2p peer device
- */
- void wpas_dbus_signal_peer_device_lost(struct wpa_supplicant *wpa_s,
- const u8 *dev_addr)
- {
- wpas_dbus_signal_peer(wpa_s, dev_addr,
- WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- "DeviceLost");
- }
- /**
- * wpas_dbus_register_peer - Register a discovered peer object with dbus
- * @wpa_s: wpa_supplicant interface structure
- * @dev_addr: P2P Device Address of the peer
- * Returns: 0 on success, -1 on failure
- *
- * Registers network representing object with dbus
- */
- int wpas_dbus_register_peer(struct wpa_supplicant *wpa_s, const u8 *dev_addr)
- {
- struct wpas_dbus_priv *ctrl_iface;
- struct wpa_dbus_object_desc *obj_desc;
- struct peer_handler_args *arg;
- char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
- /* Do nothing if the control interface is not turned on */
- if (wpa_s == NULL || wpa_s->global == NULL)
- return 0;
- ctrl_iface = wpa_s->global->dbus;
- if (ctrl_iface == NULL)
- return 0;
- wpa_s = wpa_s->parent->parent;
- if (!wpa_s->dbus_new_path)
- return 0;
- os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
- "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
- wpa_s->dbus_new_path, MAC2STR(dev_addr));
- wpa_printf(MSG_INFO, "dbus: Register peer object '%s'",
- peer_obj_path);
- obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
- if (!obj_desc) {
- wpa_printf(MSG_ERROR,
- "Not enough memory to create object description");
- goto err;
- }
- /* allocate memory for handlers arguments */
- arg = os_zalloc(sizeof(struct peer_handler_args));
- if (!arg) {
- wpa_printf(MSG_ERROR,
- "Not enough memory to create arguments for method");
- goto err;
- }
- arg->wpa_s = wpa_s;
- os_memcpy(arg->p2p_device_addr, dev_addr, ETH_ALEN);
- wpas_dbus_register(obj_desc, arg, wpa_dbus_free,
- NULL,
- wpas_dbus_p2p_peer_properties,
- wpas_dbus_p2p_peer_signals);
- if (wpa_dbus_register_object_per_iface(ctrl_iface, peer_obj_path,
- wpa_s->ifname, obj_desc))
- goto err;
- return 0;
- err:
- free_dbus_object_desc(obj_desc);
- return -1;
- }
- /**
- * wpas_dbus_unregister_peer - Unregister a peer object with dbus
- * @wpa_s: wpa_supplicant interface structure
- * @dev_addr: p2p device addr
- * Returns: 0 on success, -1 on failure
- *
- * Registers network representing object with dbus
- */
- int wpas_dbus_unregister_peer(struct wpa_supplicant *wpa_s,
- const u8 *dev_addr)
- {
- struct wpas_dbus_priv *ctrl_iface;
- char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
- int ret;
- /* Do nothing if the control interface is not turned on */
- if (wpa_s == NULL || wpa_s->global == NULL)
- return 0;
- wpa_s = wpa_s->parent->parent;
- if (!wpa_s->dbus_new_path)
- return 0;
- ctrl_iface = wpa_s->global->dbus;
- if (ctrl_iface == NULL)
- return 0;
- os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
- "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
- wpa_s->dbus_new_path, MAC2STR(dev_addr));
- wpa_printf(MSG_INFO, "dbus: Unregister peer object '%s'",
- peer_obj_path);
- ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, peer_obj_path);
- return ret;
- }
- /**
- * wpas_dbus_signal_p2p_find_stopped - Send P2P Find stopped signal
- * @wpa_s: %wpa_supplicant network interface data
- *
- * Notify listeners about P2P Find stopped
- */
- void wpas_dbus_signal_p2p_find_stopped(struct wpa_supplicant *wpa_s)
- {
- struct wpas_dbus_priv *iface;
- DBusMessage *msg;
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL || !wpa_s->dbus_new_path)
- return;
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_P2PDEVICE,
- "FindStopped");
- if (msg == NULL)
- return;
- dbus_connection_send(iface->con, msg, NULL);
- dbus_message_unref(msg);
- }
- /**
- * wpas_dbus_signal_peer_groups_changed - Send peer group change property signal
- * @wpa_s: %wpa_supplicant network interface data
- * @dev_addr: P2P Device Address
- *
- * Notify listeners about peer Groups property changes.
- */
- void wpas_dbus_signal_peer_groups_changed(struct wpa_supplicant *wpa_s,
- const u8 *dev_addr)
- {
- char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
- if (wpa_s->p2p_mgmt)
- wpa_s = wpa_s->parent;
- if (!wpa_s->dbus_new_path)
- return;
- os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
- "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
- wpa_s->dbus_new_path, MAC2STR(dev_addr));
- wpa_dbus_mark_property_changed(wpa_s->global->dbus, peer_obj_path,
- WPAS_DBUS_NEW_IFACE_P2P_PEER, "Groups");
- }
- static const struct wpa_dbus_property_desc wpas_dbus_p2p_group_properties[] = {
- { "Members", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ao",
- wpas_dbus_getter_p2p_group_members,
- NULL
- },
- { "Group", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "o",
- wpas_dbus_getter_p2p_group,
- NULL
- },
- { "Role", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "s",
- wpas_dbus_getter_p2p_role,
- NULL
- },
- { "SSID", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
- wpas_dbus_getter_p2p_group_ssid,
- NULL
- },
- { "BSSID", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
- wpas_dbus_getter_p2p_group_bssid,
- NULL
- },
- { "Frequency", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "q",
- wpas_dbus_getter_p2p_group_frequency,
- NULL
- },
- { "Passphrase", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "s",
- wpas_dbus_getter_p2p_group_passphrase,
- NULL
- },
- { "PSK", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
- wpas_dbus_getter_p2p_group_psk,
- NULL
- },
- { "WPSVendorExtensions", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "aay",
- wpas_dbus_getter_p2p_group_vendor_ext,
- wpas_dbus_setter_p2p_group_vendor_ext
- },
- { NULL, NULL, NULL, NULL, NULL }
- };
- static const struct wpa_dbus_signal_desc wpas_dbus_p2p_group_signals[] = {
- { "PeerJoined", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
- {
- { "peer", "o", ARG_OUT },
- END_ARGS
- }
- },
- { "PeerDisconnected", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
- {
- { "peer", "o", ARG_OUT },
- END_ARGS
- }
- },
- { NULL, NULL, { END_ARGS } }
- };
- /**
- * wpas_dbus_register_p2p_group - Register a p2p group object with dbus
- * @wpa_s: wpa_supplicant interface structure
- * @ssid: SSID struct
- * Returns: 0 on success, -1 on failure
- *
- * Registers p2p group representing object with dbus
- */
- void wpas_dbus_register_p2p_group(struct wpa_supplicant *wpa_s,
- struct wpa_ssid *ssid)
- {
- struct wpas_dbus_priv *ctrl_iface;
- struct wpa_dbus_object_desc *obj_desc;
- char group_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
- /* Do nothing if the control interface is not turned on */
- if (wpa_s == NULL || wpa_s->global == NULL)
- return;
- ctrl_iface = wpa_s->global->dbus;
- if (ctrl_iface == NULL)
- return;
- if (wpa_s->dbus_groupobj_path) {
- wpa_printf(MSG_INFO, "%s: Group object '%s' already exists",
- __func__, wpa_s->dbus_groupobj_path);
- return;
- }
- if (wpas_dbus_get_group_obj_path(wpa_s, ssid, group_obj_path) < 0)
- return;
- wpa_s->dbus_groupobj_path = os_strdup(group_obj_path);
- if (wpa_s->dbus_groupobj_path == NULL)
- return;
- wpa_printf(MSG_INFO, "dbus: Register group object '%s'",
- group_obj_path);
- obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
- if (!obj_desc) {
- wpa_printf(MSG_ERROR,
- "Not enough memory to create object description");
- goto err;
- }
- wpas_dbus_register(obj_desc, wpa_s, NULL, NULL,
- wpas_dbus_p2p_group_properties,
- wpas_dbus_p2p_group_signals);
- if (wpa_dbus_register_object_per_iface(ctrl_iface, group_obj_path,
- wpa_s->ifname, obj_desc))
- goto err;
- return;
- err:
- if (wpa_s->dbus_groupobj_path) {
- os_free(wpa_s->dbus_groupobj_path);
- wpa_s->dbus_groupobj_path = NULL;
- }
- free_dbus_object_desc(obj_desc);
- }
- /**
- * wpas_dbus_unregister_p2p_group - Unregister a p2p group object from dbus
- * @wpa_s: wpa_supplicant interface structure
- * @ssid: network name of the p2p group started
- */
- void wpas_dbus_unregister_p2p_group(struct wpa_supplicant *wpa_s,
- const struct wpa_ssid *ssid)
- {
- struct wpas_dbus_priv *ctrl_iface;
- /* Do nothing if the control interface is not turned on */
- if (wpa_s == NULL || wpa_s->global == NULL)
- return;
- if (wpa_s->p2p_mgmt)
- wpa_s = wpa_s->parent;
- ctrl_iface = wpa_s->global->dbus;
- if (ctrl_iface == NULL)
- return;
- if (!wpa_s->dbus_groupobj_path) {
- wpa_printf(MSG_DEBUG,
- "%s: Group object '%s' already unregistered",
- __func__, wpa_s->dbus_groupobj_path);
- return;
- }
- peer_groups_changed(wpa_s);
- wpa_printf(MSG_DEBUG, "dbus: Unregister group object '%s'",
- wpa_s->dbus_groupobj_path);
- wpa_dbus_unregister_object_per_iface(ctrl_iface,
- wpa_s->dbus_groupobj_path);
- os_free(wpa_s->dbus_groupobj_path);
- wpa_s->dbus_groupobj_path = NULL;
- }
- static const struct wpa_dbus_property_desc
- wpas_dbus_persistent_group_properties[] = {
- { "Properties", WPAS_DBUS_NEW_IFACE_PERSISTENT_GROUP, "a{sv}",
- wpas_dbus_getter_persistent_group_properties,
- wpas_dbus_setter_persistent_group_properties
- },
- { NULL, NULL, NULL, NULL, NULL }
- };
- /* No signals intended for persistent group objects */
- /**
- * wpas_dbus_register_persistent_group - Register a configured(saved)
- * persistent group with dbus
- * @wpa_s: wpa_supplicant interface structure
- * @ssid: persistent group (still represented as a network within wpa)
- * configuration data
- * Returns: 0 on success, -1 on failure
- *
- * Registers a persistent group representing object with dbus.
- */
- int wpas_dbus_register_persistent_group(struct wpa_supplicant *wpa_s,
- struct wpa_ssid *ssid)
- {
- struct wpas_dbus_priv *ctrl_iface;
- struct wpa_dbus_object_desc *obj_desc;
- struct network_handler_args *arg;
- char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
- /* Do nothing if the control interface is not turned on */
- if (wpa_s == NULL || wpa_s->global == NULL)
- return 0;
- wpa_s = wpa_s->parent->parent;
- if (!wpa_s->dbus_new_path)
- return 0;
- /* Make sure ssid is a persistent group */
- if (ssid->disabled != 2 && !ssid->p2p_persistent_group)
- return -1; /* should we return w/o complaining? */
- if (wpa_s->p2p_mgmt)
- wpa_s = wpa_s->parent;
- ctrl_iface = wpa_s->global->dbus;
- if (ctrl_iface == NULL)
- return 0;
- /*
- * Intentionally not coming up with different numbering scheme
- * for persistent groups.
- */
- os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
- "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
- wpa_s->dbus_new_path, ssid->id);
- wpa_printf(MSG_DEBUG, "dbus: Register persistent group object '%s'",
- pgrp_obj_path);
- obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
- if (!obj_desc) {
- wpa_printf(MSG_ERROR,
- "dbus: Not enough memory to create object description");
- goto err;
- }
- /*
- * Reusing the same context structure as that for networks
- * since these are represented using same data structure.
- */
- /* allocate memory for handlers arguments */
- arg = os_zalloc(sizeof(struct network_handler_args));
- if (!arg) {
- wpa_printf(MSG_ERROR,
- "dbus: Not enough memory to create arguments for method");
- goto err;
- }
- arg->wpa_s = wpa_s;
- arg->ssid = ssid;
- wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
- wpas_dbus_persistent_group_properties,
- NULL);
- if (wpa_dbus_register_object_per_iface(ctrl_iface, pgrp_obj_path,
- wpa_s->ifname, obj_desc))
- goto err;
- wpas_dbus_signal_persistent_group_added(wpa_s, ssid->id);
- return 0;
- err:
- free_dbus_object_desc(obj_desc);
- return -1;
- }
- /**
- * wpas_dbus_unregister_persistent_group - Unregister a persistent_group
- * from dbus
- * @wpa_s: wpa_supplicant interface structure
- * @nid: network id
- * Returns: 0 on success, -1 on failure
- *
- * Unregisters persistent group representing object from dbus
- *
- * NOTE: There is a slight issue with the semantics here. While the
- * implementation simply means the persistent group is unloaded from memory,
- * it should not get interpreted as the group is actually being erased/removed
- * from persistent storage as well.
- */
- int wpas_dbus_unregister_persistent_group(struct wpa_supplicant *wpa_s,
- int nid)
- {
- struct wpas_dbus_priv *ctrl_iface;
- char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
- int ret;
- /* Do nothing if the control interface is not turned on */
- if (wpa_s == NULL || wpa_s->global == NULL)
- return 0;
- wpa_s = wpa_s->parent->parent;
- ctrl_iface = wpa_s->global->dbus;
- if (ctrl_iface == NULL || !wpa_s->dbus_new_path)
- return 0;
- os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
- "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
- wpa_s->dbus_new_path, nid);
- wpa_printf(MSG_DEBUG, "dbus: Unregister persistent group object '%s'",
- pgrp_obj_path);
- ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, pgrp_obj_path);
- if (!ret)
- wpas_dbus_signal_persistent_group_removed(wpa_s, nid);
- return ret;
- }
- #endif /* CONFIG_P2P */
|