dbus_new.c 47 KB

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