notify.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. /*
  2. * wpa_supplicant - Event notifications
  3. * Copyright (c) 2009-2010, Jouni Malinen <j@w1.fi>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * Alternatively, this software may be distributed under the terms of BSD
  10. * license.
  11. *
  12. * See README and COPYING for more details.
  13. */
  14. #include "utils/includes.h"
  15. #include "utils/common.h"
  16. #include "common/wpa_ctrl.h"
  17. #include "config.h"
  18. #include "wpa_supplicant_i.h"
  19. #include "wps_supplicant.h"
  20. #include "dbus/dbus_common.h"
  21. #include "dbus/dbus_old.h"
  22. #include "dbus/dbus_new.h"
  23. #include "driver_i.h"
  24. #include "scan.h"
  25. #include "p2p_supplicant.h"
  26. #include "notify.h"
  27. int wpas_notify_supplicant_initialized(struct wpa_global *global)
  28. {
  29. #ifdef CONFIG_DBUS
  30. if (global->params.dbus_ctrl_interface) {
  31. global->dbus = wpas_dbus_init(global);
  32. if (global->dbus == NULL)
  33. return -1;
  34. }
  35. #endif /* CONFIG_DBUS */
  36. return 0;
  37. }
  38. void wpas_notify_supplicant_deinitialized(struct wpa_global *global)
  39. {
  40. #ifdef CONFIG_DBUS
  41. if (global->dbus)
  42. wpas_dbus_deinit(global->dbus);
  43. #endif /* CONFIG_DBUS */
  44. }
  45. int wpas_notify_iface_added(struct wpa_supplicant *wpa_s)
  46. {
  47. if (wpas_dbus_register_iface(wpa_s))
  48. return -1;
  49. if (wpas_dbus_register_interface(wpa_s))
  50. return -1;
  51. return 0;
  52. }
  53. void wpas_notify_iface_removed(struct wpa_supplicant *wpa_s)
  54. {
  55. /* unregister interface in old DBus ctrl iface */
  56. wpas_dbus_unregister_iface(wpa_s);
  57. /* unregister interface in new DBus ctrl iface */
  58. wpas_dbus_unregister_interface(wpa_s);
  59. }
  60. void wpas_notify_state_changed(struct wpa_supplicant *wpa_s,
  61. enum wpa_states new_state,
  62. enum wpa_states old_state)
  63. {
  64. /* notify the old DBus API */
  65. wpa_supplicant_dbus_notify_state_change(wpa_s, new_state,
  66. old_state);
  67. /* notify the new DBus API */
  68. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_STATE);
  69. #ifdef CONFIG_P2P
  70. if (new_state == WPA_COMPLETED)
  71. wpas_p2p_notif_connected(wpa_s);
  72. else if (new_state < WPA_ASSOCIATED)
  73. wpas_p2p_notif_disconnected(wpa_s);
  74. #endif /* CONFIG_P2P */
  75. }
  76. void wpas_notify_network_changed(struct wpa_supplicant *wpa_s)
  77. {
  78. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_CURRENT_NETWORK);
  79. }
  80. void wpas_notify_ap_scan_changed(struct wpa_supplicant *wpa_s)
  81. {
  82. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_AP_SCAN);
  83. }
  84. void wpas_notify_bssid_changed(struct wpa_supplicant *wpa_s)
  85. {
  86. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_CURRENT_BSS);
  87. }
  88. void wpas_notify_network_enabled_changed(struct wpa_supplicant *wpa_s,
  89. struct wpa_ssid *ssid)
  90. {
  91. wpas_dbus_signal_network_enabled_changed(wpa_s, ssid);
  92. }
  93. void wpas_notify_network_selected(struct wpa_supplicant *wpa_s,
  94. struct wpa_ssid *ssid)
  95. {
  96. wpas_dbus_signal_network_selected(wpa_s, ssid->id);
  97. }
  98. void wpas_notify_scanning(struct wpa_supplicant *wpa_s)
  99. {
  100. /* notify the old DBus API */
  101. wpa_supplicant_dbus_notify_scanning(wpa_s);
  102. /* notify the new DBus API */
  103. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_SCANNING);
  104. }
  105. void wpas_notify_scan_done(struct wpa_supplicant *wpa_s, int success)
  106. {
  107. wpas_dbus_signal_scan_done(wpa_s, success);
  108. }
  109. void wpas_notify_scan_results(struct wpa_supplicant *wpa_s)
  110. {
  111. /* notify the old DBus API */
  112. wpa_supplicant_dbus_notify_scan_results(wpa_s);
  113. wpas_wps_notify_scan_results(wpa_s);
  114. }
  115. void wpas_notify_wps_credential(struct wpa_supplicant *wpa_s,
  116. const struct wps_credential *cred)
  117. {
  118. #ifdef CONFIG_WPS
  119. /* notify the old DBus API */
  120. wpa_supplicant_dbus_notify_wps_cred(wpa_s, cred);
  121. /* notify the new DBus API */
  122. wpas_dbus_signal_wps_cred(wpa_s, cred);
  123. #endif /* CONFIG_WPS */
  124. }
  125. void wpas_notify_wps_event_m2d(struct wpa_supplicant *wpa_s,
  126. struct wps_event_m2d *m2d)
  127. {
  128. #ifdef CONFIG_WPS
  129. wpas_dbus_signal_wps_event_m2d(wpa_s, m2d);
  130. #endif /* CONFIG_WPS */
  131. }
  132. void wpas_notify_wps_event_fail(struct wpa_supplicant *wpa_s,
  133. struct wps_event_fail *fail)
  134. {
  135. #ifdef CONFIG_WPS
  136. wpas_dbus_signal_wps_event_fail(wpa_s, fail);
  137. #endif /* CONFIG_WPS */
  138. }
  139. void wpas_notify_wps_event_success(struct wpa_supplicant *wpa_s)
  140. {
  141. #ifdef CONFIG_WPS
  142. wpas_dbus_signal_wps_event_success(wpa_s);
  143. #endif /* CONFIG_WPS */
  144. }
  145. void wpas_notify_network_added(struct wpa_supplicant *wpa_s,
  146. struct wpa_ssid *ssid)
  147. {
  148. wpas_dbus_register_network(wpa_s, ssid);
  149. }
  150. void wpas_notify_network_removed(struct wpa_supplicant *wpa_s,
  151. struct wpa_ssid *ssid)
  152. {
  153. wpas_dbus_unregister_network(wpa_s, ssid->id);
  154. }
  155. void wpas_notify_bss_added(struct wpa_supplicant *wpa_s,
  156. u8 bssid[], unsigned int id)
  157. {
  158. wpas_dbus_register_bss(wpa_s, bssid, id);
  159. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_BSS_ADDED "%u " MACSTR,
  160. id, MAC2STR(bssid));
  161. }
  162. void wpas_notify_bss_removed(struct wpa_supplicant *wpa_s,
  163. u8 bssid[], unsigned int id)
  164. {
  165. wpas_dbus_unregister_bss(wpa_s, bssid, id);
  166. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_BSS_REMOVED "%u " MACSTR,
  167. id, MAC2STR(bssid));
  168. }
  169. void wpas_notify_bss_freq_changed(struct wpa_supplicant *wpa_s,
  170. unsigned int id)
  171. {
  172. wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_FREQ, id);
  173. }
  174. void wpas_notify_bss_signal_changed(struct wpa_supplicant *wpa_s,
  175. unsigned int id)
  176. {
  177. wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_SIGNAL,
  178. id);
  179. }
  180. void wpas_notify_bss_privacy_changed(struct wpa_supplicant *wpa_s,
  181. unsigned int id)
  182. {
  183. wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_PRIVACY,
  184. id);
  185. }
  186. void wpas_notify_bss_mode_changed(struct wpa_supplicant *wpa_s,
  187. unsigned int id)
  188. {
  189. wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_MODE, id);
  190. }
  191. void wpas_notify_bss_wpaie_changed(struct wpa_supplicant *wpa_s,
  192. unsigned int id)
  193. {
  194. wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_WPA, id);
  195. }
  196. void wpas_notify_bss_rsnie_changed(struct wpa_supplicant *wpa_s,
  197. unsigned int id)
  198. {
  199. wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_RSN, id);
  200. }
  201. void wpas_notify_bss_wps_changed(struct wpa_supplicant *wpa_s,
  202. unsigned int id)
  203. {
  204. }
  205. void wpas_notify_bss_ies_changed(struct wpa_supplicant *wpa_s,
  206. unsigned int id)
  207. {
  208. wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_IES, id);
  209. }
  210. void wpas_notify_bss_rates_changed(struct wpa_supplicant *wpa_s,
  211. unsigned int id)
  212. {
  213. wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_RATES, id);
  214. }
  215. void wpas_notify_blob_added(struct wpa_supplicant *wpa_s, const char *name)
  216. {
  217. wpas_dbus_signal_blob_added(wpa_s, name);
  218. }
  219. void wpas_notify_blob_removed(struct wpa_supplicant *wpa_s, const char *name)
  220. {
  221. wpas_dbus_signal_blob_removed(wpa_s, name);
  222. }
  223. void wpas_notify_debug_level_changed(struct wpa_global *global)
  224. {
  225. wpas_dbus_signal_debug_level_changed(global);
  226. }
  227. void wpas_notify_debug_timestamp_changed(struct wpa_global *global)
  228. {
  229. wpas_dbus_signal_debug_timestamp_changed(global);
  230. }
  231. void wpas_notify_debug_show_keys_changed(struct wpa_global *global)
  232. {
  233. wpas_dbus_signal_debug_show_keys_changed(global);
  234. }
  235. void wpas_notify_suspend(struct wpa_global *global)
  236. {
  237. struct wpa_supplicant *wpa_s;
  238. os_get_time(&global->suspend_time);
  239. wpa_printf(MSG_DEBUG, "System suspend notification");
  240. for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
  241. wpa_drv_suspend(wpa_s);
  242. }
  243. void wpas_notify_resume(struct wpa_global *global)
  244. {
  245. struct os_time now;
  246. int slept;
  247. struct wpa_supplicant *wpa_s;
  248. if (global->suspend_time.sec == 0)
  249. slept = -1;
  250. else {
  251. os_get_time(&now);
  252. slept = now.sec - global->suspend_time.sec;
  253. }
  254. wpa_printf(MSG_DEBUG, "System resume notification (slept %d seconds)",
  255. slept);
  256. for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
  257. wpa_drv_resume(wpa_s);
  258. if (wpa_s->wpa_state == WPA_DISCONNECTED)
  259. wpa_supplicant_req_scan(wpa_s, 0, 100000);
  260. }
  261. }