dbus_new.c 85 KB

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