dbus_new.c 99 KB

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