dbus_new.c 102 KB

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