dbus_new.c 114 KB

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