dbus_new_handlers.c 97 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601
  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 program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * Alternatively, this software may be distributed under the terms of BSD
  12. * license.
  13. *
  14. * See README and COPYING for more details.
  15. */
  16. #include "includes.h"
  17. #include "common.h"
  18. #include "common/ieee802_11_defs.h"
  19. #include "eap_peer/eap_methods.h"
  20. #include "eapol_supp/eapol_supp_sm.h"
  21. #include "rsn_supp/wpa.h"
  22. #include "../config.h"
  23. #include "../wpa_supplicant_i.h"
  24. #include "../driver_i.h"
  25. #include "../notify.h"
  26. #include "../bss.h"
  27. #include "../scan.h"
  28. #include "../ctrl_iface.h"
  29. #include "../autoscan.h"
  30. #include "dbus_new_helpers.h"
  31. #include "dbus_new.h"
  32. #include "dbus_new_handlers.h"
  33. #include "dbus_dict_helpers.h"
  34. #include "dbus_common_i.h"
  35. extern int wpa_debug_level;
  36. extern int wpa_debug_show_keys;
  37. extern int wpa_debug_timestamp;
  38. static const char *debug_strings[] = {
  39. "excessive", "msgdump", "debug", "info", "warning", "error", NULL
  40. };
  41. /**
  42. * wpas_dbus_error_unknown_error - Return a new InvalidArgs error message
  43. * @message: Pointer to incoming dbus message this error refers to
  44. * @arg: Optional string appended to error message
  45. * Returns: a dbus error message
  46. *
  47. * Convenience function to create and return an UnknownError
  48. */
  49. DBusMessage * wpas_dbus_error_unknown_error(DBusMessage *message,
  50. const char *arg)
  51. {
  52. /*
  53. * This function can be called as a result of a failure
  54. * within internal getter calls, which will call this function
  55. * with a NULL message parameter. However, dbus_message_new_error
  56. * looks very unkindly (i.e, abort()) on a NULL message, so
  57. * in this case, we should not call it.
  58. */
  59. if (message == NULL) {
  60. wpa_printf(MSG_INFO, "dbus: wpas_dbus_error_unknown_error "
  61. "called with NULL message (arg=%s)",
  62. arg ? arg : "N/A");
  63. return NULL;
  64. }
  65. return dbus_message_new_error(message, WPAS_DBUS_ERROR_UNKNOWN_ERROR,
  66. arg);
  67. }
  68. /**
  69. * wpas_dbus_error_iface_unknown - Return a new invalid interface error message
  70. * @message: Pointer to incoming dbus message this error refers to
  71. * Returns: A dbus error message
  72. *
  73. * Convenience function to create and return an invalid interface error
  74. */
  75. static DBusMessage * wpas_dbus_error_iface_unknown(DBusMessage *message)
  76. {
  77. return dbus_message_new_error(message, WPAS_DBUS_ERROR_IFACE_UNKNOWN,
  78. "wpa_supplicant knows nothing about "
  79. "this interface.");
  80. }
  81. /**
  82. * wpas_dbus_error_network_unknown - Return a new NetworkUnknown error message
  83. * @message: Pointer to incoming dbus message this error refers to
  84. * Returns: a dbus error message
  85. *
  86. * Convenience function to create and return an invalid network error
  87. */
  88. static DBusMessage * wpas_dbus_error_network_unknown(DBusMessage *message)
  89. {
  90. return dbus_message_new_error(message, WPAS_DBUS_ERROR_NETWORK_UNKNOWN,
  91. "There is no such a network in this "
  92. "interface.");
  93. }
  94. /**
  95. * wpas_dbus_error_invalid_args - Return a new InvalidArgs error message
  96. * @message: Pointer to incoming dbus message this error refers to
  97. * Returns: a dbus error message
  98. *
  99. * Convenience function to create and return an invalid options error
  100. */
  101. DBusMessage * wpas_dbus_error_invalid_args(DBusMessage *message,
  102. const char *arg)
  103. {
  104. DBusMessage *reply;
  105. reply = dbus_message_new_error(message, WPAS_DBUS_ERROR_INVALID_ARGS,
  106. "Did not receive correct message "
  107. "arguments.");
  108. if (arg != NULL)
  109. dbus_message_append_args(reply, DBUS_TYPE_STRING, &arg,
  110. DBUS_TYPE_INVALID);
  111. return reply;
  112. }
  113. static const char *dont_quote[] = {
  114. "key_mgmt", "proto", "pairwise", "auth_alg", "group", "eap",
  115. "opensc_engine_path", "pkcs11_engine_path", "pkcs11_module_path",
  116. "bssid", NULL
  117. };
  118. static dbus_bool_t should_quote_opt(const char *key)
  119. {
  120. int i = 0;
  121. while (dont_quote[i] != NULL) {
  122. if (os_strcmp(key, dont_quote[i]) == 0)
  123. return FALSE;
  124. i++;
  125. }
  126. return TRUE;
  127. }
  128. /**
  129. * get_iface_by_dbus_path - Get a new network interface
  130. * @global: Pointer to global data from wpa_supplicant_init()
  131. * @path: Pointer to a dbus object path representing an interface
  132. * Returns: Pointer to the interface or %NULL if not found
  133. */
  134. static struct wpa_supplicant * get_iface_by_dbus_path(
  135. struct wpa_global *global, const char *path)
  136. {
  137. struct wpa_supplicant *wpa_s;
  138. for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
  139. if (os_strcmp(wpa_s->dbus_new_path, path) == 0)
  140. return wpa_s;
  141. }
  142. return NULL;
  143. }
  144. /**
  145. * set_network_properties - Set properties of a configured network
  146. * @wpa_s: wpa_supplicant structure for a network interface
  147. * @ssid: wpa_ssid structure for a configured network
  148. * @iter: DBus message iterator containing dictionary of network
  149. * properties to set.
  150. * @error: On failure, an error describing the failure
  151. * Returns: TRUE if the request succeeds, FALSE if it failed
  152. *
  153. * Sets network configuration with parameters given id DBus dictionary
  154. */
  155. dbus_bool_t set_network_properties(struct wpa_supplicant *wpa_s,
  156. struct wpa_ssid *ssid,
  157. DBusMessageIter *iter,
  158. DBusError *error)
  159. {
  160. struct wpa_dbus_dict_entry entry = { .type = DBUS_TYPE_STRING };
  161. DBusMessageIter iter_dict;
  162. char *value = NULL;
  163. if (!wpa_dbus_dict_open_read(iter, &iter_dict, error))
  164. return FALSE;
  165. while (wpa_dbus_dict_has_dict_entry(&iter_dict)) {
  166. size_t size = 50;
  167. int ret;
  168. if (!wpa_dbus_dict_get_entry(&iter_dict, &entry))
  169. goto error;
  170. value = NULL;
  171. if (entry.type == DBUS_TYPE_ARRAY &&
  172. entry.array_type == DBUS_TYPE_BYTE) {
  173. if (entry.array_len <= 0)
  174. goto error;
  175. size = entry.array_len * 2 + 1;
  176. value = os_zalloc(size);
  177. if (value == NULL)
  178. goto error;
  179. ret = wpa_snprintf_hex(value, size,
  180. (u8 *) entry.bytearray_value,
  181. entry.array_len);
  182. if (ret <= 0)
  183. goto error;
  184. } else if (entry.type == DBUS_TYPE_STRING) {
  185. if (should_quote_opt(entry.key)) {
  186. size = os_strlen(entry.str_value);
  187. if (size <= 0)
  188. goto error;
  189. size += 3;
  190. value = os_zalloc(size);
  191. if (value == NULL)
  192. goto error;
  193. ret = os_snprintf(value, size, "\"%s\"",
  194. entry.str_value);
  195. if (ret < 0 || (size_t) ret != (size - 1))
  196. goto error;
  197. } else {
  198. value = os_strdup(entry.str_value);
  199. if (value == NULL)
  200. goto error;
  201. }
  202. } else if (entry.type == DBUS_TYPE_UINT32) {
  203. value = os_zalloc(size);
  204. if (value == NULL)
  205. goto error;
  206. ret = os_snprintf(value, size, "%u",
  207. entry.uint32_value);
  208. if (ret <= 0)
  209. goto error;
  210. } else if (entry.type == DBUS_TYPE_INT32) {
  211. value = os_zalloc(size);
  212. if (value == NULL)
  213. goto error;
  214. ret = os_snprintf(value, size, "%d",
  215. entry.int32_value);
  216. if (ret <= 0)
  217. goto error;
  218. } else
  219. goto error;
  220. if (wpa_config_set(ssid, entry.key, value, 0) < 0)
  221. goto error;
  222. if ((os_strcmp(entry.key, "psk") == 0 &&
  223. value[0] == '"' && ssid->ssid_len) ||
  224. (os_strcmp(entry.key, "ssid") == 0 && ssid->passphrase))
  225. wpa_config_update_psk(ssid);
  226. else if (os_strcmp(entry.key, "priority") == 0)
  227. wpa_config_update_prio_list(wpa_s->conf);
  228. os_free(value);
  229. wpa_dbus_dict_entry_clear(&entry);
  230. }
  231. return TRUE;
  232. error:
  233. os_free(value);
  234. wpa_dbus_dict_entry_clear(&entry);
  235. dbus_set_error_const(error, DBUS_ERROR_INVALID_ARGS,
  236. "invalid message format");
  237. return FALSE;
  238. }
  239. /**
  240. * wpas_dbus_simple_property_getter - Get basic type property
  241. * @iter: Message iter to use when appending arguments
  242. * @type: DBus type of property (must be basic type)
  243. * @val: pointer to place holding property value
  244. * @error: On failure an error describing the failure
  245. * Returns: TRUE if the request was successful, FALSE if it failed
  246. *
  247. * Generic getter for basic type properties. Type is required to be basic.
  248. */
  249. dbus_bool_t wpas_dbus_simple_property_getter(DBusMessageIter *iter,
  250. const int type,
  251. const void *val,
  252. DBusError *error)
  253. {
  254. DBusMessageIter variant_iter;
  255. if (!dbus_type_is_basic(type)) {
  256. dbus_set_error(error, DBUS_ERROR_FAILED,
  257. "%s: given type is not basic", __func__);
  258. return FALSE;
  259. }
  260. if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
  261. wpa_dbus_type_as_string(type),
  262. &variant_iter))
  263. goto error;
  264. if (!dbus_message_iter_append_basic(&variant_iter, type, val))
  265. goto error;
  266. if (!dbus_message_iter_close_container(iter, &variant_iter))
  267. goto error;
  268. return TRUE;
  269. error:
  270. dbus_set_error(error, DBUS_ERROR_FAILED,
  271. "%s: error constructing reply", __func__);
  272. return FALSE;
  273. }
  274. /**
  275. * wpas_dbus_simple_property_setter - Set basic type property
  276. * @message: Pointer to incoming dbus message
  277. * @type: DBus type of property (must be basic type)
  278. * @val: pointer to place where value being set will be stored
  279. * Returns: TRUE if the request was successful, FALSE if it failed
  280. *
  281. * Generic setter for basic type properties. Type is required to be basic.
  282. */
  283. dbus_bool_t wpas_dbus_simple_property_setter(DBusMessageIter *iter,
  284. DBusError *error,
  285. const int type, void *val)
  286. {
  287. DBusMessageIter variant_iter;
  288. if (!dbus_type_is_basic(type)) {
  289. dbus_set_error(error, DBUS_ERROR_FAILED,
  290. "%s: given type is not basic", __func__);
  291. return FALSE;
  292. }
  293. /* Look at the new value */
  294. dbus_message_iter_recurse(iter, &variant_iter);
  295. if (dbus_message_iter_get_arg_type(&variant_iter) != type) {
  296. dbus_set_error_const(error, DBUS_ERROR_FAILED,
  297. "wrong property type");
  298. return FALSE;
  299. }
  300. dbus_message_iter_get_basic(&variant_iter, val);
  301. return TRUE;
  302. }
  303. /**
  304. * wpas_dbus_simple_array_property_getter - Get array type property
  305. * @iter: Pointer to incoming dbus message iterator
  306. * @type: DBus type of property array elements (must be basic type)
  307. * @array: pointer to array of elements to put into response message
  308. * @array_len: length of above array
  309. * @error: a pointer to an error to fill on failure
  310. * Returns: TRUE if the request succeeded, FALSE if it failed
  311. *
  312. * Generic getter for array type properties. Array elements type is
  313. * required to be basic.
  314. */
  315. dbus_bool_t wpas_dbus_simple_array_property_getter(DBusMessageIter *iter,
  316. const int type,
  317. const void *array,
  318. size_t array_len,
  319. DBusError *error)
  320. {
  321. DBusMessageIter variant_iter, array_iter;
  322. char type_str[] = "a?"; /* ? will be replaced with subtype letter; */
  323. const char *sub_type_str;
  324. size_t element_size, i;
  325. if (!dbus_type_is_basic(type)) {
  326. dbus_set_error(error, DBUS_ERROR_FAILED,
  327. "%s: given type is not basic", __func__);
  328. return FALSE;
  329. }
  330. sub_type_str = wpa_dbus_type_as_string(type);
  331. type_str[1] = sub_type_str[0];
  332. if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
  333. type_str, &variant_iter)) {
  334. dbus_set_error(error, DBUS_ERROR_FAILED,
  335. "%s: failed to construct message 1", __func__);
  336. return FALSE;
  337. }
  338. if (!dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
  339. sub_type_str, &array_iter)) {
  340. dbus_set_error(error, DBUS_ERROR_FAILED,
  341. "%s: failed to construct message 2", __func__);
  342. return FALSE;
  343. }
  344. switch(type) {
  345. case DBUS_TYPE_BYTE:
  346. case DBUS_TYPE_BOOLEAN:
  347. element_size = 1;
  348. break;
  349. case DBUS_TYPE_INT16:
  350. case DBUS_TYPE_UINT16:
  351. element_size = sizeof(uint16_t);
  352. break;
  353. case DBUS_TYPE_INT32:
  354. case DBUS_TYPE_UINT32:
  355. element_size = sizeof(uint32_t);
  356. break;
  357. case DBUS_TYPE_INT64:
  358. case DBUS_TYPE_UINT64:
  359. element_size = sizeof(uint64_t);
  360. break;
  361. case DBUS_TYPE_DOUBLE:
  362. element_size = sizeof(double);
  363. break;
  364. case DBUS_TYPE_STRING:
  365. case DBUS_TYPE_OBJECT_PATH:
  366. element_size = sizeof(char *);
  367. break;
  368. default:
  369. dbus_set_error(error, DBUS_ERROR_FAILED,
  370. "%s: unknown element type %d", __func__, type);
  371. return FALSE;
  372. }
  373. for (i = 0; i < array_len; i++) {
  374. dbus_message_iter_append_basic(&array_iter, type,
  375. array + i * element_size);
  376. }
  377. if (!dbus_message_iter_close_container(&variant_iter, &array_iter)) {
  378. dbus_set_error(error, DBUS_ERROR_FAILED,
  379. "%s: failed to construct message 3", __func__);
  380. return FALSE;
  381. }
  382. if (!dbus_message_iter_close_container(iter, &variant_iter)) {
  383. dbus_set_error(error, DBUS_ERROR_FAILED,
  384. "%s: failed to construct message 4", __func__);
  385. return FALSE;
  386. }
  387. return TRUE;
  388. }
  389. /**
  390. * wpas_dbus_simple_array_array_property_getter - Get array array type property
  391. * @iter: Pointer to incoming dbus message iterator
  392. * @type: DBus type of property array elements (must be basic type)
  393. * @array: pointer to array of elements to put into response message
  394. * @array_len: length of above array
  395. * @error: a pointer to an error to fill on failure
  396. * Returns: TRUE if the request succeeded, FALSE if it failed
  397. *
  398. * Generic getter for array type properties. Array elements type is
  399. * required to be basic.
  400. */
  401. dbus_bool_t wpas_dbus_simple_array_array_property_getter(DBusMessageIter *iter,
  402. const int type,
  403. struct wpabuf **array,
  404. size_t array_len,
  405. DBusError *error)
  406. {
  407. DBusMessageIter variant_iter, array_iter;
  408. char type_str[] = "aa?";
  409. char inner_type_str[] = "a?";
  410. const char *sub_type_str;
  411. size_t i;
  412. if (!dbus_type_is_basic(type)) {
  413. dbus_set_error(error, DBUS_ERROR_FAILED,
  414. "%s: given type is not basic", __func__);
  415. return FALSE;
  416. }
  417. sub_type_str = wpa_dbus_type_as_string(type);
  418. type_str[2] = sub_type_str[0];
  419. inner_type_str[1] = sub_type_str[0];
  420. if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
  421. type_str, &variant_iter)) {
  422. dbus_set_error(error, DBUS_ERROR_FAILED,
  423. "%s: failed to construct message 1", __func__);
  424. return FALSE;
  425. }
  426. if (!dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
  427. inner_type_str, &array_iter)) {
  428. dbus_set_error(error, DBUS_ERROR_FAILED,
  429. "%s: failed to construct message 2", __func__);
  430. return FALSE;
  431. }
  432. for (i = 0; i < array_len; i++) {
  433. wpa_dbus_dict_bin_array_add_element(&array_iter,
  434. wpabuf_head(array[i]),
  435. wpabuf_len(array[i]));
  436. }
  437. if (!dbus_message_iter_close_container(&variant_iter, &array_iter)) {
  438. dbus_set_error(error, DBUS_ERROR_FAILED,
  439. "%s: failed to close message 2", __func__);
  440. return FALSE;
  441. }
  442. if (!dbus_message_iter_close_container(iter, &variant_iter)) {
  443. dbus_set_error(error, DBUS_ERROR_FAILED,
  444. "%s: failed to close message 1", __func__);
  445. return FALSE;
  446. }
  447. return TRUE;
  448. }
  449. /**
  450. * wpas_dbus_handler_create_interface - Request registration of a network iface
  451. * @message: Pointer to incoming dbus message
  452. * @global: %wpa_supplicant global data structure
  453. * Returns: The object path of the new interface object,
  454. * or a dbus error message with more information
  455. *
  456. * Handler function for "CreateInterface" method call. Handles requests
  457. * by dbus clients to register a network interface that wpa_supplicant
  458. * will manage.
  459. */
  460. DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message,
  461. struct wpa_global *global)
  462. {
  463. DBusMessageIter iter_dict;
  464. DBusMessage *reply = NULL;
  465. DBusMessageIter iter;
  466. struct wpa_dbus_dict_entry entry;
  467. char *driver = NULL;
  468. char *ifname = NULL;
  469. char *confname = NULL;
  470. char *bridge_ifname = NULL;
  471. dbus_message_iter_init(message, &iter);
  472. if (!wpa_dbus_dict_open_read(&iter, &iter_dict, NULL))
  473. goto error;
  474. while (wpa_dbus_dict_has_dict_entry(&iter_dict)) {
  475. if (!wpa_dbus_dict_get_entry(&iter_dict, &entry))
  476. goto error;
  477. if (!os_strcmp(entry.key, "Driver") &&
  478. (entry.type == DBUS_TYPE_STRING)) {
  479. driver = os_strdup(entry.str_value);
  480. wpa_dbus_dict_entry_clear(&entry);
  481. if (driver == NULL)
  482. goto error;
  483. } else if (!os_strcmp(entry.key, "Ifname") &&
  484. (entry.type == DBUS_TYPE_STRING)) {
  485. ifname = os_strdup(entry.str_value);
  486. wpa_dbus_dict_entry_clear(&entry);
  487. if (ifname == NULL)
  488. goto error;
  489. } else if (!os_strcmp(entry.key, "ConfigFile") &&
  490. (entry.type == DBUS_TYPE_STRING)) {
  491. confname = os_strdup(entry.str_value);
  492. wpa_dbus_dict_entry_clear(&entry);
  493. if (confname == NULL)
  494. goto error;
  495. } else if (!os_strcmp(entry.key, "BridgeIfname") &&
  496. (entry.type == DBUS_TYPE_STRING)) {
  497. bridge_ifname = os_strdup(entry.str_value);
  498. wpa_dbus_dict_entry_clear(&entry);
  499. if (bridge_ifname == NULL)
  500. goto error;
  501. } else {
  502. wpa_dbus_dict_entry_clear(&entry);
  503. goto error;
  504. }
  505. }
  506. if (ifname == NULL)
  507. goto error; /* Required Ifname argument missing */
  508. /*
  509. * Try to get the wpa_supplicant record for this iface, return
  510. * an error if we already control it.
  511. */
  512. if (wpa_supplicant_get_iface(global, ifname) != NULL) {
  513. reply = dbus_message_new_error(message,
  514. WPAS_DBUS_ERROR_IFACE_EXISTS,
  515. "wpa_supplicant already "
  516. "controls this interface.");
  517. } else {
  518. struct wpa_supplicant *wpa_s;
  519. struct wpa_interface iface;
  520. os_memset(&iface, 0, sizeof(iface));
  521. iface.driver = driver;
  522. iface.ifname = ifname;
  523. iface.confname = confname;
  524. iface.bridge_ifname = bridge_ifname;
  525. /* Otherwise, have wpa_supplicant attach to it. */
  526. if ((wpa_s = wpa_supplicant_add_iface(global, &iface))) {
  527. const char *path = wpa_s->dbus_new_path;
  528. reply = dbus_message_new_method_return(message);
  529. dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH,
  530. &path, DBUS_TYPE_INVALID);
  531. } else {
  532. reply = wpas_dbus_error_unknown_error(
  533. message, "wpa_supplicant couldn't grab this "
  534. "interface.");
  535. }
  536. }
  537. out:
  538. os_free(driver);
  539. os_free(ifname);
  540. os_free(bridge_ifname);
  541. return reply;
  542. error:
  543. reply = wpas_dbus_error_invalid_args(message, NULL);
  544. goto out;
  545. }
  546. /**
  547. * wpas_dbus_handler_remove_interface - Request deregistration of an interface
  548. * @message: Pointer to incoming dbus message
  549. * @global: wpa_supplicant global data structure
  550. * Returns: a dbus message containing a UINT32 indicating success (1) or
  551. * failure (0), or returns a dbus error message with more information
  552. *
  553. * Handler function for "removeInterface" method call. Handles requests
  554. * by dbus clients to deregister a network interface that wpa_supplicant
  555. * currently manages.
  556. */
  557. DBusMessage * wpas_dbus_handler_remove_interface(DBusMessage *message,
  558. struct wpa_global *global)
  559. {
  560. struct wpa_supplicant *wpa_s;
  561. char *path;
  562. DBusMessage *reply = NULL;
  563. dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path,
  564. DBUS_TYPE_INVALID);
  565. wpa_s = get_iface_by_dbus_path(global, path);
  566. if (wpa_s == NULL)
  567. reply = wpas_dbus_error_iface_unknown(message);
  568. else if (wpa_supplicant_remove_iface(global, wpa_s, 0)) {
  569. reply = wpas_dbus_error_unknown_error(
  570. message, "wpa_supplicant couldn't remove this "
  571. "interface.");
  572. }
  573. return reply;
  574. }
  575. /**
  576. * wpas_dbus_handler_get_interface - Get the object path for an interface name
  577. * @message: Pointer to incoming dbus message
  578. * @global: %wpa_supplicant global data structure
  579. * Returns: The object path of the interface object,
  580. * or a dbus error message with more information
  581. *
  582. * Handler function for "getInterface" method call.
  583. */
  584. DBusMessage * wpas_dbus_handler_get_interface(DBusMessage *message,
  585. struct wpa_global *global)
  586. {
  587. DBusMessage *reply = NULL;
  588. const char *ifname;
  589. const char *path;
  590. struct wpa_supplicant *wpa_s;
  591. dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &ifname,
  592. DBUS_TYPE_INVALID);
  593. wpa_s = wpa_supplicant_get_iface(global, ifname);
  594. if (wpa_s == NULL)
  595. return wpas_dbus_error_iface_unknown(message);
  596. path = wpa_s->dbus_new_path;
  597. reply = dbus_message_new_method_return(message);
  598. if (reply == NULL)
  599. return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  600. NULL);
  601. if (!dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path,
  602. DBUS_TYPE_INVALID)) {
  603. dbus_message_unref(reply);
  604. return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  605. NULL);
  606. }
  607. return reply;
  608. }
  609. /**
  610. * wpas_dbus_getter_debug_level - Get debug level
  611. * @iter: Pointer to incoming dbus message iter
  612. * @error: Location to store error on failure
  613. * @user_data: Function specific data
  614. * Returns: TRUE on success, FALSE on failure
  615. *
  616. * Getter for "DebugLevel" property.
  617. */
  618. dbus_bool_t wpas_dbus_getter_debug_level(DBusMessageIter *iter,
  619. DBusError *error,
  620. void *user_data)
  621. {
  622. const char *str;
  623. int idx = wpa_debug_level;
  624. if (idx < 0)
  625. idx = 0;
  626. if (idx > 5)
  627. idx = 5;
  628. str = debug_strings[idx];
  629. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
  630. &str, error);
  631. }
  632. /**
  633. * wpas_dbus_getter_debug_timestamp - Get debug timestamp
  634. * @iter: Pointer to incoming dbus message iter
  635. * @error: Location to store error on failure
  636. * @user_data: Function specific data
  637. * Returns: TRUE on success, FALSE on failure
  638. *
  639. * Getter for "DebugTimestamp" property.
  640. */
  641. dbus_bool_t wpas_dbus_getter_debug_timestamp(DBusMessageIter *iter,
  642. DBusError *error,
  643. void *user_data)
  644. {
  645. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
  646. &wpa_debug_timestamp, error);
  647. }
  648. /**
  649. * wpas_dbus_getter_debug_show_keys - Get debug show keys
  650. * @iter: Pointer to incoming dbus message iter
  651. * @error: Location to store error on failure
  652. * @user_data: Function specific data
  653. * Returns: TRUE on success, FALSE on failure
  654. *
  655. * Getter for "DebugShowKeys" property.
  656. */
  657. dbus_bool_t wpas_dbus_getter_debug_show_keys(DBusMessageIter *iter,
  658. DBusError *error,
  659. void *user_data)
  660. {
  661. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
  662. &wpa_debug_show_keys, error);
  663. }
  664. /**
  665. * wpas_dbus_setter_debug_level - Set debug level
  666. * @iter: Pointer to incoming dbus message iter
  667. * @error: Location to store error on failure
  668. * @user_data: Function specific data
  669. * Returns: TRUE on success, FALSE on failure
  670. *
  671. * Setter for "DebugLevel" property.
  672. */
  673. dbus_bool_t wpas_dbus_setter_debug_level(DBusMessageIter *iter,
  674. DBusError *error, void *user_data)
  675. {
  676. struct wpa_global *global = user_data;
  677. const char *str = NULL;
  678. int i, val = -1;
  679. if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_STRING,
  680. &str))
  681. return FALSE;
  682. for (i = 0; debug_strings[i]; i++)
  683. if (os_strcmp(debug_strings[i], str) == 0) {
  684. val = i;
  685. break;
  686. }
  687. if (val < 0 ||
  688. wpa_supplicant_set_debug_params(global, val, wpa_debug_timestamp,
  689. wpa_debug_show_keys)) {
  690. dbus_set_error_const(error, DBUS_ERROR_FAILED, "wrong debug "
  691. "level value");
  692. return FALSE;
  693. }
  694. return TRUE;
  695. }
  696. /**
  697. * wpas_dbus_setter_debug_timestamp - Set debug timestamp
  698. * @iter: Pointer to incoming dbus message iter
  699. * @error: Location to store error on failure
  700. * @user_data: Function specific data
  701. * Returns: TRUE on success, FALSE on failure
  702. *
  703. * Setter for "DebugTimestamp" property.
  704. */
  705. dbus_bool_t wpas_dbus_setter_debug_timestamp(DBusMessageIter *iter,
  706. DBusError *error,
  707. void *user_data)
  708. {
  709. struct wpa_global *global = user_data;
  710. dbus_bool_t val;
  711. if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_BOOLEAN,
  712. &val))
  713. return FALSE;
  714. wpa_supplicant_set_debug_params(global, wpa_debug_level, val ? 1 : 0,
  715. wpa_debug_show_keys);
  716. return TRUE;
  717. }
  718. /**
  719. * wpas_dbus_setter_debug_show_keys - Set debug show keys
  720. * @iter: Pointer to incoming dbus message iter
  721. * @error: Location to store error on failure
  722. * @user_data: Function specific data
  723. * Returns: TRUE on success, FALSE on failure
  724. *
  725. * Setter for "DebugShowKeys" property.
  726. */
  727. dbus_bool_t wpas_dbus_setter_debug_show_keys(DBusMessageIter *iter,
  728. DBusError *error,
  729. void *user_data)
  730. {
  731. struct wpa_global *global = user_data;
  732. dbus_bool_t val;
  733. if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_BOOLEAN,
  734. &val))
  735. return FALSE;
  736. wpa_supplicant_set_debug_params(global, wpa_debug_level,
  737. wpa_debug_timestamp,
  738. val ? 1 : 0);
  739. return TRUE;
  740. }
  741. /**
  742. * wpas_dbus_getter_interfaces - Request registered interfaces list
  743. * @iter: Pointer to incoming dbus message iter
  744. * @error: Location to store error on failure
  745. * @user_data: Function specific data
  746. * Returns: TRUE on success, FALSE on failure
  747. *
  748. * Getter for "Interfaces" property. Handles requests
  749. * by dbus clients to return list of registered interfaces objects
  750. * paths
  751. */
  752. dbus_bool_t wpas_dbus_getter_interfaces(DBusMessageIter *iter,
  753. DBusError *error,
  754. void *user_data)
  755. {
  756. struct wpa_global *global = user_data;
  757. struct wpa_supplicant *wpa_s;
  758. const char **paths;
  759. unsigned int i = 0, num = 0;
  760. dbus_bool_t success;
  761. for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
  762. num++;
  763. paths = os_zalloc(num * sizeof(char*));
  764. if (!paths) {
  765. dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
  766. return FALSE;
  767. }
  768. for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
  769. paths[i++] = wpa_s->dbus_new_path;
  770. success = wpas_dbus_simple_array_property_getter(iter,
  771. DBUS_TYPE_OBJECT_PATH,
  772. paths, num, error);
  773. os_free(paths);
  774. return success;
  775. }
  776. /**
  777. * wpas_dbus_getter_eap_methods - Request supported EAP methods list
  778. * @iter: Pointer to incoming dbus message iter
  779. * @error: Location to store error on failure
  780. * @user_data: Function specific data
  781. * Returns: TRUE on success, FALSE on failure
  782. *
  783. * Getter for "EapMethods" property. Handles requests
  784. * by dbus clients to return list of strings with supported EAP methods
  785. */
  786. dbus_bool_t wpas_dbus_getter_eap_methods(DBusMessageIter *iter,
  787. DBusError *error, void *user_data)
  788. {
  789. char **eap_methods;
  790. size_t num_items = 0;
  791. dbus_bool_t success;
  792. eap_methods = eap_get_names_as_string_array(&num_items);
  793. if (!eap_methods) {
  794. dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
  795. return FALSE;
  796. }
  797. success = wpas_dbus_simple_array_property_getter(iter,
  798. DBUS_TYPE_STRING,
  799. eap_methods,
  800. num_items, error);
  801. while (num_items)
  802. os_free(eap_methods[--num_items]);
  803. os_free(eap_methods);
  804. return success;
  805. }
  806. static int wpas_dbus_get_scan_type(DBusMessage *message, DBusMessageIter *var,
  807. char **type, DBusMessage **reply)
  808. {
  809. if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_STRING) {
  810. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
  811. "Type must be a string");
  812. *reply = wpas_dbus_error_invalid_args(
  813. message, "Wrong Type value type. String required");
  814. return -1;
  815. }
  816. dbus_message_iter_get_basic(var, type);
  817. return 0;
  818. }
  819. static int wpas_dbus_get_scan_ssids(DBusMessage *message, DBusMessageIter *var,
  820. struct wpa_driver_scan_params *params,
  821. DBusMessage **reply)
  822. {
  823. struct wpa_driver_scan_ssid *ssids = params->ssids;
  824. size_t ssids_num = 0;
  825. u8 *ssid;
  826. DBusMessageIter array_iter, sub_array_iter;
  827. char *val;
  828. int len;
  829. if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_ARRAY) {
  830. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: ssids "
  831. "must be an array of arrays of bytes");
  832. *reply = wpas_dbus_error_invalid_args(
  833. message, "Wrong SSIDs value type. Array of arrays of "
  834. "bytes required");
  835. return -1;
  836. }
  837. dbus_message_iter_recurse(var, &array_iter);
  838. if (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_ARRAY ||
  839. dbus_message_iter_get_element_type(&array_iter) != DBUS_TYPE_BYTE)
  840. {
  841. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: ssids "
  842. "must be an array of arrays of bytes");
  843. *reply = wpas_dbus_error_invalid_args(
  844. message, "Wrong SSIDs value type. Array of arrays of "
  845. "bytes required");
  846. return -1;
  847. }
  848. while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_ARRAY)
  849. {
  850. if (ssids_num >= WPAS_MAX_SCAN_SSIDS) {
  851. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
  852. "Too many ssids specified on scan dbus "
  853. "call");
  854. *reply = wpas_dbus_error_invalid_args(
  855. message, "Too many ssids specified. Specify "
  856. "at most four");
  857. return -1;
  858. }
  859. dbus_message_iter_recurse(&array_iter, &sub_array_iter);
  860. dbus_message_iter_get_fixed_array(&sub_array_iter, &val, &len);
  861. if (len > MAX_SSID_LEN) {
  862. wpa_printf(MSG_DEBUG,
  863. "wpas_dbus_handler_scan[dbus]: "
  864. "SSID too long (len=%d max_len=%d)",
  865. len, MAX_SSID_LEN);
  866. *reply = wpas_dbus_error_invalid_args(
  867. message, "Invalid SSID: too long");
  868. return -1;
  869. }
  870. if (len != 0) {
  871. ssid = os_malloc(len);
  872. if (ssid == NULL) {
  873. wpa_printf(MSG_DEBUG,
  874. "wpas_dbus_handler_scan[dbus]: "
  875. "out of memory. Cannot allocate "
  876. "memory for SSID");
  877. *reply = dbus_message_new_error(
  878. message, DBUS_ERROR_NO_MEMORY, NULL);
  879. return -1;
  880. }
  881. os_memcpy(ssid, val, len);
  882. } else {
  883. /* Allow zero-length SSIDs */
  884. ssid = NULL;
  885. }
  886. ssids[ssids_num].ssid = ssid;
  887. ssids[ssids_num].ssid_len = len;
  888. dbus_message_iter_next(&array_iter);
  889. ssids_num++;
  890. }
  891. params->num_ssids = ssids_num;
  892. return 0;
  893. }
  894. static int wpas_dbus_get_scan_ies(DBusMessage *message, DBusMessageIter *var,
  895. struct wpa_driver_scan_params *params,
  896. DBusMessage **reply)
  897. {
  898. u8 *ies = NULL, *nies;
  899. int ies_len = 0;
  900. DBusMessageIter array_iter, sub_array_iter;
  901. char *val;
  902. int len;
  903. if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_ARRAY) {
  904. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: ies must "
  905. "be an array of arrays of bytes");
  906. *reply = wpas_dbus_error_invalid_args(
  907. message, "Wrong IEs value type. Array of arrays of "
  908. "bytes required");
  909. return -1;
  910. }
  911. dbus_message_iter_recurse(var, &array_iter);
  912. if (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_ARRAY ||
  913. dbus_message_iter_get_element_type(&array_iter) != DBUS_TYPE_BYTE)
  914. {
  915. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: ies must "
  916. "be an array of arrays of bytes");
  917. *reply = wpas_dbus_error_invalid_args(
  918. message, "Wrong IEs value type. Array required");
  919. return -1;
  920. }
  921. while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_ARRAY)
  922. {
  923. dbus_message_iter_recurse(&array_iter, &sub_array_iter);
  924. dbus_message_iter_get_fixed_array(&sub_array_iter, &val, &len);
  925. if (len == 0) {
  926. dbus_message_iter_next(&array_iter);
  927. continue;
  928. }
  929. nies = os_realloc(ies, ies_len + len);
  930. if (nies == NULL) {
  931. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
  932. "out of memory. Cannot allocate memory for "
  933. "IE");
  934. os_free(ies);
  935. *reply = dbus_message_new_error(
  936. message, DBUS_ERROR_NO_MEMORY, NULL);
  937. return -1;
  938. }
  939. ies = nies;
  940. os_memcpy(ies + ies_len, val, len);
  941. ies_len += len;
  942. dbus_message_iter_next(&array_iter);
  943. }
  944. params->extra_ies = ies;
  945. params->extra_ies_len = ies_len;
  946. return 0;
  947. }
  948. static int wpas_dbus_get_scan_channels(DBusMessage *message,
  949. DBusMessageIter *var,
  950. struct wpa_driver_scan_params *params,
  951. DBusMessage **reply)
  952. {
  953. DBusMessageIter array_iter, sub_array_iter;
  954. int *freqs = NULL, *nfreqs;
  955. int freqs_num = 0;
  956. if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_ARRAY) {
  957. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
  958. "Channels must be an array of structs");
  959. *reply = wpas_dbus_error_invalid_args(
  960. message, "Wrong Channels value type. Array of structs "
  961. "required");
  962. return -1;
  963. }
  964. dbus_message_iter_recurse(var, &array_iter);
  965. if (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_STRUCT) {
  966. wpa_printf(MSG_DEBUG,
  967. "wpas_dbus_handler_scan[dbus]: Channels must be an "
  968. "array of structs");
  969. *reply = wpas_dbus_error_invalid_args(
  970. message, "Wrong Channels value type. Array of structs "
  971. "required");
  972. return -1;
  973. }
  974. while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_STRUCT)
  975. {
  976. int freq, width;
  977. dbus_message_iter_recurse(&array_iter, &sub_array_iter);
  978. if (dbus_message_iter_get_arg_type(&sub_array_iter) !=
  979. DBUS_TYPE_UINT32) {
  980. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
  981. "Channel must by specified by struct of "
  982. "two UINT32s %c",
  983. dbus_message_iter_get_arg_type(
  984. &sub_array_iter));
  985. *reply = wpas_dbus_error_invalid_args(
  986. message, "Wrong Channel struct. Two UINT32s "
  987. "required");
  988. os_free(freqs);
  989. return -1;
  990. }
  991. dbus_message_iter_get_basic(&sub_array_iter, &freq);
  992. if (!dbus_message_iter_next(&sub_array_iter) ||
  993. dbus_message_iter_get_arg_type(&sub_array_iter) !=
  994. DBUS_TYPE_UINT32) {
  995. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
  996. "Channel must by specified by struct of "
  997. "two UINT32s");
  998. *reply = wpas_dbus_error_invalid_args(
  999. message,
  1000. "Wrong Channel struct. Two UINT32s required");
  1001. os_free(freqs);
  1002. return -1;
  1003. }
  1004. dbus_message_iter_get_basic(&sub_array_iter, &width);
  1005. #define FREQS_ALLOC_CHUNK 32
  1006. if (freqs_num % FREQS_ALLOC_CHUNK == 0) {
  1007. nfreqs = os_realloc(freqs, sizeof(int) *
  1008. (freqs_num + FREQS_ALLOC_CHUNK));
  1009. if (nfreqs == NULL)
  1010. os_free(freqs);
  1011. freqs = nfreqs;
  1012. }
  1013. if (freqs == NULL) {
  1014. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
  1015. "out of memory. can't allocate memory for "
  1016. "freqs");
  1017. *reply = dbus_message_new_error(
  1018. message, DBUS_ERROR_NO_MEMORY, NULL);
  1019. return -1;
  1020. }
  1021. freqs[freqs_num] = freq;
  1022. freqs_num++;
  1023. dbus_message_iter_next(&array_iter);
  1024. }
  1025. nfreqs = os_realloc(freqs,
  1026. sizeof(int) * (freqs_num + 1));
  1027. if (nfreqs == NULL)
  1028. os_free(freqs);
  1029. freqs = nfreqs;
  1030. if (freqs == NULL) {
  1031. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
  1032. "out of memory. Can't allocate memory for freqs");
  1033. *reply = dbus_message_new_error(
  1034. message, DBUS_ERROR_NO_MEMORY, NULL);
  1035. return -1;
  1036. }
  1037. freqs[freqs_num] = 0;
  1038. params->freqs = freqs;
  1039. return 0;
  1040. }
  1041. /**
  1042. * wpas_dbus_handler_scan - Request a wireless scan on an interface
  1043. * @message: Pointer to incoming dbus message
  1044. * @wpa_s: wpa_supplicant structure for a network interface
  1045. * Returns: NULL indicating success or DBus error message on failure
  1046. *
  1047. * Handler function for "Scan" method call of a network device. Requests
  1048. * that wpa_supplicant perform a wireless scan as soon as possible
  1049. * on a particular wireless interface.
  1050. */
  1051. DBusMessage * wpas_dbus_handler_scan(DBusMessage *message,
  1052. struct wpa_supplicant *wpa_s)
  1053. {
  1054. DBusMessage *reply = NULL;
  1055. DBusMessageIter iter, dict_iter, entry_iter, variant_iter;
  1056. char *key = NULL, *type = NULL;
  1057. struct wpa_driver_scan_params params;
  1058. size_t i;
  1059. os_memset(&params, 0, sizeof(params));
  1060. dbus_message_iter_init(message, &iter);
  1061. dbus_message_iter_recurse(&iter, &dict_iter);
  1062. while (dbus_message_iter_get_arg_type(&dict_iter) ==
  1063. DBUS_TYPE_DICT_ENTRY) {
  1064. dbus_message_iter_recurse(&dict_iter, &entry_iter);
  1065. dbus_message_iter_get_basic(&entry_iter, &key);
  1066. dbus_message_iter_next(&entry_iter);
  1067. dbus_message_iter_recurse(&entry_iter, &variant_iter);
  1068. if (os_strcmp(key, "Type") == 0) {
  1069. if (wpas_dbus_get_scan_type(message, &variant_iter,
  1070. &type, &reply) < 0)
  1071. goto out;
  1072. } else if (os_strcmp(key, "SSIDs") == 0) {
  1073. if (wpas_dbus_get_scan_ssids(message, &variant_iter,
  1074. &params, &reply) < 0)
  1075. goto out;
  1076. } else if (os_strcmp(key, "IEs") == 0) {
  1077. if (wpas_dbus_get_scan_ies(message, &variant_iter,
  1078. &params, &reply) < 0)
  1079. goto out;
  1080. } else if (os_strcmp(key, "Channels") == 0) {
  1081. if (wpas_dbus_get_scan_channels(message, &variant_iter,
  1082. &params, &reply) < 0)
  1083. goto out;
  1084. } else {
  1085. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
  1086. "Unknown argument %s", key);
  1087. reply = wpas_dbus_error_invalid_args(message, key);
  1088. goto out;
  1089. }
  1090. dbus_message_iter_next(&dict_iter);
  1091. }
  1092. if (!type) {
  1093. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
  1094. "Scan type not specified");
  1095. reply = wpas_dbus_error_invalid_args(message, key);
  1096. goto out;
  1097. }
  1098. if (!os_strcmp(type, "passive")) {
  1099. if (params.num_ssids || params.extra_ies_len) {
  1100. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
  1101. "SSIDs or IEs specified for passive scan.");
  1102. reply = wpas_dbus_error_invalid_args(
  1103. message, "You can specify only Channels in "
  1104. "passive scan");
  1105. goto out;
  1106. } else if (params.freqs && params.freqs[0]) {
  1107. wpa_supplicant_trigger_scan(wpa_s, &params);
  1108. } else {
  1109. wpa_s->scan_req = 2;
  1110. wpa_supplicant_req_scan(wpa_s, 0, 0);
  1111. }
  1112. } else if (!os_strcmp(type, "active")) {
  1113. if (!params.num_ssids) {
  1114. /* Add wildcard ssid */
  1115. params.num_ssids++;
  1116. }
  1117. #ifdef CONFIG_AUTOSCAN
  1118. autoscan_deinit(wpa_s);
  1119. #endif /* CONFIG_AUTOSCAN */
  1120. wpa_supplicant_trigger_scan(wpa_s, &params);
  1121. } else {
  1122. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
  1123. "Unknown scan type: %s", type);
  1124. reply = wpas_dbus_error_invalid_args(message,
  1125. "Wrong scan type");
  1126. goto out;
  1127. }
  1128. out:
  1129. for (i = 0; i < WPAS_MAX_SCAN_SSIDS; i++)
  1130. os_free((u8 *) params.ssids[i].ssid);
  1131. os_free((u8 *) params.extra_ies);
  1132. os_free(params.freqs);
  1133. return reply;
  1134. }
  1135. /*
  1136. * wpas_dbus_handler_disconnect - Terminate the current connection
  1137. * @message: Pointer to incoming dbus message
  1138. * @wpa_s: wpa_supplicant structure for a network interface
  1139. * Returns: NotConnected DBus error message if already not connected
  1140. * or NULL otherwise.
  1141. *
  1142. * Handler function for "Disconnect" method call of network interface.
  1143. */
  1144. DBusMessage * wpas_dbus_handler_disconnect(DBusMessage *message,
  1145. struct wpa_supplicant *wpa_s)
  1146. {
  1147. if (wpa_s->current_ssid != NULL) {
  1148. wpa_s->disconnected = 1;
  1149. wpa_supplicant_deauthenticate(wpa_s,
  1150. WLAN_REASON_DEAUTH_LEAVING);
  1151. return NULL;
  1152. }
  1153. return dbus_message_new_error(message, WPAS_DBUS_ERROR_NOT_CONNECTED,
  1154. "This interface is not connected");
  1155. }
  1156. /**
  1157. * wpas_dbus_new_iface_add_network - Add a new configured network
  1158. * @message: Pointer to incoming dbus message
  1159. * @wpa_s: wpa_supplicant structure for a network interface
  1160. * Returns: A dbus message containing the object path of the new network
  1161. *
  1162. * Handler function for "AddNetwork" method call of a network interface.
  1163. */
  1164. DBusMessage * wpas_dbus_handler_add_network(DBusMessage *message,
  1165. struct wpa_supplicant *wpa_s)
  1166. {
  1167. DBusMessage *reply = NULL;
  1168. DBusMessageIter iter;
  1169. struct wpa_ssid *ssid = NULL;
  1170. char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *path = path_buf;
  1171. DBusError error;
  1172. dbus_message_iter_init(message, &iter);
  1173. ssid = wpa_config_add_network(wpa_s->conf);
  1174. if (ssid == NULL) {
  1175. wpa_printf(MSG_ERROR, "wpas_dbus_handler_add_network[dbus]: "
  1176. "can't add new interface.");
  1177. reply = wpas_dbus_error_unknown_error(
  1178. message,
  1179. "wpa_supplicant could not add "
  1180. "a network on this interface.");
  1181. goto err;
  1182. }
  1183. wpas_notify_network_added(wpa_s, ssid);
  1184. ssid->disabled = 1;
  1185. wpa_config_set_network_defaults(ssid);
  1186. dbus_error_init(&error);
  1187. if (!set_network_properties(wpa_s, ssid, &iter, &error)) {
  1188. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_add_network[dbus]:"
  1189. "control interface couldn't set network "
  1190. "properties");
  1191. reply = wpas_dbus_reply_new_from_error(message, &error,
  1192. DBUS_ERROR_INVALID_ARGS,
  1193. "Failed to add network");
  1194. dbus_error_free(&error);
  1195. goto err;
  1196. }
  1197. /* Construct the object path for this network. */
  1198. os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
  1199. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
  1200. wpa_s->dbus_new_path, ssid->id);
  1201. reply = dbus_message_new_method_return(message);
  1202. if (reply == NULL) {
  1203. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1204. NULL);
  1205. goto err;
  1206. }
  1207. if (!dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path,
  1208. DBUS_TYPE_INVALID)) {
  1209. dbus_message_unref(reply);
  1210. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1211. NULL);
  1212. goto err;
  1213. }
  1214. return reply;
  1215. err:
  1216. if (ssid) {
  1217. wpas_notify_network_removed(wpa_s, ssid);
  1218. wpa_config_remove_network(wpa_s->conf, ssid->id);
  1219. }
  1220. return reply;
  1221. }
  1222. /**
  1223. * wpas_dbus_handler_remove_network - Remove a configured network
  1224. * @message: Pointer to incoming dbus message
  1225. * @wpa_s: wpa_supplicant structure for a network interface
  1226. * Returns: NULL on success or dbus error on failure
  1227. *
  1228. * Handler function for "RemoveNetwork" method call of a network interface.
  1229. */
  1230. DBusMessage * wpas_dbus_handler_remove_network(DBusMessage *message,
  1231. struct wpa_supplicant *wpa_s)
  1232. {
  1233. DBusMessage *reply = NULL;
  1234. const char *op;
  1235. char *iface = NULL, *net_id = NULL;
  1236. int id;
  1237. struct wpa_ssid *ssid;
  1238. dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &op,
  1239. DBUS_TYPE_INVALID);
  1240. /* Extract the network ID and ensure the network */
  1241. /* is actually a child of this interface */
  1242. iface = wpas_dbus_new_decompose_object_path(op, 0, &net_id, NULL);
  1243. if (iface == NULL || os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
  1244. reply = wpas_dbus_error_invalid_args(message, op);
  1245. goto out;
  1246. }
  1247. id = strtoul(net_id, NULL, 10);
  1248. if (errno == EINVAL) {
  1249. reply = wpas_dbus_error_invalid_args(message, op);
  1250. goto out;
  1251. }
  1252. ssid = wpa_config_get_network(wpa_s->conf, id);
  1253. if (ssid == NULL) {
  1254. reply = wpas_dbus_error_network_unknown(message);
  1255. goto out;
  1256. }
  1257. wpas_notify_network_removed(wpa_s, ssid);
  1258. if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
  1259. wpa_printf(MSG_ERROR,
  1260. "wpas_dbus_handler_remove_network[dbus]: "
  1261. "error occurred when removing network %d", id);
  1262. reply = wpas_dbus_error_unknown_error(
  1263. message, "error removing the specified network on "
  1264. "this interface.");
  1265. goto out;
  1266. }
  1267. if (ssid == wpa_s->current_ssid)
  1268. wpa_supplicant_deauthenticate(wpa_s,
  1269. WLAN_REASON_DEAUTH_LEAVING);
  1270. out:
  1271. os_free(iface);
  1272. os_free(net_id);
  1273. return reply;
  1274. }
  1275. static void remove_network(void *arg, struct wpa_ssid *ssid)
  1276. {
  1277. struct wpa_supplicant *wpa_s = arg;
  1278. wpas_notify_network_removed(wpa_s, ssid);
  1279. if (wpa_config_remove_network(wpa_s->conf, ssid->id) < 0) {
  1280. wpa_printf(MSG_ERROR,
  1281. "wpas_dbus_handler_remove_all_networks[dbus]: "
  1282. "error occurred when removing network %d",
  1283. ssid->id);
  1284. return;
  1285. }
  1286. if (ssid == wpa_s->current_ssid)
  1287. wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1288. }
  1289. /**
  1290. * wpas_dbus_handler_remove_all_networks - Remove all configured networks
  1291. * @message: Pointer to incoming dbus message
  1292. * @wpa_s: wpa_supplicant structure for a network interface
  1293. * Returns: NULL on success or dbus error on failure
  1294. *
  1295. * Handler function for "RemoveAllNetworks" method call of a network interface.
  1296. */
  1297. DBusMessage * wpas_dbus_handler_remove_all_networks(
  1298. DBusMessage *message, struct wpa_supplicant *wpa_s)
  1299. {
  1300. /* NB: could check for failure and return an error */
  1301. wpa_config_foreach_network(wpa_s->conf, remove_network, wpa_s);
  1302. return NULL;
  1303. }
  1304. /**
  1305. * wpas_dbus_handler_select_network - Attempt association with a network
  1306. * @message: Pointer to incoming dbus message
  1307. * @wpa_s: wpa_supplicant structure for a network interface
  1308. * Returns: NULL on success or dbus error on failure
  1309. *
  1310. * Handler function for "SelectNetwork" method call of network interface.
  1311. */
  1312. DBusMessage * wpas_dbus_handler_select_network(DBusMessage *message,
  1313. struct wpa_supplicant *wpa_s)
  1314. {
  1315. DBusMessage *reply = NULL;
  1316. const char *op;
  1317. char *iface = NULL, *net_id = NULL;
  1318. int id;
  1319. struct wpa_ssid *ssid;
  1320. dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &op,
  1321. DBUS_TYPE_INVALID);
  1322. /* Extract the network ID and ensure the network */
  1323. /* is actually a child of this interface */
  1324. iface = wpas_dbus_new_decompose_object_path(op, 0, &net_id, NULL);
  1325. if (iface == NULL || os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
  1326. reply = wpas_dbus_error_invalid_args(message, op);
  1327. goto out;
  1328. }
  1329. id = strtoul(net_id, NULL, 10);
  1330. if (errno == EINVAL) {
  1331. reply = wpas_dbus_error_invalid_args(message, op);
  1332. goto out;
  1333. }
  1334. ssid = wpa_config_get_network(wpa_s->conf, id);
  1335. if (ssid == NULL) {
  1336. reply = wpas_dbus_error_network_unknown(message);
  1337. goto out;
  1338. }
  1339. /* Finally, associate with the network */
  1340. wpa_supplicant_select_network(wpa_s, ssid);
  1341. out:
  1342. os_free(iface);
  1343. os_free(net_id);
  1344. return reply;
  1345. }
  1346. /**
  1347. * wpas_dbus_handler_network_reply - Reply to a NetworkRequest signal
  1348. * @message: Pointer to incoming dbus message
  1349. * @wpa_s: wpa_supplicant structure for a network interface
  1350. * Returns: NULL on success or dbus error on failure
  1351. *
  1352. * Handler function for "NetworkReply" method call of network interface.
  1353. */
  1354. DBusMessage * wpas_dbus_handler_network_reply(DBusMessage *message,
  1355. struct wpa_supplicant *wpa_s)
  1356. {
  1357. #ifdef IEEE8021X_EAPOL
  1358. DBusMessage *reply = NULL;
  1359. const char *op, *field, *value;
  1360. char *iface = NULL, *net_id = NULL;
  1361. int id;
  1362. struct wpa_ssid *ssid;
  1363. if (!dbus_message_get_args(message, NULL,
  1364. DBUS_TYPE_OBJECT_PATH, &op,
  1365. DBUS_TYPE_STRING, &field,
  1366. DBUS_TYPE_STRING, &value,
  1367. DBUS_TYPE_INVALID))
  1368. return wpas_dbus_error_invalid_args(message, NULL);
  1369. /* Extract the network ID and ensure the network */
  1370. /* is actually a child of this interface */
  1371. iface = wpas_dbus_new_decompose_object_path(op, 0, &net_id, NULL);
  1372. if (iface == NULL || os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
  1373. reply = wpas_dbus_error_invalid_args(message, op);
  1374. goto out;
  1375. }
  1376. id = strtoul(net_id, NULL, 10);
  1377. if (errno == EINVAL) {
  1378. reply = wpas_dbus_error_invalid_args(message, net_id);
  1379. goto out;
  1380. }
  1381. ssid = wpa_config_get_network(wpa_s->conf, id);
  1382. if (ssid == NULL) {
  1383. reply = wpas_dbus_error_network_unknown(message);
  1384. goto out;
  1385. }
  1386. if (wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid,
  1387. field, value) < 0)
  1388. reply = wpas_dbus_error_invalid_args(message, field);
  1389. else {
  1390. /* Tell EAP to retry immediately */
  1391. eapol_sm_notify_ctrl_response(wpa_s->eapol);
  1392. }
  1393. out:
  1394. os_free(iface);
  1395. os_free(net_id);
  1396. return reply;
  1397. #else /* IEEE8021X_EAPOL */
  1398. wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
  1399. return wpas_dbus_error_unknown_error(message, "802.1X not included");
  1400. #endif /* IEEE8021X_EAPOL */
  1401. }
  1402. /**
  1403. * wpas_dbus_handler_add_blob - Store named binary blob (ie, for certificates)
  1404. * @message: Pointer to incoming dbus message
  1405. * @wpa_s: %wpa_supplicant data structure
  1406. * Returns: A dbus message containing an error on failure or NULL on success
  1407. *
  1408. * Asks wpa_supplicant to internally store a binary blobs.
  1409. */
  1410. DBusMessage * wpas_dbus_handler_add_blob(DBusMessage *message,
  1411. struct wpa_supplicant *wpa_s)
  1412. {
  1413. DBusMessage *reply = NULL;
  1414. DBusMessageIter iter, array_iter;
  1415. char *blob_name;
  1416. u8 *blob_data;
  1417. int blob_len;
  1418. struct wpa_config_blob *blob = NULL;
  1419. dbus_message_iter_init(message, &iter);
  1420. dbus_message_iter_get_basic(&iter, &blob_name);
  1421. if (wpa_config_get_blob(wpa_s->conf, blob_name)) {
  1422. return dbus_message_new_error(message,
  1423. WPAS_DBUS_ERROR_BLOB_EXISTS,
  1424. NULL);
  1425. }
  1426. dbus_message_iter_next(&iter);
  1427. dbus_message_iter_recurse(&iter, &array_iter);
  1428. dbus_message_iter_get_fixed_array(&array_iter, &blob_data, &blob_len);
  1429. blob = os_zalloc(sizeof(*blob));
  1430. if (!blob) {
  1431. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1432. NULL);
  1433. goto err;
  1434. }
  1435. blob->data = os_malloc(blob_len);
  1436. if (!blob->data) {
  1437. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1438. NULL);
  1439. goto err;
  1440. }
  1441. os_memcpy(blob->data, blob_data, blob_len);
  1442. blob->len = blob_len;
  1443. blob->name = os_strdup(blob_name);
  1444. if (!blob->name) {
  1445. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1446. NULL);
  1447. goto err;
  1448. }
  1449. wpa_config_set_blob(wpa_s->conf, blob);
  1450. wpas_notify_blob_added(wpa_s, blob->name);
  1451. return reply;
  1452. err:
  1453. if (blob) {
  1454. os_free(blob->name);
  1455. os_free(blob->data);
  1456. os_free(blob);
  1457. }
  1458. return reply;
  1459. }
  1460. /**
  1461. * wpas_dbus_handler_get_blob - Get named binary blob (ie, for certificates)
  1462. * @message: Pointer to incoming dbus message
  1463. * @wpa_s: %wpa_supplicant data structure
  1464. * Returns: A dbus message containing array of bytes (blob)
  1465. *
  1466. * Gets one wpa_supplicant's binary blobs.
  1467. */
  1468. DBusMessage * wpas_dbus_handler_get_blob(DBusMessage *message,
  1469. struct wpa_supplicant *wpa_s)
  1470. {
  1471. DBusMessage *reply = NULL;
  1472. DBusMessageIter iter, array_iter;
  1473. char *blob_name;
  1474. const struct wpa_config_blob *blob;
  1475. dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &blob_name,
  1476. DBUS_TYPE_INVALID);
  1477. blob = wpa_config_get_blob(wpa_s->conf, blob_name);
  1478. if (!blob) {
  1479. return dbus_message_new_error(message,
  1480. WPAS_DBUS_ERROR_BLOB_UNKNOWN,
  1481. "Blob id not set");
  1482. }
  1483. reply = dbus_message_new_method_return(message);
  1484. if (!reply) {
  1485. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1486. NULL);
  1487. goto out;
  1488. }
  1489. dbus_message_iter_init_append(reply, &iter);
  1490. if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
  1491. DBUS_TYPE_BYTE_AS_STRING,
  1492. &array_iter)) {
  1493. dbus_message_unref(reply);
  1494. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1495. NULL);
  1496. goto out;
  1497. }
  1498. if (!dbus_message_iter_append_fixed_array(&array_iter, DBUS_TYPE_BYTE,
  1499. &(blob->data), blob->len)) {
  1500. dbus_message_unref(reply);
  1501. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1502. NULL);
  1503. goto out;
  1504. }
  1505. if (!dbus_message_iter_close_container(&iter, &array_iter)) {
  1506. dbus_message_unref(reply);
  1507. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1508. NULL);
  1509. goto out;
  1510. }
  1511. out:
  1512. return reply;
  1513. }
  1514. /**
  1515. * wpas_remove_handler_remove_blob - Remove named binary blob
  1516. * @message: Pointer to incoming dbus message
  1517. * @wpa_s: %wpa_supplicant data structure
  1518. * Returns: NULL on success or dbus error
  1519. *
  1520. * Asks wpa_supplicant to internally remove a binary blobs.
  1521. */
  1522. DBusMessage * wpas_dbus_handler_remove_blob(DBusMessage *message,
  1523. struct wpa_supplicant *wpa_s)
  1524. {
  1525. DBusMessage *reply = NULL;
  1526. char *blob_name;
  1527. dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &blob_name,
  1528. DBUS_TYPE_INVALID);
  1529. if (wpa_config_remove_blob(wpa_s->conf, blob_name)) {
  1530. return dbus_message_new_error(message,
  1531. WPAS_DBUS_ERROR_BLOB_UNKNOWN,
  1532. "Blob id not set");
  1533. }
  1534. wpas_notify_blob_removed(wpa_s, blob_name);
  1535. return reply;
  1536. }
  1537. /*
  1538. * wpas_dbus_handler_flush_bss - Flush the BSS cache
  1539. * @message: Pointer to incoming dbus message
  1540. * @wpa_s: wpa_supplicant structure for a network interface
  1541. * Returns: NULL
  1542. *
  1543. * Handler function for "FlushBSS" method call of network interface.
  1544. */
  1545. DBusMessage * wpas_dbus_handler_flush_bss(DBusMessage *message,
  1546. struct wpa_supplicant *wpa_s)
  1547. {
  1548. dbus_uint32_t age;
  1549. dbus_message_get_args(message, NULL, DBUS_TYPE_UINT32, &age,
  1550. DBUS_TYPE_INVALID);
  1551. if (age == 0)
  1552. wpa_bss_flush(wpa_s);
  1553. else
  1554. wpa_bss_flush_by_age(wpa_s, age);
  1555. return NULL;
  1556. }
  1557. #ifdef CONFIG_AUTOSCAN
  1558. /**
  1559. * wpas_dbus_handler_autoscan - Set autoscan parameters for the interface
  1560. * @message: Pointer to incoming dbus message
  1561. * @wpa_s: wpa_supplicant structure for a network interface
  1562. * Returns: NULL
  1563. *
  1564. * Handler function for "AutoScan" method call of network interface.
  1565. */
  1566. DBusMessage * wpas_dbus_handler_autoscan(DBusMessage *message,
  1567. struct wpa_supplicant *wpa_s)
  1568. {
  1569. DBusMessage *reply = NULL;
  1570. enum wpa_states state = wpa_s->wpa_state;
  1571. char *arg;
  1572. dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg,
  1573. DBUS_TYPE_INVALID);
  1574. if (arg != NULL && os_strlen(arg) > 0) {
  1575. char *tmp;
  1576. tmp = os_strdup(arg);
  1577. if (tmp == NULL) {
  1578. reply = dbus_message_new_error(message,
  1579. DBUS_ERROR_NO_MEMORY,
  1580. NULL);
  1581. } else {
  1582. os_free(wpa_s->conf->autoscan);
  1583. wpa_s->conf->autoscan = tmp;
  1584. if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
  1585. autoscan_init(wpa_s);
  1586. }
  1587. } else if (arg != NULL && os_strlen(arg) == 0) {
  1588. os_free(wpa_s->conf->autoscan);
  1589. wpa_s->conf->autoscan = NULL;
  1590. autoscan_deinit(wpa_s);
  1591. } else
  1592. reply = dbus_message_new_error(message,
  1593. DBUS_ERROR_INVALID_ARGS,
  1594. NULL);
  1595. return reply;
  1596. }
  1597. #endif /* CONFIG_AUTOSCAN */
  1598. /**
  1599. * wpas_dbus_getter_capabilities - Return interface capabilities
  1600. * @iter: Pointer to incoming dbus message iter
  1601. * @error: Location to store error on failure
  1602. * @user_data: Function specific data
  1603. * Returns: TRUE on success, FALSE on failure
  1604. *
  1605. * Getter for "Capabilities" property of an interface.
  1606. */
  1607. dbus_bool_t wpas_dbus_getter_capabilities(DBusMessageIter *iter,
  1608. DBusError *error, void *user_data)
  1609. {
  1610. struct wpa_supplicant *wpa_s = user_data;
  1611. struct wpa_driver_capa capa;
  1612. int res;
  1613. DBusMessageIter iter_dict, iter_dict_entry, iter_dict_val, iter_array,
  1614. variant_iter;
  1615. const char *scans[] = { "active", "passive", "ssid" };
  1616. if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
  1617. "a{sv}", &variant_iter))
  1618. goto nomem;
  1619. if (!wpa_dbus_dict_open_write(&variant_iter, &iter_dict))
  1620. goto nomem;
  1621. res = wpa_drv_get_capa(wpa_s, &capa);
  1622. /***** pairwise cipher */
  1623. if (res < 0) {
  1624. const char *args[] = {"ccmp", "tkip", "none"};
  1625. if (!wpa_dbus_dict_append_string_array(
  1626. &iter_dict, "Pairwise", args,
  1627. sizeof(args) / sizeof(char*)))
  1628. goto nomem;
  1629. } else {
  1630. if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Pairwise",
  1631. &iter_dict_entry,
  1632. &iter_dict_val,
  1633. &iter_array))
  1634. goto nomem;
  1635. if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) {
  1636. if (!wpa_dbus_dict_string_array_add_element(
  1637. &iter_array, "ccmp"))
  1638. goto nomem;
  1639. }
  1640. if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) {
  1641. if (!wpa_dbus_dict_string_array_add_element(
  1642. &iter_array, "tkip"))
  1643. goto nomem;
  1644. }
  1645. if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
  1646. if (!wpa_dbus_dict_string_array_add_element(
  1647. &iter_array, "none"))
  1648. goto nomem;
  1649. }
  1650. if (!wpa_dbus_dict_end_string_array(&iter_dict,
  1651. &iter_dict_entry,
  1652. &iter_dict_val,
  1653. &iter_array))
  1654. goto nomem;
  1655. }
  1656. /***** group cipher */
  1657. if (res < 0) {
  1658. const char *args[] = {
  1659. "ccmp", "tkip", "wep104", "wep40"
  1660. };
  1661. if (!wpa_dbus_dict_append_string_array(
  1662. &iter_dict, "Group", args,
  1663. sizeof(args) / sizeof(char*)))
  1664. goto nomem;
  1665. } else {
  1666. if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Group",
  1667. &iter_dict_entry,
  1668. &iter_dict_val,
  1669. &iter_array))
  1670. goto nomem;
  1671. if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) {
  1672. if (!wpa_dbus_dict_string_array_add_element(
  1673. &iter_array, "ccmp"))
  1674. goto nomem;
  1675. }
  1676. if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) {
  1677. if (!wpa_dbus_dict_string_array_add_element(
  1678. &iter_array, "tkip"))
  1679. goto nomem;
  1680. }
  1681. if (capa.enc & WPA_DRIVER_CAPA_ENC_WEP104) {
  1682. if (!wpa_dbus_dict_string_array_add_element(
  1683. &iter_array, "wep104"))
  1684. goto nomem;
  1685. }
  1686. if (capa.enc & WPA_DRIVER_CAPA_ENC_WEP40) {
  1687. if (!wpa_dbus_dict_string_array_add_element(
  1688. &iter_array, "wep40"))
  1689. goto nomem;
  1690. }
  1691. if (!wpa_dbus_dict_end_string_array(&iter_dict,
  1692. &iter_dict_entry,
  1693. &iter_dict_val,
  1694. &iter_array))
  1695. goto nomem;
  1696. }
  1697. /***** key management */
  1698. if (res < 0) {
  1699. const char *args[] = {
  1700. "wpa-psk", "wpa-eap", "ieee8021x", "wpa-none",
  1701. #ifdef CONFIG_WPS
  1702. "wps",
  1703. #endif /* CONFIG_WPS */
  1704. "none"
  1705. };
  1706. if (!wpa_dbus_dict_append_string_array(
  1707. &iter_dict, "KeyMgmt", args,
  1708. sizeof(args) / sizeof(char*)))
  1709. goto nomem;
  1710. } else {
  1711. if (!wpa_dbus_dict_begin_string_array(&iter_dict, "KeyMgmt",
  1712. &iter_dict_entry,
  1713. &iter_dict_val,
  1714. &iter_array))
  1715. goto nomem;
  1716. if (!wpa_dbus_dict_string_array_add_element(&iter_array,
  1717. "none"))
  1718. goto nomem;
  1719. if (!wpa_dbus_dict_string_array_add_element(&iter_array,
  1720. "ieee8021x"))
  1721. goto nomem;
  1722. if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
  1723. WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
  1724. if (!wpa_dbus_dict_string_array_add_element(
  1725. &iter_array, "wpa-eap"))
  1726. goto nomem;
  1727. if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT)
  1728. if (!wpa_dbus_dict_string_array_add_element(
  1729. &iter_array, "wpa-ft-eap"))
  1730. goto nomem;
  1731. /* TODO: Ensure that driver actually supports sha256 encryption. */
  1732. #ifdef CONFIG_IEEE80211W
  1733. if (!wpa_dbus_dict_string_array_add_element(
  1734. &iter_array, "wpa-eap-sha256"))
  1735. goto nomem;
  1736. #endif /* CONFIG_IEEE80211W */
  1737. }
  1738. if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
  1739. WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
  1740. if (!wpa_dbus_dict_string_array_add_element(
  1741. &iter_array, "wpa-psk"))
  1742. goto nomem;
  1743. if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK)
  1744. if (!wpa_dbus_dict_string_array_add_element(
  1745. &iter_array, "wpa-ft-psk"))
  1746. goto nomem;
  1747. /* TODO: Ensure that driver actually supports sha256 encryption. */
  1748. #ifdef CONFIG_IEEE80211W
  1749. if (!wpa_dbus_dict_string_array_add_element(
  1750. &iter_array, "wpa-psk-sha256"))
  1751. goto nomem;
  1752. #endif /* CONFIG_IEEE80211W */
  1753. }
  1754. if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
  1755. if (!wpa_dbus_dict_string_array_add_element(
  1756. &iter_array, "wpa-none"))
  1757. goto nomem;
  1758. }
  1759. #ifdef CONFIG_WPS
  1760. if (!wpa_dbus_dict_string_array_add_element(&iter_array,
  1761. "wps"))
  1762. goto nomem;
  1763. #endif /* CONFIG_WPS */
  1764. if (!wpa_dbus_dict_end_string_array(&iter_dict,
  1765. &iter_dict_entry,
  1766. &iter_dict_val,
  1767. &iter_array))
  1768. goto nomem;
  1769. }
  1770. /***** WPA protocol */
  1771. if (res < 0) {
  1772. const char *args[] = { "rsn", "wpa" };
  1773. if (!wpa_dbus_dict_append_string_array(
  1774. &iter_dict, "Protocol", args,
  1775. sizeof(args) / sizeof(char*)))
  1776. goto nomem;
  1777. } else {
  1778. if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Protocol",
  1779. &iter_dict_entry,
  1780. &iter_dict_val,
  1781. &iter_array))
  1782. goto nomem;
  1783. if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
  1784. WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
  1785. if (!wpa_dbus_dict_string_array_add_element(
  1786. &iter_array, "rsn"))
  1787. goto nomem;
  1788. }
  1789. if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
  1790. WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
  1791. if (!wpa_dbus_dict_string_array_add_element(
  1792. &iter_array, "wpa"))
  1793. goto nomem;
  1794. }
  1795. if (!wpa_dbus_dict_end_string_array(&iter_dict,
  1796. &iter_dict_entry,
  1797. &iter_dict_val,
  1798. &iter_array))
  1799. goto nomem;
  1800. }
  1801. /***** auth alg */
  1802. if (res < 0) {
  1803. const char *args[] = { "open", "shared", "leap" };
  1804. if (!wpa_dbus_dict_append_string_array(
  1805. &iter_dict, "AuthAlg", args,
  1806. sizeof(args) / sizeof(char*)))
  1807. goto nomem;
  1808. } else {
  1809. if (!wpa_dbus_dict_begin_string_array(&iter_dict, "AuthAlg",
  1810. &iter_dict_entry,
  1811. &iter_dict_val,
  1812. &iter_array))
  1813. goto nomem;
  1814. if (capa.auth & (WPA_DRIVER_AUTH_OPEN)) {
  1815. if (!wpa_dbus_dict_string_array_add_element(
  1816. &iter_array, "open"))
  1817. goto nomem;
  1818. }
  1819. if (capa.auth & (WPA_DRIVER_AUTH_SHARED)) {
  1820. if (!wpa_dbus_dict_string_array_add_element(
  1821. &iter_array, "shared"))
  1822. goto nomem;
  1823. }
  1824. if (capa.auth & (WPA_DRIVER_AUTH_LEAP)) {
  1825. if (!wpa_dbus_dict_string_array_add_element(
  1826. &iter_array, "leap"))
  1827. goto nomem;
  1828. }
  1829. if (!wpa_dbus_dict_end_string_array(&iter_dict,
  1830. &iter_dict_entry,
  1831. &iter_dict_val,
  1832. &iter_array))
  1833. goto nomem;
  1834. }
  1835. /***** Scan */
  1836. if (!wpa_dbus_dict_append_string_array(&iter_dict, "Scan", scans,
  1837. sizeof(scans) / sizeof(char *)))
  1838. goto nomem;
  1839. /***** Modes */
  1840. if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Modes",
  1841. &iter_dict_entry,
  1842. &iter_dict_val,
  1843. &iter_array))
  1844. goto nomem;
  1845. if (!wpa_dbus_dict_string_array_add_element(
  1846. &iter_array, "infrastructure"))
  1847. goto nomem;
  1848. if (!wpa_dbus_dict_string_array_add_element(
  1849. &iter_array, "ad-hoc"))
  1850. goto nomem;
  1851. if (res >= 0) {
  1852. if (capa.flags & (WPA_DRIVER_FLAGS_AP)) {
  1853. if (!wpa_dbus_dict_string_array_add_element(
  1854. &iter_array, "ap"))
  1855. goto nomem;
  1856. }
  1857. if (capa.flags & (WPA_DRIVER_FLAGS_P2P_CAPABLE)) {
  1858. if (!wpa_dbus_dict_string_array_add_element(
  1859. &iter_array, "p2p"))
  1860. goto nomem;
  1861. }
  1862. }
  1863. if (!wpa_dbus_dict_end_string_array(&iter_dict,
  1864. &iter_dict_entry,
  1865. &iter_dict_val,
  1866. &iter_array))
  1867. goto nomem;
  1868. /***** Modes end */
  1869. if (res >= 0) {
  1870. dbus_int32_t max_scan_ssid = capa.max_scan_ssids;
  1871. if (!wpa_dbus_dict_append_int32(&iter_dict, "MaxScanSSID",
  1872. max_scan_ssid))
  1873. goto nomem;
  1874. }
  1875. if (!wpa_dbus_dict_close_write(&variant_iter, &iter_dict))
  1876. goto nomem;
  1877. if (!dbus_message_iter_close_container(iter, &variant_iter))
  1878. goto nomem;
  1879. return TRUE;
  1880. nomem:
  1881. dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
  1882. return FALSE;
  1883. }
  1884. /**
  1885. * wpas_dbus_getter_state - Get interface state
  1886. * @iter: Pointer to incoming dbus message iter
  1887. * @error: Location to store error on failure
  1888. * @user_data: Function specific data
  1889. * Returns: TRUE on success, FALSE on failure
  1890. *
  1891. * Getter for "State" property.
  1892. */
  1893. dbus_bool_t wpas_dbus_getter_state(DBusMessageIter *iter, DBusError *error,
  1894. void *user_data)
  1895. {
  1896. struct wpa_supplicant *wpa_s = user_data;
  1897. const char *str_state;
  1898. char *state_ls, *tmp;
  1899. dbus_bool_t success = FALSE;
  1900. str_state = wpa_supplicant_state_txt(wpa_s->wpa_state);
  1901. /* make state string lowercase to fit new DBus API convention
  1902. */
  1903. state_ls = tmp = os_strdup(str_state);
  1904. if (!tmp) {
  1905. dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
  1906. return FALSE;
  1907. }
  1908. while (*tmp) {
  1909. *tmp = tolower(*tmp);
  1910. tmp++;
  1911. }
  1912. success = wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
  1913. &state_ls, error);
  1914. os_free(state_ls);
  1915. return success;
  1916. }
  1917. /**
  1918. * wpas_dbus_new_iface_get_scanning - Get interface scanning state
  1919. * @iter: Pointer to incoming dbus message iter
  1920. * @error: Location to store error on failure
  1921. * @user_data: Function specific data
  1922. * Returns: TRUE on success, FALSE on failure
  1923. *
  1924. * Getter for "scanning" property.
  1925. */
  1926. dbus_bool_t wpas_dbus_getter_scanning(DBusMessageIter *iter, DBusError *error,
  1927. void *user_data)
  1928. {
  1929. struct wpa_supplicant *wpa_s = user_data;
  1930. dbus_bool_t scanning = wpa_s->scanning ? TRUE : FALSE;
  1931. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
  1932. &scanning, error);
  1933. }
  1934. /**
  1935. * wpas_dbus_getter_ap_scan - Control roaming mode
  1936. * @iter: Pointer to incoming dbus message iter
  1937. * @error: Location to store error on failure
  1938. * @user_data: Function specific data
  1939. * Returns: TRUE on success, FALSE on failure
  1940. *
  1941. * Getter function for "ApScan" property.
  1942. */
  1943. dbus_bool_t wpas_dbus_getter_ap_scan(DBusMessageIter *iter, DBusError *error,
  1944. void *user_data)
  1945. {
  1946. struct wpa_supplicant *wpa_s = user_data;
  1947. dbus_uint32_t ap_scan = wpa_s->conf->ap_scan;
  1948. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT32,
  1949. &ap_scan, error);
  1950. }
  1951. /**
  1952. * wpas_dbus_setter_ap_scan - Control roaming mode
  1953. * @iter: Pointer to incoming dbus message iter
  1954. * @error: Location to store error on failure
  1955. * @user_data: Function specific data
  1956. * Returns: TRUE on success, FALSE on failure
  1957. *
  1958. * Setter function for "ApScan" property.
  1959. */
  1960. dbus_bool_t wpas_dbus_setter_ap_scan(DBusMessageIter *iter, DBusError *error,
  1961. void *user_data)
  1962. {
  1963. struct wpa_supplicant *wpa_s = user_data;
  1964. dbus_uint32_t ap_scan;
  1965. if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_UINT32,
  1966. &ap_scan))
  1967. return FALSE;
  1968. if (wpa_supplicant_set_ap_scan(wpa_s, ap_scan)) {
  1969. dbus_set_error_const(error, DBUS_ERROR_FAILED,
  1970. "ap_scan must be 0, 1, or 2");
  1971. return FALSE;
  1972. }
  1973. return TRUE;
  1974. }
  1975. /**
  1976. * wpas_dbus_getter_fast_reauth - Control fast
  1977. * reauthentication (TLS session resumption)
  1978. * @iter: Pointer to incoming dbus message iter
  1979. * @error: Location to store error on failure
  1980. * @user_data: Function specific data
  1981. * Returns: TRUE on success, FALSE on failure
  1982. *
  1983. * Getter function for "FastReauth" property.
  1984. */
  1985. dbus_bool_t wpas_dbus_getter_fast_reauth(DBusMessageIter *iter,
  1986. DBusError *error,
  1987. void *user_data)
  1988. {
  1989. struct wpa_supplicant *wpa_s = user_data;
  1990. dbus_bool_t fast_reauth = wpa_s->conf->fast_reauth ? TRUE : FALSE;
  1991. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
  1992. &fast_reauth, error);
  1993. }
  1994. /**
  1995. * wpas_dbus_setter_fast_reauth - Control fast
  1996. * reauthentication (TLS session resumption)
  1997. * @iter: Pointer to incoming dbus message iter
  1998. * @error: Location to store error on failure
  1999. * @user_data: Function specific data
  2000. * Returns: TRUE on success, FALSE on failure
  2001. *
  2002. * Setter function for "FastReauth" property.
  2003. */
  2004. dbus_bool_t wpas_dbus_setter_fast_reauth(DBusMessageIter *iter,
  2005. DBusError *error,
  2006. void *user_data)
  2007. {
  2008. struct wpa_supplicant *wpa_s = user_data;
  2009. dbus_bool_t fast_reauth;
  2010. if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_BOOLEAN,
  2011. &fast_reauth))
  2012. return FALSE;
  2013. wpa_s->conf->fast_reauth = fast_reauth;
  2014. return TRUE;
  2015. }
  2016. /**
  2017. * wpas_dbus_getter_bss_expire_age - Get BSS entry expiration age
  2018. * @iter: Pointer to incoming dbus message iter
  2019. * @error: Location to store error on failure
  2020. * @user_data: Function specific data
  2021. * Returns: TRUE on success, FALSE on failure
  2022. *
  2023. * Getter function for "BSSExpireAge" property.
  2024. */
  2025. dbus_bool_t wpas_dbus_getter_bss_expire_age(DBusMessageIter *iter,
  2026. DBusError *error,
  2027. void *user_data)
  2028. {
  2029. struct wpa_supplicant *wpa_s = user_data;
  2030. dbus_uint32_t expire_age = wpa_s->conf->bss_expiration_age;
  2031. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT32,
  2032. &expire_age, error);
  2033. }
  2034. /**
  2035. * wpas_dbus_setter_bss_expire_age - Control BSS entry expiration age
  2036. * @iter: Pointer to incoming dbus message iter
  2037. * @error: Location to store error on failure
  2038. * @user_data: Function specific data
  2039. * Returns: TRUE on success, FALSE on failure
  2040. *
  2041. * Setter function for "BSSExpireAge" property.
  2042. */
  2043. dbus_bool_t wpas_dbus_setter_bss_expire_age(DBusMessageIter *iter,
  2044. DBusError *error,
  2045. void *user_data)
  2046. {
  2047. struct wpa_supplicant *wpa_s = user_data;
  2048. dbus_uint32_t expire_age;
  2049. if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_UINT32,
  2050. &expire_age))
  2051. return FALSE;
  2052. if (wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age)) {
  2053. dbus_set_error_const(error, DBUS_ERROR_FAILED,
  2054. "BSSExpireAge must be >= 10");
  2055. return FALSE;
  2056. }
  2057. return TRUE;
  2058. }
  2059. /**
  2060. * wpas_dbus_getter_bss_expire_count - Get BSS entry expiration scan count
  2061. * @iter: Pointer to incoming dbus message iter
  2062. * @error: Location to store error on failure
  2063. * @user_data: Function specific data
  2064. * Returns: TRUE on success, FALSE on failure
  2065. *
  2066. * Getter function for "BSSExpireCount" property.
  2067. */
  2068. dbus_bool_t wpas_dbus_getter_bss_expire_count(DBusMessageIter *iter,
  2069. DBusError *error,
  2070. void *user_data)
  2071. {
  2072. struct wpa_supplicant *wpa_s = user_data;
  2073. dbus_uint32_t expire_count = wpa_s->conf->bss_expiration_age;
  2074. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT32,
  2075. &expire_count, error);
  2076. }
  2077. /**
  2078. * wpas_dbus_setter_bss_expire_count - Control BSS entry expiration scan count
  2079. * @iter: Pointer to incoming dbus message iter
  2080. * @error: Location to store error on failure
  2081. * @user_data: Function specific data
  2082. * Returns: TRUE on success, FALSE on failure
  2083. *
  2084. * Setter function for "BSSExpireCount" property.
  2085. */
  2086. dbus_bool_t wpas_dbus_setter_bss_expire_count(DBusMessageIter *iter,
  2087. DBusError *error,
  2088. void *user_data)
  2089. {
  2090. struct wpa_supplicant *wpa_s = user_data;
  2091. dbus_uint32_t expire_count;
  2092. if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_UINT32,
  2093. &expire_count))
  2094. return FALSE;
  2095. if (wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count)) {
  2096. dbus_set_error_const(error, DBUS_ERROR_FAILED,
  2097. "BSSExpireCount must be > 0");
  2098. return FALSE;
  2099. }
  2100. return TRUE;
  2101. }
  2102. /**
  2103. * wpas_dbus_getter_country - Control country code
  2104. * @iter: Pointer to incoming dbus message iter
  2105. * @error: Location to store error on failure
  2106. * @user_data: Function specific data
  2107. * Returns: TRUE on success, FALSE on failure
  2108. *
  2109. * Getter function for "Country" property.
  2110. */
  2111. dbus_bool_t wpas_dbus_getter_country(DBusMessageIter *iter, DBusError *error,
  2112. void *user_data)
  2113. {
  2114. struct wpa_supplicant *wpa_s = user_data;
  2115. char country[3];
  2116. char *str = country;
  2117. country[0] = wpa_s->conf->country[0];
  2118. country[1] = wpa_s->conf->country[1];
  2119. country[2] = '\0';
  2120. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
  2121. &str, error);
  2122. }
  2123. /**
  2124. * wpas_dbus_setter_country - Control country code
  2125. * @iter: Pointer to incoming dbus message iter
  2126. * @error: Location to store error on failure
  2127. * @user_data: Function specific data
  2128. * Returns: TRUE on success, FALSE on failure
  2129. *
  2130. * Setter function for "Country" property.
  2131. */
  2132. dbus_bool_t wpas_dbus_setter_country(DBusMessageIter *iter, DBusError *error,
  2133. void *user_data)
  2134. {
  2135. struct wpa_supplicant *wpa_s = user_data;
  2136. const char *country;
  2137. if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_STRING,
  2138. &country))
  2139. return FALSE;
  2140. if (!country[0] || !country[1]) {
  2141. dbus_set_error_const(error, DBUS_ERROR_FAILED,
  2142. "invalid country code");
  2143. return FALSE;
  2144. }
  2145. if (wpa_s->drv_priv != NULL && wpa_drv_set_country(wpa_s, country)) {
  2146. wpa_printf(MSG_DEBUG, "Failed to set country");
  2147. dbus_set_error_const(error, DBUS_ERROR_FAILED,
  2148. "failed to set country code");
  2149. return FALSE;
  2150. }
  2151. wpa_s->conf->country[0] = country[0];
  2152. wpa_s->conf->country[1] = country[1];
  2153. return TRUE;
  2154. }
  2155. /**
  2156. * wpas_dbus_getter_scan_interval - Get scan interval
  2157. * @iter: Pointer to incoming dbus message iter
  2158. * @error: Location to store error on failure
  2159. * @user_data: Function specific data
  2160. * Returns: TRUE on success, FALSE on failure
  2161. *
  2162. * Getter function for "ScanInterval" property.
  2163. */
  2164. dbus_bool_t wpas_dbus_getter_scan_interval(DBusMessageIter *iter,
  2165. DBusError *error,
  2166. void *user_data)
  2167. {
  2168. struct wpa_supplicant *wpa_s = user_data;
  2169. dbus_int32_t scan_interval = wpa_s->scan_interval;
  2170. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_INT32,
  2171. &scan_interval, error);
  2172. }
  2173. /**
  2174. * wpas_dbus_setter_scan_interval - Control scan interval
  2175. * @iter: Pointer to incoming dbus message iter
  2176. * @error: Location to store error on failure
  2177. * @user_data: Function specific data
  2178. * Returns: TRUE on success, FALSE on failure
  2179. *
  2180. * Setter function for "ScanInterval" property.
  2181. */
  2182. dbus_bool_t wpas_dbus_setter_scan_interval(DBusMessageIter *iter,
  2183. DBusError *error,
  2184. void *user_data)
  2185. {
  2186. struct wpa_supplicant *wpa_s = user_data;
  2187. dbus_int32_t scan_interval;
  2188. if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_INT32,
  2189. &scan_interval))
  2190. return FALSE;
  2191. if (wpa_supplicant_set_scan_interval(wpa_s, scan_interval)) {
  2192. dbus_set_error_const(error, DBUS_ERROR_FAILED,
  2193. "scan_interval must be >= 0");
  2194. return FALSE;
  2195. }
  2196. return TRUE;
  2197. }
  2198. /**
  2199. * wpas_dbus_getter_ifname - Get interface name
  2200. * @iter: Pointer to incoming dbus message iter
  2201. * @error: Location to store error on failure
  2202. * @user_data: Function specific data
  2203. * Returns: TRUE on success, FALSE on failure
  2204. *
  2205. * Getter for "Ifname" property.
  2206. */
  2207. dbus_bool_t wpas_dbus_getter_ifname(DBusMessageIter *iter, DBusError *error,
  2208. void *user_data)
  2209. {
  2210. struct wpa_supplicant *wpa_s = user_data;
  2211. const char *ifname = wpa_s->ifname;
  2212. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
  2213. &ifname, error);
  2214. }
  2215. /**
  2216. * wpas_dbus_getter_driver - Get interface name
  2217. * @iter: Pointer to incoming dbus message iter
  2218. * @error: Location to store error on failure
  2219. * @user_data: Function specific data
  2220. * Returns: TRUE on success, FALSE on failure
  2221. *
  2222. * Getter for "Driver" property.
  2223. */
  2224. dbus_bool_t wpas_dbus_getter_driver(DBusMessageIter *iter, DBusError *error,
  2225. void *user_data)
  2226. {
  2227. struct wpa_supplicant *wpa_s = user_data;
  2228. const char *driver;
  2229. if (wpa_s->driver == NULL || wpa_s->driver->name == NULL) {
  2230. wpa_printf(MSG_DEBUG, "wpas_dbus_getter_driver[dbus]: "
  2231. "wpa_s has no driver set");
  2232. dbus_set_error(error, DBUS_ERROR_FAILED, "%s: no driver set",
  2233. __func__);
  2234. return FALSE;
  2235. }
  2236. driver = wpa_s->driver->name;
  2237. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
  2238. &driver, error);
  2239. }
  2240. /**
  2241. * wpas_dbus_getter_current_bss - Get current bss object path
  2242. * @iter: Pointer to incoming dbus message iter
  2243. * @error: Location to store error on failure
  2244. * @user_data: Function specific data
  2245. * Returns: TRUE on success, FALSE on failure
  2246. *
  2247. * Getter for "CurrentBSS" property.
  2248. */
  2249. dbus_bool_t wpas_dbus_getter_current_bss(DBusMessageIter *iter,
  2250. DBusError *error,
  2251. void *user_data)
  2252. {
  2253. struct wpa_supplicant *wpa_s = user_data;
  2254. char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *bss_obj_path = path_buf;
  2255. if (wpa_s->current_bss)
  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, wpa_s->current_bss->id);
  2259. else
  2260. os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "/");
  2261. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_OBJECT_PATH,
  2262. &bss_obj_path, error);
  2263. }
  2264. /**
  2265. * wpas_dbus_getter_current_network - Get current network object path
  2266. * @iter: Pointer to incoming dbus message iter
  2267. * @error: Location to store error on failure
  2268. * @user_data: Function specific data
  2269. * Returns: TRUE on success, FALSE on failure
  2270. *
  2271. * Getter for "CurrentNetwork" property.
  2272. */
  2273. dbus_bool_t wpas_dbus_getter_current_network(DBusMessageIter *iter,
  2274. DBusError *error,
  2275. void *user_data)
  2276. {
  2277. struct wpa_supplicant *wpa_s = user_data;
  2278. char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *net_obj_path = path_buf;
  2279. if (wpa_s->current_ssid)
  2280. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2281. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  2282. wpa_s->dbus_new_path, wpa_s->current_ssid->id);
  2283. else
  2284. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "/");
  2285. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_OBJECT_PATH,
  2286. &net_obj_path, error);
  2287. }
  2288. /**
  2289. * wpas_dbus_getter_current_auth_mode - Get current authentication type
  2290. * @iter: Pointer to incoming dbus message iter
  2291. * @error: Location to store error on failure
  2292. * @user_data: Function specific data
  2293. * Returns: TRUE on success, FALSE on failure
  2294. *
  2295. * Getter for "CurrentAuthMode" property.
  2296. */
  2297. dbus_bool_t wpas_dbus_getter_current_auth_mode(DBusMessageIter *iter,
  2298. DBusError *error,
  2299. void *user_data)
  2300. {
  2301. struct wpa_supplicant *wpa_s = user_data;
  2302. const char *eap_mode;
  2303. const char *auth_mode;
  2304. char eap_mode_buf[WPAS_DBUS_AUTH_MODE_MAX];
  2305. if (wpa_s->wpa_state != WPA_COMPLETED) {
  2306. auth_mode = "INACTIVE";
  2307. } else if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X ||
  2308. wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
  2309. eap_mode = wpa_supplicant_get_eap_mode(wpa_s);
  2310. os_snprintf(eap_mode_buf, WPAS_DBUS_AUTH_MODE_MAX,
  2311. "EAP-%s", eap_mode);
  2312. auth_mode = eap_mode_buf;
  2313. } else {
  2314. auth_mode = wpa_key_mgmt_txt(wpa_s->key_mgmt,
  2315. wpa_s->current_ssid->proto);
  2316. }
  2317. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
  2318. &auth_mode, error);
  2319. }
  2320. /**
  2321. * wpas_dbus_getter_bridge_ifname - Get interface name
  2322. * @iter: Pointer to incoming dbus message iter
  2323. * @error: Location to store error on failure
  2324. * @user_data: Function specific data
  2325. * Returns: TRUE on success, FALSE on failure
  2326. *
  2327. * Getter for "BridgeIfname" property.
  2328. */
  2329. dbus_bool_t wpas_dbus_getter_bridge_ifname(DBusMessageIter *iter,
  2330. DBusError *error,
  2331. void *user_data)
  2332. {
  2333. struct wpa_supplicant *wpa_s = user_data;
  2334. const char *bridge_ifname = wpa_s->bridge_ifname;
  2335. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
  2336. &bridge_ifname, error);
  2337. }
  2338. /**
  2339. * wpas_dbus_getter_bsss - Get array of BSSs objects
  2340. * @iter: Pointer to incoming dbus message iter
  2341. * @error: Location to store error on failure
  2342. * @user_data: Function specific data
  2343. * Returns: TRUE on success, FALSE on failure
  2344. *
  2345. * Getter for "BSSs" property.
  2346. */
  2347. dbus_bool_t wpas_dbus_getter_bsss(DBusMessageIter *iter, DBusError *error,
  2348. void *user_data)
  2349. {
  2350. struct wpa_supplicant *wpa_s = user_data;
  2351. struct wpa_bss *bss;
  2352. char **paths;
  2353. unsigned int i = 0;
  2354. dbus_bool_t success = FALSE;
  2355. paths = os_zalloc(wpa_s->num_bss * sizeof(char *));
  2356. if (!paths) {
  2357. dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
  2358. return FALSE;
  2359. }
  2360. /* Loop through scan results and append each result's object path */
  2361. dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
  2362. paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
  2363. if (paths[i] == NULL) {
  2364. dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY,
  2365. "no memory");
  2366. goto out;
  2367. }
  2368. /* Construct the object path for this BSS. */
  2369. os_snprintf(paths[i++], WPAS_DBUS_OBJECT_PATH_MAX,
  2370. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  2371. wpa_s->dbus_new_path, bss->id);
  2372. }
  2373. success = wpas_dbus_simple_array_property_getter(iter,
  2374. DBUS_TYPE_OBJECT_PATH,
  2375. paths, wpa_s->num_bss,
  2376. error);
  2377. out:
  2378. while (i)
  2379. os_free(paths[--i]);
  2380. os_free(paths);
  2381. return success;
  2382. }
  2383. /**
  2384. * wpas_dbus_getter_networks - Get array of networks objects
  2385. * @iter: Pointer to incoming dbus message iter
  2386. * @error: Location to store error on failure
  2387. * @user_data: Function specific data
  2388. * Returns: TRUE on success, FALSE on failure
  2389. *
  2390. * Getter for "Networks" property.
  2391. */
  2392. dbus_bool_t wpas_dbus_getter_networks(DBusMessageIter *iter, DBusError *error,
  2393. void *user_data)
  2394. {
  2395. struct wpa_supplicant *wpa_s = user_data;
  2396. struct wpa_ssid *ssid;
  2397. char **paths;
  2398. unsigned int i = 0, num = 0;
  2399. dbus_bool_t success = FALSE;
  2400. if (wpa_s->conf == NULL) {
  2401. wpa_printf(MSG_ERROR, "%s[dbus]: An error occurred getting "
  2402. "networks list.", __func__);
  2403. dbus_set_error(error, DBUS_ERROR_FAILED, "%s: an error "
  2404. "occurred getting the networks list", __func__);
  2405. return FALSE;
  2406. }
  2407. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next)
  2408. if (!network_is_persistent_group(ssid))
  2409. num++;
  2410. paths = os_zalloc(num * sizeof(char *));
  2411. if (!paths) {
  2412. dbus_set_error(error, DBUS_ERROR_NO_MEMORY, "no memory");
  2413. return FALSE;
  2414. }
  2415. /* Loop through configured networks and append object path of each */
  2416. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
  2417. if (network_is_persistent_group(ssid))
  2418. continue;
  2419. paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
  2420. if (paths[i] == NULL) {
  2421. dbus_set_error(error, DBUS_ERROR_NO_MEMORY, "no memory");
  2422. goto out;
  2423. }
  2424. /* Construct the object path for this network. */
  2425. os_snprintf(paths[i++], WPAS_DBUS_OBJECT_PATH_MAX,
  2426. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
  2427. wpa_s->dbus_new_path, ssid->id);
  2428. }
  2429. success = wpas_dbus_simple_array_property_getter(iter,
  2430. DBUS_TYPE_OBJECT_PATH,
  2431. paths, num, error);
  2432. out:
  2433. while (i)
  2434. os_free(paths[--i]);
  2435. os_free(paths);
  2436. return success;
  2437. }
  2438. /**
  2439. * wpas_dbus_getter_blobs - Get all blobs defined for this interface
  2440. * @iter: Pointer to incoming dbus message iter
  2441. * @error: Location to store error on failure
  2442. * @user_data: Function specific data
  2443. * Returns: TRUE on success, FALSE on failure
  2444. *
  2445. * Getter for "Blobs" property.
  2446. */
  2447. dbus_bool_t wpas_dbus_getter_blobs(DBusMessageIter *iter, DBusError *error,
  2448. void *user_data)
  2449. {
  2450. struct wpa_supplicant *wpa_s = user_data;
  2451. DBusMessageIter variant_iter, dict_iter, entry_iter, array_iter;
  2452. struct wpa_config_blob *blob;
  2453. if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
  2454. "a{say}", &variant_iter) ||
  2455. !dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
  2456. "{say}", &dict_iter)) {
  2457. dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
  2458. return FALSE;
  2459. }
  2460. blob = wpa_s->conf->blobs;
  2461. while (blob) {
  2462. if (!dbus_message_iter_open_container(&dict_iter,
  2463. DBUS_TYPE_DICT_ENTRY,
  2464. NULL, &entry_iter) ||
  2465. !dbus_message_iter_append_basic(&entry_iter,
  2466. DBUS_TYPE_STRING,
  2467. &(blob->name)) ||
  2468. !dbus_message_iter_open_container(&entry_iter,
  2469. DBUS_TYPE_ARRAY,
  2470. DBUS_TYPE_BYTE_AS_STRING,
  2471. &array_iter) ||
  2472. !dbus_message_iter_append_fixed_array(&array_iter,
  2473. DBUS_TYPE_BYTE,
  2474. &(blob->data),
  2475. blob->len) ||
  2476. !dbus_message_iter_close_container(&entry_iter,
  2477. &array_iter) ||
  2478. !dbus_message_iter_close_container(&dict_iter,
  2479. &entry_iter)) {
  2480. dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY,
  2481. "no memory");
  2482. return FALSE;
  2483. }
  2484. blob = blob->next;
  2485. }
  2486. if (!dbus_message_iter_close_container(&variant_iter, &dict_iter) ||
  2487. !dbus_message_iter_close_container(iter, &variant_iter)) {
  2488. dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
  2489. return FALSE;
  2490. }
  2491. return TRUE;
  2492. }
  2493. static struct wpa_bss * get_bss_helper(struct bss_handler_args *args,
  2494. DBusError *error, const char *func_name)
  2495. {
  2496. struct wpa_bss *res = wpa_bss_get_id(args->wpa_s, args->id);
  2497. if (!res) {
  2498. wpa_printf(MSG_ERROR, "%s[dbus]: no bss with id %d found",
  2499. func_name, args->id);
  2500. dbus_set_error(error, DBUS_ERROR_FAILED,
  2501. "%s: BSS %d not found",
  2502. func_name, args->id);
  2503. }
  2504. return res;
  2505. }
  2506. /**
  2507. * wpas_dbus_getter_bss_bssid - Return the BSSID of a BSS
  2508. * @iter: Pointer to incoming dbus message iter
  2509. * @error: Location to store error on failure
  2510. * @user_data: Function specific data
  2511. * Returns: TRUE on success, FALSE on failure
  2512. *
  2513. * Getter for "BSSID" property.
  2514. */
  2515. dbus_bool_t wpas_dbus_getter_bss_bssid(DBusMessageIter *iter, DBusError *error,
  2516. void *user_data)
  2517. {
  2518. struct bss_handler_args *args = user_data;
  2519. struct wpa_bss *res;
  2520. res = get_bss_helper(args, error, __func__);
  2521. if (!res)
  2522. return FALSE;
  2523. return wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE,
  2524. res->bssid, ETH_ALEN,
  2525. error);
  2526. }
  2527. /**
  2528. * wpas_dbus_getter_bss_ssid - Return the SSID of a BSS
  2529. * @iter: Pointer to incoming dbus message iter
  2530. * @error: Location to store error on failure
  2531. * @user_data: Function specific data
  2532. * Returns: TRUE on success, FALSE on failure
  2533. *
  2534. * Getter for "SSID" property.
  2535. */
  2536. dbus_bool_t wpas_dbus_getter_bss_ssid(DBusMessageIter *iter, DBusError *error,
  2537. void *user_data)
  2538. {
  2539. struct bss_handler_args *args = user_data;
  2540. struct wpa_bss *res;
  2541. res = get_bss_helper(args, error, __func__);
  2542. if (!res)
  2543. return FALSE;
  2544. return wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE,
  2545. res->ssid, res->ssid_len,
  2546. error);
  2547. }
  2548. /**
  2549. * wpas_dbus_getter_bss_privacy - Return the privacy flag of a BSS
  2550. * @iter: Pointer to incoming dbus message iter
  2551. * @error: Location to store error on failure
  2552. * @user_data: Function specific data
  2553. * Returns: TRUE on success, FALSE on failure
  2554. *
  2555. * Getter for "Privacy" property.
  2556. */
  2557. dbus_bool_t wpas_dbus_getter_bss_privacy(DBusMessageIter *iter,
  2558. DBusError *error, void *user_data)
  2559. {
  2560. struct bss_handler_args *args = user_data;
  2561. struct wpa_bss *res;
  2562. dbus_bool_t privacy;
  2563. res = get_bss_helper(args, error, __func__);
  2564. if (!res)
  2565. return FALSE;
  2566. privacy = (res->caps & IEEE80211_CAP_PRIVACY) ? TRUE : FALSE;
  2567. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
  2568. &privacy, error);
  2569. }
  2570. /**
  2571. * wpas_dbus_getter_bss_mode - Return the mode of a BSS
  2572. * @iter: Pointer to incoming dbus message iter
  2573. * @error: Location to store error on failure
  2574. * @user_data: Function specific data
  2575. * Returns: TRUE on success, FALSE on failure
  2576. *
  2577. * Getter for "Mode" property.
  2578. */
  2579. dbus_bool_t wpas_dbus_getter_bss_mode(DBusMessageIter *iter, DBusError *error,
  2580. void *user_data)
  2581. {
  2582. struct bss_handler_args *args = user_data;
  2583. struct wpa_bss *res;
  2584. const char *mode;
  2585. res = get_bss_helper(args, error, __func__);
  2586. if (!res)
  2587. return FALSE;
  2588. if (res->caps & IEEE80211_CAP_IBSS)
  2589. mode = "ad-hoc";
  2590. else
  2591. mode = "infrastructure";
  2592. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
  2593. &mode, error);
  2594. }
  2595. /**
  2596. * wpas_dbus_getter_bss_level - Return the signal strength of a BSS
  2597. * @iter: Pointer to incoming dbus message iter
  2598. * @error: Location to store error on failure
  2599. * @user_data: Function specific data
  2600. * Returns: TRUE on success, FALSE on failure
  2601. *
  2602. * Getter for "Level" property.
  2603. */
  2604. dbus_bool_t wpas_dbus_getter_bss_signal(DBusMessageIter *iter,
  2605. DBusError *error, void *user_data)
  2606. {
  2607. struct bss_handler_args *args = user_data;
  2608. struct wpa_bss *res;
  2609. s16 level;
  2610. res = get_bss_helper(args, error, __func__);
  2611. if (!res)
  2612. return FALSE;
  2613. level = (s16) res->level;
  2614. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_INT16,
  2615. &level, error);
  2616. }
  2617. /**
  2618. * wpas_dbus_getter_bss_frequency - Return the frequency of a BSS
  2619. * @iter: Pointer to incoming dbus message iter
  2620. * @error: Location to store error on failure
  2621. * @user_data: Function specific data
  2622. * Returns: TRUE on success, FALSE on failure
  2623. *
  2624. * Getter for "Frequency" property.
  2625. */
  2626. dbus_bool_t wpas_dbus_getter_bss_frequency(DBusMessageIter *iter,
  2627. DBusError *error, void *user_data)
  2628. {
  2629. struct bss_handler_args *args = user_data;
  2630. struct wpa_bss *res;
  2631. u16 freq;
  2632. res = get_bss_helper(args, error, __func__);
  2633. if (!res)
  2634. return FALSE;
  2635. freq = (u16) res->freq;
  2636. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT16,
  2637. &freq, error);
  2638. }
  2639. static int cmp_u8s_desc(const void *a, const void *b)
  2640. {
  2641. return (*(u8 *) b - *(u8 *) a);
  2642. }
  2643. /**
  2644. * wpas_dbus_getter_bss_rates - Return available bit rates of a BSS
  2645. * @iter: Pointer to incoming dbus message iter
  2646. * @error: Location to store error on failure
  2647. * @user_data: Function specific data
  2648. * Returns: TRUE on success, FALSE on failure
  2649. *
  2650. * Getter for "Rates" property.
  2651. */
  2652. dbus_bool_t wpas_dbus_getter_bss_rates(DBusMessageIter *iter,
  2653. DBusError *error, void *user_data)
  2654. {
  2655. struct bss_handler_args *args = user_data;
  2656. struct wpa_bss *res;
  2657. u8 *ie_rates = NULL;
  2658. u32 *real_rates;
  2659. int rates_num, i;
  2660. dbus_bool_t success = FALSE;
  2661. res = get_bss_helper(args, error, __func__);
  2662. if (!res)
  2663. return FALSE;
  2664. rates_num = wpa_bss_get_bit_rates(res, &ie_rates);
  2665. if (rates_num < 0)
  2666. return FALSE;
  2667. qsort(ie_rates, rates_num, 1, cmp_u8s_desc);
  2668. real_rates = os_malloc(sizeof(u32) * rates_num);
  2669. if (!real_rates) {
  2670. os_free(ie_rates);
  2671. dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
  2672. return FALSE;
  2673. }
  2674. for (i = 0; i < rates_num; i++)
  2675. real_rates[i] = ie_rates[i] * 500000;
  2676. success = wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_UINT32,
  2677. real_rates, rates_num,
  2678. error);
  2679. os_free(ie_rates);
  2680. os_free(real_rates);
  2681. return success;
  2682. }
  2683. static dbus_bool_t wpas_dbus_get_bss_security_prop(DBusMessageIter *iter,
  2684. struct wpa_ie_data *ie_data,
  2685. DBusError *error)
  2686. {
  2687. DBusMessageIter iter_dict, variant_iter;
  2688. const char *group;
  2689. const char *pairwise[2]; /* max 2 pairwise ciphers is supported */
  2690. const char *key_mgmt[7]; /* max 7 key managements may be supported */
  2691. int n;
  2692. if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
  2693. "a{sv}", &variant_iter))
  2694. goto nomem;
  2695. if (!wpa_dbus_dict_open_write(&variant_iter, &iter_dict))
  2696. goto nomem;
  2697. /* KeyMgmt */
  2698. n = 0;
  2699. if (ie_data->key_mgmt & WPA_KEY_MGMT_PSK)
  2700. key_mgmt[n++] = "wpa-psk";
  2701. if (ie_data->key_mgmt & WPA_KEY_MGMT_FT_PSK)
  2702. key_mgmt[n++] = "wpa-ft-psk";
  2703. if (ie_data->key_mgmt & WPA_KEY_MGMT_PSK_SHA256)
  2704. key_mgmt[n++] = "wpa-psk-sha256";
  2705. if (ie_data->key_mgmt & WPA_KEY_MGMT_IEEE8021X)
  2706. key_mgmt[n++] = "wpa-eap";
  2707. if (ie_data->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X)
  2708. key_mgmt[n++] = "wpa-ft-eap";
  2709. if (ie_data->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256)
  2710. key_mgmt[n++] = "wpa-eap-sha256";
  2711. if (ie_data->key_mgmt & WPA_KEY_MGMT_NONE)
  2712. key_mgmt[n++] = "wpa-none";
  2713. if (!wpa_dbus_dict_append_string_array(&iter_dict, "KeyMgmt",
  2714. key_mgmt, n))
  2715. goto nomem;
  2716. /* Group */
  2717. switch (ie_data->group_cipher) {
  2718. case WPA_CIPHER_WEP40:
  2719. group = "wep40";
  2720. break;
  2721. case WPA_CIPHER_TKIP:
  2722. group = "tkip";
  2723. break;
  2724. case WPA_CIPHER_CCMP:
  2725. group = "ccmp";
  2726. break;
  2727. case WPA_CIPHER_WEP104:
  2728. group = "wep104";
  2729. break;
  2730. default:
  2731. group = "";
  2732. break;
  2733. }
  2734. if (!wpa_dbus_dict_append_string(&iter_dict, "Group", group))
  2735. goto nomem;
  2736. /* Pairwise */
  2737. n = 0;
  2738. if (ie_data->pairwise_cipher & WPA_CIPHER_TKIP)
  2739. pairwise[n++] = "tkip";
  2740. if (ie_data->pairwise_cipher & WPA_CIPHER_CCMP)
  2741. pairwise[n++] = "ccmp";
  2742. if (!wpa_dbus_dict_append_string_array(&iter_dict, "Pairwise",
  2743. pairwise, n))
  2744. goto nomem;
  2745. /* Management group (RSN only) */
  2746. if (ie_data->proto == WPA_PROTO_RSN) {
  2747. switch (ie_data->mgmt_group_cipher) {
  2748. #ifdef CONFIG_IEEE80211W
  2749. case WPA_CIPHER_AES_128_CMAC:
  2750. group = "aes128cmac";
  2751. break;
  2752. #endif /* CONFIG_IEEE80211W */
  2753. default:
  2754. group = "";
  2755. break;
  2756. }
  2757. if (!wpa_dbus_dict_append_string(&iter_dict, "MgmtGroup",
  2758. group))
  2759. goto nomem;
  2760. }
  2761. if (!wpa_dbus_dict_close_write(&variant_iter, &iter_dict))
  2762. goto nomem;
  2763. if (!dbus_message_iter_close_container(iter, &variant_iter))
  2764. goto nomem;
  2765. return TRUE;
  2766. nomem:
  2767. dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
  2768. return FALSE;
  2769. }
  2770. /**
  2771. * wpas_dbus_getter_bss_wpa - Return the WPA options of a BSS
  2772. * @iter: Pointer to incoming dbus message iter
  2773. * @error: Location to store error on failure
  2774. * @user_data: Function specific data
  2775. * Returns: TRUE on success, FALSE on failure
  2776. *
  2777. * Getter for "WPA" property.
  2778. */
  2779. dbus_bool_t wpas_dbus_getter_bss_wpa(DBusMessageIter *iter, DBusError *error,
  2780. void *user_data)
  2781. {
  2782. struct bss_handler_args *args = user_data;
  2783. struct wpa_bss *res;
  2784. struct wpa_ie_data wpa_data;
  2785. const u8 *ie;
  2786. res = get_bss_helper(args, error, __func__);
  2787. if (!res)
  2788. return FALSE;
  2789. os_memset(&wpa_data, 0, sizeof(wpa_data));
  2790. ie = wpa_bss_get_vendor_ie(res, WPA_IE_VENDOR_TYPE);
  2791. if (ie) {
  2792. if (wpa_parse_wpa_ie(ie, 2 + ie[1], &wpa_data) < 0) {
  2793. dbus_set_error_const(error, DBUS_ERROR_FAILED,
  2794. "failed to parse WPA IE");
  2795. return FALSE;
  2796. }
  2797. }
  2798. return wpas_dbus_get_bss_security_prop(iter, &wpa_data, error);
  2799. }
  2800. /**
  2801. * wpas_dbus_getter_bss_rsn - Return the RSN options of a BSS
  2802. * @iter: Pointer to incoming dbus message iter
  2803. * @error: Location to store error on failure
  2804. * @user_data: Function specific data
  2805. * Returns: TRUE on success, FALSE on failure
  2806. *
  2807. * Getter for "RSN" property.
  2808. */
  2809. dbus_bool_t wpas_dbus_getter_bss_rsn(DBusMessageIter *iter, DBusError *error,
  2810. void *user_data)
  2811. {
  2812. struct bss_handler_args *args = user_data;
  2813. struct wpa_bss *res;
  2814. struct wpa_ie_data wpa_data;
  2815. const u8 *ie;
  2816. res = get_bss_helper(args, error, __func__);
  2817. if (!res)
  2818. return FALSE;
  2819. os_memset(&wpa_data, 0, sizeof(wpa_data));
  2820. ie = wpa_bss_get_ie(res, WLAN_EID_RSN);
  2821. if (ie) {
  2822. if (wpa_parse_wpa_ie(ie, 2 + ie[1], &wpa_data) < 0) {
  2823. dbus_set_error_const(error, DBUS_ERROR_FAILED,
  2824. "failed to parse RSN IE");
  2825. return FALSE;
  2826. }
  2827. }
  2828. return wpas_dbus_get_bss_security_prop(iter, &wpa_data, error);
  2829. }
  2830. /**
  2831. * wpas_dbus_getter_bss_ies - Return all IEs of a BSS
  2832. * @iter: Pointer to incoming dbus message iter
  2833. * @error: Location to store error on failure
  2834. * @user_data: Function specific data
  2835. * Returns: TRUE on success, FALSE on failure
  2836. *
  2837. * Getter for "IEs" property.
  2838. */
  2839. dbus_bool_t wpas_dbus_getter_bss_ies(DBusMessageIter *iter, DBusError *error,
  2840. void *user_data)
  2841. {
  2842. struct bss_handler_args *args = user_data;
  2843. struct wpa_bss *res;
  2844. res = get_bss_helper(args, error, __func__);
  2845. if (!res)
  2846. return FALSE;
  2847. return wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE,
  2848. res + 1, res->ie_len,
  2849. error);
  2850. }
  2851. /**
  2852. * wpas_dbus_getter_enabled - Check whether network is enabled or disabled
  2853. * @iter: Pointer to incoming dbus message iter
  2854. * @error: Location to store error on failure
  2855. * @user_data: Function specific data
  2856. * Returns: TRUE on success, FALSE on failure
  2857. *
  2858. * Getter for "enabled" property of a configured network.
  2859. */
  2860. dbus_bool_t wpas_dbus_getter_enabled(DBusMessageIter *iter, DBusError *error,
  2861. void *user_data)
  2862. {
  2863. struct network_handler_args *net = user_data;
  2864. dbus_bool_t enabled = net->ssid->disabled ? FALSE : TRUE;
  2865. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
  2866. &enabled, error);
  2867. }
  2868. /**
  2869. * wpas_dbus_setter_enabled - Mark a configured network as enabled or disabled
  2870. * @iter: Pointer to incoming dbus message iter
  2871. * @error: Location to store error on failure
  2872. * @user_data: Function specific data
  2873. * Returns: TRUE on success, FALSE on failure
  2874. *
  2875. * Setter for "Enabled" property of a configured network.
  2876. */
  2877. dbus_bool_t wpas_dbus_setter_enabled(DBusMessageIter *iter, DBusError *error,
  2878. void *user_data)
  2879. {
  2880. struct network_handler_args *net = user_data;
  2881. struct wpa_supplicant *wpa_s;
  2882. struct wpa_ssid *ssid;
  2883. dbus_bool_t enable;
  2884. if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_BOOLEAN,
  2885. &enable))
  2886. return FALSE;
  2887. wpa_s = net->wpa_s;
  2888. ssid = net->ssid;
  2889. if (enable)
  2890. wpa_supplicant_enable_network(wpa_s, ssid);
  2891. else
  2892. wpa_supplicant_disable_network(wpa_s, ssid);
  2893. return TRUE;
  2894. }
  2895. /**
  2896. * wpas_dbus_getter_network_properties - Get options for a configured network
  2897. * @iter: Pointer to incoming dbus message iter
  2898. * @error: Location to store error on failure
  2899. * @user_data: Function specific data
  2900. * Returns: TRUE on success, FALSE on failure
  2901. *
  2902. * Getter for "Properties" property of a configured network.
  2903. */
  2904. dbus_bool_t wpas_dbus_getter_network_properties(DBusMessageIter *iter,
  2905. DBusError *error,
  2906. void *user_data)
  2907. {
  2908. struct network_handler_args *net = user_data;
  2909. DBusMessageIter variant_iter, dict_iter;
  2910. char **iterator;
  2911. char **props = wpa_config_get_all(net->ssid, 1);
  2912. dbus_bool_t success = FALSE;
  2913. if (!props) {
  2914. dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
  2915. return FALSE;
  2916. }
  2917. if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, "a{sv}",
  2918. &variant_iter) ||
  2919. !wpa_dbus_dict_open_write(&variant_iter, &dict_iter)) {
  2920. dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
  2921. goto out;
  2922. }
  2923. iterator = props;
  2924. while (*iterator) {
  2925. if (!wpa_dbus_dict_append_string(&dict_iter, *iterator,
  2926. *(iterator + 1))) {
  2927. dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY,
  2928. "no memory");
  2929. goto out;
  2930. }
  2931. iterator += 2;
  2932. }
  2933. if (!wpa_dbus_dict_close_write(&variant_iter, &dict_iter) ||
  2934. !dbus_message_iter_close_container(iter, &variant_iter)) {
  2935. dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
  2936. goto out;
  2937. }
  2938. success = TRUE;
  2939. out:
  2940. iterator = props;
  2941. while (*iterator) {
  2942. os_free(*iterator);
  2943. iterator++;
  2944. }
  2945. os_free(props);
  2946. return success;
  2947. }
  2948. /**
  2949. * wpas_dbus_setter_network_properties - Set options for a configured network
  2950. * @iter: Pointer to incoming dbus message iter
  2951. * @error: Location to store error on failure
  2952. * @user_data: Function specific data
  2953. * Returns: TRUE on success, FALSE on failure
  2954. *
  2955. * Setter for "Properties" property of a configured network.
  2956. */
  2957. dbus_bool_t wpas_dbus_setter_network_properties(DBusMessageIter *iter,
  2958. DBusError *error,
  2959. void *user_data)
  2960. {
  2961. struct network_handler_args *net = user_data;
  2962. struct wpa_ssid *ssid = net->ssid;
  2963. DBusMessageIter variant_iter;
  2964. dbus_message_iter_recurse(iter, &variant_iter);
  2965. return set_network_properties(net->wpa_s, ssid, &variant_iter, error);
  2966. }
  2967. #ifdef CONFIG_AP
  2968. DBusMessage * wpas_dbus_handler_subscribe_preq(
  2969. DBusMessage *message, struct wpa_supplicant *wpa_s)
  2970. {
  2971. struct wpas_dbus_priv *priv = wpa_s->global->dbus;
  2972. char *name;
  2973. if (wpa_s->preq_notify_peer != NULL) {
  2974. if (os_strcmp(dbus_message_get_sender(message),
  2975. wpa_s->preq_notify_peer) == 0)
  2976. return NULL;
  2977. return dbus_message_new_error(message,
  2978. WPAS_DBUS_ERROR_SUBSCRIPTION_IN_USE,
  2979. "Another application is already subscribed");
  2980. }
  2981. name = os_strdup(dbus_message_get_sender(message));
  2982. if (!name)
  2983. return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  2984. "out of memory");
  2985. wpa_s->preq_notify_peer = name;
  2986. /* Subscribe to clean up if application closes socket */
  2987. wpas_dbus_subscribe_noc(priv);
  2988. /*
  2989. * Double-check it's still alive to make sure that we didn't
  2990. * miss the NameOwnerChanged signal, e.g. while strdup'ing.
  2991. */
  2992. if (!dbus_bus_name_has_owner(priv->con, name, NULL)) {
  2993. /*
  2994. * Application no longer exists, clean up.
  2995. * The return value is irrelevant now.
  2996. *
  2997. * Need to check if the NameOwnerChanged handling
  2998. * already cleaned up because we have processed
  2999. * DBus messages while checking if the name still
  3000. * has an owner.
  3001. */
  3002. if (!wpa_s->preq_notify_peer)
  3003. return NULL;
  3004. os_free(wpa_s->preq_notify_peer);
  3005. wpa_s->preq_notify_peer = NULL;
  3006. wpas_dbus_unsubscribe_noc(priv);
  3007. }
  3008. return NULL;
  3009. }
  3010. DBusMessage * wpas_dbus_handler_unsubscribe_preq(
  3011. DBusMessage *message, struct wpa_supplicant *wpa_s)
  3012. {
  3013. struct wpas_dbus_priv *priv = wpa_s->global->dbus;
  3014. if (!wpa_s->preq_notify_peer)
  3015. return dbus_message_new_error(message,
  3016. WPAS_DBUS_ERROR_NO_SUBSCRIPTION,
  3017. "Not subscribed");
  3018. if (os_strcmp(wpa_s->preq_notify_peer,
  3019. dbus_message_get_sender(message)))
  3020. return dbus_message_new_error(message,
  3021. WPAS_DBUS_ERROR_SUBSCRIPTION_EPERM,
  3022. "Can't unsubscribe others");
  3023. os_free(wpa_s->preq_notify_peer);
  3024. wpa_s->preq_notify_peer = NULL;
  3025. wpas_dbus_unsubscribe_noc(priv);
  3026. return NULL;
  3027. }
  3028. void wpas_dbus_signal_preq(struct wpa_supplicant *wpa_s,
  3029. const u8 *addr, const u8 *dst, const u8 *bssid,
  3030. const u8 *ie, size_t ie_len, u32 ssi_signal)
  3031. {
  3032. DBusMessage *msg;
  3033. DBusMessageIter iter, dict_iter;
  3034. struct wpas_dbus_priv *priv = wpa_s->global->dbus;
  3035. /* Do nothing if the control interface is not turned on */
  3036. if (priv == NULL)
  3037. return;
  3038. if (wpa_s->preq_notify_peer == NULL)
  3039. return;
  3040. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  3041. WPAS_DBUS_NEW_IFACE_INTERFACE,
  3042. "ProbeRequest");
  3043. if (msg == NULL)
  3044. return;
  3045. dbus_message_set_destination(msg, wpa_s->preq_notify_peer);
  3046. dbus_message_iter_init_append(msg, &iter);
  3047. if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
  3048. goto fail;
  3049. if (addr && !wpa_dbus_dict_append_byte_array(&dict_iter, "addr",
  3050. (const char *) addr,
  3051. ETH_ALEN))
  3052. goto fail;
  3053. if (dst && !wpa_dbus_dict_append_byte_array(&dict_iter, "dst",
  3054. (const char *) dst,
  3055. ETH_ALEN))
  3056. goto fail;
  3057. if (bssid && !wpa_dbus_dict_append_byte_array(&dict_iter, "bssid",
  3058. (const char *) bssid,
  3059. ETH_ALEN))
  3060. goto fail;
  3061. if (ie && ie_len && !wpa_dbus_dict_append_byte_array(&dict_iter, "ies",
  3062. (const char *) ie,
  3063. ie_len))
  3064. goto fail;
  3065. if (ssi_signal && !wpa_dbus_dict_append_int32(&dict_iter, "signal",
  3066. ssi_signal))
  3067. goto fail;
  3068. if (!wpa_dbus_dict_close_write(&iter, &dict_iter))
  3069. goto fail;
  3070. dbus_connection_send(priv->con, msg, NULL);
  3071. goto out;
  3072. fail:
  3073. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  3074. out:
  3075. dbus_message_unref(msg);
  3076. }
  3077. #endif /* CONFIG_AP */