dbus_new.c 41 KB

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