dbus_new.c 115 KB

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