dbus_new_handlers.c 81 KB

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