dbus_new.c 39 KB

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