dbus_new.c 104 KB

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