dbus_new.c 99 KB

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