dbus_new.c 106 KB

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