dbus_new.c 100 KB

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