notify.c 14 KB

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