dbus_new_handlers.c 128 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626
  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_malloc(len);
  937. if (ssid == NULL) {
  938. *reply = wpas_dbus_error_no_memory(message);
  939. return -1;
  940. }
  941. os_memcpy(ssid, val, len);
  942. } else {
  943. /* Allow zero-length SSIDs */
  944. ssid = NULL;
  945. }
  946. ssids[ssids_num].ssid = ssid;
  947. ssids[ssids_num].ssid_len = len;
  948. dbus_message_iter_next(&array_iter);
  949. ssids_num++;
  950. }
  951. params->num_ssids = ssids_num;
  952. return 0;
  953. }
  954. static int wpas_dbus_get_scan_ies(DBusMessage *message, DBusMessageIter *var,
  955. struct wpa_driver_scan_params *params,
  956. DBusMessage **reply)
  957. {
  958. u8 *ies = NULL, *nies;
  959. int ies_len = 0;
  960. DBusMessageIter array_iter, sub_array_iter;
  961. char *val;
  962. int len;
  963. if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_ARRAY) {
  964. wpa_printf(MSG_DEBUG,
  965. "%s[dbus]: ies must be an array of arrays of bytes",
  966. __func__);
  967. *reply = wpas_dbus_error_invalid_args(
  968. message,
  969. "Wrong IEs value type. Array of arrays of bytes required");
  970. return -1;
  971. }
  972. dbus_message_iter_recurse(var, &array_iter);
  973. if (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_ARRAY ||
  974. dbus_message_iter_get_element_type(&array_iter) != DBUS_TYPE_BYTE) {
  975. wpa_printf(MSG_DEBUG,
  976. "%s[dbus]: ies must be an array of arrays of bytes",
  977. __func__);
  978. *reply = wpas_dbus_error_invalid_args(
  979. message, "Wrong IEs value type. Array required");
  980. return -1;
  981. }
  982. while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_ARRAY) {
  983. dbus_message_iter_recurse(&array_iter, &sub_array_iter);
  984. dbus_message_iter_get_fixed_array(&sub_array_iter, &val, &len);
  985. if (len == 0) {
  986. dbus_message_iter_next(&array_iter);
  987. continue;
  988. }
  989. nies = os_realloc(ies, ies_len + len);
  990. if (nies == NULL) {
  991. os_free(ies);
  992. *reply = wpas_dbus_error_no_memory(message);
  993. return -1;
  994. }
  995. ies = nies;
  996. os_memcpy(ies + ies_len, val, len);
  997. ies_len += len;
  998. dbus_message_iter_next(&array_iter);
  999. }
  1000. params->extra_ies = ies;
  1001. params->extra_ies_len = ies_len;
  1002. return 0;
  1003. }
  1004. static int wpas_dbus_get_scan_channels(DBusMessage *message,
  1005. DBusMessageIter *var,
  1006. struct wpa_driver_scan_params *params,
  1007. DBusMessage **reply)
  1008. {
  1009. DBusMessageIter array_iter, sub_array_iter;
  1010. int *freqs = NULL, *nfreqs;
  1011. int freqs_num = 0;
  1012. if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_ARRAY) {
  1013. wpa_printf(MSG_DEBUG,
  1014. "%s[dbus]: Channels must be an array of structs",
  1015. __func__);
  1016. *reply = wpas_dbus_error_invalid_args(
  1017. message,
  1018. "Wrong Channels value type. Array of structs required");
  1019. return -1;
  1020. }
  1021. dbus_message_iter_recurse(var, &array_iter);
  1022. if (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_STRUCT) {
  1023. wpa_printf(MSG_DEBUG,
  1024. "%s[dbus]: Channels must be an array of structs",
  1025. __func__);
  1026. *reply = wpas_dbus_error_invalid_args(
  1027. message,
  1028. "Wrong Channels value type. Array of structs required");
  1029. return -1;
  1030. }
  1031. while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_STRUCT)
  1032. {
  1033. int freq, width;
  1034. dbus_message_iter_recurse(&array_iter, &sub_array_iter);
  1035. if (dbus_message_iter_get_arg_type(&sub_array_iter) !=
  1036. DBUS_TYPE_UINT32) {
  1037. wpa_printf(MSG_DEBUG,
  1038. "%s[dbus]: Channel must by specified by struct of two UINT32s %c",
  1039. __func__,
  1040. dbus_message_iter_get_arg_type(
  1041. &sub_array_iter));
  1042. *reply = wpas_dbus_error_invalid_args(
  1043. message,
  1044. "Wrong Channel struct. Two UINT32s required");
  1045. os_free(freqs);
  1046. return -1;
  1047. }
  1048. dbus_message_iter_get_basic(&sub_array_iter, &freq);
  1049. if (!dbus_message_iter_next(&sub_array_iter) ||
  1050. dbus_message_iter_get_arg_type(&sub_array_iter) !=
  1051. DBUS_TYPE_UINT32) {
  1052. wpa_printf(MSG_DEBUG,
  1053. "%s[dbus]: Channel must by specified by struct of two UINT32s",
  1054. __func__);
  1055. *reply = wpas_dbus_error_invalid_args(
  1056. message,
  1057. "Wrong Channel struct. Two UINT32s required");
  1058. os_free(freqs);
  1059. return -1;
  1060. }
  1061. dbus_message_iter_get_basic(&sub_array_iter, &width);
  1062. #define FREQS_ALLOC_CHUNK 32
  1063. if (freqs_num % FREQS_ALLOC_CHUNK == 0) {
  1064. nfreqs = os_realloc_array(
  1065. freqs, freqs_num + FREQS_ALLOC_CHUNK,
  1066. sizeof(int));
  1067. if (nfreqs == NULL)
  1068. os_free(freqs);
  1069. freqs = nfreqs;
  1070. }
  1071. if (freqs == NULL) {
  1072. *reply = wpas_dbus_error_no_memory(message);
  1073. return -1;
  1074. }
  1075. freqs[freqs_num] = freq;
  1076. freqs_num++;
  1077. dbus_message_iter_next(&array_iter);
  1078. }
  1079. nfreqs = os_realloc_array(freqs, freqs_num + 1, sizeof(int));
  1080. if (nfreqs == NULL)
  1081. os_free(freqs);
  1082. freqs = nfreqs;
  1083. if (freqs == NULL) {
  1084. *reply = wpas_dbus_error_no_memory(message);
  1085. return -1;
  1086. }
  1087. freqs[freqs_num] = 0;
  1088. params->freqs = freqs;
  1089. return 0;
  1090. }
  1091. static int wpas_dbus_get_scan_allow_roam(DBusMessage *message,
  1092. DBusMessageIter *var,
  1093. dbus_bool_t *allow,
  1094. DBusMessage **reply)
  1095. {
  1096. if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_BOOLEAN) {
  1097. wpa_printf(MSG_DEBUG, "%s[dbus]: Type must be a boolean",
  1098. __func__);
  1099. *reply = wpas_dbus_error_invalid_args(
  1100. message, "Wrong Type value type. Boolean required");
  1101. return -1;
  1102. }
  1103. dbus_message_iter_get_basic(var, allow);
  1104. return 0;
  1105. }
  1106. /**
  1107. * wpas_dbus_handler_scan - Request a wireless scan on an interface
  1108. * @message: Pointer to incoming dbus message
  1109. * @wpa_s: wpa_supplicant structure for a network interface
  1110. * Returns: NULL indicating success or DBus error message on failure
  1111. *
  1112. * Handler function for "Scan" method call of a network device. Requests
  1113. * that wpa_supplicant perform a wireless scan as soon as possible
  1114. * on a particular wireless interface.
  1115. */
  1116. DBusMessage * wpas_dbus_handler_scan(DBusMessage *message,
  1117. struct wpa_supplicant *wpa_s)
  1118. {
  1119. DBusMessage *reply = NULL;
  1120. DBusMessageIter iter, dict_iter, entry_iter, variant_iter;
  1121. char *key = NULL, *type = NULL;
  1122. struct wpa_driver_scan_params params;
  1123. size_t i;
  1124. dbus_bool_t allow_roam = 1;
  1125. os_memset(&params, 0, sizeof(params));
  1126. dbus_message_iter_init(message, &iter);
  1127. dbus_message_iter_recurse(&iter, &dict_iter);
  1128. while (dbus_message_iter_get_arg_type(&dict_iter) ==
  1129. DBUS_TYPE_DICT_ENTRY) {
  1130. dbus_message_iter_recurse(&dict_iter, &entry_iter);
  1131. dbus_message_iter_get_basic(&entry_iter, &key);
  1132. dbus_message_iter_next(&entry_iter);
  1133. dbus_message_iter_recurse(&entry_iter, &variant_iter);
  1134. if (os_strcmp(key, "Type") == 0) {
  1135. if (wpas_dbus_get_scan_type(message, &variant_iter,
  1136. &type, &reply) < 0)
  1137. goto out;
  1138. } else if (os_strcmp(key, "SSIDs") == 0) {
  1139. if (wpas_dbus_get_scan_ssids(message, &variant_iter,
  1140. &params, &reply) < 0)
  1141. goto out;
  1142. } else if (os_strcmp(key, "IEs") == 0) {
  1143. if (wpas_dbus_get_scan_ies(message, &variant_iter,
  1144. &params, &reply) < 0)
  1145. goto out;
  1146. } else if (os_strcmp(key, "Channels") == 0) {
  1147. if (wpas_dbus_get_scan_channels(message, &variant_iter,
  1148. &params, &reply) < 0)
  1149. goto out;
  1150. } else if (os_strcmp(key, "AllowRoam") == 0) {
  1151. if (wpas_dbus_get_scan_allow_roam(message,
  1152. &variant_iter,
  1153. &allow_roam,
  1154. &reply) < 0)
  1155. goto out;
  1156. } else {
  1157. wpa_printf(MSG_DEBUG, "%s[dbus]: Unknown argument %s",
  1158. __func__, key);
  1159. reply = wpas_dbus_error_invalid_args(message, key);
  1160. goto out;
  1161. }
  1162. dbus_message_iter_next(&dict_iter);
  1163. }
  1164. if (!type) {
  1165. wpa_printf(MSG_DEBUG, "%s[dbus]: Scan type not specified",
  1166. __func__);
  1167. reply = wpas_dbus_error_invalid_args(message, key);
  1168. goto out;
  1169. }
  1170. if (os_strcmp(type, "passive") == 0) {
  1171. if (params.num_ssids || params.extra_ies_len) {
  1172. wpa_printf(MSG_DEBUG,
  1173. "%s[dbus]: SSIDs or IEs specified for passive scan.",
  1174. __func__);
  1175. reply = wpas_dbus_error_invalid_args(
  1176. message,
  1177. "You can specify only Channels in passive scan");
  1178. goto out;
  1179. } else {
  1180. if (wpa_s->sched_scanning) {
  1181. wpa_printf(MSG_DEBUG,
  1182. "%s[dbus]: Stop ongoing sched_scan to allow requested scan to proceed",
  1183. __func__);
  1184. wpa_supplicant_cancel_sched_scan(wpa_s);
  1185. }
  1186. if (params.freqs && params.freqs[0]) {
  1187. wpa_s->last_scan_req = MANUAL_SCAN_REQ;
  1188. if (wpa_supplicant_trigger_scan(wpa_s,
  1189. &params)) {
  1190. reply = wpas_dbus_error_scan_error(
  1191. message,
  1192. "Scan request rejected");
  1193. }
  1194. } else {
  1195. wpa_s->scan_req = MANUAL_SCAN_REQ;
  1196. wpa_supplicant_req_scan(wpa_s, 0, 0);
  1197. }
  1198. }
  1199. } else if (os_strcmp(type, "active") == 0) {
  1200. if (!params.num_ssids) {
  1201. /* Add wildcard ssid */
  1202. params.num_ssids++;
  1203. }
  1204. #ifdef CONFIG_AUTOSCAN
  1205. autoscan_deinit(wpa_s);
  1206. #endif /* CONFIG_AUTOSCAN */
  1207. if (wpa_s->sched_scanning) {
  1208. wpa_printf(MSG_DEBUG,
  1209. "%s[dbus]: Stop ongoing sched_scan to allow requested scan to proceed",
  1210. __func__);
  1211. wpa_supplicant_cancel_sched_scan(wpa_s);
  1212. }
  1213. wpa_s->last_scan_req = MANUAL_SCAN_REQ;
  1214. if (wpa_supplicant_trigger_scan(wpa_s, &params)) {
  1215. reply = wpas_dbus_error_scan_error(
  1216. message, "Scan request rejected");
  1217. }
  1218. } else {
  1219. wpa_printf(MSG_DEBUG, "%s[dbus]: Unknown scan type: %s",
  1220. __func__, type);
  1221. reply = wpas_dbus_error_invalid_args(message,
  1222. "Wrong scan type");
  1223. goto out;
  1224. }
  1225. if (!allow_roam)
  1226. wpa_s->scan_res_handler = scan_only_handler;
  1227. out:
  1228. for (i = 0; i < WPAS_MAX_SCAN_SSIDS; i++)
  1229. os_free((u8 *) params.ssids[i].ssid);
  1230. os_free((u8 *) params.extra_ies);
  1231. os_free(params.freqs);
  1232. return reply;
  1233. }
  1234. /**
  1235. * wpas_dbus_handler_signal_poll - Request immediate signal properties
  1236. * @message: Pointer to incoming dbus message
  1237. * @wpa_s: wpa_supplicant structure for a network interface
  1238. * Returns: NULL indicating success or DBus error message on failure
  1239. *
  1240. * Handler function for "SignalPoll" method call of a network device. Requests
  1241. * that wpa_supplicant read signal properties like RSSI, noise, and link
  1242. * speed and return them.
  1243. */
  1244. DBusMessage * wpas_dbus_handler_signal_poll(DBusMessage *message,
  1245. struct wpa_supplicant *wpa_s)
  1246. {
  1247. struct wpa_signal_info si;
  1248. DBusMessage *reply = NULL;
  1249. DBusMessageIter iter, iter_dict, variant_iter;
  1250. int ret;
  1251. ret = wpa_drv_signal_poll(wpa_s, &si);
  1252. if (ret) {
  1253. return dbus_message_new_error(message, DBUS_ERROR_FAILED,
  1254. "Failed to read signal");
  1255. }
  1256. reply = dbus_message_new_method_return(message);
  1257. if (reply == NULL)
  1258. goto nomem;
  1259. dbus_message_iter_init_append(reply, &iter);
  1260. if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
  1261. "a{sv}", &variant_iter) ||
  1262. !wpa_dbus_dict_open_write(&variant_iter, &iter_dict) ||
  1263. !wpa_dbus_dict_append_int32(&iter_dict, "rssi",
  1264. si.current_signal) ||
  1265. !wpa_dbus_dict_append_int32(&iter_dict, "linkspeed",
  1266. si.current_txrate / 1000) ||
  1267. !wpa_dbus_dict_append_int32(&iter_dict, "noise",
  1268. si.current_noise) ||
  1269. !wpa_dbus_dict_append_uint32(&iter_dict, "frequency",
  1270. si.frequency) ||
  1271. (si.chanwidth != CHAN_WIDTH_UNKNOWN &&
  1272. !wpa_dbus_dict_append_string(
  1273. &iter_dict, "width",
  1274. channel_width_to_string(si.chanwidth))) ||
  1275. (si.center_frq1 > 0 && si.center_frq2 > 0 &&
  1276. (!wpa_dbus_dict_append_int32(&iter_dict, "center-frq1",
  1277. si.center_frq1) ||
  1278. !wpa_dbus_dict_append_int32(&iter_dict, "center-frq2",
  1279. si.center_frq2))) ||
  1280. (si.avg_signal &&
  1281. !wpa_dbus_dict_append_int32(&iter_dict, "avg-rssi",
  1282. si.avg_signal)) ||
  1283. !wpa_dbus_dict_close_write(&variant_iter, &iter_dict) ||
  1284. !dbus_message_iter_close_container(&iter, &variant_iter))
  1285. goto nomem;
  1286. return reply;
  1287. nomem:
  1288. if (reply)
  1289. dbus_message_unref(reply);
  1290. return wpas_dbus_error_no_memory(message);
  1291. }
  1292. /*
  1293. * wpas_dbus_handler_disconnect - Terminate the current connection
  1294. * @message: Pointer to incoming dbus message
  1295. * @wpa_s: wpa_supplicant structure for a network interface
  1296. * Returns: NotConnected DBus error message if already not connected
  1297. * or NULL otherwise.
  1298. *
  1299. * Handler function for "Disconnect" method call of network interface.
  1300. */
  1301. DBusMessage * wpas_dbus_handler_disconnect(DBusMessage *message,
  1302. struct wpa_supplicant *wpa_s)
  1303. {
  1304. if (wpa_s->current_ssid != NULL) {
  1305. wpas_request_disconnection(wpa_s);
  1306. return NULL;
  1307. }
  1308. return dbus_message_new_error(message, WPAS_DBUS_ERROR_NOT_CONNECTED,
  1309. "This interface is not connected");
  1310. }
  1311. /**
  1312. * wpas_dbus_new_iface_add_network - Add a new configured network
  1313. * @message: Pointer to incoming dbus message
  1314. * @wpa_s: wpa_supplicant structure for a network interface
  1315. * Returns: A dbus message containing the object path of the new network
  1316. *
  1317. * Handler function for "AddNetwork" method call of a network interface.
  1318. */
  1319. DBusMessage * wpas_dbus_handler_add_network(DBusMessage *message,
  1320. struct wpa_supplicant *wpa_s)
  1321. {
  1322. DBusMessage *reply = NULL;
  1323. DBusMessageIter iter;
  1324. struct wpa_ssid *ssid = NULL;
  1325. char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *path = path_buf;
  1326. DBusError error;
  1327. dbus_message_iter_init(message, &iter);
  1328. if (wpa_s->dbus_new_path)
  1329. ssid = wpa_supplicant_add_network(wpa_s);
  1330. if (ssid == NULL) {
  1331. wpa_printf(MSG_ERROR, "%s[dbus]: can't add new interface.",
  1332. __func__);
  1333. reply = wpas_dbus_error_unknown_error(
  1334. message,
  1335. "wpa_supplicant could not add a network on this interface.");
  1336. goto err;
  1337. }
  1338. dbus_error_init(&error);
  1339. if (!set_network_properties(wpa_s, ssid, &iter, &error)) {
  1340. wpa_printf(MSG_DEBUG,
  1341. "%s[dbus]: control interface couldn't set network properties",
  1342. __func__);
  1343. reply = wpas_dbus_reply_new_from_error(message, &error,
  1344. DBUS_ERROR_INVALID_ARGS,
  1345. "Failed to add network");
  1346. dbus_error_free(&error);
  1347. goto err;
  1348. }
  1349. /* Construct the object path for this network. */
  1350. os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
  1351. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
  1352. wpa_s->dbus_new_path, ssid->id);
  1353. reply = dbus_message_new_method_return(message);
  1354. if (reply == NULL) {
  1355. reply = wpas_dbus_error_no_memory(message);
  1356. goto err;
  1357. }
  1358. if (!dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path,
  1359. DBUS_TYPE_INVALID)) {
  1360. dbus_message_unref(reply);
  1361. reply = wpas_dbus_error_no_memory(message);
  1362. goto err;
  1363. }
  1364. return reply;
  1365. err:
  1366. if (ssid) {
  1367. wpas_notify_network_removed(wpa_s, ssid);
  1368. wpa_config_remove_network(wpa_s->conf, ssid->id);
  1369. }
  1370. return reply;
  1371. }
  1372. /**
  1373. * wpas_dbus_handler_reassociate - Reassociate
  1374. * @message: Pointer to incoming dbus message
  1375. * @wpa_s: wpa_supplicant structure for a network interface
  1376. * Returns: InterfaceDisabled DBus error message if disabled
  1377. * or NULL otherwise.
  1378. *
  1379. * Handler function for "Reassociate" method call of network interface.
  1380. */
  1381. DBusMessage * wpas_dbus_handler_reassociate(DBusMessage *message,
  1382. struct wpa_supplicant *wpa_s)
  1383. {
  1384. if (wpa_s->wpa_state != WPA_INTERFACE_DISABLED) {
  1385. wpas_request_connection(wpa_s);
  1386. return NULL;
  1387. }
  1388. return dbus_message_new_error(message, WPAS_DBUS_ERROR_IFACE_DISABLED,
  1389. "This interface is disabled");
  1390. }
  1391. /**
  1392. * wpas_dbus_handler_expect_disconnect - ExpectDisconnect
  1393. * @message: Pointer to incoming dbus message
  1394. * @global: %wpa_supplicant global data structure
  1395. * Returns: NULL
  1396. *
  1397. * Handler function for notifying system there will be a expected disconnect.
  1398. * This will prevent wpa_supplicant from adding blacklists upon next disconnect..
  1399. */
  1400. DBusMessage * wpas_dbus_handler_expect_disconnect(DBusMessage *message,
  1401. struct wpa_global *global)
  1402. {
  1403. struct wpa_supplicant *wpa_s = global->ifaces;
  1404. for (; wpa_s; wpa_s = wpa_s->next)
  1405. if (wpa_s->wpa_state >= WPA_ASSOCIATED)
  1406. wpa_s->own_disconnect_req = 1;
  1407. return NULL;
  1408. }
  1409. /**
  1410. * wpas_dbus_handler_reattach - Reattach to current AP
  1411. * @message: Pointer to incoming dbus message
  1412. * @wpa_s: wpa_supplicant structure for a network interface
  1413. * Returns: NotConnected DBus error message if not connected
  1414. * or NULL otherwise.
  1415. *
  1416. * Handler function for "Reattach" method call of network interface.
  1417. */
  1418. DBusMessage * wpas_dbus_handler_reattach(DBusMessage *message,
  1419. struct wpa_supplicant *wpa_s)
  1420. {
  1421. if (wpa_s->current_ssid != NULL) {
  1422. wpa_s->reattach = 1;
  1423. wpas_request_connection(wpa_s);
  1424. return NULL;
  1425. }
  1426. return dbus_message_new_error(message, WPAS_DBUS_ERROR_NOT_CONNECTED,
  1427. "This interface is not connected");
  1428. }
  1429. /**
  1430. * wpas_dbus_handler_reconnect - Reconnect if disconnected
  1431. * @message: Pointer to incoming dbus message
  1432. * @wpa_s: wpa_supplicant structure for a network interface
  1433. * Returns: InterfaceDisabled DBus error message if disabled
  1434. * or NULL otherwise.
  1435. *
  1436. * Handler function for "Reconnect" method call of network interface.
  1437. */
  1438. DBusMessage * wpas_dbus_handler_reconnect(DBusMessage *message,
  1439. struct wpa_supplicant *wpa_s)
  1440. {
  1441. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
  1442. return dbus_message_new_error(message,
  1443. WPAS_DBUS_ERROR_IFACE_DISABLED,
  1444. "This interface is disabled");
  1445. }
  1446. if (wpa_s->disconnected)
  1447. wpas_request_connection(wpa_s);
  1448. return NULL;
  1449. }
  1450. /**
  1451. * wpas_dbus_handler_remove_network - Remove a configured network
  1452. * @message: Pointer to incoming dbus message
  1453. * @wpa_s: wpa_supplicant structure for a network interface
  1454. * Returns: NULL on success or dbus error on failure
  1455. *
  1456. * Handler function for "RemoveNetwork" method call of a network interface.
  1457. */
  1458. DBusMessage * wpas_dbus_handler_remove_network(DBusMessage *message,
  1459. struct wpa_supplicant *wpa_s)
  1460. {
  1461. DBusMessage *reply = NULL;
  1462. const char *op;
  1463. char *iface, *net_id;
  1464. int id;
  1465. int result;
  1466. dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &op,
  1467. DBUS_TYPE_INVALID);
  1468. /* Extract the network ID and ensure the network */
  1469. /* is actually a child of this interface */
  1470. iface = wpas_dbus_new_decompose_object_path(op,
  1471. WPAS_DBUS_NEW_NETWORKS_PART,
  1472. &net_id);
  1473. if (iface == NULL || net_id == NULL || !wpa_s->dbus_new_path ||
  1474. os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
  1475. reply = wpas_dbus_error_invalid_args(message, op);
  1476. goto out;
  1477. }
  1478. errno = 0;
  1479. id = strtoul(net_id, NULL, 10);
  1480. if (errno != 0) {
  1481. reply = wpas_dbus_error_invalid_args(message, op);
  1482. goto out;
  1483. }
  1484. result = wpa_supplicant_remove_network(wpa_s, id);
  1485. if (result == -1) {
  1486. reply = wpas_dbus_error_network_unknown(message);
  1487. goto out;
  1488. }
  1489. if (result == -2) {
  1490. wpa_printf(MSG_ERROR,
  1491. "%s[dbus]: error occurred when removing network %d",
  1492. __func__, id);
  1493. reply = wpas_dbus_error_unknown_error(
  1494. message,
  1495. "error removing the specified network on is interface.");
  1496. goto out;
  1497. }
  1498. out:
  1499. os_free(iface);
  1500. return reply;
  1501. }
  1502. static void remove_network(void *arg, struct wpa_ssid *ssid)
  1503. {
  1504. struct wpa_supplicant *wpa_s = arg;
  1505. wpas_notify_network_removed(wpa_s, ssid);
  1506. if (wpa_config_remove_network(wpa_s->conf, ssid->id) < 0) {
  1507. wpa_printf(MSG_ERROR,
  1508. "%s[dbus]: error occurred when removing network %d",
  1509. __func__, ssid->id);
  1510. return;
  1511. }
  1512. if (ssid == wpa_s->current_ssid)
  1513. wpa_supplicant_deauthenticate(wpa_s,
  1514. WLAN_REASON_DEAUTH_LEAVING);
  1515. }
  1516. /**
  1517. * wpas_dbus_handler_remove_all_networks - Remove all configured networks
  1518. * @message: Pointer to incoming dbus message
  1519. * @wpa_s: wpa_supplicant structure for a network interface
  1520. * Returns: NULL on success or dbus error on failure
  1521. *
  1522. * Handler function for "RemoveAllNetworks" method call of a network interface.
  1523. */
  1524. DBusMessage * wpas_dbus_handler_remove_all_networks(
  1525. DBusMessage *message, struct wpa_supplicant *wpa_s)
  1526. {
  1527. if (wpa_s->sched_scanning)
  1528. wpa_supplicant_cancel_sched_scan(wpa_s);
  1529. /* NB: could check for failure and return an error */
  1530. wpa_config_foreach_network(wpa_s->conf, remove_network, wpa_s);
  1531. return NULL;
  1532. }
  1533. /**
  1534. * wpas_dbus_handler_select_network - Attempt association with a network
  1535. * @message: Pointer to incoming dbus message
  1536. * @wpa_s: wpa_supplicant structure for a network interface
  1537. * Returns: NULL on success or dbus error on failure
  1538. *
  1539. * Handler function for "SelectNetwork" method call of network interface.
  1540. */
  1541. DBusMessage * wpas_dbus_handler_select_network(DBusMessage *message,
  1542. struct wpa_supplicant *wpa_s)
  1543. {
  1544. DBusMessage *reply = NULL;
  1545. const char *op;
  1546. char *iface, *net_id;
  1547. int id;
  1548. struct wpa_ssid *ssid;
  1549. dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &op,
  1550. DBUS_TYPE_INVALID);
  1551. /* Extract the network ID and ensure the network */
  1552. /* is actually a child of this interface */
  1553. iface = wpas_dbus_new_decompose_object_path(op,
  1554. WPAS_DBUS_NEW_NETWORKS_PART,
  1555. &net_id);
  1556. if (iface == NULL || net_id == NULL || !wpa_s->dbus_new_path ||
  1557. os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
  1558. reply = wpas_dbus_error_invalid_args(message, op);
  1559. goto out;
  1560. }
  1561. errno = 0;
  1562. id = strtoul(net_id, NULL, 10);
  1563. if (errno != 0) {
  1564. reply = wpas_dbus_error_invalid_args(message, op);
  1565. goto out;
  1566. }
  1567. ssid = wpa_config_get_network(wpa_s->conf, id);
  1568. if (ssid == NULL) {
  1569. reply = wpas_dbus_error_network_unknown(message);
  1570. goto out;
  1571. }
  1572. /* Finally, associate with the network */
  1573. wpa_supplicant_select_network(wpa_s, ssid);
  1574. out:
  1575. os_free(iface);
  1576. return reply;
  1577. }
  1578. /**
  1579. * wpas_dbus_handler_network_reply - Reply to a NetworkRequest signal
  1580. * @message: Pointer to incoming dbus message
  1581. * @wpa_s: wpa_supplicant structure for a network interface
  1582. * Returns: NULL on success or dbus error on failure
  1583. *
  1584. * Handler function for "NetworkReply" method call of network interface.
  1585. */
  1586. DBusMessage * wpas_dbus_handler_network_reply(DBusMessage *message,
  1587. struct wpa_supplicant *wpa_s)
  1588. {
  1589. #ifdef IEEE8021X_EAPOL
  1590. DBusMessage *reply = NULL;
  1591. const char *op, *field, *value;
  1592. char *iface, *net_id;
  1593. int id;
  1594. struct wpa_ssid *ssid;
  1595. if (!dbus_message_get_args(message, NULL,
  1596. DBUS_TYPE_OBJECT_PATH, &op,
  1597. DBUS_TYPE_STRING, &field,
  1598. DBUS_TYPE_STRING, &value,
  1599. DBUS_TYPE_INVALID))
  1600. return wpas_dbus_error_invalid_args(message, NULL);
  1601. /* Extract the network ID and ensure the network */
  1602. /* is actually a child of this interface */
  1603. iface = wpas_dbus_new_decompose_object_path(op,
  1604. WPAS_DBUS_NEW_NETWORKS_PART,
  1605. &net_id);
  1606. if (iface == NULL || net_id == NULL || !wpa_s->dbus_new_path ||
  1607. os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
  1608. reply = wpas_dbus_error_invalid_args(message, op);
  1609. goto out;
  1610. }
  1611. errno = 0;
  1612. id = strtoul(net_id, NULL, 10);
  1613. if (errno != 0) {
  1614. reply = wpas_dbus_error_invalid_args(message, net_id);
  1615. goto out;
  1616. }
  1617. ssid = wpa_config_get_network(wpa_s->conf, id);
  1618. if (ssid == NULL) {
  1619. reply = wpas_dbus_error_network_unknown(message);
  1620. goto out;
  1621. }
  1622. if (wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid,
  1623. field, value) < 0)
  1624. reply = wpas_dbus_error_invalid_args(message, field);
  1625. else {
  1626. /* Tell EAP to retry immediately */
  1627. eapol_sm_notify_ctrl_response(wpa_s->eapol);
  1628. }
  1629. out:
  1630. os_free(iface);
  1631. return reply;
  1632. #else /* IEEE8021X_EAPOL */
  1633. wpa_printf(MSG_DEBUG, "dbus: 802.1X not included");
  1634. return wpas_dbus_error_unknown_error(message, "802.1X not included");
  1635. #endif /* IEEE8021X_EAPOL */
  1636. }
  1637. #ifndef CONFIG_NO_CONFIG_BLOBS
  1638. /**
  1639. * wpas_dbus_handler_add_blob - Store named binary blob (ie, for certificates)
  1640. * @message: Pointer to incoming dbus message
  1641. * @wpa_s: %wpa_supplicant data structure
  1642. * Returns: A dbus message containing an error on failure or NULL on success
  1643. *
  1644. * Asks wpa_supplicant to internally store a binary blobs.
  1645. */
  1646. DBusMessage * wpas_dbus_handler_add_blob(DBusMessage *message,
  1647. struct wpa_supplicant *wpa_s)
  1648. {
  1649. DBusMessage *reply = NULL;
  1650. DBusMessageIter iter, array_iter;
  1651. char *blob_name;
  1652. u8 *blob_data;
  1653. int blob_len;
  1654. struct wpa_config_blob *blob = NULL;
  1655. dbus_message_iter_init(message, &iter);
  1656. dbus_message_iter_get_basic(&iter, &blob_name);
  1657. if (wpa_config_get_blob(wpa_s->conf, blob_name)) {
  1658. return dbus_message_new_error(message,
  1659. WPAS_DBUS_ERROR_BLOB_EXISTS,
  1660. NULL);
  1661. }
  1662. dbus_message_iter_next(&iter);
  1663. dbus_message_iter_recurse(&iter, &array_iter);
  1664. dbus_message_iter_get_fixed_array(&array_iter, &blob_data, &blob_len);
  1665. blob = os_zalloc(sizeof(*blob));
  1666. if (!blob) {
  1667. reply = wpas_dbus_error_no_memory(message);
  1668. goto err;
  1669. }
  1670. blob->data = os_malloc(blob_len);
  1671. blob->name = os_strdup(blob_name);
  1672. if (!blob->data || !blob->name) {
  1673. reply = wpas_dbus_error_no_memory(message);
  1674. goto err;
  1675. }
  1676. os_memcpy(blob->data, blob_data, blob_len);
  1677. blob->len = blob_len;
  1678. wpa_config_set_blob(wpa_s->conf, blob);
  1679. wpas_notify_blob_added(wpa_s, blob->name);
  1680. return reply;
  1681. err:
  1682. if (blob) {
  1683. os_free(blob->name);
  1684. os_free(blob->data);
  1685. os_free(blob);
  1686. }
  1687. return reply;
  1688. }
  1689. /**
  1690. * wpas_dbus_handler_get_blob - Get named binary blob (ie, for certificates)
  1691. * @message: Pointer to incoming dbus message
  1692. * @wpa_s: %wpa_supplicant data structure
  1693. * Returns: A dbus message containing array of bytes (blob)
  1694. *
  1695. * Gets one wpa_supplicant's binary blobs.
  1696. */
  1697. DBusMessage * wpas_dbus_handler_get_blob(DBusMessage *message,
  1698. struct wpa_supplicant *wpa_s)
  1699. {
  1700. DBusMessage *reply = NULL;
  1701. DBusMessageIter iter, array_iter;
  1702. char *blob_name;
  1703. const struct wpa_config_blob *blob;
  1704. dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &blob_name,
  1705. DBUS_TYPE_INVALID);
  1706. blob = wpa_config_get_blob(wpa_s->conf, blob_name);
  1707. if (!blob) {
  1708. return dbus_message_new_error(message,
  1709. WPAS_DBUS_ERROR_BLOB_UNKNOWN,
  1710. "Blob id not set");
  1711. }
  1712. reply = dbus_message_new_method_return(message);
  1713. if (!reply)
  1714. return wpas_dbus_error_no_memory(message);
  1715. dbus_message_iter_init_append(reply, &iter);
  1716. if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
  1717. DBUS_TYPE_BYTE_AS_STRING,
  1718. &array_iter) ||
  1719. !dbus_message_iter_append_fixed_array(&array_iter, DBUS_TYPE_BYTE,
  1720. &(blob->data), blob->len) ||
  1721. !dbus_message_iter_close_container(&iter, &array_iter)) {
  1722. dbus_message_unref(reply);
  1723. reply = wpas_dbus_error_no_memory(message);
  1724. }
  1725. return reply;
  1726. }
  1727. /**
  1728. * wpas_remove_handler_remove_blob - Remove named binary blob
  1729. * @message: Pointer to incoming dbus message
  1730. * @wpa_s: %wpa_supplicant data structure
  1731. * Returns: NULL on success or dbus error
  1732. *
  1733. * Asks wpa_supplicant to internally remove a binary blobs.
  1734. */
  1735. DBusMessage * wpas_dbus_handler_remove_blob(DBusMessage *message,
  1736. struct wpa_supplicant *wpa_s)
  1737. {
  1738. DBusMessage *reply = NULL;
  1739. char *blob_name;
  1740. dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &blob_name,
  1741. DBUS_TYPE_INVALID);
  1742. if (wpa_config_remove_blob(wpa_s->conf, blob_name)) {
  1743. return dbus_message_new_error(message,
  1744. WPAS_DBUS_ERROR_BLOB_UNKNOWN,
  1745. "Blob id not set");
  1746. }
  1747. wpas_notify_blob_removed(wpa_s, blob_name);
  1748. return reply;
  1749. }
  1750. #endif /* CONFIG_NO_CONFIG_BLOBS */
  1751. /*
  1752. * wpas_dbus_handler_flush_bss - Flush the BSS cache
  1753. * @message: Pointer to incoming dbus message
  1754. * @wpa_s: wpa_supplicant structure for a network interface
  1755. * Returns: NULL
  1756. *
  1757. * Handler function for "FlushBSS" method call of network interface.
  1758. */
  1759. DBusMessage * wpas_dbus_handler_flush_bss(DBusMessage *message,
  1760. struct wpa_supplicant *wpa_s)
  1761. {
  1762. dbus_uint32_t age;
  1763. dbus_message_get_args(message, NULL, DBUS_TYPE_UINT32, &age,
  1764. DBUS_TYPE_INVALID);
  1765. if (age == 0)
  1766. wpa_bss_flush(wpa_s);
  1767. else
  1768. wpa_bss_flush_by_age(wpa_s, age);
  1769. return NULL;
  1770. }
  1771. #ifdef CONFIG_AUTOSCAN
  1772. /**
  1773. * wpas_dbus_handler_autoscan - Set autoscan parameters for the interface
  1774. * @message: Pointer to incoming dbus message
  1775. * @wpa_s: wpa_supplicant structure for a network interface
  1776. * Returns: NULL
  1777. *
  1778. * Handler function for "AutoScan" method call of network interface.
  1779. */
  1780. DBusMessage * wpas_dbus_handler_autoscan(DBusMessage *message,
  1781. struct wpa_supplicant *wpa_s)
  1782. {
  1783. DBusMessage *reply = NULL;
  1784. enum wpa_states state = wpa_s->wpa_state;
  1785. char *arg;
  1786. dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg,
  1787. DBUS_TYPE_INVALID);
  1788. if (arg != NULL && os_strlen(arg) > 0) {
  1789. char *tmp;
  1790. tmp = os_strdup(arg);
  1791. if (tmp == NULL) {
  1792. reply = wpas_dbus_error_no_memory(message);
  1793. } else {
  1794. os_free(wpa_s->conf->autoscan);
  1795. wpa_s->conf->autoscan = tmp;
  1796. if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
  1797. autoscan_init(wpa_s, 1);
  1798. else if (state == WPA_SCANNING)
  1799. wpa_supplicant_reinit_autoscan(wpa_s);
  1800. }
  1801. } else if (arg != NULL && os_strlen(arg) == 0) {
  1802. os_free(wpa_s->conf->autoscan);
  1803. wpa_s->conf->autoscan = NULL;
  1804. autoscan_deinit(wpa_s);
  1805. } else
  1806. reply = dbus_message_new_error(message,
  1807. DBUS_ERROR_INVALID_ARGS,
  1808. NULL);
  1809. return reply;
  1810. }
  1811. #endif /* CONFIG_AUTOSCAN */
  1812. /*
  1813. * wpas_dbus_handler_eap_logoff - IEEE 802.1X EAPOL state machine logoff
  1814. * @message: Pointer to incoming dbus message
  1815. * @wpa_s: wpa_supplicant structure for a network interface
  1816. * Returns: NULL
  1817. *
  1818. * Handler function for "EAPLogoff" method call of network interface.
  1819. */
  1820. DBusMessage * wpas_dbus_handler_eap_logoff(DBusMessage *message,
  1821. struct wpa_supplicant *wpa_s)
  1822. {
  1823. eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
  1824. return NULL;
  1825. }
  1826. /*
  1827. * wpas_dbus_handler_eap_logon - IEEE 802.1X EAPOL state machine logon
  1828. * @message: Pointer to incoming dbus message
  1829. * @wpa_s: wpa_supplicant structure for a network interface
  1830. * Returns: NULL
  1831. *
  1832. * Handler function for "EAPLogin" method call of network interface.
  1833. */
  1834. DBusMessage * wpas_dbus_handler_eap_logon(DBusMessage *message,
  1835. struct wpa_supplicant *wpa_s)
  1836. {
  1837. eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
  1838. return NULL;
  1839. }
  1840. #ifdef CONFIG_TDLS
  1841. static int get_peer_hwaddr_helper(DBusMessage *message, const char *func_name,
  1842. u8 *peer_address, DBusMessage **error)
  1843. {
  1844. const char *peer_string;
  1845. *error = NULL;
  1846. if (!dbus_message_get_args(message, NULL,
  1847. DBUS_TYPE_STRING, &peer_string,
  1848. DBUS_TYPE_INVALID)) {
  1849. *error = wpas_dbus_error_invalid_args(message, NULL);
  1850. return -1;
  1851. }
  1852. if (hwaddr_aton(peer_string, peer_address)) {
  1853. wpa_printf(MSG_DEBUG, "%s: invalid address '%s'",
  1854. func_name, peer_string);
  1855. *error = wpas_dbus_error_invalid_args(
  1856. message, "Invalid hardware address format");
  1857. return -1;
  1858. }
  1859. return 0;
  1860. }
  1861. /*
  1862. * wpas_dbus_handler_tdls_discover - Discover TDLS peer
  1863. * @message: Pointer to incoming dbus message
  1864. * @wpa_s: wpa_supplicant structure for a network interface
  1865. * Returns: NULL indicating success or DBus error message on failure
  1866. *
  1867. * Handler function for "TDLSDiscover" method call of network interface.
  1868. */
  1869. DBusMessage * wpas_dbus_handler_tdls_discover(DBusMessage *message,
  1870. struct wpa_supplicant *wpa_s)
  1871. {
  1872. u8 peer[ETH_ALEN];
  1873. DBusMessage *error_reply;
  1874. int ret;
  1875. if (get_peer_hwaddr_helper(message, __func__, peer, &error_reply) < 0)
  1876. return error_reply;
  1877. wpa_printf(MSG_DEBUG, "DBUS TDLS_DISCOVER " MACSTR, MAC2STR(peer));
  1878. if (wpa_tdls_is_external_setup(wpa_s->wpa))
  1879. ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
  1880. else
  1881. ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
  1882. if (ret) {
  1883. return wpas_dbus_error_unknown_error(
  1884. message, "error performing TDLS discovery");
  1885. }
  1886. return NULL;
  1887. }
  1888. /*
  1889. * wpas_dbus_handler_tdls_setup - Setup TDLS session
  1890. * @message: Pointer to incoming dbus message
  1891. * @wpa_s: wpa_supplicant structure for a network interface
  1892. * Returns: NULL indicating success or DBus error message on failure
  1893. *
  1894. * Handler function for "TDLSSetup" method call of network interface.
  1895. */
  1896. DBusMessage * wpas_dbus_handler_tdls_setup(DBusMessage *message,
  1897. struct wpa_supplicant *wpa_s)
  1898. {
  1899. u8 peer[ETH_ALEN];
  1900. DBusMessage *error_reply;
  1901. int ret;
  1902. if (get_peer_hwaddr_helper(message, __func__, peer, &error_reply) < 0)
  1903. return error_reply;
  1904. wpa_printf(MSG_DEBUG, "DBUS TDLS_SETUP " MACSTR, MAC2STR(peer));
  1905. wpa_tdls_remove(wpa_s->wpa, peer);
  1906. if (wpa_tdls_is_external_setup(wpa_s->wpa))
  1907. ret = wpa_tdls_start(wpa_s->wpa, peer);
  1908. else
  1909. ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
  1910. if (ret) {
  1911. return wpas_dbus_error_unknown_error(
  1912. message, "error performing TDLS setup");
  1913. }
  1914. return NULL;
  1915. }
  1916. /*
  1917. * wpas_dbus_handler_tdls_status - Return TDLS session status
  1918. * @message: Pointer to incoming dbus message
  1919. * @wpa_s: wpa_supplicant structure for a network interface
  1920. * Returns: A string representing the state of the link to this TDLS peer
  1921. *
  1922. * Handler function for "TDLSStatus" method call of network interface.
  1923. */
  1924. DBusMessage * wpas_dbus_handler_tdls_status(DBusMessage *message,
  1925. struct wpa_supplicant *wpa_s)
  1926. {
  1927. u8 peer[ETH_ALEN];
  1928. DBusMessage *reply;
  1929. const char *tdls_status;
  1930. if (get_peer_hwaddr_helper(message, __func__, peer, &reply) < 0)
  1931. return reply;
  1932. wpa_printf(MSG_DEBUG, "DBUS TDLS_STATUS " MACSTR, MAC2STR(peer));
  1933. tdls_status = wpa_tdls_get_link_status(wpa_s->wpa, peer);
  1934. reply = dbus_message_new_method_return(message);
  1935. dbus_message_append_args(reply, DBUS_TYPE_STRING,
  1936. &tdls_status, DBUS_TYPE_INVALID);
  1937. return reply;
  1938. }
  1939. /*
  1940. * wpas_dbus_handler_tdls_teardown - Teardown TDLS session
  1941. * @message: Pointer to incoming dbus message
  1942. * @wpa_s: wpa_supplicant structure for a network interface
  1943. * Returns: NULL indicating success or DBus error message on failure
  1944. *
  1945. * Handler function for "TDLSTeardown" method call of network interface.
  1946. */
  1947. DBusMessage * wpas_dbus_handler_tdls_teardown(DBusMessage *message,
  1948. struct wpa_supplicant *wpa_s)
  1949. {
  1950. u8 peer[ETH_ALEN];
  1951. DBusMessage *error_reply;
  1952. int ret;
  1953. if (get_peer_hwaddr_helper(message, __func__, peer, &error_reply) < 0)
  1954. return error_reply;
  1955. wpa_printf(MSG_DEBUG, "DBUS TDLS_TEARDOWN " MACSTR, MAC2STR(peer));
  1956. if (wpa_tdls_is_external_setup(wpa_s->wpa))
  1957. ret = wpa_tdls_teardown_link(
  1958. wpa_s->wpa, peer,
  1959. WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
  1960. else
  1961. ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
  1962. if (ret) {
  1963. return wpas_dbus_error_unknown_error(
  1964. message, "error performing TDLS teardown");
  1965. }
  1966. return NULL;
  1967. }
  1968. #endif /* CONFIG_TDLS */
  1969. #ifndef CONFIG_NO_CONFIG_WRITE
  1970. /**
  1971. * wpas_dbus_handler_save_config - Save configuration to configuration file
  1972. * @message: Pointer to incoming dbus message
  1973. * @wpa_s: wpa_supplicant structure for a network interface
  1974. * Returns: NULL on Success, Otherwise errror message
  1975. *
  1976. * Handler function for "SaveConfig" method call of network interface.
  1977. */
  1978. DBusMessage * wpas_dbus_handler_save_config(DBusMessage *message,
  1979. struct wpa_supplicant *wpa_s)
  1980. {
  1981. int ret;
  1982. if (!wpa_s->conf->update_config) {
  1983. return wpas_dbus_error_unknown_error(
  1984. message,
  1985. "Not allowed to update configuration (update_config=0)");
  1986. }
  1987. ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
  1988. if (ret)
  1989. return wpas_dbus_error_unknown_error(
  1990. message, "Failed to update configuration");
  1991. return NULL;
  1992. }
  1993. #endif /* CONFIG_NO_CONFIG_WRITE */
  1994. /**
  1995. * wpas_dbus_handler_set_pkcs11_engine_and_module_path - Set PKCS #11 engine and module path
  1996. * @message: Pointer to incoming dbus message
  1997. * @wpa_s: %wpa_supplicant data structure
  1998. * Returns: A dbus message containing an error on failure or NULL on success
  1999. *
  2000. * Sets the PKCS #11 engine and module path.
  2001. */
  2002. DBusMessage * wpas_dbus_handler_set_pkcs11_engine_and_module_path(
  2003. DBusMessage *message, struct wpa_supplicant *wpa_s)
  2004. {
  2005. DBusMessageIter iter;
  2006. char *value = NULL;
  2007. char *pkcs11_engine_path = NULL;
  2008. char *pkcs11_module_path = NULL;
  2009. dbus_message_iter_init(message, &iter);
  2010. dbus_message_iter_get_basic(&iter, &value);
  2011. if (value == NULL) {
  2012. return dbus_message_new_error(
  2013. message, DBUS_ERROR_INVALID_ARGS,
  2014. "Invalid pkcs11_engine_path argument");
  2015. }
  2016. /* Empty path defaults to NULL */
  2017. if (os_strlen(value))
  2018. pkcs11_engine_path = value;
  2019. dbus_message_iter_next(&iter);
  2020. dbus_message_iter_get_basic(&iter, &value);
  2021. if (value == NULL) {
  2022. os_free(pkcs11_engine_path);
  2023. return dbus_message_new_error(
  2024. message, DBUS_ERROR_INVALID_ARGS,
  2025. "Invalid pkcs11_module_path argument");
  2026. }
  2027. /* Empty path defaults to NULL */
  2028. if (os_strlen(value))
  2029. pkcs11_module_path = value;
  2030. if (wpas_set_pkcs11_engine_and_module_path(wpa_s, pkcs11_engine_path,
  2031. pkcs11_module_path))
  2032. return dbus_message_new_error(
  2033. message, DBUS_ERROR_FAILED,
  2034. "Reinit of the EAPOL state machine with the new PKCS #11 engine and module path failed.");
  2035. if (wpa_s->dbus_new_path) {
  2036. wpa_dbus_mark_property_changed(
  2037. wpa_s->global->dbus, wpa_s->dbus_new_path,
  2038. WPAS_DBUS_NEW_IFACE_INTERFACE, "PKCS11EnginePath");
  2039. wpa_dbus_mark_property_changed(
  2040. wpa_s->global->dbus, wpa_s->dbus_new_path,
  2041. WPAS_DBUS_NEW_IFACE_INTERFACE, "PKCS11ModulePath");
  2042. }
  2043. return NULL;
  2044. }
  2045. /**
  2046. * wpas_dbus_getter_capabilities - Return interface capabilities
  2047. * @iter: Pointer to incoming dbus message iter
  2048. * @error: Location to store error on failure
  2049. * @user_data: Function specific data
  2050. * Returns: TRUE on success, FALSE on failure
  2051. *
  2052. * Getter for "Capabilities" property of an interface.
  2053. */
  2054. dbus_bool_t wpas_dbus_getter_capabilities(
  2055. const struct wpa_dbus_property_desc *property_desc,
  2056. DBusMessageIter *iter, DBusError *error, void *user_data)
  2057. {
  2058. struct wpa_supplicant *wpa_s = user_data;
  2059. struct wpa_driver_capa capa;
  2060. int res;
  2061. DBusMessageIter iter_dict, iter_dict_entry, iter_dict_val, iter_array,
  2062. variant_iter;
  2063. const char *scans[] = { "active", "passive", "ssid" };
  2064. if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
  2065. "a{sv}", &variant_iter) ||
  2066. !wpa_dbus_dict_open_write(&variant_iter, &iter_dict))
  2067. goto nomem;
  2068. res = wpa_drv_get_capa(wpa_s, &capa);
  2069. /***** pairwise cipher */
  2070. if (res < 0) {
  2071. const char *args[] = {"ccmp", "tkip", "none"};
  2072. if (!wpa_dbus_dict_append_string_array(
  2073. &iter_dict, "Pairwise", args,
  2074. ARRAY_SIZE(args)))
  2075. goto nomem;
  2076. } else {
  2077. if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Pairwise",
  2078. &iter_dict_entry,
  2079. &iter_dict_val,
  2080. &iter_array) ||
  2081. ((capa.enc & WPA_DRIVER_CAPA_ENC_CCMP_256) &&
  2082. !wpa_dbus_dict_string_array_add_element(
  2083. &iter_array, "ccmp-256")) ||
  2084. ((capa.enc & WPA_DRIVER_CAPA_ENC_GCMP_256) &&
  2085. !wpa_dbus_dict_string_array_add_element(
  2086. &iter_array, "gcmp-256")) ||
  2087. ((capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) &&
  2088. !wpa_dbus_dict_string_array_add_element(
  2089. &iter_array, "ccmp")) ||
  2090. ((capa.enc & WPA_DRIVER_CAPA_ENC_GCMP) &&
  2091. !wpa_dbus_dict_string_array_add_element(
  2092. &iter_array, "gcmp")) ||
  2093. ((capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) &&
  2094. !wpa_dbus_dict_string_array_add_element(
  2095. &iter_array, "tkip")) ||
  2096. ((capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) &&
  2097. !wpa_dbus_dict_string_array_add_element(
  2098. &iter_array, "none")) ||
  2099. !wpa_dbus_dict_end_string_array(&iter_dict,
  2100. &iter_dict_entry,
  2101. &iter_dict_val,
  2102. &iter_array))
  2103. goto nomem;
  2104. }
  2105. /***** group cipher */
  2106. if (res < 0) {
  2107. const char *args[] = {
  2108. "ccmp", "tkip", "wep104", "wep40"
  2109. };
  2110. if (!wpa_dbus_dict_append_string_array(
  2111. &iter_dict, "Group", args,
  2112. ARRAY_SIZE(args)))
  2113. goto nomem;
  2114. } else {
  2115. if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Group",
  2116. &iter_dict_entry,
  2117. &iter_dict_val,
  2118. &iter_array) ||
  2119. ((capa.enc & WPA_DRIVER_CAPA_ENC_CCMP_256) &&
  2120. !wpa_dbus_dict_string_array_add_element(
  2121. &iter_array, "ccmp-256")) ||
  2122. ((capa.enc & WPA_DRIVER_CAPA_ENC_GCMP_256) &&
  2123. !wpa_dbus_dict_string_array_add_element(
  2124. &iter_array, "gcmp-256")) ||
  2125. ((capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) &&
  2126. !wpa_dbus_dict_string_array_add_element(
  2127. &iter_array, "ccmp")) ||
  2128. ((capa.enc & WPA_DRIVER_CAPA_ENC_GCMP) &&
  2129. !wpa_dbus_dict_string_array_add_element(
  2130. &iter_array, "gcmp")) ||
  2131. ((capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) &&
  2132. !wpa_dbus_dict_string_array_add_element(
  2133. &iter_array, "tkip")) ||
  2134. ((capa.enc & WPA_DRIVER_CAPA_ENC_WEP104) &&
  2135. !wpa_dbus_dict_string_array_add_element(
  2136. &iter_array, "wep104")) ||
  2137. ((capa.enc & WPA_DRIVER_CAPA_ENC_WEP40) &&
  2138. !wpa_dbus_dict_string_array_add_element(
  2139. &iter_array, "wep40")) ||
  2140. !wpa_dbus_dict_end_string_array(&iter_dict,
  2141. &iter_dict_entry,
  2142. &iter_dict_val,
  2143. &iter_array))
  2144. goto nomem;
  2145. }
  2146. if (!wpa_dbus_dict_begin_string_array(&iter_dict, "GroupMgmt",
  2147. &iter_dict_entry,
  2148. &iter_dict_val,
  2149. &iter_array) ||
  2150. (res == 0 && (capa.enc & WPA_DRIVER_CAPA_ENC_BIP) &&
  2151. !wpa_dbus_dict_string_array_add_element(
  2152. &iter_array, "aes-128-cmac")) ||
  2153. (res == 0 && (capa.enc & WPA_DRIVER_CAPA_ENC_BIP_GMAC_128) &&
  2154. !wpa_dbus_dict_string_array_add_element(
  2155. &iter_array, "bip-gmac-128")) ||
  2156. (res == 0 && (capa.enc & WPA_DRIVER_CAPA_ENC_BIP_GMAC_256) &&
  2157. !wpa_dbus_dict_string_array_add_element(
  2158. &iter_array, "bip-gmac-256")) ||
  2159. (res == 0 && (capa.enc & WPA_DRIVER_CAPA_ENC_BIP_CMAC_256) &&
  2160. !wpa_dbus_dict_string_array_add_element(
  2161. &iter_array, "bip-cmac-256")) ||
  2162. !wpa_dbus_dict_end_string_array(&iter_dict,
  2163. &iter_dict_entry,
  2164. &iter_dict_val,
  2165. &iter_array))
  2166. goto nomem;
  2167. /***** key management */
  2168. if (res < 0) {
  2169. const char *args[] = {
  2170. "wpa-psk", "wpa-eap", "ieee8021x", "wpa-none",
  2171. #ifdef CONFIG_WPS
  2172. "wps",
  2173. #endif /* CONFIG_WPS */
  2174. "none"
  2175. };
  2176. if (!wpa_dbus_dict_append_string_array(
  2177. &iter_dict, "KeyMgmt", args,
  2178. ARRAY_SIZE(args)))
  2179. goto nomem;
  2180. } else {
  2181. if (!wpa_dbus_dict_begin_string_array(&iter_dict, "KeyMgmt",
  2182. &iter_dict_entry,
  2183. &iter_dict_val,
  2184. &iter_array) ||
  2185. !wpa_dbus_dict_string_array_add_element(&iter_array,
  2186. "none") ||
  2187. !wpa_dbus_dict_string_array_add_element(&iter_array,
  2188. "ieee8021x"))
  2189. goto nomem;
  2190. if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
  2191. WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
  2192. if (!wpa_dbus_dict_string_array_add_element(
  2193. &iter_array, "wpa-eap") ||
  2194. ((capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT) &&
  2195. !wpa_dbus_dict_string_array_add_element(
  2196. &iter_array, "wpa-ft-eap")))
  2197. goto nomem;
  2198. /* TODO: Ensure that driver actually supports sha256 encryption. */
  2199. #ifdef CONFIG_IEEE80211W
  2200. if (!wpa_dbus_dict_string_array_add_element(
  2201. &iter_array, "wpa-eap-sha256"))
  2202. goto nomem;
  2203. #endif /* CONFIG_IEEE80211W */
  2204. }
  2205. if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
  2206. WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
  2207. if (!wpa_dbus_dict_string_array_add_element(
  2208. &iter_array, "wpa-psk") ||
  2209. ((capa.key_mgmt &
  2210. WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK) &&
  2211. !wpa_dbus_dict_string_array_add_element(
  2212. &iter_array, "wpa-ft-psk")))
  2213. goto nomem;
  2214. /* TODO: Ensure that driver actually supports sha256 encryption. */
  2215. #ifdef CONFIG_IEEE80211W
  2216. if (!wpa_dbus_dict_string_array_add_element(
  2217. &iter_array, "wpa-psk-sha256"))
  2218. goto nomem;
  2219. #endif /* CONFIG_IEEE80211W */
  2220. }
  2221. if ((capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) &&
  2222. !wpa_dbus_dict_string_array_add_element(&iter_array,
  2223. "wpa-none"))
  2224. goto nomem;
  2225. #ifdef CONFIG_WPS
  2226. if (!wpa_dbus_dict_string_array_add_element(&iter_array,
  2227. "wps"))
  2228. goto nomem;
  2229. #endif /* CONFIG_WPS */
  2230. if (!wpa_dbus_dict_end_string_array(&iter_dict,
  2231. &iter_dict_entry,
  2232. &iter_dict_val,
  2233. &iter_array))
  2234. goto nomem;
  2235. }
  2236. /***** WPA protocol */
  2237. if (res < 0) {
  2238. const char *args[] = { "rsn", "wpa" };
  2239. if (!wpa_dbus_dict_append_string_array(
  2240. &iter_dict, "Protocol", args,
  2241. ARRAY_SIZE(args)))
  2242. goto nomem;
  2243. } else {
  2244. if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Protocol",
  2245. &iter_dict_entry,
  2246. &iter_dict_val,
  2247. &iter_array) ||
  2248. ((capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
  2249. WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) &&
  2250. !wpa_dbus_dict_string_array_add_element(
  2251. &iter_array, "rsn")) ||
  2252. ((capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
  2253. WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) &&
  2254. !wpa_dbus_dict_string_array_add_element(
  2255. &iter_array, "wpa")) ||
  2256. !wpa_dbus_dict_end_string_array(&iter_dict,
  2257. &iter_dict_entry,
  2258. &iter_dict_val,
  2259. &iter_array))
  2260. goto nomem;
  2261. }
  2262. /***** auth alg */
  2263. if (res < 0) {
  2264. const char *args[] = { "open", "shared", "leap" };
  2265. if (!wpa_dbus_dict_append_string_array(
  2266. &iter_dict, "AuthAlg", args,
  2267. ARRAY_SIZE(args)))
  2268. goto nomem;
  2269. } else {
  2270. if (!wpa_dbus_dict_begin_string_array(&iter_dict, "AuthAlg",
  2271. &iter_dict_entry,
  2272. &iter_dict_val,
  2273. &iter_array))
  2274. goto nomem;
  2275. if (((capa.auth & WPA_DRIVER_AUTH_OPEN) &&
  2276. !wpa_dbus_dict_string_array_add_element(
  2277. &iter_array, "open")) ||
  2278. ((capa.auth & WPA_DRIVER_AUTH_SHARED) &&
  2279. !wpa_dbus_dict_string_array_add_element(
  2280. &iter_array, "shared")) ||
  2281. ((capa.auth & WPA_DRIVER_AUTH_LEAP) &&
  2282. !wpa_dbus_dict_string_array_add_element(
  2283. &iter_array, "leap")) ||
  2284. !wpa_dbus_dict_end_string_array(&iter_dict,
  2285. &iter_dict_entry,
  2286. &iter_dict_val,
  2287. &iter_array))
  2288. goto nomem;
  2289. }
  2290. /***** Scan */
  2291. if (!wpa_dbus_dict_append_string_array(&iter_dict, "Scan", scans,
  2292. ARRAY_SIZE(scans)))
  2293. goto nomem;
  2294. /***** Modes */
  2295. if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Modes",
  2296. &iter_dict_entry,
  2297. &iter_dict_val,
  2298. &iter_array) ||
  2299. !wpa_dbus_dict_string_array_add_element(
  2300. &iter_array, "infrastructure") ||
  2301. (res >= 0 && (capa.flags & WPA_DRIVER_FLAGS_IBSS) &&
  2302. !wpa_dbus_dict_string_array_add_element(
  2303. &iter_array, "ad-hoc")) ||
  2304. (res >= 0 && (capa.flags & WPA_DRIVER_FLAGS_AP) &&
  2305. !wpa_dbus_dict_string_array_add_element(
  2306. &iter_array, "ap")) ||
  2307. (res >= 0 && (capa.flags & WPA_DRIVER_FLAGS_P2P_CAPABLE) &&
  2308. !wpa_s->conf->p2p_disabled &&
  2309. !wpa_dbus_dict_string_array_add_element(
  2310. &iter_array, "p2p")) ||
  2311. !wpa_dbus_dict_end_string_array(&iter_dict,
  2312. &iter_dict_entry,
  2313. &iter_dict_val,
  2314. &iter_array))
  2315. goto nomem;
  2316. /***** Modes end */
  2317. if (res >= 0) {
  2318. dbus_int32_t max_scan_ssid = capa.max_scan_ssids;
  2319. if (!wpa_dbus_dict_append_int32(&iter_dict, "MaxScanSSID",
  2320. max_scan_ssid))
  2321. goto nomem;
  2322. }
  2323. if (!wpa_dbus_dict_close_write(&variant_iter, &iter_dict) ||
  2324. !dbus_message_iter_close_container(iter, &variant_iter))
  2325. goto nomem;
  2326. return TRUE;
  2327. nomem:
  2328. dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
  2329. return FALSE;
  2330. }
  2331. /**
  2332. * wpas_dbus_getter_state - Get interface state
  2333. * @iter: Pointer to incoming dbus message iter
  2334. * @error: Location to store error on failure
  2335. * @user_data: Function specific data
  2336. * Returns: TRUE on success, FALSE on failure
  2337. *
  2338. * Getter for "State" property.
  2339. */
  2340. dbus_bool_t wpas_dbus_getter_state(
  2341. const struct wpa_dbus_property_desc *property_desc,
  2342. DBusMessageIter *iter, DBusError *error, void *user_data)
  2343. {
  2344. struct wpa_supplicant *wpa_s = user_data;
  2345. const char *str_state;
  2346. char *state_ls, *tmp;
  2347. dbus_bool_t success = FALSE;
  2348. str_state = wpa_supplicant_state_txt(wpa_s->wpa_state);
  2349. /* make state string lowercase to fit new DBus API convention
  2350. */
  2351. state_ls = tmp = os_strdup(str_state);
  2352. if (!tmp) {
  2353. dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
  2354. return FALSE;
  2355. }
  2356. while (*tmp) {
  2357. *tmp = tolower(*tmp);
  2358. tmp++;
  2359. }
  2360. success = wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
  2361. &state_ls, error);
  2362. os_free(state_ls);
  2363. return success;
  2364. }
  2365. /**
  2366. * wpas_dbus_new_iface_get_scanning - Get interface scanning state
  2367. * @iter: Pointer to incoming dbus message iter
  2368. * @error: Location to store error on failure
  2369. * @user_data: Function specific data
  2370. * Returns: TRUE on success, FALSE on failure
  2371. *
  2372. * Getter for "scanning" property.
  2373. */
  2374. dbus_bool_t wpas_dbus_getter_scanning(
  2375. const struct wpa_dbus_property_desc *property_desc,
  2376. DBusMessageIter *iter, DBusError *error, void *user_data)
  2377. {
  2378. struct wpa_supplicant *wpa_s = user_data;
  2379. dbus_bool_t scanning = wpa_s->scanning ? TRUE : FALSE;
  2380. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
  2381. &scanning, error);
  2382. }
  2383. /**
  2384. * wpas_dbus_getter_ap_scan - Control roaming mode
  2385. * @iter: Pointer to incoming dbus message iter
  2386. * @error: Location to store error on failure
  2387. * @user_data: Function specific data
  2388. * Returns: TRUE on success, FALSE on failure
  2389. *
  2390. * Getter function for "ApScan" property.
  2391. */
  2392. dbus_bool_t wpas_dbus_getter_ap_scan(
  2393. const struct wpa_dbus_property_desc *property_desc,
  2394. DBusMessageIter *iter, DBusError *error, void *user_data)
  2395. {
  2396. struct wpa_supplicant *wpa_s = user_data;
  2397. dbus_uint32_t ap_scan = wpa_s->conf->ap_scan;
  2398. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT32,
  2399. &ap_scan, error);
  2400. }
  2401. /**
  2402. * wpas_dbus_setter_ap_scan - Control roaming mode
  2403. * @iter: Pointer to incoming dbus message iter
  2404. * @error: Location to store error on failure
  2405. * @user_data: Function specific data
  2406. * Returns: TRUE on success, FALSE on failure
  2407. *
  2408. * Setter function for "ApScan" property.
  2409. */
  2410. dbus_bool_t wpas_dbus_setter_ap_scan(
  2411. const struct wpa_dbus_property_desc *property_desc,
  2412. DBusMessageIter *iter, DBusError *error, void *user_data)
  2413. {
  2414. struct wpa_supplicant *wpa_s = user_data;
  2415. dbus_uint32_t ap_scan;
  2416. if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_UINT32,
  2417. &ap_scan))
  2418. return FALSE;
  2419. if (wpa_supplicant_set_ap_scan(wpa_s, ap_scan)) {
  2420. dbus_set_error_const(error, DBUS_ERROR_FAILED,
  2421. "ap_scan must be 0, 1, or 2");
  2422. return FALSE;
  2423. }
  2424. return TRUE;
  2425. }
  2426. #ifdef CONFIG_IEEE80211W
  2427. /**
  2428. * wpas_dbus_getter_pmf - Control PMF default
  2429. * @iter: Pointer to incoming dbus message iter
  2430. * @error: Location to store error on failure
  2431. * @user_data: Function specific data
  2432. * Returns: TRUE on success, FALSE on failure
  2433. *
  2434. * Getter function for "Pmf" property.
  2435. */
  2436. dbus_bool_t wpas_dbus_getter_pmf(
  2437. const struct wpa_dbus_property_desc *property_desc,
  2438. DBusMessageIter *iter, DBusError *error, void *user_data)
  2439. {
  2440. struct wpa_supplicant *wpa_s = user_data;
  2441. dbus_uint32_t pmf = wpa_s->conf->pmf;
  2442. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT32,
  2443. &pmf, error);
  2444. }
  2445. /**
  2446. * wpas_dbus_setter_pmf - Control PMF default
  2447. * @iter: Pointer to incoming dbus message iter
  2448. * @error: Location to store error on failure
  2449. * @user_data: Function specific data
  2450. * Returns: TRUE on success, FALSE on failure
  2451. *
  2452. * Setter function for "Pmf" property.
  2453. */
  2454. dbus_bool_t wpas_dbus_setter_pmf(
  2455. const struct wpa_dbus_property_desc *property_desc,
  2456. DBusMessageIter *iter, DBusError *error, void *user_data)
  2457. {
  2458. struct wpa_supplicant *wpa_s = user_data;
  2459. dbus_uint32_t pmf;
  2460. if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_UINT32,
  2461. &pmf))
  2462. return FALSE;
  2463. if (pmf > 2) {
  2464. dbus_set_error_const(error, DBUS_ERROR_FAILED,
  2465. "Pmf must be 0, 1, or 2");
  2466. return FALSE;
  2467. }
  2468. wpa_s->conf->pmf = pmf;
  2469. return TRUE;
  2470. }
  2471. #endif /* CONFIG_IEEE80211W */
  2472. /**
  2473. * wpas_dbus_getter_fast_reauth - Control fast
  2474. * reauthentication (TLS session resumption)
  2475. * @iter: Pointer to incoming dbus message iter
  2476. * @error: Location to store error on failure
  2477. * @user_data: Function specific data
  2478. * Returns: TRUE on success, FALSE on failure
  2479. *
  2480. * Getter function for "FastReauth" property.
  2481. */
  2482. dbus_bool_t wpas_dbus_getter_fast_reauth(
  2483. const struct wpa_dbus_property_desc *property_desc,
  2484. DBusMessageIter *iter, DBusError *error, void *user_data)
  2485. {
  2486. struct wpa_supplicant *wpa_s = user_data;
  2487. dbus_bool_t fast_reauth = wpa_s->conf->fast_reauth ? TRUE : FALSE;
  2488. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
  2489. &fast_reauth, error);
  2490. }
  2491. /**
  2492. * wpas_dbus_setter_fast_reauth - Control fast
  2493. * reauthentication (TLS session resumption)
  2494. * @iter: Pointer to incoming dbus message iter
  2495. * @error: Location to store error on failure
  2496. * @user_data: Function specific data
  2497. * Returns: TRUE on success, FALSE on failure
  2498. *
  2499. * Setter function for "FastReauth" property.
  2500. */
  2501. dbus_bool_t wpas_dbus_setter_fast_reauth(
  2502. const struct wpa_dbus_property_desc *property_desc,
  2503. DBusMessageIter *iter, DBusError *error, void *user_data)
  2504. {
  2505. struct wpa_supplicant *wpa_s = user_data;
  2506. dbus_bool_t fast_reauth;
  2507. if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_BOOLEAN,
  2508. &fast_reauth))
  2509. return FALSE;
  2510. wpa_s->conf->fast_reauth = fast_reauth;
  2511. return TRUE;
  2512. }
  2513. /**
  2514. * wpas_dbus_getter_disconnect_reason - Get most recent reason for disconnect
  2515. * @iter: Pointer to incoming dbus message iter
  2516. * @error: Location to store error on failure
  2517. * @user_data: Function specific data
  2518. * Returns: TRUE on success, FALSE on failure
  2519. *
  2520. * Getter for "DisconnectReason" property. The reason is negative if it is
  2521. * locally generated.
  2522. */
  2523. dbus_bool_t wpas_dbus_getter_disconnect_reason(
  2524. const struct wpa_dbus_property_desc *property_desc,
  2525. DBusMessageIter *iter, DBusError *error, void *user_data)
  2526. {
  2527. struct wpa_supplicant *wpa_s = user_data;
  2528. dbus_int32_t reason = wpa_s->disconnect_reason;
  2529. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_INT32,
  2530. &reason, error);
  2531. }
  2532. /**
  2533. * wpas_dbus_getter_assoc_status_code - Get most recent failed assoc status code
  2534. * @iter: Pointer to incoming dbus message iter
  2535. * @error: Location to store error on failure
  2536. * @user_data: Function specific data
  2537. * Returns: TRUE on success, FALSE on failure
  2538. *
  2539. * Getter for "AssocStatusCode" property.
  2540. */
  2541. dbus_bool_t wpas_dbus_getter_assoc_status_code(
  2542. const struct wpa_dbus_property_desc *property_desc,
  2543. DBusMessageIter *iter, DBusError *error, void *user_data)
  2544. {
  2545. struct wpa_supplicant *wpa_s = user_data;
  2546. dbus_int32_t status_code = wpa_s->assoc_status_code;
  2547. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_INT32,
  2548. &status_code, error);
  2549. }
  2550. /**
  2551. * wpas_dbus_getter_bss_expire_age - Get BSS entry expiration age
  2552. * @iter: Pointer to incoming dbus message iter
  2553. * @error: Location to store error on failure
  2554. * @user_data: Function specific data
  2555. * Returns: TRUE on success, FALSE on failure
  2556. *
  2557. * Getter function for "BSSExpireAge" property.
  2558. */
  2559. dbus_bool_t wpas_dbus_getter_bss_expire_age(
  2560. const struct wpa_dbus_property_desc *property_desc,
  2561. DBusMessageIter *iter, DBusError *error, void *user_data)
  2562. {
  2563. struct wpa_supplicant *wpa_s = user_data;
  2564. dbus_uint32_t expire_age = wpa_s->conf->bss_expiration_age;
  2565. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT32,
  2566. &expire_age, error);
  2567. }
  2568. /**
  2569. * wpas_dbus_setter_bss_expire_age - Control BSS entry expiration age
  2570. * @iter: Pointer to incoming dbus message iter
  2571. * @error: Location to store error on failure
  2572. * @user_data: Function specific data
  2573. * Returns: TRUE on success, FALSE on failure
  2574. *
  2575. * Setter function for "BSSExpireAge" property.
  2576. */
  2577. dbus_bool_t wpas_dbus_setter_bss_expire_age(
  2578. const struct wpa_dbus_property_desc *property_desc,
  2579. DBusMessageIter *iter, DBusError *error, void *user_data)
  2580. {
  2581. struct wpa_supplicant *wpa_s = user_data;
  2582. dbus_uint32_t expire_age;
  2583. if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_UINT32,
  2584. &expire_age))
  2585. return FALSE;
  2586. if (wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age)) {
  2587. dbus_set_error_const(error, DBUS_ERROR_FAILED,
  2588. "BSSExpireAge must be >= 10");
  2589. return FALSE;
  2590. }
  2591. return TRUE;
  2592. }
  2593. /**
  2594. * wpas_dbus_getter_bss_expire_count - Get BSS entry expiration scan count
  2595. * @iter: Pointer to incoming dbus message iter
  2596. * @error: Location to store error on failure
  2597. * @user_data: Function specific data
  2598. * Returns: TRUE on success, FALSE on failure
  2599. *
  2600. * Getter function for "BSSExpireCount" property.
  2601. */
  2602. dbus_bool_t wpas_dbus_getter_bss_expire_count(
  2603. const struct wpa_dbus_property_desc *property_desc,
  2604. DBusMessageIter *iter, DBusError *error, void *user_data)
  2605. {
  2606. struct wpa_supplicant *wpa_s = user_data;
  2607. dbus_uint32_t expire_count = wpa_s->conf->bss_expiration_scan_count;
  2608. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT32,
  2609. &expire_count, error);
  2610. }
  2611. /**
  2612. * wpas_dbus_setter_bss_expire_count - Control BSS entry expiration scan count
  2613. * @iter: Pointer to incoming dbus message iter
  2614. * @error: Location to store error on failure
  2615. * @user_data: Function specific data
  2616. * Returns: TRUE on success, FALSE on failure
  2617. *
  2618. * Setter function for "BSSExpireCount" property.
  2619. */
  2620. dbus_bool_t wpas_dbus_setter_bss_expire_count(
  2621. const struct wpa_dbus_property_desc *property_desc,
  2622. DBusMessageIter *iter, DBusError *error, void *user_data)
  2623. {
  2624. struct wpa_supplicant *wpa_s = user_data;
  2625. dbus_uint32_t expire_count;
  2626. if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_UINT32,
  2627. &expire_count))
  2628. return FALSE;
  2629. if (wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count)) {
  2630. dbus_set_error_const(error, DBUS_ERROR_FAILED,
  2631. "BSSExpireCount must be > 0");
  2632. return FALSE;
  2633. }
  2634. return TRUE;
  2635. }
  2636. /**
  2637. * wpas_dbus_getter_country - Control country code
  2638. * @iter: Pointer to incoming dbus message iter
  2639. * @error: Location to store error on failure
  2640. * @user_data: Function specific data
  2641. * Returns: TRUE on success, FALSE on failure
  2642. *
  2643. * Getter function for "Country" property.
  2644. */
  2645. dbus_bool_t wpas_dbus_getter_country(
  2646. const struct wpa_dbus_property_desc *property_desc,
  2647. DBusMessageIter *iter, DBusError *error, void *user_data)
  2648. {
  2649. struct wpa_supplicant *wpa_s = user_data;
  2650. char country[3];
  2651. char *str = country;
  2652. country[0] = wpa_s->conf->country[0];
  2653. country[1] = wpa_s->conf->country[1];
  2654. country[2] = '\0';
  2655. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
  2656. &str, error);
  2657. }
  2658. /**
  2659. * wpas_dbus_setter_country - Control country code
  2660. * @iter: Pointer to incoming dbus message iter
  2661. * @error: Location to store error on failure
  2662. * @user_data: Function specific data
  2663. * Returns: TRUE on success, FALSE on failure
  2664. *
  2665. * Setter function for "Country" property.
  2666. */
  2667. dbus_bool_t wpas_dbus_setter_country(
  2668. const struct wpa_dbus_property_desc *property_desc,
  2669. DBusMessageIter *iter, DBusError *error, void *user_data)
  2670. {
  2671. struct wpa_supplicant *wpa_s = user_data;
  2672. const char *country;
  2673. if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_STRING,
  2674. &country))
  2675. return FALSE;
  2676. if (!country[0] || !country[1]) {
  2677. dbus_set_error_const(error, DBUS_ERROR_FAILED,
  2678. "invalid country code");
  2679. return FALSE;
  2680. }
  2681. if (wpa_s->drv_priv != NULL && wpa_drv_set_country(wpa_s, country)) {
  2682. wpa_printf(MSG_DEBUG, "Failed to set country");
  2683. dbus_set_error_const(error, DBUS_ERROR_FAILED,
  2684. "failed to set country code");
  2685. return FALSE;
  2686. }
  2687. wpa_s->conf->country[0] = country[0];
  2688. wpa_s->conf->country[1] = country[1];
  2689. return TRUE;
  2690. }
  2691. /**
  2692. * wpas_dbus_getter_scan_interval - Get scan interval
  2693. * @iter: Pointer to incoming dbus message iter
  2694. * @error: Location to store error on failure
  2695. * @user_data: Function specific data
  2696. * Returns: TRUE on success, FALSE on failure
  2697. *
  2698. * Getter function for "ScanInterval" property.
  2699. */
  2700. dbus_bool_t wpas_dbus_getter_scan_interval(
  2701. const struct wpa_dbus_property_desc *property_desc,
  2702. DBusMessageIter *iter, DBusError *error, void *user_data)
  2703. {
  2704. struct wpa_supplicant *wpa_s = user_data;
  2705. dbus_int32_t scan_interval = wpa_s->scan_interval;
  2706. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_INT32,
  2707. &scan_interval, error);
  2708. }
  2709. /**
  2710. * wpas_dbus_setter_scan_interval - Control scan interval
  2711. * @iter: Pointer to incoming dbus message iter
  2712. * @error: Location to store error on failure
  2713. * @user_data: Function specific data
  2714. * Returns: TRUE on success, FALSE on failure
  2715. *
  2716. * Setter function for "ScanInterval" property.
  2717. */
  2718. dbus_bool_t wpas_dbus_setter_scan_interval(
  2719. const struct wpa_dbus_property_desc *property_desc,
  2720. DBusMessageIter *iter, DBusError *error, void *user_data)
  2721. {
  2722. struct wpa_supplicant *wpa_s = user_data;
  2723. dbus_int32_t scan_interval;
  2724. if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_INT32,
  2725. &scan_interval))
  2726. return FALSE;
  2727. if (wpa_supplicant_set_scan_interval(wpa_s, scan_interval)) {
  2728. dbus_set_error_const(error, DBUS_ERROR_FAILED,
  2729. "scan_interval must be >= 0");
  2730. return FALSE;
  2731. }
  2732. return TRUE;
  2733. }
  2734. /**
  2735. * wpas_dbus_getter_ifname - Get interface name
  2736. * @iter: Pointer to incoming dbus message iter
  2737. * @error: Location to store error on failure
  2738. * @user_data: Function specific data
  2739. * Returns: TRUE on success, FALSE on failure
  2740. *
  2741. * Getter for "Ifname" property.
  2742. */
  2743. dbus_bool_t wpas_dbus_getter_ifname(
  2744. const struct wpa_dbus_property_desc *property_desc,
  2745. DBusMessageIter *iter, DBusError *error, void *user_data)
  2746. {
  2747. struct wpa_supplicant *wpa_s = user_data;
  2748. return wpas_dbus_string_property_getter(iter, wpa_s->ifname, error);
  2749. }
  2750. /**
  2751. * wpas_dbus_getter_driver - Get interface name
  2752. * @iter: Pointer to incoming dbus message iter
  2753. * @error: Location to store error on failure
  2754. * @user_data: Function specific data
  2755. * Returns: TRUE on success, FALSE on failure
  2756. *
  2757. * Getter for "Driver" property.
  2758. */
  2759. dbus_bool_t wpas_dbus_getter_driver(
  2760. const struct wpa_dbus_property_desc *property_desc,
  2761. DBusMessageIter *iter, DBusError *error, void *user_data)
  2762. {
  2763. struct wpa_supplicant *wpa_s = user_data;
  2764. if (wpa_s->driver == NULL || wpa_s->driver->name == NULL) {
  2765. wpa_printf(MSG_DEBUG, "%s[dbus]: wpa_s has no driver set",
  2766. __func__);
  2767. dbus_set_error(error, DBUS_ERROR_FAILED, "%s: no driver set",
  2768. __func__);
  2769. return FALSE;
  2770. }
  2771. return wpas_dbus_string_property_getter(iter, wpa_s->driver->name,
  2772. error);
  2773. }
  2774. /**
  2775. * wpas_dbus_getter_current_bss - Get current bss object path
  2776. * @iter: Pointer to incoming dbus message iter
  2777. * @error: Location to store error on failure
  2778. * @user_data: Function specific data
  2779. * Returns: TRUE on success, FALSE on failure
  2780. *
  2781. * Getter for "CurrentBSS" property.
  2782. */
  2783. dbus_bool_t wpas_dbus_getter_current_bss(
  2784. const struct wpa_dbus_property_desc *property_desc,
  2785. DBusMessageIter *iter, DBusError *error, void *user_data)
  2786. {
  2787. struct wpa_supplicant *wpa_s = user_data;
  2788. char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *bss_obj_path = path_buf;
  2789. if (wpa_s->current_bss && wpa_s->dbus_new_path)
  2790. os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2791. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  2792. wpa_s->dbus_new_path, wpa_s->current_bss->id);
  2793. else
  2794. os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "/");
  2795. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_OBJECT_PATH,
  2796. &bss_obj_path, error);
  2797. }
  2798. /**
  2799. * wpas_dbus_getter_current_network - Get current network object path
  2800. * @iter: Pointer to incoming dbus message iter
  2801. * @error: Location to store error on failure
  2802. * @user_data: Function specific data
  2803. * Returns: TRUE on success, FALSE on failure
  2804. *
  2805. * Getter for "CurrentNetwork" property.
  2806. */
  2807. dbus_bool_t wpas_dbus_getter_current_network(
  2808. const struct wpa_dbus_property_desc *property_desc,
  2809. DBusMessageIter *iter, DBusError *error, void *user_data)
  2810. {
  2811. struct wpa_supplicant *wpa_s = user_data;
  2812. char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *net_obj_path = path_buf;
  2813. if (wpa_s->current_ssid && wpa_s->dbus_new_path)
  2814. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  2815. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  2816. wpa_s->dbus_new_path, wpa_s->current_ssid->id);
  2817. else
  2818. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "/");
  2819. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_OBJECT_PATH,
  2820. &net_obj_path, error);
  2821. }
  2822. /**
  2823. * wpas_dbus_getter_current_auth_mode - Get current authentication type
  2824. * @iter: Pointer to incoming dbus message iter
  2825. * @error: Location to store error on failure
  2826. * @user_data: Function specific data
  2827. * Returns: TRUE on success, FALSE on failure
  2828. *
  2829. * Getter for "CurrentAuthMode" property.
  2830. */
  2831. dbus_bool_t wpas_dbus_getter_current_auth_mode(
  2832. const struct wpa_dbus_property_desc *property_desc,
  2833. DBusMessageIter *iter, DBusError *error, void *user_data)
  2834. {
  2835. struct wpa_supplicant *wpa_s = user_data;
  2836. const char *eap_mode;
  2837. const char *auth_mode;
  2838. char eap_mode_buf[WPAS_DBUS_AUTH_MODE_MAX];
  2839. if (wpa_s->wpa_state != WPA_COMPLETED) {
  2840. auth_mode = "INACTIVE";
  2841. } else if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X ||
  2842. wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
  2843. eap_mode = wpa_supplicant_get_eap_mode(wpa_s);
  2844. os_snprintf(eap_mode_buf, WPAS_DBUS_AUTH_MODE_MAX,
  2845. "EAP-%s", eap_mode);
  2846. auth_mode = eap_mode_buf;
  2847. } else if (wpa_s->current_ssid) {
  2848. auth_mode = wpa_key_mgmt_txt(wpa_s->key_mgmt,
  2849. wpa_s->current_ssid->proto);
  2850. } else {
  2851. auth_mode = "UNKNOWN";
  2852. }
  2853. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
  2854. &auth_mode, error);
  2855. }
  2856. /**
  2857. * wpas_dbus_getter_bridge_ifname - Get interface name
  2858. * @iter: Pointer to incoming dbus message iter
  2859. * @error: Location to store error on failure
  2860. * @user_data: Function specific data
  2861. * Returns: TRUE on success, FALSE on failure
  2862. *
  2863. * Getter for "BridgeIfname" property.
  2864. */
  2865. dbus_bool_t wpas_dbus_getter_bridge_ifname(
  2866. const struct wpa_dbus_property_desc *property_desc,
  2867. DBusMessageIter *iter, DBusError *error, void *user_data)
  2868. {
  2869. struct wpa_supplicant *wpa_s = user_data;
  2870. return wpas_dbus_string_property_getter(iter, wpa_s->bridge_ifname,
  2871. error);
  2872. }
  2873. /**
  2874. * wpas_dbus_getter_config_file - Get interface configuration file path
  2875. * @iter: Pointer to incoming dbus message iter
  2876. * @error: Location to store error on failure
  2877. * @user_data: Function specific data
  2878. * Returns: TRUE on success, FALSE on failure
  2879. *
  2880. * Getter for "ConfigFile" property.
  2881. */
  2882. dbus_bool_t wpas_dbus_getter_config_file(
  2883. const struct wpa_dbus_property_desc *property_desc,
  2884. DBusMessageIter *iter, DBusError *error, void *user_data)
  2885. {
  2886. struct wpa_supplicant *wpa_s = user_data;
  2887. return wpas_dbus_string_property_getter(iter, wpa_s->confname, error);
  2888. }
  2889. /**
  2890. * wpas_dbus_getter_bsss - Get array of BSSs objects
  2891. * @iter: Pointer to incoming dbus message iter
  2892. * @error: Location to store error on failure
  2893. * @user_data: Function specific data
  2894. * Returns: TRUE on success, FALSE on failure
  2895. *
  2896. * Getter for "BSSs" property.
  2897. */
  2898. dbus_bool_t wpas_dbus_getter_bsss(
  2899. const struct wpa_dbus_property_desc *property_desc,
  2900. DBusMessageIter *iter, DBusError *error, void *user_data)
  2901. {
  2902. struct wpa_supplicant *wpa_s = user_data;
  2903. struct wpa_bss *bss;
  2904. char **paths;
  2905. unsigned int i = 0;
  2906. dbus_bool_t success = FALSE;
  2907. if (!wpa_s->dbus_new_path) {
  2908. dbus_set_error(error, DBUS_ERROR_FAILED,
  2909. "%s: no D-Bus interface", __func__);
  2910. return FALSE;
  2911. }
  2912. paths = os_calloc(wpa_s->num_bss, sizeof(char *));
  2913. if (!paths) {
  2914. dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
  2915. return FALSE;
  2916. }
  2917. /* Loop through scan results and append each result's object path */
  2918. dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
  2919. paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
  2920. if (paths[i] == NULL) {
  2921. dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY,
  2922. "no memory");
  2923. goto out;
  2924. }
  2925. /* Construct the object path for this BSS. */
  2926. os_snprintf(paths[i++], WPAS_DBUS_OBJECT_PATH_MAX,
  2927. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  2928. wpa_s->dbus_new_path, bss->id);
  2929. }
  2930. success = wpas_dbus_simple_array_property_getter(iter,
  2931. DBUS_TYPE_OBJECT_PATH,
  2932. paths, wpa_s->num_bss,
  2933. error);
  2934. out:
  2935. while (i)
  2936. os_free(paths[--i]);
  2937. os_free(paths);
  2938. return success;
  2939. }
  2940. /**
  2941. * wpas_dbus_getter_networks - Get array of networks objects
  2942. * @iter: Pointer to incoming dbus message iter
  2943. * @error: Location to store error on failure
  2944. * @user_data: Function specific data
  2945. * Returns: TRUE on success, FALSE on failure
  2946. *
  2947. * Getter for "Networks" property.
  2948. */
  2949. dbus_bool_t wpas_dbus_getter_networks(
  2950. const struct wpa_dbus_property_desc *property_desc,
  2951. DBusMessageIter *iter, DBusError *error, void *user_data)
  2952. {
  2953. struct wpa_supplicant *wpa_s = user_data;
  2954. struct wpa_ssid *ssid;
  2955. char **paths;
  2956. unsigned int i = 0, num = 0;
  2957. dbus_bool_t success = FALSE;
  2958. if (!wpa_s->dbus_new_path) {
  2959. dbus_set_error(error, DBUS_ERROR_FAILED,
  2960. "%s: no D-Bus interface", __func__);
  2961. return FALSE;
  2962. }
  2963. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next)
  2964. if (!network_is_persistent_group(ssid))
  2965. num++;
  2966. paths = os_calloc(num, sizeof(char *));
  2967. if (!paths) {
  2968. dbus_set_error(error, DBUS_ERROR_NO_MEMORY, "no memory");
  2969. return FALSE;
  2970. }
  2971. /* Loop through configured networks and append object path of each */
  2972. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
  2973. if (network_is_persistent_group(ssid))
  2974. continue;
  2975. paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
  2976. if (paths[i] == NULL) {
  2977. dbus_set_error(error, DBUS_ERROR_NO_MEMORY,
  2978. "no memory");
  2979. goto out;
  2980. }
  2981. /* Construct the object path for this network. */
  2982. os_snprintf(paths[i++], WPAS_DBUS_OBJECT_PATH_MAX,
  2983. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
  2984. wpa_s->dbus_new_path, ssid->id);
  2985. }
  2986. success = wpas_dbus_simple_array_property_getter(iter,
  2987. DBUS_TYPE_OBJECT_PATH,
  2988. paths, num, error);
  2989. out:
  2990. while (i)
  2991. os_free(paths[--i]);
  2992. os_free(paths);
  2993. return success;
  2994. }
  2995. /**
  2996. * wpas_dbus_getter_pkcs11_engine_path - Get PKCS #11 engine path
  2997. * @iter: Pointer to incoming dbus message iter
  2998. * @error: Location to store error on failure
  2999. * @user_data: Function specific data
  3000. * Returns: A dbus message containing the PKCS #11 engine path
  3001. *
  3002. * Getter for "PKCS11EnginePath" property.
  3003. */
  3004. dbus_bool_t wpas_dbus_getter_pkcs11_engine_path(
  3005. const struct wpa_dbus_property_desc *property_desc,
  3006. DBusMessageIter *iter, DBusError *error, void *user_data)
  3007. {
  3008. struct wpa_supplicant *wpa_s = user_data;
  3009. return wpas_dbus_string_property_getter(iter,
  3010. wpa_s->conf->pkcs11_engine_path,
  3011. error);
  3012. }
  3013. /**
  3014. * wpas_dbus_getter_pkcs11_module_path - Get PKCS #11 module path
  3015. * @iter: Pointer to incoming dbus message iter
  3016. * @error: Location to store error on failure
  3017. * @user_data: Function specific data
  3018. * Returns: A dbus message containing the PKCS #11 module path
  3019. *
  3020. * Getter for "PKCS11ModulePath" property.
  3021. */
  3022. dbus_bool_t wpas_dbus_getter_pkcs11_module_path(
  3023. const struct wpa_dbus_property_desc *property_desc,
  3024. DBusMessageIter *iter, DBusError *error, void *user_data)
  3025. {
  3026. struct wpa_supplicant *wpa_s = user_data;
  3027. return wpas_dbus_string_property_getter(iter,
  3028. wpa_s->conf->pkcs11_module_path,
  3029. error);
  3030. }
  3031. /**
  3032. * wpas_dbus_getter_blobs - Get all blobs defined for this interface
  3033. * @iter: Pointer to incoming dbus message iter
  3034. * @error: Location to store error on failure
  3035. * @user_data: Function specific data
  3036. * Returns: TRUE on success, FALSE on failure
  3037. *
  3038. * Getter for "Blobs" property.
  3039. */
  3040. dbus_bool_t wpas_dbus_getter_blobs(
  3041. const struct wpa_dbus_property_desc *property_desc,
  3042. DBusMessageIter *iter, DBusError *error, void *user_data)
  3043. {
  3044. struct wpa_supplicant *wpa_s = user_data;
  3045. DBusMessageIter variant_iter, dict_iter, entry_iter, array_iter;
  3046. struct wpa_config_blob *blob;
  3047. if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
  3048. "a{say}", &variant_iter) ||
  3049. !dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
  3050. "{say}", &dict_iter)) {
  3051. dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
  3052. return FALSE;
  3053. }
  3054. blob = wpa_s->conf->blobs;
  3055. while (blob) {
  3056. if (!dbus_message_iter_open_container(&dict_iter,
  3057. DBUS_TYPE_DICT_ENTRY,
  3058. NULL, &entry_iter) ||
  3059. !dbus_message_iter_append_basic(&entry_iter,
  3060. DBUS_TYPE_STRING,
  3061. &(blob->name)) ||
  3062. !dbus_message_iter_open_container(&entry_iter,
  3063. DBUS_TYPE_ARRAY,
  3064. DBUS_TYPE_BYTE_AS_STRING,
  3065. &array_iter) ||
  3066. !dbus_message_iter_append_fixed_array(&array_iter,
  3067. DBUS_TYPE_BYTE,
  3068. &(blob->data),
  3069. blob->len) ||
  3070. !dbus_message_iter_close_container(&entry_iter,
  3071. &array_iter) ||
  3072. !dbus_message_iter_close_container(&dict_iter,
  3073. &entry_iter)) {
  3074. dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY,
  3075. "no memory");
  3076. return FALSE;
  3077. }
  3078. blob = blob->next;
  3079. }
  3080. if (!dbus_message_iter_close_container(&variant_iter, &dict_iter) ||
  3081. !dbus_message_iter_close_container(iter, &variant_iter)) {
  3082. dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
  3083. return FALSE;
  3084. }
  3085. return TRUE;
  3086. }
  3087. dbus_bool_t wpas_dbus_getter_iface_global(
  3088. const struct wpa_dbus_property_desc *property_desc,
  3089. DBusMessageIter *iter, DBusError *error, void *user_data)
  3090. {
  3091. struct wpa_supplicant *wpa_s = user_data;
  3092. int ret;
  3093. char buf[250];
  3094. char *p = buf;
  3095. if (!property_desc->data) {
  3096. dbus_set_error(error, DBUS_ERROR_INVALID_ARGS,
  3097. "Unhandled interface property %s",
  3098. property_desc->dbus_property);
  3099. return FALSE;
  3100. }
  3101. ret = wpa_config_get_value(property_desc->data, wpa_s->conf, buf,
  3102. sizeof(buf));
  3103. if (ret < 0)
  3104. *p = '\0';
  3105. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING, &p,
  3106. error);
  3107. }
  3108. dbus_bool_t wpas_dbus_setter_iface_global(
  3109. const struct wpa_dbus_property_desc *property_desc,
  3110. DBusMessageIter *iter, DBusError *error, void *user_data)
  3111. {
  3112. struct wpa_supplicant *wpa_s = user_data;
  3113. const char *new_value = NULL;
  3114. char buf[250];
  3115. size_t combined_len;
  3116. int ret;
  3117. if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_STRING,
  3118. &new_value))
  3119. return FALSE;
  3120. combined_len = os_strlen(property_desc->data) + os_strlen(new_value) +
  3121. 3;
  3122. if (combined_len >= sizeof(buf)) {
  3123. dbus_set_error(error, DBUS_ERROR_INVALID_ARGS,
  3124. "Interface property %s value too large",
  3125. property_desc->dbus_property);
  3126. return FALSE;
  3127. }
  3128. if (!new_value[0])
  3129. new_value = "NULL";
  3130. ret = os_snprintf(buf, combined_len, "%s=%s", property_desc->data,
  3131. new_value);
  3132. if (os_snprintf_error(combined_len, ret)) {
  3133. dbus_set_error(error, WPAS_DBUS_ERROR_UNKNOWN_ERROR,
  3134. "Failed to construct new interface property %s",
  3135. property_desc->dbus_property);
  3136. return FALSE;
  3137. }
  3138. if (wpa_config_process_global(wpa_s->conf, buf, -1)) {
  3139. dbus_set_error(error, DBUS_ERROR_INVALID_ARGS,
  3140. "Failed to set interface property %s",
  3141. property_desc->dbus_property);
  3142. return FALSE;
  3143. }
  3144. wpa_supplicant_update_config(wpa_s);
  3145. return TRUE;
  3146. }
  3147. static struct wpa_bss * get_bss_helper(struct bss_handler_args *args,
  3148. DBusError *error, const char *func_name)
  3149. {
  3150. struct wpa_bss *res = wpa_bss_get_id(args->wpa_s, args->id);
  3151. if (!res) {
  3152. wpa_printf(MSG_ERROR, "%s[dbus]: no bss with id %d found",
  3153. func_name, args->id);
  3154. dbus_set_error(error, DBUS_ERROR_FAILED,
  3155. "%s: BSS %d not found",
  3156. func_name, args->id);
  3157. }
  3158. return res;
  3159. }
  3160. /**
  3161. * wpas_dbus_getter_bss_bssid - Return the BSSID of a BSS
  3162. * @iter: Pointer to incoming dbus message iter
  3163. * @error: Location to store error on failure
  3164. * @user_data: Function specific data
  3165. * Returns: TRUE on success, FALSE on failure
  3166. *
  3167. * Getter for "BSSID" property.
  3168. */
  3169. dbus_bool_t wpas_dbus_getter_bss_bssid(
  3170. const struct wpa_dbus_property_desc *property_desc,
  3171. DBusMessageIter *iter, DBusError *error, void *user_data)
  3172. {
  3173. struct bss_handler_args *args = user_data;
  3174. struct wpa_bss *res;
  3175. res = get_bss_helper(args, error, __func__);
  3176. if (!res)
  3177. return FALSE;
  3178. return wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE,
  3179. res->bssid, ETH_ALEN,
  3180. error);
  3181. }
  3182. /**
  3183. * wpas_dbus_getter_bss_ssid - Return the SSID of a BSS
  3184. * @iter: Pointer to incoming dbus message iter
  3185. * @error: Location to store error on failure
  3186. * @user_data: Function specific data
  3187. * Returns: TRUE on success, FALSE on failure
  3188. *
  3189. * Getter for "SSID" property.
  3190. */
  3191. dbus_bool_t wpas_dbus_getter_bss_ssid(
  3192. const struct wpa_dbus_property_desc *property_desc,
  3193. DBusMessageIter *iter, DBusError *error, void *user_data)
  3194. {
  3195. struct bss_handler_args *args = user_data;
  3196. struct wpa_bss *res;
  3197. res = get_bss_helper(args, error, __func__);
  3198. if (!res)
  3199. return FALSE;
  3200. return wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE,
  3201. res->ssid, res->ssid_len,
  3202. error);
  3203. }
  3204. /**
  3205. * wpas_dbus_getter_bss_privacy - Return the privacy flag of a BSS
  3206. * @iter: Pointer to incoming dbus message iter
  3207. * @error: Location to store error on failure
  3208. * @user_data: Function specific data
  3209. * Returns: TRUE on success, FALSE on failure
  3210. *
  3211. * Getter for "Privacy" property.
  3212. */
  3213. dbus_bool_t wpas_dbus_getter_bss_privacy(
  3214. const struct wpa_dbus_property_desc *property_desc,
  3215. DBusMessageIter *iter, DBusError *error, void *user_data)
  3216. {
  3217. struct bss_handler_args *args = user_data;
  3218. struct wpa_bss *res;
  3219. dbus_bool_t privacy;
  3220. res = get_bss_helper(args, error, __func__);
  3221. if (!res)
  3222. return FALSE;
  3223. privacy = (res->caps & IEEE80211_CAP_PRIVACY) ? TRUE : FALSE;
  3224. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
  3225. &privacy, error);
  3226. }
  3227. /**
  3228. * wpas_dbus_getter_bss_mode - Return the mode of a BSS
  3229. * @iter: Pointer to incoming dbus message iter
  3230. * @error: Location to store error on failure
  3231. * @user_data: Function specific data
  3232. * Returns: TRUE on success, FALSE on failure
  3233. *
  3234. * Getter for "Mode" property.
  3235. */
  3236. dbus_bool_t wpas_dbus_getter_bss_mode(
  3237. const struct wpa_dbus_property_desc *property_desc,
  3238. DBusMessageIter *iter, DBusError *error, void *user_data)
  3239. {
  3240. struct bss_handler_args *args = user_data;
  3241. struct wpa_bss *res;
  3242. const char *mode;
  3243. const u8 *mesh;
  3244. res = get_bss_helper(args, error, __func__);
  3245. if (!res)
  3246. return FALSE;
  3247. if (bss_is_dmg(res)) {
  3248. switch (res->caps & IEEE80211_CAP_DMG_MASK) {
  3249. case IEEE80211_CAP_DMG_PBSS:
  3250. case IEEE80211_CAP_DMG_IBSS:
  3251. mode = "ad-hoc";
  3252. break;
  3253. case IEEE80211_CAP_DMG_AP:
  3254. mode = "infrastructure";
  3255. break;
  3256. default:
  3257. mode = "";
  3258. break;
  3259. }
  3260. } else {
  3261. mesh = wpa_bss_get_ie(res, WLAN_EID_MESH_ID);
  3262. if (mesh)
  3263. mode = "mesh";
  3264. else if (res->caps & IEEE80211_CAP_IBSS)
  3265. mode = "ad-hoc";
  3266. else
  3267. mode = "infrastructure";
  3268. }
  3269. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
  3270. &mode, error);
  3271. }
  3272. /**
  3273. * wpas_dbus_getter_bss_level - Return the signal strength of a BSS
  3274. * @iter: Pointer to incoming dbus message iter
  3275. * @error: Location to store error on failure
  3276. * @user_data: Function specific data
  3277. * Returns: TRUE on success, FALSE on failure
  3278. *
  3279. * Getter for "Level" property.
  3280. */
  3281. dbus_bool_t wpas_dbus_getter_bss_signal(
  3282. const struct wpa_dbus_property_desc *property_desc,
  3283. DBusMessageIter *iter, DBusError *error, void *user_data)
  3284. {
  3285. struct bss_handler_args *args = user_data;
  3286. struct wpa_bss *res;
  3287. s16 level;
  3288. res = get_bss_helper(args, error, __func__);
  3289. if (!res)
  3290. return FALSE;
  3291. level = (s16) res->level;
  3292. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_INT16,
  3293. &level, error);
  3294. }
  3295. /**
  3296. * wpas_dbus_getter_bss_frequency - Return the frequency of a BSS
  3297. * @iter: Pointer to incoming dbus message iter
  3298. * @error: Location to store error on failure
  3299. * @user_data: Function specific data
  3300. * Returns: TRUE on success, FALSE on failure
  3301. *
  3302. * Getter for "Frequency" property.
  3303. */
  3304. dbus_bool_t wpas_dbus_getter_bss_frequency(
  3305. const struct wpa_dbus_property_desc *property_desc,
  3306. DBusMessageIter *iter, DBusError *error, void *user_data)
  3307. {
  3308. struct bss_handler_args *args = user_data;
  3309. struct wpa_bss *res;
  3310. u16 freq;
  3311. res = get_bss_helper(args, error, __func__);
  3312. if (!res)
  3313. return FALSE;
  3314. freq = (u16) res->freq;
  3315. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT16,
  3316. &freq, error);
  3317. }
  3318. static int cmp_u8s_desc(const void *a, const void *b)
  3319. {
  3320. return (*(u8 *) b - *(u8 *) a);
  3321. }
  3322. /**
  3323. * wpas_dbus_getter_bss_rates - Return available bit rates of a BSS
  3324. * @iter: Pointer to incoming dbus message iter
  3325. * @error: Location to store error on failure
  3326. * @user_data: Function specific data
  3327. * Returns: TRUE on success, FALSE on failure
  3328. *
  3329. * Getter for "Rates" property.
  3330. */
  3331. dbus_bool_t wpas_dbus_getter_bss_rates(
  3332. const struct wpa_dbus_property_desc *property_desc,
  3333. DBusMessageIter *iter, DBusError *error, void *user_data)
  3334. {
  3335. struct bss_handler_args *args = user_data;
  3336. struct wpa_bss *res;
  3337. u8 *ie_rates = NULL;
  3338. u32 *real_rates;
  3339. int rates_num, i;
  3340. dbus_bool_t success = FALSE;
  3341. res = get_bss_helper(args, error, __func__);
  3342. if (!res)
  3343. return FALSE;
  3344. rates_num = wpa_bss_get_bit_rates(res, &ie_rates);
  3345. if (rates_num < 0)
  3346. return FALSE;
  3347. qsort(ie_rates, rates_num, 1, cmp_u8s_desc);
  3348. real_rates = os_malloc(sizeof(u32) * rates_num);
  3349. if (!real_rates) {
  3350. os_free(ie_rates);
  3351. dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
  3352. return FALSE;
  3353. }
  3354. for (i = 0; i < rates_num; i++)
  3355. real_rates[i] = ie_rates[i] * 500000;
  3356. success = wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_UINT32,
  3357. real_rates, rates_num,
  3358. error);
  3359. os_free(ie_rates);
  3360. os_free(real_rates);
  3361. return success;
  3362. }
  3363. static dbus_bool_t wpas_dbus_get_bss_security_prop(
  3364. const struct wpa_dbus_property_desc *property_desc,
  3365. DBusMessageIter *iter, struct wpa_ie_data *ie_data, DBusError *error)
  3366. {
  3367. DBusMessageIter iter_dict, variant_iter;
  3368. const char *group;
  3369. const char *pairwise[5]; /* max 5 pairwise ciphers is supported */
  3370. const char *key_mgmt[9]; /* max 9 key managements may be supported */
  3371. int n;
  3372. if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
  3373. "a{sv}", &variant_iter))
  3374. goto nomem;
  3375. if (!wpa_dbus_dict_open_write(&variant_iter, &iter_dict))
  3376. goto nomem;
  3377. /* KeyMgmt */
  3378. n = 0;
  3379. if (ie_data->key_mgmt & WPA_KEY_MGMT_PSK)
  3380. key_mgmt[n++] = "wpa-psk";
  3381. if (ie_data->key_mgmt & WPA_KEY_MGMT_FT_PSK)
  3382. key_mgmt[n++] = "wpa-ft-psk";
  3383. if (ie_data->key_mgmt & WPA_KEY_MGMT_PSK_SHA256)
  3384. key_mgmt[n++] = "wpa-psk-sha256";
  3385. if (ie_data->key_mgmt & WPA_KEY_MGMT_IEEE8021X)
  3386. key_mgmt[n++] = "wpa-eap";
  3387. if (ie_data->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X)
  3388. key_mgmt[n++] = "wpa-ft-eap";
  3389. if (ie_data->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256)
  3390. key_mgmt[n++] = "wpa-eap-sha256";
  3391. #ifdef CONFIG_SUITEB
  3392. if (ie_data->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B)
  3393. key_mgmt[n++] = "wpa-eap-suite-b";
  3394. #endif /* CONFIG_SUITEB */
  3395. #ifdef CONFIG_SUITEB192
  3396. if (ie_data->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192)
  3397. key_mgmt[n++] = "wpa-eap-suite-b-192";
  3398. #endif /* CONFIG_SUITEB192 */
  3399. if (ie_data->key_mgmt & WPA_KEY_MGMT_NONE)
  3400. key_mgmt[n++] = "wpa-none";
  3401. if (!wpa_dbus_dict_append_string_array(&iter_dict, "KeyMgmt",
  3402. key_mgmt, n))
  3403. goto nomem;
  3404. /* Group */
  3405. switch (ie_data->group_cipher) {
  3406. case WPA_CIPHER_WEP40:
  3407. group = "wep40";
  3408. break;
  3409. case WPA_CIPHER_TKIP:
  3410. group = "tkip";
  3411. break;
  3412. case WPA_CIPHER_CCMP:
  3413. group = "ccmp";
  3414. break;
  3415. case WPA_CIPHER_GCMP:
  3416. group = "gcmp";
  3417. break;
  3418. case WPA_CIPHER_WEP104:
  3419. group = "wep104";
  3420. break;
  3421. case WPA_CIPHER_CCMP_256:
  3422. group = "ccmp-256";
  3423. break;
  3424. case WPA_CIPHER_GCMP_256:
  3425. group = "gcmp-256";
  3426. break;
  3427. default:
  3428. group = "";
  3429. break;
  3430. }
  3431. if (!wpa_dbus_dict_append_string(&iter_dict, "Group", group))
  3432. goto nomem;
  3433. /* Pairwise */
  3434. n = 0;
  3435. if (ie_data->pairwise_cipher & WPA_CIPHER_TKIP)
  3436. pairwise[n++] = "tkip";
  3437. if (ie_data->pairwise_cipher & WPA_CIPHER_CCMP)
  3438. pairwise[n++] = "ccmp";
  3439. if (ie_data->pairwise_cipher & WPA_CIPHER_GCMP)
  3440. pairwise[n++] = "gcmp";
  3441. if (ie_data->pairwise_cipher & WPA_CIPHER_CCMP_256)
  3442. pairwise[n++] = "ccmp-256";
  3443. if (ie_data->pairwise_cipher & WPA_CIPHER_GCMP_256)
  3444. pairwise[n++] = "gcmp-256";
  3445. if (!wpa_dbus_dict_append_string_array(&iter_dict, "Pairwise",
  3446. pairwise, n))
  3447. goto nomem;
  3448. /* Management group (RSN only) */
  3449. if (ie_data->proto == WPA_PROTO_RSN) {
  3450. switch (ie_data->mgmt_group_cipher) {
  3451. #ifdef CONFIG_IEEE80211W
  3452. case WPA_CIPHER_AES_128_CMAC:
  3453. group = "aes128cmac";
  3454. break;
  3455. #endif /* CONFIG_IEEE80211W */
  3456. default:
  3457. group = "";
  3458. break;
  3459. }
  3460. if (!wpa_dbus_dict_append_string(&iter_dict, "MgmtGroup",
  3461. group))
  3462. goto nomem;
  3463. }
  3464. if (!wpa_dbus_dict_close_write(&variant_iter, &iter_dict) ||
  3465. !dbus_message_iter_close_container(iter, &variant_iter))
  3466. goto nomem;
  3467. return TRUE;
  3468. nomem:
  3469. dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
  3470. return FALSE;
  3471. }
  3472. /**
  3473. * wpas_dbus_getter_bss_wpa - Return the WPA options of a BSS
  3474. * @iter: Pointer to incoming dbus message iter
  3475. * @error: Location to store error on failure
  3476. * @user_data: Function specific data
  3477. * Returns: TRUE on success, FALSE on failure
  3478. *
  3479. * Getter for "WPA" property.
  3480. */
  3481. dbus_bool_t wpas_dbus_getter_bss_wpa(
  3482. const struct wpa_dbus_property_desc *property_desc,
  3483. DBusMessageIter *iter, DBusError *error, void *user_data)
  3484. {
  3485. struct bss_handler_args *args = user_data;
  3486. struct wpa_bss *res;
  3487. struct wpa_ie_data wpa_data;
  3488. const u8 *ie;
  3489. res = get_bss_helper(args, error, __func__);
  3490. if (!res)
  3491. return FALSE;
  3492. os_memset(&wpa_data, 0, sizeof(wpa_data));
  3493. ie = wpa_bss_get_vendor_ie(res, WPA_IE_VENDOR_TYPE);
  3494. if (ie && wpa_parse_wpa_ie(ie, 2 + ie[1], &wpa_data) < 0) {
  3495. dbus_set_error_const(error, DBUS_ERROR_FAILED,
  3496. "failed to parse WPA IE");
  3497. return FALSE;
  3498. }
  3499. return wpas_dbus_get_bss_security_prop(property_desc, iter, &wpa_data, error);
  3500. }
  3501. /**
  3502. * wpas_dbus_getter_bss_rsn - Return the RSN options of a BSS
  3503. * @iter: Pointer to incoming dbus message iter
  3504. * @error: Location to store error on failure
  3505. * @user_data: Function specific data
  3506. * Returns: TRUE on success, FALSE on failure
  3507. *
  3508. * Getter for "RSN" property.
  3509. */
  3510. dbus_bool_t wpas_dbus_getter_bss_rsn(
  3511. const struct wpa_dbus_property_desc *property_desc,
  3512. DBusMessageIter *iter, DBusError *error, void *user_data)
  3513. {
  3514. struct bss_handler_args *args = user_data;
  3515. struct wpa_bss *res;
  3516. struct wpa_ie_data wpa_data;
  3517. const u8 *ie;
  3518. res = get_bss_helper(args, error, __func__);
  3519. if (!res)
  3520. return FALSE;
  3521. os_memset(&wpa_data, 0, sizeof(wpa_data));
  3522. ie = wpa_bss_get_ie(res, WLAN_EID_RSN);
  3523. if (ie && wpa_parse_wpa_ie(ie, 2 + ie[1], &wpa_data) < 0) {
  3524. dbus_set_error_const(error, DBUS_ERROR_FAILED,
  3525. "failed to parse RSN IE");
  3526. return FALSE;
  3527. }
  3528. return wpas_dbus_get_bss_security_prop(property_desc, iter, &wpa_data, error);
  3529. }
  3530. /**
  3531. * wpas_dbus_getter_bss_wps - Return the WPS options of a BSS
  3532. * @iter: Pointer to incoming dbus message iter
  3533. * @error: Location to store error on failure
  3534. * @user_data: Function specific data
  3535. * Returns: TRUE on success, FALSE on failure
  3536. *
  3537. * Getter for "WPS" property.
  3538. */
  3539. dbus_bool_t wpas_dbus_getter_bss_wps(
  3540. const struct wpa_dbus_property_desc *property_desc,
  3541. DBusMessageIter *iter, DBusError *error, void *user_data)
  3542. {
  3543. struct bss_handler_args *args = user_data;
  3544. struct wpa_bss *res;
  3545. #ifdef CONFIG_WPS
  3546. struct wpabuf *wps_ie;
  3547. #endif /* CONFIG_WPS */
  3548. DBusMessageIter iter_dict, variant_iter;
  3549. int wps_support = 0;
  3550. const char *type = "";
  3551. res = get_bss_helper(args, error, __func__);
  3552. if (!res)
  3553. return FALSE;
  3554. if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
  3555. "a{sv}", &variant_iter) ||
  3556. !wpa_dbus_dict_open_write(&variant_iter, &iter_dict))
  3557. goto nomem;
  3558. #ifdef CONFIG_WPS
  3559. wps_ie = wpa_bss_get_vendor_ie_multi(res, WPS_IE_VENDOR_TYPE);
  3560. if (wps_ie) {
  3561. wps_support = 1;
  3562. if (wps_is_selected_pbc_registrar(wps_ie))
  3563. type = "pbc";
  3564. else if (wps_is_selected_pin_registrar(wps_ie))
  3565. type = "pin";
  3566. wpabuf_free(wps_ie);
  3567. }
  3568. #endif /* CONFIG_WPS */
  3569. if ((wps_support && !wpa_dbus_dict_append_string(&iter_dict, "Type", type)) ||
  3570. !wpa_dbus_dict_close_write(&variant_iter, &iter_dict) ||
  3571. !dbus_message_iter_close_container(iter, &variant_iter))
  3572. goto nomem;
  3573. return TRUE;
  3574. nomem:
  3575. dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
  3576. return FALSE;
  3577. }
  3578. /**
  3579. * wpas_dbus_getter_bss_ies - Return all IEs of a BSS
  3580. * @iter: Pointer to incoming dbus message iter
  3581. * @error: Location to store error on failure
  3582. * @user_data: Function specific data
  3583. * Returns: TRUE on success, FALSE on failure
  3584. *
  3585. * Getter for "IEs" property.
  3586. */
  3587. dbus_bool_t wpas_dbus_getter_bss_ies(
  3588. const struct wpa_dbus_property_desc *property_desc,
  3589. DBusMessageIter *iter, DBusError *error, void *user_data)
  3590. {
  3591. struct bss_handler_args *args = user_data;
  3592. struct wpa_bss *res;
  3593. res = get_bss_helper(args, error, __func__);
  3594. if (!res)
  3595. return FALSE;
  3596. return wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE,
  3597. res + 1, res->ie_len,
  3598. error);
  3599. }
  3600. /**
  3601. * wpas_dbus_getter_bss_age - Return time in seconds since BSS was last seen
  3602. * @iter: Pointer to incoming dbus message iter
  3603. * @error: Location to store error on failure
  3604. * @user_data: Function specific data
  3605. * Returns: TRUE on success, FALSE on failure
  3606. *
  3607. * Getter for BSS age
  3608. */
  3609. dbus_bool_t wpas_dbus_getter_bss_age(
  3610. const struct wpa_dbus_property_desc *property_desc,
  3611. DBusMessageIter *iter, DBusError *error, void *user_data)
  3612. {
  3613. struct bss_handler_args *args = user_data;
  3614. struct wpa_bss *res;
  3615. struct os_reltime now, diff = { 0, 0 };
  3616. u32 age;
  3617. res = get_bss_helper(args, error, __func__);
  3618. if (!res)
  3619. return FALSE;
  3620. os_get_reltime(&now);
  3621. os_reltime_sub(&now, &res->last_update, &diff);
  3622. age = diff.sec > 0 ? diff.sec : 0;
  3623. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT32, &age,
  3624. error);
  3625. }
  3626. /**
  3627. * wpas_dbus_getter_enabled - Check whether network is enabled or disabled
  3628. * @iter: Pointer to incoming dbus message iter
  3629. * @error: Location to store error on failure
  3630. * @user_data: Function specific data
  3631. * Returns: TRUE on success, FALSE on failure
  3632. *
  3633. * Getter for "enabled" property of a configured network.
  3634. */
  3635. dbus_bool_t wpas_dbus_getter_enabled(
  3636. const struct wpa_dbus_property_desc *property_desc,
  3637. DBusMessageIter *iter, DBusError *error, void *user_data)
  3638. {
  3639. struct network_handler_args *net = user_data;
  3640. dbus_bool_t enabled = net->ssid->disabled ? FALSE : TRUE;
  3641. return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
  3642. &enabled, error);
  3643. }
  3644. /**
  3645. * wpas_dbus_setter_enabled - Mark a configured network as enabled or disabled
  3646. * @iter: Pointer to incoming dbus message iter
  3647. * @error: Location to store error on failure
  3648. * @user_data: Function specific data
  3649. * Returns: TRUE on success, FALSE on failure
  3650. *
  3651. * Setter for "Enabled" property of a configured network.
  3652. */
  3653. dbus_bool_t wpas_dbus_setter_enabled(
  3654. const struct wpa_dbus_property_desc *property_desc,
  3655. DBusMessageIter *iter, DBusError *error, void *user_data)
  3656. {
  3657. struct network_handler_args *net = user_data;
  3658. struct wpa_supplicant *wpa_s;
  3659. struct wpa_ssid *ssid;
  3660. dbus_bool_t enable;
  3661. if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_BOOLEAN,
  3662. &enable))
  3663. return FALSE;
  3664. wpa_s = net->wpa_s;
  3665. ssid = net->ssid;
  3666. if (enable)
  3667. wpa_supplicant_enable_network(wpa_s, ssid);
  3668. else
  3669. wpa_supplicant_disable_network(wpa_s, ssid);
  3670. return TRUE;
  3671. }
  3672. /**
  3673. * wpas_dbus_getter_network_properties - Get options for a configured network
  3674. * @iter: Pointer to incoming dbus message iter
  3675. * @error: Location to store error on failure
  3676. * @user_data: Function specific data
  3677. * Returns: TRUE on success, FALSE on failure
  3678. *
  3679. * Getter for "Properties" property of a configured network.
  3680. */
  3681. dbus_bool_t wpas_dbus_getter_network_properties(
  3682. const struct wpa_dbus_property_desc *property_desc,
  3683. DBusMessageIter *iter, DBusError *error, void *user_data)
  3684. {
  3685. struct network_handler_args *net = user_data;
  3686. DBusMessageIter variant_iter, dict_iter;
  3687. char **iterator;
  3688. char **props = wpa_config_get_all(net->ssid, 1);
  3689. dbus_bool_t success = FALSE;
  3690. if (!props) {
  3691. dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
  3692. return FALSE;
  3693. }
  3694. if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, "a{sv}",
  3695. &variant_iter) ||
  3696. !wpa_dbus_dict_open_write(&variant_iter, &dict_iter)) {
  3697. dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
  3698. goto out;
  3699. }
  3700. iterator = props;
  3701. while (*iterator) {
  3702. if (!wpa_dbus_dict_append_string(&dict_iter, *iterator,
  3703. *(iterator + 1))) {
  3704. dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY,
  3705. "no memory");
  3706. goto out;
  3707. }
  3708. iterator += 2;
  3709. }
  3710. if (!wpa_dbus_dict_close_write(&variant_iter, &dict_iter) ||
  3711. !dbus_message_iter_close_container(iter, &variant_iter)) {
  3712. dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
  3713. goto out;
  3714. }
  3715. success = TRUE;
  3716. out:
  3717. iterator = props;
  3718. while (*iterator) {
  3719. os_free(*iterator);
  3720. iterator++;
  3721. }
  3722. os_free(props);
  3723. return success;
  3724. }
  3725. /**
  3726. * wpas_dbus_setter_network_properties - Set options for a configured network
  3727. * @iter: Pointer to incoming dbus message iter
  3728. * @error: Location to store error on failure
  3729. * @user_data: Function specific data
  3730. * Returns: TRUE on success, FALSE on failure
  3731. *
  3732. * Setter for "Properties" property of a configured network.
  3733. */
  3734. dbus_bool_t wpas_dbus_setter_network_properties(
  3735. const struct wpa_dbus_property_desc *property_desc,
  3736. DBusMessageIter *iter, DBusError *error, void *user_data)
  3737. {
  3738. struct network_handler_args *net = user_data;
  3739. struct wpa_ssid *ssid = net->ssid;
  3740. DBusMessageIter variant_iter;
  3741. dbus_message_iter_recurse(iter, &variant_iter);
  3742. return set_network_properties(net->wpa_s, ssid, &variant_iter, error);
  3743. }
  3744. #ifdef CONFIG_AP
  3745. DBusMessage * wpas_dbus_handler_subscribe_preq(
  3746. DBusMessage *message, struct wpa_supplicant *wpa_s)
  3747. {
  3748. struct wpas_dbus_priv *priv = wpa_s->global->dbus;
  3749. char *name;
  3750. if (wpa_s->preq_notify_peer != NULL) {
  3751. if (os_strcmp(dbus_message_get_sender(message),
  3752. wpa_s->preq_notify_peer) == 0)
  3753. return NULL;
  3754. return dbus_message_new_error(message,
  3755. WPAS_DBUS_ERROR_SUBSCRIPTION_IN_USE,
  3756. "Another application is already subscribed");
  3757. }
  3758. name = os_strdup(dbus_message_get_sender(message));
  3759. if (!name)
  3760. return wpas_dbus_error_no_memory(message);
  3761. wpa_s->preq_notify_peer = name;
  3762. /* Subscribe to clean up if application closes socket */
  3763. wpas_dbus_subscribe_noc(priv);
  3764. /*
  3765. * Double-check it's still alive to make sure that we didn't
  3766. * miss the NameOwnerChanged signal, e.g. while strdup'ing.
  3767. */
  3768. if (!dbus_bus_name_has_owner(priv->con, name, NULL)) {
  3769. /*
  3770. * Application no longer exists, clean up.
  3771. * The return value is irrelevant now.
  3772. *
  3773. * Need to check if the NameOwnerChanged handling
  3774. * already cleaned up because we have processed
  3775. * DBus messages while checking if the name still
  3776. * has an owner.
  3777. */
  3778. if (!wpa_s->preq_notify_peer)
  3779. return NULL;
  3780. os_free(wpa_s->preq_notify_peer);
  3781. wpa_s->preq_notify_peer = NULL;
  3782. wpas_dbus_unsubscribe_noc(priv);
  3783. }
  3784. return NULL;
  3785. }
  3786. DBusMessage * wpas_dbus_handler_unsubscribe_preq(
  3787. DBusMessage *message, struct wpa_supplicant *wpa_s)
  3788. {
  3789. struct wpas_dbus_priv *priv = wpa_s->global->dbus;
  3790. if (!wpa_s->preq_notify_peer)
  3791. return dbus_message_new_error(message,
  3792. WPAS_DBUS_ERROR_NO_SUBSCRIPTION,
  3793. "Not subscribed");
  3794. if (os_strcmp(wpa_s->preq_notify_peer,
  3795. dbus_message_get_sender(message)))
  3796. return dbus_message_new_error(message,
  3797. WPAS_DBUS_ERROR_SUBSCRIPTION_EPERM,
  3798. "Can't unsubscribe others");
  3799. os_free(wpa_s->preq_notify_peer);
  3800. wpa_s->preq_notify_peer = NULL;
  3801. wpas_dbus_unsubscribe_noc(priv);
  3802. return NULL;
  3803. }
  3804. void wpas_dbus_signal_preq(struct wpa_supplicant *wpa_s,
  3805. const u8 *addr, const u8 *dst, const u8 *bssid,
  3806. const u8 *ie, size_t ie_len, u32 ssi_signal)
  3807. {
  3808. DBusMessage *msg;
  3809. DBusMessageIter iter, dict_iter;
  3810. struct wpas_dbus_priv *priv = wpa_s->global->dbus;
  3811. /* Do nothing if the control interface is not turned on */
  3812. if (priv == NULL || !wpa_s->dbus_new_path)
  3813. return;
  3814. if (wpa_s->preq_notify_peer == NULL)
  3815. return;
  3816. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  3817. WPAS_DBUS_NEW_IFACE_INTERFACE,
  3818. "ProbeRequest");
  3819. if (msg == NULL)
  3820. return;
  3821. dbus_message_set_destination(msg, wpa_s->preq_notify_peer);
  3822. dbus_message_iter_init_append(msg, &iter);
  3823. if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  3824. (addr && !wpa_dbus_dict_append_byte_array(&dict_iter, "addr",
  3825. (const char *) addr,
  3826. ETH_ALEN)) ||
  3827. (dst && !wpa_dbus_dict_append_byte_array(&dict_iter, "dst",
  3828. (const char *) dst,
  3829. ETH_ALEN)) ||
  3830. (bssid && !wpa_dbus_dict_append_byte_array(&dict_iter, "bssid",
  3831. (const char *) bssid,
  3832. ETH_ALEN)) ||
  3833. (ie && ie_len && !wpa_dbus_dict_append_byte_array(&dict_iter, "ies",
  3834. (const char *) ie,
  3835. ie_len)) ||
  3836. (ssi_signal && !wpa_dbus_dict_append_int32(&dict_iter, "signal",
  3837. ssi_signal)) ||
  3838. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  3839. goto fail;
  3840. dbus_connection_send(priv->con, msg, NULL);
  3841. goto out;
  3842. fail:
  3843. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  3844. out:
  3845. dbus_message_unref(msg);
  3846. }
  3847. #endif /* CONFIG_AP */
  3848. DBusMessage * wpas_dbus_handler_vendor_elem_add(DBusMessage *message,
  3849. struct wpa_supplicant *wpa_s)
  3850. {
  3851. u8 *ielems;
  3852. int len;
  3853. struct ieee802_11_elems elems;
  3854. dbus_int32_t frame_id;
  3855. DBusMessageIter iter, array;
  3856. dbus_message_iter_init(message, &iter);
  3857. dbus_message_iter_get_basic(&iter, &frame_id);
  3858. if (frame_id < 0 || frame_id >= NUM_VENDOR_ELEM_FRAMES) {
  3859. return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
  3860. "Invalid ID");
  3861. }
  3862. dbus_message_iter_next(&iter);
  3863. dbus_message_iter_recurse(&iter, &array);
  3864. dbus_message_iter_get_fixed_array(&array, &ielems, &len);
  3865. if (!ielems || len == 0) {
  3866. return dbus_message_new_error(
  3867. message, DBUS_ERROR_INVALID_ARGS, "Invalid value");
  3868. }
  3869. if (ieee802_11_parse_elems(ielems, len, &elems, 0) == ParseFailed) {
  3870. return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
  3871. "Parse error");
  3872. }
  3873. wpa_s = wpas_vendor_elem(wpa_s, frame_id);
  3874. if (!wpa_s->vendor_elem[frame_id]) {
  3875. wpa_s->vendor_elem[frame_id] = wpabuf_alloc_copy(ielems, len);
  3876. wpas_vendor_elem_update(wpa_s);
  3877. return NULL;
  3878. }
  3879. if (wpabuf_resize(&wpa_s->vendor_elem[frame_id], len) < 0) {
  3880. return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
  3881. "Resize error");
  3882. }
  3883. wpabuf_put_data(wpa_s->vendor_elem[frame_id], ielems, len);
  3884. wpas_vendor_elem_update(wpa_s);
  3885. return NULL;
  3886. }
  3887. DBusMessage * wpas_dbus_handler_vendor_elem_get(DBusMessage *message,
  3888. struct wpa_supplicant *wpa_s)
  3889. {
  3890. DBusMessage *reply;
  3891. DBusMessageIter iter, array_iter;
  3892. dbus_int32_t frame_id;
  3893. const u8 *elem;
  3894. size_t elem_len;
  3895. dbus_message_iter_init(message, &iter);
  3896. dbus_message_iter_get_basic(&iter, &frame_id);
  3897. if (frame_id < 0 || frame_id >= NUM_VENDOR_ELEM_FRAMES) {
  3898. return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
  3899. "Invalid ID");
  3900. }
  3901. wpa_s = wpas_vendor_elem(wpa_s, frame_id);
  3902. if (!wpa_s->vendor_elem[frame_id]) {
  3903. return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
  3904. "ID value does not exist");
  3905. }
  3906. reply = dbus_message_new_method_return(message);
  3907. if (!reply)
  3908. return wpas_dbus_error_no_memory(message);
  3909. dbus_message_iter_init_append(reply, &iter);
  3910. elem = wpabuf_head_u8(wpa_s->vendor_elem[frame_id]);
  3911. elem_len = wpabuf_len(wpa_s->vendor_elem[frame_id]);
  3912. if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
  3913. DBUS_TYPE_BYTE_AS_STRING,
  3914. &array_iter) ||
  3915. !dbus_message_iter_append_fixed_array(&array_iter, DBUS_TYPE_BYTE,
  3916. &elem, elem_len) ||
  3917. !dbus_message_iter_close_container(&iter, &array_iter)) {
  3918. dbus_message_unref(reply);
  3919. reply = wpas_dbus_error_no_memory(message);
  3920. }
  3921. return reply;
  3922. }
  3923. DBusMessage * wpas_dbus_handler_vendor_elem_remove(DBusMessage *message,
  3924. struct wpa_supplicant *wpa_s)
  3925. {
  3926. u8 *ielems;
  3927. int len;
  3928. struct ieee802_11_elems elems;
  3929. DBusMessageIter iter, array;
  3930. dbus_int32_t frame_id;
  3931. dbus_message_iter_init(message, &iter);
  3932. dbus_message_iter_get_basic(&iter, &frame_id);
  3933. if (frame_id < 0 || frame_id >= NUM_VENDOR_ELEM_FRAMES) {
  3934. return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
  3935. "Invalid ID");
  3936. }
  3937. dbus_message_iter_next(&iter);
  3938. dbus_message_iter_recurse(&iter, &array);
  3939. dbus_message_iter_get_fixed_array(&array, &ielems, &len);
  3940. if (!ielems || len == 0) {
  3941. return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
  3942. "Invalid value");
  3943. }
  3944. wpa_s = wpas_vendor_elem(wpa_s, frame_id);
  3945. if (len == 1 && *ielems == '*') {
  3946. wpabuf_free(wpa_s->vendor_elem[frame_id]);
  3947. wpa_s->vendor_elem[frame_id] = NULL;
  3948. wpas_vendor_elem_update(wpa_s);
  3949. return NULL;
  3950. }
  3951. if (!wpa_s->vendor_elem[frame_id]) {
  3952. return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
  3953. "ID value does not exist");
  3954. }
  3955. if (ieee802_11_parse_elems(ielems, len, &elems, 0) == ParseFailed) {
  3956. return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
  3957. "Parse error");
  3958. }
  3959. if (wpas_vendor_elem_remove(wpa_s, frame_id, ielems, len) == 0)
  3960. return NULL;
  3961. return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
  3962. "Not found");
  3963. }