notify.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. * wpa_supplicant - Event notifications
  3. * Copyright (c) 2009, 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 "notify.h"
  24. int wpas_notify_supplicant_initialized(struct wpa_global *global)
  25. {
  26. #ifdef CONFIG_DBUS
  27. if (global->params.dbus_ctrl_interface) {
  28. global->dbus = wpas_dbus_init(global);
  29. if (global->dbus == NULL)
  30. return -1;
  31. }
  32. #endif /* CONFIG_DBUS */
  33. return 0;
  34. }
  35. void wpas_notify_supplicant_deinitialized(struct wpa_global *global)
  36. {
  37. #ifdef CONFIG_DBUS
  38. if (global->dbus)
  39. wpas_dbus_deinit(global->dbus);
  40. #endif /* CONFIG_DBUS */
  41. }
  42. int wpas_notify_iface_added(struct wpa_supplicant *wpa_s)
  43. {
  44. if (wpas_dbus_register_iface(wpa_s))
  45. return -1;
  46. if (wpas_dbus_register_interface(wpa_s))
  47. return -1;
  48. return 0;
  49. }
  50. void wpas_notify_iface_removed(struct wpa_supplicant *wpa_s)
  51. {
  52. /* unregister interface in old DBus ctrl iface */
  53. wpas_dbus_unregister_iface(wpa_s);
  54. /* unregister interface in new DBus ctrl iface */
  55. wpas_dbus_unregister_interface(wpa_s);
  56. }
  57. void wpas_notify_state_changed(struct wpa_supplicant *wpa_s,
  58. enum wpa_states new_state,
  59. enum wpa_states old_state)
  60. {
  61. /* notify the old DBus API */
  62. wpa_supplicant_dbus_notify_state_change(wpa_s, new_state,
  63. old_state);
  64. /* notify the new DBus API */
  65. wpas_dbus_signal_state_changed(wpa_s, new_state, old_state);
  66. }
  67. void wpas_notify_network_changed(struct wpa_supplicant *wpa_s)
  68. {
  69. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_CURRENT_NETWORK);
  70. }
  71. void wpas_notify_ap_scan_changed(struct wpa_supplicant *wpa_s)
  72. {
  73. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_AP_SCAN);
  74. }
  75. void wpas_notify_bssid_changed(struct wpa_supplicant *wpa_s)
  76. {
  77. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_CURRENT_BSS);
  78. }
  79. void wpas_notify_network_enabled_changed(struct wpa_supplicant *wpa_s,
  80. struct wpa_ssid *ssid)
  81. {
  82. wpas_dbus_signal_network_enabled_changed(wpa_s, ssid);
  83. }
  84. void wpas_notify_network_selected(struct wpa_supplicant *wpa_s,
  85. struct wpa_ssid *ssid)
  86. {
  87. wpas_dbus_signal_network_selected(wpa_s, ssid->id);
  88. }
  89. void wpas_notify_scanning(struct wpa_supplicant *wpa_s)
  90. {
  91. /* notify the old DBus API */
  92. wpa_supplicant_dbus_notify_scanning(wpa_s);
  93. /* notify the new DBus API */
  94. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_SCANNING);
  95. }
  96. void wpas_notify_scan_done(struct wpa_supplicant *wpa_s, int success)
  97. {
  98. wpas_dbus_signal_scan_done(wpa_s, success);
  99. }
  100. void wpas_notify_scan_results(struct wpa_supplicant *wpa_s)
  101. {
  102. /* notify the old DBus API */
  103. wpa_supplicant_dbus_notify_scan_results(wpa_s);
  104. wpas_wps_notify_scan_results(wpa_s);
  105. }
  106. void wpas_notify_wps_credential(struct wpa_supplicant *wpa_s,
  107. const struct wps_credential *cred)
  108. {
  109. #ifdef CONFIG_WPS
  110. /* notify the old DBus API */
  111. wpa_supplicant_dbus_notify_wps_cred(wpa_s, cred);
  112. /* notify the new DBus API */
  113. wpas_dbus_signal_wps_cred(wpa_s, cred);
  114. #endif /* CONFIG_WPS */
  115. }
  116. void wpas_notify_wps_event_m2d(struct wpa_supplicant *wpa_s,
  117. struct wps_event_m2d *m2d)
  118. {
  119. #ifdef CONFIG_WPS
  120. wpas_dbus_signal_wps_event_m2d(wpa_s, m2d);
  121. #endif /* CONFIG_WPS */
  122. }
  123. void wpas_notify_wps_event_fail(struct wpa_supplicant *wpa_s,
  124. struct wps_event_fail *fail)
  125. {
  126. #ifdef CONFIG_WPS
  127. wpas_dbus_signal_wps_event_fail(wpa_s, fail);
  128. #endif /* CONFIG_WPS */
  129. }
  130. void wpas_notify_wps_event_success(struct wpa_supplicant *wpa_s)
  131. {
  132. #ifdef CONFIG_WPS
  133. wpas_dbus_signal_wps_event_success(wpa_s);
  134. #endif /* CONFIG_WPS */
  135. }
  136. void wpas_notify_network_added(struct wpa_supplicant *wpa_s,
  137. struct wpa_ssid *ssid)
  138. {
  139. wpas_dbus_register_network(wpa_s, ssid);
  140. }
  141. void wpas_notify_network_removed(struct wpa_supplicant *wpa_s,
  142. struct wpa_ssid *ssid)
  143. {
  144. wpas_dbus_unregister_network(wpa_s, ssid->id);
  145. }
  146. void wpas_notify_bss_added(struct wpa_supplicant *wpa_s,
  147. u8 bssid[], unsigned int id)
  148. {
  149. wpas_dbus_register_bss(wpa_s, bssid, id);
  150. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_BSS_ADDED "%u " MACSTR,
  151. id, MAC2STR(bssid));
  152. }
  153. void wpas_notify_bss_removed(struct wpa_supplicant *wpa_s,
  154. u8 bssid[], unsigned int id)
  155. {
  156. wpas_dbus_unregister_bss(wpa_s, bssid, id);
  157. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_BSS_REMOVED "%u " MACSTR,
  158. id, MAC2STR(bssid));
  159. }
  160. void wpas_notify_blob_added(struct wpa_supplicant *wpa_s, const char *name)
  161. {
  162. wpas_dbus_signal_blob_added(wpa_s, name);
  163. }
  164. void wpas_notify_blob_removed(struct wpa_supplicant *wpa_s, const char *name)
  165. {
  166. wpas_dbus_signal_blob_removed(wpa_s, name);
  167. }
  168. void wpas_notify_debug_level_changed(struct wpa_global *global)
  169. {
  170. wpas_dbus_signal_debug_level_changed(global);
  171. }
  172. void wpas_notify_debug_timestamp_changed(struct wpa_global *global)
  173. {
  174. wpas_dbus_signal_debug_timestamp_changed(global);
  175. }
  176. void wpas_notify_debug_show_keys_changed(struct wpa_global *global)
  177. {
  178. wpas_dbus_signal_debug_show_keys_changed(global);
  179. }