dbus_new.c 104 KB

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