dbus_new.c 95 KB

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