notify.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  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 "sme.h"
  27. #include "notify.h"
  28. int wpas_notify_supplicant_initialized(struct wpa_global *global)
  29. {
  30. #ifdef CONFIG_DBUS
  31. if (global->params.dbus_ctrl_interface) {
  32. global->dbus = wpas_dbus_init(global);
  33. if (global->dbus == NULL)
  34. return -1;
  35. }
  36. #endif /* CONFIG_DBUS */
  37. return 0;
  38. }
  39. void wpas_notify_supplicant_deinitialized(struct wpa_global *global)
  40. {
  41. #ifdef CONFIG_DBUS
  42. if (global->dbus)
  43. wpas_dbus_deinit(global->dbus);
  44. #endif /* CONFIG_DBUS */
  45. }
  46. int wpas_notify_iface_added(struct wpa_supplicant *wpa_s)
  47. {
  48. if (wpas_dbus_register_iface(wpa_s))
  49. return -1;
  50. if (wpas_dbus_register_interface(wpa_s))
  51. return -1;
  52. return 0;
  53. }
  54. void wpas_notify_iface_removed(struct wpa_supplicant *wpa_s)
  55. {
  56. /* unregister interface in old DBus ctrl iface */
  57. wpas_dbus_unregister_iface(wpa_s);
  58. /* unregister interface in new DBus ctrl iface */
  59. wpas_dbus_unregister_interface(wpa_s);
  60. }
  61. void wpas_notify_state_changed(struct wpa_supplicant *wpa_s,
  62. enum wpa_states new_state,
  63. enum wpa_states old_state)
  64. {
  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. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_STATE);
  70. #ifdef CONFIG_P2P
  71. if (new_state == WPA_COMPLETED)
  72. wpas_p2p_notif_connected(wpa_s);
  73. else if (new_state < WPA_ASSOCIATED)
  74. wpas_p2p_notif_disconnected(wpa_s);
  75. #endif /* CONFIG_P2P */
  76. sme_state_changed(wpa_s);
  77. #ifdef ANDROID
  78. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
  79. "id=%d state=%d BSSID=" MACSTR,
  80. wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
  81. new_state, MAC2STR(wpa_s->pending_bssid));
  82. #endif /* ANDROID */
  83. }
  84. void wpas_notify_network_changed(struct wpa_supplicant *wpa_s)
  85. {
  86. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_CURRENT_NETWORK);
  87. }
  88. void wpas_notify_ap_scan_changed(struct wpa_supplicant *wpa_s)
  89. {
  90. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_AP_SCAN);
  91. }
  92. void wpas_notify_bssid_changed(struct wpa_supplicant *wpa_s)
  93. {
  94. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_CURRENT_BSS);
  95. }
  96. void wpas_notify_auth_changed(struct wpa_supplicant *wpa_s)
  97. {
  98. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_CURRENT_AUTH_MODE);
  99. }
  100. void wpas_notify_network_enabled_changed(struct wpa_supplicant *wpa_s,
  101. struct wpa_ssid *ssid)
  102. {
  103. wpas_dbus_signal_network_enabled_changed(wpa_s, ssid);
  104. }
  105. void wpas_notify_network_selected(struct wpa_supplicant *wpa_s,
  106. struct wpa_ssid *ssid)
  107. {
  108. wpas_dbus_signal_network_selected(wpa_s, ssid->id);
  109. }
  110. void wpas_notify_scanning(struct wpa_supplicant *wpa_s)
  111. {
  112. /* notify the old DBus API */
  113. wpa_supplicant_dbus_notify_scanning(wpa_s);
  114. /* notify the new DBus API */
  115. wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_SCANNING);
  116. }
  117. void wpas_notify_scan_done(struct wpa_supplicant *wpa_s, int success)
  118. {
  119. wpas_dbus_signal_scan_done(wpa_s, success);
  120. }
  121. void wpas_notify_scan_results(struct wpa_supplicant *wpa_s)
  122. {
  123. /* notify the old DBus API */
  124. wpa_supplicant_dbus_notify_scan_results(wpa_s);
  125. wpas_wps_notify_scan_results(wpa_s);
  126. }
  127. void wpas_notify_wps_credential(struct wpa_supplicant *wpa_s,
  128. const struct wps_credential *cred)
  129. {
  130. #ifdef CONFIG_WPS
  131. /* notify the old DBus API */
  132. wpa_supplicant_dbus_notify_wps_cred(wpa_s, cred);
  133. /* notify the new DBus API */
  134. wpas_dbus_signal_wps_cred(wpa_s, cred);
  135. #endif /* CONFIG_WPS */
  136. }
  137. void wpas_notify_wps_event_m2d(struct wpa_supplicant *wpa_s,
  138. struct wps_event_m2d *m2d)
  139. {
  140. #ifdef CONFIG_WPS
  141. wpas_dbus_signal_wps_event_m2d(wpa_s, m2d);
  142. #endif /* CONFIG_WPS */
  143. }
  144. void wpas_notify_wps_event_fail(struct wpa_supplicant *wpa_s,
  145. struct wps_event_fail *fail)
  146. {
  147. #ifdef CONFIG_WPS
  148. wpas_dbus_signal_wps_event_fail(wpa_s, fail);
  149. #endif /* CONFIG_WPS */
  150. }
  151. void wpas_notify_wps_event_success(struct wpa_supplicant *wpa_s)
  152. {
  153. #ifdef CONFIG_WPS
  154. wpas_dbus_signal_wps_event_success(wpa_s);
  155. #endif /* CONFIG_WPS */
  156. }
  157. void wpas_notify_network_added(struct wpa_supplicant *wpa_s,
  158. struct wpa_ssid *ssid)
  159. {
  160. /*
  161. * Networks objects created during any P2P activities should not be
  162. * exposed out. They might/will confuse certain non-P2P aware
  163. * applications since these network objects won't behave like
  164. * regular ones.
  165. */
  166. if (wpa_s->global->p2p_group_formation != wpa_s)
  167. wpas_dbus_register_network(wpa_s, ssid);
  168. }
  169. void wpas_notify_persistent_group_added(struct wpa_supplicant *wpa_s,
  170. struct wpa_ssid *ssid)
  171. {
  172. #ifdef CONFIG_P2P
  173. wpas_dbus_register_persistent_group(wpa_s, ssid);
  174. #endif /* CONFIG_P2P */
  175. }
  176. void wpas_notify_persistent_group_removed(struct wpa_supplicant *wpa_s,
  177. struct wpa_ssid *ssid)
  178. {
  179. #ifdef CONFIG_P2P
  180. wpas_dbus_unregister_persistent_group(wpa_s, ssid->id);
  181. #endif /* CONFIG_P2P */
  182. }
  183. void wpas_notify_network_removed(struct wpa_supplicant *wpa_s,
  184. struct wpa_ssid *ssid)
  185. {
  186. if (wpa_s->global->p2p_group_formation != wpa_s)
  187. wpas_dbus_unregister_network(wpa_s, ssid->id);
  188. }
  189. void wpas_notify_bss_added(struct wpa_supplicant *wpa_s,
  190. u8 bssid[], unsigned int id)
  191. {
  192. wpas_dbus_register_bss(wpa_s, bssid, id);
  193. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_BSS_ADDED "%u " MACSTR,
  194. id, MAC2STR(bssid));
  195. }
  196. void wpas_notify_bss_removed(struct wpa_supplicant *wpa_s,
  197. u8 bssid[], unsigned int id)
  198. {
  199. wpas_dbus_unregister_bss(wpa_s, bssid, id);
  200. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_BSS_REMOVED "%u " MACSTR,
  201. id, MAC2STR(bssid));
  202. }
  203. void wpas_notify_bss_freq_changed(struct wpa_supplicant *wpa_s,
  204. unsigned int id)
  205. {
  206. wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_FREQ, id);
  207. }
  208. void wpas_notify_bss_signal_changed(struct wpa_supplicant *wpa_s,
  209. unsigned int id)
  210. {
  211. wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_SIGNAL,
  212. id);
  213. }
  214. void wpas_notify_bss_privacy_changed(struct wpa_supplicant *wpa_s,
  215. unsigned int id)
  216. {
  217. wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_PRIVACY,
  218. id);
  219. }
  220. void wpas_notify_bss_mode_changed(struct wpa_supplicant *wpa_s,
  221. unsigned int id)
  222. {
  223. wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_MODE, id);
  224. }
  225. void wpas_notify_bss_wpaie_changed(struct wpa_supplicant *wpa_s,
  226. unsigned int id)
  227. {
  228. wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_WPA, id);
  229. }
  230. void wpas_notify_bss_rsnie_changed(struct wpa_supplicant *wpa_s,
  231. unsigned int id)
  232. {
  233. wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_RSN, id);
  234. }
  235. void wpas_notify_bss_wps_changed(struct wpa_supplicant *wpa_s,
  236. unsigned int id)
  237. {
  238. }
  239. void wpas_notify_bss_ies_changed(struct wpa_supplicant *wpa_s,
  240. unsigned int id)
  241. {
  242. wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_IES, id);
  243. }
  244. void wpas_notify_bss_rates_changed(struct wpa_supplicant *wpa_s,
  245. unsigned int id)
  246. {
  247. wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_RATES, id);
  248. }
  249. void wpas_notify_blob_added(struct wpa_supplicant *wpa_s, const char *name)
  250. {
  251. wpas_dbus_signal_blob_added(wpa_s, name);
  252. }
  253. void wpas_notify_blob_removed(struct wpa_supplicant *wpa_s, const char *name)
  254. {
  255. wpas_dbus_signal_blob_removed(wpa_s, name);
  256. }
  257. void wpas_notify_debug_level_changed(struct wpa_global *global)
  258. {
  259. wpas_dbus_signal_debug_level_changed(global);
  260. }
  261. void wpas_notify_debug_timestamp_changed(struct wpa_global *global)
  262. {
  263. wpas_dbus_signal_debug_timestamp_changed(global);
  264. }
  265. void wpas_notify_debug_show_keys_changed(struct wpa_global *global)
  266. {
  267. wpas_dbus_signal_debug_show_keys_changed(global);
  268. }
  269. void wpas_notify_suspend(struct wpa_global *global)
  270. {
  271. struct wpa_supplicant *wpa_s;
  272. os_get_time(&global->suspend_time);
  273. wpa_printf(MSG_DEBUG, "System suspend notification");
  274. for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
  275. wpa_drv_suspend(wpa_s);
  276. }
  277. void wpas_notify_resume(struct wpa_global *global)
  278. {
  279. struct os_time now;
  280. int slept;
  281. struct wpa_supplicant *wpa_s;
  282. if (global->suspend_time.sec == 0)
  283. slept = -1;
  284. else {
  285. os_get_time(&now);
  286. slept = now.sec - global->suspend_time.sec;
  287. }
  288. wpa_printf(MSG_DEBUG, "System resume notification (slept %d seconds)",
  289. slept);
  290. for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
  291. wpa_drv_resume(wpa_s);
  292. if (wpa_s->wpa_state == WPA_DISCONNECTED)
  293. wpa_supplicant_req_scan(wpa_s, 0, 100000);
  294. }
  295. }
  296. #ifdef CONFIG_P2P
  297. void wpas_notify_p2p_device_found(struct wpa_supplicant *wpa_s,
  298. const u8 *dev_addr, int new_device)
  299. {
  300. if (new_device) {
  301. /* Create the new peer object */
  302. wpas_dbus_register_peer(wpa_s, dev_addr);
  303. }
  304. /* Notify a new peer has been detected*/
  305. wpas_dbus_signal_peer_device_found(wpa_s, dev_addr);
  306. }
  307. void wpas_notify_p2p_device_lost(struct wpa_supplicant *wpa_s,
  308. const u8 *dev_addr)
  309. {
  310. wpas_dbus_unregister_peer(wpa_s, dev_addr);
  311. /* Create signal on interface object*/
  312. wpas_dbus_signal_peer_device_lost(wpa_s, dev_addr);
  313. }
  314. void wpas_notify_p2p_group_removed(struct wpa_supplicant *wpa_s,
  315. const struct wpa_ssid *ssid,
  316. const char *role)
  317. {
  318. wpas_dbus_unregister_p2p_group(wpa_s, ssid);
  319. wpas_dbus_signal_p2p_group_removed(wpa_s, role);
  320. }
  321. void wpas_notify_p2p_go_neg_req(struct wpa_supplicant *wpa_s,
  322. const u8 *src, u16 dev_passwd_id)
  323. {
  324. wpas_dbus_signal_p2p_go_neg_req(wpa_s, src, dev_passwd_id);
  325. }
  326. void wpas_notify_p2p_go_neg_completed(struct wpa_supplicant *wpa_s, int status)
  327. {
  328. wpas_dbus_signal_p2p_go_neg_resp(wpa_s, status);
  329. }
  330. void wpas_notify_p2p_invitation_result(struct wpa_supplicant *wpa_s,
  331. int status, const u8 *bssid)
  332. {
  333. wpas_dbus_signal_p2p_invitation_result(wpa_s, status, bssid);
  334. }
  335. void wpas_notify_p2p_sd_request(struct wpa_supplicant *wpa_s,
  336. int freq, const u8 *sa, u8 dialog_token,
  337. u16 update_indic, const u8 *tlvs,
  338. size_t tlvs_len)
  339. {
  340. wpas_dbus_signal_p2p_sd_request(wpa_s, freq, sa, dialog_token,
  341. update_indic, tlvs, tlvs_len);
  342. }
  343. void wpas_notify_p2p_sd_response(struct wpa_supplicant *wpa_s,
  344. const u8 *sa, u16 update_indic,
  345. const u8 *tlvs, size_t tlvs_len)
  346. {
  347. wpas_dbus_signal_p2p_sd_response(wpa_s, sa, update_indic,
  348. tlvs, tlvs_len);
  349. }
  350. /**
  351. * wpas_notify_p2p_provision_discovery - Notification of provision discovery
  352. * @dev_addr: Who sent the request or responded to our request.
  353. * @request: Will be 1 if request, 0 for response.
  354. * @status: Valid only in case of response (0 in case of success)
  355. * @config_methods: WPS config methods
  356. * @generated_pin: PIN to be displayed in case of WPS_CONFIG_DISPLAY method
  357. *
  358. * This can be used to notify:
  359. * - Requests or responses
  360. * - Various config methods
  361. * - Failure condition in case of response
  362. */
  363. void wpas_notify_p2p_provision_discovery(struct wpa_supplicant *wpa_s,
  364. const u8 *dev_addr, int request,
  365. enum p2p_prov_disc_status status,
  366. u16 config_methods,
  367. unsigned int generated_pin)
  368. {
  369. wpas_dbus_signal_p2p_provision_discovery(wpa_s, dev_addr, request,
  370. status, config_methods,
  371. generated_pin);
  372. }
  373. void wpas_notify_p2p_group_started(struct wpa_supplicant *wpa_s,
  374. struct wpa_ssid *ssid, int network_id,
  375. int client)
  376. {
  377. /* Notify a group has been started */
  378. wpas_dbus_register_p2p_group(wpa_s, ssid);
  379. wpas_dbus_signal_p2p_group_started(wpa_s, ssid, client, network_id);
  380. }
  381. void wpas_notify_p2p_wps_failed(struct wpa_supplicant *wpa_s,
  382. struct wps_event_fail *fail)
  383. {
  384. wpas_dbus_signal_p2p_wps_failed(wpa_s, fail);
  385. }
  386. #endif /* CONFIG_P2P */
  387. static void wpas_notify_ap_sta_authorized(struct wpa_supplicant *wpa_s,
  388. const u8 *sta)
  389. {
  390. #ifdef CONFIG_P2P
  391. /*
  392. * Register a group member object corresponding to this peer and
  393. * emit a PeerJoined signal. This will check if it really is a
  394. * P2P group.
  395. */
  396. wpas_dbus_register_p2p_groupmember(wpa_s, sta);
  397. /*
  398. * Create 'peer-joined' signal on group object -- will also
  399. * check P2P itself.
  400. */
  401. wpas_dbus_signal_p2p_peer_joined(wpa_s, sta);
  402. #endif /* CONFIG_P2P */
  403. }
  404. static void wpas_notify_ap_sta_deauthorized(struct wpa_supplicant *wpa_s,
  405. const u8 *sta)
  406. {
  407. #ifdef CONFIG_P2P
  408. /*
  409. * Unregister a group member object corresponding to this peer
  410. * if this is a P2P group.
  411. */
  412. wpas_dbus_unregister_p2p_groupmember(wpa_s, sta);
  413. /*
  414. * Create 'peer-disconnected' signal on group object if this
  415. * is a P2P group.
  416. */
  417. wpas_dbus_signal_p2p_peer_disconnected(wpa_s, sta);
  418. #endif /* CONFIG_P2P */
  419. }
  420. void wpas_notify_sta_authorized(struct wpa_supplicant *wpa_s,
  421. const u8 *mac_addr, int authorized)
  422. {
  423. if (authorized)
  424. wpas_notify_ap_sta_authorized(wpa_s, mac_addr);
  425. else
  426. wpas_notify_ap_sta_deauthorized(wpa_s, mac_addr);
  427. }
  428. void wpas_notify_certification(struct wpa_supplicant *wpa_s, int depth,
  429. const char *subject, const char *cert_hash,
  430. const struct wpabuf *cert)
  431. {
  432. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_EAP_PEER_CERT
  433. "depth=%d subject='%s'%s%s",
  434. depth, subject,
  435. cert_hash ? " hash=" : "",
  436. cert_hash ? cert_hash : "");
  437. if (cert) {
  438. char *cert_hex;
  439. size_t len = wpabuf_len(cert) * 2 + 1;
  440. cert_hex = os_malloc(len);
  441. if (cert_hex) {
  442. wpa_snprintf_hex(cert_hex, len, wpabuf_head(cert),
  443. wpabuf_len(cert));
  444. wpa_msg_ctrl(wpa_s, MSG_INFO,
  445. WPA_EVENT_EAP_PEER_CERT
  446. "depth=%d subject='%s' cert=%s",
  447. depth, subject, cert_hex);
  448. os_free(cert_hex);
  449. }
  450. }
  451. /* notify the old DBus API */
  452. wpa_supplicant_dbus_notify_certification(wpa_s, depth, subject,
  453. cert_hash, cert);
  454. /* notify the new DBus API */
  455. wpas_dbus_signal_certification(wpa_s, depth, subject, cert_hash, cert);
  456. }