notify.c 14 KB

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