dbus_new.c 95 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686
  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 program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * Alternatively, this software may be distributed under the terms of BSD
  12. * license.
  13. *
  14. * See README and COPYING for more details.
  15. */
  16. #include "includes.h"
  17. #include "common.h"
  18. #include "common/ieee802_11_defs.h"
  19. #include "wps/wps.h"
  20. #include "../config.h"
  21. #include "../wpa_supplicant_i.h"
  22. #include "../bss.h"
  23. #include "../wpas_glue.h"
  24. #include "dbus_new_helpers.h"
  25. #include "dbus_dict_helpers.h"
  26. #include "dbus_new.h"
  27. #include "dbus_new_handlers.h"
  28. #include "dbus_common_i.h"
  29. #include "dbus_new_handlers_p2p.h"
  30. #include "p2p/p2p.h"
  31. #ifdef CONFIG_AP /* until needed by something else */
  32. /*
  33. * NameOwnerChanged handling
  34. *
  35. * Some services we provide allow an application to register for
  36. * a signal that it needs. While it can also unregister, we must
  37. * be prepared for the case where the application simply crashes
  38. * and thus doesn't clean up properly. The way to handle this in
  39. * DBus is to register for the NameOwnerChanged signal which will
  40. * signal an owner change to NULL if the peer closes the socket
  41. * for whatever reason.
  42. *
  43. * Handle this signal via a filter function whenever necessary.
  44. * The code below also handles refcounting in case in the future
  45. * there will be multiple instances of this subscription scheme.
  46. */
  47. static const char wpas_dbus_noc_filter_str[] =
  48. "interface=org.freedesktop.DBus,member=NameOwnerChanged";
  49. static DBusHandlerResult noc_filter(DBusConnection *conn,
  50. DBusMessage *message, void *data)
  51. {
  52. struct wpas_dbus_priv *priv = data;
  53. if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_SIGNAL)
  54. return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
  55. if (dbus_message_is_signal(message, DBUS_INTERFACE_DBUS,
  56. "NameOwnerChanged")) {
  57. const char *name;
  58. const char *prev_owner;
  59. const char *new_owner;
  60. DBusError derr;
  61. struct wpa_supplicant *wpa_s;
  62. dbus_error_init(&derr);
  63. if (!dbus_message_get_args(message, &derr,
  64. DBUS_TYPE_STRING, &name,
  65. DBUS_TYPE_STRING, &prev_owner,
  66. DBUS_TYPE_STRING, &new_owner,
  67. DBUS_TYPE_INVALID)) {
  68. /* Ignore this error */
  69. dbus_error_free(&derr);
  70. return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
  71. }
  72. for (wpa_s = priv->global->ifaces; wpa_s; wpa_s = wpa_s->next)
  73. {
  74. if (wpa_s->preq_notify_peer != NULL &&
  75. os_strcmp(name, wpa_s->preq_notify_peer) == 0 &&
  76. (new_owner == NULL || os_strlen(new_owner) == 0)) {
  77. /* probe request owner disconnected */
  78. os_free(wpa_s->preq_notify_peer);
  79. wpa_s->preq_notify_peer = NULL;
  80. wpas_dbus_unsubscribe_noc(priv);
  81. }
  82. }
  83. }
  84. return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
  85. }
  86. void wpas_dbus_subscribe_noc(struct wpas_dbus_priv *priv)
  87. {
  88. priv->dbus_noc_refcnt++;
  89. if (priv->dbus_noc_refcnt > 1)
  90. return;
  91. if (!dbus_connection_add_filter(priv->con, noc_filter, priv, NULL)) {
  92. wpa_printf(MSG_ERROR, "dbus: failed to add filter");
  93. return;
  94. }
  95. dbus_bus_add_match(priv->con, wpas_dbus_noc_filter_str, NULL);
  96. }
  97. void wpas_dbus_unsubscribe_noc(struct wpas_dbus_priv *priv)
  98. {
  99. priv->dbus_noc_refcnt--;
  100. if (priv->dbus_noc_refcnt > 0)
  101. return;
  102. dbus_bus_remove_match(priv->con, wpas_dbus_noc_filter_str, NULL);
  103. dbus_connection_remove_filter(priv->con, noc_filter, priv);
  104. }
  105. #endif /* CONFIG_AP */
  106. /**
  107. * wpas_dbus_signal_interface - Send a interface related event signal
  108. * @wpa_s: %wpa_supplicant network interface data
  109. * @sig_name: signal name - InterfaceAdded or InterfaceRemoved
  110. * @properties: Whether to add second argument with object properties
  111. *
  112. * Notify listeners about event related with interface
  113. */
  114. static void wpas_dbus_signal_interface(struct wpa_supplicant *wpa_s,
  115. const char *sig_name, int properties)
  116. {
  117. struct wpas_dbus_priv *iface;
  118. DBusMessage *msg;
  119. DBusMessageIter iter;
  120. iface = wpa_s->global->dbus;
  121. /* Do nothing if the control interface is not turned on */
  122. if (iface == NULL)
  123. return;
  124. msg = dbus_message_new_signal(WPAS_DBUS_NEW_PATH,
  125. WPAS_DBUS_NEW_INTERFACE, sig_name);
  126. if (msg == NULL)
  127. return;
  128. dbus_message_iter_init_append(msg, &iter);
  129. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  130. &wpa_s->dbus_new_path))
  131. goto err;
  132. if (properties) {
  133. if (!wpa_dbus_get_object_properties(
  134. iface, wpa_s->dbus_new_path,
  135. WPAS_DBUS_NEW_IFACE_INTERFACE, &iter))
  136. goto err;
  137. }
  138. dbus_connection_send(iface->con, msg, NULL);
  139. dbus_message_unref(msg);
  140. return;
  141. err:
  142. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  143. dbus_message_unref(msg);
  144. }
  145. /**
  146. * wpas_dbus_signal_interface_added - Send a interface created signal
  147. * @wpa_s: %wpa_supplicant network interface data
  148. *
  149. * Notify listeners about creating new interface
  150. */
  151. static void wpas_dbus_signal_interface_added(struct wpa_supplicant *wpa_s)
  152. {
  153. wpas_dbus_signal_interface(wpa_s, "InterfaceAdded", TRUE);
  154. }
  155. /**
  156. * wpas_dbus_signal_interface_removed - Send a interface removed signal
  157. * @wpa_s: %wpa_supplicant network interface data
  158. *
  159. * Notify listeners about removing interface
  160. */
  161. static void wpas_dbus_signal_interface_removed(struct wpa_supplicant *wpa_s)
  162. {
  163. wpas_dbus_signal_interface(wpa_s, "InterfaceRemoved", FALSE);
  164. }
  165. /**
  166. * wpas_dbus_signal_scan_done - send scan done signal
  167. * @wpa_s: %wpa_supplicant network interface data
  168. * @success: indicates if scanning succeed or failed
  169. *
  170. * Notify listeners about finishing a scan
  171. */
  172. void wpas_dbus_signal_scan_done(struct wpa_supplicant *wpa_s, int success)
  173. {
  174. struct wpas_dbus_priv *iface;
  175. DBusMessage *msg;
  176. dbus_bool_t succ;
  177. iface = wpa_s->global->dbus;
  178. /* Do nothing if the control interface is not turned on */
  179. if (iface == NULL)
  180. return;
  181. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  182. WPAS_DBUS_NEW_IFACE_INTERFACE,
  183. "ScanDone");
  184. if (msg == NULL)
  185. return;
  186. succ = success ? TRUE : FALSE;
  187. if (dbus_message_append_args(msg, DBUS_TYPE_BOOLEAN, &succ,
  188. DBUS_TYPE_INVALID))
  189. dbus_connection_send(iface->con, msg, NULL);
  190. else
  191. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  192. dbus_message_unref(msg);
  193. }
  194. /**
  195. * wpas_dbus_signal_blob - Send a BSS related event signal
  196. * @wpa_s: %wpa_supplicant network interface data
  197. * @bss_obj_path: BSS object path
  198. * @sig_name: signal name - BSSAdded or BSSRemoved
  199. * @properties: Whether to add second argument with object properties
  200. *
  201. * Notify listeners about event related with BSS
  202. */
  203. static void wpas_dbus_signal_bss(struct wpa_supplicant *wpa_s,
  204. const char *bss_obj_path,
  205. const char *sig_name, int properties)
  206. {
  207. struct wpas_dbus_priv *iface;
  208. DBusMessage *msg;
  209. DBusMessageIter iter;
  210. iface = wpa_s->global->dbus;
  211. /* Do nothing if the control interface is not turned on */
  212. if (iface == NULL)
  213. return;
  214. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  215. WPAS_DBUS_NEW_IFACE_INTERFACE,
  216. sig_name);
  217. if (msg == NULL)
  218. return;
  219. dbus_message_iter_init_append(msg, &iter);
  220. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  221. &bss_obj_path))
  222. goto err;
  223. if (properties) {
  224. if (!wpa_dbus_get_object_properties(iface, bss_obj_path,
  225. WPAS_DBUS_NEW_IFACE_BSS,
  226. &iter))
  227. goto err;
  228. }
  229. dbus_connection_send(iface->con, msg, NULL);
  230. dbus_message_unref(msg);
  231. return;
  232. err:
  233. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  234. dbus_message_unref(msg);
  235. }
  236. /**
  237. * wpas_dbus_signal_bss_added - Send a BSS added signal
  238. * @wpa_s: %wpa_supplicant network interface data
  239. * @bss_obj_path: new BSS object path
  240. *
  241. * Notify listeners about adding new BSS
  242. */
  243. static void wpas_dbus_signal_bss_added(struct wpa_supplicant *wpa_s,
  244. const char *bss_obj_path)
  245. {
  246. wpas_dbus_signal_bss(wpa_s, bss_obj_path, "BSSAdded", TRUE);
  247. }
  248. /**
  249. * wpas_dbus_signal_bss_removed - Send a BSS removed signal
  250. * @wpa_s: %wpa_supplicant network interface data
  251. * @bss_obj_path: BSS object path
  252. *
  253. * Notify listeners about removing BSS
  254. */
  255. static void wpas_dbus_signal_bss_removed(struct wpa_supplicant *wpa_s,
  256. const char *bss_obj_path)
  257. {
  258. wpas_dbus_signal_bss(wpa_s, bss_obj_path, "BSSRemoved", FALSE);
  259. }
  260. /**
  261. * wpas_dbus_signal_blob - Send a blob related event signal
  262. * @wpa_s: %wpa_supplicant network interface data
  263. * @name: blob name
  264. * @sig_name: signal name - BlobAdded or BlobRemoved
  265. *
  266. * Notify listeners about event related with blob
  267. */
  268. static void wpas_dbus_signal_blob(struct wpa_supplicant *wpa_s,
  269. const char *name, const char *sig_name)
  270. {
  271. struct wpas_dbus_priv *iface;
  272. DBusMessage *msg;
  273. iface = wpa_s->global->dbus;
  274. /* Do nothing if the control interface is not turned on */
  275. if (iface == NULL)
  276. return;
  277. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  278. WPAS_DBUS_NEW_IFACE_INTERFACE,
  279. sig_name);
  280. if (msg == NULL)
  281. return;
  282. if (dbus_message_append_args(msg, DBUS_TYPE_STRING, &name,
  283. DBUS_TYPE_INVALID))
  284. dbus_connection_send(iface->con, msg, NULL);
  285. else
  286. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  287. dbus_message_unref(msg);
  288. }
  289. /**
  290. * wpas_dbus_signal_blob_added - Send a blob added signal
  291. * @wpa_s: %wpa_supplicant network interface data
  292. * @name: blob name
  293. *
  294. * Notify listeners about adding a new blob
  295. */
  296. void wpas_dbus_signal_blob_added(struct wpa_supplicant *wpa_s,
  297. const char *name)
  298. {
  299. wpas_dbus_signal_blob(wpa_s, name, "BlobAdded");
  300. }
  301. /**
  302. * wpas_dbus_signal_blob_removed - Send a blob removed signal
  303. * @wpa_s: %wpa_supplicant network interface data
  304. * @name: blob name
  305. *
  306. * Notify listeners about removing blob
  307. */
  308. void wpas_dbus_signal_blob_removed(struct wpa_supplicant *wpa_s,
  309. const char *name)
  310. {
  311. wpas_dbus_signal_blob(wpa_s, name, "BlobRemoved");
  312. }
  313. /**
  314. * wpas_dbus_signal_network - Send a network related event signal
  315. * @wpa_s: %wpa_supplicant network interface data
  316. * @id: new network id
  317. * @sig_name: signal name - NetworkAdded, NetworkRemoved or NetworkSelected
  318. * @properties: determines if add second argument with object properties
  319. *
  320. * Notify listeners about event related with configured network
  321. */
  322. static void wpas_dbus_signal_network(struct wpa_supplicant *wpa_s,
  323. int id, const char *sig_name,
  324. int properties)
  325. {
  326. struct wpas_dbus_priv *iface;
  327. DBusMessage *msg;
  328. DBusMessageIter iter;
  329. char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  330. iface = wpa_s->global->dbus;
  331. /* Do nothing if the control interface is not turned on */
  332. if (iface == NULL)
  333. return;
  334. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  335. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  336. wpa_s->dbus_new_path, id);
  337. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  338. WPAS_DBUS_NEW_IFACE_INTERFACE,
  339. sig_name);
  340. if (msg == NULL)
  341. return;
  342. dbus_message_iter_init_append(msg, &iter);
  343. path = net_obj_path;
  344. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  345. &path))
  346. goto err;
  347. if (properties) {
  348. if (!wpa_dbus_get_object_properties(
  349. iface, net_obj_path, WPAS_DBUS_NEW_IFACE_NETWORK,
  350. &iter))
  351. goto err;
  352. }
  353. dbus_connection_send(iface->con, msg, NULL);
  354. dbus_message_unref(msg);
  355. return;
  356. err:
  357. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  358. dbus_message_unref(msg);
  359. }
  360. /**
  361. * wpas_dbus_signal_network_added - Send a network added signal
  362. * @wpa_s: %wpa_supplicant network interface data
  363. * @id: new network id
  364. *
  365. * Notify listeners about adding new network
  366. */
  367. static void wpas_dbus_signal_network_added(struct wpa_supplicant *wpa_s,
  368. int id)
  369. {
  370. wpas_dbus_signal_network(wpa_s, id, "NetworkAdded", TRUE);
  371. }
  372. /**
  373. * wpas_dbus_signal_network_removed - Send a network removed signal
  374. * @wpa_s: %wpa_supplicant network interface data
  375. * @id: network id
  376. *
  377. * Notify listeners about removing a network
  378. */
  379. static void wpas_dbus_signal_network_removed(struct wpa_supplicant *wpa_s,
  380. int id)
  381. {
  382. wpas_dbus_signal_network(wpa_s, id, "NetworkRemoved", FALSE);
  383. }
  384. /**
  385. * wpas_dbus_signal_network_selected - Send a network selected signal
  386. * @wpa_s: %wpa_supplicant network interface data
  387. * @id: network id
  388. *
  389. * Notify listeners about selecting a network
  390. */
  391. void wpas_dbus_signal_network_selected(struct wpa_supplicant *wpa_s, int id)
  392. {
  393. wpas_dbus_signal_network(wpa_s, id, "NetworkSelected", FALSE);
  394. }
  395. /**
  396. * wpas_dbus_signal_network_request - Indicate that additional information
  397. * (EAP password, etc.) is required to complete the association to this SSID
  398. * @wpa_s: %wpa_supplicant network interface data
  399. * @rtype: The specific additional information required
  400. * @default_text: Optional description of required information
  401. *
  402. * Request additional information or passwords to complete an association
  403. * request.
  404. */
  405. void wpas_dbus_signal_network_request(struct wpa_supplicant *wpa_s,
  406. struct wpa_ssid *ssid,
  407. enum wpa_ctrl_req_type rtype,
  408. const char *default_txt)
  409. {
  410. struct wpas_dbus_priv *iface;
  411. DBusMessage *msg;
  412. DBusMessageIter iter;
  413. char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  414. const char *field, *txt = NULL, *net_ptr;
  415. iface = wpa_s->global->dbus;
  416. /* Do nothing if the control interface is not turned on */
  417. if (iface == NULL)
  418. return;
  419. field = wpa_supplicant_ctrl_req_to_string(rtype, default_txt, &txt);
  420. if (field == NULL)
  421. return;
  422. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  423. WPAS_DBUS_NEW_IFACE_INTERFACE,
  424. "NetworkRequest");
  425. if (msg == NULL)
  426. return;
  427. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  428. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  429. wpa_s->dbus_new_path, ssid->id);
  430. net_ptr = &net_obj_path[0];
  431. dbus_message_iter_init_append(msg, &iter);
  432. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  433. &net_ptr))
  434. goto err;
  435. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &field))
  436. goto err;
  437. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &txt))
  438. goto err;
  439. dbus_connection_send(iface->con, msg, NULL);
  440. dbus_message_unref(msg);
  441. return;
  442. err:
  443. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  444. dbus_message_unref(msg);
  445. }
  446. /**
  447. * wpas_dbus_signal_network_enabled_changed - Signals Enabled property changes
  448. * @wpa_s: %wpa_supplicant network interface data
  449. * @ssid: configured network which Enabled property has changed
  450. *
  451. * Sends PropertyChanged signals containing new value of Enabled property
  452. * for specified network
  453. */
  454. void wpas_dbus_signal_network_enabled_changed(struct wpa_supplicant *wpa_s,
  455. struct wpa_ssid *ssid)
  456. {
  457. char path[WPAS_DBUS_OBJECT_PATH_MAX];
  458. os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
  459. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
  460. wpa_s->dbus_new_path, ssid->id);
  461. wpa_dbus_mark_property_changed(wpa_s->global->dbus, path,
  462. WPAS_DBUS_NEW_IFACE_NETWORK, "Enabled");
  463. }
  464. #ifdef CONFIG_WPS
  465. /**
  466. * wpas_dbus_signal_wps_event_success - Signals Success WPS event
  467. * @wpa_s: %wpa_supplicant network interface data
  468. *
  469. * Sends Event dbus signal with name "success" and empty dict as arguments
  470. */
  471. void wpas_dbus_signal_wps_event_success(struct wpa_supplicant *wpa_s)
  472. {
  473. DBusMessage *msg;
  474. DBusMessageIter iter, dict_iter;
  475. struct wpas_dbus_priv *iface;
  476. char *key = "success";
  477. iface = wpa_s->global->dbus;
  478. /* Do nothing if the control interface is not turned on */
  479. if (iface == NULL)
  480. return;
  481. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  482. WPAS_DBUS_NEW_IFACE_WPS, "Event");
  483. if (msg == NULL)
  484. return;
  485. dbus_message_iter_init_append(msg, &iter);
  486. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
  487. !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  488. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  489. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  490. else
  491. dbus_connection_send(iface->con, msg, NULL);
  492. dbus_message_unref(msg);
  493. }
  494. /**
  495. * wpas_dbus_signal_wps_event_fail - Signals Fail WPS event
  496. * @wpa_s: %wpa_supplicant network interface data
  497. *
  498. * Sends Event dbus signal with name "fail" and dictionary containing
  499. * "msg field with fail message number (int32) as arguments
  500. */
  501. void wpas_dbus_signal_wps_event_fail(struct wpa_supplicant *wpa_s,
  502. struct wps_event_fail *fail)
  503. {
  504. DBusMessage *msg;
  505. DBusMessageIter iter, dict_iter;
  506. struct wpas_dbus_priv *iface;
  507. char *key = "fail";
  508. iface = wpa_s->global->dbus;
  509. /* Do nothing if the control interface is not turned on */
  510. if (iface == NULL)
  511. return;
  512. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  513. WPAS_DBUS_NEW_IFACE_WPS, "Event");
  514. if (msg == NULL)
  515. return;
  516. dbus_message_iter_init_append(msg, &iter);
  517. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
  518. !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  519. !wpa_dbus_dict_append_int32(&dict_iter, "msg", fail->msg) ||
  520. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  521. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  522. else
  523. dbus_connection_send(iface->con, msg, NULL);
  524. dbus_message_unref(msg);
  525. }
  526. /**
  527. * wpas_dbus_signal_wps_event_m2d - Signals M2D WPS event
  528. * @wpa_s: %wpa_supplicant network interface data
  529. *
  530. * Sends Event dbus signal with name "m2d" and dictionary containing
  531. * fields of wps_event_m2d structure.
  532. */
  533. void wpas_dbus_signal_wps_event_m2d(struct wpa_supplicant *wpa_s,
  534. struct wps_event_m2d *m2d)
  535. {
  536. DBusMessage *msg;
  537. DBusMessageIter iter, dict_iter;
  538. struct wpas_dbus_priv *iface;
  539. char *key = "m2d";
  540. iface = wpa_s->global->dbus;
  541. /* Do nothing if the control interface is not turned on */
  542. if (iface == NULL)
  543. return;
  544. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  545. WPAS_DBUS_NEW_IFACE_WPS, "Event");
  546. if (msg == NULL)
  547. return;
  548. dbus_message_iter_init_append(msg, &iter);
  549. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
  550. !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  551. !wpa_dbus_dict_append_uint16(&dict_iter, "config_methods",
  552. m2d->config_methods) ||
  553. !wpa_dbus_dict_append_byte_array(&dict_iter, "manufacturer",
  554. (const char *) m2d->manufacturer,
  555. m2d->manufacturer_len) ||
  556. !wpa_dbus_dict_append_byte_array(&dict_iter, "model_name",
  557. (const char *) m2d->model_name,
  558. m2d->model_name_len) ||
  559. !wpa_dbus_dict_append_byte_array(&dict_iter, "model_number",
  560. (const char *) m2d->model_number,
  561. m2d->model_number_len) ||
  562. !wpa_dbus_dict_append_byte_array(&dict_iter, "serial_number",
  563. (const char *)
  564. m2d->serial_number,
  565. m2d->serial_number_len) ||
  566. !wpa_dbus_dict_append_byte_array(&dict_iter, "dev_name",
  567. (const char *) m2d->dev_name,
  568. m2d->dev_name_len) ||
  569. !wpa_dbus_dict_append_byte_array(&dict_iter, "primary_dev_type",
  570. (const char *)
  571. m2d->primary_dev_type, 8) ||
  572. !wpa_dbus_dict_append_uint16(&dict_iter, "config_error",
  573. m2d->config_error) ||
  574. !wpa_dbus_dict_append_uint16(&dict_iter, "dev_password_id",
  575. m2d->dev_password_id) ||
  576. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  577. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  578. else
  579. dbus_connection_send(iface->con, msg, NULL);
  580. dbus_message_unref(msg);
  581. }
  582. /**
  583. * wpas_dbus_signal_wps_cred - Signals new credentials
  584. * @wpa_s: %wpa_supplicant network interface data
  585. *
  586. * Sends signal with credentials in directory argument
  587. */
  588. void wpas_dbus_signal_wps_cred(struct wpa_supplicant *wpa_s,
  589. const struct wps_credential *cred)
  590. {
  591. DBusMessage *msg;
  592. DBusMessageIter iter, dict_iter;
  593. struct wpas_dbus_priv *iface;
  594. char *auth_type[6]; /* we have six possible authorization types */
  595. int at_num = 0;
  596. char *encr_type[4]; /* we have four possible encryption types */
  597. int et_num = 0;
  598. iface = wpa_s->global->dbus;
  599. /* Do nothing if the control interface is not turned on */
  600. if (iface == NULL)
  601. return;
  602. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  603. WPAS_DBUS_NEW_IFACE_WPS,
  604. "Credentials");
  605. if (msg == NULL)
  606. return;
  607. dbus_message_iter_init_append(msg, &iter);
  608. if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
  609. goto nomem;
  610. if (cred->auth_type & WPS_AUTH_OPEN)
  611. auth_type[at_num++] = "open";
  612. if (cred->auth_type & WPS_AUTH_WPAPSK)
  613. auth_type[at_num++] = "wpa-psk";
  614. if (cred->auth_type & WPS_AUTH_SHARED)
  615. auth_type[at_num++] = "shared";
  616. if (cred->auth_type & WPS_AUTH_WPA)
  617. auth_type[at_num++] = "wpa-eap";
  618. if (cred->auth_type & WPS_AUTH_WPA2)
  619. auth_type[at_num++] = "wpa2-eap";
  620. if (cred->auth_type & WPS_AUTH_WPA2PSK)
  621. auth_type[at_num++] =
  622. "wpa2-psk";
  623. if (cred->encr_type & WPS_ENCR_NONE)
  624. encr_type[et_num++] = "none";
  625. if (cred->encr_type & WPS_ENCR_WEP)
  626. encr_type[et_num++] = "wep";
  627. if (cred->encr_type & WPS_ENCR_TKIP)
  628. encr_type[et_num++] = "tkip";
  629. if (cred->encr_type & WPS_ENCR_AES)
  630. encr_type[et_num++] = "aes";
  631. if (wpa_s->current_ssid) {
  632. if (!wpa_dbus_dict_append_byte_array(
  633. &dict_iter, "BSSID",
  634. (const char *) wpa_s->current_ssid->bssid,
  635. ETH_ALEN))
  636. goto nomem;
  637. }
  638. if (!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 *cert_hash,
  662. const struct wpabuf *cert)
  663. {
  664. struct wpas_dbus_priv *iface;
  665. DBusMessage *msg;
  666. DBusMessageIter iter, dict_iter;
  667. iface = wpa_s->global->dbus;
  668. /* Do nothing if the control interface is not turned on */
  669. if (iface == NULL)
  670. return;
  671. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  672. WPAS_DBUS_NEW_IFACE_INTERFACE,
  673. "Certification");
  674. if (msg == NULL)
  675. return;
  676. dbus_message_iter_init_append(msg, &iter);
  677. if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
  678. goto nomem;
  679. if (!wpa_dbus_dict_append_uint32(&dict_iter, "depth", depth) ||
  680. !wpa_dbus_dict_append_string(&dict_iter, "subject", subject))
  681. goto nomem;
  682. if (cert_hash &&
  683. !wpa_dbus_dict_append_string(&dict_iter, "cert_hash", cert_hash))
  684. goto nomem;
  685. if (cert &&
  686. !wpa_dbus_dict_append_byte_array(&dict_iter, "cert",
  687. wpabuf_head(cert),
  688. wpabuf_len(cert)))
  689. goto nomem;
  690. if (!wpa_dbus_dict_close_write(&iter, &dict_iter))
  691. goto nomem;
  692. dbus_connection_send(iface->con, msg, NULL);
  693. nomem:
  694. dbus_message_unref(msg);
  695. }
  696. void wpas_dbus_signal_eap_status(struct wpa_supplicant *wpa_s,
  697. const char *status, const char *parameter)
  698. {
  699. struct wpas_dbus_priv *iface;
  700. DBusMessage *msg;
  701. DBusMessageIter iter;
  702. iface = wpa_s->global->dbus;
  703. /* Do nothing if the control interface is not turned on */
  704. if (iface == NULL)
  705. return;
  706. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  707. WPAS_DBUS_NEW_IFACE_INTERFACE,
  708. "EAP");
  709. if (msg == NULL)
  710. return;
  711. dbus_message_iter_init_append(msg, &iter);
  712. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &status)
  713. ||
  714. !dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING,
  715. &parameter))
  716. goto nomem;
  717. dbus_connection_send(iface->con, msg, NULL);
  718. nomem:
  719. dbus_message_unref(msg);
  720. }
  721. #ifdef CONFIG_P2P
  722. /**
  723. * wpas_dbus_signal_p2p_group_removed - Signals P2P group was removed
  724. * @wpa_s: %wpa_supplicant network interface data
  725. * @role: role of this device (client or GO)
  726. * Sends signal with i/f name and role as string arguments
  727. */
  728. void wpas_dbus_signal_p2p_group_removed(struct wpa_supplicant *wpa_s,
  729. const char *role)
  730. {
  731. DBusMessage *msg;
  732. DBusMessageIter iter;
  733. struct wpas_dbus_priv *iface = wpa_s->global->dbus;
  734. char *ifname = wpa_s->ifname;
  735. /* Do nothing if the control interface is not turned on */
  736. if (iface == NULL)
  737. return;
  738. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  739. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  740. "GroupFinished");
  741. if (msg == NULL)
  742. return;
  743. dbus_message_iter_init_append(msg, &iter);
  744. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &ifname)) {
  745. wpa_printf(MSG_ERROR, "dbus: Failed to construct GroupFinished"
  746. "signal -not enough memory for ifname ");
  747. goto err;
  748. }
  749. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &role))
  750. wpa_printf(MSG_ERROR, "dbus: Failed to construct GroupFinished"
  751. "signal -not enough memory for role ");
  752. else
  753. dbus_connection_send(iface->con, msg, NULL);
  754. err:
  755. dbus_message_unref(msg);
  756. }
  757. /**
  758. * wpas_dbus_signal_p2p_provision_discovery - Signals various PD events
  759. *
  760. * @dev_addr - who sent the request or responded to our request.
  761. * @request - Will be 1 if request, 0 for response.
  762. * @status - valid only in case of response
  763. * @config_methods - wps config methods
  764. * @generated_pin - pin to be displayed in case of WPS_CONFIG_DISPLAY method
  765. *
  766. * Sends following provision discovery related events:
  767. * ProvisionDiscoveryRequestDisplayPin
  768. * ProvisionDiscoveryResponseDisplayPin
  769. * ProvisionDiscoveryRequestEnterPin
  770. * ProvisionDiscoveryResponseEnterPin
  771. * ProvisionDiscoveryPBCRequest
  772. * ProvisionDiscoveryPBCResponse
  773. *
  774. * TODO::
  775. * ProvisionDiscoveryFailure (timeout case)
  776. */
  777. void wpas_dbus_signal_p2p_provision_discovery(struct wpa_supplicant *wpa_s,
  778. const u8 *dev_addr, int request,
  779. enum p2p_prov_disc_status status,
  780. u16 config_methods,
  781. unsigned int generated_pin)
  782. {
  783. DBusMessage *msg;
  784. DBusMessageIter iter;
  785. struct wpas_dbus_priv *iface;
  786. char *_signal;
  787. int add_pin = 0;
  788. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  789. int error_ret = 1;
  790. char pin[9], *p_pin = NULL;
  791. iface = wpa_s->global->dbus;
  792. /* Do nothing if the control interface is not turned on */
  793. if (iface == NULL)
  794. return;
  795. if (request || !status) {
  796. if (config_methods & WPS_CONFIG_DISPLAY)
  797. _signal = request ?
  798. "ProvisionDiscoveryRequestDisplayPin" :
  799. "ProvisionDiscoveryResponseEnterPin";
  800. else if (config_methods & WPS_CONFIG_KEYPAD)
  801. _signal = request ?
  802. "ProvisionDiscoveryRequestEnterPin" :
  803. "ProvisionDiscoveryResponseDisplayPin";
  804. else if (config_methods & WPS_CONFIG_PUSHBUTTON)
  805. _signal = request ? "ProvisionDiscoveryPBCRequest" :
  806. "ProvisionDiscoveryPBCResponse";
  807. else
  808. return; /* Unknown or un-supported method */
  809. } else if (!request && status)
  810. /* Explicit check for failure response */
  811. _signal = "ProvisionDiscoveryFailure";
  812. add_pin = ((request && (config_methods & WPS_CONFIG_DISPLAY)) ||
  813. (!request && !status &&
  814. (config_methods & WPS_CONFIG_KEYPAD)));
  815. if (add_pin) {
  816. os_snprintf(pin, sizeof(pin), "%08d", generated_pin);
  817. p_pin = pin;
  818. }
  819. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  820. WPAS_DBUS_NEW_IFACE_P2PDEVICE, _signal);
  821. if (msg == NULL)
  822. return;
  823. /* Check if this is a known peer */
  824. if (!p2p_peer_known(wpa_s->global->p2p, dev_addr))
  825. goto error;
  826. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  827. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
  828. COMPACT_MACSTR,
  829. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  830. path = peer_obj_path;
  831. dbus_message_iter_init_append(msg, &iter);
  832. if (!dbus_message_iter_append_basic(&iter,
  833. DBUS_TYPE_OBJECT_PATH,
  834. &path))
  835. goto error;
  836. if (!request && status)
  837. /* Attach status to ProvisionDiscoveryFailure */
  838. error_ret = !dbus_message_iter_append_basic(&iter,
  839. DBUS_TYPE_INT32,
  840. &status);
  841. else
  842. error_ret = (add_pin &&
  843. !dbus_message_iter_append_basic(&iter,
  844. DBUS_TYPE_STRING,
  845. &p_pin));
  846. error:
  847. if (!error_ret)
  848. dbus_connection_send(iface->con, msg, NULL);
  849. else
  850. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  851. dbus_message_unref(msg);
  852. }
  853. void wpas_dbus_signal_p2p_go_neg_req(struct wpa_supplicant *wpa_s,
  854. const u8 *src, u16 dev_passwd_id)
  855. {
  856. DBusMessage *msg;
  857. DBusMessageIter iter;
  858. struct wpas_dbus_priv *iface;
  859. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  860. iface = wpa_s->global->dbus;
  861. /* Do nothing if the control interface is not turned on */
  862. if (iface == NULL)
  863. return;
  864. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  865. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  866. wpa_s->dbus_new_path, MAC2STR(src));
  867. path = peer_obj_path;
  868. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  869. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  870. "GONegotiationRequest");
  871. if (msg == NULL)
  872. return;
  873. dbus_message_iter_init_append(msg, &iter);
  874. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  875. &path) ||
  876. !dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT16,
  877. &dev_passwd_id))
  878. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  879. else
  880. dbus_connection_send(iface->con, msg, NULL);
  881. dbus_message_unref(msg);
  882. }
  883. static int wpas_dbus_get_group_obj_path(struct wpa_supplicant *wpa_s,
  884. const struct wpa_ssid *ssid,
  885. char *group_obj_path)
  886. {
  887. char group_name[3];
  888. if (os_memcmp(ssid->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN))
  889. return -1;
  890. os_memcpy(group_name, ssid->ssid + P2P_WILDCARD_SSID_LEN, 2);
  891. group_name[2] = '\0';
  892. os_snprintf(group_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  893. "%s/" WPAS_DBUS_NEW_P2P_GROUPS_PART "/%s",
  894. wpa_s->dbus_new_path, group_name);
  895. return 0;
  896. }
  897. /**
  898. * wpas_dbus_signal_p2p_group_started - Signals P2P group has
  899. * started. Emitted when a group is successfully started
  900. * irrespective of the role (client/GO) of the current device
  901. *
  902. * @wpa_s: %wpa_supplicant network interface data
  903. * @ssid: SSID object
  904. * @client: this device is P2P client
  905. * @network_id: network id of the group started, use instead of ssid->id
  906. * to account for persistent groups
  907. */
  908. void wpas_dbus_signal_p2p_group_started(struct wpa_supplicant *wpa_s,
  909. const struct wpa_ssid *ssid,
  910. int client, int network_id)
  911. {
  912. DBusMessage *msg;
  913. DBusMessageIter iter, dict_iter;
  914. struct wpas_dbus_priv *iface;
  915. char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  916. char group_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  917. iface = wpa_s->parent->global->dbus;
  918. /* Do nothing if the control interface is not turned on */
  919. if (iface == NULL)
  920. return;
  921. if (wpas_dbus_get_group_obj_path(wpa_s, ssid, group_obj_path) < 0)
  922. return;
  923. /* New interface has been created for this group */
  924. msg = dbus_message_new_signal(wpa_s->parent->dbus_new_path,
  925. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  926. "GroupStarted");
  927. if (msg == NULL)
  928. return;
  929. dbus_message_iter_init_append(msg, &iter);
  930. if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
  931. goto nomem;
  932. /*
  933. * In case the device supports creating a separate interface the
  934. * DBus client will need to know the object path for the interface
  935. * object this group was created on, so include it here.
  936. */
  937. if (!wpa_dbus_dict_append_object_path(&dict_iter,
  938. "interface_object",
  939. wpa_s->dbus_new_path))
  940. goto nomem;
  941. if (!wpa_dbus_dict_append_string(&dict_iter, "role",
  942. client ? "client" : "GO"))
  943. goto nomem;
  944. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  945. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  946. wpa_s->parent->dbus_new_path, network_id);
  947. if (!wpa_dbus_dict_append_object_path(&dict_iter, "group_object",
  948. group_obj_path) ||
  949. !wpa_dbus_dict_append_object_path(&dict_iter, "network_object",
  950. net_obj_path) ||
  951. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  952. goto nomem;
  953. dbus_connection_send(iface->con, msg, NULL);
  954. nomem:
  955. dbus_message_unref(msg);
  956. }
  957. /**
  958. *
  959. * Method to emit GONeogtiation Success or Failure signals based
  960. * on status.
  961. * @status: Status of the GO neg request. 0 for success, other for errors.
  962. */
  963. void wpas_dbus_signal_p2p_go_neg_resp(struct wpa_supplicant *wpa_s,
  964. struct p2p_go_neg_results *res)
  965. {
  966. DBusMessage *msg;
  967. DBusMessageIter iter, dict_iter;
  968. DBusMessageIter iter_dict_entry, iter_dict_val, iter_dict_array;
  969. struct wpas_dbus_priv *iface;
  970. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  971. dbus_int32_t freqs[P2P_MAX_CHANNELS];
  972. dbus_int32_t *f_array = freqs;
  973. iface = wpa_s->global->dbus;
  974. os_memset(freqs, 0, sizeof(freqs));
  975. /* Do nothing if the control interface is not turned on */
  976. if (iface == NULL)
  977. return;
  978. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  979. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  980. wpa_s->dbus_new_path, MAC2STR(res->peer_device_addr));
  981. path = peer_obj_path;
  982. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  983. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  984. res->status ? "GONegotiationFailure" :
  985. "GONegotiationSuccess");
  986. if (msg == NULL)
  987. return;
  988. dbus_message_iter_init_append(msg, &iter);
  989. if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
  990. goto err;
  991. if (!wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
  992. path) ||
  993. !wpa_dbus_dict_append_int32(&dict_iter, "status", res->status))
  994. goto err;
  995. if (!res->status) {
  996. int i = 0;
  997. int freq_list_num = 0;
  998. if (res->role_go) {
  999. if (!wpa_dbus_dict_append_byte_array(
  1000. &dict_iter, "passphrase",
  1001. (const char *) res->passphrase,
  1002. sizeof(res->passphrase)))
  1003. goto err;
  1004. }
  1005. if (!wpa_dbus_dict_append_string(&dict_iter, "role_go",
  1006. res->role_go ? "GO" :
  1007. "client") ||
  1008. !wpa_dbus_dict_append_int32(&dict_iter, "frequency",
  1009. res->freq) ||
  1010. !wpa_dbus_dict_append_byte_array(&dict_iter, "ssid",
  1011. (const char *) res->ssid,
  1012. res->ssid_len) ||
  1013. !wpa_dbus_dict_append_byte_array(&dict_iter,
  1014. "peer_device_addr",
  1015. (const char *)
  1016. res->peer_device_addr,
  1017. ETH_ALEN) ||
  1018. !wpa_dbus_dict_append_byte_array(&dict_iter,
  1019. "peer_interface_addr",
  1020. (const char *)
  1021. res->peer_interface_addr,
  1022. ETH_ALEN) ||
  1023. !wpa_dbus_dict_append_string(&dict_iter, "wps_method",
  1024. p2p_wps_method_text(
  1025. res->wps_method)))
  1026. goto err;
  1027. for (i = 0; i < P2P_MAX_CHANNELS; i++) {
  1028. if (res->freq_list[i]) {
  1029. freqs[i] = res->freq_list[i];
  1030. freq_list_num++;
  1031. }
  1032. }
  1033. if (!wpa_dbus_dict_begin_array(&dict_iter,
  1034. "frequency_list",
  1035. DBUS_TYPE_INT32_AS_STRING,
  1036. &iter_dict_entry,
  1037. &iter_dict_val,
  1038. &iter_dict_array))
  1039. goto err;
  1040. if (!dbus_message_iter_append_fixed_array(&iter_dict_array,
  1041. DBUS_TYPE_INT32,
  1042. &f_array,
  1043. freq_list_num))
  1044. goto err;
  1045. if (!wpa_dbus_dict_end_array(&dict_iter,
  1046. &iter_dict_entry,
  1047. &iter_dict_val,
  1048. &iter_dict_array))
  1049. goto err;
  1050. if (!wpa_dbus_dict_append_int32(&dict_iter, "persistent_group",
  1051. res->persistent_group) ||
  1052. !wpa_dbus_dict_append_uint32(&dict_iter,
  1053. "peer_config_timeout",
  1054. res->peer_config_timeout))
  1055. goto err;
  1056. }
  1057. if (!wpa_dbus_dict_close_write(&iter, &dict_iter))
  1058. goto err;
  1059. dbus_connection_send(iface->con, msg, NULL);
  1060. err:
  1061. dbus_message_unref(msg);
  1062. }
  1063. /**
  1064. *
  1065. * Method to emit Invitation Result signal based on status and
  1066. * bssid
  1067. * @status: Status of the Invite request. 0 for success, other
  1068. * for errors
  1069. * @bssid : Basic Service Set Identifier
  1070. */
  1071. void wpas_dbus_signal_p2p_invitation_result(struct wpa_supplicant *wpa_s,
  1072. int status, const u8 *bssid)
  1073. {
  1074. DBusMessage *msg;
  1075. DBusMessageIter iter, dict_iter;
  1076. struct wpas_dbus_priv *iface;
  1077. wpa_printf(MSG_INFO, "%s\n", __func__);
  1078. iface = wpa_s->global->dbus;
  1079. /* Do nothing if the control interface is not turned on */
  1080. if (iface == NULL)
  1081. return;
  1082. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1083. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1084. "InvitationResult");
  1085. if (msg == NULL)
  1086. return;
  1087. dbus_message_iter_init_append(msg, &iter);
  1088. if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
  1089. goto nomem;
  1090. if (!wpa_dbus_dict_append_int32(&dict_iter, "status", status))
  1091. goto nomem;
  1092. if (bssid) {
  1093. if (!wpa_dbus_dict_append_byte_array(&dict_iter, "BSSID",
  1094. (const char *) bssid,
  1095. ETH_ALEN))
  1096. goto nomem;
  1097. }
  1098. if (!wpa_dbus_dict_close_write(&iter, &dict_iter))
  1099. goto nomem;
  1100. dbus_connection_send(iface->con, msg, NULL);
  1101. nomem:
  1102. dbus_message_unref(msg);
  1103. }
  1104. /**
  1105. *
  1106. * Method to emit a signal for a peer joining the group.
  1107. * The signal will carry path to the group member object
  1108. * constructed using p2p i/f addr used for connecting.
  1109. *
  1110. * @wpa_s: %wpa_supplicant network interface data
  1111. * @member_addr: addr (p2p i/f) of the peer joining the group
  1112. */
  1113. void wpas_dbus_signal_p2p_peer_joined(struct wpa_supplicant *wpa_s,
  1114. const u8 *member)
  1115. {
  1116. struct wpas_dbus_priv *iface;
  1117. DBusMessage *msg;
  1118. DBusMessageIter iter;
  1119. char groupmember_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  1120. iface = wpa_s->global->dbus;
  1121. /* Do nothing if the control interface is not turned on */
  1122. if (iface == NULL)
  1123. return;
  1124. if (!wpa_s->dbus_groupobj_path)
  1125. return;
  1126. os_snprintf(groupmember_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1127. "%s/" WPAS_DBUS_NEW_P2P_GROUPMEMBERS_PART "/"
  1128. COMPACT_MACSTR,
  1129. wpa_s->dbus_groupobj_path, MAC2STR(member));
  1130. msg = dbus_message_new_signal(wpa_s->dbus_groupobj_path,
  1131. WPAS_DBUS_NEW_IFACE_P2P_GROUP,
  1132. "PeerJoined");
  1133. if (msg == NULL)
  1134. return;
  1135. dbus_message_iter_init_append(msg, &iter);
  1136. path = groupmember_obj_path;
  1137. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  1138. &path))
  1139. goto err;
  1140. dbus_connection_send(iface->con, msg, NULL);
  1141. dbus_message_unref(msg);
  1142. return;
  1143. err:
  1144. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1145. dbus_message_unref(msg);
  1146. }
  1147. /**
  1148. *
  1149. * Method to emit a signal for a peer disconnecting the group.
  1150. * The signal will carry path to the group member object
  1151. * constructed using p2p i/f addr used for connecting.
  1152. *
  1153. * @wpa_s: %wpa_supplicant network interface data
  1154. * @member_addr: addr (p2p i/f) of the peer joining the group
  1155. */
  1156. void wpas_dbus_signal_p2p_peer_disconnected(struct wpa_supplicant *wpa_s,
  1157. const u8 *member)
  1158. {
  1159. struct wpas_dbus_priv *iface;
  1160. DBusMessage *msg;
  1161. DBusMessageIter iter;
  1162. char groupmember_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  1163. iface = wpa_s->global->dbus;
  1164. /* Do nothing if the control interface is not turned on */
  1165. if (iface == NULL)
  1166. return;
  1167. if (!wpa_s->dbus_groupobj_path)
  1168. return;
  1169. os_snprintf(groupmember_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1170. "%s/" WPAS_DBUS_NEW_P2P_GROUPMEMBERS_PART "/"
  1171. COMPACT_MACSTR,
  1172. wpa_s->dbus_groupobj_path, MAC2STR(member));
  1173. msg = dbus_message_new_signal(wpa_s->dbus_groupobj_path,
  1174. WPAS_DBUS_NEW_IFACE_P2P_GROUP,
  1175. "PeerDisconnected");
  1176. if (msg == NULL)
  1177. return;
  1178. dbus_message_iter_init_append(msg, &iter);
  1179. path = groupmember_obj_path;
  1180. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  1181. &path))
  1182. goto err;
  1183. dbus_connection_send(iface->con, msg, NULL);
  1184. dbus_message_unref(msg);
  1185. return;
  1186. err:
  1187. wpa_printf(MSG_ERROR, "dbus: Failed to construct PeerDisconnected "
  1188. "signal");
  1189. dbus_message_unref(msg);
  1190. }
  1191. /**
  1192. *
  1193. * Method to emit a signal for a service discovery request.
  1194. * The signal will carry station address, frequency, dialog token,
  1195. * update indicator and it tlvs
  1196. *
  1197. * @wpa_s: %wpa_supplicant network interface data
  1198. * @sa: station addr (p2p i/f) of the peer
  1199. * @dialog_token: service discovery request dialog token
  1200. * @update_indic: service discovery request update indicator
  1201. * @tlvs: service discovery request genrated byte array of tlvs
  1202. * @tlvs_len: service discovery request tlvs length
  1203. */
  1204. void wpas_dbus_signal_p2p_sd_request(struct wpa_supplicant *wpa_s,
  1205. int freq, const u8 *sa, u8 dialog_token,
  1206. u16 update_indic, const u8 *tlvs,
  1207. size_t tlvs_len)
  1208. {
  1209. DBusMessage *msg;
  1210. DBusMessageIter iter, dict_iter;
  1211. struct wpas_dbus_priv *iface;
  1212. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  1213. iface = wpa_s->global->dbus;
  1214. /* Do nothing if the control interface is not turned on */
  1215. if (iface == NULL)
  1216. return;
  1217. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1218. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1219. "ServiceDiscoveryRequest");
  1220. if (msg == NULL)
  1221. return;
  1222. /* Check if this is a known peer */
  1223. if (!p2p_peer_known(wpa_s->global->p2p, sa))
  1224. goto error;
  1225. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1226. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
  1227. COMPACT_MACSTR, wpa_s->dbus_new_path, MAC2STR(sa));
  1228. path = peer_obj_path;
  1229. dbus_message_iter_init_append(msg, &iter);
  1230. if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
  1231. goto error;
  1232. if (!wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
  1233. path) ||
  1234. !wpa_dbus_dict_append_int32(&dict_iter, "frequency", freq) ||
  1235. !wpa_dbus_dict_append_int32(&dict_iter, "dialog_token",
  1236. dialog_token) ||
  1237. !wpa_dbus_dict_append_uint16(&dict_iter, "update_indicator",
  1238. update_indic) ||
  1239. !wpa_dbus_dict_append_byte_array(&dict_iter, "tlvs",
  1240. (const char *) tlvs,
  1241. tlvs_len) ||
  1242. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  1243. goto error;
  1244. dbus_connection_send(iface->con, msg, NULL);
  1245. dbus_message_unref(msg);
  1246. return;
  1247. error:
  1248. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1249. dbus_message_unref(msg);
  1250. }
  1251. /**
  1252. *
  1253. * Method to emit a signal for a service discovery response.
  1254. * The signal will carry station address, update indicator and it
  1255. * tlvs
  1256. *
  1257. * @wpa_s: %wpa_supplicant network interface data
  1258. * @sa: station addr (p2p i/f) of the peer
  1259. * @update_indic: service discovery request update indicator
  1260. * @tlvs: service discovery request genrated byte array of tlvs
  1261. * @tlvs_len: service discovery request tlvs length
  1262. */
  1263. void wpas_dbus_signal_p2p_sd_response(struct wpa_supplicant *wpa_s,
  1264. const u8 *sa, u16 update_indic,
  1265. const u8 *tlvs, size_t tlvs_len)
  1266. {
  1267. DBusMessage *msg;
  1268. DBusMessageIter iter, dict_iter;
  1269. struct wpas_dbus_priv *iface;
  1270. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  1271. iface = wpa_s->global->dbus;
  1272. /* Do nothing if the control interface is not turned on */
  1273. if (iface == NULL)
  1274. return;
  1275. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1276. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1277. "ServiceDiscoveryResponse");
  1278. if (msg == NULL)
  1279. return;
  1280. /* Check if this is a known peer */
  1281. if (!p2p_peer_known(wpa_s->global->p2p, sa))
  1282. goto error;
  1283. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1284. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
  1285. COMPACT_MACSTR, wpa_s->dbus_new_path, MAC2STR(sa));
  1286. path = peer_obj_path;
  1287. dbus_message_iter_init_append(msg, &iter);
  1288. if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
  1289. goto error;
  1290. if (!wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
  1291. path) ||
  1292. !wpa_dbus_dict_append_uint16(&dict_iter, "update_indicator",
  1293. update_indic) ||
  1294. !wpa_dbus_dict_append_byte_array(&dict_iter, "tlvs",
  1295. (const char *) tlvs,
  1296. tlvs_len) ||
  1297. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  1298. goto error;
  1299. dbus_connection_send(iface->con, msg, NULL);
  1300. dbus_message_unref(msg);
  1301. return;
  1302. error:
  1303. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1304. dbus_message_unref(msg);
  1305. }
  1306. /**
  1307. * wpas_dbus_signal_persistent_group - Send a persistent group related
  1308. * event signal
  1309. * @wpa_s: %wpa_supplicant network interface data
  1310. * @id: new persistent group id
  1311. * @sig_name: signal name - PersistentGroupAdded, PersistentGroupRemoved
  1312. * @properties: determines if add second argument with object properties
  1313. *
  1314. * Notify listeners about an event related to persistent groups.
  1315. */
  1316. static void wpas_dbus_signal_persistent_group(struct wpa_supplicant *wpa_s,
  1317. int id, const char *sig_name,
  1318. int properties)
  1319. {
  1320. struct wpas_dbus_priv *iface;
  1321. DBusMessage *msg;
  1322. DBusMessageIter iter;
  1323. char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  1324. iface = wpa_s->global->dbus;
  1325. /* Do nothing if the control interface is not turned on */
  1326. if (iface == NULL)
  1327. return;
  1328. os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1329. "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
  1330. wpa_s->dbus_new_path, id);
  1331. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1332. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1333. sig_name);
  1334. if (msg == NULL)
  1335. return;
  1336. dbus_message_iter_init_append(msg, &iter);
  1337. path = pgrp_obj_path;
  1338. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  1339. &path))
  1340. goto err;
  1341. if (properties) {
  1342. if (!wpa_dbus_get_object_properties(
  1343. iface, pgrp_obj_path,
  1344. WPAS_DBUS_NEW_IFACE_PERSISTENT_GROUP, &iter))
  1345. goto err;
  1346. }
  1347. dbus_connection_send(iface->con, msg, NULL);
  1348. dbus_message_unref(msg);
  1349. return;
  1350. err:
  1351. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1352. dbus_message_unref(msg);
  1353. }
  1354. /**
  1355. * wpas_dbus_signal_persistent_group_added - Send a persistent_group
  1356. * added signal
  1357. * @wpa_s: %wpa_supplicant network interface data
  1358. * @id: new persistent group id
  1359. *
  1360. * Notify listeners about addition of a new persistent group.
  1361. */
  1362. static void wpas_dbus_signal_persistent_group_added(
  1363. struct wpa_supplicant *wpa_s, int id)
  1364. {
  1365. wpas_dbus_signal_persistent_group(wpa_s, id, "PersistentGroupAdded",
  1366. TRUE);
  1367. }
  1368. /**
  1369. * wpas_dbus_signal_persistent_group_removed - Send a persistent_group
  1370. * removed signal
  1371. * @wpa_s: %wpa_supplicant network interface data
  1372. * @id: persistent group id
  1373. *
  1374. * Notify listeners about removal of a persistent group.
  1375. */
  1376. static void wpas_dbus_signal_persistent_group_removed(
  1377. struct wpa_supplicant *wpa_s, int id)
  1378. {
  1379. wpas_dbus_signal_persistent_group(wpa_s, id, "PersistentGroupRemoved",
  1380. FALSE);
  1381. }
  1382. /**
  1383. * wpas_dbus_signal_p2p_wps_failed - Signals WpsFailed event
  1384. * @wpa_s: %wpa_supplicant network interface data
  1385. *
  1386. * Sends Event dbus signal with name "fail" and dictionary containing
  1387. * "msg" field with fail message number (int32) as arguments
  1388. */
  1389. void wpas_dbus_signal_p2p_wps_failed(struct wpa_supplicant *wpa_s,
  1390. struct wps_event_fail *fail)
  1391. {
  1392. DBusMessage *msg;
  1393. DBusMessageIter iter, dict_iter;
  1394. struct wpas_dbus_priv *iface;
  1395. char *key = "fail";
  1396. iface = wpa_s->global->dbus;
  1397. /* Do nothing if the control interface is not turned on */
  1398. if (iface == NULL)
  1399. return;
  1400. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  1401. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  1402. "WpsFailed");
  1403. if (msg == NULL)
  1404. return;
  1405. dbus_message_iter_init_append(msg, &iter);
  1406. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
  1407. !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  1408. !wpa_dbus_dict_append_int32(&dict_iter, "msg", fail->msg) ||
  1409. !wpa_dbus_dict_append_int16(&dict_iter, "config_error",
  1410. fail->config_error) ||
  1411. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  1412. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  1413. else
  1414. dbus_connection_send(iface->con, msg, NULL);
  1415. dbus_message_unref(msg);
  1416. }
  1417. #endif /*CONFIG_P2P*/
  1418. /**
  1419. * wpas_dbus_signal_prop_changed - Signals change of property
  1420. * @wpa_s: %wpa_supplicant network interface data
  1421. * @property: indicates which property has changed
  1422. *
  1423. * Sends PropertyChanged signals with path, interface and arguments
  1424. * depending on which property has changed.
  1425. */
  1426. void wpas_dbus_signal_prop_changed(struct wpa_supplicant *wpa_s,
  1427. enum wpas_dbus_prop property)
  1428. {
  1429. char *prop;
  1430. if (wpa_s->dbus_new_path == NULL)
  1431. return; /* Skip signal since D-Bus setup is not yet ready */
  1432. switch (property) {
  1433. case WPAS_DBUS_PROP_AP_SCAN:
  1434. prop = "ApScan";
  1435. break;
  1436. case WPAS_DBUS_PROP_SCANNING:
  1437. prop = "Scanning";
  1438. break;
  1439. case WPAS_DBUS_PROP_STATE:
  1440. prop = "State";
  1441. break;
  1442. case WPAS_DBUS_PROP_CURRENT_BSS:
  1443. prop = "CurrentBSS";
  1444. break;
  1445. case WPAS_DBUS_PROP_CURRENT_NETWORK:
  1446. prop = "CurrentNetwork";
  1447. break;
  1448. case WPAS_DBUS_PROP_BSSS:
  1449. prop = "BSSs";
  1450. break;
  1451. case WPAS_DBUS_PROP_CURRENT_AUTH_MODE:
  1452. prop = "CurrentAuthMode";
  1453. break;
  1454. default:
  1455. wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
  1456. __func__, property);
  1457. return;
  1458. }
  1459. wpa_dbus_mark_property_changed(wpa_s->global->dbus,
  1460. wpa_s->dbus_new_path,
  1461. WPAS_DBUS_NEW_IFACE_INTERFACE, prop);
  1462. }
  1463. /**
  1464. * wpas_dbus_bss_signal_prop_changed - Signals change of BSS property
  1465. * @wpa_s: %wpa_supplicant network interface data
  1466. * @property: indicates which property has changed
  1467. * @id: unique BSS identifier
  1468. *
  1469. * Sends PropertyChanged signals with path, interface, and arguments depending
  1470. * on which property has changed.
  1471. */
  1472. void wpas_dbus_bss_signal_prop_changed(struct wpa_supplicant *wpa_s,
  1473. enum wpas_dbus_bss_prop property,
  1474. unsigned int id)
  1475. {
  1476. char path[WPAS_DBUS_OBJECT_PATH_MAX];
  1477. char *prop;
  1478. switch (property) {
  1479. case WPAS_DBUS_BSS_PROP_SIGNAL:
  1480. prop = "Signal";
  1481. break;
  1482. case WPAS_DBUS_BSS_PROP_FREQ:
  1483. prop = "Frequency";
  1484. break;
  1485. case WPAS_DBUS_BSS_PROP_MODE:
  1486. prop = "Mode";
  1487. break;
  1488. case WPAS_DBUS_BSS_PROP_PRIVACY:
  1489. prop = "Privacy";
  1490. break;
  1491. case WPAS_DBUS_BSS_PROP_RATES:
  1492. prop = "Rates";
  1493. break;
  1494. case WPAS_DBUS_BSS_PROP_WPA:
  1495. prop = "WPA";
  1496. break;
  1497. case WPAS_DBUS_BSS_PROP_RSN:
  1498. prop = "RSN";
  1499. break;
  1500. case WPAS_DBUS_BSS_PROP_IES:
  1501. prop = "IEs";
  1502. break;
  1503. default:
  1504. wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
  1505. __func__, property);
  1506. return;
  1507. }
  1508. os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
  1509. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  1510. wpa_s->dbus_new_path, id);
  1511. wpa_dbus_mark_property_changed(wpa_s->global->dbus, path,
  1512. WPAS_DBUS_NEW_IFACE_BSS, prop);
  1513. }
  1514. /**
  1515. * wpas_dbus_signal_debug_level_changed - Signals change of debug param
  1516. * @global: wpa_global structure
  1517. *
  1518. * Sends PropertyChanged signals informing that debug level has changed.
  1519. */
  1520. void wpas_dbus_signal_debug_level_changed(struct wpa_global *global)
  1521. {
  1522. wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
  1523. WPAS_DBUS_NEW_INTERFACE,
  1524. "DebugLevel");
  1525. }
  1526. /**
  1527. * wpas_dbus_signal_debug_timestamp_changed - Signals change of debug param
  1528. * @global: wpa_global structure
  1529. *
  1530. * Sends PropertyChanged signals informing that debug timestamp has changed.
  1531. */
  1532. void wpas_dbus_signal_debug_timestamp_changed(struct wpa_global *global)
  1533. {
  1534. wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
  1535. WPAS_DBUS_NEW_INTERFACE,
  1536. "DebugTimestamp");
  1537. }
  1538. /**
  1539. * wpas_dbus_signal_debug_show_keys_changed - Signals change of debug param
  1540. * @global: wpa_global structure
  1541. *
  1542. * Sends PropertyChanged signals informing that debug show_keys has changed.
  1543. */
  1544. void wpas_dbus_signal_debug_show_keys_changed(struct wpa_global *global)
  1545. {
  1546. wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
  1547. WPAS_DBUS_NEW_INTERFACE,
  1548. "DebugShowKeys");
  1549. }
  1550. static void wpas_dbus_register(struct wpa_dbus_object_desc *obj_desc,
  1551. void *priv,
  1552. WPADBusArgumentFreeFunction priv_free,
  1553. const struct wpa_dbus_method_desc *methods,
  1554. const struct wpa_dbus_property_desc *properties,
  1555. const struct wpa_dbus_signal_desc *signals)
  1556. {
  1557. int n;
  1558. obj_desc->user_data = priv;
  1559. obj_desc->user_data_free_func = priv_free;
  1560. obj_desc->methods = methods;
  1561. obj_desc->properties = properties;
  1562. obj_desc->signals = signals;
  1563. for (n = 0; properties && properties->dbus_property; properties++)
  1564. n++;
  1565. obj_desc->prop_changed_flags = os_zalloc(n);
  1566. if (!obj_desc->prop_changed_flags)
  1567. wpa_printf(MSG_DEBUG, "dbus: %s: can't register handlers",
  1568. __func__);
  1569. }
  1570. static const struct wpa_dbus_method_desc wpas_dbus_global_methods[] = {
  1571. { "CreateInterface", WPAS_DBUS_NEW_INTERFACE,
  1572. (WPADBusMethodHandler) &wpas_dbus_handler_create_interface,
  1573. {
  1574. { "args", "a{sv}", ARG_IN },
  1575. { "path", "o", ARG_OUT },
  1576. END_ARGS
  1577. }
  1578. },
  1579. { "RemoveInterface", WPAS_DBUS_NEW_INTERFACE,
  1580. (WPADBusMethodHandler) &wpas_dbus_handler_remove_interface,
  1581. {
  1582. { "path", "o", ARG_IN },
  1583. END_ARGS
  1584. }
  1585. },
  1586. { "GetInterface", WPAS_DBUS_NEW_INTERFACE,
  1587. (WPADBusMethodHandler) &wpas_dbus_handler_get_interface,
  1588. {
  1589. { "ifname", "s", ARG_IN },
  1590. { "path", "o", ARG_OUT },
  1591. END_ARGS
  1592. }
  1593. },
  1594. { NULL, NULL, NULL, { END_ARGS } }
  1595. };
  1596. static const struct wpa_dbus_property_desc wpas_dbus_global_properties[] = {
  1597. { "DebugLevel", WPAS_DBUS_NEW_INTERFACE, "s",
  1598. wpas_dbus_getter_debug_level,
  1599. wpas_dbus_setter_debug_level
  1600. },
  1601. { "DebugTimestamp", WPAS_DBUS_NEW_INTERFACE, "b",
  1602. wpas_dbus_getter_debug_timestamp,
  1603. wpas_dbus_setter_debug_timestamp
  1604. },
  1605. { "DebugShowKeys", WPAS_DBUS_NEW_INTERFACE, "b",
  1606. wpas_dbus_getter_debug_show_keys,
  1607. wpas_dbus_setter_debug_show_keys
  1608. },
  1609. { "Interfaces", WPAS_DBUS_NEW_INTERFACE, "ao",
  1610. wpas_dbus_getter_interfaces,
  1611. NULL
  1612. },
  1613. { "EapMethods", WPAS_DBUS_NEW_INTERFACE, "as",
  1614. wpas_dbus_getter_eap_methods,
  1615. NULL
  1616. },
  1617. { NULL, NULL, NULL, NULL, NULL }
  1618. };
  1619. static const struct wpa_dbus_signal_desc wpas_dbus_global_signals[] = {
  1620. { "InterfaceAdded", WPAS_DBUS_NEW_INTERFACE,
  1621. {
  1622. { "path", "o", ARG_OUT },
  1623. { "properties", "a{sv}", ARG_OUT },
  1624. END_ARGS
  1625. }
  1626. },
  1627. { "InterfaceRemoved", WPAS_DBUS_NEW_INTERFACE,
  1628. {
  1629. { "path", "o", ARG_OUT },
  1630. END_ARGS
  1631. }
  1632. },
  1633. { "NetworkRequest", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1634. {
  1635. { "path", "o", ARG_OUT },
  1636. { "field", "s", ARG_OUT },
  1637. { "text", "s", ARG_OUT },
  1638. END_ARGS
  1639. }
  1640. },
  1641. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  1642. { "PropertiesChanged", WPAS_DBUS_NEW_INTERFACE,
  1643. {
  1644. { "properties", "a{sv}", ARG_OUT },
  1645. END_ARGS
  1646. }
  1647. },
  1648. { NULL, NULL, { END_ARGS } }
  1649. };
  1650. /**
  1651. * wpas_dbus_ctrl_iface_init - Initialize dbus control interface
  1652. * @global: Pointer to global data from wpa_supplicant_init()
  1653. * Returns: 0 on success or -1 on failure
  1654. *
  1655. * Initialize the dbus control interface for wpa_supplicantand and start
  1656. * receiving commands from external programs over the bus.
  1657. */
  1658. int wpas_dbus_ctrl_iface_init(struct wpas_dbus_priv *priv)
  1659. {
  1660. struct wpa_dbus_object_desc *obj_desc;
  1661. int ret;
  1662. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  1663. if (!obj_desc) {
  1664. wpa_printf(MSG_ERROR, "Not enough memory "
  1665. "to create object description");
  1666. return -1;
  1667. }
  1668. wpas_dbus_register(obj_desc, priv->global, NULL,
  1669. wpas_dbus_global_methods,
  1670. wpas_dbus_global_properties,
  1671. wpas_dbus_global_signals);
  1672. wpa_printf(MSG_DEBUG, "dbus: Register D-Bus object '%s'",
  1673. WPAS_DBUS_NEW_PATH);
  1674. ret = wpa_dbus_ctrl_iface_init(priv, WPAS_DBUS_NEW_PATH,
  1675. WPAS_DBUS_NEW_SERVICE,
  1676. obj_desc);
  1677. if (ret < 0)
  1678. free_dbus_object_desc(obj_desc);
  1679. else
  1680. priv->dbus_new_initialized = 1;
  1681. return ret;
  1682. }
  1683. /**
  1684. * wpas_dbus_ctrl_iface_deinit - Deinitialize dbus ctrl interface for
  1685. * wpa_supplicant
  1686. * @iface: Pointer to dbus private data from wpas_dbus_init()
  1687. *
  1688. * Deinitialize the dbus control interface that was initialized with
  1689. * wpas_dbus_ctrl_iface_init().
  1690. */
  1691. void wpas_dbus_ctrl_iface_deinit(struct wpas_dbus_priv *iface)
  1692. {
  1693. if (!iface->dbus_new_initialized)
  1694. return;
  1695. wpa_printf(MSG_DEBUG, "dbus: Unregister D-Bus object '%s'",
  1696. WPAS_DBUS_NEW_PATH);
  1697. dbus_connection_unregister_object_path(iface->con,
  1698. WPAS_DBUS_NEW_PATH);
  1699. }
  1700. static void wpa_dbus_free(void *ptr)
  1701. {
  1702. os_free(ptr);
  1703. }
  1704. static const struct wpa_dbus_property_desc wpas_dbus_network_properties[] = {
  1705. { "Properties", WPAS_DBUS_NEW_IFACE_NETWORK, "a{sv}",
  1706. wpas_dbus_getter_network_properties,
  1707. wpas_dbus_setter_network_properties
  1708. },
  1709. { "Enabled", WPAS_DBUS_NEW_IFACE_NETWORK, "b",
  1710. wpas_dbus_getter_enabled,
  1711. wpas_dbus_setter_enabled
  1712. },
  1713. { NULL, NULL, NULL, NULL, NULL }
  1714. };
  1715. static const struct wpa_dbus_signal_desc wpas_dbus_network_signals[] = {
  1716. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  1717. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_NETWORK,
  1718. {
  1719. { "properties", "a{sv}", ARG_OUT },
  1720. END_ARGS
  1721. }
  1722. },
  1723. { NULL, NULL, { END_ARGS } }
  1724. };
  1725. /**
  1726. * wpas_dbus_register_network - Register a configured network with dbus
  1727. * @wpa_s: wpa_supplicant interface structure
  1728. * @ssid: network configuration data
  1729. * Returns: 0 on success, -1 on failure
  1730. *
  1731. * Registers network representing object with dbus
  1732. */
  1733. int wpas_dbus_register_network(struct wpa_supplicant *wpa_s,
  1734. struct wpa_ssid *ssid)
  1735. {
  1736. struct wpas_dbus_priv *ctrl_iface;
  1737. struct wpa_dbus_object_desc *obj_desc;
  1738. struct network_handler_args *arg;
  1739. char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  1740. #ifdef CONFIG_P2P
  1741. /*
  1742. * If it is a persistent group register it as such.
  1743. * This is to handle cases where an interface is being initialized
  1744. * with a list of networks read from config.
  1745. */
  1746. if (network_is_persistent_group(ssid))
  1747. return wpas_dbus_register_persistent_group(wpa_s, ssid);
  1748. #endif /* CONFIG_P2P */
  1749. /* Do nothing if the control interface is not turned on */
  1750. if (wpa_s == NULL || wpa_s->global == NULL)
  1751. return 0;
  1752. ctrl_iface = wpa_s->global->dbus;
  1753. if (ctrl_iface == NULL)
  1754. return 0;
  1755. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1756. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  1757. wpa_s->dbus_new_path, ssid->id);
  1758. wpa_printf(MSG_DEBUG, "dbus: Register network object '%s'",
  1759. net_obj_path);
  1760. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  1761. if (!obj_desc) {
  1762. wpa_printf(MSG_ERROR, "Not enough memory "
  1763. "to create object description");
  1764. goto err;
  1765. }
  1766. /* allocate memory for handlers arguments */
  1767. arg = os_zalloc(sizeof(struct network_handler_args));
  1768. if (!arg) {
  1769. wpa_printf(MSG_ERROR, "Not enough memory "
  1770. "to create arguments for method");
  1771. goto err;
  1772. }
  1773. arg->wpa_s = wpa_s;
  1774. arg->ssid = ssid;
  1775. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  1776. wpas_dbus_network_properties,
  1777. wpas_dbus_network_signals);
  1778. if (wpa_dbus_register_object_per_iface(ctrl_iface, net_obj_path,
  1779. wpa_s->ifname, obj_desc))
  1780. goto err;
  1781. wpas_dbus_signal_network_added(wpa_s, ssid->id);
  1782. return 0;
  1783. err:
  1784. free_dbus_object_desc(obj_desc);
  1785. return -1;
  1786. }
  1787. /**
  1788. * wpas_dbus_unregister_network - Unregister a configured network from dbus
  1789. * @wpa_s: wpa_supplicant interface structure
  1790. * @nid: network id
  1791. * Returns: 0 on success, -1 on failure
  1792. *
  1793. * Unregisters network representing object from dbus
  1794. */
  1795. int wpas_dbus_unregister_network(struct wpa_supplicant *wpa_s, int nid)
  1796. {
  1797. struct wpas_dbus_priv *ctrl_iface;
  1798. char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  1799. int ret;
  1800. #ifdef CONFIG_P2P
  1801. struct wpa_ssid *ssid;
  1802. ssid = wpa_config_get_network(wpa_s->conf, nid);
  1803. /* If it is a persistent group unregister it as such */
  1804. if (ssid && network_is_persistent_group(ssid))
  1805. return wpas_dbus_unregister_persistent_group(wpa_s, nid);
  1806. #endif /* CONFIG_P2P */
  1807. /* Do nothing if the control interface is not turned on */
  1808. if (wpa_s->global == NULL || wpa_s->dbus_new_path == NULL)
  1809. return 0;
  1810. ctrl_iface = wpa_s->global->dbus;
  1811. if (ctrl_iface == NULL)
  1812. return 0;
  1813. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1814. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  1815. wpa_s->dbus_new_path, nid);
  1816. wpa_printf(MSG_DEBUG, "dbus: Unregister network object '%s'",
  1817. net_obj_path);
  1818. ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, net_obj_path);
  1819. if (!ret)
  1820. wpas_dbus_signal_network_removed(wpa_s, nid);
  1821. return ret;
  1822. }
  1823. static const struct wpa_dbus_property_desc wpas_dbus_bss_properties[] = {
  1824. { "SSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
  1825. wpas_dbus_getter_bss_ssid,
  1826. NULL
  1827. },
  1828. { "BSSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
  1829. wpas_dbus_getter_bss_bssid,
  1830. NULL
  1831. },
  1832. { "Privacy", WPAS_DBUS_NEW_IFACE_BSS, "b",
  1833. wpas_dbus_getter_bss_privacy,
  1834. NULL
  1835. },
  1836. { "Mode", WPAS_DBUS_NEW_IFACE_BSS, "s",
  1837. wpas_dbus_getter_bss_mode,
  1838. NULL
  1839. },
  1840. { "Signal", WPAS_DBUS_NEW_IFACE_BSS, "n",
  1841. wpas_dbus_getter_bss_signal,
  1842. NULL
  1843. },
  1844. { "Frequency", WPAS_DBUS_NEW_IFACE_BSS, "q",
  1845. wpas_dbus_getter_bss_frequency,
  1846. NULL
  1847. },
  1848. { "Rates", WPAS_DBUS_NEW_IFACE_BSS, "au",
  1849. wpas_dbus_getter_bss_rates,
  1850. NULL
  1851. },
  1852. { "WPA", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
  1853. wpas_dbus_getter_bss_wpa,
  1854. NULL
  1855. },
  1856. { "RSN", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
  1857. wpas_dbus_getter_bss_rsn,
  1858. NULL
  1859. },
  1860. { "IEs", WPAS_DBUS_NEW_IFACE_BSS, "ay",
  1861. wpas_dbus_getter_bss_ies,
  1862. NULL
  1863. },
  1864. { NULL, NULL, NULL, NULL, NULL }
  1865. };
  1866. static const struct wpa_dbus_signal_desc wpas_dbus_bss_signals[] = {
  1867. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  1868. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_BSS,
  1869. {
  1870. { "properties", "a{sv}", ARG_OUT },
  1871. END_ARGS
  1872. }
  1873. },
  1874. { NULL, NULL, { END_ARGS } }
  1875. };
  1876. /**
  1877. * wpas_dbus_unregister_bss - Unregister a scanned BSS from dbus
  1878. * @wpa_s: wpa_supplicant interface structure
  1879. * @bssid: scanned network bssid
  1880. * @id: unique BSS identifier
  1881. * Returns: 0 on success, -1 on failure
  1882. *
  1883. * Unregisters BSS representing object from dbus
  1884. */
  1885. int wpas_dbus_unregister_bss(struct wpa_supplicant *wpa_s,
  1886. u8 bssid[ETH_ALEN], unsigned int id)
  1887. {
  1888. struct wpas_dbus_priv *ctrl_iface;
  1889. char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  1890. /* Do nothing if the control interface is not turned on */
  1891. if (wpa_s == NULL || wpa_s->global == NULL)
  1892. return 0;
  1893. ctrl_iface = wpa_s->global->dbus;
  1894. if (ctrl_iface == NULL)
  1895. return 0;
  1896. os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1897. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  1898. wpa_s->dbus_new_path, id);
  1899. wpa_printf(MSG_DEBUG, "dbus: Unregister BSS object '%s'",
  1900. bss_obj_path);
  1901. if (wpa_dbus_unregister_object_per_iface(ctrl_iface, bss_obj_path)) {
  1902. wpa_printf(MSG_ERROR, "dbus: Cannot unregister BSS object %s",
  1903. bss_obj_path);
  1904. return -1;
  1905. }
  1906. wpas_dbus_signal_bss_removed(wpa_s, bss_obj_path);
  1907. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSSS);
  1908. return 0;
  1909. }
  1910. /**
  1911. * wpas_dbus_register_bss - Register a scanned BSS with dbus
  1912. * @wpa_s: wpa_supplicant interface structure
  1913. * @bssid: scanned network bssid
  1914. * @id: unique BSS identifier
  1915. * Returns: 0 on success, -1 on failure
  1916. *
  1917. * Registers BSS representing object with dbus
  1918. */
  1919. int wpas_dbus_register_bss(struct wpa_supplicant *wpa_s,
  1920. u8 bssid[ETH_ALEN], unsigned int id)
  1921. {
  1922. struct wpas_dbus_priv *ctrl_iface;
  1923. struct wpa_dbus_object_desc *obj_desc;
  1924. char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  1925. struct bss_handler_args *arg;
  1926. /* Do nothing if the control interface is not turned on */
  1927. if (wpa_s == NULL || wpa_s->global == NULL)
  1928. return 0;
  1929. ctrl_iface = wpa_s->global->dbus;
  1930. if (ctrl_iface == NULL)
  1931. return 0;
  1932. os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1933. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  1934. wpa_s->dbus_new_path, id);
  1935. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  1936. if (!obj_desc) {
  1937. wpa_printf(MSG_ERROR, "Not enough memory "
  1938. "to create object description");
  1939. goto err;
  1940. }
  1941. arg = os_zalloc(sizeof(struct bss_handler_args));
  1942. if (!arg) {
  1943. wpa_printf(MSG_ERROR, "Not enough memory "
  1944. "to create arguments for handler");
  1945. goto err;
  1946. }
  1947. arg->wpa_s = wpa_s;
  1948. arg->id = id;
  1949. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  1950. wpas_dbus_bss_properties,
  1951. wpas_dbus_bss_signals);
  1952. wpa_printf(MSG_DEBUG, "dbus: Register BSS object '%s'",
  1953. bss_obj_path);
  1954. if (wpa_dbus_register_object_per_iface(ctrl_iface, bss_obj_path,
  1955. wpa_s->ifname, obj_desc)) {
  1956. wpa_printf(MSG_ERROR,
  1957. "Cannot register BSSID dbus object %s.",
  1958. bss_obj_path);
  1959. goto err;
  1960. }
  1961. wpas_dbus_signal_bss_added(wpa_s, bss_obj_path);
  1962. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSSS);
  1963. return 0;
  1964. err:
  1965. free_dbus_object_desc(obj_desc);
  1966. return -1;
  1967. }
  1968. static const struct wpa_dbus_method_desc wpas_dbus_interface_methods[] = {
  1969. { "Scan", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1970. (WPADBusMethodHandler) &wpas_dbus_handler_scan,
  1971. {
  1972. { "args", "a{sv}", ARG_IN },
  1973. END_ARGS
  1974. }
  1975. },
  1976. { "Disconnect", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1977. (WPADBusMethodHandler) &wpas_dbus_handler_disconnect,
  1978. {
  1979. END_ARGS
  1980. }
  1981. },
  1982. { "AddNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1983. (WPADBusMethodHandler) &wpas_dbus_handler_add_network,
  1984. {
  1985. { "args", "a{sv}", ARG_IN },
  1986. { "path", "o", ARG_OUT },
  1987. END_ARGS
  1988. }
  1989. },
  1990. { "RemoveNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1991. (WPADBusMethodHandler) &wpas_dbus_handler_remove_network,
  1992. {
  1993. { "path", "o", ARG_IN },
  1994. END_ARGS
  1995. }
  1996. },
  1997. { "RemoveAllNetworks", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1998. (WPADBusMethodHandler) &wpas_dbus_handler_remove_all_networks,
  1999. {
  2000. END_ARGS
  2001. }
  2002. },
  2003. { "SelectNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2004. (WPADBusMethodHandler) &wpas_dbus_handler_select_network,
  2005. {
  2006. { "path", "o", ARG_IN },
  2007. END_ARGS
  2008. }
  2009. },
  2010. { "NetworkReply", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2011. (WPADBusMethodHandler) &wpas_dbus_handler_network_reply,
  2012. {
  2013. { "path", "o", ARG_IN },
  2014. { "field", "s", ARG_IN },
  2015. { "value", "s", ARG_IN },
  2016. END_ARGS
  2017. }
  2018. },
  2019. { "AddBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2020. (WPADBusMethodHandler) &wpas_dbus_handler_add_blob,
  2021. {
  2022. { "name", "s", ARG_IN },
  2023. { "data", "ay", ARG_IN },
  2024. END_ARGS
  2025. }
  2026. },
  2027. { "GetBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2028. (WPADBusMethodHandler) &wpas_dbus_handler_get_blob,
  2029. {
  2030. { "name", "s", ARG_IN },
  2031. { "data", "ay", ARG_OUT },
  2032. END_ARGS
  2033. }
  2034. },
  2035. { "RemoveBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2036. (WPADBusMethodHandler) &wpas_dbus_handler_remove_blob,
  2037. {
  2038. { "name", "s", ARG_IN },
  2039. END_ARGS
  2040. }
  2041. },
  2042. #ifdef CONFIG_WPS
  2043. { "Start", WPAS_DBUS_NEW_IFACE_WPS,
  2044. (WPADBusMethodHandler) &wpas_dbus_handler_wps_start,
  2045. {
  2046. { "args", "a{sv}", ARG_IN },
  2047. { "output", "a{sv}", ARG_OUT },
  2048. END_ARGS
  2049. }
  2050. },
  2051. #endif /* CONFIG_WPS */
  2052. #ifdef CONFIG_P2P
  2053. { "Find", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2054. (WPADBusMethodHandler)wpas_dbus_handler_p2p_find,
  2055. {
  2056. { "args", "a{sv}", ARG_IN },
  2057. END_ARGS
  2058. }
  2059. },
  2060. { "StopFind", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2061. (WPADBusMethodHandler)wpas_dbus_handler_p2p_stop_find,
  2062. {
  2063. END_ARGS
  2064. }
  2065. },
  2066. { "Listen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2067. (WPADBusMethodHandler)wpas_dbus_handler_p2p_listen,
  2068. {
  2069. { "timeout", "i", ARG_IN },
  2070. END_ARGS
  2071. }
  2072. },
  2073. { "ExtendedListen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2074. (WPADBusMethodHandler)wpas_dbus_handler_p2p_extendedlisten,
  2075. {
  2076. { "args", "a{sv}", ARG_IN },
  2077. END_ARGS
  2078. }
  2079. },
  2080. { "PresenceRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2081. (WPADBusMethodHandler)wpas_dbus_handler_p2p_presence_request,
  2082. {
  2083. { "args", "a{sv}", ARG_IN },
  2084. END_ARGS
  2085. }
  2086. },
  2087. { "ProvisionDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2088. (WPADBusMethodHandler)wpas_dbus_handler_p2p_prov_disc_req,
  2089. {
  2090. { "peer", "o", ARG_IN },
  2091. { "config_method", "s", ARG_IN },
  2092. END_ARGS
  2093. }
  2094. },
  2095. { "Connect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2096. (WPADBusMethodHandler)wpas_dbus_handler_p2p_connect,
  2097. {
  2098. { "args", "a{sv}", ARG_IN },
  2099. { "generated_pin", "s", ARG_OUT },
  2100. END_ARGS
  2101. }
  2102. },
  2103. { "GroupAdd", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2104. (WPADBusMethodHandler)wpas_dbus_handler_p2p_group_add,
  2105. {
  2106. { "args", "a{sv}", ARG_IN },
  2107. END_ARGS
  2108. }
  2109. },
  2110. { "Invite", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2111. (WPADBusMethodHandler)wpas_dbus_handler_p2p_invite,
  2112. {
  2113. { "args", "a{sv}", ARG_IN },
  2114. END_ARGS
  2115. }
  2116. },
  2117. { "Disconnect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2118. (WPADBusMethodHandler)wpas_dbus_handler_p2p_disconnect,
  2119. {
  2120. END_ARGS
  2121. }
  2122. },
  2123. { "RejectPeer", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2124. (WPADBusMethodHandler)wpas_dbus_handler_p2p_rejectpeer,
  2125. {
  2126. { "peer", "o", ARG_IN },
  2127. END_ARGS
  2128. }
  2129. },
  2130. { "Flush", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2131. (WPADBusMethodHandler)wpas_dbus_handler_p2p_flush,
  2132. {
  2133. END_ARGS
  2134. }
  2135. },
  2136. { "AddService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2137. (WPADBusMethodHandler)wpas_dbus_handler_p2p_add_service,
  2138. {
  2139. { "args", "a{sv}", ARG_IN },
  2140. END_ARGS
  2141. }
  2142. },
  2143. { "DeleteService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2144. (WPADBusMethodHandler)wpas_dbus_handler_p2p_delete_service,
  2145. {
  2146. { "args", "a{sv}", ARG_IN },
  2147. END_ARGS
  2148. }
  2149. },
  2150. { "FlushService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2151. (WPADBusMethodHandler)wpas_dbus_handler_p2p_flush_service,
  2152. {
  2153. END_ARGS
  2154. }
  2155. },
  2156. { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2157. (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_sd_req,
  2158. {
  2159. { "args", "a{sv}", ARG_IN },
  2160. END_ARGS
  2161. }
  2162. },
  2163. { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2164. (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_sd_res,
  2165. {
  2166. { "args", "a{sv}", ARG_IN },
  2167. END_ARGS
  2168. }
  2169. },
  2170. { "ServiceDiscoveryCancelRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2171. (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_sd_cancel_req,
  2172. {
  2173. { "args", "t", ARG_IN },
  2174. END_ARGS
  2175. }
  2176. },
  2177. { "ServiceUpdate", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2178. (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_update,
  2179. {
  2180. END_ARGS
  2181. }
  2182. },
  2183. { "ServiceDiscoveryExternal", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2184. (WPADBusMethodHandler)wpas_dbus_handler_p2p_serv_disc_external,
  2185. {
  2186. { "arg", "i", ARG_IN },
  2187. END_ARGS
  2188. }
  2189. },
  2190. { "ServiceDiscoveryExternal", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2191. (WPADBusMethodHandler)wpas_dbus_handler_p2p_serv_disc_external,
  2192. {
  2193. { "arg", "i", ARG_IN },
  2194. END_ARGS
  2195. }
  2196. },
  2197. { "AddPersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2198. (WPADBusMethodHandler) wpas_dbus_handler_add_persistent_group,
  2199. {
  2200. { "args", "a{sv}", ARG_IN },
  2201. { "path", "o", ARG_OUT },
  2202. END_ARGS
  2203. }
  2204. },
  2205. { "RemovePersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2206. (WPADBusMethodHandler) wpas_dbus_handler_remove_persistent_group,
  2207. {
  2208. { "path", "o", ARG_IN },
  2209. END_ARGS
  2210. }
  2211. },
  2212. { "RemoveAllPersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2213. (WPADBusMethodHandler)
  2214. wpas_dbus_handler_remove_all_persistent_groups,
  2215. {
  2216. END_ARGS
  2217. }
  2218. },
  2219. #endif /* CONFIG_P2P */
  2220. { "FlushBSS", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2221. (WPADBusMethodHandler) &wpas_dbus_handler_flush_bss,
  2222. {
  2223. { "age", "u", ARG_IN },
  2224. END_ARGS
  2225. }
  2226. },
  2227. #ifdef CONFIG_AP
  2228. { "SubscribeProbeReq", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2229. (WPADBusMethodHandler) wpas_dbus_handler_subscribe_preq,
  2230. {
  2231. END_ARGS
  2232. }
  2233. },
  2234. { "UnsubscribeProbeReq", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2235. (WPADBusMethodHandler) wpas_dbus_handler_unsubscribe_preq,
  2236. {
  2237. END_ARGS
  2238. }
  2239. },
  2240. #endif /* CONFIG_AP */
  2241. { NULL, NULL, NULL, { END_ARGS } }
  2242. };
  2243. static const struct wpa_dbus_property_desc wpas_dbus_interface_properties[] = {
  2244. { "Capabilities", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{sv}",
  2245. wpas_dbus_getter_capabilities,
  2246. NULL
  2247. },
  2248. { "State", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2249. wpas_dbus_getter_state,
  2250. NULL
  2251. },
  2252. { "Scanning", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
  2253. wpas_dbus_getter_scanning,
  2254. NULL
  2255. },
  2256. { "ApScan", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  2257. wpas_dbus_getter_ap_scan,
  2258. wpas_dbus_setter_ap_scan
  2259. },
  2260. { "BSSExpireAge", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  2261. wpas_dbus_getter_bss_expire_age,
  2262. wpas_dbus_setter_bss_expire_age
  2263. },
  2264. { "BSSExpireCount", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  2265. wpas_dbus_getter_bss_expire_count,
  2266. wpas_dbus_setter_bss_expire_count
  2267. },
  2268. { "Country", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2269. wpas_dbus_getter_country,
  2270. wpas_dbus_setter_country
  2271. },
  2272. { "Ifname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2273. wpas_dbus_getter_ifname,
  2274. NULL
  2275. },
  2276. { "Driver", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2277. wpas_dbus_getter_driver,
  2278. NULL
  2279. },
  2280. { "BridgeIfname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2281. wpas_dbus_getter_bridge_ifname,
  2282. NULL
  2283. },
  2284. { "CurrentBSS", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
  2285. wpas_dbus_getter_current_bss,
  2286. NULL
  2287. },
  2288. { "CurrentNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
  2289. wpas_dbus_getter_current_network,
  2290. NULL
  2291. },
  2292. { "CurrentAuthMode", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  2293. wpas_dbus_getter_current_auth_mode,
  2294. NULL
  2295. },
  2296. { "Blobs", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{say}",
  2297. wpas_dbus_getter_blobs,
  2298. NULL
  2299. },
  2300. { "BSSs", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
  2301. wpas_dbus_getter_bsss,
  2302. NULL
  2303. },
  2304. { "Networks", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
  2305. wpas_dbus_getter_networks,
  2306. NULL
  2307. },
  2308. { "FastReauth", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
  2309. wpas_dbus_getter_fast_reauth,
  2310. wpas_dbus_setter_fast_reauth
  2311. },
  2312. { "ScanInterval", WPAS_DBUS_NEW_IFACE_INTERFACE, "i",
  2313. wpas_dbus_getter_scan_interval,
  2314. wpas_dbus_setter_scan_interval
  2315. },
  2316. #ifdef CONFIG_WPS
  2317. { "ProcessCredentials", WPAS_DBUS_NEW_IFACE_WPS, "b",
  2318. wpas_dbus_getter_process_credentials,
  2319. wpas_dbus_setter_process_credentials
  2320. },
  2321. #endif /* CONFIG_WPS */
  2322. #ifdef CONFIG_P2P
  2323. { "P2PDeviceConfig", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "a{sv}",
  2324. wpas_dbus_getter_p2p_device_config,
  2325. wpas_dbus_setter_p2p_device_config
  2326. },
  2327. { "Peers", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
  2328. wpas_dbus_getter_p2p_peers,
  2329. NULL
  2330. },
  2331. { "Role", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "s",
  2332. wpas_dbus_getter_p2p_role,
  2333. NULL
  2334. },
  2335. { "Group", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
  2336. wpas_dbus_getter_p2p_group,
  2337. NULL
  2338. },
  2339. { "PeerGO", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
  2340. wpas_dbus_getter_p2p_peergo,
  2341. NULL
  2342. },
  2343. { "PersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
  2344. wpas_dbus_getter_persistent_groups,
  2345. NULL
  2346. },
  2347. #endif /* CONFIG_P2P */
  2348. { NULL, NULL, NULL, NULL, NULL }
  2349. };
  2350. static const struct wpa_dbus_signal_desc wpas_dbus_interface_signals[] = {
  2351. { "ScanDone", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2352. {
  2353. { "success", "b", ARG_OUT },
  2354. END_ARGS
  2355. }
  2356. },
  2357. { "BSSAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2358. {
  2359. { "path", "o", ARG_OUT },
  2360. { "properties", "a{sv}", ARG_OUT },
  2361. END_ARGS
  2362. }
  2363. },
  2364. { "BSSRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2365. {
  2366. { "path", "o", ARG_OUT },
  2367. END_ARGS
  2368. }
  2369. },
  2370. { "BlobAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2371. {
  2372. { "name", "s", ARG_OUT },
  2373. END_ARGS
  2374. }
  2375. },
  2376. { "BlobRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2377. {
  2378. { "name", "s", ARG_OUT },
  2379. END_ARGS
  2380. }
  2381. },
  2382. { "NetworkAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2383. {
  2384. { "path", "o", ARG_OUT },
  2385. { "properties", "a{sv}", ARG_OUT },
  2386. END_ARGS
  2387. }
  2388. },
  2389. { "NetworkRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2390. {
  2391. { "path", "o", ARG_OUT },
  2392. END_ARGS
  2393. }
  2394. },
  2395. { "NetworkSelected", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2396. {
  2397. { "path", "o", ARG_OUT },
  2398. END_ARGS
  2399. }
  2400. },
  2401. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  2402. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2403. {
  2404. { "properties", "a{sv}", ARG_OUT },
  2405. END_ARGS
  2406. }
  2407. },
  2408. #ifdef CONFIG_WPS
  2409. { "Event", WPAS_DBUS_NEW_IFACE_WPS,
  2410. {
  2411. { "name", "s", ARG_OUT },
  2412. { "args", "a{sv}", ARG_OUT },
  2413. END_ARGS
  2414. }
  2415. },
  2416. { "Credentials", WPAS_DBUS_NEW_IFACE_WPS,
  2417. {
  2418. { "credentials", "a{sv}", ARG_OUT },
  2419. END_ARGS
  2420. }
  2421. },
  2422. /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
  2423. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_WPS,
  2424. {
  2425. { "properties", "a{sv}", ARG_OUT },
  2426. END_ARGS
  2427. }
  2428. },
  2429. #endif /* CONFIG_WPS */
  2430. #ifdef CONFIG_P2P
  2431. { "P2PStateChanged", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2432. {
  2433. { "states", "a{ss}", ARG_OUT },
  2434. END_ARGS
  2435. }
  2436. },
  2437. { "DeviceFound", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2438. {
  2439. { "path", "o", ARG_OUT },
  2440. { "properties", "a{sv}", ARG_OUT },
  2441. END_ARGS
  2442. }
  2443. },
  2444. { "DeviceLost", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2445. {
  2446. { "path", "o", ARG_OUT },
  2447. END_ARGS
  2448. }
  2449. },
  2450. { "ProvisionDiscoveryRequestDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2451. {
  2452. { "peer_object", "o", ARG_OUT },
  2453. { "pin", "s", ARG_OUT },
  2454. END_ARGS
  2455. }
  2456. },
  2457. { "ProvisionDiscoveryResponseDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2458. {
  2459. { "peer_object", "o", ARG_OUT },
  2460. { "pin", "s", ARG_OUT },
  2461. END_ARGS
  2462. }
  2463. },
  2464. { "ProvisionDiscoveryRequestEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2465. {
  2466. { "peer_object", "o", ARG_OUT },
  2467. END_ARGS
  2468. }
  2469. },
  2470. { "ProvisionDiscoveryResponseEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2471. {
  2472. { "peer_object", "o", ARG_OUT },
  2473. END_ARGS
  2474. }
  2475. },
  2476. { "ProvisionDiscoveryPBCRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2477. {
  2478. { "peer_object", "o", ARG_OUT },
  2479. END_ARGS
  2480. }
  2481. },
  2482. { "ProvisionDiscoveryPBCResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2483. {
  2484. { "peer_object", "o", ARG_OUT },
  2485. END_ARGS
  2486. }
  2487. },
  2488. { "ProvisionDiscoveryFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2489. {
  2490. { "peer_object", "o", ARG_OUT },
  2491. { "status", "i", ARG_OUT },
  2492. END_ARGS
  2493. }
  2494. },
  2495. { "GroupStarted", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2496. {
  2497. { "properties", "a{sv}", ARG_OUT },
  2498. END_ARGS
  2499. }
  2500. },
  2501. { "GONegotiationSuccess", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2502. {
  2503. END_ARGS
  2504. }
  2505. },
  2506. { "GONegotiationFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2507. {
  2508. { "status", "i", ARG_OUT },
  2509. END_ARGS
  2510. }
  2511. },
  2512. { "GONegotiationRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2513. {
  2514. { "path", "o", ARG_OUT },
  2515. { "dev_passwd_id", "i", ARG_OUT },
  2516. END_ARGS
  2517. }
  2518. },
  2519. { "InvitationResult", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2520. {
  2521. { "invite_result", "a{sv}", ARG_OUT },
  2522. END_ARGS
  2523. }
  2524. },
  2525. { "GroupFinished", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2526. {
  2527. { "ifname", "s", ARG_OUT },
  2528. { "role", "s", ARG_OUT },
  2529. END_ARGS
  2530. }
  2531. },
  2532. { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2533. {
  2534. { "sd_request", "a{sv}", ARG_OUT },
  2535. END_ARGS
  2536. }
  2537. },
  2538. { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2539. {
  2540. { "sd_response", "a{sv}", ARG_OUT },
  2541. END_ARGS
  2542. }
  2543. },
  2544. { "PersistentGroupAdded", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2545. {
  2546. { "path", "o", ARG_OUT },
  2547. { "properties", "a{sv}", ARG_OUT },
  2548. END_ARGS
  2549. }
  2550. },
  2551. { "PersistentGroupRemoved", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2552. {
  2553. { "path", "o", ARG_OUT },
  2554. END_ARGS
  2555. }
  2556. },
  2557. { "WpsFailed", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2558. {
  2559. { "name", "s", ARG_OUT },
  2560. { "args", "a{sv}", ARG_OUT },
  2561. END_ARGS
  2562. }
  2563. },
  2564. #endif /* CONFIG_P2P */
  2565. #ifdef CONFIG_AP
  2566. { "ProbeRequest", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2567. {
  2568. { "args", "a{sv}", ARG_OUT },
  2569. END_ARGS
  2570. }
  2571. },
  2572. #endif /* CONFIG_AP */
  2573. { "Certification", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2574. {
  2575. { "certification", "a{sv}", ARG_OUT },
  2576. END_ARGS
  2577. }
  2578. },
  2579. { "EAP", WPAS_DBUS_NEW_IFACE_INTERFACE,
  2580. {
  2581. { "status", "s", ARG_OUT },
  2582. { "parameter", "s", ARG_OUT },
  2583. END_ARGS
  2584. }
  2585. },
  2586. { NULL, NULL, { END_ARGS } }
  2587. };
  2588. int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s)
  2589. {
  2590. struct wpa_dbus_object_desc *obj_desc = NULL;
  2591. struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus;
  2592. int next;
  2593. /* Do nothing if the control interface is not turned on */
  2594. if (ctrl_iface == NULL)
  2595. return 0;
  2596. /* Create and set the interface's object path */
  2597. wpa_s->dbus_new_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
  2598. if (wpa_s->dbus_new_path == NULL)
  2599. return -1;
  2600. next = ctrl_iface->next_objid++;
  2601. os_snprintf(wpa_s->dbus_new_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2602. WPAS_DBUS_NEW_PATH_INTERFACES "/%u",
  2603. next);
  2604. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  2605. if (!obj_desc) {
  2606. wpa_printf(MSG_ERROR, "Not enough memory "
  2607. "to create object description");
  2608. goto err;
  2609. }
  2610. wpas_dbus_register(obj_desc, wpa_s, NULL, wpas_dbus_interface_methods,
  2611. wpas_dbus_interface_properties,
  2612. wpas_dbus_interface_signals);
  2613. wpa_printf(MSG_DEBUG, "dbus: Register interface object '%s'",
  2614. wpa_s->dbus_new_path);
  2615. if (wpa_dbus_register_object_per_iface(ctrl_iface,
  2616. wpa_s->dbus_new_path,
  2617. wpa_s->ifname, obj_desc))
  2618. goto err;
  2619. wpas_dbus_signal_interface_added(wpa_s);
  2620. return 0;
  2621. err:
  2622. os_free(wpa_s->dbus_new_path);
  2623. wpa_s->dbus_new_path = NULL;
  2624. free_dbus_object_desc(obj_desc);
  2625. return -1;
  2626. }
  2627. int wpas_dbus_unregister_interface(struct wpa_supplicant *wpa_s)
  2628. {
  2629. struct wpas_dbus_priv *ctrl_iface;
  2630. /* Do nothing if the control interface is not turned on */
  2631. if (wpa_s == NULL || wpa_s->global == NULL)
  2632. return 0;
  2633. ctrl_iface = wpa_s->global->dbus;
  2634. if (ctrl_iface == NULL)
  2635. return 0;
  2636. wpa_printf(MSG_DEBUG, "dbus: Unregister interface object '%s'",
  2637. wpa_s->dbus_new_path);
  2638. #ifdef CONFIG_AP
  2639. if (wpa_s->preq_notify_peer) {
  2640. wpas_dbus_unsubscribe_noc(ctrl_iface);
  2641. os_free(wpa_s->preq_notify_peer);
  2642. wpa_s->preq_notify_peer = NULL;
  2643. }
  2644. #endif /* CONFIG_AP */
  2645. if (wpa_dbus_unregister_object_per_iface(ctrl_iface,
  2646. wpa_s->dbus_new_path))
  2647. return -1;
  2648. wpas_dbus_signal_interface_removed(wpa_s);
  2649. os_free(wpa_s->dbus_new_path);
  2650. wpa_s->dbus_new_path = NULL;
  2651. return 0;
  2652. }
  2653. #ifdef CONFIG_P2P
  2654. static const struct wpa_dbus_property_desc wpas_dbus_p2p_peer_properties[] = {
  2655. { "DeviceName", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
  2656. wpas_dbus_getter_p2p_peer_device_name,
  2657. NULL
  2658. },
  2659. { "PrimaryDeviceType", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
  2660. wpas_dbus_getter_p2p_peer_primary_device_type,
  2661. NULL
  2662. },
  2663. { "config_method", WPAS_DBUS_NEW_IFACE_P2P_PEER, "q",
  2664. wpas_dbus_getter_p2p_peer_config_method,
  2665. NULL
  2666. },
  2667. { "level", WPAS_DBUS_NEW_IFACE_P2P_PEER, "i",
  2668. wpas_dbus_getter_p2p_peer_level,
  2669. NULL
  2670. },
  2671. { "devicecapability", WPAS_DBUS_NEW_IFACE_P2P_PEER, "y",
  2672. wpas_dbus_getter_p2p_peer_device_capability,
  2673. NULL
  2674. },
  2675. { "groupcapability", WPAS_DBUS_NEW_IFACE_P2P_PEER, "y",
  2676. wpas_dbus_getter_p2p_peer_group_capability,
  2677. NULL
  2678. },
  2679. { "SecondaryDeviceTypes", WPAS_DBUS_NEW_IFACE_P2P_PEER, "aay",
  2680. wpas_dbus_getter_p2p_peer_secondary_device_types,
  2681. NULL
  2682. },
  2683. { "VendorExtension", WPAS_DBUS_NEW_IFACE_P2P_PEER, "aay",
  2684. wpas_dbus_getter_p2p_peer_vendor_extension,
  2685. NULL
  2686. },
  2687. { "IEs", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
  2688. wpas_dbus_getter_p2p_peer_ies,
  2689. NULL
  2690. },
  2691. { NULL, NULL, NULL, NULL, NULL }
  2692. };
  2693. static const struct wpa_dbus_signal_desc wpas_dbus_p2p_peer_signals[] = {
  2694. { NULL, NULL, { END_ARGS } }
  2695. };
  2696. /**
  2697. * wpas_dbus_signal_peer - Send a peer related event signal
  2698. * @wpa_s: %wpa_supplicant network interface data
  2699. * @dev: peer device object
  2700. * @interface: name of the interface emitting this signal.
  2701. * In case of peer objects, it would be emitted by either
  2702. * the "interface object" or by "peer objects"
  2703. * @sig_name: signal name - DeviceFound
  2704. *
  2705. * Notify listeners about event related with newly found p2p peer device
  2706. */
  2707. static void wpas_dbus_signal_peer(struct wpa_supplicant *wpa_s,
  2708. const u8 *dev_addr, const char *interface,
  2709. const char *sig_name)
  2710. {
  2711. struct wpas_dbus_priv *iface;
  2712. DBusMessage *msg;
  2713. DBusMessageIter iter;
  2714. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  2715. iface = wpa_s->global->dbus;
  2716. /* Do nothing if the control interface is not turned on */
  2717. if (iface == NULL)
  2718. return;
  2719. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2720. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  2721. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  2722. msg = dbus_message_new_signal(wpa_s->dbus_new_path, interface,
  2723. sig_name);
  2724. if (msg == NULL)
  2725. return;
  2726. dbus_message_iter_init_append(msg, &iter);
  2727. path = peer_obj_path;
  2728. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  2729. &path))
  2730. goto err;
  2731. dbus_connection_send(iface->con, msg, NULL);
  2732. dbus_message_unref(msg);
  2733. return;
  2734. err:
  2735. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  2736. dbus_message_unref(msg);
  2737. }
  2738. /**
  2739. * wpas_dbus_signal_peer_found - Send a peer found signal
  2740. * @wpa_s: %wpa_supplicant network interface data
  2741. * @dev: peer device object
  2742. *
  2743. * Notify listeners about find a p2p peer device found
  2744. */
  2745. void wpas_dbus_signal_peer_device_found(struct wpa_supplicant *wpa_s,
  2746. const u8 *dev_addr)
  2747. {
  2748. wpas_dbus_signal_peer(wpa_s, dev_addr,
  2749. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2750. "DeviceFound");
  2751. }
  2752. /**
  2753. * wpas_dbus_signal_peer_lost - Send a peer lost signal
  2754. * @wpa_s: %wpa_supplicant network interface data
  2755. * @dev: peer device object
  2756. *
  2757. * Notify listeners about lost a p2p peer device
  2758. */
  2759. void wpas_dbus_signal_peer_device_lost(struct wpa_supplicant *wpa_s,
  2760. const u8 *dev_addr)
  2761. {
  2762. wpas_dbus_signal_peer(wpa_s, dev_addr,
  2763. WPAS_DBUS_NEW_IFACE_P2PDEVICE,
  2764. "DeviceLost");
  2765. }
  2766. /**
  2767. * wpas_dbus_register_peer - Register a discovered peer object with dbus
  2768. * @wpa_s: wpa_supplicant interface structure
  2769. * @ssid: network configuration data
  2770. * Returns: 0 on success, -1 on failure
  2771. *
  2772. * Registers network representing object with dbus
  2773. */
  2774. int wpas_dbus_register_peer(struct wpa_supplicant *wpa_s, const u8 *dev_addr)
  2775. {
  2776. struct wpas_dbus_priv *ctrl_iface;
  2777. struct wpa_dbus_object_desc *obj_desc;
  2778. struct peer_handler_args *arg;
  2779. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2780. /* Do nothing if the control interface is not turned on */
  2781. if (wpa_s == NULL || wpa_s->global == NULL)
  2782. return 0;
  2783. ctrl_iface = wpa_s->global->dbus;
  2784. if (ctrl_iface == NULL)
  2785. return 0;
  2786. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2787. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  2788. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  2789. wpa_printf(MSG_INFO, "dbus: Register peer object '%s'",
  2790. peer_obj_path);
  2791. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  2792. if (!obj_desc) {
  2793. wpa_printf(MSG_ERROR, "Not enough memory "
  2794. "to create object description");
  2795. goto err;
  2796. }
  2797. /* allocate memory for handlers arguments */
  2798. arg = os_zalloc(sizeof(struct peer_handler_args));
  2799. if (!arg) {
  2800. wpa_printf(MSG_ERROR, "Not enough memory "
  2801. "to create arguments for method");
  2802. goto err;
  2803. }
  2804. arg->wpa_s = wpa_s;
  2805. os_memcpy(arg->p2p_device_addr, dev_addr, ETH_ALEN);
  2806. wpas_dbus_register(obj_desc, arg, wpa_dbus_free,
  2807. NULL,
  2808. wpas_dbus_p2p_peer_properties,
  2809. wpas_dbus_p2p_peer_signals);
  2810. if (wpa_dbus_register_object_per_iface(ctrl_iface, peer_obj_path,
  2811. wpa_s->ifname, obj_desc))
  2812. goto err;
  2813. return 0;
  2814. err:
  2815. free_dbus_object_desc(obj_desc);
  2816. return -1;
  2817. }
  2818. /**
  2819. * wpas_dbus_unregister_peer - Unregister a peer object with dbus
  2820. * @wpa_s: wpa_supplicant interface structure
  2821. * @dev_addr: p2p device addr
  2822. * Returns: 0 on success, -1 on failure
  2823. *
  2824. * Registers network representing object with dbus
  2825. */
  2826. int wpas_dbus_unregister_peer(struct wpa_supplicant *wpa_s,
  2827. const u8 *dev_addr)
  2828. {
  2829. struct wpas_dbus_priv *ctrl_iface;
  2830. char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2831. int ret;
  2832. /* Do nothing if the control interface is not turned on */
  2833. if (wpa_s == NULL || wpa_s->global == NULL ||
  2834. wpa_s->dbus_new_path == NULL)
  2835. return 0;
  2836. ctrl_iface = wpa_s->global->dbus;
  2837. if (ctrl_iface == NULL)
  2838. return 0;
  2839. os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2840. "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
  2841. wpa_s->dbus_new_path, MAC2STR(dev_addr));
  2842. wpa_printf(MSG_INFO, "dbus: Unregister peer object '%s'",
  2843. peer_obj_path);
  2844. ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, peer_obj_path);
  2845. return ret;
  2846. }
  2847. static const struct wpa_dbus_property_desc wpas_dbus_p2p_group_properties[] = {
  2848. { "Members", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ao",
  2849. wpas_dbus_getter_p2p_group_members,
  2850. NULL
  2851. },
  2852. { "Group", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "o",
  2853. wpas_dbus_getter_p2p_group,
  2854. NULL
  2855. },
  2856. { "Role", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "s",
  2857. wpas_dbus_getter_p2p_role,
  2858. NULL
  2859. },
  2860. { "SSID", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
  2861. wpas_dbus_getter_p2p_group_ssid,
  2862. NULL
  2863. },
  2864. { "BSSID", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
  2865. wpas_dbus_getter_p2p_group_bssid,
  2866. NULL
  2867. },
  2868. { "Frequency", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "q",
  2869. wpas_dbus_getter_p2p_group_frequency,
  2870. NULL
  2871. },
  2872. { "Passphrase", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "s",
  2873. wpas_dbus_getter_p2p_group_passphrase,
  2874. NULL
  2875. },
  2876. { "PSK", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
  2877. wpas_dbus_getter_p2p_group_psk,
  2878. NULL
  2879. },
  2880. { "WPSVendorExtensions", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "aay",
  2881. wpas_dbus_getter_p2p_group_vendor_ext,
  2882. wpas_dbus_setter_p2p_group_vendor_ext
  2883. },
  2884. { NULL, NULL, NULL, NULL, NULL }
  2885. };
  2886. static const struct wpa_dbus_signal_desc wpas_dbus_p2p_group_signals[] = {
  2887. { "PeerJoined", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
  2888. {
  2889. { "peer", "o", ARG_OUT },
  2890. END_ARGS
  2891. }
  2892. },
  2893. { "PeerDisconnected", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
  2894. {
  2895. { "peer", "o", ARG_OUT },
  2896. END_ARGS
  2897. }
  2898. },
  2899. { NULL, NULL, { END_ARGS } }
  2900. };
  2901. /**
  2902. * wpas_dbus_register_p2p_group - Register a p2p group object with dbus
  2903. * @wpa_s: wpa_supplicant interface structure
  2904. * @ssid: SSID struct
  2905. * Returns: 0 on success, -1 on failure
  2906. *
  2907. * Registers p2p group representing object with dbus
  2908. */
  2909. void wpas_dbus_register_p2p_group(struct wpa_supplicant *wpa_s,
  2910. struct wpa_ssid *ssid)
  2911. {
  2912. struct wpas_dbus_priv *ctrl_iface;
  2913. struct wpa_dbus_object_desc *obj_desc;
  2914. char group_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  2915. /* Do nothing if the control interface is not turned on */
  2916. if (wpa_s == NULL || wpa_s->global == NULL)
  2917. return;
  2918. ctrl_iface = wpa_s->global->dbus;
  2919. if (ctrl_iface == NULL)
  2920. return;
  2921. if (wpa_s->dbus_groupobj_path) {
  2922. wpa_printf(MSG_INFO, "%s: Group object '%s' already exists",
  2923. __func__, wpa_s->dbus_groupobj_path);
  2924. return;
  2925. }
  2926. if (wpas_dbus_get_group_obj_path(wpa_s, ssid, group_obj_path) < 0)
  2927. return;
  2928. wpa_s->dbus_groupobj_path = os_strdup(group_obj_path);
  2929. if (wpa_s->dbus_groupobj_path == NULL)
  2930. return;
  2931. wpa_printf(MSG_INFO, "dbus: Register group object '%s'",
  2932. group_obj_path);
  2933. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  2934. if (!obj_desc) {
  2935. wpa_printf(MSG_ERROR, "Not enough memory "
  2936. "to create object description");
  2937. goto err;
  2938. }
  2939. wpas_dbus_register(obj_desc, wpa_s, NULL, NULL,
  2940. wpas_dbus_p2p_group_properties,
  2941. wpas_dbus_p2p_group_signals);
  2942. if (wpa_dbus_register_object_per_iface(ctrl_iface, group_obj_path,
  2943. wpa_s->ifname, obj_desc))
  2944. goto err;
  2945. return;
  2946. err:
  2947. if (wpa_s->dbus_groupobj_path) {
  2948. os_free(wpa_s->dbus_groupobj_path);
  2949. wpa_s->dbus_groupobj_path = NULL;
  2950. }
  2951. free_dbus_object_desc(obj_desc);
  2952. }
  2953. /**
  2954. * wpas_dbus_unregister_p2p_group - Unregister a p2p group object from dbus
  2955. * @wpa_s: wpa_supplicant interface structure
  2956. * @ssid: network name of the p2p group started
  2957. */
  2958. void wpas_dbus_unregister_p2p_group(struct wpa_supplicant *wpa_s,
  2959. const struct wpa_ssid *ssid)
  2960. {
  2961. struct wpas_dbus_priv *ctrl_iface;
  2962. /* Do nothing if the control interface is not turned on */
  2963. if (wpa_s == NULL || wpa_s->global == NULL)
  2964. return;
  2965. ctrl_iface = wpa_s->global->dbus;
  2966. if (ctrl_iface == NULL)
  2967. return;
  2968. if (!wpa_s->dbus_groupobj_path) {
  2969. wpa_printf(MSG_DEBUG,
  2970. "%s: Group object '%s' already unregistered",
  2971. __func__, wpa_s->dbus_groupobj_path);
  2972. return;
  2973. }
  2974. wpa_printf(MSG_DEBUG, "dbus: Unregister group object '%s'",
  2975. wpa_s->dbus_groupobj_path);
  2976. wpa_dbus_unregister_object_per_iface(ctrl_iface,
  2977. wpa_s->dbus_groupobj_path);
  2978. os_free(wpa_s->dbus_groupobj_path);
  2979. wpa_s->dbus_groupobj_path = NULL;
  2980. }
  2981. static const struct wpa_dbus_property_desc
  2982. wpas_dbus_p2p_groupmember_properties[] = {
  2983. { NULL, NULL, NULL, NULL, NULL }
  2984. };
  2985. /**
  2986. * wpas_dbus_register_p2p_groupmember - Register a p2p groupmember
  2987. * object with dbus
  2988. * @wpa_s: wpa_supplicant interface structure
  2989. * @p2p_if_addr: i/f addr of the device joining this group
  2990. *
  2991. * Registers p2p groupmember representing object with dbus
  2992. */
  2993. void wpas_dbus_register_p2p_groupmember(struct wpa_supplicant *wpa_s,
  2994. const u8 *p2p_if_addr)
  2995. {
  2996. struct wpas_dbus_priv *ctrl_iface;
  2997. struct wpa_dbus_object_desc *obj_desc = NULL;
  2998. struct groupmember_handler_args *arg;
  2999. char groupmember_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3000. /* Do nothing if the control interface is not turned on */
  3001. if (wpa_s == NULL || wpa_s->global == NULL)
  3002. return;
  3003. ctrl_iface = wpa_s->global->dbus;
  3004. if (ctrl_iface == NULL)
  3005. return;
  3006. if (!wpa_s->dbus_groupobj_path)
  3007. return;
  3008. os_snprintf(groupmember_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3009. "%s/" WPAS_DBUS_NEW_P2P_GROUPMEMBERS_PART "/" COMPACT_MACSTR,
  3010. wpa_s->dbus_groupobj_path, MAC2STR(p2p_if_addr));
  3011. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  3012. if (!obj_desc) {
  3013. wpa_printf(MSG_ERROR, "Not enough memory "
  3014. "to create object description");
  3015. goto err;
  3016. }
  3017. /* allocate memory for handlers arguments */
  3018. arg = os_zalloc(sizeof(struct groupmember_handler_args));
  3019. if (!arg) {
  3020. wpa_printf(MSG_ERROR, "Not enough memory "
  3021. "to create arguments for method");
  3022. goto err;
  3023. }
  3024. arg->wpa_s = wpa_s;
  3025. os_memcpy(arg->member_addr, p2p_if_addr, ETH_ALEN);
  3026. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  3027. wpas_dbus_p2p_groupmember_properties, NULL);
  3028. if (wpa_dbus_register_object_per_iface(ctrl_iface, groupmember_obj_path,
  3029. wpa_s->ifname, obj_desc))
  3030. goto err;
  3031. wpa_printf(MSG_INFO,
  3032. "dbus: Registered group member object '%s' successfully",
  3033. groupmember_obj_path);
  3034. return;
  3035. err:
  3036. free_dbus_object_desc(obj_desc);
  3037. }
  3038. /**
  3039. * wpas_dbus_unregister_p2p_groupmember - Unregister a p2p groupmember
  3040. * object with dbus
  3041. * @wpa_s: wpa_supplicant interface structure
  3042. * @p2p_if_addr: i/f addr of the device joining this group
  3043. *
  3044. * Unregisters p2p groupmember representing object with dbus
  3045. */
  3046. void wpas_dbus_unregister_p2p_groupmember(struct wpa_supplicant *wpa_s,
  3047. const u8 *p2p_if_addr)
  3048. {
  3049. struct wpas_dbus_priv *ctrl_iface;
  3050. char groupmember_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3051. /* Do nothing if the control interface is not turned on */
  3052. if (wpa_s == NULL || wpa_s->global == NULL)
  3053. return;
  3054. ctrl_iface = wpa_s->global->dbus;
  3055. if (ctrl_iface == NULL)
  3056. return;
  3057. if (!wpa_s->dbus_groupobj_path)
  3058. return;
  3059. os_snprintf(groupmember_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3060. "%s/" WPAS_DBUS_NEW_P2P_GROUPMEMBERS_PART "/" COMPACT_MACSTR,
  3061. wpa_s->dbus_groupobj_path, MAC2STR(p2p_if_addr));
  3062. wpa_dbus_unregister_object_per_iface(ctrl_iface, groupmember_obj_path);
  3063. }
  3064. static const struct wpa_dbus_property_desc
  3065. wpas_dbus_persistent_group_properties[] = {
  3066. { "Properties", WPAS_DBUS_NEW_IFACE_PERSISTENT_GROUP, "a{sv}",
  3067. wpas_dbus_getter_persistent_group_properties,
  3068. wpas_dbus_setter_persistent_group_properties
  3069. },
  3070. { NULL, NULL, NULL, NULL, NULL }
  3071. };
  3072. /* No signals intended for persistent group objects */
  3073. /**
  3074. * wpas_dbus_register_persistent_group - Register a configured(saved)
  3075. * persistent group with dbus
  3076. * @wpa_s: wpa_supplicant interface structure
  3077. * @ssid: persistent group (still represented as a network within wpa)
  3078. * configuration data
  3079. * Returns: 0 on success, -1 on failure
  3080. *
  3081. * Registers a persistent group representing object with dbus.
  3082. */
  3083. int wpas_dbus_register_persistent_group(struct wpa_supplicant *wpa_s,
  3084. struct wpa_ssid *ssid)
  3085. {
  3086. struct wpas_dbus_priv *ctrl_iface;
  3087. struct wpa_dbus_object_desc *obj_desc;
  3088. struct network_handler_args *arg;
  3089. char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3090. /* Do nothing if the control interface is not turned on */
  3091. if (wpa_s == NULL || wpa_s->global == NULL)
  3092. return 0;
  3093. /* Make sure ssid is a persistent group */
  3094. if (ssid->disabled != 2 && !ssid->p2p_persistent_group)
  3095. return -1; /* should we return w/o complaining? */
  3096. ctrl_iface = wpa_s->global->dbus;
  3097. if (ctrl_iface == NULL)
  3098. return 0;
  3099. /*
  3100. * Intentionally not coming up with different numbering scheme
  3101. * for persistent groups.
  3102. */
  3103. os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3104. "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
  3105. wpa_s->dbus_new_path, ssid->id);
  3106. wpa_printf(MSG_DEBUG, "dbus: Register persistent group object '%s'",
  3107. pgrp_obj_path);
  3108. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  3109. if (!obj_desc) {
  3110. wpa_printf(MSG_ERROR, "dbus: Not enough memory to create "
  3111. "object description");
  3112. goto err;
  3113. }
  3114. /*
  3115. * Reusing the same context structure as that for networks
  3116. * since these are represented using same data structure.
  3117. */
  3118. /* allocate memory for handlers arguments */
  3119. arg = os_zalloc(sizeof(struct network_handler_args));
  3120. if (!arg) {
  3121. wpa_printf(MSG_ERROR, "dbus: Not enough memory to create "
  3122. "arguments for method");
  3123. goto err;
  3124. }
  3125. arg->wpa_s = wpa_s;
  3126. arg->ssid = ssid;
  3127. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  3128. wpas_dbus_persistent_group_properties,
  3129. NULL);
  3130. if (wpa_dbus_register_object_per_iface(ctrl_iface, pgrp_obj_path,
  3131. wpa_s->ifname, obj_desc))
  3132. goto err;
  3133. wpas_dbus_signal_persistent_group_added(wpa_s, ssid->id);
  3134. return 0;
  3135. err:
  3136. free_dbus_object_desc(obj_desc);
  3137. return -1;
  3138. }
  3139. /**
  3140. * wpas_dbus_unregister_persistent_group - Unregister a persistent_group
  3141. * from dbus
  3142. * @wpa_s: wpa_supplicant interface structure
  3143. * @nid: network id
  3144. * Returns: 0 on success, -1 on failure
  3145. *
  3146. * Unregisters persistent group representing object from dbus
  3147. *
  3148. * NOTE: There is a slight issue with the semantics here. While the
  3149. * implementation simply means the persistent group is unloaded from memory,
  3150. * it should not get interpreted as the group is actually being erased/removed
  3151. * from persistent storage as well.
  3152. */
  3153. int wpas_dbus_unregister_persistent_group(struct wpa_supplicant *wpa_s,
  3154. int nid)
  3155. {
  3156. struct wpas_dbus_priv *ctrl_iface;
  3157. char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  3158. int ret;
  3159. /* Do nothing if the control interface is not turned on */
  3160. if (wpa_s == NULL || wpa_s->global == NULL ||
  3161. wpa_s->dbus_new_path == NULL)
  3162. return 0;
  3163. ctrl_iface = wpa_s->global->dbus;
  3164. if (ctrl_iface == NULL)
  3165. return 0;
  3166. os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  3167. "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
  3168. wpa_s->dbus_new_path, nid);
  3169. wpa_printf(MSG_DEBUG, "dbus: Unregister persistent group object '%s'",
  3170. pgrp_obj_path);
  3171. ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, pgrp_obj_path);
  3172. if (!ret)
  3173. wpas_dbus_signal_persistent_group_removed(wpa_s, nid);
  3174. return ret;
  3175. }
  3176. #endif /* CONFIG_P2P */