dbus_new_handlers.c 97 KB

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