dbus_new_handlers.c 112 KB

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