dbus_new.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621
  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. static void str_to_lower(char *s)
  327. {
  328. while (*s) {
  329. *s = tolower(*s);
  330. s++;
  331. }
  332. }
  333. /**
  334. * wpas_dbus_signal_state_changed - Send a state changed signal
  335. * @wpa_s: %wpa_supplicant network interface data
  336. * @new_state: new state wpa_supplicant is entering
  337. * @old_state: old state wpa_supplicant is leaving
  338. *
  339. * Notify listeners that wpa_supplicant has changed state
  340. */
  341. void wpas_dbus_signal_state_changed(struct wpa_supplicant *wpa_s,
  342. enum wpa_states new_state,
  343. enum wpa_states old_state)
  344. {
  345. struct wpas_dbus_priv *iface;
  346. DBusMessage *msg;
  347. char *new_state_str, *old_state_str;
  348. /* Do nothing if the control interface is not turned on */
  349. if (wpa_s->global == NULL)
  350. return;
  351. iface = wpa_s->global->dbus;
  352. if (iface == NULL)
  353. return;
  354. /* Only send signal if state really changed */
  355. if (new_state == old_state)
  356. return;
  357. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  358. WPAS_DBUS_NEW_IFACE_INTERFACE,
  359. "StateChanged");
  360. if (msg == NULL)
  361. return;
  362. new_state_str = os_strdup(wpa_supplicant_state_txt(new_state));
  363. old_state_str = os_strdup(wpa_supplicant_state_txt(old_state));
  364. if (new_state_str == NULL || old_state_str == NULL)
  365. goto out;
  366. /* make state string lowercase to fit new DBus API convention */
  367. str_to_lower(new_state_str);
  368. str_to_lower(old_state_str);
  369. if (!dbus_message_append_args(msg,
  370. DBUS_TYPE_STRING, &new_state_str,
  371. DBUS_TYPE_STRING, &old_state_str,
  372. DBUS_TYPE_INVALID)) {
  373. wpa_printf(MSG_ERROR, "dbus: Failed to construct state change "
  374. "signal");
  375. goto out;
  376. }
  377. dbus_connection_send(iface->con, msg, NULL);
  378. out:
  379. dbus_message_unref(msg);
  380. os_free(new_state_str);
  381. os_free(old_state_str);
  382. }
  383. /**
  384. * wpas_dbus_signal_network_enabled_changed - Signals Enabled property changes
  385. * @wpa_s: %wpa_supplicant network interface data
  386. * @ssid: configured network which Enabled property has changed
  387. *
  388. * Sends PropertyChanged signals containing new value of Enabled property
  389. * for specified network
  390. */
  391. void wpas_dbus_signal_network_enabled_changed(struct wpa_supplicant *wpa_s,
  392. struct wpa_ssid *ssid)
  393. {
  394. struct network_handler_args args = { wpa_s, ssid };
  395. char path[WPAS_DBUS_OBJECT_PATH_MAX];
  396. os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
  397. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
  398. wpa_s->dbus_new_path, ssid->id);
  399. wpa_dbus_signal_property_changed(wpa_s->global->dbus,
  400. (WPADBusPropertyAccessor)
  401. wpas_dbus_getter_enabled, &args,
  402. path, WPAS_DBUS_NEW_IFACE_NETWORK,
  403. "Enabled");
  404. }
  405. #ifdef CONFIG_WPS
  406. /**
  407. * wpas_dbus_signal_wps_event_success - Signals Success WPS event
  408. * @wpa_s: %wpa_supplicant network interface data
  409. *
  410. * Sends Event dbus signal with name "success" and empty dict as arguments
  411. */
  412. void wpas_dbus_signal_wps_event_success(struct wpa_supplicant *wpa_s)
  413. {
  414. DBusMessage *msg;
  415. DBusMessageIter iter, dict_iter;
  416. struct wpas_dbus_priv *iface;
  417. char *key = "success";
  418. iface = wpa_s->global->dbus;
  419. /* Do nothing if the control interface is not turned on */
  420. if (iface == NULL)
  421. return;
  422. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  423. WPAS_DBUS_NEW_IFACE_WPS, "Event");
  424. if (msg == NULL)
  425. return;
  426. dbus_message_iter_init_append(msg, &iter);
  427. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
  428. !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  429. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  430. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  431. else
  432. dbus_connection_send(iface->con, msg, NULL);
  433. dbus_message_unref(msg);
  434. }
  435. /**
  436. * wpas_dbus_signal_wps_event_fail - Signals Fail WPS event
  437. * @wpa_s: %wpa_supplicant network interface data
  438. *
  439. * Sends Event dbus signal with name "fail" and dictionary containing
  440. * "msg field with fail message number (int32) as arguments
  441. */
  442. void wpas_dbus_signal_wps_event_fail(struct wpa_supplicant *wpa_s,
  443. struct wps_event_fail *fail)
  444. {
  445. DBusMessage *msg;
  446. DBusMessageIter iter, dict_iter;
  447. struct wpas_dbus_priv *iface;
  448. char *key = "fail";
  449. iface = wpa_s->global->dbus;
  450. /* Do nothing if the control interface is not turned on */
  451. if (iface == NULL)
  452. return;
  453. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  454. WPAS_DBUS_NEW_IFACE_WPS, "Event");
  455. if (msg == NULL)
  456. return;
  457. dbus_message_iter_init_append(msg, &iter);
  458. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
  459. !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  460. !wpa_dbus_dict_append_int32(&dict_iter, "msg", fail->msg) ||
  461. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  462. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  463. else
  464. dbus_connection_send(iface->con, msg, NULL);
  465. dbus_message_unref(msg);
  466. }
  467. /**
  468. * wpas_dbus_signal_wps_event_m2d - Signals M2D WPS event
  469. * @wpa_s: %wpa_supplicant network interface data
  470. *
  471. * Sends Event dbus signal with name "m2d" and dictionary containing
  472. * fields of wps_event_m2d structure.
  473. */
  474. void wpas_dbus_signal_wps_event_m2d(struct wpa_supplicant *wpa_s,
  475. struct wps_event_m2d *m2d)
  476. {
  477. DBusMessage *msg;
  478. DBusMessageIter iter, dict_iter;
  479. struct wpas_dbus_priv *iface;
  480. char *key = "m2d";
  481. iface = wpa_s->global->dbus;
  482. /* Do nothing if the control interface is not turned on */
  483. if (iface == NULL)
  484. return;
  485. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  486. WPAS_DBUS_NEW_IFACE_WPS, "Event");
  487. if (msg == NULL)
  488. return;
  489. dbus_message_iter_init_append(msg, &iter);
  490. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
  491. !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  492. !wpa_dbus_dict_append_uint16(&dict_iter, "config_methods",
  493. m2d->config_methods) ||
  494. !wpa_dbus_dict_append_byte_array(&dict_iter, "manufacturer",
  495. (const char *) m2d->manufacturer,
  496. m2d->manufacturer_len) ||
  497. !wpa_dbus_dict_append_byte_array(&dict_iter, "model_name",
  498. (const char *) m2d->model_name,
  499. m2d->model_name_len) ||
  500. !wpa_dbus_dict_append_byte_array(&dict_iter, "model_number",
  501. (const char *) m2d->model_number,
  502. m2d->model_number_len) ||
  503. !wpa_dbus_dict_append_byte_array(&dict_iter, "serial_number",
  504. (const char *)
  505. m2d->serial_number,
  506. m2d->serial_number_len) ||
  507. !wpa_dbus_dict_append_byte_array(&dict_iter, "dev_name",
  508. (const char *) m2d->dev_name,
  509. m2d->dev_name_len) ||
  510. !wpa_dbus_dict_append_byte_array(&dict_iter, "primary_dev_type",
  511. (const char *)
  512. m2d->primary_dev_type, 8) ||
  513. !wpa_dbus_dict_append_uint16(&dict_iter, "config_error",
  514. m2d->config_error) ||
  515. !wpa_dbus_dict_append_uint16(&dict_iter, "dev_password_id",
  516. m2d->dev_password_id) ||
  517. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  518. wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
  519. else
  520. dbus_connection_send(iface->con, msg, NULL);
  521. dbus_message_unref(msg);
  522. }
  523. /**
  524. * wpas_dbus_signal_wps_cred - Signals new credentials
  525. * @wpa_s: %wpa_supplicant network interface data
  526. *
  527. * Sends signal with credentials in directory argument
  528. */
  529. void wpas_dbus_signal_wps_cred(struct wpa_supplicant *wpa_s,
  530. const struct wps_credential *cred)
  531. {
  532. DBusMessage *msg;
  533. DBusMessageIter iter, dict_iter;
  534. struct wpas_dbus_priv *iface;
  535. char *auth_type[6]; /* we have six possible authorization types */
  536. int at_num = 0;
  537. char *encr_type[4]; /* we have four possible encryption types */
  538. int et_num = 0;
  539. iface = wpa_s->global->dbus;
  540. /* Do nothing if the control interface is not turned on */
  541. if (iface == NULL)
  542. return;
  543. msg = dbus_message_new_signal(wpa_s->dbus_new_path,
  544. WPAS_DBUS_NEW_IFACE_WPS,
  545. "Credentials");
  546. if (msg == NULL)
  547. return;
  548. dbus_message_iter_init_append(msg, &iter);
  549. if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
  550. goto nomem;
  551. if (cred->auth_type & WPS_AUTH_OPEN)
  552. auth_type[at_num++] = "open";
  553. if (cred->auth_type & WPS_AUTH_WPAPSK)
  554. auth_type[at_num++] = "wpa-psk";
  555. if (cred->auth_type & WPS_AUTH_SHARED)
  556. auth_type[at_num++] = "shared";
  557. if (cred->auth_type & WPS_AUTH_WPA)
  558. auth_type[at_num++] = "wpa-eap";
  559. if (cred->auth_type & WPS_AUTH_WPA2)
  560. auth_type[at_num++] = "wpa2-eap";
  561. if (cred->auth_type & WPS_AUTH_WPA2PSK)
  562. auth_type[at_num++] =
  563. "wpa2-psk";
  564. if (cred->encr_type & WPS_ENCR_NONE)
  565. encr_type[et_num++] = "none";
  566. if (cred->encr_type & WPS_ENCR_WEP)
  567. encr_type[et_num++] = "wep";
  568. if (cred->encr_type & WPS_ENCR_TKIP)
  569. encr_type[et_num++] = "tkip";
  570. if (cred->encr_type & WPS_ENCR_AES)
  571. encr_type[et_num++] = "aes";
  572. if (wpa_s->current_ssid) {
  573. if (!wpa_dbus_dict_append_byte_array(
  574. &dict_iter, "BSSID",
  575. (const char *) wpa_s->current_ssid->bssid,
  576. ETH_ALEN))
  577. goto nomem;
  578. }
  579. if (!wpa_dbus_dict_append_byte_array(&dict_iter, "SSID",
  580. (const char *) cred->ssid,
  581. cred->ssid_len) ||
  582. !wpa_dbus_dict_append_string_array(&dict_iter, "AuthType",
  583. (const char **) auth_type,
  584. at_num) ||
  585. !wpa_dbus_dict_append_string_array(&dict_iter, "EncrType",
  586. (const char **) encr_type,
  587. et_num) ||
  588. !wpa_dbus_dict_append_byte_array(&dict_iter, "Key",
  589. (const char *) cred->key,
  590. cred->key_len) ||
  591. !wpa_dbus_dict_append_uint32(&dict_iter, "KeyIndex",
  592. cred->key_idx) ||
  593. !wpa_dbus_dict_close_write(&iter, &dict_iter))
  594. goto nomem;
  595. dbus_connection_send(iface->con, msg, NULL);
  596. nomem:
  597. dbus_message_unref(msg);
  598. }
  599. #endif /* CONFIG_WPS */
  600. /**
  601. * wpas_dbus_signal_prop_changed - Signals change of property
  602. * @wpa_s: %wpa_supplicant network interface data
  603. * @property: indicates which property has changed
  604. *
  605. * Sends ProertyChanged signals with path, interface and arguments
  606. * depending on which property has changed.
  607. */
  608. void wpas_dbus_signal_prop_changed(struct wpa_supplicant *wpa_s,
  609. enum wpas_dbus_prop property)
  610. {
  611. WPADBusPropertyAccessor getter;
  612. char *prop;
  613. switch (property) {
  614. case WPAS_DBUS_PROP_AP_SCAN:
  615. getter = (WPADBusPropertyAccessor) wpas_dbus_getter_ap_scan;
  616. prop = "ApScan";
  617. break;
  618. case WPAS_DBUS_PROP_SCANNING:
  619. getter = (WPADBusPropertyAccessor) wpas_dbus_getter_scanning;
  620. prop = "Scanning";
  621. break;
  622. case WPAS_DBUS_PROP_CURRENT_BSS:
  623. getter = (WPADBusPropertyAccessor)
  624. wpas_dbus_getter_current_bss;
  625. prop = "CurrentBSS";
  626. break;
  627. case WPAS_DBUS_PROP_CURRENT_NETWORK:
  628. getter = (WPADBusPropertyAccessor)
  629. wpas_dbus_getter_current_network;
  630. prop = "CurrentNetwork";
  631. break;
  632. default:
  633. wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
  634. __func__, property);
  635. return;
  636. }
  637. wpa_dbus_signal_property_changed(wpa_s->global->dbus,
  638. getter, wpa_s, wpa_s->dbus_new_path,
  639. WPAS_DBUS_NEW_IFACE_INTERFACE, prop);
  640. }
  641. /**
  642. * wpas_dbus_signal_debug_level_changed - Signals change of debug param
  643. * @global: wpa_global structure
  644. *
  645. * Sends ProertyChanged signals informing that debug level has changed.
  646. */
  647. void wpas_dbus_signal_debug_level_changed(struct wpa_global *global)
  648. {
  649. wpa_dbus_signal_property_changed(global->dbus,
  650. (WPADBusPropertyAccessor)
  651. wpas_dbus_getter_debug_level,
  652. global, WPAS_DBUS_NEW_PATH,
  653. WPAS_DBUS_NEW_INTERFACE,
  654. "DebugLevel");
  655. }
  656. /**
  657. * wpas_dbus_signal_debug_timestamp_changed - Signals change of debug param
  658. * @global: wpa_global structure
  659. *
  660. * Sends ProertyChanged signals informing that debug timestamp has changed.
  661. */
  662. void wpas_dbus_signal_debug_timestamp_changed(struct wpa_global *global)
  663. {
  664. wpa_dbus_signal_property_changed(global->dbus,
  665. (WPADBusPropertyAccessor)
  666. wpas_dbus_getter_debug_timestamp,
  667. global, WPAS_DBUS_NEW_PATH,
  668. WPAS_DBUS_NEW_INTERFACE,
  669. "DebugTimestamp");
  670. }
  671. /**
  672. * wpas_dbus_signal_debug_show_keys_changed - Signals change of debug param
  673. * @global: wpa_global structure
  674. *
  675. * Sends ProertyChanged signals informing that debug show_keys has changed.
  676. */
  677. void wpas_dbus_signal_debug_show_keys_changed(struct wpa_global *global)
  678. {
  679. wpa_dbus_signal_property_changed(global->dbus,
  680. (WPADBusPropertyAccessor)
  681. wpas_dbus_getter_debug_show_keys,
  682. global, WPAS_DBUS_NEW_PATH,
  683. WPAS_DBUS_NEW_INTERFACE,
  684. "DebugShowKeys");
  685. }
  686. struct wpas_dbus_method {
  687. const char *name;
  688. const char *iface;
  689. WPADBusMethodHandler handler;
  690. struct wpa_dbus_argument args[3];
  691. };
  692. struct wpas_dbus_property {
  693. const char *name;
  694. const char *iface;
  695. const char *type;
  696. WPADBusPropertyAccessor getter;
  697. WPADBusPropertyAccessor setter;
  698. enum dbus_prop_access _access;
  699. };
  700. struct wpas_dbus_signal {
  701. const char *name;
  702. const char *iface;
  703. struct wpa_dbus_argument args[3];
  704. };
  705. static void wpas_dbus_register(struct wpa_dbus_object_desc *obj_desc,
  706. void *priv,
  707. WPADBusArgumentFreeFunction priv_free,
  708. const struct wpas_dbus_method *methods,
  709. const struct wpas_dbus_property *properties,
  710. const struct wpas_dbus_signal *signals)
  711. {
  712. int i;
  713. obj_desc->user_data = priv;
  714. obj_desc->user_data_free_func = priv_free;
  715. for (i = 0; methods && methods[i].name; i++) {
  716. wpa_dbus_method_register(obj_desc, methods[i].iface,
  717. methods[i].name, methods[i].handler,
  718. methods[i].args);
  719. }
  720. for (i = 0; properties && properties[i].name; i++) {
  721. wpa_dbus_property_register(obj_desc, properties[i].iface,
  722. properties[i].name,
  723. properties[i].type,
  724. properties[i].getter,
  725. properties[i].setter,
  726. properties[i]._access);
  727. }
  728. for (i = 0; signals && signals[i].name; i++) {
  729. wpa_dbus_signal_register(obj_desc, signals[i].iface,
  730. signals[i].name, signals[i].args);
  731. }
  732. }
  733. static const struct wpas_dbus_method wpas_dbus_global_methods[] = {
  734. { "CreateInterface", WPAS_DBUS_NEW_INTERFACE,
  735. (WPADBusMethodHandler) &wpas_dbus_handler_create_interface,
  736. {
  737. { "args", "a{sv}", ARG_IN },
  738. { "path", "o", ARG_OUT },
  739. END_ARGS
  740. }
  741. },
  742. { "RemoveInterface", WPAS_DBUS_NEW_INTERFACE,
  743. (WPADBusMethodHandler) &wpas_dbus_handler_remove_interface,
  744. {
  745. { "path", "o", ARG_IN },
  746. END_ARGS
  747. }
  748. },
  749. { "GetInterface", WPAS_DBUS_NEW_INTERFACE,
  750. (WPADBusMethodHandler) &wpas_dbus_handler_get_interface,
  751. {
  752. { "ifname", "s", ARG_IN },
  753. { "path", "o", ARG_OUT },
  754. END_ARGS
  755. }
  756. },
  757. { NULL, NULL, NULL, { END_ARGS } }
  758. };
  759. static const struct wpas_dbus_property wpas_dbus_global_properties[] = {
  760. { "DebugLevel", WPAS_DBUS_NEW_INTERFACE, "y",
  761. (WPADBusPropertyAccessor) wpas_dbus_getter_debug_level,
  762. (WPADBusPropertyAccessor) wpas_dbus_setter_debug_level,
  763. RW
  764. },
  765. { "DebugTimestamp", WPAS_DBUS_NEW_INTERFACE, "b",
  766. (WPADBusPropertyAccessor) wpas_dbus_getter_debug_timestamp,
  767. (WPADBusPropertyAccessor) wpas_dbus_setter_debug_timestamp,
  768. RW
  769. },
  770. { "DebugShowKeys", WPAS_DBUS_NEW_INTERFACE, "b",
  771. (WPADBusPropertyAccessor) wpas_dbus_getter_debug_show_keys,
  772. (WPADBusPropertyAccessor) wpas_dbus_setter_debug_show_keys,
  773. RW
  774. },
  775. { "Interfaces", WPAS_DBUS_NEW_INTERFACE, "ao",
  776. (WPADBusPropertyAccessor) &wpas_dbus_getter_interfaces,
  777. NULL,
  778. R
  779. },
  780. { "EapMethods", WPAS_DBUS_NEW_INTERFACE, "as",
  781. (WPADBusPropertyAccessor) wpas_dbus_getter_eap_methods,
  782. NULL,
  783. R
  784. },
  785. { NULL, NULL, NULL, NULL, NULL, 0 }
  786. };
  787. static const struct wpas_dbus_signal wpas_dbus_global_signals[] = {
  788. { "InterfaceAdded", WPAS_DBUS_NEW_INTERFACE,
  789. {
  790. { "path", "o", ARG_OUT },
  791. { "properties", "a{sv}", ARG_OUT },
  792. END_ARGS
  793. }
  794. },
  795. { "InterfaceRemoved", WPAS_DBUS_NEW_INTERFACE,
  796. {
  797. { "path", "o", ARG_OUT },
  798. END_ARGS
  799. }
  800. },
  801. { "PropertiesChanged", WPAS_DBUS_NEW_INTERFACE,
  802. {
  803. { "properties", "a{sv}", ARG_OUT },
  804. END_ARGS
  805. }
  806. },
  807. { NULL, NULL, { END_ARGS } }
  808. };
  809. /**
  810. * wpas_dbus_ctrl_iface_init - Initialize dbus control interface
  811. * @global: Pointer to global data from wpa_supplicant_init()
  812. * Returns: 0 on success or -1 on failure
  813. *
  814. * Initialize the dbus control interface for wpa_supplicantand and start
  815. * receiving commands from external programs over the bus.
  816. */
  817. int wpas_dbus_ctrl_iface_init(struct wpas_dbus_priv *priv)
  818. {
  819. struct wpa_dbus_object_desc *obj_desc;
  820. int ret;
  821. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  822. if (!obj_desc) {
  823. wpa_printf(MSG_ERROR, "Not enough memory "
  824. "to create object description");
  825. return -1;
  826. }
  827. wpas_dbus_register(obj_desc, priv->global, NULL,
  828. wpas_dbus_global_methods,
  829. wpas_dbus_global_properties,
  830. wpas_dbus_global_signals);
  831. wpa_printf(MSG_DEBUG, "dbus: Register D-Bus object '%s'",
  832. WPAS_DBUS_NEW_PATH);
  833. ret = wpa_dbus_ctrl_iface_init(priv, WPAS_DBUS_NEW_PATH,
  834. WPAS_DBUS_NEW_SERVICE,
  835. obj_desc);
  836. if (ret < 0)
  837. free_dbus_object_desc(obj_desc);
  838. else
  839. priv->dbus_new_initialized = 1;
  840. return ret;
  841. }
  842. /**
  843. * wpas_dbus_ctrl_iface_deinit - Deinitialize dbus ctrl interface for
  844. * wpa_supplicant
  845. * @iface: Pointer to dbus private data from wpas_dbus_init()
  846. *
  847. * Deinitialize the dbus control interface that was initialized with
  848. * wpas_dbus_ctrl_iface_init().
  849. */
  850. void wpas_dbus_ctrl_iface_deinit(struct wpas_dbus_priv *iface)
  851. {
  852. if (!iface->dbus_new_initialized)
  853. return;
  854. wpa_printf(MSG_DEBUG, "dbus: Unregister D-Bus object '%s'",
  855. WPAS_DBUS_NEW_PATH);
  856. dbus_connection_unregister_object_path(iface->con,
  857. WPAS_DBUS_NEW_PATH);
  858. }
  859. static void wpa_dbus_free(void *ptr)
  860. {
  861. os_free(ptr);
  862. }
  863. static const struct wpas_dbus_property wpas_dbus_network_properties[] = {
  864. { "Properties", WPAS_DBUS_NEW_IFACE_NETWORK, "a{sv}",
  865. (WPADBusPropertyAccessor) wpas_dbus_getter_network_properties,
  866. (WPADBusPropertyAccessor) wpas_dbus_setter_network_properties,
  867. RW
  868. },
  869. { "Enabled", WPAS_DBUS_NEW_IFACE_NETWORK, "b",
  870. (WPADBusPropertyAccessor) wpas_dbus_getter_enabled,
  871. (WPADBusPropertyAccessor) wpas_dbus_setter_enabled,
  872. RW
  873. },
  874. { NULL, NULL, NULL, NULL, NULL, 0 }
  875. };
  876. static const struct wpas_dbus_signal wpas_dbus_network_signals[] = {
  877. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_NETWORK,
  878. {
  879. { "properties", "a{sv}", ARG_OUT },
  880. END_ARGS
  881. }
  882. },
  883. { NULL, NULL, { END_ARGS } }
  884. };
  885. /**
  886. * wpas_dbus_register_network - Register a configured network with dbus
  887. * @wpa_s: wpa_supplicant interface structure
  888. * @ssid: network configuration data
  889. * Returns: 0 on success, -1 on failure
  890. *
  891. * Registers network representing object with dbus
  892. */
  893. int wpas_dbus_register_network(struct wpa_supplicant *wpa_s,
  894. struct wpa_ssid *ssid)
  895. {
  896. struct wpas_dbus_priv *ctrl_iface;
  897. struct wpa_dbus_object_desc *obj_desc;
  898. struct network_handler_args *arg = NULL;
  899. char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  900. /* Do nothing if the control interface is not turned on */
  901. if (wpa_s == NULL || wpa_s->global == NULL)
  902. return 0;
  903. ctrl_iface = wpa_s->global->dbus;
  904. if (ctrl_iface == NULL)
  905. return 0;
  906. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  907. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  908. wpa_s->dbus_new_path, ssid->id);
  909. wpa_printf(MSG_DEBUG, "dbus: Register network object '%s'",
  910. net_obj_path);
  911. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  912. if (!obj_desc) {
  913. wpa_printf(MSG_ERROR, "Not enough memory "
  914. "to create object description");
  915. goto err;
  916. }
  917. /* allocate memory for handlers arguments */
  918. arg = os_zalloc(sizeof(struct network_handler_args));
  919. if (!arg) {
  920. wpa_printf(MSG_ERROR, "Not enough memory "
  921. "to create arguments for method");
  922. goto err;
  923. }
  924. arg->wpa_s = wpa_s;
  925. arg->ssid = ssid;
  926. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  927. wpas_dbus_network_properties,
  928. wpas_dbus_network_signals);
  929. if (wpa_dbus_register_object_per_iface(ctrl_iface, net_obj_path,
  930. wpa_s->ifname, obj_desc))
  931. goto err;
  932. wpas_dbus_signal_network_added(wpa_s, ssid->id);
  933. return 0;
  934. err:
  935. os_free(obj_desc);
  936. os_free(arg);
  937. return -1;
  938. }
  939. /**
  940. * wpas_dbus_unregister_network - Unregister a configured network from dbus
  941. * @wpa_s: wpa_supplicant interface structure
  942. * @nid: network id
  943. * Returns: 0 on success, -1 on failure
  944. *
  945. * Unregisters network representing object from dbus
  946. */
  947. int wpas_dbus_unregister_network(struct wpa_supplicant *wpa_s, int nid)
  948. {
  949. struct wpas_dbus_priv *ctrl_iface;
  950. char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  951. int ret;
  952. /* Do nothing if the control interface is not turned on */
  953. if (wpa_s == NULL || wpa_s->global == NULL)
  954. return 0;
  955. ctrl_iface = wpa_s->global->dbus;
  956. if (ctrl_iface == NULL)
  957. return 0;
  958. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  959. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  960. wpa_s->dbus_new_path, nid);
  961. wpa_printf(MSG_DEBUG, "dbus: Unregister network object '%s'",
  962. net_obj_path);
  963. ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, net_obj_path);
  964. if (!ret)
  965. wpas_dbus_signal_network_removed(wpa_s, nid);
  966. return ret;
  967. }
  968. static const struct wpas_dbus_property wpas_dbus_bss_properties[] = {
  969. { "SSID", WPAS_DBUS_NEW_IFACE_BSSID, "ay",
  970. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_ssid,
  971. NULL,
  972. R
  973. },
  974. { "BSSID", WPAS_DBUS_NEW_IFACE_BSSID, "ay",
  975. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_bssid,
  976. NULL,
  977. R
  978. },
  979. { "Privacy", WPAS_DBUS_NEW_IFACE_BSSID, "b",
  980. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_privacy,
  981. NULL,
  982. R
  983. },
  984. { "Mode", WPAS_DBUS_NEW_IFACE_BSSID, "s",
  985. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_mode,
  986. NULL,
  987. R
  988. },
  989. { "Signal", WPAS_DBUS_NEW_IFACE_BSSID, "n",
  990. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_signal,
  991. NULL,
  992. R
  993. },
  994. { "Frequency", WPAS_DBUS_NEW_IFACE_BSSID, "q",
  995. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_frequency,
  996. NULL,
  997. R
  998. },
  999. { "MaxRate", WPAS_DBUS_NEW_IFACE_BSSID, "q",
  1000. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_max_rate,
  1001. NULL,
  1002. R
  1003. },
  1004. { "WPAIE", WPAS_DBUS_NEW_IFACE_BSSID, "ay",
  1005. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_wpaie,
  1006. NULL,
  1007. R
  1008. },
  1009. { "RSNIE", WPAS_DBUS_NEW_IFACE_BSSID, "ay",
  1010. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_rsnie,
  1011. NULL,
  1012. R
  1013. },
  1014. { "WPSIE", WPAS_DBUS_NEW_IFACE_BSSID, "ay",
  1015. (WPADBusPropertyAccessor) wpas_dbus_getter_bss_wpsie,
  1016. NULL,
  1017. R
  1018. },
  1019. { NULL, NULL, NULL, NULL, NULL, 0 }
  1020. };
  1021. static const struct wpas_dbus_signal wpas_dbus_bss_signals[] = {
  1022. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_BSSID,
  1023. {
  1024. { "properties", "a{sv}", ARG_OUT },
  1025. END_ARGS
  1026. }
  1027. },
  1028. { NULL, NULL, { END_ARGS } }
  1029. };
  1030. /**
  1031. * wpas_dbus_unregister_bss - Unregister a scanned BSS from dbus
  1032. * @wpa_s: wpa_supplicant interface structure
  1033. * @bssid: scanned network bssid
  1034. * @id: unique BSS identifier
  1035. * Returns: 0 on success, -1 on failure
  1036. *
  1037. * Unregisters BSS representing object from dbus
  1038. */
  1039. int wpas_dbus_unregister_bss(struct wpa_supplicant *wpa_s,
  1040. u8 bssid[ETH_ALEN], unsigned int id)
  1041. {
  1042. struct wpas_dbus_priv *ctrl_iface;
  1043. char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  1044. /* Do nothing if the control interface is not turned on */
  1045. if (wpa_s == NULL || wpa_s->global == NULL)
  1046. return 0;
  1047. ctrl_iface = wpa_s->global->dbus;
  1048. if (ctrl_iface == NULL)
  1049. return 0;
  1050. os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1051. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  1052. wpa_s->dbus_new_path, id);
  1053. wpa_printf(MSG_DEBUG, "dbus: Unregister BSS object '%s'",
  1054. bss_obj_path);
  1055. if (wpa_dbus_unregister_object_per_iface(ctrl_iface, bss_obj_path)) {
  1056. wpa_printf(MSG_ERROR, "dbus: Cannot unregister BSS object %s",
  1057. bss_obj_path);
  1058. return -1;
  1059. }
  1060. wpas_dbus_signal_bss_removed(wpa_s, bss_obj_path);
  1061. return 0;
  1062. }
  1063. /**
  1064. * wpas_dbus_register_bss - Register a scanned BSS with dbus
  1065. * @wpa_s: wpa_supplicant interface structure
  1066. * @bssid: scanned network bssid
  1067. * @id: unique BSS identifier
  1068. * Returns: 0 on success, -1 on failure
  1069. *
  1070. * Registers BSS representing object with dbus
  1071. */
  1072. int wpas_dbus_register_bss(struct wpa_supplicant *wpa_s,
  1073. u8 bssid[ETH_ALEN], unsigned int id)
  1074. {
  1075. struct wpas_dbus_priv *ctrl_iface;
  1076. struct wpa_dbus_object_desc *obj_desc;
  1077. char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
  1078. struct bss_handler_args *arg = NULL;
  1079. /* Do nothing if the control interface is not turned on */
  1080. if (wpa_s == NULL || wpa_s->global == NULL)
  1081. return 0;
  1082. ctrl_iface = wpa_s->global->dbus;
  1083. if (ctrl_iface == NULL)
  1084. return 0;
  1085. os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1086. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  1087. wpa_s->dbus_new_path, id);
  1088. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  1089. if (!obj_desc) {
  1090. wpa_printf(MSG_ERROR, "Not enough memory "
  1091. "to create object description");
  1092. goto err;
  1093. }
  1094. arg = os_zalloc(sizeof(struct bss_handler_args));
  1095. if (!arg) {
  1096. wpa_printf(MSG_ERROR, "Not enough memory "
  1097. "to create arguments for handler");
  1098. goto err;
  1099. }
  1100. arg->wpa_s = wpa_s;
  1101. arg->id = id;
  1102. wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
  1103. wpas_dbus_bss_properties,
  1104. wpas_dbus_bss_signals);
  1105. wpa_printf(MSG_DEBUG, "dbus: Register BSS object '%s'",
  1106. bss_obj_path);
  1107. if (wpa_dbus_register_object_per_iface(ctrl_iface, bss_obj_path,
  1108. wpa_s->ifname, obj_desc)) {
  1109. wpa_printf(MSG_ERROR,
  1110. "Cannot register BSSID dbus object %s.",
  1111. bss_obj_path);
  1112. goto err;
  1113. }
  1114. wpas_dbus_signal_bss_added(wpa_s, bss_obj_path);
  1115. return 0;
  1116. err:
  1117. os_free(obj_desc);
  1118. os_free(arg);
  1119. return -1;
  1120. }
  1121. static const struct wpas_dbus_method wpas_dbus_interface_methods[] = {
  1122. { "Scan", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1123. (WPADBusMethodHandler) &wpas_dbus_handler_scan,
  1124. {
  1125. { "args", "a{sv}", ARG_IN },
  1126. END_ARGS
  1127. }
  1128. },
  1129. { "Disconnect", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1130. (WPADBusMethodHandler) &wpas_dbus_handler_disconnect,
  1131. {
  1132. END_ARGS
  1133. }
  1134. },
  1135. { "AddNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1136. (WPADBusMethodHandler) &wpas_dbus_handler_add_network,
  1137. {
  1138. { "args", "a{sv}", ARG_IN },
  1139. { "path", "o", ARG_OUT },
  1140. END_ARGS
  1141. }
  1142. },
  1143. { "RemoveNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1144. (WPADBusMethodHandler) &wpas_dbus_handler_remove_network,
  1145. {
  1146. { "path", "o", ARG_IN },
  1147. END_ARGS
  1148. }
  1149. },
  1150. { "SelectNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1151. (WPADBusMethodHandler) &wpas_dbus_handler_select_network,
  1152. {
  1153. { "path", "o", ARG_IN },
  1154. END_ARGS
  1155. }
  1156. },
  1157. { "AddBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1158. (WPADBusMethodHandler) &wpas_dbus_handler_add_blob,
  1159. {
  1160. { "name", "s", ARG_IN },
  1161. { "data", "ay", ARG_IN },
  1162. END_ARGS
  1163. }
  1164. },
  1165. { "GetBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1166. (WPADBusMethodHandler) &wpas_dbus_handler_get_blob,
  1167. {
  1168. { "name", "s", ARG_IN },
  1169. { "data", "ay", ARG_OUT },
  1170. END_ARGS
  1171. }
  1172. },
  1173. { "RemoveBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1174. (WPADBusMethodHandler) &wpas_dbus_handler_remove_blob,
  1175. {
  1176. { "name", "s", ARG_IN },
  1177. END_ARGS
  1178. }
  1179. },
  1180. #ifdef CONFIG_WPS
  1181. { "Start", WPAS_DBUS_NEW_IFACE_WPS,
  1182. (WPADBusMethodHandler) &wpas_dbus_handler_wps_start,
  1183. {
  1184. { "args", "a{sv}", ARG_IN },
  1185. { "output", "a{sv}", ARG_OUT },
  1186. END_ARGS
  1187. }
  1188. },
  1189. #endif /* CONFIG_WPS */
  1190. { NULL, NULL, NULL, { END_ARGS } }
  1191. };
  1192. static const struct wpas_dbus_property wpas_dbus_interface_properties[] = {
  1193. { "Capabilities", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{sv}",
  1194. (WPADBusPropertyAccessor) wpas_dbus_getter_capabilities,
  1195. NULL, R
  1196. },
  1197. { "State", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  1198. (WPADBusPropertyAccessor) wpas_dbus_getter_state,
  1199. NULL, R
  1200. },
  1201. { "Scanning", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
  1202. (WPADBusPropertyAccessor) wpas_dbus_getter_scanning,
  1203. NULL, R
  1204. },
  1205. { "ApScan", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  1206. (WPADBusPropertyAccessor) wpas_dbus_getter_ap_scan,
  1207. (WPADBusPropertyAccessor) wpas_dbus_setter_ap_scan,
  1208. RW
  1209. },
  1210. { "Ifname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  1211. (WPADBusPropertyAccessor) wpas_dbus_getter_ifname,
  1212. NULL, R
  1213. },
  1214. { "Driver", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  1215. (WPADBusPropertyAccessor) wpas_dbus_getter_driver,
  1216. NULL, R
  1217. },
  1218. { "BridgeIfname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  1219. (WPADBusPropertyAccessor) wpas_dbus_getter_bridge_ifname,
  1220. NULL, R
  1221. },
  1222. { "CurrentBSS", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
  1223. (WPADBusPropertyAccessor) wpas_dbus_getter_current_bss,
  1224. NULL, R
  1225. },
  1226. { "CurrentNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
  1227. (WPADBusPropertyAccessor) wpas_dbus_getter_current_network,
  1228. NULL, R
  1229. },
  1230. { "Blobs", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{say}",
  1231. (WPADBusPropertyAccessor) wpas_dbus_getter_blobs,
  1232. NULL, R
  1233. },
  1234. { "BSSs", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
  1235. (WPADBusPropertyAccessor) wpas_dbus_getter_bsss,
  1236. NULL, R
  1237. },
  1238. { "Networks", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
  1239. (WPADBusPropertyAccessor) wpas_dbus_getter_networks,
  1240. NULL, R
  1241. },
  1242. #ifdef CONFIG_WPS
  1243. { "ProcessCredentials", WPAS_DBUS_NEW_IFACE_WPS, "b",
  1244. (WPADBusPropertyAccessor) wpas_dbus_getter_process_credentials,
  1245. (WPADBusPropertyAccessor) wpas_dbus_setter_process_credentials,
  1246. RW
  1247. },
  1248. #endif /* CONFIG_WPS */
  1249. { NULL, NULL, NULL, NULL, NULL, 0 }
  1250. };
  1251. static const struct wpas_dbus_signal wpas_dbus_interface_signals[] = {
  1252. { "ScanDone", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1253. {
  1254. { "success", "b", ARG_OUT },
  1255. END_ARGS
  1256. }
  1257. },
  1258. { "StateChanged", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1259. {
  1260. { "newState", "s", ARG_OUT },
  1261. { "oldState", "s", ARG_OUT },
  1262. END_ARGS
  1263. }
  1264. },
  1265. { "BSSAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1266. {
  1267. { "path", "o", ARG_OUT },
  1268. { "properties", "a{sv}", ARG_OUT },
  1269. END_ARGS
  1270. }
  1271. },
  1272. { "BSSRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1273. {
  1274. { "path", "o", ARG_OUT },
  1275. END_ARGS
  1276. }
  1277. },
  1278. { "BlobAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1279. {
  1280. { "name", "s", ARG_OUT },
  1281. END_ARGS
  1282. }
  1283. },
  1284. { "BlobRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1285. {
  1286. { "name", "s", ARG_OUT },
  1287. END_ARGS
  1288. }
  1289. },
  1290. { "NetworkAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1291. {
  1292. { "path", "o", ARG_OUT },
  1293. { "properties", "a{sv}", ARG_OUT },
  1294. END_ARGS
  1295. }
  1296. },
  1297. { "NetworkRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1298. {
  1299. { "path", "o", ARG_OUT },
  1300. END_ARGS
  1301. }
  1302. },
  1303. { "NetworkSelected", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1304. {
  1305. { "path", "o", ARG_OUT },
  1306. END_ARGS
  1307. }
  1308. },
  1309. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1310. {
  1311. { "properties", "a{sv}", ARG_OUT },
  1312. END_ARGS
  1313. }
  1314. },
  1315. #ifdef CONFIG_WPS
  1316. { "Event", WPAS_DBUS_NEW_IFACE_WPS,
  1317. {
  1318. { "name", "s", ARG_OUT },
  1319. { "args", "a{sv}", ARG_OUT },
  1320. END_ARGS
  1321. }
  1322. },
  1323. { "Credentials", WPAS_DBUS_NEW_IFACE_WPS,
  1324. {
  1325. { "credentials", "a{sv}", ARG_OUT },
  1326. END_ARGS
  1327. }
  1328. },
  1329. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_WPS,
  1330. {
  1331. { "properties", "a{sv}", ARG_OUT },
  1332. END_ARGS
  1333. }
  1334. },
  1335. #endif /* CONFIG_WPS */
  1336. { NULL, NULL, { END_ARGS } }
  1337. };
  1338. int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s)
  1339. {
  1340. struct wpa_dbus_object_desc *obj_desc = NULL;
  1341. struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus;
  1342. int next;
  1343. /* Do nothing if the control interface is not turned on */
  1344. if (ctrl_iface == NULL)
  1345. return 0;
  1346. /* Create and set the interface's object path */
  1347. wpa_s->dbus_new_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
  1348. if (wpa_s->dbus_new_path == NULL)
  1349. return -1;
  1350. next = ctrl_iface->next_objid++;
  1351. os_snprintf(wpa_s->dbus_new_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1352. WPAS_DBUS_NEW_PATH_INTERFACES "/%u",
  1353. next);
  1354. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  1355. if (!obj_desc) {
  1356. wpa_printf(MSG_ERROR, "Not enough memory "
  1357. "to create object description");
  1358. goto err;
  1359. }
  1360. wpas_dbus_register(obj_desc, wpa_s, NULL, wpas_dbus_interface_methods,
  1361. wpas_dbus_interface_properties,
  1362. wpas_dbus_interface_signals);
  1363. wpa_printf(MSG_DEBUG, "dbus: Register interface object '%s'",
  1364. wpa_s->dbus_new_path);
  1365. if (wpa_dbus_register_object_per_iface(ctrl_iface,
  1366. wpa_s->dbus_new_path,
  1367. wpa_s->ifname, obj_desc))
  1368. goto err;
  1369. wpas_dbus_signal_interface_added(wpa_s);
  1370. return 0;
  1371. err:
  1372. os_free(wpa_s->dbus_new_path);
  1373. wpa_s->dbus_new_path = NULL;
  1374. os_free(obj_desc);
  1375. return -1;
  1376. }
  1377. int wpas_dbus_unregister_interface(struct wpa_supplicant *wpa_s)
  1378. {
  1379. struct wpas_dbus_priv *ctrl_iface;
  1380. /* Do nothing if the control interface is not turned on */
  1381. if (wpa_s == NULL || wpa_s->global == NULL)
  1382. return 0;
  1383. ctrl_iface = wpa_s->global->dbus;
  1384. if (ctrl_iface == NULL)
  1385. return 0;
  1386. wpa_printf(MSG_DEBUG, "dbus: Unregister interface object '%s'",
  1387. wpa_s->dbus_new_path);
  1388. if (wpa_dbus_unregister_object_per_iface(ctrl_iface,
  1389. wpa_s->dbus_new_path))
  1390. return -1;
  1391. wpas_dbus_signal_interface_removed(wpa_s);
  1392. os_free(wpa_s->dbus_new_path);
  1393. wpa_s->dbus_new_path = NULL;
  1394. return 0;
  1395. }