dbus_new.c 89 KB

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