notify.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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.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. struct wpas_dbus_callbacks *cbs = wpas_dbus_get_callbacks();
  45. if (wpas_dbus_register_iface(wpa_s))
  46. return -1;
  47. if (cbs && cbs->register_interface(wpa_s))
  48. return -1;
  49. return 0;
  50. }
  51. void wpas_notify_iface_removed(struct wpa_supplicant *wpa_s)
  52. {
  53. struct wpas_dbus_callbacks *cbs = wpas_dbus_get_callbacks();
  54. /* unregister interface in old DBus ctrl iface */
  55. wpas_dbus_unregister_iface(wpa_s);
  56. /* unregister interface in new DBus ctrl iface */
  57. if (cbs)
  58. cbs->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. struct wpas_dbus_callbacks *cbs = wpas_dbus_get_callbacks();
  65. /* notify the old DBus API */
  66. wpa_supplicant_dbus_notify_state_change(wpa_s, new_state,
  67. old_state);
  68. /* notify the new DBus API */
  69. if (cbs)
  70. cbs->signal_state_changed(wpa_s, new_state, old_state);
  71. }
  72. void wpas_notify_network_changed(struct wpa_supplicant *wpa_s)
  73. {
  74. struct wpas_dbus_callbacks *cbs = wpas_dbus_get_callbacks();
  75. if (cbs)
  76. cbs->signal_prop_changed(wpa_s,
  77. WPAS_DBUS_PROP_CURRENT_NETWORK);
  78. }
  79. void wpas_notify_ap_scan_changed(struct wpa_supplicant *wpa_s)
  80. {
  81. struct wpas_dbus_callbacks *cbs = wpas_dbus_get_callbacks();
  82. if (cbs)
  83. cbs->signal_prop_changed(wpa_s, WPAS_DBUS_PROP_AP_SCAN);
  84. }
  85. void wpas_notify_bssid_changed(struct wpa_supplicant *wpa_s)
  86. {
  87. struct wpas_dbus_callbacks *cbs = wpas_dbus_get_callbacks();
  88. if (cbs)
  89. cbs->signal_prop_changed(wpa_s, WPAS_DBUS_PROP_CURRENT_BSS);
  90. }
  91. void wpas_notify_network_enabled_changed(struct wpa_supplicant *wpa_s,
  92. struct wpa_ssid *ssid)
  93. {
  94. struct wpas_dbus_callbacks *cbs = wpas_dbus_get_callbacks();
  95. if (cbs)
  96. cbs->signal_network_enabled_changed(wpa_s, ssid);
  97. }
  98. void wpas_notify_network_selected(struct wpa_supplicant *wpa_s,
  99. struct wpa_ssid *ssid)
  100. {
  101. struct wpas_dbus_callbacks *cbs = wpas_dbus_get_callbacks();
  102. if (cbs)
  103. cbs->signal_network_selected(wpa_s, ssid->id);
  104. }
  105. void wpas_notify_scanning(struct wpa_supplicant *wpa_s)
  106. {
  107. struct wpas_dbus_callbacks *cbs = wpas_dbus_get_callbacks();
  108. /* notify the old DBus API */
  109. wpa_supplicant_dbus_notify_scanning(wpa_s);
  110. /* notify the new DBus API */
  111. if (cbs)
  112. cbs->signal_prop_changed(wpa_s, WPAS_DBUS_PROP_SCANNING);
  113. }
  114. void wpas_notify_scan_done(struct wpa_supplicant *wpa_s, int success)
  115. {
  116. struct wpas_dbus_callbacks *cbs = wpas_dbus_get_callbacks();
  117. if (cbs)
  118. cbs->signal_scan_done(wpa_s, success);
  119. }
  120. void wpas_notify_scan_results(struct wpa_supplicant *wpa_s)
  121. {
  122. /* notify the old DBus API */
  123. wpa_supplicant_dbus_notify_scan_results(wpa_s);
  124. wpas_wps_notify_scan_results(wpa_s);
  125. }
  126. void wpas_notify_wps_credential(struct wpa_supplicant *wpa_s,
  127. const struct wps_credential *cred)
  128. {
  129. #ifdef CONFIG_WPS
  130. struct wpas_dbus_callbacks *cbs = wpas_dbus_get_callbacks();
  131. #endif /* CONFIG_WPS */
  132. /* notify the old DBus API */
  133. wpa_supplicant_dbus_notify_wps_cred(wpa_s, cred);
  134. /* notify the new DBus API */
  135. #ifdef CONFIG_WPS
  136. if (cbs)
  137. cbs->signal_wps_credentials(wpa_s, cred);
  138. #endif /* CONFIG_WPS */
  139. }
  140. void wpas_notify_wps_event_m2d(struct wpa_supplicant *wpa_s,
  141. struct wps_event_m2d *m2d)
  142. {
  143. #ifdef CONFIG_WPS
  144. struct wpas_dbus_callbacks *cbs = wpas_dbus_get_callbacks();
  145. if (cbs)
  146. cbs->signal_wps_event_m2d(wpa_s, m2d);
  147. #endif /* CONFIG_WPS */
  148. }
  149. void wpas_notify_wps_event_fail(struct wpa_supplicant *wpa_s,
  150. struct wps_event_fail *fail)
  151. {
  152. #ifdef CONFIG_WPS
  153. struct wpas_dbus_callbacks *cbs = wpas_dbus_get_callbacks();
  154. if (cbs)
  155. cbs->signal_wps_event_fail(wpa_s, fail);
  156. #endif /* CONFIG_WPS */
  157. }
  158. void wpas_notify_wps_event_success(struct wpa_supplicant *wpa_s)
  159. {
  160. #ifdef CONFIG_WPS
  161. struct wpas_dbus_callbacks *cbs = wpas_dbus_get_callbacks();
  162. if (cbs)
  163. cbs->signal_wps_event_success(wpa_s);
  164. #endif /* CONFIG_WPS */
  165. }
  166. void wpas_notify_network_added(struct wpa_supplicant *wpa_s,
  167. struct wpa_ssid *ssid)
  168. {
  169. struct wpas_dbus_callbacks *cbs = wpas_dbus_get_callbacks();
  170. if (wpa_s->global->dbus && cbs)
  171. cbs->register_network(wpa_s, ssid);
  172. }
  173. void wpas_notify_network_removed(struct wpa_supplicant *wpa_s,
  174. struct wpa_ssid *ssid)
  175. {
  176. struct wpas_dbus_callbacks *cbs = wpas_dbus_get_callbacks();
  177. if (wpa_s->global->dbus && cbs)
  178. cbs->unregister_network(wpa_s, ssid->id);
  179. }
  180. void wpas_notify_bss_added(struct wpa_supplicant *wpa_s,
  181. u8 bssid[], unsigned int id)
  182. {
  183. struct wpas_dbus_callbacks *cbs = wpas_dbus_get_callbacks();
  184. if (cbs)
  185. cbs->register_bss(wpa_s, bssid, id);
  186. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_BSS_ADDED "%u " MACSTR,
  187. id, MAC2STR(bssid));
  188. }
  189. void wpas_notify_bss_removed(struct wpa_supplicant *wpa_s,
  190. u8 bssid[], unsigned int id)
  191. {
  192. struct wpas_dbus_callbacks *cbs = wpas_dbus_get_callbacks();
  193. if (cbs)
  194. cbs->unregister_bss(wpa_s, bssid, id);
  195. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_BSS_REMOVED "%u " MACSTR,
  196. id, MAC2STR(bssid));
  197. }
  198. void wpas_notify_blob_added(struct wpa_supplicant *wpa_s, const char *name)
  199. {
  200. struct wpas_dbus_callbacks *cbs = wpas_dbus_get_callbacks();
  201. if (cbs)
  202. cbs->signal_blob_added(wpa_s, name);
  203. }
  204. void wpas_notify_blob_removed(struct wpa_supplicant *wpa_s, const char *name)
  205. {
  206. struct wpas_dbus_callbacks *cbs = wpas_dbus_get_callbacks();
  207. if (cbs)
  208. cbs->signal_blob_removed(wpa_s, name);
  209. }
  210. void wpas_notify_debug_params_changed(struct wpa_global *global)
  211. {
  212. struct wpas_dbus_callbacks *cbs = wpas_dbus_get_callbacks();
  213. if (cbs)
  214. cbs->signal_debug_params_changed(global);
  215. }