dbus_new_handlers.c 97 KB

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