dbus_new_handlers.c 128 KB

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