notify.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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 "notify.h"
  26. int wpas_notify_supplicant_initialized(struct wpa_global *global)
  27. {
  28. #ifdef CONFIG_DBUS
  29. if (global->params.dbus_ctrl_interface) {
  30. global->dbus = wpas_dbus_init(global);
  31. if (global->dbus == NULL)
  32. return -1;
  33. }
  34. #endif /* CONFIG_DBUS */
  35. return 0;
  36. }
  37. void wpas_notify_supplicant_deinitialized(struct wpa_global *global)
  38. {
  39. #ifdef CONFIG_DBUS
  40. if (global->dbus)
  41. wpas_dbus_deinit(global->dbus);
  42. #endif /* CONFIG_DBUS */
  43. }
  44. int wpas_notify_iface_added(struct wpa_supplicant *wpa_s)
  45. {
  46. if (wpas_dbus_register_iface(wpa_s))
  47. return -1;
  48. if (wpas_dbus_register_interface(wpa_s))
  49. return -1;
  50. return 0;
  51. }
  52. void wpas_notify_iface_removed(struct wpa_supplicant *wpa_s)
  53. {
  54. /* unregister interface in old DBus ctrl iface */
  55. wpas_dbus_unregister_iface(wpa_s);
  56. /* unregister interface in new DBus ctrl iface */
  57. wpas_dbus_unregister_interface(wpa_s);
  58. }
  59. void wpas_notify_state_changed(struct wpa_supplicant *wpa_s,
  60. enum wpa_states new_state,
  61. enum wpa_states old_state)
  62. {
  63. /* notify the old DBus API */
  64. wpa_supplicant_dbus_notify_state_change(wpa_s, new_state,
  65. old_state);
  66. /* notify the new DBus API */
  67. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_STATE);
  68. }
  69. void wpas_notify_network_changed(struct wpa_supplicant *wpa_s)
  70. {
  71. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_CURRENT_NETWORK);
  72. }
  73. void wpas_notify_ap_scan_changed(struct wpa_supplicant *wpa_s)
  74. {
  75. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_AP_SCAN);
  76. }
  77. void wpas_notify_bssid_changed(struct wpa_supplicant *wpa_s)
  78. {
  79. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_CURRENT_BSS);
  80. }
  81. void wpas_notify_network_enabled_changed(struct wpa_supplicant *wpa_s,
  82. struct wpa_ssid *ssid)
  83. {
  84. wpas_dbus_signal_network_enabled_changed(wpa_s, ssid);
  85. }
  86. void wpas_notify_network_selected(struct wpa_supplicant *wpa_s,
  87. struct wpa_ssid *ssid)
  88. {
  89. wpas_dbus_signal_network_selected(wpa_s, ssid->id);
  90. }
  91. void wpas_notify_scanning(struct wpa_supplicant *wpa_s)
  92. {
  93. /* notify the old DBus API */
  94. wpa_supplicant_dbus_notify_scanning(wpa_s);
  95. /* notify the new DBus API */
  96. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_SCANNING);
  97. }
  98. void wpas_notify_scan_done(struct wpa_supplicant *wpa_s, int success)
  99. {
  100. wpas_dbus_signal_scan_done(wpa_s, success);
  101. }
  102. void wpas_notify_scan_results(struct wpa_supplicant *wpa_s)
  103. {
  104. /* notify the old DBus API */
  105. wpa_supplicant_dbus_notify_scan_results(wpa_s);
  106. wpas_wps_notify_scan_results(wpa_s);
  107. }
  108. void wpas_notify_wps_credential(struct wpa_supplicant *wpa_s,
  109. const struct wps_credential *cred)
  110. {
  111. #ifdef CONFIG_WPS
  112. /* notify the old DBus API */
  113. wpa_supplicant_dbus_notify_wps_cred(wpa_s, cred);
  114. /* notify the new DBus API */
  115. wpas_dbus_signal_wps_cred(wpa_s, cred);
  116. #endif /* CONFIG_WPS */
  117. }
  118. void wpas_notify_wps_event_m2d(struct wpa_supplicant *wpa_s,
  119. struct wps_event_m2d *m2d)
  120. {
  121. #ifdef CONFIG_WPS
  122. wpas_dbus_signal_wps_event_m2d(wpa_s, m2d);
  123. #endif /* CONFIG_WPS */
  124. }
  125. void wpas_notify_wps_event_fail(struct wpa_supplicant *wpa_s,
  126. struct wps_event_fail *fail)
  127. {
  128. #ifdef CONFIG_WPS
  129. wpas_dbus_signal_wps_event_fail(wpa_s, fail);
  130. #endif /* CONFIG_WPS */
  131. }
  132. void wpas_notify_wps_event_success(struct wpa_supplicant *wpa_s)
  133. {
  134. #ifdef CONFIG_WPS
  135. wpas_dbus_signal_wps_event_success(wpa_s);
  136. #endif /* CONFIG_WPS */
  137. }
  138. void wpas_notify_network_added(struct wpa_supplicant *wpa_s,
  139. struct wpa_ssid *ssid)
  140. {
  141. wpas_dbus_register_network(wpa_s, ssid);
  142. }
  143. void wpas_notify_network_removed(struct wpa_supplicant *wpa_s,
  144. struct wpa_ssid *ssid)
  145. {
  146. wpas_dbus_unregister_network(wpa_s, ssid->id);
  147. }
  148. void wpas_notify_bss_added(struct wpa_supplicant *wpa_s,
  149. u8 bssid[], unsigned int id)
  150. {
  151. wpas_dbus_register_bss(wpa_s, bssid, id);
  152. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_BSS_ADDED "%u " MACSTR,
  153. id, MAC2STR(bssid));
  154. }
  155. void wpas_notify_bss_removed(struct wpa_supplicant *wpa_s,
  156. u8 bssid[], unsigned int id)
  157. {
  158. wpas_dbus_unregister_bss(wpa_s, bssid, id);
  159. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_BSS_REMOVED "%u " MACSTR,
  160. id, MAC2STR(bssid));
  161. }
  162. void wpas_notify_bss_freq_changed(struct wpa_supplicant *wpa_s,
  163. unsigned int id)
  164. {
  165. wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_FREQ, id);
  166. }
  167. void wpas_notify_bss_signal_changed(struct wpa_supplicant *wpa_s,
  168. unsigned int id)
  169. {
  170. wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_SIGNAL,
  171. id);
  172. }
  173. void wpas_notify_bss_privacy_changed(struct wpa_supplicant *wpa_s,
  174. unsigned int id)
  175. {
  176. wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_PRIVACY,
  177. id);
  178. }
  179. void wpas_notify_bss_mode_changed(struct wpa_supplicant *wpa_s,
  180. unsigned int id)
  181. {
  182. wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_MODE, id);
  183. }
  184. void wpas_notify_bss_wpaie_changed(struct wpa_supplicant *wpa_s,
  185. unsigned int id)
  186. {
  187. wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_WPA, id);
  188. }
  189. void wpas_notify_bss_rsnie_changed(struct wpa_supplicant *wpa_s,
  190. unsigned int id)
  191. {
  192. wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_RSN, id);
  193. }
  194. void wpas_notify_bss_wps_changed(struct wpa_supplicant *wpa_s,
  195. unsigned int id)
  196. {
  197. }
  198. void wpas_notify_bss_ies_changed(struct wpa_supplicant *wpa_s,
  199. unsigned int id)
  200. {
  201. wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_IES, id);
  202. }
  203. void wpas_notify_bss_rates_changed(struct wpa_supplicant *wpa_s,
  204. unsigned int id)
  205. {
  206. wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_RATES, id);
  207. }
  208. void wpas_notify_blob_added(struct wpa_supplicant *wpa_s, const char *name)
  209. {
  210. wpas_dbus_signal_blob_added(wpa_s, name);
  211. }
  212. void wpas_notify_blob_removed(struct wpa_supplicant *wpa_s, const char *name)
  213. {
  214. wpas_dbus_signal_blob_removed(wpa_s, name);
  215. }
  216. void wpas_notify_debug_level_changed(struct wpa_global *global)
  217. {
  218. wpas_dbus_signal_debug_level_changed(global);
  219. }
  220. void wpas_notify_debug_timestamp_changed(struct wpa_global *global)
  221. {
  222. wpas_dbus_signal_debug_timestamp_changed(global);
  223. }
  224. void wpas_notify_debug_show_keys_changed(struct wpa_global *global)
  225. {
  226. wpas_dbus_signal_debug_show_keys_changed(global);
  227. }
  228. void wpas_notify_suspend(struct wpa_global *global)
  229. {
  230. struct wpa_supplicant *wpa_s;
  231. os_get_time(&global->suspend_time);
  232. wpa_printf(MSG_DEBUG, "System suspend notification");
  233. for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
  234. wpa_drv_suspend(wpa_s);
  235. }
  236. void wpas_notify_resume(struct wpa_global *global)
  237. {
  238. struct os_time now;
  239. int slept;
  240. struct wpa_supplicant *wpa_s;
  241. if (global->suspend_time.sec == 0)
  242. slept = -1;
  243. else {
  244. os_get_time(&now);
  245. slept = now.sec - global->suspend_time.sec;
  246. }
  247. wpa_printf(MSG_DEBUG, "System resume notification (slept %d seconds)",
  248. slept);
  249. for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
  250. wpa_drv_resume(wpa_s);
  251. if (wpa_s->wpa_state == WPA_DISCONNECTED)
  252. wpa_supplicant_req_scan(wpa_s, 0, 100000);
  253. }
  254. }