dbus_new.c 101 KB

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