dbus_new.c 118 KB

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