dbus_new_handlers.c 128 KB

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