dbus_new_handlers.c 117 KB

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