您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605
  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 program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * Alternatively, this software may be distributed under the terms of BSD
  12. * license.
  13. *
  14. * See README and COPYING for more details.
  15. */
  16. #include "includes.h"
  17. #include "common.h"
  18. #include "wps/wps.h"
  19. #include "../config.h"
  20. #include "../wpa_supplicant_i.h"
  21. #include "../bss.h"
  22. #include "dbus_new_helpers.h"
  23. #include "dbus_dict_helpers.h"
  24. #include "dbus_new.h"
  25. #include "dbus_new_handlers.h"
  26. #include "dbus_common.h"
  27. #include "dbus_common_i.h"
  28. /**
  29. * wpas_dbus_signal_interface - Send a interface related event signal
  30. * @wpa_s: %wpa_supplicant network interface data
  31. * @sig_name: signal name - InterfaceAdded or InterfaceRemoved
  32. * @properties: Whether to add second argument with object properties
  33. *
  34. * Notify listeners about event related with interface
  35. */
  36. static void wpas_dbus_signal_interface(struct wpa_supplicant *wpa_s,
  37. const char *sig_name, int properties)
  38. {
  39. struct wpas_dbus_priv *iface;
  40. DBusMessage *msg;
  41. DBusMessageIter iter, iter_dict;
  42. iface = wpa_s->global->dbus;
  43. /* Do nothing if the control interface is not turned on */
  44. if (iface == NULL)
  45. return;
  46. msg = dbus_message_new_signal(WPAS_DBUS_NEW_PATH,
  47. WPAS_DBUS_NEW_INTERFACE, sig_name);
  48. if (msg == NULL)
  49. return;
  50. dbus_message_iter_init_append(msg, &iter);
  51. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  52. &wpa_s->dbus_new_path))
  53. goto err;
  54. if (properties) {
  55. if (!wpa_dbus_dict_open_write(&iter, &iter_dict))
  56. goto err;
  57. wpa_dbus_get_object_properties(iface, wpa_s->dbus_new_path,
  58. WPAS_DBUS_NEW_IFACE_INTERFACE,
  59. &iter_dict);
  60. if (!wpa_dbus_dict_close_write(&iter, &iter_dict))
  61. goto err;
  62. }
  63. dbus_connection_send(iface->con, msg, NULL);
  64. dbus_message_unref(msg);
  65. return;
  66. err:
  67. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  68. dbus_message_unref(msg);
  69. }
  70. /**
  71. * wpas_dbus_signal_interface_added - Send a interface created signal
  72. * @wpa_s: %wpa_supplicant network interface data
  73. *
  74. * Notify listeners about creating new interface
  75. */
  76. static void wpas_dbus_signal_interface_added(struct wpa_supplicant *wpa_s)
  77. {
  78. wpas_dbus_signal_interface(wpa_s, "InterfaceAdded", TRUE);
  79. }
  80. /**
  81. * wpas_dbus_signal_interface_removed - Send a interface removed signal
  82. * @wpa_s: %wpa_supplicant network interface data
  83. *
  84. * Notify listeners about removing interface
  85. */
  86. static void wpas_dbus_signal_interface_removed(struct wpa_supplicant *wpa_s)
  87. {
  88. wpas_dbus_signal_interface(wpa_s, "InterfaceRemoved", FALSE);
  89. }
  90. /**
  91. * wpas_dbus_signal_scan_done - send scan done signal
  92. * @wpa_s: %wpa_supplicant network interface data
  93. * @success: indicates if scanning succeed or failed
  94. *
  95. * Notify listeners about finishing a scan
  96. */
  97. void wpas_dbus_signal_scan_done(struct wpa_supplicant *wpa_s, int success)
  98. {
  99. struct wpas_dbus_priv *iface;
  100. DBusMessage *msg;
  101. dbus_bool_t succ;
  102. iface = wpa_s->global->dbus;
  103. /* Do nothing if the control interface is not turned on */
  104. if (iface == NULL)
  105. return;
  106. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  107. WPAS_DBUS_NEW_IFACE_INTERFACE,
  108. "ScanDone");
  109. if (msg == NULL)
  110. return;
  111. succ = success ? TRUE : FALSE;
  112. if (dbus_message_append_args(msg, DBUS_TYPE_BOOLEAN, &succ,
  113. DBUS_TYPE_INVALID))
  114. dbus_connection_send(iface->con, msg, NULL);
  115. else
  116. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  117. dbus_message_unref(msg);
  118. }
  119. /**
  120. * wpas_dbus_signal_blob - Send a BSS related event signal
  121. * @wpa_s: %wpa_supplicant network interface data
  122. * @bss_obj_path: BSS object path
  123. * @sig_name: signal name - BSSAdded or BSSRemoved
  124. * @properties: Whether to add second argument with object properties
  125. *
  126. * Notify listeners about event related with BSS
  127. */
  128. static void wpas_dbus_signal_bss(struct wpa_supplicant *wpa_s,
  129. const char *bss_obj_path,
  130. const char *sig_name, int properties)
  131. {
  132. struct wpas_dbus_priv *iface;
  133. DBusMessage *msg;
  134. DBusMessageIter iter, iter_dict;
  135. iface = wpa_s->global->dbus;
  136. /* Do nothing if the control interface is not turned on */
  137. if (iface == NULL)
  138. return;
  139. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  140. WPAS_DBUS_NEW_IFACE_INTERFACE,
  141. sig_name);
  142. if (msg == NULL)
  143. return;
  144. dbus_message_iter_init_append(msg, &iter);
  145. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  146. &bss_obj_path))
  147. goto err;
  148. if (properties) {
  149. if (!wpa_dbus_dict_open_write(&iter, &iter_dict))
  150. goto err;
  151. wpa_dbus_get_object_properties(iface, bss_obj_path,
  152. WPAS_DBUS_NEW_IFACE_BSS,
  153. &iter_dict);
  154. if (!wpa_dbus_dict_close_write(&iter, &iter_dict))
  155. goto err;
  156. }
  157. dbus_connection_send(iface->con, msg, NULL);
  158. dbus_message_unref(msg);
  159. return;
  160. err:
  161. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  162. dbus_message_unref(msg);
  163. }
  164. /**
  165. * wpas_dbus_signal_bss_added - Send a BSS added signal
  166. * @wpa_s: %wpa_supplicant network interface data
  167. * @bss_obj_path: new BSS object path
  168. *
  169. * Notify listeners about adding new BSS
  170. */
  171. static void wpas_dbus_signal_bss_added(struct wpa_supplicant *wpa_s,
  172. const char *bss_obj_path)
  173. {
  174. wpas_dbus_signal_bss(wpa_s, bss_obj_path, "BSSAdded", TRUE);
  175. }
  176. /**
  177. * wpas_dbus_signal_bss_removed - Send a BSS removed signal
  178. * @wpa_s: %wpa_supplicant network interface data
  179. * @bss_obj_path: BSS object path
  180. *
  181. * Notify listeners about removing BSS
  182. */
  183. static void wpas_dbus_signal_bss_removed(struct wpa_supplicant *wpa_s,
  184. const char *bss_obj_path)
  185. {
  186. wpas_dbus_signal_bss(wpa_s, bss_obj_path, "BSSRemoved", FALSE);
  187. }
  188. /**
  189. * wpas_dbus_signal_blob - Send a blob related event signal
  190. * @wpa_s: %wpa_supplicant network interface data
  191. * @name: blob name
  192. * @sig_name: signal name - BlobAdded or BlobRemoved
  193. *
  194. * Notify listeners about event related with blob
  195. */
  196. static void wpas_dbus_signal_blob(struct wpa_supplicant *wpa_s,
  197. const char *name, const char *sig_name)
  198. {
  199. struct wpas_dbus_priv *iface;
  200. DBusMessage *msg;
  201. iface = wpa_s->global->dbus;
  202. /* Do nothing if the control interface is not turned on */
  203. if (iface == NULL)
  204. return;
  205. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  206. WPAS_DBUS_NEW_IFACE_INTERFACE,
  207. sig_name);
  208. if (msg == NULL)
  209. return;
  210. if (dbus_message_append_args(msg, DBUS_TYPE_STRING, &name,
  211. DBUS_TYPE_INVALID))
  212. dbus_connection_send(iface->con, msg, NULL);
  213. else
  214. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  215. dbus_message_unref(msg);
  216. }
  217. /**
  218. * wpas_dbus_signal_blob_added - Send a blob added signal
  219. * @wpa_s: %wpa_supplicant network interface data
  220. * @name: blob name
  221. *
  222. * Notify listeners about adding a new blob
  223. */
  224. void wpas_dbus_signal_blob_added(struct wpa_supplicant *wpa_s,
  225. const char *name)
  226. {
  227. wpas_dbus_signal_blob(wpa_s, name, "BlobAdded");
  228. }
  229. /**
  230. * wpas_dbus_signal_blob_removed - Send a blob removed signal
  231. * @wpa_s: %wpa_supplicant network interface data
  232. * @name: blob name
  233. *
  234. * Notify listeners about removing blob
  235. */
  236. void wpas_dbus_signal_blob_removed(struct wpa_supplicant *wpa_s,
  237. const char *name)
  238. {
  239. wpas_dbus_signal_blob(wpa_s, name, "BlobRemoved");
  240. }
  241. /**
  242. * wpas_dbus_signal_network - Send a network related event signal
  243. * @wpa_s: %wpa_supplicant network interface data
  244. * @id: new network id
  245. * @sig_name: signal name - NetworkAdded, NetworkRemoved or NetworkSelected
  246. * @properties: determines if add second argument with object properties
  247. *
  248. * Notify listeners about event related with configured network
  249. */
  250. static void wpas_dbus_signal_network(struct wpa_supplicant *wpa_s,
  251. int id, const char *sig_name,
  252. int properties)
  253. {
  254. struct wpas_dbus_priv *iface;
  255. DBusMessage *msg;
  256. DBusMessageIter iter, iter_dict;
  257. char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
  258. iface = wpa_s->global->dbus;
  259. /* Do nothing if the control interface is not turned on */
  260. if (iface == NULL)
  261. return;
  262. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  263. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  264. wpa_s->dbus_new_path, id);
  265. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  266. WPAS_DBUS_NEW_IFACE_INTERFACE,
  267. sig_name);
  268. if (msg == NULL)
  269. return;
  270. dbus_message_iter_init_append(msg, &iter);
  271. path = net_obj_path;
  272. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
  273. &path))
  274. goto err;
  275. if (properties) {
  276. if (!wpa_dbus_dict_open_write(&iter, &iter_dict))
  277. goto err;
  278. wpa_dbus_get_object_properties(iface, net_obj_path,
  279. WPAS_DBUS_NEW_IFACE_NETWORK,
  280. &iter_dict);
  281. if (!wpa_dbus_dict_close_write(&iter, &iter_dict))
  282. goto err;
  283. }
  284. dbus_connection_send(iface->con, msg, NULL);
  285. dbus_message_unref(msg);
  286. return;
  287. err:
  288. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  289. dbus_message_unref(msg);
  290. }
  291. /**
  292. * wpas_dbus_signal_network_added - Send a network added signal
  293. * @wpa_s: %wpa_supplicant network interface data
  294. * @id: new network id
  295. *
  296. * Notify listeners about adding new network
  297. */
  298. static void wpas_dbus_signal_network_added(struct wpa_supplicant *wpa_s,
  299. int id)
  300. {
  301. wpas_dbus_signal_network(wpa_s, id, "NetworkAdded", TRUE);
  302. }
  303. /**
  304. * wpas_dbus_signal_network_removed - Send a network removed signal
  305. * @wpa_s: %wpa_supplicant network interface data
  306. * @id: network id
  307. *
  308. * Notify listeners about removing a network
  309. */
  310. static void wpas_dbus_signal_network_removed(struct wpa_supplicant *wpa_s,
  311. int id)
  312. {
  313. wpas_dbus_signal_network(wpa_s, id, "NetworkRemoved", FALSE);
  314. }
  315. /**
  316. * wpas_dbus_signal_network_selected - Send a network selected signal
  317. * @wpa_s: %wpa_supplicant network interface data
  318. * @id: network id
  319. *
  320. * Notify listeners about selecting a network
  321. */
  322. void wpas_dbus_signal_network_selected(struct wpa_supplicant *wpa_s, int id)
  323. {
  324. wpas_dbus_signal_network(wpa_s, id, "NetworkSelected", FALSE);
  325. }
  326. /**
  327. * wpas_dbus_signal_network_enabled_changed - Signals Enabled property changes
  328. * @wpa_s: %wpa_supplicant network interface data
  329. * @ssid: configured network which Enabled property has changed
  330. *
  331. * Sends PropertyChanged signals containing new value of Enabled property
  332. * for specified network
  333. */
  334. void wpas_dbus_signal_network_enabled_changed(struct wpa_supplicant *wpa_s,
  335. struct wpa_ssid *ssid)
  336. {
  337. char path[WPAS_DBUS_OBJECT_PATH_MAX];
  338. os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
  339. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
  340. wpa_s->dbus_new_path, ssid->id);
  341. wpa_dbus_mark_property_changed(wpa_s->global->dbus, path,
  342. WPAS_DBUS_NEW_IFACE_NETWORK, "Enabled");
  343. }
  344. #ifdef CONFIG_WPS
  345. /**
  346. * wpas_dbus_signal_wps_event_success - Signals Success WPS event
  347. * @wpa_s: %wpa_supplicant network interface data
  348. *
  349. * Sends Event dbus signal with name "success" and empty dict as arguments
  350. */
  351. void wpas_dbus_signal_wps_event_success(struct wpa_supplicant *wpa_s)
  352. {
  353. DBusMessage *msg;
  354. DBusMessageIter iter, dict_iter;
  355. struct wpas_dbus_priv *iface;
  356. char *key = "success";
  357. iface = wpa_s->global->dbus;
  358. /* Do nothing if the control interface is not turned on */
  359. if (iface == NULL)
  360. return;
  361. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  362. WPAS_DBUS_NEW_IFACE_WPS, "Event");
  363. if (msg == NULL)
  364. return;
  365. dbus_message_iter_init_append(msg, &iter);
  366. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
  367. !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  368. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  369. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  370. else
  371. dbus_connection_send(iface->con, msg, NULL);
  372. dbus_message_unref(msg);
  373. }
  374. /**
  375. * wpas_dbus_signal_wps_event_fail - Signals Fail WPS event
  376. * @wpa_s: %wpa_supplicant network interface data
  377. *
  378. * Sends Event dbus signal with name "fail" and dictionary containing
  379. * "msg field with fail message number (int32) as arguments
  380. */
  381. void wpas_dbus_signal_wps_event_fail(struct wpa_supplicant *wpa_s,
  382. struct wps_event_fail *fail)
  383. {
  384. DBusMessage *msg;
  385. DBusMessageIter iter, dict_iter;
  386. struct wpas_dbus_priv *iface;
  387. char *key = "fail";
  388. iface = wpa_s->global->dbus;
  389. /* Do nothing if the control interface is not turned on */
  390. if (iface == NULL)
  391. return;
  392. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  393. WPAS_DBUS_NEW_IFACE_WPS, "Event");
  394. if (msg == NULL)
  395. return;
  396. dbus_message_iter_init_append(msg, &iter);
  397. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
  398. !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  399. !wpa_dbus_dict_append_int32(&dict_iter, "msg", fail->msg) ||
  400. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  401. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  402. else
  403. dbus_connection_send(iface->con, msg, NULL);
  404. dbus_message_unref(msg);
  405. }
  406. /**
  407. * wpas_dbus_signal_wps_event_m2d - Signals M2D WPS event
  408. * @wpa_s: %wpa_supplicant network interface data
  409. *
  410. * Sends Event dbus signal with name "m2d" and dictionary containing
  411. * fields of wps_event_m2d structure.
  412. */
  413. void wpas_dbus_signal_wps_event_m2d(struct wpa_supplicant *wpa_s,
  414. struct wps_event_m2d *m2d)
  415. {
  416. DBusMessage *msg;
  417. DBusMessageIter iter, dict_iter;
  418. struct wpas_dbus_priv *iface;
  419. char *key = "m2d";
  420. iface = wpa_s->global->dbus;
  421. /* Do nothing if the control interface is not turned on */
  422. if (iface == NULL)
  423. return;
  424. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  425. WPAS_DBUS_NEW_IFACE_WPS, "Event");
  426. if (msg == NULL)
  427. return;
  428. dbus_message_iter_init_append(msg, &iter);
  429. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
  430. !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  431. !wpa_dbus_dict_append_uint16(&dict_iter, "config_methods",
  432. m2d->config_methods) ||
  433. !wpa_dbus_dict_append_byte_array(&dict_iter, "manufacturer",
  434. (const char *) m2d->manufacturer,
  435. m2d->manufacturer_len) ||
  436. !wpa_dbus_dict_append_byte_array(&dict_iter, "model_name",
  437. (const char *) m2d->model_name,
  438. m2d->model_name_len) ||
  439. !wpa_dbus_dict_append_byte_array(&dict_iter, "model_number",
  440. (const char *) m2d->model_number,
  441. m2d->model_number_len) ||
  442. !wpa_dbus_dict_append_byte_array(&dict_iter, "serial_number",
  443. (const char *)
  444. m2d->serial_number,
  445. m2d->serial_number_len) ||
  446. !wpa_dbus_dict_append_byte_array(&dict_iter, "dev_name",
  447. (const char *) m2d->dev_name,
  448. m2d->dev_name_len) ||
  449. !wpa_dbus_dict_append_byte_array(&dict_iter, "primary_dev_type",
  450. (const char *)
  451. m2d->primary_dev_type, 8) ||
  452. !wpa_dbus_dict_append_uint16(&dict_iter, "config_error",
  453. m2d->config_error) ||
  454. !wpa_dbus_dict_append_uint16(&dict_iter, "dev_password_id",
  455. m2d->dev_password_id) ||
  456. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  457. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  458. else
  459. dbus_connection_send(iface->con, msg, NULL);
  460. dbus_message_unref(msg);
  461. }
  462. /**
  463. * wpas_dbus_signal_wps_cred - Signals new credentials
  464. * @wpa_s: %wpa_supplicant network interface data
  465. *
  466. * Sends signal with credentials in directory argument
  467. */
  468. void wpas_dbus_signal_wps_cred(struct wpa_supplicant *wpa_s,
  469. const struct wps_credential *cred)
  470. {
  471. DBusMessage *msg;
  472. DBusMessageIter iter, dict_iter;
  473. struct wpas_dbus_priv *iface;
  474. char *auth_type[6]; /* we have six possible authorization types */
  475. int at_num = 0;
  476. char *encr_type[4]; /* we have four possible encryption types */
  477. int et_num = 0;
  478. iface = wpa_s->global->dbus;
  479. /* Do nothing if the control interface is not turned on */
  480. if (iface == NULL)
  481. return;
  482. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  483. WPAS_DBUS_NEW_IFACE_WPS,
  484. "Credentials");
  485. if (msg == NULL)
  486. return;
  487. dbus_message_iter_init_append(msg, &iter);
  488. if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
  489. goto nomem;
  490. if (cred->auth_type & WPS_AUTH_OPEN)
  491. auth_type[at_num++] = "open";
  492. if (cred->auth_type & WPS_AUTH_WPAPSK)
  493. auth_type[at_num++] = "wpa-psk";
  494. if (cred->auth_type & WPS_AUTH_SHARED)
  495. auth_type[at_num++] = "shared";
  496. if (cred->auth_type & WPS_AUTH_WPA)
  497. auth_type[at_num++] = "wpa-eap";
  498. if (cred->auth_type & WPS_AUTH_WPA2)
  499. auth_type[at_num++] = "wpa2-eap";
  500. if (cred->auth_type & WPS_AUTH_WPA2PSK)
  501. auth_type[at_num++] =
  502. "wpa2-psk";
  503. if (cred->encr_type & WPS_ENCR_NONE)
  504. encr_type[et_num++] = "none";
  505. if (cred->encr_type & WPS_ENCR_WEP)
  506. encr_type[et_num++] = "wep";
  507. if (cred->encr_type & WPS_ENCR_TKIP)
  508. encr_type[et_num++] = "tkip";
  509. if (cred->encr_type & WPS_ENCR_AES)
  510. encr_type[et_num++] = "aes";
  511. if (wpa_s->current_ssid) {
  512. if (!wpa_dbus_dict_append_byte_array(
  513. &dict_iter, "BSSID",
  514. (const char *) wpa_s->current_ssid->bssid,
  515. ETH_ALEN))
  516. goto nomem;
  517. }
  518. if (!wpa_dbus_dict_append_byte_array(&dict_iter, "SSID",
  519. (const char *) cred->ssid,
  520. cred->ssid_len) ||
  521. !wpa_dbus_dict_append_string_array(&dict_iter, "AuthType",
  522. (const char **) auth_type,
  523. at_num) ||
  524. !wpa_dbus_dict_append_string_array(&dict_iter, "EncrType",
  525. (const char **) encr_type,
  526. et_num) ||
  527. !wpa_dbus_dict_append_byte_array(&dict_iter, "Key",
  528. (const char *) cred->key,
  529. cred->key_len) ||
  530. !wpa_dbus_dict_append_uint32(&dict_iter, "KeyIndex",
  531. cred->key_idx) ||
  532. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  533. goto nomem;
  534. dbus_connection_send(iface->con, msg, NULL);
  535. nomem:
  536. dbus_message_unref(msg);
  537. }
  538. #endif /* CONFIG_WPS */
  539. /**
  540. * wpas_dbus_signal_prop_changed - Signals change of property
  541. * @wpa_s: %wpa_supplicant network interface data
  542. * @property: indicates which property has changed
  543. *
  544. * Sends ProertyChanged signals with path, interface and arguments
  545. * depending on which property has changed.
  546. */
  547. void wpas_dbus_signal_prop_changed(struct wpa_supplicant *wpa_s,
  548. enum wpas_dbus_prop property)
  549. {
  550. WPADBusPropertyAccessor getter;
  551. char *prop;
  552. if (wpa_s->dbus_new_path == NULL)
  553. return; /* Skip signal since D-Bus setup is not yet ready */
  554. switch (property) {
  555. case WPAS_DBUS_PROP_AP_SCAN:
  556. getter = (WPADBusPropertyAccessor) wpas_dbus_getter_ap_scan;
  557. prop = "ApScan";
  558. break;
  559. case WPAS_DBUS_PROP_SCANNING:
  560. getter = (WPADBusPropertyAccessor) wpas_dbus_getter_scanning;
  561. prop = "Scanning";
  562. break;
  563. case WPAS_DBUS_PROP_STATE:
  564. getter = (WPADBusPropertyAccessor) wpas_dbus_getter_state;
  565. prop = "State";
  566. break;
  567. case WPAS_DBUS_PROP_CURRENT_BSS:
  568. getter = (WPADBusPropertyAccessor)
  569. wpas_dbus_getter_current_bss;
  570. prop = "CurrentBSS";
  571. break;
  572. case WPAS_DBUS_PROP_CURRENT_NETWORK:
  573. getter = (WPADBusPropertyAccessor)
  574. wpas_dbus_getter_current_network;
  575. prop = "CurrentNetwork";
  576. break;
  577. case WPAS_DBUS_PROP_BSSS:
  578. getter = (WPADBusPropertyAccessor) wpas_dbus_getter_bsss;
  579. prop = "BSSs";
  580. break;
  581. case WPAS_DBUS_PROP_CURRENT_AUTH_MODE:
  582. getter = (WPADBusPropertyAccessor)
  583. wpas_dbus_getter_current_auth_mode;
  584. prop = "CurrentAuthMode";
  585. break;
  586. default:
  587. wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
  588. __func__, property);
  589. return;
  590. }
  591. wpa_dbus_mark_property_changed(wpa_s->global->dbus,
  592. wpa_s->dbus_new_path,
  593. WPAS_DBUS_NEW_IFACE_INTERFACE, prop);
  594. }
  595. /**
  596. * wpas_dbus_bss_signal_prop_changed - Signals change of BSS property
  597. * @wpa_s: %wpa_supplicant network interface data
  598. * @property: indicates which property has changed
  599. * @id: unique BSS identifier
  600. *
  601. * Sends PropertyChanged signals with path, interface, and arguments depending
  602. * on which property has changed.
  603. */
  604. void wpas_dbus_bss_signal_prop_changed(struct wpa_supplicant *wpa_s,
  605. enum wpas_dbus_bss_prop property,
  606. unsigned int id)
  607. {
  608. char path[WPAS_DBUS_OBJECT_PATH_MAX];
  609. char *prop;
  610. switch (property) {
  611. case WPAS_DBUS_BSS_PROP_SIGNAL:
  612. prop = "Signal";
  613. break;
  614. case WPAS_DBUS_BSS_PROP_FREQ:
  615. prop = "Frequency";
  616. break;
  617. case WPAS_DBUS_BSS_PROP_MODE:
  618. prop = "Mode";
  619. break;
  620. case WPAS_DBUS_BSS_PROP_PRIVACY:
  621. prop = "Privacy";
  622. break;
  623. case WPAS_DBUS_BSS_PROP_RATES:
  624. prop = "Rates";
  625. break;
  626. case WPAS_DBUS_BSS_PROP_WPA:
  627. prop = "WPA";
  628. break;
  629. case WPAS_DBUS_BSS_PROP_RSN:
  630. prop = "RSN";
  631. break;
  632. case WPAS_DBUS_BSS_PROP_IES:
  633. prop = "IEs";
  634. break;
  635. default:
  636. wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
  637. __func__, property);
  638. return;
  639. }
  640. os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
  641. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  642. wpa_s->dbus_new_path, id);
  643. wpa_dbus_mark_property_changed(wpa_s->global->dbus, path,
  644. WPAS_DBUS_NEW_IFACE_BSS, prop);
  645. }
  646. /**
  647. * wpas_dbus_signal_debug_level_changed - Signals change of debug param
  648. * @global: wpa_global structure
  649. *
  650. * Sends ProertyChanged signals informing that debug level has changed.
  651. */
  652. void wpas_dbus_signal_debug_level_changed(struct wpa_global *global)
  653. {
  654. wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
  655. WPAS_DBUS_NEW_INTERFACE,
  656. "DebugLevel");
  657. }
  658. /**
  659. * wpas_dbus_signal_debug_timestamp_changed - Signals change of debug param
  660. * @global: wpa_global structure
  661. *
  662. * Sends ProertyChanged signals informing that debug timestamp has changed.
  663. */
  664. void wpas_dbus_signal_debug_timestamp_changed(struct wpa_global *global)
  665. {
  666. wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
  667. WPAS_DBUS_NEW_INTERFACE,
  668. "DebugTimestamp");
  669. }
  670. /**
  671. * wpas_dbus_signal_debug_show_keys_changed - Signals change of debug param
  672. * @global: wpa_global structure
  673. *
  674. * Sends ProertyChanged signals informing that debug show_keys has changed.
  675. */
  676. void wpas_dbus_signal_debug_show_keys_changed(struct wpa_global *global)
  677. {
  678. wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
  679. WPAS_DBUS_NEW_INTERFACE,
  680. "DebugShowKeys");
  681. }
  682. static void wpas_dbus_register(struct wpa_dbus_object_desc *obj_desc,
  683. void *priv,
  684. WPADBusArgumentFreeFunction priv_free,
  685. const struct wpa_dbus_method_desc *methods,
  686. const struct wpa_dbus_property_desc *properties,
  687. const struct wpa_dbus_signal_desc *signals)
  688. {
  689. int n;
  690. obj_desc->user_data = priv;
  691. obj_desc->user_data_free_func = priv_free;
  692. obj_desc->methods = methods;
  693. obj_desc->properties = properties;
  694. obj_desc->signals = signals;
  695. for (n = 0; properties && properties->dbus_property; properties++)
  696. n++;
  697. obj_desc->prop_changed_flags = os_zalloc(n);
  698. if (!obj_desc->prop_changed_flags)
  699. wpa_printf(MSG_DEBUG, "dbus: %s: can't register handlers",
  700. __func__);
  701. }
  702. static const struct wpa_dbus_method_desc wpas_dbus_global_methods[] = {
  703. { "CreateInterface", WPAS_DBUS_NEW_INTERFACE,
  704. (WPADBusMethodHandler) &wpas_dbus_handler_create_interface,
  705. {
  706. { "args", "a{sv}", ARG_IN },
  707. { "path", "o", ARG_OUT },
  708. END_ARGS
  709. }
  710. },
  711. { "RemoveInterface", WPAS_DBUS_NEW_INTERFACE,
  712. (WPADBusMethodHandler) &wpas_dbus_handler_remove_interface,
  713. {
  714. { "path", "o", ARG_IN },
  715. END_ARGS
  716. }
  717. },
  718. { "GetInterface", WPAS_DBUS_NEW_INTERFACE,
  719. (WPADBusMethodHandler) &wpas_dbus_handler_get_interface,
  720. {
  721. { "ifname", "s", ARG_IN },
  722. { "path", "o", ARG_OUT },
  723. END_ARGS
  724. }
  725. },
  726. { NULL, NULL, NULL, { END_ARGS } }
  727. };
  728. static const struct wpa_dbus_property_desc wpas_dbus_global_properties[] = {
  729. { "DebugLevel", WPAS_DBUS_NEW_INTERFACE, "s",
  730. (WPADBusPropertyAccessor) wpas_dbus_getter_debug_level,
  731. (WPADBusPropertyAccessor) wpas_dbus_setter_debug_level,
  732. RW
  733. },
  734. { "DebugTimestamp", WPAS_DBUS_NEW_INTERFACE, "b",
  735. (WPADBusPropertyAccessor) wpas_dbus_getter_debug_timestamp,
  736. (WPADBusPropertyAccessor) wpas_dbus_setter_debug_timestamp,
  737. RW
  738. },
  739. { "DebugShowKeys", WPAS_DBUS_NEW_INTERFACE, "b",
  740. (WPADBusPropertyAccessor) wpas_dbus_getter_debug_show_keys,
  741. (WPADBusPropertyAccessor) wpas_dbus_setter_debug_show_keys,
  742. RW
  743. },
  744. { "Interfaces", WPAS_DBUS_NEW_INTERFACE, "ao",
  745. (WPADBusPropertyAccessor) &wpas_dbus_getter_interfaces,
  746. NULL,
  747. R
  748. },
  749. { "EapMethods", WPAS_DBUS_NEW_INTERFACE, "as",
  750. (WPADBusPropertyAccessor) wpas_dbus_getter_eap_methods,
  751. NULL,
  752. R
  753. },
  754. { NULL, NULL, NULL, NULL, NULL, 0 }
  755. };
  756. static const struct wpa_dbus_signal_desc wpas_dbus_global_signals[] = {
  757. { "InterfaceAdded", WPAS_DBUS_NEW_INTERFACE,
  758. {
  759. { "path", "o", ARG_OUT },
  760. { "properties", "a{sv}", ARG_OUT },
  761. END_ARGS
  762. }
  763. },
  764. { "InterfaceRemoved", WPAS_DBUS_NEW_INTERFACE,
  765. {
  766. { "path", "o", ARG_OUT },
  767. END_ARGS
  768. }
  769. },
  770. { "PropertiesChanged", WPAS_DBUS_NEW_INTERFACE,
  771. {
  772. { "properties", "a{sv}", ARG_OUT },
  773. END_ARGS
  774. }
  775. },
  776. { NULL, NULL, { END_ARGS } }
  777. };
  778. /**
  779. * wpas_dbus_ctrl_iface_init - Initialize dbus control interface
  780. * @global: Pointer to global data from wpa_supplicant_init()
  781. * Returns: 0 on success or -1 on failure
  782. *
  783. * Initialize the dbus control interface for wpa_supplicantand and start
  784. * receiving commands from external programs over the bus.
  785. */
  786. int wpas_dbus_ctrl_iface_init(struct wpas_dbus_priv *priv)
  787. {
  788. struct wpa_dbus_object_desc *obj_desc;
  789. int ret;
  790. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  791. if (!obj_desc) {
  792. wpa_printf(MSG_ERROR, "Not enough memory "
  793. "to create object description");
  794. return -1;
  795. }
  796. wpas_dbus_register(obj_desc, priv->global, NULL,
  797. wpas_dbus_global_methods,
  798. wpas_dbus_global_properties,
  799. wpas_dbus_global_signals);
  800. wpa_printf(MSG_DEBUG, "dbus: Register D-Bus object '%s'",
  801. WPAS_DBUS_NEW_PATH);
  802. ret = wpa_dbus_ctrl_iface_init(priv, WPAS_DBUS_NEW_PATH,
  803. WPAS_DBUS_NEW_SERVICE,
  804. obj_desc);
  805. if (ret < 0)
  806. free_dbus_object_desc(obj_desc);
  807. else
  808. priv->dbus_new_initialized = 1;
  809. return ret;
  810. }
  811. /**
  812. * wpas_dbus_ctrl_iface_deinit - Deinitialize dbus ctrl interface for
  813. * wpa_supplicant
  814. * @iface: Pointer to dbus private data from wpas_dbus_init()
  815. *
  816. * Deinitialize the dbus control interface that was initialized with
  817. * wpas_dbus_ctrl_iface_init().
  818. */
  819. void wpas_dbus_ctrl_iface_deinit(struct wpas_dbus_priv *iface)
  820. {
  821. if (!iface->dbus_new_initialized)
  822. return;
  823. wpa_printf(MSG_DEBUG, "dbus: Unregister D-Bus object '%s'",
  824. WPAS_DBUS_NEW_PATH);
  825. dbus_connection_unregister_object_path(iface->con,
  826. WPAS_DBUS_NEW_PATH);
  827. }
  828. static void wpa_dbus_free(void *ptr)
  829. {
  830. os_free(ptr);
  831. }
  832. static const struct wpa_dbus_property_desc wpas_dbus_network_properties[] = {
  833. { "Properties", WPAS_DBUS_NEW_IFACE_NETWORK, "a{sv}",
  834. (WPADBusPropertyAccessor) wpas_dbus_getter_network_properties,
  835. (WPADBusPropertyAccessor) wpas_dbus_setter_network_properties,
  836. RW
  837. },
  838. { "Enabled", WPAS_DBUS_NEW_IFACE_NETWORK, "b",
  839. (WPADBusPropertyAccessor) wpas_dbus_getter_enabled,
  840. (WPADBusPropertyAccessor) wpas_dbus_setter_enabled,
  841. RW
  842. },
  843. { NULL, NULL, NULL, NULL, NULL, 0 }
  844. };
  845. static const struct wpa_dbus_signal_desc wpas_dbus_network_signals[] = {
  846. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_NETWORK,
  847. {
  848. { "properties", "a{sv}", ARG_OUT },
  849. END_ARGS
  850. }
  851. },
  852. { NULL, NULL, { END_ARGS } }
  853. };
  854. /**
  855. * wpas_dbus_register_network - Register a configured network with dbus
  856. * @wpa_s: wpa_supplicant interface structure
  857. * @ssid: network configuration data
  858. * Returns: 0 on success, -1 on failure
  859. *
  860. * Registers network representing object with dbus
  861. */
  862. int wpas_dbus_register_network(struct wpa_supplicant *wpa_s,
  863. struct wpa_ssid *ssid)
  864. {
  865. struct wpas_dbus_priv *ctrl_iface;
  866. struct wpa_dbus_object_desc *obj_desc;
  867. struct network_handler_args *arg;
  868. char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  869. /* Do nothing if the control interface is not turned on */
  870. if (wpa_s == NULL || wpa_s->global == NULL)
  871. return 0;
  872. ctrl_iface = wpa_s->global->dbus;
  873. if (ctrl_iface == NULL)
  874. return 0;
  875. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  876. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  877. wpa_s->dbus_new_path, ssid->id);
  878. wpa_printf(MSG_DEBUG, "dbus: Register network object '%s'",
  879. net_obj_path);
  880. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  881. if (!obj_desc) {
  882. wpa_printf(MSG_ERROR, "Not enough memory "
  883. "to create object description");
  884. goto err;
  885. }
  886. /* allocate memory for handlers arguments */
  887. arg = os_zalloc(sizeof(struct network_handler_args));
  888. if (!arg) {
  889. wpa_printf(MSG_ERROR, "Not enough memory "
  890. "to create arguments for method");
  891. goto err;
  892. }
  893. arg->wpa_s = wpa_s;
  894. arg->ssid = ssid;
  895. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  896. wpas_dbus_network_properties,
  897. wpas_dbus_network_signals);
  898. if (wpa_dbus_register_object_per_iface(ctrl_iface, net_obj_path,
  899. wpa_s->ifname, obj_desc))
  900. goto err;
  901. wpas_dbus_signal_network_added(wpa_s, ssid->id);
  902. return 0;
  903. err:
  904. free_dbus_object_desc(obj_desc);
  905. return -1;
  906. }
  907. /**
  908. * wpas_dbus_unregister_network - Unregister a configured network from dbus
  909. * @wpa_s: wpa_supplicant interface structure
  910. * @nid: network id
  911. * Returns: 0 on success, -1 on failure
  912. *
  913. * Unregisters network representing object from dbus
  914. */
  915. int wpas_dbus_unregister_network(struct wpa_supplicant *wpa_s, int nid)
  916. {
  917. struct wpas_dbus_priv *ctrl_iface;
  918. char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  919. int ret;
  920. /* Do nothing if the control interface is not turned on */
  921. if (wpa_s == NULL || wpa_s->global == NULL ||
  922. wpa_s->dbus_new_path == NULL)
  923. return 0;
  924. ctrl_iface = wpa_s->global->dbus;
  925. if (ctrl_iface == NULL)
  926. return 0;
  927. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  928. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  929. wpa_s->dbus_new_path, nid);
  930. wpa_printf(MSG_DEBUG, "dbus: Unregister network object '%s'",
  931. net_obj_path);
  932. ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, net_obj_path);
  933. if (!ret)
  934. wpas_dbus_signal_network_removed(wpa_s, nid);
  935. return ret;
  936. }
  937. static const struct wpa_dbus_property_desc wpas_dbus_bss_properties[] = {
  938. { "SSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
  939. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_ssid,
  940. NULL,
  941. R
  942. },
  943. { "BSSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
  944. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_bssid,
  945. NULL,
  946. R
  947. },
  948. { "Privacy", WPAS_DBUS_NEW_IFACE_BSS, "b",
  949. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_privacy,
  950. NULL,
  951. R
  952. },
  953. { "Mode", WPAS_DBUS_NEW_IFACE_BSS, "s",
  954. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_mode,
  955. NULL,
  956. R
  957. },
  958. { "Signal", WPAS_DBUS_NEW_IFACE_BSS, "n",
  959. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_signal,
  960. NULL,
  961. R
  962. },
  963. { "Frequency", WPAS_DBUS_NEW_IFACE_BSS, "q",
  964. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_frequency,
  965. NULL,
  966. R
  967. },
  968. { "Rates", WPAS_DBUS_NEW_IFACE_BSS, "au",
  969. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_rates,
  970. NULL,
  971. R
  972. },
  973. { "WPA", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
  974. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_wpa,
  975. NULL,
  976. R
  977. },
  978. { "RSN", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
  979. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_rsn,
  980. NULL,
  981. R
  982. },
  983. { "IEs", WPAS_DBUS_NEW_IFACE_BSS, "ay",
  984. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_ies,
  985. NULL,
  986. R
  987. },
  988. { NULL, NULL, NULL, NULL, NULL, 0 }
  989. };
  990. static const struct wpa_dbus_signal_desc wpas_dbus_bss_signals[] = {
  991. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_BSS,
  992. {
  993. { "properties", "a{sv}", ARG_OUT },
  994. END_ARGS
  995. }
  996. },
  997. { NULL, NULL, { END_ARGS } }
  998. };
  999. /**
  1000. * wpas_dbus_unregister_bss - Unregister a scanned BSS from dbus
  1001. * @wpa_s: wpa_supplicant interface structure
  1002. * @bssid: scanned network bssid
  1003. * @id: unique BSS identifier
  1004. * Returns: 0 on success, -1 on failure
  1005. *
  1006. * Unregisters BSS representing object from dbus
  1007. */
  1008. int wpas_dbus_unregister_bss(struct wpa_supplicant *wpa_s,
  1009. u8 bssid[ETH_ALEN], unsigned int id)
  1010. {
  1011. struct wpas_dbus_priv *ctrl_iface;
  1012. char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  1013. /* Do nothing if the control interface is not turned on */
  1014. if (wpa_s == NULL || wpa_s->global == NULL)
  1015. return 0;
  1016. ctrl_iface = wpa_s->global->dbus;
  1017. if (ctrl_iface == NULL)
  1018. return 0;
  1019. os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1020. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  1021. wpa_s->dbus_new_path, id);
  1022. wpa_printf(MSG_DEBUG, "dbus: Unregister BSS object '%s'",
  1023. bss_obj_path);
  1024. if (wpa_dbus_unregister_object_per_iface(ctrl_iface, bss_obj_path)) {
  1025. wpa_printf(MSG_ERROR, "dbus: Cannot unregister BSS object %s",
  1026. bss_obj_path);
  1027. return -1;
  1028. }
  1029. wpas_dbus_signal_bss_removed(wpa_s, bss_obj_path);
  1030. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSSS);
  1031. return 0;
  1032. }
  1033. /**
  1034. * wpas_dbus_register_bss - Register a scanned BSS with dbus
  1035. * @wpa_s: wpa_supplicant interface structure
  1036. * @bssid: scanned network bssid
  1037. * @id: unique BSS identifier
  1038. * Returns: 0 on success, -1 on failure
  1039. *
  1040. * Registers BSS representing object with dbus
  1041. */
  1042. int wpas_dbus_register_bss(struct wpa_supplicant *wpa_s,
  1043. u8 bssid[ETH_ALEN], unsigned int id)
  1044. {
  1045. struct wpas_dbus_priv *ctrl_iface;
  1046. struct wpa_dbus_object_desc *obj_desc;
  1047. char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  1048. struct bss_handler_args *arg;
  1049. /* Do nothing if the control interface is not turned on */
  1050. if (wpa_s == NULL || wpa_s->global == NULL)
  1051. return 0;
  1052. ctrl_iface = wpa_s->global->dbus;
  1053. if (ctrl_iface == NULL)
  1054. return 0;
  1055. os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1056. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  1057. wpa_s->dbus_new_path, id);
  1058. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  1059. if (!obj_desc) {
  1060. wpa_printf(MSG_ERROR, "Not enough memory "
  1061. "to create object description");
  1062. goto err;
  1063. }
  1064. arg = os_zalloc(sizeof(struct bss_handler_args));
  1065. if (!arg) {
  1066. wpa_printf(MSG_ERROR, "Not enough memory "
  1067. "to create arguments for handler");
  1068. goto err;
  1069. }
  1070. arg->wpa_s = wpa_s;
  1071. arg->id = id;
  1072. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  1073. wpas_dbus_bss_properties,
  1074. wpas_dbus_bss_signals);
  1075. wpa_printf(MSG_DEBUG, "dbus: Register BSS object '%s'",
  1076. bss_obj_path);
  1077. if (wpa_dbus_register_object_per_iface(ctrl_iface, bss_obj_path,
  1078. wpa_s->ifname, obj_desc)) {
  1079. wpa_printf(MSG_ERROR,
  1080. "Cannot register BSSID dbus object %s.",
  1081. bss_obj_path);
  1082. goto err;
  1083. }
  1084. wpas_dbus_signal_bss_added(wpa_s, bss_obj_path);
  1085. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSSS);
  1086. return 0;
  1087. err:
  1088. free_dbus_object_desc(obj_desc);
  1089. return -1;
  1090. }
  1091. static const struct wpa_dbus_method_desc wpas_dbus_interface_methods[] = {
  1092. { "Scan", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1093. (WPADBusMethodHandler) &wpas_dbus_handler_scan,
  1094. {
  1095. { "args", "a{sv}", ARG_IN },
  1096. END_ARGS
  1097. }
  1098. },
  1099. { "Disconnect", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1100. (WPADBusMethodHandler) &wpas_dbus_handler_disconnect,
  1101. {
  1102. END_ARGS
  1103. }
  1104. },
  1105. { "AddNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1106. (WPADBusMethodHandler) &wpas_dbus_handler_add_network,
  1107. {
  1108. { "args", "a{sv}", ARG_IN },
  1109. { "path", "o", ARG_OUT },
  1110. END_ARGS
  1111. }
  1112. },
  1113. { "RemoveNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1114. (WPADBusMethodHandler) &wpas_dbus_handler_remove_network,
  1115. {
  1116. { "path", "o", ARG_IN },
  1117. END_ARGS
  1118. }
  1119. },
  1120. { "RemoveAllNetworks", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1121. (WPADBusMethodHandler) &wpas_dbus_handler_remove_all_networks,
  1122. {
  1123. END_ARGS
  1124. }
  1125. },
  1126. { "SelectNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1127. (WPADBusMethodHandler) &wpas_dbus_handler_select_network,
  1128. {
  1129. { "path", "o", ARG_IN },
  1130. END_ARGS
  1131. }
  1132. },
  1133. { "AddBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1134. (WPADBusMethodHandler) &wpas_dbus_handler_add_blob,
  1135. {
  1136. { "name", "s", ARG_IN },
  1137. { "data", "ay", ARG_IN },
  1138. END_ARGS
  1139. }
  1140. },
  1141. { "GetBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1142. (WPADBusMethodHandler) &wpas_dbus_handler_get_blob,
  1143. {
  1144. { "name", "s", ARG_IN },
  1145. { "data", "ay", ARG_OUT },
  1146. END_ARGS
  1147. }
  1148. },
  1149. { "RemoveBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1150. (WPADBusMethodHandler) &wpas_dbus_handler_remove_blob,
  1151. {
  1152. { "name", "s", ARG_IN },
  1153. END_ARGS
  1154. }
  1155. },
  1156. #ifdef CONFIG_WPS
  1157. { "Start", WPAS_DBUS_NEW_IFACE_WPS,
  1158. (WPADBusMethodHandler) &wpas_dbus_handler_wps_start,
  1159. {
  1160. { "args", "a{sv}", ARG_IN },
  1161. { "output", "a{sv}", ARG_OUT },
  1162. END_ARGS
  1163. }
  1164. },
  1165. #endif /* CONFIG_WPS */
  1166. { "FlushBSS", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1167. (WPADBusMethodHandler) &wpas_dbus_handler_flush_bss,
  1168. {
  1169. { "age", "u", ARG_IN },
  1170. END_ARGS
  1171. }
  1172. },
  1173. { NULL, NULL, NULL, { END_ARGS } }
  1174. };
  1175. static const struct wpa_dbus_property_desc wpas_dbus_interface_properties[] = {
  1176. { "Capabilities", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{sv}",
  1177. (WPADBusPropertyAccessor) wpas_dbus_getter_capabilities,
  1178. NULL, R
  1179. },
  1180. { "State", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  1181. (WPADBusPropertyAccessor) wpas_dbus_getter_state,
  1182. NULL, R
  1183. },
  1184. { "Scanning", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
  1185. (WPADBusPropertyAccessor) wpas_dbus_getter_scanning,
  1186. NULL, R
  1187. },
  1188. { "ApScan", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  1189. (WPADBusPropertyAccessor) wpas_dbus_getter_ap_scan,
  1190. (WPADBusPropertyAccessor) wpas_dbus_setter_ap_scan,
  1191. RW
  1192. },
  1193. { "BSSExpireAge", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  1194. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_expire_age,
  1195. (WPADBusPropertyAccessor) wpas_dbus_setter_bss_expire_age,
  1196. RW
  1197. },
  1198. { "BSSExpireCount", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  1199. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_expire_count,
  1200. (WPADBusPropertyAccessor) wpas_dbus_setter_bss_expire_count,
  1201. RW
  1202. },
  1203. { "Country", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  1204. (WPADBusPropertyAccessor) wpas_dbus_getter_country,
  1205. (WPADBusPropertyAccessor) wpas_dbus_setter_country,
  1206. RW
  1207. },
  1208. { "Ifname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  1209. (WPADBusPropertyAccessor) wpas_dbus_getter_ifname,
  1210. NULL, R
  1211. },
  1212. { "Driver", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  1213. (WPADBusPropertyAccessor) wpas_dbus_getter_driver,
  1214. NULL, R
  1215. },
  1216. { "BridgeIfname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  1217. (WPADBusPropertyAccessor) wpas_dbus_getter_bridge_ifname,
  1218. NULL, R
  1219. },
  1220. { "CurrentBSS", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
  1221. (WPADBusPropertyAccessor) wpas_dbus_getter_current_bss,
  1222. NULL, R
  1223. },
  1224. { "CurrentNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
  1225. (WPADBusPropertyAccessor) wpas_dbus_getter_current_network,
  1226. NULL, R
  1227. },
  1228. { "CurrentAuthMode", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  1229. (WPADBusPropertyAccessor) wpas_dbus_getter_current_auth_mode,
  1230. NULL, R
  1231. },
  1232. { "Blobs", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{say}",
  1233. (WPADBusPropertyAccessor) wpas_dbus_getter_blobs,
  1234. NULL, R
  1235. },
  1236. { "BSSs", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
  1237. (WPADBusPropertyAccessor) wpas_dbus_getter_bsss,
  1238. NULL, R
  1239. },
  1240. { "Networks", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
  1241. (WPADBusPropertyAccessor) wpas_dbus_getter_networks,
  1242. NULL, R
  1243. },
  1244. #ifdef CONFIG_WPS
  1245. { "ProcessCredentials", WPAS_DBUS_NEW_IFACE_WPS, "b",
  1246. (WPADBusPropertyAccessor) wpas_dbus_getter_process_credentials,
  1247. (WPADBusPropertyAccessor) wpas_dbus_setter_process_credentials,
  1248. RW
  1249. },
  1250. #endif /* CONFIG_WPS */
  1251. { NULL, NULL, NULL, NULL, NULL, 0 }
  1252. };
  1253. static const struct wpa_dbus_signal_desc wpas_dbus_interface_signals[] = {
  1254. { "ScanDone", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1255. {
  1256. { "success", "b", ARG_OUT },
  1257. END_ARGS
  1258. }
  1259. },
  1260. { "BSSAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1261. {
  1262. { "path", "o", ARG_OUT },
  1263. { "properties", "a{sv}", ARG_OUT },
  1264. END_ARGS
  1265. }
  1266. },
  1267. { "BSSRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1268. {
  1269. { "path", "o", ARG_OUT },
  1270. END_ARGS
  1271. }
  1272. },
  1273. { "BlobAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1274. {
  1275. { "name", "s", ARG_OUT },
  1276. END_ARGS
  1277. }
  1278. },
  1279. { "BlobRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1280. {
  1281. { "name", "s", ARG_OUT },
  1282. END_ARGS
  1283. }
  1284. },
  1285. { "NetworkAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1286. {
  1287. { "path", "o", ARG_OUT },
  1288. { "properties", "a{sv}", ARG_OUT },
  1289. END_ARGS
  1290. }
  1291. },
  1292. { "NetworkRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1293. {
  1294. { "path", "o", ARG_OUT },
  1295. END_ARGS
  1296. }
  1297. },
  1298. { "NetworkSelected", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1299. {
  1300. { "path", "o", ARG_OUT },
  1301. END_ARGS
  1302. }
  1303. },
  1304. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1305. {
  1306. { "properties", "a{sv}", ARG_OUT },
  1307. END_ARGS
  1308. }
  1309. },
  1310. #ifdef CONFIG_WPS
  1311. { "Event", WPAS_DBUS_NEW_IFACE_WPS,
  1312. {
  1313. { "name", "s", ARG_OUT },
  1314. { "args", "a{sv}", ARG_OUT },
  1315. END_ARGS
  1316. }
  1317. },
  1318. { "Credentials", WPAS_DBUS_NEW_IFACE_WPS,
  1319. {
  1320. { "credentials", "a{sv}", ARG_OUT },
  1321. END_ARGS
  1322. }
  1323. },
  1324. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_WPS,
  1325. {
  1326. { "properties", "a{sv}", ARG_OUT },
  1327. END_ARGS
  1328. }
  1329. },
  1330. #endif /* CONFIG_WPS */
  1331. { NULL, NULL, { END_ARGS } }
  1332. };
  1333. int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s)
  1334. {
  1335. struct wpa_dbus_object_desc *obj_desc = NULL;
  1336. struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus;
  1337. int next;
  1338. /* Do nothing if the control interface is not turned on */
  1339. if (ctrl_iface == NULL)
  1340. return 0;
  1341. /* Create and set the interface's object path */
  1342. wpa_s->dbus_new_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
  1343. if (wpa_s->dbus_new_path == NULL)
  1344. return -1;
  1345. next = ctrl_iface->next_objid++;
  1346. os_snprintf(wpa_s->dbus_new_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1347. WPAS_DBUS_NEW_PATH_INTERFACES "/%u",
  1348. next);
  1349. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  1350. if (!obj_desc) {
  1351. wpa_printf(MSG_ERROR, "Not enough memory "
  1352. "to create object description");
  1353. goto err;
  1354. }
  1355. wpas_dbus_register(obj_desc, wpa_s, NULL, wpas_dbus_interface_methods,
  1356. wpas_dbus_interface_properties,
  1357. wpas_dbus_interface_signals);
  1358. wpa_printf(MSG_DEBUG, "dbus: Register interface object '%s'",
  1359. wpa_s->dbus_new_path);
  1360. if (wpa_dbus_register_object_per_iface(ctrl_iface,
  1361. wpa_s->dbus_new_path,
  1362. wpa_s->ifname, obj_desc))
  1363. goto err;
  1364. wpas_dbus_signal_interface_added(wpa_s);
  1365. return 0;
  1366. err:
  1367. os_free(wpa_s->dbus_new_path);
  1368. wpa_s->dbus_new_path = NULL;
  1369. free_dbus_object_desc(obj_desc);
  1370. return -1;
  1371. }
  1372. int wpas_dbus_unregister_interface(struct wpa_supplicant *wpa_s)
  1373. {
  1374. struct wpas_dbus_priv *ctrl_iface;
  1375. /* Do nothing if the control interface is not turned on */
  1376. if (wpa_s == NULL || wpa_s->global == NULL)
  1377. return 0;
  1378. ctrl_iface = wpa_s->global->dbus;
  1379. if (ctrl_iface == NULL)
  1380. return 0;
  1381. wpa_printf(MSG_DEBUG, "dbus: Unregister interface object '%s'",
  1382. wpa_s->dbus_new_path);
  1383. if (wpa_dbus_unregister_object_per_iface(ctrl_iface,
  1384. wpa_s->dbus_new_path))
  1385. return -1;
  1386. wpas_dbus_signal_interface_removed(wpa_s);
  1387. os_free(wpa_s->dbus_new_path);
  1388. wpa_s->dbus_new_path = NULL;
  1389. return 0;
  1390. }