dbus_new.c 112 KB

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