dbus_new.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558
  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, 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_BSSID,
  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. switch (property) {
  553. case WPAS_DBUS_PROP_AP_SCAN:
  554. getter = (WPADBusPropertyAccessor) wpas_dbus_getter_ap_scan;
  555. prop = "ApScan";
  556. break;
  557. case WPAS_DBUS_PROP_SCANNING:
  558. getter = (WPADBusPropertyAccessor) wpas_dbus_getter_scanning;
  559. prop = "Scanning";
  560. break;
  561. case WPAS_DBUS_PROP_STATE:
  562. getter = (WPADBusPropertyAccessor) wpas_dbus_getter_state;
  563. prop = "State";
  564. break;
  565. case WPAS_DBUS_PROP_CURRENT_BSS:
  566. getter = (WPADBusPropertyAccessor)
  567. wpas_dbus_getter_current_bss;
  568. prop = "CurrentBSS";
  569. break;
  570. case WPAS_DBUS_PROP_CURRENT_NETWORK:
  571. getter = (WPADBusPropertyAccessor)
  572. wpas_dbus_getter_current_network;
  573. prop = "CurrentNetwork";
  574. break;
  575. default:
  576. wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
  577. __func__, property);
  578. return;
  579. }
  580. wpa_dbus_mark_property_changed(wpa_s->global->dbus,
  581. wpa_s->dbus_new_path,
  582. WPAS_DBUS_NEW_IFACE_INTERFACE, prop);
  583. }
  584. /**
  585. * wpas_dbus_bss_signal_prop_changed - Signals change of BSS property
  586. * @wpa_s: %wpa_supplicant network interface data
  587. * @property: indicates which property has changed
  588. * @id: unique BSS identifier
  589. *
  590. * Sends PropertyChanged signals with path, interface, and arguments depending
  591. * on which property has changed.
  592. */
  593. void wpas_dbus_bss_signal_prop_changed(struct wpa_supplicant *wpa_s,
  594. enum wpas_dbus_bss_prop property,
  595. unsigned int id)
  596. {
  597. char path[WPAS_DBUS_OBJECT_PATH_MAX];
  598. char *prop;
  599. switch (property) {
  600. case WPAS_DBUS_BSS_PROP_SIGNAL:
  601. prop = "Signal";
  602. break;
  603. case WPAS_DBUS_BSS_PROP_FREQ:
  604. prop = "Frequency";
  605. break;
  606. case WPAS_DBUS_BSS_PROP_MODE:
  607. prop = "Mode";
  608. break;
  609. case WPAS_DBUS_BSS_PROP_PRIVACY:
  610. prop = "Privacy";
  611. break;
  612. case WPAS_DBUS_BSS_PROP_RATES:
  613. prop = "Rates";
  614. break;
  615. case WPAS_DBUS_BSS_PROP_WPAIE:
  616. prop = "WPAIE";
  617. break;
  618. case WPAS_DBUS_BSS_PROP_RSNIE:
  619. prop = "RSNIE";
  620. break;
  621. case WPAS_DBUS_BSS_PROP_WPSIE:
  622. prop = "WPSIE";
  623. break;
  624. default:
  625. wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
  626. __func__, property);
  627. return;
  628. }
  629. os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
  630. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  631. wpa_s->dbus_new_path, id);
  632. wpa_dbus_mark_property_changed(wpa_s->global->dbus, path,
  633. WPAS_DBUS_NEW_IFACE_BSSID, prop);
  634. }
  635. /**
  636. * wpas_dbus_signal_debug_level_changed - Signals change of debug param
  637. * @global: wpa_global structure
  638. *
  639. * Sends ProertyChanged signals informing that debug level has changed.
  640. */
  641. void wpas_dbus_signal_debug_level_changed(struct wpa_global *global)
  642. {
  643. wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
  644. WPAS_DBUS_NEW_INTERFACE,
  645. "DebugLevel");
  646. }
  647. /**
  648. * wpas_dbus_signal_debug_timestamp_changed - Signals change of debug param
  649. * @global: wpa_global structure
  650. *
  651. * Sends ProertyChanged signals informing that debug timestamp has changed.
  652. */
  653. void wpas_dbus_signal_debug_timestamp_changed(struct wpa_global *global)
  654. {
  655. wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
  656. WPAS_DBUS_NEW_INTERFACE,
  657. "DebugTimestamp");
  658. }
  659. /**
  660. * wpas_dbus_signal_debug_show_keys_changed - Signals change of debug param
  661. * @global: wpa_global structure
  662. *
  663. * Sends ProertyChanged signals informing that debug show_keys has changed.
  664. */
  665. void wpas_dbus_signal_debug_show_keys_changed(struct wpa_global *global)
  666. {
  667. wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
  668. WPAS_DBUS_NEW_INTERFACE,
  669. "DebugShowKeys");
  670. }
  671. static void wpas_dbus_register(struct wpa_dbus_object_desc *obj_desc,
  672. void *priv,
  673. WPADBusArgumentFreeFunction priv_free,
  674. const struct wpa_dbus_method_desc *methods,
  675. const struct wpa_dbus_property_desc *properties,
  676. const struct wpa_dbus_signal_desc *signals)
  677. {
  678. int n;
  679. obj_desc->user_data = priv;
  680. obj_desc->user_data_free_func = priv_free;
  681. obj_desc->methods = methods;
  682. obj_desc->properties = properties;
  683. obj_desc->signals = signals;
  684. for (n = 0; properties && properties->dbus_property; properties++)
  685. n++;
  686. obj_desc->prop_changed_flags = os_zalloc(n);
  687. if (!obj_desc->prop_changed_flags)
  688. wpa_printf(MSG_DEBUG, "dbus: %s: can't register handlers",
  689. __func__);
  690. }
  691. static const struct wpa_dbus_method_desc wpas_dbus_global_methods[] = {
  692. { "CreateInterface", WPAS_DBUS_NEW_INTERFACE,
  693. (WPADBusMethodHandler) &wpas_dbus_handler_create_interface,
  694. {
  695. { "args", "a{sv}", ARG_IN },
  696. { "path", "o", ARG_OUT },
  697. END_ARGS
  698. }
  699. },
  700. { "RemoveInterface", WPAS_DBUS_NEW_INTERFACE,
  701. (WPADBusMethodHandler) &wpas_dbus_handler_remove_interface,
  702. {
  703. { "path", "o", ARG_IN },
  704. END_ARGS
  705. }
  706. },
  707. { "GetInterface", WPAS_DBUS_NEW_INTERFACE,
  708. (WPADBusMethodHandler) &wpas_dbus_handler_get_interface,
  709. {
  710. { "ifname", "s", ARG_IN },
  711. { "path", "o", ARG_OUT },
  712. END_ARGS
  713. }
  714. },
  715. { NULL, NULL, NULL, { END_ARGS } }
  716. };
  717. static const struct wpa_dbus_property_desc wpas_dbus_global_properties[] = {
  718. { "DebugLevel", WPAS_DBUS_NEW_INTERFACE, "s",
  719. (WPADBusPropertyAccessor) wpas_dbus_getter_debug_level,
  720. (WPADBusPropertyAccessor) wpas_dbus_setter_debug_level,
  721. RW
  722. },
  723. { "DebugTimestamp", WPAS_DBUS_NEW_INTERFACE, "b",
  724. (WPADBusPropertyAccessor) wpas_dbus_getter_debug_timestamp,
  725. (WPADBusPropertyAccessor) wpas_dbus_setter_debug_timestamp,
  726. RW
  727. },
  728. { "DebugShowKeys", WPAS_DBUS_NEW_INTERFACE, "b",
  729. (WPADBusPropertyAccessor) wpas_dbus_getter_debug_show_keys,
  730. (WPADBusPropertyAccessor) wpas_dbus_setter_debug_show_keys,
  731. RW
  732. },
  733. { "Interfaces", WPAS_DBUS_NEW_INTERFACE, "ao",
  734. (WPADBusPropertyAccessor) &wpas_dbus_getter_interfaces,
  735. NULL,
  736. R
  737. },
  738. { "EapMethods", WPAS_DBUS_NEW_INTERFACE, "as",
  739. (WPADBusPropertyAccessor) wpas_dbus_getter_eap_methods,
  740. NULL,
  741. R
  742. },
  743. { NULL, NULL, NULL, NULL, NULL, 0 }
  744. };
  745. static const struct wpa_dbus_signal_desc wpas_dbus_global_signals[] = {
  746. { "InterfaceAdded", WPAS_DBUS_NEW_INTERFACE,
  747. {
  748. { "path", "o", ARG_OUT },
  749. { "properties", "a{sv}", ARG_OUT },
  750. END_ARGS
  751. }
  752. },
  753. { "InterfaceRemoved", WPAS_DBUS_NEW_INTERFACE,
  754. {
  755. { "path", "o", ARG_OUT },
  756. END_ARGS
  757. }
  758. },
  759. { "PropertiesChanged", WPAS_DBUS_NEW_INTERFACE,
  760. {
  761. { "properties", "a{sv}", ARG_OUT },
  762. END_ARGS
  763. }
  764. },
  765. { NULL, NULL, { END_ARGS } }
  766. };
  767. /**
  768. * wpas_dbus_ctrl_iface_init - Initialize dbus control interface
  769. * @global: Pointer to global data from wpa_supplicant_init()
  770. * Returns: 0 on success or -1 on failure
  771. *
  772. * Initialize the dbus control interface for wpa_supplicantand and start
  773. * receiving commands from external programs over the bus.
  774. */
  775. int wpas_dbus_ctrl_iface_init(struct wpas_dbus_priv *priv)
  776. {
  777. struct wpa_dbus_object_desc *obj_desc;
  778. int ret;
  779. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  780. if (!obj_desc) {
  781. wpa_printf(MSG_ERROR, "Not enough memory "
  782. "to create object description");
  783. return -1;
  784. }
  785. wpas_dbus_register(obj_desc, priv->global, NULL,
  786. wpas_dbus_global_methods,
  787. wpas_dbus_global_properties,
  788. wpas_dbus_global_signals);
  789. wpa_printf(MSG_DEBUG, "dbus: Register D-Bus object '%s'",
  790. WPAS_DBUS_NEW_PATH);
  791. ret = wpa_dbus_ctrl_iface_init(priv, WPAS_DBUS_NEW_PATH,
  792. WPAS_DBUS_NEW_SERVICE,
  793. obj_desc);
  794. if (ret < 0)
  795. free_dbus_object_desc(obj_desc);
  796. else
  797. priv->dbus_new_initialized = 1;
  798. return ret;
  799. }
  800. /**
  801. * wpas_dbus_ctrl_iface_deinit - Deinitialize dbus ctrl interface for
  802. * wpa_supplicant
  803. * @iface: Pointer to dbus private data from wpas_dbus_init()
  804. *
  805. * Deinitialize the dbus control interface that was initialized with
  806. * wpas_dbus_ctrl_iface_init().
  807. */
  808. void wpas_dbus_ctrl_iface_deinit(struct wpas_dbus_priv *iface)
  809. {
  810. if (!iface->dbus_new_initialized)
  811. return;
  812. wpa_printf(MSG_DEBUG, "dbus: Unregister D-Bus object '%s'",
  813. WPAS_DBUS_NEW_PATH);
  814. dbus_connection_unregister_object_path(iface->con,
  815. WPAS_DBUS_NEW_PATH);
  816. }
  817. static void wpa_dbus_free(void *ptr)
  818. {
  819. os_free(ptr);
  820. }
  821. static const struct wpa_dbus_property_desc wpas_dbus_network_properties[] = {
  822. { "Properties", WPAS_DBUS_NEW_IFACE_NETWORK, "a{sv}",
  823. (WPADBusPropertyAccessor) wpas_dbus_getter_network_properties,
  824. (WPADBusPropertyAccessor) wpas_dbus_setter_network_properties,
  825. RW
  826. },
  827. { "Enabled", WPAS_DBUS_NEW_IFACE_NETWORK, "b",
  828. (WPADBusPropertyAccessor) wpas_dbus_getter_enabled,
  829. (WPADBusPropertyAccessor) wpas_dbus_setter_enabled,
  830. RW
  831. },
  832. { NULL, NULL, NULL, NULL, NULL, 0 }
  833. };
  834. static const struct wpa_dbus_signal_desc wpas_dbus_network_signals[] = {
  835. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_NETWORK,
  836. {
  837. { "properties", "a{sv}", ARG_OUT },
  838. END_ARGS
  839. }
  840. },
  841. { NULL, NULL, { END_ARGS } }
  842. };
  843. /**
  844. * wpas_dbus_register_network - Register a configured network with dbus
  845. * @wpa_s: wpa_supplicant interface structure
  846. * @ssid: network configuration data
  847. * Returns: 0 on success, -1 on failure
  848. *
  849. * Registers network representing object with dbus
  850. */
  851. int wpas_dbus_register_network(struct wpa_supplicant *wpa_s,
  852. struct wpa_ssid *ssid)
  853. {
  854. struct wpas_dbus_priv *ctrl_iface;
  855. struct wpa_dbus_object_desc *obj_desc;
  856. struct network_handler_args *arg;
  857. char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  858. /* Do nothing if the control interface is not turned on */
  859. if (wpa_s == NULL || wpa_s->global == NULL)
  860. return 0;
  861. ctrl_iface = wpa_s->global->dbus;
  862. if (ctrl_iface == NULL)
  863. return 0;
  864. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  865. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  866. wpa_s->dbus_new_path, ssid->id);
  867. wpa_printf(MSG_DEBUG, "dbus: Register network object '%s'",
  868. net_obj_path);
  869. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  870. if (!obj_desc) {
  871. wpa_printf(MSG_ERROR, "Not enough memory "
  872. "to create object description");
  873. goto err;
  874. }
  875. /* allocate memory for handlers arguments */
  876. arg = os_zalloc(sizeof(struct network_handler_args));
  877. if (!arg) {
  878. wpa_printf(MSG_ERROR, "Not enough memory "
  879. "to create arguments for method");
  880. goto err;
  881. }
  882. arg->wpa_s = wpa_s;
  883. arg->ssid = ssid;
  884. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  885. wpas_dbus_network_properties,
  886. wpas_dbus_network_signals);
  887. if (wpa_dbus_register_object_per_iface(ctrl_iface, net_obj_path,
  888. wpa_s->ifname, obj_desc))
  889. goto err;
  890. wpas_dbus_signal_network_added(wpa_s, ssid->id);
  891. return 0;
  892. err:
  893. free_dbus_object_desc(obj_desc);
  894. return -1;
  895. }
  896. /**
  897. * wpas_dbus_unregister_network - Unregister a configured network from dbus
  898. * @wpa_s: wpa_supplicant interface structure
  899. * @nid: network id
  900. * Returns: 0 on success, -1 on failure
  901. *
  902. * Unregisters network representing object from dbus
  903. */
  904. int wpas_dbus_unregister_network(struct wpa_supplicant *wpa_s, int nid)
  905. {
  906. struct wpas_dbus_priv *ctrl_iface;
  907. char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  908. int ret;
  909. /* Do nothing if the control interface is not turned on */
  910. if (wpa_s == NULL || wpa_s->global == NULL)
  911. return 0;
  912. ctrl_iface = wpa_s->global->dbus;
  913. if (ctrl_iface == NULL)
  914. return 0;
  915. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  916. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  917. wpa_s->dbus_new_path, nid);
  918. wpa_printf(MSG_DEBUG, "dbus: Unregister network object '%s'",
  919. net_obj_path);
  920. ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, net_obj_path);
  921. if (!ret)
  922. wpas_dbus_signal_network_removed(wpa_s, nid);
  923. return ret;
  924. }
  925. static const struct wpa_dbus_property_desc wpas_dbus_bss_properties[] = {
  926. { "SSID", WPAS_DBUS_NEW_IFACE_BSSID, "ay",
  927. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_ssid,
  928. NULL,
  929. R
  930. },
  931. { "BSSID", WPAS_DBUS_NEW_IFACE_BSSID, "ay",
  932. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_bssid,
  933. NULL,
  934. R
  935. },
  936. { "Privacy", WPAS_DBUS_NEW_IFACE_BSSID, "b",
  937. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_privacy,
  938. NULL,
  939. R
  940. },
  941. { "Mode", WPAS_DBUS_NEW_IFACE_BSSID, "s",
  942. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_mode,
  943. NULL,
  944. R
  945. },
  946. { "Signal", WPAS_DBUS_NEW_IFACE_BSSID, "n",
  947. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_signal,
  948. NULL,
  949. R
  950. },
  951. { "Frequency", WPAS_DBUS_NEW_IFACE_BSSID, "q",
  952. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_frequency,
  953. NULL,
  954. R
  955. },
  956. { "Rates", WPAS_DBUS_NEW_IFACE_BSSID, "au",
  957. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_rates,
  958. NULL,
  959. R
  960. },
  961. { "WPAIE", WPAS_DBUS_NEW_IFACE_BSSID, "ay",
  962. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_wpaie,
  963. NULL,
  964. R
  965. },
  966. { "RSNIE", WPAS_DBUS_NEW_IFACE_BSSID, "ay",
  967. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_rsnie,
  968. NULL,
  969. R
  970. },
  971. { "WPSIE", WPAS_DBUS_NEW_IFACE_BSSID, "ay",
  972. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_wpsie,
  973. NULL,
  974. R
  975. },
  976. { NULL, NULL, NULL, NULL, NULL, 0 }
  977. };
  978. static const struct wpa_dbus_signal_desc wpas_dbus_bss_signals[] = {
  979. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_BSSID,
  980. {
  981. { "properties", "a{sv}", ARG_OUT },
  982. END_ARGS
  983. }
  984. },
  985. { NULL, NULL, { END_ARGS } }
  986. };
  987. /**
  988. * wpas_dbus_unregister_bss - Unregister a scanned BSS from dbus
  989. * @wpa_s: wpa_supplicant interface structure
  990. * @bssid: scanned network bssid
  991. * @id: unique BSS identifier
  992. * Returns: 0 on success, -1 on failure
  993. *
  994. * Unregisters BSS representing object from dbus
  995. */
  996. int wpas_dbus_unregister_bss(struct wpa_supplicant *wpa_s,
  997. u8 bssid[ETH_ALEN], unsigned int id)
  998. {
  999. struct wpas_dbus_priv *ctrl_iface;
  1000. char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  1001. /* Do nothing if the control interface is not turned on */
  1002. if (wpa_s == NULL || wpa_s->global == NULL)
  1003. return 0;
  1004. ctrl_iface = wpa_s->global->dbus;
  1005. if (ctrl_iface == NULL)
  1006. return 0;
  1007. os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1008. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  1009. wpa_s->dbus_new_path, id);
  1010. wpa_printf(MSG_DEBUG, "dbus: Unregister BSS object '%s'",
  1011. bss_obj_path);
  1012. if (wpa_dbus_unregister_object_per_iface(ctrl_iface, bss_obj_path)) {
  1013. wpa_printf(MSG_ERROR, "dbus: Cannot unregister BSS object %s",
  1014. bss_obj_path);
  1015. return -1;
  1016. }
  1017. wpas_dbus_signal_bss_removed(wpa_s, bss_obj_path);
  1018. return 0;
  1019. }
  1020. /**
  1021. * wpas_dbus_register_bss - Register a scanned BSS with dbus
  1022. * @wpa_s: wpa_supplicant interface structure
  1023. * @bssid: scanned network bssid
  1024. * @id: unique BSS identifier
  1025. * Returns: 0 on success, -1 on failure
  1026. *
  1027. * Registers BSS representing object with dbus
  1028. */
  1029. int wpas_dbus_register_bss(struct wpa_supplicant *wpa_s,
  1030. u8 bssid[ETH_ALEN], unsigned int id)
  1031. {
  1032. struct wpas_dbus_priv *ctrl_iface;
  1033. struct wpa_dbus_object_desc *obj_desc;
  1034. char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  1035. struct bss_handler_args *arg;
  1036. /* Do nothing if the control interface is not turned on */
  1037. if (wpa_s == NULL || wpa_s->global == NULL)
  1038. return 0;
  1039. ctrl_iface = wpa_s->global->dbus;
  1040. if (ctrl_iface == NULL)
  1041. return 0;
  1042. os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1043. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  1044. wpa_s->dbus_new_path, id);
  1045. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  1046. if (!obj_desc) {
  1047. wpa_printf(MSG_ERROR, "Not enough memory "
  1048. "to create object description");
  1049. goto err;
  1050. }
  1051. arg = os_zalloc(sizeof(struct bss_handler_args));
  1052. if (!arg) {
  1053. wpa_printf(MSG_ERROR, "Not enough memory "
  1054. "to create arguments for handler");
  1055. goto err;
  1056. }
  1057. arg->wpa_s = wpa_s;
  1058. arg->id = id;
  1059. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  1060. wpas_dbus_bss_properties,
  1061. wpas_dbus_bss_signals);
  1062. wpa_printf(MSG_DEBUG, "dbus: Register BSS object '%s'",
  1063. bss_obj_path);
  1064. if (wpa_dbus_register_object_per_iface(ctrl_iface, bss_obj_path,
  1065. wpa_s->ifname, obj_desc)) {
  1066. wpa_printf(MSG_ERROR,
  1067. "Cannot register BSSID dbus object %s.",
  1068. bss_obj_path);
  1069. goto err;
  1070. }
  1071. wpas_dbus_signal_bss_added(wpa_s, bss_obj_path);
  1072. return 0;
  1073. err:
  1074. free_dbus_object_desc(obj_desc);
  1075. return -1;
  1076. }
  1077. static const struct wpa_dbus_method_desc wpas_dbus_interface_methods[] = {
  1078. { "Scan", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1079. (WPADBusMethodHandler) &wpas_dbus_handler_scan,
  1080. {
  1081. { "args", "a{sv}", ARG_IN },
  1082. END_ARGS
  1083. }
  1084. },
  1085. { "Disconnect", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1086. (WPADBusMethodHandler) &wpas_dbus_handler_disconnect,
  1087. {
  1088. END_ARGS
  1089. }
  1090. },
  1091. { "AddNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1092. (WPADBusMethodHandler) &wpas_dbus_handler_add_network,
  1093. {
  1094. { "args", "a{sv}", ARG_IN },
  1095. { "path", "o", ARG_OUT },
  1096. END_ARGS
  1097. }
  1098. },
  1099. { "RemoveNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1100. (WPADBusMethodHandler) &wpas_dbus_handler_remove_network,
  1101. {
  1102. { "path", "o", ARG_IN },
  1103. END_ARGS
  1104. }
  1105. },
  1106. { "SelectNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1107. (WPADBusMethodHandler) &wpas_dbus_handler_select_network,
  1108. {
  1109. { "path", "o", ARG_IN },
  1110. END_ARGS
  1111. }
  1112. },
  1113. { "AddBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1114. (WPADBusMethodHandler) &wpas_dbus_handler_add_blob,
  1115. {
  1116. { "name", "s", ARG_IN },
  1117. { "data", "ay", ARG_IN },
  1118. END_ARGS
  1119. }
  1120. },
  1121. { "GetBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1122. (WPADBusMethodHandler) &wpas_dbus_handler_get_blob,
  1123. {
  1124. { "name", "s", ARG_IN },
  1125. { "data", "ay", ARG_OUT },
  1126. END_ARGS
  1127. }
  1128. },
  1129. { "RemoveBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1130. (WPADBusMethodHandler) &wpas_dbus_handler_remove_blob,
  1131. {
  1132. { "name", "s", ARG_IN },
  1133. END_ARGS
  1134. }
  1135. },
  1136. #ifdef CONFIG_WPS
  1137. { "Start", WPAS_DBUS_NEW_IFACE_WPS,
  1138. (WPADBusMethodHandler) &wpas_dbus_handler_wps_start,
  1139. {
  1140. { "args", "a{sv}", ARG_IN },
  1141. { "output", "a{sv}", ARG_OUT },
  1142. END_ARGS
  1143. }
  1144. },
  1145. #endif /* CONFIG_WPS */
  1146. { NULL, NULL, NULL, { END_ARGS } }
  1147. };
  1148. static const struct wpa_dbus_property_desc wpas_dbus_interface_properties[] = {
  1149. { "Capabilities", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{sv}",
  1150. (WPADBusPropertyAccessor) wpas_dbus_getter_capabilities,
  1151. NULL, R
  1152. },
  1153. { "State", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  1154. (WPADBusPropertyAccessor) wpas_dbus_getter_state,
  1155. NULL, R
  1156. },
  1157. { "Scanning", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
  1158. (WPADBusPropertyAccessor) wpas_dbus_getter_scanning,
  1159. NULL, R
  1160. },
  1161. { "ApScan", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  1162. (WPADBusPropertyAccessor) wpas_dbus_getter_ap_scan,
  1163. (WPADBusPropertyAccessor) wpas_dbus_setter_ap_scan,
  1164. RW
  1165. },
  1166. { "Ifname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  1167. (WPADBusPropertyAccessor) wpas_dbus_getter_ifname,
  1168. NULL, R
  1169. },
  1170. { "Driver", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  1171. (WPADBusPropertyAccessor) wpas_dbus_getter_driver,
  1172. NULL, R
  1173. },
  1174. { "BridgeIfname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  1175. (WPADBusPropertyAccessor) wpas_dbus_getter_bridge_ifname,
  1176. NULL, R
  1177. },
  1178. { "CurrentBSS", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
  1179. (WPADBusPropertyAccessor) wpas_dbus_getter_current_bss,
  1180. NULL, R
  1181. },
  1182. { "CurrentNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
  1183. (WPADBusPropertyAccessor) wpas_dbus_getter_current_network,
  1184. NULL, R
  1185. },
  1186. { "Blobs", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{say}",
  1187. (WPADBusPropertyAccessor) wpas_dbus_getter_blobs,
  1188. NULL, R
  1189. },
  1190. { "BSSs", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
  1191. (WPADBusPropertyAccessor) wpas_dbus_getter_bsss,
  1192. NULL, R
  1193. },
  1194. { "Networks", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
  1195. (WPADBusPropertyAccessor) wpas_dbus_getter_networks,
  1196. NULL, R
  1197. },
  1198. #ifdef CONFIG_WPS
  1199. { "ProcessCredentials", WPAS_DBUS_NEW_IFACE_WPS, "b",
  1200. (WPADBusPropertyAccessor) wpas_dbus_getter_process_credentials,
  1201. (WPADBusPropertyAccessor) wpas_dbus_setter_process_credentials,
  1202. RW
  1203. },
  1204. #endif /* CONFIG_WPS */
  1205. { NULL, NULL, NULL, NULL, NULL, 0 }
  1206. };
  1207. static const struct wpa_dbus_signal_desc wpas_dbus_interface_signals[] = {
  1208. { "ScanDone", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1209. {
  1210. { "success", "b", ARG_OUT },
  1211. END_ARGS
  1212. }
  1213. },
  1214. { "BSSAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1215. {
  1216. { "path", "o", ARG_OUT },
  1217. { "properties", "a{sv}", ARG_OUT },
  1218. END_ARGS
  1219. }
  1220. },
  1221. { "BSSRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1222. {
  1223. { "path", "o", ARG_OUT },
  1224. END_ARGS
  1225. }
  1226. },
  1227. { "BlobAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1228. {
  1229. { "name", "s", ARG_OUT },
  1230. END_ARGS
  1231. }
  1232. },
  1233. { "BlobRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1234. {
  1235. { "name", "s", ARG_OUT },
  1236. END_ARGS
  1237. }
  1238. },
  1239. { "NetworkAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1240. {
  1241. { "path", "o", ARG_OUT },
  1242. { "properties", "a{sv}", ARG_OUT },
  1243. END_ARGS
  1244. }
  1245. },
  1246. { "NetworkRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1247. {
  1248. { "path", "o", ARG_OUT },
  1249. END_ARGS
  1250. }
  1251. },
  1252. { "NetworkSelected", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1253. {
  1254. { "path", "o", ARG_OUT },
  1255. END_ARGS
  1256. }
  1257. },
  1258. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1259. {
  1260. { "properties", "a{sv}", ARG_OUT },
  1261. END_ARGS
  1262. }
  1263. },
  1264. #ifdef CONFIG_WPS
  1265. { "Event", WPAS_DBUS_NEW_IFACE_WPS,
  1266. {
  1267. { "name", "s", ARG_OUT },
  1268. { "args", "a{sv}", ARG_OUT },
  1269. END_ARGS
  1270. }
  1271. },
  1272. { "Credentials", WPAS_DBUS_NEW_IFACE_WPS,
  1273. {
  1274. { "credentials", "a{sv}", ARG_OUT },
  1275. END_ARGS
  1276. }
  1277. },
  1278. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_WPS,
  1279. {
  1280. { "properties", "a{sv}", ARG_OUT },
  1281. END_ARGS
  1282. }
  1283. },
  1284. #endif /* CONFIG_WPS */
  1285. { NULL, NULL, { END_ARGS } }
  1286. };
  1287. int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s)
  1288. {
  1289. struct wpa_dbus_object_desc *obj_desc = NULL;
  1290. struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus;
  1291. int next;
  1292. /* Do nothing if the control interface is not turned on */
  1293. if (ctrl_iface == NULL)
  1294. return 0;
  1295. /* Create and set the interface's object path */
  1296. wpa_s->dbus_new_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
  1297. if (wpa_s->dbus_new_path == NULL)
  1298. return -1;
  1299. next = ctrl_iface->next_objid++;
  1300. os_snprintf(wpa_s->dbus_new_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1301. WPAS_DBUS_NEW_PATH_INTERFACES "/%u",
  1302. next);
  1303. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  1304. if (!obj_desc) {
  1305. wpa_printf(MSG_ERROR, "Not enough memory "
  1306. "to create object description");
  1307. goto err;
  1308. }
  1309. wpas_dbus_register(obj_desc, wpa_s, NULL, wpas_dbus_interface_methods,
  1310. wpas_dbus_interface_properties,
  1311. wpas_dbus_interface_signals);
  1312. wpa_printf(MSG_DEBUG, "dbus: Register interface object '%s'",
  1313. wpa_s->dbus_new_path);
  1314. if (wpa_dbus_register_object_per_iface(ctrl_iface,
  1315. wpa_s->dbus_new_path,
  1316. wpa_s->ifname, obj_desc))
  1317. goto err;
  1318. wpas_dbus_signal_interface_added(wpa_s);
  1319. return 0;
  1320. err:
  1321. os_free(wpa_s->dbus_new_path);
  1322. wpa_s->dbus_new_path = NULL;
  1323. free_dbus_object_desc(obj_desc);
  1324. return -1;
  1325. }
  1326. int wpas_dbus_unregister_interface(struct wpa_supplicant *wpa_s)
  1327. {
  1328. struct wpas_dbus_priv *ctrl_iface;
  1329. /* Do nothing if the control interface is not turned on */
  1330. if (wpa_s == NULL || wpa_s->global == NULL)
  1331. return 0;
  1332. ctrl_iface = wpa_s->global->dbus;
  1333. if (ctrl_iface == NULL)
  1334. return 0;
  1335. wpa_printf(MSG_DEBUG, "dbus: Unregister interface object '%s'",
  1336. wpa_s->dbus_new_path);
  1337. if (wpa_dbus_unregister_object_per_iface(ctrl_iface,
  1338. wpa_s->dbus_new_path))
  1339. return -1;
  1340. wpas_dbus_signal_interface_removed(wpa_s);
  1341. os_free(wpa_s->dbus_new_path);
  1342. wpa_s->dbus_new_path = NULL;
  1343. return 0;
  1344. }