dbus_new_handlers.c 113 KB

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