dbus_new_handlers.c 97 KB

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