dbus_new.c 100 KB

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