dbus_new_handlers.c 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962
  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, 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 "../config.h"
  22. #include "../wpa_supplicant_i.h"
  23. #include "../driver_i.h"
  24. #include "../notify.h"
  25. #include "../wpas_glue.h"
  26. #include "../bss.h"
  27. #include "dbus_new_helpers.h"
  28. #include "dbus_new.h"
  29. #include "dbus_new_handlers.h"
  30. #include "dbus_dict_helpers.h"
  31. extern int wpa_debug_level;
  32. extern int wpa_debug_show_keys;
  33. extern int wpa_debug_timestamp;
  34. /**
  35. * wpas_dbus_new_decompose_object_path - Decompose an interface object path into parts
  36. * @path: The dbus object path
  37. * @network: (out) the configured network this object path refers to, if any
  38. * @bssid: (out) the scanned bssid this object path refers to, if any
  39. * Returns: The object path of the network interface this path refers to
  40. *
  41. * For a given object path, decomposes the object path into object id, network,
  42. * and BSSID parts, if those parts exist.
  43. */
  44. static char * wpas_dbus_new_decompose_object_path(const char *path,
  45. char **network,
  46. char **bssid)
  47. {
  48. const unsigned int dev_path_prefix_len =
  49. strlen(WPAS_DBUS_NEW_PATH_INTERFACES "/");
  50. char *obj_path_only;
  51. char *next_sep;
  52. /* Be a bit paranoid about path */
  53. if (!path || os_strncmp(path, WPAS_DBUS_NEW_PATH_INTERFACES "/",
  54. dev_path_prefix_len))
  55. return NULL;
  56. /* Ensure there's something at the end of the path */
  57. if ((path + dev_path_prefix_len)[0] == '\0')
  58. return NULL;
  59. obj_path_only = os_strdup(path);
  60. if (obj_path_only == NULL)
  61. return NULL;
  62. next_sep = os_strchr(obj_path_only + dev_path_prefix_len, '/');
  63. if (next_sep != NULL) {
  64. const char *net_part = os_strstr(
  65. next_sep, WPAS_DBUS_NEW_NETWORKS_PART "/");
  66. const char *bssid_part = os_strstr(
  67. next_sep, WPAS_DBUS_NEW_BSSIDS_PART "/");
  68. if (network && net_part) {
  69. /* Deal with a request for a configured network */
  70. const char *net_name = net_part +
  71. os_strlen(WPAS_DBUS_NEW_NETWORKS_PART "/");
  72. *network = NULL;
  73. if (os_strlen(net_name))
  74. *network = os_strdup(net_name);
  75. } else if (bssid && bssid_part) {
  76. /* Deal with a request for a scanned BSSID */
  77. const char *bssid_name = bssid_part +
  78. os_strlen(WPAS_DBUS_NEW_BSSIDS_PART "/");
  79. if (strlen(bssid_name))
  80. *bssid = os_strdup(bssid_name);
  81. else
  82. *bssid = NULL;
  83. }
  84. /* Cut off interface object path before "/" */
  85. *next_sep = '\0';
  86. }
  87. return obj_path_only;
  88. }
  89. /**
  90. * wpas_dbus_error_unknown_error - Return a new InvalidArgs error message
  91. * @message: Pointer to incoming dbus message this error refers to
  92. * @arg: Optional string appended to error message
  93. * Returns: a dbus error message
  94. *
  95. * Convenience function to create and return an UnknownError
  96. */
  97. DBusMessage * wpas_dbus_error_unknown_error(DBusMessage *message,
  98. const char *arg)
  99. {
  100. return dbus_message_new_error(message, WPAS_DBUS_ERROR_UNKNOWN_ERROR,
  101. arg);
  102. }
  103. /**
  104. * wpas_dbus_error_iface_unknown - Return a new invalid interface error message
  105. * @message: Pointer to incoming dbus message this error refers to
  106. * Returns: A dbus error message
  107. *
  108. * Convenience function to create and return an invalid interface error
  109. */
  110. static DBusMessage * wpas_dbus_error_iface_unknown(DBusMessage *message)
  111. {
  112. return dbus_message_new_error(message, WPAS_DBUS_ERROR_IFACE_UNKNOWN,
  113. "wpa_supplicant knows nothing about "
  114. "this interface.");
  115. }
  116. /**
  117. * wpas_dbus_error_network_unknown - Return a new NetworkUnknown error message
  118. * @message: Pointer to incoming dbus message this error refers to
  119. * Returns: a dbus error message
  120. *
  121. * Convenience function to create and return an invalid network error
  122. */
  123. static DBusMessage * wpas_dbus_error_network_unknown(DBusMessage *message)
  124. {
  125. return dbus_message_new_error(message, WPAS_DBUS_ERROR_NETWORK_UNKNOWN,
  126. "There is no such a network in this "
  127. "interface.");
  128. }
  129. /**
  130. * wpas_dbus_error_invald_args - Return a new InvalidArgs error message
  131. * @message: Pointer to incoming dbus message this error refers to
  132. * Returns: a dbus error message
  133. *
  134. * Convenience function to create and return an invalid options error
  135. */
  136. DBusMessage * wpas_dbus_error_invald_args(DBusMessage *message,
  137. const char *arg)
  138. {
  139. DBusMessage *reply;
  140. reply = dbus_message_new_error(message, WPAS_DBUS_ERROR_INVALID_ARGS,
  141. "Did not receive correct message "
  142. "arguments.");
  143. if (arg != NULL)
  144. dbus_message_append_args(reply, DBUS_TYPE_STRING, &arg,
  145. DBUS_TYPE_INVALID);
  146. return reply;
  147. }
  148. static const char *dont_quote[] = {
  149. "key_mgmt", "proto", "pairwise", "auth_alg", "group", "eap",
  150. "opensc_engine_path", "pkcs11_engine_path", "pkcs11_module_path",
  151. "bssid", NULL
  152. };
  153. static dbus_bool_t should_quote_opt(const char *key)
  154. {
  155. int i = 0;
  156. while (dont_quote[i] != NULL) {
  157. if (os_strcmp(key, dont_quote[i]) == 0)
  158. return FALSE;
  159. i++;
  160. }
  161. return TRUE;
  162. }
  163. /**
  164. * get_iface_by_dbus_path - Get a new network interface
  165. * @global: Pointer to global data from wpa_supplicant_init()
  166. * @path: Pointer to a dbus object path representing an interface
  167. * Returns: Pointer to the interface or %NULL if not found
  168. */
  169. static struct wpa_supplicant * get_iface_by_dbus_path(
  170. struct wpa_global *global, const char *path)
  171. {
  172. struct wpa_supplicant *wpa_s;
  173. for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
  174. if (os_strcmp(wpa_s->dbus_new_path, path) == 0)
  175. return wpa_s;
  176. }
  177. return NULL;
  178. }
  179. /**
  180. * set_network_properties - Set properties of a configured network
  181. * @message: Pointer to incoming dbus message
  182. * @ssid: wpa_ssid structure for a configured network
  183. * @iter: DBus message iterator containing dictionary of network
  184. * properties to set.
  185. * Returns: NULL when succeed or DBus error on failure
  186. *
  187. * Sets network configuration with parameters given id DBus dictionary
  188. */
  189. static DBusMessage * set_network_properties(DBusMessage *message,
  190. struct wpa_ssid *ssid,
  191. DBusMessageIter *iter)
  192. {
  193. struct wpa_dbus_dict_entry entry = { .type = DBUS_TYPE_STRING };
  194. DBusMessage *reply = NULL;
  195. DBusMessageIter iter_dict;
  196. if (!wpa_dbus_dict_open_read(iter, &iter_dict))
  197. return wpas_dbus_error_invald_args(message, NULL);
  198. while (wpa_dbus_dict_has_dict_entry(&iter_dict)) {
  199. char *value = NULL;
  200. size_t size = 50;
  201. int ret;
  202. if (!wpa_dbus_dict_get_entry(&iter_dict, &entry)) {
  203. reply = wpas_dbus_error_invald_args(message, NULL);
  204. break;
  205. }
  206. if (entry.type == DBUS_TYPE_ARRAY &&
  207. entry.array_type == DBUS_TYPE_BYTE) {
  208. if (entry.array_len <= 0)
  209. goto error;
  210. size = entry.array_len * 2 + 1;
  211. value = os_zalloc(size);
  212. if (value == NULL)
  213. goto error;
  214. ret = wpa_snprintf_hex(value, size,
  215. (u8 *) entry.bytearray_value,
  216. entry.array_len);
  217. if (ret <= 0)
  218. goto error;
  219. } else if (entry.type == DBUS_TYPE_STRING) {
  220. if (should_quote_opt(entry.key)) {
  221. size = os_strlen(entry.str_value);
  222. if (size <= 0)
  223. goto error;
  224. size += 3;
  225. value = os_zalloc(size);
  226. if (value == NULL)
  227. goto error;
  228. ret = os_snprintf(value, size, "\"%s\"",
  229. entry.str_value);
  230. if (ret < 0 || (size_t) ret != (size - 1))
  231. goto error;
  232. } else {
  233. value = os_strdup(entry.str_value);
  234. if (value == NULL)
  235. goto error;
  236. }
  237. } else if (entry.type == DBUS_TYPE_UINT32) {
  238. value = os_zalloc(size);
  239. if (value == NULL)
  240. goto error;
  241. ret = os_snprintf(value, size, "%u",
  242. entry.uint32_value);
  243. if (ret <= 0)
  244. goto error;
  245. } else if (entry.type == DBUS_TYPE_INT32) {
  246. value = os_zalloc(size);
  247. if (value == NULL)
  248. goto error;
  249. ret = os_snprintf(value, size, "%d",
  250. entry.int32_value);
  251. if (ret <= 0)
  252. goto error;
  253. } else
  254. goto error;
  255. if (wpa_config_set(ssid, entry.key, value, 0) < 0)
  256. goto error;
  257. if ((os_strcmp(entry.key, "psk") == 0 &&
  258. value[0] == '"' && ssid->ssid_len) ||
  259. (strcmp(entry.key, "ssid") == 0 && ssid->passphrase))
  260. wpa_config_update_psk(ssid);
  261. os_free(value);
  262. wpa_dbus_dict_entry_clear(&entry);
  263. continue;
  264. error:
  265. os_free(value);
  266. reply = wpas_dbus_error_invald_args(message, entry.key);
  267. wpa_dbus_dict_entry_clear(&entry);
  268. break;
  269. }
  270. return reply;
  271. }
  272. static const char * _get_dbus_type_as_string(const int type)
  273. {
  274. switch(type) {
  275. case DBUS_TYPE_BYTE:
  276. return DBUS_TYPE_BYTE_AS_STRING;
  277. case DBUS_TYPE_BOOLEAN:
  278. return DBUS_TYPE_BOOLEAN_AS_STRING;
  279. case DBUS_TYPE_INT16:
  280. return DBUS_TYPE_INT16_AS_STRING;
  281. case DBUS_TYPE_UINT16:
  282. return DBUS_TYPE_UINT16_AS_STRING;
  283. case DBUS_TYPE_INT32:
  284. return DBUS_TYPE_INT32_AS_STRING;
  285. case DBUS_TYPE_UINT32:
  286. return DBUS_TYPE_UINT32_AS_STRING;
  287. case DBUS_TYPE_INT64:
  288. return DBUS_TYPE_INT64_AS_STRING;
  289. case DBUS_TYPE_UINT64:
  290. return DBUS_TYPE_UINT64_AS_STRING;
  291. case DBUS_TYPE_DOUBLE:
  292. return DBUS_TYPE_DOUBLE_AS_STRING;
  293. case DBUS_TYPE_STRING:
  294. return DBUS_TYPE_STRING_AS_STRING;
  295. case DBUS_TYPE_OBJECT_PATH:
  296. return DBUS_TYPE_OBJECT_PATH_AS_STRING;
  297. default:
  298. return NULL;
  299. }
  300. }
  301. /**
  302. * wpas_dbus_simple_property_getter - Get basic type property
  303. * @message: Pointer to incoming dbus message
  304. * @type: DBus type of property (must be basic type)
  305. * @val: pointer to place holding property value
  306. * Returns: The DBus message containing response for Properties.Get call
  307. * or DBus error message if error occurred.
  308. *
  309. * Generic getter for basic type properties. Type is required to be basic.
  310. */
  311. DBusMessage * wpas_dbus_simple_property_getter(DBusMessage *message,
  312. const int type, const void *val)
  313. {
  314. DBusMessage *reply = NULL;
  315. DBusMessageIter iter, variant_iter;
  316. if (!dbus_type_is_basic(type)) {
  317. wpa_printf(MSG_ERROR, "dbus: wpas_dbus_simple_property_getter:"
  318. " given type is not basic");
  319. return wpas_dbus_error_unknown_error(message, NULL);
  320. }
  321. if (message == NULL)
  322. reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
  323. else
  324. reply = dbus_message_new_method_return(message);
  325. if (reply != NULL) {
  326. dbus_message_iter_init_append(reply, &iter);
  327. if (!dbus_message_iter_open_container(
  328. &iter, DBUS_TYPE_VARIANT,
  329. _get_dbus_type_as_string(type), &variant_iter) ||
  330. !dbus_message_iter_append_basic(&variant_iter, type,
  331. val) ||
  332. !dbus_message_iter_close_container(&iter, &variant_iter)) {
  333. wpa_printf(MSG_ERROR, "dbus: "
  334. "wpas_dbus_simple_property_getter: out of "
  335. "memory to put property value into "
  336. "message");
  337. dbus_message_unref(reply);
  338. reply = dbus_message_new_error(message,
  339. DBUS_ERROR_NO_MEMORY,
  340. NULL);
  341. }
  342. } else {
  343. wpa_printf(MSG_ERROR, "dbus: wpas_dbus_simple_property_getter:"
  344. " out of memory to return property value");
  345. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  346. NULL);
  347. }
  348. return reply;
  349. }
  350. /**
  351. * wpas_dbus_simple_property_setter - Set basic type property
  352. * @message: Pointer to incoming dbus message
  353. * @type: DBus type of property (must be basic type)
  354. * @val: pointer to place where value being set will be stored
  355. * Returns: NULL or DBus error message if error occurred.
  356. *
  357. * Generic setter for basic type properties. Type is required to be basic.
  358. */
  359. DBusMessage * wpas_dbus_simple_property_setter(DBusMessage *message,
  360. const int type, void *val)
  361. {
  362. DBusMessageIter iter, variant_iter;
  363. if (!dbus_type_is_basic(type)) {
  364. wpa_printf(MSG_ERROR, "dbus: wpas_dbus_simple_property_setter:"
  365. " given type is not basic");
  366. return wpas_dbus_error_unknown_error(message, NULL);
  367. }
  368. if (!dbus_message_iter_init(message, &iter)) {
  369. wpa_printf(MSG_ERROR, "dbus: wpas_dbus_simple_property_setter:"
  370. " out of memory to return scanning state");
  371. return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  372. NULL);
  373. }
  374. /* omit first and second argument and get value from third */
  375. dbus_message_iter_next(&iter);
  376. dbus_message_iter_next(&iter);
  377. dbus_message_iter_recurse(&iter, &variant_iter);
  378. if (dbus_message_iter_get_arg_type(&variant_iter) != type) {
  379. return wpas_dbus_error_invald_args(message,
  380. "wrong property type");
  381. }
  382. dbus_message_iter_get_basic(&variant_iter, val);
  383. return NULL;
  384. }
  385. /**
  386. * wpas_dbus_simple_array_property_getter - Get array type property
  387. * @message: Pointer to incoming dbus message
  388. * @type: DBus type of property array elements (must be basic type)
  389. * @array: pointer to array of elements to put into response message
  390. * @array_len: length of above array
  391. * Returns: The DBus message containing response for Properties.Get call
  392. * or DBus error message if error occurred.
  393. *
  394. * Generic getter for array type properties. Array elements type is
  395. * required to be basic.
  396. */
  397. DBusMessage * wpas_dbus_simple_array_property_getter(DBusMessage *message,
  398. const int type,
  399. const void *array,
  400. size_t array_len)
  401. {
  402. DBusMessage *reply = NULL;
  403. DBusMessageIter iter, variant_iter, array_iter;
  404. char type_str[] = "a?"; /* ? will be replaced with subtype letter; */
  405. const char *sub_type_str;
  406. size_t element_size, i;
  407. if (!dbus_type_is_basic(type)) {
  408. wpa_printf(MSG_ERROR, "dbus: "
  409. "wpas_dbus_simple_array_property_getter: given "
  410. "type is not basic");
  411. return wpas_dbus_error_unknown_error(message, NULL);
  412. }
  413. sub_type_str = _get_dbus_type_as_string(type);
  414. type_str[1] = sub_type_str[0];
  415. if (message == NULL)
  416. reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
  417. else
  418. reply = dbus_message_new_method_return(message);
  419. if (reply == NULL) {
  420. wpa_printf(MSG_ERROR, "dbus: "
  421. "wpas_dbus_simple_array_property_getter: out of "
  422. "memory to create return message");
  423. return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  424. NULL);
  425. }
  426. dbus_message_iter_init_append(reply, &iter);
  427. if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
  428. type_str, &variant_iter) ||
  429. !dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
  430. sub_type_str, &array_iter)) {
  431. wpa_printf(MSG_ERROR, "dbus: "
  432. "wpas_dbus_simple_array_property_getter: out of "
  433. "memory to open container");
  434. dbus_message_unref(reply);
  435. return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  436. NULL);
  437. }
  438. switch(type) {
  439. case DBUS_TYPE_BYTE:
  440. case DBUS_TYPE_BOOLEAN:
  441. element_size = 1;
  442. break;
  443. case DBUS_TYPE_INT16:
  444. case DBUS_TYPE_UINT16:
  445. element_size = sizeof(uint16_t);
  446. break;
  447. case DBUS_TYPE_INT32:
  448. case DBUS_TYPE_UINT32:
  449. element_size = sizeof(uint32_t);
  450. break;
  451. case DBUS_TYPE_INT64:
  452. case DBUS_TYPE_UINT64:
  453. element_size = sizeof(uint64_t);
  454. break;
  455. case DBUS_TYPE_DOUBLE:
  456. element_size = sizeof(double);
  457. break;
  458. case DBUS_TYPE_STRING:
  459. case DBUS_TYPE_OBJECT_PATH:
  460. element_size = sizeof(char *);
  461. break;
  462. default:
  463. wpa_printf(MSG_ERROR, "dbus: "
  464. "wpas_dbus_simple_array_property_getter: "
  465. "fatal: unknown element type");
  466. element_size = 1;
  467. break;
  468. }
  469. for (i = 0; i < array_len; i++) {
  470. dbus_message_iter_append_basic(&array_iter, type,
  471. array + i * element_size);
  472. }
  473. if (!dbus_message_iter_close_container(&variant_iter, &array_iter) ||
  474. !dbus_message_iter_close_container(&iter, &variant_iter)) {
  475. wpa_printf(MSG_ERROR, "dbus: "
  476. "wpas_dbus_simple_array_property_getter: out of "
  477. "memory to close container");
  478. dbus_message_unref(reply);
  479. return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  480. NULL);
  481. }
  482. return reply;
  483. }
  484. /**
  485. * wpas_dbus_handler_create_interface - Request registration of a network iface
  486. * @message: Pointer to incoming dbus message
  487. * @global: %wpa_supplicant global data structure
  488. * Returns: The object path of the new interface object,
  489. * or a dbus error message with more information
  490. *
  491. * Handler function for "CreateInterface" method call. Handles requests
  492. * by dbus clients to register a network interface that wpa_supplicant
  493. * will manage.
  494. */
  495. DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message,
  496. struct wpa_global *global)
  497. {
  498. DBusMessageIter iter_dict;
  499. DBusMessage *reply = NULL;
  500. DBusMessageIter iter;
  501. struct wpa_dbus_dict_entry entry;
  502. char *driver = NULL;
  503. char *ifname = NULL;
  504. char *bridge_ifname = NULL;
  505. dbus_message_iter_init(message, &iter);
  506. if (!wpa_dbus_dict_open_read(&iter, &iter_dict))
  507. goto error;
  508. while (wpa_dbus_dict_has_dict_entry(&iter_dict)) {
  509. if (!wpa_dbus_dict_get_entry(&iter_dict, &entry))
  510. goto error;
  511. if (!strcmp(entry.key, "Driver") &&
  512. (entry.type == DBUS_TYPE_STRING)) {
  513. driver = os_strdup(entry.str_value);
  514. wpa_dbus_dict_entry_clear(&entry);
  515. if (driver == NULL)
  516. goto error;
  517. } else if (!strcmp(entry.key, "Ifname") &&
  518. (entry.type == DBUS_TYPE_STRING)) {
  519. ifname = os_strdup(entry.str_value);
  520. wpa_dbus_dict_entry_clear(&entry);
  521. if (ifname == NULL)
  522. goto error;
  523. } else if (!strcmp(entry.key, "BridgeIfname") &&
  524. (entry.type == DBUS_TYPE_STRING)) {
  525. bridge_ifname = os_strdup(entry.str_value);
  526. wpa_dbus_dict_entry_clear(&entry);
  527. if (bridge_ifname == NULL)
  528. goto error;
  529. } else {
  530. wpa_dbus_dict_entry_clear(&entry);
  531. goto error;
  532. }
  533. }
  534. if (ifname == NULL)
  535. goto error; /* Required Ifname argument missing */
  536. /*
  537. * Try to get the wpa_supplicant record for this iface, return
  538. * an error if we already control it.
  539. */
  540. if (wpa_supplicant_get_iface(global, ifname) != NULL) {
  541. reply = dbus_message_new_error(message,
  542. WPAS_DBUS_ERROR_IFACE_EXISTS,
  543. "wpa_supplicant already "
  544. "controls this interface.");
  545. } else {
  546. struct wpa_supplicant *wpa_s;
  547. struct wpa_interface iface;
  548. os_memset(&iface, 0, sizeof(iface));
  549. iface.driver = driver;
  550. iface.ifname = ifname;
  551. iface.bridge_ifname = bridge_ifname;
  552. /* Otherwise, have wpa_supplicant attach to it. */
  553. if ((wpa_s = wpa_supplicant_add_iface(global, &iface))) {
  554. const char *path = wpas_dbus_get_path(wpa_s);
  555. reply = dbus_message_new_method_return(message);
  556. dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH,
  557. &path, DBUS_TYPE_INVALID);
  558. } else {
  559. reply = wpas_dbus_error_unknown_error(
  560. message, "wpa_supplicant couldn't grab this "
  561. "interface.");
  562. }
  563. }
  564. out:
  565. os_free(driver);
  566. os_free(ifname);
  567. os_free(bridge_ifname);
  568. return reply;
  569. error:
  570. reply = wpas_dbus_error_invald_args(message, NULL);
  571. goto out;
  572. }
  573. /**
  574. * wpas_dbus_handler_remove_interface - Request deregistration of an interface
  575. * @message: Pointer to incoming dbus message
  576. * @global: wpa_supplicant global data structure
  577. * Returns: a dbus message containing a UINT32 indicating success (1) or
  578. * failure (0), or returns a dbus error message with more information
  579. *
  580. * Handler function for "removeInterface" method call. Handles requests
  581. * by dbus clients to deregister a network interface that wpa_supplicant
  582. * currently manages.
  583. */
  584. DBusMessage * wpas_dbus_handler_remove_interface(DBusMessage *message,
  585. struct wpa_global *global)
  586. {
  587. struct wpa_supplicant *wpa_s;
  588. char *path;
  589. DBusMessage *reply = NULL;
  590. dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path,
  591. DBUS_TYPE_INVALID);
  592. wpa_s = get_iface_by_dbus_path(global, path);
  593. if (wpa_s == NULL)
  594. reply = wpas_dbus_error_iface_unknown(message);
  595. else if (wpa_supplicant_remove_iface(global, wpa_s)) {
  596. reply = wpas_dbus_error_unknown_error(
  597. message, "wpa_supplicant couldn't remove this "
  598. "interface.");
  599. }
  600. return reply;
  601. }
  602. /**
  603. * wpas_dbus_handler_get_interface - Get the object path for an interface name
  604. * @message: Pointer to incoming dbus message
  605. * @global: %wpa_supplicant global data structure
  606. * Returns: The object path of the interface object,
  607. * or a dbus error message with more information
  608. *
  609. * Handler function for "getInterface" method call.
  610. */
  611. DBusMessage * wpas_dbus_handler_get_interface(DBusMessage *message,
  612. struct wpa_global *global)
  613. {
  614. DBusMessage *reply = NULL;
  615. const char *ifname;
  616. const char *path;
  617. struct wpa_supplicant *wpa_s;
  618. dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &ifname,
  619. DBUS_TYPE_INVALID);
  620. wpa_s = wpa_supplicant_get_iface(global, ifname);
  621. if (wpa_s == NULL)
  622. return wpas_dbus_error_iface_unknown(message);
  623. path = wpas_dbus_get_path(wpa_s);
  624. if (path == NULL) {
  625. wpa_printf(MSG_ERROR, "wpas_dbus_handler_get_interface[dbus]: "
  626. "interface has no dbus object path set");
  627. return wpas_dbus_error_unknown_error(message, "path not set");
  628. }
  629. reply = dbus_message_new_method_return(message);
  630. if (reply == NULL) {
  631. perror("wpas_dbus_handler_get_interface[dbus]: out of memory "
  632. "when creating reply");
  633. return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  634. NULL);
  635. }
  636. if (!dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path,
  637. DBUS_TYPE_INVALID)) {
  638. perror("wpas_dbus_handler_get_interface[dbus]: out of memory "
  639. "when appending argument to reply");
  640. dbus_message_unref(reply);
  641. return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  642. NULL);
  643. }
  644. return reply;
  645. }
  646. /**
  647. * wpas_dbus_getter_debug_level - Get debug level
  648. * @message: Pointer to incoming dbus message
  649. * @global: %wpa_supplicant global data structure
  650. * Returns: DBus message with value of debug level
  651. *
  652. * Getter for "DebugLevel" property.
  653. */
  654. DBusMessage * wpas_dbus_getter_debug_level(DBusMessage *message,
  655. struct wpa_global *global)
  656. {
  657. return wpas_dbus_simple_property_getter(message, DBUS_TYPE_BYTE,
  658. &wpa_debug_level);
  659. }
  660. /**
  661. * wpas_dbus_getter_debug_timestamp - Get debug timestamp
  662. * @message: Pointer to incoming dbus message
  663. * @global: %wpa_supplicant global data structure
  664. * Returns: DBus message with value of debug timestamp
  665. *
  666. * Getter for "DebugTimestamp" property.
  667. */
  668. DBusMessage * wpas_dbus_getter_debug_timestamp(DBusMessage *message,
  669. struct wpa_global *global)
  670. {
  671. return wpas_dbus_simple_property_getter(message, DBUS_TYPE_BOOLEAN,
  672. &wpa_debug_timestamp);
  673. }
  674. /**
  675. * wpas_dbus_getter_debug_show_keys - Get debug show keys
  676. * @message: Pointer to incoming dbus message
  677. * @global: %wpa_supplicant global data structure
  678. * Returns: DBus message with value of debug show_keys
  679. *
  680. * Getter for "DebugShowKeys" property.
  681. */
  682. DBusMessage * wpas_dbus_getter_debug_show_keys(DBusMessage *message,
  683. struct wpa_global *global)
  684. {
  685. return wpas_dbus_simple_property_getter(message, DBUS_TYPE_BOOLEAN,
  686. &wpa_debug_show_keys);
  687. }
  688. /**
  689. * wpas_dbus_setter_debug_level - Set debug level
  690. * @message: Pointer to incoming dbus message
  691. * @global: %wpa_supplicant global data structure
  692. * Returns: %NULL or DBus error message
  693. *
  694. * Setter for "DebugLevel" property.
  695. */
  696. DBusMessage * wpas_dbus_setter_debug_level(DBusMessage *message,
  697. struct wpa_global *global)
  698. {
  699. DBusMessage *reply = NULL;
  700. dbus_uint16_t val;
  701. reply = wpas_dbus_simple_property_setter(message, DBUS_TYPE_INT16,
  702. &val);
  703. if (reply)
  704. return reply;
  705. if (wpa_supplicant_set_debug_params(global, val, wpa_debug_timestamp,
  706. wpa_debug_show_keys)) {
  707. dbus_message_unref(reply);
  708. return wpas_dbus_error_invald_args(
  709. message, "Wrong debug level value");
  710. }
  711. return NULL;
  712. }
  713. /**
  714. * wpas_dbus_setter_debug_timestamp - Set debug timestamp
  715. * @message: Pointer to incoming dbus message
  716. * @global: %wpa_supplicant global data structure
  717. * Returns: %NULL or DBus error message
  718. *
  719. * Setter for "DebugTimestamp" property.
  720. */
  721. DBusMessage * wpas_dbus_setter_debug_timestamp(DBusMessage *message,
  722. struct wpa_global *global)
  723. {
  724. DBusMessage *reply = NULL;
  725. dbus_bool_t val;
  726. reply = wpas_dbus_simple_property_setter(message, DBUS_TYPE_BOOLEAN,
  727. &val);
  728. if (reply)
  729. return reply;
  730. wpa_supplicant_set_debug_params(global, wpa_debug_level, val ? 1 : 0,
  731. wpa_debug_show_keys);
  732. return NULL;
  733. }
  734. /**
  735. * wpas_dbus_setter_debug_show_keys - Set debug show keys
  736. * @message: Pointer to incoming dbus message
  737. * @global: %wpa_supplicant global data structure
  738. * Returns: %NULL or DBus error message
  739. *
  740. * Setter for "DebugShowKeys" property.
  741. */
  742. DBusMessage * wpas_dbus_setter_debug_show_keys(DBusMessage *message,
  743. struct wpa_global *global)
  744. {
  745. DBusMessage *reply = NULL;
  746. dbus_bool_t val;
  747. reply = wpas_dbus_simple_property_setter(message, DBUS_TYPE_BOOLEAN,
  748. &val);
  749. if (reply)
  750. return reply;
  751. wpa_supplicant_set_debug_params(global, wpa_debug_level,
  752. wpa_debug_timestamp,
  753. val ? 1 : 0);
  754. return NULL;
  755. }
  756. /**
  757. * wpas_dbus_getter_interfaces - Request registered interfaces list
  758. * @message: Pointer to incoming dbus message
  759. * @global: %wpa_supplicant global data structure
  760. * Returns: The object paths array containing registered interfaces
  761. * objects paths or DBus error on failure
  762. *
  763. * Getter for "Interfaces" property. Handles requests
  764. * by dbus clients to return list of registered interfaces objects
  765. * paths
  766. */
  767. DBusMessage * wpas_dbus_getter_interfaces(DBusMessage *message,
  768. struct wpa_global *global)
  769. {
  770. DBusMessage *reply = NULL;
  771. struct wpa_supplicant *wpa_s;
  772. const char **paths;
  773. unsigned int i = 0, num = 0;
  774. for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
  775. num++;
  776. paths = os_zalloc(num * sizeof(char*));
  777. if (!paths) {
  778. return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  779. NULL);
  780. }
  781. for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
  782. paths[i] = wpas_dbus_get_path(wpa_s);
  783. reply = wpas_dbus_simple_array_property_getter(message,
  784. DBUS_TYPE_OBJECT_PATH,
  785. paths, num);
  786. os_free(paths);
  787. return reply;
  788. }
  789. /**
  790. * wpas_dbus_getter_eap_methods - Request supported EAP methods list
  791. * @message: Pointer to incoming dbus message
  792. * @nothing: not used argument. may be NULL or anything else
  793. * Returns: The object paths array containing supported EAP methods
  794. * represented by strings or DBus error on failure
  795. *
  796. * Getter for "EapMethods" property. Handles requests
  797. * by dbus clients to return list of strings with supported EAP methods
  798. */
  799. DBusMessage * wpas_dbus_getter_eap_methods(DBusMessage *message, void *nothing)
  800. {
  801. DBusMessage *reply = NULL;
  802. char **eap_methods;
  803. size_t num_items = 0;
  804. eap_methods = eap_get_names_as_string_array(&num_items);
  805. if (!eap_methods) {
  806. return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  807. NULL);
  808. }
  809. reply = wpas_dbus_simple_array_property_getter(message,
  810. DBUS_TYPE_STRING,
  811. eap_methods, num_items);
  812. while (num_items)
  813. os_free(eap_methods[--num_items]);
  814. os_free(eap_methods);
  815. return reply;
  816. }
  817. static int wpas_dbus_get_scan_type(DBusMessage *message, DBusMessageIter *var,
  818. char **type, DBusMessage **reply)
  819. {
  820. if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_STRING) {
  821. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
  822. "Type must be a string");
  823. *reply = wpas_dbus_error_invald_args(
  824. message, "Wrong Type value type. String required");
  825. return -1;
  826. }
  827. dbus_message_iter_get_basic(var, type);
  828. return 0;
  829. }
  830. static int wpas_dbus_get_scan_ssids(DBusMessage *message, DBusMessageIter *var,
  831. struct wpa_driver_scan_params *params,
  832. DBusMessage **reply)
  833. {
  834. struct wpa_driver_scan_ssid *ssids = params->ssids;
  835. size_t ssids_num = 0;
  836. u8 *ssid;
  837. DBusMessageIter array_iter, sub_array_iter;
  838. char *val;
  839. int len;
  840. if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_ARRAY) {
  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_invald_args(
  844. message, "Wrong SSIDs value type. Array of arrays of "
  845. "bytes required");
  846. return -1;
  847. }
  848. dbus_message_iter_recurse(var, &array_iter);
  849. if (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_ARRAY ||
  850. dbus_message_iter_get_element_type(&array_iter) != DBUS_TYPE_BYTE)
  851. {
  852. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: ssids "
  853. "must be an array of arrays of bytes");
  854. *reply = wpas_dbus_error_invald_args(
  855. message, "Wrong SSIDs value type. Array of arrays of "
  856. "bytes required");
  857. return -1;
  858. }
  859. while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_ARRAY)
  860. {
  861. if (ssids_num >= WPAS_MAX_SCAN_SSIDS) {
  862. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
  863. "Too many ssids specified on scan dbus "
  864. "call");
  865. *reply = wpas_dbus_error_invald_args(
  866. message, "Too many ssids specified. Specify "
  867. "at most four");
  868. return -1;
  869. }
  870. dbus_message_iter_recurse(&array_iter, &sub_array_iter);
  871. dbus_message_iter_get_fixed_array(&sub_array_iter, &val, &len);
  872. if (len == 0) {
  873. dbus_message_iter_next(&array_iter);
  874. continue;
  875. }
  876. ssid = os_malloc(len);
  877. if (ssid == NULL) {
  878. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
  879. "out of memory. Cannot allocate memory for "
  880. "SSID");
  881. *reply = dbus_message_new_error(
  882. message, DBUS_ERROR_NO_MEMORY, NULL);
  883. return -1;
  884. }
  885. os_memcpy(ssid, val, len);
  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_invald_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_invald_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_invald_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_invald_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_invald_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_invald_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_invald_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_invald_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_invald_args(
  1103. message, "You can specify only Channels in "
  1104. "passive scan");
  1105. goto out;
  1106. } else if (params.freqs && params.freqs[0]) {
  1107. /* wildcard ssid */
  1108. params.num_ssids++;
  1109. wpa_supplicant_trigger_scan(wpa_s, &params);
  1110. } else {
  1111. wpa_s->scan_req = 2;
  1112. wpa_supplicant_req_scan(wpa_s, 0, 0);
  1113. }
  1114. } else if (!os_strcmp(type, "active")) {
  1115. wpa_supplicant_trigger_scan(wpa_s, &params);
  1116. } else {
  1117. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
  1118. "Unknown scan type: %s", type);
  1119. reply = wpas_dbus_error_invald_args(message,
  1120. "Wrong scan type");
  1121. goto out;
  1122. }
  1123. out:
  1124. for (i = 0; i < WPAS_MAX_SCAN_SSIDS; i++)
  1125. os_free((u8 *) params.ssids[i].ssid);
  1126. os_free((u8 *) params.extra_ies);
  1127. os_free(params.freqs);
  1128. return reply;
  1129. }
  1130. /*
  1131. * wpas_dbus_handler_disconnect - Terminate the current connection
  1132. * @message: Pointer to incoming dbus message
  1133. * @wpa_s: wpa_supplicant structure for a network interface
  1134. * Returns: NotConnected DBus error message if already not connected
  1135. * or NULL otherwise.
  1136. *
  1137. * Handler function for "Disconnect" method call of network interface.
  1138. */
  1139. DBusMessage * wpas_dbus_handler_disconnect(DBusMessage *message,
  1140. struct wpa_supplicant *wpa_s)
  1141. {
  1142. if (wpa_s->current_ssid != NULL) {
  1143. wpa_s->disconnected = 1;
  1144. wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1145. return NULL;
  1146. }
  1147. return dbus_message_new_error(message, WPAS_DBUS_ERROR_NOT_CONNECTED,
  1148. "This interface is not connected");
  1149. }
  1150. /**
  1151. * wpas_dbus_new_iface_add_network - Add a new configured network
  1152. * @message: Pointer to incoming dbus message
  1153. * @wpa_s: wpa_supplicant structure for a network interface
  1154. * Returns: A dbus message containing the object path of the new network
  1155. *
  1156. * Handler function for "AddNetwork" method call of a network interface.
  1157. */
  1158. DBusMessage * wpas_dbus_handler_add_network(DBusMessage *message,
  1159. struct wpa_supplicant *wpa_s)
  1160. {
  1161. DBusMessage *reply = NULL;
  1162. DBusMessageIter iter;
  1163. struct wpa_ssid *ssid = NULL;
  1164. char *path = NULL;
  1165. path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
  1166. if (path == NULL) {
  1167. perror("wpas_dbus_handler_add_network[dbus]: out of "
  1168. "memory.");
  1169. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1170. NULL);
  1171. goto err;
  1172. }
  1173. dbus_message_iter_init(message, &iter);
  1174. ssid = wpa_config_add_network(wpa_s->conf);
  1175. if (ssid == NULL) {
  1176. wpa_printf(MSG_ERROR, "wpas_dbus_handler_add_network[dbus]: "
  1177. "can't add new interface.");
  1178. reply = wpas_dbus_error_unknown_error(
  1179. message,
  1180. "wpa_supplicant could not add "
  1181. "a network on this interface.");
  1182. goto err;
  1183. }
  1184. wpas_notify_network_added(wpa_s, ssid);
  1185. ssid->disabled = 1;
  1186. wpa_config_set_network_defaults(ssid);
  1187. reply = set_network_properties(message, ssid, &iter);
  1188. if (reply) {
  1189. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_add_network[dbus]:"
  1190. "control interface couldn't set network "
  1191. "properties");
  1192. goto err;
  1193. }
  1194. /* Construct the object path for this network. */
  1195. os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
  1196. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
  1197. wpas_dbus_get_path(wpa_s),
  1198. ssid->id);
  1199. reply = dbus_message_new_method_return(message);
  1200. if (reply == NULL) {
  1201. perror("wpas_dbus_handler_add_network[dbus]: out of memory "
  1202. "when creating reply");
  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. perror("wpas_dbus_handler_add_network[dbus]: out of memory "
  1210. "when appending argument to reply");
  1211. dbus_message_unref(reply);
  1212. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1213. NULL);
  1214. goto err;
  1215. }
  1216. os_free(path);
  1217. return reply;
  1218. err:
  1219. if (ssid) {
  1220. wpas_notify_network_removed(wpa_s, ssid);
  1221. wpa_config_remove_network(wpa_s->conf, ssid->id);
  1222. }
  1223. os_free(path);
  1224. return reply;
  1225. }
  1226. /**
  1227. * wpas_dbus_handler_remove_network - Remove a configured network
  1228. * @message: Pointer to incoming dbus message
  1229. * @wpa_s: wpa_supplicant structure for a network interface
  1230. * Returns: NULL on success or dbus error on failure
  1231. *
  1232. * Handler function for "RemoveNetwork" method call of a network interface.
  1233. */
  1234. DBusMessage * wpas_dbus_handler_remove_network(DBusMessage *message,
  1235. struct wpa_supplicant *wpa_s)
  1236. {
  1237. DBusMessage *reply = NULL;
  1238. const char *op;
  1239. char *iface = NULL, *net_id = NULL;
  1240. int id;
  1241. struct wpa_ssid *ssid;
  1242. dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &op,
  1243. DBUS_TYPE_INVALID);
  1244. /* Extract the network ID and ensure the network */
  1245. /* is actually a child of this interface */
  1246. iface = wpas_dbus_new_decompose_object_path(op, &net_id, NULL);
  1247. if (iface == NULL || strcmp(iface, wpas_dbus_get_path(wpa_s)) != 0) {
  1248. reply = wpas_dbus_error_invald_args(message, op);
  1249. goto out;
  1250. }
  1251. id = strtoul(net_id, NULL, 10);
  1252. if (errno == EINVAL) {
  1253. reply = wpas_dbus_error_invald_args(message, op);
  1254. goto out;
  1255. }
  1256. ssid = wpa_config_get_network(wpa_s->conf, id);
  1257. if (ssid == NULL) {
  1258. reply = wpas_dbus_error_network_unknown(message);
  1259. goto out;
  1260. }
  1261. wpas_notify_network_removed(wpa_s, ssid);
  1262. if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
  1263. wpa_printf(MSG_ERROR,
  1264. "wpas_dbus_handler_remove_network[dbus]: "
  1265. "error occurred when removing network %d", id);
  1266. reply = wpas_dbus_error_unknown_error(
  1267. message, "error removing the specified network on "
  1268. "this interface.");
  1269. goto out;
  1270. }
  1271. if (ssid == wpa_s->current_ssid)
  1272. wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1273. out:
  1274. os_free(iface);
  1275. os_free(net_id);
  1276. return reply;
  1277. }
  1278. /**
  1279. * wpas_dbus_handler_select_network - Attempt association with a network
  1280. * @message: Pointer to incoming dbus message
  1281. * @wpa_s: wpa_supplicant structure for a network interface
  1282. * Returns: NULL on success or dbus error on failure
  1283. *
  1284. * Handler function for "SelectNetwork" method call of network interface.
  1285. */
  1286. DBusMessage * wpas_dbus_handler_select_network(DBusMessage *message,
  1287. struct wpa_supplicant *wpa_s)
  1288. {
  1289. DBusMessage *reply = NULL;
  1290. const char *op;
  1291. char *iface = NULL, *net_id = NULL;
  1292. int id;
  1293. struct wpa_ssid *ssid;
  1294. dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &op,
  1295. DBUS_TYPE_INVALID);
  1296. /* Extract the network ID and ensure the network */
  1297. /* is actually a child of this interface */
  1298. iface = wpas_dbus_new_decompose_object_path(op, &net_id, NULL);
  1299. if (iface == NULL || strcmp(iface, wpas_dbus_get_path(wpa_s)) != 0) {
  1300. reply = wpas_dbus_error_invald_args(message, op);
  1301. goto out;
  1302. }
  1303. id = strtoul(net_id, NULL, 10);
  1304. if (errno == EINVAL) {
  1305. reply = wpas_dbus_error_invald_args(message, op);
  1306. goto out;
  1307. }
  1308. ssid = wpa_config_get_network(wpa_s->conf, id);
  1309. if (ssid == NULL) {
  1310. reply = wpas_dbus_error_network_unknown(message);
  1311. goto out;
  1312. }
  1313. /* Finally, associate with the network */
  1314. wpa_supplicant_select_network(wpa_s, ssid);
  1315. out:
  1316. os_free(iface);
  1317. os_free(net_id);
  1318. return reply;
  1319. }
  1320. /**
  1321. * wpas_dbus_handler_add_blob - Store named binary blob (ie, for certificates)
  1322. * @message: Pointer to incoming dbus message
  1323. * @wpa_s: %wpa_supplicant data structure
  1324. * Returns: A dbus message containing an error on failure or NULL on success
  1325. *
  1326. * Asks wpa_supplicant to internally store a binary blobs.
  1327. */
  1328. DBusMessage * wpas_dbus_handler_add_blob(DBusMessage *message,
  1329. struct wpa_supplicant *wpa_s)
  1330. {
  1331. DBusMessage *reply = NULL;
  1332. DBusMessageIter iter, array_iter;
  1333. char *blob_name;
  1334. u8 *blob_data;
  1335. int blob_len;
  1336. struct wpa_config_blob *blob = NULL;
  1337. dbus_message_iter_init(message, &iter);
  1338. dbus_message_iter_get_basic(&iter, &blob_name);
  1339. if (wpa_config_get_blob(wpa_s->conf, blob_name)) {
  1340. return dbus_message_new_error(message,
  1341. WPAS_DBUS_ERROR_BLOB_EXISTS,
  1342. NULL);
  1343. }
  1344. dbus_message_iter_next(&iter);
  1345. dbus_message_iter_recurse(&iter, &array_iter);
  1346. dbus_message_iter_get_fixed_array(&array_iter, &blob_data, &blob_len);
  1347. blob = os_zalloc(sizeof(*blob));
  1348. if (!blob) {
  1349. perror("wpas_dbus_handler_add_blob[dbus] out of memory when "
  1350. "trying to allocate blob struct");
  1351. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1352. NULL);
  1353. goto err;
  1354. }
  1355. blob->data = os_malloc(blob_len);
  1356. if (!blob->data) {
  1357. perror("wpas_dbus_handler_add_blob[dbus] out of memory when "
  1358. "trying to allocate blob data");
  1359. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1360. NULL);
  1361. goto err;
  1362. }
  1363. os_memcpy(blob->data, blob_data, blob_len);
  1364. blob->len = blob_len;
  1365. blob->name = os_strdup(blob_name);
  1366. if (!blob->name) {
  1367. perror("wpas_dbus_handler_add_blob[dbus] out of memory when "
  1368. "trying to copy blob name");
  1369. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1370. NULL);
  1371. goto err;
  1372. }
  1373. wpa_config_set_blob(wpa_s->conf, blob);
  1374. wpas_notify_blob_added(wpa_s, blob->name);
  1375. return reply;
  1376. err:
  1377. if (blob) {
  1378. os_free(blob->name);
  1379. os_free(blob->data);
  1380. os_free(blob);
  1381. }
  1382. return reply;
  1383. }
  1384. /**
  1385. * wpas_dbus_handler_get_blob - Get named binary blob (ie, for certificates)
  1386. * @message: Pointer to incoming dbus message
  1387. * @wpa_s: %wpa_supplicant data structure
  1388. * Returns: A dbus message containing array of bytes (blob)
  1389. *
  1390. * Gets one wpa_supplicant's binary blobs.
  1391. */
  1392. DBusMessage * wpas_dbus_handler_get_blob(DBusMessage *message,
  1393. struct wpa_supplicant *wpa_s)
  1394. {
  1395. DBusMessage *reply = NULL;
  1396. DBusMessageIter iter, array_iter;
  1397. char *blob_name;
  1398. const struct wpa_config_blob *blob;
  1399. dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &blob_name,
  1400. DBUS_TYPE_INVALID);
  1401. blob = wpa_config_get_blob(wpa_s->conf, blob_name);
  1402. if (!blob) {
  1403. return dbus_message_new_error(message,
  1404. WPAS_DBUS_ERROR_BLOB_UNKNOWN,
  1405. "Blob id not set");
  1406. }
  1407. reply = dbus_message_new_method_return(message);
  1408. if (!reply) {
  1409. perror("wpas_dbus_handler_get_blob[dbus] out of memory when "
  1410. "trying to allocate return message");
  1411. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1412. NULL);
  1413. goto out;
  1414. }
  1415. dbus_message_iter_init_append(reply, &iter);
  1416. if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
  1417. DBUS_TYPE_BYTE_AS_STRING,
  1418. &array_iter)) {
  1419. dbus_message_unref(reply);
  1420. perror("wpas_dbus_handler_get_blob[dbus] out of memory when "
  1421. "trying to open array");
  1422. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1423. NULL);
  1424. goto out;
  1425. }
  1426. if (!dbus_message_iter_append_fixed_array(&array_iter, DBUS_TYPE_BYTE,
  1427. &(blob->data), blob->len)) {
  1428. dbus_message_unref(reply);
  1429. perror("wpas_dbus_handler_get_blob[dbus] out of memory when "
  1430. "trying to append data to array");
  1431. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1432. NULL);
  1433. goto out;
  1434. }
  1435. if (!dbus_message_iter_close_container(&iter, &array_iter)) {
  1436. dbus_message_unref(reply);
  1437. perror("wpas_dbus_handler_get_blob[dbus] out of memory when "
  1438. "trying to close array");
  1439. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1440. NULL);
  1441. goto out;
  1442. }
  1443. out:
  1444. return reply;
  1445. }
  1446. /**
  1447. * wpas_remove_handler_remove_blob - Remove named binary blob
  1448. * @message: Pointer to incoming dbus message
  1449. * @wpa_s: %wpa_supplicant data structure
  1450. * Returns: NULL on success or dbus error
  1451. *
  1452. * Asks wpa_supplicant to internally remove a binary blobs.
  1453. */
  1454. DBusMessage * wpas_dbus_handler_remove_blob(DBusMessage *message,
  1455. struct wpa_supplicant *wpa_s)
  1456. {
  1457. DBusMessage *reply = NULL;
  1458. char *blob_name;
  1459. dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &blob_name,
  1460. DBUS_TYPE_INVALID);
  1461. if (wpa_config_remove_blob(wpa_s->conf, blob_name)) {
  1462. return dbus_message_new_error(message,
  1463. WPAS_DBUS_ERROR_BLOB_UNKNOWN,
  1464. "Blob id not set");
  1465. }
  1466. wpas_notify_blob_removed(wpa_s, blob_name);
  1467. return reply;
  1468. }
  1469. /**
  1470. * wpas_dbus_getter_capabilities - Return interface capabilities
  1471. * @message: Pointer to incoming dbus message
  1472. * @wpa_s: wpa_supplicant structure for a network interface
  1473. * Returns: A dbus message containing a dict of strings
  1474. *
  1475. * Getter for "Capabilities" property of an interface.
  1476. */
  1477. DBusMessage * wpas_dbus_getter_capabilities(DBusMessage *message,
  1478. struct wpa_supplicant *wpa_s)
  1479. {
  1480. DBusMessage *reply = NULL;
  1481. struct wpa_driver_capa capa;
  1482. int res;
  1483. DBusMessageIter iter, iter_dict;
  1484. DBusMessageIter iter_dict_entry, iter_dict_val, iter_array,
  1485. variant_iter;
  1486. const char *scans[] = { "active", "passive", "ssid" };
  1487. const char *modes[] = { "infrastructure", "ad-hoc", "ap" };
  1488. int n = sizeof(modes) / sizeof(char *);
  1489. if (message == NULL)
  1490. reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
  1491. else
  1492. reply = dbus_message_new_method_return(message);
  1493. if (!reply)
  1494. goto nomem;
  1495. dbus_message_iter_init_append(reply, &iter);
  1496. if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
  1497. "a{sv}", &variant_iter))
  1498. goto nomem;
  1499. if (!wpa_dbus_dict_open_write(&variant_iter, &iter_dict))
  1500. goto nomem;
  1501. res = wpa_drv_get_capa(wpa_s, &capa);
  1502. /***** pairwise cipher */
  1503. if (res < 0) {
  1504. const char *args[] = {"ccmp", "tkip", "none"};
  1505. if (!wpa_dbus_dict_append_string_array(
  1506. &iter_dict, "Pairwise", args,
  1507. sizeof(args) / sizeof(char*)))
  1508. goto nomem;
  1509. } else {
  1510. if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Pairwise",
  1511. &iter_dict_entry,
  1512. &iter_dict_val,
  1513. &iter_array))
  1514. goto nomem;
  1515. if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) {
  1516. if (!wpa_dbus_dict_string_array_add_element(
  1517. &iter_array, "ccmp"))
  1518. goto nomem;
  1519. }
  1520. if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) {
  1521. if (!wpa_dbus_dict_string_array_add_element(
  1522. &iter_array, "tkip"))
  1523. goto nomem;
  1524. }
  1525. if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
  1526. if (!wpa_dbus_dict_string_array_add_element(
  1527. &iter_array, "none"))
  1528. goto nomem;
  1529. }
  1530. if (!wpa_dbus_dict_end_string_array(&iter_dict,
  1531. &iter_dict_entry,
  1532. &iter_dict_val,
  1533. &iter_array))
  1534. goto nomem;
  1535. }
  1536. /***** group cipher */
  1537. if (res < 0) {
  1538. const char *args[] = {
  1539. "ccmp", "tkip", "wep104", "wep40"
  1540. };
  1541. if (!wpa_dbus_dict_append_string_array(
  1542. &iter_dict, "Group", args,
  1543. sizeof(args) / sizeof(char*)))
  1544. goto nomem;
  1545. } else {
  1546. if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Group",
  1547. &iter_dict_entry,
  1548. &iter_dict_val,
  1549. &iter_array))
  1550. goto nomem;
  1551. if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) {
  1552. if (!wpa_dbus_dict_string_array_add_element(
  1553. &iter_array, "ccmp"))
  1554. goto nomem;
  1555. }
  1556. if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) {
  1557. if (!wpa_dbus_dict_string_array_add_element(
  1558. &iter_array, "tkip"))
  1559. goto nomem;
  1560. }
  1561. if (capa.enc & WPA_DRIVER_CAPA_ENC_WEP104) {
  1562. if (!wpa_dbus_dict_string_array_add_element(
  1563. &iter_array, "wep104"))
  1564. goto nomem;
  1565. }
  1566. if (capa.enc & WPA_DRIVER_CAPA_ENC_WEP40) {
  1567. if (!wpa_dbus_dict_string_array_add_element(
  1568. &iter_array, "wep40"))
  1569. goto nomem;
  1570. }
  1571. if (!wpa_dbus_dict_end_string_array(&iter_dict,
  1572. &iter_dict_entry,
  1573. &iter_dict_val,
  1574. &iter_array))
  1575. goto nomem;
  1576. }
  1577. /***** key management */
  1578. if (res < 0) {
  1579. const char *args[] = {
  1580. "wpa-psk", "wpa-eap", "ieee8021x", "wpa-none",
  1581. #ifdef CONFIG_WPS
  1582. "wps",
  1583. #endif /* CONFIG_WPS */
  1584. "none"
  1585. };
  1586. if (!wpa_dbus_dict_append_string_array(
  1587. &iter_dict, "KeyMgmt", args,
  1588. sizeof(args) / sizeof(char*)))
  1589. goto nomem;
  1590. } else {
  1591. if (!wpa_dbus_dict_begin_string_array(&iter_dict, "KeyMgmt",
  1592. &iter_dict_entry,
  1593. &iter_dict_val,
  1594. &iter_array))
  1595. goto nomem;
  1596. if (!wpa_dbus_dict_string_array_add_element(&iter_array,
  1597. "none"))
  1598. goto nomem;
  1599. if (!wpa_dbus_dict_string_array_add_element(&iter_array,
  1600. "ieee8021x"))
  1601. goto nomem;
  1602. if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
  1603. WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
  1604. if (!wpa_dbus_dict_string_array_add_element(
  1605. &iter_array, "wpa-eap"))
  1606. goto nomem;
  1607. }
  1608. if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
  1609. WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
  1610. if (!wpa_dbus_dict_string_array_add_element(
  1611. &iter_array, "wpa-psk"))
  1612. goto nomem;
  1613. }
  1614. if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
  1615. if (!wpa_dbus_dict_string_array_add_element(
  1616. &iter_array, "wpa-none"))
  1617. goto nomem;
  1618. }
  1619. #ifdef CONFIG_WPS
  1620. if (!wpa_dbus_dict_string_array_add_element(&iter_array,
  1621. "wps"))
  1622. goto nomem;
  1623. #endif /* CONFIG_WPS */
  1624. if (!wpa_dbus_dict_end_string_array(&iter_dict,
  1625. &iter_dict_entry,
  1626. &iter_dict_val,
  1627. &iter_array))
  1628. goto nomem;
  1629. }
  1630. /***** WPA protocol */
  1631. if (res < 0) {
  1632. const char *args[] = { "rsn", "wpa" };
  1633. if (!wpa_dbus_dict_append_string_array(
  1634. &iter_dict, "Protocol", args,
  1635. sizeof(args) / sizeof(char*)))
  1636. goto nomem;
  1637. } else {
  1638. if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Protocol",
  1639. &iter_dict_entry,
  1640. &iter_dict_val,
  1641. &iter_array))
  1642. goto nomem;
  1643. if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
  1644. WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
  1645. if (!wpa_dbus_dict_string_array_add_element(
  1646. &iter_array, "rsn"))
  1647. goto nomem;
  1648. }
  1649. if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
  1650. WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
  1651. if (!wpa_dbus_dict_string_array_add_element(
  1652. &iter_array, "wpa"))
  1653. goto nomem;
  1654. }
  1655. if (!wpa_dbus_dict_end_string_array(&iter_dict,
  1656. &iter_dict_entry,
  1657. &iter_dict_val,
  1658. &iter_array))
  1659. goto nomem;
  1660. }
  1661. /***** auth alg */
  1662. if (res < 0) {
  1663. const char *args[] = { "open", "shared", "leap" };
  1664. if (!wpa_dbus_dict_append_string_array(
  1665. &iter_dict, "AuthAlg", args,
  1666. sizeof(args) / sizeof(char*)))
  1667. goto nomem;
  1668. } else {
  1669. if (!wpa_dbus_dict_begin_string_array(&iter_dict, "AuthAlg",
  1670. &iter_dict_entry,
  1671. &iter_dict_val,
  1672. &iter_array))
  1673. goto nomem;
  1674. if (capa.auth & (WPA_DRIVER_AUTH_OPEN)) {
  1675. if (!wpa_dbus_dict_string_array_add_element(
  1676. &iter_array, "open"))
  1677. goto nomem;
  1678. }
  1679. if (capa.auth & (WPA_DRIVER_AUTH_SHARED)) {
  1680. if (!wpa_dbus_dict_string_array_add_element(
  1681. &iter_array, "shared"))
  1682. goto nomem;
  1683. }
  1684. if (capa.auth & (WPA_DRIVER_AUTH_LEAP)) {
  1685. if (!wpa_dbus_dict_string_array_add_element(
  1686. &iter_array, "leap"))
  1687. goto nomem;
  1688. }
  1689. if (!wpa_dbus_dict_end_string_array(&iter_dict,
  1690. &iter_dict_entry,
  1691. &iter_dict_val,
  1692. &iter_array))
  1693. goto nomem;
  1694. }
  1695. /***** Scan */
  1696. if (!wpa_dbus_dict_append_string_array(&iter_dict, "Scan", scans,
  1697. sizeof(scans) / sizeof(char *)))
  1698. goto nomem;
  1699. /***** Modes */
  1700. if (res < 0 || !(capa.flags & WPA_DRIVER_FLAGS_AP))
  1701. n--; /* exclude ap mode if it is not supported by the driver */
  1702. if (!wpa_dbus_dict_append_string_array(&iter_dict, "Modes", modes, n))
  1703. goto nomem;
  1704. if (!wpa_dbus_dict_close_write(&variant_iter, &iter_dict))
  1705. goto nomem;
  1706. if (!dbus_message_iter_close_container(&iter, &variant_iter))
  1707. goto nomem;
  1708. return reply;
  1709. nomem:
  1710. if (reply)
  1711. dbus_message_unref(reply);
  1712. return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY, NULL);
  1713. }
  1714. /**
  1715. * wpas_dbus_getter_state - Get interface state
  1716. * @message: Pointer to incoming dbus message
  1717. * @wpa_s: wpa_supplicant structure for a network interface
  1718. * Returns: A dbus message containing a STRING representing the current
  1719. * interface state
  1720. *
  1721. * Getter for "State" property.
  1722. */
  1723. DBusMessage * wpas_dbus_getter_state(DBusMessage *message,
  1724. struct wpa_supplicant *wpa_s)
  1725. {
  1726. DBusMessage *reply = NULL;
  1727. const char *str_state;
  1728. char *state_ls, *tmp;
  1729. str_state = wpa_supplicant_state_txt(wpa_s->wpa_state);
  1730. /* make state string lowercase to fit new DBus API convention
  1731. */
  1732. state_ls = tmp = os_strdup(str_state);
  1733. if (!tmp) {
  1734. return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1735. NULL);
  1736. }
  1737. while (*tmp) {
  1738. *tmp = tolower(*tmp);
  1739. tmp++;
  1740. }
  1741. reply = wpas_dbus_simple_property_getter(message, DBUS_TYPE_STRING,
  1742. &state_ls);
  1743. os_free(state_ls);
  1744. return reply;
  1745. }
  1746. /**
  1747. * wpas_dbus_new_iface_get_scanning - Get interface scanning state
  1748. * @message: Pointer to incoming dbus message
  1749. * @wpa_s: wpa_supplicant structure for a network interface
  1750. * Returns: A dbus message containing whether the interface is scanning
  1751. *
  1752. * Getter for "scanning" property.
  1753. */
  1754. DBusMessage * wpas_dbus_getter_scanning(DBusMessage *message,
  1755. struct wpa_supplicant *wpa_s)
  1756. {
  1757. dbus_bool_t scanning = wpa_s->scanning ? TRUE : FALSE;
  1758. return wpas_dbus_simple_property_getter(message, DBUS_TYPE_BOOLEAN,
  1759. &scanning);
  1760. }
  1761. /**
  1762. * wpas_dbus_getter_ap_scan - Control roaming mode
  1763. * @message: Pointer to incoming dbus message
  1764. * @wpa_s: wpa_supplicant structure for a network interface
  1765. * Returns: A message containong value of ap_scan variable
  1766. *
  1767. * Getter function for "ApScan" property.
  1768. */
  1769. DBusMessage * wpas_dbus_getter_ap_scan(DBusMessage *message,
  1770. struct wpa_supplicant *wpa_s)
  1771. {
  1772. dbus_uint32_t ap_scan = wpa_s->conf->ap_scan;
  1773. return wpas_dbus_simple_property_getter(message, DBUS_TYPE_UINT32,
  1774. &ap_scan);
  1775. }
  1776. /**
  1777. * wpas_dbus_setter_ap_scan - Control roaming mode
  1778. * @message: Pointer to incoming dbus message
  1779. * @wpa_s: wpa_supplicant structure for a network interface
  1780. * Returns: NULL
  1781. *
  1782. * Setter function for "ApScan" property.
  1783. */
  1784. DBusMessage * wpas_dbus_setter_ap_scan(DBusMessage *message,
  1785. struct wpa_supplicant *wpa_s)
  1786. {
  1787. DBusMessage *reply = NULL;
  1788. dbus_uint32_t ap_scan;
  1789. reply = wpas_dbus_simple_property_setter(message, DBUS_TYPE_UINT32,
  1790. &ap_scan);
  1791. if (reply)
  1792. return reply;
  1793. if (wpa_supplicant_set_ap_scan(wpa_s, ap_scan)) {
  1794. return wpas_dbus_error_invald_args(
  1795. message, "ap_scan must equal 0, 1 or 2");
  1796. }
  1797. return NULL;
  1798. }
  1799. /**
  1800. * wpas_dbus_getter_ifname - Get interface name
  1801. * @message: Pointer to incoming dbus message
  1802. * @wpa_s: wpa_supplicant structure for a network interface
  1803. * Returns: A dbus message containing a name of network interface
  1804. * associated with with wpa_s
  1805. *
  1806. * Getter for "Ifname" property.
  1807. */
  1808. DBusMessage * wpas_dbus_getter_ifname(DBusMessage *message,
  1809. struct wpa_supplicant *wpa_s)
  1810. {
  1811. const char *ifname = wpa_s->ifname;
  1812. return wpas_dbus_simple_property_getter(message, DBUS_TYPE_STRING,
  1813. &ifname);
  1814. }
  1815. /**
  1816. * wpas_dbus_getter_driver - Get interface name
  1817. * @message: Pointer to incoming dbus message
  1818. * @wpa_s: wpa_supplicant structure for a network interface
  1819. * Returns: A dbus message containing a name of network interface
  1820. * driver associated with with wpa_s
  1821. *
  1822. * Getter for "Driver" property.
  1823. */
  1824. DBusMessage * wpas_dbus_getter_driver(DBusMessage *message,
  1825. struct wpa_supplicant *wpa_s)
  1826. {
  1827. const char *driver;
  1828. if (wpa_s->driver == NULL || wpa_s->driver->name == NULL) {
  1829. wpa_printf(MSG_DEBUG, "wpas_dbus_getter_driver[dbus]: "
  1830. "wpa_s has no driver set");
  1831. return wpas_dbus_error_unknown_error(message, NULL);
  1832. }
  1833. driver = wpa_s->driver->name;
  1834. return wpas_dbus_simple_property_getter(message, DBUS_TYPE_STRING,
  1835. &driver);
  1836. }
  1837. /**
  1838. * wpas_dbus_getter_current_bss - Get current bss object path
  1839. * @message: Pointer to incoming dbus message
  1840. * @wpa_s: wpa_supplicant structure for a network interface
  1841. * Returns: A dbus message containing a DBus object path to
  1842. * current BSS
  1843. *
  1844. * Getter for "CurrentBSS" property.
  1845. */
  1846. DBusMessage * wpas_dbus_getter_current_bss(DBusMessage *message,
  1847. struct wpa_supplicant *wpa_s)
  1848. {
  1849. DBusMessage *reply = NULL;
  1850. const char *path = wpas_dbus_get_path(wpa_s);
  1851. char *bss_obj_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
  1852. struct wpa_bss *bss = NULL;
  1853. if (bss_obj_path == NULL) {
  1854. perror("wpas_dbus_getter_current_bss[dbus]: out of "
  1855. "memory to allocate result argument.");
  1856. return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1857. NULL);
  1858. }
  1859. /* TODO: store current BSS or BSS id in wpa_s */
  1860. if (!is_zero_ether_addr(wpa_s->bssid))
  1861. bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
  1862. if (bss)
  1863. os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1864. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  1865. path, bss->id);
  1866. else
  1867. os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "/");
  1868. reply = wpas_dbus_simple_property_getter(message,
  1869. DBUS_TYPE_OBJECT_PATH,
  1870. &bss_obj_path);
  1871. os_free(bss_obj_path);
  1872. return reply;
  1873. }
  1874. /**
  1875. * wpas_dbus_getter_current_network - Get current network object path
  1876. * @message: Pointer to incoming dbus message
  1877. * @wpa_s: wpa_supplicant structure for a network interface
  1878. * Returns: A dbus message containing a DBus object path to
  1879. * current network
  1880. *
  1881. * Getter for "CurrentNetwork" property.
  1882. */
  1883. DBusMessage * wpas_dbus_getter_current_network(DBusMessage *message,
  1884. struct wpa_supplicant *wpa_s)
  1885. {
  1886. DBusMessage *reply = NULL;
  1887. const char *path = wpas_dbus_get_path(wpa_s);
  1888. char *net_obj_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
  1889. if (net_obj_path == NULL) {
  1890. perror("wpas_dbus_getter_current_network[dbus]: out of "
  1891. "memory to allocate result argument.");
  1892. return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1893. NULL);
  1894. }
  1895. if (wpa_s->current_ssid)
  1896. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1897. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u", path,
  1898. wpa_s->current_ssid->id);
  1899. else
  1900. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "/");
  1901. reply = wpas_dbus_simple_property_getter(message,
  1902. DBUS_TYPE_OBJECT_PATH,
  1903. &net_obj_path);
  1904. os_free(net_obj_path);
  1905. return reply;
  1906. }
  1907. /**
  1908. * wpas_dbus_getter_bridge_ifname - Get interface name
  1909. * @message: Pointer to incoming dbus message
  1910. * @wpa_s: wpa_supplicant structure for a network interface
  1911. * Returns: A dbus message containing a name of bridge network
  1912. * interface associated with with wpa_s
  1913. *
  1914. * Getter for "BridgeIfname" property.
  1915. */
  1916. DBusMessage * wpas_dbus_getter_bridge_ifname(DBusMessage *message,
  1917. struct wpa_supplicant *wpa_s)
  1918. {
  1919. const char *bridge_ifname = NULL;
  1920. bridge_ifname = wpa_s->bridge_ifname;
  1921. if (bridge_ifname == NULL) {
  1922. wpa_printf(MSG_ERROR, "wpas_dbus_getter_bridge_ifname[dbus]: "
  1923. "wpa_s has no bridge interface name set");
  1924. return wpas_dbus_error_unknown_error(message, NULL);
  1925. }
  1926. return wpas_dbus_simple_property_getter(message, DBUS_TYPE_STRING,
  1927. &bridge_ifname);
  1928. }
  1929. /**
  1930. * wpas_dbus_getter_bsss - Get array of BSSs objects
  1931. * @message: Pointer to incoming dbus message
  1932. * @wpa_s: wpa_supplicant structure for a network interface
  1933. * Returns: a dbus message containing an array of all known BSS objects
  1934. * dbus paths
  1935. *
  1936. * Getter for "BSSs" property.
  1937. */
  1938. DBusMessage * wpas_dbus_getter_bsss(DBusMessage *message,
  1939. struct wpa_supplicant *wpa_s)
  1940. {
  1941. DBusMessage *reply = NULL;
  1942. struct wpa_bss *bss;
  1943. char **paths;
  1944. unsigned int i = 0;
  1945. paths = os_zalloc(wpa_s->num_bss * sizeof(char *));
  1946. if (!paths) {
  1947. return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1948. NULL);
  1949. }
  1950. /* Loop through scan results and append each result's object path */
  1951. dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
  1952. paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
  1953. if (paths[i] == NULL) {
  1954. perror("wpas_dbus_getter_bsss[dbus]: out of "
  1955. "memory.");
  1956. reply = dbus_message_new_error(message,
  1957. DBUS_ERROR_NO_MEMORY,
  1958. NULL);
  1959. goto out;
  1960. }
  1961. /* Construct the object path for this BSS. */
  1962. os_snprintf(paths[i++], WPAS_DBUS_OBJECT_PATH_MAX,
  1963. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  1964. wpas_dbus_get_path(wpa_s), bss->id);
  1965. }
  1966. reply = wpas_dbus_simple_array_property_getter(message,
  1967. DBUS_TYPE_OBJECT_PATH,
  1968. paths, wpa_s->num_bss);
  1969. out:
  1970. while(i)
  1971. os_free(paths[--i]);
  1972. os_free(paths);
  1973. return reply;
  1974. }
  1975. /**
  1976. * wpas_dbus_getter_networks - Get array of networks objects
  1977. * @message: Pointer to incoming dbus message
  1978. * @wpa_s: wpa_supplicant structure for a network interface
  1979. * Returns: a dbus message containing an array of all configured
  1980. * networks dbus object paths.
  1981. *
  1982. * Getter for "Networks" property.
  1983. */
  1984. DBusMessage * wpas_dbus_getter_networks(DBusMessage *message,
  1985. struct wpa_supplicant *wpa_s)
  1986. {
  1987. DBusMessage *reply = NULL;
  1988. struct wpa_ssid *ssid;
  1989. char **paths;
  1990. unsigned int i = 0, num = 0;
  1991. if (wpa_s->conf == NULL) {
  1992. wpa_printf(MSG_ERROR, "wpas_dbus_getter_networks[dbus]: "
  1993. "An error occurred getting networks list.");
  1994. return wpas_dbus_error_unknown_error(message, NULL);
  1995. }
  1996. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next)
  1997. num++;
  1998. paths = os_zalloc(num * sizeof(char *));
  1999. if (!paths) {
  2000. return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  2001. NULL);
  2002. }
  2003. /* Loop through configured networks and append object path of each */
  2004. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
  2005. paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
  2006. if (paths[i] == NULL) {
  2007. perror("wpas_dbus_getter_networks[dbus]: out of "
  2008. "memory.");
  2009. reply = dbus_message_new_error(message,
  2010. DBUS_ERROR_NO_MEMORY,
  2011. NULL);
  2012. goto out;
  2013. }
  2014. /* Construct the object path for this network. */
  2015. os_snprintf(paths[i++], WPAS_DBUS_OBJECT_PATH_MAX,
  2016. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
  2017. wpas_dbus_get_path(wpa_s), ssid->id);
  2018. }
  2019. reply = wpas_dbus_simple_array_property_getter(message,
  2020. DBUS_TYPE_OBJECT_PATH,
  2021. paths, num);
  2022. out:
  2023. while (i)
  2024. os_free(paths[--i]);
  2025. os_free(paths);
  2026. return reply;
  2027. }
  2028. /**
  2029. * wpas_dbus_getter_blobs - Get all blobs defined for this interface
  2030. * @message: Pointer to incoming dbus message
  2031. * @wpa_s: wpa_supplicant structure for a network interface
  2032. * Returns: a dbus message containing a dictionary of pairs (blob_name, blob)
  2033. *
  2034. * Getter for "Blobs" property.
  2035. */
  2036. DBusMessage * wpas_dbus_getter_blobs(DBusMessage *message,
  2037. struct wpa_supplicant *wpa_s)
  2038. {
  2039. DBusMessage *reply = NULL;
  2040. DBusMessageIter iter, variant_iter, dict_iter, entry_iter, array_iter;
  2041. struct wpa_config_blob *blob;
  2042. if (message == NULL)
  2043. reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
  2044. else
  2045. reply = dbus_message_new_method_return(message);
  2046. if (!reply) {
  2047. perror("wpas_dbus_getter_blobs[dbus] out of memory when "
  2048. "trying to initialize return message");
  2049. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  2050. NULL);
  2051. goto out;
  2052. }
  2053. dbus_message_iter_init_append(reply, &iter);
  2054. if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
  2055. "a{say}", &variant_iter)) {
  2056. dbus_message_unref(reply);
  2057. perror("wpas_dbus_getter_blobs[dbus] out of memory when "
  2058. "trying to open variant");
  2059. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  2060. NULL);
  2061. goto out;
  2062. }
  2063. if (!dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
  2064. "{say}", &dict_iter)) {
  2065. dbus_message_unref(reply);
  2066. perror("wpas_dbus_getter_blobs[dbus] out of memory when "
  2067. "trying to open dictionary");
  2068. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  2069. NULL);
  2070. goto out;
  2071. }
  2072. blob = wpa_s->conf->blobs;
  2073. while (blob) {
  2074. if (!dbus_message_iter_open_container(&dict_iter,
  2075. DBUS_TYPE_DICT_ENTRY,
  2076. NULL, &entry_iter)) {
  2077. dbus_message_unref(reply);
  2078. perror("wpas_dbus_getter_blobs[dbus] out of memory "
  2079. "when trying to open entry");
  2080. reply = dbus_message_new_error(message,
  2081. DBUS_ERROR_NO_MEMORY,
  2082. NULL);
  2083. goto out;
  2084. }
  2085. if (!dbus_message_iter_append_basic(&entry_iter,
  2086. DBUS_TYPE_STRING,
  2087. &(blob->name))) {
  2088. dbus_message_unref(reply);
  2089. perror("wpas_dbus_getter_blobs[dbus] out of memory "
  2090. "when trying to append blob name");
  2091. reply = dbus_message_new_error(message,
  2092. DBUS_ERROR_NO_MEMORY,
  2093. NULL);
  2094. goto out;
  2095. }
  2096. if (!dbus_message_iter_open_container(&entry_iter,
  2097. DBUS_TYPE_ARRAY,
  2098. DBUS_TYPE_BYTE_AS_STRING,
  2099. &array_iter)) {
  2100. dbus_message_unref(reply);
  2101. perror("wpas_dbus_getter_blobs[dbus] out of memory "
  2102. "when trying to open array");
  2103. reply = dbus_message_new_error(message,
  2104. DBUS_ERROR_NO_MEMORY,
  2105. NULL);
  2106. goto out;
  2107. }
  2108. if (!dbus_message_iter_append_fixed_array(&array_iter,
  2109. DBUS_TYPE_BYTE,
  2110. &(blob->data),
  2111. blob->len)) {
  2112. dbus_message_unref(reply);
  2113. perror("wpas_dbus_getter_blobs[dbus] out of memory "
  2114. "when trying to append blob data");
  2115. reply = dbus_message_new_error(message,
  2116. DBUS_ERROR_NO_MEMORY,
  2117. NULL);
  2118. goto out;
  2119. }
  2120. if (!dbus_message_iter_close_container(&entry_iter,
  2121. &array_iter)) {
  2122. dbus_message_unref(reply);
  2123. perror("wpas_dbus_getter_blobs[dbus] out of memory "
  2124. "when trying to close array");
  2125. reply = dbus_message_new_error(message,
  2126. DBUS_ERROR_NO_MEMORY,
  2127. NULL);
  2128. goto out;
  2129. }
  2130. if (!dbus_message_iter_close_container(&dict_iter,
  2131. &entry_iter)) {
  2132. dbus_message_unref(reply);
  2133. perror("wpas_dbus_getter_blobs[dbus] out of memory "
  2134. "when trying to close entry");
  2135. reply = dbus_message_new_error(message,
  2136. DBUS_ERROR_NO_MEMORY,
  2137. NULL);
  2138. goto out;
  2139. }
  2140. blob = blob->next;
  2141. }
  2142. if (!dbus_message_iter_close_container(&variant_iter, &dict_iter)) {
  2143. dbus_message_unref(reply);
  2144. perror("wpas_dbus_getter_blobs[dbus] out of memory when "
  2145. "trying to close dictionary");
  2146. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  2147. NULL);
  2148. goto out;
  2149. }
  2150. if (!dbus_message_iter_close_container(&iter, &variant_iter)) {
  2151. dbus_message_unref(reply);
  2152. perror("wpas_dbus_getter_blobs[dbus] out of memory when "
  2153. "trying to close variant");
  2154. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  2155. NULL);
  2156. goto out;
  2157. }
  2158. out:
  2159. return reply;
  2160. }
  2161. /**
  2162. * wpas_dbus_getter_bss_bssid - Return the BSSID of a BSS
  2163. * @message: Pointer to incoming dbus message
  2164. * @bss: a pair of interface describing structure and bss's id
  2165. * Returns: a dbus message containing the bssid for the requested bss
  2166. *
  2167. * Getter for "BSSID" property.
  2168. */
  2169. DBusMessage * wpas_dbus_getter_bss_bssid(DBusMessage *message,
  2170. struct bss_handler_args *bss)
  2171. {
  2172. struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
  2173. if (!res) {
  2174. wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_bssid[dbus]: no "
  2175. "bss with id %d found", bss->id);
  2176. return NULL;
  2177. }
  2178. return wpas_dbus_simple_array_property_getter(message, DBUS_TYPE_BYTE,
  2179. res->bssid, ETH_ALEN);
  2180. }
  2181. /**
  2182. * wpas_dbus_getter_bss_ssid - Return the SSID of a BSS
  2183. * @message: Pointer to incoming dbus message
  2184. * @bss: a pair of interface describing structure and bss's id
  2185. * Returns: a dbus message containing the ssid for the requested bss
  2186. *
  2187. * Getter for "SSID" property.
  2188. */
  2189. DBusMessage * wpas_dbus_getter_bss_ssid(DBusMessage *message,
  2190. struct bss_handler_args *bss)
  2191. {
  2192. struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
  2193. if (!res) {
  2194. wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_ssid[dbus]: no "
  2195. "bss with id %d found", bss->id);
  2196. return NULL;
  2197. }
  2198. return wpas_dbus_simple_array_property_getter(message, DBUS_TYPE_BYTE,
  2199. res->ssid,
  2200. res->ssid_len);
  2201. }
  2202. /**
  2203. * wpas_dbus_getter_bss_privacy - Return the privacy flag of a BSS
  2204. * @message: Pointer to incoming dbus message
  2205. * @bss: a pair of interface describing structure and bss's id
  2206. * Returns: a dbus message containing the privacy flag value of requested bss
  2207. *
  2208. * Getter for "Privacy" property.
  2209. */
  2210. DBusMessage * wpas_dbus_getter_bss_privacy(DBusMessage *message,
  2211. struct bss_handler_args *bss)
  2212. {
  2213. struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
  2214. dbus_bool_t privacy;
  2215. if (!res) {
  2216. wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_privacy[dbus]: no "
  2217. "bss with id %d found", bss->id);
  2218. return NULL;
  2219. }
  2220. privacy = res->caps && IEEE80211_CAP_PRIVACY ? TRUE : FALSE;
  2221. return wpas_dbus_simple_property_getter(message, DBUS_TYPE_BOOLEAN,
  2222. &privacy);
  2223. }
  2224. /**
  2225. * wpas_dbus_getter_bss_mode - Return the mode of a BSS
  2226. * @message: Pointer to incoming dbus message
  2227. * @bss: a pair of interface describing structure and bss's id
  2228. * Returns: a dbus message containing the mode of requested bss
  2229. *
  2230. * Getter for "Mode" property.
  2231. */
  2232. DBusMessage * wpas_dbus_getter_bss_mode(DBusMessage *message,
  2233. struct bss_handler_args *bss)
  2234. {
  2235. struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
  2236. const char *mode;
  2237. if (!res) {
  2238. wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_mode[dbus]: no "
  2239. "bss with id %d found", bss->id);
  2240. return NULL;
  2241. }
  2242. if (res->caps & IEEE80211_CAP_IBSS)
  2243. mode = "ad-hoc";
  2244. else
  2245. mode = "infrastructure";
  2246. return wpas_dbus_simple_property_getter(message, DBUS_TYPE_STRING,
  2247. &mode);
  2248. }
  2249. /**
  2250. * wpas_dbus_getter_bss_level - Return the signal strength of a BSS
  2251. * @message: Pointer to incoming dbus message
  2252. * @bss: a pair of interface describing structure and bss's id
  2253. * Returns: a dbus message containing the signal strength of requested bss
  2254. *
  2255. * Getter for "Level" property.
  2256. */
  2257. DBusMessage * wpas_dbus_getter_bss_signal(DBusMessage *message,
  2258. struct bss_handler_args *bss)
  2259. {
  2260. struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
  2261. if (!res) {
  2262. wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_signal[dbus]: no "
  2263. "bss with id %d found", bss->id);
  2264. return NULL;
  2265. }
  2266. return wpas_dbus_simple_property_getter(message, DBUS_TYPE_INT16,
  2267. &res->level);
  2268. }
  2269. /**
  2270. * wpas_dbus_getter_bss_frequency - Return the frequency of a BSS
  2271. * @message: Pointer to incoming dbus message
  2272. * @bss: a pair of interface describing structure and bss's id
  2273. * Returns: a dbus message containing the frequency of requested bss
  2274. *
  2275. * Getter for "Frequency" property.
  2276. */
  2277. DBusMessage * wpas_dbus_getter_bss_frequency(DBusMessage *message,
  2278. struct bss_handler_args *bss)
  2279. {
  2280. struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
  2281. if (!res) {
  2282. wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_frequency[dbus]: "
  2283. "no bss with id %d found", bss->id);
  2284. return NULL;
  2285. }
  2286. return wpas_dbus_simple_property_getter(message, DBUS_TYPE_UINT16,
  2287. &res->freq);
  2288. }
  2289. /**
  2290. * wpas_dbus_getter_bss_max_rate - Return the maximal rate of a BSS
  2291. * @message: Pointer to incoming dbus message
  2292. * @bss: a pair of interface describing structure and bss's id
  2293. * Returns: a dbus message containing the maximal data rate of requested bss
  2294. *
  2295. * Getter for "MaxRate" property.
  2296. */
  2297. DBusMessage * wpas_dbus_getter_bss_max_rate(DBusMessage *message,
  2298. struct bss_handler_args *bss)
  2299. {
  2300. struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
  2301. int max_rate;
  2302. if (!res) {
  2303. wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_max_rate[dbus]: "
  2304. "no bss with id %d found", bss->id);
  2305. return NULL;
  2306. }
  2307. max_rate = wpa_bss_get_max_rate(res);
  2308. return wpas_dbus_simple_property_getter(message, DBUS_TYPE_UINT16,
  2309. &max_rate);
  2310. }
  2311. /**
  2312. * wpas_dbus_getter_bss_wpaie - Return the WPA IE of a BSS
  2313. * @message: Pointer to incoming dbus message
  2314. * @bss: a pair of interface describing structure and bss's id
  2315. * Returns: a dbus message containing the WPA information elements
  2316. * of requested bss
  2317. *
  2318. * Getter for "WPAIE" property.
  2319. */
  2320. DBusMessage * wpas_dbus_getter_bss_wpaie(DBusMessage *message,
  2321. struct bss_handler_args *bss)
  2322. {
  2323. struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
  2324. const u8 *ie;
  2325. if (!res) {
  2326. wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_wpaie[dbus]: no "
  2327. "bss with id %d found", bss->id);
  2328. return NULL;
  2329. }
  2330. ie = wpa_bss_get_vendor_ie(res, WPA_IE_VENDOR_TYPE);
  2331. if (!ie)
  2332. return NULL;
  2333. return wpas_dbus_simple_array_property_getter(message, DBUS_TYPE_BYTE,
  2334. ie, ie[1] + 2);
  2335. }
  2336. /**
  2337. * wpas_dbus_getter_bss_rsnie - Return the RSN IE of a BSS
  2338. * @message: Pointer to incoming dbus message
  2339. * @bss: a pair of interface describing structure and bss's id
  2340. * Returns: a dbus message containing the RSN information elements
  2341. * of requested bss
  2342. *
  2343. * Getter for "RSNIE" property.
  2344. */
  2345. DBusMessage * wpas_dbus_getter_bss_rsnie(DBusMessage *message,
  2346. struct bss_handler_args *bss)
  2347. {
  2348. struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
  2349. const u8 *ie;
  2350. if (!res) {
  2351. wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_rsnie[dbus]: no "
  2352. "bss with id %d found", bss->id);
  2353. return NULL;
  2354. }
  2355. ie = wpa_bss_get_ie(res, WLAN_EID_RSN);
  2356. if (!ie)
  2357. return NULL;
  2358. return wpas_dbus_simple_array_property_getter(message, DBUS_TYPE_BYTE,
  2359. ie, ie[1] + 2);
  2360. }
  2361. /**
  2362. * wpas_dbus_getter_bss_wpsie - Return the WPS IE of a BSS
  2363. * @message: Pointer to incoming dbus message
  2364. * @bss: a pair of interface describing structure and bss's id
  2365. * Returns: a dbus message containing the WPS information elements
  2366. * of requested bss
  2367. *
  2368. * Getter for "WPSIE" property.
  2369. */
  2370. DBusMessage * wpas_dbus_getter_bss_wpsie(DBusMessage *message,
  2371. struct bss_handler_args *bss)
  2372. {
  2373. struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
  2374. const u8 *ie;
  2375. if (!res) {
  2376. wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_wpsie[dbus]: no "
  2377. "bss with id %d found", bss->id);
  2378. return NULL;
  2379. }
  2380. ie = wpa_bss_get_vendor_ie(res, WPS_IE_VENDOR_TYPE);
  2381. if (!ie)
  2382. return NULL;
  2383. return wpas_dbus_simple_array_property_getter(message, DBUS_TYPE_BYTE,
  2384. ie, ie[1] + 2);
  2385. }
  2386. /**
  2387. * wpas_dbus_getter_enabled - Check whether network is enabled or disabled
  2388. * @message: Pointer to incoming dbus message
  2389. * @wpas_dbus_setter_enabled: wpa_supplicant structure for a network interface
  2390. * and wpa_ssid structure for a configured network
  2391. * Returns: DBus message with boolean indicating state of configured network
  2392. * or DBus error on failure
  2393. *
  2394. * Getter for "enabled" property of a configured network.
  2395. */
  2396. DBusMessage * wpas_dbus_getter_enabled(DBusMessage *message,
  2397. struct network_handler_args *net)
  2398. {
  2399. dbus_bool_t enabled = net->ssid->disabled ? FALSE : TRUE;
  2400. return wpas_dbus_simple_property_getter(message, DBUS_TYPE_BOOLEAN,
  2401. &enabled);
  2402. }
  2403. /**
  2404. * wpas_dbus_setter_enabled - Mark a configured network as enabled or disabled
  2405. * @message: Pointer to incoming dbus message
  2406. * @wpas_dbus_setter_enabled: wpa_supplicant structure for a network interface
  2407. * and wpa_ssid structure for a configured network
  2408. * Returns: NULL indicating success or DBus error on failure
  2409. *
  2410. * Setter for "Enabled" property of a configured network.
  2411. */
  2412. DBusMessage * wpas_dbus_setter_enabled(DBusMessage *message,
  2413. struct network_handler_args *net)
  2414. {
  2415. DBusMessage *reply = NULL;
  2416. struct wpa_supplicant *wpa_s;
  2417. struct wpa_ssid *ssid;
  2418. dbus_bool_t enable;
  2419. reply = wpas_dbus_simple_property_setter(message, DBUS_TYPE_BOOLEAN,
  2420. &enable);
  2421. if (reply)
  2422. return reply;
  2423. wpa_s = net->wpa_s;
  2424. ssid = net->ssid;
  2425. if (enable)
  2426. wpa_supplicant_enable_network(wpa_s, ssid);
  2427. else
  2428. wpa_supplicant_disable_network(wpa_s, ssid);
  2429. return NULL;
  2430. }
  2431. /**
  2432. * wpas_dbus_getter_network_properties - Get options for a configured network
  2433. * @message: Pointer to incoming dbus message
  2434. * @net: wpa_supplicant structure for a network interface and
  2435. * wpa_ssid structure for a configured network
  2436. * Returns: DBus message with network properties or DBus error on failure
  2437. *
  2438. * Getter for "Properties" property of a configured network.
  2439. */
  2440. DBusMessage * wpas_dbus_getter_network_properties(
  2441. DBusMessage *message, struct network_handler_args *net)
  2442. {
  2443. DBusMessage *reply = NULL;
  2444. DBusMessageIter iter, variant_iter, dict_iter;
  2445. char **iterator;
  2446. char **props = wpa_config_get_all(net->ssid, 0);
  2447. if (!props) {
  2448. perror("wpas_dbus_getter_network_properties[dbus] couldn't "
  2449. "read network properties. out of memory.");
  2450. return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  2451. NULL);
  2452. }
  2453. if (message == NULL)
  2454. reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
  2455. else
  2456. reply = dbus_message_new_method_return(message);
  2457. if (!reply) {
  2458. perror("wpas_dbus_getter_network_properties[dbus] out of "
  2459. "memory when trying to initialize return message");
  2460. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  2461. NULL);
  2462. goto out;
  2463. }
  2464. dbus_message_iter_init_append(reply, &iter);
  2465. if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
  2466. "a{sv}", &variant_iter)) {
  2467. perror("wpas_dbus_getter_network_properties[dbus] out of "
  2468. "memory when trying to open variant container");
  2469. dbus_message_unref(reply);
  2470. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  2471. NULL);
  2472. goto out;
  2473. }
  2474. if (!wpa_dbus_dict_open_write(&variant_iter, &dict_iter)) {
  2475. perror("wpas_dbus_getter_network_properties[dbus] out of "
  2476. "memory when trying to open dict");
  2477. dbus_message_unref(reply);
  2478. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  2479. NULL);
  2480. goto out;
  2481. }
  2482. iterator = props;
  2483. while (*iterator) {
  2484. if (!wpa_dbus_dict_append_string(&dict_iter, *iterator,
  2485. *(iterator + 1))) {
  2486. perror("wpas_dbus_getter_network_properties[dbus] out "
  2487. "of memory when trying to add entry");
  2488. dbus_message_unref(reply);
  2489. reply = dbus_message_new_error(message,
  2490. DBUS_ERROR_NO_MEMORY,
  2491. NULL);
  2492. goto out;
  2493. }
  2494. iterator += 2;
  2495. }
  2496. if (!wpa_dbus_dict_close_write(&variant_iter, &dict_iter)) {
  2497. perror("wpas_dbus_getter_network_properties[dbus] out of "
  2498. "memory when trying to close dictionary");
  2499. dbus_message_unref(reply);
  2500. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  2501. NULL);
  2502. goto out;
  2503. }
  2504. if (!dbus_message_iter_close_container(&iter, &variant_iter)) {
  2505. perror("wpas_dbus_getter_network_properties[dbus] out of "
  2506. "memory when trying to close variant container");
  2507. dbus_message_unref(reply);
  2508. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  2509. NULL);
  2510. goto out;
  2511. }
  2512. out:
  2513. iterator = props;
  2514. while (*iterator) {
  2515. os_free(*iterator);
  2516. iterator++;
  2517. }
  2518. os_free(props);
  2519. return reply;
  2520. }
  2521. /**
  2522. * wpas_dbus_setter_network_properties - Set options for a configured network
  2523. * @message: Pointer to incoming dbus message
  2524. * @net: wpa_supplicant structure for a network interface and
  2525. * wpa_ssid structure for a configured network
  2526. * Returns: NULL indicating success or DBus error on failure
  2527. *
  2528. * Setter for "Properties" property of a configured network.
  2529. */
  2530. DBusMessage * wpas_dbus_setter_network_properties(
  2531. DBusMessage *message, struct network_handler_args *net)
  2532. {
  2533. struct wpa_ssid *ssid = net->ssid;
  2534. DBusMessage *reply = NULL;
  2535. DBusMessageIter iter, variant_iter;
  2536. dbus_message_iter_init(message, &iter);
  2537. dbus_message_iter_next(&iter);
  2538. dbus_message_iter_next(&iter);
  2539. dbus_message_iter_recurse(&iter, &variant_iter);
  2540. reply = set_network_properties(message, ssid, &variant_iter);
  2541. if (reply)
  2542. wpa_printf(MSG_DEBUG, "dbus control interface couldn't set "
  2543. "network properties");
  2544. return reply;
  2545. }