dbus_new.c 94 KB

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