dbus_new.c 120 KB

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