notify.c 15 KB

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