dbus_new_handlers.c 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976
  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. dbus_message_unref(reply);
  707. return wpas_dbus_error_invalid_args(
  708. message, "Wrong debug level value");
  709. }
  710. return NULL;
  711. }
  712. /**
  713. * wpas_dbus_setter_debug_timestamp - Set debug timestamp
  714. * @message: Pointer to incoming dbus message
  715. * @global: %wpa_supplicant global data structure
  716. * Returns: %NULL or DBus error message
  717. *
  718. * Setter for "DebugTimestamp" property.
  719. */
  720. DBusMessage * wpas_dbus_setter_debug_timestamp(DBusMessage *message,
  721. struct wpa_global *global)
  722. {
  723. DBusMessage *reply;
  724. dbus_bool_t val;
  725. reply = wpas_dbus_simple_property_setter(message, DBUS_TYPE_BOOLEAN,
  726. &val);
  727. if (reply)
  728. return reply;
  729. wpa_supplicant_set_debug_params(global, wpa_debug_level, val ? 1 : 0,
  730. wpa_debug_show_keys);
  731. return NULL;
  732. }
  733. /**
  734. * wpas_dbus_setter_debug_show_keys - Set debug show keys
  735. * @message: Pointer to incoming dbus message
  736. * @global: %wpa_supplicant global data structure
  737. * Returns: %NULL or DBus error message
  738. *
  739. * Setter for "DebugShowKeys" property.
  740. */
  741. DBusMessage * wpas_dbus_setter_debug_show_keys(DBusMessage *message,
  742. struct wpa_global *global)
  743. {
  744. DBusMessage *reply;
  745. dbus_bool_t val;
  746. reply = wpas_dbus_simple_property_setter(message, DBUS_TYPE_BOOLEAN,
  747. &val);
  748. if (reply)
  749. return reply;
  750. wpa_supplicant_set_debug_params(global, wpa_debug_level,
  751. wpa_debug_timestamp,
  752. val ? 1 : 0);
  753. return NULL;
  754. }
  755. /**
  756. * wpas_dbus_getter_interfaces - Request registered interfaces list
  757. * @message: Pointer to incoming dbus message
  758. * @global: %wpa_supplicant global data structure
  759. * Returns: The object paths array containing registered interfaces
  760. * objects paths or DBus error on failure
  761. *
  762. * Getter for "Interfaces" property. Handles requests
  763. * by dbus clients to return list of registered interfaces objects
  764. * paths
  765. */
  766. DBusMessage * wpas_dbus_getter_interfaces(DBusMessage *message,
  767. struct wpa_global *global)
  768. {
  769. DBusMessage *reply = NULL;
  770. struct wpa_supplicant *wpa_s;
  771. const char **paths;
  772. unsigned int i = 0, num = 0;
  773. for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
  774. num++;
  775. paths = os_zalloc(num * sizeof(char*));
  776. if (!paths) {
  777. return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  778. NULL);
  779. }
  780. for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
  781. paths[i] = wpa_s->dbus_new_path;
  782. reply = wpas_dbus_simple_array_property_getter(message,
  783. DBUS_TYPE_OBJECT_PATH,
  784. paths, num);
  785. os_free(paths);
  786. return reply;
  787. }
  788. /**
  789. * wpas_dbus_getter_eap_methods - Request supported EAP methods list
  790. * @message: Pointer to incoming dbus message
  791. * @nothing: not used argument. may be NULL or anything else
  792. * Returns: The object paths array containing supported EAP methods
  793. * represented by strings or DBus error on failure
  794. *
  795. * Getter for "EapMethods" property. Handles requests
  796. * by dbus clients to return list of strings with supported EAP methods
  797. */
  798. DBusMessage * wpas_dbus_getter_eap_methods(DBusMessage *message, void *nothing)
  799. {
  800. DBusMessage *reply = NULL;
  801. char **eap_methods;
  802. size_t num_items = 0;
  803. eap_methods = eap_get_names_as_string_array(&num_items);
  804. if (!eap_methods) {
  805. return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  806. NULL);
  807. }
  808. reply = wpas_dbus_simple_array_property_getter(message,
  809. DBUS_TYPE_STRING,
  810. eap_methods, num_items);
  811. while (num_items)
  812. os_free(eap_methods[--num_items]);
  813. os_free(eap_methods);
  814. return reply;
  815. }
  816. static int wpas_dbus_get_scan_type(DBusMessage *message, DBusMessageIter *var,
  817. char **type, DBusMessage **reply)
  818. {
  819. if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_STRING) {
  820. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
  821. "Type must be a string");
  822. *reply = wpas_dbus_error_invalid_args(
  823. message, "Wrong Type value type. String required");
  824. return -1;
  825. }
  826. dbus_message_iter_get_basic(var, type);
  827. return 0;
  828. }
  829. static int wpas_dbus_get_scan_ssids(DBusMessage *message, DBusMessageIter *var,
  830. struct wpa_driver_scan_params *params,
  831. DBusMessage **reply)
  832. {
  833. struct wpa_driver_scan_ssid *ssids = params->ssids;
  834. size_t ssids_num = 0;
  835. u8 *ssid;
  836. DBusMessageIter array_iter, sub_array_iter;
  837. char *val;
  838. int len;
  839. if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_ARRAY) {
  840. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: ssids "
  841. "must be an array of arrays of bytes");
  842. *reply = wpas_dbus_error_invalid_args(
  843. message, "Wrong SSIDs value type. Array of arrays of "
  844. "bytes required");
  845. return -1;
  846. }
  847. dbus_message_iter_recurse(var, &array_iter);
  848. if (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_ARRAY ||
  849. dbus_message_iter_get_element_type(&array_iter) != DBUS_TYPE_BYTE)
  850. {
  851. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: ssids "
  852. "must be an array of arrays of bytes");
  853. *reply = wpas_dbus_error_invalid_args(
  854. message, "Wrong SSIDs value type. Array of arrays of "
  855. "bytes required");
  856. return -1;
  857. }
  858. while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_ARRAY)
  859. {
  860. if (ssids_num >= WPAS_MAX_SCAN_SSIDS) {
  861. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
  862. "Too many ssids specified on scan dbus "
  863. "call");
  864. *reply = wpas_dbus_error_invalid_args(
  865. message, "Too many ssids specified. Specify "
  866. "at most four");
  867. return -1;
  868. }
  869. dbus_message_iter_recurse(&array_iter, &sub_array_iter);
  870. dbus_message_iter_get_fixed_array(&sub_array_iter, &val, &len);
  871. if (len != 0) {
  872. ssid = os_malloc(len);
  873. if (ssid == NULL) {
  874. wpa_printf(MSG_DEBUG,
  875. "wpas_dbus_handler_scan[dbus]: "
  876. "out of memory. Cannot allocate "
  877. "memory for SSID");
  878. *reply = dbus_message_new_error(
  879. message, DBUS_ERROR_NO_MEMORY, NULL);
  880. return -1;
  881. }
  882. os_memcpy(ssid, val, len);
  883. } else {
  884. /* Allow zero-length SSIDs */
  885. ssid = NULL;
  886. }
  887. ssids[ssids_num].ssid = ssid;
  888. ssids[ssids_num].ssid_len = len;
  889. dbus_message_iter_next(&array_iter);
  890. ssids_num++;
  891. }
  892. params->num_ssids = ssids_num;
  893. return 0;
  894. }
  895. static int wpas_dbus_get_scan_ies(DBusMessage *message, DBusMessageIter *var,
  896. struct wpa_driver_scan_params *params,
  897. DBusMessage **reply)
  898. {
  899. u8 *ies = NULL, *nies;
  900. int ies_len = 0;
  901. DBusMessageIter array_iter, sub_array_iter;
  902. char *val;
  903. int len;
  904. if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_ARRAY) {
  905. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: ies must "
  906. "be an array of arrays of bytes");
  907. *reply = wpas_dbus_error_invalid_args(
  908. message, "Wrong IEs value type. Array of arrays of "
  909. "bytes required");
  910. return -1;
  911. }
  912. dbus_message_iter_recurse(var, &array_iter);
  913. if (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_ARRAY ||
  914. dbus_message_iter_get_element_type(&array_iter) != DBUS_TYPE_BYTE)
  915. {
  916. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: ies must "
  917. "be an array of arrays of bytes");
  918. *reply = wpas_dbus_error_invalid_args(
  919. message, "Wrong IEs value type. Array required");
  920. return -1;
  921. }
  922. while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_ARRAY)
  923. {
  924. dbus_message_iter_recurse(&array_iter, &sub_array_iter);
  925. dbus_message_iter_get_fixed_array(&sub_array_iter, &val, &len);
  926. if (len == 0) {
  927. dbus_message_iter_next(&array_iter);
  928. continue;
  929. }
  930. nies = os_realloc(ies, ies_len + len);
  931. if (nies == NULL) {
  932. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
  933. "out of memory. Cannot allocate memory for "
  934. "IE");
  935. os_free(ies);
  936. *reply = dbus_message_new_error(
  937. message, DBUS_ERROR_NO_MEMORY, NULL);
  938. return -1;
  939. }
  940. ies = nies;
  941. os_memcpy(ies + ies_len, val, len);
  942. ies_len += len;
  943. dbus_message_iter_next(&array_iter);
  944. }
  945. params->extra_ies = ies;
  946. params->extra_ies_len = ies_len;
  947. return 0;
  948. }
  949. static int wpas_dbus_get_scan_channels(DBusMessage *message,
  950. DBusMessageIter *var,
  951. struct wpa_driver_scan_params *params,
  952. DBusMessage **reply)
  953. {
  954. DBusMessageIter array_iter, sub_array_iter;
  955. int *freqs = NULL, *nfreqs;
  956. int freqs_num = 0;
  957. if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_ARRAY) {
  958. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
  959. "Channels must be an array of structs");
  960. *reply = wpas_dbus_error_invalid_args(
  961. message, "Wrong Channels value type. Array of structs "
  962. "required");
  963. return -1;
  964. }
  965. dbus_message_iter_recurse(var, &array_iter);
  966. if (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_STRUCT) {
  967. wpa_printf(MSG_DEBUG,
  968. "wpas_dbus_handler_scan[dbus]: Channels must be an "
  969. "array of structs");
  970. *reply = wpas_dbus_error_invalid_args(
  971. message, "Wrong Channels value type. Array of structs "
  972. "required");
  973. return -1;
  974. }
  975. while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_STRUCT)
  976. {
  977. int freq, width;
  978. dbus_message_iter_recurse(&array_iter, &sub_array_iter);
  979. if (dbus_message_iter_get_arg_type(&sub_array_iter) !=
  980. DBUS_TYPE_UINT32) {
  981. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
  982. "Channel must by specified by struct of "
  983. "two UINT32s %c",
  984. dbus_message_iter_get_arg_type(
  985. &sub_array_iter));
  986. *reply = wpas_dbus_error_invalid_args(
  987. message, "Wrong Channel struct. Two UINT32s "
  988. "required");
  989. os_free(freqs);
  990. return -1;
  991. }
  992. dbus_message_iter_get_basic(&sub_array_iter, &freq);
  993. if (!dbus_message_iter_next(&sub_array_iter) ||
  994. dbus_message_iter_get_arg_type(&sub_array_iter) !=
  995. DBUS_TYPE_UINT32) {
  996. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
  997. "Channel must by specified by struct of "
  998. "two UINT32s");
  999. *reply = wpas_dbus_error_invalid_args(
  1000. message,
  1001. "Wrong Channel struct. Two UINT32s required");
  1002. os_free(freqs);
  1003. return -1;
  1004. }
  1005. dbus_message_iter_get_basic(&sub_array_iter, &width);
  1006. #define FREQS_ALLOC_CHUNK 32
  1007. if (freqs_num % FREQS_ALLOC_CHUNK == 0) {
  1008. nfreqs = os_realloc(freqs, sizeof(int) *
  1009. (freqs_num + FREQS_ALLOC_CHUNK));
  1010. if (nfreqs == NULL)
  1011. os_free(freqs);
  1012. freqs = nfreqs;
  1013. }
  1014. if (freqs == NULL) {
  1015. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
  1016. "out of memory. can't allocate memory for "
  1017. "freqs");
  1018. *reply = dbus_message_new_error(
  1019. message, DBUS_ERROR_NO_MEMORY, NULL);
  1020. return -1;
  1021. }
  1022. freqs[freqs_num] = freq;
  1023. freqs_num++;
  1024. dbus_message_iter_next(&array_iter);
  1025. }
  1026. nfreqs = os_realloc(freqs,
  1027. sizeof(int) * (freqs_num + 1));
  1028. if (nfreqs == NULL)
  1029. os_free(freqs);
  1030. freqs = nfreqs;
  1031. if (freqs == NULL) {
  1032. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
  1033. "out of memory. Can't allocate memory for freqs");
  1034. *reply = dbus_message_new_error(
  1035. message, DBUS_ERROR_NO_MEMORY, NULL);
  1036. return -1;
  1037. }
  1038. freqs[freqs_num] = 0;
  1039. params->freqs = freqs;
  1040. return 0;
  1041. }
  1042. /**
  1043. * wpas_dbus_handler_scan - Request a wireless scan on an interface
  1044. * @message: Pointer to incoming dbus message
  1045. * @wpa_s: wpa_supplicant structure for a network interface
  1046. * Returns: NULL indicating success or DBus error message on failure
  1047. *
  1048. * Handler function for "Scan" method call of a network device. Requests
  1049. * that wpa_supplicant perform a wireless scan as soon as possible
  1050. * on a particular wireless interface.
  1051. */
  1052. DBusMessage * wpas_dbus_handler_scan(DBusMessage *message,
  1053. struct wpa_supplicant *wpa_s)
  1054. {
  1055. DBusMessage *reply = NULL;
  1056. DBusMessageIter iter, dict_iter, entry_iter, variant_iter;
  1057. char *key = NULL, *type = NULL;
  1058. struct wpa_driver_scan_params params;
  1059. size_t i;
  1060. os_memset(&params, 0, sizeof(params));
  1061. dbus_message_iter_init(message, &iter);
  1062. dbus_message_iter_recurse(&iter, &dict_iter);
  1063. while (dbus_message_iter_get_arg_type(&dict_iter) ==
  1064. DBUS_TYPE_DICT_ENTRY) {
  1065. dbus_message_iter_recurse(&dict_iter, &entry_iter);
  1066. dbus_message_iter_get_basic(&entry_iter, &key);
  1067. dbus_message_iter_next(&entry_iter);
  1068. dbus_message_iter_recurse(&entry_iter, &variant_iter);
  1069. if (os_strcmp(key, "Type") == 0) {
  1070. if (wpas_dbus_get_scan_type(message, &variant_iter,
  1071. &type, &reply) < 0)
  1072. goto out;
  1073. } else if (os_strcmp(key, "SSIDs") == 0) {
  1074. if (wpas_dbus_get_scan_ssids(message, &variant_iter,
  1075. &params, &reply) < 0)
  1076. goto out;
  1077. } else if (os_strcmp(key, "IEs") == 0) {
  1078. if (wpas_dbus_get_scan_ies(message, &variant_iter,
  1079. &params, &reply) < 0)
  1080. goto out;
  1081. } else if (os_strcmp(key, "Channels") == 0) {
  1082. if (wpas_dbus_get_scan_channels(message, &variant_iter,
  1083. &params, &reply) < 0)
  1084. goto out;
  1085. } else {
  1086. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
  1087. "Unknown argument %s", key);
  1088. reply = wpas_dbus_error_invalid_args(message, key);
  1089. goto out;
  1090. }
  1091. dbus_message_iter_next(&dict_iter);
  1092. }
  1093. if (!type) {
  1094. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
  1095. "Scan type not specified");
  1096. reply = wpas_dbus_error_invalid_args(message, key);
  1097. goto out;
  1098. }
  1099. if (!os_strcmp(type, "passive")) {
  1100. if (params.num_ssids || params.extra_ies_len) {
  1101. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
  1102. "SSIDs or IEs specified for passive scan.");
  1103. reply = wpas_dbus_error_invalid_args(
  1104. message, "You can specify only Channels in "
  1105. "passive scan");
  1106. goto out;
  1107. } else if (params.freqs && params.freqs[0]) {
  1108. wpa_supplicant_trigger_scan(wpa_s, &params);
  1109. } else {
  1110. wpa_s->scan_req = 2;
  1111. wpa_supplicant_req_scan(wpa_s, 0, 0);
  1112. }
  1113. } else if (!os_strcmp(type, "active")) {
  1114. if (!params.num_ssids) {
  1115. /* Add wildcard ssid */
  1116. params.num_ssids++;
  1117. }
  1118. wpa_supplicant_trigger_scan(wpa_s, &params);
  1119. } else {
  1120. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
  1121. "Unknown scan type: %s", type);
  1122. reply = wpas_dbus_error_invalid_args(message,
  1123. "Wrong scan type");
  1124. goto out;
  1125. }
  1126. out:
  1127. for (i = 0; i < WPAS_MAX_SCAN_SSIDS; i++)
  1128. os_free((u8 *) params.ssids[i].ssid);
  1129. os_free((u8 *) params.extra_ies);
  1130. os_free(params.freqs);
  1131. return reply;
  1132. }
  1133. /*
  1134. * wpas_dbus_handler_disconnect - Terminate the current connection
  1135. * @message: Pointer to incoming dbus message
  1136. * @wpa_s: wpa_supplicant structure for a network interface
  1137. * Returns: NotConnected DBus error message if already not connected
  1138. * or NULL otherwise.
  1139. *
  1140. * Handler function for "Disconnect" method call of network interface.
  1141. */
  1142. DBusMessage * wpas_dbus_handler_disconnect(DBusMessage *message,
  1143. struct wpa_supplicant *wpa_s)
  1144. {
  1145. if (wpa_s->current_ssid != NULL) {
  1146. wpa_s->disconnected = 1;
  1147. wpa_supplicant_deauthenticate(wpa_s,
  1148. WLAN_REASON_DEAUTH_LEAVING);
  1149. return NULL;
  1150. }
  1151. return dbus_message_new_error(message, WPAS_DBUS_ERROR_NOT_CONNECTED,
  1152. "This interface is not connected");
  1153. }
  1154. /**
  1155. * wpas_dbus_new_iface_add_network - Add a new configured network
  1156. * @message: Pointer to incoming dbus message
  1157. * @wpa_s: wpa_supplicant structure for a network interface
  1158. * Returns: A dbus message containing the object path of the new network
  1159. *
  1160. * Handler function for "AddNetwork" method call of a network interface.
  1161. */
  1162. DBusMessage * wpas_dbus_handler_add_network(DBusMessage *message,
  1163. struct wpa_supplicant *wpa_s)
  1164. {
  1165. DBusMessage *reply = NULL;
  1166. DBusMessageIter iter;
  1167. struct wpa_ssid *ssid = NULL;
  1168. char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *path = path_buf;
  1169. dbus_message_iter_init(message, &iter);
  1170. ssid = wpa_config_add_network(wpa_s->conf);
  1171. if (ssid == NULL) {
  1172. wpa_printf(MSG_ERROR, "wpas_dbus_handler_add_network[dbus]: "
  1173. "can't add new interface.");
  1174. reply = wpas_dbus_error_unknown_error(
  1175. message,
  1176. "wpa_supplicant could not add "
  1177. "a network on this interface.");
  1178. goto err;
  1179. }
  1180. wpas_notify_network_added(wpa_s, ssid);
  1181. ssid->disabled = 1;
  1182. wpa_config_set_network_defaults(ssid);
  1183. reply = set_network_properties(message, wpa_s, ssid, &iter);
  1184. if (reply) {
  1185. wpa_printf(MSG_DEBUG, "wpas_dbus_handler_add_network[dbus]:"
  1186. "control interface couldn't set network "
  1187. "properties");
  1188. goto err;
  1189. }
  1190. /* Construct the object path for this network. */
  1191. os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
  1192. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
  1193. wpa_s->dbus_new_path, ssid->id);
  1194. reply = dbus_message_new_method_return(message);
  1195. if (reply == NULL) {
  1196. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1197. NULL);
  1198. goto err;
  1199. }
  1200. if (!dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path,
  1201. DBUS_TYPE_INVALID)) {
  1202. dbus_message_unref(reply);
  1203. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1204. NULL);
  1205. goto err;
  1206. }
  1207. return reply;
  1208. err:
  1209. if (ssid) {
  1210. wpas_notify_network_removed(wpa_s, ssid);
  1211. wpa_config_remove_network(wpa_s->conf, ssid->id);
  1212. }
  1213. return reply;
  1214. }
  1215. /**
  1216. * wpas_dbus_handler_remove_network - Remove a configured network
  1217. * @message: Pointer to incoming dbus message
  1218. * @wpa_s: wpa_supplicant structure for a network interface
  1219. * Returns: NULL on success or dbus error on failure
  1220. *
  1221. * Handler function for "RemoveNetwork" method call of a network interface.
  1222. */
  1223. DBusMessage * wpas_dbus_handler_remove_network(DBusMessage *message,
  1224. struct wpa_supplicant *wpa_s)
  1225. {
  1226. DBusMessage *reply = NULL;
  1227. const char *op;
  1228. char *iface = NULL, *net_id = NULL;
  1229. int id;
  1230. struct wpa_ssid *ssid;
  1231. dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &op,
  1232. DBUS_TYPE_INVALID);
  1233. /* Extract the network ID and ensure the network */
  1234. /* is actually a child of this interface */
  1235. iface = wpas_dbus_new_decompose_object_path(op, &net_id, NULL);
  1236. if (iface == NULL || os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
  1237. reply = wpas_dbus_error_invalid_args(message, op);
  1238. goto out;
  1239. }
  1240. id = strtoul(net_id, NULL, 10);
  1241. if (errno == EINVAL) {
  1242. reply = wpas_dbus_error_invalid_args(message, op);
  1243. goto out;
  1244. }
  1245. ssid = wpa_config_get_network(wpa_s->conf, id);
  1246. if (ssid == NULL) {
  1247. reply = wpas_dbus_error_network_unknown(message);
  1248. goto out;
  1249. }
  1250. wpas_notify_network_removed(wpa_s, ssid);
  1251. if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
  1252. wpa_printf(MSG_ERROR,
  1253. "wpas_dbus_handler_remove_network[dbus]: "
  1254. "error occurred when removing network %d", id);
  1255. reply = wpas_dbus_error_unknown_error(
  1256. message, "error removing the specified network on "
  1257. "this interface.");
  1258. goto out;
  1259. }
  1260. if (ssid == wpa_s->current_ssid)
  1261. wpa_supplicant_deauthenticate(wpa_s,
  1262. WLAN_REASON_DEAUTH_LEAVING);
  1263. out:
  1264. os_free(iface);
  1265. os_free(net_id);
  1266. return reply;
  1267. }
  1268. /**
  1269. * wpas_dbus_handler_select_network - Attempt association with a network
  1270. * @message: Pointer to incoming dbus message
  1271. * @wpa_s: wpa_supplicant structure for a network interface
  1272. * Returns: NULL on success or dbus error on failure
  1273. *
  1274. * Handler function for "SelectNetwork" method call of network interface.
  1275. */
  1276. DBusMessage * wpas_dbus_handler_select_network(DBusMessage *message,
  1277. struct wpa_supplicant *wpa_s)
  1278. {
  1279. DBusMessage *reply = NULL;
  1280. const char *op;
  1281. char *iface = NULL, *net_id = NULL;
  1282. int id;
  1283. struct wpa_ssid *ssid;
  1284. dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &op,
  1285. DBUS_TYPE_INVALID);
  1286. /* Extract the network ID and ensure the network */
  1287. /* is actually a child of this interface */
  1288. iface = wpas_dbus_new_decompose_object_path(op, &net_id, NULL);
  1289. if (iface == NULL || os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
  1290. reply = wpas_dbus_error_invalid_args(message, op);
  1291. goto out;
  1292. }
  1293. id = strtoul(net_id, NULL, 10);
  1294. if (errno == EINVAL) {
  1295. reply = wpas_dbus_error_invalid_args(message, op);
  1296. goto out;
  1297. }
  1298. ssid = wpa_config_get_network(wpa_s->conf, id);
  1299. if (ssid == NULL) {
  1300. reply = wpas_dbus_error_network_unknown(message);
  1301. goto out;
  1302. }
  1303. /* Finally, associate with the network */
  1304. wpa_supplicant_select_network(wpa_s, ssid);
  1305. out:
  1306. os_free(iface);
  1307. os_free(net_id);
  1308. return reply;
  1309. }
  1310. /**
  1311. * wpas_dbus_handler_add_blob - Store named binary blob (ie, for certificates)
  1312. * @message: Pointer to incoming dbus message
  1313. * @wpa_s: %wpa_supplicant data structure
  1314. * Returns: A dbus message containing an error on failure or NULL on success
  1315. *
  1316. * Asks wpa_supplicant to internally store a binary blobs.
  1317. */
  1318. DBusMessage * wpas_dbus_handler_add_blob(DBusMessage *message,
  1319. struct wpa_supplicant *wpa_s)
  1320. {
  1321. DBusMessage *reply = NULL;
  1322. DBusMessageIter iter, array_iter;
  1323. char *blob_name;
  1324. u8 *blob_data;
  1325. int blob_len;
  1326. struct wpa_config_blob *blob = NULL;
  1327. dbus_message_iter_init(message, &iter);
  1328. dbus_message_iter_get_basic(&iter, &blob_name);
  1329. if (wpa_config_get_blob(wpa_s->conf, blob_name)) {
  1330. return dbus_message_new_error(message,
  1331. WPAS_DBUS_ERROR_BLOB_EXISTS,
  1332. NULL);
  1333. }
  1334. dbus_message_iter_next(&iter);
  1335. dbus_message_iter_recurse(&iter, &array_iter);
  1336. dbus_message_iter_get_fixed_array(&array_iter, &blob_data, &blob_len);
  1337. blob = os_zalloc(sizeof(*blob));
  1338. if (!blob) {
  1339. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1340. NULL);
  1341. goto err;
  1342. }
  1343. blob->data = os_malloc(blob_len);
  1344. if (!blob->data) {
  1345. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1346. NULL);
  1347. goto err;
  1348. }
  1349. os_memcpy(blob->data, blob_data, blob_len);
  1350. blob->len = blob_len;
  1351. blob->name = os_strdup(blob_name);
  1352. if (!blob->name) {
  1353. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1354. NULL);
  1355. goto err;
  1356. }
  1357. wpa_config_set_blob(wpa_s->conf, blob);
  1358. wpas_notify_blob_added(wpa_s, blob->name);
  1359. return reply;
  1360. err:
  1361. if (blob) {
  1362. os_free(blob->name);
  1363. os_free(blob->data);
  1364. os_free(blob);
  1365. }
  1366. return reply;
  1367. }
  1368. /**
  1369. * wpas_dbus_handler_get_blob - Get named binary blob (ie, for certificates)
  1370. * @message: Pointer to incoming dbus message
  1371. * @wpa_s: %wpa_supplicant data structure
  1372. * Returns: A dbus message containing array of bytes (blob)
  1373. *
  1374. * Gets one wpa_supplicant's binary blobs.
  1375. */
  1376. DBusMessage * wpas_dbus_handler_get_blob(DBusMessage *message,
  1377. struct wpa_supplicant *wpa_s)
  1378. {
  1379. DBusMessage *reply = NULL;
  1380. DBusMessageIter iter, array_iter;
  1381. char *blob_name;
  1382. const struct wpa_config_blob *blob;
  1383. dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &blob_name,
  1384. DBUS_TYPE_INVALID);
  1385. blob = wpa_config_get_blob(wpa_s->conf, blob_name);
  1386. if (!blob) {
  1387. return dbus_message_new_error(message,
  1388. WPAS_DBUS_ERROR_BLOB_UNKNOWN,
  1389. "Blob id not set");
  1390. }
  1391. reply = dbus_message_new_method_return(message);
  1392. if (!reply) {
  1393. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1394. NULL);
  1395. goto out;
  1396. }
  1397. dbus_message_iter_init_append(reply, &iter);
  1398. if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
  1399. DBUS_TYPE_BYTE_AS_STRING,
  1400. &array_iter)) {
  1401. dbus_message_unref(reply);
  1402. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1403. NULL);
  1404. goto out;
  1405. }
  1406. if (!dbus_message_iter_append_fixed_array(&array_iter, DBUS_TYPE_BYTE,
  1407. &(blob->data), blob->len)) {
  1408. dbus_message_unref(reply);
  1409. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1410. NULL);
  1411. goto out;
  1412. }
  1413. if (!dbus_message_iter_close_container(&iter, &array_iter)) {
  1414. dbus_message_unref(reply);
  1415. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1416. NULL);
  1417. goto out;
  1418. }
  1419. out:
  1420. return reply;
  1421. }
  1422. /**
  1423. * wpas_remove_handler_remove_blob - Remove named binary blob
  1424. * @message: Pointer to incoming dbus message
  1425. * @wpa_s: %wpa_supplicant data structure
  1426. * Returns: NULL on success or dbus error
  1427. *
  1428. * Asks wpa_supplicant to internally remove a binary blobs.
  1429. */
  1430. DBusMessage * wpas_dbus_handler_remove_blob(DBusMessage *message,
  1431. struct wpa_supplicant *wpa_s)
  1432. {
  1433. DBusMessage *reply = NULL;
  1434. char *blob_name;
  1435. dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &blob_name,
  1436. DBUS_TYPE_INVALID);
  1437. if (wpa_config_remove_blob(wpa_s->conf, blob_name)) {
  1438. return dbus_message_new_error(message,
  1439. WPAS_DBUS_ERROR_BLOB_UNKNOWN,
  1440. "Blob id not set");
  1441. }
  1442. wpas_notify_blob_removed(wpa_s, blob_name);
  1443. return reply;
  1444. }
  1445. /**
  1446. * wpas_dbus_getter_capabilities - Return interface capabilities
  1447. * @message: Pointer to incoming dbus message
  1448. * @wpa_s: wpa_supplicant structure for a network interface
  1449. * Returns: A dbus message containing a dict of strings
  1450. *
  1451. * Getter for "Capabilities" property of an interface.
  1452. */
  1453. DBusMessage * wpas_dbus_getter_capabilities(DBusMessage *message,
  1454. struct wpa_supplicant *wpa_s)
  1455. {
  1456. DBusMessage *reply = NULL;
  1457. struct wpa_driver_capa capa;
  1458. int res;
  1459. DBusMessageIter iter, iter_dict;
  1460. DBusMessageIter iter_dict_entry, iter_dict_val, iter_array,
  1461. variant_iter;
  1462. const char *scans[] = { "active", "passive", "ssid" };
  1463. const char *modes[] = { "infrastructure", "ad-hoc", "ap" };
  1464. int n = sizeof(modes) / sizeof(char *);
  1465. if (message == NULL)
  1466. reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
  1467. else
  1468. reply = dbus_message_new_method_return(message);
  1469. if (!reply)
  1470. goto nomem;
  1471. dbus_message_iter_init_append(reply, &iter);
  1472. if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
  1473. "a{sv}", &variant_iter))
  1474. goto nomem;
  1475. if (!wpa_dbus_dict_open_write(&variant_iter, &iter_dict))
  1476. goto nomem;
  1477. res = wpa_drv_get_capa(wpa_s, &capa);
  1478. /***** pairwise cipher */
  1479. if (res < 0) {
  1480. const char *args[] = {"ccmp", "tkip", "none"};
  1481. if (!wpa_dbus_dict_append_string_array(
  1482. &iter_dict, "Pairwise", args,
  1483. sizeof(args) / sizeof(char*)))
  1484. goto nomem;
  1485. } else {
  1486. if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Pairwise",
  1487. &iter_dict_entry,
  1488. &iter_dict_val,
  1489. &iter_array))
  1490. goto nomem;
  1491. if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) {
  1492. if (!wpa_dbus_dict_string_array_add_element(
  1493. &iter_array, "ccmp"))
  1494. goto nomem;
  1495. }
  1496. if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) {
  1497. if (!wpa_dbus_dict_string_array_add_element(
  1498. &iter_array, "tkip"))
  1499. goto nomem;
  1500. }
  1501. if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
  1502. if (!wpa_dbus_dict_string_array_add_element(
  1503. &iter_array, "none"))
  1504. goto nomem;
  1505. }
  1506. if (!wpa_dbus_dict_end_string_array(&iter_dict,
  1507. &iter_dict_entry,
  1508. &iter_dict_val,
  1509. &iter_array))
  1510. goto nomem;
  1511. }
  1512. /***** group cipher */
  1513. if (res < 0) {
  1514. const char *args[] = {
  1515. "ccmp", "tkip", "wep104", "wep40"
  1516. };
  1517. if (!wpa_dbus_dict_append_string_array(
  1518. &iter_dict, "Group", args,
  1519. sizeof(args) / sizeof(char*)))
  1520. goto nomem;
  1521. } else {
  1522. if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Group",
  1523. &iter_dict_entry,
  1524. &iter_dict_val,
  1525. &iter_array))
  1526. goto nomem;
  1527. if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) {
  1528. if (!wpa_dbus_dict_string_array_add_element(
  1529. &iter_array, "ccmp"))
  1530. goto nomem;
  1531. }
  1532. if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) {
  1533. if (!wpa_dbus_dict_string_array_add_element(
  1534. &iter_array, "tkip"))
  1535. goto nomem;
  1536. }
  1537. if (capa.enc & WPA_DRIVER_CAPA_ENC_WEP104) {
  1538. if (!wpa_dbus_dict_string_array_add_element(
  1539. &iter_array, "wep104"))
  1540. goto nomem;
  1541. }
  1542. if (capa.enc & WPA_DRIVER_CAPA_ENC_WEP40) {
  1543. if (!wpa_dbus_dict_string_array_add_element(
  1544. &iter_array, "wep40"))
  1545. goto nomem;
  1546. }
  1547. if (!wpa_dbus_dict_end_string_array(&iter_dict,
  1548. &iter_dict_entry,
  1549. &iter_dict_val,
  1550. &iter_array))
  1551. goto nomem;
  1552. }
  1553. /***** key management */
  1554. if (res < 0) {
  1555. const char *args[] = {
  1556. "wpa-psk", "wpa-eap", "ieee8021x", "wpa-none",
  1557. #ifdef CONFIG_WPS
  1558. "wps",
  1559. #endif /* CONFIG_WPS */
  1560. "none"
  1561. };
  1562. if (!wpa_dbus_dict_append_string_array(
  1563. &iter_dict, "KeyMgmt", args,
  1564. sizeof(args) / sizeof(char*)))
  1565. goto nomem;
  1566. } else {
  1567. if (!wpa_dbus_dict_begin_string_array(&iter_dict, "KeyMgmt",
  1568. &iter_dict_entry,
  1569. &iter_dict_val,
  1570. &iter_array))
  1571. goto nomem;
  1572. if (!wpa_dbus_dict_string_array_add_element(&iter_array,
  1573. "none"))
  1574. goto nomem;
  1575. if (!wpa_dbus_dict_string_array_add_element(&iter_array,
  1576. "ieee8021x"))
  1577. goto nomem;
  1578. if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
  1579. WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
  1580. if (!wpa_dbus_dict_string_array_add_element(
  1581. &iter_array, "wpa-eap"))
  1582. goto nomem;
  1583. if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT)
  1584. if (!wpa_dbus_dict_string_array_add_element(
  1585. &iter_array, "wpa-ft-eap"))
  1586. goto nomem;
  1587. /* TODO: Ensure that driver actually supports sha256 encryption. */
  1588. #ifdef CONFIG_IEEE80211W
  1589. if (!wpa_dbus_dict_string_array_add_element(
  1590. &iter_array, "wpa-eap-sha256"))
  1591. goto nomem;
  1592. #endif /* CONFIG_IEEE80211W */
  1593. }
  1594. if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
  1595. WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
  1596. if (!wpa_dbus_dict_string_array_add_element(
  1597. &iter_array, "wpa-psk"))
  1598. goto nomem;
  1599. if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK)
  1600. if (!wpa_dbus_dict_string_array_add_element(
  1601. &iter_array, "wpa-ft-psk"))
  1602. goto nomem;
  1603. /* TODO: Ensure that driver actually supports sha256 encryption. */
  1604. #ifdef CONFIG_IEEE80211W
  1605. if (!wpa_dbus_dict_string_array_add_element(
  1606. &iter_array, "wpa-psk-sha256"))
  1607. goto nomem;
  1608. #endif /* CONFIG_IEEE80211W */
  1609. }
  1610. if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
  1611. if (!wpa_dbus_dict_string_array_add_element(
  1612. &iter_array, "wpa-none"))
  1613. goto nomem;
  1614. }
  1615. #ifdef CONFIG_WPS
  1616. if (!wpa_dbus_dict_string_array_add_element(&iter_array,
  1617. "wps"))
  1618. goto nomem;
  1619. #endif /* CONFIG_WPS */
  1620. if (!wpa_dbus_dict_end_string_array(&iter_dict,
  1621. &iter_dict_entry,
  1622. &iter_dict_val,
  1623. &iter_array))
  1624. goto nomem;
  1625. }
  1626. /***** WPA protocol */
  1627. if (res < 0) {
  1628. const char *args[] = { "rsn", "wpa" };
  1629. if (!wpa_dbus_dict_append_string_array(
  1630. &iter_dict, "Protocol", args,
  1631. sizeof(args) / sizeof(char*)))
  1632. goto nomem;
  1633. } else {
  1634. if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Protocol",
  1635. &iter_dict_entry,
  1636. &iter_dict_val,
  1637. &iter_array))
  1638. goto nomem;
  1639. if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
  1640. WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
  1641. if (!wpa_dbus_dict_string_array_add_element(
  1642. &iter_array, "rsn"))
  1643. goto nomem;
  1644. }
  1645. if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
  1646. WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
  1647. if (!wpa_dbus_dict_string_array_add_element(
  1648. &iter_array, "wpa"))
  1649. goto nomem;
  1650. }
  1651. if (!wpa_dbus_dict_end_string_array(&iter_dict,
  1652. &iter_dict_entry,
  1653. &iter_dict_val,
  1654. &iter_array))
  1655. goto nomem;
  1656. }
  1657. /***** auth alg */
  1658. if (res < 0) {
  1659. const char *args[] = { "open", "shared", "leap" };
  1660. if (!wpa_dbus_dict_append_string_array(
  1661. &iter_dict, "AuthAlg", args,
  1662. sizeof(args) / sizeof(char*)))
  1663. goto nomem;
  1664. } else {
  1665. if (!wpa_dbus_dict_begin_string_array(&iter_dict, "AuthAlg",
  1666. &iter_dict_entry,
  1667. &iter_dict_val,
  1668. &iter_array))
  1669. goto nomem;
  1670. if (capa.auth & (WPA_DRIVER_AUTH_OPEN)) {
  1671. if (!wpa_dbus_dict_string_array_add_element(
  1672. &iter_array, "open"))
  1673. goto nomem;
  1674. }
  1675. if (capa.auth & (WPA_DRIVER_AUTH_SHARED)) {
  1676. if (!wpa_dbus_dict_string_array_add_element(
  1677. &iter_array, "shared"))
  1678. goto nomem;
  1679. }
  1680. if (capa.auth & (WPA_DRIVER_AUTH_LEAP)) {
  1681. if (!wpa_dbus_dict_string_array_add_element(
  1682. &iter_array, "leap"))
  1683. goto nomem;
  1684. }
  1685. if (!wpa_dbus_dict_end_string_array(&iter_dict,
  1686. &iter_dict_entry,
  1687. &iter_dict_val,
  1688. &iter_array))
  1689. goto nomem;
  1690. }
  1691. /***** Scan */
  1692. if (!wpa_dbus_dict_append_string_array(&iter_dict, "Scan", scans,
  1693. sizeof(scans) / sizeof(char *)))
  1694. goto nomem;
  1695. /***** Modes */
  1696. if (res < 0 || !(capa.flags & WPA_DRIVER_FLAGS_AP))
  1697. n--; /* exclude ap mode if it is not supported by the driver */
  1698. if (!wpa_dbus_dict_append_string_array(&iter_dict, "Modes", modes, n))
  1699. goto nomem;
  1700. if (!wpa_dbus_dict_close_write(&variant_iter, &iter_dict))
  1701. goto nomem;
  1702. if (!dbus_message_iter_close_container(&iter, &variant_iter))
  1703. goto nomem;
  1704. return reply;
  1705. nomem:
  1706. if (reply)
  1707. dbus_message_unref(reply);
  1708. return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY, NULL);
  1709. }
  1710. /**
  1711. * wpas_dbus_getter_state - Get interface state
  1712. * @message: Pointer to incoming dbus message
  1713. * @wpa_s: wpa_supplicant structure for a network interface
  1714. * Returns: A dbus message containing a STRING representing the current
  1715. * interface state
  1716. *
  1717. * Getter for "State" property.
  1718. */
  1719. DBusMessage * wpas_dbus_getter_state(DBusMessage *message,
  1720. struct wpa_supplicant *wpa_s)
  1721. {
  1722. DBusMessage *reply = NULL;
  1723. const char *str_state;
  1724. char *state_ls, *tmp;
  1725. str_state = wpa_supplicant_state_txt(wpa_s->wpa_state);
  1726. /* make state string lowercase to fit new DBus API convention
  1727. */
  1728. state_ls = tmp = os_strdup(str_state);
  1729. if (!tmp) {
  1730. return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1731. NULL);
  1732. }
  1733. while (*tmp) {
  1734. *tmp = tolower(*tmp);
  1735. tmp++;
  1736. }
  1737. reply = wpas_dbus_simple_property_getter(message, DBUS_TYPE_STRING,
  1738. &state_ls);
  1739. os_free(state_ls);
  1740. return reply;
  1741. }
  1742. /**
  1743. * wpas_dbus_new_iface_get_scanning - Get interface scanning state
  1744. * @message: Pointer to incoming dbus message
  1745. * @wpa_s: wpa_supplicant structure for a network interface
  1746. * Returns: A dbus message containing whether the interface is scanning
  1747. *
  1748. * Getter for "scanning" property.
  1749. */
  1750. DBusMessage * wpas_dbus_getter_scanning(DBusMessage *message,
  1751. struct wpa_supplicant *wpa_s)
  1752. {
  1753. dbus_bool_t scanning = wpa_s->scanning ? TRUE : FALSE;
  1754. return wpas_dbus_simple_property_getter(message, DBUS_TYPE_BOOLEAN,
  1755. &scanning);
  1756. }
  1757. /**
  1758. * wpas_dbus_getter_ap_scan - Control roaming mode
  1759. * @message: Pointer to incoming dbus message
  1760. * @wpa_s: wpa_supplicant structure for a network interface
  1761. * Returns: A message containong value of ap_scan variable
  1762. *
  1763. * Getter function for "ApScan" property.
  1764. */
  1765. DBusMessage * wpas_dbus_getter_ap_scan(DBusMessage *message,
  1766. struct wpa_supplicant *wpa_s)
  1767. {
  1768. dbus_uint32_t ap_scan = wpa_s->conf->ap_scan;
  1769. return wpas_dbus_simple_property_getter(message, DBUS_TYPE_UINT32,
  1770. &ap_scan);
  1771. }
  1772. /**
  1773. * wpas_dbus_setter_ap_scan - Control roaming mode
  1774. * @message: Pointer to incoming dbus message
  1775. * @wpa_s: wpa_supplicant structure for a network interface
  1776. * Returns: NULL
  1777. *
  1778. * Setter function for "ApScan" property.
  1779. */
  1780. DBusMessage * wpas_dbus_setter_ap_scan(DBusMessage *message,
  1781. struct wpa_supplicant *wpa_s)
  1782. {
  1783. DBusMessage *reply = NULL;
  1784. dbus_uint32_t ap_scan;
  1785. reply = wpas_dbus_simple_property_setter(message, DBUS_TYPE_UINT32,
  1786. &ap_scan);
  1787. if (reply)
  1788. return reply;
  1789. if (wpa_supplicant_set_ap_scan(wpa_s, ap_scan)) {
  1790. return wpas_dbus_error_invalid_args(
  1791. message, "ap_scan must equal 0, 1 or 2");
  1792. }
  1793. return NULL;
  1794. }
  1795. /**
  1796. * wpas_dbus_getter_ifname - Get interface name
  1797. * @message: Pointer to incoming dbus message
  1798. * @wpa_s: wpa_supplicant structure for a network interface
  1799. * Returns: A dbus message containing a name of network interface
  1800. * associated with with wpa_s
  1801. *
  1802. * Getter for "Ifname" property.
  1803. */
  1804. DBusMessage * wpas_dbus_getter_ifname(DBusMessage *message,
  1805. struct wpa_supplicant *wpa_s)
  1806. {
  1807. const char *ifname = wpa_s->ifname;
  1808. return wpas_dbus_simple_property_getter(message, DBUS_TYPE_STRING,
  1809. &ifname);
  1810. }
  1811. /**
  1812. * wpas_dbus_getter_driver - Get interface name
  1813. * @message: Pointer to incoming dbus message
  1814. * @wpa_s: wpa_supplicant structure for a network interface
  1815. * Returns: A dbus message containing a name of network interface
  1816. * driver associated with with wpa_s
  1817. *
  1818. * Getter for "Driver" property.
  1819. */
  1820. DBusMessage * wpas_dbus_getter_driver(DBusMessage *message,
  1821. struct wpa_supplicant *wpa_s)
  1822. {
  1823. const char *driver;
  1824. if (wpa_s->driver == NULL || wpa_s->driver->name == NULL) {
  1825. wpa_printf(MSG_DEBUG, "wpas_dbus_getter_driver[dbus]: "
  1826. "wpa_s has no driver set");
  1827. return wpas_dbus_error_unknown_error(message, NULL);
  1828. }
  1829. driver = wpa_s->driver->name;
  1830. return wpas_dbus_simple_property_getter(message, DBUS_TYPE_STRING,
  1831. &driver);
  1832. }
  1833. /**
  1834. * wpas_dbus_getter_current_bss - Get current bss object path
  1835. * @message: Pointer to incoming dbus message
  1836. * @wpa_s: wpa_supplicant structure for a network interface
  1837. * Returns: A dbus message containing a DBus object path to
  1838. * current BSS
  1839. *
  1840. * Getter for "CurrentBSS" property.
  1841. */
  1842. DBusMessage * wpas_dbus_getter_current_bss(DBusMessage *message,
  1843. struct wpa_supplicant *wpa_s)
  1844. {
  1845. DBusMessage *reply;
  1846. char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *bss_obj_path = path_buf;
  1847. if (wpa_s->current_bss)
  1848. os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1849. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  1850. wpa_s->dbus_new_path, wpa_s->current_bss->id);
  1851. else
  1852. os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "/");
  1853. reply = wpas_dbus_simple_property_getter(message,
  1854. DBUS_TYPE_OBJECT_PATH,
  1855. &bss_obj_path);
  1856. return reply;
  1857. }
  1858. /**
  1859. * wpas_dbus_getter_current_network - Get current network object path
  1860. * @message: Pointer to incoming dbus message
  1861. * @wpa_s: wpa_supplicant structure for a network interface
  1862. * Returns: A dbus message containing a DBus object path to
  1863. * current network
  1864. *
  1865. * Getter for "CurrentNetwork" property.
  1866. */
  1867. DBusMessage * wpas_dbus_getter_current_network(DBusMessage *message,
  1868. struct wpa_supplicant *wpa_s)
  1869. {
  1870. DBusMessage *reply;
  1871. char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *net_obj_path = path_buf;
  1872. if (wpa_s->current_ssid)
  1873. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1874. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  1875. wpa_s->dbus_new_path, wpa_s->current_ssid->id);
  1876. else
  1877. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "/");
  1878. reply = wpas_dbus_simple_property_getter(message,
  1879. DBUS_TYPE_OBJECT_PATH,
  1880. &net_obj_path);
  1881. return reply;
  1882. }
  1883. /**
  1884. * wpas_dbus_getter_bridge_ifname - Get interface name
  1885. * @message: Pointer to incoming dbus message
  1886. * @wpa_s: wpa_supplicant structure for a network interface
  1887. * Returns: A dbus message containing a name of bridge network
  1888. * interface associated with with wpa_s
  1889. *
  1890. * Getter for "BridgeIfname" property.
  1891. */
  1892. DBusMessage * wpas_dbus_getter_bridge_ifname(DBusMessage *message,
  1893. struct wpa_supplicant *wpa_s)
  1894. {
  1895. const char *bridge_ifname = NULL;
  1896. bridge_ifname = wpa_s->bridge_ifname;
  1897. if (bridge_ifname == NULL) {
  1898. wpa_printf(MSG_ERROR, "wpas_dbus_getter_bridge_ifname[dbus]: "
  1899. "wpa_s has no bridge interface name set");
  1900. return wpas_dbus_error_unknown_error(message, NULL);
  1901. }
  1902. return wpas_dbus_simple_property_getter(message, DBUS_TYPE_STRING,
  1903. &bridge_ifname);
  1904. }
  1905. /**
  1906. * wpas_dbus_getter_bsss - Get array of BSSs objects
  1907. * @message: Pointer to incoming dbus message
  1908. * @wpa_s: wpa_supplicant structure for a network interface
  1909. * Returns: a dbus message containing an array of all known BSS objects
  1910. * dbus paths
  1911. *
  1912. * Getter for "BSSs" property.
  1913. */
  1914. DBusMessage * wpas_dbus_getter_bsss(DBusMessage *message,
  1915. struct wpa_supplicant *wpa_s)
  1916. {
  1917. DBusMessage *reply = NULL;
  1918. struct wpa_bss *bss;
  1919. char **paths;
  1920. unsigned int i = 0;
  1921. paths = os_zalloc(wpa_s->num_bss * sizeof(char *));
  1922. if (!paths) {
  1923. return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1924. NULL);
  1925. }
  1926. /* Loop through scan results and append each result's object path */
  1927. dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
  1928. paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
  1929. if (paths[i] == NULL) {
  1930. reply = dbus_message_new_error(message,
  1931. DBUS_ERROR_NO_MEMORY,
  1932. NULL);
  1933. goto out;
  1934. }
  1935. /* Construct the object path for this BSS. */
  1936. os_snprintf(paths[i++], WPAS_DBUS_OBJECT_PATH_MAX,
  1937. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  1938. wpa_s->dbus_new_path, bss->id);
  1939. }
  1940. reply = wpas_dbus_simple_array_property_getter(message,
  1941. DBUS_TYPE_OBJECT_PATH,
  1942. paths, wpa_s->num_bss);
  1943. out:
  1944. while (i)
  1945. os_free(paths[--i]);
  1946. os_free(paths);
  1947. return reply;
  1948. }
  1949. /**
  1950. * wpas_dbus_getter_networks - Get array of networks objects
  1951. * @message: Pointer to incoming dbus message
  1952. * @wpa_s: wpa_supplicant structure for a network interface
  1953. * Returns: a dbus message containing an array of all configured
  1954. * networks dbus object paths.
  1955. *
  1956. * Getter for "Networks" property.
  1957. */
  1958. DBusMessage * wpas_dbus_getter_networks(DBusMessage *message,
  1959. struct wpa_supplicant *wpa_s)
  1960. {
  1961. DBusMessage *reply = NULL;
  1962. struct wpa_ssid *ssid;
  1963. char **paths;
  1964. unsigned int i = 0, num = 0;
  1965. if (wpa_s->conf == NULL) {
  1966. wpa_printf(MSG_ERROR, "wpas_dbus_getter_networks[dbus]: "
  1967. "An error occurred getting networks list.");
  1968. return wpas_dbus_error_unknown_error(message, NULL);
  1969. }
  1970. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next)
  1971. num++;
  1972. paths = os_zalloc(num * sizeof(char *));
  1973. if (!paths) {
  1974. return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  1975. NULL);
  1976. }
  1977. /* Loop through configured networks and append object path of each */
  1978. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
  1979. paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
  1980. if (paths[i] == NULL) {
  1981. reply = dbus_message_new_error(message,
  1982. DBUS_ERROR_NO_MEMORY,
  1983. NULL);
  1984. goto out;
  1985. }
  1986. /* Construct the object path for this network. */
  1987. os_snprintf(paths[i++], WPAS_DBUS_OBJECT_PATH_MAX,
  1988. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
  1989. wpa_s->dbus_new_path, ssid->id);
  1990. }
  1991. reply = wpas_dbus_simple_array_property_getter(message,
  1992. DBUS_TYPE_OBJECT_PATH,
  1993. paths, num);
  1994. out:
  1995. while (i)
  1996. os_free(paths[--i]);
  1997. os_free(paths);
  1998. return reply;
  1999. }
  2000. /**
  2001. * wpas_dbus_getter_blobs - Get all blobs defined for this interface
  2002. * @message: Pointer to incoming dbus message
  2003. * @wpa_s: wpa_supplicant structure for a network interface
  2004. * Returns: a dbus message containing a dictionary of pairs (blob_name, blob)
  2005. *
  2006. * Getter for "Blobs" property.
  2007. */
  2008. DBusMessage * wpas_dbus_getter_blobs(DBusMessage *message,
  2009. struct wpa_supplicant *wpa_s)
  2010. {
  2011. DBusMessage *reply = NULL;
  2012. DBusMessageIter iter, variant_iter, dict_iter, entry_iter, array_iter;
  2013. struct wpa_config_blob *blob;
  2014. if (message == NULL)
  2015. reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
  2016. else
  2017. reply = dbus_message_new_method_return(message);
  2018. if (!reply)
  2019. return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  2020. NULL);
  2021. dbus_message_iter_init_append(reply, &iter);
  2022. if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
  2023. "a{say}", &variant_iter) ||
  2024. !dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
  2025. "{say}", &dict_iter)) {
  2026. dbus_message_unref(reply);
  2027. return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  2028. NULL);
  2029. }
  2030. blob = wpa_s->conf->blobs;
  2031. while (blob) {
  2032. if (!dbus_message_iter_open_container(&dict_iter,
  2033. DBUS_TYPE_DICT_ENTRY,
  2034. NULL, &entry_iter) ||
  2035. !dbus_message_iter_append_basic(&entry_iter,
  2036. DBUS_TYPE_STRING,
  2037. &(blob->name)) ||
  2038. !dbus_message_iter_open_container(&entry_iter,
  2039. DBUS_TYPE_ARRAY,
  2040. DBUS_TYPE_BYTE_AS_STRING,
  2041. &array_iter) ||
  2042. !dbus_message_iter_append_fixed_array(&array_iter,
  2043. DBUS_TYPE_BYTE,
  2044. &(blob->data),
  2045. blob->len) ||
  2046. !dbus_message_iter_close_container(&entry_iter,
  2047. &array_iter) ||
  2048. !dbus_message_iter_close_container(&dict_iter,
  2049. &entry_iter)) {
  2050. dbus_message_unref(reply);
  2051. return dbus_message_new_error(message,
  2052. DBUS_ERROR_NO_MEMORY,
  2053. NULL);
  2054. }
  2055. blob = blob->next;
  2056. }
  2057. if (!dbus_message_iter_close_container(&variant_iter, &dict_iter) ||
  2058. !dbus_message_iter_close_container(&iter, &variant_iter)) {
  2059. dbus_message_unref(reply);
  2060. return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  2061. NULL);
  2062. }
  2063. return reply;
  2064. }
  2065. /**
  2066. * wpas_dbus_getter_bss_bssid - Return the BSSID of a BSS
  2067. * @message: Pointer to incoming dbus message
  2068. * @bss: a pair of interface describing structure and bss's id
  2069. * Returns: a dbus message containing the bssid for the requested bss
  2070. *
  2071. * Getter for "BSSID" property.
  2072. */
  2073. DBusMessage * wpas_dbus_getter_bss_bssid(DBusMessage *message,
  2074. struct bss_handler_args *bss)
  2075. {
  2076. struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
  2077. if (!res) {
  2078. wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_bssid[dbus]: no "
  2079. "bss with id %d found", bss->id);
  2080. return NULL;
  2081. }
  2082. return wpas_dbus_simple_array_property_getter(message, DBUS_TYPE_BYTE,
  2083. res->bssid, ETH_ALEN);
  2084. }
  2085. /**
  2086. * wpas_dbus_getter_bss_ssid - Return the SSID of a BSS
  2087. * @message: Pointer to incoming dbus message
  2088. * @bss: a pair of interface describing structure and bss's id
  2089. * Returns: a dbus message containing the ssid for the requested bss
  2090. *
  2091. * Getter for "SSID" property.
  2092. */
  2093. DBusMessage * wpas_dbus_getter_bss_ssid(DBusMessage *message,
  2094. struct bss_handler_args *bss)
  2095. {
  2096. struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
  2097. if (!res) {
  2098. wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_ssid[dbus]: no "
  2099. "bss with id %d found", bss->id);
  2100. return NULL;
  2101. }
  2102. return wpas_dbus_simple_array_property_getter(message, DBUS_TYPE_BYTE,
  2103. res->ssid,
  2104. res->ssid_len);
  2105. }
  2106. /**
  2107. * wpas_dbus_getter_bss_privacy - Return the privacy flag of a BSS
  2108. * @message: Pointer to incoming dbus message
  2109. * @bss: a pair of interface describing structure and bss's id
  2110. * Returns: a dbus message containing the privacy flag value of requested bss
  2111. *
  2112. * Getter for "Privacy" property.
  2113. */
  2114. DBusMessage * wpas_dbus_getter_bss_privacy(DBusMessage *message,
  2115. struct bss_handler_args *bss)
  2116. {
  2117. struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
  2118. dbus_bool_t privacy;
  2119. if (!res) {
  2120. wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_privacy[dbus]: no "
  2121. "bss with id %d found", bss->id);
  2122. return NULL;
  2123. }
  2124. privacy = (res->caps & IEEE80211_CAP_PRIVACY) ? TRUE : FALSE;
  2125. return wpas_dbus_simple_property_getter(message, DBUS_TYPE_BOOLEAN,
  2126. &privacy);
  2127. }
  2128. /**
  2129. * wpas_dbus_getter_bss_mode - Return the mode of a BSS
  2130. * @message: Pointer to incoming dbus message
  2131. * @bss: a pair of interface describing structure and bss's id
  2132. * Returns: a dbus message containing the mode of requested bss
  2133. *
  2134. * Getter for "Mode" property.
  2135. */
  2136. DBusMessage * wpas_dbus_getter_bss_mode(DBusMessage *message,
  2137. struct bss_handler_args *bss)
  2138. {
  2139. struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
  2140. const char *mode;
  2141. if (!res) {
  2142. wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_mode[dbus]: no "
  2143. "bss with id %d found", bss->id);
  2144. return NULL;
  2145. }
  2146. if (res->caps & IEEE80211_CAP_IBSS)
  2147. mode = "ad-hoc";
  2148. else
  2149. mode = "infrastructure";
  2150. return wpas_dbus_simple_property_getter(message, DBUS_TYPE_STRING,
  2151. &mode);
  2152. }
  2153. /**
  2154. * wpas_dbus_getter_bss_level - Return the signal strength of a BSS
  2155. * @message: Pointer to incoming dbus message
  2156. * @bss: a pair of interface describing structure and bss's id
  2157. * Returns: a dbus message containing the signal strength of requested bss
  2158. *
  2159. * Getter for "Level" property.
  2160. */
  2161. DBusMessage * wpas_dbus_getter_bss_signal(DBusMessage *message,
  2162. struct bss_handler_args *bss)
  2163. {
  2164. struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
  2165. if (!res) {
  2166. wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_signal[dbus]: no "
  2167. "bss with id %d found", bss->id);
  2168. return NULL;
  2169. }
  2170. return wpas_dbus_simple_property_getter(message, DBUS_TYPE_INT16,
  2171. &res->level);
  2172. }
  2173. /**
  2174. * wpas_dbus_getter_bss_frequency - Return the frequency of a BSS
  2175. * @message: Pointer to incoming dbus message
  2176. * @bss: a pair of interface describing structure and bss's id
  2177. * Returns: a dbus message containing the frequency of requested bss
  2178. *
  2179. * Getter for "Frequency" property.
  2180. */
  2181. DBusMessage * wpas_dbus_getter_bss_frequency(DBusMessage *message,
  2182. struct bss_handler_args *bss)
  2183. {
  2184. struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
  2185. if (!res) {
  2186. wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_frequency[dbus]: "
  2187. "no bss with id %d found", bss->id);
  2188. return NULL;
  2189. }
  2190. return wpas_dbus_simple_property_getter(message, DBUS_TYPE_UINT16,
  2191. &res->freq);
  2192. }
  2193. static int cmp_u8s_desc(const void *a, const void *b)
  2194. {
  2195. return (*(u8 *) b - *(u8 *) a);
  2196. }
  2197. /**
  2198. * wpas_dbus_getter_bss_rates - Return available bit rates of a BSS
  2199. * @message: Pointer to incoming dbus message
  2200. * @bss: a pair of interface describing structure and bss's id
  2201. * Returns: a dbus message containing sorted array of bit rates
  2202. *
  2203. * Getter for "Rates" property.
  2204. */
  2205. DBusMessage * wpas_dbus_getter_bss_rates(DBusMessage *message,
  2206. struct bss_handler_args *bss)
  2207. {
  2208. DBusMessage *reply;
  2209. struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
  2210. u8 *ie_rates = NULL;
  2211. u32 *real_rates;
  2212. int rates_num, i;
  2213. if (!res) {
  2214. wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_rates[dbus]: "
  2215. "no bss with id %d found", bss->id);
  2216. return NULL;
  2217. }
  2218. rates_num = wpa_bss_get_bit_rates(res, &ie_rates);
  2219. if (rates_num < 0)
  2220. return NULL;
  2221. qsort(ie_rates, rates_num, 1, cmp_u8s_desc);
  2222. real_rates = os_malloc(sizeof(u32) * rates_num);
  2223. if (!real_rates) {
  2224. os_free(ie_rates);
  2225. return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  2226. NULL);
  2227. }
  2228. for (i = 0; i < rates_num; i++)
  2229. real_rates[i] = ie_rates[i] * 500000;
  2230. reply = wpas_dbus_simple_array_property_getter(message,
  2231. DBUS_TYPE_UINT32,
  2232. real_rates, rates_num);
  2233. os_free(ie_rates);
  2234. os_free(real_rates);
  2235. return reply;
  2236. }
  2237. static DBusMessage * wpas_dbus_get_bss_security_prop(
  2238. DBusMessage *message, struct wpa_ie_data *ie_data)
  2239. {
  2240. DBusMessage *reply;
  2241. DBusMessageIter iter, iter_dict, variant_iter;
  2242. const char *group;
  2243. const char *pairwise[2]; /* max 2 pairwise ciphers is supported */
  2244. const char *key_mgmt[7]; /* max 7 key managements may be supported */
  2245. int n;
  2246. if (message == NULL)
  2247. reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
  2248. else
  2249. reply = dbus_message_new_method_return(message);
  2250. if (!reply)
  2251. goto nomem;
  2252. dbus_message_iter_init_append(reply, &iter);
  2253. if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
  2254. "a{sv}", &variant_iter))
  2255. goto nomem;
  2256. if (!wpa_dbus_dict_open_write(&variant_iter, &iter_dict))
  2257. goto nomem;
  2258. /* KeyMgmt */
  2259. n = 0;
  2260. if (ie_data->key_mgmt & WPA_KEY_MGMT_PSK)
  2261. key_mgmt[n++] = "wpa-psk";
  2262. if (ie_data->key_mgmt & WPA_KEY_MGMT_FT_PSK)
  2263. key_mgmt[n++] = "wpa-ft-psk";
  2264. if (ie_data->key_mgmt & WPA_KEY_MGMT_PSK_SHA256)
  2265. key_mgmt[n++] = "wpa-psk-sha256";
  2266. if (ie_data->key_mgmt & WPA_KEY_MGMT_IEEE8021X)
  2267. key_mgmt[n++] = "wpa-eap";
  2268. if (ie_data->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X)
  2269. key_mgmt[n++] = "wpa-ft-eap";
  2270. if (ie_data->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256)
  2271. key_mgmt[n++] = "wpa-eap-sha256";
  2272. if (ie_data->key_mgmt & WPA_KEY_MGMT_NONE)
  2273. key_mgmt[n++] = "wpa-none";
  2274. if (!wpa_dbus_dict_append_string_array(&iter_dict, "KeyMgmt",
  2275. key_mgmt, n))
  2276. goto nomem;
  2277. /* Group */
  2278. switch (ie_data->group_cipher) {
  2279. case WPA_CIPHER_WEP40:
  2280. group = "wep40";
  2281. break;
  2282. case WPA_CIPHER_TKIP:
  2283. group = "tkip";
  2284. break;
  2285. case WPA_CIPHER_CCMP:
  2286. group = "ccmp";
  2287. break;
  2288. case WPA_CIPHER_WEP104:
  2289. group = "wep104";
  2290. break;
  2291. default:
  2292. group = "";
  2293. break;
  2294. }
  2295. if (!wpa_dbus_dict_append_string(&iter_dict, "Group", group))
  2296. goto nomem;
  2297. /* Pairwise */
  2298. n = 0;
  2299. if (ie_data->pairwise_cipher & WPA_CIPHER_TKIP)
  2300. pairwise[n++] = "tkip";
  2301. if (ie_data->pairwise_cipher & WPA_CIPHER_CCMP)
  2302. pairwise[n++] = "ccmp";
  2303. if (!wpa_dbus_dict_append_string_array(&iter_dict, "Pairwise",
  2304. pairwise, n))
  2305. goto nomem;
  2306. /* Management group (RSN only) */
  2307. if (ie_data->proto == WPA_PROTO_RSN) {
  2308. switch (ie_data->mgmt_group_cipher) {
  2309. #ifdef CONFIG_IEEE80211W
  2310. case WPA_CIPHER_AES_128_CMAC:
  2311. group = "aes128cmac";
  2312. break;
  2313. #endif /* CONFIG_IEEE80211W */
  2314. default:
  2315. group = "";
  2316. break;
  2317. }
  2318. if (!wpa_dbus_dict_append_string(&iter_dict, "MgmtGroup",
  2319. group))
  2320. goto nomem;
  2321. }
  2322. if (!wpa_dbus_dict_close_write(&variant_iter, &iter_dict))
  2323. goto nomem;
  2324. if (!dbus_message_iter_close_container(&iter, &variant_iter))
  2325. goto nomem;
  2326. return reply;
  2327. nomem:
  2328. if (reply)
  2329. dbus_message_unref(reply);
  2330. return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY, NULL);
  2331. }
  2332. /**
  2333. * wpas_dbus_getter_bss_wpa - Return the WPA options of a BSS
  2334. * @message: Pointer to incoming dbus message
  2335. * @bss: a pair of interface describing structure and bss's id
  2336. * Returns: a dbus message containing the WPA options of requested bss
  2337. *
  2338. * Getter for "WPA" property.
  2339. */
  2340. DBusMessage * wpas_dbus_getter_bss_wpa(DBusMessage *message,
  2341. struct bss_handler_args *bss)
  2342. {
  2343. struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
  2344. struct wpa_ie_data wpa_data;
  2345. const u8 *ie;
  2346. if (!res) {
  2347. wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_wpa[dbus]: no "
  2348. "bss with id %d found", bss->id);
  2349. return NULL;
  2350. }
  2351. os_memset(&wpa_data, 0, sizeof(wpa_data));
  2352. ie = wpa_bss_get_vendor_ie(res, WPA_IE_VENDOR_TYPE);
  2353. if (ie) {
  2354. if (wpa_parse_wpa_ie(ie, 2 + ie[1], &wpa_data) < 0)
  2355. return wpas_dbus_error_unknown_error(message,
  2356. "invalid WPA IE");
  2357. }
  2358. return wpas_dbus_get_bss_security_prop(message, &wpa_data);
  2359. }
  2360. /**
  2361. * wpas_dbus_getter_bss_rsn - Return the RSN options of a BSS
  2362. * @message: Pointer to incoming dbus message
  2363. * @bss: a pair of interface describing structure and bss's id
  2364. * Returns: a dbus message containing the RSN options of requested bss
  2365. *
  2366. * Getter for "RSN" property.
  2367. */
  2368. DBusMessage * wpas_dbus_getter_bss_rsn(DBusMessage *message,
  2369. struct bss_handler_args *bss)
  2370. {
  2371. struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
  2372. struct wpa_ie_data wpa_data;
  2373. const u8 *ie;
  2374. if (!res) {
  2375. wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_rsn[dbus]: no "
  2376. "bss with id %d found", bss->id);
  2377. return NULL;
  2378. }
  2379. os_memset(&wpa_data, 0, sizeof(wpa_data));
  2380. ie = wpa_bss_get_ie(res, WLAN_EID_RSN);
  2381. if (ie) {
  2382. if (wpa_parse_wpa_ie(ie, 2 + ie[1], &wpa_data) < 0)
  2383. return wpas_dbus_error_unknown_error(message,
  2384. "invalid RSN IE");
  2385. }
  2386. return wpas_dbus_get_bss_security_prop(message, &wpa_data);
  2387. }
  2388. /**
  2389. * wpas_dbus_getter_bss_ies - Return all IEs of a BSS
  2390. * @message: Pointer to incoming dbus message
  2391. * @bss: a pair of interface describing structure and bss's id
  2392. * Returns: a dbus message containing IEs byte array
  2393. *
  2394. * Getter for "IEs" property.
  2395. */
  2396. DBusMessage * wpas_dbus_getter_bss_ies(DBusMessage *message,
  2397. struct bss_handler_args *bss)
  2398. {
  2399. struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
  2400. if (!res) {
  2401. wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_ies[dbus]: no "
  2402. "bss with id %d found", bss->id);
  2403. return NULL;
  2404. }
  2405. return wpas_dbus_simple_array_property_getter(message, DBUS_TYPE_BYTE,
  2406. res + 1, res->ie_len);
  2407. }
  2408. /**
  2409. * wpas_dbus_getter_enabled - Check whether network is enabled or disabled
  2410. * @message: Pointer to incoming dbus message
  2411. * @wpas_dbus_setter_enabled: wpa_supplicant structure for a network interface
  2412. * and wpa_ssid structure for a configured network
  2413. * Returns: DBus message with boolean indicating state of configured network
  2414. * or DBus error on failure
  2415. *
  2416. * Getter for "enabled" property of a configured network.
  2417. */
  2418. DBusMessage * wpas_dbus_getter_enabled(DBusMessage *message,
  2419. struct network_handler_args *net)
  2420. {
  2421. dbus_bool_t enabled = net->ssid->disabled ? FALSE : TRUE;
  2422. return wpas_dbus_simple_property_getter(message, DBUS_TYPE_BOOLEAN,
  2423. &enabled);
  2424. }
  2425. /**
  2426. * wpas_dbus_setter_enabled - Mark a configured network as enabled or disabled
  2427. * @message: Pointer to incoming dbus message
  2428. * @wpas_dbus_setter_enabled: wpa_supplicant structure for a network interface
  2429. * and wpa_ssid structure for a configured network
  2430. * Returns: NULL indicating success or DBus error on failure
  2431. *
  2432. * Setter for "Enabled" property of a configured network.
  2433. */
  2434. DBusMessage * wpas_dbus_setter_enabled(DBusMessage *message,
  2435. struct network_handler_args *net)
  2436. {
  2437. DBusMessage *reply = NULL;
  2438. struct wpa_supplicant *wpa_s;
  2439. struct wpa_ssid *ssid;
  2440. dbus_bool_t enable;
  2441. reply = wpas_dbus_simple_property_setter(message, DBUS_TYPE_BOOLEAN,
  2442. &enable);
  2443. if (reply)
  2444. return reply;
  2445. wpa_s = net->wpa_s;
  2446. ssid = net->ssid;
  2447. if (enable)
  2448. wpa_supplicant_enable_network(wpa_s, ssid);
  2449. else
  2450. wpa_supplicant_disable_network(wpa_s, ssid);
  2451. return NULL;
  2452. }
  2453. /**
  2454. * wpas_dbus_getter_network_properties - Get options for a configured network
  2455. * @message: Pointer to incoming dbus message
  2456. * @net: wpa_supplicant structure for a network interface and
  2457. * wpa_ssid structure for a configured network
  2458. * Returns: DBus message with network properties or DBus error on failure
  2459. *
  2460. * Getter for "Properties" property of a configured network.
  2461. */
  2462. DBusMessage * wpas_dbus_getter_network_properties(
  2463. DBusMessage *message, struct network_handler_args *net)
  2464. {
  2465. DBusMessage *reply = NULL;
  2466. DBusMessageIter iter, variant_iter, dict_iter;
  2467. char **iterator;
  2468. char **props = wpa_config_get_all(net->ssid, 0);
  2469. if (!props)
  2470. return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  2471. NULL);
  2472. if (message == NULL)
  2473. reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
  2474. else
  2475. reply = dbus_message_new_method_return(message);
  2476. if (!reply) {
  2477. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  2478. NULL);
  2479. goto out;
  2480. }
  2481. dbus_message_iter_init_append(reply, &iter);
  2482. if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
  2483. "a{sv}", &variant_iter) ||
  2484. !wpa_dbus_dict_open_write(&variant_iter, &dict_iter)) {
  2485. dbus_message_unref(reply);
  2486. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  2487. NULL);
  2488. goto out;
  2489. }
  2490. iterator = props;
  2491. while (*iterator) {
  2492. if (!wpa_dbus_dict_append_string(&dict_iter, *iterator,
  2493. *(iterator + 1))) {
  2494. dbus_message_unref(reply);
  2495. reply = dbus_message_new_error(message,
  2496. DBUS_ERROR_NO_MEMORY,
  2497. NULL);
  2498. goto out;
  2499. }
  2500. iterator += 2;
  2501. }
  2502. if (!wpa_dbus_dict_close_write(&variant_iter, &dict_iter) ||
  2503. !dbus_message_iter_close_container(&iter, &variant_iter)) {
  2504. dbus_message_unref(reply);
  2505. reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
  2506. NULL);
  2507. goto out;
  2508. }
  2509. out:
  2510. iterator = props;
  2511. while (*iterator) {
  2512. os_free(*iterator);
  2513. iterator++;
  2514. }
  2515. os_free(props);
  2516. return reply;
  2517. }
  2518. /**
  2519. * wpas_dbus_setter_network_properties - Set options for a configured network
  2520. * @message: Pointer to incoming dbus message
  2521. * @net: wpa_supplicant structure for a network interface and
  2522. * wpa_ssid structure for a configured network
  2523. * Returns: NULL indicating success or DBus error on failure
  2524. *
  2525. * Setter for "Properties" property of a configured network.
  2526. */
  2527. DBusMessage * wpas_dbus_setter_network_properties(
  2528. DBusMessage *message, struct network_handler_args *net)
  2529. {
  2530. struct wpa_ssid *ssid = net->ssid;
  2531. DBusMessage *reply = NULL;
  2532. DBusMessageIter iter, variant_iter;
  2533. dbus_message_iter_init(message, &iter);
  2534. dbus_message_iter_next(&iter);
  2535. dbus_message_iter_next(&iter);
  2536. dbus_message_iter_recurse(&iter, &variant_iter);
  2537. reply = set_network_properties(message, net->wpa_s, ssid,
  2538. &variant_iter);
  2539. if (reply)
  2540. wpa_printf(MSG_DEBUG, "dbus control interface couldn't set "
  2541. "network properties");
  2542. return reply;
  2543. }