summaryrefslogtreecommitdiffstats
path: root/contrib/wpa
diff options
context:
space:
mode:
authorrpaulo <rpaulo@FreeBSD.org>2010-11-03 10:43:38 +0000
committerrpaulo <rpaulo@FreeBSD.org>2010-11-03 10:43:38 +0000
commite0d70c33109c041ff2046fe529eb8e3c0f2acec1 (patch)
treebf6082c2ad69b06fcb45c37be7157b66ffbd4fc7 /contrib/wpa
parent6ddde2168bc79a10ab0937ba69afe0a74559eea0 (diff)
parent14ab4e9475c66439a7a011706ada056765de1555 (diff)
downloadFreeBSD-src-e0d70c33109c041ff2046fe529eb8e3c0f2acec1.zip
FreeBSD-src-e0d70c33109c041ff2046fe529eb8e3c0f2acec1.tar.gz
Merge wpa_supplicant and hostapd 0.7.3.
Diffstat (limited to 'contrib/wpa')
-rw-r--r--contrib/wpa/hostapd/.gitignore7
-rw-r--r--contrib/wpa/hostapd/ChangeLog118
-rw-r--r--contrib/wpa/hostapd/Makefile682
-rw-r--r--contrib/wpa/hostapd/README5
-rw-r--r--contrib/wpa/hostapd/README-WPS28
-rw-r--r--contrib/wpa/hostapd/config_file.c (renamed from contrib/wpa/hostapd/config.c)867
-rw-r--r--contrib/wpa/hostapd/config_file.h20
-rw-r--r--contrib/wpa/hostapd/ctrl_iface.c286
-rw-r--r--contrib/wpa/hostapd/ctrl_iface.h11
-rw-r--r--contrib/wpa/hostapd/defconfig37
-rw-r--r--contrib/wpa/hostapd/doc/code_structure.doxygen5
-rw-r--r--contrib/wpa/hostapd/doc/ctrl_iface.doxygen66
-rw-r--r--contrib/wpa/hostapd/doc/doxygen.fast238
-rw-r--r--contrib/wpa/hostapd/doc/doxygen.full238
-rw-r--r--contrib/wpa/hostapd/doc/driver_wrapper.doxygen20
-rw-r--r--contrib/wpa/hostapd/doc/eap.doxygen56
-rw-r--r--contrib/wpa/hostapd/doc/hostapd.fig264
-rwxr-xr-xcontrib/wpa/hostapd/doc/kerneldoc2doxygen.pl129
-rw-r--r--contrib/wpa/hostapd/doc/mainpage.doxygen52
-rw-r--r--contrib/wpa/hostapd/doc/porting.doxygen5
-rw-r--r--contrib/wpa/hostapd/driver.h798
-rw-r--r--contrib/wpa/hostapd/driver_bsd.c839
-rw-r--r--contrib/wpa/hostapd/driver_hostap.c1279
-rw-r--r--contrib/wpa/hostapd/driver_wired.c372
-rw-r--r--contrib/wpa/hostapd/drivers.c77
-rw-r--r--contrib/wpa/hostapd/dump_state.c184
-rw-r--r--contrib/wpa/hostapd/dump_state.h20
-rw-r--r--contrib/wpa/hostapd/eap_register.c134
-rw-r--r--contrib/wpa/hostapd/eap_register.h (renamed from contrib/wpa/src/crypto/rc4.h)13
-rw-r--r--contrib/wpa/hostapd/hlr_auc_gw.c (renamed from contrib/wpa/src/hlr_auc_gw/hlr_auc_gw.c)2
-rw-r--r--contrib/wpa/hostapd/hlr_auc_gw.milenage_db (renamed from contrib/wpa/src/hlr_auc_gw/hlr_auc_gw.milenage_db)0
-rw-r--r--contrib/wpa/hostapd/hostap_common.h216
-rw-r--r--contrib/wpa/hostapd/hostapd.82
-rw-r--r--contrib/wpa/hostapd/hostapd.c2043
-rw-r--r--contrib/wpa/hostapd/hostapd.conf99
-rw-r--r--contrib/wpa/hostapd/hostapd.h238
-rw-r--r--contrib/wpa/hostapd/hostapd_cli.18
-rw-r--r--contrib/wpa/hostapd/hostapd_cli.c285
-rw-r--r--contrib/wpa/hostapd/main.c565
-rw-r--r--contrib/wpa/hostapd/nt_password_hash.c5
-rw-r--r--contrib/wpa/hostapd/sta_info.h43
-rw-r--r--contrib/wpa/hostapd/wme.h135
-rw-r--r--contrib/wpa/patches/openssl-0.9.8-tls-extensions.patch429
-rw-r--r--contrib/wpa/patches/openssl-0.9.8d-tls-extensions.patch429
-rw-r--r--contrib/wpa/patches/openssl-0.9.8e-tls-extensions.patch353
-rw-r--r--contrib/wpa/patches/openssl-0.9.8g-tls-extensions.patch330
-rw-r--r--contrib/wpa/patches/openssl-0.9.8h-tls-extensions.patch344
-rw-r--r--contrib/wpa/patches/openssl-0.9.8i-tls-extensions.patch404
-rw-r--r--contrib/wpa/patches/openssl-0.9.9-session-ticket.patch374
-rw-r--r--contrib/wpa/src/Makefile4
-rw-r--r--contrib/wpa/src/ap/Makefile (renamed from contrib/wpa/src/hlr_auc_gw/Makefile)1
-rw-r--r--contrib/wpa/src/ap/accounting.c (renamed from contrib/wpa/hostapd/accounting.c)35
-rw-r--r--contrib/wpa/src/ap/accounting.h (renamed from contrib/wpa/hostapd/accounting.h)25
-rw-r--r--contrib/wpa/src/ap/ap_config.c605
-rw-r--r--contrib/wpa/src/ap/ap_config.h (renamed from contrib/wpa/hostapd/config.h)55
-rw-r--r--contrib/wpa/src/ap/ap_drv_ops.c621
-rw-r--r--contrib/wpa/src/ap/ap_drv_ops.h67
-rw-r--r--contrib/wpa/src/ap/ap_list.c (renamed from contrib/wpa/hostapd/ap_list.c)136
-rw-r--r--contrib/wpa/src/ap/ap_list.h (renamed from contrib/wpa/hostapd/ap_list.h)19
-rw-r--r--contrib/wpa/src/ap/ap_mlme.c (renamed from contrib/wpa/hostapd/mlme.c)12
-rw-r--r--contrib/wpa/src/ap/ap_mlme.h (renamed from contrib/wpa/hostapd/mlme.h)0
-rw-r--r--contrib/wpa/src/ap/authsrv.c216
-rw-r--r--contrib/wpa/src/ap/authsrv.h21
-rw-r--r--contrib/wpa/src/ap/beacon.c (renamed from contrib/wpa/hostapd/beacon.c)131
-rw-r--r--contrib/wpa/src/ap/beacon.h (renamed from contrib/wpa/hostapd/beacon.h)16
-rw-r--r--contrib/wpa/src/ap/ctrl_iface_ap.c104
-rw-r--r--contrib/wpa/src/ap/ctrl_iface_ap.h25
-rw-r--r--contrib/wpa/src/ap/drv_callbacks.c457
-rw-r--r--contrib/wpa/src/ap/hostapd.c887
-rw-r--r--contrib/wpa/src/ap/hostapd.h276
-rw-r--r--contrib/wpa/src/ap/hw_features.c (renamed from contrib/wpa/hostapd/hw_features.c)309
-rw-r--r--contrib/wpa/src/ap/hw_features.h (renamed from contrib/wpa/hostapd/hw_features.h)70
-rw-r--r--contrib/wpa/src/ap/iapp.c (renamed from contrib/wpa/hostapd/iapp.c)32
-rw-r--r--contrib/wpa/src/ap/iapp.h (renamed from contrib/wpa/hostapd/iapp.h)9
-rw-r--r--contrib/wpa/src/ap/ieee802_11.c (renamed from contrib/wpa/hostapd/ieee802_11.c)1126
-rw-r--r--contrib/wpa/src/ap/ieee802_11.h (renamed from contrib/wpa/hostapd/ieee802_11.h)53
-rw-r--r--contrib/wpa/src/ap/ieee802_11_auth.c (renamed from contrib/wpa/hostapd/ieee802_11_auth.c)65
-rw-r--r--contrib/wpa/src/ap/ieee802_11_auth.h (renamed from contrib/wpa/hostapd/ieee802_11_auth.h)2
-rw-r--r--contrib/wpa/src/ap/ieee802_11_ht.c270
-rw-r--r--contrib/wpa/src/ap/ieee802_1x.c (renamed from contrib/wpa/hostapd/ieee802_1x.c)423
-rw-r--r--contrib/wpa/src/ap/ieee802_1x.h (renamed from contrib/wpa/hostapd/ieee802_1x.h)21
-rw-r--r--contrib/wpa/src/ap/peerkey_auth.c (renamed from contrib/wpa/hostapd/peerkey.c)15
-rw-r--r--contrib/wpa/src/ap/pmksa_cache_auth.c (renamed from contrib/wpa/hostapd/pmksa_cache.c)110
-rw-r--r--contrib/wpa/src/ap/pmksa_cache_auth.h (renamed from contrib/wpa/hostapd/pmksa_cache.h)22
-rw-r--r--contrib/wpa/src/ap/preauth_auth.c (renamed from contrib/wpa/hostapd/preauth.c)19
-rw-r--r--contrib/wpa/src/ap/preauth_auth.h (renamed from contrib/wpa/hostapd/preauth.h)0
-rw-r--r--contrib/wpa/src/ap/sta_info.c (renamed from contrib/wpa/hostapd/sta_info.c)120
-rw-r--r--contrib/wpa/src/ap/sta_info.h (renamed from contrib/wpa/hostapd/ap.h)60
-rw-r--r--contrib/wpa/src/ap/tkip_countermeasures.c93
-rw-r--r--contrib/wpa/src/ap/tkip_countermeasures.h20
-rw-r--r--contrib/wpa/src/ap/utils.c88
-rw-r--r--contrib/wpa/src/ap/vlan_init.c (renamed from contrib/wpa/hostapd/vlan_init.c)231
-rw-r--r--contrib/wpa/src/ap/vlan_init.h (renamed from contrib/wpa/hostapd/vlan_init.h)32
-rw-r--r--contrib/wpa/src/ap/wmm.c (renamed from contrib/wpa/hostapd/wme.c)101
-rw-r--r--contrib/wpa/src/ap/wmm.h29
-rw-r--r--contrib/wpa/src/ap/wpa_auth.c (renamed from contrib/wpa/hostapd/wpa.c)311
-rw-r--r--contrib/wpa/src/ap/wpa_auth.h (renamed from contrib/wpa/hostapd/wpa.h)39
-rw-r--r--contrib/wpa/src/ap/wpa_auth_ft.c (renamed from contrib/wpa/hostapd/wpa_ft.c)474
-rw-r--r--contrib/wpa/src/ap/wpa_auth_glue.c545
-rw-r--r--contrib/wpa/src/ap/wpa_auth_glue.h22
-rw-r--r--contrib/wpa/src/ap/wpa_auth_i.h (renamed from contrib/wpa/hostapd/wpa_auth_i.h)9
-rw-r--r--contrib/wpa/src/ap/wpa_auth_ie.c (renamed from contrib/wpa/hostapd/wpa_auth_ie.c)30
-rw-r--r--contrib/wpa/src/ap/wpa_auth_ie.h (renamed from contrib/wpa/hostapd/wpa_auth_ie.h)2
-rw-r--r--contrib/wpa/src/ap/wps_hostapd.c (renamed from contrib/wpa/hostapd/wps_hostapd.c)599
-rw-r--r--contrib/wpa/src/ap/wps_hostapd.h (renamed from contrib/wpa/hostapd/wps_hostapd.h)31
-rw-r--r--contrib/wpa/src/common/Makefile1
-rw-r--r--contrib/wpa/src/common/defs.h80
-rw-r--r--contrib/wpa/src/common/ieee802_11_common.c75
-rw-r--r--contrib/wpa/src/common/ieee802_11_common.h54
-rw-r--r--contrib/wpa/src/common/ieee802_11_defs.h270
-rw-r--r--contrib/wpa/src/common/privsep_commands.h3
-rw-r--r--contrib/wpa/src/common/version.h2
-rw-r--r--contrib/wpa/src/common/wpa_common.c233
-rw-r--r--contrib/wpa/src/common/wpa_common.h16
-rw-r--r--contrib/wpa/src/common/wpa_ctrl.h23
-rw-r--r--contrib/wpa/src/crypto/.gitignore1
-rw-r--r--contrib/wpa/src/crypto/Makefile55
-rw-r--r--contrib/wpa/src/crypto/aes-cbc.c86
-rw-r--r--contrib/wpa/src/crypto/aes-ctr.c61
-rw-r--r--contrib/wpa/src/crypto/aes-eax.c151
-rw-r--r--contrib/wpa/src/crypto/aes-encblock.c38
-rw-r--r--contrib/wpa/src/crypto/aes-internal-dec.c151
-rw-r--r--contrib/wpa/src/crypto/aes-internal-enc.c121
-rw-r--r--contrib/wpa/src/crypto/aes-internal.c (renamed from contrib/wpa/src/crypto/aes.c)350
-rw-r--r--contrib/wpa/src/crypto/aes-omac1.c124
-rw-r--r--contrib/wpa/src/crypto/aes-unwrap.c79
-rw-r--r--contrib/wpa/src/crypto/aes-wrap.c76
-rw-r--r--contrib/wpa/src/crypto/aes.h2
-rw-r--r--contrib/wpa/src/crypto/aes_i.h122
-rw-r--r--contrib/wpa/src/crypto/aes_wrap.c533
-rw-r--r--contrib/wpa/src/crypto/crypto.h54
-rw-r--r--contrib/wpa/src/crypto/crypto_cryptoapi.c29
-rw-r--r--contrib/wpa/src/crypto/crypto_gnutls.c24
-rw-r--r--contrib/wpa/src/crypto/crypto_internal-cipher.c256
-rw-r--r--contrib/wpa/src/crypto/crypto_internal-modexp.c55
-rw-r--r--contrib/wpa/src/crypto/crypto_internal-rsa.c115
-rw-r--r--contrib/wpa/src/crypto/crypto_internal.c639
-rw-r--r--contrib/wpa/src/crypto/crypto_libtomcrypt.c24
-rw-r--r--contrib/wpa/src/crypto/crypto_none.c3
-rw-r--r--contrib/wpa/src/crypto/crypto_nss.c213
-rw-r--r--contrib/wpa/src/crypto/crypto_openssl.c313
-rw-r--r--contrib/wpa/src/crypto/des-internal.c (renamed from contrib/wpa/src/crypto/des.c)40
-rw-r--r--contrib/wpa/src/crypto/des_i.h31
-rw-r--r--contrib/wpa/src/crypto/dh_group5.c40
-rw-r--r--contrib/wpa/src/crypto/dh_group5.h23
-rw-r--r--contrib/wpa/src/crypto/dh_groups.c3
-rw-r--r--contrib/wpa/src/crypto/fips_prf_cryptoapi.c25
-rw-r--r--contrib/wpa/src/crypto/fips_prf_gnutls.c26
-rw-r--r--contrib/wpa/src/crypto/fips_prf_internal.c74
-rw-r--r--contrib/wpa/src/crypto/fips_prf_nss.c25
-rw-r--r--contrib/wpa/src/crypto/fips_prf_openssl.c83
-rw-r--r--contrib/wpa/src/crypto/md4-internal.c (renamed from contrib/wpa/src/crypto/md4.c)8
-rw-r--r--contrib/wpa/src/crypto/md5-internal.c293
-rw-r--r--contrib/wpa/src/crypto/md5-non-fips.c113
-rw-r--r--contrib/wpa/src/crypto/md5.c307
-rw-r--r--contrib/wpa/src/crypto/md5.h29
-rw-r--r--contrib/wpa/src/crypto/md5_i.h29
-rw-r--r--contrib/wpa/src/crypto/milenage.c329
-rw-r--r--contrib/wpa/src/crypto/milenage.h (renamed from contrib/wpa/src/hlr_auc_gw/milenage.h)4
-rw-r--r--contrib/wpa/src/crypto/ms_funcs.c130
-rw-r--r--contrib/wpa/src/crypto/ms_funcs.h54
-rw-r--r--contrib/wpa/src/crypto/rc4.c20
-rw-r--r--contrib/wpa/src/crypto/sha1-internal.c308
-rw-r--r--contrib/wpa/src/crypto/sha1-pbkdf2.c100
-rw-r--r--contrib/wpa/src/crypto/sha1-tlsprf.c109
-rw-r--r--contrib/wpa/src/crypto/sha1-tprf.c76
-rw-r--r--contrib/wpa/src/crypto/sha1.c612
-rw-r--r--contrib/wpa/src/crypto/sha1.h29
-rw-r--r--contrib/wpa/src/crypto/sha1_i.h29
-rw-r--r--contrib/wpa/src/crypto/sha256-internal.c243
-rw-r--r--contrib/wpa/src/crypto/sha256.c225
-rw-r--r--contrib/wpa/src/crypto/tls.h127
-rw-r--r--contrib/wpa/src/crypto/tls_gnutls.c235
-rw-r--r--contrib/wpa/src/crypto/tls_internal.c170
-rw-r--r--contrib/wpa/src/crypto/tls_none.c49
-rw-r--r--contrib/wpa/src/crypto/tls_nss.c680
-rw-r--r--contrib/wpa/src/crypto/tls_openssl.c548
-rw-r--r--contrib/wpa/src/crypto/tls_schannel.c162
-rw-r--r--contrib/wpa/src/drivers/.gitignore2
-rw-r--r--contrib/wpa/src/drivers/Makefile2
-rw-r--r--contrib/wpa/src/drivers/driver.h1718
-rw-r--r--contrib/wpa/src/drivers/driver_atheros.c1298
-rw-r--r--contrib/wpa/src/drivers/driver_ndis.c181
-rw-r--r--contrib/wpa/src/drivers/driver_ndis.h1
-rw-r--r--contrib/wpa/src/drivers/driver_ndiswrapper.c42
-rw-r--r--contrib/wpa/src/drivers/driver_none.c99
-rw-r--r--contrib/wpa/src/drivers/driver_wired.c420
-rw-r--r--contrib/wpa/src/drivers/drivers.c28
-rw-r--r--contrib/wpa/src/drivers/drivers.mak181
-rw-r--r--contrib/wpa/src/drivers/linux_ioctl.c198
-rw-r--r--contrib/wpa/src/drivers/linux_ioctl.h27
-rw-r--r--contrib/wpa/src/drivers/netlink.c204
-rw-r--r--contrib/wpa/src/drivers/netlink.h33
-rw-r--r--contrib/wpa/src/drivers/nl80211_copy.h (renamed from contrib/wpa/src/common/nl80211_copy.h)214
-rw-r--r--contrib/wpa/src/drivers/radiotap.c287
-rw-r--r--contrib/wpa/src/drivers/radiotap.h242
-rw-r--r--contrib/wpa/src/drivers/radiotap_iter.h41
-rw-r--r--contrib/wpa/src/drivers/scan_helpers.c182
-rw-r--r--contrib/wpa/src/drivers/wireless_copy.h (renamed from contrib/wpa/src/common/wireless_copy.h)0
-rw-r--r--contrib/wpa/src/eap_common/Makefile1
-rw-r--r--contrib/wpa/src/eap_common/chap.c9
-rw-r--r--contrib/wpa/src/eap_common/chap.h6
-rw-r--r--contrib/wpa/src/eap_common/eap_fast_common.c4
-rw-r--r--contrib/wpa/src/eap_common/eap_gpsk_common.c7
-rw-r--r--contrib/wpa/src/eap_common/eap_pax_common.c2
-rw-r--r--contrib/wpa/src/eap_common/eap_peap_common.c2
-rw-r--r--contrib/wpa/src/eap_common/eap_psk_common.c2
-rw-r--r--contrib/wpa/src/eap_common/eap_sake_common.c2
-rw-r--r--contrib/wpa/src/eap_common/eap_sim_common.c22
-rw-r--r--contrib/wpa/src/eap_common/eap_sim_common.h6
-rw-r--r--contrib/wpa/src/eap_common/ikev2_common.c6
-rw-r--r--contrib/wpa/src/eap_peer/Makefile1
-rw-r--r--contrib/wpa/src/eap_peer/eap.c77
-rw-r--r--contrib/wpa/src/eap_peer/eap.h2
-rw-r--r--contrib/wpa/src/eap_peer/eap_aka.c14
-rw-r--r--contrib/wpa/src/eap_peer/eap_config.h9
-rw-r--r--contrib/wpa/src/eap_peer/eap_fast.c12
-rw-r--r--contrib/wpa/src/eap_peer/eap_fast_pac.c29
-rw-r--r--contrib/wpa/src/eap_peer/eap_leap.c32
-rw-r--r--contrib/wpa/src/eap_peer/eap_md5.c2
-rw-r--r--contrib/wpa/src/eap_peer/eap_methods.c155
-rw-r--r--contrib/wpa/src/eap_peer/eap_methods.h23
-rw-r--r--contrib/wpa/src/eap_peer/eap_mschapv2.c19
-rw-r--r--contrib/wpa/src/eap_peer/eap_pax.c4
-rw-r--r--contrib/wpa/src/eap_peer/eap_peap.c12
-rw-r--r--contrib/wpa/src/eap_peer/eap_psk.c4
-rw-r--r--contrib/wpa/src/eap_peer/eap_sim.c6
-rw-r--r--contrib/wpa/src/eap_peer/eap_tls.c2
-rw-r--r--contrib/wpa/src/eap_peer/eap_tls_common.c164
-rw-r--r--contrib/wpa/src/eap_peer/eap_tls_common.h23
-rw-r--r--contrib/wpa/src/eap_peer/eap_tnc.c5
-rw-r--r--contrib/wpa/src/eap_peer/eap_ttls.c63
-rw-r--r--contrib/wpa/src/eap_peer/eap_wsc.c94
-rw-r--r--contrib/wpa/src/eap_peer/ikev2.c2
-rw-r--r--contrib/wpa/src/eap_peer/mschapv2.c26
-rw-r--r--contrib/wpa/src/eap_peer/mschapv2.h14
-rw-r--r--contrib/wpa/src/eap_server/Makefile1
-rw-r--r--contrib/wpa/src/eap_server/eap.h4
-rw-r--r--contrib/wpa/src/eap_server/eap_i.h2
-rw-r--r--contrib/wpa/src/eap_server/eap_methods.h36
-rw-r--r--contrib/wpa/src/eap_server/eap_server.c (renamed from contrib/wpa/src/eap_server/eap.c)19
-rw-r--r--contrib/wpa/src/eap_server/eap_server_aka.c (renamed from contrib/wpa/src/eap_server/eap_aka.c)35
-rw-r--r--contrib/wpa/src/eap_server/eap_server_fast.c (renamed from contrib/wpa/src/eap_server/eap_fast.c)106
-rw-r--r--contrib/wpa/src/eap_server/eap_server_gpsk.c (renamed from contrib/wpa/src/eap_server/eap_gpsk.c)0
-rw-r--r--contrib/wpa/src/eap_server/eap_server_gtc.c (renamed from contrib/wpa/src/eap_server/eap_gtc.c)8
-rw-r--r--contrib/wpa/src/eap_server/eap_server_identity.c (renamed from contrib/wpa/src/eap_server/eap_identity.c)0
-rw-r--r--contrib/wpa/src/eap_server/eap_server_ikev2.c (renamed from contrib/wpa/src/eap_server/eap_ikev2.c)0
-rw-r--r--contrib/wpa/src/eap_server/eap_server_md5.c (renamed from contrib/wpa/src/eap_server/eap_md5.c)0
-rw-r--r--contrib/wpa/src/eap_server/eap_server_methods.c (renamed from contrib/wpa/src/eap_server/eap_methods.c)177
-rw-r--r--contrib/wpa/src/eap_server/eap_server_mschapv2.c (renamed from contrib/wpa/src/eap_server/eap_mschapv2.c)28
-rw-r--r--contrib/wpa/src/eap_server/eap_server_pax.c (renamed from contrib/wpa/src/eap_server/eap_pax.c)0
-rw-r--r--contrib/wpa/src/eap_server/eap_server_peap.c (renamed from contrib/wpa/src/eap_server/eap_peap.c)149
-rw-r--r--contrib/wpa/src/eap_server/eap_server_psk.c (renamed from contrib/wpa/src/eap_server/eap_psk.c)4
-rw-r--r--contrib/wpa/src/eap_server/eap_server_sake.c (renamed from contrib/wpa/src/eap_server/eap_sake.c)0
-rw-r--r--contrib/wpa/src/eap_server/eap_server_sim.c (renamed from contrib/wpa/src/eap_server/eap_sim.c)0
-rw-r--r--contrib/wpa/src/eap_server/eap_server_tls.c (renamed from contrib/wpa/src/eap_server/eap_tls.c)4
-rw-r--r--contrib/wpa/src/eap_server/eap_server_tls_common.c (renamed from contrib/wpa/src/eap_server/eap_tls_common.c)125
-rw-r--r--contrib/wpa/src/eap_server/eap_server_tnc.c (renamed from contrib/wpa/src/eap_server/eap_tnc.c)99
-rw-r--r--contrib/wpa/src/eap_server/eap_server_ttls.c (renamed from contrib/wpa/src/eap_server/eap_ttls.c)133
-rw-r--r--contrib/wpa/src/eap_server/eap_server_vendor_test.c (renamed from contrib/wpa/src/eap_server/eap_vendor_test.c)0
-rw-r--r--contrib/wpa/src/eap_server/eap_server_wsc.c (renamed from contrib/wpa/src/eap_server/eap_wsc.c)41
-rw-r--r--contrib/wpa/src/eap_server/eap_sim_db.c4
-rw-r--r--contrib/wpa/src/eap_server/eap_sim_db.h16
-rw-r--r--contrib/wpa/src/eap_server/eap_tls_common.h39
-rw-r--r--contrib/wpa/src/eap_server/ikev2.c2
-rw-r--r--contrib/wpa/src/eap_server/tncs.c1
-rw-r--r--contrib/wpa/src/eapol_auth/Makefile8
-rw-r--r--contrib/wpa/src/eapol_auth/eapol_auth_dump.c231
-rw-r--r--contrib/wpa/src/eapol_auth/eapol_auth_sm.c (renamed from contrib/wpa/hostapd/eapol_sm.c)315
-rw-r--r--contrib/wpa/src/eapol_auth/eapol_auth_sm.h89
-rw-r--r--contrib/wpa/src/eapol_auth/eapol_auth_sm_i.h (renamed from contrib/wpa/hostapd/eapol_sm.h)99
-rw-r--r--contrib/wpa/src/eapol_supp/Makefile1
-rw-r--r--contrib/wpa/src/eapol_supp/eapol_supp_sm.c38
-rw-r--r--contrib/wpa/src/eapol_supp/eapol_supp_sm.h11
-rw-r--r--contrib/wpa/src/hlr_auc_gw/milenage.c1142
-rw-r--r--contrib/wpa/src/l2_packet/Makefile1
-rw-r--r--contrib/wpa/src/l2_packet/l2_packet_freebsd.c2
-rw-r--r--contrib/wpa/src/l2_packet/l2_packet_ndis.c16
-rw-r--r--contrib/wpa/src/lib.rules21
-rw-r--r--contrib/wpa/src/radius/.gitignore1
-rw-r--r--contrib/wpa/src/radius/Makefile21
-rw-r--r--contrib/wpa/src/radius/radius.c293
-rw-r--r--contrib/wpa/src/radius/radius.h47
-rw-r--r--contrib/wpa/src/radius/radius_client.c354
-rw-r--r--contrib/wpa/src/radius/radius_client.h227
-rw-r--r--contrib/wpa/src/radius/radius_server.c299
-rw-r--r--contrib/wpa/src/radius/radius_server.h186
-rw-r--r--contrib/wpa/src/rsn_supp/Makefile1
-rw-r--r--contrib/wpa/src/rsn_supp/peerkey.c18
-rw-r--r--contrib/wpa/src/rsn_supp/pmksa_cache.c47
-rw-r--r--contrib/wpa/src/rsn_supp/pmksa_cache.h5
-rw-r--r--contrib/wpa/src/rsn_supp/preauth.c175
-rw-r--r--contrib/wpa/src/rsn_supp/preauth.h17
-rw-r--r--contrib/wpa/src/rsn_supp/wpa.c362
-rw-r--r--contrib/wpa/src/rsn_supp/wpa.h61
-rw-r--r--contrib/wpa/src/rsn_supp/wpa_ft.c344
-rw-r--r--contrib/wpa/src/rsn_supp/wpa_i.h28
-rw-r--r--contrib/wpa/src/rsn_supp/wpa_ie.c49
-rw-r--r--contrib/wpa/src/rsn_supp/wpa_ie.h4
-rw-r--r--contrib/wpa/src/tls/.gitignore1
-rw-r--r--contrib/wpa/src/tls/Makefile36
-rw-r--r--contrib/wpa/src/tls/asn1.c43
-rw-r--r--contrib/wpa/src/tls/asn1.h1
-rw-r--r--contrib/wpa/src/tls/asn1_test.c210
-rw-r--r--contrib/wpa/src/tls/pkcs1.c201
-rw-r--r--contrib/wpa/src/tls/pkcs1.h28
-rw-r--r--contrib/wpa/src/tls/pkcs5.c238
-rw-r--r--contrib/wpa/src/tls/pkcs5.h22
-rw-r--r--contrib/wpa/src/tls/pkcs8.c193
-rw-r--r--contrib/wpa/src/tls/pkcs8.h22
-rw-r--r--contrib/wpa/src/tls/rsa.c3
-rw-r--r--contrib/wpa/src/tls/tlsv1_client.c8
-rw-r--r--contrib/wpa/src/tls/tlsv1_client_read.c6
-rw-r--r--contrib/wpa/src/tls/tlsv1_client_write.c11
-rw-r--r--contrib/wpa/src/tls/tlsv1_common.h2
-rw-r--r--contrib/wpa/src/tls/tlsv1_cred.c83
-rw-r--r--contrib/wpa/src/tls/tlsv1_record.c4
-rw-r--r--contrib/wpa/src/tls/tlsv1_record.h2
-rw-r--r--contrib/wpa/src/tls/tlsv1_server.c8
-rw-r--r--contrib/wpa/src/tls/tlsv1_server_read.c10
-rw-r--r--contrib/wpa/src/tls/tlsv1_server_write.c12
-rw-r--r--contrib/wpa/src/tls/x509v3.c435
-rw-r--r--contrib/wpa/src/tls/x509v3.h81
-rw-r--r--contrib/wpa/src/utils/.gitignore1
-rw-r--r--contrib/wpa/src/utils/Makefile35
-rw-r--r--contrib/wpa/src/utils/base64.c35
-rw-r--r--contrib/wpa/src/utils/build_config.h44
-rw-r--r--contrib/wpa/src/utils/common.c32
-rw-r--r--contrib/wpa/src/utils/common.h21
-rw-r--r--contrib/wpa/src/utils/eloop.c242
-rw-r--r--contrib/wpa/src/utils/eloop.h30
-rw-r--r--contrib/wpa/src/utils/eloop_none.c11
-rw-r--r--contrib/wpa/src/utils/eloop_win.c13
-rw-r--r--contrib/wpa/src/utils/ip_addr.h3
-rw-r--r--contrib/wpa/src/utils/list.h89
-rw-r--r--contrib/wpa/src/utils/os.h25
-rw-r--r--contrib/wpa/src/utils/os_internal.c7
-rw-r--r--contrib/wpa/src/utils/os_unix.c164
-rw-r--r--contrib/wpa/src/utils/radiotap.c (renamed from contrib/wpa/hostapd/radiotap.c)0
-rw-r--r--contrib/wpa/src/utils/radiotap.h (renamed from contrib/wpa/hostapd/radiotap.h)2
-rw-r--r--contrib/wpa/src/utils/radiotap_iter.h (renamed from contrib/wpa/hostapd/radiotap_iter.h)0
-rw-r--r--contrib/wpa/src/utils/trace.c329
-rw-r--r--contrib/wpa/src/utils/trace.h74
-rw-r--r--contrib/wpa/src/utils/uuid.c30
-rw-r--r--contrib/wpa/src/utils/uuid.h1
-rw-r--r--contrib/wpa/src/utils/wpa_debug.c15
-rw-r--r--contrib/wpa/src/utils/wpa_debug.h17
-rw-r--r--contrib/wpa/src/utils/wpabuf.c88
-rw-r--r--contrib/wpa/src/utils/wpabuf.h6
-rw-r--r--contrib/wpa/src/wps/Makefile1
-rw-r--r--contrib/wpa/src/wps/http.h29
-rw-r--r--contrib/wpa/src/wps/http_client.c371
-rw-r--r--contrib/wpa/src/wps/http_client.h46
-rw-r--r--contrib/wpa/src/wps/http_server.c312
-rw-r--r--contrib/wpa/src/wps/http_server.h39
-rw-r--r--contrib/wpa/src/wps/httpread.c2
-rw-r--r--contrib/wpa/src/wps/httpread.h2
-rw-r--r--contrib/wpa/src/wps/ndef.c175
-rw-r--r--contrib/wpa/src/wps/upnp_xml.c252
-rw-r--r--contrib/wpa/src/wps/upnp_xml.h23
-rw-r--r--contrib/wpa/src/wps/wps.c170
-rw-r--r--contrib/wpa/src/wps/wps.h233
-rw-r--r--contrib/wpa/src/wps/wps_attr_build.c80
-rw-r--r--contrib/wpa/src/wps/wps_attr_parse.c33
-rw-r--r--contrib/wpa/src/wps/wps_attr_process.c9
-rw-r--r--contrib/wpa/src/wps/wps_common.c344
-rw-r--r--contrib/wpa/src/wps/wps_defs.h12
-rw-r--r--contrib/wpa/src/wps/wps_dev_attr.c28
-rw-r--r--contrib/wpa/src/wps/wps_enrollee.c51
-rw-r--r--contrib/wpa/src/wps/wps_er.c1663
-rw-r--r--contrib/wpa/src/wps/wps_er.h106
-rw-r--r--contrib/wpa/src/wps/wps_er_ssdp.c198
-rw-r--r--contrib/wpa/src/wps/wps_i.h34
-rw-r--r--contrib/wpa/src/wps/wps_nfc.c117
-rw-r--r--contrib/wpa/src/wps/wps_nfc_pn531.c113
-rw-r--r--contrib/wpa/src/wps/wps_registrar.c612
-rw-r--r--contrib/wpa/src/wps/wps_ufd.c235
-rw-r--r--contrib/wpa/src/wps/wps_upnp.c230
-rw-r--r--contrib/wpa/src/wps/wps_upnp.h22
-rw-r--r--contrib/wpa/src/wps/wps_upnp_ap.c80
-rw-r--r--contrib/wpa/src/wps/wps_upnp_event.c347
-rw-r--r--contrib/wpa/src/wps/wps_upnp_i.h76
-rw-r--r--contrib/wpa/src/wps/wps_upnp_ssdp.c125
-rw-r--r--contrib/wpa/src/wps/wps_upnp_web.c1046
-rw-r--r--contrib/wpa/wpa_supplicant/.gitignore8
-rw-r--r--contrib/wpa/wpa_supplicant/ChangeLog162
-rw-r--r--contrib/wpa/wpa_supplicant/Makefile956
-rw-r--r--contrib/wpa/wpa_supplicant/README11
-rw-r--r--contrib/wpa/wpa_supplicant/README-WPS25
-rw-r--r--contrib/wpa/wpa_supplicant/ap.c481
-rw-r--r--contrib/wpa/wpa_supplicant/ap.h43
-rw-r--r--contrib/wpa/wpa_supplicant/bgscan.c110
-rw-r--r--contrib/wpa/wpa_supplicant/bgscan.h69
-rw-r--r--contrib/wpa/wpa_supplicant/bgscan_simple.c230
-rw-r--r--contrib/wpa/wpa_supplicant/bss.c606
-rw-r--r--contrib/wpa/wpa_supplicant/bss.h93
-rw-r--r--contrib/wpa/wpa_supplicant/config.c203
-rw-r--r--contrib/wpa/wpa_supplicant/config.h28
-rw-r--r--contrib/wpa/wpa_supplicant/config_file.c15
-rw-r--r--contrib/wpa/wpa_supplicant/config_ssid.h45
-rw-r--r--contrib/wpa/wpa_supplicant/ctrl_iface.c581
-rw-r--r--contrib/wpa/wpa_supplicant/ctrl_iface_named_pipe.c2
-rw-r--r--contrib/wpa/wpa_supplicant/ctrl_iface_udp.c2
-rw-r--r--contrib/wpa/wpa_supplicant/ctrl_iface_unix.c60
-rw-r--r--contrib/wpa/wpa_supplicant/dbus/.gitignore1
-rw-r--r--contrib/wpa/wpa_supplicant/dbus/Makefile84
-rw-r--r--contrib/wpa/wpa_supplicant/dbus/dbus-wpa_supplicant.conf (renamed from contrib/wpa/wpa_supplicant/dbus-wpa_supplicant.conf)11
-rw-r--r--contrib/wpa/wpa_supplicant/dbus/dbus_common.c371
-rw-r--r--contrib/wpa/wpa_supplicant/dbus/dbus_common.h26
-rw-r--r--contrib/wpa/wpa_supplicant/dbus/dbus_common_i.h30
-rw-r--r--contrib/wpa/wpa_supplicant/dbus/dbus_dict_helpers.c (renamed from contrib/wpa/wpa_supplicant/dbus_dict_helpers.c)199
-rw-r--r--contrib/wpa/wpa_supplicant/dbus/dbus_dict_helpers.h (renamed from contrib/wpa/wpa_supplicant/dbus_dict_helpers.h)2
-rw-r--r--contrib/wpa/wpa_supplicant/dbus/dbus_new.c1562
-rw-r--r--contrib/wpa/wpa_supplicant/dbus/dbus_new.h234
-rw-r--r--contrib/wpa/wpa_supplicant/dbus/dbus_new_handlers.c2957
-rw-r--r--contrib/wpa/wpa_supplicant/dbus/dbus_new_handlers.h196
-rw-r--r--contrib/wpa/wpa_supplicant/dbus/dbus_new_handlers_wps.c331
-rw-r--r--contrib/wpa/wpa_supplicant/dbus/dbus_new_helpers.c875
-rw-r--r--contrib/wpa/wpa_supplicant/dbus/dbus_new_helpers.h147
-rw-r--r--contrib/wpa/wpa_supplicant/dbus/dbus_new_introspect.c278
-rw-r--r--contrib/wpa/wpa_supplicant/dbus/dbus_old.c (renamed from contrib/wpa/wpa_supplicant/ctrl_iface_dbus.c)682
-rw-r--r--contrib/wpa/wpa_supplicant/dbus/dbus_old.h (renamed from contrib/wpa/wpa_supplicant/ctrl_iface_dbus.h)53
-rw-r--r--contrib/wpa/wpa_supplicant/dbus/dbus_old_handlers.c (renamed from contrib/wpa/wpa_supplicant/ctrl_iface_dbus_handlers.c)343
-rw-r--r--contrib/wpa/wpa_supplicant/dbus/dbus_old_handlers.h (renamed from contrib/wpa/wpa_supplicant/ctrl_iface_dbus_handlers.h)18
-rw-r--r--contrib/wpa/wpa_supplicant/dbus/dbus_old_handlers_wps.c161
-rw-r--r--contrib/wpa/wpa_supplicant/dbus/fi.epitest.hostap.WPASupplicant.service (renamed from contrib/wpa/wpa_supplicant/dbus-wpa_supplicant.service)0
-rw-r--r--contrib/wpa/wpa_supplicant/dbus/fi.w1.wpa_supplicant1.service4
-rw-r--r--contrib/wpa/wpa_supplicant/defconfig55
-rw-r--r--contrib/wpa/wpa_supplicant/doc/code_structure.doxygen322
-rw-r--r--contrib/wpa/wpa_supplicant/doc/ctrl_iface.doxygen481
-rw-r--r--contrib/wpa/wpa_supplicant/doc/docbook/.gitignore6
-rw-r--r--contrib/wpa/wpa_supplicant/doc/docbook/wpa_background.82
-rw-r--r--contrib/wpa/wpa_supplicant/doc/docbook/wpa_cli.82
-rw-r--r--contrib/wpa/wpa_supplicant/doc/docbook/wpa_gui.82
-rw-r--r--contrib/wpa/wpa_supplicant/doc/docbook/wpa_passphrase.82
-rw-r--r--contrib/wpa/wpa_supplicant/doc/docbook/wpa_priv.82
-rw-r--r--contrib/wpa/wpa_supplicant/doc/docbook/wpa_supplicant.818
-rw-r--r--contrib/wpa/wpa_supplicant/doc/docbook/wpa_supplicant.conf.52
-rw-r--r--contrib/wpa/wpa_supplicant/doc/docbook/wpa_supplicant.sgml13
-rw-r--r--contrib/wpa/wpa_supplicant/doc/doxygen.fast239
-rw-r--r--contrib/wpa/wpa_supplicant/doc/doxygen.full239
-rw-r--r--contrib/wpa/wpa_supplicant/doc/driver_wrapper.doxygen180
-rw-r--r--contrib/wpa/wpa_supplicant/doc/eap.doxygen87
-rwxr-xr-xcontrib/wpa/wpa_supplicant/doc/kerneldoc2doxygen.pl134
-rw-r--r--contrib/wpa/wpa_supplicant/doc/mainpage.doxygen56
-rw-r--r--contrib/wpa/wpa_supplicant/doc/porting.doxygen208
-rw-r--r--contrib/wpa/wpa_supplicant/doc/testing_tools.doxygen295
-rw-r--r--contrib/wpa/wpa_supplicant/doc/wpa_supplicant.fig247
-rw-r--r--contrib/wpa/wpa_supplicant/driver_i.h494
-rw-r--r--contrib/wpa/wpa_supplicant/eap_register.c235
-rw-r--r--contrib/wpa/wpa_supplicant/eapol_test.c50
-rw-r--r--contrib/wpa/wpa_supplicant/events.c797
-rwxr-xr-xcontrib/wpa/wpa_supplicant/examples/60_wpa_supplicant19
-rwxr-xr-xcontrib/wpa/wpa_supplicant/examples/wpas-dbus-new-getall.py59
-rwxr-xr-xcontrib/wpa/wpa_supplicant/examples/wpas-dbus-new-signals.py203
-rwxr-xr-xcontrib/wpa/wpa_supplicant/examples/wpas-dbus-new-wps.py80
-rwxr-xr-xcontrib/wpa/wpa_supplicant/examples/wpas-dbus-new.py149
-rw-r--r--contrib/wpa/wpa_supplicant/ibss_rsn.c510
-rw-r--r--contrib/wpa/wpa_supplicant/ibss_rsn.h49
-rw-r--r--contrib/wpa/wpa_supplicant/main.c69
-rw-r--r--contrib/wpa/wpa_supplicant/mlme.c467
-rw-r--r--contrib/wpa/wpa_supplicant/mlme.h25
-rw-r--r--contrib/wpa/wpa_supplicant/nmake.mak22
-rw-r--r--contrib/wpa/wpa_supplicant/notify.c339
-rw-r--r--contrib/wpa/wpa_supplicant/notify.h81
-rw-r--r--contrib/wpa/wpa_supplicant/preauth_test.c29
-rw-r--r--contrib/wpa/wpa_supplicant/scan.c548
-rw-r--r--contrib/wpa/wpa_supplicant/scan.h37
-rw-r--r--contrib/wpa/wpa_supplicant/sme.c490
-rw-r--r--contrib/wpa/wpa_supplicant/sme.h78
-rw-r--r--contrib/wpa/wpa_supplicant/tests/test_aes.c307
-rw-r--r--contrib/wpa/wpa_supplicant/tests/test_eap_sim_common.c2
-rw-r--r--contrib/wpa/wpa_supplicant/tests/test_md4.c99
-rw-r--r--contrib/wpa/wpa_supplicant/tests/test_md5.c99
-rw-r--r--contrib/wpa/wpa_supplicant/tests/test_ms_funcs.c119
-rw-r--r--contrib/wpa/wpa_supplicant/tests/test_sha1.c347
-rw-r--r--contrib/wpa/wpa_supplicant/tests/test_sha256.c331
-rw-r--r--contrib/wpa/wpa_supplicant/tests/test_wpa.c31
-rw-r--r--contrib/wpa/wpa_supplicant/tests/test_x509v3.c69
-rwxr-xr-xcontrib/wpa/wpa_supplicant/tests/test_x509v3_nist.sh144
-rwxr-xr-xcontrib/wpa/wpa_supplicant/tests/test_x509v3_nist2.sh165
-rw-r--r--contrib/wpa/wpa_supplicant/todo.txt15
-rw-r--r--contrib/wpa/wpa_supplicant/wpa_cli.c630
-rw-r--r--contrib/wpa/wpa_supplicant/wpa_passphrase.c2
-rw-r--r--contrib/wpa/wpa_supplicant/wpa_priv.c222
-rw-r--r--contrib/wpa/wpa_supplicant/wpa_supplicant.c852
-rw-r--r--contrib/wpa/wpa_supplicant/wpa_supplicant.conf54
-rw-r--r--contrib/wpa/wpa_supplicant/wpa_supplicant.nsi10
-rw-r--r--contrib/wpa/wpa_supplicant/wpa_supplicant_i.h518
-rw-r--r--contrib/wpa/wpa_supplicant/wpas_glue.c105
-rw-r--r--contrib/wpa/wpa_supplicant/wps_supplicant.c463
-rw-r--r--contrib/wpa/wpa_supplicant/wps_supplicant.h32
-rw-r--r--contrib/wpa/wpa_supplicant/xcode/wpa_supplicant.xcodeproj/project.pbxproj513
493 files changed, 50887 insertions, 28027 deletions
diff --git a/contrib/wpa/hostapd/.gitignore b/contrib/wpa/hostapd/.gitignore
new file mode 100644
index 0000000..6dd2c2f
--- /dev/null
+++ b/contrib/wpa/hostapd/.gitignore
@@ -0,0 +1,7 @@
+*.d
+.config
+driver_conf.c
+hostapd
+hostapd_cli
+hlr_auc_gw
+nt_password_hash
diff --git a/contrib/wpa/hostapd/ChangeLog b/contrib/wpa/hostapd/ChangeLog
index 18af4b1..a7f1f10 100644
--- a/contrib/wpa/hostapd/ChangeLog
+++ b/contrib/wpa/hostapd/ChangeLog
@@ -1,42 +1,108 @@
ChangeLog for hostapd
-2010-01-12 - v0.6.10
- * fixed SHA-256 based key derivation function to match with the
- standard when using CCMP (for IEEE 802.11r and IEEE 802.11w)
- (note: this breaks interoperability with previous version) [Bug 307]
- * fixed WPS selected registrar expiration for internal PIN registrar
- * disable PMTU discovery for RADIUS packets
- * fixed WPS UPnP SSDP on 32-bit targets
- * fixed WPS AP reconfiguration with drivers that do not use hostapd
- MLME
- * fixed RSN parameter setting for multi-BSS case
- * added WPS workarounds for known interoperability issues with broken,
- deployed implementation
- * update IEEE 802.11w implementation to match with the published
- standard
- * fixed OpCode when proxying WSC_ACK or WSC_NACK from WPS ER
- * fixed proxying of WSC_NACK to WPS ER
- * fixed compilation with newer GnuTLS versions
- * added support for defining timeout for WPS PINs
+2010-09-07 - v0.7.3
+ * fixed re-association after WPS not initializing WPA state machine in
+ some cases
+ * fixed WPS IE update on reconfiguration
+ * fixed WPS code not to proxy Probe Request frames for foreign SSIDs
+ * added WPS workaround for open networks and some known interop issues
+ * fixed WPS Diffie-Hellman derivation to use correct public key length
+ * fixed FT RRB messages on big endian CPUs
+ * changed WPS protection for brute force AP PIN attacks to disable AP
+ PIN only temporarily (but with increasing time) to avoid usability
+ issues on Label-only devices
+ * added wps_ap_pin command for more secure handling of AP PIN
+ operations (e.g., to generate a random AP PIN and only use it for
+ short amount of time)
+ * fixed HT STBC negotiation
+
+2010-04-18 - v0.7.2
+ * fix WPS internal Registrar use when an external Registrar is also
+ active
+ * bsd: Cleaned up driver wrapper and added various low-level
+ configuration options
+ * TNC: fixed issues with fragmentation
+ * EAP-TNC: add Flags field into fragment acknowledgement (needed to
+ interoperate with other implementations; may potentially breaks
+ compatibility with older wpa_supplicant/hostapd versions)
+ * cleaned up driver wrapper API for multi-BSS operations
+ * nl80211: fix multi-BSS and VLAN operations
+ * fix number of issues with IEEE 802.11r/FT; this version is not
+ backwards compatible with old versions
+ * add SA Query Request processing in AP mode (IEEE 802.11w)
+ * fix IGTK PN in group rekeying (IEEE 802.11w)
+ * fix WPS PBC session overlap detection to use correct attribute
+ * hostapd_notif_Assoc() can now be called with all IEs to simplify
+ driver wrappers
+ * work around interoperability issue with some WPS External Registrar
+ implementations
+ * nl80211: fix WPS IE update
+ * hostapd_cli: add support for action script operations (run a script
+ on hostapd events)
+ * fix DH padding with internal crypto code (mainly, for WPS)
+ * fix WPS association with both WPS IE and WPA/RSN IE present with
+ driver wrappers that use hostapd MLME (e.g., nl80211)
+
+2010-01-16 - v0.7.1
+ * cleaned up driver wrapper API (struct wpa_driver_ops); the new API
+ is not fully backwards compatible, so out-of-tree driver wrappers
+ will need modifications
+ * cleaned up various module interfaces
+ * merge hostapd and wpa_supplicant developers' documentation into a
+ single document
+ * fixed HT Capabilities IE with nl80211 drivers
+ * moved generic AP functionality code into src/ap
+ * WPS: handle Selected Registrar as union of info from all Registrars
+ * remove obsolte Prism54.org driver wrapper
+ * added internal debugging mechanism with backtrace support and memory
+ allocation/freeing validation, etc. tests (CONFIG_WPA_TRACE=y)
+ * EAP-FAST server: piggyback Phase 2 start with the end of Phase 1
+ * WPS: add support for dynamically selecting whether to provision the
+ PSK as an ASCII passphrase or PSK
+ * added support for WDS (4-address frame) mode with per-station virtual
+ interfaces (wds_sta=1 in config file; only supported with
+ driver=nl80211 for now)
* fixed WPS Probe Request processing to handle missing required
attribute
* fixed PKCS#12 use with OpenSSL 1.0.0
+ * detect bridge interface automatically so that bridge parameter in
+ hostapd.conf becomes optional (though, it may now be used to
+ automatically add then WLAN interface into a bridge with
+ driver=nl80211)
-2009-03-23 - v0.6.9
+2009-11-21 - v0.7.0
+ * increased hostapd_cli ping interval to 5 seconds and made this
+ configurable with a new command line options (-G<seconds>)
+ * driver_nl80211: use Linux socket filter to improve performance
+ * added support for external Registrars with WPS (UPnP transport)
+ * 802.11n: scan for overlapping BSSes before starting 20/40 MHz channel
* driver_nl80211: fixed STA accounting data collection (TX/RX bytes
reported correctly; TX/RX packets not yet available from kernel)
+ * added support for WPS USBA out-of-band mechanism with USB Flash
+ Drives (UFD) (CONFIG_WPS_UFD=y)
* fixed EAPOL/EAP reauthentication when using an external RADIUS
authentication server
- * driver_prism54: fixed segmentation fault on initialization
* fixed TNC with EAP-TTLS
* fixed IEEE 802.11r key derivation function to match with the standard
(note: this breaks interoperability with previous version) [Bug 303]
-
-2009-02-15 - v0.6.8
- * increased hostapd_cli ping interval to 5 seconds and made this
- configurable with a new command line options (-G<seconds>)
- * driver_nl80211: use Linux socket filter to improve performance
- * added support for external Registrars with WPS (UPnP transport)
+ * fixed SHA-256 based key derivation function to match with the
+ standard when using CCMP (for IEEE 802.11r and IEEE 802.11w)
+ (note: this breaks interoperability with previous version) [Bug 307]
+ * added number of code size optimizations to remove unnecessary
+ functionality from the program binary based on build configuration
+ (part of this automatic; part configurable with CONFIG_NO_* build
+ options)
+ * use shared driver wrapper files with wpa_supplicant
+ * driver_nl80211: multiple updates to provide support for new Linux
+ nl80211/mac80211 functionality
+ * updated management frame protection to use IEEE Std 802.11w-2009
+ * fixed number of small WPS issues and added workarounds to
+ interoperate with common deployed broken implementations
+ * added some IEEE 802.11n co-existance rules to disable 40 MHz channels
+ or modify primary/secondary channels if needed based on neighboring
+ networks
+ * added support for NFC out-of-band mechanism with WPS
+ * added preliminary support for IEEE 802.11r RIC processing
2009-01-06 - v0.6.7
* added support for Wi-Fi Protected Setup (WPS)
diff --git a/contrib/wpa/hostapd/Makefile b/contrib/wpa/hostapd/Makefile
index 3b3d7fe..6d344d2 100644
--- a/contrib/wpa/hostapd/Makefile
+++ b/contrib/wpa/hostapd/Makefile
@@ -6,14 +6,8 @@ ifndef CFLAGS
CFLAGS = -MMD -O2 -Wall -g
endif
-# define HOSTAPD_DUMP_STATE to include SIGUSR1 handler for dumping state to
-# a file (undefine it, if you want to save in binary size)
-CFLAGS += -DHOSTAPD_DUMP_STATE
-
CFLAGS += -I../src
-CFLAGS += -I../src/crypto
CFLAGS += -I../src/utils
-CFLAGS += -I../src/common
# Uncomment following line and set the path to your kernel tree include
# directory if your C library does not include all header files.
@@ -38,12 +32,45 @@ CFLAGS += -DCONFIG_NATIVE_WINDOWS
LIBS += -lws2_32
endif
-OBJS = hostapd.o ieee802_1x.o eapol_sm.o \
- ieee802_11.o config.o ieee802_11_auth.o accounting.o \
- sta_info.o wpa.o ctrl_iface.o \
- drivers.o preauth.o pmksa_cache.o beacon.o \
- hw_features.o wme.o ap_list.o \
- mlme.o vlan_init.o wpa_auth_ie.o
+OBJS += main.o
+OBJS += config_file.o
+
+OBJS += ../src/ap/hostapd.o
+OBJS += ../src/ap/wpa_auth_glue.o
+OBJS += ../src/ap/drv_callbacks.o
+OBJS += ../src/ap/ap_drv_ops.o
+OBJS += ../src/ap/utils.o
+OBJS += ../src/ap/authsrv.o
+OBJS += ../src/ap/ieee802_1x.o
+OBJS += ../src/ap/ap_config.o
+OBJS += ../src/ap/ieee802_11_auth.o
+OBJS += ../src/ap/sta_info.o
+OBJS += ../src/ap/wpa_auth.o
+OBJS += ../src/ap/tkip_countermeasures.o
+OBJS += ../src/ap/ap_mlme.o
+OBJS += ../src/ap/wpa_auth_ie.o
+OBJS += ../src/ap/preauth_auth.o
+OBJS += ../src/ap/pmksa_cache_auth.o
+
+NEED_RC4=y
+NEED_AES=y
+NEED_MD5=y
+NEED_SHA1=y
+
+OBJS += ../src/drivers/drivers.o
+CFLAGS += -DHOSTAPD
+
+ifdef CONFIG_WPA_TRACE
+CFLAGS += -DWPA_TRACE
+OBJS += ../src/utils/trace.o
+LDFLAGS += -rdynamic
+CFLAGS += -funwind-tables
+ifdef CONFIG_WPA_TRACE_BFD
+CFLAGS += -DWPA_TRACE_BFD
+LIBS += -lbfd
+LIBS_c += -lbfd
+endif
+endif
OBJS += ../src/utils/eloop.o
OBJS += ../src/utils/common.o
@@ -55,24 +82,51 @@ OBJS += ../src/utils/ip_addr.o
OBJS += ../src/common/ieee802_11_common.o
OBJS += ../src/common/wpa_common.o
+OBJS += ../src/eapol_auth/eapol_auth_sm.o
+
+
+ifndef CONFIG_NO_DUMP_STATE
+# define HOSTAPD_DUMP_STATE to include SIGUSR1 handler for dumping state to
+# a file (undefine it, if you want to save in binary size)
+CFLAGS += -DHOSTAPD_DUMP_STATE
+OBJS += dump_state.o
+OBJS += ../src/eapol_auth/eapol_auth_dump.o
+endif
+
+ifdef CONFIG_NO_RADIUS
+CFLAGS += -DCONFIG_NO_RADIUS
+CONFIG_NO_ACCOUNTING=y
+else
OBJS += ../src/radius/radius.o
OBJS += ../src/radius/radius_client.o
+endif
-OBJS += ../src/crypto/md5.o
-OBJS += ../src/crypto/rc4.o
-OBJS += ../src/crypto/md4.o
-OBJS += ../src/crypto/sha1.o
-OBJS += ../src/crypto/des.o
-OBJS += ../src/crypto/aes_wrap.o
-OBJS += ../src/crypto/aes.o
+ifdef CONFIG_NO_ACCOUNTING
+CFLAGS += -DCONFIG_NO_ACCOUNTING
+else
+OBJS += ../src/ap/accounting.o
+endif
+
+ifdef CONFIG_NO_VLAN
+CFLAGS += -DCONFIG_NO_VLAN
+else
+OBJS += ../src/ap/vlan_init.o
+endif
-HOBJS=../src/hlr_auc_gw/hlr_auc_gw.o ../src/utils/common.o ../src/utils/wpa_debug.o ../src/utils/os_$(CONFIG_OS).o ../src/hlr_auc_gw/milenage.o ../src/crypto/aes_wrap.o ../src/crypto/aes.o
+ifdef CONFIG_NO_CTRL_IFACE
+CFLAGS += -DCONFIG_NO_CTRL_IFACE
+else
+OBJS += ctrl_iface.o
+OBJS += ../src/ap/ctrl_iface_ap.o
+endif
+
+OBJS += ../src/crypto/md5.o
CFLAGS += -DCONFIG_CTRL_IFACE -DCONFIG_CTRL_IFACE_UNIX
ifdef CONFIG_IAPP
CFLAGS += -DCONFIG_IAPP
-OBJS += iapp.o
+OBJS += ../src/ap/iapp.o
endif
ifdef CONFIG_RSN_PREAUTH
@@ -82,78 +136,32 @@ endif
ifdef CONFIG_PEERKEY
CFLAGS += -DCONFIG_PEERKEY
-OBJS += peerkey.o
+OBJS += ../src/ap/peerkey_auth.o
endif
ifdef CONFIG_IEEE80211W
CFLAGS += -DCONFIG_IEEE80211W
NEED_SHA256=y
+NEED_AES_OMAC1=y
endif
ifdef CONFIG_IEEE80211R
CFLAGS += -DCONFIG_IEEE80211R
-OBJS += wpa_ft.o
+OBJS += ../src/ap/wpa_auth_ft.o
NEED_SHA256=y
+NEED_AES_OMAC1=y
+NEED_AES_UNWRAP=y
endif
ifdef CONFIG_IEEE80211N
CFLAGS += -DCONFIG_IEEE80211N
endif
-ifdef CONFIG_DRIVER_HOSTAP
-CFLAGS += -DCONFIG_DRIVER_HOSTAP
-OBJS += driver_hostap.o
-endif
-
-ifdef CONFIG_DRIVER_WIRED
-CFLAGS += -DCONFIG_DRIVER_WIRED
-OBJS += driver_wired.o
-endif
-
-ifdef CONFIG_DRIVER_MADWIFI
-CFLAGS += -DCONFIG_DRIVER_MADWIFI
-OBJS += driver_madwifi.o
-CONFIG_L2_PACKET=y
-endif
-
-ifdef CONFIG_DRIVER_ATHEROS
-CFLAGS += -DCONFIG_DRIVER_ATHEROS
-OBJS += driver_atheros.o
-CONFIG_L2_PACKET=y
-endif
-
-ifdef CONFIG_DRIVER_PRISM54
-CFLAGS += -DCONFIG_DRIVER_PRISM54
-OBJS += driver_prism54.o
-endif
-
-ifdef CONFIG_DRIVER_NL80211
-CFLAGS += -DCONFIG_DRIVER_NL80211
-OBJS += driver_nl80211.o radiotap.o
-LIBS += -lnl
-ifdef CONFIG_LIBNL20
-LIBS += -lnl-genl
-CFLAGS += -DCONFIG_LIBNL20
-endif
-endif
-
-ifdef CONFIG_DRIVER_BSD
-CFLAGS += -DCONFIG_DRIVER_BSD
-OBJS += driver_bsd.o
-CONFIG_L2_PACKET=y
-CONFIG_DNET_PCAP=y
-CONFIG_L2_FREEBSD=y
-endif
-
-ifdef CONFIG_DRIVER_TEST
-CFLAGS += -DCONFIG_DRIVER_TEST
-OBJS += driver_test.o
-endif
-
-ifdef CONFIG_DRIVER_NONE
-CFLAGS += -DCONFIG_DRIVER_NONE
-OBJS += driver_none.o
-endif
+include ../src/drivers/drivers.mak
+OBJS += $(DRV_AP_OBJS)
+CFLAGS += $(DRV_AP_CFLAGS)
+LDFLAGS += $(DRV_AP_LDFLAGS)
+LIBS += $(DRV_AP_LIBS)
ifdef CONFIG_L2_PACKET
ifdef CONFIG_DNET_PCAP
@@ -173,58 +181,60 @@ endif
ifdef CONFIG_EAP_MD5
-CFLAGS += -DEAP_MD5
-OBJS += ../src/eap_server/eap_md5.o
+CFLAGS += -DEAP_SERVER_MD5
+OBJS += ../src/eap_server/eap_server_md5.o
CHAP=y
endif
ifdef CONFIG_EAP_TLS
-CFLAGS += -DEAP_TLS
-OBJS += ../src/eap_server/eap_tls.o
+CFLAGS += -DEAP_SERVER_TLS
+OBJS += ../src/eap_server/eap_server_tls.o
TLS_FUNCS=y
endif
ifdef CONFIG_EAP_PEAP
-CFLAGS += -DEAP_PEAP
-OBJS += ../src/eap_server/eap_peap.o
+CFLAGS += -DEAP_SERVER_PEAP
+OBJS += ../src/eap_server/eap_server_peap.o
OBJS += ../src/eap_common/eap_peap_common.o
TLS_FUNCS=y
CONFIG_EAP_MSCHAPV2=y
endif
ifdef CONFIG_EAP_TTLS
-CFLAGS += -DEAP_TTLS
-OBJS += ../src/eap_server/eap_ttls.o
+CFLAGS += -DEAP_SERVER_TTLS
+OBJS += ../src/eap_server/eap_server_ttls.o
TLS_FUNCS=y
CHAP=y
endif
ifdef CONFIG_EAP_MSCHAPV2
-CFLAGS += -DEAP_MSCHAPv2
-OBJS += ../src/eap_server/eap_mschapv2.o
+CFLAGS += -DEAP_SERVER_MSCHAPV2
+OBJS += ../src/eap_server/eap_server_mschapv2.o
MS_FUNCS=y
endif
ifdef CONFIG_EAP_GTC
-CFLAGS += -DEAP_GTC
-OBJS += ../src/eap_server/eap_gtc.o
+CFLAGS += -DEAP_SERVER_GTC
+OBJS += ../src/eap_server/eap_server_gtc.o
endif
ifdef CONFIG_EAP_SIM
-CFLAGS += -DEAP_SIM
-OBJS += ../src/eap_server/eap_sim.o
+CFLAGS += -DEAP_SERVER_SIM
+OBJS += ../src/eap_server/eap_server_sim.o
CONFIG_EAP_SIM_COMMON=y
+NEED_AES_CBC=y
endif
ifdef CONFIG_EAP_AKA
-CFLAGS += -DEAP_AKA
-OBJS += ../src/eap_server/eap_aka.o
+CFLAGS += -DEAP_SERVER_AKA
+OBJS += ../src/eap_server/eap_server_aka.o
CONFIG_EAP_SIM_COMMON=y
NEED_SHA256=y
+NEED_AES_CBC=y
endif
ifdef CONFIG_EAP_AKA_PRIME
-CFLAGS += -DEAP_AKA_PRIME
+CFLAGS += -DEAP_SERVER_AKA_PRIME
endif
ifdef CONFIG_EAP_SIM_COMMON
@@ -237,47 +247,52 @@ NEED_FIPS186_2_PRF=y
endif
ifdef CONFIG_EAP_PAX
-CFLAGS += -DEAP_PAX
-OBJS += ../src/eap_server/eap_pax.o ../src/eap_common/eap_pax_common.o
+CFLAGS += -DEAP_SERVER_PAX
+OBJS += ../src/eap_server/eap_server_pax.o ../src/eap_common/eap_pax_common.o
endif
ifdef CONFIG_EAP_PSK
-CFLAGS += -DEAP_PSK
-OBJS += ../src/eap_server/eap_psk.o ../src/eap_common/eap_psk_common.o
+CFLAGS += -DEAP_SERVER_PSK
+OBJS += ../src/eap_server/eap_server_psk.o ../src/eap_common/eap_psk_common.o
+NEED_AES_OMAC1=y
+NEED_AES_ENCBLOCK=y
+NEED_AES_EAX=y
endif
ifdef CONFIG_EAP_SAKE
-CFLAGS += -DEAP_SAKE
-OBJS += ../src/eap_server/eap_sake.o ../src/eap_common/eap_sake_common.o
+CFLAGS += -DEAP_SERVER_SAKE
+OBJS += ../src/eap_server/eap_server_sake.o ../src/eap_common/eap_sake_common.o
endif
ifdef CONFIG_EAP_GPSK
-CFLAGS += -DEAP_GPSK
-OBJS += ../src/eap_server/eap_gpsk.o ../src/eap_common/eap_gpsk_common.o
+CFLAGS += -DEAP_SERVER_GPSK
+OBJS += ../src/eap_server/eap_server_gpsk.o ../src/eap_common/eap_gpsk_common.o
ifdef CONFIG_EAP_GPSK_SHA256
-CFLAGS += -DEAP_GPSK_SHA256
+CFLAGS += -DEAP_SERVER_GPSK_SHA256
endif
NEED_SHA256=y
+NEED_AES_OMAC1=y
endif
ifdef CONFIG_EAP_VENDOR_TEST
-CFLAGS += -DEAP_VENDOR_TEST
-OBJS += ../src/eap_server/eap_vendor_test.o
+CFLAGS += -DEAP_SERVER_VENDOR_TEST
+OBJS += ../src/eap_server/eap_server_vendor_test.o
endif
ifdef CONFIG_EAP_FAST
-CFLAGS += -DEAP_FAST
-OBJS += ../src/eap_server/eap_fast.o
+CFLAGS += -DEAP_SERVER_FAST
+OBJS += ../src/eap_server/eap_server_fast.o
OBJS += ../src/eap_common/eap_fast_common.o
TLS_FUNCS=y
NEED_T_PRF=y
+NEED_AES_UNWRAP=y
endif
ifdef CONFIG_WPS
-CFLAGS += -DCONFIG_WPS -DEAP_WSC
+CFLAGS += -DCONFIG_WPS -DEAP_SERVER_WSC
OBJS += ../src/utils/uuid.o
-OBJS += wps_hostapd.o
-OBJS += ../src/eap_server/eap_wsc.o ../src/eap_common/eap_wsc_common.o
+OBJS += ../src/ap/wps_hostapd.o
+OBJS += ../src/eap_server/eap_server_wsc.o ../src/eap_common/eap_wsc_common.o
OBJS += ../src/wps/wps.o
OBJS += ../src/wps/wps_common.o
OBJS += ../src/wps/wps_attr_parse.o
@@ -288,8 +303,35 @@ OBJS += ../src/wps/wps_enrollee.o
OBJS += ../src/wps/wps_registrar.o
NEED_DH_GROUPS=y
NEED_SHA256=y
-NEED_CRYPTO=y
NEED_BASE64=y
+NEED_AES_CBC=y
+NEED_MODEXP=y
+CONFIG_EAP=y
+
+ifdef CONFIG_WPS_UFD
+CFLAGS += -DCONFIG_WPS_UFD
+OBJS += ../src/wps/wps_ufd.o
+NEED_WPS_OOB=y
+endif
+
+ifdef CONFIG_WPS_NFC
+CFLAGS += -DCONFIG_WPS_NFC
+OBJS += ../src/wps/ndef.o
+OBJS += ../src/wps/wps_nfc.o
+NEED_WPS_OOB=y
+ifdef CONFIG_WPS_NFC_PN531
+PN531_PATH ?= /usr/local/src/nfc
+CFLAGS += -DCONFIG_WPS_NFC_PN531
+CFLAGS += -I${PN531_PATH}/inc
+OBJS += ../src/wps/wps_nfc_pn531.o
+LIBS += ${PN531_PATH}/lib/wpsnfc.dll
+LIBS += ${PN531_PATH}/lib/libnfc_mapping_pn53x.dll
+endif
+endif
+
+ifdef NEED_WPS_OOB
+CFLAGS += -DCONFIG_WPS_OOB
+endif
ifdef CONFIG_WPS_UPNP
CFLAGS += -DCONFIG_WPS_UPNP
@@ -297,22 +339,28 @@ OBJS += ../src/wps/wps_upnp.o
OBJS += ../src/wps/wps_upnp_ssdp.o
OBJS += ../src/wps/wps_upnp_web.o
OBJS += ../src/wps/wps_upnp_event.o
+OBJS += ../src/wps/wps_upnp_ap.o
+OBJS += ../src/wps/upnp_xml.o
OBJS += ../src/wps/httpread.o
+OBJS += ../src/wps/http_client.o
+OBJS += ../src/wps/http_server.o
endif
endif
ifdef CONFIG_EAP_IKEV2
-CFLAGS += -DEAP_IKEV2
-OBJS += ../src/eap_server/eap_ikev2.o ../src/eap_server/ikev2.o
+CFLAGS += -DEAP_SERVER_IKEV2
+OBJS += ../src/eap_server/eap_server_ikev2.o ../src/eap_server/ikev2.o
OBJS += ../src/eap_common/eap_ikev2_common.o ../src/eap_common/ikev2_common.o
NEED_DH_GROUPS=y
NEED_DH_GROUPS_ALL=y
+NEED_MODEXP=y
+NEED_CIPHER=y
endif
ifdef CONFIG_EAP_TNC
-CFLAGS += -DEAP_TNC
-OBJS += ../src/eap_server/eap_tnc.o
+CFLAGS += -DEAP_SERVER_TNC
+OBJS += ../src/eap_server/eap_server_tnc.o
OBJS += ../src/eap_server/tncs.o
NEED_BASE64=y
ifndef CONFIG_DRIVER_BSD
@@ -321,135 +369,150 @@ endif
endif
# Basic EAP functionality is needed for EAPOL
-OBJS += ../src/eap_server/eap.o
+OBJS += eap_register.o
+OBJS += ../src/eap_server/eap_server.o
OBJS += ../src/eap_common/eap_common.o
-OBJS += ../src/eap_server/eap_methods.o
-OBJS += ../src/eap_server/eap_identity.o
+OBJS += ../src/eap_server/eap_server_methods.o
+OBJS += ../src/eap_server/eap_server_identity.o
+CFLAGS += -DEAP_SERVER_IDENTITY
ifdef CONFIG_EAP
CFLAGS += -DEAP_SERVER
endif
-ifndef CONFIG_TLS
-CONFIG_TLS=openssl
+ifdef CONFIG_PKCS12
+CFLAGS += -DPKCS12_FUNCS
endif
-ifeq ($(CONFIG_TLS), internal)
-ifndef CONFIG_CRYPTO
-CONFIG_CRYPTO=internal
-endif
-endif
-ifeq ($(CONFIG_CRYPTO), libtomcrypt)
-CFLAGS += -DCONFIG_INTERNAL_X509
-endif
-ifeq ($(CONFIG_CRYPTO), internal)
-CFLAGS += -DCONFIG_INTERNAL_X509
+ifdef MS_FUNCS
+OBJS += ../src/crypto/ms_funcs.o
+NEED_DES=y
+NEED_MD4=y
endif
+ifdef CHAP
+OBJS += ../src/eap_common/chap.o
+endif
ifdef TLS_FUNCS
+NEED_DES=y
# Shared TLS functions (needed for EAP_TLS, EAP_PEAP, and EAP_TTLS)
CFLAGS += -DEAP_TLS_FUNCS
-OBJS += ../src/eap_server/eap_tls_common.o
+OBJS += ../src/eap_server/eap_server_tls_common.o
NEED_TLS_PRF=y
+endif
+
+ifndef CONFIG_TLS
+CONFIG_TLS=openssl
+endif
+
ifeq ($(CONFIG_TLS), openssl)
+ifdef TLS_FUNCS
OBJS += ../src/crypto/tls_openssl.o
-LIBS += -lssl -lcrypto
-LIBS_p += -lcrypto
+LIBS += -lssl
+endif
+OBJS += ../src/crypto/crypto_openssl.o
+HOBJS += ../src/crypto/crypto_openssl.o
+ifdef NEED_FIPS186_2_PRF
+OBJS += ../src/crypto/fips_prf_openssl.o
+endif
+LIBS += -lcrypto
LIBS_h += -lcrypto
endif
+
ifeq ($(CONFIG_TLS), gnutls)
+ifdef TLS_FUNCS
OBJS += ../src/crypto/tls_gnutls.o
-LIBS += -lgnutls -lgcrypt -lgpg-error
-LIBS_p += -lgcrypt
-LIBS_h += -lgcrypt
-endif
+LIBS += -lgnutls -lgpg-error
ifdef CONFIG_GNUTLS_EXTRA
CFLAGS += -DCONFIG_GNUTLS_EXTRA
LIBS += -lgnutls-extra
endif
-ifeq ($(CONFIG_TLS), internal)
-OBJS += ../src/crypto/tls_internal.o
-OBJS += ../src/tls/tlsv1_common.o ../src/tls/tlsv1_record.o
-OBJS += ../src/tls/tlsv1_cred.o ../src/tls/tlsv1_server.o
-OBJS += ../src/tls/tlsv1_server_write.o ../src/tls/tlsv1_server_read.o
-OBJS += ../src/tls/asn1.o ../src/tls/x509v3.o
-OBJS_p += ../src/tls/asn1.o
-OBJS_p += ../src/crypto/rc4.o ../src/crypto/aes_wrap.o ../src/crypto/aes.o
-NEED_BASE64=y
-CFLAGS += -DCONFIG_TLS_INTERNAL
-CFLAGS += -DCONFIG_TLS_INTERNAL_SERVER
-ifeq ($(CONFIG_CRYPTO), internal)
-ifdef CONFIG_INTERNAL_LIBTOMMATH
-CFLAGS += -DCONFIG_INTERNAL_LIBTOMMATH
-else
-LIBS += -ltommath
-LIBS_p += -ltommath
-endif
-endif
-ifeq ($(CONFIG_CRYPTO), libtomcrypt)
-LIBS += -ltomcrypt -ltfm
-LIBS_p += -ltomcrypt -ltfm
endif
+OBJS += ../src/crypto/crypto_gnutls.o
+HOBJS += ../src/crypto/crypto_gnutls.o
+ifdef NEED_FIPS186_2_PRF
+OBJS += ../src/crypto/fips_prf_gnutls.o
endif
-NEED_CRYPTO=y
-else
-OBJS += ../src/crypto/tls_none.o
+LIBS += -lgcrypt
+LIBS_h += -lgcrypt
+CONFIG_INTERNAL_SHA256=y
+CONFIG_INTERNAL_RC4=y
+CONFIG_INTERNAL_DH_GROUP5=y
endif
-ifdef CONFIG_PKCS12
-CFLAGS += -DPKCS12_FUNCS
+ifeq ($(CONFIG_TLS), schannel)
+ifdef TLS_FUNCS
+OBJS += ../src/crypto/tls_schannel.o
endif
-
-ifdef MS_FUNCS
-OBJS += ../src/crypto/ms_funcs.o
-NEED_CRYPTO=y
+OBJS += ../src/crypto/crypto_cryptoapi.o
+OBJS_p += ../src/crypto/crypto_cryptoapi.o
+CONFIG_INTERNAL_SHA256=y
+CONFIG_INTERNAL_RC4=y
+CONFIG_INTERNAL_DH_GROUP5=y
endif
-ifdef CHAP
-OBJS += ../src/eap_common/chap.o
+ifeq ($(CONFIG_TLS), nss)
+ifdef TLS_FUNCS
+OBJS += ../src/crypto/tls_nss.o
+LIBS += -lssl3
endif
-
-ifdef NEED_CRYPTO
-ifndef TLS_FUNCS
-ifeq ($(CONFIG_TLS), openssl)
-LIBS += -lcrypto
-LIBS_p += -lcrypto
-LIBS_h += -lcrypto
+OBJS += ../src/crypto/crypto_nss.o
+ifdef NEED_FIPS186_2_PRF
+OBJS += ../src/crypto/fips_prf_nss.o
endif
-ifeq ($(CONFIG_TLS), gnutls)
-LIBS += -lgcrypt
-LIBS_p += -lgcrypt
-LIBS_h += -lgcrypt
+LIBS += -lnss3
+LIBS_h += -lnss3
+CONFIG_INTERNAL_MD4=y
+CONFIG_INTERNAL_DH_GROUP5=y
endif
+
ifeq ($(CONFIG_TLS), internal)
-ifeq ($(CONFIG_CRYPTO), libtomcrypt)
-LIBS += -ltomcrypt -ltfm
-LIBS_p += -ltomcrypt -ltfm
+ifndef CONFIG_CRYPTO
+CONFIG_CRYPTO=internal
endif
+ifdef TLS_FUNCS
+OBJS += ../src/crypto/crypto_internal-rsa.o
+OBJS += ../src/crypto/tls_internal.o
+OBJS += ../src/tls/tlsv1_common.o
+OBJS += ../src/tls/tlsv1_record.o
+OBJS += ../src/tls/tlsv1_cred.o
+OBJS += ../src/tls/tlsv1_server.o
+OBJS += ../src/tls/tlsv1_server_write.o
+OBJS += ../src/tls/tlsv1_server_read.o
+OBJS += ../src/tls/asn1.o
+OBJS += ../src/tls/rsa.o
+OBJS += ../src/tls/x509v3.o
+OBJS += ../src/tls/pkcs1.o
+OBJS += ../src/tls/pkcs5.o
+OBJS += ../src/tls/pkcs8.o
+NEED_SHA256=y
+NEED_BASE64=y
+NEED_TLS_PRF=y
+NEED_MODEXP=y
+NEED_CIPHER=y
+CFLAGS += -DCONFIG_TLS_INTERNAL
+CFLAGS += -DCONFIG_TLS_INTERNAL_SERVER
endif
+ifdef NEED_CIPHER
+NEED_DES=y
+OBJS += ../src/crypto/crypto_internal-cipher.o
endif
-ifeq ($(CONFIG_TLS), openssl)
-OBJS += ../src/crypto/crypto_openssl.o
-OBJS_p += ../src/crypto/crypto_openssl.o
-HOBJS += ../src/crypto/crypto_openssl.o
-CONFIG_INTERNAL_SHA256=y
+ifdef NEED_MODEXP
+OBJS += ../src/crypto/crypto_internal-modexp.o
+OBJS += ../src/tls/bignum.o
endif
-ifeq ($(CONFIG_TLS), gnutls)
-OBJS += ../src/crypto/crypto_gnutls.o
-OBJS_p += ../src/crypto/crypto_gnutls.o
-HOBJS += ../src/crypto/crypto_gnutls.o
-CONFIG_INTERNAL_SHA256=y
-endif
-ifeq ($(CONFIG_TLS), internal)
ifeq ($(CONFIG_CRYPTO), libtomcrypt)
OBJS += ../src/crypto/crypto_libtomcrypt.o
-OBJS_p += ../src/crypto/crypto_libtomcrypt.o
+LIBS += -ltomcrypt -ltfm
+LIBS_h += -ltomcrypt -ltfm
CONFIG_INTERNAL_SHA256=y
+CONFIG_INTERNAL_RC4=y
+CONFIG_INTERNAL_DH_GROUP5=y
endif
ifeq ($(CONFIG_CRYPTO), internal)
-OBJS += ../src/crypto/crypto_internal.o ../src/tls/rsa.o ../src/tls/bignum.o
-OBJS_p += ../src/crypto/crypto_internal.o ../src/tls/rsa.o ../src/tls/bignum.o
+OBJS += ../src/crypto/crypto_internal.o
+NEED_AES_DEC=y
CFLAGS += -DCONFIG_CRYPTO_INTERNAL
ifdef CONFIG_INTERNAL_LIBTOMMATH
CFLAGS += -DCONFIG_INTERNAL_LIBTOMMATH
@@ -458,7 +521,7 @@ CFLAGS += -DLTM_FAST
endif
else
LIBS += -ltommath
-LIBS_p += -ltommath
+LIBS_h += -ltommath
endif
CONFIG_INTERNAL_AES=y
CONFIG_INTERNAL_DES=y
@@ -466,55 +529,140 @@ CONFIG_INTERNAL_SHA1=y
CONFIG_INTERNAL_MD4=y
CONFIG_INTERNAL_MD5=y
CONFIG_INTERNAL_SHA256=y
+CONFIG_INTERNAL_RC4=y
+CONFIG_INTERNAL_DH_GROUP5=y
endif
+ifeq ($(CONFIG_CRYPTO), cryptoapi)
+OBJS += ../src/crypto/crypto_cryptoapi.o
+OBJS_p += ../src/crypto/crypto_cryptoapi.o
+CFLAGS += -DCONFIG_CRYPTO_CRYPTOAPI
+CONFIG_INTERNAL_SHA256=y
+CONFIG_INTERNAL_RC4=y
endif
-else
+endif
+
+ifeq ($(CONFIG_TLS), none)
+ifdef TLS_FUNCS
+OBJS += ../src/crypto/tls_none.o
+CFLAGS += -DEAP_TLS_NONE
CONFIG_INTERNAL_AES=y
CONFIG_INTERNAL_SHA1=y
CONFIG_INTERNAL_MD5=y
+endif
+OBJS += ../src/crypto/crypto_none.o
+OBJS_p += ../src/crypto/crypto_none.o
CONFIG_INTERNAL_SHA256=y
+CONFIG_INTERNAL_RC4=y
endif
+ifndef TLS_FUNCS
+OBJS += ../src/crypto/tls_none.o
+ifeq ($(CONFIG_TLS), internal)
+CONFIG_INTERNAL_AES=y
+CONFIG_INTERNAL_SHA1=y
+CONFIG_INTERNAL_MD5=y
+CONFIG_INTERNAL_RC4=y
+endif
+endif
+
+AESOBJS = # none so far
+ifdef CONFIG_INTERNAL_AES
+AESOBJS += ../src/crypto/aes-internal.o ../src/crypto/aes-internal-enc.o
+endif
+
+AESOBJS += ../src/crypto/aes-wrap.o
+ifdef NEED_AES_EAX
+AESOBJS += ../src/crypto/aes-eax.o
+NEED_AES_CTR=y
+endif
+ifdef NEED_AES_CTR
+AESOBJS += ../src/crypto/aes-ctr.o
+endif
+ifdef NEED_AES_ENCBLOCK
+AESOBJS += ../src/crypto/aes-encblock.o
+endif
+ifdef NEED_AES_OMAC1
+AESOBJS += ../src/crypto/aes-omac1.o
+endif
+ifdef NEED_AES_UNWRAP
+NEED_AES_DEC=y
+AESOBJS += ../src/crypto/aes-unwrap.o
+endif
+ifdef NEED_AES_CBC
+NEED_AES_DEC=y
+AESOBJS += ../src/crypto/aes-cbc.o
+endif
+ifdef NEED_AES_DEC
ifdef CONFIG_INTERNAL_AES
-CFLAGS += -DINTERNAL_AES
+AESOBJS += ../src/crypto/aes-internal-dec.o
endif
+endif
+ifdef NEED_AES
+OBJS += $(AESOBJS)
+endif
+
+ifdef NEED_SHA1
+SHA1OBJS += ../src/crypto/sha1.o
ifdef CONFIG_INTERNAL_SHA1
-CFLAGS += -DINTERNAL_SHA1
+SHA1OBJS += ../src/crypto/sha1-internal.o
+ifdef NEED_FIPS186_2_PRF
+SHA1OBJS += ../src/crypto/fips_prf_internal.o
endif
-ifdef CONFIG_INTERNAL_SHA256
-CFLAGS += -DINTERNAL_SHA256
endif
+SHA1OBJS += ../src/crypto/sha1-pbkdf2.o
+ifdef NEED_T_PRF
+SHA1OBJS += ../src/crypto/sha1-tprf.o
+endif
+ifdef NEED_TLS_PRF
+SHA1OBJS += ../src/crypto/sha1-tlsprf.o
+endif
+endif
+
+ifdef NEED_SHA1
+OBJS += $(SHA1OBJS)
+endif
+
+ifdef NEED_MD5
ifdef CONFIG_INTERNAL_MD5
-CFLAGS += -DINTERNAL_MD5
+OBJS += ../src/crypto/md5-internal.o
+endif
endif
+
+ifdef NEED_MD4
ifdef CONFIG_INTERNAL_MD4
-CFLAGS += -DINTERNAL_MD4
+OBJS += ../src/crypto/md4-internal.o
+endif
endif
+
+ifdef NEED_DES
ifdef CONFIG_INTERNAL_DES
-CFLAGS += -DINTERNAL_DES
+OBJS += ../src/crypto/des-internal.o
+endif
+endif
+
+ifdef NEED_RC4
+ifdef CONFIG_INTERNAL_RC4
+OBJS += ../src/crypto/rc4.o
+endif
endif
ifdef NEED_SHA256
OBJS += ../src/crypto/sha256.o
+ifdef CONFIG_INTERNAL_SHA256
+OBJS += ../src/crypto/sha256-internal.o
+endif
endif
ifdef NEED_DH_GROUPS
OBJS += ../src/crypto/dh_groups.o
+endif
ifdef NEED_DH_GROUPS_ALL
CFLAGS += -DALL_DH_GROUPS
endif
+ifdef CONFIG_INTERNAL_DH_GROUP5
+ifdef NEED_DH_GROUPS
+OBJS += ../src/crypto/dh_group5.o
endif
-
-ifndef NEED_FIPS186_2_PRF
-CFLAGS += -DCONFIG_NO_FIPS186_2_PRF
-endif
-
-ifndef NEED_T_PRF
-CFLAGS += -DCONFIG_NO_T_PRF
-endif
-
-ifndef NEED_TLS_PRF
-CFLAGS += -DCONFIG_NO_TLS_PRF
endif
ifdef CONFIG_RADIUS_SERVER
@@ -540,16 +688,20 @@ ifdef NEED_BASE64
OBJS += ../src/utils/base64.o
endif
-ifdef CONFIG_NO_STDOUT_DEBUG
-CFLAGS += -DCONFIG_NO_STDOUT_DEBUG
+ifdef NEED_AP_MLME
+OBJS += ../src/ap/beacon.o
+OBJS += ../src/ap/wmm.o
+OBJS += ../src/ap/ap_list.o
+OBJS += ../src/ap/ieee802_11.o
+OBJS += ../src/ap/hw_features.o
+CFLAGS += -DNEED_AP_MLME
+endif
+ifdef CONFIG_IEEE80211N
+OBJS += ../src/ap/ieee802_11_ht.o
endif
-ifdef CONFIG_NO_AES_EXTRAS
-CFLAGS += -DCONFIG_NO_AES_UNWRAP
-CFLAGS += -DCONFIG_NO_AES_CTR -DCONFIG_NO_AES_OMAC1
-CFLAGS += -DCONFIG_NO_AES_EAX -DCONFIG_NO_AES_CBC
-CFLAGS += -DCONFIG_NO_AES_DECRYPT
-CFLAGS += -DCONFIG_NO_AES_ENCRYPT_BLOCK
+ifdef CONFIG_NO_STDOUT_DEBUG
+CFLAGS += -DCONFIG_NO_STDOUT_DEBUG
endif
ALL=hostapd hostapd_cli
@@ -577,59 +729,63 @@ verify_config:
fi
install: all
- for i in $(ALL); do cp $$i /usr/local/bin/$$i; done
+ for i in $(ALL); do cp -f $$i /usr/local/bin/$$i; done
+
+../src/drivers/build.hostapd:
+ @if [ -f ../src/drivers/build.wpa_supplicant ]; then \
+ $(MAKE) -C ../src/drivers clean; \
+ fi
+ @touch ../src/drivers/build.hostapd
-hostapd: $(OBJS)
- $(CC) -o hostapd $(OBJS) $(LIBS)
+BCHECK=../src/drivers/build.hostapd
+
+hostapd: $(BCHECK) $(OBJS)
+ $(CC) $(LDFLAGS) -o hostapd $(OBJS) $(LIBS)
OBJS_c = hostapd_cli.o ../src/common/wpa_ctrl.o ../src/utils/os_$(CONFIG_OS).o
+ifdef CONFIG_WPA_TRACE
+OBJS_c += ../src/utils/trace.o
+OBJS_c += ../src/utils/wpa_debug.o
+endif
hostapd_cli: $(OBJS_c)
- $(CC) -o hostapd_cli $(OBJS_c)
+ $(CC) $(LDFLAGS) -o hostapd_cli $(OBJS_c) $(LIBS_c)
-NOBJS = nt_password_hash.o ../src/crypto/ms_funcs.o ../src/crypto/sha1.o ../src/crypto/rc4.o ../src/crypto/md5.o
+NOBJS = nt_password_hash.o ../src/crypto/ms_funcs.o $(SHA1OBJS) ../src/crypto/md5.o
+ifdef NEED_RC4
+ifdef CONFIG_INTERNAL_RC4
+NOBJS += ../src/crypto/rc4.o
+endif
+endif
+ifdef CONFIG_INTERNAL_MD5
+NOBJS += ../src/crypto/md5-internal.o
+endif
NOBJS += ../src/crypto/crypto_openssl.o ../src/utils/os_$(CONFIG_OS).o
+NOBJS += ../src/utils/wpa_debug.o
+NOBJS += ../src/utils/wpabuf.o
+ifdef CONFIG_WPA_TRACE
+NOBJS += ../src/utils/trace.o
+LIBS_n += -lbfd
+endif
ifdef TLS_FUNCS
LIBS_n += -lcrypto
endif
+HOBJS += hlr_auc_gw.o ../src/utils/common.o ../src/utils/wpa_debug.o ../src/utils/os_$(CONFIG_OS).o ../src/utils/wpabuf.o ../src/crypto/milenage.o
+HOBJS += ../src/crypto/aes-encblock.o
+ifdef CONFIG_INTERNAL_AES
+HOBJS += ../src/crypto/aes-internal.o
+HOBJS += ../src/crypto/aes-internal-enc.o
+endif
+
nt_password_hash: $(NOBJS)
- $(CC) -o nt_password_hash $(NOBJS) $(LIBS_n)
+ $(CC) $(LDFLAGS) -o nt_password_hash $(NOBJS) $(LIBS_n)
hlr_auc_gw: $(HOBJS)
- $(CC) -o hlr_auc_gw $(HOBJS) $(LIBS_h)
+ $(CC) $(LDFLAGS) -o hlr_auc_gw $(HOBJS) $(LIBS_h)
clean:
$(MAKE) -C ../src clean
rm -f core *~ *.o hostapd hostapd_cli nt_password_hash hlr_auc_gw
rm -f *.d
-%.eps: %.fig
- fig2dev -L eps $*.fig $*.eps
-
-%.png: %.fig
- fig2dev -L png -m 3 $*.fig | pngtopnm | pnmscale 0.4 | pnmtopng \
- > $*.png
-
-docs-pics: doc/hostapd.png doc/hostapd.eps
-
-docs: docs-pics
- (cd ..; doxygen hostapd/doc/doxygen.full; cd hostapd)
- $(MAKE) -C doc/latex
- cp doc/latex/refman.pdf hostapd-devel.pdf
-
-docs-fast: docs-pics
- (cd ..; doxygen hostapd/doc/doxygen.fast; cd hostapd)
-
-clean-docs:
- rm -rf doc/latex doc/html
- rm -f doc/hostapd.{eps,png} hostapd-devel.pdf
-
-TEST_SRC_MILENAGE = ../src/hlr_auc_gw/milenage.c ../src/crypto/aes_wrap.c ../src/crypto/aes.c ../src/utils/common.c ../src/utils/wpa_debug.o ../src/utils/os_$(CONFIG_OS).c
-test-milenage: $(TEST_SRC_MILENAGE)
- $(CC) -o test-milenage -Wall -Werror $(TEST_SRC_MILENAGE) \
- -DTEST_MAIN_MILENAGE -I. -DINTERNAL_AES \
- -I../src/crypto -I../src/utils
- ./test-milenage
- rm test-milenage
-
-include $(OBJS:%.o=%.d)
diff --git a/contrib/wpa/hostapd/README b/contrib/wpa/hostapd/README
index eb9aa48..1af487d 100644
--- a/contrib/wpa/hostapd/README
+++ b/contrib/wpa/hostapd/README
@@ -2,7 +2,7 @@ hostapd - user space IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP
Authenticator and RADIUS authentication server
================================================================
-Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi> and contributors
+Copyright (c) 2002-2010, Jouni Malinen <j@w1.fi> and contributors
All Rights Reserved.
This program is dual-licensed under both the GPL version 2 and BSD
@@ -95,9 +95,6 @@ Current hardware/software requirements:
madwifi driver root directory in .config (see defconfig file for
an example: CFLAGS += -I<path>)
- Prism54 driver for Intersil/Conexant Prism GT/Duette/Indigo
- (http://www.prism54.org/)
-
mac80211-based drivers that support AP mode (with driver=nl80211).
This includes drivers for Atheros (ath9k) and Broadcom (b43)
chipsets.
diff --git a/contrib/wpa/hostapd/README-WPS b/contrib/wpa/hostapd/README-WPS
index e0e370b..74f2113 100644
--- a/contrib/wpa/hostapd/README-WPS
+++ b/contrib/wpa/hostapd/README-WPS
@@ -62,7 +62,6 @@ includes WPS support and uses madwifi driver interface:
CONFIG_DRIVER_MADWIFI=y
CFLAGS += -I/usr/src/madwifi-0.9.3
-CONFIG_EAP=y
CONFIG_WPS=y
CONFIG_WPS_UPNP=y
@@ -196,6 +195,33 @@ which will generate a new WPA PSK in the same way as the PIN method
described above.
+When an external Registrar is used, the AP can act as an Enrollee and
+use its AP PIN. A static AP PIN (e.g., one one a label in the AP
+device) can be configured in hostapd.conf (ap_pin parameter). A more
+secure option is to use hostapd_cli wps_ap_pin command to enable the
+AP PIN only based on user action (and even better security by using a
+random AP PIN for each session, i.e., by using "wps_ap_pin random"
+command with a timeout value). Following commands are available for
+managing the dynamic AP PIN operations:
+
+hostapd_cli wps_ap_pin disable
+- disable AP PIN (i.e., do not allow external Registrars to use it to
+ learn the current AP settings or to reconfigure the AP)
+
+hostapd_cli wps_ap_pin random [timeout]
+- generate a random AP PIN and enable it
+- if the optional timeout parameter is given, the AP PIN will be enabled
+ for the specified number of seconds
+
+hostapd_cli wps_ap_pin get
+- fetch the current AP PIN
+
+hostapd_cli wps_ap_pin set <PIN> [timeout]
+- set the AP PIN and enable it
+- if the optional timeout parameter is given, the AP PIN will be enabled
+ for the specified number of seconds
+
+
Credential generation and configuration changes
-----------------------------------------------
diff --git a/contrib/wpa/hostapd/config.c b/contrib/wpa/hostapd/config_file.c
index 692b1a4..8916b03 100644
--- a/contrib/wpa/hostapd/config.c
+++ b/contrib/wpa/hostapd/config_file.c
@@ -1,7 +1,6 @@
/*
- * hostapd / Configuration file
- * Copyright (c) 2003-2008, Jouni Malinen <j@w1.fi>
- * Copyright (c) 2007-2008, Intel Corporation
+ * hostapd / Configuration file parser
+ * Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -13,27 +12,26 @@
* See README and COPYING for more details.
*/
-#include "includes.h"
+#include "utils/includes.h"
#ifndef CONFIG_NATIVE_WINDOWS
#include <grp.h>
#endif /* CONFIG_NATIVE_WINDOWS */
-#include "hostapd.h"
-#include "driver.h"
-#include "sha1.h"
+#include "utils/common.h"
+#include "utils/uuid.h"
+#include "common/ieee802_11_defs.h"
+#include "drivers/driver.h"
#include "eap_server/eap.h"
#include "radius/radius_client.h"
-#include "wpa_common.h"
-#include "wpa.h"
-#include "uuid.h"
-#include "eap_common/eap_wsc_common.h"
+#include "ap/wpa_auth.h"
+#include "ap/ap_config.h"
+#include "config_file.h"
-#define MAX_STA_COUNT 2007
-
-extern struct wpa_driver_ops *hostapd_drivers[];
+extern struct wpa_driver_ops *wpa_drivers[];
+#ifndef CONFIG_NO_VLAN
static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
const char *fname)
{
@@ -113,168 +111,7 @@ static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
return 0;
}
-
-
-static void hostapd_config_free_vlan(struct hostapd_bss_config *bss)
-{
- struct hostapd_vlan *vlan, *prev;
-
- vlan = bss->vlan;
- prev = NULL;
- while (vlan) {
- prev = vlan;
- vlan = vlan->next;
- os_free(prev);
- }
-
- bss->vlan = NULL;
-}
-
-
-/* convert floats with one decimal place to value*10 int, i.e.,
- * "1.5" will return 15 */
-static int hostapd_config_read_int10(const char *value)
-{
- int i, d;
- char *pos;
-
- i = atoi(value);
- pos = os_strchr(value, '.');
- d = 0;
- if (pos) {
- pos++;
- if (*pos >= '0' && *pos <= '9')
- d = *pos - '0';
- }
-
- return i * 10 + d;
-}
-
-
-static void hostapd_config_defaults_bss(struct hostapd_bss_config *bss)
-{
- bss->logger_syslog_level = HOSTAPD_LEVEL_INFO;
- bss->logger_stdout_level = HOSTAPD_LEVEL_INFO;
- bss->logger_syslog = (unsigned int) -1;
- bss->logger_stdout = (unsigned int) -1;
-
- bss->auth_algs = WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED;
-
- bss->wep_rekeying_period = 300;
- /* use key0 in individual key and key1 in broadcast key */
- bss->broadcast_key_idx_min = 1;
- bss->broadcast_key_idx_max = 2;
- bss->eap_reauth_period = 3600;
-
- bss->wpa_group_rekey = 600;
- bss->wpa_gmk_rekey = 86400;
- bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
- bss->wpa_pairwise = WPA_CIPHER_TKIP;
- bss->wpa_group = WPA_CIPHER_TKIP;
- bss->rsn_pairwise = 0;
-
- bss->max_num_sta = MAX_STA_COUNT;
-
- bss->dtim_period = 2;
-
- bss->radius_server_auth_port = 1812;
- bss->ap_max_inactivity = AP_MAX_INACTIVITY;
- bss->eapol_version = EAPOL_VERSION;
-
- bss->max_listen_interval = 65535;
-
-#ifdef CONFIG_IEEE80211W
- bss->assoc_sa_query_max_timeout = 1000;
- bss->assoc_sa_query_retry_timeout = 201;
-#endif /* CONFIG_IEEE80211W */
-#ifdef EAP_FAST
- /* both anonymous and authenticated provisioning */
- bss->eap_fast_prov = 3;
- bss->pac_key_lifetime = 7 * 24 * 60 * 60;
- bss->pac_key_refresh_time = 1 * 24 * 60 * 60;
-#endif /* EAP_FAST */
-}
-
-
-static struct hostapd_config * hostapd_config_defaults(void)
-{
- struct hostapd_config *conf;
- struct hostapd_bss_config *bss;
- int i;
- const int aCWmin = 4, aCWmax = 10;
- const struct hostapd_wmm_ac_params ac_bk =
- { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
- const struct hostapd_wmm_ac_params ac_be =
- { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
- const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
- { aCWmin - 1, aCWmin, 2, 3000 / 32, 1 };
- const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
- { aCWmin - 2, aCWmin - 1, 2, 1500 / 32, 1 };
-
- conf = os_zalloc(sizeof(*conf));
- bss = os_zalloc(sizeof(*bss));
- if (conf == NULL || bss == NULL) {
- wpa_printf(MSG_ERROR, "Failed to allocate memory for "
- "configuration data.");
- os_free(conf);
- os_free(bss);
- return NULL;
- }
-
- /* set default driver based on configuration */
- conf->driver = hostapd_drivers[0];
- if (conf->driver == NULL) {
- wpa_printf(MSG_ERROR, "No driver wrappers registered!");
- os_free(conf);
- os_free(bss);
- return NULL;
- }
-
- bss->radius = os_zalloc(sizeof(*bss->radius));
- if (bss->radius == NULL) {
- os_free(conf);
- os_free(bss);
- return NULL;
- }
-
- hostapd_config_defaults_bss(bss);
-
- conf->num_bss = 1;
- conf->bss = bss;
-
- conf->beacon_int = 100;
- conf->rts_threshold = -1; /* use driver default: 2347 */
- conf->fragm_threshold = -1; /* user driver default: 2346 */
- conf->send_probe_response = 1;
- conf->bridge_packets = INTERNAL_BRIDGE_DO_NOT_CONTROL;
-
- for (i = 0; i < NUM_TX_QUEUES; i++)
- conf->tx_queue[i].aifs = -1; /* use hw default */
-
- conf->wmm_ac_params[0] = ac_be;
- conf->wmm_ac_params[1] = ac_bk;
- conf->wmm_ac_params[2] = ac_vi;
- conf->wmm_ac_params[3] = ac_vo;
-
-#ifdef CONFIG_IEEE80211N
- conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED;
-#endif /* CONFIG_IEEE80211N */
-
- return conf;
-}
-
-
-int hostapd_mac_comp(const void *a, const void *b)
-{
- return os_memcmp(a, b, sizeof(macaddr));
-}
-
-
-int hostapd_mac_comp_empty(const void *a)
-{
- macaddr empty = { 0 };
- return os_memcmp(a, empty, sizeof(macaddr));
-}
+#endif /* CONFIG_NO_VLAN */
static int hostapd_acl_comp(const void *a, const void *b)
@@ -357,133 +194,6 @@ static int hostapd_config_read_maclist(const char *fname,
}
-static int hostapd_config_read_wpa_psk(const char *fname,
- struct hostapd_ssid *ssid)
-{
- FILE *f;
- char buf[128], *pos;
- int line = 0, ret = 0, len, ok;
- u8 addr[ETH_ALEN];
- struct hostapd_wpa_psk *psk;
-
- if (!fname)
- return 0;
-
- f = fopen(fname, "r");
- if (!f) {
- wpa_printf(MSG_ERROR, "WPA PSK file '%s' not found.", fname);
- return -1;
- }
-
- while (fgets(buf, sizeof(buf), f)) {
- line++;
-
- if (buf[0] == '#')
- continue;
- pos = buf;
- while (*pos != '\0') {
- if (*pos == '\n') {
- *pos = '\0';
- break;
- }
- pos++;
- }
- if (buf[0] == '\0')
- continue;
-
- if (hwaddr_aton(buf, addr)) {
- wpa_printf(MSG_ERROR, "Invalid MAC address '%s' on "
- "line %d in '%s'", buf, line, fname);
- ret = -1;
- break;
- }
-
- psk = os_zalloc(sizeof(*psk));
- if (psk == NULL) {
- wpa_printf(MSG_ERROR, "WPA PSK allocation failed");
- ret = -1;
- break;
- }
- if (is_zero_ether_addr(addr))
- psk->group = 1;
- else
- os_memcpy(psk->addr, addr, ETH_ALEN);
-
- pos = buf + 17;
- if (*pos == '\0') {
- wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'",
- line, fname);
- os_free(psk);
- ret = -1;
- break;
- }
- pos++;
-
- ok = 0;
- len = os_strlen(pos);
- if (len == 64 && hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
- ok = 1;
- else if (len >= 8 && len < 64) {
- pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
- 4096, psk->psk, PMK_LEN);
- ok = 1;
- }
- if (!ok) {
- wpa_printf(MSG_ERROR, "Invalid PSK '%s' on line %d in "
- "'%s'", pos, line, fname);
- os_free(psk);
- ret = -1;
- break;
- }
-
- psk->next = ssid->wpa_psk;
- ssid->wpa_psk = psk;
- }
-
- fclose(f);
-
- return ret;
-}
-
-
-int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
-{
- struct hostapd_ssid *ssid = &conf->ssid;
-
- if (ssid->wpa_passphrase != NULL) {
- if (ssid->wpa_psk != NULL) {
- wpa_printf(MSG_ERROR, "Warning: both WPA PSK and "
- "passphrase set. Using passphrase.");
- os_free(ssid->wpa_psk);
- }
- ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
- if (ssid->wpa_psk == NULL) {
- wpa_printf(MSG_ERROR, "Unable to alloc space for PSK");
- return -1;
- }
- wpa_hexdump_ascii(MSG_DEBUG, "SSID",
- (u8 *) ssid->ssid, ssid->ssid_len);
- wpa_hexdump_ascii(MSG_DEBUG, "PSK (ASCII passphrase)",
- (u8 *) ssid->wpa_passphrase,
- os_strlen(ssid->wpa_passphrase));
- pbkdf2_sha1(ssid->wpa_passphrase,
- ssid->ssid, ssid->ssid_len,
- 4096, ssid->wpa_psk->psk, PMK_LEN);
- wpa_hexdump(MSG_DEBUG, "PSK (from passphrase)",
- ssid->wpa_psk->psk, PMK_LEN);
- ssid->wpa_psk->group = 1;
- }
-
- if (ssid->wpa_psk_file) {
- if (hostapd_config_read_wpa_psk(ssid->wpa_psk_file,
- &conf->ssid))
- return -1;
- }
-
- return 0;
-}
-
-
#ifdef EAP_SERVER
static int hostapd_config_read_eap_user(const char *fname,
struct hostapd_bss_config *conf)
@@ -761,6 +471,7 @@ static int hostapd_config_read_eap_user(const char *fname,
#endif /* EAP_SERVER */
+#ifndef CONFIG_NO_RADIUS
static int
hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
int *num_server, const char *val, int def_port,
@@ -786,6 +497,7 @@ hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
return ret;
}
+#endif /* CONFIG_NO_RADIUS */
static int hostapd_config_parse_key_mgmt(int line, const char *value)
@@ -899,86 +611,6 @@ static int hostapd_config_parse_cipher(int line, const char *value)
}
-static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
- struct hostapd_config *conf)
-{
- if (bss->ieee802_1x && !bss->eap_server &&
- !bss->radius->auth_servers) {
- wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
- "EAP authenticator configured).");
- return -1;
- }
-
- if (bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
- bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
- bss->ssid.wpa_psk_file == NULL) {
- wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
- "is not configured.");
- return -1;
- }
-
- if (hostapd_mac_comp_empty(bss->bssid) != 0) {
- size_t i;
-
- for (i = 0; i < conf->num_bss; i++) {
- if ((&conf->bss[i] != bss) &&
- (hostapd_mac_comp(conf->bss[i].bssid,
- bss->bssid) == 0)) {
- wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
- " on interface '%s' and '%s'.",
- MAC2STR(bss->bssid),
- conf->bss[i].iface, bss->iface);
- return -1;
- }
- }
- }
-
-#ifdef CONFIG_IEEE80211R
- if ((bss->wpa_key_mgmt &
- (WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X)) &&
- (bss->nas_identifier == NULL ||
- os_strlen(bss->nas_identifier) < 1 ||
- os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
- wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
- "nas_identifier to be configured as a 1..48 octet "
- "string");
- return -1;
- }
-#endif /* CONFIG_IEEE80211R */
-
-#ifdef CONFIG_IEEE80211N
- if (conf->ieee80211n && bss->wpa &&
- !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
- !(bss->rsn_pairwise & WPA_CIPHER_CCMP)) {
- wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
- "requires CCMP to be enabled");
- return -1;
- }
-#endif /* CONFIG_IEEE80211N */
-
- return 0;
-}
-
-
-static int hostapd_config_check(struct hostapd_config *conf)
-{
- size_t i;
-
- if (conf->ieee80211d && (!conf->country[0] || !conf->country[1])) {
- wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
- "setting the country_code");
- return -1;
- }
-
- for (i = 0; i < conf->num_bss; i++) {
- if (hostapd_config_check_bss(&conf->bss[i], conf))
- return -1;
- }
-
- return 0;
-}
-
-
static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
char *val)
{
@@ -1089,6 +721,26 @@ static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
}
+/* convert floats with one decimal place to value*10 int, i.e.,
+ * "1.5" will return 15 */
+static int hostapd_config_read_int10(const char *value)
+{
+ int i, d;
+ char *pos;
+
+ i = atoi(value);
+ pos = os_strchr(value, '.');
+ d = 0;
+ if (pos) {
+ pos++;
+ if (*pos >= '0' && *pos <= '9')
+ d = *pos - '0';
+ }
+
+ return i * 10 + d;
+}
+
+
static int valid_cw(int cw)
{
return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 ||
@@ -1389,6 +1041,86 @@ static int hostapd_config_ht_capab(struct hostapd_config *conf,
#endif /* CONFIG_IEEE80211N */
+static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
+ struct hostapd_config *conf)
+{
+ if (bss->ieee802_1x && !bss->eap_server &&
+ !bss->radius->auth_servers) {
+ wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
+ "EAP authenticator configured).");
+ return -1;
+ }
+
+ if (bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
+ bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
+ bss->ssid.wpa_psk_file == NULL) {
+ wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
+ "is not configured.");
+ return -1;
+ }
+
+ if (hostapd_mac_comp_empty(bss->bssid) != 0) {
+ size_t i;
+
+ for (i = 0; i < conf->num_bss; i++) {
+ if ((&conf->bss[i] != bss) &&
+ (hostapd_mac_comp(conf->bss[i].bssid,
+ bss->bssid) == 0)) {
+ wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
+ " on interface '%s' and '%s'.",
+ MAC2STR(bss->bssid),
+ conf->bss[i].iface, bss->iface);
+ return -1;
+ }
+ }
+ }
+
+#ifdef CONFIG_IEEE80211R
+ if ((bss->wpa_key_mgmt &
+ (WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X)) &&
+ (bss->nas_identifier == NULL ||
+ os_strlen(bss->nas_identifier) < 1 ||
+ os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
+ wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
+ "nas_identifier to be configured as a 1..48 octet "
+ "string");
+ return -1;
+ }
+#endif /* CONFIG_IEEE80211R */
+
+#ifdef CONFIG_IEEE80211N
+ if (conf->ieee80211n && bss->wpa &&
+ !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
+ !(bss->rsn_pairwise & WPA_CIPHER_CCMP)) {
+ wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
+ "requires CCMP to be enabled");
+ return -1;
+ }
+#endif /* CONFIG_IEEE80211N */
+
+ return 0;
+}
+
+
+static int hostapd_config_check(struct hostapd_config *conf)
+{
+ size_t i;
+
+ if (conf->ieee80211d && (!conf->country[0] || !conf->country[1])) {
+ wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
+ "setting the country_code");
+ return -1;
+ }
+
+ for (i = 0; i < conf->num_bss; i++) {
+ if (hostapd_config_check_bss(&conf->bss[i], conf))
+ return -1;
+ }
+
+ return 0;
+}
+
+
/**
* hostapd_config_read - Read and parse a configuration file
* @fname: Configuration file name (including path, if needed)
@@ -1417,6 +1149,16 @@ struct hostapd_config * hostapd_config_read(const char *fname)
fclose(f);
return NULL;
}
+
+ /* set default driver based on configuration */
+ conf->driver = wpa_drivers[0];
+ if (conf->driver == NULL) {
+ wpa_printf(MSG_ERROR, "No driver wrappers registered!");
+ hostapd_config_free(conf);
+ fclose(f);
+ return NULL;
+ }
+
bss = conf->last_bss = conf->bss;
while (fgets(buf, sizeof(buf), f)) {
@@ -1455,10 +1197,10 @@ struct hostapd_config * hostapd_config_read(const char *fname)
int j;
/* clear to get error below if setting is invalid */
conf->driver = NULL;
- for (j = 0; hostapd_drivers[j]; j++) {
- if (os_strcmp(pos, hostapd_drivers[j]->name) ==
- 0) {
- conf->driver = hostapd_drivers[j];
+ for (j = 0; wpa_drivers[j]; j++) {
+ if (os_strcmp(pos, wpa_drivers[j]->name) == 0)
+ {
+ conf->driver = wpa_drivers[j];
break;
}
}
@@ -1520,6 +1262,8 @@ struct hostapd_config * hostapd_config_read(const char *fname)
line, pos);
errors++;
}
+ } else if (os_strcmp(buf, "wds_sta") == 0) {
+ bss->wds_sta = atoi(pos);
} else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
bss->ap_max_inactivity = atoi(pos);
} else if (os_strcmp(buf, "country_code") == 0) {
@@ -1569,7 +1313,7 @@ struct hostapd_config * hostapd_config_read(const char *fname)
} else if (os_strcmp(buf, "dh_file") == 0) {
os_free(bss->dh_file);
bss->dh_file = os_strdup(pos);
-#ifdef EAP_FAST
+#ifdef EAP_SERVER_FAST
} else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
os_free(bss->pac_opaque_encr_key);
bss->pac_opaque_encr_key = os_malloc(16);
@@ -1611,18 +1355,18 @@ struct hostapd_config * hostapd_config_read(const char *fname)
bss->pac_key_lifetime = atoi(pos);
} else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
bss->pac_key_refresh_time = atoi(pos);
-#endif /* EAP_FAST */
-#ifdef EAP_SIM
+#endif /* EAP_SERVER_FAST */
+#ifdef EAP_SERVER_SIM
} else if (os_strcmp(buf, "eap_sim_db") == 0) {
os_free(bss->eap_sim_db);
bss->eap_sim_db = os_strdup(pos);
} else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
bss->eap_sim_aka_result_ind = atoi(pos);
-#endif /* EAP_SIM */
-#ifdef EAP_TNC
+#endif /* EAP_SERVER_SIM */
+#ifdef EAP_SERVER_TNC
} else if (os_strcmp(buf, "tnc") == 0) {
bss->tnc = atoi(pos);
-#endif /* EAP_TNC */
+#endif /* EAP_SERVER_TNC */
#endif /* EAP_SERVER */
} else if (os_strcmp(buf, "eap_message") == 0) {
char *term;
@@ -1697,6 +1441,7 @@ struct hostapd_config * hostapd_config_read(const char *fname)
}
} else if (os_strcmp(buf, "nas_identifier") == 0) {
bss->nas_identifier = os_strdup(pos);
+#ifndef CONFIG_NO_RADIUS
} else if (os_strcmp(buf, "auth_server_addr") == 0) {
if (hostapd_config_read_radius_addr(
&bss->radius->auth_servers,
@@ -1750,7 +1495,8 @@ struct hostapd_config * hostapd_config_read(const char *fname)
bss->radius->retry_primary_interval = atoi(pos);
} else if (os_strcmp(buf, "radius_acct_interim_interval") == 0)
{
- bss->radius->acct_interim_interval = atoi(pos);
+ bss->acct_interim_interval = atoi(pos);
+#endif /* CONFIG_NO_RADIUS */
} else if (os_strcmp(buf, "auth_algs") == 0) {
bss->auth_algs = atoi(pos);
if (bss->auth_algs == 0) {
@@ -1896,6 +1642,7 @@ struct hostapd_config * hostapd_config_read(const char *fname)
} else if (os_strcmp(buf, "pmk_r1_push") == 0) {
bss->pmk_r1_push = atoi(pos);
#endif /* CONFIG_IEEE80211R */
+#ifndef CONFIG_NO_CTRL_IFACE
} else if (os_strcmp(buf, "ctrl_interface") == 0) {
os_free(bss->ctrl_interface);
bss->ctrl_interface = os_strdup(pos);
@@ -1927,6 +1674,7 @@ struct hostapd_config * hostapd_config_read(const char *fname)
wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
bss->ctrl_interface_gid);
#endif /* CONFIG_NATIVE_WINDOWS */
+#endif /* CONFIG_NO_CTRL_IFACE */
#ifdef RADIUS_SERVER
} else if (os_strcmp(buf, "radius_server_clients") == 0) {
os_free(bss->radius_server_clients);
@@ -2022,8 +1770,6 @@ struct hostapd_config * hostapd_config_read(const char *fname)
conf->preamble = LONG_PREAMBLE;
} else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
bss->ignore_broadcast_ssid = atoi(pos);
- } else if (os_strcmp(buf, "bridge_packets") == 0) {
- conf->bridge_packets = atoi(pos);
} else if (os_strcmp(buf, "wep_default_key") == 0) {
bss->ssid.wep.idx = atoi(pos);
if (bss->ssid.wep.idx > 3) {
@@ -2042,6 +1788,7 @@ struct hostapd_config * hostapd_config_read(const char *fname)
"key '%s'", line, buf);
errors++;
}
+#ifndef CONFIG_NO_VLAN
} else if (os_strcmp(buf, "dynamic_vlan") == 0) {
bss->ssid.dynamic_vlan = atoi(pos);
} else if (os_strcmp(buf, "vlan_file") == 0) {
@@ -2054,12 +1801,7 @@ struct hostapd_config * hostapd_config_read(const char *fname)
} else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
bss->ssid.vlan_tagged_interface = os_strdup(pos);
#endif /* CONFIG_FULL_DYNAMIC_VLAN */
- } else if (os_strcmp(buf, "passive_scan_interval") == 0) {
- conf->passive_scan_interval = atoi(pos);
- } else if (os_strcmp(buf, "passive_scan_listen") == 0) {
- conf->passive_scan_listen = atoi(pos);
- } else if (os_strcmp(buf, "passive_scan_mode") == 0) {
- conf->passive_scan_mode = atoi(pos);
+#endif /* CONFIG_NO_VLAN */
} else if (os_strcmp(buf, "ap_table_max_size") == 0) {
conf->ap_table_max_size = atoi(pos);
} else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
@@ -2073,6 +1815,8 @@ struct hostapd_config * hostapd_config_read(const char *fname)
} else if (os_strcmp(buf, "wme_enabled") == 0 ||
os_strcmp(buf, "wmm_enabled") == 0) {
bss->wmm_enabled = atoi(pos);
+ } else if (os_strcmp(buf, "uapsd_advertisement_enabled") == 0) {
+ bss->wmm_uapsd = atoi(pos);
} else if (os_strncmp(buf, "wme_ac_", 7) == 0 ||
os_strncmp(buf, "wmm_ac_", 7) == 0) {
if (hostapd_config_wmm_ac(conf, buf, pos)) {
@@ -2087,13 +1831,7 @@ struct hostapd_config * hostapd_config_read(const char *fname)
errors++;
}
} else if (os_strcmp(buf, "bssid") == 0) {
- if (bss == conf->bss &&
- (!conf->driver || !conf->driver->init_bssid)) {
- wpa_printf(MSG_ERROR, "Line %d: bssid item "
- "not allowed for the default "
- "interface and this driver", line);
- errors++;
- } else if (hwaddr_aton(pos, bss->bssid)) {
+ if (hwaddr_aton(pos, bss->bssid)) {
wpa_printf(MSG_ERROR, "Line %d: invalid bssid "
"item", line);
errors++;
@@ -2309,314 +2047,3 @@ struct hostapd_config * hostapd_config_read(const char *fname)
return conf;
}
-
-
-int hostapd_wep_key_cmp(struct hostapd_wep_keys *a, struct hostapd_wep_keys *b)
-{
- int i;
-
- if (a->idx != b->idx || a->default_len != b->default_len)
- return 1;
- for (i = 0; i < NUM_WEP_KEYS; i++)
- if (a->len[i] != b->len[i] ||
- os_memcmp(a->key[i], b->key[i], a->len[i]) != 0)
- return 1;
- return 0;
-}
-
-
-static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
- int num_servers)
-{
- int i;
-
- for (i = 0; i < num_servers; i++) {
- os_free(servers[i].shared_secret);
- }
- os_free(servers);
-}
-
-
-static void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
-{
- os_free(user->identity);
- os_free(user->password);
- os_free(user);
-}
-
-
-static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
-{
- int i;
- for (i = 0; i < NUM_WEP_KEYS; i++) {
- os_free(keys->key[i]);
- keys->key[i] = NULL;
- }
-}
-
-
-static void hostapd_config_free_bss(struct hostapd_bss_config *conf)
-{
- struct hostapd_wpa_psk *psk, *prev;
- struct hostapd_eap_user *user, *prev_user;
-
- if (conf == NULL)
- return;
-
- psk = conf->ssid.wpa_psk;
- while (psk) {
- prev = psk;
- psk = psk->next;
- os_free(prev);
- }
-
- os_free(conf->ssid.wpa_passphrase);
- os_free(conf->ssid.wpa_psk_file);
-#ifdef CONFIG_FULL_DYNAMIC_VLAN
- os_free(conf->ssid.vlan_tagged_interface);
-#endif /* CONFIG_FULL_DYNAMIC_VLAN */
-
- user = conf->eap_user;
- while (user) {
- prev_user = user;
- user = user->next;
- hostapd_config_free_eap_user(prev_user);
- }
-
- os_free(conf->dump_log_name);
- os_free(conf->eap_req_id_text);
- os_free(conf->accept_mac);
- os_free(conf->deny_mac);
- os_free(conf->nas_identifier);
- hostapd_config_free_radius(conf->radius->auth_servers,
- conf->radius->num_auth_servers);
- hostapd_config_free_radius(conf->radius->acct_servers,
- conf->radius->num_acct_servers);
- os_free(conf->rsn_preauth_interfaces);
- os_free(conf->ctrl_interface);
- os_free(conf->ca_cert);
- os_free(conf->server_cert);
- os_free(conf->private_key);
- os_free(conf->private_key_passwd);
- os_free(conf->dh_file);
- os_free(conf->pac_opaque_encr_key);
- os_free(conf->eap_fast_a_id);
- os_free(conf->eap_fast_a_id_info);
- os_free(conf->eap_sim_db);
- os_free(conf->radius_server_clients);
- os_free(conf->test_socket);
- os_free(conf->radius);
- hostapd_config_free_vlan(conf);
- if (conf->ssid.dyn_vlan_keys) {
- struct hostapd_ssid *ssid = &conf->ssid;
- size_t i;
- for (i = 0; i <= ssid->max_dyn_vlan_keys; i++) {
- if (ssid->dyn_vlan_keys[i] == NULL)
- continue;
- hostapd_config_free_wep(ssid->dyn_vlan_keys[i]);
- os_free(ssid->dyn_vlan_keys[i]);
- }
- os_free(ssid->dyn_vlan_keys);
- ssid->dyn_vlan_keys = NULL;
- }
-
-#ifdef CONFIG_IEEE80211R
- {
- struct ft_remote_r0kh *r0kh, *r0kh_prev;
- struct ft_remote_r1kh *r1kh, *r1kh_prev;
-
- r0kh = conf->r0kh_list;
- conf->r0kh_list = NULL;
- while (r0kh) {
- r0kh_prev = r0kh;
- r0kh = r0kh->next;
- os_free(r0kh_prev);
- }
-
- r1kh = conf->r1kh_list;
- conf->r1kh_list = NULL;
- while (r1kh) {
- r1kh_prev = r1kh;
- r1kh = r1kh->next;
- os_free(r1kh_prev);
- }
- }
-#endif /* CONFIG_IEEE80211R */
-
-#ifdef CONFIG_WPS
- os_free(conf->wps_pin_requests);
- os_free(conf->device_name);
- os_free(conf->manufacturer);
- os_free(conf->model_name);
- os_free(conf->model_number);
- os_free(conf->serial_number);
- os_free(conf->device_type);
- os_free(conf->config_methods);
- os_free(conf->ap_pin);
- os_free(conf->extra_cred);
- os_free(conf->ap_settings);
- os_free(conf->upnp_iface);
- os_free(conf->friendly_name);
- os_free(conf->manufacturer_url);
- os_free(conf->model_description);
- os_free(conf->model_url);
- os_free(conf->upc);
-#endif /* CONFIG_WPS */
-}
-
-
-/**
- * hostapd_config_free - Free hostapd configuration
- * @conf: Configuration data from hostapd_config_read().
- */
-void hostapd_config_free(struct hostapd_config *conf)
-{
- size_t i;
-
- if (conf == NULL)
- return;
-
- for (i = 0; i < conf->num_bss; i++)
- hostapd_config_free_bss(&conf->bss[i]);
- os_free(conf->bss);
- os_free(conf->supported_rates);
- os_free(conf->basic_rates);
-
- os_free(conf);
-}
-
-
-/**
- * hostapd_maclist_found - Find a MAC address from a list
- * @list: MAC address list
- * @num_entries: Number of addresses in the list
- * @addr: Address to search for
- * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
- * Returns: 1 if address is in the list or 0 if not.
- *
- * Perform a binary search for given MAC address from a pre-sorted list.
- */
-int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
- const u8 *addr, int *vlan_id)
-{
- int start, end, middle, res;
-
- start = 0;
- end = num_entries - 1;
-
- while (start <= end) {
- middle = (start + end) / 2;
- res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
- if (res == 0) {
- if (vlan_id)
- *vlan_id = list[middle].vlan_id;
- return 1;
- }
- if (res < 0)
- start = middle + 1;
- else
- end = middle - 1;
- }
-
- return 0;
-}
-
-
-int hostapd_rate_found(int *list, int rate)
-{
- int i;
-
- if (list == NULL)
- return 0;
-
- for (i = 0; list[i] >= 0; i++)
- if (list[i] == rate)
- return 1;
-
- return 0;
-}
-
-
-const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
-{
- struct hostapd_vlan *v = vlan;
- while (v) {
- if (v->vlan_id == vlan_id || v->vlan_id == VLAN_ID_WILDCARD)
- return v->ifname;
- v = v->next;
- }
- return NULL;
-}
-
-
-const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
- const u8 *addr, const u8 *prev_psk)
-{
- struct hostapd_wpa_psk *psk;
- int next_ok = prev_psk == NULL;
-
- for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
- if (next_ok &&
- (psk->group || os_memcmp(psk->addr, addr, ETH_ALEN) == 0))
- return psk->psk;
-
- if (psk->psk == prev_psk)
- next_ok = 1;
- }
-
- return NULL;
-}
-
-
-const struct hostapd_eap_user *
-hostapd_get_eap_user(const struct hostapd_bss_config *conf, const u8 *identity,
- size_t identity_len, int phase2)
-{
- struct hostapd_eap_user *user = conf->eap_user;
-
-#ifdef CONFIG_WPS
- if (conf->wps_state && identity_len == WSC_ID_ENROLLEE_LEN &&
- os_memcmp(identity, WSC_ID_ENROLLEE, WSC_ID_ENROLLEE_LEN) == 0) {
- static struct hostapd_eap_user wsc_enrollee;
- os_memset(&wsc_enrollee, 0, sizeof(wsc_enrollee));
- wsc_enrollee.methods[0].method = eap_server_get_type(
- "WSC", &wsc_enrollee.methods[0].vendor);
- return &wsc_enrollee;
- }
-
- if (conf->wps_state && conf->ap_pin &&
- identity_len == WSC_ID_REGISTRAR_LEN &&
- os_memcmp(identity, WSC_ID_REGISTRAR, WSC_ID_REGISTRAR_LEN) == 0) {
- static struct hostapd_eap_user wsc_registrar;
- os_memset(&wsc_registrar, 0, sizeof(wsc_registrar));
- wsc_registrar.methods[0].method = eap_server_get_type(
- "WSC", &wsc_registrar.methods[0].vendor);
- wsc_registrar.password = (u8 *) conf->ap_pin;
- wsc_registrar.password_len = os_strlen(conf->ap_pin);
- return &wsc_registrar;
- }
-#endif /* CONFIG_WPS */
-
- while (user) {
- if (!phase2 && user->identity == NULL) {
- /* Wildcard match */
- break;
- }
-
- if (user->phase2 == !!phase2 && user->wildcard_prefix &&
- identity_len >= user->identity_len &&
- os_memcmp(user->identity, identity, user->identity_len) ==
- 0) {
- /* Wildcard prefix match */
- break;
- }
-
- if (user->phase2 == !!phase2 &&
- user->identity_len == identity_len &&
- os_memcmp(user->identity, identity, identity_len) == 0)
- break;
- user = user->next;
- }
-
- return user;
-}
diff --git a/contrib/wpa/hostapd/config_file.h b/contrib/wpa/hostapd/config_file.h
new file mode 100644
index 0000000..7111a9a
--- /dev/null
+++ b/contrib/wpa/hostapd/config_file.h
@@ -0,0 +1,20 @@
+/*
+ * hostapd / Configuration file parser
+ * Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef CONFIG_FILE_H
+#define CONFIG_FILE_H
+
+struct hostapd_config * hostapd_config_read(const char *fname);
+
+#endif /* CONFIG_FILE_H */
diff --git a/contrib/wpa/hostapd/ctrl_iface.c b/contrib/wpa/hostapd/ctrl_iface.c
index 9dec724..9c47ba8 100644
--- a/contrib/wpa/hostapd/ctrl_iface.c
+++ b/contrib/wpa/hostapd/ctrl_iface.c
@@ -1,6 +1,6 @@
/*
* hostapd / UNIX domain socket -based control interface
- * Copyright (c) 2004-2008, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -12,7 +12,7 @@
* See README and COPYING for more details.
*/
-#include "includes.h"
+#include "utils/includes.h"
#ifndef CONFIG_NATIVE_WINDOWS
@@ -20,17 +20,21 @@
#include <sys/stat.h>
#include <stddef.h>
-#include "hostapd.h"
-#include "eloop.h"
-#include "config.h"
-#include "ieee802_1x.h"
-#include "wpa.h"
+#include "utils/common.h"
+#include "utils/eloop.h"
+#include "common/ieee802_11_defs.h"
+#include "drivers/driver.h"
#include "radius/radius_client.h"
-#include "ieee802_11.h"
+#include "ap/hostapd.h"
+#include "ap/ap_config.h"
+#include "ap/ieee802_1x.h"
+#include "ap/wpa_auth.h"
+#include "ap/ieee802_11.h"
+#include "ap/sta_info.h"
+#include "ap/accounting.h"
+#include "ap/wps_hostapd.h"
+#include "ap/ctrl_iface_ap.h"
#include "ctrl_iface.h"
-#include "sta_info.h"
-#include "accounting.h"
-#include "wps_hostapd.h"
struct wpa_ctrl_dst {
@@ -125,111 +129,126 @@ static int hostapd_ctrl_iface_level(struct hostapd_data *hapd,
}
-static int hostapd_ctrl_iface_sta_mib(struct hostapd_data *hapd,
- struct sta_info *sta,
- char *buf, size_t buflen)
+static int hostapd_ctrl_iface_new_sta(struct hostapd_data *hapd,
+ const char *txtaddr)
{
- int len, res, ret;
+ u8 addr[ETH_ALEN];
+ struct sta_info *sta;
- if (sta == NULL) {
- ret = os_snprintf(buf, buflen, "FAIL\n");
- if (ret < 0 || (size_t) ret >= buflen)
- return 0;
- return ret;
- }
+ wpa_printf(MSG_DEBUG, "CTRL_IFACE NEW_STA %s", txtaddr);
- len = 0;
- ret = os_snprintf(buf + len, buflen - len, MACSTR "\n",
- MAC2STR(sta->addr));
- if (ret < 0 || (size_t) ret >= buflen - len)
- return len;
- len += ret;
-
- res = ieee802_11_get_mib_sta(hapd, sta, buf + len, buflen - len);
- if (res >= 0)
- len += res;
- res = wpa_get_mib_sta(sta->wpa_sm, buf + len, buflen - len);
- if (res >= 0)
- len += res;
- res = ieee802_1x_get_mib_sta(hapd, sta, buf + len, buflen - len);
- if (res >= 0)
- len += res;
-
- return len;
-}
+ if (hwaddr_aton(txtaddr, addr))
+ return -1;
+ sta = ap_get_sta(hapd, addr);
+ if (sta)
+ return 0;
-static int hostapd_ctrl_iface_sta_first(struct hostapd_data *hapd,
- char *buf, size_t buflen)
-{
- return hostapd_ctrl_iface_sta_mib(hapd, hapd->sta_list, buf, buflen);
+ wpa_printf(MSG_DEBUG, "Add new STA " MACSTR " based on ctrl_iface "
+ "notification", MAC2STR(addr));
+ sta = ap_sta_add(hapd, addr);
+ if (sta == NULL)
+ return -1;
+
+ hostapd_new_assoc_sta(hapd, sta, 0);
+ return 0;
}
-static int hostapd_ctrl_iface_sta(struct hostapd_data *hapd,
- const char *txtaddr,
- char *buf, size_t buflen)
+static int hostapd_ctrl_iface_deauthenticate(struct hostapd_data *hapd,
+ const char *txtaddr)
{
u8 addr[ETH_ALEN];
- int ret;
+ struct sta_info *sta;
+ const char *pos;
- if (hwaddr_aton(txtaddr, addr)) {
- ret = os_snprintf(buf, buflen, "FAIL\n");
- if (ret < 0 || (size_t) ret >= buflen)
- return 0;
- return ret;
- }
- return hostapd_ctrl_iface_sta_mib(hapd, ap_get_sta(hapd, addr),
- buf, buflen);
-}
+ wpa_printf(MSG_DEBUG, "CTRL_IFACE DEAUTHENTICATE %s", txtaddr);
+ if (hwaddr_aton(txtaddr, addr))
+ return -1;
-static int hostapd_ctrl_iface_sta_next(struct hostapd_data *hapd,
- const char *txtaddr,
- char *buf, size_t buflen)
-{
- u8 addr[ETH_ALEN];
- struct sta_info *sta;
- int ret;
+ pos = os_strstr(txtaddr, " test=");
+ if (pos) {
+ struct ieee80211_mgmt mgmt;
+ int encrypt;
+ if (hapd->driver->send_frame == NULL)
+ return -1;
+ pos += 6;
+ encrypt = atoi(pos);
+ os_memset(&mgmt, 0, sizeof(mgmt));
+ mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
+ WLAN_FC_STYPE_DEAUTH);
+ os_memcpy(mgmt.da, addr, ETH_ALEN);
+ os_memcpy(mgmt.sa, hapd->own_addr, ETH_ALEN);
+ os_memcpy(mgmt.bssid, hapd->own_addr, ETH_ALEN);
+ mgmt.u.deauth.reason_code =
+ host_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID);
+ if (hapd->driver->send_frame(hapd->drv_priv, (u8 *) &mgmt,
+ IEEE80211_HDRLEN +
+ sizeof(mgmt.u.deauth),
+ encrypt) < 0)
+ return -1;
+ return 0;
+ }
- if (hwaddr_aton(txtaddr, addr) ||
- (sta = ap_get_sta(hapd, addr)) == NULL) {
- ret = os_snprintf(buf, buflen, "FAIL\n");
- if (ret < 0 || (size_t) ret >= buflen)
- return 0;
- return ret;
- }
- return hostapd_ctrl_iface_sta_mib(hapd, sta->next, buf, buflen);
+ hapd->drv.sta_deauth(hapd, addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
+ sta = ap_get_sta(hapd, addr);
+ if (sta)
+ ap_sta_deauthenticate(hapd, sta,
+ WLAN_REASON_PREV_AUTH_NOT_VALID);
+
+ return 0;
}
-static int hostapd_ctrl_iface_new_sta(struct hostapd_data *hapd,
- const char *txtaddr)
+static int hostapd_ctrl_iface_disassociate(struct hostapd_data *hapd,
+ const char *txtaddr)
{
u8 addr[ETH_ALEN];
struct sta_info *sta;
+ const char *pos;
- wpa_printf(MSG_DEBUG, "CTRL_IFACE NEW_STA %s", txtaddr);
+ wpa_printf(MSG_DEBUG, "CTRL_IFACE DISASSOCIATE %s", txtaddr);
if (hwaddr_aton(txtaddr, addr))
return -1;
- sta = ap_get_sta(hapd, addr);
- if (sta)
+ pos = os_strstr(txtaddr, " test=");
+ if (pos) {
+ struct ieee80211_mgmt mgmt;
+ int encrypt;
+ if (hapd->driver->send_frame == NULL)
+ return -1;
+ pos += 6;
+ encrypt = atoi(pos);
+ os_memset(&mgmt, 0, sizeof(mgmt));
+ mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
+ WLAN_FC_STYPE_DISASSOC);
+ os_memcpy(mgmt.da, addr, ETH_ALEN);
+ os_memcpy(mgmt.sa, hapd->own_addr, ETH_ALEN);
+ os_memcpy(mgmt.bssid, hapd->own_addr, ETH_ALEN);
+ mgmt.u.disassoc.reason_code =
+ host_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID);
+ if (hapd->driver->send_frame(hapd->drv_priv, (u8 *) &mgmt,
+ IEEE80211_HDRLEN +
+ sizeof(mgmt.u.deauth),
+ encrypt) < 0)
+ return -1;
return 0;
+ }
- wpa_printf(MSG_DEBUG, "Add new STA " MACSTR " based on ctrl_iface "
- "notification", MAC2STR(addr));
- sta = ap_sta_add(hapd, addr);
- if (sta == NULL)
- return -1;
+ hapd->drv.sta_disassoc(hapd, addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
+ sta = ap_get_sta(hapd, addr);
+ if (sta)
+ ap_sta_disassociate(hapd, sta,
+ WLAN_REASON_PREV_AUTH_NOT_VALID);
- hostapd_new_assoc_sta(hapd, sta, 0);
return 0;
}
#ifdef CONFIG_IEEE80211W
+#ifdef NEED_AP_MLME
static int hostapd_ctrl_iface_sa_query(struct hostapd_data *hapd,
const char *txtaddr)
{
@@ -238,14 +257,15 @@ static int hostapd_ctrl_iface_sa_query(struct hostapd_data *hapd,
wpa_printf(MSG_DEBUG, "CTRL_IFACE SA_QUERY %s", txtaddr);
- if (hwaddr_aton(txtaddr, addr))
+ if (hwaddr_aton(txtaddr, addr) ||
+ os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN) < 0)
return -1;
- os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN);
ieee802_11_send_sa_query_req(hapd, addr, trans_id);
return 0;
}
+#endif /* NEED_AP_MLME */
#endif /* CONFIG_IEEE80211W */
@@ -269,6 +289,83 @@ static int hostapd_ctrl_iface_wps_pin(struct hostapd_data *hapd, char *txt)
return hostapd_wps_add_pin(hapd, txt, pin, timeout);
}
+
+
+#ifdef CONFIG_WPS_OOB
+static int hostapd_ctrl_iface_wps_oob(struct hostapd_data *hapd, char *txt)
+{
+ char *path, *method, *name;
+
+ path = os_strchr(txt, ' ');
+ if (path == NULL)
+ return -1;
+ *path++ = '\0';
+
+ method = os_strchr(path, ' ');
+ if (method == NULL)
+ return -1;
+ *method++ = '\0';
+
+ name = os_strchr(method, ' ');
+ if (name != NULL)
+ *name++ = '\0';
+
+ return hostapd_wps_start_oob(hapd, txt, path, method, name);
+}
+#endif /* CONFIG_WPS_OOB */
+
+
+static int hostapd_ctrl_iface_wps_ap_pin(struct hostapd_data *hapd, char *txt,
+ char *buf, size_t buflen)
+{
+ int timeout = 300;
+ char *pos;
+ const char *pin_txt;
+
+ pos = os_strchr(txt, ' ');
+ if (pos)
+ *pos++ = '\0';
+
+ if (os_strcmp(txt, "disable") == 0) {
+ hostapd_wps_ap_pin_disable(hapd);
+ return os_snprintf(buf, buflen, "OK\n");
+ }
+
+ if (os_strcmp(txt, "random") == 0) {
+ if (pos)
+ timeout = atoi(pos);
+ pin_txt = hostapd_wps_ap_pin_random(hapd, timeout);
+ if (pin_txt == NULL)
+ return -1;
+ return os_snprintf(buf, buflen, "%s", pin_txt);
+ }
+
+ if (os_strcmp(txt, "get") == 0) {
+ pin_txt = hostapd_wps_ap_pin_get(hapd);
+ if (pin_txt == NULL)
+ return -1;
+ return os_snprintf(buf, buflen, "%s", pin_txt);
+ }
+
+ if (os_strcmp(txt, "set") == 0) {
+ char *pin;
+ if (pos == NULL)
+ return -1;
+ pin = pos;
+ pos = os_strchr(pos, ' ');
+ if (pos) {
+ *pos++ = '\0';
+ timeout = atoi(pos);
+ }
+ if (os_strlen(pin) > buflen)
+ return -1;
+ if (hostapd_wps_ap_pin_set(hapd, pin, timeout) < 0)
+ return -1;
+ return os_snprintf(buf, buflen, "%s", pin);
+ }
+
+ return -1;
+}
#endif /* CONFIG_WPS */
@@ -324,6 +421,7 @@ static void hostapd_ctrl_iface_receive(int sock, void *eloop_ctx,
else
reply_len += res;
}
+#ifndef CONFIG_NO_RADIUS
if (reply_len >= 0) {
res = radius_client_get_mib(hapd->radius,
reply + reply_len,
@@ -333,6 +431,7 @@ static void hostapd_ctrl_iface_receive(int sock, void *eloop_ctx,
else
reply_len += res;
}
+#endif /* CONFIG_NO_RADIUS */
} else if (os_strcmp(buf, "STA-FIRST") == 0) {
reply_len = hostapd_ctrl_iface_sta_first(hapd, reply,
reply_size);
@@ -355,10 +454,18 @@ static void hostapd_ctrl_iface_receive(int sock, void *eloop_ctx,
} else if (os_strncmp(buf, "NEW_STA ", 8) == 0) {
if (hostapd_ctrl_iface_new_sta(hapd, buf + 8))
reply_len = -1;
+ } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
+ if (hostapd_ctrl_iface_deauthenticate(hapd, buf + 15))
+ reply_len = -1;
+ } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
+ if (hostapd_ctrl_iface_disassociate(hapd, buf + 13))
+ reply_len = -1;
#ifdef CONFIG_IEEE80211W
+#ifdef NEED_AP_MLME
} else if (os_strncmp(buf, "SA_QUERY ", 9) == 0) {
if (hostapd_ctrl_iface_sa_query(hapd, buf + 9))
reply_len = -1;
+#endif /* NEED_AP_MLME */
#endif /* CONFIG_IEEE80211W */
#ifdef CONFIG_WPS
} else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
@@ -367,6 +474,14 @@ static void hostapd_ctrl_iface_receive(int sock, void *eloop_ctx,
} else if (os_strcmp(buf, "WPS_PBC") == 0) {
if (hostapd_wps_button_pushed(hapd))
reply_len = -1;
+#ifdef CONFIG_WPS_OOB
+ } else if (os_strncmp(buf, "WPS_OOB ", 8) == 0) {
+ if (hostapd_ctrl_iface_wps_oob(hapd, buf + 8))
+ reply_len = -1;
+#endif /* CONFIG_WPS_OOB */
+ } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
+ reply_len = hostapd_ctrl_iface_wps_ap_pin(hapd, buf + 11,
+ reply, reply_size);
#endif /* CONFIG_WPS */
} else {
os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
@@ -507,6 +622,7 @@ int hostapd_ctrl_iface_init(struct hostapd_data *hapd)
hapd->ctrl_sock = s;
eloop_register_read_sock(s, hostapd_ctrl_iface_receive, hapd,
NULL);
+ hapd->msg_ctx = hapd;
wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb);
return 0;
diff --git a/contrib/wpa/hostapd/ctrl_iface.h b/contrib/wpa/hostapd/ctrl_iface.h
index d86de8c..c997141 100644
--- a/contrib/wpa/hostapd/ctrl_iface.h
+++ b/contrib/wpa/hostapd/ctrl_iface.h
@@ -15,7 +15,18 @@
#ifndef CTRL_IFACE_H
#define CTRL_IFACE_H
+#ifndef CONFIG_NO_CTRL_IFACE
int hostapd_ctrl_iface_init(struct hostapd_data *hapd);
void hostapd_ctrl_iface_deinit(struct hostapd_data *hapd);
+#else /* CONFIG_NO_CTRL_IFACE */
+static inline int hostapd_ctrl_iface_init(struct hostapd_data *hapd)
+{
+ return 0;
+}
+
+static inline void hostapd_ctrl_iface_deinit(struct hostapd_data *hapd)
+{
+}
+#endif /* CONFIG_NO_CTRL_IFACE */
#endif /* CTRL_IFACE_H */
diff --git a/contrib/wpa/hostapd/defconfig b/contrib/wpa/hostapd/defconfig
index 96a023d..1d28c02 100644
--- a/contrib/wpa/hostapd/defconfig
+++ b/contrib/wpa/hostapd/defconfig
@@ -19,9 +19,6 @@ CONFIG_DRIVER_HOSTAP=y
#CONFIG_DRIVER_MADWIFI=y
#CFLAGS += -I../../madwifi # change to the madwifi source directory
-# Driver interface for Prism54 driver
-#CONFIG_DRIVER_PRISM54=y
-
# Driver interface for drivers using the nl80211 kernel interface
#CONFIG_DRIVER_NL80211=y
# driver_nl80211.c requires a rather new libnl (version 1.1) which may not be
@@ -35,6 +32,8 @@ CONFIG_DRIVER_HOSTAP=y
#CONFIG_DRIVER_BSD=y
#CFLAGS += -I/usr/local/include
#LIBS += -L/usr/local/lib
+#LIBS_p += -L/usr/local/lib
+#LIBS_c += -L/usr/local/lib
# Driver interface for no driver (e.g., RADIUS server only)
#CONFIG_DRIVER_NONE=y
@@ -142,3 +141,35 @@ CONFIG_IPV6=y
# This can be used to reduce the size of the hostapd considerably if debugging
# code is not needed.
#CONFIG_NO_STDOUT_DEBUG=y
+
+# Remove support for RADIUS accounting
+#CONFIG_NO_ACCOUNTING=y
+
+# Remove support for RADIUS
+#CONFIG_NO_RADIUS=y
+
+# Remove support for VLANs
+#CONFIG_NO_VLAN=y
+
+# Remove support for dumping state into a file on SIGUSR1 signal
+# This can be used to reduce binary size at the cost of disabling a debugging
+# option.
+#CONFIG_NO_DUMP_STATE=y
+
+# Enable tracing code for developer debugging
+# This tracks use of memory allocations and other registrations and reports
+# incorrect use with a backtrace of call (or allocation) location.
+#CONFIG_WPA_TRACE=y
+# For BSD, comment out these.
+#LIBS += -lexecinfo
+#LIBS_p += -lexecinfo
+#LIBS_c += -lexecinfo
+
+# Use libbfd to get more details for developer debugging
+# This enables use of libbfd to get more detailed symbols for the backtraces
+# generated by CONFIG_WPA_TRACE=y.
+#CONFIG_WPA_TRACE_BFD=y
+# For BSD, comment out these.
+#LIBS += -lbfd -liberty -lz
+#LIBS_p += -lbfd -liberty -lz
+#LIBS_c += -lbfd -liberty -lz
diff --git a/contrib/wpa/hostapd/doc/code_structure.doxygen b/contrib/wpa/hostapd/doc/code_structure.doxygen
deleted file mode 100644
index fdcf725..0000000
--- a/contrib/wpa/hostapd/doc/code_structure.doxygen
+++ /dev/null
@@ -1,5 +0,0 @@
-/**
-\page code_structure Structure of the source code
-
-
-*/
diff --git a/contrib/wpa/hostapd/doc/ctrl_iface.doxygen b/contrib/wpa/hostapd/doc/ctrl_iface.doxygen
deleted file mode 100644
index 76cfc6a..0000000
--- a/contrib/wpa/hostapd/doc/ctrl_iface.doxygen
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
-\page ctrl_iface_page Control interface
-
-hostapd implements a control interface that can be used by
-external programs to control the operations of the hostapd
-daemon and to get status information and event notifications. There is
-a small C library, in a form of a single C file, wpa_ctrl.c, that
-provides helper functions to facilitate the use of the control
-interface. External programs can link this file into them and then use
-the library functions documented in wpa_ctrl.h to interact with
-%wpa_supplicant. This library can also be used with C++. hostapd_cli.c
-is an example program using this library.
-
-There are multiple mechanisms for inter-process communication. For
-example, Linux version of hostapd is using UNIX domain sockets for the
-control interface. The use of the functions defined in wpa_ctrl.h can
-be used to hide the details of the used IPC from external programs.
-
-
-\section using_ctrl_iface Using the control interface
-
-External programs, e.g., a GUI or a configuration utility, that need to
-communicate with hostapd should link in wpa_ctrl.c. This
-allows them to use helper functions to open connection to the control
-interface with wpa_ctrl_open() and to send commands with
-wpa_ctrl_request().
-
-hostapd uses the control interface for two types of communication:
-commands and unsolicited event messages. Commands are a pair of
-messages, a request from the external program and a response from
-hostapd. These can be executed using wpa_ctrl_request().
-Unsolicited event messages are sent by hostapd to the control
-interface connection without specific request from the external program
-for receiving each message. However, the external program needs to
-attach to the control interface with wpa_ctrl_attach() to receive these
-unsolicited messages.
-
-If the control interface connection is used both for commands and
-unsolicited event messages, there is potential for receiving an
-unsolicited message between the command request and response.
-wpa_ctrl_request() caller will need to supply a callback, msg_cb,
-for processing these messages. Often it is easier to open two
-control interface connections by calling wpa_ctrl_open() twice and
-then use one of the connections for commands and the other one for
-unsolicited messages. This way command request/response pairs will
-not be broken by unsolicited messages. wpa_cli is an example of how
-to use only one connection for both purposes and wpa_gui demonstrates
-how to use two separate connections.
-
-Once the control interface connection is not needed anymore, it should
-be closed by calling wpa_ctrl_close(). If the connection was used for
-unsolicited event messages, it should be first detached by calling
-wpa_ctrl_detach().
-
-
-\section ctrl_iface_cmds Control interface commands
-
-Following commands can be used with wpa_ctrl_request():
-
-\subsection ctrl_iface_PING PING
-
-This command can be used to test whether hostapd is replying
-to the control interface commands. The expected reply is \c PONG if the
-connection is open and hostapd is processing commands.
-
-*/
diff --git a/contrib/wpa/hostapd/doc/doxygen.fast b/contrib/wpa/hostapd/doc/doxygen.fast
deleted file mode 100644
index 650c73d..0000000
--- a/contrib/wpa/hostapd/doc/doxygen.fast
+++ /dev/null
@@ -1,238 +0,0 @@
-# Doxyfile 1.4.4
-
-#---------------------------------------------------------------------------
-# Project related configuration options
-#---------------------------------------------------------------------------
-PROJECT_NAME = hostapd
-PROJECT_NUMBER = 0.6.x
-OUTPUT_DIRECTORY = hostapd/doc
-CREATE_SUBDIRS = NO
-OUTPUT_LANGUAGE = English
-BRIEF_MEMBER_DESC = YES
-REPEAT_BRIEF = YES
-ABBREVIATE_BRIEF = "The $name class" \
- "The $name widget" \
- "The $name file" \
- is \
- provides \
- specifies \
- contains \
- represents \
- a \
- an \
- the
-ALWAYS_DETAILED_SEC = NO
-INLINE_INHERITED_MEMB = NO
-FULL_PATH_NAMES = YES
-STRIP_FROM_PATH =
-STRIP_FROM_INC_PATH =
-SHORT_NAMES = NO
-JAVADOC_AUTOBRIEF = NO
-MULTILINE_CPP_IS_BRIEF = NO
-DETAILS_AT_TOP = NO
-INHERIT_DOCS = YES
-DISTRIBUTE_GROUP_DOC = NO
-SEPARATE_MEMBER_PAGES = NO
-TAB_SIZE = 8
-ALIASES =
-OPTIMIZE_OUTPUT_FOR_C = YES
-OPTIMIZE_OUTPUT_JAVA = NO
-SUBGROUPING = YES
-#---------------------------------------------------------------------------
-# Build related configuration options
-#---------------------------------------------------------------------------
-EXTRACT_ALL = NO
-EXTRACT_PRIVATE = NO
-EXTRACT_STATIC = NO
-EXTRACT_LOCAL_CLASSES = YES
-EXTRACT_LOCAL_METHODS = NO
-HIDE_UNDOC_MEMBERS = NO
-HIDE_UNDOC_CLASSES = NO
-HIDE_FRIEND_COMPOUNDS = NO
-HIDE_IN_BODY_DOCS = NO
-INTERNAL_DOCS = NO
-CASE_SENSE_NAMES = YES
-HIDE_SCOPE_NAMES = NO
-SHOW_INCLUDE_FILES = YES
-INLINE_INFO = YES
-SORT_MEMBER_DOCS = YES
-SORT_BRIEF_DOCS = NO
-SORT_BY_SCOPE_NAME = NO
-GENERATE_TODOLIST = YES
-GENERATE_TESTLIST = YES
-GENERATE_BUGLIST = YES
-GENERATE_DEPRECATEDLIST= YES
-ENABLED_SECTIONS =
-MAX_INITIALIZER_LINES = 30
-SHOW_USED_FILES = YES
-SHOW_DIRECTORIES = YES
-FILE_VERSION_FILTER =
-#---------------------------------------------------------------------------
-# configuration options related to warning and progress messages
-#---------------------------------------------------------------------------
-QUIET = NO
-WARNINGS = YES
-WARN_IF_UNDOCUMENTED = NO
-WARN_IF_DOC_ERROR = YES
-WARN_NO_PARAMDOC = YES
-WARN_FORMAT = "$file:$line: $text"
-WARN_LOGFILE =
-#---------------------------------------------------------------------------
-# configuration options related to the input files
-#---------------------------------------------------------------------------
-INPUT = hostapd \
- src/common \
- src/crypto \
- src/eap_common \
- src/eap_server \
- src/l2_packet \
- src/radius \
- src/rsn_supp \
- src/tls \
- src/utils \
- src/wps
-FILE_PATTERNS = *.c *.h *.doxygen
-RECURSIVE = YES
-EXCLUDE =
-EXCLUDE_SYMLINKS = NO
-EXCLUDE_PATTERNS =
-EXAMPLE_PATH =
-EXAMPLE_PATTERNS = *
-EXAMPLE_RECURSIVE = NO
-IMAGE_PATH = hostapd/doc
-INPUT_FILTER = kerneldoc2doxygen.pl
-FILTER_PATTERNS =
-FILTER_SOURCE_FILES = YES
-#---------------------------------------------------------------------------
-# configuration options related to source browsing
-#---------------------------------------------------------------------------
-SOURCE_BROWSER = YES
-INLINE_SOURCES = NO
-STRIP_CODE_COMMENTS = YES
-REFERENCED_BY_RELATION = NO
-REFERENCES_RELATION = NO
-VERBATIM_HEADERS = NO
-#---------------------------------------------------------------------------
-# configuration options related to the alphabetical class index
-#---------------------------------------------------------------------------
-ALPHABETICAL_INDEX = YES
-COLS_IN_ALPHA_INDEX = 3
-IGNORE_PREFIX =
-#---------------------------------------------------------------------------
-# configuration options related to the HTML output
-#---------------------------------------------------------------------------
-GENERATE_HTML = YES
-HTML_OUTPUT = html
-HTML_FILE_EXTENSION = .html
-HTML_HEADER =
-HTML_FOOTER =
-HTML_STYLESHEET =
-HTML_ALIGN_MEMBERS = YES
-GENERATE_HTMLHELP = NO
-CHM_FILE =
-HHC_LOCATION =
-GENERATE_CHI = NO
-BINARY_TOC = NO
-TOC_EXPAND = NO
-DISABLE_INDEX = NO
-ENUM_VALUES_PER_LINE = 4
-GENERATE_TREEVIEW = NO
-TREEVIEW_WIDTH = 250
-#---------------------------------------------------------------------------
-# configuration options related to the LaTeX output
-#---------------------------------------------------------------------------
-GENERATE_LATEX = NO
-LATEX_OUTPUT = latex
-LATEX_CMD_NAME = latex
-MAKEINDEX_CMD_NAME = makeindex
-COMPACT_LATEX = NO
-PAPER_TYPE = a4wide
-EXTRA_PACKAGES =
-LATEX_HEADER =
-PDF_HYPERLINKS = YES
-USE_PDFLATEX = YES
-LATEX_BATCHMODE = NO
-LATEX_HIDE_INDICES = NO
-#---------------------------------------------------------------------------
-# configuration options related to the RTF output
-#---------------------------------------------------------------------------
-GENERATE_RTF = NO
-RTF_OUTPUT = rtf
-COMPACT_RTF = NO
-RTF_HYPERLINKS = NO
-RTF_STYLESHEET_FILE =
-RTF_EXTENSIONS_FILE =
-#---------------------------------------------------------------------------
-# configuration options related to the man page output
-#---------------------------------------------------------------------------
-GENERATE_MAN = NO
-MAN_OUTPUT = man
-MAN_EXTENSION = .3
-MAN_LINKS = NO
-#---------------------------------------------------------------------------
-# configuration options related to the XML output
-#---------------------------------------------------------------------------
-GENERATE_XML = NO
-XML_OUTPUT = xml
-XML_SCHEMA =
-XML_DTD =
-XML_PROGRAMLISTING = YES
-#---------------------------------------------------------------------------
-# configuration options for the AutoGen Definitions output
-#---------------------------------------------------------------------------
-GENERATE_AUTOGEN_DEF = NO
-#---------------------------------------------------------------------------
-# configuration options related to the Perl module output
-#---------------------------------------------------------------------------
-GENERATE_PERLMOD = NO
-PERLMOD_LATEX = NO
-PERLMOD_PRETTY = YES
-PERLMOD_MAKEVAR_PREFIX =
-#---------------------------------------------------------------------------
-# Configuration options related to the preprocessor
-#---------------------------------------------------------------------------
-ENABLE_PREPROCESSING = YES
-MACRO_EXPANSION = NO
-EXPAND_ONLY_PREDEF = NO
-SEARCH_INCLUDES = YES
-INCLUDE_PATH =
-INCLUDE_FILE_PATTERNS =
-PREDEFINED = RADIUS_SERVER EAP_SERVER EAP_SIM
-EXPAND_AS_DEFINED =
-SKIP_FUNCTION_MACROS = YES
-#---------------------------------------------------------------------------
-# Configuration::additions related to external references
-#---------------------------------------------------------------------------
-TAGFILES =
-GENERATE_TAGFILE =
-ALLEXTERNALS = NO
-EXTERNAL_GROUPS = YES
-PERL_PATH = /usr/bin/perl
-#---------------------------------------------------------------------------
-# Configuration options related to the dot tool
-#---------------------------------------------------------------------------
-CLASS_DIAGRAMS = NO
-HIDE_UNDOC_RELATIONS = YES
-HAVE_DOT = NO
-CLASS_GRAPH = YES
-COLLABORATION_GRAPH = YES
-GROUP_GRAPHS = YES
-UML_LOOK = NO
-TEMPLATE_RELATIONS = NO
-INCLUDE_GRAPH = YES
-INCLUDED_BY_GRAPH = YES
-CALL_GRAPH = YES
-GRAPHICAL_HIERARCHY = YES
-DIRECTORY_GRAPH = NO
-DOT_IMAGE_FORMAT = png
-DOT_PATH =
-DOTFILE_DIRS =
-MAX_DOT_GRAPH_DEPTH = 1000
-DOT_TRANSPARENT = NO
-DOT_MULTI_TARGETS = NO
-GENERATE_LEGEND = YES
-DOT_CLEANUP = YES
-#---------------------------------------------------------------------------
-# Configuration::additions related to the search engine
-#---------------------------------------------------------------------------
-SEARCHENGINE = NO
diff --git a/contrib/wpa/hostapd/doc/doxygen.full b/contrib/wpa/hostapd/doc/doxygen.full
deleted file mode 100644
index f8c49bf..0000000
--- a/contrib/wpa/hostapd/doc/doxygen.full
+++ /dev/null
@@ -1,238 +0,0 @@
-# Doxyfile 1.4.4
-
-#---------------------------------------------------------------------------
-# Project related configuration options
-#---------------------------------------------------------------------------
-PROJECT_NAME = hostapd
-PROJECT_NUMBER = 0.6.x
-OUTPUT_DIRECTORY = hostapd/doc
-CREATE_SUBDIRS = NO
-OUTPUT_LANGUAGE = English
-BRIEF_MEMBER_DESC = YES
-REPEAT_BRIEF = YES
-ABBREVIATE_BRIEF = "The $name class" \
- "The $name widget" \
- "The $name file" \
- is \
- provides \
- specifies \
- contains \
- represents \
- a \
- an \
- the
-ALWAYS_DETAILED_SEC = NO
-INLINE_INHERITED_MEMB = NO
-FULL_PATH_NAMES = YES
-STRIP_FROM_PATH =
-STRIP_FROM_INC_PATH =
-SHORT_NAMES = NO
-JAVADOC_AUTOBRIEF = NO
-MULTILINE_CPP_IS_BRIEF = NO
-DETAILS_AT_TOP = NO
-INHERIT_DOCS = YES
-DISTRIBUTE_GROUP_DOC = NO
-SEPARATE_MEMBER_PAGES = NO
-TAB_SIZE = 8
-ALIASES =
-OPTIMIZE_OUTPUT_FOR_C = YES
-OPTIMIZE_OUTPUT_JAVA = NO
-SUBGROUPING = YES
-#---------------------------------------------------------------------------
-# Build related configuration options
-#---------------------------------------------------------------------------
-EXTRACT_ALL = NO
-EXTRACT_PRIVATE = NO
-EXTRACT_STATIC = NO
-EXTRACT_LOCAL_CLASSES = YES
-EXTRACT_LOCAL_METHODS = NO
-HIDE_UNDOC_MEMBERS = NO
-HIDE_UNDOC_CLASSES = NO
-HIDE_FRIEND_COMPOUNDS = NO
-HIDE_IN_BODY_DOCS = NO
-INTERNAL_DOCS = NO
-CASE_SENSE_NAMES = YES
-HIDE_SCOPE_NAMES = NO
-SHOW_INCLUDE_FILES = YES
-INLINE_INFO = YES
-SORT_MEMBER_DOCS = YES
-SORT_BRIEF_DOCS = NO
-SORT_BY_SCOPE_NAME = NO
-GENERATE_TODOLIST = YES
-GENERATE_TESTLIST = YES
-GENERATE_BUGLIST = YES
-GENERATE_DEPRECATEDLIST= YES
-ENABLED_SECTIONS =
-MAX_INITIALIZER_LINES = 30
-SHOW_USED_FILES = YES
-SHOW_DIRECTORIES = YES
-FILE_VERSION_FILTER =
-#---------------------------------------------------------------------------
-# configuration options related to warning and progress messages
-#---------------------------------------------------------------------------
-QUIET = NO
-WARNINGS = YES
-WARN_IF_UNDOCUMENTED = NO
-WARN_IF_DOC_ERROR = YES
-WARN_NO_PARAMDOC = YES
-WARN_FORMAT = "$file:$line: $text"
-WARN_LOGFILE =
-#---------------------------------------------------------------------------
-# configuration options related to the input files
-#---------------------------------------------------------------------------
-INPUT = hostapd \
- src/common \
- src/crypto \
- src/eap_common \
- src/eap_server \
- src/l2_packet \
- src/radius \
- src/rsn_supp \
- src/tls \
- src/utils \
- src/wps
-FILE_PATTERNS = *.c *.h *.doxygen
-RECURSIVE = YES
-EXCLUDE =
-EXCLUDE_SYMLINKS = NO
-EXCLUDE_PATTERNS =
-EXAMPLE_PATH =
-EXAMPLE_PATTERNS = *
-EXAMPLE_RECURSIVE = NO
-IMAGE_PATH = hostapd/doc
-INPUT_FILTER = kerneldoc2doxygen.pl
-FILTER_PATTERNS =
-FILTER_SOURCE_FILES = YES
-#---------------------------------------------------------------------------
-# configuration options related to source browsing
-#---------------------------------------------------------------------------
-SOURCE_BROWSER = YES
-INLINE_SOURCES = NO
-STRIP_CODE_COMMENTS = YES
-REFERENCED_BY_RELATION = NO
-REFERENCES_RELATION = NO
-VERBATIM_HEADERS = NO
-#---------------------------------------------------------------------------
-# configuration options related to the alphabetical class index
-#---------------------------------------------------------------------------
-ALPHABETICAL_INDEX = YES
-COLS_IN_ALPHA_INDEX = 3
-IGNORE_PREFIX =
-#---------------------------------------------------------------------------
-# configuration options related to the HTML output
-#---------------------------------------------------------------------------
-GENERATE_HTML = YES
-HTML_OUTPUT = html
-HTML_FILE_EXTENSION = .html
-HTML_HEADER =
-HTML_FOOTER =
-HTML_STYLESHEET =
-HTML_ALIGN_MEMBERS = YES
-GENERATE_HTMLHELP = NO
-CHM_FILE =
-HHC_LOCATION =
-GENERATE_CHI = NO
-BINARY_TOC = NO
-TOC_EXPAND = NO
-DISABLE_INDEX = NO
-ENUM_VALUES_PER_LINE = 4
-GENERATE_TREEVIEW = NO
-TREEVIEW_WIDTH = 250
-#---------------------------------------------------------------------------
-# configuration options related to the LaTeX output
-#---------------------------------------------------------------------------
-GENERATE_LATEX = YES
-LATEX_OUTPUT = latex
-LATEX_CMD_NAME = latex
-MAKEINDEX_CMD_NAME = makeindex
-COMPACT_LATEX = NO
-PAPER_TYPE = a4wide
-EXTRA_PACKAGES =
-LATEX_HEADER =
-PDF_HYPERLINKS = YES
-USE_PDFLATEX = YES
-LATEX_BATCHMODE = NO
-LATEX_HIDE_INDICES = NO
-#---------------------------------------------------------------------------
-# configuration options related to the RTF output
-#---------------------------------------------------------------------------
-GENERATE_RTF = NO
-RTF_OUTPUT = rtf
-COMPACT_RTF = NO
-RTF_HYPERLINKS = NO
-RTF_STYLESHEET_FILE =
-RTF_EXTENSIONS_FILE =
-#---------------------------------------------------------------------------
-# configuration options related to the man page output
-#---------------------------------------------------------------------------
-GENERATE_MAN = NO
-MAN_OUTPUT = man
-MAN_EXTENSION = .3
-MAN_LINKS = NO
-#---------------------------------------------------------------------------
-# configuration options related to the XML output
-#---------------------------------------------------------------------------
-GENERATE_XML = NO
-XML_OUTPUT = xml
-XML_SCHEMA =
-XML_DTD =
-XML_PROGRAMLISTING = YES
-#---------------------------------------------------------------------------
-# configuration options for the AutoGen Definitions output
-#---------------------------------------------------------------------------
-GENERATE_AUTOGEN_DEF = NO
-#---------------------------------------------------------------------------
-# configuration options related to the Perl module output
-#---------------------------------------------------------------------------
-GENERATE_PERLMOD = NO
-PERLMOD_LATEX = NO
-PERLMOD_PRETTY = YES
-PERLMOD_MAKEVAR_PREFIX =
-#---------------------------------------------------------------------------
-# Configuration options related to the preprocessor
-#---------------------------------------------------------------------------
-ENABLE_PREPROCESSING = YES
-MACRO_EXPANSION = NO
-EXPAND_ONLY_PREDEF = NO
-SEARCH_INCLUDES = YES
-INCLUDE_PATH =
-INCLUDE_FILE_PATTERNS =
-PREDEFINED = RADIUS_SERVER EAP_SERVER EAP_SIM
-EXPAND_AS_DEFINED =
-SKIP_FUNCTION_MACROS = YES
-#---------------------------------------------------------------------------
-# Configuration::additions related to external references
-#---------------------------------------------------------------------------
-TAGFILES =
-GENERATE_TAGFILE =
-ALLEXTERNALS = NO
-EXTERNAL_GROUPS = YES
-PERL_PATH = /usr/bin/perl
-#---------------------------------------------------------------------------
-# Configuration options related to the dot tool
-#---------------------------------------------------------------------------
-CLASS_DIAGRAMS = NO
-HIDE_UNDOC_RELATIONS = YES
-HAVE_DOT = YES
-CLASS_GRAPH = YES
-COLLABORATION_GRAPH = YES
-GROUP_GRAPHS = YES
-UML_LOOK = NO
-TEMPLATE_RELATIONS = NO
-INCLUDE_GRAPH = YES
-INCLUDED_BY_GRAPH = YES
-CALL_GRAPH = YES
-GRAPHICAL_HIERARCHY = YES
-DIRECTORY_GRAPH = NO
-DOT_IMAGE_FORMAT = png
-DOT_PATH =
-DOTFILE_DIRS =
-MAX_DOT_GRAPH_DEPTH = 1000
-DOT_TRANSPARENT = NO
-DOT_MULTI_TARGETS = NO
-GENERATE_LEGEND = YES
-DOT_CLEANUP = YES
-#---------------------------------------------------------------------------
-# Configuration::additions related to the search engine
-#---------------------------------------------------------------------------
-SEARCHENGINE = YES
diff --git a/contrib/wpa/hostapd/doc/driver_wrapper.doxygen b/contrib/wpa/hostapd/doc/driver_wrapper.doxygen
deleted file mode 100644
index 0ad196f..0000000
--- a/contrib/wpa/hostapd/doc/driver_wrapper.doxygen
+++ /dev/null
@@ -1,20 +0,0 @@
-/**
-\page driver_wrapper Driver wrapper implementation (driver.h, drivers.c)
-
-All hardware and driver dependent functionality is in separate C files
-that implement defined wrapper functions. Other parts
-of the hostapd are designed to be hardware, driver, and operating
-system independent.
-
-Driver wrappers need to implement whatever calls are used in the
-target operating system/driver for controlling wireless LAN
-devices. As an example, in case of Linux, these are mostly some glue
-code and ioctl() calls and netlink message parsing for Linux Wireless
-Extensions (WE). Since features required for WPA were added only recently to
-Linux Wireless Extensions (in version 18), some driver specific code is used
-in number of driver interface implementations. These driver dependent parts
-can be replaced with generic code in driver_wext.c once the target driver
-includes full support for WE-18. After that, all Linux drivers, at
-least in theory, could use the same driver wrapper code.
-
-*/
diff --git a/contrib/wpa/hostapd/doc/eap.doxygen b/contrib/wpa/hostapd/doc/eap.doxygen
deleted file mode 100644
index f0f135a..0000000
--- a/contrib/wpa/hostapd/doc/eap.doxygen
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
-\page eap_module EAP server implementation
-
-Extensible Authentication Protocol (EAP) is an authentication framework
-defined in RFC 3748. hostapd uses a separate code module for EAP server
-implementation. This module was designed to use only a minimal set of
-direct function calls (mainly, to debug/event functions) in order for
-it to be usable in other programs. The design of the EAP
-implementation is based loosely on RFC 4137. The state machine is
-defined in this RFC and so is the interface between the server state
-machine and methods. As such, this RFC provides useful information for
-understanding the EAP server implementation in hostapd.
-
-Some of the terminology used in EAP state machine is referring to
-EAPOL (IEEE 802.1X), but there is no strict requirement on the lower
-layer being IEEE 802.1X if EAP module is built for other programs than
-%wpa_supplicant. These terms should be understood to refer to the
-lower layer as defined in RFC 4137.
-
-
-\section adding_eap_methods Adding EAP methods
-
-Each EAP method is implemented as a separate module, usually as one C
-file named eap_<name of the method>.c, e.g., eap_md5.c. All EAP
-methods use the same interface between the server state machine and
-method specific functions. This allows new EAP methods to be added
-without modifying the core EAP state machine implementation.
-
-New EAP methods need to be registered by adding them into the build
-(Makefile) and the EAP method registration list in the
-eap_server_register_methods() function of eap_methods.c. Each EAP
-method should use a build-time configuration option, e.g., EAP_TLS, in
-order to make it possible to select which of the methods are included
-in the build.
-
-EAP methods must implement the interface defined in eap_i.h. struct
-eap_method defines the needed function pointers that each EAP method
-must provide. In addition, the EAP type and name are registered using
-this structure. This interface is based on section 4.4 of RFC 4137.
-
-It is recommended that the EAP methods would use generic helper
-functions, eap_msg_alloc() and eap_hdr_validate() when processing
-messages. This allows code sharing and can avoid missing some of the
-needed validation steps for received packets. In addition, these
-functions make it easier to change between expanded and legacy EAP
-header, if needed.
-
-When adding an EAP method that uses a vendor specific EAP type
-(Expanded Type as defined in RFC 3748, Chapter 5.7), the new method
-must be registered by passing vendor id instead of EAP_VENDOR_IETF to
-eap_server_method_alloc(). These methods must not try to emulate
-expanded types by registering a legacy EAP method for type 254. See
-eap_vendor_test.c for an example of an EAP method implementation that
-is implemented as an expanded type.
-
-*/
diff --git a/contrib/wpa/hostapd/doc/hostapd.fig b/contrib/wpa/hostapd/doc/hostapd.fig
deleted file mode 100644
index af3f0be..0000000
--- a/contrib/wpa/hostapd/doc/hostapd.fig
+++ /dev/null
@@ -1,264 +0,0 @@
-#FIG 3.2
-Landscape
-Center
-Inches
-Letter
-100.00
-Single
--2
-1200 2
-6 1875 4050 2925 4350
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 1875 4050 2925 4050 2925 4350 1875 4350 1875 4050
-4 0 0 50 -1 0 12 0.0000 4 180 735 2025 4275 l2_packet\001
--6
-6 4725 1200 5925 1500
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 4725 1200 5925 1200 5925 1500 4725 1500 4725 1200
-4 0 0 50 -1 0 12 0.0000 4 135 1005 4800 1425 GUI frontend\001
--6
-6 6000 2700 7200 3225
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 6000 2700 7200 2700 7200 3225 6000 3225 6000 2700
-4 0 0 50 -1 0 12 0.0000 4 135 975 6075 2925 WPA/WPA2\001
-4 0 0 50 -1 0 12 0.0000 4 135 1065 6075 3150 state machine\001
--6
-6 6000 4950 7200 5475
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 6000 4950 7200 4950 7200 5475 6000 5475 6000 4950
-4 0 0 50 -1 0 12 0.0000 4 135 360 6075 5175 EAP\001
-4 0 0 50 -1 0 12 0.0000 4 135 1065 6075 5400 state machine\001
--6
-6 4350 3900 5025 4425
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 4350 3900 5025 3900 5025 4425 4350 4425 4350 3900
-4 0 0 50 -1 0 12 0.0000 4 105 420 4500 4125 event\001
-4 0 0 50 -1 0 12 0.0000 4 180 315 4500 4350 loop\001
--6
-6 4275 2550 5100 2850
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 4275 2550 5100 2550 5100 2850 4275 2850 4275 2550
-4 0 0 50 -1 0 12 0.0000 4 135 450 4425 2775 ctrl i/f\001
--6
-6 6000 3900 7200 4425
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 6000 3900 7200 3900 7200 4425 6000 4425 6000 3900
-4 0 0 50 -1 0 12 0.0000 4 135 600 6075 4125 EAPOL\001
-4 0 0 50 -1 0 12 0.0000 4 135 1065 6075 4350 state machine\001
--6
-6 2775 3150 4050 3450
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 2775 3150 4050 3150 4050 3450 2775 3450 2775 3150
-4 0 0 50 -1 0 12 0.0000 4 180 990 2925 3375 configuration\001
--6
-6 3450 1200 4575 1500
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 3450 1200 4575 1200 4575 1500 3450 1500 3450 1200
-4 0 0 50 -1 0 12 0.0000 4 180 870 3600 1425 hostapd_cli\001
--6
-6 3525 7800 5775 8100
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 3525 7800 5775 7800 5775 8100 3525 8100 3525 7800
-4 0 0 50 -1 0 12 0.0000 4 135 2145 3600 8025 kernel network device driver\001
--6
-6 4275 6000 5100 6300
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 4275 6000 5100 6000 5100 6300 4275 6300 4275 6000
-4 0 0 50 -1 0 12 0.0000 4 135 630 4350 6225 driver i/f\001
--6
-6 8175 4725 9225 5025
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 8175 4725 9225 4725 9225 5025 8175 5025 8175 4725
-4 0 0 50 -1 0 12 0.0000 4 135 735 8250 4950 EAP-TLS\001
--6
-6 9300 4725 10350 5025
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 9300 4725 10350 4725 10350 5025 9300 5025 9300 4725
-4 0 0 50 -1 0 12 0.0000 4 135 810 9375 4950 EAP-MD5\001
--6
-6 8175 5100 9225 5400
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 8175 5100 9225 5100 9225 5400 8175 5400 8175 5100
-4 0 0 50 -1 0 12 0.0000 4 135 885 8250 5325 EAP-PEAP\001
--6
-6 9300 5100 10350 5400
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 9300 5100 10350 5100 10350 5400 9300 5400 9300 5100
-4 0 0 50 -1 0 12 0.0000 4 135 840 9375 5325 EAP-TTLS\001
--6
-6 8175 5475 9225 5775
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 8175 5475 9225 5475 9225 5775 8175 5775 8175 5475
-4 0 0 50 -1 0 12 0.0000 4 135 780 8250 5700 EAP-GTC\001
--6
-6 8175 5850 9225 6150
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 8175 5850 9225 5850 9225 6150 8175 6150 8175 5850
-4 0 0 50 -1 0 12 0.0000 4 135 750 8250 6075 EAP-SIM\001
--6
-6 8175 6225 9225 6525
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 8175 6225 9225 6225 9225 6525 8175 6525 8175 6225
-4 0 0 50 -1 0 12 0.0000 4 135 765 8250 6450 EAP-PSK\001
--6
-6 9300 5850 10350 6150
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 9300 5850 10350 5850 10350 6150 9300 6150 9300 5850
-4 0 0 50 -1 0 12 0.0000 4 135 825 9375 6075 EAP-AKA\001
--6
-6 9300 5475 10350 5775
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 9300 5475 10350 5475 10350 5775 9300 5775 9300 5475
-4 0 0 50 -1 0 12 0.0000 4 135 795 9375 5700 EAP-PAX\001
--6
-6 8175 6600 9675 6900
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 8175 6600 9675 6600 9675 6900 8175 6900 8175 6600
-4 0 0 50 -1 0 12 0.0000 4 135 1365 8250 6825 EAP-MSCHAPv2\001
--6
-6 8700 3450 9375 3750
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 8700 3450 9375 3450 9375 3750 8700 3750 8700 3450
-4 0 0 50 -1 0 12 0.0000 4 150 480 8775 3675 crypto\001
--6
-6 9600 3450 10275 3750
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 9600 3450 10275 3450 10275 3750 9600 3750 9600 3450
-4 0 0 50 -1 0 12 0.0000 4 135 315 9750 3675 TLS\001
--6
-6 6000 5775 7200 6300
-6 6000 5775 7200 6300
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 6000 5775 7200 5775 7200 6300 6000 6300 6000 5775
-4 0 0 50 -1 0 12 0.0000 4 135 690 6075 6000 RADIUS\001
--6
-4 0 0 50 -1 0 12 0.0000 4 90 480 6075 6225 server\001
--6
-6 8100 2250 8925 2775
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 8100 2250 8925 2250 8925 2775 8100 2775 8100 2250
-4 0 0 50 -1 0 12 0.0000 4 135 690 8175 2475 RADIUS\001
-4 0 0 50 -1 0 12 0.0000 4 135 420 8175 2700 client\001
--6
-6 3150 5475 4425 5775
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 3150 5475 4425 5475 4425 5775 3150 5775 3150 5475
-4 0 0 50 -1 0 12 0.0000 4 135 990 3300 5700 driver events\001
--6
-6 1950 5550 2625 6075
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 1950 5550 2625 5550 2625 6075 1950 6075 1950 5550
-4 0 0 50 -1 0 12 0.0000 4 135 540 2025 5775 Station\001
-4 0 0 50 -1 0 12 0.0000 4 135 375 2025 6000 table\001
--6
-6 1875 4725 2925 5250
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 1875 4725 2925 4725 2925 5250 1875 5250 1875 4725
-4 0 0 50 -1 0 12 0.0000 4 135 960 1950 4950 IEEE 802.11\001
-4 0 0 50 -1 0 12 0.0000 4 135 555 1950 5175 MLME\001
--6
-2 1 1 1 0 7 50 -1 -1 3.000 0 0 -1 0 0 2
- 1275 4200 1875 4200
-2 1 1 1 0 7 50 -1 -1 4.000 0 0 -1 0 0 2
- 4500 2550 3900 1500
-2 1 1 1 0 7 50 -1 -1 4.000 0 0 -1 0 0 2
- 4800 2550 5400 1500
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 2925 4200 4350 4200
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 5025 3900 6000 3000
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 5025 4200 6000 4200
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 4650 6000 4650 4425
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 6600 4425 6600 4950
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 6600 3225 6600 3900
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 7200 5250 8100 5250
-2 1 0 1 2 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 9075 4425 9075 3750
-2 1 0 1 2 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 7200 3000 8700 3525
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 4650 3900 4650 2850
-2 1 0 1 2 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 7200 4125 8700 3675
-2 1 0 1 2 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 6000 4350 5025 6000
-2 1 0 1 2 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 6000 3150 4875 6000
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 1500 2100 10800 2100 10800 7500 1500 7500 1500 2100
-2 1 0 1 2 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 9900 4425 9900 3750
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 1
- 4350 3900
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 4350 3900 4050 3450
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 4350 4425 4050 5475
-2 1 1 1 0 7 50 -1 -1 4.000 0 0 -1 0 0 2
- 2250 7200 4200 7800
-2 1 1 1 0 7 50 -1 -1 4.000 0 0 -1 0 0 2
- 7200 7200 5100 7800
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 2775 6900 3675 6900 3675 7200 2775 7200 2775 6900
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 3750 6900 4650 6900 4650 7200 3750 7200 3750 6900
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 4
- 2250 6900 2250 6600 7200 6600 7200 6900
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 3225 6900 3225 6600
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 4200 6900 4200 6600
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 5175 6900 5175 6600
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 6150 6900 6150 6600
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 4650 6600 4650 6300
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 1800 6900 2700 6900 2700 7200 1800 7200 1800 6900
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 4725 6900 5625 6900 5625 7200 4725 7200 4725 6900
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 5700 6900 6600 6900 6600 7200 5700 7200 5700 6900
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 6675 6900 7800 6900 7800 7200 6675 7200 6675 6900
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 8100 6975 10425 6975 10425 4425 8100 4425 8100 6975
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 6600 5475 6600 5775
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 5025 4425 6000 5775
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 3
- 4800 3900 5925 2550 8100 2550
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 7200 3900 8475 2775
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 9450 2250 10425 2250 10425 2775 9450 2775 9450 2250
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 8925 2475 9450 2475
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 2325 5550 2325 5250
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 2925 4950 4350 4275
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 3
- 2850 4725 5775 2400 8100 2400
-4 0 0 50 -1 0 12 0.0000 4 135 915 375 3975 EAPOL and\001
-4 0 0 50 -1 0 12 0.0000 4 180 630 375 4200 pre-auth\001
-4 0 0 50 -1 0 12 0.0000 4 180 810 375 4425 ethertypes\001
-4 0 0 50 -1 0 12 0.0000 4 135 1050 375 4650 from/to kernel\001
-4 0 0 50 -1 0 12 0.0000 4 135 1920 3675 1875 frontend control interface\001
-4 0 0 50 -1 2 14 0.0000 4 195 720 1637 2371 hostapd\001
-4 0 0 50 -1 0 12 0.0000 4 180 600 3825 7125 prism54\001
-4 0 0 50 -1 0 12 0.0000 4 180 510 1875 7125 hostap\001
-4 0 0 50 -1 0 12 0.0000 4 135 600 2850 7125 madwifi\001
-4 0 0 50 -1 0 12 0.0000 4 135 270 4800 7125 bsd\001
-4 0 0 50 -1 0 12 0.0000 4 105 300 6750 7125 test\001
-4 0 0 50 -1 0 12 0.0000 4 135 420 5775 7125 wired\001
-4 0 0 50 -1 0 12 0.0000 4 135 1050 8700 4650 EAP methods\001
-4 0 0 50 -1 0 12 0.0000 4 135 690 9525 2475 RADIUS\001
-4 0 0 50 -1 0 12 0.0000 4 180 825 9525 2700 accounting\001
diff --git a/contrib/wpa/hostapd/doc/kerneldoc2doxygen.pl b/contrib/wpa/hostapd/doc/kerneldoc2doxygen.pl
deleted file mode 100755
index 68835a1..0000000
--- a/contrib/wpa/hostapd/doc/kerneldoc2doxygen.pl
+++ /dev/null
@@ -1,129 +0,0 @@
-#!/usr/bin/perl -w
-#
-##########################################################################
-# Convert kernel-doc style comments to Doxygen comments.
-##########################################################################
-#
-# This script reads a C source file from stdin, and writes
-# to stdout. Normal usage:
-#
-# $ mv file.c file.c.gtkdoc
-# $ kerneldoc2doxygen.pl <file.c.gtkdoc >file.c
-#
-# Or to do the same thing with multiple files:
-# $ perl -i.gtkdoc kerneldoc2doxygen.pl *.c *.h
-#
-# This script may also be suitable for use as a Doxygen input filter,
-# but that has not been tested.
-#
-# Back up your source files before using this script!!
-#
-##########################################################################
-# Copyright (C) 2003 Jonathan Foster <jon@jon-foster.co.uk>
-# Copyright (C) 2005 Jouni Malinen <j@w1.fi>
-# (modified for kerneldoc format used in wpa_supplicant)
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License version 2 as
-# published by the Free Software Foundation.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-# or look at http://www.gnu.org/licenses/gpl.html
-##########################################################################
-
-
-##########################################################################
-#
-# This function converts a single comment from gtk-doc to Doxygen format.
-# The parameter does not include the opening or closing lines
-# (i.e. given a comment like this:
-# "/**\n"
-# " * FunctionName:\n"
-# " * @foo: This describes the foo parameter\n"
-# " * @bar: This describes the bar parameter\n"
-# " * @Returns: This describes the return value\n"
-# " *\n"
-# " * This describes the function.\n"
-# " */\n"
-# This function gets:
-# " * FunctionName:\n"
-# " * @foo: This describes the foo parameter\n"
-# " * @bar: This describes the bar parameter\n"
-# " * @Returns: This describes the return value\n"
-# " *\n"
-# " * This describes the function.\n"
-# And it returns:
-# " * This describes the function.\n"
-# " *\n"
-# " * @param foo This describes the foo parameter\n"
-# " * @param bar This describes the bar parameter\n"
-# " * @return This describes the return value\n"
-# )
-#
-sub fixcomment {
- $t = $_[0];
-
- # " * func: foo" --> "\brief foo\n"
- # " * struct bar: foo" --> "\brief foo\n"
- # If this fails, not a kernel-doc comment ==> return unmodified.
- ($t =~ s/^[\t ]*\*[\t ]*(struct )?([^ \t\n]*) - ([^\n]*)/\\brief $3\n/s)
- or return $t;
-
- # " * Returns: foo" --> "\return foo"
- $t =~ s/\n[\t ]*\*[\t ]*Returns:/\n\\return/sig;
-
- # " * @foo: bar" --> "\param foo bar"
- # Handle two common typos: No ":", or "," instead of ":".
- $t =~ s/\n[\t ]*\*[\t ]*\@([^ :,]*)[:,]?[\t ]*/\n\\param $1 /sg;
-
- return $t;
-}
-
-##########################################################################
-# Start of main code
-
-# Read entire stdin into memory - one multi-line string.
-$_ = do { local $/; <> };
-
-s{^/\*\n \*}{/\*\* \\file\n\\brief};
-s{ \* Copyright}{\\par Copyright\nCopyright};
-
-# Fix any comments like "/*************" so they don't match.
-# "/***" ===> "/* *"
-s{/\*\*\*}{/\* \*}gs;
-
-# The main comment-detection code.
-s{
- ( # $1 = Open comment
- /\*\* # Open comment
- (?!\*) # Do not match /*** (redundant due to fixup above).
- [\t ]*\n? # If 1st line is whitespace, match the lot (including the newline).
- )
- (.*?) # $2 = Body of comment (multi-line)
- ( # $3 = Close comment
- ( # If possible, match the whitespace before the close-comment
- (?<=\n) # This part only matches after a newline
- [\t ]* # Eat whitespace
- )?
- \*/ # Close comment
- )
- }
- {
- $1 . fixcomment($2) . $3
- }gesx;
-# ^^^^ Modes: g - Global, match all occurances.
-# e - Evaluate the replacement as an expression.
-# s - Single-line - allows the pattern to match across newlines.
-# x - eXtended pattern, ignore embedded whitespace
-# and allow comments.
-
-# Write results to stdout
-print $_;
-
diff --git a/contrib/wpa/hostapd/doc/mainpage.doxygen b/contrib/wpa/hostapd/doc/mainpage.doxygen
deleted file mode 100644
index 7cf95de..0000000
--- a/contrib/wpa/hostapd/doc/mainpage.doxygen
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
-\mainpage Developers' documentation for hostapd
-
-hostapd includes IEEE 802.11 access point management (authentication /
-association), IEEE 802.1X/WPA/WPA2 Authenticator, EAP server, and
-RADIUS authentication server functionality. It can be build with
-various configuration option, e.g., a standalone AP management
-solution or a RADIUS authentication server with support for number of
-EAP methods.
-
-The goal of this documentation and comments in the source code is to
-give enough information for other developers to understand how hostapd
-has been implemented, how it can be modified, how new drivers can be
-supported, and how hostapd can be ported to other operating
-systems. If any information is missing, feel free to contact Jouni
-Malinen <j@w1.fi> for more information. Contributions as
-patch files are also very welcome at the same address. Please note
-that hostapd is licensed under dual license, GPLv2 or BSD at user's
-choice. All contributions to hostapd are expected to use compatible
-licensing terms.
-
-The source code and read-only access to hostapd CVS repository
-is available from the project home page at
-http://hostap.epitest.fi/hostapd/. This developers' documentation
-is also available as a PDF file from
-http://hostap.epitest.fi/hostapd/hostapd-devel.pdf .
-
-The design goal for hostapd was to use hardware, driver, and
-OS independent, portable C code for all WPA functionality. The source
-code is divided into separate C files as shown on the \ref
-code_structure "code structure page". All hardware/driver specific
-functionality is in separate files that implement a \ref
-driver_wrapper "well-defined driver API". Information about porting
-to different target boards and operating systems is available on
-the \ref porting "porting page".
-
-EAPOL (IEEE 802.1X) state machines are implemented as a separate
-module that interacts with \ref eap_module "EAP server implementation".
-Similarly, RADIUS authentication server is in its own separate module.
-Both IEEE 802.1X and RADIUS authentication server can use EAP server
-functionality.
-
-hostapd implements a \ref ctrl_iface_page "control interface" that can
-be used by external programs to control the operations of the hostapdt
-daemon and to get status information and event notifications. There is
-a small C library that provides helper functions to facilitate the use
-of the control interface. This library can also be used with C++.
-
-\image html hostapd.png "hostapd modules"
-\image latex hostapd.eps "hostapd modules" width=15cm
-
-*/
diff --git a/contrib/wpa/hostapd/doc/porting.doxygen b/contrib/wpa/hostapd/doc/porting.doxygen
deleted file mode 100644
index 0621791..0000000
--- a/contrib/wpa/hostapd/doc/porting.doxygen
+++ /dev/null
@@ -1,5 +0,0 @@
-/**
-\page porting Porting to different target boards and operating systems
-
-
-*/
diff --git a/contrib/wpa/hostapd/driver.h b/contrib/wpa/hostapd/driver.h
deleted file mode 100644
index 45f5460..0000000
--- a/contrib/wpa/hostapd/driver.h
+++ /dev/null
@@ -1,798 +0,0 @@
-/*
- * hostapd - driver interface definition
- * Copyright (c) 2002-2007, Jouni Malinen <j@w1.fi>
- * Copyright (c) 2007-2008, Intel Corporation
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
- */
-
-#ifndef DRIVER_H
-#define DRIVER_H
-
-struct hostapd_sta_add_params {
- const u8 *addr;
- u16 aid;
- u16 capability;
- const u8 *supp_rates;
- size_t supp_rates_len;
- int flags;
- u16 listen_interval;
- const struct ht_cap_ie *ht_capabilities;
-};
-
-struct hostapd_freq_params {
- int mode;
- int freq;
- int ht_enabled;
- int sec_channel_offset; /* 0 = HT40 disabled, -1 = HT40 enabled,
- * secondary channel below primary, 1 = HT40
- * enabled, secondary channel above primary */
-};
-
-enum hostapd_driver_if_type {
- HOSTAPD_IF_VLAN, HOSTAPD_IF_WDS
-};
-
-struct wpa_driver_ops {
- const char *name; /* as appears in the config file */
-
- void * (*init)(struct hostapd_data *hapd);
- void * (*init_bssid)(struct hostapd_data *hapd, const u8 *bssid);
- void (*deinit)(void *priv);
-
- int (*wireless_event_init)(void *priv);
- void (*wireless_event_deinit)(void *priv);
-
- /**
- * set_8021x - enable/disable IEEE 802.1X support
- * @ifname: Interface name (for multi-SSID/VLAN support)
- * @priv: driver private data
- * @enabled: 1 = enable, 0 = disable
- *
- * Returns: 0 on success, -1 on failure
- *
- * Configure the kernel driver to enable/disable 802.1X support.
- * This may be an empty function if 802.1X support is always enabled.
- */
- int (*set_ieee8021x)(const char *ifname, void *priv, int enabled);
-
- /**
- * set_privacy - enable/disable privacy
- * @priv: driver private data
- * @enabled: 1 = privacy enabled, 0 = disabled
- *
- * Return: 0 on success, -1 on failure
- *
- * Configure privacy.
- */
- int (*set_privacy)(const char *ifname, void *priv, int enabled);
-
- int (*set_encryption)(const char *ifname, void *priv, const char *alg,
- const u8 *addr, int idx,
- const u8 *key, size_t key_len, int txkey);
- int (*get_seqnum)(const char *ifname, void *priv, const u8 *addr,
- int idx, u8 *seq);
- int (*get_seqnum_igtk)(const char *ifname, void *priv, const u8 *addr,
- int idx, u8 *seq);
- int (*flush)(void *priv);
- int (*set_generic_elem)(const char *ifname, void *priv, const u8 *elem,
- size_t elem_len);
-
- int (*read_sta_data)(void *priv, struct hostap_sta_driver_data *data,
- const u8 *addr);
- int (*send_eapol)(void *priv, const u8 *addr, const u8 *data,
- size_t data_len, int encrypt, const u8 *own_addr);
- int (*sta_deauth)(void *priv, const u8 *addr, int reason);
- int (*sta_disassoc)(void *priv, const u8 *addr, int reason);
- int (*sta_remove)(void *priv, const u8 *addr);
- int (*get_ssid)(const char *ifname, void *priv, u8 *buf, int len);
- int (*set_ssid)(const char *ifname, void *priv, const u8 *buf,
- int len);
- int (*set_countermeasures)(void *priv, int enabled);
- int (*send_mgmt_frame)(void *priv, const void *msg, size_t len,
- int flags);
- int (*set_assoc_ap)(void *priv, const u8 *addr);
- /* note: sta_add() is deprecated; use sta_add2() instead */
- int (*sta_add)(const char *ifname, void *priv, const u8 *addr, u16 aid,
- u16 capability, u8 *supp_rates, size_t supp_rates_len,
- int flags, u16 listen_interval);
- int (*sta_add2)(const char *ifname, void *priv,
- struct hostapd_sta_add_params *params);
- int (*get_inact_sec)(void *priv, const u8 *addr);
- int (*sta_clear_stats)(void *priv, const u8 *addr);
-
- /* note: set_freq() is deprecated; use set_freq2() instead */
- int (*set_freq)(void *priv, int mode, int freq);
- int (*set_freq2)(void *priv, struct hostapd_freq_params *freq);
- int (*set_rts)(void *priv, int rts);
- int (*get_rts)(void *priv, int *rts);
- int (*set_frag)(void *priv, int frag);
- int (*get_frag)(void *priv, int *frag);
- int (*set_retry)(void *priv, int short_retry, int long_retry);
- int (*get_retry)(void *priv, int *short_retry, int *long_retry);
-
- int (*sta_set_flags)(void *priv, const u8 *addr,
- int total_flags, int flags_or, int flags_and);
- int (*set_rate_sets)(void *priv, int *supp_rates, int *basic_rates,
- int mode);
- int (*set_regulatory_domain)(void *priv, unsigned int rd);
- int (*set_country)(void *priv, const char *country);
- int (*set_ieee80211d)(void *priv, int enabled);
- int (*set_beacon)(const char *ifname, void *priv,
- u8 *head, size_t head_len,
- u8 *tail, size_t tail_len);
-
- /* Configure internal bridge:
- * 0 = disabled, i.e., client separation is enabled (no bridging of
- * packets between associated STAs
- * 1 = enabled, i.e., bridge packets between associated STAs (default)
- */
- int (*set_internal_bridge)(void *priv, int value);
- int (*set_beacon_int)(void *priv, int value);
- int (*set_dtim_period)(const char *ifname, void *priv, int value);
- /* Configure broadcast SSID mode:
- * 0 = include SSID in Beacon frames and reply to Probe Request frames
- * that use broadcast SSID
- * 1 = hide SSID from Beacon frames and ignore Probe Request frames for
- * broadcast SSID
- */
- int (*set_broadcast_ssid)(void *priv, int value);
- int (*set_cts_protect)(void *priv, int value);
- int (*set_key_tx_rx_threshold)(void *priv, int value);
- int (*set_preamble)(void *priv, int value);
- int (*set_short_slot_time)(void *priv, int value);
- int (*set_tx_queue_params)(void *priv, int queue, int aifs, int cw_min,
- int cw_max, int burst_time);
- int (*bss_add)(void *priv, const char *ifname, const u8 *bssid);
- int (*bss_remove)(void *priv, const char *ifname);
- int (*valid_bss_mask)(void *priv, const u8 *addr, const u8 *mask);
- int (*passive_scan)(void *priv, int now, int our_mode_only,
- int interval, int _listen, int *channel,
- int *last_rx);
- struct hostapd_hw_modes * (*get_hw_feature_data)(void *priv,
- u16 *num_modes,
- u16 *flags);
- int (*if_add)(const char *iface, void *priv,
- enum hostapd_driver_if_type type, char *ifname,
- const u8 *addr);
- int (*if_update)(void *priv, enum hostapd_driver_if_type type,
- char *ifname, const u8 *addr);
- int (*if_remove)(void *priv, enum hostapd_driver_if_type type,
- const char *ifname, const u8 *addr);
- int (*set_sta_vlan)(void *priv, const u8 *addr, const char *ifname,
- int vlan_id);
- /**
- * commit - Optional commit changes handler
- * @priv: driver private data
- * Returns: 0 on success, -1 on failure
- *
- * This optional handler function can be registered if the driver
- * interface implementation needs to commit changes (e.g., by setting
- * network interface up) at the end of initial configuration. If set,
- * this handler will be called after initial setup has been completed.
- */
- int (*commit)(void *priv);
-
- int (*send_ether)(void *priv, const u8 *dst, const u8 *src, u16 proto,
- const u8 *data, size_t data_len);
-
- int (*set_radius_acl_auth)(void *priv, const u8 *mac, int accepted,
- u32 session_timeout);
- int (*set_radius_acl_expire)(void *priv, const u8 *mac);
-
- int (*set_ht_params)(const char *ifname, void *priv,
- const u8 *ht_capab, size_t ht_capab_len,
- const u8 *ht_oper, size_t ht_oper_len);
-
- int (*set_wps_beacon_ie)(const char *ifname, void *priv,
- const u8 *ie, size_t len);
- int (*set_wps_probe_resp_ie)(const char *ifname, void *priv,
- const u8 *ie, size_t len);
-};
-
-static inline void *
-hostapd_driver_init(struct hostapd_data *hapd)
-{
- if (hapd->driver == NULL || hapd->driver->init == NULL)
- return NULL;
- return hapd->driver->init(hapd);
-}
-
-static inline void *
-hostapd_driver_init_bssid(struct hostapd_data *hapd, const u8 *bssid)
-{
- if (hapd->driver == NULL || hapd->driver->init_bssid == NULL)
- return NULL;
- return hapd->driver->init_bssid(hapd, bssid);
-}
-
-static inline void
-hostapd_driver_deinit(struct hostapd_data *hapd)
-{
- if (hapd->driver == NULL || hapd->driver->deinit == NULL)
- return;
- hapd->driver->deinit(hapd->drv_priv);
-}
-
-static inline int
-hostapd_wireless_event_init(struct hostapd_data *hapd)
-{
- if (hapd->driver == NULL ||
- hapd->driver->wireless_event_init == NULL)
- return 0;
- return hapd->driver->wireless_event_init(hapd->drv_priv);
-}
-
-static inline void
-hostapd_wireless_event_deinit(struct hostapd_data *hapd)
-{
- if (hapd->driver == NULL ||
- hapd->driver->wireless_event_deinit == NULL)
- return;
- hapd->driver->wireless_event_deinit(hapd->drv_priv);
-}
-
-static inline int
-hostapd_set_ieee8021x(const char *ifname, struct hostapd_data *hapd,
- int enabled)
-{
- if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
- return 0;
- return hapd->driver->set_ieee8021x(ifname, hapd->drv_priv, enabled);
-}
-
-static inline int
-hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
-{
- if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
- return 0;
- return hapd->driver->set_privacy(hapd->conf->iface, hapd->drv_priv,
- enabled);
-}
-
-static inline int
-hostapd_set_encryption(const char *ifname, struct hostapd_data *hapd,
- const char *alg, const u8 *addr, int idx,
- u8 *key, size_t key_len, int txkey)
-{
- if (hapd->driver == NULL || hapd->driver->set_encryption == NULL)
- return 0;
- return hapd->driver->set_encryption(ifname, hapd->drv_priv, alg, addr,
- idx, key, key_len, txkey);
-}
-
-static inline int
-hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
- const u8 *addr, int idx, u8 *seq)
-{
- if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
- return 0;
- return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx,
- seq);
-}
-
-static inline int
-hostapd_get_seqnum_igtk(const char *ifname, struct hostapd_data *hapd,
- const u8 *addr, int idx, u8 *seq)
-{
- if (hapd->driver == NULL || hapd->driver->get_seqnum_igtk == NULL)
- return -1;
- return hapd->driver->get_seqnum_igtk(ifname, hapd->drv_priv, addr, idx,
- seq);
-}
-
-static inline int
-hostapd_flush(struct hostapd_data *hapd)
-{
- if (hapd->driver == NULL || hapd->driver->flush == NULL)
- return 0;
- return hapd->driver->flush(hapd->drv_priv);
-}
-
-static inline int
-hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
- size_t elem_len)
-{
- if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
- return 0;
- return hapd->driver->set_generic_elem(hapd->conf->iface,
- hapd->drv_priv, elem, elem_len);
-}
-
-static inline int
-hostapd_read_sta_data(struct hostapd_data *hapd,
- struct hostap_sta_driver_data *data, const u8 *addr)
-{
- if (hapd->driver == NULL || hapd->driver->read_sta_data == NULL)
- return -1;
- return hapd->driver->read_sta_data(hapd->drv_priv, data, addr);
-}
-
-static inline int
-hostapd_send_eapol(struct hostapd_data *hapd, const u8 *addr, const u8 *data,
- size_t data_len, int encrypt)
-{
- if (hapd->driver == NULL || hapd->driver->send_eapol == NULL)
- return 0;
- return hapd->driver->send_eapol(hapd->drv_priv, addr, data, data_len,
- encrypt, hapd->own_addr);
-}
-
-static inline int
-hostapd_sta_deauth(struct hostapd_data *hapd, const u8 *addr, int reason)
-{
- if (hapd->driver == NULL || hapd->driver->sta_deauth == NULL)
- return 0;
- return hapd->driver->sta_deauth(hapd->drv_priv, addr, reason);
-}
-
-static inline int
-hostapd_sta_disassoc(struct hostapd_data *hapd, const u8 *addr, int reason)
-{
- if (hapd->driver == NULL || hapd->driver->sta_disassoc == NULL)
- return 0;
- return hapd->driver->sta_disassoc(hapd->drv_priv, addr, reason);
-}
-
-static inline int
-hostapd_sta_remove(struct hostapd_data *hapd, const u8 *addr)
-{
- if (hapd->driver == NULL || hapd->driver->sta_remove == NULL)
- return 0;
- return hapd->driver->sta_remove(hapd->drv_priv, addr);
-}
-
-static inline int
-hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
-{
- if (hapd->driver == NULL || hapd->driver->get_ssid == NULL)
- return 0;
- return hapd->driver->get_ssid(hapd->conf->iface, hapd->drv_priv, buf,
- len);
-}
-
-static inline int
-hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
-{
- if (hapd->driver == NULL || hapd->driver->set_ssid == NULL)
- return 0;
- return hapd->driver->set_ssid(hapd->conf->iface, hapd->drv_priv, buf,
- len);
-}
-
-static inline int
-hostapd_send_mgmt_frame(struct hostapd_data *hapd, const void *msg, size_t len,
- int flags)
-{
- if (hapd->driver == NULL || hapd->driver->send_mgmt_frame == NULL)
- return 0;
- return hapd->driver->send_mgmt_frame(hapd->drv_priv, msg, len, flags);
-}
-
-static inline int
-hostapd_set_assoc_ap(struct hostapd_data *hapd, const u8 *addr)
-{
- if (hapd->driver == NULL || hapd->driver->set_assoc_ap == NULL)
- return 0;
- return hapd->driver->set_assoc_ap(hapd->drv_priv, addr);
-}
-
-static inline int
-hostapd_set_countermeasures(struct hostapd_data *hapd, int enabled)
-{
- if (hapd->driver == NULL || hapd->driver->set_countermeasures == NULL)
- return 0;
- return hapd->driver->set_countermeasures(hapd->drv_priv, enabled);
-}
-
-static inline int
-hostapd_sta_add(const char *ifname, struct hostapd_data *hapd, const u8 *addr,
- u16 aid, u16 capability, const u8 *supp_rates,
- size_t supp_rates_len, int flags, u16 listen_interval,
- const struct ht_cap_ie *ht_capabilities)
-{
- if (hapd->driver == NULL)
- return 0;
-
- if (hapd->driver->sta_add2) {
- struct hostapd_sta_add_params params;
- os_memset(&params, 0, sizeof(params));
- params.addr = addr;
- params.aid = aid;
- params.capability = capability;
- params.supp_rates = supp_rates;
- params.supp_rates_len = supp_rates_len;
- params.flags = flags;
- params.listen_interval = listen_interval;
- params.ht_capabilities = ht_capabilities;
- return hapd->driver->sta_add2(ifname, hapd->drv_priv, &params);
- }
-
- if (hapd->driver->sta_add == NULL)
- return 0;
- return hapd->driver->sta_add(ifname, hapd->drv_priv, addr, aid,
- capability, (u8 *) supp_rates,
- supp_rates_len,
- flags, listen_interval);
-}
-
-static inline int
-hostapd_get_inact_sec(struct hostapd_data *hapd, const u8 *addr)
-{
- if (hapd->driver == NULL || hapd->driver->get_inact_sec == NULL)
- return 0;
- return hapd->driver->get_inact_sec(hapd->drv_priv, addr);
-}
-
-static inline int
-hostapd_set_freq(struct hostapd_data *hapd, int mode, int freq, int ht_enabled,
- int sec_channel_offset)
-{
- if (hapd->driver == NULL)
- return 0;
- if (hapd->driver->set_freq2) {
- struct hostapd_freq_params data;
- os_memset(&data, 0, sizeof(data));
- data.mode = mode;
- data.freq = freq;
- data.ht_enabled = ht_enabled;
- data.sec_channel_offset = sec_channel_offset;
- return hapd->driver->set_freq2(hapd->drv_priv, &data);
- }
-
- if (hapd->driver->set_freq == NULL)
- return 0;
- return hapd->driver->set_freq(hapd->drv_priv, mode, freq);
-}
-
-static inline int
-hostapd_set_rts(struct hostapd_data *hapd, int rts)
-{
- if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
- return 0;
- return hapd->driver->set_rts(hapd->drv_priv, rts);
-}
-
-static inline int
-hostapd_get_rts(struct hostapd_data *hapd, int *rts)
-{
- if (hapd->driver == NULL || hapd->driver->get_rts == NULL)
- return 0;
- return hapd->driver->get_rts(hapd->drv_priv, rts);
-}
-
-static inline int
-hostapd_set_frag(struct hostapd_data *hapd, int frag)
-{
- if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
- return 0;
- return hapd->driver->set_frag(hapd->drv_priv, frag);
-}
-
-static inline int
-hostapd_get_frag(struct hostapd_data *hapd, int *frag)
-{
- if (hapd->driver == NULL || hapd->driver->get_frag == NULL)
- return 0;
- return hapd->driver->get_frag(hapd->drv_priv, frag);
-}
-
-static inline int
-hostapd_set_retry(struct hostapd_data *hapd, int short_retry, int long_retry)
-{
- if (hapd->driver == NULL || hapd->driver->set_retry == NULL)
- return 0;
- return hapd->driver->set_retry(hapd->drv_priv, short_retry,
- long_retry);
-}
-
-static inline int
-hostapd_get_retry(struct hostapd_data *hapd, int *short_retry, int *long_retry)
-{
- if (hapd->driver == NULL || hapd->driver->get_retry == NULL)
- return 0;
- return hapd->driver->get_retry(hapd->drv_priv, short_retry,
- long_retry);
-}
-
-static inline int
-hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
- int total_flags, int flags_or, int flags_and)
-{
- if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
- return 0;
- return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
- flags_or, flags_and);
-}
-
-static inline int
-hostapd_set_rate_sets(struct hostapd_data *hapd, int *supp_rates,
- int *basic_rates, int mode)
-{
- if (hapd->driver == NULL || hapd->driver->set_rate_sets == NULL)
- return 0;
- return hapd->driver->set_rate_sets(hapd->drv_priv, supp_rates,
- basic_rates, mode);
-}
-
-static inline int
-hostapd_set_regulatory_domain(struct hostapd_data *hapd, unsigned int rd)
-{
- if (hapd->driver == NULL ||
- hapd->driver->set_regulatory_domain == NULL)
- return 0;
- return hapd->driver->set_regulatory_domain(hapd->drv_priv, rd);
-}
-
-static inline int
-hostapd_set_country(struct hostapd_data *hapd, const char *country)
-{
- if (hapd->driver == NULL ||
- hapd->driver->set_country == NULL)
- return 0;
- return hapd->driver->set_country(hapd->drv_priv, country);
-}
-
-static inline int
-hostapd_set_ieee80211d(struct hostapd_data *hapd, int enabled)
-{
- if (hapd->driver == NULL ||
- hapd->driver->set_ieee80211d == NULL)
- return 0;
- return hapd->driver->set_ieee80211d(hapd->drv_priv, enabled);
-}
-
-static inline int
-hostapd_sta_clear_stats(struct hostapd_data *hapd, const u8 *addr)
-{
- if (hapd->driver == NULL || hapd->driver->sta_clear_stats == NULL)
- return 0;
- return hapd->driver->sta_clear_stats(hapd->drv_priv, addr);
-}
-
-static inline int
-hostapd_set_beacon(const char *ifname, struct hostapd_data *hapd,
- u8 *head, size_t head_len,
- u8 *tail, size_t tail_len)
-{
- if (hapd->driver == NULL || hapd->driver->set_beacon == NULL)
- return 0;
- return hapd->driver->set_beacon(ifname, hapd->drv_priv, head, head_len,
- tail, tail_len);
-}
-
-static inline int
-hostapd_set_internal_bridge(struct hostapd_data *hapd, int value)
-{
- if (hapd->driver == NULL || hapd->driver->set_internal_bridge == NULL)
- return 0;
- return hapd->driver->set_internal_bridge(hapd->drv_priv, value);
-}
-
-static inline int
-hostapd_set_beacon_int(struct hostapd_data *hapd, int value)
-{
- if (hapd->driver == NULL || hapd->driver->set_beacon_int == NULL)
- return 0;
- return hapd->driver->set_beacon_int(hapd->drv_priv, value);
-}
-
-static inline int
-hostapd_set_dtim_period(struct hostapd_data *hapd, int value)
-{
- if (hapd->driver == NULL || hapd->driver->set_dtim_period == NULL)
- return 0;
- return hapd->driver->set_dtim_period(hapd->conf->iface, hapd->drv_priv,
- value);
-}
-
-static inline int
-hostapd_set_broadcast_ssid(struct hostapd_data *hapd, int value)
-{
- if (hapd->driver == NULL || hapd->driver->set_broadcast_ssid == NULL)
- return 0;
- return hapd->driver->set_broadcast_ssid(hapd->drv_priv, value);
-}
-
-static inline int
-hostapd_set_cts_protect(struct hostapd_data *hapd, int value)
-{
- if (hapd->driver == NULL || hapd->driver->set_cts_protect == NULL)
- return 0;
- return hapd->driver->set_cts_protect(hapd->drv_priv, value);
-}
-
-static inline int
-hostapd_set_key_tx_rx_threshold(struct hostapd_data *hapd, int value)
-{
- if (hapd->driver == NULL ||
- hapd->driver->set_key_tx_rx_threshold == NULL)
- return 0;
- return hapd->driver->set_key_tx_rx_threshold(hapd->drv_priv, value);
-}
-
-static inline int
-hostapd_set_preamble(struct hostapd_data *hapd, int value)
-{
- if (hapd->driver == NULL || hapd->driver->set_preamble == NULL)
- return 0;
- return hapd->driver->set_preamble(hapd->drv_priv, value);
-}
-
-static inline int
-hostapd_set_short_slot_time(struct hostapd_data *hapd, int value)
-{
- if (hapd->driver == NULL || hapd->driver->set_short_slot_time == NULL)
- return 0;
- return hapd->driver->set_short_slot_time(hapd->drv_priv, value);
-}
-
-static inline int
-hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
- int cw_min, int cw_max, int burst_time)
-{
- if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
- return 0;
- return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
- cw_min, cw_max, burst_time);
-}
-
-static inline int
-hostapd_bss_add(struct hostapd_data *hapd, const char *ifname, const u8 *bssid)
-{
- if (hapd->driver == NULL || hapd->driver->bss_add == NULL)
- return 0;
- return hapd->driver->bss_add(hapd->drv_priv, ifname, bssid);
-}
-
-static inline int
-hostapd_bss_remove(struct hostapd_data *hapd, const char *ifname)
-{
- if (hapd->driver == NULL || hapd->driver->bss_remove == NULL)
- return 0;
- return hapd->driver->bss_remove(hapd->drv_priv, ifname);
-}
-
-static inline int
-hostapd_valid_bss_mask(struct hostapd_data *hapd, const u8 *addr,
- const u8 *mask)
-{
- if (hapd->driver == NULL || hapd->driver->valid_bss_mask == NULL)
- return 1;
- return hapd->driver->valid_bss_mask(hapd->drv_priv, addr, mask);
-}
-
-static inline int
-hostapd_if_add(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
- char *ifname, const u8 *addr)
-{
- if (hapd->driver == NULL || hapd->driver->if_add == NULL)
- return -1;
- return hapd->driver->if_add(hapd->conf->iface, hapd->drv_priv, type,
- ifname, addr);
-}
-
-static inline int
-hostapd_if_update(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
- char *ifname, const u8 *addr)
-{
- if (hapd->driver == NULL || hapd->driver->if_update == NULL)
- return -1;
- return hapd->driver->if_update(hapd->drv_priv, type, ifname, addr);
-}
-
-static inline int
-hostapd_if_remove(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
- char *ifname, const u8 *addr)
-{
- if (hapd->driver == NULL || hapd->driver->if_remove == NULL)
- return -1;
- return hapd->driver->if_remove(hapd->drv_priv, type, ifname, addr);
-}
-
-static inline int
-hostapd_passive_scan(struct hostapd_data *hapd, int now, int our_mode_only,
- int interval, int _listen, int *channel,
- int *last_rx)
-{
- if (hapd->driver == NULL || hapd->driver->passive_scan == NULL)
- return -1;
- return hapd->driver->passive_scan(hapd->drv_priv, now, our_mode_only,
- interval, _listen, channel, last_rx);
-}
-
-static inline struct hostapd_hw_modes *
-hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
- u16 *flags)
-{
- if (hapd->driver == NULL || hapd->driver->get_hw_feature_data == NULL)
- return NULL;
- return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
- flags);
-}
-
-static inline int
-hostapd_set_sta_vlan(const char *ifname, struct hostapd_data *hapd,
- const u8 *addr, int vlan_id)
-{
- if (hapd->driver == NULL || hapd->driver->set_sta_vlan == NULL)
- return 0;
- return hapd->driver->set_sta_vlan(hapd->drv_priv, addr, ifname, vlan_id);
-}
-
-static inline int
-hostapd_driver_commit(struct hostapd_data *hapd)
-{
- if (hapd->driver == NULL || hapd->driver->commit == NULL)
- return 0;
- return hapd->driver->commit(hapd->drv_priv);
-}
-
-static inline int
-hostapd_set_radius_acl_auth(struct hostapd_data *hapd, const u8 *mac,
- int accepted, u32 session_timeout)
-{
- if (hapd->driver == NULL || hapd->driver->set_radius_acl_auth == NULL)
- return 0;
- return hapd->driver->set_radius_acl_auth(hapd->drv_priv, mac, accepted,
- session_timeout);
-}
-
-static inline int
-hostapd_set_radius_acl_expire(struct hostapd_data *hapd, const u8 *mac)
-{
- if (hapd->driver == NULL ||
- hapd->driver->set_radius_acl_expire == NULL)
- return 0;
- return hapd->driver->set_radius_acl_expire(hapd->drv_priv, mac);
-}
-
-#ifdef CONFIG_IEEE80211N
-static inline int
-hostapd_set_ht_params(const char *ifname, struct hostapd_data *hapd,
- const u8 *ht_capab, size_t ht_capab_len,
- const u8 *ht_oper, size_t ht_oper_len)
-{
- if (hapd->driver == NULL || hapd->driver->set_ht_params == NULL ||
- ht_capab == NULL || ht_oper == NULL)
- return 0;
- return hapd->driver->set_ht_params(
- ifname, hapd->drv_priv, ht_capab, ht_capab_len,
- ht_oper, ht_oper_len);
-}
-#endif /* CONFIG_IEEE80211N */
-
-static inline int
-hostapd_drv_none(struct hostapd_data *hapd)
-{
- return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
-}
-
-static inline int
-hostapd_set_wps_beacon_ie(struct hostapd_data *hapd, const u8 *ie, size_t len)
-{
- if (hapd->driver == NULL || hapd->driver->set_wps_beacon_ie == NULL)
- return 0;
- return hapd->driver->set_wps_beacon_ie(hapd->conf->iface,
- hapd->drv_priv, ie, len);
-}
-
-static inline int
-hostapd_set_wps_probe_resp_ie(struct hostapd_data *hapd, const u8 *ie,
- size_t len)
-{
- if (hapd->driver == NULL ||
- hapd->driver->set_wps_probe_resp_ie == NULL)
- return 0;
- return hapd->driver->set_wps_probe_resp_ie(hapd->conf->iface,
- hapd->drv_priv, ie, len);
-}
-
-#endif /* DRIVER_H */
diff --git a/contrib/wpa/hostapd/driver_bsd.c b/contrib/wpa/hostapd/driver_bsd.c
deleted file mode 100644
index 43d57d9..0000000
--- a/contrib/wpa/hostapd/driver_bsd.c
+++ /dev/null
@@ -1,839 +0,0 @@
-/*
- * hostapd / Driver interaction with BSD net80211 layer
- * Copyright (c) 2004, Sam Leffler <sam@errno.com>
- * Copyright (c) 2004, 2Wire, Inc
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
- */
-
-#include "includes.h"
-#include <sys/ioctl.h>
-
-#include <net/if.h>
-
-#include <net80211/ieee80211.h>
-#include <net80211/ieee80211_crypto.h>
-#include <net80211/ieee80211_ioctl.h>
-
-/*
- * Avoid conflicts with hostapd definitions by undefining couple of defines
- * from net80211 header files.
- */
-#undef RSN_VERSION
-#undef WPA_VERSION
-#undef WPA_OUI_TYPE
-#undef WME_OUI_TYPE
-
-#include "hostapd.h"
-#include "driver.h"
-#include "ieee802_1x.h"
-#include "eloop.h"
-#include "sta_info.h"
-#include "l2_packet/l2_packet.h"
-
-#include "eapol_sm.h"
-#include "wpa.h"
-#include "radius/radius.h"
-#include "ieee802_11.h"
-#include "common.h"
-
-struct bsd_driver_data {
- struct hostapd_data *hapd; /* back pointer */
-
- char iface[IFNAMSIZ + 1];
- struct l2_packet_data *sock_xmit; /* raw packet xmit socket */
- int ioctl_sock; /* socket for ioctl() use */
- int wext_sock; /* socket for wireless events */
-};
-
-static int bsd_sta_deauth(void *priv, const u8 *addr, int reason_code);
-
-static int
-set80211var(struct bsd_driver_data *drv, int op, const void *arg, int arg_len)
-{
- struct ieee80211req ireq;
-
- memset(&ireq, 0, sizeof(ireq));
- os_strlcpy(ireq.i_name, drv->iface, IFNAMSIZ);
- ireq.i_type = op;
- ireq.i_len = arg_len;
- ireq.i_data = (void *) arg;
-
- if (ioctl(drv->ioctl_sock, SIOCS80211, &ireq) < 0) {
- perror("ioctl[SIOCS80211]");
- return -1;
- }
- return 0;
-}
-
-static int
-get80211var(struct bsd_driver_data *drv, int op, void *arg, int arg_len)
-{
- struct ieee80211req ireq;
-
- memset(&ireq, 0, sizeof(ireq));
- os_strlcpy(ireq.i_name, drv->iface, IFNAMSIZ);
- ireq.i_type = op;
- ireq.i_len = arg_len;
- ireq.i_data = arg;
-
- if (ioctl(drv->ioctl_sock, SIOCG80211, &ireq) < 0) {
- perror("ioctl[SIOCG80211]");
- return -1;
- }
- return ireq.i_len;
-}
-
-static int
-set80211param(struct bsd_driver_data *drv, int op, int arg)
-{
- struct ieee80211req ireq;
-
- memset(&ireq, 0, sizeof(ireq));
- os_strlcpy(ireq.i_name, drv->iface, IFNAMSIZ);
- ireq.i_type = op;
- ireq.i_val = arg;
-
- if (ioctl(drv->ioctl_sock, SIOCS80211, &ireq) < 0) {
- perror("ioctl[SIOCS80211]");
- return -1;
- }
- return 0;
-}
-
-static const char *
-ether_sprintf(const u8 *addr)
-{
- static char buf[sizeof(MACSTR)];
-
- if (addr != NULL)
- snprintf(buf, sizeof(buf), MACSTR, MAC2STR(addr));
- else
- snprintf(buf, sizeof(buf), MACSTR, 0,0,0,0,0,0);
- return buf;
-}
-
-/*
- * Configure WPA parameters.
- */
-static int
-bsd_configure_wpa(struct bsd_driver_data *drv)
-{
- static const char *ciphernames[] =
- { "WEP", "TKIP", "AES-OCB", "AES-CCM", "CKIP", "NONE" };
- struct hostapd_data *hapd = drv->hapd;
- struct hostapd_bss_config *conf = hapd->conf;
- int v;
-
- switch (conf->wpa_group) {
- case WPA_CIPHER_CCMP:
- v = IEEE80211_CIPHER_AES_CCM;
- break;
- case WPA_CIPHER_TKIP:
- v = IEEE80211_CIPHER_TKIP;
- break;
- case WPA_CIPHER_WEP104:
- v = IEEE80211_CIPHER_WEP;
- break;
- case WPA_CIPHER_WEP40:
- v = IEEE80211_CIPHER_WEP;
- break;
- case WPA_CIPHER_NONE:
- v = IEEE80211_CIPHER_NONE;
- break;
- default:
- printf("Unknown group key cipher %u\n",
- conf->wpa_group);
- return -1;
- }
- wpa_printf(MSG_DEBUG, "%s: group key cipher=%s (%u)",
- __func__, ciphernames[v], v);
- if (set80211param(drv, IEEE80211_IOC_MCASTCIPHER, v)) {
- printf("Unable to set group key cipher to %u (%s)\n",
- v, ciphernames[v]);
- return -1;
- }
- if (v == IEEE80211_CIPHER_WEP) {
- /* key length is done only for specific ciphers */
- v = (conf->wpa_group == WPA_CIPHER_WEP104 ? 13 : 5);
- if (set80211param(drv, IEEE80211_IOC_MCASTKEYLEN, v)) {
- printf("Unable to set group key length to %u\n", v);
- return -1;
- }
- }
-
- v = 0;
- if (conf->wpa_pairwise & WPA_CIPHER_CCMP)
- v |= 1<<IEEE80211_CIPHER_AES_CCM;
- if (conf->wpa_pairwise & WPA_CIPHER_TKIP)
- v |= 1<<IEEE80211_CIPHER_TKIP;
- if (conf->wpa_pairwise & WPA_CIPHER_NONE)
- v |= 1<<IEEE80211_CIPHER_NONE;
- wpa_printf(MSG_DEBUG, "%s: pairwise key ciphers=0x%x", __func__, v);
- if (set80211param(drv, IEEE80211_IOC_UCASTCIPHERS, v)) {
- printf("Unable to set pairwise key ciphers to 0x%x\n", v);
- return -1;
- }
-
- wpa_printf(MSG_DEBUG, "%s: key management algorithms=0x%x",
- __func__, conf->wpa_key_mgmt);
- if (set80211param(drv, IEEE80211_IOC_KEYMGTALGS, conf->wpa_key_mgmt)) {
- printf("Unable to set key management algorithms to 0x%x\n",
- conf->wpa_key_mgmt);
- return -1;
- }
-
- v = 0;
- if (conf->rsn_preauth)
- v |= BIT(0);
- wpa_printf(MSG_DEBUG, "%s: rsn capabilities=0x%x",
- __func__, conf->rsn_preauth);
- if (set80211param(drv, IEEE80211_IOC_RSNCAPS, v)) {
- printf("Unable to set RSN capabilities to 0x%x\n", v);
- return -1;
- }
-
- wpa_printf(MSG_DEBUG, "%s: enable WPA= 0x%x", __func__, conf->wpa);
- if (set80211param(drv, IEEE80211_IOC_WPA, conf->wpa)) {
- printf("Unable to set WPA to %u\n", conf->wpa);
- return -1;
- }
- return 0;
-}
-
-
-static int
-bsd_set_iface_flags(void *priv, int dev_up)
-{
- struct bsd_driver_data *drv = priv;
- struct ifreq ifr;
-
- wpa_printf(MSG_DEBUG, "%s: dev_up=%d", __func__, dev_up);
-
- if (drv->ioctl_sock < 0)
- return -1;
-
- memset(&ifr, 0, sizeof(ifr));
- os_strlcpy(ifr.ifr_name, drv->iface, IFNAMSIZ);
-
- if (ioctl(drv->ioctl_sock, SIOCGIFFLAGS, &ifr) != 0) {
- perror("ioctl[SIOCGIFFLAGS]");
- return -1;
- }
-
- if (dev_up)
- ifr.ifr_flags |= IFF_UP;
- else
- ifr.ifr_flags &= ~IFF_UP;
-
- if (ioctl(drv->ioctl_sock, SIOCSIFFLAGS, &ifr) != 0) {
- perror("ioctl[SIOCSIFFLAGS]");
- return -1;
- }
-
- if (dev_up) {
- memset(&ifr, 0, sizeof(ifr));
- os_strlcpy(ifr.ifr_name, drv->iface, IFNAMSIZ);
- ifr.ifr_mtu = HOSTAPD_MTU;
- if (ioctl(drv->ioctl_sock, SIOCSIFMTU, &ifr) != 0) {
- perror("ioctl[SIOCSIFMTU]");
- printf("Setting MTU failed - trying to survive with "
- "current value\n");
- }
- }
-
- return 0;
-}
-
-static int
-bsd_set_ieee8021x(const char *ifname, void *priv, int enabled)
-{
- struct bsd_driver_data *drv = priv;
- struct hostapd_data *hapd = drv->hapd;
- struct hostapd_bss_config *conf = hapd->conf;
-
- wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled);
-
- if (!enabled) {
- /* XXX restore state */
- return set80211param(priv, IEEE80211_IOC_AUTHMODE,
- IEEE80211_AUTH_AUTO);
- }
- if (!conf->wpa && !conf->ieee802_1x) {
- hostapd_logger(hapd, NULL, HOSTAPD_MODULE_DRIVER,
- HOSTAPD_LEVEL_WARNING, "No 802.1X or WPA enabled!");
- return -1;
- }
- if (conf->wpa && bsd_configure_wpa(drv) != 0) {
- hostapd_logger(hapd, NULL, HOSTAPD_MODULE_DRIVER,
- HOSTAPD_LEVEL_WARNING, "Error configuring WPA state!");
- return -1;
- }
- if (set80211param(priv, IEEE80211_IOC_AUTHMODE,
- (conf->wpa ? IEEE80211_AUTH_WPA : IEEE80211_AUTH_8021X))) {
- hostapd_logger(hapd, NULL, HOSTAPD_MODULE_DRIVER,
- HOSTAPD_LEVEL_WARNING, "Error enabling WPA/802.1X!");
- return -1;
- }
- return bsd_set_iface_flags(priv, 1);
-}
-
-static int
-bsd_set_privacy(const char *ifname, void *priv, int enabled)
-{
- struct bsd_driver_data *drv = priv;
-
- wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled);
-
- return set80211param(drv, IEEE80211_IOC_PRIVACY, enabled);
-}
-
-static int
-bsd_set_sta_authorized(void *priv, const u8 *addr, int authorized)
-{
- struct bsd_driver_data *drv = priv;
- struct ieee80211req_mlme mlme;
-
- wpa_printf(MSG_DEBUG, "%s: addr=%s authorized=%d",
- __func__, ether_sprintf(addr), authorized);
-
- if (authorized)
- mlme.im_op = IEEE80211_MLME_AUTHORIZE;
- else
- mlme.im_op = IEEE80211_MLME_UNAUTHORIZE;
- mlme.im_reason = 0;
- memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
- return set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
-}
-
-static int
-bsd_sta_set_flags(void *priv, const u8 *addr, int total_flags, int flags_or,
- int flags_and)
-{
- /* For now, only support setting Authorized flag */
- if (flags_or & WLAN_STA_AUTHORIZED)
- return bsd_set_sta_authorized(priv, addr, 1);
- if (!(flags_and & WLAN_STA_AUTHORIZED))
- return bsd_set_sta_authorized(priv, addr, 0);
- return 0;
-}
-
-static int
-bsd_del_key(void *priv, const u8 *addr, int key_idx)
-{
- struct bsd_driver_data *drv = priv;
- struct ieee80211req_del_key wk;
-
- wpa_printf(MSG_DEBUG, "%s: addr=%s key_idx=%d",
- __func__, ether_sprintf(addr), key_idx);
-
- memset(&wk, 0, sizeof(wk));
- if (addr != NULL) {
- memcpy(wk.idk_macaddr, addr, IEEE80211_ADDR_LEN);
- wk.idk_keyix = (u_int8_t) IEEE80211_KEYIX_NONE; /* XXX */
- } else {
- wk.idk_keyix = key_idx;
- }
-
- return set80211var(drv, IEEE80211_IOC_DELKEY, &wk, sizeof(wk));
-}
-
-static int
-bsd_set_key(const char *ifname, void *priv, const char *alg,
- const u8 *addr, int key_idx,
- const u8 *key, size_t key_len, int txkey)
-{
- struct bsd_driver_data *drv = priv;
- struct ieee80211req_key wk;
- u_int8_t cipher;
-
- if (strcmp(alg, "none") == 0)
- return bsd_del_key(drv, addr, key_idx);
-
- wpa_printf(MSG_DEBUG, "%s: alg=%s addr=%s key_idx=%d",
- __func__, alg, ether_sprintf(addr), key_idx);
-
- if (strcmp(alg, "WEP") == 0)
- cipher = IEEE80211_CIPHER_WEP;
- else if (strcmp(alg, "TKIP") == 0)
- cipher = IEEE80211_CIPHER_TKIP;
- else if (strcmp(alg, "CCMP") == 0)
- cipher = IEEE80211_CIPHER_AES_CCM;
- else {
- printf("%s: unknown/unsupported algorithm %s\n",
- __func__, alg);
- return -1;
- }
-
- if (key_len > sizeof(wk.ik_keydata)) {
- printf("%s: key length %d too big\n", __func__, key_len);
- return -3;
- }
-
- memset(&wk, 0, sizeof(wk));
- wk.ik_type = cipher;
- wk.ik_flags = IEEE80211_KEY_RECV | IEEE80211_KEY_XMIT;
- if (addr == NULL) {
- memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
- wk.ik_keyix = key_idx;
- wk.ik_flags |= IEEE80211_KEY_DEFAULT;
- } else {
- memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
- wk.ik_keyix = IEEE80211_KEYIX_NONE;
- }
- wk.ik_keylen = key_len;
- memcpy(wk.ik_keydata, key, key_len);
-
- return set80211var(drv, IEEE80211_IOC_WPAKEY, &wk, sizeof(wk));
-}
-
-
-static int
-bsd_get_seqnum(const char *ifname, void *priv, const u8 *addr, int idx,
- u8 *seq)
-{
- struct bsd_driver_data *drv = priv;
- struct ieee80211req_key wk;
-
- wpa_printf(MSG_DEBUG, "%s: addr=%s idx=%d",
- __func__, ether_sprintf(addr), idx);
-
- memset(&wk, 0, sizeof(wk));
- if (addr == NULL)
- memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
- else
- memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
- wk.ik_keyix = idx;
-
- if (get80211var(drv, IEEE80211_IOC_WPAKEY, &wk, sizeof(wk)) < 0) {
- printf("Failed to get encryption.\n");
- return -1;
- }
-
-#ifdef WORDS_BIGENDIAN
- {
- /*
- * wk.ik_keytsc is in host byte order (big endian), need to
- * swap it to match with the byte order used in WPA.
- */
- int i;
- u8 tmp[WPA_KEY_RSC_LEN];
- memcpy(tmp, &wk.ik_keytsc, sizeof(wk.ik_keytsc));
- for (i = 0; i < WPA_KEY_RSC_LEN; i++) {
- seq[i] = tmp[WPA_KEY_RSC_LEN - i - 1];
- }
- }
-#else /* WORDS_BIGENDIAN */
- memcpy(seq, &wk.ik_keytsc, sizeof(wk.ik_keytsc));
-#endif /* WORDS_BIGENDIAN */
- return 0;
-}
-
-
-static int
-bsd_flush(void *priv)
-{
- u8 allsta[IEEE80211_ADDR_LEN];
-
- memset(allsta, 0xff, IEEE80211_ADDR_LEN);
- return bsd_sta_deauth(priv, allsta, IEEE80211_REASON_AUTH_LEAVE);
-}
-
-
-static int
-bsd_read_sta_driver_data(void *priv, struct hostap_sta_driver_data *data,
- const u8 *addr)
-{
- struct bsd_driver_data *drv = priv;
- struct ieee80211req_sta_stats stats;
-
- memcpy(stats.is_u.macaddr, addr, IEEE80211_ADDR_LEN);
- if (get80211var(drv, IEEE80211_IOC_STA_STATS, &stats, sizeof(stats)) > 0) {
- /* XXX? do packets counts include non-data frames? */
- data->rx_packets = stats.is_stats.ns_rx_data;
- data->rx_bytes = stats.is_stats.ns_rx_bytes;
- data->tx_packets = stats.is_stats.ns_tx_data;
- data->tx_bytes = stats.is_stats.ns_tx_bytes;
- }
- return 0;
-}
-
-static int
-bsd_set_opt_ie(const char *ifname, void *priv, const u8 *ie, size_t ie_len)
-{
- /*
- * Do nothing; we setup parameters at startup that define the
- * contents of the beacon information element.
- */
- return 0;
-}
-
-static int
-bsd_sta_deauth(void *priv, const u8 *addr, int reason_code)
-{
- struct bsd_driver_data *drv = priv;
- struct ieee80211req_mlme mlme;
-
- wpa_printf(MSG_DEBUG, "%s: addr=%s reason_code=%d",
- __func__, ether_sprintf(addr), reason_code);
-
- mlme.im_op = IEEE80211_MLME_DEAUTH;
- mlme.im_reason = reason_code;
- memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
- return set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
-}
-
-static int
-bsd_sta_disassoc(void *priv, const u8 *addr, int reason_code)
-{
- struct bsd_driver_data *drv = priv;
- struct ieee80211req_mlme mlme;
-
- wpa_printf(MSG_DEBUG, "%s: addr=%s reason_code=%d",
- __func__, ether_sprintf(addr), reason_code);
-
- mlme.im_op = IEEE80211_MLME_DISASSOC;
- mlme.im_reason = reason_code;
- memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
- return set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
-}
-
-static int
-bsd_del_sta(struct bsd_driver_data *drv, u8 addr[IEEE80211_ADDR_LEN])
-{
- struct hostapd_data *hapd = drv->hapd;
- struct hostapd_bss_config *conf = hapd->conf;
- struct sta_info *sta;
-
- hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
- HOSTAPD_LEVEL_INFO, "deassociated");
-
- sta = ap_get_sta(hapd, addr);
- if (sta != NULL) {
- sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
- if (conf->wpa)
- wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
- sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
- ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
- ap_free_sta(hapd, sta);
- }
- return 0;
-}
-
-static int
-bsd_new_sta(struct bsd_driver_data *drv, u8 addr[IEEE80211_ADDR_LEN])
-{
- struct hostapd_data *hapd = drv->hapd;
- struct hostapd_bss_config *conf = hapd->conf;
- struct sta_info *sta;
- struct ieee80211req_wpaie ie;
- int new_assoc, ielen, res;
-
- hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
- HOSTAPD_LEVEL_INFO, "associated");
-
- sta = ap_sta_add(hapd, addr);
- if (sta == NULL)
- return -1;
- /*
- * Fetch and validate any negotiated WPA/RSN parameters.
- */
- if (conf->wpa) {
- memset(&ie, 0, sizeof(ie));
- memcpy(ie.wpa_macaddr, addr, IEEE80211_ADDR_LEN);
- if (get80211var(drv, IEEE80211_IOC_WPAIE, &ie, sizeof(ie)) < 0) {
- printf("Failed to get WPA/RSN information element.\n");
- return -1; /* XXX not right */
- }
- ielen = ie.wpa_ie[1];
- if (ielen == 0) {
- printf("No WPA/RSN information element for station!\n");
- return -1; /* XXX not right */
- }
- ielen += 2;
- if (sta->wpa_sm == NULL)
- sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
- sta->addr);
- if (sta->wpa_sm == NULL) {
- printf("Failed to initialize WPA state machine\n");
- return -1;
- }
- res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
- ie.wpa_ie, ielen, NULL, 0);
- if (res != WPA_IE_OK) {
- printf("WPA/RSN information element rejected? "
- "(res %u)\n", res);
- return -1;
- }
- }
-
- /*
- * Now that the internal station state is setup
- * kick the authenticator into action.
- */
- new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
- sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
- wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
- hostapd_new_assoc_sta(hapd, sta, !new_assoc);
- ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
- return 0;
-}
-
-#include <net/route.h>
-#include <net80211/ieee80211_freebsd.h>
-
-static void
-bsd_wireless_event_receive(int sock, void *ctx, void *sock_ctx)
-{
- struct bsd_driver_data *drv = ctx;
- struct hostapd_data *hapd = drv->hapd;
- char buf[2048];
- struct if_announcemsghdr *ifan;
- struct rt_msghdr *rtm;
- struct ieee80211_michael_event *mic;
- struct ieee80211_join_event *join;
- struct ieee80211_leave_event *leave;
- int n;
-
- n = read(sock, buf, sizeof(buf));
- if (n < 0) {
- if (errno != EINTR && errno != EAGAIN)
- perror("read(PF_ROUTE)");
- return;
- }
-
- rtm = (struct rt_msghdr *) buf;
- if (rtm->rtm_version != RTM_VERSION) {
- wpa_printf(MSG_DEBUG, "Routing message version %d not "
- "understood\n", rtm->rtm_version);
- return;
- }
- ifan = (struct if_announcemsghdr *) rtm;
- switch (rtm->rtm_type) {
- case RTM_IEEE80211:
- switch (ifan->ifan_what) {
- case RTM_IEEE80211_ASSOC:
- case RTM_IEEE80211_REASSOC:
- case RTM_IEEE80211_DISASSOC:
- case RTM_IEEE80211_SCAN:
- break;
- case RTM_IEEE80211_LEAVE:
- leave = (struct ieee80211_leave_event *) &ifan[1];
- bsd_del_sta(drv, leave->iev_addr);
- break;
- case RTM_IEEE80211_JOIN:
-#ifdef RTM_IEEE80211_REJOIN
- case RTM_IEEE80211_REJOIN:
-#endif
- join = (struct ieee80211_join_event *) &ifan[1];
- bsd_new_sta(drv, join->iev_addr);
- break;
- case RTM_IEEE80211_REPLAY:
- /* ignore */
- break;
- case RTM_IEEE80211_MICHAEL:
- mic = (struct ieee80211_michael_event *) &ifan[1];
- wpa_printf(MSG_DEBUG,
- "Michael MIC failure wireless event: "
- "keyix=%u src_addr=" MACSTR, mic->iev_keyix,
- MAC2STR(mic->iev_src));
- ieee80211_michael_mic_failure(hapd, mic->iev_src, 1);
- break;
- }
- break;
- }
-}
-
-static int
-bsd_wireless_event_init(void *priv)
-{
- struct bsd_driver_data *drv = priv;
- int s;
-
- drv->wext_sock = -1;
-
- s = socket(PF_ROUTE, SOCK_RAW, 0);
- if (s < 0) {
- perror("socket(PF_ROUTE,SOCK_RAW)");
- return -1;
- }
- eloop_register_read_sock(s, bsd_wireless_event_receive, drv, NULL);
- drv->wext_sock = s;
-
- return 0;
-}
-
-static void
-bsd_wireless_event_deinit(void *priv)
-{
- struct bsd_driver_data *drv = priv;
-
- if (drv != NULL) {
- if (drv->wext_sock < 0)
- return;
- eloop_unregister_read_sock(drv->wext_sock);
- close(drv->wext_sock);
- }
-}
-
-
-static int
-bsd_send_eapol(void *priv, const u8 *addr, const u8 *data, size_t data_len,
- int encrypt, const u8 *own_addr)
-{
- struct bsd_driver_data *drv = priv;
- unsigned char buf[3000];
- unsigned char *bp = buf;
- struct l2_ethhdr *eth;
- size_t len;
- int status;
-
- /*
- * Prepend the Etherent header. If the caller left us
- * space at the front we could just insert it but since
- * we don't know we copy to a local buffer. Given the frequency
- * and size of frames this probably doesn't matter.
- */
- len = data_len + sizeof(struct l2_ethhdr);
- if (len > sizeof(buf)) {
- bp = malloc(len);
- if (bp == NULL) {
- printf("EAPOL frame discarded, cannot malloc temp "
- "buffer of size %u!\n", len);
- return -1;
- }
- }
- eth = (struct l2_ethhdr *) bp;
- memcpy(eth->h_dest, addr, ETH_ALEN);
- memcpy(eth->h_source, own_addr, ETH_ALEN);
- eth->h_proto = htons(ETH_P_EAPOL);
- memcpy(eth+1, data, data_len);
-
- wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", bp, len);
-
- status = l2_packet_send(drv->sock_xmit, addr, ETH_P_EAPOL, bp, len);
-
- if (bp != buf)
- free(bp);
- return status;
-}
-
-static void
-handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
-{
- struct bsd_driver_data *drv = ctx;
- struct hostapd_data *hapd = drv->hapd;
- struct sta_info *sta;
-
- sta = ap_get_sta(hapd, src_addr);
- if (!sta || !(sta->flags & WLAN_STA_ASSOC)) {
- printf("Data frame from not associated STA %s\n",
- ether_sprintf(src_addr));
- /* XXX cannot happen */
- return;
- }
- ieee802_1x_receive(hapd, src_addr, buf + sizeof(struct l2_ethhdr),
- len - sizeof(struct l2_ethhdr));
-}
-
-static int
-bsd_get_ssid(const char *ifname, void *priv, u8 *buf, int len)
-{
- struct bsd_driver_data *drv = priv;
- int ssid_len = get80211var(drv, IEEE80211_IOC_SSID, buf, len);
-
- wpa_printf(MSG_DEBUG, "%s: ssid=\"%.*s\"", __func__, ssid_len, buf);
-
- return ssid_len;
-}
-
-static int
-bsd_set_ssid(const char *ifname, void *priv, const u8 *buf, int len)
-{
- struct bsd_driver_data *drv = priv;
-
- wpa_printf(MSG_DEBUG, "%s: ssid=\"%.*s\"", __func__, len, buf);
-
- return set80211var(drv, IEEE80211_IOC_SSID, buf, len);
-}
-
-static void *
-bsd_init(struct hostapd_data *hapd)
-{
- struct bsd_driver_data *drv;
-
- drv = os_zalloc(sizeof(struct bsd_driver_data));
- if (drv == NULL) {
- printf("Could not allocate memory for bsd driver data\n");
- goto bad;
- }
-
- drv->hapd = hapd;
- drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
- if (drv->ioctl_sock < 0) {
- perror("socket[PF_INET,SOCK_DGRAM]");
- goto bad;
- }
- memcpy(drv->iface, hapd->conf->iface, sizeof(drv->iface));
-
- drv->sock_xmit = l2_packet_init(drv->iface, NULL, ETH_P_EAPOL,
- handle_read, drv, 1);
- if (drv->sock_xmit == NULL)
- goto bad;
- if (l2_packet_get_own_addr(drv->sock_xmit, hapd->own_addr))
- goto bad;
-
- bsd_set_iface_flags(drv, 0); /* mark down during setup */
-
- return drv;
-bad:
- if (drv->sock_xmit != NULL)
- l2_packet_deinit(drv->sock_xmit);
- if (drv->ioctl_sock >= 0)
- close(drv->ioctl_sock);
- if (drv != NULL)
- free(drv);
- return NULL;
-}
-
-
-static void
-bsd_deinit(void *priv)
-{
- struct bsd_driver_data *drv = priv;
-
- (void) bsd_set_iface_flags(drv, 0);
- if (drv->ioctl_sock >= 0)
- close(drv->ioctl_sock);
- if (drv->sock_xmit != NULL)
- l2_packet_deinit(drv->sock_xmit);
- free(drv);
-}
-
-const struct wpa_driver_ops wpa_driver_bsd_ops = {
- .name = "bsd",
- .init = bsd_init,
- .deinit = bsd_deinit,
- .set_ieee8021x = bsd_set_ieee8021x,
- .set_privacy = bsd_set_privacy,
- .set_encryption = bsd_set_key,
- .get_seqnum = bsd_get_seqnum,
- .flush = bsd_flush,
- .set_generic_elem = bsd_set_opt_ie,
- .wireless_event_init = bsd_wireless_event_init,
- .wireless_event_deinit = bsd_wireless_event_deinit,
- .sta_set_flags = bsd_sta_set_flags,
- .read_sta_data = bsd_read_sta_driver_data,
- .send_eapol = bsd_send_eapol,
- .sta_disassoc = bsd_sta_disassoc,
- .sta_deauth = bsd_sta_deauth,
- .set_ssid = bsd_set_ssid,
- .get_ssid = bsd_get_ssid,
-};
diff --git a/contrib/wpa/hostapd/driver_hostap.c b/contrib/wpa/hostapd/driver_hostap.c
deleted file mode 100644
index ceff099..0000000
--- a/contrib/wpa/hostapd/driver_hostap.c
+++ /dev/null
@@ -1,1279 +0,0 @@
-/*
- * hostapd / Kernel driver communication with Linux Host AP driver
- * Copyright (c) 2002-2007, Jouni Malinen <j@w1.fi>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
- */
-
-#include "includes.h"
-#include <sys/ioctl.h>
-
-#ifdef USE_KERNEL_HEADERS
-/* compat-wireless does not include linux/compiler.h to define __user, so
- * define it here */
-#ifndef __user
-#define __user
-#endif /* __user */
-#include <asm/types.h>
-#include <linux/if_packet.h>
-#include <linux/if_ether.h> /* The L2 protocols */
-#include <linux/if_arp.h>
-#include <linux/wireless.h>
-#else /* USE_KERNEL_HEADERS */
-#include <net/if_arp.h>
-#include <netpacket/packet.h>
-#include "wireless_copy.h"
-#endif /* USE_KERNEL_HEADERS */
-
-#include "hostapd.h"
-#include "driver.h"
-#include "ieee802_1x.h"
-#include "eloop.h"
-#include "priv_netlink.h"
-#include "ieee802_11.h"
-#include "sta_info.h"
-#include "hostap_common.h"
-#include "hw_features.h"
-
-
-struct hostap_driver_data {
- struct hostapd_data *hapd;
-
- char iface[IFNAMSIZ + 1];
- int sock; /* raw packet socket for driver access */
- int ioctl_sock; /* socket for ioctl() use */
- int wext_sock; /* socket for wireless events */
-
- int we_version;
-
- u8 *generic_ie;
- size_t generic_ie_len;
- u8 *wps_ie;
- size_t wps_ie_len;
-};
-
-
-static int hostapd_ioctl(void *priv, struct prism2_hostapd_param *param,
- int len);
-static int hostap_set_iface_flags(void *priv, int dev_up);
-
-static void handle_data(struct hostapd_data *hapd, u8 *buf, size_t len,
- u16 stype)
-{
- struct ieee80211_hdr *hdr;
- u16 fc, ethertype;
- u8 *pos, *sa;
- size_t left;
- struct sta_info *sta;
-
- if (len < sizeof(struct ieee80211_hdr))
- return;
-
- hdr = (struct ieee80211_hdr *) buf;
- fc = le_to_host16(hdr->frame_control);
-
- if ((fc & (WLAN_FC_FROMDS | WLAN_FC_TODS)) != WLAN_FC_TODS) {
- printf("Not ToDS data frame (fc=0x%04x)\n", fc);
- return;
- }
-
- sa = hdr->addr2;
- sta = ap_get_sta(hapd, sa);
- if (!sta || !(sta->flags & WLAN_STA_ASSOC)) {
- printf("Data frame from not associated STA " MACSTR "\n",
- MAC2STR(sa));
- if (sta && (sta->flags & WLAN_STA_AUTH))
- hostapd_sta_disassoc(
- hapd, sa,
- WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
- else
- hostapd_sta_deauth(
- hapd, sa,
- WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
- return;
- }
-
- pos = (u8 *) (hdr + 1);
- left = len - sizeof(*hdr);
-
- if (left < sizeof(rfc1042_header)) {
- printf("Too short data frame\n");
- return;
- }
-
- if (memcmp(pos, rfc1042_header, sizeof(rfc1042_header)) != 0) {
- printf("Data frame with no RFC1042 header\n");
- return;
- }
- pos += sizeof(rfc1042_header);
- left -= sizeof(rfc1042_header);
-
- if (left < 2) {
- printf("No ethertype in data frame\n");
- return;
- }
-
- ethertype = WPA_GET_BE16(pos);
- pos += 2;
- left -= 2;
- switch (ethertype) {
- case ETH_P_PAE:
- ieee802_1x_receive(hapd, sa, pos, left);
- break;
-
- default:
- printf("Unknown ethertype 0x%04x in data frame\n", ethertype);
- break;
- }
-}
-
-
-static void handle_tx_callback(struct hostapd_data *hapd, u8 *buf, size_t len,
- int ok)
-{
- struct ieee80211_hdr *hdr;
- u16 fc, type, stype;
- struct sta_info *sta;
-
- hdr = (struct ieee80211_hdr *) buf;
- fc = le_to_host16(hdr->frame_control);
-
- type = WLAN_FC_GET_TYPE(fc);
- stype = WLAN_FC_GET_STYPE(fc);
-
- switch (type) {
- case WLAN_FC_TYPE_MGMT:
- wpa_printf(MSG_DEBUG, "MGMT (TX callback) %s",
- ok ? "ACK" : "fail");
- ieee802_11_mgmt_cb(hapd, buf, len, stype, ok);
- break;
- case WLAN_FC_TYPE_CTRL:
- wpa_printf(MSG_DEBUG, "CTRL (TX callback) %s",
- ok ? "ACK" : "fail");
- break;
- case WLAN_FC_TYPE_DATA:
- wpa_printf(MSG_DEBUG, "DATA (TX callback) %s",
- ok ? "ACK" : "fail");
- sta = ap_get_sta(hapd, hdr->addr1);
- if (sta && sta->flags & WLAN_STA_PENDING_POLL) {
- wpa_printf(MSG_DEBUG, "STA " MACSTR
- " %s pending activity poll",
- MAC2STR(sta->addr),
- ok ? "ACKed" : "did not ACK");
- if (ok)
- sta->flags &= ~WLAN_STA_PENDING_POLL;
- }
- if (sta)
- ieee802_1x_tx_status(hapd, sta, buf, len, ok);
- break;
- default:
- printf("unknown TX callback frame type %d\n", type);
- break;
- }
-}
-
-
-static void handle_frame(struct hostapd_data *hapd, u8 *buf, size_t len)
-{
- struct ieee80211_hdr *hdr;
- u16 fc, extra_len, type, stype;
- unsigned char *extra = NULL;
- size_t data_len = len;
- int ver;
-
- /* PSPOLL is only 16 bytes, but driver does not (at least yet) pass
- * these to user space */
- if (len < 24) {
- wpa_printf(MSG_MSGDUMP, "handle_frame: too short (%lu)",
- (unsigned long) len);
- return;
- }
-
- hdr = (struct ieee80211_hdr *) buf;
- fc = le_to_host16(hdr->frame_control);
- type = WLAN_FC_GET_TYPE(fc);
- stype = WLAN_FC_GET_STYPE(fc);
-
- if (type != WLAN_FC_TYPE_MGMT || stype != WLAN_FC_STYPE_BEACON) {
- wpa_hexdump(MSG_MSGDUMP, "Received management frame",
- buf, len);
- }
-
- ver = fc & WLAN_FC_PVER;
-
- /* protocol version 3 is reserved for indicating extra data after the
- * payload, version 2 for indicating ACKed frame (TX callbacks), and
- * version 1 for indicating failed frame (no ACK, TX callbacks) */
- if (ver == 3) {
- u8 *pos = buf + len - 2;
- extra_len = WPA_GET_LE16(pos);
- printf("extra data in frame (elen=%d)\n", extra_len);
- if ((size_t) extra_len + 2 > len) {
- printf(" extra data overflow\n");
- return;
- }
- len -= extra_len + 2;
- extra = buf + len;
- } else if (ver == 1 || ver == 2) {
- handle_tx_callback(hapd, buf, data_len, ver == 2 ? 1 : 0);
- return;
- } else if (ver != 0) {
- printf("unknown protocol version %d\n", ver);
- return;
- }
-
- switch (type) {
- case WLAN_FC_TYPE_MGMT:
- if (stype != WLAN_FC_STYPE_BEACON)
- wpa_printf(MSG_MSGDUMP, "MGMT");
- ieee802_11_mgmt(hapd, buf, data_len, stype, NULL);
- break;
- case WLAN_FC_TYPE_CTRL:
- wpa_printf(MSG_DEBUG, "CTRL");
- break;
- case WLAN_FC_TYPE_DATA:
- wpa_printf(MSG_DEBUG, "DATA");
- handle_data(hapd, buf, data_len, stype);
- break;
- default:
- wpa_printf(MSG_DEBUG, "unknown frame type %d", type);
- break;
- }
-}
-
-
-static void handle_read(int sock, void *eloop_ctx, void *sock_ctx)
-{
- struct hostapd_data *hapd = (struct hostapd_data *) eloop_ctx;
- int len;
- unsigned char buf[3000];
-
- len = recv(sock, buf, sizeof(buf), 0);
- if (len < 0) {
- perror("recv");
- return;
- }
-
- handle_frame(hapd, buf, len);
-}
-
-
-static int hostap_init_sockets(struct hostap_driver_data *drv)
-{
- struct ifreq ifr;
- struct sockaddr_ll addr;
-
- drv->sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
- if (drv->sock < 0) {
- perror("socket[PF_PACKET,SOCK_RAW]");
- return -1;
- }
-
- if (eloop_register_read_sock(drv->sock, handle_read, drv->hapd, NULL))
- {
- printf("Could not register read socket\n");
- return -1;
- }
-
- memset(&ifr, 0, sizeof(ifr));
- snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%sap", drv->iface);
- if (ioctl(drv->sock, SIOCGIFINDEX, &ifr) != 0) {
- perror("ioctl(SIOCGIFINDEX)");
- return -1;
- }
-
- if (hostap_set_iface_flags(drv, 1)) {
- return -1;
- }
-
- memset(&addr, 0, sizeof(addr));
- addr.sll_family = AF_PACKET;
- addr.sll_ifindex = ifr.ifr_ifindex;
- wpa_printf(MSG_DEBUG, "Opening raw packet socket for ifindex %d",
- addr.sll_ifindex);
-
- if (bind(drv->sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
- perror("bind");
- return -1;
- }
-
- memset(&ifr, 0, sizeof(ifr));
- os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
- if (ioctl(drv->sock, SIOCGIFHWADDR, &ifr) != 0) {
- perror("ioctl(SIOCGIFHWADDR)");
- return -1;
- }
-
- if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
- printf("Invalid HW-addr family 0x%04x\n",
- ifr.ifr_hwaddr.sa_family);
- return -1;
- }
- memcpy(drv->hapd->own_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
-
- return 0;
-}
-
-
-static int hostap_send_mgmt_frame(void *priv, const void *msg, size_t len,
- int flags)
-{
- struct hostap_driver_data *drv = priv;
- struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) msg;
- int res;
-
- /* Request TX callback */
- hdr->frame_control |= host_to_le16(BIT(1));
- res = send(drv->sock, msg, len, flags);
- hdr->frame_control &= ~host_to_le16(BIT(1));
-
- return res;
-}
-
-
-static int hostap_send_eapol(void *priv, const u8 *addr, const u8 *data,
- size_t data_len, int encrypt, const u8 *own_addr)
-{
- struct hostap_driver_data *drv = priv;
- struct ieee80211_hdr *hdr;
- size_t len;
- u8 *pos;
- int res;
-
- len = sizeof(*hdr) + sizeof(rfc1042_header) + 2 + data_len;
- hdr = os_zalloc(len);
- if (hdr == NULL) {
- printf("malloc() failed for hostapd_send_data(len=%lu)\n",
- (unsigned long) len);
- return -1;
- }
-
- hdr->frame_control =
- IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA);
- hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS);
- if (encrypt)
- hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP);
- memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN);
- memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
- memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
-
- pos = (u8 *) (hdr + 1);
- memcpy(pos, rfc1042_header, sizeof(rfc1042_header));
- pos += sizeof(rfc1042_header);
- *((u16 *) pos) = htons(ETH_P_PAE);
- pos += 2;
- memcpy(pos, data, data_len);
-
- res = hostap_send_mgmt_frame(drv, (u8 *) hdr, len, 0);
- free(hdr);
-
- if (res < 0) {
- perror("hostapd_send_eapol: send");
- printf("hostapd_send_eapol - packet len: %lu - failed\n",
- (unsigned long) len);
- }
-
- return res;
-}
-
-
-static int hostap_sta_set_flags(void *priv, const u8 *addr,
- int total_flags, int flags_or, int flags_and)
-{
- struct hostap_driver_data *drv = priv;
- struct prism2_hostapd_param param;
-
- memset(&param, 0, sizeof(param));
- param.cmd = PRISM2_HOSTAPD_SET_FLAGS_STA;
- memcpy(param.sta_addr, addr, ETH_ALEN);
- param.u.set_flags_sta.flags_or = flags_or;
- param.u.set_flags_sta.flags_and = flags_and;
- return hostapd_ioctl(drv, &param, sizeof(param));
-}
-
-
-static int hostap_set_iface_flags(void *priv, int dev_up)
-{
- struct hostap_driver_data *drv = priv;
- struct ifreq ifr;
-
- if (drv->ioctl_sock < 0)
- return -1;
-
- memset(&ifr, 0, sizeof(ifr));
- snprintf(ifr.ifr_name, IFNAMSIZ, "%sap", drv->iface);
-
- if (ioctl(drv->ioctl_sock, SIOCGIFFLAGS, &ifr) != 0) {
- perror("ioctl[SIOCGIFFLAGS]");
- return -1;
- }
-
- if (dev_up)
- ifr.ifr_flags |= IFF_UP;
- else
- ifr.ifr_flags &= ~IFF_UP;
-
- if (ioctl(drv->ioctl_sock, SIOCSIFFLAGS, &ifr) != 0) {
- perror("ioctl[SIOCSIFFLAGS]");
- return -1;
- }
-
- if (dev_up) {
- memset(&ifr, 0, sizeof(ifr));
- snprintf(ifr.ifr_name, IFNAMSIZ, "%sap", drv->iface);
- ifr.ifr_mtu = HOSTAPD_MTU;
- if (ioctl(drv->ioctl_sock, SIOCSIFMTU, &ifr) != 0) {
- perror("ioctl[SIOCSIFMTU]");
- printf("Setting MTU failed - trying to survive with "
- "current value\n");
- }
- }
-
- return 0;
-}
-
-
-static int hostapd_ioctl(void *priv, struct prism2_hostapd_param *param,
- int len)
-{
- struct hostap_driver_data *drv = priv;
- struct iwreq iwr;
-
- memset(&iwr, 0, sizeof(iwr));
- os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
- iwr.u.data.pointer = (caddr_t) param;
- iwr.u.data.length = len;
-
- if (ioctl(drv->ioctl_sock, PRISM2_IOCTL_HOSTAPD, &iwr) < 0) {
- perror("ioctl[PRISM2_IOCTL_HOSTAPD]");
- return -1;
- }
-
- return 0;
-}
-
-
-static int hostap_set_encryption(const char *ifname, void *priv,
- const char *alg, const u8 *addr,
- int idx, const u8 *key, size_t key_len,
- int txkey)
-{
- struct hostap_driver_data *drv = priv;
- struct prism2_hostapd_param *param;
- u8 *buf;
- size_t blen;
- int ret = 0;
-
- blen = sizeof(*param) + key_len;
- buf = os_zalloc(blen);
- if (buf == NULL)
- return -1;
-
- param = (struct prism2_hostapd_param *) buf;
- param->cmd = PRISM2_SET_ENCRYPTION;
- if (addr == NULL)
- memset(param->sta_addr, 0xff, ETH_ALEN);
- else
- memcpy(param->sta_addr, addr, ETH_ALEN);
- os_strlcpy((char *) param->u.crypt.alg, alg,
- HOSTAP_CRYPT_ALG_NAME_LEN);
- param->u.crypt.flags = txkey ? HOSTAP_CRYPT_FLAG_SET_TX_KEY : 0;
- param->u.crypt.idx = idx;
- param->u.crypt.key_len = key_len;
- memcpy((u8 *) (param + 1), key, key_len);
-
- if (hostapd_ioctl(drv, param, blen)) {
- printf("Failed to set encryption.\n");
- ret = -1;
- }
- free(buf);
-
- return ret;
-}
-
-
-static int hostap_get_seqnum(const char *ifname, void *priv, const u8 *addr,
- int idx, u8 *seq)
-{
- struct hostap_driver_data *drv = priv;
- struct prism2_hostapd_param *param;
- u8 *buf;
- size_t blen;
- int ret = 0;
-
- blen = sizeof(*param) + 32;
- buf = os_zalloc(blen);
- if (buf == NULL)
- return -1;
-
- param = (struct prism2_hostapd_param *) buf;
- param->cmd = PRISM2_GET_ENCRYPTION;
- if (addr == NULL)
- memset(param->sta_addr, 0xff, ETH_ALEN);
- else
- memcpy(param->sta_addr, addr, ETH_ALEN);
- param->u.crypt.idx = idx;
-
- if (hostapd_ioctl(drv, param, blen)) {
- printf("Failed to get encryption.\n");
- ret = -1;
- } else {
- memcpy(seq, param->u.crypt.seq, 8);
- }
- free(buf);
-
- return ret;
-}
-
-
-static int hostap_ioctl_prism2param(void *priv, int param, int value)
-{
- struct hostap_driver_data *drv = priv;
- struct iwreq iwr;
- int *i;
-
- memset(&iwr, 0, sizeof(iwr));
- os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
- i = (int *) iwr.u.name;
- *i++ = param;
- *i++ = value;
-
- if (ioctl(drv->ioctl_sock, PRISM2_IOCTL_PRISM2_PARAM, &iwr) < 0) {
- perror("ioctl[PRISM2_IOCTL_PRISM2_PARAM]");
- return -1;
- }
-
- return 0;
-}
-
-
-static int hostap_set_ieee8021x(const char *ifname, void *priv, int enabled)
-{
- struct hostap_driver_data *drv = priv;
-
- /* enable kernel driver support for IEEE 802.1X */
- if (hostap_ioctl_prism2param(drv, PRISM2_PARAM_IEEE_802_1X, enabled)) {
- printf("Could not setup IEEE 802.1X support in kernel driver."
- "\n");
- return -1;
- }
-
- if (!enabled)
- return 0;
-
- /* use host driver implementation of encryption to allow
- * individual keys and passing plaintext EAPOL frames */
- if (hostap_ioctl_prism2param(drv, PRISM2_PARAM_HOST_DECRYPT, 1) ||
- hostap_ioctl_prism2param(drv, PRISM2_PARAM_HOST_ENCRYPT, 1)) {
- printf("Could not setup host-based encryption in kernel "
- "driver.\n");
- return -1;
- }
-
- return 0;
-}
-
-
-static int hostap_set_privacy(const char *ifname, void *priv, int enabled)
-{
- struct hostap_drvier_data *drv = priv;
-
- return hostap_ioctl_prism2param(drv, PRISM2_PARAM_PRIVACY_INVOKED,
- enabled);
-}
-
-
-static int hostap_set_ssid(const char *ifname, void *priv, const u8 *buf,
- int len)
-{
- struct hostap_driver_data *drv = priv;
- struct iwreq iwr;
-
- memset(&iwr, 0, sizeof(iwr));
- os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
- iwr.u.essid.flags = 1; /* SSID active */
- iwr.u.essid.pointer = (caddr_t) buf;
- iwr.u.essid.length = len + 1;
-
- if (ioctl(drv->ioctl_sock, SIOCSIWESSID, &iwr) < 0) {
- perror("ioctl[SIOCSIWESSID]");
- printf("len=%d\n", len);
- return -1;
- }
-
- return 0;
-}
-
-
-static int hostap_flush(void *priv)
-{
- struct hostap_driver_data *drv = priv;
- struct prism2_hostapd_param param;
-
- memset(&param, 0, sizeof(param));
- param.cmd = PRISM2_HOSTAPD_FLUSH;
- return hostapd_ioctl(drv, &param, sizeof(param));
-}
-
-
-static int hostap_read_sta_data(void *priv,
- struct hostap_sta_driver_data *data,
- const u8 *addr)
-{
- struct hostap_driver_data *drv = priv;
- char buf[1024], line[128], *pos;
- FILE *f;
- unsigned long val;
-
- memset(data, 0, sizeof(*data));
- snprintf(buf, sizeof(buf), "/proc/net/hostap/%s/" MACSTR,
- drv->iface, MAC2STR(addr));
-
- f = fopen(buf, "r");
- if (!f)
- return -1;
- /* Need to read proc file with in one piece, so use large enough
- * buffer. */
- setbuffer(f, buf, sizeof(buf));
-
- while (fgets(line, sizeof(line), f)) {
- pos = strchr(line, '=');
- if (!pos)
- continue;
- *pos++ = '\0';
- val = strtoul(pos, NULL, 10);
- if (strcmp(line, "rx_packets") == 0)
- data->rx_packets = val;
- else if (strcmp(line, "tx_packets") == 0)
- data->tx_packets = val;
- else if (strcmp(line, "rx_bytes") == 0)
- data->rx_bytes = val;
- else if (strcmp(line, "tx_bytes") == 0)
- data->tx_bytes = val;
- }
-
- fclose(f);
-
- return 0;
-}
-
-
-static int hostap_sta_add(const char *ifname, void *priv, const u8 *addr,
- u16 aid, u16 capability, u8 *supp_rates,
- size_t supp_rates_len, int flags,
- u16 listen_interval)
-{
- struct hostap_driver_data *drv = priv;
- struct prism2_hostapd_param param;
- int tx_supp_rates = 0;
- size_t i;
-
-#define WLAN_RATE_1M BIT(0)
-#define WLAN_RATE_2M BIT(1)
-#define WLAN_RATE_5M5 BIT(2)
-#define WLAN_RATE_11M BIT(3)
-
- for (i = 0; i < supp_rates_len; i++) {
- if ((supp_rates[i] & 0x7f) == 2)
- tx_supp_rates |= WLAN_RATE_1M;
- if ((supp_rates[i] & 0x7f) == 4)
- tx_supp_rates |= WLAN_RATE_2M;
- if ((supp_rates[i] & 0x7f) == 11)
- tx_supp_rates |= WLAN_RATE_5M5;
- if ((supp_rates[i] & 0x7f) == 22)
- tx_supp_rates |= WLAN_RATE_11M;
- }
-
- memset(&param, 0, sizeof(param));
- param.cmd = PRISM2_HOSTAPD_ADD_STA;
- memcpy(param.sta_addr, addr, ETH_ALEN);
- param.u.add_sta.aid = aid;
- param.u.add_sta.capability = capability;
- param.u.add_sta.tx_supp_rates = tx_supp_rates;
- return hostapd_ioctl(drv, &param, sizeof(param));
-}
-
-
-static int hostap_sta_remove(void *priv, const u8 *addr)
-{
- struct hostap_driver_data *drv = priv;
- struct prism2_hostapd_param param;
-
- hostap_sta_set_flags(drv, addr, 0, 0, ~WLAN_STA_AUTHORIZED);
-
- memset(&param, 0, sizeof(param));
- param.cmd = PRISM2_HOSTAPD_REMOVE_STA;
- memcpy(param.sta_addr, addr, ETH_ALEN);
- if (hostapd_ioctl(drv, &param, sizeof(param))) {
- printf("Could not remove station from kernel driver.\n");
- return -1;
- }
- return 0;
-}
-
-
-static int hostap_get_inact_sec(void *priv, const u8 *addr)
-{
- struct hostap_driver_data *drv = priv;
- struct prism2_hostapd_param param;
-
- memset(&param, 0, sizeof(param));
- param.cmd = PRISM2_HOSTAPD_GET_INFO_STA;
- memcpy(param.sta_addr, addr, ETH_ALEN);
- if (hostapd_ioctl(drv, &param, sizeof(param))) {
- return -1;
- }
-
- return param.u.get_info_sta.inactive_sec;
-}
-
-
-static int hostap_sta_clear_stats(void *priv, const u8 *addr)
-{
- struct hostap_driver_data *drv = priv;
- struct prism2_hostapd_param param;
-
- memset(&param, 0, sizeof(param));
- param.cmd = PRISM2_HOSTAPD_STA_CLEAR_STATS;
- memcpy(param.sta_addr, addr, ETH_ALEN);
- if (hostapd_ioctl(drv, &param, sizeof(param))) {
- return -1;
- }
-
- return 0;
-}
-
-
-static int hostap_set_assoc_ap(void *priv, const u8 *addr)
-{
- struct hostap_driver_data *drv = priv;
- struct prism2_hostapd_param param;
-
- memset(&param, 0, sizeof(param));
- param.cmd = PRISM2_HOSTAPD_SET_ASSOC_AP_ADDR;
- memcpy(param.sta_addr, addr, ETH_ALEN);
- if (hostapd_ioctl(drv, &param, sizeof(param)))
- return -1;
-
- return 0;
-}
-
-
-static int hostapd_ioctl_set_generic_elem(struct hostap_driver_data *drv)
-{
- struct prism2_hostapd_param *param;
- int res;
- size_t blen, elem_len;
-
- elem_len = drv->generic_ie_len + drv->wps_ie_len;
- blen = PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN + elem_len;
- if (blen < sizeof(*param))
- blen = sizeof(*param);
-
- param = os_zalloc(blen);
- if (param == NULL)
- return -1;
-
- param->cmd = PRISM2_HOSTAPD_SET_GENERIC_ELEMENT;
- param->u.generic_elem.len = elem_len;
- if (drv->generic_ie) {
- os_memcpy(param->u.generic_elem.data, drv->generic_ie,
- drv->generic_ie_len);
- }
- if (drv->wps_ie) {
- os_memcpy(&param->u.generic_elem.data[drv->generic_ie_len],
- drv->wps_ie, drv->wps_ie_len);
- }
- wpa_hexdump(MSG_DEBUG, "hostap: Set generic IE",
- param->u.generic_elem.data, elem_len);
- res = hostapd_ioctl(drv, param, blen);
-
- os_free(param);
-
- return res;
-}
-
-
-static int hostap_set_generic_elem(const char *ifname, void *priv,
- const u8 *elem, size_t elem_len)
-{
- struct hostap_driver_data *drv = priv;
-
- os_free(drv->generic_ie);
- drv->generic_ie = NULL;
- drv->generic_ie_len = 0;
- if (elem) {
- drv->generic_ie = os_malloc(elem_len);
- if (drv->generic_ie == NULL)
- return -1;
- os_memcpy(drv->generic_ie, elem, elem_len);
- drv->generic_ie_len = elem_len;
- }
-
- return hostapd_ioctl_set_generic_elem(drv);
-}
-
-
-static int hostap_set_wps_beacon_ie(const char *ifname, void *priv,
- const u8 *ie, size_t len)
-{
- /* Host AP driver supports only one set of extra IEs, so we need to
- * use the ProbeResp IEs also for Beacon frames since they include more
- * information. */
- return 0;
-}
-
-
-static int hostap_set_wps_probe_resp_ie(const char *ifname, void *priv,
- const u8 *ie, size_t len)
-{
- struct hostap_driver_data *drv = priv;
-
- os_free(drv->wps_ie);
- drv->wps_ie = NULL;
- drv->wps_ie_len = 0;
- if (ie) {
- drv->wps_ie = os_malloc(len);
- if (drv->wps_ie == NULL)
- return -1;
- os_memcpy(drv->wps_ie, ie, len);
- drv->wps_ie_len = len;
- }
-
- return hostapd_ioctl_set_generic_elem(drv);
-}
-
-
-static void
-hostapd_wireless_event_wireless_custom(struct hostap_driver_data *drv,
- char *custom)
-{
- wpa_printf(MSG_DEBUG, "Custom wireless event: '%s'", custom);
-
- if (strncmp(custom, "MLME-MICHAELMICFAILURE.indication", 33) == 0) {
- char *pos;
- u8 addr[ETH_ALEN];
- pos = strstr(custom, "addr=");
- if (pos == NULL) {
- wpa_printf(MSG_DEBUG,
- "MLME-MICHAELMICFAILURE.indication "
- "without sender address ignored");
- return;
- }
- pos += 5;
- if (hwaddr_aton(pos, addr) == 0) {
- ieee80211_michael_mic_failure(drv->hapd, addr, 1);
- } else {
- wpa_printf(MSG_DEBUG,
- "MLME-MICHAELMICFAILURE.indication "
- "with invalid MAC address");
- }
- }
-}
-
-
-static void hostapd_wireless_event_wireless(struct hostap_driver_data *drv,
- char *data, int len)
-{
- struct iw_event iwe_buf, *iwe = &iwe_buf;
- char *pos, *end, *custom, *buf;
-
- pos = data;
- end = data + len;
-
- while (pos + IW_EV_LCP_LEN <= end) {
- /* Event data may be unaligned, so make a local, aligned copy
- * before processing. */
- memcpy(&iwe_buf, pos, IW_EV_LCP_LEN);
- wpa_printf(MSG_DEBUG, "Wireless event: cmd=0x%x len=%d",
- iwe->cmd, iwe->len);
- if (iwe->len <= IW_EV_LCP_LEN)
- return;
-
- custom = pos + IW_EV_POINT_LEN;
- if (drv->we_version > 18 &&
- (iwe->cmd == IWEVMICHAELMICFAILURE ||
- iwe->cmd == IWEVCUSTOM)) {
- /* WE-19 removed the pointer from struct iw_point */
- char *dpos = (char *) &iwe_buf.u.data.length;
- int dlen = dpos - (char *) &iwe_buf;
- memcpy(dpos, pos + IW_EV_LCP_LEN,
- sizeof(struct iw_event) - dlen);
- } else {
- memcpy(&iwe_buf, pos, sizeof(struct iw_event));
- custom += IW_EV_POINT_OFF;
- }
-
- switch (iwe->cmd) {
- case IWEVCUSTOM:
- if (custom + iwe->u.data.length > end)
- return;
- buf = malloc(iwe->u.data.length + 1);
- if (buf == NULL)
- return;
- memcpy(buf, custom, iwe->u.data.length);
- buf[iwe->u.data.length] = '\0';
- hostapd_wireless_event_wireless_custom(drv, buf);
- free(buf);
- break;
- }
-
- pos += iwe->len;
- }
-}
-
-
-static void hostapd_wireless_event_rtm_newlink(struct hostap_driver_data *drv,
- struct nlmsghdr *h, int len)
-{
- struct ifinfomsg *ifi;
- int attrlen, nlmsg_len, rta_len;
- struct rtattr * attr;
-
- if (len < (int) sizeof(*ifi))
- return;
-
- ifi = NLMSG_DATA(h);
-
- /* TODO: use ifi->ifi_index to filter out wireless events from other
- * interfaces */
-
- nlmsg_len = NLMSG_ALIGN(sizeof(struct ifinfomsg));
-
- attrlen = h->nlmsg_len - nlmsg_len;
- if (attrlen < 0)
- return;
-
- attr = (struct rtattr *) (((char *) ifi) + nlmsg_len);
-
- rta_len = RTA_ALIGN(sizeof(struct rtattr));
- while (RTA_OK(attr, attrlen)) {
- if (attr->rta_type == IFLA_WIRELESS) {
- hostapd_wireless_event_wireless(
- drv, ((char *) attr) + rta_len,
- attr->rta_len - rta_len);
- }
- attr = RTA_NEXT(attr, attrlen);
- }
-}
-
-
-static void hostapd_wireless_event_receive(int sock, void *eloop_ctx,
- void *sock_ctx)
-{
- char buf[256];
- int left;
- struct sockaddr_nl from;
- socklen_t fromlen;
- struct nlmsghdr *h;
- struct hostap_driver_data *drv = eloop_ctx;
-
- fromlen = sizeof(from);
- left = recvfrom(sock, buf, sizeof(buf), MSG_DONTWAIT,
- (struct sockaddr *) &from, &fromlen);
- if (left < 0) {
- if (errno != EINTR && errno != EAGAIN)
- perror("recvfrom(netlink)");
- return;
- }
-
- h = (struct nlmsghdr *) buf;
- while (left >= (int) sizeof(*h)) {
- int len, plen;
-
- len = h->nlmsg_len;
- plen = len - sizeof(*h);
- if (len > left || plen < 0) {
- printf("Malformed netlink message: "
- "len=%d left=%d plen=%d\n",
- len, left, plen);
- break;
- }
-
- switch (h->nlmsg_type) {
- case RTM_NEWLINK:
- hostapd_wireless_event_rtm_newlink(drv, h, plen);
- break;
- }
-
- len = NLMSG_ALIGN(len);
- left -= len;
- h = (struct nlmsghdr *) ((char *) h + len);
- }
-
- if (left > 0) {
- printf("%d extra bytes in the end of netlink message\n", left);
- }
-}
-
-
-static int hostap_get_we_version(struct hostap_driver_data *drv)
-{
- struct iw_range *range;
- struct iwreq iwr;
- int minlen;
- size_t buflen;
-
- drv->we_version = 0;
-
- /*
- * Use larger buffer than struct iw_range in order to allow the
- * structure to grow in the future.
- */
- buflen = sizeof(struct iw_range) + 500;
- range = os_zalloc(buflen);
- if (range == NULL)
- return -1;
-
- memset(&iwr, 0, sizeof(iwr));
- os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
- iwr.u.data.pointer = (caddr_t) range;
- iwr.u.data.length = buflen;
-
- minlen = ((char *) &range->enc_capa) - (char *) range +
- sizeof(range->enc_capa);
-
- if (ioctl(drv->ioctl_sock, SIOCGIWRANGE, &iwr) < 0) {
- perror("ioctl[SIOCGIWRANGE]");
- free(range);
- return -1;
- } else if (iwr.u.data.length >= minlen &&
- range->we_version_compiled >= 18) {
- wpa_printf(MSG_DEBUG, "SIOCGIWRANGE: WE(compiled)=%d "
- "WE(source)=%d enc_capa=0x%x",
- range->we_version_compiled,
- range->we_version_source,
- range->enc_capa);
- drv->we_version = range->we_version_compiled;
- }
-
- free(range);
- return 0;
-}
-
-
-static int hostap_wireless_event_init(void *priv)
-{
- struct hostap_driver_data *drv = priv;
- int s;
- struct sockaddr_nl local;
-
- hostap_get_we_version(drv);
-
- drv->wext_sock = -1;
-
- s = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
- if (s < 0) {
- perror("socket(PF_NETLINK,SOCK_RAW,NETLINK_ROUTE)");
- return -1;
- }
-
- memset(&local, 0, sizeof(local));
- local.nl_family = AF_NETLINK;
- local.nl_groups = RTMGRP_LINK;
- if (bind(s, (struct sockaddr *) &local, sizeof(local)) < 0) {
- perror("bind(netlink)");
- close(s);
- return -1;
- }
-
- eloop_register_read_sock(s, hostapd_wireless_event_receive, drv,
- NULL);
- drv->wext_sock = s;
-
- return 0;
-}
-
-
-static void hostap_wireless_event_deinit(void *priv)
-{
- struct hostap_driver_data *drv = priv;
- if (drv->wext_sock < 0)
- return;
- eloop_unregister_read_sock(drv->wext_sock);
- close(drv->wext_sock);
-}
-
-
-static void * hostap_init(struct hostapd_data *hapd)
-{
- struct hostap_driver_data *drv;
-
- drv = os_zalloc(sizeof(struct hostap_driver_data));
- if (drv == NULL) {
- printf("Could not allocate memory for hostapd driver data\n");
- return NULL;
- }
-
- drv->hapd = hapd;
- drv->ioctl_sock = drv->sock = -1;
- memcpy(drv->iface, hapd->conf->iface, sizeof(drv->iface));
-
- drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
- if (drv->ioctl_sock < 0) {
- perror("socket[PF_INET,SOCK_DGRAM]");
- free(drv);
- return NULL;
- }
-
- if (hostap_ioctl_prism2param(drv, PRISM2_PARAM_HOSTAPD, 1)) {
- printf("Could not enable hostapd mode for interface %s\n",
- drv->iface);
- close(drv->ioctl_sock);
- free(drv);
- return NULL;
- }
-
- if (hostap_init_sockets(drv)) {
- close(drv->ioctl_sock);
- free(drv);
- return NULL;
- }
-
- return drv;
-}
-
-
-static void hostap_driver_deinit(void *priv)
-{
- struct hostap_driver_data *drv = priv;
-
- (void) hostap_set_iface_flags(drv, 0);
- (void) hostap_ioctl_prism2param(drv, PRISM2_PARAM_HOSTAPD, 0);
- (void) hostap_ioctl_prism2param(drv, PRISM2_PARAM_HOSTAPD_STA, 0);
-
- if (drv->ioctl_sock >= 0)
- close(drv->ioctl_sock);
-
- if (drv->sock >= 0)
- close(drv->sock);
-
- os_free(drv->generic_ie);
- os_free(drv->wps_ie);
-
- free(drv);
-}
-
-
-static int hostap_sta_deauth(void *priv, const u8 *addr, int reason)
-{
- struct hostap_driver_data *drv = priv;
- struct ieee80211_mgmt mgmt;
-
- memset(&mgmt, 0, sizeof(mgmt));
- mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
- WLAN_FC_STYPE_DEAUTH);
- memcpy(mgmt.da, addr, ETH_ALEN);
- memcpy(mgmt.sa, drv->hapd->own_addr, ETH_ALEN);
- memcpy(mgmt.bssid, drv->hapd->own_addr, ETH_ALEN);
- mgmt.u.deauth.reason_code = host_to_le16(reason);
- return hostap_send_mgmt_frame(drv, &mgmt, IEEE80211_HDRLEN +
- sizeof(mgmt.u.deauth), 0);
-}
-
-
-static int hostap_sta_disassoc(void *priv, const u8 *addr, int reason)
-{
- struct hostap_driver_data *drv = priv;
- struct ieee80211_mgmt mgmt;
-
- memset(&mgmt, 0, sizeof(mgmt));
- mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
- WLAN_FC_STYPE_DISASSOC);
- memcpy(mgmt.da, addr, ETH_ALEN);
- memcpy(mgmt.sa, drv->hapd->own_addr, ETH_ALEN);
- memcpy(mgmt.bssid, drv->hapd->own_addr, ETH_ALEN);
- mgmt.u.disassoc.reason_code = host_to_le16(reason);
- return hostap_send_mgmt_frame(drv, &mgmt, IEEE80211_HDRLEN +
- sizeof(mgmt.u.disassoc), 0);
-}
-
-
-static struct hostapd_hw_modes * hostap_get_hw_feature_data(void *priv,
- u16 *num_modes,
- u16 *flags)
-{
- struct hostapd_hw_modes *mode;
- int i, clen, rlen;
- const short chan2freq[14] = {
- 2412, 2417, 2422, 2427, 2432, 2437, 2442,
- 2447, 2452, 2457, 2462, 2467, 2472, 2484
- };
-
- mode = os_zalloc(sizeof(struct hostapd_hw_modes));
- if (mode == NULL)
- return NULL;
-
- *num_modes = 1;
- *flags = 0;
-
- mode->mode = HOSTAPD_MODE_IEEE80211B;
- mode->num_channels = 14;
- mode->num_rates = 4;
-
- clen = mode->num_channels * sizeof(struct hostapd_channel_data);
- rlen = mode->num_rates * sizeof(struct hostapd_rate_data);
-
- mode->channels = os_zalloc(clen);
- mode->rates = os_zalloc(rlen);
- if (mode->channels == NULL || mode->rates == NULL) {
- hostapd_free_hw_features(mode, *num_modes);
- return NULL;
- }
-
- for (i = 0; i < 14; i++) {
- mode->channels[i].chan = i + 1;
- mode->channels[i].freq = chan2freq[i];
- /* TODO: Get allowed channel list from the driver */
- if (i >= 11)
- mode->channels[i].flag = HOSTAPD_CHAN_DISABLED;
- }
-
- mode->rates[0].rate = 10;
- mode->rates[0].flags = HOSTAPD_RATE_CCK;
- mode->rates[1].rate = 20;
- mode->rates[1].flags = HOSTAPD_RATE_CCK;
- mode->rates[2].rate = 55;
- mode->rates[2].flags = HOSTAPD_RATE_CCK;
- mode->rates[3].rate = 110;
- mode->rates[3].flags = HOSTAPD_RATE_CCK;
-
- return mode;
-}
-
-
-const struct wpa_driver_ops wpa_driver_hostap_ops = {
- .name = "hostap",
- .init = hostap_init,
- .deinit = hostap_driver_deinit,
- .wireless_event_init = hostap_wireless_event_init,
- .wireless_event_deinit = hostap_wireless_event_deinit,
- .set_ieee8021x = hostap_set_ieee8021x,
- .set_privacy = hostap_set_privacy,
- .set_encryption = hostap_set_encryption,
- .get_seqnum = hostap_get_seqnum,
- .flush = hostap_flush,
- .set_generic_elem = hostap_set_generic_elem,
- .read_sta_data = hostap_read_sta_data,
- .send_eapol = hostap_send_eapol,
- .sta_set_flags = hostap_sta_set_flags,
- .sta_deauth = hostap_sta_deauth,
- .sta_disassoc = hostap_sta_disassoc,
- .sta_remove = hostap_sta_remove,
- .set_ssid = hostap_set_ssid,
- .send_mgmt_frame = hostap_send_mgmt_frame,
- .set_assoc_ap = hostap_set_assoc_ap,
- .sta_add = hostap_sta_add,
- .get_inact_sec = hostap_get_inact_sec,
- .sta_clear_stats = hostap_sta_clear_stats,
- .get_hw_feature_data = hostap_get_hw_feature_data,
- .set_wps_beacon_ie = hostap_set_wps_beacon_ie,
- .set_wps_probe_resp_ie = hostap_set_wps_probe_resp_ie,
-};
diff --git a/contrib/wpa/hostapd/driver_wired.c b/contrib/wpa/hostapd/driver_wired.c
deleted file mode 100644
index 61cb667..0000000
--- a/contrib/wpa/hostapd/driver_wired.c
+++ /dev/null
@@ -1,372 +0,0 @@
-/*
- * hostapd / Kernel driver communication for wired (Ethernet) drivers
- * Copyright (c) 2002-2007, Jouni Malinen <j@w1.fi>
- * Copyright (c) 2004, Gunter Burchardt <tira@isx.de>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
- */
-
-#include "includes.h"
-#include <sys/ioctl.h>
-
-#ifdef USE_KERNEL_HEADERS
-#include <asm/types.h>
-#include <linux/if_packet.h>
-#include <linux/if_ether.h> /* The L2 protocols */
-#include <linux/if_arp.h>
-#include <linux/if.h>
-#else /* USE_KERNEL_HEADERS */
-#include <net/if_arp.h>
-#include <net/if.h>
-#include <netpacket/packet.h>
-#endif /* USE_KERNEL_HEADERS */
-
-#include "hostapd.h"
-#include "ieee802_1x.h"
-#include "eloop.h"
-#include "sta_info.h"
-#include "driver.h"
-#include "accounting.h"
-
-
-struct wired_driver_data {
- struct hostapd_data *hapd;
-
- int sock; /* raw packet socket for driver access */
- int dhcp_sock; /* socket for dhcp packets */
- int use_pae_group_addr;
-};
-
-
-#define WIRED_EAPOL_MULTICAST_GROUP {0x01,0x80,0xc2,0x00,0x00,0x03}
-
-
-/* TODO: detecting new devices should eventually be changed from using DHCP
- * snooping to trigger on any packet from a new layer 2 MAC address, e.g.,
- * based on ebtables, etc. */
-
-struct dhcp_message {
- u_int8_t op;
- u_int8_t htype;
- u_int8_t hlen;
- u_int8_t hops;
- u_int32_t xid;
- u_int16_t secs;
- u_int16_t flags;
- u_int32_t ciaddr;
- u_int32_t yiaddr;
- u_int32_t siaddr;
- u_int32_t giaddr;
- u_int8_t chaddr[16];
- u_int8_t sname[64];
- u_int8_t file[128];
- u_int32_t cookie;
- u_int8_t options[308]; /* 312 - cookie */
-};
-
-
-static void wired_possible_new_sta(struct hostapd_data *hapd, u8 *addr)
-{
- struct sta_info *sta;
-
- sta = ap_get_sta(hapd, addr);
- if (sta)
- return;
-
- wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR
- " - adding a new STA", MAC2STR(addr));
- sta = ap_sta_add(hapd, addr);
- if (sta) {
- hostapd_new_assoc_sta(hapd, sta, 0);
- } else {
- wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR,
- MAC2STR(addr));
- }
-}
-
-
-static void handle_data(struct hostapd_data *hapd, unsigned char *buf,
- size_t len)
-{
- struct ieee8023_hdr *hdr;
- u8 *pos, *sa;
- size_t left;
-
- /* must contain at least ieee8023_hdr 6 byte source, 6 byte dest,
- * 2 byte ethertype */
- if (len < 14) {
- wpa_printf(MSG_MSGDUMP, "handle_data: too short (%lu)",
- (unsigned long) len);
- return;
- }
-
- hdr = (struct ieee8023_hdr *) buf;
-
- switch (ntohs(hdr->ethertype)) {
- case ETH_P_PAE:
- wpa_printf(MSG_MSGDUMP, "Received EAPOL packet");
- sa = hdr->src;
- wired_possible_new_sta(hapd, sa);
-
- pos = (u8 *) (hdr + 1);
- left = len - sizeof(*hdr);
-
- ieee802_1x_receive(hapd, sa, pos, left);
- break;
-
- default:
- wpa_printf(MSG_DEBUG, "Unknown ethertype 0x%04x in data frame",
- ntohs(hdr->ethertype));
- break;
- }
-}
-
-
-static void handle_read(int sock, void *eloop_ctx, void *sock_ctx)
-{
- struct hostapd_data *hapd = (struct hostapd_data *) eloop_ctx;
- int len;
- unsigned char buf[3000];
-
- len = recv(sock, buf, sizeof(buf), 0);
- if (len < 0) {
- perror("recv");
- return;
- }
-
- handle_data(hapd, buf, len);
-}
-
-
-static void handle_dhcp(int sock, void *eloop_ctx, void *sock_ctx)
-{
- struct hostapd_data *hapd = (struct hostapd_data *) eloop_ctx;
- int len;
- unsigned char buf[3000];
- struct dhcp_message *msg;
- u8 *mac_address;
-
- len = recv(sock, buf, sizeof(buf), 0);
- if (len < 0) {
- perror("recv");
- return;
- }
-
- /* must contain at least dhcp_message->chaddr */
- if (len < 44) {
- wpa_printf(MSG_MSGDUMP, "handle_dhcp: too short (%d)", len);
- return;
- }
-
- msg = (struct dhcp_message *) buf;
- mac_address = (u8 *) &(msg->chaddr);
-
- wpa_printf(MSG_MSGDUMP, "Got DHCP broadcast packet from " MACSTR,
- MAC2STR(mac_address));
-
- wired_possible_new_sta(hapd, mac_address);
-}
-
-
-static int wired_init_sockets(struct wired_driver_data *drv)
-{
- struct hostapd_data *hapd = drv->hapd;
- struct ifreq ifr;
- struct sockaddr_ll addr;
- struct sockaddr_in addr2;
- struct packet_mreq mreq;
- u8 multicastgroup_eapol[6] = WIRED_EAPOL_MULTICAST_GROUP;
- int n = 1;
-
- drv->sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_PAE));
- if (drv->sock < 0) {
- perror("socket[PF_PACKET,SOCK_RAW]");
- return -1;
- }
-
- if (eloop_register_read_sock(drv->sock, handle_read, hapd, NULL)) {
- printf("Could not register read socket\n");
- return -1;
- }
-
- memset(&ifr, 0, sizeof(ifr));
- os_strlcpy(ifr.ifr_name, hapd->conf->iface, sizeof(ifr.ifr_name));
- if (ioctl(drv->sock, SIOCGIFINDEX, &ifr) != 0) {
- perror("ioctl(SIOCGIFINDEX)");
- return -1;
- }
-
-
- memset(&addr, 0, sizeof(addr));
- addr.sll_family = AF_PACKET;
- addr.sll_ifindex = ifr.ifr_ifindex;
- wpa_printf(MSG_DEBUG, "Opening raw packet socket for ifindex %d",
- addr.sll_ifindex);
-
- if (bind(drv->sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
- perror("bind");
- return -1;
- }
-
- /* filter multicast address */
- memset(&mreq, 0, sizeof(mreq));
- mreq.mr_ifindex = ifr.ifr_ifindex;
- mreq.mr_type = PACKET_MR_MULTICAST;
- mreq.mr_alen = 6;
- memcpy(mreq.mr_address, multicastgroup_eapol, mreq.mr_alen);
-
- if (setsockopt(drv->sock, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mreq,
- sizeof(mreq)) < 0) {
- perror("setsockopt[SOL_SOCKET,PACKET_ADD_MEMBERSHIP]");
- return -1;
- }
-
- memset(&ifr, 0, sizeof(ifr));
- os_strlcpy(ifr.ifr_name, hapd->conf->iface, sizeof(ifr.ifr_name));
- if (ioctl(drv->sock, SIOCGIFHWADDR, &ifr) != 0) {
- perror("ioctl(SIOCGIFHWADDR)");
- return -1;
- }
-
- if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
- printf("Invalid HW-addr family 0x%04x\n",
- ifr.ifr_hwaddr.sa_family);
- return -1;
- }
- memcpy(hapd->own_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
-
- /* setup dhcp listen socket for sta detection */
- if ((drv->dhcp_sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
- perror("socket call failed for dhcp");
- return -1;
- }
-
- if (eloop_register_read_sock(drv->dhcp_sock, handle_dhcp, hapd, NULL))
- {
- printf("Could not register read socket\n");
- return -1;
- }
-
- memset(&addr2, 0, sizeof(addr2));
- addr2.sin_family = AF_INET;
- addr2.sin_port = htons(67);
- addr2.sin_addr.s_addr = INADDR_ANY;
-
- if (setsockopt(drv->dhcp_sock, SOL_SOCKET, SO_REUSEADDR, (char *) &n,
- sizeof(n)) == -1) {
- perror("setsockopt[SOL_SOCKET,SO_REUSEADDR]");
- return -1;
- }
- if (setsockopt(drv->dhcp_sock, SOL_SOCKET, SO_BROADCAST, (char *) &n,
- sizeof(n)) == -1) {
- perror("setsockopt[SOL_SOCKET,SO_BROADCAST]");
- return -1;
- }
-
- memset(&ifr, 0, sizeof(ifr));
- os_strlcpy(ifr.ifr_ifrn.ifrn_name, hapd->conf->iface, IFNAMSIZ);
- if (setsockopt(drv->dhcp_sock, SOL_SOCKET, SO_BINDTODEVICE,
- (char *) &ifr, sizeof(ifr)) < 0) {
- perror("setsockopt[SOL_SOCKET,SO_BINDTODEVICE]");
- return -1;
- }
-
- if (bind(drv->dhcp_sock, (struct sockaddr *) &addr2,
- sizeof(struct sockaddr)) == -1) {
- perror("bind");
- return -1;
- }
-
- return 0;
-}
-
-
-static int wired_send_eapol(void *priv, const u8 *addr,
- const u8 *data, size_t data_len, int encrypt,
- const u8 *own_addr)
-{
- struct wired_driver_data *drv = priv;
- u8 pae_group_addr[ETH_ALEN] = WIRED_EAPOL_MULTICAST_GROUP;
- struct ieee8023_hdr *hdr;
- size_t len;
- u8 *pos;
- int res;
-
- len = sizeof(*hdr) + data_len;
- hdr = os_zalloc(len);
- if (hdr == NULL) {
- printf("malloc() failed for wired_send_eapol(len=%lu)\n",
- (unsigned long) len);
- return -1;
- }
-
- memcpy(hdr->dest, drv->use_pae_group_addr ? pae_group_addr : addr,
- ETH_ALEN);
- memcpy(hdr->src, own_addr, ETH_ALEN);
- hdr->ethertype = htons(ETH_P_PAE);
-
- pos = (u8 *) (hdr + 1);
- memcpy(pos, data, data_len);
-
- res = send(drv->sock, (u8 *) hdr, len, 0);
- free(hdr);
-
- if (res < 0) {
- perror("wired_send_eapol: send");
- printf("wired_send_eapol - packet len: %lu - failed\n",
- (unsigned long) len);
- }
-
- return res;
-}
-
-
-static void * wired_driver_init(struct hostapd_data *hapd)
-{
- struct wired_driver_data *drv;
-
- drv = os_zalloc(sizeof(struct wired_driver_data));
- if (drv == NULL) {
- printf("Could not allocate memory for wired driver data\n");
- return NULL;
- }
-
- drv->hapd = hapd;
- drv->use_pae_group_addr = hapd->conf->use_pae_group_addr;
-
- if (wired_init_sockets(drv)) {
- free(drv);
- return NULL;
- }
-
- return drv;
-}
-
-
-static void wired_driver_deinit(void *priv)
-{
- struct wired_driver_data *drv = priv;
-
- if (drv->sock >= 0)
- close(drv->sock);
-
- if (drv->dhcp_sock >= 0)
- close(drv->dhcp_sock);
-
- free(drv);
-}
-
-
-const struct wpa_driver_ops wpa_driver_wired_ops = {
- .name = "wired",
- .init = wired_driver_init,
- .deinit = wired_driver_deinit,
- .send_eapol = wired_send_eapol,
-};
diff --git a/contrib/wpa/hostapd/drivers.c b/contrib/wpa/hostapd/drivers.c
deleted file mode 100644
index bde6e60..0000000
--- a/contrib/wpa/hostapd/drivers.c
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * hostapd / driver interface list
- * Copyright (c) 2007, Jouni Malinen <j@w1.fi>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
- */
-
-#include "includes.h"
-
-
-#ifdef CONFIG_DRIVER_HOSTAP
-extern struct wpa_driver_ops wpa_driver_hostap_ops; /* driver_hostap.c */
-#endif /* CONFIG_DRIVER_HOSTAP */
-#ifdef CONFIG_DRIVER_NL80211
-extern struct wpa_driver_ops wpa_driver_nl80211_ops; /* driver_nl80211.c */
-#endif /* CONFIG_DRIVER_NL80211 */
-#ifdef CONFIG_DRIVER_PRISM54
-extern struct wpa_driver_ops wpa_driver_prism54_ops; /* driver_prism54.c */
-#endif /* CONFIG_DRIVER_PRISM54 */
-#ifdef CONFIG_DRIVER_MADWIFI
-extern struct wpa_driver_ops wpa_driver_madwifi_ops; /* driver_madwifi.c */
-#endif /* CONFIG_DRIVER_MADWIFI */
-#ifdef CONFIG_DRIVER_ATHEROS
-extern struct wpa_driver_ops wpa_driver_atheros_ops; /* driver_atheros.c */
-#endif /* CONFIG_DRIVER_ATHEROS */
-#ifdef CONFIG_DRIVER_BSD
-extern struct wpa_driver_ops wpa_driver_bsd_ops; /* driver_bsd.c */
-#endif /* CONFIG_DRIVER_BSD */
-#ifdef CONFIG_DRIVER_WIRED
-extern struct wpa_driver_ops wpa_driver_wired_ops; /* driver_wired.c */
-#endif /* CONFIG_DRIVER_WIRED */
-#ifdef CONFIG_DRIVER_TEST
-extern struct wpa_driver_ops wpa_driver_test_ops; /* driver_test.c */
-#endif /* CONFIG_DRIVER_TEST */
-#ifdef CONFIG_DRIVER_NONE
-extern struct wpa_driver_ops wpa_driver_none_ops; /* driver_none.c */
-#endif /* CONFIG_DRIVER_NONE */
-
-
-struct wpa_driver_ops *hostapd_drivers[] =
-{
-#ifdef CONFIG_DRIVER_HOSTAP
- &wpa_driver_hostap_ops,
-#endif /* CONFIG_DRIVER_HOSTAP */
-#ifdef CONFIG_DRIVER_NL80211
- &wpa_driver_nl80211_ops,
-#endif /* CONFIG_DRIVER_NL80211 */
-#ifdef CONFIG_DRIVER_PRISM54
- &wpa_driver_prism54_ops,
-#endif /* CONFIG_DRIVER_PRISM54 */
-#ifdef CONFIG_DRIVER_MADWIFI
- &wpa_driver_madwifi_ops,
-#endif /* CONFIG_DRIVER_MADWIFI */
-#ifdef CONFIG_DRIVER_ATHEROS
- &wpa_driver_atheros_ops,
-#endif /* CONFIG_DRIVER_ATHEROS */
-#ifdef CONFIG_DRIVER_BSD
- &wpa_driver_bsd_ops,
-#endif /* CONFIG_DRIVER_BSD */
-#ifdef CONFIG_DRIVER_WIRED
- &wpa_driver_wired_ops,
-#endif /* CONFIG_DRIVER_WIRED */
-#ifdef CONFIG_DRIVER_TEST
- &wpa_driver_test_ops,
-#endif /* CONFIG_DRIVER_TEST */
-#ifdef CONFIG_DRIVER_NONE
- &wpa_driver_none_ops,
-#endif /* CONFIG_DRIVER_NONE */
- NULL
-};
diff --git a/contrib/wpa/hostapd/dump_state.c b/contrib/wpa/hostapd/dump_state.c
new file mode 100644
index 0000000..bba3068
--- /dev/null
+++ b/contrib/wpa/hostapd/dump_state.c
@@ -0,0 +1,184 @@
+/*
+ * hostapd / State dump
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "utils/includes.h"
+
+#include "utils/common.h"
+#include "radius/radius_client.h"
+#include "radius/radius_server.h"
+#include "eapol_auth/eapol_auth_sm.h"
+#include "eapol_auth/eapol_auth_sm_i.h"
+#include "eap_server/eap.h"
+#include "ap/hostapd.h"
+#include "ap/ap_config.h"
+#include "ap/sta_info.h"
+#include "dump_state.h"
+
+
+static void fprint_char(FILE *f, char c)
+{
+ if (c >= 32 && c < 127)
+ fprintf(f, "%c", c);
+ else
+ fprintf(f, "<%02x>", c);
+}
+
+
+static void ieee802_1x_dump_state(FILE *f, const char *prefix,
+ struct sta_info *sta)
+{
+ struct eapol_state_machine *sm = sta->eapol_sm;
+ if (sm == NULL)
+ return;
+
+ fprintf(f, "%sIEEE 802.1X:\n", prefix);
+
+ if (sm->identity) {
+ size_t i;
+ fprintf(f, "%sidentity=", prefix);
+ for (i = 0; i < sm->identity_len; i++)
+ fprint_char(f, sm->identity[i]);
+ fprintf(f, "\n");
+ }
+
+ fprintf(f, "%slast EAP type: Authentication Server: %d (%s) "
+ "Supplicant: %d (%s)\n", prefix,
+ sm->eap_type_authsrv,
+ eap_server_get_name(0, sm->eap_type_authsrv),
+ sm->eap_type_supp, eap_server_get_name(0, sm->eap_type_supp));
+
+ fprintf(f, "%scached_packets=%s\n", prefix,
+ sm->last_recv_radius ? "[RX RADIUS]" : "");
+
+ eapol_auth_dump_state(f, prefix, sm);
+}
+
+
+/**
+ * hostapd_dump_state - SIGUSR1 handler to dump hostapd state to a text file
+ */
+static void hostapd_dump_state(struct hostapd_data *hapd)
+{
+ FILE *f;
+ time_t now;
+ struct sta_info *sta;
+ int i;
+#ifndef CONFIG_NO_RADIUS
+ char *buf;
+#endif /* CONFIG_NO_RADIUS */
+
+ if (!hapd->conf->dump_log_name) {
+ wpa_printf(MSG_DEBUG, "Dump file not defined - ignoring dump "
+ "request");
+ return;
+ }
+
+ wpa_printf(MSG_DEBUG, "Dumping hostapd state to '%s'",
+ hapd->conf->dump_log_name);
+ f = fopen(hapd->conf->dump_log_name, "w");
+ if (f == NULL) {
+ wpa_printf(MSG_WARNING, "Could not open dump file '%s' for "
+ "writing.", hapd->conf->dump_log_name);
+ return;
+ }
+
+ time(&now);
+ fprintf(f, "hostapd state dump - %s", ctime(&now));
+ fprintf(f, "num_sta=%d num_sta_non_erp=%d "
+ "num_sta_no_short_slot_time=%d\n"
+ "num_sta_no_short_preamble=%d\n",
+ hapd->num_sta, hapd->iface->num_sta_non_erp,
+ hapd->iface->num_sta_no_short_slot_time,
+ hapd->iface->num_sta_no_short_preamble);
+
+ for (sta = hapd->sta_list; sta != NULL; sta = sta->next) {
+ fprintf(f, "\nSTA=" MACSTR "\n", MAC2STR(sta->addr));
+
+ fprintf(f,
+ " AID=%d flags=0x%x %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n"
+ " capability=0x%x listen_interval=%d\n",
+ sta->aid,
+ sta->flags,
+ (sta->flags & WLAN_STA_AUTH ? "[AUTH]" : ""),
+ (sta->flags & WLAN_STA_ASSOC ? "[ASSOC]" : ""),
+ (sta->flags & WLAN_STA_PS ? "[PS]" : ""),
+ (sta->flags & WLAN_STA_TIM ? "[TIM]" : ""),
+ (sta->flags & WLAN_STA_PERM ? "[PERM]" : ""),
+ (sta->flags & WLAN_STA_AUTHORIZED ? "[AUTHORIZED]" :
+ ""),
+ (sta->flags & WLAN_STA_PENDING_POLL ? "[PENDING_POLL" :
+ ""),
+ (sta->flags & WLAN_STA_SHORT_PREAMBLE ?
+ "[SHORT_PREAMBLE]" : ""),
+ (sta->flags & WLAN_STA_PREAUTH ? "[PREAUTH]" : ""),
+ (sta->flags & WLAN_STA_WMM ? "[WMM]" : ""),
+ (sta->flags & WLAN_STA_MFP ? "[MFP]" : ""),
+ (sta->flags & WLAN_STA_WPS ? "[WPS]" : ""),
+ (sta->flags & WLAN_STA_MAYBE_WPS ? "[MAYBE_WPS]" : ""),
+ (sta->flags & WLAN_STA_WDS ? "[WDS]" : ""),
+ (sta->flags & WLAN_STA_NONERP ? "[NonERP]" : ""),
+ sta->capability,
+ sta->listen_interval);
+
+ fprintf(f, " supported_rates=");
+ for (i = 0; i < sta->supported_rates_len; i++)
+ fprintf(f, "%02x ", sta->supported_rates[i]);
+ fprintf(f, "\n");
+
+ fprintf(f,
+ " timeout_next=%s\n",
+ (sta->timeout_next == STA_NULLFUNC ? "NULLFUNC POLL" :
+ (sta->timeout_next == STA_DISASSOC ? "DISASSOC" :
+ "DEAUTH")));
+
+ ieee802_1x_dump_state(f, " ", sta);
+ }
+
+#ifndef CONFIG_NO_RADIUS
+ buf = os_malloc(4096);
+ if (buf) {
+ int count = radius_client_get_mib(hapd->radius, buf, 4096);
+ if (count < 0)
+ count = 0;
+ else if (count > 4095)
+ count = 4095;
+ buf[count] = '\0';
+ fprintf(f, "%s", buf);
+
+#ifdef RADIUS_SERVER
+ count = radius_server_get_mib(hapd->radius_srv, buf, 4096);
+ if (count < 0)
+ count = 0;
+ else if (count > 4095)
+ count = 4095;
+ buf[count] = '\0';
+ fprintf(f, "%s", buf);
+#endif /* RADIUS_SERVER */
+
+ os_free(buf);
+ }
+#endif /* CONFIG_NO_RADIUS */
+ fclose(f);
+}
+
+
+int handle_dump_state_iface(struct hostapd_iface *iface, void *ctx)
+{
+ size_t i;
+
+ for (i = 0; i < iface->num_bss; i++)
+ hostapd_dump_state(iface->bss[i]);
+
+ return 0;
+}
diff --git a/contrib/wpa/hostapd/dump_state.h b/contrib/wpa/hostapd/dump_state.h
new file mode 100644
index 0000000..e14f08a
--- /dev/null
+++ b/contrib/wpa/hostapd/dump_state.h
@@ -0,0 +1,20 @@
+/*
+ * hostapd / State dump
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef DUMP_STATE_H
+#define DUMP_STATE_H
+
+int handle_dump_state_iface(struct hostapd_iface *iface, void *ctx);
+
+#endif /* DUMP_STATE_H */
diff --git a/contrib/wpa/hostapd/eap_register.c b/contrib/wpa/hostapd/eap_register.c
new file mode 100644
index 0000000..ae9bf9d
--- /dev/null
+++ b/contrib/wpa/hostapd/eap_register.c
@@ -0,0 +1,134 @@
+/*
+ * EAP method registration
+ * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "eap_server/eap_methods.h"
+#include "eap_register.h"
+
+
+/**
+ * eap_server_register_methods - Register statically linked EAP server methods
+ * Returns: 0 on success, -1 or -2 on failure
+ *
+ * This function is called at program initialization to register all EAP
+ * methods that were linked in statically.
+ */
+int eap_server_register_methods(void)
+{
+ int ret = 0;
+
+#ifdef EAP_SERVER_IDENTITY
+ if (ret == 0)
+ ret = eap_server_identity_register();
+#endif /* EAP_SERVER_IDENTITY */
+
+#ifdef EAP_SERVER_MD5
+ if (ret == 0)
+ ret = eap_server_md5_register();
+#endif /* EAP_SERVER_MD5 */
+
+#ifdef EAP_SERVER_TLS
+ if (ret == 0)
+ ret = eap_server_tls_register();
+#endif /* EAP_SERVER_TLS */
+
+#ifdef EAP_SERVER_MSCHAPV2
+ if (ret == 0)
+ ret = eap_server_mschapv2_register();
+#endif /* EAP_SERVER_MSCHAPV2 */
+
+#ifdef EAP_SERVER_PEAP
+ if (ret == 0)
+ ret = eap_server_peap_register();
+#endif /* EAP_SERVER_PEAP */
+
+#ifdef EAP_SERVER_TLV
+ if (ret == 0)
+ ret = eap_server_tlv_register();
+#endif /* EAP_SERVER_TLV */
+
+#ifdef EAP_SERVER_GTC
+ if (ret == 0)
+ ret = eap_server_gtc_register();
+#endif /* EAP_SERVER_GTC */
+
+#ifdef EAP_SERVER_TTLS
+ if (ret == 0)
+ ret = eap_server_ttls_register();
+#endif /* EAP_SERVER_TTLS */
+
+#ifdef EAP_SERVER_SIM
+ if (ret == 0)
+ ret = eap_server_sim_register();
+#endif /* EAP_SERVER_SIM */
+
+#ifdef EAP_SERVER_AKA
+ if (ret == 0)
+ ret = eap_server_aka_register();
+#endif /* EAP_SERVER_AKA */
+
+#ifdef EAP_SERVER_AKA_PRIME
+ if (ret == 0)
+ ret = eap_server_aka_prime_register();
+#endif /* EAP_SERVER_AKA_PRIME */
+
+#ifdef EAP_SERVER_PAX
+ if (ret == 0)
+ ret = eap_server_pax_register();
+#endif /* EAP_SERVER_PAX */
+
+#ifdef EAP_SERVER_PSK
+ if (ret == 0)
+ ret = eap_server_psk_register();
+#endif /* EAP_SERVER_PSK */
+
+#ifdef EAP_SERVER_SAKE
+ if (ret == 0)
+ ret = eap_server_sake_register();
+#endif /* EAP_SERVER_SAKE */
+
+#ifdef EAP_SERVER_GPSK
+ if (ret == 0)
+ ret = eap_server_gpsk_register();
+#endif /* EAP_SERVER_GPSK */
+
+#ifdef EAP_SERVER_VENDOR_TEST
+ if (ret == 0)
+ ret = eap_server_vendor_test_register();
+#endif /* EAP_SERVER_VENDOR_TEST */
+
+#ifdef EAP_SERVER_FAST
+ if (ret == 0)
+ ret = eap_server_fast_register();
+#endif /* EAP_SERVER_FAST */
+
+#ifdef EAP_SERVER_WSC
+ if (ret == 0)
+ ret = eap_server_wsc_register();
+#endif /* EAP_SERVER_WSC */
+
+#ifdef EAP_SERVER_IKEV2
+ if (ret == 0)
+ ret = eap_server_ikev2_register();
+#endif /* EAP_SERVER_IKEV2 */
+
+#ifdef EAP_SERVER_TNC
+ if (ret == 0)
+ ret = eap_server_tnc_register();
+#endif /* EAP_SERVER_TNC */
+
+ return ret;
+}
diff --git a/contrib/wpa/src/crypto/rc4.h b/contrib/wpa/hostapd/eap_register.h
index 35c7e41..82e7171 100644
--- a/contrib/wpa/src/crypto/rc4.h
+++ b/contrib/wpa/hostapd/eap_register.h
@@ -1,6 +1,6 @@
/*
- * RC4 stream cipher
- * Copyright (c) 2002-2005, Jouni Malinen <j@w1.fi>
+ * EAP method registration
+ * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -12,10 +12,9 @@
* See README and COPYING for more details.
*/
-#ifndef RC4_H
-#define RC4_H
+#ifndef EAP_REGISTER_H
+#define EAP_REGISTER_H
-void rc4_skip(const u8 *key, size_t keylen, size_t skip,
- u8 *data, size_t data_len);
+int eap_server_register_methods(void);
-#endif /* RC4_H */
+#endif /* EAP_REGISTER_H */
diff --git a/contrib/wpa/src/hlr_auc_gw/hlr_auc_gw.c b/contrib/wpa/hostapd/hlr_auc_gw.c
index e318903..36934aa 100644
--- a/contrib/wpa/src/hlr_auc_gw/hlr_auc_gw.c
+++ b/contrib/wpa/hostapd/hlr_auc_gw.c
@@ -47,7 +47,7 @@
#include <sys/un.h>
#include "common.h"
-#include "milenage.h"
+#include "crypto/milenage.h"
static const char *default_socket_path = "/tmp/hlr_auc_gw.sock";
static const char *socket_path;
diff --git a/contrib/wpa/src/hlr_auc_gw/hlr_auc_gw.milenage_db b/contrib/wpa/hostapd/hlr_auc_gw.milenage_db
index ecd06d7..ecd06d7 100644
--- a/contrib/wpa/src/hlr_auc_gw/hlr_auc_gw.milenage_db
+++ b/contrib/wpa/hostapd/hlr_auc_gw.milenage_db
diff --git a/contrib/wpa/hostapd/hostap_common.h b/contrib/wpa/hostapd/hostap_common.h
deleted file mode 100644
index 5a57dca..0000000
--- a/contrib/wpa/hostapd/hostap_common.h
+++ /dev/null
@@ -1,216 +0,0 @@
-/*
- * hostapd / Kernel driver communication with Linux Host AP driver
- * Copyright (c) 2002-2006, Jouni Malinen <j@w1.fi>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
- */
-
-#ifndef HOSTAP_COMMON_H
-#define HOSTAP_COMMON_H
-
-/* netdevice private ioctls (used, e.g., with iwpriv from user space) */
-
-/* New wireless extensions API - SET/GET convention (even ioctl numbers are
- * root only)
- */
-#define PRISM2_IOCTL_PRISM2_PARAM (SIOCIWFIRSTPRIV + 0)
-#define PRISM2_IOCTL_GET_PRISM2_PARAM (SIOCIWFIRSTPRIV + 1)
-#define PRISM2_IOCTL_WRITEMIF (SIOCIWFIRSTPRIV + 2)
-#define PRISM2_IOCTL_READMIF (SIOCIWFIRSTPRIV + 3)
-#define PRISM2_IOCTL_MONITOR (SIOCIWFIRSTPRIV + 4)
-#define PRISM2_IOCTL_RESET (SIOCIWFIRSTPRIV + 6)
-#define PRISM2_IOCTL_INQUIRE (SIOCIWFIRSTPRIV + 8)
-#define PRISM2_IOCTL_WDS_ADD (SIOCIWFIRSTPRIV + 10)
-#define PRISM2_IOCTL_WDS_DEL (SIOCIWFIRSTPRIV + 12)
-#define PRISM2_IOCTL_SET_RID_WORD (SIOCIWFIRSTPRIV + 14)
-#define PRISM2_IOCTL_MACCMD (SIOCIWFIRSTPRIV + 16)
-#define PRISM2_IOCTL_ADDMAC (SIOCIWFIRSTPRIV + 18)
-#define PRISM2_IOCTL_DELMAC (SIOCIWFIRSTPRIV + 20)
-#define PRISM2_IOCTL_KICKMAC (SIOCIWFIRSTPRIV + 22)
-
-/* following are not in SIOCGIWPRIV list; check permission in the driver code
- */
-#define PRISM2_IOCTL_DOWNLOAD (SIOCDEVPRIVATE + 13)
-#define PRISM2_IOCTL_HOSTAPD (SIOCDEVPRIVATE + 14)
-
-
-/* PRISM2_IOCTL_PRISM2_PARAM ioctl() subtypes: */
-enum {
- /* PRISM2_PARAM_PTYPE = 1, */ /* REMOVED 2003-10-22 */
- PRISM2_PARAM_TXRATECTRL = 2,
- PRISM2_PARAM_BEACON_INT = 3,
- PRISM2_PARAM_PSEUDO_IBSS = 4,
- PRISM2_PARAM_ALC = 5,
- /* PRISM2_PARAM_TXPOWER = 6, */ /* REMOVED 2003-10-22 */
- PRISM2_PARAM_DUMP = 7,
- PRISM2_PARAM_OTHER_AP_POLICY = 8,
- PRISM2_PARAM_AP_MAX_INACTIVITY = 9,
- PRISM2_PARAM_AP_BRIDGE_PACKETS = 10,
- PRISM2_PARAM_DTIM_PERIOD = 11,
- PRISM2_PARAM_AP_NULLFUNC_ACK = 12,
- PRISM2_PARAM_MAX_WDS = 13,
- PRISM2_PARAM_AP_AUTOM_AP_WDS = 14,
- PRISM2_PARAM_AP_AUTH_ALGS = 15,
- PRISM2_PARAM_MONITOR_ALLOW_FCSERR = 16,
- PRISM2_PARAM_HOST_ENCRYPT = 17,
- PRISM2_PARAM_HOST_DECRYPT = 18,
- PRISM2_PARAM_BUS_MASTER_THRESHOLD_RX = 19,
- PRISM2_PARAM_BUS_MASTER_THRESHOLD_TX = 20,
- PRISM2_PARAM_HOST_ROAMING = 21,
- PRISM2_PARAM_BCRX_STA_KEY = 22,
- PRISM2_PARAM_IEEE_802_1X = 23,
- PRISM2_PARAM_ANTSEL_TX = 24,
- PRISM2_PARAM_ANTSEL_RX = 25,
- PRISM2_PARAM_MONITOR_TYPE = 26,
- PRISM2_PARAM_WDS_TYPE = 27,
- PRISM2_PARAM_HOSTSCAN = 28,
- PRISM2_PARAM_AP_SCAN = 29,
- PRISM2_PARAM_ENH_SEC = 30,
- PRISM2_PARAM_IO_DEBUG = 31,
- PRISM2_PARAM_BASIC_RATES = 32,
- PRISM2_PARAM_OPER_RATES = 33,
- PRISM2_PARAM_HOSTAPD = 34,
- PRISM2_PARAM_HOSTAPD_STA = 35,
- PRISM2_PARAM_WPA = 36,
- PRISM2_PARAM_PRIVACY_INVOKED = 37,
- PRISM2_PARAM_TKIP_COUNTERMEASURES = 38,
- PRISM2_PARAM_DROP_UNENCRYPTED = 39,
- PRISM2_PARAM_SCAN_CHANNEL_MASK = 40,
-};
-
-enum { HOSTAP_ANTSEL_DO_NOT_TOUCH = 0, HOSTAP_ANTSEL_DIVERSITY = 1,
- HOSTAP_ANTSEL_LOW = 2, HOSTAP_ANTSEL_HIGH = 3 };
-
-
-/* PRISM2_IOCTL_MACCMD ioctl() subcommands: */
-enum { AP_MAC_CMD_POLICY_OPEN = 0, AP_MAC_CMD_POLICY_ALLOW = 1,
- AP_MAC_CMD_POLICY_DENY = 2, AP_MAC_CMD_FLUSH = 3,
- AP_MAC_CMD_KICKALL = 4 };
-
-
-/* PRISM2_IOCTL_DOWNLOAD ioctl() dl_cmd: */
-enum {
- PRISM2_DOWNLOAD_VOLATILE = 1 /* RAM */,
- /* Note! Old versions of prism2_srec have a fatal error in CRC-16
- * calculation, which will corrupt all non-volatile downloads.
- * PRISM2_DOWNLOAD_NON_VOLATILE used to be 2, but it is now 3 to
- * prevent use of old versions of prism2_srec for non-volatile
- * download. */
- PRISM2_DOWNLOAD_NON_VOLATILE = 3 /* FLASH */,
- PRISM2_DOWNLOAD_VOLATILE_GENESIS = 4 /* RAM in Genesis mode */,
- /* Persistent versions of volatile download commands (keep firmware
- * data in memory and automatically re-download after hw_reset */
- PRISM2_DOWNLOAD_VOLATILE_PERSISTENT = 5,
- PRISM2_DOWNLOAD_VOLATILE_GENESIS_PERSISTENT = 6,
-};
-
-struct prism2_download_param {
- u32 dl_cmd;
- u32 start_addr;
- u32 num_areas;
- struct prism2_download_area {
- u32 addr; /* wlan card address */
- u32 len;
- caddr_t ptr; /* pointer to data in user space */
- } data[0];
-};
-
-#define PRISM2_MAX_DOWNLOAD_AREA_LEN 131072
-#define PRISM2_MAX_DOWNLOAD_LEN 262144
-
-
-/* PRISM2_IOCTL_HOSTAPD ioctl() cmd: */
-enum {
- PRISM2_HOSTAPD_FLUSH = 1,
- PRISM2_HOSTAPD_ADD_STA = 2,
- PRISM2_HOSTAPD_REMOVE_STA = 3,
- PRISM2_HOSTAPD_GET_INFO_STA = 4,
- /* REMOVED: PRISM2_HOSTAPD_RESET_TXEXC_STA = 5, */
- PRISM2_SET_ENCRYPTION = 6,
- PRISM2_GET_ENCRYPTION = 7,
- PRISM2_HOSTAPD_SET_FLAGS_STA = 8,
- PRISM2_HOSTAPD_GET_RID = 9,
- PRISM2_HOSTAPD_SET_RID = 10,
- PRISM2_HOSTAPD_SET_ASSOC_AP_ADDR = 11,
- PRISM2_HOSTAPD_SET_GENERIC_ELEMENT = 12,
- PRISM2_HOSTAPD_MLME = 13,
- PRISM2_HOSTAPD_SCAN_REQ = 14,
- PRISM2_HOSTAPD_STA_CLEAR_STATS = 15,
-};
-
-#define PRISM2_HOSTAPD_MAX_BUF_SIZE 1024
-#define PRISM2_HOSTAPD_RID_HDR_LEN \
-((size_t) (&((struct prism2_hostapd_param *) 0)->u.rid.data))
-#define PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN \
-((size_t) (&((struct prism2_hostapd_param *) 0)->u.generic_elem.data))
-
-/* Maximum length for algorithm names (-1 for nul termination) used in ioctl()
- */
-#define HOSTAP_CRYPT_ALG_NAME_LEN 16
-
-
-struct prism2_hostapd_param {
- u32 cmd;
- u8 sta_addr[ETH_ALEN];
- union {
- struct {
- u16 aid;
- u16 capability;
- u8 tx_supp_rates;
- } add_sta;
- struct {
- u32 inactive_sec;
- } get_info_sta;
- struct {
- u8 alg[HOSTAP_CRYPT_ALG_NAME_LEN];
- u32 flags;
- u32 err;
- u8 idx;
- u8 seq[8]; /* sequence counter (set: RX, get: TX) */
- u16 key_len;
- u8 key[0];
- } crypt;
- struct {
- u32 flags_and;
- u32 flags_or;
- } set_flags_sta;
- struct {
- u16 rid;
- u16 len;
- u8 data[0];
- } rid;
- struct {
- u8 len;
- u8 data[0];
- } generic_elem;
- struct {
-#define MLME_STA_DEAUTH 0
-#define MLME_STA_DISASSOC 1
- u16 cmd;
- u16 reason_code;
- } mlme;
- struct {
- u8 ssid_len;
- u8 ssid[32];
- } scan_req;
- } u;
-};
-
-#define HOSTAP_CRYPT_FLAG_SET_TX_KEY BIT(0)
-#define HOSTAP_CRYPT_FLAG_PERMANENT BIT(1)
-
-#define HOSTAP_CRYPT_ERR_UNKNOWN_ALG 2
-#define HOSTAP_CRYPT_ERR_UNKNOWN_ADDR 3
-#define HOSTAP_CRYPT_ERR_CRYPT_INIT_FAILED 4
-#define HOSTAP_CRYPT_ERR_KEY_SET_FAILED 5
-#define HOSTAP_CRYPT_ERR_TX_KEY_SET_FAILED 6
-#define HOSTAP_CRYPT_ERR_CARD_CONF_FAILED 7
-
-#endif /* HOSTAP_COMMON_H */
diff --git a/contrib/wpa/hostapd/hostapd.8 b/contrib/wpa/hostapd/hostapd.8
index a67a1bc..b4456bb 100644
--- a/contrib/wpa/hostapd/hostapd.8
+++ b/contrib/wpa/hostapd/hostapd.8
@@ -12,7 +12,7 @@ daemon.
.B hostapd
is a user space daemon for access point and authentication servers.
It implements IEEE 802.11 access point management, IEEE 802.1X/WPA/WPA2/EAP Authenticators and RADIUS authentication server.
-The current version supports Linux (Host AP, madwifi, Prism54 drivers) and FreeBSD (net80211).
+The current version supports Linux (Host AP, madwifi, mac80211-based drivers) and FreeBSD (net80211).
.B hostapd
is designed to be a "daemon" program that runs in the background and acts as the backend component controlling authentication.
diff --git a/contrib/wpa/hostapd/hostapd.c b/contrib/wpa/hostapd/hostapd.c
deleted file mode 100644
index b1c5a2c..0000000
--- a/contrib/wpa/hostapd/hostapd.c
+++ /dev/null
@@ -1,2043 +0,0 @@
-/*
- * hostapd / Initialization and configuration
- * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
- */
-
-#include "includes.h"
-#ifndef CONFIG_NATIVE_WINDOWS
-#include <syslog.h>
-#endif /* CONFIG_NATIVE_WINDOWS */
-
-#include "eloop.h"
-#include "hostapd.h"
-#include "ieee802_1x.h"
-#include "ieee802_11.h"
-#include "beacon.h"
-#include "hw_features.h"
-#include "accounting.h"
-#include "eapol_sm.h"
-#include "iapp.h"
-#include "ap.h"
-#include "ieee802_11_auth.h"
-#include "ap_list.h"
-#include "sta_info.h"
-#include "driver.h"
-#include "radius/radius_client.h"
-#include "radius/radius_server.h"
-#include "wpa.h"
-#include "preauth.h"
-#include "wme.h"
-#include "vlan_init.h"
-#include "ctrl_iface.h"
-#include "tls.h"
-#include "eap_server/eap_sim_db.h"
-#include "eap_server/eap.h"
-#include "eap_server/tncs.h"
-#include "version.h"
-#include "l2_packet/l2_packet.h"
-#include "wps_hostapd.h"
-
-
-static int hostapd_radius_get_eap_user(void *ctx, const u8 *identity,
- size_t identity_len, int phase2,
- struct eap_user *user);
-static int hostapd_flush_old_stations(struct hostapd_data *hapd);
-static int hostapd_setup_wpa(struct hostapd_data *hapd);
-static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd);
-
-struct hapd_interfaces {
- size_t count;
- struct hostapd_iface **iface;
-};
-
-unsigned char rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
-
-
-extern int wpa_debug_level;
-extern int wpa_debug_show_keys;
-extern int wpa_debug_timestamp;
-
-
-static void hostapd_logger_cb(void *ctx, const u8 *addr, unsigned int module,
- int level, const char *txt, size_t len)
-{
- struct hostapd_data *hapd = ctx;
- char *format, *module_str;
- int maxlen;
- int conf_syslog_level, conf_stdout_level;
- unsigned int conf_syslog, conf_stdout;
-
- maxlen = len + 100;
- format = os_malloc(maxlen);
- if (!format)
- return;
-
- if (hapd && hapd->conf) {
- conf_syslog_level = hapd->conf->logger_syslog_level;
- conf_stdout_level = hapd->conf->logger_stdout_level;
- conf_syslog = hapd->conf->logger_syslog;
- conf_stdout = hapd->conf->logger_stdout;
- } else {
- conf_syslog_level = conf_stdout_level = 0;
- conf_syslog = conf_stdout = (unsigned int) -1;
- }
-
- switch (module) {
- case HOSTAPD_MODULE_IEEE80211:
- module_str = "IEEE 802.11";
- break;
- case HOSTAPD_MODULE_IEEE8021X:
- module_str = "IEEE 802.1X";
- break;
- case HOSTAPD_MODULE_RADIUS:
- module_str = "RADIUS";
- break;
- case HOSTAPD_MODULE_WPA:
- module_str = "WPA";
- break;
- case HOSTAPD_MODULE_DRIVER:
- module_str = "DRIVER";
- break;
- case HOSTAPD_MODULE_IAPP:
- module_str = "IAPP";
- break;
- case HOSTAPD_MODULE_MLME:
- module_str = "MLME";
- break;
- default:
- module_str = NULL;
- break;
- }
-
- if (hapd && hapd->conf && addr)
- os_snprintf(format, maxlen, "%s: STA " MACSTR "%s%s: %s",
- hapd->conf->iface, MAC2STR(addr),
- module_str ? " " : "", module_str, txt);
- else if (hapd && hapd->conf)
- os_snprintf(format, maxlen, "%s:%s%s %s",
- hapd->conf->iface, module_str ? " " : "",
- module_str, txt);
- else if (addr)
- os_snprintf(format, maxlen, "STA " MACSTR "%s%s: %s",
- MAC2STR(addr), module_str ? " " : "",
- module_str, txt);
- else
- os_snprintf(format, maxlen, "%s%s%s",
- module_str, module_str ? ": " : "", txt);
-
- if ((conf_stdout & module) && level >= conf_stdout_level) {
- wpa_debug_print_timestamp();
- printf("%s\n", format);
- }
-
-#ifndef CONFIG_NATIVE_WINDOWS
- if ((conf_syslog & module) && level >= conf_syslog_level) {
- int priority;
- switch (level) {
- case HOSTAPD_LEVEL_DEBUG_VERBOSE:
- case HOSTAPD_LEVEL_DEBUG:
- priority = LOG_DEBUG;
- break;
- case HOSTAPD_LEVEL_INFO:
- priority = LOG_INFO;
- break;
- case HOSTAPD_LEVEL_NOTICE:
- priority = LOG_NOTICE;
- break;
- case HOSTAPD_LEVEL_WARNING:
- priority = LOG_WARNING;
- break;
- default:
- priority = LOG_INFO;
- break;
- }
- syslog(priority, "%s", format);
- }
-#endif /* CONFIG_NATIVE_WINDOWS */
-
- os_free(format);
-}
-
-
-static void hostapd_deauth_all_stas(struct hostapd_data *hapd)
-{
- u8 addr[ETH_ALEN];
-
- /* New Prism2.5/3 STA firmware versions seem to have issues with this
- * broadcast deauth frame. This gets the firmware in odd state where
- * nothing works correctly, so let's skip sending this for the hostap
- * driver. */
-
- if (hapd->driver && os_strcmp(hapd->driver->name, "hostap") != 0) {
- os_memset(addr, 0xff, ETH_ALEN);
- hostapd_sta_deauth(hapd, addr,
- WLAN_REASON_PREV_AUTH_NOT_VALID);
- }
-}
-
-
-/**
- * hostapd_prune_associations - Remove extraneous associations
- * @hapd: Pointer to BSS data for the most recent association
- * @sta: Pointer to the associated STA data
- *
- * This function looks through all radios and BSS's for previous
- * (stale) associations of STA. If any are found they are removed.
- */
-static void hostapd_prune_associations(struct hostapd_data *hapd,
- struct sta_info *sta)
-{
- struct sta_info *osta;
- struct hostapd_data *ohapd;
- size_t i, j;
- struct hapd_interfaces *interfaces = eloop_get_user_data();
-
- for (i = 0; i < interfaces->count; i++) {
- for (j = 0; j < interfaces->iface[i]->num_bss; j++) {
- ohapd = interfaces->iface[i]->bss[j];
- if (ohapd == hapd)
- continue;
- osta = ap_get_sta(ohapd, sta->addr);
- if (!osta)
- continue;
-
- ap_sta_disassociate(ohapd, osta,
- WLAN_REASON_UNSPECIFIED);
- }
- }
-}
-
-
-/**
- * hostapd_new_assoc_sta - Notify that a new station associated with the AP
- * @hapd: Pointer to BSS data
- * @sta: Pointer to the associated STA data
- * @reassoc: 1 to indicate this was a re-association; 0 = first association
- *
- * This function will be called whenever a station associates with the AP. It
- * can be called for ieee802_11.c for drivers that export MLME to hostapd and
- * from driver_*.c for drivers that take care of management frames (IEEE 802.11
- * authentication and association) internally.
- */
-void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
- int reassoc)
-{
- if (hapd->tkip_countermeasures) {
- hostapd_sta_deauth(hapd, sta->addr,
- WLAN_REASON_MICHAEL_MIC_FAILURE);
- return;
- }
-
- hostapd_prune_associations(hapd, sta);
-
- /* IEEE 802.11F (IAPP) */
- if (hapd->conf->ieee802_11f)
- iapp_new_station(hapd->iapp, sta);
-
- /* Start accounting here, if IEEE 802.1X and WPA are not used.
- * IEEE 802.1X/WPA code will start accounting after the station has
- * been authorized. */
- if (!hapd->conf->ieee802_1x && !hapd->conf->wpa)
- accounting_sta_start(hapd, sta);
-
- hostapd_wmm_sta_config(hapd, sta);
-
- /* Start IEEE 802.1X authentication process for new stations */
- ieee802_1x_new_station(hapd, sta);
- if (reassoc) {
- if (sta->auth_alg != WLAN_AUTH_FT &&
- !(sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)))
- wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH);
- } else
- wpa_auth_sta_associated(hapd->wpa_auth, sta->wpa_sm);
-}
-
-
-#ifdef EAP_SERVER
-static int hostapd_sim_db_cb_sta(struct hostapd_data *hapd,
- struct sta_info *sta, void *ctx)
-{
- if (eapol_auth_eap_pending_cb(sta->eapol_sm, ctx) == 0)
- return 1;
- return 0;
-}
-
-
-static void hostapd_sim_db_cb(void *ctx, void *session_ctx)
-{
- struct hostapd_data *hapd = ctx;
- if (ap_for_each_sta(hapd, hostapd_sim_db_cb_sta, session_ctx) == 0)
- radius_server_eap_pending_cb(hapd->radius_srv, session_ctx);
-}
-#endif /* EAP_SERVER */
-
-
-/**
- * handle_term - SIGINT and SIGTERM handler to terminate hostapd process
- */
-static void handle_term(int sig, void *eloop_ctx, void *signal_ctx)
-{
- wpa_printf(MSG_DEBUG, "Signal %d received - terminating", sig);
- eloop_terminate();
-}
-
-
-static void hostapd_wpa_auth_conf(struct hostapd_bss_config *conf,
- struct wpa_auth_config *wconf)
-{
- wconf->wpa = conf->wpa;
- wconf->wpa_key_mgmt = conf->wpa_key_mgmt;
- wconf->wpa_pairwise = conf->wpa_pairwise;
- wconf->wpa_group = conf->wpa_group;
- wconf->wpa_group_rekey = conf->wpa_group_rekey;
- wconf->wpa_strict_rekey = conf->wpa_strict_rekey;
- wconf->wpa_gmk_rekey = conf->wpa_gmk_rekey;
- wconf->wpa_ptk_rekey = conf->wpa_ptk_rekey;
- wconf->rsn_pairwise = conf->rsn_pairwise;
- wconf->rsn_preauth = conf->rsn_preauth;
- wconf->eapol_version = conf->eapol_version;
- wconf->peerkey = conf->peerkey;
- wconf->wmm_enabled = conf->wmm_enabled;
- wconf->okc = conf->okc;
-#ifdef CONFIG_IEEE80211W
- wconf->ieee80211w = conf->ieee80211w;
-#endif /* CONFIG_IEEE80211W */
-#ifdef CONFIG_IEEE80211R
- wconf->ssid_len = conf->ssid.ssid_len;
- if (wconf->ssid_len > SSID_LEN)
- wconf->ssid_len = SSID_LEN;
- os_memcpy(wconf->ssid, conf->ssid.ssid, wconf->ssid_len);
- os_memcpy(wconf->mobility_domain, conf->mobility_domain,
- MOBILITY_DOMAIN_ID_LEN);
- if (conf->nas_identifier &&
- os_strlen(conf->nas_identifier) <= FT_R0KH_ID_MAX_LEN) {
- wconf->r0_key_holder_len = os_strlen(conf->nas_identifier);
- os_memcpy(wconf->r0_key_holder, conf->nas_identifier,
- wconf->r0_key_holder_len);
- }
- os_memcpy(wconf->r1_key_holder, conf->r1_key_holder, FT_R1KH_ID_LEN);
- wconf->r0_key_lifetime = conf->r0_key_lifetime;
- wconf->reassociation_deadline = conf->reassociation_deadline;
- wconf->r0kh_list = conf->r0kh_list;
- wconf->r1kh_list = conf->r1kh_list;
- wconf->pmk_r1_push = conf->pmk_r1_push;
-#endif /* CONFIG_IEEE80211R */
-}
-
-
-int hostapd_reload_config(struct hostapd_iface *iface)
-{
- struct hostapd_data *hapd = iface->bss[0];
- struct hostapd_config *newconf, *oldconf;
- struct wpa_auth_config wpa_auth_conf;
- size_t j;
-
- newconf = hostapd_config_read(iface->config_fname);
- if (newconf == NULL)
- return -1;
-
- /*
- * Deauthenticate all stations since the new configuration may not
- * allow them to use the BSS anymore.
- */
- for (j = 0; j < iface->num_bss; j++)
- hostapd_flush_old_stations(iface->bss[j]);
-
- /* TODO: update dynamic data based on changed configuration
- * items (e.g., open/close sockets, etc.) */
- radius_client_flush(hapd->radius, 0);
-
- oldconf = hapd->iconf;
- hapd->iconf = newconf;
- hapd->conf = &newconf->bss[0];
- iface->conf = newconf;
-
- if (hostapd_setup_wpa_psk(hapd->conf)) {
- wpa_printf(MSG_ERROR, "Failed to re-configure WPA PSK "
- "after reloading configuration");
- }
-
- if (hapd->conf->wpa && hapd->wpa_auth == NULL)
- hostapd_setup_wpa(hapd);
- else if (hapd->conf->wpa) {
- hostapd_wpa_auth_conf(&newconf->bss[0], &wpa_auth_conf);
- wpa_reconfig(hapd->wpa_auth, &wpa_auth_conf);
- } else if (hapd->wpa_auth) {
- wpa_deinit(hapd->wpa_auth);
- hapd->wpa_auth = NULL;
- hostapd_set_privacy(hapd, 0);
- hostapd_setup_encryption(hapd->conf->iface, hapd);
- }
-
- ieee802_11_set_beacon(hapd);
-
- if (hapd->conf->ssid.ssid_set &&
- hostapd_set_ssid(hapd, (u8 *) hapd->conf->ssid.ssid,
- hapd->conf->ssid.ssid_len)) {
- wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
- /* try to continue */
- }
-
- if (hapd->conf->ieee802_1x || hapd->conf->wpa)
- hostapd_set_ieee8021x(hapd->conf->iface, hapd, 1);
-
- hostapd_config_free(oldconf);
-
- wpa_printf(MSG_DEBUG, "Reconfigured interface %s", hapd->conf->iface);
-
- return 0;
-}
-
-
-#ifndef CONFIG_NATIVE_WINDOWS
-/**
- * handle_reload - SIGHUP handler to reload configuration
- */
-static void handle_reload(int sig, void *eloop_ctx, void *signal_ctx)
-{
- struct hapd_interfaces *hapds = (struct hapd_interfaces *) eloop_ctx;
- size_t i;
-
- wpa_printf(MSG_DEBUG, "Signal %d received - reloading configuration",
- sig);
-
- for (i = 0; i < hapds->count; i++) {
- if (hostapd_reload_config(hapds->iface[i]) < 0) {
- wpa_printf(MSG_WARNING, "Failed to read new "
- "configuration file - continuing with "
- "old.");
- continue;
- }
- }
-}
-
-
-#ifdef HOSTAPD_DUMP_STATE
-/**
- * hostapd_dump_state - SIGUSR1 handler to dump hostapd state to a text file
- */
-static void hostapd_dump_state(struct hostapd_data *hapd)
-{
- FILE *f;
- time_t now;
- struct sta_info *sta;
- int i;
- char *buf;
-
- if (!hapd->conf->dump_log_name) {
- wpa_printf(MSG_DEBUG, "Dump file not defined - ignoring dump "
- "request");
- return;
- }
-
- wpa_printf(MSG_DEBUG, "Dumping hostapd state to '%s'",
- hapd->conf->dump_log_name);
- f = fopen(hapd->conf->dump_log_name, "w");
- if (f == NULL) {
- wpa_printf(MSG_WARNING, "Could not open dump file '%s' for "
- "writing.", hapd->conf->dump_log_name);
- return;
- }
-
- time(&now);
- fprintf(f, "hostapd state dump - %s", ctime(&now));
- fprintf(f, "num_sta=%d num_sta_non_erp=%d "
- "num_sta_no_short_slot_time=%d\n"
- "num_sta_no_short_preamble=%d\n",
- hapd->num_sta, hapd->iface->num_sta_non_erp,
- hapd->iface->num_sta_no_short_slot_time,
- hapd->iface->num_sta_no_short_preamble);
-
- for (sta = hapd->sta_list; sta != NULL; sta = sta->next) {
- fprintf(f, "\nSTA=" MACSTR "\n", MAC2STR(sta->addr));
-
- fprintf(f,
- " AID=%d flags=0x%x %s%s%s%s%s%s%s%s%s%s%s%s%s%s\n"
- " capability=0x%x listen_interval=%d\n",
- sta->aid,
- sta->flags,
- (sta->flags & WLAN_STA_AUTH ? "[AUTH]" : ""),
- (sta->flags & WLAN_STA_ASSOC ? "[ASSOC]" : ""),
- (sta->flags & WLAN_STA_PS ? "[PS]" : ""),
- (sta->flags & WLAN_STA_TIM ? "[TIM]" : ""),
- (sta->flags & WLAN_STA_PERM ? "[PERM]" : ""),
- (sta->flags & WLAN_STA_AUTHORIZED ? "[AUTHORIZED]" :
- ""),
- (sta->flags & WLAN_STA_PENDING_POLL ? "[PENDING_POLL" :
- ""),
- (sta->flags & WLAN_STA_SHORT_PREAMBLE ?
- "[SHORT_PREAMBLE]" : ""),
- (sta->flags & WLAN_STA_PREAUTH ? "[PREAUTH]" : ""),
- (sta->flags & WLAN_STA_WMM ? "[WMM]" : ""),
- (sta->flags & WLAN_STA_MFP ? "[MFP]" : ""),
- (sta->flags & WLAN_STA_WPS ? "[WPS]" : ""),
- (sta->flags & WLAN_STA_MAYBE_WPS ? "[MAYBE_WPS]" : ""),
- (sta->flags & WLAN_STA_NONERP ? "[NonERP]" : ""),
- sta->capability,
- sta->listen_interval);
-
- fprintf(f, " supported_rates=");
- for (i = 0; i < sta->supported_rates_len; i++)
- fprintf(f, "%02x ", sta->supported_rates[i]);
- fprintf(f, "\n");
-
- fprintf(f,
- " timeout_next=%s\n",
- (sta->timeout_next == STA_NULLFUNC ? "NULLFUNC POLL" :
- (sta->timeout_next == STA_DISASSOC ? "DISASSOC" :
- "DEAUTH")));
-
- ieee802_1x_dump_state(f, " ", sta);
- }
-
- buf = os_malloc(4096);
- if (buf) {
- int count = radius_client_get_mib(hapd->radius, buf, 4096);
- if (count < 0)
- count = 0;
- else if (count > 4095)
- count = 4095;
- buf[count] = '\0';
- fprintf(f, "%s", buf);
-
- count = radius_server_get_mib(hapd->radius_srv, buf, 4096);
- if (count < 0)
- count = 0;
- else if (count > 4095)
- count = 4095;
- buf[count] = '\0';
- fprintf(f, "%s", buf);
- os_free(buf);
- }
- fclose(f);
-}
-#endif /* HOSTAPD_DUMP_STATE */
-
-
-static void handle_dump_state(int sig, void *eloop_ctx, void *signal_ctx)
-{
-#ifdef HOSTAPD_DUMP_STATE
- struct hapd_interfaces *hapds = (struct hapd_interfaces *) eloop_ctx;
- size_t i, j;
-
- for (i = 0; i < hapds->count; i++) {
- struct hostapd_iface *hapd_iface = hapds->iface[i];
- for (j = 0; j < hapd_iface->num_bss; j++)
- hostapd_dump_state(hapd_iface->bss[j]);
- }
-#endif /* HOSTAPD_DUMP_STATE */
-}
-#endif /* CONFIG_NATIVE_WINDOWS */
-
-static void hostapd_broadcast_key_clear_iface(struct hostapd_data *hapd,
- char *ifname)
-{
- int i;
-
- for (i = 0; i < NUM_WEP_KEYS; i++) {
- if (hostapd_set_encryption(ifname, hapd, "none", NULL, i, NULL,
- 0, i == 0 ? 1 : 0)) {
- wpa_printf(MSG_DEBUG, "Failed to clear default "
- "encryption keys (ifname=%s keyidx=%d)",
- ifname, i);
- }
- }
-#ifdef CONFIG_IEEE80211W
- if (hapd->conf->ieee80211w) {
- for (i = NUM_WEP_KEYS; i < NUM_WEP_KEYS + 2; i++) {
- if (hostapd_set_encryption(ifname, hapd, "none", NULL,
- i, NULL, 0,
- i == 0 ? 1 : 0)) {
- wpa_printf(MSG_DEBUG, "Failed to clear "
- "default mgmt encryption keys "
- "(ifname=%s keyidx=%d)", ifname, i);
- }
- }
- }
-#endif /* CONFIG_IEEE80211W */
-}
-
-
-static int hostapd_broadcast_wep_clear(struct hostapd_data *hapd)
-{
- hostapd_broadcast_key_clear_iface(hapd, hapd->conf->iface);
- return 0;
-}
-
-
-static int hostapd_broadcast_wep_set(struct hostapd_data *hapd)
-{
- int errors = 0, idx;
- struct hostapd_ssid *ssid = &hapd->conf->ssid;
-
- idx = ssid->wep.idx;
- if (ssid->wep.default_len &&
- hostapd_set_encryption(hapd->conf->iface,
- hapd, "WEP", NULL, idx,
- ssid->wep.key[idx],
- ssid->wep.len[idx],
- idx == ssid->wep.idx)) {
- wpa_printf(MSG_WARNING, "Could not set WEP encryption.");
- errors++;
- }
-
- if (ssid->dyn_vlan_keys) {
- size_t i;
- for (i = 0; i <= ssid->max_dyn_vlan_keys; i++) {
- const char *ifname;
- struct hostapd_wep_keys *key = ssid->dyn_vlan_keys[i];
- if (key == NULL)
- continue;
- ifname = hostapd_get_vlan_id_ifname(hapd->conf->vlan,
- i);
- if (ifname == NULL)
- continue;
-
- idx = key->idx;
- if (hostapd_set_encryption(ifname, hapd, "WEP", NULL,
- idx, key->key[idx],
- key->len[idx],
- idx == key->idx)) {
- wpa_printf(MSG_WARNING, "Could not set "
- "dynamic VLAN WEP encryption.");
- errors++;
- }
- }
- }
-
- return errors;
-}
-
-/**
- * hostapd_cleanup - Per-BSS cleanup (deinitialization)
- * @hapd: Pointer to BSS data
- *
- * This function is used to free all per-BSS data structures and resources.
- * This gets called in a loop for each BSS between calls to
- * hostapd_cleanup_iface_pre() and hostapd_cleanup_iface() when an interface
- * is deinitialized. Most of the modules that are initialized in
- * hostapd_setup_bss() are deinitialized here.
- */
-static void hostapd_cleanup(struct hostapd_data *hapd)
-{
- hostapd_ctrl_iface_deinit(hapd);
-
- os_free(hapd->default_wep_key);
- hapd->default_wep_key = NULL;
- iapp_deinit(hapd->iapp);
- hapd->iapp = NULL;
- accounting_deinit(hapd);
- rsn_preauth_iface_deinit(hapd);
- if (hapd->wpa_auth) {
- wpa_deinit(hapd->wpa_auth);
- hapd->wpa_auth = NULL;
-
- if (hostapd_set_privacy(hapd, 0)) {
- wpa_printf(MSG_DEBUG, "Could not disable "
- "PrivacyInvoked for interface %s",
- hapd->conf->iface);
- }
-
- if (hostapd_set_generic_elem(hapd, (u8 *) "", 0)) {
- wpa_printf(MSG_DEBUG, "Could not remove generic "
- "information element from interface %s",
- hapd->conf->iface);
- }
- }
- ieee802_1x_deinit(hapd);
- vlan_deinit(hapd);
- hostapd_acl_deinit(hapd);
- radius_client_deinit(hapd->radius);
- hapd->radius = NULL;
- radius_server_deinit(hapd->radius_srv);
- hapd->radius_srv = NULL;
-
-#ifdef CONFIG_IEEE80211R
- l2_packet_deinit(hapd->l2);
-#endif /* CONFIG_IEEE80211R */
-
- hostapd_deinit_wps(hapd);
-
- hostapd_wireless_event_deinit(hapd);
-
-#ifdef EAP_TLS_FUNCS
- if (hapd->ssl_ctx) {
- tls_deinit(hapd->ssl_ctx);
- hapd->ssl_ctx = NULL;
- }
-#endif /* EAP_TLS_FUNCS */
-
-#ifdef EAP_SERVER
- if (hapd->eap_sim_db_priv) {
- eap_sim_db_deinit(hapd->eap_sim_db_priv);
- hapd->eap_sim_db_priv = NULL;
- }
-#endif /* EAP_SERVER */
-
- if (hapd->interface_added &&
- hostapd_bss_remove(hapd, hapd->conf->iface)) {
- wpa_printf(MSG_WARNING, "Failed to remove BSS interface %s",
- hapd->conf->iface);
- }
-}
-
-
-/**
- * hostapd_cleanup_iface_pre - Preliminary per-interface cleanup
- * @iface: Pointer to interface data
- *
- * This function is called before per-BSS data structures are deinitialized
- * with hostapd_cleanup().
- */
-static void hostapd_cleanup_iface_pre(struct hostapd_iface *iface)
-{
-}
-
-
-/**
- * hostapd_cleanup_iface - Complete per-interface cleanup
- * @iface: Pointer to interface data
- *
- * This function is called after per-BSS data structures are deinitialized
- * with hostapd_cleanup().
- */
-static void hostapd_cleanup_iface(struct hostapd_iface *iface)
-{
- hostapd_free_hw_features(iface->hw_features, iface->num_hw_features);
- iface->hw_features = NULL;
- os_free(iface->current_rates);
- iface->current_rates = NULL;
- ap_list_deinit(iface);
- hostapd_config_free(iface->conf);
- iface->conf = NULL;
-
- os_free(iface->config_fname);
- os_free(iface->bss);
- os_free(iface);
-}
-
-
-static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd)
-{
- int i;
-
- hostapd_broadcast_wep_set(hapd);
-
- if (hapd->conf->ssid.wep.default_len)
- return 0;
-
- for (i = 0; i < 4; i++) {
- if (hapd->conf->ssid.wep.key[i] &&
- hostapd_set_encryption(iface, hapd, "WEP", NULL,
- i, hapd->conf->ssid.wep.key[i],
- hapd->conf->ssid.wep.len[i],
- i == hapd->conf->ssid.wep.idx)) {
- wpa_printf(MSG_WARNING, "Could not set WEP "
- "encryption.");
- return -1;
- }
- if (hapd->conf->ssid.wep.key[i] &&
- i == hapd->conf->ssid.wep.idx)
- hostapd_set_privacy(hapd, 1);
- }
-
- return 0;
-}
-
-
-static int hostapd_flush_old_stations(struct hostapd_data *hapd)
-{
- int ret = 0;
-
- if (hostapd_drv_none(hapd))
- return 0;
-
- wpa_printf(MSG_DEBUG, "Flushing old station entries");
- if (hostapd_flush(hapd)) {
- wpa_printf(MSG_WARNING, "Could not connect to kernel driver.");
- ret = -1;
- }
- wpa_printf(MSG_DEBUG, "Deauthenticate all stations");
- hostapd_deauth_all_stas(hapd);
-
- return ret;
-}
-
-
-static void hostapd_wpa_auth_logger(void *ctx, const u8 *addr,
- logger_level level, const char *txt)
-{
- struct hostapd_data *hapd = ctx;
- int hlevel;
-
- switch (level) {
- case LOGGER_WARNING:
- hlevel = HOSTAPD_LEVEL_WARNING;
- break;
- case LOGGER_INFO:
- hlevel = HOSTAPD_LEVEL_INFO;
- break;
- case LOGGER_DEBUG:
- default:
- hlevel = HOSTAPD_LEVEL_DEBUG;
- break;
- }
-
- hostapd_logger(hapd, addr, HOSTAPD_MODULE_WPA, hlevel, "%s", txt);
-}
-
-
-static void hostapd_wpa_auth_disconnect(void *ctx, const u8 *addr,
- u16 reason)
-{
- struct hostapd_data *hapd = ctx;
- struct sta_info *sta;
-
- wpa_printf(MSG_DEBUG, "%s: WPA authenticator requests disconnect: "
- "STA " MACSTR " reason %d",
- __func__, MAC2STR(addr), reason);
-
- sta = ap_get_sta(hapd, addr);
- hostapd_sta_deauth(hapd, addr, reason);
- if (sta == NULL)
- return;
- sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_AUTHORIZED);
- eloop_cancel_timeout(ap_handle_timer, hapd, sta);
- eloop_register_timeout(0, 0, ap_handle_timer, hapd, sta);
- sta->timeout_next = STA_REMOVE;
-}
-
-
-static void hostapd_wpa_auth_mic_failure_report(void *ctx, const u8 *addr)
-{
- struct hostapd_data *hapd = ctx;
- ieee80211_michael_mic_failure(hapd, addr, 0);
-}
-
-
-static void hostapd_wpa_auth_set_eapol(void *ctx, const u8 *addr,
- wpa_eapol_variable var, int value)
-{
- struct hostapd_data *hapd = ctx;
- struct sta_info *sta = ap_get_sta(hapd, addr);
- if (sta == NULL)
- return;
- switch (var) {
- case WPA_EAPOL_portEnabled:
- ieee802_1x_notify_port_enabled(sta->eapol_sm, value);
- break;
- case WPA_EAPOL_portValid:
- ieee802_1x_notify_port_valid(sta->eapol_sm, value);
- break;
- case WPA_EAPOL_authorized:
- ieee802_1x_set_sta_authorized(hapd, sta, value);
- break;
- case WPA_EAPOL_portControl_Auto:
- if (sta->eapol_sm)
- sta->eapol_sm->portControl = Auto;
- break;
- case WPA_EAPOL_keyRun:
- if (sta->eapol_sm)
- sta->eapol_sm->keyRun = value ? TRUE : FALSE;
- break;
- case WPA_EAPOL_keyAvailable:
- if (sta->eapol_sm)
- sta->eapol_sm->eap_if->eapKeyAvailable =
- value ? TRUE : FALSE;
- break;
- case WPA_EAPOL_keyDone:
- if (sta->eapol_sm)
- sta->eapol_sm->keyDone = value ? TRUE : FALSE;
- break;
- case WPA_EAPOL_inc_EapolFramesTx:
- if (sta->eapol_sm)
- sta->eapol_sm->dot1xAuthEapolFramesTx++;
- break;
- }
-}
-
-
-static int hostapd_wpa_auth_get_eapol(void *ctx, const u8 *addr,
- wpa_eapol_variable var)
-{
- struct hostapd_data *hapd = ctx;
- struct sta_info *sta = ap_get_sta(hapd, addr);
- if (sta == NULL || sta->eapol_sm == NULL)
- return -1;
- switch (var) {
- case WPA_EAPOL_keyRun:
- return sta->eapol_sm->keyRun;
- case WPA_EAPOL_keyAvailable:
- return sta->eapol_sm->eap_if->eapKeyAvailable;
- default:
- return -1;
- }
-}
-
-
-static const u8 * hostapd_wpa_auth_get_psk(void *ctx, const u8 *addr,
- const u8 *prev_psk)
-{
- struct hostapd_data *hapd = ctx;
- return hostapd_get_psk(hapd->conf, addr, prev_psk);
-}
-
-
-static int hostapd_wpa_auth_get_msk(void *ctx, const u8 *addr, u8 *msk,
- size_t *len)
-{
- struct hostapd_data *hapd = ctx;
- const u8 *key;
- size_t keylen;
- struct sta_info *sta;
-
- sta = ap_get_sta(hapd, addr);
- if (sta == NULL)
- return -1;
-
- key = ieee802_1x_get_key(sta->eapol_sm, &keylen);
- if (key == NULL)
- return -1;
-
- if (keylen > *len)
- keylen = *len;
- os_memcpy(msk, key, keylen);
- *len = keylen;
-
- return 0;
-}
-
-
-static int hostapd_wpa_auth_set_key(void *ctx, int vlan_id, const char *alg,
- const u8 *addr, int idx, u8 *key,
- size_t key_len)
-{
- struct hostapd_data *hapd = ctx;
- const char *ifname = hapd->conf->iface;
-
- if (vlan_id > 0) {
- ifname = hostapd_get_vlan_id_ifname(hapd->conf->vlan, vlan_id);
- if (ifname == NULL)
- return -1;
- }
-
- return hostapd_set_encryption(ifname, hapd, alg, addr, idx,
- key, key_len, 1);
-}
-
-
-static int hostapd_wpa_auth_get_seqnum(void *ctx, const u8 *addr, int idx,
- u8 *seq)
-{
- struct hostapd_data *hapd = ctx;
- return hostapd_get_seqnum(hapd->conf->iface, hapd, addr, idx, seq);
-}
-
-
-static int hostapd_wpa_auth_get_seqnum_igtk(void *ctx, const u8 *addr, int idx,
- u8 *seq)
-{
- struct hostapd_data *hapd = ctx;
- return hostapd_get_seqnum_igtk(hapd->conf->iface, hapd, addr, idx,
- seq);
-}
-
-
-static int hostapd_wpa_auth_send_eapol(void *ctx, const u8 *addr,
- const u8 *data, size_t data_len,
- int encrypt)
-{
- struct hostapd_data *hapd = ctx;
- return hostapd_send_eapol(hapd, addr, data, data_len, encrypt);
-}
-
-
-static int hostapd_wpa_auth_for_each_sta(
- void *ctx, int (*cb)(struct wpa_state_machine *sm, void *ctx),
- void *cb_ctx)
-{
- struct hostapd_data *hapd = ctx;
- struct sta_info *sta;
-
- for (sta = hapd->sta_list; sta; sta = sta->next) {
- if (sta->wpa_sm && cb(sta->wpa_sm, cb_ctx))
- return 1;
- }
- return 0;
-}
-
-
-static int hostapd_wpa_auth_for_each_auth(
- void *ctx, int (*cb)(struct wpa_authenticator *sm, void *ctx),
- void *cb_ctx)
-{
- struct hostapd_data *ohapd;
- size_t i, j;
- struct hapd_interfaces *interfaces = eloop_get_user_data();
-
- for (i = 0; i < interfaces->count; i++) {
- for (j = 0; j < interfaces->iface[i]->num_bss; j++) {
- ohapd = interfaces->iface[i]->bss[j];
- if (cb(ohapd->wpa_auth, cb_ctx))
- return 1;
- }
- }
-
- return 0;
-}
-
-
-static int hostapd_wpa_auth_send_ether(void *ctx, const u8 *dst, u16 proto,
- const u8 *data, size_t data_len)
-{
- struct hostapd_data *hapd = ctx;
-
- if (hapd->driver && hapd->driver->send_ether)
- return hapd->driver->send_ether(hapd->drv_priv, dst,
- hapd->own_addr, proto,
- data, data_len);
- if (hapd->l2 == NULL)
- return -1;
- return l2_packet_send(hapd->l2, dst, proto, data, data_len);
-}
-
-
-#ifdef CONFIG_IEEE80211R
-
-static int hostapd_wpa_auth_send_ft_action(void *ctx, const u8 *dst,
- const u8 *data, size_t data_len)
-{
- struct hostapd_data *hapd = ctx;
- int res;
- struct ieee80211_mgmt *m;
- size_t mlen;
- struct sta_info *sta;
-
- sta = ap_get_sta(hapd, dst);
- if (sta == NULL || sta->wpa_sm == NULL)
- return -1;
-
- m = os_zalloc(sizeof(*m) + data_len);
- if (m == NULL)
- return -1;
- mlen = ((u8 *) &m->u - (u8 *) m) + data_len;
- m->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
- WLAN_FC_STYPE_ACTION);
- os_memcpy(m->da, dst, ETH_ALEN);
- os_memcpy(m->sa, hapd->own_addr, ETH_ALEN);
- os_memcpy(m->bssid, hapd->own_addr, ETH_ALEN);
- os_memcpy(&m->u, data, data_len);
-
- res = hostapd_send_mgmt_frame(hapd, (u8 *) m, mlen, 0);
- os_free(m);
- return res;
-}
-
-
-static struct wpa_state_machine *
-hostapd_wpa_auth_add_sta(void *ctx, const u8 *sta_addr)
-{
- struct hostapd_data *hapd = ctx;
- struct sta_info *sta;
-
- sta = ap_sta_add(hapd, sta_addr);
- if (sta == NULL)
- return NULL;
- if (sta->wpa_sm)
- return sta->wpa_sm;
-
- sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, sta->addr);
- if (sta->wpa_sm == NULL) {
- ap_free_sta(hapd, sta);
- return NULL;
- }
- sta->auth_alg = WLAN_AUTH_FT;
-
- return sta->wpa_sm;
-}
-
-
-static void hostapd_rrb_receive(void *ctx, const u8 *src_addr, const u8 *buf,
- size_t len)
-{
- struct hostapd_data *hapd = ctx;
- wpa_ft_rrb_rx(hapd->wpa_auth, src_addr, buf, len);
-}
-
-#endif /* CONFIG_IEEE80211R */
-
-
-/**
- * hostapd_validate_bssid_configuration - Validate BSSID configuration
- * @iface: Pointer to interface data
- * Returns: 0 on success, -1 on failure
- *
- * This function is used to validate that the configured BSSIDs are valid.
- */
-static int hostapd_validate_bssid_configuration(struct hostapd_iface *iface)
-{
- u8 mask[ETH_ALEN] = { 0 };
- struct hostapd_data *hapd = iface->bss[0];
- unsigned int i = iface->conf->num_bss, bits = 0, j;
- int res;
-
- if (hostapd_drv_none(hapd))
- return 0;
-
- /* Generate BSSID mask that is large enough to cover the BSSIDs. */
-
- /* Determine the bits necessary to cover the number of BSSIDs. */
- for (i--; i; i >>= 1)
- bits++;
-
- /* Determine the bits necessary to any configured BSSIDs,
- if they are higher than the number of BSSIDs. */
- for (j = 0; j < iface->conf->num_bss; j++) {
- if (hostapd_mac_comp_empty(iface->conf->bss[j].bssid) == 0)
- continue;
-
- for (i = 0; i < ETH_ALEN; i++) {
- mask[i] |=
- iface->conf->bss[j].bssid[i] ^
- hapd->own_addr[i];
- }
- }
-
- for (i = 0; i < ETH_ALEN && mask[i] == 0; i++)
- ;
- j = 0;
- if (i < ETH_ALEN) {
- j = (5 - i) * 8;
-
- while (mask[i] != 0) {
- mask[i] >>= 1;
- j++;
- }
- }
-
- if (bits < j)
- bits = j;
-
- if (bits > 40)
- return -1;
-
- os_memset(mask, 0xff, ETH_ALEN);
- j = bits / 8;
- for (i = 5; i > 5 - j; i--)
- mask[i] = 0;
- j = bits % 8;
- while (j--)
- mask[i] <<= 1;
-
- wpa_printf(MSG_DEBUG, "BSS count %lu, BSSID mask " MACSTR " (%d bits)",
- (unsigned long) iface->conf->num_bss, MAC2STR(mask), bits);
-
- res = hostapd_valid_bss_mask(hapd, hapd->own_addr, mask);
- if (res == 0)
- return 0;
-
- if (res < 0) {
- wpa_printf(MSG_ERROR, "Driver did not accept BSSID mask "
- MACSTR " for start address " MACSTR ".",
- MAC2STR(mask), MAC2STR(hapd->own_addr));
- return -1;
- }
-
- for (i = 0; i < ETH_ALEN; i++) {
- if ((hapd->own_addr[i] & mask[i]) != hapd->own_addr[i]) {
- wpa_printf(MSG_ERROR, "Invalid BSSID mask " MACSTR
- " for start address " MACSTR ".",
- MAC2STR(mask), MAC2STR(hapd->own_addr));
- wpa_printf(MSG_ERROR, "Start address must be the "
- "first address in the block (i.e., addr "
- "AND mask == addr).");
- return -1;
- }
- }
-
- return 0;
-}
-
-
-static int mac_in_conf(struct hostapd_config *conf, const void *a)
-{
- size_t i;
-
- for (i = 0; i < conf->num_bss; i++) {
- if (hostapd_mac_comp(conf->bss[i].bssid, a) == 0) {
- return 1;
- }
- }
-
- return 0;
-}
-
-
-static int hostapd_setup_wpa(struct hostapd_data *hapd)
-{
- struct wpa_auth_config _conf;
- struct wpa_auth_callbacks cb;
- const u8 *wpa_ie;
- size_t wpa_ie_len;
-
- hostapd_wpa_auth_conf(hapd->conf, &_conf);
- os_memset(&cb, 0, sizeof(cb));
- cb.ctx = hapd;
- cb.logger = hostapd_wpa_auth_logger;
- cb.disconnect = hostapd_wpa_auth_disconnect;
- cb.mic_failure_report = hostapd_wpa_auth_mic_failure_report;
- cb.set_eapol = hostapd_wpa_auth_set_eapol;
- cb.get_eapol = hostapd_wpa_auth_get_eapol;
- cb.get_psk = hostapd_wpa_auth_get_psk;
- cb.get_msk = hostapd_wpa_auth_get_msk;
- cb.set_key = hostapd_wpa_auth_set_key;
- cb.get_seqnum = hostapd_wpa_auth_get_seqnum;
- cb.get_seqnum_igtk = hostapd_wpa_auth_get_seqnum_igtk;
- cb.send_eapol = hostapd_wpa_auth_send_eapol;
- cb.for_each_sta = hostapd_wpa_auth_for_each_sta;
- cb.for_each_auth = hostapd_wpa_auth_for_each_auth;
- cb.send_ether = hostapd_wpa_auth_send_ether;
-#ifdef CONFIG_IEEE80211R
- cb.send_ft_action = hostapd_wpa_auth_send_ft_action;
- cb.add_sta = hostapd_wpa_auth_add_sta;
-#endif /* CONFIG_IEEE80211R */
- hapd->wpa_auth = wpa_init(hapd->own_addr, &_conf, &cb);
- if (hapd->wpa_auth == NULL) {
- wpa_printf(MSG_ERROR, "WPA initialization failed.");
- return -1;
- }
-
- if (hostapd_set_privacy(hapd, 1)) {
- wpa_printf(MSG_ERROR, "Could not set PrivacyInvoked "
- "for interface %s", hapd->conf->iface);
- return -1;
- }
-
- wpa_ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &wpa_ie_len);
- if (hostapd_set_generic_elem(hapd, wpa_ie, wpa_ie_len)) {
- wpa_printf(MSG_ERROR, "Failed to configure WPA IE for "
- "the kernel driver.");
- return -1;
- }
-
- if (rsn_preauth_iface_init(hapd)) {
- wpa_printf(MSG_ERROR, "Initialization of RSN "
- "pre-authentication failed.");
- return -1;
- }
-
- return 0;
-
-}
-
-
-static int hostapd_setup_radius_srv(struct hostapd_data *hapd,
- struct hostapd_bss_config *conf)
-{
- struct radius_server_conf srv;
- os_memset(&srv, 0, sizeof(srv));
- srv.client_file = conf->radius_server_clients;
- srv.auth_port = conf->radius_server_auth_port;
- srv.conf_ctx = conf;
- srv.eap_sim_db_priv = hapd->eap_sim_db_priv;
- srv.ssl_ctx = hapd->ssl_ctx;
- srv.pac_opaque_encr_key = conf->pac_opaque_encr_key;
- srv.eap_fast_a_id = conf->eap_fast_a_id;
- srv.eap_fast_a_id_len = conf->eap_fast_a_id_len;
- srv.eap_fast_a_id_info = conf->eap_fast_a_id_info;
- srv.eap_fast_prov = conf->eap_fast_prov;
- srv.pac_key_lifetime = conf->pac_key_lifetime;
- srv.pac_key_refresh_time = conf->pac_key_refresh_time;
- srv.eap_sim_aka_result_ind = conf->eap_sim_aka_result_ind;
- srv.tnc = conf->tnc;
- srv.wps = hapd->wps;
- srv.ipv6 = conf->radius_server_ipv6;
- srv.get_eap_user = hostapd_radius_get_eap_user;
- srv.eap_req_id_text = conf->eap_req_id_text;
- srv.eap_req_id_text_len = conf->eap_req_id_text_len;
-
- hapd->radius_srv = radius_server_init(&srv);
- if (hapd->radius_srv == NULL) {
- wpa_printf(MSG_ERROR, "RADIUS server initialization failed.");
- return -1;
- }
-
- return 0;
-}
-
-
-/**
- * hostapd_setup_bss - Per-BSS setup (initialization)
- * @hapd: Pointer to BSS data
- * @first: Whether this BSS is the first BSS of an interface
- *
- * This function is used to initialize all per-BSS data structures and
- * resources. This gets called in a loop for each BSS when an interface is
- * initialized. Most of the modules that are initialized here will be
- * deinitialized in hostapd_cleanup().
- */
-static int hostapd_setup_bss(struct hostapd_data *hapd, int first)
-{
- struct hostapd_bss_config *conf = hapd->conf;
- u8 ssid[HOSTAPD_MAX_SSID_LEN + 1];
- int ssid_len, set_ssid;
-
- if (!first) {
- if (hostapd_mac_comp_empty(hapd->conf->bssid) == 0) {
- /* Allocate the next available BSSID. */
- do {
- inc_byte_array(hapd->own_addr, ETH_ALEN);
- } while (mac_in_conf(hapd->iconf, hapd->own_addr));
- } else {
- /* Allocate the configured BSSID. */
- os_memcpy(hapd->own_addr, hapd->conf->bssid, ETH_ALEN);
-
- if (hostapd_mac_comp(hapd->own_addr,
- hapd->iface->bss[0]->own_addr) ==
- 0) {
- wpa_printf(MSG_ERROR, "BSS '%s' may not have "
- "BSSID set to the MAC address of "
- "the radio", hapd->conf->iface);
- return -1;
- }
- }
-
- hapd->interface_added = 1;
- if (hostapd_bss_add(hapd->iface->bss[0], hapd->conf->iface,
- hapd->own_addr)) {
- wpa_printf(MSG_ERROR, "Failed to add BSS (BSSID="
- MACSTR ")", MAC2STR(hapd->own_addr));
- return -1;
- }
- }
-
- hostapd_flush_old_stations(hapd);
- hostapd_set_privacy(hapd, 0);
-
- hostapd_broadcast_wep_clear(hapd);
- if (hostapd_setup_encryption(hapd->conf->iface, hapd))
- return -1;
-
- /*
- * Fetch the SSID from the system and use it or,
- * if one was specified in the config file, verify they
- * match.
- */
- ssid_len = hostapd_get_ssid(hapd, ssid, sizeof(ssid));
- if (ssid_len < 0) {
- wpa_printf(MSG_ERROR, "Could not read SSID from system");
- return -1;
- }
- if (conf->ssid.ssid_set) {
- /*
- * If SSID is specified in the config file and it differs
- * from what is being used then force installation of the
- * new SSID.
- */
- set_ssid = (conf->ssid.ssid_len != (size_t) ssid_len ||
- os_memcmp(conf->ssid.ssid, ssid, ssid_len) != 0);
- } else {
- /*
- * No SSID in the config file; just use the one we got
- * from the system.
- */
- set_ssid = 0;
- conf->ssid.ssid_len = ssid_len;
- os_memcpy(conf->ssid.ssid, ssid, conf->ssid.ssid_len);
- conf->ssid.ssid[conf->ssid.ssid_len] = '\0';
- }
-
- if (!hostapd_drv_none(hapd)) {
- wpa_printf(MSG_ERROR, "Using interface %s with hwaddr " MACSTR
- " and ssid '%s'",
- hapd->conf->iface, MAC2STR(hapd->own_addr),
- hapd->conf->ssid.ssid);
- }
-
- if (hostapd_setup_wpa_psk(conf)) {
- wpa_printf(MSG_ERROR, "WPA-PSK setup failed.");
- return -1;
- }
-
- /* Set flag for whether SSID is broadcast in beacons */
- if (hostapd_set_broadcast_ssid(hapd,
- !!hapd->conf->ignore_broadcast_ssid)) {
- wpa_printf(MSG_ERROR, "Could not set broadcast SSID flag for "
- "kernel driver");
- return -1;
- }
-
- if (hostapd_set_dtim_period(hapd, hapd->conf->dtim_period)) {
- wpa_printf(MSG_ERROR, "Could not set DTIM period for kernel "
- "driver");
- return -1;
- }
-
- /* Set SSID for the kernel driver (to be used in beacon and probe
- * response frames) */
- if (set_ssid && hostapd_set_ssid(hapd, (u8 *) conf->ssid.ssid,
- conf->ssid.ssid_len)) {
- wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
- return -1;
- }
-
- if (wpa_debug_level == MSG_MSGDUMP)
- conf->radius->msg_dumps = 1;
- hapd->radius = radius_client_init(hapd, conf->radius);
- if (hapd->radius == NULL) {
- wpa_printf(MSG_ERROR, "RADIUS client initialization failed.");
- return -1;
- }
-
- if (hostapd_acl_init(hapd)) {
- wpa_printf(MSG_ERROR, "ACL initialization failed.");
- return -1;
- }
- if (hostapd_init_wps(hapd, conf))
- return -1;
-
- if (ieee802_1x_init(hapd)) {
- wpa_printf(MSG_ERROR, "IEEE 802.1X initialization failed.");
- return -1;
- }
-
- if (hapd->conf->wpa && hostapd_setup_wpa(hapd))
- return -1;
-
- if (accounting_init(hapd)) {
- wpa_printf(MSG_ERROR, "Accounting initialization failed.");
- return -1;
- }
-
- if (hapd->conf->ieee802_11f &&
- (hapd->iapp = iapp_init(hapd, hapd->conf->iapp_iface)) == NULL) {
- wpa_printf(MSG_ERROR, "IEEE 802.11F (IAPP) initialization "
- "failed.");
- return -1;
- }
-
- if (hostapd_ctrl_iface_init(hapd)) {
- wpa_printf(MSG_ERROR, "Failed to setup control interface");
- return -1;
- }
-
- if (!hostapd_drv_none(hapd) && vlan_init(hapd)) {
- wpa_printf(MSG_ERROR, "VLAN initialization failed.");
- return -1;
- }
-
-#ifdef CONFIG_IEEE80211R
- if (!hostapd_drv_none(hapd)) {
- hapd->l2 = l2_packet_init(hapd->conf->iface, NULL, ETH_P_RRB,
- hostapd_rrb_receive, hapd, 0);
- if (hapd->l2 == NULL &&
- (hapd->driver == NULL ||
- hapd->driver->send_ether == NULL)) {
- wpa_printf(MSG_ERROR, "Failed to open l2_packet "
- "interface");
- return -1;
- }
- }
-#endif /* CONFIG_IEEE80211R */
-
- ieee802_11_set_beacon(hapd);
-
- if (conf->radius_server_clients &&
- hostapd_setup_radius_srv(hapd, conf))
- return -1;
-
- return 0;
-}
-
-
-static void hostapd_tx_queue_params(struct hostapd_iface *iface)
-{
- struct hostapd_data *hapd = iface->bss[0];
- int i;
- struct hostapd_tx_queue_params *p;
-
- for (i = 0; i < NUM_TX_QUEUES; i++) {
- p = &iface->conf->tx_queue[i];
-
- if (!p->configured)
- continue;
-
- if (hostapd_set_tx_queue_params(hapd, i, p->aifs, p->cwmin,
- p->cwmax, p->burst)) {
- wpa_printf(MSG_DEBUG, "Failed to set TX queue "
- "parameters for queue %d.", i);
- /* Continue anyway */
- }
- }
-}
-
-
-static int hostapd_radius_get_eap_user(void *ctx, const u8 *identity,
- size_t identity_len, int phase2,
- struct eap_user *user)
-{
- const struct hostapd_eap_user *eap_user;
- int i, count;
-
- eap_user = hostapd_get_eap_user(ctx, identity, identity_len, phase2);
- if (eap_user == NULL)
- return -1;
-
- if (user == NULL)
- return 0;
-
- os_memset(user, 0, sizeof(*user));
- count = EAP_USER_MAX_METHODS;
- if (count > EAP_MAX_METHODS)
- count = EAP_MAX_METHODS;
- for (i = 0; i < count; i++) {
- user->methods[i].vendor = eap_user->methods[i].vendor;
- user->methods[i].method = eap_user->methods[i].method;
- }
-
- if (eap_user->password) {
- user->password = os_malloc(eap_user->password_len);
- if (user->password == NULL)
- return -1;
- os_memcpy(user->password, eap_user->password,
- eap_user->password_len);
- user->password_len = eap_user->password_len;
- user->password_hash = eap_user->password_hash;
- }
- user->force_version = eap_user->force_version;
- user->ttls_auth = eap_user->ttls_auth;
-
- return 0;
-}
-
-
-static int setup_interface(struct hostapd_iface *iface)
-{
- struct hostapd_data *hapd = iface->bss[0];
- struct hostapd_bss_config *conf = hapd->conf;
- size_t i;
- char country[4];
- u8 *b = conf->bssid;
- int freq;
- size_t j;
- u8 *prev_addr;
-
- /*
- * Initialize the driver interface and make sure that all BSSes get
- * configured with a pointer to this driver interface.
- */
- if (b[0] | b[1] | b[2] | b[3] | b[4] | b[5]) {
- hapd->drv_priv = hostapd_driver_init_bssid(hapd, b);
- } else {
- hapd->drv_priv = hostapd_driver_init(hapd);
- }
-
- if (hapd->drv_priv == NULL) {
- wpa_printf(MSG_ERROR, "%s driver initialization failed.",
- hapd->driver ? hapd->driver->name : "Unknown");
- hapd->driver = NULL;
- return -1;
- }
- for (i = 0; i < iface->num_bss; i++) {
- iface->bss[i]->driver = hapd->driver;
- iface->bss[i]->drv_priv = hapd->drv_priv;
- }
-
- if (hostapd_validate_bssid_configuration(iface))
- return -1;
-
-#ifdef CONFIG_IEEE80211N
- SET_2BIT_LE16(&iface->ht_op_mode,
- HT_INFO_OPERATION_MODE_OP_MODE_OFFSET,
- OP_MODE_PURE);
-#endif /* CONFIG_IEEE80211N */
-
- if (hapd->iconf->country[0] && hapd->iconf->country[1]) {
- os_memcpy(country, hapd->iconf->country, 3);
- country[3] = '\0';
- if (hostapd_set_country(hapd, country) < 0) {
- wpa_printf(MSG_ERROR, "Failed to set country code");
- return -1;
- }
- }
-
- if (hapd->iconf->ieee80211d &&
- hostapd_set_ieee80211d(hapd, 1) < 0) {
- wpa_printf(MSG_ERROR, "Failed to set ieee80211d (%d)",
- hapd->iconf->ieee80211d);
- return -1;
- }
-
- if (hapd->iconf->bridge_packets != INTERNAL_BRIDGE_DO_NOT_CONTROL &&
- hostapd_set_internal_bridge(hapd, hapd->iconf->bridge_packets)) {
- wpa_printf(MSG_ERROR, "Failed to set bridge_packets for "
- "kernel driver");
- return -1;
- }
-
- /* TODO: merge with hostapd_driver_init() ? */
- if (hostapd_wireless_event_init(hapd) < 0)
- return -1;
-
- if (hostapd_get_hw_features(iface)) {
- /* Not all drivers support this yet, so continue without hw
- * feature data. */
- } else {
- int ret = hostapd_select_hw_mode(iface);
- if (ret < 0) {
- wpa_printf(MSG_ERROR, "Could not select hw_mode and "
- "channel. (%d)", ret);
- return -1;
- }
- }
-
- if (hapd->iconf->channel) {
- freq = hostapd_hw_get_freq(hapd, hapd->iconf->channel);
- wpa_printf(MSG_DEBUG, "Mode: %s Channel: %d "
- "Frequency: %d MHz",
- hostapd_hw_mode_txt(hapd->iconf->hw_mode),
- hapd->iconf->channel, freq);
-
- if (hostapd_set_freq(hapd, hapd->iconf->hw_mode, freq,
- hapd->iconf->ieee80211n,
- hapd->iconf->secondary_channel)) {
- wpa_printf(MSG_ERROR, "Could not set channel for "
- "kernel driver");
- return -1;
- }
- }
-
- hostapd_set_beacon_int(hapd, hapd->iconf->beacon_int);
-
- if (hapd->iconf->rts_threshold > -1 &&
- hostapd_set_rts(hapd, hapd->iconf->rts_threshold)) {
- wpa_printf(MSG_ERROR, "Could not set RTS threshold for "
- "kernel driver");
- return -1;
- }
-
- if (hapd->iconf->fragm_threshold > -1 &&
- hostapd_set_frag(hapd, hapd->iconf->fragm_threshold)) {
- wpa_printf(MSG_ERROR, "Could not set fragmentation threshold "
- "for kernel driver");
- return -1;
- }
-
- prev_addr = hapd->own_addr;
-
- for (j = 0; j < iface->num_bss; j++) {
- hapd = iface->bss[j];
- if (j)
- os_memcpy(hapd->own_addr, prev_addr, ETH_ALEN);
- if (hostapd_setup_bss(hapd, j == 0))
- return -1;
- if (hostapd_mac_comp_empty(hapd->conf->bssid) == 0)
- prev_addr = hapd->own_addr;
- }
-
- hostapd_tx_queue_params(iface);
-
- ap_list_init(iface);
-
- if (hostapd_driver_commit(hapd) < 0) {
- wpa_printf(MSG_ERROR, "%s: Failed to commit driver "
- "configuration", __func__);
- return -1;
- }
-
- return 0;
-}
-
-
-/**
- * hostapd_setup_interface - Setup of an interface
- * @iface: Pointer to interface data.
- * Returns: 0 on success, -1 on failure
- *
- * Initializes the driver interface, validates the configuration,
- * and sets driver parameters based on the configuration.
- * Flushes old stations, sets the channel, encryption,
- * beacons, and WDS links based on the configuration.
- */
-static int hostapd_setup_interface(struct hostapd_iface *iface)
-{
- int ret;
-
- ret = setup_interface(iface);
- if (ret) {
- wpa_printf(MSG_DEBUG, "%s: Unable to setup interface.",
- iface->bss[0]->conf->iface);
- eloop_terminate();
- return -1;
- } else if (!hostapd_drv_none(iface->bss[0])) {
- wpa_printf(MSG_DEBUG, "%s: Setup of interface done.",
- iface->bss[0]->conf->iface);
- }
-
- return 0;
-}
-
-
-static void show_version(void)
-{
- fprintf(stderr,
- "hostapd v" VERSION_STR "\n"
- "User space daemon for IEEE 802.11 AP management,\n"
- "IEEE 802.1X/WPA/WPA2/EAP/RADIUS Authenticator\n"
- "Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi> "
- "and contributors\n");
-}
-
-
-static void usage(void)
-{
- show_version();
- fprintf(stderr,
- "\n"
- "usage: hostapd [-hdBKtv] [-P <PID file>] "
- "<configuration file(s)>\n"
- "\n"
- "options:\n"
- " -h show this usage\n"
- " -d show more debug messages (-dd for even more)\n"
- " -B run daemon in the background\n"
- " -P PID file\n"
- " -K include key data in debug messages\n"
- " -t include timestamps in some debug messages\n"
- " -v show hostapd version\n");
-
- exit(1);
-}
-
-
-/**
- * hostapd_alloc_bss_data - Allocate and initialize per-BSS data
- * @hapd_iface: Pointer to interface data
- * @conf: Pointer to per-interface configuration
- * @bss: Pointer to per-BSS configuration for this BSS
- * Returns: Pointer to allocated BSS data
- *
- * This function is used to allocate per-BSS data structure. This data will be
- * freed after hostapd_cleanup() is called for it during interface
- * deinitialization.
- */
-static struct hostapd_data *
-hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
- struct hostapd_config *conf,
- struct hostapd_bss_config *bss)
-{
- struct hostapd_data *hapd;
-
- hapd = os_zalloc(sizeof(*hapd));
- if (hapd == NULL)
- return NULL;
-
- hapd->iconf = conf;
- hapd->conf = bss;
- hapd->iface = hapd_iface;
-
- if (hapd->conf->individual_wep_key_len > 0) {
- /* use key0 in individual key and key1 in broadcast key */
- hapd->default_wep_key_idx = 1;
- }
-
-#ifdef EAP_TLS_FUNCS
- if (hapd->conf->eap_server &&
- (hapd->conf->ca_cert || hapd->conf->server_cert ||
- hapd->conf->dh_file)) {
- struct tls_connection_params params;
-
- hapd->ssl_ctx = tls_init(NULL);
- if (hapd->ssl_ctx == NULL) {
- wpa_printf(MSG_ERROR, "Failed to initialize TLS");
- goto fail;
- }
-
- os_memset(&params, 0, sizeof(params));
- params.ca_cert = hapd->conf->ca_cert;
- params.client_cert = hapd->conf->server_cert;
- params.private_key = hapd->conf->private_key;
- params.private_key_passwd = hapd->conf->private_key_passwd;
- params.dh_file = hapd->conf->dh_file;
-
- if (tls_global_set_params(hapd->ssl_ctx, &params)) {
- wpa_printf(MSG_ERROR, "Failed to set TLS parameters");
- goto fail;
- }
-
- if (tls_global_set_verify(hapd->ssl_ctx,
- hapd->conf->check_crl)) {
- wpa_printf(MSG_ERROR, "Failed to enable check_crl");
- goto fail;
- }
- }
-#endif /* EAP_TLS_FUNCS */
-
-#ifdef EAP_SERVER
- if (hapd->conf->eap_sim_db) {
- hapd->eap_sim_db_priv =
- eap_sim_db_init(hapd->conf->eap_sim_db,
- hostapd_sim_db_cb, hapd);
- if (hapd->eap_sim_db_priv == NULL) {
- wpa_printf(MSG_ERROR, "Failed to initialize EAP-SIM "
- "database interface");
- goto fail;
- }
- }
-#endif /* EAP_SERVER */
-
- hapd->driver = hapd->iconf->driver;
-
- return hapd;
-
-#if defined(EAP_TLS_FUNCS) || defined(EAP_SERVER)
-fail:
-#endif
- /* TODO: cleanup allocated resources(?) */
- os_free(hapd);
- return NULL;
-}
-
-
-/**
- * hostapd_init - Allocate and initialize per-interface data
- * @config_file: Path to the configuration file
- * Returns: Pointer to the allocated interface data or %NULL on failure
- *
- * This function is used to allocate main data structures for per-interface
- * data. The allocated data buffer will be freed by calling
- * hostapd_cleanup_iface().
- */
-static struct hostapd_iface * hostapd_init(const char *config_file)
-{
- struct hostapd_iface *hapd_iface = NULL;
- struct hostapd_config *conf = NULL;
- struct hostapd_data *hapd;
- size_t i;
-
- hapd_iface = os_zalloc(sizeof(*hapd_iface));
- if (hapd_iface == NULL)
- goto fail;
-
- hapd_iface->config_fname = os_strdup(config_file);
- if (hapd_iface->config_fname == NULL)
- goto fail;
-
- conf = hostapd_config_read(hapd_iface->config_fname);
- if (conf == NULL)
- goto fail;
- hapd_iface->conf = conf;
-
- hapd_iface->num_bss = conf->num_bss;
- hapd_iface->bss = os_zalloc(conf->num_bss *
- sizeof(struct hostapd_data *));
- if (hapd_iface->bss == NULL)
- goto fail;
-
- for (i = 0; i < conf->num_bss; i++) {
- hapd = hapd_iface->bss[i] =
- hostapd_alloc_bss_data(hapd_iface, conf,
- &conf->bss[i]);
- if (hapd == NULL)
- goto fail;
- }
-
- return hapd_iface;
-
-fail:
- if (conf)
- hostapd_config_free(conf);
- if (hapd_iface) {
- for (i = 0; hapd_iface->bss && i < hapd_iface->num_bss; i++) {
- hapd = hapd_iface->bss[i];
- if (hapd && hapd->ssl_ctx)
- tls_deinit(hapd->ssl_ctx);
- }
-
- os_free(hapd_iface->config_fname);
- os_free(hapd_iface->bss);
- os_free(hapd_iface);
- }
- return NULL;
-}
-
-
-int main(int argc, char *argv[])
-{
- struct hapd_interfaces interfaces;
- int ret = 1, k;
- size_t i, j;
- int c, debug = 0, daemonize = 0, tnc = 0;
- char *pid_file = NULL;
-
- hostapd_logger_register_cb(hostapd_logger_cb);
-
- for (;;) {
- c = getopt(argc, argv, "BdhKP:tv");
- if (c < 0)
- break;
- switch (c) {
- case 'h':
- usage();
- break;
- case 'd':
- debug++;
- if (wpa_debug_level > 0)
- wpa_debug_level--;
- break;
- case 'B':
- daemonize++;
- break;
- case 'K':
- wpa_debug_show_keys++;
- break;
- case 'P':
- os_free(pid_file);
- pid_file = os_rel2abs_path(optarg);
- break;
- case 't':
- wpa_debug_timestamp++;
- break;
- case 'v':
- show_version();
- exit(1);
- break;
-
- default:
- usage();
- break;
- }
- }
-
- if (optind == argc)
- usage();
-
-#ifdef EAP_SERVER
- if (eap_server_register_methods()) {
- wpa_printf(MSG_ERROR, "Failed to register EAP methods");
- return -1;
- }
-#endif /* EAP_SERVER */
-
- interfaces.count = argc - optind;
-
- interfaces.iface = os_malloc(interfaces.count *
- sizeof(struct hostapd_iface *));
- if (interfaces.iface == NULL) {
- wpa_printf(MSG_ERROR, "malloc failed\n");
- return -1;
- }
-
- if (eloop_init(&interfaces)) {
- wpa_printf(MSG_ERROR, "Failed to initialize event loop");
- return -1;
- }
-
-#ifndef CONFIG_NATIVE_WINDOWS
- eloop_register_signal(SIGHUP, handle_reload, NULL);
- eloop_register_signal(SIGUSR1, handle_dump_state, NULL);
-#endif /* CONFIG_NATIVE_WINDOWS */
- eloop_register_signal_terminate(handle_term, NULL);
-
- /* Initialize interfaces */
- for (i = 0; i < interfaces.count; i++) {
- wpa_printf(MSG_ERROR, "Configuration file: %s",
- argv[optind + i]);
- interfaces.iface[i] = hostapd_init(argv[optind + i]);
- if (!interfaces.iface[i])
- goto out;
- for (k = 0; k < debug; k++) {
- if (interfaces.iface[i]->bss[0]->conf->
- logger_stdout_level > 0)
- interfaces.iface[i]->bss[0]->conf->
- logger_stdout_level--;
- }
-
- ret = hostapd_setup_interface(interfaces.iface[i]);
- if (ret)
- goto out;
-
- for (k = 0; k < (int) interfaces.iface[i]->num_bss; k++) {
- if (interfaces.iface[i]->bss[0]->conf->tnc)
- tnc++;
- }
- }
-
-#ifdef EAP_TNC
- if (tnc && tncs_global_init() < 0) {
- wpa_printf(MSG_ERROR, "Failed to initialize TNCS");
- goto out;
- }
-#endif /* EAP_TNC */
-
- if (daemonize && os_daemonize(pid_file)) {
- perror("daemon");
- goto out;
- }
-
-#ifndef CONFIG_NATIVE_WINDOWS
- openlog("hostapd", 0, LOG_DAEMON);
-#endif /* CONFIG_NATIVE_WINDOWS */
-
- eloop_run();
-
- /* Disconnect associated stations from all interfaces and BSSes */
- for (i = 0; i < interfaces.count; i++) {
- for (j = 0; j < interfaces.iface[i]->num_bss; j++) {
- struct hostapd_data *hapd =
- interfaces.iface[i]->bss[j];
- hostapd_free_stas(hapd);
- hostapd_flush_old_stations(hapd);
- }
- }
-
- ret = 0;
-
- out:
- /* Deinitialize all interfaces */
- for (i = 0; i < interfaces.count; i++) {
- if (!interfaces.iface[i])
- continue;
- hostapd_cleanup_iface_pre(interfaces.iface[i]);
- for (j = 0; j < interfaces.iface[i]->num_bss; j++) {
- struct hostapd_data *hapd =
- interfaces.iface[i]->bss[j];
- hostapd_cleanup(hapd);
- if (j == interfaces.iface[i]->num_bss - 1 &&
- hapd->driver)
- hostapd_driver_deinit(hapd);
- }
- for (j = 0; j < interfaces.iface[i]->num_bss; j++)
- os_free(interfaces.iface[i]->bss[j]);
- hostapd_cleanup_iface(interfaces.iface[i]);
- }
- os_free(interfaces.iface);
-
-#ifdef EAP_TNC
- tncs_global_deinit();
-#endif /* EAP_TNC */
-
- eloop_destroy();
-
-#ifndef CONFIG_NATIVE_WINDOWS
- closelog();
-#endif /* CONFIG_NATIVE_WINDOWS */
-
-#ifdef EAP_SERVER
- eap_server_unregister_methods();
-#endif /* EAP_SERVER */
-
- os_daemonize_terminate(pid_file);
- os_free(pid_file);
-
- return ret;
-}
diff --git a/contrib/wpa/hostapd/hostapd.conf b/contrib/wpa/hostapd/hostapd.conf
index 703b646..b44a818 100644
--- a/contrib/wpa/hostapd/hostapd.conf
+++ b/contrib/wpa/hostapd/hostapd.conf
@@ -5,12 +5,20 @@
# management frames); ath0 for madwifi
interface=wlan0
-# In case of madwifi and nl80211 driver interfaces, an additional configuration
-# parameter, bridge, must be used to notify hostapd if the interface is
-# included in a bridge. This parameter is not used with Host AP driver.
+# In case of madwifi, atheros, and nl80211 driver interfaces, an additional
+# configuration parameter, bridge, may be used to notify hostapd if the
+# interface is included in a bridge. This parameter is not used with Host AP
+# driver. If the bridge parameter is not set, the drivers will automatically
+# figure out the bridge interface (assuming sysfs is enabled and mounted to
+# /sys) and this parameter may not be needed.
+#
+# For nl80211, this parameter can be used to request the AP interface to be
+# added to the bridge automatically (brctl may refuse to do this before hostapd
+# has been started to change the interface mode). If needed, the bridge
+# interface is also created.
#bridge=br0
-# Driver interface type (hostap/wired/madwifi/prism54/test/none/nl80211/bsd);
+# Driver interface type (hostap/wired/madwifi/test/none/nl80211/bsd);
# default: hostap). nl80211 is used with all Linux mac80211 drivers.
# Use driver=none if building hostapd as a standalone RADIUS server that does
# not control any wireless/wired driver.
@@ -275,6 +283,10 @@ ignore_broadcast_ssid=0
#
wmm_enabled=1
#
+# WMM-PS Unscheduled Automatic Power Save Delivery [U-APSD]
+# Enable this flag if U-APSD supported outside hostapd (eg., Firmware/driver)
+#uapsd_advertisement_enabled=1
+#
# Low priority / AC_BK = background
wmm_ac_bk_cwmin=4
wmm_ac_bk_cwmax=10
@@ -342,34 +354,16 @@ wmm_ac_vo_acm=0
# default: 300 (i.e., 5 minutes)
#ap_max_inactivity=300
-# Enable/disable internal bridge for packets between associated stations.
-#
-# When IEEE 802.11 is used in managed mode, packets are usually send through
-# the AP even if they are from a wireless station to another wireless station.
-# This functionality requires that the AP has a bridge functionality that sends
-# frames back to the same interface if their destination is another associated
-# station. In addition, broadcast/multicast frames from wireless stations will
-# be sent both to the host system net stack (e.g., to eventually wired network)
-# and back to the wireless interface.
-#
-# The internal bridge is implemented within the wireless kernel module and it
-# bypasses kernel filtering (netfilter/iptables/ebtables). If direct
-# communication between the stations needs to be prevented, the internal
-# bridge can be disabled by setting bridge_packets=0.
-#
-# Note: If this variable is not included in hostapd.conf, hostapd does not
-# change the configuration and iwpriv can be used to set the value with
-# 'iwpriv wlan# param 10 0' command. If the variable is in hostapd.conf,
-# hostapd will override possible iwpriv configuration whenever configuration
-# file is reloaded.
-#
-# default: do not control from hostapd (80211.o defaults to 1=enabled)
-#bridge_packets=1
-
# Maximum allowed Listen Interval (how many Beacon periods STAs are allowed to
# remain asleep). Default: 65535 (no limit apart from field size)
#max_listen_interval=100
+# WDS (4-address frame) mode with per-station virtual interfaces
+# (only supported with driver=nl80211)
+# This mode allows associated stations to use 4-address frames to allow layer 2
+# bridging to be used.
+#wds_sta=1
+
##### IEEE 802.11n related configuration ######################################
# ieee80211n: Whether IEEE 802.11n (HT) is enabled
@@ -392,6 +386,10 @@ wmm_ac_vo_acm=0
# 5 GHz 40,48,56,64 36,44,52,60
# (depending on the location, not all of these channels may be available
# for use)
+# Please note that 40 MHz channels may switch their primary and secondary
+# channels if needed or creation of 40 MHz channel maybe rejected based
+# on overlapping BSSes. These changes are done automatically when hostapd
+# is setting up the 40 MHz channel.
# Spatial Multiplexing (SM) Power Save: [SMPS-STATIC] or [SMPS-DYNAMIC]
# (SMPS disabled if neither is set)
# HT-greenfield: [GF] (disabled if not set)
@@ -522,9 +520,9 @@ eap_server=0
# EAP-FAST authority identity (A-ID)
# A-ID indicates the identity of the authority that issues PACs. The A-ID
# should be unique across all issuing servers. In theory, this is a variable
-# length field, but due to some existing implementations required A-ID to be
+# length field, but due to some existing implementations requiring A-ID to be
# 16 octets in length, it is strongly recommended to use that length for the
-# field to provided interoperability with deployed peer implementation. This
+# field to provid interoperability with deployed peer implementations. This
# field is configured in hex format.
#eap_fast_a_id=101112131415161718191a1b1c1d1e1f
@@ -808,7 +806,7 @@ own_ip_addr=127.0.0.1
# And so on.. One line per R0KH.
# List of R1KHs in the same Mobility Domain
-# format: <MAC address> <R0KH-ID> <128-bit key as hex string>
+# format: <MAC address> <R1KH-ID> <128-bit key as hex string>
# This list is used to map R1KH-ID to a destination MAC address when sending
# PMK-R1 key from the R0KH. This is also the list of authorized R1KHs in the MD
# that can request PMK-R1 keys.
@@ -821,27 +819,11 @@ own_ip_addr=127.0.0.1
# 1 = push PMK-R1 to all configured R1KHs whenever a new PMK-R0 is derived
#pmk_r1_push=1
-##### Passive scanning ########################################################
-# Scan different channels every N seconds. 0 = disable passive scanning.
-#passive_scan_interval=60
-
-# Listen N usecs on each channel when doing passive scanning.
-# This value plus the time needed for changing channels should be less than
-# 32 milliseconds (i.e. 32000 usec) to avoid interruptions to normal
-# operations. Time needed for channel changing varies based on the used wlan
-# hardware.
-# default: disabled (0)
-#passive_scan_listen=10000
-
-# Passive scanning mode:
-# 0 = scan all supported modes (802.11a/b/g/Turbo) (default)
-# 1 = scan only the mode that is currently used for normal operations
-#passive_scan_mode=1
-
-# Maximum number of entries kept in AP table (either for passive scanning or
-# for detecting Overlapping Legacy BSS Condition). The oldest entry will be
+##### Neighbor table ##########################################################
+# Maximum number of entries kept in AP table (either for neigbor table or for
+# detecting Overlapping Legacy BSS Condition). The oldest entry will be
# removed when adding a new entry that would make the list grow over this
-# limit. Note! Wi-Fi certification for IEEE 802.11g requires that OLBC is
+# limit. Note! WFA certification for IEEE 802.11g requires that OLBC is
# enabled, so this field should not be set to 0 when using IEEE 802.11g.
# default: 255
#ap_table_max_size=255
@@ -927,11 +909,17 @@ own_ip_addr=127.0.0.1
# Config Methods
# List of the supported configuration methods
+# Available methods: usba ethernet label display ext_nfc_token int_nfc_token
+# nfc_interface push_button keypad
#config_methods=label display push_button keypad
-# Access point PIN for initial configuration and adding Registrars
+# Static access point PIN for initial configuration and adding Registrars
# If not set, hostapd will not allow external WPS Registrars to control the
-# access point.
+# access point. The AP PIN can also be set at runtime with hostapd_cli
+# wps_ap_pin command. Use of temporary (enabled by user action) and random
+# AP PIN is much more secure than configuring a static AP PIN here. As such,
+# use of the ap_pin parameter is not recommended if the AP device has means for
+# displaying a random PIN.
#ap_pin=12345670
# Skip building of automatic WPS credential
@@ -1002,7 +990,10 @@ own_ip_addr=127.0.0.1
# hostapd will generate BSSID mask based on the BSSIDs that are
# configured. hostapd will verify that dev_addr & MASK == dev_addr. If this is
# not the case, the MAC address of the radio must be changed before starting
-# hostapd (ifconfig wlan0 hw ether <MAC addr>).
+# hostapd (ifconfig wlan0 hw ether <MAC addr>). If a BSSID is configured for
+# every secondary BSS, this limitation is not applied at hostapd and other
+# masks may be used if the driver supports them (e.g., swap the locally
+# administered bit)
#
# BSSIDs are assigned in order to each BSS, unless an explicit BSSID is
# specified using the 'bssid' parameter.
diff --git a/contrib/wpa/hostapd/hostapd.h b/contrib/wpa/hostapd/hostapd.h
deleted file mode 100644
index 26f30d7..0000000
--- a/contrib/wpa/hostapd/hostapd.h
+++ /dev/null
@@ -1,238 +0,0 @@
-/*
- * hostapd / Initialization and configuration
- * Host AP kernel driver
- * Copyright (c) 2002-2008, Jouni Malinen <j@w1.fi>
- * Copyright (c) 2007-2008, Intel Corporation
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
- */
-
-#ifndef HOSTAPD_H
-#define HOSTAPD_H
-
-#include "common.h"
-#include "ap.h"
-
-#ifndef ETH_ALEN
-#define ETH_ALEN 6
-#endif
-#ifndef IFNAMSIZ
-#define IFNAMSIZ 16
-#endif
-#ifndef ETH_P_ALL
-#define ETH_P_ALL 0x0003
-#endif
-#ifndef ETH_P_PAE
-#define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
-#endif /* ETH_P_PAE */
-#ifndef ETH_P_EAPOL
-#define ETH_P_EAPOL ETH_P_PAE
-#endif /* ETH_P_EAPOL */
-
-#ifndef ETH_P_RRB
-#define ETH_P_RRB 0x890D
-#endif /* ETH_P_RRB */
-
-#include "config.h"
-
-#ifdef _MSC_VER
-#pragma pack(push, 1)
-#endif /* _MSC_VER */
-
-#define MAX_VLAN_ID 4094
-
-struct ieee8023_hdr {
- u8 dest[6];
- u8 src[6];
- u16 ethertype;
-} STRUCT_PACKED;
-
-
-struct ieee80211_hdr {
- le16 frame_control;
- le16 duration_id;
- u8 addr1[6];
- u8 addr2[6];
- u8 addr3[6];
- le16 seq_ctrl;
- /* followed by 'u8 addr4[6];' if ToDS and FromDS is set in data frame
- */
-} STRUCT_PACKED;
-
-#ifdef _MSC_VER
-#pragma pack(pop)
-#endif /* _MSC_VER */
-
-#define IEEE80211_DA_FROMDS addr1
-#define IEEE80211_BSSID_FROMDS addr2
-#define IEEE80211_SA_FROMDS addr3
-
-#define IEEE80211_HDRLEN (sizeof(struct ieee80211_hdr))
-
-#define IEEE80211_FC(type, stype) host_to_le16((type << 2) | (stype << 4))
-
-/* MTU to be set for the wlan#ap device; this is mainly needed for IEEE 802.1X
- * frames that might be longer than normal default MTU and they are not
- * fragmented */
-#define HOSTAPD_MTU 2290
-
-extern unsigned char rfc1042_header[6];
-
-struct hostap_sta_driver_data {
- unsigned long rx_packets, tx_packets, rx_bytes, tx_bytes;
- unsigned long current_tx_rate;
- unsigned long inactive_msec;
- unsigned long flags;
- unsigned long num_ps_buf_frames;
- unsigned long tx_retry_failed;
- unsigned long tx_retry_count;
- int last_rssi;
- int last_ack_rssi;
-};
-
-struct wpa_driver_ops;
-struct wpa_ctrl_dst;
-struct radius_server_data;
-struct upnp_wps_device_sm;
-
-#ifdef CONFIG_FULL_DYNAMIC_VLAN
-struct full_dynamic_vlan;
-#endif /* CONFIG_FULL_DYNAMIC_VLAN */
-
-/**
- * struct hostapd_data - hostapd per-BSS data structure
- */
-struct hostapd_data {
- struct hostapd_iface *iface;
- struct hostapd_config *iconf;
- struct hostapd_bss_config *conf;
- int interface_added; /* virtual interface added for this BSS */
-
- u8 own_addr[ETH_ALEN];
-
- int num_sta; /* number of entries in sta_list */
- struct sta_info *sta_list; /* STA info list head */
- struct sta_info *sta_hash[STA_HASH_SIZE];
-
- /* pointers to STA info; based on allocated AID or NULL if AID free
- * AID is in the range 1-2007, so sta_aid[0] corresponders to AID 1
- * and so on
- */
- struct sta_info *sta_aid[MAX_AID_TABLE_SIZE];
-
- const struct wpa_driver_ops *driver;
- void *drv_priv;
-
- u8 *default_wep_key;
- u8 default_wep_key_idx;
-
- struct radius_client_data *radius;
- int radius_client_reconfigured;
- u32 acct_session_id_hi, acct_session_id_lo;
-
- struct iapp_data *iapp;
-
- struct hostapd_cached_radius_acl *acl_cache;
- struct hostapd_acl_query_data *acl_queries;
-
- struct wpa_authenticator *wpa_auth;
- struct eapol_authenticator *eapol_auth;
-
- struct rsn_preauth_interface *preauth_iface;
- time_t michael_mic_failure;
- int michael_mic_failures;
- int tkip_countermeasures;
-
- int ctrl_sock;
- struct wpa_ctrl_dst *ctrl_dst;
-
- void *ssl_ctx;
- void *eap_sim_db_priv;
- struct radius_server_data *radius_srv;
-
- int parameter_set_count;
-
-#ifdef CONFIG_FULL_DYNAMIC_VLAN
- struct full_dynamic_vlan *full_dynamic_vlan;
-#endif /* CONFIG_FULL_DYNAMIC_VLAN */
-
- struct l2_packet_data *l2;
- struct wps_context *wps;
-
-#ifdef CONFIG_WPS
- u8 *wps_beacon_ie;
- size_t wps_beacon_ie_len;
- u8 *wps_probe_resp_ie;
- size_t wps_probe_resp_ie_len;
- unsigned int ap_pin_failures;
- struct upnp_wps_device_sm *wps_upnp;
-#endif /* CONFIG_WPS */
-};
-
-
-/**
- * struct hostapd_iface - hostapd per-interface data structure
- */
-struct hostapd_iface {
- char *config_fname;
- struct hostapd_config *conf;
-
- size_t num_bss;
- struct hostapd_data **bss;
-
- int num_ap; /* number of entries in ap_list */
- struct ap_info *ap_list; /* AP info list head */
- struct ap_info *ap_hash[STA_HASH_SIZE];
- struct ap_info *ap_iter_list;
-
- struct hostapd_hw_modes *hw_features;
- int num_hw_features;
- struct hostapd_hw_modes *current_mode;
- /* Rates that are currently used (i.e., filtered copy of
- * current_mode->channels */
- int num_rates;
- struct hostapd_rate_data *current_rates;
-
- u16 hw_flags;
-
- /* Number of associated Non-ERP stations (i.e., stations using 802.11b
- * in 802.11g BSS) */
- int num_sta_non_erp;
-
- /* Number of associated stations that do not support Short Slot Time */
- int num_sta_no_short_slot_time;
-
- /* Number of associated stations that do not support Short Preamble */
- int num_sta_no_short_preamble;
-
- int olbc; /* Overlapping Legacy BSS Condition */
-
- /* Number of HT associated stations that do not support greenfield */
- int num_sta_ht_no_gf;
-
- /* Number of associated non-HT stations */
- int num_sta_no_ht;
-
- /* Number of HT associated stations 20 MHz */
- int num_sta_ht_20mhz;
-
- /* Overlapping BSS information */
- int olbc_ht;
-
-#ifdef CONFIG_IEEE80211N
- u16 ht_op_mode;
-#endif /* CONFIG_IEEE80211N */
-};
-
-void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
- int reassoc);
-int hostapd_reload_config(struct hostapd_iface *iface);
-
-#endif /* HOSTAPD_H */
diff --git a/contrib/wpa/hostapd/hostapd_cli.1 b/contrib/wpa/hostapd/hostapd_cli.1
index 2fe4907..218ea15 100644
--- a/contrib/wpa/hostapd/hostapd_cli.1
+++ b/contrib/wpa/hostapd/hostapd_cli.1
@@ -3,7 +3,7 @@
hostapd_cli \- hostapd command-line interface
.SH SYNOPSIS
.B hostapd_cli
-[\-p<path>] [\-i<ifname>] [\-hv] [command..]
+[\-p<path>] [\-i<ifname>] [\-a<path>] [\-hvB] [command..]
.SH DESCRIPTION
This manual page documents briefly the
.B hostapd_cli
@@ -38,6 +38,12 @@ Interface to listen on.
Default: first interface found in socket path.
.TP
+.B \-a<path>
+Run in daemon mode executing the action file based on events from hostapd.
+.TP
+.B \-B
+Run a daemon in the background.
+.TP
.B \-h
Show usage.
.TP
diff --git a/contrib/wpa/hostapd/hostapd_cli.c b/contrib/wpa/hostapd/hostapd_cli.c
index c2ecd4e..589530e 100644
--- a/contrib/wpa/hostapd/hostapd_cli.c
+++ b/contrib/wpa/hostapd/hostapd_cli.c
@@ -1,6 +1,6 @@
/*
* hostapd - command line interface for hostapd daemon
- * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2004-2010, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -15,14 +15,14 @@
#include "includes.h"
#include <dirent.h>
-#include "wpa_ctrl.h"
+#include "common/wpa_ctrl.h"
#include "common.h"
-#include "version.h"
+#include "common/version.h"
static const char *hostapd_cli_version =
"hostapd_cli v" VERSION_STR "\n"
-"Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi> and contributors";
+"Copyright (c) 2004-2010, Jouni Malinen <j@w1.fi> and contributors";
static const char *hostapd_cli_license =
@@ -83,12 +83,18 @@ static const char *commands_help =
" sta <addr> get MIB variables for one station\n"
" all_sta get MIB variables for all stations\n"
" new_sta <addr> add a new station\n"
+" deauthenticate <addr> deauthenticate a station\n"
+" disassociate <addr> disassociate a station\n"
#ifdef CONFIG_IEEE80211W
" sa_query <addr> send SA Query to a station\n"
#endif /* CONFIG_IEEE80211W */
#ifdef CONFIG_WPS
" wps_pin <uuid> <pin> [timeout] add WPS Enrollee PIN (Device Password)\n"
" wps_pbc indicate button pushed to initiate PBC\n"
+#ifdef CONFIG_WPS_OOB
+" wps_oob <type> <path> <method> use WPS with out-of-band (UFD)\n"
+#endif /* CONFIG_WPS_OOB */
+" wps_ap_pin <cmd> [params..] enable/disable AP PIN\n"
#endif /* CONFIG_WPS */
" help show this usage help\n"
" interface [ifname] show interfaces/select interface\n"
@@ -101,23 +107,29 @@ static int hostapd_cli_quit = 0;
static int hostapd_cli_attached = 0;
static const char *ctrl_iface_dir = "/var/run/hostapd";
static char *ctrl_ifname = NULL;
+static const char *pid_file = NULL;
+static const char *action_file = NULL;
static int ping_interval = 5;
static void usage(void)
{
fprintf(stderr, "%s\n", hostapd_cli_version);
- fprintf(stderr,
- "\n"
- "usage: hostapd_cli [-p<path>] [-i<ifname>] [-hv] "
- "[-G<ping interval>] \\\n"
- " [command..]\n"
+ fprintf(stderr,
+ "\n"
+ "usage: hostapd_cli [-p<path>] [-i<ifname>] [-hvB] "
+ "[-a<path>] \\\n"
+ " [-G<ping interval>] [command..]\n"
"\n"
"Options:\n"
" -h help (show this usage text)\n"
" -v shown version information\n"
" -p<path> path to find control sockets (default: "
"/var/run/hostapd)\n"
+ " -a<file> run in daemon mode executing the action file "
+ "based on events\n"
+ " from hostapd\n"
+ " -B run a daemon in the background\n"
" -i<ifname> Interface to listen on (default: first "
"interface found in the\n"
" socket path)\n\n"
@@ -212,6 +224,51 @@ static int hostapd_cli_cmd_mib(struct wpa_ctrl *ctrl, int argc, char *argv[])
}
+static int hostapd_cli_exec(const char *program, const char *arg1,
+ const char *arg2)
+{
+ char *cmd;
+ size_t len;
+ int res;
+ int ret = 0;
+
+ len = os_strlen(program) + os_strlen(arg1) + os_strlen(arg2) + 3;
+ cmd = os_malloc(len);
+ if (cmd == NULL)
+ return -1;
+ res = os_snprintf(cmd, len, "%s %s %s", program, arg1, arg2);
+ if (res < 0 || (size_t) res >= len) {
+ os_free(cmd);
+ return -1;
+ }
+ cmd[len - 1] = '\0';
+#ifndef _WIN32_WCE
+ if (system(cmd) < 0)
+ ret = -1;
+#endif /* _WIN32_WCE */
+ os_free(cmd);
+
+ return ret;
+}
+
+
+static void hostapd_cli_action_process(char *msg, size_t len)
+{
+ const char *pos;
+
+ pos = msg;
+ if (*pos == '<') {
+ pos = os_strchr(pos, '>');
+ if (pos)
+ pos++;
+ else
+ pos = msg;
+ }
+
+ hostapd_cli_exec(action_file, ctrl_ifname, pos);
+}
+
+
static int hostapd_cli_cmd_sta(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
char buf[64];
@@ -239,6 +296,42 @@ static int hostapd_cli_cmd_new_sta(struct wpa_ctrl *ctrl, int argc,
}
+static int hostapd_cli_cmd_deauthenticate(struct wpa_ctrl *ctrl, int argc,
+ char *argv[])
+{
+ char buf[64];
+ if (argc < 1) {
+ printf("Invalid 'deauthenticate' command - exactly one "
+ "argument, STA address, is required.\n");
+ return -1;
+ }
+ if (argc > 1)
+ os_snprintf(buf, sizeof(buf), "DEAUTHENTICATE %s %s",
+ argv[0], argv[1]);
+ else
+ os_snprintf(buf, sizeof(buf), "DEAUTHENTICATE %s", argv[0]);
+ return wpa_ctrl_command(ctrl, buf);
+}
+
+
+static int hostapd_cli_cmd_disassociate(struct wpa_ctrl *ctrl, int argc,
+ char *argv[])
+{
+ char buf[64];
+ if (argc < 1) {
+ printf("Invalid 'disassociate' command - exactly one "
+ "argument, STA address, is required.\n");
+ return -1;
+ }
+ if (argc > 1)
+ os_snprintf(buf, sizeof(buf), "DISASSOCIATE %s %s",
+ argv[0], argv[1]);
+ else
+ os_snprintf(buf, sizeof(buf), "DISASSOCIATE %s", argv[0]);
+ return wpa_ctrl_command(ctrl, buf);
+}
+
+
#ifdef CONFIG_IEEE80211W
static int hostapd_cli_cmd_sa_query(struct wpa_ctrl *ctrl, int argc,
char *argv[])
@@ -279,6 +372,61 @@ static int hostapd_cli_cmd_wps_pbc(struct wpa_ctrl *ctrl, int argc,
{
return wpa_ctrl_command(ctrl, "WPS_PBC");
}
+
+
+#ifdef CONFIG_WPS_OOB
+static int hostapd_cli_cmd_wps_oob(struct wpa_ctrl *ctrl, int argc,
+ char *argv[])
+{
+ char cmd[256];
+ int res;
+
+ if (argc != 3 && argc != 4) {
+ printf("Invalid WPS_OOB command: need three or four "
+ "arguments:\n"
+ "- DEV_TYPE: use 'ufd' or 'nfc'\n"
+ "- PATH: path of OOB device like '/mnt'\n"
+ "- METHOD: OOB method 'pin-e' or 'pin-r', "
+ "'cred'\n"
+ "- DEV_NAME: (only for NFC) device name like "
+ "'pn531'\n");
+ return -1;
+ }
+
+ if (argc == 3)
+ res = os_snprintf(cmd, sizeof(cmd), "WPS_OOB %s %s %s",
+ argv[0], argv[1], argv[2]);
+ else
+ res = os_snprintf(cmd, sizeof(cmd), "WPS_OOB %s %s %s %s",
+ argv[0], argv[1], argv[2], argv[3]);
+ if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
+ printf("Too long WPS_OOB command.\n");
+ return -1;
+ }
+ return wpa_ctrl_command(ctrl, cmd);
+}
+#endif /* CONFIG_WPS_OOB */
+
+
+static int hostapd_cli_cmd_wps_ap_pin(struct wpa_ctrl *ctrl, int argc,
+ char *argv[])
+{
+ char buf[64];
+ if (argc < 1) {
+ printf("Invalid 'wps_ap_pin' command - at least one argument "
+ "is required.\n");
+ return -1;
+ }
+ if (argc > 2)
+ snprintf(buf, sizeof(buf), "WPS_AP_PIN %s %s %s",
+ argv[0], argv[1], argv[2]);
+ else if (argc > 1)
+ snprintf(buf, sizeof(buf), "WPS_AP_PIN %s %s",
+ argv[0], argv[1]);
+ else
+ snprintf(buf, sizeof(buf), "WPS_AP_PIN %s", argv[0]);
+ return wpa_ctrl_command(ctrl, buf);
+}
#endif /* CONFIG_WPS */
@@ -430,12 +578,18 @@ static struct hostapd_cli_cmd hostapd_cli_commands[] = {
{ "sta", hostapd_cli_cmd_sta },
{ "all_sta", hostapd_cli_cmd_all_sta },
{ "new_sta", hostapd_cli_cmd_new_sta },
+ { "deauthenticate", hostapd_cli_cmd_deauthenticate },
+ { "disassociate", hostapd_cli_cmd_disassociate },
#ifdef CONFIG_IEEE80211W
{ "sa_query", hostapd_cli_cmd_sa_query },
#endif /* CONFIG_IEEE80211W */
#ifdef CONFIG_WPS
{ "wps_pin", hostapd_cli_cmd_wps_pin },
{ "wps_pbc", hostapd_cli_cmd_wps_pbc },
+#ifdef CONFIG_WPS_OOB
+ { "wps_oob", hostapd_cli_cmd_wps_oob },
+#endif /* CONFIG_WPS_OOB */
+ { "wps_ap_pin", hostapd_cli_cmd_wps_ap_pin },
#endif /* CONFIG_WPS */
{ "help", hostapd_cli_cmd_help },
{ "interface", hostapd_cli_cmd_interface },
@@ -480,7 +634,8 @@ static void wpa_request(struct wpa_ctrl *ctrl, int argc, char *argv[])
}
-static void hostapd_cli_recv_pending(struct wpa_ctrl *ctrl, int in_read)
+static void hostapd_cli_recv_pending(struct wpa_ctrl *ctrl, int in_read,
+ int action_monitor)
{
int first = 1;
if (ctrl_conn == NULL)
@@ -490,10 +645,14 @@ static void hostapd_cli_recv_pending(struct wpa_ctrl *ctrl, int in_read)
size_t len = sizeof(buf) - 1;
if (wpa_ctrl_recv(ctrl, buf, &len) == 0) {
buf[len] = '\0';
- if (in_read && first)
- printf("\n");
- first = 0;
- printf("%s\n", buf);
+ if (action_monitor)
+ hostapd_cli_action_process(buf, len);
+ else {
+ if (in_read && first)
+ printf("\n");
+ first = 0;
+ printf("%s\n", buf);
+ }
} else {
printf("Could not read pending message.\n");
break;
@@ -511,7 +670,7 @@ static void hostapd_cli_interactive(void)
printf("\nInteractive mode\n\n");
do {
- hostapd_cli_recv_pending(ctrl_conn, 0);
+ hostapd_cli_recv_pending(ctrl_conn, 0, 0);
printf("> ");
alarm(ping_interval);
res = fgets(cmd, sizeof(cmd), stdin);
@@ -548,9 +707,19 @@ static void hostapd_cli_interactive(void)
}
-static void hostapd_cli_terminate(int sig)
+static void hostapd_cli_cleanup(void)
{
hostapd_cli_close_connection();
+ if (pid_file)
+ os_daemonize_terminate(pid_file);
+
+ os_program_deinit();
+}
+
+
+static void hostapd_cli_terminate(int sig)
+{
+ hostapd_cli_cleanup();
exit(0);
}
@@ -574,22 +743,69 @@ static void hostapd_cli_alarm(int sig)
}
}
if (ctrl_conn)
- hostapd_cli_recv_pending(ctrl_conn, 1);
+ hostapd_cli_recv_pending(ctrl_conn, 1, 0);
alarm(ping_interval);
}
+static void hostapd_cli_action(struct wpa_ctrl *ctrl)
+{
+ fd_set rfds;
+ int fd, res;
+ struct timeval tv;
+ char buf[256];
+ size_t len;
+
+ fd = wpa_ctrl_get_fd(ctrl);
+
+ while (!hostapd_cli_quit) {
+ FD_ZERO(&rfds);
+ FD_SET(fd, &rfds);
+ tv.tv_sec = ping_interval;
+ tv.tv_usec = 0;
+ res = select(fd + 1, &rfds, NULL, NULL, &tv);
+ if (res < 0 && errno != EINTR) {
+ perror("select");
+ break;
+ }
+
+ if (FD_ISSET(fd, &rfds))
+ hostapd_cli_recv_pending(ctrl, 0, 1);
+ else {
+ len = sizeof(buf) - 1;
+ if (wpa_ctrl_request(ctrl, "PING", 4, buf, &len,
+ hostapd_cli_action_process) < 0 ||
+ len < 4 || os_memcmp(buf, "PONG", 4) != 0) {
+ printf("hostapd did not reply to PING "
+ "command - exiting\n");
+ break;
+ }
+ }
+ }
+}
+
+
int main(int argc, char *argv[])
{
int interactive;
int warning_displayed = 0;
int c;
+ int daemonize = 0;
+
+ if (os_program_init())
+ return -1;
for (;;) {
- c = getopt(argc, argv, "hG:i:p:v");
+ c = getopt(argc, argv, "a:BhG:i:p:v");
if (c < 0)
break;
switch (c) {
+ case 'a':
+ action_file = optarg;
+ break;
+ case 'B':
+ daemonize = 1;
+ break;
case 'G':
ping_interval = atoi(optarg);
break;
@@ -600,8 +816,8 @@ int main(int argc, char *argv[])
printf("%s\n", hostapd_cli_version);
return 0;
case 'i':
- free(ctrl_ifname);
- ctrl_ifname = strdup(optarg);
+ os_free(ctrl_ifname);
+ ctrl_ifname = os_strdup(optarg);
break;
case 'p':
ctrl_iface_dir = optarg;
@@ -612,7 +828,7 @@ int main(int argc, char *argv[])
}
}
- interactive = argc == optind;
+ interactive = (argc == optind) && (action_file == NULL);
if (interactive) {
printf("%s\n\n%s\n\n", hostapd_cli_version,
@@ -625,12 +841,13 @@ int main(int argc, char *argv[])
DIR *dir = opendir(ctrl_iface_dir);
if (dir) {
while ((dent = readdir(dir))) {
- if (strcmp(dent->d_name, ".") == 0 ||
- strcmp(dent->d_name, "..") == 0)
+ if (os_strcmp(dent->d_name, ".") == 0
+ ||
+ os_strcmp(dent->d_name, "..") == 0)
continue;
printf("Selected interface '%s'\n",
dent->d_name);
- ctrl_ifname = strdup(dent->d_name);
+ ctrl_ifname = os_strdup(dent->d_name);
break;
}
closedir(dir);
@@ -653,7 +870,7 @@ int main(int argc, char *argv[])
printf("Could not connect to hostapd - re-trying\n");
warning_displayed = 1;
}
- sleep(1);
+ os_sleep(1, 0);
continue;
}
@@ -661,17 +878,27 @@ int main(int argc, char *argv[])
signal(SIGTERM, hostapd_cli_terminate);
signal(SIGALRM, hostapd_cli_alarm);
- if (interactive) {
+ if (interactive || action_file) {
if (wpa_ctrl_attach(ctrl_conn) == 0) {
hostapd_cli_attached = 1;
} else {
printf("Warning: Failed to attach to hostapd.\n");
+ if (action_file)
+ return -1;
}
+ }
+
+ if (daemonize && os_daemonize(pid_file))
+ return -1;
+
+ if (interactive)
hostapd_cli_interactive();
- } else
+ else if (action_file)
+ hostapd_cli_action(ctrl_conn);
+ else
wpa_request(ctrl_conn, argc - optind, &argv[optind]);
- free(ctrl_ifname);
- hostapd_cli_close_connection();
+ os_free(ctrl_ifname);
+ hostapd_cli_cleanup();
return 0;
}
diff --git a/contrib/wpa/hostapd/main.c b/contrib/wpa/hostapd/main.c
new file mode 100644
index 0000000..9c532d4
--- /dev/null
+++ b/contrib/wpa/hostapd/main.c
@@ -0,0 +1,565 @@
+/*
+ * hostapd / main()
+ * Copyright (c) 2002-2010, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "utils/includes.h"
+#ifndef CONFIG_NATIVE_WINDOWS
+#include <syslog.h>
+#endif /* CONFIG_NATIVE_WINDOWS */
+
+#include "utils/common.h"
+#include "utils/eloop.h"
+#include "crypto/tls.h"
+#include "common/version.h"
+#include "drivers/driver.h"
+#include "eap_server/eap.h"
+#include "eap_server/tncs.h"
+#include "ap/hostapd.h"
+#include "ap/ap_config.h"
+#include "config_file.h"
+#include "eap_register.h"
+#include "dump_state.h"
+#include "ctrl_iface.h"
+
+
+extern int wpa_debug_level;
+extern int wpa_debug_show_keys;
+extern int wpa_debug_timestamp;
+
+
+struct hapd_interfaces {
+ size_t count;
+ struct hostapd_iface **iface;
+};
+
+
+static int hostapd_for_each_interface(struct hapd_interfaces *interfaces,
+ int (*cb)(struct hostapd_iface *iface,
+ void *ctx), void *ctx)
+{
+ size_t i;
+ int ret;
+
+ for (i = 0; i < interfaces->count; i++) {
+ ret = cb(interfaces->iface[i], ctx);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
+
+#ifndef CONFIG_NO_HOSTAPD_LOGGER
+static void hostapd_logger_cb(void *ctx, const u8 *addr, unsigned int module,
+ int level, const char *txt, size_t len)
+{
+ struct hostapd_data *hapd = ctx;
+ char *format, *module_str;
+ int maxlen;
+ int conf_syslog_level, conf_stdout_level;
+ unsigned int conf_syslog, conf_stdout;
+
+ maxlen = len + 100;
+ format = os_malloc(maxlen);
+ if (!format)
+ return;
+
+ if (hapd && hapd->conf) {
+ conf_syslog_level = hapd->conf->logger_syslog_level;
+ conf_stdout_level = hapd->conf->logger_stdout_level;
+ conf_syslog = hapd->conf->logger_syslog;
+ conf_stdout = hapd->conf->logger_stdout;
+ } else {
+ conf_syslog_level = conf_stdout_level = 0;
+ conf_syslog = conf_stdout = (unsigned int) -1;
+ }
+
+ switch (module) {
+ case HOSTAPD_MODULE_IEEE80211:
+ module_str = "IEEE 802.11";
+ break;
+ case HOSTAPD_MODULE_IEEE8021X:
+ module_str = "IEEE 802.1X";
+ break;
+ case HOSTAPD_MODULE_RADIUS:
+ module_str = "RADIUS";
+ break;
+ case HOSTAPD_MODULE_WPA:
+ module_str = "WPA";
+ break;
+ case HOSTAPD_MODULE_DRIVER:
+ module_str = "DRIVER";
+ break;
+ case HOSTAPD_MODULE_IAPP:
+ module_str = "IAPP";
+ break;
+ case HOSTAPD_MODULE_MLME:
+ module_str = "MLME";
+ break;
+ default:
+ module_str = NULL;
+ break;
+ }
+
+ if (hapd && hapd->conf && addr)
+ os_snprintf(format, maxlen, "%s: STA " MACSTR "%s%s: %s",
+ hapd->conf->iface, MAC2STR(addr),
+ module_str ? " " : "", module_str, txt);
+ else if (hapd && hapd->conf)
+ os_snprintf(format, maxlen, "%s:%s%s %s",
+ hapd->conf->iface, module_str ? " " : "",
+ module_str, txt);
+ else if (addr)
+ os_snprintf(format, maxlen, "STA " MACSTR "%s%s: %s",
+ MAC2STR(addr), module_str ? " " : "",
+ module_str, txt);
+ else
+ os_snprintf(format, maxlen, "%s%s%s",
+ module_str, module_str ? ": " : "", txt);
+
+ if ((conf_stdout & module) && level >= conf_stdout_level) {
+ wpa_debug_print_timestamp();
+ printf("%s\n", format);
+ }
+
+#ifndef CONFIG_NATIVE_WINDOWS
+ if ((conf_syslog & module) && level >= conf_syslog_level) {
+ int priority;
+ switch (level) {
+ case HOSTAPD_LEVEL_DEBUG_VERBOSE:
+ case HOSTAPD_LEVEL_DEBUG:
+ priority = LOG_DEBUG;
+ break;
+ case HOSTAPD_LEVEL_INFO:
+ priority = LOG_INFO;
+ break;
+ case HOSTAPD_LEVEL_NOTICE:
+ priority = LOG_NOTICE;
+ break;
+ case HOSTAPD_LEVEL_WARNING:
+ priority = LOG_WARNING;
+ break;
+ default:
+ priority = LOG_INFO;
+ break;
+ }
+ syslog(priority, "%s", format);
+ }
+#endif /* CONFIG_NATIVE_WINDOWS */
+
+ os_free(format);
+}
+#endif /* CONFIG_NO_HOSTAPD_LOGGER */
+
+
+/**
+ * hostapd_init - Allocate and initialize per-interface data
+ * @config_file: Path to the configuration file
+ * Returns: Pointer to the allocated interface data or %NULL on failure
+ *
+ * This function is used to allocate main data structures for per-interface
+ * data. The allocated data buffer will be freed by calling
+ * hostapd_cleanup_iface().
+ */
+static struct hostapd_iface * hostapd_init(const char *config_file)
+{
+ struct hostapd_iface *hapd_iface = NULL;
+ struct hostapd_config *conf = NULL;
+ struct hostapd_data *hapd;
+ size_t i;
+
+ hapd_iface = os_zalloc(sizeof(*hapd_iface));
+ if (hapd_iface == NULL)
+ goto fail;
+
+ hapd_iface->reload_config = hostapd_reload_config;
+ hapd_iface->config_read_cb = hostapd_config_read;
+ hapd_iface->config_fname = os_strdup(config_file);
+ if (hapd_iface->config_fname == NULL)
+ goto fail;
+ hapd_iface->ctrl_iface_init = hostapd_ctrl_iface_init;
+ hapd_iface->ctrl_iface_deinit = hostapd_ctrl_iface_deinit;
+ hapd_iface->for_each_interface = hostapd_for_each_interface;
+
+ conf = hostapd_config_read(hapd_iface->config_fname);
+ if (conf == NULL)
+ goto fail;
+ hapd_iface->conf = conf;
+
+ hapd_iface->num_bss = conf->num_bss;
+ hapd_iface->bss = os_zalloc(conf->num_bss *
+ sizeof(struct hostapd_data *));
+ if (hapd_iface->bss == NULL)
+ goto fail;
+
+ for (i = 0; i < conf->num_bss; i++) {
+ hapd = hapd_iface->bss[i] =
+ hostapd_alloc_bss_data(hapd_iface, conf,
+ &conf->bss[i]);
+ if (hapd == NULL)
+ goto fail;
+ hapd->msg_ctx = hapd;
+ }
+
+ return hapd_iface;
+
+fail:
+ if (conf)
+ hostapd_config_free(conf);
+ if (hapd_iface) {
+ os_free(hapd_iface->config_fname);
+ os_free(hapd_iface->bss);
+ os_free(hapd_iface);
+ }
+ return NULL;
+}
+
+
+static int hostapd_driver_init(struct hostapd_iface *iface)
+{
+ struct wpa_init_params params;
+ size_t i;
+ struct hostapd_data *hapd = iface->bss[0];
+ struct hostapd_bss_config *conf = hapd->conf;
+ u8 *b = conf->bssid;
+
+ if (hapd->driver == NULL || hapd->driver->hapd_init == NULL) {
+ wpa_printf(MSG_ERROR, "No hostapd driver wrapper available");
+ return -1;
+ }
+
+ /* Initialize the driver interface */
+ if (!(b[0] | b[1] | b[2] | b[3] | b[4] | b[5]))
+ b = NULL;
+
+ os_memset(&params, 0, sizeof(params));
+ params.bssid = b;
+ params.ifname = hapd->conf->iface;
+ params.ssid = (const u8 *) hapd->conf->ssid.ssid;
+ params.ssid_len = hapd->conf->ssid.ssid_len;
+ params.test_socket = hapd->conf->test_socket;
+ params.use_pae_group_addr = hapd->conf->use_pae_group_addr;
+
+ params.num_bridge = hapd->iface->num_bss;
+ params.bridge = os_zalloc(hapd->iface->num_bss * sizeof(char *));
+ if (params.bridge == NULL)
+ return -1;
+ for (i = 0; i < hapd->iface->num_bss; i++) {
+ struct hostapd_data *bss = hapd->iface->bss[i];
+ if (bss->conf->bridge[0])
+ params.bridge[i] = bss->conf->bridge;
+ }
+
+ params.own_addr = hapd->own_addr;
+
+ hapd->drv_priv = hapd->driver->hapd_init(hapd, &params);
+ os_free(params.bridge);
+ if (hapd->drv_priv == NULL) {
+ wpa_printf(MSG_ERROR, "%s driver initialization failed.",
+ hapd->driver->name);
+ hapd->driver = NULL;
+ return -1;
+ }
+
+ return 0;
+}
+
+
+static void hostapd_interface_deinit_free(struct hostapd_iface *iface)
+{
+ const struct wpa_driver_ops *driver;
+ void *drv_priv;
+ if (iface == NULL)
+ return;
+ driver = iface->bss[0]->driver;
+ drv_priv = iface->bss[0]->drv_priv;
+ hostapd_interface_deinit(iface);
+ if (driver && driver->hapd_deinit)
+ driver->hapd_deinit(drv_priv);
+ hostapd_interface_free(iface);
+}
+
+
+static struct hostapd_iface *
+hostapd_interface_init(struct hapd_interfaces *interfaces,
+ const char *config_fname, int debug)
+{
+ struct hostapd_iface *iface;
+ int k;
+
+ wpa_printf(MSG_ERROR, "Configuration file: %s", config_fname);
+ iface = hostapd_init(config_fname);
+ if (!iface)
+ return NULL;
+ iface->interfaces = interfaces;
+
+ for (k = 0; k < debug; k++) {
+ if (iface->bss[0]->conf->logger_stdout_level > 0)
+ iface->bss[0]->conf->logger_stdout_level--;
+ }
+
+ if (hostapd_driver_init(iface) ||
+ hostapd_setup_interface(iface)) {
+ hostapd_interface_deinit_free(iface);
+ return NULL;
+ }
+
+ return iface;
+}
+
+
+/**
+ * handle_term - SIGINT and SIGTERM handler to terminate hostapd process
+ */
+static void handle_term(int sig, void *signal_ctx)
+{
+ wpa_printf(MSG_DEBUG, "Signal %d received - terminating", sig);
+ eloop_terminate();
+}
+
+
+#ifndef CONFIG_NATIVE_WINDOWS
+
+static int handle_reload_iface(struct hostapd_iface *iface, void *ctx)
+{
+ if (hostapd_reload_config(iface) < 0) {
+ wpa_printf(MSG_WARNING, "Failed to read new configuration "
+ "file - continuing with old.");
+ }
+ return 0;
+}
+
+
+/**
+ * handle_reload - SIGHUP handler to reload configuration
+ */
+static void handle_reload(int sig, void *signal_ctx)
+{
+ struct hapd_interfaces *interfaces = signal_ctx;
+ wpa_printf(MSG_DEBUG, "Signal %d received - reloading configuration",
+ sig);
+ hostapd_for_each_interface(interfaces, handle_reload_iface, NULL);
+}
+
+
+static void handle_dump_state(int sig, void *signal_ctx)
+{
+#ifdef HOSTAPD_DUMP_STATE
+ struct hapd_interfaces *interfaces = signal_ctx;
+ hostapd_for_each_interface(interfaces, handle_dump_state_iface, NULL);
+#endif /* HOSTAPD_DUMP_STATE */
+}
+#endif /* CONFIG_NATIVE_WINDOWS */
+
+
+static int hostapd_global_init(struct hapd_interfaces *interfaces)
+{
+ hostapd_logger_register_cb(hostapd_logger_cb);
+
+ if (eap_server_register_methods()) {
+ wpa_printf(MSG_ERROR, "Failed to register EAP methods");
+ return -1;
+ }
+
+ if (eloop_init()) {
+ wpa_printf(MSG_ERROR, "Failed to initialize event loop");
+ return -1;
+ }
+
+#ifndef CONFIG_NATIVE_WINDOWS
+ eloop_register_signal(SIGHUP, handle_reload, interfaces);
+ eloop_register_signal(SIGUSR1, handle_dump_state, interfaces);
+#endif /* CONFIG_NATIVE_WINDOWS */
+ eloop_register_signal_terminate(handle_term, interfaces);
+
+#ifndef CONFIG_NATIVE_WINDOWS
+ openlog("hostapd", 0, LOG_DAEMON);
+#endif /* CONFIG_NATIVE_WINDOWS */
+
+ return 0;
+}
+
+
+static void hostapd_global_deinit(const char *pid_file)
+{
+#ifdef EAP_SERVER_TNC
+ tncs_global_deinit();
+#endif /* EAP_SERVER_TNC */
+
+ eloop_destroy();
+
+#ifndef CONFIG_NATIVE_WINDOWS
+ closelog();
+#endif /* CONFIG_NATIVE_WINDOWS */
+
+ eap_server_unregister_methods();
+
+ os_daemonize_terminate(pid_file);
+}
+
+
+static int hostapd_global_run(struct hapd_interfaces *ifaces, int daemonize,
+ const char *pid_file)
+{
+#ifdef EAP_SERVER_TNC
+ int tnc = 0;
+ size_t i, k;
+
+ for (i = 0; !tnc && i < ifaces->count; i++) {
+ for (k = 0; k < ifaces->iface[i]->num_bss; k++) {
+ if (ifaces->iface[i]->bss[0]->conf->tnc) {
+ tnc++;
+ break;
+ }
+ }
+ }
+
+ if (tnc && tncs_global_init() < 0) {
+ wpa_printf(MSG_ERROR, "Failed to initialize TNCS");
+ return -1;
+ }
+#endif /* EAP_SERVER_TNC */
+
+ if (daemonize && os_daemonize(pid_file)) {
+ perror("daemon");
+ return -1;
+ }
+
+ eloop_run();
+
+ return 0;
+}
+
+
+static void show_version(void)
+{
+ fprintf(stderr,
+ "hostapd v" VERSION_STR "\n"
+ "User space daemon for IEEE 802.11 AP management,\n"
+ "IEEE 802.1X/WPA/WPA2/EAP/RADIUS Authenticator\n"
+ "Copyright (c) 2002-2010, Jouni Malinen <j@w1.fi> "
+ "and contributors\n");
+}
+
+
+static void usage(void)
+{
+ show_version();
+ fprintf(stderr,
+ "\n"
+ "usage: hostapd [-hdBKtv] [-P <PID file>] "
+ "<configuration file(s)>\n"
+ "\n"
+ "options:\n"
+ " -h show this usage\n"
+ " -d show more debug messages (-dd for even more)\n"
+ " -B run daemon in the background\n"
+ " -P PID file\n"
+ " -K include key data in debug messages\n"
+ " -t include timestamps in some debug messages\n"
+ " -v show hostapd version\n");
+
+ exit(1);
+}
+
+
+int main(int argc, char *argv[])
+{
+ struct hapd_interfaces interfaces;
+ int ret = 1;
+ size_t i;
+ int c, debug = 0, daemonize = 0;
+ char *pid_file = NULL;
+
+ if (os_program_init())
+ return -1;
+
+ for (;;) {
+ c = getopt(argc, argv, "BdhKP:tv");
+ if (c < 0)
+ break;
+ switch (c) {
+ case 'h':
+ usage();
+ break;
+ case 'd':
+ debug++;
+ if (wpa_debug_level > 0)
+ wpa_debug_level--;
+ break;
+ case 'B':
+ daemonize++;
+ break;
+ case 'K':
+ wpa_debug_show_keys++;
+ break;
+ case 'P':
+ os_free(pid_file);
+ pid_file = os_rel2abs_path(optarg);
+ break;
+ case 't':
+ wpa_debug_timestamp++;
+ break;
+ case 'v':
+ show_version();
+ exit(1);
+ break;
+
+ default:
+ usage();
+ break;
+ }
+ }
+
+ if (optind == argc)
+ usage();
+
+ interfaces.count = argc - optind;
+ interfaces.iface = os_malloc(interfaces.count *
+ sizeof(struct hostapd_iface *));
+ if (interfaces.iface == NULL) {
+ wpa_printf(MSG_ERROR, "malloc failed\n");
+ return -1;
+ }
+
+ if (hostapd_global_init(&interfaces))
+ return -1;
+
+ /* Initialize interfaces */
+ for (i = 0; i < interfaces.count; i++) {
+ interfaces.iface[i] = hostapd_interface_init(&interfaces,
+ argv[optind + i],
+ debug);
+ if (!interfaces.iface[i])
+ goto out;
+ }
+
+ if (hostapd_global_run(&interfaces, daemonize, pid_file))
+ goto out;
+
+ ret = 0;
+
+ out:
+ /* Deinitialize all interfaces */
+ for (i = 0; i < interfaces.count; i++)
+ hostapd_interface_deinit_free(interfaces.iface[i]);
+ os_free(interfaces.iface);
+
+ hostapd_global_deinit(pid_file);
+ os_free(pid_file);
+
+ os_program_deinit();
+
+ return ret;
+}
diff --git a/contrib/wpa/hostapd/nt_password_hash.c b/contrib/wpa/hostapd/nt_password_hash.c
index 9df307d..839802a 100644
--- a/contrib/wpa/hostapd/nt_password_hash.c
+++ b/contrib/wpa/hostapd/nt_password_hash.c
@@ -15,7 +15,7 @@
#include "includes.h"
#include "common.h"
-#include "ms_funcs.h"
+#include "crypto/ms_funcs.h"
int main(int argc, char *argv[])
@@ -43,7 +43,8 @@ int main(int argc, char *argv[])
password = buf;
}
- nt_password_hash((u8 *) password, strlen(password), password_hash);
+ if (nt_password_hash((u8 *) password, strlen(password), password_hash))
+ return -1;
for (i = 0; i < sizeof(password_hash); i++)
printf("%02x", password_hash[i]);
printf("\n");
diff --git a/contrib/wpa/hostapd/sta_info.h b/contrib/wpa/hostapd/sta_info.h
deleted file mode 100644
index e835970..0000000
--- a/contrib/wpa/hostapd/sta_info.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * hostapd / Station table
- * Copyright (c) 2002-2008, Jouni Malinen <j@w1.fi>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
- */
-
-#ifndef STA_INFO_H
-#define STA_INFO_H
-
-int ap_for_each_sta(struct hostapd_data *hapd,
- int (*cb)(struct hostapd_data *hapd, struct sta_info *sta,
- void *ctx),
- void *ctx);
-struct sta_info * ap_get_sta(struct hostapd_data *hapd, const u8 *sta);
-void ap_sta_hash_add(struct hostapd_data *hapd, struct sta_info *sta);
-void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta);
-void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta);
-void hostapd_free_stas(struct hostapd_data *hapd);
-void ap_handle_timer(void *eloop_ctx, void *timeout_ctx);
-void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,
- u32 session_timeout);
-void ap_sta_no_session_timeout(struct hostapd_data *hapd,
- struct sta_info *sta);
-struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr);
-void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,
- u16 reason);
-void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
- u16 reason);
-int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
- int old_vlanid);
-void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta);
-void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta);
-int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta);
-
-#endif /* STA_INFO_H */
diff --git a/contrib/wpa/hostapd/wme.h b/contrib/wpa/hostapd/wme.h
deleted file mode 100644
index 9bc48cb..0000000
--- a/contrib/wpa/hostapd/wme.h
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * hostapd / WMM (Wi-Fi Multimedia)
- * Copyright 2002-2003, Instant802 Networks, Inc.
- * Copyright 2005-2006, Devicescape Software, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
- */
-
-#ifndef WME_H
-#define WME_H
-
-/*
- * WMM Information Element (used in (Re)Association Request frames; may also be
- * used in Beacon frames)
- */
-struct wmm_information_element {
- /* Element ID: 221 (0xdd); Length: 7 */
- /* required fields for WMM version 1 */
- u8 oui[3]; /* 00:50:f2 */
- u8 oui_type; /* 2 */
- u8 oui_subtype; /* 0 */
- u8 version; /* 1 for WMM version 1.0 */
- u8 qos_info; /* AP/STA specific QoS info */
-};
-
-#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
-#include <sys/types.h>
-#include <sys/endian.h>
-#endif /* defined(__FreeBSD__) || defined(__NetBSD__) ||
- * defined(__DragonFly__) */
-
-
-static inline u16 tsinfo(int tag1d, int contention_based, int direction)
-{
- return (tag1d << 11) | (contention_based << 7) | (direction << 5) |
- (tag1d << 1);
-}
-
-
-struct wme_information_element {
- /* required fields for WME version 1 */
- u8 oui[3];
- u8 oui_type;
- u8 oui_subtype;
- u8 version;
- u8 acInfo;
-
-} __attribute__ ((packed));
-
-#define WMM_AC_AIFSN_MASK 0x0f
-#define WMM_AC_AIFNS_SHIFT 0
-#define WMM_AC_ACM 0x10
-#define WMM_AC_ACI_MASK 0x60
-#define WMM_AC_ACI_SHIFT 5
-
-#define WMM_AC_ECWMIN_MASK 0x0f
-#define WMM_AC_ECWMIN_SHIFT 0
-#define WMM_AC_ECWMAX_MASK 0xf0
-#define WMM_AC_ECWMAX_SHIFT 4
-
-struct wmm_ac_parameter {
- u8 aci_aifsn; /* AIFSN, ACM, ACI */
- u8 cw; /* ECWmin, ECWmax (CW = 2^ECW - 1) */
- le16 txop_limit;
-} __attribute__ ((packed));
-
-/*
- * WMM Parameter Element (used in Beacon, Probe Response, and (Re)Association
- * Response frmaes)
- */
-struct wmm_parameter_element {
- /* Element ID: 221 (0xdd); Length: 24 */
- /* required fields for WMM version 1 */
- u8 oui[3]; /* 00:50:f2 */
- u8 oui_type; /* 2 */
- u8 oui_subtype; /* 1 */
- u8 version; /* 1 for WMM version 1.0 */
- u8 qos_info; /* AP/STA specif QoS info */
- u8 reserved; /* 0 */
- struct wmm_ac_parameter ac[4]; /* AC_BE, AC_BK, AC_VI, AC_VO */
-
-} __attribute__ ((packed));
-
-/* WMM TSPEC Element */
-struct wmm_tspec_element {
- u8 eid; /* 221 = 0xdd */
- u8 length; /* 6 + 55 = 61 */
- u8 oui[3]; /* 00:50:f2 */
- u8 oui_type; /* 2 */
- u8 oui_subtype; /* 2 */
- u8 version; /* 1 */
- /* WMM TSPEC body (55 octets): */
- u8 ts_info[3];
- le16 nominal_msdu_size;
- le16 maximum_msdu_size;
- le32 minimum_service_interval;
- le32 maximum_service_interval;
- le32 inactivity_interval;
- le32 suspension_interval;
- le32 service_start_time;
- le32 minimum_data_rate;
- le32 mean_data_rate;
- le32 peak_data_rate;
- le32 maximum_burst_size;
- le32 delay_bound;
- le32 minimum_phy_rate;
- le16 surplus_bandwidth_allowance;
- le16 medium_time;
-} __attribute__ ((packed));
-
-
-/* Access Categories / ACI to AC coding */
-enum {
- WMM_AC_BE = 0 /* Best Effort */,
- WMM_AC_BK = 1 /* Background */,
- WMM_AC_VI = 2 /* Video */,
- WMM_AC_VO = 3 /* Voice */
-};
-
-struct ieee80211_mgmt;
-
-u8 * hostapd_eid_wmm(struct hostapd_data *hapd, u8 *eid);
-int hostapd_eid_wmm_valid(struct hostapd_data *hapd, u8 *eid, size_t len);
-int hostapd_wmm_sta_config(struct hostapd_data *hapd, struct sta_info *sta);
-void hostapd_wmm_action(struct hostapd_data *hapd, struct ieee80211_mgmt *mgmt,
- size_t len);
-
-#endif /* WME_H */
diff --git a/contrib/wpa/patches/openssl-0.9.8-tls-extensions.patch b/contrib/wpa/patches/openssl-0.9.8-tls-extensions.patch
new file mode 100644
index 0000000..44490cc
--- /dev/null
+++ b/contrib/wpa/patches/openssl-0.9.8-tls-extensions.patch
@@ -0,0 +1,429 @@
+This patch is adding support for TLS hello extensions and externally
+generated pre-shared key material to OpenSSL 0.9.8. This is
+based on the patch from Alexey Kobozev <akobozev@cisco.com>
+(sent to openssl-dev mailing list on Tue, 07 Jun 2005 15:40:58 +0300).
+
+
+
+diff -uprN openssl-0.9.8.orig/include/openssl/ssl.h openssl-0.9.8/include/openssl/ssl.h
+--- openssl-0.9.8.orig/include/openssl/ssl.h 2005-06-10 12:51:16.000000000 -0700
++++ openssl-0.9.8/include/openssl/ssl.h 2005-07-19 20:02:15.000000000 -0700
+@@ -340,6 +340,7 @@ extern "C" {
+ * 'struct ssl_st *' function parameters used to prototype callbacks
+ * in SSL_CTX. */
+ typedef struct ssl_st *ssl_crock_st;
++typedef struct tls_extension_st TLS_EXTENSION;
+
+ /* used to hold info on the particular ciphers used */
+ typedef struct ssl_cipher_st
+@@ -361,6 +362,8 @@ DECLARE_STACK_OF(SSL_CIPHER)
+ typedef struct ssl_st SSL;
+ typedef struct ssl_ctx_st SSL_CTX;
+
++typedef int (*tls_session_secret_cb_fn)(SSL *s, void *secret, int *secret_len, STACK_OF(SSL_CIPHER) *peer_ciphers, SSL_CIPHER **cipher, void *arg);
++
+ /* Used to hold functions for SSLv2 or SSLv3/TLSv1 functions */
+ typedef struct ssl_method_st
+ {
+@@ -968,6 +971,15 @@ struct ssl_st
+ int first_packet;
+ int client_version; /* what was passed, used for
+ * SSLv3/TLS rollback check */
++
++ /* TLS externsions */
++ TLS_EXTENSION *tls_extension;
++ int (*tls_extension_cb)(SSL *s, TLS_EXTENSION *tls_ext, void *arg);
++ void *tls_extension_cb_arg;
++
++ /* TLS pre-shared secret session resumption */
++ tls_session_secret_cb_fn tls_session_secret_cb;
++ void *tls_session_secret_cb_arg;
+ };
+
+ #ifdef __cplusplus
+@@ -1533,6 +1545,13 @@ void *SSL_COMP_get_compression_methods(v
+ int SSL_COMP_add_compression_method(int id,void *cm);
+ #endif
+
++/* TLS extensions functions */
++int SSL_set_hello_extension(SSL *s, int ext_type, void *ext_data, int ext_len);
++int SSL_set_hello_extension_cb(SSL *s, int (*cb)(SSL *, TLS_EXTENSION *, void *), void *arg);
++
++/* Pre-shared secret session resumption functions */
++int SSL_set_session_secret_cb(SSL *s, tls_session_secret_cb_fn tls_session_secret_cb, void *arg);
++
+ /* BEGIN ERROR CODES */
+ /* The following lines are auto generated by the script mkerr.pl. Any changes
+ * made after this point may be overwritten when the script is next run.
+@@ -1714,6 +1733,7 @@ void ERR_load_SSL_strings(void);
+ #define SSL_F_TLS1_ENC 210
+ #define SSL_F_TLS1_SETUP_KEY_BLOCK 211
+ #define SSL_F_WRITE_PENDING 212
++#define SSL_F_SSL_SET_HELLO_EXTENSION 213
+
+ /* Reason codes. */
+ #define SSL_R_APP_DATA_IN_HANDSHAKE 100
+diff -uprN openssl-0.9.8.orig/include/openssl/tls1.h openssl-0.9.8/include/openssl/tls1.h
+--- openssl-0.9.8.orig/include/openssl/tls1.h 2003-07-22 05:34:21.000000000 -0700
++++ openssl-0.9.8/include/openssl/tls1.h 2005-07-19 20:02:15.000000000 -0700
+@@ -282,6 +282,14 @@ extern "C" {
+ #define TLS_MD_MASTER_SECRET_CONST "\x6d\x61\x73\x74\x65\x72\x20\x73\x65\x63\x72\x65\x74" /*master secret*/
+ #endif
+
++/* TLS extension struct */
++struct tls_extension_st
++{
++ unsigned short type;
++ unsigned short length;
++ void *data;
++};
++
+ #ifdef __cplusplus
+ }
+ #endif
+diff -uprN openssl-0.9.8.orig/ssl/Makefile openssl-0.9.8/ssl/Makefile
+--- openssl-0.9.8.orig/ssl/Makefile 2005-05-30 16:20:30.000000000 -0700
++++ openssl-0.9.8/ssl/Makefile 2005-07-19 20:02:15.000000000 -0700
+@@ -24,7 +24,7 @@ LIBSRC= \
+ s2_meth.c s2_srvr.c s2_clnt.c s2_lib.c s2_enc.c s2_pkt.c \
+ s3_meth.c s3_srvr.c s3_clnt.c s3_lib.c s3_enc.c s3_pkt.c s3_both.c \
+ s23_meth.c s23_srvr.c s23_clnt.c s23_lib.c s23_pkt.c \
+- t1_meth.c t1_srvr.c t1_clnt.c t1_lib.c t1_enc.c \
++ t1_meth.c t1_srvr.c t1_clnt.c t1_lib.c t1_enc.c t1_ext.c \
+ d1_meth.c d1_srvr.c d1_clnt.c d1_lib.c d1_pkt.c \
+ d1_both.c d1_enc.c \
+ ssl_lib.c ssl_err2.c ssl_cert.c ssl_sess.c \
+@@ -35,7 +35,7 @@ LIBOBJ= \
+ s2_meth.o s2_srvr.o s2_clnt.o s2_lib.o s2_enc.o s2_pkt.o \
+ s3_meth.o s3_srvr.o s3_clnt.o s3_lib.o s3_enc.o s3_pkt.o s3_both.o \
+ s23_meth.o s23_srvr.o s23_clnt.o s23_lib.o s23_pkt.o \
+- t1_meth.o t1_srvr.o t1_clnt.o t1_lib.o t1_enc.o \
++ t1_meth.o t1_srvr.o t1_clnt.o t1_lib.o t1_enc.o t1_ext.o \
+ d1_meth.o d1_srvr.o d1_clnt.o d1_lib.o d1_pkt.o \
+ d1_both.o d1_enc.o \
+ ssl_lib.o ssl_err2.o ssl_cert.o ssl_sess.o \
+@@ -968,3 +968,4 @@ t1_srvr.o: ../include/openssl/ssl23.h ..
+ t1_srvr.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+ t1_srvr.o: ../include/openssl/tls1.h ../include/openssl/x509.h
+ t1_srvr.o: ../include/openssl/x509_vfy.h ssl_locl.h t1_srvr.c
++t1_ext.o: t1_ext.c ssl_locl.h
+diff -uprN openssl-0.9.8.orig/ssl/s3_clnt.c openssl-0.9.8/ssl/s3_clnt.c
+--- openssl-0.9.8.orig/ssl/s3_clnt.c 2005-05-16 03:11:03.000000000 -0700
++++ openssl-0.9.8/ssl/s3_clnt.c 2005-07-19 20:02:15.000000000 -0700
+@@ -606,6 +606,20 @@ int ssl3_client_hello(SSL *s)
+ }
+ *(p++)=0; /* Add the NULL method */
+
++ /* send client hello extensions if any */
++ if (s->version >= TLS1_VERSION && s->tls_extension)
++ {
++ // set the total extensions length
++ s2n(s->tls_extension->length + 4, p);
++
++ // put the extensions with type and length
++ s2n(s->tls_extension->type, p);
++ s2n(s->tls_extension->length, p);
++
++ memcpy(p, s->tls_extension->data, s->tls_extension->length);
++ p+=s->tls_extension->length;
++ }
++
+ l=(p-d);
+ d=buf;
+ *(d++)=SSL3_MT_CLIENT_HELLO;
+@@ -628,7 +642,7 @@ int ssl3_get_server_hello(SSL *s)
+ STACK_OF(SSL_CIPHER) *sk;
+ SSL_CIPHER *c;
+ unsigned char *p,*d;
+- int i,al,ok;
++ int i,al,ok,pre_shared;
+ unsigned int j;
+ long n;
+ SSL_COMP *comp;
+@@ -693,7 +707,24 @@ int ssl3_get_server_hello(SSL *s)
+ goto f_err;
+ }
+
+- if (j != 0 && j == s->session->session_id_length
++ /* check if we want to resume the session based on external pre-shared secret */
++ pre_shared = 0;
++ if (s->version >= TLS1_VERSION && s->tls_session_secret_cb)
++ {
++ SSL_CIPHER *pref_cipher=NULL;
++ s->session->master_key_length=sizeof(s->session->master_key);
++ if (s->tls_session_secret_cb(s, s->session->master_key, &s->session->master_key_length,
++ NULL, &pref_cipher, s->tls_session_secret_cb_arg))
++ {
++ s->hit=1;
++ s->session->cipher=pref_cipher ? pref_cipher : ssl_get_cipher_by_char(s,p+j);
++ s->session->session_id_length = j;
++ memcpy(s->session->session_id, p, j);
++ pre_shared = 1;
++ }
++ }
++
++ if ((pre_shared || j != 0) && j == s->session->session_id_length
+ && memcmp(p,s->session->session_id,j) == 0)
+ {
+ if(s->sid_ctx_length != s->session->sid_ctx_length
+diff -uprN openssl-0.9.8.orig/ssl/s3_srvr.c openssl-0.9.8/ssl/s3_srvr.c
+--- openssl-0.9.8.orig/ssl/s3_srvr.c 2005-05-22 17:32:55.000000000 -0700
++++ openssl-0.9.8/ssl/s3_srvr.c 2005-07-19 20:02:15.000000000 -0700
+@@ -955,6 +955,75 @@ int ssl3_get_client_hello(SSL *s)
+ }
+ #endif
+
++ /* Check for TLS client hello extension here */
++ if (p < (d+n) && s->version >= TLS1_VERSION)
++ {
++ if (s->tls_extension_cb)
++ {
++ TLS_EXTENSION tls_ext;
++ unsigned short ext_total_len;
++
++ n2s(p, ext_total_len);
++ n2s(p, tls_ext.type);
++ n2s(p, tls_ext.length);
++
++ // sanity check in TLS extension len
++ if (tls_ext.length > (d+n) - p)
++ {
++ // just cut the lenth to packet border
++ tls_ext.length = (d+n) - p;
++ }
++
++ tls_ext.data = p;
++
++ // returns an alert code or 0
++ al = s->tls_extension_cb(s, &tls_ext, s->tls_extension_cb_arg);
++ if (al != 0)
++ {
++ SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_PEER_ERROR);
++ goto f_err;
++ }
++ }
++ }
++
++ /* Check if we want to use external pre-shared secret for this handshake */
++ /* for not reused session only */
++ if (!s->hit && s->version >= TLS1_VERSION && s->tls_session_secret_cb)
++ {
++ SSL_CIPHER *pref_cipher=NULL;
++
++ s->session->master_key_length=sizeof(s->session->master_key);
++ if(s->tls_session_secret_cb(s, s->session->master_key, &s->session->master_key_length,
++ ciphers, &pref_cipher, s->tls_session_secret_cb_arg))
++ {
++ s->hit=1;
++ s->session->ciphers=ciphers;
++ s->session->verify_result=X509_V_OK;
++
++ ciphers=NULL;
++
++ /* check if some cipher was preferred by call back */
++ pref_cipher=pref_cipher ? pref_cipher : ssl3_choose_cipher(s, s->session->ciphers, SSL_get_ciphers(s));
++ if (pref_cipher == NULL)
++ {
++ al=SSL_AD_HANDSHAKE_FAILURE;
++ SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_SHARED_CIPHER);
++ goto f_err;
++ }
++
++ s->session->cipher=pref_cipher;
++
++ if (s->cipher_list)
++ sk_SSL_CIPHER_free(s->cipher_list);
++
++ if (s->cipher_list_by_id)
++ sk_SSL_CIPHER_free(s->cipher_list_by_id);
++
++ s->cipher_list = sk_SSL_CIPHER_dup(s->session->ciphers);
++ s->cipher_list_by_id = sk_SSL_CIPHER_dup(s->session->ciphers);
++ }
++ }
++
+ /* Given s->session->ciphers and SSL_get_ciphers, we must
+ * pick a cipher */
+
+diff -uprN openssl-0.9.8.orig/ssl/ssl_err.c openssl-0.9.8/ssl/ssl_err.c
+--- openssl-0.9.8.orig/ssl/ssl_err.c 2005-06-10 12:51:16.000000000 -0700
++++ openssl-0.9.8/ssl/ssl_err.c 2005-07-19 20:02:15.000000000 -0700
+@@ -242,6 +242,7 @@ static ERR_STRING_DATA SSL_str_functs[]=
+ {ERR_FUNC(SSL_F_TLS1_ENC), "TLS1_ENC"},
+ {ERR_FUNC(SSL_F_TLS1_SETUP_KEY_BLOCK), "TLS1_SETUP_KEY_BLOCK"},
+ {ERR_FUNC(SSL_F_WRITE_PENDING), "WRITE_PENDING"},
++{ERR_FUNC(SSL_F_SSL_SET_HELLO_EXTENSION), "SSL_set_hello_extension"},
+ {0,NULL}
+ };
+
+diff -uprN openssl-0.9.8.orig/ssl/ssl.h openssl-0.9.8/ssl/ssl.h
+--- openssl-0.9.8.orig/ssl/ssl.h 2005-06-10 12:51:16.000000000 -0700
++++ openssl-0.9.8/ssl/ssl.h 2005-07-19 20:02:15.000000000 -0700
+@@ -340,6 +340,7 @@ extern "C" {
+ * 'struct ssl_st *' function parameters used to prototype callbacks
+ * in SSL_CTX. */
+ typedef struct ssl_st *ssl_crock_st;
++typedef struct tls_extension_st TLS_EXTENSION;
+
+ /* used to hold info on the particular ciphers used */
+ typedef struct ssl_cipher_st
+@@ -361,6 +362,8 @@ DECLARE_STACK_OF(SSL_CIPHER)
+ typedef struct ssl_st SSL;
+ typedef struct ssl_ctx_st SSL_CTX;
+
++typedef int (*tls_session_secret_cb_fn)(SSL *s, void *secret, int *secret_len, STACK_OF(SSL_CIPHER) *peer_ciphers, SSL_CIPHER **cipher, void *arg);
++
+ /* Used to hold functions for SSLv2 or SSLv3/TLSv1 functions */
+ typedef struct ssl_method_st
+ {
+@@ -968,6 +971,15 @@ struct ssl_st
+ int first_packet;
+ int client_version; /* what was passed, used for
+ * SSLv3/TLS rollback check */
++
++ /* TLS externsions */
++ TLS_EXTENSION *tls_extension;
++ int (*tls_extension_cb)(SSL *s, TLS_EXTENSION *tls_ext, void *arg);
++ void *tls_extension_cb_arg;
++
++ /* TLS pre-shared secret session resumption */
++ tls_session_secret_cb_fn tls_session_secret_cb;
++ void *tls_session_secret_cb_arg;
+ };
+
+ #ifdef __cplusplus
+@@ -1533,6 +1545,13 @@ void *SSL_COMP_get_compression_methods(v
+ int SSL_COMP_add_compression_method(int id,void *cm);
+ #endif
+
++/* TLS extensions functions */
++int SSL_set_hello_extension(SSL *s, int ext_type, void *ext_data, int ext_len);
++int SSL_set_hello_extension_cb(SSL *s, int (*cb)(SSL *, TLS_EXTENSION *, void *), void *arg);
++
++/* Pre-shared secret session resumption functions */
++int SSL_set_session_secret_cb(SSL *s, tls_session_secret_cb_fn tls_session_secret_cb, void *arg);
++
+ /* BEGIN ERROR CODES */
+ /* The following lines are auto generated by the script mkerr.pl. Any changes
+ * made after this point may be overwritten when the script is next run.
+@@ -1714,6 +1733,7 @@ void ERR_load_SSL_strings(void);
+ #define SSL_F_TLS1_ENC 210
+ #define SSL_F_TLS1_SETUP_KEY_BLOCK 211
+ #define SSL_F_WRITE_PENDING 212
++#define SSL_F_SSL_SET_HELLO_EXTENSION 213
+
+ /* Reason codes. */
+ #define SSL_R_APP_DATA_IN_HANDSHAKE 100
+diff -uprN openssl-0.9.8.orig/ssl/ssl_sess.c openssl-0.9.8/ssl/ssl_sess.c
+--- openssl-0.9.8.orig/ssl/ssl_sess.c 2005-04-29 13:10:06.000000000 -0700
++++ openssl-0.9.8/ssl/ssl_sess.c 2005-07-19 20:02:15.000000000 -0700
+@@ -656,6 +656,15 @@ long SSL_CTX_get_timeout(const SSL_CTX *
+ return(s->session_timeout);
+ }
+
++int SSL_set_session_secret_cb(SSL *s, int (*tls_session_secret_cb)(SSL *s, void *secret, int *secret_len,
++ STACK_OF(SSL_CIPHER) *peer_ciphers, SSL_CIPHER **cipher, void *arg), void *arg)
++{
++ if (s == NULL) return(0);
++ s->tls_session_secret_cb = tls_session_secret_cb;
++ s->tls_session_secret_cb_arg = arg;
++ return(1);
++}
++
+ typedef struct timeout_param_st
+ {
+ SSL_CTX *ctx;
+diff -uprN openssl-0.9.8.orig/ssl/t1_ext.c openssl-0.9.8/ssl/t1_ext.c
+--- openssl-0.9.8.orig/ssl/t1_ext.c 1969-12-31 16:00:00.000000000 -0800
++++ openssl-0.9.8/ssl/t1_ext.c 2005-07-19 20:03:29.000000000 -0700
+@@ -0,0 +1,48 @@
++
++#include <stdio.h>
++#include "ssl_locl.h"
++
++
++int SSL_set_hello_extension(SSL *s, int ext_type, void *ext_data, int ext_len)
++{
++ if(s->version >= TLS1_VERSION)
++ {
++ if(s->tls_extension)
++ {
++ OPENSSL_free(s->tls_extension);
++ s->tls_extension = NULL;
++ }
++
++ if(ext_data)
++ {
++ s->tls_extension = OPENSSL_malloc(sizeof(TLS_EXTENSION) + ext_len);
++ if(!s->tls_extension)
++ {
++ SSLerr(SSL_F_SSL_SET_HELLO_EXTENSION, ERR_R_MALLOC_FAILURE);
++ return 0;
++ }
++
++ s->tls_extension->type = ext_type;
++ s->tls_extension->length = ext_len;
++ s->tls_extension->data = s->tls_extension + 1;
++ memcpy(s->tls_extension->data, ext_data, ext_len);
++ }
++
++ return 1;
++ }
++
++ return 0;
++}
++
++int SSL_set_hello_extension_cb(SSL *s, int (*cb)(SSL *, TLS_EXTENSION *, void *), void *arg)
++{
++ if(s->version >= TLS1_VERSION)
++ {
++ s->tls_extension_cb = cb;
++ s->tls_extension_cb_arg = arg;
++
++ return 1;
++ }
++
++ return 0;
++}
+diff -uprN openssl-0.9.8.orig/ssl/t1_lib.c openssl-0.9.8/ssl/t1_lib.c
+--- openssl-0.9.8.orig/ssl/t1_lib.c 2005-04-26 09:02:40.000000000 -0700
++++ openssl-0.9.8/ssl/t1_lib.c 2005-07-19 20:02:15.000000000 -0700
+@@ -131,6 +131,10 @@ int tls1_new(SSL *s)
+
+ void tls1_free(SSL *s)
+ {
++ if(s->tls_extension)
++ {
++ OPENSSL_free(s->tls_extension);
++ }
+ ssl3_free(s);
+ }
+
+diff -uprN openssl-0.9.8.orig/ssl/tls1.h openssl-0.9.8/ssl/tls1.h
+--- openssl-0.9.8.orig/ssl/tls1.h 2003-07-22 05:34:21.000000000 -0700
++++ openssl-0.9.8/ssl/tls1.h 2005-07-19 20:02:15.000000000 -0700
+@@ -282,6 +282,14 @@ extern "C" {
+ #define TLS_MD_MASTER_SECRET_CONST "\x6d\x61\x73\x74\x65\x72\x20\x73\x65\x63\x72\x65\x74" /*master secret*/
+ #endif
+
++/* TLS extension struct */
++struct tls_extension_st
++{
++ unsigned short type;
++ unsigned short length;
++ void *data;
++};
++
+ #ifdef __cplusplus
+ }
+ #endif
+diff -uprN openssl-0.9.8.orig/util/ssleay.num openssl-0.9.8/util/ssleay.num
+--- openssl-0.9.8.orig/util/ssleay.num 2005-05-08 17:22:02.000000000 -0700
++++ openssl-0.9.8/util/ssleay.num 2005-07-19 20:02:15.000000000 -0700
+@@ -226,3 +226,6 @@ DTLSv1_server_method
+ SSL_COMP_get_compression_methods 276 EXIST:!VMS:FUNCTION:COMP
+ SSL_COMP_get_compress_methods 276 EXIST:VMS:FUNCTION:COMP
+ SSL_SESSION_get_id 277 EXIST::FUNCTION:
++SSL_set_hello_extension 278 EXIST::FUNCTION:
++SSL_set_hello_extension_cb 279 EXIST::FUNCTION:
++SSL_set_session_secret_cb 280 EXIST::FUNCTION:
diff --git a/contrib/wpa/patches/openssl-0.9.8d-tls-extensions.patch b/contrib/wpa/patches/openssl-0.9.8d-tls-extensions.patch
new file mode 100644
index 0000000..eec6db8
--- /dev/null
+++ b/contrib/wpa/patches/openssl-0.9.8d-tls-extensions.patch
@@ -0,0 +1,429 @@
+This patch is adding support for TLS hello extensions and externally
+generated pre-shared key material to OpenSSL 0.9.8d. This is
+based on the patch from Alexey Kobozev <akobozev@cisco.com>
+(sent to openssl-dev mailing list on Tue, 07 Jun 2005 15:40:58 +0300).
+
+
+
+diff -uprN openssl-0.9.8d.orig/include/openssl/ssl.h openssl-0.9.8d/include/openssl/ssl.h
+--- openssl-0.9.8d.orig/include/openssl/ssl.h 2006-06-14 06:52:49.000000000 -0700
++++ openssl-0.9.8d/include/openssl/ssl.h 2006-12-10 08:20:02.000000000 -0800
+@@ -345,6 +345,7 @@ extern "C" {
+ * 'struct ssl_st *' function parameters used to prototype callbacks
+ * in SSL_CTX. */
+ typedef struct ssl_st *ssl_crock_st;
++typedef struct tls_extension_st TLS_EXTENSION;
+
+ /* used to hold info on the particular ciphers used */
+ typedef struct ssl_cipher_st
+@@ -366,6 +367,8 @@ DECLARE_STACK_OF(SSL_CIPHER)
+ typedef struct ssl_st SSL;
+ typedef struct ssl_ctx_st SSL_CTX;
+
++typedef int (*tls_session_secret_cb_fn)(SSL *s, void *secret, int *secret_len, STACK_OF(SSL_CIPHER) *peer_ciphers, SSL_CIPHER **cipher, void *arg);
++
+ /* Used to hold functions for SSLv2 or SSLv3/TLSv1 functions */
+ typedef struct ssl_method_st
+ {
+@@ -973,6 +976,15 @@ struct ssl_st
+ int first_packet;
+ int client_version; /* what was passed, used for
+ * SSLv3/TLS rollback check */
++
++ /* TLS externsions */
++ TLS_EXTENSION *tls_extension;
++ int (*tls_extension_cb)(SSL *s, TLS_EXTENSION *tls_ext, void *arg);
++ void *tls_extension_cb_arg;
++
++ /* TLS pre-shared secret session resumption */
++ tls_session_secret_cb_fn tls_session_secret_cb;
++ void *tls_session_secret_cb_arg;
+ };
+
+ #ifdef __cplusplus
+@@ -1538,6 +1550,13 @@ void *SSL_COMP_get_compression_methods(v
+ int SSL_COMP_add_compression_method(int id,void *cm);
+ #endif
+
++/* TLS extensions functions */
++int SSL_set_hello_extension(SSL *s, int ext_type, void *ext_data, int ext_len);
++int SSL_set_hello_extension_cb(SSL *s, int (*cb)(SSL *, TLS_EXTENSION *, void *), void *arg);
++
++/* Pre-shared secret session resumption functions */
++int SSL_set_session_secret_cb(SSL *s, tls_session_secret_cb_fn tls_session_secret_cb, void *arg);
++
+ /* BEGIN ERROR CODES */
+ /* The following lines are auto generated by the script mkerr.pl. Any changes
+ * made after this point may be overwritten when the script is next run.
+@@ -1719,6 +1738,7 @@ void ERR_load_SSL_strings(void);
+ #define SSL_F_TLS1_ENC 210
+ #define SSL_F_TLS1_SETUP_KEY_BLOCK 211
+ #define SSL_F_WRITE_PENDING 212
++#define SSL_F_SSL_SET_HELLO_EXTENSION 213
+
+ /* Reason codes. */
+ #define SSL_R_APP_DATA_IN_HANDSHAKE 100
+diff -uprN openssl-0.9.8d.orig/include/openssl/tls1.h openssl-0.9.8d/include/openssl/tls1.h
+--- openssl-0.9.8d.orig/include/openssl/tls1.h 2006-06-14 10:52:01.000000000 -0700
++++ openssl-0.9.8d/include/openssl/tls1.h 2006-12-10 08:20:02.000000000 -0800
+@@ -296,6 +296,14 @@ extern "C" {
+ #define TLS_MD_MASTER_SECRET_CONST "\x6d\x61\x73\x74\x65\x72\x20\x73\x65\x63\x72\x65\x74" /*master secret*/
+ #endif
+
++/* TLS extension struct */
++struct tls_extension_st
++{
++ unsigned short type;
++ unsigned short length;
++ void *data;
++};
++
+ #ifdef __cplusplus
+ }
+ #endif
+diff -uprN openssl-0.9.8d.orig/ssl/Makefile openssl-0.9.8d/ssl/Makefile
+--- openssl-0.9.8d.orig/ssl/Makefile 2006-02-03 17:49:35.000000000 -0800
++++ openssl-0.9.8d/ssl/Makefile 2006-12-10 08:20:02.000000000 -0800
+@@ -24,7 +24,7 @@ LIBSRC= \
+ s2_meth.c s2_srvr.c s2_clnt.c s2_lib.c s2_enc.c s2_pkt.c \
+ s3_meth.c s3_srvr.c s3_clnt.c s3_lib.c s3_enc.c s3_pkt.c s3_both.c \
+ s23_meth.c s23_srvr.c s23_clnt.c s23_lib.c s23_pkt.c \
+- t1_meth.c t1_srvr.c t1_clnt.c t1_lib.c t1_enc.c \
++ t1_meth.c t1_srvr.c t1_clnt.c t1_lib.c t1_enc.c t1_ext.c \
+ d1_meth.c d1_srvr.c d1_clnt.c d1_lib.c d1_pkt.c \
+ d1_both.c d1_enc.c \
+ ssl_lib.c ssl_err2.c ssl_cert.c ssl_sess.c \
+@@ -35,7 +35,7 @@ LIBOBJ= \
+ s2_meth.o s2_srvr.o s2_clnt.o s2_lib.o s2_enc.o s2_pkt.o \
+ s3_meth.o s3_srvr.o s3_clnt.o s3_lib.o s3_enc.o s3_pkt.o s3_both.o \
+ s23_meth.o s23_srvr.o s23_clnt.o s23_lib.o s23_pkt.o \
+- t1_meth.o t1_srvr.o t1_clnt.o t1_lib.o t1_enc.o \
++ t1_meth.o t1_srvr.o t1_clnt.o t1_lib.o t1_enc.o t1_ext.o \
+ d1_meth.o d1_srvr.o d1_clnt.o d1_lib.o d1_pkt.o \
+ d1_both.o d1_enc.o \
+ ssl_lib.o ssl_err2.o ssl_cert.o ssl_sess.o \
+@@ -968,3 +968,4 @@ t1_srvr.o: ../include/openssl/ssl23.h ..
+ t1_srvr.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+ t1_srvr.o: ../include/openssl/tls1.h ../include/openssl/x509.h
+ t1_srvr.o: ../include/openssl/x509_vfy.h ssl_locl.h t1_srvr.c
++t1_ext.o: t1_ext.c ssl_locl.h
+diff -uprN openssl-0.9.8d.orig/ssl/s3_clnt.c openssl-0.9.8d/ssl/s3_clnt.c
+--- openssl-0.9.8d.orig/ssl/s3_clnt.c 2005-12-12 23:41:46.000000000 -0800
++++ openssl-0.9.8d/ssl/s3_clnt.c 2006-12-10 08:20:02.000000000 -0800
+@@ -601,6 +601,20 @@ int ssl3_client_hello(SSL *s)
+ #endif
+ *(p++)=0; /* Add the NULL method */
+
++ /* send client hello extensions if any */
++ if (s->version >= TLS1_VERSION && s->tls_extension)
++ {
++ // set the total extensions length
++ s2n(s->tls_extension->length + 4, p);
++
++ // put the extensions with type and length
++ s2n(s->tls_extension->type, p);
++ s2n(s->tls_extension->length, p);
++
++ memcpy(p, s->tls_extension->data, s->tls_extension->length);
++ p+=s->tls_extension->length;
++ }
++
+ l=(p-d);
+ d=buf;
+ *(d++)=SSL3_MT_CLIENT_HELLO;
+@@ -623,7 +637,7 @@ int ssl3_get_server_hello(SSL *s)
+ STACK_OF(SSL_CIPHER) *sk;
+ SSL_CIPHER *c;
+ unsigned char *p,*d;
+- int i,al,ok;
++ int i,al,ok,pre_shared;
+ unsigned int j;
+ long n;
+ #ifndef OPENSSL_NO_COMP
+@@ -690,7 +704,24 @@ int ssl3_get_server_hello(SSL *s)
+ goto f_err;
+ }
+
+- if (j != 0 && j == s->session->session_id_length
++ /* check if we want to resume the session based on external pre-shared secret */
++ pre_shared = 0;
++ if (s->version >= TLS1_VERSION && s->tls_session_secret_cb)
++ {
++ SSL_CIPHER *pref_cipher=NULL;
++ s->session->master_key_length=sizeof(s->session->master_key);
++ if (s->tls_session_secret_cb(s, s->session->master_key, &s->session->master_key_length,
++ NULL, &pref_cipher, s->tls_session_secret_cb_arg))
++ {
++ s->hit=1;
++ s->session->cipher=pref_cipher ? pref_cipher : ssl_get_cipher_by_char(s,p+j);
++ s->session->session_id_length = j;
++ memcpy(s->session->session_id, p, j);
++ pre_shared = 1;
++ }
++ }
++
++ if ((pre_shared || j != 0) && j == s->session->session_id_length
+ && memcmp(p,s->session->session_id,j) == 0)
+ {
+ if(s->sid_ctx_length != s->session->sid_ctx_length
+diff -uprN openssl-0.9.8d.orig/ssl/s3_srvr.c openssl-0.9.8d/ssl/s3_srvr.c
+--- openssl-0.9.8d.orig/ssl/s3_srvr.c 2006-09-28 04:29:03.000000000 -0700
++++ openssl-0.9.8d/ssl/s3_srvr.c 2006-12-10 08:20:02.000000000 -0800
+@@ -943,6 +943,75 @@ int ssl3_get_client_hello(SSL *s)
+ }
+ #endif
+
++ /* Check for TLS client hello extension here */
++ if (p < (d+n) && s->version >= TLS1_VERSION)
++ {
++ if (s->tls_extension_cb)
++ {
++ TLS_EXTENSION tls_ext;
++ unsigned short ext_total_len;
++
++ n2s(p, ext_total_len);
++ n2s(p, tls_ext.type);
++ n2s(p, tls_ext.length);
++
++ // sanity check in TLS extension len
++ if (tls_ext.length > (d+n) - p)
++ {
++ // just cut the lenth to packet border
++ tls_ext.length = (d+n) - p;
++ }
++
++ tls_ext.data = p;
++
++ // returns an alert code or 0
++ al = s->tls_extension_cb(s, &tls_ext, s->tls_extension_cb_arg);
++ if (al != 0)
++ {
++ SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_PEER_ERROR);
++ goto f_err;
++ }
++ }
++ }
++
++ /* Check if we want to use external pre-shared secret for this handshake */
++ /* for not reused session only */
++ if (!s->hit && s->version >= TLS1_VERSION && s->tls_session_secret_cb)
++ {
++ SSL_CIPHER *pref_cipher=NULL;
++
++ s->session->master_key_length=sizeof(s->session->master_key);
++ if(s->tls_session_secret_cb(s, s->session->master_key, &s->session->master_key_length,
++ ciphers, &pref_cipher, s->tls_session_secret_cb_arg))
++ {
++ s->hit=1;
++ s->session->ciphers=ciphers;
++ s->session->verify_result=X509_V_OK;
++
++ ciphers=NULL;
++
++ /* check if some cipher was preferred by call back */
++ pref_cipher=pref_cipher ? pref_cipher : ssl3_choose_cipher(s, s->session->ciphers, SSL_get_ciphers(s));
++ if (pref_cipher == NULL)
++ {
++ al=SSL_AD_HANDSHAKE_FAILURE;
++ SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_SHARED_CIPHER);
++ goto f_err;
++ }
++
++ s->session->cipher=pref_cipher;
++
++ if (s->cipher_list)
++ sk_SSL_CIPHER_free(s->cipher_list);
++
++ if (s->cipher_list_by_id)
++ sk_SSL_CIPHER_free(s->cipher_list_by_id);
++
++ s->cipher_list = sk_SSL_CIPHER_dup(s->session->ciphers);
++ s->cipher_list_by_id = sk_SSL_CIPHER_dup(s->session->ciphers);
++ }
++ }
++
+ /* Given s->session->ciphers and SSL_get_ciphers, we must
+ * pick a cipher */
+
+diff -uprN openssl-0.9.8d.orig/ssl/ssl.h openssl-0.9.8d/ssl/ssl.h
+--- openssl-0.9.8d.orig/ssl/ssl.h 2006-06-14 06:52:49.000000000 -0700
++++ openssl-0.9.8d/ssl/ssl.h 2006-12-10 08:20:02.000000000 -0800
+@@ -345,6 +345,7 @@ extern "C" {
+ * 'struct ssl_st *' function parameters used to prototype callbacks
+ * in SSL_CTX. */
+ typedef struct ssl_st *ssl_crock_st;
++typedef struct tls_extension_st TLS_EXTENSION;
+
+ /* used to hold info on the particular ciphers used */
+ typedef struct ssl_cipher_st
+@@ -366,6 +367,8 @@ DECLARE_STACK_OF(SSL_CIPHER)
+ typedef struct ssl_st SSL;
+ typedef struct ssl_ctx_st SSL_CTX;
+
++typedef int (*tls_session_secret_cb_fn)(SSL *s, void *secret, int *secret_len, STACK_OF(SSL_CIPHER) *peer_ciphers, SSL_CIPHER **cipher, void *arg);
++
+ /* Used to hold functions for SSLv2 or SSLv3/TLSv1 functions */
+ typedef struct ssl_method_st
+ {
+@@ -973,6 +976,15 @@ struct ssl_st
+ int first_packet;
+ int client_version; /* what was passed, used for
+ * SSLv3/TLS rollback check */
++
++ /* TLS externsions */
++ TLS_EXTENSION *tls_extension;
++ int (*tls_extension_cb)(SSL *s, TLS_EXTENSION *tls_ext, void *arg);
++ void *tls_extension_cb_arg;
++
++ /* TLS pre-shared secret session resumption */
++ tls_session_secret_cb_fn tls_session_secret_cb;
++ void *tls_session_secret_cb_arg;
+ };
+
+ #ifdef __cplusplus
+@@ -1538,6 +1550,13 @@ void *SSL_COMP_get_compression_methods(v
+ int SSL_COMP_add_compression_method(int id,void *cm);
+ #endif
+
++/* TLS extensions functions */
++int SSL_set_hello_extension(SSL *s, int ext_type, void *ext_data, int ext_len);
++int SSL_set_hello_extension_cb(SSL *s, int (*cb)(SSL *, TLS_EXTENSION *, void *), void *arg);
++
++/* Pre-shared secret session resumption functions */
++int SSL_set_session_secret_cb(SSL *s, tls_session_secret_cb_fn tls_session_secret_cb, void *arg);
++
+ /* BEGIN ERROR CODES */
+ /* The following lines are auto generated by the script mkerr.pl. Any changes
+ * made after this point may be overwritten when the script is next run.
+@@ -1719,6 +1738,7 @@ void ERR_load_SSL_strings(void);
+ #define SSL_F_TLS1_ENC 210
+ #define SSL_F_TLS1_SETUP_KEY_BLOCK 211
+ #define SSL_F_WRITE_PENDING 212
++#define SSL_F_SSL_SET_HELLO_EXTENSION 213
+
+ /* Reason codes. */
+ #define SSL_R_APP_DATA_IN_HANDSHAKE 100
+diff -uprN openssl-0.9.8d.orig/ssl/ssl_err.c openssl-0.9.8d/ssl/ssl_err.c
+--- openssl-0.9.8d.orig/ssl/ssl_err.c 2006-01-08 13:52:46.000000000 -0800
++++ openssl-0.9.8d/ssl/ssl_err.c 2006-12-10 08:20:02.000000000 -0800
+@@ -242,6 +242,7 @@ static ERR_STRING_DATA SSL_str_functs[]=
+ {ERR_FUNC(SSL_F_TLS1_ENC), "TLS1_ENC"},
+ {ERR_FUNC(SSL_F_TLS1_SETUP_KEY_BLOCK), "TLS1_SETUP_KEY_BLOCK"},
+ {ERR_FUNC(SSL_F_WRITE_PENDING), "WRITE_PENDING"},
++{ERR_FUNC(SSL_F_SSL_SET_HELLO_EXTENSION), "SSL_set_hello_extension"},
+ {0,NULL}
+ };
+
+diff -uprN openssl-0.9.8d.orig/ssl/ssl_sess.c openssl-0.9.8d/ssl/ssl_sess.c
+--- openssl-0.9.8d.orig/ssl/ssl_sess.c 2005-12-30 15:51:57.000000000 -0800
++++ openssl-0.9.8d/ssl/ssl_sess.c 2006-12-10 08:20:02.000000000 -0800
+@@ -656,6 +656,15 @@ long SSL_CTX_get_timeout(const SSL_CTX *
+ return(s->session_timeout);
+ }
+
++int SSL_set_session_secret_cb(SSL *s, int (*tls_session_secret_cb)(SSL *s, void *secret, int *secret_len,
++ STACK_OF(SSL_CIPHER) *peer_ciphers, SSL_CIPHER **cipher, void *arg), void *arg)
++{
++ if (s == NULL) return(0);
++ s->tls_session_secret_cb = tls_session_secret_cb;
++ s->tls_session_secret_cb_arg = arg;
++ return(1);
++}
++
+ typedef struct timeout_param_st
+ {
+ SSL_CTX *ctx;
+diff -uprN openssl-0.9.8d.orig/ssl/t1_ext.c openssl-0.9.8d/ssl/t1_ext.c
+--- openssl-0.9.8d.orig/ssl/t1_ext.c 1969-12-31 16:00:00.000000000 -0800
++++ openssl-0.9.8d/ssl/t1_ext.c 2006-12-10 08:20:02.000000000 -0800
+@@ -0,0 +1,48 @@
++
++#include <stdio.h>
++#include "ssl_locl.h"
++
++
++int SSL_set_hello_extension(SSL *s, int ext_type, void *ext_data, int ext_len)
++{
++ if(s->version >= TLS1_VERSION)
++ {
++ if(s->tls_extension)
++ {
++ OPENSSL_free(s->tls_extension);
++ s->tls_extension = NULL;
++ }
++
++ if(ext_data)
++ {
++ s->tls_extension = OPENSSL_malloc(sizeof(TLS_EXTENSION) + ext_len);
++ if(!s->tls_extension)
++ {
++ SSLerr(SSL_F_SSL_SET_HELLO_EXTENSION, ERR_R_MALLOC_FAILURE);
++ return 0;
++ }
++
++ s->tls_extension->type = ext_type;
++ s->tls_extension->length = ext_len;
++ s->tls_extension->data = s->tls_extension + 1;
++ memcpy(s->tls_extension->data, ext_data, ext_len);
++ }
++
++ return 1;
++ }
++
++ return 0;
++}
++
++int SSL_set_hello_extension_cb(SSL *s, int (*cb)(SSL *, TLS_EXTENSION *, void *), void *arg)
++{
++ if(s->version >= TLS1_VERSION)
++ {
++ s->tls_extension_cb = cb;
++ s->tls_extension_cb_arg = arg;
++
++ return 1;
++ }
++
++ return 0;
++}
+diff -uprN openssl-0.9.8d.orig/ssl/t1_lib.c openssl-0.9.8d/ssl/t1_lib.c
+--- openssl-0.9.8d.orig/ssl/t1_lib.c 2005-08-05 16:52:07.000000000 -0700
++++ openssl-0.9.8d/ssl/t1_lib.c 2006-12-10 08:20:02.000000000 -0800
+@@ -97,6 +97,10 @@ int tls1_new(SSL *s)
+
+ void tls1_free(SSL *s)
+ {
++ if(s->tls_extension)
++ {
++ OPENSSL_free(s->tls_extension);
++ }
+ ssl3_free(s);
+ }
+
+diff -uprN openssl-0.9.8d.orig/ssl/tls1.h openssl-0.9.8d/ssl/tls1.h
+--- openssl-0.9.8d.orig/ssl/tls1.h 2006-06-14 10:52:01.000000000 -0700
++++ openssl-0.9.8d/ssl/tls1.h 2006-12-10 08:20:02.000000000 -0800
+@@ -296,6 +296,14 @@ extern "C" {
+ #define TLS_MD_MASTER_SECRET_CONST "\x6d\x61\x73\x74\x65\x72\x20\x73\x65\x63\x72\x65\x74" /*master secret*/
+ #endif
+
++/* TLS extension struct */
++struct tls_extension_st
++{
++ unsigned short type;
++ unsigned short length;
++ void *data;
++};
++
+ #ifdef __cplusplus
+ }
+ #endif
+diff -uprN openssl-0.9.8d.orig/util/ssleay.num openssl-0.9.8d/util/ssleay.num
+--- openssl-0.9.8d.orig/util/ssleay.num 2005-05-08 17:22:02.000000000 -0700
++++ openssl-0.9.8d/util/ssleay.num 2006-12-10 08:20:02.000000000 -0800
+@@ -226,3 +226,6 @@ DTLSv1_server_method
+ SSL_COMP_get_compression_methods 276 EXIST:!VMS:FUNCTION:COMP
+ SSL_COMP_get_compress_methods 276 EXIST:VMS:FUNCTION:COMP
+ SSL_SESSION_get_id 277 EXIST::FUNCTION:
++SSL_set_hello_extension 278 EXIST::FUNCTION:
++SSL_set_hello_extension_cb 279 EXIST::FUNCTION:
++SSL_set_session_secret_cb 280 EXIST::FUNCTION:
diff --git a/contrib/wpa/patches/openssl-0.9.8e-tls-extensions.patch b/contrib/wpa/patches/openssl-0.9.8e-tls-extensions.patch
new file mode 100644
index 0000000..ede053f
--- /dev/null
+++ b/contrib/wpa/patches/openssl-0.9.8e-tls-extensions.patch
@@ -0,0 +1,353 @@
+This patch is adding support for TLS hello extensions and externally
+generated pre-shared key material to OpenSSL 0.9.8e. This is
+based on the patch from Alexey Kobozev <akobozev@cisco.com>
+(sent to openssl-dev mailing list on Tue, 07 Jun 2005 15:40:58 +0300).
+
+
+
+diff -uprN openssl-0.9.8e.orig/ssl/Makefile openssl-0.9.8e/ssl/Makefile
+--- openssl-0.9.8e.orig/ssl/Makefile 2006-02-03 17:49:35.000000000 -0800
++++ openssl-0.9.8e/ssl/Makefile 2007-03-22 20:23:19.000000000 -0700
+@@ -24,7 +24,7 @@ LIBSRC= \
+ s2_meth.c s2_srvr.c s2_clnt.c s2_lib.c s2_enc.c s2_pkt.c \
+ s3_meth.c s3_srvr.c s3_clnt.c s3_lib.c s3_enc.c s3_pkt.c s3_both.c \
+ s23_meth.c s23_srvr.c s23_clnt.c s23_lib.c s23_pkt.c \
+- t1_meth.c t1_srvr.c t1_clnt.c t1_lib.c t1_enc.c \
++ t1_meth.c t1_srvr.c t1_clnt.c t1_lib.c t1_enc.c t1_ext.c \
+ d1_meth.c d1_srvr.c d1_clnt.c d1_lib.c d1_pkt.c \
+ d1_both.c d1_enc.c \
+ ssl_lib.c ssl_err2.c ssl_cert.c ssl_sess.c \
+@@ -35,7 +35,7 @@ LIBOBJ= \
+ s2_meth.o s2_srvr.o s2_clnt.o s2_lib.o s2_enc.o s2_pkt.o \
+ s3_meth.o s3_srvr.o s3_clnt.o s3_lib.o s3_enc.o s3_pkt.o s3_both.o \
+ s23_meth.o s23_srvr.o s23_clnt.o s23_lib.o s23_pkt.o \
+- t1_meth.o t1_srvr.o t1_clnt.o t1_lib.o t1_enc.o \
++ t1_meth.o t1_srvr.o t1_clnt.o t1_lib.o t1_enc.o t1_ext.o \
+ d1_meth.o d1_srvr.o d1_clnt.o d1_lib.o d1_pkt.o \
+ d1_both.o d1_enc.o \
+ ssl_lib.o ssl_err2.o ssl_cert.o ssl_sess.o \
+@@ -968,3 +968,4 @@ t1_srvr.o: ../include/openssl/ssl23.h ..
+ t1_srvr.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
+ t1_srvr.o: ../include/openssl/tls1.h ../include/openssl/x509.h
+ t1_srvr.o: ../include/openssl/x509_vfy.h ssl_locl.h t1_srvr.c
++t1_ext.o: t1_ext.c ssl_locl.h
+diff -uprN openssl-0.9.8e.orig/ssl/s3_clnt.c openssl-0.9.8e/ssl/s3_clnt.c
+--- openssl-0.9.8e.orig/ssl/s3_clnt.c 2006-09-28 05:23:15.000000000 -0700
++++ openssl-0.9.8e/ssl/s3_clnt.c 2007-03-22 20:23:19.000000000 -0700
+@@ -601,6 +601,20 @@ int ssl3_client_hello(SSL *s)
+ #endif
+ *(p++)=0; /* Add the NULL method */
+
++ /* send client hello extensions if any */
++ if (s->version >= TLS1_VERSION && s->tls_extension)
++ {
++ // set the total extensions length
++ s2n(s->tls_extension->length + 4, p);
++
++ // put the extensions with type and length
++ s2n(s->tls_extension->type, p);
++ s2n(s->tls_extension->length, p);
++
++ memcpy(p, s->tls_extension->data, s->tls_extension->length);
++ p+=s->tls_extension->length;
++ }
++
+ l=(p-d);
+ d=buf;
+ *(d++)=SSL3_MT_CLIENT_HELLO;
+@@ -623,7 +637,7 @@ int ssl3_get_server_hello(SSL *s)
+ STACK_OF(SSL_CIPHER) *sk;
+ SSL_CIPHER *c;
+ unsigned char *p,*d;
+- int i,al,ok;
++ int i,al,ok,pre_shared;
+ unsigned int j;
+ long n;
+ #ifndef OPENSSL_NO_COMP
+@@ -690,7 +704,24 @@ int ssl3_get_server_hello(SSL *s)
+ goto f_err;
+ }
+
+- if (j != 0 && j == s->session->session_id_length
++ /* check if we want to resume the session based on external pre-shared secret */
++ pre_shared = 0;
++ if (s->version >= TLS1_VERSION && s->tls_session_secret_cb)
++ {
++ SSL_CIPHER *pref_cipher=NULL;
++ s->session->master_key_length=sizeof(s->session->master_key);
++ if (s->tls_session_secret_cb(s, s->session->master_key, &s->session->master_key_length,
++ NULL, &pref_cipher, s->tls_session_secret_cb_arg))
++ {
++ s->hit=1;
++ s->session->cipher=pref_cipher ? pref_cipher : ssl_get_cipher_by_char(s,p+j);
++ s->session->session_id_length = j;
++ memcpy(s->session->session_id, p, j);
++ pre_shared = 1;
++ }
++ }
++
++ if ((pre_shared || j != 0) && j == s->session->session_id_length
+ && memcmp(p,s->session->session_id,j) == 0)
+ {
+ if(s->sid_ctx_length != s->session->sid_ctx_length
+diff -uprN openssl-0.9.8e.orig/ssl/s3_srvr.c openssl-0.9.8e/ssl/s3_srvr.c
+--- openssl-0.9.8e.orig/ssl/s3_srvr.c 2007-02-07 12:36:40.000000000 -0800
++++ openssl-0.9.8e/ssl/s3_srvr.c 2007-03-22 20:23:19.000000000 -0700
+@@ -945,6 +945,75 @@ int ssl3_get_client_hello(SSL *s)
+ }
+ #endif
+
++ /* Check for TLS client hello extension here */
++ if (p < (d+n) && s->version >= TLS1_VERSION)
++ {
++ if (s->tls_extension_cb)
++ {
++ TLS_EXTENSION tls_ext;
++ unsigned short ext_total_len;
++
++ n2s(p, ext_total_len);
++ n2s(p, tls_ext.type);
++ n2s(p, tls_ext.length);
++
++ // sanity check in TLS extension len
++ if (tls_ext.length > (d+n) - p)
++ {
++ // just cut the lenth to packet border
++ tls_ext.length = (d+n) - p;
++ }
++
++ tls_ext.data = p;
++
++ // returns an alert code or 0
++ al = s->tls_extension_cb(s, &tls_ext, s->tls_extension_cb_arg);
++ if (al != 0)
++ {
++ SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_PEER_ERROR);
++ goto f_err;
++ }
++ }
++ }
++
++ /* Check if we want to use external pre-shared secret for this handshake */
++ /* for not reused session only */
++ if (!s->hit && s->version >= TLS1_VERSION && s->tls_session_secret_cb)
++ {
++ SSL_CIPHER *pref_cipher=NULL;
++
++ s->session->master_key_length=sizeof(s->session->master_key);
++ if(s->tls_session_secret_cb(s, s->session->master_key, &s->session->master_key_length,
++ ciphers, &pref_cipher, s->tls_session_secret_cb_arg))
++ {
++ s->hit=1;
++ s->session->ciphers=ciphers;
++ s->session->verify_result=X509_V_OK;
++
++ ciphers=NULL;
++
++ /* check if some cipher was preferred by call back */
++ pref_cipher=pref_cipher ? pref_cipher : ssl3_choose_cipher(s, s->session->ciphers, SSL_get_ciphers(s));
++ if (pref_cipher == NULL)
++ {
++ al=SSL_AD_HANDSHAKE_FAILURE;
++ SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_SHARED_CIPHER);
++ goto f_err;
++ }
++
++ s->session->cipher=pref_cipher;
++
++ if (s->cipher_list)
++ sk_SSL_CIPHER_free(s->cipher_list);
++
++ if (s->cipher_list_by_id)
++ sk_SSL_CIPHER_free(s->cipher_list_by_id);
++
++ s->cipher_list = sk_SSL_CIPHER_dup(s->session->ciphers);
++ s->cipher_list_by_id = sk_SSL_CIPHER_dup(s->session->ciphers);
++ }
++ }
++
+ /* Given s->session->ciphers and SSL_get_ciphers, we must
+ * pick a cipher */
+
+diff -uprN openssl-0.9.8e.orig/ssl/ssl.h openssl-0.9.8e/ssl/ssl.h
+--- openssl-0.9.8e.orig/ssl/ssl.h 2007-02-19 09:55:07.000000000 -0800
++++ openssl-0.9.8e/ssl/ssl.h 2007-03-22 20:23:19.000000000 -0700
+@@ -345,6 +345,7 @@ extern "C" {
+ * 'struct ssl_st *' function parameters used to prototype callbacks
+ * in SSL_CTX. */
+ typedef struct ssl_st *ssl_crock_st;
++typedef struct tls_extension_st TLS_EXTENSION;
+
+ /* used to hold info on the particular ciphers used */
+ typedef struct ssl_cipher_st
+@@ -366,6 +367,8 @@ DECLARE_STACK_OF(SSL_CIPHER)
+ typedef struct ssl_st SSL;
+ typedef struct ssl_ctx_st SSL_CTX;
+
++typedef int (*tls_session_secret_cb_fn)(SSL *s, void *secret, int *secret_len, STACK_OF(SSL_CIPHER) *peer_ciphers, SSL_CIPHER **cipher, void *arg);
++
+ /* Used to hold functions for SSLv2 or SSLv3/TLSv1 functions */
+ typedef struct ssl_method_st
+ {
+@@ -973,6 +976,15 @@ struct ssl_st
+ int first_packet;
+ int client_version; /* what was passed, used for
+ * SSLv3/TLS rollback check */
++
++ /* TLS externsions */
++ TLS_EXTENSION *tls_extension;
++ int (*tls_extension_cb)(SSL *s, TLS_EXTENSION *tls_ext, void *arg);
++ void *tls_extension_cb_arg;
++
++ /* TLS pre-shared secret session resumption */
++ tls_session_secret_cb_fn tls_session_secret_cb;
++ void *tls_session_secret_cb_arg;
+ };
+
+ #ifdef __cplusplus
+@@ -1538,6 +1550,13 @@ void *SSL_COMP_get_compression_methods(v
+ int SSL_COMP_add_compression_method(int id,void *cm);
+ #endif
+
++/* TLS extensions functions */
++int SSL_set_hello_extension(SSL *s, int ext_type, void *ext_data, int ext_len);
++int SSL_set_hello_extension_cb(SSL *s, int (*cb)(SSL *, TLS_EXTENSION *, void *), void *arg);
++
++/* Pre-shared secret session resumption functions */
++int SSL_set_session_secret_cb(SSL *s, tls_session_secret_cb_fn tls_session_secret_cb, void *arg);
++
+ /* BEGIN ERROR CODES */
+ /* The following lines are auto generated by the script mkerr.pl. Any changes
+ * made after this point may be overwritten when the script is next run.
+@@ -1719,6 +1738,7 @@ void ERR_load_SSL_strings(void);
+ #define SSL_F_TLS1_ENC 210
+ #define SSL_F_TLS1_SETUP_KEY_BLOCK 211
+ #define SSL_F_WRITE_PENDING 212
++#define SSL_F_SSL_SET_HELLO_EXTENSION 213
+
+ /* Reason codes. */
+ #define SSL_R_APP_DATA_IN_HANDSHAKE 100
+diff -uprN openssl-0.9.8e.orig/ssl/ssl_err.c openssl-0.9.8e/ssl/ssl_err.c
+--- openssl-0.9.8e.orig/ssl/ssl_err.c 2006-11-21 12:14:46.000000000 -0800
++++ openssl-0.9.8e/ssl/ssl_err.c 2007-03-22 20:23:19.000000000 -0700
+@@ -242,6 +242,7 @@ static ERR_STRING_DATA SSL_str_functs[]=
+ {ERR_FUNC(SSL_F_TLS1_ENC), "TLS1_ENC"},
+ {ERR_FUNC(SSL_F_TLS1_SETUP_KEY_BLOCK), "TLS1_SETUP_KEY_BLOCK"},
+ {ERR_FUNC(SSL_F_WRITE_PENDING), "WRITE_PENDING"},
++{ERR_FUNC(SSL_F_SSL_SET_HELLO_EXTENSION), "SSL_set_hello_extension"},
+ {0,NULL}
+ };
+
+diff -uprN openssl-0.9.8e.orig/ssl/ssl_sess.c openssl-0.9.8e/ssl/ssl_sess.c
+--- openssl-0.9.8e.orig/ssl/ssl_sess.c 2007-02-10 02:40:24.000000000 -0800
++++ openssl-0.9.8e/ssl/ssl_sess.c 2007-03-22 20:23:19.000000000 -0700
+@@ -656,6 +656,15 @@ long SSL_CTX_get_timeout(const SSL_CTX *
+ return(s->session_timeout);
+ }
+
++int SSL_set_session_secret_cb(SSL *s, int (*tls_session_secret_cb)(SSL *s, void *secret, int *secret_len,
++ STACK_OF(SSL_CIPHER) *peer_ciphers, SSL_CIPHER **cipher, void *arg), void *arg)
++{
++ if (s == NULL) return(0);
++ s->tls_session_secret_cb = tls_session_secret_cb;
++ s->tls_session_secret_cb_arg = arg;
++ return(1);
++}
++
+ typedef struct timeout_param_st
+ {
+ SSL_CTX *ctx;
+diff -uprN openssl-0.9.8e.orig/ssl/t1_ext.c openssl-0.9.8e/ssl/t1_ext.c
+--- openssl-0.9.8e.orig/ssl/t1_ext.c 1969-12-31 16:00:00.000000000 -0800
++++ openssl-0.9.8e/ssl/t1_ext.c 2007-03-22 20:23:19.000000000 -0700
+@@ -0,0 +1,48 @@
++
++#include <stdio.h>
++#include "ssl_locl.h"
++
++
++int SSL_set_hello_extension(SSL *s, int ext_type, void *ext_data, int ext_len)
++{
++ if(s->version >= TLS1_VERSION)
++ {
++ if(s->tls_extension)
++ {
++ OPENSSL_free(s->tls_extension);
++ s->tls_extension = NULL;
++ }
++
++ if(ext_data)
++ {
++ s->tls_extension = OPENSSL_malloc(sizeof(TLS_EXTENSION) + ext_len);
++ if(!s->tls_extension)
++ {
++ SSLerr(SSL_F_SSL_SET_HELLO_EXTENSION, ERR_R_MALLOC_FAILURE);
++ return 0;
++ }
++
++ s->tls_extension->type = ext_type;
++ s->tls_extension->length = ext_len;
++ s->tls_extension->data = s->tls_extension + 1;
++ memcpy(s->tls_extension->data, ext_data, ext_len);
++ }
++
++ return 1;
++ }
++
++ return 0;
++}
++
++int SSL_set_hello_extension_cb(SSL *s, int (*cb)(SSL *, TLS_EXTENSION *, void *), void *arg)
++{
++ if(s->version >= TLS1_VERSION)
++ {
++ s->tls_extension_cb = cb;
++ s->tls_extension_cb_arg = arg;
++
++ return 1;
++ }
++
++ return 0;
++}
+diff -uprN openssl-0.9.8e.orig/ssl/t1_lib.c openssl-0.9.8e/ssl/t1_lib.c
+--- openssl-0.9.8e.orig/ssl/t1_lib.c 2007-01-21 08:07:25.000000000 -0800
++++ openssl-0.9.8e/ssl/t1_lib.c 2007-03-22 20:23:19.000000000 -0700
+@@ -97,6 +97,10 @@ int tls1_new(SSL *s)
+
+ void tls1_free(SSL *s)
+ {
++ if(s->tls_extension)
++ {
++ OPENSSL_free(s->tls_extension);
++ }
+ ssl3_free(s);
+ }
+
+diff -uprN openssl-0.9.8e.orig/ssl/tls1.h openssl-0.9.8e/ssl/tls1.h
+--- openssl-0.9.8e.orig/ssl/tls1.h 2006-06-14 10:52:01.000000000 -0700
++++ openssl-0.9.8e/ssl/tls1.h 2007-03-22 20:23:19.000000000 -0700
+@@ -296,6 +296,14 @@ extern "C" {
+ #define TLS_MD_MASTER_SECRET_CONST "\x6d\x61\x73\x74\x65\x72\x20\x73\x65\x63\x72\x65\x74" /*master secret*/
+ #endif
+
++/* TLS extension struct */
++struct tls_extension_st
++{
++ unsigned short type;
++ unsigned short length;
++ void *data;
++};
++
+ #ifdef __cplusplus
+ }
+ #endif
+diff -uprN openssl-0.9.8e.orig/util/ssleay.num openssl-0.9.8e/util/ssleay.num
+--- openssl-0.9.8e.orig/util/ssleay.num 2006-11-30 05:04:43.000000000 -0800
++++ openssl-0.9.8e/util/ssleay.num 2007-03-22 20:24:07.000000000 -0700
+@@ -238,3 +238,6 @@ SSL_CTX_set_info_callback
+ SSL_CTX_sess_get_new_cb 287 EXIST::FUNCTION:
+ SSL_CTX_get_client_cert_cb 288 EXIST::FUNCTION:
+ SSL_CTX_sess_get_remove_cb 289 EXIST::FUNCTION:
++SSL_set_hello_extension 290 EXIST::FUNCTION:
++SSL_set_hello_extension_cb 291 EXIST::FUNCTION:
++SSL_set_session_secret_cb 292 EXIST::FUNCTION:
diff --git a/contrib/wpa/patches/openssl-0.9.8g-tls-extensions.patch b/contrib/wpa/patches/openssl-0.9.8g-tls-extensions.patch
new file mode 100644
index 0000000..8ccbfaa
--- /dev/null
+++ b/contrib/wpa/patches/openssl-0.9.8g-tls-extensions.patch
@@ -0,0 +1,330 @@
+This patch adds support for TLS SessionTicket extension (RFC 5077) for
+the parts used by EAP-FAST (RFC 4851).
+
+This is based on the patch from Alexey Kobozev <akobozev@cisco.com>
+(sent to openssl-dev mailing list on Tue, 07 Jun 2005 15:40:58 +0300).
+
+OpenSSL 0.9.8g does not enable TLS extension support by default, so it
+will need to be enabled by adding enable-tlsext to config script
+command line.
+
+
+diff -upr openssl-0.9.8g.orig/ssl/s3_clnt.c openssl-0.9.8g/ssl/s3_clnt.c
+--- openssl-0.9.8g.orig/ssl/s3_clnt.c 2007-08-31 03:28:51.000000000 +0300
++++ openssl-0.9.8g/ssl/s3_clnt.c 2008-04-15 17:11:46.000000000 +0300
+@@ -727,6 +727,20 @@ int ssl3_get_server_hello(SSL *s)
+ goto f_err;
+ }
+
++#ifndef OPENSSL_NO_TLSEXT
++ /* check if we want to resume the session based on external pre-shared secret */
++ if (s->version >= TLS1_VERSION && s->tls_session_secret_cb)
++ {
++ SSL_CIPHER *pref_cipher=NULL;
++ s->session->master_key_length=sizeof(s->session->master_key);
++ if (s->tls_session_secret_cb(s, s->session->master_key, &s->session->master_key_length,
++ NULL, &pref_cipher, s->tls_session_secret_cb_arg))
++ {
++ s->session->cipher=pref_cipher ? pref_cipher : ssl_get_cipher_by_char(s,p+j);
++ }
++ }
++#endif /* OPENSSL_NO_TLSEXT */
++
+ if (j != 0 && j == s->session->session_id_length
+ && memcmp(p,s->session->session_id,j) == 0)
+ {
+diff -upr openssl-0.9.8g.orig/ssl/s3_srvr.c openssl-0.9.8g/ssl/s3_srvr.c
+--- openssl-0.9.8g.orig/ssl/s3_srvr.c 2007-09-30 21:55:59.000000000 +0300
++++ openssl-0.9.8g/ssl/s3_srvr.c 2008-04-15 17:10:37.000000000 +0300
+@@ -928,6 +928,59 @@ int ssl3_get_client_hello(SSL *s)
+ SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_CLIENTHELLO_TLSEXT);
+ goto err;
+ }
++
++ /* Check if we want to use external pre-shared secret for this
++ * handshake for not reused session only. We need to generate
++ * server_random before calling tls_session_secret_cb in order to allow
++ * SessionTicket processing to use it in key derivation. */
++ {
++ unsigned long Time;
++ unsigned char *pos;
++ Time=(unsigned long)time(NULL); /* Time */
++ pos=s->s3->server_random;
++ l2n(Time,pos);
++ if (RAND_pseudo_bytes(pos,SSL3_RANDOM_SIZE-4) <= 0)
++ {
++ al=SSL_AD_INTERNAL_ERROR;
++ goto f_err;
++ }
++ }
++
++ if (!s->hit && s->version >= TLS1_VERSION && s->tls_session_secret_cb)
++ {
++ SSL_CIPHER *pref_cipher=NULL;
++
++ s->session->master_key_length=sizeof(s->session->master_key);
++ if(s->tls_session_secret_cb(s, s->session->master_key, &s->session->master_key_length,
++ ciphers, &pref_cipher, s->tls_session_secret_cb_arg))
++ {
++ s->hit=1;
++ s->session->ciphers=ciphers;
++ s->session->verify_result=X509_V_OK;
++
++ ciphers=NULL;
++
++ /* check if some cipher was preferred by call back */
++ pref_cipher=pref_cipher ? pref_cipher : ssl3_choose_cipher(s, s->session->ciphers, SSL_get_ciphers(s));
++ if (pref_cipher == NULL)
++ {
++ al=SSL_AD_HANDSHAKE_FAILURE;
++ SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_SHARED_CIPHER);
++ goto f_err;
++ }
++
++ s->session->cipher=pref_cipher;
++
++ if (s->cipher_list)
++ sk_SSL_CIPHER_free(s->cipher_list);
++
++ if (s->cipher_list_by_id)
++ sk_SSL_CIPHER_free(s->cipher_list_by_id);
++
++ s->cipher_list = sk_SSL_CIPHER_dup(s->session->ciphers);
++ s->cipher_list_by_id = sk_SSL_CIPHER_dup(s->session->ciphers);
++ }
++ }
+ #endif
+ /* Worst case, we will use the NULL compression, but if we have other
+ * options, we will now look for them. We have i-1 compression
+@@ -1066,16 +1119,22 @@ int ssl3_send_server_hello(SSL *s)
+ unsigned char *buf;
+ unsigned char *p,*d;
+ int i,sl;
+- unsigned long l,Time;
++ unsigned long l;
++#ifdef OPENSSL_NO_TLSEXT
++ unsigned long Time;
++#endif
+
+ if (s->state == SSL3_ST_SW_SRVR_HELLO_A)
+ {
+ buf=(unsigned char *)s->init_buf->data;
++#ifdef OPENSSL_NO_TLSEXT
+ p=s->s3->server_random;
++ /* Generate server_random if it was not needed previously */
+ Time=(unsigned long)time(NULL); /* Time */
+ l2n(Time,p);
+ if (RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-4) <= 0)
+ return -1;
++#endif
+ /* Do the message type and length last */
+ d=p= &(buf[4]);
+
+diff -upr openssl-0.9.8g.orig/ssl/ssl.h openssl-0.9.8g/ssl/ssl.h
+--- openssl-0.9.8g.orig/ssl/ssl.h 2007-10-19 10:42:38.000000000 +0300
++++ openssl-0.9.8g/ssl/ssl.h 2008-04-15 17:10:37.000000000 +0300
+@@ -342,6 +342,7 @@ extern "C" {
+ * 'struct ssl_st *' function parameters used to prototype callbacks
+ * in SSL_CTX. */
+ typedef struct ssl_st *ssl_crock_st;
++typedef struct tls_extension_st TLS_EXTENSION;
+
+ /* used to hold info on the particular ciphers used */
+ typedef struct ssl_cipher_st
+@@ -363,6 +364,8 @@ DECLARE_STACK_OF(SSL_CIPHER)
+ typedef struct ssl_st SSL;
+ typedef struct ssl_ctx_st SSL_CTX;
+
++typedef int (*tls_session_secret_cb_fn)(SSL *s, void *secret, int *secret_len, STACK_OF(SSL_CIPHER) *peer_ciphers, SSL_CIPHER **cipher, void *arg);
++
+ /* Used to hold functions for SSLv2 or SSLv3/TLSv1 functions */
+ typedef struct ssl_method_st
+ {
+@@ -1004,6 +1007,14 @@ struct ssl_st
+ */
+ /* RFC4507 session ticket expected to be received or sent */
+ int tlsext_ticket_expected;
++
++ /* TLS extensions */
++ TLS_EXTENSION *tls_extension;
++
++ /* TLS pre-shared secret session resumption */
++ tls_session_secret_cb_fn tls_session_secret_cb;
++ void *tls_session_secret_cb_arg;
++
+ SSL_CTX * initial_ctx; /* initial ctx, used to store sessions */
+ #define session_ctx initial_ctx
+ #else
+@@ -1589,6 +1600,12 @@ void *SSL_COMP_get_compression_methods(v
+ int SSL_COMP_add_compression_method(int id,void *cm);
+ #endif
+
++/* TLS extensions functions */
++int SSL_set_hello_extension(SSL *s, int ext_type, void *ext_data, int ext_len);
++
++/* Pre-shared secret session resumption functions */
++int SSL_set_session_secret_cb(SSL *s, tls_session_secret_cb_fn tls_session_secret_cb, void *arg);
++
+ /* BEGIN ERROR CODES */
+ /* The following lines are auto generated by the script mkerr.pl. Any changes
+ * made after this point may be overwritten when the script is next run.
+@@ -1778,6 +1795,7 @@ void ERR_load_SSL_strings(void);
+ #define SSL_F_TLS1_ENC 210
+ #define SSL_F_TLS1_SETUP_KEY_BLOCK 211
+ #define SSL_F_WRITE_PENDING 212
++#define SSL_F_SSL_SET_HELLO_EXTENSION 213
+
+ /* Reason codes. */
+ #define SSL_R_APP_DATA_IN_HANDSHAKE 100
+diff -upr openssl-0.9.8g.orig/ssl/ssl_err.c openssl-0.9.8g/ssl/ssl_err.c
+--- openssl-0.9.8g.orig/ssl/ssl_err.c 2007-10-11 17:36:59.000000000 +0300
++++ openssl-0.9.8g/ssl/ssl_err.c 2008-04-15 17:10:37.000000000 +0300
+@@ -250,6 +250,7 @@ static ERR_STRING_DATA SSL_str_functs[]=
+ {ERR_FUNC(SSL_F_TLS1_ENC), "TLS1_ENC"},
+ {ERR_FUNC(SSL_F_TLS1_SETUP_KEY_BLOCK), "TLS1_SETUP_KEY_BLOCK"},
+ {ERR_FUNC(SSL_F_WRITE_PENDING), "WRITE_PENDING"},
++{ERR_FUNC(SSL_F_SSL_SET_HELLO_EXTENSION), "SSL_set_hello_extension"},
+ {0,NULL}
+ };
+
+diff -upr openssl-0.9.8g.orig/ssl/ssl_sess.c openssl-0.9.8g/ssl/ssl_sess.c
+--- openssl-0.9.8g.orig/ssl/ssl_sess.c 2007-10-19 10:36:34.000000000 +0300
++++ openssl-0.9.8g/ssl/ssl_sess.c 2008-04-15 17:10:37.000000000 +0300
+@@ -704,6 +704,52 @@ long SSL_CTX_get_timeout(const SSL_CTX *
+ return(s->session_timeout);
+ }
+
++#ifndef OPENSSL_NO_TLSEXT
++int SSL_set_session_secret_cb(SSL *s, int (*tls_session_secret_cb)(SSL *s, void *secret, int *secret_len,
++ STACK_OF(SSL_CIPHER) *peer_ciphers, SSL_CIPHER **cipher, void *arg), void *arg)
++{
++ if (s == NULL) return(0);
++ s->tls_session_secret_cb = tls_session_secret_cb;
++ s->tls_session_secret_cb_arg = arg;
++ return(1);
++}
++
++int SSL_set_hello_extension(SSL *s, int ext_type, void *ext_data, int ext_len)
++{
++ if(s->version >= TLS1_VERSION)
++ {
++ if(s->tls_extension)
++ {
++ OPENSSL_free(s->tls_extension);
++ s->tls_extension = NULL;
++ }
++
++ s->tls_extension = OPENSSL_malloc(sizeof(TLS_EXTENSION) + ext_len);
++ if(!s->tls_extension)
++ {
++ SSLerr(SSL_F_SSL_SET_HELLO_EXTENSION, ERR_R_MALLOC_FAILURE);
++ return 0;
++ }
++
++ s->tls_extension->type = ext_type;
++
++ if(ext_data)
++ {
++ s->tls_extension->length = ext_len;
++ s->tls_extension->data = s->tls_extension + 1;
++ memcpy(s->tls_extension->data, ext_data, ext_len);
++ } else {
++ s->tls_extension->length = 0;
++ s->tls_extension->data = NULL;
++ }
++
++ return 1;
++ }
++
++ return 0;
++}
++#endif /* OPENSSL_NO_TLSEXT */
++
+ typedef struct timeout_param_st
+ {
+ SSL_CTX *ctx;
+diff -upr openssl-0.9.8g.orig/ssl/t1_lib.c openssl-0.9.8g/ssl/t1_lib.c
+--- openssl-0.9.8g.orig/ssl/t1_lib.c 2007-10-19 10:44:10.000000000 +0300
++++ openssl-0.9.8g/ssl/t1_lib.c 2008-04-15 17:10:37.000000000 +0300
+@@ -105,6 +105,12 @@ int tls1_new(SSL *s)
+
+ void tls1_free(SSL *s)
+ {
++#ifndef OPENSSL_NO_TLSEXT
++ if(s->tls_extension)
++ {
++ OPENSSL_free(s->tls_extension);
++ }
++#endif
+ ssl3_free(s);
+ }
+
+@@ -174,8 +180,24 @@ unsigned char *ssl_add_clienthello_tlsex
+ int ticklen;
+ if (s->session && s->session->tlsext_tick)
+ ticklen = s->session->tlsext_ticklen;
++ else if (s->session && s->tls_extension &&
++ s->tls_extension->type == TLSEXT_TYPE_session_ticket &&
++ s->tls_extension->data)
++ {
++ ticklen = s->tls_extension->length;
++ s->session->tlsext_tick = OPENSSL_malloc(ticklen);
++ if (!s->session->tlsext_tick)
++ return NULL;
++ memcpy(s->session->tlsext_tick, s->tls_extension->data,
++ ticklen);
++ s->session->tlsext_ticklen = ticklen;
++ }
+ else
+ ticklen = 0;
++ if (ticklen == 0 && s->tls_extension &&
++ s->tls_extension->type == TLSEXT_TYPE_session_ticket &&
++ s->tls_extension->data == NULL)
++ goto skip_ext;
+ /* Check for enough room 2 for extension type, 2 for len
+ * rest for ticket
+ */
+@@ -189,6 +211,7 @@ unsigned char *ssl_add_clienthello_tlsex
+ ret += ticklen;
+ }
+ }
++ skip_ext:
+
+ if ((extdatalen = ret-p-2)== 0)
+ return p;
+@@ -543,6 +566,8 @@ int tls1_process_ticket(SSL *s, unsigned
+ s->tlsext_ticket_expected = 1;
+ return 0; /* Cache miss */
+ }
++ if (s->tls_session_secret_cb)
++ return 0;
+ return tls_decrypt_ticket(s, p, size, session_id, len,
+ ret);
+ }
+diff -upr openssl-0.9.8g.orig/ssl/tls1.h openssl-0.9.8g/ssl/tls1.h
+--- openssl-0.9.8g.orig/ssl/tls1.h 2007-08-28 04:12:44.000000000 +0300
++++ openssl-0.9.8g/ssl/tls1.h 2008-04-15 17:10:37.000000000 +0300
+@@ -365,6 +365,14 @@ SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TLSEXT_SER
+ #define TLS_MD_MASTER_SECRET_CONST "\x6d\x61\x73\x74\x65\x72\x20\x73\x65\x63\x72\x65\x74" /*master secret*/
+ #endif
+
++/* TLS extension struct */
++struct tls_extension_st
++{
++ unsigned short type;
++ unsigned short length;
++ void *data;
++};
++
+ #ifdef __cplusplus
+ }
+ #endif
+diff -upr openssl-0.9.8g.orig/util/ssleay.num openssl-0.9.8g/util/ssleay.num
+--- openssl-0.9.8g.orig/util/ssleay.num 2007-08-13 01:31:16.000000000 +0300
++++ openssl-0.9.8g/util/ssleay.num 2008-04-15 17:10:37.000000000 +0300
+@@ -241,3 +241,5 @@ SSL_CTX_sess_get_remove_cb
+ SSL_set_SSL_CTX 290 EXIST::FUNCTION:
+ SSL_get_servername 291 EXIST::FUNCTION:TLSEXT
+ SSL_get_servername_type 292 EXIST::FUNCTION:TLSEXT
++SSL_set_hello_extension 305 EXIST::FUNCTION:TLSEXT
++SSL_set_session_secret_cb 306 EXIST::FUNCTION:TLSEXT
diff --git a/contrib/wpa/patches/openssl-0.9.8h-tls-extensions.patch b/contrib/wpa/patches/openssl-0.9.8h-tls-extensions.patch
new file mode 100644
index 0000000..c68f227
--- /dev/null
+++ b/contrib/wpa/patches/openssl-0.9.8h-tls-extensions.patch
@@ -0,0 +1,344 @@
+This patch adds support for TLS SessionTicket extension (RFC 5077) for
+the parts used by EAP-FAST (RFC 4851).
+
+This is based on the patch from Alexey Kobozev <akobozev@cisco.com>
+(sent to openssl-dev mailing list on Tue, 07 Jun 2005 15:40:58 +0300).
+
+OpenSSL 0.9.8h does not enable TLS extension support by default, so it
+will need to be enabled by adding enable-tlsext to config script
+command line.
+
+
+diff -upr openssl-0.9.8h.orig/ssl/s3_clnt.c openssl-0.9.8h/ssl/s3_clnt.c
+--- openssl-0.9.8h.orig/ssl/s3_clnt.c 2008-05-28 10:29:27.000000000 +0300
++++ openssl-0.9.8h/ssl/s3_clnt.c 2008-05-29 10:44:25.000000000 +0300
+@@ -752,6 +752,20 @@ int ssl3_get_server_hello(SSL *s)
+ goto f_err;
+ }
+
++#ifndef OPENSSL_NO_TLSEXT
++ /* check if we want to resume the session based on external pre-shared secret */
++ if (s->version >= TLS1_VERSION && s->tls_session_secret_cb)
++ {
++ SSL_CIPHER *pref_cipher=NULL;
++ s->session->master_key_length=sizeof(s->session->master_key);
++ if (s->tls_session_secret_cb(s, s->session->master_key, &s->session->master_key_length,
++ NULL, &pref_cipher, s->tls_session_secret_cb_arg))
++ {
++ s->session->cipher=pref_cipher ? pref_cipher : ssl_get_cipher_by_char(s,p+j);
++ }
++ }
++#endif /* OPENSSL_NO_TLSEXT */
++
+ if (j != 0 && j == s->session->session_id_length
+ && memcmp(p,s->session->session_id,j) == 0)
+ {
+@@ -2693,11 +2707,8 @@ static int ssl3_check_finished(SSL *s)
+ {
+ int ok;
+ long n;
+- /* If we have no ticket or session ID is non-zero length (a match of
+- * a non-zero session length would never reach here) it cannot be a
+- * resumed session.
+- */
+- if (!s->session->tlsext_tick || s->session->session_id_length)
++ /* If we have no ticket it cannot be a resumed session. */
++ if (!s->session->tlsext_tick)
+ return 1;
+ /* this function is called when we really expect a Certificate
+ * message, so permit appropriate message length */
+diff -upr openssl-0.9.8h.orig/ssl/s3_srvr.c openssl-0.9.8h/ssl/s3_srvr.c
+--- openssl-0.9.8h.orig/ssl/s3_srvr.c 2008-04-30 19:11:32.000000000 +0300
++++ openssl-0.9.8h/ssl/s3_srvr.c 2008-05-28 18:49:34.000000000 +0300
+@@ -959,6 +959,59 @@ int ssl3_get_client_hello(SSL *s)
+ SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_CLIENTHELLO_TLSEXT);
+ goto err;
+ }
++
++ /* Check if we want to use external pre-shared secret for this
++ * handshake for not reused session only. We need to generate
++ * server_random before calling tls_session_secret_cb in order to allow
++ * SessionTicket processing to use it in key derivation. */
++ {
++ unsigned long Time;
++ unsigned char *pos;
++ Time=(unsigned long)time(NULL); /* Time */
++ pos=s->s3->server_random;
++ l2n(Time,pos);
++ if (RAND_pseudo_bytes(pos,SSL3_RANDOM_SIZE-4) <= 0)
++ {
++ al=SSL_AD_INTERNAL_ERROR;
++ goto f_err;
++ }
++ }
++
++ if (!s->hit && s->version >= TLS1_VERSION && s->tls_session_secret_cb)
++ {
++ SSL_CIPHER *pref_cipher=NULL;
++
++ s->session->master_key_length=sizeof(s->session->master_key);
++ if(s->tls_session_secret_cb(s, s->session->master_key, &s->session->master_key_length,
++ ciphers, &pref_cipher, s->tls_session_secret_cb_arg))
++ {
++ s->hit=1;
++ s->session->ciphers=ciphers;
++ s->session->verify_result=X509_V_OK;
++
++ ciphers=NULL;
++
++ /* check if some cipher was preferred by call back */
++ pref_cipher=pref_cipher ? pref_cipher : ssl3_choose_cipher(s, s->session->ciphers, SSL_get_ciphers(s));
++ if (pref_cipher == NULL)
++ {
++ al=SSL_AD_HANDSHAKE_FAILURE;
++ SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_SHARED_CIPHER);
++ goto f_err;
++ }
++
++ s->session->cipher=pref_cipher;
++
++ if (s->cipher_list)
++ sk_SSL_CIPHER_free(s->cipher_list);
++
++ if (s->cipher_list_by_id)
++ sk_SSL_CIPHER_free(s->cipher_list_by_id);
++
++ s->cipher_list = sk_SSL_CIPHER_dup(s->session->ciphers);
++ s->cipher_list_by_id = sk_SSL_CIPHER_dup(s->session->ciphers);
++ }
++ }
+ #endif
+ /* Worst case, we will use the NULL compression, but if we have other
+ * options, we will now look for them. We have i-1 compression
+@@ -1097,16 +1150,22 @@ int ssl3_send_server_hello(SSL *s)
+ unsigned char *buf;
+ unsigned char *p,*d;
+ int i,sl;
+- unsigned long l,Time;
++ unsigned long l;
++#ifdef OPENSSL_NO_TLSEXT
++ unsigned long Time;
++#endif
+
+ if (s->state == SSL3_ST_SW_SRVR_HELLO_A)
+ {
+ buf=(unsigned char *)s->init_buf->data;
++#ifdef OPENSSL_NO_TLSEXT
+ p=s->s3->server_random;
++ /* Generate server_random if it was not needed previously */
+ Time=(unsigned long)time(NULL); /* Time */
+ l2n(Time,p);
+ if (RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-4) <= 0)
+ return -1;
++#endif
+ /* Do the message type and length last */
+ d=p= &(buf[4]);
+
+diff -upr openssl-0.9.8h.orig/ssl/ssl.h openssl-0.9.8h/ssl/ssl.h
+--- openssl-0.9.8h.orig/ssl/ssl.h 2008-04-30 19:11:32.000000000 +0300
++++ openssl-0.9.8h/ssl/ssl.h 2008-05-28 18:49:34.000000000 +0300
+@@ -343,6 +343,7 @@ extern "C" {
+ * 'struct ssl_st *' function parameters used to prototype callbacks
+ * in SSL_CTX. */
+ typedef struct ssl_st *ssl_crock_st;
++typedef struct tls_extension_st TLS_EXTENSION;
+
+ /* used to hold info on the particular ciphers used */
+ typedef struct ssl_cipher_st
+@@ -364,6 +365,8 @@ DECLARE_STACK_OF(SSL_CIPHER)
+ typedef struct ssl_st SSL;
+ typedef struct ssl_ctx_st SSL_CTX;
+
++typedef int (*tls_session_secret_cb_fn)(SSL *s, void *secret, int *secret_len, STACK_OF(SSL_CIPHER) *peer_ciphers, SSL_CIPHER **cipher, void *arg);
++
+ /* Used to hold functions for SSLv2 or SSLv3/TLSv1 functions */
+ typedef struct ssl_method_st
+ {
+@@ -1027,6 +1030,14 @@ struct ssl_st
+
+ /* RFC4507 session ticket expected to be received or sent */
+ int tlsext_ticket_expected;
++
++ /* TLS extensions */
++ TLS_EXTENSION *tls_extension;
++
++ /* TLS pre-shared secret session resumption */
++ tls_session_secret_cb_fn tls_session_secret_cb;
++ void *tls_session_secret_cb_arg;
++
+ SSL_CTX * initial_ctx; /* initial ctx, used to store sessions */
+ #define session_ctx initial_ctx
+ #else
+@@ -1625,6 +1636,12 @@ void *SSL_COMP_get_compression_methods(v
+ int SSL_COMP_add_compression_method(int id,void *cm);
+ #endif
+
++/* TLS extensions functions */
++int SSL_set_hello_extension(SSL *s, int ext_type, void *ext_data, int ext_len);
++
++/* Pre-shared secret session resumption functions */
++int SSL_set_session_secret_cb(SSL *s, tls_session_secret_cb_fn tls_session_secret_cb, void *arg);
++
+ /* BEGIN ERROR CODES */
+ /* The following lines are auto generated by the script mkerr.pl. Any changes
+ * made after this point may be overwritten when the script is next run.
+@@ -1815,6 +1832,7 @@ void ERR_load_SSL_strings(void);
+ #define SSL_F_TLS1_ENC 210
+ #define SSL_F_TLS1_SETUP_KEY_BLOCK 211
+ #define SSL_F_WRITE_PENDING 212
++#define SSL_F_SSL_SET_HELLO_EXTENSION 213
+
+ /* Reason codes. */
+ #define SSL_R_APP_DATA_IN_HANDSHAKE 100
+diff -upr openssl-0.9.8h.orig/ssl/ssl_err.c openssl-0.9.8h/ssl/ssl_err.c
+--- openssl-0.9.8h.orig/ssl/ssl_err.c 2007-10-12 03:00:30.000000000 +0300
++++ openssl-0.9.8h/ssl/ssl_err.c 2008-05-28 18:49:34.000000000 +0300
+@@ -251,6 +251,7 @@ static ERR_STRING_DATA SSL_str_functs[]=
+ {ERR_FUNC(SSL_F_TLS1_ENC), "TLS1_ENC"},
+ {ERR_FUNC(SSL_F_TLS1_SETUP_KEY_BLOCK), "TLS1_SETUP_KEY_BLOCK"},
+ {ERR_FUNC(SSL_F_WRITE_PENDING), "WRITE_PENDING"},
++{ERR_FUNC(SSL_F_SSL_SET_HELLO_EXTENSION), "SSL_set_hello_extension"},
+ {0,NULL}
+ };
+
+diff -upr openssl-0.9.8h.orig/ssl/ssl_sess.c openssl-0.9.8h/ssl/ssl_sess.c
+--- openssl-0.9.8h.orig/ssl/ssl_sess.c 2007-10-17 20:30:15.000000000 +0300
++++ openssl-0.9.8h/ssl/ssl_sess.c 2008-05-28 18:49:34.000000000 +0300
+@@ -704,6 +704,52 @@ long SSL_CTX_get_timeout(const SSL_CTX *
+ return(s->session_timeout);
+ }
+
++#ifndef OPENSSL_NO_TLSEXT
++int SSL_set_session_secret_cb(SSL *s, int (*tls_session_secret_cb)(SSL *s, void *secret, int *secret_len,
++ STACK_OF(SSL_CIPHER) *peer_ciphers, SSL_CIPHER **cipher, void *arg), void *arg)
++{
++ if (s == NULL) return(0);
++ s->tls_session_secret_cb = tls_session_secret_cb;
++ s->tls_session_secret_cb_arg = arg;
++ return(1);
++}
++
++int SSL_set_hello_extension(SSL *s, int ext_type, void *ext_data, int ext_len)
++{
++ if(s->version >= TLS1_VERSION)
++ {
++ if(s->tls_extension)
++ {
++ OPENSSL_free(s->tls_extension);
++ s->tls_extension = NULL;
++ }
++
++ s->tls_extension = OPENSSL_malloc(sizeof(TLS_EXTENSION) + ext_len);
++ if(!s->tls_extension)
++ {
++ SSLerr(SSL_F_SSL_SET_HELLO_EXTENSION, ERR_R_MALLOC_FAILURE);
++ return 0;
++ }
++
++ s->tls_extension->type = ext_type;
++
++ if(ext_data)
++ {
++ s->tls_extension->length = ext_len;
++ s->tls_extension->data = s->tls_extension + 1;
++ memcpy(s->tls_extension->data, ext_data, ext_len);
++ } else {
++ s->tls_extension->length = 0;
++ s->tls_extension->data = NULL;
++ }
++
++ return 1;
++ }
++
++ return 0;
++}
++#endif /* OPENSSL_NO_TLSEXT */
++
+ typedef struct timeout_param_st
+ {
+ SSL_CTX *ctx;
+diff -upr openssl-0.9.8h.orig/ssl/t1_lib.c openssl-0.9.8h/ssl/t1_lib.c
+--- openssl-0.9.8h.orig/ssl/t1_lib.c 2008-05-28 10:26:33.000000000 +0300
++++ openssl-0.9.8h/ssl/t1_lib.c 2008-05-28 18:49:34.000000000 +0300
+@@ -106,6 +106,12 @@ int tls1_new(SSL *s)
+
+ void tls1_free(SSL *s)
+ {
++#ifndef OPENSSL_NO_TLSEXT
++ if(s->tls_extension)
++ {
++ OPENSSL_free(s->tls_extension);
++ }
++#endif
+ ssl3_free(s);
+ }
+
+@@ -175,8 +181,24 @@ unsigned char *ssl_add_clienthello_tlsex
+ int ticklen;
+ if (s->session && s->session->tlsext_tick)
+ ticklen = s->session->tlsext_ticklen;
++ else if (s->session && s->tls_extension &&
++ s->tls_extension->type == TLSEXT_TYPE_session_ticket &&
++ s->tls_extension->data)
++ {
++ ticklen = s->tls_extension->length;
++ s->session->tlsext_tick = OPENSSL_malloc(ticklen);
++ if (!s->session->tlsext_tick)
++ return NULL;
++ memcpy(s->session->tlsext_tick, s->tls_extension->data,
++ ticklen);
++ s->session->tlsext_ticklen = ticklen;
++ }
+ else
+ ticklen = 0;
++ if (ticklen == 0 && s->tls_extension &&
++ s->tls_extension->type == TLSEXT_TYPE_session_ticket &&
++ s->tls_extension->data == NULL)
++ goto skip_ext;
+ /* Check for enough room 2 for extension type, 2 for len
+ * rest for ticket
+ */
+@@ -190,6 +212,7 @@ unsigned char *ssl_add_clienthello_tlsex
+ ret += ticklen;
+ }
+ }
++ skip_ext:
+
+ if (s->tlsext_status_type == TLSEXT_STATUSTYPE_ocsp)
+ {
+@@ -774,6 +797,8 @@ int tls1_process_ticket(SSL *s, unsigned
+ s->tlsext_ticket_expected = 1;
+ return 0; /* Cache miss */
+ }
++ if (s->tls_session_secret_cb)
++ return 0;
+ return tls_decrypt_ticket(s, p, size, session_id, len,
+ ret);
+ }
+diff -upr openssl-0.9.8h.orig/ssl/tls1.h openssl-0.9.8h/ssl/tls1.h
+--- openssl-0.9.8h.orig/ssl/tls1.h 2008-04-30 19:11:33.000000000 +0300
++++ openssl-0.9.8h/ssl/tls1.h 2008-05-28 18:49:34.000000000 +0300
+@@ -398,6 +398,14 @@ SSL_CTX_callback_ctrl(ssl,SSL_CTRL_SET_T
+ #define TLS_MD_MASTER_SECRET_CONST "\x6d\x61\x73\x74\x65\x72\x20\x73\x65\x63\x72\x65\x74" /*master secret*/
+ #endif
+
++/* TLS extension struct */
++struct tls_extension_st
++{
++ unsigned short type;
++ unsigned short length;
++ void *data;
++};
++
+ #ifdef __cplusplus
+ }
+ #endif
+diff -upr openssl-0.9.8h.orig/util/ssleay.num openssl-0.9.8h/util/ssleay.num
+--- openssl-0.9.8h.orig/util/ssleay.num 2007-08-13 01:31:16.000000000 +0300
++++ openssl-0.9.8h/util/ssleay.num 2008-05-28 18:49:34.000000000 +0300
+@@ -241,3 +241,5 @@ SSL_CTX_sess_get_remove_cb
+ SSL_set_SSL_CTX 290 EXIST::FUNCTION:
+ SSL_get_servername 291 EXIST::FUNCTION:TLSEXT
+ SSL_get_servername_type 292 EXIST::FUNCTION:TLSEXT
++SSL_set_hello_extension 305 EXIST::FUNCTION:TLSEXT
++SSL_set_session_secret_cb 306 EXIST::FUNCTION:TLSEXT
diff --git a/contrib/wpa/patches/openssl-0.9.8i-tls-extensions.patch b/contrib/wpa/patches/openssl-0.9.8i-tls-extensions.patch
new file mode 100644
index 0000000..90bff54
--- /dev/null
+++ b/contrib/wpa/patches/openssl-0.9.8i-tls-extensions.patch
@@ -0,0 +1,404 @@
+This patch adds support for TLS SessionTicket extension (RFC 5077) for
+the parts used by EAP-FAST (RFC 4851).
+
+This is based on the patch from Alexey Kobozev <akobozev@cisco.com>
+(sent to openssl-dev mailing list on Tue, 07 Jun 2005 15:40:58 +0300).
+
+OpenSSL 0.9.8i does not enable TLS extension support by default, so it
+will need to be enabled by adding enable-tlsext to config script
+command line.
+
+
+Index: openssl-0.9.8i/ssl/s3_clnt.c
+===================================================================
+--- openssl-0.9.8i.orig/ssl/s3_clnt.c 2008-06-16 19:56:41.000000000 +0300
++++ openssl-0.9.8i/ssl/s3_clnt.c 2008-11-23 20:39:40.000000000 +0200
+@@ -759,6 +759,21 @@
+ goto f_err;
+ }
+
++#ifndef OPENSSL_NO_TLSEXT
++ /* check if we want to resume the session based on external pre-shared secret */
++ if (s->version >= TLS1_VERSION && s->tls_session_secret_cb)
++ {
++ SSL_CIPHER *pref_cipher=NULL;
++ s->session->master_key_length=sizeof(s->session->master_key);
++ if (s->tls_session_secret_cb(s, s->session->master_key, &s->session->master_key_length,
++ NULL, &pref_cipher, s->tls_session_secret_cb_arg))
++ {
++ s->session->cipher=pref_cipher ?
++ pref_cipher : ssl_get_cipher_by_char(s,p+j);
++ }
++ }
++#endif /* OPENSSL_NO_TLSEXT */
++
+ if (j != 0 && j == s->session->session_id_length
+ && memcmp(p,s->session->session_id,j) == 0)
+ {
+@@ -2701,11 +2716,8 @@
+ {
+ int ok;
+ long n;
+- /* If we have no ticket or session ID is non-zero length (a match of
+- * a non-zero session length would never reach here) it cannot be a
+- * resumed session.
+- */
+- if (!s->session->tlsext_tick || s->session->session_id_length)
++ /* If we have no ticket it cannot be a resumed session. */
++ if (!s->session->tlsext_tick)
+ return 1;
+ /* this function is called when we really expect a Certificate
+ * message, so permit appropriate message length */
+Index: openssl-0.9.8i/ssl/s3_srvr.c
+===================================================================
+--- openssl-0.9.8i.orig/ssl/s3_srvr.c 2008-09-14 21:16:09.000000000 +0300
++++ openssl-0.9.8i/ssl/s3_srvr.c 2008-11-23 20:37:40.000000000 +0200
+@@ -959,6 +959,59 @@
+ SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_CLIENTHELLO_TLSEXT);
+ goto err;
+ }
++
++ /* Check if we want to use external pre-shared secret for this
++ * handshake for not reused session only. We need to generate
++ * server_random before calling tls_session_secret_cb in order to allow
++ * SessionTicket processing to use it in key derivation. */
++ {
++ unsigned long Time;
++ unsigned char *pos;
++ Time=(unsigned long)time(NULL); /* Time */
++ pos=s->s3->server_random;
++ l2n(Time,pos);
++ if (RAND_pseudo_bytes(pos,SSL3_RANDOM_SIZE-4) <= 0)
++ {
++ al=SSL_AD_INTERNAL_ERROR;
++ goto f_err;
++ }
++ }
++
++ if (!s->hit && s->version >= TLS1_VERSION && s->tls_session_secret_cb)
++ {
++ SSL_CIPHER *pref_cipher=NULL;
++
++ s->session->master_key_length=sizeof(s->session->master_key);
++ if(s->tls_session_secret_cb(s, s->session->master_key, &s->session->master_key_length,
++ ciphers, &pref_cipher, s->tls_session_secret_cb_arg))
++ {
++ s->hit=1;
++ s->session->ciphers=ciphers;
++ s->session->verify_result=X509_V_OK;
++
++ ciphers=NULL;
++
++ /* check if some cipher was preferred by call back */
++ pref_cipher=pref_cipher ? pref_cipher : ssl3_choose_cipher(s, s->session->ciphers, SSL_get_ciphers(s));
++ if (pref_cipher == NULL)
++ {
++ al=SSL_AD_HANDSHAKE_FAILURE;
++ SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_SHARED_CIPHER);
++ goto f_err;
++ }
++
++ s->session->cipher=pref_cipher;
++
++ if (s->cipher_list)
++ sk_SSL_CIPHER_free(s->cipher_list);
++
++ if (s->cipher_list_by_id)
++ sk_SSL_CIPHER_free(s->cipher_list_by_id);
++
++ s->cipher_list = sk_SSL_CIPHER_dup(s->session->ciphers);
++ s->cipher_list_by_id = sk_SSL_CIPHER_dup(s->session->ciphers);
++ }
++ }
+ #endif
+ /* Worst case, we will use the NULL compression, but if we have other
+ * options, we will now look for them. We have i-1 compression
+@@ -1097,16 +1150,22 @@
+ unsigned char *buf;
+ unsigned char *p,*d;
+ int i,sl;
+- unsigned long l,Time;
++ unsigned long l;
++#ifdef OPENSSL_NO_TLSEXT
++ unsigned long Time;
++#endif
+
+ if (s->state == SSL3_ST_SW_SRVR_HELLO_A)
+ {
+ buf=(unsigned char *)s->init_buf->data;
++#ifdef OPENSSL_NO_TLSEXT
+ p=s->s3->server_random;
++ /* Generate server_random if it was not needed previously */
+ Time=(unsigned long)time(NULL); /* Time */
+ l2n(Time,p);
+ if (RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-4) <= 0)
+ return -1;
++#endif
+ /* Do the message type and length last */
+ d=p= &(buf[4]);
+
+Index: openssl-0.9.8i/ssl/ssl_err.c
+===================================================================
+--- openssl-0.9.8i.orig/ssl/ssl_err.c 2008-08-13 22:44:44.000000000 +0300
++++ openssl-0.9.8i/ssl/ssl_err.c 2008-11-23 20:33:43.000000000 +0200
+@@ -253,6 +253,7 @@
+ {ERR_FUNC(SSL_F_TLS1_ENC), "TLS1_ENC"},
+ {ERR_FUNC(SSL_F_TLS1_SETUP_KEY_BLOCK), "TLS1_SETUP_KEY_BLOCK"},
+ {ERR_FUNC(SSL_F_WRITE_PENDING), "WRITE_PENDING"},
++{ERR_FUNC(SSL_F_SSL_SET_SESSION_TICKET_EXT), "SSL_set_session_ticket_ext"},
+ {0,NULL}
+ };
+
+Index: openssl-0.9.8i/ssl/ssl.h
+===================================================================
+--- openssl-0.9.8i.orig/ssl/ssl.h 2008-08-13 22:44:44.000000000 +0300
++++ openssl-0.9.8i/ssl/ssl.h 2008-11-23 20:35:41.000000000 +0200
+@@ -344,6 +344,7 @@
+ * 'struct ssl_st *' function parameters used to prototype callbacks
+ * in SSL_CTX. */
+ typedef struct ssl_st *ssl_crock_st;
++typedef struct tls_session_ticket_ext_st TLS_SESSION_TICKET_EXT;
+
+ /* used to hold info on the particular ciphers used */
+ typedef struct ssl_cipher_st
+@@ -362,6 +363,9 @@
+
+ DECLARE_STACK_OF(SSL_CIPHER)
+
++typedef int (*tls_session_ticket_ext_cb_fn)(SSL *s, const unsigned char *data, int len, void *arg);
++typedef int (*tls_session_secret_cb_fn)(SSL *s, void *secret, int *secret_len, STACK_OF(SSL_CIPHER) *peer_ciphers, SSL_CIPHER **cipher, void *arg);
++
+ /* Used to hold functions for SSLv2 or SSLv3/TLSv1 functions */
+ typedef struct ssl_method_st
+ {
+@@ -1034,6 +1038,18 @@
+
+ /* RFC4507 session ticket expected to be received or sent */
+ int tlsext_ticket_expected;
++
++ /* TLS Session Ticket extension override */
++ TLS_SESSION_TICKET_EXT *tlsext_session_ticket;
++
++ /* TLS Session Ticket extension callback */
++ tls_session_ticket_ext_cb_fn tls_session_ticket_ext_cb;
++ void *tls_session_ticket_ext_cb_arg;
++
++ /* TLS pre-shared secret session resumption */
++ tls_session_secret_cb_fn tls_session_secret_cb;
++ void *tls_session_secret_cb_arg;
++
+ SSL_CTX * initial_ctx; /* initial ctx, used to store sessions */
+ #define session_ctx initial_ctx
+ #else
+@@ -1632,6 +1648,15 @@
+ int SSL_COMP_add_compression_method(int id,void *cm);
+ #endif
+
++/* TLS extensions functions */
++int SSL_set_session_ticket_ext(SSL *s, void *ext_data, int ext_len);
++
++int SSL_set_session_ticket_ext_cb(SSL *s, tls_session_ticket_ext_cb_fn cb,
++ void *arg);
++
++/* Pre-shared secret session resumption functions */
++int SSL_set_session_secret_cb(SSL *s, tls_session_secret_cb_fn tls_session_secret_cb, void *arg);
++
+ /* BEGIN ERROR CODES */
+ /* The following lines are auto generated by the script mkerr.pl. Any changes
+ * made after this point may be overwritten when the script is next run.
+@@ -1824,6 +1849,7 @@
+ #define SSL_F_TLS1_ENC 210
+ #define SSL_F_TLS1_SETUP_KEY_BLOCK 211
+ #define SSL_F_WRITE_PENDING 212
++#define SSL_F_SSL_SET_SESSION_TICKET_EXT 213
+
+ /* Reason codes. */
+ #define SSL_R_APP_DATA_IN_HANDSHAKE 100
+Index: openssl-0.9.8i/ssl/ssl_sess.c
+===================================================================
+--- openssl-0.9.8i.orig/ssl/ssl_sess.c 2008-06-04 21:35:27.000000000 +0300
++++ openssl-0.9.8i/ssl/ssl_sess.c 2008-11-23 20:32:24.000000000 +0200
+@@ -707,6 +707,61 @@
+ return(s->session_timeout);
+ }
+
++#ifndef OPENSSL_NO_TLSEXT
++int SSL_set_session_secret_cb(SSL *s, int (*tls_session_secret_cb)(SSL *s, void *secret, int *secret_len,
++ STACK_OF(SSL_CIPHER) *peer_ciphers, SSL_CIPHER **cipher, void *arg), void *arg)
++ {
++ if (s == NULL) return(0);
++ s->tls_session_secret_cb = tls_session_secret_cb;
++ s->tls_session_secret_cb_arg = arg;
++ return(1);
++ }
++
++int SSL_set_session_ticket_ext_cb(SSL *s, tls_session_ticket_ext_cb_fn cb,
++ void *arg)
++ {
++ if (s == NULL) return(0);
++ s->tls_session_ticket_ext_cb = cb;
++ s->tls_session_ticket_ext_cb_arg = arg;
++ return(1);
++ }
++
++int SSL_set_session_ticket_ext(SSL *s, void *ext_data, int ext_len)
++ {
++ if (s->version >= TLS1_VERSION)
++ {
++ if (s->tlsext_session_ticket)
++ {
++ OPENSSL_free(s->tlsext_session_ticket);
++ s->tlsext_session_ticket = NULL;
++ }
++
++ s->tlsext_session_ticket = OPENSSL_malloc(sizeof(TLS_SESSION_TICKET_EXT) + ext_len);
++ if (!s->tlsext_session_ticket)
++ {
++ SSLerr(SSL_F_SSL_SET_SESSION_TICKET_EXT, ERR_R_MALLOC_FAILURE);
++ return 0;
++ }
++
++ if (ext_data)
++ {
++ s->tlsext_session_ticket->length = ext_len;
++ s->tlsext_session_ticket->data = s->tlsext_session_ticket + 1;
++ memcpy(s->tlsext_session_ticket->data, ext_data, ext_len);
++ }
++ else
++ {
++ s->tlsext_session_ticket->length = 0;
++ s->tlsext_session_ticket->data = NULL;
++ }
++
++ return 1;
++ }
++
++ return 0;
++ }
++#endif /* OPENSSL_NO_TLSEXT */
++
+ typedef struct timeout_param_st
+ {
+ SSL_CTX *ctx;
+Index: openssl-0.9.8i/ssl/t1_lib.c
+===================================================================
+--- openssl-0.9.8i.orig/ssl/t1_lib.c 2008-09-04 01:13:04.000000000 +0300
++++ openssl-0.9.8i/ssl/t1_lib.c 2008-11-23 20:31:20.000000000 +0200
+@@ -106,6 +106,12 @@
+
+ void tls1_free(SSL *s)
+ {
++#ifndef OPENSSL_NO_TLSEXT
++ if (s->tlsext_session_ticket)
++ {
++ OPENSSL_free(s->tlsext_session_ticket);
++ }
++#endif
+ ssl3_free(s);
+ }
+
+@@ -175,8 +181,23 @@
+ int ticklen;
+ if (s->session && s->session->tlsext_tick)
+ ticklen = s->session->tlsext_ticklen;
++ else if (s->session && s->tlsext_session_ticket &&
++ s->tlsext_session_ticket->data)
++ {
++ ticklen = s->tlsext_session_ticket->length;
++ s->session->tlsext_tick = OPENSSL_malloc(ticklen);
++ if (!s->session->tlsext_tick)
++ return NULL;
++ memcpy(s->session->tlsext_tick,
++ s->tlsext_session_ticket->data,
++ ticklen);
++ s->session->tlsext_ticklen = ticklen;
++ }
+ else
+ ticklen = 0;
++ if (ticklen == 0 && s->tlsext_session_ticket &&
++ s->tlsext_session_ticket->data == NULL)
++ goto skip_ext;
+ /* Check for enough room 2 for extension type, 2 for len
+ * rest for ticket
+ */
+@@ -190,6 +211,7 @@
+ ret += ticklen;
+ }
+ }
++ skip_ext:
+
+ if (s->tlsext_status_type == TLSEXT_STATUSTYPE_ocsp)
+ {
+@@ -407,6 +429,15 @@
+ }
+
+ }
++ else if (type == TLSEXT_TYPE_session_ticket)
++ {
++ if (s->tls_session_ticket_ext_cb &&
++ !s->tls_session_ticket_ext_cb(s, data, size, s->tls_session_ticket_ext_cb_arg))
++ {
++ *al = TLS1_AD_INTERNAL_ERROR;
++ return 0;
++ }
++ }
+ else if (type == TLSEXT_TYPE_status_request
+ && s->ctx->tlsext_status_cb)
+ {
+@@ -553,6 +584,12 @@
+ }
+ else if (type == TLSEXT_TYPE_session_ticket)
+ {
++ if (s->tls_session_ticket_ext_cb &&
++ !s->tls_session_ticket_ext_cb(s, data, size, s->tls_session_ticket_ext_cb_arg))
++ {
++ *al = TLS1_AD_INTERNAL_ERROR;
++ return 0;
++ }
+ if ((SSL_get_options(s) & SSL_OP_NO_TICKET)
+ || (size > 0))
+ {
+@@ -776,6 +813,15 @@
+ s->tlsext_ticket_expected = 1;
+ return 0; /* Cache miss */
+ }
++ if (s->tls_session_secret_cb)
++ {
++ /* Indicate cache miss here and instead of
++ * generating the session from ticket now,
++ * trigger abbreviated handshake based on
++ * external mechanism to calculate the master
++ * secret later. */
++ return 0;
++ }
+ return tls_decrypt_ticket(s, p, size, session_id, len,
+ ret);
+ }
+Index: openssl-0.9.8i/ssl/tls1.h
+===================================================================
+--- openssl-0.9.8i.orig/ssl/tls1.h 2008-04-30 19:11:33.000000000 +0300
++++ openssl-0.9.8i/ssl/tls1.h 2008-11-23 20:22:38.000000000 +0200
+@@ -398,6 +398,13 @@
+ #define TLS_MD_MASTER_SECRET_CONST "\x6d\x61\x73\x74\x65\x72\x20\x73\x65\x63\x72\x65\x74" /*master secret*/
+ #endif
+
++/* TLS extension struct */
++struct tls_session_ticket_ext_st
++ {
++ unsigned short length;
++ void *data;
++ };
++
+ #ifdef __cplusplus
+ }
+ #endif
+Index: openssl-0.9.8i/util/ssleay.num
+===================================================================
+--- openssl-0.9.8i.orig/util/ssleay.num 2008-06-05 13:57:21.000000000 +0300
++++ openssl-0.9.8i/util/ssleay.num 2008-11-23 20:22:05.000000000 +0200
+@@ -242,3 +242,5 @@
+ SSL_get_servername 291 EXIST::FUNCTION:TLSEXT
+ SSL_get_servername_type 292 EXIST::FUNCTION:TLSEXT
+ SSL_CTX_set_client_cert_engine 293 EXIST::FUNCTION:ENGINE
++SSL_set_session_ticket_ext 306 EXIST::FUNCTION:TLSEXT
++SSL_set_session_secret_cb 307 EXIST::FUNCTION:TLSEXT
diff --git a/contrib/wpa/patches/openssl-0.9.9-session-ticket.patch b/contrib/wpa/patches/openssl-0.9.9-session-ticket.patch
new file mode 100644
index 0000000..3afa639
--- /dev/null
+++ b/contrib/wpa/patches/openssl-0.9.9-session-ticket.patch
@@ -0,0 +1,374 @@
+This patch adds support for TLS SessionTicket extension (RFC 5077) for
+the parts used by EAP-FAST (RFC 4851).
+
+This is based on the patch from Alexey Kobozev <akobozev@cisco.com>
+(sent to openssl-dev mailing list on Tue, 07 Jun 2005 15:40:58 +0300).
+
+NOTE: This patch (without SSL_set_hello_extension() wrapper) was
+merged into the upstream OpenSSL 0.9.9 tree and as such, an external
+patch for EAP-FAST support is not needed anymore.
+
+
+
+Index: openssl-SNAP-20081111/ssl/s3_clnt.c
+===================================================================
+--- openssl-SNAP-20081111.orig/ssl/s3_clnt.c
++++ openssl-SNAP-20081111/ssl/s3_clnt.c
+@@ -788,6 +788,23 @@ int ssl3_get_server_hello(SSL *s)
+ goto f_err;
+ }
+
++#ifndef OPENSSL_NO_TLSEXT
++ /* check if we want to resume the session based on external pre-shared secret */
++ if (s->version >= TLS1_VERSION && s->tls_session_secret_cb)
++ {
++ SSL_CIPHER *pref_cipher=NULL;
++ s->session->master_key_length=sizeof(s->session->master_key);
++ if (s->tls_session_secret_cb(s, s->session->master_key,
++ &s->session->master_key_length,
++ NULL, &pref_cipher,
++ s->tls_session_secret_cb_arg))
++ {
++ s->session->cipher = pref_cipher ?
++ pref_cipher : ssl_get_cipher_by_char(s, p+j);
++ }
++ }
++#endif /* OPENSSL_NO_TLSEXT */
++
+ if (j != 0 && j == s->session->session_id_length
+ && memcmp(p,s->session->session_id,j) == 0)
+ {
+@@ -2927,11 +2944,8 @@ static int ssl3_check_finished(SSL *s)
+ {
+ int ok;
+ long n;
+- /* If we have no ticket or session ID is non-zero length (a match of
+- * a non-zero session length would never reach here) it cannot be a
+- * resumed session.
+- */
+- if (!s->session->tlsext_tick || s->session->session_id_length)
++ /* If we have no ticket it cannot be a resumed session. */
++ if (!s->session->tlsext_tick)
+ return 1;
+ /* this function is called when we really expect a Certificate
+ * message, so permit appropriate message length */
+Index: openssl-SNAP-20081111/ssl/s3_srvr.c
+===================================================================
+--- openssl-SNAP-20081111.orig/ssl/s3_srvr.c
++++ openssl-SNAP-20081111/ssl/s3_srvr.c
+@@ -1010,6 +1010,59 @@ int ssl3_get_client_hello(SSL *s)
+ SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_CLIENTHELLO_TLSEXT);
+ goto err;
+ }
++
++ /* Check if we want to use external pre-shared secret for this
++ * handshake for not reused session only. We need to generate
++ * server_random before calling tls_session_secret_cb in order to allow
++ * SessionTicket processing to use it in key derivation. */
++ {
++ unsigned long Time;
++ unsigned char *pos;
++ Time=(unsigned long)time(NULL); /* Time */
++ pos=s->s3->server_random;
++ l2n(Time,pos);
++ if (RAND_pseudo_bytes(pos,SSL3_RANDOM_SIZE-4) <= 0)
++ {
++ al=SSL_AD_INTERNAL_ERROR;
++ goto f_err;
++ }
++ }
++
++ if (!s->hit && s->version >= TLS1_VERSION && s->tls_session_secret_cb)
++ {
++ SSL_CIPHER *pref_cipher=NULL;
++
++ s->session->master_key_length=sizeof(s->session->master_key);
++ if(s->tls_session_secret_cb(s, s->session->master_key, &s->session->master_key_length,
++ ciphers, &pref_cipher, s->tls_session_secret_cb_arg))
++ {
++ s->hit=1;
++ s->session->ciphers=ciphers;
++ s->session->verify_result=X509_V_OK;
++
++ ciphers=NULL;
++
++ /* check if some cipher was preferred by call back */
++ pref_cipher=pref_cipher ? pref_cipher : ssl3_choose_cipher(s, s->session->ciphers, SSL_get_ciphers(s));
++ if (pref_cipher == NULL)
++ {
++ al=SSL_AD_HANDSHAKE_FAILURE;
++ SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_SHARED_CIPHER);
++ goto f_err;
++ }
++
++ s->session->cipher=pref_cipher;
++
++ if (s->cipher_list)
++ sk_SSL_CIPHER_free(s->cipher_list);
++
++ if (s->cipher_list_by_id)
++ sk_SSL_CIPHER_free(s->cipher_list_by_id);
++
++ s->cipher_list = sk_SSL_CIPHER_dup(s->session->ciphers);
++ s->cipher_list_by_id = sk_SSL_CIPHER_dup(s->session->ciphers);
++ }
++ }
+ #endif
+
+ /* Worst case, we will use the NULL compression, but if we have other
+@@ -1134,16 +1187,22 @@ int ssl3_send_server_hello(SSL *s)
+ unsigned char *buf;
+ unsigned char *p,*d;
+ int i,sl;
+- unsigned long l,Time;
++ unsigned long l;
++#ifdef OPENSSL_NO_TLSEXT
++ unsigned long Time;
++#endif
+
+ if (s->state == SSL3_ST_SW_SRVR_HELLO_A)
+ {
+ buf=(unsigned char *)s->init_buf->data;
++#ifdef OPENSSL_NO_TLSEXT
+ p=s->s3->server_random;
++ /* Generate server_random if it was not needed previously */
+ Time=(unsigned long)time(NULL); /* Time */
+ l2n(Time,p);
+ if (RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-4) <= 0)
+ return -1;
++#endif
+ /* Do the message type and length last */
+ d=p= &(buf[4]);
+
+Index: openssl-SNAP-20081111/ssl/ssl_err.c
+===================================================================
+--- openssl-SNAP-20081111.orig/ssl/ssl_err.c
++++ openssl-SNAP-20081111/ssl/ssl_err.c
+@@ -263,6 +263,7 @@ static ERR_STRING_DATA SSL_str_functs[]=
+ {ERR_FUNC(SSL_F_TLS1_PRF), "tls1_prf"},
+ {ERR_FUNC(SSL_F_TLS1_SETUP_KEY_BLOCK), "TLS1_SETUP_KEY_BLOCK"},
+ {ERR_FUNC(SSL_F_WRITE_PENDING), "WRITE_PENDING"},
++{ERR_FUNC(SSL_F_SSL_SET_SESSION_TICKET_EXT), "SSL_set_session_ticket_ext"},
+ {0,NULL}
+ };
+
+Index: openssl-SNAP-20081111/ssl/ssl.h
+===================================================================
+--- openssl-SNAP-20081111.orig/ssl/ssl.h
++++ openssl-SNAP-20081111/ssl/ssl.h
+@@ -355,6 +355,7 @@ extern "C" {
+ * 'struct ssl_st *' function parameters used to prototype callbacks
+ * in SSL_CTX. */
+ typedef struct ssl_st *ssl_crock_st;
++typedef struct tls_session_ticket_ext_st TLS_SESSION_TICKET_EXT;
+
+ /* used to hold info on the particular ciphers used */
+ typedef struct ssl_cipher_st
+@@ -378,6 +379,8 @@ typedef struct ssl_cipher_st
+
+ DECLARE_STACK_OF(SSL_CIPHER)
+
++typedef int (*tls_session_secret_cb_fn)(SSL *s, void *secret, int *secret_len, STACK_OF(SSL_CIPHER) *peer_ciphers, SSL_CIPHER **cipher, void *arg);
++
+ /* Used to hold functions for SSLv2 or SSLv3/TLSv1 functions */
+ typedef struct ssl_method_st
+ {
+@@ -1145,6 +1148,13 @@ struct ssl_st
+ void *tlsext_opaque_prf_input;
+ size_t tlsext_opaque_prf_input_len;
+
++ /* TLS Session Ticket extension override */
++ TLS_SESSION_TICKET_EXT *tlsext_session_ticket;
++
++ /* TLS pre-shared secret session resumption */
++ tls_session_secret_cb_fn tls_session_secret_cb;
++ void *tls_session_secret_cb_arg;
++
+ SSL_CTX * initial_ctx; /* initial ctx, used to store sessions */
+ #define session_ctx initial_ctx
+ #else
+@@ -1746,6 +1756,16 @@ void *SSL_COMP_get_compression_methods(v
+ int SSL_COMP_add_compression_method(int id,void *cm);
+ #endif
+
++/* NOTE: This function will be removed; it is only here for backwards
++ * compatibility for the API during testing. */
++int SSL_set_hello_extension(SSL *s, int ext_type, void *ext_data, int ext_len);
++
++/* TLS extensions functions */
++int SSL_set_session_ticket_ext(SSL *s, void *ext_data, int ext_len);
++
++/* Pre-shared secret session resumption functions */
++int SSL_set_session_secret_cb(SSL *s, tls_session_secret_cb_fn tls_session_secret_cb, void *arg);
++
+ /* BEGIN ERROR CODES */
+ /* The following lines are auto generated by the script mkerr.pl. Any changes
+ * made after this point may be overwritten when the script is next run.
+@@ -1948,6 +1968,7 @@ void ERR_load_SSL_strings(void);
+ #define SSL_F_TLS1_PRF 284
+ #define SSL_F_TLS1_SETUP_KEY_BLOCK 211
+ #define SSL_F_WRITE_PENDING 212
++#define SSL_F_SSL_SET_SESSION_TICKET_EXT 213
+
+ /* Reason codes. */
+ #define SSL_R_APP_DATA_IN_HANDSHAKE 100
+Index: openssl-SNAP-20081111/ssl/ssl_sess.c
+===================================================================
+--- openssl-SNAP-20081111.orig/ssl/ssl_sess.c
++++ openssl-SNAP-20081111/ssl/ssl_sess.c
+@@ -834,6 +834,62 @@ long SSL_CTX_get_timeout(const SSL_CTX *
+ return(s->session_timeout);
+ }
+
++#ifndef OPENSSL_NO_TLSEXT
++int SSL_set_session_secret_cb(SSL *s, int (*tls_session_secret_cb)(SSL *s, void *secret, int *secret_len,
++ STACK_OF(SSL_CIPHER) *peer_ciphers, SSL_CIPHER **cipher, void *arg), void *arg)
++ {
++ if (s == NULL) return(0);
++ s->tls_session_secret_cb = tls_session_secret_cb;
++ s->tls_session_secret_cb_arg = arg;
++ return(1);
++ }
++
++int SSL_set_session_ticket_ext(SSL *s, void *ext_data, int ext_len)
++ {
++ if (s->version >= TLS1_VERSION)
++ {
++ if (s->tlsext_session_ticket)
++ {
++ OPENSSL_free(s->tlsext_session_ticket);
++ s->tlsext_session_ticket = NULL;
++ }
++
++ s->tlsext_session_ticket = OPENSSL_malloc(sizeof(TLS_SESSION_TICKET_EXT) + ext_len);
++ if (!s->tlsext_session_ticket)
++ {
++ SSLerr(SSL_F_SSL_SET_SESSION_TICKET_EXT, ERR_R_MALLOC_FAILURE);
++ return 0;
++ }
++
++ if (ext_data)
++ {
++ s->tlsext_session_ticket->length = ext_len;
++ s->tlsext_session_ticket->data = s->tlsext_session_ticket + 1;
++ memcpy(s->tlsext_session_ticket->data, ext_data, ext_len);
++ }
++ else
++ {
++ s->tlsext_session_ticket->length = 0;
++ s->tlsext_session_ticket->data = NULL;
++ }
++
++ return 1;
++ }
++
++ return 0;
++ }
++
++/* NOTE: This function will be removed; it is only here for backwards
++ * compatibility for the API during testing. */
++int SSL_set_hello_extension(SSL *s, int ext_type, void *ext_data, int ext_len)
++ {
++ if (ext_type != TLSEXT_TYPE_session_ticket)
++ return 0;
++
++ return SSL_set_session_ticket_ext(s, ext_data, ext_len);
++ }
++#endif /* OPENSSL_NO_TLSEXT */
++
+ typedef struct timeout_param_st
+ {
+ SSL_CTX *ctx;
+Index: openssl-SNAP-20081111/ssl/t1_lib.c
+===================================================================
+--- openssl-SNAP-20081111.orig/ssl/t1_lib.c
++++ openssl-SNAP-20081111/ssl/t1_lib.c
+@@ -154,6 +154,12 @@ int tls1_new(SSL *s)
+
+ void tls1_free(SSL *s)
+ {
++#ifndef OPENSSL_NO_TLSEXT
++ if (s->tlsext_session_ticket)
++ {
++ OPENSSL_free(s->tlsext_session_ticket);
++ }
++#endif /* OPENSSL_NO_TLSEXT */
+ ssl3_free(s);
+ }
+
+@@ -357,8 +363,23 @@ unsigned char *ssl_add_clienthello_tlsex
+ int ticklen;
+ if (s->session && s->session->tlsext_tick)
+ ticklen = s->session->tlsext_ticklen;
++ else if (s->session && s->tlsext_session_ticket &&
++ s->tlsext_session_ticket->data)
++ {
++ ticklen = s->tlsext_session_ticket->length;
++ s->session->tlsext_tick = OPENSSL_malloc(ticklen);
++ if (!s->session->tlsext_tick)
++ return NULL;
++ memcpy(s->session->tlsext_tick,
++ s->tlsext_session_ticket->data,
++ ticklen);
++ s->session->tlsext_ticklen = ticklen;
++ }
+ else
+ ticklen = 0;
++ if (ticklen == 0 && s->tlsext_session_ticket &&
++ s->tlsext_session_ticket->data == NULL)
++ goto skip_ext;
+ /* Check for enough room 2 for extension type, 2 for len
+ * rest for ticket
+ */
+@@ -371,6 +392,7 @@ unsigned char *ssl_add_clienthello_tlsex
+ ret += ticklen;
+ }
+ }
++ skip_ext:
+
+ #ifdef TLSEXT_TYPE_opaque_prf_input
+ if (s->s3->client_opaque_prf_input != NULL)
+@@ -1435,6 +1457,15 @@ int tls1_process_ticket(SSL *s, unsigned
+ s->tlsext_ticket_expected = 1;
+ return 0; /* Cache miss */
+ }
++ if (s->tls_session_secret_cb)
++ {
++ /* Indicate cache miss here and instead of
++ * generating the session from ticket now,
++ * trigger abbreviated handshake based on
++ * external mechanism to calculate the master
++ * secret later. */
++ return 0;
++ }
+ return tls_decrypt_ticket(s, p, size, session_id, len,
+ ret);
+ }
+Index: openssl-SNAP-20081111/ssl/tls1.h
+===================================================================
+--- openssl-SNAP-20081111.orig/ssl/tls1.h
++++ openssl-SNAP-20081111/ssl/tls1.h
+@@ -512,6 +512,13 @@ SSL_CTX_callback_ctrl(ssl,SSL_CTRL_SET_T
+ #define TLS_MD_MASTER_SECRET_CONST "\x6d\x61\x73\x74\x65\x72\x20\x73\x65\x63\x72\x65\x74" /*master secret*/
+ #endif
+
++/* TLS Session Ticket extension struct */
++struct tls_session_ticket_ext_st
++ {
++ unsigned short length;
++ void *data;
++ };
++
+ #ifdef __cplusplus
+ }
+ #endif
+Index: openssl-SNAP-20081111/util/ssleay.num
+===================================================================
+--- openssl-SNAP-20081111.orig/util/ssleay.num
++++ openssl-SNAP-20081111/util/ssleay.num
+@@ -254,3 +254,5 @@ PEM_read_bio_SSL_SESSION
+ SSL_CTX_set_psk_server_callback 303 EXIST::FUNCTION:PSK
+ SSL_get_psk_identity 304 EXIST::FUNCTION:PSK
+ PEM_write_SSL_SESSION 305 EXIST:!WIN16:FUNCTION:
++SSL_set_session_ticket_ext 306 EXIST::FUNCTION:TLSEXT
++SSL_set_session_secret_cb 307 EXIST::FUNCTION:TLSEXT
diff --git a/contrib/wpa/src/Makefile b/contrib/wpa/src/Makefile
index bd1c160..f47da7b 100644
--- a/contrib/wpa/src/Makefile
+++ b/contrib/wpa/src/Makefile
@@ -1,7 +1,7 @@
-SUBDIRS=common crypto drivers hlr_auc_gw eapol_supp eap_common eap_peer eap_server l2_packet radius rsn_supp tls utils wps
+SUBDIRS=ap common crypto drivers eapol_auth eapol_supp eap_common eap_peer eap_server l2_packet radius rsn_supp tls utils wps
all:
- @echo Nothing to be made.
+ for d in $(SUBDIRS); do [ -d $$d ] && $(MAKE) -C $$d; done
clean:
for d in $(SUBDIRS); do [ -d $$d ] && $(MAKE) -C $$d clean; done
diff --git a/contrib/wpa/src/hlr_auc_gw/Makefile b/contrib/wpa/src/ap/Makefile
index cffba62..9c41962 100644
--- a/contrib/wpa/src/hlr_auc_gw/Makefile
+++ b/contrib/wpa/src/ap/Makefile
@@ -2,7 +2,6 @@ all:
@echo Nothing to be made.
clean:
- for d in $(SUBDIRS); do make -C $$d clean; done
rm -f *~ *.o *.d
install:
diff --git a/contrib/wpa/hostapd/accounting.c b/contrib/wpa/src/ap/accounting.c
index ce71678..7939c68 100644
--- a/contrib/wpa/hostapd/accounting.c
+++ b/contrib/wpa/src/ap/accounting.c
@@ -1,6 +1,6 @@
/*
* hostapd / RADIUS Accounting
- * Copyright (c) 2002-2008, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -12,15 +12,18 @@
* See README and COPYING for more details.
*/
-#include "includes.h"
+#include "utils/includes.h"
-#include "hostapd.h"
+#include "utils/common.h"
+#include "utils/eloop.h"
+#include "drivers/driver.h"
#include "radius/radius.h"
#include "radius/radius_client.h"
-#include "eloop.h"
-#include "accounting.h"
+#include "hostapd.h"
#include "ieee802_1x.h"
-#include "driver.h"
+#include "ap_config.h"
+#include "sta_info.h"
+#include "accounting.h"
/* Default interval in seconds for polling TX/RX octets from the driver if
@@ -175,7 +178,6 @@ static struct radius_msg * accounting_msg(struct hostapd_data *hapd,
fail:
radius_msg_free(msg);
- os_free(msg);
return NULL;
}
@@ -184,7 +186,7 @@ static int accounting_sta_update_stats(struct hostapd_data *hapd,
struct sta_info *sta,
struct hostap_sta_driver_data *data)
{
- if (hostapd_read_sta_data(hapd, data, sta->addr))
+ if (hapd->drv.read_sta_data(hapd, data, sta->addr))
return -1;
if (sta->last_rx_bytes > data->rx_bytes)
@@ -247,7 +249,7 @@ void accounting_sta_start(struct hostapd_data *hapd, struct sta_info *sta)
time(&sta->acct_session_start);
sta->last_rx_bytes = sta->last_tx_bytes = 0;
sta->acct_input_gigawords = sta->acct_output_gigawords = 0;
- hostapd_sta_clear_stats(hapd, sta->addr);
+ hapd->drv.sta_clear_stats(hapd, sta->addr);
if (!hapd->conf->radius->acct_server)
return;
@@ -364,7 +366,6 @@ static void accounting_sta_report(struct hostapd_data *hapd,
fail:
radius_msg_free(msg);
- os_free(msg);
}
@@ -425,7 +426,7 @@ accounting_receive(struct radius_msg *msg, struct radius_msg *req,
const u8 *shared_secret, size_t shared_secret_len,
void *data)
{
- if (msg->hdr->code != RADIUS_CODE_ACCOUNTING_RESPONSE) {
+ if (radius_msg_get_hdr(msg)->code != RADIUS_CODE_ACCOUNTING_RESPONSE) {
printf("Unknown RADIUS message code\n");
return RADIUS_RX_UNKNOWN;
}
@@ -460,7 +461,6 @@ static void accounting_report_state(struct hostapd_data *hapd, int on)
{
printf("Could not add Acct-Terminate-Cause\n");
radius_msg_free(msg);
- os_free(msg);
return;
}
@@ -497,14 +497,3 @@ void accounting_deinit(struct hostapd_data *hapd)
{
accounting_report_state(hapd, 0);
}
-
-
-int accounting_reconfig(struct hostapd_data *hapd,
- struct hostapd_config *oldconf)
-{
- if (!hapd->radius_client_reconfigured)
- return 0;
-
- accounting_deinit(hapd);
- return accounting_init(hapd);
-}
diff --git a/contrib/wpa/hostapd/accounting.h b/contrib/wpa/src/ap/accounting.h
index 51e6b4d..f3d60f0 100644
--- a/contrib/wpa/hostapd/accounting.h
+++ b/contrib/wpa/src/ap/accounting.h
@@ -15,12 +15,31 @@
#ifndef ACCOUNTING_H
#define ACCOUNTING_H
-void accounting_sta_start(struct hostapd_data *hapd, struct sta_info *sta);
void accounting_sta_interim(struct hostapd_data *hapd, struct sta_info *sta);
+#ifdef CONFIG_NO_ACCOUNTING
+static inline void accounting_sta_start(struct hostapd_data *hapd,
+ struct sta_info *sta)
+{
+}
+
+static inline void accounting_sta_stop(struct hostapd_data *hapd,
+ struct sta_info *sta)
+{
+}
+
+static inline int accounting_init(struct hostapd_data *hapd)
+{
+ return 0;
+}
+
+static inline void accounting_deinit(struct hostapd_data *hapd)
+{
+}
+#else /* CONFIG_NO_ACCOUNTING */
+void accounting_sta_start(struct hostapd_data *hapd, struct sta_info *sta);
void accounting_sta_stop(struct hostapd_data *hapd, struct sta_info *sta);
int accounting_init(struct hostapd_data *hapd);
void accounting_deinit(struct hostapd_data *hapd);
-int accounting_reconfig(struct hostapd_data *hapd,
- struct hostapd_config *oldconf);
+#endif /* CONFIG_NO_ACCOUNTING */
#endif /* ACCOUNTING_H */
diff --git a/contrib/wpa/src/ap/ap_config.c b/contrib/wpa/src/ap/ap_config.c
new file mode 100644
index 0000000..5996993
--- /dev/null
+++ b/contrib/wpa/src/ap/ap_config.c
@@ -0,0 +1,605 @@
+/*
+ * hostapd / Configuration helper functions
+ * Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "utils/includes.h"
+
+#include "utils/common.h"
+#include "crypto/sha1.h"
+#include "radius/radius_client.h"
+#include "common/ieee802_11_defs.h"
+#include "common/eapol_common.h"
+#include "eap_common/eap_wsc_common.h"
+#include "eap_server/eap.h"
+#include "wpa_auth.h"
+#include "sta_info.h"
+#include "ap_config.h"
+
+
+static void hostapd_config_free_vlan(struct hostapd_bss_config *bss)
+{
+ struct hostapd_vlan *vlan, *prev;
+
+ vlan = bss->vlan;
+ prev = NULL;
+ while (vlan) {
+ prev = vlan;
+ vlan = vlan->next;
+ os_free(prev);
+ }
+
+ bss->vlan = NULL;
+}
+
+
+void hostapd_config_defaults_bss(struct hostapd_bss_config *bss)
+{
+ bss->logger_syslog_level = HOSTAPD_LEVEL_INFO;
+ bss->logger_stdout_level = HOSTAPD_LEVEL_INFO;
+ bss->logger_syslog = (unsigned int) -1;
+ bss->logger_stdout = (unsigned int) -1;
+
+ bss->auth_algs = WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED;
+
+ bss->wep_rekeying_period = 300;
+ /* use key0 in individual key and key1 in broadcast key */
+ bss->broadcast_key_idx_min = 1;
+ bss->broadcast_key_idx_max = 2;
+ bss->eap_reauth_period = 3600;
+
+ bss->wpa_group_rekey = 600;
+ bss->wpa_gmk_rekey = 86400;
+ bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
+ bss->wpa_pairwise = WPA_CIPHER_TKIP;
+ bss->wpa_group = WPA_CIPHER_TKIP;
+ bss->rsn_pairwise = 0;
+
+ bss->max_num_sta = MAX_STA_COUNT;
+
+ bss->dtim_period = 2;
+
+ bss->radius_server_auth_port = 1812;
+ bss->ap_max_inactivity = AP_MAX_INACTIVITY;
+ bss->eapol_version = EAPOL_VERSION;
+
+ bss->max_listen_interval = 65535;
+
+#ifdef CONFIG_IEEE80211W
+ bss->assoc_sa_query_max_timeout = 1000;
+ bss->assoc_sa_query_retry_timeout = 201;
+#endif /* CONFIG_IEEE80211W */
+#ifdef EAP_SERVER_FAST
+ /* both anonymous and authenticated provisioning */
+ bss->eap_fast_prov = 3;
+ bss->pac_key_lifetime = 7 * 24 * 60 * 60;
+ bss->pac_key_refresh_time = 1 * 24 * 60 * 60;
+#endif /* EAP_SERVER_FAST */
+}
+
+
+struct hostapd_config * hostapd_config_defaults(void)
+{
+ struct hostapd_config *conf;
+ struct hostapd_bss_config *bss;
+ int i;
+ const int aCWmin = 4, aCWmax = 10;
+ const struct hostapd_wmm_ac_params ac_bk =
+ { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
+ const struct hostapd_wmm_ac_params ac_be =
+ { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
+ const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
+ { aCWmin - 1, aCWmin, 2, 3000 / 32, 1 };
+ const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
+ { aCWmin - 2, aCWmin - 1, 2, 1500 / 32, 1 };
+
+ conf = os_zalloc(sizeof(*conf));
+ bss = os_zalloc(sizeof(*bss));
+ if (conf == NULL || bss == NULL) {
+ wpa_printf(MSG_ERROR, "Failed to allocate memory for "
+ "configuration data.");
+ os_free(conf);
+ os_free(bss);
+ return NULL;
+ }
+
+ bss->radius = os_zalloc(sizeof(*bss->radius));
+ if (bss->radius == NULL) {
+ os_free(conf);
+ os_free(bss);
+ return NULL;
+ }
+
+ hostapd_config_defaults_bss(bss);
+
+ conf->num_bss = 1;
+ conf->bss = bss;
+
+ conf->beacon_int = 100;
+ conf->rts_threshold = -1; /* use driver default: 2347 */
+ conf->fragm_threshold = -1; /* user driver default: 2346 */
+ conf->send_probe_response = 1;
+
+ for (i = 0; i < NUM_TX_QUEUES; i++)
+ conf->tx_queue[i].aifs = -1; /* use hw default */
+
+ conf->wmm_ac_params[0] = ac_be;
+ conf->wmm_ac_params[1] = ac_bk;
+ conf->wmm_ac_params[2] = ac_vi;
+ conf->wmm_ac_params[3] = ac_vo;
+
+ conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED;
+
+ return conf;
+}
+
+
+int hostapd_mac_comp(const void *a, const void *b)
+{
+ return os_memcmp(a, b, sizeof(macaddr));
+}
+
+
+int hostapd_mac_comp_empty(const void *a)
+{
+ macaddr empty = { 0 };
+ return os_memcmp(a, empty, sizeof(macaddr));
+}
+
+
+static int hostapd_config_read_wpa_psk(const char *fname,
+ struct hostapd_ssid *ssid)
+{
+ FILE *f;
+ char buf[128], *pos;
+ int line = 0, ret = 0, len, ok;
+ u8 addr[ETH_ALEN];
+ struct hostapd_wpa_psk *psk;
+
+ if (!fname)
+ return 0;
+
+ f = fopen(fname, "r");
+ if (!f) {
+ wpa_printf(MSG_ERROR, "WPA PSK file '%s' not found.", fname);
+ return -1;
+ }
+
+ while (fgets(buf, sizeof(buf), f)) {
+ line++;
+
+ if (buf[0] == '#')
+ continue;
+ pos = buf;
+ while (*pos != '\0') {
+ if (*pos == '\n') {
+ *pos = '\0';
+ break;
+ }
+ pos++;
+ }
+ if (buf[0] == '\0')
+ continue;
+
+ if (hwaddr_aton(buf, addr)) {
+ wpa_printf(MSG_ERROR, "Invalid MAC address '%s' on "
+ "line %d in '%s'", buf, line, fname);
+ ret = -1;
+ break;
+ }
+
+ psk = os_zalloc(sizeof(*psk));
+ if (psk == NULL) {
+ wpa_printf(MSG_ERROR, "WPA PSK allocation failed");
+ ret = -1;
+ break;
+ }
+ if (is_zero_ether_addr(addr))
+ psk->group = 1;
+ else
+ os_memcpy(psk->addr, addr, ETH_ALEN);
+
+ pos = buf + 17;
+ if (*pos == '\0') {
+ wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'",
+ line, fname);
+ os_free(psk);
+ ret = -1;
+ break;
+ }
+ pos++;
+
+ ok = 0;
+ len = os_strlen(pos);
+ if (len == 64 && hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
+ ok = 1;
+ else if (len >= 8 && len < 64) {
+ pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
+ 4096, psk->psk, PMK_LEN);
+ ok = 1;
+ }
+ if (!ok) {
+ wpa_printf(MSG_ERROR, "Invalid PSK '%s' on line %d in "
+ "'%s'", pos, line, fname);
+ os_free(psk);
+ ret = -1;
+ break;
+ }
+
+ psk->next = ssid->wpa_psk;
+ ssid->wpa_psk = psk;
+ }
+
+ fclose(f);
+
+ return ret;
+}
+
+
+static int hostapd_derive_psk(struct hostapd_ssid *ssid)
+{
+ ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
+ if (ssid->wpa_psk == NULL) {
+ wpa_printf(MSG_ERROR, "Unable to alloc space for PSK");
+ return -1;
+ }
+ wpa_hexdump_ascii(MSG_DEBUG, "SSID",
+ (u8 *) ssid->ssid, ssid->ssid_len);
+ wpa_hexdump_ascii_key(MSG_DEBUG, "PSK (ASCII passphrase)",
+ (u8 *) ssid->wpa_passphrase,
+ os_strlen(ssid->wpa_passphrase));
+ pbkdf2_sha1(ssid->wpa_passphrase,
+ ssid->ssid, ssid->ssid_len,
+ 4096, ssid->wpa_psk->psk, PMK_LEN);
+ wpa_hexdump_key(MSG_DEBUG, "PSK (from passphrase)",
+ ssid->wpa_psk->psk, PMK_LEN);
+ return 0;
+}
+
+
+int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
+{
+ struct hostapd_ssid *ssid = &conf->ssid;
+
+ if (ssid->wpa_passphrase != NULL) {
+ if (ssid->wpa_psk != NULL) {
+ wpa_printf(MSG_DEBUG, "Using pre-configured WPA PSK "
+ "instead of passphrase");
+ } else {
+ wpa_printf(MSG_DEBUG, "Deriving WPA PSK based on "
+ "passphrase");
+ if (hostapd_derive_psk(ssid) < 0)
+ return -1;
+ }
+ ssid->wpa_psk->group = 1;
+ }
+
+ if (ssid->wpa_psk_file) {
+ if (hostapd_config_read_wpa_psk(ssid->wpa_psk_file,
+ &conf->ssid))
+ return -1;
+ }
+
+ return 0;
+}
+
+
+int hostapd_wep_key_cmp(struct hostapd_wep_keys *a, struct hostapd_wep_keys *b)
+{
+ int i;
+
+ if (a->idx != b->idx || a->default_len != b->default_len)
+ return 1;
+ for (i = 0; i < NUM_WEP_KEYS; i++)
+ if (a->len[i] != b->len[i] ||
+ os_memcmp(a->key[i], b->key[i], a->len[i]) != 0)
+ return 1;
+ return 0;
+}
+
+
+static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
+ int num_servers)
+{
+ int i;
+
+ for (i = 0; i < num_servers; i++) {
+ os_free(servers[i].shared_secret);
+ }
+ os_free(servers);
+}
+
+
+static void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
+{
+ os_free(user->identity);
+ os_free(user->password);
+ os_free(user);
+}
+
+
+static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
+{
+ int i;
+ for (i = 0; i < NUM_WEP_KEYS; i++) {
+ os_free(keys->key[i]);
+ keys->key[i] = NULL;
+ }
+}
+
+
+static void hostapd_config_free_bss(struct hostapd_bss_config *conf)
+{
+ struct hostapd_wpa_psk *psk, *prev;
+ struct hostapd_eap_user *user, *prev_user;
+
+ if (conf == NULL)
+ return;
+
+ psk = conf->ssid.wpa_psk;
+ while (psk) {
+ prev = psk;
+ psk = psk->next;
+ os_free(prev);
+ }
+
+ os_free(conf->ssid.wpa_passphrase);
+ os_free(conf->ssid.wpa_psk_file);
+ hostapd_config_free_wep(&conf->ssid.wep);
+#ifdef CONFIG_FULL_DYNAMIC_VLAN
+ os_free(conf->ssid.vlan_tagged_interface);
+#endif /* CONFIG_FULL_DYNAMIC_VLAN */
+
+ user = conf->eap_user;
+ while (user) {
+ prev_user = user;
+ user = user->next;
+ hostapd_config_free_eap_user(prev_user);
+ }
+
+ os_free(conf->dump_log_name);
+ os_free(conf->eap_req_id_text);
+ os_free(conf->accept_mac);
+ os_free(conf->deny_mac);
+ os_free(conf->nas_identifier);
+ hostapd_config_free_radius(conf->radius->auth_servers,
+ conf->radius->num_auth_servers);
+ hostapd_config_free_radius(conf->radius->acct_servers,
+ conf->radius->num_acct_servers);
+ os_free(conf->rsn_preauth_interfaces);
+ os_free(conf->ctrl_interface);
+ os_free(conf->ca_cert);
+ os_free(conf->server_cert);
+ os_free(conf->private_key);
+ os_free(conf->private_key_passwd);
+ os_free(conf->dh_file);
+ os_free(conf->pac_opaque_encr_key);
+ os_free(conf->eap_fast_a_id);
+ os_free(conf->eap_fast_a_id_info);
+ os_free(conf->eap_sim_db);
+ os_free(conf->radius_server_clients);
+ os_free(conf->test_socket);
+ os_free(conf->radius);
+ hostapd_config_free_vlan(conf);
+ if (conf->ssid.dyn_vlan_keys) {
+ struct hostapd_ssid *ssid = &conf->ssid;
+ size_t i;
+ for (i = 0; i <= ssid->max_dyn_vlan_keys; i++) {
+ if (ssid->dyn_vlan_keys[i] == NULL)
+ continue;
+ hostapd_config_free_wep(ssid->dyn_vlan_keys[i]);
+ os_free(ssid->dyn_vlan_keys[i]);
+ }
+ os_free(ssid->dyn_vlan_keys);
+ ssid->dyn_vlan_keys = NULL;
+ }
+
+#ifdef CONFIG_IEEE80211R
+ {
+ struct ft_remote_r0kh *r0kh, *r0kh_prev;
+ struct ft_remote_r1kh *r1kh, *r1kh_prev;
+
+ r0kh = conf->r0kh_list;
+ conf->r0kh_list = NULL;
+ while (r0kh) {
+ r0kh_prev = r0kh;
+ r0kh = r0kh->next;
+ os_free(r0kh_prev);
+ }
+
+ r1kh = conf->r1kh_list;
+ conf->r1kh_list = NULL;
+ while (r1kh) {
+ r1kh_prev = r1kh;
+ r1kh = r1kh->next;
+ os_free(r1kh_prev);
+ }
+ }
+#endif /* CONFIG_IEEE80211R */
+
+#ifdef CONFIG_WPS
+ os_free(conf->wps_pin_requests);
+ os_free(conf->device_name);
+ os_free(conf->manufacturer);
+ os_free(conf->model_name);
+ os_free(conf->model_number);
+ os_free(conf->serial_number);
+ os_free(conf->device_type);
+ os_free(conf->config_methods);
+ os_free(conf->ap_pin);
+ os_free(conf->extra_cred);
+ os_free(conf->ap_settings);
+ os_free(conf->upnp_iface);
+ os_free(conf->friendly_name);
+ os_free(conf->manufacturer_url);
+ os_free(conf->model_description);
+ os_free(conf->model_url);
+ os_free(conf->upc);
+#endif /* CONFIG_WPS */
+}
+
+
+/**
+ * hostapd_config_free - Free hostapd configuration
+ * @conf: Configuration data from hostapd_config_read().
+ */
+void hostapd_config_free(struct hostapd_config *conf)
+{
+ size_t i;
+
+ if (conf == NULL)
+ return;
+
+ for (i = 0; i < conf->num_bss; i++)
+ hostapd_config_free_bss(&conf->bss[i]);
+ os_free(conf->bss);
+ os_free(conf->supported_rates);
+ os_free(conf->basic_rates);
+
+ os_free(conf);
+}
+
+
+/**
+ * hostapd_maclist_found - Find a MAC address from a list
+ * @list: MAC address list
+ * @num_entries: Number of addresses in the list
+ * @addr: Address to search for
+ * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
+ * Returns: 1 if address is in the list or 0 if not.
+ *
+ * Perform a binary search for given MAC address from a pre-sorted list.
+ */
+int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
+ const u8 *addr, int *vlan_id)
+{
+ int start, end, middle, res;
+
+ start = 0;
+ end = num_entries - 1;
+
+ while (start <= end) {
+ middle = (start + end) / 2;
+ res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
+ if (res == 0) {
+ if (vlan_id)
+ *vlan_id = list[middle].vlan_id;
+ return 1;
+ }
+ if (res < 0)
+ start = middle + 1;
+ else
+ end = middle - 1;
+ }
+
+ return 0;
+}
+
+
+int hostapd_rate_found(int *list, int rate)
+{
+ int i;
+
+ if (list == NULL)
+ return 0;
+
+ for (i = 0; list[i] >= 0; i++)
+ if (list[i] == rate)
+ return 1;
+
+ return 0;
+}
+
+
+const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
+{
+ struct hostapd_vlan *v = vlan;
+ while (v) {
+ if (v->vlan_id == vlan_id || v->vlan_id == VLAN_ID_WILDCARD)
+ return v->ifname;
+ v = v->next;
+ }
+ return NULL;
+}
+
+
+const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
+ const u8 *addr, const u8 *prev_psk)
+{
+ struct hostapd_wpa_psk *psk;
+ int next_ok = prev_psk == NULL;
+
+ for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
+ if (next_ok &&
+ (psk->group || os_memcmp(psk->addr, addr, ETH_ALEN) == 0))
+ return psk->psk;
+
+ if (psk->psk == prev_psk)
+ next_ok = 1;
+ }
+
+ return NULL;
+}
+
+
+const struct hostapd_eap_user *
+hostapd_get_eap_user(const struct hostapd_bss_config *conf, const u8 *identity,
+ size_t identity_len, int phase2)
+{
+ struct hostapd_eap_user *user = conf->eap_user;
+
+#ifdef CONFIG_WPS
+ if (conf->wps_state && identity_len == WSC_ID_ENROLLEE_LEN &&
+ os_memcmp(identity, WSC_ID_ENROLLEE, WSC_ID_ENROLLEE_LEN) == 0) {
+ static struct hostapd_eap_user wsc_enrollee;
+ os_memset(&wsc_enrollee, 0, sizeof(wsc_enrollee));
+ wsc_enrollee.methods[0].method = eap_server_get_type(
+ "WSC", &wsc_enrollee.methods[0].vendor);
+ return &wsc_enrollee;
+ }
+
+ if (conf->wps_state && identity_len == WSC_ID_REGISTRAR_LEN &&
+ os_memcmp(identity, WSC_ID_REGISTRAR, WSC_ID_REGISTRAR_LEN) == 0) {
+ static struct hostapd_eap_user wsc_registrar;
+ os_memset(&wsc_registrar, 0, sizeof(wsc_registrar));
+ wsc_registrar.methods[0].method = eap_server_get_type(
+ "WSC", &wsc_registrar.methods[0].vendor);
+ wsc_registrar.password = (u8 *) conf->ap_pin;
+ wsc_registrar.password_len = conf->ap_pin ?
+ os_strlen(conf->ap_pin) : 0;
+ return &wsc_registrar;
+ }
+#endif /* CONFIG_WPS */
+
+ while (user) {
+ if (!phase2 && user->identity == NULL) {
+ /* Wildcard match */
+ break;
+ }
+
+ if (user->phase2 == !!phase2 && user->wildcard_prefix &&
+ identity_len >= user->identity_len &&
+ os_memcmp(user->identity, identity, user->identity_len) ==
+ 0) {
+ /* Wildcard prefix match */
+ break;
+ }
+
+ if (user->phase2 == !!phase2 &&
+ user->identity_len == identity_len &&
+ os_memcmp(user->identity, identity, identity_len) == 0)
+ break;
+ user = user->next;
+ }
+
+ return user;
+}
diff --git a/contrib/wpa/hostapd/config.h b/contrib/wpa/src/ap/ap_config.h
index ea530d4..f509b5b 100644
--- a/contrib/wpa/hostapd/config.h
+++ b/contrib/wpa/src/ap/ap_config.h
@@ -1,7 +1,6 @@
/*
- * hostapd / Configuration file
- * Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
- * Copyright (c) 2007-2008, Intel Corporation
+ * hostapd / Configuration definitions and helpers functions
+ * Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -13,16 +12,15 @@
* See README and COPYING for more details.
*/
-#ifndef CONFIG_H
-#define CONFIG_H
+#ifndef HOSTAPD_CONFIG_H
+#define HOSTAPD_CONFIG_H
-#include "defs.h"
+#include "common/defs.h"
#include "ip_addr.h"
-#include "wpa_common.h"
+#include "common/wpa_common.h"
-#ifndef IFNAMSIZ
-#define IFNAMSIZ 16
-#endif
+#define MAX_STA_COUNT 2007
+#define MAX_VLAN_ID 4094
typedef u8 macaddr[ETH_ALEN];
@@ -171,6 +169,7 @@ struct hostapd_bss_config {
struct hostapd_ip_addr own_ip_addr;
char *nas_identifier;
struct hostapd_radius_servers *radius;
+ int acct_interim_interval;
struct hostapd_ssid ssid;
@@ -198,6 +197,7 @@ struct hostapd_bss_config {
int num_accept_mac;
struct mac_acl_entry *deny_mac;
int num_deny_mac;
+ int wds_sta;
int auth_algs; /* bitfield of allowed IEEE 802.11 authentication
* algorithms, WPA_AUTH_ALG_{OPEN,SHARED,LEAP} */
@@ -205,11 +205,7 @@ struct hostapd_bss_config {
int wpa; /* bitfield of WPA_PROTO_WPA, WPA_PROTO_RSN */
int wpa_key_mgmt;
#ifdef CONFIG_IEEE80211W
- enum {
- NO_IEEE80211W = 0,
- IEEE80211W_OPTIONAL = 1,
- IEEE80211W_REQUIRED = 2
- } ieee80211w;
+ enum mfp_options ieee80211w;
/* dot11AssociationSAQueryMaximumTimeout (in TUs) */
unsigned int assoc_sa_query_max_timeout;
/* dot11AssociationSAQueryRetryTimeout (in TUs) */
@@ -238,7 +234,9 @@ struct hostapd_bss_config {
#endif /* CONFIG_IEEE80211R */
char *ctrl_interface; /* directory for UNIX domain sockets */
+#ifndef CONFIG_NATIVE_WINDOWS
gid_t ctrl_interface_gid;
+#endif /* CONFIG_NATIVE_WINDOWS */
int ctrl_interface_gid_set;
char *ca_cert;
@@ -272,6 +270,7 @@ struct hostapd_bss_config {
int ignore_broadcast_ssid;
int wmm_enabled;
+ int wmm_uapsd;
struct hostapd_vlan *vlan, *vlan_tail;
@@ -316,14 +315,6 @@ struct hostapd_bss_config {
};
-typedef enum {
- HOSTAPD_MODE_IEEE80211B,
- HOSTAPD_MODE_IEEE80211G,
- HOSTAPD_MODE_IEEE80211A,
- NUM_HOSTAPD_MODES
-} hostapd_hw_mode;
-
-
/**
* struct hostapd_config - Per-radio interface configuration
*/
@@ -336,7 +327,7 @@ struct hostapd_config {
int fragm_threshold;
u8 send_probe_response;
u8 channel;
- hostapd_hw_mode hw_mode; /* HOSTAPD_MODE_IEEE80211A, .. */
+ enum hostapd_hw_mode hw_mode; /* HOSTAPD_MODE_IEEE80211A, .. */
enum {
LONG_PREAMBLE = 0,
SHORT_PREAMBLE = 1
@@ -353,9 +344,6 @@ struct hostapd_config {
const struct wpa_driver_ops *driver;
- int passive_scan_interval; /* seconds, 0 = disabled */
- int passive_scan_listen; /* usec */
- int passive_scan_mode;
int ap_table_max_size;
int ap_table_expiration_time;
@@ -379,16 +367,8 @@ struct hostapd_config {
*/
struct hostapd_wmm_ac_params wmm_ac_params[4];
- enum {
- INTERNAL_BRIDGE_DO_NOT_CONTROL = -1,
- INTERNAL_BRIDGE_DISABLED = 0,
- INTERNAL_BRIDGE_ENABLED = 1
- } bridge_packets;
-
-#ifdef CONFIG_IEEE80211N
int ht_op_mode_fixed;
u16 ht_capab;
-#endif /* CONFIG_IEEE80211N */
int ieee80211n;
int secondary_channel;
};
@@ -396,7 +376,8 @@ struct hostapd_config {
int hostapd_mac_comp(const void *a, const void *b);
int hostapd_mac_comp_empty(const void *a);
-struct hostapd_config * hostapd_config_read(const char *fname);
+struct hostapd_config * hostapd_config_defaults(void);
+void hostapd_config_defaults_bss(struct hostapd_bss_config *bss);
void hostapd_config_free(struct hostapd_config *conf);
int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
const u8 *addr, int *vlan_id);
@@ -412,4 +393,4 @@ const struct hostapd_eap_user *
hostapd_get_eap_user(const struct hostapd_bss_config *conf, const u8 *identity,
size_t identity_len, int phase2);
-#endif /* CONFIG_H */
+#endif /* HOSTAPD_CONFIG_H */
diff --git a/contrib/wpa/src/ap/ap_drv_ops.c b/contrib/wpa/src/ap/ap_drv_ops.c
new file mode 100644
index 0000000..f264a3e
--- /dev/null
+++ b/contrib/wpa/src/ap/ap_drv_ops.c
@@ -0,0 +1,621 @@
+/*
+ * hostapd - Driver operations
+ * Copyright (c) 2009-2010, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "utils/includes.h"
+
+#include "utils/common.h"
+#include "drivers/driver.h"
+#include "common/ieee802_11_defs.h"
+#include "hostapd.h"
+#include "ieee802_11.h"
+#include "sta_info.h"
+#include "ap_config.h"
+#include "ap_drv_ops.h"
+
+
+static int hostapd_sta_flags_to_drv(int flags)
+{
+ int res = 0;
+ if (flags & WLAN_STA_AUTHORIZED)
+ res |= WPA_STA_AUTHORIZED;
+ if (flags & WLAN_STA_WMM)
+ res |= WPA_STA_WMM;
+ if (flags & WLAN_STA_SHORT_PREAMBLE)
+ res |= WPA_STA_SHORT_PREAMBLE;
+ if (flags & WLAN_STA_MFP)
+ res |= WPA_STA_MFP;
+ return res;
+}
+
+
+static int hostapd_set_ap_wps_ie(struct hostapd_data *hapd)
+{
+ struct wpabuf *beacon, *proberesp;
+ int ret;
+
+ if (hapd->driver == NULL || hapd->driver->set_ap_wps_ie == NULL)
+ return 0;
+
+ beacon = hapd->wps_beacon_ie;
+ proberesp = hapd->wps_probe_resp_ie;
+
+ ret = hapd->driver->set_ap_wps_ie(hapd->drv_priv, beacon, proberesp);
+
+ return ret;
+}
+
+
+static int hostapd_send_mgmt_frame(struct hostapd_data *hapd, const void *msg,
+ size_t len)
+{
+ if (hapd->driver == NULL || hapd->driver->send_mlme == NULL)
+ return 0;
+ return hapd->driver->send_mlme(hapd->drv_priv, msg, len);
+}
+
+
+static int hostapd_send_eapol(struct hostapd_data *hapd, const u8 *addr,
+ const u8 *data, size_t data_len, int encrypt)
+{
+ if (hapd->driver == NULL || hapd->driver->hapd_send_eapol == NULL)
+ return 0;
+ return hapd->driver->hapd_send_eapol(hapd->drv_priv, addr, data,
+ data_len, encrypt,
+ hapd->own_addr);
+}
+
+
+static int hostapd_set_authorized(struct hostapd_data *hapd,
+ struct sta_info *sta, int authorized)
+{
+ if (authorized) {
+ return hostapd_sta_set_flags(hapd, sta->addr,
+ hostapd_sta_flags_to_drv(
+ sta->flags),
+ WPA_STA_AUTHORIZED, ~0);
+ }
+
+ return hostapd_sta_set_flags(hapd, sta->addr,
+ hostapd_sta_flags_to_drv(sta->flags),
+ 0, ~WPA_STA_AUTHORIZED);
+}
+
+
+static int hostapd_set_key(const char *ifname, struct hostapd_data *hapd,
+ enum wpa_alg alg, const u8 *addr, int key_idx,
+ int set_tx, const u8 *seq, size_t seq_len,
+ const u8 *key, size_t key_len)
+{
+ if (hapd->driver == NULL || hapd->driver->set_key == NULL)
+ return 0;
+ return hapd->driver->set_key(ifname, hapd->drv_priv, alg, addr,
+ key_idx, set_tx, seq, seq_len, key,
+ key_len);
+}
+
+
+static int hostapd_read_sta_data(struct hostapd_data *hapd,
+ struct hostap_sta_driver_data *data,
+ const u8 *addr)
+{
+ if (hapd->driver == NULL || hapd->driver->read_sta_data == NULL)
+ return -1;
+ return hapd->driver->read_sta_data(hapd->drv_priv, data, addr);
+}
+
+
+static int hostapd_sta_clear_stats(struct hostapd_data *hapd, const u8 *addr)
+{
+ if (hapd->driver == NULL || hapd->driver->sta_clear_stats == NULL)
+ return 0;
+ return hapd->driver->sta_clear_stats(hapd->drv_priv, addr);
+}
+
+
+static int hostapd_set_sta_flags(struct hostapd_data *hapd,
+ struct sta_info *sta)
+{
+ int set_flags, total_flags, flags_and, flags_or;
+ total_flags = hostapd_sta_flags_to_drv(sta->flags);
+ set_flags = WPA_STA_SHORT_PREAMBLE | WPA_STA_WMM | WPA_STA_MFP;
+ if (((!hapd->conf->ieee802_1x && !hapd->conf->wpa) ||
+ sta->auth_alg == WLAN_AUTH_FT) &&
+ sta->flags & WLAN_STA_AUTHORIZED)
+ set_flags |= WPA_STA_AUTHORIZED;
+ flags_or = total_flags & set_flags;
+ flags_and = total_flags | ~set_flags;
+ return hostapd_sta_set_flags(hapd, sta->addr, total_flags,
+ flags_or, flags_and);
+}
+
+
+static int hostapd_set_drv_ieee8021x(struct hostapd_data *hapd,
+ const char *ifname, int enabled)
+{
+ struct wpa_bss_params params;
+ os_memset(&params, 0, sizeof(params));
+ params.ifname = ifname;
+ params.enabled = enabled;
+ if (enabled) {
+ params.wpa = hapd->conf->wpa;
+ params.ieee802_1x = hapd->conf->ieee802_1x;
+ params.wpa_group = hapd->conf->wpa_group;
+ params.wpa_pairwise = hapd->conf->wpa_pairwise;
+ params.wpa_key_mgmt = hapd->conf->wpa_key_mgmt;
+ params.rsn_preauth = hapd->conf->rsn_preauth;
+ }
+ return hostapd_set_ieee8021x(hapd, &params);
+}
+
+
+static int hostapd_set_radius_acl_auth(struct hostapd_data *hapd,
+ const u8 *mac, int accepted,
+ u32 session_timeout)
+{
+ if (hapd->driver == NULL || hapd->driver->set_radius_acl_auth == NULL)
+ return 0;
+ return hapd->driver->set_radius_acl_auth(hapd->drv_priv, mac, accepted,
+ session_timeout);
+}
+
+
+static int hostapd_set_radius_acl_expire(struct hostapd_data *hapd,
+ const u8 *mac)
+{
+ if (hapd->driver == NULL ||
+ hapd->driver->set_radius_acl_expire == NULL)
+ return 0;
+ return hapd->driver->set_radius_acl_expire(hapd->drv_priv, mac);
+}
+
+
+static int hostapd_set_bss_params(struct hostapd_data *hapd,
+ int use_protection)
+{
+ int ret = 0;
+ int preamble;
+#ifdef CONFIG_IEEE80211N
+ u8 buf[60], *ht_capab, *ht_oper, *pos;
+
+ pos = buf;
+ ht_capab = pos;
+ pos = hostapd_eid_ht_capabilities(hapd, pos);
+ ht_oper = pos;
+ pos = hostapd_eid_ht_operation(hapd, pos);
+ if (pos > ht_oper && ht_oper > ht_capab &&
+ hostapd_set_ht_params(hapd, ht_capab + 2, ht_capab[1],
+ ht_oper + 2, ht_oper[1])) {
+ wpa_printf(MSG_ERROR, "Could not set HT capabilities "
+ "for kernel driver");
+ ret = -1;
+ }
+
+#endif /* CONFIG_IEEE80211N */
+
+ if (hostapd_set_cts_protect(hapd, use_protection)) {
+ wpa_printf(MSG_ERROR, "Failed to set CTS protect in kernel "
+ "driver");
+ ret = -1;
+ }
+
+ if (hapd->iface->current_mode &&
+ hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
+ hostapd_set_short_slot_time(hapd,
+ hapd->iface->num_sta_no_short_slot_time
+ > 0 ? 0 : 1)) {
+ wpa_printf(MSG_ERROR, "Failed to set Short Slot Time option "
+ "in kernel driver");
+ ret = -1;
+ }
+
+ if (hapd->iface->num_sta_no_short_preamble == 0 &&
+ hapd->iconf->preamble == SHORT_PREAMBLE)
+ preamble = SHORT_PREAMBLE;
+ else
+ preamble = LONG_PREAMBLE;
+ if (hostapd_set_preamble(hapd, preamble)) {
+ wpa_printf(MSG_ERROR, "Could not set preamble for kernel "
+ "driver");
+ ret = -1;
+ }
+
+ return ret;
+}
+
+
+static int hostapd_set_beacon(struct hostapd_data *hapd,
+ const u8 *head, size_t head_len,
+ const u8 *tail, size_t tail_len, int dtim_period,
+ int beacon_int)
+{
+ if (hapd->driver == NULL || hapd->driver->set_beacon == NULL)
+ return 0;
+ return hapd->driver->set_beacon(hapd->drv_priv,
+ head, head_len, tail, tail_len,
+ dtim_period, beacon_int);
+}
+
+
+static int hostapd_vlan_if_add(struct hostapd_data *hapd, const char *ifname)
+{
+ char force_ifname[IFNAMSIZ];
+ u8 if_addr[ETH_ALEN];
+ return hostapd_if_add(hapd, WPA_IF_AP_VLAN, ifname, NULL, NULL, NULL,
+ force_ifname, if_addr);
+}
+
+static int hostapd_vlan_if_remove(struct hostapd_data *hapd,
+ const char *ifname)
+{
+ return hostapd_if_remove(hapd, WPA_IF_AP_VLAN, ifname);
+}
+
+
+static int hostapd_set_wds_sta(struct hostapd_data *hapd, const u8 *addr,
+ int aid, int val)
+{
+ if (hapd->driver == NULL || hapd->driver->set_wds_sta == NULL)
+ return 0;
+ return hapd->driver->set_wds_sta(hapd->drv_priv, addr, aid, val);
+}
+
+
+static int hostapd_set_sta_vlan(const char *ifname, struct hostapd_data *hapd,
+ const u8 *addr, int vlan_id)
+{
+ if (hapd->driver == NULL || hapd->driver->set_sta_vlan == NULL)
+ return 0;
+ return hapd->driver->set_sta_vlan(hapd->drv_priv, addr, ifname,
+ vlan_id);
+}
+
+
+static int hostapd_get_inact_sec(struct hostapd_data *hapd, const u8 *addr)
+{
+ if (hapd->driver == NULL || hapd->driver->get_inact_sec == NULL)
+ return 0;
+ return hapd->driver->get_inact_sec(hapd->drv_priv, addr);
+}
+
+
+static int hostapd_sta_deauth(struct hostapd_data *hapd, const u8 *addr,
+ int reason)
+{
+ if (hapd->driver == NULL || hapd->driver->sta_deauth == NULL)
+ return 0;
+ return hapd->driver->sta_deauth(hapd->drv_priv, hapd->own_addr, addr,
+ reason);
+}
+
+
+static int hostapd_sta_disassoc(struct hostapd_data *hapd, const u8 *addr,
+ int reason)
+{
+ if (hapd->driver == NULL || hapd->driver->sta_disassoc == NULL)
+ return 0;
+ return hapd->driver->sta_disassoc(hapd->drv_priv, hapd->own_addr, addr,
+ reason);
+}
+
+
+static int hostapd_sta_add(struct hostapd_data *hapd,
+ const u8 *addr, u16 aid, u16 capability,
+ const u8 *supp_rates, size_t supp_rates_len,
+ u16 listen_interval,
+ const struct ieee80211_ht_capabilities *ht_capab)
+{
+ struct hostapd_sta_add_params params;
+
+ if (hapd->driver == NULL)
+ return 0;
+ if (hapd->driver->sta_add == NULL)
+ return 0;
+
+ os_memset(&params, 0, sizeof(params));
+ params.addr = addr;
+ params.aid = aid;
+ params.capability = capability;
+ params.supp_rates = supp_rates;
+ params.supp_rates_len = supp_rates_len;
+ params.listen_interval = listen_interval;
+ params.ht_capabilities = ht_capab;
+ return hapd->driver->sta_add(hapd->drv_priv, &params);
+}
+
+
+static int hostapd_sta_remove(struct hostapd_data *hapd, const u8 *addr)
+{
+ if (hapd->driver == NULL || hapd->driver->sta_remove == NULL)
+ return 0;
+ return hapd->driver->sta_remove(hapd->drv_priv, addr);
+}
+
+
+static int hostapd_set_countermeasures(struct hostapd_data *hapd, int enabled)
+{
+ if (hapd->driver == NULL ||
+ hapd->driver->hapd_set_countermeasures == NULL)
+ return 0;
+ return hapd->driver->hapd_set_countermeasures(hapd->drv_priv, enabled);
+}
+
+
+void hostapd_set_driver_ops(struct hostapd_driver_ops *ops)
+{
+ ops->set_ap_wps_ie = hostapd_set_ap_wps_ie;
+ ops->send_mgmt_frame = hostapd_send_mgmt_frame;
+ ops->send_eapol = hostapd_send_eapol;
+ ops->set_authorized = hostapd_set_authorized;
+ ops->set_key = hostapd_set_key;
+ ops->read_sta_data = hostapd_read_sta_data;
+ ops->sta_clear_stats = hostapd_sta_clear_stats;
+ ops->set_sta_flags = hostapd_set_sta_flags;
+ ops->set_drv_ieee8021x = hostapd_set_drv_ieee8021x;
+ ops->set_radius_acl_auth = hostapd_set_radius_acl_auth;
+ ops->set_radius_acl_expire = hostapd_set_radius_acl_expire;
+ ops->set_bss_params = hostapd_set_bss_params;
+ ops->set_beacon = hostapd_set_beacon;
+ ops->vlan_if_add = hostapd_vlan_if_add;
+ ops->vlan_if_remove = hostapd_vlan_if_remove;
+ ops->set_wds_sta = hostapd_set_wds_sta;
+ ops->set_sta_vlan = hostapd_set_sta_vlan;
+ ops->get_inact_sec = hostapd_get_inact_sec;
+ ops->sta_deauth = hostapd_sta_deauth;
+ ops->sta_disassoc = hostapd_sta_disassoc;
+ ops->sta_add = hostapd_sta_add;
+ ops->sta_remove = hostapd_sta_remove;
+ ops->set_countermeasures = hostapd_set_countermeasures;
+}
+
+
+int hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
+{
+ if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
+ return 0;
+ return hapd->driver->set_privacy(hapd->drv_priv, enabled);
+}
+
+
+int hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
+ size_t elem_len)
+{
+ if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
+ return 0;
+ return hapd->driver->set_generic_elem(hapd->drv_priv, elem, elem_len);
+}
+
+
+int hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
+{
+ if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL)
+ return 0;
+ return hapd->driver->hapd_get_ssid(hapd->drv_priv, buf, len);
+}
+
+
+int hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
+{
+ if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL)
+ return 0;
+ return hapd->driver->hapd_set_ssid(hapd->drv_priv, buf, len);
+}
+
+
+int hostapd_if_add(struct hostapd_data *hapd, enum wpa_driver_if_type type,
+ const char *ifname, const u8 *addr, void *bss_ctx,
+ void **drv_priv, char *force_ifname, u8 *if_addr)
+{
+ if (hapd->driver == NULL || hapd->driver->if_add == NULL)
+ return -1;
+ return hapd->driver->if_add(hapd->drv_priv, type, ifname, addr,
+ bss_ctx, drv_priv, force_ifname, if_addr);
+}
+
+
+int hostapd_if_remove(struct hostapd_data *hapd, enum wpa_driver_if_type type,
+ const char *ifname)
+{
+ if (hapd->driver == NULL || hapd->driver->if_remove == NULL)
+ return -1;
+ return hapd->driver->if_remove(hapd->drv_priv, type, ifname);
+}
+
+
+int hostapd_set_ieee8021x(struct hostapd_data *hapd,
+ struct wpa_bss_params *params)
+{
+ if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
+ return 0;
+ return hapd->driver->set_ieee8021x(hapd->drv_priv, params);
+}
+
+
+int hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
+ const u8 *addr, int idx, u8 *seq)
+{
+ if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
+ return 0;
+ return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx,
+ seq);
+}
+
+
+int hostapd_flush(struct hostapd_data *hapd)
+{
+ if (hapd->driver == NULL || hapd->driver->flush == NULL)
+ return 0;
+ return hapd->driver->flush(hapd->drv_priv);
+}
+
+
+int hostapd_set_freq(struct hostapd_data *hapd, int mode, int freq,
+ int channel, int ht_enabled, int sec_channel_offset)
+{
+ struct hostapd_freq_params data;
+ if (hapd->driver == NULL)
+ return 0;
+ if (hapd->driver->set_freq == NULL)
+ return 0;
+ os_memset(&data, 0, sizeof(data));
+ data.mode = mode;
+ data.freq = freq;
+ data.channel = channel;
+ data.ht_enabled = ht_enabled;
+ data.sec_channel_offset = sec_channel_offset;
+ return hapd->driver->set_freq(hapd->drv_priv, &data);
+}
+
+int hostapd_set_rts(struct hostapd_data *hapd, int rts)
+{
+ if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
+ return 0;
+ return hapd->driver->set_rts(hapd->drv_priv, rts);
+}
+
+
+int hostapd_set_frag(struct hostapd_data *hapd, int frag)
+{
+ if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
+ return 0;
+ return hapd->driver->set_frag(hapd->drv_priv, frag);
+}
+
+
+int hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
+ int total_flags, int flags_or, int flags_and)
+{
+ if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
+ return 0;
+ return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
+ flags_or, flags_and);
+}
+
+
+int hostapd_set_rate_sets(struct hostapd_data *hapd, int *supp_rates,
+ int *basic_rates, int mode)
+{
+ if (hapd->driver == NULL || hapd->driver->set_rate_sets == NULL)
+ return 0;
+ return hapd->driver->set_rate_sets(hapd->drv_priv, supp_rates,
+ basic_rates, mode);
+}
+
+
+int hostapd_set_country(struct hostapd_data *hapd, const char *country)
+{
+ if (hapd->driver == NULL ||
+ hapd->driver->set_country == NULL)
+ return 0;
+ return hapd->driver->set_country(hapd->drv_priv, country);
+}
+
+
+int hostapd_set_cts_protect(struct hostapd_data *hapd, int value)
+{
+ if (hapd->driver == NULL || hapd->driver->set_cts_protect == NULL)
+ return 0;
+ return hapd->driver->set_cts_protect(hapd->drv_priv, value);
+}
+
+
+int hostapd_set_preamble(struct hostapd_data *hapd, int value)
+{
+ if (hapd->driver == NULL || hapd->driver->set_preamble == NULL)
+ return 0;
+ return hapd->driver->set_preamble(hapd->drv_priv, value);
+}
+
+
+int hostapd_set_short_slot_time(struct hostapd_data *hapd, int value)
+{
+ if (hapd->driver == NULL || hapd->driver->set_short_slot_time == NULL)
+ return 0;
+ return hapd->driver->set_short_slot_time(hapd->drv_priv, value);
+}
+
+
+int hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
+ int cw_min, int cw_max, int burst_time)
+{
+ if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
+ return 0;
+ return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
+ cw_min, cw_max, burst_time);
+}
+
+
+int hostapd_valid_bss_mask(struct hostapd_data *hapd, const u8 *addr,
+ const u8 *mask)
+{
+ if (hapd->driver == NULL || hapd->driver->valid_bss_mask == NULL)
+ return 1;
+ return hapd->driver->valid_bss_mask(hapd->drv_priv, addr, mask);
+}
+
+
+struct hostapd_hw_modes *
+hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
+ u16 *flags)
+{
+ if (hapd->driver == NULL ||
+ hapd->driver->get_hw_feature_data == NULL)
+ return NULL;
+ return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
+ flags);
+}
+
+
+int hostapd_driver_commit(struct hostapd_data *hapd)
+{
+ if (hapd->driver == NULL || hapd->driver->commit == NULL)
+ return 0;
+ return hapd->driver->commit(hapd->drv_priv);
+}
+
+
+int hostapd_set_ht_params(struct hostapd_data *hapd,
+ const u8 *ht_capab, size_t ht_capab_len,
+ const u8 *ht_oper, size_t ht_oper_len)
+{
+ if (hapd->driver == NULL || hapd->driver->set_ht_params == NULL ||
+ ht_capab == NULL || ht_oper == NULL)
+ return 0;
+ return hapd->driver->set_ht_params(hapd->drv_priv,
+ ht_capab, ht_capab_len,
+ ht_oper, ht_oper_len);
+}
+
+
+int hostapd_drv_none(struct hostapd_data *hapd)
+{
+ return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
+}
+
+
+int hostapd_driver_scan(struct hostapd_data *hapd,
+ struct wpa_driver_scan_params *params)
+{
+ if (hapd->driver && hapd->driver->scan2)
+ return hapd->driver->scan2(hapd->drv_priv, params);
+ return -1;
+}
+
+
+struct wpa_scan_results * hostapd_driver_get_scan_results(
+ struct hostapd_data *hapd)
+{
+ if (hapd->driver && hapd->driver->get_scan_results2)
+ return hapd->driver->get_scan_results2(hapd->drv_priv);
+ return NULL;
+}
diff --git a/contrib/wpa/src/ap/ap_drv_ops.h b/contrib/wpa/src/ap/ap_drv_ops.h
new file mode 100644
index 0000000..9b75d09
--- /dev/null
+++ b/contrib/wpa/src/ap/ap_drv_ops.h
@@ -0,0 +1,67 @@
+/*
+ * hostapd - Driver operations
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef AP_DRV_OPS
+#define AP_DRV_OPS
+
+enum wpa_driver_if_type;
+struct wpa_bss_params;
+struct wpa_driver_scan_params;
+
+void hostapd_set_driver_ops(struct hostapd_driver_ops *ops);
+int hostapd_set_privacy(struct hostapd_data *hapd, int enabled);
+int hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
+ size_t elem_len);
+int hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len);
+int hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len);
+int hostapd_if_add(struct hostapd_data *hapd, enum wpa_driver_if_type type,
+ const char *ifname, const u8 *addr, void *bss_ctx,
+ void **drv_priv, char *force_ifname, u8 *if_addr);
+int hostapd_if_remove(struct hostapd_data *hapd, enum wpa_driver_if_type type,
+ const char *ifname);
+int hostapd_set_ieee8021x(struct hostapd_data *hapd,
+ struct wpa_bss_params *params);
+int hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
+ const u8 *addr, int idx, u8 *seq);
+int hostapd_flush(struct hostapd_data *hapd);
+int hostapd_set_freq(struct hostapd_data *hapd, int mode, int freq,
+ int channel, int ht_enabled, int sec_channel_offset);
+int hostapd_set_rts(struct hostapd_data *hapd, int rts);
+int hostapd_set_frag(struct hostapd_data *hapd, int frag);
+int hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
+ int total_flags, int flags_or, int flags_and);
+int hostapd_set_rate_sets(struct hostapd_data *hapd, int *supp_rates,
+ int *basic_rates, int mode);
+int hostapd_set_country(struct hostapd_data *hapd, const char *country);
+int hostapd_set_cts_protect(struct hostapd_data *hapd, int value);
+int hostapd_set_preamble(struct hostapd_data *hapd, int value);
+int hostapd_set_short_slot_time(struct hostapd_data *hapd, int value);
+int hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
+ int cw_min, int cw_max, int burst_time);
+int hostapd_valid_bss_mask(struct hostapd_data *hapd, const u8 *addr,
+ const u8 *mask);
+struct hostapd_hw_modes *
+hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
+ u16 *flags);
+int hostapd_driver_commit(struct hostapd_data *hapd);
+int hostapd_set_ht_params(struct hostapd_data *hapd,
+ const u8 *ht_capab, size_t ht_capab_len,
+ const u8 *ht_oper, size_t ht_oper_len);
+int hostapd_drv_none(struct hostapd_data *hapd);
+int hostapd_driver_scan(struct hostapd_data *hapd,
+ struct wpa_driver_scan_params *params);
+struct wpa_scan_results * hostapd_driver_get_scan_results(
+ struct hostapd_data *hapd);
+
+#endif /* AP_DRV_OPS */
diff --git a/contrib/wpa/hostapd/ap_list.c b/contrib/wpa/src/ap/ap_list.c
index 4f217dc..5297dbf 100644
--- a/contrib/wpa/hostapd/ap_list.c
+++ b/contrib/wpa/src/ap/ap_list.c
@@ -1,9 +1,8 @@
/*
* hostapd / AP table
- * Copyright (c) 2002-2003, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
* Copyright (c) 2003-2004, Instant802 Networks, Inc.
* Copyright (c) 2006, Devicescape Software, Inc.
- * Copyright (c) 2007-2008, Intel Corporation
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -15,52 +14,19 @@
* See README and COPYING for more details.
*/
-#include "includes.h"
+#include "utils/includes.h"
+#include "utils/common.h"
+#include "utils/eloop.h"
+#include "common/ieee802_11_defs.h"
+#include "common/ieee802_11_common.h"
+#include "drivers/driver.h"
#include "hostapd.h"
+#include "ap_config.h"
#include "ieee802_11.h"
-#include "eloop.h"
-#include "ap_list.h"
-#include "hw_features.h"
+#include "sta_info.h"
#include "beacon.h"
-
-
-struct ieee80211_frame_info {
- u32 version;
- u32 length;
- u64 mactime;
- u64 hosttime;
- u32 phytype;
- u32 channel;
- u32 datarate;
- u32 antenna;
- u32 priority;
- u32 ssi_type;
- u32 ssi_signal;
- u32 ssi_noise;
- u32 preamble;
- u32 encoding;
-
- /* Note: this structure is otherwise identical to capture format used
- * in linux-wlan-ng, but this additional field is used to provide meta
- * data about the frame to hostapd. This was the easiest method for
- * providing this information, but this might change in the future. */
- u32 msg_type;
-} __attribute__ ((packed));
-
-
-enum ieee80211_phytype {
- ieee80211_phytype_fhss_dot11_97 = 1,
- ieee80211_phytype_dsss_dot11_97 = 2,
- ieee80211_phytype_irbaseband = 3,
- ieee80211_phytype_dsss_dot11_b = 4,
- ieee80211_phytype_pbcc_dot11_b = 5,
- ieee80211_phytype_ofdm_dot11_g = 6,
- ieee80211_phytype_pbcc_dot11_g = 7,
- ieee80211_phytype_ofdm_dot11_a = 8,
- ieee80211_phytype_dsss_dot11_turbog = 255,
- ieee80211_phytype_dsss_dot11_turbo = 256,
-};
+#include "ap_list.h"
/* AP list is a double linked list with head->prev pointing to the end of the
@@ -69,29 +35,11 @@ enum ieee80211_phytype {
* in this link will thus be the least recently used entry. */
-static void ap_list_new_ap(struct hostapd_iface *iface, struct ap_info *ap)
-{
- wpa_printf(MSG_DEBUG, "New AP detected: " MACSTR, MAC2STR(ap->addr));
-
- /* TODO: could send a notification message to an external program that
- * would then determine whether a rogue AP has been detected */
-}
-
-
-static void ap_list_expired_ap(struct hostapd_iface *iface, struct ap_info *ap)
-{
- wpa_printf(MSG_DEBUG, "AP info expired: " MACSTR, MAC2STR(ap->addr));
-
- /* TODO: could send a notification message to an external program */
-}
-
-
static int ap_list_beacon_olbc(struct hostapd_iface *iface, struct ap_info *ap)
{
int i;
if (iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G ||
- ap->phytype != ieee80211_phytype_pbcc_dot11_g ||
iface->conf->channel != ap->channel)
return 0;
@@ -108,16 +56,7 @@ static int ap_list_beacon_olbc(struct hostapd_iface *iface, struct ap_info *ap)
}
-#ifdef CONFIG_IEEE80211N
-static int ap_list_beacon_olbc_ht(struct hostapd_iface *iface,
- struct ap_info *ap)
-{
- return !ap->ht_support;
-}
-#endif /* CONFIG_IEEE80211N */
-
-
-struct ap_info * ap_get_ap(struct hostapd_iface *iface, u8 *ap)
+struct ap_info * ap_get_ap(struct hostapd_iface *iface, const u8 *ap)
{
struct ap_info *s;
@@ -257,7 +196,7 @@ int ap_ap_for_each(struct hostapd_iface *iface,
}
-static struct ap_info * ap_ap_add(struct hostapd_iface *iface, u8 *addr)
+static struct ap_info * ap_ap_add(struct hostapd_iface *iface, const u8 *addr)
{
struct ap_info *ap;
@@ -275,8 +214,6 @@ static struct ap_info * ap_ap_add(struct hostapd_iface *iface, u8 *addr)
if (iface->num_ap > iface->conf->ap_table_max_size && ap != ap->prev) {
wpa_printf(MSG_DEBUG, "Removing the least recently used AP "
MACSTR " from AP table", MAC2STR(ap->prev->addr));
- if (iface->conf->passive_scan_interval > 0)
- ap_list_expired_ap(iface, ap->prev);
ap_free_ap(iface, ap->prev);
}
@@ -285,7 +222,7 @@ static struct ap_info * ap_ap_add(struct hostapd_iface *iface, u8 *addr)
void ap_list_process_beacon(struct hostapd_iface *iface,
- struct ieee80211_mgmt *mgmt,
+ const struct ieee80211_mgmt *mgmt,
struct ieee802_11_elems *elems,
struct hostapd_frame_info *fi)
{
@@ -357,15 +294,11 @@ void ap_list_process_beacon(struct hostapd_iface *iface,
ap->num_beacons++;
time(&ap->last_beacon);
if (fi) {
- ap->phytype = fi->phytype;
ap->ssi_signal = fi->ssi_signal;
ap->datarate = fi->datarate;
}
- if (new_ap) {
- if (iface->conf->passive_scan_interval > 0)
- ap_list_new_ap(iface, ap);
- } else if (ap != iface->ap_list) {
+ if (!new_ap && ap != iface->ap_list) {
/* move AP entry into the beginning of the list so that the
* oldest entry is always in the end of the list */
ap_ap_list_del(iface, ap);
@@ -381,7 +314,7 @@ void ap_list_process_beacon(struct hostapd_iface *iface,
}
#ifdef CONFIG_IEEE80211N
- if (!iface->olbc_ht && ap_list_beacon_olbc_ht(iface, ap)) {
+ if (!iface->olbc_ht && !ap->ht_support) {
iface->olbc_ht = 1;
hostapd_ht_operation_update(iface);
wpa_printf(MSG_DEBUG, "OLBC HT AP detected: " MACSTR
@@ -409,18 +342,12 @@ static void ap_list_timer(void *eloop_ctx, void *timeout_ctx)
time(&now);
- /* FIX: it looks like jkm-Purina ended up in busy loop in this
- * function. Apparently, something can still cause a loop in the AP
- * list.. */
-
while (iface->ap_list) {
ap = iface->ap_list->prev;
if (ap->last_beacon + iface->conf->ap_table_expiration_time >=
now)
break;
- if (iface->conf->passive_scan_interval > 0)
- ap_list_expired_ap(iface, ap);
ap_free_ap(iface, ap);
}
@@ -432,10 +359,8 @@ static void ap_list_timer(void *eloop_ctx, void *timeout_ctx)
while (ap && (olbc == 0 || olbc_ht == 0)) {
if (ap_list_beacon_olbc(iface, ap))
olbc = 1;
-#ifdef CONFIG_IEEE80211N
- if (ap_list_beacon_olbc_ht(iface, ap))
+ if (!ap->ht_support)
olbc_ht = 1;
-#endif /* CONFIG_IEEE80211N */
ap = ap->next;
}
if (!olbc && iface->olbc) {
@@ -470,32 +395,3 @@ void ap_list_deinit(struct hostapd_iface *iface)
eloop_cancel_timeout(ap_list_timer, iface, NULL);
hostapd_free_aps(iface);
}
-
-
-int ap_list_reconfig(struct hostapd_iface *iface,
- struct hostapd_config *oldconf)
-{
- time_t now;
- struct ap_info *ap;
-
- if (iface->conf->ap_table_max_size == oldconf->ap_table_max_size &&
- iface->conf->ap_table_expiration_time ==
- oldconf->ap_table_expiration_time)
- return 0;
-
- time(&now);
-
- while (iface->ap_list) {
- ap = iface->ap_list->prev;
- if (iface->num_ap <= iface->conf->ap_table_max_size &&
- ap->last_beacon + iface->conf->ap_table_expiration_time >=
- now)
- break;
-
- if (iface->conf->passive_scan_interval > 0)
- ap_list_expired_ap(iface, iface->ap_list->prev);
- ap_free_ap(iface, iface->ap_list->prev);
- }
-
- return 0;
-}
diff --git a/contrib/wpa/hostapd/ap_list.h b/contrib/wpa/src/ap/ap_list.h
index 93704f8..f49f58b 100644
--- a/contrib/wpa/hostapd/ap_list.h
+++ b/contrib/wpa/src/ap/ap_list.h
@@ -3,7 +3,6 @@
* Copyright (c) 2002-2003, Jouni Malinen <j@w1.fi>
* Copyright (c) 2003-2004, Instant802 Networks, Inc.
* Copyright (c) 2006, Devicescape Software, Inc.
- * Copyright (c) 2007-2008, Intel Corporation
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -39,7 +38,6 @@ struct ap_info {
int wpa;
int erp; /* ERP Info or -1 if ERP info element not present */
- int phytype; /* .11a / .11b / .11g / Atheros Turbo */
int channel;
int datarate; /* in 100 kbps */
int ssi_signal;
@@ -56,16 +54,25 @@ struct ap_info {
struct ieee802_11_elems;
struct hostapd_frame_info;
-struct ap_info * ap_get_ap(struct hostapd_iface *iface, u8 *sta);
+struct ap_info * ap_get_ap(struct hostapd_iface *iface, const u8 *sta);
int ap_ap_for_each(struct hostapd_iface *iface,
int (*func)(struct ap_info *s, void *data), void *data);
void ap_list_process_beacon(struct hostapd_iface *iface,
- struct ieee80211_mgmt *mgmt,
+ const struct ieee80211_mgmt *mgmt,
struct ieee802_11_elems *elems,
struct hostapd_frame_info *fi);
+#ifdef NEED_AP_MLME
int ap_list_init(struct hostapd_iface *iface);
void ap_list_deinit(struct hostapd_iface *iface);
-int ap_list_reconfig(struct hostapd_iface *iface,
- struct hostapd_config *oldconf);
+#else /* NEED_AP_MLME */
+static inline int ap_list_init(struct hostapd_iface *iface)
+{
+ return 0;
+}
+
+static inline void ap_list_deinit(struct hostapd_iface *iface)
+{
+}
+#endif /* NEED_AP_MLME */
#endif /* AP_LIST_H */
diff --git a/contrib/wpa/hostapd/mlme.c b/contrib/wpa/src/ap/ap_mlme.c
index d883931..2b09b11 100644
--- a/contrib/wpa/hostapd/mlme.c
+++ b/contrib/wpa/src/ap/ap_mlme.c
@@ -14,14 +14,17 @@
* See README and COPYING for more details.
*/
-#include "includes.h"
+#include "utils/includes.h"
-#include "hostapd.h"
+#include "utils/common.h"
+#include "common/ieee802_11_defs.h"
#include "ieee802_11.h"
-#include "wpa.h"
-#include "mlme.h"
+#include "wpa_auth.h"
+#include "sta_info.h"
+#include "ap_mlme.h"
+#ifndef CONFIG_NO_HOSTAPD_LOGGER
static const char * mlme_auth_alg_str(int alg)
{
switch (alg) {
@@ -35,6 +38,7 @@ static const char * mlme_auth_alg_str(int alg)
return "unknown";
}
+#endif /* CONFIG_NO_HOSTAPD_LOGGER */
/**
diff --git a/contrib/wpa/hostapd/mlme.h b/contrib/wpa/src/ap/ap_mlme.h
index c77a939..c77a939 100644
--- a/contrib/wpa/hostapd/mlme.h
+++ b/contrib/wpa/src/ap/ap_mlme.h
diff --git a/contrib/wpa/src/ap/authsrv.c b/contrib/wpa/src/ap/authsrv.c
new file mode 100644
index 0000000..0ab0668
--- /dev/null
+++ b/contrib/wpa/src/ap/authsrv.c
@@ -0,0 +1,216 @@
+/*
+ * Authentication server setup
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "utils/includes.h"
+
+#include "utils/common.h"
+#include "crypto/tls.h"
+#include "eap_server/eap.h"
+#include "eap_server/eap_sim_db.h"
+#include "eapol_auth/eapol_auth_sm.h"
+#include "radius/radius_server.h"
+#include "hostapd.h"
+#include "ap_config.h"
+#include "sta_info.h"
+#include "authsrv.h"
+
+
+#if defined(EAP_SERVER_SIM) || defined(EAP_SERVER_AKA)
+#define EAP_SIM_DB
+#endif /* EAP_SERVER_SIM || EAP_SERVER_AKA */
+
+
+#ifdef EAP_SIM_DB
+static int hostapd_sim_db_cb_sta(struct hostapd_data *hapd,
+ struct sta_info *sta, void *ctx)
+{
+ if (eapol_auth_eap_pending_cb(sta->eapol_sm, ctx) == 0)
+ return 1;
+ return 0;
+}
+
+
+static void hostapd_sim_db_cb(void *ctx, void *session_ctx)
+{
+ struct hostapd_data *hapd = ctx;
+ if (ap_for_each_sta(hapd, hostapd_sim_db_cb_sta, session_ctx) == 0) {
+#ifdef RADIUS_SERVER
+ radius_server_eap_pending_cb(hapd->radius_srv, session_ctx);
+#endif /* RADIUS_SERVER */
+ }
+}
+#endif /* EAP_SIM_DB */
+
+
+#ifdef RADIUS_SERVER
+
+static int hostapd_radius_get_eap_user(void *ctx, const u8 *identity,
+ size_t identity_len, int phase2,
+ struct eap_user *user)
+{
+ const struct hostapd_eap_user *eap_user;
+ int i, count;
+
+ eap_user = hostapd_get_eap_user(ctx, identity, identity_len, phase2);
+ if (eap_user == NULL)
+ return -1;
+
+ if (user == NULL)
+ return 0;
+
+ os_memset(user, 0, sizeof(*user));
+ count = EAP_USER_MAX_METHODS;
+ if (count > EAP_MAX_METHODS)
+ count = EAP_MAX_METHODS;
+ for (i = 0; i < count; i++) {
+ user->methods[i].vendor = eap_user->methods[i].vendor;
+ user->methods[i].method = eap_user->methods[i].method;
+ }
+
+ if (eap_user->password) {
+ user->password = os_malloc(eap_user->password_len);
+ if (user->password == NULL)
+ return -1;
+ os_memcpy(user->password, eap_user->password,
+ eap_user->password_len);
+ user->password_len = eap_user->password_len;
+ user->password_hash = eap_user->password_hash;
+ }
+ user->force_version = eap_user->force_version;
+ user->ttls_auth = eap_user->ttls_auth;
+
+ return 0;
+}
+
+
+static int hostapd_setup_radius_srv(struct hostapd_data *hapd)
+{
+ struct radius_server_conf srv;
+ struct hostapd_bss_config *conf = hapd->conf;
+ os_memset(&srv, 0, sizeof(srv));
+ srv.client_file = conf->radius_server_clients;
+ srv.auth_port = conf->radius_server_auth_port;
+ srv.conf_ctx = conf;
+ srv.eap_sim_db_priv = hapd->eap_sim_db_priv;
+ srv.ssl_ctx = hapd->ssl_ctx;
+ srv.msg_ctx = hapd->msg_ctx;
+ srv.pac_opaque_encr_key = conf->pac_opaque_encr_key;
+ srv.eap_fast_a_id = conf->eap_fast_a_id;
+ srv.eap_fast_a_id_len = conf->eap_fast_a_id_len;
+ srv.eap_fast_a_id_info = conf->eap_fast_a_id_info;
+ srv.eap_fast_prov = conf->eap_fast_prov;
+ srv.pac_key_lifetime = conf->pac_key_lifetime;
+ srv.pac_key_refresh_time = conf->pac_key_refresh_time;
+ srv.eap_sim_aka_result_ind = conf->eap_sim_aka_result_ind;
+ srv.tnc = conf->tnc;
+ srv.wps = hapd->wps;
+ srv.ipv6 = conf->radius_server_ipv6;
+ srv.get_eap_user = hostapd_radius_get_eap_user;
+ srv.eap_req_id_text = conf->eap_req_id_text;
+ srv.eap_req_id_text_len = conf->eap_req_id_text_len;
+
+ hapd->radius_srv = radius_server_init(&srv);
+ if (hapd->radius_srv == NULL) {
+ wpa_printf(MSG_ERROR, "RADIUS server initialization failed.");
+ return -1;
+ }
+
+ return 0;
+}
+
+#endif /* RADIUS_SERVER */
+
+
+int authsrv_init(struct hostapd_data *hapd)
+{
+#ifdef EAP_TLS_FUNCS
+ if (hapd->conf->eap_server &&
+ (hapd->conf->ca_cert || hapd->conf->server_cert ||
+ hapd->conf->dh_file)) {
+ struct tls_connection_params params;
+
+ hapd->ssl_ctx = tls_init(NULL);
+ if (hapd->ssl_ctx == NULL) {
+ wpa_printf(MSG_ERROR, "Failed to initialize TLS");
+ authsrv_deinit(hapd);
+ return -1;
+ }
+
+ os_memset(&params, 0, sizeof(params));
+ params.ca_cert = hapd->conf->ca_cert;
+ params.client_cert = hapd->conf->server_cert;
+ params.private_key = hapd->conf->private_key;
+ params.private_key_passwd = hapd->conf->private_key_passwd;
+ params.dh_file = hapd->conf->dh_file;
+
+ if (tls_global_set_params(hapd->ssl_ctx, &params)) {
+ wpa_printf(MSG_ERROR, "Failed to set TLS parameters");
+ authsrv_deinit(hapd);
+ return -1;
+ }
+
+ if (tls_global_set_verify(hapd->ssl_ctx,
+ hapd->conf->check_crl)) {
+ wpa_printf(MSG_ERROR, "Failed to enable check_crl");
+ authsrv_deinit(hapd);
+ return -1;
+ }
+ }
+#endif /* EAP_TLS_FUNCS */
+
+#ifdef EAP_SIM_DB
+ if (hapd->conf->eap_sim_db) {
+ hapd->eap_sim_db_priv =
+ eap_sim_db_init(hapd->conf->eap_sim_db,
+ hostapd_sim_db_cb, hapd);
+ if (hapd->eap_sim_db_priv == NULL) {
+ wpa_printf(MSG_ERROR, "Failed to initialize EAP-SIM "
+ "database interface");
+ authsrv_deinit(hapd);
+ return -1;
+ }
+ }
+#endif /* EAP_SIM_DB */
+
+#ifdef RADIUS_SERVER
+ if (hapd->conf->radius_server_clients &&
+ hostapd_setup_radius_srv(hapd))
+ return -1;
+#endif /* RADIUS_SERVER */
+
+ return 0;
+}
+
+
+void authsrv_deinit(struct hostapd_data *hapd)
+{
+#ifdef RADIUS_SERVER
+ radius_server_deinit(hapd->radius_srv);
+ hapd->radius_srv = NULL;
+#endif /* RADIUS_SERVER */
+
+#ifdef EAP_TLS_FUNCS
+ if (hapd->ssl_ctx) {
+ tls_deinit(hapd->ssl_ctx);
+ hapd->ssl_ctx = NULL;
+ }
+#endif /* EAP_TLS_FUNCS */
+
+#ifdef EAP_SIM_DB
+ if (hapd->eap_sim_db_priv) {
+ eap_sim_db_deinit(hapd->eap_sim_db_priv);
+ hapd->eap_sim_db_priv = NULL;
+ }
+#endif /* EAP_SIM_DB */
+}
diff --git a/contrib/wpa/src/ap/authsrv.h b/contrib/wpa/src/ap/authsrv.h
new file mode 100644
index 0000000..be3051e
--- /dev/null
+++ b/contrib/wpa/src/ap/authsrv.h
@@ -0,0 +1,21 @@
+/*
+ * Authentication server setup
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef AUTHSRV_H
+#define AUTHSRV_H
+
+int authsrv_init(struct hostapd_data *hapd);
+void authsrv_deinit(struct hostapd_data *hapd);
+
+#endif /* AUTHSRV_H */
diff --git a/contrib/wpa/hostapd/beacon.c b/contrib/wpa/src/ap/beacon.c
index 1f82d9c..004cc8a 100644
--- a/contrib/wpa/hostapd/beacon.c
+++ b/contrib/wpa/src/ap/beacon.c
@@ -2,8 +2,7 @@
* hostapd / IEEE 802.11 Management: Beacon and Probe Request/Response
* Copyright (c) 2002-2004, Instant802 Networks, Inc.
* Copyright (c) 2005-2006, Devicescape Software, Inc.
- * Copyright (c) 2008, Jouni Malinen <j@w1.fi>
- * Copyright (c) 2007-2008, Intel Corporation
+ * Copyright (c) 2008-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -15,19 +14,21 @@
* See README and COPYING for more details.
*/
-#include "includes.h"
+#include "utils/includes.h"
#ifndef CONFIG_NATIVE_WINDOWS
+#include "utils/common.h"
+#include "common/ieee802_11_defs.h"
+#include "common/ieee802_11_common.h"
+#include "drivers/driver.h"
#include "hostapd.h"
#include "ieee802_11.h"
-#include "wpa.h"
-#include "wme.h"
-#include "beacon.h"
-#include "hw_features.h"
-#include "driver.h"
+#include "wpa_auth.h"
+#include "wmm.h"
+#include "ap_config.h"
#include "sta_info.h"
-#include "wps_hostapd.h"
+#include "beacon.h"
static u8 ieee802_11_erp_info(struct hostapd_data *hapd)
@@ -56,7 +57,8 @@ static u8 ieee802_11_erp_info(struct hostapd_data *hapd)
}
break;
}
- if (hapd->iface->num_sta_no_short_preamble > 0)
+ if (hapd->iface->num_sta_no_short_preamble > 0 ||
+ hapd->iconf->preamble == LONG_PREAMBLE)
erp |= ERP_INFO_BARKER_PREAMBLE_MODE;
return erp;
@@ -191,20 +193,26 @@ static u8 * hostapd_eid_wpa(struct hostapd_data *hapd, u8 *eid, size_t len,
}
-void handle_probe_req(struct hostapd_data *hapd, struct ieee80211_mgmt *mgmt,
- size_t len)
+void handle_probe_req(struct hostapd_data *hapd,
+ const struct ieee80211_mgmt *mgmt, size_t len)
{
struct ieee80211_mgmt *resp;
struct ieee802_11_elems elems;
char *ssid;
- u8 *pos, *epos, *ie;
+ u8 *pos, *epos;
+ const u8 *ie;
size_t ssid_len, ie_len;
struct sta_info *sta = NULL;
+ size_t buflen;
+ size_t i;
ie = mgmt->u.probe_req.variable;
ie_len = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req));
- hostapd_wps_probe_req_rx(hapd, mgmt->sa, ie, ie_len);
+ for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
+ if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
+ mgmt->sa, ie, ie_len) > 0)
+ return;
if (!hapd->iconf->send_probe_response)
return;
@@ -258,7 +266,12 @@ void handle_probe_req(struct hostapd_data *hapd, struct ieee80211_mgmt *mgmt,
/* TODO: verify that supp_rates contains at least one matching rate
* with AP configuration */
#define MAX_PROBERESP_LEN 768
- resp = os_zalloc(MAX_PROBERESP_LEN);
+ buflen = MAX_PROBERESP_LEN;
+#ifdef CONFIG_WPS
+ if (hapd->wps_probe_resp_ie)
+ buflen += wpabuf_len(hapd->wps_probe_resp_ie);
+#endif /* CONFIG_WPS */
+ resp = os_zalloc(buflen);
if (resp == NULL)
return;
epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
@@ -296,23 +309,26 @@ void handle_probe_req(struct hostapd_data *hapd, struct ieee80211_mgmt *mgmt,
/* Extended supported rates */
pos = hostapd_eid_ext_supp_rates(hapd, pos);
+ /* RSN, MDIE, WPA */
pos = hostapd_eid_wpa(hapd, pos, epos - pos, sta);
+#ifdef CONFIG_IEEE80211N
+ pos = hostapd_eid_ht_capabilities(hapd, pos);
+ pos = hostapd_eid_ht_operation(hapd, pos);
+#endif /* CONFIG_IEEE80211N */
+
/* Wi-Fi Alliance WMM */
pos = hostapd_eid_wmm(hapd, pos);
- pos = hostapd_eid_ht_capabilities_info(hapd, pos);
- pos = hostapd_eid_ht_operation(hapd, pos);
-
#ifdef CONFIG_WPS
if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
- os_memcpy(pos, hapd->wps_probe_resp_ie,
- hapd->wps_probe_resp_ie_len);
- pos += hapd->wps_probe_resp_ie_len;
+ os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
+ wpabuf_len(hapd->wps_probe_resp_ie));
+ pos += wpabuf_len(hapd->wps_probe_resp_ie);
}
#endif /* CONFIG_WPS */
- if (hostapd_send_mgmt_frame(hapd, resp, pos - (u8 *) resp, 0) < 0)
+ if (hapd->drv.send_mgmt_frame(hapd, resp, pos - (u8 *) resp) < 0)
perror("handle_probe_req: send");
os_free(resp);
@@ -327,16 +343,18 @@ void ieee802_11_set_beacon(struct hostapd_data *hapd)
{
struct ieee80211_mgmt *head;
u8 *pos, *tail, *tailpos;
- int preamble;
u16 capab_info;
size_t head_len, tail_len;
- int cts_protection = ((ieee802_11_erp_info(hapd) &
- ERP_INFO_USE_PROTECTION) ? 1 : 0);
#define BEACON_HEAD_BUF_SIZE 256
#define BEACON_TAIL_BUF_SIZE 512
head = os_zalloc(BEACON_HEAD_BUF_SIZE);
- tailpos = tail = os_malloc(BEACON_TAIL_BUF_SIZE);
+ tail_len = BEACON_TAIL_BUF_SIZE;
+#ifdef CONFIG_WPS
+ if (hapd->conf->wps_state && hapd->wps_beacon_ie)
+ tail_len += wpabuf_len(hapd->wps_beacon_ie);
+#endif /* CONFIG_WPS */
+ tailpos = tail = os_malloc(tail_len);
if (head == NULL || tail == NULL) {
wpa_printf(MSG_ERROR, "Failed to set beacon data");
os_free(head);
@@ -392,68 +410,39 @@ void ieee802_11_set_beacon(struct hostapd_data *hapd)
/* Extended supported rates */
tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
+ /* RSN, MDIE, WPA */
tailpos = hostapd_eid_wpa(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE -
tailpos, NULL);
- /* Wi-Fi Alliance WMM */
- tailpos = hostapd_eid_wmm(hapd, tailpos);
-
#ifdef CONFIG_IEEE80211N
- if (hapd->iconf->ieee80211n) {
- u8 *ht_capab, *ht_oper;
- ht_capab = tailpos;
- tailpos = hostapd_eid_ht_capabilities_info(hapd, tailpos);
-
- ht_oper = tailpos;
- tailpos = hostapd_eid_ht_operation(hapd, tailpos);
-
- if (tailpos > ht_oper && ht_oper > ht_capab &&
- hostapd_set_ht_params(hapd->conf->iface, hapd,
- ht_capab + 2, ht_capab[1],
- ht_oper + 2, ht_oper[1])) {
- wpa_printf(MSG_ERROR, "Could not set HT capabilities "
- "for kernel driver");
- }
- }
+ tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
+ tailpos = hostapd_eid_ht_operation(hapd, tailpos);
#endif /* CONFIG_IEEE80211N */
+ /* Wi-Fi Alliance WMM */
+ tailpos = hostapd_eid_wmm(hapd, tailpos);
+
#ifdef CONFIG_WPS
if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
- os_memcpy(tailpos, hapd->wps_beacon_ie,
- hapd->wps_beacon_ie_len);
- tailpos += hapd->wps_beacon_ie_len;
+ os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
+ wpabuf_len(hapd->wps_beacon_ie));
+ tailpos += wpabuf_len(hapd->wps_beacon_ie);
}
#endif /* CONFIG_WPS */
tail_len = tailpos > tail ? tailpos - tail : 0;
- if (hostapd_set_beacon(hapd->conf->iface, hapd, (u8 *) head, head_len,
- tail, tail_len))
- wpa_printf(MSG_ERROR, "Failed to set beacon head/tail");
+ if (hapd->drv.set_beacon(hapd, (u8 *) head, head_len,
+ tail, tail_len, hapd->conf->dtim_period,
+ hapd->iconf->beacon_int))
+ wpa_printf(MSG_ERROR, "Failed to set beacon head/tail or DTIM "
+ "period");
os_free(tail);
os_free(head);
- if (hostapd_set_cts_protect(hapd, cts_protection))
- wpa_printf(MSG_ERROR, "Failed to set CTS protect in kernel "
- "driver");
-
- if (hapd->iface->current_mode &&
- hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
- hostapd_set_short_slot_time(hapd,
- hapd->iface->num_sta_no_short_slot_time
- > 0 ? 0 : 1))
- wpa_printf(MSG_ERROR, "Failed to set Short Slot Time option "
- "in kernel driver");
-
- if (hapd->iface->num_sta_no_short_preamble == 0 &&
- hapd->iconf->preamble == SHORT_PREAMBLE)
- preamble = SHORT_PREAMBLE;
- else
- preamble = LONG_PREAMBLE;
- if (hostapd_set_preamble(hapd, preamble))
- wpa_printf(MSG_ERROR, "Could not set preamble for kernel "
- "driver");
+ hapd->drv.set_bss_params(hapd, !!(ieee802_11_erp_info(hapd) &
+ ERP_INFO_USE_PROTECTION));
}
diff --git a/contrib/wpa/hostapd/beacon.h b/contrib/wpa/src/ap/beacon.h
index 18e0da2..c1510e1 100644
--- a/contrib/wpa/hostapd/beacon.h
+++ b/contrib/wpa/src/ap/beacon.h
@@ -16,9 +16,21 @@
#ifndef BEACON_H
#define BEACON_H
-void handle_probe_req(struct hostapd_data *hapd, struct ieee80211_mgmt *mgmt,
- size_t len);
+struct ieee80211_mgmt;
+
+void handle_probe_req(struct hostapd_data *hapd,
+ const struct ieee80211_mgmt *mgmt, size_t len);
+#ifdef NEED_AP_MLME
void ieee802_11_set_beacon(struct hostapd_data *hapd);
void ieee802_11_set_beacons(struct hostapd_iface *iface);
+#else /* NEED_AP_MLME */
+static inline void ieee802_11_set_beacon(struct hostapd_data *hapd)
+{
+}
+
+static inline void ieee802_11_set_beacons(struct hostapd_iface *iface)
+{
+}
+#endif /* NEED_AP_MLME */
#endif /* BEACON_H */
diff --git a/contrib/wpa/src/ap/ctrl_iface_ap.c b/contrib/wpa/src/ap/ctrl_iface_ap.c
new file mode 100644
index 0000000..e50b0a7
--- /dev/null
+++ b/contrib/wpa/src/ap/ctrl_iface_ap.c
@@ -0,0 +1,104 @@
+/*
+ * Control interface for shared AP commands
+ * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "utils/includes.h"
+
+#include "utils/common.h"
+#include "hostapd.h"
+#include "ieee802_1x.h"
+#include "wpa_auth.h"
+#include "ieee802_11.h"
+#include "sta_info.h"
+#include "wps_hostapd.h"
+#include "ctrl_iface_ap.h"
+
+
+static int hostapd_ctrl_iface_sta_mib(struct hostapd_data *hapd,
+ struct sta_info *sta,
+ char *buf, size_t buflen)
+{
+ int len, res, ret;
+
+ if (sta == NULL) {
+ ret = os_snprintf(buf, buflen, "FAIL\n");
+ if (ret < 0 || (size_t) ret >= buflen)
+ return 0;
+ return ret;
+ }
+
+ len = 0;
+ ret = os_snprintf(buf + len, buflen - len, MACSTR "\n",
+ MAC2STR(sta->addr));
+ if (ret < 0 || (size_t) ret >= buflen - len)
+ return len;
+ len += ret;
+
+ res = ieee802_11_get_mib_sta(hapd, sta, buf + len, buflen - len);
+ if (res >= 0)
+ len += res;
+ res = wpa_get_mib_sta(sta->wpa_sm, buf + len, buflen - len);
+ if (res >= 0)
+ len += res;
+ res = ieee802_1x_get_mib_sta(hapd, sta, buf + len, buflen - len);
+ if (res >= 0)
+ len += res;
+ res = hostapd_wps_get_mib_sta(hapd, sta->addr, buf + len,
+ buflen - len);
+ if (res >= 0)
+ len += res;
+
+ return len;
+}
+
+
+int hostapd_ctrl_iface_sta_first(struct hostapd_data *hapd,
+ char *buf, size_t buflen)
+{
+ return hostapd_ctrl_iface_sta_mib(hapd, hapd->sta_list, buf, buflen);
+}
+
+
+int hostapd_ctrl_iface_sta(struct hostapd_data *hapd, const char *txtaddr,
+ char *buf, size_t buflen)
+{
+ u8 addr[ETH_ALEN];
+ int ret;
+
+ if (hwaddr_aton(txtaddr, addr)) {
+ ret = os_snprintf(buf, buflen, "FAIL\n");
+ if (ret < 0 || (size_t) ret >= buflen)
+ return 0;
+ return ret;
+ }
+ return hostapd_ctrl_iface_sta_mib(hapd, ap_get_sta(hapd, addr),
+ buf, buflen);
+}
+
+
+int hostapd_ctrl_iface_sta_next(struct hostapd_data *hapd, const char *txtaddr,
+ char *buf, size_t buflen)
+{
+ u8 addr[ETH_ALEN];
+ struct sta_info *sta;
+ int ret;
+
+ if (hwaddr_aton(txtaddr, addr) ||
+ (sta = ap_get_sta(hapd, addr)) == NULL) {
+ ret = os_snprintf(buf, buflen, "FAIL\n");
+ if (ret < 0 || (size_t) ret >= buflen)
+ return 0;
+ return ret;
+ }
+ return hostapd_ctrl_iface_sta_mib(hapd, sta->next, buf, buflen);
+}
diff --git a/contrib/wpa/src/ap/ctrl_iface_ap.h b/contrib/wpa/src/ap/ctrl_iface_ap.h
new file mode 100644
index 0000000..8690bea
--- /dev/null
+++ b/contrib/wpa/src/ap/ctrl_iface_ap.h
@@ -0,0 +1,25 @@
+/*
+ * Control interface for shared AP commands
+ * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef CTRL_IFACE_AP_H
+#define CTRL_IFACE_AP_H
+
+int hostapd_ctrl_iface_sta_first(struct hostapd_data *hapd,
+ char *buf, size_t buflen);
+int hostapd_ctrl_iface_sta(struct hostapd_data *hapd, const char *txtaddr,
+ char *buf, size_t buflen);
+int hostapd_ctrl_iface_sta_next(struct hostapd_data *hapd, const char *txtaddr,
+ char *buf, size_t buflen);
+
+#endif /* CTRL_IFACE_AP_H */
diff --git a/contrib/wpa/src/ap/drv_callbacks.c b/contrib/wpa/src/ap/drv_callbacks.c
new file mode 100644
index 0000000..26ef584
--- /dev/null
+++ b/contrib/wpa/src/ap/drv_callbacks.c
@@ -0,0 +1,457 @@
+/*
+ * hostapd / Callback functions for driver wrappers
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "utils/includes.h"
+
+#include "utils/common.h"
+#include "radius/radius.h"
+#include "drivers/driver.h"
+#include "common/ieee802_11_defs.h"
+#include "common/ieee802_11_common.h"
+#include "common/wpa_ctrl.h"
+#include "hostapd.h"
+#include "ieee802_11.h"
+#include "sta_info.h"
+#include "accounting.h"
+#include "tkip_countermeasures.h"
+#include "iapp.h"
+#include "ieee802_1x.h"
+#include "wpa_auth.h"
+#include "wmm.h"
+#include "wps_hostapd.h"
+#include "ap_config.h"
+
+
+int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
+ const u8 *ie, size_t ielen)
+{
+ struct sta_info *sta;
+ int new_assoc, res;
+ struct ieee802_11_elems elems;
+
+ if (addr == NULL) {
+ /*
+ * This could potentially happen with unexpected event from the
+ * driver wrapper. This was seen at least in one case where the
+ * driver ended up being set to station mode while hostapd was
+ * running, so better make sure we stop processing such an
+ * event here.
+ */
+ wpa_printf(MSG_DEBUG, "hostapd_notif_assoc: Skip event with "
+ "no address");
+ return -1;
+ }
+
+ hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
+ HOSTAPD_LEVEL_INFO, "associated");
+
+ ieee802_11_parse_elems(ie, ielen, &elems, 0);
+ if (elems.wps_ie) {
+ ie = elems.wps_ie - 2;
+ ielen = elems.wps_ie_len + 2;
+ wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)AssocReq");
+ } else if (elems.rsn_ie) {
+ ie = elems.rsn_ie - 2;
+ ielen = elems.rsn_ie_len + 2;
+ wpa_printf(MSG_DEBUG, "STA included RSN IE in (Re)AssocReq");
+ } else if (elems.wpa_ie) {
+ ie = elems.wpa_ie - 2;
+ ielen = elems.wpa_ie_len + 2;
+ wpa_printf(MSG_DEBUG, "STA included WPA IE in (Re)AssocReq");
+ } else {
+ ie = NULL;
+ ielen = 0;
+ wpa_printf(MSG_DEBUG, "STA did not include WPS/RSN/WPA IE in "
+ "(Re)AssocReq");
+ }
+
+ sta = ap_get_sta(hapd, addr);
+ if (sta) {
+ accounting_sta_stop(hapd, sta);
+ } else {
+ sta = ap_sta_add(hapd, addr);
+ if (sta == NULL)
+ return -1;
+ }
+ sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS);
+
+ if (hapd->conf->wpa) {
+ if (ie == NULL || ielen == 0) {
+ if (hapd->conf->wps_state) {
+ wpa_printf(MSG_DEBUG, "STA did not include "
+ "WPA/RSN IE in (Re)Association "
+ "Request - possible WPS use");
+ sta->flags |= WLAN_STA_MAYBE_WPS;
+ goto skip_wpa_check;
+ }
+
+ wpa_printf(MSG_DEBUG, "No WPA/RSN IE from STA");
+ return -1;
+ }
+ if (hapd->conf->wps_state && ie[0] == 0xdd && ie[1] >= 4 &&
+ os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) {
+ sta->flags |= WLAN_STA_WPS;
+ goto skip_wpa_check;
+ }
+
+ if (sta->wpa_sm == NULL)
+ sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
+ sta->addr);
+ if (sta->wpa_sm == NULL) {
+ wpa_printf(MSG_ERROR, "Failed to initialize WPA state "
+ "machine");
+ return -1;
+ }
+ res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
+ ie, ielen, NULL, 0);
+ if (res != WPA_IE_OK) {
+ int resp;
+ wpa_printf(MSG_DEBUG, "WPA/RSN information element "
+ "rejected? (res %u)", res);
+ wpa_hexdump(MSG_DEBUG, "IE", ie, ielen);
+ if (res == WPA_INVALID_GROUP)
+ resp = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
+ else if (res == WPA_INVALID_PAIRWISE)
+ resp = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID;
+ else if (res == WPA_INVALID_AKMP)
+ resp = WLAN_REASON_AKMP_NOT_VALID;
+#ifdef CONFIG_IEEE80211W
+ else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
+ resp = WLAN_REASON_INVALID_IE;
+ else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
+ resp = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
+#endif /* CONFIG_IEEE80211W */
+ else
+ resp = WLAN_REASON_INVALID_IE;
+ hapd->drv.sta_disassoc(hapd, sta->addr, resp);
+ ap_free_sta(hapd, sta);
+ return -1;
+ }
+ } else if (hapd->conf->wps_state) {
+ if (ie && ielen > 4 && ie[0] == 0xdd && ie[1] >= 4 &&
+ os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) {
+ sta->flags |= WLAN_STA_WPS;
+ } else
+ sta->flags |= WLAN_STA_MAYBE_WPS;
+ }
+skip_wpa_check:
+
+ new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
+ sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
+ wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
+
+ hostapd_new_assoc_sta(hapd, sta, !new_assoc);
+
+ ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
+
+ return 0;
+}
+
+
+void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr)
+{
+ struct sta_info *sta;
+
+ hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
+ HOSTAPD_LEVEL_INFO, "disassociated");
+
+ sta = ap_get_sta(hapd, addr);
+ if (sta == NULL) {
+ wpa_printf(MSG_DEBUG, "Disassociation notification for "
+ "unknown STA " MACSTR, MAC2STR(addr));
+ return;
+ }
+
+ sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
+ wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED MACSTR,
+ MAC2STR(sta->addr));
+ wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
+ sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
+ ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
+ ap_free_sta(hapd, sta);
+}
+
+
+#ifdef HOSTAPD
+
+#ifdef NEED_AP_MLME
+
+static const u8 * get_hdr_bssid(const struct ieee80211_hdr *hdr, size_t len)
+{
+ u16 fc, type, stype;
+
+ /*
+ * PS-Poll frames are 16 bytes. All other frames are
+ * 24 bytes or longer.
+ */
+ if (len < 16)
+ return NULL;
+
+ fc = le_to_host16(hdr->frame_control);
+ type = WLAN_FC_GET_TYPE(fc);
+ stype = WLAN_FC_GET_STYPE(fc);
+
+ switch (type) {
+ case WLAN_FC_TYPE_DATA:
+ if (len < 24)
+ return NULL;
+ switch (fc & (WLAN_FC_FROMDS | WLAN_FC_TODS)) {
+ case WLAN_FC_FROMDS | WLAN_FC_TODS:
+ case WLAN_FC_TODS:
+ return hdr->addr1;
+ case WLAN_FC_FROMDS:
+ return hdr->addr2;
+ default:
+ return NULL;
+ }
+ case WLAN_FC_TYPE_CTRL:
+ if (stype != WLAN_FC_STYPE_PSPOLL)
+ return NULL;
+ return hdr->addr1;
+ case WLAN_FC_TYPE_MGMT:
+ return hdr->addr3;
+ default:
+ return NULL;
+ }
+}
+
+
+#define HAPD_BROADCAST ((struct hostapd_data *) -1)
+
+static struct hostapd_data * get_hapd_bssid(struct hostapd_iface *iface,
+ const u8 *bssid)
+{
+ size_t i;
+
+ if (bssid == NULL)
+ return NULL;
+ if (bssid[0] == 0xff && bssid[1] == 0xff && bssid[2] == 0xff &&
+ bssid[3] == 0xff && bssid[4] == 0xff && bssid[5] == 0xff)
+ return HAPD_BROADCAST;
+
+ for (i = 0; i < iface->num_bss; i++) {
+ if (os_memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0)
+ return iface->bss[i];
+ }
+
+ return NULL;
+}
+
+
+static void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd,
+ const u8 *frame, size_t len)
+{
+ const struct ieee80211_hdr *hdr = (const struct ieee80211_hdr *) frame;
+ u16 fc = le_to_host16(hdr->frame_control);
+ hapd = get_hapd_bssid(hapd->iface, get_hdr_bssid(hdr, len));
+ if (hapd == NULL || hapd == HAPD_BROADCAST)
+ return;
+
+ ieee802_11_rx_from_unknown(hapd, hdr->addr2,
+ (fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) ==
+ (WLAN_FC_TODS | WLAN_FC_FROMDS));
+}
+
+
+static void hostapd_mgmt_rx(struct hostapd_data *hapd, struct rx_mgmt *rx_mgmt)
+{
+ struct hostapd_iface *iface = hapd->iface;
+ const struct ieee80211_hdr *hdr;
+ const u8 *bssid;
+ struct hostapd_frame_info fi;
+
+ hdr = (const struct ieee80211_hdr *) rx_mgmt->frame;
+ bssid = get_hdr_bssid(hdr, rx_mgmt->frame_len);
+ if (bssid == NULL)
+ return;
+
+ hapd = get_hapd_bssid(iface, bssid);
+ if (hapd == NULL) {
+ u16 fc;
+ fc = le_to_host16(hdr->frame_control);
+
+ /*
+ * Drop frames to unknown BSSIDs except for Beacon frames which
+ * could be used to update neighbor information.
+ */
+ if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
+ WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
+ hapd = iface->bss[0];
+ else
+ return;
+ }
+
+ os_memset(&fi, 0, sizeof(fi));
+ fi.datarate = rx_mgmt->datarate;
+ fi.ssi_signal = rx_mgmt->ssi_signal;
+
+ if (hapd == HAPD_BROADCAST) {
+ size_t i;
+ for (i = 0; i < iface->num_bss; i++)
+ ieee802_11_mgmt(iface->bss[i], rx_mgmt->frame,
+ rx_mgmt->frame_len, &fi);
+ } else
+ ieee802_11_mgmt(hapd, rx_mgmt->frame, rx_mgmt->frame_len, &fi);
+}
+
+
+static void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, const u8 *buf,
+ size_t len, u16 stype, int ok)
+{
+ struct ieee80211_hdr *hdr;
+ hdr = (struct ieee80211_hdr *) buf;
+ hapd = get_hapd_bssid(hapd->iface, get_hdr_bssid(hdr, len));
+ if (hapd == NULL || hapd == HAPD_BROADCAST)
+ return;
+ ieee802_11_mgmt_cb(hapd, buf, len, stype, ok);
+}
+
+#endif /* NEED_AP_MLME */
+
+
+static int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa,
+ const u8 *ie, size_t ie_len)
+{
+ size_t i;
+ int ret = 0;
+
+ for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) {
+ if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
+ sa, ie, ie_len) > 0) {
+ ret = 1;
+ break;
+ }
+ }
+ return ret;
+}
+
+
+static int hostapd_event_new_sta(struct hostapd_data *hapd, const u8 *addr)
+{
+ struct sta_info *sta = ap_get_sta(hapd, addr);
+ if (sta)
+ return 0;
+
+ wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR
+ " - adding a new STA", MAC2STR(addr));
+ sta = ap_sta_add(hapd, addr);
+ if (sta) {
+ hostapd_new_assoc_sta(hapd, sta, 0);
+ } else {
+ wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR,
+ MAC2STR(addr));
+ return -1;
+ }
+
+ return 0;
+}
+
+
+static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src,
+ const u8 *data, size_t data_len)
+{
+ struct hostapd_iface *iface = hapd->iface;
+ size_t j;
+
+ for (j = 0; j < iface->num_bss; j++) {
+ if (ap_get_sta(iface->bss[j], src)) {
+ hapd = iface->bss[j];
+ break;
+ }
+ }
+
+ ieee802_1x_receive(hapd, src, data, data_len);
+}
+
+
+void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
+ union wpa_event_data *data)
+{
+ struct hostapd_data *hapd = ctx;
+
+ switch (event) {
+ case EVENT_MICHAEL_MIC_FAILURE:
+ michael_mic_failure(hapd, data->michael_mic_failure.src, 1);
+ break;
+ case EVENT_SCAN_RESULTS:
+ if (hapd->iface->scan_cb)
+ hapd->iface->scan_cb(hapd->iface);
+ break;
+#ifdef CONFIG_IEEE80211R
+ case EVENT_FT_RRB_RX:
+ wpa_ft_rrb_rx(hapd->wpa_auth, data->ft_rrb_rx.src,
+ data->ft_rrb_rx.data, data->ft_rrb_rx.data_len);
+ break;
+#endif /* CONFIG_IEEE80211R */
+ case EVENT_WPS_BUTTON_PUSHED:
+ hostapd_wps_button_pushed(hapd);
+ break;
+#ifdef NEED_AP_MLME
+ case EVENT_TX_STATUS:
+ switch (data->tx_status.type) {
+ case WLAN_FC_TYPE_MGMT:
+ hostapd_mgmt_tx_cb(hapd, data->tx_status.data,
+ data->tx_status.data_len,
+ data->tx_status.stype,
+ data->tx_status.ack);
+ break;
+ case WLAN_FC_TYPE_DATA:
+ hostapd_tx_status(hapd, data->tx_status.dst,
+ data->tx_status.data,
+ data->tx_status.data_len,
+ data->tx_status.ack);
+ break;
+ }
+ break;
+ case EVENT_RX_FROM_UNKNOWN:
+ hostapd_rx_from_unknown_sta(hapd, data->rx_from_unknown.frame,
+ data->rx_from_unknown.len);
+ break;
+ case EVENT_RX_MGMT:
+ hostapd_mgmt_rx(hapd, &data->rx_mgmt);
+ break;
+#endif /* NEED_AP_MLME */
+ case EVENT_RX_PROBE_REQ:
+ hostapd_probe_req_rx(hapd, data->rx_probe_req.sa,
+ data->rx_probe_req.ie,
+ data->rx_probe_req.ie_len);
+ break;
+ case EVENT_NEW_STA:
+ hostapd_event_new_sta(hapd, data->new_sta.addr);
+ break;
+ case EVENT_EAPOL_RX:
+ hostapd_event_eapol_rx(hapd, data->eapol_rx.src,
+ data->eapol_rx.data,
+ data->eapol_rx.data_len);
+ break;
+ case EVENT_ASSOC:
+ hostapd_notif_assoc(hapd, data->assoc_info.addr,
+ data->assoc_info.req_ies,
+ data->assoc_info.req_ies_len);
+ break;
+ case EVENT_DISASSOC:
+ if (data)
+ hostapd_notif_disassoc(hapd, data->disassoc_info.addr);
+ break;
+ case EVENT_DEAUTH:
+ if (data)
+ hostapd_notif_disassoc(hapd, data->deauth_info.addr);
+ break;
+ default:
+ wpa_printf(MSG_DEBUG, "Unknown event %d", event);
+ break;
+ }
+}
+
+#endif /* HOSTAPD */
diff --git a/contrib/wpa/src/ap/hostapd.c b/contrib/wpa/src/ap/hostapd.c
new file mode 100644
index 0000000..841f9c5
--- /dev/null
+++ b/contrib/wpa/src/ap/hostapd.c
@@ -0,0 +1,887 @@
+/*
+ * hostapd / Initialization and configuration
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "utils/includes.h"
+
+#include "utils/common.h"
+#include "utils/eloop.h"
+#include "common/ieee802_11_defs.h"
+#include "radius/radius_client.h"
+#include "drivers/driver.h"
+#include "hostapd.h"
+#include "authsrv.h"
+#include "sta_info.h"
+#include "accounting.h"
+#include "ap_list.h"
+#include "beacon.h"
+#include "iapp.h"
+#include "ieee802_1x.h"
+#include "ieee802_11_auth.h"
+#include "vlan_init.h"
+#include "wpa_auth.h"
+#include "wps_hostapd.h"
+#include "hw_features.h"
+#include "wpa_auth_glue.h"
+#include "ap_drv_ops.h"
+#include "ap_config.h"
+
+
+static int hostapd_flush_old_stations(struct hostapd_data *hapd);
+static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd);
+
+extern int wpa_debug_level;
+
+
+int hostapd_reload_config(struct hostapd_iface *iface)
+{
+ struct hostapd_data *hapd = iface->bss[0];
+ struct hostapd_config *newconf, *oldconf;
+ size_t j;
+
+ if (iface->config_read_cb == NULL)
+ return -1;
+ newconf = iface->config_read_cb(iface->config_fname);
+ if (newconf == NULL)
+ return -1;
+
+ /*
+ * Deauthenticate all stations since the new configuration may not
+ * allow them to use the BSS anymore.
+ */
+ for (j = 0; j < iface->num_bss; j++)
+ hostapd_flush_old_stations(iface->bss[j]);
+
+#ifndef CONFIG_NO_RADIUS
+ /* TODO: update dynamic data based on changed configuration
+ * items (e.g., open/close sockets, etc.) */
+ radius_client_flush(hapd->radius, 0);
+#endif /* CONFIG_NO_RADIUS */
+
+ oldconf = hapd->iconf;
+ hapd->iconf = newconf;
+ hapd->conf = &newconf->bss[0];
+ iface->conf = newconf;
+
+ if (hostapd_setup_wpa_psk(hapd->conf)) {
+ wpa_printf(MSG_ERROR, "Failed to re-configure WPA PSK "
+ "after reloading configuration");
+ }
+
+ if (hapd->conf->ieee802_1x || hapd->conf->wpa)
+ hapd->drv.set_drv_ieee8021x(hapd, hapd->conf->iface, 1);
+ else
+ hapd->drv.set_drv_ieee8021x(hapd, hapd->conf->iface, 0);
+
+ if (hapd->conf->wpa && hapd->wpa_auth == NULL)
+ hostapd_setup_wpa(hapd);
+ else if (hapd->conf->wpa) {
+ const u8 *wpa_ie;
+ size_t wpa_ie_len;
+ hostapd_reconfig_wpa(hapd);
+ wpa_ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &wpa_ie_len);
+ if (hostapd_set_generic_elem(hapd, wpa_ie, wpa_ie_len))
+ wpa_printf(MSG_ERROR, "Failed to configure WPA IE for "
+ "the kernel driver.");
+ } else if (hapd->wpa_auth) {
+ wpa_deinit(hapd->wpa_auth);
+ hapd->wpa_auth = NULL;
+ hostapd_set_privacy(hapd, 0);
+ hostapd_setup_encryption(hapd->conf->iface, hapd);
+ hostapd_set_generic_elem(hapd, (u8 *) "", 0);
+ }
+
+ ieee802_11_set_beacon(hapd);
+ hostapd_update_wps(hapd);
+
+ if (hapd->conf->ssid.ssid_set &&
+ hostapd_set_ssid(hapd, (u8 *) hapd->conf->ssid.ssid,
+ hapd->conf->ssid.ssid_len)) {
+ wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
+ /* try to continue */
+ }
+
+ hostapd_config_free(oldconf);
+
+ wpa_printf(MSG_DEBUG, "Reconfigured interface %s", hapd->conf->iface);
+
+ return 0;
+}
+
+
+static void hostapd_broadcast_key_clear_iface(struct hostapd_data *hapd,
+ char *ifname)
+{
+ int i;
+
+ for (i = 0; i < NUM_WEP_KEYS; i++) {
+ if (hapd->drv.set_key(ifname, hapd, WPA_ALG_NONE, NULL, i,
+ i == 0 ? 1 : 0, NULL, 0, NULL, 0)) {
+ wpa_printf(MSG_DEBUG, "Failed to clear default "
+ "encryption keys (ifname=%s keyidx=%d)",
+ ifname, i);
+ }
+ }
+#ifdef CONFIG_IEEE80211W
+ if (hapd->conf->ieee80211w) {
+ for (i = NUM_WEP_KEYS; i < NUM_WEP_KEYS + 2; i++) {
+ if (hapd->drv.set_key(ifname, hapd, WPA_ALG_NONE, NULL,
+ i, i == 0 ? 1 : 0, NULL, 0,
+ NULL, 0)) {
+ wpa_printf(MSG_DEBUG, "Failed to clear "
+ "default mgmt encryption keys "
+ "(ifname=%s keyidx=%d)", ifname, i);
+ }
+ }
+ }
+#endif /* CONFIG_IEEE80211W */
+}
+
+
+static int hostapd_broadcast_wep_clear(struct hostapd_data *hapd)
+{
+ hostapd_broadcast_key_clear_iface(hapd, hapd->conf->iface);
+ return 0;
+}
+
+
+static int hostapd_broadcast_wep_set(struct hostapd_data *hapd)
+{
+ int errors = 0, idx;
+ struct hostapd_ssid *ssid = &hapd->conf->ssid;
+
+ idx = ssid->wep.idx;
+ if (ssid->wep.default_len &&
+ hapd->drv.set_key(hapd->conf->iface,
+ hapd, WPA_ALG_WEP, NULL, idx,
+ idx == ssid->wep.idx,
+ NULL, 0, ssid->wep.key[idx],
+ ssid->wep.len[idx])) {
+ wpa_printf(MSG_WARNING, "Could not set WEP encryption.");
+ errors++;
+ }
+
+ if (ssid->dyn_vlan_keys) {
+ size_t i;
+ for (i = 0; i <= ssid->max_dyn_vlan_keys; i++) {
+ const char *ifname;
+ struct hostapd_wep_keys *key = ssid->dyn_vlan_keys[i];
+ if (key == NULL)
+ continue;
+ ifname = hostapd_get_vlan_id_ifname(hapd->conf->vlan,
+ i);
+ if (ifname == NULL)
+ continue;
+
+ idx = key->idx;
+ if (hapd->drv.set_key(ifname, hapd, WPA_ALG_WEP, NULL,
+ idx, idx == key->idx, NULL, 0,
+ key->key[idx], key->len[idx])) {
+ wpa_printf(MSG_WARNING, "Could not set "
+ "dynamic VLAN WEP encryption.");
+ errors++;
+ }
+ }
+ }
+
+ return errors;
+}
+
+/**
+ * hostapd_cleanup - Per-BSS cleanup (deinitialization)
+ * @hapd: Pointer to BSS data
+ *
+ * This function is used to free all per-BSS data structures and resources.
+ * This gets called in a loop for each BSS between calls to
+ * hostapd_cleanup_iface_pre() and hostapd_cleanup_iface() when an interface
+ * is deinitialized. Most of the modules that are initialized in
+ * hostapd_setup_bss() are deinitialized here.
+ */
+static void hostapd_cleanup(struct hostapd_data *hapd)
+{
+ if (hapd->iface->ctrl_iface_deinit)
+ hapd->iface->ctrl_iface_deinit(hapd);
+
+ iapp_deinit(hapd->iapp);
+ hapd->iapp = NULL;
+ accounting_deinit(hapd);
+ hostapd_deinit_wpa(hapd);
+ vlan_deinit(hapd);
+ hostapd_acl_deinit(hapd);
+#ifndef CONFIG_NO_RADIUS
+ radius_client_deinit(hapd->radius);
+ hapd->radius = NULL;
+#endif /* CONFIG_NO_RADIUS */
+
+ hostapd_deinit_wps(hapd);
+
+ authsrv_deinit(hapd);
+
+ if (hapd->interface_added &&
+ hostapd_if_remove(hapd, WPA_IF_AP_BSS, hapd->conf->iface)) {
+ wpa_printf(MSG_WARNING, "Failed to remove BSS interface %s",
+ hapd->conf->iface);
+ }
+
+ os_free(hapd->probereq_cb);
+ hapd->probereq_cb = NULL;
+}
+
+
+/**
+ * hostapd_cleanup_iface_pre - Preliminary per-interface cleanup
+ * @iface: Pointer to interface data
+ *
+ * This function is called before per-BSS data structures are deinitialized
+ * with hostapd_cleanup().
+ */
+static void hostapd_cleanup_iface_pre(struct hostapd_iface *iface)
+{
+}
+
+
+/**
+ * hostapd_cleanup_iface - Complete per-interface cleanup
+ * @iface: Pointer to interface data
+ *
+ * This function is called after per-BSS data structures are deinitialized
+ * with hostapd_cleanup().
+ */
+static void hostapd_cleanup_iface(struct hostapd_iface *iface)
+{
+ hostapd_free_hw_features(iface->hw_features, iface->num_hw_features);
+ iface->hw_features = NULL;
+ os_free(iface->current_rates);
+ iface->current_rates = NULL;
+ ap_list_deinit(iface);
+ hostapd_config_free(iface->conf);
+ iface->conf = NULL;
+
+ os_free(iface->config_fname);
+ os_free(iface->bss);
+ os_free(iface);
+}
+
+
+static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd)
+{
+ int i;
+
+ hostapd_broadcast_wep_set(hapd);
+
+ if (hapd->conf->ssid.wep.default_len) {
+ hostapd_set_privacy(hapd, 1);
+ return 0;
+ }
+
+ for (i = 0; i < 4; i++) {
+ if (hapd->conf->ssid.wep.key[i] &&
+ hapd->drv.set_key(iface, hapd, WPA_ALG_WEP, NULL, i,
+ i == hapd->conf->ssid.wep.idx, NULL, 0,
+ hapd->conf->ssid.wep.key[i],
+ hapd->conf->ssid.wep.len[i])) {
+ wpa_printf(MSG_WARNING, "Could not set WEP "
+ "encryption.");
+ return -1;
+ }
+ if (hapd->conf->ssid.wep.key[i] &&
+ i == hapd->conf->ssid.wep.idx)
+ hostapd_set_privacy(hapd, 1);
+ }
+
+ return 0;
+}
+
+
+static int hostapd_flush_old_stations(struct hostapd_data *hapd)
+{
+ int ret = 0;
+
+ if (hostapd_drv_none(hapd) || hapd->drv_priv == NULL)
+ return 0;
+
+ wpa_printf(MSG_DEBUG, "Flushing old station entries");
+ if (hostapd_flush(hapd)) {
+ wpa_printf(MSG_WARNING, "Could not connect to kernel driver.");
+ ret = -1;
+ }
+ wpa_printf(MSG_DEBUG, "Deauthenticate all stations");
+
+ /* New Prism2.5/3 STA firmware versions seem to have issues with this
+ * broadcast deauth frame. This gets the firmware in odd state where
+ * nothing works correctly, so let's skip sending this for the hostap
+ * driver. */
+ if (hapd->driver && os_strcmp(hapd->driver->name, "hostap") != 0) {
+ u8 addr[ETH_ALEN];
+ os_memset(addr, 0xff, ETH_ALEN);
+ hapd->drv.sta_deauth(hapd, addr,
+ WLAN_REASON_PREV_AUTH_NOT_VALID);
+ }
+
+ return ret;
+}
+
+
+/**
+ * hostapd_validate_bssid_configuration - Validate BSSID configuration
+ * @iface: Pointer to interface data
+ * Returns: 0 on success, -1 on failure
+ *
+ * This function is used to validate that the configured BSSIDs are valid.
+ */
+static int hostapd_validate_bssid_configuration(struct hostapd_iface *iface)
+{
+ u8 mask[ETH_ALEN] = { 0 };
+ struct hostapd_data *hapd = iface->bss[0];
+ unsigned int i = iface->conf->num_bss, bits = 0, j;
+ int res;
+ int auto_addr = 0;
+
+ if (hostapd_drv_none(hapd))
+ return 0;
+
+ /* Generate BSSID mask that is large enough to cover the BSSIDs. */
+
+ /* Determine the bits necessary to cover the number of BSSIDs. */
+ for (i--; i; i >>= 1)
+ bits++;
+
+ /* Determine the bits necessary to any configured BSSIDs,
+ if they are higher than the number of BSSIDs. */
+ for (j = 0; j < iface->conf->num_bss; j++) {
+ if (hostapd_mac_comp_empty(iface->conf->bss[j].bssid) == 0) {
+ if (j)
+ auto_addr++;
+ continue;
+ }
+
+ for (i = 0; i < ETH_ALEN; i++) {
+ mask[i] |=
+ iface->conf->bss[j].bssid[i] ^
+ hapd->own_addr[i];
+ }
+ }
+
+ if (!auto_addr)
+ goto skip_mask_ext;
+
+ for (i = 0; i < ETH_ALEN && mask[i] == 0; i++)
+ ;
+ j = 0;
+ if (i < ETH_ALEN) {
+ j = (5 - i) * 8;
+
+ while (mask[i] != 0) {
+ mask[i] >>= 1;
+ j++;
+ }
+ }
+
+ if (bits < j)
+ bits = j;
+
+ if (bits > 40) {
+ wpa_printf(MSG_ERROR, "Too many bits in the BSSID mask (%u)",
+ bits);
+ return -1;
+ }
+
+ os_memset(mask, 0xff, ETH_ALEN);
+ j = bits / 8;
+ for (i = 5; i > 5 - j; i--)
+ mask[i] = 0;
+ j = bits % 8;
+ while (j--)
+ mask[i] <<= 1;
+
+skip_mask_ext:
+ wpa_printf(MSG_DEBUG, "BSS count %lu, BSSID mask " MACSTR " (%d bits)",
+ (unsigned long) iface->conf->num_bss, MAC2STR(mask), bits);
+
+ res = hostapd_valid_bss_mask(hapd, hapd->own_addr, mask);
+ if (res == 0)
+ return 0;
+
+ if (res < 0) {
+ wpa_printf(MSG_ERROR, "Driver did not accept BSSID mask "
+ MACSTR " for start address " MACSTR ".",
+ MAC2STR(mask), MAC2STR(hapd->own_addr));
+ return -1;
+ }
+
+ if (!auto_addr)
+ return 0;
+
+ for (i = 0; i < ETH_ALEN; i++) {
+ if ((hapd->own_addr[i] & mask[i]) != hapd->own_addr[i]) {
+ wpa_printf(MSG_ERROR, "Invalid BSSID mask " MACSTR
+ " for start address " MACSTR ".",
+ MAC2STR(mask), MAC2STR(hapd->own_addr));
+ wpa_printf(MSG_ERROR, "Start address must be the "
+ "first address in the block (i.e., addr "
+ "AND mask == addr).");
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+
+static int mac_in_conf(struct hostapd_config *conf, const void *a)
+{
+ size_t i;
+
+ for (i = 0; i < conf->num_bss; i++) {
+ if (hostapd_mac_comp(conf->bss[i].bssid, a) == 0) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+
+
+
+/**
+ * hostapd_setup_bss - Per-BSS setup (initialization)
+ * @hapd: Pointer to BSS data
+ * @first: Whether this BSS is the first BSS of an interface
+ *
+ * This function is used to initialize all per-BSS data structures and
+ * resources. This gets called in a loop for each BSS when an interface is
+ * initialized. Most of the modules that are initialized here will be
+ * deinitialized in hostapd_cleanup().
+ */
+static int hostapd_setup_bss(struct hostapd_data *hapd, int first)
+{
+ struct hostapd_bss_config *conf = hapd->conf;
+ u8 ssid[HOSTAPD_MAX_SSID_LEN + 1];
+ int ssid_len, set_ssid;
+ char force_ifname[IFNAMSIZ];
+ u8 if_addr[ETH_ALEN];
+
+ if (!first) {
+ if (hostapd_mac_comp_empty(hapd->conf->bssid) == 0) {
+ /* Allocate the next available BSSID. */
+ do {
+ inc_byte_array(hapd->own_addr, ETH_ALEN);
+ } while (mac_in_conf(hapd->iconf, hapd->own_addr));
+ } else {
+ /* Allocate the configured BSSID. */
+ os_memcpy(hapd->own_addr, hapd->conf->bssid, ETH_ALEN);
+
+ if (hostapd_mac_comp(hapd->own_addr,
+ hapd->iface->bss[0]->own_addr) ==
+ 0) {
+ wpa_printf(MSG_ERROR, "BSS '%s' may not have "
+ "BSSID set to the MAC address of "
+ "the radio", hapd->conf->iface);
+ return -1;
+ }
+ }
+
+ hapd->interface_added = 1;
+ if (hostapd_if_add(hapd->iface->bss[0], WPA_IF_AP_BSS,
+ hapd->conf->iface, hapd->own_addr, hapd,
+ &hapd->drv_priv, force_ifname, if_addr)) {
+ wpa_printf(MSG_ERROR, "Failed to add BSS (BSSID="
+ MACSTR ")", MAC2STR(hapd->own_addr));
+ return -1;
+ }
+ }
+
+ hostapd_flush_old_stations(hapd);
+ hostapd_set_privacy(hapd, 0);
+
+ hostapd_broadcast_wep_clear(hapd);
+ if (hostapd_setup_encryption(hapd->conf->iface, hapd))
+ return -1;
+
+ /*
+ * Fetch the SSID from the system and use it or,
+ * if one was specified in the config file, verify they
+ * match.
+ */
+ ssid_len = hostapd_get_ssid(hapd, ssid, sizeof(ssid));
+ if (ssid_len < 0) {
+ wpa_printf(MSG_ERROR, "Could not read SSID from system");
+ return -1;
+ }
+ if (conf->ssid.ssid_set) {
+ /*
+ * If SSID is specified in the config file and it differs
+ * from what is being used then force installation of the
+ * new SSID.
+ */
+ set_ssid = (conf->ssid.ssid_len != (size_t) ssid_len ||
+ os_memcmp(conf->ssid.ssid, ssid, ssid_len) != 0);
+ } else {
+ /*
+ * No SSID in the config file; just use the one we got
+ * from the system.
+ */
+ set_ssid = 0;
+ conf->ssid.ssid_len = ssid_len;
+ os_memcpy(conf->ssid.ssid, ssid, conf->ssid.ssid_len);
+ conf->ssid.ssid[conf->ssid.ssid_len] = '\0';
+ }
+
+ if (!hostapd_drv_none(hapd)) {
+ wpa_printf(MSG_ERROR, "Using interface %s with hwaddr " MACSTR
+ " and ssid '%s'",
+ hapd->conf->iface, MAC2STR(hapd->own_addr),
+ hapd->conf->ssid.ssid);
+ }
+
+ if (hostapd_setup_wpa_psk(conf)) {
+ wpa_printf(MSG_ERROR, "WPA-PSK setup failed.");
+ return -1;
+ }
+
+ /* Set SSID for the kernel driver (to be used in beacon and probe
+ * response frames) */
+ if (set_ssid && hostapd_set_ssid(hapd, (u8 *) conf->ssid.ssid,
+ conf->ssid.ssid_len)) {
+ wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
+ return -1;
+ }
+
+ if (wpa_debug_level == MSG_MSGDUMP)
+ conf->radius->msg_dumps = 1;
+#ifndef CONFIG_NO_RADIUS
+ hapd->radius = radius_client_init(hapd, conf->radius);
+ if (hapd->radius == NULL) {
+ wpa_printf(MSG_ERROR, "RADIUS client initialization failed.");
+ return -1;
+ }
+#endif /* CONFIG_NO_RADIUS */
+
+ if (hostapd_acl_init(hapd)) {
+ wpa_printf(MSG_ERROR, "ACL initialization failed.");
+ return -1;
+ }
+ if (hostapd_init_wps(hapd, conf))
+ return -1;
+
+ if (authsrv_init(hapd) < 0)
+ return -1;
+
+ if (ieee802_1x_init(hapd)) {
+ wpa_printf(MSG_ERROR, "IEEE 802.1X initialization failed.");
+ return -1;
+ }
+
+ if (hapd->conf->wpa && hostapd_setup_wpa(hapd))
+ return -1;
+
+ if (accounting_init(hapd)) {
+ wpa_printf(MSG_ERROR, "Accounting initialization failed.");
+ return -1;
+ }
+
+ if (hapd->conf->ieee802_11f &&
+ (hapd->iapp = iapp_init(hapd, hapd->conf->iapp_iface)) == NULL) {
+ wpa_printf(MSG_ERROR, "IEEE 802.11F (IAPP) initialization "
+ "failed.");
+ return -1;
+ }
+
+ if (hapd->iface->ctrl_iface_init &&
+ hapd->iface->ctrl_iface_init(hapd)) {
+ wpa_printf(MSG_ERROR, "Failed to setup control interface");
+ return -1;
+ }
+
+ if (!hostapd_drv_none(hapd) && vlan_init(hapd)) {
+ wpa_printf(MSG_ERROR, "VLAN initialization failed.");
+ return -1;
+ }
+
+ ieee802_11_set_beacon(hapd);
+
+ return 0;
+}
+
+
+static void hostapd_tx_queue_params(struct hostapd_iface *iface)
+{
+ struct hostapd_data *hapd = iface->bss[0];
+ int i;
+ struct hostapd_tx_queue_params *p;
+
+ for (i = 0; i < NUM_TX_QUEUES; i++) {
+ p = &iface->conf->tx_queue[i];
+
+ if (!p->configured)
+ continue;
+
+ if (hostapd_set_tx_queue_params(hapd, i, p->aifs, p->cwmin,
+ p->cwmax, p->burst)) {
+ wpa_printf(MSG_DEBUG, "Failed to set TX queue "
+ "parameters for queue %d.", i);
+ /* Continue anyway */
+ }
+ }
+}
+
+
+static int setup_interface(struct hostapd_iface *iface)
+{
+ struct hostapd_data *hapd = iface->bss[0];
+ size_t i;
+ char country[4];
+
+ /*
+ * Make sure that all BSSes get configured with a pointer to the same
+ * driver interface.
+ */
+ for (i = 1; i < iface->num_bss; i++) {
+ iface->bss[i]->driver = hapd->driver;
+ iface->bss[i]->drv_priv = hapd->drv_priv;
+ }
+
+ if (hostapd_validate_bssid_configuration(iface))
+ return -1;
+
+ if (hapd->iconf->country[0] && hapd->iconf->country[1]) {
+ os_memcpy(country, hapd->iconf->country, 3);
+ country[3] = '\0';
+ if (hostapd_set_country(hapd, country) < 0) {
+ wpa_printf(MSG_ERROR, "Failed to set country code");
+ return -1;
+ }
+ }
+
+ if (hostapd_get_hw_features(iface)) {
+ /* Not all drivers support this yet, so continue without hw
+ * feature data. */
+ } else {
+ int ret = hostapd_select_hw_mode(iface);
+ if (ret < 0) {
+ wpa_printf(MSG_ERROR, "Could not select hw_mode and "
+ "channel. (%d)", ret);
+ return -1;
+ }
+ ret = hostapd_check_ht_capab(iface);
+ if (ret < 0)
+ return -1;
+ if (ret == 1) {
+ wpa_printf(MSG_DEBUG, "Interface initialization will "
+ "be completed in a callback");
+ return 0;
+ }
+ }
+ return hostapd_setup_interface_complete(iface, 0);
+}
+
+
+int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err)
+{
+ struct hostapd_data *hapd = iface->bss[0];
+ size_t j;
+ u8 *prev_addr;
+
+ if (err) {
+ wpa_printf(MSG_ERROR, "Interface initialization failed");
+ eloop_terminate();
+ return -1;
+ }
+
+ wpa_printf(MSG_DEBUG, "Completing interface initialization");
+ if (hapd->iconf->channel) {
+ iface->freq = hostapd_hw_get_freq(hapd, hapd->iconf->channel);
+ wpa_printf(MSG_DEBUG, "Mode: %s Channel: %d "
+ "Frequency: %d MHz",
+ hostapd_hw_mode_txt(hapd->iconf->hw_mode),
+ hapd->iconf->channel, iface->freq);
+
+ if (hostapd_set_freq(hapd, hapd->iconf->hw_mode, iface->freq,
+ hapd->iconf->channel,
+ hapd->iconf->ieee80211n,
+ hapd->iconf->secondary_channel)) {
+ wpa_printf(MSG_ERROR, "Could not set channel for "
+ "kernel driver");
+ return -1;
+ }
+ }
+
+ if (hapd->iconf->rts_threshold > -1 &&
+ hostapd_set_rts(hapd, hapd->iconf->rts_threshold)) {
+ wpa_printf(MSG_ERROR, "Could not set RTS threshold for "
+ "kernel driver");
+ return -1;
+ }
+
+ if (hapd->iconf->fragm_threshold > -1 &&
+ hostapd_set_frag(hapd, hapd->iconf->fragm_threshold)) {
+ wpa_printf(MSG_ERROR, "Could not set fragmentation threshold "
+ "for kernel driver");
+ return -1;
+ }
+
+ prev_addr = hapd->own_addr;
+
+ for (j = 0; j < iface->num_bss; j++) {
+ hapd = iface->bss[j];
+ if (j)
+ os_memcpy(hapd->own_addr, prev_addr, ETH_ALEN);
+ if (hostapd_setup_bss(hapd, j == 0))
+ return -1;
+ if (hostapd_mac_comp_empty(hapd->conf->bssid) == 0)
+ prev_addr = hapd->own_addr;
+ }
+
+ hostapd_tx_queue_params(iface);
+
+ ap_list_init(iface);
+
+ if (hostapd_driver_commit(hapd) < 0) {
+ wpa_printf(MSG_ERROR, "%s: Failed to commit driver "
+ "configuration", __func__);
+ return -1;
+ }
+
+ wpa_printf(MSG_DEBUG, "%s: Setup of interface done.",
+ iface->bss[0]->conf->iface);
+
+ return 0;
+}
+
+
+/**
+ * hostapd_setup_interface - Setup of an interface
+ * @iface: Pointer to interface data.
+ * Returns: 0 on success, -1 on failure
+ *
+ * Initializes the driver interface, validates the configuration,
+ * and sets driver parameters based on the configuration.
+ * Flushes old stations, sets the channel, encryption,
+ * beacons, and WDS links based on the configuration.
+ */
+int hostapd_setup_interface(struct hostapd_iface *iface)
+{
+ int ret;
+
+ ret = setup_interface(iface);
+ if (ret) {
+ wpa_printf(MSG_ERROR, "%s: Unable to setup interface.",
+ iface->bss[0]->conf->iface);
+ return -1;
+ }
+
+ return 0;
+}
+
+
+/**
+ * hostapd_alloc_bss_data - Allocate and initialize per-BSS data
+ * @hapd_iface: Pointer to interface data
+ * @conf: Pointer to per-interface configuration
+ * @bss: Pointer to per-BSS configuration for this BSS
+ * Returns: Pointer to allocated BSS data
+ *
+ * This function is used to allocate per-BSS data structure. This data will be
+ * freed after hostapd_cleanup() is called for it during interface
+ * deinitialization.
+ */
+struct hostapd_data *
+hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
+ struct hostapd_config *conf,
+ struct hostapd_bss_config *bss)
+{
+ struct hostapd_data *hapd;
+
+ hapd = os_zalloc(sizeof(*hapd));
+ if (hapd == NULL)
+ return NULL;
+
+ hostapd_set_driver_ops(&hapd->drv);
+ hapd->new_assoc_sta_cb = hostapd_new_assoc_sta;
+ hapd->iconf = conf;
+ hapd->conf = bss;
+ hapd->iface = hapd_iface;
+ hapd->driver = hapd->iconf->driver;
+
+ return hapd;
+}
+
+
+void hostapd_interface_deinit(struct hostapd_iface *iface)
+{
+ size_t j;
+
+ if (iface == NULL)
+ return;
+
+ hostapd_cleanup_iface_pre(iface);
+ for (j = 0; j < iface->num_bss; j++) {
+ struct hostapd_data *hapd = iface->bss[j];
+ hostapd_free_stas(hapd);
+ hostapd_flush_old_stations(hapd);
+ hostapd_cleanup(hapd);
+ }
+}
+
+
+void hostapd_interface_free(struct hostapd_iface *iface)
+{
+ size_t j;
+ for (j = 0; j < iface->num_bss; j++)
+ os_free(iface->bss[j]);
+ hostapd_cleanup_iface(iface);
+}
+
+
+/**
+ * hostapd_new_assoc_sta - Notify that a new station associated with the AP
+ * @hapd: Pointer to BSS data
+ * @sta: Pointer to the associated STA data
+ * @reassoc: 1 to indicate this was a re-association; 0 = first association
+ *
+ * This function will be called whenever a station associates with the AP. It
+ * can be called from ieee802_11.c for drivers that export MLME to hostapd and
+ * from drv_callbacks.c based on driver events for drivers that take care of
+ * management frames (IEEE 802.11 authentication and association) internally.
+ */
+void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
+ int reassoc)
+{
+ if (hapd->tkip_countermeasures) {
+ hapd->drv.sta_deauth(hapd, sta->addr,
+ WLAN_REASON_MICHAEL_MIC_FAILURE);
+ return;
+ }
+
+ hostapd_prune_associations(hapd, sta->addr);
+
+ /* IEEE 802.11F (IAPP) */
+ if (hapd->conf->ieee802_11f)
+ iapp_new_station(hapd->iapp, sta);
+
+ /* Start accounting here, if IEEE 802.1X and WPA are not used.
+ * IEEE 802.1X/WPA code will start accounting after the station has
+ * been authorized. */
+ if (!hapd->conf->ieee802_1x && !hapd->conf->wpa)
+ accounting_sta_start(hapd, sta);
+
+ /* Start IEEE 802.1X authentication process for new stations */
+ ieee802_1x_new_station(hapd, sta);
+ if (reassoc) {
+ if (sta->auth_alg != WLAN_AUTH_FT &&
+ !(sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)))
+ wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH);
+ } else
+ wpa_auth_sta_associated(hapd->wpa_auth, sta->wpa_sm);
+}
diff --git a/contrib/wpa/src/ap/hostapd.h b/contrib/wpa/src/ap/hostapd.h
new file mode 100644
index 0000000..d0d67c8
--- /dev/null
+++ b/contrib/wpa/src/ap/hostapd.h
@@ -0,0 +1,276 @@
+/*
+ * hostapd / Initialization and configuration
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef HOSTAPD_H
+#define HOSTAPD_H
+
+#include "common/defs.h"
+
+struct wpa_driver_ops;
+struct wpa_ctrl_dst;
+struct radius_server_data;
+struct upnp_wps_device_sm;
+struct hapd_interfaces;
+struct hostapd_data;
+struct sta_info;
+struct hostap_sta_driver_data;
+struct ieee80211_ht_capabilities;
+struct full_dynamic_vlan;
+
+struct hostapd_probereq_cb {
+ int (*cb)(void *ctx, const u8 *sa, const u8 *ie, size_t ie_len);
+ void *ctx;
+};
+
+#define HOSTAPD_RATE_BASIC 0x00000001
+
+struct hostapd_rate_data {
+ int rate; /* rate in 100 kbps */
+ int flags; /* HOSTAPD_RATE_ flags */
+};
+
+struct hostapd_frame_info {
+ u32 channel;
+ u32 datarate;
+ u32 ssi_signal;
+};
+
+
+struct hostapd_driver_ops {
+ int (*set_ap_wps_ie)(struct hostapd_data *hapd);
+ int (*send_mgmt_frame)(struct hostapd_data *hapd, const void *msg,
+ size_t len);
+ int (*send_eapol)(struct hostapd_data *hapd, const u8 *addr,
+ const u8 *data, size_t data_len, int encrypt);
+ int (*set_authorized)(struct hostapd_data *hapd, struct sta_info *sta,
+ int authorized);
+ int (*set_key)(const char *ifname, struct hostapd_data *hapd,
+ enum wpa_alg alg, const u8 *addr, int key_idx,
+ int set_tx, const u8 *seq, size_t seq_len,
+ const u8 *key, size_t key_len);
+ int (*read_sta_data)(struct hostapd_data *hapd,
+ struct hostap_sta_driver_data *data,
+ const u8 *addr);
+ int (*sta_clear_stats)(struct hostapd_data *hapd, const u8 *addr);
+ int (*set_sta_flags)(struct hostapd_data *hapd, struct sta_info *sta);
+ int (*set_drv_ieee8021x)(struct hostapd_data *hapd, const char *ifname,
+ int enabled);
+ int (*set_radius_acl_auth)(struct hostapd_data *hapd,
+ const u8 *mac, int accepted,
+ u32 session_timeout);
+ int (*set_radius_acl_expire)(struct hostapd_data *hapd,
+ const u8 *mac);
+ int (*set_bss_params)(struct hostapd_data *hapd, int use_protection);
+ int (*set_beacon)(struct hostapd_data *hapd,
+ const u8 *head, size_t head_len,
+ const u8 *tail, size_t tail_len, int dtim_period,
+ int beacon_int);
+ int (*vlan_if_add)(struct hostapd_data *hapd, const char *ifname);
+ int (*vlan_if_remove)(struct hostapd_data *hapd, const char *ifname);
+ int (*set_wds_sta)(struct hostapd_data *hapd, const u8 *addr, int aid,
+ int val);
+ int (*set_sta_vlan)(const char *ifname, struct hostapd_data *hapd,
+ const u8 *addr, int vlan_id);
+ int (*get_inact_sec)(struct hostapd_data *hapd, const u8 *addr);
+ int (*sta_deauth)(struct hostapd_data *hapd, const u8 *addr,
+ int reason);
+ int (*sta_disassoc)(struct hostapd_data *hapd, const u8 *addr,
+ int reason);
+ int (*sta_add)(struct hostapd_data *hapd,
+ const u8 *addr, u16 aid, u16 capability,
+ const u8 *supp_rates, size_t supp_rates_len,
+ u16 listen_interval,
+ const struct ieee80211_ht_capabilities *ht_capab);
+ int (*sta_remove)(struct hostapd_data *hapd, const u8 *addr);
+ int (*set_countermeasures)(struct hostapd_data *hapd, int enabled);
+};
+
+/**
+ * struct hostapd_data - hostapd per-BSS data structure
+ */
+struct hostapd_data {
+ struct hostapd_iface *iface;
+ struct hostapd_config *iconf;
+ struct hostapd_bss_config *conf;
+ int interface_added; /* virtual interface added for this BSS */
+
+ u8 own_addr[ETH_ALEN];
+
+ int num_sta; /* number of entries in sta_list */
+ struct sta_info *sta_list; /* STA info list head */
+#define STA_HASH_SIZE 256
+#define STA_HASH(sta) (sta[5])
+ struct sta_info *sta_hash[STA_HASH_SIZE];
+
+ /*
+ * Bitfield for indicating which AIDs are allocated. Only AID values
+ * 1-2007 are used and as such, the bit at index 0 corresponds to AID
+ * 1.
+ */
+#define AID_WORDS ((2008 + 31) / 32)
+ u32 sta_aid[AID_WORDS];
+
+ const struct wpa_driver_ops *driver;
+ void *drv_priv;
+ struct hostapd_driver_ops drv;
+
+ void (*new_assoc_sta_cb)(struct hostapd_data *hapd,
+ struct sta_info *sta, int reassoc);
+
+ void *msg_ctx; /* ctx for wpa_msg() calls */
+
+ struct radius_client_data *radius;
+ u32 acct_session_id_hi, acct_session_id_lo;
+
+ struct iapp_data *iapp;
+
+ struct hostapd_cached_radius_acl *acl_cache;
+ struct hostapd_acl_query_data *acl_queries;
+
+ struct wpa_authenticator *wpa_auth;
+ struct eapol_authenticator *eapol_auth;
+
+ struct rsn_preauth_interface *preauth_iface;
+ time_t michael_mic_failure;
+ int michael_mic_failures;
+ int tkip_countermeasures;
+
+ int ctrl_sock;
+ struct wpa_ctrl_dst *ctrl_dst;
+
+ void *ssl_ctx;
+ void *eap_sim_db_priv;
+ struct radius_server_data *radius_srv;
+
+ int parameter_set_count;
+
+#ifdef CONFIG_FULL_DYNAMIC_VLAN
+ struct full_dynamic_vlan *full_dynamic_vlan;
+#endif /* CONFIG_FULL_DYNAMIC_VLAN */
+
+ struct l2_packet_data *l2;
+ struct wps_context *wps;
+
+ struct wpabuf *wps_beacon_ie;
+ struct wpabuf *wps_probe_resp_ie;
+#ifdef CONFIG_WPS
+ unsigned int ap_pin_failures;
+ struct upnp_wps_device_sm *wps_upnp;
+ unsigned int ap_pin_lockout_time;
+#endif /* CONFIG_WPS */
+
+ struct hostapd_probereq_cb *probereq_cb;
+ size_t num_probereq_cb;
+
+ void (*public_action_cb)(void *ctx, const u8 *buf, size_t len,
+ int freq);
+ void *public_action_cb_ctx;
+
+ void (*wps_reg_success_cb)(void *ctx, const u8 *mac_addr,
+ const u8 *uuid_e);
+ void *wps_reg_success_cb_ctx;
+};
+
+
+/**
+ * struct hostapd_iface - hostapd per-interface data structure
+ */
+struct hostapd_iface {
+ struct hapd_interfaces *interfaces;
+ void *owner;
+ int (*reload_config)(struct hostapd_iface *iface);
+ struct hostapd_config * (*config_read_cb)(const char *config_fname);
+ char *config_fname;
+ struct hostapd_config *conf;
+
+ size_t num_bss;
+ struct hostapd_data **bss;
+
+ int num_ap; /* number of entries in ap_list */
+ struct ap_info *ap_list; /* AP info list head */
+ struct ap_info *ap_hash[STA_HASH_SIZE];
+ struct ap_info *ap_iter_list;
+
+ struct hostapd_hw_modes *hw_features;
+ int num_hw_features;
+ struct hostapd_hw_modes *current_mode;
+ /* Rates that are currently used (i.e., filtered copy of
+ * current_mode->channels */
+ int num_rates;
+ struct hostapd_rate_data *current_rates;
+ int freq;
+
+ u16 hw_flags;
+
+ /* Number of associated Non-ERP stations (i.e., stations using 802.11b
+ * in 802.11g BSS) */
+ int num_sta_non_erp;
+
+ /* Number of associated stations that do not support Short Slot Time */
+ int num_sta_no_short_slot_time;
+
+ /* Number of associated stations that do not support Short Preamble */
+ int num_sta_no_short_preamble;
+
+ int olbc; /* Overlapping Legacy BSS Condition */
+
+ /* Number of HT associated stations that do not support greenfield */
+ int num_sta_ht_no_gf;
+
+ /* Number of associated non-HT stations */
+ int num_sta_no_ht;
+
+ /* Number of HT associated stations 20 MHz */
+ int num_sta_ht_20mhz;
+
+ /* Overlapping BSS information */
+ int olbc_ht;
+
+ u16 ht_op_mode;
+ void (*scan_cb)(struct hostapd_iface *iface);
+
+ int (*ctrl_iface_init)(struct hostapd_data *hapd);
+ void (*ctrl_iface_deinit)(struct hostapd_data *hapd);
+
+ int (*for_each_interface)(struct hapd_interfaces *interfaces,
+ int (*cb)(struct hostapd_iface *iface,
+ void *ctx), void *ctx);
+};
+
+/* hostapd.c */
+int hostapd_reload_config(struct hostapd_iface *iface);
+struct hostapd_data *
+hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
+ struct hostapd_config *conf,
+ struct hostapd_bss_config *bss);
+int hostapd_setup_interface(struct hostapd_iface *iface);
+int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err);
+void hostapd_interface_deinit(struct hostapd_iface *iface);
+void hostapd_interface_free(struct hostapd_iface *iface);
+void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
+ int reassoc);
+
+/* utils.c */
+int hostapd_register_probereq_cb(struct hostapd_data *hapd,
+ int (*cb)(void *ctx, const u8 *sa,
+ const u8 *ie, size_t ie_len),
+ void *ctx);
+void hostapd_prune_associations(struct hostapd_data *hapd, const u8 *addr);
+
+/* drv_callbacks.c (TODO: move to somewhere else?) */
+int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
+ const u8 *ie, size_t ielen);
+void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr);
+
+#endif /* HOSTAPD_H */
diff --git a/contrib/wpa/hostapd/hw_features.c b/contrib/wpa/src/ap/hw_features.c
index 1d6299e..0159c72 100644
--- a/contrib/wpa/hostapd/hw_features.c
+++ b/contrib/wpa/src/ap/hw_features.c
@@ -2,7 +2,7 @@
* hostapd / Hardware feature query and different modes
* Copyright 2002-2003, Instant802 Networks, Inc.
* Copyright 2005-2006, Devicescape Software, Inc.
- * Copyright (c) 2008, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2008-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -14,12 +14,17 @@
* See README and COPYING for more details.
*/
-#include "includes.h"
+#include "utils/includes.h"
+#include "utils/common.h"
+#include "utils/eloop.h"
+#include "common/ieee802_11_defs.h"
+#include "common/ieee802_11_common.h"
+#include "drivers/driver.h"
#include "hostapd.h"
+#include "ap_config.h"
+#include "ap_drv_ops.h"
#include "hw_features.h"
-#include "driver.h"
-#include "config.h"
void hostapd_free_hw_features(struct hostapd_hw_modes *hw_features,
@@ -131,7 +136,7 @@ static int hostapd_prepare_rates(struct hostapd_data *hapd,
hapd->iface->num_rates = 0;
hapd->iface->current_rates =
- os_malloc(mode->num_rates * sizeof(struct hostapd_rate_data));
+ os_zalloc(mode->num_rates * sizeof(struct hostapd_rate_data));
if (!hapd->iface->current_rates) {
wpa_printf(MSG_ERROR, "Failed to allocate memory for rate "
"table.");
@@ -143,17 +148,15 @@ static int hostapd_prepare_rates(struct hostapd_data *hapd,
if (hapd->iconf->supported_rates &&
!hostapd_rate_found(hapd->iconf->supported_rates,
- mode->rates[i].rate))
+ mode->rates[i]))
continue;
rate = &hapd->iface->current_rates[hapd->iface->num_rates];
- os_memcpy(rate, &mode->rates[i],
- sizeof(struct hostapd_rate_data));
+ rate->rate = mode->rates[i];
if (hostapd_rate_found(basic_rates, rate->rate)) {
rate->flags |= HOSTAPD_RATE_BASIC;
num_basic_rates++;
- } else
- rate->flags &= ~HOSTAPD_RATE_BASIC;
+ }
wpa_printf(MSG_DEBUG, "RATE[%d] rate=%d flags=0x%x",
hapd->iface->num_rates, rate->rate, rate->flags);
hapd->iface->num_rates++;
@@ -236,6 +239,245 @@ static int ieee80211n_allowed_ht40_channel_pair(struct hostapd_iface *iface)
}
+static void ieee80211n_switch_pri_sec(struct hostapd_iface *iface)
+{
+ if (iface->conf->secondary_channel > 0) {
+ iface->conf->channel += 4;
+ iface->conf->secondary_channel = -1;
+ } else {
+ iface->conf->channel -= 4;
+ iface->conf->secondary_channel = 1;
+ }
+}
+
+
+static void ieee80211n_get_pri_sec_chan(struct wpa_scan_res *bss,
+ int *pri_chan, int *sec_chan)
+{
+ struct ieee80211_ht_operation *oper;
+ struct ieee802_11_elems elems;
+
+ *pri_chan = *sec_chan = 0;
+
+ ieee802_11_parse_elems((u8 *) (bss + 1), bss->ie_len, &elems, 0);
+ if (elems.ht_operation &&
+ elems.ht_operation_len >= sizeof(*oper)) {
+ oper = (struct ieee80211_ht_operation *) elems.ht_operation;
+ *pri_chan = oper->control_chan;
+ if (oper->ht_param & HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH) {
+ if (oper->ht_param &
+ HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE)
+ *sec_chan = *pri_chan + 4;
+ else if (oper->ht_param &
+ HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW)
+ *sec_chan = *pri_chan - 4;
+ }
+ }
+}
+
+
+static int ieee80211n_check_40mhz_5g(struct hostapd_iface *iface,
+ struct wpa_scan_results *scan_res)
+{
+ int pri_chan, sec_chan, pri_freq, sec_freq, pri_bss, sec_bss;
+ int bss_pri_chan, bss_sec_chan;
+ size_t i;
+ int match;
+
+ pri_chan = iface->conf->channel;
+ sec_chan = iface->conf->secondary_channel * 4;
+ pri_freq = hostapd_hw_get_freq(iface->bss[0], pri_chan);
+ if (iface->conf->secondary_channel > 0)
+ sec_freq = pri_freq + 20;
+ else
+ sec_freq = pri_freq - 20;
+
+ /*
+ * Switch PRI/SEC channels if Beacons were detected on selected SEC
+ * channel, but not on selected PRI channel.
+ */
+ pri_bss = sec_bss = 0;
+ for (i = 0; i < scan_res->num; i++) {
+ struct wpa_scan_res *bss = scan_res->res[i];
+ if (bss->freq == pri_freq)
+ pri_bss++;
+ else if (bss->freq == sec_freq)
+ sec_bss++;
+ }
+ if (sec_bss && !pri_bss) {
+ wpa_printf(MSG_INFO, "Switch own primary and secondary "
+ "channel to get secondary channel with no Beacons "
+ "from other BSSes");
+ ieee80211n_switch_pri_sec(iface);
+ }
+
+ /*
+ * Match PRI/SEC channel with any existing HT40 BSS on the same
+ * channels that we are about to use (if already mixed order in
+ * existing BSSes, use own preference).
+ */
+ match = 0;
+ for (i = 0; i < scan_res->num; i++) {
+ struct wpa_scan_res *bss = scan_res->res[i];
+ ieee80211n_get_pri_sec_chan(bss, &bss_pri_chan, &bss_sec_chan);
+ if (pri_chan == bss_pri_chan &&
+ sec_chan == bss_sec_chan) {
+ match = 1;
+ break;
+ }
+ }
+ if (!match) {
+ for (i = 0; i < scan_res->num; i++) {
+ struct wpa_scan_res *bss = scan_res->res[i];
+ ieee80211n_get_pri_sec_chan(bss, &bss_pri_chan,
+ &bss_sec_chan);
+ if (pri_chan == bss_sec_chan &&
+ sec_chan == bss_pri_chan) {
+ wpa_printf(MSG_INFO, "Switch own primary and "
+ "secondary channel due to BSS "
+ "overlap with " MACSTR,
+ MAC2STR(bss->bssid));
+ ieee80211n_switch_pri_sec(iface);
+ break;
+ }
+ }
+ }
+
+ return 1;
+}
+
+
+static int ieee80211n_check_40mhz_2g4(struct hostapd_iface *iface,
+ struct wpa_scan_results *scan_res)
+{
+ int pri_freq, sec_freq;
+ int affected_start, affected_end;
+ size_t i;
+
+ pri_freq = hostapd_hw_get_freq(iface->bss[0], iface->conf->channel);
+ if (iface->conf->secondary_channel > 0)
+ sec_freq = pri_freq + 20;
+ else
+ sec_freq = pri_freq - 20;
+ affected_start = (pri_freq + sec_freq) / 2 - 25;
+ affected_end = (pri_freq + sec_freq) / 2 + 25;
+ wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
+ affected_start, affected_end);
+ for (i = 0; i < scan_res->num; i++) {
+ struct wpa_scan_res *bss = scan_res->res[i];
+ int pri = bss->freq;
+ int sec = pri;
+ int sec_chan, pri_chan;
+
+ ieee80211n_get_pri_sec_chan(bss, &pri_chan, &sec_chan);
+
+ if (sec_chan) {
+ if (sec_chan < pri_chan)
+ sec = pri - 20;
+ else
+ sec = pri + 20;
+ }
+
+ if ((pri < affected_start || pri > affected_end) &&
+ (sec < affected_start || sec > affected_end))
+ continue; /* not within affected channel range */
+
+ wpa_printf(MSG_DEBUG, "Neighboring BSS: " MACSTR
+ " freq=%d pri=%d sec=%d",
+ MAC2STR(bss->bssid), bss->freq, pri_chan, sec_chan);
+
+ if (sec_chan) {
+ if (pri_freq != pri || sec_freq != sec) {
+ wpa_printf(MSG_DEBUG, "40 MHz pri/sec "
+ "mismatch with BSS " MACSTR
+ " <%d,%d> (chan=%d%c) vs. <%d,%d>",
+ MAC2STR(bss->bssid),
+ pri, sec, pri_chan,
+ sec > pri ? '+' : '-',
+ pri_freq, sec_freq);
+ return 0;
+ }
+ }
+
+ /* TODO: 40 MHz intolerant */
+ }
+
+ return 1;
+}
+
+
+static void wpa_scan_results_free(struct wpa_scan_results *res)
+{
+ size_t i;
+
+ if (res == NULL)
+ return;
+
+ for (i = 0; i < res->num; i++)
+ os_free(res->res[i]);
+ os_free(res->res);
+ os_free(res);
+}
+
+
+static void ieee80211n_check_scan(struct hostapd_iface *iface)
+{
+ struct wpa_scan_results *scan_res;
+ int oper40;
+
+ /* Check list of neighboring BSSes (from scan) to see whether 40 MHz is
+ * allowed per IEEE 802.11n/D7.0, 11.14.3.2 */
+
+ iface->scan_cb = NULL;
+
+ scan_res = hostapd_driver_get_scan_results(iface->bss[0]);
+ if (scan_res == NULL) {
+ hostapd_setup_interface_complete(iface, 1);
+ return;
+ }
+
+ if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A)
+ oper40 = ieee80211n_check_40mhz_5g(iface, scan_res);
+ else
+ oper40 = ieee80211n_check_40mhz_2g4(iface, scan_res);
+ wpa_scan_results_free(scan_res);
+
+ if (!oper40) {
+ wpa_printf(MSG_INFO, "20/40 MHz operation not permitted on "
+ "channel pri=%d sec=%d based on overlapping BSSes",
+ iface->conf->channel,
+ iface->conf->channel +
+ iface->conf->secondary_channel * 4);
+ iface->conf->secondary_channel = 0;
+ iface->conf->ht_capab &= ~HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
+ }
+
+ hostapd_setup_interface_complete(iface, 0);
+}
+
+
+static int ieee80211n_check_40mhz(struct hostapd_iface *iface)
+{
+ struct wpa_driver_scan_params params;
+
+ if (!iface->conf->secondary_channel)
+ return 0; /* HT40 not used */
+
+ wpa_printf(MSG_DEBUG, "Scan for neighboring BSSes prior to enabling "
+ "40 MHz channel");
+ os_memset(&params, 0, sizeof(params));
+ /* TODO: scan only the needed frequency */
+ if (hostapd_driver_scan(iface->bss[0], &params) < 0) {
+ wpa_printf(MSG_ERROR, "Failed to request a scan of "
+ "neighboring BSSes");
+ return -1;
+ }
+
+ iface->scan_cb = ieee80211n_check_scan;
+ return 1;
+}
+
+
static int ieee80211n_supported_ht_capab(struct hostapd_iface *iface)
{
u16 hw = iface->current_mode->ht_capab;
@@ -335,8 +577,26 @@ static int ieee80211n_supported_ht_capab(struct hostapd_iface *iface)
return 1;
}
+
+#endif /* CONFIG_IEEE80211N */
+
+
+int hostapd_check_ht_capab(struct hostapd_iface *iface)
+{
+#ifdef CONFIG_IEEE80211N
+ int ret;
+ ret = ieee80211n_check_40mhz(iface);
+ if (ret)
+ return ret;
+ if (!ieee80211n_allowed_ht40_channel_pair(iface))
+ return -1;
+ if (!ieee80211n_supported_ht_capab(iface))
+ return -1;
#endif /* CONFIG_IEEE80211N */
+ return 0;
+}
+
/**
* hostapd_select_hw_mode - Select the hardware mode
@@ -348,7 +608,7 @@ static int ieee80211n_supported_ht_capab(struct hostapd_iface *iface)
*/
int hostapd_select_hw_mode(struct hostapd_iface *iface)
{
- int i, j, ok, ret;
+ int i, j, ok;
if (iface->num_hw_features < 1)
return -1;
@@ -356,7 +616,7 @@ int hostapd_select_hw_mode(struct hostapd_iface *iface)
iface->current_mode = NULL;
for (i = 0; i < iface->num_hw_features; i++) {
struct hostapd_hw_modes *mode = &iface->hw_features[i];
- if (mode->mode == (int) iface->conf->hw_mode) {
+ if (mode->mode == iface->conf->hw_mode) {
iface->current_mode = mode;
break;
}
@@ -408,13 +668,6 @@ int hostapd_select_hw_mode(struct hostapd_iface *iface)
return -1;
}
-#ifdef CONFIG_IEEE80211N
- if (!ieee80211n_allowed_ht40_channel_pair(iface))
- return -1;
- if (!ieee80211n_supported_ht_capab(iface))
- return -1;
-#endif /* CONFIG_IEEE80211N */
-
if (hostapd_prepare_rates(iface->bss[0], iface->current_mode)) {
wpa_printf(MSG_ERROR, "Failed to prepare rates table.");
hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211,
@@ -423,23 +676,7 @@ int hostapd_select_hw_mode(struct hostapd_iface *iface)
return -1;
}
- ret = hostapd_passive_scan(iface->bss[0], 0,
- iface->conf->passive_scan_mode,
- iface->conf->passive_scan_interval,
- iface->conf->passive_scan_listen,
- NULL, NULL);
- if (ret) {
- if (ret == -1) {
- wpa_printf(MSG_DEBUG, "Passive scanning not "
- "supported");
- } else {
- wpa_printf(MSG_ERROR, "Could not set passive "
- "scanning: %s", strerror(ret));
- }
- ret = 0;
- }
-
- return ret;
+ return 0;
}
diff --git a/contrib/wpa/hostapd/hw_features.h b/contrib/wpa/src/ap/hw_features.h
index 7d43c89..0295549 100644
--- a/contrib/wpa/hostapd/hw_features.h
+++ b/contrib/wpa/src/ap/hw_features.h
@@ -16,41 +16,7 @@
#ifndef HW_FEATURES_H
#define HW_FEATURES_H
-#define HOSTAPD_CHAN_DISABLED 0x00000001
-#define HOSTAPD_CHAN_PASSIVE_SCAN 0x00000002
-#define HOSTAPD_CHAN_NO_IBSS 0x00000004
-#define HOSTAPD_CHAN_RADAR 0x00000008
-
-struct hostapd_channel_data {
- short chan; /* channel number (IEEE 802.11) */
- short freq; /* frequency in MHz */
- int flag; /* flag for hostapd use (HOSTAPD_CHAN_*) */
- u8 max_tx_power; /* maximum transmit power in dBm */
-};
-
-#define HOSTAPD_RATE_ERP 0x00000001
-#define HOSTAPD_RATE_BASIC 0x00000002
-#define HOSTAPD_RATE_PREAMBLE2 0x00000004
-#define HOSTAPD_RATE_SUPPORTED 0x00000010
-#define HOSTAPD_RATE_OFDM 0x00000020
-#define HOSTAPD_RATE_CCK 0x00000040
-#define HOSTAPD_RATE_MANDATORY 0x00000100
-
-struct hostapd_rate_data {
- int rate; /* rate in 100 kbps */
- int flags; /* HOSTAPD_RATE_ flags */
-};
-
-struct hostapd_hw_modes {
- int mode;
- int num_channels;
- struct hostapd_channel_data *channels;
- int num_rates;
- struct hostapd_rate_data *rates;
- u16 ht_capab;
-};
-
-
+#ifdef NEED_AP_MLME
void hostapd_free_hw_features(struct hostapd_hw_modes *hw_features,
size_t num_hw_features);
int hostapd_get_hw_features(struct hostapd_iface *iface);
@@ -58,5 +24,39 @@ int hostapd_select_hw_mode(struct hostapd_iface *iface);
const char * hostapd_hw_mode_txt(int mode);
int hostapd_hw_get_freq(struct hostapd_data *hapd, int chan);
int hostapd_hw_get_channel(struct hostapd_data *hapd, int freq);
+int hostapd_check_ht_capab(struct hostapd_iface *iface);
+#else /* NEED_AP_MLME */
+static inline void
+hostapd_free_hw_features(struct hostapd_hw_modes *hw_features,
+ size_t num_hw_features)
+{
+}
+
+static inline int hostapd_get_hw_features(struct hostapd_iface *iface)
+{
+ return -1;
+}
+
+static inline int hostapd_select_hw_mode(struct hostapd_iface *iface)
+{
+ return -1;
+}
+
+static inline const char * hostapd_hw_mode_txt(int mode)
+{
+ return NULL;
+}
+
+static inline int hostapd_hw_get_freq(struct hostapd_data *hapd, int chan)
+{
+ return -1;
+}
+
+static inline int hostapd_check_ht_capab(struct hostapd_iface *iface)
+{
+ return 0;
+}
+
+#endif /* NEED_AP_MLME */
#endif /* HW_FEATURES_H */
diff --git a/contrib/wpa/hostapd/iapp.c b/contrib/wpa/src/ap/iapp.c
index 6d6dba8..115d91e 100644
--- a/contrib/wpa/hostapd/iapp.c
+++ b/contrib/wpa/src/ap/iapp.c
@@ -37,7 +37,7 @@
* - IEEE 802.11 context transfer
*/
-#include "includes.h"
+#include "utils/includes.h"
#include <net/if.h>
#include <sys/ioctl.h>
#ifdef USE_KERNEL_HEADERS
@@ -46,11 +46,14 @@
#include <netpacket/packet.h>
#endif /* USE_KERNEL_HEADERS */
+#include "utils/common.h"
+#include "utils/eloop.h"
+#include "common/ieee802_11_defs.h"
#include "hostapd.h"
+#include "ap_config.h"
#include "ieee802_11.h"
-#include "iapp.h"
-#include "eloop.h"
#include "sta_info.h"
+#include "iapp.h"
#define IAPP_MULTICAST "224.0.1.178"
@@ -304,10 +307,7 @@ static void iapp_process_add_notify(struct iapp_data *iapp,
hostapd_logger(iapp->hapd, add->mac_addr, HOSTAPD_MODULE_IAPP,
HOSTAPD_LEVEL_DEBUG,
"Removing STA due to IAPP ADD-notify");
- sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_AUTHORIZED);
- eloop_cancel_timeout(ap_handle_timer, iapp->hapd, sta);
- eloop_register_timeout(0, 0, ap_handle_timer, iapp->hapd, sta);
- sta->timeout_next = STA_REMOVE;
+ ap_sta_disconnect(iapp->hapd, sta, NULL, 0);
}
@@ -533,21 +533,3 @@ void iapp_deinit(struct iapp_data *iapp)
}
os_free(iapp);
}
-
-int iapp_reconfig(struct hostapd_data *hapd, struct hostapd_config *oldconf,
- struct hostapd_bss_config *oldbss)
-{
- if (hapd->conf->ieee802_11f != oldbss->ieee802_11f ||
- os_strcmp(hapd->conf->iapp_iface, oldbss->iapp_iface) != 0) {
- iapp_deinit(hapd->iapp);
- hapd->iapp = NULL;
-
- if (hapd->conf->ieee802_11f) {
- hapd->iapp = iapp_init(hapd, hapd->conf->iapp_iface);
- if (hapd->iapp == NULL)
- return -1;
- }
- }
-
- return 0;
-}
diff --git a/contrib/wpa/hostapd/iapp.h b/contrib/wpa/src/ap/iapp.h
index 86de592..5fc01cb 100644
--- a/contrib/wpa/hostapd/iapp.h
+++ b/contrib/wpa/src/ap/iapp.h
@@ -22,8 +22,6 @@ struct iapp_data;
void iapp_new_station(struct iapp_data *iapp, struct sta_info *sta);
struct iapp_data * iapp_init(struct hostapd_data *hapd, const char *iface);
void iapp_deinit(struct iapp_data *iapp);
-int iapp_reconfig(struct hostapd_data *hapd, struct hostapd_config *oldconf,
- struct hostapd_bss_config *oldbss);
#else /* CONFIG_IAPP */
@@ -42,13 +40,6 @@ static inline void iapp_deinit(struct iapp_data *iapp)
{
}
-static inline int
-iapp_reconfig(struct hostapd_data *hapd, struct hostapd_config *oldconf,
- struct hostapd_bss_config *oldbss)
-{
- return 0;
-}
-
#endif /* CONFIG_IAPP */
#endif /* IAPP_H */
diff --git a/contrib/wpa/hostapd/ieee802_11.c b/contrib/wpa/src/ap/ieee802_11.c
index 70491b4..3375aa2 100644
--- a/contrib/wpa/hostapd/ieee802_11.c
+++ b/contrib/wpa/src/ap/ieee802_11.c
@@ -1,7 +1,6 @@
/*
* hostapd / IEEE 802.11 Management
- * Copyright (c) 2002-2008, Jouni Malinen <j@w1.fi>
- * Copyright (c) 2007-2008, Intel Corporation
+ * Copyright (c) 2002-2010, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -13,29 +12,32 @@
* See README and COPYING for more details.
*/
-#include "includes.h"
+#include "utils/includes.h"
#ifndef CONFIG_NATIVE_WINDOWS
-#include <net/if.h>
-
-#include "eloop.h"
-#include "hostapd.h"
-#include "ieee802_11.h"
-#include "beacon.h"
-#include "hw_features.h"
+#include "utils/common.h"
+#include "utils/eloop.h"
+#include "crypto/crypto.h"
+#include "drivers/driver.h"
+#include "common/ieee802_11_defs.h"
+#include "common/ieee802_11_common.h"
+#include "common/wpa_ctrl.h"
#include "radius/radius.h"
#include "radius/radius_client.h"
+#include "wps/wps.h"
+#include "hostapd.h"
+#include "beacon.h"
#include "ieee802_11_auth.h"
#include "sta_info.h"
-#include "rc4.h"
#include "ieee802_1x.h"
-#include "wpa.h"
-#include "wme.h"
+#include "wpa_auth.h"
+#include "wmm.h"
#include "ap_list.h"
#include "accounting.h"
-#include "driver.h"
-#include "mlme.h"
+#include "ap_config.h"
+#include "ap_mlme.h"
+#include "ieee802_11.h"
u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid)
@@ -100,153 +102,6 @@ u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid)
}
-u8 * hostapd_eid_ht_capabilities_info(struct hostapd_data *hapd, u8 *eid)
-{
-#ifdef CONFIG_IEEE80211N
- struct ieee80211_ht_capability *cap;
- u8 *pos = eid;
-
- if (!hapd->iconf->ieee80211n)
- return eid;
-
- *pos++ = WLAN_EID_HT_CAP;
- *pos++ = sizeof(*cap);
-
- cap = (struct ieee80211_ht_capability *) pos;
- os_memset(cap, 0, sizeof(*cap));
- SET_2BIT_U8(&cap->mac_ht_params_info,
- MAC_HT_PARAM_INFO_MAX_RX_AMPDU_FACTOR_OFFSET,
- MAX_RX_AMPDU_FACTOR_64KB);
-
- cap->capabilities_info = host_to_le16(hapd->iconf->ht_capab);
-
- cap->supported_mcs_set[0] = 0xff;
- cap->supported_mcs_set[1] = 0xff;
-
- pos += sizeof(*cap);
-
- return pos;
-#else /* CONFIG_IEEE80211N */
- return eid;
-#endif /* CONFIG_IEEE80211N */
-}
-
-
-u8 * hostapd_eid_ht_operation(struct hostapd_data *hapd, u8 *eid)
-{
-#ifdef CONFIG_IEEE80211N
- struct ieee80211_ht_operation *oper;
- u8 *pos = eid;
-
- if (!hapd->iconf->ieee80211n)
- return eid;
-
- *pos++ = WLAN_EID_HT_OPERATION;
- *pos++ = sizeof(*oper);
-
- oper = (struct ieee80211_ht_operation *) pos;
- os_memset(oper, 0, sizeof(*oper));
-
- oper->control_chan = hapd->iconf->channel;
- oper->operation_mode = host_to_le16(hapd->iface->ht_op_mode);
- if (hapd->iconf->secondary_channel == 1)
- oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE |
- HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH;
- if (hapd->iconf->secondary_channel == -1)
- oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW |
- HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH;
-
- pos += sizeof(*oper);
-
- return pos;
-#else /* CONFIG_IEEE80211N */
- return eid;
-#endif /* CONFIG_IEEE80211N */
-}
-
-
-#ifdef CONFIG_IEEE80211N
-
-/*
-op_mode
-Set to 0 (HT pure) under the followign conditions
- - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or
- - all STAs in the BSS are 20 MHz HT in 20 MHz BSS
-Set to 1 (HT non-member protection) if there may be non-HT STAs
- in both the primary and the secondary channel
-Set to 2 if only HT STAs are associated in BSS,
- however and at least one 20 MHz HT STA is associated
-Set to 3 (HT mixed mode) when one or more non-HT STAs are associated
- (currently non-GF HT station is considered as non-HT STA also)
-*/
-int hostapd_ht_operation_update(struct hostapd_iface *iface)
-{
- u16 cur_op_mode, new_op_mode;
- int op_mode_changes = 0;
-
- if (!iface->conf->ieee80211n || iface->conf->ht_op_mode_fixed)
- return 0;
-
- wpa_printf(MSG_DEBUG, "%s current operation mode=0x%X",
- __func__, iface->ht_op_mode);
-
- if (!(iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT)
- && iface->num_sta_ht_no_gf) {
- iface->ht_op_mode |=
- HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
- op_mode_changes++;
- } else if ((iface->ht_op_mode &
- HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT) &&
- iface->num_sta_ht_no_gf == 0) {
- iface->ht_op_mode &=
- ~HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
- op_mode_changes++;
- }
-
- if (!(iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
- (iface->num_sta_no_ht || iface->olbc_ht)) {
- iface->ht_op_mode |= HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
- op_mode_changes++;
- } else if ((iface->ht_op_mode &
- HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
- (iface->num_sta_no_ht == 0 && !iface->olbc_ht)) {
- iface->ht_op_mode &=
- ~HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
- op_mode_changes++;
- }
-
- /* Note: currently we switch to the MIXED op mode if HT non-greenfield
- * station is associated. Probably it's a theoretical case, since
- * it looks like all known HT STAs support greenfield.
- */
- new_op_mode = 0;
- if (iface->num_sta_no_ht ||
- (iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT))
- new_op_mode = OP_MODE_MIXED;
- else if ((iface->conf->ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)
- && iface->num_sta_ht_20mhz)
- new_op_mode = OP_MODE_20MHZ_HT_STA_ASSOCED;
- else if (iface->olbc_ht)
- new_op_mode = OP_MODE_MAY_BE_LEGACY_STAS;
- else
- new_op_mode = OP_MODE_PURE;
-
- cur_op_mode = iface->ht_op_mode & HT_INFO_OPERATION_MODE_OP_MODE_MASK;
- if (cur_op_mode != new_op_mode) {
- iface->ht_op_mode &= ~HT_INFO_OPERATION_MODE_OP_MODE_MASK;
- iface->ht_op_mode |= new_op_mode;
- op_mode_changes++;
- }
-
- wpa_printf(MSG_DEBUG, "%s new operation mode=0x%X changes=%d",
- __func__, iface->ht_op_mode, op_mode_changes);
-
- return op_mode_changes;
-}
-
-#endif /* CONFIG_IEEE80211N */
-
-
u16 hostapd_own_capab_info(struct hostapd_data *hapd, struct sta_info *sta,
int probe)
{
@@ -336,34 +191,9 @@ void ieee802_11_print_ssid(char *buf, const u8 *ssid, u8 len)
}
-/**
- * ieee802_11_send_deauth - Send Deauthentication frame
- * @hapd: hostapd BSS data
- * @addr: Address of the destination STA
- * @reason: Reason code for Deauthentication
- */
-void ieee802_11_send_deauth(struct hostapd_data *hapd, u8 *addr, u16 reason)
-{
- struct ieee80211_mgmt mgmt;
-
- hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
- HOSTAPD_LEVEL_DEBUG,
- "deauthenticate - reason %d", reason);
- os_memset(&mgmt, 0, sizeof(mgmt));
- mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
- WLAN_FC_STYPE_DEAUTH);
- os_memcpy(mgmt.da, addr, ETH_ALEN);
- os_memcpy(mgmt.sa, hapd->own_addr, ETH_ALEN);
- os_memcpy(mgmt.bssid, hapd->own_addr, ETH_ALEN);
- mgmt.u.deauth.reason_code = host_to_le16(reason);
- if (hostapd_send_mgmt_frame(hapd, &mgmt, IEEE80211_HDRLEN +
- sizeof(mgmt.u.deauth), 0) < 0)
- perror("ieee802_11_send_deauth: send");
-}
-
-
static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
- u16 auth_transaction, u8 *challenge, int iswep)
+ u16 auth_transaction, const u8 *challenge,
+ int iswep)
{
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
HOSTAPD_LEVEL_DEBUG,
@@ -452,7 +282,7 @@ static void send_auth_reply(struct hostapd_data *hapd,
" auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
MAC2STR(dst), auth_alg, auth_transaction,
resp, (unsigned long) ies_len);
- if (hostapd_send_mgmt_frame(hapd, reply, rlen, 0) < 0)
+ if (hapd->drv.send_mgmt_frame(hapd, reply, rlen) < 0)
perror("send_auth_reply: send");
os_free(buf);
@@ -485,15 +315,15 @@ static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
#endif /* CONFIG_IEEE80211R */
-static void handle_auth(struct hostapd_data *hapd, struct ieee80211_mgmt *mgmt,
- size_t len)
+static void handle_auth(struct hostapd_data *hapd,
+ const struct ieee80211_mgmt *mgmt, size_t len)
{
u16 auth_alg, auth_transaction, status_code;
u16 resp = WLAN_STATUS_SUCCESS;
struct sta_info *sta = NULL;
int res;
u16 fc;
- u8 *challenge = NULL;
+ const u8 *challenge = NULL;
u32 session_timeout, acct_interim_interval;
int vlan_id = 0;
u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
@@ -601,8 +431,7 @@ static void handle_auth(struct hostapd_data *hapd, struct ieee80211_mgmt *mgmt,
sta->flags &= ~WLAN_STA_PREAUTH;
ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
- if (hapd->conf->radius->acct_interim_interval == 0 &&
- acct_interim_interval)
+ if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
sta->acct_interim_interval = acct_interim_interval;
if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
ap_sta_session_timeout(hapd, sta, session_timeout);
@@ -665,110 +494,66 @@ static void handle_auth(struct hostapd_data *hapd, struct ieee80211_mgmt *mgmt,
}
-static void handle_assoc(struct hostapd_data *hapd,
- struct ieee80211_mgmt *mgmt, size_t len, int reassoc)
+static int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
{
- u16 capab_info, listen_interval;
- u16 resp = WLAN_STATUS_SUCCESS;
- u8 *pos, *wpa_ie;
- size_t wpa_ie_len;
- int send_deauth = 0, send_len, left, i;
- struct sta_info *sta;
- struct ieee802_11_elems elems;
- u8 buf[sizeof(struct ieee80211_mgmt) + 512];
- struct ieee80211_mgmt *reply;
-
- if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
- sizeof(mgmt->u.assoc_req))) {
- printf("handle_assoc(reassoc=%d) - too short payload (len=%lu)"
- "\n", reassoc, (unsigned long) len);
- return;
- }
+ int i, j = 32, aid;
- if (reassoc) {
- capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
- listen_interval = le_to_host16(
- mgmt->u.reassoc_req.listen_interval);
- wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
- " capab_info=0x%02x listen_interval=%d current_ap="
- MACSTR,
- MAC2STR(mgmt->sa), capab_info, listen_interval,
- MAC2STR(mgmt->u.reassoc_req.current_ap));
- left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
- pos = mgmt->u.reassoc_req.variable;
- } else {
- capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
- listen_interval = le_to_host16(
- mgmt->u.assoc_req.listen_interval);
- wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
- " capab_info=0x%02x listen_interval=%d",
- MAC2STR(mgmt->sa), capab_info, listen_interval);
- left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
- pos = mgmt->u.assoc_req.variable;
+ /* get a unique AID */
+ if (sta->aid > 0) {
+ wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
+ return 0;
}
- sta = ap_get_sta(hapd, mgmt->sa);
-#ifdef CONFIG_IEEE80211R
- if (sta && sta->auth_alg == WLAN_AUTH_FT &&
- (sta->flags & WLAN_STA_AUTH) == 0) {
- wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
- "prior to authentication since it is using "
- "over-the-DS FT", MAC2STR(mgmt->sa));
- } else
-#endif /* CONFIG_IEEE80211R */
- if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
- printf("STA " MACSTR " trying to associate before "
- "authentication\n", MAC2STR(mgmt->sa));
- if (sta) {
- printf(" sta: addr=" MACSTR " aid=%d flags=0x%04x\n",
- MAC2STR(sta->addr), sta->aid, sta->flags);
+ for (i = 0; i < AID_WORDS; i++) {
+ if (hapd->sta_aid[i] == (u32) -1)
+ continue;
+ for (j = 0; j < 32; j++) {
+ if (!(hapd->sta_aid[i] & BIT(j)))
+ break;
}
- send_deauth = 1;
- resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
- goto fail;
- }
-
- if (hapd->tkip_countermeasures) {
- resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
- goto fail;
+ if (j < 32)
+ break;
}
+ if (j == 32)
+ return -1;
+ aid = i * 32 + j + 1;
+ if (aid > 2007)
+ return -1;
- if (listen_interval > hapd->conf->max_listen_interval) {
- hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
- HOSTAPD_LEVEL_DEBUG,
- "Too large Listen Interval (%d)",
- listen_interval);
- resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
- goto fail;
- }
+ sta->aid = aid;
+ hapd->sta_aid[i] |= BIT(j);
+ wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
+ return 0;
+}
- sta->capability = capab_info;
- sta->listen_interval = listen_interval;
- /* followed by SSID and Supported rates; and HT capabilities if 802.11n
- * is used */
- if (ieee802_11_parse_elems(pos, left, &elems, 1) == ParseFailed ||
- !elems.ssid) {
- printf("STA " MACSTR " sent invalid association request\n",
- MAC2STR(sta->addr));
- resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
- goto fail;
- }
+static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
+ const u8 *ssid_ie, size_t ssid_ie_len)
+{
+ if (ssid_ie == NULL)
+ return WLAN_STATUS_UNSPECIFIED_FAILURE;
- if (elems.ssid_len != hapd->conf->ssid.ssid_len ||
- os_memcmp(elems.ssid, hapd->conf->ssid.ssid, elems.ssid_len) != 0)
- {
+ if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
+ os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
char ssid_txt[33];
- ieee802_11_print_ssid(ssid_txt, elems.ssid, elems.ssid_len);
- printf("Station " MACSTR " tried to associate with "
- "unknown SSID '%s'\n", MAC2STR(sta->addr), ssid_txt);
- resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
- goto fail;
+ ieee802_11_print_ssid(ssid_txt, ssid_ie, ssid_ie_len);
+ hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
+ HOSTAPD_LEVEL_INFO,
+ "Station tried to associate with unknown SSID "
+ "'%s'", ssid_txt);
+ return WLAN_STATUS_UNSPECIFIED_FAILURE;
}
+ return WLAN_STATUS_SUCCESS;
+}
+
+
+static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
+ const u8 *wmm_ie, size_t wmm_ie_len)
+{
sta->flags &= ~WLAN_STA_WMM;
- if (elems.wmm && hapd->conf->wmm_enabled) {
- if (hostapd_eid_wmm_valid(hapd, elems.wmm, elems.wmm_len))
+ if (wmm_ie && hapd->conf->wmm_enabled) {
+ if (hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len))
hostapd_logger(hapd, sta->addr,
HOSTAPD_MODULE_WPA,
HOSTAPD_LEVEL_DEBUG,
@@ -777,62 +562,83 @@ static void handle_assoc(struct hostapd_data *hapd,
else
sta->flags |= WLAN_STA_WMM;
}
+ return WLAN_STATUS_SUCCESS;
+}
- if (!elems.supp_rates) {
- hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
+
+static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
+ struct ieee802_11_elems *elems)
+{
+ if (!elems->supp_rates) {
+ hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
HOSTAPD_LEVEL_DEBUG,
"No supported rates element in AssocReq");
- resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
- goto fail;
+ return WLAN_STATUS_UNSPECIFIED_FAILURE;
}
- if (elems.supp_rates_len > sizeof(sta->supported_rates)) {
- hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
+ if (elems->supp_rates_len > sizeof(sta->supported_rates)) {
+ hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
HOSTAPD_LEVEL_DEBUG,
"Invalid supported rates element length %d",
- elems.supp_rates_len);
- resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
- goto fail;
+ elems->supp_rates_len);
+ return WLAN_STATUS_UNSPECIFIED_FAILURE;
}
os_memset(sta->supported_rates, 0, sizeof(sta->supported_rates));
- os_memcpy(sta->supported_rates, elems.supp_rates,
- elems.supp_rates_len);
- sta->supported_rates_len = elems.supp_rates_len;
+ os_memcpy(sta->supported_rates, elems->supp_rates,
+ elems->supp_rates_len);
+ sta->supported_rates_len = elems->supp_rates_len;
- if (elems.ext_supp_rates) {
- if (elems.supp_rates_len + elems.ext_supp_rates_len >
+ if (elems->ext_supp_rates) {
+ if (elems->supp_rates_len + elems->ext_supp_rates_len >
sizeof(sta->supported_rates)) {
- hostapd_logger(hapd, mgmt->sa,
+ hostapd_logger(hapd, sta->addr,
HOSTAPD_MODULE_IEEE80211,
HOSTAPD_LEVEL_DEBUG,
"Invalid supported rates element length"
- " %d+%d", elems.supp_rates_len,
- elems.ext_supp_rates_len);
- resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
- goto fail;
+ " %d+%d", elems->supp_rates_len,
+ elems->ext_supp_rates_len);
+ return WLAN_STATUS_UNSPECIFIED_FAILURE;
}
- os_memcpy(sta->supported_rates + elems.supp_rates_len,
- elems.ext_supp_rates, elems.ext_supp_rates_len);
- sta->supported_rates_len += elems.ext_supp_rates_len;
+ os_memcpy(sta->supported_rates + elems->supp_rates_len,
+ elems->ext_supp_rates, elems->ext_supp_rates_len);
+ sta->supported_rates_len += elems->ext_supp_rates_len;
+ }
+
+ return WLAN_STATUS_SUCCESS;
+}
+
+
+static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
+ const u8 *ies, size_t ies_len, int reassoc)
+{
+ struct ieee802_11_elems elems;
+ u16 resp;
+ const u8 *wpa_ie;
+ size_t wpa_ie_len;
+
+ if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
+ hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
+ HOSTAPD_LEVEL_INFO, "Station sent an invalid "
+ "association request");
+ return WLAN_STATUS_UNSPECIFIED_FAILURE;
}
+ resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
+ if (resp != WLAN_STATUS_SUCCESS)
+ return resp;
+ resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
+ if (resp != WLAN_STATUS_SUCCESS)
+ return resp;
+ resp = copy_supp_rates(hapd, sta, &elems);
+ if (resp != WLAN_STATUS_SUCCESS)
+ return resp;
#ifdef CONFIG_IEEE80211N
- /* save HT capabilities in the sta object */
- os_memset(&sta->ht_capabilities, 0, sizeof(sta->ht_capabilities));
- if (elems.ht_capabilities &&
- elems.ht_capabilities_len >=
- sizeof(struct ieee80211_ht_capability)) {
- sta->flags |= WLAN_STA_HT;
- sta->ht_capabilities.id = WLAN_EID_HT_CAP;
- sta->ht_capabilities.length =
- sizeof(struct ieee80211_ht_capability);
- os_memcpy(&sta->ht_capabilities.data,
- elems.ht_capabilities,
- sizeof(struct ieee80211_ht_capability));
- } else
- sta->flags &= ~WLAN_STA_HT;
+ resp = copy_sta_ht_capab(sta, elems.ht_capabilities,
+ elems.ht_capabilities_len);
+ if (resp != WLAN_STATUS_SUCCESS)
+ return resp;
#endif /* CONFIG_IEEE80211N */
if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
@@ -846,30 +652,29 @@ static void handle_assoc(struct hostapd_data *hapd,
wpa_ie = NULL;
wpa_ie_len = 0;
}
+
#ifdef CONFIG_WPS
sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS);
- if (hapd->conf->wps_state && wpa_ie == NULL) {
- if (elems.wps_ie) {
- wpa_printf(MSG_DEBUG, "STA included WPS IE in "
- "(Re)Association Request - assume WPS is "
- "used");
- sta->flags |= WLAN_STA_WPS;
- wpabuf_free(sta->wps_ie);
- sta->wps_ie = wpabuf_alloc_copy(elems.wps_ie + 4,
- elems.wps_ie_len - 4);
- } else {
- wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE "
- "in (Re)Association Request - possible WPS "
- "use");
- sta->flags |= WLAN_STA_MAYBE_WPS;
- }
+ if (hapd->conf->wps_state && elems.wps_ie) {
+ wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
+ "Request - assume WPS is used");
+ sta->flags |= WLAN_STA_WPS;
+ wpabuf_free(sta->wps_ie);
+ sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
+ WPS_IE_VENDOR_TYPE);
+ wpa_ie = NULL;
+ wpa_ie_len = 0;
+ } else if (hapd->conf->wps_state && wpa_ie == NULL) {
+ wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
+ "(Re)Association Request - possible WPS use");
+ sta->flags |= WLAN_STA_MAYBE_WPS;
} else
#endif /* CONFIG_WPS */
if (hapd->conf->wpa && wpa_ie == NULL) {
- printf("STA " MACSTR ": No WPA/RSN IE in association "
- "request\n", MAC2STR(sta->addr));
- resp = WLAN_STATUS_INVALID_IE;
- goto fail;
+ hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
+ HOSTAPD_LEVEL_INFO,
+ "No WPA/RSN IE in association request");
+ return WLAN_STATUS_INVALID_IE;
}
if (hapd->conf->wpa && wpa_ie) {
@@ -880,9 +685,9 @@ static void handle_assoc(struct hostapd_data *hapd,
sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
sta->addr);
if (sta->wpa_sm == NULL) {
- printf("Failed to initialize WPA state machine\n");
- resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
- goto fail;
+ wpa_printf(MSG_WARNING, "Failed to initialize WPA "
+ "state machine");
+ return WLAN_STATUS_UNSPECIFIED_FAILURE;
}
res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
wpa_ie, wpa_ie_len,
@@ -906,7 +711,7 @@ static void handle_assoc(struct hostapd_data *hapd,
else if (res != WPA_IE_OK)
resp = WLAN_STATUS_INVALID_IE;
if (resp != WLAN_STATUS_SUCCESS)
- goto fail;
+ return resp;
#ifdef CONFIG_IEEE80211W
if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
sta->sa_query_count > 0)
@@ -923,8 +728,7 @@ static void handle_assoc(struct hostapd_data *hapd,
if (sta->sa_query_count == 0)
ap_sta_start_sa_query(hapd, sta);
- resp = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
- goto fail;
+ return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
}
if (wpa_auth_uses_mfp(sta->wpa_sm))
@@ -940,28 +744,219 @@ static void handle_assoc(struct hostapd_data *hapd,
"to use association (not "
"re-association) with FT auth_alg",
MAC2STR(sta->addr));
- resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
- goto fail;
+ return WLAN_STATUS_UNSPECIFIED_FAILURE;
}
- resp = wpa_ft_validate_reassoc(sta->wpa_sm, pos, left);
+ resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
+ ies_len);
if (resp != WLAN_STATUS_SUCCESS)
- goto fail;
+ return resp;
}
#endif /* CONFIG_IEEE80211R */
+
#ifdef CONFIG_IEEE80211N
if ((sta->flags & WLAN_STA_HT) &&
wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
- wpa_printf(MSG_DEBUG, "HT: " MACSTR " tried to "
- "use TKIP with HT association",
- MAC2STR(sta->addr));
- resp = WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
- goto fail;
+ hostapd_logger(hapd, sta->addr,
+ HOSTAPD_MODULE_IEEE80211,
+ HOSTAPD_LEVEL_INFO,
+ "Station tried to use TKIP with HT "
+ "association");
+ return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
}
#endif /* CONFIG_IEEE80211N */
} else
wpa_auth_sta_no_wpa(sta->wpa_sm);
+ return WLAN_STATUS_SUCCESS;
+}
+
+
+static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
+ u16 reason_code)
+{
+ int send_len;
+ struct ieee80211_mgmt reply;
+
+ os_memset(&reply, 0, sizeof(reply));
+ reply.frame_control =
+ IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
+ os_memcpy(reply.da, addr, ETH_ALEN);
+ os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
+ os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
+
+ send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
+ reply.u.deauth.reason_code = host_to_le16(reason_code);
+
+ if (hapd->drv.send_mgmt_frame(hapd, &reply, send_len) < 0)
+ wpa_printf(MSG_INFO, "Failed to send deauth: %s",
+ strerror(errno));
+}
+
+
+static void send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
+ u16 status_code, int reassoc, const u8 *ies,
+ size_t ies_len)
+{
+ int send_len;
+ u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
+ struct ieee80211_mgmt *reply;
+ u8 *p;
+
+ os_memset(buf, 0, sizeof(buf));
+ reply = (struct ieee80211_mgmt *) buf;
+ reply->frame_control =
+ IEEE80211_FC(WLAN_FC_TYPE_MGMT,
+ (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
+ WLAN_FC_STYPE_ASSOC_RESP));
+ os_memcpy(reply->da, sta->addr, ETH_ALEN);
+ os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
+ os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
+
+ send_len = IEEE80211_HDRLEN;
+ send_len += sizeof(reply->u.assoc_resp);
+ reply->u.assoc_resp.capab_info =
+ host_to_le16(hostapd_own_capab_info(hapd, sta, 0));
+ reply->u.assoc_resp.status_code = host_to_le16(status_code);
+ reply->u.assoc_resp.aid = host_to_le16((sta ? sta->aid : 0)
+ | BIT(14) | BIT(15));
+ /* Supported rates */
+ p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
+ /* Extended supported rates */
+ p = hostapd_eid_ext_supp_rates(hapd, p);
+
+#ifdef CONFIG_IEEE80211R
+ if (status_code == WLAN_STATUS_SUCCESS) {
+ /* IEEE 802.11r: Mobility Domain Information, Fast BSS
+ * Transition Information, RSN, [RIC Response] */
+ p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
+ buf + sizeof(buf) - p,
+ sta->auth_alg, ies, ies_len);
+ }
+#endif /* CONFIG_IEEE80211R */
+
+#ifdef CONFIG_IEEE80211W
+ if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
+ p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
+#endif /* CONFIG_IEEE80211W */
+
+#ifdef CONFIG_IEEE80211N
+ p = hostapd_eid_ht_capabilities(hapd, p);
+ p = hostapd_eid_ht_operation(hapd, p);
+#endif /* CONFIG_IEEE80211N */
+
+ if (sta->flags & WLAN_STA_WMM)
+ p = hostapd_eid_wmm(hapd, p);
+
+#ifdef CONFIG_WPS
+ if (sta->flags & WLAN_STA_WPS) {
+ struct wpabuf *wps = wps_build_assoc_resp_ie();
+ if (wps) {
+ os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
+ p += wpabuf_len(wps);
+ wpabuf_free(wps);
+ }
+ }
+#endif /* CONFIG_WPS */
+
+ send_len += p - reply->u.assoc_resp.variable;
+
+ if (hapd->drv.send_mgmt_frame(hapd, reply, send_len) < 0)
+ wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
+ strerror(errno));
+}
+
+
+static void handle_assoc(struct hostapd_data *hapd,
+ const struct ieee80211_mgmt *mgmt, size_t len,
+ int reassoc)
+{
+ u16 capab_info, listen_interval;
+ u16 resp = WLAN_STATUS_SUCCESS;
+ const u8 *pos;
+ int left, i;
+ struct sta_info *sta;
+
+ if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
+ sizeof(mgmt->u.assoc_req))) {
+ printf("handle_assoc(reassoc=%d) - too short payload (len=%lu)"
+ "\n", reassoc, (unsigned long) len);
+ return;
+ }
+
+ if (reassoc) {
+ capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
+ listen_interval = le_to_host16(
+ mgmt->u.reassoc_req.listen_interval);
+ wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
+ " capab_info=0x%02x listen_interval=%d current_ap="
+ MACSTR,
+ MAC2STR(mgmt->sa), capab_info, listen_interval,
+ MAC2STR(mgmt->u.reassoc_req.current_ap));
+ left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
+ pos = mgmt->u.reassoc_req.variable;
+ } else {
+ capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
+ listen_interval = le_to_host16(
+ mgmt->u.assoc_req.listen_interval);
+ wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
+ " capab_info=0x%02x listen_interval=%d",
+ MAC2STR(mgmt->sa), capab_info, listen_interval);
+ left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
+ pos = mgmt->u.assoc_req.variable;
+ }
+
+ sta = ap_get_sta(hapd, mgmt->sa);
+#ifdef CONFIG_IEEE80211R
+ if (sta && sta->auth_alg == WLAN_AUTH_FT &&
+ (sta->flags & WLAN_STA_AUTH) == 0) {
+ wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
+ "prior to authentication since it is using "
+ "over-the-DS FT", MAC2STR(mgmt->sa));
+ } else
+#endif /* CONFIG_IEEE80211R */
+ if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
+ hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
+ HOSTAPD_LEVEL_INFO, "Station tried to "
+ "associate before authentication "
+ "(aid=%d flags=0x%x)",
+ sta ? sta->aid : -1,
+ sta ? sta->flags : 0);
+ send_deauth(hapd, mgmt->sa,
+ WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
+ return;
+ }
+
+ if (hapd->tkip_countermeasures) {
+ resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
+ goto fail;
+ }
+
+ if (listen_interval > hapd->conf->max_listen_interval) {
+ hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
+ HOSTAPD_LEVEL_DEBUG,
+ "Too large Listen Interval (%d)",
+ listen_interval);
+ resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
+ goto fail;
+ }
+
+ /* followed by SSID and Supported rates; and HT capabilities if 802.11n
+ * is used */
+ resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
+ if (resp != WLAN_STATUS_SUCCESS)
+ goto fail;
+
+ if (hostapd_get_aid(hapd, sta) < 0) {
+ hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
+ HOSTAPD_LEVEL_INFO, "No room for more AIDs");
+ resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
+ goto fail;
+ }
+
+ sta->capability = capab_info;
+ sta->listen_interval = listen_interval;
+
if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
sta->flags |= WLAN_STA_NONERP;
for (i = 0; i < sta->supported_rates_len; i++) {
@@ -1002,66 +997,9 @@ static void handle_assoc(struct hostapd_data *hapd,
}
#ifdef CONFIG_IEEE80211N
- if (sta->flags & WLAN_STA_HT) {
- u16 ht_capab = le_to_host16(
- sta->ht_capabilities.data.capabilities_info);
- wpa_printf(MSG_DEBUG, "HT: STA " MACSTR " HT Capabilities "
- "Info: 0x%04x", MAC2STR(sta->addr), ht_capab);
- if ((ht_capab & HT_CAP_INFO_GREEN_FIELD) == 0) {
- if (!sta->no_ht_gf_set) {
- sta->no_ht_gf_set = 1;
- hapd->iface->num_sta_ht_no_gf++;
- }
- wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - no "
- "greenfield, num of non-gf stations %d",
- __func__, MAC2STR(sta->addr),
- hapd->iface->num_sta_ht_no_gf);
- }
- if ((ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) == 0) {
- if (!sta->ht_20mhz_set) {
- sta->ht_20mhz_set = 1;
- hapd->iface->num_sta_ht_20mhz++;
- }
- wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - 20 MHz HT, "
- "num of 20MHz HT STAs %d",
- __func__, MAC2STR(sta->addr),
- hapd->iface->num_sta_ht_20mhz);
- }
- } else {
- if (!sta->no_ht_set) {
- sta->no_ht_set = 1;
- hapd->iface->num_sta_no_ht++;
- }
- if (hapd->iconf->ieee80211n) {
- wpa_printf(MSG_DEBUG, "%s STA " MACSTR
- " - no HT, num of non-HT stations %d",
- __func__, MAC2STR(sta->addr),
- hapd->iface->num_sta_no_ht);
- }
- }
-
- if (hostapd_ht_operation_update(hapd->iface) > 0)
- ieee802_11_set_beacons(hapd->iface);
+ update_ht_state(hapd, sta);
#endif /* CONFIG_IEEE80211N */
- /* get a unique AID */
- if (sta->aid > 0) {
- wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
- } else {
- for (sta->aid = 1; sta->aid <= MAX_AID_TABLE_SIZE; sta->aid++)
- if (hapd->sta_aid[sta->aid - 1] == NULL)
- break;
- if (sta->aid > MAX_AID_TABLE_SIZE) {
- sta->aid = 0;
- resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
- wpa_printf(MSG_ERROR, " no room for more AIDs");
- goto fail;
- } else {
- hapd->sta_aid[sta->aid - 1] = sta;
- wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
- }
- }
-
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
HOSTAPD_LEVEL_DEBUG,
"association OK (aid %d)", sta->aid);
@@ -1097,64 +1035,12 @@ static void handle_assoc(struct hostapd_data *hapd,
sta->timeout_next = STA_NULLFUNC;
fail:
- os_memset(buf, 0, sizeof(buf));
- reply = (struct ieee80211_mgmt *) buf;
- reply->frame_control =
- IEEE80211_FC(WLAN_FC_TYPE_MGMT,
- (send_deauth ? WLAN_FC_STYPE_DEAUTH :
- (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
- WLAN_FC_STYPE_ASSOC_RESP)));
- os_memcpy(reply->da, mgmt->sa, ETH_ALEN);
- os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
- os_memcpy(reply->bssid, mgmt->bssid, ETH_ALEN);
-
- send_len = IEEE80211_HDRLEN;
- if (send_deauth) {
- send_len += sizeof(reply->u.deauth);
- reply->u.deauth.reason_code = host_to_le16(resp);
- } else {
- u8 *p;
- send_len += sizeof(reply->u.assoc_resp);
- reply->u.assoc_resp.capab_info =
- host_to_le16(hostapd_own_capab_info(hapd, sta, 0));
- reply->u.assoc_resp.status_code = host_to_le16(resp);
- reply->u.assoc_resp.aid = host_to_le16((sta ? sta->aid : 0)
- | BIT(14) | BIT(15));
- /* Supported rates */
- p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
- /* Extended supported rates */
- p = hostapd_eid_ext_supp_rates(hapd, p);
- if (sta->flags & WLAN_STA_WMM)
- p = hostapd_eid_wmm(hapd, p);
-
- p = hostapd_eid_ht_capabilities_info(hapd, p);
- p = hostapd_eid_ht_operation(hapd, p);
-
-#ifdef CONFIG_IEEE80211R
- if (resp == WLAN_STATUS_SUCCESS) {
- /* IEEE 802.11r: Mobility Domain Information, Fast BSS
- * Transition Information, RSN */
- p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
- buf + sizeof(buf) - p,
- sta->auth_alg);
- }
-#endif /* CONFIG_IEEE80211R */
-
-#ifdef CONFIG_IEEE80211W
- if (resp == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
- p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
-#endif /* CONFIG_IEEE80211W */
-
- send_len += p - reply->u.assoc_resp.variable;
- }
-
- if (hostapd_send_mgmt_frame(hapd, reply, send_len, 0) < 0)
- perror("handle_assoc: send");
+ send_assoc_resp(hapd, sta, resp, reassoc, pos, left);
}
static void handle_disassoc(struct hostapd_data *hapd,
- struct ieee80211_mgmt *mgmt, size_t len)
+ const struct ieee80211_mgmt *mgmt, size_t len)
{
struct sta_info *sta;
@@ -1176,6 +1062,8 @@ static void handle_disassoc(struct hostapd_data *hapd,
}
sta->flags &= ~WLAN_STA_ASSOC;
+ wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED MACSTR,
+ MAC2STR(sta->addr));
wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
HOSTAPD_LEVEL_INFO, "disassociated");
@@ -1185,7 +1073,7 @@ static void handle_disassoc(struct hostapd_data *hapd,
* authenticated. */
accounting_sta_stop(hapd, sta);
ieee802_1x_free_station(sta);
- hostapd_sta_remove(hapd, sta->addr);
+ hapd->drv.sta_remove(hapd, sta->addr);
if (sta->timeout_next == STA_NULLFUNC ||
sta->timeout_next == STA_DISASSOC) {
@@ -1201,7 +1089,7 @@ static void handle_disassoc(struct hostapd_data *hapd,
static void handle_deauth(struct hostapd_data *hapd,
- struct ieee80211_mgmt *mgmt, size_t len)
+ const struct ieee80211_mgmt *mgmt, size_t len)
{
struct sta_info *sta;
@@ -1224,6 +1112,8 @@ static void handle_deauth(struct hostapd_data *hapd,
}
sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
+ wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED MACSTR,
+ MAC2STR(sta->addr));
wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
HOSTAPD_LEVEL_DEBUG, "deauthenticated");
@@ -1236,7 +1126,7 @@ static void handle_deauth(struct hostapd_data *hapd,
static void handle_beacon(struct hostapd_data *hapd,
- struct ieee80211_mgmt *mgmt, size_t len,
+ const struct ieee80211_mgmt *mgmt, size_t len,
struct hostapd_frame_info *fi)
{
struct ieee802_11_elems elems;
@@ -1281,16 +1171,57 @@ void ieee802_11_send_sa_query_req(struct hostapd_data *hapd,
os_memcpy(mgmt.u.action.u.sa_query_req.trans_id, trans_id,
WLAN_SA_QUERY_TR_ID_LEN);
end = mgmt.u.action.u.sa_query_req.trans_id + WLAN_SA_QUERY_TR_ID_LEN;
- if (hostapd_send_mgmt_frame(hapd, &mgmt, end - (u8 *) &mgmt, 0) < 0)
+ if (hapd->drv.send_mgmt_frame(hapd, &mgmt, end - (u8 *) &mgmt) < 0)
perror("ieee802_11_send_sa_query_req: send");
}
-static void hostapd_sa_query_action(struct hostapd_data *hapd,
- struct ieee80211_mgmt *mgmt, size_t len)
+static void hostapd_sa_query_request(struct hostapd_data *hapd,
+ const struct ieee80211_mgmt *mgmt)
{
struct sta_info *sta;
+ struct ieee80211_mgmt resp;
u8 *end;
+
+ wpa_printf(MSG_DEBUG, "IEEE 802.11: Received SA Query Request from "
+ MACSTR, MAC2STR(mgmt->sa));
+ wpa_hexdump(MSG_DEBUG, "IEEE 802.11: SA Query Transaction ID",
+ mgmt->u.action.u.sa_query_resp.trans_id,
+ WLAN_SA_QUERY_TR_ID_LEN);
+
+ sta = ap_get_sta(hapd, mgmt->sa);
+ if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
+ wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignore SA Query Request "
+ "from unassociated STA " MACSTR, MAC2STR(mgmt->sa));
+ return;
+ }
+
+ wpa_printf(MSG_DEBUG, "IEEE 802.11: Sending SA Query Response to "
+ MACSTR, MAC2STR(mgmt->sa));
+
+ os_memset(&resp, 0, sizeof(resp));
+ resp.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
+ WLAN_FC_STYPE_ACTION);
+ os_memcpy(resp.da, mgmt->sa, ETH_ALEN);
+ os_memcpy(resp.sa, hapd->own_addr, ETH_ALEN);
+ os_memcpy(resp.bssid, hapd->own_addr, ETH_ALEN);
+ resp.u.action.category = WLAN_ACTION_SA_QUERY;
+ resp.u.action.u.sa_query_req.action = WLAN_SA_QUERY_RESPONSE;
+ os_memcpy(resp.u.action.u.sa_query_req.trans_id,
+ mgmt->u.action.u.sa_query_req.trans_id,
+ WLAN_SA_QUERY_TR_ID_LEN);
+ end = resp.u.action.u.sa_query_req.trans_id + WLAN_SA_QUERY_TR_ID_LEN;
+ if (hapd->drv.send_mgmt_frame(hapd, &resp, end - (u8 *) &resp) < 0)
+ perror("hostapd_sa_query_request: send");
+}
+
+
+static void hostapd_sa_query_action(struct hostapd_data *hapd,
+ const struct ieee80211_mgmt *mgmt,
+ size_t len)
+{
+ struct sta_info *sta;
+ const u8 *end;
int i;
end = mgmt->u.action.u.sa_query_resp.trans_id +
@@ -1301,6 +1232,11 @@ static void hostapd_sa_query_action(struct hostapd_data *hapd,
return;
}
+ if (mgmt->u.action.u.sa_query_resp.action == WLAN_SA_QUERY_REQUEST) {
+ hostapd_sa_query_request(hapd, mgmt);
+ return;
+ }
+
if (mgmt->u.action.u.sa_query_resp.action != WLAN_SA_QUERY_RESPONSE) {
wpa_printf(MSG_DEBUG, "IEEE 802.11: Unexpected SA Query "
"Action %d", mgmt->u.action.u.sa_query_resp.action);
@@ -1352,7 +1288,7 @@ static int robust_action_frame(u8 category)
static void handle_action(struct hostapd_data *hapd,
- struct ieee80211_mgmt *mgmt, size_t len)
+ const struct ieee80211_mgmt *mgmt, size_t len)
{
struct sta_info *sta;
@@ -1403,6 +1339,14 @@ static void handle_action(struct hostapd_data *hapd,
hostapd_sa_query_action(hapd, mgmt, len);
return;
#endif /* CONFIG_IEEE80211W */
+ case WLAN_ACTION_PUBLIC:
+ if (hapd->public_action_cb) {
+ hapd->public_action_cb(hapd->public_action_cb_ctx,
+ (u8 *) mgmt, len,
+ hapd->iface->freq);
+ return;
+ }
+ break;
}
hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
@@ -1412,6 +1356,8 @@ static void handle_action(struct hostapd_data *hapd,
mgmt->u.action.category);
if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
!(mgmt->sa[0] & 0x01)) {
+ struct ieee80211_mgmt *resp;
+
/*
* IEEE 802.11-REVma/D9.0 - 7.3.1.11
* Return the Action frame to the source without change
@@ -1419,12 +1365,17 @@ static void handle_action(struct hostapd_data *hapd,
*/
wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
"frame back to sender");
- os_memcpy(mgmt->da, mgmt->sa, ETH_ALEN);
- os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
- os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
- mgmt->u.action.category |= 0x80;
+ resp = os_malloc(len);
+ if (resp == NULL)
+ return;
+ os_memcpy(resp, mgmt, len);
+ os_memcpy(resp->da, resp->sa, ETH_ALEN);
+ os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
+ os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
+ resp->u.action.category |= 0x80;
- hostapd_send_mgmt_frame(hapd, mgmt, len, 0);
+ hapd->drv.send_mgmt_frame(hapd, resp, len);
+ os_free(resp);
}
}
@@ -1435,7 +1386,6 @@ static void handle_action(struct hostapd_data *hapd,
* sent to)
* @buf: management frame data (starting from IEEE 802.11 header)
* @len: length of frame data in octets
- * @stype: management frame subtype from frame control field
* @fi: meta data about received frame (signal level, etc.)
*
* Process all incoming IEEE 802.11 management frames. This will be called for
@@ -1443,20 +1393,22 @@ static void handle_action(struct hostapd_data *hapd,
* addition, it can be called to re-inserted pending frames (e.g., when using
* external RADIUS server as an MAC ACL).
*/
-void ieee802_11_mgmt(struct hostapd_data *hapd, u8 *buf, size_t len, u16 stype,
+void ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
struct hostapd_frame_info *fi)
{
- struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) buf;
+ struct ieee80211_mgmt *mgmt;
int broadcast;
+ u16 fc, stype;
+
+ mgmt = (struct ieee80211_mgmt *) buf;
+ fc = le_to_host16(mgmt->frame_control);
+ stype = WLAN_FC_GET_STYPE(fc);
if (stype == WLAN_FC_STYPE_BEACON) {
handle_beacon(hapd, mgmt, len, fi);
return;
}
- if (fi && fi->passive_scan)
- return;
-
broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
@@ -1517,7 +1469,7 @@ void ieee802_11_mgmt(struct hostapd_data *hapd, u8 *buf, size_t len, u16 stype,
static void handle_auth_cb(struct hostapd_data *hapd,
- struct ieee80211_mgmt *mgmt,
+ const struct ieee80211_mgmt *mgmt,
size_t len, int ok)
{
u16 auth_alg, auth_transaction, status_code;
@@ -1557,38 +1509,14 @@ static void handle_auth_cb(struct hostapd_data *hapd,
}
-#ifdef CONFIG_IEEE80211N
-static void
-hostapd_get_ht_capab(struct hostapd_data *hapd,
- struct ht_cap_ie *ht_cap_ie,
- struct ht_cap_ie *neg_ht_cap_ie)
-{
- u16 cap;
-
- os_memcpy(neg_ht_cap_ie, ht_cap_ie, sizeof(struct ht_cap_ie));
- cap = le_to_host16(neg_ht_cap_ie->data.capabilities_info);
- cap &= hapd->iconf->ht_capab;
- cap |= (hapd->iconf->ht_capab & HT_CAP_INFO_SMPS_DISABLED);
-
- /* FIXME: Rx STBC needs to be handled specially */
- cap |= (hapd->iconf->ht_capab & HT_CAP_INFO_RX_STBC_MASK);
- neg_ht_cap_ie->data.capabilities_info = host_to_le16(cap);
-}
-#endif /* CONFIG_IEEE80211N */
-
-
static void handle_assoc_cb(struct hostapd_data *hapd,
- struct ieee80211_mgmt *mgmt,
+ const struct ieee80211_mgmt *mgmt,
size_t len, int reassoc, int ok)
{
u16 status;
struct sta_info *sta;
int new_assoc = 1;
-#ifdef CONFIG_IEEE80211N
- struct ht_cap_ie ht_cap;
-#endif /* CONFIG_IEEE80211N */
- struct ht_cap_ie *ht_cap_ptr = NULL;
- int set_flags, flags_and, flags_or;
+ struct ieee80211_ht_capabilities ht_cap;
if (!ok) {
hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
@@ -1631,19 +1559,22 @@ static void handle_assoc_cb(struct hostapd_data *hapd,
if (sta->flags & WLAN_STA_ASSOC)
new_assoc = 0;
sta->flags |= WLAN_STA_ASSOC;
+ if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa) ||
+ sta->auth_alg == WLAN_AUTH_FT) {
+ /*
+ * Open, static WEP, or FT protocol; no separate authorization
+ * step.
+ */
+ sta->flags |= WLAN_STA_AUTHORIZED;
+ wpa_msg(hapd->msg_ctx, MSG_INFO,
+ AP_STA_CONNECTED MACSTR, MAC2STR(sta->addr));
+ }
if (reassoc)
mlme_reassociate_indication(hapd, sta);
else
mlme_associate_indication(hapd, sta);
-#ifdef CONFIG_IEEE80211N
- if (sta->flags & WLAN_STA_HT) {
- ht_cap_ptr = &ht_cap;
- hostapd_get_ht_capab(hapd, &sta->ht_capabilities, ht_cap_ptr);
- }
-#endif /* CONFIG_IEEE80211N */
-
#ifdef CONFIG_IEEE80211W
sta->sa_query_timed_out = 0;
#endif /* CONFIG_IEEE80211W */
@@ -1653,13 +1584,17 @@ static void handle_assoc_cb(struct hostapd_data *hapd,
* cleared and configuration gets updated in case of reassociation back
* to the same AP.
*/
- hostapd_sta_remove(hapd, sta->addr);
+ hapd->drv.sta_remove(hapd, sta->addr);
- if (hostapd_sta_add(hapd->conf->iface, hapd, sta->addr, sta->aid,
- sta->capability, sta->supported_rates,
- sta->supported_rates_len, 0, sta->listen_interval,
- ht_cap_ptr))
- {
+#ifdef CONFIG_IEEE80211N
+ if (sta->flags & WLAN_STA_HT)
+ hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
+#endif /* CONFIG_IEEE80211N */
+
+ if (hapd->drv.sta_add(hapd, sta->addr, sta->aid, sta->capability,
+ sta->supported_rates, sta->supported_rates_len,
+ sta->listen_interval,
+ sta->flags & WLAN_STA_HT ? &ht_cap : NULL)) {
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
HOSTAPD_LEVEL_NOTICE,
"Could not add STA to kernel driver");
@@ -1671,26 +1606,21 @@ static void handle_assoc_cb(struct hostapd_data *hapd,
* so bind it to the selected VLAN interface now, since the
* interface selection is not going to change anymore.
*/
- ap_sta_bind_vlan(hapd, sta, 0);
+ if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
+ goto fail;
} else if (sta->vlan_id) {
/* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
- ap_sta_bind_vlan(hapd, sta, 0);
+ if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
+ goto fail;
}
- set_flags = WLAN_STA_SHORT_PREAMBLE | WLAN_STA_WMM | WLAN_STA_MFP;
- if (!hapd->conf->ieee802_1x && !hapd->conf->wpa &&
- sta->flags & WLAN_STA_AUTHORIZED)
- set_flags |= WLAN_STA_AUTHORIZED;
- flags_or = sta->flags & set_flags;
- flags_and = sta->flags | ~set_flags;
- hostapd_sta_set_flags(hapd, sta->addr, sta->flags,
- flags_or, flags_and);
+ hapd->drv.set_sta_flags(hapd, sta);
if (sta->auth_alg == WLAN_AUTH_FT)
wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
else
wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
- hostapd_new_assoc_sta(hapd, sta, !new_assoc);
+ hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
@@ -1712,10 +1642,11 @@ static void handle_assoc_cb(struct hostapd_data *hapd,
* @stype: management frame subtype from frame control field
* @ok: Whether the frame was ACK'ed
*/
-void ieee802_11_mgmt_cb(struct hostapd_data *hapd, u8 *buf, size_t len,
+void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
u16 stype, int ok)
{
- struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) buf;
+ const struct ieee80211_mgmt *mgmt;
+ mgmt = (const struct ieee80211_mgmt *) buf;
switch (stype) {
case WLAN_FC_STYPE_AUTH:
@@ -1746,88 +1677,79 @@ void ieee802_11_mgmt_cb(struct hostapd_data *hapd, u8 *buf, size_t len,
}
-static void ieee80211_tkip_countermeasures_stop(void *eloop_ctx,
- void *timeout_ctx)
+int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
{
- struct hostapd_data *hapd = eloop_ctx;
- hapd->tkip_countermeasures = 0;
- hostapd_set_countermeasures(hapd, 0);
- hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
- HOSTAPD_LEVEL_INFO, "TKIP countermeasures ended");
+ /* TODO */
+ return 0;
}
-static void ieee80211_tkip_countermeasures_start(struct hostapd_data *hapd)
+int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
+ char *buf, size_t buflen)
{
- struct sta_info *sta;
-
- hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
- HOSTAPD_LEVEL_INFO, "TKIP countermeasures initiated");
-
- wpa_auth_countermeasures_start(hapd->wpa_auth);
- hapd->tkip_countermeasures = 1;
- hostapd_set_countermeasures(hapd, 1);
- wpa_gtk_rekey(hapd->wpa_auth);
- eloop_cancel_timeout(ieee80211_tkip_countermeasures_stop, hapd, NULL);
- eloop_register_timeout(60, 0, ieee80211_tkip_countermeasures_stop,
- hapd, NULL);
- for (sta = hapd->sta_list; sta != NULL; sta = sta->next) {
- hostapd_sta_deauth(hapd, sta->addr,
- WLAN_REASON_MICHAEL_MIC_FAILURE);
- sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
- WLAN_STA_AUTHORIZED);
- hostapd_sta_remove(hapd, sta->addr);
- }
+ /* TODO */
+ return 0;
}
-void ieee80211_michael_mic_failure(struct hostapd_data *hapd, const u8 *addr,
- int local)
+void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
+ const u8 *buf, size_t len, int ack)
{
- time_t now;
-
- if (addr && local) {
- struct sta_info *sta = ap_get_sta(hapd, addr);
- if (sta != NULL) {
- wpa_auth_sta_local_mic_failure_report(sta->wpa_sm);
- hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
- HOSTAPD_LEVEL_INFO,
- "Michael MIC failure detected in "
- "received frame");
- mlme_michaelmicfailure_indication(hapd, addr);
- } else {
- wpa_printf(MSG_DEBUG,
- "MLME-MICHAELMICFAILURE.indication "
- "for not associated STA (" MACSTR
- ") ignored", MAC2STR(addr));
- return;
+ struct sta_info *sta;
+ struct hostapd_iface *iface = hapd->iface;
+
+ sta = ap_get_sta(hapd, addr);
+ if (sta == NULL && iface->num_bss > 1) {
+ size_t j;
+ for (j = 0; j < iface->num_bss; j++) {
+ hapd = iface->bss[j];
+ sta = ap_get_sta(hapd, addr);
+ if (sta)
+ break;
}
}
-
- time(&now);
- if (now > hapd->michael_mic_failure + 60) {
- hapd->michael_mic_failures = 1;
- } else {
- hapd->michael_mic_failures++;
- if (hapd->michael_mic_failures > 1)
- ieee80211_tkip_countermeasures_start(hapd);
+ if (sta == NULL)
+ return;
+ if (sta->flags & WLAN_STA_PENDING_POLL) {
+ wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
+ "activity poll", MAC2STR(sta->addr),
+ ack ? "ACKed" : "did not ACK");
+ if (ack)
+ sta->flags &= ~WLAN_STA_PENDING_POLL;
}
- hapd->michael_mic_failure = now;
+
+ ieee802_1x_tx_status(hapd, sta, buf, len, ack);
}
-int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
+void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
+ int wds)
{
- /* TODO */
- return 0;
-}
+ struct sta_info *sta;
+ sta = ap_get_sta(hapd, src);
+ if (sta && (sta->flags & WLAN_STA_ASSOC)) {
+ if (wds && !(sta->flags & WLAN_STA_WDS)) {
+ wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
+ "STA " MACSTR " (aid %u)",
+ MAC2STR(sta->addr), sta->aid);
+ sta->flags |= WLAN_STA_WDS;
+ hapd->drv.set_wds_sta(hapd, sta->addr, sta->aid, 1);
+ }
+ return;
+ }
-int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
- char *buf, size_t buflen)
-{
- /* TODO */
- return 0;
+ wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
+ MACSTR, MAC2STR(src));
+ if (sta && (sta->flags & WLAN_STA_AUTH))
+ hapd->drv.sta_disassoc(
+ hapd, src,
+ WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
+ else
+ hapd->drv.sta_deauth(
+ hapd, src,
+ WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
}
+
#endif /* CONFIG_NATIVE_WINDOWS */
diff --git a/contrib/wpa/hostapd/ieee802_11.h b/contrib/wpa/src/ap/ieee802_11.h
index ca8ef93..cfc069c 100644
--- a/contrib/wpa/hostapd/ieee802_11.h
+++ b/contrib/wpa/src/ap/ieee802_11.h
@@ -1,7 +1,6 @@
/*
* hostapd / IEEE 802.11 Management
- * Copyright (c) 2002-2006, Jouni Malinen <j@w1.fi>
- * Copyright (c) 2007-2008, Intel Corporation
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -16,41 +15,53 @@
#ifndef IEEE802_11_H
#define IEEE802_11_H
-#include "ieee802_11_defs.h"
-#include "ieee802_11_common.h"
-
-struct hostapd_frame_info {
- u32 phytype;
- u32 channel;
- u32 datarate;
- u32 ssi_signal;
-
- unsigned int passive_scan:1;
-};
-
struct hostapd_iface;
struct hostapd_data;
struct sta_info;
+struct hostapd_frame_info;
+struct ieee80211_ht_capabilities;
-void ieee802_11_send_deauth(struct hostapd_data *hapd, u8 *addr, u16 reason);
-void ieee802_11_mgmt(struct hostapd_data *hapd, u8 *buf, size_t len,
- u16 stype, struct hostapd_frame_info *fi);
-void ieee802_11_mgmt_cb(struct hostapd_data *hapd, u8 *buf, size_t len,
+void ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
+ struct hostapd_frame_info *fi);
+void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
u16 stype, int ok);
void ieee802_11_print_ssid(char *buf, const u8 *ssid, u8 len);
-void ieee80211_michael_mic_failure(struct hostapd_data *hapd, const u8 *addr,
- int local);
+#ifdef NEED_AP_MLME
int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen);
int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
char *buf, size_t buflen);
+#else /* NEED_AP_MLME */
+static inline int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf,
+ size_t buflen)
+{
+ return 0;
+}
+
+static inline int ieee802_11_get_mib_sta(struct hostapd_data *hapd,
+ struct sta_info *sta,
+ char *buf, size_t buflen)
+{
+ return 0;
+}
+#endif /* NEED_AP_MLME */
u16 hostapd_own_capab_info(struct hostapd_data *hapd, struct sta_info *sta,
int probe);
u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid);
u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid);
-u8 * hostapd_eid_ht_capabilities_info(struct hostapd_data *hapd, u8 *eid);
+u8 * hostapd_eid_ht_capabilities(struct hostapd_data *hapd, u8 *eid);
u8 * hostapd_eid_ht_operation(struct hostapd_data *hapd, u8 *eid);
int hostapd_ht_operation_update(struct hostapd_iface *iface);
void ieee802_11_send_sa_query_req(struct hostapd_data *hapd,
const u8 *addr, const u8 *trans_id);
+void hostapd_get_ht_capab(struct hostapd_data *hapd,
+ struct ieee80211_ht_capabilities *ht_cap,
+ struct ieee80211_ht_capabilities *neg_ht_cap);
+u16 copy_sta_ht_capab(struct sta_info *sta, const u8 *ht_capab,
+ size_t ht_capab_len);
+void update_ht_state(struct hostapd_data *hapd, struct sta_info *sta);
+void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
+ const u8 *buf, size_t len, int ack);
+void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
+ int wds);
#endif /* IEEE802_11_H */
diff --git a/contrib/wpa/hostapd/ieee802_11_auth.c b/contrib/wpa/src/ap/ieee802_11_auth.c
index 9aba1fe..dec56d1 100644
--- a/contrib/wpa/hostapd/ieee802_11_auth.c
+++ b/contrib/wpa/src/ap/ieee802_11_auth.c
@@ -1,6 +1,6 @@
/*
* hostapd / IEEE 802.11 authentication (ACL)
- * Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -17,17 +17,16 @@
* authentication frame processing.
*/
-#include "includes.h"
-
-#ifndef CONFIG_NATIVE_WINDOWS
+#include "utils/includes.h"
+#include "utils/common.h"
+#include "utils/eloop.h"
+#include "radius/radius.h"
+#include "radius/radius_client.h"
#include "hostapd.h"
+#include "ap_config.h"
#include "ieee802_11.h"
#include "ieee802_11_auth.h"
-#include "radius/radius.h"
-#include "radius/radius_client.h"
-#include "eloop.h"
-#include "driver.h"
#define RADIUS_ACL_TIMEOUT 30
@@ -53,6 +52,7 @@ struct hostapd_acl_query_data {
};
+#ifndef CONFIG_NO_RADIUS
static void hostapd_acl_cache_free(struct hostapd_cached_radius_acl *acl_cache)
{
struct hostapd_cached_radius_acl *prev;
@@ -96,6 +96,7 @@ static int hostapd_acl_cache_get(struct hostapd_data *hapd, const u8 *addr,
return -1;
}
+#endif /* CONFIG_NO_RADIUS */
static void hostapd_acl_query_free(struct hostapd_acl_query_data *query)
@@ -107,6 +108,7 @@ static void hostapd_acl_query_free(struct hostapd_acl_query_data *query)
}
+#ifndef CONFIG_NO_RADIUS
static int hostapd_radius_acl_query(struct hostapd_data *hapd, const u8 *addr,
struct hostapd_acl_query_data *query)
{
@@ -193,9 +195,9 @@ static int hostapd_radius_acl_query(struct hostapd_data *hapd, const u8 *addr,
fail:
radius_msg_free(msg);
- os_free(msg);
return -1;
}
+#endif /* CONFIG_NO_RADIUS */
/**
@@ -234,6 +236,9 @@ int hostapd_allowed_address(struct hostapd_data *hapd, const u8 *addr,
return HOSTAPD_ACL_REJECT;
if (hapd->conf->macaddr_acl == USE_EXTERNAL_RADIUS_AUTH) {
+#ifdef CONFIG_NO_RADIUS
+ return HOSTAPD_ACL_REJECT;
+#else /* CONFIG_NO_RADIUS */
struct hostapd_acl_query_data *query;
/* Check whether ACL cache has an entry for this station */
@@ -289,12 +294,14 @@ int hostapd_allowed_address(struct hostapd_data *hapd, const u8 *addr,
/* Queued data will be processed in hostapd_acl_recv_radius()
* when RADIUS server replies to the sent Access-Request. */
return HOSTAPD_ACL_PENDING;
+#endif /* CONFIG_NO_RADIUS */
}
return HOSTAPD_ACL_REJECT;
}
+#ifndef CONFIG_NO_RADIUS
static void hostapd_acl_expire_cache(struct hostapd_data *hapd, time_t now)
{
struct hostapd_cached_radius_acl *prev, *entry, *tmp;
@@ -311,7 +318,7 @@ static void hostapd_acl_expire_cache(struct hostapd_data *hapd, time_t now)
else
hapd->acl_cache = entry->next;
#ifdef CONFIG_DRIVER_RADIUS_ACL
- hostapd_set_radius_acl_expire(hapd, entry->addr);
+ hapd->drv.set_radius_acl_expire(hapd, entry->addr);
#endif /* CONFIG_DRIVER_RADIUS_ACL */
tmp = entry;
entry = entry->next;
@@ -389,11 +396,12 @@ hostapd_acl_recv_radius(struct radius_msg *msg, struct radius_msg *req,
struct hostapd_data *hapd = data;
struct hostapd_acl_query_data *query, *prev;
struct hostapd_cached_radius_acl *cache;
+ struct radius_hdr *hdr = radius_msg_get_hdr(msg);
query = hapd->acl_queries;
prev = NULL;
while (query) {
- if (query->radius_id == msg->hdr->identifier)
+ if (query->radius_id == hdr->identifier)
break;
prev = query;
query = query->next;
@@ -410,10 +418,10 @@ hostapd_acl_recv_radius(struct radius_msg *msg, struct radius_msg *req,
return RADIUS_RX_INVALID_AUTHENTICATOR;
}
- if (msg->hdr->code != RADIUS_CODE_ACCESS_ACCEPT &&
- msg->hdr->code != RADIUS_CODE_ACCESS_REJECT) {
+ if (hdr->code != RADIUS_CODE_ACCESS_ACCEPT &&
+ hdr->code != RADIUS_CODE_ACCESS_REJECT) {
wpa_printf(MSG_DEBUG, "Unknown RADIUS message code %d to ACL "
- "query", msg->hdr->code);
+ "query", hdr->code);
return RADIUS_RX_UNKNOWN;
}
@@ -425,7 +433,7 @@ hostapd_acl_recv_radius(struct radius_msg *msg, struct radius_msg *req,
}
time(&cache->timestamp);
os_memcpy(cache->addr, query->addr, sizeof(cache->addr));
- if (msg->hdr->code == RADIUS_CODE_ACCESS_ACCEPT) {
+ if (hdr->code == RADIUS_CODE_ACCESS_ACCEPT) {
if (radius_msg_get_attr_int32(msg, RADIUS_ATTR_SESSION_TIMEOUT,
&cache->session_timeout) == 0)
cache->accepted = HOSTAPD_ACL_ACCEPT_TIMEOUT;
@@ -450,14 +458,15 @@ hostapd_acl_recv_radius(struct radius_msg *msg, struct radius_msg *req,
hapd->acl_cache = cache;
#ifdef CONFIG_DRIVER_RADIUS_ACL
- hostapd_set_radius_acl_auth(hapd, query->addr, cache->accepted,
- cache->session_timeout);
+ hapd->drv.set_radius_acl_auth(hapd, query->addr, cache->accepted,
+ cache->session_timeout);
#else /* CONFIG_DRIVER_RADIUS_ACL */
+#ifdef NEED_AP_MLME
/* Re-send original authentication frame for 802.11 processing */
wpa_printf(MSG_DEBUG, "Re-sending authentication frame after "
"successful RADIUS ACL query");
- ieee802_11_mgmt(hapd, query->auth_msg, query->auth_msg_len,
- WLAN_FC_STYPE_AUTH, NULL);
+ ieee802_11_mgmt(hapd, query->auth_msg, query->auth_msg_len, NULL);
+#endif /* NEED_AP_MLME */
#endif /* CONFIG_DRIVER_RADIUS_ACL */
done:
@@ -470,6 +479,7 @@ hostapd_acl_recv_radius(struct radius_msg *msg, struct radius_msg *req,
return RADIUS_RX_PROCESSED;
}
+#endif /* CONFIG_NO_RADIUS */
/**
@@ -479,11 +489,13 @@ hostapd_acl_recv_radius(struct radius_msg *msg, struct radius_msg *req,
*/
int hostapd_acl_init(struct hostapd_data *hapd)
{
+#ifndef CONFIG_NO_RADIUS
if (radius_client_register(hapd->radius, RADIUS_AUTH,
hostapd_acl_recv_radius, hapd))
return -1;
eloop_register_timeout(10, 0, hostapd_acl_expire, hapd, NULL);
+#endif /* CONFIG_NO_RADIUS */
return 0;
}
@@ -497,9 +509,11 @@ void hostapd_acl_deinit(struct hostapd_data *hapd)
{
struct hostapd_acl_query_data *query, *prev;
+#ifndef CONFIG_NO_RADIUS
eloop_cancel_timeout(hostapd_acl_expire, hapd, NULL);
hostapd_acl_cache_free(hapd->acl_cache);
+#endif /* CONFIG_NO_RADIUS */
query = hapd->acl_queries;
while (query) {
@@ -508,16 +522,3 @@ void hostapd_acl_deinit(struct hostapd_data *hapd)
hostapd_acl_query_free(prev);
}
}
-
-
-int hostapd_acl_reconfig(struct hostapd_data *hapd,
- struct hostapd_config *oldconf)
-{
- if (!hapd->radius_client_reconfigured)
- return 0;
-
- hostapd_acl_deinit(hapd);
- return hostapd_acl_init(hapd);
-}
-
-#endif /* CONFIG_NATIVE_WINDOWS */
diff --git a/contrib/wpa/hostapd/ieee802_11_auth.h b/contrib/wpa/src/ap/ieee802_11_auth.h
index 0eed825..b2971e5 100644
--- a/contrib/wpa/hostapd/ieee802_11_auth.h
+++ b/contrib/wpa/src/ap/ieee802_11_auth.h
@@ -27,7 +27,5 @@ int hostapd_allowed_address(struct hostapd_data *hapd, const u8 *addr,
u32 *acct_interim_interval, int *vlan_id);
int hostapd_acl_init(struct hostapd_data *hapd);
void hostapd_acl_deinit(struct hostapd_data *hapd);
-int hostapd_acl_reconfig(struct hostapd_data *hapd,
- struct hostapd_config *oldconf);
#endif /* IEEE802_11_AUTH_H */
diff --git a/contrib/wpa/src/ap/ieee802_11_ht.c b/contrib/wpa/src/ap/ieee802_11_ht.c
new file mode 100644
index 0000000..7541b83
--- /dev/null
+++ b/contrib/wpa/src/ap/ieee802_11_ht.c
@@ -0,0 +1,270 @@
+/*
+ * hostapd / IEEE 802.11n HT
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2007-2008, Intel Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "utils/includes.h"
+
+#include "utils/common.h"
+#include "common/ieee802_11_defs.h"
+#include "drivers/driver.h"
+#include "hostapd.h"
+#include "ap_config.h"
+#include "sta_info.h"
+#include "beacon.h"
+#include "ieee802_11.h"
+
+
+u8 * hostapd_eid_ht_capabilities(struct hostapd_data *hapd, u8 *eid)
+{
+ struct ieee80211_ht_capabilities *cap;
+ u8 *pos = eid;
+
+ if (!hapd->iconf->ieee80211n || !hapd->iface->current_mode)
+ return eid;
+
+ *pos++ = WLAN_EID_HT_CAP;
+ *pos++ = sizeof(*cap);
+
+ cap = (struct ieee80211_ht_capabilities *) pos;
+ os_memset(cap, 0, sizeof(*cap));
+ cap->ht_capabilities_info = host_to_le16(hapd->iconf->ht_capab);
+ cap->a_mpdu_params = hapd->iface->current_mode->a_mpdu_params;
+ os_memcpy(cap->supported_mcs_set, hapd->iface->current_mode->mcs_set,
+ 16);
+
+ /* TODO: ht_extended_capabilities (now fully disabled) */
+ /* TODO: tx_bf_capability_info (now fully disabled) */
+ /* TODO: asel_capabilities (now fully disabled) */
+
+ pos += sizeof(*cap);
+
+ return pos;
+}
+
+
+u8 * hostapd_eid_ht_operation(struct hostapd_data *hapd, u8 *eid)
+{
+ struct ieee80211_ht_operation *oper;
+ u8 *pos = eid;
+
+ if (!hapd->iconf->ieee80211n)
+ return eid;
+
+ *pos++ = WLAN_EID_HT_OPERATION;
+ *pos++ = sizeof(*oper);
+
+ oper = (struct ieee80211_ht_operation *) pos;
+ os_memset(oper, 0, sizeof(*oper));
+
+ oper->control_chan = hapd->iconf->channel;
+ oper->operation_mode = host_to_le16(hapd->iface->ht_op_mode);
+ if (hapd->iconf->secondary_channel == 1)
+ oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE |
+ HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH;
+ if (hapd->iconf->secondary_channel == -1)
+ oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW |
+ HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH;
+
+ pos += sizeof(*oper);
+
+ return pos;
+}
+
+
+/*
+op_mode
+Set to 0 (HT pure) under the followign conditions
+ - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or
+ - all STAs in the BSS are 20 MHz HT in 20 MHz BSS
+Set to 1 (HT non-member protection) if there may be non-HT STAs
+ in both the primary and the secondary channel
+Set to 2 if only HT STAs are associated in BSS,
+ however and at least one 20 MHz HT STA is associated
+Set to 3 (HT mixed mode) when one or more non-HT STAs are associated
+ (currently non-GF HT station is considered as non-HT STA also)
+*/
+int hostapd_ht_operation_update(struct hostapd_iface *iface)
+{
+ u16 cur_op_mode, new_op_mode;
+ int op_mode_changes = 0;
+
+ if (!iface->conf->ieee80211n || iface->conf->ht_op_mode_fixed)
+ return 0;
+
+ wpa_printf(MSG_DEBUG, "%s current operation mode=0x%X",
+ __func__, iface->ht_op_mode);
+
+ if (!(iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT)
+ && iface->num_sta_ht_no_gf) {
+ iface->ht_op_mode |=
+ HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
+ op_mode_changes++;
+ } else if ((iface->ht_op_mode &
+ HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT) &&
+ iface->num_sta_ht_no_gf == 0) {
+ iface->ht_op_mode &=
+ ~HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
+ op_mode_changes++;
+ }
+
+ if (!(iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
+ (iface->num_sta_no_ht || iface->olbc_ht)) {
+ iface->ht_op_mode |= HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
+ op_mode_changes++;
+ } else if ((iface->ht_op_mode &
+ HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
+ (iface->num_sta_no_ht == 0 && !iface->olbc_ht)) {
+ iface->ht_op_mode &=
+ ~HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
+ op_mode_changes++;
+ }
+
+ /* Note: currently we switch to the MIXED op mode if HT non-greenfield
+ * station is associated. Probably it's a theoretical case, since
+ * it looks like all known HT STAs support greenfield.
+ */
+ new_op_mode = 0;
+ if (iface->num_sta_no_ht ||
+ (iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT))
+ new_op_mode = OP_MODE_MIXED;
+ else if ((iface->conf->ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)
+ && iface->num_sta_ht_20mhz)
+ new_op_mode = OP_MODE_20MHZ_HT_STA_ASSOCED;
+ else if (iface->olbc_ht)
+ new_op_mode = OP_MODE_MAY_BE_LEGACY_STAS;
+ else
+ new_op_mode = OP_MODE_PURE;
+
+ cur_op_mode = iface->ht_op_mode & HT_INFO_OPERATION_MODE_OP_MODE_MASK;
+ if (cur_op_mode != new_op_mode) {
+ iface->ht_op_mode &= ~HT_INFO_OPERATION_MODE_OP_MODE_MASK;
+ iface->ht_op_mode |= new_op_mode;
+ op_mode_changes++;
+ }
+
+ wpa_printf(MSG_DEBUG, "%s new operation mode=0x%X changes=%d",
+ __func__, iface->ht_op_mode, op_mode_changes);
+
+ return op_mode_changes;
+}
+
+
+u16 copy_sta_ht_capab(struct sta_info *sta, const u8 *ht_capab,
+ size_t ht_capab_len)
+{
+ if (!ht_capab ||
+ ht_capab_len < sizeof(struct ieee80211_ht_capabilities)) {
+ sta->flags &= ~WLAN_STA_HT;
+ os_free(sta->ht_capabilities);
+ sta->ht_capabilities = NULL;
+ return WLAN_STATUS_SUCCESS;
+ }
+
+ if (sta->ht_capabilities == NULL) {
+ sta->ht_capabilities =
+ os_zalloc(sizeof(struct ieee80211_ht_capabilities));
+ if (sta->ht_capabilities == NULL)
+ return WLAN_STATUS_UNSPECIFIED_FAILURE;
+ }
+
+ sta->flags |= WLAN_STA_HT;
+ os_memcpy(sta->ht_capabilities, ht_capab,
+ sizeof(struct ieee80211_ht_capabilities));
+
+ return WLAN_STATUS_SUCCESS;
+}
+
+
+static void update_sta_ht(struct hostapd_data *hapd, struct sta_info *sta)
+{
+ u16 ht_capab;
+
+ ht_capab = le_to_host16(sta->ht_capabilities->ht_capabilities_info);
+ wpa_printf(MSG_DEBUG, "HT: STA " MACSTR " HT Capabilities Info: "
+ "0x%04x", MAC2STR(sta->addr), ht_capab);
+ if ((ht_capab & HT_CAP_INFO_GREEN_FIELD) == 0) {
+ if (!sta->no_ht_gf_set) {
+ sta->no_ht_gf_set = 1;
+ hapd->iface->num_sta_ht_no_gf++;
+ }
+ wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - no greenfield, num "
+ "of non-gf stations %d",
+ __func__, MAC2STR(sta->addr),
+ hapd->iface->num_sta_ht_no_gf);
+ }
+ if ((ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) == 0) {
+ if (!sta->ht_20mhz_set) {
+ sta->ht_20mhz_set = 1;
+ hapd->iface->num_sta_ht_20mhz++;
+ }
+ wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - 20 MHz HT, num of "
+ "20MHz HT STAs %d",
+ __func__, MAC2STR(sta->addr),
+ hapd->iface->num_sta_ht_20mhz);
+ }
+}
+
+
+static void update_sta_no_ht(struct hostapd_data *hapd, struct sta_info *sta)
+{
+ if (!sta->no_ht_set) {
+ sta->no_ht_set = 1;
+ hapd->iface->num_sta_no_ht++;
+ }
+ if (hapd->iconf->ieee80211n) {
+ wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - no HT, num of "
+ "non-HT stations %d",
+ __func__, MAC2STR(sta->addr),
+ hapd->iface->num_sta_no_ht);
+ }
+}
+
+
+void update_ht_state(struct hostapd_data *hapd, struct sta_info *sta)
+{
+ if ((sta->flags & WLAN_STA_HT) && sta->ht_capabilities)
+ update_sta_ht(hapd, sta);
+ else
+ update_sta_no_ht(hapd, sta);
+
+ if (hostapd_ht_operation_update(hapd->iface) > 0)
+ ieee802_11_set_beacons(hapd->iface);
+}
+
+
+void hostapd_get_ht_capab(struct hostapd_data *hapd,
+ struct ieee80211_ht_capabilities *ht_cap,
+ struct ieee80211_ht_capabilities *neg_ht_cap)
+{
+ u16 cap;
+
+ if (ht_cap == NULL)
+ return;
+ os_memcpy(neg_ht_cap, ht_cap, sizeof(*neg_ht_cap));
+ cap = le_to_host16(neg_ht_cap->ht_capabilities_info);
+ cap &= hapd->iconf->ht_capab;
+ cap |= (hapd->iconf->ht_capab & HT_CAP_INFO_SMPS_DISABLED);
+
+ /*
+ * STBC needs to be handled specially
+ * if we don't support RX STBC, mask out TX STBC in the STA's HT caps
+ * if we don't support TX STBC, mask out RX STBC in the STA's HT caps
+ */
+ if (!(hapd->iconf->ht_capab & HT_CAP_INFO_RX_STBC_MASK))
+ cap &= ~HT_CAP_INFO_TX_STBC;
+ if (!(hapd->iconf->ht_capab & HT_CAP_INFO_TX_STBC))
+ cap &= ~HT_CAP_INFO_RX_STBC_MASK;
+
+ neg_ht_cap->ht_capabilities_info = host_to_le16(cap);
+}
diff --git a/contrib/wpa/hostapd/ieee802_1x.c b/contrib/wpa/src/ap/ieee802_1x.c
index 7fd8028..eb160f8 100644
--- a/contrib/wpa/hostapd/ieee802_1x.c
+++ b/contrib/wpa/src/ap/ieee802_1x.c
@@ -1,6 +1,6 @@
/*
* hostapd / IEEE 802.1X-2004 Authenticator
- * Copyright (c) 2002-2008, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -12,25 +12,28 @@
* See README and COPYING for more details.
*/
-#include "includes.h"
+#include "utils/includes.h"
-#include "hostapd.h"
-#include "ieee802_1x.h"
-#include "accounting.h"
+#include "utils/common.h"
+#include "utils/eloop.h"
+#include "crypto/md5.h"
+#include "crypto/crypto.h"
+#include "common/ieee802_11_defs.h"
+#include "common/wpa_ctrl.h"
#include "radius/radius.h"
#include "radius/radius_client.h"
-#include "eapol_sm.h"
-#include "md5.h"
-#include "rc4.h"
-#include "eloop.h"
-#include "sta_info.h"
-#include "wpa.h"
-#include "preauth.h"
-#include "pmksa_cache.h"
-#include "driver.h"
-#include "hw_features.h"
#include "eap_server/eap.h"
-#include "ieee802_11_defs.h"
+#include "eap_common/eap_wsc_common.h"
+#include "eapol_auth/eapol_auth_sm.h"
+#include "eapol_auth/eapol_auth_sm_i.h"
+#include "hostapd.h"
+#include "accounting.h"
+#include "sta_info.h"
+#include "wpa_auth.h"
+#include "preauth_auth.h"
+#include "pmksa_cache_auth.h"
+#include "ap_config.h"
+#include "ieee802_1x.h"
static void ieee802_1x_finished(struct hostapd_data *hapd,
@@ -67,7 +70,7 @@ static void ieee802_1x_send(struct hostapd_data *hapd, struct sta_info *sta,
if (sta->flags & WLAN_STA_PREAUTH) {
rsn_preauth_send(hapd, sta, buf, len);
} else {
- hostapd_send_eapol(hapd, sta->addr, buf, len, encrypt);
+ hapd->drv.send_eapol(hapd, sta->addr, buf, len, encrypt);
}
os_free(buf);
@@ -83,15 +86,21 @@ void ieee802_1x_set_sta_authorized(struct hostapd_data *hapd,
return;
if (authorized) {
+ if (!(sta->flags & WLAN_STA_AUTHORIZED))
+ wpa_msg(hapd->msg_ctx, MSG_INFO,
+ AP_STA_CONNECTED MACSTR, MAC2STR(sta->addr));
sta->flags |= WLAN_STA_AUTHORIZED;
- res = hostapd_sta_set_flags(hapd, sta->addr, sta->flags,
- WLAN_STA_AUTHORIZED, ~0);
+ res = hapd->drv.set_authorized(hapd, sta, 1);
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
HOSTAPD_LEVEL_DEBUG, "authorizing port");
} else {
+ if ((sta->flags & (WLAN_STA_AUTHORIZED | WLAN_STA_ASSOC)) ==
+ (WLAN_STA_AUTHORIZED | WLAN_STA_ASSOC))
+ wpa_msg(hapd->msg_ctx, MSG_INFO,
+ AP_STA_DISCONNECTED MACSTR,
+ MAC2STR(sta->addr));
sta->flags &= ~WLAN_STA_AUTHORIZED;
- res = hostapd_sta_set_flags(hapd, sta->addr, sta->flags,
- 0, ~WLAN_STA_AUTHORIZED);
+ res = hapd->drv.set_authorized(hapd, sta, 0);
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
HOSTAPD_LEVEL_DEBUG, "unauthorizing port");
}
@@ -185,6 +194,7 @@ static void ieee802_1x_tx_key_one(struct hostapd_data *hapd,
}
+#ifndef CONFIG_NO_VLAN
static struct hostapd_wep_keys *
ieee802_1x_group_alloc(struct hostapd_data *hapd, const char *ifname)
{
@@ -219,11 +229,11 @@ ieee802_1x_group_alloc(struct hostapd_data *hapd, const char *ifname)
wpa_hexdump_key(MSG_DEBUG, "Default WEP key (dynamic VLAN)",
key->key[key->idx], key->len[key->idx]);
- if (hostapd_set_encryption(ifname, hapd, "WEP", NULL, key->idx,
- key->key[key->idx], key->len[key->idx], 1))
+ if (hapd->drv.set_key(ifname, hapd, WPA_ALG_WEP, NULL, key->idx, 1,
+ NULL, 0, key->key[key->idx], key->len[key->idx]))
printf("Could not set dynamic VLAN WEP encryption key.\n");
- hostapd_set_ieee8021x(ifname, hapd, 1);
+ hapd->drv.set_drv_ieee8021x(hapd, ifname, 1);
return key;
}
@@ -279,13 +289,17 @@ ieee802_1x_get_group(struct hostapd_data *hapd, struct hostapd_ssid *ssid,
return ssid->dyn_vlan_keys[vlan_id];
}
+#endif /* CONFIG_NO_VLAN */
void ieee802_1x_tx_key(struct hostapd_data *hapd, struct sta_info *sta)
{
- struct hostapd_wep_keys *key = NULL;
+ struct eapol_authenticator *eapol = hapd->eapol_auth;
struct eapol_state_machine *sm = sta->eapol_sm;
+#ifndef CONFIG_NO_VLAN
+ struct hostapd_wep_keys *key = NULL;
int vlan_id;
+#endif /* CONFIG_NO_VLAN */
if (sm == NULL || !sm->eap_if->eapKeyData)
return;
@@ -293,6 +307,7 @@ void ieee802_1x_tx_key(struct hostapd_data *hapd, struct sta_info *sta)
wpa_printf(MSG_DEBUG, "IEEE 802.1X: Sending EAPOL-Key(s) to " MACSTR,
MAC2STR(sta->addr));
+#ifndef CONFIG_NO_VLAN
vlan_id = sta->vlan_id;
if (vlan_id < 0 || vlan_id > MAX_VLAN_ID)
vlan_id = 0;
@@ -303,9 +318,11 @@ void ieee802_1x_tx_key(struct hostapd_data *hapd, struct sta_info *sta)
ieee802_1x_tx_key_one(hapd, sta, key->idx, 1,
key->key[key->idx],
key->len[key->idx]);
- } else if (hapd->default_wep_key) {
- ieee802_1x_tx_key_one(hapd, sta, hapd->default_wep_key_idx, 1,
- hapd->default_wep_key,
+ } else
+#endif /* CONFIG_NO_VLAN */
+ if (eapol->default_wep_key) {
+ ieee802_1x_tx_key_one(hapd, sta, eapol->default_wep_key_idx, 1,
+ eapol->default_wep_key,
hapd->conf->default_wep_key_len);
}
@@ -328,10 +345,9 @@ void ieee802_1x_tx_key(struct hostapd_data *hapd, struct sta_info *sta)
/* TODO: set encryption in TX callback, i.e., only after STA
* has ACKed EAPOL-Key frame */
- if (hostapd_set_encryption(hapd->conf->iface, hapd, "WEP",
- sta->addr, 0, ikey,
- hapd->conf->individual_wep_key_len,
- 1)) {
+ if (hapd->drv.set_key(hapd->conf->iface, hapd, WPA_ALG_WEP,
+ sta->addr, 0, 1, NULL, 0, ikey,
+ hapd->conf->individual_wep_key_len)) {
wpa_printf(MSG_ERROR, "Could not set individual WEP "
"encryption.");
}
@@ -343,10 +359,7 @@ void ieee802_1x_tx_key(struct hostapd_data *hapd, struct sta_info *sta)
const char *radius_mode_txt(struct hostapd_data *hapd)
{
- if (hapd->iface->current_mode == NULL)
- return "802.11";
-
- switch (hapd->iface->current_mode->mode) {
+ switch (hapd->iface->conf->hw_mode) {
case HOSTAPD_MODE_IEEE80211A:
return "802.11a";
case HOSTAPD_MODE_IEEE80211G:
@@ -371,6 +384,7 @@ int radius_sta_rate(struct hostapd_data *hapd, struct sta_info *sta)
}
+#ifndef CONFIG_NO_RADIUS
static void ieee802_1x_learn_identity(struct hostapd_data *hapd,
struct eapol_state_machine *sm,
const u8 *eap, size_t len)
@@ -520,7 +534,8 @@ static void ieee802_1x_encapsulate_radius(struct hostapd_data *hapd,
/* State attribute must be copied if and only if this packet is
* Access-Request reply to the previous Access-Challenge */
- if (sm->last_recv_radius && sm->last_recv_radius->hdr->code ==
+ if (sm->last_recv_radius &&
+ radius_msg_get_hdr(sm->last_recv_radius)->code ==
RADIUS_CODE_ACCESS_CHALLENGE) {
int res = radius_msg_copy_attr(msg, sm->last_recv_radius,
RADIUS_ATTR_STATE);
@@ -539,30 +554,8 @@ static void ieee802_1x_encapsulate_radius(struct hostapd_data *hapd,
fail:
radius_msg_free(msg);
- os_free(msg);
-}
-
-
-char *eap_type_text(u8 type)
-{
- switch (type) {
- case EAP_TYPE_IDENTITY: return "Identity";
- case EAP_TYPE_NOTIFICATION: return "Notification";
- case EAP_TYPE_NAK: return "Nak";
- case EAP_TYPE_MD5: return "MD5-Challenge";
- case EAP_TYPE_OTP: return "One-Time Password";
- case EAP_TYPE_GTC: return "Generic Token Card";
- case EAP_TYPE_TLS: return "TLS";
- case EAP_TYPE_TTLS: return "TTLS";
- case EAP_TYPE_PEAP: return "PEAP";
- case EAP_TYPE_SIM: return "SIM";
- case EAP_TYPE_FAST: return "FAST";
- case EAP_TYPE_SAKE: return "SAKE";
- case EAP_TYPE_PSK: return "PSK";
- case EAP_TYPE_PAX: return "PAX";
- default: return "Unknown";
- }
}
+#endif /* CONFIG_NO_RADIUS */
static void handle_eap_response(struct hostapd_data *hapd,
@@ -587,7 +580,7 @@ static void handle_eap_response(struct hostapd_data *hapd,
HOSTAPD_LEVEL_DEBUG, "received EAP packet (code=%d "
"id=%d len=%d) from STA: EAP Response-%s (%d)",
eap->code, eap->identifier, be_to_host16(eap->length),
- eap_type_text(type), type);
+ eap_server_get_name(0, type), type);
sm->dot1xAuthEapolRespFramesRx++;
@@ -647,6 +640,22 @@ static void handle_eap(struct hostapd_data *hapd, struct sta_info *sta,
}
+static struct eapol_state_machine *
+ieee802_1x_alloc_eapol_sm(struct hostapd_data *hapd, struct sta_info *sta)
+{
+ int flags = 0;
+ if (sta->flags & WLAN_STA_PREAUTH)
+ flags |= EAPOL_SM_PREAUTH;
+ if (sta->wpa_sm) {
+ flags |= EAPOL_SM_USES_WPA;
+ if (wpa_auth_sta_get_pmksa(sta->wpa_sm))
+ flags |= EAPOL_SM_FROM_PMKSA_CACHE;
+ }
+ return eapol_auth_alloc(hapd->eapol_auth, sta->addr, flags,
+ sta->wps_ie, sta);
+}
+
+
/**
* ieee802_1x_receive - Process the EAPOL frames from the Supplicant
* @hapd: hostapd BSS data
@@ -672,8 +681,9 @@ void ieee802_1x_receive(struct hostapd_data *hapd, const u8 *sa, const u8 *buf,
wpa_printf(MSG_DEBUG, "IEEE 802.1X: %lu bytes from " MACSTR,
(unsigned long) len, MAC2STR(sa));
sta = ap_get_sta(hapd, sa);
- if (!sta) {
- printf(" no station information available\n");
+ if (!sta || !(sta->flags & WLAN_STA_ASSOC)) {
+ wpa_printf(MSG_DEBUG, "IEEE 802.1X data frame from not "
+ "associated STA");
return;
}
@@ -720,9 +730,7 @@ void ieee802_1x_receive(struct hostapd_data *hapd, const u8 *sa, const u8 *buf,
return;
if (!sta->eapol_sm) {
- sta->eapol_sm = eapol_auth_alloc(hapd->eapol_auth, sta->addr,
- sta->flags & WLAN_STA_PREAUTH,
- sta);
+ sta->eapol_sm = ieee802_1x_alloc_eapol_sm(hapd, sta);
if (!sta->eapol_sm)
return;
@@ -839,9 +847,7 @@ void ieee802_1x_new_station(struct hostapd_data *hapd, struct sta_info *sta)
if (sta->eapol_sm == NULL) {
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
HOSTAPD_LEVEL_DEBUG, "start authentication");
- sta->eapol_sm = eapol_auth_alloc(hapd->eapol_auth, sta->addr,
- sta->flags & WLAN_STA_PREAUTH,
- sta);
+ sta->eapol_sm = ieee802_1x_alloc_eapol_sm(hapd, sta);
if (sta->eapol_sm == NULL) {
hostapd_logger(hapd, sta->addr,
HOSTAPD_MODULE_IEEE8021X,
@@ -900,47 +906,6 @@ void ieee802_1x_new_station(struct hostapd_data *hapd, struct sta_info *sta)
}
-void ieee802_1x_free_radius_class(struct radius_class_data *class)
-{
- size_t i;
- if (class == NULL)
- return;
- for (i = 0; i < class->count; i++)
- os_free(class->attr[i].data);
- os_free(class->attr);
- class->attr = NULL;
- class->count = 0;
-}
-
-
-int ieee802_1x_copy_radius_class(struct radius_class_data *dst,
- const struct radius_class_data *src)
-{
- size_t i;
-
- if (src->attr == NULL)
- return 0;
-
- dst->attr = os_zalloc(src->count * sizeof(struct radius_attr_data));
- if (dst->attr == NULL)
- return -1;
-
- dst->count = 0;
-
- for (i = 0; i < src->count; i++) {
- dst->attr[i].data = os_malloc(src->attr[i].len);
- if (dst->attr[i].data == NULL)
- break;
- dst->count++;
- os_memcpy(dst->attr[i].data, src->attr[i].data,
- src->attr[i].len);
- dst->attr[i].len = src->attr[i].len;
- }
-
- return 0;
-}
-
-
void ieee802_1x_free_station(struct sta_info *sta)
{
struct eapol_state_machine *sm = sta->eapol_sm;
@@ -950,17 +915,17 @@ void ieee802_1x_free_station(struct sta_info *sta)
sta->eapol_sm = NULL;
- if (sm->last_recv_radius) {
- radius_msg_free(sm->last_recv_radius);
- os_free(sm->last_recv_radius);
- }
+#ifndef CONFIG_NO_RADIUS
+ radius_msg_free(sm->last_recv_radius);
+ radius_free_class(&sm->radius_class);
+#endif /* CONFIG_NO_RADIUS */
os_free(sm->identity);
- ieee802_1x_free_radius_class(&sm->radius_class);
eapol_auth_free(sm);
}
+#ifndef CONFIG_NO_RADIUS
static void ieee802_1x_decapsulate_radius(struct hostapd_data *hapd,
struct sta_info *sta)
{
@@ -1010,12 +975,14 @@ static void ieee802_1x_decapsulate_radius(struct hostapd_data *hapd,
if (eap_type >= 0)
sm->eap_type_authsrv = eap_type;
os_snprintf(buf, sizeof(buf), "EAP-Request-%s (%d)",
- eap_type >= 0 ? eap_type_text(eap_type) : "??",
+ eap_type >= 0 ? eap_server_get_name(0, eap_type) :
+ "??",
eap_type);
break;
case EAP_CODE_RESPONSE:
os_snprintf(buf, sizeof(buf), "EAP Response-%s (%d)",
- eap_type >= 0 ? eap_type_text(eap_type) : "??",
+ eap_type >= 0 ? eap_server_get_name(0, eap_type) :
+ "??",
eap_type);
break;
case EAP_CODE_SUCCESS:
@@ -1097,7 +1064,7 @@ static void ieee802_1x_store_radius_class(struct hostapd_data *hapd,
sm == NULL)
return;
- ieee802_1x_free_radius_class(&sm->radius_class);
+ radius_free_class(&sm->radius_class);
count = radius_msg_count_attr(msg, RADIUS_ATTR_CLASS, 1);
if (count <= 0)
return;
@@ -1225,8 +1192,9 @@ ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
int session_timeout_set, old_vlanid = 0;
struct eapol_state_machine *sm;
int override_eapReq = 0;
+ struct radius_hdr *hdr = radius_msg_get_hdr(msg);
- sm = ieee802_1x_search_radius_identifier(hapd, msg->hdr->identifier);
+ sm = ieee802_1x_search_radius_identifier(hapd, hdr->identifier);
if (sm == NULL) {
wpa_printf(MSG_DEBUG, "IEEE 802.1X: Could not find matching "
"station for this RADIUS message");
@@ -1236,7 +1204,7 @@ ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
/* RFC 2869, Ch. 5.13: valid Message-Authenticator attribute MUST be
* present when packet contains an EAP-Message attribute */
- if (msg->hdr->code == RADIUS_CODE_ACCESS_REJECT &&
+ if (hdr->code == RADIUS_CODE_ACCESS_REJECT &&
radius_msg_get_attr(msg, RADIUS_ATTR_MESSAGE_AUTHENTICATOR, NULL,
0) < 0 &&
radius_msg_get_attr(msg, RADIUS_ATTR_EAP_MESSAGE, NULL, 0) < 0) {
@@ -1250,9 +1218,9 @@ ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
return RADIUS_RX_INVALID_AUTHENTICATOR;
}
- if (msg->hdr->code != RADIUS_CODE_ACCESS_ACCEPT &&
- msg->hdr->code != RADIUS_CODE_ACCESS_REJECT &&
- msg->hdr->code != RADIUS_CODE_ACCESS_CHALLENGE) {
+ if (hdr->code != RADIUS_CODE_ACCESS_ACCEPT &&
+ hdr->code != RADIUS_CODE_ACCESS_REJECT &&
+ hdr->code != RADIUS_CODE_ACCESS_CHALLENGE) {
printf("Unknown RADIUS message code\n");
return RADIUS_RX_UNKNOWN;
}
@@ -1261,11 +1229,7 @@ ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
wpa_printf(MSG_DEBUG, "RADIUS packet matching with station " MACSTR,
MAC2STR(sta->addr));
- if (sm->last_recv_radius) {
- radius_msg_free(sm->last_recv_radius);
- os_free(sm->last_recv_radius);
- }
-
+ radius_msg_free(sm->last_recv_radius);
sm->last_recv_radius = msg;
session_timeout_set =
@@ -1275,8 +1239,8 @@ ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
&termination_action))
termination_action = RADIUS_TERMINATION_ACTION_DEFAULT;
- if (hapd->conf->radius->acct_interim_interval == 0 &&
- msg->hdr->code == RADIUS_CODE_ACCESS_ACCEPT &&
+ if (hapd->conf->acct_interim_interval == 0 &&
+ hdr->code == RADIUS_CODE_ACCESS_ACCEPT &&
radius_msg_get_attr_int32(msg, RADIUS_ATTR_ACCT_INTERIM_INTERVAL,
&acct_interim_interval) == 0) {
if (acct_interim_interval < 60) {
@@ -1291,10 +1255,11 @@ ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
}
- switch (msg->hdr->code) {
+ switch (hdr->code) {
case RADIUS_CODE_ACCESS_ACCEPT:
if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)
sta->vlan_id = 0;
+#ifndef CONFIG_NO_VLAN
else {
old_vlanid = sta->vlan_id;
sta->vlan_id = radius_msg_get_vlanid(msg);
@@ -1315,8 +1280,10 @@ ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
"ID in Access-Accept");
break;
}
+#endif /* CONFIG_NO_VLAN */
- ap_sta_bind_vlan(hapd, sta, old_vlanid);
+ if (ap_sta_bind_vlan(hapd, sta, old_vlanid) < 0)
+ break;
/* RFC 3580, Ch. 3.17 */
if (session_timeout_set && termination_action ==
@@ -1373,6 +1340,7 @@ ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
return RADIUS_RX_QUEUED;
}
+#endif /* CONFIG_NO_RADIUS */
void ieee802_1x_abort_auth(struct hostapd_data *hapd, struct sta_info *sta)
@@ -1384,11 +1352,10 @@ void ieee802_1x_abort_auth(struct hostapd_data *hapd, struct sta_info *sta)
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
HOSTAPD_LEVEL_DEBUG, "aborting authentication");
- if (sm->last_recv_radius) {
- radius_msg_free(sm->last_recv_radius);
- os_free(sm->last_recv_radius);
- sm->last_recv_radius = NULL;
- }
+#ifndef CONFIG_NO_RADIUS
+ radius_msg_free(sm->last_recv_radius);
+ sm->last_recv_radius = NULL;
+#endif /* CONFIG_NO_RADIUS */
if (sm->eap_if->eapTimeout) {
/*
@@ -1397,74 +1364,32 @@ void ieee802_1x_abort_auth(struct hostapd_data *hapd, struct sta_info *sta)
* could only be sent if the EAP peer actually replied).
*/
sm->eap_if->portEnabled = FALSE;
- hostapd_sta_deauth(hapd, sta->addr,
- WLAN_REASON_PREV_AUTH_NOT_VALID);
- sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
- WLAN_STA_AUTHORIZED);
- eloop_cancel_timeout(ap_handle_timer, hapd, sta);
- eloop_register_timeout(0, 0, ap_handle_timer, hapd, sta);
- sta->timeout_next = STA_REMOVE;
+ ap_sta_disconnect(hapd, sta, sta->addr,
+ WLAN_REASON_PREV_AUTH_NOT_VALID);
}
}
-#ifdef HOSTAPD_DUMP_STATE
-static void fprint_char(FILE *f, char c)
-{
- if (c >= 32 && c < 127)
- fprintf(f, "%c", c);
- else
- fprintf(f, "<%02x>", c);
-}
-
-
-void ieee802_1x_dump_state(FILE *f, const char *prefix, struct sta_info *sta)
-{
- struct eapol_state_machine *sm = sta->eapol_sm;
- if (sm == NULL)
- return;
-
- fprintf(f, "%sIEEE 802.1X:\n", prefix);
-
- if (sm->identity) {
- size_t i;
- fprintf(f, "%sidentity=", prefix);
- for (i = 0; i < sm->identity_len; i++)
- fprint_char(f, sm->identity[i]);
- fprintf(f, "\n");
- }
-
- fprintf(f, "%slast EAP type: Authentication Server: %d (%s) "
- "Supplicant: %d (%s)\n", prefix,
- sm->eap_type_authsrv, eap_type_text(sm->eap_type_authsrv),
- sm->eap_type_supp, eap_type_text(sm->eap_type_supp));
-
- fprintf(f, "%scached_packets=%s\n", prefix,
- sm->last_recv_radius ? "[RX RADIUS]" : "");
-
- eapol_auth_dump_state(f, prefix, sm);
-}
-#endif /* HOSTAPD_DUMP_STATE */
-
-
static int ieee802_1x_rekey_broadcast(struct hostapd_data *hapd)
{
+ struct eapol_authenticator *eapol = hapd->eapol_auth;
+
if (hapd->conf->default_wep_key_len < 1)
return 0;
- os_free(hapd->default_wep_key);
- hapd->default_wep_key = os_malloc(hapd->conf->default_wep_key_len);
- if (hapd->default_wep_key == NULL ||
- os_get_random(hapd->default_wep_key,
+ os_free(eapol->default_wep_key);
+ eapol->default_wep_key = os_malloc(hapd->conf->default_wep_key_len);
+ if (eapol->default_wep_key == NULL ||
+ os_get_random(eapol->default_wep_key,
hapd->conf->default_wep_key_len)) {
printf("Could not generate random WEP key.\n");
- os_free(hapd->default_wep_key);
- hapd->default_wep_key = NULL;
+ os_free(eapol->default_wep_key);
+ eapol->default_wep_key = NULL;
return -1;
}
wpa_hexdump_key(MSG_DEBUG, "IEEE 802.1X: New default WEP key",
- hapd->default_wep_key,
+ eapol->default_wep_key,
hapd->conf->default_wep_key_len);
return 0;
@@ -1485,36 +1410,37 @@ static int ieee802_1x_sta_key_available(struct hostapd_data *hapd,
static void ieee802_1x_rekey(void *eloop_ctx, void *timeout_ctx)
{
struct hostapd_data *hapd = eloop_ctx;
+ struct eapol_authenticator *eapol = hapd->eapol_auth;
- if (hapd->default_wep_key_idx >= 3)
- hapd->default_wep_key_idx =
+ if (eapol->default_wep_key_idx >= 3)
+ eapol->default_wep_key_idx =
hapd->conf->individual_wep_key_len > 0 ? 1 : 0;
else
- hapd->default_wep_key_idx++;
+ eapol->default_wep_key_idx++;
wpa_printf(MSG_DEBUG, "IEEE 802.1X: New default WEP key index %d",
- hapd->default_wep_key_idx);
+ eapol->default_wep_key_idx);
if (ieee802_1x_rekey_broadcast(hapd)) {
hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE8021X,
HOSTAPD_LEVEL_WARNING, "failed to generate a "
"new broadcast key");
- os_free(hapd->default_wep_key);
- hapd->default_wep_key = NULL;
+ os_free(eapol->default_wep_key);
+ eapol->default_wep_key = NULL;
return;
}
/* TODO: Could setup key for RX here, but change default TX keyid only
* after new broadcast key has been sent to all stations. */
- if (hostapd_set_encryption(hapd->conf->iface, hapd, "WEP", NULL,
- hapd->default_wep_key_idx,
- hapd->default_wep_key,
- hapd->conf->default_wep_key_len, 1)) {
+ if (hapd->drv.set_key(hapd->conf->iface, hapd, WPA_ALG_WEP, NULL,
+ eapol->default_wep_key_idx, 1, NULL, 0,
+ eapol->default_wep_key,
+ hapd->conf->default_wep_key_len)) {
hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE8021X,
HOSTAPD_LEVEL_WARNING, "failed to configure a "
"new broadcast key");
- os_free(hapd->default_wep_key);
- hapd->default_wep_key = NULL;
+ os_free(eapol->default_wep_key);
+ eapol->default_wep_key = NULL;
return;
}
@@ -1530,6 +1456,30 @@ static void ieee802_1x_rekey(void *eloop_ctx, void *timeout_ctx)
static void ieee802_1x_eapol_send(void *ctx, void *sta_ctx, u8 type,
const u8 *data, size_t datalen)
{
+#ifdef CONFIG_WPS
+ struct sta_info *sta = sta_ctx;
+
+ if ((sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)) ==
+ WLAN_STA_MAYBE_WPS) {
+ const u8 *identity;
+ size_t identity_len;
+ struct eapol_state_machine *sm = sta->eapol_sm;
+
+ identity = eap_get_identity(sm->eap, &identity_len);
+ if (identity &&
+ ((identity_len == WSC_ID_ENROLLEE_LEN &&
+ os_memcmp(identity, WSC_ID_ENROLLEE,
+ WSC_ID_ENROLLEE_LEN) == 0) ||
+ (identity_len == WSC_ID_REGISTRAR_LEN &&
+ os_memcmp(identity, WSC_ID_REGISTRAR,
+ WSC_ID_REGISTRAR_LEN) == 0))) {
+ wpa_printf(MSG_DEBUG, "WPS: WLAN_STA_MAYBE_WPS -> "
+ "WLAN_STA_WPS");
+ sta->flags |= WLAN_STA_WPS;
+ }
+ }
+#endif /* CONFIG_WPS */
+
ieee802_1x_send(ctx, sta_ctx, type, data, datalen);
}
@@ -1537,10 +1487,12 @@ static void ieee802_1x_eapol_send(void *ctx, void *sta_ctx, u8 type,
static void ieee802_1x_aaa_send(void *ctx, void *sta_ctx,
const u8 *data, size_t datalen)
{
+#ifndef CONFIG_NO_RADIUS
struct hostapd_data *hapd = ctx;
struct sta_info *sta = sta_ctx;
ieee802_1x_encapsulate_radius(hapd, sta, data, datalen);
+#endif /* CONFIG_NO_RADIUS */
}
@@ -1608,6 +1560,7 @@ static int ieee802_1x_sta_entry_alive(void *ctx, const u8 *addr)
static void ieee802_1x_logger(void *ctx, const u8 *addr,
eapol_logger_level level, const char *txt)
{
+#ifndef CONFIG_NO_HOSTAPD_LOGGER
struct hostapd_data *hapd = ctx;
int hlevel;
@@ -1626,6 +1579,7 @@ static void ieee802_1x_logger(void *ctx, const u8 *addr,
hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE8021X, hlevel, "%s",
txt);
+#endif /* CONFIG_NO_HOSTAPD_LOGGER */
}
@@ -1654,6 +1608,22 @@ static void _ieee802_1x_tx_key(void *ctx, void *sta_ctx)
}
+static void ieee802_1x_eapol_event(void *ctx, void *sta_ctx,
+ enum eapol_event type)
+{
+ /* struct hostapd_data *hapd = ctx; */
+ struct sta_info *sta = sta_ctx;
+ switch (type) {
+ case EAPOL_AUTH_SM_CHANGE:
+ wpa_auth_sm_notify(sta->wpa_sm);
+ break;
+ case EAPOL_AUTH_REAUTHENTICATE:
+ wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH_EAPOL);
+ break;
+ }
+}
+
+
int ieee802_1x_init(struct hostapd_data *hapd)
{
int i;
@@ -1661,12 +1631,13 @@ int ieee802_1x_init(struct hostapd_data *hapd)
struct eapol_auth_cb cb;
os_memset(&conf, 0, sizeof(conf));
- conf.hapd = hapd;
+ conf.ctx = hapd;
conf.eap_reauth_period = hapd->conf->eap_reauth_period;
conf.wpa = hapd->conf->wpa;
conf.individual_wep_key_len = hapd->conf->individual_wep_key_len;
conf.eap_server = hapd->conf->eap_server;
conf.ssl_ctx = hapd->ssl_ctx;
+ conf.msg_ctx = hapd->msg_ctx;
conf.eap_sim_db_priv = hapd->eap_sim_db_priv;
conf.eap_req_id_text = hapd->conf->eap_req_id_text;
conf.eap_req_id_text_len = hapd->conf->eap_req_id_text_len;
@@ -1691,29 +1662,31 @@ int ieee802_1x_init(struct hostapd_data *hapd)
cb.set_port_authorized = ieee802_1x_set_port_authorized;
cb.abort_auth = _ieee802_1x_abort_auth;
cb.tx_key = _ieee802_1x_tx_key;
+ cb.eapol_event = ieee802_1x_eapol_event;
hapd->eapol_auth = eapol_auth_init(&conf, &cb);
if (hapd->eapol_auth == NULL)
return -1;
if ((hapd->conf->ieee802_1x || hapd->conf->wpa) &&
- hostapd_set_ieee8021x(hapd->conf->iface, hapd, 1))
+ hapd->drv.set_drv_ieee8021x(hapd, hapd->conf->iface, 1))
return -1;
+#ifndef CONFIG_NO_RADIUS
if (radius_client_register(hapd->radius, RADIUS_AUTH,
ieee802_1x_receive_auth, hapd))
return -1;
+#endif /* CONFIG_NO_RADIUS */
if (hapd->conf->default_wep_key_len) {
- hostapd_set_privacy(hapd, 1);
-
for (i = 0; i < 4; i++)
- hostapd_set_encryption(hapd->conf->iface, hapd,
- "none", NULL, i, NULL, 0, 0);
+ hapd->drv.set_key(hapd->conf->iface, hapd,
+ WPA_ALG_NONE, NULL, i, 0, NULL, 0,
+ NULL, 0);
ieee802_1x_rekey(hapd, NULL);
- if (hapd->default_wep_key == NULL)
+ if (hapd->eapol_auth->default_wep_key == NULL)
return -1;
}
@@ -1727,24 +1700,15 @@ void ieee802_1x_deinit(struct hostapd_data *hapd)
if (hapd->driver != NULL &&
(hapd->conf->ieee802_1x || hapd->conf->wpa))
- hostapd_set_ieee8021x(hapd->conf->iface, hapd, 0);
+ hapd->drv.set_drv_ieee8021x(hapd, hapd->conf->iface, 0);
eapol_auth_deinit(hapd->eapol_auth);
hapd->eapol_auth = NULL;
}
-int ieee802_1x_reconfig(struct hostapd_data *hapd,
- struct hostapd_config *oldconf,
- struct hostapd_bss_config *oldbss)
-{
- ieee802_1x_deinit(hapd);
- return ieee802_1x_init(hapd);
-}
-
-
int ieee802_1x_tx_status(struct hostapd_data *hapd, struct sta_info *sta,
- u8 *buf, size_t len, int ack)
+ const u8 *buf, size_t len, int ack)
{
struct ieee80211_hdr *hdr;
struct ieee802_1x_hdr *xhdr;
@@ -2039,4 +2003,23 @@ static void ieee802_1x_finished(struct hostapd_data *hapd,
HOSTAPD_LEVEL_DEBUG,
"Added PMKSA cache entry (IEEE 802.1X)");
}
+
+#ifdef CONFIG_WPS
+ if (!success && (sta->flags & WLAN_STA_WPS)) {
+ /*
+ * Many devices require deauthentication after WPS provisioning
+ * and some may not be be able to do that themselves, so
+ * disconnect the client here.
+ */
+ wpa_printf(MSG_DEBUG, "WPS: Force disconnection after "
+ "EAP-Failure");
+ /* Add a small sleep to increase likelihood of previously
+ * requested EAP-Failure TX getting out before this should the
+ * driver reorder operations.
+ */
+ os_sleep(0, 10000);
+ ap_sta_disconnect(hapd, sta, sta->addr,
+ WLAN_REASON_PREV_AUTH_NOT_VALID);
+ }
+#endif /* CONFIG_WPS */
}
diff --git a/contrib/wpa/hostapd/ieee802_1x.h b/contrib/wpa/src/ap/ieee802_1x.h
index 94cff93..1a4d2eb 100644
--- a/contrib/wpa/hostapd/ieee802_1x.h
+++ b/contrib/wpa/src/ap/ieee802_1x.h
@@ -21,6 +21,10 @@ struct eapol_state_machine;
struct hostapd_config;
struct hostapd_bss_config;
+#ifdef _MSC_VER
+#pragma pack(push, 1)
+#endif /* _MSC_VER */
+
/* RFC 3580, 4. RC4 EAPOL-Key Frame */
struct ieee802_1x_eapol_key {
@@ -43,7 +47,11 @@ struct ieee802_1x_eapol_key {
* represents the number of least significant octets from
* MS-MPPE-Send-Key attribute to be used as the keying material;
* RC4 key used in encryption = Key-IV + MS-MPPE-Recv-Key */
-} __attribute__ ((packed));
+} STRUCT_PACKED;
+
+#ifdef _MSC_VER
+#pragma pack(pop)
+#endif /* _MSC_VER */
void ieee802_1x_receive(struct hostapd_data *hapd, const u8 *sa, const u8 *buf,
@@ -58,11 +66,8 @@ void ieee802_1x_set_sta_authorized(struct hostapd_data *hapd,
void ieee802_1x_dump_state(FILE *f, const char *prefix, struct sta_info *sta);
int ieee802_1x_init(struct hostapd_data *hapd);
void ieee802_1x_deinit(struct hostapd_data *hapd);
-int ieee802_1x_reconfig(struct hostapd_data *hapd,
- struct hostapd_config *oldconf,
- struct hostapd_bss_config *oldbss);
int ieee802_1x_tx_status(struct hostapd_data *hapd, struct sta_info *sta,
- u8 *buf, size_t len, int ack);
+ const u8 *buf, size_t len, int ack);
u8 * ieee802_1x_get_identity(struct eapol_state_machine *sm, size_t *len);
u8 * ieee802_1x_get_radius_class(struct eapol_state_machine *sm, size_t *len,
int idx);
@@ -78,12 +83,6 @@ int ieee802_1x_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
void hostapd_get_ntp_timestamp(u8 *buf);
char *eap_type_text(u8 type);
-struct radius_class_data;
-
-void ieee802_1x_free_radius_class(struct radius_class_data *class);
-int ieee802_1x_copy_radius_class(struct radius_class_data *dst,
- const struct radius_class_data *src);
-
const char *radius_mode_txt(struct hostapd_data *hapd);
int radius_sta_rate(struct hostapd_data *hapd, struct sta_info *sta);
diff --git a/contrib/wpa/hostapd/peerkey.c b/contrib/wpa/src/ap/peerkey_auth.c
index 83f3ce5..f68c479 100644
--- a/contrib/wpa/hostapd/peerkey.c
+++ b/contrib/wpa/src/ap/peerkey_auth.c
@@ -1,6 +1,6 @@
/*
* hostapd - PeerKey for Direct Link Setup (DLS)
- * Copyright (c) 2006-2008, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2006-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -12,14 +12,13 @@
* See README and COPYING for more details.
*/
-#include "includes.h"
+#include "utils/includes.h"
-#include "common.h"
-#include "eloop.h"
-#include "sha1.h"
-#include "sha256.h"
-#include "wpa.h"
-#include "defs.h"
+#include "utils/common.h"
+#include "utils/eloop.h"
+#include "crypto/sha1.h"
+#include "crypto/sha256.h"
+#include "wpa_auth.h"
#include "wpa_auth_i.h"
#include "wpa_auth_ie.h"
diff --git a/contrib/wpa/hostapd/pmksa_cache.c b/contrib/wpa/src/ap/pmksa_cache_auth.c
index 5f54a34..22f44b7 100644
--- a/contrib/wpa/hostapd/pmksa_cache.c
+++ b/contrib/wpa/src/ap/pmksa_cache_auth.c
@@ -12,18 +12,15 @@
* See README and COPYING for more details.
*/
-#include "includes.h"
+#include "utils/includes.h"
-#include "common.h"
-#include "ap.h"
-#include "config.h"
-#include "common.h"
-#include "eloop.h"
-#include "sha1.h"
-#include "sha256.h"
-#include "ieee802_1x.h"
-#include "eapol_sm.h"
-#include "pmksa_cache.h"
+#include "utils/common.h"
+#include "utils/eloop.h"
+#include "eapol_auth/eapol_auth_sm.h"
+#include "eapol_auth/eapol_auth_sm_i.h"
+#include "sta_info.h"
+#include "ap_config.h"
+#include "pmksa_cache_auth.h"
static const int pmksa_cache_max_entries = 1024;
@@ -41,40 +38,6 @@ struct rsn_pmksa_cache {
};
-/**
- * rsn_pmkid - Calculate PMK identifier
- * @pmk: Pairwise master key
- * @pmk_len: Length of pmk in bytes
- * @aa: Authenticator address
- * @spa: Supplicant address
- * @pmkid: Buffer for PMKID
- * @use_sha256: Whether to use SHA256-based KDF
- *
- * IEEE Std 802.11i-2004 - 8.5.1.2 Pairwise key hierarchy
- * PMKID = HMAC-SHA1-128(PMK, "PMK Name" || AA || SPA)
- */
-void rsn_pmkid(const u8 *pmk, size_t pmk_len, const u8 *aa, const u8 *spa,
- u8 *pmkid, int use_sha256)
-{
- char *title = "PMK Name";
- const u8 *addr[3];
- const size_t len[3] = { 8, ETH_ALEN, ETH_ALEN };
- unsigned char hash[SHA256_MAC_LEN];
-
- addr[0] = (u8 *) title;
- addr[1] = aa;
- addr[2] = spa;
-
-#ifdef CONFIG_IEEE80211W
- if (use_sha256)
- hmac_sha256_vector(pmk, pmk_len, 3, addr, len, hash);
- else
-#endif /* CONFIG_IEEE80211W */
- hmac_sha1_vector(pmk, pmk_len, 3, addr, len, hash);
- os_memcpy(pmkid, hash, PMKID_LEN);
-}
-
-
static void pmksa_cache_set_expiration(struct rsn_pmksa_cache *pmksa);
@@ -83,7 +46,9 @@ static void _pmksa_cache_free_entry(struct rsn_pmksa_cache_entry *entry)
if (entry == NULL)
return;
os_free(entry->identity);
- ieee802_1x_free_radius_class(&entry->radius_class);
+#ifndef CONFIG_NO_RADIUS
+ radius_free_class(&entry->radius_class);
+#endif /* CONFIG_NO_RADIUS */
os_free(entry);
}
@@ -177,11 +142,12 @@ static void pmksa_cache_from_eapol_data(struct rsn_pmksa_cache_entry *entry,
}
}
- ieee802_1x_copy_radius_class(&entry->radius_class,
- &eapol->radius_class);
+#ifndef CONFIG_NO_RADIUS
+ radius_copy_class(&entry->radius_class, &eapol->radius_class);
+#endif /* CONFIG_NO_RADIUS */
entry->eap_type_authsrv = eapol->eap_type_authsrv;
- entry->vlan_id = eapol->sta->vlan_id;
+ entry->vlan_id = ((struct sta_info *) eapol->sta)->vlan_id;
}
@@ -203,16 +169,17 @@ void pmksa_cache_to_eapol_data(struct rsn_pmksa_cache_entry *entry,
eapol->identity, eapol->identity_len);
}
- ieee802_1x_free_radius_class(&eapol->radius_class);
- ieee802_1x_copy_radius_class(&eapol->radius_class,
- &entry->radius_class);
+#ifndef CONFIG_NO_RADIUS
+ radius_free_class(&eapol->radius_class);
+ radius_copy_class(&eapol->radius_class, &entry->radius_class);
+#endif /* CONFIG_NO_RADIUS */
if (eapol->radius_class.attr) {
wpa_printf(MSG_DEBUG, "Copied %lu Class attribute(s) from "
"PMKSA", (unsigned long) eapol->radius_class.count);
}
eapol->eap_type_authsrv = entry->eap_type_authsrv;
- eapol->sta->vlan_id = entry->vlan_id;
+ ((struct sta_info *) eapol->sta)->vlan_id = entry->vlan_id;
}
@@ -248,8 +215,8 @@ static void pmksa_cache_link_entry(struct rsn_pmksa_cache *pmksa,
/**
- * pmksa_cache_add - Add a PMKSA cache entry
- * @pmksa: Pointer to PMKSA cache data from pmksa_cache_init()
+ * pmksa_cache_auth_add - Add a PMKSA cache entry
+ * @pmksa: Pointer to PMKSA cache data from pmksa_cache_auth_init()
* @pmk: The new pairwise master key
* @pmk_len: PMK length in bytes, usually PMK_LEN (32)
* @aa: Authenticator address
@@ -265,7 +232,8 @@ static void pmksa_cache_link_entry(struct rsn_pmksa_cache *pmksa,
* based on the PMK.
*/
struct rsn_pmksa_cache_entry *
-pmksa_cache_add(struct rsn_pmksa_cache *pmksa, const u8 *pmk, size_t pmk_len,
+pmksa_cache_auth_add(struct rsn_pmksa_cache *pmksa,
+ const u8 *pmk, size_t pmk_len,
const u8 *aa, const u8 *spa, int session_timeout,
struct eapol_state_machine *eapol, int akmp)
{
@@ -294,7 +262,7 @@ pmksa_cache_add(struct rsn_pmksa_cache *pmksa, const u8 *pmk, size_t pmk_len,
/* Replace an old entry for the same STA (if found) with the new entry
*/
- pos = pmksa_cache_get(pmksa, spa, NULL);
+ pos = pmksa_cache_auth_get(pmksa, spa, NULL);
if (pos)
pmksa_cache_free_entry(pmksa, pos);
@@ -337,8 +305,9 @@ pmksa_cache_add_okc(struct rsn_pmksa_cache *pmksa,
old_entry->identity_len);
}
}
- ieee802_1x_copy_radius_class(&entry->radius_class,
- &old_entry->radius_class);
+#ifndef CONFIG_NO_RADIUS
+ radius_copy_class(&entry->radius_class, &old_entry->radius_class);
+#endif /* CONFIG_NO_RADIUS */
entry->eap_type_authsrv = old_entry->eap_type_authsrv;
entry->vlan_id = old_entry->vlan_id;
entry->opportunistic = 1;
@@ -350,10 +319,10 @@ pmksa_cache_add_okc(struct rsn_pmksa_cache *pmksa,
/**
- * pmksa_cache_deinit - Free all entries in PMKSA cache
- * @pmksa: Pointer to PMKSA cache data from pmksa_cache_init()
+ * pmksa_cache_auth_deinit - Free all entries in PMKSA cache
+ * @pmksa: Pointer to PMKSA cache data from pmksa_cache_auth_init()
*/
-void pmksa_cache_deinit(struct rsn_pmksa_cache *pmksa)
+void pmksa_cache_auth_deinit(struct rsn_pmksa_cache *pmksa)
{
struct rsn_pmksa_cache_entry *entry, *prev;
int i;
@@ -375,14 +344,15 @@ void pmksa_cache_deinit(struct rsn_pmksa_cache *pmksa)
/**
- * pmksa_cache_get - Fetch a PMKSA cache entry
- * @pmksa: Pointer to PMKSA cache data from pmksa_cache_init()
+ * pmksa_cache_auth_get - Fetch a PMKSA cache entry
+ * @pmksa: Pointer to PMKSA cache data from pmksa_cache_auth_init()
* @spa: Supplicant address or %NULL to match any
* @pmkid: PMKID or %NULL to match any
* Returns: Pointer to PMKSA cache entry or %NULL if no match was found
*/
-struct rsn_pmksa_cache_entry * pmksa_cache_get(struct rsn_pmksa_cache *pmksa,
- const u8 *spa, const u8 *pmkid)
+struct rsn_pmksa_cache_entry *
+pmksa_cache_auth_get(struct rsn_pmksa_cache *pmksa,
+ const u8 *spa, const u8 *pmkid)
{
struct rsn_pmksa_cache_entry *entry;
@@ -404,7 +374,7 @@ struct rsn_pmksa_cache_entry * pmksa_cache_get(struct rsn_pmksa_cache *pmksa,
/**
* pmksa_cache_get_okc - Fetch a PMKSA cache entry using OKC
- * @pmksa: Pointer to PMKSA cache data from pmksa_cache_init()
+ * @pmksa: Pointer to PMKSA cache data from pmksa_cache_auth_init()
* @aa: Authenticator address
* @spa: Supplicant address
* @pmkid: PMKID
@@ -434,14 +404,14 @@ struct rsn_pmksa_cache_entry * pmksa_cache_get_okc(
/**
- * pmksa_cache_init - Initialize PMKSA cache
+ * pmksa_cache_auth_init - Initialize PMKSA cache
* @free_cb: Callback function to be called when a PMKSA cache entry is freed
* @ctx: Context pointer for free_cb function
* Returns: Pointer to PMKSA cache data or %NULL on failure
*/
struct rsn_pmksa_cache *
-pmksa_cache_init(void (*free_cb)(struct rsn_pmksa_cache_entry *entry,
- void *ctx), void *ctx)
+pmksa_cache_auth_init(void (*free_cb)(struct rsn_pmksa_cache_entry *entry,
+ void *ctx), void *ctx)
{
struct rsn_pmksa_cache *pmksa;
diff --git a/contrib/wpa/hostapd/pmksa_cache.h b/contrib/wpa/src/ap/pmksa_cache_auth.h
index 6ba2da6..9628b13 100644
--- a/contrib/wpa/hostapd/pmksa_cache.h
+++ b/contrib/wpa/src/ap/pmksa_cache_auth.h
@@ -15,6 +15,8 @@
#ifndef PMKSA_CACHE_H
#define PMKSA_CACHE_H
+#include "radius/radius.h"
+
/**
* struct rsn_pmksa_cache_entry - PMKSA cache entry
*/
@@ -38,25 +40,25 @@ struct rsn_pmksa_cache_entry {
struct rsn_pmksa_cache;
struct rsn_pmksa_cache *
-pmksa_cache_init(void (*free_cb)(struct rsn_pmksa_cache_entry *entry,
- void *ctx), void *ctx);
-void pmksa_cache_deinit(struct rsn_pmksa_cache *pmksa);
-struct rsn_pmksa_cache_entry * pmksa_cache_get(struct rsn_pmksa_cache *pmksa,
- const u8 *spa, const u8 *pmkid);
+pmksa_cache_auth_init(void (*free_cb)(struct rsn_pmksa_cache_entry *entry,
+ void *ctx), void *ctx);
+void pmksa_cache_auth_deinit(struct rsn_pmksa_cache *pmksa);
+struct rsn_pmksa_cache_entry *
+pmksa_cache_auth_get(struct rsn_pmksa_cache *pmksa,
+ const u8 *spa, const u8 *pmkid);
struct rsn_pmksa_cache_entry * pmksa_cache_get_okc(
struct rsn_pmksa_cache *pmksa, const u8 *spa, const u8 *aa,
const u8 *pmkid);
struct rsn_pmksa_cache_entry *
-pmksa_cache_add(struct rsn_pmksa_cache *pmksa, const u8 *pmk, size_t pmk_len,
- const u8 *aa, const u8 *spa, int session_timeout,
- struct eapol_state_machine *eapol, int akmp);
+pmksa_cache_auth_add(struct rsn_pmksa_cache *pmksa,
+ const u8 *pmk, size_t pmk_len,
+ const u8 *aa, const u8 *spa, int session_timeout,
+ struct eapol_state_machine *eapol, int akmp);
struct rsn_pmksa_cache_entry *
pmksa_cache_add_okc(struct rsn_pmksa_cache *pmksa,
const struct rsn_pmksa_cache_entry *old_entry,
const u8 *aa, const u8 *pmkid);
void pmksa_cache_to_eapol_data(struct rsn_pmksa_cache_entry *entry,
struct eapol_state_machine *eapol);
-void rsn_pmkid(const u8 *pmk, size_t pmk_len, const u8 *aa, const u8 *spa,
- u8 *pmkid, int use_sha256);
#endif /* PMKSA_CACHE_H */
diff --git a/contrib/wpa/hostapd/preauth.c b/contrib/wpa/src/ap/preauth_auth.c
index 9ab41ed..8e13315 100644
--- a/contrib/wpa/hostapd/preauth.c
+++ b/contrib/wpa/src/ap/preauth_auth.c
@@ -12,19 +12,22 @@
* See README and COPYING for more details.
*/
-#include "includes.h"
+#include "utils/includes.h"
#ifdef CONFIG_RSN_PREAUTH
-#include "hostapd.h"
+#include "utils/common.h"
+#include "utils/eloop.h"
#include "l2_packet/l2_packet.h"
+#include "common/wpa_common.h"
+#include "eapol_auth/eapol_auth_sm.h"
+#include "eapol_auth/eapol_auth_sm_i.h"
+#include "hostapd.h"
+#include "ap_config.h"
#include "ieee802_1x.h"
-#include "eloop.h"
#include "sta_info.h"
-#include "wpa_common.h"
-#include "eapol_sm.h"
-#include "wpa.h"
-#include "preauth.h"
+#include "wpa_auth.h"
+#include "preauth_auth.h"
#ifndef ETH_P_PREAUTH
#define ETH_P_PREAUTH 0x88C7 /* IEEE 802.11i pre-authentication */
@@ -256,7 +259,7 @@ void rsn_preauth_send(struct hostapd_data *hapd, struct sta_info *sta,
os_memcpy(ethhdr->h_dest, sta->addr, ETH_ALEN);
os_memcpy(ethhdr->h_source, hapd->own_addr, ETH_ALEN);
- ethhdr->h_proto = htons(ETH_P_PREAUTH);
+ ethhdr->h_proto = host_to_be16(ETH_P_PREAUTH);
os_memcpy(ethhdr + 1, buf, len);
if (l2_packet_send(piface->l2, sta->addr, ETH_P_PREAUTH, (u8 *) ethhdr,
diff --git a/contrib/wpa/hostapd/preauth.h b/contrib/wpa/src/ap/preauth_auth.h
index 5348bee..5348bee 100644
--- a/contrib/wpa/hostapd/preauth.h
+++ b/contrib/wpa/src/ap/preauth_auth.h
diff --git a/contrib/wpa/hostapd/sta_info.c b/contrib/wpa/src/ap/sta_info.c
index a139ba9..335c9a5 100644
--- a/contrib/wpa/hostapd/sta_info.c
+++ b/contrib/wpa/src/ap/sta_info.c
@@ -1,7 +1,6 @@
/*
* hostapd / Station table
- * Copyright (c) 2002-2008, Jouni Malinen <j@w1.fi>
- * Copyright (c) 2007-2008, Intel Corporation
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -13,26 +12,28 @@
* See README and COPYING for more details.
*/
-#include "includes.h"
+#include "utils/includes.h"
+#include "utils/common.h"
+#include "utils/eloop.h"
+#include "common/ieee802_11_defs.h"
+#include "radius/radius.h"
+#include "radius/radius_client.h"
+#include "drivers/driver.h"
#include "hostapd.h"
-#include "sta_info.h"
-#include "eloop.h"
#include "accounting.h"
#include "ieee802_1x.h"
#include "ieee802_11.h"
-#include "radius/radius.h"
-#include "wpa.h"
-#include "preauth.h"
-#include "radius/radius_client.h"
-#include "driver.h"
+#include "wpa_auth.h"
+#include "preauth_auth.h"
+#include "ap_config.h"
#include "beacon.h"
-#include "hw_features.h"
-#include "mlme.h"
+#include "ap_mlme.h"
#include "vlan_init.h"
+#include "sta_info.h"
-static int ap_sta_in_other_bss(struct hostapd_data *hapd,
- struct sta_info *sta, u32 flags);
+static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
+ struct sta_info *sta);
static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx);
#ifdef CONFIG_IEEE80211W
static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx);
@@ -120,15 +121,18 @@ void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
accounting_sta_stop(hapd, sta);
- if (!ap_sta_in_other_bss(hapd, sta, WLAN_STA_ASSOC) &&
- !(sta->flags & WLAN_STA_PREAUTH))
- hostapd_sta_remove(hapd, sta->addr);
+ if (sta->flags & WLAN_STA_WDS)
+ hapd->drv.set_wds_sta(hapd, sta->addr, sta->aid, 0);
+
+ if (!(sta->flags & WLAN_STA_PREAUTH))
+ hapd->drv.sta_remove(hapd, sta->addr);
ap_sta_hash_del(hapd, sta);
ap_sta_list_del(hapd, sta);
if (sta->aid > 0)
- hapd->sta_aid[sta->aid - 1] = NULL;
+ hapd->sta_aid[(sta->aid - 1) / 32] &=
+ ~BIT((sta->aid - 1) % 32);
hapd->num_sta--;
if (sta->nonerp_set) {
@@ -154,7 +158,6 @@ void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
set_beacon++;
}
-#ifdef CONFIG_IEEE80211N
if (sta->no_ht_gf_set) {
sta->no_ht_gf_set = 0;
hapd->iface->num_sta_ht_no_gf--;
@@ -170,9 +173,10 @@ void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
hapd->iface->num_sta_ht_20mhz--;
}
+#if defined(NEED_AP_MLME) && defined(CONFIG_IEEE80211N)
if (hostapd_ht_operation_update(hapd->iface) > 0)
set_beacon++;
-#endif /* CONFIG_IEEE80211N */
+#endif /* NEED_AP_MLME && CONFIG_IEEE80211N */
if (set_beacon)
ieee802_11_set_beacons(hapd->iface);
@@ -183,7 +187,9 @@ void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
ieee802_1x_free_station(sta);
wpa_auth_sta_deinit(sta->wpa_sm);
rsn_preauth_free_station(hapd, sta);
+#ifndef CONFIG_NO_RADIUS
radius_client_flush_auth(hapd->radius, sta->addr);
+#endif /* CONFIG_NO_RADIUS */
os_free(sta->last_assoc_req);
os_free(sta->challenge);
@@ -195,6 +201,8 @@ void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
wpabuf_free(sta->wps_ie);
+ os_free(sta->ht_capabilities);
+
os_free(sta);
}
@@ -247,7 +255,7 @@ void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
int inactive_sec;
wpa_printf(MSG_DEBUG, "Checking STA " MACSTR " inactivity:",
MAC2STR(sta->addr));
- inactive_sec = hostapd_get_inact_sec(hapd, sta->addr);
+ inactive_sec = hapd->drv.get_inact_sec(hapd, sta->addr);
if (inactive_sec == -1) {
wpa_printf(MSG_DEBUG, "Could not get station info "
"from kernel driver for " MACSTR ".",
@@ -280,6 +288,7 @@ void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
if (sta->timeout_next == STA_NULLFUNC &&
(sta->flags & WLAN_STA_ASSOC)) {
+#ifndef CONFIG_NATIVE_WINDOWS
/* send data frame to poll STA and check whether this frame
* is ACKed */
struct ieee80211_hdr hdr;
@@ -287,7 +296,6 @@ void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
wpa_printf(MSG_DEBUG, " Polling STA with data frame");
sta->flags |= WLAN_STA_PENDING_POLL;
-#ifndef CONFIG_NATIVE_WINDOWS
os_memset(&hdr, 0, sizeof(hdr));
if (hapd->driver &&
os_strcmp(hapd->driver->name, "hostap") == 0) {
@@ -311,7 +319,7 @@ void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
ETH_ALEN);
os_memcpy(hdr.IEEE80211_SA_FROMDS, hapd->own_addr, ETH_ALEN);
- if (hostapd_send_mgmt_frame(hapd, &hdr, sizeof(hdr), 0) < 0)
+ if (hapd->drv.send_mgmt_frame(hapd, &hdr, sizeof(hdr)) < 0)
perror("ap_handle_timer: send");
#endif /* CONFIG_NATIVE_WINDOWS */
} else if (sta->timeout_next != STA_REMOVE) {
@@ -322,10 +330,10 @@ void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
MAC2STR(sta->addr));
if (deauth) {
- hostapd_sta_deauth(hapd, sta->addr,
- WLAN_REASON_PREV_AUTH_NOT_VALID);
+ hapd->drv.sta_deauth(hapd, sta->addr,
+ WLAN_REASON_PREV_AUTH_NOT_VALID);
} else {
- hostapd_sta_disassoc(
+ hapd->drv.sta_disassoc(
hapd, sta->addr,
WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
}
@@ -389,7 +397,7 @@ static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx)
RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT;
os_memcpy(addr, sta->addr, ETH_ALEN);
ap_free_sta(hapd, sta);
- hostapd_sta_deauth(hapd, addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
+ hapd->drv.sta_deauth(hapd, addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
}
@@ -432,7 +440,7 @@ struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr)
wpa_printf(MSG_ERROR, "malloc failed");
return NULL;
}
- sta->acct_interim_interval = hapd->conf->radius->acct_interim_interval;
+ sta->acct_interim_interval = hapd->conf->acct_interim_interval;
/* initialize STA info data */
eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
@@ -443,6 +451,7 @@ struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr)
hapd->num_sta++;
ap_sta_hash_add(hapd, sta);
sta->ssid = &hapd->conf->ssid;
+ ap_sta_remove_in_other_bss(hapd, sta);
return sta;
}
@@ -454,7 +463,7 @@ static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta)
wpa_printf(MSG_DEBUG, "Removing STA " MACSTR " from kernel driver",
MAC2STR(sta->addr));
- if (hostapd_sta_remove(hapd, sta->addr) &&
+ if (hapd->drv.sta_remove(hapd, sta->addr) &&
sta->flags & WLAN_STA_ASSOC) {
wpa_printf(MSG_DEBUG, "Could not remove station " MACSTR
" from kernel driver.", MAC2STR(sta->addr));
@@ -464,8 +473,8 @@ static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta)
}
-static int ap_sta_in_other_bss(struct hostapd_data *hapd,
- struct sta_info *sta, u32 flags)
+static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
+ struct sta_info *sta)
{
struct hostapd_iface *iface = hapd->iface;
size_t i;
@@ -480,11 +489,12 @@ static int ap_sta_in_other_bss(struct hostapd_data *hapd,
if (bss == hapd || bss == NULL)
continue;
sta2 = ap_get_sta(bss, sta->addr);
- if (sta2 && ((sta2->flags & flags) == flags))
- return 1;
- }
+ if (!sta2)
+ continue;
- return 0;
+ ap_sta_disconnect(bss, sta2, sta2->addr,
+ WLAN_REASON_PREV_AUTH_NOT_VALID);
+ }
}
@@ -494,8 +504,7 @@ void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,
wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR,
hapd->conf->iface, MAC2STR(sta->addr));
sta->flags &= ~WLAN_STA_ASSOC;
- if (!ap_sta_in_other_bss(hapd, sta, WLAN_STA_ASSOC))
- ap_sta_remove(hapd, sta);
+ ap_sta_remove(hapd, sta);
sta->timeout_next = STA_DEAUTH;
eloop_cancel_timeout(ap_handle_timer, hapd, sta);
eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0,
@@ -513,8 +522,7 @@ void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR,
hapd->conf->iface, MAC2STR(sta->addr));
sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
- if (!ap_sta_in_other_bss(hapd, sta, WLAN_STA_ASSOC))
- ap_sta_remove(hapd, sta);
+ ap_sta_remove(hapd, sta);
sta->timeout_next = STA_REMOVE;
eloop_cancel_timeout(ap_handle_timer, hapd, sta);
eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
@@ -529,8 +537,10 @@ void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
int old_vlanid)
{
+#ifndef CONFIG_NO_VLAN
const char *iface;
struct hostapd_vlan *vlan = NULL;
+ int ret;
/*
* Do not proceed furthur if the vlan id remains same. We do not want
@@ -626,7 +636,16 @@ int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0)
wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA");
- return hostapd_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id);
+ ret = hapd->drv.set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id);
+ if (ret < 0) {
+ hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
+ HOSTAPD_LEVEL_DEBUG, "could not bind the STA "
+ "entry to vlan_id=%d", sta->vlan_id);
+ }
+ return ret;
+#else /* CONFIG_NO_VLAN */
+ return 0;
+#endif /* CONFIG_NO_VLAN */
}
@@ -690,7 +709,9 @@ static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx)
HOSTAPD_LEVEL_DEBUG,
"association SA Query attempt %d", sta->sa_query_count);
+#ifdef NEED_AP_MLME
ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id);
+#endif /* NEED_AP_MLME */
}
@@ -709,3 +730,22 @@ void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
}
#endif /* CONFIG_IEEE80211W */
+
+
+void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta,
+ const u8 *addr, u16 reason)
+{
+
+ if (sta == NULL && addr)
+ sta = ap_get_sta(hapd, addr);
+
+ if (addr)
+ hapd->drv.sta_deauth(hapd, addr, reason);
+
+ if (sta == NULL)
+ return;
+ sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_AUTHORIZED);
+ eloop_cancel_timeout(ap_handle_timer, hapd, sta);
+ eloop_register_timeout(0, 0, ap_handle_timer, hapd, sta);
+ sta->timeout_next = STA_REMOVE;
+}
diff --git a/contrib/wpa/hostapd/ap.h b/contrib/wpa/src/ap/sta_info.h
index 2c6d7e9..55faa5a 100644
--- a/contrib/wpa/hostapd/ap.h
+++ b/contrib/wpa/src/ap/sta_info.h
@@ -1,7 +1,6 @@
/*
- * hostapd / Station table data structures
- * Copyright (c) 2002-2008, Jouni Malinen <j@w1.fi>
- * Copyright (c) 2007-2008, Intel Corporation
+ * hostapd / Station table
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -13,12 +12,8 @@
* See README and COPYING for more details.
*/
-#ifndef AP_H
-#define AP_H
-
-#ifdef CONFIG_IEEE80211N
-#include "ieee802_11_defs.h"
-#endif /* CONFIG_IEEE80211N */
+#ifndef STA_INFO_H
+#define STA_INFO_H
/* STA flags */
#define WLAN_STA_AUTH BIT(0)
@@ -35,6 +30,7 @@
#define WLAN_STA_HT BIT(11)
#define WLAN_STA_WPS BIT(12)
#define WLAN_STA_MAYBE_WPS BIT(13)
+#define WLAN_STA_WDS BIT(14)
#define WLAN_STA_NONERP BIT(31)
/* Maximum number of supported rates (from both Supported Rates and Extended
@@ -47,7 +43,7 @@ struct sta_info {
struct sta_info *hnext; /* next entry in hash table list */
u8 addr[6];
u16 aid; /* STA's unique AID (1 .. 2007) or 0 if not yet assigned */
- u32 flags;
+ u32 flags; /* Bitfield of WLAN_STA_* */
u16 capability;
u16 listen_interval; /* or beacon_int for APs */
u8 supported_rates[WLAN_SUPP_RATES_MAX];
@@ -95,9 +91,7 @@ struct sta_info {
int vlan_id;
-#ifdef CONFIG_IEEE80211N
- struct ht_cap_ie ht_capabilities; /* IEEE 802.11n capabilities */
-#endif /* CONFIG_IEEE80211N */
+ struct ieee80211_ht_capabilities *ht_capabilities;
#ifdef CONFIG_IEEE80211W
int sa_query_count; /* number of pending SA Query requests;
@@ -113,14 +107,6 @@ struct sta_info {
};
-/* Maximum number of AIDs to use for STAs; must be 2007 or lower
- * (8802.11 limitation) */
-#define MAX_AID_TABLE_SIZE 128
-
-#define STA_HASH_SIZE 256
-#define STA_HASH(sta) (sta[5])
-
-
/* Default value for maximum station inactivity. After AP_MAX_INACTIVITY has
* passed since last received frame from the station, a nullfunc data frame is
* sent to the station. If this frame is not acknowledged and no other frames
@@ -136,4 +122,34 @@ struct sta_info {
/* Number of seconds to keep STA entry after it has been deauthenticated. */
#define AP_MAX_INACTIVITY_AFTER_DEAUTH (1 * 5)
-#endif /* AP_H */
+
+struct hostapd_data;
+
+int ap_for_each_sta(struct hostapd_data *hapd,
+ int (*cb)(struct hostapd_data *hapd, struct sta_info *sta,
+ void *ctx),
+ void *ctx);
+struct sta_info * ap_get_sta(struct hostapd_data *hapd, const u8 *sta);
+void ap_sta_hash_add(struct hostapd_data *hapd, struct sta_info *sta);
+void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta);
+void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta);
+void hostapd_free_stas(struct hostapd_data *hapd);
+void ap_handle_timer(void *eloop_ctx, void *timeout_ctx);
+void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,
+ u32 session_timeout);
+void ap_sta_no_session_timeout(struct hostapd_data *hapd,
+ struct sta_info *sta);
+struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr);
+void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,
+ u16 reason);
+void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
+ u16 reason);
+int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
+ int old_vlanid);
+void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta);
+void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta);
+int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta);
+void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta,
+ const u8 *addr, u16 reason);
+
+#endif /* STA_INFO_H */
diff --git a/contrib/wpa/src/ap/tkip_countermeasures.c b/contrib/wpa/src/ap/tkip_countermeasures.c
new file mode 100644
index 0000000..9690348
--- /dev/null
+++ b/contrib/wpa/src/ap/tkip_countermeasures.c
@@ -0,0 +1,93 @@
+/*
+ * hostapd / TKIP countermeasures
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "utils/includes.h"
+
+#include "utils/common.h"
+#include "utils/eloop.h"
+#include "common/ieee802_11_defs.h"
+#include "hostapd.h"
+#include "sta_info.h"
+#include "ap_mlme.h"
+#include "wpa_auth.h"
+#include "tkip_countermeasures.h"
+
+
+static void ieee80211_tkip_countermeasures_stop(void *eloop_ctx,
+ void *timeout_ctx)
+{
+ struct hostapd_data *hapd = eloop_ctx;
+ hapd->tkip_countermeasures = 0;
+ hapd->drv.set_countermeasures(hapd, 0);
+ hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
+ HOSTAPD_LEVEL_INFO, "TKIP countermeasures ended");
+}
+
+
+static void ieee80211_tkip_countermeasures_start(struct hostapd_data *hapd)
+{
+ struct sta_info *sta;
+
+ hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
+ HOSTAPD_LEVEL_INFO, "TKIP countermeasures initiated");
+
+ wpa_auth_countermeasures_start(hapd->wpa_auth);
+ hapd->tkip_countermeasures = 1;
+ hapd->drv.set_countermeasures(hapd, 1);
+ wpa_gtk_rekey(hapd->wpa_auth);
+ eloop_cancel_timeout(ieee80211_tkip_countermeasures_stop, hapd, NULL);
+ eloop_register_timeout(60, 0, ieee80211_tkip_countermeasures_stop,
+ hapd, NULL);
+ for (sta = hapd->sta_list; sta != NULL; sta = sta->next) {
+ hapd->drv.sta_deauth(hapd, sta->addr,
+ WLAN_REASON_MICHAEL_MIC_FAILURE);
+ sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
+ WLAN_STA_AUTHORIZED);
+ hapd->drv.sta_remove(hapd, sta->addr);
+ }
+}
+
+
+void michael_mic_failure(struct hostapd_data *hapd, const u8 *addr, int local)
+{
+ time_t now;
+
+ if (addr && local) {
+ struct sta_info *sta = ap_get_sta(hapd, addr);
+ if (sta != NULL) {
+ wpa_auth_sta_local_mic_failure_report(sta->wpa_sm);
+ hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
+ HOSTAPD_LEVEL_INFO,
+ "Michael MIC failure detected in "
+ "received frame");
+ mlme_michaelmicfailure_indication(hapd, addr);
+ } else {
+ wpa_printf(MSG_DEBUG,
+ "MLME-MICHAELMICFAILURE.indication "
+ "for not associated STA (" MACSTR
+ ") ignored", MAC2STR(addr));
+ return;
+ }
+ }
+
+ time(&now);
+ if (now > hapd->michael_mic_failure + 60) {
+ hapd->michael_mic_failures = 1;
+ } else {
+ hapd->michael_mic_failures++;
+ if (hapd->michael_mic_failures > 1)
+ ieee80211_tkip_countermeasures_start(hapd);
+ }
+ hapd->michael_mic_failure = now;
+}
diff --git a/contrib/wpa/src/ap/tkip_countermeasures.h b/contrib/wpa/src/ap/tkip_countermeasures.h
new file mode 100644
index 0000000..5a1afce
--- /dev/null
+++ b/contrib/wpa/src/ap/tkip_countermeasures.h
@@ -0,0 +1,20 @@
+/*
+ * hostapd / TKIP countermeasures
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef TKIP_COUNTERMEASURES_H
+#define TKIP_COUNTERMEASURES_H
+
+void michael_mic_failure(struct hostapd_data *hapd, const u8 *addr, int local);
+
+#endif /* TKIP_COUNTERMEASURES_H */
diff --git a/contrib/wpa/src/ap/utils.c b/contrib/wpa/src/ap/utils.c
new file mode 100644
index 0000000..0ff48ae
--- /dev/null
+++ b/contrib/wpa/src/ap/utils.c
@@ -0,0 +1,88 @@
+/*
+ * AP mode helper functions
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "common/ieee802_11_defs.h"
+#include "sta_info.h"
+#include "hostapd.h"
+
+
+int hostapd_register_probereq_cb(struct hostapd_data *hapd,
+ int (*cb)(void *ctx, const u8 *sa,
+ const u8 *ie, size_t ie_len),
+ void *ctx)
+{
+ struct hostapd_probereq_cb *n;
+
+ n = os_realloc(hapd->probereq_cb, (hapd->num_probereq_cb + 1) *
+ sizeof(struct hostapd_probereq_cb));
+ if (n == NULL)
+ return -1;
+
+ hapd->probereq_cb = n;
+ n = &hapd->probereq_cb[hapd->num_probereq_cb];
+ hapd->num_probereq_cb++;
+
+ n->cb = cb;
+ n->ctx = ctx;
+
+ return 0;
+}
+
+
+struct prune_data {
+ struct hostapd_data *hapd;
+ const u8 *addr;
+};
+
+static int prune_associations(struct hostapd_iface *iface, void *ctx)
+{
+ struct prune_data *data = ctx;
+ struct sta_info *osta;
+ struct hostapd_data *ohapd;
+ size_t j;
+
+ for (j = 0; j < iface->num_bss; j++) {
+ ohapd = iface->bss[j];
+ if (ohapd == data->hapd)
+ continue;
+ osta = ap_get_sta(ohapd, data->addr);
+ if (!osta)
+ continue;
+
+ ap_sta_disassociate(ohapd, osta, WLAN_REASON_UNSPECIFIED);
+ }
+
+ return 0;
+}
+
+/**
+ * hostapd_prune_associations - Remove extraneous associations
+ * @hapd: Pointer to BSS data for the most recent association
+ * @addr: Associated STA address
+ *
+ * This function looks through all radios and BSS's for previous
+ * (stale) associations of STA. If any are found they are removed.
+ */
+void hostapd_prune_associations(struct hostapd_data *hapd, const u8 *addr)
+{
+ struct prune_data data;
+ data.hapd = hapd;
+ data.addr = addr;
+ if (hapd->iface->for_each_interface)
+ hapd->iface->for_each_interface(hapd->iface->interfaces,
+ prune_associations, &data);
+}
diff --git a/contrib/wpa/hostapd/vlan_init.c b/contrib/wpa/src/ap/vlan_init.c
index 87c61e2..c9d166a 100644
--- a/contrib/wpa/hostapd/vlan_init.c
+++ b/contrib/wpa/src/ap/vlan_init.c
@@ -2,6 +2,7 @@
* hostapd / VLAN initialization
* Copyright 2003, Instant802 Networks, Inc.
* Copyright 2005-2006, Devicescape Software, Inc.
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -13,10 +14,11 @@
* See README and COPYING for more details.
*/
-#include "includes.h"
+#include "utils/includes.h"
+#include "utils/common.h"
#include "hostapd.h"
-#include "driver.h"
+#include "ap_config.h"
#include "vlan_init.h"
@@ -28,8 +30,8 @@
#include <linux/if_vlan.h>
#include <linux/if_bridge.h>
-#include "priv_netlink.h"
-#include "eloop.h"
+#include "drivers/priv_netlink.h"
+#include "utils/eloop.h"
struct full_dynamic_vlan {
@@ -43,7 +45,8 @@ static int ifconfig_helper(const char *if_name, int up)
struct ifreq ifr;
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
- perror("socket[AF_INET,SOCK_STREAM]");
+ wpa_printf(MSG_ERROR, "VLAN: %s: socket(AF_INET,SOCK_STREAM) "
+ "failed: %s", __func__, strerror(errno));
return -1;
}
@@ -51,7 +54,9 @@ static int ifconfig_helper(const char *if_name, int up)
os_strlcpy(ifr.ifr_name, if_name, IFNAMSIZ);
if (ioctl(fd, SIOCGIFFLAGS, &ifr) != 0) {
- perror("ioctl[SIOCGIFFLAGS]");
+ wpa_printf(MSG_ERROR, "VLAN: %s: ioctl(SIOCGIFFLAGS) failed "
+ "for interface %s: %s",
+ __func__, if_name, strerror(errno));
close(fd);
return -1;
}
@@ -62,7 +67,9 @@ static int ifconfig_helper(const char *if_name, int up)
ifr.ifr_flags &= ~IFF_UP;
if (ioctl(fd, SIOCSIFFLAGS, &ifr) != 0) {
- perror("ioctl[SIOCSIFFLAGS]");
+ wpa_printf(MSG_ERROR, "VLAN: %s: ioctl(SIOCSIFFLAGS) failed "
+ "for interface %s (up=%d): %s",
+ __func__, if_name, up, strerror(errno));
close(fd);
return -1;
}
@@ -74,12 +81,14 @@ static int ifconfig_helper(const char *if_name, int up)
static int ifconfig_up(const char *if_name)
{
+ wpa_printf(MSG_DEBUG, "VLAN: Set interface %s up", if_name);
return ifconfig_helper(if_name, 1);
}
static int ifconfig_down(const char *if_name)
{
+ wpa_printf(MSG_DEBUG, "VLAN: Set interface %s down", if_name);
return ifconfig_helper(if_name, 0);
}
@@ -104,16 +113,19 @@ static int br_delif(const char *br_name, const char *if_name)
unsigned long args[2];
int if_index;
+ wpa_printf(MSG_DEBUG, "VLAN: br_delif(%s, %s)", br_name, if_name);
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
- perror("socket[AF_INET,SOCK_STREAM]");
+ wpa_printf(MSG_ERROR, "VLAN: %s: socket(AF_INET,SOCK_STREAM) "
+ "failed: %s", __func__, strerror(errno));
return -1;
}
if_index = if_nametoindex(if_name);
if (if_index == 0) {
- printf("Failure determining interface index for '%s'\n",
- if_name);
+ wpa_printf(MSG_ERROR, "VLAN: %s: Failure determining "
+ "interface index for '%s'",
+ __func__, if_name);
close(fd);
return -1;
}
@@ -126,7 +138,9 @@ static int br_delif(const char *br_name, const char *if_name)
if (ioctl(fd, SIOCDEVPRIVATE, &ifr) < 0 && errno != EINVAL) {
/* No error if interface already removed. */
- perror("ioctl[SIOCDEVPRIVATE,BRCTL_DEL_IF]");
+ wpa_printf(MSG_ERROR, "VLAN: %s: ioctl[SIOCDEVPRIVATE,"
+ "BRCTL_DEL_IF] failed for br_name=%s if_name=%s: "
+ "%s", __func__, br_name, if_name, strerror(errno));
close(fd);
return -1;
}
@@ -150,16 +164,19 @@ static int br_addif(const char *br_name, const char *if_name)
unsigned long args[2];
int if_index;
+ wpa_printf(MSG_DEBUG, "VLAN: br_addif(%s, %s)", br_name, if_name);
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
- perror("socket[AF_INET,SOCK_STREAM]");
+ wpa_printf(MSG_ERROR, "VLAN: %s: socket(AF_INET,SOCK_STREAM) "
+ "failed: %s", __func__, strerror(errno));
return -1;
}
if_index = if_nametoindex(if_name);
if (if_index == 0) {
- printf("Failure determining interface index for '%s'\n",
- if_name);
+ wpa_printf(MSG_ERROR, "VLAN: %s: Failure determining "
+ "interface index for '%s'",
+ __func__, if_name);
close(fd);
return -1;
}
@@ -177,7 +194,9 @@ static int br_addif(const char *br_name, const char *if_name)
return 1;
}
- perror("ioctl[SIOCDEVPRIVATE,BRCTL_ADD_IF]");
+ wpa_printf(MSG_ERROR, "VLAN: %s: ioctl[SIOCDEVPRIVATE,"
+ "BRCTL_ADD_IF] failed for br_name=%s if_name=%s: "
+ "%s", __func__, br_name, if_name, strerror(errno));
close(fd);
return -1;
}
@@ -192,8 +211,10 @@ static int br_delbr(const char *br_name)
int fd;
unsigned long arg[2];
+ wpa_printf(MSG_DEBUG, "VLAN: br_delbr(%s)", br_name);
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
- perror("socket[AF_INET,SOCK_STREAM]");
+ wpa_printf(MSG_ERROR, "VLAN: %s: socket(AF_INET,SOCK_STREAM) "
+ "failed: %s", __func__, strerror(errno));
return -1;
}
@@ -202,7 +223,8 @@ static int br_delbr(const char *br_name)
if (ioctl(fd, SIOCGIFBR, arg) < 0 && errno != ENXIO) {
/* No error if bridge already removed. */
- perror("ioctl[BRCTL_DEL_BRIDGE]");
+ wpa_printf(MSG_ERROR, "VLAN: %s: BRCTL_DEL_BRIDGE failed for "
+ "%s: %s", __func__, br_name, strerror(errno));
close(fd);
return -1;
}
@@ -222,10 +244,13 @@ static int br_delbr(const char *br_name)
static int br_addbr(const char *br_name)
{
int fd;
- unsigned long arg[2];
+ unsigned long arg[4];
+ struct ifreq ifr;
+ wpa_printf(MSG_DEBUG, "VLAN: br_addbr(%s)", br_name);
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
- perror("socket[AF_INET,SOCK_STREAM]");
+ wpa_printf(MSG_ERROR, "VLAN: %s: socket(AF_INET,SOCK_STREAM) "
+ "failed: %s", __func__, strerror(errno));
return -1;
}
@@ -238,12 +263,29 @@ static int br_addbr(const char *br_name)
close(fd);
return 1;
} else {
- perror("ioctl[BRCTL_ADD_BRIDGE]");
+ wpa_printf(MSG_ERROR, "VLAN: %s: BRCTL_ADD_BRIDGE "
+ "failed for %s: %s",
+ __func__, br_name, strerror(errno));
close(fd);
return -1;
}
}
+ /* Decrease forwarding delay to avoid EAPOL timeouts. */
+ os_memset(&ifr, 0, sizeof(ifr));
+ os_strlcpy(ifr.ifr_name, br_name, IFNAMSIZ);
+ arg[0] = BRCTL_SET_BRIDGE_FORWARD_DELAY;
+ arg[1] = 1;
+ arg[2] = 0;
+ arg[3] = 0;
+ ifr.ifr_data = (char *) &arg;
+ if (ioctl(fd, SIOCDEVPRIVATE, &ifr) < 0) {
+ wpa_printf(MSG_ERROR, "VLAN: %s: "
+ "BRCTL_SET_BRIDGE_FORWARD_DELAY (1 sec) failed for "
+ "%s: %s", __func__, br_name, strerror(errno));
+ /* Continue anyway */
+ }
+
close(fd);
return 0;
}
@@ -259,7 +301,8 @@ static int br_getnumports(const char *br_name)
struct ifreq ifr;
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
- perror("socket[AF_INET,SOCK_STREAM]");
+ wpa_printf(MSG_ERROR, "VLAN: %s: socket(AF_INET,SOCK_STREAM) "
+ "failed: %s", __func__, strerror(errno));
return -1;
}
@@ -273,7 +316,9 @@ static int br_getnumports(const char *br_name)
ifr.ifr_data = (__caddr_t) arg;
if (ioctl(fd, SIOCDEVPRIVATE, &ifr) < 0) {
- perror("ioctl[SIOCDEVPRIVATE,BRCTL_GET_PORT_LIST]");
+ wpa_printf(MSG_ERROR, "VLAN: %s: BRCTL_GET_PORT_LIST "
+ "failed for %s: %s",
+ __func__, br_name, strerror(errno));
close(fd);
return -1;
}
@@ -294,13 +339,16 @@ static int vlan_rem(const char *if_name)
int fd;
struct vlan_ioctl_args if_request;
+ wpa_printf(MSG_DEBUG, "VLAN: vlan_rem(%s)", if_name);
if ((os_strlen(if_name) + 1) > sizeof(if_request.device1)) {
- fprintf(stderr, "Interface name to long.\n");
+ wpa_printf(MSG_ERROR, "VLAN: Interface name too long: '%s'",
+ if_name);
return -1;
}
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
- perror("socket[AF_INET,SOCK_STREAM]");
+ wpa_printf(MSG_ERROR, "VLAN: %s: socket(AF_INET,SOCK_STREAM) "
+ "failed: %s", __func__, strerror(errno));
return -1;
}
@@ -310,7 +358,8 @@ static int vlan_rem(const char *if_name)
if_request.cmd = DEL_VLAN_CMD;
if (ioctl(fd, SIOCSIFVLAN, &if_request) < 0) {
- perror("ioctl[SIOCSIFVLAN,DEL_VLAN_CMD]");
+ wpa_printf(MSG_ERROR, "VLAN: %s: DEL_VLAN_CMD failed for %s: "
+ "%s", __func__, if_name, strerror(errno));
close(fd);
return -1;
}
@@ -333,15 +382,19 @@ static int vlan_add(const char *if_name, int vid)
int fd;
struct vlan_ioctl_args if_request;
+ wpa_printf(MSG_DEBUG, "VLAN: vlan_add(if_name=%s, vid=%d)",
+ if_name, vid);
ifconfig_up(if_name);
if ((os_strlen(if_name) + 1) > sizeof(if_request.device1)) {
- fprintf(stderr, "Interface name to long.\n");
+ wpa_printf(MSG_ERROR, "VLAN: Interface name too long: '%s'",
+ if_name);
return -1;
}
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
- perror("socket[AF_INET,SOCK_STREAM]");
+ wpa_printf(MSG_ERROR, "VLAN: %s: socket(AF_INET,SOCK_STREAM) "
+ "failed: %s", __func__, strerror(errno));
return -1;
}
@@ -363,6 +416,9 @@ static int vlan_add(const char *if_name, int vid)
os_strncmp(if_request.u.device2, if_name,
sizeof(if_request.u.device2)) == 0) {
close(fd);
+ wpa_printf(MSG_DEBUG, "VLAN: vlan_add: "
+ "if_name %s exists already",
+ if_request.device1);
return 1;
}
}
@@ -376,7 +432,9 @@ static int vlan_add(const char *if_name, int vid)
if_request.cmd = ADD_VLAN_CMD;
if (ioctl(fd, SIOCSIFVLAN, &if_request) < 0) {
- perror("ioctl[SIOCSIFVLAN,ADD_VLAN_CMD]");
+ wpa_printf(MSG_ERROR, "VLAN: %s: ADD_VLAN_CMD failed for %s: "
+ "%s",
+ __func__, if_request.device1, strerror(errno));
close(fd);
return -1;
}
@@ -391,8 +449,11 @@ static int vlan_set_name_type(unsigned int name_type)
int fd;
struct vlan_ioctl_args if_request;
+ wpa_printf(MSG_DEBUG, "VLAN: vlan_set_name_type(name_type=%u)",
+ name_type);
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
- perror("socket[AF_INET,SOCK_STREAM]");
+ wpa_printf(MSG_ERROR, "VLAN: %s: socket(AF_INET,SOCK_STREAM) "
+ "failed: %s", __func__, strerror(errno));
return -1;
}
@@ -401,7 +462,9 @@ static int vlan_set_name_type(unsigned int name_type)
if_request.u.name_type = name_type;
if_request.cmd = SET_VLAN_NAME_TYPE_CMD;
if (ioctl(fd, SIOCSIFVLAN, &if_request) < 0) {
- perror("ioctl[SIOCSIFVLAN,SET_VLAN_NAME_TYPE_CMD]");
+ wpa_printf(MSG_ERROR, "VLAN: %s: SET_VLAN_NAME_TYPE_CMD "
+ "name_type=%u failed: %s",
+ __func__, name_type, strerror(errno));
close(fd);
return -1;
}
@@ -418,6 +481,8 @@ static void vlan_newlink(char *ifname, struct hostapd_data *hapd)
struct hostapd_vlan *vlan = hapd->conf->vlan;
char *tagged_interface = hapd->conf->ssid.vlan_tagged_interface;
+ wpa_printf(MSG_DEBUG, "VLAN: vlan_newlink(%s)", ifname);
+
while (vlan) {
if (os_strcmp(ifname, vlan->ifname) == 0) {
@@ -461,7 +526,8 @@ static void vlan_dellink(char *ifname, struct hostapd_data *hapd)
char br_name[IFNAMSIZ];
struct hostapd_vlan *first, *prev, *vlan = hapd->conf->vlan;
char *tagged_interface = hapd->conf->ssid.vlan_tagged_interface;
- int numports;
+
+ wpa_printf(MSG_DEBUG, "VLAN: vlan_dellink(%s)", ifname);
first = prev = vlan;
@@ -470,19 +536,24 @@ static void vlan_dellink(char *ifname, struct hostapd_data *hapd)
os_snprintf(br_name, sizeof(br_name), "brvlan%d",
vlan->vlan_id);
+ if (vlan->clean & DVLAN_CLEAN_WLAN_PORT)
+ br_delif(br_name, vlan->ifname);
+
if (tagged_interface) {
os_snprintf(vlan_ifname, sizeof(vlan_ifname),
"vlan%d", vlan->vlan_id);
-
- numports = br_getnumports(br_name);
- if (numports == 1) {
+ if (vlan->clean & DVLAN_CLEAN_VLAN_PORT)
br_delif(br_name, vlan_ifname);
+ ifconfig_down(vlan_ifname);
+ if (vlan->clean & DVLAN_CLEAN_VLAN)
vlan_rem(vlan_ifname);
+ }
- ifconfig_down(br_name);
- br_delbr(br_name);
- }
+ if ((vlan->clean & DVLAN_CLEAN_BR) &&
+ br_getnumports(br_name) == 0) {
+ ifconfig_down(br_name);
+ br_delbr(br_name);
}
if (vlan == first) {
@@ -561,7 +632,8 @@ static void vlan_event_receive(int sock, void *eloop_ctx, void *sock_ctx)
(struct sockaddr *) &from, &fromlen);
if (left < 0) {
if (errno != EINTR && errno != EAGAIN)
- perror("recvfrom(netlink)");
+ wpa_printf(MSG_ERROR, "VLAN: %s: recvfrom failed: %s",
+ __func__, strerror(errno));
return;
}
@@ -572,8 +644,9 @@ static void vlan_event_receive(int sock, void *eloop_ctx, void *sock_ctx)
len = h->nlmsg_len;
plen = len - sizeof(*h);
if (len > left || plen < 0) {
- printf("Malformed netlink message: "
- "len=%d left=%d plen=%d", len, left, plen);
+ wpa_printf(MSG_DEBUG, "VLAN: Malformed netlink "
+ "message: len=%d left=%d plen=%d",
+ len, left, plen);
break;
}
@@ -592,8 +665,8 @@ static void vlan_event_receive(int sock, void *eloop_ctx, void *sock_ctx)
}
if (left > 0) {
- printf("%d extra bytes in the end of netlink message",
- left);
+ wpa_printf(MSG_DEBUG, "VLAN: %s: %d extra bytes in the end of "
+ "netlink message", __func__, left);
}
}
@@ -612,7 +685,9 @@ full_dynamic_vlan_init(struct hostapd_data *hapd)
priv->s = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (priv->s < 0) {
- perror("socket(PF_NETLINK,SOCK_RAW,NETLINK_ROUTE)");
+ wpa_printf(MSG_ERROR, "VLAN: %s: socket(PF_NETLINK,SOCK_RAW,"
+ "NETLINK_ROUTE) failed: %s",
+ __func__, strerror(errno));
os_free(priv);
return NULL;
}
@@ -621,7 +696,8 @@ full_dynamic_vlan_init(struct hostapd_data *hapd)
local.nl_family = AF_NETLINK;
local.nl_groups = RTMGRP_LINK;
if (bind(priv->s, (struct sockaddr *) &local, sizeof(local)) < 0) {
- perror("bind(netlink)");
+ wpa_printf(MSG_ERROR, "VLAN: %s: bind(netlink) failed: %s",
+ __func__, strerror(errno));
close(priv->s);
os_free(priv);
return NULL;
@@ -661,12 +737,11 @@ int vlan_setup_encryption_dyn(struct hostapd_data *hapd,
* functions for setting up dynamic broadcast keys. */
for (i = 0; i < 4; i++) {
if (mssid->wep.key[i] &&
- hostapd_set_encryption(dyn_vlan, hapd, "WEP", NULL,
- i, mssid->wep.key[i],
- mssid->wep.len[i],
- i == mssid->wep.idx)) {
- printf("VLAN: Could not set WEP encryption for "
- "dynamic VLAN.\n");
+ hapd->drv.set_key(dyn_vlan, hapd, WPA_ALG_WEP, NULL, i,
+ i == mssid->wep.idx, NULL, 0,
+ mssid->wep.key[i], mssid->wep.len[i])) {
+ wpa_printf(MSG_ERROR, "VLAN: Could not set WEP "
+ "encryption for dynamic VLAN");
return -1;
}
}
@@ -679,14 +754,19 @@ static int vlan_dynamic_add(struct hostapd_data *hapd,
struct hostapd_vlan *vlan)
{
while (vlan) {
- if (vlan->vlan_id != VLAN_ID_WILDCARD &&
- hostapd_if_add(hapd, HOSTAPD_IF_VLAN, vlan->ifname, NULL))
- {
- if (errno != EEXIST) {
- printf("Could not add VLAN iface: %s: %s\n",
- vlan->ifname, strerror(errno));
- return -1;
+ if (vlan->vlan_id != VLAN_ID_WILDCARD) {
+ if (hapd->drv.vlan_if_add(hapd, vlan->ifname)) {
+ if (errno != EEXIST) {
+ wpa_printf(MSG_ERROR, "VLAN: Could "
+ "not add VLAN %s: %s",
+ vlan->ifname,
+ strerror(errno));
+ return -1;
+ }
}
+#ifdef CONFIG_FULL_DYNAMIC_VLAN
+ ifconfig_up(vlan->ifname);
+#endif /* CONFIG_FULL_DYNAMIC_VLAN */
}
vlan = vlan->next;
@@ -705,10 +785,10 @@ static void vlan_dynamic_remove(struct hostapd_data *hapd,
next = vlan->next;
if (vlan->vlan_id != VLAN_ID_WILDCARD &&
- hostapd_if_remove(hapd, HOSTAPD_IF_VLAN, vlan->ifname,
- NULL)) {
- printf("Could not remove VLAN iface: %s: %s\n",
- vlan->ifname, strerror(errno));
+ hapd->drv.vlan_if_remove(hapd, vlan->ifname)) {
+ wpa_printf(MSG_ERROR, "VLAN: Could not remove VLAN "
+ "iface: %s: %s",
+ vlan->ifname, strerror(errno));
}
#ifdef CONFIG_FULL_DYNAMIC_VLAN
if (vlan->clean)
@@ -722,13 +802,13 @@ static void vlan_dynamic_remove(struct hostapd_data *hapd,
int vlan_init(struct hostapd_data *hapd)
{
- if (vlan_dynamic_add(hapd, hapd->conf->vlan))
- return -1;
-
#ifdef CONFIG_FULL_DYNAMIC_VLAN
hapd->full_dynamic_vlan = full_dynamic_vlan_init(hapd);
#endif /* CONFIG_FULL_DYNAMIC_VLAN */
+ if (vlan_dynamic_add(hapd, hapd->conf->vlan))
+ return -1;
+
return 0;
}
@@ -743,17 +823,6 @@ void vlan_deinit(struct hostapd_data *hapd)
}
-int vlan_reconfig(struct hostapd_data *hapd, struct hostapd_config *oldconf,
- struct hostapd_bss_config *oldbss)
-{
- vlan_dynamic_remove(hapd, oldbss->vlan);
- if (vlan_dynamic_add(hapd, hapd->conf->vlan))
- return -1;
-
- return 0;
-}
-
-
struct hostapd_vlan * vlan_add_dynamic(struct hostapd_data *hapd,
struct hostapd_vlan *vlan,
int vlan_id)
@@ -765,6 +834,8 @@ struct hostapd_vlan * vlan_add_dynamic(struct hostapd_data *hapd,
vlan->vlan_id != VLAN_ID_WILDCARD)
return NULL;
+ wpa_printf(MSG_DEBUG, "VLAN: %s(vlan_id=%d ifname=%s)",
+ __func__, vlan_id, vlan->ifname);
ifname = os_strdup(vlan->ifname);
if (ifname == NULL)
return NULL;
@@ -788,7 +859,7 @@ struct hostapd_vlan * vlan_add_dynamic(struct hostapd_data *hapd,
pos);
os_free(ifname);
- if (hostapd_if_add(hapd, HOSTAPD_IF_VLAN, n->ifname, NULL)) {
+ if (hapd->drv.vlan_if_add(hapd, n->ifname)) {
os_free(n);
return NULL;
}
@@ -796,6 +867,10 @@ struct hostapd_vlan * vlan_add_dynamic(struct hostapd_data *hapd,
n->next = hapd->conf->vlan;
hapd->conf->vlan = n;
+#ifdef CONFIG_FULL_DYNAMIC_VLAN
+ ifconfig_up(n->ifname);
+#endif /* CONFIG_FULL_DYNAMIC_VLAN */
+
return n;
}
@@ -807,6 +882,8 @@ int vlan_remove_dynamic(struct hostapd_data *hapd, int vlan_id)
if (vlan_id <= 0 || vlan_id > MAX_VLAN_ID)
return 1;
+ wpa_printf(MSG_DEBUG, "VLAN: %s(vlan_id=%d)", __func__, vlan_id);
+
vlan = hapd->conf->vlan;
while (vlan) {
if (vlan->vlan_id == vlan_id && vlan->dynamic_vlan > 0) {
@@ -820,7 +897,7 @@ int vlan_remove_dynamic(struct hostapd_data *hapd, int vlan_id)
return 1;
if (vlan->dynamic_vlan == 0)
- hostapd_if_remove(hapd, HOSTAPD_IF_VLAN, vlan->ifname, NULL);
+ hapd->drv.vlan_if_remove(hapd, vlan->ifname);
return 0;
}
diff --git a/contrib/wpa/hostapd/vlan_init.h b/contrib/wpa/src/ap/vlan_init.h
index cf55ac2..382d5de 100644
--- a/contrib/wpa/hostapd/vlan_init.h
+++ b/contrib/wpa/src/ap/vlan_init.h
@@ -16,10 +16,9 @@
#ifndef VLAN_INIT_H
#define VLAN_INIT_H
+#ifndef CONFIG_NO_VLAN
int vlan_init(struct hostapd_data *hapd);
void vlan_deinit(struct hostapd_data *hapd);
-int vlan_reconfig(struct hostapd_data *hapd, struct hostapd_config *oldconf,
- struct hostapd_bss_config *oldbss);
struct hostapd_vlan * vlan_add_dynamic(struct hostapd_data *hapd,
struct hostapd_vlan *vlan,
int vlan_id);
@@ -27,5 +26,34 @@ int vlan_remove_dynamic(struct hostapd_data *hapd, int vlan_id);
int vlan_setup_encryption_dyn(struct hostapd_data *hapd,
struct hostapd_ssid *mssid,
const char *dyn_vlan);
+#else /* CONFIG_NO_VLAN */
+static inline int vlan_init(struct hostapd_data *hapd)
+{
+ return 0;
+}
+
+static inline void vlan_deinit(struct hostapd_data *hapd)
+{
+}
+
+static inline struct hostapd_vlan * vlan_add_dynamic(struct hostapd_data *hapd,
+ struct hostapd_vlan *vlan,
+ int vlan_id)
+{
+ return NULL;
+}
+
+static inline int vlan_remove_dynamic(struct hostapd_data *hapd, int vlan_id)
+{
+ return -1;
+}
+
+static inline int vlan_setup_encryption_dyn(struct hostapd_data *hapd,
+ struct hostapd_ssid *mssid,
+ const char *dyn_vlan)
+{
+ return -1;
+}
+#endif /* CONFIG_NO_VLAN */
#endif /* VLAN_INIT_H */
diff --git a/contrib/wpa/hostapd/wme.c b/contrib/wpa/src/ap/wmm.c
index f2bbbd9..3668130 100644
--- a/contrib/wpa/hostapd/wme.c
+++ b/contrib/wpa/src/ap/wmm.c
@@ -2,6 +2,7 @@
* hostapd / WMM (Wi-Fi Multimedia)
* Copyright 2002-2003, Instant802 Networks, Inc.
* Copyright 2005-2006, Devicescape Software, Inc.
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -13,13 +14,16 @@
* See README and COPYING for more details.
*/
-#include "includes.h"
+#include "utils/includes.h"
+#include "utils/common.h"
+#include "common/ieee802_11_defs.h"
+#include "common/ieee802_11_common.h"
#include "hostapd.h"
#include "ieee802_11.h"
-#include "wme.h"
#include "sta_info.h"
-#include "driver.h"
+#include "ap_config.h"
+#include "wmm.h"
/* TODO: maintain separate sequence and fragment numbers for each AC
@@ -67,6 +71,9 @@ u8 * hostapd_eid_wmm(struct hostapd_data *hapd, u8 *eid)
wmm->version = WMM_VERSION;
wmm->qos_info = hapd->parameter_set_count & 0xf;
+ if (hapd->conf->wmm_uapsd)
+ wmm->qos_info |= 0x80;
+
/* fill in a parameter set record for each AC */
for (e = 0; e < 4; e++) {
struct wmm_ac_parameter *ac = &wmm->ac[e];
@@ -90,7 +97,7 @@ u8 * hostapd_eid_wmm(struct hostapd_data *hapd, u8 *eid)
/* This function is called when a station sends an association request with
* WMM info element. The function returns zero on success or non-zero on any
* error in WMM element. eid does not include Element ID and Length octets. */
-int hostapd_eid_wmm_valid(struct hostapd_data *hapd, u8 *eid, size_t len)
+int hostapd_eid_wmm_valid(struct hostapd_data *hapd, const u8 *eid, size_t len)
{
struct wmm_information_element *wmm;
@@ -117,23 +124,6 @@ int hostapd_eid_wmm_valid(struct hostapd_data *hapd, u8 *eid, size_t len)
}
-/* This function is called when a station sends an ACK frame for an AssocResp
- * frame (status=success) and the matching AssocReq contained a WMM element.
- */
-int hostapd_wmm_sta_config(struct hostapd_data *hapd, struct sta_info *sta)
-{
- /* update kernel STA data for WMM related items (WLAN_STA_WPA flag) */
- if (sta->flags & WLAN_STA_WMM)
- hostapd_sta_set_flags(hapd, sta->addr, sta->flags,
- WLAN_STA_WMM, ~0);
- else
- hostapd_sta_set_flags(hapd, sta->addr, sta->flags,
- 0, ~WLAN_STA_WMM);
-
- return 0;
-}
-
-
static void wmm_send_action(struct hostapd_data *hapd, const u8 *addr,
const struct wmm_tspec_element *tspec,
u8 action_code, u8 dialogue_token, u8 status_code)
@@ -160,30 +150,17 @@ static void wmm_send_action(struct hostapd_data *hapd, const u8 *addr,
os_memcpy(t, tspec, sizeof(struct wmm_tspec_element));
len = ((u8 *) (t + 1)) - buf;
- if (hostapd_send_mgmt_frame(hapd, m, len, 0) < 0)
+ if (hapd->drv.send_mgmt_frame(hapd, m, len) < 0)
perror("wmm_send_action: send");
}
-static void wmm_addts_req(struct hostapd_data *hapd,
- struct ieee80211_mgmt *mgmt,
- struct wmm_tspec_element *tspec, size_t len)
+int wmm_process_tspec(struct wmm_tspec_element *tspec)
{
- u8 *end = ((u8 *) mgmt) + len;
int medium_time, pps, duration;
int up, psb, dir, tid;
u16 val, surplus;
- if ((u8 *) (tspec + 1) > end) {
- wpa_printf(MSG_DEBUG, "WMM: TSPEC overflow in ADDTS Request");
- return;
- }
-
- wpa_printf(MSG_DEBUG, "WMM: ADDTS Request (Dialog Token %d) for TSPEC "
- "from " MACSTR,
- mgmt->u.action.u.wmm_action.dialog_token,
- MAC2STR(mgmt->sa));
-
up = (tspec->ts_info[1] >> 3) & 0x07;
psb = (tspec->ts_info[1] >> 2) & 0x01;
dir = (tspec->ts_info[0] >> 5) & 0x03;
@@ -204,7 +181,7 @@ static void wmm_addts_req(struct hostapd_data *hapd,
val = le_to_host16(tspec->nominal_msdu_size);
if (val == 0) {
wpa_printf(MSG_DEBUG, "WMM: Invalid Nominal MSDU Size (0)");
- goto invalid;
+ return WMM_ADDTS_STATUS_INVALID_PARAMETERS;
}
/* pps = Ceiling((Mean Data Rate / 8) / Nominal MSDU Size) */
pps = ((le_to_host32(tspec->mean_data_rate) / 8) + val - 1) / val;
@@ -213,7 +190,7 @@ static void wmm_addts_req(struct hostapd_data *hapd,
if (le_to_host32(tspec->minimum_phy_rate) < 1000000) {
wpa_printf(MSG_DEBUG, "WMM: Too small Minimum PHY Rate");
- goto invalid;
+ return WMM_ADDTS_STATUS_INVALID_PARAMETERS;
}
duration = (le_to_host16(tspec->nominal_msdu_size) & 0x7fff) * 8 /
@@ -226,7 +203,7 @@ static void wmm_addts_req(struct hostapd_data *hapd,
if (surplus <= 0x2000) {
wpa_printf(MSG_DEBUG, "WMM: Surplus Bandwidth Allowance not "
"greater than unity");
- goto invalid;
+ return WMM_ADDTS_STATUS_INVALID_PARAMETERS;
}
medium_time = surplus * pps * duration / 0x2000;
@@ -241,35 +218,47 @@ static void wmm_addts_req(struct hostapd_data *hapd,
if (medium_time > 750000) {
wpa_printf(MSG_DEBUG, "WMM: Refuse TSPEC request for over "
"75%% of available bandwidth");
- wmm_send_action(hapd, mgmt->sa, tspec,
- WMM_ACTION_CODE_ADDTS_RESP,
- mgmt->u.action.u.wmm_action.dialog_token,
- WMM_ADDTS_STATUS_REFUSED);
- return;
+ return WMM_ADDTS_STATUS_REFUSED;
}
/* Convert to 32 microseconds per second unit */
tspec->medium_time = host_to_le16(medium_time / 32);
+ return WMM_ADDTS_STATUS_ADMISSION_ACCEPTED;
+}
+
+
+static void wmm_addts_req(struct hostapd_data *hapd,
+ const struct ieee80211_mgmt *mgmt,
+ struct wmm_tspec_element *tspec, size_t len)
+{
+ const u8 *end = ((const u8 *) mgmt) + len;
+ int res;
+
+ if ((const u8 *) (tspec + 1) > end) {
+ wpa_printf(MSG_DEBUG, "WMM: TSPEC overflow in ADDTS Request");
+ return;
+ }
+
+ wpa_printf(MSG_DEBUG, "WMM: ADDTS Request (Dialog Token %d) for TSPEC "
+ "from " MACSTR,
+ mgmt->u.action.u.wmm_action.dialog_token,
+ MAC2STR(mgmt->sa));
+
+ res = wmm_process_tspec(tspec);
+ wpa_printf(MSG_DEBUG, "WMM: ADDTS processing result: %d", res);
+
wmm_send_action(hapd, mgmt->sa, tspec, WMM_ACTION_CODE_ADDTS_RESP,
- mgmt->u.action.u.wmm_action.dialog_token,
- WMM_ADDTS_STATUS_ADMISSION_ACCEPTED);
- return;
-
-invalid:
- wmm_send_action(hapd, mgmt->sa, tspec,
- WMM_ACTION_CODE_ADDTS_RESP,
- mgmt->u.action.u.wmm_action.dialog_token,
- WMM_ADDTS_STATUS_INVALID_PARAMETERS);
+ mgmt->u.action.u.wmm_action.dialog_token, res);
}
-void hostapd_wmm_action(struct hostapd_data *hapd, struct ieee80211_mgmt *mgmt,
- size_t len)
+void hostapd_wmm_action(struct hostapd_data *hapd,
+ const struct ieee80211_mgmt *mgmt, size_t len)
{
int action_code;
int left = len - IEEE80211_HDRLEN - 4;
- u8 *pos = ((u8 *) mgmt) + IEEE80211_HDRLEN + 4;
+ const u8 *pos = ((const u8 *) mgmt) + IEEE80211_HDRLEN + 4;
struct ieee802_11_elems elems;
struct sta_info *sta = ap_get_sta(hapd, mgmt->sa);
diff --git a/contrib/wpa/src/ap/wmm.h b/contrib/wpa/src/ap/wmm.h
new file mode 100644
index 0000000..96b04e8
--- /dev/null
+++ b/contrib/wpa/src/ap/wmm.h
@@ -0,0 +1,29 @@
+/*
+ * hostapd / WMM (Wi-Fi Multimedia)
+ * Copyright 2002-2003, Instant802 Networks, Inc.
+ * Copyright 2005-2006, Devicescape Software, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef WME_H
+#define WME_H
+
+struct ieee80211_mgmt;
+struct wmm_tspec_element;
+
+u8 * hostapd_eid_wmm(struct hostapd_data *hapd, u8 *eid);
+int hostapd_eid_wmm_valid(struct hostapd_data *hapd, const u8 *eid,
+ size_t len);
+void hostapd_wmm_action(struct hostapd_data *hapd,
+ const struct ieee80211_mgmt *mgmt, size_t len);
+int wmm_process_tspec(struct wmm_tspec_element *tspec);
+
+#endif /* WME_H */
diff --git a/contrib/wpa/hostapd/wpa.c b/contrib/wpa/src/ap/wpa_auth.c
index 19b11d5..36cb0f4 100644
--- a/contrib/wpa/hostapd/wpa.c
+++ b/contrib/wpa/src/ap/wpa_auth.c
@@ -12,23 +12,21 @@
* See README and COPYING for more details.
*/
-#include "includes.h"
-
-#ifndef CONFIG_NATIVE_WINDOWS
-
-#include "common.h"
-#include "config.h"
-#include "eapol_sm.h"
-#include "wpa.h"
-#include "sha1.h"
-#include "sha256.h"
-#include "rc4.h"
-#include "aes_wrap.h"
-#include "crypto.h"
-#include "eloop.h"
+#include "utils/includes.h"
+
+#include "utils/common.h"
+#include "utils/eloop.h"
+#include "utils/state_machine.h"
+#include "common/ieee802_11_defs.h"
+#include "crypto/aes_wrap.h"
+#include "crypto/crypto.h"
+#include "crypto/sha1.h"
+#include "crypto/sha256.h"
+#include "eapol_auth/eapol_auth_sm.h"
+#include "ap_config.h"
#include "ieee802_11.h"
-#include "pmksa_cache.h"
-#include "state_machine.h"
+#include "wpa_auth.h"
+#include "pmksa_cache_auth.h"
#include "wpa_auth_i.h"
#include "wpa_auth_ie.h"
@@ -38,7 +36,7 @@
static void wpa_send_eapol_timeout(void *eloop_ctx, void *timeout_ctx);
-static void wpa_sm_step(struct wpa_state_machine *sm);
+static int wpa_sm_step(struct wpa_state_machine *sm);
static int wpa_verify_key_mic(struct wpa_ptk *PTK, u8 *data, size_t data_len);
static void wpa_sm_call_step(void *eloop_ctx, void *timeout_ctx);
static void wpa_group_sm_step(struct wpa_authenticator *wpa_auth,
@@ -104,7 +102,7 @@ static inline int wpa_auth_get_msk(struct wpa_authenticator *wpa_auth,
static inline int wpa_auth_set_key(struct wpa_authenticator *wpa_auth,
int vlan_id,
- const char *alg, const u8 *addr, int idx,
+ enum wpa_alg alg, const u8 *addr, int idx,
u8 *key, size_t key_len)
{
if (wpa_auth->cb.set_key == NULL)
@@ -123,15 +121,6 @@ static inline int wpa_auth_get_seqnum(struct wpa_authenticator *wpa_auth,
}
-static inline int wpa_auth_get_seqnum_igtk(struct wpa_authenticator *wpa_auth,
- const u8 *addr, int idx, u8 *seq)
-{
- if (wpa_auth->cb.get_seqnum_igtk == NULL)
- return -1;
- return wpa_auth->cb.get_seqnum_igtk(wpa_auth->cb.ctx, addr, idx, seq);
-}
-
-
static inline int
wpa_auth_send_eapol(struct wpa_authenticator *wpa_auth, const u8 *addr,
const u8 *data, size_t data_len, int encrypt)
@@ -382,7 +371,8 @@ struct wpa_authenticator * wpa_init(const u8 *addr,
return NULL;
}
- wpa_auth->pmksa = pmksa_cache_init(wpa_auth_pmksa_free_cb, wpa_auth);
+ wpa_auth->pmksa = pmksa_cache_auth_init(wpa_auth_pmksa_free_cb,
+ wpa_auth);
if (wpa_auth->pmksa == NULL) {
wpa_printf(MSG_ERROR, "PMKSA cache initialization failed.");
os_free(wpa_auth->wpa_ie);
@@ -395,7 +385,7 @@ struct wpa_authenticator * wpa_init(const u8 *addr,
if (wpa_auth->ft_pmk_cache == NULL) {
wpa_printf(MSG_ERROR, "FT PMK cache initialization failed.");
os_free(wpa_auth->wpa_ie);
- pmksa_cache_deinit(wpa_auth->pmksa);
+ pmksa_cache_auth_deinit(wpa_auth->pmksa);
os_free(wpa_auth);
return NULL;
}
@@ -431,7 +421,7 @@ void wpa_deinit(struct wpa_authenticator *wpa_auth)
wpa_stsl_remove(wpa_auth, wpa_auth->stsl_negotiations);
#endif /* CONFIG_PEERKEY */
- pmksa_cache_deinit(wpa_auth->pmksa);
+ pmksa_cache_auth_deinit(wpa_auth->pmksa);
#ifdef CONFIG_IEEE80211R
wpa_ft_pmk_cache_deinit(wpa_auth->ft_pmk_cache);
@@ -501,26 +491,25 @@ wpa_auth_sta_init(struct wpa_authenticator *wpa_auth, const u8 *addr)
}
-void wpa_auth_sta_associated(struct wpa_authenticator *wpa_auth,
- struct wpa_state_machine *sm)
+int wpa_auth_sta_associated(struct wpa_authenticator *wpa_auth,
+ struct wpa_state_machine *sm)
{
if (wpa_auth == NULL || !wpa_auth->conf.wpa || sm == NULL)
- return;
+ return -1;
#ifdef CONFIG_IEEE80211R
if (sm->ft_completed) {
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_DEBUG,
"FT authentication already completed - do not "
"start 4-way handshake");
- return;
+ return 0;
}
#endif /* CONFIG_IEEE80211R */
if (sm->started) {
os_memset(&sm->key_replay, 0, sizeof(sm->key_replay));
sm->ReAuthenticationRequest = TRUE;
- wpa_sm_step(sm);
- return;
+ return wpa_sm_step(sm);
}
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_DEBUG,
@@ -528,10 +517,11 @@ void wpa_auth_sta_associated(struct wpa_authenticator *wpa_auth,
sm->started = 1;
sm->Init = TRUE;
- wpa_sm_step(sm);
+ if (wpa_sm_step(sm) == 1)
+ return 1; /* should not really happen */
sm->Init = FALSE;
sm->AuthenticationRequest = TRUE;
- wpa_sm_step(sm);
+ return wpa_sm_step(sm);
}
@@ -549,6 +539,9 @@ void wpa_auth_sta_no_wpa(struct wpa_state_machine *sm)
static void wpa_free_sta_sm(struct wpa_state_machine *sm)
{
+#ifdef CONFIG_IEEE80211R
+ os_free(sm->assoc_resp_ftie);
+#endif /* CONFIG_IEEE80211R */
os_free(sm->last_rx_eapol_key);
os_free(sm->wpa_ie);
os_free(sm);
@@ -608,6 +601,56 @@ static int wpa_replay_counter_valid(struct wpa_state_machine *sm,
}
+#ifdef CONFIG_IEEE80211R
+static int ft_check_msg_2_of_4(struct wpa_authenticator *wpa_auth,
+ struct wpa_state_machine *sm,
+ struct wpa_eapol_ie_parse *kde)
+{
+ struct wpa_ie_data ie;
+ struct rsn_mdie *mdie;
+
+ if (wpa_parse_wpa_ie_rsn(kde->rsn_ie, kde->rsn_ie_len, &ie) < 0 ||
+ ie.num_pmkid != 1 || ie.pmkid == NULL) {
+ wpa_printf(MSG_DEBUG, "FT: No PMKR1Name in "
+ "FT 4-way handshake message 2/4");
+ return -1;
+ }
+
+ os_memcpy(sm->sup_pmk_r1_name, ie.pmkid, PMKID_LEN);
+ wpa_hexdump(MSG_DEBUG, "FT: PMKR1Name from Supplicant",
+ sm->sup_pmk_r1_name, PMKID_LEN);
+
+ if (!kde->mdie || !kde->ftie) {
+ wpa_printf(MSG_DEBUG, "FT: No %s in FT 4-way handshake "
+ "message 2/4", kde->mdie ? "FTIE" : "MDIE");
+ return -1;
+ }
+
+ mdie = (struct rsn_mdie *) (kde->mdie + 2);
+ if (kde->mdie[1] < sizeof(struct rsn_mdie) ||
+ os_memcmp(wpa_auth->conf.mobility_domain, mdie->mobility_domain,
+ MOBILITY_DOMAIN_ID_LEN) != 0) {
+ wpa_printf(MSG_DEBUG, "FT: MDIE mismatch");
+ return -1;
+ }
+
+ if (sm->assoc_resp_ftie &&
+ (kde->ftie[1] != sm->assoc_resp_ftie[1] ||
+ os_memcmp(kde->ftie, sm->assoc_resp_ftie,
+ 2 + sm->assoc_resp_ftie[1]) != 0)) {
+ wpa_printf(MSG_DEBUG, "FT: FTIE mismatch");
+ wpa_hexdump(MSG_DEBUG, "FT: FTIE in EAPOL-Key msg 2/4",
+ kde->ftie, kde->ftie_len);
+ wpa_hexdump(MSG_DEBUG, "FT: FTIE in (Re)AssocResp",
+ sm->assoc_resp_ftie, 2 + sm->assoc_resp_ftie[1]);
+ return -1;
+ }
+
+ return 0;
+}
+#endif /* CONFIG_IEEE80211R */
+
+
void wpa_receive(struct wpa_authenticator *wpa_auth,
struct wpa_state_machine *sm,
u8 *data, size_t data_len)
@@ -619,6 +662,9 @@ void wpa_receive(struct wpa_authenticator *wpa_auth,
SMK_M1, SMK_M3, SMK_ERROR } msg;
char *msgtxt;
struct wpa_eapol_ie_parse kde;
+ int ft;
+ const u8 *eapol_key_ie;
+ size_t eapol_key_ie_len;
if (wpa_auth == NULL || !wpa_auth->conf.wpa || sm == NULL)
return;
@@ -749,9 +795,26 @@ void wpa_receive(struct wpa_authenticator *wpa_auth,
sm->wpa_ptk_state);
return;
}
+ if (wpa_parse_kde_ies((u8 *) (key + 1), key_data_length,
+ &kde) < 0) {
+ wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_INFO,
+ "received EAPOL-Key msg 2/4 with "
+ "invalid Key Data contents");
+ return;
+ }
+ if (kde.rsn_ie) {
+ eapol_key_ie = kde.rsn_ie;
+ eapol_key_ie_len = kde.rsn_ie_len;
+ } else {
+ eapol_key_ie = kde.wpa_ie;
+ eapol_key_ie_len = kde.wpa_ie_len;
+ }
+ ft = sm->wpa == WPA_VERSION_WPA2 &&
+ wpa_key_mgmt_ft(sm->wpa_key_mgmt);
if (sm->wpa_ie == NULL ||
- sm->wpa_ie_len != key_data_length ||
- os_memcmp(sm->wpa_ie, key + 1, key_data_length) != 0) {
+ wpa_compare_rsn_ie(ft,
+ sm->wpa_ie, sm->wpa_ie_len,
+ eapol_key_ie, eapol_key_ie_len)) {
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
"WPA IE from (Re)AssocReq did not "
"match with msg 2/4");
@@ -760,11 +823,17 @@ void wpa_receive(struct wpa_authenticator *wpa_auth,
sm->wpa_ie, sm->wpa_ie_len);
}
wpa_hexdump(MSG_DEBUG, "WPA IE in msg 2/4",
- (u8 *) (key + 1), key_data_length);
+ eapol_key_ie, eapol_key_ie_len);
/* MLME-DEAUTHENTICATE.request */
wpa_sta_disconnect(wpa_auth, sm->addr);
return;
}
+#ifdef CONFIG_IEEE80211R
+ if (ft && ft_check_msg_2_of_4(wpa_auth, sm, &kde) < 0) {
+ wpa_sta_disconnect(wpa_auth, sm->addr);
+ return;
+ }
+#endif /* CONFIG_IEEE80211R */
break;
case PAIRWISE_4:
if (sm->wpa_ptk_state != WPA_PTK_PTKINITNEGOTIATING ||
@@ -1178,18 +1247,19 @@ void wpa_remove_ptk(struct wpa_state_machine *sm)
{
sm->PTK_valid = FALSE;
os_memset(&sm->PTK, 0, sizeof(sm->PTK));
- wpa_auth_set_key(sm->wpa_auth, 0, "none", sm->addr, 0, (u8 *) "", 0);
+ wpa_auth_set_key(sm->wpa_auth, 0, WPA_ALG_NONE, sm->addr, 0, (u8 *) "",
+ 0);
sm->pairwise_set = FALSE;
eloop_cancel_timeout(wpa_rekey_ptk, sm->wpa_auth, sm);
}
-void wpa_auth_sm_event(struct wpa_state_machine *sm, wpa_event event)
+int wpa_auth_sm_event(struct wpa_state_machine *sm, wpa_event event)
{
int remove_ptk = 1;
if (sm == NULL)
- return;
+ return -1;
wpa_auth_vlogger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
"event %d notification", event);
@@ -1204,6 +1274,24 @@ void wpa_auth_sm_event(struct wpa_state_machine *sm, wpa_event event)
break;
case WPA_REAUTH:
case WPA_REAUTH_EAPOL:
+ if (!sm->started) {
+ /*
+ * When using WPS, we may end up here if the STA
+ * manages to re-associate without the previous STA
+ * entry getting removed. Consequently, we need to make
+ * sure that the WPA state machines gets initialized
+ * properly at this point.
+ */
+ wpa_printf(MSG_DEBUG, "WPA state machine had not been "
+ "started - initialize now");
+ sm->started = 1;
+ sm->Init = TRUE;
+ if (wpa_sm_step(sm) == 1)
+ return 1; /* should not really happen */
+ sm->Init = FALSE;
+ sm->AuthenticationRequest = TRUE;
+ break;
+ }
if (sm->GUpdateStationKeys) {
/*
* Reauthentication cancels the pending group key
@@ -1217,9 +1305,13 @@ void wpa_auth_sm_event(struct wpa_state_machine *sm, wpa_event event)
break;
case WPA_ASSOC_FT:
#ifdef CONFIG_IEEE80211R
+ wpa_printf(MSG_DEBUG, "FT: Retry PTK configuration "
+ "after association");
+ wpa_ft_install_ptk(sm);
+
/* Using FT protocol, not WPA auth state machine */
sm->ft_completed = 1;
- return;
+ return 0;
#else /* CONFIG_IEEE80211R */
break;
#endif /* CONFIG_IEEE80211R */
@@ -1242,22 +1334,22 @@ void wpa_auth_sm_event(struct wpa_state_machine *sm, wpa_event event)
wpa_remove_ptk(sm);
}
- wpa_sm_step(sm);
+ return wpa_sm_step(sm);
}
-static const char * wpa_alg_txt(int alg)
+static enum wpa_alg wpa_alg_enum(int alg)
{
switch (alg) {
case WPA_CIPHER_CCMP:
- return "CCMP";
+ return WPA_ALG_CCMP;
case WPA_CIPHER_TKIP:
- return "TKIP";
+ return WPA_ALG_TKIP;
case WPA_CIPHER_WEP104:
case WPA_CIPHER_WEP40:
- return "WEP";
+ return WPA_ALG_WEP;
default:
- return "";
+ return WPA_ALG_NONE;
}
}
@@ -1492,6 +1584,27 @@ SM_STATE(WPA_PTK, PTKCALCNEGOTIATING)
return;
}
+#ifdef CONFIG_IEEE80211R
+ if (sm->wpa == WPA_VERSION_WPA2 && wpa_key_mgmt_ft(sm->wpa_key_mgmt)) {
+ /*
+ * Verify that PMKR1Name from EAPOL-Key message 2/4 matches
+ * with the value we derived.
+ */
+ if (os_memcmp(sm->sup_pmk_r1_name, sm->pmk_r1_name,
+ WPA_PMK_NAME_LEN) != 0) {
+ wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
+ "PMKR1Name mismatch in FT 4-way "
+ "handshake");
+ wpa_hexdump(MSG_DEBUG, "FT: PMKR1Name from "
+ "Supplicant",
+ sm->sup_pmk_r1_name, WPA_PMK_NAME_LEN);
+ wpa_hexdump(MSG_DEBUG, "FT: Derived PMKR1Name",
+ sm->pmk_r1_name, WPA_PMK_NAME_LEN);
+ return;
+ }
+ }
+#endif /* CONFIG_IEEE80211R */
+
eloop_cancel_timeout(wpa_send_eapol_timeout, sm->wpa_auth, sm);
if (wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt)) {
@@ -1537,8 +1650,8 @@ static u8 * ieee80211w_kde_add(struct wpa_state_machine *sm, u8 *pos)
igtk.keyid[0] = gsm->GN_igtk;
igtk.keyid[1] = 0;
- if (wpa_auth_get_seqnum_igtk(sm->wpa_auth, NULL, gsm->GN_igtk, igtk.pn)
- < 0)
+ if (gsm->wpa_group_state != WPA_GROUP_SETKEYSDONE ||
+ wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN_igtk, igtk.pn) < 0)
os_memset(igtk.pn, 0, sizeof(igtk.pn));
os_memcpy(igtk.igtk, gsm->IGTK[gsm->GN_igtk - 4], WPA_IGTK_LEN);
pos = wpa_add_kde(pos, RSN_KEY_DATA_IGTK,
@@ -1581,10 +1694,12 @@ SM_STATE(WPA_PTK, PTKINITNEGOTIATING)
return;
}
- /* Send EAPOL(1, 1, 1, Pair, P, RSC, ANonce, MIC(PTK), RSNIE, GTK[GN])
+ /* Send EAPOL(1, 1, 1, Pair, P, RSC, ANonce, MIC(PTK), RSNIE, [MDIE],
+ GTK[GN], IGTK, [FTIE], [TIE * 2])
*/
os_memset(rsc, 0, WPA_KEY_RSC_LEN);
wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN, rsc);
+ /* If FT is used, wpa_auth->wpa_ie includes both RSNIE and MDIE */
wpa_ie = sm->wpa_auth->wpa_ie;
wpa_ie_len = sm->wpa_auth->wpa_ie_len;
if (sm->wpa == WPA_VERSION_WPA &&
@@ -1616,6 +1731,12 @@ SM_STATE(WPA_PTK, PTKINITNEGOTIATING)
kde_len = wpa_ie_len + ieee80211w_kde_len(sm);
if (gtk)
kde_len += 2 + RSN_SELECTOR_LEN + 2 + gtk_len;
+#ifdef CONFIG_IEEE80211R
+ if (wpa_key_mgmt_ft(sm->wpa_key_mgmt)) {
+ kde_len += 2 + PMKID_LEN; /* PMKR1Name into RSN IE */
+ kde_len += 300; /* FTIE + 2 * TIE */
+ }
+#endif /* CONFIG_IEEE80211R */
kde = os_malloc(kde_len);
if (kde == NULL)
return;
@@ -1623,6 +1744,18 @@ SM_STATE(WPA_PTK, PTKINITNEGOTIATING)
pos = kde;
os_memcpy(pos, wpa_ie, wpa_ie_len);
pos += wpa_ie_len;
+#ifdef CONFIG_IEEE80211R
+ if (wpa_key_mgmt_ft(sm->wpa_key_mgmt)) {
+ int res = wpa_insert_pmkid(kde, pos - kde, sm->pmk_r1_name);
+ if (res < 0) {
+ wpa_printf(MSG_ERROR, "FT: Failed to insert "
+ "PMKR1Name into RSN IE in EAPOL-Key data");
+ os_free(kde);
+ return;
+ }
+ pos += res;
+ }
+#endif /* CONFIG_IEEE80211R */
if (gtk) {
u8 hdr[2];
hdr[0] = keyidx & 0x03;
@@ -1632,6 +1765,40 @@ SM_STATE(WPA_PTK, PTKINITNEGOTIATING)
}
pos = ieee80211w_kde_add(sm, pos);
+#ifdef CONFIG_IEEE80211R
+ if (wpa_key_mgmt_ft(sm->wpa_key_mgmt)) {
+ int res;
+ struct wpa_auth_config *conf;
+
+ conf = &sm->wpa_auth->conf;
+ res = wpa_write_ftie(conf, conf->r0_key_holder,
+ conf->r0_key_holder_len,
+ NULL, NULL, pos, kde + kde_len - pos,
+ NULL, 0);
+ if (res < 0) {
+ wpa_printf(MSG_ERROR, "FT: Failed to insert FTIE "
+ "into EAPOL-Key Key Data");
+ os_free(kde);
+ return;
+ }
+ pos += res;
+
+ /* TIE[ReassociationDeadline] (TU) */
+ *pos++ = WLAN_EID_TIMEOUT_INTERVAL;
+ *pos++ = 5;
+ *pos++ = WLAN_TIMEOUT_REASSOC_DEADLINE;
+ WPA_PUT_LE32(pos, conf->reassociation_deadline);
+ pos += 4;
+
+ /* TIE[KeyLifetime] (seconds) */
+ *pos++ = WLAN_EID_TIMEOUT_INTERVAL;
+ *pos++ = 5;
+ *pos++ = WLAN_TIMEOUT_KEY_LIFETIME;
+ WPA_PUT_LE32(pos, conf->r0_key_lifetime * 60);
+ pos += 4;
+ }
+#endif /* CONFIG_IEEE80211R */
+
wpa_send_eapol(sm->wpa_auth, sm,
(secure ? WPA_KEY_INFO_SECURE : 0) | WPA_KEY_INFO_MIC |
WPA_KEY_INFO_ACK | WPA_KEY_INFO_INSTALL |
@@ -1646,13 +1813,13 @@ SM_STATE(WPA_PTK, PTKINITDONE)
SM_ENTRY_MA(WPA_PTK, PTKINITDONE, wpa_ptk);
sm->EAPOLKeyReceived = FALSE;
if (sm->Pair) {
- char *alg;
+ enum wpa_alg alg;
int klen;
if (sm->pairwise == WPA_CIPHER_TKIP) {
- alg = "TKIP";
+ alg = WPA_ALG_TKIP;
klen = 32;
} else {
- alg = "CCMP";
+ alg = WPA_ALG_CCMP;
klen = 16;
}
if (wpa_auth_set_key(sm->wpa_auth, 0, alg, sm->addr, 0,
@@ -1934,7 +2101,7 @@ static int wpa_gtk_update(struct wpa_authenticator *wpa_auth,
group->GTK[group->GN - 1], group->GTK_len);
#ifdef CONFIG_IEEE80211W
- if (wpa_auth->conf.ieee80211w != WPA_NO_IEEE80211W) {
+ if (wpa_auth->conf.ieee80211w != NO_MGMT_FRAME_PROTECTION) {
if (os_get_random(group->IGTK[group->GN_igtk - 4],
WPA_IGTK_LEN) < 0) {
wpa_printf(MSG_INFO, "RSN: Failed to get new random "
@@ -2032,13 +2199,13 @@ static void wpa_group_setkeysdone(struct wpa_authenticator *wpa_auth,
group->changed = TRUE;
group->wpa_group_state = WPA_GROUP_SETKEYSDONE;
wpa_auth_set_key(wpa_auth, group->vlan_id,
- wpa_alg_txt(wpa_auth->conf.wpa_group),
+ wpa_alg_enum(wpa_auth->conf.wpa_group),
NULL, group->GN, group->GTK[group->GN - 1],
group->GTK_len);
#ifdef CONFIG_IEEE80211W
- if (wpa_auth->conf.ieee80211w != WPA_NO_IEEE80211W) {
- wpa_auth_set_key(wpa_auth, group->vlan_id, "IGTK",
+ if (wpa_auth->conf.ieee80211w != NO_MGMT_FRAME_PROTECTION) {
+ wpa_auth_set_key(wpa_auth, group->vlan_id, WPA_ALG_IGTK,
NULL, group->GN_igtk,
group->IGTK[group->GN_igtk - 4],
WPA_IGTK_LEN);
@@ -2067,17 +2234,17 @@ static void wpa_group_sm_step(struct wpa_authenticator *wpa_auth,
}
-static void wpa_sm_step(struct wpa_state_machine *sm)
+static int wpa_sm_step(struct wpa_state_machine *sm)
{
if (sm == NULL)
- return;
+ return 0;
if (sm->in_step_loop) {
/* This should not happen, but if it does, make sure we do not
* end up freeing the state machine too early by exiting the
* recursive call. */
wpa_printf(MSG_ERROR, "WPA: wpa_sm_step() called recursively");
- return;
+ return 0;
}
sm->in_step_loop = 1;
@@ -2102,7 +2269,9 @@ static void wpa_sm_step(struct wpa_state_machine *sm)
wpa_printf(MSG_DEBUG, "WPA: Completing pending STA state "
"machine deinit for " MACSTR, MAC2STR(sm->addr));
wpa_free_sta_sm(sm);
+ return 1;
}
+ return 0;
}
@@ -2404,9 +2573,9 @@ int wpa_auth_pmksa_add(struct wpa_state_machine *sm, const u8 *pmk,
if (sm == NULL || sm->wpa != WPA_VERSION_WPA2)
return -1;
- if (pmksa_cache_add(sm->wpa_auth->pmksa, pmk, PMK_LEN,
- sm->wpa_auth->addr, sm->addr, session_timeout,
- eapol, sm->wpa_key_mgmt))
+ if (pmksa_cache_auth_add(sm->wpa_auth->pmksa, pmk, PMK_LEN,
+ sm->wpa_auth->addr, sm->addr, session_timeout,
+ eapol, sm->wpa_key_mgmt))
return 0;
return -1;
@@ -2421,9 +2590,9 @@ int wpa_auth_pmksa_add_preauth(struct wpa_authenticator *wpa_auth,
if (wpa_auth == NULL)
return -1;
- if (pmksa_cache_add(wpa_auth->pmksa, pmk, len, wpa_auth->addr,
- sta_addr, session_timeout, eapol,
- WPA_KEY_MGMT_IEEE8021X))
+ if (pmksa_cache_auth_add(wpa_auth->pmksa, pmk, len, wpa_auth->addr,
+ sta_addr, session_timeout, eapol,
+ WPA_KEY_MGMT_IEEE8021X))
return 0;
return -1;
@@ -2480,5 +2649,3 @@ int wpa_auth_sta_set_vlan(struct wpa_state_machine *sm, int vlan_id)
sm->group = group;
return 0;
}
-
-#endif /* CONFIG_NATIVE_WINDOWS */
diff --git a/contrib/wpa/hostapd/wpa.h b/contrib/wpa/src/ap/wpa_auth.h
index 7d9b3d3..d0136c7 100644
--- a/contrib/wpa/hostapd/wpa.h
+++ b/contrib/wpa/src/ap/wpa_auth.h
@@ -15,8 +15,9 @@
#ifndef WPA_AUTH_H
#define WPA_AUTH_H
-#include "eapol_common.h"
-#include "wpa_common.h"
+#include "common/defs.h"
+#include "common/eapol_common.h"
+#include "common/wpa_common.h"
#ifdef _MSC_VER
#pragma pack(push, 1)
@@ -44,13 +45,9 @@ struct ft_rrb_frame {
#define FT_PACKET_R0KH_R1KH_RESP 201
#define FT_PACKET_R0KH_R1KH_PUSH 202
-#ifndef ETH_P_RRB
-#define ETH_P_RRB 0x890D
-#endif /* ETH_P_RRB */
-
#define FT_R0KH_R1KH_PULL_DATA_LEN 44
#define FT_R0KH_R1KH_RESP_DATA_LEN 76
-#define FT_R0KH_R1KH_PUSH_DATA_LEN 80
+#define FT_R0KH_R1KH_PUSH_DATA_LEN 88
struct ft_r0kh_r1kh_pull_frame {
u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */
@@ -77,14 +74,15 @@ struct ft_r0kh_r1kh_resp_frame {
u8 s1kh_id[ETH_ALEN]; /* copied from pull */
u8 pmk_r1[PMK_LEN];
u8 pmk_r1_name[WPA_PMK_NAME_LEN];
- u8 pad[4]; /* 8-octet boundary for AES key wrap */
+ le16 pairwise;
+ u8 pad[2]; /* 8-octet boundary for AES key wrap */
u8 key_wrap_extra[8];
} STRUCT_PACKED;
struct ft_r0kh_r1kh_push_frame {
u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */
u8 packet_type; /* FT_PACKET_R0KH_R1KH_PUSH */
- le16 data_length; /* little endian length of data (80) */
+ le16 data_length; /* little endian length of data (88) */
u8 ap_address[ETH_ALEN];
/* Encrypted with AES key-wrap */
@@ -95,6 +93,8 @@ struct ft_r0kh_r1kh_push_frame {
u8 pmk_r0_name[WPA_PMK_NAME_LEN];
u8 pmk_r1[PMK_LEN];
u8 pmk_r1_name[WPA_PMK_NAME_LEN];
+ le16 pairwise;
+ u8 pad[6]; /* 8-octet boundary for AES key wrap */
u8 key_wrap_extra[8];
} STRUCT_PACKED;
@@ -142,13 +142,10 @@ struct wpa_auth_config {
int eapol_version;
int peerkey;
int wmm_enabled;
+ int wmm_uapsd;
int okc;
#ifdef CONFIG_IEEE80211W
- enum {
- WPA_NO_IEEE80211W = 0,
- WPA_IEEE80211W_OPTIONAL = 1,
- WPA_IEEE80211W_REQUIRED = 2
- } ieee80211w;
+ enum mfp_options ieee80211w;
#endif /* CONFIG_IEEE80211W */
#ifdef CONFIG_IEEE80211R
#define SSID_LEN 32
@@ -187,10 +184,9 @@ struct wpa_auth_callbacks {
int (*get_eapol)(void *ctx, const u8 *addr, wpa_eapol_variable var);
const u8 * (*get_psk)(void *ctx, const u8 *addr, const u8 *prev_psk);
int (*get_msk)(void *ctx, const u8 *addr, u8 *msk, size_t *len);
- int (*set_key)(void *ctx, int vlan_id, const char *alg, const u8 *addr,
- int idx, u8 *key, size_t key_len);
+ int (*set_key)(void *ctx, int vlan_id, enum wpa_alg alg,
+ const u8 *addr, int idx, u8 *key, size_t key_len);
int (*get_seqnum)(void *ctx, const u8 *addr, int idx, u8 *seq);
- int (*get_seqnum_igtk)(void *ctx, const u8 *addr, int idx, u8 *seq);
int (*send_eapol)(void *ctx, const u8 *addr, const u8 *data,
size_t data_len, int encrypt);
int (*for_each_sta)(void *ctx, int (*cb)(struct wpa_state_machine *sm,
@@ -227,8 +223,8 @@ int wpa_validate_wpa_ie(struct wpa_authenticator *wpa_auth,
int wpa_auth_uses_mfp(struct wpa_state_machine *sm);
struct wpa_state_machine *
wpa_auth_sta_init(struct wpa_authenticator *wpa_auth, const u8 *addr);
-void wpa_auth_sta_associated(struct wpa_authenticator *wpa_auth,
- struct wpa_state_machine *sm);
+int wpa_auth_sta_associated(struct wpa_authenticator *wpa_auth,
+ struct wpa_state_machine *sm);
void wpa_auth_sta_no_wpa(struct wpa_state_machine *sm);
void wpa_auth_sta_deinit(struct wpa_state_machine *sm);
void wpa_receive(struct wpa_authenticator *wpa_auth,
@@ -239,7 +235,7 @@ typedef enum {
WPA_REAUTH_EAPOL, WPA_ASSOC_FT
} wpa_event;
void wpa_remove_ptk(struct wpa_state_machine *sm);
-void wpa_auth_sm_event(struct wpa_state_machine *sm, wpa_event event);
+int wpa_auth_sm_event(struct wpa_state_machine *sm, wpa_event event);
void wpa_auth_sm_notify(struct wpa_state_machine *sm);
void wpa_gtk_rekey(struct wpa_authenticator *wpa_auth);
int wpa_get_mib(struct wpa_authenticator *wpa_auth, char *buf, size_t buflen);
@@ -266,7 +262,8 @@ int wpa_auth_sta_set_vlan(struct wpa_state_machine *sm, int vlan_id);
#ifdef CONFIG_IEEE80211R
u8 * wpa_sm_write_assoc_resp_ies(struct wpa_state_machine *sm, u8 *pos,
- size_t max_len, int auth_alg);
+ size_t max_len, int auth_alg,
+ const u8 *req_ies, size_t req_ies_len);
void wpa_ft_process_auth(struct wpa_state_machine *sm, const u8 *bssid,
u16 auth_transaction, const u8 *ies, size_t ies_len,
void (*cb)(void *ctx, const u8 *dst, const u8 *bssid,
diff --git a/contrib/wpa/hostapd/wpa_ft.c b/contrib/wpa/src/ap/wpa_auth_ft.c
index 3139105..c9871d9 100644
--- a/contrib/wpa/hostapd/wpa_ft.c
+++ b/contrib/wpa/src/ap/wpa_auth_ft.c
@@ -1,6 +1,6 @@
/*
* hostapd - IEEE 802.11r - Fast BSS Transition
- * Copyright (c) 2004-2007, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -12,25 +12,50 @@
* See README and COPYING for more details.
*/
-#include "includes.h"
+#include "utils/includes.h"
-#include "common.h"
-#include "config.h"
-#include "wpa.h"
-#include "aes_wrap.h"
+#include "utils/common.h"
+#include "common/ieee802_11_defs.h"
+#include "common/ieee802_11_common.h"
+#include "crypto/aes_wrap.h"
+#include "ap_config.h"
#include "ieee802_11.h"
-#include "defs.h"
+#include "wmm.h"
+#include "wpa_auth.h"
#include "wpa_auth_i.h"
#include "wpa_auth_ie.h"
#ifdef CONFIG_IEEE80211R
+struct wpa_ft_ies {
+ const u8 *mdie;
+ size_t mdie_len;
+ const u8 *ftie;
+ size_t ftie_len;
+ const u8 *r1kh_id;
+ const u8 *gtk;
+ size_t gtk_len;
+ const u8 *r0kh_id;
+ size_t r0kh_id_len;
+ const u8 *rsn;
+ size_t rsn_len;
+ const u8 *rsn_pmkid;
+ const u8 *ric;
+ size_t ric_len;
+};
+
+
+static int wpa_ft_parse_ies(const u8 *ies, size_t ies_len,
+ struct wpa_ft_ies *parse);
+
+
static int wpa_ft_rrb_send(struct wpa_authenticator *wpa_auth, const u8 *dst,
const u8 *data, size_t data_len)
{
if (wpa_auth->cb.send_ether == NULL)
return -1;
+ wpa_printf(MSG_DEBUG, "FT: RRB send to " MACSTR, MAC2STR(dst));
return wpa_auth->cb.send_ether(wpa_auth->cb.ctx, dst, ETH_P_RRB,
data, data_len);
}
@@ -73,11 +98,11 @@ int wpa_write_mdie(struct wpa_auth_config *conf, u8 *buf, size_t len)
}
-static int wpa_write_ftie(struct wpa_auth_config *conf, const u8 *r0kh_id,
- size_t r0kh_id_len,
- const u8 *anonce, const u8 *snonce,
- u8 *buf, size_t len, const u8 *subelem,
- size_t subelem_len)
+int wpa_write_ftie(struct wpa_auth_config *conf, const u8 *r0kh_id,
+ size_t r0kh_id_len,
+ const u8 *anonce, const u8 *snonce,
+ u8 *buf, size_t len, const u8 *subelem,
+ size_t subelem_len)
{
u8 *pos = buf, *ielen;
struct rsn_ftie *hdr;
@@ -127,6 +152,7 @@ struct wpa_ft_pmk_r0_sa {
u8 pmk_r0[PMK_LEN];
u8 pmk_r0_name[WPA_PMK_NAME_LEN];
u8 spa[ETH_ALEN];
+ int pairwise; /* Pairwise cipher suite, WPA_CIPHER_* */
/* TODO: expiration, identity, radius_class, EAP type, VLAN ID */
int pmk_r1_pushed;
};
@@ -136,6 +162,7 @@ struct wpa_ft_pmk_r1_sa {
u8 pmk_r1[PMK_LEN];
u8 pmk_r1_name[WPA_PMK_NAME_LEN];
u8 spa[ETH_ALEN];
+ int pairwise; /* Pairwise cipher suite, WPA_CIPHER_* */
/* TODO: expiration, identity, radius_class, EAP type, VLAN ID */
};
@@ -181,7 +208,7 @@ void wpa_ft_pmk_cache_deinit(struct wpa_ft_pmk_cache *cache)
static int wpa_ft_store_pmk_r0(struct wpa_authenticator *wpa_auth,
const u8 *spa, const u8 *pmk_r0,
- const u8 *pmk_r0_name)
+ const u8 *pmk_r0_name, int pairwise)
{
struct wpa_ft_pmk_cache *cache = wpa_auth->ft_pmk_cache;
struct wpa_ft_pmk_r0_sa *r0;
@@ -195,6 +222,7 @@ static int wpa_ft_store_pmk_r0(struct wpa_authenticator *wpa_auth,
os_memcpy(r0->pmk_r0, pmk_r0, PMK_LEN);
os_memcpy(r0->pmk_r0_name, pmk_r0_name, WPA_PMK_NAME_LEN);
os_memcpy(r0->spa, spa, ETH_ALEN);
+ r0->pairwise = pairwise;
r0->next = cache->pmk_r0;
cache->pmk_r0 = r0;
@@ -205,7 +233,7 @@ static int wpa_ft_store_pmk_r0(struct wpa_authenticator *wpa_auth,
static int wpa_ft_fetch_pmk_r0(struct wpa_authenticator *wpa_auth,
const u8 *spa, const u8 *pmk_r0_name,
- u8 *pmk_r0)
+ u8 *pmk_r0, int *pairwise)
{
struct wpa_ft_pmk_cache *cache = wpa_auth->ft_pmk_cache;
struct wpa_ft_pmk_r0_sa *r0;
@@ -216,6 +244,8 @@ static int wpa_ft_fetch_pmk_r0(struct wpa_authenticator *wpa_auth,
os_memcmp(r0->pmk_r0_name, pmk_r0_name, WPA_PMK_NAME_LEN)
== 0) {
os_memcpy(pmk_r0, r0->pmk_r0, PMK_LEN);
+ if (pairwise)
+ *pairwise = r0->pairwise;
return 0;
}
@@ -228,7 +258,7 @@ static int wpa_ft_fetch_pmk_r0(struct wpa_authenticator *wpa_auth,
static int wpa_ft_store_pmk_r1(struct wpa_authenticator *wpa_auth,
const u8 *spa, const u8 *pmk_r1,
- const u8 *pmk_r1_name)
+ const u8 *pmk_r1_name, int pairwise)
{
struct wpa_ft_pmk_cache *cache = wpa_auth->ft_pmk_cache;
struct wpa_ft_pmk_r1_sa *r1;
@@ -242,6 +272,7 @@ static int wpa_ft_store_pmk_r1(struct wpa_authenticator *wpa_auth,
os_memcpy(r1->pmk_r1, pmk_r1, PMK_LEN);
os_memcpy(r1->pmk_r1_name, pmk_r1_name, WPA_PMK_NAME_LEN);
os_memcpy(r1->spa, spa, ETH_ALEN);
+ r1->pairwise = pairwise;
r1->next = cache->pmk_r1;
cache->pmk_r1 = r1;
@@ -252,7 +283,7 @@ static int wpa_ft_store_pmk_r1(struct wpa_authenticator *wpa_auth,
static int wpa_ft_fetch_pmk_r1(struct wpa_authenticator *wpa_auth,
const u8 *spa, const u8 *pmk_r1_name,
- u8 *pmk_r1)
+ u8 *pmk_r1, int *pairwise)
{
struct wpa_ft_pmk_cache *cache = wpa_auth->ft_pmk_cache;
struct wpa_ft_pmk_r1_sa *r1;
@@ -263,6 +294,8 @@ static int wpa_ft_fetch_pmk_r1(struct wpa_authenticator *wpa_auth,
os_memcmp(r1->pmk_r1_name, pmk_r1_name, WPA_PMK_NAME_LEN)
== 0) {
os_memcpy(pmk_r1, r1->pmk_r1, PMK_LEN);
+ if (pairwise)
+ *pairwise = r1->pairwise;
return 0;
}
@@ -324,7 +357,7 @@ int wpa_auth_derive_ptk_ft(struct wpa_state_machine *sm, const u8 *pmk,
struct wpa_ptk *ptk, size_t ptk_len)
{
u8 pmk_r0[PMK_LEN], pmk_r0_name[WPA_PMK_NAME_LEN];
- u8 pmk_r1[PMK_LEN], pmk_r1_name[WPA_PMK_NAME_LEN];
+ u8 pmk_r1[PMK_LEN];
u8 ptk_name[WPA_PMK_NAME_LEN];
const u8 *mdid = sm->wpa_auth->conf.mobility_domain;
const u8 *r0kh = sm->wpa_auth->conf.r0_key_holder;
@@ -344,16 +377,19 @@ int wpa_auth_derive_ptk_ft(struct wpa_state_machine *sm, const u8 *pmk,
r0kh, r0kh_len, sm->addr, pmk_r0, pmk_r0_name);
wpa_hexdump_key(MSG_DEBUG, "FT: PMK-R0", pmk_r0, PMK_LEN);
wpa_hexdump(MSG_DEBUG, "FT: PMKR0Name", pmk_r0_name, WPA_PMK_NAME_LEN);
- wpa_ft_store_pmk_r0(sm->wpa_auth, sm->addr, pmk_r0, pmk_r0_name);
+ wpa_ft_store_pmk_r0(sm->wpa_auth, sm->addr, pmk_r0, pmk_r0_name,
+ sm->pairwise);
wpa_derive_pmk_r1(pmk_r0, pmk_r0_name, r1kh, sm->addr,
- pmk_r1, pmk_r1_name);
+ pmk_r1, sm->pmk_r1_name);
wpa_hexdump_key(MSG_DEBUG, "FT: PMK-R1", pmk_r1, PMK_LEN);
- wpa_hexdump(MSG_DEBUG, "FT: PMKR1Name", pmk_r1_name, WPA_PMK_NAME_LEN);
- wpa_ft_store_pmk_r1(sm->wpa_auth, sm->addr, pmk_r1, pmk_r1_name);
+ wpa_hexdump(MSG_DEBUG, "FT: PMKR1Name", sm->pmk_r1_name,
+ WPA_PMK_NAME_LEN);
+ wpa_ft_store_pmk_r1(sm->wpa_auth, sm->addr, pmk_r1, sm->pmk_r1_name,
+ sm->pairwise);
wpa_pmk_r1_to_ptk(pmk_r1, sm->SNonce, sm->ANonce, sm->addr,
- sm->wpa_auth->addr, pmk_r1_name,
+ sm->wpa_auth->addr, sm->pmk_r1_name,
(u8 *) ptk, ptk_len, ptk_name);
wpa_hexdump_key(MSG_DEBUG, "FT: PTK", (u8 *) ptk, ptk_len);
wpa_hexdump(MSG_DEBUG, "FT: PTKName", ptk_name, WPA_PMK_NAME_LEN);
@@ -371,17 +407,6 @@ static inline int wpa_auth_get_seqnum(struct wpa_authenticator *wpa_auth,
}
-#ifdef CONFIG_IEEE80211W
-static inline int wpa_auth_get_seqnum_igtk(struct wpa_authenticator *wpa_auth,
- const u8 *addr, int idx, u8 *seq)
-{
- if (wpa_auth->cb.get_seqnum_igtk == NULL)
- return -1;
- return wpa_auth->cb.get_seqnum_igtk(wpa_auth->cb.ctx, addr, idx, seq);
-}
-#endif /* CONFIG_IEEE80211W */
-
-
static u8 * wpa_ft_gtk_subelem(struct wpa_state_machine *sm, size_t *len)
{
u8 *subelem;
@@ -414,20 +439,21 @@ static u8 * wpa_ft_gtk_subelem(struct wpa_state_machine *sm, size_t *len)
key = gsm->GTK[gsm->GN - 1];
/*
- * Sub-elem ID[1] | Length[1] | Key Info[1] | Key Length[1] | RSC[8] |
+ * Sub-elem ID[1] | Length[1] | Key Info[2] | Key Length[1] | RSC[8] |
* Key[5..32].
*/
- subelem_len = 12 + key_len + 8;
+ subelem_len = 13 + key_len + 8;
subelem = os_zalloc(subelem_len);
if (subelem == NULL)
return NULL;
subelem[0] = FTIE_SUBELEM_GTK;
- subelem[1] = 10 + key_len + 8;
- subelem[2] = gsm->GN & 0x03; /* Key ID in B0-B1 of Key Info */
- subelem[3] = gsm->GTK_len;
- wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN, subelem + 4);
- if (aes_wrap(sm->PTK.kek, key_len / 8, key, subelem + 12)) {
+ subelem[1] = 11 + key_len + 8;
+ /* Key ID in B0-B1 of Key Info */
+ WPA_PUT_LE16(&subelem[2], gsm->GN & 0x03);
+ subelem[4] = gsm->GTK_len;
+ wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN, subelem + 5);
+ if (aes_wrap(sm->PTK.kek, key_len / 8, key, subelem + 13)) {
os_free(subelem);
return NULL;
}
@@ -456,7 +482,7 @@ static u8 * wpa_ft_igtk_subelem(struct wpa_state_machine *sm, size_t *len)
*pos++ = subelem_len - 2;
WPA_PUT_LE16(pos, gsm->GN_igtk);
pos += 2;
- wpa_auth_get_seqnum_igtk(sm->wpa_auth, NULL, gsm->GN_igtk, pos);
+ wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN_igtk, pos);
pos += 6;
*pos++ = WPA_IGTK_LEN;
if (aes_wrap(sm->PTK.kek, WPA_IGTK_LEN / 8,
@@ -471,14 +497,125 @@ static u8 * wpa_ft_igtk_subelem(struct wpa_state_machine *sm, size_t *len)
#endif /* CONFIG_IEEE80211W */
+static u8 * wpa_ft_process_rdie(u8 *pos, u8 *end, u8 id, u8 descr_count,
+ const u8 *ies, size_t ies_len)
+{
+ struct ieee802_11_elems parse;
+ struct rsn_rdie *rdie;
+
+ wpa_printf(MSG_DEBUG, "FT: Resource Request: id=%d descr_count=%d",
+ id, descr_count);
+ wpa_hexdump(MSG_MSGDUMP, "FT: Resource descriptor IE(s)",
+ ies, ies_len);
+
+ if (end - pos < (int) sizeof(*rdie)) {
+ wpa_printf(MSG_ERROR, "FT: Not enough room for response RDIE");
+ return pos;
+ }
+
+ *pos++ = WLAN_EID_RIC_DATA;
+ *pos++ = sizeof(*rdie);
+ rdie = (struct rsn_rdie *) pos;
+ rdie->id = id;
+ rdie->descr_count = 0;
+ rdie->status_code = host_to_le16(WLAN_STATUS_SUCCESS);
+ pos += sizeof(*rdie);
+
+ if (ieee802_11_parse_elems((u8 *) ies, ies_len, &parse, 1) ==
+ ParseFailed) {
+ wpa_printf(MSG_DEBUG, "FT: Failed to parse request IEs");
+ rdie->status_code =
+ host_to_le16(WLAN_STATUS_UNSPECIFIED_FAILURE);
+ return pos;
+ }
+
+#ifdef NEED_AP_MLME
+ if (parse.wmm_tspec) {
+ struct wmm_tspec_element *tspec;
+ int res;
+
+ if (parse.wmm_tspec_len + 2 < (int) sizeof(*tspec)) {
+ wpa_printf(MSG_DEBUG, "FT: Too short WMM TSPEC IE "
+ "(%d)", (int) parse.wmm_tspec_len);
+ rdie->status_code =
+ host_to_le16(WLAN_STATUS_UNSPECIFIED_FAILURE);
+ return pos;
+ }
+ if (end - pos < (int) sizeof(*tspec)) {
+ wpa_printf(MSG_ERROR, "FT: Not enough room for "
+ "response TSPEC");
+ rdie->status_code =
+ host_to_le16(WLAN_STATUS_UNSPECIFIED_FAILURE);
+ return pos;
+ }
+ tspec = (struct wmm_tspec_element *) pos;
+ os_memcpy(tspec, parse.wmm_tspec - 2, sizeof(*tspec));
+ res = wmm_process_tspec(tspec);
+ wpa_printf(MSG_DEBUG, "FT: ADDTS processing result: %d", res);
+ if (res == WMM_ADDTS_STATUS_INVALID_PARAMETERS)
+ rdie->status_code =
+ host_to_le16(WLAN_STATUS_INVALID_PARAMETERS);
+ else if (res == WMM_ADDTS_STATUS_REFUSED)
+ rdie->status_code =
+ host_to_le16(WLAN_STATUS_REQUEST_DECLINED);
+ else {
+ /* TSPEC accepted; include updated TSPEC in response */
+ rdie->descr_count = 1;
+ pos += sizeof(*tspec);
+ }
+ return pos;
+ }
+#endif /* NEED_AP_MLME */
+
+ wpa_printf(MSG_DEBUG, "FT: No supported resource requested");
+ rdie->status_code = host_to_le16(WLAN_STATUS_UNSPECIFIED_FAILURE);
+ return pos;
+}
+
+
+static u8 * wpa_ft_process_ric(u8 *pos, u8 *end, const u8 *ric, size_t ric_len)
+{
+ const u8 *rpos, *start;
+ const struct rsn_rdie *rdie;
+
+ wpa_hexdump(MSG_MSGDUMP, "FT: RIC Request", ric, ric_len);
+
+ rpos = ric;
+ while (rpos + sizeof(*rdie) < ric + ric_len) {
+ if (rpos[0] != WLAN_EID_RIC_DATA || rpos[1] < sizeof(*rdie) ||
+ rpos + 2 + rpos[1] > ric + ric_len)
+ break;
+ rdie = (const struct rsn_rdie *) (rpos + 2);
+ rpos += 2 + rpos[1];
+ start = rpos;
+
+ while (rpos + 2 <= ric + ric_len &&
+ rpos + 2 + rpos[1] <= ric + ric_len) {
+ if (rpos[0] == WLAN_EID_RIC_DATA)
+ break;
+ rpos += 2 + rpos[1];
+ }
+ pos = wpa_ft_process_rdie(pos, end, rdie->id,
+ rdie->descr_count,
+ start, rpos - start);
+ }
+
+ return pos;
+}
+
+
u8 * wpa_sm_write_assoc_resp_ies(struct wpa_state_machine *sm, u8 *pos,
- size_t max_len, int auth_alg)
+ size_t max_len, int auth_alg,
+ const u8 *req_ies, size_t req_ies_len)
{
- u8 *end, *mdie, *ftie, *rsnie, *r0kh_id, *subelem = NULL;
- size_t mdie_len, ftie_len, rsnie_len, r0kh_id_len, subelem_len = 0;
+ u8 *end, *mdie, *ftie, *rsnie = NULL, *r0kh_id, *subelem = NULL;
+ size_t mdie_len, ftie_len, rsnie_len = 0, r0kh_id_len, subelem_len = 0;
int res;
struct wpa_auth_config *conf;
struct rsn_ftie *_ftie;
+ struct wpa_ft_ies parse;
+ u8 *ric_start;
+ u8 *anonce, *snonce;
if (sm == NULL)
return pos;
@@ -491,13 +628,18 @@ u8 * wpa_sm_write_assoc_resp_ies(struct wpa_state_machine *sm, u8 *pos,
end = pos + max_len;
- /* RSN */
- res = wpa_write_rsn_ie(conf, pos, end - pos, sm->pmk_r1_name);
- if (res < 0)
- return pos;
- rsnie = pos;
- rsnie_len = res;
- pos += res;
+ if (auth_alg == WLAN_AUTH_FT) {
+ /*
+ * RSN (only present if this is a Reassociation Response and
+ * part of a fast BSS transition)
+ */
+ res = wpa_write_rsn_ie(conf, pos, end - pos, sm->pmk_r1_name);
+ if (res < 0)
+ return pos;
+ rsnie = pos;
+ rsnie_len = res;
+ pos += res;
+ }
/* Mobility Domain Information */
res = wpa_write_mdie(conf, pos, end - pos);
@@ -512,6 +654,8 @@ u8 * wpa_sm_write_assoc_resp_ies(struct wpa_state_machine *sm, u8 *pos,
subelem = wpa_ft_gtk_subelem(sm, &subelem_len);
r0kh_id = sm->r0kh_id;
r0kh_id_len = sm->r0kh_id_len;
+ anonce = sm->ANonce;
+ snonce = sm->SNonce;
#ifdef CONFIG_IEEE80211W
if (sm->mgmt_frame_prot) {
u8 *igtk;
@@ -537,8 +681,10 @@ u8 * wpa_sm_write_assoc_resp_ies(struct wpa_state_machine *sm, u8 *pos,
} else {
r0kh_id = conf->r0_key_holder;
r0kh_id_len = conf->r0_key_holder_len;
+ anonce = NULL;
+ snonce = NULL;
}
- res = wpa_write_ftie(conf, r0kh_id, r0kh_id_len, NULL, NULL, pos,
+ res = wpa_write_ftie(conf, r0kh_id, r0kh_id_len, anonce, snonce, pos,
end - pos, subelem, subelem_len);
os_free(subelem);
if (res < 0)
@@ -547,33 +693,38 @@ u8 * wpa_sm_write_assoc_resp_ies(struct wpa_state_machine *sm, u8 *pos,
ftie_len = res;
pos += res;
+ os_free(sm->assoc_resp_ftie);
+ sm->assoc_resp_ftie = os_malloc(ftie_len);
+ if (sm->assoc_resp_ftie)
+ os_memcpy(sm->assoc_resp_ftie, ftie, ftie_len);
+
_ftie = (struct rsn_ftie *) (ftie + 2);
- _ftie->mic_control[1] = 3; /* Information element count */
- if (wpa_ft_mic(sm->PTK.kck, sm->addr, sm->wpa_auth->addr, 6,
+ if (auth_alg == WLAN_AUTH_FT)
+ _ftie->mic_control[1] = 3; /* Information element count */
+
+ ric_start = pos;
+ if (wpa_ft_parse_ies(req_ies, req_ies_len, &parse) == 0 && parse.ric) {
+ pos = wpa_ft_process_ric(pos, end, parse.ric, parse.ric_len);
+ if (auth_alg == WLAN_AUTH_FT)
+ _ftie->mic_control[1] +=
+ ieee802_11_ie_count(ric_start,
+ pos - ric_start);
+ }
+ if (ric_start == pos)
+ ric_start = NULL;
+
+ if (auth_alg == WLAN_AUTH_FT &&
+ wpa_ft_mic(sm->PTK.kck, sm->addr, sm->wpa_auth->addr, 6,
mdie, mdie_len, ftie, ftie_len,
- rsnie, rsnie_len, NULL, 0, _ftie->mic) < 0)
+ rsnie, rsnie_len,
+ ric_start, ric_start ? pos - ric_start : 0,
+ _ftie->mic) < 0)
wpa_printf(MSG_DEBUG, "FT: Failed to calculate MIC");
return pos;
}
-struct wpa_ft_ies {
- const u8 *mdie;
- size_t mdie_len;
- const u8 *ftie;
- size_t ftie_len;
- const u8 *r1kh_id;
- const u8 *gtk;
- size_t gtk_len;
- const u8 *r0kh_id;
- size_t r0kh_id_len;
- const u8 *rsn;
- size_t rsn_len;
- const u8 *rsn_pmkid;
-};
-
-
static int wpa_ft_parse_ftie(const u8 *ie, size_t ie_len,
struct wpa_ft_ies *parse)
{
@@ -623,6 +774,8 @@ static int wpa_ft_parse_ies(const u8 *ies, size_t ies_len,
const u8 *end, *pos;
struct wpa_ie_data data;
int ret;
+ const struct rsn_ftie *ftie;
+ int prot_ie_count = 0;
os_memset(parse, 0, sizeof(*parse));
if (ies == NULL)
@@ -651,21 +804,67 @@ static int wpa_ft_parse_ies(const u8 *ies, size_t ies_len,
parse->mdie_len = pos[1];
break;
case WLAN_EID_FAST_BSS_TRANSITION:
+ if (pos[1] < sizeof(*ftie))
+ return -1;
+ ftie = (const struct rsn_ftie *) (pos + 2);
+ prot_ie_count = ftie->mic_control[1];
if (wpa_ft_parse_ftie(pos + 2, pos[1], parse) < 0)
return -1;
break;
+ case WLAN_EID_RIC_DATA:
+ if (parse->ric == NULL)
+ parse->ric = pos;
}
pos += 2 + pos[1];
}
+ if (prot_ie_count == 0)
+ return 0; /* no MIC */
+
+ /*
+ * Check that the protected IE count matches with IEs included in the
+ * frame.
+ */
+ if (parse->rsn)
+ prot_ie_count--;
+ if (parse->mdie)
+ prot_ie_count--;
+ if (parse->ftie)
+ prot_ie_count--;
+ if (prot_ie_count < 0) {
+ wpa_printf(MSG_DEBUG, "FT: Some required IEs not included in "
+ "the protected IE count");
+ return -1;
+ }
+
+ if (prot_ie_count == 0 && parse->ric) {
+ wpa_printf(MSG_DEBUG, "FT: RIC IE(s) in the frame, but not "
+ "included in protected IE count");
+ return -1;
+ }
+
+ /* Determine the end of the RIC IE(s) */
+ pos = parse->ric;
+ while (pos && pos + 2 <= end && pos + 2 + pos[1] <= end &&
+ prot_ie_count) {
+ prot_ie_count--;
+ pos += 2 + pos[1];
+ }
+ parse->ric_len = pos - parse->ric;
+ if (prot_ie_count) {
+ wpa_printf(MSG_DEBUG, "FT: %d protected IEs missing from "
+ "frame", (int) prot_ie_count);
+ return -1;
+ }
+
return 0;
}
static inline int wpa_auth_set_key(struct wpa_authenticator *wpa_auth,
int vlan_id,
- const char *alg, const u8 *addr, int idx,
+ enum wpa_alg alg, const u8 *addr, int idx,
u8 *key, size_t key_len)
{
if (wpa_auth->cb.set_key == NULL)
@@ -675,25 +874,29 @@ static inline int wpa_auth_set_key(struct wpa_authenticator *wpa_auth,
}
-static void wpa_ft_install_ptk(struct wpa_state_machine *sm)
+void wpa_ft_install_ptk(struct wpa_state_machine *sm)
{
- char *alg;
+ enum wpa_alg alg;
int klen;
/* MLME-SETKEYS.request(PTK) */
if (sm->pairwise == WPA_CIPHER_TKIP) {
- alg = "TKIP";
+ alg = WPA_ALG_TKIP;
klen = 32;
} else if (sm->pairwise == WPA_CIPHER_CCMP) {
- alg = "CCMP";
+ alg = WPA_ALG_CCMP;
klen = 16;
- } else
+ } else {
+ wpa_printf(MSG_DEBUG, "FT: Unknown pairwise alg 0x%x - skip "
+ "PTK configuration", sm->pairwise);
return;
+ }
/* FIX: add STA entry to kernel/driver here? The set_key will fail
* most likely without this.. At the moment, STA entry is added only
- * after association has been completed. Alternatively, could
- * re-configure PTK at that point(?).
+ * after association has been completed. This function will be called
+ * again after association to get the PTK configured, but that could be
+ * optimized by adding the STA entry earlier.
*/
if (wpa_auth_set_key(sm->wpa_auth, 0, alg, sm->addr, 0,
sm->PTK.tk1, klen))
@@ -717,6 +920,7 @@ static u16 wpa_ft_process_auth_req(struct wpa_state_machine *sm,
size_t buflen, ptk_len;
int ret;
u8 *pos, *end;
+ int pairwise;
*resp_ies = NULL;
*resp_ies_len = 0;
@@ -772,8 +976,8 @@ static u16 wpa_ft_process_auth_req(struct wpa_state_machine *sm,
wpa_hexdump(MSG_DEBUG, "FT: Derived requested PMKR1Name",
pmk_r1_name, WPA_PMK_NAME_LEN);
- if (wpa_ft_fetch_pmk_r1(sm->wpa_auth, sm->addr, pmk_r1_name, pmk_r1) <
- 0) {
+ if (wpa_ft_fetch_pmk_r1(sm->wpa_auth, sm->addr, pmk_r1_name, pmk_r1,
+ &pairwise) < 0) {
if (wpa_ft_pull_pmk_r1(sm->wpa_auth, sm->addr, sm->r0kh_id,
sm->r0kh_id_len, parse.rsn_pmkid) < 0) {
wpa_printf(MSG_DEBUG, "FT: Did not have matching "
@@ -804,7 +1008,7 @@ static u16 wpa_ft_process_auth_req(struct wpa_state_machine *sm,
wpa_hexdump(MSG_DEBUG, "FT: Generated ANonce",
sm->ANonce, WPA_NONCE_LEN);
- ptk_len = sm->pairwise == WPA_CIPHER_CCMP ? 48 : 64;
+ ptk_len = pairwise != WPA_CIPHER_CCMP ? 64 : 48;
wpa_pmk_r1_to_ptk(pmk_r1, sm->SNonce, sm->ANonce, sm->addr,
sm->wpa_auth->addr, pmk_r1_name,
(u8 *) &sm->PTK, ptk_len, ptk_name);
@@ -812,6 +1016,7 @@ static u16 wpa_ft_process_auth_req(struct wpa_state_machine *sm,
(u8 *) &sm->PTK, ptk_len);
wpa_hexdump(MSG_DEBUG, "FT: PTKName", ptk_name, WPA_PMK_NAME_LEN);
+ sm->pairwise = pairwise;
wpa_ft_install_ptk(sm);
buflen = 2 + sizeof(struct rsn_mdie) + 2 + sizeof(struct rsn_ftie) +
@@ -895,6 +1100,7 @@ u16 wpa_ft_validate_reassoc(struct wpa_state_machine *sm, const u8 *ies,
struct rsn_mdie *mdie;
struct rsn_ftie *ftie;
u8 mic[16];
+ unsigned int count;
if (sm == NULL)
return WLAN_STATUS_UNSPECIFIED_FAILURE;
@@ -938,20 +1144,79 @@ u16 wpa_ft_validate_reassoc(struct wpa_state_machine *sm, const u8 *ies,
return WLAN_STATUS_INVALID_FTIE;
}
- /*
- * Assume that MDIE, FTIE, and RSN IE are protected and that there is
- * no RIC, so total of 3 protected IEs.
- */
- if (ftie->mic_control[1] != 3) {
- wpa_printf(MSG_DEBUG, "FT: Unexpected IE count in FTIE (%d)",
- ftie->mic_control[1]);
- return WLAN_STATUS_INVALID_FTIE;
+ if (os_memcmp(ftie->snonce, sm->SNonce, WPA_NONCE_LEN) != 0) {
+ wpa_printf(MSG_DEBUG, "FT: SNonce mismatch in FTIE");
+ wpa_hexdump(MSG_DEBUG, "FT: Received SNonce",
+ ftie->snonce, WPA_NONCE_LEN);
+ wpa_hexdump(MSG_DEBUG, "FT: Expected SNonce",
+ sm->SNonce, WPA_NONCE_LEN);
+ return -1;
+ }
+
+ if (os_memcmp(ftie->anonce, sm->ANonce, WPA_NONCE_LEN) != 0) {
+ wpa_printf(MSG_DEBUG, "FT: ANonce mismatch in FTIE");
+ wpa_hexdump(MSG_DEBUG, "FT: Received ANonce",
+ ftie->anonce, WPA_NONCE_LEN);
+ wpa_hexdump(MSG_DEBUG, "FT: Expected ANonce",
+ sm->ANonce, WPA_NONCE_LEN);
+ return -1;
+ }
+
+
+ if (parse.r0kh_id == NULL) {
+ wpa_printf(MSG_DEBUG, "FT: No R0KH-ID subelem in FTIE");
+ return -1;
+ }
+
+ if (parse.r0kh_id_len != sm->r0kh_id_len ||
+ os_memcmp(parse.r0kh_id, sm->r0kh_id, parse.r0kh_id_len) != 0) {
+ wpa_printf(MSG_DEBUG, "FT: R0KH-ID in FTIE did not match with "
+ "the current R0KH-ID");
+ wpa_hexdump(MSG_DEBUG, "FT: R0KH-ID in FTIE",
+ parse.r0kh_id, parse.r0kh_id_len);
+ wpa_hexdump(MSG_DEBUG, "FT: The current R0KH-ID",
+ sm->r0kh_id, sm->r0kh_id_len);
+ return -1;
+ }
+
+ if (parse.r1kh_id == NULL) {
+ wpa_printf(MSG_DEBUG, "FT: No R1KH-ID subelem in FTIE");
+ return -1;
+ }
+
+ if (os_memcmp(parse.r1kh_id, sm->wpa_auth->conf.r1_key_holder,
+ FT_R1KH_ID_LEN) != 0) {
+ wpa_printf(MSG_DEBUG, "FT: Unknown R1KH-ID used in "
+ "ReassocReq");
+ wpa_hexdump(MSG_DEBUG, "FT: R1KH-ID in FTIE",
+ parse.r1kh_id, FT_R1KH_ID_LEN);
+ wpa_hexdump(MSG_DEBUG, "FT: Expected R1KH-ID",
+ sm->wpa_auth->conf.r1_key_holder, FT_R1KH_ID_LEN);
+ return -1;
+ }
+
+ if (parse.rsn_pmkid == NULL ||
+ os_memcmp(parse.rsn_pmkid, sm->pmk_r1_name, WPA_PMK_NAME_LEN)) {
+ wpa_printf(MSG_DEBUG, "FT: No matching PMKR1Name (PMKID) in "
+ "RSNIE (pmkid=%d)", !!parse.rsn_pmkid);
+ return -1;
+ }
+
+ count = 3;
+ if (parse.ric)
+ count++;
+ if (ftie->mic_control[1] != count) {
+ wpa_printf(MSG_DEBUG, "FT: Unexpected IE count in MIC "
+ "Control: received %u expected %u",
+ ftie->mic_control[1], count);
+ return -1;
}
if (wpa_ft_mic(sm->PTK.kck, sm->addr, sm->wpa_auth->addr, 5,
parse.mdie - 2, parse.mdie_len + 2,
parse.ftie - 2, parse.ftie_len + 2,
- parse.rsn - 2, parse.rsn_len + 2, NULL, 0,
+ parse.rsn - 2, parse.rsn_len + 2,
+ parse.ric, parse.ric_len,
mic) < 0) {
wpa_printf(MSG_DEBUG, "FT: Failed to calculate MIC");
return WLAN_STATUS_UNSPECIFIED_FAILURE;
@@ -1107,6 +1372,7 @@ static int wpa_ft_rrb_rx_pull(struct wpa_authenticator *wpa_auth,
struct ft_remote_r1kh *r1kh;
struct ft_r0kh_r1kh_resp_frame resp, r;
u8 pmk_r0[PMK_LEN];
+ int pairwise;
wpa_printf(MSG_DEBUG, "FT: Received PMK-R1 pull");
@@ -1154,8 +1420,8 @@ static int wpa_ft_rrb_rx_pull(struct wpa_authenticator *wpa_auth,
os_memcpy(r.nonce, f.nonce, sizeof(f.nonce));
os_memcpy(r.r1kh_id, f.r1kh_id, FT_R1KH_ID_LEN);
os_memcpy(r.s1kh_id, f.s1kh_id, ETH_ALEN);
- if (wpa_ft_fetch_pmk_r0(wpa_auth, f.s1kh_id, f.pmk_r0_name, pmk_r0) <
- 0) {
+ if (wpa_ft_fetch_pmk_r0(wpa_auth, f.s1kh_id, f.pmk_r0_name, pmk_r0,
+ &pairwise) < 0) {
wpa_printf(MSG_DEBUG, "FT: No matching PMKR0Name found for "
"PMK-R1 pull");
return -1;
@@ -1166,6 +1432,7 @@ static int wpa_ft_rrb_rx_pull(struct wpa_authenticator *wpa_auth,
wpa_hexdump_key(MSG_DEBUG, "FT: PMK-R1", r.pmk_r1, PMK_LEN);
wpa_hexdump(MSG_DEBUG, "FT: PMKR1Name", r.pmk_r1_name,
WPA_PMK_NAME_LEN);
+ r.pairwise = host_to_le16(pairwise);
if (aes_wrap(r1kh->key, (FT_R0KH_R1KH_RESP_DATA_LEN + 7) / 8,
r.nonce, resp.nonce) < 0) {
@@ -1187,6 +1454,7 @@ static int wpa_ft_rrb_rx_resp(struct wpa_authenticator *wpa_auth,
{
struct ft_r0kh_r1kh_resp_frame *frame, f;
struct ft_remote_r0kh *r0kh;
+ int pairwise;
wpa_printf(MSG_DEBUG, "FT: Received PMK-R1 pull response");
@@ -1227,16 +1495,19 @@ static int wpa_ft_rrb_rx_resp(struct wpa_authenticator *wpa_auth,
* and call this requests callback function to finish request
* processing */
+ pairwise = le_to_host16(f.pairwise);
wpa_hexdump(MSG_DEBUG, "FT: PMK-R1 pull - nonce",
f.nonce, sizeof(f.nonce));
wpa_printf(MSG_DEBUG, "FT: PMK-R1 pull - R1KH-ID=" MACSTR "S1KH-ID="
- MACSTR, MAC2STR(f.r1kh_id), MAC2STR(f.s1kh_id));
+ MACSTR " pairwise=0x%x",
+ MAC2STR(f.r1kh_id), MAC2STR(f.s1kh_id), pairwise);
wpa_hexdump_key(MSG_DEBUG, "FT: PMK-R1 pull - PMK-R1",
f.pmk_r1, PMK_LEN);
wpa_hexdump(MSG_DEBUG, "FT: PMK-R1 pull - PMKR1Name",
f.pmk_r1_name, WPA_PMK_NAME_LEN);
- wpa_ft_store_pmk_r1(wpa_auth, f.s1kh_id, f.pmk_r1, f.pmk_r1_name);
+ wpa_ft_store_pmk_r1(wpa_auth, f.s1kh_id, f.pmk_r1, f.pmk_r1_name,
+ pairwise);
os_memset(f.pmk_r1, 0, PMK_LEN);
return 0;
@@ -1251,6 +1522,7 @@ static int wpa_ft_rrb_rx_push(struct wpa_authenticator *wpa_auth,
struct ft_remote_r0kh *r0kh;
struct os_time now;
os_time_t tsend;
+ int pairwise;
wpa_printf(MSG_DEBUG, "FT: Received PMK-R1 push");
@@ -1299,14 +1571,17 @@ static int wpa_ft_rrb_rx_push(struct wpa_authenticator *wpa_auth,
return -1;
}
+ pairwise = le_to_host16(f.pairwise);
wpa_printf(MSG_DEBUG, "FT: PMK-R1 push - R1KH-ID=" MACSTR " S1KH-ID="
- MACSTR, MAC2STR(f.r1kh_id), MAC2STR(f.s1kh_id));
+ MACSTR " pairwise=0x%x",
+ MAC2STR(f.r1kh_id), MAC2STR(f.s1kh_id), pairwise);
wpa_hexdump_key(MSG_DEBUG, "FT: PMK-R1 push - PMK-R1",
f.pmk_r1, PMK_LEN);
wpa_hexdump(MSG_DEBUG, "FT: PMK-R1 push - PMKR1Name",
f.pmk_r1_name, WPA_PMK_NAME_LEN);
- wpa_ft_store_pmk_r1(wpa_auth, f.s1kh_id, f.pmk_r1, f.pmk_r1_name);
+ wpa_ft_store_pmk_r1(wpa_auth, f.s1kh_id, f.pmk_r1, f.pmk_r1_name,
+ pairwise);
os_memset(f.pmk_r1, 0, PMK_LEN);
return 0;
@@ -1436,7 +1711,7 @@ int wpa_ft_rrb_rx(struct wpa_authenticator *wpa_auth, const u8 *src_addr,
static void wpa_ft_generate_pmk_r1(struct wpa_authenticator *wpa_auth,
struct wpa_ft_pmk_r0_sa *pmk_r0,
struct ft_remote_r1kh *r1kh,
- const u8 *s1kh_id)
+ const u8 *s1kh_id, int pairwise)
{
struct ft_r0kh_r1kh_push_frame frame, f;
struct os_time now;
@@ -1460,6 +1735,7 @@ static void wpa_ft_generate_pmk_r1(struct wpa_authenticator *wpa_auth,
WPA_PMK_NAME_LEN);
os_get_time(&now);
WPA_PUT_LE32(f.timestamp, now.sec);
+ f.pairwise = host_to_le16(pairwise);
if (aes_wrap(r1kh->key, (FT_R0KH_R1KH_PUSH_DATA_LEN + 7) / 8,
f.timestamp, frame.timestamp) < 0)
return;
@@ -1492,7 +1768,7 @@ void wpa_ft_push_pmk_r1(struct wpa_authenticator *wpa_auth, const u8 *addr)
r1kh = wpa_auth->conf.r1kh_list;
while (r1kh) {
- wpa_ft_generate_pmk_r1(wpa_auth, r0, r1kh, addr);
+ wpa_ft_generate_pmk_r1(wpa_auth, r0, r1kh, addr, r0->pairwise);
r1kh = r1kh->next;
}
}
diff --git a/contrib/wpa/src/ap/wpa_auth_glue.c b/contrib/wpa/src/ap/wpa_auth_glue.c
new file mode 100644
index 0000000..afa13a6
--- /dev/null
+++ b/contrib/wpa/src/ap/wpa_auth_glue.c
@@ -0,0 +1,545 @@
+/*
+ * hostapd / WPA authenticator glue code
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "utils/includes.h"
+
+#include "utils/common.h"
+#include "common/ieee802_11_defs.h"
+#include "eapol_auth/eapol_auth_sm.h"
+#include "eapol_auth/eapol_auth_sm_i.h"
+#include "eap_server/eap.h"
+#include "l2_packet/l2_packet.h"
+#include "drivers/driver.h"
+#include "hostapd.h"
+#include "ieee802_1x.h"
+#include "preauth_auth.h"
+#include "sta_info.h"
+#include "tkip_countermeasures.h"
+#include "ap_drv_ops.h"
+#include "ap_config.h"
+#include "wpa_auth.h"
+
+
+#ifdef CONFIG_IEEE80211R
+static void hostapd_rrb_receive(void *ctx, const u8 *src_addr, const u8 *buf,
+ size_t len);
+#endif /* CONFIG_IEEE80211R */
+
+
+static void hostapd_wpa_auth_conf(struct hostapd_bss_config *conf,
+ struct wpa_auth_config *wconf)
+{
+ wconf->wpa = conf->wpa;
+ wconf->wpa_key_mgmt = conf->wpa_key_mgmt;
+ wconf->wpa_pairwise = conf->wpa_pairwise;
+ wconf->wpa_group = conf->wpa_group;
+ wconf->wpa_group_rekey = conf->wpa_group_rekey;
+ wconf->wpa_strict_rekey = conf->wpa_strict_rekey;
+ wconf->wpa_gmk_rekey = conf->wpa_gmk_rekey;
+ wconf->wpa_ptk_rekey = conf->wpa_ptk_rekey;
+ wconf->rsn_pairwise = conf->rsn_pairwise;
+ wconf->rsn_preauth = conf->rsn_preauth;
+ wconf->eapol_version = conf->eapol_version;
+ wconf->peerkey = conf->peerkey;
+ wconf->wmm_enabled = conf->wmm_enabled;
+ wconf->wmm_uapsd = conf->wmm_uapsd;
+ wconf->okc = conf->okc;
+#ifdef CONFIG_IEEE80211W
+ wconf->ieee80211w = conf->ieee80211w;
+#endif /* CONFIG_IEEE80211W */
+#ifdef CONFIG_IEEE80211R
+ wconf->ssid_len = conf->ssid.ssid_len;
+ if (wconf->ssid_len > SSID_LEN)
+ wconf->ssid_len = SSID_LEN;
+ os_memcpy(wconf->ssid, conf->ssid.ssid, wconf->ssid_len);
+ os_memcpy(wconf->mobility_domain, conf->mobility_domain,
+ MOBILITY_DOMAIN_ID_LEN);
+ if (conf->nas_identifier &&
+ os_strlen(conf->nas_identifier) <= FT_R0KH_ID_MAX_LEN) {
+ wconf->r0_key_holder_len = os_strlen(conf->nas_identifier);
+ os_memcpy(wconf->r0_key_holder, conf->nas_identifier,
+ wconf->r0_key_holder_len);
+ }
+ os_memcpy(wconf->r1_key_holder, conf->r1_key_holder, FT_R1KH_ID_LEN);
+ wconf->r0_key_lifetime = conf->r0_key_lifetime;
+ wconf->reassociation_deadline = conf->reassociation_deadline;
+ wconf->r0kh_list = conf->r0kh_list;
+ wconf->r1kh_list = conf->r1kh_list;
+ wconf->pmk_r1_push = conf->pmk_r1_push;
+#endif /* CONFIG_IEEE80211R */
+}
+
+
+static void hostapd_wpa_auth_logger(void *ctx, const u8 *addr,
+ logger_level level, const char *txt)
+{
+#ifndef CONFIG_NO_HOSTAPD_LOGGER
+ struct hostapd_data *hapd = ctx;
+ int hlevel;
+
+ switch (level) {
+ case LOGGER_WARNING:
+ hlevel = HOSTAPD_LEVEL_WARNING;
+ break;
+ case LOGGER_INFO:
+ hlevel = HOSTAPD_LEVEL_INFO;
+ break;
+ case LOGGER_DEBUG:
+ default:
+ hlevel = HOSTAPD_LEVEL_DEBUG;
+ break;
+ }
+
+ hostapd_logger(hapd, addr, HOSTAPD_MODULE_WPA, hlevel, "%s", txt);
+#endif /* CONFIG_NO_HOSTAPD_LOGGER */
+}
+
+
+static void hostapd_wpa_auth_disconnect(void *ctx, const u8 *addr,
+ u16 reason)
+{
+ struct hostapd_data *hapd = ctx;
+ wpa_printf(MSG_DEBUG, "%s: WPA authenticator requests disconnect: "
+ "STA " MACSTR " reason %d",
+ __func__, MAC2STR(addr), reason);
+ ap_sta_disconnect(hapd, NULL, addr, reason);
+}
+
+
+static void hostapd_wpa_auth_mic_failure_report(void *ctx, const u8 *addr)
+{
+ struct hostapd_data *hapd = ctx;
+ michael_mic_failure(hapd, addr, 0);
+}
+
+
+static void hostapd_wpa_auth_set_eapol(void *ctx, const u8 *addr,
+ wpa_eapol_variable var, int value)
+{
+ struct hostapd_data *hapd = ctx;
+ struct sta_info *sta = ap_get_sta(hapd, addr);
+ if (sta == NULL)
+ return;
+ switch (var) {
+ case WPA_EAPOL_portEnabled:
+ ieee802_1x_notify_port_enabled(sta->eapol_sm, value);
+ break;
+ case WPA_EAPOL_portValid:
+ ieee802_1x_notify_port_valid(sta->eapol_sm, value);
+ break;
+ case WPA_EAPOL_authorized:
+ ieee802_1x_set_sta_authorized(hapd, sta, value);
+ break;
+ case WPA_EAPOL_portControl_Auto:
+ if (sta->eapol_sm)
+ sta->eapol_sm->portControl = Auto;
+ break;
+ case WPA_EAPOL_keyRun:
+ if (sta->eapol_sm)
+ sta->eapol_sm->keyRun = value ? TRUE : FALSE;
+ break;
+ case WPA_EAPOL_keyAvailable:
+ if (sta->eapol_sm)
+ sta->eapol_sm->eap_if->eapKeyAvailable =
+ value ? TRUE : FALSE;
+ break;
+ case WPA_EAPOL_keyDone:
+ if (sta->eapol_sm)
+ sta->eapol_sm->keyDone = value ? TRUE : FALSE;
+ break;
+ case WPA_EAPOL_inc_EapolFramesTx:
+ if (sta->eapol_sm)
+ sta->eapol_sm->dot1xAuthEapolFramesTx++;
+ break;
+ }
+}
+
+
+static int hostapd_wpa_auth_get_eapol(void *ctx, const u8 *addr,
+ wpa_eapol_variable var)
+{
+ struct hostapd_data *hapd = ctx;
+ struct sta_info *sta = ap_get_sta(hapd, addr);
+ if (sta == NULL || sta->eapol_sm == NULL)
+ return -1;
+ switch (var) {
+ case WPA_EAPOL_keyRun:
+ return sta->eapol_sm->keyRun;
+ case WPA_EAPOL_keyAvailable:
+ return sta->eapol_sm->eap_if->eapKeyAvailable;
+ default:
+ return -1;
+ }
+}
+
+
+static const u8 * hostapd_wpa_auth_get_psk(void *ctx, const u8 *addr,
+ const u8 *prev_psk)
+{
+ struct hostapd_data *hapd = ctx;
+ return hostapd_get_psk(hapd->conf, addr, prev_psk);
+}
+
+
+static int hostapd_wpa_auth_get_msk(void *ctx, const u8 *addr, u8 *msk,
+ size_t *len)
+{
+ struct hostapd_data *hapd = ctx;
+ const u8 *key;
+ size_t keylen;
+ struct sta_info *sta;
+
+ sta = ap_get_sta(hapd, addr);
+ if (sta == NULL)
+ return -1;
+
+ key = ieee802_1x_get_key(sta->eapol_sm, &keylen);
+ if (key == NULL)
+ return -1;
+
+ if (keylen > *len)
+ keylen = *len;
+ os_memcpy(msk, key, keylen);
+ *len = keylen;
+
+ return 0;
+}
+
+
+static int hostapd_wpa_auth_set_key(void *ctx, int vlan_id, enum wpa_alg alg,
+ const u8 *addr, int idx, u8 *key,
+ size_t key_len)
+{
+ struct hostapd_data *hapd = ctx;
+ const char *ifname = hapd->conf->iface;
+
+ if (vlan_id > 0) {
+ ifname = hostapd_get_vlan_id_ifname(hapd->conf->vlan, vlan_id);
+ if (ifname == NULL)
+ return -1;
+ }
+
+ return hapd->drv.set_key(ifname, hapd, alg, addr, idx, 1, NULL, 0,
+ key, key_len);
+}
+
+
+static int hostapd_wpa_auth_get_seqnum(void *ctx, const u8 *addr, int idx,
+ u8 *seq)
+{
+ struct hostapd_data *hapd = ctx;
+ return hostapd_get_seqnum(hapd->conf->iface, hapd, addr, idx, seq);
+}
+
+
+static int hostapd_wpa_auth_send_eapol(void *ctx, const u8 *addr,
+ const u8 *data, size_t data_len,
+ int encrypt)
+{
+ struct hostapd_data *hapd = ctx;
+ return hapd->drv.send_eapol(hapd, addr, data, data_len, encrypt);
+}
+
+
+static int hostapd_wpa_auth_for_each_sta(
+ void *ctx, int (*cb)(struct wpa_state_machine *sm, void *ctx),
+ void *cb_ctx)
+{
+ struct hostapd_data *hapd = ctx;
+ struct sta_info *sta;
+
+ for (sta = hapd->sta_list; sta; sta = sta->next) {
+ if (sta->wpa_sm && cb(sta->wpa_sm, cb_ctx))
+ return 1;
+ }
+ return 0;
+}
+
+
+struct wpa_auth_iface_iter_data {
+ int (*cb)(struct wpa_authenticator *sm, void *ctx);
+ void *cb_ctx;
+};
+
+static int wpa_auth_iface_iter(struct hostapd_iface *iface, void *ctx)
+{
+ struct wpa_auth_iface_iter_data *data = ctx;
+ size_t i;
+ for (i = 0; i < iface->num_bss; i++) {
+ if (iface->bss[i]->wpa_auth &&
+ data->cb(iface->bss[i]->wpa_auth, data->cb_ctx))
+ return 1;
+ }
+ return 0;
+}
+
+
+static int hostapd_wpa_auth_for_each_auth(
+ void *ctx, int (*cb)(struct wpa_authenticator *sm, void *ctx),
+ void *cb_ctx)
+{
+ struct hostapd_data *hapd = ctx;
+ struct wpa_auth_iface_iter_data data;
+ if (hapd->iface->for_each_interface == NULL)
+ return -1;
+ data.cb = cb;
+ data.cb_ctx = cb_ctx;
+ return hapd->iface->for_each_interface(hapd->iface->interfaces,
+ wpa_auth_iface_iter, &data);
+}
+
+
+#ifdef CONFIG_IEEE80211R
+
+struct wpa_auth_ft_iface_iter_data {
+ struct hostapd_data *src_hapd;
+ const u8 *dst;
+ const u8 *data;
+ size_t data_len;
+};
+
+
+static int hostapd_wpa_auth_ft_iter(struct hostapd_iface *iface, void *ctx)
+{
+ struct wpa_auth_ft_iface_iter_data *idata = ctx;
+ struct hostapd_data *hapd;
+ size_t j;
+
+ for (j = 0; j < iface->num_bss; j++) {
+ hapd = iface->bss[j];
+ if (hapd == idata->src_hapd)
+ continue;
+ if (os_memcmp(hapd->own_addr, idata->dst, ETH_ALEN) == 0) {
+ wpa_printf(MSG_DEBUG, "FT: Send RRB data directly to "
+ "locally managed BSS " MACSTR "@%s -> "
+ MACSTR "@%s",
+ MAC2STR(idata->src_hapd->own_addr),
+ idata->src_hapd->conf->iface,
+ MAC2STR(hapd->own_addr), hapd->conf->iface);
+ hostapd_rrb_receive(hapd, idata->src_hapd->own_addr,
+ idata->data, idata->data_len);
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+#endif /* CONFIG_IEEE80211R */
+
+
+static int hostapd_wpa_auth_send_ether(void *ctx, const u8 *dst, u16 proto,
+ const u8 *data, size_t data_len)
+{
+ struct hostapd_data *hapd = ctx;
+
+#ifdef CONFIG_IEEE80211R
+ if (proto == ETH_P_RRB && hapd->iface->for_each_interface) {
+ int res;
+ struct wpa_auth_ft_iface_iter_data idata;
+ idata.src_hapd = hapd;
+ idata.dst = dst;
+ idata.data = data;
+ idata.data_len = data_len;
+ res = hapd->iface->for_each_interface(hapd->iface->interfaces,
+ hostapd_wpa_auth_ft_iter,
+ &idata);
+ if (res == 1)
+ return data_len;
+ }
+#endif /* CONFIG_IEEE80211R */
+
+ if (hapd->driver && hapd->driver->send_ether)
+ return hapd->driver->send_ether(hapd->drv_priv, dst,
+ hapd->own_addr, proto,
+ data, data_len);
+ if (hapd->l2 == NULL)
+ return -1;
+ return l2_packet_send(hapd->l2, dst, proto, data, data_len);
+}
+
+
+#ifdef CONFIG_IEEE80211R
+
+static int hostapd_wpa_auth_send_ft_action(void *ctx, const u8 *dst,
+ const u8 *data, size_t data_len)
+{
+ struct hostapd_data *hapd = ctx;
+ int res;
+ struct ieee80211_mgmt *m;
+ size_t mlen;
+ struct sta_info *sta;
+
+ sta = ap_get_sta(hapd, dst);
+ if (sta == NULL || sta->wpa_sm == NULL)
+ return -1;
+
+ m = os_zalloc(sizeof(*m) + data_len);
+ if (m == NULL)
+ return -1;
+ mlen = ((u8 *) &m->u - (u8 *) m) + data_len;
+ m->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
+ WLAN_FC_STYPE_ACTION);
+ os_memcpy(m->da, dst, ETH_ALEN);
+ os_memcpy(m->sa, hapd->own_addr, ETH_ALEN);
+ os_memcpy(m->bssid, hapd->own_addr, ETH_ALEN);
+ os_memcpy(&m->u, data, data_len);
+
+ res = hapd->drv.send_mgmt_frame(hapd, (u8 *) m, mlen);
+ os_free(m);
+ return res;
+}
+
+
+static struct wpa_state_machine *
+hostapd_wpa_auth_add_sta(void *ctx, const u8 *sta_addr)
+{
+ struct hostapd_data *hapd = ctx;
+ struct sta_info *sta;
+
+ sta = ap_sta_add(hapd, sta_addr);
+ if (sta == NULL)
+ return NULL;
+ if (sta->wpa_sm) {
+ sta->auth_alg = WLAN_AUTH_FT;
+ return sta->wpa_sm;
+ }
+
+ sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, sta->addr);
+ if (sta->wpa_sm == NULL) {
+ ap_free_sta(hapd, sta);
+ return NULL;
+ }
+ sta->auth_alg = WLAN_AUTH_FT;
+
+ return sta->wpa_sm;
+}
+
+
+static void hostapd_rrb_receive(void *ctx, const u8 *src_addr, const u8 *buf,
+ size_t len)
+{
+ struct hostapd_data *hapd = ctx;
+ wpa_ft_rrb_rx(hapd->wpa_auth, src_addr, buf, len);
+}
+
+#endif /* CONFIG_IEEE80211R */
+
+
+int hostapd_setup_wpa(struct hostapd_data *hapd)
+{
+ struct wpa_auth_config _conf;
+ struct wpa_auth_callbacks cb;
+ const u8 *wpa_ie;
+ size_t wpa_ie_len;
+
+ hostapd_wpa_auth_conf(hapd->conf, &_conf);
+ os_memset(&cb, 0, sizeof(cb));
+ cb.ctx = hapd;
+ cb.logger = hostapd_wpa_auth_logger;
+ cb.disconnect = hostapd_wpa_auth_disconnect;
+ cb.mic_failure_report = hostapd_wpa_auth_mic_failure_report;
+ cb.set_eapol = hostapd_wpa_auth_set_eapol;
+ cb.get_eapol = hostapd_wpa_auth_get_eapol;
+ cb.get_psk = hostapd_wpa_auth_get_psk;
+ cb.get_msk = hostapd_wpa_auth_get_msk;
+ cb.set_key = hostapd_wpa_auth_set_key;
+ cb.get_seqnum = hostapd_wpa_auth_get_seqnum;
+ cb.send_eapol = hostapd_wpa_auth_send_eapol;
+ cb.for_each_sta = hostapd_wpa_auth_for_each_sta;
+ cb.for_each_auth = hostapd_wpa_auth_for_each_auth;
+ cb.send_ether = hostapd_wpa_auth_send_ether;
+#ifdef CONFIG_IEEE80211R
+ cb.send_ft_action = hostapd_wpa_auth_send_ft_action;
+ cb.add_sta = hostapd_wpa_auth_add_sta;
+#endif /* CONFIG_IEEE80211R */
+ hapd->wpa_auth = wpa_init(hapd->own_addr, &_conf, &cb);
+ if (hapd->wpa_auth == NULL) {
+ wpa_printf(MSG_ERROR, "WPA initialization failed.");
+ return -1;
+ }
+
+ if (hostapd_set_privacy(hapd, 1)) {
+ wpa_printf(MSG_ERROR, "Could not set PrivacyInvoked "
+ "for interface %s", hapd->conf->iface);
+ return -1;
+ }
+
+ wpa_ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &wpa_ie_len);
+ if (hostapd_set_generic_elem(hapd, wpa_ie, wpa_ie_len)) {
+ wpa_printf(MSG_ERROR, "Failed to configure WPA IE for "
+ "the kernel driver.");
+ return -1;
+ }
+
+ if (rsn_preauth_iface_init(hapd)) {
+ wpa_printf(MSG_ERROR, "Initialization of RSN "
+ "pre-authentication failed.");
+ return -1;
+ }
+
+#ifdef CONFIG_IEEE80211R
+ if (!hostapd_drv_none(hapd)) {
+ hapd->l2 = l2_packet_init(hapd->conf->bridge[0] ?
+ hapd->conf->bridge :
+ hapd->conf->iface, NULL, ETH_P_RRB,
+ hostapd_rrb_receive, hapd, 0);
+ if (hapd->l2 == NULL &&
+ (hapd->driver == NULL ||
+ hapd->driver->send_ether == NULL)) {
+ wpa_printf(MSG_ERROR, "Failed to open l2_packet "
+ "interface");
+ return -1;
+ }
+ }
+#endif /* CONFIG_IEEE80211R */
+
+ return 0;
+
+}
+
+
+void hostapd_reconfig_wpa(struct hostapd_data *hapd)
+{
+ struct wpa_auth_config wpa_auth_conf;
+ hostapd_wpa_auth_conf(hapd->conf, &wpa_auth_conf);
+ wpa_reconfig(hapd->wpa_auth, &wpa_auth_conf);
+}
+
+
+void hostapd_deinit_wpa(struct hostapd_data *hapd)
+{
+ rsn_preauth_iface_deinit(hapd);
+ if (hapd->wpa_auth) {
+ wpa_deinit(hapd->wpa_auth);
+ hapd->wpa_auth = NULL;
+
+ if (hostapd_set_privacy(hapd, 0)) {
+ wpa_printf(MSG_DEBUG, "Could not disable "
+ "PrivacyInvoked for interface %s",
+ hapd->conf->iface);
+ }
+
+ if (hostapd_set_generic_elem(hapd, (u8 *) "", 0)) {
+ wpa_printf(MSG_DEBUG, "Could not remove generic "
+ "information element from interface %s",
+ hapd->conf->iface);
+ }
+ }
+ ieee802_1x_deinit(hapd);
+
+#ifdef CONFIG_IEEE80211R
+ l2_packet_deinit(hapd->l2);
+#endif /* CONFIG_IEEE80211R */
+}
diff --git a/contrib/wpa/src/ap/wpa_auth_glue.h b/contrib/wpa/src/ap/wpa_auth_glue.h
new file mode 100644
index 0000000..79d7e05
--- /dev/null
+++ b/contrib/wpa/src/ap/wpa_auth_glue.h
@@ -0,0 +1,22 @@
+/*
+ * hostapd / WPA authenticator glue code
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef WPA_AUTH_GLUE_H
+#define WPA_AUTH_GLUE_H
+
+int hostapd_setup_wpa(struct hostapd_data *hapd);
+void hostapd_reconfig_wpa(struct hostapd_data *hapd);
+void hostapd_deinit_wpa(struct hostapd_data *hapd);
+
+#endif /* WPA_AUTH_GLUE_H */
diff --git a/contrib/wpa/hostapd/wpa_auth_i.h b/contrib/wpa/src/ap/wpa_auth_i.h
index 925d3ee..b69129f 100644
--- a/contrib/wpa/hostapd/wpa_auth_i.h
+++ b/contrib/wpa/src/ap/wpa_auth_i.h
@@ -116,6 +116,9 @@ struct wpa_state_machine {
* Request */
u8 r0kh_id[FT_R0KH_ID_MAX_LEN]; /* R0KH-ID from FT Auth Request */
size_t r0kh_id_len;
+ u8 sup_pmk_r1_name[WPA_PMK_NAME_LEN]; /* PMKR1Name from EAPOL-Key
+ * message 2/4 */
+ u8 *assoc_resp_ftie;
#endif /* CONFIG_IEEE80211R */
};
@@ -212,10 +215,16 @@ void wpa_smk_m3(struct wpa_authenticator *wpa_auth,
#ifdef CONFIG_IEEE80211R
int wpa_write_mdie(struct wpa_auth_config *conf, u8 *buf, size_t len);
+int wpa_write_ftie(struct wpa_auth_config *conf, const u8 *r0kh_id,
+ size_t r0kh_id_len,
+ const u8 *anonce, const u8 *snonce,
+ u8 *buf, size_t len, const u8 *subelem,
+ size_t subelem_len);
int wpa_auth_derive_ptk_ft(struct wpa_state_machine *sm, const u8 *pmk,
struct wpa_ptk *ptk, size_t ptk_len);
struct wpa_ft_pmk_cache * wpa_ft_pmk_cache_init(void);
void wpa_ft_pmk_cache_deinit(struct wpa_ft_pmk_cache *cache);
+void wpa_ft_install_ptk(struct wpa_state_machine *sm);
#endif /* CONFIG_IEEE80211R */
#endif /* WPA_AUTH_I_H */
diff --git a/contrib/wpa/hostapd/wpa_auth_ie.c b/contrib/wpa/src/ap/wpa_auth_ie.c
index 7e01635..f8a1804 100644
--- a/contrib/wpa/hostapd/wpa_auth_ie.c
+++ b/contrib/wpa/src/ap/wpa_auth_ie.c
@@ -12,14 +12,15 @@
* See README and COPYING for more details.
*/
-#include "includes.h"
+#include "utils/includes.h"
-#include "common.h"
-#include "config.h"
+#include "utils/common.h"
+#include "common/ieee802_11_defs.h"
+#include "eapol_auth/eapol_auth_sm.h"
+#include "ap_config.h"
#include "ieee802_11.h"
-#include "eapol_sm.h"
-#include "wpa.h"
-#include "pmksa_cache.h"
+#include "wpa_auth.h"
+#include "pmksa_cache_auth.h"
#include "wpa_auth_ie.h"
#include "wpa_auth_i.h"
@@ -220,9 +221,9 @@ int wpa_write_rsn_ie(struct wpa_auth_config *conf, u8 *buf, size_t len,
capab |= (RSN_NUM_REPLAY_COUNTERS_16 << 2);
}
#ifdef CONFIG_IEEE80211W
- if (conf->ieee80211w != WPA_NO_IEEE80211W) {
+ if (conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
capab |= WPA_CAPABILITY_MFPC;
- if (conf->ieee80211w == IEEE80211W_REQUIRED)
+ if (conf->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED)
capab |= WPA_CAPABILITY_MFPR;
}
#endif /* CONFIG_IEEE80211W */
@@ -240,7 +241,7 @@ int wpa_write_rsn_ie(struct wpa_auth_config *conf, u8 *buf, size_t len,
}
#ifdef CONFIG_IEEE80211W
- if (conf->ieee80211w != WPA_NO_IEEE80211W) {
+ if (conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
if (pos + 2 + 4 > buf + len)
return -1;
if (pmkid == NULL) {
@@ -612,7 +613,7 @@ int wpa_validate_wpa_ie(struct wpa_authenticator *wpa_auth,
}
#ifdef CONFIG_IEEE80211W
- if (wpa_auth->conf.ieee80211w == WPA_IEEE80211W_REQUIRED) {
+ if (wpa_auth->conf.ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) {
if (!(data.capabilities & WPA_CAPABILITY_MFPC)) {
wpa_printf(MSG_DEBUG, "Management frame protection "
"required, but client did not enable it");
@@ -632,7 +633,7 @@ int wpa_validate_wpa_ie(struct wpa_authenticator *wpa_auth,
}
}
- if (wpa_auth->conf.ieee80211w == WPA_NO_IEEE80211W ||
+ if (wpa_auth->conf.ieee80211w == NO_MGMT_FRAME_PROTECTION ||
!(data.capabilities & WPA_CAPABILITY_MFPC))
sm->mgmt_frame_prot = 0;
else
@@ -670,8 +671,8 @@ int wpa_validate_wpa_ie(struct wpa_authenticator *wpa_auth,
for (i = 0; i < data.num_pmkid; i++) {
wpa_hexdump(MSG_DEBUG, "RSN IE: STA PMKID",
&data.pmkid[i * PMKID_LEN], PMKID_LEN);
- sm->pmksa = pmksa_cache_get(wpa_auth->pmksa, sm->addr,
- &data.pmkid[i * PMKID_LEN]);
+ sm->pmksa = pmksa_cache_auth_get(wpa_auth->pmksa, sm->addr,
+ &data.pmkid[i * PMKID_LEN]);
if (sm->pmksa) {
pmkid = sm->pmksa->pmkid;
break;
@@ -839,6 +840,9 @@ int wpa_parse_kde_ies(const u8 *buf, size_t len, struct wpa_eapol_ie_parse *ie)
} else if (*pos == WLAN_EID_MOBILITY_DOMAIN) {
ie->mdie = pos;
ie->mdie_len = pos[1] + 2;
+ } else if (*pos == WLAN_EID_FAST_BSS_TRANSITION) {
+ ie->ftie = pos;
+ ie->ftie_len = pos[1] + 2;
#endif /* CONFIG_IEEE80211R */
} else if (*pos == WLAN_EID_VENDOR_SPECIFIC) {
ret = wpa_parse_generic(pos, end, ie);
diff --git a/contrib/wpa/hostapd/wpa_auth_ie.h b/contrib/wpa/src/ap/wpa_auth_ie.h
index 9968d2d..61d4cb4 100644
--- a/contrib/wpa/hostapd/wpa_auth_ie.h
+++ b/contrib/wpa/src/ap/wpa_auth_ie.h
@@ -42,6 +42,8 @@ struct wpa_eapol_ie_parse {
#ifdef CONFIG_IEEE80211R
const u8 *mdie;
size_t mdie_len;
+ const u8 *ftie;
+ size_t ftie_len;
#endif /* CONFIG_IEEE80211R */
};
diff --git a/contrib/wpa/hostapd/wps_hostapd.c b/contrib/wpa/src/ap/wps_hostapd.c
index 818767e..a6ffd4d 100644
--- a/contrib/wpa/hostapd/wps_hostapd.c
+++ b/contrib/wpa/src/ap/wps_hostapd.c
@@ -1,6 +1,6 @@
/*
* hostapd / WPS integration
- * Copyright (c) 2008, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2008-2010, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -12,19 +12,24 @@
* See README and COPYING for more details.
*/
-#include "includes.h"
-
-#include "hostapd.h"
-#include "driver.h"
-#include "eloop.h"
-#include "uuid.h"
-#include "wpa_ctrl.h"
-#include "ieee802_11_defs.h"
-#include "sta_info.h"
-#include "eapol_sm.h"
+#include "utils/includes.h"
+
+#include "utils/common.h"
+#include "utils/eloop.h"
+#include "utils/uuid.h"
+#include "crypto/dh_groups.h"
+#include "common/wpa_ctrl.h"
+#include "common/ieee802_11_defs.h"
+#include "common/ieee802_11_common.h"
+#include "eapol_auth/eapol_auth_sm.h"
+#include "eapol_auth/eapol_auth_sm_i.h"
#include "wps/wps.h"
#include "wps/wps_defs.h"
#include "wps/wps_dev_attr.h"
+#include "hostapd.h"
+#include "ap_config.h"
+#include "beacon.h"
+#include "sta_info.h"
#include "wps_hostapd.h"
@@ -35,6 +40,10 @@ static int hostapd_wps_upnp_init(struct hostapd_data *hapd,
static void hostapd_wps_upnp_deinit(struct hostapd_data *hapd);
#endif /* CONFIG_WPS_UPNP */
+static int hostapd_wps_probe_req_rx(void *ctx, const u8 *addr,
+ const u8 *ie, size_t ie_len);
+static void hostapd_wps_ap_pin_timeout(void *eloop_data, void *user_ctx);
+
static int hostapd_wps_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *psk,
size_t psk_len)
@@ -83,46 +92,16 @@ static int hostapd_wps_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *psk,
}
-static int hostapd_wps_set_ie_cb(void *ctx, const u8 *beacon_ie,
- size_t beacon_ie_len, const u8 *probe_resp_ie,
- size_t probe_resp_ie_len)
+static int hostapd_wps_set_ie_cb(void *ctx, struct wpabuf *beacon_ie,
+ struct wpabuf *probe_resp_ie)
{
struct hostapd_data *hapd = ctx;
-
- os_free(hapd->wps_beacon_ie);
- if (beacon_ie_len == 0) {
- hapd->wps_beacon_ie = NULL;
- hapd->wps_beacon_ie_len = 0;
- } else {
- hapd->wps_beacon_ie = os_malloc(beacon_ie_len);
- if (hapd->wps_beacon_ie == NULL) {
- hapd->wps_beacon_ie_len = 0;
- return -1;
- }
- os_memcpy(hapd->wps_beacon_ie, beacon_ie, beacon_ie_len);
- hapd->wps_beacon_ie_len = beacon_ie_len;
- }
- hostapd_set_wps_beacon_ie(hapd, hapd->wps_beacon_ie,
- hapd->wps_beacon_ie_len);
-
- os_free(hapd->wps_probe_resp_ie);
- if (probe_resp_ie_len == 0) {
- hapd->wps_probe_resp_ie = NULL;
- hapd->wps_probe_resp_ie_len = 0;
- } else {
- hapd->wps_probe_resp_ie = os_malloc(probe_resp_ie_len);
- if (hapd->wps_probe_resp_ie == NULL) {
- hapd->wps_probe_resp_ie_len = 0;
- return -1;
- }
- os_memcpy(hapd->wps_probe_resp_ie, probe_resp_ie,
- probe_resp_ie_len);
- hapd->wps_probe_resp_ie_len = probe_resp_ie_len;
- }
- hostapd_set_wps_probe_resp_ie(hapd, hapd->wps_probe_resp_ie,
- hapd->wps_probe_resp_ie_len);
-
- return 0;
+ wpabuf_free(hapd->wps_beacon_ie);
+ hapd->wps_beacon_ie = beacon_ie;
+ wpabuf_free(hapd->wps_probe_resp_ie);
+ hapd->wps_probe_resp_ie = probe_resp_ie;
+ ieee802_11_set_beacon(hapd);
+ return hapd->drv.set_ap_wps_ie(hapd);
}
@@ -132,17 +111,19 @@ static void hostapd_wps_pin_needed_cb(void *ctx, const u8 *uuid_e,
struct hostapd_data *hapd = ctx;
char uuid[40], txt[400];
int len;
+ char devtype[WPS_DEV_TYPE_BUFSIZE];
if (uuid_bin2str(uuid_e, uuid, sizeof(uuid)))
return;
wpa_printf(MSG_DEBUG, "WPS: PIN needed for E-UUID %s", uuid);
len = os_snprintf(txt, sizeof(txt), WPS_EVENT_PIN_NEEDED
- "%s " MACSTR " [%s|%s|%s|%s|%s|%d-%08X-%d]",
+ "%s " MACSTR " [%s|%s|%s|%s|%s|%s]",
uuid, MAC2STR(dev->mac_addr), dev->device_name,
dev->manufacturer, dev->model_name,
dev->model_number, dev->serial_number,
- dev->categ, dev->oui, dev->sub_categ);
+ wps_dev_type_bin2str(dev->pri_dev_type, devtype,
+ sizeof(devtype)));
if (len > 0 && len < (int) sizeof(txt))
- wpa_msg(hapd, MSG_INFO, "%s", txt);
+ wpa_msg(hapd->msg_ctx, MSG_INFO, "%s", txt);
if (hapd->conf->wps_pin_requests) {
FILE *f;
@@ -152,11 +133,12 @@ static void hostapd_wps_pin_needed_cb(void *ctx, const u8 *uuid_e,
return;
os_get_time(&t);
fprintf(f, "%ld\t%s\t" MACSTR "\t%s\t%s\t%s\t%s\t%s"
- "\t%d-%08X-%d\n",
+ "\t%s\n",
t.sec, uuid, MAC2STR(dev->mac_addr), dev->device_name,
dev->manufacturer, dev->model_name, dev->model_number,
dev->serial_number,
- dev->categ, dev->oui, dev->sub_categ);
+ wps_dev_type_bin2str(dev->pri_dev_type, devtype,
+ sizeof(devtype)));
fclose(f);
}
}
@@ -169,8 +151,34 @@ static void hostapd_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
char uuid[40];
if (uuid_bin2str(uuid_e, uuid, sizeof(uuid)))
return;
- wpa_msg(hapd, MSG_INFO, WPS_EVENT_REG_SUCCESS MACSTR " %s",
+ wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_REG_SUCCESS MACSTR " %s",
MAC2STR(mac_addr), uuid);
+ if (hapd->wps_reg_success_cb)
+ hapd->wps_reg_success_cb(hapd->wps_reg_success_cb_ctx,
+ mac_addr, uuid_e);
+}
+
+
+static void hostapd_wps_enrollee_seen_cb(void *ctx, const u8 *addr,
+ const u8 *uuid_e,
+ const u8 *pri_dev_type,
+ u16 config_methods,
+ u16 dev_password_id, u8 request_type,
+ const char *dev_name)
+{
+ struct hostapd_data *hapd = ctx;
+ char uuid[40];
+ char devtype[WPS_DEV_TYPE_BUFSIZE];
+ if (uuid_bin2str(uuid_e, uuid, sizeof(uuid)))
+ return;
+ if (dev_name == NULL)
+ dev_name = "";
+ wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, WPS_EVENT_ENROLLEE_SEEN MACSTR
+ " %s %s 0x%x %u %u [%s]",
+ MAC2STR(addr), uuid,
+ wps_dev_type_bin2str(pri_dev_type, devtype,
+ sizeof(devtype)),
+ config_methods, dev_password_id, request_type, dev_name);
}
@@ -185,7 +193,7 @@ static void wps_reload_config(void *eloop_data, void *user_ctx)
struct hostapd_iface *iface = eloop_data;
wpa_printf(MSG_DEBUG, "WPS: Reload configuration data");
- if (hostapd_reload_config(iface) < 0) {
+ if (iface->reload_config(iface) < 0) {
wpa_printf(MSG_WARNING, "WPS: Failed to reload the updated "
"configuration");
}
@@ -223,12 +231,12 @@ static int hostapd_wps_cred_cb(void *ctx, const struct wps_credential *cred)
if (_buf) {
wpa_snprintf_hex(_buf, blen,
cred->cred_attr, cred->cred_attr_len);
- wpa_msg(hapd, MSG_INFO, "%s%s",
+ wpa_msg(hapd->msg_ctx, MSG_INFO, "%s%s",
WPS_EVENT_NEW_AP_SETTINGS, _buf);
os_free(_buf);
}
} else
- wpa_msg(hapd, MSG_INFO, WPS_EVENT_NEW_AP_SETTINGS);
+ wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_NEW_AP_SETTINGS);
if (hapd->conf->wps_cred_processing == 1)
return 0;
@@ -414,44 +422,58 @@ static int hostapd_wps_cred_cb(void *ctx, const struct wps_credential *cred)
}
+static void hostapd_wps_reenable_ap_pin(void *eloop_data, void *user_ctx)
+{
+ struct hostapd_data *hapd = eloop_data;
+
+ if (hapd->conf->ap_setup_locked)
+ return;
+
+ wpa_printf(MSG_DEBUG, "WPS: Re-enable AP PIN");
+ wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_AP_SETUP_UNLOCKED);
+ hapd->wps->ap_setup_locked = 0;
+ wps_registrar_update_ie(hapd->wps->registrar);
+}
+
+
static void hostapd_pwd_auth_fail(struct hostapd_data *hapd,
struct wps_event_pwd_auth_fail *data)
{
- FILE *f;
-
- if (!data->enrollee)
+ if (!data->enrollee || hapd->conf->ap_pin == NULL)
return;
/*
* Registrar failed to prove its knowledge of the AP PIN. Lock AP setup
- * if this happens multiple times.
+ * for some time if this happens multiple times to slow down brute
+ * force attacks.
*/
hapd->ap_pin_failures++;
- if (hapd->ap_pin_failures < 4)
+ wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
+ hapd->ap_pin_failures);
+ if (hapd->ap_pin_failures < 3)
return;
- wpa_msg(hapd, MSG_INFO, WPS_EVENT_AP_SETUP_LOCKED);
+ wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_AP_SETUP_LOCKED);
hapd->wps->ap_setup_locked = 1;
wps_registrar_update_ie(hapd->wps->registrar);
- if (hapd->conf->wps_cred_processing == 1)
- return;
+ if (!hapd->conf->ap_setup_locked) {
+ if (hapd->ap_pin_lockout_time == 0)
+ hapd->ap_pin_lockout_time = 60;
+ else if (hapd->ap_pin_lockout_time < 365 * 24 * 60 * 60 &&
+ (hapd->ap_pin_failures % 3) == 0)
+ hapd->ap_pin_lockout_time *= 2;
- f = fopen(hapd->iface->config_fname, "a");
- if (f == NULL) {
- wpa_printf(MSG_WARNING, "WPS: Could not append to the current "
- "configuration file");
- return;
+ wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN for %u seconds",
+ hapd->ap_pin_lockout_time);
+ eloop_cancel_timeout(hostapd_wps_reenable_ap_pin, hapd, NULL);
+ eloop_register_timeout(hapd->ap_pin_lockout_time, 0,
+ hostapd_wps_reenable_ap_pin, hapd,
+ NULL);
}
- fprintf(f, "# WPS AP Setup Locked based on possible attack\n");
- fprintf(f, "ap_setup_locked=1\n");
- fclose(f);
-
- /* TODO: dualband AP may need to update multiple configuration files */
-
- wpa_printf(MSG_DEBUG, "WPS: AP configuration updated");
+ /* TODO: dualband AP may need to update other interfaces */
}
@@ -467,15 +489,13 @@ static void hostapd_wps_event_cb(void *ctx, enum wps_event event,
static void hostapd_wps_clear_ies(struct hostapd_data *hapd)
{
- os_free(hapd->wps_beacon_ie);
+ wpabuf_free(hapd->wps_beacon_ie);
hapd->wps_beacon_ie = NULL;
- hapd->wps_beacon_ie_len = 0;
- hostapd_set_wps_beacon_ie(hapd, NULL, 0);
- os_free(hapd->wps_probe_resp_ie);
+ wpabuf_free(hapd->wps_probe_resp_ie);
hapd->wps_probe_resp_ie = NULL;
- hapd->wps_probe_resp_ie_len = 0;
- hostapd_set_wps_probe_resp_ie(hapd, NULL, 0);
+
+ hapd->drv.set_ap_wps_ie(hapd);
}
@@ -521,43 +541,14 @@ int hostapd_init_wps(struct hostapd_data *hapd,
os_strdup(hapd->conf->model_number) : NULL;
wps->dev.serial_number = hapd->conf->serial_number ?
os_strdup(hapd->conf->serial_number) : NULL;
- if (hapd->conf->config_methods) {
- char *m = hapd->conf->config_methods;
- if (os_strstr(m, "label"))
- wps->config_methods |= WPS_CONFIG_LABEL;
- if (os_strstr(m, "display"))
- wps->config_methods |= WPS_CONFIG_DISPLAY;
- if (os_strstr(m, "push_button"))
- wps->config_methods |= WPS_CONFIG_PUSHBUTTON;
- if (os_strstr(m, "keypad"))
- wps->config_methods |= WPS_CONFIG_KEYPAD;
- }
- if (hapd->conf->device_type) {
- char *pos;
- u8 oui[4];
- /* <categ>-<OUI>-<subcateg> */
- wps->dev.categ = atoi(hapd->conf->device_type);
- pos = os_strchr(hapd->conf->device_type, '-');
- if (pos == NULL) {
- wpa_printf(MSG_ERROR, "WPS: Invalid device_type");
- os_free(wps);
- return -1;
- }
- pos++;
- if (hexstr2bin(pos, oui, 4)) {
- wpa_printf(MSG_ERROR, "WPS: Invalid device_type OUI");
- os_free(wps);
- return -1;
- }
- wps->dev.oui = WPA_GET_BE32(oui);
- pos = os_strchr(pos, '-');
- if (pos == NULL) {
- wpa_printf(MSG_ERROR, "WPS: Invalid device_type");
- os_free(wps);
- return -1;
- }
- pos++;
- wps->dev.sub_categ = atoi(pos);
+ wps->config_methods =
+ wps_config_methods_str2bin(hapd->conf->config_methods);
+ if (hapd->conf->device_type &&
+ wps_dev_type_str2bin(hapd->conf->device_type,
+ wps->dev.pri_dev_type) < 0) {
+ wpa_printf(MSG_ERROR, "WPS: Invalid device_type");
+ os_free(wps);
+ return -1;
}
wps->dev.os_version = WPA_GET_BE32(hapd->conf->os_version);
wps->dev.rf_bands = hapd->iconf->hw_mode == HOSTAPD_MODE_IEEE80211A ?
@@ -629,6 +620,11 @@ int hostapd_init_wps(struct hostapd_data *hapd,
wps->network_key_len = conf->ssid.wep.len[0];
}
+ if (conf->ssid.wpa_psk) {
+ os_memcpy(wps->psk, conf->ssid.wpa_psk->psk, PMK_LEN);
+ wps->psk_set = 1;
+ }
+
if (conf->wps_state == WPS_STATE_NOT_CONFIGURED) {
/* Override parameters to enable security by default */
wps->auth_types = WPS_AUTH_WPA2PSK | WPS_AUTH_WPAPSK;
@@ -642,6 +638,7 @@ int hostapd_init_wps(struct hostapd_data *hapd,
cfg.set_ie_cb = hostapd_wps_set_ie_cb;
cfg.pin_needed_cb = hostapd_wps_pin_needed_cb;
cfg.reg_success_cb = hostapd_wps_reg_success_cb;
+ cfg.enrollee_seen_cb = hostapd_wps_enrollee_seen_cb;
cfg.cb_ctx = hapd;
cfg.skip_cred_build = conf->skip_cred_build;
cfg.extra_cred = conf->extra_cred;
@@ -675,6 +672,8 @@ int hostapd_init_wps(struct hostapd_data *hapd,
}
#endif /* CONFIG_WPS_UPNP */
+ hostapd_register_probereq_cb(hapd, hostapd_wps_probe_req_rx, hapd);
+
hapd->wps = wps;
return 0;
@@ -683,6 +682,8 @@ int hostapd_init_wps(struct hostapd_data *hapd,
void hostapd_deinit_wps(struct hostapd_data *hapd)
{
+ eloop_cancel_timeout(hostapd_wps_reenable_ap_pin, hapd, NULL);
+ eloop_cancel_timeout(hostapd_wps_ap_pin_timeout, hapd, NULL);
if (hapd->wps == NULL)
return;
#ifdef CONFIG_WPS_UPNP
@@ -691,6 +692,10 @@ void hostapd_deinit_wps(struct hostapd_data *hapd)
wps_registrar_deinit(hapd->wps->registrar);
os_free(hapd->wps->network_key);
wps_device_data_free(&hapd->wps->dev);
+ wpabuf_free(hapd->wps->dh_pubkey);
+ wpabuf_free(hapd->wps->dh_privkey);
+ wpabuf_free(hapd->wps->oob_conf.pubkey_hash);
+ wpabuf_free(hapd->wps->oob_conf.dev_password);
wps_free_pending_msgs(hapd->wps->upnp_msgs);
os_free(hapd->wps);
hapd->wps = NULL;
@@ -698,6 +703,17 @@ void hostapd_deinit_wps(struct hostapd_data *hapd)
}
+void hostapd_update_wps(struct hostapd_data *hapd)
+{
+ if (hapd->wps == NULL)
+ return;
+ if (hapd->conf->wps_state)
+ wps_registrar_update_ie(hapd->wps->registrar);
+ else
+ hostapd_deinit_wps(hapd);
+}
+
+
int hostapd_wps_add_pin(struct hostapd_data *hapd, const char *uuid,
const char *pin, int timeout)
{
@@ -724,48 +740,86 @@ int hostapd_wps_button_pushed(struct hostapd_data *hapd)
}
-void hostapd_wps_probe_req_rx(struct hostapd_data *hapd, const u8 *addr,
- const u8 *ie, size_t ie_len)
+#ifdef CONFIG_WPS_OOB
+int hostapd_wps_start_oob(struct hostapd_data *hapd, char *device_type,
+ char *path, char *method, char *name)
{
- struct wpabuf *wps_ie;
- const u8 *end, *pos, *wps;
-
- if (hapd->wps == NULL)
- return;
+ struct wps_context *wps = hapd->wps;
+ struct oob_device_data *oob_dev;
- pos = ie;
- end = ie + ie_len;
- wps = NULL;
+ oob_dev = wps_get_oob_device(device_type);
+ if (oob_dev == NULL)
+ return -1;
+ oob_dev->device_path = path;
+ oob_dev->device_name = name;
+ wps->oob_conf.oob_method = wps_get_oob_method(method);
- while (pos + 1 < end) {
- if (pos + 2 + pos[1] > end)
- return;
- if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
- WPA_GET_BE32(&pos[2]) == WPS_DEV_OUI_WFA) {
- wps = pos;
- break;
+ if (wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_R) {
+ /*
+ * Use pre-configured DH keys in order to be able to write the
+ * key hash into the OOB file.
+ */
+ wpabuf_free(wps->dh_pubkey);
+ wpabuf_free(wps->dh_privkey);
+ wps->dh_privkey = NULL;
+ wps->dh_pubkey = dh_init(dh_groups_get(WPS_DH_GROUP),
+ &wps->dh_privkey);
+ wps->dh_pubkey = wpabuf_zeropad(wps->dh_pubkey, 192);
+ if (wps->dh_pubkey == NULL) {
+ wpa_printf(MSG_ERROR, "WPS: Failed to initialize "
+ "Diffie-Hellman handshake");
+ return -1;
}
- pos += 2 + pos[1];
}
- if (wps == NULL)
- return; /* No WPS IE in Probe Request */
+ if (wps_process_oob(wps, oob_dev, 1) < 0)
+ goto error;
- wps_ie = wpabuf_alloc(ie_len);
- if (wps_ie == NULL)
- return;
+ if ((wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_E ||
+ wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_R) &&
+ hostapd_wps_add_pin(hapd, "any",
+ wpabuf_head(wps->oob_conf.dev_password), 0) <
+ 0)
+ goto error;
+
+ return 0;
+
+error:
+ wpabuf_free(wps->dh_pubkey);
+ wps->dh_pubkey = NULL;
+ wpabuf_free(wps->dh_privkey);
+ wps->dh_privkey = NULL;
+ return -1;
+}
+#endif /* CONFIG_WPS_OOB */
- /* There may be multiple WPS IEs in the message, so need to concatenate
- * their WPS Data fields */
- while (pos + 1 < end) {
- if (pos + 2 + pos[1] > end)
- break;
- if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
- WPA_GET_BE32(&pos[2]) == WPS_DEV_OUI_WFA)
- wpabuf_put_data(wps_ie, pos + 6, pos[1] - 4);
- pos += 2 + pos[1];
+
+static int hostapd_wps_probe_req_rx(void *ctx, const u8 *addr,
+ const u8 *ie, size_t ie_len)
+{
+ struct hostapd_data *hapd = ctx;
+ struct wpabuf *wps_ie;
+ struct ieee802_11_elems elems;
+
+ if (hapd->wps == NULL)
+ return 0;
+
+ if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
+ wpa_printf(MSG_DEBUG, "WPS: Could not parse ProbeReq from "
+ MACSTR, MAC2STR(addr));
+ return 0;
}
+ if (elems.ssid && elems.ssid_len > 0 &&
+ (elems.ssid_len != hapd->conf->ssid.ssid_len ||
+ os_memcmp(elems.ssid, hapd->conf->ssid.ssid, elems.ssid_len) !=
+ 0))
+ return 0; /* Not for us */
+
+ wps_ie = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
+ if (wps_ie == NULL)
+ return 0;
+
if (wpabuf_len(wps_ie) > 0) {
wps_registrar_probe_req_rx(hapd->wps->registrar, addr, wps_ie);
#ifdef CONFIG_WPS_UPNP
@@ -778,111 +832,12 @@ void hostapd_wps_probe_req_rx(struct hostapd_data *hapd, const u8 *addr,
}
wpabuf_free(wps_ie);
-}
-
-
-#ifdef CONFIG_WPS_UPNP
-
-static struct wpabuf *
-hostapd_rx_req_get_device_info(void *priv, struct upnp_wps_peer *peer)
-{
- struct hostapd_data *hapd = priv;
- struct wps_config cfg;
- struct wps_data *wps;
- enum wsc_op_code op_code;
- struct wpabuf *m1;
-
- /*
- * Request for DeviceInfo, i.e., M1 TLVs. This is a start of WPS
- * registration over UPnP with the AP acting as an Enrollee. It should
- * be noted that this is frequently used just to get the device data,
- * i.e., there may not be any intent to actually complete the
- * registration.
- */
-
- if (peer->wps)
- wps_deinit(peer->wps);
-
- os_memset(&cfg, 0, sizeof(cfg));
- cfg.wps = hapd->wps;
- cfg.pin = (u8 *) hapd->conf->ap_pin;
- cfg.pin_len = os_strlen(hapd->conf->ap_pin);
- wps = wps_init(&cfg);
- if (wps == NULL)
- return NULL;
-
- m1 = wps_get_msg(wps, &op_code);
- if (m1 == NULL) {
- wps_deinit(wps);
- return NULL;
- }
-
- peer->wps = wps;
-
- return m1;
-}
-
-
-static struct wpabuf *
-hostapd_rx_req_put_message(void *priv, struct upnp_wps_peer *peer,
- const struct wpabuf *msg)
-{
- enum wps_process_res res;
- enum wsc_op_code op_code;
-
- /* PutMessage: msg = InMessage, return OutMessage */
- res = wps_process_msg(peer->wps, WSC_UPnP, msg);
- if (res == WPS_FAILURE)
- return NULL;
- return wps_get_msg(peer->wps, &op_code);
-}
-
-static struct wpabuf *
-hostapd_rx_req_get_ap_settings(void *priv, const struct wpabuf *msg)
-{
- wpa_printf(MSG_DEBUG, "WPS UPnP: TODO %s", __func__);
- return NULL;
-}
-
-
-static int hostapd_rx_req_set_ap_settings(void *priv, const struct wpabuf *msg)
-{
- wpa_printf(MSG_DEBUG, "WPS UPnP: TODO %s", __func__);
- return -1;
-}
-
-
-static int hostapd_rx_req_del_ap_settings(void *priv, const struct wpabuf *msg)
-{
- wpa_printf(MSG_DEBUG, "WPS UPnP: TODO %s", __func__);
- return -1;
-}
-
-
-static struct wpabuf *
-hostapd_rx_req_get_sta_settings(void *priv, const struct wpabuf *msg)
-{
- wpa_printf(MSG_DEBUG, "WPS UPnP: TODO %s", __func__);
- return NULL;
-}
-
-
-static int hostapd_rx_req_set_sta_settings(void *priv,
- const struct wpabuf *msg)
-{
- wpa_printf(MSG_DEBUG, "WPS UPnP: TODO %s", __func__);
- return -1;
+ return 0;
}
-static int hostapd_rx_req_del_sta_settings(void *priv,
- const struct wpabuf *msg)
-{
- wpa_printf(MSG_DEBUG, "WPS UPnP: TODO %s", __func__);
- return -1;
-}
-
+#ifdef CONFIG_WPS_UPNP
static int hostapd_rx_req_put_wlan_response(
void *priv, enum upnp_wps_wlanevent_type ev_type,
@@ -941,42 +896,6 @@ static int hostapd_rx_req_put_wlan_response(
}
-static int hostapd_rx_req_set_selected_registrar(void *priv,
- const struct wpabuf *msg)
-{
- struct hostapd_data *hapd = priv;
- return wps_registrar_set_selected_registrar(hapd->wps->registrar, msg);
-}
-
-
-static int hostapd_rx_req_reboot_ap(void *priv, const struct wpabuf *msg)
-{
- wpa_printf(MSG_DEBUG, "WPS UPnP: TODO %s", __func__);
- return -1;
-}
-
-
-static int hostapd_rx_req_reset_ap(void *priv, const struct wpabuf *msg)
-{
- wpa_printf(MSG_DEBUG, "WPS UPnP: TODO %s", __func__);
- return -1;
-}
-
-
-static int hostapd_rx_req_reboot_sta(void *priv, const struct wpabuf *msg)
-{
- wpa_printf(MSG_DEBUG, "WPS UPnP: TODO %s", __func__);
- return -1;
-}
-
-
-static int hostapd_rx_req_reset_sta(void *priv, const struct wpabuf *msg)
-{
- wpa_printf(MSG_DEBUG, "WPS UPnP: TODO %s", __func__);
- return -1;
-}
-
-
static int hostapd_wps_upnp_init(struct hostapd_data *hapd,
struct wps_context *wps)
{
@@ -988,21 +907,9 @@ static int hostapd_wps_upnp_init(struct hostapd_data *hapd,
if (ctx == NULL)
return -1;
- ctx->rx_req_get_device_info = hostapd_rx_req_get_device_info;
- ctx->rx_req_put_message = hostapd_rx_req_put_message;
- ctx->rx_req_get_ap_settings = hostapd_rx_req_get_ap_settings;
- ctx->rx_req_set_ap_settings = hostapd_rx_req_set_ap_settings;
- ctx->rx_req_del_ap_settings = hostapd_rx_req_del_ap_settings;
- ctx->rx_req_get_sta_settings = hostapd_rx_req_get_sta_settings;
- ctx->rx_req_set_sta_settings = hostapd_rx_req_set_sta_settings;
- ctx->rx_req_del_sta_settings = hostapd_rx_req_del_sta_settings;
ctx->rx_req_put_wlan_response = hostapd_rx_req_put_wlan_response;
- ctx->rx_req_set_selected_registrar =
- hostapd_rx_req_set_selected_registrar;
- ctx->rx_req_reboot_ap = hostapd_rx_req_reboot_ap;
- ctx->rx_req_reset_ap = hostapd_rx_req_reset_ap;
- ctx->rx_req_reboot_sta = hostapd_rx_req_reboot_sta;
- ctx->rx_req_reset_sta = hostapd_rx_req_reset_sta;
+ if (hapd->conf->ap_pin)
+ ctx->ap_pin = os_strdup(hapd->conf->ap_pin);
hapd->wps_upnp = upnp_wps_device_init(ctx, wps, hapd);
if (hapd->wps_upnp == NULL) {
@@ -1027,3 +934,87 @@ static void hostapd_wps_upnp_deinit(struct hostapd_data *hapd)
}
#endif /* CONFIG_WPS_UPNP */
+
+
+int hostapd_wps_get_mib_sta(struct hostapd_data *hapd, const u8 *addr,
+ char *buf, size_t buflen)
+{
+ if (hapd->wps == NULL)
+ return 0;
+ return wps_registrar_get_info(hapd->wps->registrar, addr, buf, buflen);
+}
+
+
+static void hostapd_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
+{
+ struct hostapd_data *hapd = eloop_data;
+ wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
+ hostapd_wps_ap_pin_disable(hapd);
+}
+
+
+static void hostapd_wps_ap_pin_enable(struct hostapd_data *hapd, int timeout)
+{
+ wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
+ hapd->ap_pin_failures = 0;
+ hapd->conf->ap_setup_locked = 0;
+ if (hapd->wps->ap_setup_locked) {
+ wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_AP_SETUP_UNLOCKED);
+ hapd->wps->ap_setup_locked = 0;
+ wps_registrar_update_ie(hapd->wps->registrar);
+ }
+ eloop_cancel_timeout(hostapd_wps_ap_pin_timeout, hapd, NULL);
+ if (timeout > 0)
+ eloop_register_timeout(timeout, 0,
+ hostapd_wps_ap_pin_timeout, hapd, NULL);
+}
+
+
+void hostapd_wps_ap_pin_disable(struct hostapd_data *hapd)
+{
+ wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
+ os_free(hapd->conf->ap_pin);
+ hapd->conf->ap_pin = NULL;
+#ifdef CONFIG_WPS_UPNP
+ upnp_wps_set_ap_pin(hapd->wps_upnp, NULL);
+#endif /* CONFIG_WPS_UPNP */
+ eloop_cancel_timeout(hostapd_wps_ap_pin_timeout, hapd, NULL);
+}
+
+
+const char * hostapd_wps_ap_pin_random(struct hostapd_data *hapd, int timeout)
+{
+ unsigned int pin;
+ char pin_txt[9];
+
+ pin = wps_generate_pin();
+ os_snprintf(pin_txt, sizeof(pin_txt), "%u", pin);
+ os_free(hapd->conf->ap_pin);
+ hapd->conf->ap_pin = os_strdup(pin_txt);
+#ifdef CONFIG_WPS_UPNP
+ upnp_wps_set_ap_pin(hapd->wps_upnp, pin_txt);
+#endif /* CONFIG_WPS_UPNP */
+ hostapd_wps_ap_pin_enable(hapd, timeout);
+ return hapd->conf->ap_pin;
+}
+
+
+const char * hostapd_wps_ap_pin_get(struct hostapd_data *hapd)
+{
+ return hapd->conf->ap_pin;
+}
+
+
+int hostapd_wps_ap_pin_set(struct hostapd_data *hapd, const char *pin,
+ int timeout)
+{
+ os_free(hapd->conf->ap_pin);
+ hapd->conf->ap_pin = os_strdup(pin);
+ if (hapd->conf->ap_pin == NULL)
+ return -1;
+#ifdef CONFIG_WPS_UPNP
+ upnp_wps_set_ap_pin(hapd->wps_upnp, hapd->conf->ap_pin);
+#endif /* CONFIG_WPS_UPNP */
+ hostapd_wps_ap_pin_enable(hapd, timeout);
+ return 0;
+}
diff --git a/contrib/wpa/hostapd/wps_hostapd.h b/contrib/wpa/src/ap/wps_hostapd.h
index e949bee..e978a1c 100644
--- a/contrib/wpa/hostapd/wps_hostapd.h
+++ b/contrib/wpa/src/ap/wps_hostapd.h
@@ -1,6 +1,6 @@
/*
* hostapd / WPS integration
- * Copyright (c) 2008, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2008-2010, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -20,11 +20,19 @@
int hostapd_init_wps(struct hostapd_data *hapd,
struct hostapd_bss_config *conf);
void hostapd_deinit_wps(struct hostapd_data *hapd);
+void hostapd_update_wps(struct hostapd_data *hapd);
int hostapd_wps_add_pin(struct hostapd_data *hapd, const char *uuid,
const char *pin, int timeout);
int hostapd_wps_button_pushed(struct hostapd_data *hapd);
-void hostapd_wps_probe_req_rx(struct hostapd_data *hapd, const u8 *addr,
- const u8 *ie, size_t ie_len);
+int hostapd_wps_start_oob(struct hostapd_data *hapd, char *device_type,
+ char *path, char *method, char *name);
+int hostapd_wps_get_mib_sta(struct hostapd_data *hapd, const u8 *addr,
+ char *buf, size_t buflen);
+void hostapd_wps_ap_pin_disable(struct hostapd_data *hapd);
+const char * hostapd_wps_ap_pin_random(struct hostapd_data *hapd, int timeout);
+const char * hostapd_wps_ap_pin_get(struct hostapd_data *hapd);
+int hostapd_wps_ap_pin_set(struct hostapd_data *hapd, const char *pin,
+ int timeout);
#else /* CONFIG_WPS */
@@ -38,11 +46,22 @@ static inline void hostapd_deinit_wps(struct hostapd_data *hapd)
{
}
-static inline void hostapd_wps_probe_req_rx(struct hostapd_data *hapd,
- const u8 *addr,
- const u8 *ie, size_t ie_len)
+static inline void hostapd_update_wps(struct hostapd_data *hapd)
{
}
+
+static inline int hostapd_wps_get_mib_sta(struct hostapd_data *hapd,
+ const u8 *addr,
+ char *buf, size_t buflen)
+{
+ return 0;
+}
+
+static inline int hostapd_wps_button_pushed(struct hostapd_data *hapd)
+{
+ return 0;
+}
+
#endif /* CONFIG_WPS */
#endif /* WPS_HOSTAPD_H */
diff --git a/contrib/wpa/src/common/Makefile b/contrib/wpa/src/common/Makefile
index cffba62..9c41962 100644
--- a/contrib/wpa/src/common/Makefile
+++ b/contrib/wpa/src/common/Makefile
@@ -2,7 +2,6 @@ all:
@echo Nothing to be made.
clean:
- for d in $(SUBDIRS); do make -C $$d clean; done
rm -f *~ *.o *.d
install:
diff --git a/contrib/wpa/src/common/defs.h b/contrib/wpa/src/common/defs.h
index 4930e73..173bbd1 100644
--- a/contrib/wpa/src/common/defs.h
+++ b/contrib/wpa/src/common/defs.h
@@ -77,18 +77,44 @@ static inline int wpa_key_mgmt_sha256(int akm)
#define WPA_AUTH_ALG_OPEN BIT(0)
#define WPA_AUTH_ALG_SHARED BIT(1)
#define WPA_AUTH_ALG_LEAP BIT(2)
+#define WPA_AUTH_ALG_FT BIT(3)
-typedef enum { WPA_ALG_NONE, WPA_ALG_WEP, WPA_ALG_TKIP, WPA_ALG_CCMP,
- WPA_ALG_IGTK, WPA_ALG_PMK } wpa_alg;
-typedef enum { CIPHER_NONE, CIPHER_WEP40, CIPHER_TKIP, CIPHER_CCMP,
- CIPHER_WEP104 } wpa_cipher;
-typedef enum { KEY_MGMT_802_1X, KEY_MGMT_PSK, KEY_MGMT_NONE,
- KEY_MGMT_802_1X_NO_WPA, KEY_MGMT_WPA_NONE,
- KEY_MGMT_FT_802_1X, KEY_MGMT_FT_PSK,
- KEY_MGMT_802_1X_SHA256, KEY_MGMT_PSK_SHA256,
- KEY_MGMT_WPS
-} wpa_key_mgmt;
+enum wpa_alg {
+ WPA_ALG_NONE,
+ WPA_ALG_WEP,
+ WPA_ALG_TKIP,
+ WPA_ALG_CCMP,
+ WPA_ALG_IGTK,
+ WPA_ALG_PMK
+};
+
+/**
+ * enum wpa_cipher - Cipher suites
+ */
+enum wpa_cipher {
+ CIPHER_NONE,
+ CIPHER_WEP40,
+ CIPHER_TKIP,
+ CIPHER_CCMP,
+ CIPHER_WEP104
+};
+
+/**
+ * enum wpa_key_mgmt - Key management suites
+ */
+enum wpa_key_mgmt {
+ KEY_MGMT_802_1X,
+ KEY_MGMT_PSK,
+ KEY_MGMT_NONE,
+ KEY_MGMT_802_1X_NO_WPA,
+ KEY_MGMT_WPA_NONE,
+ KEY_MGMT_FT_802_1X,
+ KEY_MGMT_FT_PSK,
+ KEY_MGMT_802_1X_SHA256,
+ KEY_MGMT_PSK_SHA256,
+ KEY_MGMT_WPS
+};
/**
* enum wpa_states - wpa_supplicant state
@@ -100,7 +126,7 @@ typedef enum { KEY_MGMT_802_1X, KEY_MGMT_PSK, KEY_MGMT_NONE,
* wrapper functions wpa_sm_get_state() and wpa_sm_set_state() should be used
* to access the state variable.
*/
-typedef enum {
+enum wpa_states {
/**
* WPA_DISCONNECTED - Disconnected state
*
@@ -129,6 +155,16 @@ typedef enum {
WPA_SCANNING,
/**
+ * WPA_AUTHENTICATING - Trying to authenticate with a BSS/SSID
+ *
+ * This state is entered when wpa_supplicant has found a suitable BSS
+ * to authenticate with and the driver is configured to try to
+ * authenticate with this BSS. This state is used only with drivers
+ * that use wpa_supplicant as the SME.
+ */
+ WPA_AUTHENTICATING,
+
+ /**
* WPA_ASSOCIATING - Trying to associate with a BSS/SSID
*
* This state is entered when wpa_supplicant has found a suitable BSS
@@ -186,7 +222,7 @@ typedef enum {
* fully configured.
*/
WPA_COMPLETED
-} wpa_states;
+};
#define MLME_SETPROTECTION_PROTECT_TYPE_NONE 0
#define MLME_SETPROTECTION_PROTECT_TYPE_RX 1
@@ -196,4 +232,24 @@ typedef enum {
#define MLME_SETPROTECTION_KEY_TYPE_GROUP 0
#define MLME_SETPROTECTION_KEY_TYPE_PAIRWISE 1
+
+/**
+ * enum mfp_options - Management frame protection (IEEE 802.11w) options
+ */
+enum mfp_options {
+ NO_MGMT_FRAME_PROTECTION = 0,
+ MGMT_FRAME_PROTECTION_OPTIONAL = 1,
+ MGMT_FRAME_PROTECTION_REQUIRED = 2
+};
+
+/**
+ * enum hostapd_hw_mode - Hardware mode
+ */
+enum hostapd_hw_mode {
+ HOSTAPD_MODE_IEEE80211B,
+ HOSTAPD_MODE_IEEE80211G,
+ HOSTAPD_MODE_IEEE80211A,
+ NUM_HOSTAPD_MODES
+};
+
#endif /* DEFS_H */
diff --git a/contrib/wpa/src/common/ieee802_11_common.c b/contrib/wpa/src/common/ieee802_11_common.c
index 242f933..96ef5b6 100644
--- a/contrib/wpa/src/common/ieee802_11_common.c
+++ b/contrib/wpa/src/common/ieee802_11_common.c
@@ -1,6 +1,6 @@
/*
* IEEE 802.11 Common routines
- * Copyright (c) 2002-2008, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -19,7 +19,7 @@
#include "ieee802_11_common.h"
-static int ieee802_11_parse_vendor_specific(u8 *pos, size_t elen,
+static int ieee802_11_parse_vendor_specific(const u8 *pos, size_t elen,
struct ieee802_11_elems *elems,
int show_errors)
{
@@ -131,12 +131,12 @@ static int ieee802_11_parse_vendor_specific(u8 *pos, size_t elen,
* @show_errors: Whether to show parsing errors in debug log
* Returns: Parsing result
*/
-ParseRes ieee802_11_parse_elems(u8 *start, size_t len,
+ParseRes ieee802_11_parse_elems(const u8 *start, size_t len,
struct ieee802_11_elems *elems,
int show_errors)
{
size_t left = len;
- u8 *pos = start;
+ const u8 *pos = start;
int unknown = 0;
os_memset(elems, 0, sizeof(*elems));
@@ -257,3 +257,70 @@ ParseRes ieee802_11_parse_elems(u8 *start, size_t len,
return unknown ? ParseUnknown : ParseOK;
}
+
+
+int ieee802_11_ie_count(const u8 *ies, size_t ies_len)
+{
+ int count = 0;
+ const u8 *pos, *end;
+
+ if (ies == NULL)
+ return 0;
+
+ pos = ies;
+ end = ies + ies_len;
+
+ while (pos + 2 <= end) {
+ if (pos + 2 + pos[1] > end)
+ break;
+ count++;
+ pos += 2 + pos[1];
+ }
+
+ return count;
+}
+
+
+struct wpabuf * ieee802_11_vendor_ie_concat(const u8 *ies, size_t ies_len,
+ u32 oui_type)
+{
+ struct wpabuf *buf;
+ const u8 *end, *pos, *ie;
+
+ pos = ies;
+ end = ies + ies_len;
+ ie = NULL;
+
+ while (pos + 1 < end) {
+ if (pos + 2 + pos[1] > end)
+ return NULL;
+ if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
+ WPA_GET_BE32(&pos[2]) == oui_type) {
+ ie = pos;
+ break;
+ }
+ pos += 2 + pos[1];
+ }
+
+ if (ie == NULL)
+ return NULL; /* No specified vendor IE found */
+
+ buf = wpabuf_alloc(ies_len);
+ if (buf == NULL)
+ return NULL;
+
+ /*
+ * There may be multiple vendor IEs in the message, so need to
+ * concatenate their data fields.
+ */
+ while (pos + 1 < end) {
+ if (pos + 2 + pos[1] > end)
+ break;
+ if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
+ WPA_GET_BE32(&pos[2]) == oui_type)
+ wpabuf_put_data(buf, pos + 6, pos[1] - 4);
+ pos += 2 + pos[1];
+ }
+
+ return buf;
+}
diff --git a/contrib/wpa/src/common/ieee802_11_common.h b/contrib/wpa/src/common/ieee802_11_common.h
index b7e497b..4a4f5a7 100644
--- a/contrib/wpa/src/common/ieee802_11_common.h
+++ b/contrib/wpa/src/common/ieee802_11_common.h
@@ -1,6 +1,6 @@
/*
* IEEE 802.11 Common routines
- * Copyright (c) 2002-2008, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -17,58 +17,62 @@
/* Parsed Information Elements */
struct ieee802_11_elems {
- u8 *ssid;
+ const u8 *ssid;
+ const u8 *supp_rates;
+ const u8 *fh_params;
+ const u8 *ds_params;
+ const u8 *cf_params;
+ const u8 *tim;
+ const u8 *ibss_params;
+ const u8 *challenge;
+ const u8 *erp_info;
+ const u8 *ext_supp_rates;
+ const u8 *wpa_ie;
+ const u8 *rsn_ie;
+ const u8 *wmm; /* WMM Information or Parameter Element */
+ const u8 *wmm_tspec;
+ const u8 *wps_ie;
+ const u8 *power_cap;
+ const u8 *supp_channels;
+ const u8 *mdie;
+ const u8 *ftie;
+ const u8 *timeout_int;
+ const u8 *ht_capabilities;
+ const u8 *ht_operation;
+ const u8 *vendor_ht_cap;
+
u8 ssid_len;
- u8 *supp_rates;
u8 supp_rates_len;
- u8 *fh_params;
u8 fh_params_len;
- u8 *ds_params;
u8 ds_params_len;
- u8 *cf_params;
u8 cf_params_len;
- u8 *tim;
u8 tim_len;
- u8 *ibss_params;
u8 ibss_params_len;
- u8 *challenge;
u8 challenge_len;
- u8 *erp_info;
u8 erp_info_len;
- u8 *ext_supp_rates;
u8 ext_supp_rates_len;
- u8 *wpa_ie;
u8 wpa_ie_len;
- u8 *rsn_ie;
u8 rsn_ie_len;
- u8 *wmm; /* WMM Information or Parameter Element */
u8 wmm_len; /* 7 = WMM Information; 24 = WMM Parameter */
- u8 *wmm_tspec;
u8 wmm_tspec_len;
- u8 *wps_ie;
u8 wps_ie_len;
- u8 *power_cap;
u8 power_cap_len;
- u8 *supp_channels;
u8 supp_channels_len;
- u8 *mdie;
u8 mdie_len;
- u8 *ftie;
u8 ftie_len;
- u8 *timeout_int;
u8 timeout_int_len;
- u8 *ht_capabilities;
u8 ht_capabilities_len;
- u8 *ht_operation;
u8 ht_operation_len;
- u8 *vendor_ht_cap;
u8 vendor_ht_cap_len;
};
typedef enum { ParseOK = 0, ParseUnknown = 1, ParseFailed = -1 } ParseRes;
-ParseRes ieee802_11_parse_elems(u8 *start, size_t len,
+ParseRes ieee802_11_parse_elems(const u8 *start, size_t len,
struct ieee802_11_elems *elems,
int show_errors);
+int ieee802_11_ie_count(const u8 *ies, size_t ies_len);
+struct wpabuf * ieee802_11_vendor_ie_concat(const u8 *ies, size_t ies_len,
+ u32 oui_type);
#endif /* IEEE802_11_COMMON_H */
diff --git a/contrib/wpa/src/common/ieee802_11_defs.h b/contrib/wpa/src/common/ieee802_11_defs.h
index d9e54a9..4881e39 100644
--- a/contrib/wpa/src/common/ieee802_11_defs.h
+++ b/contrib/wpa/src/common/ieee802_11_defs.h
@@ -1,6 +1,6 @@
/*
* IEEE 802.11 Frame type definitions
- * Copyright (c) 2002-2007, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
* Copyright (c) 2007-2008 Intel Corporation
*
* This program is free software; you can redistribute it and/or modify
@@ -116,9 +116,13 @@
#define WLAN_STATUS_ASSOC_DENIED_NO_SHORT_SLOT_TIME 25
#define WLAN_STATUS_ASSOC_DENIED_NO_ER_PBCC 26
#define WLAN_STATUS_ASSOC_DENIED_NO_DSSS_OFDM 27
+#define WLAN_STATUS_R0KH_UNREACHABLE 28
/* IEEE 802.11w */
#define WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY 30
#define WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION 31
+#define WLAN_STATUS_UNSPECIFIED_QOS_FAILURE 32
+#define WLAN_STATUS_REQUEST_DECLINED 37
+#define WLAN_STATUS_INVALID_PARAMETERS 38
/* IEEE 802.11i */
#define WLAN_STATUS_INVALID_IE 40
#define WLAN_STATUS_GROUP_CIPHER_NOT_VALID 41
@@ -233,6 +237,25 @@
#pragma pack(push, 1)
#endif /* _MSC_VER */
+struct ieee80211_hdr {
+ le16 frame_control;
+ le16 duration_id;
+ u8 addr1[6];
+ u8 addr2[6];
+ u8 addr3[6];
+ le16 seq_ctrl;
+ /* followed by 'u8 addr4[6];' if ToDS and FromDS is set in data frame
+ */
+} STRUCT_PACKED;
+
+#define IEEE80211_DA_FROMDS addr1
+#define IEEE80211_BSSID_FROMDS addr2
+#define IEEE80211_SA_FROMDS addr3
+
+#define IEEE80211_HDRLEN (sizeof(struct ieee80211_hdr))
+
+#define IEEE80211_FC(type, stype) host_to_le16((type << 2) | (stype << 4))
+
struct ieee80211_mgmt {
le16 frame_control;
le16 duration;
@@ -337,45 +360,14 @@ struct ieee80211_mgmt {
} u;
} STRUCT_PACKED;
-#ifdef _MSC_VER
-#pragma pack(pop)
-#endif /* _MSC_VER */
-
-#define ERP_INFO_NON_ERP_PRESENT BIT(0)
-#define ERP_INFO_USE_PROTECTION BIT(1)
-#define ERP_INFO_BARKER_PREAMBLE_MODE BIT(2)
-
-
-/* HT Capability element */
-
-enum {
- MAX_RX_AMPDU_FACTOR_8KB = 0,
- MAX_RX_AMPDU_FACTOR_16KB,
- MAX_RX_AMPDU_FACTOR_32KB,
- MAX_RX_AMPDU_FACTOR_64KB
-};
-
-enum {
- CALIBRATION_NOT_SUPPORTED = 0,
- CALIBRATION_CANNOT_INIT,
- CALIBRATION_CAN_INIT,
- CALIBRATION_FULL_SUPPORT
-};
-enum {
- MCS_FEEDBACK_NOT_PROVIDED = 0,
- MCS_FEEDBACK_UNSOLICITED,
- MCS_FEEDBACK_MRQ_RESPONSE
-};
-
-
-struct ieee80211_ht_capability {
- le16 capabilities_info;
- u8 mac_ht_params_info;
+struct ieee80211_ht_capabilities {
+ le16 ht_capabilities_info;
+ u8 a_mpdu_params;
u8 supported_mcs_set[16];
- le16 extended_ht_capability_info;
- le32 tx_BF_capability_info;
- u8 antenna_selection_info;
+ le16 ht_extended_capabilities;
+ le32 tx_bf_capability_info;
+ u8 asel_capabilities;
} STRUCT_PACKED;
@@ -387,47 +379,13 @@ struct ieee80211_ht_operation {
u8 basic_set[16];
} STRUCT_PACKED;
-/* auxiliary bit manipulation macros FIXME: move it to common later... */
-#define SET_2BIT_U8(_ptr_, _shift_, _val_) \
- ((*(_ptr_) &= ~(3 << (_shift_))), \
- (*(_ptr_) |= (*(_ptr_) & (((u8)3) << (_shift_))) | \
- (((u8)(_val_) & 3) << _shift_)))
-
-#define GET_2BIT_U8(_var_, _shift_) \
- (((_var_) & (((u8)3) << (_shift_))) >> (_shift_))
-
-#define SET_2BIT_LE16(_u16ptr_, _shift_, _val_) \
- ((*(_u16ptr_) &= ~(3 << (_shift_))), \
- (*(_u16ptr_) |= \
- (((*(_u16ptr_)) & (((u16)3) << ((u16)_shift_))) | \
- (((u16)(_val_) & (u16)3) << (u16)(_shift_)))))
-
-#define GET_2BIT_LE16(_var_, _shift_) \
- (((_var_) & (((u16)3) << (_shift_))) >> (_shift_))
-
-#define SET_2BIT_LE32(_u32ptr_, _shift_, _val_) \
- ((*(_u32ptr_) &= ~(3 << (_shift_))), \
- (*(_u32ptr_) |= (((*(_u32ptr_)) & (((u32)3) << (_shift_))) | \
- (((u32)(_val_) & 3) << _shift_))))
-
-#define GET_2BIT_LE32(_var_, _shift_) \
- (((_var_) & (((u32)3) << (_shift_))) >> (_shift_))
-
-#define SET_3BIT_LE16(_u16ptr_, _shift_, _val_) \
- ((*(_u16ptr_) &= ~(7 << (_shift_))), \
- (*(_u16ptr_) |= (((*(_u16ptr_)) & (((u16)7) << (_shift_))) | \
- (((u16)(_val_) & 7) << _shift_))))
-
-#define GET_3BIT_LE16(_var_, _shift_) \
- (((_var_) & (((u16)7) << (_shift_))) >> (_shift_))
-
-#define SET_3BIT_LE32(_u32ptr_, _shift_, _val_) \
- ((*(_u32ptr_) &= ~(7 << (_shift_))), \
- (*(_u32ptr_) |= (((*(_u32ptr_)) & (((u32)7) << (_shift_))) | \
- (((u32)(_val_) & 7) << _shift_))))
+#ifdef _MSC_VER
+#pragma pack(pop)
+#endif /* _MSC_VER */
-#define GET_3BIT_LE32(_var_, _shift_) \
- (((_var_) & (((u32)7) << (_shift_))) >> (_shift_))
+#define ERP_INFO_NON_ERP_PRESENT BIT(0)
+#define ERP_INFO_USE_PROTECTION BIT(1)
+#define ERP_INFO_BARKER_PREAMBLE_MODE BIT(2)
#define HT_CAP_INFO_LDPC_CODING_CAP ((u16) BIT(0))
@@ -452,9 +410,6 @@ struct ieee80211_ht_operation {
#define HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT ((u16) BIT(15))
-#define MAC_HT_PARAM_INFO_MAX_RX_AMPDU_FACTOR_OFFSET 0
-#define MAC_HT_PARAM_INFO_MAX_MPDU_DENSITY_OFFSET 2
-
#define EXT_HT_CAP_INFO_PCO ((u16) BIT(0))
#define EXT_HT_CAP_INFO_TRANS_TIME_OFFSET 1
#define EXT_HT_CAP_INFO_MCS_FEEDBACK_OFFSET 8
@@ -490,22 +445,6 @@ struct ieee80211_ht_operation {
#define ASEL_CAPABILITY_RX_AS_CAP ((u8) BIT(5))
#define ASEL_CAPABILITY_TX_SOUND_PPDUS_CAP ((u8) BIT(6))
-
-struct ht_cap_ie {
- u8 id;
- u8 length;
- struct ieee80211_ht_capability data;
-} STRUCT_PACKED;
-
-
-#define REC_TRANS_CHNL_WIDTH_20 0
-#define REC_TRANS_CHNL_WIDTH_ANY 1
-
-#define OP_MODE_PURE 0
-#define OP_MODE_MAY_BE_LEGACY_STAS 1
-#define OP_MODE_20MHZ_HT_STA_ASSOCED 2
-#define OP_MODE_MIXED 3
-
#define HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK ((u8) BIT(0) | BIT(1))
#define HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE ((u8) BIT(0))
#define HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW ((u8) BIT(0) | BIT(1))
@@ -514,6 +453,12 @@ struct ht_cap_ie {
#define HT_INFO_HT_PARAM_CTRL_ACCESS_ONLY ((u8) BIT(4))
#define HT_INFO_HT_PARAM_SRV_INTERVAL_GRANULARITY ((u8) BIT(5))
+
+#define OP_MODE_PURE 0
+#define OP_MODE_MAY_BE_LEGACY_STAS 1
+#define OP_MODE_20MHZ_HT_STA_ASSOCED 2
+#define OP_MODE_MIXED 3
+
#define HT_INFO_OPERATION_MODE_OP_MODE_MASK \
((le16) (0x0001 | 0x0002))
#define HT_INFO_OPERATION_MODE_OP_MODE_OFFSET 0
@@ -529,39 +474,10 @@ struct ht_cap_ie {
#define HT_INFO_STBC_PARAM_PCO_PHASE ((u16) BIT(11))
-/* Secondary channel offset element */
-#define SECONDARY_CHANNEL_OFFSET_NONE 0
-#define SECONDARY_CHANNEL_OFFSET_ABOVE 1
-#define SECONDARY_CHANNEL_OFFSET_BELOW 3
-struct secondary_channel_offset_ie {
- u8 id;
- u8 length;
- u8 secondary_offset_offset;
-} STRUCT_PACKED;
-
-
-/* body of Recommended Transmit Channel Width action frame */
-#define CHANNEL_WIDTH_20 0
-#define CHANNEL_WIDTH_ANY 1
-struct recommended_tx_channel_width_action {
- u8 category;
- u8 action;
- u8 channel_width;
-} STRUCT_PACKED;
-
-/* body of MIMO Power Save action frame */
-#define PWR_SAVE_MODE_STATIC 0
-#define PWR_SAVE_MODE_DYNAMIC 1
-struct mimo_pwr_save_action {
- u8 category;
- u8 action;
- u8 enable;
- u8 mode;
-} STRUCT_PACKED;
-
-
#define OUI_MICROSOFT 0x0050f2 /* Microsoft (also used in Wi-Fi specs)
* 00:50:F2 */
+#define WPA_IE_VENDOR_TYPE 0x0050f201
+#define WPS_IE_VENDOR_TYPE 0x0050f204
#define WMM_OUI_TYPE 2
#define WMM_OUI_SUBTYPE_INFORMATION_ELEMENT 0
@@ -585,9 +501,107 @@ struct mimo_pwr_save_action {
/* 2 - Reserved */
#define WMM_TSPEC_DIRECTION_BI_DIRECTIONAL 3
+/*
+ * WMM Information Element (used in (Re)Association Request frames; may also be
+ * used in Beacon frames)
+ */
+struct wmm_information_element {
+ /* Element ID: 221 (0xdd); Length: 7 */
+ /* required fields for WMM version 1 */
+ u8 oui[3]; /* 00:50:f2 */
+ u8 oui_type; /* 2 */
+ u8 oui_subtype; /* 0 */
+ u8 version; /* 1 for WMM version 1.0 */
+ u8 qos_info; /* AP/STA specific QoS info */
+
+} STRUCT_PACKED;
+
+#define WMM_AC_AIFSN_MASK 0x0f
+#define WMM_AC_AIFNS_SHIFT 0
+#define WMM_AC_ACM 0x10
+#define WMM_AC_ACI_MASK 0x60
+#define WMM_AC_ACI_SHIFT 5
+
+#define WMM_AC_ECWMIN_MASK 0x0f
+#define WMM_AC_ECWMIN_SHIFT 0
+#define WMM_AC_ECWMAX_MASK 0xf0
+#define WMM_AC_ECWMAX_SHIFT 4
+
+struct wmm_ac_parameter {
+ u8 aci_aifsn; /* AIFSN, ACM, ACI */
+ u8 cw; /* ECWmin, ECWmax (CW = 2^ECW - 1) */
+ le16 txop_limit;
+} STRUCT_PACKED;
+
+/*
+ * WMM Parameter Element (used in Beacon, Probe Response, and (Re)Association
+ * Response frmaes)
+ */
+struct wmm_parameter_element {
+ /* Element ID: 221 (0xdd); Length: 24 */
+ /* required fields for WMM version 1 */
+ u8 oui[3]; /* 00:50:f2 */
+ u8 oui_type; /* 2 */
+ u8 oui_subtype; /* 1 */
+ u8 version; /* 1 for WMM version 1.0 */
+ u8 qos_info; /* AP/STA specif QoS info */
+ u8 reserved; /* 0 */
+ struct wmm_ac_parameter ac[4]; /* AC_BE, AC_BK, AC_VI, AC_VO */
+
+} STRUCT_PACKED;
+
+/* WMM TSPEC Element */
+struct wmm_tspec_element {
+ u8 eid; /* 221 = 0xdd */
+ u8 length; /* 6 + 55 = 61 */
+ u8 oui[3]; /* 00:50:f2 */
+ u8 oui_type; /* 2 */
+ u8 oui_subtype; /* 2 */
+ u8 version; /* 1 */
+ /* WMM TSPEC body (55 octets): */
+ u8 ts_info[3];
+ le16 nominal_msdu_size;
+ le16 maximum_msdu_size;
+ le32 minimum_service_interval;
+ le32 maximum_service_interval;
+ le32 inactivity_interval;
+ le32 suspension_interval;
+ le32 service_start_time;
+ le32 minimum_data_rate;
+ le32 mean_data_rate;
+ le32 peak_data_rate;
+ le32 maximum_burst_size;
+ le32 delay_bound;
+ le32 minimum_phy_rate;
+ le16 surplus_bandwidth_allowance;
+ le16 medium_time;
+} STRUCT_PACKED;
+
+
+/* Access Categories / ACI to AC coding */
+enum {
+ WMM_AC_BE = 0 /* Best Effort */,
+ WMM_AC_BK = 1 /* Background */,
+ WMM_AC_VI = 2 /* Video */,
+ WMM_AC_VO = 3 /* Voice */
+};
+
#define OUI_BROADCOM 0x00904c /* Broadcom (Epigram) */
#define VENDOR_HT_CAPAB_OUI_TYPE 0x33 /* 00-90-4c:0x33 */
+/* cipher suite selectors */
+#define WLAN_CIPHER_SUITE_USE_GROUP 0x000FAC00
+#define WLAN_CIPHER_SUITE_WEP40 0x000FAC01
+#define WLAN_CIPHER_SUITE_TKIP 0x000FAC02
+/* reserved: 0x000FAC03 */
+#define WLAN_CIPHER_SUITE_CCMP 0x000FAC04
+#define WLAN_CIPHER_SUITE_WEP104 0x000FAC05
+#define WLAN_CIPHER_SUITE_AES_CMAC 0x000FAC06
+
+/* AKM suite selectors */
+#define WLAN_AKM_SUITE_8021X 0x000FAC01
+#define WLAN_AKM_SUITE_PSK 0x000FAC02
+
#endif /* IEEE802_11_DEFS_H */
diff --git a/contrib/wpa/src/common/privsep_commands.h b/contrib/wpa/src/common/privsep_commands.h
index 81b7f54..cc900be 100644
--- a/contrib/wpa/src/common/privsep_commands.h
+++ b/contrib/wpa/src/common/privsep_commands.h
@@ -18,7 +18,6 @@
enum privsep_cmd {
PRIVSEP_CMD_REGISTER,
PRIVSEP_CMD_UNREGISTER,
- PRIVSEP_CMD_SET_WPA,
PRIVSEP_CMD_SCAN,
PRIVSEP_CMD_GET_SCAN_RESULTS,
PRIVSEP_CMD_ASSOCIATE,
@@ -30,7 +29,6 @@ enum privsep_cmd {
PRIVSEP_CMD_L2_UNREGISTER,
PRIVSEP_CMD_L2_NOTIFY_AUTH_START,
PRIVSEP_CMD_L2_SEND,
- PRIVSEP_CMD_SET_MODE,
PRIVSEP_CMD_SET_COUNTRY,
};
@@ -72,7 +70,6 @@ enum privsep_event {
PRIVSEP_EVENT_STKSTART,
PRIVSEP_EVENT_FT_RESPONSE,
PRIVSEP_EVENT_RX_EAPOL,
- PRIVSEP_EVENT_STA_RX,
};
#endif /* PRIVSEP_COMMANDS_H */
diff --git a/contrib/wpa/src/common/version.h b/contrib/wpa/src/common/version.h
index b79c494..02f34be 100644
--- a/contrib/wpa/src/common/version.h
+++ b/contrib/wpa/src/common/version.h
@@ -1,6 +1,6 @@
#ifndef VERSION_H
#define VERSION_H
-#define VERSION_STR "0.6.10"
+#define VERSION_STR "0.7.3"
#endif /* VERSION_H */
diff --git a/contrib/wpa/src/common/wpa_common.c b/contrib/wpa/src/common/wpa_common.c
index 074cb80..b295f31 100644
--- a/contrib/wpa/src/common/wpa_common.c
+++ b/contrib/wpa/src/common/wpa_common.c
@@ -15,11 +15,11 @@
#include "includes.h"
#include "common.h"
-#include "md5.h"
-#include "sha1.h"
-#include "sha256.h"
-#include "aes_wrap.h"
-#include "crypto.h"
+#include "crypto/md5.h"
+#include "crypto/sha1.h"
+#include "crypto/sha256.h"
+#include "crypto/aes_wrap.h"
+#include "crypto/crypto.h"
#include "ieee802_11_defs.h"
#include "defs.h"
#include "wpa_common.h"
@@ -50,10 +50,10 @@ int wpa_eapol_key_mic(const u8 *key, int ver, const u8 *buf, size_t len,
switch (ver) {
case WPA_KEY_INFO_TYPE_HMAC_MD5_RC4:
- hmac_md5(key, 16, buf, len, mic);
- break;
+ return hmac_md5(key, 16, buf, len, mic);
case WPA_KEY_INFO_TYPE_HMAC_SHA1_AES:
- hmac_sha1(key, 16, buf, len, hash);
+ if (hmac_sha1(key, 16, buf, len, hash))
+ return -1;
os_memcpy(mic, hash, MD5_MAC_LEN);
break;
#if defined(CONFIG_IEEE80211R) || defined(CONFIG_IEEE80211W)
@@ -568,3 +568,220 @@ void wpa_pmk_r1_to_ptk(const u8 *pmk_r1, const u8 *snonce, const u8 *anonce,
}
#endif /* CONFIG_IEEE80211R */
+
+
+/**
+ * rsn_pmkid - Calculate PMK identifier
+ * @pmk: Pairwise master key
+ * @pmk_len: Length of pmk in bytes
+ * @aa: Authenticator address
+ * @spa: Supplicant address
+ * @pmkid: Buffer for PMKID
+ * @use_sha256: Whether to use SHA256-based KDF
+ *
+ * IEEE Std 802.11i-2004 - 8.5.1.2 Pairwise key hierarchy
+ * PMKID = HMAC-SHA1-128(PMK, "PMK Name" || AA || SPA)
+ */
+void rsn_pmkid(const u8 *pmk, size_t pmk_len, const u8 *aa, const u8 *spa,
+ u8 *pmkid, int use_sha256)
+{
+ char *title = "PMK Name";
+ const u8 *addr[3];
+ const size_t len[3] = { 8, ETH_ALEN, ETH_ALEN };
+ unsigned char hash[SHA256_MAC_LEN];
+
+ addr[0] = (u8 *) title;
+ addr[1] = aa;
+ addr[2] = spa;
+
+#ifdef CONFIG_IEEE80211W
+ if (use_sha256)
+ hmac_sha256_vector(pmk, pmk_len, 3, addr, len, hash);
+ else
+#endif /* CONFIG_IEEE80211W */
+ hmac_sha1_vector(pmk, pmk_len, 3, addr, len, hash);
+ os_memcpy(pmkid, hash, PMKID_LEN);
+}
+
+
+/**
+ * wpa_cipher_txt - Convert cipher suite to a text string
+ * @cipher: Cipher suite (WPA_CIPHER_* enum)
+ * Returns: Pointer to a text string of the cipher suite name
+ */
+const char * wpa_cipher_txt(int cipher)
+{
+ switch (cipher) {
+ case WPA_CIPHER_NONE:
+ return "NONE";
+ case WPA_CIPHER_WEP40:
+ return "WEP-40";
+ case WPA_CIPHER_WEP104:
+ return "WEP-104";
+ case WPA_CIPHER_TKIP:
+ return "TKIP";
+ case WPA_CIPHER_CCMP:
+ return "CCMP";
+ case WPA_CIPHER_CCMP | WPA_CIPHER_TKIP:
+ return "CCMP+TKIP";
+ default:
+ return "UNKNOWN";
+ }
+}
+
+
+/**
+ * wpa_key_mgmt_txt - Convert key management suite to a text string
+ * @key_mgmt: Key management suite (WPA_KEY_MGMT_* enum)
+ * @proto: WPA/WPA2 version (WPA_PROTO_*)
+ * Returns: Pointer to a text string of the key management suite name
+ */
+const char * wpa_key_mgmt_txt(int key_mgmt, int proto)
+{
+ switch (key_mgmt) {
+ case WPA_KEY_MGMT_IEEE8021X:
+ if (proto == (WPA_PROTO_RSN | WPA_PROTO_WPA))
+ return "WPA2+WPA/IEEE 802.1X/EAP";
+ return proto == WPA_PROTO_RSN ?
+ "WPA2/IEEE 802.1X/EAP" : "WPA/IEEE 802.1X/EAP";
+ case WPA_KEY_MGMT_PSK:
+ if (proto == (WPA_PROTO_RSN | WPA_PROTO_WPA))
+ return "WPA2-PSK+WPA-PSK";
+ return proto == WPA_PROTO_RSN ?
+ "WPA2-PSK" : "WPA-PSK";
+ case WPA_KEY_MGMT_NONE:
+ return "NONE";
+ case WPA_KEY_MGMT_IEEE8021X_NO_WPA:
+ return "IEEE 802.1X (no WPA)";
+#ifdef CONFIG_IEEE80211R
+ case WPA_KEY_MGMT_FT_IEEE8021X:
+ return "FT-EAP";
+ case WPA_KEY_MGMT_FT_PSK:
+ return "FT-PSK";
+#endif /* CONFIG_IEEE80211R */
+#ifdef CONFIG_IEEE80211W
+ case WPA_KEY_MGMT_IEEE8021X_SHA256:
+ return "WPA2-EAP-SHA256";
+ case WPA_KEY_MGMT_PSK_SHA256:
+ return "WPA2-PSK-SHA256";
+#endif /* CONFIG_IEEE80211W */
+ default:
+ return "UNKNOWN";
+ }
+}
+
+
+int wpa_compare_rsn_ie(int ft_initial_assoc,
+ const u8 *ie1, size_t ie1len,
+ const u8 *ie2, size_t ie2len)
+{
+ if (ie1 == NULL || ie2 == NULL)
+ return -1;
+
+ if (ie1len == ie2len && os_memcmp(ie1, ie2, ie1len) == 0)
+ return 0; /* identical IEs */
+
+#ifdef CONFIG_IEEE80211R
+ if (ft_initial_assoc) {
+ struct wpa_ie_data ie1d, ie2d;
+ /*
+ * The PMKID-List in RSN IE is different between Beacon/Probe
+ * Response/(Re)Association Request frames and EAPOL-Key
+ * messages in FT initial mobility domain association. Allow
+ * for this, but verify that other parts of the RSN IEs are
+ * identical.
+ */
+ if (wpa_parse_wpa_ie_rsn(ie1, ie1len, &ie1d) < 0 ||
+ wpa_parse_wpa_ie_rsn(ie2, ie2len, &ie2d) < 0)
+ return -1;
+ if (ie1d.proto == ie2d.proto &&
+ ie1d.pairwise_cipher == ie2d.pairwise_cipher &&
+ ie1d.group_cipher == ie2d.group_cipher &&
+ ie1d.key_mgmt == ie2d.key_mgmt &&
+ ie1d.capabilities == ie2d.capabilities &&
+ ie1d.mgmt_group_cipher == ie2d.mgmt_group_cipher)
+ return 0;
+ }
+#endif /* CONFIG_IEEE80211R */
+
+ return -1;
+}
+
+
+#ifdef CONFIG_IEEE80211R
+int wpa_insert_pmkid(u8 *ies, size_t ies_len, const u8 *pmkid)
+{
+ u8 *start, *end, *rpos, *rend;
+ int added = 0;
+
+ start = ies;
+ end = ies + ies_len;
+
+ while (start < end) {
+ if (*start == WLAN_EID_RSN)
+ break;
+ start += 2 + start[1];
+ }
+ if (start >= end) {
+ wpa_printf(MSG_ERROR, "FT: Could not find RSN IE in "
+ "IEs data");
+ return -1;
+ }
+ wpa_hexdump(MSG_DEBUG, "FT: RSN IE before modification",
+ start, 2 + start[1]);
+
+ /* Find start of PMKID-Count */
+ rpos = start + 2;
+ rend = rpos + start[1];
+
+ /* Skip Version and Group Data Cipher Suite */
+ rpos += 2 + 4;
+ /* Skip Pairwise Cipher Suite Count and List */
+ rpos += 2 + WPA_GET_LE16(rpos) * RSN_SELECTOR_LEN;
+ /* Skip AKM Suite Count and List */
+ rpos += 2 + WPA_GET_LE16(rpos) * RSN_SELECTOR_LEN;
+
+ if (rpos == rend) {
+ /* Add RSN Capabilities */
+ os_memmove(rpos + 2, rpos, end - rpos);
+ *rpos++ = 0;
+ *rpos++ = 0;
+ } else {
+ /* Skip RSN Capabilities */
+ rpos += 2;
+ if (rpos > rend) {
+ wpa_printf(MSG_ERROR, "FT: Could not parse RSN IE in "
+ "IEs data");
+ return -1;
+ }
+ }
+
+ if (rpos == rend) {
+ /* No PMKID-Count field included; add it */
+ os_memmove(rpos + 2 + PMKID_LEN, rpos, end - rpos);
+ WPA_PUT_LE16(rpos, 1);
+ rpos += 2;
+ os_memcpy(rpos, pmkid, PMKID_LEN);
+ added += 2 + PMKID_LEN;
+ start[1] += 2 + PMKID_LEN;
+ } else {
+ /* PMKID-Count was included; use it */
+ if (WPA_GET_LE16(rpos) != 0) {
+ wpa_printf(MSG_ERROR, "FT: Unexpected PMKID "
+ "in RSN IE in EAPOL-Key data");
+ return -1;
+ }
+ WPA_PUT_LE16(rpos, 1);
+ rpos += 2;
+ os_memmove(rpos + PMKID_LEN, rpos, end - rpos);
+ os_memcpy(rpos, pmkid, PMKID_LEN);
+ added += PMKID_LEN;
+ start[1] += PMKID_LEN;
+ }
+
+ wpa_hexdump(MSG_DEBUG, "FT: RSN IE after modification "
+ "(PMKID inserted)", start, 2 + start[1]);
+
+ return added;
+}
+#endif /* CONFIG_IEEE80211R */
diff --git a/contrib/wpa/src/common/wpa_common.h b/contrib/wpa/src/common/wpa_common.h
index 3074cd4..fd8a79f 100644
--- a/contrib/wpa/src/common/wpa_common.h
+++ b/contrib/wpa/src/common/wpa_common.h
@@ -282,6 +282,12 @@ struct rsn_ftie {
#define FTIE_SUBELEM_R0KH_ID 3
#define FTIE_SUBELEM_IGTK 4
+struct rsn_rdie {
+ u8 id;
+ u8 descr_count;
+ le16 status_code;
+} STRUCT_PACKED;
+
#endif /* CONFIG_IEEE80211R */
#ifdef _MSC_VER
@@ -332,4 +338,14 @@ struct wpa_ie_data {
int wpa_parse_wpa_ie_rsn(const u8 *rsn_ie, size_t rsn_ie_len,
struct wpa_ie_data *data);
+void rsn_pmkid(const u8 *pmk, size_t pmk_len, const u8 *aa, const u8 *spa,
+ u8 *pmkid, int use_sha256);
+
+const char * wpa_cipher_txt(int cipher);
+const char * wpa_key_mgmt_txt(int key_mgmt, int proto);
+int wpa_compare_rsn_ie(int ft_initial_assoc,
+ const u8 *ie1, size_t ie1len,
+ const u8 *ie2, size_t ie2len);
+int wpa_insert_pmkid(u8 *ies, size_t ies_len, const u8 *pmkid);
+
#endif /* WPA_COMMON_H */
diff --git a/contrib/wpa/src/common/wpa_ctrl.h b/contrib/wpa/src/common/wpa_ctrl.h
index 1bfc0d6..d770fd4 100644
--- a/contrib/wpa/src/common/wpa_ctrl.h
+++ b/contrib/wpa/src/common/wpa_ctrl.h
@@ -40,14 +40,24 @@ extern "C" {
#define WPA_EVENT_EAP_NOTIFICATION "CTRL-EVENT-EAP-NOTIFICATION "
/** EAP authentication started (EAP-Request/Identity received) */
#define WPA_EVENT_EAP_STARTED "CTRL-EVENT-EAP-STARTED "
+/** EAP method proposed by the server */
+#define WPA_EVENT_EAP_PROPOSED_METHOD "CTRL-EVENT-EAP-PROPOSED-METHOD "
/** EAP method selected */
#define WPA_EVENT_EAP_METHOD "CTRL-EVENT-EAP-METHOD "
+/** EAP peer certificate from TLS */
+#define WPA_EVENT_EAP_PEER_CERT "CTRL-EVENT-EAP-PEER-CERT "
+/** EAP TLS certificate chain validation error */
+#define WPA_EVENT_EAP_TLS_CERT_ERROR "CTRL-EVENT-EAP-TLS-CERT-ERROR "
/** EAP authentication completed successfully */
#define WPA_EVENT_EAP_SUCCESS "CTRL-EVENT-EAP-SUCCESS "
/** EAP authentication failed (EAP-Failure received) */
#define WPA_EVENT_EAP_FAILURE "CTRL-EVENT-EAP-FAILURE "
/** New scan results available */
#define WPA_EVENT_SCAN_RESULTS "CTRL-EVENT-SCAN-RESULTS "
+/** A new BSS entry was added (followed by BSS entry id and BSSID) */
+#define WPA_EVENT_BSS_ADDED "CTRL-EVENT-BSS-ADDED "
+/** A BSS entry was removed (followed by BSS entry id and BSSID) */
+#define WPA_EVENT_BSS_REMOVED "CTRL-EVENT-BSS-REMOVED "
/** WPS overlap detected in PBC mode */
#define WPS_EVENT_OVERLAP "WPS-OVERLAP-DETECTED "
@@ -69,11 +79,24 @@ extern "C" {
/** WPS enrollment attempt timed out and was terminated */
#define WPS_EVENT_TIMEOUT "WPS-TIMEOUT "
+#define WPS_EVENT_ENROLLEE_SEEN "WPS-ENROLLEE-SEEN "
+
+/* WPS ER events */
+#define WPS_EVENT_ER_AP_ADD "WPS-ER-AP-ADD "
+#define WPS_EVENT_ER_AP_REMOVE "WPS-ER-AP-REMOVE "
+#define WPS_EVENT_ER_ENROLLEE_ADD "WPS-ER-ENROLLEE-ADD "
+#define WPS_EVENT_ER_ENROLLEE_REMOVE "WPS-ER-ENROLLEE-REMOVE "
+
/* hostapd control interface - fixed message prefixes */
#define WPS_EVENT_PIN_NEEDED "WPS-PIN-NEEDED "
#define WPS_EVENT_NEW_AP_SETTINGS "WPS-NEW-AP-SETTINGS "
#define WPS_EVENT_REG_SUCCESS "WPS-REG-SUCCESS "
#define WPS_EVENT_AP_SETUP_LOCKED "WPS-AP-SETUP-LOCKED "
+#define WPS_EVENT_AP_SETUP_UNLOCKED "WPS-AP-SETUP-UNLOCKED "
+#define WPS_EVENT_AP_PIN_ENABLED "WPS-AP-PIN-ENABLED "
+#define WPS_EVENT_AP_PIN_DISABLED "WPS-AP-PIN-DISABLED "
+#define AP_STA_CONNECTED "AP-STA-CONNECTED "
+#define AP_STA_DISCONNECTED "AP-STA-DISCONNECTED "
/* wpa_supplicant/hostapd control interface access */
diff --git a/contrib/wpa/src/crypto/.gitignore b/contrib/wpa/src/crypto/.gitignore
new file mode 100644
index 0000000..ee60604
--- /dev/null
+++ b/contrib/wpa/src/crypto/.gitignore
@@ -0,0 +1 @@
+libcrypto.a
diff --git a/contrib/wpa/src/crypto/Makefile b/contrib/wpa/src/crypto/Makefile
index cffba62..69aa16a 100644
--- a/contrib/wpa/src/crypto/Makefile
+++ b/contrib/wpa/src/crypto/Makefile
@@ -1,9 +1,56 @@
-all:
- @echo Nothing to be made.
+all: libcrypto.a
clean:
- for d in $(SUBDIRS); do make -C $$d clean; done
- rm -f *~ *.o *.d
+ rm -f *~ *.o *.d libcrypto.a
install:
@echo Nothing to be made.
+
+
+include ../lib.rules
+
+CFLAGS += -DCONFIG_TLS_INTERNAL_CLIENT
+CFLAGS += -DCONFIG_TLS_INTERNAL_SERVER
+#CFLAGS += -DALL_DH_GROUPS
+
+LIB_OBJS= \
+ aes-cbc.o \
+ aes-ctr.o \
+ aes-eax.o \
+ aes-encblock.o \
+ aes-internal.o \
+ aes-internal-dec.o \
+ aes-internal-enc.o \
+ aes-omac1.o \
+ aes-unwrap.o \
+ aes-wrap.o \
+ des-internal.o \
+ dh_group5.o \
+ dh_groups.o \
+ md4-internal.o \
+ md5.o \
+ md5-internal.o \
+ md5-non-fips.o \
+ milenage.o \
+ ms_funcs.o \
+ rc4.o \
+ sha1.o \
+ sha1-internal.o \
+ sha1-pbkdf2.o \
+ sha1-tlsprf.o \
+ sha1-tprf.o \
+ sha256.o \
+ sha256-internal.o
+
+LIB_OBJS += crypto_internal.o
+LIB_OBJS += crypto_internal-cipher.o
+LIB_OBJS += crypto_internal-modexp.o
+LIB_OBJS += crypto_internal-rsa.o
+LIB_OBJS += tls_internal.o
+LIB_OBJS += fips_prf_internal.o
+
+
+libcrypto.a: $(LIB_OBJS)
+ $(AR) crT $@ $?
+
+-include $(OBJS:%.o=%.d)
diff --git a/contrib/wpa/src/crypto/aes-cbc.c b/contrib/wpa/src/crypto/aes-cbc.c
new file mode 100644
index 0000000..bd74769
--- /dev/null
+++ b/contrib/wpa/src/crypto/aes-cbc.c
@@ -0,0 +1,86 @@
+/*
+ * AES-128 CBC
+ *
+ * Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "aes.h"
+#include "aes_wrap.h"
+
+/**
+ * aes_128_cbc_encrypt - AES-128 CBC encryption
+ * @key: Encryption key
+ * @iv: Encryption IV for CBC mode (16 bytes)
+ * @data: Data to encrypt in-place
+ * @data_len: Length of data in bytes (must be divisible by 16)
+ * Returns: 0 on success, -1 on failure
+ */
+int aes_128_cbc_encrypt(const u8 *key, const u8 *iv, u8 *data, size_t data_len)
+{
+ void *ctx;
+ u8 cbc[AES_BLOCK_SIZE];
+ u8 *pos = data;
+ int i, j, blocks;
+
+ ctx = aes_encrypt_init(key, 16);
+ if (ctx == NULL)
+ return -1;
+ os_memcpy(cbc, iv, AES_BLOCK_SIZE);
+
+ blocks = data_len / AES_BLOCK_SIZE;
+ for (i = 0; i < blocks; i++) {
+ for (j = 0; j < AES_BLOCK_SIZE; j++)
+ cbc[j] ^= pos[j];
+ aes_encrypt(ctx, cbc, cbc);
+ os_memcpy(pos, cbc, AES_BLOCK_SIZE);
+ pos += AES_BLOCK_SIZE;
+ }
+ aes_encrypt_deinit(ctx);
+ return 0;
+}
+
+
+/**
+ * aes_128_cbc_decrypt - AES-128 CBC decryption
+ * @key: Decryption key
+ * @iv: Decryption IV for CBC mode (16 bytes)
+ * @data: Data to decrypt in-place
+ * @data_len: Length of data in bytes (must be divisible by 16)
+ * Returns: 0 on success, -1 on failure
+ */
+int aes_128_cbc_decrypt(const u8 *key, const u8 *iv, u8 *data, size_t data_len)
+{
+ void *ctx;
+ u8 cbc[AES_BLOCK_SIZE], tmp[AES_BLOCK_SIZE];
+ u8 *pos = data;
+ int i, j, blocks;
+
+ ctx = aes_decrypt_init(key, 16);
+ if (ctx == NULL)
+ return -1;
+ os_memcpy(cbc, iv, AES_BLOCK_SIZE);
+
+ blocks = data_len / AES_BLOCK_SIZE;
+ for (i = 0; i < blocks; i++) {
+ os_memcpy(tmp, pos, AES_BLOCK_SIZE);
+ aes_decrypt(ctx, pos, pos);
+ for (j = 0; j < AES_BLOCK_SIZE; j++)
+ pos[j] ^= cbc[j];
+ os_memcpy(cbc, tmp, AES_BLOCK_SIZE);
+ pos += AES_BLOCK_SIZE;
+ }
+ aes_decrypt_deinit(ctx);
+ return 0;
+}
diff --git a/contrib/wpa/src/crypto/aes-ctr.c b/contrib/wpa/src/crypto/aes-ctr.c
new file mode 100644
index 0000000..468f877
--- /dev/null
+++ b/contrib/wpa/src/crypto/aes-ctr.c
@@ -0,0 +1,61 @@
+/*
+ * AES-128 CTR
+ *
+ * Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "aes.h"
+#include "aes_wrap.h"
+
+/**
+ * aes_128_ctr_encrypt - AES-128 CTR mode encryption
+ * @key: Key for encryption (16 bytes)
+ * @nonce: Nonce for counter mode (16 bytes)
+ * @data: Data to encrypt in-place
+ * @data_len: Length of data in bytes
+ * Returns: 0 on success, -1 on failure
+ */
+int aes_128_ctr_encrypt(const u8 *key, const u8 *nonce,
+ u8 *data, size_t data_len)
+{
+ void *ctx;
+ size_t j, len, left = data_len;
+ int i;
+ u8 *pos = data;
+ u8 counter[AES_BLOCK_SIZE], buf[AES_BLOCK_SIZE];
+
+ ctx = aes_encrypt_init(key, 16);
+ if (ctx == NULL)
+ return -1;
+ os_memcpy(counter, nonce, AES_BLOCK_SIZE);
+
+ while (left > 0) {
+ aes_encrypt(ctx, counter, buf);
+
+ len = (left < AES_BLOCK_SIZE) ? left : AES_BLOCK_SIZE;
+ for (j = 0; j < len; j++)
+ pos[j] ^= buf[j];
+ pos += len;
+ left -= len;
+
+ for (i = AES_BLOCK_SIZE - 1; i >= 0; i--) {
+ counter[i]++;
+ if (counter[i])
+ break;
+ }
+ }
+ aes_encrypt_deinit(ctx);
+ return 0;
+}
diff --git a/contrib/wpa/src/crypto/aes-eax.c b/contrib/wpa/src/crypto/aes-eax.c
new file mode 100644
index 0000000..d5c3971
--- /dev/null
+++ b/contrib/wpa/src/crypto/aes-eax.c
@@ -0,0 +1,151 @@
+/*
+ * AES-128 EAX
+ *
+ * Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "aes.h"
+#include "aes_wrap.h"
+
+/**
+ * aes_128_eax_encrypt - AES-128 EAX mode encryption
+ * @key: Key for encryption (16 bytes)
+ * @nonce: Nonce for counter mode
+ * @nonce_len: Nonce length in bytes
+ * @hdr: Header data to be authenticity protected
+ * @hdr_len: Length of the header data bytes
+ * @data: Data to encrypt in-place
+ * @data_len: Length of data in bytes
+ * @tag: 16-byte tag value
+ * Returns: 0 on success, -1 on failure
+ */
+int aes_128_eax_encrypt(const u8 *key, const u8 *nonce, size_t nonce_len,
+ const u8 *hdr, size_t hdr_len,
+ u8 *data, size_t data_len, u8 *tag)
+{
+ u8 *buf;
+ size_t buf_len;
+ u8 nonce_mac[AES_BLOCK_SIZE], hdr_mac[AES_BLOCK_SIZE],
+ data_mac[AES_BLOCK_SIZE];
+ int i, ret = -1;
+
+ if (nonce_len > data_len)
+ buf_len = nonce_len;
+ else
+ buf_len = data_len;
+ if (hdr_len > buf_len)
+ buf_len = hdr_len;
+ buf_len += 16;
+
+ buf = os_malloc(buf_len);
+ if (buf == NULL)
+ return -1;
+
+ os_memset(buf, 0, 15);
+
+ buf[15] = 0;
+ os_memcpy(buf + 16, nonce, nonce_len);
+ if (omac1_aes_128(key, buf, 16 + nonce_len, nonce_mac))
+ goto fail;
+
+ buf[15] = 1;
+ os_memcpy(buf + 16, hdr, hdr_len);
+ if (omac1_aes_128(key, buf, 16 + hdr_len, hdr_mac))
+ goto fail;
+
+ if (aes_128_ctr_encrypt(key, nonce_mac, data, data_len))
+ goto fail;
+ buf[15] = 2;
+ os_memcpy(buf + 16, data, data_len);
+ if (omac1_aes_128(key, buf, 16 + data_len, data_mac))
+ goto fail;
+
+ for (i = 0; i < AES_BLOCK_SIZE; i++)
+ tag[i] = nonce_mac[i] ^ data_mac[i] ^ hdr_mac[i];
+
+ ret = 0;
+fail:
+ os_free(buf);
+
+ return ret;
+}
+
+
+/**
+ * aes_128_eax_decrypt - AES-128 EAX mode decryption
+ * @key: Key for decryption (16 bytes)
+ * @nonce: Nonce for counter mode
+ * @nonce_len: Nonce length in bytes
+ * @hdr: Header data to be authenticity protected
+ * @hdr_len: Length of the header data bytes
+ * @data: Data to encrypt in-place
+ * @data_len: Length of data in bytes
+ * @tag: 16-byte tag value
+ * Returns: 0 on success, -1 on failure, -2 if tag does not match
+ */
+int aes_128_eax_decrypt(const u8 *key, const u8 *nonce, size_t nonce_len,
+ const u8 *hdr, size_t hdr_len,
+ u8 *data, size_t data_len, const u8 *tag)
+{
+ u8 *buf;
+ size_t buf_len;
+ u8 nonce_mac[AES_BLOCK_SIZE], hdr_mac[AES_BLOCK_SIZE],
+ data_mac[AES_BLOCK_SIZE];
+ int i;
+
+ if (nonce_len > data_len)
+ buf_len = nonce_len;
+ else
+ buf_len = data_len;
+ if (hdr_len > buf_len)
+ buf_len = hdr_len;
+ buf_len += 16;
+
+ buf = os_malloc(buf_len);
+ if (buf == NULL)
+ return -1;
+
+ os_memset(buf, 0, 15);
+
+ buf[15] = 0;
+ os_memcpy(buf + 16, nonce, nonce_len);
+ if (omac1_aes_128(key, buf, 16 + nonce_len, nonce_mac)) {
+ os_free(buf);
+ return -1;
+ }
+
+ buf[15] = 1;
+ os_memcpy(buf + 16, hdr, hdr_len);
+ if (omac1_aes_128(key, buf, 16 + hdr_len, hdr_mac)) {
+ os_free(buf);
+ return -1;
+ }
+
+ buf[15] = 2;
+ os_memcpy(buf + 16, data, data_len);
+ if (omac1_aes_128(key, buf, 16 + data_len, data_mac)) {
+ os_free(buf);
+ return -1;
+ }
+
+ os_free(buf);
+
+ for (i = 0; i < AES_BLOCK_SIZE; i++) {
+ if (tag[i] != (nonce_mac[i] ^ data_mac[i] ^ hdr_mac[i]))
+ return -2;
+ }
+
+ return aes_128_ctr_encrypt(key, nonce_mac, data, data_len);
+}
diff --git a/contrib/wpa/src/crypto/aes-encblock.c b/contrib/wpa/src/crypto/aes-encblock.c
new file mode 100644
index 0000000..8f35caa
--- /dev/null
+++ b/contrib/wpa/src/crypto/aes-encblock.c
@@ -0,0 +1,38 @@
+/*
+ * AES encrypt_block
+ *
+ * Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "aes.h"
+#include "aes_wrap.h"
+
+/**
+ * aes_128_encrypt_block - Perform one AES 128-bit block operation
+ * @key: Key for AES
+ * @in: Input data (16 bytes)
+ * @out: Output of the AES block operation (16 bytes)
+ * Returns: 0 on success, -1 on failure
+ */
+int aes_128_encrypt_block(const u8 *key, const u8 *in, u8 *out)
+{
+ void *ctx;
+ ctx = aes_encrypt_init(key, 16);
+ if (ctx == NULL)
+ return -1;
+ aes_encrypt(ctx, in, out);
+ aes_encrypt_deinit(ctx);
+ return 0;
+}
diff --git a/contrib/wpa/src/crypto/aes-internal-dec.c b/contrib/wpa/src/crypto/aes-internal-dec.c
new file mode 100644
index 0000000..2d32c03
--- /dev/null
+++ b/contrib/wpa/src/crypto/aes-internal-dec.c
@@ -0,0 +1,151 @@
+/*
+ * AES (Rijndael) cipher - decrypt
+ *
+ * Modifications to public domain implementation:
+ * - support only 128-bit keys
+ * - cleanup
+ * - use C pre-processor to make it easier to change S table access
+ * - added option (AES_SMALL_TABLES) for reducing code size by about 8 kB at
+ * cost of reduced throughput (quite small difference on Pentium 4,
+ * 10-25% when using -O1 or -O2 optimization)
+ *
+ * Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "crypto.h"
+#include "aes_i.h"
+
+/**
+ * Expand the cipher key into the decryption key schedule.
+ *
+ * @return the number of rounds for the given cipher key size.
+ */
+void rijndaelKeySetupDec(u32 rk[/*44*/], const u8 cipherKey[])
+{
+ int Nr = 10, i, j;
+ u32 temp;
+
+ /* expand the cipher key: */
+ rijndaelKeySetupEnc(rk, cipherKey);
+ /* invert the order of the round keys: */
+ for (i = 0, j = 4*Nr; i < j; i += 4, j -= 4) {
+ temp = rk[i ]; rk[i ] = rk[j ]; rk[j ] = temp;
+ temp = rk[i + 1]; rk[i + 1] = rk[j + 1]; rk[j + 1] = temp;
+ temp = rk[i + 2]; rk[i + 2] = rk[j + 2]; rk[j + 2] = temp;
+ temp = rk[i + 3]; rk[i + 3] = rk[j + 3]; rk[j + 3] = temp;
+ }
+ /* apply the inverse MixColumn transform to all round keys but the
+ * first and the last: */
+ for (i = 1; i < Nr; i++) {
+ rk += 4;
+ for (j = 0; j < 4; j++) {
+ rk[j] = TD0_(TE4((rk[j] >> 24) )) ^
+ TD1_(TE4((rk[j] >> 16) & 0xff)) ^
+ TD2_(TE4((rk[j] >> 8) & 0xff)) ^
+ TD3_(TE4((rk[j] ) & 0xff));
+ }
+ }
+}
+
+void * aes_decrypt_init(const u8 *key, size_t len)
+{
+ u32 *rk;
+ if (len != 16)
+ return NULL;
+ rk = os_malloc(AES_PRIV_SIZE);
+ if (rk == NULL)
+ return NULL;
+ rijndaelKeySetupDec(rk, key);
+ return rk;
+}
+
+static void rijndaelDecrypt(const u32 rk[/*44*/], const u8 ct[16], u8 pt[16])
+{
+ u32 s0, s1, s2, s3, t0, t1, t2, t3;
+ const int Nr = 10;
+#ifndef FULL_UNROLL
+ int r;
+#endif /* ?FULL_UNROLL */
+
+ /*
+ * map byte array block to cipher state
+ * and add initial round key:
+ */
+ s0 = GETU32(ct ) ^ rk[0];
+ s1 = GETU32(ct + 4) ^ rk[1];
+ s2 = GETU32(ct + 8) ^ rk[2];
+ s3 = GETU32(ct + 12) ^ rk[3];
+
+#define ROUND(i,d,s) \
+d##0 = TD0(s##0) ^ TD1(s##3) ^ TD2(s##2) ^ TD3(s##1) ^ rk[4 * i]; \
+d##1 = TD0(s##1) ^ TD1(s##0) ^ TD2(s##3) ^ TD3(s##2) ^ rk[4 * i + 1]; \
+d##2 = TD0(s##2) ^ TD1(s##1) ^ TD2(s##0) ^ TD3(s##3) ^ rk[4 * i + 2]; \
+d##3 = TD0(s##3) ^ TD1(s##2) ^ TD2(s##1) ^ TD3(s##0) ^ rk[4 * i + 3]
+
+#ifdef FULL_UNROLL
+
+ ROUND(1,t,s);
+ ROUND(2,s,t);
+ ROUND(3,t,s);
+ ROUND(4,s,t);
+ ROUND(5,t,s);
+ ROUND(6,s,t);
+ ROUND(7,t,s);
+ ROUND(8,s,t);
+ ROUND(9,t,s);
+
+ rk += Nr << 2;
+
+#else /* !FULL_UNROLL */
+
+ /* Nr - 1 full rounds: */
+ r = Nr >> 1;
+ for (;;) {
+ ROUND(1,t,s);
+ rk += 8;
+ if (--r == 0)
+ break;
+ ROUND(0,s,t);
+ }
+
+#endif /* ?FULL_UNROLL */
+
+#undef ROUND
+
+ /*
+ * apply last round and
+ * map cipher state to byte array block:
+ */
+ s0 = TD41(t0) ^ TD42(t3) ^ TD43(t2) ^ TD44(t1) ^ rk[0];
+ PUTU32(pt , s0);
+ s1 = TD41(t1) ^ TD42(t0) ^ TD43(t3) ^ TD44(t2) ^ rk[1];
+ PUTU32(pt + 4, s1);
+ s2 = TD41(t2) ^ TD42(t1) ^ TD43(t0) ^ TD44(t3) ^ rk[2];
+ PUTU32(pt + 8, s2);
+ s3 = TD41(t3) ^ TD42(t2) ^ TD43(t1) ^ TD44(t0) ^ rk[3];
+ PUTU32(pt + 12, s3);
+}
+
+void aes_decrypt(void *ctx, const u8 *crypt, u8 *plain)
+{
+ rijndaelDecrypt(ctx, crypt, plain);
+}
+
+
+void aes_decrypt_deinit(void *ctx)
+{
+ os_memset(ctx, 0, AES_PRIV_SIZE);
+ os_free(ctx);
+}
diff --git a/contrib/wpa/src/crypto/aes-internal-enc.c b/contrib/wpa/src/crypto/aes-internal-enc.c
new file mode 100644
index 0000000..2f19826
--- /dev/null
+++ b/contrib/wpa/src/crypto/aes-internal-enc.c
@@ -0,0 +1,121 @@
+/*
+ * AES (Rijndael) cipher - encrypt
+ *
+ * Modifications to public domain implementation:
+ * - support only 128-bit keys
+ * - cleanup
+ * - use C pre-processor to make it easier to change S table access
+ * - added option (AES_SMALL_TABLES) for reducing code size by about 8 kB at
+ * cost of reduced throughput (quite small difference on Pentium 4,
+ * 10-25% when using -O1 or -O2 optimization)
+ *
+ * Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "crypto.h"
+#include "aes_i.h"
+
+void rijndaelEncrypt(const u32 rk[/*44*/], const u8 pt[16], u8 ct[16])
+{
+ u32 s0, s1, s2, s3, t0, t1, t2, t3;
+ const int Nr = 10;
+#ifndef FULL_UNROLL
+ int r;
+#endif /* ?FULL_UNROLL */
+
+ /*
+ * map byte array block to cipher state
+ * and add initial round key:
+ */
+ s0 = GETU32(pt ) ^ rk[0];
+ s1 = GETU32(pt + 4) ^ rk[1];
+ s2 = GETU32(pt + 8) ^ rk[2];
+ s3 = GETU32(pt + 12) ^ rk[3];
+
+#define ROUND(i,d,s) \
+d##0 = TE0(s##0) ^ TE1(s##1) ^ TE2(s##2) ^ TE3(s##3) ^ rk[4 * i]; \
+d##1 = TE0(s##1) ^ TE1(s##2) ^ TE2(s##3) ^ TE3(s##0) ^ rk[4 * i + 1]; \
+d##2 = TE0(s##2) ^ TE1(s##3) ^ TE2(s##0) ^ TE3(s##1) ^ rk[4 * i + 2]; \
+d##3 = TE0(s##3) ^ TE1(s##0) ^ TE2(s##1) ^ TE3(s##2) ^ rk[4 * i + 3]
+
+#ifdef FULL_UNROLL
+
+ ROUND(1,t,s);
+ ROUND(2,s,t);
+ ROUND(3,t,s);
+ ROUND(4,s,t);
+ ROUND(5,t,s);
+ ROUND(6,s,t);
+ ROUND(7,t,s);
+ ROUND(8,s,t);
+ ROUND(9,t,s);
+
+ rk += Nr << 2;
+
+#else /* !FULL_UNROLL */
+
+ /* Nr - 1 full rounds: */
+ r = Nr >> 1;
+ for (;;) {
+ ROUND(1,t,s);
+ rk += 8;
+ if (--r == 0)
+ break;
+ ROUND(0,s,t);
+ }
+
+#endif /* ?FULL_UNROLL */
+
+#undef ROUND
+
+ /*
+ * apply last round and
+ * map cipher state to byte array block:
+ */
+ s0 = TE41(t0) ^ TE42(t1) ^ TE43(t2) ^ TE44(t3) ^ rk[0];
+ PUTU32(ct , s0);
+ s1 = TE41(t1) ^ TE42(t2) ^ TE43(t3) ^ TE44(t0) ^ rk[1];
+ PUTU32(ct + 4, s1);
+ s2 = TE41(t2) ^ TE42(t3) ^ TE43(t0) ^ TE44(t1) ^ rk[2];
+ PUTU32(ct + 8, s2);
+ s3 = TE41(t3) ^ TE42(t0) ^ TE43(t1) ^ TE44(t2) ^ rk[3];
+ PUTU32(ct + 12, s3);
+}
+
+
+void * aes_encrypt_init(const u8 *key, size_t len)
+{
+ u32 *rk;
+ if (len != 16)
+ return NULL;
+ rk = os_malloc(AES_PRIV_SIZE);
+ if (rk == NULL)
+ return NULL;
+ rijndaelKeySetupEnc(rk, key);
+ return rk;
+}
+
+
+void aes_encrypt(void *ctx, const u8 *plain, u8 *crypt)
+{
+ rijndaelEncrypt(ctx, plain, crypt);
+}
+
+
+void aes_encrypt_deinit(void *ctx)
+{
+ os_memset(ctx, 0, AES_PRIV_SIZE);
+ os_free(ctx);
+}
diff --git a/contrib/wpa/src/crypto/aes.c b/contrib/wpa/src/crypto/aes-internal.c
index 8b8f2a0..4161220 100644
--- a/contrib/wpa/src/crypto/aes.c
+++ b/contrib/wpa/src/crypto/aes-internal.c
@@ -24,10 +24,8 @@
#include "includes.h"
#include "common.h"
-
-#ifdef INTERNAL_AES
-
#include "crypto.h"
+#include "aes_i.h"
/*
* rijndael-alg-fst.c
@@ -55,9 +53,6 @@
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-/* #define FULL_UNROLL */
-#define AES_SMALL_TABLES
-
/*
Te0[x] = S [x].[02, 01, 01, 03];
@@ -73,7 +68,7 @@ Td3[x] = Si[x].[09, 0d, 0b, 0e];
Td4[x] = Si[x].[01, 01, 01, 01];
*/
-static const u32 Te0[256] = {
+const u32 Te0[256] = {
0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU,
0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U,
0x60303050U, 0x02010103U, 0xce6767a9U, 0x562b2b7dU,
@@ -140,7 +135,7 @@ static const u32 Te0[256] = {
0x7bb0b0cbU, 0xa85454fcU, 0x6dbbbbd6U, 0x2c16163aU,
};
#ifndef AES_SMALL_TABLES
-static const u32 Te1[256] = {
+const u32 Te1[256] = {
0xa5c66363U, 0x84f87c7cU, 0x99ee7777U, 0x8df67b7bU,
0x0dfff2f2U, 0xbdd66b6bU, 0xb1de6f6fU, 0x5491c5c5U,
0x50603030U, 0x03020101U, 0xa9ce6767U, 0x7d562b2bU,
@@ -206,7 +201,7 @@ static const u32 Te1[256] = {
0xc3824141U, 0xb0299999U, 0x775a2d2dU, 0x111e0f0fU,
0xcb7bb0b0U, 0xfca85454U, 0xd66dbbbbU, 0x3a2c1616U,
};
-static const u32 Te2[256] = {
+const u32 Te2[256] = {
0x63a5c663U, 0x7c84f87cU, 0x7799ee77U, 0x7b8df67bU,
0xf20dfff2U, 0x6bbdd66bU, 0x6fb1de6fU, 0xc55491c5U,
0x30506030U, 0x01030201U, 0x67a9ce67U, 0x2b7d562bU,
@@ -272,7 +267,7 @@ static const u32 Te2[256] = {
0x41c38241U, 0x99b02999U, 0x2d775a2dU, 0x0f111e0fU,
0xb0cb7bb0U, 0x54fca854U, 0xbbd66dbbU, 0x163a2c16U,
};
-static const u32 Te3[256] = {
+const u32 Te3[256] = {
0x6363a5c6U, 0x7c7c84f8U, 0x777799eeU, 0x7b7b8df6U,
0xf2f20dffU, 0x6b6bbdd6U, 0x6f6fb1deU, 0xc5c55491U,
@@ -339,7 +334,7 @@ static const u32 Te3[256] = {
0x4141c382U, 0x9999b029U, 0x2d2d775aU, 0x0f0f111eU,
0xb0b0cb7bU, 0x5454fca8U, 0xbbbbd66dU, 0x16163a2cU,
};
-static const u32 Te4[256] = {
+const u32 Te4[256] = {
0x63636363U, 0x7c7c7c7cU, 0x77777777U, 0x7b7b7b7bU,
0xf2f2f2f2U, 0x6b6b6b6bU, 0x6f6f6f6fU, 0xc5c5c5c5U,
0x30303030U, 0x01010101U, 0x67676767U, 0x2b2b2b2bU,
@@ -406,7 +401,7 @@ static const u32 Te4[256] = {
0xb0b0b0b0U, 0x54545454U, 0xbbbbbbbbU, 0x16161616U,
};
#endif /* AES_SMALL_TABLES */
-static const u32 Td0[256] = {
+const u32 Td0[256] = {
0x51f4a750U, 0x7e416553U, 0x1a17a4c3U, 0x3a275e96U,
0x3bab6bcbU, 0x1f9d45f1U, 0xacfa58abU, 0x4be30393U,
0x2030fa55U, 0xad766df6U, 0x88cc7691U, 0xf5024c25U,
@@ -473,7 +468,7 @@ static const u32 Td0[256] = {
0x7bcb8461U, 0xd532b670U, 0x486c5c74U, 0xd0b85742U,
};
#ifndef AES_SMALL_TABLES
-static const u32 Td1[256] = {
+const u32 Td1[256] = {
0x5051f4a7U, 0x537e4165U, 0xc31a17a4U, 0x963a275eU,
0xcb3bab6bU, 0xf11f9d45U, 0xabacfa58U, 0x934be303U,
0x552030faU, 0xf6ad766dU, 0x9188cc76U, 0x25f5024cU,
@@ -539,7 +534,7 @@ static const u32 Td1[256] = {
0x7139a801U, 0xde080cb3U, 0x9cd8b4e4U, 0x906456c1U,
0x617bcb84U, 0x70d532b6U, 0x74486c5cU, 0x42d0b857U,
};
-static const u32 Td2[256] = {
+const u32 Td2[256] = {
0xa75051f4U, 0x65537e41U, 0xa4c31a17U, 0x5e963a27U,
0x6bcb3babU, 0x45f11f9dU, 0x58abacfaU, 0x03934be3U,
0xfa552030U, 0x6df6ad76U, 0x769188ccU, 0x4c25f502U,
@@ -606,7 +601,7 @@ static const u32 Td2[256] = {
0x017139a8U, 0xb3de080cU, 0xe49cd8b4U, 0xc1906456U,
0x84617bcbU, 0xb670d532U, 0x5c74486cU, 0x5742d0b8U,
};
-static const u32 Td3[256] = {
+const u32 Td3[256] = {
0xf4a75051U, 0x4165537eU, 0x17a4c31aU, 0x275e963aU,
0xab6bcb3bU, 0x9d45f11fU, 0xfa58abacU, 0xe303934bU,
0x30fa5520U, 0x766df6adU, 0xcc769188U, 0x024c25f5U,
@@ -672,7 +667,7 @@ static const u32 Td3[256] = {
0xa8017139U, 0x0cb3de08U, 0xb4e49cd8U, 0x56c19064U,
0xcb84617bU, 0x32b670d5U, 0x6c5c7448U, 0xb85742d0U,
};
-static const u32 Td4[256] = {
+const u32 Td4[256] = {
0x52525252U, 0x09090909U, 0x6a6a6a6aU, 0xd5d5d5d5U,
0x30303030U, 0x36363636U, 0xa5a5a5a5U, 0x38383838U,
0xbfbfbfbfU, 0x40404040U, 0xa3a3a3a3U, 0x9e9e9e9eU,
@@ -738,13 +733,13 @@ static const u32 Td4[256] = {
0xe1e1e1e1U, 0x69696969U, 0x14141414U, 0x63636363U,
0x55555555U, 0x21212121U, 0x0c0c0c0cU, 0x7d7d7d7dU,
};
-static const u32 rcon[] = {
+const u32 rcon[] = {
0x01000000, 0x02000000, 0x04000000, 0x08000000,
0x10000000, 0x20000000, 0x40000000, 0x80000000,
0x1B000000, 0x36000000, /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */
};
#else /* AES_SMALL_TABLES */
-static const u8 Td4s[256] = {
+const u8 Td4s[256] = {
0x52U, 0x09U, 0x6aU, 0xd5U, 0x30U, 0x36U, 0xa5U, 0x38U,
0xbfU, 0x40U, 0xa3U, 0x9eU, 0x81U, 0xf3U, 0xd7U, 0xfbU,
0x7cU, 0xe3U, 0x39U, 0x82U, 0x9bU, 0x2fU, 0xffU, 0x87U,
@@ -778,95 +773,11 @@ static const u8 Td4s[256] = {
0x17U, 0x2bU, 0x04U, 0x7eU, 0xbaU, 0x77U, 0xd6U, 0x26U,
0xe1U, 0x69U, 0x14U, 0x63U, 0x55U, 0x21U, 0x0cU, 0x7dU,
};
-static const u8 rcons[] = {
+const u8 rcons[] = {
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1B, 0x36
/* for 128-bit blocks, Rijndael never uses more than 10 rcon values */
};
#endif /* AES_SMALL_TABLES */
-
-
-#ifndef AES_SMALL_TABLES
-
-#define RCON(i) rcon[(i)]
-
-#define TE0(i) Te0[((i) >> 24) & 0xff]
-#define TE1(i) Te1[((i) >> 16) & 0xff]
-#define TE2(i) Te2[((i) >> 8) & 0xff]
-#define TE3(i) Te3[(i) & 0xff]
-#define TE41(i) (Te4[((i) >> 24) & 0xff] & 0xff000000)
-#define TE42(i) (Te4[((i) >> 16) & 0xff] & 0x00ff0000)
-#define TE43(i) (Te4[((i) >> 8) & 0xff] & 0x0000ff00)
-#define TE44(i) (Te4[(i) & 0xff] & 0x000000ff)
-#define TE421(i) (Te4[((i) >> 16) & 0xff] & 0xff000000)
-#define TE432(i) (Te4[((i) >> 8) & 0xff] & 0x00ff0000)
-#define TE443(i) (Te4[(i) & 0xff] & 0x0000ff00)
-#define TE414(i) (Te4[((i) >> 24) & 0xff] & 0x000000ff)
-#define TE4(i) (Te4[(i)] & 0x000000ff)
-
-#define TD0(i) Td0[((i) >> 24) & 0xff]
-#define TD1(i) Td1[((i) >> 16) & 0xff]
-#define TD2(i) Td2[((i) >> 8) & 0xff]
-#define TD3(i) Td3[(i) & 0xff]
-#define TD41(i) (Td4[((i) >> 24) & 0xff] & 0xff000000)
-#define TD42(i) (Td4[((i) >> 16) & 0xff] & 0x00ff0000)
-#define TD43(i) (Td4[((i) >> 8) & 0xff] & 0x0000ff00)
-#define TD44(i) (Td4[(i) & 0xff] & 0x000000ff)
-#define TD0_(i) Td0[(i) & 0xff]
-#define TD1_(i) Td1[(i) & 0xff]
-#define TD2_(i) Td2[(i) & 0xff]
-#define TD3_(i) Td3[(i) & 0xff]
-
-#else /* AES_SMALL_TABLES */
-
-#define RCON(i) (rcons[(i)] << 24)
-
-static inline u32 rotr(u32 val, int bits)
-{
- return (val >> bits) | (val << (32 - bits));
-}
-
-#define TE0(i) Te0[((i) >> 24) & 0xff]
-#define TE1(i) rotr(Te0[((i) >> 16) & 0xff], 8)
-#define TE2(i) rotr(Te0[((i) >> 8) & 0xff], 16)
-#define TE3(i) rotr(Te0[(i) & 0xff], 24)
-#define TE41(i) ((Te0[((i) >> 24) & 0xff] << 8) & 0xff000000)
-#define TE42(i) (Te0[((i) >> 16) & 0xff] & 0x00ff0000)
-#define TE43(i) (Te0[((i) >> 8) & 0xff] & 0x0000ff00)
-#define TE44(i) ((Te0[(i) & 0xff] >> 8) & 0x000000ff)
-#define TE421(i) ((Te0[((i) >> 16) & 0xff] << 8) & 0xff000000)
-#define TE432(i) (Te0[((i) >> 8) & 0xff] & 0x00ff0000)
-#define TE443(i) (Te0[(i) & 0xff] & 0x0000ff00)
-#define TE414(i) ((Te0[((i) >> 24) & 0xff] >> 8) & 0x000000ff)
-#define TE4(i) ((Te0[(i)] >> 8) & 0x000000ff)
-
-#define TD0(i) Td0[((i) >> 24) & 0xff]
-#define TD1(i) rotr(Td0[((i) >> 16) & 0xff], 8)
-#define TD2(i) rotr(Td0[((i) >> 8) & 0xff], 16)
-#define TD3(i) rotr(Td0[(i) & 0xff], 24)
-#define TD41(i) (Td4s[((i) >> 24) & 0xff] << 24)
-#define TD42(i) (Td4s[((i) >> 16) & 0xff] << 16)
-#define TD43(i) (Td4s[((i) >> 8) & 0xff] << 8)
-#define TD44(i) (Td4s[(i) & 0xff])
-#define TD0_(i) Td0[(i) & 0xff]
-#define TD1_(i) rotr(Td0[(i) & 0xff], 8)
-#define TD2_(i) rotr(Td0[(i) & 0xff], 16)
-#define TD3_(i) rotr(Td0[(i) & 0xff], 24)
-
-#endif /* AES_SMALL_TABLES */
-
-#define SWAP(x) (_lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00)
-
-#ifdef _MSC_VER
-#define GETU32(p) SWAP(*((u32 *)(p)))
-#define PUTU32(ct, st) { *((u32 *)(ct)) = SWAP((st)); }
-#else
-#define GETU32(pt) (((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ \
-((u32)(pt)[2] << 8) ^ ((u32)(pt)[3]))
-#define PUTU32(ct, st) { \
-(ct)[0] = (u8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); \
-(ct)[2] = (u8)((st) >> 8); (ct)[3] = (u8)(st); }
-#endif
-
/**
* Expand the cipher key into the encryption key schedule.
*
@@ -892,236 +803,3 @@ void rijndaelKeySetupEnc(u32 rk[/*44*/], const u8 cipherKey[])
rk += 4;
}
}
-
-#ifndef CONFIG_NO_AES_DECRYPT
-/**
- * Expand the cipher key into the decryption key schedule.
- *
- * @return the number of rounds for the given cipher key size.
- */
-void rijndaelKeySetupDec(u32 rk[/*44*/], const u8 cipherKey[])
-{
- int Nr = 10, i, j;
- u32 temp;
-
- /* expand the cipher key: */
- rijndaelKeySetupEnc(rk, cipherKey);
- /* invert the order of the round keys: */
- for (i = 0, j = 4*Nr; i < j; i += 4, j -= 4) {
- temp = rk[i ]; rk[i ] = rk[j ]; rk[j ] = temp;
- temp = rk[i + 1]; rk[i + 1] = rk[j + 1]; rk[j + 1] = temp;
- temp = rk[i + 2]; rk[i + 2] = rk[j + 2]; rk[j + 2] = temp;
- temp = rk[i + 3]; rk[i + 3] = rk[j + 3]; rk[j + 3] = temp;
- }
- /* apply the inverse MixColumn transform to all round keys but the
- * first and the last: */
- for (i = 1; i < Nr; i++) {
- rk += 4;
- for (j = 0; j < 4; j++) {
- rk[j] = TD0_(TE4((rk[j] >> 24) )) ^
- TD1_(TE4((rk[j] >> 16) & 0xff)) ^
- TD2_(TE4((rk[j] >> 8) & 0xff)) ^
- TD3_(TE4((rk[j] ) & 0xff));
- }
- }
-}
-#endif /* CONFIG_NO_AES_DECRYPT */
-
-#ifndef CONFIG_NO_AES_ENCRYPT
-void rijndaelEncrypt(const u32 rk[/*44*/], const u8 pt[16], u8 ct[16])
-{
- u32 s0, s1, s2, s3, t0, t1, t2, t3;
- const int Nr = 10;
-#ifndef FULL_UNROLL
- int r;
-#endif /* ?FULL_UNROLL */
-
- /*
- * map byte array block to cipher state
- * and add initial round key:
- */
- s0 = GETU32(pt ) ^ rk[0];
- s1 = GETU32(pt + 4) ^ rk[1];
- s2 = GETU32(pt + 8) ^ rk[2];
- s3 = GETU32(pt + 12) ^ rk[3];
-
-#define ROUND(i,d,s) \
-d##0 = TE0(s##0) ^ TE1(s##1) ^ TE2(s##2) ^ TE3(s##3) ^ rk[4 * i]; \
-d##1 = TE0(s##1) ^ TE1(s##2) ^ TE2(s##3) ^ TE3(s##0) ^ rk[4 * i + 1]; \
-d##2 = TE0(s##2) ^ TE1(s##3) ^ TE2(s##0) ^ TE3(s##1) ^ rk[4 * i + 2]; \
-d##3 = TE0(s##3) ^ TE1(s##0) ^ TE2(s##1) ^ TE3(s##2) ^ rk[4 * i + 3]
-
-#ifdef FULL_UNROLL
-
- ROUND(1,t,s);
- ROUND(2,s,t);
- ROUND(3,t,s);
- ROUND(4,s,t);
- ROUND(5,t,s);
- ROUND(6,s,t);
- ROUND(7,t,s);
- ROUND(8,s,t);
- ROUND(9,t,s);
-
- rk += Nr << 2;
-
-#else /* !FULL_UNROLL */
-
- /* Nr - 1 full rounds: */
- r = Nr >> 1;
- for (;;) {
- ROUND(1,t,s);
- rk += 8;
- if (--r == 0)
- break;
- ROUND(0,s,t);
- }
-
-#endif /* ?FULL_UNROLL */
-
-#undef ROUND
-
- /*
- * apply last round and
- * map cipher state to byte array block:
- */
- s0 = TE41(t0) ^ TE42(t1) ^ TE43(t2) ^ TE44(t3) ^ rk[0];
- PUTU32(ct , s0);
- s1 = TE41(t1) ^ TE42(t2) ^ TE43(t3) ^ TE44(t0) ^ rk[1];
- PUTU32(ct + 4, s1);
- s2 = TE41(t2) ^ TE42(t3) ^ TE43(t0) ^ TE44(t1) ^ rk[2];
- PUTU32(ct + 8, s2);
- s3 = TE41(t3) ^ TE42(t0) ^ TE43(t1) ^ TE44(t2) ^ rk[3];
- PUTU32(ct + 12, s3);
-}
-#endif /* CONFIG_NO_AES_ENCRYPT */
-
-void rijndaelDecrypt(const u32 rk[/*44*/], const u8 ct[16], u8 pt[16])
-{
- u32 s0, s1, s2, s3, t0, t1, t2, t3;
- const int Nr = 10;
-#ifndef FULL_UNROLL
- int r;
-#endif /* ?FULL_UNROLL */
-
- /*
- * map byte array block to cipher state
- * and add initial round key:
- */
- s0 = GETU32(ct ) ^ rk[0];
- s1 = GETU32(ct + 4) ^ rk[1];
- s2 = GETU32(ct + 8) ^ rk[2];
- s3 = GETU32(ct + 12) ^ rk[3];
-
-#define ROUND(i,d,s) \
-d##0 = TD0(s##0) ^ TD1(s##3) ^ TD2(s##2) ^ TD3(s##1) ^ rk[4 * i]; \
-d##1 = TD0(s##1) ^ TD1(s##0) ^ TD2(s##3) ^ TD3(s##2) ^ rk[4 * i + 1]; \
-d##2 = TD0(s##2) ^ TD1(s##1) ^ TD2(s##0) ^ TD3(s##3) ^ rk[4 * i + 2]; \
-d##3 = TD0(s##3) ^ TD1(s##2) ^ TD2(s##1) ^ TD3(s##0) ^ rk[4 * i + 3]
-
-#ifdef FULL_UNROLL
-
- ROUND(1,t,s);
- ROUND(2,s,t);
- ROUND(3,t,s);
- ROUND(4,s,t);
- ROUND(5,t,s);
- ROUND(6,s,t);
- ROUND(7,t,s);
- ROUND(8,s,t);
- ROUND(9,t,s);
-
- rk += Nr << 2;
-
-#else /* !FULL_UNROLL */
-
- /* Nr - 1 full rounds: */
- r = Nr >> 1;
- for (;;) {
- ROUND(1,t,s);
- rk += 8;
- if (--r == 0)
- break;
- ROUND(0,s,t);
- }
-
-#endif /* ?FULL_UNROLL */
-
-#undef ROUND
-
- /*
- * apply last round and
- * map cipher state to byte array block:
- */
- s0 = TD41(t0) ^ TD42(t3) ^ TD43(t2) ^ TD44(t1) ^ rk[0];
- PUTU32(pt , s0);
- s1 = TD41(t1) ^ TD42(t0) ^ TD43(t3) ^ TD44(t2) ^ rk[1];
- PUTU32(pt + 4, s1);
- s2 = TD41(t2) ^ TD42(t1) ^ TD43(t0) ^ TD44(t3) ^ rk[2];
- PUTU32(pt + 8, s2);
- s3 = TD41(t3) ^ TD42(t2) ^ TD43(t1) ^ TD44(t0) ^ rk[3];
- PUTU32(pt + 12, s3);
-}
-
-
-
-/* Generic wrapper functions for AES functions */
-
-#define AES_PRIV_SIZE (4 * 44)
-
-#ifndef CONFIG_NO_AES_ENCRYPT
-void * aes_encrypt_init(const u8 *key, size_t len)
-{
- u32 *rk;
- if (len != 16)
- return NULL;
- rk = os_malloc(AES_PRIV_SIZE);
- if (rk == NULL)
- return NULL;
- rijndaelKeySetupEnc(rk, key);
- return rk;
-}
-
-
-void aes_encrypt(void *ctx, const u8 *plain, u8 *crypt)
-{
- rijndaelEncrypt(ctx, plain, crypt);
-}
-
-
-void aes_encrypt_deinit(void *ctx)
-{
- os_memset(ctx, 0, AES_PRIV_SIZE);
- os_free(ctx);
-}
-#endif /* CONFIG_NO_AES_ENCRYPT */
-
-
-#ifndef CONFIG_NO_AES_DECRYPT
-void * aes_decrypt_init(const u8 *key, size_t len)
-{
- u32 *rk;
- if (len != 16)
- return NULL;
- rk = os_malloc(AES_PRIV_SIZE);
- if (rk == NULL)
- return NULL;
- rijndaelKeySetupDec(rk, key);
- return rk;
-}
-
-
-void aes_decrypt(void *ctx, const u8 *crypt, u8 *plain)
-{
- rijndaelDecrypt(ctx, crypt, plain);
-}
-
-
-void aes_decrypt_deinit(void *ctx)
-{
- os_memset(ctx, 0, AES_PRIV_SIZE);
- os_free(ctx);
-}
-#endif /* CONFIG_NO_AES_DECRYPT */
-
-#endif /* INTERNAL_AES */
diff --git a/contrib/wpa/src/crypto/aes-omac1.c b/contrib/wpa/src/crypto/aes-omac1.c
new file mode 100644
index 0000000..f775296
--- /dev/null
+++ b/contrib/wpa/src/crypto/aes-omac1.c
@@ -0,0 +1,124 @@
+/*
+ * One-key CBC MAC (OMAC1) hash with AES-128
+ *
+ * Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "aes.h"
+#include "aes_wrap.h"
+
+static void gf_mulx(u8 *pad)
+{
+ int i, carry;
+
+ carry = pad[0] & 0x80;
+ for (i = 0; i < AES_BLOCK_SIZE - 1; i++)
+ pad[i] = (pad[i] << 1) | (pad[i + 1] >> 7);
+ pad[AES_BLOCK_SIZE - 1] <<= 1;
+ if (carry)
+ pad[AES_BLOCK_SIZE - 1] ^= 0x87;
+}
+
+
+/**
+ * omac1_aes_128_vector - One-Key CBC MAC (OMAC1) hash with AES-128
+ * @key: 128-bit key for the hash operation
+ * @num_elem: Number of elements in the data vector
+ * @addr: Pointers to the data areas
+ * @len: Lengths of the data blocks
+ * @mac: Buffer for MAC (128 bits, i.e., 16 bytes)
+ * Returns: 0 on success, -1 on failure
+ *
+ * This is a mode for using block cipher (AES in this case) for authentication.
+ * OMAC1 was standardized with the name CMAC by NIST in a Special Publication
+ * (SP) 800-38B.
+ */
+int omac1_aes_128_vector(const u8 *key, size_t num_elem,
+ const u8 *addr[], const size_t *len, u8 *mac)
+{
+ void *ctx;
+ u8 cbc[AES_BLOCK_SIZE], pad[AES_BLOCK_SIZE];
+ const u8 *pos, *end;
+ size_t i, e, left, total_len;
+
+ ctx = aes_encrypt_init(key, 16);
+ if (ctx == NULL)
+ return -1;
+ os_memset(cbc, 0, AES_BLOCK_SIZE);
+
+ total_len = 0;
+ for (e = 0; e < num_elem; e++)
+ total_len += len[e];
+ left = total_len;
+
+ e = 0;
+ pos = addr[0];
+ end = pos + len[0];
+
+ while (left >= AES_BLOCK_SIZE) {
+ for (i = 0; i < AES_BLOCK_SIZE; i++) {
+ cbc[i] ^= *pos++;
+ if (pos >= end) {
+ e++;
+ pos = addr[e];
+ end = pos + len[e];
+ }
+ }
+ if (left > AES_BLOCK_SIZE)
+ aes_encrypt(ctx, cbc, cbc);
+ left -= AES_BLOCK_SIZE;
+ }
+
+ os_memset(pad, 0, AES_BLOCK_SIZE);
+ aes_encrypt(ctx, pad, pad);
+ gf_mulx(pad);
+
+ if (left || total_len == 0) {
+ for (i = 0; i < left; i++) {
+ cbc[i] ^= *pos++;
+ if (pos >= end) {
+ e++;
+ pos = addr[e];
+ end = pos + len[e];
+ }
+ }
+ cbc[left] ^= 0x80;
+ gf_mulx(pad);
+ }
+
+ for (i = 0; i < AES_BLOCK_SIZE; i++)
+ pad[i] ^= cbc[i];
+ aes_encrypt(ctx, pad, mac);
+ aes_encrypt_deinit(ctx);
+ return 0;
+}
+
+
+/**
+ * omac1_aes_128 - One-Key CBC MAC (OMAC1) hash with AES-128 (aka AES-CMAC)
+ * @key: 128-bit key for the hash operation
+ * @data: Data buffer for which a MAC is determined
+ * @data_len: Length of data buffer in bytes
+ * @mac: Buffer for MAC (128 bits, i.e., 16 bytes)
+ * Returns: 0 on success, -1 on failure
+ *
+ * This is a mode for using block cipher (AES in this case) for authentication.
+ * OMAC1 was standardized with the name CMAC by NIST in a Special Publication
+ * (SP) 800-38B.
+ */
+int omac1_aes_128(const u8 *key, const u8 *data, size_t data_len, u8 *mac)
+{
+ return omac1_aes_128_vector(key, 1, &data, &data_len, mac);
+}
diff --git a/contrib/wpa/src/crypto/aes-unwrap.c b/contrib/wpa/src/crypto/aes-unwrap.c
new file mode 100644
index 0000000..f233ffa
--- /dev/null
+++ b/contrib/wpa/src/crypto/aes-unwrap.c
@@ -0,0 +1,79 @@
+/*
+ * AES key unwrap (128-bit KEK, RFC3394)
+ *
+ * Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "aes.h"
+#include "aes_wrap.h"
+
+/**
+ * aes_unwrap - Unwrap key with AES Key Wrap Algorithm (128-bit KEK) (RFC3394)
+ * @kek: Key encryption key (KEK)
+ * @n: Length of the plaintext key in 64-bit units; e.g., 2 = 128-bit = 16
+ * bytes
+ * @cipher: Wrapped key to be unwrapped, (n + 1) * 64 bits
+ * @plain: Plaintext key, n * 64 bits
+ * Returns: 0 on success, -1 on failure (e.g., integrity verification failed)
+ */
+int aes_unwrap(const u8 *kek, int n, const u8 *cipher, u8 *plain)
+{
+ u8 a[8], *r, b[16];
+ int i, j;
+ void *ctx;
+
+ /* 1) Initialize variables. */
+ os_memcpy(a, cipher, 8);
+ r = plain;
+ os_memcpy(r, cipher + 8, 8 * n);
+
+ ctx = aes_decrypt_init(kek, 16);
+ if (ctx == NULL)
+ return -1;
+
+ /* 2) Compute intermediate values.
+ * For j = 5 to 0
+ * For i = n to 1
+ * B = AES-1(K, (A ^ t) | R[i]) where t = n*j+i
+ * A = MSB(64, B)
+ * R[i] = LSB(64, B)
+ */
+ for (j = 5; j >= 0; j--) {
+ r = plain + (n - 1) * 8;
+ for (i = n; i >= 1; i--) {
+ os_memcpy(b, a, 8);
+ b[7] ^= n * j + i;
+
+ os_memcpy(b + 8, r, 8);
+ aes_decrypt(ctx, b, b);
+ os_memcpy(a, b, 8);
+ os_memcpy(r, b + 8, 8);
+ r -= 8;
+ }
+ }
+ aes_decrypt_deinit(ctx);
+
+ /* 3) Output results.
+ *
+ * These are already in @plain due to the location of temporary
+ * variables. Just verify that the IV matches with the expected value.
+ */
+ for (i = 0; i < 8; i++) {
+ if (a[i] != 0xa6)
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/contrib/wpa/src/crypto/aes-wrap.c b/contrib/wpa/src/crypto/aes-wrap.c
new file mode 100644
index 0000000..28d0c89
--- /dev/null
+++ b/contrib/wpa/src/crypto/aes-wrap.c
@@ -0,0 +1,76 @@
+/*
+ * AES Key Wrap Algorithm (128-bit KEK) (RFC3394)
+ *
+ * Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "aes.h"
+#include "aes_wrap.h"
+
+/**
+ * aes_wrap - Wrap keys with AES Key Wrap Algorithm (128-bit KEK) (RFC3394)
+ * @kek: 16-octet Key encryption key (KEK)
+ * @n: Length of the plaintext key in 64-bit units; e.g., 2 = 128-bit = 16
+ * bytes
+ * @plain: Plaintext key to be wrapped, n * 64 bits
+ * @cipher: Wrapped key, (n + 1) * 64 bits
+ * Returns: 0 on success, -1 on failure
+ */
+int aes_wrap(const u8 *kek, int n, const u8 *plain, u8 *cipher)
+{
+ u8 *a, *r, b[16];
+ int i, j;
+ void *ctx;
+
+ a = cipher;
+ r = cipher + 8;
+
+ /* 1) Initialize variables. */
+ os_memset(a, 0xa6, 8);
+ os_memcpy(r, plain, 8 * n);
+
+ ctx = aes_encrypt_init(kek, 16);
+ if (ctx == NULL)
+ return -1;
+
+ /* 2) Calculate intermediate values.
+ * For j = 0 to 5
+ * For i=1 to n
+ * B = AES(K, A | R[i])
+ * A = MSB(64, B) ^ t where t = (n*j)+i
+ * R[i] = LSB(64, B)
+ */
+ for (j = 0; j <= 5; j++) {
+ r = cipher + 8;
+ for (i = 1; i <= n; i++) {
+ os_memcpy(b, a, 8);
+ os_memcpy(b + 8, r, 8);
+ aes_encrypt(ctx, b, b);
+ os_memcpy(a, b, 8);
+ a[7] ^= n * j + i;
+ os_memcpy(r, b + 8, 8);
+ r += 8;
+ }
+ }
+ aes_encrypt_deinit(ctx);
+
+ /* 3) Output the results.
+ *
+ * These are already in @cipher due to the location of temporary
+ * variables.
+ */
+
+ return 0;
+}
diff --git a/contrib/wpa/src/crypto/aes.h b/contrib/wpa/src/crypto/aes.h
index 6b9f414..ba384a9 100644
--- a/contrib/wpa/src/crypto/aes.h
+++ b/contrib/wpa/src/crypto/aes.h
@@ -15,6 +15,8 @@
#ifndef AES_H
#define AES_H
+#define AES_BLOCK_SIZE 16
+
void * aes_encrypt_init(const u8 *key, size_t len);
void aes_encrypt(void *ctx, const u8 *plain, u8 *crypt);
void aes_encrypt_deinit(void *ctx);
diff --git a/contrib/wpa/src/crypto/aes_i.h b/contrib/wpa/src/crypto/aes_i.h
new file mode 100644
index 0000000..6b40bc7
--- /dev/null
+++ b/contrib/wpa/src/crypto/aes_i.h
@@ -0,0 +1,122 @@
+/*
+ * AES (Rijndael) cipher
+ * Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef AES_I_H
+#define AES_I_H
+
+#include "aes.h"
+
+/* #define FULL_UNROLL */
+#define AES_SMALL_TABLES
+
+extern const u32 Te0[256];
+extern const u32 Te1[256];
+extern const u32 Te2[256];
+extern const u32 Te3[256];
+extern const u32 Te4[256];
+extern const u32 Td0[256];
+extern const u32 Td1[256];
+extern const u32 Td2[256];
+extern const u32 Td3[256];
+extern const u32 Td4[256];
+extern const u32 rcon[10];
+extern const u8 Td4s[256];
+extern const u8 rcons[10];
+
+#ifndef AES_SMALL_TABLES
+
+#define RCON(i) rcon[(i)]
+
+#define TE0(i) Te0[((i) >> 24) & 0xff]
+#define TE1(i) Te1[((i) >> 16) & 0xff]
+#define TE2(i) Te2[((i) >> 8) & 0xff]
+#define TE3(i) Te3[(i) & 0xff]
+#define TE41(i) (Te4[((i) >> 24) & 0xff] & 0xff000000)
+#define TE42(i) (Te4[((i) >> 16) & 0xff] & 0x00ff0000)
+#define TE43(i) (Te4[((i) >> 8) & 0xff] & 0x0000ff00)
+#define TE44(i) (Te4[(i) & 0xff] & 0x000000ff)
+#define TE421(i) (Te4[((i) >> 16) & 0xff] & 0xff000000)
+#define TE432(i) (Te4[((i) >> 8) & 0xff] & 0x00ff0000)
+#define TE443(i) (Te4[(i) & 0xff] & 0x0000ff00)
+#define TE414(i) (Te4[((i) >> 24) & 0xff] & 0x000000ff)
+#define TE4(i) (Te4[(i)] & 0x000000ff)
+
+#define TD0(i) Td0[((i) >> 24) & 0xff]
+#define TD1(i) Td1[((i) >> 16) & 0xff]
+#define TD2(i) Td2[((i) >> 8) & 0xff]
+#define TD3(i) Td3[(i) & 0xff]
+#define TD41(i) (Td4[((i) >> 24) & 0xff] & 0xff000000)
+#define TD42(i) (Td4[((i) >> 16) & 0xff] & 0x00ff0000)
+#define TD43(i) (Td4[((i) >> 8) & 0xff] & 0x0000ff00)
+#define TD44(i) (Td4[(i) & 0xff] & 0x000000ff)
+#define TD0_(i) Td0[(i) & 0xff]
+#define TD1_(i) Td1[(i) & 0xff]
+#define TD2_(i) Td2[(i) & 0xff]
+#define TD3_(i) Td3[(i) & 0xff]
+
+#else /* AES_SMALL_TABLES */
+
+#define RCON(i) (rcons[(i)] << 24)
+
+static inline u32 rotr(u32 val, int bits)
+{
+ return (val >> bits) | (val << (32 - bits));
+}
+
+#define TE0(i) Te0[((i) >> 24) & 0xff]
+#define TE1(i) rotr(Te0[((i) >> 16) & 0xff], 8)
+#define TE2(i) rotr(Te0[((i) >> 8) & 0xff], 16)
+#define TE3(i) rotr(Te0[(i) & 0xff], 24)
+#define TE41(i) ((Te0[((i) >> 24) & 0xff] << 8) & 0xff000000)
+#define TE42(i) (Te0[((i) >> 16) & 0xff] & 0x00ff0000)
+#define TE43(i) (Te0[((i) >> 8) & 0xff] & 0x0000ff00)
+#define TE44(i) ((Te0[(i) & 0xff] >> 8) & 0x000000ff)
+#define TE421(i) ((Te0[((i) >> 16) & 0xff] << 8) & 0xff000000)
+#define TE432(i) (Te0[((i) >> 8) & 0xff] & 0x00ff0000)
+#define TE443(i) (Te0[(i) & 0xff] & 0x0000ff00)
+#define TE414(i) ((Te0[((i) >> 24) & 0xff] >> 8) & 0x000000ff)
+#define TE4(i) ((Te0[(i)] >> 8) & 0x000000ff)
+
+#define TD0(i) Td0[((i) >> 24) & 0xff]
+#define TD1(i) rotr(Td0[((i) >> 16) & 0xff], 8)
+#define TD2(i) rotr(Td0[((i) >> 8) & 0xff], 16)
+#define TD3(i) rotr(Td0[(i) & 0xff], 24)
+#define TD41(i) (Td4s[((i) >> 24) & 0xff] << 24)
+#define TD42(i) (Td4s[((i) >> 16) & 0xff] << 16)
+#define TD43(i) (Td4s[((i) >> 8) & 0xff] << 8)
+#define TD44(i) (Td4s[(i) & 0xff])
+#define TD0_(i) Td0[(i) & 0xff]
+#define TD1_(i) rotr(Td0[(i) & 0xff], 8)
+#define TD2_(i) rotr(Td0[(i) & 0xff], 16)
+#define TD3_(i) rotr(Td0[(i) & 0xff], 24)
+
+#endif /* AES_SMALL_TABLES */
+
+#ifdef _MSC_VER
+#define SWAP(x) (_lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00)
+#define GETU32(p) SWAP(*((u32 *)(p)))
+#define PUTU32(ct, st) { *((u32 *)(ct)) = SWAP((st)); }
+#else
+#define GETU32(pt) (((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ \
+((u32)(pt)[2] << 8) ^ ((u32)(pt)[3]))
+#define PUTU32(ct, st) { \
+(ct)[0] = (u8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); \
+(ct)[2] = (u8)((st) >> 8); (ct)[3] = (u8)(st); }
+#endif
+
+#define AES_PRIV_SIZE (4 * 44)
+
+void rijndaelKeySetupEnc(u32 rk[/*44*/], const u8 cipherKey[]);
+
+#endif /* AES_I_H */
diff --git a/contrib/wpa/src/crypto/aes_wrap.c b/contrib/wpa/src/crypto/aes_wrap.c
deleted file mode 100644
index b1448b0..0000000
--- a/contrib/wpa/src/crypto/aes_wrap.c
+++ /dev/null
@@ -1,533 +0,0 @@
-/*
- * AES-based functions
- *
- * - AES Key Wrap Algorithm (128-bit KEK) (RFC3394)
- * - One-Key CBC MAC (OMAC1, i.e., CMAC) hash with AES-128
- * - AES-128 CTR mode encryption
- * - AES-128 EAX mode encryption/decryption
- * - AES-128 CBC
- *
- * Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
- */
-
-#include "includes.h"
-
-#include "common.h"
-#include "aes_wrap.h"
-#include "crypto.h"
-
-#ifndef CONFIG_NO_AES_WRAP
-
-/**
- * aes_wrap - Wrap keys with AES Key Wrap Algorithm (128-bit KEK) (RFC3394)
- * @kek: 16-octet Key encryption key (KEK)
- * @n: Length of the plaintext key in 64-bit units; e.g., 2 = 128-bit = 16
- * bytes
- * @plain: Plaintext key to be wrapped, n * 64 bits
- * @cipher: Wrapped key, (n + 1) * 64 bits
- * Returns: 0 on success, -1 on failure
- */
-int aes_wrap(const u8 *kek, int n, const u8 *plain, u8 *cipher)
-{
- u8 *a, *r, b[16];
- int i, j;
- void *ctx;
-
- a = cipher;
- r = cipher + 8;
-
- /* 1) Initialize variables. */
- os_memset(a, 0xa6, 8);
- os_memcpy(r, plain, 8 * n);
-
- ctx = aes_encrypt_init(kek, 16);
- if (ctx == NULL)
- return -1;
-
- /* 2) Calculate intermediate values.
- * For j = 0 to 5
- * For i=1 to n
- * B = AES(K, A | R[i])
- * A = MSB(64, B) ^ t where t = (n*j)+i
- * R[i] = LSB(64, B)
- */
- for (j = 0; j <= 5; j++) {
- r = cipher + 8;
- for (i = 1; i <= n; i++) {
- os_memcpy(b, a, 8);
- os_memcpy(b + 8, r, 8);
- aes_encrypt(ctx, b, b);
- os_memcpy(a, b, 8);
- a[7] ^= n * j + i;
- os_memcpy(r, b + 8, 8);
- r += 8;
- }
- }
- aes_encrypt_deinit(ctx);
-
- /* 3) Output the results.
- *
- * These are already in @cipher due to the location of temporary
- * variables.
- */
-
- return 0;
-}
-
-#endif /* CONFIG_NO_AES_WRAP */
-
-
-#ifndef CONFIG_NO_AES_UNWRAP
-
-/**
- * aes_unwrap - Unwrap key with AES Key Wrap Algorithm (128-bit KEK) (RFC3394)
- * @kek: Key encryption key (KEK)
- * @n: Length of the plaintext key in 64-bit units; e.g., 2 = 128-bit = 16
- * bytes
- * @cipher: Wrapped key to be unwrapped, (n + 1) * 64 bits
- * @plain: Plaintext key, n * 64 bits
- * Returns: 0 on success, -1 on failure (e.g., integrity verification failed)
- */
-int aes_unwrap(const u8 *kek, int n, const u8 *cipher, u8 *plain)
-{
- u8 a[8], *r, b[16];
- int i, j;
- void *ctx;
-
- /* 1) Initialize variables. */
- os_memcpy(a, cipher, 8);
- r = plain;
- os_memcpy(r, cipher + 8, 8 * n);
-
- ctx = aes_decrypt_init(kek, 16);
- if (ctx == NULL)
- return -1;
-
- /* 2) Compute intermediate values.
- * For j = 5 to 0
- * For i = n to 1
- * B = AES-1(K, (A ^ t) | R[i]) where t = n*j+i
- * A = MSB(64, B)
- * R[i] = LSB(64, B)
- */
- for (j = 5; j >= 0; j--) {
- r = plain + (n - 1) * 8;
- for (i = n; i >= 1; i--) {
- os_memcpy(b, a, 8);
- b[7] ^= n * j + i;
-
- os_memcpy(b + 8, r, 8);
- aes_decrypt(ctx, b, b);
- os_memcpy(a, b, 8);
- os_memcpy(r, b + 8, 8);
- r -= 8;
- }
- }
- aes_decrypt_deinit(ctx);
-
- /* 3) Output results.
- *
- * These are already in @plain due to the location of temporary
- * variables. Just verify that the IV matches with the expected value.
- */
- for (i = 0; i < 8; i++) {
- if (a[i] != 0xa6)
- return -1;
- }
-
- return 0;
-}
-
-#endif /* CONFIG_NO_AES_UNWRAP */
-
-
-#define BLOCK_SIZE 16
-
-#ifndef CONFIG_NO_AES_OMAC1
-
-static void gf_mulx(u8 *pad)
-{
- int i, carry;
-
- carry = pad[0] & 0x80;
- for (i = 0; i < BLOCK_SIZE - 1; i++)
- pad[i] = (pad[i] << 1) | (pad[i + 1] >> 7);
- pad[BLOCK_SIZE - 1] <<= 1;
- if (carry)
- pad[BLOCK_SIZE - 1] ^= 0x87;
-}
-
-
-/**
- * omac1_aes_128_vector - One-Key CBC MAC (OMAC1) hash with AES-128
- * @key: 128-bit key for the hash operation
- * @num_elem: Number of elements in the data vector
- * @addr: Pointers to the data areas
- * @len: Lengths of the data blocks
- * @mac: Buffer for MAC (128 bits, i.e., 16 bytes)
- * Returns: 0 on success, -1 on failure
- *
- * This is a mode for using block cipher (AES in this case) for authentication.
- * OMAC1 was standardized with the name CMAC by NIST in a Special Publication
- * (SP) 800-38B.
- */
-int omac1_aes_128_vector(const u8 *key, size_t num_elem,
- const u8 *addr[], const size_t *len, u8 *mac)
-{
- void *ctx;
- u8 cbc[BLOCK_SIZE], pad[BLOCK_SIZE];
- const u8 *pos, *end;
- size_t i, e, left, total_len;
-
- ctx = aes_encrypt_init(key, 16);
- if (ctx == NULL)
- return -1;
- os_memset(cbc, 0, BLOCK_SIZE);
-
- total_len = 0;
- for (e = 0; e < num_elem; e++)
- total_len += len[e];
- left = total_len;
-
- e = 0;
- pos = addr[0];
- end = pos + len[0];
-
- while (left >= BLOCK_SIZE) {
- for (i = 0; i < BLOCK_SIZE; i++) {
- cbc[i] ^= *pos++;
- if (pos >= end) {
- e++;
- pos = addr[e];
- end = pos + len[e];
- }
- }
- if (left > BLOCK_SIZE)
- aes_encrypt(ctx, cbc, cbc);
- left -= BLOCK_SIZE;
- }
-
- os_memset(pad, 0, BLOCK_SIZE);
- aes_encrypt(ctx, pad, pad);
- gf_mulx(pad);
-
- if (left || total_len == 0) {
- for (i = 0; i < left; i++) {
- cbc[i] ^= *pos++;
- if (pos >= end) {
- e++;
- pos = addr[e];
- end = pos + len[e];
- }
- }
- cbc[left] ^= 0x80;
- gf_mulx(pad);
- }
-
- for (i = 0; i < BLOCK_SIZE; i++)
- pad[i] ^= cbc[i];
- aes_encrypt(ctx, pad, mac);
- aes_encrypt_deinit(ctx);
- return 0;
-}
-
-
-/**
- * omac1_aes_128 - One-Key CBC MAC (OMAC1) hash with AES-128 (aka AES-CMAC)
- * @key: 128-bit key for the hash operation
- * @data: Data buffer for which a MAC is determined
- * @data_len: Length of data buffer in bytes
- * @mac: Buffer for MAC (128 bits, i.e., 16 bytes)
- * Returns: 0 on success, -1 on failure
- *
- * This is a mode for using block cipher (AES in this case) for authentication.
- * OMAC1 was standardized with the name CMAC by NIST in a Special Publication
- * (SP) 800-38B.
- */
-int omac1_aes_128(const u8 *key, const u8 *data, size_t data_len, u8 *mac)
-{
- return omac1_aes_128_vector(key, 1, &data, &data_len, mac);
-}
-
-#endif /* CONFIG_NO_AES_OMAC1 */
-
-
-#ifndef CONFIG_NO_AES_ENCRYPT_BLOCK
-/**
- * aes_128_encrypt_block - Perform one AES 128-bit block operation
- * @key: Key for AES
- * @in: Input data (16 bytes)
- * @out: Output of the AES block operation (16 bytes)
- * Returns: 0 on success, -1 on failure
- */
-int aes_128_encrypt_block(const u8 *key, const u8 *in, u8 *out)
-{
- void *ctx;
- ctx = aes_encrypt_init(key, 16);
- if (ctx == NULL)
- return -1;
- aes_encrypt(ctx, in, out);
- aes_encrypt_deinit(ctx);
- return 0;
-}
-#endif /* CONFIG_NO_AES_ENCRYPT_BLOCK */
-
-
-#ifndef CONFIG_NO_AES_CTR
-
-/**
- * aes_128_ctr_encrypt - AES-128 CTR mode encryption
- * @key: Key for encryption (16 bytes)
- * @nonce: Nonce for counter mode (16 bytes)
- * @data: Data to encrypt in-place
- * @data_len: Length of data in bytes
- * Returns: 0 on success, -1 on failure
- */
-int aes_128_ctr_encrypt(const u8 *key, const u8 *nonce,
- u8 *data, size_t data_len)
-{
- void *ctx;
- size_t j, len, left = data_len;
- int i;
- u8 *pos = data;
- u8 counter[BLOCK_SIZE], buf[BLOCK_SIZE];
-
- ctx = aes_encrypt_init(key, 16);
- if (ctx == NULL)
- return -1;
- os_memcpy(counter, nonce, BLOCK_SIZE);
-
- while (left > 0) {
- aes_encrypt(ctx, counter, buf);
-
- len = (left < BLOCK_SIZE) ? left : BLOCK_SIZE;
- for (j = 0; j < len; j++)
- pos[j] ^= buf[j];
- pos += len;
- left -= len;
-
- for (i = BLOCK_SIZE - 1; i >= 0; i--) {
- counter[i]++;
- if (counter[i])
- break;
- }
- }
- aes_encrypt_deinit(ctx);
- return 0;
-}
-
-#endif /* CONFIG_NO_AES_CTR */
-
-
-#ifndef CONFIG_NO_AES_EAX
-
-/**
- * aes_128_eax_encrypt - AES-128 EAX mode encryption
- * @key: Key for encryption (16 bytes)
- * @nonce: Nonce for counter mode
- * @nonce_len: Nonce length in bytes
- * @hdr: Header data to be authenticity protected
- * @hdr_len: Length of the header data bytes
- * @data: Data to encrypt in-place
- * @data_len: Length of data in bytes
- * @tag: 16-byte tag value
- * Returns: 0 on success, -1 on failure
- */
-int aes_128_eax_encrypt(const u8 *key, const u8 *nonce, size_t nonce_len,
- const u8 *hdr, size_t hdr_len,
- u8 *data, size_t data_len, u8 *tag)
-{
- u8 *buf;
- size_t buf_len;
- u8 nonce_mac[BLOCK_SIZE], hdr_mac[BLOCK_SIZE], data_mac[BLOCK_SIZE];
- int i, ret = -1;
-
- if (nonce_len > data_len)
- buf_len = nonce_len;
- else
- buf_len = data_len;
- if (hdr_len > buf_len)
- buf_len = hdr_len;
- buf_len += 16;
-
- buf = os_malloc(buf_len);
- if (buf == NULL)
- return -1;
-
- os_memset(buf, 0, 15);
-
- buf[15] = 0;
- os_memcpy(buf + 16, nonce, nonce_len);
- if (omac1_aes_128(key, buf, 16 + nonce_len, nonce_mac))
- goto fail;
-
- buf[15] = 1;
- os_memcpy(buf + 16, hdr, hdr_len);
- if (omac1_aes_128(key, buf, 16 + hdr_len, hdr_mac))
- goto fail;
-
- if (aes_128_ctr_encrypt(key, nonce_mac, data, data_len))
- goto fail;
- buf[15] = 2;
- os_memcpy(buf + 16, data, data_len);
- if (omac1_aes_128(key, buf, 16 + data_len, data_mac))
- goto fail;
-
- for (i = 0; i < BLOCK_SIZE; i++)
- tag[i] = nonce_mac[i] ^ data_mac[i] ^ hdr_mac[i];
-
- ret = 0;
-fail:
- os_free(buf);
-
- return ret;
-}
-
-
-/**
- * aes_128_eax_decrypt - AES-128 EAX mode decryption
- * @key: Key for decryption (16 bytes)
- * @nonce: Nonce for counter mode
- * @nonce_len: Nonce length in bytes
- * @hdr: Header data to be authenticity protected
- * @hdr_len: Length of the header data bytes
- * @data: Data to encrypt in-place
- * @data_len: Length of data in bytes
- * @tag: 16-byte tag value
- * Returns: 0 on success, -1 on failure, -2 if tag does not match
- */
-int aes_128_eax_decrypt(const u8 *key, const u8 *nonce, size_t nonce_len,
- const u8 *hdr, size_t hdr_len,
- u8 *data, size_t data_len, const u8 *tag)
-{
- u8 *buf;
- size_t buf_len;
- u8 nonce_mac[BLOCK_SIZE], hdr_mac[BLOCK_SIZE], data_mac[BLOCK_SIZE];
- int i;
-
- if (nonce_len > data_len)
- buf_len = nonce_len;
- else
- buf_len = data_len;
- if (hdr_len > buf_len)
- buf_len = hdr_len;
- buf_len += 16;
-
- buf = os_malloc(buf_len);
- if (buf == NULL)
- return -1;
-
- os_memset(buf, 0, 15);
-
- buf[15] = 0;
- os_memcpy(buf + 16, nonce, nonce_len);
- if (omac1_aes_128(key, buf, 16 + nonce_len, nonce_mac)) {
- os_free(buf);
- return -1;
- }
-
- buf[15] = 1;
- os_memcpy(buf + 16, hdr, hdr_len);
- if (omac1_aes_128(key, buf, 16 + hdr_len, hdr_mac)) {
- os_free(buf);
- return -1;
- }
-
- buf[15] = 2;
- os_memcpy(buf + 16, data, data_len);
- if (omac1_aes_128(key, buf, 16 + data_len, data_mac)) {
- os_free(buf);
- return -1;
- }
-
- os_free(buf);
-
- for (i = 0; i < BLOCK_SIZE; i++) {
- if (tag[i] != (nonce_mac[i] ^ data_mac[i] ^ hdr_mac[i]))
- return -2;
- }
-
- return aes_128_ctr_encrypt(key, nonce_mac, data, data_len);
-}
-
-#endif /* CONFIG_NO_AES_EAX */
-
-
-#ifndef CONFIG_NO_AES_CBC
-
-/**
- * aes_128_cbc_encrypt - AES-128 CBC encryption
- * @key: Encryption key
- * @iv: Encryption IV for CBC mode (16 bytes)
- * @data: Data to encrypt in-place
- * @data_len: Length of data in bytes (must be divisible by 16)
- * Returns: 0 on success, -1 on failure
- */
-int aes_128_cbc_encrypt(const u8 *key, const u8 *iv, u8 *data, size_t data_len)
-{
- void *ctx;
- u8 cbc[BLOCK_SIZE];
- u8 *pos = data;
- int i, j, blocks;
-
- ctx = aes_encrypt_init(key, 16);
- if (ctx == NULL)
- return -1;
- os_memcpy(cbc, iv, BLOCK_SIZE);
-
- blocks = data_len / BLOCK_SIZE;
- for (i = 0; i < blocks; i++) {
- for (j = 0; j < BLOCK_SIZE; j++)
- cbc[j] ^= pos[j];
- aes_encrypt(ctx, cbc, cbc);
- os_memcpy(pos, cbc, BLOCK_SIZE);
- pos += BLOCK_SIZE;
- }
- aes_encrypt_deinit(ctx);
- return 0;
-}
-
-
-/**
- * aes_128_cbc_decrypt - AES-128 CBC decryption
- * @key: Decryption key
- * @iv: Decryption IV for CBC mode (16 bytes)
- * @data: Data to decrypt in-place
- * @data_len: Length of data in bytes (must be divisible by 16)
- * Returns: 0 on success, -1 on failure
- */
-int aes_128_cbc_decrypt(const u8 *key, const u8 *iv, u8 *data, size_t data_len)
-{
- void *ctx;
- u8 cbc[BLOCK_SIZE], tmp[BLOCK_SIZE];
- u8 *pos = data;
- int i, j, blocks;
-
- ctx = aes_decrypt_init(key, 16);
- if (ctx == NULL)
- return -1;
- os_memcpy(cbc, iv, BLOCK_SIZE);
-
- blocks = data_len / BLOCK_SIZE;
- for (i = 0; i < blocks; i++) {
- os_memcpy(tmp, pos, BLOCK_SIZE);
- aes_decrypt(ctx, pos, pos);
- for (j = 0; j < BLOCK_SIZE; j++)
- pos[j] ^= cbc[j];
- os_memcpy(cbc, tmp, BLOCK_SIZE);
- pos += BLOCK_SIZE;
- }
- aes_decrypt_deinit(ctx);
- return 0;
-}
-
-#endif /* CONFIG_NO_AES_CBC */
diff --git a/contrib/wpa/src/crypto/crypto.h b/contrib/wpa/src/crypto/crypto.h
index a5129bb..587b5a9 100644
--- a/contrib/wpa/src/crypto/crypto.h
+++ b/contrib/wpa/src/crypto/crypto.h
@@ -1,6 +1,6 @@
/*
* WPA Supplicant / wrapper functions for crypto libraries
- * Copyright (c) 2004-2007, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -33,8 +33,9 @@
* @addr: Pointers to the data areas
* @len: Lengths of the data blocks
* @mac: Buffer for the hash
+ * Returns: 0 on success, -1 on failure
*/
-void md4_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac);
+int md4_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac);
/**
* md5_vector - MD5 hash for data vector
@@ -42,8 +43,25 @@ void md4_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac);
* @addr: Pointers to the data areas
* @len: Lengths of the data blocks
* @mac: Buffer for the hash
+ * Returns: 0 on success, -1 on failure
+ */
+int md5_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac);
+
+#ifdef CONFIG_FIPS
+/**
+ * md5_vector_non_fips_allow - MD5 hash for data vector (non-FIPS use allowed)
+ * @num_elem: Number of elements in the data vector
+ * @addr: Pointers to the data areas
+ * @len: Lengths of the data blocks
+ * @mac: Buffer for the hash
+ * Returns: 0 on success, -1 on failure
*/
-void md5_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac);
+int md5_vector_non_fips_allow(size_t num_elem, const u8 *addr[],
+ const size_t *len, u8 *mac);
+#else /* CONFIG_FIPS */
+#define md5_vector_non_fips_allow md5_vector
+#endif /* CONFIG_FIPS */
+
/**
* sha1_vector - SHA-1 hash for data vector
@@ -51,9 +69,10 @@ void md5_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac);
* @addr: Pointers to the data areas
* @len: Lengths of the data blocks
* @mac: Buffer for the hash
+ * Returns: 0 on success, -1 on failure
*/
-void sha1_vector(size_t num_elem, const u8 *addr[], const size_t *len,
- u8 *mac);
+int sha1_vector(size_t num_elem, const u8 *addr[], const size_t *len,
+ u8 *mac);
/**
* fips186_2-prf - NIST FIPS Publication 186-2 change notice 1 PRF
@@ -76,9 +95,10 @@ int __must_check fips186_2_prf(const u8 *seed, size_t seed_len, u8 *x,
* @addr: Pointers to the data areas
* @len: Lengths of the data blocks
* @mac: Buffer for the hash
+ * Returns: 0 on success, -1 on failure
*/
-void sha256_vector(size_t num_elem, const u8 *addr[], const size_t *len,
- u8 *mac);
+int sha256_vector(size_t num_elem, const u8 *addr[], const size_t *len,
+ u8 *mac);
/**
* des_encrypt - Encrypt one block with DES
@@ -275,6 +295,7 @@ struct crypto_public_key * crypto_public_key_import(const u8 *key, size_t len);
* crypto_private_key_import - Import an RSA private key
* @key: Key buffer (DER encoded RSA private key)
* @len: Key buffer length in bytes
+ * @passwd: Key encryption password or %NULL if key is not encrypted
* Returns: Pointer to the private key or %NULL on failure
*
* This function is only used with internal TLSv1 implementation
@@ -282,7 +303,8 @@ struct crypto_public_key * crypto_public_key_import(const u8 *key, size_t len);
* to implement this.
*/
struct crypto_private_key * crypto_private_key_import(const u8 *key,
- size_t len);
+ size_t len,
+ const char *passwd);
/**
* crypto_public_key_from_cert - Import an RSA public key from a certificate
@@ -428,4 +450,20 @@ int __must_check crypto_mod_exp(const u8 *base, size_t base_len,
const u8 *modulus, size_t modulus_len,
u8 *result, size_t *result_len);
+/**
+ * rc4_skip - XOR RC4 stream to given data with skip-stream-start
+ * @key: RC4 key
+ * @keylen: RC4 key length
+ * @skip: number of bytes to skip from the beginning of the RC4 stream
+ * @data: data to be XOR'ed with RC4 stream
+ * @data_len: buf length
+ * Returns: 0 on success, -1 on failure
+ *
+ * Generate RC4 pseudo random stream for the given key, skip beginning of the
+ * stream, and XOR the end result with the data buffer to perform RC4
+ * encryption/decryption.
+ */
+int rc4_skip(const u8 *key, size_t keylen, size_t skip,
+ u8 *data, size_t data_len);
+
#endif /* CRYPTO_H */
diff --git a/contrib/wpa/src/crypto/crypto_cryptoapi.c b/contrib/wpa/src/crypto/crypto_cryptoapi.c
index 45333dd..2a8d200 100644
--- a/contrib/wpa/src/crypto/crypto_cryptoapi.c
+++ b/contrib/wpa/src/crypto/crypto_cryptoapi.c
@@ -33,7 +33,6 @@ L"Microsoft Enhanced RSA and AES Cryptographic Provider (Prototype)"
#define CALG_HMAC (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_HMAC)
#endif
-#ifdef CONFIG_TLS_INTERNAL
#ifdef __MINGW32_VERSION
/*
* MinGW does not yet include all the needed definitions for CryptoAPI, so
@@ -83,7 +82,6 @@ static int mingw_load_crypto_func(void)
}
#endif /* __MINGW32_VERSION */
-#endif /* CONFIG_TLS_INTERNAL */
static void cryptoapi_report_error(const char *msg)
@@ -152,9 +150,9 @@ int cryptoapi_hash_vector(ALG_ID alg, size_t hash_len, size_t num_elem,
}
-void md4_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
+int md4_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
{
- cryptoapi_hash_vector(CALG_MD4, 16, num_elem, addr, len, mac);
+ return cryptoapi_hash_vector(CALG_MD4, 16, num_elem, addr, len, mac);
}
@@ -223,16 +221,15 @@ void des_encrypt(const u8 *clear, const u8 *key, u8 *cypher)
}
-#ifdef EAP_TLS_FUNCS
-void md5_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
+int md5_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
{
- cryptoapi_hash_vector(CALG_MD5, 16, num_elem, addr, len, mac);
+ return cryptoapi_hash_vector(CALG_MD5, 16, num_elem, addr, len, mac);
}
-void sha1_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
+int sha1_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
{
- cryptoapi_hash_vector(CALG_SHA, 20, num_elem, addr, len, mac);
+ return cryptoapi_hash_vector(CALG_SHA, 20, num_elem, addr, len, mac);
}
@@ -349,7 +346,6 @@ void aes_decrypt_deinit(void *ctx)
aes_encrypt_deinit(ctx);
}
-#ifdef CONFIG_TLS_INTERNAL
struct crypto_hash {
enum crypto_hash_alg alg;
@@ -657,7 +653,8 @@ struct crypto_public_key * crypto_public_key_import(const u8 *key, size_t len)
struct crypto_private_key * crypto_private_key_import(const u8 *key,
- size_t len)
+ size_t len,
+ const char *passwd)
{
/* TODO */
return NULL;
@@ -781,6 +778,12 @@ void crypto_global_deinit(void)
{
}
-#endif /* CONFIG_TLS_INTERNAL */
-#endif /* EAP_TLS_FUNCS */
+int crypto_mod_exp(const u8 *base, size_t base_len,
+ const u8 *power, size_t power_len,
+ const u8 *modulus, size_t modulus_len,
+ u8 *result, size_t *result_len)
+{
+ /* TODO */
+ return -1;
+}
diff --git a/contrib/wpa/src/crypto/crypto_gnutls.c b/contrib/wpa/src/crypto/crypto_gnutls.c
index 8f8611c..0998cca 100644
--- a/contrib/wpa/src/crypto/crypto_gnutls.c
+++ b/contrib/wpa/src/crypto/crypto_gnutls.c
@@ -18,20 +18,21 @@
#include "common.h"
#include "crypto.h"
-void md4_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
+int md4_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
{
gcry_md_hd_t hd;
unsigned char *p;
size_t i;
if (gcry_md_open(&hd, GCRY_MD_MD4, 0) != GPG_ERR_NO_ERROR)
- return;
+ return -1;
for (i = 0; i < num_elem; i++)
gcry_md_write(hd, addr[i], len[i]);
p = gcry_md_read(hd, GCRY_MD_MD4);
if (p)
memcpy(mac, p, gcry_md_get_algo_dlen(GCRY_MD_MD4));
gcry_md_close(hd);
+ return 0;
}
@@ -57,49 +58,42 @@ void des_encrypt(const u8 *clear, const u8 *key, u8 *cypher)
}
-void md5_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
+int md5_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
{
gcry_md_hd_t hd;
unsigned char *p;
size_t i;
if (gcry_md_open(&hd, GCRY_MD_MD5, 0) != GPG_ERR_NO_ERROR)
- return;
+ return -1;
for (i = 0; i < num_elem; i++)
gcry_md_write(hd, addr[i], len[i]);
p = gcry_md_read(hd, GCRY_MD_MD5);
if (p)
memcpy(mac, p, gcry_md_get_algo_dlen(GCRY_MD_MD5));
gcry_md_close(hd);
+ return 0;
}
-void sha1_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
+int sha1_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
{
gcry_md_hd_t hd;
unsigned char *p;
size_t i;
if (gcry_md_open(&hd, GCRY_MD_SHA1, 0) != GPG_ERR_NO_ERROR)
- return;
+ return -1;
for (i = 0; i < num_elem; i++)
gcry_md_write(hd, addr[i], len[i]);
p = gcry_md_read(hd, GCRY_MD_SHA1);
if (p)
memcpy(mac, p, gcry_md_get_algo_dlen(GCRY_MD_SHA1));
gcry_md_close(hd);
+ return 0;
}
-#ifndef CONFIG_NO_FIPS186_2_PRF
-int fips186_2_prf(const u8 *seed, size_t seed_len, u8 *x, size_t xlen)
-{
- /* FIX: how to do this with libgcrypt? */
- return -1;
-}
-#endif /* CONFIG_NO_FIPS186_2_PRF */
-
-
void * aes_encrypt_init(const u8 *key, size_t len)
{
gcry_cipher_hd_t hd;
diff --git a/contrib/wpa/src/crypto/crypto_internal-cipher.c b/contrib/wpa/src/crypto/crypto_internal-cipher.c
new file mode 100644
index 0000000..75134f0
--- /dev/null
+++ b/contrib/wpa/src/crypto/crypto_internal-cipher.c
@@ -0,0 +1,256 @@
+/*
+ * Crypto wrapper for internal crypto implementation - Cipher wrappers
+ * Copyright (c) 2006-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "crypto.h"
+#include "aes.h"
+#include "des_i.h"
+
+
+struct crypto_cipher {
+ enum crypto_cipher_alg alg;
+ union {
+ struct {
+ size_t used_bytes;
+ u8 key[16];
+ size_t keylen;
+ } rc4;
+ struct {
+ u8 cbc[32];
+ size_t block_size;
+ void *ctx_enc;
+ void *ctx_dec;
+ } aes;
+ struct {
+ struct des3_key_s key;
+ u8 cbc[8];
+ } des3;
+ struct {
+ u32 ek[32];
+ u32 dk[32];
+ u8 cbc[8];
+ } des;
+ } u;
+};
+
+
+struct crypto_cipher * crypto_cipher_init(enum crypto_cipher_alg alg,
+ const u8 *iv, const u8 *key,
+ size_t key_len)
+{
+ struct crypto_cipher *ctx;
+
+ ctx = os_zalloc(sizeof(*ctx));
+ if (ctx == NULL)
+ return NULL;
+
+ ctx->alg = alg;
+
+ switch (alg) {
+ case CRYPTO_CIPHER_ALG_RC4:
+ if (key_len > sizeof(ctx->u.rc4.key)) {
+ os_free(ctx);
+ return NULL;
+ }
+ ctx->u.rc4.keylen = key_len;
+ os_memcpy(ctx->u.rc4.key, key, key_len);
+ break;
+ case CRYPTO_CIPHER_ALG_AES:
+ if (key_len > sizeof(ctx->u.aes.cbc)) {
+ os_free(ctx);
+ return NULL;
+ }
+ ctx->u.aes.ctx_enc = aes_encrypt_init(key, key_len);
+ if (ctx->u.aes.ctx_enc == NULL) {
+ os_free(ctx);
+ return NULL;
+ }
+ ctx->u.aes.ctx_dec = aes_decrypt_init(key, key_len);
+ if (ctx->u.aes.ctx_dec == NULL) {
+ aes_encrypt_deinit(ctx->u.aes.ctx_enc);
+ os_free(ctx);
+ return NULL;
+ }
+ ctx->u.aes.block_size = key_len;
+ os_memcpy(ctx->u.aes.cbc, iv, ctx->u.aes.block_size);
+ break;
+ case CRYPTO_CIPHER_ALG_3DES:
+ if (key_len != 24) {
+ os_free(ctx);
+ return NULL;
+ }
+ des3_key_setup(key, &ctx->u.des3.key);
+ os_memcpy(ctx->u.des3.cbc, iv, 8);
+ break;
+ case CRYPTO_CIPHER_ALG_DES:
+ if (key_len != 8) {
+ os_free(ctx);
+ return NULL;
+ }
+ des_key_setup(key, ctx->u.des.ek, ctx->u.des.dk);
+ os_memcpy(ctx->u.des.cbc, iv, 8);
+ break;
+ default:
+ os_free(ctx);
+ return NULL;
+ }
+
+ return ctx;
+}
+
+
+int crypto_cipher_encrypt(struct crypto_cipher *ctx, const u8 *plain,
+ u8 *crypt, size_t len)
+{
+ size_t i, j, blocks;
+
+ switch (ctx->alg) {
+ case CRYPTO_CIPHER_ALG_RC4:
+ if (plain != crypt)
+ os_memcpy(crypt, plain, len);
+ rc4_skip(ctx->u.rc4.key, ctx->u.rc4.keylen,
+ ctx->u.rc4.used_bytes, crypt, len);
+ ctx->u.rc4.used_bytes += len;
+ break;
+ case CRYPTO_CIPHER_ALG_AES:
+ if (len % ctx->u.aes.block_size)
+ return -1;
+ blocks = len / ctx->u.aes.block_size;
+ for (i = 0; i < blocks; i++) {
+ for (j = 0; j < ctx->u.aes.block_size; j++)
+ ctx->u.aes.cbc[j] ^= plain[j];
+ aes_encrypt(ctx->u.aes.ctx_enc, ctx->u.aes.cbc,
+ ctx->u.aes.cbc);
+ os_memcpy(crypt, ctx->u.aes.cbc,
+ ctx->u.aes.block_size);
+ plain += ctx->u.aes.block_size;
+ crypt += ctx->u.aes.block_size;
+ }
+ break;
+ case CRYPTO_CIPHER_ALG_3DES:
+ if (len % 8)
+ return -1;
+ blocks = len / 8;
+ for (i = 0; i < blocks; i++) {
+ for (j = 0; j < 8; j++)
+ ctx->u.des3.cbc[j] ^= plain[j];
+ des3_encrypt(ctx->u.des3.cbc, &ctx->u.des3.key,
+ ctx->u.des3.cbc);
+ os_memcpy(crypt, ctx->u.des3.cbc, 8);
+ plain += 8;
+ crypt += 8;
+ }
+ break;
+ case CRYPTO_CIPHER_ALG_DES:
+ if (len % 8)
+ return -1;
+ blocks = len / 8;
+ for (i = 0; i < blocks; i++) {
+ for (j = 0; j < 8; j++)
+ ctx->u.des3.cbc[j] ^= plain[j];
+ des_block_encrypt(ctx->u.des.cbc, ctx->u.des.ek,
+ ctx->u.des.cbc);
+ os_memcpy(crypt, ctx->u.des.cbc, 8);
+ plain += 8;
+ crypt += 8;
+ }
+ break;
+ default:
+ return -1;
+ }
+
+ return 0;
+}
+
+
+int crypto_cipher_decrypt(struct crypto_cipher *ctx, const u8 *crypt,
+ u8 *plain, size_t len)
+{
+ size_t i, j, blocks;
+ u8 tmp[32];
+
+ switch (ctx->alg) {
+ case CRYPTO_CIPHER_ALG_RC4:
+ if (plain != crypt)
+ os_memcpy(plain, crypt, len);
+ rc4_skip(ctx->u.rc4.key, ctx->u.rc4.keylen,
+ ctx->u.rc4.used_bytes, plain, len);
+ ctx->u.rc4.used_bytes += len;
+ break;
+ case CRYPTO_CIPHER_ALG_AES:
+ if (len % ctx->u.aes.block_size)
+ return -1;
+ blocks = len / ctx->u.aes.block_size;
+ for (i = 0; i < blocks; i++) {
+ os_memcpy(tmp, crypt, ctx->u.aes.block_size);
+ aes_decrypt(ctx->u.aes.ctx_dec, crypt, plain);
+ for (j = 0; j < ctx->u.aes.block_size; j++)
+ plain[j] ^= ctx->u.aes.cbc[j];
+ os_memcpy(ctx->u.aes.cbc, tmp, ctx->u.aes.block_size);
+ plain += ctx->u.aes.block_size;
+ crypt += ctx->u.aes.block_size;
+ }
+ break;
+ case CRYPTO_CIPHER_ALG_3DES:
+ if (len % 8)
+ return -1;
+ blocks = len / 8;
+ for (i = 0; i < blocks; i++) {
+ os_memcpy(tmp, crypt, 8);
+ des3_decrypt(crypt, &ctx->u.des3.key, plain);
+ for (j = 0; j < 8; j++)
+ plain[j] ^= ctx->u.des3.cbc[j];
+ os_memcpy(ctx->u.des3.cbc, tmp, 8);
+ plain += 8;
+ crypt += 8;
+ }
+ break;
+ case CRYPTO_CIPHER_ALG_DES:
+ if (len % 8)
+ return -1;
+ blocks = len / 8;
+ for (i = 0; i < blocks; i++) {
+ os_memcpy(tmp, crypt, 8);
+ des_block_decrypt(crypt, ctx->u.des.dk, plain);
+ for (j = 0; j < 8; j++)
+ plain[j] ^= ctx->u.des.cbc[j];
+ os_memcpy(ctx->u.des.cbc, tmp, 8);
+ plain += 8;
+ crypt += 8;
+ }
+ break;
+ default:
+ return -1;
+ }
+
+ return 0;
+}
+
+
+void crypto_cipher_deinit(struct crypto_cipher *ctx)
+{
+ switch (ctx->alg) {
+ case CRYPTO_CIPHER_ALG_AES:
+ aes_encrypt_deinit(ctx->u.aes.ctx_enc);
+ aes_decrypt_deinit(ctx->u.aes.ctx_dec);
+ break;
+ case CRYPTO_CIPHER_ALG_3DES:
+ break;
+ default:
+ break;
+ }
+ os_free(ctx);
+}
diff --git a/contrib/wpa/src/crypto/crypto_internal-modexp.c b/contrib/wpa/src/crypto/crypto_internal-modexp.c
new file mode 100644
index 0000000..3124742
--- /dev/null
+++ b/contrib/wpa/src/crypto/crypto_internal-modexp.c
@@ -0,0 +1,55 @@
+/*
+ * Crypto wrapper for internal crypto implementation - modexp
+ * Copyright (c) 2006-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "tls/bignum.h"
+#include "crypto.h"
+
+
+int crypto_mod_exp(const u8 *base, size_t base_len,
+ const u8 *power, size_t power_len,
+ const u8 *modulus, size_t modulus_len,
+ u8 *result, size_t *result_len)
+{
+ struct bignum *bn_base, *bn_exp, *bn_modulus, *bn_result;
+ int ret = -1;
+
+ bn_base = bignum_init();
+ bn_exp = bignum_init();
+ bn_modulus = bignum_init();
+ bn_result = bignum_init();
+
+ if (bn_base == NULL || bn_exp == NULL || bn_modulus == NULL ||
+ bn_result == NULL)
+ goto error;
+
+ if (bignum_set_unsigned_bin(bn_base, base, base_len) < 0 ||
+ bignum_set_unsigned_bin(bn_exp, power, power_len) < 0 ||
+ bignum_set_unsigned_bin(bn_modulus, modulus, modulus_len) < 0)
+ goto error;
+
+ if (bignum_exptmod(bn_base, bn_exp, bn_modulus, bn_result) < 0)
+ goto error;
+
+ ret = bignum_get_unsigned_bin(bn_result, result, result_len);
+
+error:
+ bignum_deinit(bn_base);
+ bignum_deinit(bn_exp);
+ bignum_deinit(bn_modulus);
+ bignum_deinit(bn_result);
+ return ret;
+}
diff --git a/contrib/wpa/src/crypto/crypto_internal-rsa.c b/contrib/wpa/src/crypto/crypto_internal-rsa.c
new file mode 100644
index 0000000..205042c
--- /dev/null
+++ b/contrib/wpa/src/crypto/crypto_internal-rsa.c
@@ -0,0 +1,115 @@
+/*
+ * Crypto wrapper for internal crypto implementation - RSA parts
+ * Copyright (c) 2006-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "crypto.h"
+#include "tls/rsa.h"
+#include "tls/bignum.h"
+#include "tls/pkcs1.h"
+#include "tls/pkcs8.h"
+
+/* Dummy structures; these are just typecast to struct crypto_rsa_key */
+struct crypto_public_key;
+struct crypto_private_key;
+
+
+struct crypto_public_key * crypto_public_key_import(const u8 *key, size_t len)
+{
+ return (struct crypto_public_key *)
+ crypto_rsa_import_public_key(key, len);
+}
+
+
+struct crypto_private_key * crypto_private_key_import(const u8 *key,
+ size_t len,
+ const char *passwd)
+{
+ struct crypto_private_key *res;
+
+ /* First, check for possible PKCS #8 encoding */
+ res = pkcs8_key_import(key, len);
+ if (res)
+ return res;
+
+ if (passwd) {
+ /* Try to parse as encrypted PKCS #8 */
+ res = pkcs8_enc_key_import(key, len, passwd);
+ if (res)
+ return res;
+ }
+
+ /* Not PKCS#8, so try to import PKCS #1 encoded RSA private key */
+ wpa_printf(MSG_DEBUG, "Trying to parse PKCS #1 encoded RSA private "
+ "key");
+ return (struct crypto_private_key *)
+ crypto_rsa_import_private_key(key, len);
+}
+
+
+struct crypto_public_key * crypto_public_key_from_cert(const u8 *buf,
+ size_t len)
+{
+ /* No X.509 support in crypto_internal.c */
+ return NULL;
+}
+
+
+int crypto_public_key_encrypt_pkcs1_v15(struct crypto_public_key *key,
+ const u8 *in, size_t inlen,
+ u8 *out, size_t *outlen)
+{
+ return pkcs1_encrypt(2, (struct crypto_rsa_key *) key,
+ 0, in, inlen, out, outlen);
+}
+
+
+int crypto_private_key_decrypt_pkcs1_v15(struct crypto_private_key *key,
+ const u8 *in, size_t inlen,
+ u8 *out, size_t *outlen)
+{
+ return pkcs1_v15_private_key_decrypt((struct crypto_rsa_key *) key,
+ in, inlen, out, outlen);
+}
+
+
+int crypto_private_key_sign_pkcs1(struct crypto_private_key *key,
+ const u8 *in, size_t inlen,
+ u8 *out, size_t *outlen)
+{
+ return pkcs1_encrypt(1, (struct crypto_rsa_key *) key,
+ 1, in, inlen, out, outlen);
+}
+
+
+void crypto_public_key_free(struct crypto_public_key *key)
+{
+ crypto_rsa_free((struct crypto_rsa_key *) key);
+}
+
+
+void crypto_private_key_free(struct crypto_private_key *key)
+{
+ crypto_rsa_free((struct crypto_rsa_key *) key);
+}
+
+
+int crypto_public_key_decrypt_pkcs1(struct crypto_public_key *key,
+ const u8 *crypt, size_t crypt_len,
+ u8 *plain, size_t *plain_len)
+{
+ return pkcs1_decrypt_public_key((struct crypto_rsa_key *) key,
+ crypt, crypt_len, plain, plain_len);
+}
diff --git a/contrib/wpa/src/crypto/crypto_internal.c b/contrib/wpa/src/crypto/crypto_internal.c
index cddfb4d..8fdba65 100644
--- a/contrib/wpa/src/crypto/crypto_internal.c
+++ b/contrib/wpa/src/crypto/crypto_internal.c
@@ -1,6 +1,6 @@
/*
- * WPA Supplicant / Crypto wrapper for internal crypto implementation
- * Copyright (c) 2006-2007, Jouni Malinen <j@w1.fi>
+ * Crypto wrapper for internal crypto implementation
+ * Copyright (c) 2006-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -16,42 +16,8 @@
#include "common.h"
#include "crypto.h"
-#include "md5.h"
-#include "sha1.h"
-#include "rc4.h"
-#include "aes.h"
-#include "tls/rsa.h"
-#include "tls/bignum.h"
-#include "tls/asn1.h"
-
-
-#ifdef CONFIG_CRYPTO_INTERNAL
-
-#ifdef CONFIG_TLS_INTERNAL
-
-/* from des.c */
-struct des3_key_s {
- u32 ek[3][32];
- u32 dk[3][32];
-};
-
-void des3_key_setup(const u8 *key, struct des3_key_s *dkey);
-void des3_encrypt(const u8 *plain, const struct des3_key_s *key, u8 *crypt);
-void des3_decrypt(const u8 *crypt, const struct des3_key_s *key, u8 *plain);
-
-
-struct MD5Context {
- u32 buf[4];
- u32 bits[2];
- u8 in[64];
-};
-
-struct SHA1Context {
- u32 state[5];
- u32 count[2];
- unsigned char buffer[64];
-};
-
+#include "sha1_i.h"
+#include "md5_i.h"
struct crypto_hash {
enum crypto_hash_alg alg;
@@ -228,559 +194,6 @@ int crypto_hash_finish(struct crypto_hash *ctx, u8 *mac, size_t *len)
}
-struct crypto_cipher {
- enum crypto_cipher_alg alg;
- union {
- struct {
- size_t used_bytes;
- u8 key[16];
- size_t keylen;
- } rc4;
- struct {
- u8 cbc[32];
- size_t block_size;
- void *ctx_enc;
- void *ctx_dec;
- } aes;
- struct {
- struct des3_key_s key;
- u8 cbc[8];
- } des3;
- } u;
-};
-
-
-struct crypto_cipher * crypto_cipher_init(enum crypto_cipher_alg alg,
- const u8 *iv, const u8 *key,
- size_t key_len)
-{
- struct crypto_cipher *ctx;
-
- ctx = os_zalloc(sizeof(*ctx));
- if (ctx == NULL)
- return NULL;
-
- ctx->alg = alg;
-
- switch (alg) {
- case CRYPTO_CIPHER_ALG_RC4:
- if (key_len > sizeof(ctx->u.rc4.key)) {
- os_free(ctx);
- return NULL;
- }
- ctx->u.rc4.keylen = key_len;
- os_memcpy(ctx->u.rc4.key, key, key_len);
- break;
- case CRYPTO_CIPHER_ALG_AES:
- if (key_len > sizeof(ctx->u.aes.cbc)) {
- os_free(ctx);
- return NULL;
- }
- ctx->u.aes.ctx_enc = aes_encrypt_init(key, key_len);
- if (ctx->u.aes.ctx_enc == NULL) {
- os_free(ctx);
- return NULL;
- }
- ctx->u.aes.ctx_dec = aes_decrypt_init(key, key_len);
- if (ctx->u.aes.ctx_dec == NULL) {
- aes_encrypt_deinit(ctx->u.aes.ctx_enc);
- os_free(ctx);
- return NULL;
- }
- ctx->u.aes.block_size = key_len;
- os_memcpy(ctx->u.aes.cbc, iv, ctx->u.aes.block_size);
- break;
- case CRYPTO_CIPHER_ALG_3DES:
- if (key_len != 24) {
- os_free(ctx);
- return NULL;
- }
- des3_key_setup(key, &ctx->u.des3.key);
- os_memcpy(ctx->u.des3.cbc, iv, 8);
- break;
- default:
- os_free(ctx);
- return NULL;
- }
-
- return ctx;
-}
-
-
-int crypto_cipher_encrypt(struct crypto_cipher *ctx, const u8 *plain,
- u8 *crypt, size_t len)
-{
- size_t i, j, blocks;
-
- switch (ctx->alg) {
- case CRYPTO_CIPHER_ALG_RC4:
- if (plain != crypt)
- os_memcpy(crypt, plain, len);
- rc4_skip(ctx->u.rc4.key, ctx->u.rc4.keylen,
- ctx->u.rc4.used_bytes, crypt, len);
- ctx->u.rc4.used_bytes += len;
- break;
- case CRYPTO_CIPHER_ALG_AES:
- if (len % ctx->u.aes.block_size)
- return -1;
- blocks = len / ctx->u.aes.block_size;
- for (i = 0; i < blocks; i++) {
- for (j = 0; j < ctx->u.aes.block_size; j++)
- ctx->u.aes.cbc[j] ^= plain[j];
- aes_encrypt(ctx->u.aes.ctx_enc, ctx->u.aes.cbc,
- ctx->u.aes.cbc);
- os_memcpy(crypt, ctx->u.aes.cbc,
- ctx->u.aes.block_size);
- plain += ctx->u.aes.block_size;
- crypt += ctx->u.aes.block_size;
- }
- break;
- case CRYPTO_CIPHER_ALG_3DES:
- if (len % 8)
- return -1;
- blocks = len / 8;
- for (i = 0; i < blocks; i++) {
- for (j = 0; j < 8; j++)
- ctx->u.des3.cbc[j] ^= plain[j];
- des3_encrypt(ctx->u.des3.cbc, &ctx->u.des3.key,
- ctx->u.des3.cbc);
- os_memcpy(crypt, ctx->u.des3.cbc, 8);
- plain += 8;
- crypt += 8;
- }
- break;
- default:
- return -1;
- }
-
- return 0;
-}
-
-
-int crypto_cipher_decrypt(struct crypto_cipher *ctx, const u8 *crypt,
- u8 *plain, size_t len)
-{
- size_t i, j, blocks;
- u8 tmp[32];
-
- switch (ctx->alg) {
- case CRYPTO_CIPHER_ALG_RC4:
- if (plain != crypt)
- os_memcpy(plain, crypt, len);
- rc4_skip(ctx->u.rc4.key, ctx->u.rc4.keylen,
- ctx->u.rc4.used_bytes, plain, len);
- ctx->u.rc4.used_bytes += len;
- break;
- case CRYPTO_CIPHER_ALG_AES:
- if (len % ctx->u.aes.block_size)
- return -1;
- blocks = len / ctx->u.aes.block_size;
- for (i = 0; i < blocks; i++) {
- os_memcpy(tmp, crypt, ctx->u.aes.block_size);
- aes_decrypt(ctx->u.aes.ctx_dec, crypt, plain);
- for (j = 0; j < ctx->u.aes.block_size; j++)
- plain[j] ^= ctx->u.aes.cbc[j];
- os_memcpy(ctx->u.aes.cbc, tmp, ctx->u.aes.block_size);
- plain += ctx->u.aes.block_size;
- crypt += ctx->u.aes.block_size;
- }
- break;
- case CRYPTO_CIPHER_ALG_3DES:
- if (len % 8)
- return -1;
- blocks = len / 8;
- for (i = 0; i < blocks; i++) {
- os_memcpy(tmp, crypt, 8);
- des3_decrypt(crypt, &ctx->u.des3.key, plain);
- for (j = 0; j < 8; j++)
- plain[j] ^= ctx->u.des3.cbc[j];
- os_memcpy(ctx->u.des3.cbc, tmp, 8);
- plain += 8;
- crypt += 8;
- }
- break;
- default:
- return -1;
- }
-
- return 0;
-}
-
-
-void crypto_cipher_deinit(struct crypto_cipher *ctx)
-{
- switch (ctx->alg) {
- case CRYPTO_CIPHER_ALG_AES:
- aes_encrypt_deinit(ctx->u.aes.ctx_enc);
- aes_decrypt_deinit(ctx->u.aes.ctx_dec);
- break;
- case CRYPTO_CIPHER_ALG_3DES:
- break;
- default:
- break;
- }
- os_free(ctx);
-}
-
-
-/* Dummy structures; these are just typecast to struct crypto_rsa_key */
-struct crypto_public_key;
-struct crypto_private_key;
-
-
-struct crypto_public_key * crypto_public_key_import(const u8 *key, size_t len)
-{
- return (struct crypto_public_key *)
- crypto_rsa_import_public_key(key, len);
-}
-
-
-#ifdef EAP_TLS_FUNCS
-static struct crypto_private_key *
-crypto_pkcs8_key_import(const u8 *buf, size_t len)
-{
- struct asn1_hdr hdr;
- const u8 *pos, *end;
- struct bignum *zero;
- struct asn1_oid oid;
- char obuf[80];
-
- /* PKCS #8, Chapter 6 */
-
- /* PrivateKeyInfo ::= SEQUENCE */
- if (asn1_get_next(buf, len, &hdr) < 0 ||
- hdr.class != ASN1_CLASS_UNIVERSAL ||
- hdr.tag != ASN1_TAG_SEQUENCE) {
- wpa_printf(MSG_DEBUG, "PKCS #8: Does not start with PKCS #8 "
- "header (SEQUENCE); assume PKCS #8 not used");
- return NULL;
- }
- pos = hdr.payload;
- end = pos + hdr.length;
-
- /* version Version (Version ::= INTEGER) */
- if (asn1_get_next(pos, end - pos, &hdr) < 0 ||
- hdr.class != ASN1_CLASS_UNIVERSAL || hdr.tag != ASN1_TAG_INTEGER) {
- wpa_printf(MSG_DEBUG, "PKCS #8: Expected INTEGER - found "
- "class %d tag 0x%x; assume PKCS #8 not used",
- hdr.class, hdr.tag);
- return NULL;
- }
-
- zero = bignum_init();
- if (zero == NULL)
- return NULL;
-
- if (bignum_set_unsigned_bin(zero, hdr.payload, hdr.length) < 0) {
- wpa_printf(MSG_DEBUG, "PKCS #8: Failed to parse INTEGER");
- bignum_deinit(zero);
- return NULL;
- }
- pos = hdr.payload + hdr.length;
-
- if (bignum_cmp_d(zero, 0) != 0) {
- wpa_printf(MSG_DEBUG, "PKCS #8: Expected zero INTEGER in the "
- "beginning of private key; not found; assume "
- "PKCS #8 not used");
- bignum_deinit(zero);
- return NULL;
- }
- bignum_deinit(zero);
-
- /* privateKeyAlgorithm PrivateKeyAlgorithmIdentifier
- * (PrivateKeyAlgorithmIdentifier ::= AlgorithmIdentifier) */
- if (asn1_get_next(pos, len, &hdr) < 0 ||
- hdr.class != ASN1_CLASS_UNIVERSAL ||
- hdr.tag != ASN1_TAG_SEQUENCE) {
- wpa_printf(MSG_DEBUG, "PKCS #8: Expected SEQUENCE "
- "(AlgorithmIdentifier) - found class %d tag 0x%x; "
- "assume PKCS #8 not used",
- hdr.class, hdr.tag);
- return NULL;
- }
-
- if (asn1_get_oid(hdr.payload, hdr.length, &oid, &pos)) {
- wpa_printf(MSG_DEBUG, "PKCS #8: Failed to parse OID "
- "(algorithm); assume PKCS #8 not used");
- return NULL;
- }
-
- asn1_oid_to_str(&oid, obuf, sizeof(obuf));
- wpa_printf(MSG_DEBUG, "PKCS #8: algorithm=%s", obuf);
-
- if (oid.len != 7 ||
- oid.oid[0] != 1 /* iso */ ||
- oid.oid[1] != 2 /* member-body */ ||
- oid.oid[2] != 840 /* us */ ||
- oid.oid[3] != 113549 /* rsadsi */ ||
- oid.oid[4] != 1 /* pkcs */ ||
- oid.oid[5] != 1 /* pkcs-1 */ ||
- oid.oid[6] != 1 /* rsaEncryption */) {
- wpa_printf(MSG_DEBUG, "PKCS #8: Unsupported private key "
- "algorithm %s", obuf);
- return NULL;
- }
-
- pos = hdr.payload + hdr.length;
-
- /* privateKey PrivateKey (PrivateKey ::= OCTET STRING) */
- if (asn1_get_next(pos, end - pos, &hdr) < 0 ||
- hdr.class != ASN1_CLASS_UNIVERSAL ||
- hdr.tag != ASN1_TAG_OCTETSTRING) {
- wpa_printf(MSG_DEBUG, "PKCS #8: Expected OCTETSTRING "
- "(privateKey) - found class %d tag 0x%x",
- hdr.class, hdr.tag);
- return NULL;
- }
- wpa_printf(MSG_DEBUG, "PKCS #8: Try to parse RSAPrivateKey");
-
- return (struct crypto_private_key *)
- crypto_rsa_import_private_key(hdr.payload, hdr.length);
-}
-#endif /* EAP_TLS_FUNCS */
-
-
-struct crypto_private_key * crypto_private_key_import(const u8 *key,
- size_t len)
-{
- struct crypto_private_key *res;
-
- /* First, check for possible PKCS #8 encoding */
- res = crypto_pkcs8_key_import(key, len);
- if (res)
- return res;
-
- /* Not PKCS#8, so try to import PKCS #1 encoded RSA private key */
- wpa_printf(MSG_DEBUG, "Trying to parse PKCS #1 encoded RSA private "
- "key");
- return (struct crypto_private_key *)
- crypto_rsa_import_private_key(key, len);
-}
-
-
-struct crypto_public_key * crypto_public_key_from_cert(const u8 *buf,
- size_t len)
-{
- /* No X.509 support in crypto_internal.c */
- return NULL;
-}
-
-
-static int pkcs1_generate_encryption_block(u8 block_type, size_t modlen,
- const u8 *in, size_t inlen,
- u8 *out, size_t *outlen)
-{
- size_t ps_len;
- u8 *pos;
-
- /*
- * PKCS #1 v1.5, 8.1:
- *
- * EB = 00 || BT || PS || 00 || D
- * BT = 00 or 01 for private-key operation; 02 for public-key operation
- * PS = k-3-||D||; at least eight octets
- * (BT=0: PS=0x00, BT=1: PS=0xff, BT=2: PS=pseudorandom non-zero)
- * k = length of modulus in octets (modlen)
- */
-
- if (modlen < 12 || modlen > *outlen || inlen > modlen - 11) {
- wpa_printf(MSG_DEBUG, "PKCS #1: %s - Invalid buffer "
- "lengths (modlen=%lu outlen=%lu inlen=%lu)",
- __func__, (unsigned long) modlen,
- (unsigned long) *outlen,
- (unsigned long) inlen);
- return -1;
- }
-
- pos = out;
- *pos++ = 0x00;
- *pos++ = block_type; /* BT */
- ps_len = modlen - inlen - 3;
- switch (block_type) {
- case 0:
- os_memset(pos, 0x00, ps_len);
- pos += ps_len;
- break;
- case 1:
- os_memset(pos, 0xff, ps_len);
- pos += ps_len;
- break;
- case 2:
- if (os_get_random(pos, ps_len) < 0) {
- wpa_printf(MSG_DEBUG, "PKCS #1: %s - Failed to get "
- "random data for PS", __func__);
- return -1;
- }
- while (ps_len--) {
- if (*pos == 0x00)
- *pos = 0x01;
- pos++;
- }
- break;
- default:
- wpa_printf(MSG_DEBUG, "PKCS #1: %s - Unsupported block type "
- "%d", __func__, block_type);
- return -1;
- }
- *pos++ = 0x00;
- os_memcpy(pos, in, inlen); /* D */
-
- return 0;
-}
-
-
-static int crypto_rsa_encrypt_pkcs1(int block_type, struct crypto_rsa_key *key,
- int use_private,
- const u8 *in, size_t inlen,
- u8 *out, size_t *outlen)
-{
- size_t modlen;
-
- modlen = crypto_rsa_get_modulus_len(key);
-
- if (pkcs1_generate_encryption_block(block_type, modlen, in, inlen,
- out, outlen) < 0)
- return -1;
-
- return crypto_rsa_exptmod(out, modlen, out, outlen, key, use_private);
-}
-
-
-int crypto_public_key_encrypt_pkcs1_v15(struct crypto_public_key *key,
- const u8 *in, size_t inlen,
- u8 *out, size_t *outlen)
-{
- return crypto_rsa_encrypt_pkcs1(2, (struct crypto_rsa_key *) key,
- 0, in, inlen, out, outlen);
-}
-
-
-int crypto_private_key_decrypt_pkcs1_v15(struct crypto_private_key *key,
- const u8 *in, size_t inlen,
- u8 *out, size_t *outlen)
-{
- struct crypto_rsa_key *rkey = (struct crypto_rsa_key *) key;
- int res;
- u8 *pos, *end;
-
- res = crypto_rsa_exptmod(in, inlen, out, outlen, rkey, 1);
- if (res)
- return res;
-
- if (*outlen < 2 || out[0] != 0 || out[1] != 2)
- return -1;
-
- /* Skip PS (pseudorandom non-zero octets) */
- pos = out + 2;
- end = out + *outlen;
- while (*pos && pos < end)
- pos++;
- if (pos == end)
- return -1;
- pos++;
-
- *outlen -= pos - out;
-
- /* Strip PKCS #1 header */
- os_memmove(out, pos, *outlen);
-
- return 0;
-}
-
-
-int crypto_private_key_sign_pkcs1(struct crypto_private_key *key,
- const u8 *in, size_t inlen,
- u8 *out, size_t *outlen)
-{
- return crypto_rsa_encrypt_pkcs1(1, (struct crypto_rsa_key *) key,
- 1, in, inlen, out, outlen);
-}
-
-
-void crypto_public_key_free(struct crypto_public_key *key)
-{
- crypto_rsa_free((struct crypto_rsa_key *) key);
-}
-
-
-void crypto_private_key_free(struct crypto_private_key *key)
-{
- crypto_rsa_free((struct crypto_rsa_key *) key);
-}
-
-
-int crypto_public_key_decrypt_pkcs1(struct crypto_public_key *key,
- const u8 *crypt, size_t crypt_len,
- u8 *plain, size_t *plain_len)
-{
- size_t len;
- u8 *pos;
-
- len = *plain_len;
- if (crypto_rsa_exptmod(crypt, crypt_len, plain, &len,
- (struct crypto_rsa_key *) key, 0) < 0)
- return -1;
-
- /*
- * PKCS #1 v1.5, 8.1:
- *
- * EB = 00 || BT || PS || 00 || D
- * BT = 00 or 01
- * PS = k-3-||D|| times (00 if BT=00) or (FF if BT=01)
- * k = length of modulus in octets
- */
-
- if (len < 3 + 8 + 16 /* min hash len */ ||
- plain[0] != 0x00 || (plain[1] != 0x00 && plain[1] != 0x01)) {
- wpa_printf(MSG_INFO, "LibTomCrypt: Invalid signature EB "
- "structure");
- return -1;
- }
-
- pos = plain + 3;
- if (plain[1] == 0x00) {
- /* BT = 00 */
- if (plain[2] != 0x00) {
- wpa_printf(MSG_INFO, "LibTomCrypt: Invalid signature "
- "PS (BT=00)");
- return -1;
- }
- while (pos + 1 < plain + len && *pos == 0x00 && pos[1] == 0x00)
- pos++;
- } else {
- /* BT = 01 */
- if (plain[2] != 0xff) {
- wpa_printf(MSG_INFO, "LibTomCrypt: Invalid signature "
- "PS (BT=01)");
- return -1;
- }
- while (pos < plain + len && *pos == 0xff)
- pos++;
- }
-
- if (pos - plain - 2 < 8) {
- /* PKCS #1 v1.5, 8.1: At least eight octets long PS */
- wpa_printf(MSG_INFO, "LibTomCrypt: Too short signature "
- "padding");
- return -1;
- }
-
- if (pos + 16 /* min hash len */ >= plain + len || *pos != 0x00) {
- wpa_printf(MSG_INFO, "LibTomCrypt: Invalid signature EB "
- "structure (2)");
- return -1;
- }
- pos++;
- len -= pos - plain;
-
- /* Strip PKCS #1 header */
- os_memmove(plain, pos, len);
- *plain_len = len;
-
- return 0;
-}
-
-
int crypto_global_init(void)
{
return 0;
@@ -790,47 +203,3 @@ int crypto_global_init(void)
void crypto_global_deinit(void)
{
}
-#endif /* CONFIG_TLS_INTERNAL */
-
-
-#if defined(EAP_FAST) || defined(CONFIG_WPS)
-
-int crypto_mod_exp(const u8 *base, size_t base_len,
- const u8 *power, size_t power_len,
- const u8 *modulus, size_t modulus_len,
- u8 *result, size_t *result_len)
-{
- struct bignum *bn_base, *bn_exp, *bn_modulus, *bn_result;
- int ret = -1;
-
- bn_base = bignum_init();
- bn_exp = bignum_init();
- bn_modulus = bignum_init();
- bn_result = bignum_init();
-
- if (bn_base == NULL || bn_exp == NULL || bn_modulus == NULL ||
- bn_result == NULL)
- goto error;
-
- if (bignum_set_unsigned_bin(bn_base, base, base_len) < 0 ||
- bignum_set_unsigned_bin(bn_exp, power, power_len) < 0 ||
- bignum_set_unsigned_bin(bn_modulus, modulus, modulus_len) < 0)
- goto error;
-
- if (bignum_exptmod(bn_base, bn_exp, bn_modulus, bn_result) < 0)
- goto error;
-
- ret = bignum_get_unsigned_bin(bn_result, result, result_len);
-
-error:
- bignum_deinit(bn_base);
- bignum_deinit(bn_exp);
- bignum_deinit(bn_modulus);
- bignum_deinit(bn_result);
- return ret;
-}
-
-#endif /* EAP_FAST || CONFIG_WPS */
-
-
-#endif /* CONFIG_CRYPTO_INTERNAL */
diff --git a/contrib/wpa/src/crypto/crypto_libtomcrypt.c b/contrib/wpa/src/crypto/crypto_libtomcrypt.c
index e82097f..52b67a7 100644
--- a/contrib/wpa/src/crypto/crypto_libtomcrypt.c
+++ b/contrib/wpa/src/crypto/crypto_libtomcrypt.c
@@ -16,7 +16,6 @@
#include <tomcrypt.h>
#include "common.h"
-#include "rc4.h"
#include "crypto.h"
#ifndef mp_init_multi
@@ -29,7 +28,7 @@
#endif
-void md4_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
+int md4_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
{
hash_state md;
size_t i;
@@ -38,6 +37,7 @@ void md4_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
for (i = 0; i < num_elem; i++)
md4_process(&md, addr[i], len[i]);
md4_done(&md, mac);
+ return 0;
}
@@ -62,8 +62,7 @@ void des_encrypt(const u8 *clear, const u8 *key, u8 *cypher)
}
-#ifdef EAP_TLS_FUNCS
-void md5_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
+int md5_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
{
hash_state md;
size_t i;
@@ -72,10 +71,11 @@ void md5_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
for (i = 0; i < num_elem; i++)
md5_process(&md, addr[i], len[i]);
md5_done(&md, mac);
+ return 0;
}
-void sha1_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
+int sha1_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
{
hash_state md;
size_t i;
@@ -84,6 +84,7 @@ void sha1_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
for (i = 0; i < num_elem; i++)
sha1_process(&md, addr[i], len[i]);
sha1_done(&md, mac);
+ return 0;
}
@@ -145,8 +146,6 @@ void aes_decrypt_deinit(void *ctx)
}
-#ifdef CONFIG_TLS_INTERNAL
-
struct crypto_hash {
enum crypto_hash_alg alg;
int error;
@@ -451,7 +450,8 @@ struct crypto_public_key * crypto_public_key_import(const u8 *key, size_t len)
struct crypto_private_key * crypto_private_key_import(const u8 *key,
- size_t len)
+ size_t len,
+ const char *passwd)
{
int res;
struct crypto_private_key *pk;
@@ -697,7 +697,7 @@ void crypto_global_deinit(void)
}
-#ifdef EAP_FAST
+#ifdef CONFIG_MODEXP
int crypto_mod_exp(const u8 *base, size_t base_len,
const u8 *power, size_t power_len,
@@ -729,8 +729,4 @@ fail:
return -1;
}
-#endif /* EAP_FAST */
-
-#endif /* CONFIG_TLS_INTERNAL */
-
-#endif /* EAP_TLS_FUNCS */
+#endif /* CONFIG_MODEXP */
diff --git a/contrib/wpa/src/crypto/crypto_none.c b/contrib/wpa/src/crypto/crypto_none.c
index f18c2a8..9f43775 100644
--- a/contrib/wpa/src/crypto/crypto_none.c
+++ b/contrib/wpa/src/crypto/crypto_none.c
@@ -18,8 +18,9 @@
#include "crypto.h"
-void md4_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
+int md4_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
{
+ return 0;
}
diff --git a/contrib/wpa/src/crypto/crypto_nss.c b/contrib/wpa/src/crypto/crypto_nss.c
new file mode 100644
index 0000000..fee4195
--- /dev/null
+++ b/contrib/wpa/src/crypto/crypto_nss.c
@@ -0,0 +1,213 @@
+/*
+ * Crypto wrapper functions for NSS
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+#include <nspr/prtypes.h>
+#include <nspr/plarenas.h>
+#include <nspr/plhash.h>
+#include <nspr/prtime.h>
+#include <nspr/prinrval.h>
+#include <nspr/prclist.h>
+#include <nspr/prlock.h>
+#include <nss/sechash.h>
+#include <nss/pk11pub.h>
+
+#include "common.h"
+#include "crypto.h"
+
+
+static int nss_hash(HASH_HashType type, unsigned int max_res_len,
+ size_t num_elem, const u8 *addr[], const size_t *len,
+ u8 *mac)
+{
+ HASHContext *ctx;
+ size_t i;
+ unsigned int reslen;
+
+ ctx = HASH_Create(type);
+ if (ctx == NULL)
+ return -1;
+
+ HASH_Begin(ctx);
+ for (i = 0; i < num_elem; i++)
+ HASH_Update(ctx, addr[i], len[i]);
+ HASH_End(ctx, mac, &reslen, max_res_len);
+ HASH_Destroy(ctx);
+
+ return 0;
+}
+
+
+void des_encrypt(const u8 *clear, const u8 *key, u8 *cypher)
+{
+ PK11Context *ctx = NULL;
+ PK11SlotInfo *slot;
+ SECItem *param = NULL;
+ PK11SymKey *symkey = NULL;
+ SECItem item;
+ int olen;
+ u8 pkey[8], next, tmp;
+ int i;
+
+ /* Add parity bits to the key */
+ next = 0;
+ for (i = 0; i < 7; i++) {
+ tmp = key[i];
+ pkey[i] = (tmp >> i) | next | 1;
+ next = tmp << (7 - i);
+ }
+ pkey[i] = next | 1;
+
+ slot = PK11_GetBestSlot(CKM_DES_ECB, NULL);
+ if (slot == NULL) {
+ wpa_printf(MSG_ERROR, "NSS: PK11_GetBestSlot failed");
+ goto out;
+ }
+
+ item.type = siBuffer;
+ item.data = pkey;
+ item.len = 8;
+ symkey = PK11_ImportSymKey(slot, CKM_DES_ECB, PK11_OriginDerive,
+ CKA_ENCRYPT, &item, NULL);
+ if (symkey == NULL) {
+ wpa_printf(MSG_ERROR, "NSS: PK11_ImportSymKey failed");
+ goto out;
+ }
+
+ param = PK11_GenerateNewParam(CKM_DES_ECB, symkey);
+ if (param == NULL) {
+ wpa_printf(MSG_ERROR, "NSS: PK11_GenerateNewParam failed");
+ goto out;
+ }
+
+ ctx = PK11_CreateContextBySymKey(CKM_DES_ECB, CKA_ENCRYPT,
+ symkey, param);
+ if (ctx == NULL) {
+ wpa_printf(MSG_ERROR, "NSS: PK11_CreateContextBySymKey("
+ "CKM_DES_ECB) failed");
+ goto out;
+ }
+
+ if (PK11_CipherOp(ctx, cypher, &olen, 8, (void *) clear, 8) !=
+ SECSuccess) {
+ wpa_printf(MSG_ERROR, "NSS: PK11_CipherOp failed");
+ goto out;
+ }
+
+out:
+ if (ctx)
+ PK11_DestroyContext(ctx, PR_TRUE);
+ if (symkey)
+ PK11_FreeSymKey(symkey);
+ if (param)
+ SECITEM_FreeItem(param, PR_TRUE);
+}
+
+
+int rc4_skip(const u8 *key, size_t keylen, size_t skip,
+ u8 *data, size_t data_len)
+{
+ return -1;
+}
+
+
+int md5_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
+{
+ return nss_hash(HASH_AlgMD5, 16, num_elem, addr, len, mac);
+}
+
+
+int sha1_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
+{
+ return nss_hash(HASH_AlgSHA1, 20, num_elem, addr, len, mac);
+}
+
+
+int sha256_vector(size_t num_elem, const u8 *addr[], const size_t *len,
+ u8 *mac)
+{
+ return nss_hash(HASH_AlgSHA256, 32, num_elem, addr, len, mac);
+}
+
+
+void * aes_encrypt_init(const u8 *key, size_t len)
+{
+ return NULL;
+}
+
+
+void aes_encrypt(void *ctx, const u8 *plain, u8 *crypt)
+{
+}
+
+
+void aes_encrypt_deinit(void *ctx)
+{
+}
+
+
+void * aes_decrypt_init(const u8 *key, size_t len)
+{
+ return NULL;
+}
+
+
+void aes_decrypt(void *ctx, const u8 *crypt, u8 *plain)
+{
+}
+
+
+void aes_decrypt_deinit(void *ctx)
+{
+}
+
+
+int crypto_mod_exp(const u8 *base, size_t base_len,
+ const u8 *power, size_t power_len,
+ const u8 *modulus, size_t modulus_len,
+ u8 *result, size_t *result_len)
+{
+ return -1;
+}
+
+
+struct crypto_cipher {
+};
+
+
+struct crypto_cipher * crypto_cipher_init(enum crypto_cipher_alg alg,
+ const u8 *iv, const u8 *key,
+ size_t key_len)
+{
+ return NULL;
+}
+
+
+int crypto_cipher_encrypt(struct crypto_cipher *ctx, const u8 *plain,
+ u8 *crypt, size_t len)
+{
+ return -1;
+}
+
+
+int crypto_cipher_decrypt(struct crypto_cipher *ctx, const u8 *crypt,
+ u8 *plain, size_t len)
+{
+ return -1;
+}
+
+
+void crypto_cipher_deinit(struct crypto_cipher *ctx)
+{
+}
diff --git a/contrib/wpa/src/crypto/crypto_openssl.c b/contrib/wpa/src/crypto/crypto_openssl.c
index a4c3415..08c98af 100644
--- a/contrib/wpa/src/crypto/crypto_openssl.c
+++ b/contrib/wpa/src/crypto/crypto_openssl.c
@@ -1,6 +1,6 @@
/*
* WPA Supplicant / wrapper functions for libcrypto
- * Copyright (c) 2004-2005, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -14,15 +14,16 @@
#include "includes.h"
#include <openssl/opensslv.h>
-#include <openssl/md4.h>
-#include <openssl/md5.h>
-#include <openssl/sha.h>
+#include <openssl/err.h>
#include <openssl/des.h>
#include <openssl/aes.h>
#include <openssl/bn.h>
#include <openssl/evp.h>
+#include <openssl/dh.h>
#include "common.h"
+#include "wpabuf.h"
+#include "dh_group5.h"
#include "crypto.h"
#if OPENSSL_VERSION_NUMBER < 0x00907000
@@ -33,16 +34,87 @@
des_ecb_encrypt((input), (output), *(ks), (enc))
#endif /* openssl < 0.9.7 */
+static BIGNUM * get_group5_prime(void)
+{
+#if OPENSSL_VERSION_NUMBER < 0x00908000
+ static const unsigned char RFC3526_PRIME_1536[] = {
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC9,0x0F,0xDA,0xA2,
+ 0x21,0x68,0xC2,0x34,0xC4,0xC6,0x62,0x8B,0x80,0xDC,0x1C,0xD1,
+ 0x29,0x02,0x4E,0x08,0x8A,0x67,0xCC,0x74,0x02,0x0B,0xBE,0xA6,
+ 0x3B,0x13,0x9B,0x22,0x51,0x4A,0x08,0x79,0x8E,0x34,0x04,0xDD,
+ 0xEF,0x95,0x19,0xB3,0xCD,0x3A,0x43,0x1B,0x30,0x2B,0x0A,0x6D,
+ 0xF2,0x5F,0x14,0x37,0x4F,0xE1,0x35,0x6D,0x6D,0x51,0xC2,0x45,
+ 0xE4,0x85,0xB5,0x76,0x62,0x5E,0x7E,0xC6,0xF4,0x4C,0x42,0xE9,
+ 0xA6,0x37,0xED,0x6B,0x0B,0xFF,0x5C,0xB6,0xF4,0x06,0xB7,0xED,
+ 0xEE,0x38,0x6B,0xFB,0x5A,0x89,0x9F,0xA5,0xAE,0x9F,0x24,0x11,
+ 0x7C,0x4B,0x1F,0xE6,0x49,0x28,0x66,0x51,0xEC,0xE4,0x5B,0x3D,
+ 0xC2,0x00,0x7C,0xB8,0xA1,0x63,0xBF,0x05,0x98,0xDA,0x48,0x36,
+ 0x1C,0x55,0xD3,0x9A,0x69,0x16,0x3F,0xA8,0xFD,0x24,0xCF,0x5F,
+ 0x83,0x65,0x5D,0x23,0xDC,0xA3,0xAD,0x96,0x1C,0x62,0xF3,0x56,
+ 0x20,0x85,0x52,0xBB,0x9E,0xD5,0x29,0x07,0x70,0x96,0x96,0x6D,
+ 0x67,0x0C,0x35,0x4E,0x4A,0xBC,0x98,0x04,0xF1,0x74,0x6C,0x08,
+ 0xCA,0x23,0x73,0x27,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ };
+ return BN_bin2bn(RFC3526_PRIME_1536, sizeof(RFC3526_PRIME_1536), NULL);
+#else /* openssl < 0.9.8 */
+ return get_rfc3526_prime_1536(NULL);
+#endif /* openssl < 0.9.8 */
+}
+
+#if OPENSSL_VERSION_NUMBER < 0x00908000
+#ifndef OPENSSL_NO_SHA256
+#ifndef OPENSSL_FIPS
+#define NO_SHA256_WRAPPER
+#endif
+#endif
+
+#endif /* openssl < 0.9.8 */
-void md4_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
+#ifdef OPENSSL_NO_SHA256
+#define NO_SHA256_WRAPPER
+#endif
+
+static int openssl_digest_vector(const EVP_MD *type, int non_fips,
+ size_t num_elem, const u8 *addr[],
+ const size_t *len, u8 *mac)
{
- MD4_CTX ctx;
+ EVP_MD_CTX ctx;
size_t i;
+ unsigned int mac_len;
+
+ EVP_MD_CTX_init(&ctx);
+#ifdef CONFIG_FIPS
+#ifdef OPENSSL_FIPS
+ if (non_fips)
+ EVP_MD_CTX_set_flags(&ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
+#endif /* OPENSSL_FIPS */
+#endif /* CONFIG_FIPS */
+ if (!EVP_DigestInit_ex(&ctx, type, NULL)) {
+ wpa_printf(MSG_ERROR, "OpenSSL: EVP_DigestInit_ex failed: %s",
+ ERR_error_string(ERR_get_error(), NULL));
+ return -1;
+ }
+ for (i = 0; i < num_elem; i++) {
+ if (!EVP_DigestUpdate(&ctx, addr[i], len[i])) {
+ wpa_printf(MSG_ERROR, "OpenSSL: EVP_DigestUpdate "
+ "failed: %s",
+ ERR_error_string(ERR_get_error(), NULL));
+ return -1;
+ }
+ }
+ if (!EVP_DigestFinal(&ctx, mac, &mac_len)) {
+ wpa_printf(MSG_ERROR, "OpenSSL: EVP_DigestFinal failed: %s",
+ ERR_error_string(ERR_get_error(), NULL));
+ return -1;
+ }
+
+ return 0;
+}
- MD4_Init(&ctx);
- for (i = 0; i < num_elem; i++)
- MD4_Update(&ctx, addr[i], len[i]);
- MD4_Final(mac, &ctx);
+
+int md4_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
+{
+ return openssl_digest_vector(EVP_md4(), 0, num_elem, addr, len, mac);
}
@@ -67,94 +139,72 @@ void des_encrypt(const u8 *clear, const u8 *key, u8 *cypher)
}
-void md5_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
+int rc4_skip(const u8 *key, size_t keylen, size_t skip,
+ u8 *data, size_t data_len)
{
- MD5_CTX ctx;
- size_t i;
+#ifdef OPENSSL_NO_RC4
+ return -1;
+#else /* OPENSSL_NO_RC4 */
+ EVP_CIPHER_CTX ctx;
+ int outl;
+ int res = -1;
+ unsigned char skip_buf[16];
+
+ EVP_CIPHER_CTX_init(&ctx);
+ if (!EVP_CIPHER_CTX_set_padding(&ctx, 0) ||
+ !EVP_CipherInit_ex(&ctx, EVP_rc4(), NULL, NULL, NULL, 1) ||
+ !EVP_CIPHER_CTX_set_key_length(&ctx, keylen) ||
+ !EVP_CipherInit_ex(&ctx, NULL, NULL, key, NULL, 1))
+ goto out;
+
+ while (skip >= sizeof(skip_buf)) {
+ size_t len = skip;
+ if (len > sizeof(skip_buf))
+ len = sizeof(skip_buf);
+ if (!EVP_CipherUpdate(&ctx, skip_buf, &outl, skip_buf, len))
+ goto out;
+ skip -= len;
+ }
+
+ if (EVP_CipherUpdate(&ctx, data, &outl, data, data_len))
+ res = 0;
- MD5_Init(&ctx);
- for (i = 0; i < num_elem; i++)
- MD5_Update(&ctx, addr[i], len[i]);
- MD5_Final(mac, &ctx);
+out:
+ EVP_CIPHER_CTX_cleanup(&ctx);
+ return res;
+#endif /* OPENSSL_NO_RC4 */
}
-void sha1_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
+int md5_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
{
- SHA_CTX ctx;
- size_t i;
-
- SHA1_Init(&ctx);
- for (i = 0; i < num_elem; i++)
- SHA1_Update(&ctx, addr[i], len[i]);
- SHA1_Final(mac, &ctx);
+ return openssl_digest_vector(EVP_md5(), 0, num_elem, addr, len, mac);
}
-#ifndef CONFIG_NO_FIPS186_2_PRF
-static void sha1_transform(u8 *state, const u8 data[64])
+#ifdef CONFIG_FIPS
+int md5_vector_non_fips_allow(size_t num_elem, const u8 *addr[],
+ const size_t *len, u8 *mac)
{
- SHA_CTX context;
- os_memset(&context, 0, sizeof(context));
- os_memcpy(&context.h0, state, 5 * 4);
- SHA1_Transform(&context, data);
- os_memcpy(state, &context.h0, 5 * 4);
+ return openssl_digest_vector(EVP_md5(), 1, num_elem, addr, len, mac);
}
+#endif /* CONFIG_FIPS */
-int fips186_2_prf(const u8 *seed, size_t seed_len, u8 *x, size_t xlen)
+int sha1_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
{
- u8 xkey[64];
- u32 t[5], _t[5];
- int i, j, m, k;
- u8 *xpos = x;
- u32 carry;
-
- if (seed_len > sizeof(xkey))
- seed_len = sizeof(xkey);
-
- /* FIPS 186-2 + change notice 1 */
-
- os_memcpy(xkey, seed, seed_len);
- os_memset(xkey + seed_len, 0, 64 - seed_len);
- t[0] = 0x67452301;
- t[1] = 0xEFCDAB89;
- t[2] = 0x98BADCFE;
- t[3] = 0x10325476;
- t[4] = 0xC3D2E1F0;
-
- m = xlen / 40;
- for (j = 0; j < m; j++) {
- /* XSEED_j = 0 */
- for (i = 0; i < 2; i++) {
- /* XVAL = (XKEY + XSEED_j) mod 2^b */
-
- /* w_i = G(t, XVAL) */
- os_memcpy(_t, t, 20);
- sha1_transform((u8 *) _t, xkey);
- _t[0] = host_to_be32(_t[0]);
- _t[1] = host_to_be32(_t[1]);
- _t[2] = host_to_be32(_t[2]);
- _t[3] = host_to_be32(_t[3]);
- _t[4] = host_to_be32(_t[4]);
- os_memcpy(xpos, _t, 20);
-
- /* XKEY = (1 + XKEY + w_i) mod 2^b */
- carry = 1;
- for (k = 19; k >= 0; k--) {
- carry += xkey[k] + xpos[k];
- xkey[k] = carry & 0xff;
- carry >>= 8;
- }
-
- xpos += 20;
- }
- /* x_j = w_0|w_1 */
- }
+ return openssl_digest_vector(EVP_sha1(), 0, num_elem, addr, len, mac);
+}
- return 0;
+
+#ifndef NO_SHA256_WRAPPER
+int sha256_vector(size_t num_elem, const u8 *addr[], const size_t *len,
+ u8 *mac)
+{
+ return openssl_digest_vector(EVP_sha256(), 0, num_elem, addr, len,
+ mac);
}
-#endif /* CONFIG_NO_FIPS186_2_PRF */
+#endif /* NO_SHA256_WRAPPER */
void * aes_encrypt_init(const u8 *key, size_t len)
@@ -310,7 +360,7 @@ struct crypto_cipher * crypto_cipher_init(enum crypto_cipher_alg alg,
EVP_CIPHER_CTX_set_padding(&ctx->enc, 0);
if (!EVP_EncryptInit_ex(&ctx->enc, cipher, NULL, NULL, NULL) ||
!EVP_CIPHER_CTX_set_key_length(&ctx->enc, key_len) ||
- !EVP_EncryptInit_ex(&ctx->enc, cipher, NULL, key, iv)) {
+ !EVP_EncryptInit_ex(&ctx->enc, NULL, NULL, key, iv)) {
EVP_CIPHER_CTX_cleanup(&ctx->enc);
os_free(ctx);
return NULL;
@@ -320,7 +370,7 @@ struct crypto_cipher * crypto_cipher_init(enum crypto_cipher_alg alg,
EVP_CIPHER_CTX_set_padding(&ctx->dec, 0);
if (!EVP_DecryptInit_ex(&ctx->dec, cipher, NULL, NULL, NULL) ||
!EVP_CIPHER_CTX_set_key_length(&ctx->dec, key_len) ||
- !EVP_DecryptInit_ex(&ctx->dec, cipher, NULL, key, iv)) {
+ !EVP_DecryptInit_ex(&ctx->dec, NULL, NULL, key, iv)) {
EVP_CIPHER_CTX_cleanup(&ctx->enc);
EVP_CIPHER_CTX_cleanup(&ctx->dec);
os_free(ctx);
@@ -358,3 +408,98 @@ void crypto_cipher_deinit(struct crypto_cipher *ctx)
EVP_CIPHER_CTX_cleanup(&ctx->dec);
os_free(ctx);
}
+
+
+void * dh5_init(struct wpabuf **priv, struct wpabuf **publ)
+{
+ DH *dh;
+ struct wpabuf *pubkey = NULL, *privkey = NULL;
+ size_t publen, privlen;
+
+ *priv = NULL;
+ *publ = NULL;
+
+ dh = DH_new();
+ if (dh == NULL)
+ return NULL;
+
+ dh->g = BN_new();
+ if (dh->g == NULL || BN_set_word(dh->g, 2) != 1)
+ goto err;
+
+ dh->p = get_group5_prime();
+ if (dh->p == NULL)
+ goto err;
+
+ if (DH_generate_key(dh) != 1)
+ goto err;
+
+ publen = BN_num_bytes(dh->pub_key);
+ pubkey = wpabuf_alloc(publen);
+ if (pubkey == NULL)
+ goto err;
+ privlen = BN_num_bytes(dh->priv_key);
+ privkey = wpabuf_alloc(privlen);
+ if (privkey == NULL)
+ goto err;
+
+ BN_bn2bin(dh->pub_key, wpabuf_put(pubkey, publen));
+ BN_bn2bin(dh->priv_key, wpabuf_put(privkey, privlen));
+
+ *priv = privkey;
+ *publ = pubkey;
+ return dh;
+
+err:
+ wpabuf_free(pubkey);
+ wpabuf_free(privkey);
+ DH_free(dh);
+ return NULL;
+}
+
+
+struct wpabuf * dh5_derive_shared(void *ctx, const struct wpabuf *peer_public,
+ const struct wpabuf *own_private)
+{
+ BIGNUM *pub_key;
+ struct wpabuf *res = NULL;
+ size_t rlen;
+ DH *dh = ctx;
+ int keylen;
+
+ if (ctx == NULL)
+ return NULL;
+
+ pub_key = BN_bin2bn(wpabuf_head(peer_public), wpabuf_len(peer_public),
+ NULL);
+ if (pub_key == NULL)
+ return NULL;
+
+ rlen = DH_size(dh);
+ res = wpabuf_alloc(rlen);
+ if (res == NULL)
+ goto err;
+
+ keylen = DH_compute_key(wpabuf_mhead(res), pub_key, dh);
+ if (keylen < 0)
+ goto err;
+ wpabuf_put(res, keylen);
+ BN_free(pub_key);
+
+ return res;
+
+err:
+ BN_free(pub_key);
+ wpabuf_free(res);
+ return NULL;
+}
+
+
+void dh5_free(void *ctx)
+{
+ DH *dh;
+ if (ctx == NULL)
+ return;
+ dh = ctx;
+ DH_free(dh);
+}
diff --git a/contrib/wpa/src/crypto/des.c b/contrib/wpa/src/crypto/des-internal.c
index 103e592..ccea950 100644
--- a/contrib/wpa/src/crypto/des.c
+++ b/contrib/wpa/src/crypto/des-internal.c
@@ -2,7 +2,7 @@
* DES and 3DES-EDE ciphers
*
* Modifications to LibTomCrypt implementation:
- * Copyright (c) 2006, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2006-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -18,9 +18,7 @@
#include "common.h"
#include "crypto.h"
-
-
-#ifdef INTERNAL_DES
+#include "des_i.h"
/*
* This implementation is based on a DES implementation included in
@@ -432,10 +430,34 @@ void des_encrypt(const u8 *clear, const u8 *key, u8 *cypher)
}
-struct des3_key_s {
- u32 ek[3][32];
- u32 dk[3][32];
-};
+void des_key_setup(const u8 *key, u32 *ek, u32 *dk)
+{
+ deskey(key, 0, ek);
+ deskey(key, 1, dk);
+}
+
+
+void des_block_encrypt(const u8 *plain, const u32 *ek, u8 *crypt)
+{
+ u32 work[2];
+ work[0] = WPA_GET_BE32(plain);
+ work[1] = WPA_GET_BE32(plain + 4);
+ desfunc(work, ek);
+ WPA_PUT_BE32(crypt, work[0]);
+ WPA_PUT_BE32(crypt + 4, work[1]);
+}
+
+
+void des_block_decrypt(const u8 *crypt, const u32 *dk, u8 *plain)
+{
+ u32 work[2];
+ work[0] = WPA_GET_BE32(crypt);
+ work[1] = WPA_GET_BE32(crypt + 4);
+ desfunc(work, dk);
+ WPA_PUT_BE32(plain, work[0]);
+ WPA_PUT_BE32(plain + 4, work[1]);
+}
+
void des3_key_setup(const u8 *key, struct des3_key_s *dkey)
{
@@ -475,5 +497,3 @@ void des3_decrypt(const u8 *crypt, const struct des3_key_s *key, u8 *plain)
WPA_PUT_BE32(plain, work[0]);
WPA_PUT_BE32(plain + 4, work[1]);
}
-
-#endif /* INTERNAL_DES */
diff --git a/contrib/wpa/src/crypto/des_i.h b/contrib/wpa/src/crypto/des_i.h
new file mode 100644
index 0000000..6f27414
--- /dev/null
+++ b/contrib/wpa/src/crypto/des_i.h
@@ -0,0 +1,31 @@
+/*
+ * DES and 3DES-EDE ciphers
+ * Copyright (c) 2006-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef DES_I_H
+#define DES_I_H
+
+struct des3_key_s {
+ u32 ek[3][32];
+ u32 dk[3][32];
+};
+
+void des_key_setup(const u8 *key, u32 *ek, u32 *dk);
+void des_block_encrypt(const u8 *plain, const u32 *ek, u8 *crypt);
+void des_block_decrypt(const u8 *crypt, const u32 *dk, u8 *plain);
+
+void des3_key_setup(const u8 *key, struct des3_key_s *dkey);
+void des3_encrypt(const u8 *plain, const struct des3_key_s *key, u8 *crypt);
+void des3_decrypt(const u8 *crypt, const struct des3_key_s *key, u8 *plain);
+
+#endif /* DES_I_H */
diff --git a/contrib/wpa/src/crypto/dh_group5.c b/contrib/wpa/src/crypto/dh_group5.c
new file mode 100644
index 0000000..8c475bf
--- /dev/null
+++ b/contrib/wpa/src/crypto/dh_group5.c
@@ -0,0 +1,40 @@
+/*
+ * Diffie-Hellman group 5 operations
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "dh_groups.h"
+#include "dh_group5.h"
+
+
+void * dh5_init(struct wpabuf **priv, struct wpabuf **publ)
+{
+ *publ = dh_init(dh_groups_get(5), priv);
+ if (*publ == 0)
+ return NULL;
+ return (void *) 1;
+}
+
+
+struct wpabuf * dh5_derive_shared(void *ctx, const struct wpabuf *peer_public,
+ const struct wpabuf *own_private)
+{
+ return dh_derive_shared(peer_public, own_private, dh_groups_get(5));
+}
+
+
+void dh5_free(void *ctx)
+{
+}
diff --git a/contrib/wpa/src/crypto/dh_group5.h b/contrib/wpa/src/crypto/dh_group5.h
new file mode 100644
index 0000000..595f111
--- /dev/null
+++ b/contrib/wpa/src/crypto/dh_group5.h
@@ -0,0 +1,23 @@
+/*
+ * Diffie-Hellman group 5 operations
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef DH_GROUP5_H
+#define DH_GROUP5_H
+
+void * dh5_init(struct wpabuf **priv, struct wpabuf **publ);
+struct wpabuf * dh5_derive_shared(void *ctx, const struct wpabuf *peer_public,
+ const struct wpabuf *own_private);
+void dh5_free(void *ctx);
+
+#endif /* DH_GROUP5_H */
diff --git a/contrib/wpa/src/crypto/dh_groups.c b/contrib/wpa/src/crypto/dh_groups.c
index 5f6008a..7bd2fb7 100644
--- a/contrib/wpa/src/crypto/dh_groups.c
+++ b/contrib/wpa/src/crypto/dh_groups.c
@@ -619,11 +619,12 @@ struct wpabuf * dh_derive_shared(const struct wpabuf *peer_public,
if (crypto_mod_exp(wpabuf_head(peer_public), wpabuf_len(peer_public),
wpabuf_head(own_private), wpabuf_len(own_private),
dh->prime, dh->prime_len,
- wpabuf_put(shared, shared_len), &shared_len) < 0) {
+ wpabuf_mhead(shared), &shared_len) < 0) {
wpabuf_free(shared);
wpa_printf(MSG_INFO, "DH: crypto_mod_exp failed");
return NULL;
}
+ wpabuf_put(shared, shared_len);
wpa_hexdump_buf_key(MSG_DEBUG, "DH: shared key", shared);
return shared;
diff --git a/contrib/wpa/src/crypto/fips_prf_cryptoapi.c b/contrib/wpa/src/crypto/fips_prf_cryptoapi.c
new file mode 100644
index 0000000..17d3116
--- /dev/null
+++ b/contrib/wpa/src/crypto/fips_prf_cryptoapi.c
@@ -0,0 +1,25 @@
+/*
+ * FIPS 186-2 PRF for Microsoft CryptoAPI
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "crypto.h"
+
+
+int fips186_2_prf(const u8 *seed, size_t seed_len, u8 *x, size_t xlen)
+{
+ /* FIX: how to do this with CryptoAPI? */
+ return -1;
+}
diff --git a/contrib/wpa/src/crypto/fips_prf_gnutls.c b/contrib/wpa/src/crypto/fips_prf_gnutls.c
new file mode 100644
index 0000000..f742e98
--- /dev/null
+++ b/contrib/wpa/src/crypto/fips_prf_gnutls.c
@@ -0,0 +1,26 @@
+/*
+ * FIPS 186-2 PRF for libgcrypt
+ * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+#include <gcrypt.h>
+
+#include "common.h"
+#include "crypto.h"
+
+
+int fips186_2_prf(const u8 *seed, size_t seed_len, u8 *x, size_t xlen)
+{
+ /* FIX: how to do this with libgcrypt? */
+ return -1;
+}
diff --git a/contrib/wpa/src/crypto/fips_prf_internal.c b/contrib/wpa/src/crypto/fips_prf_internal.c
new file mode 100644
index 0000000..a85cb14
--- /dev/null
+++ b/contrib/wpa/src/crypto/fips_prf_internal.c
@@ -0,0 +1,74 @@
+/*
+ * FIPS 186-2 PRF for internal crypto implementation
+ * Copyright (c) 2006-2007, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "sha1.h"
+#include "sha1_i.h"
+#include "crypto.h"
+
+
+int fips186_2_prf(const u8 *seed, size_t seed_len, u8 *x, size_t xlen)
+{
+ u8 xkey[64];
+ u32 t[5], _t[5];
+ int i, j, m, k;
+ u8 *xpos = x;
+ u32 carry;
+
+ if (seed_len > sizeof(xkey))
+ seed_len = sizeof(xkey);
+
+ /* FIPS 186-2 + change notice 1 */
+
+ os_memcpy(xkey, seed, seed_len);
+ os_memset(xkey + seed_len, 0, 64 - seed_len);
+ t[0] = 0x67452301;
+ t[1] = 0xEFCDAB89;
+ t[2] = 0x98BADCFE;
+ t[3] = 0x10325476;
+ t[4] = 0xC3D2E1F0;
+
+ m = xlen / 40;
+ for (j = 0; j < m; j++) {
+ /* XSEED_j = 0 */
+ for (i = 0; i < 2; i++) {
+ /* XVAL = (XKEY + XSEED_j) mod 2^b */
+
+ /* w_i = G(t, XVAL) */
+ os_memcpy(_t, t, 20);
+ SHA1Transform(_t, xkey);
+ _t[0] = host_to_be32(_t[0]);
+ _t[1] = host_to_be32(_t[1]);
+ _t[2] = host_to_be32(_t[2]);
+ _t[3] = host_to_be32(_t[3]);
+ _t[4] = host_to_be32(_t[4]);
+ os_memcpy(xpos, _t, 20);
+
+ /* XKEY = (1 + XKEY + w_i) mod 2^b */
+ carry = 1;
+ for (k = 19; k >= 0; k--) {
+ carry += xkey[k] + xpos[k];
+ xkey[k] = carry & 0xff;
+ carry >>= 8;
+ }
+
+ xpos += SHA1_MAC_LEN;
+ }
+ /* x_j = w_0|w_1 */
+ }
+
+ return 0;
+}
diff --git a/contrib/wpa/src/crypto/fips_prf_nss.c b/contrib/wpa/src/crypto/fips_prf_nss.c
new file mode 100644
index 0000000..f941983
--- /dev/null
+++ b/contrib/wpa/src/crypto/fips_prf_nss.c
@@ -0,0 +1,25 @@
+/*
+ * FIPS 186-2 PRF for NSS
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+#include <openssl/sha.h>
+
+#include "common.h"
+#include "crypto.h"
+
+
+int fips186_2_prf(const u8 *seed, size_t seed_len, u8 *x, size_t xlen)
+{
+ return -1;
+}
diff --git a/contrib/wpa/src/crypto/fips_prf_openssl.c b/contrib/wpa/src/crypto/fips_prf_openssl.c
new file mode 100644
index 0000000..d0af983
--- /dev/null
+++ b/contrib/wpa/src/crypto/fips_prf_openssl.c
@@ -0,0 +1,83 @@
+/*
+ * FIPS 186-2 PRF for libcrypto
+ * Copyright (c) 2004-2005, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+#include <openssl/sha.h>
+
+#include "common.h"
+#include "crypto.h"
+
+
+static void sha1_transform(u8 *state, const u8 data[64])
+{
+ SHA_CTX context;
+ os_memset(&context, 0, sizeof(context));
+ os_memcpy(&context.h0, state, 5 * 4);
+ SHA1_Transform(&context, data);
+ os_memcpy(state, &context.h0, 5 * 4);
+}
+
+
+int fips186_2_prf(const u8 *seed, size_t seed_len, u8 *x, size_t xlen)
+{
+ u8 xkey[64];
+ u32 t[5], _t[5];
+ int i, j, m, k;
+ u8 *xpos = x;
+ u32 carry;
+
+ if (seed_len > sizeof(xkey))
+ seed_len = sizeof(xkey);
+
+ /* FIPS 186-2 + change notice 1 */
+
+ os_memcpy(xkey, seed, seed_len);
+ os_memset(xkey + seed_len, 0, 64 - seed_len);
+ t[0] = 0x67452301;
+ t[1] = 0xEFCDAB89;
+ t[2] = 0x98BADCFE;
+ t[3] = 0x10325476;
+ t[4] = 0xC3D2E1F0;
+
+ m = xlen / 40;
+ for (j = 0; j < m; j++) {
+ /* XSEED_j = 0 */
+ for (i = 0; i < 2; i++) {
+ /* XVAL = (XKEY + XSEED_j) mod 2^b */
+
+ /* w_i = G(t, XVAL) */
+ os_memcpy(_t, t, 20);
+ sha1_transform((u8 *) _t, xkey);
+ _t[0] = host_to_be32(_t[0]);
+ _t[1] = host_to_be32(_t[1]);
+ _t[2] = host_to_be32(_t[2]);
+ _t[3] = host_to_be32(_t[3]);
+ _t[4] = host_to_be32(_t[4]);
+ os_memcpy(xpos, _t, 20);
+
+ /* XKEY = (1 + XKEY + w_i) mod 2^b */
+ carry = 1;
+ for (k = 19; k >= 0; k--) {
+ carry += xkey[k] + xpos[k];
+ xkey[k] = carry & 0xff;
+ carry >>= 8;
+ }
+
+ xpos += 20;
+ }
+ /* x_j = w_0|w_1 */
+ }
+
+ return 0;
+}
diff --git a/contrib/wpa/src/crypto/md4.c b/contrib/wpa/src/crypto/md4-internal.c
index 41c84a3..d9f499f 100644
--- a/contrib/wpa/src/crypto/md4.c
+++ b/contrib/wpa/src/crypto/md4-internal.c
@@ -17,9 +17,6 @@
#include "common.h"
#include "crypto.h"
-
-#ifdef INTERNAL_MD4
-
#define MD4_BLOCK_LENGTH 64
#define MD4_DIGEST_LENGTH 16
@@ -35,7 +32,7 @@ static void MD4Update(MD4_CTX *ctx, const unsigned char *input, size_t len);
static void MD4Final(unsigned char digest[MD4_DIGEST_LENGTH], MD4_CTX *ctx);
-void md4_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
+int md4_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
{
MD4_CTX ctx;
size_t i;
@@ -44,6 +41,7 @@ void md4_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
for (i = 0; i < num_elem; i++)
MD4Update(&ctx, addr[i], len[i]);
MD4Final(mac, &ctx);
+ return 0;
}
@@ -278,5 +276,3 @@ MD4Transform(u32 state[4], const u8 block[MD4_BLOCK_LENGTH])
state[3] += d;
}
/* ===== end - public domain MD4 implementation ===== */
-
-#endif /* INTERNAL_MD4 */
diff --git a/contrib/wpa/src/crypto/md5-internal.c b/contrib/wpa/src/crypto/md5-internal.c
new file mode 100644
index 0000000..f8692a9
--- /dev/null
+++ b/contrib/wpa/src/crypto/md5-internal.c
@@ -0,0 +1,293 @@
+/*
+ * MD5 hash implementation and interface functions
+ * Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "md5.h"
+#include "md5_i.h"
+#include "crypto.h"
+
+
+static void MD5Transform(u32 buf[4], u32 const in[16]);
+
+
+typedef struct MD5Context MD5_CTX;
+
+
+/**
+ * md5_vector - MD5 hash for data vector
+ * @num_elem: Number of elements in the data vector
+ * @addr: Pointers to the data areas
+ * @len: Lengths of the data blocks
+ * @mac: Buffer for the hash
+ * Returns: 0 on success, -1 of failure
+ */
+int md5_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
+{
+ MD5_CTX ctx;
+ size_t i;
+
+ MD5Init(&ctx);
+ for (i = 0; i < num_elem; i++)
+ MD5Update(&ctx, addr[i], len[i]);
+ MD5Final(mac, &ctx);
+ return 0;
+}
+
+
+/* ===== start - public domain MD5 implementation ===== */
+/*
+ * This code implements the MD5 message-digest algorithm.
+ * The algorithm is due to Ron Rivest. This code was
+ * written by Colin Plumb in 1993, no copyright is claimed.
+ * This code is in the public domain; do with it what you wish.
+ *
+ * Equivalent code is available from RSA Data Security, Inc.
+ * This code has been tested against that, and is equivalent,
+ * except that you don't need to include two pages of legalese
+ * with every copy.
+ *
+ * To compute the message digest of a chunk of bytes, declare an
+ * MD5Context structure, pass it to MD5Init, call MD5Update as
+ * needed on buffers full of bytes, and then call MD5Final, which
+ * will fill a supplied 16-byte array with the digest.
+ */
+
+#ifndef WORDS_BIGENDIAN
+#define byteReverse(buf, len) /* Nothing */
+#else
+/*
+ * Note: this code is harmless on little-endian machines.
+ */
+static void byteReverse(unsigned char *buf, unsigned longs)
+{
+ u32 t;
+ do {
+ t = (u32) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
+ ((unsigned) buf[1] << 8 | buf[0]);
+ *(u32 *) buf = t;
+ buf += 4;
+ } while (--longs);
+}
+#endif
+
+/*
+ * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
+ * initialization constants.
+ */
+void MD5Init(struct MD5Context *ctx)
+{
+ ctx->buf[0] = 0x67452301;
+ ctx->buf[1] = 0xefcdab89;
+ ctx->buf[2] = 0x98badcfe;
+ ctx->buf[3] = 0x10325476;
+
+ ctx->bits[0] = 0;
+ ctx->bits[1] = 0;
+}
+
+/*
+ * Update context to reflect the concatenation of another buffer full
+ * of bytes.
+ */
+void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
+{
+ u32 t;
+
+ /* Update bitcount */
+
+ t = ctx->bits[0];
+ if ((ctx->bits[0] = t + ((u32) len << 3)) < t)
+ ctx->bits[1]++; /* Carry from low to high */
+ ctx->bits[1] += len >> 29;
+
+ t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
+
+ /* Handle any leading odd-sized chunks */
+
+ if (t) {
+ unsigned char *p = (unsigned char *) ctx->in + t;
+
+ t = 64 - t;
+ if (len < t) {
+ os_memcpy(p, buf, len);
+ return;
+ }
+ os_memcpy(p, buf, t);
+ byteReverse(ctx->in, 16);
+ MD5Transform(ctx->buf, (u32 *) ctx->in);
+ buf += t;
+ len -= t;
+ }
+ /* Process data in 64-byte chunks */
+
+ while (len >= 64) {
+ os_memcpy(ctx->in, buf, 64);
+ byteReverse(ctx->in, 16);
+ MD5Transform(ctx->buf, (u32 *) ctx->in);
+ buf += 64;
+ len -= 64;
+ }
+
+ /* Handle any remaining bytes of data. */
+
+ os_memcpy(ctx->in, buf, len);
+}
+
+/*
+ * Final wrapup - pad to 64-byte boundary with the bit pattern
+ * 1 0* (64-bit count of bits processed, MSB-first)
+ */
+void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
+{
+ unsigned count;
+ unsigned char *p;
+
+ /* Compute number of bytes mod 64 */
+ count = (ctx->bits[0] >> 3) & 0x3F;
+
+ /* Set the first char of padding to 0x80. This is safe since there is
+ always at least one byte free */
+ p = ctx->in + count;
+ *p++ = 0x80;
+
+ /* Bytes of padding needed to make 64 bytes */
+ count = 64 - 1 - count;
+
+ /* Pad out to 56 mod 64 */
+ if (count < 8) {
+ /* Two lots of padding: Pad the first block to 64 bytes */
+ os_memset(p, 0, count);
+ byteReverse(ctx->in, 16);
+ MD5Transform(ctx->buf, (u32 *) ctx->in);
+
+ /* Now fill the next block with 56 bytes */
+ os_memset(ctx->in, 0, 56);
+ } else {
+ /* Pad block to 56 bytes */
+ os_memset(p, 0, count - 8);
+ }
+ byteReverse(ctx->in, 14);
+
+ /* Append length in bits and transform */
+ ((u32 *) ctx->in)[14] = ctx->bits[0];
+ ((u32 *) ctx->in)[15] = ctx->bits[1];
+
+ MD5Transform(ctx->buf, (u32 *) ctx->in);
+ byteReverse((unsigned char *) ctx->buf, 4);
+ os_memcpy(digest, ctx->buf, 16);
+ os_memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
+}
+
+/* The four core functions - F1 is optimized somewhat */
+
+/* #define F1(x, y, z) (x & y | ~x & z) */
+#define F1(x, y, z) (z ^ (x & (y ^ z)))
+#define F2(x, y, z) F1(z, x, y)
+#define F3(x, y, z) (x ^ y ^ z)
+#define F4(x, y, z) (y ^ (x | ~z))
+
+/* This is the central step in the MD5 algorithm. */
+#define MD5STEP(f, w, x, y, z, data, s) \
+ ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
+
+/*
+ * The core of the MD5 algorithm, this alters an existing MD5 hash to
+ * reflect the addition of 16 longwords of new data. MD5Update blocks
+ * the data and converts bytes into longwords for this routine.
+ */
+static void MD5Transform(u32 buf[4], u32 const in[16])
+{
+ register u32 a, b, c, d;
+
+ a = buf[0];
+ b = buf[1];
+ c = buf[2];
+ d = buf[3];
+
+ MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
+ MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
+ MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
+ MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
+ MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
+ MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
+ MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
+ MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
+ MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
+ MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
+ MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
+ MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
+ MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
+ MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
+ MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
+ MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
+
+ MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
+ MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
+ MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
+ MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
+ MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
+ MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
+ MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
+ MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
+ MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
+ MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
+ MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
+ MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
+ MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
+ MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
+ MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
+ MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
+
+ MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
+ MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
+ MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
+ MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
+ MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
+ MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
+ MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
+ MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
+ MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
+ MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
+ MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
+ MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
+ MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
+ MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
+ MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
+ MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
+
+ MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
+ MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
+ MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
+ MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
+ MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
+ MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
+ MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
+ MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
+ MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
+ MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
+ MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
+ MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
+ MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
+ MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
+ MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
+ MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
+
+ buf[0] += a;
+ buf[1] += b;
+ buf[2] += c;
+ buf[3] += d;
+}
+/* ===== end - public domain MD5 implementation ===== */
diff --git a/contrib/wpa/src/crypto/md5-non-fips.c b/contrib/wpa/src/crypto/md5-non-fips.c
new file mode 100644
index 0000000..6f29201
--- /dev/null
+++ b/contrib/wpa/src/crypto/md5-non-fips.c
@@ -0,0 +1,113 @@
+/*
+ * MD5 hash implementation and interface functions (non-FIPS allowed cases)
+ * Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "md5.h"
+#include "crypto.h"
+
+
+/**
+ * hmac_md5_vector_non_fips_allow - HMAC-MD5 over data vector (RFC 2104)
+ * @key: Key for HMAC operations
+ * @key_len: Length of the key in bytes
+ * @num_elem: Number of elements in the data vector
+ * @addr: Pointers to the data areas
+ * @len: Lengths of the data blocks
+ * @mac: Buffer for the hash (16 bytes)
+ * Returns: 0 on success, -1 on failure
+ */
+int hmac_md5_vector_non_fips_allow(const u8 *key, size_t key_len,
+ size_t num_elem, const u8 *addr[],
+ const size_t *len, u8 *mac)
+{
+ u8 k_pad[64]; /* padding - key XORd with ipad/opad */
+ u8 tk[16];
+ const u8 *_addr[6];
+ size_t i, _len[6];
+
+ if (num_elem > 5) {
+ /*
+ * Fixed limit on the number of fragments to avoid having to
+ * allocate memory (which could fail).
+ */
+ return -1;
+ }
+
+ /* if key is longer than 64 bytes reset it to key = MD5(key) */
+ if (key_len > 64) {
+ if (md5_vector_non_fips_allow(1, &key, &key_len, tk))
+ return -1;
+ key = tk;
+ key_len = 16;
+ }
+
+ /* the HMAC_MD5 transform looks like:
+ *
+ * MD5(K XOR opad, MD5(K XOR ipad, text))
+ *
+ * where K is an n byte key
+ * ipad is the byte 0x36 repeated 64 times
+ * opad is the byte 0x5c repeated 64 times
+ * and text is the data being protected */
+
+ /* start out by storing key in ipad */
+ os_memset(k_pad, 0, sizeof(k_pad));
+ os_memcpy(k_pad, key, key_len);
+
+ /* XOR key with ipad values */
+ for (i = 0; i < 64; i++)
+ k_pad[i] ^= 0x36;
+
+ /* perform inner MD5 */
+ _addr[0] = k_pad;
+ _len[0] = 64;
+ for (i = 0; i < num_elem; i++) {
+ _addr[i + 1] = addr[i];
+ _len[i + 1] = len[i];
+ }
+ if (md5_vector_non_fips_allow(1 + num_elem, _addr, _len, mac))
+ return -1;
+
+ os_memset(k_pad, 0, sizeof(k_pad));
+ os_memcpy(k_pad, key, key_len);
+ /* XOR key with opad values */
+ for (i = 0; i < 64; i++)
+ k_pad[i] ^= 0x5c;
+
+ /* perform outer MD5 */
+ _addr[0] = k_pad;
+ _len[0] = 64;
+ _addr[1] = mac;
+ _len[1] = MD5_MAC_LEN;
+ return md5_vector_non_fips_allow(2, _addr, _len, mac);
+}
+
+
+/**
+ * hmac_md5_non_fips_allow - HMAC-MD5 over data buffer (RFC 2104)
+ * @key: Key for HMAC operations
+ * @key_len: Length of the key in bytes
+ * @data: Pointers to the data area
+ * @data_len: Length of the data area
+ * @mac: Buffer for the hash (16 bytes)
+ * Returns: 0 on success, -1 on failure
+ */
+int hmac_md5_non_fips_allow(const u8 *key, size_t key_len, const u8 *data,
+ size_t data_len, u8 *mac)
+{
+ return hmac_md5_vector_non_fips_allow(key, key_len, 1, &data,
+ &data_len, mac);
+}
diff --git a/contrib/wpa/src/crypto/md5.c b/contrib/wpa/src/crypto/md5.c
index a7db7aa..7f14e9b 100644
--- a/contrib/wpa/src/crypto/md5.c
+++ b/contrib/wpa/src/crypto/md5.c
@@ -27,9 +27,10 @@
* @addr: Pointers to the data areas
* @len: Lengths of the data blocks
* @mac: Buffer for the hash (16 bytes)
+ * Returns: 0 on success, -1 on failure
*/
-void hmac_md5_vector(const u8 *key, size_t key_len, size_t num_elem,
- const u8 *addr[], const size_t *len, u8 *mac)
+int hmac_md5_vector(const u8 *key, size_t key_len, size_t num_elem,
+ const u8 *addr[], const size_t *len, u8 *mac)
{
u8 k_pad[64]; /* padding - key XORd with ipad/opad */
u8 tk[16];
@@ -41,12 +42,13 @@ void hmac_md5_vector(const u8 *key, size_t key_len, size_t num_elem,
* Fixed limit on the number of fragments to avoid having to
* allocate memory (which could fail).
*/
- return;
+ return -1;
}
/* if key is longer than 64 bytes reset it to key = MD5(key) */
if (key_len > 64) {
- md5_vector(1, &key, &key_len, tk);
+ if (md5_vector(1, &key, &key_len, tk))
+ return -1;
key = tk;
key_len = 16;
}
@@ -75,7 +77,8 @@ void hmac_md5_vector(const u8 *key, size_t key_len, size_t num_elem,
_addr[i + 1] = addr[i];
_len[i + 1] = len[i];
}
- md5_vector(1 + num_elem, _addr, _len, mac);
+ if (md5_vector(1 + num_elem, _addr, _len, mac))
+ return -1;
os_memset(k_pad, 0, sizeof(k_pad));
os_memcpy(k_pad, key, key_len);
@@ -88,7 +91,7 @@ void hmac_md5_vector(const u8 *key, size_t key_len, size_t num_elem,
_len[0] = 64;
_addr[1] = mac;
_len[1] = MD5_MAC_LEN;
- md5_vector(2, _addr, _len, mac);
+ return md5_vector(2, _addr, _len, mac);
}
@@ -99,296 +102,10 @@ void hmac_md5_vector(const u8 *key, size_t key_len, size_t num_elem,
* @data: Pointers to the data area
* @data_len: Length of the data area
* @mac: Buffer for the hash (16 bytes)
+ * Returns: 0 on success, -1 on failure
*/
-void hmac_md5(const u8 *key, size_t key_len, const u8 *data, size_t data_len,
+int hmac_md5(const u8 *key, size_t key_len, const u8 *data, size_t data_len,
u8 *mac)
{
- hmac_md5_vector(key, key_len, 1, &data, &data_len, mac);
+ return hmac_md5_vector(key, key_len, 1, &data, &data_len, mac);
}
-
-
-#ifdef INTERNAL_MD5
-
-struct MD5Context {
- u32 buf[4];
- u32 bits[2];
- u8 in[64];
-};
-
-#ifndef CONFIG_CRYPTO_INTERNAL
-static void MD5Init(struct MD5Context *context);
-static void MD5Update(struct MD5Context *context, unsigned char const *buf,
- unsigned len);
-static void MD5Final(unsigned char digest[16], struct MD5Context *context);
-#endif /* CONFIG_CRYPTO_INTERNAL */
-static void MD5Transform(u32 buf[4], u32 const in[16]);
-
-
-typedef struct MD5Context MD5_CTX;
-
-
-/**
- * md5_vector - MD5 hash for data vector
- * @num_elem: Number of elements in the data vector
- * @addr: Pointers to the data areas
- * @len: Lengths of the data blocks
- * @mac: Buffer for the hash
- */
-void md5_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
-{
- MD5_CTX ctx;
- size_t i;
-
- MD5Init(&ctx);
- for (i = 0; i < num_elem; i++)
- MD5Update(&ctx, addr[i], len[i]);
- MD5Final(mac, &ctx);
-}
-
-
-/* ===== start - public domain MD5 implementation ===== */
-/*
- * This code implements the MD5 message-digest algorithm.
- * The algorithm is due to Ron Rivest. This code was
- * written by Colin Plumb in 1993, no copyright is claimed.
- * This code is in the public domain; do with it what you wish.
- *
- * Equivalent code is available from RSA Data Security, Inc.
- * This code has been tested against that, and is equivalent,
- * except that you don't need to include two pages of legalese
- * with every copy.
- *
- * To compute the message digest of a chunk of bytes, declare an
- * MD5Context structure, pass it to MD5Init, call MD5Update as
- * needed on buffers full of bytes, and then call MD5Final, which
- * will fill a supplied 16-byte array with the digest.
- */
-
-#ifndef WORDS_BIGENDIAN
-#define byteReverse(buf, len) /* Nothing */
-#else
-/*
- * Note: this code is harmless on little-endian machines.
- */
-static void byteReverse(unsigned char *buf, unsigned longs)
-{
- u32 t;
- do {
- t = (u32) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
- ((unsigned) buf[1] << 8 | buf[0]);
- *(u32 *) buf = t;
- buf += 4;
- } while (--longs);
-}
-#endif
-
-/*
- * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
- * initialization constants.
- */
-void MD5Init(struct MD5Context *ctx)
-{
- ctx->buf[0] = 0x67452301;
- ctx->buf[1] = 0xefcdab89;
- ctx->buf[2] = 0x98badcfe;
- ctx->buf[3] = 0x10325476;
-
- ctx->bits[0] = 0;
- ctx->bits[1] = 0;
-}
-
-/*
- * Update context to reflect the concatenation of another buffer full
- * of bytes.
- */
-void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
-{
- u32 t;
-
- /* Update bitcount */
-
- t = ctx->bits[0];
- if ((ctx->bits[0] = t + ((u32) len << 3)) < t)
- ctx->bits[1]++; /* Carry from low to high */
- ctx->bits[1] += len >> 29;
-
- t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
-
- /* Handle any leading odd-sized chunks */
-
- if (t) {
- unsigned char *p = (unsigned char *) ctx->in + t;
-
- t = 64 - t;
- if (len < t) {
- os_memcpy(p, buf, len);
- return;
- }
- os_memcpy(p, buf, t);
- byteReverse(ctx->in, 16);
- MD5Transform(ctx->buf, (u32 *) ctx->in);
- buf += t;
- len -= t;
- }
- /* Process data in 64-byte chunks */
-
- while (len >= 64) {
- os_memcpy(ctx->in, buf, 64);
- byteReverse(ctx->in, 16);
- MD5Transform(ctx->buf, (u32 *) ctx->in);
- buf += 64;
- len -= 64;
- }
-
- /* Handle any remaining bytes of data. */
-
- os_memcpy(ctx->in, buf, len);
-}
-
-/*
- * Final wrapup - pad to 64-byte boundary with the bit pattern
- * 1 0* (64-bit count of bits processed, MSB-first)
- */
-void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
-{
- unsigned count;
- unsigned char *p;
-
- /* Compute number of bytes mod 64 */
- count = (ctx->bits[0] >> 3) & 0x3F;
-
- /* Set the first char of padding to 0x80. This is safe since there is
- always at least one byte free */
- p = ctx->in + count;
- *p++ = 0x80;
-
- /* Bytes of padding needed to make 64 bytes */
- count = 64 - 1 - count;
-
- /* Pad out to 56 mod 64 */
- if (count < 8) {
- /* Two lots of padding: Pad the first block to 64 bytes */
- os_memset(p, 0, count);
- byteReverse(ctx->in, 16);
- MD5Transform(ctx->buf, (u32 *) ctx->in);
-
- /* Now fill the next block with 56 bytes */
- os_memset(ctx->in, 0, 56);
- } else {
- /* Pad block to 56 bytes */
- os_memset(p, 0, count - 8);
- }
- byteReverse(ctx->in, 14);
-
- /* Append length in bits and transform */
- ((u32 *) ctx->in)[14] = ctx->bits[0];
- ((u32 *) ctx->in)[15] = ctx->bits[1];
-
- MD5Transform(ctx->buf, (u32 *) ctx->in);
- byteReverse((unsigned char *) ctx->buf, 4);
- os_memcpy(digest, ctx->buf, 16);
- os_memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
-}
-
-/* The four core functions - F1 is optimized somewhat */
-
-/* #define F1(x, y, z) (x & y | ~x & z) */
-#define F1(x, y, z) (z ^ (x & (y ^ z)))
-#define F2(x, y, z) F1(z, x, y)
-#define F3(x, y, z) (x ^ y ^ z)
-#define F4(x, y, z) (y ^ (x | ~z))
-
-/* This is the central step in the MD5 algorithm. */
-#define MD5STEP(f, w, x, y, z, data, s) \
- ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
-
-/*
- * The core of the MD5 algorithm, this alters an existing MD5 hash to
- * reflect the addition of 16 longwords of new data. MD5Update blocks
- * the data and converts bytes into longwords for this routine.
- */
-static void MD5Transform(u32 buf[4], u32 const in[16])
-{
- register u32 a, b, c, d;
-
- a = buf[0];
- b = buf[1];
- c = buf[2];
- d = buf[3];
-
- MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
- MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
- MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
- MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
- MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
- MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
- MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
- MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
- MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
- MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
- MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
- MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
- MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
- MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
- MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
- MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
-
- MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
- MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
- MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
- MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
- MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
- MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
- MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
- MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
- MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
- MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
- MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
- MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
- MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
- MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
- MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
- MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
-
- MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
- MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
- MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
- MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
- MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
- MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
- MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
- MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
- MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
- MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
- MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
- MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
- MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
- MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
- MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
- MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
-
- MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
- MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
- MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
- MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
- MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
- MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
- MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
- MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
- MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
- MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
- MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
- MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
- MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
- MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
- MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
- MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
-
- buf[0] += a;
- buf[1] += b;
- buf[2] += c;
- buf[3] += d;
-}
-/* ===== end - public domain MD5 implementation ===== */
-
-#endif /* INTERNAL_MD5 */
diff --git a/contrib/wpa/src/crypto/md5.h b/contrib/wpa/src/crypto/md5.h
index e82f396..8952590 100644
--- a/contrib/wpa/src/crypto/md5.h
+++ b/contrib/wpa/src/crypto/md5.h
@@ -1,6 +1,6 @@
/*
* MD5 hash implementation and interface functions
- * Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -17,18 +17,19 @@
#define MD5_MAC_LEN 16
-void hmac_md5_vector(const u8 *key, size_t key_len, size_t num_elem,
- const u8 *addr[], const size_t *len, u8 *mac);
-void hmac_md5(const u8 *key, size_t key_len, const u8 *data, size_t data_len,
- u8 *mac);
-
-#ifdef CONFIG_CRYPTO_INTERNAL
-struct MD5Context;
-
-void MD5Init(struct MD5Context *context);
-void MD5Update(struct MD5Context *context, unsigned char const *buf,
- unsigned len);
-void MD5Final(unsigned char digest[16], struct MD5Context *context);
-#endif /* CONFIG_CRYPTO_INTERNAL */
+int hmac_md5_vector(const u8 *key, size_t key_len, size_t num_elem,
+ const u8 *addr[], const size_t *len, u8 *mac);
+int hmac_md5(const u8 *key, size_t key_len, const u8 *data, size_t data_len,
+ u8 *mac);
+#ifdef CONFIG_FIPS
+int hmac_md5_vector_non_fips_allow(const u8 *key, size_t key_len,
+ size_t num_elem, const u8 *addr[],
+ const size_t *len, u8 *mac);
+int hmac_md5_non_fips_allow(const u8 *key, size_t key_len, const u8 *data,
+ size_t data_len, u8 *mac);
+#else /* CONFIG_FIPS */
+#define hmac_md5_vector_non_fips_allow hmac_md5_vector
+#define hmac_md5_non_fips_allow hmac_md5
+#endif /* CONFIG_FIPS */
#endif /* MD5_H */
diff --git a/contrib/wpa/src/crypto/md5_i.h b/contrib/wpa/src/crypto/md5_i.h
new file mode 100644
index 0000000..b7f6596
--- /dev/null
+++ b/contrib/wpa/src/crypto/md5_i.h
@@ -0,0 +1,29 @@
+/*
+ * MD5 internal definitions
+ * Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef MD5_I_H
+#define MD5_I_H
+
+struct MD5Context {
+ u32 buf[4];
+ u32 bits[2];
+ u8 in[64];
+};
+
+void MD5Init(struct MD5Context *context);
+void MD5Update(struct MD5Context *context, unsigned char const *buf,
+ unsigned len);
+void MD5Final(unsigned char digest[16], struct MD5Context *context);
+
+#endif /* MD5_I_H */
diff --git a/contrib/wpa/src/crypto/milenage.c b/contrib/wpa/src/crypto/milenage.c
new file mode 100644
index 0000000..cf0c60e
--- /dev/null
+++ b/contrib/wpa/src/crypto/milenage.c
@@ -0,0 +1,329 @@
+/*
+ * 3GPP AKA - Milenage algorithm (3GPP TS 35.205, .206, .207, .208)
+ * Copyright (c) 2006-2007 <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ *
+ * This file implements an example authentication algorithm defined for 3GPP
+ * AKA. This can be used to implement a simple HLR/AuC into hlr_auc_gw to allow
+ * EAP-AKA to be tested properly with real USIM cards.
+ *
+ * This implementations assumes that the r1..r5 and c1..c5 constants defined in
+ * TS 35.206 are used, i.e., r1=64, r2=0, r3=32, r4=64, r5=96, c1=00..00,
+ * c2=00..01, c3=00..02, c4=00..04, c5=00..08. The block cipher is assumed to
+ * be AES (Rijndael).
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "crypto/aes_wrap.h"
+#include "milenage.h"
+
+
+/**
+ * milenage_f1 - Milenage f1 and f1* algorithms
+ * @opc: OPc = 128-bit value derived from OP and K
+ * @k: K = 128-bit subscriber key
+ * @_rand: RAND = 128-bit random challenge
+ * @sqn: SQN = 48-bit sequence number
+ * @amf: AMF = 16-bit authentication management field
+ * @mac_a: Buffer for MAC-A = 64-bit network authentication code, or %NULL
+ * @mac_s: Buffer for MAC-S = 64-bit resync authentication code, or %NULL
+ * Returns: 0 on success, -1 on failure
+ */
+int milenage_f1(const u8 *opc, const u8 *k, const u8 *_rand,
+ const u8 *sqn, const u8 *amf, u8 *mac_a, u8 *mac_s)
+{
+ u8 tmp1[16], tmp2[16], tmp3[16];
+ int i;
+
+ /* tmp1 = TEMP = E_K(RAND XOR OP_C) */
+ for (i = 0; i < 16; i++)
+ tmp1[i] = _rand[i] ^ opc[i];
+ if (aes_128_encrypt_block(k, tmp1, tmp1))
+ return -1;
+
+ /* tmp2 = IN1 = SQN || AMF || SQN || AMF */
+ os_memcpy(tmp2, sqn, 6);
+ os_memcpy(tmp2 + 6, amf, 2);
+ os_memcpy(tmp2 + 8, tmp2, 8);
+
+ /* OUT1 = E_K(TEMP XOR rot(IN1 XOR OP_C, r1) XOR c1) XOR OP_C */
+
+ /* rotate (tmp2 XOR OP_C) by r1 (= 0x40 = 8 bytes) */
+ for (i = 0; i < 16; i++)
+ tmp3[(i + 8) % 16] = tmp2[i] ^ opc[i];
+ /* XOR with TEMP = E_K(RAND XOR OP_C) */
+ for (i = 0; i < 16; i++)
+ tmp3[i] ^= tmp1[i];
+ /* XOR with c1 (= ..00, i.e., NOP) */
+
+ /* f1 || f1* = E_K(tmp3) XOR OP_c */
+ if (aes_128_encrypt_block(k, tmp3, tmp1))
+ return -1;
+ for (i = 0; i < 16; i++)
+ tmp1[i] ^= opc[i];
+ if (mac_a)
+ os_memcpy(mac_a, tmp1, 8); /* f1 */
+ if (mac_s)
+ os_memcpy(mac_s, tmp1 + 8, 8); /* f1* */
+ return 0;
+}
+
+
+/**
+ * milenage_f2345 - Milenage f2, f3, f4, f5, f5* algorithms
+ * @opc: OPc = 128-bit value derived from OP and K
+ * @k: K = 128-bit subscriber key
+ * @_rand: RAND = 128-bit random challenge
+ * @res: Buffer for RES = 64-bit signed response (f2), or %NULL
+ * @ck: Buffer for CK = 128-bit confidentiality key (f3), or %NULL
+ * @ik: Buffer for IK = 128-bit integrity key (f4), or %NULL
+ * @ak: Buffer for AK = 48-bit anonymity key (f5), or %NULL
+ * @akstar: Buffer for AK = 48-bit anonymity key (f5*), or %NULL
+ * Returns: 0 on success, -1 on failure
+ */
+int milenage_f2345(const u8 *opc, const u8 *k, const u8 *_rand,
+ u8 *res, u8 *ck, u8 *ik, u8 *ak, u8 *akstar)
+{
+ u8 tmp1[16], tmp2[16], tmp3[16];
+ int i;
+
+ /* tmp2 = TEMP = E_K(RAND XOR OP_C) */
+ for (i = 0; i < 16; i++)
+ tmp1[i] = _rand[i] ^ opc[i];
+ if (aes_128_encrypt_block(k, tmp1, tmp2))
+ return -1;
+
+ /* OUT2 = E_K(rot(TEMP XOR OP_C, r2) XOR c2) XOR OP_C */
+ /* OUT3 = E_K(rot(TEMP XOR OP_C, r3) XOR c3) XOR OP_C */
+ /* OUT4 = E_K(rot(TEMP XOR OP_C, r4) XOR c4) XOR OP_C */
+ /* OUT5 = E_K(rot(TEMP XOR OP_C, r5) XOR c5) XOR OP_C */
+
+ /* f2 and f5 */
+ /* rotate by r2 (= 0, i.e., NOP) */
+ for (i = 0; i < 16; i++)
+ tmp1[i] = tmp2[i] ^ opc[i];
+ tmp1[15] ^= 1; /* XOR c2 (= ..01) */
+ /* f5 || f2 = E_K(tmp1) XOR OP_c */
+ if (aes_128_encrypt_block(k, tmp1, tmp3))
+ return -1;
+ for (i = 0; i < 16; i++)
+ tmp3[i] ^= opc[i];
+ if (res)
+ os_memcpy(res, tmp3 + 8, 8); /* f2 */
+ if (ak)
+ os_memcpy(ak, tmp3, 6); /* f5 */
+
+ /* f3 */
+ if (ck) {
+ /* rotate by r3 = 0x20 = 4 bytes */
+ for (i = 0; i < 16; i++)
+ tmp1[(i + 12) % 16] = tmp2[i] ^ opc[i];
+ tmp1[15] ^= 2; /* XOR c3 (= ..02) */
+ if (aes_128_encrypt_block(k, tmp1, ck))
+ return -1;
+ for (i = 0; i < 16; i++)
+ ck[i] ^= opc[i];
+ }
+
+ /* f4 */
+ if (ik) {
+ /* rotate by r4 = 0x40 = 8 bytes */
+ for (i = 0; i < 16; i++)
+ tmp1[(i + 8) % 16] = tmp2[i] ^ opc[i];
+ tmp1[15] ^= 4; /* XOR c4 (= ..04) */
+ if (aes_128_encrypt_block(k, tmp1, ik))
+ return -1;
+ for (i = 0; i < 16; i++)
+ ik[i] ^= opc[i];
+ }
+
+ /* f5* */
+ if (akstar) {
+ /* rotate by r5 = 0x60 = 12 bytes */
+ for (i = 0; i < 16; i++)
+ tmp1[(i + 4) % 16] = tmp2[i] ^ opc[i];
+ tmp1[15] ^= 8; /* XOR c5 (= ..08) */
+ if (aes_128_encrypt_block(k, tmp1, tmp1))
+ return -1;
+ for (i = 0; i < 6; i++)
+ akstar[i] = tmp1[i] ^ opc[i];
+ }
+
+ return 0;
+}
+
+
+/**
+ * milenage_generate - Generate AKA AUTN,IK,CK,RES
+ * @opc: OPc = 128-bit operator variant algorithm configuration field (encr.)
+ * @amf: AMF = 16-bit authentication management field
+ * @k: K = 128-bit subscriber key
+ * @sqn: SQN = 48-bit sequence number
+ * @_rand: RAND = 128-bit random challenge
+ * @autn: Buffer for AUTN = 128-bit authentication token
+ * @ik: Buffer for IK = 128-bit integrity key (f4), or %NULL
+ * @ck: Buffer for CK = 128-bit confidentiality key (f3), or %NULL
+ * @res: Buffer for RES = 64-bit signed response (f2), or %NULL
+ * @res_len: Max length for res; set to used length or 0 on failure
+ */
+void milenage_generate(const u8 *opc, const u8 *amf, const u8 *k,
+ const u8 *sqn, const u8 *_rand, u8 *autn, u8 *ik,
+ u8 *ck, u8 *res, size_t *res_len)
+{
+ int i;
+ u8 mac_a[8], ak[6];
+
+ if (*res_len < 8) {
+ *res_len = 0;
+ return;
+ }
+ if (milenage_f1(opc, k, _rand, sqn, amf, mac_a, NULL) ||
+ milenage_f2345(opc, k, _rand, res, ck, ik, ak, NULL)) {
+ *res_len = 0;
+ return;
+ }
+ *res_len = 8;
+
+ /* AUTN = (SQN ^ AK) || AMF || MAC */
+ for (i = 0; i < 6; i++)
+ autn[i] = sqn[i] ^ ak[i];
+ os_memcpy(autn + 6, amf, 2);
+ os_memcpy(autn + 8, mac_a, 8);
+}
+
+
+/**
+ * milenage_auts - Milenage AUTS validation
+ * @opc: OPc = 128-bit operator variant algorithm configuration field (encr.)
+ * @k: K = 128-bit subscriber key
+ * @_rand: RAND = 128-bit random challenge
+ * @auts: AUTS = 112-bit authentication token from client
+ * @sqn: Buffer for SQN = 48-bit sequence number
+ * Returns: 0 = success (sqn filled), -1 on failure
+ */
+int milenage_auts(const u8 *opc, const u8 *k, const u8 *_rand, const u8 *auts,
+ u8 *sqn)
+{
+ u8 amf[2] = { 0x00, 0x00 }; /* TS 33.102 v7.0.0, 6.3.3 */
+ u8 ak[6], mac_s[8];
+ int i;
+
+ if (milenage_f2345(opc, k, _rand, NULL, NULL, NULL, NULL, ak))
+ return -1;
+ for (i = 0; i < 6; i++)
+ sqn[i] = auts[i] ^ ak[i];
+ if (milenage_f1(opc, k, _rand, sqn, amf, NULL, mac_s) ||
+ memcmp(mac_s, auts + 6, 8) != 0)
+ return -1;
+ return 0;
+}
+
+
+/**
+ * gsm_milenage - Generate GSM-Milenage (3GPP TS 55.205) authentication triplet
+ * @opc: OPc = 128-bit operator variant algorithm configuration field (encr.)
+ * @k: K = 128-bit subscriber key
+ * @_rand: RAND = 128-bit random challenge
+ * @sres: Buffer for SRES = 32-bit SRES
+ * @kc: Buffer for Kc = 64-bit Kc
+ * Returns: 0 on success, -1 on failure
+ */
+int gsm_milenage(const u8 *opc, const u8 *k, const u8 *_rand, u8 *sres, u8 *kc)
+{
+ u8 res[8], ck[16], ik[16];
+ int i;
+
+ if (milenage_f2345(opc, k, _rand, res, ck, ik, NULL, NULL))
+ return -1;
+
+ for (i = 0; i < 8; i++)
+ kc[i] = ck[i] ^ ck[i + 8] ^ ik[i] ^ ik[i + 8];
+
+#ifdef GSM_MILENAGE_ALT_SRES
+ os_memcpy(sres, res, 4);
+#else /* GSM_MILENAGE_ALT_SRES */
+ for (i = 0; i < 4; i++)
+ sres[i] = res[i] ^ res[i + 4];
+#endif /* GSM_MILENAGE_ALT_SRES */
+ return 0;
+}
+
+
+/**
+ * milenage_generate - Generate AKA AUTN,IK,CK,RES
+ * @opc: OPc = 128-bit operator variant algorithm configuration field (encr.)
+ * @k: K = 128-bit subscriber key
+ * @sqn: SQN = 48-bit sequence number
+ * @_rand: RAND = 128-bit random challenge
+ * @autn: AUTN = 128-bit authentication token
+ * @ik: Buffer for IK = 128-bit integrity key (f4), or %NULL
+ * @ck: Buffer for CK = 128-bit confidentiality key (f3), or %NULL
+ * @res: Buffer for RES = 64-bit signed response (f2), or %NULL
+ * @res_len: Variable that will be set to RES length
+ * @auts: 112-bit buffer for AUTS
+ * Returns: 0 on success, -1 on failure, or -2 on synchronization failure
+ */
+int milenage_check(const u8 *opc, const u8 *k, const u8 *sqn, const u8 *_rand,
+ const u8 *autn, u8 *ik, u8 *ck, u8 *res, size_t *res_len,
+ u8 *auts)
+{
+ int i;
+ u8 mac_a[8], ak[6], rx_sqn[6];
+ const u8 *amf;
+
+ wpa_hexdump(MSG_DEBUG, "Milenage: AUTN", autn, 16);
+ wpa_hexdump(MSG_DEBUG, "Milenage: RAND", _rand, 16);
+
+ if (milenage_f2345(opc, k, _rand, res, ck, ik, ak, NULL))
+ return -1;
+
+ *res_len = 8;
+ wpa_hexdump_key(MSG_DEBUG, "Milenage: RES", res, *res_len);
+ wpa_hexdump_key(MSG_DEBUG, "Milenage: CK", ck, 16);
+ wpa_hexdump_key(MSG_DEBUG, "Milenage: IK", ik, 16);
+ wpa_hexdump_key(MSG_DEBUG, "Milenage: AK", ak, 6);
+
+ /* AUTN = (SQN ^ AK) || AMF || MAC */
+ for (i = 0; i < 6; i++)
+ rx_sqn[i] = autn[i] ^ ak[i];
+ wpa_hexdump(MSG_DEBUG, "Milenage: SQN", rx_sqn, 6);
+
+ if (os_memcmp(rx_sqn, sqn, 6) <= 0) {
+ u8 auts_amf[2] = { 0x00, 0x00 }; /* TS 33.102 v7.0.0, 6.3.3 */
+ if (milenage_f2345(opc, k, _rand, NULL, NULL, NULL, NULL, ak))
+ return -1;
+ wpa_hexdump_key(MSG_DEBUG, "Milenage: AK*", ak, 6);
+ for (i = 0; i < 6; i++)
+ auts[i] = sqn[i] ^ ak[i];
+ if (milenage_f1(opc, k, _rand, sqn, auts_amf, NULL, auts + 6))
+ return -1;
+ wpa_hexdump(MSG_DEBUG, "Milenage: AUTS", auts, 14);
+ return -2;
+ }
+
+ amf = autn + 6;
+ wpa_hexdump(MSG_DEBUG, "Milenage: AMF", amf, 2);
+ if (milenage_f1(opc, k, _rand, rx_sqn, amf, mac_a, NULL))
+ return -1;
+
+ wpa_hexdump(MSG_DEBUG, "Milenage: MAC_A", mac_a, 8);
+
+ if (os_memcmp(mac_a, autn + 8, 8) != 0) {
+ wpa_printf(MSG_DEBUG, "Milenage: MAC mismatch");
+ wpa_hexdump(MSG_DEBUG, "Milenage: Received MAC_A",
+ autn + 8, 8);
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/contrib/wpa/src/hlr_auc_gw/milenage.h b/contrib/wpa/src/crypto/milenage.h
index b35603c..d5054d6 100644
--- a/contrib/wpa/src/hlr_auc_gw/milenage.h
+++ b/contrib/wpa/src/crypto/milenage.h
@@ -25,5 +25,9 @@ int gsm_milenage(const u8 *opc, const u8 *k, const u8 *_rand, u8 *sres,
int milenage_check(const u8 *opc, const u8 *k, const u8 *sqn, const u8 *_rand,
const u8 *autn, u8 *ik, u8 *ck, u8 *res, size_t *res_len,
u8 *auts);
+int milenage_f1(const u8 *opc, const u8 *k, const u8 *_rand,
+ const u8 *sqn, const u8 *amf, u8 *mac_a, u8 *mac_s);
+int milenage_f2345(const u8 *opc, const u8 *k, const u8 *_rand,
+ u8 *res, u8 *ck, u8 *ik, u8 *ak, u8 *akstar);
#endif /* MILENAGE_H */
diff --git a/contrib/wpa/src/crypto/ms_funcs.c b/contrib/wpa/src/crypto/ms_funcs.c
index 7e2f0fa..dae15ab 100644
--- a/contrib/wpa/src/crypto/ms_funcs.c
+++ b/contrib/wpa/src/crypto/ms_funcs.c
@@ -1,6 +1,6 @@
/*
* WPA Supplicant / shared MSCHAPV2 helper functions / RFC 2433 / RFC 2759
- * Copyright (c) 2004-2007, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -18,7 +18,6 @@
#include "sha1.h"
#include "ms_funcs.h"
#include "crypto.h"
-#include "rc4.h"
/**
@@ -28,10 +27,11 @@
* @username: 0-to-256-char UserName (IN)
* @username_len: Length of username
* @challenge: 8-octet Challenge (OUT)
+ * Returns: 0 on success, -1 on failure
*/
-static void challenge_hash(const u8 *peer_challenge, const u8 *auth_challenge,
- const u8 *username, size_t username_len,
- u8 *challenge)
+static int challenge_hash(const u8 *peer_challenge, const u8 *auth_challenge,
+ const u8 *username, size_t username_len,
+ u8 *challenge)
{
u8 hash[SHA1_MAC_LEN];
const unsigned char *addr[3];
@@ -44,8 +44,10 @@ static void challenge_hash(const u8 *peer_challenge, const u8 *auth_challenge,
addr[2] = username;
len[2] = username_len;
- sha1_vector(3, addr, len, hash);
+ if (sha1_vector(3, addr, len, hash))
+ return -1;
os_memcpy(challenge, hash, 8);
+ return 0;
}
@@ -54,8 +56,9 @@ static void challenge_hash(const u8 *peer_challenge, const u8 *auth_challenge,
* @password: 0-to-256-unicode-char Password (IN; ASCII)
* @password_len: Length of password
* @password_hash: 16-octet PasswordHash (OUT)
+ * Returns: 0 on success, -1 on failure
*/
-void nt_password_hash(const u8 *password, size_t password_len,
+int nt_password_hash(const u8 *password, size_t password_len,
u8 *password_hash)
{
u8 buf[512], *pos;
@@ -72,7 +75,7 @@ void nt_password_hash(const u8 *password, size_t password_len,
len = password_len * 2;
pos = buf;
- md4_vector(1, (const u8 **) &pos, &len, password_hash);
+ return md4_vector(1, (const u8 **) &pos, &len, password_hash);
}
@@ -80,11 +83,12 @@ void nt_password_hash(const u8 *password, size_t password_len,
* hash_nt_password_hash - HashNtPasswordHash() - RFC 2759, Sect. 8.4
* @password_hash: 16-octet PasswordHash (IN)
* @password_hash_hash: 16-octet PasswordHashHash (OUT)
+ * Returns: 0 on success, -1 on failure
*/
-void hash_nt_password_hash(const u8 *password_hash, u8 *password_hash_hash)
+int hash_nt_password_hash(const u8 *password_hash, u8 *password_hash_hash)
{
size_t len = 16;
- md4_vector(1, &password_hash, &len, password_hash_hash);
+ return md4_vector(1, &password_hash, &len, password_hash_hash);
}
@@ -116,19 +120,22 @@ void challenge_response(const u8 *challenge, const u8 *password_hash,
* @password: 0-to-256-unicode-char Password (IN; ASCII)
* @password_len: Length of password
* @response: 24-octet Response (OUT)
+ * Returns: 0 on success, -1 on failure
*/
-void generate_nt_response(const u8 *auth_challenge, const u8 *peer_challenge,
- const u8 *username, size_t username_len,
- const u8 *password, size_t password_len,
- u8 *response)
+int generate_nt_response(const u8 *auth_challenge, const u8 *peer_challenge,
+ const u8 *username, size_t username_len,
+ const u8 *password, size_t password_len,
+ u8 *response)
{
u8 challenge[8];
u8 password_hash[16];
challenge_hash(peer_challenge, auth_challenge, username, username_len,
challenge);
- nt_password_hash(password, password_len, password_hash);
+ if (nt_password_hash(password, password_len, password_hash))
+ return -1;
challenge_response(challenge, password_hash, response);
+ return 0;
}
@@ -140,18 +147,22 @@ void generate_nt_response(const u8 *auth_challenge, const u8 *peer_challenge,
* @username_len: Length of username
* @password_hash: 16-octet PasswordHash (IN)
* @response: 24-octet Response (OUT)
+ * Returns: 0 on success, -1 on failure
*/
-void generate_nt_response_pwhash(const u8 *auth_challenge,
- const u8 *peer_challenge,
- const u8 *username, size_t username_len,
- const u8 *password_hash,
- u8 *response)
+int generate_nt_response_pwhash(const u8 *auth_challenge,
+ const u8 *peer_challenge,
+ const u8 *username, size_t username_len,
+ const u8 *password_hash,
+ u8 *response)
{
u8 challenge[8];
- challenge_hash(peer_challenge, auth_challenge, username, username_len,
- challenge);
+ if (challenge_hash(peer_challenge, auth_challenge,
+ username, username_len,
+ challenge))
+ return -1;
challenge_response(challenge, password_hash, response);
+ return 0;
}
@@ -165,8 +176,9 @@ void generate_nt_response_pwhash(const u8 *auth_challenge,
* @username_len: Length of username
* @response: 20-octet AuthenticatorResponse (OUT) (note: this value is usually
* encoded as a 42-octet ASCII string (S=hexdump_of_response)
+ * Returns: 0 on success, -1 on failure
*/
-void generate_authenticator_response_pwhash(
+int generate_authenticator_response_pwhash(
const u8 *password_hash,
const u8 *peer_challenge, const u8 *auth_challenge,
const u8 *username, size_t username_len,
@@ -200,12 +212,14 @@ void generate_authenticator_response_pwhash(
addr2[1] = challenge;
addr2[2] = magic2;
- hash_nt_password_hash(password_hash, password_hash_hash);
- sha1_vector(3, addr1, len1, response);
+ if (hash_nt_password_hash(password_hash, password_hash_hash))
+ return -1;
+ if (sha1_vector(3, addr1, len1, response))
+ return -1;
challenge_hash(peer_challenge, auth_challenge, username, username_len,
challenge);
- sha1_vector(3, addr2, len2, response);
+ return sha1_vector(3, addr2, len2, response);
}
@@ -220,19 +234,20 @@ void generate_authenticator_response_pwhash(
* @username_len: Length of username
* @response: 20-octet AuthenticatorResponse (OUT) (note: this value is usually
* encoded as a 42-octet ASCII string (S=hexdump_of_response)
+ * Returns: 0 on success, -1 on failure
*/
-void generate_authenticator_response(const u8 *password, size_t password_len,
- const u8 *peer_challenge,
- const u8 *auth_challenge,
- const u8 *username, size_t username_len,
- const u8 *nt_response, u8 *response)
+int generate_authenticator_response(const u8 *password, size_t password_len,
+ const u8 *peer_challenge,
+ const u8 *auth_challenge,
+ const u8 *username, size_t username_len,
+ const u8 *nt_response, u8 *response)
{
u8 password_hash[16];
- nt_password_hash(password, password_len, password_hash);
- generate_authenticator_response_pwhash(password_hash,
- peer_challenge, auth_challenge,
- username, username_len,
- nt_response, response);
+ if (nt_password_hash(password, password_len, password_hash))
+ return -1;
+ return generate_authenticator_response_pwhash(
+ password_hash, peer_challenge, auth_challenge,
+ username, username_len, nt_response, response);
}
@@ -242,13 +257,16 @@ void generate_authenticator_response(const u8 *password, size_t password_len,
* @password: 0-to-256-unicode-char Password (IN; ASCII)
* @password_len: Length of password
* @response: 24-octet Response (OUT)
+ * Returns: 0 on success, -1 on failure
*/
-void nt_challenge_response(const u8 *challenge, const u8 *password,
- size_t password_len, u8 *response)
+int nt_challenge_response(const u8 *challenge, const u8 *password,
+ size_t password_len, u8 *response)
{
u8 password_hash[16];
- nt_password_hash(password, password_len, password_hash);
+ if (nt_password_hash(password, password_len, password_hash))
+ return -1;
challenge_response(challenge, password_hash, response);
+ return 0;
}
@@ -257,9 +275,10 @@ void nt_challenge_response(const u8 *challenge, const u8 *password,
* @password_hash_hash: 16-octet PasswordHashHash (IN)
* @nt_response: 24-octet NTResponse (IN)
* @master_key: 16-octet MasterKey (OUT)
+ * Returns: 0 on success, -1 on failure
*/
-void get_master_key(const u8 *password_hash_hash, const u8 *nt_response,
- u8 *master_key)
+int get_master_key(const u8 *password_hash_hash, const u8 *nt_response,
+ u8 *master_key)
{
static const u8 magic1[27] = {
0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x74,
@@ -274,8 +293,10 @@ void get_master_key(const u8 *password_hash_hash, const u8 *nt_response,
addr[1] = nt_response;
addr[2] = magic1;
- sha1_vector(3, addr, len, hash);
+ if (sha1_vector(3, addr, len, hash))
+ return -1;
os_memcpy(master_key, hash, 16);
+ return 0;
}
@@ -286,10 +307,11 @@ void get_master_key(const u8 *password_hash_hash, const u8 *nt_response,
* @session_key_len: SessionKeyLength (Length of session_key) (IN)
* @is_send: IsSend (IN, BOOLEAN)
* @is_server: IsServer (IN, BOOLEAN)
+ * Returns: 0 on success, -1 on failure
*/
-void get_asymetric_start_key(const u8 *master_key, u8 *session_key,
- size_t session_key_len, int is_send,
- int is_server)
+int get_asymetric_start_key(const u8 *master_key, u8 *session_key,
+ size_t session_key_len, int is_send,
+ int is_server)
{
static const u8 magic2[84] = {
0x4f, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x69,
@@ -339,11 +361,13 @@ void get_asymetric_start_key(const u8 *master_key, u8 *session_key,
}
addr[3] = shs_pad2;
- sha1_vector(4, addr, len, digest);
+ if (sha1_vector(4, addr, len, digest))
+ return -1;
if (session_key_len > SHA1_MAC_LEN)
session_key_len = SHA1_MAC_LEN;
os_memcpy(session_key, digest, session_key_len);
+ return 0;
}
@@ -400,7 +424,8 @@ int new_password_encrypted_with_old_nt_password_hash(
{
u8 password_hash[16];
- nt_password_hash(old_password, old_password_len, password_hash);
+ if (nt_password_hash(old_password, old_password_len, password_hash))
+ return -1;
if (encrypt_pw_block_with_password_hash(new_password, new_password_len,
password_hash,
encrypted_pw_block))
@@ -430,17 +455,22 @@ void nt_password_hash_encrypted_with_block(const u8 *password_hash,
* @old_password: 0-to-256-unicode-char OldPassword (IN; ASCII)
* @old_password_len: Length of old_password
* @encrypted_password_hash: 16-octet EncryptedPasswordHash (OUT)
+ * Returns: 0 on success, -1 on failure
*/
-void old_nt_password_hash_encrypted_with_new_nt_password_hash(
+int old_nt_password_hash_encrypted_with_new_nt_password_hash(
const u8 *new_password, size_t new_password_len,
const u8 *old_password, size_t old_password_len,
u8 *encrypted_password_hash)
{
u8 old_password_hash[16], new_password_hash[16];
- nt_password_hash(old_password, old_password_len, old_password_hash);
- nt_password_hash(new_password, new_password_len, new_password_hash);
+ if (nt_password_hash(old_password, old_password_len,
+ old_password_hash) ||
+ nt_password_hash(new_password, new_password_len,
+ new_password_hash))
+ return -1;
nt_password_hash_encrypted_with_block(old_password_hash,
new_password_hash,
encrypted_password_hash);
+ return 0;
}
diff --git a/contrib/wpa/src/crypto/ms_funcs.h b/contrib/wpa/src/crypto/ms_funcs.h
index 6205bf6..298dbcf 100644
--- a/contrib/wpa/src/crypto/ms_funcs.h
+++ b/contrib/wpa/src/crypto/ms_funcs.h
@@ -1,6 +1,6 @@
/*
* WPA Supplicant / shared MSCHAPV2 helper functions / RFC 2433 / RFC 2759
- * Copyright (c) 2004-2007, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -15,38 +15,38 @@
#ifndef MS_FUNCS_H
#define MS_FUNCS_H
-void generate_nt_response(const u8 *auth_challenge, const u8 *peer_challenge,
- const u8 *username, size_t username_len,
- const u8 *password, size_t password_len,
- u8 *response);
-void generate_nt_response_pwhash(const u8 *auth_challenge,
- const u8 *peer_challenge,
- const u8 *username, size_t username_len,
- const u8 *password_hash,
- u8 *response);
-void generate_authenticator_response(const u8 *password, size_t password_len,
- const u8 *peer_challenge,
- const u8 *auth_challenge,
- const u8 *username, size_t username_len,
- const u8 *nt_response, u8 *response);
-void generate_authenticator_response_pwhash(
+int generate_nt_response(const u8 *auth_challenge, const u8 *peer_challenge,
+ const u8 *username, size_t username_len,
+ const u8 *password, size_t password_len,
+ u8 *response);
+int generate_nt_response_pwhash(const u8 *auth_challenge,
+ const u8 *peer_challenge,
+ const u8 *username, size_t username_len,
+ const u8 *password_hash,
+ u8 *response);
+int generate_authenticator_response(const u8 *password, size_t password_len,
+ const u8 *peer_challenge,
+ const u8 *auth_challenge,
+ const u8 *username, size_t username_len,
+ const u8 *nt_response, u8 *response);
+int generate_authenticator_response_pwhash(
const u8 *password_hash,
const u8 *peer_challenge, const u8 *auth_challenge,
const u8 *username, size_t username_len,
const u8 *nt_response, u8 *response);
-void nt_challenge_response(const u8 *challenge, const u8 *password,
- size_t password_len, u8 *response);
+int nt_challenge_response(const u8 *challenge, const u8 *password,
+ size_t password_len, u8 *response);
void challenge_response(const u8 *challenge, const u8 *password_hash,
u8 *response);
-void nt_password_hash(const u8 *password, size_t password_len,
- u8 *password_hash);
-void hash_nt_password_hash(const u8 *password_hash, u8 *password_hash_hash);
-void get_master_key(const u8 *password_hash_hash, const u8 *nt_response,
- u8 *master_key);
-void get_asymetric_start_key(const u8 *master_key, u8 *session_key,
- size_t session_key_len, int is_send,
- int is_server);
+int nt_password_hash(const u8 *password, size_t password_len,
+ u8 *password_hash);
+int hash_nt_password_hash(const u8 *password_hash, u8 *password_hash_hash);
+int get_master_key(const u8 *password_hash_hash, const u8 *nt_response,
+ u8 *master_key);
+int get_asymetric_start_key(const u8 *master_key, u8 *session_key,
+ size_t session_key_len, int is_send,
+ int is_server);
int __must_check encrypt_pw_block_with_password_hash(
const u8 *password, size_t password_len,
const u8 *password_hash, u8 *pw_block);
@@ -56,7 +56,7 @@ int __must_check new_password_encrypted_with_old_nt_password_hash(
u8 *encrypted_pw_block);
void nt_password_hash_encrypted_with_block(const u8 *password_hash,
const u8 *block, u8 *cypher);
-void old_nt_password_hash_encrypted_with_new_nt_password_hash(
+int old_nt_password_hash_encrypted_with_new_nt_password_hash(
const u8 *new_password, size_t new_password_len,
const u8 *old_password, size_t old_password_len,
u8 *encrypted_password_hash);
diff --git a/contrib/wpa/src/crypto/rc4.c b/contrib/wpa/src/crypto/rc4.c
index 70c790e..5ab1be1 100644
--- a/contrib/wpa/src/crypto/rc4.c
+++ b/contrib/wpa/src/crypto/rc4.c
@@ -15,24 +15,12 @@
#include "includes.h"
#include "common.h"
-#include "rc4.h"
+#include "crypto.h"
#define S_SWAP(a,b) do { u8 t = S[a]; S[a] = S[b]; S[b] = t; } while(0)
-/**
- * rc4 - XOR RC4 stream to given data with skip-stream-start
- * @key: RC4 key
- * @keylen: RC4 key length
- * @skip: number of bytes to skip from the beginning of the RC4 stream
- * @data: data to be XOR'ed with RC4 stream
- * @data_len: buf length
- *
- * Generate RC4 pseudo random stream for the given key, skip beginning of the
- * stream, and XOR the end result with the data buffer to perform RC4
- * encryption/decryption.
- */
-void rc4_skip(const u8 *key, size_t keylen, size_t skip,
- u8 *data, size_t data_len)
+int rc4_skip(const u8 *key, size_t keylen, size_t skip,
+ u8 *data, size_t data_len)
{
u32 i, j, k;
u8 S[256], *pos;
@@ -67,4 +55,6 @@ void rc4_skip(const u8 *key, size_t keylen, size_t skip,
S_SWAP(i, j);
*pos++ ^= S[(S[i] + S[j]) & 0xff];
}
+
+ return 0;
}
diff --git a/contrib/wpa/src/crypto/sha1-internal.c b/contrib/wpa/src/crypto/sha1-internal.c
new file mode 100644
index 0000000..3f05ca1
--- /dev/null
+++ b/contrib/wpa/src/crypto/sha1-internal.c
@@ -0,0 +1,308 @@
+/*
+ * SHA1 hash implementation and interface functions
+ * Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "sha1.h"
+#include "sha1_i.h"
+#include "md5.h"
+#include "crypto.h"
+
+typedef struct SHA1Context SHA1_CTX;
+
+void SHA1Transform(u32 state[5], const unsigned char buffer[64]);
+
+
+/**
+ * sha1_vector - SHA-1 hash for data vector
+ * @num_elem: Number of elements in the data vector
+ * @addr: Pointers to the data areas
+ * @len: Lengths of the data blocks
+ * @mac: Buffer for the hash
+ * Returns: 0 on success, -1 of failure
+ */
+int sha1_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
+{
+ SHA1_CTX ctx;
+ size_t i;
+
+ SHA1Init(&ctx);
+ for (i = 0; i < num_elem; i++)
+ SHA1Update(&ctx, addr[i], len[i]);
+ SHA1Final(mac, &ctx);
+ return 0;
+}
+
+
+/* ===== start - public domain SHA1 implementation ===== */
+
+/*
+SHA-1 in C
+By Steve Reid <sreid@sea-to-sky.net>
+100% Public Domain
+
+-----------------
+Modified 7/98
+By James H. Brown <jbrown@burgoyne.com>
+Still 100% Public Domain
+
+Corrected a problem which generated improper hash values on 16 bit machines
+Routine SHA1Update changed from
+ void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int
+len)
+to
+ void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned
+long len)
+
+The 'len' parameter was declared an int which works fine on 32 bit machines.
+However, on 16 bit machines an int is too small for the shifts being done
+against
+it. This caused the hash function to generate incorrect values if len was
+greater than 8191 (8K - 1) due to the 'len << 3' on line 3 of SHA1Update().
+
+Since the file IO in main() reads 16K at a time, any file 8K or larger would
+be guaranteed to generate the wrong hash (e.g. Test Vector #3, a million
+"a"s).
+
+I also changed the declaration of variables i & j in SHA1Update to
+unsigned long from unsigned int for the same reason.
+
+These changes should make no difference to any 32 bit implementations since
+an
+int and a long are the same size in those environments.
+
+--
+I also corrected a few compiler warnings generated by Borland C.
+1. Added #include <process.h> for exit() prototype
+2. Removed unused variable 'j' in SHA1Final
+3. Changed exit(0) to return(0) at end of main.
+
+ALL changes I made can be located by searching for comments containing 'JHB'
+-----------------
+Modified 8/98
+By Steve Reid <sreid@sea-to-sky.net>
+Still 100% public domain
+
+1- Removed #include <process.h> and used return() instead of exit()
+2- Fixed overwriting of finalcount in SHA1Final() (discovered by Chris Hall)
+3- Changed email address from steve@edmweb.com to sreid@sea-to-sky.net
+
+-----------------
+Modified 4/01
+By Saul Kravitz <Saul.Kravitz@celera.com>
+Still 100% PD
+Modified to run on Compaq Alpha hardware.
+
+-----------------
+Modified 4/01
+By Jouni Malinen <j@w1.fi>
+Minor changes to match the coding style used in Dynamics.
+
+Modified September 24, 2004
+By Jouni Malinen <j@w1.fi>
+Fixed alignment issue in SHA1Transform when SHA1HANDSOFF is defined.
+
+*/
+
+/*
+Test Vectors (from FIPS PUB 180-1)
+"abc"
+ A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
+"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
+ 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
+A million repetitions of "a"
+ 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
+*/
+
+#define SHA1HANDSOFF
+
+#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
+
+/* blk0() and blk() perform the initial expand. */
+/* I got the idea of expanding during the round function from SSLeay */
+#ifndef WORDS_BIGENDIAN
+#define blk0(i) (block->l[i] = (rol(block->l[i], 24) & 0xFF00FF00) | \
+ (rol(block->l[i], 8) & 0x00FF00FF))
+#else
+#define blk0(i) block->l[i]
+#endif
+#define blk(i) (block->l[i & 15] = rol(block->l[(i + 13) & 15] ^ \
+ block->l[(i + 8) & 15] ^ block->l[(i + 2) & 15] ^ block->l[i & 15], 1))
+
+/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
+#define R0(v,w,x,y,z,i) \
+ z += ((w & (x ^ y)) ^ y) + blk0(i) + 0x5A827999 + rol(v, 5); \
+ w = rol(w, 30);
+#define R1(v,w,x,y,z,i) \
+ z += ((w & (x ^ y)) ^ y) + blk(i) + 0x5A827999 + rol(v, 5); \
+ w = rol(w, 30);
+#define R2(v,w,x,y,z,i) \
+ z += (w ^ x ^ y) + blk(i) + 0x6ED9EBA1 + rol(v, 5); w = rol(w, 30);
+#define R3(v,w,x,y,z,i) \
+ z += (((w | x) & y) | (w & x)) + blk(i) + 0x8F1BBCDC + rol(v, 5); \
+ w = rol(w, 30);
+#define R4(v,w,x,y,z,i) \
+ z += (w ^ x ^ y) + blk(i) + 0xCA62C1D6 + rol(v, 5); \
+ w=rol(w, 30);
+
+
+#ifdef VERBOSE /* SAK */
+void SHAPrintContext(SHA1_CTX *context, char *msg)
+{
+ printf("%s (%d,%d) %x %x %x %x %x\n",
+ msg,
+ context->count[0], context->count[1],
+ context->state[0],
+ context->state[1],
+ context->state[2],
+ context->state[3],
+ context->state[4]);
+}
+#endif
+
+/* Hash a single 512-bit block. This is the core of the algorithm. */
+
+void SHA1Transform(u32 state[5], const unsigned char buffer[64])
+{
+ u32 a, b, c, d, e;
+ typedef union {
+ unsigned char c[64];
+ u32 l[16];
+ } CHAR64LONG16;
+ CHAR64LONG16* block;
+#ifdef SHA1HANDSOFF
+ CHAR64LONG16 workspace;
+ block = &workspace;
+ os_memcpy(block, buffer, 64);
+#else
+ block = (CHAR64LONG16 *) buffer;
+#endif
+ /* Copy context->state[] to working vars */
+ a = state[0];
+ b = state[1];
+ c = state[2];
+ d = state[3];
+ e = state[4];
+ /* 4 rounds of 20 operations each. Loop unrolled. */
+ R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
+ R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
+ R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
+ R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
+ R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
+ R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
+ R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
+ R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
+ R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
+ R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
+ R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
+ R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
+ R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
+ R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
+ R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
+ R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
+ R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
+ R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
+ R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
+ R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
+ /* Add the working vars back into context.state[] */
+ state[0] += a;
+ state[1] += b;
+ state[2] += c;
+ state[3] += d;
+ state[4] += e;
+ /* Wipe variables */
+ a = b = c = d = e = 0;
+#ifdef SHA1HANDSOFF
+ os_memset(block, 0, 64);
+#endif
+}
+
+
+/* SHA1Init - Initialize new context */
+
+void SHA1Init(SHA1_CTX* context)
+{
+ /* SHA1 initialization constants */
+ context->state[0] = 0x67452301;
+ context->state[1] = 0xEFCDAB89;
+ context->state[2] = 0x98BADCFE;
+ context->state[3] = 0x10325476;
+ context->state[4] = 0xC3D2E1F0;
+ context->count[0] = context->count[1] = 0;
+}
+
+
+/* Run your data through this. */
+
+void SHA1Update(SHA1_CTX* context, const void *_data, u32 len)
+{
+ u32 i, j;
+ const unsigned char *data = _data;
+
+#ifdef VERBOSE
+ SHAPrintContext(context, "before");
+#endif
+ j = (context->count[0] >> 3) & 63;
+ if ((context->count[0] += len << 3) < (len << 3))
+ context->count[1]++;
+ context->count[1] += (len >> 29);
+ if ((j + len) > 63) {
+ os_memcpy(&context->buffer[j], data, (i = 64-j));
+ SHA1Transform(context->state, context->buffer);
+ for ( ; i + 63 < len; i += 64) {
+ SHA1Transform(context->state, &data[i]);
+ }
+ j = 0;
+ }
+ else i = 0;
+ os_memcpy(&context->buffer[j], &data[i], len - i);
+#ifdef VERBOSE
+ SHAPrintContext(context, "after ");
+#endif
+}
+
+
+/* Add padding and return the message digest. */
+
+void SHA1Final(unsigned char digest[20], SHA1_CTX* context)
+{
+ u32 i;
+ unsigned char finalcount[8];
+
+ for (i = 0; i < 8; i++) {
+ finalcount[i] = (unsigned char)
+ ((context->count[(i >= 4 ? 0 : 1)] >>
+ ((3-(i & 3)) * 8) ) & 255); /* Endian independent */
+ }
+ SHA1Update(context, (unsigned char *) "\200", 1);
+ while ((context->count[0] & 504) != 448) {
+ SHA1Update(context, (unsigned char *) "\0", 1);
+ }
+ SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform()
+ */
+ for (i = 0; i < 20; i++) {
+ digest[i] = (unsigned char)
+ ((context->state[i >> 2] >> ((3 - (i & 3)) * 8)) &
+ 255);
+ }
+ /* Wipe variables */
+ i = 0;
+ os_memset(context->buffer, 0, 64);
+ os_memset(context->state, 0, 20);
+ os_memset(context->count, 0, 8);
+ os_memset(finalcount, 0, 8);
+}
+
+/* ===== end - public domain SHA1 implementation ===== */
diff --git a/contrib/wpa/src/crypto/sha1-pbkdf2.c b/contrib/wpa/src/crypto/sha1-pbkdf2.c
new file mode 100644
index 0000000..11323de
--- /dev/null
+++ b/contrib/wpa/src/crypto/sha1-pbkdf2.c
@@ -0,0 +1,100 @@
+/*
+ * SHA1-based key derivation function (PBKDF2) for IEEE 802.11i
+ * Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "sha1.h"
+#include "md5.h"
+#include "crypto.h"
+
+static int pbkdf2_sha1_f(const char *passphrase, const char *ssid,
+ size_t ssid_len, int iterations, unsigned int count,
+ u8 *digest)
+{
+ unsigned char tmp[SHA1_MAC_LEN], tmp2[SHA1_MAC_LEN];
+ int i, j;
+ unsigned char count_buf[4];
+ const u8 *addr[2];
+ size_t len[2];
+ size_t passphrase_len = os_strlen(passphrase);
+
+ addr[0] = (u8 *) ssid;
+ len[0] = ssid_len;
+ addr[1] = count_buf;
+ len[1] = 4;
+
+ /* F(P, S, c, i) = U1 xor U2 xor ... Uc
+ * U1 = PRF(P, S || i)
+ * U2 = PRF(P, U1)
+ * Uc = PRF(P, Uc-1)
+ */
+
+ count_buf[0] = (count >> 24) & 0xff;
+ count_buf[1] = (count >> 16) & 0xff;
+ count_buf[2] = (count >> 8) & 0xff;
+ count_buf[3] = count & 0xff;
+ if (hmac_sha1_vector((u8 *) passphrase, passphrase_len, 2, addr, len,
+ tmp))
+ return -1;
+ os_memcpy(digest, tmp, SHA1_MAC_LEN);
+
+ for (i = 1; i < iterations; i++) {
+ if (hmac_sha1((u8 *) passphrase, passphrase_len, tmp,
+ SHA1_MAC_LEN, tmp2))
+ return -1;
+ os_memcpy(tmp, tmp2, SHA1_MAC_LEN);
+ for (j = 0; j < SHA1_MAC_LEN; j++)
+ digest[j] ^= tmp2[j];
+ }
+
+ return 0;
+}
+
+
+/**
+ * pbkdf2_sha1 - SHA1-based key derivation function (PBKDF2) for IEEE 802.11i
+ * @passphrase: ASCII passphrase
+ * @ssid: SSID
+ * @ssid_len: SSID length in bytes
+ * @iterations: Number of iterations to run
+ * @buf: Buffer for the generated key
+ * @buflen: Length of the buffer in bytes
+ * Returns: 0 on success, -1 of failure
+ *
+ * This function is used to derive PSK for WPA-PSK. For this protocol,
+ * iterations is set to 4096 and buflen to 32. This function is described in
+ * IEEE Std 802.11-2004, Clause H.4. The main construction is from PKCS#5 v2.0.
+ */
+int pbkdf2_sha1(const char *passphrase, const char *ssid, size_t ssid_len,
+ int iterations, u8 *buf, size_t buflen)
+{
+ unsigned int count = 0;
+ unsigned char *pos = buf;
+ size_t left = buflen, plen;
+ unsigned char digest[SHA1_MAC_LEN];
+
+ while (left > 0) {
+ count++;
+ if (pbkdf2_sha1_f(passphrase, ssid, ssid_len, iterations,
+ count, digest))
+ return -1;
+ plen = left > SHA1_MAC_LEN ? SHA1_MAC_LEN : left;
+ os_memcpy(pos, digest, plen);
+ pos += plen;
+ left -= plen;
+ }
+
+ return 0;
+}
diff --git a/contrib/wpa/src/crypto/sha1-tlsprf.c b/contrib/wpa/src/crypto/sha1-tlsprf.c
new file mode 100644
index 0000000..2c8c029
--- /dev/null
+++ b/contrib/wpa/src/crypto/sha1-tlsprf.c
@@ -0,0 +1,109 @@
+/*
+ * TLS PRF (SHA1 + MD5)
+ * Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "sha1.h"
+#include "md5.h"
+#include "crypto.h"
+
+
+/**
+ * tls_prf - Pseudo-Random Function for TLS (TLS-PRF, RFC 2246)
+ * @secret: Key for PRF
+ * @secret_len: Length of the key in bytes
+ * @label: A unique label for each purpose of the PRF
+ * @seed: Seed value to bind into the key
+ * @seed_len: Length of the seed
+ * @out: Buffer for the generated pseudo-random key
+ * @outlen: Number of bytes of key to generate
+ * Returns: 0 on success, -1 on failure.
+ *
+ * This function is used to derive new, cryptographically separate keys from a
+ * given key in TLS. This PRF is defined in RFC 2246, Chapter 5.
+ */
+int tls_prf(const u8 *secret, size_t secret_len, const char *label,
+ const u8 *seed, size_t seed_len, u8 *out, size_t outlen)
+{
+ size_t L_S1, L_S2, i;
+ const u8 *S1, *S2;
+ u8 A_MD5[MD5_MAC_LEN], A_SHA1[SHA1_MAC_LEN];
+ u8 P_MD5[MD5_MAC_LEN], P_SHA1[SHA1_MAC_LEN];
+ int MD5_pos, SHA1_pos;
+ const u8 *MD5_addr[3];
+ size_t MD5_len[3];
+ const unsigned char *SHA1_addr[3];
+ size_t SHA1_len[3];
+
+ if (secret_len & 1)
+ return -1;
+
+ MD5_addr[0] = A_MD5;
+ MD5_len[0] = MD5_MAC_LEN;
+ MD5_addr[1] = (unsigned char *) label;
+ MD5_len[1] = os_strlen(label);
+ MD5_addr[2] = seed;
+ MD5_len[2] = seed_len;
+
+ SHA1_addr[0] = A_SHA1;
+ SHA1_len[0] = SHA1_MAC_LEN;
+ SHA1_addr[1] = (unsigned char *) label;
+ SHA1_len[1] = os_strlen(label);
+ SHA1_addr[2] = seed;
+ SHA1_len[2] = seed_len;
+
+ /* RFC 2246, Chapter 5
+ * A(0) = seed, A(i) = HMAC(secret, A(i-1))
+ * P_hash = HMAC(secret, A(1) + seed) + HMAC(secret, A(2) + seed) + ..
+ * PRF = P_MD5(S1, label + seed) XOR P_SHA-1(S2, label + seed)
+ */
+
+ L_S1 = L_S2 = (secret_len + 1) / 2;
+ S1 = secret;
+ S2 = secret + L_S1;
+ if (secret_len & 1) {
+ /* The last byte of S1 will be shared with S2 */
+ S2--;
+ }
+
+ hmac_md5_vector_non_fips_allow(S1, L_S1, 2, &MD5_addr[1], &MD5_len[1],
+ A_MD5);
+ hmac_sha1_vector(S2, L_S2, 2, &SHA1_addr[1], &SHA1_len[1], A_SHA1);
+
+ MD5_pos = MD5_MAC_LEN;
+ SHA1_pos = SHA1_MAC_LEN;
+ for (i = 0; i < outlen; i++) {
+ if (MD5_pos == MD5_MAC_LEN) {
+ hmac_md5_vector_non_fips_allow(S1, L_S1, 3, MD5_addr,
+ MD5_len, P_MD5);
+ MD5_pos = 0;
+ hmac_md5_non_fips_allow(S1, L_S1, A_MD5, MD5_MAC_LEN,
+ A_MD5);
+ }
+ if (SHA1_pos == SHA1_MAC_LEN) {
+ hmac_sha1_vector(S2, L_S2, 3, SHA1_addr, SHA1_len,
+ P_SHA1);
+ SHA1_pos = 0;
+ hmac_sha1(S2, L_S2, A_SHA1, SHA1_MAC_LEN, A_SHA1);
+ }
+
+ out[i] = P_MD5[MD5_pos] ^ P_SHA1[SHA1_pos];
+
+ MD5_pos++;
+ SHA1_pos++;
+ }
+
+ return 0;
+}
diff --git a/contrib/wpa/src/crypto/sha1-tprf.c b/contrib/wpa/src/crypto/sha1-tprf.c
new file mode 100644
index 0000000..4a80e96
--- /dev/null
+++ b/contrib/wpa/src/crypto/sha1-tprf.c
@@ -0,0 +1,76 @@
+/*
+ * SHA1 T-PRF for EAP-FAST
+ * Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "sha1.h"
+#include "crypto.h"
+
+/**
+ * sha1_t_prf - EAP-FAST Pseudo-Random Function (T-PRF)
+ * @key: Key for PRF
+ * @key_len: Length of the key in bytes
+ * @label: A unique label for each purpose of the PRF
+ * @seed: Seed value to bind into the key
+ * @seed_len: Length of the seed
+ * @buf: Buffer for the generated pseudo-random key
+ * @buf_len: Number of bytes of key to generate
+ * Returns: 0 on success, -1 of failure
+ *
+ * This function is used to derive new, cryptographically separate keys from a
+ * given key for EAP-FAST. T-PRF is defined in RFC 4851, Section 5.5.
+ */
+int sha1_t_prf(const u8 *key, size_t key_len, const char *label,
+ const u8 *seed, size_t seed_len, u8 *buf, size_t buf_len)
+{
+ unsigned char counter = 0;
+ size_t pos, plen;
+ u8 hash[SHA1_MAC_LEN];
+ size_t label_len = os_strlen(label);
+ u8 output_len[2];
+ const unsigned char *addr[5];
+ size_t len[5];
+
+ addr[0] = hash;
+ len[0] = 0;
+ addr[1] = (unsigned char *) label;
+ len[1] = label_len + 1;
+ addr[2] = seed;
+ len[2] = seed_len;
+ addr[3] = output_len;
+ len[3] = 2;
+ addr[4] = &counter;
+ len[4] = 1;
+
+ output_len[0] = (buf_len >> 8) & 0xff;
+ output_len[1] = buf_len & 0xff;
+ pos = 0;
+ while (pos < buf_len) {
+ counter++;
+ plen = buf_len - pos;
+ if (hmac_sha1_vector(key, key_len, 5, addr, len, hash))
+ return -1;
+ if (plen >= SHA1_MAC_LEN) {
+ os_memcpy(&buf[pos], hash, SHA1_MAC_LEN);
+ pos += SHA1_MAC_LEN;
+ } else {
+ os_memcpy(&buf[pos], hash, plen);
+ break;
+ }
+ len[0] = SHA1_MAC_LEN;
+ }
+
+ return 0;
+}
diff --git a/contrib/wpa/src/crypto/sha1.c b/contrib/wpa/src/crypto/sha1.c
index 141e4f4..fe00bdb 100644
--- a/contrib/wpa/src/crypto/sha1.c
+++ b/contrib/wpa/src/crypto/sha1.c
@@ -16,7 +16,6 @@
#include "common.h"
#include "sha1.h"
-#include "md5.h"
#include "crypto.h"
@@ -28,9 +27,10 @@
* @addr: Pointers to the data areas
* @len: Lengths of the data blocks
* @mac: Buffer for the hash (20 bytes)
+ * Returns: 0 on success, -1 on failure
*/
-void hmac_sha1_vector(const u8 *key, size_t key_len, size_t num_elem,
- const u8 *addr[], const size_t *len, u8 *mac)
+int hmac_sha1_vector(const u8 *key, size_t key_len, size_t num_elem,
+ const u8 *addr[], const size_t *len, u8 *mac)
{
unsigned char k_pad[64]; /* padding - key XORd with ipad/opad */
unsigned char tk[20];
@@ -42,12 +42,13 @@ void hmac_sha1_vector(const u8 *key, size_t key_len, size_t num_elem,
* Fixed limit on the number of fragments to avoid having to
* allocate memory (which could fail).
*/
- return;
+ return -1;
}
/* if key is longer than 64 bytes reset it to key = SHA1(key) */
if (key_len > 64) {
- sha1_vector(1, &key, &key_len, tk);
+ if (sha1_vector(1, &key, &key_len, tk))
+ return -1;
key = tk;
key_len = 20;
}
@@ -75,7 +76,8 @@ void hmac_sha1_vector(const u8 *key, size_t key_len, size_t num_elem,
_addr[i + 1] = addr[i];
_len[i + 1] = len[i];
}
- sha1_vector(1 + num_elem, _addr, _len, mac);
+ if (sha1_vector(1 + num_elem, _addr, _len, mac))
+ return -1;
os_memset(k_pad, 0, sizeof(k_pad));
os_memcpy(k_pad, key, key_len);
@@ -88,7 +90,7 @@ void hmac_sha1_vector(const u8 *key, size_t key_len, size_t num_elem,
_len[0] = 64;
_addr[1] = mac;
_len[1] = SHA1_MAC_LEN;
- sha1_vector(2, _addr, _len, mac);
+ return sha1_vector(2, _addr, _len, mac);
}
@@ -99,11 +101,12 @@ void hmac_sha1_vector(const u8 *key, size_t key_len, size_t num_elem,
* @data: Pointers to the data area
* @data_len: Length of the data area
* @mac: Buffer for the hash (20 bytes)
+ * Returns: 0 on success, -1 of failure
*/
-void hmac_sha1(const u8 *key, size_t key_len, const u8 *data, size_t data_len,
+int hmac_sha1(const u8 *key, size_t key_len, const u8 *data, size_t data_len,
u8 *mac)
{
- hmac_sha1_vector(key, key_len, 1, &data, &data_len, mac);
+ return hmac_sha1_vector(key, key_len, 1, &data, &data_len, mac);
}
@@ -116,12 +119,13 @@ void hmac_sha1(const u8 *key, size_t key_len, const u8 *data, size_t data_len,
* @data_len: Length of the data
* @buf: Buffer for the generated pseudo-random key
* @buf_len: Number of bytes of key to generate
+ * Returns: 0 on success, -1 of failure
*
* This function is used to derive new, cryptographically separate keys from a
* given key (e.g., PMK in IEEE 802.11i).
*/
-void sha1_prf(const u8 *key, size_t key_len, const char *label,
- const u8 *data, size_t data_len, u8 *buf, size_t buf_len)
+int sha1_prf(const u8 *key, size_t key_len, const char *label,
+ const u8 *data, size_t data_len, u8 *buf, size_t buf_len)
{
u8 counter = 0;
size_t pos, plen;
@@ -141,593 +145,19 @@ void sha1_prf(const u8 *key, size_t key_len, const char *label,
while (pos < buf_len) {
plen = buf_len - pos;
if (plen >= SHA1_MAC_LEN) {
- hmac_sha1_vector(key, key_len, 3, addr, len,
- &buf[pos]);
+ if (hmac_sha1_vector(key, key_len, 3, addr, len,
+ &buf[pos]))
+ return -1;
pos += SHA1_MAC_LEN;
} else {
- hmac_sha1_vector(key, key_len, 3, addr, len,
- hash);
+ if (hmac_sha1_vector(key, key_len, 3, addr, len,
+ hash))
+ return -1;
os_memcpy(&buf[pos], hash, plen);
break;
}
counter++;
}
-}
-
-
-#ifndef CONFIG_NO_T_PRF
-/**
- * sha1_t_prf - EAP-FAST Pseudo-Random Function (T-PRF)
- * @key: Key for PRF
- * @key_len: Length of the key in bytes
- * @label: A unique label for each purpose of the PRF
- * @seed: Seed value to bind into the key
- * @seed_len: Length of the seed
- * @buf: Buffer for the generated pseudo-random key
- * @buf_len: Number of bytes of key to generate
- *
- * This function is used to derive new, cryptographically separate keys from a
- * given key for EAP-FAST. T-PRF is defined in RFC 4851, Section 5.5.
- */
-void sha1_t_prf(const u8 *key, size_t key_len, const char *label,
- const u8 *seed, size_t seed_len, u8 *buf, size_t buf_len)
-{
- unsigned char counter = 0;
- size_t pos, plen;
- u8 hash[SHA1_MAC_LEN];
- size_t label_len = os_strlen(label);
- u8 output_len[2];
- const unsigned char *addr[5];
- size_t len[5];
-
- addr[0] = hash;
- len[0] = 0;
- addr[1] = (unsigned char *) label;
- len[1] = label_len + 1;
- addr[2] = seed;
- len[2] = seed_len;
- addr[3] = output_len;
- len[3] = 2;
- addr[4] = &counter;
- len[4] = 1;
-
- output_len[0] = (buf_len >> 8) & 0xff;
- output_len[1] = buf_len & 0xff;
- pos = 0;
- while (pos < buf_len) {
- counter++;
- plen = buf_len - pos;
- hmac_sha1_vector(key, key_len, 5, addr, len, hash);
- if (plen >= SHA1_MAC_LEN) {
- os_memcpy(&buf[pos], hash, SHA1_MAC_LEN);
- pos += SHA1_MAC_LEN;
- } else {
- os_memcpy(&buf[pos], hash, plen);
- break;
- }
- len[0] = SHA1_MAC_LEN;
- }
-}
-#endif /* CONFIG_NO_T_PRF */
-
-
-#ifndef CONFIG_NO_TLS_PRF
-/**
- * tls_prf - Pseudo-Random Function for TLS (TLS-PRF, RFC 2246)
- * @secret: Key for PRF
- * @secret_len: Length of the key in bytes
- * @label: A unique label for each purpose of the PRF
- * @seed: Seed value to bind into the key
- * @seed_len: Length of the seed
- * @out: Buffer for the generated pseudo-random key
- * @outlen: Number of bytes of key to generate
- * Returns: 0 on success, -1 on failure.
- *
- * This function is used to derive new, cryptographically separate keys from a
- * given key in TLS. This PRF is defined in RFC 2246, Chapter 5.
- */
-int tls_prf(const u8 *secret, size_t secret_len, const char *label,
- const u8 *seed, size_t seed_len, u8 *out, size_t outlen)
-{
- size_t L_S1, L_S2, i;
- const u8 *S1, *S2;
- u8 A_MD5[MD5_MAC_LEN], A_SHA1[SHA1_MAC_LEN];
- u8 P_MD5[MD5_MAC_LEN], P_SHA1[SHA1_MAC_LEN];
- int MD5_pos, SHA1_pos;
- const u8 *MD5_addr[3];
- size_t MD5_len[3];
- const unsigned char *SHA1_addr[3];
- size_t SHA1_len[3];
-
- if (secret_len & 1)
- return -1;
-
- MD5_addr[0] = A_MD5;
- MD5_len[0] = MD5_MAC_LEN;
- MD5_addr[1] = (unsigned char *) label;
- MD5_len[1] = os_strlen(label);
- MD5_addr[2] = seed;
- MD5_len[2] = seed_len;
-
- SHA1_addr[0] = A_SHA1;
- SHA1_len[0] = SHA1_MAC_LEN;
- SHA1_addr[1] = (unsigned char *) label;
- SHA1_len[1] = os_strlen(label);
- SHA1_addr[2] = seed;
- SHA1_len[2] = seed_len;
-
- /* RFC 2246, Chapter 5
- * A(0) = seed, A(i) = HMAC(secret, A(i-1))
- * P_hash = HMAC(secret, A(1) + seed) + HMAC(secret, A(2) + seed) + ..
- * PRF = P_MD5(S1, label + seed) XOR P_SHA-1(S2, label + seed)
- */
-
- L_S1 = L_S2 = (secret_len + 1) / 2;
- S1 = secret;
- S2 = secret + L_S1;
- if (secret_len & 1) {
- /* The last byte of S1 will be shared with S2 */
- S2--;
- }
-
- hmac_md5_vector(S1, L_S1, 2, &MD5_addr[1], &MD5_len[1], A_MD5);
- hmac_sha1_vector(S2, L_S2, 2, &SHA1_addr[1], &SHA1_len[1], A_SHA1);
-
- MD5_pos = MD5_MAC_LEN;
- SHA1_pos = SHA1_MAC_LEN;
- for (i = 0; i < outlen; i++) {
- if (MD5_pos == MD5_MAC_LEN) {
- hmac_md5_vector(S1, L_S1, 3, MD5_addr, MD5_len, P_MD5);
- MD5_pos = 0;
- hmac_md5(S1, L_S1, A_MD5, MD5_MAC_LEN, A_MD5);
- }
- if (SHA1_pos == SHA1_MAC_LEN) {
- hmac_sha1_vector(S2, L_S2, 3, SHA1_addr, SHA1_len,
- P_SHA1);
- SHA1_pos = 0;
- hmac_sha1(S2, L_S2, A_SHA1, SHA1_MAC_LEN, A_SHA1);
- }
-
- out[i] = P_MD5[MD5_pos] ^ P_SHA1[SHA1_pos];
-
- MD5_pos++;
- SHA1_pos++;
- }
-
- return 0;
-}
-#endif /* CONFIG_NO_TLS_PRF */
-
-
-#ifndef CONFIG_NO_PBKDF2
-
-static void pbkdf2_sha1_f(const char *passphrase, const char *ssid,
- size_t ssid_len, int iterations, unsigned int count,
- u8 *digest)
-{
- unsigned char tmp[SHA1_MAC_LEN], tmp2[SHA1_MAC_LEN];
- int i, j;
- unsigned char count_buf[4];
- const u8 *addr[2];
- size_t len[2];
- size_t passphrase_len = os_strlen(passphrase);
-
- addr[0] = (u8 *) ssid;
- len[0] = ssid_len;
- addr[1] = count_buf;
- len[1] = 4;
-
- /* F(P, S, c, i) = U1 xor U2 xor ... Uc
- * U1 = PRF(P, S || i)
- * U2 = PRF(P, U1)
- * Uc = PRF(P, Uc-1)
- */
-
- count_buf[0] = (count >> 24) & 0xff;
- count_buf[1] = (count >> 16) & 0xff;
- count_buf[2] = (count >> 8) & 0xff;
- count_buf[3] = count & 0xff;
- hmac_sha1_vector((u8 *) passphrase, passphrase_len, 2, addr, len, tmp);
- os_memcpy(digest, tmp, SHA1_MAC_LEN);
-
- for (i = 1; i < iterations; i++) {
- hmac_sha1((u8 *) passphrase, passphrase_len, tmp, SHA1_MAC_LEN,
- tmp2);
- os_memcpy(tmp, tmp2, SHA1_MAC_LEN);
- for (j = 0; j < SHA1_MAC_LEN; j++)
- digest[j] ^= tmp2[j];
- }
-}
-
-
-/**
- * pbkdf2_sha1 - SHA1-based key derivation function (PBKDF2) for IEEE 802.11i
- * @passphrase: ASCII passphrase
- * @ssid: SSID
- * @ssid_len: SSID length in bytes
- * @iterations: Number of iterations to run
- * @buf: Buffer for the generated key
- * @buflen: Length of the buffer in bytes
- *
- * This function is used to derive PSK for WPA-PSK. For this protocol,
- * iterations is set to 4096 and buflen to 32. This function is described in
- * IEEE Std 802.11-2004, Clause H.4. The main construction is from PKCS#5 v2.0.
- */
-void pbkdf2_sha1(const char *passphrase, const char *ssid, size_t ssid_len,
- int iterations, u8 *buf, size_t buflen)
-{
- unsigned int count = 0;
- unsigned char *pos = buf;
- size_t left = buflen, plen;
- unsigned char digest[SHA1_MAC_LEN];
-
- while (left > 0) {
- count++;
- pbkdf2_sha1_f(passphrase, ssid, ssid_len, iterations, count,
- digest);
- plen = left > SHA1_MAC_LEN ? SHA1_MAC_LEN : left;
- os_memcpy(pos, digest, plen);
- pos += plen;
- left -= plen;
- }
-}
-
-#endif /* CONFIG_NO_PBKDF2 */
-
-
-#ifdef INTERNAL_SHA1
-
-struct SHA1Context {
- u32 state[5];
- u32 count[2];
- unsigned char buffer[64];
-};
-
-typedef struct SHA1Context SHA1_CTX;
-
-#ifndef CONFIG_CRYPTO_INTERNAL
-static void SHA1Init(struct SHA1Context *context);
-static void SHA1Update(struct SHA1Context *context, const void *data, u32 len);
-static void SHA1Final(unsigned char digest[20], struct SHA1Context *context);
-#endif /* CONFIG_CRYPTO_INTERNAL */
-static void SHA1Transform(u32 state[5], const unsigned char buffer[64]);
-
-
-/**
- * sha1_vector - SHA-1 hash for data vector
- * @num_elem: Number of elements in the data vector
- * @addr: Pointers to the data areas
- * @len: Lengths of the data blocks
- * @mac: Buffer for the hash
- */
-void sha1_vector(size_t num_elem, const u8 *addr[], const size_t *len,
- u8 *mac)
-{
- SHA1_CTX ctx;
- size_t i;
-
- SHA1Init(&ctx);
- for (i = 0; i < num_elem; i++)
- SHA1Update(&ctx, addr[i], len[i]);
- SHA1Final(mac, &ctx);
-}
-
-
-#ifndef CONFIG_NO_FIPS186_2_PRF
-int fips186_2_prf(const u8 *seed, size_t seed_len, u8 *x, size_t xlen)
-{
- u8 xkey[64];
- u32 t[5], _t[5];
- int i, j, m, k;
- u8 *xpos = x;
- u32 carry;
-
- if (seed_len > sizeof(xkey))
- seed_len = sizeof(xkey);
-
- /* FIPS 186-2 + change notice 1 */
-
- os_memcpy(xkey, seed, seed_len);
- os_memset(xkey + seed_len, 0, 64 - seed_len);
- t[0] = 0x67452301;
- t[1] = 0xEFCDAB89;
- t[2] = 0x98BADCFE;
- t[3] = 0x10325476;
- t[4] = 0xC3D2E1F0;
-
- m = xlen / 40;
- for (j = 0; j < m; j++) {
- /* XSEED_j = 0 */
- for (i = 0; i < 2; i++) {
- /* XVAL = (XKEY + XSEED_j) mod 2^b */
-
- /* w_i = G(t, XVAL) */
- os_memcpy(_t, t, 20);
- SHA1Transform(_t, xkey);
- _t[0] = host_to_be32(_t[0]);
- _t[1] = host_to_be32(_t[1]);
- _t[2] = host_to_be32(_t[2]);
- _t[3] = host_to_be32(_t[3]);
- _t[4] = host_to_be32(_t[4]);
- os_memcpy(xpos, _t, 20);
-
- /* XKEY = (1 + XKEY + w_i) mod 2^b */
- carry = 1;
- for (k = 19; k >= 0; k--) {
- carry += xkey[k] + xpos[k];
- xkey[k] = carry & 0xff;
- carry >>= 8;
- }
-
- xpos += SHA1_MAC_LEN;
- }
- /* x_j = w_0|w_1 */
- }
return 0;
}
-#endif /* CONFIG_NO_FIPS186_2_PRF */
-
-
-/* ===== start - public domain SHA1 implementation ===== */
-
-/*
-SHA-1 in C
-By Steve Reid <sreid@sea-to-sky.net>
-100% Public Domain
-
------------------
-Modified 7/98
-By James H. Brown <jbrown@burgoyne.com>
-Still 100% Public Domain
-
-Corrected a problem which generated improper hash values on 16 bit machines
-Routine SHA1Update changed from
- void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int
-len)
-to
- void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned
-long len)
-
-The 'len' parameter was declared an int which works fine on 32 bit machines.
-However, on 16 bit machines an int is too small for the shifts being done
-against
-it. This caused the hash function to generate incorrect values if len was
-greater than 8191 (8K - 1) due to the 'len << 3' on line 3 of SHA1Update().
-
-Since the file IO in main() reads 16K at a time, any file 8K or larger would
-be guaranteed to generate the wrong hash (e.g. Test Vector #3, a million
-"a"s).
-
-I also changed the declaration of variables i & j in SHA1Update to
-unsigned long from unsigned int for the same reason.
-
-These changes should make no difference to any 32 bit implementations since
-an
-int and a long are the same size in those environments.
-
---
-I also corrected a few compiler warnings generated by Borland C.
-1. Added #include <process.h> for exit() prototype
-2. Removed unused variable 'j' in SHA1Final
-3. Changed exit(0) to return(0) at end of main.
-
-ALL changes I made can be located by searching for comments containing 'JHB'
------------------
-Modified 8/98
-By Steve Reid <sreid@sea-to-sky.net>
-Still 100% public domain
-
-1- Removed #include <process.h> and used return() instead of exit()
-2- Fixed overwriting of finalcount in SHA1Final() (discovered by Chris Hall)
-3- Changed email address from steve@edmweb.com to sreid@sea-to-sky.net
-
------------------
-Modified 4/01
-By Saul Kravitz <Saul.Kravitz@celera.com>
-Still 100% PD
-Modified to run on Compaq Alpha hardware.
-
------------------
-Modified 4/01
-By Jouni Malinen <j@w1.fi>
-Minor changes to match the coding style used in Dynamics.
-
-Modified September 24, 2004
-By Jouni Malinen <j@w1.fi>
-Fixed alignment issue in SHA1Transform when SHA1HANDSOFF is defined.
-
-*/
-
-/*
-Test Vectors (from FIPS PUB 180-1)
-"abc"
- A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
-"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
- 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
-A million repetitions of "a"
- 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
-*/
-
-#define SHA1HANDSOFF
-
-#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
-
-/* blk0() and blk() perform the initial expand. */
-/* I got the idea of expanding during the round function from SSLeay */
-#ifndef WORDS_BIGENDIAN
-#define blk0(i) (block->l[i] = (rol(block->l[i], 24) & 0xFF00FF00) | \
- (rol(block->l[i], 8) & 0x00FF00FF))
-#else
-#define blk0(i) block->l[i]
-#endif
-#define blk(i) (block->l[i & 15] = rol(block->l[(i + 13) & 15] ^ \
- block->l[(i + 8) & 15] ^ block->l[(i + 2) & 15] ^ block->l[i & 15], 1))
-
-/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
-#define R0(v,w,x,y,z,i) \
- z += ((w & (x ^ y)) ^ y) + blk0(i) + 0x5A827999 + rol(v, 5); \
- w = rol(w, 30);
-#define R1(v,w,x,y,z,i) \
- z += ((w & (x ^ y)) ^ y) + blk(i) + 0x5A827999 + rol(v, 5); \
- w = rol(w, 30);
-#define R2(v,w,x,y,z,i) \
- z += (w ^ x ^ y) + blk(i) + 0x6ED9EBA1 + rol(v, 5); w = rol(w, 30);
-#define R3(v,w,x,y,z,i) \
- z += (((w | x) & y) | (w & x)) + blk(i) + 0x8F1BBCDC + rol(v, 5); \
- w = rol(w, 30);
-#define R4(v,w,x,y,z,i) \
- z += (w ^ x ^ y) + blk(i) + 0xCA62C1D6 + rol(v, 5); \
- w=rol(w, 30);
-
-
-#ifdef VERBOSE /* SAK */
-void SHAPrintContext(SHA1_CTX *context, char *msg)
-{
- printf("%s (%d,%d) %x %x %x %x %x\n",
- msg,
- context->count[0], context->count[1],
- context->state[0],
- context->state[1],
- context->state[2],
- context->state[3],
- context->state[4]);
-}
-#endif
-
-/* Hash a single 512-bit block. This is the core of the algorithm. */
-
-static void SHA1Transform(u32 state[5], const unsigned char buffer[64])
-{
- u32 a, b, c, d, e;
- typedef union {
- unsigned char c[64];
- u32 l[16];
- } CHAR64LONG16;
- CHAR64LONG16* block;
-#ifdef SHA1HANDSOFF
- CHAR64LONG16 workspace;
- block = &workspace;
- os_memcpy(block, buffer, 64);
-#else
- block = (CHAR64LONG16 *) buffer;
-#endif
- /* Copy context->state[] to working vars */
- a = state[0];
- b = state[1];
- c = state[2];
- d = state[3];
- e = state[4];
- /* 4 rounds of 20 operations each. Loop unrolled. */
- R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
- R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
- R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
- R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
- R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
- R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
- R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
- R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
- R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
- R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
- R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
- R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
- R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
- R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
- R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
- R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
- R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
- R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
- R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
- R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
- /* Add the working vars back into context.state[] */
- state[0] += a;
- state[1] += b;
- state[2] += c;
- state[3] += d;
- state[4] += e;
- /* Wipe variables */
- a = b = c = d = e = 0;
-#ifdef SHA1HANDSOFF
- os_memset(block, 0, 64);
-#endif
-}
-
-
-/* SHA1Init - Initialize new context */
-
-void SHA1Init(SHA1_CTX* context)
-{
- /* SHA1 initialization constants */
- context->state[0] = 0x67452301;
- context->state[1] = 0xEFCDAB89;
- context->state[2] = 0x98BADCFE;
- context->state[3] = 0x10325476;
- context->state[4] = 0xC3D2E1F0;
- context->count[0] = context->count[1] = 0;
-}
-
-
-/* Run your data through this. */
-
-void SHA1Update(SHA1_CTX* context, const void *_data, u32 len)
-{
- u32 i, j;
- const unsigned char *data = _data;
-
-#ifdef VERBOSE
- SHAPrintContext(context, "before");
-#endif
- j = (context->count[0] >> 3) & 63;
- if ((context->count[0] += len << 3) < (len << 3))
- context->count[1]++;
- context->count[1] += (len >> 29);
- if ((j + len) > 63) {
- os_memcpy(&context->buffer[j], data, (i = 64-j));
- SHA1Transform(context->state, context->buffer);
- for ( ; i + 63 < len; i += 64) {
- SHA1Transform(context->state, &data[i]);
- }
- j = 0;
- }
- else i = 0;
- os_memcpy(&context->buffer[j], &data[i], len - i);
-#ifdef VERBOSE
- SHAPrintContext(context, "after ");
-#endif
-}
-
-
-/* Add padding and return the message digest. */
-
-void SHA1Final(unsigned char digest[20], SHA1_CTX* context)
-{
- u32 i;
- unsigned char finalcount[8];
-
- for (i = 0; i < 8; i++) {
- finalcount[i] = (unsigned char)
- ((context->count[(i >= 4 ? 0 : 1)] >>
- ((3-(i & 3)) * 8) ) & 255); /* Endian independent */
- }
- SHA1Update(context, (unsigned char *) "\200", 1);
- while ((context->count[0] & 504) != 448) {
- SHA1Update(context, (unsigned char *) "\0", 1);
- }
- SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform()
- */
- for (i = 0; i < 20; i++) {
- digest[i] = (unsigned char)
- ((context->state[i >> 2] >> ((3 - (i & 3)) * 8)) &
- 255);
- }
- /* Wipe variables */
- i = 0;
- os_memset(context->buffer, 0, 64);
- os_memset(context->state, 0, 20);
- os_memset(context->count, 0, 8);
- os_memset(finalcount, 0, 8);
-}
-
-/* ===== end - public domain SHA1 implementation ===== */
-
-#endif /* INTERNAL_SHA1 */
diff --git a/contrib/wpa/src/crypto/sha1.h b/contrib/wpa/src/crypto/sha1.h
index 9c365e2..c1a6233 100644
--- a/contrib/wpa/src/crypto/sha1.h
+++ b/contrib/wpa/src/crypto/sha1.h
@@ -1,6 +1,6 @@
/*
* SHA1 hash implementation and interface functions
- * Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -17,26 +17,17 @@
#define SHA1_MAC_LEN 20
-void hmac_sha1_vector(const u8 *key, size_t key_len, size_t num_elem,
- const u8 *addr[], const size_t *len, u8 *mac);
-void hmac_sha1(const u8 *key, size_t key_len, const u8 *data, size_t data_len,
+int hmac_sha1_vector(const u8 *key, size_t key_len, size_t num_elem,
+ const u8 *addr[], const size_t *len, u8 *mac);
+int hmac_sha1(const u8 *key, size_t key_len, const u8 *data, size_t data_len,
u8 *mac);
-void sha1_prf(const u8 *key, size_t key_len, const char *label,
- const u8 *data, size_t data_len, u8 *buf, size_t buf_len);
-void sha1_t_prf(const u8 *key, size_t key_len, const char *label,
- const u8 *seed, size_t seed_len, u8 *buf, size_t buf_len);
+int sha1_prf(const u8 *key, size_t key_len, const char *label,
+ const u8 *data, size_t data_len, u8 *buf, size_t buf_len);
+int sha1_t_prf(const u8 *key, size_t key_len, const char *label,
+ const u8 *seed, size_t seed_len, u8 *buf, size_t buf_len);
int __must_check tls_prf(const u8 *secret, size_t secret_len,
const char *label, const u8 *seed, size_t seed_len,
u8 *out, size_t outlen);
-void pbkdf2_sha1(const char *passphrase, const char *ssid, size_t ssid_len,
- int iterations, u8 *buf, size_t buflen);
-
-#ifdef CONFIG_CRYPTO_INTERNAL
-struct SHA1Context;
-
-void SHA1Init(struct SHA1Context *context);
-void SHA1Update(struct SHA1Context *context, const void *data, u32 len);
-void SHA1Final(unsigned char digest[20], struct SHA1Context *context);
-#endif /* CONFIG_CRYPTO_INTERNAL */
-
+int pbkdf2_sha1(const char *passphrase, const char *ssid, size_t ssid_len,
+ int iterations, u8 *buf, size_t buflen);
#endif /* SHA1_H */
diff --git a/contrib/wpa/src/crypto/sha1_i.h b/contrib/wpa/src/crypto/sha1_i.h
new file mode 100644
index 0000000..ec2f82f
--- /dev/null
+++ b/contrib/wpa/src/crypto/sha1_i.h
@@ -0,0 +1,29 @@
+/*
+ * SHA1 internal definitions
+ * Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef SHA1_I_H
+#define SHA1_I_H
+
+struct SHA1Context {
+ u32 state[5];
+ u32 count[2];
+ unsigned char buffer[64];
+};
+
+void SHA1Init(struct SHA1Context *context);
+void SHA1Update(struct SHA1Context *context, const void *data, u32 len);
+void SHA1Final(unsigned char digest[20], struct SHA1Context *context);
+void SHA1Transform(u32 state[5], const unsigned char buffer[64]);
+
+#endif /* SHA1_I_H */
diff --git a/contrib/wpa/src/crypto/sha256-internal.c b/contrib/wpa/src/crypto/sha256-internal.c
new file mode 100644
index 0000000..b061373
--- /dev/null
+++ b/contrib/wpa/src/crypto/sha256-internal.c
@@ -0,0 +1,243 @@
+/*
+ * SHA-256 hash implementation and interface functions
+ * Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "sha256.h"
+#include "crypto.h"
+
+struct sha256_state {
+ u64 length;
+ u32 state[8], curlen;
+ u8 buf[64];
+};
+
+static void sha256_init(struct sha256_state *md);
+static int sha256_process(struct sha256_state *md, const unsigned char *in,
+ unsigned long inlen);
+static int sha256_done(struct sha256_state *md, unsigned char *out);
+
+
+/**
+ * sha256_vector - SHA256 hash for data vector
+ * @num_elem: Number of elements in the data vector
+ * @addr: Pointers to the data areas
+ * @len: Lengths of the data blocks
+ * @mac: Buffer for the hash
+ * Returns: 0 on success, -1 of failure
+ */
+int sha256_vector(size_t num_elem, const u8 *addr[], const size_t *len,
+ u8 *mac)
+{
+ struct sha256_state ctx;
+ size_t i;
+
+ sha256_init(&ctx);
+ for (i = 0; i < num_elem; i++)
+ if (sha256_process(&ctx, addr[i], len[i]))
+ return -1;
+ if (sha256_done(&ctx, mac))
+ return -1;
+ return 0;
+}
+
+
+/* ===== start - public domain SHA256 implementation ===== */
+
+/* This is based on SHA256 implementation in LibTomCrypt that was released into
+ * public domain by Tom St Denis. */
+
+/* the K array */
+static const unsigned long K[64] = {
+ 0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL, 0x3956c25bUL,
+ 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL, 0xd807aa98UL, 0x12835b01UL,
+ 0x243185beUL, 0x550c7dc3UL, 0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL,
+ 0xc19bf174UL, 0xe49b69c1UL, 0xefbe4786UL, 0x0fc19dc6UL, 0x240ca1ccUL,
+ 0x2de92c6fUL, 0x4a7484aaUL, 0x5cb0a9dcUL, 0x76f988daUL, 0x983e5152UL,
+ 0xa831c66dUL, 0xb00327c8UL, 0xbf597fc7UL, 0xc6e00bf3UL, 0xd5a79147UL,
+ 0x06ca6351UL, 0x14292967UL, 0x27b70a85UL, 0x2e1b2138UL, 0x4d2c6dfcUL,
+ 0x53380d13UL, 0x650a7354UL, 0x766a0abbUL, 0x81c2c92eUL, 0x92722c85UL,
+ 0xa2bfe8a1UL, 0xa81a664bUL, 0xc24b8b70UL, 0xc76c51a3UL, 0xd192e819UL,
+ 0xd6990624UL, 0xf40e3585UL, 0x106aa070UL, 0x19a4c116UL, 0x1e376c08UL,
+ 0x2748774cUL, 0x34b0bcb5UL, 0x391c0cb3UL, 0x4ed8aa4aUL, 0x5b9cca4fUL,
+ 0x682e6ff3UL, 0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL,
+ 0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL
+};
+
+
+/* Various logical functions */
+#define RORc(x, y) \
+( ((((unsigned long) (x) & 0xFFFFFFFFUL) >> (unsigned long) ((y) & 31)) | \
+ ((unsigned long) (x) << (unsigned long) (32 - ((y) & 31)))) & 0xFFFFFFFFUL)
+#define Ch(x,y,z) (z ^ (x & (y ^ z)))
+#define Maj(x,y,z) (((x | y) & z) | (x & y))
+#define S(x, n) RORc((x), (n))
+#define R(x, n) (((x)&0xFFFFFFFFUL)>>(n))
+#define Sigma0(x) (S(x, 2) ^ S(x, 13) ^ S(x, 22))
+#define Sigma1(x) (S(x, 6) ^ S(x, 11) ^ S(x, 25))
+#define Gamma0(x) (S(x, 7) ^ S(x, 18) ^ R(x, 3))
+#define Gamma1(x) (S(x, 17) ^ S(x, 19) ^ R(x, 10))
+#ifndef MIN
+#define MIN(x, y) (((x) < (y)) ? (x) : (y))
+#endif
+
+/* compress 512-bits */
+static int sha256_compress(struct sha256_state *md, unsigned char *buf)
+{
+ u32 S[8], W[64], t0, t1;
+ u32 t;
+ int i;
+
+ /* copy state into S */
+ for (i = 0; i < 8; i++) {
+ S[i] = md->state[i];
+ }
+
+ /* copy the state into 512-bits into W[0..15] */
+ for (i = 0; i < 16; i++)
+ W[i] = WPA_GET_BE32(buf + (4 * i));
+
+ /* fill W[16..63] */
+ for (i = 16; i < 64; i++) {
+ W[i] = Gamma1(W[i - 2]) + W[i - 7] + Gamma0(W[i - 15]) +
+ W[i - 16];
+ }
+
+ /* Compress */
+#define RND(a,b,c,d,e,f,g,h,i) \
+ t0 = h + Sigma1(e) + Ch(e, f, g) + K[i] + W[i]; \
+ t1 = Sigma0(a) + Maj(a, b, c); \
+ d += t0; \
+ h = t0 + t1;
+
+ for (i = 0; i < 64; ++i) {
+ RND(S[0], S[1], S[2], S[3], S[4], S[5], S[6], S[7], i);
+ t = S[7]; S[7] = S[6]; S[6] = S[5]; S[5] = S[4];
+ S[4] = S[3]; S[3] = S[2]; S[2] = S[1]; S[1] = S[0]; S[0] = t;
+ }
+
+ /* feedback */
+ for (i = 0; i < 8; i++) {
+ md->state[i] = md->state[i] + S[i];
+ }
+ return 0;
+}
+
+
+/* Initialize the hash state */
+static void sha256_init(struct sha256_state *md)
+{
+ md->curlen = 0;
+ md->length = 0;
+ md->state[0] = 0x6A09E667UL;
+ md->state[1] = 0xBB67AE85UL;
+ md->state[2] = 0x3C6EF372UL;
+ md->state[3] = 0xA54FF53AUL;
+ md->state[4] = 0x510E527FUL;
+ md->state[5] = 0x9B05688CUL;
+ md->state[6] = 0x1F83D9ABUL;
+ md->state[7] = 0x5BE0CD19UL;
+}
+
+/**
+ Process a block of memory though the hash
+ @param md The hash state
+ @param in The data to hash
+ @param inlen The length of the data (octets)
+ @return CRYPT_OK if successful
+*/
+static int sha256_process(struct sha256_state *md, const unsigned char *in,
+ unsigned long inlen)
+{
+ unsigned long n;
+#define block_size 64
+
+ if (md->curlen > sizeof(md->buf))
+ return -1;
+
+ while (inlen > 0) {
+ if (md->curlen == 0 && inlen >= block_size) {
+ if (sha256_compress(md, (unsigned char *) in) < 0)
+ return -1;
+ md->length += block_size * 8;
+ in += block_size;
+ inlen -= block_size;
+ } else {
+ n = MIN(inlen, (block_size - md->curlen));
+ os_memcpy(md->buf + md->curlen, in, n);
+ md->curlen += n;
+ in += n;
+ inlen -= n;
+ if (md->curlen == block_size) {
+ if (sha256_compress(md, md->buf) < 0)
+ return -1;
+ md->length += 8 * block_size;
+ md->curlen = 0;
+ }
+ }
+ }
+
+ return 0;
+}
+
+
+/**
+ Terminate the hash to get the digest
+ @param md The hash state
+ @param out [out] The destination of the hash (32 bytes)
+ @return CRYPT_OK if successful
+*/
+static int sha256_done(struct sha256_state *md, unsigned char *out)
+{
+ int i;
+
+ if (md->curlen >= sizeof(md->buf))
+ return -1;
+
+ /* increase the length of the message */
+ md->length += md->curlen * 8;
+
+ /* append the '1' bit */
+ md->buf[md->curlen++] = (unsigned char) 0x80;
+
+ /* if the length is currently above 56 bytes we append zeros
+ * then compress. Then we can fall back to padding zeros and length
+ * encoding like normal.
+ */
+ if (md->curlen > 56) {
+ while (md->curlen < 64) {
+ md->buf[md->curlen++] = (unsigned char) 0;
+ }
+ sha256_compress(md, md->buf);
+ md->curlen = 0;
+ }
+
+ /* pad upto 56 bytes of zeroes */
+ while (md->curlen < 56) {
+ md->buf[md->curlen++] = (unsigned char) 0;
+ }
+
+ /* store length */
+ WPA_PUT_BE64(md->buf + 56, md->length);
+ sha256_compress(md, md->buf);
+
+ /* copy output */
+ for (i = 0; i < 8; i++)
+ WPA_PUT_BE32(out + (4 * i), md->state[i]);
+
+ return 0;
+}
+
+/* ===== end - public domain SHA256 implementation ===== */
diff --git a/contrib/wpa/src/crypto/sha256.c b/contrib/wpa/src/crypto/sha256.c
index 96dac0e..7f320f9 100644
--- a/contrib/wpa/src/crypto/sha256.c
+++ b/contrib/wpa/src/crypto/sha256.c
@@ -155,228 +155,3 @@ void sha256_prf(const u8 *key, size_t key_len, const char *label,
counter++;
}
}
-
-
-#ifdef INTERNAL_SHA256
-
-struct sha256_state {
- u64 length;
- u32 state[8], curlen;
- u8 buf[64];
-};
-
-static void sha256_init(struct sha256_state *md);
-static int sha256_process(struct sha256_state *md, const unsigned char *in,
- unsigned long inlen);
-static int sha256_done(struct sha256_state *md, unsigned char *out);
-
-
-/**
- * sha256_vector - SHA256 hash for data vector
- * @num_elem: Number of elements in the data vector
- * @addr: Pointers to the data areas
- * @len: Lengths of the data blocks
- * @mac: Buffer for the hash
- */
-void sha256_vector(size_t num_elem, const u8 *addr[], const size_t *len,
- u8 *mac)
-{
- struct sha256_state ctx;
- size_t i;
-
- sha256_init(&ctx);
- for (i = 0; i < num_elem; i++)
- sha256_process(&ctx, addr[i], len[i]);
- sha256_done(&ctx, mac);
-}
-
-
-/* ===== start - public domain SHA256 implementation ===== */
-
-/* This is based on SHA256 implementation in LibTomCrypt that was released into
- * public domain by Tom St Denis. */
-
-/* the K array */
-static const unsigned long K[64] = {
- 0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL, 0x3956c25bUL,
- 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL, 0xd807aa98UL, 0x12835b01UL,
- 0x243185beUL, 0x550c7dc3UL, 0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL,
- 0xc19bf174UL, 0xe49b69c1UL, 0xefbe4786UL, 0x0fc19dc6UL, 0x240ca1ccUL,
- 0x2de92c6fUL, 0x4a7484aaUL, 0x5cb0a9dcUL, 0x76f988daUL, 0x983e5152UL,
- 0xa831c66dUL, 0xb00327c8UL, 0xbf597fc7UL, 0xc6e00bf3UL, 0xd5a79147UL,
- 0x06ca6351UL, 0x14292967UL, 0x27b70a85UL, 0x2e1b2138UL, 0x4d2c6dfcUL,
- 0x53380d13UL, 0x650a7354UL, 0x766a0abbUL, 0x81c2c92eUL, 0x92722c85UL,
- 0xa2bfe8a1UL, 0xa81a664bUL, 0xc24b8b70UL, 0xc76c51a3UL, 0xd192e819UL,
- 0xd6990624UL, 0xf40e3585UL, 0x106aa070UL, 0x19a4c116UL, 0x1e376c08UL,
- 0x2748774cUL, 0x34b0bcb5UL, 0x391c0cb3UL, 0x4ed8aa4aUL, 0x5b9cca4fUL,
- 0x682e6ff3UL, 0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL,
- 0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL
-};
-
-
-/* Various logical functions */
-#define RORc(x, y) \
-( ((((unsigned long) (x) & 0xFFFFFFFFUL) >> (unsigned long) ((y) & 31)) | \
- ((unsigned long) (x) << (unsigned long) (32 - ((y) & 31)))) & 0xFFFFFFFFUL)
-#define Ch(x,y,z) (z ^ (x & (y ^ z)))
-#define Maj(x,y,z) (((x | y) & z) | (x & y))
-#define S(x, n) RORc((x), (n))
-#define R(x, n) (((x)&0xFFFFFFFFUL)>>(n))
-#define Sigma0(x) (S(x, 2) ^ S(x, 13) ^ S(x, 22))
-#define Sigma1(x) (S(x, 6) ^ S(x, 11) ^ S(x, 25))
-#define Gamma0(x) (S(x, 7) ^ S(x, 18) ^ R(x, 3))
-#define Gamma1(x) (S(x, 17) ^ S(x, 19) ^ R(x, 10))
-#ifndef MIN
-#define MIN(x, y) (((x) < (y)) ? (x) : (y))
-#endif
-
-/* compress 512-bits */
-static int sha256_compress(struct sha256_state *md, unsigned char *buf)
-{
- u32 S[8], W[64], t0, t1;
- u32 t;
- int i;
-
- /* copy state into S */
- for (i = 0; i < 8; i++) {
- S[i] = md->state[i];
- }
-
- /* copy the state into 512-bits into W[0..15] */
- for (i = 0; i < 16; i++)
- W[i] = WPA_GET_BE32(buf + (4 * i));
-
- /* fill W[16..63] */
- for (i = 16; i < 64; i++) {
- W[i] = Gamma1(W[i - 2]) + W[i - 7] + Gamma0(W[i - 15]) +
- W[i - 16];
- }
-
- /* Compress */
-#define RND(a,b,c,d,e,f,g,h,i) \
- t0 = h + Sigma1(e) + Ch(e, f, g) + K[i] + W[i]; \
- t1 = Sigma0(a) + Maj(a, b, c); \
- d += t0; \
- h = t0 + t1;
-
- for (i = 0; i < 64; ++i) {
- RND(S[0], S[1], S[2], S[3], S[4], S[5], S[6], S[7], i);
- t = S[7]; S[7] = S[6]; S[6] = S[5]; S[5] = S[4];
- S[4] = S[3]; S[3] = S[2]; S[2] = S[1]; S[1] = S[0]; S[0] = t;
- }
-
- /* feedback */
- for (i = 0; i < 8; i++) {
- md->state[i] = md->state[i] + S[i];
- }
- return 0;
-}
-
-
-/* Initialize the hash state */
-static void sha256_init(struct sha256_state *md)
-{
- md->curlen = 0;
- md->length = 0;
- md->state[0] = 0x6A09E667UL;
- md->state[1] = 0xBB67AE85UL;
- md->state[2] = 0x3C6EF372UL;
- md->state[3] = 0xA54FF53AUL;
- md->state[4] = 0x510E527FUL;
- md->state[5] = 0x9B05688CUL;
- md->state[6] = 0x1F83D9ABUL;
- md->state[7] = 0x5BE0CD19UL;
-}
-
-/**
- Process a block of memory though the hash
- @param md The hash state
- @param in The data to hash
- @param inlen The length of the data (octets)
- @return CRYPT_OK if successful
-*/
-static int sha256_process(struct sha256_state *md, const unsigned char *in,
- unsigned long inlen)
-{
- unsigned long n;
-#define block_size 64
-
- if (md->curlen > sizeof(md->buf))
- return -1;
-
- while (inlen > 0) {
- if (md->curlen == 0 && inlen >= block_size) {
- if (sha256_compress(md, (unsigned char *) in) < 0)
- return -1;
- md->length += block_size * 8;
- in += block_size;
- inlen -= block_size;
- } else {
- n = MIN(inlen, (block_size - md->curlen));
- os_memcpy(md->buf + md->curlen, in, n);
- md->curlen += n;
- in += n;
- inlen -= n;
- if (md->curlen == block_size) {
- if (sha256_compress(md, md->buf) < 0)
- return -1;
- md->length += 8 * block_size;
- md->curlen = 0;
- }
- }
- }
-
- return 0;
-}
-
-
-/**
- Terminate the hash to get the digest
- @param md The hash state
- @param out [out] The destination of the hash (32 bytes)
- @return CRYPT_OK if successful
-*/
-static int sha256_done(struct sha256_state *md, unsigned char *out)
-{
- int i;
-
- if (md->curlen >= sizeof(md->buf))
- return -1;
-
- /* increase the length of the message */
- md->length += md->curlen * 8;
-
- /* append the '1' bit */
- md->buf[md->curlen++] = (unsigned char) 0x80;
-
- /* if the length is currently above 56 bytes we append zeros
- * then compress. Then we can fall back to padding zeros and length
- * encoding like normal.
- */
- if (md->curlen > 56) {
- while (md->curlen < 64) {
- md->buf[md->curlen++] = (unsigned char) 0;
- }
- sha256_compress(md, md->buf);
- md->curlen = 0;
- }
-
- /* pad upto 56 bytes of zeroes */
- while (md->curlen < 56) {
- md->buf[md->curlen++] = (unsigned char) 0;
- }
-
- /* store length */
- WPA_PUT_BE64(md->buf + 56, md->length);
- sha256_compress(md, md->buf);
-
- /* copy output */
- for (i = 0; i < 8; i++)
- WPA_PUT_BE32(out + (4 * i), md->state[i]);
-
- return 0;
-}
-
-/* ===== end - public domain SHA256 implementation ===== */
-
-#endif /* INTERNAL_SHA256 */
diff --git a/contrib/wpa/src/crypto/tls.h b/contrib/wpa/src/crypto/tls.h
index aafb7999..0928b5b 100644
--- a/contrib/wpa/src/crypto/tls.h
+++ b/contrib/wpa/src/crypto/tls.h
@@ -1,6 +1,6 @@
/*
- * WPA Supplicant / SSL/TLS interface definition
- * Copyright (c) 2004-2007, Jouni Malinen <j@w1.fi>
+ * SSL/TLS interface definition
+ * Copyright (c) 2004-2010, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -28,10 +28,54 @@ struct tls_keys {
size_t inner_secret_len;
};
+enum tls_event {
+ TLS_CERT_CHAIN_FAILURE,
+ TLS_PEER_CERTIFICATE
+};
+
+/*
+ * Note: These are used as identifier with external programs and as such, the
+ * values must not be changed.
+ */
+enum tls_fail_reason {
+ TLS_FAIL_UNSPECIFIED = 0,
+ TLS_FAIL_UNTRUSTED = 1,
+ TLS_FAIL_REVOKED = 2,
+ TLS_FAIL_NOT_YET_VALID = 3,
+ TLS_FAIL_EXPIRED = 4,
+ TLS_FAIL_SUBJECT_MISMATCH = 5,
+ TLS_FAIL_ALTSUBJECT_MISMATCH = 6,
+ TLS_FAIL_BAD_CERTIFICATE = 7,
+ TLS_FAIL_SERVER_CHAIN_PROBE = 8
+};
+
+union tls_event_data {
+ struct {
+ int depth;
+ const char *subject;
+ enum tls_fail_reason reason;
+ const char *reason_txt;
+ const struct wpabuf *cert;
+ } cert_fail;
+
+ struct {
+ int depth;
+ const char *subject;
+ const struct wpabuf *cert;
+ const u8 *hash;
+ size_t hash_len;
+ } peer_cert;
+};
+
struct tls_config {
const char *opensc_engine_path;
const char *pkcs11_engine_path;
const char *pkcs11_module_path;
+ int fips_mode;
+
+ void (*event_cb)(void *ctx, enum tls_event ev,
+ union tls_event_data *data);
+ void *cb_ctx;
};
#define TLS_CONN_ALLOW_SIGN_RSA_MD5 BIT(0)
@@ -292,17 +336,14 @@ int __must_check tls_connection_prf(void *tls_ctx,
* tls_connection_handshake - Process TLS handshake (client side)
* @tls_ctx: TLS context data from tls_init()
* @conn: Connection context data from tls_connection_init()
- * @in_data: Input data from TLS peer
- * @in_len: Input data length
- * @out_len: Length of the output buffer.
+ * @in_data: Input data from TLS server
* @appl_data: Pointer to application data pointer, or %NULL if dropped
- * @appl_data_len: Pointer to variable that is set to appl_data length
- * Returns: Pointer to output data, %NULL on failure
+ * Returns: Output data, %NULL on failure
*
- * Caller is responsible for freeing returned output data. If the final
+ * The caller is responsible for freeing the returned output data. If the final
* handshake message includes application data, this is decrypted and
- * appl_data (if not %NULL) is set to point this data. Caller is responsible
- * for freeing appl_data.
+ * appl_data (if not %NULL) is set to point this data. The caller is
+ * responsible for freeing appl_data.
*
* This function is used during TLS handshake. The first call is done with
* in_data == %NULL and the library is expected to return ClientHello packet.
@@ -318,62 +359,55 @@ int __must_check tls_connection_prf(void *tls_ctx,
* tls_connection_established() should return 1 once the TLS handshake has been
* completed successfully.
*/
-u8 * tls_connection_handshake(void *tls_ctx, struct tls_connection *conn,
- const u8 *in_data, size_t in_len,
- size_t *out_len, u8 **appl_data,
- size_t *appl_data_len);
+struct wpabuf * tls_connection_handshake(void *tls_ctx,
+ struct tls_connection *conn,
+ const struct wpabuf *in_data,
+ struct wpabuf **appl_data);
/**
* tls_connection_server_handshake - Process TLS handshake (server side)
* @tls_ctx: TLS context data from tls_init()
* @conn: Connection context data from tls_connection_init()
* @in_data: Input data from TLS peer
- * @in_len: Input data length
- * @out_len: Length of the output buffer.
- * Returns: pointer to output data, %NULL on failure
+ * @appl_data: Pointer to application data pointer, or %NULL if dropped
+ * Returns: Output data, %NULL on failure
*
- * Caller is responsible for freeing returned output data.
+ * The caller is responsible for freeing the returned output data.
*/
-u8 * tls_connection_server_handshake(void *tls_ctx,
- struct tls_connection *conn,
- const u8 *in_data, size_t in_len,
- size_t *out_len);
+struct wpabuf * tls_connection_server_handshake(void *tls_ctx,
+ struct tls_connection *conn,
+ const struct wpabuf *in_data,
+ struct wpabuf **appl_data);
/**
* tls_connection_encrypt - Encrypt data into TLS tunnel
* @tls_ctx: TLS context data from tls_init()
* @conn: Connection context data from tls_connection_init()
- * @in_data: Pointer to plaintext data to be encrypted
- * @in_len: Input buffer length
- * @out_data: Pointer to output buffer (encrypted TLS data)
- * @out_len: Maximum out_data length
- * Returns: Number of bytes written to out_data, -1 on failure
+ * @in_data: Plaintext data to be encrypted
+ * Returns: Encrypted TLS data or %NULL on failure
*
* This function is used after TLS handshake has been completed successfully to
- * send data in the encrypted tunnel.
+ * send data in the encrypted tunnel. The caller is responsible for freeing the
+ * returned output data.
*/
-int __must_check tls_connection_encrypt(void *tls_ctx,
- struct tls_connection *conn,
- const u8 *in_data, size_t in_len,
- u8 *out_data, size_t out_len);
+struct wpabuf * tls_connection_encrypt(void *tls_ctx,
+ struct tls_connection *conn,
+ const struct wpabuf *in_data);
/**
* tls_connection_decrypt - Decrypt data from TLS tunnel
* @tls_ctx: TLS context data from tls_init()
* @conn: Connection context data from tls_connection_init()
- * @in_data: Pointer to input buffer (encrypted TLS data)
- * @in_len: Input buffer length
- * @out_data: Pointer to output buffer (decrypted data from TLS tunnel)
- * @out_len: Maximum out_data length
- * Returns: Number of bytes written to out_data, -1 on failure
+ * @in_data: Encrypted TLS data
+ * Returns: Decrypted TLS data or %NULL on failure
*
* This function is used after TLS handshake has been completed successfully to
- * receive data from the encrypted tunnel.
+ * receive data from the encrypted tunnel. The caller is responsible for
+ * freeing the returned output data.
*/
-int __must_check tls_connection_decrypt(void *tls_ctx,
- struct tls_connection *conn,
- const u8 *in_data, size_t in_len,
- u8 *out_data, size_t out_len);
+struct wpabuf * tls_connection_decrypt(void *tls_ctx,
+ struct tls_connection *conn,
+ const struct wpabuf *in_data);
/**
* tls_connection_resumed - Was session resumption used
@@ -493,16 +527,13 @@ unsigned int tls_capabilities(void *tls_ctx);
* @tls_ctx: TLS context data from tls_init()
* @conn: Connection context data from tls_connection_init()
* @final: 1 = FinalPhaseFinished, 0 = IntermediatePhaseFinished
- * @out_data: Pointer to output buffer (encrypted TLS/IA data)
- * @out_len: Maximum out_data length
- * Returns: Number of bytes written to out_data on success, -1 on failure
+ * Returns: Encrypted TLS/IA data, %NULL on failure
*
* This function is used to send the TLS/IA end phase message, e.g., when the
* EAP server completes EAP-TTLSv1.
*/
-int __must_check tls_connection_ia_send_phase_finished(
- void *tls_ctx, struct tls_connection *conn, int final,
- u8 *out_data, size_t out_len);
+struct wpabuf * tls_connection_ia_send_phase_finished(
+ void *tls_ctx, struct tls_connection *conn, int final);
/**
* tls_connection_ia_final_phase_finished - Has final phase been completed
diff --git a/contrib/wpa/src/crypto/tls_gnutls.c b/contrib/wpa/src/crypto/tls_gnutls.c
index 2c5c5a2..c3a7358 100644
--- a/contrib/wpa/src/crypto/tls_gnutls.c
+++ b/contrib/wpa/src/crypto/tls_gnutls.c
@@ -1,6 +1,6 @@
/*
- * WPA Supplicant / SSL/TLS interface functions for openssl
- * Copyright (c) 2004-2007, Jouni Malinen <j@w1.fi>
+ * SSL/TLS interface functions for GnuTLS
+ * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -112,8 +112,9 @@ struct tls_connection {
int established;
int verify_peer;
- u8 *push_buf, *pull_buf, *pull_buf_offset;
- size_t push_buf_len, pull_buf_len;
+ struct wpabuf *push_buf;
+ struct wpabuf *pull_buf;
+ const u8 *pull_buf_offset;
int params_set;
gnutls_certificate_credentials_t xcred;
@@ -241,22 +242,22 @@ static ssize_t tls_pull_func(gnutls_transport_ptr ptr, void *buf,
size_t len)
{
struct tls_connection *conn = (struct tls_connection *) ptr;
- u8 *end;
+ const u8 *end;
if (conn->pull_buf == NULL) {
errno = EWOULDBLOCK;
return -1;
}
- end = conn->pull_buf + conn->pull_buf_len;
+ end = wpabuf_head_u8(conn->pull_buf) + wpabuf_len(conn->pull_buf);
if ((size_t) (end - conn->pull_buf_offset) < len)
len = end - conn->pull_buf_offset;
os_memcpy(buf, conn->pull_buf_offset, len);
conn->pull_buf_offset += len;
if (conn->pull_buf_offset == end) {
wpa_printf(MSG_DEBUG, "%s - pull_buf consumed", __func__);
- os_free(conn->pull_buf);
- conn->pull_buf = conn->pull_buf_offset = NULL;
- conn->pull_buf_len = 0;
+ wpabuf_free(conn->pull_buf);
+ conn->pull_buf = NULL;
+ conn->pull_buf_offset = NULL;
} else {
wpa_printf(MSG_DEBUG, "%s - %lu bytes remaining in pull_buf",
__func__,
@@ -270,16 +271,12 @@ static ssize_t tls_push_func(gnutls_transport_ptr ptr, const void *buf,
size_t len)
{
struct tls_connection *conn = (struct tls_connection *) ptr;
- u8 *nbuf;
- nbuf = os_realloc(conn->push_buf, conn->push_buf_len + len);
- if (nbuf == NULL) {
+ if (wpabuf_resize(&conn->push_buf, len) < 0) {
errno = ENOMEM;
return -1;
}
- os_memcpy(nbuf + conn->push_buf_len, buf, len);
- conn->push_buf = nbuf;
- conn->push_buf_len += len;
+ wpabuf_put_data(conn->push_buf, buf, len);
return len;
}
@@ -383,8 +380,8 @@ void tls_connection_deinit(void *ssl_ctx, struct tls_connection *conn)
os_free(conn->pre_shared_secret);
os_free(conn->subject_match);
os_free(conn->altsubject_match);
- os_free(conn->push_buf);
- os_free(conn->pull_buf);
+ wpabuf_free(conn->push_buf);
+ wpabuf_free(conn->pull_buf);
os_free(conn);
}
@@ -407,9 +404,8 @@ int tls_connection_shutdown(void *ssl_ctx, struct tls_connection *conn)
* because the connection was already terminated in practice
* and "close notify" shutdown alert would confuse AS. */
gnutls_bye(conn->session, GNUTLS_SHUT_RDWR);
- os_free(conn->push_buf);
+ wpabuf_free(conn->push_buf);
conn->push_buf = NULL;
- conn->push_buf_len = 0;
conn->established = 0;
conn->final_phase_finished = 0;
#ifdef GNUTLS_IA
@@ -979,31 +975,56 @@ static int tls_connection_verify_peer(struct tls_connection *conn,
}
-u8 * tls_connection_handshake(void *ssl_ctx, struct tls_connection *conn,
- const u8 *in_data, size_t in_len,
- size_t *out_len, u8 **appl_data,
- size_t *appl_data_len)
+static struct wpabuf * gnutls_get_appl_data(struct tls_connection *conn)
{
- struct tls_global *global = ssl_ctx;
- u8 *out_data;
+ int res;
+ struct wpabuf *ad;
+ wpa_printf(MSG_DEBUG, "GnuTLS: Check for possible Application Data");
+ ad = wpabuf_alloc((wpabuf_len(conn->pull_buf) + 500) * 3);
+ if (ad == NULL)
+ return NULL;
+
+ res = gnutls_record_recv(conn->session, wpabuf_mhead(ad),
+ wpabuf_size(ad));
+ wpa_printf(MSG_DEBUG, "GnuTLS: gnutls_record_recv: %d", res);
+ if (res < 0) {
+ wpa_printf(MSG_DEBUG, "%s - gnutls_ia_recv failed: %d "
+ "(%s)", __func__, (int) res,
+ gnutls_strerror(res));
+ wpabuf_free(ad);
+ return NULL;
+ }
+
+ wpabuf_put(ad, res);
+ wpa_printf(MSG_DEBUG, "GnuTLS: Received %d bytes of Application Data",
+ res);
+ return ad;
+}
+
+
+struct wpabuf * tls_connection_handshake(void *tls_ctx,
+ struct tls_connection *conn,
+ const struct wpabuf *in_data,
+ struct wpabuf **appl_data)
+{
+ struct tls_global *global = tls_ctx;
+ struct wpabuf *out_data;
int ret;
if (appl_data)
*appl_data = NULL;
- if (in_data && in_len) {
+ if (in_data && wpabuf_len(in_data) > 0) {
if (conn->pull_buf) {
wpa_printf(MSG_DEBUG, "%s - %lu bytes remaining in "
"pull_buf", __func__,
- (unsigned long) conn->pull_buf_len);
- os_free(conn->pull_buf);
+ (unsigned long) wpabuf_len(conn->pull_buf));
+ wpabuf_free(conn->pull_buf);
}
- conn->pull_buf = os_malloc(in_len);
+ conn->pull_buf = wpabuf_dup(in_data);
if (conn->pull_buf == NULL)
return NULL;
- os_memcpy(conn->pull_buf, in_data, in_len);
- conn->pull_buf_offset = conn->pull_buf;
- conn->pull_buf_len = in_len;
+ conn->pull_buf_offset = wpabuf_head(conn->pull_buf);
}
ret = gnutls_handshake(conn->session);
@@ -1014,7 +1035,7 @@ u8 * tls_connection_handshake(void *ssl_ctx, struct tls_connection *conn,
conn->push_buf == NULL) {
/* Need to return something to trigger
* completion of EAP-TLS. */
- conn->push_buf = os_malloc(1);
+ conn->push_buf = wpabuf_alloc(0);
}
break;
case GNUTLS_E_FATAL_ALERT_RECEIVED:
@@ -1058,7 +1079,7 @@ u8 * tls_connection_handshake(void *ssl_ctx, struct tls_connection *conn,
conn->established = 1;
if (conn->push_buf == NULL) {
/* Need to return something to get final TLS ACK. */
- conn->push_buf = os_malloc(1);
+ conn->push_buf = wpabuf_alloc(0);
}
gnutls_session_get_data(conn->session, NULL, &size);
@@ -1073,90 +1094,88 @@ u8 * tls_connection_handshake(void *ssl_ctx, struct tls_connection *conn,
global->session_data,
&global->session_data_size);
}
+
+ if (conn->pull_buf && appl_data)
+ *appl_data = gnutls_get_appl_data(conn);
}
out:
out_data = conn->push_buf;
- *out_len = conn->push_buf_len;
conn->push_buf = NULL;
- conn->push_buf_len = 0;
return out_data;
}
-u8 * tls_connection_server_handshake(void *ssl_ctx,
- struct tls_connection *conn,
- const u8 *in_data, size_t in_len,
- size_t *out_len)
+struct wpabuf * tls_connection_server_handshake(void *tls_ctx,
+ struct tls_connection *conn,
+ const struct wpabuf *in_data,
+ struct wpabuf **appl_data)
{
- return tls_connection_handshake(ssl_ctx, conn, in_data, in_len,
- out_len, NULL, NULL);
+ return tls_connection_handshake(tls_ctx, conn, in_data, appl_data);
}
-int tls_connection_encrypt(void *ssl_ctx, struct tls_connection *conn,
- const u8 *in_data, size_t in_len,
- u8 *out_data, size_t out_len)
+struct wpabuf * tls_connection_encrypt(void *tls_ctx,
+ struct tls_connection *conn,
+ const struct wpabuf *in_data)
{
ssize_t res;
+ struct wpabuf *buf;
#ifdef GNUTLS_IA
if (conn->tls_ia)
- res = gnutls_ia_send(conn->session, (char *) in_data, in_len);
+ res = gnutls_ia_send(conn->session, wpabuf_head(in_data),
+ wpabuf_len(in_data));
else
#endif /* GNUTLS_IA */
- res = gnutls_record_send(conn->session, in_data, in_len);
+ res = gnutls_record_send(conn->session, wpabuf_head(in_data),
+ wpabuf_len(in_data));
if (res < 0) {
wpa_printf(MSG_INFO, "%s: Encryption failed: %s",
__func__, gnutls_strerror(res));
- return -1;
- }
- if (conn->push_buf == NULL)
- return -1;
- if (conn->push_buf_len < out_len)
- out_len = conn->push_buf_len;
- else if (conn->push_buf_len > out_len) {
- wpa_printf(MSG_INFO, "GnuTLS: Not enough buffer space for "
- "encrypted message (in_len=%lu push_buf_len=%lu "
- "out_len=%lu",
- (unsigned long) in_len,
- (unsigned long) conn->push_buf_len,
- (unsigned long) out_len);
+ return NULL;
}
- os_memcpy(out_data, conn->push_buf, out_len);
- os_free(conn->push_buf);
+
+ buf = conn->push_buf;
conn->push_buf = NULL;
- conn->push_buf_len = 0;
- return out_len;
+ return buf;
}
-int tls_connection_decrypt(void *ssl_ctx, struct tls_connection *conn,
- const u8 *in_data, size_t in_len,
- u8 *out_data, size_t out_len)
+struct wpabuf * tls_connection_decrypt(void *tls_ctx,
+ struct tls_connection *conn,
+ const struct wpabuf *in_data)
{
ssize_t res;
+ struct wpabuf *out;
if (conn->pull_buf) {
wpa_printf(MSG_DEBUG, "%s - %lu bytes remaining in "
"pull_buf", __func__,
- (unsigned long) conn->pull_buf_len);
- os_free(conn->pull_buf);
+ (unsigned long) wpabuf_len(conn->pull_buf));
+ wpabuf_free(conn->pull_buf);
}
- conn->pull_buf = os_malloc(in_len);
+ conn->pull_buf = wpabuf_dup(in_data);
if (conn->pull_buf == NULL)
- return -1;
- os_memcpy(conn->pull_buf, in_data, in_len);
- conn->pull_buf_offset = conn->pull_buf;
- conn->pull_buf_len = in_len;
+ return NULL;
+ conn->pull_buf_offset = wpabuf_head(conn->pull_buf);
+
+ /*
+ * Even though we try to disable TLS compression, it is possible that
+ * this cannot be done with all TLS libraries. Add extra buffer space
+ * to handle the possibility of the decrypted data being longer than
+ * input data.
+ */
+ out = wpabuf_alloc((wpabuf_len(in_data) + 500) * 3);
+ if (out == NULL)
+ return NULL;
#ifdef GNUTLS_IA
if (conn->tls_ia) {
- res = gnutls_ia_recv(conn->session, (char *) out_data,
- out_len);
- if (out_len >= 12 &&
- (res == GNUTLS_E_WARNING_IA_IPHF_RECEIVED ||
- res == GNUTLS_E_WARNING_IA_FPHF_RECEIVED)) {
+ res = gnutls_ia_recv(conn->session, wpabuf_mhead(out),
+ wpabuf_size(out));
+ if (res == GNUTLS_E_WARNING_IA_IPHF_RECEIVED ||
+ res == GNUTLS_E_WARNING_IA_FPHF_RECEIVED) {
int final = res == GNUTLS_E_WARNING_IA_FPHF_RECEIVED;
wpa_printf(MSG_DEBUG, "%s: Received %sPhaseFinished",
__func__, final ? "Final" : "Intermediate");
@@ -1175,11 +1194,12 @@ int tls_connection_decrypt(void *ssl_ctx, struct tls_connection *conn,
wpa_printf(MSG_DEBUG, "%s: Failed to permute "
"inner secret: %s",
__func__, gnutls_strerror(res));
- return -1;
+ wpabuf_free(out);
+ return NULL;
}
res = gnutls_ia_verify_endphase(conn->session,
- (char *) out_data);
+ wpabuf_head(out));
if (res == 0) {
wpa_printf(MSG_DEBUG, "%s: Correct endphase "
"checksum", __func__);
@@ -1187,31 +1207,39 @@ int tls_connection_decrypt(void *ssl_ctx, struct tls_connection *conn,
wpa_printf(MSG_INFO, "%s: Endphase "
"verification failed: %s",
__func__, gnutls_strerror(res));
- return -1;
+ wpabuf_free(out);
+ return NULL;
}
if (final)
conn->final_phase_finished = 1;
- return 0;
+ return out;
}
if (res < 0) {
wpa_printf(MSG_DEBUG, "%s - gnutls_ia_recv failed: %d "
"(%s)", __func__, (int) res,
gnutls_strerror(res));
+ wpabuf_free(out);
+ return NULL;
}
- return res;
+ wpabuf_put(out, res);
+ return out;
}
#endif /* GNUTLS_IA */
- res = gnutls_record_recv(conn->session, out_data, out_len);
+ res = gnutls_record_recv(conn->session, wpabuf_mhead(out),
+ wpabuf_size(out));
if (res < 0) {
wpa_printf(MSG_DEBUG, "%s - gnutls_record_recv failed: %d "
"(%s)", __func__, (int) res, gnutls_strerror(res));
+ wpabuf_free(out);
+ return NULL;
}
+ wpabuf_put(out, res);
- return res;
+ return out;
}
@@ -1243,7 +1271,7 @@ int tls_get_cipher(void *ssl_ctx, struct tls_connection *conn,
int tls_connection_enable_workaround(void *ssl_ctx,
struct tls_connection *conn)
{
- /* TODO: set SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS */
+ gnutls_record_disable_padding(conn->session);
return 0;
}
@@ -1338,16 +1366,15 @@ int tls_connection_set_ia(void *tls_ctx, struct tls_connection *conn,
}
-int tls_connection_ia_send_phase_finished(void *tls_ctx,
- struct tls_connection *conn,
- int final,
- u8 *out_data, size_t out_len)
+struct wpabuf * tls_connection_ia_send_phase_finished(
+ void *tls_ctx, struct tls_connection *conn, int final)
{
#ifdef GNUTLS_IA
int ret;
+ struct wpabuf *buf;
if (conn == NULL || conn->session == NULL || !conn->tls_ia)
- return -1;
+ return NULL;
ret = gnutls_ia_permute_inner_secret(conn->session,
conn->session_keys_len,
@@ -1361,27 +1388,21 @@ int tls_connection_ia_send_phase_finished(void *tls_ctx,
if (ret) {
wpa_printf(MSG_DEBUG, "%s: Failed to permute inner secret: %s",
__func__, gnutls_strerror(ret));
- return -1;
+ return NULL;
}
ret = gnutls_ia_endphase_send(conn->session, final);
if (ret) {
wpa_printf(MSG_DEBUG, "%s: Failed to send endphase: %s",
__func__, gnutls_strerror(ret));
- return -1;
+ return NULL;
}
- if (conn->push_buf == NULL)
- return -1;
- if (conn->push_buf_len < out_len)
- out_len = conn->push_buf_len;
- os_memcpy(out_data, conn->push_buf, out_len);
- os_free(conn->push_buf);
+ buf = conn->push_buf;
conn->push_buf = NULL;
- conn->push_buf_len = 0;
- return out_len;
+ return buf;
#else /* GNUTLS_IA */
- return -1;
+ return NULL;
#endif /* GNUTLS_IA */
}
@@ -1426,3 +1447,11 @@ int tls_connection_ia_permute_inner_secret(void *tls_ctx,
return -1;
#endif /* GNUTLS_IA */
}
+
+
+int tls_connection_set_session_ticket_cb(void *tls_ctx,
+ struct tls_connection *conn,
+ tls_session_ticket_cb cb, void *ctx)
+{
+ return -1;
+}
diff --git a/contrib/wpa/src/crypto/tls_internal.c b/contrib/wpa/src/crypto/tls_internal.c
index 42120c8..64124d8 100644
--- a/contrib/wpa/src/crypto/tls_internal.c
+++ b/contrib/wpa/src/crypto/tls_internal.c
@@ -1,6 +1,6 @@
/*
- * WPA Supplicant / TLS interface functions and an internal TLS implementation
- * Copyright (c) 2004-2007, Jouni Malinen <j@w1.fi>
+ * TLS interface functions and an internal TLS implementation
+ * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -331,45 +331,77 @@ int tls_connection_prf(void *tls_ctx, struct tls_connection *conn,
}
-u8 * tls_connection_handshake(void *tls_ctx, struct tls_connection *conn,
- const u8 *in_data, size_t in_len,
- size_t *out_len, u8 **appl_data,
- size_t *appl_data_len)
+struct wpabuf * tls_connection_handshake(void *tls_ctx,
+ struct tls_connection *conn,
+ const struct wpabuf *in_data,
+ struct wpabuf **appl_data)
{
#ifdef CONFIG_TLS_INTERNAL_CLIENT
+ u8 *res, *ad;
+ size_t res_len, ad_len;
+ struct wpabuf *out;
+
if (conn->client == NULL)
return NULL;
- if (appl_data)
- *appl_data = NULL;
+ ad = NULL;
+ res = tlsv1_client_handshake(conn->client,
+ in_data ? wpabuf_head(in_data) : NULL,
+ in_data ? wpabuf_len(in_data) : 0,
+ &res_len, &ad, &ad_len);
+ if (res == NULL)
+ return NULL;
+ out = wpabuf_alloc_ext_data(res, res_len);
+ if (out == NULL) {
+ os_free(res);
+ os_free(ad);
+ return NULL;
+ }
+ if (appl_data) {
+ if (ad) {
+ *appl_data = wpabuf_alloc_ext_data(ad, ad_len);
+ if (*appl_data == NULL)
+ os_free(ad);
+ } else
+ *appl_data = NULL;
+ } else
+ os_free(ad);
- wpa_printf(MSG_DEBUG, "TLS: %s(in_data=%p in_len=%lu)",
- __func__, in_data, (unsigned long) in_len);
- return tlsv1_client_handshake(conn->client, in_data, in_len, out_len,
- appl_data, appl_data_len);
+ return out;
#else /* CONFIG_TLS_INTERNAL_CLIENT */
return NULL;
#endif /* CONFIG_TLS_INTERNAL_CLIENT */
}
-u8 * tls_connection_server_handshake(void *tls_ctx,
- struct tls_connection *conn,
- const u8 *in_data, size_t in_len,
- size_t *out_len)
+struct wpabuf * tls_connection_server_handshake(void *tls_ctx,
+ struct tls_connection *conn,
+ const struct wpabuf *in_data,
+ struct wpabuf **appl_data)
{
#ifdef CONFIG_TLS_INTERNAL_SERVER
- u8 *out;
+ u8 *res;
+ size_t res_len;
+ struct wpabuf *out;
+
if (conn->server == NULL)
return NULL;
- wpa_printf(MSG_DEBUG, "TLS: %s(in_data=%p in_len=%lu)",
- __func__, in_data, (unsigned long) in_len);
- out = tlsv1_server_handshake(conn->server, in_data, in_len, out_len);
- if (out == NULL && tlsv1_server_established(conn->server)) {
- out = os_malloc(1);
- *out_len = 0;
+ if (appl_data)
+ *appl_data = NULL;
+
+ res = tlsv1_server_handshake(conn->server, wpabuf_head(in_data),
+ wpabuf_len(in_data), &res_len);
+ if (res == NULL && tlsv1_server_established(conn->server))
+ return wpabuf_alloc(0);
+ if (res == NULL)
+ return NULL;
+ out = wpabuf_alloc_ext_data(res, res_len);
+ if (out == NULL) {
+ os_free(res);
+ return NULL;
}
+
return out;
#else /* CONFIG_TLS_INTERNAL_SERVER */
return NULL;
@@ -377,43 +409,95 @@ u8 * tls_connection_server_handshake(void *tls_ctx,
}
-int tls_connection_encrypt(void *tls_ctx, struct tls_connection *conn,
- const u8 *in_data, size_t in_len,
- u8 *out_data, size_t out_len)
+struct wpabuf * tls_connection_encrypt(void *tls_ctx,
+ struct tls_connection *conn,
+ const struct wpabuf *in_data)
{
#ifdef CONFIG_TLS_INTERNAL_CLIENT
if (conn->client) {
- return tlsv1_client_encrypt(conn->client, in_data, in_len,
- out_data, out_len);
+ struct wpabuf *buf;
+ int res;
+ buf = wpabuf_alloc(wpabuf_len(in_data) + 300);
+ if (buf == NULL)
+ return NULL;
+ res = tlsv1_client_encrypt(conn->client, wpabuf_head(in_data),
+ wpabuf_len(in_data),
+ wpabuf_mhead(buf),
+ wpabuf_size(buf));
+ if (res < 0) {
+ wpabuf_free(buf);
+ return NULL;
+ }
+ wpabuf_put(buf, res);
+ return buf;
}
#endif /* CONFIG_TLS_INTERNAL_CLIENT */
#ifdef CONFIG_TLS_INTERNAL_SERVER
if (conn->server) {
- return tlsv1_server_encrypt(conn->server, in_data, in_len,
- out_data, out_len);
+ struct wpabuf *buf;
+ int res;
+ buf = wpabuf_alloc(wpabuf_len(in_data) + 300);
+ if (buf == NULL)
+ return NULL;
+ res = tlsv1_server_encrypt(conn->server, wpabuf_head(in_data),
+ wpabuf_len(in_data),
+ wpabuf_mhead(buf),
+ wpabuf_size(buf));
+ if (res < 0) {
+ wpabuf_free(buf);
+ return NULL;
+ }
+ wpabuf_put(buf, res);
+ return buf;
}
#endif /* CONFIG_TLS_INTERNAL_SERVER */
- return -1;
+ return NULL;
}
-int tls_connection_decrypt(void *tls_ctx, struct tls_connection *conn,
- const u8 *in_data, size_t in_len,
- u8 *out_data, size_t out_len)
+struct wpabuf * tls_connection_decrypt(void *tls_ctx,
+ struct tls_connection *conn,
+ const struct wpabuf *in_data)
{
#ifdef CONFIG_TLS_INTERNAL_CLIENT
if (conn->client) {
- return tlsv1_client_decrypt(conn->client, in_data, in_len,
- out_data, out_len);
+ struct wpabuf *buf;
+ int res;
+ buf = wpabuf_alloc((wpabuf_len(in_data) + 500) * 3);
+ if (buf == NULL)
+ return NULL;
+ res = tlsv1_client_decrypt(conn->client, wpabuf_head(in_data),
+ wpabuf_len(in_data),
+ wpabuf_mhead(buf),
+ wpabuf_size(buf));
+ if (res < 0) {
+ wpabuf_free(buf);
+ return NULL;
+ }
+ wpabuf_put(buf, res);
+ return buf;
}
#endif /* CONFIG_TLS_INTERNAL_CLIENT */
#ifdef CONFIG_TLS_INTERNAL_SERVER
if (conn->server) {
- return tlsv1_server_decrypt(conn->server, in_data, in_len,
- out_data, out_len);
+ struct wpabuf *buf;
+ int res;
+ buf = wpabuf_alloc((wpabuf_len(in_data) + 500) * 3);
+ if (buf == NULL)
+ return NULL;
+ res = tlsv1_server_decrypt(conn->server, wpabuf_head(in_data),
+ wpabuf_len(in_data),
+ wpabuf_mhead(buf),
+ wpabuf_size(buf));
+ if (res < 0) {
+ wpabuf_free(buf);
+ return NULL;
+ }
+ wpabuf_put(buf, res);
+ return buf;
}
#endif /* CONFIG_TLS_INTERNAL_SERVER */
- return -1;
+ return NULL;
}
@@ -524,12 +608,10 @@ unsigned int tls_capabilities(void *tls_ctx)
}
-int tls_connection_ia_send_phase_finished(void *tls_ctx,
- struct tls_connection *conn,
- int final,
- u8 *out_data, size_t out_len)
+struct wpabuf * tls_connection_ia_send_phase_finished(
+ void *tls_ctx, struct tls_connection *conn, int final)
{
- return -1;
+ return NULL;
}
diff --git a/contrib/wpa/src/crypto/tls_none.c b/contrib/wpa/src/crypto/tls_none.c
index f731628..0c836bb 100644
--- a/contrib/wpa/src/crypto/tls_none.c
+++ b/contrib/wpa/src/crypto/tls_none.c
@@ -1,6 +1,6 @@
/*
- * WPA Supplicant / SSL/TLS interface functions for no TLS case
- * Copyright (c) 2004, Jouni Malinen <j@w1.fi>
+ * SSL/TLS interface functions for no TLS case
+ * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -22,13 +22,12 @@ void * tls_init(const struct tls_config *conf)
return (void *) 1;
}
+
void tls_deinit(void *ssl_ctx)
{
}
-#ifdef EAP_TLS_NONE
-
int tls_get_errors(void *tls_ctx)
{
return 0;
@@ -107,37 +106,37 @@ int tls_connection_prf(void *tls_ctx, struct tls_connection *conn,
}
-u8 * tls_connection_handshake(void *tls_ctx, struct tls_connection *conn,
- const u8 *in_data, size_t in_len,
- size_t *out_len, u8 **appl_data,
- size_t *appl_data_len)
+struct wpabuf * tls_connection_handshake(void *tls_ctx,
+ struct tls_connection *conn,
+ const struct wpabuf *in_data,
+ struct wpabuf **appl_data)
{
return NULL;
}
-u8 * tls_connection_server_handshake(void *tls_ctx,
- struct tls_connection *conn,
- const u8 *in_data, size_t in_len,
- size_t *out_len)
+struct wpabuf * tls_connection_server_handshake(void *tls_ctx,
+ struct tls_connection *conn,
+ const struct wpabuf *in_data,
+ struct wpabuf **appl_data)
{
return NULL;
}
-int tls_connection_encrypt(void *tls_ctx, struct tls_connection *conn,
- const u8 *in_data, size_t in_len,
- u8 *out_data, size_t out_len)
+struct wpabuf * tls_connection_encrypt(void *tls_ctx,
+ struct tls_connection *conn,
+ const struct wpabuf *in_data)
{
- return -1;
+ return NULL;
}
-int tls_connection_decrypt(void *tls_ctx, struct tls_connection *conn,
- const u8 *in_data, size_t in_len,
- u8 *out_data, size_t out_len)
+struct wpabuf * tls_connection_decrypt(void *tls_ctx,
+ struct tls_connection *conn,
+ const struct wpabuf *in_data)
{
- return -1;
+ return NULL;
}
@@ -208,12 +207,10 @@ unsigned int tls_capabilities(void *tls_ctx)
}
-int tls_connection_ia_send_phase_finished(void *tls_ctx,
- struct tls_connection *conn,
- int final,
- u8 *out_data, size_t out_len)
+struct wpabuf * tls_connection_ia_send_phase_finished(
+ void *tls_ctx, struct tls_connection *conn, int final)
{
- return -1;
+ return NULL;
}
@@ -230,5 +227,3 @@ int tls_connection_ia_permute_inner_secret(void *tls_ctx,
{
return -1;
}
-
-#endif /* EAP_TLS_NONE */
diff --git a/contrib/wpa/src/crypto/tls_nss.c b/contrib/wpa/src/crypto/tls_nss.c
new file mode 100644
index 0000000..ad834b6
--- /dev/null
+++ b/contrib/wpa/src/crypto/tls_nss.c
@@ -0,0 +1,680 @@
+/*
+ * SSL/TLS interface functions for NSS
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+#include <nspr/prtypes.h>
+#include <nspr/plarenas.h>
+#include <nspr/plhash.h>
+#include <nspr/prio.h>
+#include <nspr/prclist.h>
+#include <nspr/prlock.h>
+#include <nspr/prinit.h>
+#include <nspr/prerror.h>
+#include <nspr/prmem.h>
+#include <nss/nss.h>
+#include <nss/nssilckt.h>
+#include <nss/ssl.h>
+#include <nss/pk11func.h>
+#include <nss/secerr.h>
+
+#include "common.h"
+#include "tls.h"
+
+static int tls_nss_ref_count = 0;
+
+static PRDescIdentity nss_layer_id;
+
+
+struct tls_connection {
+ PRFileDesc *fd;
+
+ int established;
+ int verify_peer;
+ u8 *push_buf, *pull_buf, *pull_buf_offset;
+ size_t push_buf_len, pull_buf_len;
+};
+
+
+static PRStatus nss_io_close(PRFileDesc *fd)
+{
+ wpa_printf(MSG_DEBUG, "NSS: I/O close");
+ return PR_SUCCESS;
+}
+
+
+static PRInt32 nss_io_read(PRFileDesc *fd, void *buf, PRInt32 amount)
+{
+ wpa_printf(MSG_DEBUG, "NSS: I/O read(%d)", amount);
+ return PR_FAILURE;
+}
+
+
+static PRInt32 nss_io_write(PRFileDesc *fd, const void *buf, PRInt32 amount)
+{
+ wpa_printf(MSG_DEBUG, "NSS: I/O write(%d)", amount);
+ return PR_FAILURE;
+}
+
+
+static PRInt32 nss_io_writev(PRFileDesc *fd, const PRIOVec *iov,
+ PRInt32 iov_size, PRIntervalTime timeout)
+{
+ wpa_printf(MSG_DEBUG, "NSS: I/O writev(%d)", iov_size);
+ return PR_FAILURE;
+}
+
+
+static PRInt32 nss_io_recv(PRFileDesc *fd, void *buf, PRInt32 amount,
+ PRIntn flags, PRIntervalTime timeout)
+{
+ struct tls_connection *conn = (struct tls_connection *) fd->secret;
+ u8 *end;
+
+ wpa_printf(MSG_DEBUG, "NSS: I/O recv(%d)", amount);
+
+ if (conn->pull_buf == NULL) {
+ wpa_printf(MSG_DEBUG, "NSS: No data available to be read yet");
+ return PR_FAILURE;
+ }
+
+ end = conn->pull_buf + conn->pull_buf_len;
+ if (end - conn->pull_buf_offset < amount)
+ amount = end - conn->pull_buf_offset;
+ os_memcpy(buf, conn->pull_buf_offset, amount);
+ conn->pull_buf_offset += amount;
+ if (conn->pull_buf_offset == end) {
+ wpa_printf(MSG_DEBUG, "%s - pull_buf consumed", __func__);
+ os_free(conn->pull_buf);
+ conn->pull_buf = conn->pull_buf_offset = NULL;
+ conn->pull_buf_len = 0;
+ } else {
+ wpa_printf(MSG_DEBUG, "%s - %lu bytes remaining in pull_buf",
+ __func__,
+ (unsigned long) (end - conn->pull_buf_offset));
+ }
+ return amount;
+}
+
+
+static PRInt32 nss_io_send(PRFileDesc *fd, const void *buf, PRInt32 amount,
+ PRIntn flags, PRIntervalTime timeout)
+{
+ struct tls_connection *conn = (struct tls_connection *) fd->secret;
+ u8 *nbuf;
+
+ wpa_printf(MSG_DEBUG, "NSS: I/O %s", __func__);
+ wpa_hexdump(MSG_MSGDUMP, "NSS: I/O send data", buf, amount);
+
+ nbuf = os_realloc(conn->push_buf, conn->push_buf_len + amount);
+ if (nbuf == NULL) {
+ wpa_printf(MSG_ERROR, "NSS: Failed to allocate memory for the "
+ "data to be sent");
+ return PR_FAILURE;
+ }
+ os_memcpy(nbuf + conn->push_buf_len, buf, amount);
+ conn->push_buf = nbuf;
+ conn->push_buf_len += amount;
+
+ return amount;
+}
+
+
+static PRInt32 nss_io_recvfrom(PRFileDesc *fd, void *buf, PRInt32 amount,
+ PRIntn flags, PRNetAddr *addr,
+ PRIntervalTime timeout)
+{
+ wpa_printf(MSG_DEBUG, "NSS: I/O %s", __func__);
+ return PR_FAILURE;
+}
+
+
+static PRInt32 nss_io_sendto(PRFileDesc *fd, const void *buf, PRInt32 amount,
+ PRIntn flags, const PRNetAddr *addr,
+ PRIntervalTime timeout)
+{
+ wpa_printf(MSG_DEBUG, "NSS: I/O %s", __func__);
+ return PR_FAILURE;
+}
+
+
+static PRStatus nss_io_getpeername(PRFileDesc *fd, PRNetAddr *addr)
+{
+ wpa_printf(MSG_DEBUG, "NSS: I/O getpeername");
+
+ /*
+ * It Looks like NSS only supports IPv4 and IPv6 TCP sockets. Provide a
+ * fake IPv4 address to work around this even though we are not really
+ * using TCP.
+ */
+ os_memset(addr, 0, sizeof(*addr));
+ addr->inet.family = PR_AF_INET;
+
+ return PR_SUCCESS;
+}
+
+
+static PRStatus nss_io_getsocketoption(PRFileDesc *fd,
+ PRSocketOptionData *data)
+{
+ switch (data->option) {
+ case PR_SockOpt_Nonblocking:
+ wpa_printf(MSG_DEBUG, "NSS: I/O getsocketoption(Nonblocking)");
+ data->value.non_blocking = PR_TRUE;
+ return PR_SUCCESS;
+ default:
+ wpa_printf(MSG_DEBUG, "NSS: I/O getsocketoption(%d)",
+ data->option);
+ return PR_FAILURE;
+ }
+}
+
+
+static const PRIOMethods nss_io = {
+ PR_DESC_LAYERED,
+ nss_io_close,
+ nss_io_read,
+ nss_io_write,
+ NULL /* available */,
+ NULL /* available64 */,
+ NULL /* fsync */,
+ NULL /* fseek */,
+ NULL /* fseek64 */,
+ NULL /* fileinfo */,
+ NULL /* fileinfo64 */,
+ nss_io_writev,
+ NULL /* connect */,
+ NULL /* accept */,
+ NULL /* bind */,
+ NULL /* listen */,
+ NULL /* shutdown */,
+ nss_io_recv,
+ nss_io_send,
+ nss_io_recvfrom,
+ nss_io_sendto,
+ NULL /* poll */,
+ NULL /* acceptread */,
+ NULL /* transmitfile */,
+ NULL /* getsockname */,
+ nss_io_getpeername,
+ NULL /* reserved_fn_6 */,
+ NULL /* reserved_fn_5 */,
+ nss_io_getsocketoption,
+ NULL /* setsocketoption */,
+ NULL /* sendfile */,
+ NULL /* connectcontinue */,
+ NULL /* reserved_fn_3 */,
+ NULL /* reserved_fn_2 */,
+ NULL /* reserved_fn_1 */,
+ NULL /* reserved_fn_0 */
+};
+
+
+static char * nss_password_cb(PK11SlotInfo *slot, PRBool retry, void *arg)
+{
+ wpa_printf(MSG_ERROR, "NSS: TODO - %s", __func__);
+ return NULL;
+}
+
+
+void * tls_init(const struct tls_config *conf)
+{
+ char *dir;
+
+ tls_nss_ref_count++;
+ if (tls_nss_ref_count > 1)
+ return (void *) 1;
+
+ PR_Init(PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 1);
+
+ nss_layer_id = PR_GetUniqueIdentity("wpa_supplicant");
+
+ PK11_SetPasswordFunc(nss_password_cb);
+
+ dir = getenv("SSL_DIR");
+ if (dir) {
+ if (NSS_Init(dir) != SECSuccess) {
+ wpa_printf(MSG_ERROR, "NSS: NSS_Init(cert_dir=%s) "
+ "failed", dir);
+ return NULL;
+ }
+ } else {
+ if (NSS_NoDB_Init(NULL) != SECSuccess) {
+ wpa_printf(MSG_ERROR, "NSS: NSS_NoDB_Init(NULL) "
+ "failed");
+ return NULL;
+ }
+ }
+
+ if (SSL_OptionSetDefault(SSL_V2_COMPATIBLE_HELLO, PR_FALSE) !=
+ SECSuccess ||
+ SSL_OptionSetDefault(SSL_ENABLE_SSL3, PR_FALSE) != SECSuccess ||
+ SSL_OptionSetDefault(SSL_ENABLE_SSL2, PR_FALSE) != SECSuccess ||
+ SSL_OptionSetDefault(SSL_ENABLE_TLS, PR_TRUE) != SECSuccess) {
+ wpa_printf(MSG_ERROR, "NSS: SSL_OptionSetDefault failed");
+ return NULL;
+ }
+
+ if (NSS_SetDomesticPolicy() != SECSuccess) {
+ wpa_printf(MSG_ERROR, "NSS: NSS_SetDomesticPolicy() failed");
+ return NULL;
+ }
+
+ return (void *) 1;
+}
+
+void tls_deinit(void *ssl_ctx)
+{
+ tls_nss_ref_count--;
+ if (tls_nss_ref_count == 0) {
+ if (NSS_Shutdown() != SECSuccess)
+ wpa_printf(MSG_ERROR, "NSS: NSS_Shutdown() failed");
+ }
+}
+
+
+int tls_get_errors(void *tls_ctx)
+{
+ return 0;
+}
+
+
+static SECStatus nss_bad_cert_cb(void *arg, PRFileDesc *fd)
+{
+ struct tls_connection *conn = arg;
+ SECStatus res = SECSuccess;
+ PRErrorCode err;
+ CERTCertificate *cert;
+ char *subject, *issuer;
+
+ err = PR_GetError();
+ if (IS_SEC_ERROR(err))
+ wpa_printf(MSG_DEBUG, "NSS: Bad Server Certificate (sec err "
+ "%d)", err - SEC_ERROR_BASE);
+ else
+ wpa_printf(MSG_DEBUG, "NSS: Bad Server Certificate (err %d)",
+ err);
+ cert = SSL_PeerCertificate(fd);
+ subject = CERT_NameToAscii(&cert->subject);
+ issuer = CERT_NameToAscii(&cert->issuer);
+ wpa_printf(MSG_DEBUG, "NSS: Peer certificate subject='%s' issuer='%s'",
+ subject, issuer);
+ CERT_DestroyCertificate(cert);
+ PR_Free(subject);
+ PR_Free(issuer);
+ if (conn->verify_peer)
+ res = SECFailure;
+
+ return res;
+}
+
+
+static void nss_handshake_cb(PRFileDesc *fd, void *client_data)
+{
+ struct tls_connection *conn = client_data;
+ wpa_printf(MSG_DEBUG, "NSS: Handshake completed");
+ conn->established = 1;
+}
+
+
+struct tls_connection * tls_connection_init(void *tls_ctx)
+{
+ struct tls_connection *conn;
+
+ conn = os_zalloc(sizeof(*conn));
+ if (conn == NULL)
+ return NULL;
+
+ conn->fd = PR_CreateIOLayerStub(nss_layer_id, &nss_io);
+ if (conn->fd == NULL) {
+ os_free(conn);
+ return NULL;
+ }
+ conn->fd->secret = (void *) conn;
+
+ conn->fd = SSL_ImportFD(NULL, conn->fd);
+ if (conn->fd == NULL) {
+ os_free(conn);
+ return NULL;
+ }
+
+ if (SSL_OptionSet(conn->fd, SSL_SECURITY, PR_TRUE) != SECSuccess ||
+ SSL_OptionSet(conn->fd, SSL_HANDSHAKE_AS_CLIENT, PR_TRUE) !=
+ SECSuccess ||
+ SSL_OptionSet(conn->fd, SSL_HANDSHAKE_AS_SERVER, PR_FALSE) !=
+ SECSuccess ||
+ SSL_OptionSet(conn->fd, SSL_ENABLE_TLS, PR_TRUE) != SECSuccess ||
+ SSL_BadCertHook(conn->fd, nss_bad_cert_cb, conn) != SECSuccess ||
+ SSL_HandshakeCallback(conn->fd, nss_handshake_cb, conn) !=
+ SECSuccess) {
+ wpa_printf(MSG_ERROR, "NSS: Failed to set options");
+ PR_Close(conn->fd);
+ os_free(conn);
+ return NULL;
+ }
+
+ SSL_ResetHandshake(conn->fd, PR_FALSE);
+
+ return conn;
+}
+
+
+void tls_connection_deinit(void *tls_ctx, struct tls_connection *conn)
+{
+ PR_Close(conn->fd);
+ os_free(conn->push_buf);
+ os_free(conn->pull_buf);
+ os_free(conn);
+}
+
+
+int tls_connection_established(void *tls_ctx, struct tls_connection *conn)
+{
+ return conn->established;
+}
+
+
+int tls_connection_shutdown(void *tls_ctx, struct tls_connection *conn)
+{
+ return -1;
+}
+
+
+int tls_connection_set_params(void *tls_ctx, struct tls_connection *conn,
+ const struct tls_connection_params *params)
+{
+ wpa_printf(MSG_ERROR, "NSS: TODO - %s", __func__);
+ return 0;
+}
+
+
+int tls_global_set_params(void *tls_ctx,
+ const struct tls_connection_params *params)
+{
+ return -1;
+}
+
+
+int tls_global_set_verify(void *tls_ctx, int check_crl)
+{
+ return -1;
+}
+
+
+int tls_connection_set_verify(void *tls_ctx, struct tls_connection *conn,
+ int verify_peer)
+{
+ conn->verify_peer = verify_peer;
+ return 0;
+}
+
+
+int tls_connection_set_ia(void *tls_ctx, struct tls_connection *conn,
+ int tls_ia)
+{
+ return -1;
+}
+
+
+int tls_connection_get_keys(void *tls_ctx, struct tls_connection *conn,
+ struct tls_keys *keys)
+{
+ /* NSS does not export master secret or client/server random. */
+ return -1;
+}
+
+
+int tls_connection_prf(void *tls_ctx, struct tls_connection *conn,
+ const char *label, int server_random_first,
+ u8 *out, size_t out_len)
+{
+ if (conn == NULL || server_random_first) {
+ wpa_printf(MSG_INFO, "NSS: Unsupported PRF request "
+ "(server_random_first=%d)",
+ server_random_first);
+ return -1;
+ }
+
+ if (SSL_ExportKeyingMaterial(conn->fd, label, NULL, 0, out, out_len) !=
+ SECSuccess) {
+ wpa_printf(MSG_INFO, "NSS: Failed to use TLS extractor "
+ "(label='%s' out_len=%d", label, (int) out_len);
+ return -1;
+ }
+
+ return 0;
+}
+
+
+struct wpabuf * tls_connection_handshake(void *tls_ctx,
+ struct tls_connection *conn,
+ const struct wpabuf *in_data,
+ struct wpabuf **appl_data)
+{
+ struct wpabuf *out_data;
+
+ wpa_printf(MSG_DEBUG, "NSS: handshake: in_len=%u",
+ in_data ? (unsigned int) wpabuf_len(in_data) : 0);
+
+ if (appl_data)
+ *appl_data = NULL;
+
+ if (in_data && wpabuf_len(in_data) > 0) {
+ if (conn->pull_buf) {
+ wpa_printf(MSG_DEBUG, "%s - %lu bytes remaining in "
+ "pull_buf", __func__,
+ (unsigned long) conn->pull_buf_len);
+ os_free(conn->pull_buf);
+ }
+ conn->pull_buf = os_malloc(wpabuf_len(in_data));
+ if (conn->pull_buf == NULL)
+ return NULL;
+ os_memcpy(conn->pull_buf, wpabuf_head(in_data),
+ wpabuf_len(in_data));
+ conn->pull_buf_offset = conn->pull_buf;
+ conn->pull_buf_len = wpabuf_len(in_data);
+ }
+
+ SSL_ForceHandshake(conn->fd);
+
+ if (conn->established && conn->push_buf == NULL) {
+ /* Need to return something to get final TLS ACK. */
+ conn->push_buf = os_malloc(1);
+ }
+
+ if (conn->push_buf == NULL)
+ return NULL;
+ out_data = wpabuf_alloc_ext_data(conn->push_buf, conn->push_buf_len);
+ if (out_data == NULL)
+ os_free(conn->push_buf);
+ conn->push_buf = NULL;
+ conn->push_buf_len = 0;
+ return out_data;
+}
+
+
+struct wpabuf * tls_connection_server_handshake(void *tls_ctx,
+ struct tls_connection *conn,
+ const struct wpabuf *in_data,
+ struct wpabuf **appl_data)
+{
+ return NULL;
+}
+
+
+struct wpabuf * tls_connection_encrypt(void *tls_ctx,
+ struct tls_connection *conn,
+ const struct wpabuf *in_data)
+{
+ PRInt32 res;
+ struct wpabuf *buf;
+
+ wpa_printf(MSG_DEBUG, "NSS: encrypt %d bytes",
+ (int) wpabuf_len(in_data));
+ res = PR_Send(conn->fd, wpabuf_head(in_data), wpabuf_len(in_data), 0,
+ 0);
+ if (res < 0) {
+ wpa_printf(MSG_ERROR, "NSS: Encryption failed");
+ return NULL;
+ }
+ if (conn->push_buf == NULL)
+ return NULL;
+ buf = wpabuf_alloc_ext_data(conn->push_buf, conn->push_buf_len);
+ if (buf == NULL)
+ os_free(conn->push_buf);
+ conn->push_buf = NULL;
+ conn->push_buf_len = 0;
+ return buf;
+}
+
+
+struct wpabuf * tls_connection_decrypt(void *tls_ctx,
+ struct tls_connection *conn,
+ const struct wpabuf *in_data)
+{
+ PRInt32 res;
+ struct wpabuf *out;
+
+ wpa_printf(MSG_DEBUG, "NSS: decrypt %d bytes",
+ (int) wpabuf_len(in_data));
+ if (conn->pull_buf) {
+ wpa_printf(MSG_DEBUG, "%s - %lu bytes remaining in "
+ "pull_buf", __func__,
+ (unsigned long) conn->pull_buf_len);
+ os_free(conn->pull_buf);
+ }
+ conn->pull_buf = os_malloc(wpabuf_len(in_data));
+ if (conn->pull_buf == NULL)
+ return NULL;
+ os_memcpy(conn->pull_buf, wpabuf_head(in_data), wpabuf_len(in_data));
+ conn->pull_buf_offset = conn->pull_buf;
+ conn->pull_buf_len = wpabuf_len(in_data);
+
+ /*
+ * Even though we try to disable TLS compression, it is possible that
+ * this cannot be done with all TLS libraries. Add extra buffer space
+ * to handle the possibility of the decrypted data being longer than
+ * input data.
+ */
+ out = wpabuf_alloc((wpabuf_len(in_data) + 500) * 3);
+ if (out == NULL)
+ return NULL;
+
+ res = PR_Recv(conn->fd, wpabuf_mhead(out), wpabuf_size(out), 0, 0);
+ wpa_printf(MSG_DEBUG, "NSS: PR_Recv: %d", res);
+ if (res < 0) {
+ wpabuf_free(out);
+ return NULL;
+ }
+ wpabuf_put(out, res);
+
+ return out;
+}
+
+
+int tls_connection_resumed(void *tls_ctx, struct tls_connection *conn)
+{
+ return 0;
+}
+
+
+int tls_connection_set_cipher_list(void *tls_ctx, struct tls_connection *conn,
+ u8 *ciphers)
+{
+ return -1;
+}
+
+
+int tls_get_cipher(void *tls_ctx, struct tls_connection *conn,
+ char *buf, size_t buflen)
+{
+ return -1;
+}
+
+
+int tls_connection_enable_workaround(void *tls_ctx,
+ struct tls_connection *conn)
+{
+ return -1;
+}
+
+
+int tls_connection_client_hello_ext(void *tls_ctx, struct tls_connection *conn,
+ int ext_type, const u8 *data,
+ size_t data_len)
+{
+ return -1;
+}
+
+
+int tls_connection_get_failed(void *tls_ctx, struct tls_connection *conn)
+{
+ return 0;
+}
+
+
+int tls_connection_get_read_alerts(void *tls_ctx, struct tls_connection *conn)
+{
+ return 0;
+}
+
+
+int tls_connection_get_write_alerts(void *tls_ctx,
+ struct tls_connection *conn)
+{
+ return 0;
+}
+
+
+int tls_connection_get_keyblock_size(void *tls_ctx,
+ struct tls_connection *conn)
+{
+ return -1;
+}
+
+
+unsigned int tls_capabilities(void *tls_ctx)
+{
+ return 0;
+}
+
+
+struct wpabuf * tls_connection_ia_send_phase_finished(
+ void *tls_ctx, struct tls_connection *conn, int final)
+{
+ return NULL;
+}
+
+
+int tls_connection_ia_final_phase_finished(void *tls_ctx,
+ struct tls_connection *conn)
+{
+ return -1;
+}
+
+
+int tls_connection_ia_permute_inner_secret(void *tls_ctx,
+ struct tls_connection *conn,
+ const u8 *key, size_t key_len)
+{
+ return -1;
+}
+
+
+int tls_connection_set_session_ticket_cb(void *tls_ctx,
+ struct tls_connection *conn,
+ tls_session_ticket_cb cb,
+ void *ctx)
+{
+ return -1;
+}
diff --git a/contrib/wpa/src/crypto/tls_openssl.c b/contrib/wpa/src/crypto/tls_openssl.c
index b5a1d64..c0a40f9 100644
--- a/contrib/wpa/src/crypto/tls_openssl.c
+++ b/contrib/wpa/src/crypto/tls_openssl.c
@@ -1,6 +1,6 @@
/*
- * WPA Supplicant / SSL/TLS interface functions for openssl
- * Copyright (c) 2004-2008, Jouni Malinen <j@w1.fi>
+ * SSL/TLS interface functions for OpenSSL
+ * Copyright (c) 2004-2010, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -29,6 +29,7 @@
#endif /* OPENSSL_NO_ENGINE */
#include "common.h"
+#include "crypto.h"
#include "tls.h"
#if OPENSSL_VERSION_NUMBER >= 0x0090800fL
@@ -49,6 +50,15 @@
static int tls_openssl_ref_count = 0;
+struct tls_global {
+ void (*event_cb)(void *ctx, enum tls_event ev,
+ union tls_event_data *data);
+ void *cb_ctx;
+};
+
+static struct tls_global *tls_global = NULL;
+
+
struct tls_connection {
SSL *ssl;
BIO *ssl_in, *ssl_out;
@@ -65,6 +75,12 @@ struct tls_connection {
/* SessionTicket received from OpenSSL hello_extension_cb (server) */
u8 *session_ticket;
size_t session_ticket_len;
+
+ unsigned int ca_cert_verify:1;
+ unsigned int cert_probe:1;
+ unsigned int server_cert_only:1;
+
+ u8 srv_cert_hash[32];
};
@@ -665,6 +681,34 @@ void * tls_init(const struct tls_config *conf)
SSL_CTX *ssl;
if (tls_openssl_ref_count == 0) {
+ tls_global = os_zalloc(sizeof(*tls_global));
+ if (tls_global == NULL)
+ return NULL;
+ if (conf) {
+ tls_global->event_cb = conf->event_cb;
+ tls_global->cb_ctx = conf->cb_ctx;
+ }
+
+#ifdef CONFIG_FIPS
+#ifdef OPENSSL_FIPS
+ if (conf && conf->fips_mode) {
+ if (!FIPS_mode_set(1)) {
+ wpa_printf(MSG_ERROR, "Failed to enable FIPS "
+ "mode");
+ ERR_load_crypto_strings();
+ ERR_print_errors_fp(stderr);
+ return NULL;
+ } else
+ wpa_printf(MSG_INFO, "Running in FIPS mode");
+ }
+#else /* OPENSSL_FIPS */
+ if (conf && conf->fips_mode) {
+ wpa_printf(MSG_ERROR, "FIPS mode requested, but not "
+ "supported");
+ return NULL;
+ }
+#endif /* OPENSSL_FIPS */
+#endif /* CONFIG_FIPS */
SSL_load_error_strings();
SSL_library_init();
#ifndef OPENSSL_NO_SHA256
@@ -730,6 +774,8 @@ void tls_deinit(void *ssl_ctx)
ERR_remove_state(0);
ERR_free_strings();
EVP_cleanup();
+ os_free(tls_global);
+ tls_global = NULL;
}
}
@@ -996,6 +1042,124 @@ static int tls_match_altsubject(X509 *cert, const char *match)
}
+static enum tls_fail_reason openssl_tls_fail_reason(int err)
+{
+ switch (err) {
+ case X509_V_ERR_CERT_REVOKED:
+ return TLS_FAIL_REVOKED;
+ case X509_V_ERR_CERT_NOT_YET_VALID:
+ case X509_V_ERR_CRL_NOT_YET_VALID:
+ return TLS_FAIL_NOT_YET_VALID;
+ case X509_V_ERR_CERT_HAS_EXPIRED:
+ case X509_V_ERR_CRL_HAS_EXPIRED:
+ return TLS_FAIL_EXPIRED;
+ case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
+ case X509_V_ERR_UNABLE_TO_GET_CRL:
+ case X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER:
+ case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN:
+ case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY:
+ case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
+ case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE:
+ case X509_V_ERR_CERT_CHAIN_TOO_LONG:
+ case X509_V_ERR_PATH_LENGTH_EXCEEDED:
+ case X509_V_ERR_INVALID_CA:
+ return TLS_FAIL_UNTRUSTED;
+ case X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE:
+ case X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE:
+ case X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY:
+ case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
+ case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
+ case X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD:
+ case X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD:
+ case X509_V_ERR_CERT_UNTRUSTED:
+ case X509_V_ERR_CERT_REJECTED:
+ return TLS_FAIL_BAD_CERTIFICATE;
+ default:
+ return TLS_FAIL_UNSPECIFIED;
+ }
+}
+
+
+static struct wpabuf * get_x509_cert(X509 *cert)
+{
+ struct wpabuf *buf;
+ u8 *tmp;
+
+ int cert_len = i2d_X509(cert, NULL);
+ if (cert_len <= 0)
+ return NULL;
+
+ buf = wpabuf_alloc(cert_len);
+ if (buf == NULL)
+ return NULL;
+
+ tmp = wpabuf_put(buf, cert_len);
+ i2d_X509(cert, &tmp);
+ return buf;
+}
+
+
+static void openssl_tls_fail_event(struct tls_connection *conn,
+ X509 *err_cert, int err, int depth,
+ const char *subject, const char *err_str,
+ enum tls_fail_reason reason)
+{
+ union tls_event_data ev;
+ struct wpabuf *cert = NULL;
+
+ if (tls_global->event_cb == NULL)
+ return;
+
+ cert = get_x509_cert(err_cert);
+ os_memset(&ev, 0, sizeof(ev));
+ ev.cert_fail.reason = reason != TLS_FAIL_UNSPECIFIED ?
+ reason : openssl_tls_fail_reason(err);
+ ev.cert_fail.depth = depth;
+ ev.cert_fail.subject = subject;
+ ev.cert_fail.reason_txt = err_str;
+ ev.cert_fail.cert = cert;
+ tls_global->event_cb(tls_global->cb_ctx, TLS_CERT_CHAIN_FAILURE, &ev);
+ wpabuf_free(cert);
+}
+
+
+static void openssl_tls_cert_event(struct tls_connection *conn,
+ X509 *err_cert, int depth,
+ const char *subject)
+{
+ struct wpabuf *cert = NULL;
+ union tls_event_data ev;
+#ifdef CONFIG_SHA256
+ u8 hash[32];
+#endif /* CONFIG_SHA256 */
+
+ if (tls_global->event_cb == NULL)
+ return;
+
+ os_memset(&ev, 0, sizeof(ev));
+ if (conn->cert_probe) {
+ cert = get_x509_cert(err_cert);
+ ev.peer_cert.cert = cert;
+ }
+#ifdef CONFIG_SHA256
+ if (cert) {
+ const u8 *addr[1];
+ size_t len[1];
+ addr[0] = wpabuf_head(cert);
+ len[0] = wpabuf_len(cert);
+ if (sha256_vector(1, addr, len, hash) == 0) {
+ ev.peer_cert.hash = hash;
+ ev.peer_cert.hash_len = sizeof(hash);
+ }
+ }
+#endif /* CONFIG_SHA256 */
+ ev.peer_cert.depth = depth;
+ ev.peer_cert.subject = subject;
+ tls_global->event_cb(tls_global->cb_ctx, TLS_PEER_CERTIFICATE, &ev);
+ wpabuf_free(cert);
+}
+
+
static int tls_verify_cb(int preverify_ok, X509_STORE_CTX *x509_ctx)
{
char buf[256];
@@ -1004,6 +1168,7 @@ static int tls_verify_cb(int preverify_ok, X509_STORE_CTX *x509_ctx)
SSL *ssl;
struct tls_connection *conn;
char *match, *altmatch;
+ const char *err_str;
err_cert = X509_STORE_CTX_get_current_cert(x509_ctx);
err = X509_STORE_CTX_get_error(x509_ctx);
@@ -1016,26 +1181,77 @@ static int tls_verify_cb(int preverify_ok, X509_STORE_CTX *x509_ctx)
match = conn ? conn->subject_match : NULL;
altmatch = conn ? conn->altsubject_match : NULL;
- if (!preverify_ok) {
- wpa_printf(MSG_WARNING, "TLS: Certificate verification failed,"
- " error %d (%s) depth %d for '%s'", err,
- X509_verify_cert_error_string(err), depth, buf);
- } else {
- wpa_printf(MSG_DEBUG, "TLS: tls_verify_cb - "
- "preverify_ok=%d err=%d (%s) depth=%d buf='%s'",
- preverify_ok, err,
- X509_verify_cert_error_string(err), depth, buf);
- if (depth == 0 && match && os_strstr(buf, match) == NULL) {
- wpa_printf(MSG_WARNING, "TLS: Subject '%s' did not "
- "match with '%s'", buf, match);
- preverify_ok = 0;
- } else if (depth == 0 && altmatch &&
- !tls_match_altsubject(err_cert, altmatch)) {
- wpa_printf(MSG_WARNING, "TLS: altSubjectName match "
- "'%s' not found", altmatch);
+ if (!preverify_ok && !conn->ca_cert_verify)
+ preverify_ok = 1;
+ if (!preverify_ok && depth > 0 && conn->server_cert_only)
+ preverify_ok = 1;
+
+ err_str = X509_verify_cert_error_string(err);
+
+#ifdef CONFIG_SHA256
+ if (preverify_ok && depth == 0 && conn->server_cert_only) {
+ struct wpabuf *cert;
+ cert = get_x509_cert(err_cert);
+ if (!cert) {
+ wpa_printf(MSG_DEBUG, "OpenSSL: Could not fetch "
+ "server certificate data");
preverify_ok = 0;
+ } else {
+ u8 hash[32];
+ const u8 *addr[1];
+ size_t len[1];
+ addr[0] = wpabuf_head(cert);
+ len[0] = wpabuf_len(cert);
+ if (sha256_vector(1, addr, len, hash) < 0 ||
+ os_memcmp(conn->srv_cert_hash, hash, 32) != 0) {
+ err_str = "Server certificate mismatch";
+ err = X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN;
+ preverify_ok = 0;
+ }
+ wpabuf_free(cert);
}
}
+#endif /* CONFIG_SHA256 */
+
+ if (!preverify_ok) {
+ wpa_printf(MSG_WARNING, "TLS: Certificate verification failed,"
+ " error %d (%s) depth %d for '%s'", err, err_str,
+ depth, buf);
+ openssl_tls_fail_event(conn, err_cert, err, depth, buf,
+ err_str, TLS_FAIL_UNSPECIFIED);
+ return preverify_ok;
+ }
+
+ wpa_printf(MSG_DEBUG, "TLS: tls_verify_cb - preverify_ok=%d "
+ "err=%d (%s) ca_cert_verify=%d depth=%d buf='%s'",
+ preverify_ok, err, err_str,
+ conn->ca_cert_verify, depth, buf);
+ if (depth == 0 && match && os_strstr(buf, match) == NULL) {
+ wpa_printf(MSG_WARNING, "TLS: Subject '%s' did not "
+ "match with '%s'", buf, match);
+ preverify_ok = 0;
+ openssl_tls_fail_event(conn, err_cert, err, depth, buf,
+ "Subject mismatch",
+ TLS_FAIL_SUBJECT_MISMATCH);
+ } else if (depth == 0 && altmatch &&
+ !tls_match_altsubject(err_cert, altmatch)) {
+ wpa_printf(MSG_WARNING, "TLS: altSubjectName match "
+ "'%s' not found", altmatch);
+ preverify_ok = 0;
+ openssl_tls_fail_event(conn, err_cert, err, depth, buf,
+ "AltSubject mismatch",
+ TLS_FAIL_ALTSUBJECT_MISMATCH);
+ } else
+ openssl_tls_cert_event(conn, err_cert, depth, buf);
+
+ if (conn->cert_probe && preverify_ok && depth == 0) {
+ wpa_printf(MSG_DEBUG, "OpenSSL: Reject server certificate "
+ "on probe-only run");
+ preverify_ok = 0;
+ openssl_tls_fail_event(conn, err_cert, err, depth, buf,
+ "Server certificate chain probe",
+ TLS_FAIL_SERVER_CHAIN_PROBE);
+ }
return preverify_ok;
}
@@ -1092,6 +1308,47 @@ static int tls_connection_ca_cert(void *_ssl_ctx, struct tls_connection *conn,
return -1;
}
+ SSL_set_verify(conn->ssl, SSL_VERIFY_PEER, tls_verify_cb);
+ conn->ca_cert_verify = 1;
+
+ if (ca_cert && os_strncmp(ca_cert, "probe://", 8) == 0) {
+ wpa_printf(MSG_DEBUG, "OpenSSL: Probe for server certificate "
+ "chain");
+ conn->cert_probe = 1;
+ conn->ca_cert_verify = 0;
+ return 0;
+ }
+
+ if (ca_cert && os_strncmp(ca_cert, "hash://", 7) == 0) {
+#ifdef CONFIG_SHA256
+ const char *pos = ca_cert + 7;
+ if (os_strncmp(pos, "server/sha256/", 14) != 0) {
+ wpa_printf(MSG_DEBUG, "OpenSSL: Unsupported ca_cert "
+ "hash value '%s'", ca_cert);
+ return -1;
+ }
+ pos += 14;
+ if (os_strlen(pos) != 32 * 2) {
+ wpa_printf(MSG_DEBUG, "OpenSSL: Unexpected SHA256 "
+ "hash length in ca_cert '%s'", ca_cert);
+ return -1;
+ }
+ if (hexstr2bin(pos, conn->srv_cert_hash, 32) < 0) {
+ wpa_printf(MSG_DEBUG, "OpenSSL: Invalid SHA256 hash "
+ "value in ca_cert '%s'", ca_cert);
+ return -1;
+ }
+ conn->server_cert_only = 1;
+ wpa_printf(MSG_DEBUG, "OpenSSL: Checking only server "
+ "certificate match");
+ return 0;
+#else /* CONFIG_SHA256 */
+ wpa_printf(MSG_INFO, "No SHA256 included in the build - "
+ "cannot validate server certificate hash");
+ return -1;
+#endif /* CONFIG_SHA256 */
+ }
+
if (ca_cert_blob) {
X509 *cert = d2i_X509(NULL, (OPENSSL_d2i_TYPE) &ca_cert_blob,
ca_cert_blob_len);
@@ -1120,7 +1377,6 @@ static int tls_connection_ca_cert(void *_ssl_ctx, struct tls_connection *conn,
X509_free(cert);
wpa_printf(MSG_DEBUG, "OpenSSL: %s - added ca_cert_blob "
"to certificate store", __func__);
- SSL_set_verify(conn->ssl, SSL_VERIFY_PEER, tls_verify_cb);
return 0;
}
@@ -1129,7 +1385,6 @@ static int tls_connection_ca_cert(void *_ssl_ctx, struct tls_connection *conn,
0) {
wpa_printf(MSG_DEBUG, "OpenSSL: Added CA certificates from "
"system certificate store");
- SSL_set_verify(conn->ssl, SSL_VERIFY_PEER, tls_verify_cb);
return 0;
}
#endif /* CONFIG_NATIVE_WINDOWS */
@@ -1152,7 +1407,6 @@ static int tls_connection_ca_cert(void *_ssl_ctx, struct tls_connection *conn,
"certificate(s) loaded");
tls_get_errors(ssl_ctx);
}
- SSL_set_verify(conn->ssl, SSL_VERIFY_PEER, tls_verify_cb);
#else /* OPENSSL_NO_STDIO */
wpa_printf(MSG_DEBUG, "OpenSSL: %s - OPENSSL_NO_STDIO",
__func__);
@@ -1161,7 +1415,7 @@ static int tls_connection_ca_cert(void *_ssl_ctx, struct tls_connection *conn,
} else {
/* No ca_cert configured - do not try to verify server
* certificate */
- SSL_set_verify(conn->ssl, SSL_VERIFY_NONE, NULL);
+ conn->ca_cert_verify = 0;
}
return 0;
@@ -1246,10 +1500,12 @@ int tls_connection_set_verify(void *ssl_ctx, struct tls_connection *conn,
return -1;
if (verify_peer) {
+ conn->ca_cert_verify = 1;
SSL_set_verify(conn->ssl, SSL_VERIFY_PEER |
SSL_VERIFY_FAIL_IF_NO_PEER_CERT |
SSL_VERIFY_CLIENT_ONCE, tls_verify_cb);
} else {
+ conn->ca_cert_verify = 0;
SSL_set_verify(conn->ssl, SSL_VERIFY_NONE, NULL);
}
@@ -1979,30 +2235,30 @@ int tls_connection_prf(void *tls_ctx, struct tls_connection *conn,
}
-u8 * tls_connection_handshake(void *ssl_ctx, struct tls_connection *conn,
- const u8 *in_data, size_t in_len,
- size_t *out_len, u8 **appl_data,
- size_t *appl_data_len)
+static struct wpabuf *
+openssl_handshake(struct tls_connection *conn, const struct wpabuf *in_data,
+ int server)
{
int res;
- u8 *out_data;
-
- if (appl_data)
- *appl_data = NULL;
+ struct wpabuf *out_data;
/*
* Give TLS handshake data from the server (if available) to OpenSSL
* for processing.
*/
if (in_data &&
- BIO_write(conn->ssl_in, in_data, in_len) < 0) {
+ BIO_write(conn->ssl_in, wpabuf_head(in_data), wpabuf_len(in_data))
+ < 0) {
tls_show_errors(MSG_INFO, __func__,
"Handshake failed - BIO_write");
return NULL;
}
/* Initiate TLS handshake or continue the existing handshake */
- res = SSL_connect(conn->ssl);
+ if (server)
+ res = SSL_accept(conn->ssl);
+ else
+ res = SSL_connect(conn->ssl);
if (res != 1) {
int err = SSL_get_error(conn->ssl, res);
if (err == SSL_ERROR_WANT_READ)
@@ -2020,7 +2276,7 @@ u8 * tls_connection_handshake(void *ssl_ctx, struct tls_connection *conn,
/* Get the TLS handshake data to be sent to the server */
res = BIO_ctrl_pending(conn->ssl_out);
wpa_printf(MSG_DEBUG, "SSL: %d bytes pending from ssl_out", res);
- out_data = os_malloc(res == 0 ? 1 : res);
+ out_data = wpabuf_alloc(res);
if (out_data == NULL) {
wpa_printf(MSG_DEBUG, "SSL: Failed to allocate memory for "
"handshake output (%d bytes)", res);
@@ -2028,10 +2284,10 @@ u8 * tls_connection_handshake(void *ssl_ctx, struct tls_connection *conn,
tls_show_errors(MSG_INFO, __func__,
"BIO_reset failed");
}
- *out_len = 0;
return NULL;
}
- res = res == 0 ? 0 : BIO_read(conn->ssl_out, out_data, res);
+ res = res == 0 ? 0 : BIO_read(conn->ssl_out, wpabuf_mhead(out_data),
+ res);
if (res < 0) {
tls_show_errors(MSG_INFO, __func__,
"Handshake failed - BIO_read");
@@ -2039,169 +2295,169 @@ u8 * tls_connection_handshake(void *ssl_ctx, struct tls_connection *conn,
tls_show_errors(MSG_INFO, __func__,
"BIO_reset failed");
}
- *out_len = 0;
+ wpabuf_free(out_data);
return NULL;
}
- *out_len = res;
-
- if (SSL_is_init_finished(conn->ssl) && appl_data) {
- *appl_data = os_malloc(in_len);
- if (*appl_data) {
- res = SSL_read(conn->ssl, *appl_data, in_len);
- if (res < 0) {
- int err = SSL_get_error(conn->ssl, res);
- if (err == SSL_ERROR_WANT_READ ||
- err == SSL_ERROR_WANT_WRITE) {
- wpa_printf(MSG_DEBUG,
- "SSL: No Application Data "
- "included");
- } else {
- tls_show_errors(MSG_INFO, __func__,
- "Failed to read "
- "possible "
- "Application Data");
- }
- os_free(*appl_data);
- *appl_data = NULL;
- } else {
- *appl_data_len = res;
- wpa_hexdump_key(MSG_MSGDUMP, "SSL: Application"
- " Data in Finish message",
- *appl_data, *appl_data_len);
- }
- }
- }
+ wpabuf_put(out_data, res);
return out_data;
}
-u8 * tls_connection_server_handshake(void *ssl_ctx,
- struct tls_connection *conn,
- const u8 *in_data, size_t in_len,
- size_t *out_len)
+static struct wpabuf *
+openssl_get_appl_data(struct tls_connection *conn, size_t max_len)
{
+ struct wpabuf *appl_data;
int res;
- u8 *out_data;
- /*
- * Give TLS handshake data from the client (if available) to OpenSSL
- * for processing.
- */
- if (in_data &&
- BIO_write(conn->ssl_in, in_data, in_len) < 0) {
- tls_show_errors(MSG_INFO, __func__,
- "Handshake failed - BIO_write");
+ appl_data = wpabuf_alloc(max_len + 100);
+ if (appl_data == NULL)
return NULL;
- }
- /* Initiate TLS handshake or continue the existing handshake */
- res = SSL_accept(conn->ssl);
- if (res != 1) {
+ res = SSL_read(conn->ssl, wpabuf_mhead(appl_data),
+ wpabuf_size(appl_data));
+ if (res < 0) {
int err = SSL_get_error(conn->ssl, res);
- if (err == SSL_ERROR_WANT_READ)
- wpa_printf(MSG_DEBUG, "SSL: SSL_accept - want "
- "more data");
- else if (err == SSL_ERROR_WANT_WRITE)
- wpa_printf(MSG_DEBUG, "SSL: SSL_accept - want to "
- "write");
- else {
- tls_show_errors(MSG_INFO, __func__, "SSL_accept");
- return NULL;
- }
- }
-
- /* Get the TLS handshake data to be sent to the client */
- res = BIO_ctrl_pending(conn->ssl_out);
- wpa_printf(MSG_DEBUG, "SSL: %d bytes pending from ssl_out", res);
- out_data = os_malloc(res == 0 ? 1 : res);
- if (out_data == NULL) {
- wpa_printf(MSG_DEBUG, "SSL: Failed to allocate memory for "
- "handshake output (%d bytes)", res);
- if (BIO_reset(conn->ssl_out) < 0) {
+ if (err == SSL_ERROR_WANT_READ ||
+ err == SSL_ERROR_WANT_WRITE) {
+ wpa_printf(MSG_DEBUG, "SSL: No Application Data "
+ "included");
+ } else {
tls_show_errors(MSG_INFO, __func__,
- "BIO_reset failed");
+ "Failed to read possible "
+ "Application Data");
}
- *out_len = 0;
+ wpabuf_free(appl_data);
return NULL;
}
- res = res == 0 ? 0 : BIO_read(conn->ssl_out, out_data, res);
- if (res < 0) {
- tls_show_errors(MSG_INFO, __func__,
- "Handshake failed - BIO_read");
- if (BIO_reset(conn->ssl_out) < 0) {
- tls_show_errors(MSG_INFO, __func__,
- "BIO_reset failed");
- }
- *out_len = 0;
+
+ wpabuf_put(appl_data, res);
+ wpa_hexdump_buf_key(MSG_MSGDUMP, "SSL: Application Data in Finished "
+ "message", appl_data);
+
+ return appl_data;
+}
+
+
+static struct wpabuf *
+openssl_connection_handshake(struct tls_connection *conn,
+ const struct wpabuf *in_data,
+ struct wpabuf **appl_data, int server)
+{
+ struct wpabuf *out_data;
+
+ if (appl_data)
+ *appl_data = NULL;
+
+ out_data = openssl_handshake(conn, in_data, server);
+ if (out_data == NULL)
return NULL;
- }
- *out_len = res;
+
+ if (SSL_is_init_finished(conn->ssl) && appl_data && in_data)
+ *appl_data = openssl_get_appl_data(conn, wpabuf_len(in_data));
+
return out_data;
}
-int tls_connection_encrypt(void *ssl_ctx, struct tls_connection *conn,
- const u8 *in_data, size_t in_len,
- u8 *out_data, size_t out_len)
+struct wpabuf *
+tls_connection_handshake(void *ssl_ctx, struct tls_connection *conn,
+ const struct wpabuf *in_data,
+ struct wpabuf **appl_data)
+{
+ return openssl_connection_handshake(conn, in_data, appl_data, 0);
+}
+
+
+struct wpabuf * tls_connection_server_handshake(void *tls_ctx,
+ struct tls_connection *conn,
+ const struct wpabuf *in_data,
+ struct wpabuf **appl_data)
+{
+ return openssl_connection_handshake(conn, in_data, appl_data, 1);
+}
+
+
+struct wpabuf * tls_connection_encrypt(void *tls_ctx,
+ struct tls_connection *conn,
+ const struct wpabuf *in_data)
{
int res;
+ struct wpabuf *buf;
if (conn == NULL)
- return -1;
+ return NULL;
/* Give plaintext data for OpenSSL to encrypt into the TLS tunnel. */
if ((res = BIO_reset(conn->ssl_in)) < 0 ||
(res = BIO_reset(conn->ssl_out)) < 0) {
tls_show_errors(MSG_INFO, __func__, "BIO_reset failed");
- return res;
+ return NULL;
}
- res = SSL_write(conn->ssl, in_data, in_len);
+ res = SSL_write(conn->ssl, wpabuf_head(in_data), wpabuf_len(in_data));
if (res < 0) {
tls_show_errors(MSG_INFO, __func__,
"Encryption failed - SSL_write");
- return res;
+ return NULL;
}
/* Read encrypted data to be sent to the server */
- res = BIO_read(conn->ssl_out, out_data, out_len);
+ buf = wpabuf_alloc(wpabuf_len(in_data) + 300);
+ if (buf == NULL)
+ return NULL;
+ res = BIO_read(conn->ssl_out, wpabuf_mhead(buf), wpabuf_size(buf));
if (res < 0) {
tls_show_errors(MSG_INFO, __func__,
"Encryption failed - BIO_read");
- return res;
+ wpabuf_free(buf);
+ return NULL;
}
+ wpabuf_put(buf, res);
- return res;
+ return buf;
}
-int tls_connection_decrypt(void *ssl_ctx, struct tls_connection *conn,
- const u8 *in_data, size_t in_len,
- u8 *out_data, size_t out_len)
+struct wpabuf * tls_connection_decrypt(void *tls_ctx,
+ struct tls_connection *conn,
+ const struct wpabuf *in_data)
{
int res;
+ struct wpabuf *buf;
/* Give encrypted data from TLS tunnel for OpenSSL to decrypt. */
- res = BIO_write(conn->ssl_in, in_data, in_len);
+ res = BIO_write(conn->ssl_in, wpabuf_head(in_data),
+ wpabuf_len(in_data));
if (res < 0) {
tls_show_errors(MSG_INFO, __func__,
"Decryption failed - BIO_write");
- return res;
+ return NULL;
}
if (BIO_reset(conn->ssl_out) < 0) {
tls_show_errors(MSG_INFO, __func__, "BIO_reset failed");
- return res;
+ return NULL;
}
/* Read decrypted data for further processing */
- res = SSL_read(conn->ssl, out_data, out_len);
+ /*
+ * Even though we try to disable TLS compression, it is possible that
+ * this cannot be done with all TLS libraries. Add extra buffer space
+ * to handle the possibility of the decrypted data being longer than
+ * input data.
+ */
+ buf = wpabuf_alloc((wpabuf_len(in_data) + 500) * 3);
+ if (buf == NULL)
+ return NULL;
+ res = SSL_read(conn->ssl, wpabuf_mhead(buf), wpabuf_size(buf));
if (res < 0) {
tls_show_errors(MSG_INFO, __func__,
"Decryption failed - SSL_read");
- return res;
+ wpabuf_free(buf);
+ return NULL;
}
+ wpabuf_put(buf, res);
- return res;
+ return buf;
}
@@ -2292,7 +2548,7 @@ int tls_connection_enable_workaround(void *ssl_ctx,
}
-#if defined(EAP_FAST) || defined(EAP_FAST_DYNAMIC)
+#if defined(EAP_FAST) || defined(EAP_FAST_DYNAMIC) || defined(EAP_SERVER_FAST)
/* ClientHello TLS extensions require a patch to openssl, so this function is
* commented out unless explicitly needed for EAP-FAST in order to be able to
* build this file with unmodified openssl. */
@@ -2315,7 +2571,7 @@ int tls_connection_client_hello_ext(void *ssl_ctx, struct tls_connection *conn,
return 0;
}
-#endif /* EAP_FAST || EAP_FAST_DYNAMIC */
+#endif /* EAP_FAST || EAP_FAST_DYNAMIC || EAP_SERVER_FAST */
int tls_connection_get_failed(void *ssl_ctx, struct tls_connection *conn)
@@ -2482,12 +2738,10 @@ int tls_connection_set_ia(void *tls_ctx, struct tls_connection *conn,
}
-int tls_connection_ia_send_phase_finished(void *tls_ctx,
- struct tls_connection *conn,
- int final,
- u8 *out_data, size_t out_len)
+struct wpabuf * tls_connection_ia_send_phase_finished(
+ void *tls_ctx, struct tls_connection *conn, int final)
{
- return -1;
+ return NULL;
}
@@ -2506,7 +2760,7 @@ int tls_connection_ia_permute_inner_secret(void *tls_ctx,
}
-#if defined(EAP_FAST) || defined(EAP_FAST_DYNAMIC)
+#if defined(EAP_FAST) || defined(EAP_FAST_DYNAMIC) || defined(EAP_SERVER_FAST)
/* Pre-shared secred requires a patch to openssl, so this function is
* commented out unless explicitly needed for EAP-FAST in order to be able to
* build this file with unmodified openssl. */
@@ -2619,7 +2873,7 @@ static int tls_hello_ext_cb(SSL *s, TLS_EXTENSION *ext, void *arg)
}
#endif /* SSL_OP_NO_TICKET */
#endif /* CONFIG_OPENSSL_TICKET_OVERRIDE */
-#endif /* EAP_FAST || EAP_FAST_DYNAMIC */
+#endif /* EAP_FAST || EAP_FAST_DYNAMIC || EAP_SERVER_FAST */
int tls_connection_set_session_ticket_cb(void *tls_ctx,
@@ -2627,7 +2881,7 @@ int tls_connection_set_session_ticket_cb(void *tls_ctx,
tls_session_ticket_cb cb,
void *ctx)
{
-#if defined(EAP_FAST) || defined(EAP_FAST_DYNAMIC)
+#if defined(EAP_FAST) || defined(EAP_FAST_DYNAMIC) || defined(EAP_SERVER_FAST)
conn->session_ticket_cb = cb;
conn->session_ticket_cb_ctx = ctx;
@@ -2665,7 +2919,7 @@ int tls_connection_set_session_ticket_cb(void *tls_ctx,
}
return 0;
-#else /* EAP_FAST || EAP_FAST_DYNAMIC */
+#else /* EAP_FAST || EAP_FAST_DYNAMIC || EAP_SERVER_FAST */
return -1;
-#endif /* EAP_FAST || EAP_FAST_DYNAMIC */
+#endif /* EAP_FAST || EAP_FAST_DYNAMIC || EAP_SERVER_FAST */
}
diff --git a/contrib/wpa/src/crypto/tls_schannel.c b/contrib/wpa/src/crypto/tls_schannel.c
index 87e7435..4a94e99 100644
--- a/contrib/wpa/src/crypto/tls_schannel.c
+++ b/contrib/wpa/src/crypto/tls_schannel.c
@@ -1,6 +1,6 @@
/*
- * WPA Supplicant / SSL/TLS interface functions for Microsoft Schannel
- * Copyright (c) 2005, Jouni Malinen <j@w1.fi>
+ * SSL/TLS interface functions for Microsoft Schannel
+ * Copyright (c) 2005-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -215,9 +215,8 @@ int tls_connection_prf(void *tls_ctx, struct tls_connection *conn,
}
-static u8 * tls_conn_hs_clienthello(struct tls_global *global,
- struct tls_connection *conn,
- size_t *out_len)
+static struct wpabuf * tls_conn_hs_clienthello(struct tls_global *global,
+ struct tls_connection *conn)
{
DWORD sspi_flags, sspi_flags_out;
SecBufferDesc outbuf;
@@ -260,15 +259,14 @@ static u8 * tls_conn_hs_clienthello(struct tls_global *global,
}
if (outbufs[0].cbBuffer != 0 && outbufs[0].pvBuffer) {
- u8 *buf;
+ struct wpabuf *buf;
wpa_hexdump(MSG_MSGDUMP, "SChannel - ClientHello",
outbufs[0].pvBuffer, outbufs[0].cbBuffer);
conn->start = 0;
- *out_len = outbufs[0].cbBuffer;
- buf = os_malloc(*out_len);
+ buf = wpabuf_alloc_copy(outbufs[0].pvBuffer,
+ outbufs[0].cbBuffer);
if (buf == NULL)
return NULL;
- os_memcpy(buf, outbufs[0].pvBuffer, *out_len);
global->sspi->FreeContextBuffer(outbufs[0].pvBuffer);
return buf;
}
@@ -316,28 +314,27 @@ static int tls_get_eap(struct tls_global *global, struct tls_connection *conn)
}
-u8 * tls_connection_handshake(void *ssl_ctx, struct tls_connection *conn,
- const u8 *in_data, size_t in_len,
- size_t *out_len, u8 **appl_data,
- size_t *appl_data_len)
+struct wpabuf * tls_connection_handshake(void *tls_ctx,
+ struct tls_connection *conn,
+ const struct wpabuf *in_data,
+ struct wpabuf **appl_data)
{
- struct tls_global *global = ssl_ctx;
+ struct tls_global *global = tls_ctx;
DWORD sspi_flags, sspi_flags_out;
SecBufferDesc inbuf, outbuf;
SecBuffer inbufs[2], outbufs[1];
SECURITY_STATUS status;
TimeStamp ts_expiry;
- u8 *out_buf = NULL;
+ struct wpabuf *out_buf = NULL;
if (appl_data)
*appl_data = NULL;
- if (conn->start) {
- return tls_conn_hs_clienthello(global, conn, out_len);
- }
+ if (conn->start)
+ return tls_conn_hs_clienthello(global, conn);
wpa_printf(MSG_DEBUG, "SChannel: %d bytes handshake data to process",
- in_len);
+ (int) wpabuf_len(in_data));
sspi_flags = ISC_REQ_REPLAY_DETECT |
ISC_REQ_CONFIDENTIALITY |
@@ -346,8 +343,8 @@ u8 * tls_connection_handshake(void *ssl_ctx, struct tls_connection *conn,
ISC_REQ_MANUAL_CRED_VALIDATION;
/* Input buffer for Schannel */
- inbufs[0].pvBuffer = (u8 *) in_data;
- inbufs[0].cbBuffer = in_len;
+ inbufs[0].pvBuffer = (u8 *) wpabuf_head(in_data);
+ inbufs[0].cbBuffer = wpabuf_len(in_data);
inbufs[0].BufferType = SECBUFFER_TOKEN;
/* Place for leftover data from Schannel */
@@ -392,11 +389,8 @@ u8 * tls_connection_handshake(void *ssl_ctx, struct tls_connection *conn,
if (outbufs[0].cbBuffer != 0 && outbufs[0].pvBuffer) {
wpa_hexdump(MSG_MSGDUMP, "SChannel - output",
outbufs[0].pvBuffer, outbufs[0].cbBuffer);
- *out_len = outbufs[0].cbBuffer;
- out_buf = os_malloc(*out_len);
- if (out_buf)
- os_memcpy(out_buf, outbufs[0].pvBuffer,
- *out_len);
+ out_buf = wpabuf_alloc_copy(outbufs[0].pvBuffer,
+ outbufs[0].cbBuffer);
global->sspi->FreeContextBuffer(outbufs[0].pvBuffer);
outbufs[0].pvBuffer = NULL;
if (out_buf == NULL)
@@ -420,19 +414,16 @@ u8 * tls_connection_handshake(void *ssl_ctx, struct tls_connection *conn,
/* Need to return something to get final TLS ACK. */
if (out_buf == NULL)
- out_buf = os_malloc(1);
+ out_buf = wpabuf_alloc(0);
if (inbufs[1].BufferType == SECBUFFER_EXTRA) {
wpa_hexdump(MSG_MSGDUMP, "SChannel - Encrypted "
"application data",
inbufs[1].pvBuffer, inbufs[1].cbBuffer);
if (appl_data) {
- *appl_data_len = outbufs[1].cbBuffer;
- appl_data = os_malloc(*appl_data_len);
- if (appl_data)
- os_memcpy(appl_data,
- outbufs[1].pvBuffer,
- *appl_data_len);
+ *appl_data = wpabuf_alloc_copy(
+ outbufs[1].pvBuffer,
+ outbufs[1].cbBuffer);
}
global->sspi->FreeContextBuffer(inbufs[1].pvBuffer);
inbufs[1].pvBuffer = NULL;
@@ -470,26 +461,26 @@ u8 * tls_connection_handshake(void *ssl_ctx, struct tls_connection *conn,
}
-u8 * tls_connection_server_handshake(void *ssl_ctx,
- struct tls_connection *conn,
- const u8 *in_data, size_t in_len,
- size_t *out_len)
+struct wpabuf * tls_connection_server_handshake(void *tls_ctx,
+ struct tls_connection *conn,
+ const struct wpabuf *in_data,
+ struct wpabuf **appl_data)
{
return NULL;
}
-int tls_connection_encrypt(void *ssl_ctx, struct tls_connection *conn,
- const u8 *in_data, size_t in_len,
- u8 *out_data, size_t out_len)
+struct wpabuf * tls_connection_encrypt(void *tls_ctx,
+ struct tls_connection *conn,
+ const struct wpabuf *in_data)
{
- struct tls_global *global = ssl_ctx;
+ struct tls_global *global = tls_ctx;
SECURITY_STATUS status;
SecBufferDesc buf;
SecBuffer bufs[4];
SecPkgContext_StreamSizes sizes;
int i;
- size_t total_len;
+ struct wpabuf *out;
status = global->sspi->QueryContextAttributes(&conn->context,
SECPKG_ATTR_STREAM_SIZES,
@@ -497,34 +488,27 @@ int tls_connection_encrypt(void *ssl_ctx, struct tls_connection *conn,
if (status != SEC_E_OK) {
wpa_printf(MSG_DEBUG, "%s: QueryContextAttributes failed",
__func__);
- return -1;
+ return NULL;
}
wpa_printf(MSG_DEBUG, "%s: Stream sizes: header=%u trailer=%u",
__func__,
(unsigned int) sizes.cbHeader,
(unsigned int) sizes.cbTrailer);
- total_len = sizes.cbHeader + in_len + sizes.cbTrailer;
-
- if (out_len < total_len) {
- wpa_printf(MSG_DEBUG, "%s: too short out_data (out_len=%lu "
- "in_len=%lu total_len=%lu)", __func__,
- (unsigned long) out_len, (unsigned long) in_len,
- (unsigned long) total_len);
- return -1;
- }
+ out = wpabuf_alloc(sizes.cbHeader + wpabuf_len(in_data) +
+ sizes.cbTrailer);
os_memset(&bufs, 0, sizeof(bufs));
- bufs[0].pvBuffer = out_data;
+ bufs[0].pvBuffer = wpabuf_put(out, sizes.cbHeader);
bufs[0].cbBuffer = sizes.cbHeader;
bufs[0].BufferType = SECBUFFER_STREAM_HEADER;
- os_memcpy(out_data + sizes.cbHeader, in_data, in_len);
- bufs[1].pvBuffer = out_data + sizes.cbHeader;
- bufs[1].cbBuffer = in_len;
+ bufs[1].pvBuffer = wpabuf_put(out, 0);
+ wpabuf_put_buf(out, in_data);
+ bufs[1].cbBuffer = wpabuf_len(in_data);
bufs[1].BufferType = SECBUFFER_DATA;
- bufs[2].pvBuffer = out_data + sizes.cbHeader + in_len;
+ bufs[2].pvBuffer = wpabuf_put(out, sizes.cbTrailer);
bufs[2].cbBuffer = sizes.cbTrailer;
bufs[2].BufferType = SECBUFFER_STREAM_TRAILER;
@@ -543,7 +527,7 @@ int tls_connection_encrypt(void *ssl_ctx, struct tls_connection *conn,
(int) bufs[2].cbBuffer, (int) bufs[2].BufferType);
wpa_printf(MSG_MSGDUMP, "Schannel: EncryptMessage pointers: "
"out_data=%p bufs %p %p %p",
- out_data, bufs[0].pvBuffer, bufs[1].pvBuffer,
+ wpabuf_head(out), bufs[0].pvBuffer, bufs[1].pvBuffer,
bufs[2].pvBuffer);
for (i = 0; i < 3; i++) {
@@ -556,39 +540,37 @@ int tls_connection_encrypt(void *ssl_ctx, struct tls_connection *conn,
if (status == SEC_E_OK) {
wpa_printf(MSG_DEBUG, "%s: SEC_E_OK", __func__);
- wpa_hexdump_key(MSG_MSGDUMP, "Schannel: Encrypted data from "
- "EncryptMessage", out_data, total_len);
- return total_len;
+ wpa_hexdump_buf_key(MSG_MSGDUMP, "Schannel: Encrypted data "
+ "from EncryptMessage", out);
+ return out;
}
wpa_printf(MSG_DEBUG, "%s: Failed - status=%d",
__func__, (int) status);
- return -1;
+ wpabuf_free(out);
+ return NULL;
}
-int tls_connection_decrypt(void *ssl_ctx, struct tls_connection *conn,
- const u8 *in_data, size_t in_len,
- u8 *out_data, size_t out_len)
+struct wpabuf * tls_connection_decrypt(void *tls_ctx,
+ struct tls_connection *conn,
+ const struct wpabuf *in_data)
{
- struct tls_global *global = ssl_ctx;
+ struct tls_global *global = tls_ctx;
SECURITY_STATUS status;
SecBufferDesc buf;
SecBuffer bufs[4];
int i;
+ struct wpabuf *out, *tmp;
- if (out_len < in_len) {
- wpa_printf(MSG_DEBUG, "%s: out_len=%lu < in_len=%lu", __func__,
- (unsigned long) out_len, (unsigned long) in_len);
- return -1;
- }
-
- wpa_hexdump(MSG_MSGDUMP, "Schannel: Encrypted data to DecryptMessage",
- in_data, in_len);
+ wpa_hexdump_buf(MSG_MSGDUMP,
+ "Schannel: Encrypted data to DecryptMessage", in_data);
os_memset(&bufs, 0, sizeof(bufs));
- os_memcpy(out_data, in_data, in_len);
- bufs[0].pvBuffer = out_data;
- bufs[0].cbBuffer = in_len;
+ tmp = wpabuf_dup(in_data);
+ if (tmp == NULL)
+ return NULL;
+ bufs[0].pvBuffer = wpabuf_mhead(tmp);
+ bufs[0].cbBuffer = wpabuf_len(in_data);
bufs[0].BufferType = SECBUFFER_DATA;
bufs[1].BufferType = SECBUFFER_EMPTY;
@@ -611,7 +593,7 @@ int tls_connection_decrypt(void *ssl_ctx, struct tls_connection *conn,
(int) bufs[3].cbBuffer, (int) bufs[3].BufferType);
wpa_printf(MSG_MSGDUMP, "Schannel: DecryptMessage pointers: "
"out_data=%p bufs %p %p %p %p",
- out_data, bufs[0].pvBuffer, bufs[1].pvBuffer,
+ wpabuf_head(tmp), bufs[0].pvBuffer, bufs[1].pvBuffer,
bufs[2].pvBuffer, bufs[3].pvBuffer);
switch (status) {
@@ -628,23 +610,21 @@ int tls_connection_decrypt(void *ssl_ctx, struct tls_connection *conn,
if (i == 4) {
wpa_printf(MSG_DEBUG, "%s: No output data from "
"DecryptMessage", __func__);
- return -1;
+ wpabuf_free(tmp);
+ return NULL;
}
wpa_hexdump_key(MSG_MSGDUMP, "Schannel: Decrypted data from "
"DecryptMessage",
bufs[i].pvBuffer, bufs[i].cbBuffer);
- if (bufs[i].cbBuffer > out_len) {
- wpa_printf(MSG_DEBUG, "%s: Too long output data",
- __func__);
- return -1;
- }
- os_memmove(out_data, bufs[i].pvBuffer, bufs[i].cbBuffer);
- return bufs[i].cbBuffer;
+ out = wpabuf_alloc_copy(bufs[i].pvBuffer, bufs[i].cbBuffer);
+ wpabuf_free(tmp);
+ return out;
}
wpa_printf(MSG_DEBUG, "%s: Failed - status=%d",
__func__, (int) status);
- return -1;
+ wpabuf_free(tmp);
+ return NULL;
}
@@ -765,12 +745,10 @@ int tls_connection_set_ia(void *tls_ctx, struct tls_connection *conn,
}
-int tls_connection_ia_send_phase_finished(void *tls_ctx,
- struct tls_connection *conn,
- int final,
- u8 *out_data, size_t out_len)
+struct wpabuf * tls_connection_ia_send_phase_finished(
+ void *tls_ctx, struct tls_connection *conn, int final);
{
- return -1;
+ return NULL;
}
diff --git a/contrib/wpa/src/drivers/.gitignore b/contrib/wpa/src/drivers/.gitignore
new file mode 100644
index 0000000..1d9e0e6
--- /dev/null
+++ b/contrib/wpa/src/drivers/.gitignore
@@ -0,0 +1,2 @@
+build.wpa_supplicant
+build.hostapd
diff --git a/contrib/wpa/src/drivers/Makefile b/contrib/wpa/src/drivers/Makefile
index cffba62..07600e5 100644
--- a/contrib/wpa/src/drivers/Makefile
+++ b/contrib/wpa/src/drivers/Makefile
@@ -2,8 +2,8 @@ all:
@echo Nothing to be made.
clean:
- for d in $(SUBDIRS); do make -C $$d clean; done
rm -f *~ *.o *.d
+ rm -f build.wpa_supplicant build.hostapd
install:
@echo Nothing to be made.
diff --git a/contrib/wpa/src/drivers/driver.h b/contrib/wpa/src/drivers/driver.h
index c2975d2..fa49da4 100644
--- a/contrib/wpa/src/drivers/driver.h
+++ b/contrib/wpa/src/drivers/driver.h
@@ -1,6 +1,6 @@
/*
- * WPA Supplicant - driver interface definition
- * Copyright (c) 2003-2008, Jouni Malinen <j@w1.fi>
+ * Driver interface definition
+ * Copyright (c) 2003-2010, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -10,79 +10,117 @@
* license.
*
* See README and COPYING for more details.
+ *
+ * This file defines a driver interface used by both %wpa_supplicant and
+ * hostapd. The first part of the file defines data structures used in various
+ * driver operations. This is followed by the struct wpa_driver_ops that each
+ * driver wrapper will beed to define with callback functions for requesting
+ * driver operations. After this, there are definitions for driver event
+ * reporting with wpa_supplicant_event() and some convenience helper functions
+ * that can be used to report events.
*/
#ifndef DRIVER_H
#define DRIVER_H
-#define WPA_SUPPLICANT_DRIVER_VERSION 3
+#define WPA_SUPPLICANT_DRIVER_VERSION 4
+
+#include "common/defs.h"
+
+#define HOSTAPD_CHAN_DISABLED 0x00000001
+#define HOSTAPD_CHAN_PASSIVE_SCAN 0x00000002
+#define HOSTAPD_CHAN_NO_IBSS 0x00000004
+#define HOSTAPD_CHAN_RADAR 0x00000008
+
+/**
+ * struct hostapd_channel_data - Channel information
+ */
+struct hostapd_channel_data {
+ /**
+ * chan - Channel number (IEEE 802.11)
+ */
+ short chan;
+
+ /**
+ * freq - Frequency in MHz
+ */
+ short freq;
+
+ /**
+ * flag - Channel flags (HOSTAPD_CHAN_*)
+ */
+ int flag;
+
+ /**
+ * max_tx_power - maximum transmit power in dBm
+ */
+ u8 max_tx_power;
+};
+
+/**
+ * struct hostapd_hw_modes - Supported hardware mode information
+ */
+struct hostapd_hw_modes {
+ /**
+ * mode - Hardware mode
+ */
+ enum hostapd_hw_mode mode;
-#include "defs.h"
+ /**
+ * num_channels - Number of entries in the channels array
+ */
+ int num_channels;
+
+ /**
+ * channels - Array of supported channels
+ */
+ struct hostapd_channel_data *channels;
+
+ /**
+ * num_rates - Number of entries in the rates array
+ */
+ int num_rates;
+
+ /**
+ * rates - Array of supported rates in 100 kbps units
+ */
+ int *rates;
+
+ /**
+ * ht_capab - HT (IEEE 802.11n) capabilities
+ */
+ u16 ht_capab;
+
+ /**
+ * mcs_set - MCS (IEEE 802.11n) rate parameters
+ */
+ u8 mcs_set[16];
+
+ /**
+ * a_mpdu_params - A-MPDU (IEEE 802.11n) parameters
+ */
+ u8 a_mpdu_params;
+};
-#define AUTH_ALG_OPEN_SYSTEM 0x01
-#define AUTH_ALG_SHARED_KEY 0x02
-#define AUTH_ALG_LEAP 0x04
#define IEEE80211_MODE_INFRA 0
#define IEEE80211_MODE_IBSS 1
+#define IEEE80211_MODE_AP 2
#define IEEE80211_CAP_ESS 0x0001
#define IEEE80211_CAP_IBSS 0x0002
#define IEEE80211_CAP_PRIVACY 0x0010
-#define SSID_MAX_WPA_IE_LEN 40
-/**
- * struct wpa_scan_result - Scan results (old structure)
- * @bssid: BSSID
- * @ssid: SSID
- * @ssid_len: length of the ssid
- * @wpa_ie: WPA IE
- * @wpa_ie_len: length of the wpa_ie
- * @rsn_ie: RSN IE
- * @rsn_ie_len: length of the RSN IE
- * @freq: frequency of the channel in MHz (e.g., 2412 = channel 1)
- * @caps: capability information field in host byte order
- * @qual: signal quality
- * @noise: noise level
- * @level: signal level
- * @maxrate: maximum supported rate
- * @mdie_present: Whether MDIE was included in Beacon/ProbeRsp frame
- * @mdie: Mobility domain identifier IE (IEEE 802.11r MDIE) (starting from
- * IE type field)
- * @tsf: Timestamp
- *
- * This structure is used as a generic format for scan results from the
- * driver. Each driver interface implementation is responsible for converting
- * the driver or OS specific scan results into this format.
- *
- * This structure is the old data structure used for scan results. It is
- * obsoleted by the new struct wpa_scan_res structure and the old version is
- * only included for backwards compatibility with existing driver wrapper
- * implementations. New implementations are encouraged to implement for struct
- * wpa_scan_res. The old structure will be removed at some point.
- */
-struct wpa_scan_result {
- u8 bssid[ETH_ALEN];
- u8 ssid[32];
- size_t ssid_len;
- u8 wpa_ie[SSID_MAX_WPA_IE_LEN];
- size_t wpa_ie_len;
- u8 rsn_ie[SSID_MAX_WPA_IE_LEN];
- size_t rsn_ie_len;
- int freq;
- u16 caps;
- int qual;
- int noise;
- int level;
- int maxrate;
- int mdie_present;
- u8 mdie[5];
- u64 tsf;
-};
-
+#define WPA_SCAN_QUAL_INVALID BIT(0)
+#define WPA_SCAN_NOISE_INVALID BIT(1)
+#define WPA_SCAN_LEVEL_INVALID BIT(2)
+#define WPA_SCAN_LEVEL_DBM BIT(3)
+#define WPA_SCAN_AUTHENTICATED BIT(4)
+#define WPA_SCAN_ASSOCIATED BIT(5)
/**
* struct wpa_scan_res - Scan result for an BSS/IBSS
+ * @flags: information flags about the BSS/IBSS (WPA_SCAN_*)
* @bssid: BSSID
* @freq: frequency of the channel in MHz (e.g., 2412 = channel 1)
* @beacon_int: beacon interval in TUs (host byte order)
@@ -91,7 +129,10 @@ struct wpa_scan_result {
* @noise: noise level
* @level: signal level
* @tsf: Timestamp
+ * @age: Age of the information in milliseconds (i.e., how many milliseconds
+ * ago the last Beacon or Probe Response frame was received)
* @ie_len: length of the following IE field in octets
+ * @beacon_ie_len: length of the following Beacon IE field in octets
*
* This structure is used as a generic format for scan results from the
* driver. Each driver interface implementation is responsible for converting
@@ -103,6 +144,7 @@ struct wpa_scan_result {
* report all IEs to make it easier to support future additions.
*/
struct wpa_scan_res {
+ unsigned int flags;
u8 bssid[ETH_ALEN];
int freq;
u16 beacon_int;
@@ -111,8 +153,16 @@ struct wpa_scan_res {
int noise;
int level;
u64 tsf;
+ unsigned int age;
size_t ie_len;
- /* followed by ie_len octets of IEs */
+ size_t beacon_ie_len;
+ /*
+ * Followed by ie_len octets of IEs from Probe Response frame (or if
+ * the driver does not indicate source of IEs, these may also be from
+ * Beacon frame). After the first set of IEs, another set of IEs may
+ * follow (with beacon_ie_len octets of data) if the driver provides
+ * both IE sets.
+ */
};
/**
@@ -142,6 +192,95 @@ struct wpa_interface_info {
const char *drv_name;
};
+#define WPAS_MAX_SCAN_SSIDS 4
+
+/**
+ * struct wpa_driver_scan_params - Scan parameters
+ * Data for struct wpa_driver_ops::scan2().
+ */
+struct wpa_driver_scan_params {
+ /**
+ * ssids - SSIDs to scan for
+ */
+ struct wpa_driver_scan_ssid {
+ /**
+ * ssid - specific SSID to scan for (ProbeReq)
+ * %NULL or zero-length SSID is used to indicate active scan
+ * with wildcard SSID.
+ */
+ const u8 *ssid;
+ /**
+ * ssid_len: Length of the SSID in octets
+ */
+ size_t ssid_len;
+ } ssids[WPAS_MAX_SCAN_SSIDS];
+
+ /**
+ * num_ssids - Number of entries in ssids array
+ * Zero indicates a request for a passive scan.
+ */
+ size_t num_ssids;
+
+ /**
+ * extra_ies - Extra IE(s) to add into Probe Request or %NULL
+ */
+ const u8 *extra_ies;
+
+ /**
+ * extra_ies_len - Length of extra_ies in octets
+ */
+ size_t extra_ies_len;
+
+ /**
+ * freqs - Array of frequencies to scan or %NULL for all frequencies
+ *
+ * The frequency is set in MHz. The array is zero-terminated.
+ */
+ int *freqs;
+
+ /**
+ * filter_ssids - Filter for reporting SSIDs
+ *
+ * This optional parameter can be used to request the driver wrapper to
+ * filter scan results to include only the specified SSIDs. %NULL
+ * indicates that no filtering is to be done. This can be used to
+ * reduce memory needs for scan results in environments that have large
+ * number of APs with different SSIDs.
+ *
+ * The driver wrapper is allowed to take this allocated buffer into its
+ * own use by setting the pointer to %NULL. In that case, the driver
+ * wrapper is responsible for freeing the buffer with os_free() once it
+ * is not needed anymore.
+ */
+ struct wpa_driver_scan_filter {
+ u8 ssid[32];
+ size_t ssid_len;
+ } *filter_ssids;
+
+ /**
+ * num_filter_ssids - Number of entries in filter_ssids array
+ */
+ size_t num_filter_ssids;
+};
+
+/**
+ * struct wpa_driver_auth_params - Authentication parameters
+ * Data for struct wpa_driver_ops::authenticate().
+ */
+struct wpa_driver_auth_params {
+ int freq;
+ const u8 *bssid;
+ const u8 *ssid;
+ size_t ssid_len;
+ int auth_alg;
+ const u8 *ie;
+ size_t ie_len;
+ const u8 *wep_key[4];
+ size_t wep_key_len[4];
+ int wep_tx_keyidx;
+ int local_state_change;
+};
+
/**
* struct wpa_driver_associate_params - Association parameters
* Data for struct wpa_driver_ops::associate().
@@ -157,6 +296,10 @@ struct wpa_driver_associate_params {
* ssid - The selected SSID
*/
const u8 *ssid;
+
+ /**
+ * ssid_len - Length of the SSID (1..32)
+ */
size_t ssid_len;
/**
@@ -185,20 +328,36 @@ struct wpa_driver_associate_params {
* When using WPS, wpa_ie is used for WPS IE instead of WPA/RSN IE.
*/
const u8 *wpa_ie;
+
/**
* wpa_ie_len - length of the wpa_ie
*/
size_t wpa_ie_len;
- /* The selected pairwise/group cipher and key management
- * suites. These are usually ignored if @wpa_ie is used. */
- wpa_cipher pairwise_suite;
- wpa_cipher group_suite;
- wpa_key_mgmt key_mgmt_suite;
+ /**
+ * pairwise_suite - Selected pairwise cipher suite
+ *
+ * This is usually ignored if @wpa_ie is used.
+ */
+ enum wpa_cipher pairwise_suite;
+
+ /**
+ * group_suite - Selected group cipher suite
+ *
+ * This is usually ignored if @wpa_ie is used.
+ */
+ enum wpa_cipher group_suite;
+
+ /**
+ * key_mgmt_suite - Selected key management suite
+ *
+ * This is usually ignored if @wpa_ie is used.
+ */
+ enum wpa_key_mgmt key_mgmt_suite;
/**
* auth_alg - Allowed authentication algorithms
- * Bit field of AUTH_ALG_*
+ * Bit field of WPA_AUTH_ALG_*
*/
int auth_alg;
@@ -225,11 +384,7 @@ struct wpa_driver_associate_params {
/**
* mgmt_frame_protection - IEEE 802.11w management frame protection
*/
- enum {
- NO_MGMT_FRAME_PROTECTION,
- MGMT_FRAME_PROTECTION_OPTIONAL,
- MGMT_FRAME_PROTECTION_REQUIRED
- } mgmt_frame_protection;
+ enum mfp_options mgmt_frame_protection;
/**
* ft_ies - IEEE 802.11r / FT information elements
@@ -288,6 +443,23 @@ struct wpa_driver_associate_params {
* be prepared to handle %NULL value as an error.
*/
const u8 *psk;
+
+ /**
+ * drop_unencrypted - Enable/disable unencrypted frame filtering
+ *
+ * Configure the driver to drop all non-EAPOL frames (both receive and
+ * transmit paths). Unencrypted EAPOL frames (ethertype 0x888e) must
+ * still be allowed for key negotiation.
+ */
+ int drop_unencrypted;
+
+ /**
+ * prev_bssid - Previously used BSSID in this ESS
+ *
+ * When not %NULL, this is a request to use reassociation instead of
+ * association.
+ */
+ const u8 *prev_bssid;
};
/**
@@ -316,59 +488,119 @@ struct wpa_driver_capa {
/* Driver generated WPA/RSN IE */
#define WPA_DRIVER_FLAGS_DRIVER_IE 0x00000001
+/* Driver needs static WEP key setup after association command */
#define WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC 0x00000002
#define WPA_DRIVER_FLAGS_USER_SPACE_MLME 0x00000004
/* Driver takes care of RSN 4-way handshake internally; PMK is configured with
* struct wpa_driver_ops::set_key using alg = WPA_ALG_PMK */
#define WPA_DRIVER_FLAGS_4WAY_HANDSHAKE 0x00000008
+#define WPA_DRIVER_FLAGS_WIRED 0x00000010
+/* Driver provides separate commands for authentication and association (SME in
+ * wpa_supplicant). */
+#define WPA_DRIVER_FLAGS_SME 0x00000020
+/* Driver supports AP mode */
+#define WPA_DRIVER_FLAGS_AP 0x00000040
+/* Driver needs static WEP key setup after association has been completed */
+#define WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE 0x00000080
unsigned int flags;
+
+ int max_scan_ssids;
+
+ /**
+ * max_remain_on_chan - Maximum remain-on-channel duration in msec
+ */
+ unsigned int max_remain_on_chan;
};
-#define WPA_CHAN_W_SCAN 0x00000001
-#define WPA_CHAN_W_ACTIVE_SCAN 0x00000002
-#define WPA_CHAN_W_IBSS 0x00000004
+struct hostapd_data;
-struct wpa_channel_data {
- short chan; /* channel number (IEEE 802.11) */
- short freq; /* frequency in MHz */
- int flag; /* flag for user space use (WPA_CHAN_*) */
+struct hostap_sta_driver_data {
+ unsigned long rx_packets, tx_packets, rx_bytes, tx_bytes;
+ unsigned long current_tx_rate;
+ unsigned long inactive_msec;
+ unsigned long flags;
+ unsigned long num_ps_buf_frames;
+ unsigned long tx_retry_failed;
+ unsigned long tx_retry_count;
+ int last_rssi;
+ int last_ack_rssi;
};
-#define WPA_RATE_ERP 0x00000001
-#define WPA_RATE_BASIC 0x00000002
-#define WPA_RATE_PREAMBLE2 0x00000004
-#define WPA_RATE_SUPPORTED 0x00000010
-#define WPA_RATE_OFDM 0x00000020
-#define WPA_RATE_CCK 0x00000040
-#define WPA_RATE_MANDATORY 0x00000100
-
-struct wpa_rate_data {
- int rate; /* rate in 100 kbps */
- int flags; /* WPA_RATE_ flags */
+struct hostapd_sta_add_params {
+ const u8 *addr;
+ u16 aid;
+ u16 capability;
+ const u8 *supp_rates;
+ size_t supp_rates_len;
+ u16 listen_interval;
+ const struct ieee80211_ht_capabilities *ht_capabilities;
};
-typedef enum {
- WPA_MODE_IEEE80211B,
- WPA_MODE_IEEE80211G,
- WPA_MODE_IEEE80211A,
- NUM_WPA_MODES
-} wpa_hw_mode;
+struct hostapd_freq_params {
+ int mode;
+ int freq;
+ int channel;
+ int ht_enabled;
+ int sec_channel_offset; /* 0 = HT40 disabled, -1 = HT40 enabled,
+ * secondary channel below primary, 1 = HT40
+ * enabled, secondary channel above primary */
+};
-struct wpa_hw_modes {
- wpa_hw_mode mode;
- int num_channels;
- struct wpa_channel_data *channels;
- int num_rates;
- struct wpa_rate_data *rates;
+enum wpa_driver_if_type {
+ /**
+ * WPA_IF_STATION - Station mode interface
+ */
+ WPA_IF_STATION,
+
+ /**
+ * WPA_IF_AP_VLAN - AP mode VLAN interface
+ *
+ * This interface shares its address and Beacon frame with the main
+ * BSS.
+ */
+ WPA_IF_AP_VLAN,
+
+ /**
+ * WPA_IF_AP_BSS - AP mode BSS interface
+ *
+ * This interface has its own address and Beacon frame.
+ */
+ WPA_IF_AP_BSS,
+};
+
+struct wpa_init_params {
+ const u8 *bssid;
+ const char *ifname;
+ const u8 *ssid;
+ size_t ssid_len;
+ const char *test_socket;
+ int use_pae_group_addr;
+ char **bridge;
+ size_t num_bridge;
+
+ u8 *own_addr; /* buffer for writing own MAC address */
};
-struct ieee80211_rx_status {
- int channel;
- int ssi;
+struct wpa_bss_params {
+ /** Interface name (for multi-SSID/VLAN support) */
+ const char *ifname;
+ /** Whether IEEE 802.1X or WPA/WPA2 is enabled */
+ int enabled;
+
+ int wpa;
+ int ieee802_1x;
+ int wpa_group;
+ int wpa_pairwise;
+ int wpa_key_mgmt;
+ int rsn_preauth;
};
+#define WPA_STA_AUTHORIZED BIT(0)
+#define WPA_STA_WMM BIT(1)
+#define WPA_STA_SHORT_PREAMBLE BIT(2)
+#define WPA_STA_MFP BIT(3)
/**
* struct wpa_driver_ops - Driver interface API definition
@@ -414,31 +646,8 @@ struct wpa_driver_ops {
int (*get_ssid)(void *priv, u8 *ssid);
/**
- * set_wpa - Enable/disable WPA support (OBSOLETE)
- * @priv: private driver interface data
- * @enabled: 1 = enable, 0 = disable
- *
- * Returns: 0 on success, -1 on failure
- *
- * Note: This function is included for backwards compatibility. This is
- * called only just after init and just before deinit, so these
- * functions can be used to implement same functionality and the driver
- * interface need not define this function.
- *
- * Configure the kernel driver to enable/disable WPA support. This may
- * be empty function, if WPA support is always enabled. Common
- * configuration items are WPA IE (clearing it when WPA support is
- * disabled), Privacy flag configuration for capability field (note:
- * this the value need to set in associate handler to allow plaintext
- * mode to be used) when trying to associate with, roaming mode (can
- * allow wpa_supplicant to control roaming if ap_scan=1 is used;
- * however, drivers can also implement roaming if desired, especially
- * ap_scan=2 mode is used for this).
- */
- int (*set_wpa)(void *priv, int enabled);
-
- /**
* set_key - Configure encryption key
+ * @ifname: Interface name (for multi-SSID/VLAN support)
* @priv: private driver interface data
* @alg: encryption algorithm (%WPA_ALG_NONE, %WPA_ALG_WEP,
* %WPA_ALG_TKIP, %WPA_ALG_CCMP, %WPA_ALG_IGTK, %WPA_ALG_PMK);
@@ -480,8 +689,9 @@ struct wpa_driver_ops {
* in driver_*.c set_key() implementation, see driver_ndis.c for an
* example on how this can be done.
*/
- int (*set_key)(void *priv, wpa_alg alg, const u8 *addr,
- int key_idx, int set_tx, const u8 *seq, size_t seq_len,
+ int (*set_key)(const char *ifname, void *priv, enum wpa_alg alg,
+ const u8 *addr, int key_idx, int set_tx,
+ const u8 *seq, size_t seq_len,
const u8 *key, size_t key_len);
/**
@@ -543,55 +753,6 @@ struct wpa_driver_ops {
int (*set_countermeasures)(void *priv, int enabled);
/**
- * set_drop_unencrypted - Enable/disable unencrypted frame filtering
- * @priv: private driver interface data
- * @enabled: 1 = unencrypted Tx/Rx frames will be dropped, 0 = disabled
- *
- * Returns: 0 on success, -1 on failure
- *
- * Configure the driver to drop all non-EAPOL frames (both receive and
- * transmit paths). Unencrypted EAPOL frames (ethertype 0x888e) must
- * still be allowed for key negotiation.
- */
- int (*set_drop_unencrypted)(void *priv, int enabled);
-
- /**
- * scan - Request the driver to initiate scan
- * @priv: private driver interface data
- * @ssid: specific SSID to scan for (ProbeReq) or %NULL to scan for
- * all SSIDs (either active scan with broadcast SSID or passive
- * scan
- * @ssid_len: length of the SSID
- *
- * Returns: 0 on success, -1 on failure
- *
- * Once the scan results are ready, the driver should report scan
- * results event for wpa_supplicant which will eventually request the
- * results with wpa_driver_get_scan_results().
- */
- int (*scan)(void *priv, const u8 *ssid, size_t ssid_len);
-
- /**
- * get_scan_results - Fetch the latest scan results (old version)
- * @priv: private driver interface data
- * @results: pointer to buffer for scan results
- * @max_size: maximum number of entries (buffer size)
- *
- * Returns: Number of scan result entries used on success, -1 on
- * failure
- *
- * If scan results include more than max_size BSSes, max_size will be
- * returned and the remaining entries will not be included in the
- * buffer.
- *
- * This function is depracated. New driver wrapper implementations
- * should implement support for get_scan_results2().
- */
- int (*get_scan_results)(void *priv,
- struct wpa_scan_result *results,
- size_t max_size);
-
- /**
* deauthenticate - Request driver to deauthenticate
* @priv: private driver interface data
* @addr: peer address (BSSID of the AP)
@@ -624,27 +785,6 @@ struct wpa_driver_ops {
struct wpa_driver_associate_params *params);
/**
- * set_auth_alg - Set IEEE 802.11 authentication algorithm
- * @priv: private driver interface data
- * @auth_alg: bit field of AUTH_ALG_*
- *
- * If the driver supports more than one authentication algorithm at the
- * same time, it should configure all supported algorithms. If not, one
- * algorithm needs to be selected arbitrarily. Open System
- * authentication should be ok for most cases and it is recommended to
- * be used if other options are not supported. Static WEP configuration
- * may also use Shared Key authentication and LEAP requires its own
- * algorithm number. For LEAP, user can make sure that only one
- * algorithm is used at a time by configuring LEAP as the only
- * supported EAP method. This information is also available in
- * associate() params, so set_auth_alg may not be needed in case of
- * most drivers.
- *
- * Returns: 0 on success, -1 on failure
- */
- int (*set_auth_alg)(void *priv, int auth_alg);
-
- /**
* add_pmkid - Add PMKSA cache entry to the driver
* @priv: private driver interface data
* @bssid: BSSID for the PMKSA cache entry
@@ -764,9 +904,9 @@ struct wpa_driver_ops {
* with driver specific functionality. If this function pointer is set,
* l2_packet module is not used at all and the driver interface code is
* responsible for receiving and sending all EAPOL packets. The
- * received EAPOL packets are sent to core code by calling
- * wpa_supplicant_rx_eapol(). The driver interface is required to
- * implement get_mac_addr() handler if send_eapol() is used.
+ * received EAPOL packets are sent to core code with EVENT_EAPOL_RX
+ * event. The driver interface is required to implement get_mac_addr()
+ * handler if send_eapol() is used.
*/
int (*send_eapol)(void *priv, const u8 *dest, u16 proto,
const u8 *data, size_t data_len);
@@ -813,16 +953,16 @@ struct wpa_driver_ops {
* failure. Caller is responsible for freeing this.
*
* This function is only needed for drivers that export MLME
- * (management frame processing) to wpa_supplicant.
+ * (management frame processing) to %wpa_supplicant or hostapd.
*/
- struct wpa_hw_modes * (*get_hw_feature_data)(void *priv,
- u16 *num_modes,
- u16 *flags);
+ struct hostapd_hw_modes * (*get_hw_feature_data)(void *priv,
+ u16 *num_modes,
+ u16 *flags);
/**
* set_channel - Set channel
* @priv: Private driver interface data
- * @phymode: WPA_MODE_IEEE80211B, ..
+ * @phymode: HOSTAPD_MODE_IEEE80211B, ..
* @chan: IEEE 802.11 channel number
* @freq: Frequency of the channel in MHz
* Returns: 0 on success, -1 on failure
@@ -830,7 +970,7 @@ struct wpa_driver_ops {
* This function is only needed for drivers that export MLME
* (management frame processing) to wpa_supplicant.
*/
- int (*set_channel)(void *priv, wpa_hw_mode phymode, int chan,
+ int (*set_channel)(void *priv, enum hostapd_hw_mode phymode, int chan,
int freq);
/**
@@ -941,29 +1081,6 @@ struct wpa_driver_ops {
struct wpa_scan_results * (*get_scan_results2)(void *priv);
/**
- * set_probe_req_ie - Set information element(s) for Probe Request
- * @priv: private driver interface data
- * @ies: Information elements to append or %NULL to remove extra IEs
- * @ies_len: Length of the IE buffer in octets
- * Returns: 0 on success, -1 on failure
- */
- int (*set_probe_req_ie)(void *priv, const u8 *ies, size_t ies_len);
-
- /**
- * set_mode - Request driver to set the operating mode
- * @priv: private driver interface data
- * @mode: Operation mode (infra/ibss) IEEE80211_MODE_*
- *
- * This handler will be called before any key configuration and call to
- * associate() handler in order to allow the operation mode to be
- * configured as early as possible. This information is also available
- * in associate() params and as such, some driver wrappers may not need
- * to implement set_mode() handler.
- * Returns: 0 on success, -1 on failure
- */
- int (*set_mode)(void *priv, int mode);
-
- /**
* set_country - Set country
* @priv: Private driver interface data
* @alpha2: country to which to switch to
@@ -1017,19 +1134,644 @@ struct wpa_driver_ops {
* failure
*/
struct wpa_interface_info * (*get_interfaces)(void *global_priv);
+
+ /**
+ * scan2 - Request the driver to initiate scan
+ * @priv: private driver interface data
+ * @params: Scan parameters
+ *
+ * Returns: 0 on success, -1 on failure
+ *
+ * Once the scan results are ready, the driver should report scan
+ * results event for wpa_supplicant which will eventually request the
+ * results with wpa_driver_get_scan_results2().
+ */
+ int (*scan2)(void *priv, struct wpa_driver_scan_params *params);
+
+ /**
+ * authenticate - Request driver to authenticate
+ * @priv: private driver interface data
+ * @params: authentication parameters
+ * Returns: 0 on success, -1 on failure
+ *
+ * This is an optional function that can be used with drivers that
+ * support separate authentication and association steps, i.e., when
+ * wpa_supplicant can act as the SME. If not implemented, associate()
+ * function is expected to take care of IEEE 802.11 authentication,
+ * too.
+ */
+ int (*authenticate)(void *priv,
+ struct wpa_driver_auth_params *params);
+
+ /**
+ * set_beacon - Set Beacon frame template
+ * @priv: Private driver interface data
+ * @head: Beacon head from IEEE 802.11 header to IEs before TIM IE
+ * @head_len: Length of the head buffer in octets
+ * @tail: Beacon tail following TIM IE
+ * @tail_len: Length of the tail buffer in octets
+ * @dtim_period: DTIM period
+ * @beacon_int: Beacon interval
+ * Returns: 0 on success, -1 on failure
+ *
+ * This function is used to configure Beacon template for the driver in
+ * AP mode. The driver is responsible for building the full Beacon
+ * frame by concatenating the head part with TIM IE generated by the
+ * driver/firmware and finishing with the tail part.
+ */
+ int (*set_beacon)(void *priv, const u8 *head, size_t head_len,
+ const u8 *tail, size_t tail_len, int dtim_period,
+ int beacon_int);
+
+ /**
+ * hapd_init - Initialize driver interface (hostapd only)
+ * @hapd: Pointer to hostapd context
+ * @params: Configuration for the driver wrapper
+ * Returns: Pointer to private data, %NULL on failure
+ *
+ * This function is used instead of init() or init2() when the driver
+ * wrapper is used withh hostapd.
+ */
+ void * (*hapd_init)(struct hostapd_data *hapd,
+ struct wpa_init_params *params);
+
+ /**
+ * hapd_deinit - Deinitialize driver interface (hostapd only)
+ * @priv: Private driver interface data from hapd_init()
+ */
+ void (*hapd_deinit)(void *priv);
+
+ /**
+ * set_ieee8021x - Enable/disable IEEE 802.1X support (AP only)
+ * @priv: Private driver interface data
+ * @params: BSS parameters
+ * Returns: 0 on success, -1 on failure
+ *
+ * This is an optional function to configure the kernel driver to
+ * enable/disable IEEE 802.1X support and set WPA/WPA2 parameters. This
+ * can be left undefined (set to %NULL) if IEEE 802.1X support is
+ * always enabled and the driver uses set_beacon() to set WPA/RSN IE
+ * for Beacon frames.
+ */
+ int (*set_ieee8021x)(void *priv, struct wpa_bss_params *params);
+
+ /**
+ * set_privacy - Enable/disable privacy (AP only)
+ * @priv: Private driver interface data
+ * @enabled: 1 = privacy enabled, 0 = disabled
+ * Returns: 0 on success, -1 on failure
+ *
+ * This is an optional function to configure privacy field in the
+ * kernel driver for Beacon frames. This can be left undefined (set to
+ * %NULL) if the driver uses the Beacon template from set_beacon().
+ */
+ int (*set_privacy)(void *priv, int enabled);
+
+ /**
+ * get_seqnum - Fetch the current TSC/packet number (AP only)
+ * @ifname: The interface name (main or virtual)
+ * @priv: Private driver interface data
+ * @addr: MAC address of the station or %NULL for group keys
+ * @idx: Key index
+ * @seq: Buffer for returning the latest used TSC/packet number
+ * Returns: 0 on success, -1 on failure
+ *
+ * This function is used to fetch the last used TSC/packet number for
+ * a TKIP, CCMP, or BIP/IGTK key. It is mainly used with group keys, so
+ * there is no strict requirement on implementing support for unicast
+ * keys (i.e., addr != %NULL).
+ */
+ int (*get_seqnum)(const char *ifname, void *priv, const u8 *addr,
+ int idx, u8 *seq);
+
+ /**
+ * flush - Flush all association stations (AP only)
+ * @priv: Private driver interface data
+ * Returns: 0 on success, -1 on failure
+ *
+ * This function requests the driver to disassociate all associated
+ * stations. This function does not need to be implemented if the
+ * driver does not process association frames internally.
+ */
+ int (*flush)(void *priv);
+
+ /**
+ * set_generic_elem - Add IEs into Beacon/Probe Response frames (AP)
+ * @priv: Private driver interface data
+ * @elem: Information elements
+ * @elem_len: Length of the elem buffer in octets
+ * Returns: 0 on success, -1 on failure
+ *
+ * This is an optional function to add information elements in the
+ * kernel driver for Beacon and Probe Response frames. This can be left
+ * undefined (set to %NULL) if the driver uses the Beacon template from
+ * set_beacon().
+ */
+ int (*set_generic_elem)(void *priv, const u8 *elem, size_t elem_len);
+
+ /**
+ * read_sta_data - Fetch station data (AP only)
+ * @priv: Private driver interface data
+ * @data: Buffer for returning station information
+ * @addr: MAC address of the station
+ * Returns: 0 on success, -1 on failure
+ */
+ int (*read_sta_data)(void *priv, struct hostap_sta_driver_data *data,
+ const u8 *addr);
+
+ /**
+ * hapd_send_eapol - Send an EAPOL packet (AP only)
+ * @priv: private driver interface data
+ * @addr: Destination MAC address
+ * @data: EAPOL packet starting with IEEE 802.1X header
+ * @data_len: Length of the EAPOL packet in octets
+ * @encrypt: Whether the frame should be encrypted
+ * @own_addr: Source MAC address
+ *
+ * Returns: 0 on success, -1 on failure
+ */
+ int (*hapd_send_eapol)(void *priv, const u8 *addr, const u8 *data,
+ size_t data_len, int encrypt,
+ const u8 *own_addr);
+
+ /**
+ * sta_deauth - Deauthenticate a station (AP only)
+ * @priv: Private driver interface data
+ * @own_addr: Source address and BSSID for the Deauthentication frame
+ * @addr: MAC address of the station to deauthenticate
+ * @reason: Reason code for the Deauthentiation frame
+ * Returns: 0 on success, -1 on failure
+ *
+ * This function requests a specific station to be deauthenticated and
+ * a Deauthentication frame to be sent to it.
+ */
+ int (*sta_deauth)(void *priv, const u8 *own_addr, const u8 *addr,
+ int reason);
+
+ /**
+ * sta_disassoc - Disassociate a station (AP only)
+ * @priv: Private driver interface data
+ * @own_addr: Source address and BSSID for the Disassociation frame
+ * @addr: MAC address of the station to disassociate
+ * @reason: Reason code for the Disassociation frame
+ * Returns: 0 on success, -1 on failure
+ *
+ * This function requests a specific station to be disassociated and
+ * a Disassociation frame to be sent to it.
+ */
+ int (*sta_disassoc)(void *priv, const u8 *own_addr, const u8 *addr,
+ int reason);
+
+ /**
+ * sta_remove - Remove a station entry (AP only)
+ * @priv: Private driver interface data
+ * @addr: MAC address of the station to be removed
+ * Returns: 0 on success, -1 on failure
+ */
+ int (*sta_remove)(void *priv, const u8 *addr);
+
+ /**
+ * hapd_get_ssid - Get the current SSID (AP only)
+ * @priv: Private driver interface data
+ * @buf: Buffer for returning the SSID
+ * @len: Maximum length of the buffer
+ * Returns: Length of the SSID on success, -1 on failure
+ *
+ * This function need not be implemented if the driver uses Beacon
+ * template from set_beacon() and does not reply to Probe Request
+ * frames.
+ */
+ int (*hapd_get_ssid)(void *priv, u8 *buf, int len);
+
+ /**
+ * hapd_set_ssid - Set SSID (AP only)
+ * @priv: Private driver interface data
+ * @buf: SSID
+ * @len: Length of the SSID in octets
+ * Returns: 0 on success, -1 on failure
+ */
+ int (*hapd_set_ssid)(void *priv, const u8 *buf, int len);
+
+ /**
+ * hapd_set_countermeasures - Enable/disable TKIP countermeasures (AP)
+ * @priv: Private driver interface data
+ * @enabled: 1 = countermeasures enabled, 0 = disabled
+ * Returns: 0 on success, -1 on failure
+ *
+ * This need not be implemented if the driver does not take care of
+ * association processing.
+ */
+ int (*hapd_set_countermeasures)(void *priv, int enabled);
+
+ /**
+ * sta_add - Add a station entry
+ * @priv: Private driver interface data
+ * @params: Station parameters
+ * Returns: 0 on success, -1 on failure
+ *
+ * This function is used to add a station entry to the driver once the
+ * station has completed association. This is only used if the driver
+ * does not take care of association processing.
+ */
+ int (*sta_add)(void *priv, struct hostapd_sta_add_params *params);
+
+ /**
+ * get_inact_sec - Get station inactivity duration (AP only)
+ * @priv: Private driver interface data
+ * @addr: Station address
+ * Returns: Number of seconds station has been inactive, -1 on failure
+ */
+ int (*get_inact_sec)(void *priv, const u8 *addr);
+
+ /**
+ * sta_clear_stats - Clear station statistics (AP only)
+ * @priv: Private driver interface data
+ * @addr: Station address
+ * Returns: 0 on success, -1 on failure
+ */
+ int (*sta_clear_stats)(void *priv, const u8 *addr);
+
+ /**
+ * set_freq - Set channel/frequency (AP only)
+ * @priv: Private driver interface data
+ * @freq: Channel parameters
+ * Returns: 0 on success, -1 on failure
+ */
+ int (*set_freq)(void *priv, struct hostapd_freq_params *freq);
+
+ /**
+ * set_rts - Set RTS threshold
+ * @priv: Private driver interface data
+ * @rts: RTS threshold in octets
+ * Returns: 0 on success, -1 on failure
+ */
+ int (*set_rts)(void *priv, int rts);
+
+ /**
+ * set_frag - Set fragmentation threshold
+ * @priv: Private driver interface data
+ * @frag: Fragmentation threshold in octets
+ * Returns: 0 on success, -1 on failure
+ */
+ int (*set_frag)(void *priv, int frag);
+
+ /**
+ * sta_set_flags - Set station flags (AP only)
+ * @priv: Private driver interface data
+ * @addr: Station address
+ * @total_flags: Bitmap of all WPA_STA_* flags currently set
+ * @flags_or: Bitmap of WPA_STA_* flags to add
+ * @flags_and: Bitmap of WPA_STA_* flags to us as a mask
+ * Returns: 0 on success, -1 on failure
+ */
+ int (*sta_set_flags)(void *priv, const u8 *addr,
+ int total_flags, int flags_or, int flags_and);
+
+ /**
+ * set_rate_sets - Set supported and basic rate sets (AP only)
+ * @priv: Private driver interface data
+ * @supp_rates: -1 terminated array of supported rates in 100 kbps
+ * @basic_rates: -1 terminated array of basic rates in 100 kbps
+ * @mode: hardware mode (HOSTAPD_MODE_*)
+ * Returns: 0 on success, -1 on failure
+ */
+ int (*set_rate_sets)(void *priv, int *supp_rates, int *basic_rates,
+ int mode);
+
+ /**
+ * set_cts_protect - Set CTS protection mode (AP only)
+ * @priv: Private driver interface data
+ * @value: Whether CTS protection is enabled
+ * Returns: 0 on success, -1 on failure
+ */
+ int (*set_cts_protect)(void *priv, int value);
+
+ /**
+ * set_preamble - Set preamble mode (AP only)
+ * @priv: Private driver interface data
+ * @value: Whether short preamble is enabled
+ * Returns: 0 on success, -1 on failure
+ */
+ int (*set_preamble)(void *priv, int value);
+
+ /**
+ * set_short_slot_time - Set short slot time (AP only)
+ * @priv: Private driver interface data
+ * @value: Whether short slot time is enabled
+ * Returns: 0 on success, -1 on failure
+ */
+ int (*set_short_slot_time)(void *priv, int value);
+
+ /**
+ * set_tx_queue_params - Set TX queue parameters
+ * @priv: Private driver interface data
+ * @queue: Queue number
+ * @aifs: AIFS
+ * @cw_min: cwMin
+ * @cw_max: cwMax
+ * @burst_time: Maximum length for bursting in 0.1 msec units
+ */
+ int (*set_tx_queue_params)(void *priv, int queue, int aifs, int cw_min,
+ int cw_max, int burst_time);
+
+ /**
+ * valid_bss_mask - Validate BSSID mask
+ * @priv: Private driver interface data
+ * @addr: Address
+ * @mask: Mask
+ * Returns: 0 if mask is valid, -1 if mask is not valid, 1 if mask can
+ * be used, but the main interface address must be the first address in
+ * the block if mask is applied
+ */
+ int (*valid_bss_mask)(void *priv, const u8 *addr, const u8 *mask);
+
+ /**
+ * if_add - Add a virtual interface
+ * @priv: Private driver interface data
+ * @type: Interface type
+ * @ifname: Interface name for the new virtual interface
+ * @addr: Local address to use for the interface or %NULL to use the
+ * parent interface address
+ * @bss_ctx: BSS context for %WPA_IF_AP_BSS interfaces
+ * @drv_priv: Pointer for overwriting the driver context or %NULL if
+ * not allowed (applies only to %WPA_IF_AP_BSS type)
+ * @force_ifname: Buffer for returning an interface name that the
+ * driver ended up using if it differs from the requested ifname
+ * @if_addr: Buffer for returning the allocated interface address
+ * (this may differ from the requested addr if the driver cannot
+ * change interface address)
+ * Returns: 0 on success, -1 on failure
+ */
+ int (*if_add)(void *priv, enum wpa_driver_if_type type,
+ const char *ifname, const u8 *addr, void *bss_ctx,
+ void **drv_priv, char *force_ifname, u8 *if_addr);
+
+ /**
+ * if_remove - Remove a virtual interface
+ * @priv: Private driver interface data
+ * @type: Interface type
+ * @ifname: Interface name of the virtual interface to be removed
+ * Returns: 0 on success, -1 on failure
+ */
+ int (*if_remove)(void *priv, enum wpa_driver_if_type type,
+ const char *ifname);
+
+ /**
+ * set_sta_vlan - Bind a station into a specific interface (AP only)
+ * @priv: Private driver interface data
+ * @ifname: Interface (main or virtual BSS or VLAN)
+ * @addr: MAC address of the associated station
+ * @vlan_id: VLAN ID
+ * Returns: 0 on success, -1 on failure
+ *
+ * This function is used to bind a station to a specific virtual
+ * interface. It is only used if when virtual interfaces are supported,
+ * e.g., to assign stations to different VLAN interfaces based on
+ * information from a RADIUS server. This allows separate broadcast
+ * domains to be used with a single BSS.
+ */
+ int (*set_sta_vlan)(void *priv, const u8 *addr, const char *ifname,
+ int vlan_id);
+
+ /**
+ * commit - Optional commit changes handler (AP only)
+ * @priv: driver private data
+ * Returns: 0 on success, -1 on failure
+ *
+ * This optional handler function can be registered if the driver
+ * interface implementation needs to commit changes (e.g., by setting
+ * network interface up) at the end of initial configuration. If set,
+ * this handler will be called after initial setup has been completed.
+ */
+ int (*commit)(void *priv);
+
+ /**
+ * send_ether - Send an ethernet packet (AP only)
+ * @priv: private driver interface data
+ * @dst: Destination MAC address
+ * @src: Source MAC address
+ * @proto: Ethertype
+ * @data: EAPOL packet starting with IEEE 802.1X header
+ * @data_len: Length of the EAPOL packet in octets
+ * Returns: 0 on success, -1 on failure
+ */
+ int (*send_ether)(void *priv, const u8 *dst, const u8 *src, u16 proto,
+ const u8 *data, size_t data_len);
+
+ /**
+ * set_radius_acl_auth - Notification of RADIUS ACL change
+ * @priv: Private driver interface data
+ * @mac: MAC address of the station
+ * @accepted: Whether the station was accepted
+ * @session_timeout: Session timeout for the station
+ * Returns: 0 on success, -1 on failure
+ */
+ int (*set_radius_acl_auth)(void *priv, const u8 *mac, int accepted,
+ u32 session_timeout);
+
+ /**
+ * set_radius_acl_expire - Notification of RADIUS ACL expiration
+ * @priv: Private driver interface data
+ * @mac: MAC address of the station
+ * Returns: 0 on success, -1 on failure
+ */
+ int (*set_radius_acl_expire)(void *priv, const u8 *mac);
+
+ /**
+ * set_ht_params - Set HT parameters (AP only)
+ * @priv: Private driver interface data
+ * @ht_capab: HT Capabilities IE
+ * @ht_capab_len: Length of ht_capab in octets
+ * @ht_oper: HT Operation IE
+ * @ht_oper_len: Length of ht_oper in octets
+ * Returns: 0 on success, -1 on failure
+ */
+ int (*set_ht_params)(void *priv,
+ const u8 *ht_capab, size_t ht_capab_len,
+ const u8 *ht_oper, size_t ht_oper_len);
+
+ /**
+ * set_ap_wps_ie - Add WPS IE(s) into Beacon/Probe Response frames (AP)
+ * @priv: Private driver interface data
+ * @beacon: WPS IE(s) for Beacon frames or %NULL to remove extra IE(s)
+ * @proberesp: WPS IE(s) for Probe Response frames or %NULL to remove
+ * extra IE(s)
+ * Returns: 0 on success, -1 on failure
+ *
+ * This is an optional function to add WPS IE in the kernel driver for
+ * Beacon and Probe Response frames. This can be left undefined (set
+ * to %NULL) if the driver uses the Beacon template from set_beacon()
+ * and does not process Probe Request frames.
+ */
+ int (*set_ap_wps_ie)(void *priv, const struct wpabuf *beacon,
+ const struct wpabuf *proberesp);
+
+ /**
+ * set_supp_port - Set IEEE 802.1X Supplicant Port status
+ * @priv: Private driver interface data
+ * @authorized: Whether the port is authorized
+ * Returns: 0 on success, -1 on failure
+ */
+ int (*set_supp_port)(void *priv, int authorized);
+
+ /**
+ * set_wds_sta - Bind a station into a 4-address WDS (AP only)
+ * @priv: Private driver interface data
+ * @addr: MAC address of the associated station
+ * @aid: Association ID
+ * @val: 1 = bind to 4-address WDS; 0 = unbind
+ * Returns: 0 on success, -1 on failure
+ */
+ int (*set_wds_sta)(void *priv, const u8 *addr, int aid, int val);
+
+ /**
+ * send_action - Transmit an Action frame
+ * @priv: Private driver interface data
+ * @freq: Frequency (in MHz) of the channel
+ * @dst: Destination MAC address (Address 1)
+ * @src: Source MAC address (Address 2)
+ * @bssid: BSSID (Address 3)
+ * @data: Frame body
+ * @data_len: data length in octets
+ * Returns: 0 on success, -1 on failure
+ *
+ * This command can be used to request the driver to transmit an action
+ * frame to the specified destination. If a remain-on-channel duration
+ * is in progress, the frame is transmitted on that channel. Otherwise,
+ * the frame is transmitted on the current operational channel if in
+ * associated state in station mode or if operating as an AP. If none
+ * of these conditions is in effect, send_action() cannot be used.
+ */
+ int (*send_action)(void *priv, unsigned int freq,
+ const u8 *dst, const u8 *src, const u8 *bssid,
+ const u8 *data, size_t data_len);
+
+ /**
+ * remain_on_channel - Remain awake on a channel
+ * @priv: Private driver interface data
+ * @freq: Frequency (in MHz) of the channel
+ * @duration: Duration in milliseconds
+ * Returns: 0 on success, -1 on failure
+ *
+ * This command is used to request the driver to remain awake on the
+ * specified channel for the specified duration and report received
+ * Action frames with EVENT_RX_ACTION events. Optionally, received
+ * Probe Request frames may also be requested to be reported by calling
+ * probe_req_report(). These will be reported with EVENT_RX_PROBE_REQ.
+ *
+ * The driver may not be at the requested channel when this function
+ * returns, i.e., the return code is only indicating whether the
+ * request was accepted. The caller will need to wait until the
+ * EVENT_REMAIN_ON_CHANNEL event indicates that the driver has
+ * completed the channel change. This may take some time due to other
+ * need for the radio and the caller should be prepared to timing out
+ * its wait since there are no guarantees on when this request can be
+ * executed.
+ */
+ int (*remain_on_channel)(void *priv, unsigned int freq,
+ unsigned int duration);
+
+ /**
+ * cancel_remain_on_channel - Cancel remain-on-channel operation
+ * @priv: Private driver interface data
+ *
+ * This command can be used to cancel a remain-on-channel operation
+ * before its originally requested duration has passed. This could be
+ * used, e.g., when remain_on_channel() is used to request extra time
+ * to receive a response to an Action frame and the response is
+ * received when there is still unneeded time remaining on the
+ * remain-on-channel operation.
+ */
+ int (*cancel_remain_on_channel)(void *priv);
+
+ /**
+ * probe_req_report - Request Probe Request frames to be indicated
+ * @priv: Private driver interface data
+ * @report: Whether to report received Probe Request frames
+ * Returns: 0 on success, -1 on failure (or if not supported)
+ *
+ * This command can be used to request the driver to indicate when
+ * Probe Request frames are received with EVENT_RX_PROBE_REQ events.
+ * Since this operation may require extra resources, e.g., due to less
+ * optimal hardware/firmware RX filtering, many drivers may disable
+ * Probe Request reporting at least in station mode. This command is
+ * used to notify the driver when the Probe Request frames need to be
+ * reported, e.g., during remain-on-channel operations.
+ */
+ int (*probe_req_report)(void *priv, int report);
+
+ /**
+ * disable_11b_rates - Set whether IEEE 802.11b rates are used for TX
+ * @priv: Private driver interface data
+ * @disabled: Whether IEEE 802.11b rates are disabled
+ * Returns: 0 on success, -1 on failure (or if not supported)
+ *
+ * This command is used to disable IEEE 802.11b rates (1, 2, 5.5, and
+ * 11 Mbps) as TX rates for data and management frames. This can be
+ * used to optimize channel use when there is no need to support IEEE
+ * 802.11b-only devices.
+ */
+ int (*disable_11b_rates)(void *priv, int disabled);
+
+ /**
+ * deinit_ap - Deinitialize AP mode
+ * @priv: Private driver interface data
+ * Returns: 0 on success, -1 on failure (or if not supported)
+ *
+ * This optional function can be used to disable AP mode related
+ * configuration and change the driver mode to station mode to allow
+ * normal station operations like scanning to be completed.
+ */
+ int (*deinit_ap)(void *priv);
+
+ /**
+ * suspend - Notification on system suspend/hibernate event
+ * @priv: Private driver interface data
+ */
+ void (*suspend)(void *priv);
+
+ /**
+ * resume - Notification on system resume/thaw event
+ * @priv: Private driver interface data
+ */
+ void (*resume)(void *priv);
+
+ /**
+ * signal_monitor - Set signal monitoring parameters
+ * @priv: Private driver interface data
+ * @threshold: Threshold value for signal change events; 0 = disabled
+ * @hysteresis: Minimum change in signal strength before indicating a
+ * new event
+ * Returns: 0 on success, -1 on failure (or if not supported)
+ *
+ * This function can be used to configure monitoring of signal strength
+ * with the current AP. Whenever signal strength drops below the
+ * %threshold value or increases above it, EVENT_SIGNAL_CHANGE event
+ * should be generated assuming the signal strength has changed at
+ * least %hysteresis from the previously indicated signal change event.
+ */
+ int (*signal_monitor)(void *priv, int threshold, int hysteresis);
+
+ /**
+ * send_frame - Send IEEE 802.11 frame (testing use only)
+ * @priv: Private driver interface data
+ * @data: IEEE 802.11 frame with IEEE 802.11 header
+ * @data_len: Size of the frame
+ * @encrypt: Whether to encrypt the frame (if keys are set)
+ * Returns: 0 on success, -1 on failure
+ *
+ * This function is only used for debugging purposes and is not
+ * required to be implemented for normal operations.
+ */
+ int (*send_frame)(void *priv, const u8 *data, size_t data_len,
+ int encrypt);
};
-/* Function to check whether a driver is for wired connections */
-static inline int IS_WIRED(const struct wpa_driver_ops *drv)
-{
- return os_strcmp(drv->name, "wired") == 0 ||
- os_strcmp(drv->name, "roboswitch") == 0;
-}
/**
* enum wpa_event_type - Event type for wpa_supplicant_event() calls
*/
-typedef enum wpa_event_type {
+enum wpa_event_type {
/**
* EVENT_ASSOC - Association completed
*
@@ -1049,7 +1791,10 @@ typedef enum wpa_event_type {
*
* This event should be called when association is lost either due to
* receiving deauthenticate or disassociate frame from the AP or when
- * sending either of these frames to the current AP.
+ * sending either of these frames to the current AP. If the driver
+ * supports separate deauthentication event, EVENT_DISASSOC should only
+ * be used for disassociation and EVENT_DEAUTH for deauthentication.
+ * In AP mode, union wpa_event_data::disassoc_info is required.
*/
EVENT_DISASSOC,
@@ -1075,7 +1820,8 @@ typedef enum wpa_event_type {
* EVENT_SCAN_RESULTS call. If such event is not available from the
* driver, the driver wrapper code is expected to use a registered
* timeout to generate EVENT_SCAN_RESULTS call after the time that the
- * scan is expected to be completed.
+ * scan is expected to be completed. Optional information about
+ * completed scan can be provided with union wpa_event_data::scan_info.
*/
EVENT_SCAN_RESULTS,
@@ -1147,8 +1893,161 @@ typedef enum wpa_event_type {
* FT authentication sequence from the AP. The FT IEs are included in
* the extra information in union wpa_event_data::ft_ies.
*/
- EVENT_FT_RESPONSE
-} wpa_event_type;
+ EVENT_FT_RESPONSE,
+
+ /**
+ * EVENT_IBSS_RSN_START - Request RSN authentication in IBSS
+ *
+ * The driver can use this event to inform wpa_supplicant about a STA
+ * in an IBSS with which protected frames could be exchanged. This
+ * event starts RSN authentication with the other STA to authenticate
+ * the STA and set up encryption keys with it.
+ */
+ EVENT_IBSS_RSN_START,
+
+ /**
+ * EVENT_AUTH - Authentication result
+ *
+ * This event should be called when authentication attempt has been
+ * completed. This is only used if the driver supports separate
+ * authentication step (struct wpa_driver_ops::authenticate).
+ * Information about authentication result is included in
+ * union wpa_event_data::auth.
+ */
+ EVENT_AUTH,
+
+ /**
+ * EVENT_DEAUTH - Authentication lost
+ *
+ * This event should be called when authentication is lost either due
+ * to receiving deauthenticate frame from the AP or when sending that
+ * frame to the current AP.
+ * In AP mode, union wpa_event_data::deauth_info is required.
+ */
+ EVENT_DEAUTH,
+
+ /**
+ * EVENT_ASSOC_REJECT - Association rejected
+ *
+ * This event should be called when (re)association attempt has been
+ * rejected by the AP. Information about authentication result is
+ * included in union wpa_event_data::assoc_reject.
+ */
+ EVENT_ASSOC_REJECT,
+
+ /**
+ * EVENT_AUTH_TIMED_OUT - Authentication timed out
+ */
+ EVENT_AUTH_TIMED_OUT,
+
+ /**
+ * EVENT_ASSOC_TIMED_OUT - Association timed out
+ */
+ EVENT_ASSOC_TIMED_OUT,
+
+ /**
+ * EVENT_FT_RRB_RX - FT (IEEE 802.11r) RRB frame received
+ */
+ EVENT_FT_RRB_RX,
+
+ /**
+ * EVENT_WPS_BUTTON_PUSHED - Report hardware push button press for WPS
+ */
+ EVENT_WPS_BUTTON_PUSHED,
+
+ /**
+ * EVENT_TX_STATUS - Report TX status
+ */
+ EVENT_TX_STATUS,
+
+ /**
+ * EVENT_RX_FROM_UNKNOWN - Report RX from unknown STA
+ */
+ EVENT_RX_FROM_UNKNOWN,
+
+ /**
+ * EVENT_RX_MGMT - Report RX of a management frame
+ */
+ EVENT_RX_MGMT,
+
+ /**
+ * EVENT_RX_ACTION - Action frame received
+ *
+ * This event is used to indicate when an Action frame has been
+ * received. Information about the received frame is included in
+ * union wpa_event_data::rx_action.
+ */
+ EVENT_RX_ACTION,
+
+ /**
+ * EVENT_REMAIN_ON_CHANNEL - Remain-on-channel duration started
+ *
+ * This event is used to indicate when the driver has started the
+ * requested remain-on-channel duration. Information about the
+ * operation is included in union wpa_event_data::remain_on_channel.
+ */
+ EVENT_REMAIN_ON_CHANNEL,
+
+ /**
+ * EVENT_CANCEL_REMAIN_ON_CHANNEL - Remain-on-channel timed out
+ *
+ * This event is used to indicate when the driver has completed
+ * remain-on-channel duration, i.e., may noot be available on the
+ * requested channel anymore. Information about the
+ * operation is included in union wpa_event_data::remain_on_channel.
+ */
+ EVENT_CANCEL_REMAIN_ON_CHANNEL,
+
+ /**
+ * EVENT_MLME_RX - Report reception of frame for MLME (test use only)
+ *
+ * This event is used only by driver_test.c and userspace MLME.
+ */
+ EVENT_MLME_RX,
+
+ /**
+ * EVENT_RX_PROBE_REQ - Indicate received Probe Request frame
+ *
+ * This event is used to indicate when a Probe Request frame has been
+ * received. Information about the received frame is included in
+ * union wpa_event_data::rx_probe_req. The driver is required to report
+ * these events only after successfully completed probe_req_report()
+ * commands to request the events (i.e., report parameter is non-zero)
+ * in station mode. In AP mode, Probe Request frames should always be
+ * reported.
+ */
+ EVENT_RX_PROBE_REQ,
+
+ /**
+ * EVENT_NEW_STA - New wired device noticed
+ *
+ * This event is used to indicate that a new device has been detected
+ * in a network that does not use association-like functionality (i.e.,
+ * mainly wired Ethernet). This can be used to start EAPOL
+ * authenticator when receiving a frame from a device. The address of
+ * the device is included in union wpa_event_data::new_sta.
+ */
+ EVENT_NEW_STA,
+
+ /**
+ * EVENT_EAPOL_RX - Report received EAPOL frame
+ *
+ * When in AP mode with hostapd, this event is required to be used to
+ * deliver the receive EAPOL frames from the driver. With
+ * %wpa_supplicant, this event is used only if the send_eapol() handler
+ * is used to override the use of l2_packet for EAPOL frame TX.
+ */
+ EVENT_EAPOL_RX,
+
+ /**
+ * EVENT_SIGNAL_CHANGE - Indicate change in signal strength
+ *
+ * This event is used to indicate changes in the signal strength
+ * observed in frames received from the current AP if signal strength
+ * monitoring has been enabled with signal_monitor().
+ */
+ EVENT_SIGNAL_CHANGE
+};
/**
@@ -1175,7 +2074,7 @@ union wpa_event_data {
* This should start with the first IE (fixed fields before IEs
* are not included).
*/
- u8 *req_ies;
+ const u8 *req_ies;
/**
* req_ies_len - Length of req_ies in bytes
@@ -1193,7 +2092,7 @@ union wpa_event_data {
* This should start with the first IE (fixed fields before IEs
* are not included).
*/
- u8 *resp_ies;
+ const u8 *resp_ies;
/**
* resp_ies_len - Length of resp_ies in bytes
@@ -1216,18 +2115,61 @@ union wpa_event_data {
* This should start with the first IE (fixed fields before IEs
* are not included).
*/
- u8 *beacon_ies;
+ const u8 *beacon_ies;
/**
* beacon_ies_len - Length of beacon_ies */
size_t beacon_ies_len;
+
+ /**
+ * freq - Frequency of the operational channel in MHz
+ */
+ unsigned int freq;
+
+ /**
+ * addr - Station address (for AP mode)
+ */
+ const u8 *addr;
} assoc_info;
/**
+ * struct disassoc_info - Data for EVENT_DISASSOC events
+ */
+ struct disassoc_info {
+ /**
+ * addr - Station address (for AP mode)
+ */
+ const u8 *addr;
+
+ /**
+ * reason_code - Reason Code (host byte order) used in
+ * Deauthentication frame
+ */
+ u16 reason_code;
+ } disassoc_info;
+
+ /**
+ * struct deauth_info - Data for EVENT_DEAUTH events
+ */
+ struct deauth_info {
+ /**
+ * addr - Station address (for AP mode)
+ */
+ const u8 *addr;
+
+ /**
+ * reason_code - Reason Code (host byte order) used in
+ * Deauthentication frame
+ */
+ u16 reason_code;
+ } deauth_info;
+
+ /**
* struct michael_mic_failure - Data for EVENT_MICHAEL_MIC_FAILURE
*/
struct michael_mic_failure {
int unicast;
+ const u8 *src;
} michael_mic_failure;
/**
@@ -1273,7 +2215,228 @@ union wpa_event_data {
size_t ies_len;
int ft_action;
u8 target_ap[ETH_ALEN];
+ /** Optional IE(s), e.g., WMM TSPEC(s), for RIC-Request */
+ const u8 *ric_ies;
+ /** Length of ric_ies buffer in octets */
+ size_t ric_ies_len;
} ft_ies;
+
+ /**
+ * struct ibss_rsn_start - Data for EVENT_IBSS_RSN_START
+ */
+ struct ibss_rsn_start {
+ u8 peer[ETH_ALEN];
+ } ibss_rsn_start;
+
+ /**
+ * struct auth_info - Data for EVENT_AUTH events
+ */
+ struct auth_info {
+ u8 peer[ETH_ALEN];
+ u16 auth_type;
+ u16 status_code;
+ const u8 *ies;
+ size_t ies_len;
+ } auth;
+
+ /**
+ * struct assoc_reject - Data for EVENT_ASSOC_REJECT events
+ */
+ struct assoc_reject {
+ /**
+ * resp_ies - (Re)Association Response IEs
+ *
+ * Optional association data from the driver. This data is not
+ * required WPA, but may be useful for some protocols and as
+ * such, should be reported if this is available to the driver
+ * interface.
+ *
+ * This should start with the first IE (fixed fields before IEs
+ * are not included).
+ */
+ u8 *resp_ies;
+
+ /**
+ * resp_ies_len - Length of resp_ies in bytes
+ */
+ size_t resp_ies_len;
+
+ /**
+ * status_code - Status Code from (Re)association Response
+ */
+ u16 status_code;
+ } assoc_reject;
+
+ struct timeout_event {
+ u8 addr[ETH_ALEN];
+ } timeout_event;
+
+ /**
+ * struct ft_rrb_rx - Data for EVENT_FT_RRB_RX events
+ */
+ struct ft_rrb_rx {
+ const u8 *src;
+ const u8 *data;
+ size_t data_len;
+ } ft_rrb_rx;
+
+ /**
+ * struct tx_status - Data for EVENT_TX_STATUS events
+ */
+ struct tx_status {
+ u16 type;
+ u16 stype;
+ const u8 *dst;
+ const u8 *data;
+ size_t data_len;
+ int ack;
+ } tx_status;
+
+ /**
+ * struct rx_from_unknown - Data for EVENT_RX_FROM_UNKNOWN events
+ */
+ struct rx_from_unknown {
+ const u8 *frame;
+ size_t len;
+ } rx_from_unknown;
+
+ /**
+ * struct rx_mgmt - Data for EVENT_RX_MGMT events
+ */
+ struct rx_mgmt {
+ const u8 *frame;
+ size_t frame_len;
+ u32 datarate;
+ u32 ssi_signal;
+ } rx_mgmt;
+
+ /**
+ * struct rx_action - Data for EVENT_RX_ACTION events
+ */
+ struct rx_action {
+ /**
+ * da - Destination address of the received Action frame
+ */
+ const u8 *da;
+
+ /**
+ * sa - Source address of the received Action frame
+ */
+ const u8 *sa;
+
+ /**
+ * bssid - Address 3 of the received Action frame
+ */
+ const u8 *bssid;
+
+ /**
+ * category - Action frame category
+ */
+ u8 category;
+
+ /**
+ * data - Action frame body after category field
+ */
+ const u8 *data;
+
+ /**
+ * len - Length of data in octets
+ */
+ size_t len;
+
+ /**
+ * freq - Frequency (in MHz) on which the frame was received
+ */
+ int freq;
+ } rx_action;
+
+ /**
+ * struct remain_on_channel - Data for EVENT_REMAIN_ON_CHANNEL events
+ *
+ * This is also used with EVENT_CANCEL_REMAIN_ON_CHANNEL events.
+ */
+ struct remain_on_channel {
+ /**
+ * freq - Channel frequency in MHz
+ */
+ unsigned int freq;
+
+ /**
+ * duration - Duration to remain on the channel in milliseconds
+ */
+ unsigned int duration;
+ } remain_on_channel;
+
+ /**
+ * struct scan_info - Optional data for EVENT_SCAN_RESULTS events
+ * @aborted: Whether the scan was aborted
+ * @freqs: Scanned frequencies in MHz (%NULL = all channels scanned)
+ * @num_freqs: Number of entries in freqs array
+ * @ssids: Scanned SSIDs (%NULL or zero-length SSID indicates wildcard
+ * SSID)
+ * @num_ssids: Number of entries in ssids array
+ */
+ struct scan_info {
+ int aborted;
+ const int *freqs;
+ size_t num_freqs;
+ struct wpa_driver_scan_ssid ssids[WPAS_MAX_SCAN_SSIDS];
+ size_t num_ssids;
+ } scan_info;
+
+ /**
+ * struct mlme_rx - Data for EVENT_MLME_RX events
+ */
+ struct mlme_rx {
+ const u8 *buf;
+ size_t len;
+ int freq;
+ int channel;
+ int ssi;
+ } mlme_rx;
+
+ /**
+ * struct rx_probe_req - Data for EVENT_RX_PROBE_REQ events
+ */
+ struct rx_probe_req {
+ /**
+ * sa - Source address of the received Probe Request frame
+ */
+ const u8 *sa;
+
+ /**
+ * ie - IEs from the Probe Request body
+ */
+ const u8 *ie;
+
+ /**
+ * ie_len - Length of ie buffer in octets
+ */
+ size_t ie_len;
+ } rx_probe_req;
+
+ /**
+ * struct new_sta - Data for EVENT_NEW_STA events
+ */
+ struct new_sta {
+ const u8 *addr;
+ } new_sta;
+
+ /**
+ * struct eapol_rx - Data for EVENT_EAPOL_RX events
+ */
+ struct eapol_rx {
+ const u8 *src;
+ const u8 *data;
+ size_t data_len;
+ } eapol_rx;
+
+ /**
+ * struct signal_change - Data for EVENT_SIGNAL_CHANGE events
+ */
+ struct signal_change {
+ int above_threshold;
+ } signal_change;
};
/**
@@ -1286,40 +2449,43 @@ union wpa_event_data {
* Driver wrapper code should call this function whenever an event is received
* from the driver.
*/
-void wpa_supplicant_event(void *ctx, wpa_event_type event,
+void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
union wpa_event_data *data);
-/**
- * wpa_supplicant_rx_eapol - Deliver a received EAPOL frame to wpa_supplicant
- * @ctx: Context pointer (wpa_s); this is the ctx variable registered
- * with struct wpa_driver_ops::init()
- * @src_addr: Source address of the EAPOL frame
- * @buf: EAPOL data starting from the EAPOL header (i.e., no Ethernet header)
- * @len: Length of the EAPOL data
- *
- * This function is called for each received EAPOL frame. Most driver
- * interfaces rely on more generic OS mechanism for receiving frames through
- * l2_packet, but if such a mechanism is not available, the driver wrapper may
- * take care of received EAPOL frames and deliver them to the core supplicant
- * code by calling this function.
+
+/*
+ * The following inline functions are provided for convenience to simplify
+ * event indication for some of the common events.
*/
-void wpa_supplicant_rx_eapol(void *ctx, const u8 *src_addr,
- const u8 *buf, size_t len);
-
-void wpa_supplicant_sta_rx(void *ctx, const u8 *buf, size_t len,
- struct ieee80211_rx_status *rx_status);
-void wpa_supplicant_sta_free_hw_features(struct wpa_hw_modes *hw_features,
- size_t num_hw_features);
-
-const u8 * wpa_scan_get_ie(const struct wpa_scan_res *res, u8 ie);
-#define WPA_IE_VENDOR_TYPE 0x0050f201
-#define WPS_IE_VENDOR_TYPE 0x0050f204
-const u8 * wpa_scan_get_vendor_ie(const struct wpa_scan_res *res,
- u32 vendor_type);
-struct wpabuf * wpa_scan_get_vendor_ie_multi(const struct wpa_scan_res *res,
- u32 vendor_type);
-int wpa_scan_get_max_rate(const struct wpa_scan_res *res);
-void wpa_scan_results_free(struct wpa_scan_results *res);
-void wpa_scan_sort_results(struct wpa_scan_results *res);
+
+static inline void drv_event_assoc(void *ctx, const u8 *addr, const u8 *ie,
+ size_t ielen)
+{
+ union wpa_event_data event;
+ os_memset(&event, 0, sizeof(event));
+ event.assoc_info.req_ies = ie;
+ event.assoc_info.req_ies_len = ielen;
+ event.assoc_info.addr = addr;
+ wpa_supplicant_event(ctx, EVENT_ASSOC, &event);
+}
+
+static inline void drv_event_disassoc(void *ctx, const u8 *addr)
+{
+ union wpa_event_data event;
+ os_memset(&event, 0, sizeof(event));
+ event.disassoc_info.addr = addr;
+ wpa_supplicant_event(ctx, EVENT_DISASSOC, &event);
+}
+
+static inline void drv_event_eapol_rx(void *ctx, const u8 *src, const u8 *data,
+ size_t data_len)
+{
+ union wpa_event_data event;
+ os_memset(&event, 0, sizeof(event));
+ event.eapol_rx.src = src;
+ event.eapol_rx.data = data;
+ event.eapol_rx.data_len = data_len;
+ wpa_supplicant_event(ctx, EVENT_EAPOL_RX, &event);
+}
#endif /* DRIVER_H */
diff --git a/contrib/wpa/src/drivers/driver_atheros.c b/contrib/wpa/src/drivers/driver_atheros.c
new file mode 100644
index 0000000..5c25f00
--- /dev/null
+++ b/contrib/wpa/src/drivers/driver_atheros.c
@@ -0,0 +1,1298 @@
+/*
+ * hostapd / Driver interaction with Atheros driver
+ * Copyright (c) 2004, Sam Leffler <sam@errno.com>
+ * Copyright (c) 2004, Video54 Technologies
+ * Copyright (c) 2005-2007, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2009, Atheros Communications
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+#include <net/if.h>
+#include <sys/ioctl.h>
+
+#include "common.h"
+#ifndef _BYTE_ORDER
+#ifdef WORDS_BIGENDIAN
+#define _BYTE_ORDER _BIG_ENDIAN
+#else
+#define _BYTE_ORDER _LITTLE_ENDIAN
+#endif
+#endif /* _BYTE_ORDER */
+
+/*
+ * Note, the ATH_WPS_IE setting must match with the driver build.. If the
+ * driver does not include this, the IEEE80211_IOCTL_GETWPAIE ioctl will fail.
+ */
+#define ATH_WPS_IE
+
+#include "os/linux/include/ieee80211_external.h"
+
+
+#ifdef CONFIG_WPS
+#include <netpacket/packet.h>
+
+#ifndef ETH_P_80211_RAW
+#define ETH_P_80211_RAW 0x0019
+#endif
+#endif /* CONFIG_WPS */
+
+#include "wireless_copy.h"
+
+#include "driver.h"
+#include "eloop.h"
+#include "priv_netlink.h"
+#include "l2_packet/l2_packet.h"
+#include "common/ieee802_11_defs.h"
+#include "netlink.h"
+#include "linux_ioctl.h"
+
+
+struct madwifi_driver_data {
+ struct hostapd_data *hapd; /* back pointer */
+
+ char iface[IFNAMSIZ + 1];
+ int ifindex;
+ struct l2_packet_data *sock_xmit; /* raw packet xmit socket */
+ struct l2_packet_data *sock_recv; /* raw packet recv socket */
+ int ioctl_sock; /* socket for ioctl() use */
+ struct netlink_data *netlink;
+ int we_version;
+ u8 acct_mac[ETH_ALEN];
+ struct hostap_sta_driver_data acct_data;
+
+ struct l2_packet_data *sock_raw; /* raw 802.11 management frames */
+};
+
+static int madwifi_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
+ int reason_code);
+static int madwifi_set_privacy(void *priv, int enabled);
+
+static const char * athr_get_ioctl_name(int op)
+{
+ switch (op) {
+ case IEEE80211_IOCTL_SETPARAM:
+ return "SETPARAM";
+ case IEEE80211_IOCTL_GETPARAM:
+ return "GETPARAM";
+ case IEEE80211_IOCTL_SETKEY:
+ return "SETKEY";
+ case IEEE80211_IOCTL_SETWMMPARAMS:
+ return "SETWMMPARAMS";
+ case IEEE80211_IOCTL_DELKEY:
+ return "DELKEY";
+ case IEEE80211_IOCTL_GETWMMPARAMS:
+ return "GETWMMPARAMS";
+ case IEEE80211_IOCTL_SETMLME:
+ return "SETMLME";
+ case IEEE80211_IOCTL_GETCHANINFO:
+ return "GETCHANINFO";
+ case IEEE80211_IOCTL_SETOPTIE:
+ return "SETOPTIE";
+ case IEEE80211_IOCTL_GETOPTIE:
+ return "GETOPTIE";
+ case IEEE80211_IOCTL_ADDMAC:
+ return "ADDMAC";
+ case IEEE80211_IOCTL_DELMAC:
+ return "DELMAC";
+ case IEEE80211_IOCTL_GETCHANLIST:
+ return "GETCHANLIST";
+ case IEEE80211_IOCTL_SETCHANLIST:
+ return "SETCHANLIST";
+ case IEEE80211_IOCTL_KICKMAC:
+ return "KICKMAC";
+ case IEEE80211_IOCTL_CHANSWITCH:
+ return "CHANSWITCH";
+ case IEEE80211_IOCTL_GETMODE:
+ return "GETMODE";
+ case IEEE80211_IOCTL_SETMODE:
+ return "SETMODE";
+ case IEEE80211_IOCTL_GET_APPIEBUF:
+ return "GET_APPIEBUF";
+ case IEEE80211_IOCTL_SET_APPIEBUF:
+ return "SET_APPIEBUF";
+ case IEEE80211_IOCTL_SET_ACPARAMS:
+ return "SET_ACPARAMS";
+ case IEEE80211_IOCTL_FILTERFRAME:
+ return "FILTERFRAME";
+ case IEEE80211_IOCTL_SET_RTPARAMS:
+ return "SET_RTPARAMS";
+ case IEEE80211_IOCTL_SENDADDBA:
+ return "SENDADDBA";
+ case IEEE80211_IOCTL_GETADDBASTATUS:
+ return "GETADDBASTATUS";
+ case IEEE80211_IOCTL_SENDDELBA:
+ return "SENDDELBA";
+ case IEEE80211_IOCTL_SET_MEDENYENTRY:
+ return "SET_MEDENYENTRY";
+ case IEEE80211_IOCTL_SET_ADDBARESP:
+ return "SET_ADDBARESP";
+ case IEEE80211_IOCTL_GET_MACADDR:
+ return "GET_MACADDR";
+ case IEEE80211_IOCTL_SET_HBRPARAMS:
+ return "SET_HBRPARAMS";
+ case IEEE80211_IOCTL_SET_RXTIMEOUT:
+ return "SET_RXTIMEOUT";
+ case IEEE80211_IOCTL_STA_STATS:
+ return "STA_STATS";
+ case IEEE80211_IOCTL_GETWPAIE:
+ return "GETWPAIE";
+ default:
+ return "??";
+ }
+}
+
+
+static const char * athr_get_param_name(int op)
+{
+ switch (op) {
+ case IEEE80211_IOC_MCASTCIPHER:
+ return "MCASTCIPHER";
+ case IEEE80211_PARAM_MCASTKEYLEN:
+ return "MCASTKEYLEN";
+ case IEEE80211_PARAM_UCASTCIPHERS:
+ return "UCASTCIPHERS";
+ case IEEE80211_PARAM_KEYMGTALGS:
+ return "KEYMGTALGS";
+ case IEEE80211_PARAM_RSNCAPS:
+ return "RSNCAPS";
+ case IEEE80211_PARAM_WPA:
+ return "WPA";
+ case IEEE80211_PARAM_AUTHMODE:
+ return "AUTHMODE";
+ case IEEE80211_PARAM_PRIVACY:
+ return "PRIVACY";
+ case IEEE80211_PARAM_COUNTERMEASURES:
+ return "COUNTERMEASURES";
+ default:
+ return "??";
+ }
+}
+
+
+static int
+set80211priv(struct madwifi_driver_data *drv, int op, void *data, int len)
+{
+ struct iwreq iwr;
+ int do_inline = len < IFNAMSIZ;
+
+ /* Certain ioctls must use the non-inlined method */
+ if (op == IEEE80211_IOCTL_SET_APPIEBUF ||
+ op == IEEE80211_IOCTL_FILTERFRAME)
+ do_inline = 0;
+
+ memset(&iwr, 0, sizeof(iwr));
+ os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
+ if (do_inline) {
+ /*
+ * Argument data fits inline; put it there.
+ */
+ memcpy(iwr.u.name, data, len);
+ } else {
+ /*
+ * Argument data too big for inline transfer; setup a
+ * parameter block instead; the kernel will transfer
+ * the data for the driver.
+ */
+ iwr.u.data.pointer = data;
+ iwr.u.data.length = len;
+ }
+
+ if (ioctl(drv->ioctl_sock, op, &iwr) < 0) {
+ wpa_printf(MSG_DEBUG, "atheros: %s: %s: ioctl op=0x%x "
+ "(%s) len=%d failed: %d (%s)",
+ __func__, drv->iface, op,
+ athr_get_ioctl_name(op),
+ len, errno, strerror(errno));
+ return -1;
+ }
+ return 0;
+}
+
+static int
+set80211param(struct madwifi_driver_data *drv, int op, int arg)
+{
+ struct iwreq iwr;
+
+ memset(&iwr, 0, sizeof(iwr));
+ os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
+ iwr.u.mode = op;
+ memcpy(iwr.u.name+sizeof(__u32), &arg, sizeof(arg));
+
+ if (ioctl(drv->ioctl_sock, IEEE80211_IOCTL_SETPARAM, &iwr) < 0) {
+ perror("ioctl[IEEE80211_IOCTL_SETPARAM]");
+ wpa_printf(MSG_DEBUG, "%s: %s: Failed to set parameter (op %d "
+ "(%s) arg %d)", __func__, drv->iface, op,
+ athr_get_param_name(op), arg);
+ return -1;
+ }
+ return 0;
+}
+
+#ifndef CONFIG_NO_STDOUT_DEBUG
+static const char *
+ether_sprintf(const u8 *addr)
+{
+ static char buf[sizeof(MACSTR)];
+
+ if (addr != NULL)
+ snprintf(buf, sizeof(buf), MACSTR, MAC2STR(addr));
+ else
+ snprintf(buf, sizeof(buf), MACSTR, 0,0,0,0,0,0);
+ return buf;
+}
+#endif /* CONFIG_NO_STDOUT_DEBUG */
+
+/*
+ * Configure WPA parameters.
+ */
+static int
+madwifi_configure_wpa(struct madwifi_driver_data *drv,
+ struct wpa_bss_params *params)
+{
+ int v;
+
+ switch (params->wpa_group) {
+ case WPA_CIPHER_CCMP:
+ v = IEEE80211_CIPHER_AES_CCM;
+ break;
+ case WPA_CIPHER_TKIP:
+ v = IEEE80211_CIPHER_TKIP;
+ break;
+ case WPA_CIPHER_WEP104:
+ v = IEEE80211_CIPHER_WEP;
+ break;
+ case WPA_CIPHER_WEP40:
+ v = IEEE80211_CIPHER_WEP;
+ break;
+ case WPA_CIPHER_NONE:
+ v = IEEE80211_CIPHER_NONE;
+ break;
+ default:
+ wpa_printf(MSG_ERROR, "Unknown group key cipher %u",
+ params->wpa_group);
+ return -1;
+ }
+ wpa_printf(MSG_DEBUG, "%s: group key cipher=%d", __func__, v);
+ if (set80211param(drv, IEEE80211_PARAM_MCASTCIPHER, v)) {
+ printf("Unable to set group key cipher to %u\n", v);
+ return -1;
+ }
+ if (v == IEEE80211_CIPHER_WEP) {
+ /* key length is done only for specific ciphers */
+ v = (params->wpa_group == WPA_CIPHER_WEP104 ? 13 : 5);
+ if (set80211param(drv, IEEE80211_PARAM_MCASTKEYLEN, v)) {
+ printf("Unable to set group key length to %u\n", v);
+ return -1;
+ }
+ }
+
+ v = 0;
+ if (params->wpa_pairwise & WPA_CIPHER_CCMP)
+ v |= 1<<IEEE80211_CIPHER_AES_CCM;
+ if (params->wpa_pairwise & WPA_CIPHER_TKIP)
+ v |= 1<<IEEE80211_CIPHER_TKIP;
+ if (params->wpa_pairwise & WPA_CIPHER_NONE)
+ v |= 1<<IEEE80211_CIPHER_NONE;
+ wpa_printf(MSG_DEBUG, "%s: pairwise key ciphers=0x%x", __func__, v);
+ if (set80211param(drv, IEEE80211_PARAM_UCASTCIPHERS, v)) {
+ printf("Unable to set pairwise key ciphers to 0x%x\n", v);
+ return -1;
+ }
+
+ wpa_printf(MSG_DEBUG, "%s: key management algorithms=0x%x",
+ __func__, params->wpa_key_mgmt);
+ if (set80211param(drv, IEEE80211_PARAM_KEYMGTALGS,
+ params->wpa_key_mgmt)) {
+ printf("Unable to set key management algorithms to 0x%x\n",
+ params->wpa_key_mgmt);
+ return -1;
+ }
+
+ v = 0;
+ if (params->rsn_preauth)
+ v |= BIT(0);
+ wpa_printf(MSG_DEBUG, "%s: rsn capabilities=0x%x",
+ __func__, params->rsn_preauth);
+ if (set80211param(drv, IEEE80211_PARAM_RSNCAPS, v)) {
+ printf("Unable to set RSN capabilities to 0x%x\n", v);
+ return -1;
+ }
+
+ wpa_printf(MSG_DEBUG, "%s: enable WPA=0x%x", __func__, params->wpa);
+ if (set80211param(drv, IEEE80211_PARAM_WPA, params->wpa)) {
+ printf("Unable to set WPA to %u\n", params->wpa);
+ return -1;
+ }
+ return 0;
+}
+
+static int
+madwifi_set_ieee8021x(void *priv, struct wpa_bss_params *params)
+{
+ struct madwifi_driver_data *drv = priv;
+
+ wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, params->enabled);
+
+ if (!params->enabled) {
+ /* XXX restore state */
+ if (set80211param(priv, IEEE80211_PARAM_AUTHMODE,
+ IEEE80211_AUTH_AUTO) < 0)
+ return -1;
+ /* IEEE80211_AUTH_AUTO ends up enabling Privacy; clear that */
+ return madwifi_set_privacy(drv, 0);
+ }
+ if (!params->wpa && !params->ieee802_1x) {
+ hostapd_logger(drv->hapd, NULL, HOSTAPD_MODULE_DRIVER,
+ HOSTAPD_LEVEL_WARNING, "No 802.1X or WPA enabled!");
+ return -1;
+ }
+ if (params->wpa && madwifi_configure_wpa(drv, params) != 0) {
+ hostapd_logger(drv->hapd, NULL, HOSTAPD_MODULE_DRIVER,
+ HOSTAPD_LEVEL_WARNING, "Error configuring WPA state!");
+ return -1;
+ }
+ if (set80211param(priv, IEEE80211_PARAM_AUTHMODE,
+ (params->wpa ? IEEE80211_AUTH_WPA : IEEE80211_AUTH_8021X))) {
+ hostapd_logger(drv->hapd, NULL, HOSTAPD_MODULE_DRIVER,
+ HOSTAPD_LEVEL_WARNING, "Error enabling WPA/802.1X!");
+ return -1;
+ }
+
+ return 0;
+}
+
+static int
+madwifi_set_privacy(void *priv, int enabled)
+{
+ struct madwifi_driver_data *drv = priv;
+
+ wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled);
+
+ return set80211param(drv, IEEE80211_PARAM_PRIVACY, enabled);
+}
+
+static int
+madwifi_set_sta_authorized(void *priv, const u8 *addr, int authorized)
+{
+ struct madwifi_driver_data *drv = priv;
+ struct ieee80211req_mlme mlme;
+ int ret;
+
+ wpa_printf(MSG_DEBUG, "%s: addr=%s authorized=%d",
+ __func__, ether_sprintf(addr), authorized);
+
+ if (authorized)
+ mlme.im_op = IEEE80211_MLME_AUTHORIZE;
+ else
+ mlme.im_op = IEEE80211_MLME_UNAUTHORIZE;
+ mlme.im_reason = 0;
+ memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
+ ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
+ if (ret < 0) {
+ wpa_printf(MSG_DEBUG, "%s: Failed to %sauthorize STA " MACSTR,
+ __func__, authorized ? "" : "un", MAC2STR(addr));
+ }
+
+ return ret;
+}
+
+static int
+madwifi_sta_set_flags(void *priv, const u8 *addr,
+ int total_flags, int flags_or, int flags_and)
+{
+ /* For now, only support setting Authorized flag */
+ if (flags_or & WPA_STA_AUTHORIZED)
+ return madwifi_set_sta_authorized(priv, addr, 1);
+ if (!(flags_and & WPA_STA_AUTHORIZED))
+ return madwifi_set_sta_authorized(priv, addr, 0);
+ return 0;
+}
+
+static int
+madwifi_del_key(void *priv, const u8 *addr, int key_idx)
+{
+ struct madwifi_driver_data *drv = priv;
+ struct ieee80211req_del_key wk;
+ int ret;
+
+ wpa_printf(MSG_DEBUG, "%s: addr=%s key_idx=%d",
+ __func__, ether_sprintf(addr), key_idx);
+
+ memset(&wk, 0, sizeof(wk));
+ if (addr != NULL) {
+ memcpy(wk.idk_macaddr, addr, IEEE80211_ADDR_LEN);
+ wk.idk_keyix = (u8) IEEE80211_KEYIX_NONE;
+ } else {
+ wk.idk_keyix = key_idx;
+ }
+
+ ret = set80211priv(drv, IEEE80211_IOCTL_DELKEY, &wk, sizeof(wk));
+ if (ret < 0) {
+ wpa_printf(MSG_DEBUG, "%s: Failed to delete key (addr %s"
+ " key_idx %d)", __func__, ether_sprintf(addr),
+ key_idx);
+ }
+
+ return ret;
+}
+
+static int
+madwifi_set_key(const char *ifname, void *priv, enum wpa_alg alg,
+ const u8 *addr, int key_idx, int set_tx, const u8 *seq,
+ size_t seq_len, const u8 *key, size_t key_len)
+{
+ struct madwifi_driver_data *drv = priv;
+ struct ieee80211req_key wk;
+ u_int8_t cipher;
+ int ret;
+
+ if (alg == WPA_ALG_NONE)
+ return madwifi_del_key(drv, addr, key_idx);
+
+ wpa_printf(MSG_DEBUG, "%s: alg=%d addr=%s key_idx=%d",
+ __func__, alg, ether_sprintf(addr), key_idx);
+
+ switch (alg) {
+ case WPA_ALG_WEP:
+ cipher = IEEE80211_CIPHER_WEP;
+ break;
+ case WPA_ALG_TKIP:
+ cipher = IEEE80211_CIPHER_TKIP;
+ break;
+ case WPA_ALG_CCMP:
+ cipher = IEEE80211_CIPHER_AES_CCM;
+ break;
+ default:
+ printf("%s: unknown/unsupported algorithm %d\n",
+ __func__, alg);
+ return -1;
+ }
+
+ if (key_len > sizeof(wk.ik_keydata)) {
+ printf("%s: key length %lu too big\n", __func__,
+ (unsigned long) key_len);
+ return -3;
+ }
+
+ memset(&wk, 0, sizeof(wk));
+ wk.ik_type = cipher;
+ wk.ik_flags = IEEE80211_KEY_RECV | IEEE80211_KEY_XMIT;
+ if (addr == NULL) {
+ memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
+ wk.ik_keyix = key_idx;
+ wk.ik_flags |= IEEE80211_KEY_DEFAULT;
+ } else {
+ memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
+ wk.ik_keyix = IEEE80211_KEYIX_NONE;
+ }
+ wk.ik_keylen = key_len;
+ memcpy(wk.ik_keydata, key, key_len);
+
+ ret = set80211priv(drv, IEEE80211_IOCTL_SETKEY, &wk, sizeof(wk));
+ if (ret < 0) {
+ wpa_printf(MSG_DEBUG, "%s: Failed to set key (addr %s"
+ " key_idx %d alg %d key_len %lu set_tx %d)",
+ __func__, ether_sprintf(wk.ik_macaddr), key_idx,
+ alg, (unsigned long) key_len, set_tx);
+ }
+
+ return ret;
+}
+
+
+static int
+madwifi_get_seqnum(const char *ifname, void *priv, const u8 *addr, int idx,
+ u8 *seq)
+{
+ struct madwifi_driver_data *drv = priv;
+ struct ieee80211req_key wk;
+
+ wpa_printf(MSG_DEBUG, "%s: addr=%s idx=%d",
+ __func__, ether_sprintf(addr), idx);
+
+ memset(&wk, 0, sizeof(wk));
+ if (addr == NULL)
+ memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
+ else
+ memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
+ wk.ik_keyix = idx;
+
+ if (set80211priv(drv, IEEE80211_IOCTL_GETKEY, &wk, sizeof(wk))) {
+ wpa_printf(MSG_DEBUG, "%s: Failed to get encryption data "
+ "(addr " MACSTR " key_idx %d)",
+ __func__, MAC2STR(wk.ik_macaddr), idx);
+ return -1;
+ }
+
+#ifdef WORDS_BIGENDIAN
+ {
+ /*
+ * wk.ik_keytsc is in host byte order (big endian), need to
+ * swap it to match with the byte order used in WPA.
+ */
+ int i;
+#ifndef WPA_KEY_RSC_LEN
+#define WPA_KEY_RSC_LEN 8
+#endif
+ u8 tmp[WPA_KEY_RSC_LEN];
+ memcpy(tmp, &wk.ik_keytsc, sizeof(wk.ik_keytsc));
+ for (i = 0; i < WPA_KEY_RSC_LEN; i++) {
+ seq[i] = tmp[WPA_KEY_RSC_LEN - i - 1];
+ }
+ }
+#else /* WORDS_BIGENDIAN */
+ memcpy(seq, &wk.ik_keytsc, sizeof(wk.ik_keytsc));
+#endif /* WORDS_BIGENDIAN */
+ return 0;
+}
+
+
+static int
+madwifi_flush(void *priv)
+{
+ u8 allsta[IEEE80211_ADDR_LEN];
+ memset(allsta, 0xff, IEEE80211_ADDR_LEN);
+ return madwifi_sta_deauth(priv, NULL, allsta,
+ IEEE80211_REASON_AUTH_LEAVE);
+}
+
+
+static int
+madwifi_read_sta_driver_data(void *priv, struct hostap_sta_driver_data *data,
+ const u8 *addr)
+{
+ struct madwifi_driver_data *drv = priv;
+ struct ieee80211req_sta_stats stats;
+
+ memset(data, 0, sizeof(*data));
+
+ /*
+ * Fetch statistics for station from the system.
+ */
+ memset(&stats, 0, sizeof(stats));
+ memcpy(stats.is_u.macaddr, addr, IEEE80211_ADDR_LEN);
+ if (set80211priv(drv, IEEE80211_IOCTL_STA_STATS,
+ &stats, sizeof(stats))) {
+ wpa_printf(MSG_DEBUG, "%s: Failed to fetch STA stats (addr "
+ MACSTR ")", __func__, MAC2STR(addr));
+ if (memcmp(addr, drv->acct_mac, ETH_ALEN) == 0) {
+ memcpy(data, &drv->acct_data, sizeof(*data));
+ return 0;
+ }
+
+ printf("Failed to get station stats information element.\n");
+ return -1;
+ }
+
+ data->rx_packets = stats.is_stats.ns_rx_data;
+ data->rx_bytes = stats.is_stats.ns_rx_bytes;
+ data->tx_packets = stats.is_stats.ns_tx_data;
+ data->tx_bytes = stats.is_stats.ns_tx_bytes;
+ return 0;
+}
+
+
+static int
+madwifi_sta_clear_stats(void *priv, const u8 *addr)
+{
+ struct madwifi_driver_data *drv = priv;
+ struct ieee80211req_mlme mlme;
+ int ret;
+
+ wpa_printf(MSG_DEBUG, "%s: addr=%s", __func__, ether_sprintf(addr));
+
+ mlme.im_op = IEEE80211_MLME_CLEAR_STATS;
+ memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
+ ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme,
+ sizeof(mlme));
+ if (ret < 0) {
+ wpa_printf(MSG_DEBUG, "%s: Failed to clear STA stats (addr "
+ MACSTR ")", __func__, MAC2STR(addr));
+ }
+
+ return ret;
+}
+
+
+static int
+madwifi_set_opt_ie(void *priv, const u8 *ie, size_t ie_len)
+{
+ /*
+ * Do nothing; we setup parameters at startup that define the
+ * contents of the beacon information element.
+ */
+ return 0;
+}
+
+static int
+madwifi_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
+ int reason_code)
+{
+ struct madwifi_driver_data *drv = priv;
+ struct ieee80211req_mlme mlme;
+ int ret;
+
+ wpa_printf(MSG_DEBUG, "%s: addr=%s reason_code=%d",
+ __func__, ether_sprintf(addr), reason_code);
+
+ mlme.im_op = IEEE80211_MLME_DEAUTH;
+ mlme.im_reason = reason_code;
+ memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
+ ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
+ if (ret < 0) {
+ wpa_printf(MSG_DEBUG, "%s: Failed to deauth STA (addr " MACSTR
+ " reason %d)",
+ __func__, MAC2STR(addr), reason_code);
+ }
+
+ return ret;
+}
+
+static int
+madwifi_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr,
+ int reason_code)
+{
+ struct madwifi_driver_data *drv = priv;
+ struct ieee80211req_mlme mlme;
+ int ret;
+
+ wpa_printf(MSG_DEBUG, "%s: addr=%s reason_code=%d",
+ __func__, ether_sprintf(addr), reason_code);
+
+ mlme.im_op = IEEE80211_MLME_DISASSOC;
+ mlme.im_reason = reason_code;
+ memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
+ ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
+ if (ret < 0) {
+ wpa_printf(MSG_DEBUG, "%s: Failed to disassoc STA (addr "
+ MACSTR " reason %d)",
+ __func__, MAC2STR(addr), reason_code);
+ }
+
+ return ret;
+}
+
+#ifdef CONFIG_WPS
+static void madwifi_raw_receive(void *ctx, const u8 *src_addr, const u8 *buf,
+ size_t len)
+{
+ struct madwifi_driver_data *drv = ctx;
+ const struct ieee80211_mgmt *mgmt;
+ u16 fc;
+ union wpa_event_data event;
+
+ /* Send Probe Request information to WPS processing */
+
+ if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req))
+ return;
+ mgmt = (const struct ieee80211_mgmt *) buf;
+
+ fc = le_to_host16(mgmt->frame_control);
+ if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT ||
+ WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_PROBE_REQ)
+ return;
+
+ os_memset(&event, 0, sizeof(event));
+ event.rx_probe_req.sa = mgmt->sa;
+ event.rx_probe_req.ie = mgmt->u.probe_req.variable;
+ event.rx_probe_req.ie_len =
+ len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req));
+ wpa_supplicant_event(drv->hapd, EVENT_RX_PROBE_REQ, &event);
+}
+#endif /* CONFIG_WPS */
+
+static int madwifi_receive_probe_req(struct madwifi_driver_data *drv)
+{
+ int ret = 0;
+#ifdef CONFIG_WPS
+ struct ieee80211req_set_filter filt;
+
+ wpa_printf(MSG_DEBUG, "%s Enter", __func__);
+ filt.app_filterype = IEEE80211_FILTER_TYPE_PROBE_REQ;
+
+ ret = set80211priv(drv, IEEE80211_IOCTL_FILTERFRAME, &filt,
+ sizeof(struct ieee80211req_set_filter));
+ if (ret)
+ return ret;
+
+ drv->sock_raw = l2_packet_init(drv->iface, NULL, ETH_P_80211_RAW,
+ madwifi_raw_receive, drv, 1);
+ if (drv->sock_raw == NULL)
+ return -1;
+#endif /* CONFIG_WPS */
+ return ret;
+}
+
+#ifdef CONFIG_WPS
+static int
+madwifi_set_wps_ie(void *priv, const u8 *ie, size_t len, u32 frametype)
+{
+ struct madwifi_driver_data *drv = priv;
+ u8 buf[256];
+ struct ieee80211req_getset_appiebuf *beac_ie;
+
+ wpa_printf(MSG_DEBUG, "%s buflen = %lu", __func__,
+ (unsigned long) len);
+
+ beac_ie = (struct ieee80211req_getset_appiebuf *) buf;
+ beac_ie->app_frmtype = frametype;
+ beac_ie->app_buflen = len;
+ memcpy(&(beac_ie->app_buf[0]), ie, len);
+
+ return set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, beac_ie,
+ sizeof(struct ieee80211req_getset_appiebuf) + len);
+}
+
+static int
+madwifi_set_ap_wps_ie(void *priv, const struct wpabuf *beacon,
+ const struct wpabuf *proberesp)
+{
+ if (madwifi_set_wps_ie(priv, beacon ? wpabuf_head(beacon) : NULL,
+ beacon ? wpabuf_len(beacon) : 0,
+ IEEE80211_APPIE_FRAME_BEACON))
+ return -1;
+ return madwifi_set_wps_ie(priv,
+ proberesp ? wpabuf_head(proberesp) : NULL,
+ proberesp ? wpabuf_len(proberesp): 0,
+ IEEE80211_APPIE_FRAME_PROBE_RESP);
+}
+#else /* CONFIG_WPS */
+#define madwifi_set_ap_wps_ie NULL
+#endif /* CONFIG_WPS */
+
+static void
+madwifi_new_sta(struct madwifi_driver_data *drv, u8 addr[IEEE80211_ADDR_LEN])
+{
+ struct hostapd_data *hapd = drv->hapd;
+ struct ieee80211req_wpaie ie;
+ int ielen = 0;
+ u8 *iebuf = NULL;
+
+ /*
+ * Fetch negotiated WPA/RSN parameters from the system.
+ */
+ memset(&ie, 0, sizeof(ie));
+ memcpy(ie.wpa_macaddr, addr, IEEE80211_ADDR_LEN);
+ if (set80211priv(drv, IEEE80211_IOCTL_GETWPAIE, &ie, sizeof(ie))) {
+ /*
+ * See ATH_WPS_IE comment in the beginning of the file for a
+ * possible cause for the failure..
+ */
+ wpa_printf(MSG_DEBUG, "%s: Failed to get WPA/RSN IE: %s",
+ __func__, strerror(errno));
+ goto no_ie;
+ }
+ wpa_hexdump(MSG_MSGDUMP, "madwifi req WPA IE",
+ ie.wpa_ie, IEEE80211_MAX_OPT_IE);
+ wpa_hexdump(MSG_MSGDUMP, "madwifi req RSN IE",
+ ie.rsn_ie, IEEE80211_MAX_OPT_IE);
+ iebuf = ie.wpa_ie;
+ /* madwifi seems to return some random data if WPA/RSN IE is not set.
+ * Assume the IE was not included if the IE type is unknown. */
+ if (iebuf[0] != WLAN_EID_VENDOR_SPECIFIC)
+ iebuf[1] = 0;
+ if (iebuf[1] == 0 && ie.rsn_ie[1] > 0) {
+ /* madwifi-ng svn #1453 added rsn_ie. Use it, if wpa_ie was not
+ * set. This is needed for WPA2. */
+ iebuf = ie.rsn_ie;
+ if (iebuf[0] != WLAN_EID_RSN)
+ iebuf[1] = 0;
+ }
+
+ ielen = iebuf[1];
+ if (ielen == 0)
+ iebuf = NULL;
+ else
+ ielen += 2;
+
+no_ie:
+ drv_event_assoc(hapd, addr, iebuf, ielen);
+
+ if (memcmp(addr, drv->acct_mac, ETH_ALEN) == 0) {
+ /* Cached accounting data is not valid anymore. */
+ memset(drv->acct_mac, 0, ETH_ALEN);
+ memset(&drv->acct_data, 0, sizeof(drv->acct_data));
+ }
+}
+
+static void
+madwifi_wireless_event_wireless_custom(struct madwifi_driver_data *drv,
+ char *custom, char *end)
+{
+ wpa_printf(MSG_DEBUG, "Custom wireless event: '%s'", custom);
+
+ if (strncmp(custom, "MLME-MICHAELMICFAILURE.indication", 33) == 0) {
+ char *pos;
+ u8 addr[ETH_ALEN];
+ pos = strstr(custom, "addr=");
+ if (pos == NULL) {
+ wpa_printf(MSG_DEBUG,
+ "MLME-MICHAELMICFAILURE.indication "
+ "without sender address ignored");
+ return;
+ }
+ pos += 5;
+ if (hwaddr_aton(pos, addr) == 0) {
+ union wpa_event_data data;
+ os_memset(&data, 0, sizeof(data));
+ data.michael_mic_failure.unicast = 1;
+ data.michael_mic_failure.src = addr;
+ wpa_supplicant_event(drv->hapd,
+ EVENT_MICHAEL_MIC_FAILURE, &data);
+ } else {
+ wpa_printf(MSG_DEBUG,
+ "MLME-MICHAELMICFAILURE.indication "
+ "with invalid MAC address");
+ }
+ } else if (strncmp(custom, "STA-TRAFFIC-STAT", 16) == 0) {
+ char *key, *value;
+ u32 val;
+ key = custom;
+ while ((key = strchr(key, '\n')) != NULL) {
+ key++;
+ value = strchr(key, '=');
+ if (value == NULL)
+ continue;
+ *value++ = '\0';
+ val = strtoul(value, NULL, 10);
+ if (strcmp(key, "mac") == 0)
+ hwaddr_aton(value, drv->acct_mac);
+ else if (strcmp(key, "rx_packets") == 0)
+ drv->acct_data.rx_packets = val;
+ else if (strcmp(key, "tx_packets") == 0)
+ drv->acct_data.tx_packets = val;
+ else if (strcmp(key, "rx_bytes") == 0)
+ drv->acct_data.rx_bytes = val;
+ else if (strcmp(key, "tx_bytes") == 0)
+ drv->acct_data.tx_bytes = val;
+ key = value;
+ }
+#ifdef CONFIG_WPS
+ } else if (strncmp(custom, "PUSH-BUTTON.indication", 22) == 0) {
+ /* Some atheros kernels send push button as a wireless event */
+ /* PROBLEM! this event is received for ALL BSSs ...
+ * so all are enabled for WPS... ugh.
+ */
+ wpa_supplicant_event(drv->hapd, EVENT_WPS_BUTTON_PUSHED, NULL);
+ } else if (strncmp(custom, "Manage.prob_req ", 16) == 0) {
+ /*
+ * Atheros driver uses a hack to pass Probe Request frames as a
+ * binary data in the custom wireless event. The old way (using
+ * packet sniffing) didn't work when bridging.
+ * Format: "Manage.prob_req <frame len>" | zero padding | frame
+ */
+#define WPS_FRAM_TAG_SIZE 30 /* hardcoded in driver */
+ int len = atoi(custom + 16);
+ if (len < 0 || custom + WPS_FRAM_TAG_SIZE + len > end) {
+ wpa_printf(MSG_DEBUG, "Invalid Manage.prob_req event "
+ "length %d", len);
+ return;
+ }
+ madwifi_raw_receive(drv, NULL,
+ (u8 *) custom + WPS_FRAM_TAG_SIZE, len);
+#endif /* CONFIG_WPS */
+ }
+}
+
+static void
+madwifi_wireless_event_wireless(struct madwifi_driver_data *drv,
+ char *data, int len)
+{
+ struct iw_event iwe_buf, *iwe = &iwe_buf;
+ char *pos, *end, *custom, *buf;
+
+ pos = data;
+ end = data + len;
+
+ while (pos + IW_EV_LCP_LEN <= end) {
+ /* Event data may be unaligned, so make a local, aligned copy
+ * before processing. */
+ memcpy(&iwe_buf, pos, IW_EV_LCP_LEN);
+ wpa_printf(MSG_MSGDUMP, "Wireless event: cmd=0x%x len=%d",
+ iwe->cmd, iwe->len);
+ if (iwe->len <= IW_EV_LCP_LEN)
+ return;
+
+ custom = pos + IW_EV_POINT_LEN;
+ if (drv->we_version > 18 &&
+ (iwe->cmd == IWEVMICHAELMICFAILURE ||
+ iwe->cmd == IWEVASSOCREQIE ||
+ iwe->cmd == IWEVCUSTOM)) {
+ /* WE-19 removed the pointer from struct iw_point */
+ char *dpos = (char *) &iwe_buf.u.data.length;
+ int dlen = dpos - (char *) &iwe_buf;
+ memcpy(dpos, pos + IW_EV_LCP_LEN,
+ sizeof(struct iw_event) - dlen);
+ } else {
+ memcpy(&iwe_buf, pos, sizeof(struct iw_event));
+ custom += IW_EV_POINT_OFF;
+ }
+
+ switch (iwe->cmd) {
+ case IWEVEXPIRED:
+ drv_event_disassoc(drv->hapd,
+ (u8 *) iwe->u.addr.sa_data);
+ break;
+ case IWEVREGISTERED:
+ madwifi_new_sta(drv, (u8 *) iwe->u.addr.sa_data);
+ break;
+ case IWEVASSOCREQIE:
+ /* Driver hack.. Use IWEVASSOCREQIE to bypass
+ * IWEVCUSTOM size limitations. Need to handle this
+ * just like IWEVCUSTOM.
+ */
+ case IWEVCUSTOM:
+ if (custom + iwe->u.data.length > end)
+ return;
+ buf = malloc(iwe->u.data.length + 1);
+ if (buf == NULL)
+ return; /* XXX */
+ memcpy(buf, custom, iwe->u.data.length);
+ buf[iwe->u.data.length] = '\0';
+ madwifi_wireless_event_wireless_custom(
+ drv, buf, buf + iwe->u.data.length);
+ free(buf);
+ break;
+ }
+
+ pos += iwe->len;
+ }
+}
+
+
+static void
+madwifi_wireless_event_rtm_newlink(void *ctx,
+ struct ifinfomsg *ifi, u8 *buf, size_t len)
+{
+ struct madwifi_driver_data *drv = ctx;
+ int attrlen, rta_len;
+ struct rtattr *attr;
+
+ if (ifi->ifi_index != drv->ifindex)
+ return;
+
+ attrlen = len;
+ attr = (struct rtattr *) buf;
+
+ rta_len = RTA_ALIGN(sizeof(struct rtattr));
+ while (RTA_OK(attr, attrlen)) {
+ if (attr->rta_type == IFLA_WIRELESS) {
+ madwifi_wireless_event_wireless(
+ drv, ((char *) attr) + rta_len,
+ attr->rta_len - rta_len);
+ }
+ attr = RTA_NEXT(attr, attrlen);
+ }
+}
+
+
+static int
+madwifi_get_we_version(struct madwifi_driver_data *drv)
+{
+ struct iw_range *range;
+ struct iwreq iwr;
+ int minlen;
+ size_t buflen;
+
+ drv->we_version = 0;
+
+ /*
+ * Use larger buffer than struct iw_range in order to allow the
+ * structure to grow in the future.
+ */
+ buflen = sizeof(struct iw_range) + 500;
+ range = os_zalloc(buflen);
+ if (range == NULL)
+ return -1;
+
+ memset(&iwr, 0, sizeof(iwr));
+ os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
+ iwr.u.data.pointer = (caddr_t) range;
+ iwr.u.data.length = buflen;
+
+ minlen = ((char *) &range->enc_capa) - (char *) range +
+ sizeof(range->enc_capa);
+
+ if (ioctl(drv->ioctl_sock, SIOCGIWRANGE, &iwr) < 0) {
+ perror("ioctl[SIOCGIWRANGE]");
+ free(range);
+ return -1;
+ } else if (iwr.u.data.length >= minlen &&
+ range->we_version_compiled >= 18) {
+ wpa_printf(MSG_DEBUG, "SIOCGIWRANGE: WE(compiled)=%d "
+ "WE(source)=%d enc_capa=0x%x",
+ range->we_version_compiled,
+ range->we_version_source,
+ range->enc_capa);
+ drv->we_version = range->we_version_compiled;
+ }
+
+ free(range);
+ return 0;
+}
+
+
+static int
+madwifi_wireless_event_init(struct madwifi_driver_data *drv)
+{
+ struct netlink_config *cfg;
+
+ madwifi_get_we_version(drv);
+
+ cfg = os_zalloc(sizeof(*cfg));
+ if (cfg == NULL)
+ return -1;
+ cfg->ctx = drv;
+ cfg->newlink_cb = madwifi_wireless_event_rtm_newlink;
+ drv->netlink = netlink_init(cfg);
+ if (drv->netlink == NULL) {
+ os_free(cfg);
+ return -1;
+ }
+
+ return 0;
+}
+
+
+static int
+madwifi_send_eapol(void *priv, const u8 *addr, const u8 *data, size_t data_len,
+ int encrypt, const u8 *own_addr)
+{
+ struct madwifi_driver_data *drv = priv;
+ unsigned char buf[3000];
+ unsigned char *bp = buf;
+ struct l2_ethhdr *eth;
+ size_t len;
+ int status;
+
+ /*
+ * Prepend the Ethernet header. If the caller left us
+ * space at the front we could just insert it but since
+ * we don't know we copy to a local buffer. Given the frequency
+ * and size of frames this probably doesn't matter.
+ */
+ len = data_len + sizeof(struct l2_ethhdr);
+ if (len > sizeof(buf)) {
+ bp = malloc(len);
+ if (bp == NULL) {
+ printf("EAPOL frame discarded, cannot malloc temp "
+ "buffer of size %lu!\n", (unsigned long) len);
+ return -1;
+ }
+ }
+ eth = (struct l2_ethhdr *) bp;
+ memcpy(eth->h_dest, addr, ETH_ALEN);
+ memcpy(eth->h_source, own_addr, ETH_ALEN);
+ eth->h_proto = host_to_be16(ETH_P_EAPOL);
+ memcpy(eth+1, data, data_len);
+
+ wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", bp, len);
+
+ status = l2_packet_send(drv->sock_xmit, addr, ETH_P_EAPOL, bp, len);
+
+ if (bp != buf)
+ free(bp);
+ return status;
+}
+
+static void
+handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
+{
+ struct madwifi_driver_data *drv = ctx;
+ drv_event_eapol_rx(drv->hapd, src_addr, buf + sizeof(struct l2_ethhdr),
+ len - sizeof(struct l2_ethhdr));
+}
+
+static void *
+madwifi_init(struct hostapd_data *hapd, struct wpa_init_params *params)
+{
+ struct madwifi_driver_data *drv;
+ struct ifreq ifr;
+ struct iwreq iwr;
+ char brname[IFNAMSIZ];
+
+ drv = os_zalloc(sizeof(struct madwifi_driver_data));
+ if (drv == NULL) {
+ printf("Could not allocate memory for madwifi driver data\n");
+ return NULL;
+ }
+
+ drv->hapd = hapd;
+ drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
+ if (drv->ioctl_sock < 0) {
+ perror("socket[PF_INET,SOCK_DGRAM]");
+ goto bad;
+ }
+ memcpy(drv->iface, params->ifname, sizeof(drv->iface));
+
+ memset(&ifr, 0, sizeof(ifr));
+ os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
+ if (ioctl(drv->ioctl_sock, SIOCGIFINDEX, &ifr) != 0) {
+ perror("ioctl(SIOCGIFINDEX)");
+ goto bad;
+ }
+ drv->ifindex = ifr.ifr_ifindex;
+
+ drv->sock_xmit = l2_packet_init(drv->iface, NULL, ETH_P_EAPOL,
+ handle_read, drv, 1);
+ if (drv->sock_xmit == NULL)
+ goto bad;
+ if (l2_packet_get_own_addr(drv->sock_xmit, params->own_addr))
+ goto bad;
+ if (params->bridge[0]) {
+ wpa_printf(MSG_DEBUG, "Configure bridge %s for EAPOL traffic.",
+ params->bridge[0]);
+ drv->sock_recv = l2_packet_init(params->bridge[0], NULL,
+ ETH_P_EAPOL, handle_read, drv,
+ 1);
+ if (drv->sock_recv == NULL)
+ goto bad;
+ } else if (linux_br_get(brname, drv->iface) == 0) {
+ wpa_printf(MSG_DEBUG, "Interface in bridge %s; configure for "
+ "EAPOL receive", brname);
+ drv->sock_recv = l2_packet_init(brname, NULL, ETH_P_EAPOL,
+ handle_read, drv, 1);
+ if (drv->sock_recv == NULL)
+ goto bad;
+ } else
+ drv->sock_recv = drv->sock_xmit;
+
+ memset(&iwr, 0, sizeof(iwr));
+ os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
+
+ iwr.u.mode = IW_MODE_MASTER;
+
+ if (ioctl(drv->ioctl_sock, SIOCSIWMODE, &iwr) < 0) {
+ perror("ioctl[SIOCSIWMODE]");
+ printf("Could not set interface to master mode!\n");
+ goto bad;
+ }
+
+ /* mark down during setup */
+ linux_set_iface_flags(drv->ioctl_sock, drv->iface, 0);
+ madwifi_set_privacy(drv, 0); /* default to no privacy */
+
+ madwifi_receive_probe_req(drv);
+
+ if (madwifi_wireless_event_init(drv))
+ goto bad;
+
+ return drv;
+bad:
+ if (drv->sock_recv != NULL && drv->sock_recv != drv->sock_xmit)
+ l2_packet_deinit(drv->sock_recv);
+ if (drv->sock_xmit != NULL)
+ l2_packet_deinit(drv->sock_xmit);
+ if (drv->ioctl_sock >= 0)
+ close(drv->ioctl_sock);
+ if (drv != NULL)
+ free(drv);
+ return NULL;
+}
+
+
+static void
+madwifi_deinit(void *priv)
+{
+ struct madwifi_driver_data *drv = priv;
+
+ netlink_deinit(drv->netlink);
+ (void) linux_set_iface_flags(drv->ioctl_sock, drv->iface, 0);
+ if (drv->ioctl_sock >= 0)
+ close(drv->ioctl_sock);
+ if (drv->sock_recv != NULL && drv->sock_recv != drv->sock_xmit)
+ l2_packet_deinit(drv->sock_recv);
+ if (drv->sock_xmit != NULL)
+ l2_packet_deinit(drv->sock_xmit);
+ if (drv->sock_raw)
+ l2_packet_deinit(drv->sock_raw);
+ free(drv);
+}
+
+static int
+madwifi_set_ssid(void *priv, const u8 *buf, int len)
+{
+ struct madwifi_driver_data *drv = priv;
+ struct iwreq iwr;
+
+ memset(&iwr, 0, sizeof(iwr));
+ os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
+ iwr.u.essid.flags = 1; /* SSID active */
+ iwr.u.essid.pointer = (caddr_t) buf;
+ iwr.u.essid.length = len + 1;
+
+ if (ioctl(drv->ioctl_sock, SIOCSIWESSID, &iwr) < 0) {
+ perror("ioctl[SIOCSIWESSID]");
+ printf("len=%d\n", len);
+ return -1;
+ }
+ return 0;
+}
+
+static int
+madwifi_get_ssid(void *priv, u8 *buf, int len)
+{
+ struct madwifi_driver_data *drv = priv;
+ struct iwreq iwr;
+ int ret = 0;
+
+ memset(&iwr, 0, sizeof(iwr));
+ os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
+ iwr.u.essid.pointer = (caddr_t) buf;
+ iwr.u.essid.length = len;
+
+ if (ioctl(drv->ioctl_sock, SIOCGIWESSID, &iwr) < 0) {
+ perror("ioctl[SIOCGIWESSID]");
+ ret = -1;
+ } else
+ ret = iwr.u.essid.length;
+
+ return ret;
+}
+
+static int
+madwifi_set_countermeasures(void *priv, int enabled)
+{
+ struct madwifi_driver_data *drv = priv;
+ wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled);
+ return set80211param(drv, IEEE80211_PARAM_COUNTERMEASURES, enabled);
+}
+
+static int
+madwifi_commit(void *priv)
+{
+ struct madwifi_driver_data *drv = priv;
+ return linux_set_iface_flags(drv->ioctl_sock, drv->iface, 1);
+}
+
+const struct wpa_driver_ops wpa_driver_atheros_ops = {
+ .name = "atheros",
+ .hapd_init = madwifi_init,
+ .hapd_deinit = madwifi_deinit,
+ .set_ieee8021x = madwifi_set_ieee8021x,
+ .set_privacy = madwifi_set_privacy,
+ .set_key = madwifi_set_key,
+ .get_seqnum = madwifi_get_seqnum,
+ .flush = madwifi_flush,
+ .set_generic_elem = madwifi_set_opt_ie,
+ .sta_set_flags = madwifi_sta_set_flags,
+ .read_sta_data = madwifi_read_sta_driver_data,
+ .hapd_send_eapol = madwifi_send_eapol,
+ .sta_disassoc = madwifi_sta_disassoc,
+ .sta_deauth = madwifi_sta_deauth,
+ .hapd_set_ssid = madwifi_set_ssid,
+ .hapd_get_ssid = madwifi_get_ssid,
+ .set_countermeasures = madwifi_set_countermeasures,
+ .sta_clear_stats = madwifi_sta_clear_stats,
+ .commit = madwifi_commit,
+ .set_ap_wps_ie = madwifi_set_ap_wps_ie,
+};
diff --git a/contrib/wpa/src/drivers/driver_ndis.c b/contrib/wpa/src/drivers/driver_ndis.c
index 0bda20a..9344a99 100644
--- a/contrib/wpa/src/drivers/driver_ndis.c
+++ b/contrib/wpa/src/drivers/driver_ndis.c
@@ -40,7 +40,7 @@ int close(int fd);
#include "common.h"
#include "driver.h"
#include "eloop.h"
-#include "ieee802_11_defs.h"
+#include "common/ieee802_11_defs.h"
#include "driver_ndis.h"
int wpa_driver_register_event_cb(struct wpa_driver_ndis_data *drv);
@@ -354,6 +354,47 @@ typedef struct NDIS_802_11_PMKID_CANDIDATE_LIST {
#endif /* OID_802_11_CAPABILITY */
+#ifndef OID_DOT11_CURRENT_OPERATION_MODE
+/* Native 802.11 OIDs */
+#define OID_DOT11_NDIS_START 0x0D010300
+#define OID_DOT11_CURRENT_OPERATION_MODE (OID_DOT11_NDIS_START + 8)
+#define OID_DOT11_SCAN_REQUEST (OID_DOT11_NDIS_START + 11)
+
+typedef enum _DOT11_BSS_TYPE {
+ dot11_BSS_type_infrastructure = 1,
+ dot11_BSS_type_independent = 2,
+ dot11_BSS_type_any = 3
+} DOT11_BSS_TYPE, * PDOT11_BSS_TYPE;
+
+typedef UCHAR DOT11_MAC_ADDRESS[6];
+typedef DOT11_MAC_ADDRESS * PDOT11_MAC_ADDRESS;
+
+typedef enum _DOT11_SCAN_TYPE {
+ dot11_scan_type_active = 1,
+ dot11_scan_type_passive = 2,
+ dot11_scan_type_auto = 3,
+ dot11_scan_type_forced = 0x80000000
+} DOT11_SCAN_TYPE, * PDOT11_SCAN_TYPE;
+
+typedef struct _DOT11_SCAN_REQUEST_V2 {
+ DOT11_BSS_TYPE dot11BSSType;
+ DOT11_MAC_ADDRESS dot11BSSID;
+ DOT11_SCAN_TYPE dot11ScanType;
+ BOOLEAN bRestrictedScan;
+ ULONG udot11SSIDsOffset;
+ ULONG uNumOfdot11SSIDs;
+ BOOLEAN bUseRequestIE;
+ ULONG uRequestIDsOffset;
+ ULONG uNumOfRequestIDs;
+ ULONG uPhyTypeInfosOffset;
+ ULONG uNumOfPhyTypeInfos;
+ ULONG uIEsOffset;
+ ULONG uIEsLength;
+ UCHAR ucBuffer[1];
+} DOT11_SCAN_REQUEST_V2, * PDOT11_SCAN_REQUEST_V2;
+
+#endif /* OID_DOT11_CURRENT_OPERATION_MODE */
+
#ifdef CONFIG_USE_NDISUIO
#ifndef _WIN32_WCE
#ifdef __MINGW32_VERSION
@@ -699,25 +740,42 @@ static int wpa_driver_ndis_disassociate(void *priv, const u8 *addr,
}
-static int wpa_driver_ndis_set_wpa(void *priv, int enabled)
+static void wpa_driver_ndis_scan_timeout(void *eloop_ctx, void *timeout_ctx)
{
- wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled);
- return 0;
+ wpa_printf(MSG_DEBUG, "Scan timeout - try to get results");
+ wpa_supplicant_event(timeout_ctx, EVENT_SCAN_RESULTS, NULL);
}
-static void wpa_driver_ndis_scan_timeout(void *eloop_ctx, void *timeout_ctx)
+static int wpa_driver_ndis_scan_native80211(
+ struct wpa_driver_ndis_data *drv,
+ struct wpa_driver_scan_params *params)
{
- wpa_printf(MSG_DEBUG, "Scan timeout - try to get results");
- wpa_supplicant_event(timeout_ctx, EVENT_SCAN_RESULTS, NULL);
+ DOT11_SCAN_REQUEST_V2 req;
+ int res;
+
+ os_memset(&req, 0, sizeof(req));
+ req.dot11BSSType = dot11_BSS_type_any;
+ os_memset(req.dot11BSSID, 0xff, ETH_ALEN);
+ req.dot11ScanType = dot11_scan_type_auto;
+ res = ndis_set_oid(drv, OID_DOT11_SCAN_REQUEST, (char *) &req,
+ sizeof(req));
+ eloop_cancel_timeout(wpa_driver_ndis_scan_timeout, drv, drv->ctx);
+ eloop_register_timeout(7, 0, wpa_driver_ndis_scan_timeout, drv,
+ drv->ctx);
+ return res;
}
-static int wpa_driver_ndis_scan(void *priv, const u8 *ssid, size_t ssid_len)
+static int wpa_driver_ndis_scan(void *priv,
+ struct wpa_driver_scan_params *params)
{
struct wpa_driver_ndis_data *drv = priv;
int res;
+ if (drv->native80211)
+ return wpa_driver_ndis_scan_native80211(drv, params);
+
if (!drv->radio_enabled) {
wpa_printf(MSG_DEBUG, "NDIS: turning radio on before the first"
" scan");
@@ -735,6 +793,25 @@ static int wpa_driver_ndis_scan(void *priv, const u8 *ssid, size_t ssid_len)
}
+static const u8 * wpa_scan_get_ie(const struct wpa_scan_res *res, u8 ie)
+{
+ const u8 *end, *pos;
+
+ pos = (const u8 *) (res + 1);
+ end = pos + res->ie_len;
+
+ while (pos + 1 < end) {
+ if (pos + 2 + pos[1] > end)
+ break;
+ if (pos[0] == ie)
+ return pos;
+ pos += 2 + pos[1];
+ }
+
+ return NULL;
+}
+
+
static struct wpa_scan_res * wpa_driver_ndis_add_scan_ssid(
struct wpa_scan_res *r, NDIS_802_11_SSID *ssid)
{
@@ -913,7 +990,8 @@ static int wpa_driver_ndis_add_wep(struct wpa_driver_ndis_data *drv,
}
-static int wpa_driver_ndis_set_key(void *priv, wpa_alg alg, const u8 *addr,
+static int wpa_driver_ndis_set_key(const char *ifname, void *priv,
+ enum wpa_alg alg, const u8 *addr,
int key_idx, int set_tx,
const u8 *seq, size_t seq_len,
const u8 *key, size_t key_len)
@@ -1021,7 +1099,8 @@ wpa_driver_ndis_associate(void *priv,
continue;
wpa_printf(MSG_DEBUG, "NDIS: Re-setting static WEP "
"key %d", i);
- wpa_driver_ndis_set_key(drv, WPA_ALG_WEP, bcast, i,
+ wpa_driver_ndis_set_key(drv->ifname, drv, WPA_ALG_WEP,
+ bcast, i,
i == params->wep_tx_keyidx,
NULL, 0, params->wep_key[i],
params->wep_key_len[i]);
@@ -1029,8 +1108,8 @@ wpa_driver_ndis_associate(void *priv,
}
if (params->wpa_ie == NULL || params->wpa_ie_len == 0) {
- if (params->auth_alg & AUTH_ALG_SHARED_KEY) {
- if (params->auth_alg & AUTH_ALG_OPEN_SYSTEM)
+ if (params->auth_alg & WPA_AUTH_ALG_SHARED) {
+ if (params->auth_alg & WPA_AUTH_ALG_OPEN)
auth_mode = Ndis802_11AuthModeAutoSwitch;
else
auth_mode = Ndis802_11AuthModeShared;
@@ -2802,16 +2881,31 @@ static void * wpa_driver_ndis_init(void *ctx, const char *ifname)
mode = Ndis802_11Infrastructure;
if (ndis_set_oid(drv, OID_802_11_INFRASTRUCTURE_MODE,
(char *) &mode, sizeof(mode)) < 0) {
+ char buf[8];
+ int res;
wpa_printf(MSG_DEBUG, "NDIS: Failed to set "
"OID_802_11_INFRASTRUCTURE_MODE (%d)",
(int) mode);
/* Try to continue anyway */
- if (!drv->has_capability && drv->capa.enc == 0) {
+ res = ndis_get_oid(drv, OID_DOT11_CURRENT_OPERATION_MODE, buf,
+ sizeof(buf));
+ if (res > 0) {
+ wpa_printf(MSG_INFO, "NDIS: The driver seems to use "
+ "Native 802.11 OIDs. These are not yet "
+ "fully supported.");
+ drv->native80211 = 1;
+ } else if (!drv->has_capability || drv->capa.enc == 0) {
+ /*
+ * Note: This will also happen with NDIS 6 drivers with
+ * Vista.
+ */
wpa_printf(MSG_DEBUG, "NDIS: Driver did not provide "
"any wireless capabilities - assume it is "
"a wired interface");
drv->wired = 1;
+ drv->capa.flags |= WPA_DRIVER_FLAGS_WIRED;
+ drv->has_capability = 1;
ndis_add_multicast(drv);
}
}
@@ -3097,19 +3191,14 @@ const struct wpa_driver_ops wpa_driver_ndis_ops = {
"Windows NDIS driver",
wpa_driver_ndis_get_bssid,
wpa_driver_ndis_get_ssid,
- wpa_driver_ndis_set_wpa,
wpa_driver_ndis_set_key,
wpa_driver_ndis_init,
wpa_driver_ndis_deinit,
NULL /* set_param */,
NULL /* set_countermeasures */,
- NULL /* set_drop_unencrypted */,
- wpa_driver_ndis_scan,
- NULL /* get_scan_results */,
wpa_driver_ndis_deauthenticate,
wpa_driver_ndis_disassociate,
wpa_driver_ndis_associate,
- NULL /* set_auth_alg */,
wpa_driver_ndis_add_pmkid,
wpa_driver_ndis_remove_pmkid,
wpa_driver_ndis_flush_pmkid,
@@ -3130,11 +3219,61 @@ const struct wpa_driver_ops wpa_driver_ndis_ops = {
NULL /* update_ft_ies */,
NULL /* send_ft_action */,
wpa_driver_ndis_get_scan_results,
- NULL /* set_probe_req_ie */,
- NULL /* set_mode */,
NULL /* set_country */,
NULL /* global_init */,
NULL /* global_deinit */,
NULL /* init2 */,
- wpa_driver_ndis_get_interfaces
+ wpa_driver_ndis_get_interfaces,
+ wpa_driver_ndis_scan,
+ NULL /* authenticate */,
+ NULL /* set_beacon */,
+ NULL /* hapd_init */,
+ NULL /* hapd_deinit */,
+ NULL /* set_ieee8021x */,
+ NULL /* set_privacy */,
+ NULL /* get_seqnum */,
+ NULL /* flush */,
+ NULL /* set_generic_elem */,
+ NULL /* read_sta_data */,
+ NULL /* hapd_send_eapol */,
+ NULL /* sta_deauth */,
+ NULL /* sta_disassoc */,
+ NULL /* sta_remove */,
+ NULL /* hapd_get_ssid */,
+ NULL /* hapd_set_ssid */,
+ NULL /* hapd_set_countermeasures */,
+ NULL /* sta_add */,
+ NULL /* get_inact_sec */,
+ NULL /* sta_clear_stats */,
+ NULL /* set_freq */,
+ NULL /* set_rts */,
+ NULL /* set_frag */,
+ NULL /* sta_set_flags */,
+ NULL /* set_rate_sets */,
+ NULL /* set_cts_protect */,
+ NULL /* set_preamble */,
+ NULL /* set_short_slot_time */,
+ NULL /* set_tx_queue_params */,
+ NULL /* valid_bss_mask */,
+ NULL /* if_add */,
+ NULL /* if_remove */,
+ NULL /* set_sta_vlan */,
+ NULL /* commit */,
+ NULL /* send_ether */,
+ NULL /* set_radius_acl_auth */,
+ NULL /* set_radius_acl_expire */,
+ NULL /* set_ht_params */,
+ NULL /* set_ap_wps_ie */,
+ NULL /* set_supp_port */,
+ NULL /* set_wds_sta */,
+ NULL /* send_action */,
+ NULL /* remain_on_channel */,
+ NULL /* cancel_remain_on_channel */,
+ NULL /* probe_req_report */,
+ NULL /* disable_11b_rates */,
+ NULL /* deinit_ap */,
+ NULL /* suspend */,
+ NULL /* resume */,
+ NULL /* signal_monitor */,
+ NULL /* send_frame */
};
diff --git a/contrib/wpa/src/drivers/driver_ndis.h b/contrib/wpa/src/drivers/driver_ndis.h
index cdce4ba..f263f0e 100644
--- a/contrib/wpa/src/drivers/driver_ndis.h
+++ b/contrib/wpa/src/drivers/driver_ndis.h
@@ -52,6 +52,7 @@ struct wpa_driver_ndis_data {
struct ndis_pmkid_entry *pmkid;
char *adapter_desc;
int wired;
+ int native80211;
int mode;
int wzc_disabled;
int oid_bssid_set;
diff --git a/contrib/wpa/src/drivers/driver_ndiswrapper.c b/contrib/wpa/src/drivers/driver_ndiswrapper.c
index b5c534a..cd2f61e 100644
--- a/contrib/wpa/src/drivers/driver_ndiswrapper.c
+++ b/contrib/wpa/src/drivers/driver_ndiswrapper.c
@@ -33,9 +33,8 @@ struct wpa_driver_ndiswrapper_data {
};
-struct wpa_key
-{
- wpa_alg alg;
+struct wpa_key {
+ enum wpa_alg alg;
const u8 *addr;
int key_index;
int set_tx;
@@ -45,17 +44,16 @@ struct wpa_key
size_t key_len;
};
-struct wpa_assoc_info
-{
+struct wpa_assoc_info {
const u8 *bssid;
const u8 *ssid;
size_t ssid_len;
int freq;
const u8 *wpa_ie;
size_t wpa_ie_len;
- wpa_cipher pairwise_suite;
- wpa_cipher group_suite;
- wpa_key_mgmt key_mgmt_suite;
+ enum wpa_cipher pairwise_suite;
+ enum wpa_cipher group_suite;
+ enum wpa_key_mgmt key_mgmt_suite;
int auth_alg;
int mode;
};
@@ -73,6 +71,8 @@ struct wpa_assoc_info
#define WPA_DEINIT SIOCIWFIRSTPRIV+10
#define WPA_GET_CAPA SIOCIWFIRSTPRIV+11
+static int wpa_ndiswrapper_set_auth_alg(void *priv, int auth_alg);
+
static int get_socket(void)
{
static const int families[] = {
@@ -111,7 +111,8 @@ static int wpa_ndiswrapper_set_wpa(void *priv, int enabled)
return ret;
}
-static int wpa_ndiswrapper_set_key(void *priv, wpa_alg alg, const u8 *addr,
+static int wpa_ndiswrapper_set_key(const char *ifname, void *priv,
+ enum wpa_alg alg, const u8 *addr,
int key_idx, int set_tx,
const u8 *seq, size_t seq_len,
const u8 *key, size_t key_len)
@@ -146,8 +147,8 @@ static int wpa_ndiswrapper_set_key(void *priv, wpa_alg alg, const u8 *addr,
* did not associate. Try to make sure the keys are cleared so
* that plaintext APs can be used in all cases.
*/
- wpa_driver_wext_set_key(drv->wext, alg, addr, key_idx, set_tx,
- seq, seq_len, key, key_len);
+ wpa_driver_wext_set_key(ifname, drv->wext, alg, addr, key_idx,
+ set_tx, seq, seq_len, key, key_len);
}
return ret;
@@ -223,6 +224,12 @@ wpa_ndiswrapper_associate(void *priv,
struct wpa_assoc_info wpa_assoc_info;
struct iwreq priv_req;
+ if (wpa_ndiswrapper_set_drop_unencrypted(drv,
+ params->drop_unencrypted) < 0)
+ ret = -1;
+ if (wpa_ndiswrapper_set_auth_alg(drv, params->auth_alg) < 0)
+ ret = -1;
+
os_memset(&priv_req, 0, sizeof(priv_req));
os_memset(&wpa_assoc_info, 0, sizeof(wpa_assoc_info));
@@ -274,10 +281,11 @@ static int wpa_ndiswrapper_get_ssid(void *priv, u8 *ssid)
}
-static int wpa_ndiswrapper_scan(void *priv, const u8 *ssid, size_t ssid_len)
+static int wpa_ndiswrapper_scan(void *priv,
+ struct wpa_driver_scan_params *params)
{
struct wpa_driver_ndiswrapper_data *drv = priv;
- return wpa_driver_wext_scan(drv->wext, ssid, ssid_len);
+ return wpa_driver_wext_scan(drv->wext, params);
}
@@ -334,6 +342,8 @@ static void * wpa_ndiswrapper_init(void *ctx, const char *ifname)
return NULL;
}
+ wpa_ndiswrapper_set_wpa(drv, 1);
+
return drv;
}
@@ -341,6 +351,7 @@ static void * wpa_ndiswrapper_init(void *ctx, const char *ifname)
static void wpa_ndiswrapper_deinit(void *priv)
{
struct wpa_driver_ndiswrapper_data *drv = priv;
+ wpa_ndiswrapper_set_wpa(drv, 0);
wpa_driver_wext_deinit(drv->wext);
close(drv->sock);
os_free(drv);
@@ -350,18 +361,15 @@ static void wpa_ndiswrapper_deinit(void *priv)
const struct wpa_driver_ops wpa_driver_ndiswrapper_ops = {
.name = "ndiswrapper",
.desc = "Linux ndiswrapper (deprecated; use wext)",
- .set_wpa = wpa_ndiswrapper_set_wpa,
.set_key = wpa_ndiswrapper_set_key,
.set_countermeasures = wpa_ndiswrapper_set_countermeasures,
- .set_drop_unencrypted = wpa_ndiswrapper_set_drop_unencrypted,
.deauthenticate = wpa_ndiswrapper_deauthenticate,
.disassociate = wpa_ndiswrapper_disassociate,
.associate = wpa_ndiswrapper_associate,
- .set_auth_alg = wpa_ndiswrapper_set_auth_alg,
.get_bssid = wpa_ndiswrapper_get_bssid,
.get_ssid = wpa_ndiswrapper_get_ssid,
- .scan = wpa_ndiswrapper_scan,
+ .scan2 = wpa_ndiswrapper_scan,
.get_scan_results2 = wpa_ndiswrapper_get_scan_results,
.init = wpa_ndiswrapper_init,
.deinit = wpa_ndiswrapper_deinit,
diff --git a/contrib/wpa/src/drivers/driver_none.c b/contrib/wpa/src/drivers/driver_none.c
new file mode 100644
index 0000000..aaeacd6
--- /dev/null
+++ b/contrib/wpa/src/drivers/driver_none.c
@@ -0,0 +1,99 @@
+/*
+ * Driver interface for RADIUS server or WPS ER only (no driver)
+ * Copyright (c) 2008, Atheros Communications
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "driver.h"
+
+
+struct none_driver_data {
+ struct hostapd_data *hapd;
+ void *ctx;
+};
+
+
+static void * none_driver_hapd_init(struct hostapd_data *hapd,
+ struct wpa_init_params *params)
+{
+ struct none_driver_data *drv;
+
+ drv = os_zalloc(sizeof(struct none_driver_data));
+ if (drv == NULL) {
+ wpa_printf(MSG_ERROR, "Could not allocate memory for none "
+ "driver data");
+ return NULL;
+ }
+ drv->hapd = hapd;
+
+ return drv;
+}
+
+
+static void none_driver_hapd_deinit(void *priv)
+{
+ struct none_driver_data *drv = priv;
+
+ os_free(drv);
+}
+
+
+static int none_driver_send_ether(void *priv, const u8 *dst, const u8 *src,
+ u16 proto, const u8 *data, size_t data_len)
+{
+ return 0;
+}
+
+
+static void * none_driver_init(void *ctx, const char *ifname)
+{
+ struct none_driver_data *drv;
+
+ drv = os_zalloc(sizeof(struct none_driver_data));
+ if (drv == NULL) {
+ wpa_printf(MSG_ERROR, "Could not allocate memory for none "
+ "driver data");
+ return NULL;
+ }
+ drv->ctx = ctx;
+
+ return drv;
+}
+
+
+static void none_driver_deinit(void *priv)
+{
+ struct none_driver_data *drv = priv;
+
+ os_free(drv);
+}
+
+
+static int none_driver_send_eapol(void *priv, const u8 *dest, u16 proto,
+ const u8 *data, size_t data_len)
+{
+ return -1;
+}
+
+
+const struct wpa_driver_ops wpa_driver_none_ops = {
+ .name = "none",
+ .desc = "no driver (RADIUS server/WPS ER)",
+ .hapd_init = none_driver_hapd_init,
+ .hapd_deinit = none_driver_hapd_deinit,
+ .send_ether = none_driver_send_ether,
+ .init = none_driver_init,
+ .deinit = none_driver_deinit,
+ .send_eapol = none_driver_send_eapol,
+};
diff --git a/contrib/wpa/src/drivers/driver_wired.c b/contrib/wpa/src/drivers/driver_wired.c
index 098991a..2b197f0 100644
--- a/contrib/wpa/src/drivers/driver_wired.c
+++ b/contrib/wpa/src/drivers/driver_wired.c
@@ -1,6 +1,7 @@
/*
- * WPA Supplicant - wired Ethernet driver interface
- * Copyright (c) 2005-2007, Jouni Malinen <j@w1.fi>
+ * Wired Ethernet driver interface
+ * Copyright (c) 2005-2009, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2004, Gunter Burchardt <tira@isx.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -17,27 +18,374 @@
#include <net/if.h>
#ifdef __linux__
#include <netpacket/packet.h>
+#include <net/if_arp.h>
+#include <net/if.h>
#endif /* __linux__ */
-#if defined(__FreeBSD__) || defined(__DragonFly__)
+#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
#include <net/if_dl.h>
-#endif /* defined(__FreeBSD__) || defined(__DragonFly__) */
+#endif /* defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__) */
#include "common.h"
+#include "eloop.h"
#include "driver.h"
+#ifdef _MSC_VER
+#pragma pack(push, 1)
+#endif /* _MSC_VER */
+
+struct ieee8023_hdr {
+ u8 dest[6];
+ u8 src[6];
+ u16 ethertype;
+} STRUCT_PACKED;
+
+#ifdef _MSC_VER
+#pragma pack(pop)
+#endif /* _MSC_VER */
static const u8 pae_group_addr[ETH_ALEN] =
{ 0x01, 0x80, 0xc2, 0x00, 0x00, 0x03 };
struct wpa_driver_wired_data {
+ char ifname[IFNAMSIZ + 1];
void *ctx;
+
+ int sock; /* raw packet socket for driver access */
+ int dhcp_sock; /* socket for dhcp packets */
+ int use_pae_group_addr;
+
int pf_sock;
- char ifname[IFNAMSIZ + 1];
int membership, multi, iff_allmulti, iff_up;
};
+/* TODO: detecting new devices should eventually be changed from using DHCP
+ * snooping to trigger on any packet from a new layer 2 MAC address, e.g.,
+ * based on ebtables, etc. */
+
+struct dhcp_message {
+ u_int8_t op;
+ u_int8_t htype;
+ u_int8_t hlen;
+ u_int8_t hops;
+ u_int32_t xid;
+ u_int16_t secs;
+ u_int16_t flags;
+ u_int32_t ciaddr;
+ u_int32_t yiaddr;
+ u_int32_t siaddr;
+ u_int32_t giaddr;
+ u_int8_t chaddr[16];
+ u_int8_t sname[64];
+ u_int8_t file[128];
+ u_int32_t cookie;
+ u_int8_t options[308]; /* 312 - cookie */
+};
+
+
+static int wired_multicast_membership(int sock, int ifindex,
+ const u8 *addr, int add)
+{
+#ifdef __linux__
+ struct packet_mreq mreq;
+
+ if (sock < 0)
+ return -1;
+
+ os_memset(&mreq, 0, sizeof(mreq));
+ mreq.mr_ifindex = ifindex;
+ mreq.mr_type = PACKET_MR_MULTICAST;
+ mreq.mr_alen = ETH_ALEN;
+ os_memcpy(mreq.mr_address, addr, ETH_ALEN);
+
+ if (setsockopt(sock, SOL_PACKET,
+ add ? PACKET_ADD_MEMBERSHIP : PACKET_DROP_MEMBERSHIP,
+ &mreq, sizeof(mreq)) < 0) {
+ perror("setsockopt");
+ return -1;
+ }
+ return 0;
+#else /* __linux__ */
+ return -1;
+#endif /* __linux__ */
+}
+
+
+#ifdef __linux__
+static void handle_data(void *ctx, unsigned char *buf, size_t len)
+{
+#ifdef HOSTAPD
+ struct ieee8023_hdr *hdr;
+ u8 *pos, *sa;
+ size_t left;
+ union wpa_event_data event;
+
+ /* must contain at least ieee8023_hdr 6 byte source, 6 byte dest,
+ * 2 byte ethertype */
+ if (len < 14) {
+ wpa_printf(MSG_MSGDUMP, "handle_data: too short (%lu)",
+ (unsigned long) len);
+ return;
+ }
+
+ hdr = (struct ieee8023_hdr *) buf;
+
+ switch (ntohs(hdr->ethertype)) {
+ case ETH_P_PAE:
+ wpa_printf(MSG_MSGDUMP, "Received EAPOL packet");
+ sa = hdr->src;
+ os_memset(&event, 0, sizeof(event));
+ event.new_sta.addr = sa;
+ wpa_supplicant_event(ctx, EVENT_NEW_STA, &event);
+
+ pos = (u8 *) (hdr + 1);
+ left = len - sizeof(*hdr);
+ drv_event_eapol_rx(ctx, sa, pos, left);
+ break;
+
+ default:
+ wpa_printf(MSG_DEBUG, "Unknown ethertype 0x%04x in data frame",
+ ntohs(hdr->ethertype));
+ break;
+ }
+#endif /* HOSTAPD */
+}
+
+
+static void handle_read(int sock, void *eloop_ctx, void *sock_ctx)
+{
+ int len;
+ unsigned char buf[3000];
+
+ len = recv(sock, buf, sizeof(buf), 0);
+ if (len < 0) {
+ perror("recv");
+ return;
+ }
+
+ handle_data(eloop_ctx, buf, len);
+}
+
+
+static void handle_dhcp(int sock, void *eloop_ctx, void *sock_ctx)
+{
+ int len;
+ unsigned char buf[3000];
+ struct dhcp_message *msg;
+ u8 *mac_address;
+ union wpa_event_data event;
+
+ len = recv(sock, buf, sizeof(buf), 0);
+ if (len < 0) {
+ perror("recv");
+ return;
+ }
+
+ /* must contain at least dhcp_message->chaddr */
+ if (len < 44) {
+ wpa_printf(MSG_MSGDUMP, "handle_dhcp: too short (%d)", len);
+ return;
+ }
+
+ msg = (struct dhcp_message *) buf;
+ mac_address = (u8 *) &(msg->chaddr);
+
+ wpa_printf(MSG_MSGDUMP, "Got DHCP broadcast packet from " MACSTR,
+ MAC2STR(mac_address));
+
+ os_memset(&event, 0, sizeof(event));
+ event.new_sta.addr = mac_address;
+ wpa_supplicant_event(eloop_ctx, EVENT_NEW_STA, &event);
+}
+#endif /* __linux__ */
+
+
+static int wired_init_sockets(struct wpa_driver_wired_data *drv, u8 *own_addr)
+{
+#ifdef __linux__
+ struct ifreq ifr;
+ struct sockaddr_ll addr;
+ struct sockaddr_in addr2;
+ int n = 1;
+
+ drv->sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_PAE));
+ if (drv->sock < 0) {
+ perror("socket[PF_PACKET,SOCK_RAW]");
+ return -1;
+ }
+
+ if (eloop_register_read_sock(drv->sock, handle_read, drv->ctx, NULL)) {
+ printf("Could not register read socket\n");
+ return -1;
+ }
+
+ os_memset(&ifr, 0, sizeof(ifr));
+ os_strlcpy(ifr.ifr_name, drv->ifname, sizeof(ifr.ifr_name));
+ if (ioctl(drv->sock, SIOCGIFINDEX, &ifr) != 0) {
+ perror("ioctl(SIOCGIFINDEX)");
+ return -1;
+ }
+
+ os_memset(&addr, 0, sizeof(addr));
+ addr.sll_family = AF_PACKET;
+ addr.sll_ifindex = ifr.ifr_ifindex;
+ wpa_printf(MSG_DEBUG, "Opening raw packet socket for ifindex %d",
+ addr.sll_ifindex);
+
+ if (bind(drv->sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
+ perror("bind");
+ return -1;
+ }
+
+ /* filter multicast address */
+ if (wired_multicast_membership(drv->sock, ifr.ifr_ifindex,
+ pae_group_addr, 1) < 0) {
+ wpa_printf(MSG_ERROR, "wired: Failed to add multicast group "
+ "membership");
+ return -1;
+ }
+
+ os_memset(&ifr, 0, sizeof(ifr));
+ os_strlcpy(ifr.ifr_name, drv->ifname, sizeof(ifr.ifr_name));
+ if (ioctl(drv->sock, SIOCGIFHWADDR, &ifr) != 0) {
+ perror("ioctl(SIOCGIFHWADDR)");
+ return -1;
+ }
+
+ if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
+ printf("Invalid HW-addr family 0x%04x\n",
+ ifr.ifr_hwaddr.sa_family);
+ return -1;
+ }
+ os_memcpy(own_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
+
+ /* setup dhcp listen socket for sta detection */
+ if ((drv->dhcp_sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
+ perror("socket call failed for dhcp");
+ return -1;
+ }
+
+ if (eloop_register_read_sock(drv->dhcp_sock, handle_dhcp, drv->ctx,
+ NULL)) {
+ printf("Could not register read socket\n");
+ return -1;
+ }
+
+ os_memset(&addr2, 0, sizeof(addr2));
+ addr2.sin_family = AF_INET;
+ addr2.sin_port = htons(67);
+ addr2.sin_addr.s_addr = INADDR_ANY;
+
+ if (setsockopt(drv->dhcp_sock, SOL_SOCKET, SO_REUSEADDR, (char *) &n,
+ sizeof(n)) == -1) {
+ perror("setsockopt[SOL_SOCKET,SO_REUSEADDR]");
+ return -1;
+ }
+ if (setsockopt(drv->dhcp_sock, SOL_SOCKET, SO_BROADCAST, (char *) &n,
+ sizeof(n)) == -1) {
+ perror("setsockopt[SOL_SOCKET,SO_BROADCAST]");
+ return -1;
+ }
+
+ os_memset(&ifr, 0, sizeof(ifr));
+ os_strlcpy(ifr.ifr_ifrn.ifrn_name, drv->ifname, IFNAMSIZ);
+ if (setsockopt(drv->dhcp_sock, SOL_SOCKET, SO_BINDTODEVICE,
+ (char *) &ifr, sizeof(ifr)) < 0) {
+ perror("setsockopt[SOL_SOCKET,SO_BINDTODEVICE]");
+ return -1;
+ }
+
+ if (bind(drv->dhcp_sock, (struct sockaddr *) &addr2,
+ sizeof(struct sockaddr)) == -1) {
+ perror("bind");
+ return -1;
+ }
+
+ return 0;
+#else /* __linux__ */
+ return -1;
+#endif /* __linux__ */
+}
+
+
+static int wired_send_eapol(void *priv, const u8 *addr,
+ const u8 *data, size_t data_len, int encrypt,
+ const u8 *own_addr)
+{
+ struct wpa_driver_wired_data *drv = priv;
+ struct ieee8023_hdr *hdr;
+ size_t len;
+ u8 *pos;
+ int res;
+
+ len = sizeof(*hdr) + data_len;
+ hdr = os_zalloc(len);
+ if (hdr == NULL) {
+ printf("malloc() failed for wired_send_eapol(len=%lu)\n",
+ (unsigned long) len);
+ return -1;
+ }
+
+ os_memcpy(hdr->dest, drv->use_pae_group_addr ? pae_group_addr : addr,
+ ETH_ALEN);
+ os_memcpy(hdr->src, own_addr, ETH_ALEN);
+ hdr->ethertype = htons(ETH_P_PAE);
+
+ pos = (u8 *) (hdr + 1);
+ os_memcpy(pos, data, data_len);
+
+ res = send(drv->sock, (u8 *) hdr, len, 0);
+ os_free(hdr);
+
+ if (res < 0) {
+ perror("wired_send_eapol: send");
+ printf("wired_send_eapol - packet len: %lu - failed\n",
+ (unsigned long) len);
+ }
+
+ return res;
+}
+
+
+static void * wired_driver_hapd_init(struct hostapd_data *hapd,
+ struct wpa_init_params *params)
+{
+ struct wpa_driver_wired_data *drv;
+
+ drv = os_zalloc(sizeof(struct wpa_driver_wired_data));
+ if (drv == NULL) {
+ printf("Could not allocate memory for wired driver data\n");
+ return NULL;
+ }
+
+ drv->ctx = hapd;
+ os_strlcpy(drv->ifname, params->ifname, sizeof(drv->ifname));
+ drv->use_pae_group_addr = params->use_pae_group_addr;
+
+ if (wired_init_sockets(drv, params->own_addr)) {
+ os_free(drv);
+ return NULL;
+ }
+
+ return drv;
+}
+
+
+static void wired_driver_hapd_deinit(void *priv)
+{
+ struct wpa_driver_wired_data *drv = priv;
+
+ if (drv->sock >= 0)
+ close(drv->sock);
+
+ if (drv->dhcp_sock >= 0)
+ close(drv->dhcp_sock);
+
+ os_free(drv);
+}
+
+
static int wpa_driver_wired_get_ssid(void *priv, u8 *ssid)
{
ssid[0] = 0;
@@ -53,6 +401,14 @@ static int wpa_driver_wired_get_bssid(void *priv, u8 *bssid)
}
+static int wpa_driver_wired_get_capa(void *priv, struct wpa_driver_capa *capa)
+{
+ os_memset(capa, 0, sizeof(*capa));
+ capa->flags = WPA_DRIVER_FLAGS_WIRED;
+ return 0;
+}
+
+
static int wpa_driver_wired_get_ifflags(const char *ifname, int *flags)
{
struct ifreq ifr;
@@ -118,7 +474,7 @@ static int wpa_driver_wired_multi(const char *ifname, const u8 *addr, int add)
ifr.ifr_hwaddr.sa_family = AF_UNSPEC;
os_memcpy(ifr.ifr_hwaddr.sa_data, addr, ETH_ALEN);
#endif /* __linux__ */
-#if defined(__FreeBSD__) || defined(__DragonFly__)
+#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
{
struct sockaddr_dl *dlp;
dlp = (struct sockaddr_dl *) &ifr.ifr_addr;
@@ -128,9 +484,9 @@ static int wpa_driver_wired_multi(const char *ifname, const u8 *addr, int add)
dlp->sdl_nlen = 0;
dlp->sdl_alen = ETH_ALEN;
dlp->sdl_slen = 0;
- os_memcpy(LLADDR(dlp), addr, ETH_ALEN);
+ os_memcpy(LLADDR(dlp), addr, ETH_ALEN);
}
-#endif /* defined(__FreeBSD__) || defined(__DragonFly__) */
+#endif /* defined(__FreeBSD__) || defined(__DragonFly__) || defined(FreeBSD_kernel__) */
#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
{
struct sockaddr *sap;
@@ -151,34 +507,6 @@ static int wpa_driver_wired_multi(const char *ifname, const u8 *addr, int add)
}
-static int wpa_driver_wired_membership(struct wpa_driver_wired_data *drv,
- const u8 *addr, int add)
-{
-#ifdef __linux__
- struct packet_mreq mreq;
-
- if (drv->pf_sock == -1)
- return -1;
-
- os_memset(&mreq, 0, sizeof(mreq));
- mreq.mr_ifindex = if_nametoindex(drv->ifname);
- mreq.mr_type = PACKET_MR_MULTICAST;
- mreq.mr_alen = ETH_ALEN;
- os_memcpy(mreq.mr_address, addr, ETH_ALEN);
-
- if (setsockopt(drv->pf_sock, SOL_PACKET,
- add ? PACKET_ADD_MEMBERSHIP : PACKET_DROP_MEMBERSHIP,
- &mreq, sizeof(mreq)) < 0) {
- perror("setsockopt");
- return -1;
- }
- return 0;
-#else /* __linux__ */
- return -1;
-#endif /* __linux__ */
-}
-
-
static void * wpa_driver_wired_init(void *ctx, const char *ifname)
{
struct wpa_driver_wired_data *drv;
@@ -195,16 +523,18 @@ static void * wpa_driver_wired_init(void *ctx, const char *ifname)
if (drv->pf_sock < 0)
perror("socket(PF_PACKET)");
#else /* __linux__ */
- drv->pf_sock = -1;
+ drv->pf_sock = -1;
#endif /* __linux__ */
-
+
if (wpa_driver_wired_get_ifflags(ifname, &flags) == 0 &&
!(flags & IFF_UP) &&
wpa_driver_wired_set_ifflags(ifname, flags | IFF_UP) == 0) {
drv->iff_up = 1;
}
- if (wpa_driver_wired_membership(drv, pae_group_addr, 1) == 0) {
+ if (wired_multicast_membership(drv->pf_sock,
+ if_nametoindex(drv->ifname),
+ pae_group_addr, 1) == 0) {
wpa_printf(MSG_DEBUG, "%s: Added multicast membership with "
"packet socket", __func__);
drv->membership = 1;
@@ -242,7 +572,9 @@ static void wpa_driver_wired_deinit(void *priv)
int flags;
if (drv->membership &&
- wpa_driver_wired_membership(drv, pae_group_addr, 0) < 0) {
+ wired_multicast_membership(drv->pf_sock,
+ if_nametoindex(drv->ifname),
+ pae_group_addr, 0) < 0) {
wpa_printf(MSG_DEBUG, "%s: Failed to remove PAE multicast "
"group (PACKET)", __func__);
}
@@ -271,16 +603,20 @@ static void wpa_driver_wired_deinit(void *priv)
if (drv->pf_sock != -1)
close(drv->pf_sock);
-
+
os_free(drv);
}
const struct wpa_driver_ops wpa_driver_wired_ops = {
.name = "wired",
- .desc = "wpa_supplicant wired Ethernet driver",
+ .desc = "Wired Ethernet driver",
+ .hapd_init = wired_driver_hapd_init,
+ .hapd_deinit = wired_driver_hapd_deinit,
+ .hapd_send_eapol = wired_send_eapol,
.get_ssid = wpa_driver_wired_get_ssid,
.get_bssid = wpa_driver_wired_get_bssid,
+ .get_capa = wpa_driver_wired_get_capa,
.init = wpa_driver_wired_init,
.deinit = wpa_driver_wired_deinit,
};
diff --git a/contrib/wpa/src/drivers/drivers.c b/contrib/wpa/src/drivers/drivers.c
index d278797..bffbbde 100644
--- a/contrib/wpa/src/drivers/drivers.c
+++ b/contrib/wpa/src/drivers/drivers.c
@@ -1,5 +1,5 @@
/*
- * WPA Supplicant / driver interface list
+ * Driver interface list
* Copyright (c) 2004-2005, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
@@ -24,9 +24,6 @@ extern struct wpa_driver_ops wpa_driver_nl80211_ops; /* driver_nl80211.c */
#ifdef CONFIG_DRIVER_HOSTAP
extern struct wpa_driver_ops wpa_driver_hostap_ops; /* driver_hostap.c */
#endif /* CONFIG_DRIVER_HOSTAP */
-#ifdef CONFIG_DRIVER_PRISM54
-extern struct wpa_driver_ops wpa_driver_prism54_ops; /* driver_prism54.c */
-#endif /* CONFIG_DRIVER_PRISM54 */
#ifdef CONFIG_DRIVER_HERMES
extern struct wpa_driver_ops wpa_driver_hermes_ops; /* driver_hermes.c */
#endif /* CONFIG_DRIVER_HERMES */
@@ -64,9 +61,6 @@ extern struct wpa_driver_ops wpa_driver_ralink_ops; /* driver_ralink.c */
#ifdef CONFIG_DRIVER_OSX
extern struct wpa_driver_ops wpa_driver_osx_ops; /* driver_osx.m */
#endif /* CONFIG_DRIVER_OSX */
-#ifdef CONFIG_DRIVER_PS3
-extern struct wpa_driver_ops wpa_driver_ps3_ops; /* driver_ps3.c */
-#endif /* CONFIG_DRIVER_PS3 */
#ifdef CONFIG_DRIVER_IPHONE
extern struct wpa_driver_ops wpa_driver_iphone_ops; /* driver_iphone.m */
#endif /* CONFIG_DRIVER_IPHONE */
@@ -74,9 +68,15 @@ extern struct wpa_driver_ops wpa_driver_iphone_ops; /* driver_iphone.m */
/* driver_roboswitch.c */
extern struct wpa_driver_ops wpa_driver_roboswitch_ops;
#endif /* CONFIG_DRIVER_ROBOSWITCH */
+#ifdef CONFIG_DRIVER_ATHEROS
+extern struct wpa_driver_ops wpa_driver_atheros_ops; /* driver_atheros.c */
+#endif /* CONFIG_DRIVER_ATHEROS */
+#ifdef CONFIG_DRIVER_NONE
+extern struct wpa_driver_ops wpa_driver_none_ops; /* driver_none.c */
+#endif /* CONFIG_DRIVER_NONE */
-struct wpa_driver_ops *wpa_supplicant_drivers[] =
+struct wpa_driver_ops *wpa_drivers[] =
{
#ifdef CONFIG_DRIVER_WEXT
&wpa_driver_wext_ops,
@@ -87,9 +87,6 @@ struct wpa_driver_ops *wpa_supplicant_drivers[] =
#ifdef CONFIG_DRIVER_HOSTAP
&wpa_driver_hostap_ops,
#endif /* CONFIG_DRIVER_HOSTAP */
-#ifdef CONFIG_DRIVER_PRISM54
- &wpa_driver_prism54_ops,
-#endif /* CONFIG_DRIVER_PRISM54 */
#ifdef CONFIG_DRIVER_HERMES
&wpa_driver_hermes_ops,
#endif /* CONFIG_DRIVER_HERMES */
@@ -126,14 +123,17 @@ struct wpa_driver_ops *wpa_supplicant_drivers[] =
#ifdef CONFIG_DRIVER_OSX
&wpa_driver_osx_ops,
#endif /* CONFIG_DRIVER_OSX */
-#ifdef CONFIG_DRIVER_PS3
- &wpa_driver_ps3_ops,
-#endif /* CONFIG_DRIVER_PS3 */
#ifdef CONFIG_DRIVER_IPHONE
&wpa_driver_iphone_ops,
#endif /* CONFIG_DRIVER_IPHONE */
#ifdef CONFIG_DRIVER_ROBOSWITCH
&wpa_driver_roboswitch_ops,
#endif /* CONFIG_DRIVER_ROBOSWITCH */
+#ifdef CONFIG_DRIVER_ATHEROS
+ &wpa_driver_atheros_ops,
+#endif /* CONFIG_DRIVER_ATHEROS */
+#ifdef CONFIG_DRIVER_NONE
+ &wpa_driver_none_ops,
+#endif /* CONFIG_DRIVER_NONE */
NULL
};
diff --git a/contrib/wpa/src/drivers/drivers.mak b/contrib/wpa/src/drivers/drivers.mak
new file mode 100644
index 0000000..b76b229
--- /dev/null
+++ b/contrib/wpa/src/drivers/drivers.mak
@@ -0,0 +1,181 @@
+##### COMMON DRIVERS
+
+ifdef CONFIG_DRIVER_HOSTAP
+DRV_CFLAGS += -DCONFIG_DRIVER_HOSTAP
+DRV_OBJS += ../src/drivers/driver_hostap.o
+CONFIG_WIRELESS_EXTENSION=y
+NEED_AP_MLME=y
+NEED_NETLINK=y
+NEED_LINUX_IOCTL=y
+endif
+
+ifdef CONFIG_DRIVER_WIRED
+DRV_CFLAGS += -DCONFIG_DRIVER_WIRED
+DRV_OBJS += ../src/drivers/driver_wired.o
+endif
+
+ifdef CONFIG_DRIVER_MADWIFI
+DRV_CFLAGS += -DCONFIG_DRIVER_MADWIFI
+DRV_OBJS += ../src/drivers/driver_madwifi.o
+CONFIG_WIRELESS_EXTENSION=y
+CONFIG_L2_PACKET=linux
+NEED_NETLINK=y
+NEED_LINUX_IOCTL=y
+endif
+
+ifdef CONFIG_DRIVER_NL80211
+DRV_CFLAGS += -DCONFIG_DRIVER_NL80211
+DRV_OBJS += ../src/drivers/driver_nl80211.o
+DRV_OBJS += ../src/utils/radiotap.o
+NEED_SME=y
+NEED_AP_MLME=y
+NEED_NETLINK=y
+NEED_LINUX_IOCTL=y
+DRV_LIBS += -lnl
+
+ifdef CONFIG_LIBNL20
+DRV_LIBS += -lnl-genl
+DRV_CFLAGS += -DCONFIG_LIBNL20
+endif
+endif
+
+ifdef CONFIG_DRIVER_BSD
+ifndef CONFIG_L2_PACKET
+CONFIG_L2_PACKET=freebsd
+endif
+DRV_CFLAGS += -DCONFIG_DRIVER_BSD
+DRV_OBJS += ../src/drivers/driver_bsd.o
+CONFIG_L2_FREEBSD=y
+CONFIG_DNET_PCAP=y
+endif
+
+ifdef CONFIG_DRIVER_TEST
+DRV_CFLAGS += -DCONFIG_DRIVER_TEST
+DRV_OBJS += ../src/drivers/driver_test.o
+NEED_AP_MLME=y
+endif
+
+ifdef CONFIG_DRIVER_NONE
+DRV_CFLAGS += -DCONFIG_DRIVER_NONE
+DRV_OBJS += ../src/drivers/driver_none.o
+endif
+
+##### PURE AP DRIVERS
+
+ifdef CONFIG_DRIVER_ATHEROS
+DRV_AP_CFLAGS += -DCONFIG_DRIVER_ATHEROS
+DRV_AP_OBJS += ../src/drivers/driver_atheros.o
+CONFIG_L2_PACKET=linux
+NEED_NETLINK=y
+NEED_LINUX_IOCTL=y
+endif
+
+##### PURE CLIENT DRIVERS
+
+ifdef CONFIG_DRIVER_WEXT
+DRV_WPA_CFLAGS += -DCONFIG_DRIVER_WEXT
+CONFIG_WIRELESS_EXTENSION=y
+NEED_NETLINK=y
+NEED_LINUX_IOCTL=y
+endif
+
+ifdef CONFIG_DRIVER_HERMES
+DRV_WPA_CFLAGS += -DCONFIG_DRIVER_HERMES
+DRV_WPA_OBJS += ../src/drivers/driver_hermes.o
+CONFIG_WIRELESS_EXTENSION=y
+endif
+
+ifdef CONFIG_DRIVER_ATMEL
+DRV_WPA_CFLAGS += -DCONFIG_DRIVER_ATMEL
+DRV_WPA_OBJS += ../src/drivers/driver_atmel.o
+CONFIG_WIRELESS_EXTENSION=y
+endif
+
+ifdef CONFIG_DRIVER_NDISWRAPPER
+DRV_WPA_CFLAGS += -DCONFIG_DRIVER_NDISWRAPPER
+DRV_WPA_OBJS += ../src/drivers/driver_ndiswrapper.o
+CONFIG_WIRELESS_EXTENSION=y
+endif
+
+ifdef CONFIG_DRIVER_RALINK
+DRV_WPA_CFLAGS += -DCONFIG_DRIVER_RALINK
+DRV_WPA_OBJS += ../src/drivers/driver_ralink.o
+NEED_NETLINK=y
+NEED_LINUX_IOCTL=y
+endif
+
+ifdef CONFIG_DRIVER_BROADCOM
+DRV_WPA_CFLAGS += -DCONFIG_DRIVER_BROADCOM
+DRV_WPA_OBJS += ../src/drivers/driver_broadcom.o
+endif
+
+ifdef CONFIG_DRIVER_IPW
+DRV_WPA_CFLAGS += -DCONFIG_DRIVER_IPW
+DRV_WPA_OBJS += ../src/drivers/driver_ipw.o
+CONFIG_WIRELESS_EXTENSION=y
+endif
+
+ifdef CONFIG_DRIVER_NDIS
+DRV_WPA_CFLAGS += -DCONFIG_DRIVER_NDIS
+DRV_WPA_OBJS += ../src/drivers/driver_ndis.o
+ifdef CONFIG_NDIS_EVENTS_INTEGRATED
+DRV_WPA_OBJS += ../src/drivers/driver_ndis_.o
+endif
+ifndef CONFIG_L2_PACKET
+CONFIG_L2_PACKET=pcap
+endif
+CONFIG_WINPCAP=y
+ifdef CONFIG_USE_NDISUIO
+DRV_WPA_CFLAGS += -DCONFIG_USE_NDISUIO
+endif
+endif
+
+ifdef CONFIG_DRIVER_OSX
+DRV_WPA_CFLAGS += -DCONFIG_DRIVER_OSX
+DRV_WPA_OBJS += ../src/drivers/driver_osx.o
+DRV_WPA_LDFLAGS += -framework CoreFoundation
+DRV_WPA_LDFLAGS += -F/System/Library/PrivateFrameworks -framework Apple80211
+endif
+
+ifdef CONFIG_DRIVER_IPHONE
+DRV_WPA_CFLAGS += -DCONFIG_DRIVER_IPHONE
+DRV_WPA_OBJS += ../src/drivers/driver_iphone.o
+DRV_WPA_OBJS += ../src/drivers/MobileApple80211.o
+DRV_WPA_LDFLAGS += -framework CoreFoundation
+endif
+
+ifdef CONFIG_DRIVER_ROBOSWITCH
+DRV_WPA_CFLAGS += -DCONFIG_DRIVER_ROBOSWITCH
+DRV_WPA_OBJS += ../src/drivers/driver_roboswitch.o
+endif
+
+ifdef CONFIG_WIRELESS_EXTENSION
+DRV_WPA_CFLAGS += -DCONFIG_WIRELESS_EXTENSION
+DRV_WPA_OBJS += ../src/drivers/driver_wext.o
+endif
+
+ifdef NEED_NETLINK
+DRV_OBJS += ../src/drivers/netlink.o
+endif
+
+ifdef NEED_LINUX_IOCTL
+DRV_OBJS += ../src/drivers/linux_ioctl.o
+endif
+
+
+##### COMMON VARS
+DRV_BOTH_CFLAGS := $(DRV_CFLAGS) $(DRV_WPA_CFLAGS) $(DRV_AP_CFLAGS)
+DRV_WPA_CFLAGS += $(DRV_CFLAGS)
+DRV_AP_CFLAGS += $(DRV_CFLAGS)
+
+DRV_BOTH_LIBS := $(DRV_LIBS) $(DRV_WPA_LIBS) $(DRV_AP_LIBS)
+DRV_WPA_LIBS += $(DRV_LIBS)
+DRV_AP_LIBS += $(DRV_LIBS)
+
+DRV_BOTH_OBJS := $(DRV_OBJS) $(DRV_WPA_OBJS) $(DRV_AP_OBJS)
+DRV_WPA_OBJS += $(DRV_OBJS)
+DRV_AP_OBJS += $(DRV_OBJS)
+
+DRV_BOTH_LDFLAGS := $(DRV_LDFLAGS) $(DRV_WPA_LDFLAGS) $(DRV_AP_LDFLAGS)
+DRV_WPA_LDFLAGS += $(DRV_LDFLAGS)
+DRV_AP_LDFLAGS += $(DRV_LDFLAGS)
diff --git a/contrib/wpa/src/drivers/linux_ioctl.c b/contrib/wpa/src/drivers/linux_ioctl.c
new file mode 100644
index 0000000..0d6cf54
--- /dev/null
+++ b/contrib/wpa/src/drivers/linux_ioctl.c
@@ -0,0 +1,198 @@
+/*
+ * Linux ioctl helper functions for driver wrappers
+ * Copyright (c) 2002-2010, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "utils/includes.h"
+#include <sys/ioctl.h>
+#include <net/if.h>
+#include <net/if_arp.h>
+
+#include "utils/common.h"
+#include "linux_ioctl.h"
+
+
+int linux_set_iface_flags(int sock, const char *ifname, int dev_up)
+{
+ struct ifreq ifr;
+
+ if (sock < 0)
+ return -1;
+
+ os_memset(&ifr, 0, sizeof(ifr));
+ os_strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
+
+ if (ioctl(sock, SIOCGIFFLAGS, &ifr) != 0) {
+ wpa_printf(MSG_ERROR, "Could not read interface %s flags: %s",
+ ifname, strerror(errno));
+ return -1;
+ }
+
+ if (dev_up) {
+ if (ifr.ifr_flags & IFF_UP)
+ return 0;
+ ifr.ifr_flags |= IFF_UP;
+ } else {
+ if (!(ifr.ifr_flags & IFF_UP))
+ return 0;
+ ifr.ifr_flags &= ~IFF_UP;
+ }
+
+ if (ioctl(sock, SIOCSIFFLAGS, &ifr) != 0) {
+ wpa_printf(MSG_ERROR, "Could not set interface %s flags: %s",
+ ifname, strerror(errno));
+ return -1;
+ }
+
+ return 0;
+}
+
+
+int linux_get_ifhwaddr(int sock, const char *ifname, u8 *addr)
+{
+ struct ifreq ifr;
+
+ os_memset(&ifr, 0, sizeof(ifr));
+ os_strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
+ if (ioctl(sock, SIOCGIFHWADDR, &ifr)) {
+ wpa_printf(MSG_ERROR, "Could not get interface %s hwaddr: %s",
+ ifname, strerror(errno));
+ return -1;
+ }
+
+ if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
+ wpa_printf(MSG_ERROR, "%s: Invalid HW-addr family 0x%04x",
+ ifname, ifr.ifr_hwaddr.sa_family);
+ return -1;
+ }
+ os_memcpy(addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
+
+ return 0;
+}
+
+
+int linux_set_ifhwaddr(int sock, const char *ifname, const u8 *addr)
+{
+ struct ifreq ifr;
+
+ os_memset(&ifr, 0, sizeof(ifr));
+ os_strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
+ os_memcpy(ifr.ifr_hwaddr.sa_data, addr, ETH_ALEN);
+ ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
+
+ if (ioctl(sock, SIOCSIFHWADDR, &ifr)) {
+ wpa_printf(MSG_DEBUG, "Could not set interface %s hwaddr: %s",
+ ifname, strerror(errno));
+ return -1;
+ }
+
+ return 0;
+}
+
+
+#ifndef SIOCBRADDBR
+#define SIOCBRADDBR 0x89a0
+#endif
+#ifndef SIOCBRDELBR
+#define SIOCBRDELBR 0x89a1
+#endif
+#ifndef SIOCBRADDIF
+#define SIOCBRADDIF 0x89a2
+#endif
+#ifndef SIOCBRDELIF
+#define SIOCBRDELIF 0x89a3
+#endif
+
+
+int linux_br_add(int sock, const char *brname)
+{
+ if (ioctl(sock, SIOCBRADDBR, brname) < 0) {
+ wpa_printf(MSG_DEBUG, "Could not add bridge %s: %s",
+ brname, strerror(errno));
+ return -1;
+ }
+
+ return 0;
+}
+
+
+int linux_br_del(int sock, const char *brname)
+{
+ if (ioctl(sock, SIOCBRDELBR, brname) < 0) {
+ wpa_printf(MSG_DEBUG, "Could not remove bridge %s: %s",
+ brname, strerror(errno));
+ return -1;
+ }
+
+ return 0;
+}
+
+
+int linux_br_add_if(int sock, const char *brname, const char *ifname)
+{
+ struct ifreq ifr;
+ int ifindex;
+
+ ifindex = if_nametoindex(ifname);
+ if (ifindex == 0)
+ return -1;
+
+ os_memset(&ifr, 0, sizeof(ifr));
+ os_strlcpy(ifr.ifr_name, brname, IFNAMSIZ);
+ ifr.ifr_ifindex = ifindex;
+ if (ioctl(sock, SIOCBRADDIF, &ifr) < 0) {
+ wpa_printf(MSG_DEBUG, "Could not add interface %s into bridge "
+ "%s: %s", ifname, brname, strerror(errno));
+ return -1;
+ }
+
+ return 0;
+}
+
+
+int linux_br_del_if(int sock, const char *brname, const char *ifname)
+{
+ struct ifreq ifr;
+ int ifindex;
+
+ ifindex = if_nametoindex(ifname);
+ if (ifindex == 0)
+ return -1;
+
+ os_memset(&ifr, 0, sizeof(ifr));
+ os_strlcpy(ifr.ifr_name, brname, IFNAMSIZ);
+ ifr.ifr_ifindex = ifindex;
+ if (ioctl(sock, SIOCBRDELIF, &ifr) < 0) {
+ wpa_printf(MSG_DEBUG, "Could not remove interface %s from "
+ "bridge %s: %s", ifname, brname, strerror(errno));
+ return -1;
+ }
+
+ return 0;
+}
+
+
+int linux_br_get(char *brname, const char *ifname)
+{
+ char path[128], brlink[128], *pos;
+ os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/bridge",
+ ifname);
+ os_memset(brlink, 0, sizeof(brlink));
+ if (readlink(path, brlink, sizeof(brlink) - 1) < 0)
+ return -1;
+ pos = os_strrchr(brlink, '/');
+ if (pos == NULL)
+ return -1;
+ pos++;
+ os_strlcpy(brname, pos, IFNAMSIZ);
+ return 0;
+}
diff --git a/contrib/wpa/src/drivers/linux_ioctl.h b/contrib/wpa/src/drivers/linux_ioctl.h
new file mode 100644
index 0000000..a555738
--- /dev/null
+++ b/contrib/wpa/src/drivers/linux_ioctl.h
@@ -0,0 +1,27 @@
+/*
+ * Linux ioctl helper functions for driver wrappers
+ * Copyright (c) 2002-2010, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef LINUX_IOCTL_H
+#define LINUX_IOCTL_H
+
+int linux_set_iface_flags(int sock, const char *ifname, int dev_up);
+int linux_get_ifhwaddr(int sock, const char *ifname, u8 *addr);
+int linux_set_ifhwaddr(int sock, const char *ifname, const u8 *addr);
+int linux_br_add(int sock, const char *brname);
+int linux_br_del(int sock, const char *brname);
+int linux_br_add_if(int sock, const char *brname, const char *ifname);
+int linux_br_del_if(int sock, const char *brname, const char *ifname);
+int linux_br_get(char *brname, const char *ifname);
+
+#endif /* LINUX_IOCTL_H */
diff --git a/contrib/wpa/src/drivers/netlink.c b/contrib/wpa/src/drivers/netlink.c
new file mode 100644
index 0000000..ad15b1d
--- /dev/null
+++ b/contrib/wpa/src/drivers/netlink.c
@@ -0,0 +1,204 @@
+/*
+ * Netlink helper functions for driver wrappers
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "eloop.h"
+#include "priv_netlink.h"
+#include "netlink.h"
+
+
+struct netlink_data {
+ struct netlink_config *cfg;
+ int sock;
+};
+
+
+static void netlink_receive_link(struct netlink_data *netlink,
+ void (*cb)(void *ctx, struct ifinfomsg *ifi,
+ u8 *buf, size_t len),
+ struct nlmsghdr *h)
+{
+ if (cb == NULL || NLMSG_PAYLOAD(h, 0) < sizeof(struct ifinfomsg))
+ return;
+ cb(netlink->cfg->ctx, NLMSG_DATA(h),
+ NLMSG_DATA(h) + NLMSG_ALIGN(sizeof(struct ifinfomsg)),
+ NLMSG_PAYLOAD(h, sizeof(struct ifinfomsg)));
+}
+
+
+static void netlink_receive(int sock, void *eloop_ctx, void *sock_ctx)
+{
+ struct netlink_data *netlink = eloop_ctx;
+ char buf[8192];
+ int left;
+ struct sockaddr_nl from;
+ socklen_t fromlen;
+ struct nlmsghdr *h;
+ int max_events = 10;
+
+try_again:
+ fromlen = sizeof(from);
+ left = recvfrom(sock, buf, sizeof(buf), MSG_DONTWAIT,
+ (struct sockaddr *) &from, &fromlen);
+ if (left < 0) {
+ if (errno != EINTR && errno != EAGAIN)
+ wpa_printf(MSG_INFO, "netlink: recvfrom failed: %s",
+ strerror(errno));
+ return;
+ }
+
+ h = (struct nlmsghdr *) buf;
+ while (NLMSG_OK(h, left)) {
+ switch (h->nlmsg_type) {
+ case RTM_NEWLINK:
+ netlink_receive_link(netlink, netlink->cfg->newlink_cb,
+ h);
+ break;
+ case RTM_DELLINK:
+ netlink_receive_link(netlink, netlink->cfg->dellink_cb,
+ h);
+ break;
+ }
+
+ h = NLMSG_NEXT(h, left);
+ }
+
+ if (left > 0) {
+ wpa_printf(MSG_DEBUG, "netlink: %d extra bytes in the end of "
+ "netlink message", left);
+ }
+
+ if (--max_events > 0) {
+ /*
+ * Try to receive all events in one eloop call in order to
+ * limit race condition on cases where AssocInfo event, Assoc
+ * event, and EAPOL frames are received more or less at the
+ * same time. We want to process the event messages first
+ * before starting EAPOL processing.
+ */
+ goto try_again;
+ }
+}
+
+
+struct netlink_data * netlink_init(struct netlink_config *cfg)
+{
+ struct netlink_data *netlink;
+ struct sockaddr_nl local;
+
+ netlink = os_zalloc(sizeof(*netlink));
+ if (netlink == NULL)
+ return NULL;
+
+ netlink->cfg = cfg;
+
+ netlink->sock = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
+ if (netlink->sock < 0) {
+ wpa_printf(MSG_ERROR, "netlink: Failed to open netlink "
+ "socket: %s", strerror(errno));
+ netlink_deinit(netlink);
+ return NULL;
+ }
+
+ os_memset(&local, 0, sizeof(local));
+ local.nl_family = AF_NETLINK;
+ local.nl_groups = RTMGRP_LINK;
+ if (bind(netlink->sock, (struct sockaddr *) &local, sizeof(local)) < 0)
+ {
+ wpa_printf(MSG_ERROR, "netlink: Failed to bind netlink "
+ "socket: %s", strerror(errno));
+ netlink_deinit(netlink);
+ return NULL;
+ }
+
+ eloop_register_read_sock(netlink->sock, netlink_receive, netlink,
+ NULL);
+
+ return netlink;
+}
+
+
+void netlink_deinit(struct netlink_data *netlink)
+{
+ if (netlink == NULL)
+ return;
+ if (netlink->sock >= 0) {
+ eloop_unregister_read_sock(netlink->sock);
+ close(netlink->sock);
+ }
+ os_free(netlink->cfg);
+ os_free(netlink);
+}
+
+int netlink_send_oper_ifla(struct netlink_data *netlink, int ifindex,
+ int linkmode, int operstate)
+{
+ struct {
+ struct nlmsghdr hdr;
+ struct ifinfomsg ifinfo;
+ char opts[16];
+ } req;
+ struct rtattr *rta;
+ static int nl_seq;
+ ssize_t ret;
+
+ os_memset(&req, 0, sizeof(req));
+
+ req.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
+ req.hdr.nlmsg_type = RTM_SETLINK;
+ req.hdr.nlmsg_flags = NLM_F_REQUEST;
+ req.hdr.nlmsg_seq = ++nl_seq;
+ req.hdr.nlmsg_pid = 0;
+
+ req.ifinfo.ifi_family = AF_UNSPEC;
+ req.ifinfo.ifi_type = 0;
+ req.ifinfo.ifi_index = ifindex;
+ req.ifinfo.ifi_flags = 0;
+ req.ifinfo.ifi_change = 0;
+
+ if (linkmode != -1) {
+ rta = aliasing_hide_typecast(
+ ((char *) &req + NLMSG_ALIGN(req.hdr.nlmsg_len)),
+ struct rtattr);
+ rta->rta_type = IFLA_LINKMODE;
+ rta->rta_len = RTA_LENGTH(sizeof(char));
+ *((char *) RTA_DATA(rta)) = linkmode;
+ req.hdr.nlmsg_len = NLMSG_ALIGN(req.hdr.nlmsg_len) +
+ RTA_LENGTH(sizeof(char));
+ }
+ if (operstate != -1) {
+ rta = aliasing_hide_typecast(
+ ((char *) &req + NLMSG_ALIGN(req.hdr.nlmsg_len)),
+ struct rtattr);
+ rta->rta_type = IFLA_OPERSTATE;
+ rta->rta_len = RTA_LENGTH(sizeof(char));
+ *((char *) RTA_DATA(rta)) = operstate;
+ req.hdr.nlmsg_len = NLMSG_ALIGN(req.hdr.nlmsg_len) +
+ RTA_LENGTH(sizeof(char));
+ }
+
+ wpa_printf(MSG_DEBUG, "netlink: Operstate: linkmode=%d, operstate=%d",
+ linkmode, operstate);
+
+ ret = send(netlink->sock, &req, req.hdr.nlmsg_len, 0);
+ if (ret < 0) {
+ wpa_printf(MSG_DEBUG, "netlink: Sending operstate IFLA "
+ "failed: %s (assume operstate is not supported)",
+ strerror(errno));
+ }
+
+ return ret < 0 ? -1 : 0;
+}
diff --git a/contrib/wpa/src/drivers/netlink.h b/contrib/wpa/src/drivers/netlink.h
new file mode 100644
index 0000000..bcbfbb5
--- /dev/null
+++ b/contrib/wpa/src/drivers/netlink.h
@@ -0,0 +1,33 @@
+/*
+ * Netlink helper functions for driver wrappers
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef NETLINK_H
+#define NETLINK_H
+
+struct netlink_data;
+
+struct netlink_config {
+ void *ctx;
+ void (*newlink_cb)(void *ctx, struct ifinfomsg *ifi, u8 *buf,
+ size_t len);
+ void (*dellink_cb)(void *ctx, struct ifinfomsg *ifi, u8 *buf,
+ size_t len);
+};
+
+struct netlink_data * netlink_init(struct netlink_config *cfg);
+void netlink_deinit(struct netlink_data *netlink);
+int netlink_send_oper_ifla(struct netlink_data *netlink, int ifindex,
+ int linkmode, int operstate);
+
+#endif /* NETLINK_H */
diff --git a/contrib/wpa/src/common/nl80211_copy.h b/contrib/wpa/src/drivers/nl80211_copy.h
index 45db17f..2ea3ede 100644
--- a/contrib/wpa/src/common/nl80211_copy.h
+++ b/contrib/wpa/src/drivers/nl80211_copy.h
@@ -3,7 +3,7 @@
/*
* 802.11 netlink interface public header
*
- * Copyright 2006, 2007, 2008 Johannes Berg <johannes@sipsolutions.net>
+ * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
* Copyright 2008 Michael Wu <flamingice@sourmilk.net>
* Copyright 2008 Luis Carlos Cobo <luisca@cozybit.com>
* Copyright 2008 Michael Buesch <mb@bu3sch.de>
@@ -270,6 +270,66 @@
* @NL80211_CMD_SET_WIPHY_NETNS: Set a wiphy's netns. Note that all devices
* associated with this wiphy must be down and will follow.
*
+ * @NL80211_CMD_REMAIN_ON_CHANNEL: Request to remain awake on the specified
+ * channel for the specified amount of time. This can be used to do
+ * off-channel operations like transmit a Public Action frame and wait for
+ * a response while being associated to an AP on another channel.
+ * %NL80211_ATTR_WIPHY or %NL80211_ATTR_IFINDEX is used to specify which
+ * radio is used. %NL80211_ATTR_WIPHY_FREQ is used to specify the
+ * frequency for the operation and %NL80211_ATTR_WIPHY_CHANNEL_TYPE may be
+ * optionally used to specify additional channel parameters.
+ * %NL80211_ATTR_DURATION is used to specify the duration in milliseconds
+ * to remain on the channel. This command is also used as an event to
+ * notify when the requested duration starts (it may take a while for the
+ * driver to schedule this time due to other concurrent needs for the
+ * radio).
+ * When called, this operation returns a cookie (%NL80211_ATTR_COOKIE)
+ * that will be included with any events pertaining to this request;
+ * the cookie is also used to cancel the request.
+ * @NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL: This command can be used to cancel a
+ * pending remain-on-channel duration if the desired operation has been
+ * completed prior to expiration of the originally requested duration.
+ * %NL80211_ATTR_WIPHY or %NL80211_ATTR_IFINDEX is used to specify the
+ * radio. The %NL80211_ATTR_COOKIE attribute must be given as well to
+ * uniquely identify the request.
+ * This command is also used as an event to notify when a requested
+ * remain-on-channel duration has expired.
+ *
+ * @NL80211_CMD_SET_TX_BITRATE_MASK: Set the mask of rates to be used in TX
+ * rate selection. %NL80211_ATTR_IFINDEX is used to specify the interface
+ * and @NL80211_ATTR_TX_RATES the set of allowed rates.
+ *
+ * @NL80211_CMD_REGISTER_ACTION: Register for receiving certain action frames
+ * (via @NL80211_CMD_ACTION) for processing in userspace. This command
+ * requires an interface index and a match attribute containing the first
+ * few bytes of the frame that should match, e.g. a single byte for only
+ * a category match or four bytes for vendor frames including the OUI.
+ * The registration cannot be dropped, but is removed automatically
+ * when the netlink socket is closed. Multiple registrations can be made.
+ * @NL80211_CMD_ACTION: Action frame TX request and RX notification. This
+ * command is used both as a request to transmit an Action frame and as an
+ * event indicating reception of an Action frame that was not processed in
+ * kernel code, but is for us (i.e., which may need to be processed in a
+ * user space application). %NL80211_ATTR_FRAME is used to specify the
+ * frame contents (including header). %NL80211_ATTR_WIPHY_FREQ (and
+ * optionally %NL80211_ATTR_WIPHY_CHANNEL_TYPE) is used to indicate on
+ * which channel the frame is to be transmitted or was received. This
+ * channel has to be the current channel (remain-on-channel or the
+ * operational channel). When called, this operation returns a cookie
+ * (%NL80211_ATTR_COOKIE) that will be included with the TX status event
+ * pertaining to the TX request.
+ * @NL80211_CMD_ACTION_TX_STATUS: Report TX status of an Action frame
+ * transmitted with %NL80211_CMD_ACTION. %NL80211_ATTR_COOKIE identifies
+ * the TX command and %NL80211_ATTR_FRAME includes the contents of the
+ * frame. %NL80211_ATTR_ACK flag is included if the recipient acknowledged
+ * the frame.
+ * @NL80211_CMD_SET_CQM: Connection quality monitor configuration. This command
+ * is used to configure connection quality monitoring notification trigger
+ * levels.
+ * @NL80211_CMD_NOTIFY_CQM: Connection quality monitor notification. This
+ * command is used as an event to indicate the that a trigger level was
+ * reached.
+ *
* @NL80211_CMD_MAX: highest used command number
* @__NL80211_CMD_AFTER_LAST: internal use
*/
@@ -349,6 +409,25 @@ enum nl80211_commands {
NL80211_CMD_GET_SURVEY,
NL80211_CMD_NEW_SURVEY_RESULTS,
+ NL80211_CMD_SET_PMKSA,
+ NL80211_CMD_DEL_PMKSA,
+ NL80211_CMD_FLUSH_PMKSA,
+
+ NL80211_CMD_REMAIN_ON_CHANNEL,
+ NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
+
+ NL80211_CMD_SET_TX_BITRATE_MASK,
+
+ NL80211_CMD_REGISTER_ACTION,
+ NL80211_CMD_ACTION,
+ NL80211_CMD_ACTION_TX_STATUS,
+
+ NL80211_CMD_SET_POWER_SAVE,
+ NL80211_CMD_GET_POWER_SAVE,
+
+ NL80211_CMD_SET_CQM,
+ NL80211_CMD_NOTIFY_CQM,
+
/* add new commands above here */
/* used to define NL80211_CMD_MAX below */
@@ -398,6 +477,8 @@ enum nl80211_commands {
* @NL80211_ATTR_WIPHY_RTS_THRESHOLD: RTS threshold (TX frames with length
* larger than or equal to this use RTS/CTS handshake); allowed range:
* 0..65536, disable with (u32)-1; dot11RTSThreshold; u32
+ * @NL80211_ATTR_WIPHY_COVERAGE_CLASS: Coverage Class as defined by IEEE 802.11
+ * section 7.3.2.9; dot11CoverageClass; u8
*
* @NL80211_ATTR_IFINDEX: network interface index of the device to operate on
* @NL80211_ATTR_IFNAME: network interface name
@@ -598,6 +679,36 @@ enum nl80211_commands {
* the survey response for %NL80211_CMD_GET_SURVEY, nested attribute
* containing info as possible, see &enum survey_info.
*
+ * @NL80211_ATTR_PMKID: PMK material for PMKSA caching.
+ * @NL80211_ATTR_MAX_NUM_PMKIDS: maximum number of PMKIDs a firmware can
+ * cache, a wiphy attribute.
+ *
+ * @NL80211_ATTR_DURATION: Duration of an operation in milliseconds, u32.
+ *
+ * @NL80211_ATTR_COOKIE: Generic 64-bit cookie to identify objects.
+ *
+ * @NL80211_ATTR_TX_RATES: Nested set of attributes
+ * (enum nl80211_tx_rate_attributes) describing TX rates per band. The
+ * enum nl80211_band value is used as the index (nla_type() of the nested
+ * data. If a band is not included, it will be configured to allow all
+ * rates based on negotiated supported rates information. This attribute
+ * is used with %NL80211_CMD_SET_TX_BITRATE_MASK.
+ *
+ * @NL80211_ATTR_FRAME_MATCH: A binary attribute which typically must contain
+ * at least one byte, currently used with @NL80211_CMD_REGISTER_ACTION.
+ *
+ * @NL80211_ATTR_ACK: Flag attribute indicating that the frame was
+ * acknowledged by the recipient.
+ *
+ * @NL80211_ATTR_CQM: connection quality monitor configuration in a
+ * nested attribute with %NL80211_ATTR_CQM_* sub-attributes.
+ *
+ * @NL80211_ATTR_LOCAL_STATE_CHANGE: Flag attribute to indicate that a command
+ * is requesting a local authentication/association state change without
+ * invoking actual management frame exchange. This can be used with
+ * NL80211_CMD_AUTHENTICATE, NL80211_CMD_DEAUTHENTICATE,
+ * NL80211_CMD_DISASSOCIATE.
+ *
* @NL80211_ATTR_MAX: highest attribute number currently defined
* @__NL80211_ATTR_AFTER_LAST: internal use
*/
@@ -732,6 +843,27 @@ enum nl80211_attrs {
NL80211_ATTR_SURVEY_INFO,
+ NL80211_ATTR_PMKID,
+ NL80211_ATTR_MAX_NUM_PMKIDS,
+
+ NL80211_ATTR_DURATION,
+
+ NL80211_ATTR_COOKIE,
+
+ NL80211_ATTR_WIPHY_COVERAGE_CLASS,
+
+ NL80211_ATTR_TX_RATES,
+
+ NL80211_ATTR_FRAME_MATCH,
+
+ NL80211_ATTR_ACK,
+
+ NL80211_ATTR_PS_STATE,
+
+ NL80211_ATTR_CQM,
+
+ NL80211_ATTR_LOCAL_STATE_CHANGE,
+
/* add attributes here, update the policy in nl80211.c */
__NL80211_ATTR_AFTER_LAST,
@@ -1312,13 +1444,20 @@ enum nl80211_channel_type {
* @NL80211_BSS_BEACON_INTERVAL: beacon interval of the (I)BSS (u16)
* @NL80211_BSS_CAPABILITY: capability field (CPU order, u16)
* @NL80211_BSS_INFORMATION_ELEMENTS: binary attribute containing the
- * raw information elements from the probe response/beacon (bin)
+ * raw information elements from the probe response/beacon (bin);
+ * if the %NL80211_BSS_BEACON_IES attribute is present, the IEs here are
+ * from a Probe Response frame; otherwise they are from a Beacon frame.
+ * However, if the driver does not indicate the source of the IEs, these
+ * IEs may be from either frame subtype.
* @NL80211_BSS_SIGNAL_MBM: signal strength of probe response/beacon
* in mBm (100 * dBm) (s32)
* @NL80211_BSS_SIGNAL_UNSPEC: signal strength of the probe response/beacon
* in unspecified units, scaled to 0..100 (u8)
* @NL80211_BSS_STATUS: status, if this BSS is "used"
* @NL80211_BSS_SEEN_MS_AGO: age of this BSS entry in ms
+ * @NL80211_BSS_BEACON_IES: binary attribute containing the raw information
+ * elements from a Beacon frame (bin); not present if no Beacon frame has
+ * yet been received
* @__NL80211_BSS_AFTER_LAST: internal
* @NL80211_BSS_MAX: highest BSS attribute
*/
@@ -1334,6 +1473,7 @@ enum nl80211_bss {
NL80211_BSS_SIGNAL_UNSPEC,
NL80211_BSS_STATUS,
NL80211_BSS_SEEN_MS_AGO,
+ NL80211_BSS_BEACON_IES,
/* keep last */
__NL80211_BSS_AFTER_LAST,
@@ -1431,4 +1571,74 @@ enum nl80211_key_attributes {
NL80211_KEY_MAX = __NL80211_KEY_AFTER_LAST - 1
};
+/**
+ * enum nl80211_tx_rate_attributes - TX rate set attributes
+ * @__NL80211_TXRATE_INVALID: invalid
+ * @NL80211_TXRATE_LEGACY: Legacy (non-MCS) rates allowed for TX rate selection
+ * in an array of rates as defined in IEEE 802.11 7.3.2.2 (u8 values with
+ * 1 = 500 kbps) but without the IE length restriction (at most
+ * %NL80211_MAX_SUPP_RATES in a single array).
+ * @__NL80211_TXRATE_AFTER_LAST: internal
+ * @NL80211_TXRATE_MAX: highest TX rate attribute
+ */
+enum nl80211_tx_rate_attributes {
+ __NL80211_TXRATE_INVALID,
+ NL80211_TXRATE_LEGACY,
+
+ /* keep last */
+ __NL80211_TXRATE_AFTER_LAST,
+ NL80211_TXRATE_MAX = __NL80211_TXRATE_AFTER_LAST - 1
+};
+
+/**
+ * enum nl80211_band - Frequency band
+ * @NL80211_BAND_2GHZ - 2.4 GHz ISM band
+ * @NL80211_BAND_5GHZ - around 5 GHz band (4.9 - 5.7 GHz)
+ */
+enum nl80211_band {
+ NL80211_BAND_2GHZ,
+ NL80211_BAND_5GHZ,
+};
+
+enum nl80211_ps_state {
+ NL80211_PS_DISABLED,
+ NL80211_PS_ENABLED,
+};
+
+/**
+ * enum nl80211_attr_cqm - connection quality monitor attributes
+ * @__NL80211_ATTR_CQM_INVALID: invalid
+ * @NL80211_ATTR_CQM_RSSI_THOLD: RSSI threshold in dBm. This value specifies
+ * the threshold for the RSSI level at which an event will be sent. Zero
+ * to disable.
+ * @NL80211_ATTR_CQM_RSSI_HYST: RSSI hysteresis in dBm. This value specifies
+ * the minimum amount the RSSI level must change after an event before a
+ * new event may be issued (to reduce effects of RSSI oscillation).
+ * @NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT: RSSI threshold event
+ * @__NL80211_ATTR_CQM_AFTER_LAST: internal
+ * @NL80211_ATTR_CQM_MAX: highest key attribute
+ */
+enum nl80211_attr_cqm {
+ __NL80211_ATTR_CQM_INVALID,
+ NL80211_ATTR_CQM_RSSI_THOLD,
+ NL80211_ATTR_CQM_RSSI_HYST,
+ NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
+
+ /* keep last */
+ __NL80211_ATTR_CQM_AFTER_LAST,
+ NL80211_ATTR_CQM_MAX = __NL80211_ATTR_CQM_AFTER_LAST - 1
+};
+
+/**
+ * enum nl80211_cqm_rssi_threshold_event - RSSI threshold event
+ * @NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW - The RSSI level is lower than the
+ * configured threshold
+ * @NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH - The RSSI is higher than the
+ * configured threshold
+ */
+enum nl80211_cqm_rssi_threshold_event {
+ NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
+ NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
+};
+
#endif /* __LINUX_NL80211_H */
diff --git a/contrib/wpa/src/drivers/radiotap.c b/contrib/wpa/src/drivers/radiotap.c
deleted file mode 100644
index 804473f..0000000
--- a/contrib/wpa/src/drivers/radiotap.c
+++ /dev/null
@@ -1,287 +0,0 @@
-/*
- * Radiotap parser
- *
- * Copyright 2007 Andy Green <andy@warmcat.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
- *
- *
- * Modified for userspace by Johannes Berg <johannes@sipsolutions.net>
- * I only modified some things on top to ease syncing should bugs be found.
- */
-
-#include "includes.h"
-
-#include "common.h"
-#include "radiotap_iter.h"
-
-#define le16_to_cpu le_to_host16
-#define le32_to_cpu le_to_host32
-#define __le32 uint32_t
-#define ulong unsigned long
-#define unlikely(cond) (cond)
-#define get_unaligned(p) \
-({ \
- struct packed_dummy_struct { \
- typeof(*(p)) __val; \
- } __attribute__((packed)) *__ptr = (void *) (p); \
- \
- __ptr->__val; \
-})
-
-/* function prototypes and related defs are in radiotap_iter.h */
-
-/**
- * ieee80211_radiotap_iterator_init - radiotap parser iterator initialization
- * @iterator: radiotap_iterator to initialize
- * @radiotap_header: radiotap header to parse
- * @max_length: total length we can parse into (eg, whole packet length)
- *
- * Returns: 0 or a negative error code if there is a problem.
- *
- * This function initializes an opaque iterator struct which can then
- * be passed to ieee80211_radiotap_iterator_next() to visit every radiotap
- * argument which is present in the header. It knows about extended
- * present headers and handles them.
- *
- * How to use:
- * call __ieee80211_radiotap_iterator_init() to init a semi-opaque iterator
- * struct ieee80211_radiotap_iterator (no need to init the struct beforehand)
- * checking for a good 0 return code. Then loop calling
- * __ieee80211_radiotap_iterator_next()... it returns either 0,
- * -ENOENT if there are no more args to parse, or -EINVAL if there is a problem.
- * The iterator's @this_arg member points to the start of the argument
- * associated with the current argument index that is present, which can be
- * found in the iterator's @this_arg_index member. This arg index corresponds
- * to the IEEE80211_RADIOTAP_... defines.
- *
- * Radiotap header length:
- * You can find the CPU-endian total radiotap header length in
- * iterator->max_length after executing ieee80211_radiotap_iterator_init()
- * successfully.
- *
- * Alignment Gotcha:
- * You must take care when dereferencing iterator.this_arg
- * for multibyte types... the pointer is not aligned. Use
- * get_unaligned((type *)iterator.this_arg) to dereference
- * iterator.this_arg for type "type" safely on all arches.
- *
- * Example code:
- * See Documentation/networking/radiotap-headers.txt
- */
-
-int ieee80211_radiotap_iterator_init(
- struct ieee80211_radiotap_iterator *iterator,
- struct ieee80211_radiotap_header *radiotap_header,
- int max_length)
-{
- /* Linux only supports version 0 radiotap format */
- if (radiotap_header->it_version)
- return -EINVAL;
-
- /* sanity check for allowed length and radiotap length field */
- if (max_length < le16_to_cpu(get_unaligned(&radiotap_header->it_len)))
- return -EINVAL;
-
- iterator->rtheader = radiotap_header;
- iterator->max_length = le16_to_cpu(get_unaligned(
- &radiotap_header->it_len));
- iterator->arg_index = 0;
- iterator->bitmap_shifter = le32_to_cpu(get_unaligned(
- &radiotap_header->it_present));
- iterator->arg = (u8 *)radiotap_header + sizeof(*radiotap_header);
- iterator->this_arg = NULL;
-
- /* find payload start allowing for extended bitmap(s) */
-
- if (unlikely(iterator->bitmap_shifter & (1<<IEEE80211_RADIOTAP_EXT))) {
- while (le32_to_cpu(get_unaligned((__le32 *)iterator->arg)) &
- (1<<IEEE80211_RADIOTAP_EXT)) {
- iterator->arg += sizeof(u32);
-
- /*
- * check for insanity where the present bitmaps
- * keep claiming to extend up to or even beyond the
- * stated radiotap header length
- */
-
- if (((ulong)iterator->arg - (ulong)iterator->rtheader)
- > (ulong)iterator->max_length)
- return -EINVAL;
- }
-
- iterator->arg += sizeof(u32);
-
- /*
- * no need to check again for blowing past stated radiotap
- * header length, because ieee80211_radiotap_iterator_next
- * checks it before it is dereferenced
- */
- }
-
- /* we are all initialized happily */
-
- return 0;
-}
-
-
-/**
- * ieee80211_radiotap_iterator_next - return next radiotap parser iterator arg
- * @iterator: radiotap_iterator to move to next arg (if any)
- *
- * Returns: 0 if there is an argument to handle,
- * -ENOENT if there are no more args or -EINVAL
- * if there is something else wrong.
- *
- * This function provides the next radiotap arg index (IEEE80211_RADIOTAP_*)
- * in @this_arg_index and sets @this_arg to point to the
- * payload for the field. It takes care of alignment handling and extended
- * present fields. @this_arg can be changed by the caller (eg,
- * incremented to move inside a compound argument like
- * IEEE80211_RADIOTAP_CHANNEL). The args pointed to are in
- * little-endian format whatever the endianess of your CPU.
- *
- * Alignment Gotcha:
- * You must take care when dereferencing iterator.this_arg
- * for multibyte types... the pointer is not aligned. Use
- * get_unaligned((type *)iterator.this_arg) to dereference
- * iterator.this_arg for type "type" safely on all arches.
- */
-
-int ieee80211_radiotap_iterator_next(
- struct ieee80211_radiotap_iterator *iterator)
-{
-
- /*
- * small length lookup table for all radiotap types we heard of
- * starting from b0 in the bitmap, so we can walk the payload
- * area of the radiotap header
- *
- * There is a requirement to pad args, so that args
- * of a given length must begin at a boundary of that length
- * -- but note that compound args are allowed (eg, 2 x u16
- * for IEEE80211_RADIOTAP_CHANNEL) so total arg length is not
- * a reliable indicator of alignment requirement.
- *
- * upper nybble: content alignment for arg
- * lower nybble: content length for arg
- */
-
- static const u8 rt_sizes[] = {
- [IEEE80211_RADIOTAP_TSFT] = 0x88,
- [IEEE80211_RADIOTAP_FLAGS] = 0x11,
- [IEEE80211_RADIOTAP_RATE] = 0x11,
- [IEEE80211_RADIOTAP_CHANNEL] = 0x24,
- [IEEE80211_RADIOTAP_FHSS] = 0x22,
- [IEEE80211_RADIOTAP_DBM_ANTSIGNAL] = 0x11,
- [IEEE80211_RADIOTAP_DBM_ANTNOISE] = 0x11,
- [IEEE80211_RADIOTAP_LOCK_QUALITY] = 0x22,
- [IEEE80211_RADIOTAP_TX_ATTENUATION] = 0x22,
- [IEEE80211_RADIOTAP_DB_TX_ATTENUATION] = 0x22,
- [IEEE80211_RADIOTAP_DBM_TX_POWER] = 0x11,
- [IEEE80211_RADIOTAP_ANTENNA] = 0x11,
- [IEEE80211_RADIOTAP_DB_ANTSIGNAL] = 0x11,
- [IEEE80211_RADIOTAP_DB_ANTNOISE] = 0x11,
- [IEEE80211_RADIOTAP_RX_FLAGS] = 0x22,
- [IEEE80211_RADIOTAP_TX_FLAGS] = 0x22,
- [IEEE80211_RADIOTAP_RTS_RETRIES] = 0x11,
- [IEEE80211_RADIOTAP_DATA_RETRIES] = 0x11,
- /*
- * add more here as they are defined in
- * include/net/ieee80211_radiotap.h
- */
- };
-
- /*
- * for every radiotap entry we can at
- * least skip (by knowing the length)...
- */
-
- while (iterator->arg_index < (int) sizeof(rt_sizes)) {
- int hit = 0;
- int pad;
-
- if (!(iterator->bitmap_shifter & 1))
- goto next_entry; /* arg not present */
-
- /*
- * arg is present, account for alignment padding
- * 8-bit args can be at any alignment
- * 16-bit args must start on 16-bit boundary
- * 32-bit args must start on 32-bit boundary
- * 64-bit args must start on 64-bit boundary
- *
- * note that total arg size can differ from alignment of
- * elements inside arg, so we use upper nybble of length
- * table to base alignment on
- *
- * also note: these alignments are ** relative to the
- * start of the radiotap header **. There is no guarantee
- * that the radiotap header itself is aligned on any
- * kind of boundary.
- *
- * the above is why get_unaligned() is used to dereference
- * multibyte elements from the radiotap area
- */
-
- pad = (((ulong)iterator->arg) -
- ((ulong)iterator->rtheader)) &
- ((rt_sizes[iterator->arg_index] >> 4) - 1);
-
- if (pad)
- iterator->arg +=
- (rt_sizes[iterator->arg_index] >> 4) - pad;
-
- /*
- * this is what we will return to user, but we need to
- * move on first so next call has something fresh to test
- */
- iterator->this_arg_index = iterator->arg_index;
- iterator->this_arg = iterator->arg;
- hit = 1;
-
- /* internally move on the size of this arg */
- iterator->arg += rt_sizes[iterator->arg_index] & 0x0f;
-
- /*
- * check for insanity where we are given a bitmap that
- * claims to have more arg content than the length of the
- * radiotap section. We will normally end up equalling this
- * max_length on the last arg, never exceeding it.
- */
-
- if (((ulong)iterator->arg - (ulong)iterator->rtheader) >
- (ulong) iterator->max_length)
- return -EINVAL;
-
- next_entry:
- iterator->arg_index++;
- if (unlikely((iterator->arg_index & 31) == 0)) {
- /* completed current u32 bitmap */
- if (iterator->bitmap_shifter & 1) {
- /* b31 was set, there is more */
- /* move to next u32 bitmap */
- iterator->bitmap_shifter = le32_to_cpu(
- get_unaligned(iterator->next_bitmap));
- iterator->next_bitmap++;
- } else
- /* no more bitmaps: end */
- iterator->arg_index = sizeof(rt_sizes);
- } else /* just try the next bit */
- iterator->bitmap_shifter >>= 1;
-
- /* if we found a valid arg earlier, return it now */
- if (hit)
- return 0;
- }
-
- /* we don't know how to handle any more args, we're done */
- return -ENOENT;
-}
diff --git a/contrib/wpa/src/drivers/radiotap.h b/contrib/wpa/src/drivers/radiotap.h
deleted file mode 100644
index 508264c..0000000
--- a/contrib/wpa/src/drivers/radiotap.h
+++ /dev/null
@@ -1,242 +0,0 @@
-/* $FreeBSD: src/sys/net80211/ieee80211_radiotap.h,v 1.5 2005/01/22 20:12:05 sam Exp $ */
-/* $NetBSD: ieee80211_radiotap.h,v 1.11 2005/06/22 06:16:02 dyoung Exp $ */
-
-/*-
- * Copyright (c) 2003, 2004 David Young. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of David Young may not be used to endorse or promote
- * products derived from this software without specific prior
- * written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY DAVID YOUNG ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID
- * YOUNG BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
- * OF SUCH DAMAGE.
- */
-
-/*
- * Modifications to fit into the linux IEEE 802.11 stack,
- * Mike Kershaw (dragorn@kismetwireless.net)
- */
-
-#ifndef IEEE80211RADIOTAP_H
-#define IEEE80211RADIOTAP_H
-
-#include <stdint.h>
-
-/* Base version of the radiotap packet header data */
-#define PKTHDR_RADIOTAP_VERSION 0
-
-/* A generic radio capture format is desirable. There is one for
- * Linux, but it is neither rigidly defined (there were not even
- * units given for some fields) nor easily extensible.
- *
- * I suggest the following extensible radio capture format. It is
- * based on a bitmap indicating which fields are present.
- *
- * I am trying to describe precisely what the application programmer
- * should expect in the following, and for that reason I tell the
- * units and origin of each measurement (where it applies), or else I
- * use sufficiently weaselly language ("is a monotonically nondecreasing
- * function of...") that I cannot set false expectations for lawyerly
- * readers.
- */
-
-/* The radio capture header precedes the 802.11 header.
- * All data in the header is little endian on all platforms.
- */
-struct ieee80211_radiotap_header {
- uint8_t it_version; /* Version 0. Only increases
- * for drastic changes,
- * introduction of compatible
- * new fields does not count.
- */
- uint8_t it_pad;
- uint16_t it_len; /* length of the whole
- * header in bytes, including
- * it_version, it_pad,
- * it_len, and data fields.
- */
- uint32_t it_present; /* A bitmap telling which
- * fields are present. Set bit 31
- * (0x80000000) to extend the
- * bitmap by another 32 bits.
- * Additional extensions are made
- * by setting bit 31.
- */
-};
-
-/* Name Data type Units
- * ---- --------- -----
- *
- * IEEE80211_RADIOTAP_TSFT __le64 microseconds
- *
- * Value in microseconds of the MAC's 64-bit 802.11 Time
- * Synchronization Function timer when the first bit of the
- * MPDU arrived at the MAC. For received frames, only.
- *
- * IEEE80211_RADIOTAP_CHANNEL 2 x uint16_t MHz, bitmap
- *
- * Tx/Rx frequency in MHz, followed by flags (see below).
- *
- * IEEE80211_RADIOTAP_FHSS uint16_t see below
- *
- * For frequency-hopping radios, the hop set (first byte)
- * and pattern (second byte).
- *
- * IEEE80211_RADIOTAP_RATE u8 500kb/s
- *
- * Tx/Rx data rate
- *
- * IEEE80211_RADIOTAP_DBM_ANTSIGNAL s8 decibels from
- * one milliwatt (dBm)
- *
- * RF signal power at the antenna, decibel difference from
- * one milliwatt.
- *
- * IEEE80211_RADIOTAP_DBM_ANTNOISE s8 decibels from
- * one milliwatt (dBm)
- *
- * RF noise power at the antenna, decibel difference from one
- * milliwatt.
- *
- * IEEE80211_RADIOTAP_DB_ANTSIGNAL u8 decibel (dB)
- *
- * RF signal power at the antenna, decibel difference from an
- * arbitrary, fixed reference.
- *
- * IEEE80211_RADIOTAP_DB_ANTNOISE u8 decibel (dB)
- *
- * RF noise power at the antenna, decibel difference from an
- * arbitrary, fixed reference point.
- *
- * IEEE80211_RADIOTAP_LOCK_QUALITY uint16_t unitless
- *
- * Quality of Barker code lock. Unitless. Monotonically
- * nondecreasing with "better" lock strength. Called "Signal
- * Quality" in datasheets. (Is there a standard way to measure
- * this?)
- *
- * IEEE80211_RADIOTAP_TX_ATTENUATION uint16_t unitless
- *
- * Transmit power expressed as unitless distance from max
- * power set at factory calibration. 0 is max power.
- * Monotonically nondecreasing with lower power levels.
- *
- * IEEE80211_RADIOTAP_DB_TX_ATTENUATION uint16_t decibels (dB)
- *
- * Transmit power expressed as decibel distance from max power
- * set at factory calibration. 0 is max power. Monotonically
- * nondecreasing with lower power levels.
- *
- * IEEE80211_RADIOTAP_DBM_TX_POWER s8 decibels from
- * one milliwatt (dBm)
- *
- * Transmit power expressed as dBm (decibels from a 1 milliwatt
- * reference). This is the absolute power level measured at
- * the antenna port.
- *
- * IEEE80211_RADIOTAP_FLAGS u8 bitmap
- *
- * Properties of transmitted and received frames. See flags
- * defined below.
- *
- * IEEE80211_RADIOTAP_ANTENNA u8 antenna index
- *
- * Unitless indication of the Rx/Tx antenna for this packet.
- * The first antenna is antenna 0.
- *
- * IEEE80211_RADIOTAP_RX_FLAGS uint16_t bitmap
- *
- * Properties of received frames. See flags defined below.
- *
- * IEEE80211_RADIOTAP_TX_FLAGS uint16_t bitmap
- *
- * Properties of transmitted frames. See flags defined below.
- *
- * IEEE80211_RADIOTAP_RTS_RETRIES u8 data
- *
- * Number of rts retries a transmitted frame used.
- *
- * IEEE80211_RADIOTAP_DATA_RETRIES u8 data
- *
- * Number of unicast retries a transmitted frame used.
- *
- */
-enum ieee80211_radiotap_type {
- IEEE80211_RADIOTAP_TSFT = 0,
- IEEE80211_RADIOTAP_FLAGS = 1,
- IEEE80211_RADIOTAP_RATE = 2,
- IEEE80211_RADIOTAP_CHANNEL = 3,
- IEEE80211_RADIOTAP_FHSS = 4,
- IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5,
- IEEE80211_RADIOTAP_DBM_ANTNOISE = 6,
- IEEE80211_RADIOTAP_LOCK_QUALITY = 7,
- IEEE80211_RADIOTAP_TX_ATTENUATION = 8,
- IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9,
- IEEE80211_RADIOTAP_DBM_TX_POWER = 10,
- IEEE80211_RADIOTAP_ANTENNA = 11,
- IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12,
- IEEE80211_RADIOTAP_DB_ANTNOISE = 13,
- IEEE80211_RADIOTAP_RX_FLAGS = 14,
- IEEE80211_RADIOTAP_TX_FLAGS = 15,
- IEEE80211_RADIOTAP_RTS_RETRIES = 16,
- IEEE80211_RADIOTAP_DATA_RETRIES = 17,
- IEEE80211_RADIOTAP_EXT = 31
-};
-
-/* Channel flags. */
-#define IEEE80211_CHAN_TURBO 0x0010 /* Turbo channel */
-#define IEEE80211_CHAN_CCK 0x0020 /* CCK channel */
-#define IEEE80211_CHAN_OFDM 0x0040 /* OFDM channel */
-#define IEEE80211_CHAN_2GHZ 0x0080 /* 2 GHz spectrum channel. */
-#define IEEE80211_CHAN_5GHZ 0x0100 /* 5 GHz spectrum channel */
-#define IEEE80211_CHAN_PASSIVE 0x0200 /* Only passive scan allowed */
-#define IEEE80211_CHAN_DYN 0x0400 /* Dynamic CCK-OFDM channel */
-#define IEEE80211_CHAN_GFSK 0x0800 /* GFSK channel (FHSS PHY) */
-
-/* For IEEE80211_RADIOTAP_FLAGS */
-#define IEEE80211_RADIOTAP_F_CFP 0x01 /* sent/received
- * during CFP
- */
-#define IEEE80211_RADIOTAP_F_SHORTPRE 0x02 /* sent/received
- * with short
- * preamble
- */
-#define IEEE80211_RADIOTAP_F_WEP 0x04 /* sent/received
- * with WEP encryption
- */
-#define IEEE80211_RADIOTAP_F_FRAG 0x08 /* sent/received
- * with fragmentation
- */
-#define IEEE80211_RADIOTAP_F_FCS 0x10 /* frame includes FCS */
-#define IEEE80211_RADIOTAP_F_DATAPAD 0x20 /* frame has padding between
- * 802.11 header and payload
- * (to 32-bit boundary)
- */
-/* For IEEE80211_RADIOTAP_RX_FLAGS */
-#define IEEE80211_RADIOTAP_F_RX_BADFCS 0x0001 /* frame failed crc check */
-
-/* For IEEE80211_RADIOTAP_TX_FLAGS */
-#define IEEE80211_RADIOTAP_F_TX_FAIL 0x0001 /* failed due to excessive
- * retries */
-#define IEEE80211_RADIOTAP_F_TX_CTS 0x0002 /* used cts 'protection' */
-#define IEEE80211_RADIOTAP_F_TX_RTS 0x0004 /* used rts/cts handshake */
-
-#endif /* IEEE80211_RADIOTAP_H */
diff --git a/contrib/wpa/src/drivers/radiotap_iter.h b/contrib/wpa/src/drivers/radiotap_iter.h
deleted file mode 100644
index 92a798a..0000000
--- a/contrib/wpa/src/drivers/radiotap_iter.h
+++ /dev/null
@@ -1,41 +0,0 @@
-#ifndef __RADIOTAP_ITER_H
-#define __RADIOTAP_ITER_H
-
-#include "radiotap.h"
-
-/* Radiotap header iteration
- * implemented in radiotap.c
- */
-/**
- * struct ieee80211_radiotap_iterator - tracks walk thru present radiotap args
- * @rtheader: pointer to the radiotap header we are walking through
- * @max_length: length of radiotap header in cpu byte ordering
- * @this_arg_index: IEEE80211_RADIOTAP_... index of current arg
- * @this_arg: pointer to current radiotap arg
- * @arg_index: internal next argument index
- * @arg: internal next argument pointer
- * @next_bitmap: internal pointer to next present u32
- * @bitmap_shifter: internal shifter for curr u32 bitmap, b0 set == arg present
- */
-
-struct ieee80211_radiotap_iterator {
- struct ieee80211_radiotap_header *rtheader;
- int max_length;
- int this_arg_index;
- unsigned char *this_arg;
-
- int arg_index;
- unsigned char *arg;
- uint32_t *next_bitmap;
- uint32_t bitmap_shifter;
-};
-
-extern int ieee80211_radiotap_iterator_init(
- struct ieee80211_radiotap_iterator *iterator,
- struct ieee80211_radiotap_header *radiotap_header,
- int max_length);
-
-extern int ieee80211_radiotap_iterator_next(
- struct ieee80211_radiotap_iterator *iterator);
-
-#endif /* __RADIOTAP_ITER_H */
diff --git a/contrib/wpa/src/drivers/scan_helpers.c b/contrib/wpa/src/drivers/scan_helpers.c
deleted file mode 100644
index 6338770..0000000
--- a/contrib/wpa/src/drivers/scan_helpers.c
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * WPA Supplicant - Helper functions for scan result processing
- * Copyright (c) 2007-2008, Jouni Malinen <j@w1.fi>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
- */
-
-#include "includes.h"
-
-#include "common.h"
-#include "drivers/driver.h"
-#include "ieee802_11_defs.h"
-
-
-const u8 * wpa_scan_get_ie(const struct wpa_scan_res *res, u8 ie)
-{
- const u8 *end, *pos;
-
- pos = (const u8 *) (res + 1);
- end = pos + res->ie_len;
-
- while (pos + 1 < end) {
- if (pos + 2 + pos[1] > end)
- break;
- if (pos[0] == ie)
- return pos;
- pos += 2 + pos[1];
- }
-
- return NULL;
-}
-
-
-const u8 * wpa_scan_get_vendor_ie(const struct wpa_scan_res *res,
- u32 vendor_type)
-{
- const u8 *end, *pos;
-
- pos = (const u8 *) (res + 1);
- end = pos + res->ie_len;
-
- while (pos + 1 < end) {
- if (pos + 2 + pos[1] > end)
- break;
- if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
- vendor_type == WPA_GET_BE32(&pos[2]))
- return pos;
- pos += 2 + pos[1];
- }
-
- return NULL;
-}
-
-
-struct wpabuf * wpa_scan_get_vendor_ie_multi(const struct wpa_scan_res *res,
- u32 vendor_type)
-{
- struct wpabuf *buf;
- const u8 *end, *pos;
-
- buf = wpabuf_alloc(res->ie_len);
- if (buf == NULL)
- return NULL;
-
- pos = (const u8 *) (res + 1);
- end = pos + res->ie_len;
-
- while (pos + 1 < end) {
- if (pos + 2 + pos[1] > end)
- break;
- if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
- vendor_type == WPA_GET_BE32(&pos[2]))
- wpabuf_put_data(buf, pos + 2 + 4, pos[1] - 4);
- pos += 2 + pos[1];
- }
-
- if (wpabuf_len(buf) == 0) {
- wpabuf_free(buf);
- buf = NULL;
- }
-
- return buf;
-}
-
-
-int wpa_scan_get_max_rate(const struct wpa_scan_res *res)
-{
- int rate = 0;
- const u8 *ie;
- int i;
-
- ie = wpa_scan_get_ie(res, WLAN_EID_SUPP_RATES);
- for (i = 0; ie && i < ie[1]; i++) {
- if ((ie[i + 2] & 0x7f) > rate)
- rate = ie[i + 2] & 0x7f;
- }
-
- ie = wpa_scan_get_ie(res, WLAN_EID_EXT_SUPP_RATES);
- for (i = 0; ie && i < ie[1]; i++) {
- if ((ie[i + 2] & 0x7f) > rate)
- rate = ie[i + 2] & 0x7f;
- }
-
- return rate;
-}
-
-
-void wpa_scan_results_free(struct wpa_scan_results *res)
-{
- size_t i;
-
- if (res == NULL)
- return;
-
- for (i = 0; i < res->num; i++)
- os_free(res->res[i]);
- os_free(res->res);
- os_free(res);
-}
-
-
-/* Compare function for sorting scan results. Return >0 if @b is considered
- * better. */
-static int wpa_scan_result_compar(const void *a, const void *b)
-{
- struct wpa_scan_res **_wa = (void *) a;
- struct wpa_scan_res **_wb = (void *) b;
- struct wpa_scan_res *wa = *_wa;
- struct wpa_scan_res *wb = *_wb;
- int wpa_a, wpa_b, maxrate_a, maxrate_b;
-
- /* WPA/WPA2 support preferred */
- wpa_a = wpa_scan_get_vendor_ie(wa, WPA_IE_VENDOR_TYPE) != NULL ||
- wpa_scan_get_ie(wa, WLAN_EID_RSN) != NULL;
- wpa_b = wpa_scan_get_vendor_ie(wb, WPA_IE_VENDOR_TYPE) != NULL ||
- wpa_scan_get_ie(wb, WLAN_EID_RSN) != NULL;
-
- if (wpa_b && !wpa_a)
- return 1;
- if (!wpa_b && wpa_a)
- return -1;
-
- /* privacy support preferred */
- if ((wa->caps & IEEE80211_CAP_PRIVACY) == 0 &&
- (wb->caps & IEEE80211_CAP_PRIVACY))
- return 1;
- if ((wa->caps & IEEE80211_CAP_PRIVACY) &&
- (wb->caps & IEEE80211_CAP_PRIVACY) == 0)
- return -1;
-
- /* best/max rate preferred if signal level close enough XXX */
- if ((wa->level && wb->level && abs(wb->level - wa->level) < 5) ||
- (wa->qual && wb->qual && abs(wb->qual - wa->qual) < 10)) {
- maxrate_a = wpa_scan_get_max_rate(wa);
- maxrate_b = wpa_scan_get_max_rate(wb);
- if (maxrate_a != maxrate_b)
- return maxrate_b - maxrate_a;
- }
-
- /* use freq for channel preference */
-
- /* all things being equal, use signal level; if signal levels are
- * identical, use quality values since some drivers may only report
- * that value and leave the signal level zero */
- if (wb->level == wa->level)
- return wb->qual - wa->qual;
- return wb->level - wa->level;
-}
-
-
-void wpa_scan_sort_results(struct wpa_scan_results *res)
-{
- qsort(res->res, res->num, sizeof(struct wpa_scan_res *),
- wpa_scan_result_compar);
-}
diff --git a/contrib/wpa/src/common/wireless_copy.h b/contrib/wpa/src/drivers/wireless_copy.h
index ad76466..ad76466 100644
--- a/contrib/wpa/src/common/wireless_copy.h
+++ b/contrib/wpa/src/drivers/wireless_copy.h
diff --git a/contrib/wpa/src/eap_common/Makefile b/contrib/wpa/src/eap_common/Makefile
index cffba62..9c41962 100644
--- a/contrib/wpa/src/eap_common/Makefile
+++ b/contrib/wpa/src/eap_common/Makefile
@@ -2,7 +2,6 @@ all:
@echo Nothing to be made.
clean:
- for d in $(SUBDIRS); do make -C $$d clean; done
rm -f *~ *.o *.d
install:
diff --git a/contrib/wpa/src/eap_common/chap.c b/contrib/wpa/src/eap_common/chap.c
index a088aff..60bfc1c 100644
--- a/contrib/wpa/src/eap_common/chap.c
+++ b/contrib/wpa/src/eap_common/chap.c
@@ -1,6 +1,6 @@
/*
* CHAP-MD5 (RFC 1994)
- * Copyright (c) 2007, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2007-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -15,11 +15,10 @@
#include "includes.h"
#include "common.h"
-#include "md5.h"
-#include "crypto.h"
+#include "crypto/crypto.h"
#include "chap.h"
-void chap_md5(u8 id, const u8 *secret, size_t secret_len, const u8 *challenge,
+int chap_md5(u8 id, const u8 *secret, size_t secret_len, const u8 *challenge,
size_t challenge_len, u8 *response)
{
const u8 *addr[3];
@@ -31,5 +30,5 @@ void chap_md5(u8 id, const u8 *secret, size_t secret_len, const u8 *challenge,
len[1] = secret_len;
addr[2] = challenge;
len[2] = challenge_len;
- md5_vector(3, addr, len, response);
+ return md5_vector(3, addr, len, response);
}
diff --git a/contrib/wpa/src/eap_common/chap.h b/contrib/wpa/src/eap_common/chap.h
index 209dc8a..b9c400c 100644
--- a/contrib/wpa/src/eap_common/chap.h
+++ b/contrib/wpa/src/eap_common/chap.h
@@ -1,6 +1,6 @@
/*
* CHAP-MD5 (RFC 1994)
- * Copyright (c) 2007, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2007-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -17,7 +17,7 @@
#define CHAP_MD5_LEN 16
-void chap_md5(u8 id, const u8 *secret, size_t secret_len, const u8 *challenge,
- size_t challenge_len, u8 *response);
+int chap_md5(u8 id, const u8 *secret, size_t secret_len, const u8 *challenge,
+ size_t challenge_len, u8 *response);
#endif /* CHAP_H */
diff --git a/contrib/wpa/src/eap_common/eap_fast_common.c b/contrib/wpa/src/eap_common/eap_fast_common.c
index 4d3deaf..4de34a8 100644
--- a/contrib/wpa/src/eap_common/eap_fast_common.c
+++ b/contrib/wpa/src/eap_common/eap_fast_common.c
@@ -15,8 +15,8 @@
#include "includes.h"
#include "common.h"
-#include "sha1.h"
-#include "tls.h"
+#include "crypto/sha1.h"
+#include "crypto/tls.h"
#include "eap_defs.h"
#include "eap_tlv_common.h"
#include "eap_fast_common.h"
diff --git a/contrib/wpa/src/eap_common/eap_gpsk_common.c b/contrib/wpa/src/eap_common/eap_gpsk_common.c
index 414610c..4076262 100644
--- a/contrib/wpa/src/eap_common/eap_gpsk_common.c
+++ b/contrib/wpa/src/eap_common/eap_gpsk_common.c
@@ -15,12 +15,9 @@
#include "includes.h"
#include "common.h"
+#include "crypto/aes_wrap.h"
+#include "crypto/sha256.h"
#include "eap_defs.h"
-#include "aes_wrap.h"
-#include "crypto.h"
-#ifdef EAP_GPSK_SHA256
-#include "sha256.h"
-#endif /* EAP_GPSK_SHA256 */
#include "eap_gpsk_common.h"
diff --git a/contrib/wpa/src/eap_common/eap_pax_common.c b/contrib/wpa/src/eap_common/eap_pax_common.c
index 8011046..32dc80c 100644
--- a/contrib/wpa/src/eap_common/eap_pax_common.c
+++ b/contrib/wpa/src/eap_common/eap_pax_common.c
@@ -15,7 +15,7 @@
#include "includes.h"
#include "common.h"
-#include "sha1.h"
+#include "crypto/sha1.h"
#include "eap_pax_common.h"
diff --git a/contrib/wpa/src/eap_common/eap_peap_common.c b/contrib/wpa/src/eap_common/eap_peap_common.c
index 14625f9..3a64b8e 100644
--- a/contrib/wpa/src/eap_common/eap_peap_common.c
+++ b/contrib/wpa/src/eap_common/eap_peap_common.c
@@ -15,7 +15,7 @@
#include "includes.h"
#include "common.h"
-#include "sha1.h"
+#include "crypto/sha1.h"
#include "eap_peap_common.h"
void peap_prfplus(int version, const u8 *key, size_t key_len,
diff --git a/contrib/wpa/src/eap_common/eap_psk_common.c b/contrib/wpa/src/eap_common/eap_psk_common.c
index 0def3e8..7417d5c 100644
--- a/contrib/wpa/src/eap_common/eap_psk_common.c
+++ b/contrib/wpa/src/eap_common/eap_psk_common.c
@@ -15,7 +15,7 @@
#include "includes.h"
#include "common.h"
-#include "aes_wrap.h"
+#include "crypto/aes_wrap.h"
#include "eap_defs.h"
#include "eap_psk_common.h"
diff --git a/contrib/wpa/src/eap_common/eap_sake_common.c b/contrib/wpa/src/eap_common/eap_sake_common.c
index eafad1d..9002b0c 100644
--- a/contrib/wpa/src/eap_common/eap_sake_common.c
+++ b/contrib/wpa/src/eap_common/eap_sake_common.c
@@ -15,8 +15,8 @@
#include "includes.h"
#include "common.h"
-#include "sha1.h"
#include "wpabuf.h"
+#include "crypto/sha1.h"
#include "eap_defs.h"
#include "eap_sake_common.h"
diff --git a/contrib/wpa/src/eap_common/eap_sim_common.c b/contrib/wpa/src/eap_common/eap_sim_common.c
index fccda02..56b4ded 100644
--- a/contrib/wpa/src/eap_common/eap_sim_common.c
+++ b/contrib/wpa/src/eap_common/eap_sim_common.c
@@ -15,12 +15,12 @@
#include "includes.h"
#include "common.h"
-#include "eap_common/eap_defs.h"
-#include "sha1.h"
-#include "sha256.h"
-#include "crypto.h"
-#include "aes_wrap.h"
#include "wpabuf.h"
+#include "crypto/aes_wrap.h"
+#include "crypto/crypto.h"
+#include "crypto/sha1.h"
+#include "crypto/sha256.h"
+#include "eap_common/eap_defs.h"
#include "eap_common/eap_sim_common.h"
@@ -233,7 +233,7 @@ void eap_sim_add_mac(const u8 *k_aut, const u8 *msg, size_t msg_len, u8 *mac,
}
-#ifdef EAP_AKA_PRIME
+#if defined(EAP_AKA_PRIME) || defined(EAP_SERVER_AKA_PRIME)
static void prf_prime(const u8 *k, const char *seed1,
const u8 *seed2, size_t seed2_len,
const u8 *seed3, size_t seed3_len,
@@ -496,7 +496,7 @@ void eap_aka_prime_derive_ck_ik_prime(u8 *ck, u8 *ik, const u8 *sqn_ak,
wpa_hexdump_key(MSG_DEBUG, "EAP-AKA': CK'", ck, EAP_AKA_CK_LEN);
wpa_hexdump_key(MSG_DEBUG, "EAP-AKA': IK'", ik, EAP_AKA_IK_LEN);
}
-#endif /* EAP_AKA_PRIME */
+#endif /* EAP_AKA_PRIME || EAP_SERVER_AKA_PRIME */
int eap_sim_parse_attr(const u8 *start, const u8 *end,
@@ -858,7 +858,7 @@ int eap_sim_parse_attr(const u8 *start, const u8 *end,
wpa_printf(MSG_DEBUG, "EAP-SIM: AT_RESULT_IND");
attr->result_ind = 1;
break;
-#ifdef EAP_AKA_PRIME
+#if defined(EAP_AKA_PRIME) || defined(EAP_SERVER_AKA_PRIME)
case EAP_SIM_AT_KDF_INPUT:
if (aka != 2) {
wpa_printf(MSG_INFO, "EAP-AKA: Unexpected "
@@ -913,7 +913,7 @@ int eap_sim_parse_attr(const u8 *start, const u8 *end,
}
attr->bidding = apos;
break;
-#endif /* EAP_AKA_PRIME */
+#endif /* EAP_AKA_PRIME || EAP_SERVER_AKA_PRIME */
default:
if (pos[0] < 128) {
wpa_printf(MSG_INFO, "EAP-SIM: Unrecognized "
@@ -1023,14 +1023,14 @@ struct wpabuf * eap_sim_msg_finish(struct eap_sim_msg *msg, const u8 *k_aut,
eap = wpabuf_mhead(msg->buf);
eap->length = host_to_be16(wpabuf_len(msg->buf));
-#ifdef EAP_AKA_PRIME
+#if defined(EAP_AKA_PRIME) || defined(EAP_SERVER_AKA_PRIME)
if (k_aut && msg->mac && msg->type == EAP_TYPE_AKA_PRIME) {
eap_sim_add_mac_sha256(k_aut, (u8 *) wpabuf_head(msg->buf),
wpabuf_len(msg->buf),
(u8 *) wpabuf_mhead(msg->buf) +
msg->mac, extra, extra_len);
} else
-#endif /* EAP_AKA_PRIME */
+#endif /* EAP_AKA_PRIME || EAP_SERVER_AKA_PRIME */
if (k_aut && msg->mac) {
eap_sim_add_mac(k_aut, (u8 *) wpabuf_head(msg->buf),
wpabuf_len(msg->buf),
diff --git a/contrib/wpa/src/eap_common/eap_sim_common.h b/contrib/wpa/src/eap_common/eap_sim_common.h
index a8080e2..48c8eaa 100644
--- a/contrib/wpa/src/eap_common/eap_sim_common.h
+++ b/contrib/wpa/src/eap_common/eap_sim_common.h
@@ -94,7 +94,7 @@ int eap_sim_verify_mac(const u8 *k_aut, const struct wpabuf *req,
void eap_sim_add_mac(const u8 *k_aut, const u8 *msg, size_t msg_len, u8 *mac,
const u8 *extra, size_t extra_len);
-#ifdef EAP_AKA_PRIME
+#if defined(EAP_AKA_PRIME) || defined(EAP_SERVER_AKA_PRIME)
void eap_aka_prime_derive_keys(const u8 *identity, size_t identity_len,
const u8 *ik, const u8 *ck, u8 *k_encr,
u8 *k_aut, u8 *k_re, u8 *msk, u8 *emsk);
@@ -110,7 +110,7 @@ void eap_sim_add_mac_sha256(const u8 *k_aut, const u8 *msg, size_t msg_len,
void eap_aka_prime_derive_ck_ik_prime(u8 *ck, u8 *ik, const u8 *sqn_ak,
const u8 *network_name,
size_t network_name_len);
-#else /* EAP_AKA_PRIME */
+#else /* EAP_AKA_PRIME || EAP_SERVER_AKA_PRIME */
static inline void eap_aka_prime_derive_keys(const u8 *identity,
size_t identity_len,
const u8 *ik, const u8 *ck,
@@ -135,7 +135,7 @@ static inline int eap_sim_verify_mac_sha256(const u8 *k_aut,
{
return -1;
}
-#endif /* EAP_AKA_PRIME */
+#endif /* EAP_AKA_PRIME || EAP_SERVER_AKA_PRIME */
/* EAP-SIM/AKA Attributes (0..127 non-skippable) */
diff --git a/contrib/wpa/src/eap_common/ikev2_common.c b/contrib/wpa/src/eap_common/ikev2_common.c
index 818b5bd..67754d8 100644
--- a/contrib/wpa/src/eap_common/ikev2_common.c
+++ b/contrib/wpa/src/eap_common/ikev2_common.c
@@ -15,9 +15,9 @@
#include "includes.h"
#include "common.h"
-#include "sha1.h"
-#include "md5.h"
-#include "crypto.h"
+#include "crypto/crypto.h"
+#include "crypto/md5.h"
+#include "crypto/sha1.h"
#include "ikev2_common.h"
diff --git a/contrib/wpa/src/eap_peer/Makefile b/contrib/wpa/src/eap_peer/Makefile
index d9449a2..3651056 100644
--- a/contrib/wpa/src/eap_peer/Makefile
+++ b/contrib/wpa/src/eap_peer/Makefile
@@ -2,7 +2,6 @@ all:
@echo Nothing to be made.
clean:
- for d in $(SUBDIRS); do make -C $$d clean; done
rm -f *~ *.o *.so *.d
install:
diff --git a/contrib/wpa/src/eap_peer/eap.c b/contrib/wpa/src/eap_peer/eap.c
index e8e504a..b9f186b 100644
--- a/contrib/wpa/src/eap_peer/eap.c
+++ b/contrib/wpa/src/eap_peer/eap.c
@@ -1,6 +1,6 @@
/*
* EAP peer state machines (RFC 4137)
- * Copyright (c) 2004-2008, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2004-2010, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -24,14 +24,14 @@
#include "includes.h"
#include "common.h"
-#include "eap_i.h"
-#include "eap_config.h"
-#include "tls.h"
-#include "crypto.h"
#include "pcsc_funcs.h"
-#include "wpa_ctrl.h"
#include "state_machine.h"
+#include "crypto/crypto.h"
+#include "crypto/tls.h"
+#include "common/wpa_ctrl.h"
#include "eap_common/eap_wsc_common.h"
+#include "eap_i.h"
+#include "eap_config.h"
#define STATE_MACHINE_DATA struct eap_sm
#define STATE_MACHINE_DEBUG_PREFIX "EAP"
@@ -228,9 +228,15 @@ SM_STATE(EAP, GET_METHOD)
if (!eap_sm_allowMethod(sm, sm->reqVendor, method)) {
wpa_printf(MSG_DEBUG, "EAP: vendor %u method %u not allowed",
sm->reqVendor, method);
+ wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_PROPOSED_METHOD
+ "vendor=%u method=%u -> NAK",
+ sm->reqVendor, method);
goto nak;
}
+ wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_PROPOSED_METHOD
+ "vendor=%u method=%u", sm->reqVendor, method);
+
/*
* RFC 4137 does not define specific operation for fast
* re-authentication (session resumption). The design here is to allow
@@ -1154,6 +1160,60 @@ static void eap_sm_parseEapReq(struct eap_sm *sm, const struct wpabuf *req)
}
+static void eap_peer_sm_tls_event(void *ctx, enum tls_event ev,
+ union tls_event_data *data)
+{
+ struct eap_sm *sm = ctx;
+ char *hash_hex = NULL;
+ char *cert_hex = NULL;
+
+ switch (ev) {
+ case TLS_CERT_CHAIN_FAILURE:
+ wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_TLS_CERT_ERROR
+ "reason=%d depth=%d subject='%s' err='%s'",
+ data->cert_fail.reason,
+ data->cert_fail.depth,
+ data->cert_fail.subject,
+ data->cert_fail.reason_txt);
+ break;
+ case TLS_PEER_CERTIFICATE:
+ if (data->peer_cert.hash) {
+ size_t len = data->peer_cert.hash_len * 2 + 1;
+ hash_hex = os_malloc(len);
+ if (hash_hex) {
+ wpa_snprintf_hex(hash_hex, len,
+ data->peer_cert.hash,
+ data->peer_cert.hash_len);
+ }
+ }
+ wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_PEER_CERT
+ "depth=%d subject='%s'%s%s",
+ data->peer_cert.depth, data->peer_cert.subject,
+ hash_hex ? " hash=" : "", hash_hex ? hash_hex : "");
+
+ if (data->peer_cert.cert) {
+ size_t len = wpabuf_len(data->peer_cert.cert) * 2 + 1;
+ cert_hex = os_malloc(len);
+ if (cert_hex == NULL)
+ break;
+ wpa_snprintf_hex(cert_hex, len,
+ wpabuf_head(data->peer_cert.cert),
+ wpabuf_len(data->peer_cert.cert));
+ wpa_msg_ctrl(sm->msg_ctx, MSG_INFO,
+ WPA_EVENT_EAP_PEER_CERT
+ "depth=%d subject='%s' cert=%s",
+ data->peer_cert.depth,
+ data->peer_cert.subject,
+ cert_hex);
+ }
+ break;
+ }
+
+ os_free(hash_hex);
+ os_free(cert_hex);
+}
+
+
/**
* eap_peer_sm_init - Allocate and initialize EAP peer state machine
* @eapol_ctx: Context data to be used with eapol_cb calls
@@ -1188,6 +1248,11 @@ struct eap_sm * eap_peer_sm_init(void *eapol_ctx,
tlsconf.opensc_engine_path = conf->opensc_engine_path;
tlsconf.pkcs11_engine_path = conf->pkcs11_engine_path;
tlsconf.pkcs11_module_path = conf->pkcs11_module_path;
+#ifdef CONFIG_FIPS
+ tlsconf.fips_mode = 1;
+#endif /* CONFIG_FIPS */
+ tlsconf.event_cb = eap_peer_sm_tls_event;
+ tlsconf.cb_ctx = sm;
sm->ssl_ctx = tls_init(&tlsconf);
if (sm->ssl_ctx == NULL) {
wpa_printf(MSG_WARNING, "SSL: Failed to initialize TLS "
diff --git a/contrib/wpa/src/eap_peer/eap.h b/contrib/wpa/src/eap_peer/eap.h
index d7a5628..40d0b69 100644
--- a/contrib/wpa/src/eap_peer/eap.h
+++ b/contrib/wpa/src/eap_peer/eap.h
@@ -15,7 +15,7 @@
#ifndef EAP_H
#define EAP_H
-#include "defs.h"
+#include "common/defs.h"
#include "eap_common/eap_defs.h"
#include "eap_peer/eap_methods.h"
diff --git a/contrib/wpa/src/eap_peer/eap_aka.c b/contrib/wpa/src/eap_peer/eap_aka.c
index f237141..182f01a 100644
--- a/contrib/wpa/src/eap_peer/eap_aka.c
+++ b/contrib/wpa/src/eap_peer/eap_aka.c
@@ -15,16 +15,14 @@
#include "includes.h"
#include "common.h"
-#include "eap_peer/eap_i.h"
#include "pcsc_funcs.h"
+#include "crypto/crypto.h"
+#include "crypto/sha1.h"
+#include "crypto/sha256.h"
+#include "crypto/milenage.h"
#include "eap_common/eap_sim_common.h"
-#include "sha1.h"
-#include "sha256.h"
-#include "crypto.h"
-#include "eap_peer/eap_config.h"
-#ifdef CONFIG_USIM_SIMULATOR
-#include "hlr_auc_gw/milenage.h"
-#endif /* CONFIG_USIM_SIMULATOR */
+#include "eap_config.h"
+#include "eap_i.h"
struct eap_aka_data {
diff --git a/contrib/wpa/src/eap_peer/eap_config.h b/contrib/wpa/src/eap_peer/eap_config.h
index 94245c3..b64b68f 100644
--- a/contrib/wpa/src/eap_peer/eap_config.h
+++ b/contrib/wpa/src/eap_peer/eap_config.h
@@ -85,6 +85,15 @@ struct eap_peer_config {
* Alternatively, a named configuration blob can be used by setting
* this to blob://blob_name.
*
+ * Alternatively, this can be used to only perform matching of the
+ * server certificate (SHA-256 hash of the DER encoded X.509
+ * certificate). In this case, the possible CA certificates in the
+ * server certificate chain are ignored and only the server certificate
+ * is verified. This is configured with the following format:
+ * hash:://server/sha256/cert_hash_in_hex
+ * For example: "hash://server/sha256/
+ * 5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca6a"
+ *
* On Windows, trusted CA certificates can be loaded from the system
* certificate store by setting this to cert_store://name, e.g.,
* ca_cert="cert_store://CA" or ca_cert="cert_store://ROOT".
diff --git a/contrib/wpa/src/eap_peer/eap_fast.c b/contrib/wpa/src/eap_peer/eap_fast.c
index d008670..5d3e69d 100644
--- a/contrib/wpa/src/eap_peer/eap_fast.c
+++ b/contrib/wpa/src/eap_peer/eap_fast.c
@@ -15,12 +15,12 @@
#include "includes.h"
#include "common.h"
+#include "crypto/tls.h"
+#include "crypto/sha1.h"
+#include "eap_common/eap_tlv_common.h"
#include "eap_i.h"
#include "eap_tls_common.h"
#include "eap_config.h"
-#include "tls.h"
-#include "eap_common/eap_tlv_common.h"
-#include "sha1.h"
#include "eap_fast_pac.h"
#ifdef EAP_FAST_DYNAMIC
@@ -1445,9 +1445,9 @@ static int eap_fast_process_start(struct eap_sm *sm,
/* EAP-FAST Version negotiation (section 3.1) */
wpa_printf(MSG_DEBUG, "EAP-FAST: Start (server ver=%d, own ver=%d)",
- flags & EAP_PEAP_VERSION_MASK, data->fast_version);
- if ((flags & EAP_PEAP_VERSION_MASK) < data->fast_version)
- data->fast_version = flags & EAP_PEAP_VERSION_MASK;
+ flags & EAP_TLS_VERSION_MASK, data->fast_version);
+ if ((flags & EAP_TLS_VERSION_MASK) < data->fast_version)
+ data->fast_version = flags & EAP_TLS_VERSION_MASK;
wpa_printf(MSG_DEBUG, "EAP-FAST: Using FAST version %d",
data->fast_version);
diff --git a/contrib/wpa/src/eap_peer/eap_fast_pac.c b/contrib/wpa/src/eap_peer/eap_fast_pac.c
index 77893d6..541cce5 100644
--- a/contrib/wpa/src/eap_peer/eap_fast_pac.c
+++ b/contrib/wpa/src/eap_peer/eap_fast_pac.c
@@ -480,8 +480,10 @@ static void eap_fast_write(char **buf, char **pos, size_t *buf_len,
{
size_t i, need;
int ret;
+ char *end;
- if (data == NULL || *buf == NULL)
+ if (data == NULL || buf == NULL || *buf == NULL ||
+ pos == NULL || *pos == NULL || *pos < *buf)
return;
need = os_strlen(field) + len * 2 + 30;
@@ -498,32 +500,31 @@ static void eap_fast_write(char **buf, char **pos, size_t *buf_len,
*buf = nbuf;
*buf_len += need;
}
+ end = *buf + *buf_len;
- ret = os_snprintf(*pos, *buf + *buf_len - *pos, "%s=", field);
- if (ret < 0 || ret >= *buf + *buf_len - *pos)
+ ret = os_snprintf(*pos, end - *pos, "%s=", field);
+ if (ret < 0 || ret >= end - *pos)
return;
*pos += ret;
- *pos += wpa_snprintf_hex(*pos, *buf + *buf_len - *pos, data, len);
- ret = os_snprintf(*pos, *buf + *buf_len - *pos, "\n");
- if (ret < 0 || ret >= *buf + *buf_len - *pos)
+ *pos += wpa_snprintf_hex(*pos, end - *pos, data, len);
+ ret = os_snprintf(*pos, end - *pos, "\n");
+ if (ret < 0 || ret >= end - *pos)
return;
*pos += ret;
if (txt) {
- ret = os_snprintf(*pos, *buf + *buf_len - *pos,
- "%s-txt=", field);
- if (ret < 0 || ret >= *buf + *buf_len - *pos)
+ ret = os_snprintf(*pos, end - *pos, "%s-txt=", field);
+ if (ret < 0 || ret >= end - *pos)
return;
*pos += ret;
for (i = 0; i < len; i++) {
- ret = os_snprintf(*pos, *buf + *buf_len - *pos,
- "%c", data[i]);
- if (ret < 0 || ret >= *buf + *buf_len - *pos)
+ ret = os_snprintf(*pos, end - *pos, "%c", data[i]);
+ if (ret < 0 || ret >= end - *pos)
return;
*pos += ret;
}
- ret = os_snprintf(*pos, *buf + *buf_len - *pos, "\n");
- if (ret < 0 || ret >= *buf + *buf_len - *pos)
+ ret = os_snprintf(*pos, end - *pos, "\n");
+ if (ret < 0 || ret >= end - *pos)
return;
*pos += ret;
}
diff --git a/contrib/wpa/src/eap_peer/eap_leap.c b/contrib/wpa/src/eap_peer/eap_leap.c
index 01c1f16..a7c94a4 100644
--- a/contrib/wpa/src/eap_peer/eap_leap.c
+++ b/contrib/wpa/src/eap_peer/eap_leap.c
@@ -15,9 +15,9 @@
#include "includes.h"
#include "common.h"
+#include "crypto/ms_funcs.h"
+#include "crypto/crypto.h"
#include "eap_i.h"
-#include "ms_funcs.h"
-#include "crypto.h"
#define LEAP_VERSION 1
#define LEAP_CHALLENGE_LEN 8
@@ -233,10 +233,16 @@ static struct wpabuf * eap_leap_process_response(struct eap_sm *sm, void *priv,
os_memcpy(data->ap_response, pos, LEAP_RESPONSE_LEN);
if (pwhash) {
- hash_nt_password_hash(password, pw_hash_hash);
+ if (hash_nt_password_hash(password, pw_hash_hash)) {
+ ret->ignore = TRUE;
+ return NULL;
+ }
} else {
- nt_password_hash(password, password_len, pw_hash);
- hash_nt_password_hash(pw_hash, pw_hash_hash);
+ if (nt_password_hash(password, password_len, pw_hash) ||
+ hash_nt_password_hash(pw_hash, pw_hash_hash)) {
+ ret->ignore = TRUE;
+ return NULL;
+ }
}
challenge_response(data->ap_challenge, pw_hash_hash, expected);
@@ -345,11 +351,17 @@ static u8 * eap_leap_getKey(struct eap_sm *sm, void *priv, size_t *len)
if (key == NULL)
return NULL;
- if (pwhash)
- hash_nt_password_hash(password, pw_hash_hash);
- else {
- nt_password_hash(password, password_len, pw_hash);
- hash_nt_password_hash(pw_hash, pw_hash_hash);
+ if (pwhash) {
+ if (hash_nt_password_hash(password, pw_hash_hash)) {
+ os_free(key);
+ return NULL;
+ }
+ } else {
+ if (nt_password_hash(password, password_len, pw_hash) ||
+ hash_nt_password_hash(pw_hash, pw_hash_hash)) {
+ os_free(key);
+ return NULL;
+ }
}
wpa_hexdump_key(MSG_DEBUG, "EAP-LEAP: pw_hash_hash",
pw_hash_hash, 16);
diff --git a/contrib/wpa/src/eap_peer/eap_md5.c b/contrib/wpa/src/eap_peer/eap_md5.c
index 7961143..0edbae8 100644
--- a/contrib/wpa/src/eap_peer/eap_md5.c
+++ b/contrib/wpa/src/eap_peer/eap_md5.c
@@ -76,7 +76,7 @@ static struct wpabuf * eap_md5_process(struct eap_sm *sm, void *priv,
wpa_printf(MSG_DEBUG, "EAP-MD5: Generating Challenge Response");
ret->methodState = METHOD_DONE;
- ret->decision = DECISION_UNCOND_SUCC;
+ ret->decision = DECISION_COND_SUCC;
ret->allowNotifications = TRUE;
resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_MD5, 1 + CHAP_MD5_LEN,
diff --git a/contrib/wpa/src/eap_peer/eap_methods.c b/contrib/wpa/src/eap_peer/eap_methods.c
index 2374e5e..3b0af05 100644
--- a/contrib/wpa/src/eap_peer/eap_methods.c
+++ b/contrib/wpa/src/eap_peer/eap_methods.c
@@ -340,161 +340,6 @@ int eap_peer_method_register(struct eap_method *method)
/**
- * eap_peer_register_methods - Register statically linked EAP peer methods
- * Returns: 0 on success, -1 on failure
- *
- * This function is called at program initialization to register all EAP peer
- * methods that were linked in statically.
- */
-int eap_peer_register_methods(void)
-{
- int ret = 0;
-
-#ifdef EAP_MD5
- if (ret == 0) {
- int eap_peer_md5_register(void);
- ret = eap_peer_md5_register();
- }
-#endif /* EAP_MD5 */
-
-#ifdef EAP_TLS
- if (ret == 0) {
- int eap_peer_tls_register(void);
- ret = eap_peer_tls_register();
- }
-#endif /* EAP_TLS */
-
-#ifdef EAP_MSCHAPv2
- if (ret == 0) {
- int eap_peer_mschapv2_register(void);
- ret = eap_peer_mschapv2_register();
- }
-#endif /* EAP_MSCHAPv2 */
-
-#ifdef EAP_PEAP
- if (ret == 0) {
- int eap_peer_peap_register(void);
- ret = eap_peer_peap_register();
- }
-#endif /* EAP_PEAP */
-
-#ifdef EAP_TTLS
- if (ret == 0) {
- int eap_peer_ttls_register(void);
- ret = eap_peer_ttls_register();
- }
-#endif /* EAP_TTLS */
-
-#ifdef EAP_GTC
- if (ret == 0) {
- int eap_peer_gtc_register(void);
- ret = eap_peer_gtc_register();
- }
-#endif /* EAP_GTC */
-
-#ifdef EAP_OTP
- if (ret == 0) {
- int eap_peer_otp_register(void);
- ret = eap_peer_otp_register();
- }
-#endif /* EAP_OTP */
-
-#ifdef EAP_SIM
- if (ret == 0) {
- int eap_peer_sim_register(void);
- ret = eap_peer_sim_register();
- }
-#endif /* EAP_SIM */
-
-#ifdef EAP_LEAP
- if (ret == 0) {
- int eap_peer_leap_register(void);
- ret = eap_peer_leap_register();
- }
-#endif /* EAP_LEAP */
-
-#ifdef EAP_PSK
- if (ret == 0) {
- int eap_peer_psk_register(void);
- ret = eap_peer_psk_register();
- }
-#endif /* EAP_PSK */
-
-#ifdef EAP_AKA
- if (ret == 0) {
- int eap_peer_aka_register(void);
- ret = eap_peer_aka_register();
- }
-#endif /* EAP_AKA */
-
-#ifdef EAP_AKA_PRIME
- if (ret == 0) {
- int eap_peer_aka_prime_register(void);
- ret = eap_peer_aka_prime_register();
- }
-#endif /* EAP_AKA_PRIME */
-
-#ifdef EAP_FAST
- if (ret == 0) {
- int eap_peer_fast_register(void);
- ret = eap_peer_fast_register();
- }
-#endif /* EAP_FAST */
-
-#ifdef EAP_PAX
- if (ret == 0) {
- int eap_peer_pax_register(void);
- ret = eap_peer_pax_register();
- }
-#endif /* EAP_PAX */
-
-#ifdef EAP_SAKE
- if (ret == 0) {
- int eap_peer_sake_register(void);
- ret = eap_peer_sake_register();
- }
-#endif /* EAP_SAKE */
-
-#ifdef EAP_GPSK
- if (ret == 0) {
- int eap_peer_gpsk_register(void);
- ret = eap_peer_gpsk_register();
- }
-#endif /* EAP_GPSK */
-
-#ifdef EAP_WSC
- if (ret == 0) {
- int eap_peer_wsc_register(void);
- ret = eap_peer_wsc_register();
- }
-#endif /* EAP_WSC */
-
-#ifdef EAP_IKEV2
- if (ret == 0) {
- int eap_peer_ikev2_register(void);
- ret = eap_peer_ikev2_register();
- }
-#endif /* EAP_IKEV2 */
-
-#ifdef EAP_VENDOR_TEST
- if (ret == 0) {
- int eap_peer_vendor_test_register(void);
- ret = eap_peer_vendor_test_register();
- }
-#endif /* EAP_VENDOR_TEST */
-
-#ifdef EAP_TNC
- if (ret == 0) {
- int eap_peer_tnc_register(void);
- ret = eap_peer_tnc_register();
- }
-#endif /* EAP_TNC */
-
- return ret;
-}
-
-
-/**
* eap_peer_unregister_methods - Unregister EAP peer methods
*
* This function is called at program termination to unregister all EAP peer
diff --git a/contrib/wpa/src/eap_peer/eap_methods.h b/contrib/wpa/src/eap_peer/eap_methods.h
index 9fd9b51..384c61b 100644
--- a/contrib/wpa/src/eap_peer/eap_methods.h
+++ b/contrib/wpa/src/eap_peer/eap_methods.h
@@ -32,7 +32,6 @@ EapType eap_peer_get_type(const char *name, int *vendor);
const char * eap_get_name(int vendor, EapType type);
size_t eap_get_names(char *buf, size_t buflen);
char ** eap_get_names_as_string_array(size_t *num);
-int eap_peer_register_methods(void);
void eap_peer_unregister_methods(void);
#else /* IEEE8021X_EAPOL */
@@ -89,4 +88,26 @@ static inline int eap_peer_method_unload(struct eap_method *method)
#endif /* CONFIG_DYNAMIC_EAP_METHODS */
+/* EAP peer method registration calls for statically linked in methods */
+int eap_peer_md5_register(void);
+int eap_peer_tls_register(void);
+int eap_peer_mschapv2_register(void);
+int eap_peer_peap_register(void);
+int eap_peer_ttls_register(void);
+int eap_peer_gtc_register(void);
+int eap_peer_otp_register(void);
+int eap_peer_sim_register(void);
+int eap_peer_leap_register(void);
+int eap_peer_psk_register(void);
+int eap_peer_aka_register(void);
+int eap_peer_aka_prime_register(void);
+int eap_peer_fast_register(void);
+int eap_peer_pax_register(void);
+int eap_peer_sake_register(void);
+int eap_peer_gpsk_register(void);
+int eap_peer_wsc_register(void);
+int eap_peer_ikev2_register(void);
+int eap_peer_vendor_test_register(void);
+int eap_peer_tnc_register(void);
+
#endif /* EAP_METHODS_H */
diff --git a/contrib/wpa/src/eap_peer/eap_mschapv2.c b/contrib/wpa/src/eap_peer/eap_mschapv2.c
index b0c3ab7..cd410d9 100644
--- a/contrib/wpa/src/eap_peer/eap_mschapv2.c
+++ b/contrib/wpa/src/eap_peer/eap_mschapv2.c
@@ -22,11 +22,11 @@
#include "includes.h"
#include "common.h"
+#include "crypto/ms_funcs.h"
+#include "common/wpa_ctrl.h"
+#include "mschapv2.h"
#include "eap_i.h"
#include "eap_config.h"
-#include "ms_funcs.h"
-#include "wpa_ctrl.h"
-#include "mschapv2.h"
#ifdef _MSC_VER
@@ -209,10 +209,15 @@ static struct wpabuf * eap_mschapv2_challenge_reply(
"in Phase 1");
auth_challenge = data->auth_challenge;
}
- mschapv2_derive_response(identity, identity_len, password,
- password_len, pwhash, auth_challenge,
- peer_challenge, r->nt_response,
- data->auth_response, data->master_key);
+ if (mschapv2_derive_response(identity, identity_len, password,
+ password_len, pwhash, auth_challenge,
+ peer_challenge, r->nt_response,
+ data->auth_response, data->master_key)) {
+ wpa_printf(MSG_ERROR, "EAP-MSCHAPV2: Failed to derive "
+ "response");
+ wpabuf_free(resp);
+ return NULL;
+ }
data->auth_response_valid = 1;
data->master_key_valid = 1;
diff --git a/contrib/wpa/src/eap_peer/eap_pax.c b/contrib/wpa/src/eap_peer/eap_pax.c
index afd56dd..2e04831 100644
--- a/contrib/wpa/src/eap_peer/eap_pax.c
+++ b/contrib/wpa/src/eap_peer/eap_pax.c
@@ -15,10 +15,8 @@
#include "includes.h"
#include "common.h"
-#include "eap_peer/eap_i.h"
#include "eap_common/eap_pax_common.h"
-#include "sha1.h"
-#include "crypto.h"
+#include "eap_i.h"
/*
* Note: only PAX_STD subprotocol is currently supported
diff --git a/contrib/wpa/src/eap_peer/eap_peap.c b/contrib/wpa/src/eap_peer/eap_peap.c
index 894fc63..2b72084 100644
--- a/contrib/wpa/src/eap_peer/eap_peap.c
+++ b/contrib/wpa/src/eap_peer/eap_peap.c
@@ -16,12 +16,12 @@
#include "common.h"
#include "crypto/sha1.h"
+#include "crypto/tls.h"
+#include "eap_common/eap_tlv_common.h"
+#include "eap_common/eap_peap_common.h"
#include "eap_i.h"
#include "eap_tls_common.h"
#include "eap_config.h"
-#include "tls.h"
-#include "eap_common/eap_tlv_common.h"
-#include "eap_common/eap_peap_common.h"
#include "tncc.h"
@@ -1048,10 +1048,10 @@ static struct wpabuf * eap_peap_process(struct eap_sm *sm, void *priv,
if (flags & EAP_TLS_FLAGS_START) {
wpa_printf(MSG_DEBUG, "EAP-PEAP: Start (server ver=%d, own "
- "ver=%d)", flags & EAP_PEAP_VERSION_MASK,
+ "ver=%d)", flags & EAP_TLS_VERSION_MASK,
data->peap_version);
- if ((flags & EAP_PEAP_VERSION_MASK) < data->peap_version)
- data->peap_version = flags & EAP_PEAP_VERSION_MASK;
+ if ((flags & EAP_TLS_VERSION_MASK) < data->peap_version)
+ data->peap_version = flags & EAP_TLS_VERSION_MASK;
if (data->force_peap_version >= 0 &&
data->force_peap_version != data->peap_version) {
wpa_printf(MSG_WARNING, "EAP-PEAP: Failed to select "
diff --git a/contrib/wpa/src/eap_peer/eap_psk.c b/contrib/wpa/src/eap_peer/eap_psk.c
index 1ce63566..ccf871e 100644
--- a/contrib/wpa/src/eap_peer/eap_psk.c
+++ b/contrib/wpa/src/eap_peer/eap_psk.c
@@ -18,9 +18,9 @@
#include "includes.h"
#include "common.h"
-#include "eap_peer/eap_i.h"
-#include "aes_wrap.h"
+#include "crypto/aes_wrap.h"
#include "eap_common/eap_psk_common.h"
+#include "eap_i.h"
struct eap_psk_data {
diff --git a/contrib/wpa/src/eap_peer/eap_sim.c b/contrib/wpa/src/eap_peer/eap_sim.c
index 5e30d1f..3d8afb2 100644
--- a/contrib/wpa/src/eap_peer/eap_sim.c
+++ b/contrib/wpa/src/eap_peer/eap_sim.c
@@ -15,13 +15,11 @@
#include "includes.h"
#include "common.h"
+#include "pcsc_funcs.h"
+#include "crypto/milenage.h"
#include "eap_peer/eap_i.h"
#include "eap_config.h"
-#include "pcsc_funcs.h"
#include "eap_common/eap_sim_common.h"
-#ifdef CONFIG_SIM_SIMULATOR
-#include "hlr_auc_gw/milenage.h"
-#endif /* CONFIG_SIM_SIMULATOR */
struct eap_sim_data {
diff --git a/contrib/wpa/src/eap_peer/eap_tls.c b/contrib/wpa/src/eap_peer/eap_tls.c
index 31344a9..20b2212 100644
--- a/contrib/wpa/src/eap_peer/eap_tls.c
+++ b/contrib/wpa/src/eap_peer/eap_tls.c
@@ -15,10 +15,10 @@
#include "includes.h"
#include "common.h"
+#include "crypto/tls.h"
#include "eap_i.h"
#include "eap_tls_common.h"
#include "eap_config.h"
-#include "tls.h"
static void eap_tls_deinit(struct eap_sm *sm, void *priv);
diff --git a/contrib/wpa/src/eap_peer/eap_tls_common.c b/contrib/wpa/src/eap_peer/eap_tls_common.c
index 186feaa..7bd50f6 100644
--- a/contrib/wpa/src/eap_peer/eap_tls_common.c
+++ b/contrib/wpa/src/eap_peer/eap_tls_common.c
@@ -1,6 +1,6 @@
/*
* EAP peer: EAP-TLS/PEAP/TTLS/FAST common functions
- * Copyright (c) 2004-2008, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -15,11 +15,11 @@
#include "includes.h"
#include "common.h"
+#include "crypto/sha1.h"
+#include "crypto/tls.h"
#include "eap_i.h"
#include "eap_tls_common.h"
#include "eap_config.h"
-#include "sha1.h"
-#include "tls.h"
static int eap_tls_check_blob(struct eap_sm *sm, const char **name,
@@ -169,10 +169,14 @@ static int eap_tls_init_connection(struct eap_sm *sm,
config->pin = NULL;
eap_sm_request_pin(sm);
sm->ignore = TRUE;
+ tls_connection_deinit(sm->ssl_ctx, data->conn);
+ data->conn = NULL;
return -1;
} else if (res) {
wpa_printf(MSG_INFO, "TLS: Failed to set TLS connection "
"parameters");
+ tls_connection_deinit(sm->ssl_ctx, data->conn);
+ data->conn = NULL;
return -1;
}
@@ -310,27 +314,29 @@ fail:
* eap_peer_tls_reassemble_fragment - Reassemble a received fragment
* @data: Data for TLS processing
* @in_data: Next incoming TLS segment
- * @in_len: Length of in_data
* Returns: 0 on success, 1 if more data is needed for the full message, or
* -1 on error
*/
static int eap_peer_tls_reassemble_fragment(struct eap_ssl_data *data,
- const u8 *in_data, size_t in_len)
+ const struct wpabuf *in_data)
{
- u8 *buf;
+ size_t tls_in_len, in_len;
+
+ tls_in_len = data->tls_in ? wpabuf_len(data->tls_in) : 0;
+ in_len = in_data ? wpabuf_len(in_data) : 0;
- if (data->tls_in_len + in_len == 0) {
+ if (tls_in_len + in_len == 0) {
/* No message data received?! */
wpa_printf(MSG_WARNING, "SSL: Invalid reassembly state: "
"tls_in_left=%lu tls_in_len=%lu in_len=%lu",
(unsigned long) data->tls_in_left,
- (unsigned long) data->tls_in_len,
+ (unsigned long) tls_in_len,
(unsigned long) in_len);
eap_peer_tls_reset_input(data);
return -1;
}
- if (data->tls_in_len + in_len > 65536) {
+ if (tls_in_len + in_len > 65536) {
/*
* Limit length to avoid rogue servers from causing large
* memory allocations.
@@ -349,16 +355,13 @@ static int eap_peer_tls_reassemble_fragment(struct eap_ssl_data *data,
return -1;
}
- buf = os_realloc(data->tls_in, data->tls_in_len + in_len);
- if (buf == NULL) {
+ if (wpabuf_resize(&data->tls_in, in_len) < 0) {
wpa_printf(MSG_INFO, "SSL: Could not allocate memory for TLS "
"data");
eap_peer_tls_reset_input(data);
return -1;
}
- os_memcpy(buf + data->tls_in_len, in_data, in_len);
- data->tls_in = buf;
- data->tls_in_len += in_len;
+ wpabuf_put_buf(data->tls_in, in_data);
data->tls_in_left -= in_len;
if (data->tls_in_left > 0) {
@@ -375,8 +378,6 @@ static int eap_peer_tls_reassemble_fragment(struct eap_ssl_data *data,
* eap_peer_tls_data_reassemble - Reassemble TLS data
* @data: Data for TLS processing
* @in_data: Next incoming TLS segment
- * @in_len: Length of in_data
- * @out_len: Variable for returning length of the reassembled message
* @need_more_input: Variable for returning whether more input data is needed
* to reassemble this TLS packet
* Returns: Pointer to output data, %NULL on error or when more data is needed
@@ -385,16 +386,15 @@ static int eap_peer_tls_reassemble_fragment(struct eap_ssl_data *data,
* This function reassembles TLS fragments. Caller must not free the returned
* data buffer since an internal pointer to it is maintained.
*/
-const u8 * eap_peer_tls_data_reassemble(
- struct eap_ssl_data *data, const u8 *in_data, size_t in_len,
- size_t *out_len, int *need_more_input)
+static const struct wpabuf * eap_peer_tls_data_reassemble(
+ struct eap_ssl_data *data, const struct wpabuf *in_data,
+ int *need_more_input)
{
*need_more_input = 0;
- if (data->tls_in_left > in_len || data->tls_in) {
+ if (data->tls_in_left > wpabuf_len(in_data) || data->tls_in) {
/* Message has fragments */
- int res = eap_peer_tls_reassemble_fragment(data, in_data,
- in_len);
+ int res = eap_peer_tls_reassemble_fragment(data, in_data);
if (res) {
if (res == 1)
*need_more_input = 1;
@@ -405,14 +405,11 @@ const u8 * eap_peer_tls_data_reassemble(
} else {
/* No fragments in this message, so just make a copy of it. */
data->tls_in_left = 0;
- data->tls_in = os_malloc(in_len ? in_len : 1);
+ data->tls_in = wpabuf_dup(in_data);
if (data->tls_in == NULL)
return NULL;
- os_memcpy(data->tls_in, in_data, in_len);
- data->tls_in_len = in_len;
}
- *out_len = data->tls_in_len;
return data->tls_in;
}
@@ -431,14 +428,13 @@ static int eap_tls_process_input(struct eap_sm *sm, struct eap_ssl_data *data,
const u8 *in_data, size_t in_len,
struct wpabuf **out_data)
{
- const u8 *msg;
- size_t msg_len;
+ const struct wpabuf *msg;
int need_more_input;
- u8 *appl_data;
- size_t appl_data_len;
+ struct wpabuf *appl_data;
+ struct wpabuf buf;
- msg = eap_peer_tls_data_reassemble(data, in_data, in_len,
- &msg_len, &need_more_input);
+ wpabuf_set(&buf, in_data, in_len);
+ msg = eap_peer_tls_data_reassemble(data, &buf, &need_more_input);
if (msg == NULL)
return need_more_input ? 1 : -1;
@@ -447,31 +443,25 @@ static int eap_tls_process_input(struct eap_sm *sm, struct eap_ssl_data *data,
/* This should not happen.. */
wpa_printf(MSG_INFO, "SSL: eap_tls_process_input - pending "
"tls_out data even though tls_out_len = 0");
- os_free(data->tls_out);
+ wpabuf_free(data->tls_out);
WPA_ASSERT(data->tls_out == NULL);
}
appl_data = NULL;
data->tls_out = tls_connection_handshake(sm->ssl_ctx, data->conn,
- msg, msg_len,
- &data->tls_out_len,
- &appl_data, &appl_data_len);
+ msg, &appl_data);
eap_peer_tls_reset_input(data);
if (appl_data &&
tls_connection_established(sm->ssl_ctx, data->conn) &&
!tls_connection_get_failed(sm->ssl_ctx, data->conn)) {
- wpa_hexdump_key(MSG_MSGDUMP, "SSL: Application data",
- appl_data, appl_data_len);
- *out_data = wpabuf_alloc_ext_data(appl_data, appl_data_len);
- if (*out_data == NULL) {
- os_free(appl_data);
- return -1;
- }
+ wpa_hexdump_buf_key(MSG_MSGDUMP, "SSL: Application data",
+ appl_data);
+ *out_data = appl_data;
return 2;
}
- os_free(appl_data);
+ wpabuf_free(appl_data);
return 0;
}
@@ -494,11 +484,14 @@ static int eap_tls_process_output(struct eap_ssl_data *data, EapType eap_type,
size_t len;
u8 *flags;
int more_fragments, length_included;
-
- len = data->tls_out_len - data->tls_out_pos;
+
+ if (data->tls_out == NULL)
+ return -1;
+ len = wpabuf_len(data->tls_out) - data->tls_out_pos;
wpa_printf(MSG_DEBUG, "SSL: %lu bytes left to be sent out (of total "
"%lu bytes)",
- (unsigned long) len, (unsigned long) data->tls_out_len);
+ (unsigned long) len,
+ (unsigned long) wpabuf_len(data->tls_out));
/*
* Limit outgoing message to the configured maximum size. Fragment
@@ -513,7 +506,7 @@ static int eap_tls_process_output(struct eap_ssl_data *data, EapType eap_type,
more_fragments = 0;
length_included = data->tls_out_pos == 0 &&
- (data->tls_out_len > data->tls_out_limit ||
+ (wpabuf_len(data->tls_out) > data->tls_out_limit ||
data->include_tls_length);
if (!length_included &&
eap_type == EAP_TYPE_PEAP && peap_version == 0 &&
@@ -539,10 +532,12 @@ static int eap_tls_process_output(struct eap_ssl_data *data, EapType eap_type,
*flags |= EAP_TLS_FLAGS_MORE_FRAGMENTS;
if (length_included) {
*flags |= EAP_TLS_FLAGS_LENGTH_INCLUDED;
- wpabuf_put_be32(*out_data, data->tls_out_len);
+ wpabuf_put_be32(*out_data, wpabuf_len(data->tls_out));
}
- wpabuf_put_data(*out_data, &data->tls_out[data->tls_out_pos], len);
+ wpabuf_put_data(*out_data,
+ wpabuf_head_u8(data->tls_out) + data->tls_out_pos,
+ len);
data->tls_out_pos += len;
if (!more_fragments)
@@ -590,13 +585,13 @@ int eap_peer_tls_process_helper(struct eap_sm *sm, struct eap_ssl_data *data,
*out_data = NULL;
- if (data->tls_out_len > 0 && in_len > 0) {
+ if (data->tls_out && wpabuf_len(data->tls_out) > 0 && in_len > 0) {
wpa_printf(MSG_DEBUG, "SSL: Received non-ACK when output "
"fragments are waiting to be sent out");
return -1;
}
- if (data->tls_out_len == 0) {
+ if (data->tls_out == NULL || wpabuf_len(data->tls_out) == 0) {
/*
* No more data to send out - expect to receive more data from
* the AS.
@@ -635,14 +630,14 @@ int eap_peer_tls_process_helper(struct eap_sm *sm, struct eap_ssl_data *data,
/* TODO: clean pin if engine used? */
}
- if (data->tls_out_len == 0) {
+ if (data->tls_out == NULL || wpabuf_len(data->tls_out) == 0) {
/*
* TLS negotiation should now be complete since all other cases
* needing more data should have been caught above based on
* the TLS Message Length field.
*/
wpa_printf(MSG_DEBUG, "SSL: No data to be sent out");
- os_free(data->tls_out);
+ wpabuf_free(data->tls_out);
data->tls_out = NULL;
return 1;
}
@@ -794,9 +789,8 @@ const u8 * eap_peer_tls_process_init(struct eap_sm *sm,
if (data->tls_in_left == 0) {
data->tls_in_total = tls_msg_len;
data->tls_in_left = tls_msg_len;
- os_free(data->tls_in);
+ wpabuf_free(data->tls_in);
data->tls_in = NULL;
- data->tls_in_len = 0;
}
pos += 4;
left -= 4;
@@ -821,8 +815,8 @@ const u8 * eap_peer_tls_process_init(struct eap_sm *sm,
*/
void eap_peer_tls_reset_input(struct eap_ssl_data *data)
{
- data->tls_in_left = data->tls_in_total = data->tls_in_len = 0;
- os_free(data->tls_in);
+ data->tls_in_left = data->tls_in_total = 0;
+ wpabuf_free(data->tls_in);
data->tls_in = NULL;
}
@@ -836,9 +830,8 @@ void eap_peer_tls_reset_input(struct eap_ssl_data *data)
*/
void eap_peer_tls_reset_output(struct eap_ssl_data *data)
{
- data->tls_out_len = 0;
data->tls_out_pos = 0;
- os_free(data->tls_out);
+ wpabuf_free(data->tls_out);
data->tls_out = NULL;
}
@@ -855,44 +848,19 @@ int eap_peer_tls_decrypt(struct eap_sm *sm, struct eap_ssl_data *data,
const struct wpabuf *in_data,
struct wpabuf **in_decrypted)
{
- int res;
- const u8 *msg;
- size_t msg_len, buf_len;
+ const struct wpabuf *msg;
int need_more_input;
- msg = eap_peer_tls_data_reassemble(data, wpabuf_head(in_data),
- wpabuf_len(in_data), &msg_len,
- &need_more_input);
+ msg = eap_peer_tls_data_reassemble(data, in_data, &need_more_input);
if (msg == NULL)
return need_more_input ? 1 : -1;
- buf_len = wpabuf_len(in_data);
- if (data->tls_in_total > buf_len)
- buf_len = data->tls_in_total;
- /*
- * Even though we try to disable TLS compression, it is possible that
- * this cannot be done with all TLS libraries. Add extra buffer space
- * to handle the possibility of the decrypted data being longer than
- * input data.
- */
- buf_len += 500;
- buf_len *= 3;
- *in_decrypted = wpabuf_alloc(buf_len ? buf_len : 1);
- if (*in_decrypted == NULL) {
- eap_peer_tls_reset_input(data);
- wpa_printf(MSG_WARNING, "SSL: Failed to allocate memory for "
- "decryption");
- return -1;
- }
-
- res = tls_connection_decrypt(sm->ssl_ctx, data->conn, msg, msg_len,
- wpabuf_mhead(*in_decrypted), buf_len);
+ *in_decrypted = tls_connection_decrypt(sm->ssl_ctx, data->conn, msg);
eap_peer_tls_reset_input(data);
- if (res < 0) {
+ if (*in_decrypted == NULL) {
wpa_printf(MSG_INFO, "SSL: Failed to decrypt Phase 2 data");
return -1;
}
- wpabuf_put(*in_decrypted, res);
return 0;
}
@@ -913,29 +881,17 @@ int eap_peer_tls_encrypt(struct eap_sm *sm, struct eap_ssl_data *data,
const struct wpabuf *in_data,
struct wpabuf **out_data)
{
- int res;
- size_t len;
-
if (in_data) {
eap_peer_tls_reset_output(data);
- len = wpabuf_len(in_data) + 300;
- data->tls_out = os_malloc(len);
- if (data->tls_out == NULL)
- return -1;
-
- res = tls_connection_encrypt(sm->ssl_ctx, data->conn,
- wpabuf_head(in_data),
- wpabuf_len(in_data),
- data->tls_out, len);
- if (res < 0) {
+ data->tls_out = tls_connection_encrypt(sm->ssl_ctx, data->conn,
+ in_data);
+ if (data->tls_out == NULL) {
wpa_printf(MSG_INFO, "SSL: Failed to encrypt Phase 2 "
"data (in_len=%lu)",
(unsigned long) wpabuf_len(in_data));
eap_peer_tls_reset_output(data);
return -1;
}
-
- data->tls_out_len = res;
}
return eap_tls_process_output(data, eap_type, peap_version, id, 0,
diff --git a/contrib/wpa/src/eap_peer/eap_tls_common.h b/contrib/wpa/src/eap_peer/eap_tls_common.h
index 2c87427..e9e0998 100644
--- a/contrib/wpa/src/eap_peer/eap_tls_common.h
+++ b/contrib/wpa/src/eap_peer/eap_tls_common.h
@@ -1,6 +1,6 @@
/*
* EAP peer: EAP-TLS/PEAP/TTLS/FAST common functions
- * Copyright (c) 2004-2006, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -27,12 +27,7 @@ struct eap_ssl_data {
/**
* tls_out - TLS message to be sent out in fragments
*/
- u8 *tls_out;
-
- /**
- * tls_out_len - Total length of the outgoing TLS message
- */
- size_t tls_out_len;
+ struct wpabuf *tls_out;
/**
* tls_out_pos - The current position in the outgoing TLS message
@@ -47,12 +42,7 @@ struct eap_ssl_data {
/**
* tls_in - Received TLS message buffer for re-assembly
*/
- u8 *tls_in;
-
- /**
- * tls_in_len - Number of bytes of the received TLS message in tls_in
- */
- size_t tls_in_len;
+ struct wpabuf *tls_in;
/**
* tls_in_left - Number of remaining bytes in the incoming TLS message
@@ -81,7 +71,7 @@ struct eap_ssl_data {
int tls_ia;
/**
- * eap - Pointer to EAP state machine allocated with eap_peer_sm_init()
+ * eap - EAP state machine allocated with eap_peer_sm_init()
*/
struct eap_sm *eap;
};
@@ -91,7 +81,7 @@ struct eap_ssl_data {
#define EAP_TLS_FLAGS_LENGTH_INCLUDED 0x80
#define EAP_TLS_FLAGS_MORE_FRAGMENTS 0x40
#define EAP_TLS_FLAGS_START 0x20
-#define EAP_PEAP_VERSION_MASK 0x07
+#define EAP_TLS_VERSION_MASK 0x07
/* could be up to 128 bytes, but only the first 64 bytes are used */
#define EAP_TLS_KEY_LEN 64
@@ -102,9 +92,6 @@ int eap_peer_tls_ssl_init(struct eap_sm *sm, struct eap_ssl_data *data,
void eap_peer_tls_ssl_deinit(struct eap_sm *sm, struct eap_ssl_data *data);
u8 * eap_peer_tls_derive_key(struct eap_sm *sm, struct eap_ssl_data *data,
const char *label, size_t len);
-const u8 * eap_peer_tls_data_reassemble(
- struct eap_ssl_data *data, const u8 *in_data, size_t in_len,
- size_t *out_len, int *need_more_input);
int eap_peer_tls_process_helper(struct eap_sm *sm, struct eap_ssl_data *data,
EapType eap_type, int peap_version,
u8 id, const u8 *in_data, size_t in_len,
diff --git a/contrib/wpa/src/eap_peer/eap_tnc.c b/contrib/wpa/src/eap_peer/eap_tnc.c
index c560015..6c95f72 100644
--- a/contrib/wpa/src/eap_peer/eap_tnc.c
+++ b/contrib/wpa/src/eap_peer/eap_tnc.c
@@ -73,12 +73,13 @@ static struct wpabuf * eap_tnc_build_frag_ack(u8 id, u8 code)
{
struct wpabuf *msg;
- msg = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_TNC, 0, code, id);
+ msg = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_TNC, 1, code, id);
if (msg == NULL) {
wpa_printf(MSG_ERROR, "EAP-TNC: Failed to allocate memory "
"for fragment ack");
return NULL;
}
+ wpabuf_put_u8(msg, EAP_TNC_VERSION); /* Flags */
wpa_printf(MSG_DEBUG, "EAP-TNC: Send fragment ack");
@@ -262,7 +263,7 @@ static struct wpabuf * eap_tnc_process(struct eap_sm *sm, void *priv,
"Message Length %u", flags, message_length);
if (data->state == WAIT_FRAG_ACK) {
- if (len != 0) {
+ if (len > 1) {
wpa_printf(MSG_DEBUG, "EAP-TNC: Unexpected payload in "
"WAIT_FRAG_ACK state");
ret->ignore = TRUE;
diff --git a/contrib/wpa/src/eap_peer/eap_ttls.c b/contrib/wpa/src/eap_peer/eap_ttls.c
index 0851f8b..2573780 100644
--- a/contrib/wpa/src/eap_peer/eap_ttls.c
+++ b/contrib/wpa/src/eap_peer/eap_ttls.c
@@ -15,15 +15,15 @@
#include "includes.h"
#include "common.h"
-#include "eap_peer/eap_i.h"
-#include "eap_peer/eap_tls_common.h"
-#include "eap_peer/eap_config.h"
-#include "ms_funcs.h"
-#include "sha1.h"
+#include "crypto/ms_funcs.h"
+#include "crypto/sha1.h"
+#include "crypto/tls.h"
#include "eap_common/chap.h"
-#include "tls.h"
-#include "mschapv2.h"
#include "eap_common/eap_ttls.h"
+#include "mschapv2.h"
+#include "eap_i.h"
+#include "eap_tls_common.h"
+#include "eap_config.h"
/* Maximum supported TTLS version
@@ -691,10 +691,15 @@ static int eap_ttls_phase2_request_mschapv2(struct eap_sm *sm,
pos += EAP_TTLS_MSCHAPV2_CHALLENGE_LEN;
os_memset(pos, 0, 8); /* Reserved, must be zero */
pos += 8;
- mschapv2_derive_response(identity, identity_len, password,
- password_len, pwhash, challenge,
- peer_challenge, pos, data->auth_response,
- data->master_key);
+ if (mschapv2_derive_response(identity, identity_len, password,
+ password_len, pwhash, challenge,
+ peer_challenge, pos, data->auth_response,
+ data->master_key)) {
+ wpabuf_free(msg);
+ wpa_printf(MSG_ERROR, "EAP-TTLS/MSCHAPV2: Failed to derive "
+ "response");
+ return -1;
+ }
data->auth_response_valid = 1;
eap_ttlsv1_permute_inner(sm, data);
@@ -1026,27 +1031,25 @@ static int eap_ttls_phase2_request(struct eap_sm *sm,
static struct wpabuf * eap_ttls_build_phase_finished(
struct eap_sm *sm, struct eap_ttls_data *data, int id, int final)
{
- int len;
- struct wpabuf *req;
- u8 *pos;
- const int max_len = 300;
+ struct wpabuf *req, *buf;
- req = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_TTLS, 1 + max_len,
- EAP_CODE_RESPONSE, id);
- if (req == NULL)
+ buf = tls_connection_ia_send_phase_finished(sm->ssl_ctx,
+ data->ssl.conn,
+ final);
+ if (buf == NULL)
return NULL;
- wpabuf_put_u8(req, data->ttls_version);
-
- pos = wpabuf_put(req, 0);
- len = tls_connection_ia_send_phase_finished(sm->ssl_ctx,
- data->ssl.conn,
- final, pos, max_len);
- if (len < 0) {
- wpabuf_free(req);
+ req = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_TTLS,
+ 1 + wpabuf_len(buf),
+ EAP_CODE_RESPONSE, id);
+ if (req == NULL) {
+ wpabuf_free(buf);
return NULL;
}
- wpabuf_put(req, len);
+
+ wpabuf_put_u8(req, data->ttls_version);
+ wpabuf_put_buf(req, buf);
+ wpabuf_free(buf);
eap_update_len(req);
return req;
@@ -1666,10 +1669,10 @@ static int eap_ttls_process_start(struct eap_sm *sm,
struct eap_peer_config *config = eap_get_config(sm);
wpa_printf(MSG_DEBUG, "EAP-TTLS: Start (server ver=%d, own ver=%d)",
- flags & EAP_PEAP_VERSION_MASK, data->ttls_version);
+ flags & EAP_TLS_VERSION_MASK, data->ttls_version);
#if EAP_TTLS_VERSION > 0
- if ((flags & EAP_PEAP_VERSION_MASK) < data->ttls_version)
- data->ttls_version = flags & EAP_PEAP_VERSION_MASK;
+ if ((flags & EAP_TLS_VERSION_MASK) < data->ttls_version)
+ data->ttls_version = flags & EAP_TLS_VERSION_MASK;
if (data->force_ttls_version >= 0 &&
data->force_ttls_version != data->ttls_version) {
wpa_printf(MSG_WARNING, "EAP-TTLS: Failed to select "
diff --git a/contrib/wpa/src/eap_peer/eap_wsc.c b/contrib/wpa/src/eap_peer/eap_wsc.c
index 7c8ad2f..8317f72 100644
--- a/contrib/wpa/src/eap_peer/eap_wsc.c
+++ b/contrib/wpa/src/eap_peer/eap_wsc.c
@@ -1,6 +1,6 @@
/*
* EAP-WSC peer for Wi-Fi Protected Setup
- * Copyright (c) 2007-2008, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2007-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -65,6 +65,72 @@ static void eap_wsc_state(struct eap_wsc_data *data, int state)
}
+static int eap_wsc_new_ap_settings(struct wps_credential *cred,
+ const char *params)
+{
+ const char *pos, *end;
+ size_t len;
+
+ os_memset(cred, 0, sizeof(*cred));
+
+ pos = os_strstr(params, "new_ssid=");
+ if (pos == NULL)
+ return 0;
+ pos += 9;
+ end = os_strchr(pos, ' ');
+ if (end == NULL)
+ len = os_strlen(pos);
+ else
+ len = end - pos;
+ if ((len & 1) || len > 2 * sizeof(cred->ssid) ||
+ hexstr2bin(pos, cred->ssid, len / 2))
+ return -1;
+ cred->ssid_len = len / 2;
+
+ pos = os_strstr(params, "new_auth=");
+ if (pos == NULL)
+ return -1;
+ if (os_strncmp(pos + 9, "OPEN", 4) == 0)
+ cred->auth_type = WPS_AUTH_OPEN;
+ else if (os_strncmp(pos + 9, "WPAPSK", 6) == 0)
+ cred->auth_type = WPS_AUTH_WPAPSK;
+ else if (os_strncmp(pos + 9, "WPA2PSK", 7) == 0)
+ cred->auth_type = WPS_AUTH_WPA2PSK;
+ else
+ return -1;
+
+ pos = os_strstr(params, "new_encr=");
+ if (pos == NULL)
+ return -1;
+ if (os_strncmp(pos + 9, "NONE", 4) == 0)
+ cred->encr_type = WPS_ENCR_NONE;
+ else if (os_strncmp(pos + 9, "WEP", 3) == 0)
+ cred->encr_type = WPS_ENCR_WEP;
+ else if (os_strncmp(pos + 9, "TKIP", 4) == 0)
+ cred->encr_type = WPS_ENCR_TKIP;
+ else if (os_strncmp(pos + 9, "CCMP", 4) == 0)
+ cred->encr_type = WPS_ENCR_AES;
+ else
+ return -1;
+
+ pos = os_strstr(params, "new_key=");
+ if (pos == NULL)
+ return 0;
+ pos += 8;
+ end = os_strchr(pos, ' ');
+ if (end == NULL)
+ len = os_strlen(pos);
+ else
+ len = end - pos;
+ if ((len & 1) || len > 2 * sizeof(cred->key) ||
+ hexstr2bin(pos, cred->key, len / 2))
+ return -1;
+ cred->key_len = len / 2;
+
+ return 1;
+}
+
+
static void * eap_wsc_init(struct eap_sm *sm)
{
struct eap_wsc_data *data;
@@ -75,6 +141,8 @@ static void * eap_wsc_init(struct eap_sm *sm)
const char *pos;
const char *phase1;
struct wps_context *wps;
+ struct wps_credential new_ap_settings;
+ int res;
wps = sm->wps;
if (wps == NULL) {
@@ -135,6 +203,17 @@ static void * eap_wsc_init(struct eap_sm *sm)
return NULL;
}
+ res = eap_wsc_new_ap_settings(&new_ap_settings, phase1);
+ if (res < 0) {
+ os_free(data);
+ return NULL;
+ }
+ if (res == 1) {
+ wpa_printf(MSG_DEBUG, "EAP-WSC: Provide new AP settings for "
+ "WPS");
+ cfg.new_ap_settings = &new_ap_settings;
+ }
+
data->wps = wps_init(&cfg);
if (data->wps == NULL) {
os_free(data);
@@ -147,6 +226,10 @@ static void * eap_wsc_init(struct eap_sm *sm)
cfg.pin, cfg.pin_len, 0);
}
+ /* Use reduced client timeout for WPS to avoid long wait */
+ if (sm->ClientTimeout > 30)
+ sm->ClientTimeout = 30;
+
return data;
}
@@ -302,6 +385,7 @@ static struct wpabuf * eap_wsc_process(struct eap_sm *sm, void *priv,
u16 message_length = 0;
enum wps_process_res res;
struct wpabuf tmpbuf;
+ struct wpabuf *r;
pos = eap_hdr_validate(EAP_VENDOR_WFA, EAP_VENDOR_TYPE_WSC, reqData,
&len);
@@ -427,7 +511,13 @@ send_msg:
}
eap_wsc_state(data, MESG);
- return eap_wsc_build_msg(data, ret, id);
+ r = eap_wsc_build_msg(data, ret, id);
+ if (data->state == FAIL && ret->methodState == METHOD_DONE) {
+ /* Use reduced client timeout for WPS to avoid long wait */
+ if (sm->ClientTimeout > 2)
+ sm->ClientTimeout = 2;
+ }
+ return r;
}
diff --git a/contrib/wpa/src/eap_peer/ikev2.c b/contrib/wpa/src/eap_peer/ikev2.c
index 9172e1f..309a331 100644
--- a/contrib/wpa/src/eap_peer/ikev2.c
+++ b/contrib/wpa/src/eap_peer/ikev2.c
@@ -15,7 +15,7 @@
#include "includes.h"
#include "common.h"
-#include "dh_groups.h"
+#include "crypto/dh_groups.h"
#include "ikev2.h"
diff --git a/contrib/wpa/src/eap_peer/mschapv2.c b/contrib/wpa/src/eap_peer/mschapv2.c
index 01c22d8..b8fb075 100644
--- a/contrib/wpa/src/eap_peer/mschapv2.c
+++ b/contrib/wpa/src/eap_peer/mschapv2.c
@@ -15,7 +15,7 @@
#include "includes.h"
#include "common.h"
-#include "ms_funcs.h"
+#include "crypto/ms_funcs.h"
#include "mschapv2.h"
const u8 * mschapv2_remove_domain(const u8 *username, size_t *len)
@@ -39,13 +39,13 @@ const u8 * mschapv2_remove_domain(const u8 *username, size_t *len)
}
-void mschapv2_derive_response(const u8 *identity, size_t identity_len,
- const u8 *password, size_t password_len,
- int pwhash,
- const u8 *auth_challenge,
- const u8 *peer_challenge,
- u8 *nt_response, u8 *auth_response,
- u8 *master_key)
+int mschapv2_derive_response(const u8 *identity, size_t identity_len,
+ const u8 *password, size_t password_len,
+ int pwhash,
+ const u8 *auth_challenge,
+ const u8 *peer_challenge,
+ u8 *nt_response, u8 *auth_response,
+ u8 *master_key)
{
const u8 *username;
size_t username_len;
@@ -93,14 +93,18 @@ void mschapv2_derive_response(const u8 *identity, size_t identity_len,
/* Generate master_key here since we have the needed data available. */
if (pwhash) {
- hash_nt_password_hash(password, password_hash_hash);
+ if (hash_nt_password_hash(password, password_hash_hash))
+ return -1;
} else {
- nt_password_hash(password, password_len, password_hash);
- hash_nt_password_hash(password_hash, password_hash_hash);
+ if (nt_password_hash(password, password_len, password_hash) ||
+ hash_nt_password_hash(password_hash, password_hash_hash))
+ return -1;
}
get_master_key(password_hash_hash, nt_response, master_key);
wpa_hexdump_key(MSG_DEBUG, "MSCHAPV2: Master Key",
master_key, MSCHAPV2_MASTER_KEY_LEN);
+
+ return 0;
}
diff --git a/contrib/wpa/src/eap_peer/mschapv2.h b/contrib/wpa/src/eap_peer/mschapv2.h
index c7c36f7..90dad31 100644
--- a/contrib/wpa/src/eap_peer/mschapv2.h
+++ b/contrib/wpa/src/eap_peer/mschapv2.h
@@ -21,13 +21,13 @@
#define MSCHAPV2_MASTER_KEY_LEN 16
const u8 * mschapv2_remove_domain(const u8 *username, size_t *len);
-void mschapv2_derive_response(const u8 *username, size_t username_len,
- const u8 *password, size_t password_len,
- int pwhash,
- const u8 *auth_challenge,
- const u8 *peer_challenge,
- u8 *nt_response, u8 *auth_response,
- u8 *master_key);
+int mschapv2_derive_response(const u8 *username, size_t username_len,
+ const u8 *password, size_t password_len,
+ int pwhash,
+ const u8 *auth_challenge,
+ const u8 *peer_challenge,
+ u8 *nt_response, u8 *auth_response,
+ u8 *master_key);
int mschapv2_verify_auth_response(const u8 *auth_response,
const u8 *buf, size_t buf_len);
diff --git a/contrib/wpa/src/eap_server/Makefile b/contrib/wpa/src/eap_server/Makefile
index cffba62..9c41962 100644
--- a/contrib/wpa/src/eap_server/Makefile
+++ b/contrib/wpa/src/eap_server/Makefile
@@ -2,7 +2,6 @@ all:
@echo Nothing to be made.
clean:
- for d in $(SUBDIRS); do make -C $$d clean; done
rm -f *~ *.o *.d
install:
diff --git a/contrib/wpa/src/eap_server/eap.h b/contrib/wpa/src/eap_server/eap.h
index 6a20da4..92400a5 100644
--- a/contrib/wpa/src/eap_server/eap.h
+++ b/contrib/wpa/src/eap_server/eap.h
@@ -15,7 +15,7 @@
#ifndef EAP_H
#define EAP_H
-#include "defs.h"
+#include "common/defs.h"
#include "eap_common/eap_defs.h"
#include "eap_server/eap_methods.h"
#include "wpabuf.h"
@@ -91,6 +91,7 @@ struct eapol_callbacks {
struct eap_config {
void *ssl_ctx;
+ void *msg_ctx;
void *eap_sim_db_priv;
Boolean backend_auth;
int eap_server;
@@ -105,6 +106,7 @@ struct eap_config {
int tnc;
struct wps_context *wps;
const struct wpabuf *assoc_wps_ie;
+ const u8 *peer_addr;
};
diff --git a/contrib/wpa/src/eap_server/eap_i.h b/contrib/wpa/src/eap_server/eap_i.h
index d52b86f..4269a8c 100644
--- a/contrib/wpa/src/eap_server/eap_i.h
+++ b/contrib/wpa/src/eap_server/eap_i.h
@@ -185,6 +185,8 @@ struct eap_sm {
struct wpabuf *assoc_wps_ie;
Boolean start_reauth;
+
+ u8 peer_addr[ETH_ALEN];
};
int eap_user_get(struct eap_sm *sm, const u8 *identity, size_t identity_len,
diff --git a/contrib/wpa/src/eap_server/eap_methods.h b/contrib/wpa/src/eap_server/eap_methods.h
index 0fd5390..5d4d92c 100644
--- a/contrib/wpa/src/eap_server/eap_methods.h
+++ b/contrib/wpa/src/eap_server/eap_methods.h
@@ -1,6 +1,6 @@
/*
- * hostapd / EAP method registration
- * Copyright (c) 2004-2006, Jouni Malinen <j@w1.fi>
+ * EAP server method registration
+ * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -12,8 +12,10 @@
* See README and COPYING for more details.
*/
-#ifndef EAP_METHODS_H
-#define EAP_METHODS_H
+#ifndef EAP_SERVER_METHODS_H
+#define EAP_SERVER_METHODS_H
+
+#include "eap_common/eap_defs.h"
const struct eap_method * eap_server_get_eap_method(int vendor,
EapType method);
@@ -23,7 +25,29 @@ void eap_server_method_free(struct eap_method *method);
int eap_server_method_register(struct eap_method *method);
EapType eap_server_get_type(const char *name, int *vendor);
-int eap_server_register_methods(void);
void eap_server_unregister_methods(void);
+const char * eap_server_get_name(int vendor, EapType type);
+
+/* EAP server method registration calls for statically linked in methods */
+int eap_server_identity_register(void);
+int eap_server_md5_register(void);
+int eap_server_tls_register(void);
+int eap_server_mschapv2_register(void);
+int eap_server_peap_register(void);
+int eap_server_tlv_register(void);
+int eap_server_gtc_register(void);
+int eap_server_ttls_register(void);
+int eap_server_sim_register(void);
+int eap_server_aka_register(void);
+int eap_server_aka_prime_register(void);
+int eap_server_pax_register(void);
+int eap_server_psk_register(void);
+int eap_server_sake_register(void);
+int eap_server_gpsk_register(void);
+int eap_server_vendor_test_register(void);
+int eap_server_fast_register(void);
+int eap_server_wsc_register(void);
+int eap_server_ikev2_register(void);
+int eap_server_tnc_register(void);
-#endif /* EAP_METHODS_H */
+#endif /* EAP_SERVER_METHODS_H */
diff --git a/contrib/wpa/src/eap_server/eap.c b/contrib/wpa/src/eap_server/eap_server.c
index 897adc3..fdc26f9 100644
--- a/contrib/wpa/src/eap_server/eap.c
+++ b/contrib/wpa/src/eap_server/eap_server.c
@@ -23,6 +23,7 @@
#include "common.h"
#include "eap_i.h"
#include "state_machine.h"
+#include "common/wpa_ctrl.h"
#define STATE_MACHINE_DATA struct eap_sm
#define STATE_MACHINE_DEBUG_PREFIX "EAP"
@@ -167,6 +168,9 @@ SM_STATE(EAP, INITIALIZE)
}
sm->num_rounds = 0;
sm->method_pending = METHOD_PENDING_NONE;
+
+ wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_STARTED
+ MACSTR, MAC2STR(sm->peer_addr));
}
@@ -196,6 +200,9 @@ SM_STATE(EAP, PICK_UP_METHOD)
sm->currentMethod = EAP_TYPE_NONE;
}
}
+
+ wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_PROPOSED_METHOD
+ "method=%u", sm->currentMethod);
}
@@ -350,6 +357,9 @@ SM_STATE(EAP, PROPOSE_METHOD)
sm->methodState = METHOD_CONTINUE;
else
sm->methodState = METHOD_PROPOSED;
+
+ wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_PROPOSED_METHOD
+ "vendor=%u method=%u", vendor, sm->currentMethod);
}
@@ -410,6 +420,9 @@ SM_STATE(EAP, FAILURE)
wpabuf_free(sm->lastReqData);
sm->lastReqData = NULL;
sm->eap_if.eapFail = TRUE;
+
+ wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_FAILURE
+ MACSTR, MAC2STR(sm->peer_addr));
}
@@ -424,6 +437,9 @@ SM_STATE(EAP, SUCCESS)
if (sm->eap_if.eapKeyData)
sm->eap_if.eapKeyAvailable = TRUE;
sm->eap_if.eapSuccess = TRUE;
+
+ wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_SUCCESS
+ MACSTR, MAC2STR(sm->peer_addr));
}
@@ -1210,6 +1226,7 @@ struct eap_sm * eap_server_sm_init(void *eapol_ctx,
sm->eapol_cb = eapol_cb;
sm->MaxRetrans = 5; /* RFC 3748: max 3-5 retransmissions suggested */
sm->ssl_ctx = conf->ssl_ctx;
+ sm->msg_ctx = conf->msg_ctx;
sm->eap_sim_db_priv = conf->eap_sim_db_priv;
sm->backend_auth = conf->backend_auth;
sm->eap_server = conf->eap_server;
@@ -1238,6 +1255,8 @@ struct eap_sm * eap_server_sm_init(void *eapol_ctx,
sm->wps = conf->wps;
if (conf->assoc_wps_ie)
sm->assoc_wps_ie = wpabuf_dup(conf->assoc_wps_ie);
+ if (conf->peer_addr)
+ os_memcpy(sm->peer_addr, conf->peer_addr, ETH_ALEN);
wpa_printf(MSG_DEBUG, "EAP: Server state machine created");
diff --git a/contrib/wpa/src/eap_server/eap_aka.c b/contrib/wpa/src/eap_server/eap_server_aka.c
index aad52fd..4e7db48 100644
--- a/contrib/wpa/src/eap_server/eap_aka.c
+++ b/contrib/wpa/src/eap_server/eap_server_aka.c
@@ -15,12 +15,11 @@
#include "includes.h"
#include "common.h"
-#include "eap_server/eap_i.h"
+#include "crypto/sha256.h"
+#include "crypto/crypto.h"
#include "eap_common/eap_sim_common.h"
+#include "eap_server/eap_i.h"
#include "eap_server/eap_sim_db.h"
-#include "sha1.h"
-#include "sha256.h"
-#include "crypto.h"
struct eap_aka_data {
@@ -116,7 +115,7 @@ static void * eap_aka_init(struct eap_sm *sm)
}
-#ifdef EAP_AKA_PRIME
+#ifdef EAP_SERVER_AKA_PRIME
static void * eap_aka_prime_init(struct eap_sm *sm)
{
struct eap_aka_data *data;
@@ -148,7 +147,7 @@ static void * eap_aka_prime_init(struct eap_sm *sm)
return data;
}
-#endif /* EAP_AKA_PRIME */
+#endif /* EAP_SERVER_AKA_PRIME */
static void eap_aka_reset(struct eap_sm *sm, void *priv)
@@ -399,7 +398,7 @@ static struct wpabuf * eap_aka_build_challenge(struct eap_sm *sm,
eap_sim_msg_add(msg, EAP_SIM_AT_RESULT_IND, 0, NULL, 0);
}
-#ifdef EAP_AKA_PRIME
+#ifdef EAP_SERVER_AKA_PRIME
if (data->eap_method == EAP_TYPE_AKA) {
u16 flags = 0;
int i;
@@ -426,7 +425,7 @@ static struct wpabuf * eap_aka_build_challenge(struct eap_sm *sm,
flags |= EAP_AKA_BIDDING_FLAG_D;
eap_sim_msg_add(msg, EAP_SIM_AT_BIDDING, flags, NULL, 0);
}
-#endif /* EAP_AKA_PRIME */
+#endif /* EAP_SERVER_AKA_PRIME */
wpa_printf(MSG_DEBUG, " AT_MAC");
eap_sim_msg_add_mac(msg, EAP_SIM_AT_MAC);
@@ -701,7 +700,7 @@ static void eap_aka_determine_identity(struct eap_sm *sm,
return;
}
-#ifdef EAP_AKA_PRIME
+#ifdef EAP_SERVER_AKA_PRIME
if (data->eap_method == EAP_TYPE_AKA_PRIME) {
/* Note: AUTN = (SQN ^ AK) || AMF || MAC which gives us the
* needed 6-octet SQN ^AK for CK',IK' derivation */
@@ -710,7 +709,7 @@ static void eap_aka_determine_identity(struct eap_sm *sm,
data->network_name,
data->network_name_len);
}
-#endif /* EAP_AKA_PRIME */
+#endif /* EAP_SERVER_AKA_PRIME */
data->reauth = NULL;
data->counter = 0; /* reset re-auth counter since this is full auth */
@@ -807,7 +806,7 @@ static void eap_aka_process_challenge(struct eap_sm *sm,
wpa_printf(MSG_DEBUG, "EAP-AKA: Processing Challenge");
-#ifdef EAP_AKA_PRIME
+#ifdef EAP_SERVER_AKA_PRIME
#if 0
/* KDF negotiation; to be enabled only after more than one KDF is
* supported */
@@ -830,7 +829,7 @@ static void eap_aka_process_challenge(struct eap_sm *sm,
return;
}
#endif
-#endif /* EAP_AKA_PRIME */
+#endif /* EAP_SERVER_AKA_PRIME */
if (attr->checkcode &&
eap_aka_verify_checkcode(data, attr->checkcode,
@@ -892,7 +891,7 @@ static void eap_aka_process_challenge(struct eap_sm *sm,
}
if (data->next_reauth_id) {
if (data->eap_method == EAP_TYPE_AKA_PRIME) {
-#ifdef EAP_AKA_PRIME
+#ifdef EAP_SERVER_AKA_PRIME
eap_sim_db_add_reauth_prime(sm->eap_sim_db_priv,
identity,
identity_len,
@@ -900,7 +899,7 @@ static void eap_aka_process_challenge(struct eap_sm *sm,
data->counter + 1,
data->k_encr, data->k_aut,
data->k_re);
-#endif /* EAP_AKA_PRIME */
+#endif /* EAP_SERVER_AKA_PRIME */
} else {
eap_sim_db_add_reauth(sm->eap_sim_db_priv, identity,
identity_len,
@@ -1031,7 +1030,7 @@ static void eap_aka_process_reauth(struct eap_sm *sm,
}
if (data->next_reauth_id) {
if (data->eap_method == EAP_TYPE_AKA_PRIME) {
-#ifdef EAP_AKA_PRIME
+#ifdef EAP_SERVER_AKA_PRIME
eap_sim_db_add_reauth_prime(sm->eap_sim_db_priv,
identity,
identity_len,
@@ -1039,7 +1038,7 @@ static void eap_aka_process_reauth(struct eap_sm *sm,
data->counter + 1,
data->k_encr, data->k_aut,
data->k_re);
-#endif /* EAP_AKA_PRIME */
+#endif /* EAP_SERVER_AKA_PRIME */
} else {
eap_sim_db_add_reauth(sm->eap_sim_db_priv, identity,
identity_len,
@@ -1247,7 +1246,7 @@ int eap_server_aka_register(void)
}
-#ifdef EAP_AKA_PRIME
+#ifdef EAP_SERVER_AKA_PRIME
int eap_server_aka_prime_register(void)
{
struct eap_method *eap;
@@ -1275,4 +1274,4 @@ int eap_server_aka_prime_register(void)
return ret;
}
-#endif /* EAP_AKA_PRIME */
+#endif /* EAP_SERVER_AKA_PRIME */
diff --git a/contrib/wpa/src/eap_server/eap_fast.c b/contrib/wpa/src/eap_server/eap_server_fast.c
index c06f396..39beb33 100644
--- a/contrib/wpa/src/eap_server/eap_fast.c
+++ b/contrib/wpa/src/eap_server/eap_server_fast.c
@@ -15,13 +15,13 @@
#include "includes.h"
#include "common.h"
-#include "aes_wrap.h"
-#include "sha1.h"
-#include "eap_i.h"
-#include "eap_tls_common.h"
-#include "tls.h"
+#include "crypto/aes_wrap.h"
+#include "crypto/sha1.h"
+#include "crypto/tls.h"
#include "eap_common/eap_tlv_common.h"
#include "eap_common/eap_fast_common.h"
+#include "eap_i.h"
+#include "eap_tls_common.h"
static void eap_fast_reset(struct eap_sm *sm, void *priv);
@@ -791,6 +791,11 @@ static struct wpabuf * eap_fast_build_pac(struct eap_sm *sm,
/* Note: headers may be misaligned after A-ID */
+ if (sm->identity) {
+ eap_fast_put_tlv(buf, PAC_TYPE_I_ID, sm->identity,
+ sm->identity_len);
+ }
+
/* A-ID-Info (inside PAC-Info) */
eap_fast_put_tlv(buf, PAC_TYPE_A_ID_INFO, data->srv_id_info,
srv_id_info_len);
@@ -816,29 +821,28 @@ static int eap_fast_encrypt_phase2(struct eap_sm *sm,
wpa_hexdump_buf_key(MSG_DEBUG, "EAP-FAST: Encrypting Phase 2 TLVs",
plain);
- encr = eap_server_tls_encrypt(sm, &data->ssl, wpabuf_mhead(plain),
- wpabuf_len(plain));
+ encr = eap_server_tls_encrypt(sm, &data->ssl, plain);
wpabuf_free(plain);
- if (data->ssl.out_buf && piggyback) {
+ if (data->ssl.tls_out && piggyback) {
wpa_printf(MSG_DEBUG, "EAP-FAST: Piggyback Phase 2 data "
"(len=%d) with last Phase 1 Message (len=%d "
"used=%d)",
(int) wpabuf_len(encr),
- (int) wpabuf_len(data->ssl.out_buf),
- (int) data->ssl.out_used);
- if (wpabuf_resize(&data->ssl.out_buf, wpabuf_len(encr)) < 0) {
+ (int) wpabuf_len(data->ssl.tls_out),
+ (int) data->ssl.tls_out_pos);
+ if (wpabuf_resize(&data->ssl.tls_out, wpabuf_len(encr)) < 0) {
wpa_printf(MSG_WARNING, "EAP-FAST: Failed to resize "
"output buffer");
wpabuf_free(encr);
return -1;
}
- wpabuf_put_buf(data->ssl.out_buf, encr);
+ wpabuf_put_buf(data->ssl.tls_out, encr);
wpabuf_free(encr);
} else {
- wpabuf_free(data->ssl.out_buf);
- data->ssl.out_used = 0;
- data->ssl.out_buf = encr;
+ wpabuf_free(data->ssl.tls_out);
+ data->ssl.tls_out_pos = 0;
+ data->ssl.tls_out = encr;
}
return 0;
@@ -987,7 +991,7 @@ static void eap_fast_process_phase2_response(struct eap_sm *sm,
left = in_len - sizeof(*hdr);
wpa_hexdump(MSG_DEBUG, "EAP-FAST: Phase2 type Nak'ed; "
"allowed types", pos + 1, left - 1);
-#ifdef EAP_TNC
+#ifdef EAP_SERVER_TNC
if (m && m->vendor == EAP_VENDOR_IETF &&
m->method == EAP_TYPE_TNC) {
wpa_printf(MSG_DEBUG, "EAP-FAST: Peer Nak'ed required "
@@ -996,7 +1000,7 @@ static void eap_fast_process_phase2_response(struct eap_sm *sm,
eap_fast_phase2_init(sm, data, next_type);
return;
}
-#endif /* EAP_TNC */
+#endif /* EAP_SERVER_TNC */
eap_sm_process_nak(sm, pos + 1, left - 1);
if (sm->user && sm->user_eap_method_index < EAP_MAX_METHODS &&
sm->user->methods[sm->user_eap_method_index].method !=
@@ -1064,13 +1068,13 @@ static void eap_fast_process_phase2_response(struct eap_sm *sm,
eap_fast_state(data, CRYPTO_BINDING);
data->eap_seq++;
next_type = EAP_TYPE_NONE;
-#ifdef EAP_TNC
+#ifdef EAP_SERVER_TNC
if (sm->tnc && !data->tnc_started) {
wpa_printf(MSG_DEBUG, "EAP-FAST: Initialize TNC");
next_type = EAP_TYPE_TNC;
data->tnc_started = 1;
}
-#endif /* EAP_TNC */
+#endif /* EAP_SERVER_TNC */
break;
case FAILURE:
break;
@@ -1121,7 +1125,7 @@ static void eap_fast_process_phase2_eap(struct eap_sm *sm,
}
-static int eap_fast_parse_tlvs(u8 *data, size_t data_len,
+static int eap_fast_parse_tlvs(struct wpabuf *data,
struct eap_fast_tlv_parse *tlv)
{
int mandatory, tlv_type, len, res;
@@ -1129,8 +1133,8 @@ static int eap_fast_parse_tlvs(u8 *data, size_t data_len,
os_memset(tlv, 0, sizeof(*tlv));
- pos = data;
- end = data + data_len;
+ pos = wpabuf_mhead(data);
+ end = pos + wpabuf_len(data);
while (pos + 4 < end) {
mandatory = pos[0] & 0x80;
tlv_type = WPA_GET_BE16(pos) & 0x3fff;
@@ -1241,12 +1245,12 @@ static int eap_fast_pac_type(u8 *pac, size_t len, u16 type)
static void eap_fast_process_phase2_tlvs(struct eap_sm *sm,
struct eap_fast_data *data,
- u8 *in_data, size_t in_len)
+ struct wpabuf *in_data)
{
struct eap_fast_tlv_parse tlv;
int check_crypto_binding = data->state == CRYPTO_BINDING;
- if (eap_fast_parse_tlvs(in_data, in_len, &tlv) < 0) {
+ if (eap_fast_parse_tlvs(in_data, &tlv) < 0) {
wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to parse received "
"Phase 2 TLVs");
return;
@@ -1373,70 +1377,44 @@ static void eap_fast_process_phase2(struct eap_sm *sm,
struct eap_fast_data *data,
struct wpabuf *in_buf)
{
- u8 *in_decrypted;
- int len_decrypted;
- size_t buf_len;
- u8 *in_data;
- size_t in_len;
-
- in_data = wpabuf_mhead(in_buf);
- in_len = wpabuf_len(in_buf);
+ struct wpabuf *in_decrypted;
wpa_printf(MSG_DEBUG, "EAP-FAST: Received %lu bytes encrypted data for"
- " Phase 2", (unsigned long) in_len);
+ " Phase 2", (unsigned long) wpabuf_len(in_buf));
if (data->pending_phase2_resp) {
wpa_printf(MSG_DEBUG, "EAP-PEAP: Pending Phase 2 response - "
"skip decryption and use old data");
- eap_fast_process_phase2_tlvs(
- sm, data, wpabuf_mhead(data->pending_phase2_resp),
- wpabuf_len(data->pending_phase2_resp));
+ eap_fast_process_phase2_tlvs(sm, data,
+ data->pending_phase2_resp);
wpabuf_free(data->pending_phase2_resp);
data->pending_phase2_resp = NULL;
return;
}
- buf_len = in_len;
- /*
- * Even though we try to disable TLS compression, it is possible that
- * this cannot be done with all TLS libraries. Add extra buffer space
- * to handle the possibility of the decrypted data being longer than
- * input data.
- */
- buf_len += 500;
- buf_len *= 3;
- in_decrypted = os_malloc(buf_len);
+ in_decrypted = tls_connection_decrypt(sm->ssl_ctx, data->ssl.conn,
+ in_buf);
if (in_decrypted == NULL) {
- wpa_printf(MSG_WARNING, "EAP-FAST: Failed to allocate memory "
- "for decryption");
- return;
- }
-
- len_decrypted = tls_connection_decrypt(sm->ssl_ctx, data->ssl.conn,
- in_data, in_len,
- in_decrypted, buf_len);
- if (len_decrypted < 0) {
wpa_printf(MSG_INFO, "EAP-FAST: Failed to decrypt Phase 2 "
"data");
- os_free(in_decrypted);
eap_fast_state(data, FAILURE);
return;
}
- wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: Decrypted Phase 2 TLVs",
- in_decrypted, len_decrypted);
+ wpa_hexdump_buf_key(MSG_DEBUG, "EAP-FAST: Decrypted Phase 2 TLVs",
+ in_decrypted);
- eap_fast_process_phase2_tlvs(sm, data, in_decrypted, len_decrypted);
+ eap_fast_process_phase2_tlvs(sm, data, in_decrypted);
if (sm->method_pending == METHOD_PENDING_WAIT) {
wpa_printf(MSG_DEBUG, "EAP-FAST: Phase2 method is in "
"pending wait state - save decrypted response");
wpabuf_free(data->pending_phase2_resp);
- data->pending_phase2_resp = wpabuf_alloc_copy(in_decrypted,
- len_decrypted);
+ data->pending_phase2_resp = in_decrypted;
+ return;
}
- os_free(in_decrypted);
+ wpabuf_free(in_decrypted);
}
@@ -1475,7 +1453,7 @@ static int eap_fast_process_phase1(struct eap_sm *sm,
}
if (!tls_connection_established(sm->ssl_ctx, data->ssl.conn) ||
- wpabuf_len(data->ssl.out_buf) > 0)
+ wpabuf_len(data->ssl.tls_out) > 0)
return 1;
/*
@@ -1541,7 +1519,7 @@ static void eap_fast_process_msg(struct eap_sm *sm, void *priv,
case PHASE2_METHOD:
case CRYPTO_BINDING:
case REQUEST_PAC:
- eap_fast_process_phase2(sm, data, data->ssl.in_buf);
+ eap_fast_process_phase2(sm, data, data->ssl.tls_in);
break;
default:
wpa_printf(MSG_DEBUG, "EAP-FAST: Unexpected state %d in %s",
diff --git a/contrib/wpa/src/eap_server/eap_gpsk.c b/contrib/wpa/src/eap_server/eap_server_gpsk.c
index d0c7559..d0c7559 100644
--- a/contrib/wpa/src/eap_server/eap_gpsk.c
+++ b/contrib/wpa/src/eap_server/eap_server_gpsk.c
diff --git a/contrib/wpa/src/eap_server/eap_gtc.c b/contrib/wpa/src/eap_server/eap_server_gtc.c
index 97e328b..79b9696 100644
--- a/contrib/wpa/src/eap_server/eap_gtc.c
+++ b/contrib/wpa/src/eap_server/eap_server_gtc.c
@@ -33,14 +33,14 @@ static void * eap_gtc_init(struct eap_sm *sm)
return NULL;
data->state = CONTINUE;
-#ifdef EAP_FAST
+#ifdef EAP_SERVER_FAST
if (sm->m && sm->m->vendor == EAP_VENDOR_IETF &&
sm->m->method == EAP_TYPE_FAST) {
wpa_printf(MSG_DEBUG, "EAP-GTC: EAP-FAST tunnel - use prefix "
"with challenge/response");
data->prefix = 1;
}
-#endif /* EAP_FAST */
+#endif /* EAP_SERVER_FAST */
return data;
}
@@ -109,7 +109,7 @@ static void eap_gtc_process(struct eap_sm *sm, void *priv,
wpa_hexdump_ascii_key(MSG_MSGDUMP, "EAP-GTC: Response", pos, rlen);
-#ifdef EAP_FAST
+#ifdef EAP_SERVER_FAST
if (data->prefix) {
const u8 *pos2, *end;
/* "RESPONSE=<user>\0<password>" */
@@ -170,7 +170,7 @@ static void eap_gtc_process(struct eap_sm *sm, void *priv,
"EAP-GTC: Response password",
pos, rlen);
}
-#endif /* EAP_FAST */
+#endif /* EAP_SERVER_FAST */
if (sm->user == NULL || sm->user->password == NULL ||
sm->user->password_hash) {
diff --git a/contrib/wpa/src/eap_server/eap_identity.c b/contrib/wpa/src/eap_server/eap_server_identity.c
index cd8da2a..cd8da2a 100644
--- a/contrib/wpa/src/eap_server/eap_identity.c
+++ b/contrib/wpa/src/eap_server/eap_server_identity.c
diff --git a/contrib/wpa/src/eap_server/eap_ikev2.c b/contrib/wpa/src/eap_server/eap_server_ikev2.c
index 06074ee..06074ee 100644
--- a/contrib/wpa/src/eap_server/eap_ikev2.c
+++ b/contrib/wpa/src/eap_server/eap_server_ikev2.c
diff --git a/contrib/wpa/src/eap_server/eap_md5.c b/contrib/wpa/src/eap_server/eap_server_md5.c
index dee2dc5..dee2dc5 100644
--- a/contrib/wpa/src/eap_server/eap_md5.c
+++ b/contrib/wpa/src/eap_server/eap_server_md5.c
diff --git a/contrib/wpa/src/eap_server/eap_methods.c b/contrib/wpa/src/eap_server/eap_server_methods.c
index 4092d67..900a5dd 100644
--- a/contrib/wpa/src/eap_server/eap_methods.c
+++ b/contrib/wpa/src/eap_server/eap_server_methods.c
@@ -1,6 +1,6 @@
/*
- * hostapd / EAP method registration
- * Copyright (c) 2004-2006, Jouni Malinen <j@w1.fi>
+ * EAP server method registration
+ * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -134,159 +134,6 @@ int eap_server_method_register(struct eap_method *method)
/**
- * eap_server_register_methods - Register statically linked EAP server methods
- * Returns: 0 on success, -1 on failure
- *
- * This function is called at program initialization to register all EAP server
- * methods that were linked in statically.
- */
-int eap_server_register_methods(void)
-{
- int ret = 0;
-
- if (ret == 0) {
- int eap_server_identity_register(void);
- ret = eap_server_identity_register();
- }
-
-#ifdef EAP_MD5
- if (ret == 0) {
- int eap_server_md5_register(void);
- ret = eap_server_md5_register();
- }
-#endif /* EAP_MD5 */
-
-#ifdef EAP_TLS
- if (ret == 0) {
- int eap_server_tls_register(void);
- ret = eap_server_tls_register();
- }
-#endif /* EAP_TLS */
-
-#ifdef EAP_MSCHAPv2
- if (ret == 0) {
- int eap_server_mschapv2_register(void);
- ret = eap_server_mschapv2_register();
- }
-#endif /* EAP_MSCHAPv2 */
-
-#ifdef EAP_PEAP
- if (ret == 0) {
- int eap_server_peap_register(void);
- ret = eap_server_peap_register();
- }
-#endif /* EAP_PEAP */
-
-#ifdef EAP_TLV
- if (ret == 0) {
- int eap_server_tlv_register(void);
- ret = eap_server_tlv_register();
- }
-#endif /* EAP_TLV */
-
-#ifdef EAP_GTC
- if (ret == 0) {
- int eap_server_gtc_register(void);
- ret = eap_server_gtc_register();
- }
-#endif /* EAP_GTC */
-
-#ifdef EAP_TTLS
- if (ret == 0) {
- int eap_server_ttls_register(void);
- ret = eap_server_ttls_register();
- }
-#endif /* EAP_TTLS */
-
-#ifdef EAP_SIM
- if (ret == 0) {
- int eap_server_sim_register(void);
- ret = eap_server_sim_register();
- }
-#endif /* EAP_SIM */
-
-#ifdef EAP_AKA
- if (ret == 0) {
- int eap_server_aka_register(void);
- ret = eap_server_aka_register();
- }
-#endif /* EAP_AKA */
-
-#ifdef EAP_AKA_PRIME
- if (ret == 0) {
- int eap_server_aka_prime_register(void);
- ret = eap_server_aka_prime_register();
- }
-#endif /* EAP_AKA_PRIME */
-
-#ifdef EAP_PAX
- if (ret == 0) {
- int eap_server_pax_register(void);
- ret = eap_server_pax_register();
- }
-#endif /* EAP_PAX */
-
-#ifdef EAP_PSK
- if (ret == 0) {
- int eap_server_psk_register(void);
- ret = eap_server_psk_register();
- }
-#endif /* EAP_PSK */
-
-#ifdef EAP_SAKE
- if (ret == 0) {
- int eap_server_sake_register(void);
- ret = eap_server_sake_register();
- }
-#endif /* EAP_SAKE */
-
-#ifdef EAP_GPSK
- if (ret == 0) {
- int eap_server_gpsk_register(void);
- ret = eap_server_gpsk_register();
- }
-#endif /* EAP_GPSK */
-
-#ifdef EAP_VENDOR_TEST
- if (ret == 0) {
- int eap_server_vendor_test_register(void);
- ret = eap_server_vendor_test_register();
- }
-#endif /* EAP_VENDOR_TEST */
-
-#ifdef EAP_FAST
- if (ret == 0) {
- int eap_server_fast_register(void);
- ret = eap_server_fast_register();
- }
-#endif /* EAP_FAST */
-
-#ifdef EAP_WSC
- if (ret == 0) {
- int eap_server_wsc_register(void);
- ret = eap_server_wsc_register();
- }
-#endif /* EAP_WSC */
-
-#ifdef EAP_IKEV2
- if (ret == 0) {
- int eap_server_ikev2_register(void);
- ret = eap_server_ikev2_register();
- }
-#endif /* EAP_IKEV2 */
-
-#ifdef EAP_TNC
- if (ret == 0) {
- int eap_server_tnc_register(void);
- ret = eap_server_tnc_register();
- }
-#endif /* EAP_TNC */
-
- return ret;
-}
-
-
-/**
* eap_server_unregister_methods - Unregister EAP server methods
*
* This function is called at program termination to unregister all EAP server
@@ -306,3 +153,23 @@ void eap_server_unregister_methods(void)
eap_server_method_free(m);
}
}
+
+
+/**
+ * eap_server_get_name - Get EAP method name for the given EAP type
+ * @vendor: EAP Vendor-Id (0 = IETF)
+ * @type: EAP method type
+ * Returns: EAP method name, e.g., TLS, or %NULL if not found
+ *
+ * This function maps EAP type numbers into EAP type names based on the list of
+ * EAP methods included in the build.
+ */
+const char * eap_server_get_name(int vendor, EapType type)
+{
+ struct eap_method *m;
+ for (m = eap_methods; m; m = m->next) {
+ if (m->vendor == vendor && m->method == type)
+ return m->name;
+ }
+ return NULL;
+}
diff --git a/contrib/wpa/src/eap_server/eap_mschapv2.c b/contrib/wpa/src/eap_server/eap_server_mschapv2.c
index 20e7ade..39d1c6e 100644
--- a/contrib/wpa/src/eap_server/eap_mschapv2.c
+++ b/contrib/wpa/src/eap_server/eap_server_mschapv2.c
@@ -15,8 +15,8 @@
#include "includes.h"
#include "common.h"
+#include "crypto/ms_funcs.h"
#include "eap_i.h"
-#include "ms_funcs.h"
struct eap_mschapv2_hdr {
@@ -295,6 +295,7 @@ static void eap_mschapv2_process_response(struct eap_sm *sm,
u8 expected[24];
const u8 *username, *user;
size_t username_len, user_len;
+ int res;
pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_MSCHAPV2, respData,
&len);
@@ -372,17 +373,22 @@ static void eap_mschapv2_process_response(struct eap_sm *sm,
username, username_len);
if (sm->user->password_hash) {
- generate_nt_response_pwhash(data->auth_challenge,
- peer_challenge,
- username, username_len,
- sm->user->password,
- expected);
+ res = generate_nt_response_pwhash(data->auth_challenge,
+ peer_challenge,
+ username, username_len,
+ sm->user->password,
+ expected);
} else {
- generate_nt_response(data->auth_challenge, peer_challenge,
- username, username_len,
- sm->user->password,
- sm->user->password_len,
- expected);
+ res = generate_nt_response(data->auth_challenge,
+ peer_challenge,
+ username, username_len,
+ sm->user->password,
+ sm->user->password_len,
+ expected);
+ }
+ if (res) {
+ data->state = FAILURE;
+ return;
}
if (os_memcmp(nt_response, expected, 24) == 0) {
diff --git a/contrib/wpa/src/eap_server/eap_pax.c b/contrib/wpa/src/eap_server/eap_server_pax.c
index 1dc023b..1dc023b 100644
--- a/contrib/wpa/src/eap_server/eap_pax.c
+++ b/contrib/wpa/src/eap_server/eap_server_pax.c
diff --git a/contrib/wpa/src/eap_server/eap_peap.c b/contrib/wpa/src/eap_server/eap_server_peap.c
index 4b2d5a5..674ecd2 100644
--- a/contrib/wpa/src/eap_server/eap_peap.c
+++ b/contrib/wpa/src/eap_server/eap_server_peap.c
@@ -15,12 +15,12 @@
#include "includes.h"
#include "common.h"
-#include "sha1.h"
+#include "crypto/sha1.h"
+#include "crypto/tls.h"
#include "eap_i.h"
#include "eap_tls_common.h"
#include "eap_common/eap_tlv_common.h"
#include "eap_common/eap_peap_common.h"
-#include "tls.h"
#include "tncs.h"
@@ -235,7 +235,7 @@ static struct wpabuf * eap_peap_build_phase2_req(struct eap_sm *sm,
struct eap_peap_data *data,
u8 id)
{
- struct wpabuf *buf, *encr_req;
+ struct wpabuf *buf, *encr_req, msgbuf;
const u8 *req;
size_t req_len;
@@ -260,19 +260,20 @@ static struct wpabuf * eap_peap_build_phase2_req(struct eap_sm *sm,
req_len -= sizeof(struct eap_hdr);
}
- encr_req = eap_server_tls_encrypt(sm, &data->ssl, req, req_len);
+ wpabuf_set(&msgbuf, req, req_len);
+ encr_req = eap_server_tls_encrypt(sm, &data->ssl, &msgbuf);
wpabuf_free(buf);
return encr_req;
}
-#ifdef EAP_TNC
+#ifdef EAP_SERVER_TNC
static struct wpabuf * eap_peap_build_phase2_soh(struct eap_sm *sm,
struct eap_peap_data *data,
u8 id)
{
- struct wpabuf *buf1, *buf, *encr_req;
+ struct wpabuf *buf1, *buf, *encr_req, msgbuf;
const u8 *req;
size_t req_len;
@@ -297,13 +298,14 @@ static struct wpabuf * eap_peap_build_phase2_soh(struct eap_sm *sm,
req += sizeof(struct eap_hdr);
req_len -= sizeof(struct eap_hdr);
+ wpabuf_set(&msgbuf, req, req_len);
- encr_req = eap_server_tls_encrypt(sm, &data->ssl, req, req_len);
+ encr_req = eap_server_tls_encrypt(sm, &data->ssl, &msgbuf);
wpabuf_free(buf);
return encr_req;
}
-#endif /* EAP_TNC */
+#endif /* EAP_SERVER_TNC */
static void eap_peap_get_isk(struct eap_peap_data *data,
@@ -370,17 +372,17 @@ static struct wpabuf * eap_peap_build_phase2_tlv(struct eap_sm *sm,
u8 id)
{
struct wpabuf *buf, *encr_req;
- size_t len;
+ size_t mlen;
- len = 6; /* Result TLV */
+ mlen = 6; /* Result TLV */
if (data->crypto_binding != NO_BINDING)
- len += 60; /* Cryptobinding TLV */
-#ifdef EAP_TNC
+ mlen += 60; /* Cryptobinding TLV */
+#ifdef EAP_SERVER_TNC
if (data->soh_response)
- len += wpabuf_len(data->soh_response);
-#endif /* EAP_TNC */
+ mlen += wpabuf_len(data->soh_response);
+#endif /* EAP_SERVER_TNC */
- buf = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_TLV, len,
+ buf = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_TLV, mlen,
EAP_CODE_REQUEST, id);
if (buf == NULL)
return NULL;
@@ -401,7 +403,7 @@ static struct wpabuf * eap_peap_build_phase2_tlv(struct eap_sm *sm,
size_t len[2];
u16 tlv_type;
-#ifdef EAP_TNC
+#ifdef EAP_SERVER_TNC
if (data->soh_response) {
wpa_printf(MSG_DEBUG, "EAP-PEAP: Adding MS-SOH "
"Response TLV");
@@ -409,7 +411,7 @@ static struct wpabuf * eap_peap_build_phase2_tlv(struct eap_sm *sm,
wpabuf_free(data->soh_response);
data->soh_response = NULL;
}
-#endif /* EAP_TNC */
+#endif /* EAP_SERVER_TNC */
if (eap_peap_derive_cmk(sm, data) < 0 ||
os_get_random(data->binding_nonce, 32)) {
@@ -450,8 +452,7 @@ static struct wpabuf * eap_peap_build_phase2_tlv(struct eap_sm *sm,
wpa_hexdump_buf_key(MSG_DEBUG, "EAP-PEAP: Encrypting Phase 2 TLV data",
buf);
- encr_req = eap_server_tls_encrypt(sm, &data->ssl, wpabuf_head(buf),
- wpabuf_len(buf));
+ encr_req = eap_server_tls_encrypt(sm, &data->ssl, buf);
wpabuf_free(buf);
return encr_req;
@@ -462,7 +463,7 @@ static struct wpabuf * eap_peap_build_phase2_term(struct eap_sm *sm,
struct eap_peap_data *data,
u8 id, int success)
{
- struct wpabuf *encr_req;
+ struct wpabuf *encr_req, msgbuf;
size_t req_len;
struct eap_hdr *hdr;
@@ -478,7 +479,8 @@ static struct wpabuf * eap_peap_build_phase2_term(struct eap_sm *sm,
wpa_hexdump_key(MSG_DEBUG, "EAP-PEAP: Encrypting Phase 2 data",
(u8 *) hdr, req_len);
- encr_req = eap_server_tls_encrypt(sm, &data->ssl, (u8 *) hdr, req_len);
+ wpabuf_set(&msgbuf, hdr, req_len);
+ encr_req = eap_server_tls_encrypt(sm, &data->ssl, &msgbuf);
os_free(hdr);
return encr_req;
@@ -513,32 +515,32 @@ static struct wpabuf * eap_peap_buildReq(struct eap_sm *sm, void *priv, u8 id)
break;
case PHASE2_ID:
case PHASE2_METHOD:
- wpabuf_free(data->ssl.out_buf);
- data->ssl.out_used = 0;
- data->ssl.out_buf = eap_peap_build_phase2_req(sm, data, id);
+ wpabuf_free(data->ssl.tls_out);
+ data->ssl.tls_out_pos = 0;
+ data->ssl.tls_out = eap_peap_build_phase2_req(sm, data, id);
break;
-#ifdef EAP_TNC
+#ifdef EAP_SERVER_TNC
case PHASE2_SOH:
- wpabuf_free(data->ssl.out_buf);
- data->ssl.out_used = 0;
- data->ssl.out_buf = eap_peap_build_phase2_soh(sm, data, id);
+ wpabuf_free(data->ssl.tls_out);
+ data->ssl.tls_out_pos = 0;
+ data->ssl.tls_out = eap_peap_build_phase2_soh(sm, data, id);
break;
-#endif /* EAP_TNC */
+#endif /* EAP_SERVER_TNC */
case PHASE2_TLV:
- wpabuf_free(data->ssl.out_buf);
- data->ssl.out_used = 0;
- data->ssl.out_buf = eap_peap_build_phase2_tlv(sm, data, id);
+ wpabuf_free(data->ssl.tls_out);
+ data->ssl.tls_out_pos = 0;
+ data->ssl.tls_out = eap_peap_build_phase2_tlv(sm, data, id);
break;
case SUCCESS_REQ:
- wpabuf_free(data->ssl.out_buf);
- data->ssl.out_used = 0;
- data->ssl.out_buf = eap_peap_build_phase2_term(sm, data, id,
+ wpabuf_free(data->ssl.tls_out);
+ data->ssl.tls_out_pos = 0;
+ data->ssl.tls_out = eap_peap_build_phase2_term(sm, data, id,
1);
break;
case FAILURE_REQ:
- wpabuf_free(data->ssl.out_buf);
- data->ssl.out_used = 0;
- data->ssl.out_buf = eap_peap_build_phase2_term(sm, data, id,
+ wpabuf_free(data->ssl.tls_out);
+ data->ssl.tls_out_pos = 0;
+ data->ssl.tls_out = eap_peap_build_phase2_term(sm, data, id,
0);
break;
default:
@@ -757,7 +759,7 @@ static void eap_peap_process_phase2_tlv(struct eap_sm *sm,
}
-#ifdef EAP_TNC
+#ifdef EAP_SERVER_TNC
static void eap_peap_process_phase2_soh(struct eap_sm *sm,
struct eap_peap_data *data,
struct wpabuf *in_data)
@@ -885,7 +887,7 @@ auth_method:
wpa_printf(MSG_DEBUG, "EAP-PEAP: try EAP type %d", next_type);
eap_peap_phase2_init(sm, data, next_type);
}
-#endif /* EAP_TNC */
+#endif /* EAP_SERVER_TNC */
static void eap_peap_process_phase2_response(struct eap_sm *sm,
@@ -902,12 +904,12 @@ static void eap_peap_process_phase2_response(struct eap_sm *sm,
return;
}
-#ifdef EAP_TNC
+#ifdef EAP_SERVER_TNC
if (data->state == PHASE2_SOH) {
eap_peap_process_phase2_soh(sm, data, in_data);
return;
}
-#endif /* EAP_TNC */
+#endif /* EAP_SERVER_TNC */
if (data->phase2_priv == NULL) {
wpa_printf(MSG_DEBUG, "EAP-PEAP: %s - Phase2 not "
@@ -991,7 +993,7 @@ static void eap_peap_process_phase2_response(struct eap_sm *sm,
break;
}
-#ifdef EAP_TNC
+#ifdef EAP_SERVER_TNC
if (data->state != PHASE2_SOH && sm->tnc &&
data->peap_version == 0) {
eap_peap_state(data, PHASE2_SOH);
@@ -1000,7 +1002,7 @@ static void eap_peap_process_phase2_response(struct eap_sm *sm,
next_type = EAP_TYPE_NONE;
break;
}
-#endif /* EAP_TNC */
+#endif /* EAP_SERVER_TNC */
eap_peap_state(data, PHASE2_METHOD);
next_type = sm->user->methods[0].method;
@@ -1029,17 +1031,11 @@ static void eap_peap_process_phase2(struct eap_sm *sm,
struct wpabuf *in_buf)
{
struct wpabuf *in_decrypted;
- int len_decrypted;
const struct eap_hdr *hdr;
- size_t buf_len, len;
- u8 *in_data;
- size_t in_len;
-
- in_data = wpabuf_mhead(in_buf);
- in_len = wpabuf_len(in_buf);
+ size_t len;
wpa_printf(MSG_DEBUG, "EAP-PEAP: received %lu bytes encrypted data for"
- " Phase 2", (unsigned long) in_len);
+ " Phase 2", (unsigned long) wpabuf_len(in_buf));
if (data->pending_phase2_resp) {
wpa_printf(MSG_DEBUG, "EAP-PEAP: Pending Phase 2 response - "
@@ -1051,34 +1047,14 @@ static void eap_peap_process_phase2(struct eap_sm *sm,
return;
}
- buf_len = in_len;
- /*
- * Even though we try to disable TLS compression, it is possible that
- * this cannot be done with all TLS libraries. Add extra buffer space
- * to handle the possibility of the decrypted data being longer than
- * input data.
- */
- buf_len += 500;
- buf_len *= 3;
- in_decrypted = wpabuf_alloc(buf_len);
+ in_decrypted = tls_connection_decrypt(sm->ssl_ctx, data->ssl.conn,
+ in_buf);
if (in_decrypted == NULL) {
- wpa_printf(MSG_WARNING, "EAP-PEAP: failed to allocate memory "
- "for decryption");
- return;
- }
-
- len_decrypted = tls_connection_decrypt(sm->ssl_ctx, data->ssl.conn,
- in_data, in_len,
- wpabuf_mhead(in_decrypted),
- buf_len);
- if (len_decrypted < 0) {
wpa_printf(MSG_INFO, "EAP-PEAP: Failed to decrypt Phase 2 "
"data");
- wpabuf_free(in_decrypted);
eap_peap_state(data, FAILURE);
return;
}
- wpabuf_put(in_decrypted, len_decrypted);
wpa_hexdump_buf_key(MSG_DEBUG, "EAP-PEAP: Decrypted Phase 2 EAP",
in_decrypted);
@@ -1191,7 +1167,7 @@ static void eap_peap_process_phase2(struct eap_sm *sm,
break;
}
- os_free(in_decrypted);
+ wpabuf_free(in_decrypted);
}
@@ -1199,7 +1175,6 @@ static int eap_peapv2_start_phase2(struct eap_sm *sm,
struct eap_peap_data *data)
{
struct wpabuf *buf, *buf2;
- int res;
wpa_printf(MSG_DEBUG, "EAP-PEAPv2: Phase1 done, include first Phase2 "
"payload in the same message");
@@ -1218,35 +1193,25 @@ static int eap_peapv2_start_phase2(struct eap_sm *sm,
wpa_hexdump_buf(MSG_DEBUG, "EAP-PEAPv2: Identity Request", buf2);
- buf = wpabuf_alloc(data->ssl.tls_out_limit);
- if (buf == NULL) {
- wpabuf_free(buf2);
- return -1;
- }
-
- res = tls_connection_encrypt(sm->ssl_ctx, data->ssl.conn,
- wpabuf_head(buf2), wpabuf_len(buf2),
- wpabuf_put(buf, 0),
- data->ssl.tls_out_limit);
+ buf = tls_connection_encrypt(sm->ssl_ctx, data->ssl.conn,
+ buf2);
wpabuf_free(buf2);
- if (res < 0) {
+ if (buf == NULL) {
wpa_printf(MSG_INFO, "EAP-PEAPv2: Failed to encrypt Phase 2 "
"data");
- wpabuf_free(buf);
return -1;
}
- wpabuf_put(buf, res);
wpa_hexdump_buf(MSG_DEBUG, "EAP-PEAPv2: Encrypted Identity Request",
buf);
/* Append TLS data into the pending buffer after the Server Finished */
- if (wpabuf_resize(&data->ssl.out_buf, wpabuf_len(buf)) < 0) {
+ if (wpabuf_resize(&data->ssl.tls_out, wpabuf_len(buf)) < 0) {
wpabuf_free(buf);
return -1;
}
- wpabuf_put_buf(data->ssl.out_buf, buf);
+ wpabuf_put_buf(data->ssl.tls_out, buf);
wpabuf_free(buf);
return 0;
@@ -1305,7 +1270,7 @@ static void eap_peap_process_msg(struct eap_sm *sm, void *priv,
case PHASE2_METHOD:
case PHASE2_SOH:
case PHASE2_TLV:
- eap_peap_process_phase2(sm, data, respData, data->ssl.in_buf);
+ eap_peap_process_phase2(sm, data, respData, data->ssl.tls_in);
break;
case SUCCESS_REQ:
eap_peap_state(data, SUCCESS);
diff --git a/contrib/wpa/src/eap_server/eap_psk.c b/contrib/wpa/src/eap_server/eap_server_psk.c
index c68d4c3..4c30346 100644
--- a/contrib/wpa/src/eap_server/eap_psk.c
+++ b/contrib/wpa/src/eap_server/eap_server_psk.c
@@ -18,9 +18,9 @@
#include "includes.h"
#include "common.h"
-#include "eap_server/eap_i.h"
-#include "aes_wrap.h"
+#include "crypto/aes_wrap.h"
#include "eap_common/eap_psk_common.h"
+#include "eap_server/eap_i.h"
struct eap_psk_data {
diff --git a/contrib/wpa/src/eap_server/eap_sake.c b/contrib/wpa/src/eap_server/eap_server_sake.c
index ce4848f..ce4848f 100644
--- a/contrib/wpa/src/eap_server/eap_sake.c
+++ b/contrib/wpa/src/eap_server/eap_server_sake.c
diff --git a/contrib/wpa/src/eap_server/eap_sim.c b/contrib/wpa/src/eap_server/eap_server_sim.c
index 436c655..436c655 100644
--- a/contrib/wpa/src/eap_server/eap_sim.c
+++ b/contrib/wpa/src/eap_server/eap_server_sim.c
diff --git a/contrib/wpa/src/eap_server/eap_tls.c b/contrib/wpa/src/eap_server/eap_server_tls.c
index 5747940..c98fa18 100644
--- a/contrib/wpa/src/eap_server/eap_tls.c
+++ b/contrib/wpa/src/eap_server/eap_server_tls.c
@@ -17,7 +17,7 @@
#include "common.h"
#include "eap_i.h"
#include "eap_tls_common.h"
-#include "tls.h"
+#include "crypto/tls.h"
static void eap_tls_reset(struct eap_sm *sm, void *priv);
@@ -169,7 +169,7 @@ static void eap_tls_process_msg(struct eap_sm *sm, void *priv,
const struct wpabuf *respData)
{
struct eap_tls_data *data = priv;
- if (data->state == SUCCESS && wpabuf_len(data->ssl.in_buf) == 0) {
+ if (data->state == SUCCESS && wpabuf_len(data->ssl.tls_in) == 0) {
wpa_printf(MSG_DEBUG, "EAP-TLS: Client acknowledged final TLS "
"handshake message");
return;
diff --git a/contrib/wpa/src/eap_server/eap_tls_common.c b/contrib/wpa/src/eap_server/eap_server_tls_common.c
index bda1184..25ae683 100644
--- a/contrib/wpa/src/eap_server/eap_tls_common.c
+++ b/contrib/wpa/src/eap_server/eap_server_tls_common.c
@@ -1,6 +1,6 @@
/*
- * hostapd / EAP-TLS/PEAP/TTLS/FAST common functions
- * Copyright (c) 2004-2008, Jouni Malinen <j@w1.fi>
+ * EAP-TLS/PEAP/TTLS/FAST server common functions
+ * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -15,10 +15,13 @@
#include "includes.h"
#include "common.h"
+#include "crypto/sha1.h"
+#include "crypto/tls.h"
#include "eap_i.h"
#include "eap_tls_common.h"
-#include "sha1.h"
-#include "tls.h"
+
+
+static void eap_server_tls_free_in_buf(struct eap_ssl_data *data);
int eap_server_tls_ssl_init(struct eap_sm *sm, struct eap_ssl_data *data,
@@ -58,8 +61,9 @@ int eap_server_tls_ssl_init(struct eap_sm *sm, struct eap_ssl_data *data,
void eap_server_tls_ssl_deinit(struct eap_sm *sm, struct eap_ssl_data *data)
{
tls_connection_deinit(sm->ssl_ctx, data->conn);
- os_free(data->in_buf);
- os_free(data->out_buf);
+ eap_server_tls_free_in_buf(data);
+ wpabuf_free(data->tls_out);
+ data->tls_out = NULL;
}
@@ -114,17 +118,17 @@ struct wpabuf * eap_server_tls_build_msg(struct eap_ssl_data *data,
size_t send_len, plen;
wpa_printf(MSG_DEBUG, "SSL: Generating Request");
- if (data->out_buf == NULL) {
- wpa_printf(MSG_ERROR, "SSL: out_buf NULL in %s", __func__);
+ if (data->tls_out == NULL) {
+ wpa_printf(MSG_ERROR, "SSL: tls_out NULL in %s", __func__);
return NULL;
}
flags = version;
- send_len = wpabuf_len(data->out_buf) - data->out_used;
+ send_len = wpabuf_len(data->tls_out) - data->tls_out_pos;
if (1 + send_len > data->tls_out_limit) {
send_len = data->tls_out_limit - 1;
flags |= EAP_TLS_FLAGS_MORE_FRAGMENTS;
- if (data->out_used == 0) {
+ if (data->tls_out_pos == 0) {
flags |= EAP_TLS_FLAGS_LENGTH_INCLUDED;
send_len -= 4;
}
@@ -141,25 +145,25 @@ struct wpabuf * eap_server_tls_build_msg(struct eap_ssl_data *data,
wpabuf_put_u8(req, flags); /* Flags */
if (flags & EAP_TLS_FLAGS_LENGTH_INCLUDED)
- wpabuf_put_be32(req, wpabuf_len(data->out_buf));
+ wpabuf_put_be32(req, wpabuf_len(data->tls_out));
- wpabuf_put_data(req, wpabuf_head_u8(data->out_buf) + data->out_used,
+ wpabuf_put_data(req, wpabuf_head_u8(data->tls_out) + data->tls_out_pos,
send_len);
- data->out_used += send_len;
+ data->tls_out_pos += send_len;
- if (data->out_used == wpabuf_len(data->out_buf)) {
+ if (data->tls_out_pos == wpabuf_len(data->tls_out)) {
wpa_printf(MSG_DEBUG, "SSL: Sending out %lu bytes "
"(message sent completely)",
(unsigned long) send_len);
- wpabuf_free(data->out_buf);
- data->out_buf = NULL;
- data->out_used = 0;
+ wpabuf_free(data->tls_out);
+ data->tls_out = NULL;
+ data->tls_out_pos = 0;
data->state = MSG;
} else {
wpa_printf(MSG_DEBUG, "SSL: Sending out %lu bytes "
"(%lu more to send)", (unsigned long) send_len,
- (unsigned long) wpabuf_len(data->out_buf) -
- data->out_used);
+ (unsigned long) wpabuf_len(data->tls_out) -
+ data->tls_out_pos);
data->state = WAIT_FRAG_ACK;
}
@@ -185,15 +189,15 @@ static int eap_server_tls_process_cont(struct eap_ssl_data *data,
const u8 *buf, size_t len)
{
/* Process continuation of a pending message */
- if (len > wpabuf_tailroom(data->in_buf)) {
+ if (len > wpabuf_tailroom(data->tls_in)) {
wpa_printf(MSG_DEBUG, "SSL: Fragment overflow");
return -1;
}
- wpabuf_put_data(data->in_buf, buf, len);
+ wpabuf_put_data(data->tls_in, buf, len);
wpa_printf(MSG_DEBUG, "SSL: Received %lu bytes, waiting for %lu "
"bytes more", (unsigned long) len,
- (unsigned long) wpabuf_tailroom(data->in_buf));
+ (unsigned long) wpabuf_tailroom(data->tls_in));
return 0;
}
@@ -204,13 +208,13 @@ static int eap_server_tls_process_fragment(struct eap_ssl_data *data,
const u8 *buf, size_t len)
{
/* Process a fragment that is not the last one of the message */
- if (data->in_buf == NULL && !(flags & EAP_TLS_FLAGS_LENGTH_INCLUDED)) {
+ if (data->tls_in == NULL && !(flags & EAP_TLS_FLAGS_LENGTH_INCLUDED)) {
wpa_printf(MSG_DEBUG, "SSL: No Message Length field in a "
"fragmented packet");
return -1;
}
- if (data->in_buf == NULL) {
+ if (data->tls_in == NULL) {
/* First fragment of the message */
/* Limit length to avoid rogue peers from causing large
@@ -221,16 +225,16 @@ static int eap_server_tls_process_fragment(struct eap_ssl_data *data,
return -1;
}
- data->in_buf = wpabuf_alloc(message_length);
- if (data->in_buf == NULL) {
+ data->tls_in = wpabuf_alloc(message_length);
+ if (data->tls_in == NULL) {
wpa_printf(MSG_DEBUG, "SSL: No memory for message");
return -1;
}
- wpabuf_put_data(data->in_buf, buf, len);
+ wpabuf_put_data(data->tls_in, buf, len);
wpa_printf(MSG_DEBUG, "SSL: Received %lu bytes in first "
"fragment, waiting for %lu bytes more",
(unsigned long) len,
- (unsigned long) wpabuf_tailroom(data->in_buf));
+ (unsigned long) wpabuf_tailroom(data->tls_in));
}
return 0;
@@ -239,30 +243,28 @@ static int eap_server_tls_process_fragment(struct eap_ssl_data *data,
int eap_server_tls_phase1(struct eap_sm *sm, struct eap_ssl_data *data)
{
- u8 *next;
- size_t next_len;
-
- next = tls_connection_server_handshake(
- sm->ssl_ctx, data->conn,
- wpabuf_mhead(data->in_buf),
- wpabuf_len(data->in_buf),
- &next_len);
- if (next == NULL) {
- wpa_printf(MSG_INFO, "SSL: TLS processing failed");
- return -1;
- }
- if (data->out_buf) {
+ if (data->tls_out) {
/* This should not happen.. */
wpa_printf(MSG_INFO, "SSL: pending tls_out data when "
"processing new message");
- os_free(data->out_buf);
- WPA_ASSERT(data->out_buf == NULL);
+ wpabuf_free(data->tls_out);
+ WPA_ASSERT(data->tls_out == NULL);
}
- data->out_buf = wpabuf_alloc_ext_data(next, next_len);
- if (data->out_buf == NULL) {
- os_free(next);
+
+ data->tls_out = tls_connection_server_handshake(sm->ssl_ctx,
+ data->conn,
+ data->tls_in, NULL);
+ if (data->tls_out == NULL) {
+ wpa_printf(MSG_INFO, "SSL: TLS processing failed");
+ return -1;
+ }
+ if (tls_connection_get_failed(sm->ssl_ctx, data->conn)) {
+ /* TLS processing has failed - return error */
+ wpa_printf(MSG_DEBUG, "SSL: Failed - tls_out available to "
+ "report error");
return -1;
}
+
return 0;
}
@@ -299,7 +301,7 @@ static int eap_server_tls_reassemble(struct eap_ssl_data *data, u8 flags,
return 1;
}
- if (data->in_buf &&
+ if (data->tls_in &&
eap_server_tls_process_cont(data, *pos, end - *pos) < 0)
return -1;
@@ -317,10 +319,10 @@ static int eap_server_tls_reassemble(struct eap_ssl_data *data, u8 flags,
data->state = MSG;
}
- if (data->in_buf == NULL) {
+ if (data->tls_in == NULL) {
/* Wrap unfragmented messages as wpabuf without extra copy */
wpabuf_set(&data->tmpbuf, *pos, end - *pos);
- data->in_buf = &data->tmpbuf;
+ data->tls_in = &data->tmpbuf;
}
return 0;
@@ -329,36 +331,25 @@ static int eap_server_tls_reassemble(struct eap_ssl_data *data, u8 flags,
static void eap_server_tls_free_in_buf(struct eap_ssl_data *data)
{
- if (data->in_buf != &data->tmpbuf)
- wpabuf_free(data->in_buf);
- data->in_buf = NULL;
+ if (data->tls_in != &data->tmpbuf)
+ wpabuf_free(data->tls_in);
+ data->tls_in = NULL;
}
struct wpabuf * eap_server_tls_encrypt(struct eap_sm *sm,
struct eap_ssl_data *data,
- const u8 *plain, size_t plain_len)
+ const struct wpabuf *plain)
{
- int res;
struct wpabuf *buf;
- size_t buf_len;
- /* reserve some extra room for encryption overhead */
- buf_len = plain_len + 300;
- buf = wpabuf_alloc(buf_len);
- if (buf == NULL)
- return NULL;
- res = tls_connection_encrypt(sm->ssl_ctx, data->conn,
- plain, plain_len, wpabuf_put(buf, 0),
- buf_len);
- if (res < 0) {
+ buf = tls_connection_encrypt(sm->ssl_ctx, data->conn,
+ plain);
+ if (buf == NULL) {
wpa_printf(MSG_INFO, "SSL: Failed to encrypt Phase 2 data");
- wpabuf_free(buf);
return NULL;
}
- wpabuf_put(buf, res);
-
return buf;
}
diff --git a/contrib/wpa/src/eap_server/eap_tnc.c b/contrib/wpa/src/eap_server/eap_server_tnc.c
index 4cb3ecf..f3b70ed 100644
--- a/contrib/wpa/src/eap_server/eap_tnc.c
+++ b/contrib/wpa/src/eap_server/eap_server_tnc.c
@@ -1,6 +1,6 @@
/*
* EAP server method: EAP-TNC (Trusted Network Connect)
- * Copyright (c) 2007-2008, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2007-2010, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -21,14 +21,18 @@
struct eap_tnc_data {
- enum { START, CONTINUE, RECOMMENDATION, FRAG_ACK, WAIT_FRAG_ACK, DONE,
- FAIL } state;
+ enum eap_tnc_state {
+ START, CONTINUE, RECOMMENDATION, FRAG_ACK, WAIT_FRAG_ACK, DONE,
+ FAIL
+ } state;
enum { ALLOW, ISOLATE, NO_ACCESS, NO_RECOMMENDATION } recommendation;
struct tncs_data *tncs;
struct wpabuf *in_buf;
struct wpabuf *out_buf;
size_t out_used;
size_t fragment_size;
+ unsigned int was_done:1;
+ unsigned int was_fail:1;
};
@@ -41,6 +45,38 @@ struct eap_tnc_data {
#define EAP_TNC_VERSION 1
+static const char * eap_tnc_state_txt(enum eap_tnc_state state)
+{
+ switch (state) {
+ case START:
+ return "START";
+ case CONTINUE:
+ return "CONTINUE";
+ case RECOMMENDATION:
+ return "RECOMMENDATION";
+ case FRAG_ACK:
+ return "FRAG_ACK";
+ case WAIT_FRAG_ACK:
+ return "WAIT_FRAG_ACK";
+ case DONE:
+ return "DONE";
+ case FAIL:
+ return "FAIL";
+ }
+ return "??";
+}
+
+
+static void eap_tnc_set_state(struct eap_tnc_data *data,
+ enum eap_tnc_state new_state)
+{
+ wpa_printf(MSG_DEBUG, "EAP-TNC: %s -> %s",
+ eap_tnc_state_txt(data->state),
+ eap_tnc_state_txt(new_state));
+ data->state = new_state;
+}
+
+
static void * eap_tnc_init(struct eap_sm *sm)
{
struct eap_tnc_data *data;
@@ -48,7 +84,7 @@ static void * eap_tnc_init(struct eap_sm *sm)
data = os_zalloc(sizeof(*data));
if (data == NULL)
return NULL;
- data->state = START;
+ eap_tnc_set_state(data, START);
data->tncs = tncs_init();
if (data->tncs == NULL) {
os_free(data);
@@ -81,13 +117,13 @@ static struct wpabuf * eap_tnc_build_start(struct eap_sm *sm,
if (req == NULL) {
wpa_printf(MSG_ERROR, "EAP-TNC: Failed to allocate memory for "
"request");
- data->state = FAIL;
+ eap_tnc_set_state(data, FAIL);
return NULL;
}
wpabuf_put_u8(req, EAP_TNC_FLAGS_START | EAP_TNC_VERSION);
- data->state = CONTINUE;
+ eap_tnc_set_state(data, CONTINUE);
return req;
}
@@ -146,17 +182,17 @@ static struct wpabuf * eap_tnc_build_recommendation(struct eap_sm *sm,
{
switch (data->recommendation) {
case ALLOW:
- data->state = DONE;
+ eap_tnc_set_state(data, DONE);
break;
case ISOLATE:
- data->state = FAIL;
+ eap_tnc_set_state(data, FAIL);
/* TODO: support assignment to a different VLAN */
break;
case NO_ACCESS:
- data->state = FAIL;
+ eap_tnc_set_state(data, FAIL);
break;
case NO_RECOMMENDATION:
- data->state = DONE;
+ eap_tnc_set_state(data, DONE);
break;
default:
wpa_printf(MSG_DEBUG, "EAP-TNC: Unknown recommendation");
@@ -171,12 +207,13 @@ static struct wpabuf * eap_tnc_build_frag_ack(u8 id, u8 code)
{
struct wpabuf *msg;
- msg = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_TNC, 0, code, id);
+ msg = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_TNC, 1, code, id);
if (msg == NULL) {
wpa_printf(MSG_ERROR, "EAP-TNC: Failed to allocate memory "
"for fragment ack");
return NULL;
}
+ wpabuf_put_u8(msg, EAP_TNC_VERSION); /* Flags */
wpa_printf(MSG_DEBUG, "EAP-TNC: Send fragment ack");
@@ -226,12 +263,20 @@ static struct wpabuf * eap_tnc_build_msg(struct eap_tnc_data *data, u8 id)
wpabuf_free(data->out_buf);
data->out_buf = NULL;
data->out_used = 0;
+ if (data->was_fail)
+ eap_tnc_set_state(data, FAIL);
+ else if (data->was_done)
+ eap_tnc_set_state(data, DONE);
} else {
wpa_printf(MSG_DEBUG, "EAP-TNC: Sending out %lu bytes "
"(%lu more to send)", (unsigned long) send_len,
(unsigned long) wpabuf_len(data->out_buf) -
data->out_used);
- data->state = WAIT_FRAG_ACK;
+ if (data->state == FAIL)
+ data->was_fail = 1;
+ else if (data->state == DONE)
+ data->was_done = 1;
+ eap_tnc_set_state(data, WAIT_FRAG_ACK);
}
return req;
@@ -327,27 +372,27 @@ static void tncs_process(struct eap_tnc_data *data, struct wpabuf *inbuf)
switch (res) {
case TNCCS_RECOMMENDATION_ALLOW:
wpa_printf(MSG_DEBUG, "EAP-TNC: TNCS allowed access");
- data->state = RECOMMENDATION;
+ eap_tnc_set_state(data, RECOMMENDATION);
data->recommendation = ALLOW;
break;
case TNCCS_RECOMMENDATION_NO_RECOMMENDATION:
wpa_printf(MSG_DEBUG, "EAP-TNC: TNCS has no recommendation");
- data->state = RECOMMENDATION;
+ eap_tnc_set_state(data, RECOMMENDATION);
data->recommendation = NO_RECOMMENDATION;
break;
case TNCCS_RECOMMENDATION_ISOLATE:
wpa_printf(MSG_DEBUG, "EAP-TNC: TNCS requested isolation");
- data->state = RECOMMENDATION;
+ eap_tnc_set_state(data, RECOMMENDATION);
data->recommendation = ISOLATE;
break;
case TNCCS_RECOMMENDATION_NO_ACCESS:
wpa_printf(MSG_DEBUG, "EAP-TNC: TNCS rejected access");
- data->state = RECOMMENDATION;
+ eap_tnc_set_state(data, RECOMMENDATION);
data->recommendation = NO_ACCESS;
break;
case TNCCS_PROCESS_ERROR:
wpa_printf(MSG_DEBUG, "EAP-TNC: TNCS processing error");
- data->state = FAIL;
+ eap_tnc_set_state(data, FAIL);
break;
default:
break;
@@ -361,7 +406,7 @@ static int eap_tnc_process_cont(struct eap_tnc_data *data,
/* Process continuation of a pending message */
if (len > wpabuf_tailroom(data->in_buf)) {
wpa_printf(MSG_DEBUG, "EAP-TNC: Fragment overflow");
- data->state = FAIL;
+ eap_tnc_set_state(data, FAIL);
return -1;
}
@@ -435,7 +480,7 @@ static void eap_tnc_process(struct eap_sm *sm, void *priv,
if (flags & EAP_TNC_FLAGS_LENGTH_INCLUDED) {
if (end - pos < 4) {
wpa_printf(MSG_DEBUG, "EAP-TNC: Message underflow");
- data->state = FAIL;
+ eap_tnc_set_state(data, FAIL);
return;
}
message_length = WPA_GET_BE32(pos);
@@ -445,7 +490,7 @@ static void eap_tnc_process(struct eap_sm *sm, void *priv,
wpa_printf(MSG_DEBUG, "EAP-TNC: Invalid Message "
"Length (%d; %ld remaining in this msg)",
message_length, (long) (end - pos));
- data->state = FAIL;
+ eap_tnc_set_state(data, FAIL);
return;
}
}
@@ -453,32 +498,32 @@ static void eap_tnc_process(struct eap_sm *sm, void *priv,
"Message Length %u", flags, message_length);
if (data->state == WAIT_FRAG_ACK) {
- if (len != 0) {
+ if (len > 1) {
wpa_printf(MSG_DEBUG, "EAP-TNC: Unexpected payload "
"in WAIT_FRAG_ACK state");
- data->state = FAIL;
+ eap_tnc_set_state(data, FAIL);
return;
}
wpa_printf(MSG_DEBUG, "EAP-TNC: Fragment acknowledged");
- data->state = CONTINUE;
+ eap_tnc_set_state(data, CONTINUE);
return;
}
if (data->in_buf && eap_tnc_process_cont(data, pos, end - pos) < 0) {
- data->state = FAIL;
+ eap_tnc_set_state(data, FAIL);
return;
}
if (flags & EAP_TNC_FLAGS_MORE_FRAGMENTS) {
if (eap_tnc_process_fragment(data, flags, message_length,
pos, end - pos) < 0)
- data->state = FAIL;
+ eap_tnc_set_state(data, FAIL);
else
- data->state = FRAG_ACK;
+ eap_tnc_set_state(data, FRAG_ACK);
return;
} else if (data->state == FRAG_ACK) {
wpa_printf(MSG_DEBUG, "EAP-TNC: All fragments received");
- data->state = CONTINUE;
+ eap_tnc_set_state(data, CONTINUE);
}
if (data->in_buf == NULL) {
diff --git a/contrib/wpa/src/eap_server/eap_ttls.c b/contrib/wpa/src/eap_server/eap_server_ttls.c
index 21e4b21..702c50c 100644
--- a/contrib/wpa/src/eap_server/eap_ttls.c
+++ b/contrib/wpa/src/eap_server/eap_server_ttls.c
@@ -15,12 +15,12 @@
#include "includes.h"
#include "common.h"
+#include "crypto/ms_funcs.h"
+#include "crypto/sha1.h"
+#include "crypto/tls.h"
#include "eap_server/eap_i.h"
#include "eap_server/eap_tls_common.h"
-#include "ms_funcs.h"
-#include "sha1.h"
#include "eap_common/chap.h"
-#include "tls.h"
#include "eap_common/eap_ttls.h"
@@ -163,14 +163,14 @@ struct eap_ttls_avp {
};
-static int eap_ttls_avp_parse(u8 *buf, size_t len, struct eap_ttls_avp *parse)
+static int eap_ttls_avp_parse(struct wpabuf *buf, struct eap_ttls_avp *parse)
{
struct ttls_avp *avp;
u8 *pos;
int left;
- pos = buf;
- left = len;
+ pos = wpabuf_mhead(buf);
+ left = wpabuf_len(buf);
os_memset(parse, 0, sizeof(*parse));
while (left > 0) {
@@ -449,8 +449,6 @@ static struct wpabuf * eap_ttls_build_phase2_eap_req(
struct eap_sm *sm, struct eap_ttls_data *data, u8 id)
{
struct wpabuf *buf, *encr_req;
- u8 *req;
- size_t req_len;
buf = data->phase2_method->buildReq(sm, data->phase2_priv, id);
@@ -467,12 +465,10 @@ static struct wpabuf * eap_ttls_build_phase2_eap_req(
return NULL;
}
- req = wpabuf_mhead(buf);
- req_len = wpabuf_len(buf);
- wpa_hexdump_key(MSG_DEBUG, "EAP-TTLS/EAP: Encrypt encapsulated Phase "
- "2 data", req, req_len);
+ wpa_hexdump_buf_key(MSG_DEBUG, "EAP-TTLS/EAP: Encrypt encapsulated "
+ "Phase 2 data", buf);
- encr_req = eap_server_tls_encrypt(sm, &data->ssl, req, req_len);
+ encr_req = eap_server_tls_encrypt(sm, &data->ssl, buf);
wpabuf_free(buf);
return encr_req;
@@ -482,10 +478,9 @@ static struct wpabuf * eap_ttls_build_phase2_eap_req(
static struct wpabuf * eap_ttls_build_phase2_mschapv2(
struct eap_sm *sm, struct eap_ttls_data *data)
{
- struct wpabuf *encr_req;
+ struct wpabuf *encr_req, msgbuf;
u8 *req, *pos, *end;
int ret;
- size_t req_len;
pos = req = os_malloc(100);
if (req == NULL)
@@ -510,11 +505,11 @@ static struct wpabuf * eap_ttls_build_phase2_mschapv2(
AVP_PAD(req, pos);
}
- req_len = pos - req;
- wpa_hexdump_key(MSG_DEBUG, "EAP-TTLS/MSCHAPV2: Encrypting Phase 2 "
- "data", req, req_len);
+ wpabuf_set(&msgbuf, req, pos - req);
+ wpa_hexdump_buf_key(MSG_DEBUG, "EAP-TTLS/MSCHAPV2: Encrypting Phase 2 "
+ "data", &msgbuf);
- encr_req = eap_server_tls_encrypt(sm, &data->ssl, req, req_len);
+ encr_req = eap_server_tls_encrypt(sm, &data->ssl, &msgbuf);
os_free(req);
return encr_req;
@@ -524,25 +519,8 @@ static struct wpabuf * eap_ttls_build_phase2_mschapv2(
static struct wpabuf * eap_ttls_build_phase_finished(
struct eap_sm *sm, struct eap_ttls_data *data, int final)
{
- int len;
- struct wpabuf *req;
- const int max_len = 300;
-
- req = wpabuf_alloc(max_len);
- if (req == NULL)
- return NULL;
-
- len = tls_connection_ia_send_phase_finished(sm->ssl_ctx,
- data->ssl.conn, final,
- wpabuf_mhead(req),
- max_len);
- if (len < 0) {
- wpabuf_free(req);
- return NULL;
- }
- wpabuf_put(req, len);
-
- return req;
+ return tls_connection_ia_send_phase_finished(sm->ssl_ctx,
+ data->ssl.conn, final);
}
@@ -571,20 +549,20 @@ static struct wpabuf * eap_ttls_buildReq(struct eap_sm *sm, void *priv, u8 id)
}
break;
case PHASE2_METHOD:
- wpabuf_free(data->ssl.out_buf);
- data->ssl.out_used = 0;
- data->ssl.out_buf = eap_ttls_build_phase2_eap_req(sm, data,
+ wpabuf_free(data->ssl.tls_out);
+ data->ssl.tls_out_pos = 0;
+ data->ssl.tls_out = eap_ttls_build_phase2_eap_req(sm, data,
id);
break;
case PHASE2_MSCHAPV2_RESP:
- wpabuf_free(data->ssl.out_buf);
- data->ssl.out_used = 0;
- data->ssl.out_buf = eap_ttls_build_phase2_mschapv2(sm, data);
+ wpabuf_free(data->ssl.tls_out);
+ data->ssl.tls_out_pos = 0;
+ data->ssl.tls_out = eap_ttls_build_phase2_mschapv2(sm, data);
break;
case PHASE_FINISHED:
- wpabuf_free(data->ssl.out_buf);
- data->ssl.out_used = 0;
- data->ssl.out_buf = eap_ttls_build_phase_finished(sm, data, 1);
+ wpabuf_free(data->ssl.tls_out);
+ data->ssl.tls_out_pos = 0;
+ data->ssl.tls_out = eap_ttls_build_phase_finished(sm, data, 1);
break;
default:
wpa_printf(MSG_DEBUG, "EAP-TTLS: %s - unexpected state %d",
@@ -1126,18 +1104,11 @@ static void eap_ttls_process_phase2(struct eap_sm *sm,
struct eap_ttls_data *data,
struct wpabuf *in_buf)
{
- u8 *in_decrypted;
- int len_decrypted;
+ struct wpabuf *in_decrypted;
struct eap_ttls_avp parse;
- size_t buf_len;
- u8 *in_data;
- size_t in_len;
-
- in_data = wpabuf_mhead(in_buf);
- in_len = wpabuf_len(in_buf);
wpa_printf(MSG_DEBUG, "EAP-TTLS: received %lu bytes encrypted data for"
- " Phase 2", (unsigned long) in_len);
+ " Phase 2", (unsigned long) wpabuf_len(in_buf));
if (data->pending_phase2_eap_resp) {
wpa_printf(MSG_DEBUG, "EAP-TTLS: Pending Phase 2 EAP response "
@@ -1150,35 +1121,17 @@ static void eap_ttls_process_phase2(struct eap_sm *sm,
return;
}
- buf_len = in_len;
- /*
- * Even though we try to disable TLS compression, it is possible that
- * this cannot be done with all TLS libraries. Add extra buffer space
- * to handle the possibility of the decrypted data being longer than
- * input data.
- */
- buf_len += 500;
- buf_len *= 3;
- in_decrypted = os_malloc(buf_len);
+ in_decrypted = tls_connection_decrypt(sm->ssl_ctx, data->ssl.conn,
+ in_buf);
if (in_decrypted == NULL) {
- wpa_printf(MSG_WARNING, "EAP-TTLS: failed to allocate memory "
- "for decryption");
- return;
- }
-
- len_decrypted = tls_connection_decrypt(sm->ssl_ctx, data->ssl.conn,
- in_data, in_len,
- in_decrypted, buf_len);
- if (len_decrypted < 0) {
wpa_printf(MSG_INFO, "EAP-TTLS: Failed to decrypt Phase 2 "
"data");
- os_free(in_decrypted);
eap_ttls_state(data, FAILURE);
return;
}
if (data->state == PHASE_FINISHED) {
- if (len_decrypted == 0 &&
+ if (wpabuf_len(in_decrypted) == 0 &&
tls_connection_ia_final_phase_finished(sm->ssl_ctx,
data->ssl.conn)) {
wpa_printf(MSG_DEBUG, "EAP-TTLS: FinalPhaseFinished "
@@ -1190,16 +1143,16 @@ static void eap_ttls_process_phase2(struct eap_sm *sm,
eap_ttls_state(data, FAILURE);
}
- os_free(in_decrypted);
+ wpabuf_free(in_decrypted);
return;
}
- wpa_hexdump_key(MSG_DEBUG, "EAP-TTLS: Decrypted Phase 2 EAP",
- in_decrypted, len_decrypted);
+ wpa_hexdump_buf_key(MSG_DEBUG, "EAP-TTLS: Decrypted Phase 2 EAP",
+ in_decrypted);
- if (eap_ttls_avp_parse(in_decrypted, len_decrypted, &parse) < 0) {
+ if (eap_ttls_avp_parse(in_decrypted, &parse) < 0) {
wpa_printf(MSG_DEBUG, "EAP-TTLS: Failed to parse AVPs");
- os_free(in_decrypted);
+ wpabuf_free(in_decrypted);
eap_ttls_state(data, FAILURE);
return;
}
@@ -1221,14 +1174,14 @@ static void eap_ttls_process_phase2(struct eap_sm *sm,
}
}
-#ifdef EAP_TNC
+#ifdef EAP_SERVER_TNC
if (data->tnc_started && parse.eap == NULL) {
wpa_printf(MSG_DEBUG, "EAP-TTLS: TNC started but no EAP "
"response from peer");
eap_ttls_state(data, FAILURE);
goto done;
}
-#endif /* EAP_TNC */
+#endif /* EAP_SERVER_TNC */
if (parse.eap) {
eap_ttls_process_phase2_eap(sm, data, parse.eap,
@@ -1257,14 +1210,14 @@ static void eap_ttls_process_phase2(struct eap_sm *sm,
}
done:
- os_free(in_decrypted);
+ wpabuf_free(in_decrypted);
os_free(parse.eap);
}
static void eap_ttls_start_tnc(struct eap_sm *sm, struct eap_ttls_data *data)
{
-#ifdef EAP_TNC
+#ifdef EAP_SERVER_TNC
if (!sm->tnc || data->state != SUCCESS || data->tnc_started)
return;
@@ -1277,7 +1230,7 @@ static void eap_ttls_start_tnc(struct eap_sm *sm, struct eap_ttls_data *data)
data->tnc_started = 1;
eap_ttls_state(data, PHASE2_METHOD);
-#endif /* EAP_TNC */
+#endif /* EAP_SERVER_TNC */
}
@@ -1318,11 +1271,11 @@ static void eap_ttls_process_msg(struct eap_sm *sm, void *priv,
case PHASE2_START:
case PHASE2_METHOD:
case PHASE_FINISHED:
- eap_ttls_process_phase2(sm, data, data->ssl.in_buf);
+ eap_ttls_process_phase2(sm, data, data->ssl.tls_in);
eap_ttls_start_tnc(sm, data);
break;
case PHASE2_MSCHAPV2_RESP:
- if (data->mschapv2_resp_ok && wpabuf_len(data->ssl.in_buf) ==
+ if (data->mschapv2_resp_ok && wpabuf_len(data->ssl.tls_in) ==
0) {
wpa_printf(MSG_DEBUG, "EAP-TTLS/MSCHAPV2: Peer "
"acknowledged response");
@@ -1337,7 +1290,7 @@ static void eap_ttls_process_msg(struct eap_sm *sm, void *priv,
"frame from peer (payload len %lu, "
"expected empty frame)",
(unsigned long)
- wpabuf_len(data->ssl.in_buf));
+ wpabuf_len(data->ssl.tls_in));
eap_ttls_state(data, FAILURE);
}
eap_ttls_start_tnc(sm, data);
diff --git a/contrib/wpa/src/eap_server/eap_vendor_test.c b/contrib/wpa/src/eap_server/eap_server_vendor_test.c
index 0dd0aca..0dd0aca 100644
--- a/contrib/wpa/src/eap_server/eap_vendor_test.c
+++ b/contrib/wpa/src/eap_server/eap_server_vendor_test.c
diff --git a/contrib/wpa/src/eap_server/eap_wsc.c b/contrib/wpa/src/eap_server/eap_server_wsc.c
index 3c17577..77cf9e2 100644
--- a/contrib/wpa/src/eap_server/eap_wsc.c
+++ b/contrib/wpa/src/eap_server/eap_server_wsc.c
@@ -22,7 +22,7 @@
struct eap_wsc_data {
- enum { START, MSG, FRAG_ACK, WAIT_FRAG_ACK, DONE, FAIL } state;
+ enum { START, MESG, FRAG_ACK, WAIT_FRAG_ACK, DONE, FAIL } state;
int registrar;
struct wpabuf *in_buf;
struct wpabuf *out_buf;
@@ -34,13 +34,14 @@ struct eap_wsc_data {
};
+#ifndef CONFIG_NO_STDOUT_DEBUG
static const char * eap_wsc_state_txt(int state)
{
switch (state) {
case START:
return "START";
- case MSG:
- return "MSG";
+ case MESG:
+ return "MESG";
case FRAG_ACK:
return "FRAG_ACK";
case WAIT_FRAG_ACK:
@@ -53,6 +54,7 @@ static const char * eap_wsc_state_txt(int state)
return "?";
}
}
+#endif /* CONFIG_NO_STDOUT_DEBUG */
static void eap_wsc_state(struct eap_wsc_data *data, int state)
@@ -102,7 +104,7 @@ static void * eap_wsc_init(struct eap_sm *sm)
data = os_zalloc(sizeof(*data));
if (data == NULL)
return NULL;
- data->state = registrar ? START : MSG;
+ data->state = registrar ? START : MESG;
data->registrar = registrar;
os_memset(&cfg, 0, sizeof(cfg));
@@ -117,15 +119,24 @@ static void * eap_wsc_init(struct eap_sm *sm)
}
} else {
if (sm->user == NULL || sm->user->password == NULL) {
- wpa_printf(MSG_INFO, "EAP-WSC: No AP PIN (password) "
- "configured for Enrollee functionality");
- os_free(data);
- return NULL;
+ /*
+ * In theory, this should not really be needed, but
+ * Windows 7 uses Registrar mode to probe AP's WPS
+ * capabilities before trying to use Enrollee and fails
+ * if the AP does not allow that probing to happen..
+ */
+ wpa_printf(MSG_DEBUG, "EAP-WSC: No AP PIN (password) "
+ "configured for Enrollee functionality - "
+ "allow for probing capabilities (M1)");
+ } else {
+ cfg.pin = sm->user->password;
+ cfg.pin_len = sm->user->password_len;
}
- cfg.pin = sm->user->password;
- cfg.pin_len = sm->user->password_len;
}
cfg.assoc_wps_ie = sm->assoc_wps_ie;
+ cfg.peer_addr = sm->peer_addr;
+ if (0 /* TODO: could provide option for forcing PSK format */)
+ cfg.use_psk_key = 1;
data->wps = wps_init(&cfg);
if (data->wps == NULL) {
os_free(data);
@@ -212,7 +223,7 @@ static struct wpabuf * eap_wsc_build_msg(struct eap_wsc_data *data, u8 id)
wpabuf_free(data->out_buf);
data->out_buf = NULL;
data->out_used = 0;
- eap_wsc_state(data, MSG);
+ eap_wsc_state(data, MESG);
} else {
wpa_printf(MSG_DEBUG, "EAP-WSC: Sending out %lu bytes "
"(%lu more to send)", (unsigned long) send_len,
@@ -232,7 +243,7 @@ static struct wpabuf * eap_wsc_buildReq(struct eap_sm *sm, void *priv, u8 id)
switch (data->state) {
case START:
return eap_wsc_build_start(sm, data, id);
- case MSG:
+ case MESG:
if (data->out_buf == NULL) {
data->out_buf = wps_get_msg(data->wps,
&data->out_op_code);
@@ -385,7 +396,7 @@ static void eap_wsc_process(struct eap_sm *sm, void *priv,
return;
}
wpa_printf(MSG_DEBUG, "EAP-WSC: Fragment acknowledged");
- eap_wsc_state(data, MSG);
+ eap_wsc_state(data, MESG);
return;
}
@@ -427,14 +438,14 @@ static void eap_wsc_process(struct eap_sm *sm, void *priv,
eap_wsc_state(data, FAIL);
break;
case WPS_CONTINUE:
- eap_wsc_state(data, MSG);
+ eap_wsc_state(data, MESG);
break;
case WPS_FAILURE:
wpa_printf(MSG_DEBUG, "EAP-WSC: WPS processing failed");
eap_wsc_state(data, FAIL);
break;
case WPS_PENDING:
- eap_wsc_state(data, MSG);
+ eap_wsc_state(data, MESG);
sm->method_pending = METHOD_PENDING_WAIT;
eloop_cancel_timeout(eap_wsc_ext_reg_timeout, sm, data);
eloop_register_timeout(5, 0, eap_wsc_ext_reg_timeout,
diff --git a/contrib/wpa/src/eap_server/eap_sim_db.c b/contrib/wpa/src/eap_server/eap_sim_db.c
index ed0bd3c..aba919a 100644
--- a/contrib/wpa/src/eap_server/eap_sim_db.c
+++ b/contrib/wpa/src/eap_server/eap_sim_db.c
@@ -1023,7 +1023,7 @@ int eap_sim_db_add_reauth(void *priv, const u8 *identity,
}
-#ifdef EAP_AKA_PRIME
+#ifdef EAP_SERVER_AKA_PRIME
/**
* eap_sim_db_add_reauth_prime - EAP-AKA' DB: Add new re-authentication entry
* @priv: Private data pointer from eap_sim_db_init()
@@ -1062,7 +1062,7 @@ int eap_sim_db_add_reauth_prime(void *priv, const u8 *identity,
return 0;
}
-#endif /* EAP_AKA_PRIME */
+#endif /* EAP_SERVER_AKA_PRIME */
/**
diff --git a/contrib/wpa/src/eap_server/eap_sim_db.h b/contrib/wpa/src/eap_server/eap_sim_db.h
index 6622181..ab89ae9 100644
--- a/contrib/wpa/src/eap_server/eap_sim_db.h
+++ b/contrib/wpa/src/eap_server/eap_sim_db.h
@@ -15,8 +15,6 @@
#ifndef EAP_SIM_DB_H
#define EAP_SIM_DB_H
-#ifdef EAP_SIM
-
#include "eap_common/eap_sim_common.h"
/* Identity prefixes */
@@ -90,18 +88,4 @@ int eap_sim_db_resynchronize(void *priv, const u8 *identity,
size_t identity_len, const u8 *auts,
const u8 *_rand);
-#else /* EAP_SIM */
-static inline void *
-eap_sim_db_init(const char *config,
- void (*get_complete_cb)(void *ctx, void *session_ctx),
- void *ctx)
-{
- return (void *) 1;
-}
-
-static inline void eap_sim_db_deinit(void *priv)
-{
-}
-#endif /* EAP_SIM */
-
#endif /* EAP_SIM_DB_H */
diff --git a/contrib/wpa/src/eap_server/eap_tls_common.h b/contrib/wpa/src/eap_server/eap_tls_common.h
index ce8dd25..c34c401 100644
--- a/contrib/wpa/src/eap_server/eap_tls_common.h
+++ b/contrib/wpa/src/eap_server/eap_tls_common.h
@@ -1,6 +1,6 @@
/*
- * hostapd / EAP-TLS/PEAP/TTLS/FAST common functions
- * Copyright (c) 2004-2008, Jouni Malinen <j@w1.fi>
+ * EAP-TLS/PEAP/TTLS/FAST server common functions
+ * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -15,19 +15,46 @@
#ifndef EAP_TLS_COMMON_H
#define EAP_TLS_COMMON_H
+/**
+ * struct eap_ssl_data - TLS data for EAP methods
+ */
struct eap_ssl_data {
+ /**
+ * conn - TLS connection context data from tls_connection_init()
+ */
struct tls_connection *conn;
+ /**
+ * tls_out - TLS message to be sent out in fragments
+ */
+ struct wpabuf *tls_out;
+
+ /**
+ * tls_out_pos - The current position in the outgoing TLS message
+ */
+ size_t tls_out_pos;
+
+ /**
+ * tls_out_limit - Maximum fragment size for outgoing TLS messages
+ */
size_t tls_out_limit;
+ /**
+ * tls_in - Received TLS message buffer for re-assembly
+ */
+ struct wpabuf *tls_in;
+
+ /**
+ * phase2 - Whether this TLS connection is used in EAP phase 2 (tunnel)
+ */
int phase2;
+ /**
+ * eap - EAP state machine allocated with eap_server_sm_init()
+ */
struct eap_sm *eap;
enum { MSG, FRAG_ACK, WAIT_FRAG_ACK } state;
- struct wpabuf *in_buf;
- struct wpabuf *out_buf;
- size_t out_used;
struct wpabuf tmpbuf;
};
@@ -53,7 +80,7 @@ struct wpabuf * eap_server_tls_build_ack(u8 id, int eap_type, int version);
int eap_server_tls_phase1(struct eap_sm *sm, struct eap_ssl_data *data);
struct wpabuf * eap_server_tls_encrypt(struct eap_sm *sm,
struct eap_ssl_data *data,
- const u8 *plain, size_t plain_len);
+ const struct wpabuf *plain);
int eap_server_tls_process(struct eap_sm *sm, struct eap_ssl_data *data,
struct wpabuf *respData, void *priv, int eap_type,
int (*proc_version)(struct eap_sm *sm, void *priv,
diff --git a/contrib/wpa/src/eap_server/ikev2.c b/contrib/wpa/src/eap_server/ikev2.c
index 46767c5..435ba26 100644
--- a/contrib/wpa/src/eap_server/ikev2.c
+++ b/contrib/wpa/src/eap_server/ikev2.c
@@ -15,7 +15,7 @@
#include "includes.h"
#include "common.h"
-#include "dh_groups.h"
+#include "crypto/dh_groups.h"
#include "ikev2.h"
diff --git a/contrib/wpa/src/eap_server/tncs.c b/contrib/wpa/src/eap_server/tncs.c
index 21d83b3..497b51a 100644
--- a/contrib/wpa/src/eap_server/tncs.c
+++ b/contrib/wpa/src/eap_server/tncs.c
@@ -1231,6 +1231,7 @@ void tncs_global_deinit(void)
}
os_free(tncs_global_data);
+ tncs_global_data = NULL;
}
diff --git a/contrib/wpa/src/eapol_auth/Makefile b/contrib/wpa/src/eapol_auth/Makefile
new file mode 100644
index 0000000..9c41962
--- /dev/null
+++ b/contrib/wpa/src/eapol_auth/Makefile
@@ -0,0 +1,8 @@
+all:
+ @echo Nothing to be made.
+
+clean:
+ rm -f *~ *.o *.d
+
+install:
+ @echo Nothing to be made.
diff --git a/contrib/wpa/src/eapol_auth/eapol_auth_dump.c b/contrib/wpa/src/eapol_auth/eapol_auth_dump.c
new file mode 100644
index 0000000..a0f0e8d
--- /dev/null
+++ b/contrib/wpa/src/eapol_auth/eapol_auth_dump.c
@@ -0,0 +1,231 @@
+/*
+ * IEEE 802.1X-2004 Authenticator - State dump
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "eap_server/eap.h"
+#include "eapol_auth_sm.h"
+#include "eapol_auth_sm_i.h"
+
+static inline const char * port_type_txt(PortTypes pt)
+{
+ switch (pt) {
+ case ForceUnauthorized: return "ForceUnauthorized";
+ case ForceAuthorized: return "ForceAuthorized";
+ case Auto: return "Auto";
+ default: return "Unknown";
+ }
+}
+
+
+static inline const char * port_state_txt(PortState ps)
+{
+ switch (ps) {
+ case Unauthorized: return "Unauthorized";
+ case Authorized: return "Authorized";
+ default: return "Unknown";
+ }
+}
+
+
+static inline const char * ctrl_dir_txt(ControlledDirection dir)
+{
+ switch (dir) {
+ case Both: return "Both";
+ case In: return "In";
+ default: return "Unknown";
+ }
+}
+
+
+static inline const char * auth_pae_state_txt(int s)
+{
+ switch (s) {
+ case AUTH_PAE_INITIALIZE: return "INITIALIZE";
+ case AUTH_PAE_DISCONNECTED: return "DISCONNECTED";
+ case AUTH_PAE_CONNECTING: return "CONNECTING";
+ case AUTH_PAE_AUTHENTICATING: return "AUTHENTICATING";
+ case AUTH_PAE_AUTHENTICATED: return "AUTHENTICATED";
+ case AUTH_PAE_ABORTING: return "ABORTING";
+ case AUTH_PAE_HELD: return "HELD";
+ case AUTH_PAE_FORCE_AUTH: return "FORCE_AUTH";
+ case AUTH_PAE_FORCE_UNAUTH: return "FORCE_UNAUTH";
+ case AUTH_PAE_RESTART: return "RESTART";
+ default: return "Unknown";
+ }
+}
+
+
+static inline const char * be_auth_state_txt(int s)
+{
+ switch (s) {
+ case BE_AUTH_REQUEST: return "REQUEST";
+ case BE_AUTH_RESPONSE: return "RESPONSE";
+ case BE_AUTH_SUCCESS: return "SUCCESS";
+ case BE_AUTH_FAIL: return "FAIL";
+ case BE_AUTH_TIMEOUT: return "TIMEOUT";
+ case BE_AUTH_IDLE: return "IDLE";
+ case BE_AUTH_INITIALIZE: return "INITIALIZE";
+ case BE_AUTH_IGNORE: return "IGNORE";
+ default: return "Unknown";
+ }
+}
+
+
+static inline const char * reauth_timer_state_txt(int s)
+{
+ switch (s) {
+ case REAUTH_TIMER_INITIALIZE: return "INITIALIZE";
+ case REAUTH_TIMER_REAUTHENTICATE: return "REAUTHENTICATE";
+ default: return "Unknown";
+ }
+}
+
+
+static inline const char * auth_key_tx_state_txt(int s)
+{
+ switch (s) {
+ case AUTH_KEY_TX_NO_KEY_TRANSMIT: return "NO_KEY_TRANSMIT";
+ case AUTH_KEY_TX_KEY_TRANSMIT: return "KEY_TRANSMIT";
+ default: return "Unknown";
+ }
+}
+
+
+static inline const char * key_rx_state_txt(int s)
+{
+ switch (s) {
+ case KEY_RX_NO_KEY_RECEIVE: return "NO_KEY_RECEIVE";
+ case KEY_RX_KEY_RECEIVE: return "KEY_RECEIVE";
+ default: return "Unknown";
+ }
+}
+
+
+static inline const char * ctrl_dir_state_txt(int s)
+{
+ switch (s) {
+ case CTRL_DIR_FORCE_BOTH: return "FORCE_BOTH";
+ case CTRL_DIR_IN_OR_BOTH: return "IN_OR_BOTH";
+ default: return "Unknown";
+ }
+}
+
+
+void eapol_auth_dump_state(FILE *f, const char *prefix,
+ struct eapol_state_machine *sm)
+{
+ fprintf(f, "%sEAPOL state machine:\n", prefix);
+ fprintf(f, "%s aWhile=%d quietWhile=%d reAuthWhen=%d\n", prefix,
+ sm->aWhile, sm->quietWhile, sm->reAuthWhen);
+#define _SB(b) ((b) ? "TRUE" : "FALSE")
+ fprintf(f,
+ "%s authAbort=%s authFail=%s authPortStatus=%s authStart=%s\n"
+ "%s authTimeout=%s authSuccess=%s eapFail=%s eapolEap=%s\n"
+ "%s eapSuccess=%s eapTimeout=%s initialize=%s "
+ "keyAvailable=%s\n"
+ "%s keyDone=%s keyRun=%s keyTxEnabled=%s portControl=%s\n"
+ "%s portEnabled=%s portValid=%s reAuthenticate=%s\n",
+ prefix, _SB(sm->authAbort), _SB(sm->authFail),
+ port_state_txt(sm->authPortStatus), _SB(sm->authStart),
+ prefix, _SB(sm->authTimeout), _SB(sm->authSuccess),
+ _SB(sm->eap_if->eapFail), _SB(sm->eapolEap),
+ prefix, _SB(sm->eap_if->eapSuccess),
+ _SB(sm->eap_if->eapTimeout),
+ _SB(sm->initialize), _SB(sm->eap_if->eapKeyAvailable),
+ prefix, _SB(sm->keyDone), _SB(sm->keyRun),
+ _SB(sm->keyTxEnabled), port_type_txt(sm->portControl),
+ prefix, _SB(sm->eap_if->portEnabled), _SB(sm->portValid),
+ _SB(sm->reAuthenticate));
+
+ fprintf(f, "%s Authenticator PAE:\n"
+ "%s state=%s\n"
+ "%s eapolLogoff=%s eapolStart=%s eapRestart=%s\n"
+ "%s portMode=%s reAuthCount=%d\n"
+ "%s quietPeriod=%d reAuthMax=%d\n"
+ "%s authEntersConnecting=%d\n"
+ "%s authEapLogoffsWhileConnecting=%d\n"
+ "%s authEntersAuthenticating=%d\n"
+ "%s authAuthSuccessesWhileAuthenticating=%d\n"
+ "%s authAuthTimeoutsWhileAuthenticating=%d\n"
+ "%s authAuthFailWhileAuthenticating=%d\n"
+ "%s authAuthEapStartsWhileAuthenticating=%d\n"
+ "%s authAuthEapLogoffWhileAuthenticating=%d\n"
+ "%s authAuthReauthsWhileAuthenticated=%d\n"
+ "%s authAuthEapStartsWhileAuthenticated=%d\n"
+ "%s authAuthEapLogoffWhileAuthenticated=%d\n",
+ prefix, prefix, auth_pae_state_txt(sm->auth_pae_state), prefix,
+ _SB(sm->eapolLogoff), _SB(sm->eapolStart),
+ _SB(sm->eap_if->eapRestart),
+ prefix, port_type_txt(sm->portMode), sm->reAuthCount,
+ prefix, sm->quietPeriod, sm->reAuthMax,
+ prefix, sm->authEntersConnecting,
+ prefix, sm->authEapLogoffsWhileConnecting,
+ prefix, sm->authEntersAuthenticating,
+ prefix, sm->authAuthSuccessesWhileAuthenticating,
+ prefix, sm->authAuthTimeoutsWhileAuthenticating,
+ prefix, sm->authAuthFailWhileAuthenticating,
+ prefix, sm->authAuthEapStartsWhileAuthenticating,
+ prefix, sm->authAuthEapLogoffWhileAuthenticating,
+ prefix, sm->authAuthReauthsWhileAuthenticated,
+ prefix, sm->authAuthEapStartsWhileAuthenticated,
+ prefix, sm->authAuthEapLogoffWhileAuthenticated);
+
+ fprintf(f, "%s Backend Authentication:\n"
+ "%s state=%s\n"
+ "%s eapNoReq=%s eapReq=%s eapResp=%s\n"
+ "%s serverTimeout=%d\n"
+ "%s backendResponses=%d\n"
+ "%s backendAccessChallenges=%d\n"
+ "%s backendOtherRequestsToSupplicant=%d\n"
+ "%s backendAuthSuccesses=%d\n"
+ "%s backendAuthFails=%d\n",
+ prefix, prefix,
+ be_auth_state_txt(sm->be_auth_state),
+ prefix, _SB(sm->eap_if->eapNoReq), _SB(sm->eap_if->eapReq),
+ _SB(sm->eap_if->eapResp),
+ prefix, sm->serverTimeout,
+ prefix, sm->backendResponses,
+ prefix, sm->backendAccessChallenges,
+ prefix, sm->backendOtherRequestsToSupplicant,
+ prefix, sm->backendAuthSuccesses,
+ prefix, sm->backendAuthFails);
+
+ fprintf(f, "%s Reauthentication Timer:\n"
+ "%s state=%s\n"
+ "%s reAuthPeriod=%d reAuthEnabled=%s\n", prefix, prefix,
+ reauth_timer_state_txt(sm->reauth_timer_state), prefix,
+ sm->reAuthPeriod, _SB(sm->reAuthEnabled));
+
+ fprintf(f, "%s Authenticator Key Transmit:\n"
+ "%s state=%s\n", prefix, prefix,
+ auth_key_tx_state_txt(sm->auth_key_tx_state));
+
+ fprintf(f, "%s Key Receive:\n"
+ "%s state=%s\n"
+ "%s rxKey=%s\n", prefix, prefix,
+ key_rx_state_txt(sm->key_rx_state), prefix, _SB(sm->rxKey));
+
+ fprintf(f, "%s Controlled Directions:\n"
+ "%s state=%s\n"
+ "%s adminControlledDirections=%s "
+ "operControlledDirections=%s\n"
+ "%s operEdge=%s\n", prefix, prefix,
+ ctrl_dir_state_txt(sm->ctrl_dir_state),
+ prefix, ctrl_dir_txt(sm->adminControlledDirections),
+ ctrl_dir_txt(sm->operControlledDirections),
+ prefix, _SB(sm->operEdge));
+#undef _SB
+}
diff --git a/contrib/wpa/hostapd/eapol_sm.c b/contrib/wpa/src/eapol_auth/eapol_auth_sm.c
index 8e9d56c..a1976e8 100644
--- a/contrib/wpa/hostapd/eapol_sm.c
+++ b/contrib/wpa/src/eapol_auth/eapol_auth_sm.c
@@ -1,6 +1,6 @@
/*
- * hostapd / IEEE 802.1X-2004 Authenticator - EAPOL state machine
- * Copyright (c) 2002-2008, Jouni Malinen <j@w1.fi>
+ * IEEE 802.1X-2004 Authenticator - EAPOL state machine
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -14,16 +14,15 @@
#include "includes.h"
-#include "hostapd.h"
-#include "ieee802_1x.h"
-#include "eapol_sm.h"
+#include "common.h"
#include "eloop.h"
-#include "wpa.h"
-#include "preauth.h"
-#include "sta_info.h"
-#include "eap_server/eap.h"
#include "state_machine.h"
+#include "common/eapol_common.h"
+#include "eap_common/eap_defs.h"
#include "eap_common/eap_common.h"
+#include "eap_server/eap.h"
+#include "eapol_auth_sm.h"
+#include "eapol_auth_sm_i.h"
#define STATE_MACHINE_DATA struct eapol_state_machine
#define STATE_MACHINE_DEBUG_PREFIX "IEEE 802.1X"
@@ -34,35 +33,36 @@ static struct eapol_callbacks eapol_cb;
/* EAPOL state machines are described in IEEE Std 802.1X-2004, Chap. 8.2 */
#define setPortAuthorized() \
-sm->eapol->cb.set_port_authorized(sm->hapd, sm->sta, 1)
+sm->eapol->cb.set_port_authorized(sm->eapol->conf.ctx, sm->sta, 1)
#define setPortUnauthorized() \
-sm->eapol->cb.set_port_authorized(sm->hapd, sm->sta, 0)
+sm->eapol->cb.set_port_authorized(sm->eapol->conf.ctx, sm->sta, 0)
/* procedures */
#define txCannedFail() eapol_auth_tx_canned_eap(sm, 0)
#define txCannedSuccess() eapol_auth_tx_canned_eap(sm, 1)
#define txReq() eapol_auth_tx_req(sm)
-#define abortAuth() sm->eapol->cb.abort_auth(sm->hapd, sm->sta)
-#define txKey() sm->eapol->cb.tx_key(sm->hapd, sm->sta)
+#define abortAuth() sm->eapol->cb.abort_auth(sm->eapol->conf.ctx, sm->sta)
+#define txKey() sm->eapol->cb.tx_key(sm->eapol->conf.ctx, sm->sta)
#define processKey() do { } while (0)
static void eapol_sm_step_run(struct eapol_state_machine *sm);
static void eapol_sm_step_cb(void *eloop_ctx, void *timeout_ctx);
+static void eapol_auth_initialize(struct eapol_state_machine *sm);
static void eapol_auth_logger(struct eapol_authenticator *eapol,
- const u8 *addr, logger_level level,
+ const u8 *addr, eapol_logger_level level,
const char *txt)
{
if (eapol->cb.logger == NULL)
return;
- eapol->cb.logger(eapol->conf.hapd, addr, level, txt);
+ eapol->cb.logger(eapol->conf.ctx, addr, level, txt);
}
static void eapol_auth_vlogger(struct eapol_authenticator *eapol,
- const u8 *addr, logger_level level,
+ const u8 *addr, eapol_logger_level level,
const char *fmt, ...)
{
char *format;
@@ -101,7 +101,8 @@ static void eapol_auth_tx_canned_eap(struct eapol_state_machine *sm,
eapol_auth_vlogger(sm->eapol, sm->addr, EAPOL_LOGGER_DEBUG,
"Sending canned EAP packet %s (identifier %d)",
success ? "SUCCESS" : "FAILURE", eap.identifier);
- sm->eapol->cb.eapol_send(sm->hapd, sm->sta, IEEE802_1X_TYPE_EAP_PACKET,
+ sm->eapol->cb.eapol_send(sm->eapol->conf.ctx, sm->sta,
+ IEEE802_1X_TYPE_EAP_PACKET,
(u8 *) &eap, sizeof(eap));
sm->dot1xAuthEapolFramesTx++;
}
@@ -129,7 +130,8 @@ static void eapol_auth_tx_req(struct eapol_state_machine *sm)
eapol_auth_vlogger(sm->eapol, sm->addr, EAPOL_LOGGER_DEBUG,
"Sending EAP Packet (identifier %d)",
sm->last_eap_id);
- sm->eapol->cb.eapol_send(sm->hapd, sm->sta, IEEE802_1X_TYPE_EAP_PACKET,
+ sm->eapol->cb.eapol_send(sm->eapol->conf.ctx, sm->sta,
+ IEEE802_1X_TYPE_EAP_PACKET,
wpabuf_head(sm->eap_if->eapReqData),
wpabuf_len(sm->eap_if->eapReqData));
sm->dot1xAuthEapolFramesTx++;
@@ -222,7 +224,7 @@ SM_STATE(AUTH_PAE, DISCONNECTED)
sm->reAuthCount = 0;
sm->eapolLogoff = FALSE;
if (!from_initialize) {
- sm->eapol->cb.finished(sm->hapd, sm->sta, 0,
+ sm->eapol->cb.finished(sm->eapol->conf.ctx, sm->sta, 0,
sm->flags & EAPOL_SM_PREAUTH);
}
}
@@ -272,14 +274,14 @@ SM_STATE(AUTH_PAE, HELD)
eapol_auth_vlogger(sm->eapol, sm->addr, EAPOL_LOGGER_WARNING,
"authentication failed - EAP type: %d (%s)",
sm->eap_type_authsrv,
- eap_type_text(sm->eap_type_authsrv));
+ eap_server_get_name(0, sm->eap_type_authsrv));
if (sm->eap_type_authsrv != sm->eap_type_supp) {
eapol_auth_vlogger(sm->eapol, sm->addr, EAPOL_LOGGER_INFO,
"Supplicant used different EAP type: "
"%d (%s)", sm->eap_type_supp,
- eap_type_text(sm->eap_type_supp));
+ eap_server_get_name(0, sm->eap_type_supp));
}
- sm->eapol->cb.finished(sm->hapd, sm->sta, 0,
+ sm->eapol->cb.finished(sm->eapol->conf.ctx, sm->sta, 0,
sm->flags & EAPOL_SM_PREAUTH);
}
@@ -298,13 +300,14 @@ SM_STATE(AUTH_PAE, AUTHENTICATED)
sm->reAuthCount = 0;
if (sm->flags & EAPOL_SM_PREAUTH)
extra = " (pre-authentication)";
- else if (wpa_auth_sta_get_pmksa(sm->sta->wpa_sm))
+ else if (sm->flags & EAPOL_SM_FROM_PMKSA_CACHE)
extra = " (PMKSA cache)";
eapol_auth_vlogger(sm->eapol, sm->addr, EAPOL_LOGGER_INFO,
"authenticated - EAP type: %d (%s)%s",
sm->eap_type_authsrv,
- eap_type_text(sm->eap_type_authsrv), extra);
- sm->eapol->cb.finished(sm->hapd, sm->sta, 1,
+ eap_server_get_name(0, sm->eap_type_authsrv),
+ extra);
+ sm->eapol->cb.finished(sm->eapol->conf.ctx, sm->sta, 1,
sm->flags & EAPOL_SM_PREAUTH);
}
@@ -611,7 +614,8 @@ SM_STATE(REAUTH_TIMER, REAUTHENTICATE)
SM_ENTRY_MA(REAUTH_TIMER, REAUTHENTICATE, reauth_timer);
sm->reAuthenticate = TRUE;
- wpa_auth_sm_event(sm->sta->wpa_sm, WPA_REAUTH_EAPOL);
+ sm->eapol->cb.eapol_event(sm->eapol->conf.ctx, sm->sta,
+ EAPOL_AUTH_REAUTHENTICATE);
}
@@ -664,7 +668,7 @@ SM_STEP(AUTH_KEY_TX)
switch (sm->auth_key_tx_state) {
case AUTH_KEY_TX_NO_KEY_TRANSMIT:
if (sm->keyTxEnabled && sm->eap_if->eapKeyAvailable &&
- sm->keyRun && !wpa_auth_sta_wpa_version(sm->sta->wpa_sm))
+ sm->keyRun && !(sm->flags & EAPOL_SM_USES_WPA))
SM_ENTER(AUTH_KEY_TX, KEY_TRANSMIT);
break;
case AUTH_KEY_TX_KEY_TRANSMIT:
@@ -758,15 +762,13 @@ SM_STEP(CTRL_DIR)
struct eapol_state_machine *
eapol_auth_alloc(struct eapol_authenticator *eapol, const u8 *addr,
- int preauth, struct sta_info *sta)
+ int flags, const struct wpabuf *assoc_wps_ie, void *sta_ctx)
{
struct eapol_state_machine *sm;
- struct hostapd_data *hapd; /* TODO: to be removed */
struct eap_config eap_conf;
if (eapol == NULL)
return NULL;
- hapd = eapol->conf.hapd;
sm = os_zalloc(sizeof(*sm));
if (sm == NULL) {
@@ -776,12 +778,10 @@ eapol_auth_alloc(struct eapol_authenticator *eapol, const u8 *addr,
}
sm->radius_identifier = -1;
os_memcpy(sm->addr, addr, ETH_ALEN);
- if (preauth)
- sm->flags |= EAPOL_SM_PREAUTH;
+ sm->flags = flags;
- sm->hapd = hapd;
sm->eapol = eapol;
- sm->sta = sta;
+ sm->sta = sta_ctx;
/* Set default values for state machine constants */
sm->auth_pae_state = AUTH_PAE_INITIALIZE;
@@ -804,7 +804,7 @@ eapol_auth_alloc(struct eapol_authenticator *eapol, const u8 *addr,
sm->portControl = Auto;
if (!eapol->conf.wpa &&
- (hapd->default_wep_key || eapol->conf.individual_wep_key_len > 0))
+ (eapol->default_wep_key || eapol->conf.individual_wep_key_len > 0))
sm->keyTxEnabled = TRUE;
else
sm->keyTxEnabled = FALSE;
@@ -816,6 +816,7 @@ eapol_auth_alloc(struct eapol_authenticator *eapol, const u8 *addr,
os_memset(&eap_conf, 0, sizeof(eap_conf));
eap_conf.eap_server = eapol->conf.eap_server;
eap_conf.ssl_ctx = eapol->conf.ssl_ctx;
+ eap_conf.msg_ctx = eapol->conf.msg_ctx;
eap_conf.eap_sim_db_priv = eapol->conf.eap_sim_db_priv;
eap_conf.pac_opaque_encr_key = eapol->conf.pac_opaque_encr_key;
eap_conf.eap_fast_a_id = eapol->conf.eap_fast_a_id;
@@ -827,7 +828,8 @@ eapol_auth_alloc(struct eapol_authenticator *eapol, const u8 *addr,
eap_conf.eap_sim_aka_result_ind = eapol->conf.eap_sim_aka_result_ind;
eap_conf.tnc = eapol->conf.tnc;
eap_conf.wps = eapol->conf.wps;
- eap_conf.assoc_wps_ie = sta->wps_ie;
+ eap_conf.assoc_wps_ie = assoc_wps_ie;
+ eap_conf.peer_addr = addr;
sm->eap = eap_server_sm_init(sm, &eapol_cb, &eap_conf);
if (sm->eap == NULL) {
eapol_auth_free(sm);
@@ -857,7 +859,7 @@ void eapol_auth_free(struct eapol_state_machine *sm)
static int eapol_sm_sta_entry_alive(struct eapol_authenticator *eapol,
const u8 *addr)
{
- return eapol->cb.sta_entry_alive(eapol->conf.hapd, addr);
+ return eapol->cb.sta_entry_alive(eapol->conf.ctx, addr);
}
@@ -928,14 +930,15 @@ restart:
return;
}
sm->eapol->cb.aaa_send(
- sm->hapd, sm->sta,
+ sm->eapol->conf.ctx, sm->sta,
wpabuf_head(sm->eap_if->aaaEapRespData),
wpabuf_len(sm->eap_if->aaaEapRespData));
}
}
if (eapol_sm_sta_entry_alive(eapol, addr))
- wpa_auth_sm_notify(sm->sta->wpa_sm);
+ sm->eapol->cb.eapol_event(sm->eapol->conf.ctx, sm->sta,
+ EAPOL_AUTH_SM_CHANGE);
}
@@ -965,7 +968,7 @@ void eapol_auth_step(struct eapol_state_machine *sm)
}
-void eapol_auth_initialize(struct eapol_state_machine *sm)
+static void eapol_auth_initialize(struct eapol_state_machine *sm)
{
sm->initializing = TRUE;
/* Initialize the state machines by asserting initialize and then
@@ -982,227 +985,13 @@ void eapol_auth_initialize(struct eapol_state_machine *sm)
}
-#ifdef HOSTAPD_DUMP_STATE
-static inline const char * port_type_txt(PortTypes pt)
-{
- switch (pt) {
- case ForceUnauthorized: return "ForceUnauthorized";
- case ForceAuthorized: return "ForceAuthorized";
- case Auto: return "Auto";
- default: return "Unknown";
- }
-}
-
-
-static inline const char * port_state_txt(PortState ps)
-{
- switch (ps) {
- case Unauthorized: return "Unauthorized";
- case Authorized: return "Authorized";
- default: return "Unknown";
- }
-}
-
-
-static inline const char * ctrl_dir_txt(ControlledDirection dir)
-{
- switch (dir) {
- case Both: return "Both";
- case In: return "In";
- default: return "Unknown";
- }
-}
-
-
-static inline const char * auth_pae_state_txt(int s)
-{
- switch (s) {
- case AUTH_PAE_INITIALIZE: return "INITIALIZE";
- case AUTH_PAE_DISCONNECTED: return "DISCONNECTED";
- case AUTH_PAE_CONNECTING: return "CONNECTING";
- case AUTH_PAE_AUTHENTICATING: return "AUTHENTICATING";
- case AUTH_PAE_AUTHENTICATED: return "AUTHENTICATED";
- case AUTH_PAE_ABORTING: return "ABORTING";
- case AUTH_PAE_HELD: return "HELD";
- case AUTH_PAE_FORCE_AUTH: return "FORCE_AUTH";
- case AUTH_PAE_FORCE_UNAUTH: return "FORCE_UNAUTH";
- case AUTH_PAE_RESTART: return "RESTART";
- default: return "Unknown";
- }
-}
-
-
-static inline const char * be_auth_state_txt(int s)
-{
- switch (s) {
- case BE_AUTH_REQUEST: return "REQUEST";
- case BE_AUTH_RESPONSE: return "RESPONSE";
- case BE_AUTH_SUCCESS: return "SUCCESS";
- case BE_AUTH_FAIL: return "FAIL";
- case BE_AUTH_TIMEOUT: return "TIMEOUT";
- case BE_AUTH_IDLE: return "IDLE";
- case BE_AUTH_INITIALIZE: return "INITIALIZE";
- case BE_AUTH_IGNORE: return "IGNORE";
- default: return "Unknown";
- }
-}
-
-
-static inline const char * reauth_timer_state_txt(int s)
-{
- switch (s) {
- case REAUTH_TIMER_INITIALIZE: return "INITIALIZE";
- case REAUTH_TIMER_REAUTHENTICATE: return "REAUTHENTICATE";
- default: return "Unknown";
- }
-}
-
-
-static inline const char * auth_key_tx_state_txt(int s)
-{
- switch (s) {
- case AUTH_KEY_TX_NO_KEY_TRANSMIT: return "NO_KEY_TRANSMIT";
- case AUTH_KEY_TX_KEY_TRANSMIT: return "KEY_TRANSMIT";
- default: return "Unknown";
- }
-}
-
-
-static inline const char * key_rx_state_txt(int s)
-{
- switch (s) {
- case KEY_RX_NO_KEY_RECEIVE: return "NO_KEY_RECEIVE";
- case KEY_RX_KEY_RECEIVE: return "KEY_RECEIVE";
- default: return "Unknown";
- }
-}
-
-
-static inline const char * ctrl_dir_state_txt(int s)
-{
- switch (s) {
- case CTRL_DIR_FORCE_BOTH: return "FORCE_BOTH";
- case CTRL_DIR_IN_OR_BOTH: return "IN_OR_BOTH";
- default: return "Unknown";
- }
-}
-
-
-void eapol_auth_dump_state(FILE *f, const char *prefix,
- struct eapol_state_machine *sm)
-{
- fprintf(f, "%sEAPOL state machine:\n", prefix);
- fprintf(f, "%s aWhile=%d quietWhile=%d reAuthWhen=%d\n", prefix,
- sm->aWhile, sm->quietWhile, sm->reAuthWhen);
-#define _SB(b) ((b) ? "TRUE" : "FALSE")
- fprintf(f,
- "%s authAbort=%s authFail=%s authPortStatus=%s authStart=%s\n"
- "%s authTimeout=%s authSuccess=%s eapFail=%s eapolEap=%s\n"
- "%s eapSuccess=%s eapTimeout=%s initialize=%s "
- "keyAvailable=%s\n"
- "%s keyDone=%s keyRun=%s keyTxEnabled=%s portControl=%s\n"
- "%s portEnabled=%s portValid=%s reAuthenticate=%s\n",
- prefix, _SB(sm->authAbort), _SB(sm->authFail),
- port_state_txt(sm->authPortStatus), _SB(sm->authStart),
- prefix, _SB(sm->authTimeout), _SB(sm->authSuccess),
- _SB(sm->eap_if->eapFail), _SB(sm->eapolEap),
- prefix, _SB(sm->eap_if->eapSuccess),
- _SB(sm->eap_if->eapTimeout),
- _SB(sm->initialize), _SB(sm->eap_if->eapKeyAvailable),
- prefix, _SB(sm->keyDone), _SB(sm->keyRun),
- _SB(sm->keyTxEnabled), port_type_txt(sm->portControl),
- prefix, _SB(sm->eap_if->portEnabled), _SB(sm->portValid),
- _SB(sm->reAuthenticate));
-
- fprintf(f, "%s Authenticator PAE:\n"
- "%s state=%s\n"
- "%s eapolLogoff=%s eapolStart=%s eapRestart=%s\n"
- "%s portMode=%s reAuthCount=%d\n"
- "%s quietPeriod=%d reAuthMax=%d\n"
- "%s authEntersConnecting=%d\n"
- "%s authEapLogoffsWhileConnecting=%d\n"
- "%s authEntersAuthenticating=%d\n"
- "%s authAuthSuccessesWhileAuthenticating=%d\n"
- "%s authAuthTimeoutsWhileAuthenticating=%d\n"
- "%s authAuthFailWhileAuthenticating=%d\n"
- "%s authAuthEapStartsWhileAuthenticating=%d\n"
- "%s authAuthEapLogoffWhileAuthenticating=%d\n"
- "%s authAuthReauthsWhileAuthenticated=%d\n"
- "%s authAuthEapStartsWhileAuthenticated=%d\n"
- "%s authAuthEapLogoffWhileAuthenticated=%d\n",
- prefix, prefix, auth_pae_state_txt(sm->auth_pae_state), prefix,
- _SB(sm->eapolLogoff), _SB(sm->eapolStart),
- _SB(sm->eap_if->eapRestart),
- prefix, port_type_txt(sm->portMode), sm->reAuthCount,
- prefix, sm->quietPeriod, sm->reAuthMax,
- prefix, sm->authEntersConnecting,
- prefix, sm->authEapLogoffsWhileConnecting,
- prefix, sm->authEntersAuthenticating,
- prefix, sm->authAuthSuccessesWhileAuthenticating,
- prefix, sm->authAuthTimeoutsWhileAuthenticating,
- prefix, sm->authAuthFailWhileAuthenticating,
- prefix, sm->authAuthEapStartsWhileAuthenticating,
- prefix, sm->authAuthEapLogoffWhileAuthenticating,
- prefix, sm->authAuthReauthsWhileAuthenticated,
- prefix, sm->authAuthEapStartsWhileAuthenticated,
- prefix, sm->authAuthEapLogoffWhileAuthenticated);
-
- fprintf(f, "%s Backend Authentication:\n"
- "%s state=%s\n"
- "%s eapNoReq=%s eapReq=%s eapResp=%s\n"
- "%s serverTimeout=%d\n"
- "%s backendResponses=%d\n"
- "%s backendAccessChallenges=%d\n"
- "%s backendOtherRequestsToSupplicant=%d\n"
- "%s backendAuthSuccesses=%d\n"
- "%s backendAuthFails=%d\n",
- prefix, prefix,
- be_auth_state_txt(sm->be_auth_state),
- prefix, _SB(sm->eap_if->eapNoReq), _SB(sm->eap_if->eapReq),
- _SB(sm->eap_if->eapResp),
- prefix, sm->serverTimeout,
- prefix, sm->backendResponses,
- prefix, sm->backendAccessChallenges,
- prefix, sm->backendOtherRequestsToSupplicant,
- prefix, sm->backendAuthSuccesses,
- prefix, sm->backendAuthFails);
-
- fprintf(f, "%s Reauthentication Timer:\n"
- "%s state=%s\n"
- "%s reAuthPeriod=%d reAuthEnabled=%s\n", prefix, prefix,
- reauth_timer_state_txt(sm->reauth_timer_state), prefix,
- sm->reAuthPeriod, _SB(sm->reAuthEnabled));
-
- fprintf(f, "%s Authenticator Key Transmit:\n"
- "%s state=%s\n", prefix, prefix,
- auth_key_tx_state_txt(sm->auth_key_tx_state));
-
- fprintf(f, "%s Key Receive:\n"
- "%s state=%s\n"
- "%s rxKey=%s\n", prefix, prefix,
- key_rx_state_txt(sm->key_rx_state), prefix, _SB(sm->rxKey));
-
- fprintf(f, "%s Controlled Directions:\n"
- "%s state=%s\n"
- "%s adminControlledDirections=%s "
- "operControlledDirections=%s\n"
- "%s operEdge=%s\n", prefix, prefix,
- ctrl_dir_state_txt(sm->ctrl_dir_state),
- prefix, ctrl_dir_txt(sm->adminControlledDirections),
- ctrl_dir_txt(sm->operControlledDirections),
- prefix, _SB(sm->operEdge));
-#undef _SB
-}
-#endif /* HOSTAPD_DUMP_STATE */
-
-
static int eapol_sm_get_eap_user(void *ctx, const u8 *identity,
size_t identity_len, int phase2,
struct eap_user *user)
{
struct eapol_state_machine *sm = ctx;
- return sm->eapol->cb.get_eap_user(sm->hapd, identity, identity_len,
- phase2, user);
+ return sm->eapol->cb.get_eap_user(sm->eapol->conf.ctx, identity,
+ identity_len, phase2, user);
}
@@ -1216,8 +1005,8 @@ static const char * eapol_sm_get_eap_req_id_text(void *ctx, size_t *len)
static struct eapol_callbacks eapol_cb =
{
- .get_eap_user = eapol_sm_get_eap_user,
- .get_eap_req_id_text = eapol_sm_get_eap_req_id_text,
+ eapol_sm_get_eap_user,
+ eapol_sm_get_eap_req_id_text
};
@@ -1236,12 +1025,13 @@ int eapol_auth_eap_pending_cb(struct eapol_state_machine *sm, void *ctx)
static int eapol_auth_conf_clone(struct eapol_auth_config *dst,
struct eapol_auth_config *src)
{
- dst->hapd = src->hapd;
+ dst->ctx = src->ctx;
dst->eap_reauth_period = src->eap_reauth_period;
dst->wpa = src->wpa;
dst->individual_wep_key_len = src->individual_wep_key_len;
dst->eap_server = src->eap_server;
dst->ssl_ctx = src->ssl_ctx;
+ dst->msg_ctx = src->msg_ctx;
dst->eap_sim_db_priv = src->eap_sim_db_priv;
os_free(dst->eap_req_id_text);
if (src->eap_req_id_text) {
@@ -1318,6 +1108,11 @@ struct eapol_authenticator * eapol_auth_init(struct eapol_auth_config *conf,
return NULL;
}
+ if (conf->individual_wep_key_len > 0) {
+ /* use key0 in individual key and key1 in broadcast key */
+ eapol->default_wep_key_idx = 1;
+ }
+
eapol->cb.eapol_send = cb->eapol_send;
eapol->cb.aaa_send = cb->aaa_send;
eapol->cb.finished = cb->finished;
@@ -1327,6 +1122,7 @@ struct eapol_authenticator * eapol_auth_init(struct eapol_auth_config *conf,
eapol->cb.set_port_authorized = cb->set_port_authorized;
eapol->cb.abort_auth = cb->abort_auth;
eapol->cb.tx_key = cb->tx_key;
+ eapol->cb.eapol_event = cb->eapol_event;
return eapol;
}
@@ -1338,5 +1134,6 @@ void eapol_auth_deinit(struct eapol_authenticator *eapol)
return;
eapol_auth_conf_free(&eapol->conf);
+ os_free(eapol->default_wep_key);
os_free(eapol);
}
diff --git a/contrib/wpa/src/eapol_auth/eapol_auth_sm.h b/contrib/wpa/src/eapol_auth/eapol_auth_sm.h
new file mode 100644
index 0000000..ef943ad
--- /dev/null
+++ b/contrib/wpa/src/eapol_auth/eapol_auth_sm.h
@@ -0,0 +1,89 @@
+/*
+ * IEEE 802.1X-2004 Authenticator - EAPOL state machine
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef EAPOL_AUTH_SM_H
+#define EAPOL_AUTH_SM_H
+
+#define EAPOL_SM_PREAUTH BIT(0)
+#define EAPOL_SM_WAIT_START BIT(1)
+#define EAPOL_SM_USES_WPA BIT(2)
+#define EAPOL_SM_FROM_PMKSA_CACHE BIT(3)
+
+struct eapol_auth_config {
+ int eap_reauth_period;
+ int wpa;
+ int individual_wep_key_len;
+ int eap_server;
+ void *ssl_ctx;
+ void *msg_ctx;
+ void *eap_sim_db_priv;
+ char *eap_req_id_text; /* a copy of this will be allocated */
+ size_t eap_req_id_text_len;
+ u8 *pac_opaque_encr_key;
+ u8 *eap_fast_a_id;
+ size_t eap_fast_a_id_len;
+ char *eap_fast_a_id_info;
+ int eap_fast_prov;
+ int pac_key_lifetime;
+ int pac_key_refresh_time;
+ int eap_sim_aka_result_ind;
+ int tnc;
+ struct wps_context *wps;
+
+ /* Opaque context pointer to owner data for callback functions */
+ void *ctx;
+};
+
+struct eap_user;
+
+typedef enum {
+ EAPOL_LOGGER_DEBUG, EAPOL_LOGGER_INFO, EAPOL_LOGGER_WARNING
+} eapol_logger_level;
+
+enum eapol_event {
+ EAPOL_AUTH_SM_CHANGE,
+ EAPOL_AUTH_REAUTHENTICATE
+};
+
+struct eapol_auth_cb {
+ void (*eapol_send)(void *ctx, void *sta_ctx, u8 type, const u8 *data,
+ size_t datalen);
+ void (*aaa_send)(void *ctx, void *sta_ctx, const u8 *data,
+ size_t datalen);
+ void (*finished)(void *ctx, void *sta_ctx, int success, int preauth);
+ int (*get_eap_user)(void *ctx, const u8 *identity, size_t identity_len,
+ int phase2, struct eap_user *user);
+ int (*sta_entry_alive)(void *ctx, const u8 *addr);
+ void (*logger)(void *ctx, const u8 *addr, eapol_logger_level level,
+ const char *txt);
+ void (*set_port_authorized)(void *ctx, void *sta_ctx, int authorized);
+ void (*abort_auth)(void *ctx, void *sta_ctx);
+ void (*tx_key)(void *ctx, void *sta_ctx);
+ void (*eapol_event)(void *ctx, void *sta_ctx, enum eapol_event type);
+};
+
+
+struct eapol_authenticator * eapol_auth_init(struct eapol_auth_config *conf,
+ struct eapol_auth_cb *cb);
+void eapol_auth_deinit(struct eapol_authenticator *eapol);
+struct eapol_state_machine *
+eapol_auth_alloc(struct eapol_authenticator *eapol, const u8 *addr,
+ int flags, const struct wpabuf *assoc_wps_ie, void *sta_ctx);
+void eapol_auth_free(struct eapol_state_machine *sm);
+void eapol_auth_step(struct eapol_state_machine *sm);
+void eapol_auth_dump_state(FILE *f, const char *prefix,
+ struct eapol_state_machine *sm);
+int eapol_auth_eap_pending_cb(struct eapol_state_machine *sm, void *ctx);
+
+#endif /* EAPOL_AUTH_SM_H */
diff --git a/contrib/wpa/hostapd/eapol_sm.h b/contrib/wpa/src/eapol_auth/eapol_auth_sm_i.h
index 7a13e8e..1000da4 100644
--- a/contrib/wpa/hostapd/eapol_sm.h
+++ b/contrib/wpa/src/eapol_auth/eapol_auth_sm_i.h
@@ -1,6 +1,6 @@
/*
- * hostapd / IEEE 802.1X-2004 Authenticator - EAPOL state machine
- * Copyright (c) 2002-2007, Jouni Malinen <j@w1.fi>
+ * IEEE 802.1X-2004 Authenticator - EAPOL state machine (internal definitions)
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -12,10 +12,11 @@
* See README and COPYING for more details.
*/
-#ifndef EAPOL_SM_H
-#define EAPOL_SM_H
+#ifndef EAPOL_AUTH_SM_I_H
+#define EAPOL_AUTH_SM_I_H
-#include "defs.h"
+#include "common/defs.h"
+#include "radius/radius.h"
/* IEEE Std 802.1X-2004, Ch. 8.2 */
@@ -25,68 +26,6 @@ typedef enum { Unauthorized = 2, Authorized = 1 } PortState;
typedef enum { Both = 0, In = 1 } ControlledDirection;
typedef unsigned int Counter;
-struct eap_sm;
-
-struct radius_attr_data {
- u8 *data;
- size_t len;
-};
-
-struct radius_class_data {
- struct radius_attr_data *attr;
- size_t count;
-};
-
-
-struct eapol_auth_config {
- int eap_reauth_period;
- int wpa;
- int individual_wep_key_len;
- int eap_server;
- void *ssl_ctx;
- void *eap_sim_db_priv;
- char *eap_req_id_text; /* a copy of this will be allocated */
- size_t eap_req_id_text_len;
- u8 *pac_opaque_encr_key;
- u8 *eap_fast_a_id;
- size_t eap_fast_a_id_len;
- char *eap_fast_a_id_info;
- int eap_fast_prov;
- int pac_key_lifetime;
- int pac_key_refresh_time;
- int eap_sim_aka_result_ind;
- int tnc;
- struct wps_context *wps;
-
- /*
- * Pointer to hostapd data. This is a temporary workaround for
- * transition phase and will be removed once IEEE 802.1X/EAPOL code is
- * separated more cleanly from rest of hostapd.
- */
- struct hostapd_data *hapd;
-};
-
-struct eap_user;
-
-typedef enum {
- EAPOL_LOGGER_DEBUG, EAPOL_LOGGER_INFO, EAPOL_LOGGER_WARNING
-} eapol_logger_level;
-
-struct eapol_auth_cb {
- void (*eapol_send)(void *ctx, void *sta_ctx, u8 type, const u8 *data,
- size_t datalen);
- void (*aaa_send)(void *ctx, void *sta_ctx, const u8 *data,
- size_t datalen);
- void (*finished)(void *ctx, void *sta_ctx, int success, int preauth);
- int (*get_eap_user)(void *ctx, const u8 *identity, size_t identity_len,
- int phase2, struct eap_user *user);
- int (*sta_entry_alive)(void *ctx, const u8 *addr);
- void (*logger)(void *ctx, const u8 *addr, eapol_logger_level level,
- const char *txt);
- void (*set_port_authorized)(void *ctx, void *sta_ctx, int authorized);
- void (*abort_auth)(void *ctx, void *sta_ctx);
- void (*tx_key)(void *ctx, void *sta_ctx);
-};
/**
* struct eapol_authenticator - Global EAPOL authenticator data
@@ -94,6 +33,9 @@ struct eapol_auth_cb {
struct eapol_authenticator {
struct eapol_auth_config conf;
struct eapol_auth_cb cb;
+
+ u8 *default_wep_key;
+ u8 default_wep_key_idx;
};
@@ -206,8 +148,6 @@ struct eapol_state_machine {
/* Other variables - not defined in IEEE 802.1X */
u8 addr[ETH_ALEN]; /* Supplicant address */
-#define EAPOL_SM_PREAUTH BIT(0)
-#define EAPOL_SM_WAIT_START BIT(1)
int flags; /* EAPOL_SM_* */
/* EAPOL/AAA <-> EAP full authenticator interface */
@@ -237,24 +177,7 @@ struct eapol_state_machine {
struct eapol_authenticator *eapol;
- /* Somewhat nasty pointers to global hostapd and STA data to avoid
- * passing these to every function */
- struct hostapd_data *hapd;
- struct sta_info *sta;
+ void *sta; /* station context pointer to use in callbacks */
};
-
-struct eapol_authenticator * eapol_auth_init(struct eapol_auth_config *conf,
- struct eapol_auth_cb *cb);
-void eapol_auth_deinit(struct eapol_authenticator *eapol);
-struct eapol_state_machine *
-eapol_auth_alloc(struct eapol_authenticator *eapol, const u8 *addr,
- int preauth, struct sta_info *sta);
-void eapol_auth_free(struct eapol_state_machine *sm);
-void eapol_auth_step(struct eapol_state_machine *sm);
-void eapol_auth_initialize(struct eapol_state_machine *sm);
-void eapol_auth_dump_state(FILE *f, const char *prefix,
- struct eapol_state_machine *sm);
-int eapol_auth_eap_pending_cb(struct eapol_state_machine *sm, void *ctx);
-
-#endif /* EAPOL_SM_H */
+#endif /* EAPOL_AUTH_SM_I_H */
diff --git a/contrib/wpa/src/eapol_supp/Makefile b/contrib/wpa/src/eapol_supp/Makefile
index cffba62..9c41962 100644
--- a/contrib/wpa/src/eapol_supp/Makefile
+++ b/contrib/wpa/src/eapol_supp/Makefile
@@ -2,7 +2,6 @@ all:
@echo Nothing to be made.
clean:
- for d in $(SUBDIRS); do make -C $$d clean; done
rm -f *~ *.o *.d
install:
diff --git a/contrib/wpa/src/eapol_supp/eapol_supp_sm.c b/contrib/wpa/src/eapol_supp/eapol_supp_sm.c
index d163049..77cd564 100644
--- a/contrib/wpa/src/eapol_supp/eapol_supp_sm.c
+++ b/contrib/wpa/src/eapol_supp/eapol_supp_sm.c
@@ -15,14 +15,14 @@
#include "includes.h"
#include "common.h"
-#include "eapol_supp_sm.h"
-#include "eap_peer/eap.h"
-#include "eloop.h"
-#include "eapol_common.h"
-#include "md5.h"
-#include "rc4.h"
#include "state_machine.h"
#include "wpabuf.h"
+#include "eloop.h"
+#include "crypto/crypto.h"
+#include "crypto/md5.h"
+#include "common/eapol_common.h"
+#include "eap_peer/eap.h"
+#include "eapol_supp_sm.h"
#define STATE_MACHINE_DATA struct eapol_sm
#define STATE_MACHINE_DEBUG_PREFIX "EAPOL"
@@ -193,6 +193,8 @@ static void eapol_sm_txSuppRsp(struct eapol_sm *sm);
static void eapol_sm_abortSupp(struct eapol_sm *sm);
static void eapol_sm_abort_cached(struct eapol_sm *sm);
static void eapol_sm_step_timeout(void *eloop_ctx, void *timeout_ctx);
+static void eapol_sm_set_port_authorized(struct eapol_sm *sm);
+static void eapol_sm_set_port_unauthorized(struct eapol_sm *sm);
/* Port Timers state machine - implemented as a function that will be called
@@ -250,6 +252,7 @@ SM_STATE(SUPP_PAE, LOGOFF)
eapol_sm_txLogoff(sm);
sm->logoffSent = TRUE;
sm->suppPortStatus = Unauthorized;
+ eapol_sm_set_port_unauthorized(sm);
}
@@ -260,6 +263,7 @@ SM_STATE(SUPP_PAE, DISCONNECTED)
sm->startCount = 0;
sm->logoffSent = FALSE;
sm->suppPortStatus = Unauthorized;
+ eapol_sm_set_port_unauthorized(sm);
sm->suppAbort = TRUE;
sm->unicast_key_received = FALSE;
@@ -315,6 +319,7 @@ SM_STATE(SUPP_PAE, HELD)
sm->heldWhile = sm->heldPeriod;
eapol_enable_timer_tick(sm);
sm->suppPortStatus = Unauthorized;
+ eapol_sm_set_port_unauthorized(sm);
sm->cb_status = EAPOL_CB_FAILURE;
}
@@ -323,6 +328,7 @@ SM_STATE(SUPP_PAE, AUTHENTICATED)
{
SM_ENTRY(SUPP_PAE, AUTHENTICATED);
sm->suppPortStatus = Authorized;
+ eapol_sm_set_port_authorized(sm);
sm->cb_status = EAPOL_CB_SUCCESS;
}
@@ -338,6 +344,7 @@ SM_STATE(SUPP_PAE, S_FORCE_AUTH)
{
SM_ENTRY(SUPP_PAE, S_FORCE_AUTH);
sm->suppPortStatus = Authorized;
+ eapol_sm_set_port_authorized(sm);
sm->sPortMode = ForceAuthorized;
}
@@ -346,6 +353,7 @@ SM_STATE(SUPP_PAE, S_FORCE_UNAUTH)
{
SM_ENTRY(SUPP_PAE, S_FORCE_UNAUTH);
sm->suppPortStatus = Unauthorized;
+ eapol_sm_set_port_unauthorized(sm);
sm->sPortMode = ForceUnauthorized;
eapol_sm_txLogoff(sm);
}
@@ -862,6 +870,20 @@ static void eapol_sm_step_timeout(void *eloop_ctx, void *timeout_ctx)
}
+static void eapol_sm_set_port_authorized(struct eapol_sm *sm)
+{
+ if (sm->ctx->port_cb)
+ sm->ctx->port_cb(sm->ctx->ctx, 1);
+}
+
+
+static void eapol_sm_set_port_unauthorized(struct eapol_sm *sm)
+{
+ if (sm->ctx->port_cb)
+ sm->ctx->port_cb(sm->ctx->ctx, 0);
+}
+
+
/**
* eapol_sm_step - EAPOL state machine step function
* @sm: Pointer to EAPOL state machine allocated with eapol_sm_init()
@@ -1456,6 +1478,7 @@ void eapol_sm_notify_cached(struct eapol_sm *sm)
wpa_printf(MSG_DEBUG, "EAPOL: PMKSA caching was used - skip EAPOL");
sm->SUPP_PAE_state = SUPP_PAE_AUTHENTICATED;
sm->suppPortStatus = Authorized;
+ eapol_sm_set_port_authorized(sm);
sm->portValid = TRUE;
eap_notify_success(sm->eap);
eapol_sm_step(sm);
@@ -1492,6 +1515,7 @@ static void eapol_sm_abort_cached(struct eapol_sm *sm)
sm->cached_pmk = FALSE;
sm->SUPP_PAE_state = SUPP_PAE_CONNECTING;
sm->suppPortStatus = Unauthorized;
+ eapol_sm_set_port_unauthorized(sm);
/* Make sure we do not start sending EAPOL-Start frames first, but
* instead move to RESTART state to start EAPOL authentication. */
@@ -1830,11 +1854,9 @@ struct eapol_sm *eapol_sm_init(struct eapol_ctx *ctx)
sm->authPeriod = 30;
os_memset(&conf, 0, sizeof(conf));
-#ifdef EAP_TLS_OPENSSL
conf.opensc_engine_path = ctx->opensc_engine_path;
conf.pkcs11_engine_path = ctx->pkcs11_engine_path;
conf.pkcs11_module_path = ctx->pkcs11_module_path;
-#endif /* EAP_TLS_OPENSSL */
conf.wps = ctx->wps;
sm->eap = eap_peer_sm_init(sm, &eapol_cb, sm->ctx->msg_ctx, &conf);
diff --git a/contrib/wpa/src/eapol_supp/eapol_supp_sm.h b/contrib/wpa/src/eapol_supp/eapol_supp_sm.h
index 57d7bc1a..1d2a32b 100644
--- a/contrib/wpa/src/eapol_supp/eapol_supp_sm.h
+++ b/contrib/wpa/src/eapol_supp/eapol_supp_sm.h
@@ -15,7 +15,7 @@
#ifndef EAPOL_SUPP_SM_H
#define EAPOL_SUPP_SM_H
-#include "defs.h"
+#include "common/defs.h"
typedef enum { Unauthorized, Authorized } PortStatus;
typedef enum { Auto, ForceUnauthorized, ForceAuthorized } PortControl;
@@ -173,7 +173,6 @@ struct eapol_ctx {
*/
void (*aborted_cached)(void *ctx);
-#ifdef EAP_TLS_OPENSSL
/**
* opensc_engine_path - Path to the OpenSSL engine for opensc
*
@@ -198,7 +197,6 @@ struct eapol_ctx {
* module is not loaded.
*/
const char *pkcs11_module_path;
-#endif /* EAP_TLS_OPENSSL */
/**
* wps - WPS context data
@@ -215,6 +213,13 @@ struct eapol_ctx {
*/
void (*eap_param_needed)(void *ctx, const char *field,
const char *txt);
+
+ /**
+ * port_cb - Set port authorized/unauthorized callback (optional)
+ * @ctx: Callback context (ctx)
+ * @authorized: Whether the supplicant port is now in authorized state
+ */
+ void (*port_cb)(void *ctx, int authorized);
};
diff --git a/contrib/wpa/src/hlr_auc_gw/milenage.c b/contrib/wpa/src/hlr_auc_gw/milenage.c
deleted file mode 100644
index 0ce5ef3..0000000
--- a/contrib/wpa/src/hlr_auc_gw/milenage.c
+++ /dev/null
@@ -1,1142 +0,0 @@
-/*
- * 3GPP AKA - Milenage algorithm (3GPP TS 35.205, .206, .207, .208)
- * Copyright (c) 2006-2007 <j@w1.fi>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
- *
- * This file implements an example authentication algorithm defined for 3GPP
- * AKA. This can be used to implement a simple HLR/AuC into hlr_auc_gw to allow
- * EAP-AKA to be tested properly with real USIM cards.
- *
- * This implementations assumes that the r1..r5 and c1..c5 constants defined in
- * TS 35.206 are used, i.e., r1=64, r2=0, r3=32, r4=64, r5=96, c1=00..00,
- * c2=00..01, c3=00..02, c4=00..04, c5=00..08. The block cipher is assumed to
- * be AES (Rijndael).
- */
-
-#include "includes.h"
-
-#include "common.h"
-#include "milenage.h"
-#include "aes_wrap.h"
-
-
-/**
- * milenage_f1 - Milenage f1 and f1* algorithms
- * @opc: OPc = 128-bit value derived from OP and K
- * @k: K = 128-bit subscriber key
- * @_rand: RAND = 128-bit random challenge
- * @sqn: SQN = 48-bit sequence number
- * @amf: AMF = 16-bit authentication management field
- * @mac_a: Buffer for MAC-A = 64-bit network authentication code, or %NULL
- * @mac_s: Buffer for MAC-S = 64-bit resync authentication code, or %NULL
- * Returns: 0 on success, -1 on failure
- */
-static int milenage_f1(const u8 *opc, const u8 *k, const u8 *_rand,
- const u8 *sqn, const u8 *amf, u8 *mac_a, u8 *mac_s)
-{
- u8 tmp1[16], tmp2[16], tmp3[16];
- int i;
-
- /* tmp1 = TEMP = E_K(RAND XOR OP_C) */
- for (i = 0; i < 16; i++)
- tmp1[i] = _rand[i] ^ opc[i];
- if (aes_128_encrypt_block(k, tmp1, tmp1))
- return -1;
-
- /* tmp2 = IN1 = SQN || AMF || SQN || AMF */
- os_memcpy(tmp2, sqn, 6);
- os_memcpy(tmp2 + 6, amf, 2);
- os_memcpy(tmp2 + 8, tmp2, 8);
-
- /* OUT1 = E_K(TEMP XOR rot(IN1 XOR OP_C, r1) XOR c1) XOR OP_C */
-
- /* rotate (tmp2 XOR OP_C) by r1 (= 0x40 = 8 bytes) */
- for (i = 0; i < 16; i++)
- tmp3[(i + 8) % 16] = tmp2[i] ^ opc[i];
- /* XOR with TEMP = E_K(RAND XOR OP_C) */
- for (i = 0; i < 16; i++)
- tmp3[i] ^= tmp1[i];
- /* XOR with c1 (= ..00, i.e., NOP) */
-
- /* f1 || f1* = E_K(tmp3) XOR OP_c */
- if (aes_128_encrypt_block(k, tmp3, tmp1))
- return -1;
- for (i = 0; i < 16; i++)
- tmp1[i] ^= opc[i];
- if (mac_a)
- os_memcpy(mac_a, tmp1, 8); /* f1 */
- if (mac_s)
- os_memcpy(mac_s, tmp1 + 8, 8); /* f1* */
- return 0;
-}
-
-
-/**
- * milenage_f2345 - Milenage f2, f3, f4, f5, f5* algorithms
- * @opc: OPc = 128-bit value derived from OP and K
- * @k: K = 128-bit subscriber key
- * @_rand: RAND = 128-bit random challenge
- * @res: Buffer for RES = 64-bit signed response (f2), or %NULL
- * @ck: Buffer for CK = 128-bit confidentiality key (f3), or %NULL
- * @ik: Buffer for IK = 128-bit integrity key (f4), or %NULL
- * @ak: Buffer for AK = 48-bit anonymity key (f5), or %NULL
- * @akstar: Buffer for AK = 48-bit anonymity key (f5*), or %NULL
- * Returns: 0 on success, -1 on failure
- */
-static int milenage_f2345(const u8 *opc, const u8 *k, const u8 *_rand,
- u8 *res, u8 *ck, u8 *ik, u8 *ak, u8 *akstar)
-{
- u8 tmp1[16], tmp2[16], tmp3[16];
- int i;
-
- /* tmp2 = TEMP = E_K(RAND XOR OP_C) */
- for (i = 0; i < 16; i++)
- tmp1[i] = _rand[i] ^ opc[i];
- if (aes_128_encrypt_block(k, tmp1, tmp2))
- return -1;
-
- /* OUT2 = E_K(rot(TEMP XOR OP_C, r2) XOR c2) XOR OP_C */
- /* OUT3 = E_K(rot(TEMP XOR OP_C, r3) XOR c3) XOR OP_C */
- /* OUT4 = E_K(rot(TEMP XOR OP_C, r4) XOR c4) XOR OP_C */
- /* OUT5 = E_K(rot(TEMP XOR OP_C, r5) XOR c5) XOR OP_C */
-
- /* f2 and f5 */
- /* rotate by r2 (= 0, i.e., NOP) */
- for (i = 0; i < 16; i++)
- tmp1[i] = tmp2[i] ^ opc[i];
- tmp1[15] ^= 1; /* XOR c2 (= ..01) */
- /* f5 || f2 = E_K(tmp1) XOR OP_c */
- if (aes_128_encrypt_block(k, tmp1, tmp3))
- return -1;
- for (i = 0; i < 16; i++)
- tmp3[i] ^= opc[i];
- if (res)
- os_memcpy(res, tmp3 + 8, 8); /* f2 */
- if (ak)
- os_memcpy(ak, tmp3, 6); /* f5 */
-
- /* f3 */
- if (ck) {
- /* rotate by r3 = 0x20 = 4 bytes */
- for (i = 0; i < 16; i++)
- tmp1[(i + 12) % 16] = tmp2[i] ^ opc[i];
- tmp1[15] ^= 2; /* XOR c3 (= ..02) */
- if (aes_128_encrypt_block(k, tmp1, ck))
- return -1;
- for (i = 0; i < 16; i++)
- ck[i] ^= opc[i];
- }
-
- /* f4 */
- if (ik) {
- /* rotate by r4 = 0x40 = 8 bytes */
- for (i = 0; i < 16; i++)
- tmp1[(i + 8) % 16] = tmp2[i] ^ opc[i];
- tmp1[15] ^= 4; /* XOR c4 (= ..04) */
- if (aes_128_encrypt_block(k, tmp1, ik))
- return -1;
- for (i = 0; i < 16; i++)
- ik[i] ^= opc[i];
- }
-
- /* f5* */
- if (akstar) {
- /* rotate by r5 = 0x60 = 12 bytes */
- for (i = 0; i < 16; i++)
- tmp1[(i + 4) % 16] = tmp2[i] ^ opc[i];
- tmp1[15] ^= 8; /* XOR c5 (= ..08) */
- if (aes_128_encrypt_block(k, tmp1, tmp1))
- return -1;
- for (i = 0; i < 6; i++)
- akstar[i] = tmp1[i] ^ opc[i];
- }
-
- return 0;
-}
-
-
-/**
- * milenage_generate - Generate AKA AUTN,IK,CK,RES
- * @opc: OPc = 128-bit operator variant algorithm configuration field (encr.)
- * @amf: AMF = 16-bit authentication management field
- * @k: K = 128-bit subscriber key
- * @sqn: SQN = 48-bit sequence number
- * @_rand: RAND = 128-bit random challenge
- * @autn: Buffer for AUTN = 128-bit authentication token
- * @ik: Buffer for IK = 128-bit integrity key (f4), or %NULL
- * @ck: Buffer for CK = 128-bit confidentiality key (f3), or %NULL
- * @res: Buffer for RES = 64-bit signed response (f2), or %NULL
- * @res_len: Max length for res; set to used length or 0 on failure
- */
-void milenage_generate(const u8 *opc, const u8 *amf, const u8 *k,
- const u8 *sqn, const u8 *_rand, u8 *autn, u8 *ik,
- u8 *ck, u8 *res, size_t *res_len)
-{
- int i;
- u8 mac_a[8], ak[6];
-
- if (*res_len < 8) {
- *res_len = 0;
- return;
- }
- if (milenage_f1(opc, k, _rand, sqn, amf, mac_a, NULL) ||
- milenage_f2345(opc, k, _rand, res, ck, ik, ak, NULL)) {
- *res_len = 0;
- return;
- }
- *res_len = 8;
-
- /* AUTN = (SQN ^ AK) || AMF || MAC */
- for (i = 0; i < 6; i++)
- autn[i] = sqn[i] ^ ak[i];
- os_memcpy(autn + 6, amf, 2);
- os_memcpy(autn + 8, mac_a, 8);
-}
-
-
-/**
- * milenage_auts - Milenage AUTS validation
- * @opc: OPc = 128-bit operator variant algorithm configuration field (encr.)
- * @k: K = 128-bit subscriber key
- * @_rand: RAND = 128-bit random challenge
- * @auts: AUTS = 112-bit authentication token from client
- * @sqn: Buffer for SQN = 48-bit sequence number
- * Returns: 0 = success (sqn filled), -1 on failure
- */
-int milenage_auts(const u8 *opc, const u8 *k, const u8 *_rand, const u8 *auts,
- u8 *sqn)
-{
- u8 amf[2] = { 0x00, 0x00 }; /* TS 33.102 v7.0.0, 6.3.3 */
- u8 ak[6], mac_s[8];
- int i;
-
- if (milenage_f2345(opc, k, _rand, NULL, NULL, NULL, NULL, ak))
- return -1;
- for (i = 0; i < 6; i++)
- sqn[i] = auts[i] ^ ak[i];
- if (milenage_f1(opc, k, _rand, sqn, amf, NULL, mac_s) ||
- memcmp(mac_s, auts + 6, 8) != 0)
- return -1;
- return 0;
-}
-
-
-/**
- * gsm_milenage - Generate GSM-Milenage (3GPP TS 55.205) authentication triplet
- * @opc: OPc = 128-bit operator variant algorithm configuration field (encr.)
- * @k: K = 128-bit subscriber key
- * @_rand: RAND = 128-bit random challenge
- * @sres: Buffer for SRES = 32-bit SRES
- * @kc: Buffer for Kc = 64-bit Kc
- * Returns: 0 on success, -1 on failure
- */
-int gsm_milenage(const u8 *opc, const u8 *k, const u8 *_rand, u8 *sres, u8 *kc)
-{
- u8 res[8], ck[16], ik[16];
- int i;
-
- if (milenage_f2345(opc, k, _rand, res, ck, ik, NULL, NULL))
- return -1;
-
- for (i = 0; i < 8; i++)
- kc[i] = ck[i] ^ ck[i + 8] ^ ik[i] ^ ik[i + 8];
-
-#ifdef GSM_MILENAGE_ALT_SRES
- os_memcpy(sres, res, 4);
-#else /* GSM_MILENAGE_ALT_SRES */
- for (i = 0; i < 4; i++)
- sres[i] = res[i] ^ res[i + 4];
-#endif /* GSM_MILENAGE_ALT_SRES */
- return 0;
-}
-
-
-/**
- * milenage_generate - Generate AKA AUTN,IK,CK,RES
- * @opc: OPc = 128-bit operator variant algorithm configuration field (encr.)
- * @k: K = 128-bit subscriber key
- * @sqn: SQN = 48-bit sequence number
- * @_rand: RAND = 128-bit random challenge
- * @autn: AUTN = 128-bit authentication token
- * @ik: Buffer for IK = 128-bit integrity key (f4), or %NULL
- * @ck: Buffer for CK = 128-bit confidentiality key (f3), or %NULL
- * @res: Buffer for RES = 64-bit signed response (f2), or %NULL
- * @res_len: Variable that will be set to RES length
- * @auts: 112-bit buffer for AUTS
- * Returns: 0 on success, -1 on failure, or -2 on synchronization failure
- */
-int milenage_check(const u8 *opc, const u8 *k, const u8 *sqn, const u8 *_rand,
- const u8 *autn, u8 *ik, u8 *ck, u8 *res, size_t *res_len,
- u8 *auts)
-{
- int i;
- u8 mac_a[8], ak[6], rx_sqn[6];
- const u8 *amf;
-
- wpa_hexdump(MSG_DEBUG, "Milenage: AUTN", autn, 16);
- wpa_hexdump(MSG_DEBUG, "Milenage: RAND", _rand, 16);
-
- if (milenage_f2345(opc, k, _rand, res, ck, ik, ak, NULL))
- return -1;
-
- *res_len = 8;
- wpa_hexdump_key(MSG_DEBUG, "Milenage: RES", res, *res_len);
- wpa_hexdump_key(MSG_DEBUG, "Milenage: CK", ck, 16);
- wpa_hexdump_key(MSG_DEBUG, "Milenage: IK", ik, 16);
- wpa_hexdump_key(MSG_DEBUG, "Milenage: AK", ak, 6);
-
- /* AUTN = (SQN ^ AK) || AMF || MAC */
- for (i = 0; i < 6; i++)
- rx_sqn[i] = autn[i] ^ ak[i];
- wpa_hexdump(MSG_DEBUG, "Milenage: SQN", rx_sqn, 6);
-
- if (os_memcmp(rx_sqn, sqn, 6) <= 0) {
- u8 auts_amf[2] = { 0x00, 0x00 }; /* TS 33.102 v7.0.0, 6.3.3 */
- if (milenage_f2345(opc, k, _rand, NULL, NULL, NULL, NULL, ak))
- return -1;
- wpa_hexdump_key(MSG_DEBUG, "Milenage: AK*", ak, 6);
- for (i = 0; i < 6; i++)
- auts[i] = sqn[i] ^ ak[i];
- if (milenage_f1(opc, k, _rand, sqn, auts_amf, NULL, auts + 6))
- return -1;
- wpa_hexdump(MSG_DEBUG, "Milenage: AUTS", auts, 14);
- return -2;
- }
-
- amf = autn + 6;
- wpa_hexdump(MSG_DEBUG, "Milenage: AMF", amf, 2);
- if (milenage_f1(opc, k, _rand, rx_sqn, amf, mac_a, NULL))
- return -1;
-
- wpa_hexdump(MSG_DEBUG, "Milenage: MAC_A", mac_a, 8);
-
- if (os_memcmp(mac_a, autn + 8, 8) != 0) {
- wpa_printf(MSG_DEBUG, "Milenage: MAC mismatch");
- wpa_hexdump(MSG_DEBUG, "Milenage: Received MAC_A",
- autn + 8, 8);
- return -1;
- }
-
- return 0;
-}
-
-
-#ifdef TEST_MAIN_MILENAGE
-
-extern int wpa_debug_level;
-
-
-/**
- * milenage_opc - Determine OPc from OP and K
- * @op: OP = 128-bit operator variant algorithm configuration field
- * @k: K = 128-bit subscriber key
- * @opc: Buffer for OPc = 128-bit value derived from OP and K
- */
-static void milenage_opc(const u8 *op, const u8 *k, u8 *opc)
-{
- int i;
- /* OP_C = OP XOR E_K(OP) */
- aes_128_encrypt_block(k, op, opc);
- for (i = 0; i < 16; i++)
- opc[i] ^= op[i];
-}
-
-
-struct gsm_milenage_test_set {
- u8 ki[16];
- u8 rand[16];
- u8 opc[16];
- u8 sres1[4];
- u8 sres2[4];
- u8 kc[8];
-};
-
-static const struct gsm_milenage_test_set gsm_test_sets[] =
-{
- {
- /* 3GPP TS 55.205 v6.0.0 - Test Set 1 */
- { 0x46, 0x5b, 0x5c, 0xe8, 0xb1, 0x99, 0xb4, 0x9f,
- 0xaa, 0x5f, 0x0a, 0x2e, 0xe2, 0x38, 0xa6, 0xbc },
- { 0x23, 0x55, 0x3c, 0xbe, 0x96, 0x37, 0xa8, 0x9d,
- 0x21, 0x8a, 0xe6, 0x4d, 0xae, 0x47, 0xbf, 0x35 },
- { 0xcd, 0x63, 0xcb, 0x71, 0x95, 0x4a, 0x9f, 0x4e,
- 0x48, 0xa5, 0x99, 0x4e, 0x37, 0xa0, 0x2b, 0xaf },
- { 0x46, 0xf8, 0x41, 0x6a },
- { 0xa5, 0x42, 0x11, 0xd5 },
- { 0xea, 0xe4, 0xbe, 0x82, 0x3a, 0xf9, 0xa0, 0x8b }
- }, {
- /* 3GPP TS 55.205 v6.0.0 - Test Set 2 */
- { 0xfe, 0xc8, 0x6b, 0xa6, 0xeb, 0x70, 0x7e, 0xd0,
- 0x89, 0x05, 0x75, 0x7b, 0x1b, 0xb4, 0x4b, 0x8f },
- { 0x9f, 0x7c, 0x8d, 0x02, 0x1a, 0xcc, 0xf4, 0xdb,
- 0x21, 0x3c, 0xcf, 0xf0, 0xc7, 0xf7, 0x1a, 0x6a },
- { 0x10, 0x06, 0x02, 0x0f, 0x0a, 0x47, 0x8b, 0xf6,
- 0xb6, 0x99, 0xf1, 0x5c, 0x06, 0x2e, 0x42, 0xb3 },
- { 0x8c, 0x30, 0x8a, 0x5e },
- { 0x80, 0x11, 0xc4, 0x8c },
- { 0xaa, 0x01, 0x73, 0x9b, 0x8c, 0xaa, 0x97, 0x6d }
- }, {
- /* 3GPP TS 55.205 v6.0.0 - Test Set 3 */
- { 0x9e, 0x59, 0x44, 0xae, 0xa9, 0x4b, 0x81, 0x16,
- 0x5c, 0x82, 0xfb, 0xf9, 0xf3, 0x2d, 0xb7, 0x51 },
- { 0xce, 0x83, 0xdb, 0xc5, 0x4a, 0xc0, 0x27, 0x4a,
- 0x15, 0x7c, 0x17, 0xf8, 0x0d, 0x01, 0x7b, 0xd6 },
- { 0xa6, 0x4a, 0x50, 0x7a, 0xe1, 0xa2, 0xa9, 0x8b,
- 0xb8, 0x8e, 0xb4, 0x21, 0x01, 0x35, 0xdc, 0x87 },
- { 0xcf, 0xbc, 0xe3, 0xfe },
- { 0xf3, 0x65, 0xcd, 0x68 },
- { 0x9a, 0x8e, 0xc9, 0x5f, 0x40, 0x8c, 0xc5, 0x07 }
- }, {
- /* 3GPP TS 55.205 v6.0.0 - Test Set 4 */
- { 0x4a, 0xb1, 0xde, 0xb0, 0x5c, 0xa6, 0xce, 0xb0,
- 0x51, 0xfc, 0x98, 0xe7, 0x7d, 0x02, 0x6a, 0x84 },
- { 0x74, 0xb0, 0xcd, 0x60, 0x31, 0xa1, 0xc8, 0x33,
- 0x9b, 0x2b, 0x6c, 0xe2, 0xb8, 0xc4, 0xa1, 0x86 },
- { 0xdc, 0xf0, 0x7c, 0xbd, 0x51, 0x85, 0x52, 0x90,
- 0xb9, 0x2a, 0x07, 0xa9, 0x89, 0x1e, 0x52, 0x3e },
- { 0x96, 0x55, 0xe2, 0x65 },
- { 0x58, 0x60, 0xfc, 0x1b },
- { 0xcd, 0xc1, 0xdc, 0x08, 0x41, 0xb8, 0x1a, 0x22 }
- }, {
- /* 3GPP TS 55.205 v6.0.0 - Test Set 5 */
- { 0x6c, 0x38, 0xa1, 0x16, 0xac, 0x28, 0x0c, 0x45,
- 0x4f, 0x59, 0x33, 0x2e, 0xe3, 0x5c, 0x8c, 0x4f },
- { 0xee, 0x64, 0x66, 0xbc, 0x96, 0x20, 0x2c, 0x5a,
- 0x55, 0x7a, 0xbb, 0xef, 0xf8, 0xba, 0xbf, 0x63 },
- { 0x38, 0x03, 0xef, 0x53, 0x63, 0xb9, 0x47, 0xc6,
- 0xaa, 0xa2, 0x25, 0xe5, 0x8f, 0xae, 0x39, 0x34 },
- { 0x13, 0x68, 0x8f, 0x17 },
- { 0x16, 0xc8, 0x23, 0x3f },
- { 0xdf, 0x75, 0xbc, 0x5e, 0xa8, 0x99, 0x87, 0x9f }
- }, {
- /* 3GPP TS 55.205 v6.0.0 - Test Set 6 */
- { 0x2d, 0x60, 0x9d, 0x4d, 0xb0, 0xac, 0x5b, 0xf0,
- 0xd2, 0xc0, 0xde, 0x26, 0x70, 0x14, 0xde, 0x0d },
- { 0x19, 0x4a, 0xa7, 0x56, 0x01, 0x38, 0x96, 0xb7,
- 0x4b, 0x4a, 0x2a, 0x3b, 0x0a, 0xf4, 0x53, 0x9e },
- { 0xc3, 0x5a, 0x0a, 0xb0, 0xbc, 0xbf, 0xc9, 0x25,
- 0x2c, 0xaf, 0xf1, 0x5f, 0x24, 0xef, 0xbd, 0xe0 },
- { 0x55, 0x3d, 0x00, 0xb3 },
- { 0x8c, 0x25, 0xa1, 0x6c },
- { 0x84, 0xb4, 0x17, 0xae, 0x3a, 0xea, 0xb4, 0xf3 }
- }, {
- /* 3GPP TS 55.205 v6.0.0 - Test Set 7 */
- { 0xa5, 0x30, 0xa7, 0xfe, 0x42, 0x8f, 0xad, 0x10,
- 0x82, 0xc4, 0x5e, 0xdd, 0xfc, 0xe1, 0x38, 0x84 },
- { 0x3a, 0x4c, 0x2b, 0x32, 0x45, 0xc5, 0x0e, 0xb5,
- 0xc7, 0x1d, 0x08, 0x63, 0x93, 0x95, 0x76, 0x4d },
- { 0x27, 0x95, 0x3e, 0x49, 0xbc, 0x8a, 0xf6, 0xdc,
- 0xc6, 0xe7, 0x30, 0xeb, 0x80, 0x28, 0x6b, 0xe3 },
- { 0x59, 0xf1, 0xa4, 0x4a },
- { 0xa6, 0x32, 0x41, 0xe1 },
- { 0x3b, 0x4e, 0x24, 0x4c, 0xdc, 0x60, 0xce, 0x03 }
- }, {
- /* 3GPP TS 55.205 v6.0.0 - Test Set 8 */
- { 0xd9, 0x15, 0x1c, 0xf0, 0x48, 0x96, 0xe2, 0x58,
- 0x30, 0xbf, 0x2e, 0x08, 0x26, 0x7b, 0x83, 0x60 },
- { 0xf7, 0x61, 0xe5, 0xe9, 0x3d, 0x60, 0x3f, 0xeb,
- 0x73, 0x0e, 0x27, 0x55, 0x6c, 0xb8, 0xa2, 0xca },
- { 0xc4, 0xc9, 0x3e, 0xff, 0xe8, 0xa0, 0x81, 0x38,
- 0xc2, 0x03, 0xd4, 0xc2, 0x7c, 0xe4, 0xe3, 0xd9 },
- { 0x50, 0x58, 0x88, 0x61 },
- { 0x4a, 0x90, 0xb2, 0x17 },
- { 0x8d, 0x4e, 0xc0, 0x1d, 0xe5, 0x97, 0xac, 0xfe }
- }, {
- /* 3GPP TS 55.205 v6.0.0 - Test Set 9 */
- { 0xa0, 0xe2, 0x97, 0x1b, 0x68, 0x22, 0xe8, 0xd3,
- 0x54, 0xa1, 0x8c, 0xc2, 0x35, 0x62, 0x4e, 0xcb },
- { 0x08, 0xef, 0xf8, 0x28, 0xb1, 0x3f, 0xdb, 0x56,
- 0x27, 0x22, 0xc6, 0x5c, 0x7f, 0x30, 0xa9, 0xb2 },
- { 0x82, 0xa2, 0x6f, 0x22, 0xbb, 0xa9, 0xe9, 0x48,
- 0x8f, 0x94, 0x9a, 0x10, 0xd9, 0x8e, 0x9c, 0xc4 },
- { 0xcd, 0xe6, 0xb0, 0x27 },
- { 0x4b, 0xc2, 0x21, 0x2d },
- { 0xd8, 0xde, 0xbc, 0x4f, 0xfb, 0xcd, 0x60, 0xaa }
- }, {
- /* 3GPP TS 55.205 v6.0.0 - Test Set 10 */
- { 0x0d, 0xa6, 0xf7, 0xba, 0x86, 0xd5, 0xea, 0xc8,
- 0xa1, 0x9c, 0xf5, 0x63, 0xac, 0x58, 0x64, 0x2d },
- { 0x67, 0x9a, 0xc4, 0xdb, 0xac, 0xd7, 0xd2, 0x33,
- 0xff, 0x9d, 0x68, 0x06, 0xf4, 0x14, 0x9c, 0xe3 },
- { 0x0d, 0xb1, 0x07, 0x1f, 0x87, 0x67, 0x56, 0x2c,
- 0xa4, 0x3a, 0x0a, 0x64, 0xc4, 0x1e, 0x8d, 0x08 },
- { 0x02, 0xd1, 0x3a, 0xcd },
- { 0x6f, 0xc3, 0x0f, 0xee },
- { 0xf0, 0xea, 0xa5, 0x0a, 0x1e, 0xdc, 0xeb, 0xb7 }
- }, {
- /* 3GPP TS 55.205 v6.0.0 - Test Set 11 */
- { 0x77, 0xb4, 0x58, 0x43, 0xc8, 0x8e, 0x58, 0xc1,
- 0x0d, 0x20, 0x26, 0x84, 0x51, 0x5e, 0xd4, 0x30 },
- { 0x4c, 0x47, 0xeb, 0x30, 0x76, 0xdc, 0x55, 0xfe,
- 0x51, 0x06, 0xcb, 0x20, 0x34, 0xb8, 0xcd, 0x78 },
- { 0xd4, 0x83, 0xaf, 0xae, 0x56, 0x24, 0x09, 0xa3,
- 0x26, 0xb5, 0xbb, 0x0b, 0x20, 0xc4, 0xd7, 0x62 },
- { 0x44, 0x38, 0x9d, 0x01 },
- { 0xae, 0xfa, 0x35, 0x7b },
- { 0x82, 0xdb, 0xab, 0x7f, 0x83, 0xf0, 0x63, 0xda }
- }, {
- /* 3GPP TS 55.205 v6.0.0 - Test Set 12 */
- { 0x72, 0x9b, 0x17, 0x72, 0x92, 0x70, 0xdd, 0x87,
- 0xcc, 0xdf, 0x1b, 0xfe, 0x29, 0xb4, 0xe9, 0xbb },
- { 0x31, 0x1c, 0x4c, 0x92, 0x97, 0x44, 0xd6, 0x75,
- 0xb7, 0x20, 0xf3, 0xb7, 0xe9, 0xb1, 0xcb, 0xd0 },
- { 0x22, 0x8c, 0x2f, 0x2f, 0x06, 0xac, 0x32, 0x68,
- 0xa9, 0xe6, 0x16, 0xee, 0x16, 0xdb, 0x4b, 0xa1 },
- { 0x03, 0xe0, 0xfd, 0x84 },
- { 0x98, 0xdb, 0xbd, 0x09 },
- { 0x3c, 0x66, 0xcb, 0x98, 0xca, 0xb2, 0xd3, 0x3d }
- }, {
- /* 3GPP TS 55.205 v6.0.0 - Test Set 13 */
- { 0xd3, 0x2d, 0xd2, 0x3e, 0x89, 0xdc, 0x66, 0x23,
- 0x54, 0xca, 0x12, 0xeb, 0x79, 0xdd, 0x32, 0xfa },
- { 0xcf, 0x7d, 0x0a, 0xb1, 0xd9, 0x43, 0x06, 0x95,
- 0x0b, 0xf1, 0x20, 0x18, 0xfb, 0xd4, 0x68, 0x87 },
- { 0xd2, 0x2a, 0x4b, 0x41, 0x80, 0xa5, 0x32, 0x57,
- 0x08, 0xa5, 0xff, 0x70, 0xd9, 0xf6, 0x7e, 0xc7 },
- { 0xbe, 0x73, 0xb3, 0xdc },
- { 0xaf, 0x4a, 0x41, 0x1e },
- { 0x96, 0x12, 0xb5, 0xd8, 0x8a, 0x41, 0x30, 0xbb }
- }, {
- /* 3GPP TS 55.205 v6.0.0 - Test Set 14 */
- { 0xaf, 0x7c, 0x65, 0xe1, 0x92, 0x72, 0x21, 0xde,
- 0x59, 0x11, 0x87, 0xa2, 0xc5, 0x98, 0x7a, 0x53 },
- { 0x1f, 0x0f, 0x85, 0x78, 0x46, 0x4f, 0xd5, 0x9b,
- 0x64, 0xbe, 0xd2, 0xd0, 0x94, 0x36, 0xb5, 0x7a },
- { 0xa4, 0xcf, 0x5c, 0x81, 0x55, 0xc0, 0x8a, 0x7e,
- 0xff, 0x41, 0x8e, 0x54, 0x43, 0xb9, 0x8e, 0x55 },
- { 0x8f, 0xe0, 0x19, 0xc7 },
- { 0x7b, 0xff, 0xa5, 0xc2 },
- { 0x75, 0xa1, 0x50, 0xdf, 0x3c, 0x6a, 0xed, 0x08 }
- }, {
- /* 3GPP TS 55.205 v6.0.0 - Test Set 15 */
- { 0x5b, 0xd7, 0xec, 0xd3, 0xd3, 0x12, 0x7a, 0x41,
- 0xd1, 0x25, 0x39, 0xbe, 0xd4, 0xe7, 0xcf, 0x71 },
- { 0x59, 0xb7, 0x5f, 0x14, 0x25, 0x1c, 0x75, 0x03,
- 0x1d, 0x0b, 0xcb, 0xac, 0x1c, 0x2c, 0x04, 0xc7 },
- { 0x76, 0x08, 0x9d, 0x3c, 0x0f, 0xf3, 0xef, 0xdc,
- 0x6e, 0x36, 0x72, 0x1d, 0x4f, 0xce, 0xb7, 0x47 },
- { 0x27, 0x20, 0x2b, 0x82 },
- { 0x7e, 0x3f, 0x44, 0xc7 },
- { 0xb7, 0xf9, 0x2e, 0x42, 0x6a, 0x36, 0xfe, 0xc5 }
- }, {
- /* 3GPP TS 55.205 v6.0.0 - Test Set 16 */
- { 0x6c, 0xd1, 0xc6, 0xce, 0xb1, 0xe0, 0x1e, 0x14,
- 0xf1, 0xb8, 0x23, 0x16, 0xa9, 0x0b, 0x7f, 0x3d },
- { 0xf6, 0x9b, 0x78, 0xf3, 0x00, 0xa0, 0x56, 0x8b,
- 0xce, 0x9f, 0x0c, 0xb9, 0x3c, 0x4b, 0xe4, 0xc9 },
- { 0xa2, 0x19, 0xdc, 0x37, 0xf1, 0xdc, 0x7d, 0x66,
- 0x73, 0x8b, 0x58, 0x43, 0xc7, 0x99, 0xf2, 0x06 },
- { 0xdd, 0xd7, 0xef, 0xe6 },
- { 0x70, 0xf6, 0xbd, 0xb9 },
- { 0x88, 0xd9, 0xde, 0x10, 0xa2, 0x20, 0x04, 0xc5 }
- }, {
- /* 3GPP TS 55.205 v6.0.0 - Test Set 17 */
- { 0xb7, 0x3a, 0x90, 0xcb, 0xcf, 0x3a, 0xfb, 0x62,
- 0x2d, 0xba, 0x83, 0xc5, 0x8a, 0x84, 0x15, 0xdf },
- { 0xb1, 0x20, 0xf1, 0xc1, 0xa0, 0x10, 0x2a, 0x2f,
- 0x50, 0x7d, 0xd5, 0x43, 0xde, 0x68, 0x28, 0x1f },
- { 0xdf, 0x0c, 0x67, 0x86, 0x8f, 0xa2, 0x5f, 0x74,
- 0x8b, 0x70, 0x44, 0xc6, 0xe7, 0xc2, 0x45, 0xb8 },
- { 0x67, 0xe4, 0xff, 0x3f },
- { 0x47, 0x9d, 0xd2, 0x5c },
- { 0xa8, 0x19, 0xe5, 0x77, 0xa8, 0xd6, 0x17, 0x5b }
- }, {
- /* 3GPP TS 55.205 v6.0.0 - Test Set 18 */
- { 0x51, 0x22, 0x25, 0x02, 0x14, 0xc3, 0x3e, 0x72,
- 0x3a, 0x5d, 0xd5, 0x23, 0xfc, 0x14, 0x5f, 0xc0 },
- { 0x81, 0xe9, 0x2b, 0x6c, 0x0e, 0xe0, 0xe1, 0x2e,
- 0xbc, 0xeb, 0xa8, 0xd9, 0x2a, 0x99, 0xdf, 0xa5 },
- { 0x98, 0x1d, 0x46, 0x4c, 0x7c, 0x52, 0xeb, 0x6e,
- 0x50, 0x36, 0x23, 0x49, 0x84, 0xad, 0x0b, 0xcf },
- { 0x8a, 0x3b, 0x8d, 0x17 },
- { 0x28, 0xd7, 0xb0, 0xf2 },
- { 0x9a, 0x8d, 0x0e, 0x88, 0x3f, 0xf0, 0x88, 0x7a }
- }, {
- /* 3GPP TS 55.205 v6.0.0 - Test Set 19 */
- { 0x90, 0xdc, 0xa4, 0xed, 0xa4, 0x5b, 0x53, 0xcf,
- 0x0f, 0x12, 0xd7, 0xc9, 0xc3, 0xbc, 0x6a, 0x89 },
- { 0x9f, 0xdd, 0xc7, 0x20, 0x92, 0xc6, 0xad, 0x03,
- 0x6b, 0x6e, 0x46, 0x47, 0x89, 0x31, 0x5b, 0x78 },
- { 0xcb, 0x9c, 0xcc, 0xc4, 0xb9, 0x25, 0x8e, 0x6d,
- 0xca, 0x47, 0x60, 0x37, 0x9f, 0xb8, 0x25, 0x81 },
- { 0xdf, 0x58, 0x52, 0x2f },
- { 0xa9, 0x51, 0x00, 0xe2 },
- { 0xed, 0x29, 0xb2, 0xf1, 0xc2, 0x7f, 0x9f, 0x34 }
- }
-};
-
-#define NUM_GSM_TESTS (sizeof(gsm_test_sets) / sizeof(gsm_test_sets[0]))
-
-
-struct milenage_test_set {
- u8 k[16];
- u8 rand[16];
- u8 sqn[6];
- u8 amf[2];
- u8 op[16];
- u8 opc[16];
- u8 f1[8];
- u8 f1star[8];
- u8 f2[8];
- u8 f3[16];
- u8 f4[16];
- u8 f5[6];
- u8 f5star[6];
-};
-
-static const struct milenage_test_set test_sets[] =
-{
- {
- /* 3GPP TS 35.208 v6.0.0 - 4.3.1 Test Set 1 */
- { 0x46, 0x5b, 0x5c, 0xe8, 0xb1, 0x99, 0xb4, 0x9f,
- 0xaa, 0x5f, 0x0a, 0x2e, 0xe2, 0x38, 0xa6, 0xbc },
- { 0x23, 0x55, 0x3c, 0xbe, 0x96, 0x37, 0xa8, 0x9d,
- 0x21, 0x8a, 0xe6, 0x4d, 0xae, 0x47, 0xbf, 0x35 },
- { 0xff, 0x9b, 0xb4, 0xd0, 0xb6, 0x07 },
- { 0xb9, 0xb9 },
- { 0xcd, 0xc2, 0x02, 0xd5, 0x12, 0x3e, 0x20, 0xf6,
- 0x2b, 0x6d, 0x67, 0x6a, 0xc7, 0x2c, 0xb3, 0x18 },
- { 0xcd, 0x63, 0xcb, 0x71, 0x95, 0x4a, 0x9f, 0x4e,
- 0x48, 0xa5, 0x99, 0x4e, 0x37, 0xa0, 0x2b, 0xaf },
- { 0x4a, 0x9f, 0xfa, 0xc3, 0x54, 0xdf, 0xaf, 0xb3 },
- { 0x01, 0xcf, 0xaf, 0x9e, 0xc4, 0xe8, 0x71, 0xe9 },
- { 0xa5, 0x42, 0x11, 0xd5, 0xe3, 0xba, 0x50, 0xbf },
- { 0xb4, 0x0b, 0xa9, 0xa3, 0xc5, 0x8b, 0x2a, 0x05,
- 0xbb, 0xf0, 0xd9, 0x87, 0xb2, 0x1b, 0xf8, 0xcb },
- { 0xf7, 0x69, 0xbc, 0xd7, 0x51, 0x04, 0x46, 0x04,
- 0x12, 0x76, 0x72, 0x71, 0x1c, 0x6d, 0x34, 0x41 },
- { 0xaa, 0x68, 0x9c, 0x64, 0x83, 0x70 },
- { 0x45, 0x1e, 0x8b, 0xec, 0xa4, 0x3b }
- }, {
- /* 3GPP TS 35.208 v6.0.0 - 4.3.2 Test Set 2 */
- { 0x46, 0x5b, 0x5c, 0xe8, 0xb1, 0x99, 0xb4, 0x9f,
- 0xaa, 0x5f, 0x0a, 0x2e, 0xe2, 0x38, 0xa6, 0xbc },
- { 0x23, 0x55, 0x3c, 0xbe, 0x96, 0x37, 0xa8, 0x9d,
- 0x21, 0x8a, 0xe6, 0x4d, 0xae, 0x47, 0xbf, 0x35 },
- { 0xff, 0x9b, 0xb4, 0xd0, 0xb6, 0x07 },
- { 0xb9, 0xb9 },
- { 0xcd, 0xc2, 0x02, 0xd5, 0x12, 0x3e, 0x20, 0xf6,
- 0x2b, 0x6d, 0x67, 0x6a, 0xc7, 0x2c, 0xb3, 0x18 },
- { 0xcd, 0x63, 0xcb, 0x71, 0x95, 0x4a, 0x9f, 0x4e,
- 0x48, 0xa5, 0x99, 0x4e, 0x37, 0xa0, 0x2b, 0xaf },
- { 0x4a, 0x9f, 0xfa, 0xc3, 0x54, 0xdf, 0xaf, 0xb3 },
- { 0x01, 0xcf, 0xaf, 0x9e, 0xc4, 0xe8, 0x71, 0xe9 },
- { 0xa5, 0x42, 0x11, 0xd5, 0xe3, 0xba, 0x50, 0xbf },
- { 0xb4, 0x0b, 0xa9, 0xa3, 0xc5, 0x8b, 0x2a, 0x05,
- 0xbb, 0xf0, 0xd9, 0x87, 0xb2, 0x1b, 0xf8, 0xcb },
- { 0xf7, 0x69, 0xbc, 0xd7, 0x51, 0x04, 0x46, 0x04,
- 0x12, 0x76, 0x72, 0x71, 0x1c, 0x6d, 0x34, 0x41 },
- { 0xaa, 0x68, 0x9c, 0x64, 0x83, 0x70 },
- { 0x45, 0x1e, 0x8b, 0xec, 0xa4, 0x3b }
- }, {
- /* 3GPP TS 35.208 v6.0.0 - 4.3.3 Test Set 3 */
- { 0xfe, 0xc8, 0x6b, 0xa6, 0xeb, 0x70, 0x7e, 0xd0,
- 0x89, 0x05, 0x75, 0x7b, 0x1b, 0xb4, 0x4b, 0x8f },
- { 0x9f, 0x7c, 0x8d, 0x02, 0x1a, 0xcc, 0xf4, 0xdb,
- 0x21, 0x3c, 0xcf, 0xf0, 0xc7, 0xf7, 0x1a, 0x6a },
- { 0x9d, 0x02, 0x77, 0x59, 0x5f, 0xfc },
- { 0x72, 0x5c },
- { 0xdb, 0xc5, 0x9a, 0xdc, 0xb6, 0xf9, 0xa0, 0xef,
- 0x73, 0x54, 0x77, 0xb7, 0xfa, 0xdf, 0x83, 0x74 },
- { 0x10, 0x06, 0x02, 0x0f, 0x0a, 0x47, 0x8b, 0xf6,
- 0xb6, 0x99, 0xf1, 0x5c, 0x06, 0x2e, 0x42, 0xb3 },
- { 0x9c, 0xab, 0xc3, 0xe9, 0x9b, 0xaf, 0x72, 0x81 },
- { 0x95, 0x81, 0x4b, 0xa2, 0xb3, 0x04, 0x43, 0x24 },
- { 0x80, 0x11, 0xc4, 0x8c, 0x0c, 0x21, 0x4e, 0xd2 },
- { 0x5d, 0xbd, 0xbb, 0x29, 0x54, 0xe8, 0xf3, 0xcd,
- 0xe6, 0x65, 0xb0, 0x46, 0x17, 0x9a, 0x50, 0x98 },
- { 0x59, 0xa9, 0x2d, 0x3b, 0x47, 0x6a, 0x04, 0x43,
- 0x48, 0x70, 0x55, 0xcf, 0x88, 0xb2, 0x30, 0x7b },
- { 0x33, 0x48, 0x4d, 0xc2, 0x13, 0x6b },
- { 0xde, 0xac, 0xdd, 0x84, 0x8c, 0xc6 }
- }, {
- /* 3GPP TS 35.208 v6.0.0 - 4.3.4 Test Set 4 */
- { 0x9e, 0x59, 0x44, 0xae, 0xa9, 0x4b, 0x81, 0x16,
- 0x5c, 0x82, 0xfb, 0xf9, 0xf3, 0x2d, 0xb7, 0x51 },
- { 0xce, 0x83, 0xdb, 0xc5, 0x4a, 0xc0, 0x27, 0x4a,
- 0x15, 0x7c, 0x17, 0xf8, 0x0d, 0x01, 0x7b, 0xd6 },
- { 0x0b, 0x60, 0x4a, 0x81, 0xec, 0xa8 },
- { 0x9e, 0x09 },
- { 0x22, 0x30, 0x14, 0xc5, 0x80, 0x66, 0x94, 0xc0,
- 0x07, 0xca, 0x1e, 0xee, 0xf5, 0x7f, 0x00, 0x4f },
- { 0xa6, 0x4a, 0x50, 0x7a, 0xe1, 0xa2, 0xa9, 0x8b,
- 0xb8, 0x8e, 0xb4, 0x21, 0x01, 0x35, 0xdc, 0x87 },
- { 0x74, 0xa5, 0x82, 0x20, 0xcb, 0xa8, 0x4c, 0x49 },
- { 0xac, 0x2c, 0xc7, 0x4a, 0x96, 0x87, 0x18, 0x37 },
- { 0xf3, 0x65, 0xcd, 0x68, 0x3c, 0xd9, 0x2e, 0x96 },
- { 0xe2, 0x03, 0xed, 0xb3, 0x97, 0x15, 0x74, 0xf5,
- 0xa9, 0x4b, 0x0d, 0x61, 0xb8, 0x16, 0x34, 0x5d },
- { 0x0c, 0x45, 0x24, 0xad, 0xea, 0xc0, 0x41, 0xc4,
- 0xdd, 0x83, 0x0d, 0x20, 0x85, 0x4f, 0xc4, 0x6b },
- { 0xf0, 0xb9, 0xc0, 0x8a, 0xd0, 0x2e },
- { 0x60, 0x85, 0xa8, 0x6c, 0x6f, 0x63 }
- }, {
- /* 3GPP TS 35.208 v6.0.0 - 4.3.5 Test Set 5 */
- { 0x4a, 0xb1, 0xde, 0xb0, 0x5c, 0xa6, 0xce, 0xb0,
- 0x51, 0xfc, 0x98, 0xe7, 0x7d, 0x02, 0x6a, 0x84 },
- { 0x74, 0xb0, 0xcd, 0x60, 0x31, 0xa1, 0xc8, 0x33,
- 0x9b, 0x2b, 0x6c, 0xe2, 0xb8, 0xc4, 0xa1, 0x86 },
- { 0xe8, 0x80, 0xa1, 0xb5, 0x80, 0xb6 },
- { 0x9f, 0x07 },
- { 0x2d, 0x16, 0xc5, 0xcd, 0x1f, 0xdf, 0x6b, 0x22,
- 0x38, 0x35, 0x84, 0xe3, 0xbe, 0xf2, 0xa8, 0xd8 },
- { 0xdc, 0xf0, 0x7c, 0xbd, 0x51, 0x85, 0x52, 0x90,
- 0xb9, 0x2a, 0x07, 0xa9, 0x89, 0x1e, 0x52, 0x3e },
- { 0x49, 0xe7, 0x85, 0xdd, 0x12, 0x62, 0x6e, 0xf2 },
- { 0x9e, 0x85, 0x79, 0x03, 0x36, 0xbb, 0x3f, 0xa2 },
- { 0x58, 0x60, 0xfc, 0x1b, 0xce, 0x35, 0x1e, 0x7e },
- { 0x76, 0x57, 0x76, 0x6b, 0x37, 0x3d, 0x1c, 0x21,
- 0x38, 0xf3, 0x07, 0xe3, 0xde, 0x92, 0x42, 0xf9 },
- { 0x1c, 0x42, 0xe9, 0x60, 0xd8, 0x9b, 0x8f, 0xa9,
- 0x9f, 0x27, 0x44, 0xe0, 0x70, 0x8c, 0xcb, 0x53 },
- { 0x31, 0xe1, 0x1a, 0x60, 0x91, 0x18 },
- { 0xfe, 0x25, 0x55, 0xe5, 0x4a, 0xa9 }
- }, {
- /* 3GPP TS 35.208 v6.0.0 - 4.3.6 Test Set 6 */
- { 0x6c, 0x38, 0xa1, 0x16, 0xac, 0x28, 0x0c, 0x45,
- 0x4f, 0x59, 0x33, 0x2e, 0xe3, 0x5c, 0x8c, 0x4f },
- { 0xee, 0x64, 0x66, 0xbc, 0x96, 0x20, 0x2c, 0x5a,
- 0x55, 0x7a, 0xbb, 0xef, 0xf8, 0xba, 0xbf, 0x63 },
- { 0x41, 0x4b, 0x98, 0x22, 0x21, 0x81 },
- { 0x44, 0x64 },
- { 0x1b, 0xa0, 0x0a, 0x1a, 0x7c, 0x67, 0x00, 0xac,
- 0x8c, 0x3f, 0xf3, 0xe9, 0x6a, 0xd0, 0x87, 0x25 },
- { 0x38, 0x03, 0xef, 0x53, 0x63, 0xb9, 0x47, 0xc6,
- 0xaa, 0xa2, 0x25, 0xe5, 0x8f, 0xae, 0x39, 0x34 },
- { 0x07, 0x8a, 0xdf, 0xb4, 0x88, 0x24, 0x1a, 0x57 },
- { 0x80, 0x24, 0x6b, 0x8d, 0x01, 0x86, 0xbc, 0xf1 },
- { 0x16, 0xc8, 0x23, 0x3f, 0x05, 0xa0, 0xac, 0x28 },
- { 0x3f, 0x8c, 0x75, 0x87, 0xfe, 0x8e, 0x4b, 0x23,
- 0x3a, 0xf6, 0x76, 0xae, 0xde, 0x30, 0xba, 0x3b },
- { 0xa7, 0x46, 0x6c, 0xc1, 0xe6, 0xb2, 0xa1, 0x33,
- 0x7d, 0x49, 0xd3, 0xb6, 0x6e, 0x95, 0xd7, 0xb4 },
- { 0x45, 0xb0, 0xf6, 0x9a, 0xb0, 0x6c },
- { 0x1f, 0x53, 0xcd, 0x2b, 0x11, 0x13 }
- }, {
- /* 3GPP TS 35.208 v6.0.0 - 4.3.7 Test Set 7 */
- { 0x2d, 0x60, 0x9d, 0x4d, 0xb0, 0xac, 0x5b, 0xf0,
- 0xd2, 0xc0, 0xde, 0x26, 0x70, 0x14, 0xde, 0x0d },
- { 0x19, 0x4a, 0xa7, 0x56, 0x01, 0x38, 0x96, 0xb7,
- 0x4b, 0x4a, 0x2a, 0x3b, 0x0a, 0xf4, 0x53, 0x9e },
- { 0x6b, 0xf6, 0x94, 0x38, 0xc2, 0xe4 },
- { 0x5f, 0x67 },
- { 0x46, 0x0a, 0x48, 0x38, 0x54, 0x27, 0xaa, 0x39,
- 0x26, 0x4a, 0xac, 0x8e, 0xfc, 0x9e, 0x73, 0xe8 },
- { 0xc3, 0x5a, 0x0a, 0xb0, 0xbc, 0xbf, 0xc9, 0x25,
- 0x2c, 0xaf, 0xf1, 0x5f, 0x24, 0xef, 0xbd, 0xe0 },
- { 0xbd, 0x07, 0xd3, 0x00, 0x3b, 0x9e, 0x5c, 0xc3 },
- { 0xbc, 0xb6, 0xc2, 0xfc, 0xad, 0x15, 0x22, 0x50 },
- { 0x8c, 0x25, 0xa1, 0x6c, 0xd9, 0x18, 0xa1, 0xdf },
- { 0x4c, 0xd0, 0x84, 0x60, 0x20, 0xf8, 0xfa, 0x07,
- 0x31, 0xdd, 0x47, 0xcb, 0xdc, 0x6b, 0xe4, 0x11 },
- { 0x88, 0xab, 0x80, 0xa4, 0x15, 0xf1, 0x5c, 0x73,
- 0x71, 0x12, 0x54, 0xa1, 0xd3, 0x88, 0xf6, 0x96 },
- { 0x7e, 0x64, 0x55, 0xf3, 0x4c, 0xf3 },
- { 0xdc, 0x6d, 0xd0, 0x1e, 0x8f, 0x15 }
- }, {
- /* 3GPP TS 35.208 v6.0.0 - 4.3.8 Test Set 8 */
- { 0xa5, 0x30, 0xa7, 0xfe, 0x42, 0x8f, 0xad, 0x10,
- 0x82, 0xc4, 0x5e, 0xdd, 0xfc, 0xe1, 0x38, 0x84 },
- { 0x3a, 0x4c, 0x2b, 0x32, 0x45, 0xc5, 0x0e, 0xb5,
- 0xc7, 0x1d, 0x08, 0x63, 0x93, 0x95, 0x76, 0x4d },
- { 0xf6, 0x3f, 0x5d, 0x76, 0x87, 0x84 },
- { 0xb9, 0x0e },
- { 0x51, 0x1c, 0x6c, 0x4e, 0x83, 0xe3, 0x8c, 0x89,
- 0xb1, 0xc5, 0xd8, 0xdd, 0xe6, 0x24, 0x26, 0xfa },
- { 0x27, 0x95, 0x3e, 0x49, 0xbc, 0x8a, 0xf6, 0xdc,
- 0xc6, 0xe7, 0x30, 0xeb, 0x80, 0x28, 0x6b, 0xe3 },
- { 0x53, 0x76, 0x1f, 0xbd, 0x67, 0x9b, 0x0b, 0xad },
- { 0x21, 0xad, 0xfd, 0x33, 0x4a, 0x10, 0xe7, 0xce },
- { 0xa6, 0x32, 0x41, 0xe1, 0xff, 0xc3, 0xe5, 0xab },
- { 0x10, 0xf0, 0x5b, 0xab, 0x75, 0xa9, 0x9a, 0x5f,
- 0xbb, 0x98, 0xa9, 0xc2, 0x87, 0x67, 0x9c, 0x3b },
- { 0xf9, 0xec, 0x08, 0x65, 0xeb, 0x32, 0xf2, 0x23,
- 0x69, 0xca, 0xde, 0x40, 0xc5, 0x9c, 0x3a, 0x44 },
- { 0x88, 0x19, 0x6c, 0x47, 0x98, 0x6f },
- { 0xc9, 0x87, 0xa3, 0xd2, 0x31, 0x15 }
- }, {
- /* 3GPP TS 35.208 v6.0.0 - 4.3.9 Test Set 9 */
- { 0xd9, 0x15, 0x1c, 0xf0, 0x48, 0x96, 0xe2, 0x58,
- 0x30, 0xbf, 0x2e, 0x08, 0x26, 0x7b, 0x83, 0x60 },
- { 0xf7, 0x61, 0xe5, 0xe9, 0x3d, 0x60, 0x3f, 0xeb,
- 0x73, 0x0e, 0x27, 0x55, 0x6c, 0xb8, 0xa2, 0xca },
- { 0x47, 0xee, 0x01, 0x99, 0x82, 0x0a },
- { 0x91, 0x13 },
- { 0x75, 0xfc, 0x22, 0x33, 0xa4, 0x42, 0x94, 0xee,
- 0x8e, 0x6d, 0xe2, 0x5c, 0x43, 0x53, 0xd2, 0x6b },
- { 0xc4, 0xc9, 0x3e, 0xff, 0xe8, 0xa0, 0x81, 0x38,
- 0xc2, 0x03, 0xd4, 0xc2, 0x7c, 0xe4, 0xe3, 0xd9 },
- { 0x66, 0xcc, 0x4b, 0xe4, 0x48, 0x62, 0xaf, 0x1f },
- { 0x7a, 0x4b, 0x8d, 0x7a, 0x87, 0x53, 0xf2, 0x46 },
- { 0x4a, 0x90, 0xb2, 0x17, 0x1a, 0xc8, 0x3a, 0x76 },
- { 0x71, 0x23, 0x6b, 0x71, 0x29, 0xf9, 0xb2, 0x2a,
- 0xb7, 0x7e, 0xa7, 0xa5, 0x4c, 0x96, 0xda, 0x22 },
- { 0x90, 0x52, 0x7e, 0xba, 0xa5, 0x58, 0x89, 0x68,
- 0xdb, 0x41, 0x72, 0x73, 0x25, 0xa0, 0x4d, 0x9e },
- { 0x82, 0xa0, 0xf5, 0x28, 0x7a, 0x71 },
- { 0x52, 0x7d, 0xbf, 0x41, 0xf3, 0x5f }
- }, {
- /* 3GPP TS 35.208 v6.0.0 - 4.3.10 Test Set 10 */
- { 0xa0, 0xe2, 0x97, 0x1b, 0x68, 0x22, 0xe8, 0xd3,
- 0x54, 0xa1, 0x8c, 0xc2, 0x35, 0x62, 0x4e, 0xcb },
- { 0x08, 0xef, 0xf8, 0x28, 0xb1, 0x3f, 0xdb, 0x56,
- 0x27, 0x22, 0xc6, 0x5c, 0x7f, 0x30, 0xa9, 0xb2 },
- { 0xdb, 0x5c, 0x06, 0x64, 0x81, 0xe0 },
- { 0x71, 0x6b },
- { 0x32, 0x37, 0x92, 0xfa, 0xca, 0x21, 0xfb, 0x4d,
- 0x5d, 0x6f, 0x13, 0xc1, 0x45, 0xa9, 0xd2, 0xc1 },
- { 0x82, 0xa2, 0x6f, 0x22, 0xbb, 0xa9, 0xe9, 0x48,
- 0x8f, 0x94, 0x9a, 0x10, 0xd9, 0x8e, 0x9c, 0xc4 },
- { 0x94, 0x85, 0xfe, 0x24, 0x62, 0x1c, 0xb9, 0xf6 },
- { 0xbc, 0xe3, 0x25, 0xce, 0x03, 0xe2, 0xe9, 0xb9 },
- { 0x4b, 0xc2, 0x21, 0x2d, 0x86, 0x24, 0x91, 0x0a },
- { 0x08, 0xce, 0xf6, 0xd0, 0x04, 0xec, 0x61, 0x47,
- 0x1a, 0x3c, 0x3c, 0xda, 0x04, 0x81, 0x37, 0xfa },
- { 0xed, 0x03, 0x18, 0xca, 0x5d, 0xeb, 0x92, 0x06,
- 0x27, 0x2f, 0x6e, 0x8f, 0xa6, 0x4b, 0xa4, 0x11 },
- { 0xa2, 0xf8, 0x58, 0xaa, 0x9e, 0x5d },
- { 0x74, 0xe7, 0x6f, 0xbb, 0xec, 0x38 }
- }, {
- /* 3GPP TS 35.208 v6.0.0 - 4.3.11 Test Set 11 */
- { 0x0d, 0xa6, 0xf7, 0xba, 0x86, 0xd5, 0xea, 0xc8,
- 0xa1, 0x9c, 0xf5, 0x63, 0xac, 0x58, 0x64, 0x2d },
- { 0x67, 0x9a, 0xc4, 0xdb, 0xac, 0xd7, 0xd2, 0x33,
- 0xff, 0x9d, 0x68, 0x06, 0xf4, 0x14, 0x9c, 0xe3 },
- { 0x6e, 0x23, 0x31, 0xd6, 0x92, 0xad },
- { 0x22, 0x4a },
- { 0x4b, 0x9a, 0x26, 0xfa, 0x45, 0x9e, 0x3a, 0xcb,
- 0xff, 0x36, 0xf4, 0x01, 0x5d, 0xe3, 0xbd, 0xc1 },
- { 0x0d, 0xb1, 0x07, 0x1f, 0x87, 0x67, 0x56, 0x2c,
- 0xa4, 0x3a, 0x0a, 0x64, 0xc4, 0x1e, 0x8d, 0x08 },
- { 0x28, 0x31, 0xd7, 0xae, 0x90, 0x88, 0xe4, 0x92 },
- { 0x9b, 0x2e, 0x16, 0x95, 0x11, 0x35, 0xd5, 0x23 },
- { 0x6f, 0xc3, 0x0f, 0xee, 0x6d, 0x12, 0x35, 0x23 },
- { 0x69, 0xb1, 0xca, 0xe7, 0xc7, 0x42, 0x9d, 0x97,
- 0x5e, 0x24, 0x5c, 0xac, 0xb0, 0x5a, 0x51, 0x7c },
- { 0x74, 0xf2, 0x4e, 0x8c, 0x26, 0xdf, 0x58, 0xe1,
- 0xb3, 0x8d, 0x7d, 0xcd, 0x4f, 0x1b, 0x7f, 0xbd },
- { 0x4c, 0x53, 0x9a, 0x26, 0xe1, 0xfa },
- { 0x07, 0x86, 0x1e, 0x12, 0x69, 0x28 }
- }, {
- /* 3GPP TS 35.208 v6.0.0 - 4.3.12 Test Set 12 */
- { 0x77, 0xb4, 0x58, 0x43, 0xc8, 0x8e, 0x58, 0xc1,
- 0x0d, 0x20, 0x26, 0x84, 0x51, 0x5e, 0xd4, 0x30 },
- { 0x4c, 0x47, 0xeb, 0x30, 0x76, 0xdc, 0x55, 0xfe,
- 0x51, 0x06, 0xcb, 0x20, 0x34, 0xb8, 0xcd, 0x78 },
- { 0xfe, 0x1a, 0x87, 0x31, 0x00, 0x5d },
- { 0xad, 0x25 },
- { 0xbf, 0x32, 0x86, 0xc7, 0xa5, 0x14, 0x09, 0xce,
- 0x95, 0x72, 0x4d, 0x50, 0x3b, 0xfe, 0x6e, 0x70 },
- { 0xd4, 0x83, 0xaf, 0xae, 0x56, 0x24, 0x09, 0xa3,
- 0x26, 0xb5, 0xbb, 0x0b, 0x20, 0xc4, 0xd7, 0x62 },
- { 0x08, 0x33, 0x2d, 0x7e, 0x9f, 0x48, 0x45, 0x70 },
- { 0xed, 0x41, 0xb7, 0x34, 0x48, 0x9d, 0x52, 0x07 },
- { 0xae, 0xfa, 0x35, 0x7b, 0xea, 0xc2, 0xa8, 0x7a },
- { 0x90, 0x8c, 0x43, 0xf0, 0x56, 0x9c, 0xb8, 0xf7,
- 0x4b, 0xc9, 0x71, 0xe7, 0x06, 0xc3, 0x6c, 0x5f },
- { 0xc2, 0x51, 0xdf, 0x0d, 0x88, 0x8d, 0xd9, 0x32,
- 0x9b, 0xcf, 0x46, 0x65, 0x5b, 0x22, 0x6e, 0x40 },
- { 0x30, 0xff, 0x25, 0xcd, 0xad, 0xf6 },
- { 0xe8, 0x4e, 0xd0, 0xd4, 0x67, 0x7e }
- }, {
- /* 3GPP TS 35.208 v6.0.0 - 4.3.13 Test Set 13 */
- { 0x72, 0x9b, 0x17, 0x72, 0x92, 0x70, 0xdd, 0x87,
- 0xcc, 0xdf, 0x1b, 0xfe, 0x29, 0xb4, 0xe9, 0xbb },
- { 0x31, 0x1c, 0x4c, 0x92, 0x97, 0x44, 0xd6, 0x75,
- 0xb7, 0x20, 0xf3, 0xb7, 0xe9, 0xb1, 0xcb, 0xd0 },
- { 0xc8, 0x5c, 0x4c, 0xf6, 0x59, 0x16 },
- { 0x5b, 0xb2 },
- { 0xd0, 0x4c, 0x9c, 0x35, 0xbd, 0x22, 0x62, 0xfa,
- 0x81, 0x0d, 0x29, 0x24, 0xd0, 0x36, 0xfd, 0x13 },
- { 0x22, 0x8c, 0x2f, 0x2f, 0x06, 0xac, 0x32, 0x68,
- 0xa9, 0xe6, 0x16, 0xee, 0x16, 0xdb, 0x4b, 0xa1 },
- { 0xff, 0x79, 0x4f, 0xe2, 0xf8, 0x27, 0xeb, 0xf8 },
- { 0x24, 0xfe, 0x4d, 0xc6, 0x1e, 0x87, 0x4b, 0x52 },
- { 0x98, 0xdb, 0xbd, 0x09, 0x9b, 0x3b, 0x40, 0x8d },
- { 0x44, 0xc0, 0xf2, 0x3c, 0x54, 0x93, 0xcf, 0xd2,
- 0x41, 0xe4, 0x8f, 0x19, 0x7e, 0x1d, 0x10, 0x12 },
- { 0x0c, 0x9f, 0xb8, 0x16, 0x13, 0x88, 0x4c, 0x25,
- 0x35, 0xdd, 0x0e, 0xab, 0xf3, 0xb4, 0x40, 0xd8 },
- { 0x53, 0x80, 0xd1, 0x58, 0xcf, 0xe3 },
- { 0x87, 0xac, 0x3b, 0x55, 0x9f, 0xb6 }
- }, {
- /* 3GPP TS 35.208 v6.0.0 - 4.3.14 Test Set 14 */
- { 0xd3, 0x2d, 0xd2, 0x3e, 0x89, 0xdc, 0x66, 0x23,
- 0x54, 0xca, 0x12, 0xeb, 0x79, 0xdd, 0x32, 0xfa },
- { 0xcf, 0x7d, 0x0a, 0xb1, 0xd9, 0x43, 0x06, 0x95,
- 0x0b, 0xf1, 0x20, 0x18, 0xfb, 0xd4, 0x68, 0x87 },
- { 0x48, 0x41, 0x07, 0xe5, 0x6a, 0x43 },
- { 0xb5, 0xe6 },
- { 0xfe, 0x75, 0x90, 0x5b, 0x9d, 0xa4, 0x7d, 0x35,
- 0x62, 0x36, 0xd0, 0x31, 0x4e, 0x09, 0xc3, 0x2e },
- { 0xd2, 0x2a, 0x4b, 0x41, 0x80, 0xa5, 0x32, 0x57,
- 0x08, 0xa5, 0xff, 0x70, 0xd9, 0xf6, 0x7e, 0xc7 },
- { 0xcf, 0x19, 0xd6, 0x2b, 0x6a, 0x80, 0x98, 0x66 },
- { 0x5d, 0x26, 0x95, 0x37, 0xe4, 0x5e, 0x2c, 0xe6 },
- { 0xaf, 0x4a, 0x41, 0x1e, 0x11, 0x39, 0xf2, 0xc2 },
- { 0x5a, 0xf8, 0x6b, 0x80, 0xed, 0xb7, 0x0d, 0xf5,
- 0x29, 0x2c, 0xc1, 0x12, 0x1c, 0xba, 0xd5, 0x0c },
- { 0x7f, 0x4d, 0x6a, 0xe7, 0x44, 0x0e, 0x18, 0x78,
- 0x9a, 0x8b, 0x75, 0xad, 0x3f, 0x42, 0xf0, 0x3a },
- { 0x21, 0x7a, 0xf4, 0x92, 0x72, 0xad },
- { 0x90, 0x0e, 0x10, 0x1c, 0x67, 0x7e }
- }, {
- /* 3GPP TS 35.208 v6.0.0 - 4.3.15 Test Set 15 */
- { 0xaf, 0x7c, 0x65, 0xe1, 0x92, 0x72, 0x21, 0xde,
- 0x59, 0x11, 0x87, 0xa2, 0xc5, 0x98, 0x7a, 0x53 },
- { 0x1f, 0x0f, 0x85, 0x78, 0x46, 0x4f, 0xd5, 0x9b,
- 0x64, 0xbe, 0xd2, 0xd0, 0x94, 0x36, 0xb5, 0x7a },
- { 0x3d, 0x62, 0x7b, 0x01, 0x41, 0x8d },
- { 0x84, 0xf6 },
- { 0x0c, 0x7a, 0xcb, 0x8d, 0x95, 0xb7, 0xd4, 0xa3,
- 0x1c, 0x5a, 0xca, 0x6d, 0x26, 0x34, 0x5a, 0x88 },
- { 0xa4, 0xcf, 0x5c, 0x81, 0x55, 0xc0, 0x8a, 0x7e,
- 0xff, 0x41, 0x8e, 0x54, 0x43, 0xb9, 0x8e, 0x55 },
- { 0xc3, 0x7c, 0xae, 0x78, 0x05, 0x64, 0x20, 0x32 },
- { 0x68, 0xcd, 0x09, 0xa4, 0x52, 0xd8, 0xdb, 0x7c },
- { 0x7b, 0xff, 0xa5, 0xc2, 0xf4, 0x1f, 0xbc, 0x05 },
- { 0x3f, 0x8c, 0x3f, 0x3c, 0xcf, 0x76, 0x25, 0xbf,
- 0x77, 0xfc, 0x94, 0xbc, 0xfd, 0x22, 0xfd, 0x26 },
- { 0xab, 0xcb, 0xae, 0x8f, 0xd4, 0x61, 0x15, 0xe9,
- 0x96, 0x1a, 0x55, 0xd0, 0xda, 0x5f, 0x20, 0x78 },
- { 0x83, 0x7f, 0xd7, 0xb7, 0x44, 0x19 },
- { 0x56, 0xe9, 0x7a, 0x60, 0x90, 0xb1 }
- }, {
- /* 3GPP TS 35.208 v6.0.0 - 4.3.16 Test Set 16 */
- { 0x5b, 0xd7, 0xec, 0xd3, 0xd3, 0x12, 0x7a, 0x41,
- 0xd1, 0x25, 0x39, 0xbe, 0xd4, 0xe7, 0xcf, 0x71 },
- { 0x59, 0xb7, 0x5f, 0x14, 0x25, 0x1c, 0x75, 0x03,
- 0x1d, 0x0b, 0xcb, 0xac, 0x1c, 0x2c, 0x04, 0xc7 },
- { 0xa2, 0x98, 0xae, 0x89, 0x29, 0xdc },
- { 0xd0, 0x56 },
- { 0xf9, 0x67, 0xf7, 0x60, 0x38, 0xb9, 0x20, 0xa9,
- 0xcd, 0x25, 0xe1, 0x0c, 0x08, 0xb4, 0x99, 0x24 },
- { 0x76, 0x08, 0x9d, 0x3c, 0x0f, 0xf3, 0xef, 0xdc,
- 0x6e, 0x36, 0x72, 0x1d, 0x4f, 0xce, 0xb7, 0x47 },
- { 0xc3, 0xf2, 0x5c, 0xd9, 0x43, 0x09, 0x10, 0x7e },
- { 0xb0, 0xc8, 0xba, 0x34, 0x36, 0x65, 0xaf, 0xcc },
- { 0x7e, 0x3f, 0x44, 0xc7, 0x59, 0x1f, 0x6f, 0x45 },
- { 0xd4, 0x2b, 0x2d, 0x61, 0x5e, 0x49, 0xa0, 0x3a,
- 0xc2, 0x75, 0xa5, 0xae, 0xf9, 0x7a, 0xf8, 0x92 },
- { 0x0b, 0x3f, 0x8d, 0x02, 0x4f, 0xe6, 0xbf, 0xaf,
- 0xaa, 0x98, 0x2b, 0x8f, 0x82, 0xe3, 0x19, 0xc2 },
- { 0x5b, 0xe1, 0x14, 0x95, 0x52, 0x5d },
- { 0x4d, 0x6a, 0x34, 0xa1, 0xe4, 0xeb }
- }, {
- /* 3GPP TS 35.208 v6.0.0 - 4.3.17 Test Set 17 */
- { 0x6c, 0xd1, 0xc6, 0xce, 0xb1, 0xe0, 0x1e, 0x14,
- 0xf1, 0xb8, 0x23, 0x16, 0xa9, 0x0b, 0x7f, 0x3d },
- { 0xf6, 0x9b, 0x78, 0xf3, 0x00, 0xa0, 0x56, 0x8b,
- 0xce, 0x9f, 0x0c, 0xb9, 0x3c, 0x4b, 0xe4, 0xc9 },
- { 0xb4, 0xfc, 0xe5, 0xfe, 0xb0, 0x59 },
- { 0xe4, 0xbb },
- { 0x07, 0x8b, 0xfc, 0xa9, 0x56, 0x46, 0x59, 0xec,
- 0xd8, 0x85, 0x1e, 0x84, 0xe6, 0xc5, 0x9b, 0x48 },
- { 0xa2, 0x19, 0xdc, 0x37, 0xf1, 0xdc, 0x7d, 0x66,
- 0x73, 0x8b, 0x58, 0x43, 0xc7, 0x99, 0xf2, 0x06 },
- { 0x69, 0xa9, 0x08, 0x69, 0xc2, 0x68, 0xcb, 0x7b },
- { 0x2e, 0x0f, 0xdc, 0xf9, 0xfd, 0x1c, 0xfa, 0x6a },
- { 0x70, 0xf6, 0xbd, 0xb9, 0xad, 0x21, 0x52, 0x5f },
- { 0x6e, 0xda, 0xf9, 0x9e, 0x5b, 0xd9, 0xf8, 0x5d,
- 0x5f, 0x36, 0xd9, 0x1c, 0x12, 0x72, 0xfb, 0x4b },
- { 0xd6, 0x1c, 0x85, 0x3c, 0x28, 0x0d, 0xd9, 0xc4,
- 0x6f, 0x29, 0x7b, 0xae, 0xc3, 0x86, 0xde, 0x17 },
- { 0x1c, 0x40, 0x8a, 0x85, 0x8b, 0x3e },
- { 0xaa, 0x4a, 0xe5, 0x2d, 0xaa, 0x30 }
- }, {
- /* 3GPP TS 35.208 v6.0.0 - 4.3.18 Test Set 18 */
- { 0xb7, 0x3a, 0x90, 0xcb, 0xcf, 0x3a, 0xfb, 0x62,
- 0x2d, 0xba, 0x83, 0xc5, 0x8a, 0x84, 0x15, 0xdf },
- { 0xb1, 0x20, 0xf1, 0xc1, 0xa0, 0x10, 0x2a, 0x2f,
- 0x50, 0x7d, 0xd5, 0x43, 0xde, 0x68, 0x28, 0x1f },
- { 0xf1, 0xe8, 0xa5, 0x23, 0xa3, 0x6d },
- { 0x47, 0x1b },
- { 0xb6, 0x72, 0x04, 0x7e, 0x00, 0x3b, 0xb9, 0x52,
- 0xdc, 0xa6, 0xcb, 0x8a, 0xf0, 0xe5, 0xb7, 0x79 },
- { 0xdf, 0x0c, 0x67, 0x86, 0x8f, 0xa2, 0x5f, 0x74,
- 0x8b, 0x70, 0x44, 0xc6, 0xe7, 0xc2, 0x45, 0xb8 },
- { 0xeb, 0xd7, 0x03, 0x41, 0xbc, 0xd4, 0x15, 0xb0 },
- { 0x12, 0x35, 0x9f, 0x5d, 0x82, 0x22, 0x0c, 0x14 },
- { 0x47, 0x9d, 0xd2, 0x5c, 0x20, 0x79, 0x2d, 0x63 },
- { 0x66, 0x19, 0x5d, 0xbe, 0xd0, 0x31, 0x32, 0x74,
- 0xc5, 0xca, 0x77, 0x66, 0x61, 0x5f, 0xa2, 0x5e },
- { 0x66, 0xbe, 0xc7, 0x07, 0xeb, 0x2a, 0xfc, 0x47,
- 0x6d, 0x74, 0x08, 0xa8, 0xf2, 0x92, 0x7b, 0x36 },
- { 0xae, 0xfd, 0xaa, 0x5d, 0xdd, 0x99 },
- { 0x12, 0xec, 0x2b, 0x87, 0xfb, 0xb1 }
- }, {
- /* 3GPP TS 35.208 v6.0.0 - 4.3.19 Test Set 19 */
- { 0x51, 0x22, 0x25, 0x02, 0x14, 0xc3, 0x3e, 0x72,
- 0x3a, 0x5d, 0xd5, 0x23, 0xfc, 0x14, 0x5f, 0xc0 },
- { 0x81, 0xe9, 0x2b, 0x6c, 0x0e, 0xe0, 0xe1, 0x2e,
- 0xbc, 0xeb, 0xa8, 0xd9, 0x2a, 0x99, 0xdf, 0xa5 },
- { 0x16, 0xf3, 0xb3, 0xf7, 0x0f, 0xc2 },
- { 0xc3, 0xab },
- { 0xc9, 0xe8, 0x76, 0x32, 0x86, 0xb5, 0xb9, 0xff,
- 0xbd, 0xf5, 0x6e, 0x12, 0x97, 0xd0, 0x88, 0x7b },
- { 0x98, 0x1d, 0x46, 0x4c, 0x7c, 0x52, 0xeb, 0x6e,
- 0x50, 0x36, 0x23, 0x49, 0x84, 0xad, 0x0b, 0xcf },
- { 0x2a, 0x5c, 0x23, 0xd1, 0x5e, 0xe3, 0x51, 0xd5 },
- { 0x62, 0xda, 0xe3, 0x85, 0x3f, 0x3a, 0xf9, 0xd2 },
- { 0x28, 0xd7, 0xb0, 0xf2, 0xa2, 0xec, 0x3d, 0xe5 },
- { 0x53, 0x49, 0xfb, 0xe0, 0x98, 0x64, 0x9f, 0x94,
- 0x8f, 0x5d, 0x2e, 0x97, 0x3a, 0x81, 0xc0, 0x0f },
- { 0x97, 0x44, 0x87, 0x1a, 0xd3, 0x2b, 0xf9, 0xbb,
- 0xd1, 0xdd, 0x5c, 0xe5, 0x4e, 0x3e, 0x2e, 0x5a },
- { 0xad, 0xa1, 0x5a, 0xeb, 0x7b, 0xb8 },
- { 0xd4, 0x61, 0xbc, 0x15, 0x47, 0x5d }
- }, {
- /* 3GPP TS 35.208 v6.0.0 - 4.3.20 Test Set 20 */
- { 0x90, 0xdc, 0xa4, 0xed, 0xa4, 0x5b, 0x53, 0xcf,
- 0x0f, 0x12, 0xd7, 0xc9, 0xc3, 0xbc, 0x6a, 0x89 },
- { 0x9f, 0xdd, 0xc7, 0x20, 0x92, 0xc6, 0xad, 0x03,
- 0x6b, 0x6e, 0x46, 0x47, 0x89, 0x31, 0x5b, 0x78 },
- { 0x20, 0xf8, 0x13, 0xbd, 0x41, 0x41 },
- { 0x61, 0xdf },
- { 0x3f, 0xfc, 0xfe, 0x5b, 0x7b, 0x11, 0x11, 0x58,
- 0x99, 0x20, 0xd3, 0x52, 0x8e, 0x84, 0xe6, 0x55 },
- { 0xcb, 0x9c, 0xcc, 0xc4, 0xb9, 0x25, 0x8e, 0x6d,
- 0xca, 0x47, 0x60, 0x37, 0x9f, 0xb8, 0x25, 0x81 },
- { 0x09, 0xdb, 0x94, 0xea, 0xb4, 0xf8, 0x14, 0x9e },
- { 0xa2, 0x94, 0x68, 0xaa, 0x97, 0x75, 0xb5, 0x27 },
- { 0xa9, 0x51, 0x00, 0xe2, 0x76, 0x09, 0x52, 0xcd },
- { 0xb5, 0xf2, 0xda, 0x03, 0x88, 0x3b, 0x69, 0xf9,
- 0x6b, 0xf5, 0x2e, 0x02, 0x9e, 0xd9, 0xac, 0x45 },
- { 0xb4, 0x72, 0x13, 0x68, 0xbc, 0x16, 0xea, 0x67,
- 0x87, 0x5c, 0x55, 0x98, 0x68, 0x8b, 0xb0, 0xef },
- { 0x83, 0xcf, 0xd5, 0x4d, 0xb9, 0x13 },
- { 0x4f, 0x20, 0x39, 0x39, 0x2d, 0xdc }
- }
-};
-
-#define NUM_TESTS (sizeof(test_sets) / sizeof(test_sets[0]))
-
-
-int main(int argc, char *argv[])
-{
- u8 buf[16], buf2[16], buf3[16], buf4[16], buf5[16], opc[16];
- u8 auts[14], sqn[6], _rand[16];
- int ret = 0, res, i;
- const struct milenage_test_set *t;
- size_t res_len;
-
- wpa_debug_level = 0;
-
- printf("Milenage test sets\n");
- for (i = 0; i < NUM_TESTS; i++) {
- t = &test_sets[i];
- printf("Test Set %d\n", i + 1);
-
- milenage_opc(t->op, t->k, opc);
- if (memcmp(opc, t->opc, 16) != 0) {
- printf("- milenage_opc failed\n");
- ret++;
- }
-
- if (milenage_f1(opc, t->k, t->rand, t->sqn, t->amf, buf, buf2)
- || memcmp(buf, t->f1, 8) != 0) {
- printf("- milenage_f1 failed\n");
- ret++;
- }
- if (memcmp(buf2, t->f1star, 8) != 0) {
- printf("- milenage_f1* failed\n");
- ret++;
- }
-
- if (milenage_f2345(opc, t->k, t->rand, buf, buf2, buf3, buf4,
- buf5) ||
- memcmp(buf, t->f2, 8) != 0) {
- printf("- milenage_f2 failed\n");
- ret++;
- }
- if (memcmp(buf2, t->f3, 16) != 0) {
- printf("- milenage_f3 failed\n");
- ret++;
- }
- if (memcmp(buf3, t->f4, 16) != 0) {
- printf("- milenage_f4 failed\n");
- ret++;
- }
- if (memcmp(buf4, t->f5, 6) != 0) {
- printf("- milenage_f5 failed\n");
- ret++;
- }
- if (memcmp(buf5, t->f5star, 6) != 0) {
- printf("- milenage_f5* failed\n");
- ret++;
- }
- }
-
- printf("milenage_auts test:\n");
- os_memcpy(auts, "\x4f\x20\x39\x39\x2d\xdd", 6);
- os_memcpy(auts + 6, "\x4b\xb4\x31\x6e\xd4\xa1\x46\x88", 8);
- res = milenage_auts(t->opc, t->k, t->rand, auts, buf);
- printf("AUTS for test set %d: %d / SQN=%02x%02x%02x%02x%02x%02x\n",
- i, res, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
- if (res)
- ret++;
-
- os_memset(_rand, 0xaa, sizeof(_rand));
- os_memcpy(auts,
- "\x43\x68\x1a\xd3\xda\xf0\x06\xbc\xde\x40\x5a\x20\x72\x67",
- 14);
- res = milenage_auts(t->opc, t->k, _rand, auts, buf);
- printf("AUTS from a test USIM: %d / SQN=%02x%02x%02x%02x%02x%02x\n",
- res, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
- if (res)
- ret++;
-
- printf("milenage_generate test:\n");
- os_memcpy(sqn, "\x00\x00\x00\x00\x40\x44", 6);
- os_memcpy(_rand, "\x12\x69\xb8\x23\x41\x39\x35\x66\xfb\x99\x41\xe9\x84"
- "\x4f\xe6\x2f", 16);
- res_len = 8;
- milenage_generate(t->opc, t->amf, t->k, sqn, _rand, buf, buf2, buf3,
- buf4, &res_len);
- wpa_hexdump(MSG_DEBUG, "SQN", sqn, 6);
- wpa_hexdump(MSG_DEBUG, "RAND", _rand, 16);
- wpa_hexdump(MSG_DEBUG, "AUTN", buf, 16);
- wpa_hexdump(MSG_DEBUG, "IK", buf2, 16);
- wpa_hexdump(MSG_DEBUG, "CK", buf3, 16);
- wpa_hexdump(MSG_DEBUG, "RES", buf4, res_len);
-
- printf("GSM-Milenage test sets\n");
- for (i = 0; i < NUM_GSM_TESTS; i++) {
- const struct gsm_milenage_test_set *g;
- u8 sres[4], kc[8];
- g = &gsm_test_sets[i];
- printf("Test Set %d\n", i + 1);
- gsm_milenage(g->opc, g->ki, g->rand, sres, kc);
- if (memcmp(g->kc, kc, 8) != 0) {
- printf("- gsm_milenage Kc failed\n");
- ret++;
- }
-#ifdef GSM_MILENAGE_ALT_SRES
- if (memcmp(g->sres2, sres, 4) != 0) {
- printf("- gsm_milenage SRES#2 failed\n");
- ret++;
- }
-#else /* GSM_MILENAGE_ALT_SRES */
- if (memcmp(g->sres1, sres, 4) != 0) {
- printf("- gsm_milenage SRES#1 failed\n");
- ret++;
- }
-#endif /* GSM_MILENAGE_ALT_SRES */
- }
-
- if (ret)
- printf("Something failed\n");
- else
- printf("OK\n");
-
- return ret;
-}
-#endif /* TEST_MAIN_MILENAGE */
diff --git a/contrib/wpa/src/l2_packet/Makefile b/contrib/wpa/src/l2_packet/Makefile
index cffba62..9c41962 100644
--- a/contrib/wpa/src/l2_packet/Makefile
+++ b/contrib/wpa/src/l2_packet/Makefile
@@ -2,7 +2,6 @@ all:
@echo Nothing to be made.
clean:
- for d in $(SUBDIRS); do make -C $$d clean; done
rm -f *~ *.o *.d
install:
diff --git a/contrib/wpa/src/l2_packet/l2_packet_freebsd.c b/contrib/wpa/src/l2_packet/l2_packet_freebsd.c
index d1034aa..009e02c 100644
--- a/contrib/wpa/src/l2_packet/l2_packet_freebsd.c
+++ b/contrib/wpa/src/l2_packet/l2_packet_freebsd.c
@@ -14,7 +14,7 @@
*/
#include "includes.h"
-#ifdef __APPLE__
+#if defined(__APPLE__) || defined(__GLIBC__)
#include <net/bpf.h>
#endif /* __APPLE__ */
#include <pcap.h>
diff --git a/contrib/wpa/src/l2_packet/l2_packet_ndis.c b/contrib/wpa/src/l2_packet/l2_packet_ndis.c
index 7de5880..6ce29aa 100644
--- a/contrib/wpa/src/l2_packet/l2_packet_ndis.c
+++ b/contrib/wpa/src/l2_packet/l2_packet_ndis.c
@@ -137,11 +137,17 @@ int l2_packet_send(struct l2_packet_data *l2, const u8 *dst_addr, u16 proto,
DWORD err = GetLastError();
#ifndef _WIN32_WCE
if (err == ERROR_IO_PENDING) {
- /* For now, just assume that the packet will be sent in
- * time before the next write happens. This could be
- * cleaned up at some point to actually wait for
- * completion before starting new writes.
- */
+ wpa_printf(MSG_DEBUG, "L2(NDISUIO): Wait for pending "
+ "write to complete");
+ res = GetOverlappedResult(
+ driver_ndis_get_ndisuio_handle(), &overlapped,
+ &written, TRUE);
+ if (!res) {
+ wpa_printf(MSG_DEBUG, "L2(NDISUIO): "
+ "GetOverlappedResult failed: %d",
+ (int) GetLastError());
+ return -1;
+ }
return 0;
}
#endif /* _WIN32_WCE */
diff --git a/contrib/wpa/src/lib.rules b/contrib/wpa/src/lib.rules
new file mode 100644
index 0000000..b260d25
--- /dev/null
+++ b/contrib/wpa/src/lib.rules
@@ -0,0 +1,21 @@
+ifndef CC
+CC=gcc
+endif
+
+ifndef CFLAGS
+CFLAGS = -MMD -O2 -Wall -g
+endif
+
+CFLAGS += -I.. -I../utils
+
+
+Q=@
+E=echo
+ifeq ($(V), 1)
+Q=
+E=true
+endif
+
+%.o: %.c
+ $(Q)$(CC) -c -o $@ $(CFLAGS) $<
+ @$(E) " CC " $<
diff --git a/contrib/wpa/src/radius/.gitignore b/contrib/wpa/src/radius/.gitignore
new file mode 100644
index 0000000..a89a1f9
--- /dev/null
+++ b/contrib/wpa/src/radius/.gitignore
@@ -0,0 +1 @@
+libradius.a
diff --git a/contrib/wpa/src/radius/Makefile b/contrib/wpa/src/radius/Makefile
index cffba62..b199be8 100644
--- a/contrib/wpa/src/radius/Makefile
+++ b/contrib/wpa/src/radius/Makefile
@@ -1,9 +1,22 @@
-all:
- @echo Nothing to be made.
+all: libradius.a
clean:
- for d in $(SUBDIRS); do make -C $$d clean; done
- rm -f *~ *.o *.d
+ rm -f *~ *.o *.d libradius.a
install:
@echo Nothing to be made.
+
+
+include ../lib.rules
+
+CFLAGS += -DCONFIG_IPV6
+
+LIB_OBJS= \
+ radius.o \
+ radius_client.o \
+ radius_server.o
+
+libradius.a: $(LIB_OBJS)
+ $(AR) crT $@ $?
+
+-include $(OBJS:%.o=%.d)
diff --git a/contrib/wpa/src/radius/radius.c b/contrib/wpa/src/radius/radius.c
index 71bbfb5..70754ef 100644
--- a/contrib/wpa/src/radius/radius.c
+++ b/contrib/wpa/src/radius/radius.c
@@ -1,6 +1,6 @@
/*
- * hostapd / RADIUS message processing
- * Copyright (c) 2002-2008, Jouni Malinen <j@w1.fi>
+ * RADIUS message processing
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -12,62 +12,82 @@
* See README and COPYING for more details.
*/
-#include "includes.h"
+#include "utils/includes.h"
-#include "common.h"
+#include "utils/common.h"
+#include "utils/wpabuf.h"
+#include "crypto/md5.h"
+#include "crypto/crypto.h"
#include "radius.h"
-#include "md5.h"
-#include "crypto.h"
-static struct radius_attr_hdr *
-radius_get_attr_hdr(struct radius_msg *msg, int idx)
-{
- return (struct radius_attr_hdr *) (msg->buf + msg->attr_pos[idx]);
-}
+/**
+ * struct radius_msg - RADIUS message structure for new and parsed messages
+ */
+struct radius_msg {
+ /**
+ * buf - Allocated buffer for RADIUS message
+ */
+ struct wpabuf *buf;
+
+ /**
+ * hdr - Pointer to the RADIUS header in buf
+ */
+ struct radius_hdr *hdr;
+ /**
+ * attr_pos - Array of indexes to attributes
+ *
+ * The values are number of bytes from buf to the beginning of
+ * struct radius_attr_hdr.
+ */
+ size_t *attr_pos;
+
+ /**
+ * attr_size - Total size of the attribute pointer array
+ */
+ size_t attr_size;
+
+ /**
+ * attr_used - Total number of attributes in the array
+ */
+ size_t attr_used;
+};
-struct radius_msg *radius_msg_new(u8 code, u8 identifier)
+
+struct radius_hdr * radius_msg_get_hdr(struct radius_msg *msg)
{
- struct radius_msg *msg;
+ return msg->hdr;
+}
- msg = os_malloc(sizeof(*msg));
- if (msg == NULL)
- return NULL;
- if (radius_msg_initialize(msg, RADIUS_DEFAULT_MSG_SIZE)) {
- os_free(msg);
- return NULL;
- }
+struct wpabuf * radius_msg_get_buf(struct radius_msg *msg)
+{
+ return msg->buf;
+}
- radius_msg_set_hdr(msg, code, identifier);
- return msg;
+static struct radius_attr_hdr *
+radius_get_attr_hdr(struct radius_msg *msg, int idx)
+{
+ return (struct radius_attr_hdr *)
+ (wpabuf_mhead_u8(msg->buf) + msg->attr_pos[idx]);
}
-int radius_msg_initialize(struct radius_msg *msg, size_t init_len)
+static void radius_msg_set_hdr(struct radius_msg *msg, u8 code, u8 identifier)
{
- if (msg == NULL || init_len < sizeof(struct radius_hdr))
- return -1;
-
- os_memset(msg, 0, sizeof(*msg));
- msg->buf = os_zalloc(init_len);
- if (msg->buf == NULL)
- return -1;
+ msg->hdr->code = code;
+ msg->hdr->identifier = identifier;
+}
- msg->buf_size = init_len;
- msg->hdr = (struct radius_hdr *) msg->buf;
- msg->buf_used = sizeof(*msg->hdr);
+static int radius_msg_initialize(struct radius_msg *msg)
+{
msg->attr_pos =
os_zalloc(RADIUS_DEFAULT_ATTR_COUNT * sizeof(*msg->attr_pos));
- if (msg->attr_pos == NULL) {
- os_free(msg->buf);
- msg->buf = NULL;
- msg->hdr = NULL;
+ if (msg->attr_pos == NULL)
return -1;
- }
msg->attr_size = RADIUS_DEFAULT_ATTR_COUNT;
msg->attr_used = 0;
@@ -76,23 +96,48 @@ int radius_msg_initialize(struct radius_msg *msg, size_t init_len)
}
-void radius_msg_set_hdr(struct radius_msg *msg, u8 code, u8 identifier)
+/**
+ * radius_msg_new - Create a new RADIUS message
+ * @code: Code for RADIUS header
+ * @identifier: Identifier for RADIUS header
+ * Returns: Context for RADIUS message or %NULL on failure
+ *
+ * The caller is responsible for freeing the returned data with
+ * radius_msg_free().
+ */
+struct radius_msg * radius_msg_new(u8 code, u8 identifier)
{
- msg->hdr->code = code;
- msg->hdr->identifier = identifier;
+ struct radius_msg *msg;
+
+ msg = os_zalloc(sizeof(*msg));
+ if (msg == NULL)
+ return NULL;
+
+ msg->buf = wpabuf_alloc(RADIUS_DEFAULT_MSG_SIZE);
+ if (msg->buf == NULL || radius_msg_initialize(msg)) {
+ radius_msg_free(msg);
+ return NULL;
+ }
+ msg->hdr = wpabuf_put(msg->buf, sizeof(struct radius_hdr));
+
+ radius_msg_set_hdr(msg, code, identifier);
+
+ return msg;
}
+/**
+ * radius_msg_free - Free a RADIUS message
+ * @msg: RADIUS message from radius_msg_new() or radius_msg_parse()
+ */
void radius_msg_free(struct radius_msg *msg)
{
- os_free(msg->buf);
- msg->buf = NULL;
- msg->hdr = NULL;
- msg->buf_size = msg->buf_used = 0;
+ if (msg == NULL)
+ return;
+ wpabuf_free(msg->buf);
os_free(msg->attr_pos);
- msg->attr_pos = NULL;
- msg->attr_size = msg->attr_used = 0;
+ os_free(msg);
}
@@ -305,19 +350,19 @@ int radius_msg_finish(struct radius_msg *msg, const u8 *secret,
RADIUS_ATTR_MESSAGE_AUTHENTICATOR,
auth, MD5_MAC_LEN);
if (attr == NULL) {
- printf("WARNING: Could not add "
- "Message-Authenticator\n");
+ wpa_printf(MSG_WARNING, "RADIUS: Could not add "
+ "Message-Authenticator");
return -1;
}
- msg->hdr->length = htons(msg->buf_used);
- hmac_md5(secret, secret_len, msg->buf, msg->buf_used,
- (u8 *) (attr + 1));
+ msg->hdr->length = htons(wpabuf_len(msg->buf));
+ hmac_md5(secret, secret_len, wpabuf_head(msg->buf),
+ wpabuf_len(msg->buf), (u8 *) (attr + 1));
} else
- msg->hdr->length = htons(msg->buf_used);
+ msg->hdr->length = htons(wpabuf_len(msg->buf));
- if (msg->buf_used > 0xffff) {
- printf("WARNING: too long RADIUS message (%lu)\n",
- (unsigned long) msg->buf_used);
+ if (wpabuf_len(msg->buf) > 0xffff) {
+ wpa_printf(MSG_WARNING, "RADIUS: Too long message (%lu)",
+ (unsigned long) wpabuf_len(msg->buf));
return -1;
}
return 0;
@@ -339,26 +384,26 @@ int radius_msg_finish_srv(struct radius_msg *msg, const u8 *secret,
printf("WARNING: Could not add Message-Authenticator\n");
return -1;
}
- msg->hdr->length = htons(msg->buf_used);
+ msg->hdr->length = htons(wpabuf_len(msg->buf));
os_memcpy(msg->hdr->authenticator, req_authenticator,
sizeof(msg->hdr->authenticator));
- hmac_md5(secret, secret_len, msg->buf, msg->buf_used,
- (u8 *) (attr + 1));
+ hmac_md5(secret, secret_len, wpabuf_head(msg->buf),
+ wpabuf_len(msg->buf), (u8 *) (attr + 1));
/* ResponseAuth = MD5(Code+ID+Length+RequestAuth+Attributes+Secret) */
addr[0] = (u8 *) msg->hdr;
len[0] = 1 + 1 + 2;
addr[1] = req_authenticator;
len[1] = MD5_MAC_LEN;
- addr[2] = (u8 *) (msg->hdr + 1);
- len[2] = msg->buf_used - sizeof(*msg->hdr);
+ addr[2] = wpabuf_head_u8(msg->buf) + sizeof(struct radius_hdr);
+ len[2] = wpabuf_len(msg->buf) - sizeof(struct radius_hdr);
addr[3] = secret;
len[3] = secret_len;
md5_vector(4, addr, len, msg->hdr->authenticator);
- if (msg->buf_used > 0xffff) {
- printf("WARNING: too long RADIUS message (%lu)\n",
- (unsigned long) msg->buf_used);
+ if (wpabuf_len(msg->buf) > 0xffff) {
+ wpa_printf(MSG_WARNING, "RADIUS: Too long message (%lu)",
+ (unsigned long) wpabuf_len(msg->buf));
return -1;
}
return 0;
@@ -371,17 +416,17 @@ void radius_msg_finish_acct(struct radius_msg *msg, const u8 *secret,
const u8 *addr[2];
size_t len[2];
- msg->hdr->length = htons(msg->buf_used);
+ msg->hdr->length = htons(wpabuf_len(msg->buf));
os_memset(msg->hdr->authenticator, 0, MD5_MAC_LEN);
- addr[0] = msg->buf;
- len[0] = msg->buf_used;
+ addr[0] = wpabuf_head(msg->buf);
+ len[0] = wpabuf_len(msg->buf);
addr[1] = secret;
len[1] = secret_len;
md5_vector(2, addr, len, msg->hdr->authenticator);
- if (msg->buf_used > 0xffff) {
- printf("WARNING: too long RADIUS messages (%lu)\n",
- (unsigned long) msg->buf_used);
+ if (wpabuf_len(msg->buf) > 0xffff) {
+ wpa_printf(MSG_WARNING, "RADIUS: Too long messages (%lu)",
+ (unsigned long) wpabuf_len(msg->buf));
}
}
@@ -402,7 +447,8 @@ static int radius_msg_add_attr_to_array(struct radius_msg *msg,
msg->attr_size = nlen;
}
- msg->attr_pos[msg->attr_used++] = (unsigned char *) attr - msg->buf;
+ msg->attr_pos[msg->attr_used++] =
+ (unsigned char *) attr - wpabuf_head_u8(msg->buf);
return 0;
}
@@ -420,31 +466,19 @@ struct radius_attr_hdr *radius_msg_add_attr(struct radius_msg *msg, u8 type,
return NULL;
}
- buf_needed = msg->buf_used + sizeof(*attr) + data_len;
+ buf_needed = sizeof(*attr) + data_len;
- if (msg->buf_size < buf_needed) {
+ if (wpabuf_tailroom(msg->buf) < buf_needed) {
/* allocate more space for message buffer */
- unsigned char *nbuf;
- size_t nlen = msg->buf_size;
-
- while (nlen < buf_needed)
- nlen *= 2;
- nbuf = os_realloc(msg->buf, nlen);
- if (nbuf == NULL)
+ if (wpabuf_resize(&msg->buf, buf_needed) < 0)
return NULL;
- msg->buf = nbuf;
- msg->hdr = (struct radius_hdr *) msg->buf;
- os_memset(msg->buf + msg->buf_size, 0, nlen - msg->buf_size);
- msg->buf_size = nlen;
+ msg->hdr = wpabuf_mhead(msg->buf);
}
- attr = (struct radius_attr_hdr *) (msg->buf + msg->buf_used);
+ attr = wpabuf_put(msg->buf, sizeof(struct radius_attr_hdr));
attr->type = type;
attr->length = sizeof(*attr) + data_len;
- if (data_len > 0)
- os_memcpy(attr + 1, data, data_len);
-
- msg->buf_used += sizeof(*attr) + data_len;
+ wpabuf_put_data(msg->buf, data, data_len);
if (radius_msg_add_attr_to_array(msg, attr))
return NULL;
@@ -453,7 +487,16 @@ struct radius_attr_hdr *radius_msg_add_attr(struct radius_msg *msg, u8 type,
}
-struct radius_msg *radius_msg_parse(const u8 *data, size_t len)
+/**
+ * radius_msg_parse - Parse a RADIUS message
+ * @data: RADIUS message to be parsed
+ * @len: Length of data buffer in octets
+ * Returns: Parsed RADIUS message or %NULL on failure
+ *
+ * This parses a RADIUS message and makes a copy of its data. The caller is
+ * responsible for freeing the returned data with radius_msg_free().
+ */
+struct radius_msg * radius_msg_parse(const u8 *data, size_t len)
{
struct radius_msg *msg;
struct radius_hdr *hdr;
@@ -468,30 +511,29 @@ struct radius_msg *radius_msg_parse(const u8 *data, size_t len)
msg_len = ntohs(hdr->length);
if (msg_len < sizeof(*hdr) || msg_len > len) {
- printf("Invalid RADIUS message length\n");
+ wpa_printf(MSG_INFO, "RADIUS: Invalid message length");
return NULL;
}
if (msg_len < len) {
- printf("Ignored %lu extra bytes after RADIUS message\n",
- (unsigned long) len - msg_len);
+ wpa_printf(MSG_DEBUG, "RADIUS: Ignored %lu extra bytes after "
+ "RADIUS message", (unsigned long) len - msg_len);
}
- msg = os_malloc(sizeof(*msg));
+ msg = os_zalloc(sizeof(*msg));
if (msg == NULL)
return NULL;
- if (radius_msg_initialize(msg, msg_len)) {
- os_free(msg);
+ msg->buf = wpabuf_alloc_copy(data, msg_len);
+ if (msg->buf == NULL || radius_msg_initialize(msg)) {
+ radius_msg_free(msg);
return NULL;
}
-
- os_memcpy(msg->buf, data, msg_len);
- msg->buf_size = msg->buf_used = msg_len;
+ msg->hdr = wpabuf_mhead(msg->buf);
/* parse attributes */
- pos = (unsigned char *) (msg->hdr + 1);
- end = msg->buf + msg->buf_used;
+ pos = wpabuf_mhead_u8(msg->buf) + sizeof(struct radius_hdr);
+ end = wpabuf_mhead_u8(msg->buf) + wpabuf_len(msg->buf);
while (pos < end) {
if ((size_t) (end - pos) < sizeof(*attr))
goto fail;
@@ -513,7 +555,6 @@ struct radius_msg *radius_msg_parse(const u8 *data, size_t len)
fail:
radius_msg_free(msg);
- os_free(msg);
return NULL;
}
@@ -615,7 +656,8 @@ int radius_msg_verify_msg_auth(struct radius_msg *msg, const u8 *secret,
os_memcpy(msg->hdr->authenticator, req_auth,
sizeof(msg->hdr->authenticator));
}
- hmac_md5(secret, secret_len, msg->buf, msg->buf_used, auth);
+ hmac_md5(secret, secret_len, wpabuf_head(msg->buf),
+ wpabuf_len(msg->buf), auth);
os_memcpy(attr + 1, orig, MD5_MAC_LEN);
if (req_auth) {
os_memcpy(msg->hdr->authenticator, orig_authenticator,
@@ -654,8 +696,8 @@ int radius_msg_verify(struct radius_msg *msg, const u8 *secret,
len[0] = 1 + 1 + 2;
addr[1] = sent_msg->hdr->authenticator;
len[1] = MD5_MAC_LEN;
- addr[2] = (u8 *) (msg->hdr + 1);
- len[2] = msg->buf_used - sizeof(*msg->hdr);
+ addr[2] = wpabuf_head_u8(msg->buf) + sizeof(struct radius_hdr);
+ len[2] = wpabuf_len(msg->buf) - sizeof(struct radius_hdr);
addr[3] = secret;
len[3] = secret_len;
md5_vector(4, addr, len, hash);
@@ -1232,3 +1274,44 @@ int radius_msg_get_vlanid(struct radius_msg *msg)
return -1;
}
+
+
+void radius_free_class(struct radius_class_data *c)
+{
+ size_t i;
+ if (c == NULL)
+ return;
+ for (i = 0; i < c->count; i++)
+ os_free(c->attr[i].data);
+ os_free(c->attr);
+ c->attr = NULL;
+ c->count = 0;
+}
+
+
+int radius_copy_class(struct radius_class_data *dst,
+ const struct radius_class_data *src)
+{
+ size_t i;
+
+ if (src->attr == NULL)
+ return 0;
+
+ dst->attr = os_zalloc(src->count * sizeof(struct radius_attr_data));
+ if (dst->attr == NULL)
+ return -1;
+
+ dst->count = 0;
+
+ for (i = 0; i < src->count; i++) {
+ dst->attr[i].data = os_malloc(src->attr[i].len);
+ if (dst->attr[i].data == NULL)
+ break;
+ dst->count++;
+ os_memcpy(dst->attr[i].data, src->attr[i].data,
+ src->attr[i].len);
+ dst->attr[i].len = src->attr[i].len;
+ }
+
+ return 0;
+}
diff --git a/contrib/wpa/src/radius/radius.h b/contrib/wpa/src/radius/radius.h
index c30621d..a3cdac0 100644
--- a/contrib/wpa/src/radius/radius.h
+++ b/contrib/wpa/src/radius/radius.h
@@ -1,6 +1,6 @@
/*
- * hostapd / RADIUS message processing
- * Copyright (c) 2002-2007, Jouni Malinen <j@w1.fi>
+ * RADIUS message processing
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -173,21 +173,7 @@ struct radius_ms_mppe_keys {
};
-/* RADIUS message structure for new and parsed messages */
-struct radius_msg {
- unsigned char *buf;
- size_t buf_size; /* total size allocated for buf */
- size_t buf_used; /* bytes used in buf */
-
- struct radius_hdr *hdr;
-
- size_t *attr_pos; /* array of indexes to attributes (number of bytes
- * from buf to the beginning of
- * struct radius_attr_hdr). */
- size_t attr_size; /* total size of the attribute pointer array */
- size_t attr_used; /* total number of attributes in the array */
-};
-
+struct radius_msg;
/* Default size to be allocated for new RADIUS messages */
#define RADIUS_DEFAULT_MSG_SIZE 1024
@@ -202,9 +188,9 @@ struct radius_msg {
/* MAC address ASCII format for non-802.1X use */
#define RADIUS_ADDR_FORMAT "%02x%02x%02x%02x%02x%02x"
-struct radius_msg *radius_msg_new(u8 code, u8 identifier);
-int radius_msg_initialize(struct radius_msg *msg, size_t init_len);
-void radius_msg_set_hdr(struct radius_msg *msg, u8 code, u8 identifier);
+struct radius_hdr * radius_msg_get_hdr(struct radius_msg *msg);
+struct wpabuf * radius_msg_get_buf(struct radius_msg *msg);
+struct radius_msg * radius_msg_new(u8 code, u8 identifier);
void radius_msg_free(struct radius_msg *msg);
void radius_msg_dump(struct radius_msg *msg);
int radius_msg_finish(struct radius_msg *msg, const u8 *secret,
@@ -213,9 +199,9 @@ int radius_msg_finish_srv(struct radius_msg *msg, const u8 *secret,
size_t secret_len, const u8 *req_authenticator);
void radius_msg_finish_acct(struct radius_msg *msg, const u8 *secret,
size_t secret_len);
-struct radius_attr_hdr *radius_msg_add_attr(struct radius_msg *msg, u8 type,
- const u8 *data, size_t data_len);
-struct radius_msg *radius_msg_parse(const u8 *data, size_t len);
+struct radius_attr_hdr * radius_msg_add_attr(struct radius_msg *msg, u8 type,
+ const u8 *data, size_t data_len);
+struct radius_msg * radius_msg_parse(const u8 *data, size_t len);
int radius_msg_add_eap(struct radius_msg *msg, const u8 *data,
size_t data_len);
u8 *radius_msg_get_eap(struct radius_msg *msg, size_t *len);
@@ -269,4 +255,19 @@ int radius_msg_get_attr_ptr(struct radius_msg *msg, u8 type, u8 **buf,
size_t *len, const u8 *start);
int radius_msg_count_attr(struct radius_msg *msg, u8 type, int min_len);
+
+struct radius_attr_data {
+ u8 *data;
+ size_t len;
+};
+
+struct radius_class_data {
+ struct radius_attr_data *attr;
+ size_t count;
+};
+
+void radius_free_class(struct radius_class_data *c);
+int radius_copy_class(struct radius_class_data *dst,
+ const struct radius_class_data *src);
+
#endif /* RADIUS_H */
diff --git a/contrib/wpa/src/radius/radius_client.c b/contrib/wpa/src/radius/radius_client.c
index 826acad..171af29 100644
--- a/contrib/wpa/src/radius/radius_client.c
+++ b/contrib/wpa/src/radius/radius_client.c
@@ -1,6 +1,6 @@
/*
- * hostapd / RADIUS client
- * Copyright (c) 2002-2005, Jouni Malinen <j@w1.fi>
+ * RADIUS client
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -20,68 +20,217 @@
#include "eloop.h"
/* Defaults for RADIUS retransmit values (exponential backoff) */
-#define RADIUS_CLIENT_FIRST_WAIT 3 /* seconds */
-#define RADIUS_CLIENT_MAX_WAIT 120 /* seconds */
-#define RADIUS_CLIENT_MAX_RETRIES 10 /* maximum number of retransmit attempts
- * before entry is removed from retransmit
- * list */
-#define RADIUS_CLIENT_MAX_ENTRIES 30 /* maximum number of entries in retransmit
- * list (oldest will be removed, if this
- * limit is exceeded) */
-#define RADIUS_CLIENT_NUM_FAILOVER 4 /* try to change RADIUS server after this
- * many failed retry attempts */
+/**
+ * RADIUS_CLIENT_FIRST_WAIT - RADIUS client timeout for first retry in seconds
+ */
+#define RADIUS_CLIENT_FIRST_WAIT 3
+
+/**
+ * RADIUS_CLIENT_MAX_WAIT - RADIUS client maximum retry timeout in seconds
+ */
+#define RADIUS_CLIENT_MAX_WAIT 120
+
+/**
+ * RADIUS_CLIENT_MAX_RETRIES - RADIUS client maximum retries
+ *
+ * Maximum number of retransmit attempts before the entry is removed from
+ * retransmit list.
+ */
+#define RADIUS_CLIENT_MAX_RETRIES 10
+
+/**
+ * RADIUS_CLIENT_MAX_ENTRIES - RADIUS client maximum pending messages
+ *
+ * Maximum number of entries in retransmit list (oldest entries will be
+ * removed, if this limit is exceeded).
+ */
+#define RADIUS_CLIENT_MAX_ENTRIES 30
+/**
+ * RADIUS_CLIENT_NUM_FAILOVER - RADIUS client failover point
+ *
+ * The number of failed retry attempts after which the RADIUS server will be
+ * changed (if one of more backup servers are configured).
+ */
+#define RADIUS_CLIENT_NUM_FAILOVER 4
+
+
+/**
+ * struct radius_rx_handler - RADIUS client RX handler
+ *
+ * This data structure is used internally inside the RADIUS client module to
+ * store registered RX handlers. These handlers are registered by calls to
+ * radius_client_register() and unregistered when the RADIUS client is
+ * deinitialized with a call to radius_client_deinit().
+ */
struct radius_rx_handler {
+ /**
+ * handler - Received RADIUS message handler
+ */
RadiusRxResult (*handler)(struct radius_msg *msg,
struct radius_msg *req,
const u8 *shared_secret,
size_t shared_secret_len,
void *data);
+
+ /**
+ * data - Context data for the handler
+ */
void *data;
};
-/* RADIUS message retransmit list */
+/**
+ * struct radius_msg_list - RADIUS client message retransmit list
+ *
+ * This data structure is used internally inside the RADIUS client module to
+ * store pending RADIUS requests that may still need to be retransmitted.
+ */
struct radius_msg_list {
- u8 addr[ETH_ALEN]; /* STA/client address; used to find RADIUS messages
- * for the same STA. */
+ /**
+ * addr - STA/client address
+ *
+ * This is used to find RADIUS messages for the same STA.
+ */
+ u8 addr[ETH_ALEN];
+
+ /**
+ * msg - RADIUS message
+ */
struct radius_msg *msg;
+
+ /**
+ * msg_type - Message type
+ */
RadiusType msg_type;
+
+ /**
+ * first_try - Time of the first transmission attempt
+ */
os_time_t first_try;
+
+ /**
+ * next_try - Time for the next transmission attempt
+ */
os_time_t next_try;
+
+ /**
+ * attempts - Number of transmission attempts
+ */
int attempts;
+
+ /**
+ * next_wait - Next retransmission wait time in seconds
+ */
int next_wait;
+
+ /**
+ * last_attempt - Time of the last transmission attempt
+ */
struct os_time last_attempt;
- u8 *shared_secret;
+ /**
+ * shared_secret - Shared secret with the target RADIUS server
+ */
+ const u8 *shared_secret;
+
+ /**
+ * shared_secret_len - shared_secret length in octets
+ */
size_t shared_secret_len;
/* TODO: server config with failover to backup server(s) */
+ /**
+ * next - Next message in the list
+ */
struct radius_msg_list *next;
};
+/**
+ * struct radius_client_data - Internal RADIUS client data
+ *
+ * This data structure is used internally inside the RADIUS client module.
+ * External users allocate this by calling radius_client_init() and free it by
+ * calling radius_client_deinit(). The pointer to this opaque data is used in
+ * calls to other functions as an identifier for the RADIUS client instance.
+ */
struct radius_client_data {
+ /**
+ * ctx - Context pointer for hostapd_logger() callbacks
+ */
void *ctx;
+
+ /**
+ * conf - RADIUS client configuration (list of RADIUS servers to use)
+ */
struct hostapd_radius_servers *conf;
- int auth_serv_sock; /* socket for authentication RADIUS messages */
- int acct_serv_sock; /* socket for accounting RADIUS messages */
+ /**
+ * auth_serv_sock - IPv4 socket for RADIUS authentication messages
+ */
+ int auth_serv_sock;
+
+ /**
+ * acct_serv_sock - IPv4 socket for RADIUS accounting messages
+ */
+ int acct_serv_sock;
+
+ /**
+ * auth_serv_sock6 - IPv6 socket for RADIUS authentication messages
+ */
int auth_serv_sock6;
+
+ /**
+ * acct_serv_sock6 - IPv6 socket for RADIUS accounting messages
+ */
int acct_serv_sock6;
- int auth_sock; /* currently used socket */
- int acct_sock; /* currently used socket */
+ /**
+ * auth_sock - Currently used socket for RADIUS authentication server
+ */
+ int auth_sock;
+
+ /**
+ * acct_sock - Currently used socket for RADIUS accounting server
+ */
+ int acct_sock;
+
+ /**
+ * auth_handlers - Authentication message handlers
+ */
struct radius_rx_handler *auth_handlers;
+
+ /**
+ * num_auth_handlers - Number of handlers in auth_handlers
+ */
size_t num_auth_handlers;
+
+ /**
+ * acct_handlers - Accounting message handlers
+ */
struct radius_rx_handler *acct_handlers;
+
+ /**
+ * num_acct_handlers - Number of handlers in acct_handlers
+ */
size_t num_acct_handlers;
+ /**
+ * msgs - Pending outgoing RADIUS messages
+ */
struct radius_msg_list *msgs;
+
+ /**
+ * num_msgs - Number of pending messages in the msgs list
+ */
size_t num_msgs;
+ /**
+ * next_radius_identifier - Next RADIUS message identifier to use
+ */
u8 next_radius_identifier;
};
@@ -98,11 +247,26 @@ static int radius_client_init_auth(struct radius_client_data *radius);
static void radius_client_msg_free(struct radius_msg_list *req)
{
radius_msg_free(req->msg);
- os_free(req->msg);
os_free(req);
}
+/**
+ * radius_client_register - Register a RADIUS client RX handler
+ * @radius: RADIUS client context from radius_client_init()
+ * @msg_type: RADIUS client type (RADIUS_AUTH or RADIUS_ACCT)
+ * @handler: Handler for received RADIUS messages
+ * @data: Context pointer for handler callbacks
+ * Returns: 0 on success, -1 on failure
+ *
+ * This function is used to register a handler for processing received RADIUS
+ * authentication and accounting messages. The handler() callback function will
+ * be called whenever a RADIUS message is received from the active server.
+ *
+ * There can be multiple registered RADIUS message handlers. The handlers will
+ * be called in order until one of them indicates that it has processed or
+ * queued the message.
+ */
int radius_client_register(struct radius_client_data *radius,
RadiusType msg_type,
RadiusRxResult (*handler)(struct radius_msg *msg,
@@ -166,6 +330,7 @@ static int radius_client_retransmit(struct radius_client_data *radius,
{
struct hostapd_radius_servers *conf = radius->conf;
int s;
+ struct wpabuf *buf;
if (entry->msg_type == RADIUS_ACCT ||
entry->msg_type == RADIUS_ACCT_INTERIM) {
@@ -190,10 +355,11 @@ static int radius_client_retransmit(struct radius_client_data *radius,
entry->attempts++;
hostapd_logger(radius->ctx, entry->addr, HOSTAPD_MODULE_RADIUS,
HOSTAPD_LEVEL_DEBUG, "Resending RADIUS message (id=%d)",
- entry->msg->hdr->identifier);
+ radius_msg_get_hdr(entry->msg)->identifier);
os_get_time(&entry->last_attempt);
- if (send(s, entry->msg->buf, entry->msg->buf_used, 0) < 0)
+ buf = radius_msg_get_buf(entry->msg);
+ if (send(s, wpabuf_head(buf), wpabuf_len(buf), 0) < 0)
radius_client_handle_send_error(radius, s, entry->msg_type);
entry->next_try = now + entry->next_wait;
@@ -351,7 +517,8 @@ static void radius_client_update_timeout(struct radius_client_data *radius)
static void radius_client_list_add(struct radius_client_data *radius,
struct radius_msg *msg,
- RadiusType msg_type, u8 *shared_secret,
+ RadiusType msg_type,
+ const u8 *shared_secret,
size_t shared_secret_len, const u8 *addr)
{
struct radius_msg_list *entry, *prev;
@@ -360,7 +527,6 @@ static void radius_client_list_add(struct radius_client_data *radius,
/* No point in adding entries to retransmit queue since event
* loop has already been terminated. */
radius_msg_free(msg);
- os_free(msg);
return;
}
@@ -368,7 +534,6 @@ static void radius_client_list_add(struct radius_client_data *radius,
if (entry == NULL) {
printf("Failed to add RADIUS packet into retransmit list\n");
radius_msg_free(msg);
- os_free(msg);
return;
}
@@ -437,15 +602,38 @@ static void radius_client_list_del(struct radius_client_data *radius,
}
+/**
+ * radius_client_send - Send a RADIUS request
+ * @radius: RADIUS client context from radius_client_init()
+ * @msg: RADIUS message to be sent
+ * @msg_type: Message type (RADIUS_AUTH, RADIUS_ACCT, RADIUS_ACCT_INTERIM)
+ * @addr: MAC address of the device related to this message or %NULL
+ * Returns: 0 on success, -1 on failure
+ *
+ * This function is used to transmit a RADIUS authentication (RADIUS_AUTH) or
+ * accounting request (RADIUS_ACCT or RADIUS_ACCT_INTERIM). The only difference
+ * between accounting and interim accounting messages is that the interim
+ * message will override any pending interim accounting updates while a new
+ * accounting message does not remove any pending messages.
+ *
+ * The message is added on the retransmission queue and will be retransmitted
+ * automatically until a response is received or maximum number of retries
+ * (RADIUS_CLIENT_MAX_RETRIES) is reached.
+ *
+ * The related device MAC address can be used to identify pending messages that
+ * can be removed with radius_client_flush_auth() or with interim accounting
+ * updates.
+ */
int radius_client_send(struct radius_client_data *radius,
struct radius_msg *msg, RadiusType msg_type,
const u8 *addr)
{
struct hostapd_radius_servers *conf = radius->conf;
- u8 *shared_secret;
+ const u8 *shared_secret;
size_t shared_secret_len;
char *name;
int s, res;
+ struct wpabuf *buf;
if (msg_type == RADIUS_ACCT_INTERIM) {
/* Remove any pending interim acct update for the same STA. */
@@ -488,7 +676,8 @@ int radius_client_send(struct radius_client_data *radius,
if (conf->msg_dumps)
radius_msg_dump(msg);
- res = send(s, msg->buf, msg->buf_used, 0);
+ buf = radius_msg_get_buf(msg);
+ res = send(s, wpabuf_head(buf), wpabuf_len(buf), 0);
if (res < 0)
radius_client_handle_send_error(radius, s, msg_type);
@@ -507,6 +696,7 @@ static void radius_client_receive(int sock, void *eloop_ctx, void *sock_ctx)
int len, roundtrip;
unsigned char buf[3000];
struct radius_msg *msg;
+ struct radius_hdr *hdr;
struct radius_rx_handler *handlers;
size_t num_handlers, i;
struct radius_msg_list *req, *prev_req;
@@ -544,13 +734,14 @@ static void radius_client_receive(int sock, void *eloop_ctx, void *sock_ctx)
rconf->malformed_responses++;
return;
}
+ hdr = radius_msg_get_hdr(msg);
hostapd_logger(radius->ctx, NULL, HOSTAPD_MODULE_RADIUS,
HOSTAPD_LEVEL_DEBUG, "Received RADIUS message");
if (conf->msg_dumps)
radius_msg_dump(msg);
- switch (msg->hdr->code) {
+ switch (hdr->code) {
case RADIUS_CODE_ACCESS_ACCEPT:
rconf->access_accepts++;
break;
@@ -573,7 +764,8 @@ static void radius_client_receive(int sock, void *eloop_ctx, void *sock_ctx)
if ((req->msg_type == msg_type ||
(req->msg_type == RADIUS_ACCT_INTERIM &&
msg_type == RADIUS_ACCT)) &&
- req->msg->hdr->identifier == msg->hdr->identifier)
+ radius_msg_get_hdr(req->msg)->identifier ==
+ hdr->identifier)
break;
prev_req = req;
@@ -585,7 +777,7 @@ static void radius_client_receive(int sock, void *eloop_ctx, void *sock_ctx)
HOSTAPD_LEVEL_DEBUG,
"No matching RADIUS request found (type=%d "
"id=%d) - dropping packet",
- msg_type, msg->hdr->identifier);
+ msg_type, hdr->identifier);
goto fail;
}
@@ -614,7 +806,6 @@ static void radius_client_receive(int sock, void *eloop_ctx, void *sock_ctx)
switch (res) {
case RADIUS_RX_PROCESSED:
radius_msg_free(msg);
- os_free(msg);
/* continue */
case RADIUS_RX_QUEUED:
radius_client_msg_free(req);
@@ -635,17 +826,24 @@ static void radius_client_receive(int sock, void *eloop_ctx, void *sock_ctx)
hostapd_logger(radius->ctx, req->addr, HOSTAPD_MODULE_RADIUS,
HOSTAPD_LEVEL_DEBUG, "No RADIUS RX handler found "
"(type=%d code=%d id=%d)%s - dropping packet",
- msg_type, msg->hdr->code, msg->hdr->identifier,
+ msg_type, hdr->code, hdr->identifier,
invalid_authenticator ? " [INVALID AUTHENTICATOR]" :
"");
radius_client_msg_free(req);
fail:
radius_msg_free(msg);
- os_free(msg);
}
+/**
+ * radius_client_get_id - Get an identifier for a new RADIUS message
+ * @radius: RADIUS client context from radius_client_init()
+ * Returns: Allocated identifier
+ *
+ * This function is used to fetch a unique (among pending requests) identifier
+ * for a new RADIUS message.
+ */
u8 radius_client_get_id(struct radius_client_data *radius)
{
struct radius_msg_list *entry, *prev, *_remove;
@@ -656,7 +854,7 @@ u8 radius_client_get_id(struct radius_client_data *radius)
entry = radius->msgs;
prev = NULL;
while (entry) {
- if (entry->msg->hdr->identifier == id) {
+ if (radius_msg_get_hdr(entry->msg)->identifier == id) {
hostapd_logger(radius->ctx, entry->addr,
HOSTAPD_MODULE_RADIUS,
HOSTAPD_LEVEL_DEBUG,
@@ -681,6 +879,11 @@ u8 radius_client_get_id(struct radius_client_data *radius)
}
+/**
+ * radius_client_flush - Flush all pending RADIUS client messages
+ * @radius: RADIUS client context from radius_client_init()
+ * @only_auth: Whether only authentication messages are removed
+ */
void radius_client_flush(struct radius_client_data *radius, int only_auth)
{
struct radius_msg_list *entry, *prev, *tmp;
@@ -714,7 +917,7 @@ void radius_client_flush(struct radius_client_data *radius, int only_auth)
static void radius_client_update_acct_msgs(struct radius_client_data *radius,
- u8 *shared_secret,
+ const u8 *shared_secret,
size_t shared_secret_len)
{
struct radius_msg_list *entry;
@@ -1037,6 +1240,16 @@ static int radius_client_init_acct(struct radius_client_data *radius)
}
+/**
+ * radius_client_init - Initialize RADIUS client
+ * @ctx: Callback context to be used in hostapd_logger() calls
+ * @conf: RADIUS client configuration (RADIUS servers)
+ * Returns: Pointer to private RADIUS client context or %NULL on failure
+ *
+ * The caller is responsible for keeping the configuration data available for
+ * the lifetime of the RADIUS client, i.e., until radius_client_deinit() is
+ * called for the returned context pointer.
+ */
struct radius_client_data *
radius_client_init(void *ctx, struct hostapd_radius_servers *conf)
{
@@ -1071,6 +1284,10 @@ radius_client_init(void *ctx, struct hostapd_radius_servers *conf)
}
+/**
+ * radius_client_deinit - Deinitialize RADIUS client
+ * @radius: RADIUS client context from radius_client_init()
+ */
void radius_client_deinit(struct radius_client_data *radius)
{
if (!radius)
@@ -1096,7 +1313,18 @@ void radius_client_deinit(struct radius_client_data *radius)
}
-void radius_client_flush_auth(struct radius_client_data *radius, u8 *addr)
+/**
+ * radius_client_flush_auth - Flush pending RADIUS messages for an address
+ * @radius: RADIUS client context from radius_client_init()
+ * @addr: MAC address of the related device
+ *
+ * This function can be used to remove pending RADIUS authentication messages
+ * that are related to a specific device. The addr parameter is matched with
+ * the one used in radius_client_send() call that was used to transmit the
+ * authentication request.
+ */
+void radius_client_flush_auth(struct radius_client_data *radius,
+ const u8 *addr)
{
struct radius_msg_list *entry, *prev, *tmp;
@@ -1224,6 +1452,13 @@ static int radius_client_dump_acct_server(char *buf, size_t buflen,
}
+/**
+ * radius_client_get_mib - Get RADIUS client MIB information
+ * @radius: RADIUS client context from radius_client_init()
+ * @buf: Buffer for returning MIB data in text format
+ * @buflen: Maximum buf length in octets
+ * Returns: Number of octets written into the buffer
+ */
int radius_client_get_mib(struct radius_client_data *radius, char *buf,
size_t buflen)
{
@@ -1254,48 +1489,3 @@ int radius_client_get_mib(struct radius_client_data *radius, char *buf,
return count;
}
-
-
-static int radius_servers_diff(struct hostapd_radius_server *nserv,
- struct hostapd_radius_server *oserv,
- int num)
-{
- int i;
-
- for (i = 0; i < num; i++) {
- if (hostapd_ip_diff(&nserv[i].addr, &oserv[i].addr) ||
- nserv[i].port != oserv[i].port ||
- nserv[i].shared_secret_len != oserv[i].shared_secret_len ||
- os_memcmp(nserv[i].shared_secret, oserv[i].shared_secret,
- nserv[i].shared_secret_len) != 0)
- return 1;
- }
-
- return 0;
-}
-
-
-struct radius_client_data *
-radius_client_reconfig(struct radius_client_data *old, void *ctx,
- struct hostapd_radius_servers *oldconf,
- struct hostapd_radius_servers *newconf)
-{
- radius_client_flush(old, 0);
-
- if (newconf->retry_primary_interval !=
- oldconf->retry_primary_interval ||
- newconf->num_auth_servers != oldconf->num_auth_servers ||
- newconf->num_acct_servers != oldconf->num_acct_servers ||
- radius_servers_diff(newconf->auth_servers, oldconf->auth_servers,
- newconf->num_auth_servers) ||
- radius_servers_diff(newconf->acct_servers, oldconf->acct_servers,
- newconf->num_acct_servers)) {
- hostapd_logger(ctx, NULL, HOSTAPD_MODULE_RADIUS,
- HOSTAPD_LEVEL_DEBUG,
- "Reconfiguring RADIUS client");
- radius_client_deinit(old);
- return radius_client_init(ctx, newconf);
- }
-
- return old;
-}
diff --git a/contrib/wpa/src/radius/radius_client.h b/contrib/wpa/src/radius/radius_client.h
index 4fe9ba9..644ea23 100644
--- a/contrib/wpa/src/radius/radius_client.h
+++ b/contrib/wpa/src/radius/radius_client.h
@@ -1,6 +1,6 @@
/*
- * hostapd / RADIUS client
- * Copyright (c) 2002-2005, Jouni Malinen <j@w1.fi>
+ * RADIUS client
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -19,63 +19,222 @@
struct radius_msg;
+/**
+ * struct hostapd_radius_server - RADIUS server information for RADIUS client
+ *
+ * This structure contains information about a RADIUS server. The values are
+ * mainly for MIB information. The MIB variable prefix (radiusAuth or
+ * radiusAcc) depends on whether this is an authentication or accounting
+ * server.
+ *
+ * radiusAuthClientPendingRequests (or radiusAccClientPendingRequests) is the
+ * number struct radius_client_data::msgs for matching msg_type.
+ */
struct hostapd_radius_server {
- /* MIB prefix for shared variables:
- * @ = radiusAuth or radiusAcc depending on the type of the server */
- struct hostapd_ip_addr addr; /* @ServerAddress */
- int port; /* @ClientServerPortNumber */
+ /**
+ * addr - radiusAuthServerAddress or radiusAccServerAddress
+ */
+ struct hostapd_ip_addr addr;
+
+ /**
+ * port - radiusAuthClientServerPortNumber or radiusAccClientServerPortNumber
+ */
+ int port;
+
+ /**
+ * shared_secret - Shared secret for authenticating RADIUS messages
+ */
u8 *shared_secret;
+
+ /**
+ * shared_secret_len - Length of shared_secret in octets
+ */
size_t shared_secret_len;
/* Dynamic (not from configuration file) MIB data */
- int index; /* @ServerIndex */
- int round_trip_time; /* @ClientRoundTripTime; in hundredths of a
- * second */
- u32 requests; /* @Client{Access,}Requests */
- u32 retransmissions; /* @Client{Access,}Retransmissions */
- u32 access_accepts; /* radiusAuthClientAccessAccepts */
- u32 access_rejects; /* radiusAuthClientAccessRejects */
- u32 access_challenges; /* radiusAuthClientAccessChallenges */
- u32 responses; /* radiusAccClientResponses */
- u32 malformed_responses; /* @ClientMalformed{Access,}Responses */
- u32 bad_authenticators; /* @ClientBadAuthenticators */
- u32 timeouts; /* @ClientTimeouts */
- u32 unknown_types; /* @ClientUnknownTypes */
- u32 packets_dropped; /* @ClientPacketsDropped */
- /* @ClientPendingRequests: length of hapd->radius->msgs for matching
- * msg_type */
+
+ /**
+ * index - radiusAuthServerIndex or radiusAccServerIndex
+ */
+ int index;
+
+ /**
+ * round_trip_time - radiusAuthClientRoundTripTime or radiusAccClientRoundTripTime
+ * Round-trip time in hundredths of a second.
+ */
+ int round_trip_time;
+
+ /**
+ * requests - radiusAuthClientAccessRequests or radiusAccClientRequests
+ */
+ u32 requests;
+
+ /**
+ * retransmissions - radiusAuthClientAccessRetransmissions or radiusAccClientRetransmissions
+ */
+ u32 retransmissions;
+
+ /**
+ * access_accepts - radiusAuthClientAccessAccepts
+ */
+ u32 access_accepts;
+
+ /**
+ * access_rejects - radiusAuthClientAccessRejects
+ */
+ u32 access_rejects;
+
+ /**
+ * access_challenges - radiusAuthClientAccessChallenges
+ */
+ u32 access_challenges;
+
+ /**
+ * responses - radiusAccClientResponses
+ */
+ u32 responses;
+
+ /**
+ * malformed_responses - radiusAuthClientMalformedAccessResponses or radiusAccClientMalformedResponses
+ */
+ u32 malformed_responses;
+
+ /**
+ * bad_authenticators - radiusAuthClientBadAuthenticators or radiusAccClientBadAuthenticators
+ */
+ u32 bad_authenticators;
+
+ /**
+ * timeouts - radiusAuthClientTimeouts or radiusAccClientTimeouts
+ */
+ u32 timeouts;
+
+ /**
+ * unknown_types - radiusAuthClientUnknownTypes or radiusAccClientUnknownTypes
+ */
+ u32 unknown_types;
+
+ /**
+ * packets_dropped - radiusAuthClientPacketsDropped or radiusAccClientPacketsDropped
+ */
+ u32 packets_dropped;
};
+/**
+ * struct hostapd_radius_servers - RADIUS servers for RADIUS client
+ */
struct hostapd_radius_servers {
- /* RADIUS Authentication and Accounting servers in priority order */
- struct hostapd_radius_server *auth_servers, *auth_server;
+ /**
+ * auth_servers - RADIUS Authentication servers in priority order
+ */
+ struct hostapd_radius_server *auth_servers;
+
+ /**
+ * num_auth_servers - Number of auth_servers entries
+ */
int num_auth_servers;
- struct hostapd_radius_server *acct_servers, *acct_server;
+
+ /**
+ * auth_server - The current Authentication server
+ */
+ struct hostapd_radius_server *auth_server;
+
+ /**
+ * acct_servers - RADIUS Accounting servers in priority order
+ */
+ struct hostapd_radius_server *acct_servers;
+
+ /**
+ * num_acct_servers - Number of acct_servers entries
+ */
int num_acct_servers;
+ /**
+ * acct_server - The current Accounting server
+ */
+ struct hostapd_radius_server *acct_server;
+
+ /**
+ * retry_primary_interval - Retry interval for trying primary server
+ *
+ * This specifies a retry interval in sexconds for trying to return to
+ * the primary RADIUS server. RADIUS client code will automatically try
+ * to use the next server when the current server is not replying to
+ * requests. If this interval is set (non-zero), the primary server
+ * will be retried after the specified number of seconds has passed
+ * even if the current used secondary server is still working.
+ */
int retry_primary_interval;
- int acct_interim_interval;
+ /**
+ * msg_dumps - Whether RADIUS message details are shown in stdout
+ */
int msg_dumps;
+ /**
+ * client_addr - Client (local) address to use if force_client_addr
+ */
struct hostapd_ip_addr client_addr;
+
+ /**
+ * force_client_addr - Whether to force client (local) address
+ */
int force_client_addr;
};
+/**
+ * RadiusType - RADIUS server type for RADIUS client
+ */
typedef enum {
+ /**
+ * RADIUS authentication
+ */
RADIUS_AUTH,
+
+ /**
+ * RADIUS_ACCT - RADIUS accounting
+ */
RADIUS_ACCT,
- RADIUS_ACCT_INTERIM /* used only with radius_client_send(); just like
- * RADIUS_ACCT, but removes any pending interim
- * RADIUS Accounting packages for the same STA
- * before sending the new interim update */
+
+ /**
+ * RADIUS_ACCT_INTERIM - RADIUS interim accounting message
+ *
+ * Used only with radius_client_send(). This behaves just like
+ * RADIUS_ACCT, but removes any pending interim RADIUS Accounting
+ * messages for the same STA before sending the new interim update.
+ */
+ RADIUS_ACCT_INTERIM
} RadiusType;
+/**
+ * RadiusRxResult - RADIUS client RX handler result
+ */
typedef enum {
+ /**
+ * RADIUS_RX_PROCESSED - Message processed
+ *
+ * This stops handler calls and frees the message.
+ */
RADIUS_RX_PROCESSED,
+
+ /**
+ * RADIUS_RX_QUEUED - Message has been queued
+ *
+ * This stops handler calls, but does not free the message; the handler
+ * that returned this is responsible for eventually freeing the
+ * message.
+ */
RADIUS_RX_QUEUED,
+
+ /**
+ * RADIUS_RX_UNKNOWN - Message is not for this handler
+ */
RADIUS_RX_UNKNOWN,
+
+ /**
+ * RADIUS_RX_INVALID_AUTHENTICATOR - Message has invalid Authenticator
+ */
RADIUS_RX_INVALID_AUTHENTICATOR
} RadiusRxResult;
@@ -92,17 +251,13 @@ int radius_client_send(struct radius_client_data *radius,
struct radius_msg *msg,
RadiusType msg_type, const u8 *addr);
u8 radius_client_get_id(struct radius_client_data *radius);
-
void radius_client_flush(struct radius_client_data *radius, int only_auth);
struct radius_client_data *
radius_client_init(void *ctx, struct hostapd_radius_servers *conf);
void radius_client_deinit(struct radius_client_data *radius);
-void radius_client_flush_auth(struct radius_client_data *radius, u8 *addr);
+void radius_client_flush_auth(struct radius_client_data *radius,
+ const u8 *addr);
int radius_client_get_mib(struct radius_client_data *radius, char *buf,
size_t buflen);
-struct radius_client_data *
-radius_client_reconfig(struct radius_client_data *old, void *ctx,
- struct hostapd_radius_servers *oldconf,
- struct hostapd_radius_servers *newconf);
#endif /* RADIUS_CLIENT_H */
diff --git a/contrib/wpa/src/radius/radius_server.c b/contrib/wpa/src/radius/radius_server.c
index 4f399bc..f8780a6 100644
--- a/contrib/wpa/src/radius/radius_server.c
+++ b/contrib/wpa/src/radius/radius_server.c
@@ -1,6 +1,6 @@
/*
- * hostapd / RADIUS authentication server
- * Copyright (c) 2005-2008, Jouni Malinen <j@w1.fi>
+ * RADIUS authentication server
+ * Copyright (c) 2005-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -18,12 +18,22 @@
#include "common.h"
#include "radius.h"
#include "eloop.h"
-#include "defs.h"
#include "eap_server/eap.h"
#include "radius_server.h"
+/**
+ * RADIUS_SESSION_TIMEOUT - Session timeout in seconds
+ */
#define RADIUS_SESSION_TIMEOUT 60
+
+/**
+ * RADIUS_MAX_SESSION - Maximum number of active sessions
+ */
#define RADIUS_MAX_SESSION 100
+
+/**
+ * RADIUS_MAX_MSG_LEN - Maximum message length for incoming RADIUS messages
+ */
#define RADIUS_MAX_MSG_LEN 3000
static struct eapol_callbacks radius_server_eapol_cb;
@@ -31,6 +41,9 @@ static struct eapol_callbacks radius_server_eapol_cb;
struct radius_client;
struct radius_server_data;
+/**
+ * struct radius_server_counters - RADIUS server statistics counters
+ */
struct radius_server_counters {
u32 access_requests;
u32 invalid_requests;
@@ -44,6 +57,9 @@ struct radius_server_counters {
u32 unknown_types;
};
+/**
+ * struct radius_session - Internal RADIUS server data for a session
+ */
struct radius_session {
struct radius_session *next;
struct radius_client *client;
@@ -62,6 +78,9 @@ struct radius_session {
u8 last_authenticator[16];
};
+/**
+ * struct radius_client - Internal RADIUS server data for a client
+ */
struct radius_client {
struct radius_client *next;
struct in_addr addr;
@@ -76,31 +95,196 @@ struct radius_client {
struct radius_server_counters counters;
};
+/**
+ * struct radius_server_data - Internal RADIUS server data
+ */
struct radius_server_data {
+ /**
+ * auth_sock - Socket for RADIUS authentication messages
+ */
int auth_sock;
+
+ /**
+ * clients - List of authorized RADIUS clients
+ */
struct radius_client *clients;
+
+ /**
+ * next_sess_id - Next session identifier
+ */
unsigned int next_sess_id;
+
+ /**
+ * conf_ctx - Context pointer for callbacks
+ *
+ * This is used as the ctx argument in get_eap_user() calls.
+ */
void *conf_ctx;
+
+ /**
+ * num_sess - Number of active sessions
+ */
int num_sess;
+
+ /**
+ * eap_sim_db_priv - EAP-SIM/AKA database context
+ *
+ * This is passed to the EAP-SIM/AKA server implementation as a
+ * callback context.
+ */
void *eap_sim_db_priv;
+
+ /**
+ * ssl_ctx - TLS context
+ *
+ * This is passed to the EAP server implementation as a callback
+ * context for TLS operations.
+ */
void *ssl_ctx;
+
+ /**
+ * pac_opaque_encr_key - PAC-Opaque encryption key for EAP-FAST
+ *
+ * This parameter is used to set a key for EAP-FAST to encrypt the
+ * PAC-Opaque data. It can be set to %NULL if EAP-FAST is not used. If
+ * set, must point to a 16-octet key.
+ */
u8 *pac_opaque_encr_key;
+
+ /**
+ * eap_fast_a_id - EAP-FAST authority identity (A-ID)
+ *
+ * If EAP-FAST is not used, this can be set to %NULL. In theory, this
+ * is a variable length field, but due to some existing implementations
+ * requiring A-ID to be 16 octets in length, it is recommended to use
+ * that length for the field to provide interoperability with deployed
+ * peer implementations.
+ */
u8 *eap_fast_a_id;
+
+ /**
+ * eap_fast_a_id_len - Length of eap_fast_a_id buffer in octets
+ */
size_t eap_fast_a_id_len;
+
+ /**
+ * eap_fast_a_id_info - EAP-FAST authority identifier information
+ *
+ * This A-ID-Info contains a user-friendly name for the A-ID. For
+ * example, this could be the enterprise and server names in
+ * human-readable format. This field is encoded as UTF-8. If EAP-FAST
+ * is not used, this can be set to %NULL.
+ */
char *eap_fast_a_id_info;
+
+ /**
+ * eap_fast_prov - EAP-FAST provisioning modes
+ *
+ * 0 = provisioning disabled, 1 = only anonymous provisioning allowed,
+ * 2 = only authenticated provisioning allowed, 3 = both provisioning
+ * modes allowed.
+ */
int eap_fast_prov;
+
+ /**
+ * pac_key_lifetime - EAP-FAST PAC-Key lifetime in seconds
+ *
+ * This is the hard limit on how long a provisioned PAC-Key can be
+ * used.
+ */
int pac_key_lifetime;
+
+ /**
+ * pac_key_refresh_time - EAP-FAST PAC-Key refresh time in seconds
+ *
+ * This is a soft limit on the PAC-Key. The server will automatically
+ * generate a new PAC-Key when this number of seconds (or fewer) of the
+ * lifetime remains.
+ */
int pac_key_refresh_time;
+
+ /**
+ * eap_sim_aka_result_ind - EAP-SIM/AKA protected success indication
+ *
+ * This controls whether the protected success/failure indication
+ * (AT_RESULT_IND) is used with EAP-SIM and EAP-AKA.
+ */
int eap_sim_aka_result_ind;
+
+ /**
+ * tnc - Trusted Network Connect (TNC)
+ *
+ * This controls whether TNC is enabled and will be required before the
+ * peer is allowed to connect. Note: This is only used with EAP-TTLS
+ * and EAP-FAST. If any other EAP method is enabled, the peer will be
+ * allowed to connect without TNC.
+ */
int tnc;
+
+ /**
+ * wps - Wi-Fi Protected Setup context
+ *
+ * If WPS is used with an external RADIUS server (which is quite
+ * unlikely configuration), this is used to provide a pointer to WPS
+ * context data. Normally, this can be set to %NULL.
+ */
struct wps_context *wps;
+
+ /**
+ * ipv6 - Whether to enable IPv6 support in the RADIUS server
+ */
int ipv6;
+
+ /**
+ * start_time - Timestamp of server start
+ */
struct os_time start_time;
+
+ /**
+ * counters - Statistics counters for server operations
+ *
+ * These counters are the sum over all clients.
+ */
struct radius_server_counters counters;
+
+ /**
+ * get_eap_user - Callback for fetching EAP user information
+ * @ctx: Context data from conf_ctx
+ * @identity: User identity
+ * @identity_len: identity buffer length in octets
+ * @phase2: Whether this is for Phase 2 identity
+ * @user: Data structure for filling in the user information
+ * Returns: 0 on success, -1 on failure
+ *
+ * This is used to fetch information from user database. The callback
+ * will fill in information about allowed EAP methods and the user
+ * password. The password field will be an allocated copy of the
+ * password data and RADIUS server will free it after use.
+ */
int (*get_eap_user)(void *ctx, const u8 *identity, size_t identity_len,
int phase2, struct eap_user *user);
+
+ /**
+ * eap_req_id_text - Optional data for EAP-Request/Identity
+ *
+ * This can be used to configure an optional, displayable message that
+ * will be sent in EAP-Request/Identity. This string can contain an
+ * ASCII-0 character (nul) to separate network infromation per RFC
+ * 4284. The actual string length is explicit provided in
+ * eap_req_id_text_len since nul character will not be used as a string
+ * terminator.
+ */
char *eap_req_id_text;
+
+ /**
+ * eap_req_id_text_len - Length of eap_req_id_text buffer in octets
+ */
size_t eap_req_id_text_len;
+
+ /*
+ * msg_ctx - Context data for wpa_msg() calls
+ */
+ void *msg_ctx;
};
@@ -182,15 +366,9 @@ static void radius_server_session_free(struct radius_server_data *data,
eloop_cancel_timeout(radius_server_session_timeout, data, sess);
eloop_cancel_timeout(radius_server_session_remove_timeout, data, sess);
eap_server_sm_deinit(sess->eap);
- if (sess->last_msg) {
- radius_msg_free(sess->last_msg);
- os_free(sess->last_msg);
- }
+ radius_msg_free(sess->last_msg);
os_free(sess->last_from_addr);
- if (sess->last_reply) {
- radius_msg_free(sess->last_reply);
- os_free(sess->last_reply);
- }
+ radius_msg_free(sess->last_reply);
os_free(sess);
data->num_sess--;
}
@@ -313,6 +491,7 @@ radius_server_get_new_session(struct radius_server_data *data,
os_memset(&eap_conf, 0, sizeof(eap_conf));
eap_conf.ssl_ctx = data->ssl_ctx;
+ eap_conf.msg_ctx = data->msg_ctx;
eap_conf.eap_sim_db_priv = data->eap_sim_db_priv;
eap_conf.backend_auth = TRUE;
eap_conf.eap_server = 1;
@@ -353,6 +532,7 @@ radius_server_encapsulate_eap(struct radius_server_data *data,
struct radius_msg *msg;
int code;
unsigned int sess_id;
+ struct radius_hdr *hdr = radius_msg_get_hdr(request);
if (sess->eap_if->eapFail) {
sess->eap_if->eapFail = FALSE;
@@ -365,7 +545,7 @@ radius_server_encapsulate_eap(struct radius_server_data *data,
code = RADIUS_CODE_ACCESS_CHALLENGE;
}
- msg = radius_msg_new(code, request->hdr->identifier);
+ msg = radius_msg_new(code, hdr->identifier);
if (msg == NULL) {
RADIUS_DEBUG("Failed to allocate reply message");
return NULL;
@@ -391,7 +571,7 @@ radius_server_encapsulate_eap(struct radius_server_data *data,
} else {
len = sess->eap_if->eapKeyDataLen / 2;
}
- if (!radius_msg_add_mppe_keys(msg, request->hdr->authenticator,
+ if (!radius_msg_add_mppe_keys(msg, hdr->authenticator,
(u8 *) client->shared_secret,
client->shared_secret_len,
sess->eap_if->eapKeyData + len,
@@ -404,13 +584,12 @@ radius_server_encapsulate_eap(struct radius_server_data *data,
if (radius_msg_copy_attr(msg, request, RADIUS_ATTR_PROXY_STATE) < 0) {
RADIUS_DEBUG("Failed to copy Proxy-State attribute(s)");
radius_msg_free(msg);
- os_free(msg);
return NULL;
}
if (radius_msg_finish_srv(msg, (u8 *) client->shared_secret,
client->shared_secret_len,
- request->hdr->authenticator) < 0) {
+ hdr->authenticator) < 0) {
RADIUS_DEBUG("Failed to add Message-Authenticator attribute");
}
@@ -427,12 +606,13 @@ static int radius_server_reject(struct radius_server_data *data,
struct radius_msg *msg;
int ret = 0;
struct eap_hdr eapfail;
+ struct wpabuf *buf;
+ struct radius_hdr *hdr = radius_msg_get_hdr(request);
RADIUS_DEBUG("Reject invalid request from %s:%d",
from_addr, from_port);
- msg = radius_msg_new(RADIUS_CODE_ACCESS_REJECT,
- request->hdr->identifier);
+ msg = radius_msg_new(RADIUS_CODE_ACCESS_REJECT, hdr->identifier);
if (msg == NULL) {
return -1;
}
@@ -449,13 +629,13 @@ static int radius_server_reject(struct radius_server_data *data,
if (radius_msg_copy_attr(msg, request, RADIUS_ATTR_PROXY_STATE) < 0) {
RADIUS_DEBUG("Failed to copy Proxy-State attribute(s)");
radius_msg_free(msg);
- os_free(msg);
return -1;
}
if (radius_msg_finish_srv(msg, (u8 *) client->shared_secret,
client->shared_secret_len,
- request->hdr->authenticator) < 0) {
+ hdr->authenticator) <
+ 0) {
RADIUS_DEBUG("Failed to add Message-Authenticator attribute");
}
@@ -465,14 +645,14 @@ static int radius_server_reject(struct radius_server_data *data,
data->counters.access_rejects++;
client->counters.access_rejects++;
- if (sendto(data->auth_sock, msg->buf, msg->buf_used, 0,
+ buf = radius_msg_get_buf(msg);
+ if (sendto(data->auth_sock, wpabuf_head(buf), wpabuf_len(buf), 0,
(struct sockaddr *) from, sizeof(*from)) < 0) {
perror("sendto[RADIUS SRV]");
ret = -1;
}
radius_msg_free(msg);
- os_free(msg);
return ret;
}
@@ -526,16 +706,18 @@ static int radius_server_request(struct radius_server_data *data,
}
if (sess->last_from_port == from_port &&
- sess->last_identifier == msg->hdr->identifier &&
- os_memcmp(sess->last_authenticator, msg->hdr->authenticator, 16) ==
- 0) {
+ sess->last_identifier == radius_msg_get_hdr(msg)->identifier &&
+ os_memcmp(sess->last_authenticator,
+ radius_msg_get_hdr(msg)->authenticator, 16) == 0) {
RADIUS_DEBUG("Duplicate message from %s", from_addr);
data->counters.dup_access_requests++;
client->counters.dup_access_requests++;
if (sess->last_reply) {
- res = sendto(data->auth_sock, sess->last_reply->buf,
- sess->last_reply->buf_used, 0,
+ struct wpabuf *buf;
+ buf = radius_msg_get_buf(sess->last_reply);
+ res = sendto(data->auth_sock, wpabuf_head(buf),
+ wpabuf_len(buf), 0,
(struct sockaddr *) from, fromlen);
if (res < 0) {
perror("sendto[RADIUS SRV]");
@@ -583,10 +765,7 @@ static int radius_server_request(struct radius_server_data *data,
RADIUS_DEBUG("No EAP data from the state machine, but eapFail "
"set");
} else if (eap_sm_method_pending(sess->eap)) {
- if (sess->last_msg) {
- radius_msg_free(sess->last_msg);
- os_free(sess->last_msg);
- }
+ radius_msg_free(sess->last_msg);
sess->last_msg = msg;
sess->last_from_port = from_port;
os_free(sess->last_from_addr);
@@ -609,12 +788,15 @@ static int radius_server_request(struct radius_server_data *data,
reply = radius_server_encapsulate_eap(data, client, sess, msg);
if (reply) {
+ struct wpabuf *buf;
+ struct radius_hdr *hdr;
+
RADIUS_DEBUG("Reply to %s:%d", from_addr, from_port);
if (wpa_debug_level <= MSG_MSGDUMP) {
radius_msg_dump(reply);
}
- switch (reply->hdr->code) {
+ switch (radius_msg_get_hdr(reply)->code) {
case RADIUS_CODE_ACCESS_ACCEPT:
data->counters.access_accepts++;
client->counters.access_accepts++;
@@ -628,20 +810,19 @@ static int radius_server_request(struct radius_server_data *data,
client->counters.access_challenges++;
break;
}
- res = sendto(data->auth_sock, reply->buf, reply->buf_used, 0,
+ buf = radius_msg_get_buf(reply);
+ res = sendto(data->auth_sock, wpabuf_head(buf),
+ wpabuf_len(buf), 0,
(struct sockaddr *) from, fromlen);
if (res < 0) {
perror("sendto[RADIUS SRV]");
}
- if (sess->last_reply) {
- radius_msg_free(sess->last_reply);
- os_free(sess->last_reply);
- }
+ radius_msg_free(sess->last_reply);
sess->last_reply = reply;
sess->last_from_port = from_port;
- sess->last_identifier = msg->hdr->identifier;
- os_memcpy(sess->last_authenticator, msg->hdr->authenticator,
- 16);
+ hdr = radius_msg_get_hdr(msg);
+ sess->last_identifier = hdr->identifier;
+ os_memcpy(sess->last_authenticator, hdr->authenticator, 16);
} else {
data->counters.packets_dropped++;
client->counters.packets_dropped++;
@@ -740,8 +921,9 @@ static void radius_server_receive_auth(int sock, void *eloop_ctx,
radius_msg_dump(msg);
}
- if (msg->hdr->code != RADIUS_CODE_ACCESS_REQUEST) {
- RADIUS_DEBUG("Unexpected RADIUS code %d", msg->hdr->code);
+ if (radius_msg_get_hdr(msg)->code != RADIUS_CODE_ACCESS_REQUEST) {
+ RADIUS_DEBUG("Unexpected RADIUS code %d",
+ radius_msg_get_hdr(msg)->code);
data->counters.unknown_types++;
client->counters.unknown_types++;
goto fail;
@@ -764,10 +946,7 @@ static void radius_server_receive_auth(int sock, void *eloop_ctx,
return; /* msg was stored with the session */
fail:
- if (msg) {
- radius_msg_free(msg);
- os_free(msg);
- }
+ radius_msg_free(msg);
os_free(buf);
}
@@ -1026,6 +1205,15 @@ radius_server_read_clients(const char *client_file, int ipv6)
}
+/**
+ * radius_server_init - Initialize RADIUS server
+ * @conf: Configuration for the RADIUS server
+ * Returns: Pointer to private RADIUS server context or %NULL on failure
+ *
+ * This initializes a RADIUS server instance and returns a context pointer that
+ * will be used in other calls to the RADIUS server module. The server can be
+ * deinitialize by calling radius_server_deinit().
+ */
struct radius_server_data *
radius_server_init(struct radius_server_conf *conf)
{
@@ -1047,6 +1235,7 @@ radius_server_init(struct radius_server_conf *conf)
data->conf_ctx = conf->conf_ctx;
data->eap_sim_db_priv = conf->eap_sim_db_priv;
data->ssl_ctx = conf->ssl_ctx;
+ data->msg_ctx = conf->msg_ctx;
data->ipv6 = conf->ipv6;
if (conf->pac_opaque_encr_key) {
data->pac_opaque_encr_key = os_malloc(16);
@@ -1110,6 +1299,10 @@ radius_server_init(struct radius_server_conf *conf)
}
+/**
+ * radius_server_deinit - Deinitialize RADIUS server
+ * @data: RADIUS server context from radius_server_init()
+ */
void radius_server_deinit(struct radius_server_data *data)
{
if (data == NULL)
@@ -1130,6 +1323,13 @@ void radius_server_deinit(struct radius_server_data *data)
}
+/**
+ * radius_server_get_mib - Get RADIUS server MIB information
+ * @data: RADIUS server context from radius_server_init()
+ * @buf: Buffer for returning the MIB data in text format
+ * @buflen: buf length in octets
+ * Returns: Number of octets written into buf
+ */
int radius_server_get_mib(struct radius_server_data *data, char *buf,
size_t buflen)
{
@@ -1269,6 +1469,14 @@ static struct eapol_callbacks radius_server_eapol_cb =
};
+/**
+ * radius_server_eap_pending_cb - Pending EAP data notification
+ * @data: RADIUS server context from radius_server_init()
+ * @ctx: Pending EAP context pointer
+ *
+ * This function is used to notify EAP server module that a pending operation
+ * has been completed and processing of the EAP session can proceed.
+ */
void radius_server_eap_pending_cb(struct radius_server_data *data, void *ctx)
{
struct radius_client *cli;
@@ -1307,5 +1515,4 @@ void radius_server_eap_pending_cb(struct radius_server_data *data, void *ctx)
return; /* msg was stored with the session */
radius_msg_free(msg);
- os_free(msg);
}
diff --git a/contrib/wpa/src/radius/radius_server.h b/contrib/wpa/src/radius/radius_server.h
index d5fb6a1..f9c951d 100644
--- a/contrib/wpa/src/radius/radius_server.h
+++ b/contrib/wpa/src/radius/radius_server.h
@@ -1,6 +1,6 @@
/*
- * hostapd / RADIUS authentication server
- * Copyright (c) 2005-2007, Jouni Malinen <j@w1.fi>
+ * RADIUS authentication server
+ * Copyright (c) 2005-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -18,31 +18,184 @@
struct radius_server_data;
struct eap_user;
+/**
+ * struct radius_server_conf - RADIUS server configuration
+ */
struct radius_server_conf {
+ /**
+ * auth_port - UDP port to listen to as an authentication server
+ */
int auth_port;
+
+ /**
+ * client_file - RADIUS client configuration file
+ *
+ * This file contains the RADIUS clients and the shared secret to be
+ * used with them in a format where each client is on its own line. The
+ * first item on the line is the IPv4 or IPv6 address of the client
+ * with an optional address mask to allow full network to be specified
+ * (e.g., 192.168.1.2 or 192.168.1.0/24). This is followed by white
+ * space (space or tabulator) and the shared secret. Lines starting
+ * with '#' are skipped and can be used as comments.
+ */
char *client_file;
+
+ /**
+ * conf_ctx - Context pointer for callbacks
+ *
+ * This is used as the ctx argument in get_eap_user() calls.
+ */
void *conf_ctx;
+
+ /**
+ * eap_sim_db_priv - EAP-SIM/AKA database context
+ *
+ * This is passed to the EAP-SIM/AKA server implementation as a
+ * callback context.
+ */
void *eap_sim_db_priv;
+
+ /**
+ * ssl_ctx - TLS context
+ *
+ * This is passed to the EAP server implementation as a callback
+ * context for TLS operations.
+ */
void *ssl_ctx;
+
+ /**
+ * pac_opaque_encr_key - PAC-Opaque encryption key for EAP-FAST
+ *
+ * This parameter is used to set a key for EAP-FAST to encrypt the
+ * PAC-Opaque data. It can be set to %NULL if EAP-FAST is not used. If
+ * set, must point to a 16-octet key.
+ */
u8 *pac_opaque_encr_key;
+
+ /**
+ * eap_fast_a_id - EAP-FAST authority identity (A-ID)
+ *
+ * If EAP-FAST is not used, this can be set to %NULL. In theory, this
+ * is a variable length field, but due to some existing implementations
+ * requiring A-ID to be 16 octets in length, it is recommended to use
+ * that length for the field to provide interoperability with deployed
+ * peer implementations.
+ */
u8 *eap_fast_a_id;
+
+ /**
+ * eap_fast_a_id_len - Length of eap_fast_a_id buffer in octets
+ */
size_t eap_fast_a_id_len;
+
+ /**
+ * eap_fast_a_id_info - EAP-FAST authority identifier information
+ *
+ * This A-ID-Info contains a user-friendly name for the A-ID. For
+ * example, this could be the enterprise and server names in
+ * human-readable format. This field is encoded as UTF-8. If EAP-FAST
+ * is not used, this can be set to %NULL.
+ */
char *eap_fast_a_id_info;
+
+ /**
+ * eap_fast_prov - EAP-FAST provisioning modes
+ *
+ * 0 = provisioning disabled, 1 = only anonymous provisioning allowed,
+ * 2 = only authenticated provisioning allowed, 3 = both provisioning
+ * modes allowed.
+ */
int eap_fast_prov;
+
+ /**
+ * pac_key_lifetime - EAP-FAST PAC-Key lifetime in seconds
+ *
+ * This is the hard limit on how long a provisioned PAC-Key can be
+ * used.
+ */
int pac_key_lifetime;
+
+ /**
+ * pac_key_refresh_time - EAP-FAST PAC-Key refresh time in seconds
+ *
+ * This is a soft limit on the PAC-Key. The server will automatically
+ * generate a new PAC-Key when this number of seconds (or fewer) of the
+ * lifetime remains.
+ */
int pac_key_refresh_time;
+
+ /**
+ * eap_sim_aka_result_ind - EAP-SIM/AKA protected success indication
+ *
+ * This controls whether the protected success/failure indication
+ * (AT_RESULT_IND) is used with EAP-SIM and EAP-AKA.
+ */
int eap_sim_aka_result_ind;
+
+ /**
+ * tnc - Trusted Network Connect (TNC)
+ *
+ * This controls whether TNC is enabled and will be required before the
+ * peer is allowed to connect. Note: This is only used with EAP-TTLS
+ * and EAP-FAST. If any other EAP method is enabled, the peer will be
+ * allowed to connect without TNC.
+ */
int tnc;
+
+ /**
+ * wps - Wi-Fi Protected Setup context
+ *
+ * If WPS is used with an external RADIUS server (which is quite
+ * unlikely configuration), this is used to provide a pointer to WPS
+ * context data. Normally, this can be set to %NULL.
+ */
struct wps_context *wps;
+
+ /**
+ * ipv6 - Whether to enable IPv6 support in the RADIUS server
+ */
int ipv6;
+
+ /**
+ * get_eap_user - Callback for fetching EAP user information
+ * @ctx: Context data from conf_ctx
+ * @identity: User identity
+ * @identity_len: identity buffer length in octets
+ * @phase2: Whether this is for Phase 2 identity
+ * @user: Data structure for filling in the user information
+ * Returns: 0 on success, -1 on failure
+ *
+ * This is used to fetch information from user database. The callback
+ * will fill in information about allowed EAP methods and the user
+ * password. The password field will be an allocated copy of the
+ * password data and RADIUS server will free it after use.
+ */
int (*get_eap_user)(void *ctx, const u8 *identity, size_t identity_len,
int phase2, struct eap_user *user);
+
+ /**
+ * eap_req_id_text - Optional data for EAP-Request/Identity
+ *
+ * This can be used to configure an optional, displayable message that
+ * will be sent in EAP-Request/Identity. This string can contain an
+ * ASCII-0 character (nul) to separate network infromation per RFC
+ * 4284. The actual string length is explicit provided in
+ * eap_req_id_text_len since nul character will not be used as a string
+ * terminator.
+ */
const char *eap_req_id_text;
+
+ /**
+ * eap_req_id_text_len - Length of eap_req_id_text buffer in octets
+ */
size_t eap_req_id_text_len;
-};
+ /*
+ * msg_ctx - Context data for wpa_msg() calls
+ */
+ void *msg_ctx;
+};
-#ifdef RADIUS_SERVER
struct radius_server_data *
radius_server_init(struct radius_server_conf *conf);
@@ -54,29 +207,4 @@ int radius_server_get_mib(struct radius_server_data *data, char *buf,
void radius_server_eap_pending_cb(struct radius_server_data *data, void *ctx);
-#else /* RADIUS_SERVER */
-
-static inline struct radius_server_data *
-radius_server_init(struct radius_server_conf *conf)
-{
- return NULL;
-}
-
-static inline void radius_server_deinit(struct radius_server_data *data)
-{
-}
-
-static inline int radius_server_get_mib(struct radius_server_data *data,
- char *buf, size_t buflen)
-{
- return 0;
-}
-
-static inline void
-radius_server_eap_pending_cb(struct radius_server_data *data, void *ctx)
-{
-}
-
-#endif /* RADIUS_SERVER */
-
#endif /* RADIUS_SERVER_H */
diff --git a/contrib/wpa/src/rsn_supp/Makefile b/contrib/wpa/src/rsn_supp/Makefile
index cffba62..9c41962 100644
--- a/contrib/wpa/src/rsn_supp/Makefile
+++ b/contrib/wpa/src/rsn_supp/Makefile
@@ -2,7 +2,6 @@ all:
@echo Nothing to be made.
clean:
- for d in $(SUBDIRS); do make -C $$d clean; done
rm -f *~ *.o *.d
install:
diff --git a/contrib/wpa/src/rsn_supp/peerkey.c b/contrib/wpa/src/rsn_supp/peerkey.c
index 45c256a..9d60d4a 100644
--- a/contrib/wpa/src/rsn_supp/peerkey.c
+++ b/contrib/wpa/src/rsn_supp/peerkey.c
@@ -17,13 +17,13 @@
#ifdef CONFIG_PEERKEY
#include "common.h"
-#include "sha1.h"
-#include "sha256.h"
#include "eloop.h"
+#include "crypto/sha1.h"
+#include "crypto/sha256.h"
+#include "common/ieee802_11_defs.h"
#include "wpa.h"
#include "wpa_i.h"
#include "wpa_ie.h"
-#include "ieee802_11_defs.h"
#include "peerkey.h"
@@ -255,7 +255,7 @@ static int wpa_supplicant_process_smk_m2(
#endif /* CONFIG_IEEE80211W */
if (os_get_random(peerkey->pnonce, WPA_NONCE_LEN)) {
- wpa_msg(sm->ctx->ctx, MSG_WARNING,
+ wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
"WPA: Failed to get random data for PNonce");
wpa_supplicant_peerkey_free(sm, peerkey);
return -1;
@@ -371,7 +371,7 @@ static void wpa_supplicant_send_stk_1_of_4(struct wpa_sm *sm,
peerkey->smkid, PMKID_LEN);
if (os_get_random(peerkey->inonce, WPA_NONCE_LEN)) {
- wpa_msg(sm->ctx->ctx, MSG_WARNING,
+ wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
"RSN: Failed to get random data for INonce (STK)");
os_free(mbuf);
return;
@@ -634,9 +634,11 @@ static int wpa_supplicant_process_smk_error(
if (kde.mac_addr && kde.mac_addr_len >= ETH_ALEN)
os_memcpy(peer, kde.mac_addr, ETH_ALEN);
+ else
+ os_memset(peer, 0, ETH_ALEN);
os_memcpy(&error, kde.error, sizeof(error));
error_type = be_to_host16(error.error_type);
- wpa_msg(sm->ctx->ctx, MSG_INFO,
+ wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
"RSN: SMK Error KDE received: MUI %d error_type %d peer "
MACSTR,
be_to_host16(error.mui), error_type,
@@ -696,7 +698,7 @@ static void wpa_supplicant_process_stk_1_of_4(struct wpa_sm *sm,
}
if (os_get_random(peerkey->pnonce, WPA_NONCE_LEN)) {
- wpa_msg(sm->ctx->ctx, MSG_WARNING,
+ wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
"RSN: Failed to get random data for PNonce");
return;
}
@@ -1096,7 +1098,7 @@ int wpa_sm_stkstart(struct wpa_sm *sm, const u8 *peer)
inc_byte_array(sm->request_counter, WPA_REPLAY_COUNTER_LEN);
if (os_get_random(peerkey->inonce, WPA_NONCE_LEN)) {
- wpa_msg(sm->ctx->ctx, MSG_WARNING,
+ wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
"WPA: Failed to get random data for INonce");
os_free(rbuf);
wpa_supplicant_peerkey_free(sm, peerkey);
diff --git a/contrib/wpa/src/rsn_supp/pmksa_cache.c b/contrib/wpa/src/rsn_supp/pmksa_cache.c
index f8373de..cac8c83 100644
--- a/contrib/wpa/src/rsn_supp/pmksa_cache.c
+++ b/contrib/wpa/src/rsn_supp/pmksa_cache.c
@@ -15,12 +15,10 @@
#include "includes.h"
#include "common.h"
-#include "wpa.h"
#include "eloop.h"
-#include "sha1.h"
-#include "sha256.h"
-#include "wpa_i.h"
#include "eapol_supp/eapol_supp_sm.h"
+#include "wpa.h"
+#include "wpa_i.h"
#include "pmksa_cache.h"
#if defined(IEEE8021X_EAPOL) && !defined(CONFIG_NO_WPA2)
@@ -38,39 +36,6 @@ struct rsn_pmksa_cache {
};
-/**
- * rsn_pmkid - Calculate PMK identifier
- * @pmk: Pairwise master key
- * @pmk_len: Length of pmk in bytes
- * @aa: Authenticator address
- * @spa: Supplicant address
- * @use_sha256: Whether to use SHA256-based KDF
- *
- * IEEE Std 802.11i-2004 - 8.5.1.2 Pairwise key hierarchy
- * PMKID = HMAC-SHA1-128(PMK, "PMK Name" || AA || SPA)
- */
-static void rsn_pmkid(const u8 *pmk, size_t pmk_len, const u8 *aa,
- const u8 *spa, u8 *pmkid, int use_sha256)
-{
- char *title = "PMK Name";
- const u8 *addr[3];
- const size_t len[3] = { 8, ETH_ALEN, ETH_ALEN };
- unsigned char hash[SHA256_MAC_LEN];
-
- addr[0] = (u8 *) title;
- addr[1] = aa;
- addr[2] = spa;
-
-#ifdef CONFIG_IEEE80211W
- if (use_sha256)
- hmac_sha256_vector(pmk, pmk_len, 3, addr, len, hash);
- else
-#endif /* CONFIG_IEEE80211W */
- hmac_sha1_vector(pmk, pmk_len, 3, addr, len, hash);
- os_memcpy(pmkid, hash, PMKID_LEN);
-}
-
-
static void pmksa_cache_set_expiration(struct rsn_pmksa_cache *pmksa);
@@ -167,7 +132,7 @@ pmksa_cache_add(struct rsn_pmksa_cache *pmksa, const u8 *pmk, size_t pmk_len,
struct rsn_pmksa_cache_entry *entry, *pos, *prev;
struct os_time now;
- if (pmksa->sm->proto != WPA_PROTO_RSN || pmk_len > PMK_LEN)
+ if (pmk_len > PMK_LEN)
return NULL;
entry = os_zalloc(sizeof(*entry));
@@ -439,7 +404,7 @@ int pmksa_cache_set_current(struct wpa_sm *sm, const u8 *pmkid,
/**
* pmksa_cache_list - Dump text list of entries in PMKSA cache
- * @sm: Pointer to WPA state machine data from wpa_sm_init()
+ * @pmksa: Pointer to PMKSA cache data from pmksa_cache_init()
* @buf: Buffer for the list
* @len: Length of the buffer
* Returns: number of bytes written to buffer
@@ -447,7 +412,7 @@ int pmksa_cache_set_current(struct wpa_sm *sm, const u8 *pmkid,
* This function is used to generate a text format representation of the
* current PMKSA cache contents for the ctrl_iface PMKSA command.
*/
-int pmksa_cache_list(struct wpa_sm *sm, char *buf, size_t len)
+int pmksa_cache_list(struct rsn_pmksa_cache *pmksa, char *buf, size_t len)
{
int i, ret;
char *pos = buf;
@@ -462,7 +427,7 @@ int pmksa_cache_list(struct wpa_sm *sm, char *buf, size_t len)
return pos - buf;
pos += ret;
i = 0;
- entry = sm->pmksa->pmksa;
+ entry = pmksa->pmksa;
while (entry) {
i++;
ret = os_snprintf(pos, buf + len - pos, "%d " MACSTR " ",
diff --git a/contrib/wpa/src/rsn_supp/pmksa_cache.h b/contrib/wpa/src/rsn_supp/pmksa_cache.h
index a329b25..a1447e5 100644
--- a/contrib/wpa/src/rsn_supp/pmksa_cache.h
+++ b/contrib/wpa/src/rsn_supp/pmksa_cache.h
@@ -53,7 +53,7 @@ pmksa_cache_init(void (*free_cb)(struct rsn_pmksa_cache_entry *entry,
void pmksa_cache_deinit(struct rsn_pmksa_cache *pmksa);
struct rsn_pmksa_cache_entry * pmksa_cache_get(struct rsn_pmksa_cache *pmksa,
const u8 *aa, const u8 *pmkid);
-int pmksa_cache_list(struct wpa_sm *sm, char *buf, size_t len);
+int pmksa_cache_list(struct rsn_pmksa_cache *pmksa, char *buf, size_t len);
struct rsn_pmksa_cache_entry *
pmksa_cache_add(struct rsn_pmksa_cache *pmksa, const u8 *pmk, size_t pmk_len,
const u8 *aa, const u8 *spa, void *network_ctx, int akmp);
@@ -93,7 +93,8 @@ pmksa_cache_get_current(struct wpa_sm *sm)
return NULL;
}
-static inline int pmksa_cache_list(struct wpa_sm *sm, char *buf, size_t len)
+static inline int pmksa_cache_list(struct rsn_pmksa_cache *pmksa, char *buf,
+ size_t len)
{
return -1;
}
diff --git a/contrib/wpa/src/rsn_supp/preauth.c b/contrib/wpa/src/rsn_supp/preauth.c
index b00c004..6109f5e 100644
--- a/contrib/wpa/src/rsn_supp/preauth.c
+++ b/contrib/wpa/src/rsn_supp/preauth.c
@@ -1,6 +1,6 @@
/*
- * WPA Supplicant - RSN pre-authentication
- * Copyright (c) 2003-2008, Jouni Malinen <j@w1.fi>
+ * RSN pre-authentication (supplicant)
+ * Copyright (c) 2003-2010, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -16,14 +16,13 @@
#include "common.h"
#include "wpa.h"
-#include "drivers/driver.h"
#include "eloop.h"
#include "l2_packet/l2_packet.h"
#include "eapol_supp/eapol_supp_sm.h"
#include "preauth.h"
#include "pmksa_cache.h"
#include "wpa_i.h"
-#include "ieee802_11_defs.h"
+#include "common/ieee802_11_defs.h"
#if defined(IEEE8021X_EAPOL) && !defined(CONFIG_NO_WPA2)
@@ -32,7 +31,7 @@
struct rsn_pmksa_candidate {
- struct rsn_pmksa_candidate *next;
+ struct dl_list list;
u8 bssid[ETH_ALEN];
int priority;
};
@@ -44,17 +43,15 @@ struct rsn_pmksa_candidate {
*/
void pmksa_candidate_free(struct wpa_sm *sm)
{
- struct rsn_pmksa_candidate *entry, *prev;
+ struct rsn_pmksa_candidate *entry, *n;
if (sm == NULL)
return;
- entry = sm->pmksa_candidates;
- sm->pmksa_candidates = NULL;
- while (entry) {
- prev = entry;
- entry = entry->next;
- os_free(prev);
+ dl_list_for_each_safe(entry, n, &sm->pmksa_candidates,
+ struct rsn_pmksa_candidate, list) {
+ dl_list_del(&entry->list);
+ os_free(entry);
}
}
@@ -107,15 +104,15 @@ static void rsn_preauth_eapol_cb(struct eapol_sm *eapol, int success,
sm->network_ctx,
WPA_KEY_MGMT_IEEE8021X);
} else {
- wpa_msg(sm->ctx->ctx, MSG_INFO, "RSN: failed to get "
- "master session key from pre-auth EAPOL state "
- "machines");
+ wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
+ "RSN: failed to get master session key from "
+ "pre-auth EAPOL state machines");
success = 0;
}
}
- wpa_msg(sm->ctx->ctx, MSG_INFO, "RSN: pre-authentication with " MACSTR
- " %s", MAC2STR(sm->preauth_bssid),
+ wpa_msg(sm->ctx->msg_ctx, MSG_INFO, "RSN: pre-authentication with "
+ MACSTR " %s", MAC2STR(sm->preauth_bssid),
success ? "completed successfully" : "failed");
rsn_preauth_deinit(sm);
@@ -127,8 +124,8 @@ static void rsn_preauth_timeout(void *eloop_ctx, void *timeout_ctx)
{
struct wpa_sm *sm = eloop_ctx;
- wpa_msg(sm->ctx->ctx, MSG_INFO, "RSN: pre-authentication with " MACSTR
- " timed out", MAC2STR(sm->preauth_bssid));
+ wpa_msg(sm->ctx->msg_ctx, MSG_INFO, "RSN: pre-authentication with "
+ MACSTR " timed out", MAC2STR(sm->preauth_bssid));
rsn_preauth_deinit(sm);
rsn_preauth_candidate_process(sm);
}
@@ -183,8 +180,8 @@ int rsn_preauth_init(struct wpa_sm *sm, const u8 *dst,
if (sm->preauth_eapol)
return -1;
- wpa_msg(sm->ctx->ctx, MSG_DEBUG, "RSN: starting pre-authentication "
- "with " MACSTR, MAC2STR(dst));
+ wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG,
+ "RSN: starting pre-authentication with " MACSTR, MAC2STR(dst));
sm->l2_preauth = l2_packet_init(sm->ifname, sm->own_addr,
ETH_P_RSN_PREAUTH,
@@ -293,42 +290,42 @@ void rsn_preauth_deinit(struct wpa_sm *sm)
*/
void rsn_preauth_candidate_process(struct wpa_sm *sm)
{
- struct rsn_pmksa_candidate *candidate;
+ struct rsn_pmksa_candidate *candidate, *n;
- if (sm->pmksa_candidates == NULL)
+ if (dl_list_empty(&sm->pmksa_candidates))
return;
/* TODO: drop priority for old candidate entries */
- wpa_msg(sm->ctx->ctx, MSG_DEBUG, "RSN: processing PMKSA candidate "
+ wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG, "RSN: processing PMKSA candidate "
"list");
if (sm->preauth_eapol ||
sm->proto != WPA_PROTO_RSN ||
wpa_sm_get_state(sm) != WPA_COMPLETED ||
(sm->key_mgmt != WPA_KEY_MGMT_IEEE8021X &&
sm->key_mgmt != WPA_KEY_MGMT_IEEE8021X_SHA256)) {
- wpa_msg(sm->ctx->ctx, MSG_DEBUG, "RSN: not in suitable state "
- "for new pre-authentication");
+ wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG, "RSN: not in suitable "
+ "state for new pre-authentication");
return; /* invalid state for new pre-auth */
}
- while (sm->pmksa_candidates) {
+ dl_list_for_each_safe(candidate, n, &sm->pmksa_candidates,
+ struct rsn_pmksa_candidate, list) {
struct rsn_pmksa_cache_entry *p = NULL;
- candidate = sm->pmksa_candidates;
p = pmksa_cache_get(sm->pmksa, candidate->bssid, NULL);
if (os_memcmp(sm->bssid, candidate->bssid, ETH_ALEN) != 0 &&
(p == NULL || p->opportunistic)) {
- wpa_msg(sm->ctx->ctx, MSG_DEBUG, "RSN: PMKSA "
+ wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG, "RSN: PMKSA "
"candidate " MACSTR
" selected for pre-authentication",
MAC2STR(candidate->bssid));
- sm->pmksa_candidates = candidate->next;
+ dl_list_del(&candidate->list);
rsn_preauth_init(sm, candidate->bssid,
sm->eap_conf_ctx);
os_free(candidate);
return;
}
- wpa_msg(sm->ctx->ctx, MSG_DEBUG, "RSN: PMKSA candidate "
+ wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG, "RSN: PMKSA candidate "
MACSTR " does not need pre-authentication anymore",
MAC2STR(candidate->bssid));
/* Some drivers (e.g., NDIS) expect to get notified about the
@@ -337,10 +334,10 @@ void rsn_preauth_candidate_process(struct wpa_sm *sm)
wpa_sm_add_pmkid(sm, candidate->bssid, p->pmkid);
}
- sm->pmksa_candidates = candidate->next;
+ dl_list_del(&candidate->list);
os_free(candidate);
}
- wpa_msg(sm->ctx->ctx, MSG_DEBUG, "RSN: no more pending PMKSA "
+ wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG, "RSN: no more pending PMKSA "
"candidates");
}
@@ -359,7 +356,7 @@ void rsn_preauth_candidate_process(struct wpa_sm *sm)
void pmksa_candidate_add(struct wpa_sm *sm, const u8 *bssid,
int prio, int preauth)
{
- struct rsn_pmksa_candidate *cand, *prev, *pos;
+ struct rsn_pmksa_candidate *cand, *pos;
if (sm->network_ctx && sm->proactive_key_caching)
pmksa_cache_get_opportunistic(sm->pmksa, sm->network_ctx,
@@ -373,21 +370,17 @@ void pmksa_candidate_add(struct wpa_sm *sm, const u8 *bssid,
/* If BSSID already on candidate list, update the priority of the old
* entry. Do not override priority based on normal scan results. */
- prev = NULL;
- cand = sm->pmksa_candidates;
- while (cand) {
- if (os_memcmp(cand->bssid, bssid, ETH_ALEN) == 0) {
- if (prev)
- prev->next = cand->next;
- else
- sm->pmksa_candidates = cand->next;
+ cand = NULL;
+ dl_list_for_each(pos, &sm->pmksa_candidates,
+ struct rsn_pmksa_candidate, list) {
+ if (os_memcmp(pos->bssid, bssid, ETH_ALEN) == 0) {
+ cand = pos;
break;
}
- prev = cand;
- cand = cand->next;
}
if (cand) {
+ dl_list_del(&cand->list);
if (prio < PMKID_CANDIDATE_PRIO_SCAN)
cand->priority = prio;
} else {
@@ -400,21 +393,18 @@ void pmksa_candidate_add(struct wpa_sm *sm, const u8 *bssid,
/* Add candidate to the list; order by increasing priority value. i.e.,
* highest priority (smallest value) first. */
- prev = NULL;
- pos = sm->pmksa_candidates;
- while (pos) {
- if (cand->priority <= pos->priority)
+ dl_list_for_each(pos, &sm->pmksa_candidates,
+ struct rsn_pmksa_candidate, list) {
+ if (cand->priority <= pos->priority) {
+ dl_list_add(pos->list.prev, &cand->list);
+ cand = NULL;
break;
- prev = pos;
- pos = pos->next;
+ }
}
- cand->next = pos;
- if (prev)
- prev->next = cand;
- else
- sm->pmksa_candidates = cand;
+ if (cand)
+ dl_list_add_tail(&sm->pmksa_candidates, &cand->list);
- wpa_msg(sm->ctx->ctx, MSG_DEBUG, "RSN: added PMKSA cache "
+ wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG, "RSN: added PMKSA cache "
"candidate " MACSTR " prio %d", MAC2STR(bssid), prio);
rsn_preauth_candidate_process(sm);
}
@@ -423,23 +413,18 @@ void pmksa_candidate_add(struct wpa_sm *sm, const u8 *bssid,
/* TODO: schedule periodic scans if current AP supports preauth */
/**
- * rsn_preauth_scan_results - Process scan results to find PMKSA candidates
+ * rsn_preauth_scan_results - Start processing scan results for canditates
* @sm: Pointer to WPA state machine data from wpa_sm_init()
- * @results: Scan results
+ * Returns: 0 if ready to process results or -1 to skip processing
*
- * This functions goes through the scan results and adds all suitable APs
- * (Authenticators) into PMKSA candidate list.
+ * This functions is used to notify RSN code about start of new scan results
+ * processing. The actual scan results will be provided by calling
+ * rsn_preauth_scan_result() for each BSS if this function returned 0.
*/
-void rsn_preauth_scan_results(struct wpa_sm *sm,
- struct wpa_scan_results *results)
+int rsn_preauth_scan_results(struct wpa_sm *sm)
{
- struct wpa_scan_res *r;
- struct wpa_ie_data ie;
- int i;
- struct rsn_pmksa_cache_entry *pmksa;
-
if (sm->ssid_len == 0)
- return;
+ return -1;
/*
* TODO: is it ok to free all candidates? What about the entries
@@ -447,37 +432,41 @@ void rsn_preauth_scan_results(struct wpa_sm *sm,
*/
pmksa_candidate_free(sm);
- for (i = results->num - 1; i >= 0; i--) {
- const u8 *ssid, *rsn;
+ return 0;
+}
- r = results->res[i];
- ssid = wpa_scan_get_ie(r, WLAN_EID_SSID);
- if (ssid == NULL || ssid[1] != sm->ssid_len ||
- os_memcmp(ssid + 2, sm->ssid, ssid[1]) != 0)
- continue;
+/**
+ * rsn_preauth_scan_result - Processing scan result for PMKSA canditates
+ * @sm: Pointer to WPA state machine data from wpa_sm_init()
+ *
+ * Add all suitable APs (Authenticators) from scan results into PMKSA
+ * candidate list.
+ */
+void rsn_preauth_scan_result(struct wpa_sm *sm, const u8 *bssid,
+ const u8 *ssid, const u8 *rsn)
+{
+ struct wpa_ie_data ie;
+ struct rsn_pmksa_cache_entry *pmksa;
- if (os_memcmp(r->bssid, sm->bssid, ETH_ALEN) == 0)
- continue;
+ if (ssid[1] != sm->ssid_len ||
+ os_memcmp(ssid + 2, sm->ssid, sm->ssid_len) != 0)
+ return; /* Not for the current SSID */
- rsn = wpa_scan_get_ie(r, WLAN_EID_RSN);
- if (rsn == NULL || wpa_parse_wpa_ie(rsn, 2 + rsn[1], &ie))
- continue;
+ if (os_memcmp(bssid, sm->bssid, ETH_ALEN) == 0)
+ return; /* Ignore current AP */
- pmksa = pmksa_cache_get(sm->pmksa, r->bssid, NULL);
- if (pmksa &&
- (!pmksa->opportunistic ||
- !(ie.capabilities & WPA_CAPABILITY_PREAUTH)))
- continue;
+ if (wpa_parse_wpa_ie(rsn, 2 + rsn[1], &ie))
+ return;
- /*
- * Give less priority to candidates found from normal
- * scan results.
- */
- pmksa_candidate_add(sm, r->bssid,
- PMKID_CANDIDATE_PRIO_SCAN,
- ie.capabilities & WPA_CAPABILITY_PREAUTH);
- }
+ pmksa = pmksa_cache_get(sm->pmksa, bssid, NULL);
+ if (pmksa && (!pmksa->opportunistic ||
+ !(ie.capabilities & WPA_CAPABILITY_PREAUTH)))
+ return;
+
+ /* Give less priority to candidates found from normal scan results. */
+ pmksa_candidate_add(sm, bssid, PMKID_CANDIDATE_PRIO_SCAN,
+ ie.capabilities & WPA_CAPABILITY_PREAUTH);
}
diff --git a/contrib/wpa/src/rsn_supp/preauth.h b/contrib/wpa/src/rsn_supp/preauth.h
index b9ac57b..f8240ab 100644
--- a/contrib/wpa/src/rsn_supp/preauth.h
+++ b/contrib/wpa/src/rsn_supp/preauth.h
@@ -1,6 +1,6 @@
/*
* wpa_supplicant - WPA2/RSN pre-authentication functions
- * Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -23,8 +23,9 @@ void pmksa_candidate_free(struct wpa_sm *sm);
int rsn_preauth_init(struct wpa_sm *sm, const u8 *dst,
struct eap_peer_config *eap_conf);
void rsn_preauth_deinit(struct wpa_sm *sm);
-void rsn_preauth_scan_results(struct wpa_sm *sm,
- struct wpa_scan_results *results);
+int rsn_preauth_scan_results(struct wpa_sm *sm);
+void rsn_preauth_scan_result(struct wpa_sm *sm, const u8 *bssid,
+ const u8 *ssid, const u8 *rsn);
void pmksa_candidate_add(struct wpa_sm *sm, const u8 *bssid,
int prio, int preauth);
void rsn_preauth_candidate_process(struct wpa_sm *sm);
@@ -51,8 +52,14 @@ static inline int rsn_preauth_init(struct wpa_sm *sm, const u8 *dst,
static inline void rsn_preauth_deinit(struct wpa_sm *sm)
{
}
-static inline void rsn_preauth_scan_results(struct wpa_sm *sm,
- struct wpa_scan_results *results)
+
+static inline int rsn_preauth_scan_results(struct wpa_sm *sm)
+{
+ return -1;
+}
+
+static inline void rsn_preauth_scan_result(struct wpa_sm *sm, const u8 *bssid,
+ const u8 *ssid, const u8 *rsn)
{
}
diff --git a/contrib/wpa/src/rsn_supp/wpa.c b/contrib/wpa/src/rsn_supp/wpa.c
index e611fc5..9439f97 100644
--- a/contrib/wpa/src/rsn_supp/wpa.c
+++ b/contrib/wpa/src/rsn_supp/wpa.c
@@ -1,6 +1,6 @@
/*
* WPA Supplicant - WPA state machine and EAPOL-Key processing
- * Copyright (c) 2003-2008, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2003-2010, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -15,78 +15,17 @@
#include "includes.h"
#include "common.h"
-#include "rc4.h"
-#include "aes_wrap.h"
+#include "crypto/aes_wrap.h"
+#include "crypto/crypto.h"
+#include "common/ieee802_11_defs.h"
+#include "eapol_supp/eapol_supp_sm.h"
#include "wpa.h"
#include "eloop.h"
-#include "eapol_supp/eapol_supp_sm.h"
#include "preauth.h"
#include "pmksa_cache.h"
#include "wpa_i.h"
#include "wpa_ie.h"
#include "peerkey.h"
-#include "ieee802_11_defs.h"
-
-
-/**
- * wpa_cipher_txt - Convert cipher suite to a text string
- * @cipher: Cipher suite (WPA_CIPHER_* enum)
- * Returns: Pointer to a text string of the cipher suite name
- */
-static const char * wpa_cipher_txt(int cipher)
-{
- switch (cipher) {
- case WPA_CIPHER_NONE:
- return "NONE";
- case WPA_CIPHER_WEP40:
- return "WEP-40";
- case WPA_CIPHER_WEP104:
- return "WEP-104";
- case WPA_CIPHER_TKIP:
- return "TKIP";
- case WPA_CIPHER_CCMP:
- return "CCMP";
- default:
- return "UNKNOWN";
- }
-}
-
-
-/**
- * wpa_key_mgmt_txt - Convert key management suite to a text string
- * @key_mgmt: Key management suite (WPA_KEY_MGMT_* enum)
- * @proto: WPA/WPA2 version (WPA_PROTO_*)
- * Returns: Pointer to a text string of the key management suite name
- */
-static const char * wpa_key_mgmt_txt(int key_mgmt, int proto)
-{
- switch (key_mgmt) {
- case WPA_KEY_MGMT_IEEE8021X:
- return proto == WPA_PROTO_RSN ?
- "WPA2/IEEE 802.1X/EAP" : "WPA/IEEE 802.1X/EAP";
- case WPA_KEY_MGMT_PSK:
- return proto == WPA_PROTO_RSN ?
- "WPA2-PSK" : "WPA-PSK";
- case WPA_KEY_MGMT_NONE:
- return "NONE";
- case WPA_KEY_MGMT_IEEE8021X_NO_WPA:
- return "IEEE 802.1X (no WPA)";
-#ifdef CONFIG_IEEE80211R
- case WPA_KEY_MGMT_FT_IEEE8021X:
- return "FT-EAP";
- case WPA_KEY_MGMT_FT_PSK:
- return "FT-PSK";
-#endif /* CONFIG_IEEE80211R */
-#ifdef CONFIG_IEEE80211W
- case WPA_KEY_MGMT_IEEE8021X_SHA256:
- return "WPA2-EAP-SHA256";
- case WPA_KEY_MGMT_PSK_SHA256:
- return "WPA2-PSK-SHA256";
-#endif /* CONFIG_IEEE80211W */
- default:
- return "UNKNOWN";
- }
-}
/**
@@ -119,11 +58,16 @@ void wpa_eapol_key_send(struct wpa_sm *sm, const u8 *kck,
MAC2STR(dest));
}
}
- if (key_mic)
- wpa_eapol_key_mic(kck, ver, msg, msg_len, key_mic);
+ if (key_mic &&
+ wpa_eapol_key_mic(kck, ver, msg, msg_len, key_mic)) {
+ wpa_printf(MSG_ERROR, "WPA: Failed to generate EAPOL-Key "
+ "version %d MIC", ver);
+ goto out;
+ }
wpa_hexdump(MSG_MSGDUMP, "WPA: TX EAPOL-Key", msg, msg_len);
wpa_sm_ether_send(sm, dest, proto, msg, msg_len);
eapol_sm_notify_tx_eapol_key(sm->eapol);
+out:
os_free(msg);
}
@@ -246,9 +190,11 @@ static int wpa_supplicant_get_pmk(struct wpa_sm *sm,
wpa_hexdump_key(MSG_DEBUG, "WPA: PMK from EAPOL state "
"machines", sm->pmk, pmk_len);
sm->pmk_len = pmk_len;
- pmksa_cache_add(sm->pmksa, sm->pmk, pmk_len, src_addr,
- sm->own_addr, sm->network_ctx,
- sm->key_mgmt);
+ if (sm->proto == WPA_PROTO_RSN) {
+ pmksa_cache_add(sm->pmksa, sm->pmk, pmk_len,
+ src_addr, sm->own_addr,
+ sm->network_ctx, sm->key_mgmt);
+ }
if (!sm->cur_pmksa && pmkid &&
pmksa_cache_get(sm->pmksa, src_addr, pmkid)) {
wpa_printf(MSG_DEBUG, "RSN: the new PMK "
@@ -256,10 +202,10 @@ static int wpa_supplicant_get_pmk(struct wpa_sm *sm,
abort_cached = 0;
}
} else {
- wpa_msg(sm->ctx->ctx, MSG_WARNING,
+ wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
"WPA: Failed to get master session key from "
"EAPOL state machines");
- wpa_msg(sm->ctx->ctx, MSG_WARNING,
+ wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
"WPA: Key handshake aborted");
if (sm->cur_pmksa) {
wpa_printf(MSG_DEBUG, "RSN: Cancelled PMKSA "
@@ -285,6 +231,7 @@ static int wpa_supplicant_get_pmk(struct wpa_sm *sm,
wpa_sm_ether_send(sm, sm->bssid, ETH_P_EAPOL,
buf, buflen);
os_free(buf);
+ return -2;
}
return -1;
@@ -315,6 +262,7 @@ int wpa_supplicant_send_2_of_4(struct wpa_sm *sm, const unsigned char *dst,
size_t rlen;
struct wpa_eapol_key *reply;
u8 *rbuf;
+ u8 *rsn_ie_buf = NULL;
if (wpa_ie == NULL) {
wpa_printf(MSG_WARNING, "WPA: No wpa_ie set - cannot "
@@ -322,13 +270,46 @@ int wpa_supplicant_send_2_of_4(struct wpa_sm *sm, const unsigned char *dst,
return -1;
}
+#ifdef CONFIG_IEEE80211R
+ if (wpa_key_mgmt_ft(sm->key_mgmt)) {
+ int res;
+
+ /*
+ * Add PMKR1Name into RSN IE (PMKID-List) and add MDIE and
+ * FTIE from (Re)Association Response.
+ */
+ rsn_ie_buf = os_malloc(wpa_ie_len + 2 + 2 + PMKID_LEN +
+ sm->assoc_resp_ies_len);
+ if (rsn_ie_buf == NULL)
+ return -1;
+ os_memcpy(rsn_ie_buf, wpa_ie, wpa_ie_len);
+ res = wpa_insert_pmkid(rsn_ie_buf, wpa_ie_len,
+ sm->pmk_r1_name);
+ if (res < 0) {
+ os_free(rsn_ie_buf);
+ return -1;
+ }
+ wpa_ie_len += res;
+
+ if (sm->assoc_resp_ies) {
+ os_memcpy(rsn_ie_buf + wpa_ie_len, sm->assoc_resp_ies,
+ sm->assoc_resp_ies_len);
+ wpa_ie_len += sm->assoc_resp_ies_len;
+ }
+
+ wpa_ie = rsn_ie_buf;
+ }
+#endif /* CONFIG_IEEE80211R */
+
wpa_hexdump(MSG_DEBUG, "WPA: WPA IE for msg 2/4", wpa_ie, wpa_ie_len);
rbuf = wpa_sm_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_KEY,
NULL, sizeof(*reply) + wpa_ie_len,
&rlen, (void *) &reply);
- if (rbuf == NULL)
+ if (rbuf == NULL) {
+ os_free(rsn_ie_buf);
return -1;
+ }
reply->type = sm->proto == WPA_PROTO_RSN ?
EAPOL_KEY_TYPE_RSN : EAPOL_KEY_TYPE_WPA;
@@ -343,6 +324,7 @@ int wpa_supplicant_send_2_of_4(struct wpa_sm *sm, const unsigned char *dst,
WPA_PUT_BE16(reply->key_data_length, wpa_ie_len);
os_memcpy(reply + 1, wpa_ie, wpa_ie_len);
+ os_free(rsn_ie_buf);
os_memcpy(reply->key_nonce, nonce, WPA_NONCE_LEN);
@@ -380,6 +362,7 @@ static void wpa_supplicant_process_1_of_4(struct wpa_sm *sm,
struct wpa_eapol_ie_parse ie;
struct wpa_ptk *ptk;
u8 buf[8];
+ int res;
if (wpa_sm_get_network_ctx(sm) == NULL) {
wpa_printf(MSG_WARNING, "WPA: No SSID info found (msg 1 of "
@@ -407,12 +390,18 @@ static void wpa_supplicant_process_1_of_4(struct wpa_sm *sm,
}
#endif /* CONFIG_NO_WPA2 */
- if (wpa_supplicant_get_pmk(sm, src_addr, ie.pmkid))
+ res = wpa_supplicant_get_pmk(sm, src_addr, ie.pmkid);
+ if (res == -2) {
+ wpa_printf(MSG_DEBUG, "RSN: Do not reply to msg 1/4 - "
+ "requesting full EAP authentication");
+ return;
+ }
+ if (res)
goto failed;
if (sm->renew_snonce) {
if (os_get_random(sm->snonce, WPA_NONCE_LEN)) {
- wpa_msg(sm->ctx->ctx, MSG_WARNING,
+ wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
"WPA: Failed to get random data for SNonce");
goto failed;
}
@@ -454,7 +443,8 @@ static void wpa_sm_start_preauth(void *eloop_ctx, void *timeout_ctx)
static void wpa_supplicant_key_neg_complete(struct wpa_sm *sm,
const u8 *addr, int secure)
{
- wpa_msg(sm->ctx->ctx, MSG_INFO, "WPA: Key negotiation completed with "
+ wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
+ "WPA: Key negotiation completed with "
MACSTR " [PTK=%s GTK=%s]", MAC2STR(addr),
wpa_cipher_txt(sm->pairwise_cipher),
wpa_cipher_txt(sm->group_cipher));
@@ -487,7 +477,7 @@ static void wpa_supplicant_key_neg_complete(struct wpa_sm *sm,
#ifdef CONFIG_IEEE80211R
if (wpa_key_mgmt_ft(sm->key_mgmt)) {
/* Prepare for the next transition */
- wpa_ft_prepare_auth_request(sm);
+ wpa_ft_prepare_auth_request(sm, NULL);
}
#endif /* CONFIG_IEEE80211R */
}
@@ -505,7 +495,7 @@ static int wpa_supplicant_install_ptk(struct wpa_sm *sm,
const struct wpa_eapol_key *key)
{
int keylen, rsclen;
- wpa_alg alg;
+ enum wpa_alg alg;
const u8 *key_rsc;
u8 null_rsc[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
@@ -559,7 +549,8 @@ static int wpa_supplicant_install_ptk(struct wpa_sm *sm,
static int wpa_supplicant_check_group_cipher(int group_cipher,
int keylen, int maxkeylen,
- int *key_rsc_len, wpa_alg *alg)
+ int *key_rsc_len,
+ enum wpa_alg *alg)
{
int ret = 0;
@@ -613,7 +604,7 @@ static int wpa_supplicant_check_group_cipher(int group_cipher,
struct wpa_gtk_data {
- wpa_alg alg;
+ enum wpa_alg alg;
int tx, key_rsc_len, keyidx;
u8 gtk[32];
int gtk_len;
@@ -774,7 +765,7 @@ static void wpa_report_ie_mismatch(struct wpa_sm *sm,
const u8 *wpa_ie, size_t wpa_ie_len,
const u8 *rsn_ie, size_t rsn_ie_len)
{
- wpa_msg(sm->ctx->ctx, MSG_WARNING, "WPA: %s (src=" MACSTR ")",
+ wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, "WPA: %s (src=" MACSTR ")",
reason, MAC2STR(src_addr));
if (sm->ap_wpa_ie) {
@@ -807,6 +798,135 @@ static void wpa_report_ie_mismatch(struct wpa_sm *sm,
}
+#ifdef CONFIG_IEEE80211R
+
+static int ft_validate_mdie(struct wpa_sm *sm,
+ const unsigned char *src_addr,
+ struct wpa_eapol_ie_parse *ie,
+ const u8 *assoc_resp_mdie)
+{
+ struct rsn_mdie *mdie;
+
+ mdie = (struct rsn_mdie *) (ie->mdie + 2);
+ if (ie->mdie == NULL || ie->mdie_len < 2 + sizeof(*mdie) ||
+ os_memcmp(mdie->mobility_domain, sm->mobility_domain,
+ MOBILITY_DOMAIN_ID_LEN) != 0) {
+ wpa_printf(MSG_DEBUG, "FT: MDIE in msg 3/4 did not "
+ "match with the current mobility domain");
+ return -1;
+ }
+
+ if (assoc_resp_mdie &&
+ (assoc_resp_mdie[1] != ie->mdie[1] ||
+ os_memcmp(assoc_resp_mdie, ie->mdie, 2 + ie->mdie[1]) != 0)) {
+ wpa_printf(MSG_DEBUG, "FT: MDIE mismatch");
+ wpa_hexdump(MSG_DEBUG, "FT: MDIE in EAPOL-Key msg 3/4",
+ ie->mdie, 2 + ie->mdie[1]);
+ wpa_hexdump(MSG_DEBUG, "FT: MDIE in (Re)Association Response",
+ assoc_resp_mdie, 2 + assoc_resp_mdie[1]);
+ return -1;
+ }
+
+ return 0;
+}
+
+
+static int ft_validate_ftie(struct wpa_sm *sm,
+ const unsigned char *src_addr,
+ struct wpa_eapol_ie_parse *ie,
+ const u8 *assoc_resp_ftie)
+{
+ if (ie->ftie == NULL) {
+ wpa_printf(MSG_DEBUG, "FT: No FTIE in EAPOL-Key msg 3/4");
+ return -1;
+ }
+
+ if (assoc_resp_ftie == NULL)
+ return 0;
+
+ if (assoc_resp_ftie[1] != ie->ftie[1] ||
+ os_memcmp(assoc_resp_ftie, ie->ftie, 2 + ie->ftie[1]) != 0) {
+ wpa_printf(MSG_DEBUG, "FT: FTIE mismatch");
+ wpa_hexdump(MSG_DEBUG, "FT: FTIE in EAPOL-Key msg 3/4",
+ ie->ftie, 2 + ie->ftie[1]);
+ wpa_hexdump(MSG_DEBUG, "FT: FTIE in (Re)Association Response",
+ assoc_resp_ftie, 2 + assoc_resp_ftie[1]);
+ return -1;
+ }
+
+ return 0;
+}
+
+
+static int ft_validate_rsnie(struct wpa_sm *sm,
+ const unsigned char *src_addr,
+ struct wpa_eapol_ie_parse *ie)
+{
+ struct wpa_ie_data rsn;
+
+ if (!ie->rsn_ie)
+ return 0;
+
+ /*
+ * Verify that PMKR1Name from EAPOL-Key message 3/4
+ * matches with the value we derived.
+ */
+ if (wpa_parse_wpa_ie_rsn(ie->rsn_ie, ie->rsn_ie_len, &rsn) < 0 ||
+ rsn.num_pmkid != 1 || rsn.pmkid == NULL) {
+ wpa_printf(MSG_DEBUG, "FT: No PMKR1Name in "
+ "FT 4-way handshake message 3/4");
+ return -1;
+ }
+
+ if (os_memcmp(rsn.pmkid, sm->pmk_r1_name, WPA_PMK_NAME_LEN) != 0) {
+ wpa_printf(MSG_DEBUG, "FT: PMKR1Name mismatch in "
+ "FT 4-way handshake message 3/4");
+ wpa_hexdump(MSG_DEBUG, "FT: PMKR1Name from Authenticator",
+ rsn.pmkid, WPA_PMK_NAME_LEN);
+ wpa_hexdump(MSG_DEBUG, "FT: Derived PMKR1Name",
+ sm->pmk_r1_name, WPA_PMK_NAME_LEN);
+ return -1;
+ }
+
+ return 0;
+}
+
+
+static int wpa_supplicant_validate_ie_ft(struct wpa_sm *sm,
+ const unsigned char *src_addr,
+ struct wpa_eapol_ie_parse *ie)
+{
+ const u8 *pos, *end, *mdie = NULL, *ftie = NULL;
+
+ if (sm->assoc_resp_ies) {
+ pos = sm->assoc_resp_ies;
+ end = pos + sm->assoc_resp_ies_len;
+ while (pos + 2 < end) {
+ if (pos + 2 + pos[1] > end)
+ break;
+ switch (*pos) {
+ case WLAN_EID_MOBILITY_DOMAIN:
+ mdie = pos;
+ break;
+ case WLAN_EID_FAST_BSS_TRANSITION:
+ ftie = pos;
+ break;
+ }
+ pos += 2 + pos[1];
+ }
+ }
+
+ if (ft_validate_mdie(sm, src_addr, ie, mdie) < 0 ||
+ ft_validate_ftie(sm, src_addr, ie, ftie) < 0 ||
+ ft_validate_rsnie(sm, src_addr, ie) < 0)
+ return -1;
+
+ return 0;
+}
+
+#endif /* CONFIG_IEEE80211R */
+
+
static int wpa_supplicant_validate_ie(struct wpa_sm *sm,
const unsigned char *src_addr,
struct wpa_eapol_ie_parse *ie)
@@ -836,8 +956,9 @@ static int wpa_supplicant_validate_ie(struct wpa_sm *sm,
(ie->wpa_ie_len != sm->ap_wpa_ie_len ||
os_memcmp(ie->wpa_ie, sm->ap_wpa_ie, ie->wpa_ie_len) != 0)) ||
(ie->rsn_ie && sm->ap_rsn_ie &&
- (ie->rsn_ie_len != sm->ap_rsn_ie_len ||
- os_memcmp(ie->rsn_ie, sm->ap_rsn_ie, ie->rsn_ie_len) != 0))) {
+ wpa_compare_rsn_ie(wpa_key_mgmt_ft(sm->key_mgmt),
+ sm->ap_rsn_ie, sm->ap_rsn_ie_len,
+ ie->rsn_ie, ie->rsn_ie_len))) {
wpa_report_ie_mismatch(sm, "IE in 3/4 msg does not match "
"with IE in Beacon/ProbeResp",
src_addr, ie->wpa_ie, ie->wpa_ie_len,
@@ -857,19 +978,9 @@ static int wpa_supplicant_validate_ie(struct wpa_sm *sm,
}
#ifdef CONFIG_IEEE80211R
- if (wpa_key_mgmt_ft(sm->key_mgmt)) {
- struct rsn_mdie *mdie;
- /* TODO: verify that full MDIE matches with the one from scan
- * results, not only mobility domain */
- mdie = (struct rsn_mdie *) (ie->mdie + 2);
- if (ie->mdie == NULL || ie->mdie_len < 2 + sizeof(*mdie) ||
- os_memcmp(mdie->mobility_domain, sm->mobility_domain,
- MOBILITY_DOMAIN_ID_LEN) != 0) {
- wpa_printf(MSG_DEBUG, "FT: MDIE in msg 3/4 did not "
- "match with the current mobility domain");
- return -1;
- }
- }
+ if (wpa_key_mgmt_ft(sm->key_mgmt) &&
+ wpa_supplicant_validate_ie_ft(sm, src_addr, ie) < 0)
+ return -1;
#endif /* CONFIG_IEEE80211R */
return 0;
@@ -1128,7 +1239,10 @@ static int wpa_supplicant_process_1_of_2_wpa(struct wpa_sm *sm,
return -1;
}
os_memcpy(gd->gtk, key + 1, keydatalen);
- rc4_skip(ek, 32, 256, gd->gtk, keydatalen);
+ if (rc4_skip(ek, 32, 256, gd->gtk, keydatalen)) {
+ wpa_printf(MSG_ERROR, "WPA: RC4 failed");
+ return -1;
+ }
} else if (ver == WPA_KEY_INFO_TYPE_HMAC_SHA1_AES) {
if (keydatalen % 8) {
wpa_printf(MSG_WARNING, "WPA: Unsupported AES-WRAP "
@@ -1233,7 +1347,7 @@ static void wpa_supplicant_process_1_of_2(struct wpa_sm *sm,
goto failed;
if (rekey) {
- wpa_msg(sm->ctx->ctx, MSG_INFO, "WPA: Group rekeying "
+ wpa_msg(sm->ctx->msg_ctx, MSG_INFO, "WPA: Group rekeying "
"completed with " MACSTR " [GTK=%s]",
MAC2STR(sm->bssid), wpa_cipher_txt(sm->group_cipher));
wpa_sm_cancel_auth_timeout(sm);
@@ -1319,7 +1433,10 @@ static int wpa_supplicant_decrypt_key_data(struct wpa_sm *sm,
u8 ek[32];
os_memcpy(ek, key->key_iv, 16);
os_memcpy(ek + 16, sm->ptk.kek, 16);
- rc4_skip(ek, 32, 256, (u8 *) (key + 1), keydatalen);
+ if (rc4_skip(ek, 32, 256, (u8 *) (key + 1), keydatalen)) {
+ wpa_printf(MSG_ERROR, "WPA: RC4 failed");
+ return -1;
+ }
} else if (ver == WPA_KEY_INFO_TYPE_HMAC_SHA1_AES ||
ver == WPA_KEY_INFO_TYPE_AES_128_CMAC) {
u8 *buf;
@@ -1605,7 +1722,7 @@ int wpa_sm_rx_eapol(struct wpa_sm *sm, const u8 *src_addr,
extra_len = data_len - sizeof(*hdr) - sizeof(*key);
if (WPA_GET_BE16(key->key_data_length) > extra_len) {
- wpa_msg(sm->ctx->ctx, MSG_INFO, "WPA: Invalid EAPOL-Key "
+ wpa_msg(sm->ctx->msg_ctx, MSG_INFO, "WPA: Invalid EAPOL-Key "
"frame - key_data overflow (%d > %lu)",
WPA_GET_BE16(key->key_data_length),
(unsigned long) extra_len);
@@ -1855,6 +1972,7 @@ struct wpa_sm * wpa_sm_init(struct wpa_sm_ctx *ctx)
sm = os_zalloc(sizeof(*sm));
if (sm == NULL)
return NULL;
+ dl_list_init(&sm->pmksa_candidates);
sm->renew_snonce = 1;
sm->ctx = ctx;
@@ -1890,6 +2008,9 @@ void wpa_sm_deinit(struct wpa_sm *sm)
os_free(sm->ap_rsn_ie);
os_free(sm->ctx);
peerkey_deinit(sm);
+#ifdef CONFIG_IEEE80211R
+ os_free(sm->assoc_resp_ies);
+#endif /* CONFIG_IEEE80211R */
os_free(sm);
}
@@ -1919,10 +2040,15 @@ void wpa_sm_notify_assoc(struct wpa_sm *sm, const u8 *bssid)
#ifdef CONFIG_IEEE80211R
if (wpa_ft_is_completed(sm)) {
+ /*
+ * Clear portValid to kick EAPOL state machine to re-enter
+ * AUTHENTICATED state to get the EAPOL port Authorized.
+ */
+ eapol_sm_notify_portValid(sm->eapol, FALSE);
wpa_supplicant_key_neg_complete(sm, sm->bssid, 1);
/* Prepare for the next transition */
- wpa_ft_prepare_auth_request(sm);
+ wpa_ft_prepare_auth_request(sm, NULL);
clear_ptk = 0;
}
@@ -2164,6 +2290,9 @@ int wpa_sm_set_param(struct wpa_sm *sm, enum wpa_sm_conf_params param,
case WPA_PARAM_RSN_ENABLED:
sm->rsn_enabled = value;
break;
+ case WPA_PARAM_MFP:
+ sm->mfp = value;
+ break;
default:
break;
}
@@ -2406,3 +2535,32 @@ int wpa_sm_parse_own_wpa_ie(struct wpa_sm *sm, struct wpa_ie_data *data)
return -2;
return 0;
}
+
+
+int wpa_sm_pmksa_cache_list(struct wpa_sm *sm, char *buf, size_t len)
+{
+#ifndef CONFIG_NO_WPA2
+ return pmksa_cache_list(sm->pmksa, buf, len);
+#else /* CONFIG_NO_WPA2 */
+ return -1;
+#endif /* CONFIG_NO_WPA2 */
+}
+
+
+void wpa_sm_drop_sa(struct wpa_sm *sm)
+{
+ wpa_printf(MSG_DEBUG, "WPA: Clear old PMK and PTK");
+ sm->ptk_set = 0;
+ sm->tptk_set = 0;
+ os_memset(sm->pmk, 0, sizeof(sm->pmk));
+ os_memset(&sm->ptk, 0, sizeof(sm->ptk));
+ os_memset(&sm->tptk, 0, sizeof(sm->tptk));
+}
+
+
+int wpa_sm_has_ptk(struct wpa_sm *sm)
+{
+ if (sm == NULL)
+ return 0;
+ return sm->ptk_set;
+}
diff --git a/contrib/wpa/src/rsn_supp/wpa.h b/contrib/wpa/src/rsn_supp/wpa.h
index bdf7785..f1a5554 100644
--- a/contrib/wpa/src/rsn_supp/wpa.h
+++ b/contrib/wpa/src/rsn_supp/wpa.h
@@ -15,17 +15,9 @@
#ifndef WPA_H
#define WPA_H
-#include "defs.h"
-#include "eapol_common.h"
-#include "wpa_common.h"
-
-#ifndef ETH_P_EAPOL
-#define ETH_P_EAPOL 0x888e
-#endif
-
-#ifndef ETH_P_RSN_PREAUTH
-#define ETH_P_RSN_PREAUTH 0x88c7
-#endif
+#include "common/defs.h"
+#include "common/eapol_common.h"
+#include "common/wpa_common.h"
struct wpa_sm;
struct eapol_sm;
@@ -33,12 +25,13 @@ struct wpa_config_blob;
struct wpa_sm_ctx {
void *ctx; /* pointer to arbitrary upper level context */
+ void *msg_ctx; /* upper level context for wpa_msg() calls */
- void (*set_state)(void *ctx, wpa_states state);
- wpa_states (*get_state)(void *ctx);
+ void (*set_state)(void *ctx, enum wpa_states state);
+ enum wpa_states (*get_state)(void *ctx);
void (*deauthenticate)(void * ctx, int reason_code);
void (*disassociate)(void *ctx, int reason_code);
- int (*set_key)(void *ctx, wpa_alg alg,
+ int (*set_key)(void *ctx, enum wpa_alg alg,
const u8 *addr, int key_idx, int set_tx,
const u8 *seq, size_t seq_len,
const u8 *key, size_t key_len);
@@ -61,6 +54,7 @@ struct wpa_sm_ctx {
size_t ies_len);
int (*send_ft_action)(void *ctx, u8 action, const u8 *target_ap,
const u8 *ies, size_t ies_len);
+ int (*mark_authenticated)(void *ctx, const u8 *target_ap);
};
@@ -73,7 +67,8 @@ enum wpa_sm_conf_params {
WPA_PARAM_GROUP,
WPA_PARAM_KEY_MGMT,
WPA_PARAM_MGMT_GROUP,
- WPA_PARAM_RSN_ENABLED
+ WPA_PARAM_RSN_ENABLED,
+ WPA_PARAM_MFP
};
struct rsn_supp_config {
@@ -127,6 +122,9 @@ void wpa_sm_aborted_cached(struct wpa_sm *sm);
int wpa_sm_rx_eapol(struct wpa_sm *sm, const u8 *src_addr,
const u8 *buf, size_t len);
int wpa_sm_parse_own_wpa_ie(struct wpa_sm *sm, struct wpa_ie_data *data);
+int wpa_sm_pmksa_cache_list(struct wpa_sm *sm, char *buf, size_t len);
+void wpa_sm_drop_sa(struct wpa_sm *sm);
+int wpa_sm_has_ptk(struct wpa_sm *sm);
#else /* CONFIG_NO_WPA */
@@ -258,6 +256,21 @@ static inline int wpa_sm_parse_own_wpa_ie(struct wpa_sm *sm,
return -1;
}
+static inline int wpa_sm_pmksa_cache_list(struct wpa_sm *sm, char *buf,
+ size_t len)
+{
+ return -1;
+}
+
+static inline void wpa_sm_drop_sa(struct wpa_sm *sm)
+{
+}
+
+static inline int wpa_sm_has_ptk(struct wpa_sm *sm)
+{
+ return 0;
+}
+
#endif /* CONFIG_NO_WPA */
#ifdef CONFIG_PEERKEY
@@ -271,27 +284,27 @@ static inline int wpa_sm_stkstart(struct wpa_sm *sm, const u8 *peer)
#ifdef CONFIG_IEEE80211R
-int wpa_sm_set_ft_params(struct wpa_sm *sm, const u8 *mobility_domain,
- const u8 *r0kh_id, size_t r0kh_id_len,
- const u8 *r1kh_id);
-int wpa_ft_prepare_auth_request(struct wpa_sm *sm);
+int wpa_sm_set_ft_params(struct wpa_sm *sm, const u8 *ies, size_t ies_len);
+int wpa_ft_prepare_auth_request(struct wpa_sm *sm, const u8 *mdie);
int wpa_ft_process_response(struct wpa_sm *sm, const u8 *ies, size_t ies_len,
- int ft_action, const u8 *target_ap);
+ int ft_action, const u8 *target_ap,
+ const u8 *ric_ies, size_t ric_ies_len);
int wpa_ft_is_completed(struct wpa_sm *sm);
int wpa_ft_validate_reassoc_resp(struct wpa_sm *sm, const u8 *ies,
size_t ies_len, const u8 *src_addr);
-int wpa_ft_start_over_ds(struct wpa_sm *sm, const u8 *target_ap);
+int wpa_ft_start_over_ds(struct wpa_sm *sm, const u8 *target_ap,
+ const u8 *mdie);
#else /* CONFIG_IEEE80211R */
static inline int
-wpa_sm_set_ft_params(struct wpa_sm *sm, const u8 *mobility_domain,
- const u8 *r0kh_id, const u8 *r1kh_id)
+wpa_sm_set_ft_params(struct wpa_sm *sm, const u8 *ies, size_t ies_len)
{
return 0;
}
-static inline int wpa_ft_prepare_auth_request(struct wpa_sm *sm)
+static inline int wpa_ft_prepare_auth_request(struct wpa_sm *sm,
+ const u8 *mdie)
{
return 0;
}
diff --git a/contrib/wpa/src/rsn_supp/wpa_ft.c b/contrib/wpa/src/rsn_supp/wpa_ft.c
index 557b311..23063bc 100644
--- a/contrib/wpa/src/rsn_supp/wpa_ft.c
+++ b/contrib/wpa/src/rsn_supp/wpa_ft.c
@@ -15,19 +15,44 @@
#include "includes.h"
#include "common.h"
+#include "crypto/aes_wrap.h"
+#include "common/ieee802_11_defs.h"
+#include "common/ieee802_11_common.h"
#include "wpa.h"
#include "wpa_i.h"
#include "wpa_ie.h"
-#include "aes_wrap.h"
-#include "ieee802_11_defs.h"
#ifdef CONFIG_IEEE80211R
+struct wpa_ft_ies {
+ const u8 *mdie;
+ size_t mdie_len;
+ const u8 *ftie;
+ size_t ftie_len;
+ const u8 *r1kh_id;
+ const u8 *gtk;
+ size_t gtk_len;
+ const u8 *r0kh_id;
+ size_t r0kh_id_len;
+ const u8 *rsn;
+ size_t rsn_len;
+ const u8 *rsn_pmkid;
+ const u8 *tie;
+ size_t tie_len;
+ const u8 *igtk;
+ size_t igtk_len;
+ const u8 *ric;
+ size_t ric_len;
+};
+
+static int wpa_ft_parse_ies(const u8 *ies, size_t ies_len,
+ struct wpa_ft_ies *parse);
+
+
int wpa_derive_ptk_ft(struct wpa_sm *sm, const unsigned char *src_addr,
const struct wpa_eapol_key *key,
struct wpa_ptk *ptk, size_t ptk_len)
{
- u8 pmk_r1_name[WPA_PMK_NAME_LEN];
u8 ptk_name[WPA_PMK_NAME_LEN];
const u8 *anonce = key->key_nonce;
@@ -45,11 +70,12 @@ int wpa_derive_ptk_ft(struct wpa_sm *sm, const unsigned char *src_addr,
wpa_hexdump(MSG_DEBUG, "FT: PMKR0Name",
sm->pmk_r0_name, WPA_PMK_NAME_LEN);
wpa_derive_pmk_r1(sm->pmk_r0, sm->pmk_r0_name, sm->r1kh_id,
- sm->own_addr, sm->pmk_r1, pmk_r1_name);
+ sm->own_addr, sm->pmk_r1, sm->pmk_r1_name);
wpa_hexdump_key(MSG_DEBUG, "FT: PMK-R1", sm->pmk_r1, PMK_LEN);
- wpa_hexdump(MSG_DEBUG, "FT: PMKR1Name", pmk_r1_name, WPA_PMK_NAME_LEN);
+ wpa_hexdump(MSG_DEBUG, "FT: PMKR1Name", sm->pmk_r1_name,
+ WPA_PMK_NAME_LEN);
wpa_pmk_r1_to_ptk(sm->pmk_r1, sm->snonce, anonce, sm->own_addr,
- sm->bssid, pmk_r1_name,
+ sm->bssid, sm->pmk_r1_name,
(u8 *) ptk, ptk_len, ptk_name);
wpa_hexdump_key(MSG_DEBUG, "FT: PTK", (u8 *) ptk, ptk_len);
wpa_hexdump(MSG_DEBUG, "FT: PTKName", ptk_name, WPA_PMK_NAME_LEN);
@@ -61,31 +87,40 @@ int wpa_derive_ptk_ft(struct wpa_sm *sm, const unsigned char *src_addr,
/**
* wpa_sm_set_ft_params - Set FT (IEEE 802.11r) parameters
* @sm: Pointer to WPA state machine data from wpa_sm_init()
- * @mobility_domain: Mobility domain identifier (2 octets)
- * @r0kh_id: PMK-R0 key holder identity (1-48 octets)
- * @r0kh_id_len: R0KH-ID length (1-48)
- * @r1kh_id: PMK-R1 key holder identity (16 octets)
+ * @ies: Association Response IEs or %NULL to clear FT parameters
+ * @ies_len: Length of ies buffer in octets
* Returns: 0 on success, -1 on failure
*/
-int wpa_sm_set_ft_params(struct wpa_sm *sm, const u8 *mobility_domain,
- const u8 *r0kh_id, size_t r0kh_id_len,
- const u8 *r1kh_id)
+int wpa_sm_set_ft_params(struct wpa_sm *sm, const u8 *ies, size_t ies_len)
{
- if (sm && mobility_domain) {
+ struct wpa_ft_ies ft;
+
+ if (sm == NULL)
+ return 0;
+
+ if (wpa_ft_parse_ies(ies, ies_len, &ft) < 0)
+ return -1;
+
+ if (ft.mdie && ft.mdie_len < MOBILITY_DOMAIN_ID_LEN + 1)
+ return -1;
+
+ if (ft.mdie) {
wpa_hexdump(MSG_DEBUG, "FT: Mobility domain",
- mobility_domain, MOBILITY_DOMAIN_ID_LEN);
- os_memcpy(sm->mobility_domain, mobility_domain,
+ ft.mdie, MOBILITY_DOMAIN_ID_LEN);
+ os_memcpy(sm->mobility_domain, ft.mdie,
MOBILITY_DOMAIN_ID_LEN);
- } else if (sm)
+ sm->mdie_ft_capab = ft.mdie[MOBILITY_DOMAIN_ID_LEN];
+ wpa_printf(MSG_DEBUG, "FT: Capability and Policy: 0x%02x",
+ sm->mdie_ft_capab);
+ } else
os_memset(sm->mobility_domain, 0, MOBILITY_DOMAIN_ID_LEN);
- if (sm && r0kh_id) {
- if (r0kh_id_len > FT_R0KH_ID_MAX_LEN)
- return -1;
- wpa_hexdump(MSG_DEBUG, "FT: R0KH-ID", r0kh_id, r0kh_id_len);
- os_memcpy(sm->r0kh_id, r0kh_id, r0kh_id_len);
- sm->r0kh_id_len = r0kh_id_len;
- } else if (sm) {
+ if (ft.r0kh_id) {
+ wpa_hexdump(MSG_DEBUG, "FT: R0KH-ID",
+ ft.r0kh_id, ft.r0kh_id_len);
+ os_memcpy(sm->r0kh_id, ft.r0kh_id, ft.r0kh_id_len);
+ sm->r0kh_id_len = ft.r0kh_id_len;
+ } else {
/* FIX: When should R0KH-ID be cleared? We need to keep the
* old R0KH-ID in order to be able to use this during FT. */
/*
@@ -94,31 +129,55 @@ int wpa_sm_set_ft_params(struct wpa_sm *sm, const u8 *mobility_domain,
*/
}
- if (sm && r1kh_id) {
- wpa_hexdump(MSG_DEBUG, "FT: R1KH-ID", r1kh_id, FT_R1KH_ID_LEN);
- os_memcpy(sm->r1kh_id, r1kh_id, FT_R1KH_ID_LEN);
- } else if (sm)
+ if (ft.r1kh_id) {
+ wpa_hexdump(MSG_DEBUG, "FT: R1KH-ID",
+ ft.r1kh_id, FT_R1KH_ID_LEN);
+ os_memcpy(sm->r1kh_id, ft.r1kh_id, FT_R1KH_ID_LEN);
+ } else
os_memset(sm->r1kh_id, 0, FT_R1KH_ID_LEN);
+ os_free(sm->assoc_resp_ies);
+ sm->assoc_resp_ies = os_malloc(ft.mdie_len + 2 + ft.ftie_len + 2);
+ if (sm->assoc_resp_ies) {
+ u8 *pos = sm->assoc_resp_ies;
+ if (ft.mdie) {
+ os_memcpy(pos, ft.mdie - 2, ft.mdie_len + 2);
+ pos += ft.mdie_len + 2;
+ }
+ if (ft.ftie) {
+ os_memcpy(pos, ft.ftie - 2, ft.ftie_len + 2);
+ pos += ft.ftie_len + 2;
+ }
+ sm->assoc_resp_ies_len = pos - sm->assoc_resp_ies;
+ wpa_hexdump(MSG_DEBUG, "FT: Stored MDIE and FTIE from "
+ "(Re)Association Response",
+ sm->assoc_resp_ies, sm->assoc_resp_ies_len);
+ }
+
return 0;
}
/**
- * wpa_ft_gen_req_ies - Generate FT (IEEE 802.11r) IEs for Auth Request
+ * wpa_ft_gen_req_ies - Generate FT (IEEE 802.11r) IEs for Auth/ReAssoc Request
* @sm: Pointer to WPA state machine data from wpa_sm_init()
* @len: Buffer for returning the length of the IEs
* @anonce: ANonce or %NULL if not yet available
* @pmk_name: PMKR0Name or PMKR1Name to be added into the RSN IE PMKID List
* @kck: 128-bit KCK for MIC or %NULL if no MIC is used
* @target_ap: Target AP address
+ * @ric_ies: Optional IE(s), e.g., WMM TSPEC(s), for RIC-Request or %NULL
+ * @ric_ies_len: Length of ric_ies buffer in octets
+ * @ap_mdie: Mobility Domain IE from the target AP
* Returns: Pointer to buffer with IEs or %NULL on failure
*
* Caller is responsible for freeing the returned buffer with os_free();
*/
static u8 * wpa_ft_gen_req_ies(struct wpa_sm *sm, size_t *len,
const u8 *anonce, const u8 *pmk_name,
- const u8 *kck, const u8 *target_ap)
+ const u8 *kck, const u8 *target_ap,
+ const u8 *ric_ies, size_t ric_ies_len,
+ const u8 *ap_mdie)
{
size_t buf_len;
u8 *buf, *pos, *ftie_len, *ftie_pos;
@@ -130,13 +189,13 @@ static u8 * wpa_ft_gen_req_ies(struct wpa_sm *sm, size_t *len,
sm->ft_completed = 0;
buf_len = 2 + sizeof(struct rsn_mdie) + 2 + sizeof(struct rsn_ftie) +
- 2 + sm->r0kh_id_len + 100;
+ 2 + sm->r0kh_id_len + ric_ies_len + 100;
buf = os_zalloc(buf_len);
if (buf == NULL)
return NULL;
pos = buf;
- /* RSNIE[PMKR0Name] */
+ /* RSNIE[PMKR0Name/PMKR1Name] */
rsnie = (struct rsn_ie_hdr *) pos;
rsnie->elem_id = WLAN_EID_RSN;
WPA_PUT_LE16(rsnie->version, RSN_VERSION);
@@ -223,9 +282,10 @@ static u8 * wpa_ft_gen_req_ies(struct wpa_sm *sm, size_t *len,
pos += sizeof(*mdie);
os_memcpy(mdie->mobility_domain, sm->mobility_domain,
MOBILITY_DOMAIN_ID_LEN);
- mdie->ft_capab = 0; /* FIX: copy from the target AP's MDIE */
+ mdie->ft_capab = ap_mdie && ap_mdie[1] >= 3 ? ap_mdie[4] :
+ sm->mdie_ft_capab;
- /* FTIE[SNonce, R0KH-ID] */
+ /* FTIE[SNonce, [R1KH-ID,] R0KH-ID ] */
ftie_pos = pos;
*pos++ = WLAN_EID_FAST_BSS_TRANSITION;
ftie_len = pos++;
@@ -234,6 +294,13 @@ static u8 * wpa_ft_gen_req_ies(struct wpa_sm *sm, size_t *len,
os_memcpy(ftie->snonce, sm->snonce, WPA_NONCE_LEN);
if (anonce)
os_memcpy(ftie->anonce, anonce, WPA_NONCE_LEN);
+ if (kck) {
+ /* R1KH-ID sub-element in third FT message */
+ *pos++ = FTIE_SUBELEM_R1KH_ID;
+ *pos++ = FT_R1KH_ID_LEN;
+ os_memcpy(pos, sm->r1kh_id, FT_R1KH_ID_LEN);
+ pos += FT_R1KH_ID_LEN;
+ }
/* R0KH-ID sub-element */
*pos++ = FTIE_SUBELEM_R0KH_ID;
*pos++ = sm->r0kh_id_len;
@@ -241,6 +308,12 @@ static u8 * wpa_ft_gen_req_ies(struct wpa_sm *sm, size_t *len,
pos += sm->r0kh_id_len;
*ftie_len = pos - ftie_len - 1;
+ if (ric_ies) {
+ /* RIC Request */
+ os_memcpy(pos, ric_ies, ric_ies_len);
+ pos += ric_ies_len;
+ }
+
if (kck) {
/*
* IEEE Std 802.11r-2008, 11A.8.4
@@ -253,12 +326,14 @@ static u8 * wpa_ft_gen_req_ies(struct wpa_sm *sm, size_t *len,
* FTIE (with MIC field set to 0)
* RIC-Request (if present)
*/
- ftie->mic_control[1] = 3; /* Information element count */
+ /* Information element count */
+ ftie->mic_control[1] = 3 + ieee802_11_ie_count(ric_ies,
+ ric_ies_len);
if (wpa_ft_mic(kck, sm->own_addr, target_ap, 5,
((u8 *) mdie) - 2, 2 + sizeof(*mdie),
ftie_pos, 2 + *ftie_len,
- (u8 *) rsnie, 2 + rsnie->len, NULL, 0,
- ftie->mic) < 0) {
+ (u8 *) rsnie, 2 + rsnie->len, ric_ies,
+ ric_ies_len, ftie->mic) < 0) {
wpa_printf(MSG_INFO, "FT: Failed to calculate MIC");
os_free(buf);
return NULL;
@@ -271,26 +346,6 @@ static u8 * wpa_ft_gen_req_ies(struct wpa_sm *sm, size_t *len,
}
-struct wpa_ft_ies {
- const u8 *mdie;
- size_t mdie_len;
- const u8 *ftie;
- size_t ftie_len;
- const u8 *r1kh_id;
- const u8 *gtk;
- size_t gtk_len;
- const u8 *r0kh_id;
- size_t r0kh_id_len;
- const u8 *rsn;
- size_t rsn_len;
- const u8 *rsn_pmkid;
- const u8 *tie;
- size_t tie_len;
- const u8 *igtk;
- size_t igtk_len;
-};
-
-
static int wpa_ft_parse_ftie(const u8 *ie, size_t ie_len,
struct wpa_ft_ies *parse)
{
@@ -346,6 +401,8 @@ static int wpa_ft_parse_ies(const u8 *ies, size_t ies_len,
const u8 *end, *pos;
struct wpa_ie_data data;
int ret;
+ const struct rsn_ftie *ftie;
+ int prot_ie_count = 0;
os_memset(parse, 0, sizeof(*parse));
if (ies == NULL)
@@ -374,6 +431,10 @@ static int wpa_ft_parse_ies(const u8 *ies, size_t ies_len,
parse->mdie_len = pos[1];
break;
case WLAN_EID_FAST_BSS_TRANSITION:
+ if (pos[1] < sizeof(*ftie))
+ return -1;
+ ftie = (const struct rsn_ftie *) (pos + 2);
+ prot_ie_count = ftie->mic_control[1];
if (wpa_ft_parse_ftie(pos + 2, pos[1], parse) < 0)
return -1;
break;
@@ -381,11 +442,55 @@ static int wpa_ft_parse_ies(const u8 *ies, size_t ies_len,
parse->tie = pos + 2;
parse->tie_len = pos[1];
break;
+ case WLAN_EID_RIC_DATA:
+ if (parse->ric == NULL)
+ parse->ric = pos;
}
pos += 2 + pos[1];
}
+ if (prot_ie_count == 0)
+ return 0; /* no MIC */
+
+ /*
+ * Check that the protected IE count matches with IEs included in the
+ * frame.
+ */
+ if (parse->rsn)
+ prot_ie_count--;
+ if (parse->mdie)
+ prot_ie_count--;
+ if (parse->ftie)
+ prot_ie_count--;
+ if (parse->tie)
+ prot_ie_count--;
+ if (prot_ie_count < 0) {
+ wpa_printf(MSG_DEBUG, "FT: Some required IEs not included in "
+ "the protected IE count");
+ return -1;
+ }
+
+ if (prot_ie_count == 0 && parse->ric) {
+ wpa_printf(MSG_DEBUG, "FT: RIC IE(s) in the frame, but not "
+ "included in protected IE count");
+ return -1;
+ }
+
+ /* Determine the end of the RIC IE(s) */
+ pos = parse->ric;
+ while (pos && pos + 2 <= end && pos + 2 + pos[1] <= end &&
+ prot_ie_count) {
+ prot_ie_count--;
+ pos += 2 + pos[1];
+ }
+ parse->ric_len = pos - parse->ric;
+ if (prot_ie_count) {
+ wpa_printf(MSG_DEBUG, "FT: %d protected IEs missing from "
+ "frame", (int) prot_ie_count);
+ return -1;
+ }
+
return 0;
}
@@ -393,7 +498,7 @@ static int wpa_ft_parse_ies(const u8 *ies, size_t ies_len,
static int wpa_ft_install_ptk(struct wpa_sm *sm, const u8 *bssid)
{
int keylen;
- wpa_alg alg;
+ enum wpa_alg alg;
u8 null_rsc[6] = { 0, 0, 0, 0, 0, 0 };
wpa_printf(MSG_DEBUG, "FT: Installing PTK to the driver.");
@@ -426,9 +531,10 @@ static int wpa_ft_install_ptk(struct wpa_sm *sm, const u8 *bssid)
/**
* wpa_ft_prepare_auth_request - Generate over-the-air auth request
* @sm: Pointer to WPA state machine data from wpa_sm_init()
+ * @mdie: Target AP MDIE
* Returns: 0 on success, -1 on failure
*/
-int wpa_ft_prepare_auth_request(struct wpa_sm *sm)
+int wpa_ft_prepare_auth_request(struct wpa_sm *sm, const u8 *mdie)
{
u8 *ft_ies;
size_t ft_ies_len;
@@ -440,7 +546,7 @@ int wpa_ft_prepare_auth_request(struct wpa_sm *sm)
}
ft_ies = wpa_ft_gen_req_ies(sm, &ft_ies_len, NULL, sm->pmk_r0_name,
- NULL, sm->bssid);
+ NULL, sm->bssid, NULL, 0, mdie);
if (ft_ies) {
wpa_sm_update_ft_ies(sm, sm->mobility_domain,
ft_ies, ft_ies_len);
@@ -452,7 +558,8 @@ int wpa_ft_prepare_auth_request(struct wpa_sm *sm)
int wpa_ft_process_response(struct wpa_sm *sm, const u8 *ies, size_t ies_len,
- int ft_action, const u8 *target_ap)
+ int ft_action, const u8 *target_ap,
+ const u8 *ric_ies, size_t ric_ies_len)
{
u8 *ft_ies;
size_t ft_ies_len, ptk_len;
@@ -464,6 +571,7 @@ int wpa_ft_process_response(struct wpa_sm *sm, const u8 *ies, size_t ies_len,
const u8 *bssid;
wpa_hexdump(MSG_DEBUG, "FT: Response IEs", ies, ies_len);
+ wpa_hexdump(MSG_DEBUG, "FT: RIC IEs", ric_ies, ric_ies_len);
if (ft_action) {
if (!sm->over_the_ds_in_progress) {
@@ -506,6 +614,15 @@ int wpa_ft_process_response(struct wpa_sm *sm, const u8 *ies, size_t ies_len,
return -1;
}
+ if (os_memcmp(ftie->snonce, sm->snonce, WPA_NONCE_LEN) != 0) {
+ wpa_printf(MSG_DEBUG, "FT: SNonce mismatch in FTIE");
+ wpa_hexdump(MSG_DEBUG, "FT: Received SNonce",
+ ftie->snonce, WPA_NONCE_LEN);
+ wpa_hexdump(MSG_DEBUG, "FT: Expected SNonce",
+ sm->snonce, WPA_NONCE_LEN);
+ return -1;
+ }
+
if (parse.r0kh_id == NULL) {
wpa_printf(MSG_DEBUG, "FT: No R0KH-ID subelem in FTIE");
return -1;
@@ -538,6 +655,7 @@ int wpa_ft_process_response(struct wpa_sm *sm, const u8 *ies, size_t ies_len,
wpa_hexdump(MSG_DEBUG, "FT: R1KH-ID", sm->r1kh_id, FT_R1KH_ID_LEN);
wpa_hexdump(MSG_DEBUG, "FT: SNonce", sm->snonce, WPA_NONCE_LEN);
wpa_hexdump(MSG_DEBUG, "FT: ANonce", ftie->anonce, WPA_NONCE_LEN);
+ os_memcpy(sm->anonce, ftie->anonce, WPA_NONCE_LEN);
wpa_derive_pmk_r1(sm->pmk_r0, sm->pmk_r0_name, sm->r1kh_id,
sm->own_addr, sm->pmk_r1, sm->pmk_r1_name);
wpa_hexdump_key(MSG_DEBUG, "FT: PMK-R1", sm->pmk_r1, PMK_LEN);
@@ -554,26 +672,40 @@ int wpa_ft_process_response(struct wpa_sm *sm, const u8 *ies, size_t ies_len,
wpa_hexdump(MSG_DEBUG, "FT: PTKName", ptk_name, WPA_PMK_NAME_LEN);
ft_ies = wpa_ft_gen_req_ies(sm, &ft_ies_len, ftie->anonce,
- sm->pmk_r1_name, sm->ptk.kck, bssid);
+ sm->pmk_r1_name, sm->ptk.kck, bssid,
+ ric_ies, ric_ies_len,
+ parse.mdie ? parse.mdie - 2 : NULL);
if (ft_ies) {
wpa_sm_update_ft_ies(sm, sm->mobility_domain,
ft_ies, ft_ies_len);
os_free(ft_ies);
}
+ wpa_sm_mark_authenticated(sm, bssid);
ret = wpa_ft_install_ptk(sm, bssid);
+ if (ret) {
+ /*
+ * Some drivers do not support key configuration when we are
+ * not associated with the target AP. Work around this by
+ * trying again after the following reassociation gets
+ * completed.
+ */
+ wpa_printf(MSG_DEBUG, "FT: Failed to set PTK prior to "
+ "association - try again after reassociation");
+ sm->set_ptk_after_assoc = 1;
+ } else
+ sm->set_ptk_after_assoc = 0;
- if (ret == 0) {
- sm->ft_completed = 1;
- if (ft_action) {
- /* TODO: trigger re-association to the Target AP;
- * MLME is now doing this automatically, but it should
- * really be done only if we get here successfully. */
- os_memcpy(sm->bssid, target_ap, ETH_ALEN);
- }
+ sm->ft_completed = 1;
+ if (ft_action) {
+ /*
+ * The caller is expected trigger re-association with the
+ * Target AP.
+ */
+ os_memcpy(sm->bssid, target_ap, ETH_ALEN);
}
- return ret;
+ return 0;
}
@@ -595,7 +727,7 @@ static int wpa_ft_process_gtk_subelem(struct wpa_sm *sm, const u8 *gtk_elem,
{
u8 gtk[32];
int keyidx;
- wpa_alg alg;
+ enum wpa_alg alg;
size_t gtk_len, keylen, rsc_len;
if (gtk_elem == NULL) {
@@ -606,14 +738,14 @@ static int wpa_ft_process_gtk_subelem(struct wpa_sm *sm, const u8 *gtk_elem,
wpa_hexdump_key(MSG_DEBUG, "FT: Received GTK in Reassoc Resp",
gtk_elem, gtk_elem_len);
- if (gtk_elem_len < 10 + 24 || (gtk_elem_len - 10) % 8 ||
- gtk_elem_len - 18 > sizeof(gtk)) {
+ if (gtk_elem_len < 11 + 24 || (gtk_elem_len - 11) % 8 ||
+ gtk_elem_len - 19 > sizeof(gtk)) {
wpa_printf(MSG_DEBUG, "FT: Invalid GTK sub-elem "
"length %lu", (unsigned long) gtk_elem_len);
return -1;
}
- gtk_len = gtk_elem_len - 18;
- if (aes_unwrap(sm->ptk.kek, gtk_len / 8, gtk_elem + 10, gtk)) {
+ gtk_len = gtk_elem_len - 19;
+ if (aes_unwrap(sm->ptk.kek, gtk_len / 8, gtk_elem + 11, gtk)) {
wpa_printf(MSG_WARNING, "FT: AES unwrap failed - could not "
"decrypt GTK");
return -1;
@@ -651,20 +783,20 @@ static int wpa_ft_process_gtk_subelem(struct wpa_sm *sm, const u8 *gtk_elem,
return -1;
}
- /* Key Info[1] | Key Length[1] | RSC[8] | Key[5..32]. */
+ /* Key Info[2] | Key Length[1] | RSC[8] | Key[5..32]. */
- keyidx = gtk_elem[0] & 0x03;
+ keyidx = WPA_GET_LE16(gtk_elem) & 0x03;
- if (gtk_elem[1] != keylen) {
+ if (gtk_elem[2] != keylen) {
wpa_printf(MSG_DEBUG, "FT: GTK length mismatch: received %d "
"negotiated %lu",
- gtk_elem[1], (unsigned long) keylen);
+ gtk_elem[2], (unsigned long) keylen);
return -1;
}
wpa_hexdump_key(MSG_DEBUG, "FT: GTK from Reassoc Resp", gtk, keylen);
if (wpa_sm_set_key(sm, alg, (u8 *) "\xff\xff\xff\xff\xff\xff",
- keyidx, 0, gtk_elem + 2, rsc_len, gtk, keylen) <
+ keyidx, 0, gtk_elem + 3, rsc_len, gtk, keylen) <
0) {
wpa_printf(MSG_WARNING, "WPA: Failed to set GTK to the "
"driver.");
@@ -735,7 +867,7 @@ int wpa_ft_validate_reassoc_resp(struct wpa_sm *sm, const u8 *ies,
struct wpa_ft_ies parse;
struct rsn_mdie *mdie;
struct rsn_ftie *ftie;
- size_t count;
+ unsigned int count;
u8 mic[16];
wpa_hexdump(MSG_DEBUG, "FT: Response IEs", ies, ies_len);
@@ -766,6 +898,24 @@ int wpa_ft_validate_reassoc_resp(struct wpa_sm *sm, const u8 *ies,
return -1;
}
+ if (os_memcmp(ftie->snonce, sm->snonce, WPA_NONCE_LEN) != 0) {
+ wpa_printf(MSG_DEBUG, "FT: SNonce mismatch in FTIE");
+ wpa_hexdump(MSG_DEBUG, "FT: Received SNonce",
+ ftie->snonce, WPA_NONCE_LEN);
+ wpa_hexdump(MSG_DEBUG, "FT: Expected SNonce",
+ sm->snonce, WPA_NONCE_LEN);
+ return -1;
+ }
+
+ if (os_memcmp(ftie->anonce, sm->anonce, WPA_NONCE_LEN) != 0) {
+ wpa_printf(MSG_DEBUG, "FT: ANonce mismatch in FTIE");
+ wpa_hexdump(MSG_DEBUG, "FT: Received ANonce",
+ ftie->anonce, WPA_NONCE_LEN);
+ wpa_hexdump(MSG_DEBUG, "FT: Expected ANonce",
+ sm->anonce, WPA_NONCE_LEN);
+ return -1;
+ }
+
if (parse.r0kh_id == NULL) {
wpa_printf(MSG_DEBUG, "FT: No R0KH-ID subelem in FTIE");
return -1;
@@ -803,17 +953,18 @@ int wpa_ft_validate_reassoc_resp(struct wpa_sm *sm, const u8 *ies,
count = 3;
if (parse.tie)
count++;
-
if (ftie->mic_control[1] != count) {
- wpa_printf(MSG_DEBUG, "FT: Unexpected IE count in FTIE (%d)",
- ftie->mic_control[1]);
+ wpa_printf(MSG_DEBUG, "FT: Unexpected IE count in MIC "
+ "Control: received %u expected %u",
+ ftie->mic_control[1], count);
return -1;
}
if (wpa_ft_mic(sm->ptk.kck, sm->own_addr, src_addr, 6,
parse.mdie - 2, parse.mdie_len + 2,
parse.ftie - 2, parse.ftie_len + 2,
- parse.rsn - 2, parse.rsn_len + 2, NULL, 0,
+ parse.rsn - 2, parse.rsn_len + 2,
+ parse.ric, parse.ric_len,
mic) < 0) {
wpa_printf(MSG_DEBUG, "FT: Failed to calculate MIC");
return -1;
@@ -834,6 +985,20 @@ int wpa_ft_validate_reassoc_resp(struct wpa_sm *sm, const u8 *ies,
return -1;
#endif /* CONFIG_IEEE80211W */
+ if (sm->set_ptk_after_assoc) {
+ wpa_printf(MSG_DEBUG, "FT: Try to set PTK again now that we "
+ "are associated");
+ if (wpa_ft_install_ptk(sm, src_addr) < 0)
+ return -1;
+ sm->set_ptk_after_assoc = 0;
+ }
+
+ if (parse.ric) {
+ wpa_hexdump(MSG_MSGDUMP, "FT: RIC Response",
+ parse.ric, parse.ric_len);
+ /* TODO: parse response and inform driver about results */
+ }
+
return 0;
}
@@ -841,9 +1006,12 @@ int wpa_ft_validate_reassoc_resp(struct wpa_sm *sm, const u8 *ies,
/**
* wpa_ft_start_over_ds - Generate over-the-DS auth request
* @sm: Pointer to WPA state machine data from wpa_sm_init()
+ * @target_ap: Target AP Address
+ * @mdie: Mobility Domain IE from the target AP
* Returns: 0 on success, -1 on failure
*/
-int wpa_ft_start_over_ds(struct wpa_sm *sm, const u8 *target_ap)
+int wpa_ft_start_over_ds(struct wpa_sm *sm, const u8 *target_ap,
+ const u8 *mdie)
{
u8 *ft_ies;
size_t ft_ies_len;
@@ -858,7 +1026,7 @@ int wpa_ft_start_over_ds(struct wpa_sm *sm, const u8 *target_ap)
}
ft_ies = wpa_ft_gen_req_ies(sm, &ft_ies_len, NULL, sm->pmk_r0_name,
- NULL, target_ap);
+ NULL, target_ap, NULL, 0, mdie);
if (ft_ies) {
sm->over_the_ds_in_progress = 1;
os_memcpy(sm->target_ap, target_ap, ETH_ALEN);
diff --git a/contrib/wpa/src/rsn_supp/wpa_i.h b/contrib/wpa/src/rsn_supp/wpa_i.h
index e0dc6bd..618c090 100644
--- a/contrib/wpa/src/rsn_supp/wpa_i.h
+++ b/contrib/wpa/src/rsn_supp/wpa_i.h
@@ -1,6 +1,6 @@
/*
- * wpa_supplicant - Internal WPA state machine definitions
- * Copyright (c) 2004-2007, Jouni Malinen <j@w1.fi>
+ * Internal WPA/RSN supplicant state machine definitions
+ * Copyright (c) 2004-2010, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -15,7 +15,8 @@
#ifndef WPA_I_H
#define WPA_I_H
-struct rsn_pmksa_candidate;
+#include "utils/list.h"
+
struct wpa_peerkey;
struct wpa_eapol_key;
@@ -38,7 +39,7 @@ struct wpa_sm {
struct rsn_pmksa_cache *pmksa; /* PMKSA cache */
struct rsn_pmksa_cache_entry *cur_pmksa; /* current PMKSA entry */
- struct rsn_pmksa_candidate *pmksa_candidates;
+ struct dl_list pmksa_candidates;
struct l2_packet_data *l2_preauth;
struct l2_packet_data *l2_preauth_br;
@@ -81,6 +82,7 @@ struct wpa_sm {
unsigned int mgmt_group_cipher;
int rsn_enabled; /* Whether RSN is enabled in configuration */
+ int mfp; /* 0 = disabled, 1 = optional, 2 = mandatory */
u8 *assoc_wpa_ie; /* Own WPA/RSN IE from (Re)AssocReq */
size_t assoc_wpa_ie_len;
@@ -105,17 +107,21 @@ struct wpa_sm {
int ft_completed;
int over_the_ds_in_progress;
u8 target_ap[ETH_ALEN]; /* over-the-DS target AP */
+ int set_ptk_after_assoc;
+ u8 mdie_ft_capab; /* FT Capability and Policy from target AP MDIE */
+ u8 *assoc_resp_ies; /* MDIE and FTIE from (Re)Association Response */
+ size_t assoc_resp_ies_len;
#endif /* CONFIG_IEEE80211R */
};
-static inline void wpa_sm_set_state(struct wpa_sm *sm, wpa_states state)
+static inline void wpa_sm_set_state(struct wpa_sm *sm, enum wpa_states state)
{
WPA_ASSERT(sm->ctx->set_state);
sm->ctx->set_state(sm->ctx->ctx, state);
}
-static inline wpa_states wpa_sm_get_state(struct wpa_sm *sm)
+static inline enum wpa_states wpa_sm_get_state(struct wpa_sm *sm)
{
WPA_ASSERT(sm->ctx->get_state);
return sm->ctx->get_state(sm->ctx->ctx);
@@ -133,7 +139,7 @@ static inline void wpa_sm_disassociate(struct wpa_sm *sm, int reason_code)
sm->ctx->disassociate(sm->ctx->ctx, reason_code);
}
-static inline int wpa_sm_set_key(struct wpa_sm *sm, wpa_alg alg,
+static inline int wpa_sm_set_key(struct wpa_sm *sm, enum wpa_alg alg,
const u8 *addr, int key_idx, int set_tx,
const u8 *seq, size_t seq_len,
const u8 *key, size_t key_len)
@@ -223,6 +229,14 @@ static inline int wpa_sm_send_ft_action(struct wpa_sm *sm, u8 action,
return -1;
}
+static inline int wpa_sm_mark_authenticated(struct wpa_sm *sm,
+ const u8 *target_ap)
+{
+ if (sm->ctx->mark_authenticated)
+ return sm->ctx->mark_authenticated(sm->ctx->ctx, target_ap);
+ return -1;
+}
+
void wpa_eapol_key_send(struct wpa_sm *sm, const u8 *kck,
int ver, const u8 *dest, u16 proto,
diff --git a/contrib/wpa/src/rsn_supp/wpa_ie.c b/contrib/wpa/src/rsn_supp/wpa_ie.c
index 84f2811..f447223 100644
--- a/contrib/wpa/src/rsn_supp/wpa_ie.c
+++ b/contrib/wpa/src/rsn_supp/wpa_ie.c
@@ -17,7 +17,7 @@
#include "common.h"
#include "wpa.h"
#include "pmksa_cache.h"
-#include "ieee802_11_defs.h"
+#include "common/ieee802_11_defs.h"
#include "wpa_i.h"
#include "wpa_ie.h"
@@ -332,8 +332,10 @@ static int wpa_gen_wpa_ie_rsn(u8 *rsn_ie, size_t rsn_ie_len,
/* RSN Capabilities */
capab = 0;
#ifdef CONFIG_IEEE80211W
- if (mgmt_group_cipher == WPA_CIPHER_AES_128_CMAC)
+ if (sm->mfp)
capab |= WPA_CAPABILITY_MFPC;
+ if (sm->mfp == 2)
+ capab |= WPA_CAPABILITY_MFPR;
#endif /* CONFIG_IEEE80211W */
WPA_PUT_LE16(pos, capab);
pos += 2;
@@ -414,6 +416,8 @@ static int wpa_parse_generic(const u8 *pos, const u8 *end,
pos[2 + WPA_SELECTOR_LEN + 1] == 0) {
ie->wpa_ie = pos;
ie->wpa_ie_len = pos[1] + 2;
+ wpa_hexdump(MSG_DEBUG, "WPA: WPA IE in EAPOL-Key",
+ ie->wpa_ie, ie->wpa_ie_len);
return 0;
}
@@ -421,6 +425,8 @@ static int wpa_parse_generic(const u8 *pos, const u8 *end,
pos[1] >= RSN_SELECTOR_LEN + PMKID_LEN &&
RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_PMKID) {
ie->pmkid = pos + 2 + RSN_SELECTOR_LEN;
+ wpa_hexdump(MSG_DEBUG, "WPA: PMKID in EAPOL-Key",
+ pos, pos[1] + 2);
return 0;
}
@@ -428,6 +434,8 @@ static int wpa_parse_generic(const u8 *pos, const u8 *end,
RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_GROUPKEY) {
ie->gtk = pos + 2 + RSN_SELECTOR_LEN;
ie->gtk_len = pos[1] - RSN_SELECTOR_LEN;
+ wpa_hexdump_key(MSG_DEBUG, "WPA: GTK in EAPOL-Key",
+ pos, pos[1] + 2);
return 0;
}
@@ -435,6 +443,8 @@ static int wpa_parse_generic(const u8 *pos, const u8 *end,
RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_MAC_ADDR) {
ie->mac_addr = pos + 2 + RSN_SELECTOR_LEN;
ie->mac_addr_len = pos[1] - RSN_SELECTOR_LEN;
+ wpa_hexdump(MSG_DEBUG, "WPA: MAC Address in EAPOL-Key",
+ pos, pos[1] + 2);
return 0;
}
@@ -443,6 +453,8 @@ static int wpa_parse_generic(const u8 *pos, const u8 *end,
RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_SMK) {
ie->smk = pos + 2 + RSN_SELECTOR_LEN;
ie->smk_len = pos[1] - RSN_SELECTOR_LEN;
+ wpa_hexdump_key(MSG_DEBUG, "WPA: SMK in EAPOL-Key",
+ pos, pos[1] + 2);
return 0;
}
@@ -450,6 +462,8 @@ static int wpa_parse_generic(const u8 *pos, const u8 *end,
RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_NONCE) {
ie->nonce = pos + 2 + RSN_SELECTOR_LEN;
ie->nonce_len = pos[1] - RSN_SELECTOR_LEN;
+ wpa_hexdump(MSG_DEBUG, "WPA: Nonce in EAPOL-Key",
+ pos, pos[1] + 2);
return 0;
}
@@ -457,6 +471,8 @@ static int wpa_parse_generic(const u8 *pos, const u8 *end,
RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_LIFETIME) {
ie->lifetime = pos + 2 + RSN_SELECTOR_LEN;
ie->lifetime_len = pos[1] - RSN_SELECTOR_LEN;
+ wpa_hexdump(MSG_DEBUG, "WPA: Lifetime in EAPOL-Key",
+ pos, pos[1] + 2);
return 0;
}
@@ -464,6 +480,8 @@ static int wpa_parse_generic(const u8 *pos, const u8 *end,
RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_ERROR) {
ie->error = pos + 2 + RSN_SELECTOR_LEN;
ie->error_len = pos[1] - RSN_SELECTOR_LEN;
+ wpa_hexdump(MSG_DEBUG, "WPA: Error in EAPOL-Key",
+ pos, pos[1] + 2);
return 0;
}
#endif /* CONFIG_PEERKEY */
@@ -473,6 +491,8 @@ static int wpa_parse_generic(const u8 *pos, const u8 *end,
RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_IGTK) {
ie->igtk = pos + 2 + RSN_SELECTOR_LEN;
ie->igtk_len = pos[1] - RSN_SELECTOR_LEN;
+ wpa_hexdump_key(MSG_DEBUG, "WPA: IGTK in EAPOL-Key",
+ pos, pos[1] + 2);
return 0;
}
#endif /* CONFIG_IEEE80211W */
@@ -513,10 +533,35 @@ int wpa_supplicant_parse_ies(const u8 *buf, size_t len,
if (*pos == WLAN_EID_RSN) {
ie->rsn_ie = pos;
ie->rsn_ie_len = pos[1] + 2;
+ wpa_hexdump(MSG_DEBUG, "WPA: RSN IE in EAPOL-Key",
+ ie->rsn_ie, ie->rsn_ie_len);
#ifdef CONFIG_IEEE80211R
} else if (*pos == WLAN_EID_MOBILITY_DOMAIN) {
ie->mdie = pos;
ie->mdie_len = pos[1] + 2;
+ wpa_hexdump(MSG_DEBUG, "WPA: MDIE in EAPOL-Key",
+ ie->mdie, ie->mdie_len);
+ } else if (*pos == WLAN_EID_FAST_BSS_TRANSITION) {
+ ie->ftie = pos;
+ ie->ftie_len = pos[1] + 2;
+ wpa_hexdump(MSG_DEBUG, "WPA: FTIE in EAPOL-Key",
+ ie->ftie, ie->ftie_len);
+ } else if (*pos == WLAN_EID_TIMEOUT_INTERVAL && pos[1] >= 5) {
+ if (pos[2] == WLAN_TIMEOUT_REASSOC_DEADLINE) {
+ ie->reassoc_deadline = pos;
+ wpa_hexdump(MSG_DEBUG, "WPA: Reassoc Deadline "
+ "in EAPOL-Key",
+ ie->reassoc_deadline, pos[1] + 2);
+ } else if (pos[2] == WLAN_TIMEOUT_KEY_LIFETIME) {
+ ie->key_lifetime = pos;
+ wpa_hexdump(MSG_DEBUG, "WPA: KeyLifetime "
+ "in EAPOL-Key",
+ ie->key_lifetime, pos[1] + 2);
+ } else {
+ wpa_hexdump(MSG_DEBUG, "WPA: Unrecognized "
+ "EAPOL-Key Key Data IE",
+ pos, 2 + pos[1]);
+ }
#endif /* CONFIG_IEEE80211R */
} else if (*pos == WLAN_EID_VENDOR_SPECIFIC) {
ret = wpa_parse_generic(pos, end, ie);
diff --git a/contrib/wpa/src/rsn_supp/wpa_ie.h b/contrib/wpa/src/rsn_supp/wpa_ie.h
index 17e375a..94518d8 100644
--- a/contrib/wpa/src/rsn_supp/wpa_ie.h
+++ b/contrib/wpa/src/rsn_supp/wpa_ie.h
@@ -42,6 +42,10 @@ struct wpa_eapol_ie_parse {
#ifdef CONFIG_IEEE80211R
const u8 *mdie;
size_t mdie_len;
+ const u8 *ftie;
+ size_t ftie_len;
+ const u8 *reassoc_deadline;
+ const u8 *key_lifetime;
#endif /* CONFIG_IEEE80211R */
};
diff --git a/contrib/wpa/src/tls/.gitignore b/contrib/wpa/src/tls/.gitignore
new file mode 100644
index 0000000..d43242d
--- /dev/null
+++ b/contrib/wpa/src/tls/.gitignore
@@ -0,0 +1 @@
+libtls.a
diff --git a/contrib/wpa/src/tls/Makefile b/contrib/wpa/src/tls/Makefile
index cffba62..a2da096 100644
--- a/contrib/wpa/src/tls/Makefile
+++ b/contrib/wpa/src/tls/Makefile
@@ -1,9 +1,37 @@
-all:
- @echo Nothing to be made.
+all: libtls.a
clean:
- for d in $(SUBDIRS); do make -C $$d clean; done
- rm -f *~ *.o *.d
+ rm -f *~ *.o *.d libtls.a
install:
@echo Nothing to be made.
+
+
+include ../lib.rules
+
+CFLAGS += -DCONFIG_INTERNAL_LIBTOMMATH
+CFLAGS += -DCONFIG_CRYPTO_INTERNAL
+
+LIB_OBJS= \
+ asn1.o \
+ bignum.o \
+ pkcs1.o \
+ pkcs5.o \
+ pkcs8.o \
+ rsa.o \
+ tlsv1_client.o \
+ tlsv1_client_read.o \
+ tlsv1_client_write.o \
+ tlsv1_common.o \
+ tlsv1_cred.o \
+ tlsv1_record.o \
+ tlsv1_server.o \
+ tlsv1_server_read.o \
+ tlsv1_server_write.o \
+ x509v3.o
+
+
+libtls.a: $(LIB_OBJS)
+ $(AR) crT $@ $?
+
+-include $(OBJS:%.o=%.d)
diff --git a/contrib/wpa/src/tls/asn1.c b/contrib/wpa/src/tls/asn1.c
index 96bc1ac..3391245 100644
--- a/contrib/wpa/src/tls/asn1.c
+++ b/contrib/wpa/src/tls/asn1.c
@@ -15,9 +15,6 @@
#include "includes.h"
#include "common.h"
-
-#ifdef CONFIG_INTERNAL_X509
-
#include "asn1.h"
int asn1_get_next(const u8 *buf, size_t len, struct asn1_hdr *hdr)
@@ -85,28 +82,16 @@ int asn1_get_next(const u8 *buf, size_t len, struct asn1_hdr *hdr)
}
-int asn1_get_oid(const u8 *buf, size_t len, struct asn1_oid *oid,
- const u8 **next)
+int asn1_parse_oid(const u8 *buf, size_t len, struct asn1_oid *oid)
{
- struct asn1_hdr hdr;
const u8 *pos, *end;
unsigned long val;
u8 tmp;
os_memset(oid, 0, sizeof(*oid));
- if (asn1_get_next(buf, len, &hdr) < 0 || hdr.length == 0)
- return -1;
-
- if (hdr.class != ASN1_CLASS_UNIVERSAL || hdr.tag != ASN1_TAG_OID) {
- wpa_printf(MSG_DEBUG, "ASN.1: Expected OID - found class %d "
- "tag 0x%x", hdr.class, hdr.tag);
- return -1;
- }
-
- pos = hdr.payload;
- end = hdr.payload + hdr.length;
- *next = end;
+ pos = buf;
+ end = buf + len;
while (pos < end) {
val = 0;
@@ -141,6 +126,26 @@ int asn1_get_oid(const u8 *buf, size_t len, struct asn1_oid *oid,
}
+int asn1_get_oid(const u8 *buf, size_t len, struct asn1_oid *oid,
+ const u8 **next)
+{
+ struct asn1_hdr hdr;
+
+ if (asn1_get_next(buf, len, &hdr) < 0 || hdr.length == 0)
+ return -1;
+
+ if (hdr.class != ASN1_CLASS_UNIVERSAL || hdr.tag != ASN1_TAG_OID) {
+ wpa_printf(MSG_DEBUG, "ASN.1: Expected OID - found class %d "
+ "tag 0x%x", hdr.class, hdr.tag);
+ return -1;
+ }
+
+ *next = hdr.payload + hdr.length;
+
+ return asn1_parse_oid(hdr.payload, hdr.length, oid);
+}
+
+
void asn1_oid_to_str(struct asn1_oid *oid, char *buf, size_t len)
{
char *pos = buf;
@@ -205,5 +210,3 @@ unsigned long asn1_bit_string_to_long(const u8 *buf, size_t len)
return val;
}
-
-#endif /* CONFIG_INTERNAL_X509 */
diff --git a/contrib/wpa/src/tls/asn1.h b/contrib/wpa/src/tls/asn1.h
index c02ada8..2ff571e 100644
--- a/contrib/wpa/src/tls/asn1.h
+++ b/contrib/wpa/src/tls/asn1.h
@@ -63,6 +63,7 @@ struct asn1_oid {
int asn1_get_next(const u8 *buf, size_t len, struct asn1_hdr *hdr);
+int asn1_parse_oid(const u8 *buf, size_t len, struct asn1_oid *oid);
int asn1_get_oid(const u8 *buf, size_t len, struct asn1_oid *oid,
const u8 **next);
void asn1_oid_to_str(struct asn1_oid *oid, char *buf, size_t len);
diff --git a/contrib/wpa/src/tls/asn1_test.c b/contrib/wpa/src/tls/asn1_test.c
deleted file mode 100644
index a5c7753..0000000
--- a/contrib/wpa/src/tls/asn1_test.c
+++ /dev/null
@@ -1,210 +0,0 @@
-/*
- * Testing tool for ASN.1/X.509v3 routines
- * Copyright (c) 2006, Jouni Malinen <j@w1.fi>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
- */
-
-#include "includes.h"
-
-#include "common.h"
-#include "asn1.h"
-#include "x509v3.h"
-
-extern int wpa_debug_level;
-
-
-static const char * asn1_class_str(int class)
-{
- switch (class) {
- case ASN1_CLASS_UNIVERSAL:
- return "Universal";
- case ASN1_CLASS_APPLICATION:
- return "Application";
- case ASN1_CLASS_CONTEXT_SPECIFIC:
- return "Context-specific";
- case ASN1_CLASS_PRIVATE:
- return "Private";
- default:
- return "?";
- }
-}
-
-
-int asn1_parse(const u8 *buf, size_t len, int level)
-{
- const u8 *pos, *prev, *end;
- char prefix[10], str[100];
- int _level;
- struct asn1_hdr hdr;
- struct asn1_oid oid;
- u8 tmp;
-
- _level = level;
- if ((size_t) _level > sizeof(prefix) - 1)
- _level = sizeof(prefix) - 1;
- memset(prefix, ' ', _level);
- prefix[_level] = '\0';
-
- pos = buf;
- end = buf + len;
-
- while (pos < end) {
- if (asn1_get_next(pos, end - pos, &hdr) < 0)
- return -1;
-
- prev = pos;
- pos = hdr.payload;
-
- wpa_printf(MSG_MSGDUMP, "ASN.1:%s Class %d(%s) P/C %d(%s) "
- "Tag %u Length %u",
- prefix, hdr.class, asn1_class_str(hdr.class),
- hdr.constructed,
- hdr.constructed ? "Constructed" : "Primitive",
- hdr.tag, hdr.length);
-
- if (hdr.class == ASN1_CLASS_CONTEXT_SPECIFIC &&
- hdr.constructed) {
- if (asn1_parse(pos, hdr.length, level + 1) < 0)
- return -1;
- pos += hdr.length;
- }
-
- if (hdr.class != ASN1_CLASS_UNIVERSAL)
- continue;
-
- switch (hdr.tag) {
- case ASN1_TAG_EOC:
- if (hdr.length) {
- wpa_printf(MSG_DEBUG, "ASN.1: Non-zero "
- "end-of-contents length (%u)",
- hdr.length);
- return -1;
- }
- wpa_printf(MSG_MSGDUMP, "ASN.1:%s EOC", prefix);
- break;
- case ASN1_TAG_BOOLEAN:
- if (hdr.length != 1) {
- wpa_printf(MSG_DEBUG, "ASN.1: Unexpected "
- "Boolean length (%u)", hdr.length);
- return -1;
- }
- tmp = *pos++;
- wpa_printf(MSG_MSGDUMP, "ASN.1:%s Boolean %s",
- prefix, tmp ? "TRUE" : "FALSE");
- break;
- case ASN1_TAG_INTEGER:
- wpa_hexdump(MSG_MSGDUMP, "ASN.1: INTEGER",
- pos, hdr.length);
- pos += hdr.length;
- break;
- case ASN1_TAG_BITSTRING:
- wpa_hexdump(MSG_MSGDUMP, "ASN.1: BitString",
- pos, hdr.length);
- pos += hdr.length;
- break;
- case ASN1_TAG_OCTETSTRING:
- wpa_hexdump(MSG_MSGDUMP, "ASN.1: OctetString",
- pos, hdr.length);
- pos += hdr.length;
- break;
- case ASN1_TAG_NULL:
- if (hdr.length) {
- wpa_printf(MSG_DEBUG, "ASN.1: Non-zero Null "
- "length (%u)", hdr.length);
- return -1;
- }
- wpa_printf(MSG_MSGDUMP, "ASN.1:%s Null", prefix);
- break;
- case ASN1_TAG_OID:
- if (asn1_get_oid(prev, end - prev, &oid, &prev) < 0) {
- wpa_printf(MSG_DEBUG, "ASN.1: Invalid OID");
- return -1;
- }
- asn1_oid_to_str(&oid, str, sizeof(str));
- wpa_printf(MSG_DEBUG, "ASN.1:%s OID %s", prefix, str);
- pos += hdr.length;
- break;
- case ANS1_TAG_RELATIVE_OID:
- wpa_hexdump(MSG_MSGDUMP, "ASN.1: Relative OID",
- pos, hdr.length);
- pos += hdr.length;
- break;
- case ASN1_TAG_SEQUENCE:
- wpa_printf(MSG_MSGDUMP, "ASN.1:%s SEQUENCE", prefix);
- if (asn1_parse(pos, hdr.length, level + 1) < 0)
- return -1;
- pos += hdr.length;
- break;
- case ASN1_TAG_SET:
- wpa_printf(MSG_MSGDUMP, "ASN.1:%s SET", prefix);
- if (asn1_parse(pos, hdr.length, level + 1) < 0)
- return -1;
- pos += hdr.length;
- break;
- case ASN1_TAG_PRINTABLESTRING:
- wpa_hexdump_ascii(MSG_MSGDUMP,
- "ASN.1: PrintableString",
- pos, hdr.length);
- pos += hdr.length;
- break;
- case ASN1_TAG_IA5STRING:
- wpa_hexdump_ascii(MSG_MSGDUMP, "ASN.1: IA5String",
- pos, hdr.length);
- pos += hdr.length;
- break;
- case ASN1_TAG_UTCTIME:
- wpa_hexdump_ascii(MSG_MSGDUMP, "ASN.1: UTCTIME",
- pos, hdr.length);
- pos += hdr.length;
- break;
- case ASN1_TAG_VISIBLESTRING:
- wpa_hexdump_ascii(MSG_MSGDUMP, "ASN.1: VisibleString",
- pos, hdr.length);
- pos += hdr.length;
- break;
- default:
- wpa_printf(MSG_DEBUG, "ASN.1: Unknown tag %d",
- hdr.tag);
- return -1;
- }
- }
-
- return 0;
-}
-
-
-int main(int argc, char *argv[])
-{
- FILE *f;
- u8 buf[3000];
- size_t len;
- struct x509_certificate *cert;
-
- wpa_debug_level = 0;
-
- f = fopen(argv[1], "rb");
- if (f == NULL)
- return -1;
- len = fread(buf, 1, sizeof(buf), f);
- fclose(f);
-
- if (asn1_parse(buf, len, 0) < 0)
- printf("Failed to parse DER ASN.1\n");
-
- printf("\n\n");
-
- cert = x509_certificate_parse(buf, len);
- if (cert == NULL)
- printf("Failed to parse X.509 certificate\n");
- x509_certificate_free(cert);
-
- return 0;
-}
diff --git a/contrib/wpa/src/tls/pkcs1.c b/contrib/wpa/src/tls/pkcs1.c
new file mode 100644
index 0000000..72ebd87
--- /dev/null
+++ b/contrib/wpa/src/tls/pkcs1.c
@@ -0,0 +1,201 @@
+/*
+ * PKCS #1 (RSA Encryption)
+ * Copyright (c) 2006-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "rsa.h"
+#include "pkcs1.h"
+
+
+static int pkcs1_generate_encryption_block(u8 block_type, size_t modlen,
+ const u8 *in, size_t inlen,
+ u8 *out, size_t *outlen)
+{
+ size_t ps_len;
+ u8 *pos;
+
+ /*
+ * PKCS #1 v1.5, 8.1:
+ *
+ * EB = 00 || BT || PS || 00 || D
+ * BT = 00 or 01 for private-key operation; 02 for public-key operation
+ * PS = k-3-||D||; at least eight octets
+ * (BT=0: PS=0x00, BT=1: PS=0xff, BT=2: PS=pseudorandom non-zero)
+ * k = length of modulus in octets (modlen)
+ */
+
+ if (modlen < 12 || modlen > *outlen || inlen > modlen - 11) {
+ wpa_printf(MSG_DEBUG, "PKCS #1: %s - Invalid buffer "
+ "lengths (modlen=%lu outlen=%lu inlen=%lu)",
+ __func__, (unsigned long) modlen,
+ (unsigned long) *outlen,
+ (unsigned long) inlen);
+ return -1;
+ }
+
+ pos = out;
+ *pos++ = 0x00;
+ *pos++ = block_type; /* BT */
+ ps_len = modlen - inlen - 3;
+ switch (block_type) {
+ case 0:
+ os_memset(pos, 0x00, ps_len);
+ pos += ps_len;
+ break;
+ case 1:
+ os_memset(pos, 0xff, ps_len);
+ pos += ps_len;
+ break;
+ case 2:
+ if (os_get_random(pos, ps_len) < 0) {
+ wpa_printf(MSG_DEBUG, "PKCS #1: %s - Failed to get "
+ "random data for PS", __func__);
+ return -1;
+ }
+ while (ps_len--) {
+ if (*pos == 0x00)
+ *pos = 0x01;
+ pos++;
+ }
+ break;
+ default:
+ wpa_printf(MSG_DEBUG, "PKCS #1: %s - Unsupported block type "
+ "%d", __func__, block_type);
+ return -1;
+ }
+ *pos++ = 0x00;
+ os_memcpy(pos, in, inlen); /* D */
+
+ return 0;
+}
+
+
+int pkcs1_encrypt(int block_type, struct crypto_rsa_key *key,
+ int use_private, const u8 *in, size_t inlen,
+ u8 *out, size_t *outlen)
+{
+ size_t modlen;
+
+ modlen = crypto_rsa_get_modulus_len(key);
+
+ if (pkcs1_generate_encryption_block(block_type, modlen, in, inlen,
+ out, outlen) < 0)
+ return -1;
+
+ return crypto_rsa_exptmod(out, modlen, out, outlen, key, use_private);
+}
+
+
+int pkcs1_v15_private_key_decrypt(struct crypto_rsa_key *key,
+ const u8 *in, size_t inlen,
+ u8 *out, size_t *outlen)
+{
+ int res;
+ u8 *pos, *end;
+
+ res = crypto_rsa_exptmod(in, inlen, out, outlen, key, 1);
+ if (res)
+ return res;
+
+ if (*outlen < 2 || out[0] != 0 || out[1] != 2)
+ return -1;
+
+ /* Skip PS (pseudorandom non-zero octets) */
+ pos = out + 2;
+ end = out + *outlen;
+ while (*pos && pos < end)
+ pos++;
+ if (pos == end)
+ return -1;
+ pos++;
+
+ *outlen -= pos - out;
+
+ /* Strip PKCS #1 header */
+ os_memmove(out, pos, *outlen);
+
+ return 0;
+}
+
+
+int pkcs1_decrypt_public_key(struct crypto_rsa_key *key,
+ const u8 *crypt, size_t crypt_len,
+ u8 *plain, size_t *plain_len)
+{
+ size_t len;
+ u8 *pos;
+
+ len = *plain_len;
+ if (crypto_rsa_exptmod(crypt, crypt_len, plain, &len, key, 0) < 0)
+ return -1;
+
+ /*
+ * PKCS #1 v1.5, 8.1:
+ *
+ * EB = 00 || BT || PS || 00 || D
+ * BT = 00 or 01
+ * PS = k-3-||D|| times (00 if BT=00) or (FF if BT=01)
+ * k = length of modulus in octets
+ */
+
+ if (len < 3 + 8 + 16 /* min hash len */ ||
+ plain[0] != 0x00 || (plain[1] != 0x00 && plain[1] != 0x01)) {
+ wpa_printf(MSG_INFO, "LibTomCrypt: Invalid signature EB "
+ "structure");
+ return -1;
+ }
+
+ pos = plain + 3;
+ if (plain[1] == 0x00) {
+ /* BT = 00 */
+ if (plain[2] != 0x00) {
+ wpa_printf(MSG_INFO, "LibTomCrypt: Invalid signature "
+ "PS (BT=00)");
+ return -1;
+ }
+ while (pos + 1 < plain + len && *pos == 0x00 && pos[1] == 0x00)
+ pos++;
+ } else {
+ /* BT = 01 */
+ if (plain[2] != 0xff) {
+ wpa_printf(MSG_INFO, "LibTomCrypt: Invalid signature "
+ "PS (BT=01)");
+ return -1;
+ }
+ while (pos < plain + len && *pos == 0xff)
+ pos++;
+ }
+
+ if (pos - plain - 2 < 8) {
+ /* PKCS #1 v1.5, 8.1: At least eight octets long PS */
+ wpa_printf(MSG_INFO, "LibTomCrypt: Too short signature "
+ "padding");
+ return -1;
+ }
+
+ if (pos + 16 /* min hash len */ >= plain + len || *pos != 0x00) {
+ wpa_printf(MSG_INFO, "LibTomCrypt: Invalid signature EB "
+ "structure (2)");
+ return -1;
+ }
+ pos++;
+ len -= pos - plain;
+
+ /* Strip PKCS #1 header */
+ os_memmove(plain, pos, len);
+ *plain_len = len;
+
+ return 0;
+}
diff --git a/contrib/wpa/src/tls/pkcs1.h b/contrib/wpa/src/tls/pkcs1.h
new file mode 100644
index 0000000..68872b1
--- /dev/null
+++ b/contrib/wpa/src/tls/pkcs1.h
@@ -0,0 +1,28 @@
+/*
+ * PKCS #1 (RSA Encryption)
+ * Copyright (c) 2006-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef PKCS1_H
+#define PKCS1_H
+
+int pkcs1_encrypt(int block_type, struct crypto_rsa_key *key,
+ int use_private, const u8 *in, size_t inlen,
+ u8 *out, size_t *outlen);
+int pkcs1_v15_private_key_decrypt(struct crypto_rsa_key *key,
+ const u8 *in, size_t inlen,
+ u8 *out, size_t *outlen);
+int pkcs1_decrypt_public_key(struct crypto_rsa_key *key,
+ const u8 *crypt, size_t crypt_len,
+ u8 *plain, size_t *plain_len);
+
+#endif /* PKCS1_H */
diff --git a/contrib/wpa/src/tls/pkcs5.c b/contrib/wpa/src/tls/pkcs5.c
new file mode 100644
index 0000000..4291b84
--- /dev/null
+++ b/contrib/wpa/src/tls/pkcs5.c
@@ -0,0 +1,238 @@
+/*
+ * PKCS #5 (Password-based Encryption)
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "crypto/crypto.h"
+#include "crypto/md5.h"
+#include "asn1.h"
+#include "pkcs5.h"
+
+
+struct pkcs5_params {
+ enum pkcs5_alg {
+ PKCS5_ALG_UNKNOWN,
+ PKCS5_ALG_MD5_DES_CBC
+ } alg;
+ u8 salt[8];
+ size_t salt_len;
+ unsigned int iter_count;
+};
+
+
+enum pkcs5_alg pkcs5_get_alg(struct asn1_oid *oid)
+{
+ if (oid->len == 7 &&
+ oid->oid[0] == 1 /* iso */ &&
+ oid->oid[1] == 2 /* member-body */ &&
+ oid->oid[2] == 840 /* us */ &&
+ oid->oid[3] == 113549 /* rsadsi */ &&
+ oid->oid[4] == 1 /* pkcs */ &&
+ oid->oid[5] == 5 /* pkcs-5 */ &&
+ oid->oid[6] == 3 /* pbeWithMD5AndDES-CBC */)
+ return PKCS5_ALG_MD5_DES_CBC;
+
+ return PKCS5_ALG_UNKNOWN;
+}
+
+
+static int pkcs5_get_params(const u8 *enc_alg, size_t enc_alg_len,
+ struct pkcs5_params *params)
+{
+ struct asn1_hdr hdr;
+ const u8 *enc_alg_end, *pos, *end;
+ struct asn1_oid oid;
+ char obuf[80];
+
+ /* AlgorithmIdentifier */
+
+ enc_alg_end = enc_alg + enc_alg_len;
+
+ os_memset(params, 0, sizeof(*params));
+
+ if (asn1_get_oid(enc_alg, enc_alg_end - enc_alg, &oid, &pos)) {
+ wpa_printf(MSG_DEBUG, "PKCS #5: Failed to parse OID "
+ "(algorithm)");
+ return -1;
+ }
+
+ asn1_oid_to_str(&oid, obuf, sizeof(obuf));
+ wpa_printf(MSG_DEBUG, "PKCS #5: encryption algorithm %s", obuf);
+ params->alg = pkcs5_get_alg(&oid);
+ if (params->alg == PKCS5_ALG_UNKNOWN) {
+ wpa_printf(MSG_INFO, "PKCS #5: unsupported encryption "
+ "algorithm %s", obuf);
+ return -1;
+ }
+
+ /*
+ * PKCS#5, Section 8
+ * PBEParameter ::= SEQUENCE {
+ * salt OCTET STRING SIZE(8),
+ * iterationCount INTEGER }
+ */
+
+ if (asn1_get_next(pos, enc_alg_end - pos, &hdr) < 0 ||
+ hdr.class != ASN1_CLASS_UNIVERSAL ||
+ hdr.tag != ASN1_TAG_SEQUENCE) {
+ wpa_printf(MSG_DEBUG, "PKCS #5: Expected SEQUENCE "
+ "(PBEParameter) - found class %d tag 0x%x",
+ hdr.class, hdr.tag);
+ return -1;
+ }
+ pos = hdr.payload;
+ end = hdr.payload + hdr.length;
+
+ /* salt OCTET STRING SIZE(8) */
+ if (asn1_get_next(pos, end - pos, &hdr) < 0 ||
+ hdr.class != ASN1_CLASS_UNIVERSAL ||
+ hdr.tag != ASN1_TAG_OCTETSTRING ||
+ hdr.length != 8) {
+ wpa_printf(MSG_DEBUG, "PKCS #5: Expected OCTETSTRING SIZE(8) "
+ "(salt) - found class %d tag 0x%x size %d",
+ hdr.class, hdr.tag, hdr.length);
+ return -1;
+ }
+ pos = hdr.payload + hdr.length;
+ os_memcpy(params->salt, hdr.payload, hdr.length);
+ params->salt_len = hdr.length;
+ wpa_hexdump(MSG_DEBUG, "PKCS #5: salt",
+ params->salt, params->salt_len);
+
+ /* iterationCount INTEGER */
+ if (asn1_get_next(pos, end - pos, &hdr) < 0 ||
+ hdr.class != ASN1_CLASS_UNIVERSAL || hdr.tag != ASN1_TAG_INTEGER) {
+ wpa_printf(MSG_DEBUG, "PKCS #5: Expected INTEGER - found "
+ "class %d tag 0x%x", hdr.class, hdr.tag);
+ return -1;
+ }
+ if (hdr.length == 1)
+ params->iter_count = *hdr.payload;
+ else if (hdr.length == 2)
+ params->iter_count = WPA_GET_BE16(hdr.payload);
+ else if (hdr.length == 4)
+ params->iter_count = WPA_GET_BE32(hdr.payload);
+ else {
+ wpa_hexdump(MSG_DEBUG, "PKCS #5: Unsupported INTEGER value "
+ " (iterationCount)",
+ hdr.payload, hdr.length);
+ return -1;
+ }
+ wpa_printf(MSG_DEBUG, "PKCS #5: iterationCount=0x%x",
+ params->iter_count);
+ if (params->iter_count == 0 || params->iter_count > 0xffff) {
+ wpa_printf(MSG_INFO, "PKCS #5: Unsupported "
+ "iterationCount=0x%x", params->iter_count);
+ return -1;
+ }
+
+ return 0;
+}
+
+
+static struct crypto_cipher * pkcs5_crypto_init(struct pkcs5_params *params,
+ const char *passwd)
+{
+ unsigned int i;
+ u8 hash[MD5_MAC_LEN];
+ const u8 *addr[2];
+ size_t len[2];
+
+ if (params->alg != PKCS5_ALG_MD5_DES_CBC)
+ return NULL;
+
+ addr[0] = (const u8 *) passwd;
+ len[0] = os_strlen(passwd);
+ addr[1] = params->salt;
+ len[1] = params->salt_len;
+ if (md5_vector(2, addr, len, hash) < 0)
+ return NULL;
+ addr[0] = hash;
+ len[0] = MD5_MAC_LEN;
+ for (i = 1; i < params->iter_count; i++) {
+ if (md5_vector(1, addr, len, hash) < 0)
+ return NULL;
+ }
+ /* TODO: DES key parity bits(?) */
+ wpa_hexdump_key(MSG_DEBUG, "PKCS #5: DES key", hash, 8);
+ wpa_hexdump_key(MSG_DEBUG, "PKCS #5: DES IV", hash + 8, 8);
+
+ return crypto_cipher_init(CRYPTO_CIPHER_ALG_DES, hash + 8, hash, 8);
+}
+
+
+u8 * pkcs5_decrypt(const u8 *enc_alg, size_t enc_alg_len,
+ const u8 *enc_data, size_t enc_data_len,
+ const char *passwd, size_t *data_len)
+{
+ struct crypto_cipher *ctx;
+ u8 *eb, pad;
+ struct pkcs5_params params;
+ unsigned int i;
+
+ if (pkcs5_get_params(enc_alg, enc_alg_len, &params) < 0) {
+ wpa_printf(MSG_DEBUG, "PKCS #5: Unsupported parameters");
+ return NULL;
+ }
+
+ ctx = pkcs5_crypto_init(&params, passwd);
+ if (ctx == NULL) {
+ wpa_printf(MSG_DEBUG, "PKCS #5: Failed to initialize crypto");
+ return NULL;
+ }
+
+ /* PKCS #5, Section 7 - Decryption process */
+ if (enc_data_len < 16 || enc_data_len % 8) {
+ wpa_printf(MSG_INFO, "PKCS #5: invalid length of ciphertext "
+ "%d", (int) enc_data_len);
+ crypto_cipher_deinit(ctx);
+ return NULL;
+ }
+
+ eb = os_malloc(enc_data_len);
+ if (eb == NULL) {
+ crypto_cipher_deinit(ctx);
+ return NULL;
+ }
+
+ if (crypto_cipher_decrypt(ctx, enc_data, eb, enc_data_len) < 0) {
+ wpa_printf(MSG_DEBUG, "PKCS #5: Failed to decrypt EB");
+ crypto_cipher_deinit(ctx);
+ os_free(eb);
+ return NULL;
+ }
+ crypto_cipher_deinit(ctx);
+
+ pad = eb[enc_data_len - 1];
+ if (pad > 8) {
+ wpa_printf(MSG_INFO, "PKCS #5: Invalid PS octet 0x%x", pad);
+ os_free(eb);
+ return NULL;
+ }
+ for (i = enc_data_len - pad; i < enc_data_len; i++) {
+ if (eb[i] != pad) {
+ wpa_hexdump(MSG_INFO, "PKCS #5: Invalid PS",
+ eb + enc_data_len - pad, pad);
+ os_free(eb);
+ return NULL;
+ }
+ }
+
+ wpa_hexdump_key(MSG_MSGDUMP, "PKCS #5: message M (encrypted key)",
+ eb, enc_data_len - pad);
+
+ *data_len = enc_data_len - pad;
+ return eb;
+}
diff --git a/contrib/wpa/src/tls/pkcs5.h b/contrib/wpa/src/tls/pkcs5.h
new file mode 100644
index 0000000..6ed3923
--- /dev/null
+++ b/contrib/wpa/src/tls/pkcs5.h
@@ -0,0 +1,22 @@
+/*
+ * PKCS #5 (Password-based Encryption)
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef PKCS5_H
+#define PKCS5_H
+
+u8 * pkcs5_decrypt(const u8 *enc_alg, size_t enc_alg_len,
+ const u8 *enc_data, size_t enc_data_len,
+ const char *passwd, size_t *data_len);
+
+#endif /* PKCS5_H */
diff --git a/contrib/wpa/src/tls/pkcs8.c b/contrib/wpa/src/tls/pkcs8.c
new file mode 100644
index 0000000..69ab262
--- /dev/null
+++ b/contrib/wpa/src/tls/pkcs8.c
@@ -0,0 +1,193 @@
+/*
+ * PKCS #8 (Private-key information syntax)
+ * Copyright (c) 2006-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "asn1.h"
+#include "bignum.h"
+#include "rsa.h"
+#include "pkcs5.h"
+#include "pkcs8.h"
+
+
+struct crypto_private_key * pkcs8_key_import(const u8 *buf, size_t len)
+{
+ struct asn1_hdr hdr;
+ const u8 *pos, *end;
+ struct bignum *zero;
+ struct asn1_oid oid;
+ char obuf[80];
+
+ /* PKCS #8, Chapter 6 */
+
+ /* PrivateKeyInfo ::= SEQUENCE */
+ if (asn1_get_next(buf, len, &hdr) < 0 ||
+ hdr.class != ASN1_CLASS_UNIVERSAL ||
+ hdr.tag != ASN1_TAG_SEQUENCE) {
+ wpa_printf(MSG_DEBUG, "PKCS #8: Does not start with PKCS #8 "
+ "header (SEQUENCE); assume PKCS #8 not used");
+ return NULL;
+ }
+ pos = hdr.payload;
+ end = pos + hdr.length;
+
+ /* version Version (Version ::= INTEGER) */
+ if (asn1_get_next(pos, end - pos, &hdr) < 0 ||
+ hdr.class != ASN1_CLASS_UNIVERSAL || hdr.tag != ASN1_TAG_INTEGER) {
+ wpa_printf(MSG_DEBUG, "PKCS #8: Expected INTEGER - found "
+ "class %d tag 0x%x; assume PKCS #8 not used",
+ hdr.class, hdr.tag);
+ return NULL;
+ }
+
+ zero = bignum_init();
+ if (zero == NULL)
+ return NULL;
+
+ if (bignum_set_unsigned_bin(zero, hdr.payload, hdr.length) < 0) {
+ wpa_printf(MSG_DEBUG, "PKCS #8: Failed to parse INTEGER");
+ bignum_deinit(zero);
+ return NULL;
+ }
+ pos = hdr.payload + hdr.length;
+
+ if (bignum_cmp_d(zero, 0) != 0) {
+ wpa_printf(MSG_DEBUG, "PKCS #8: Expected zero INTEGER in the "
+ "beginning of private key; not found; assume "
+ "PKCS #8 not used");
+ bignum_deinit(zero);
+ return NULL;
+ }
+ bignum_deinit(zero);
+
+ /* privateKeyAlgorithm PrivateKeyAlgorithmIdentifier
+ * (PrivateKeyAlgorithmIdentifier ::= AlgorithmIdentifier) */
+ if (asn1_get_next(pos, len, &hdr) < 0 ||
+ hdr.class != ASN1_CLASS_UNIVERSAL ||
+ hdr.tag != ASN1_TAG_SEQUENCE) {
+ wpa_printf(MSG_DEBUG, "PKCS #8: Expected SEQUENCE "
+ "(AlgorithmIdentifier) - found class %d tag 0x%x; "
+ "assume PKCS #8 not used",
+ hdr.class, hdr.tag);
+ return NULL;
+ }
+
+ if (asn1_get_oid(hdr.payload, hdr.length, &oid, &pos)) {
+ wpa_printf(MSG_DEBUG, "PKCS #8: Failed to parse OID "
+ "(algorithm); assume PKCS #8 not used");
+ return NULL;
+ }
+
+ asn1_oid_to_str(&oid, obuf, sizeof(obuf));
+ wpa_printf(MSG_DEBUG, "PKCS #8: algorithm=%s", obuf);
+
+ if (oid.len != 7 ||
+ oid.oid[0] != 1 /* iso */ ||
+ oid.oid[1] != 2 /* member-body */ ||
+ oid.oid[2] != 840 /* us */ ||
+ oid.oid[3] != 113549 /* rsadsi */ ||
+ oid.oid[4] != 1 /* pkcs */ ||
+ oid.oid[5] != 1 /* pkcs-1 */ ||
+ oid.oid[6] != 1 /* rsaEncryption */) {
+ wpa_printf(MSG_DEBUG, "PKCS #8: Unsupported private key "
+ "algorithm %s", obuf);
+ return NULL;
+ }
+
+ pos = hdr.payload + hdr.length;
+
+ /* privateKey PrivateKey (PrivateKey ::= OCTET STRING) */
+ if (asn1_get_next(pos, end - pos, &hdr) < 0 ||
+ hdr.class != ASN1_CLASS_UNIVERSAL ||
+ hdr.tag != ASN1_TAG_OCTETSTRING) {
+ wpa_printf(MSG_DEBUG, "PKCS #8: Expected OCTETSTRING "
+ "(privateKey) - found class %d tag 0x%x",
+ hdr.class, hdr.tag);
+ return NULL;
+ }
+ wpa_printf(MSG_DEBUG, "PKCS #8: Try to parse RSAPrivateKey");
+
+ return (struct crypto_private_key *)
+ crypto_rsa_import_private_key(hdr.payload, hdr.length);
+}
+
+
+struct crypto_private_key *
+pkcs8_enc_key_import(const u8 *buf, size_t len, const char *passwd)
+{
+ struct asn1_hdr hdr;
+ const u8 *pos, *end, *enc_alg;
+ size_t enc_alg_len;
+ u8 *data;
+ size_t data_len;
+
+ if (passwd == NULL)
+ return NULL;
+
+ /*
+ * PKCS #8, Chapter 7
+ * EncryptedPrivateKeyInfo ::= SEQUENCE {
+ * encryptionAlgorithm EncryptionAlgorithmIdentifier,
+ * encryptedData EncryptedData }
+ * EncryptionAlgorithmIdentifier ::= AlgorithmIdentifier
+ * EncryptedData ::= OCTET STRING
+ */
+
+ if (asn1_get_next(buf, len, &hdr) < 0 ||
+ hdr.class != ASN1_CLASS_UNIVERSAL ||
+ hdr.tag != ASN1_TAG_SEQUENCE) {
+ wpa_printf(MSG_DEBUG, "PKCS #8: Does not start with PKCS #8 "
+ "header (SEQUENCE); assume encrypted PKCS #8 not "
+ "used");
+ return NULL;
+ }
+ pos = hdr.payload;
+ end = pos + hdr.length;
+
+ /* encryptionAlgorithm EncryptionAlgorithmIdentifier */
+ if (asn1_get_next(pos, end - pos, &hdr) < 0 ||
+ hdr.class != ASN1_CLASS_UNIVERSAL ||
+ hdr.tag != ASN1_TAG_SEQUENCE) {
+ wpa_printf(MSG_DEBUG, "PKCS #8: Expected SEQUENCE "
+ "(AlgorithmIdentifier) - found class %d tag 0x%x; "
+ "assume encrypted PKCS #8 not used",
+ hdr.class, hdr.tag);
+ return NULL;
+ }
+ enc_alg = hdr.payload;
+ enc_alg_len = hdr.length;
+ pos = hdr.payload + hdr.length;
+
+ /* encryptedData EncryptedData */
+ if (asn1_get_next(pos, end - pos, &hdr) < 0 ||
+ hdr.class != ASN1_CLASS_UNIVERSAL ||
+ hdr.tag != ASN1_TAG_OCTETSTRING) {
+ wpa_printf(MSG_DEBUG, "PKCS #8: Expected OCTETSTRING "
+ "(encryptedData) - found class %d tag 0x%x",
+ hdr.class, hdr.tag);
+ return NULL;
+ }
+
+ data = pkcs5_decrypt(enc_alg, enc_alg_len, hdr.payload, hdr.length,
+ passwd, &data_len);
+ if (data) {
+ struct crypto_private_key *key;
+ key = pkcs8_key_import(data, data_len);
+ os_free(data);
+ return key;
+ }
+
+ return NULL;
+}
diff --git a/contrib/wpa/src/tls/pkcs8.h b/contrib/wpa/src/tls/pkcs8.h
new file mode 100644
index 0000000..dac517c
--- /dev/null
+++ b/contrib/wpa/src/tls/pkcs8.h
@@ -0,0 +1,22 @@
+/*
+ * PKCS #8 (Private-key information syntax)
+ * Copyright (c) 2006-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef PKCS8_H
+#define PKCS8_H
+
+struct crypto_private_key * pkcs8_key_import(const u8 *buf, size_t len);
+struct crypto_private_key *
+pkcs8_enc_key_import(const u8 *buf, size_t len, const char *passwd);
+
+#endif /* PKCS8_H */
diff --git a/contrib/wpa/src/tls/rsa.c b/contrib/wpa/src/tls/rsa.c
index 4965a2a..3084adc 100644
--- a/contrib/wpa/src/tls/rsa.c
+++ b/contrib/wpa/src/tls/rsa.c
@@ -15,7 +15,6 @@
#include "includes.h"
#include "common.h"
-#include "crypto.h"
#include "asn1.h"
#include "bignum.h"
#include "rsa.h"
@@ -35,7 +34,6 @@ struct crypto_rsa_key {
};
-#ifdef EAP_TLS_FUNCS
static const u8 * crypto_rsa_parse_integer(const u8 *pos, const u8 *end,
struct bignum *num)
{
@@ -224,7 +222,6 @@ error:
crypto_rsa_free(key);
return NULL;
}
-#endif /* EAP_TLS_FUNCS */
/**
diff --git a/contrib/wpa/src/tls/tlsv1_client.c b/contrib/wpa/src/tls/tlsv1_client.c
index 0bf1174..afb6031 100644
--- a/contrib/wpa/src/tls/tlsv1_client.c
+++ b/contrib/wpa/src/tls/tlsv1_client.c
@@ -15,8 +15,8 @@
#include "includes.h"
#include "common.h"
-#include "sha1.h"
-#include "tls.h"
+#include "crypto/sha1.h"
+#include "crypto/tls.h"
#include "tlsv1_common.h"
#include "tlsv1_record.h"
#include "tlsv1_client.h"
@@ -605,7 +605,6 @@ int tlsv1_client_get_keyblock_size(struct tlsv1_client *conn)
*/
int tlsv1_client_set_cipher_list(struct tlsv1_client *conn, u8 *ciphers)
{
-#ifdef EAP_FAST
size_t count;
u16 *suites;
@@ -635,9 +634,6 @@ int tlsv1_client_set_cipher_list(struct tlsv1_client *conn, u8 *ciphers)
}
return 0;
-#else /* EAP_FAST */
- return -1;
-#endif /* EAP_FAST */
}
diff --git a/contrib/wpa/src/tls/tlsv1_client_read.c b/contrib/wpa/src/tls/tlsv1_client_read.c
index ee20330..ed3f260 100644
--- a/contrib/wpa/src/tls/tlsv1_client_read.c
+++ b/contrib/wpa/src/tls/tlsv1_client_read.c
@@ -15,10 +15,10 @@
#include "includes.h"
#include "common.h"
-#include "md5.h"
-#include "sha1.h"
+#include "crypto/md5.h"
+#include "crypto/sha1.h"
+#include "crypto/tls.h"
#include "x509v3.h"
-#include "tls.h"
#include "tlsv1_common.h"
#include "tlsv1_record.h"
#include "tlsv1_client.h"
diff --git a/contrib/wpa/src/tls/tlsv1_client_write.c b/contrib/wpa/src/tls/tlsv1_client_write.c
index e0c95cb..b47425f 100644
--- a/contrib/wpa/src/tls/tlsv1_client_write.c
+++ b/contrib/wpa/src/tls/tlsv1_client_write.c
@@ -15,10 +15,10 @@
#include "includes.h"
#include "common.h"
-#include "md5.h"
-#include "sha1.h"
+#include "crypto/md5.h"
+#include "crypto/sha1.h"
+#include "crypto/tls.h"
#include "x509v3.h"
-#include "tls.h"
#include "tlsv1_common.h"
#include "tlsv1_record.h"
#include "tlsv1_client.h"
@@ -209,7 +209,6 @@ static int tls_write_client_certificate(struct tlsv1_client *conn,
static int tlsv1_key_x_anon_dh(struct tlsv1_client *conn, u8 **pos, u8 *end)
{
-#ifdef EAP_FAST
/* ClientDiffieHellmanPublic */
u8 *csecret, *csecret_start, *dh_yc, *shared;
size_t csecret_len, dh_yc_len, shared_len;
@@ -321,10 +320,6 @@ static int tlsv1_key_x_anon_dh(struct tlsv1_client *conn, u8 **pos, u8 *end)
os_free(shared);
tlsv1_client_free_dh(conn);
return 0;
-#else /* EAP_FAST */
- tls_alert(conn, TLS_ALERT_LEVEL_FATAL, TLS_ALERT_INTERNAL_ERROR);
- return -1;
-#endif /* EAP_FAST */
}
diff --git a/contrib/wpa/src/tls/tlsv1_common.h b/contrib/wpa/src/tls/tlsv1_common.h
index 7750564..763a4af 100644
--- a/contrib/wpa/src/tls/tlsv1_common.h
+++ b/contrib/wpa/src/tls/tlsv1_common.h
@@ -15,7 +15,7 @@
#ifndef TLSV1_COMMON_H
#define TLSV1_COMMON_H
-#include "crypto.h"
+#include "crypto/crypto.h"
#define TLS_VERSION 0x0301 /* TLSv1 */
#define TLS_RANDOM_LEN 32
diff --git a/contrib/wpa/src/tls/tlsv1_cred.c b/contrib/wpa/src/tls/tlsv1_cred.c
index d5564672..aa467ef 100644
--- a/contrib/wpa/src/tls/tlsv1_cred.c
+++ b/contrib/wpa/src/tls/tlsv1_cred.c
@@ -1,6 +1,6 @@
/*
* TLSv1 credentials
- * Copyright (c) 2006-2007, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2006-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -16,7 +16,7 @@
#include "common.h"
#include "base64.h"
-#include "crypto.h"
+#include "crypto/crypto.h"
#include "x509v3.h"
#include "tlsv1_cred.h"
@@ -68,6 +68,12 @@ static int tlsv1_add_cert_der(struct x509_certificate **chain,
static const char *pem_cert_begin = "-----BEGIN CERTIFICATE-----";
static const char *pem_cert_end = "-----END CERTIFICATE-----";
+static const char *pem_key_begin = "-----BEGIN RSA PRIVATE KEY-----";
+static const char *pem_key_end = "-----END RSA PRIVATE KEY-----";
+static const char *pem_key2_begin = "-----BEGIN PRIVATE KEY-----";
+static const char *pem_key2_end = "-----END PRIVATE KEY-----";
+static const char *pem_key_enc_begin = "-----BEGIN ENCRYPTED PRIVATE KEY-----";
+static const char *pem_key_enc_end = "-----END ENCRYPTED PRIVATE KEY-----";
static const u8 * search_tag(const char *tag, const u8 *buf, size_t len)
@@ -209,10 +215,74 @@ int tlsv1_set_cert(struct tlsv1_credentials *cred, const char *cert,
}
+static struct crypto_private_key * tlsv1_set_key_pem(const u8 *key, size_t len)
+{
+ const u8 *pos, *end;
+ unsigned char *der;
+ size_t der_len;
+ struct crypto_private_key *pkey;
+
+ pos = search_tag(pem_key_begin, key, len);
+ if (!pos) {
+ pos = search_tag(pem_key2_begin, key, len);
+ if (!pos)
+ return NULL;
+ pos += os_strlen(pem_key2_begin);
+ end = search_tag(pem_key2_end, pos, key + len - pos);
+ if (!end)
+ return NULL;
+ } else {
+ pos += os_strlen(pem_key_begin);
+ end = search_tag(pem_key_end, pos, key + len - pos);
+ if (!end)
+ return NULL;
+ }
+
+ der = base64_decode(pos, end - pos, &der_len);
+ if (!der)
+ return NULL;
+ pkey = crypto_private_key_import(der, der_len, NULL);
+ os_free(der);
+ return pkey;
+}
+
+
+static struct crypto_private_key * tlsv1_set_key_enc_pem(const u8 *key,
+ size_t len,
+ const char *passwd)
+{
+ const u8 *pos, *end;
+ unsigned char *der;
+ size_t der_len;
+ struct crypto_private_key *pkey;
+
+ if (passwd == NULL)
+ return NULL;
+ pos = search_tag(pem_key_enc_begin, key, len);
+ if (!pos)
+ return NULL;
+ pos += os_strlen(pem_key_enc_begin);
+ end = search_tag(pem_key_enc_end, pos, key + len - pos);
+ if (!end)
+ return NULL;
+
+ der = base64_decode(pos, end - pos, &der_len);
+ if (!der)
+ return NULL;
+ pkey = crypto_private_key_import(der, der_len, passwd);
+ os_free(der);
+ return pkey;
+}
+
+
static int tlsv1_set_key(struct tlsv1_credentials *cred,
- const u8 *key, size_t len)
+ const u8 *key, size_t len, const char *passwd)
{
- cred->key = crypto_private_key_import(key, len);
+ cred->key = crypto_private_key_import(key, len, passwd);
+ if (cred->key == NULL)
+ cred->key = tlsv1_set_key_pem(key, len);
+ if (cred->key == NULL)
+ cred->key = tlsv1_set_key_enc_pem(key, len, passwd);
if (cred->key == NULL) {
wpa_printf(MSG_INFO, "TLSv1: Failed to parse private key");
return -1;
@@ -242,7 +312,8 @@ int tlsv1_set_private_key(struct tlsv1_credentials *cred,
if (private_key_blob)
return tlsv1_set_key(cred, private_key_blob,
- private_key_blob_len);
+ private_key_blob_len,
+ private_key_passwd);
if (private_key) {
u8 *buf;
@@ -256,7 +327,7 @@ int tlsv1_set_private_key(struct tlsv1_credentials *cred,
return -1;
}
- ret = tlsv1_set_key(cred, buf, len);
+ ret = tlsv1_set_key(cred, buf, len, private_key_passwd);
os_free(buf);
return ret;
}
diff --git a/contrib/wpa/src/tls/tlsv1_record.c b/contrib/wpa/src/tls/tlsv1_record.c
index f226ac3..e811f0e 100644
--- a/contrib/wpa/src/tls/tlsv1_record.c
+++ b/contrib/wpa/src/tls/tlsv1_record.c
@@ -15,8 +15,8 @@
#include "includes.h"
#include "common.h"
-#include "md5.h"
-#include "sha1.h"
+#include "crypto/md5.h"
+#include "crypto/sha1.h"
#include "tlsv1_common.h"
#include "tlsv1_record.h"
diff --git a/contrib/wpa/src/tls/tlsv1_record.h b/contrib/wpa/src/tls/tlsv1_record.h
index 9170fb1..9c7c0a4 100644
--- a/contrib/wpa/src/tls/tlsv1_record.h
+++ b/contrib/wpa/src/tls/tlsv1_record.h
@@ -15,7 +15,7 @@
#ifndef TLSV1_RECORD_H
#define TLSV1_RECORD_H
-#include "crypto.h"
+#include "crypto/crypto.h"
#define TLS_MAX_WRITE_MAC_SECRET_LEN 20
#define TLS_MAX_WRITE_KEY_LEN 32
diff --git a/contrib/wpa/src/tls/tlsv1_server.c b/contrib/wpa/src/tls/tlsv1_server.c
index c204a47..6a61235 100644
--- a/contrib/wpa/src/tls/tlsv1_server.c
+++ b/contrib/wpa/src/tls/tlsv1_server.c
@@ -15,8 +15,8 @@
#include "includes.h"
#include "common.h"
-#include "sha1.h"
-#include "tls.h"
+#include "crypto/sha1.h"
+#include "crypto/tls.h"
#include "tlsv1_common.h"
#include "tlsv1_record.h"
#include "tlsv1_server.h"
@@ -546,7 +546,6 @@ int tlsv1_server_get_keyblock_size(struct tlsv1_server *conn)
*/
int tlsv1_server_set_cipher_list(struct tlsv1_server *conn, u8 *ciphers)
{
-#ifdef EAP_FAST
size_t count;
u16 *suites;
@@ -572,9 +571,6 @@ int tlsv1_server_set_cipher_list(struct tlsv1_server *conn, u8 *ciphers)
}
return 0;
-#else /* EAP_FAST */
- return -1;
-#endif /* EAP_FAST */
}
diff --git a/contrib/wpa/src/tls/tlsv1_server_read.c b/contrib/wpa/src/tls/tlsv1_server_read.c
index 397d74a..49e811f 100644
--- a/contrib/wpa/src/tls/tlsv1_server_read.c
+++ b/contrib/wpa/src/tls/tlsv1_server_read.c
@@ -15,10 +15,10 @@
#include "includes.h"
#include "common.h"
-#include "md5.h"
-#include "sha1.h"
+#include "crypto/md5.h"
+#include "crypto/sha1.h"
+#include "crypto/tls.h"
#include "x509v3.h"
-#include "tls.h"
#include "tlsv1_common.h"
#include "tlsv1_record.h"
#include "tlsv1_server.h"
@@ -567,7 +567,6 @@ static int tls_process_client_key_exchange_rsa(
static int tls_process_client_key_exchange_dh_anon(
struct tlsv1_server *conn, const u8 *pos, const u8 *end)
{
-#ifdef EAP_FAST
const u8 *dh_yc;
u16 dh_yc_len;
u8 *shared;
@@ -665,9 +664,6 @@ static int tls_process_client_key_exchange_dh_anon(
}
return 0;
-#else /* EAP_FAST */
- return -1;
-#endif /* EAP_FAST */
}
diff --git a/contrib/wpa/src/tls/tlsv1_server_write.c b/contrib/wpa/src/tls/tlsv1_server_write.c
index cf54f42..6d1df7f 100644
--- a/contrib/wpa/src/tls/tlsv1_server_write.c
+++ b/contrib/wpa/src/tls/tlsv1_server_write.c
@@ -15,10 +15,10 @@
#include "includes.h"
#include "common.h"
-#include "md5.h"
-#include "sha1.h"
+#include "crypto/md5.h"
+#include "crypto/sha1.h"
+#include "crypto/tls.h"
#include "x509v3.h"
-#include "tls.h"
#include "tlsv1_common.h"
#include "tlsv1_record.h"
#include "tlsv1_server.h"
@@ -247,12 +247,10 @@ static int tls_write_server_key_exchange(struct tlsv1_server *conn,
{
tls_key_exchange keyx;
const struct tls_cipher_suite *suite;
-#ifdef EAP_FAST
u8 *pos, *rhdr, *hs_start, *hs_length;
size_t rlen;
u8 *dh_ys;
size_t dh_ys_len;
-#endif /* EAP_FAST */
suite = tls_get_cipher_suite(conn->rl.cipher_suite);
if (suite == NULL)
@@ -272,7 +270,6 @@ static int tls_write_server_key_exchange(struct tlsv1_server *conn,
return -1;
}
-#ifdef EAP_FAST
if (conn->cred == NULL || conn->cred->dh_p == NULL ||
conn->cred->dh_g == NULL) {
wpa_printf(MSG_DEBUG, "TLSv1: No DH parameters available for "
@@ -433,9 +430,6 @@ static int tls_write_server_key_exchange(struct tlsv1_server *conn,
*msgpos = pos;
return 0;
-#else /* EAP_FAST */
- return -1;
-#endif /* EAP_FAST */
}
diff --git a/contrib/wpa/src/tls/x509v3.c b/contrib/wpa/src/tls/x509v3.c
index 59bf4ff..bc93df6 100644
--- a/contrib/wpa/src/tls/x509v3.c
+++ b/contrib/wpa/src/tls/x509v3.c
@@ -15,25 +15,32 @@
#include "includes.h"
#include "common.h"
-
-#ifdef CONFIG_INTERNAL_X509
-
+#include "crypto/crypto.h"
#include "asn1.h"
-#include "crypto.h"
#include "x509v3.h"
static void x509_free_name(struct x509_name *name)
{
- os_free(name->cn);
- os_free(name->c);
- os_free(name->l);
- os_free(name->st);
- os_free(name->o);
- os_free(name->ou);
+ size_t i;
+
+ for (i = 0; i < name->num_attr; i++) {
+ os_free(name->attr[i].value);
+ name->attr[i].value = NULL;
+ name->attr[i].type = X509_NAME_ATTR_NOT_USED;
+ }
+ name->num_attr = 0;
os_free(name->email);
- name->cn = name->c = name->l = name->st = name->o = name->ou = NULL;
name->email = NULL;
+
+ os_free(name->alt_email);
+ os_free(name->dns);
+ os_free(name->uri);
+ os_free(name->ip);
+ name->alt_email = name->dns = name->uri = NULL;
+ name->ip = NULL;
+ name->ip_len = 0;
+ os_memset(&name->rid, 0, sizeof(name->rid));
}
@@ -146,6 +153,7 @@ static int x509_str_compare(const char *a, const char *b)
int x509_name_compare(struct x509_name *a, struct x509_name *b)
{
int res;
+ size_t i;
if (!a && b)
return -1;
@@ -153,25 +161,20 @@ int x509_name_compare(struct x509_name *a, struct x509_name *b)
return 1;
if (!a && !b)
return 0;
+ if (a->num_attr < b->num_attr)
+ return -1;
+ if (a->num_attr > b->num_attr)
+ return 1;
- res = x509_str_compare(a->cn, b->cn);
- if (res)
- return res;
- res = x509_str_compare(a->c, b->c);
- if (res)
- return res;
- res = x509_str_compare(a->l, b->l);
- if (res)
- return res;
- res = x509_str_compare(a->st, b->st);
- if (res)
- return res;
- res = x509_str_compare(a->o, b->o);
- if (res)
- return res;
- res = x509_str_compare(a->ou, b->ou);
- if (res)
- return res;
+ for (i = 0; i < a->num_attr; i++) {
+ if (a->attr[i].type < b->attr[i].type)
+ return -1;
+ if (a->attr[i].type > b->attr[i].type)
+ return -1;
+ res = x509_str_compare(a->attr[i].value, b->attr[i].value);
+ if (res)
+ return res;
+ }
res = x509_str_compare(a->email, b->email);
if (res)
return res;
@@ -298,7 +301,7 @@ static int x509_parse_name(const u8 *buf, size_t len, struct x509_name *name,
struct asn1_hdr hdr;
const u8 *pos, *end, *set_pos, *set_end, *seq_pos, *seq_end;
struct asn1_oid oid;
- char **fieldp;
+ char *val;
/*
* Name ::= CHOICE { RDNSequence }
@@ -328,6 +331,8 @@ static int x509_parse_name(const u8 *buf, size_t len, struct x509_name *name,
end = *next = pos + hdr.length;
while (pos < end) {
+ enum x509_name_attr_type type;
+
if (asn1_get_next(pos, end - pos, &hdr) < 0 ||
hdr.class != ASN1_CLASS_UNIVERSAL ||
hdr.tag != ASN1_TAG_SET) {
@@ -375,34 +380,34 @@ static int x509_parse_name(const u8 *buf, size_t len, struct x509_name *name,
* pseudonym, generation qualifier.
* MUST: domainComponent (RFC 2247).
*/
- fieldp = NULL;
+ type = X509_NAME_ATTR_NOT_USED;
if (oid.len == 4 &&
oid.oid[0] == 2 && oid.oid[1] == 5 && oid.oid[2] == 4) {
/* id-at ::= 2.5.4 */
switch (oid.oid[3]) {
case 3:
/* commonName */
- fieldp = &name->cn;
+ type = X509_NAME_ATTR_CN;
break;
case 6:
/* countryName */
- fieldp = &name->c;
+ type = X509_NAME_ATTR_C;
break;
case 7:
/* localityName */
- fieldp = &name->l;
+ type = X509_NAME_ATTR_L;
break;
case 8:
/* stateOrProvinceName */
- fieldp = &name->st;
+ type = X509_NAME_ATTR_ST;
break;
case 10:
/* organizationName */
- fieldp = &name->o;
+ type = X509_NAME_ATTR_O;
break;
case 11:
/* organizationalUnitName */
- fieldp = &name->ou;
+ type = X509_NAME_ATTR_OU;
break;
}
} else if (oid.len == 7 &&
@@ -411,10 +416,25 @@ static int x509_parse_name(const u8 *buf, size_t len, struct x509_name *name,
oid.oid[4] == 1 && oid.oid[5] == 9 &&
oid.oid[6] == 1) {
/* 1.2.840.113549.1.9.1 - e-mailAddress */
- fieldp = &name->email;
+ os_free(name->email);
+ name->email = os_malloc(hdr.length + 1);
+ if (name->email == NULL) {
+ x509_free_name(name);
+ return -1;
+ }
+ os_memcpy(name->email, hdr.payload, hdr.length);
+ name->email[hdr.length] = '\0';
+ continue;
+ } else if (oid.len == 7 &&
+ oid.oid[0] == 0 && oid.oid[1] == 9 &&
+ oid.oid[2] == 2342 && oid.oid[3] == 19200300 &&
+ oid.oid[4] == 100 && oid.oid[5] == 1 &&
+ oid.oid[6] == 25) {
+ /* 0.9.2342.19200300.100.1.25 - domainComponent */
+ type = X509_NAME_ATTR_DC;
}
- if (fieldp == NULL) {
+ if (type == X509_NAME_ATTR_NOT_USED) {
wpa_hexdump(MSG_DEBUG, "X509: Unrecognized OID",
(u8 *) oid.oid,
oid.len * sizeof(oid.oid[0]));
@@ -423,20 +443,60 @@ static int x509_parse_name(const u8 *buf, size_t len, struct x509_name *name,
continue;
}
- os_free(*fieldp);
- *fieldp = os_malloc(hdr.length + 1);
- if (*fieldp == NULL) {
+ if (name->num_attr == X509_MAX_NAME_ATTRIBUTES) {
+ wpa_printf(MSG_INFO, "X509: Too many Name attributes");
+ x509_free_name(name);
+ return -1;
+ }
+
+ val = os_malloc(hdr.length + 1);
+ if (val == NULL) {
x509_free_name(name);
return -1;
}
- os_memcpy(*fieldp, hdr.payload, hdr.length);
- (*fieldp)[hdr.length] = '\0';
+ os_memcpy(val, hdr.payload, hdr.length);
+ val[hdr.length] = '\0';
+ if (os_strlen(val) != hdr.length) {
+ wpa_printf(MSG_INFO, "X509: Reject certificate with "
+ "embedded NUL byte in a string (%s[NUL])",
+ val);
+ x509_free_name(name);
+ return -1;
+ }
+
+ name->attr[name->num_attr].type = type;
+ name->attr[name->num_attr].value = val;
+ name->num_attr++;
}
return 0;
}
+static char * x509_name_attr_str(enum x509_name_attr_type type)
+{
+ switch (type) {
+ case X509_NAME_ATTR_NOT_USED:
+ return "[N/A]";
+ case X509_NAME_ATTR_DC:
+ return "DC";
+ case X509_NAME_ATTR_CN:
+ return "CN";
+ case X509_NAME_ATTR_C:
+ return "C";
+ case X509_NAME_ATTR_L:
+ return "L";
+ case X509_NAME_ATTR_ST:
+ return "ST";
+ case X509_NAME_ATTR_O:
+ return "O";
+ case X509_NAME_ATTR_OU:
+ return "OU";
+ }
+ return "?";
+}
+
+
/**
* x509_name_string - Convert an X.509 certificate name into a string
* @name: Name to convert
@@ -447,6 +507,7 @@ void x509_name_string(struct x509_name *name, char *buf, size_t len)
{
char *pos, *end;
int ret;
+ size_t i;
if (len == 0)
return;
@@ -454,46 +515,20 @@ void x509_name_string(struct x509_name *name, char *buf, size_t len)
pos = buf;
end = buf + len;
- if (name->c) {
- ret = os_snprintf(pos, end - pos, "C=%s, ", name->c);
- if (ret < 0 || ret >= end - pos)
- goto done;
- pos += ret;
- }
- if (name->st) {
- ret = os_snprintf(pos, end - pos, "ST=%s, ", name->st);
- if (ret < 0 || ret >= end - pos)
- goto done;
- pos += ret;
- }
- if (name->l) {
- ret = os_snprintf(pos, end - pos, "L=%s, ", name->l);
- if (ret < 0 || ret >= end - pos)
- goto done;
- pos += ret;
- }
- if (name->o) {
- ret = os_snprintf(pos, end - pos, "O=%s, ", name->o);
- if (ret < 0 || ret >= end - pos)
- goto done;
- pos += ret;
- }
- if (name->ou) {
- ret = os_snprintf(pos, end - pos, "OU=%s, ", name->ou);
- if (ret < 0 || ret >= end - pos)
- goto done;
- pos += ret;
- }
- if (name->cn) {
- ret = os_snprintf(pos, end - pos, "CN=%s, ", name->cn);
+ for (i = 0; i < name->num_attr; i++) {
+ ret = os_snprintf(pos, end - pos, "%s=%s, ",
+ x509_name_attr_str(name->attr[i].type),
+ name->attr[i].value);
if (ret < 0 || ret >= end - pos)
goto done;
pos += ret;
}
if (pos > buf + 1 && pos[-1] == ' ' && pos[-2] == ',') {
- *pos-- = '\0';
- *pos-- = '\0';
+ pos--;
+ *pos = '\0';
+ pos--;
+ *pos = '\0';
}
if (name->email) {
@@ -815,6 +850,237 @@ static int x509_parse_ext_basic_constraints(struct x509_certificate *cert,
}
+static int x509_parse_alt_name_rfc8222(struct x509_name *name,
+ const u8 *pos, size_t len)
+{
+ /* rfc822Name IA5String */
+ wpa_hexdump_ascii(MSG_MSGDUMP, "X509: altName - rfc822Name", pos, len);
+ os_free(name->alt_email);
+ name->alt_email = os_zalloc(len + 1);
+ if (name->alt_email == NULL)
+ return -1;
+ os_memcpy(name->alt_email, pos, len);
+ if (os_strlen(name->alt_email) != len) {
+ wpa_printf(MSG_INFO, "X509: Reject certificate with "
+ "embedded NUL byte in rfc822Name (%s[NUL])",
+ name->alt_email);
+ os_free(name->alt_email);
+ name->alt_email = NULL;
+ return -1;
+ }
+ return 0;
+}
+
+
+static int x509_parse_alt_name_dns(struct x509_name *name,
+ const u8 *pos, size_t len)
+{
+ /* dNSName IA5String */
+ wpa_hexdump_ascii(MSG_MSGDUMP, "X509: altName - dNSName", pos, len);
+ os_free(name->dns);
+ name->dns = os_zalloc(len + 1);
+ if (name->dns == NULL)
+ return -1;
+ os_memcpy(name->dns, pos, len);
+ if (os_strlen(name->dns) != len) {
+ wpa_printf(MSG_INFO, "X509: Reject certificate with "
+ "embedded NUL byte in dNSName (%s[NUL])",
+ name->dns);
+ os_free(name->dns);
+ name->dns = NULL;
+ return -1;
+ }
+ return 0;
+}
+
+
+static int x509_parse_alt_name_uri(struct x509_name *name,
+ const u8 *pos, size_t len)
+{
+ /* uniformResourceIdentifier IA5String */
+ wpa_hexdump_ascii(MSG_MSGDUMP,
+ "X509: altName - uniformResourceIdentifier",
+ pos, len);
+ os_free(name->uri);
+ name->uri = os_zalloc(len + 1);
+ if (name->uri == NULL)
+ return -1;
+ os_memcpy(name->uri, pos, len);
+ if (os_strlen(name->uri) != len) {
+ wpa_printf(MSG_INFO, "X509: Reject certificate with "
+ "embedded NUL byte in uniformResourceIdentifier "
+ "(%s[NUL])", name->uri);
+ os_free(name->uri);
+ name->uri = NULL;
+ return -1;
+ }
+ return 0;
+}
+
+
+static int x509_parse_alt_name_ip(struct x509_name *name,
+ const u8 *pos, size_t len)
+{
+ /* iPAddress OCTET STRING */
+ wpa_hexdump(MSG_MSGDUMP, "X509: altName - iPAddress", pos, len);
+ os_free(name->ip);
+ name->ip = os_malloc(len);
+ if (name->ip == NULL)
+ return -1;
+ os_memcpy(name->ip, pos, len);
+ name->ip_len = len;
+ return 0;
+}
+
+
+static int x509_parse_alt_name_rid(struct x509_name *name,
+ const u8 *pos, size_t len)
+{
+ char buf[80];
+
+ /* registeredID OBJECT IDENTIFIER */
+ if (asn1_parse_oid(pos, len, &name->rid) < 0)
+ return -1;
+
+ asn1_oid_to_str(&name->rid, buf, sizeof(buf));
+ wpa_printf(MSG_MSGDUMP, "X509: altName - registeredID: %s", buf);
+
+ return 0;
+}
+
+
+static int x509_parse_ext_alt_name(struct x509_name *name,
+ const u8 *pos, size_t len)
+{
+ struct asn1_hdr hdr;
+ const u8 *p, *end;
+
+ /*
+ * GeneralNames ::= SEQUENCE SIZE (1..MAX) OF GeneralName
+ *
+ * GeneralName ::= CHOICE {
+ * otherName [0] OtherName,
+ * rfc822Name [1] IA5String,
+ * dNSName [2] IA5String,
+ * x400Address [3] ORAddress,
+ * directoryName [4] Name,
+ * ediPartyName [5] EDIPartyName,
+ * uniformResourceIdentifier [6] IA5String,
+ * iPAddress [7] OCTET STRING,
+ * registeredID [8] OBJECT IDENTIFIER }
+ *
+ * OtherName ::= SEQUENCE {
+ * type-id OBJECT IDENTIFIER,
+ * value [0] EXPLICIT ANY DEFINED BY type-id }
+ *
+ * EDIPartyName ::= SEQUENCE {
+ * nameAssigner [0] DirectoryString OPTIONAL,
+ * partyName [1] DirectoryString }
+ */
+
+ for (p = pos, end = pos + len; p < end; p = hdr.payload + hdr.length) {
+ int res;
+
+ if (asn1_get_next(p, end - p, &hdr) < 0) {
+ wpa_printf(MSG_DEBUG, "X509: Failed to parse "
+ "SubjectAltName item");
+ return -1;
+ }
+
+ if (hdr.class != ASN1_CLASS_CONTEXT_SPECIFIC)
+ continue;
+
+ switch (hdr.tag) {
+ case 1:
+ res = x509_parse_alt_name_rfc8222(name, hdr.payload,
+ hdr.length);
+ break;
+ case 2:
+ res = x509_parse_alt_name_dns(name, hdr.payload,
+ hdr.length);
+ break;
+ case 6:
+ res = x509_parse_alt_name_uri(name, hdr.payload,
+ hdr.length);
+ break;
+ case 7:
+ res = x509_parse_alt_name_ip(name, hdr.payload,
+ hdr.length);
+ break;
+ case 8:
+ res = x509_parse_alt_name_rid(name, hdr.payload,
+ hdr.length);
+ break;
+ case 0: /* TODO: otherName */
+ case 3: /* TODO: x500Address */
+ case 4: /* TODO: directoryName */
+ case 5: /* TODO: ediPartyName */
+ default:
+ res = 0;
+ break;
+ }
+ if (res < 0)
+ return res;
+ }
+
+ return 0;
+}
+
+
+static int x509_parse_ext_subject_alt_name(struct x509_certificate *cert,
+ const u8 *pos, size_t len)
+{
+ struct asn1_hdr hdr;
+
+ /* SubjectAltName ::= GeneralNames */
+
+ if (asn1_get_next(pos, len, &hdr) < 0 ||
+ hdr.class != ASN1_CLASS_UNIVERSAL ||
+ hdr.tag != ASN1_TAG_SEQUENCE) {
+ wpa_printf(MSG_DEBUG, "X509: Expected SEQUENCE in "
+ "SubjectAltName; found %d tag 0x%x",
+ hdr.class, hdr.tag);
+ return -1;
+ }
+
+ wpa_printf(MSG_DEBUG, "X509: SubjectAltName");
+ cert->extensions_present |= X509_EXT_SUBJECT_ALT_NAME;
+
+ if (hdr.length == 0)
+ return 0;
+
+ return x509_parse_ext_alt_name(&cert->subject, hdr.payload,
+ hdr.length);
+}
+
+
+static int x509_parse_ext_issuer_alt_name(struct x509_certificate *cert,
+ const u8 *pos, size_t len)
+{
+ struct asn1_hdr hdr;
+
+ /* IssuerAltName ::= GeneralNames */
+
+ if (asn1_get_next(pos, len, &hdr) < 0 ||
+ hdr.class != ASN1_CLASS_UNIVERSAL ||
+ hdr.tag != ASN1_TAG_SEQUENCE) {
+ wpa_printf(MSG_DEBUG, "X509: Expected SEQUENCE in "
+ "IssuerAltName; found %d tag 0x%x",
+ hdr.class, hdr.tag);
+ return -1;
+ }
+
+ wpa_printf(MSG_DEBUG, "X509: IssuerAltName");
+ cert->extensions_present |= X509_EXT_ISSUER_ALT_NAME;
+
+ if (hdr.length == 0)
+ return 0;
+
+ return x509_parse_ext_alt_name(&cert->issuer, hdr.payload,
+ hdr.length);
+}
+
+
static int x509_parse_extension_data(struct x509_certificate *cert,
struct asn1_oid *oid,
const u8 *pos, size_t len)
@@ -824,7 +1090,6 @@ static int x509_parse_extension_data(struct x509_certificate *cert,
/* TODO: add other extensions required by RFC 3280, Ch 4.2:
* certificate policies (section 4.2.1.5)
- * the subject alternative name (section 4.2.1.7)
* name constraints (section 4.2.1.11)
* policy constraints (section 4.2.1.12)
* extended key usage (section 4.2.1.13)
@@ -833,6 +1098,10 @@ static int x509_parse_extension_data(struct x509_certificate *cert,
switch (oid->oid[3]) {
case 15: /* id-ce-keyUsage */
return x509_parse_ext_key_usage(cert, pos, len);
+ case 17: /* id-ce-subjectAltName */
+ return x509_parse_ext_subject_alt_name(cert, pos, len);
+ case 18: /* id-ce-issuerAltName */
+ return x509_parse_ext_issuer_alt_name(cert, pos, len);
case 19: /* id-ce-basicConstraints */
return x509_parse_ext_basic_constraints(cert, pos, len);
default:
@@ -1495,18 +1764,12 @@ skip_digest_oid:
hash, hash_len);
break;
case 11: /* sha256WithRSAEncryption */
-#ifdef NEED_SHA256
sha256_vector(1, &cert->tbs_cert_start, &cert->tbs_cert_len,
hash);
hash_len = 32;
wpa_hexdump(MSG_MSGDUMP, "X509: Certificate hash (SHA256)",
hash, hash_len);
break;
-#else /* NEED_SHA256 */
- wpa_printf(MSG_INFO, "X509: SHA256 support disabled");
- os_free(data);
- return -1;
-#endif /* NEED_SHA256 */
case 2: /* md2WithRSAEncryption */
case 12: /* sha384WithRSAEncryption */
case 13: /* sha512WithRSAEncryption */
@@ -1720,5 +1983,3 @@ int x509_certificate_self_signed(struct x509_certificate *cert)
{
return x509_name_compare(&cert->issuer, &cert->subject) == 0;
}
-
-#endif /* CONFIG_INTERNAL_X509 */
diff --git a/contrib/wpa/src/tls/x509v3.h b/contrib/wpa/src/tls/x509v3.h
index a52bcf8..37292d7 100644
--- a/contrib/wpa/src/tls/x509v3.h
+++ b/contrib/wpa/src/tls/x509v3.h
@@ -21,14 +21,34 @@ struct x509_algorithm_identifier {
struct asn1_oid oid;
};
+struct x509_name_attr {
+ enum x509_name_attr_type {
+ X509_NAME_ATTR_NOT_USED,
+ X509_NAME_ATTR_DC,
+ X509_NAME_ATTR_CN,
+ X509_NAME_ATTR_C,
+ X509_NAME_ATTR_L,
+ X509_NAME_ATTR_ST,
+ X509_NAME_ATTR_O,
+ X509_NAME_ATTR_OU
+ } type;
+ char *value;
+};
+
+#define X509_MAX_NAME_ATTRIBUTES 20
+
struct x509_name {
- char *cn; /* commonName */
- char *c; /* countryName */
- char *l; /* localityName */
- char *st; /* stateOrProvinceName */
- char *o; /* organizationName */
- char *ou; /* organizationalUnitName */
+ struct x509_name_attr attr[X509_MAX_NAME_ATTRIBUTES];
+ size_t num_attr;
char *email; /* emailAddress */
+
+ /* from alternative name extension */
+ char *alt_email; /* rfc822Name */
+ char *dns; /* dNSName */
+ char *uri; /* uniformResourceIdentifier */
+ u8 *ip; /* iPAddress */
+ size_t ip_len; /* IPv4: 4, IPv6: 16 */
+ struct asn1_oid rid; /* registeredID */
};
struct x509_certificate {
@@ -52,6 +72,8 @@ struct x509_certificate {
#define X509_EXT_BASIC_CONSTRAINTS (1 << 0)
#define X509_EXT_PATH_LEN_CONSTRAINT (1 << 1)
#define X509_EXT_KEY_USAGE (1 << 2)
+#define X509_EXT_SUBJECT_ALT_NAME (1 << 3)
+#define X509_EXT_ISSUER_ALT_NAME (1 << 4)
/* BasicConstraints */
int ca; /* cA */
@@ -89,8 +111,6 @@ enum {
X509_VALIDATE_UNKNOWN_CA
};
-#ifdef CONFIG_INTERNAL_X509
-
void x509_certificate_free(struct x509_certificate *cert);
struct x509_certificate * x509_certificate_parse(const u8 *buf, size_t len);
void x509_name_string(struct x509_name *name, char *buf, size_t len);
@@ -106,49 +126,4 @@ x509_certificate_get_subject(struct x509_certificate *chain,
struct x509_name *name);
int x509_certificate_self_signed(struct x509_certificate *cert);
-#else /* CONFIG_INTERNAL_X509 */
-
-static inline void x509_certificate_free(struct x509_certificate *cert)
-{
-}
-
-static inline struct x509_certificate *
-x509_certificate_parse(const u8 *buf, size_t len)
-{
- return NULL;
-}
-
-static inline void x509_name_string(struct x509_name *name, char *buf,
- size_t len)
-{
- if (len)
- buf[0] = '\0';
-}
-
-static inline void x509_certificate_chain_free(struct x509_certificate *cert)
-{
-}
-
-static inline int
-x509_certificate_chain_validate(struct x509_certificate *trusted,
- struct x509_certificate *chain,
- int *reason)
-{
- return -1;
-}
-
-static inline struct x509_certificate *
-x509_certificate_get_subject(struct x509_certificate *chain,
- struct x509_name *name)
-{
- return NULL;
-}
-
-static inline int x509_certificate_self_signed(struct x509_certificate *cert)
-{
- return -1;
-}
-
-#endif /* CONFIG_INTERNAL_X509 */
-
#endif /* X509V3_H */
diff --git a/contrib/wpa/src/utils/.gitignore b/contrib/wpa/src/utils/.gitignore
new file mode 100644
index 0000000..833734f
--- /dev/null
+++ b/contrib/wpa/src/utils/.gitignore
@@ -0,0 +1 @@
+libutils.a
diff --git a/contrib/wpa/src/utils/Makefile b/contrib/wpa/src/utils/Makefile
index cffba62..527cf3e 100644
--- a/contrib/wpa/src/utils/Makefile
+++ b/contrib/wpa/src/utils/Makefile
@@ -1,9 +1,36 @@
-all:
- @echo Nothing to be made.
+all: libutils.a
clean:
- for d in $(SUBDIRS); do make -C $$d clean; done
- rm -f *~ *.o *.d
+ rm -f *~ *.o *.d libutils.a
install:
@echo Nothing to be made.
+
+
+include ../lib.rules
+
+#CFLAGS += -DWPA_TRACE
+CFLAGS += -DCONFIG_IPV6
+
+LIB_OBJS= \
+ base64.o \
+ common.o \
+ ip_addr.o \
+ radiotap.o \
+ trace.o \
+ uuid.o \
+ wpa_debug.o \
+ wpabuf.o
+
+# Pick correct OS wrapper implementation
+LIB_OBJS += os_unix.o
+
+# Pick correct event loop implementation
+LIB_OBJS += eloop.o
+
+#LIB_OBJS += pcsc_funcs.o
+
+libutils.a: $(LIB_OBJS)
+ $(AR) crT $@ $?
+
+-include $(OBJS:%.o=%.d)
diff --git a/contrib/wpa/src/utils/base64.c b/contrib/wpa/src/utils/base64.c
index 13fc511..155bfce 100644
--- a/contrib/wpa/src/utils/base64.c
+++ b/contrib/wpa/src/utils/base64.c
@@ -152,38 +152,3 @@ unsigned char * base64_decode(const unsigned char *src, size_t len,
*out_len = pos - out;
return out;
}
-
-
-#ifdef TEST_MAIN
-
-int main(int argc, char *argv[])
-{
- FILE *f;
- size_t len, elen;
- unsigned char *buf, *e;
-
- if (argc != 4) {
- printf("Usage: base64 <encode|decode> <in file> <out file>\n");
- return -1;
- }
-
- buf = os_readfile(argv[2], &len);
- if (buf == NULL)
- return -1;
-
- if (strcmp(argv[1], "encode") == 0)
- e = base64_encode(buf, len, &elen);
- else
- e = base64_decode(buf, len, &elen);
- if (e == NULL)
- return -2;
- f = fopen(argv[3], "w");
- if (f == NULL)
- return -3;
- fwrite(e, 1, elen, f);
- fclose(f);
- free(e);
-
- return 0;
-}
-#endif /* TEST_MAIN */
diff --git a/contrib/wpa/src/utils/build_config.h b/contrib/wpa/src/utils/build_config.h
index 1e147fe..3666778 100644
--- a/contrib/wpa/src/utils/build_config.h
+++ b/contrib/wpa/src/utils/build_config.h
@@ -28,7 +28,6 @@
#define CONFIG_ANSI_C_EXTRA
#define CONFIG_WINPCAP
#define IEEE8021X_EAPOL
-#define EAP_TLS_FUNCS
#define PKCS12_FUNCS
#define PCSC_FUNCS
#define CONFIG_CTRL_IFACE
@@ -48,16 +47,8 @@
#define _CRT_SECURE_NO_DEPRECATE
#ifdef USE_INTERNAL_CRYPTO
-#define CONFIG_TLS_INTERNAL
#define CONFIG_TLS_INTERNAL_CLIENT
#define CONFIG_INTERNAL_LIBTOMMATH
-#define INTERNAL_AES
-#define INTERNAL_SHA1
-#define INTERNAL_SHA256
-#define INTERNAL_MD5
-#define INTERNAL_MD4
-#define INTERNAL_DES
-#define CONFIG_INTERNAL_X509
#define CONFIG_CRYPTO_INTERNAL
#endif /* USE_INTERNAL_CRYPTO */
#endif /* CONFIG_WIN32_DEFAULTS */
@@ -69,15 +60,7 @@
#define CONFIG_NO_HOSTAPD_LOGGER
#define CONFIG_NO_STDOUT_DEBUG
#define CONFIG_BACKEND_FILE
-#define INTERNAL_AES
-#define INTERNAL_SHA1
-#define INTERNAL_MD5
-#define INTERNAL_MD4
-#define INTERNAL_DES
#define CONFIG_INTERNAL_LIBTOMMATH
-#define CONFIG_INTERNAL_X509
-#define EAP_TLS_FUNCS
-#define CONFIG_TLS_INTERNAL
#define CONFIG_CRYPTO_INTERNAL
#define IEEE8021X_EAPOL
#define PKCS12_FUNCS
@@ -92,4 +75,31 @@
#define EAP_FAST
#endif /* __SYMBIAN32__ */
+#ifdef CONFIG_XCODE_DEFAULTS
+#define CONFIG_DRIVER_OSX
+#define CONFIG_BACKEND_FILE
+#define IEEE8021X_EAPOL
+#define PKCS12_FUNCS
+#define CONFIG_CTRL_IFACE
+#define CONFIG_CTRL_IFACE_UNIX
+#define CONFIG_DEBUG_FILE
+#define EAP_MD5
+#define EAP_TLS
+#define EAP_MSCHAPv2
+#define EAP_PEAP
+#define EAP_TTLS
+#define EAP_GTC
+#define EAP_OTP
+#define EAP_LEAP
+#define EAP_TNC
+#define CONFIG_WPS
+#define EAP_WSC
+
+#ifdef USE_INTERNAL_CRYPTO
+#define CONFIG_TLS_INTERNAL_CLIENT
+#define CONFIG_INTERNAL_LIBTOMMATH
+#define CONFIG_CRYPTO_INTERNAL
+#endif /* USE_INTERNAL_CRYPTO */
+#endif /* CONFIG_XCODE_DEFAULTS */
+
#endif /* BUILD_CONFIG_H */
diff --git a/contrib/wpa/src/utils/common.c b/contrib/wpa/src/utils/common.c
index 9a46ebe..1b8ea80 100644
--- a/contrib/wpa/src/utils/common.c
+++ b/contrib/wpa/src/utils/common.c
@@ -43,7 +43,7 @@ static int hex2byte(const char *hex)
/**
- * hwaddr_aton - Convert ASCII string to MAC address
+ * hwaddr_aton - Convert ASCII string to MAC address (colon-delimited format)
* @txt: MAC address as a string (e.g., "00:11:22:33:44:55")
* @addr: Buffer for the MAC address (ETH_ALEN = 6 bytes)
* Returns: 0 on success, -1 on failure (e.g., string not a MAC address)
@@ -71,6 +71,36 @@ int hwaddr_aton(const char *txt, u8 *addr)
/**
+ * hwaddr_aton2 - Convert ASCII string to MAC address (in any known format)
+ * @txt: MAC address as a string (e.g., 00:11:22:33:44:55 or 0011.2233.4455)
+ * @addr: Buffer for the MAC address (ETH_ALEN = 6 bytes)
+ * Returns: Characters used (> 0) on success, -1 on failure
+ */
+int hwaddr_aton2(const char *txt, u8 *addr)
+{
+ int i;
+ const char *pos = txt;
+
+ for (i = 0; i < 6; i++) {
+ int a, b;
+
+ while (*pos == ':' || *pos == '.' || *pos == '-')
+ pos++;
+
+ a = hex2num(*pos++);
+ if (a < 0)
+ return -1;
+ b = hex2num(*pos++);
+ if (b < 0)
+ return -1;
+ *addr++ = (a << 4) | b;
+ }
+
+ return pos - txt;
+}
+
+
+/**
* hexstr2bin - Convert ASCII hex string into binary data
* @hex: ASCII hex string (e.g., "01ab")
* @buf: Buffer for the binary data
diff --git a/contrib/wpa/src/utils/common.h b/contrib/wpa/src/utils/common.h
index d649391..f17bf69 100644
--- a/contrib/wpa/src/utils/common.h
+++ b/contrib/wpa/src/utils/common.h
@@ -17,7 +17,7 @@
#include "os.h"
-#ifdef __linux__
+#if defined(__linux__) || defined(__GLIBC__)
#include <endian.h>
#include <byteswap.h>
#endif /* __linux__ */
@@ -314,6 +314,24 @@ static inline unsigned int wpa_swap_32(unsigned int v)
#ifndef ETH_ALEN
#define ETH_ALEN 6
#endif
+#ifndef IFNAMSIZ
+#define IFNAMSIZ 16
+#endif
+#ifndef ETH_P_ALL
+#define ETH_P_ALL 0x0003
+#endif
+#ifndef ETH_P_PAE
+#define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
+#endif /* ETH_P_PAE */
+#ifndef ETH_P_EAPOL
+#define ETH_P_EAPOL ETH_P_PAE
+#endif /* ETH_P_EAPOL */
+#ifndef ETH_P_RSN_PREAUTH
+#define ETH_P_RSN_PREAUTH 0x88c7
+#endif /* ETH_P_RSN_PREAUTH */
+#ifndef ETH_P_RRB
+#define ETH_P_RRB 0x890D
+#endif /* ETH_P_RRB */
#ifdef __GNUC__
@@ -418,6 +436,7 @@ typedef u64 __bitwise le64;
#endif /* __must_check */
int hwaddr_aton(const char *txt, u8 *addr);
+int hwaddr_aton2(const char *txt, u8 *addr);
int hexstr2bin(const char *hex, u8 *buf, size_t len);
void inc_byte_array(u8 *counter, size_t len);
void wpa_get_ntp_timestamp(u8 *buf);
diff --git a/contrib/wpa/src/utils/eloop.c b/contrib/wpa/src/utils/eloop.c
index 4edb2a7..4b61598 100644
--- a/contrib/wpa/src/utils/eloop.c
+++ b/contrib/wpa/src/utils/eloop.c
@@ -1,6 +1,6 @@
/*
* Event loop based on select() loop
- * Copyright (c) 2002-2005, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -15,6 +15,8 @@
#include "includes.h"
#include "common.h"
+#include "trace.h"
+#include "list.h"
#include "eloop.h"
@@ -23,14 +25,20 @@ struct eloop_sock {
void *eloop_data;
void *user_data;
eloop_sock_handler handler;
+ WPA_TRACE_REF(eloop);
+ WPA_TRACE_REF(user);
+ WPA_TRACE_INFO
};
struct eloop_timeout {
+ struct dl_list list;
struct os_time time;
void *eloop_data;
void *user_data;
eloop_timeout_handler handler;
- struct eloop_timeout *next;
+ WPA_TRACE_REF(eloop);
+ WPA_TRACE_REF(user);
+ WPA_TRACE_INFO
};
struct eloop_signal {
@@ -47,15 +55,13 @@ struct eloop_sock_table {
};
struct eloop_data {
- void *user_data;
-
int max_sock;
struct eloop_sock_table readers;
struct eloop_sock_table writers;
struct eloop_sock_table exceptions;
- struct eloop_timeout *timeout;
+ struct dl_list timeout;
int signal_count;
struct eloop_signal *signals;
@@ -69,10 +75,56 @@ struct eloop_data {
static struct eloop_data eloop;
-int eloop_init(void *user_data)
+#ifdef WPA_TRACE
+
+static void eloop_sigsegv_handler(int sig)
+{
+ wpa_trace_show("eloop SIGSEGV");
+ abort();
+}
+
+static void eloop_trace_sock_add_ref(struct eloop_sock_table *table)
+{
+ int i;
+ if (table == NULL || table->table == NULL)
+ return;
+ for (i = 0; i < table->count; i++) {
+ wpa_trace_add_ref(&table->table[i], eloop,
+ table->table[i].eloop_data);
+ wpa_trace_add_ref(&table->table[i], user,
+ table->table[i].user_data);
+ }
+}
+
+
+static void eloop_trace_sock_remove_ref(struct eloop_sock_table *table)
+{
+ int i;
+ if (table == NULL || table->table == NULL)
+ return;
+ for (i = 0; i < table->count; i++) {
+ wpa_trace_remove_ref(&table->table[i], eloop,
+ table->table[i].eloop_data);
+ wpa_trace_remove_ref(&table->table[i], user,
+ table->table[i].user_data);
+ }
+}
+
+#else /* WPA_TRACE */
+
+#define eloop_trace_sock_add_ref(table) do { } while (0)
+#define eloop_trace_sock_remove_ref(table) do { } while (0)
+
+#endif /* WPA_TRACE */
+
+
+int eloop_init(void)
{
os_memset(&eloop, 0, sizeof(eloop));
- eloop.user_data = user_data;
+ dl_list_init(&eloop.timeout);
+#ifdef WPA_TRACE
+ signal(SIGSEGV, eloop_sigsegv_handler);
+#endif /* WPA_TRACE */
return 0;
}
@@ -86,6 +138,7 @@ static int eloop_sock_table_add_sock(struct eloop_sock_table *table,
if (table == NULL)
return -1;
+ eloop_trace_sock_remove_ref(table);
tmp = (struct eloop_sock *)
os_realloc(table->table,
(table->count + 1) * sizeof(struct eloop_sock));
@@ -96,11 +149,13 @@ static int eloop_sock_table_add_sock(struct eloop_sock_table *table,
tmp[table->count].eloop_data = eloop_data;
tmp[table->count].user_data = user_data;
tmp[table->count].handler = handler;
+ wpa_trace_record(&tmp[table->count]);
table->count++;
table->table = tmp;
if (sock > eloop.max_sock)
eloop.max_sock = sock;
table->changed = 1;
+ eloop_trace_sock_add_ref(table);
return 0;
}
@@ -120,6 +175,7 @@ static void eloop_sock_table_remove_sock(struct eloop_sock_table *table,
}
if (i == table->count)
return;
+ eloop_trace_sock_remove_ref(table);
if (i != table->count - 1) {
os_memmove(&table->table[i], &table->table[i + 1],
(table->count - i - 1) *
@@ -127,6 +183,7 @@ static void eloop_sock_table_remove_sock(struct eloop_sock_table *table,
}
table->count--;
table->changed = 1;
+ eloop_trace_sock_add_ref(table);
}
@@ -171,12 +228,17 @@ static void eloop_sock_table_destroy(struct eloop_sock_table *table)
if (table) {
int i;
for (i = 0; i < table->count && table->table; i++) {
- printf("ELOOP: remaining socket: sock=%d "
- "eloop_data=%p user_data=%p handler=%p\n",
- table->table[i].sock,
- table->table[i].eloop_data,
- table->table[i].user_data,
- table->table[i].handler);
+ wpa_printf(MSG_INFO, "ELOOP: remaining socket: "
+ "sock=%d eloop_data=%p user_data=%p "
+ "handler=%p",
+ table->table[i].sock,
+ table->table[i].eloop_data,
+ table->table[i].user_data,
+ table->table[i].handler);
+ wpa_trace_dump_funcname("eloop unregistered socket "
+ "handler",
+ table->table[i].handler);
+ wpa_trace_dump("eloop sock", &table->table[i]);
}
os_free(table->table);
}
@@ -237,9 +299,9 @@ int eloop_register_timeout(unsigned int secs, unsigned int usecs,
eloop_timeout_handler handler,
void *eloop_data, void *user_data)
{
- struct eloop_timeout *timeout, *tmp, *prev;
+ struct eloop_timeout *timeout, *tmp;
- timeout = os_malloc(sizeof(*timeout));
+ timeout = os_zalloc(sizeof(*timeout));
if (timeout == NULL)
return -1;
if (os_get_time(&timeout->time) < 0) {
@@ -255,60 +317,48 @@ int eloop_register_timeout(unsigned int secs, unsigned int usecs,
timeout->eloop_data = eloop_data;
timeout->user_data = user_data;
timeout->handler = handler;
- timeout->next = NULL;
-
- if (eloop.timeout == NULL) {
- eloop.timeout = timeout;
- return 0;
+ wpa_trace_add_ref(timeout, eloop, eloop_data);
+ wpa_trace_add_ref(timeout, user, user_data);
+ wpa_trace_record(timeout);
+
+ /* Maintain timeouts in order of increasing time */
+ dl_list_for_each(tmp, &eloop.timeout, struct eloop_timeout, list) {
+ if (os_time_before(&timeout->time, &tmp->time)) {
+ dl_list_add(tmp->list.prev, &timeout->list);
+ return 0;
+ }
}
+ dl_list_add_tail(&eloop.timeout, &timeout->list);
- prev = NULL;
- tmp = eloop.timeout;
- while (tmp != NULL) {
- if (os_time_before(&timeout->time, &tmp->time))
- break;
- prev = tmp;
- tmp = tmp->next;
- }
+ return 0;
+}
- if (prev == NULL) {
- timeout->next = eloop.timeout;
- eloop.timeout = timeout;
- } else {
- timeout->next = prev->next;
- prev->next = timeout;
- }
- return 0;
+static void eloop_remove_timeout(struct eloop_timeout *timeout)
+{
+ dl_list_del(&timeout->list);
+ wpa_trace_remove_ref(timeout, eloop, timeout->eloop_data);
+ wpa_trace_remove_ref(timeout, user, timeout->user_data);
+ os_free(timeout);
}
int eloop_cancel_timeout(eloop_timeout_handler handler,
void *eloop_data, void *user_data)
{
- struct eloop_timeout *timeout, *prev, *next;
+ struct eloop_timeout *timeout, *prev;
int removed = 0;
- prev = NULL;
- timeout = eloop.timeout;
- while (timeout != NULL) {
- next = timeout->next;
-
+ dl_list_for_each_safe(timeout, prev, &eloop.timeout,
+ struct eloop_timeout, list) {
if (timeout->handler == handler &&
(timeout->eloop_data == eloop_data ||
eloop_data == ELOOP_ALL_CTX) &&
(timeout->user_data == user_data ||
user_data == ELOOP_ALL_CTX)) {
- if (prev == NULL)
- eloop.timeout = next;
- else
- prev->next = next;
- os_free(timeout);
+ eloop_remove_timeout(timeout);
removed++;
- } else
- prev = timeout;
-
- timeout = next;
+ }
}
return removed;
@@ -320,14 +370,11 @@ int eloop_is_timeout_registered(eloop_timeout_handler handler,
{
struct eloop_timeout *tmp;
- tmp = eloop.timeout;
- while (tmp != NULL) {
+ dl_list_for_each(tmp, &eloop.timeout, struct eloop_timeout, list) {
if (tmp->handler == handler &&
tmp->eloop_data == eloop_data &&
tmp->user_data == user_data)
return 1;
-
- tmp = tmp->next;
}
return 0;
@@ -337,11 +384,11 @@ int eloop_is_timeout_registered(eloop_timeout_handler handler,
#ifndef CONFIG_NATIVE_WINDOWS
static void eloop_handle_alarm(int sig)
{
- fprintf(stderr, "eloop: could not process SIGINT or SIGTERM in two "
- "seconds. Looks like there\n"
- "is a bug that ends up in a busy loop that "
- "prevents clean shutdown.\n"
- "Killing program forcefully.\n");
+ wpa_printf(MSG_ERROR, "eloop: could not process SIGINT or SIGTERM in "
+ "two seconds. Looks like there\n"
+ "is a bug that ends up in a busy loop that "
+ "prevents clean shutdown.\n"
+ "Killing program forcefully.\n");
exit(1);
}
#endif /* CONFIG_NATIVE_WINDOWS */
@@ -390,7 +437,6 @@ static void eloop_process_pending_signals(void)
if (eloop.signals[i].signaled) {
eloop.signals[i].signaled = 0;
eloop.signals[i].handler(eloop.signals[i].sig,
- eloop.user_data,
eloop.signals[i].user_data);
}
}
@@ -452,24 +498,21 @@ void eloop_run(void)
rfds = os_malloc(sizeof(*rfds));
wfds = os_malloc(sizeof(*wfds));
efds = os_malloc(sizeof(*efds));
- if (rfds == NULL || wfds == NULL || efds == NULL) {
- printf("eloop_run - malloc failed\n");
+ if (rfds == NULL || wfds == NULL || efds == NULL)
goto out;
- }
while (!eloop.terminate &&
- (eloop.timeout || eloop.readers.count > 0 ||
+ (!dl_list_empty(&eloop.timeout) || eloop.readers.count > 0 ||
eloop.writers.count > 0 || eloop.exceptions.count > 0)) {
- if (eloop.timeout) {
+ struct eloop_timeout *timeout;
+ timeout = dl_list_first(&eloop.timeout, struct eloop_timeout,
+ list);
+ if (timeout) {
os_get_time(&now);
- if (os_time_before(&now, &eloop.timeout->time))
- os_time_sub(&eloop.timeout->time, &now, &tv);
+ if (os_time_before(&now, &timeout->time))
+ os_time_sub(&timeout->time, &now, &tv);
else
tv.sec = tv.usec = 0;
-#if 0
- printf("next timeout in %lu.%06lu sec\n",
- tv.sec, tv.usec);
-#endif
_tv.tv_sec = tv.sec;
_tv.tv_usec = tv.usec;
}
@@ -478,7 +521,7 @@ void eloop_run(void)
eloop_sock_table_set_fds(&eloop.writers, wfds);
eloop_sock_table_set_fds(&eloop.exceptions, efds);
res = select(eloop.max_sock + 1, rfds, wfds, efds,
- eloop.timeout ? &_tv : NULL);
+ timeout ? &_tv : NULL);
if (res < 0 && errno != EINTR && errno != 0) {
perror("select");
goto out;
@@ -486,16 +529,17 @@ void eloop_run(void)
eloop_process_pending_signals();
/* check if some registered timeouts have occurred */
- if (eloop.timeout) {
- struct eloop_timeout *tmp;
-
+ timeout = dl_list_first(&eloop.timeout, struct eloop_timeout,
+ list);
+ if (timeout) {
os_get_time(&now);
- if (!os_time_before(&now, &eloop.timeout->time)) {
- tmp = eloop.timeout;
- eloop.timeout = eloop.timeout->next;
- tmp->handler(tmp->eloop_data,
- tmp->user_data);
- os_free(tmp);
+ if (!os_time_before(&now, &timeout->time)) {
+ void *eloop_data = timeout->eloop_data;
+ void *user_data = timeout->user_data;
+ eloop_timeout_handler handler =
+ timeout->handler;
+ eloop_remove_timeout(timeout);
+ handler(eloop_data, user_data);
}
}
@@ -526,24 +570,24 @@ void eloop_destroy(void)
struct eloop_timeout *timeout, *prev;
struct os_time now;
- timeout = eloop.timeout;
- if (timeout)
- os_get_time(&now);
- while (timeout != NULL) {
+ os_get_time(&now);
+ dl_list_for_each_safe(timeout, prev, &eloop.timeout,
+ struct eloop_timeout, list) {
int sec, usec;
- prev = timeout;
- timeout = timeout->next;
- sec = prev->time.sec - now.sec;
- usec = prev->time.usec - now.usec;
- if (prev->time.usec < now.usec) {
+ sec = timeout->time.sec - now.sec;
+ usec = timeout->time.usec - now.usec;
+ if (timeout->time.usec < now.usec) {
sec--;
usec += 1000000;
}
- printf("ELOOP: remaining timeout: %d.%06d eloop_data=%p "
- "user_data=%p handler=%p\n",
- sec, usec, prev->eloop_data, prev->user_data,
- prev->handler);
- os_free(prev);
+ wpa_printf(MSG_INFO, "ELOOP: remaining timeout: %d.%06d "
+ "eloop_data=%p user_data=%p handler=%p",
+ sec, usec, timeout->eloop_data, timeout->user_data,
+ timeout->handler);
+ wpa_trace_dump_funcname("eloop unregistered timeout handler",
+ timeout->handler);
+ wpa_trace_dump("eloop timeout", timeout);
+ eloop_remove_timeout(timeout);
}
eloop_sock_table_destroy(&eloop.readers);
eloop_sock_table_destroy(&eloop.writers);
@@ -569,9 +613,3 @@ void eloop_wait_for_read_sock(int sock)
FD_SET(sock, &rfds);
select(sock + 1, &rfds, NULL, NULL, NULL);
}
-
-
-void * eloop_get_user_data(void)
-{
- return eloop.user_data;
-}
diff --git a/contrib/wpa/src/utils/eloop.h b/contrib/wpa/src/utils/eloop.h
index cf83f38..1228f24 100644
--- a/contrib/wpa/src/utils/eloop.h
+++ b/contrib/wpa/src/utils/eloop.h
@@ -65,25 +65,19 @@ typedef void (*eloop_timeout_handler)(void *eloop_data, void *user_ctx);
/**
* eloop_signal_handler - eloop signal event callback type
* @sig: Signal number
- * @eloop_ctx: Registered callback context data (global user_data from
- * eloop_init() call)
* @signal_ctx: Registered callback context data (user_data from
* eloop_register_signal(), eloop_register_signal_terminate(), or
* eloop_register_signal_reconfig() call)
*/
-typedef void (*eloop_signal_handler)(int sig, void *eloop_ctx,
- void *signal_ctx);
+typedef void (*eloop_signal_handler)(int sig, void *signal_ctx);
/**
* eloop_init() - Initialize global event loop data
- * @user_data: Pointer to global data passed as eloop_ctx to signal handlers
* Returns: 0 on success, -1 on failure
*
- * This function must be called before any other eloop_* function. user_data
- * can be used to configure a global (to the process) pointer that will be
- * passed as eloop_ctx parameter to signal handlers.
+ * This function must be called before any other eloop_* function.
*/
-int eloop_init(void *user_data);
+int eloop_init(void);
/**
* eloop_register_read_sock - Register handler for read events
@@ -231,10 +225,6 @@ int eloop_is_timeout_registered(eloop_timeout_handler handler,
* handler has returned. This means that the normal limits for sighandlers
* (i.e., only "safe functions" allowed) do not apply for the registered
* callback.
- *
- * Signals are 'global' events and there is no local eloop_data pointer like
- * with other handlers. The global user_data pointer registered with
- * eloop_init() will be used as eloop_ctx for signal handlers.
*/
int eloop_register_signal(int sig, eloop_signal_handler handler,
void *user_data);
@@ -251,10 +241,6 @@ int eloop_register_signal(int sig, eloop_signal_handler handler,
* sighandlers (i.e., only "safe functions" allowed) do not apply for the
* registered callback.
*
- * Signals are 'global' events and there is no local eloop_data pointer like
- * with other handlers. The global user_data pointer registered with
- * eloop_init() will be used as eloop_ctx for signal handlers.
- *
* This function is a more portable version of eloop_register_signal() since
* the knowledge of exact details of the signals is hidden in eloop
* implementation. In case of operating systems using signal(), this function
@@ -275,10 +261,6 @@ int eloop_register_signal_terminate(eloop_signal_handler handler,
* limits for sighandlers (i.e., only "safe functions" allowed) do not apply
* for the registered callback.
*
- * Signals are 'global' events and there is no local eloop_data pointer like
- * with other handlers. The global user_data pointer registered with
- * eloop_init() will be used as eloop_ctx for signal handlers.
- *
* This function is a more portable version of eloop_register_signal() since
* the knowledge of exact details of the signals is hidden in eloop
* implementation. In case of operating systems using signal(), this function
@@ -331,10 +313,4 @@ int eloop_terminated(void);
*/
void eloop_wait_for_read_sock(int sock);
-/**
- * eloop_get_user_data - Get global user data
- * Returns: user_data pointer that was registered with eloop_init()
- */
-void * eloop_get_user_data(void);
-
#endif /* ELOOP_H */
diff --git a/contrib/wpa/src/utils/eloop_none.c b/contrib/wpa/src/utils/eloop_none.c
index 215030b..18eae4e 100644
--- a/contrib/wpa/src/utils/eloop_none.c
+++ b/contrib/wpa/src/utils/eloop_none.c
@@ -41,8 +41,6 @@ struct eloop_signal {
};
struct eloop_data {
- void *user_data;
-
int max_sock, reader_count;
struct eloop_sock *readers;
@@ -60,10 +58,9 @@ struct eloop_data {
static struct eloop_data eloop;
-int eloop_init(void *user_data)
+int eloop_init(void)
{
memset(&eloop, 0, sizeof(eloop));
- eloop.user_data = user_data;
return 0;
}
@@ -402,9 +399,3 @@ void eloop_wait_for_read_sock(int sock)
* reading
*/
}
-
-
-void * eloop_get_user_data(void)
-{
- return eloop.user_data;
-}
diff --git a/contrib/wpa/src/utils/eloop_win.c b/contrib/wpa/src/utils/eloop_win.c
index c95aa76..94cc72d 100644
--- a/contrib/wpa/src/utils/eloop_win.c
+++ b/contrib/wpa/src/utils/eloop_win.c
@@ -50,8 +50,6 @@ struct eloop_signal {
};
struct eloop_data {
- void *user_data;
-
int max_sock;
size_t reader_count;
struct eloop_sock *readers;
@@ -79,10 +77,9 @@ struct eloop_data {
static struct eloop_data eloop;
-int eloop_init(void *user_data)
+int eloop_init(void)
{
os_memset(&eloop, 0, sizeof(eloop));
- eloop.user_data = user_data;
eloop.num_handles = 1;
eloop.handles = os_malloc(eloop.num_handles *
sizeof(eloop.handles[0]));
@@ -372,7 +369,6 @@ static void eloop_process_pending_signals(void)
if (eloop.signals[i].signaled) {
eloop.signals[i].signaled = 0;
eloop.signals[i].handler(eloop.signals[i].sig,
- eloop.user_data,
eloop.signals[i].user_data);
}
}
@@ -380,7 +376,6 @@ static void eloop_process_pending_signals(void)
if (eloop.term_signal.signaled) {
eloop.term_signal.signaled = 0;
eloop.term_signal.handler(eloop.term_signal.sig,
- eloop.user_data,
eloop.term_signal.user_data);
}
}
@@ -614,9 +609,3 @@ void eloop_wait_for_read_sock(int sock)
WSAEventSelect(sock, event, 0);
WSACloseEvent(event);
}
-
-
-void * eloop_get_user_data(void)
-{
- return eloop.user_data;
-}
diff --git a/contrib/wpa/src/utils/ip_addr.h b/contrib/wpa/src/utils/ip_addr.h
index 192049a..28ccaef 100644
--- a/contrib/wpa/src/utils/ip_addr.h
+++ b/contrib/wpa/src/utils/ip_addr.h
@@ -16,13 +16,14 @@
#define IP_ADDR_H
struct hostapd_ip_addr {
+ int af; /* AF_INET / AF_INET6 */
union {
struct in_addr v4;
#ifdef CONFIG_IPV6
struct in6_addr v6;
#endif /* CONFIG_IPV6 */
+ u8 max_len[16];
} u;
- int af; /* AF_INET / AF_INET6 */
};
const char * hostapd_ip_txt(const struct hostapd_ip_addr *addr, char *buf,
diff --git a/contrib/wpa/src/utils/list.h b/contrib/wpa/src/utils/list.h
new file mode 100644
index 0000000..ed7c022
--- /dev/null
+++ b/contrib/wpa/src/utils/list.h
@@ -0,0 +1,89 @@
+/*
+ * Doubly-linked list
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef LIST_H
+#define LIST_H
+
+/**
+ * struct dl_list - Doubly-linked list
+ */
+struct dl_list {
+ struct dl_list *next;
+ struct dl_list *prev;
+};
+
+static inline void dl_list_init(struct dl_list *list)
+{
+ list->next = list;
+ list->prev = list;
+}
+
+static inline void dl_list_add(struct dl_list *list, struct dl_list *item)
+{
+ item->next = list->next;
+ item->prev = list;
+ list->next->prev = item;
+ list->next = item;
+}
+
+static inline void dl_list_add_tail(struct dl_list *list, struct dl_list *item)
+{
+ dl_list_add(list->prev, item);
+}
+
+static inline void dl_list_del(struct dl_list *item)
+{
+ item->next->prev = item->prev;
+ item->prev->next = item->next;
+ item->next = NULL;
+ item->prev = NULL;
+}
+
+static inline int dl_list_empty(struct dl_list *list)
+{
+ return list->next == list;
+}
+
+static inline unsigned int dl_list_len(struct dl_list *list)
+{
+ struct dl_list *item;
+ int count = 0;
+ for (item = list->next; item != list; item = item->next)
+ count++;
+ return count;
+}
+
+#ifndef offsetof
+#define offsetof(type, member) ((long) &((type *) 0)->member)
+#endif
+
+#define dl_list_entry(item, type, member) \
+ ((type *) ((char *) item - offsetof(type, member)))
+
+#define dl_list_first(list, type, member) \
+ (dl_list_empty((list)) ? NULL : \
+ dl_list_entry((list)->next, type, member))
+
+#define dl_list_for_each(item, list, type, member) \
+ for (item = dl_list_entry((list)->next, type, member); \
+ &item->member != (list); \
+ item = dl_list_entry(item->member.next, type, member))
+
+#define dl_list_for_each_safe(item, n, list, type, member) \
+ for (item = dl_list_entry((list)->next, type, member), \
+ n = dl_list_entry(item->member.next, type, member); \
+ &item->member != (list); \
+ item = n, n = dl_list_entry(n->member.next, type, member))
+
+#endif /* LIST_H */
diff --git a/contrib/wpa/src/utils/os.h b/contrib/wpa/src/utils/os.h
index d6dfea6..f4723d8 100644
--- a/contrib/wpa/src/utils/os.h
+++ b/contrib/wpa/src/utils/os.h
@@ -1,6 +1,6 @@
/*
- * wpa_supplicant/hostapd / OS specific functions
- * Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
+ * OS specific functions
+ * Copyright (c) 2005-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -379,6 +379,12 @@ int os_snprintf(char *str, size_t size, const char *format, ...);
#else /* OS_NO_C_LIB_DEFINES */
+#ifdef WPA_TRACE
+void * os_malloc(size_t size);
+void * os_realloc(void *ptr, size_t size);
+void os_free(void *ptr);
+char * os_strdup(const char *s);
+#else /* WPA_TRACE */
#ifndef os_malloc
#define os_malloc(s) malloc((s))
#endif
@@ -388,6 +394,14 @@ int os_snprintf(char *str, size_t size, const char *format, ...);
#ifndef os_free
#define os_free(p) free((p))
#endif
+#ifndef os_strdup
+#ifdef _MSC_VER
+#define os_strdup(s) _strdup(s)
+#else
+#define os_strdup(s) strdup(s)
+#endif
+#endif
+#endif /* WPA_TRACE */
#ifndef os_memcpy
#define os_memcpy(d, s, n) memcpy((d), (s), (n))
@@ -402,13 +416,6 @@ int os_snprintf(char *str, size_t size, const char *format, ...);
#define os_memcmp(s1, s2, n) memcmp((s1), (s2), (n))
#endif
-#ifndef os_strdup
-#ifdef _MSC_VER
-#define os_strdup(s) _strdup(s)
-#else
-#define os_strdup(s) strdup(s)
-#endif
-#endif
#ifndef os_strlen
#define os_strlen(s) strlen(s)
#endif
diff --git a/contrib/wpa/src/utils/os_internal.c b/contrib/wpa/src/utils/os_internal.c
index 7b74bbf..5260e23 100644
--- a/contrib/wpa/src/utils/os_internal.c
+++ b/contrib/wpa/src/utils/os_internal.c
@@ -206,7 +206,12 @@ char * os_readfile(const char *name, size_t *len)
return NULL;
}
- fread(buf, 1, *len, f);
+ if (fread(buf, 1, *len, f) != *len) {
+ fclose(f);
+ os_free(buf);
+ return NULL;
+ }
+
fclose(f);
return buf;
diff --git a/contrib/wpa/src/utils/os_unix.c b/contrib/wpa/src/utils/os_unix.c
index bc2fc40..6f58fa4 100644
--- a/contrib/wpa/src/utils/os_unix.c
+++ b/contrib/wpa/src/utils/os_unix.c
@@ -1,6 +1,6 @@
/*
- * wpa_supplicant/hostapd / OS specific functions for UNIX/POSIX systems
- * Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
+ * OS specific functions for UNIX/POSIX systems
+ * Copyright (c) 2005-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -16,6 +16,28 @@
#include "os.h"
+#ifdef WPA_TRACE
+
+#include "common.h"
+#include "list.h"
+#include "wpa_debug.h"
+#include "trace.h"
+
+static struct dl_list alloc_list;
+
+#define ALLOC_MAGIC 0xa84ef1b2
+#define FREED_MAGIC 0x67fd487a
+
+struct os_alloc_trace {
+ unsigned int magic;
+ struct dl_list list;
+ size_t len;
+ WPA_TRACE_INFO
+};
+
+#endif /* WPA_TRACE */
+
+
void os_sleep(os_time_t sec, os_time_t usec)
{
if (sec)
@@ -172,16 +194,16 @@ char * os_rel2abs_path(const char *rel_path)
int last_errno;
if (rel_path[0] == '/')
- return strdup(rel_path);
+ return os_strdup(rel_path);
for (;;) {
- buf = malloc(len);
+ buf = os_malloc(len);
if (buf == NULL)
return NULL;
cwd = getcwd(buf, len);
if (cwd == NULL) {
last_errno = errno;
- free(buf);
+ os_free(buf);
if (last_errno != ERANGE)
return NULL;
len *= 2;
@@ -193,29 +215,51 @@ char * os_rel2abs_path(const char *rel_path)
}
}
- cwd_len = strlen(cwd);
- rel_len = strlen(rel_path);
+ cwd_len = os_strlen(cwd);
+ rel_len = os_strlen(rel_path);
ret_len = cwd_len + 1 + rel_len + 1;
- ret = malloc(ret_len);
+ ret = os_malloc(ret_len);
if (ret) {
- memcpy(ret, cwd, cwd_len);
+ os_memcpy(ret, cwd, cwd_len);
ret[cwd_len] = '/';
- memcpy(ret + cwd_len + 1, rel_path, rel_len);
+ os_memcpy(ret + cwd_len + 1, rel_path, rel_len);
ret[ret_len - 1] = '\0';
}
- free(buf);
+ os_free(buf);
return ret;
}
int os_program_init(void)
{
+#ifdef WPA_TRACE
+ dl_list_init(&alloc_list);
+#endif /* WPA_TRACE */
return 0;
}
void os_program_deinit(void)
{
+#ifdef WPA_TRACE
+ struct os_alloc_trace *a;
+ unsigned long total = 0;
+ dl_list_for_each(a, &alloc_list, struct os_alloc_trace, list) {
+ total += a->len;
+ if (a->magic != ALLOC_MAGIC) {
+ wpa_printf(MSG_INFO, "MEMLEAK[%p]: invalid magic 0x%x "
+ "len %lu",
+ a, a->magic, (unsigned long) a->len);
+ continue;
+ }
+ wpa_printf(MSG_INFO, "MEMLEAK[%p]: len %lu",
+ a, (unsigned long) a->len);
+ wpa_trace_dump("memleak", a);
+ }
+ if (total)
+ wpa_printf(MSG_INFO, "MEMLEAK: total %lu bytes",
+ (unsigned long) total);
+#endif /* WPA_TRACE */
}
@@ -250,7 +294,7 @@ char * os_readfile(const char *name, size_t *len)
*len = ftell(f);
fseek(f, 0, SEEK_SET);
- buf = malloc(*len);
+ buf = os_malloc(*len);
if (buf == NULL) {
fclose(f);
return NULL;
@@ -258,7 +302,7 @@ char * os_readfile(const char *name, size_t *len)
if (fread(buf, 1, *len, f) != *len) {
fclose(f);
- free(buf);
+ os_free(buf);
return NULL;
}
@@ -268,10 +312,12 @@ char * os_readfile(const char *name, size_t *len)
}
+#ifndef WPA_TRACE
void * os_zalloc(size_t size)
{
return calloc(1, size);
}
+#endif /* WPA_TRACE */
size_t os_strlcpy(char *dest, const char *src, size_t siz)
@@ -297,3 +343,95 @@ size_t os_strlcpy(char *dest, const char *src, size_t siz)
return s - src - 1;
}
+
+
+#ifdef WPA_TRACE
+
+void * os_malloc(size_t size)
+{
+ struct os_alloc_trace *a;
+ a = malloc(sizeof(*a) + size);
+ if (a == NULL)
+ return NULL;
+ a->magic = ALLOC_MAGIC;
+ dl_list_add(&alloc_list, &a->list);
+ a->len = size;
+ wpa_trace_record(a);
+ return a + 1;
+}
+
+
+void * os_realloc(void *ptr, size_t size)
+{
+ struct os_alloc_trace *a;
+ size_t copy_len;
+ void *n;
+
+ if (ptr == NULL)
+ return os_malloc(size);
+
+ a = (struct os_alloc_trace *) ptr - 1;
+ if (a->magic != ALLOC_MAGIC) {
+ wpa_printf(MSG_INFO, "REALLOC[%p]: invalid magic 0x%x%s",
+ a, a->magic,
+ a->magic == FREED_MAGIC ? " (already freed)" : "");
+ wpa_trace_show("Invalid os_realloc() call");
+ abort();
+ }
+ n = os_malloc(size);
+ if (n == NULL)
+ return NULL;
+ copy_len = a->len;
+ if (copy_len > size)
+ copy_len = size;
+ os_memcpy(n, a + 1, copy_len);
+ os_free(ptr);
+ return n;
+}
+
+
+void os_free(void *ptr)
+{
+ struct os_alloc_trace *a;
+
+ if (ptr == NULL)
+ return;
+ a = (struct os_alloc_trace *) ptr - 1;
+ if (a->magic != ALLOC_MAGIC) {
+ wpa_printf(MSG_INFO, "FREE[%p]: invalid magic 0x%x%s",
+ a, a->magic,
+ a->magic == FREED_MAGIC ? " (already freed)" : "");
+ wpa_trace_show("Invalid os_free() call");
+ abort();
+ }
+ dl_list_del(&a->list);
+ a->magic = FREED_MAGIC;
+
+ wpa_trace_check_ref(ptr);
+ free(a);
+}
+
+
+void * os_zalloc(size_t size)
+{
+ void *ptr = os_malloc(size);
+ if (ptr)
+ os_memset(ptr, 0, size);
+ return ptr;
+}
+
+
+char * os_strdup(const char *s)
+{
+ size_t len;
+ char *d;
+ len = os_strlen(s);
+ d = os_malloc(len + 1);
+ if (d == NULL)
+ return NULL;
+ os_memcpy(d, s, len);
+ d[len] = '\0';
+ return d;
+}
+
+#endif /* WPA_TRACE */
diff --git a/contrib/wpa/hostapd/radiotap.c b/contrib/wpa/src/utils/radiotap.c
index 804473f..804473f 100644
--- a/contrib/wpa/hostapd/radiotap.c
+++ b/contrib/wpa/src/utils/radiotap.c
diff --git a/contrib/wpa/hostapd/radiotap.h b/contrib/wpa/src/utils/radiotap.h
index 508264c..ba23ed3 100644
--- a/contrib/wpa/hostapd/radiotap.h
+++ b/contrib/wpa/src/utils/radiotap.h
@@ -1,4 +1,4 @@
-/* $FreeBSD: src/sys/net80211/ieee80211_radiotap.h,v 1.5 2005/01/22 20:12:05 sam Exp $ */
+/* $FreeBSD$ */
/* $NetBSD: ieee80211_radiotap.h,v 1.11 2005/06/22 06:16:02 dyoung Exp $ */
/*-
diff --git a/contrib/wpa/hostapd/radiotap_iter.h b/contrib/wpa/src/utils/radiotap_iter.h
index 92a798a..92a798a 100644
--- a/contrib/wpa/hostapd/radiotap_iter.h
+++ b/contrib/wpa/src/utils/radiotap_iter.h
diff --git a/contrib/wpa/src/utils/trace.c b/contrib/wpa/src/utils/trace.c
new file mode 100644
index 0000000..bb3eb24
--- /dev/null
+++ b/contrib/wpa/src/utils/trace.c
@@ -0,0 +1,329 @@
+/*
+ * Backtrace debugging
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "trace.h"
+
+#ifdef WPA_TRACE
+
+static struct dl_list active_references =
+{ &active_references, &active_references };
+
+#ifdef WPA_TRACE_BFD
+#include <bfd.h>
+#ifdef __linux__
+#include <demangle.h>
+#else /* __linux__ */
+#include <libiberty/demangle.h>
+#endif /* __linux__ */
+
+static char *prg_fname = NULL;
+static bfd *cached_abfd = NULL;
+static asymbol **syms = NULL;
+
+static void get_prg_fname(void)
+{
+ char exe[50], fname[512];
+ int len;
+ os_snprintf(exe, sizeof(exe) - 1, "/proc/%u/exe", getpid());
+ len = readlink(exe, fname, sizeof(fname) - 1);
+ if (len < 0 || len >= (int) sizeof(fname)) {
+ perror("readlink");
+ return;
+ }
+ fname[len] = '\0';
+ prg_fname = strdup(fname);
+}
+
+
+static bfd * open_bfd(const char *fname)
+{
+ bfd *abfd;
+ char **matching;
+
+ abfd = bfd_openr(prg_fname, NULL);
+ if (abfd == NULL) {
+ wpa_printf(MSG_INFO, "bfd_openr failed");
+ return NULL;
+ }
+
+ if (bfd_check_format(abfd, bfd_archive)) {
+ wpa_printf(MSG_INFO, "bfd_check_format failed");
+ bfd_close(abfd);
+ return NULL;
+ }
+
+ if (!bfd_check_format_matches(abfd, bfd_object, &matching)) {
+ wpa_printf(MSG_INFO, "bfd_check_format_matches failed");
+ free(matching);
+ bfd_close(abfd);
+ return NULL;
+ }
+
+ return abfd;
+}
+
+
+static void read_syms(bfd *abfd)
+{
+ long storage, symcount;
+ bfd_boolean dynamic = FALSE;
+
+ if (syms)
+ return;
+
+ if (!(bfd_get_file_flags(abfd) & HAS_SYMS)) {
+ wpa_printf(MSG_INFO, "No symbols");
+ return;
+ }
+
+ storage = bfd_get_symtab_upper_bound(abfd);
+ if (storage == 0) {
+ storage = bfd_get_dynamic_symtab_upper_bound(abfd);
+ dynamic = TRUE;
+ }
+ if (storage < 0) {
+ wpa_printf(MSG_INFO, "Unknown symtab upper bound");
+ return;
+ }
+
+ syms = malloc(storage);
+ if (syms == NULL) {
+ wpa_printf(MSG_INFO, "Failed to allocate memory for symtab "
+ "(%ld bytes)", storage);
+ return;
+ }
+ if (dynamic)
+ symcount = bfd_canonicalize_dynamic_symtab(abfd, syms);
+ else
+ symcount = bfd_canonicalize_symtab(abfd, syms);
+ if (symcount < 0) {
+ wpa_printf(MSG_INFO, "Failed to canonicalize %ssymtab",
+ dynamic ? "dynamic " : "");
+ free(syms);
+ syms = NULL;
+ return;
+ }
+}
+
+
+struct bfd_data {
+ bfd_vma pc;
+ bfd_boolean found;
+ const char *filename;
+ const char *function;
+ unsigned int line;
+};
+
+
+static void find_addr_sect(bfd *abfd, asection *section, void *obj)
+{
+ struct bfd_data *data = obj;
+ bfd_vma vma;
+ bfd_size_type size;
+
+ if (data->found)
+ return;
+
+ if (!(bfd_get_section_vma(abfd, section)))
+ return;
+
+ vma = bfd_get_section_vma(abfd, section);
+ if (data->pc < vma)
+ return;
+
+ size = bfd_get_section_size(section);
+ if (data->pc >= vma + size)
+ return;
+
+ data->found = bfd_find_nearest_line(abfd, section, syms,
+ data->pc - vma,
+ &data->filename,
+ &data->function,
+ &data->line);
+}
+
+
+static void wpa_trace_bfd_addr(void *pc)
+{
+ bfd *abfd = cached_abfd;
+ struct bfd_data data;
+ const char *name;
+ char *aname = NULL;
+ const char *filename;
+
+ if (abfd == NULL)
+ return;
+
+ data.pc = (bfd_vma) pc;
+ data.found = FALSE;
+ bfd_map_over_sections(abfd, find_addr_sect, &data);
+
+ if (!data.found)
+ return;
+
+ do {
+ if (data.function)
+ aname = bfd_demangle(abfd, data.function,
+ DMGL_ANSI | DMGL_PARAMS);
+ name = aname ? aname : data.function;
+ filename = data.filename;
+ if (filename) {
+ char *end = os_strrchr(filename, '/');
+ int i = 0;
+ while (*filename && *filename == prg_fname[i] &&
+ filename <= end) {
+ filename++;
+ i++;
+ }
+ }
+ wpa_printf(MSG_INFO, " %s() %s:%u",
+ name, filename, data.line);
+ free(aname);
+
+ data.found = bfd_find_inliner_info(abfd, &data.filename,
+ &data.function, &data.line);
+ } while (data.found);
+}
+
+
+static const char * wpa_trace_bfd_addr2func(void *pc)
+{
+ bfd *abfd = cached_abfd;
+ struct bfd_data data;
+
+ if (abfd == NULL)
+ return NULL;
+
+ data.pc = (bfd_vma) pc;
+ data.found = FALSE;
+ bfd_map_over_sections(abfd, find_addr_sect, &data);
+
+ if (!data.found)
+ return NULL;
+
+ return data.function;
+}
+
+
+static void wpa_trace_bfd_init(void)
+{
+ if (!prg_fname) {
+ get_prg_fname();
+ if (!prg_fname)
+ return;
+ }
+
+ if (!cached_abfd) {
+ cached_abfd = open_bfd(prg_fname);
+ if (!cached_abfd) {
+ wpa_printf(MSG_INFO, "Failed to open bfd");
+ return;
+ }
+ }
+
+ read_syms(cached_abfd);
+ if (!syms) {
+ wpa_printf(MSG_INFO, "Failed to read symbols");
+ return;
+ }
+}
+
+
+void wpa_trace_dump_funcname(const char *title, void *pc)
+{
+ wpa_printf(MSG_INFO, "WPA_TRACE: %s: %p", title, pc);
+ wpa_trace_bfd_init();
+ wpa_trace_bfd_addr(pc);
+}
+
+#else /* WPA_TRACE_BFD */
+
+#define wpa_trace_bfd_init() do { } while (0)
+#define wpa_trace_bfd_addr(pc) do { } while (0)
+#define wpa_trace_bfd_addr2func(pc) NULL
+
+#endif /* WPA_TRACE_BFD */
+
+void wpa_trace_dump_func(const char *title, void **btrace, int btrace_num)
+{
+ char **sym;
+ int i;
+ enum { TRACE_HEAD, TRACE_RELEVANT, TRACE_TAIL } state;
+
+ wpa_trace_bfd_init();
+ wpa_printf(MSG_INFO, "WPA_TRACE: %s - START", title);
+ sym = backtrace_symbols(btrace, btrace_num);
+ state = TRACE_HEAD;
+ for (i = 0; i < btrace_num; i++) {
+ const char *func = wpa_trace_bfd_addr2func(btrace[i]);
+ if (state == TRACE_HEAD && func &&
+ (os_strcmp(func, "wpa_trace_add_ref_func") == 0 ||
+ os_strcmp(func, "wpa_trace_check_ref") == 0 ||
+ os_strcmp(func, "wpa_trace_show") == 0))
+ continue;
+ if (state == TRACE_TAIL && sym && sym[i] &&
+ os_strstr(sym[i], "__libc_start_main"))
+ break;
+ if (state == TRACE_HEAD)
+ state = TRACE_RELEVANT;
+ if (sym)
+ wpa_printf(MSG_INFO, "[%d]: %s", i, sym[i]);
+ else
+ wpa_printf(MSG_INFO, "[%d]: ?? [%p]", i, btrace[i]);
+ wpa_trace_bfd_addr(btrace[i]);
+ if (state == TRACE_RELEVANT && func &&
+ os_strcmp(func, "main") == 0)
+ state = TRACE_TAIL;
+ }
+ free(sym);
+ wpa_printf(MSG_INFO, "WPA_TRACE: %s - END", title);
+}
+
+
+void wpa_trace_show(const char *title)
+{
+ struct info {
+ WPA_TRACE_INFO
+ } info;
+ wpa_trace_record(&info);
+ wpa_trace_dump(title, &info);
+}
+
+
+void wpa_trace_add_ref_func(struct wpa_trace_ref *ref, const void *addr)
+{
+ if (addr == NULL)
+ return;
+ ref->addr = addr;
+ wpa_trace_record(ref);
+ dl_list_add(&active_references, &ref->list);
+}
+
+
+void wpa_trace_check_ref(const void *addr)
+{
+ struct wpa_trace_ref *ref;
+ dl_list_for_each(ref, &active_references, struct wpa_trace_ref, list) {
+ if (addr != ref->addr)
+ continue;
+ wpa_trace_show("Freeing referenced memory");
+ wpa_trace_dump("Reference registration", ref);
+ abort();
+ }
+}
+
+#endif /* WPA_TRACE */
diff --git a/contrib/wpa/src/utils/trace.h b/contrib/wpa/src/utils/trace.h
new file mode 100644
index 0000000..22d3de0
--- /dev/null
+++ b/contrib/wpa/src/utils/trace.h
@@ -0,0 +1,74 @@
+/*
+ * Backtrace debugging
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef TRACE_H
+#define TRACE_H
+
+#define WPA_TRACE_LEN 16
+
+#ifdef WPA_TRACE
+#include <execinfo.h>
+
+#include "list.h"
+
+#define WPA_TRACE_INFO void *btrace[WPA_TRACE_LEN]; int btrace_num;
+
+struct wpa_trace_ref {
+ struct dl_list list;
+ const void *addr;
+ WPA_TRACE_INFO
+};
+#define WPA_TRACE_REF(name) struct wpa_trace_ref wpa_trace_ref_##name
+
+#define wpa_trace_dump(title, ptr) \
+ wpa_trace_dump_func((title), (ptr)->btrace, (ptr)->btrace_num)
+void wpa_trace_dump_func(const char *title, void **btrace, int btrace_num);
+#define wpa_trace_record(ptr) \
+ (ptr)->btrace_num = backtrace((ptr)->btrace, WPA_TRACE_LEN)
+void wpa_trace_show(const char *title);
+#define wpa_trace_add_ref(ptr, name, addr) \
+ wpa_trace_add_ref_func(&(ptr)->wpa_trace_ref_##name, (addr))
+void wpa_trace_add_ref_func(struct wpa_trace_ref *ref, const void *addr);
+#define wpa_trace_remove_ref(ptr, name, addr) \
+ do { \
+ if ((addr)) \
+ dl_list_del(&(ptr)->wpa_trace_ref_##name.list); \
+ } while (0)
+void wpa_trace_check_ref(const void *addr);
+
+#else /* WPA_TRACE */
+
+#define WPA_TRACE_INFO
+#define WPA_TRACE_REF(n)
+#define wpa_trace_dump(title, ptr) do { } while (0)
+#define wpa_trace_record(ptr) do { } while (0)
+#define wpa_trace_show(title) do { } while (0)
+#define wpa_trace_add_ref(ptr, name, addr) do { } while (0)
+#define wpa_trace_remove_ref(ptr, name, addr) do { } while (0)
+#define wpa_trace_check_ref(addr) do { } while (0)
+
+#endif /* WPA_TRACE */
+
+
+#ifdef WPA_TRACE_BFD
+
+void wpa_trace_dump_funcname(const char *title, void *pc);
+
+#else /* WPA_TRACE_BFD */
+
+#define wpa_trace_dump_funcname(title, pc) do { } while (0)
+
+#endif /* WPA_TRACE_BFD */
+
+#endif /* TRACE_H */
diff --git a/contrib/wpa/src/utils/uuid.c b/contrib/wpa/src/utils/uuid.c
index 620d3d6..d8cc267 100644
--- a/contrib/wpa/src/utils/uuid.c
+++ b/contrib/wpa/src/utils/uuid.c
@@ -15,8 +15,6 @@
#include "includes.h"
#include "common.h"
-#include "crypto.h"
-#include "sha1.h"
#include "uuid.h"
int uuid_str2bin(const char *str, u8 *bin)
@@ -77,31 +75,3 @@ int is_nil_uuid(const u8 *uuid)
return 0;
return 1;
}
-
-
-void uuid_gen_mac_addr(const u8 *mac_addr, u8 *uuid)
-{
- const u8 *addr[2];
- size_t len[2];
- u8 hash[SHA1_MAC_LEN];
- u8 nsid[16] = {
- 0x52, 0x64, 0x80, 0xf8,
- 0xc9, 0x9b,
- 0x4b, 0xe5,
- 0xa6, 0x55,
- 0x58, 0xed, 0x5f, 0x5d, 0x60, 0x84
- };
-
- addr[0] = nsid;
- len[0] = sizeof(nsid);
- addr[1] = mac_addr;
- len[1] = 6;
- sha1_vector(2, addr, len, hash);
- os_memcpy(uuid, hash, 16);
-
- /* Version: 5 = named-based version using SHA-1 */
- uuid[6] = (5 << 4) | (uuid[6] & 0x0f);
-
- /* Variant specified in RFC 4122 */
- uuid[8] = 0x80 | (uuid[8] & 0x3f);
-}
diff --git a/contrib/wpa/src/utils/uuid.h b/contrib/wpa/src/utils/uuid.h
index 9fc2ba0..0759165 100644
--- a/contrib/wpa/src/utils/uuid.h
+++ b/contrib/wpa/src/utils/uuid.h
@@ -20,6 +20,5 @@
int uuid_str2bin(const char *str, u8 *bin);
int uuid_bin2str(const u8 *bin, char *str, size_t max_len);
int is_nil_uuid(const u8 *uuid);
-void uuid_gen_mac_addr(const u8 *mac_addr, u8 *uuid);
#endif /* UUID_H */
diff --git a/contrib/wpa/src/utils/wpa_debug.c b/contrib/wpa/src/utils/wpa_debug.c
index 0f46aee..6f6fc69 100644
--- a/contrib/wpa/src/utils/wpa_debug.c
+++ b/contrib/wpa/src/utils/wpa_debug.c
@@ -18,6 +18,8 @@
#ifdef CONFIG_DEBUG_SYSLOG
#include <syslog.h>
+
+static int wpa_debug_syslog = 0;
#endif /* CONFIG_DEBUG_SYSLOG */
@@ -27,7 +29,6 @@ static FILE *out_file = NULL;
int wpa_debug_level = MSG_INFO;
int wpa_debug_show_keys = 0;
int wpa_debug_timestamp = 0;
-int wpa_debug_syslog = 0;
#ifndef CONFIG_NO_STDOUT_DEBUG
@@ -49,23 +50,22 @@ void wpa_debug_print_timestamp(void)
printf("%ld.%06u: ", (long) tv.sec, (unsigned int) tv.usec);
}
+
+#ifdef CONFIG_DEBUG_SYSLOG
void wpa_debug_open_syslog(void)
{
-#ifdef CONFIG_DEBUG_SYSLOG
openlog("wpa_supplicant", LOG_PID | LOG_NDELAY, LOG_DAEMON);
wpa_debug_syslog++;
-#endif
}
+
void wpa_debug_close_syslog(void)
{
-#ifdef CONFIG_DEBUG_SYSLOG
if (wpa_debug_syslog)
closelog();
-#endif
}
-#ifdef CONFIG_DEBUG_SYSLOG
+
static int syslog_priority(int level)
{
switch (level) {
@@ -390,6 +390,9 @@ void hostapd_logger(void *ctx, const u8 *addr, unsigned int module, int level,
va_end(ap);
if (hostapd_logger_cb)
hostapd_logger_cb(ctx, addr, module, level, buf, len);
+ else if (addr)
+ wpa_printf(MSG_DEBUG, "hostapd_logger: STA " MACSTR " - %s",
+ MAC2STR(addr), buf);
else
wpa_printf(MSG_DEBUG, "hostapd_logger: %s", buf);
os_free(buf);
diff --git a/contrib/wpa/src/utils/wpa_debug.h b/contrib/wpa/src/utils/wpa_debug.h
index b4010d5..6e5e79e 100644
--- a/contrib/wpa/src/utils/wpa_debug.h
+++ b/contrib/wpa/src/utils/wpa_debug.h
@@ -221,6 +221,23 @@ enum hostapd_logger_level {
};
+#ifdef CONFIG_DEBUG_SYSLOG
+
+void wpa_debug_open_syslog(void);
+void wpa_debug_close_syslog(void);
+
+#else /* CONFIG_DEBUG_SYSLOG */
+
+static inline void wpa_debug_open_syslog(void)
+{
+}
+
+static inline void wpa_debug_close_syslog(void)
+{
+}
+
+#endif /* CONFIG_DEBUG_SYSLOG */
+
#ifdef EAPOL_TEST
#define WPA_ASSERT(a) \
diff --git a/contrib/wpa/src/utils/wpabuf.c b/contrib/wpa/src/utils/wpabuf.c
index 8181912..eda779e 100644
--- a/contrib/wpa/src/utils/wpabuf.c
+++ b/contrib/wpa/src/utils/wpabuf.c
@@ -15,13 +15,37 @@
#include "includes.h"
#include "common.h"
+#include "trace.h"
#include "wpabuf.h"
+#ifdef WPA_TRACE
+#define WPABUF_MAGIC 0x51a974e3
+
+struct wpabuf_trace {
+ unsigned int magic;
+};
+
+static struct wpabuf_trace * wpabuf_get_trace(const struct wpabuf *buf)
+{
+ return (struct wpabuf_trace *)
+ ((const u8 *) buf - sizeof(struct wpabuf_trace));
+}
+#endif /* WPA_TRACE */
+
+
static void wpabuf_overflow(const struct wpabuf *buf, size_t len)
{
+#ifdef WPA_TRACE
+ struct wpabuf_trace *trace = wpabuf_get_trace(buf);
+ if (trace->magic != WPABUF_MAGIC) {
+ wpa_printf(MSG_ERROR, "wpabuf: invalid magic %x",
+ trace->magic);
+ }
+#endif /* WPA_TRACE */
wpa_printf(MSG_ERROR, "wpabuf %p (size=%lu used=%lu) overflow len=%lu",
buf, (unsigned long) buf->size, (unsigned long) buf->used,
(unsigned long) len);
+ wpa_trace_show("wpabuf overflow");
abort();
}
@@ -29,10 +53,25 @@ static void wpabuf_overflow(const struct wpabuf *buf, size_t len)
int wpabuf_resize(struct wpabuf **_buf, size_t add_len)
{
struct wpabuf *buf = *_buf;
+#ifdef WPA_TRACE
+ struct wpabuf_trace *trace;
+#endif /* WPA_TRACE */
+
if (buf == NULL) {
*_buf = wpabuf_alloc(add_len);
return *_buf == NULL ? -1 : 0;
}
+
+#ifdef WPA_TRACE
+ trace = wpabuf_get_trace(buf);
+ if (trace->magic != WPABUF_MAGIC) {
+ wpa_printf(MSG_ERROR, "wpabuf: invalid magic %x",
+ trace->magic);
+ wpa_trace_show("wpabuf_resize invalid magic");
+ abort();
+ }
+#endif /* WPA_TRACE */
+
if (buf->used + add_len > buf->size) {
unsigned char *nbuf;
if (buf->ext_data) {
@@ -42,6 +81,18 @@ int wpabuf_resize(struct wpabuf **_buf, size_t add_len)
os_memset(nbuf + buf->used, 0, add_len);
buf->ext_data = nbuf;
} else {
+#ifdef WPA_TRACE
+ nbuf = os_realloc(trace, sizeof(struct wpabuf_trace) +
+ sizeof(struct wpabuf) +
+ buf->used + add_len);
+ if (nbuf == NULL)
+ return -1;
+ trace = (struct wpabuf_trace *) nbuf;
+ buf = (struct wpabuf *) (trace + 1);
+ os_memset(nbuf + sizeof(struct wpabuf_trace) +
+ sizeof(struct wpabuf) + buf->used, 0,
+ add_len);
+#else /* WPA_TRACE */
nbuf = os_realloc(buf, sizeof(struct wpabuf) +
buf->used + add_len);
if (nbuf == NULL)
@@ -49,6 +100,7 @@ int wpabuf_resize(struct wpabuf **_buf, size_t add_len)
buf = (struct wpabuf *) nbuf;
os_memset(nbuf + sizeof(struct wpabuf) + buf->used, 0,
add_len);
+#endif /* WPA_TRACE */
*_buf = buf;
}
buf->size = buf->used + add_len;
@@ -65,9 +117,20 @@ int wpabuf_resize(struct wpabuf **_buf, size_t add_len)
*/
struct wpabuf * wpabuf_alloc(size_t len)
{
+#ifdef WPA_TRACE
+ struct wpabuf_trace *trace = os_zalloc(sizeof(struct wpabuf_trace) +
+ sizeof(struct wpabuf) + len);
+ struct wpabuf *buf;
+ if (trace == NULL)
+ return NULL;
+ trace->magic = WPABUF_MAGIC;
+ buf = (struct wpabuf *) (trace + 1);
+#else /* WPA_TRACE */
struct wpabuf *buf = os_zalloc(sizeof(struct wpabuf) + len);
if (buf == NULL)
return NULL;
+#endif /* WPA_TRACE */
+
buf->size = len;
return buf;
}
@@ -75,9 +138,19 @@ struct wpabuf * wpabuf_alloc(size_t len)
struct wpabuf * wpabuf_alloc_ext_data(u8 *data, size_t len)
{
+#ifdef WPA_TRACE
+ struct wpabuf_trace *trace = os_zalloc(sizeof(struct wpabuf_trace) +
+ sizeof(struct wpabuf));
+ struct wpabuf *buf;
+ if (trace == NULL)
+ return NULL;
+ trace->magic = WPABUF_MAGIC;
+ buf = (struct wpabuf *) (trace + 1);
+#else /* WPA_TRACE */
struct wpabuf *buf = os_zalloc(sizeof(struct wpabuf));
if (buf == NULL)
return NULL;
+#endif /* WPA_TRACE */
buf->size = len;
buf->used = len;
@@ -111,10 +184,25 @@ struct wpabuf * wpabuf_dup(const struct wpabuf *src)
*/
void wpabuf_free(struct wpabuf *buf)
{
+#ifdef WPA_TRACE
+ struct wpabuf_trace *trace;
+ if (buf == NULL)
+ return;
+ trace = wpabuf_get_trace(buf);
+ if (trace->magic != WPABUF_MAGIC) {
+ wpa_printf(MSG_ERROR, "wpabuf_free: invalid magic %x",
+ trace->magic);
+ wpa_trace_show("wpabuf_free magic mismatch");
+ abort();
+ }
+ os_free(buf->ext_data);
+ os_free(trace);
+#else /* WPA_TRACE */
if (buf == NULL)
return;
os_free(buf->ext_data);
os_free(buf);
+#endif /* WPA_TRACE */
}
diff --git a/contrib/wpa/src/utils/wpabuf.h b/contrib/wpa/src/utils/wpabuf.h
index bd8f09e..a150455 100644
--- a/contrib/wpa/src/utils/wpabuf.h
+++ b/contrib/wpa/src/utils/wpabuf.h
@@ -111,6 +111,12 @@ static inline void wpabuf_put_u8(struct wpabuf *buf, u8 data)
*pos = data;
}
+static inline void wpabuf_put_le16(struct wpabuf *buf, u16 data)
+{
+ u8 *pos = wpabuf_put(buf, 2);
+ WPA_PUT_LE16(pos, data);
+}
+
static inline void wpabuf_put_be16(struct wpabuf *buf, u16 data)
{
u8 *pos = wpabuf_put(buf, 2);
diff --git a/contrib/wpa/src/wps/Makefile b/contrib/wpa/src/wps/Makefile
index cffba62..9c41962 100644
--- a/contrib/wpa/src/wps/Makefile
+++ b/contrib/wpa/src/wps/Makefile
@@ -2,7 +2,6 @@ all:
@echo Nothing to be made.
clean:
- for d in $(SUBDIRS); do make -C $$d clean; done
rm -f *~ *.o *.d
install:
diff --git a/contrib/wpa/src/wps/http.h b/contrib/wpa/src/wps/http.h
new file mode 100644
index 0000000..2fee3a8
--- /dev/null
+++ b/contrib/wpa/src/wps/http.h
@@ -0,0 +1,29 @@
+/*
+ * HTTP for WPS
+ * Copyright (c) 2000-2003 Intel Corporation
+ * Copyright (c) 2006-2007 Sony Corporation
+ * Copyright (c) 2008-2009 Atheros Communications
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ *
+ * See wps_upnp.c for more details on licensing and code history.
+ */
+
+#ifndef HTTP_H
+#define HTTP_H
+
+enum http_reply_code {
+ HTTP_OK = 200,
+ HTTP_BAD_REQUEST = 400,
+ UPNP_INVALID_ACTION = 401,
+ UPNP_INVALID_ARGS = 402,
+ HTTP_NOT_FOUND = 404,
+ HTTP_PRECONDITION_FAILED = 412,
+ HTTP_INTERNAL_SERVER_ERROR = 500,
+ HTTP_UNIMPLEMENTED = 501,
+ UPNP_ACTION_FAILED = 501,
+ UPNP_ARG_VALUE_INVALID = 600,
+ UPNP_ARG_VALUE_OUT_OF_RANGE = 601,
+ UPNP_OUT_OF_MEMORY = 603
+};
+
+#endif /* HTTP_H */
diff --git a/contrib/wpa/src/wps/http_client.c b/contrib/wpa/src/wps/http_client.c
new file mode 100644
index 0000000..fea2a04
--- /dev/null
+++ b/contrib/wpa/src/wps/http_client.c
@@ -0,0 +1,371 @@
+/*
+ * http_client - HTTP client
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+#include <fcntl.h>
+
+#include "common.h"
+#include "eloop.h"
+#include "httpread.h"
+#include "http_client.h"
+
+
+#define HTTP_CLIENT_TIMEOUT 30
+
+
+struct http_client {
+ struct sockaddr_in dst;
+ int sd;
+ struct wpabuf *req;
+ size_t req_pos;
+ size_t max_response;
+
+ void (*cb)(void *ctx, struct http_client *c,
+ enum http_client_event event);
+ void *cb_ctx;
+ struct httpread *hread;
+ struct wpabuf body;
+};
+
+
+static void http_client_timeout(void *eloop_data, void *user_ctx)
+{
+ struct http_client *c = eloop_data;
+ wpa_printf(MSG_DEBUG, "HTTP: Timeout");
+ c->cb(c->cb_ctx, c, HTTP_CLIENT_TIMEOUT);
+}
+
+
+static void http_client_got_response(struct httpread *handle, void *cookie,
+ enum httpread_event e)
+{
+ struct http_client *c = cookie;
+
+ eloop_cancel_timeout(http_client_timeout, c, NULL);
+ switch (e) {
+ case HTTPREAD_EVENT_FILE_READY:
+ if (httpread_hdr_type_get(c->hread) == HTTPREAD_HDR_TYPE_REPLY)
+ {
+ int reply_code = httpread_reply_code_get(c->hread);
+ if (reply_code == 200 /* OK */) {
+ wpa_printf(MSG_DEBUG, "HTTP: Response OK from "
+ "%s:%d",
+ inet_ntoa(c->dst.sin_addr),
+ ntohs(c->dst.sin_port));
+ c->cb(c->cb_ctx, c, HTTP_CLIENT_OK);
+ } else {
+ wpa_printf(MSG_DEBUG, "HTTP: Error %d from "
+ "%s:%d", reply_code,
+ inet_ntoa(c->dst.sin_addr),
+ ntohs(c->dst.sin_port));
+ c->cb(c->cb_ctx, c, HTTP_CLIENT_INVALID_REPLY);
+ }
+ } else
+ c->cb(c->cb_ctx, c, HTTP_CLIENT_INVALID_REPLY);
+ break;
+ case HTTPREAD_EVENT_TIMEOUT:
+ c->cb(c->cb_ctx, c, HTTP_CLIENT_TIMEOUT);
+ break;
+ case HTTPREAD_EVENT_ERROR:
+ c->cb(c->cb_ctx, c, HTTP_CLIENT_FAILED);
+ break;
+ }
+}
+
+
+static void http_client_tx_ready(int sock, void *eloop_ctx, void *sock_ctx)
+{
+ struct http_client *c = eloop_ctx;
+ int res;
+
+ wpa_printf(MSG_DEBUG, "HTTP: Send client request to %s:%d (%lu of %lu "
+ "bytes remaining)",
+ inet_ntoa(c->dst.sin_addr), ntohs(c->dst.sin_port),
+ (unsigned long) wpabuf_len(c->req),
+ (unsigned long) wpabuf_len(c->req) - c->req_pos);
+
+ res = send(c->sd, wpabuf_head(c->req) + c->req_pos,
+ wpabuf_len(c->req) - c->req_pos, 0);
+ if (res < 0) {
+ wpa_printf(MSG_DEBUG, "HTTP: Failed to send buffer: %s",
+ strerror(errno));
+ eloop_unregister_sock(c->sd, EVENT_TYPE_WRITE);
+ c->cb(c->cb_ctx, c, HTTP_CLIENT_FAILED);
+ return;
+ }
+
+ if ((size_t) res < wpabuf_len(c->req) - c->req_pos) {
+ wpa_printf(MSG_DEBUG, "HTTP: Sent %d of %lu bytes; %lu bytes "
+ "remaining",
+ res, (unsigned long) wpabuf_len(c->req),
+ (unsigned long) wpabuf_len(c->req) - c->req_pos -
+ res);
+ c->req_pos += res;
+ return;
+ }
+
+ wpa_printf(MSG_DEBUG, "HTTP: Full client request sent to %s:%d",
+ inet_ntoa(c->dst.sin_addr), ntohs(c->dst.sin_port));
+ eloop_unregister_sock(c->sd, EVENT_TYPE_WRITE);
+ wpabuf_free(c->req);
+ c->req = NULL;
+
+ c->hread = httpread_create(c->sd, http_client_got_response, c,
+ c->max_response, HTTP_CLIENT_TIMEOUT);
+ if (c->hread == NULL) {
+ c->cb(c->cb_ctx, c, HTTP_CLIENT_FAILED);
+ return;
+ }
+}
+
+
+struct http_client * http_client_addr(struct sockaddr_in *dst,
+ struct wpabuf *req, size_t max_response,
+ void (*cb)(void *ctx,
+ struct http_client *c,
+ enum http_client_event event),
+ void *cb_ctx)
+{
+ struct http_client *c;
+
+ c = os_zalloc(sizeof(*c));
+ if (c == NULL)
+ return NULL;
+ c->sd = -1;
+ c->dst = *dst;
+ c->max_response = max_response;
+ c->cb = cb;
+ c->cb_ctx = cb_ctx;
+
+ c->sd = socket(AF_INET, SOCK_STREAM, 0);
+ if (c->sd < 0) {
+ http_client_free(c);
+ return NULL;
+ }
+
+ if (fcntl(c->sd, F_SETFL, O_NONBLOCK) != 0) {
+ wpa_printf(MSG_DEBUG, "HTTP: fnctl(O_NONBLOCK) failed: %s",
+ strerror(errno));
+ http_client_free(c);
+ return NULL;
+ }
+
+ if (connect(c->sd, (struct sockaddr *) dst, sizeof(*dst))) {
+ if (errno != EINPROGRESS) {
+ wpa_printf(MSG_DEBUG, "HTTP: Failed to connect: %s",
+ strerror(errno));
+ http_client_free(c);
+ return NULL;
+ }
+
+ /*
+ * Continue connecting in the background; eloop will call us
+ * once the connection is ready (or failed).
+ */
+ }
+
+ if (eloop_register_sock(c->sd, EVENT_TYPE_WRITE, http_client_tx_ready,
+ c, NULL)) {
+ http_client_free(c);
+ return NULL;
+ }
+
+ if (eloop_register_timeout(HTTP_CLIENT_TIMEOUT, 0, http_client_timeout,
+ c, NULL)) {
+ http_client_free(c);
+ return NULL;
+ }
+
+ c->req = req;
+
+ return c;
+}
+
+
+char * http_client_url_parse(const char *url, struct sockaddr_in *dst,
+ char **ret_path)
+{
+ char *u, *addr, *port, *path;
+
+ u = os_strdup(url);
+ if (u == NULL)
+ return NULL;
+
+ os_memset(dst, 0, sizeof(*dst));
+ dst->sin_family = AF_INET;
+ addr = u + 7;
+ path = os_strchr(addr, '/');
+ port = os_strchr(addr, ':');
+ if (path == NULL) {
+ path = "/";
+ } else {
+ *path = '\0'; /* temporary nul termination for address */
+ if (port > path)
+ port = NULL;
+ }
+ if (port)
+ *port++ = '\0';
+
+ if (inet_aton(addr, &dst->sin_addr) == 0) {
+ /* TODO: name lookup */
+ wpa_printf(MSG_DEBUG, "HTTP: Unsupported address in URL '%s' "
+ "(addr='%s' port='%s')",
+ url, addr, port);
+ os_free(u);
+ return NULL;
+ }
+
+ if (port)
+ dst->sin_port = htons(atoi(port));
+ else
+ dst->sin_port = htons(80);
+
+ if (*path == '\0') {
+ /* remove temporary nul termination for address */
+ *path = '/';
+ }
+
+ *ret_path = path;
+
+ return u;
+}
+
+
+struct http_client * http_client_url(const char *url,
+ struct wpabuf *req, size_t max_response,
+ void (*cb)(void *ctx,
+ struct http_client *c,
+ enum http_client_event event),
+ void *cb_ctx)
+{
+ struct sockaddr_in dst;
+ struct http_client *c;
+ char *u, *path;
+ struct wpabuf *req_buf = NULL;
+
+ if (os_strncmp(url, "http://", 7) != 0)
+ return NULL;
+ u = http_client_url_parse(url, &dst, &path);
+ if (u == NULL)
+ return NULL;
+
+ if (req == NULL) {
+ req_buf = wpabuf_alloc(os_strlen(url) + 1000);
+ if (req_buf == NULL) {
+ os_free(u);
+ return NULL;
+ }
+ req = req_buf;
+ wpabuf_printf(req,
+ "GET %s HTTP/1.1\r\n"
+ "Cache-Control: no-cache\r\n"
+ "Pragma: no-cache\r\n"
+ "Accept: text/xml, application/xml\r\n"
+ "User-Agent: wpa_supplicant\r\n"
+ "Host: %s:%d\r\n"
+ "\r\n",
+ path, inet_ntoa(dst.sin_addr),
+ ntohs(dst.sin_port));
+ }
+ os_free(u);
+
+ c = http_client_addr(&dst, req, max_response, cb, cb_ctx);
+ if (c == NULL) {
+ wpabuf_free(req_buf);
+ return NULL;
+ }
+
+ return c;
+}
+
+
+void http_client_free(struct http_client *c)
+{
+ if (c == NULL)
+ return;
+ httpread_destroy(c->hread);
+ wpabuf_free(c->req);
+ if (c->sd >= 0) {
+ eloop_unregister_sock(c->sd, EVENT_TYPE_WRITE);
+ close(c->sd);
+ }
+ eloop_cancel_timeout(http_client_timeout, c, NULL);
+ os_free(c);
+}
+
+
+struct wpabuf * http_client_get_body(struct http_client *c)
+{
+ if (c->hread == NULL)
+ return NULL;
+ wpabuf_set(&c->body, httpread_data_get(c->hread),
+ httpread_length_get(c->hread));
+ return &c->body;
+}
+
+
+char * http_client_get_hdr_line(struct http_client *c, const char *tag)
+{
+ if (c->hread == NULL)
+ return NULL;
+ return httpread_hdr_line_get(c->hread, tag);
+}
+
+
+char * http_link_update(char *url, const char *base)
+{
+ char *n;
+ size_t len;
+ const char *pos;
+
+ /* RFC 2396, Chapter 5.2 */
+ /* TODO: consider adding all cases described in RFC 2396 */
+
+ if (url == NULL)
+ return NULL;
+
+ if (os_strncmp(url, "http://", 7) == 0)
+ return url; /* absolute link */
+
+ if (os_strncmp(base, "http://", 7) != 0)
+ return url; /* unable to handle base URL */
+
+ len = os_strlen(url) + 1 + os_strlen(base) + 1;
+ n = os_malloc(len);
+ if (n == NULL)
+ return url; /* failed */
+
+ if (url[0] == '/') {
+ pos = os_strchr(base + 7, '/');
+ if (pos == NULL) {
+ os_snprintf(n, len, "%s%s", base, url);
+ } else {
+ os_memcpy(n, base, pos - base);
+ os_memcpy(n + (pos - base), url, os_strlen(url) + 1);
+ }
+ } else {
+ pos = os_strrchr(base + 7, '/');
+ if (pos == NULL) {
+ os_snprintf(n, len, "%s/%s", base, url);
+ } else {
+ os_memcpy(n, base, pos - base + 1);
+ os_memcpy(n + (pos - base) + 1, url, os_strlen(url) +
+ 1);
+ }
+ }
+
+ os_free(url);
+
+ return n;
+}
diff --git a/contrib/wpa/src/wps/http_client.h b/contrib/wpa/src/wps/http_client.h
new file mode 100644
index 0000000..924d6ab
--- /dev/null
+++ b/contrib/wpa/src/wps/http_client.h
@@ -0,0 +1,46 @@
+/*
+ * http_client - HTTP client
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef HTTP_CLIENT_H
+#define HTTP_CLIENT_H
+
+struct http_client;
+
+enum http_client_event {
+ HTTP_CLIENT_FAILED,
+ HTTP_CLIENT_TIMEOUT,
+ HTTP_CLIENT_OK,
+ HTTP_CLIENT_INVALID_REPLY,
+};
+
+char * http_client_url_parse(const char *url, struct sockaddr_in *dst,
+ char **path);
+struct http_client * http_client_addr(struct sockaddr_in *dst,
+ struct wpabuf *req, size_t max_response,
+ void (*cb)(void *ctx,
+ struct http_client *c,
+ enum http_client_event event),
+ void *cb_ctx);
+struct http_client * http_client_url(const char *url,
+ struct wpabuf *req, size_t max_response,
+ void (*cb)(void *ctx,
+ struct http_client *c,
+ enum http_client_event event),
+ void *cb_ctx);
+void http_client_free(struct http_client *c);
+struct wpabuf * http_client_get_body(struct http_client *c);
+char * http_client_get_hdr_line(struct http_client *c, const char *tag);
+char * http_link_update(char *url, const char *base);
+
+#endif /* HTTP_CLIENT_H */
diff --git a/contrib/wpa/src/wps/http_server.c b/contrib/wpa/src/wps/http_server.c
new file mode 100644
index 0000000..356f599
--- /dev/null
+++ b/contrib/wpa/src/wps/http_server.c
@@ -0,0 +1,312 @@
+/*
+ * http_server - HTTP server
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+#include <fcntl.h>
+
+#include "common.h"
+#include "eloop.h"
+#include "httpread.h"
+#include "http_server.h"
+
+#define HTTP_SERVER_TIMEOUT 30
+#define HTTP_SERVER_MAX_REQ_LEN 8000
+#define HTTP_SERVER_MAX_CONNECTIONS 10
+
+struct http_request {
+ struct http_request *next;
+ struct http_server *srv;
+ int fd;
+ struct sockaddr_in cli;
+ struct httpread *hread;
+};
+
+struct http_server {
+ void (*cb)(void *ctx, struct http_request *req);
+ void *cb_ctx;
+
+ int fd;
+ int port;
+
+ struct http_request *requests;
+ unsigned int request_count;
+};
+
+
+static void http_request_cb(struct httpread *handle, void *cookie,
+ enum httpread_event en)
+{
+ struct http_request *req = cookie;
+ struct http_server *srv = req->srv;
+
+ if (en == HTTPREAD_EVENT_FILE_READY) {
+ wpa_printf(MSG_DEBUG, "HTTP: Request from %s:%d received",
+ inet_ntoa(req->cli.sin_addr),
+ ntohs(req->cli.sin_port));
+ srv->cb(srv->cb_ctx, req);
+ return;
+ }
+ wpa_printf(MSG_DEBUG, "HTTP: Request from %s:%d could not be received "
+ "completely", inet_ntoa(req->cli.sin_addr),
+ ntohs(req->cli.sin_port));
+ http_request_deinit(req);
+}
+
+
+static struct http_request * http_request_init(struct http_server *srv, int fd,
+ struct sockaddr_in *cli)
+{
+ struct http_request *req;
+
+ if (srv->request_count >= HTTP_SERVER_MAX_CONNECTIONS) {
+ wpa_printf(MSG_DEBUG, "HTTP: Too many concurrent requests");
+ return NULL;
+ }
+
+ req = os_zalloc(sizeof(*req));
+ if (req == NULL)
+ return NULL;
+
+ req->srv = srv;
+ req->fd = fd;
+ req->cli = *cli;
+
+ req->hread = httpread_create(req->fd, http_request_cb, req,
+ HTTP_SERVER_MAX_REQ_LEN,
+ HTTP_SERVER_TIMEOUT);
+ if (req->hread == NULL) {
+ http_request_deinit(req);
+ return NULL;
+ }
+
+ return req;
+}
+
+
+void http_request_deinit(struct http_request *req)
+{
+ struct http_request *r, *p;
+ struct http_server *srv;
+
+ if (req == NULL)
+ return;
+
+ srv = req->srv;
+ p = NULL;
+ r = srv->requests;
+ while (r) {
+ if (r == req) {
+ if (p)
+ p->next = r->next;
+ else
+ srv->requests = r->next;
+ srv->request_count--;
+ break;
+ }
+ p = r;
+ r = r->next;
+ }
+
+ httpread_destroy(req->hread);
+ close(req->fd);
+ os_free(req);
+}
+
+
+static void http_request_free_all(struct http_request *req)
+{
+ struct http_request *prev;
+ while (req) {
+ prev = req;
+ req = req->next;
+ http_request_deinit(prev);
+ }
+}
+
+
+void http_request_send(struct http_request *req, struct wpabuf *resp)
+{
+ int res;
+
+ wpa_printf(MSG_DEBUG, "HTTP: Send %lu byte response to %s:%d",
+ (unsigned long) wpabuf_len(resp),
+ inet_ntoa(req->cli.sin_addr),
+ ntohs(req->cli.sin_port));
+
+ res = send(req->fd, wpabuf_head(resp), wpabuf_len(resp), 0);
+ if (res < 0) {
+ wpa_printf(MSG_DEBUG, "HTTP: Send failed: %s",
+ strerror(errno));
+ } else if ((size_t) res < wpabuf_len(resp)) {
+ wpa_printf(MSG_DEBUG, "HTTP: Sent only %d of %lu bytes",
+ res, (unsigned long) wpabuf_len(resp));
+ /* TODO: add eloop handler for sending rest of the data */
+ }
+
+ wpabuf_free(resp);
+}
+
+
+void http_request_send_and_deinit(struct http_request *req,
+ struct wpabuf *resp)
+{
+ http_request_send(req, resp);
+ http_request_deinit(req);
+}
+
+
+enum httpread_hdr_type http_request_get_type(struct http_request *req)
+{
+ return httpread_hdr_type_get(req->hread);
+}
+
+
+char * http_request_get_uri(struct http_request *req)
+{
+ return httpread_uri_get(req->hread);
+}
+
+
+char * http_request_get_hdr(struct http_request *req)
+{
+ return httpread_hdr_get(req->hread);
+}
+
+
+char * http_request_get_data(struct http_request *req)
+{
+ return httpread_data_get(req->hread);
+}
+
+
+char * http_request_get_hdr_line(struct http_request *req, const char *tag)
+{
+ return httpread_hdr_line_get(req->hread, tag);
+}
+
+
+struct sockaddr_in * http_request_get_cli_addr(struct http_request *req)
+{
+ return &req->cli;
+}
+
+
+static void http_server_cb(int sd, void *eloop_ctx, void *sock_ctx)
+{
+ struct sockaddr_in addr;
+ socklen_t addr_len = sizeof(addr);
+ struct http_server *srv = eloop_ctx;
+ int conn;
+ struct http_request *req;
+
+ conn = accept(srv->fd, (struct sockaddr *) &addr, &addr_len);
+ if (conn < 0) {
+ wpa_printf(MSG_DEBUG, "HTTP: Failed to accept new connection: "
+ "%s", strerror(errno));
+ return;
+ }
+ wpa_printf(MSG_DEBUG, "HTTP: Connection from %s:%d",
+ inet_ntoa(addr.sin_addr), ntohs(addr.sin_port));
+
+ req = http_request_init(srv, conn, &addr);
+ if (req == NULL) {
+ close(conn);
+ return;
+ }
+
+ req->next = srv->requests;
+ srv->requests = req;
+ srv->request_count++;
+}
+
+
+struct http_server * http_server_init(struct in_addr *addr, int port,
+ void (*cb)(void *ctx,
+ struct http_request *req),
+ void *cb_ctx)
+{
+ struct sockaddr_in sin;
+ struct http_server *srv;
+
+ srv = os_zalloc(sizeof(*srv));
+ if (srv == NULL)
+ return NULL;
+ srv->cb = cb;
+ srv->cb_ctx = cb_ctx;
+
+ srv->fd = socket(AF_INET, SOCK_STREAM, 0);
+ if (srv->fd < 0)
+ goto fail;
+ if (fcntl(srv->fd, F_SETFL, O_NONBLOCK) < 0)
+ goto fail;
+ if (port < 0)
+ srv->port = 49152;
+ else
+ srv->port = port;
+
+ os_memset(&sin, 0, sizeof(sin));
+ sin.sin_family = AF_INET;
+ sin.sin_addr.s_addr = addr->s_addr;
+
+ for (;;) {
+ sin.sin_port = htons(srv->port);
+ if (bind(srv->fd, (struct sockaddr *) &sin, sizeof(sin)) == 0)
+ break;
+ if (errno == EADDRINUSE) {
+ /* search for unused port */
+ if (++srv->port == 65535 || port >= 0)
+ goto fail;
+ continue;
+ }
+ wpa_printf(MSG_DEBUG, "HTTP: Failed to bind server port %d: "
+ "%s", srv->port, strerror(errno));
+ goto fail;
+ }
+ if (listen(srv->fd, 10 /* max backlog */) < 0)
+ goto fail;
+ if (fcntl(srv->fd, F_SETFL, O_NONBLOCK) < 0)
+ goto fail;
+ if (eloop_register_sock(srv->fd, EVENT_TYPE_READ, http_server_cb,
+ srv, NULL))
+ goto fail;
+
+ wpa_printf(MSG_DEBUG, "HTTP: Started server on %s:%d",
+ inet_ntoa(*addr), srv->port);
+
+ return srv;
+
+fail:
+ http_server_deinit(srv);
+ return NULL;
+}
+
+
+void http_server_deinit(struct http_server *srv)
+{
+ if (srv == NULL)
+ return;
+ if (srv->fd >= 0) {
+ eloop_unregister_sock(srv->fd, EVENT_TYPE_READ);
+ close(srv->fd);
+ }
+ http_request_free_all(srv->requests);
+
+ os_free(srv);
+}
+
+
+int http_server_get_port(struct http_server *srv)
+{
+ return srv->port;
+}
diff --git a/contrib/wpa/src/wps/http_server.h b/contrib/wpa/src/wps/http_server.h
new file mode 100644
index 0000000..219941c
--- /dev/null
+++ b/contrib/wpa/src/wps/http_server.h
@@ -0,0 +1,39 @@
+/*
+ * http_server - HTTP server
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef HTTP_SERVER_H
+#define HTTP_SERVER_H
+
+struct http_server;
+struct http_request;
+
+void http_request_deinit(struct http_request *req);
+void http_request_send(struct http_request *req, struct wpabuf *resp);
+void http_request_send_and_deinit(struct http_request *req,
+ struct wpabuf *resp);
+enum httpread_hdr_type http_request_get_type(struct http_request *req);
+char * http_request_get_uri(struct http_request *req);
+char * http_request_get_hdr(struct http_request *req);
+char * http_request_get_data(struct http_request *req);
+char * http_request_get_hdr_line(struct http_request *req, const char *tag);
+struct sockaddr_in * http_request_get_cli_addr(struct http_request *req);
+
+struct http_server * http_server_init(struct in_addr *addr, int port,
+ void (*cb)(void *ctx,
+ struct http_request *req),
+ void *cb_ctx);
+void http_server_deinit(struct http_server *srv);
+int http_server_get_port(struct http_server *srv);
+
+#endif /* HTTP_SERVER_H */
diff --git a/contrib/wpa/src/wps/httpread.c b/contrib/wpa/src/wps/httpread.c
index 0d7165e..40422e4 100644
--- a/contrib/wpa/src/wps/httpread.c
+++ b/contrib/wpa/src/wps/httpread.c
@@ -1,4 +1,4 @@
-/**
+/*
* httpread - Manage reading file(s) from HTTP/TCP socket
* Author: Ted Merrill
* Copyright 2008 Atheros Communications
diff --git a/contrib/wpa/src/wps/httpread.h b/contrib/wpa/src/wps/httpread.h
index fb1ecb7..51aa214 100644
--- a/contrib/wpa/src/wps/httpread.h
+++ b/contrib/wpa/src/wps/httpread.h
@@ -1,4 +1,4 @@
-/**
+/*
* httpread - Manage reading file(s) from HTTP/TCP socket
* Author: Ted Merrill
* Copyright 2008 Atheros Communications
diff --git a/contrib/wpa/src/wps/ndef.c b/contrib/wpa/src/wps/ndef.c
new file mode 100644
index 0000000..9baec7f
--- /dev/null
+++ b/contrib/wpa/src/wps/ndef.c
@@ -0,0 +1,175 @@
+/*
+ * NDEF(NFC Data Exchange Format) routines for Wi-Fi Protected Setup
+ * Reference is "NFCForum-TS-NDEF_1.0 2006-07-24".
+ * Copyright (c) 2009, Masashi Honma <honma@ictec.co.jp>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+#include "common.h"
+#include "wps/wps.h"
+#include "wps/wps_i.h"
+
+#define FLAG_MESSAGE_BEGIN (1 << 7)
+#define FLAG_MESSAGE_END (1 << 6)
+#define FLAG_CHUNK (1 << 5)
+#define FLAG_SHORT_RECORD (1 << 4)
+#define FLAG_ID_LENGTH_PRESENT (1 << 3)
+#define FLAG_TNF_RFC2046 (0x02)
+
+struct ndef_record {
+ u8 *type;
+ u8 *id;
+ u8 *payload;
+ u8 type_length;
+ u8 id_length;
+ u32 payload_length;
+ u32 total_length;
+};
+
+static char wifi_handover_type[] = "application/vnd.wfa.wsc";
+
+static int ndef_parse_record(u8 *data, u32 size, struct ndef_record *record)
+{
+ u8 *pos = data + 1;
+
+ if (size < 2)
+ return -1;
+ record->type_length = *pos++;
+ if (data[0] & FLAG_SHORT_RECORD) {
+ if (size < 3)
+ return -1;
+ record->payload_length = *pos++;
+ } else {
+ if (size < 6)
+ return -1;
+ record->payload_length = ntohl(*(u32 *)pos);
+ pos += sizeof(u32);
+ }
+
+ if (data[0] & FLAG_ID_LENGTH_PRESENT) {
+ if ((int) size < pos - data + 1)
+ return -1;
+ record->id_length = *pos++;
+ } else
+ record->id_length = 0;
+
+ record->type = record->type_length == 0 ? NULL : pos;
+ pos += record->type_length;
+
+ record->id = record->id_length == 0 ? NULL : pos;
+ pos += record->id_length;
+
+ record->payload = record->payload_length == 0 ? NULL : pos;
+ pos += record->payload_length;
+
+ record->total_length = pos - data;
+ if (record->total_length > size)
+ return -1;
+ return 0;
+}
+
+
+static struct wpabuf * ndef_parse_records(struct wpabuf *buf,
+ int (*filter)(struct ndef_record *))
+{
+ struct ndef_record record;
+ int len = wpabuf_len(buf);
+ u8 *data = wpabuf_mhead(buf);
+
+ while (len > 0) {
+ if (ndef_parse_record(data, len, &record) < 0) {
+ wpa_printf(MSG_ERROR, "NDEF : Failed to parse");
+ return NULL;
+ }
+ if (filter == NULL || filter(&record))
+ return wpabuf_alloc_copy(record.payload,
+ record.payload_length);
+ data += record.total_length;
+ len -= record.total_length;
+ }
+ wpa_printf(MSG_ERROR, "NDEF : Record not found");
+ return NULL;
+}
+
+
+static struct wpabuf * ndef_build_record(u8 flags, void *type,
+ u8 type_length, void *id,
+ u8 id_length, void *payload,
+ u32 payload_length)
+{
+ struct wpabuf *record;
+ size_t total_len;
+ int short_record;
+ u8 local_flag;
+
+ short_record = payload_length < 256 ? 1 : 0;
+
+ total_len = 2; /* flag + type length */
+ /* payload length */
+ total_len += short_record ? sizeof(u8) : sizeof(u32);
+ if (id_length > 0)
+ total_len += 1;
+ total_len += type_length + id_length + payload_length;
+ record = wpabuf_alloc(total_len);
+ if (record == NULL) {
+ wpa_printf(MSG_ERROR, "NDEF : Failed to allocate "
+ "record for build");
+ return NULL;
+ }
+
+ local_flag = flags;
+ if (id_length > 0)
+ local_flag |= FLAG_ID_LENGTH_PRESENT;
+ if (short_record)
+ local_flag |= FLAG_SHORT_RECORD;
+ wpabuf_put_u8(record, local_flag);
+
+ wpabuf_put_u8(record, type_length);
+
+ if (short_record)
+ wpabuf_put_u8(record, payload_length);
+ else
+ wpabuf_put_be32(record, payload_length);
+
+ if (id_length > 0)
+ wpabuf_put_u8(record, id_length);
+ wpabuf_put_data(record, type, type_length);
+ wpabuf_put_data(record, id, id_length);
+ wpabuf_put_data(record, payload, payload_length);
+ return record;
+}
+
+
+static int wifi_filter(struct ndef_record *record)
+{
+ if (record->type_length != os_strlen(wifi_handover_type))
+ return 0;
+ if (os_memcmp(record->type, wifi_handover_type,
+ os_strlen(wifi_handover_type)) != 0)
+ return 0;
+ return 1;
+}
+
+
+struct wpabuf * ndef_parse_wifi(struct wpabuf *buf)
+{
+ return ndef_parse_records(buf, wifi_filter);
+}
+
+
+struct wpabuf * ndef_build_wifi(struct wpabuf *buf)
+{
+ return ndef_build_record(FLAG_MESSAGE_BEGIN | FLAG_MESSAGE_END |
+ FLAG_TNF_RFC2046, wifi_handover_type,
+ os_strlen(wifi_handover_type), NULL, 0,
+ wpabuf_mhead(buf), wpabuf_len(buf));
+}
diff --git a/contrib/wpa/src/wps/upnp_xml.c b/contrib/wpa/src/wps/upnp_xml.c
new file mode 100644
index 0000000..b1b1e2b
--- /dev/null
+++ b/contrib/wpa/src/wps/upnp_xml.c
@@ -0,0 +1,252 @@
+/*
+ * UPnP XML helper routines
+ * Copyright (c) 2000-2003 Intel Corporation
+ * Copyright (c) 2006-2007 Sony Corporation
+ * Copyright (c) 2008-2009 Atheros Communications
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ *
+ * See wps_upnp.c for more details on licensing and code history.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "base64.h"
+#include "http.h"
+#include "upnp_xml.h"
+
+
+/*
+ * XML parsing and formatting
+ *
+ * XML is a markup language based on unicode; usually (and in our case,
+ * always!) based on utf-8. utf-8 uses a variable number of bytes per
+ * character. utf-8 has the advantage that all non-ASCII unicode characters are
+ * represented by sequences of non-ascii (high bit set) bytes, whereas ASCII
+ * characters are single ascii bytes, thus we can use typical text processing.
+ *
+ * (One other interesting thing about utf-8 is that it is possible to look at
+ * any random byte and determine if it is the first byte of a character as
+ * versus a continuation byte).
+ *
+ * The base syntax of XML uses a few ASCII punctionation characters; any
+ * characters that would appear in the payload data are rewritten using
+ * sequences, e.g., &amp; for ampersand(&) and &lt for left angle bracket (<).
+ * Five such escapes total (more can be defined but that does not apply to our
+ * case). Thus we can safely parse for angle brackets etc.
+ *
+ * XML describes tree structures of tagged data, with each element beginning
+ * with an opening tag <label> and ending with a closing tag </label> with
+ * matching label. (There is also a self-closing tag <label/> which is supposed
+ * to be equivalent to <label></label>, i.e., no payload, but we are unlikely
+ * to see it for our purpose).
+ *
+ * Actually the opening tags are a little more complicated because they can
+ * contain "attributes" after the label (delimited by ascii space or tab chars)
+ * of the form attribute_label="value" or attribute_label='value'; as it turns
+ * out we do not have to read any of these attributes, just ignore them.
+ *
+ * Labels are any sequence of chars other than space, tab, right angle bracket
+ * (and ?), but may have an inner structure of <namespace><colon><plain_label>.
+ * As it turns out, we can ignore the namespaces, in fact we can ignore the
+ * entire tree hierarchy, because the plain labels we are looking for will be
+ * unique (not in general, but for this application). We do however have to be
+ * careful to skip over the namespaces.
+ *
+ * In generating XML we have to be more careful, but that is easy because
+ * everything we do is pretty canned. The only real care to take is to escape
+ * any special chars in our payload.
+ */
+
+/**
+ * xml_next_tag - Advance to next tag
+ * @in: Input
+ * @out: OUT: start of tag just after '<'
+ * @out_tagname: OUT: start of name of tag, skipping namespace
+ * @end: OUT: one after tag
+ * Returns: 0 on success, 1 on failure
+ *
+ * A tag has form:
+ * <left angle bracket><...><right angle bracket>
+ * Within the angle brackets, there is an optional leading forward slash (which
+ * makes the tag an ending tag), then an optional leading label (followed by
+ * colon) and then the tag name itself.
+ *
+ * Note that angle brackets present in the original data must have been encoded
+ * as &lt; and &gt; so they will not trouble us.
+ */
+static int xml_next_tag(const char *in, const char **out,
+ const char **out_tagname, const char **end)
+{
+ while (*in && *in != '<')
+ in++;
+ if (*in != '<')
+ return 1;
+ *out = ++in;
+ if (*in == '/')
+ in++;
+ *out_tagname = in; /* maybe */
+ while (isalnum(*in) || *in == '-')
+ in++;
+ if (*in == ':')
+ *out_tagname = ++in;
+ while (*in && *in != '>')
+ in++;
+ if (*in != '>')
+ return 1;
+ *end = ++in;
+ return 0;
+}
+
+
+/* xml_data_encode -- format data for xml file, escaping special characters.
+ *
+ * Note that we assume we are using utf8 both as input and as output!
+ * In utf8, characters may be classed as follows:
+ * 0xxxxxxx(2) -- 1 byte ascii char
+ * 11xxxxxx(2) -- 1st byte of multi-byte char w/ unicode value >= 0x80
+ * 110xxxxx(2) -- 1st byte of 2 byte sequence (5 payload bits here)
+ * 1110xxxx(2) -- 1st byte of 3 byte sequence (4 payload bits here)
+ * 11110xxx(2) -- 1st byte of 4 byte sequence (3 payload bits here)
+ * 10xxxxxx(2) -- extension byte (6 payload bits per byte)
+ * Some values implied by the above are however illegal because they
+ * do not represent unicode chars or are not the shortest encoding.
+ * Actually, we can almost entirely ignore the above and just do
+ * text processing same as for ascii text.
+ *
+ * XML is written with arbitrary unicode characters, except that five
+ * characters have special meaning and so must be escaped where they
+ * appear in payload data... which we do here.
+ */
+void xml_data_encode(struct wpabuf *buf, const char *data, int len)
+{
+ int i;
+ for (i = 0; i < len; i++) {
+ u8 c = ((u8 *) data)[i];
+ if (c == '<') {
+ wpabuf_put_str(buf, "&lt;");
+ continue;
+ }
+ if (c == '>') {
+ wpabuf_put_str(buf, "&gt;");
+ continue;
+ }
+ if (c == '&') {
+ wpabuf_put_str(buf, "&amp;");
+ continue;
+ }
+ if (c == '\'') {
+ wpabuf_put_str(buf, "&apos;");
+ continue;
+ }
+ if (c == '"') {
+ wpabuf_put_str(buf, "&quot;");
+ continue;
+ }
+ /*
+ * We could try to represent control characters using the
+ * sequence: &#x; where x is replaced by a hex numeral, but not
+ * clear why we would do this.
+ */
+ wpabuf_put_u8(buf, c);
+ }
+}
+
+
+/* xml_add_tagged_data -- format tagged data as a new xml line.
+ *
+ * tag must not have any special chars.
+ * data may have special chars, which are escaped.
+ */
+void xml_add_tagged_data(struct wpabuf *buf, const char *tag, const char *data)
+{
+ wpabuf_printf(buf, "<%s>", tag);
+ xml_data_encode(buf, data, os_strlen(data));
+ wpabuf_printf(buf, "</%s>\n", tag);
+}
+
+
+/* A POST body looks something like (per upnp spec):
+ * <?xml version="1.0"?>
+ * <s:Envelope
+ * xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
+ * s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
+ * <s:Body>
+ * <u:actionName xmlns:u="urn:schemas-upnp-org:service:serviceType:v">
+ * <argumentName>in arg value</argumentName>
+ * other in args and their values go here, if any
+ * </u:actionName>
+ * </s:Body>
+ * </s:Envelope>
+ *
+ * where :
+ * s: might be some other namespace name followed by colon
+ * u: might be some other namespace name followed by colon
+ * actionName will be replaced according to action requested
+ * schema following actionName will be WFA scheme instead
+ * argumentName will be actual argument name
+ * (in arg value) will be actual argument value
+ */
+char * xml_get_first_item(const char *doc, const char *item)
+{
+ const char *match = item;
+ int match_len = os_strlen(item);
+ const char *tag, *tagname, *end;
+ char *value;
+
+ /*
+ * This is crude: ignore any possible tag name conflicts and go right
+ * to the first tag of this name. This should be ok for the limited
+ * domain of UPnP messages.
+ */
+ for (;;) {
+ if (xml_next_tag(doc, &tag, &tagname, &end))
+ return NULL;
+ doc = end;
+ if (!os_strncasecmp(tagname, match, match_len) &&
+ *tag != '/' &&
+ (tagname[match_len] == '>' ||
+ !isgraph(tagname[match_len]))) {
+ break;
+ }
+ }
+ end = doc;
+ while (*end && *end != '<')
+ end++;
+ value = os_zalloc(1 + (end - doc));
+ if (value == NULL)
+ return NULL;
+ os_memcpy(value, doc, end - doc);
+ return value;
+}
+
+
+struct wpabuf * xml_get_base64_item(const char *data, const char *name,
+ enum http_reply_code *ret)
+{
+ char *msg;
+ struct wpabuf *buf;
+ unsigned char *decoded;
+ size_t len;
+
+ msg = xml_get_first_item(data, name);
+ if (msg == NULL) {
+ *ret = UPNP_ARG_VALUE_INVALID;
+ return NULL;
+ }
+
+ decoded = base64_decode((unsigned char *) msg, os_strlen(msg), &len);
+ os_free(msg);
+ if (decoded == NULL) {
+ *ret = UPNP_OUT_OF_MEMORY;
+ return NULL;
+ }
+
+ buf = wpabuf_alloc_ext_data(decoded, len);
+ if (buf == NULL) {
+ os_free(decoded);
+ *ret = UPNP_OUT_OF_MEMORY;
+ return NULL;
+ }
+ return buf;
+}
diff --git a/contrib/wpa/src/wps/upnp_xml.h b/contrib/wpa/src/wps/upnp_xml.h
new file mode 100644
index 0000000..62dbe60
--- /dev/null
+++ b/contrib/wpa/src/wps/upnp_xml.h
@@ -0,0 +1,23 @@
+/*
+ * UPnP XML helper routines
+ * Copyright (c) 2000-2003 Intel Corporation
+ * Copyright (c) 2006-2007 Sony Corporation
+ * Copyright (c) 2008-2009 Atheros Communications
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ *
+ * See wps_upnp.c for more details on licensing and code history.
+ */
+
+#ifndef UPNP_XML_H
+#define UPNP_XML_H
+
+#include "http.h"
+
+void xml_data_encode(struct wpabuf *buf, const char *data, int len);
+void xml_add_tagged_data(struct wpabuf *buf, const char *tag,
+ const char *data);
+char * xml_get_first_item(const char *doc, const char *item);
+struct wpabuf * xml_get_base64_item(const char *data, const char *name,
+ enum http_reply_code *ret);
+
+#endif /* UPNP_XML_H */
diff --git a/contrib/wpa/src/wps/wps.c b/contrib/wpa/src/wps/wps.c
index 395eba6..619af15 100644
--- a/contrib/wpa/src/wps/wps.c
+++ b/contrib/wpa/src/wps/wps.c
@@ -1,6 +1,6 @@
/*
* Wi-Fi Protected Setup
- * Copyright (c) 2007-2008, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2007-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -15,9 +15,10 @@
#include "includes.h"
#include "common.h"
+#include "crypto/dh_group5.h"
+#include "common/ieee802_11_defs.h"
#include "wps_i.h"
#include "wps_dev_attr.h"
-#include "ieee802_11_defs.h"
/**
@@ -44,7 +45,8 @@ struct wps_data * wps_init(const struct wps_config *cfg)
os_memcpy(data->uuid_e, cfg->wps->uuid, WPS_UUID_LEN);
}
if (cfg->pin) {
- data->dev_pw_id = DEV_PW_DEFAULT;
+ data->dev_pw_id = data->wps->oob_dev_pw_id == 0 ?
+ DEV_PW_DEFAULT : data->wps->oob_dev_pw_id;
data->dev_password = os_malloc(cfg->pin_len);
if (data->dev_password == NULL) {
os_free(data);
@@ -88,6 +90,22 @@ struct wps_data * wps_init(const struct wps_config *cfg)
}
}
+ if (cfg->new_ap_settings) {
+ data->new_ap_settings =
+ os_malloc(sizeof(*data->new_ap_settings));
+ if (data->new_ap_settings == NULL) {
+ os_free(data);
+ return NULL;
+ }
+ os_memcpy(data->new_ap_settings, cfg->new_ap_settings,
+ sizeof(*data->new_ap_settings));
+ }
+
+ if (cfg->peer_addr)
+ os_memcpy(data->peer_dev.mac_addr, cfg->peer_addr, ETH_ALEN);
+
+ data->use_psk_key = cfg->use_psk_key;
+
return data;
}
@@ -114,6 +132,8 @@ void wps_deinit(struct wps_data *data)
os_free(data->dev_password);
os_free(data->new_psk);
wps_device_data_free(&data->peer_dev);
+ os_free(data->new_ap_settings);
+ dh5_free(data->dh_ctx);
os_free(data);
}
@@ -269,6 +289,39 @@ struct wpabuf * wps_build_assoc_req_ie(enum wps_request_type req_type)
/**
+ * wps_build_assoc_resp_ie - Build WPS IE for (Re)Association Response
+ * Returns: WPS IE or %NULL on failure
+ *
+ * The caller is responsible for freeing the buffer.
+ */
+struct wpabuf * wps_build_assoc_resp_ie(void)
+{
+ struct wpabuf *ie;
+ u8 *len;
+
+ wpa_printf(MSG_DEBUG, "WPS: Building WPS IE for (Re)Association "
+ "Response");
+ ie = wpabuf_alloc(100);
+ if (ie == NULL)
+ return NULL;
+
+ wpabuf_put_u8(ie, WLAN_EID_VENDOR_SPECIFIC);
+ len = wpabuf_put(ie, 1);
+ wpabuf_put_be32(ie, WPS_DEV_OUI_WFA);
+
+ if (wps_build_version(ie) ||
+ wps_build_resp_type(ie, WPS_RESP_AP)) {
+ wpabuf_free(ie);
+ return NULL;
+ }
+
+ *len = wpabuf_len(ie) - 2;
+
+ return ie;
+}
+
+
+/**
* wps_build_probe_req_ie - Build WPS IE for Probe Request
* @pbc: Whether searching for PBC mode APs
* @dev: Device attributes
@@ -298,9 +351,16 @@ struct wpabuf * wps_build_probe_req_ie(int pbc, struct wps_device_data *dev,
if (pbc)
methods = WPS_CONFIG_PUSHBUTTON;
- else
+ else {
methods = WPS_CONFIG_LABEL | WPS_CONFIG_DISPLAY |
WPS_CONFIG_KEYPAD;
+#ifdef CONFIG_WPS_UFD
+ methods |= WPS_CONFIG_USBA;
+#endif /* CONFIG_WPS_UFD */
+#ifdef CONFIG_WPS_NFC
+ methods |= WPS_CONFIG_NFC_INTERFACE;
+#endif /* CONFIG_WPS_NFC */
+ }
if (wps_build_version(ie) ||
wps_build_req_type(ie, req_type) ||
@@ -333,3 +393,105 @@ void wps_free_pending_msgs(struct upnp_pending_message *msgs)
os_free(prev);
}
}
+
+
+int wps_attr_text(struct wpabuf *data, char *buf, char *end)
+{
+ struct wps_parse_attr attr;
+ char *pos = buf;
+ int ret;
+
+ if (wps_parse_msg(data, &attr) < 0)
+ return -1;
+
+ if (attr.wps_state) {
+ if (*attr.wps_state == WPS_STATE_NOT_CONFIGURED)
+ ret = os_snprintf(pos, end - pos,
+ "wps_state=unconfigured\n");
+ else if (*attr.wps_state == WPS_STATE_CONFIGURED)
+ ret = os_snprintf(pos, end - pos,
+ "wps_state=configured\n");
+ else
+ ret = 0;
+ if (ret < 0 || ret >= end - pos)
+ return pos - buf;
+ pos += ret;
+ }
+
+ if (attr.ap_setup_locked && *attr.ap_setup_locked) {
+ ret = os_snprintf(pos, end - pos,
+ "wps_ap_setup_locked=1\n");
+ if (ret < 0 || ret >= end - pos)
+ return pos - buf;
+ pos += ret;
+ }
+
+ if (attr.selected_registrar && *attr.selected_registrar) {
+ ret = os_snprintf(pos, end - pos,
+ "wps_selected_registrar=1\n");
+ if (ret < 0 || ret >= end - pos)
+ return pos - buf;
+ pos += ret;
+ }
+
+ if (attr.dev_password_id) {
+ ret = os_snprintf(pos, end - pos,
+ "wps_device_password_id=%u\n",
+ WPA_GET_BE16(attr.dev_password_id));
+ if (ret < 0 || ret >= end - pos)
+ return pos - buf;
+ pos += ret;
+ }
+
+ if (attr.sel_reg_config_methods) {
+ ret = os_snprintf(pos, end - pos,
+ "wps_selected_registrar_config_methods="
+ "0x%04x\n",
+ WPA_GET_BE16(attr.sel_reg_config_methods));
+ if (ret < 0 || ret >= end - pos)
+ return pos - buf;
+ pos += ret;
+ }
+
+ if (attr.primary_dev_type) {
+ char devtype[WPS_DEV_TYPE_BUFSIZE];
+ ret = os_snprintf(pos, end - pos,
+ "wps_primary_device_type=%s\n",
+ wps_dev_type_bin2str(attr.primary_dev_type,
+ devtype,
+ sizeof(devtype)));
+ if (ret < 0 || ret >= end - pos)
+ return pos - buf;
+ pos += ret;
+ }
+
+ if (attr.dev_name) {
+ char *str = os_malloc(attr.dev_name_len + 1);
+ size_t i;
+ if (str == NULL)
+ return pos - buf;
+ for (i = 0; i < attr.dev_name_len; i++) {
+ if (attr.dev_name[i] < 32)
+ str[i] = '_';
+ else
+ str[i] = attr.dev_name[i];
+ }
+ str[i] = '\0';
+ ret = os_snprintf(pos, end - pos, "wps_device_name=%s\n", str);
+ os_free(str);
+ if (ret < 0 || ret >= end - pos)
+ return pos - buf;
+ pos += ret;
+ }
+
+ if (attr.config_methods) {
+ ret = os_snprintf(pos, end - pos,
+ "wps_config_methods=0x%04x\n",
+ WPA_GET_BE16(attr.config_methods));
+ if (ret < 0 || ret >= end - pos)
+ return pos - buf;
+ pos += ret;
+ }
+
+ return pos - buf;
+}
diff --git a/contrib/wpa/src/wps/wps.h b/contrib/wpa/src/wps/wps.h
index faf32c4..1fd1e52 100644
--- a/contrib/wpa/src/wps/wps.h
+++ b/contrib/wpa/src/wps/wps.h
@@ -1,6 +1,6 @@
/*
* Wi-Fi Protected Setup
- * Copyright (c) 2007-2008, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2007-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -32,6 +32,7 @@ enum wsc_op_code {
struct wps_registrar;
struct upnp_wps_device_sm;
+struct wps_er;
/**
* struct wps_credential - WPS Credential
@@ -60,6 +61,9 @@ struct wps_credential {
size_t cred_attr_len;
};
+#define WPS_DEV_TYPE_LEN 8
+#define WPS_DEV_TYPE_BUFSIZE 21
+
/**
* struct wps_device_data - WPS Device Data
* @mac_addr: Device MAC address
@@ -68,9 +72,7 @@ struct wps_credential {
* @model_name: Model Name (0..32 octets encoded in UTF-8)
* @model_number: Model Number (0..32 octets encoded in UTF-8)
* @serial_number: Serial Number (0..32 octets encoded in UTF-8)
- * @categ: Primary Device Category
- * @oui: Primary Device OUI
- * @sub_categ: Primary Device Sub-Category
+ * @pri_dev_type: Primary Device Type
* @os_version: OS Version
* @rf_bands: RF bands (WPS_RF_24GHZ, WPS_RF_50GHZ flags)
*/
@@ -81,13 +83,22 @@ struct wps_device_data {
char *model_name;
char *model_number;
char *serial_number;
- u16 categ;
- u32 oui;
- u16 sub_categ;
+ u8 pri_dev_type[WPS_DEV_TYPE_LEN];
u32 os_version;
u8 rf_bands;
};
+struct oob_conf_data {
+ enum {
+ OOB_METHOD_UNKNOWN = 0,
+ OOB_METHOD_DEV_PWD_E,
+ OOB_METHOD_DEV_PWD_R,
+ OOB_METHOD_CRED,
+ } oob_method;
+ struct wpabuf *dev_password;
+ struct wpabuf *pubkey_hash;
+};
+
/**
* struct wps_config - WPS configuration for a single registration protocol run
*/
@@ -121,6 +132,30 @@ struct wps_config {
* assoc_wps_ie: (Re)AssocReq WPS IE (in AP; %NULL if not AP)
*/
const struct wpabuf *assoc_wps_ie;
+
+ /**
+ * new_ap_settings - New AP settings (%NULL if not used)
+ *
+ * This parameter provides new AP settings when using a wireless
+ * stations as a Registrar to configure the AP. %NULL means that AP
+ * will not be reconfigured, i.e., the station will only learn the
+ * current AP settings by using AP PIN.
+ */
+ const struct wps_credential *new_ap_settings;
+
+ /**
+ * peer_addr: MAC address of the peer in AP; %NULL if not AP
+ */
+ const u8 *peer_addr;
+
+ /**
+ * use_psk_key - Use PSK format key in Credential
+ *
+ * Force PSK format to be used instead of ASCII passphrase when
+ * building Credential for an Enrollee. The PSK value is set in
+ * struct wpa_context::psk.
+ */
+ int use_psk_key;
};
struct wps_data * wps_init(const struct wps_config *cfg);
@@ -163,6 +198,7 @@ int wps_is_selected_pin_registrar(const struct wpabuf *msg);
const u8 * wps_get_uuid_e(const struct wpabuf *msg);
struct wpabuf * wps_build_assoc_req_ie(enum wps_request_type req_type);
+struct wpabuf * wps_build_assoc_resp_ie(void);
struct wpabuf * wps_build_probe_req_ie(int pbc, struct wps_device_data *dev,
const u8 *uuid,
enum wps_request_type req_type);
@@ -189,16 +225,15 @@ struct wps_registrar_config {
* set_ie_cb - Callback for WPS IE changes
* @ctx: Higher layer context data (cb_ctx)
* @beacon_ie: WPS IE for Beacon
- * @beacon_ie_len: WPS IE length for Beacon
* @probe_resp_ie: WPS IE for Probe Response
- * @probe_resp_ie_len: WPS IE length for Probe Response
* Returns: 0 on success, -1 on failure
*
* This callback is called whenever the WPS IE in Beacon or Probe
- * Response frames needs to be changed (AP only).
+ * Response frames needs to be changed (AP only). Callee is responsible
+ * for freeing the buffers.
*/
- int (*set_ie_cb)(void *ctx, const u8 *beacon_ie, size_t beacon_ie_len,
- const u8 *probe_resp_ie, size_t probe_resp_ie_len);
+ int (*set_ie_cb)(void *ctx, struct wpabuf *beacon_ie,
+ struct wpabuf *probe_resp_ie);
/**
* pin_needed_cb - Callback for requesting a PIN
@@ -226,6 +261,40 @@ struct wps_registrar_config {
const u8 *uuid_e);
/**
+ * set_sel_reg_cb - Callback for reporting selected registrar changes
+ * @ctx: Higher layer context data (cb_ctx)
+ * @sel_reg: Whether the Registrar is selected
+ * @dev_passwd_id: Device Password ID to indicate with method or
+ * specific password the Registrar intends to use
+ * @sel_reg_config_methods: Bit field of active config methods
+ *
+ * This callback is called whenever the Selected Registrar state
+ * changes (e.g., a new PIN becomes available or PBC is invoked). This
+ * callback is only used by External Registrar implementation;
+ * set_ie_cb() is used by AP implementation in similar caes, but it
+ * provides the full WPS IE data instead of just the minimal Registrar
+ * state information.
+ */
+ void (*set_sel_reg_cb)(void *ctx, int sel_reg, u16 dev_passwd_id,
+ u16 sel_reg_config_methods);
+
+ /**
+ * enrollee_seen_cb - Callback for reporting Enrollee based on ProbeReq
+ * @ctx: Higher layer context data (cb_ctx)
+ * @addr: MAC address of the Enrollee
+ * @uuid_e: UUID of the Enrollee
+ * @pri_dev_type: Primary device type
+ * @config_methods: Config Methods
+ * @dev_password_id: Device Password ID
+ * @request_type: Request Type
+ * @dev_name: Device Name (if available)
+ */
+ void (*enrollee_seen_cb)(void *ctx, const u8 *addr, const u8 *uuid_e,
+ const u8 *pri_dev_type, u16 config_methods,
+ u16 dev_password_id, u8 request_type,
+ const char *dev_name);
+
+ /**
* cb_ctx: Higher layer context data for Registrar callbacks
*/
void *cb_ctx;
@@ -306,7 +375,27 @@ enum wps_event {
/**
* WPS_EV_PBC_TIMEOUT - PBC walktime expired before protocol run start
*/
- WPS_EV_PBC_TIMEOUT
+ WPS_EV_PBC_TIMEOUT,
+
+ /**
+ * WPS_EV_ER_AP_ADD - ER: AP added
+ */
+ WPS_EV_ER_AP_ADD,
+
+ /**
+ * WPS_EV_ER_AP_REMOVE - ER: AP removed
+ */
+ WPS_EV_ER_AP_REMOVE,
+
+ /**
+ * WPS_EV_ER_ENROLLEE_ADD - ER: Enrollee added
+ */
+ WPS_EV_ER_ENROLLEE_ADD,
+
+ /**
+ * WPS_EV_ER_ENROLLEE_REMOVE - ER: Enrollee removed
+ */
+ WPS_EV_ER_ENROLLEE_REMOVE
};
/**
@@ -345,6 +434,36 @@ union wps_event_data {
int enrollee;
int part;
} pwd_auth_fail;
+
+ struct wps_event_er_ap {
+ const u8 *uuid;
+ const u8 *mac_addr;
+ const char *friendly_name;
+ const char *manufacturer;
+ const char *manufacturer_url;
+ const char *model_description;
+ const char *model_name;
+ const char *model_number;
+ const char *model_url;
+ const char *serial_number;
+ const char *upc;
+ const u8 *pri_dev_type;
+ u8 wps_state;
+ } ap;
+
+ struct wps_event_er_enrollee {
+ const u8 *uuid;
+ const u8 *mac_addr;
+ int m1_received;
+ u16 config_methods;
+ u16 dev_passwd_id;
+ const u8 *pri_dev_type;
+ const char *dev_name;
+ const char *manufacturer;
+ const char *model_name;
+ const char *model_number;
+ const char *serial_number;
+ } enrollee;
};
/**
@@ -413,6 +532,31 @@ struct wps_context {
struct wps_device_data dev;
/**
+ * oob_conf - OOB Config data
+ */
+ struct oob_conf_data oob_conf;
+
+ /**
+ * oob_dev_pw_id - OOB Device password id
+ */
+ u16 oob_dev_pw_id;
+
+ /**
+ * dh_ctx - Context data for Diffie-Hellman operation
+ */
+ void *dh_ctx;
+
+ /**
+ * dh_privkey - Diffie-Hellman private key
+ */
+ struct wpabuf *dh_privkey;
+
+ /**
+ * dh_pubkey_oob - Diffie-Hellman public key
+ */
+ struct wpabuf *dh_pubkey;
+
+ /**
* config_methods - Enabled configuration methods
*
* Bit field of WPS_CONFIG_*
@@ -435,6 +579,14 @@ struct wps_context {
* If %NULL, Registrar will generate per-device PSK. In addition, AP
* uses this when acting as an Enrollee to notify Registrar of the
* current configuration.
+ *
+ * When using WPA/WPA2-Person, this key can be either the ASCII
+ * passphrase (8..63 characters) or the 32-octet PSK (64 hex
+ * characters). When this is set to the ASCII passphrase, the PSK can
+ * be provided in the psk buffer and used per-Enrollee to control which
+ * key type is included in the Credential (e.g., to reduce calculation
+ * need on low-powered devices by provisioning PSK while still allowing
+ * other devices to get the passphrase).
*/
u8 *network_key;
@@ -444,6 +596,19 @@ struct wps_context {
size_t network_key_len;
/**
+ * psk - The current network PSK
+ *
+ * This optional value can be used to provide the current PSK if
+ * network_key is set to the ASCII passphrase.
+ */
+ u8 psk[32];
+
+ /**
+ * psk_set - Whether psk value is set
+ */
+ int psk_set;
+
+ /**
* ap_settings - AP Settings override for M7 (only used at AP)
*
* If %NULL, AP Settings attributes will be generated based on the
@@ -509,6 +674,22 @@ struct wps_context {
struct upnp_pending_message *upnp_msgs;
};
+struct oob_device_data {
+ char *device_name;
+ char *device_path;
+ void * (*init_func)(struct wps_context *, struct oob_device_data *,
+ int);
+ struct wpabuf * (*read_func)(void *);
+ int (*write_func)(void *, struct wpabuf *);
+ void (*deinit_func)(void *);
+};
+
+struct oob_nfc_device_data {
+ int (*init_func)(char *);
+ void * (*read_func)(size_t *);
+ int (*write_func)(void *, size_t);
+ void (*deinit_func)(void);
+};
struct wps_registrar *
wps_registrar_init(struct wps_context *wps,
@@ -522,12 +703,34 @@ int wps_registrar_button_pushed(struct wps_registrar *reg);
void wps_registrar_probe_req_rx(struct wps_registrar *reg, const u8 *addr,
const struct wpabuf *wps_data);
int wps_registrar_update_ie(struct wps_registrar *reg);
-int wps_registrar_set_selected_registrar(struct wps_registrar *reg,
- const struct wpabuf *msg);
+int wps_registrar_get_info(struct wps_registrar *reg, const u8 *addr,
+ char *buf, size_t buflen);
unsigned int wps_pin_checksum(unsigned int pin);
unsigned int wps_pin_valid(unsigned int pin);
unsigned int wps_generate_pin(void);
void wps_free_pending_msgs(struct upnp_pending_message *msgs);
+struct oob_device_data * wps_get_oob_device(char *device_type);
+struct oob_nfc_device_data * wps_get_oob_nfc_device(char *device_name);
+int wps_get_oob_method(char *method);
+int wps_process_oob(struct wps_context *wps, struct oob_device_data *oob_dev,
+ int registrar);
+int wps_attr_text(struct wpabuf *data, char *buf, char *end);
+
+struct wps_er * wps_er_init(struct wps_context *wps, const char *ifname);
+void wps_er_refresh(struct wps_er *er);
+void wps_er_deinit(struct wps_er *er, void (*cb)(void *ctx), void *ctx);
+void wps_er_set_sel_reg(struct wps_er *er, int sel_reg, u16 dev_passwd_id,
+ u16 sel_reg_config_methods);
+int wps_er_pbc(struct wps_er *er, const u8 *uuid);
+int wps_er_learn(struct wps_er *er, const u8 *uuid, const u8 *pin,
+ size_t pin_len);
+
+int wps_dev_type_str2bin(const char *str, u8 dev_type[WPS_DEV_TYPE_LEN]);
+char * wps_dev_type_bin2str(const u8 dev_type[WPS_DEV_TYPE_LEN], char *buf,
+ size_t buf_len);
+void uuid_gen_mac_addr(const u8 *mac_addr, u8 *uuid);
+u16 wps_config_methods_str2bin(const char *str);
+
#endif /* WPS_H */
diff --git a/contrib/wpa/src/wps/wps_attr_build.c b/contrib/wpa/src/wps/wps_attr_build.c
index edeff5c..9da556a 100644
--- a/contrib/wpa/src/wps/wps_attr_build.c
+++ b/contrib/wpa/src/wps/wps_attr_build.c
@@ -15,9 +15,10 @@
#include "includes.h"
#include "common.h"
-#include "dh_groups.h"
-#include "sha256.h"
-#include "aes_wrap.h"
+#include "crypto/aes_wrap.h"
+#include "crypto/crypto.h"
+#include "crypto/dh_group5.h"
+#include "crypto/sha256.h"
#include "wps_i.h"
@@ -26,11 +27,24 @@ int wps_build_public_key(struct wps_data *wps, struct wpabuf *msg)
struct wpabuf *pubkey;
wpa_printf(MSG_DEBUG, "WPS: * Public Key");
- pubkey = dh_init(dh_groups_get(WPS_DH_GROUP), &wps->dh_privkey);
- pubkey = wpabuf_zeropad(pubkey, 192);
- if (pubkey == NULL) {
+ wpabuf_free(wps->dh_privkey);
+ if (wps->dev_pw_id != DEV_PW_DEFAULT && wps->wps->dh_privkey) {
+ wpa_printf(MSG_DEBUG, "WPS: Using pre-configured DH keys");
+ wps->dh_privkey = wpabuf_dup(wps->wps->dh_privkey);
+ wps->dh_ctx = wps->wps->dh_ctx;
+ wps->wps->dh_ctx = NULL;
+ pubkey = wpabuf_dup(wps->wps->dh_pubkey);
+ } else {
+ wpa_printf(MSG_DEBUG, "WPS: Generate new DH keys");
+ wps->dh_privkey = NULL;
+ dh5_free(wps->dh_ctx);
+ wps->dh_ctx = dh5_init(&wps->dh_privkey, &pubkey);
+ pubkey = wpabuf_zeropad(pubkey, 192);
+ }
+ if (wps->dh_ctx == NULL || wps->dh_privkey == NULL || pubkey == NULL) {
wpa_printf(MSG_DEBUG, "WPS: Failed to initialize "
"Diffie-Hellman handshake");
+ wpabuf_free(pubkey);
return -1;
}
@@ -60,6 +74,16 @@ int wps_build_req_type(struct wpabuf *msg, enum wps_request_type type)
}
+int wps_build_resp_type(struct wpabuf *msg, enum wps_response_type type)
+{
+ wpa_printf(MSG_DEBUG, "WPS: * Response Type (%d)", type);
+ wpabuf_put_be16(msg, ATTR_RESPONSE_TYPE);
+ wpabuf_put_be16(msg, 1);
+ wpabuf_put_u8(msg, type);
+ return 0;
+}
+
+
int wps_build_config_methods(struct wpabuf *msg, u16 methods)
{
wpa_printf(MSG_DEBUG, "WPS: * Config Methods (%x)", methods);
@@ -252,3 +276,47 @@ int wps_build_encr_settings(struct wps_data *wps, struct wpabuf *msg,
return 0;
}
+
+
+#ifdef CONFIG_WPS_OOB
+int wps_build_oob_dev_password(struct wpabuf *msg, struct wps_context *wps)
+{
+ size_t hash_len;
+ const u8 *addr[1];
+ u8 pubkey_hash[WPS_HASH_LEN];
+ u8 dev_password_bin[WPS_OOB_DEVICE_PASSWORD_LEN];
+
+ wpa_printf(MSG_DEBUG, "WPS: * OOB Device Password");
+
+ addr[0] = wpabuf_head(wps->dh_pubkey);
+ hash_len = wpabuf_len(wps->dh_pubkey);
+ sha256_vector(1, addr, &hash_len, pubkey_hash);
+
+ if (os_get_random((u8 *) &wps->oob_dev_pw_id, sizeof(u16)) < 0) {
+ wpa_printf(MSG_ERROR, "WPS: device password id "
+ "generation error");
+ return -1;
+ }
+ wps->oob_dev_pw_id |= 0x0010;
+
+ if (os_get_random(dev_password_bin, WPS_OOB_DEVICE_PASSWORD_LEN) < 0) {
+ wpa_printf(MSG_ERROR, "WPS: OOB device password "
+ "generation error");
+ return -1;
+ }
+
+ wpabuf_put_be16(msg, ATTR_OOB_DEVICE_PASSWORD);
+ wpabuf_put_be16(msg, WPS_OOB_DEVICE_PASSWORD_ATTR_LEN);
+ wpabuf_put_data(msg, pubkey_hash, WPS_OOB_PUBKEY_HASH_LEN);
+ wpabuf_put_be16(msg, wps->oob_dev_pw_id);
+ wpabuf_put_data(msg, dev_password_bin, WPS_OOB_DEVICE_PASSWORD_LEN);
+
+ wpa_snprintf_hex_uppercase(
+ wpabuf_put(wps->oob_conf.dev_password,
+ wpabuf_size(wps->oob_conf.dev_password)),
+ wpabuf_size(wps->oob_conf.dev_password),
+ dev_password_bin, WPS_OOB_DEVICE_PASSWORD_LEN);
+
+ return 0;
+}
+#endif /* CONFIG_WPS_OOB */
diff --git a/contrib/wpa/src/wps/wps_attr_parse.c b/contrib/wpa/src/wps/wps_attr_parse.c
index f50ae39..30b0e79 100644
--- a/contrib/wpa/src/wps/wps_attr_parse.c
+++ b/contrib/wpa/src/wps/wps_attr_parse.c
@@ -17,6 +17,8 @@
#include "common.h"
#include "wps_i.h"
+#define WPS_WORKAROUNDS
+
static int wps_set_attr(struct wps_parse_attr *attr, u16 type,
const u8 *pos, u16 len)
@@ -111,7 +113,7 @@ static int wps_set_attr(struct wps_parse_attr *attr, u16 type,
attr->sel_reg_config_methods = pos;
break;
case ATTR_PRIMARY_DEV_TYPE:
- if (len != sizeof(struct wps_dev_type)) {
+ if (len != WPS_DEV_TYPE_LEN) {
wpa_printf(MSG_DEBUG, "WPS: Invalid Primary Device "
"Type length %u", len);
return -1;
@@ -150,6 +152,14 @@ static int wps_set_attr(struct wps_parse_attr *attr, u16 type,
}
attr->dev_password_id = pos;
break;
+ case ATTR_OOB_DEVICE_PASSWORD:
+ if (len != WPS_OOB_DEVICE_PASSWORD_ATTR_LEN) {
+ wpa_printf(MSG_DEBUG, "WPS: Invalid OOB Device "
+ "Password length %u", len);
+ return -1;
+ }
+ attr->oob_dev_password = pos;
+ break;
case ATTR_OS_VERSION:
if (len != 4) {
wpa_printf(MSG_DEBUG, "WPS: Invalid OS Version length "
@@ -324,7 +334,7 @@ static int wps_set_attr(struct wps_parse_attr *attr, u16 type,
"length %u", len);
return -1;
}
- attr->request_type = pos;
+ attr->response_type = pos;
break;
case ATTR_MANUFACTURER:
attr->manufacturer = pos;
@@ -427,6 +437,25 @@ int wps_parse_msg(const struct wpabuf *msg, struct wps_parse_attr *attr)
return -1;
}
+#ifdef WPS_WORKAROUNDS
+ if (type == 0 && len == 0) {
+ /*
+ * Mac OS X 10.6 seems to be adding 0x00 padding to the
+ * end of M1. Skip those to avoid interop issues.
+ */
+ int i;
+ for (i = 0; i < end - pos; i++) {
+ if (pos[i])
+ break;
+ }
+ if (i == end - pos) {
+ wpa_printf(MSG_DEBUG, "WPS: Workaround - skip "
+ "unexpected message padding");
+ break;
+ }
+ }
+#endif /* WPS_WORKAROUNDS */
+
if (wps_set_attr(attr, type, pos, len) < 0)
return -1;
diff --git a/contrib/wpa/src/wps/wps_attr_process.c b/contrib/wpa/src/wps/wps_attr_process.c
index ae6e906..4751bbc 100644
--- a/contrib/wpa/src/wps/wps_attr_process.c
+++ b/contrib/wpa/src/wps/wps_attr_process.c
@@ -15,7 +15,7 @@
#include "includes.h"
#include "common.h"
-#include "sha256.h"
+#include "crypto/sha256.h"
#include "wps_i.h"
@@ -177,6 +177,13 @@ static int wps_process_cred_network_key(struct wps_credential *cred,
if (key == NULL) {
wpa_printf(MSG_DEBUG, "WPS: Credential did not include "
"Network Key");
+ if (cred->auth_type == WPS_AUTH_OPEN &&
+ cred->encr_type == WPS_ENCR_NONE) {
+ wpa_printf(MSG_DEBUG, "WPS: Workaround - Allow "
+ "missing mandatory Network Key attribute "
+ "for open network");
+ return 0;
+ }
return -1;
}
diff --git a/contrib/wpa/src/wps/wps_common.c b/contrib/wpa/src/wps/wps_common.c
index 4b45f00..6ef14db 100644
--- a/contrib/wpa/src/wps/wps_common.c
+++ b/contrib/wpa/src/wps/wps_common.c
@@ -1,6 +1,6 @@
/*
* Wi-Fi Protected Setup - common functionality
- * Copyright (c) 2008, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2008-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -15,10 +15,11 @@
#include "includes.h"
#include "common.h"
-#include "dh_groups.h"
-#include "sha256.h"
-#include "aes_wrap.h"
-#include "crypto.h"
+#include "crypto/aes_wrap.h"
+#include "crypto/crypto.h"
+#include "crypto/dh_group5.h"
+#include "crypto/sha1.h"
+#include "crypto/sha256.h"
#include "wps_i.h"
#include "wps_dev_attr.h"
@@ -80,8 +81,9 @@ int wps_derive_keys(struct wps_data *wps)
return -1;
}
- dh_shared = dh_derive_shared(pubkey, wps->dh_privkey,
- dh_groups_get(WPS_DH_GROUP));
+ dh_shared = dh5_derive_shared(wps->dh_ctx, pubkey, wps->dh_privkey);
+ dh5_free(wps->dh_ctx);
+ wps->dh_ctx = NULL;
dh_shared = wpabuf_zeropad(dh_shared, 192);
if (dh_shared == NULL) {
wpa_printf(MSG_DEBUG, "WPS: Failed to derive DH shared key");
@@ -303,3 +305,331 @@ void wps_pbc_timeout_event(struct wps_context *wps)
wps->event_cb(wps->cb_ctx, WPS_EV_PBC_TIMEOUT, NULL);
}
+
+
+#ifdef CONFIG_WPS_OOB
+
+static struct wpabuf * wps_get_oob_cred(struct wps_context *wps)
+{
+ struct wps_data data;
+ struct wpabuf *plain;
+
+ plain = wpabuf_alloc(500);
+ if (plain == NULL) {
+ wpa_printf(MSG_ERROR, "WPS: Failed to allocate memory for OOB "
+ "credential");
+ return NULL;
+ }
+
+ os_memset(&data, 0, sizeof(data));
+ data.wps = wps;
+ data.auth_type = wps->auth_types;
+ data.encr_type = wps->encr_types;
+ if (wps_build_version(plain) || wps_build_cred(&data, plain)) {
+ wpabuf_free(plain);
+ return NULL;
+ }
+
+ return plain;
+}
+
+
+static struct wpabuf * wps_get_oob_dev_pwd(struct wps_context *wps)
+{
+ struct wpabuf *data;
+
+ data = wpabuf_alloc(9 + WPS_OOB_DEVICE_PASSWORD_ATTR_LEN);
+ if (data == NULL) {
+ wpa_printf(MSG_ERROR, "WPS: Failed to allocate memory for OOB "
+ "device password attribute");
+ return NULL;
+ }
+
+ wpabuf_free(wps->oob_conf.dev_password);
+ wps->oob_conf.dev_password =
+ wpabuf_alloc(WPS_OOB_DEVICE_PASSWORD_LEN * 2 + 1);
+ if (wps->oob_conf.dev_password == NULL) {
+ wpa_printf(MSG_ERROR, "WPS: Failed to allocate memory for OOB "
+ "device password");
+ wpabuf_free(data);
+ return NULL;
+ }
+
+ if (wps_build_version(data) ||
+ wps_build_oob_dev_password(data, wps)) {
+ wpa_printf(MSG_ERROR, "WPS: Build OOB device password "
+ "attribute error");
+ wpabuf_free(data);
+ return NULL;
+ }
+
+ return data;
+}
+
+
+static int wps_parse_oob_dev_pwd(struct wps_context *wps,
+ struct wpabuf *data)
+{
+ struct oob_conf_data *oob_conf = &wps->oob_conf;
+ struct wps_parse_attr attr;
+ const u8 *pos;
+
+ if (wps_parse_msg(data, &attr) < 0 ||
+ attr.oob_dev_password == NULL) {
+ wpa_printf(MSG_ERROR, "WPS: OOB device password not found");
+ return -1;
+ }
+
+ pos = attr.oob_dev_password;
+
+ oob_conf->pubkey_hash =
+ wpabuf_alloc_copy(pos, WPS_OOB_PUBKEY_HASH_LEN);
+ if (oob_conf->pubkey_hash == NULL) {
+ wpa_printf(MSG_ERROR, "WPS: Failed to allocate memory for OOB "
+ "public key hash");
+ return -1;
+ }
+ pos += WPS_OOB_PUBKEY_HASH_LEN;
+
+ wps->oob_dev_pw_id = WPA_GET_BE16(pos);
+ pos += sizeof(wps->oob_dev_pw_id);
+
+ oob_conf->dev_password =
+ wpabuf_alloc(WPS_OOB_DEVICE_PASSWORD_LEN * 2 + 1);
+ if (oob_conf->dev_password == NULL) {
+ wpa_printf(MSG_ERROR, "WPS: Failed to allocate memory for OOB "
+ "device password");
+ return -1;
+ }
+ wpa_snprintf_hex_uppercase(wpabuf_put(oob_conf->dev_password,
+ wpabuf_size(oob_conf->dev_password)),
+ wpabuf_size(oob_conf->dev_password), pos,
+ WPS_OOB_DEVICE_PASSWORD_LEN);
+
+ return 0;
+}
+
+
+static int wps_parse_oob_cred(struct wps_context *wps, struct wpabuf *data)
+{
+ struct wpabuf msg;
+ struct wps_parse_attr attr;
+ size_t i;
+
+ if (wps_parse_msg(data, &attr) < 0 || attr.num_cred <= 0) {
+ wpa_printf(MSG_ERROR, "WPS: OOB credential not found");
+ return -1;
+ }
+
+ for (i = 0; i < attr.num_cred; i++) {
+ struct wps_credential local_cred;
+ struct wps_parse_attr cattr;
+
+ os_memset(&local_cred, 0, sizeof(local_cred));
+ wpabuf_set(&msg, attr.cred[i], attr.cred_len[i]);
+ if (wps_parse_msg(&msg, &cattr) < 0 ||
+ wps_process_cred(&cattr, &local_cred)) {
+ wpa_printf(MSG_ERROR, "WPS: Failed to parse OOB "
+ "credential");
+ return -1;
+ }
+ wps->cred_cb(wps->cb_ctx, &local_cred);
+ }
+
+ return 0;
+}
+
+
+int wps_process_oob(struct wps_context *wps, struct oob_device_data *oob_dev,
+ int registrar)
+{
+ struct wpabuf *data;
+ int ret, write_f, oob_method = wps->oob_conf.oob_method;
+ void *oob_priv;
+
+ write_f = oob_method == OOB_METHOD_DEV_PWD_E ? !registrar : registrar;
+
+ oob_priv = oob_dev->init_func(wps, oob_dev, registrar);
+ if (oob_priv == NULL) {
+ wpa_printf(MSG_ERROR, "WPS: Failed to initialize OOB device");
+ return -1;
+ }
+
+ if (write_f) {
+ if (oob_method == OOB_METHOD_CRED)
+ data = wps_get_oob_cred(wps);
+ else
+ data = wps_get_oob_dev_pwd(wps);
+
+ ret = 0;
+ if (data == NULL || oob_dev->write_func(oob_priv, data) < 0)
+ ret = -1;
+ } else {
+ data = oob_dev->read_func(oob_priv);
+ if (data == NULL)
+ ret = -1;
+ else {
+ if (oob_method == OOB_METHOD_CRED)
+ ret = wps_parse_oob_cred(wps, data);
+ else
+ ret = wps_parse_oob_dev_pwd(wps, data);
+ }
+ }
+ wpabuf_free(data);
+ oob_dev->deinit_func(oob_priv);
+
+ if (ret < 0) {
+ wpa_printf(MSG_ERROR, "WPS: Failed to process OOB data");
+ return -1;
+ }
+
+ return 0;
+}
+
+
+struct oob_device_data * wps_get_oob_device(char *device_type)
+{
+#ifdef CONFIG_WPS_UFD
+ if (os_strstr(device_type, "ufd") != NULL)
+ return &oob_ufd_device_data;
+#endif /* CONFIG_WPS_UFD */
+#ifdef CONFIG_WPS_NFC
+ if (os_strstr(device_type, "nfc") != NULL)
+ return &oob_nfc_device_data;
+#endif /* CONFIG_WPS_NFC */
+
+ return NULL;
+}
+
+
+#ifdef CONFIG_WPS_NFC
+struct oob_nfc_device_data * wps_get_oob_nfc_device(char *device_name)
+{
+ if (device_name == NULL)
+ return NULL;
+#ifdef CONFIG_WPS_NFC_PN531
+ if (os_strstr(device_name, "pn531") != NULL)
+ return &oob_nfc_pn531_device_data;
+#endif /* CONFIG_WPS_NFC_PN531 */
+
+ return NULL;
+}
+#endif /* CONFIG_WPS_NFC */
+
+
+int wps_get_oob_method(char *method)
+{
+ if (os_strstr(method, "pin-e") != NULL)
+ return OOB_METHOD_DEV_PWD_E;
+ if (os_strstr(method, "pin-r") != NULL)
+ return OOB_METHOD_DEV_PWD_R;
+ if (os_strstr(method, "cred") != NULL)
+ return OOB_METHOD_CRED;
+ return OOB_METHOD_UNKNOWN;
+}
+
+#endif /* CONFIG_WPS_OOB */
+
+
+int wps_dev_type_str2bin(const char *str, u8 dev_type[WPS_DEV_TYPE_LEN])
+{
+ const char *pos;
+
+ /* <categ>-<OUI>-<subcateg> */
+ WPA_PUT_BE16(dev_type, atoi(str));
+ pos = os_strchr(str, '-');
+ if (pos == NULL)
+ return -1;
+ pos++;
+ if (hexstr2bin(pos, &dev_type[2], 4))
+ return -1;
+ pos = os_strchr(pos, '-');
+ if (pos == NULL)
+ return -1;
+ pos++;
+ WPA_PUT_BE16(&dev_type[6], atoi(pos));
+
+
+ return 0;
+}
+
+
+char * wps_dev_type_bin2str(const u8 dev_type[WPS_DEV_TYPE_LEN], char *buf,
+ size_t buf_len)
+{
+ int ret;
+
+ ret = os_snprintf(buf, buf_len, "%u-%08X-%u",
+ WPA_GET_BE16(dev_type), WPA_GET_BE32(&dev_type[2]),
+ WPA_GET_BE16(&dev_type[6]));
+ if (ret < 0 || (unsigned int) ret >= buf_len)
+ return NULL;
+
+ return buf;
+}
+
+
+void uuid_gen_mac_addr(const u8 *mac_addr, u8 *uuid)
+{
+ const u8 *addr[2];
+ size_t len[2];
+ u8 hash[SHA1_MAC_LEN];
+ u8 nsid[16] = {
+ 0x52, 0x64, 0x80, 0xf8,
+ 0xc9, 0x9b,
+ 0x4b, 0xe5,
+ 0xa6, 0x55,
+ 0x58, 0xed, 0x5f, 0x5d, 0x60, 0x84
+ };
+
+ addr[0] = nsid;
+ len[0] = sizeof(nsid);
+ addr[1] = mac_addr;
+ len[1] = 6;
+ sha1_vector(2, addr, len, hash);
+ os_memcpy(uuid, hash, 16);
+
+ /* Version: 5 = named-based version using SHA-1 */
+ uuid[6] = (5 << 4) | (uuid[6] & 0x0f);
+
+ /* Variant specified in RFC 4122 */
+ uuid[8] = 0x80 | (uuid[8] & 0x3f);
+}
+
+
+u16 wps_config_methods_str2bin(const char *str)
+{
+ u16 methods = 0;
+
+ if (str == NULL) {
+ /* Default to enabling methods based on build configuration */
+ methods |= WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD;
+#ifdef CONFIG_WPS_UFD
+ methods |= WPS_CONFIG_USBA;
+#endif /* CONFIG_WPS_UFD */
+#ifdef CONFIG_WPS_NFC
+ methods |= WPS_CONFIG_NFC_INTERFACE;
+#endif /* CONFIG_WPS_NFC */
+ } else {
+ if (os_strstr(str, "usba"))
+ methods |= WPS_CONFIG_USBA;
+ if (os_strstr(str, "ethernet"))
+ methods |= WPS_CONFIG_ETHERNET;
+ if (os_strstr(str, "label"))
+ methods |= WPS_CONFIG_LABEL;
+ if (os_strstr(str, "display"))
+ methods |= WPS_CONFIG_DISPLAY;
+ if (os_strstr(str, "ext_nfc_token"))
+ methods |= WPS_CONFIG_EXT_NFC_TOKEN;
+ if (os_strstr(str, "int_nfc_token"))
+ methods |= WPS_CONFIG_INT_NFC_TOKEN;
+ if (os_strstr(str, "nfc_interface"))
+ methods |= WPS_CONFIG_NFC_INTERFACE;
+ if (os_strstr(str, "push_button"))
+ methods |= WPS_CONFIG_PUSHBUTTON;
+ if (os_strstr(str, "keypad"))
+ methods |= WPS_CONFIG_KEYPAD;
+ }
+
+ return methods;
+}
diff --git a/contrib/wpa/src/wps/wps_defs.h b/contrib/wpa/src/wps/wps_defs.h
index bf6ccc5..750ca41 100644
--- a/contrib/wpa/src/wps/wps_defs.h
+++ b/contrib/wpa/src/wps/wps_defs.h
@@ -33,6 +33,9 @@
#define WPS_MGMTAUTHKEY_LEN 32
#define WPS_MGMTENCKEY_LEN 16
#define WPS_MGMT_KEY_ID_LEN 16
+#define WPS_OOB_DEVICE_PASSWORD_ATTR_LEN 54
+#define WPS_OOB_DEVICE_PASSWORD_LEN 32
+#define WPS_OOB_PUBKEY_HASH_LEN 20
/* Attribute Types */
enum wps_attribute {
@@ -112,7 +115,7 @@ enum wps_attribute {
ATTR_PERMITTED_CFG_METHODS = 0x1052,
ATTR_SELECTED_REGISTRAR_CONFIG_METHODS = 0x1053,
ATTR_PRIMARY_DEV_TYPE = 0x1054,
- ATTR_SECONDARY_DEV_TYP_ELIST = 0x1055,
+ ATTR_SECONDARY_DEV_TYPE_LIST = 0x1055,
ATTR_PORTABLE_DEV = 0x1056,
ATTR_AP_SETUP_LOCKED = 0x1057,
ATTR_APPLICATION_EXT = 0x1058,
@@ -229,13 +232,6 @@ enum wps_assoc_state {
};
-/* Primary Device Type */
-struct wps_dev_type {
- u8 categ_id[2];
- u8 oui[4];
- u8 sub_categ_id[2];
-};
-
#define WPS_DEV_OUI_WFA 0x0050f204
enum wps_dev_categ {
diff --git a/contrib/wpa/src/wps/wps_dev_attr.c b/contrib/wpa/src/wps/wps_dev_attr.c
index 35f58d1..090bfa2 100644
--- a/contrib/wpa/src/wps/wps_dev_attr.c
+++ b/contrib/wpa/src/wps/wps_dev_attr.c
@@ -113,14 +113,10 @@ static int wps_build_serial_number(struct wps_device_data *dev,
int wps_build_primary_dev_type(struct wps_device_data *dev, struct wpabuf *msg)
{
- struct wps_dev_type *d;
wpa_printf(MSG_DEBUG, "WPS: * Primary Device Type");
wpabuf_put_be16(msg, ATTR_PRIMARY_DEV_TYPE);
- wpabuf_put_be16(msg, sizeof(*d));
- d = wpabuf_put(msg, sizeof(*d));
- WPA_PUT_BE16(d->categ_id, dev->categ);
- WPA_PUT_BE32(d->oui, dev->oui);
- WPA_PUT_BE16(d->sub_categ_id, dev->sub_categ);
+ wpabuf_put_be16(msg, WPS_DEV_TYPE_LEN);
+ wpabuf_put_data(msg, dev->pri_dev_type, WPS_DEV_TYPE_LEN);
return 0;
}
@@ -288,21 +284,19 @@ static int wps_process_dev_name(struct wps_device_data *dev, const u8 *str,
static int wps_process_primary_dev_type(struct wps_device_data *dev,
const u8 *dev_type)
{
- struct wps_dev_type *d;
+#ifndef CONFIG_NO_STDOUT_DEBUG
+ char devtype[WPS_DEV_TYPE_BUFSIZE];
+#endif /* CONFIG_NO_STDOUT_DEBUG */
if (dev_type == NULL) {
wpa_printf(MSG_DEBUG, "WPS: No Primary Device Type received");
return -1;
}
- d = (struct wps_dev_type *) dev_type;
- dev->categ = WPA_GET_BE16(d->categ_id);
- dev->oui = WPA_GET_BE32(d->oui);
- dev->sub_categ = WPA_GET_BE16(d->sub_categ_id);
-
- wpa_printf(MSG_DEBUG, "WPS: Primary Device Type: category %d "
- "OUI %08x sub-category %d",
- dev->categ, dev->oui, dev->sub_categ);
+ os_memcpy(dev->pri_dev_type, dev_type, WPS_DEV_TYPE_LEN);
+ wpa_printf(MSG_DEBUG, "WPS: Primary Device Type: %s",
+ wps_dev_type_bin2str(dev->pri_dev_type, devtype,
+ sizeof(devtype)));
return 0;
}
@@ -367,9 +361,7 @@ void wps_device_data_dup(struct wps_device_data *dst,
dst->model_number = os_strdup(src->model_number);
if (src->serial_number)
dst->serial_number = os_strdup(src->serial_number);
- dst->categ = src->categ;
- dst->oui = src->oui;
- dst->sub_categ = src->sub_categ;
+ os_memcpy(dst->pri_dev_type, src->pri_dev_type, WPS_DEV_TYPE_LEN);
dst->os_version = src->os_version;
dst->rf_bands = src->rf_bands;
}
diff --git a/contrib/wpa/src/wps/wps_enrollee.c b/contrib/wpa/src/wps/wps_enrollee.c
index 5cb3e1e..dff24d4 100644
--- a/contrib/wpa/src/wps/wps_enrollee.c
+++ b/contrib/wpa/src/wps/wps_enrollee.c
@@ -15,7 +15,8 @@
#include "includes.h"
#include "common.h"
-#include "sha256.h"
+#include "crypto/crypto.h"
+#include "crypto/sha256.h"
#include "wps_i.h"
#include "wps_dev_attr.h"
@@ -118,7 +119,6 @@ static int wps_build_e_snonce2(struct wps_data *wps, struct wpabuf *msg)
static struct wpabuf * wps_build_m1(struct wps_data *wps)
{
struct wpabuf *msg;
- u16 methods;
if (os_get_random(wps->nonce_e, WPS_NONCE_LEN) < 0)
return NULL;
@@ -130,10 +130,6 @@ static struct wpabuf * wps_build_m1(struct wps_data *wps)
if (msg == NULL)
return NULL;
- methods = WPS_CONFIG_LABEL | WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD;
- if (wps->pbc)
- methods |= WPS_CONFIG_PUSHBUTTON;
-
if (wps_build_version(msg) ||
wps_build_msg_type(msg, WPS_M1) ||
wps_build_uuid_e(msg, wps->uuid_e) ||
@@ -143,7 +139,7 @@ static struct wpabuf * wps_build_m1(struct wps_data *wps)
wps_build_auth_type_flags(wps, msg) ||
wps_build_encr_type_flags(wps, msg) ||
wps_build_conn_type_flags(wps, msg) ||
- wps_build_config_methods(msg, methods) ||
+ wps_build_config_methods(msg, wps->wps->config_methods) ||
wps_build_wps_state(wps, msg) ||
wps_build_device_attrs(&wps->wps->dev, msg) ||
wps_build_rf_bands(&wps->wps->dev, msg) ||
@@ -321,6 +317,16 @@ static struct wpabuf * wps_build_m7(struct wps_data *wps)
}
wpabuf_free(plain);
+ if (wps->wps->ap && wps->wps->registrar) {
+ /*
+ * If the Registrar is only learning our current configuration,
+ * it may not continue protocol run to successful completion.
+ * Store information here to make sure it remains available.
+ */
+ wps_device_store(wps->wps->registrar, &wps->peer_dev,
+ wps->uuid_r);
+ }
+
wps->state = RECV_M8;
return msg;
}
@@ -513,6 +519,23 @@ static int wps_process_pubkey(struct wps_data *wps, const u8 *pk,
return -1;
}
+#ifdef CONFIG_WPS_OOB
+ if (wps->dev_pw_id != DEV_PW_DEFAULT &&
+ wps->wps->oob_conf.pubkey_hash) {
+ const u8 *addr[1];
+ u8 hash[WPS_HASH_LEN];
+
+ addr[0] = pk;
+ sha256_vector(1, addr, &pk_len, hash);
+ if (os_memcmp(hash,
+ wpabuf_head(wps->wps->oob_conf.pubkey_hash),
+ WPS_OOB_PUBKEY_HASH_LEN) != 0) {
+ wpa_printf(MSG_ERROR, "WPS: Public Key hash error");
+ return -1;
+ }
+ }
+#endif /* CONFIG_WPS_OOB */
+
wpabuf_free(wps->dh_pubkey_r);
wps->dh_pubkey_r = wpabuf_alloc_copy(pk, pk_len);
if (wps->dh_pubkey_r == NULL)
@@ -751,14 +774,13 @@ static enum wps_process_res wps_process_m2(struct wps_data *wps,
if (wps_process_registrar_nonce(wps, attr->registrar_nonce) ||
wps_process_enrollee_nonce(wps, attr->enrollee_nonce) ||
- wps_process_uuid_r(wps, attr->uuid_r) ||
- wps_process_pubkey(wps, attr->public_key, attr->public_key_len) ||
- wps_process_authenticator(wps, attr->authenticator, msg)) {
+ wps_process_uuid_r(wps, attr->uuid_r)) {
wps->state = SEND_WSC_NACK;
return WPS_CONTINUE;
}
- if (wps->wps->ap && wps->wps->ap_setup_locked) {
+ if (wps->wps->ap &&
+ (wps->wps->ap_setup_locked || wps->dev_password == NULL)) {
wpa_printf(MSG_DEBUG, "WPS: AP Setup is locked - refuse "
"registration of a new Registrar");
wps->config_error = WPS_CFG_SETUP_LOCKED;
@@ -766,6 +788,13 @@ static enum wps_process_res wps_process_m2(struct wps_data *wps,
return WPS_CONTINUE;
}
+ if (wps_process_pubkey(wps, attr->public_key, attr->public_key_len) ||
+ wps_process_authenticator(wps, attr->authenticator, msg) ||
+ wps_process_device_attrs(&wps->peer_dev, attr)) {
+ wps->state = SEND_WSC_NACK;
+ return WPS_CONTINUE;
+ }
+
wps->state = SEND_M3;
return WPS_CONTINUE;
}
diff --git a/contrib/wpa/src/wps/wps_er.c b/contrib/wpa/src/wps/wps_er.c
new file mode 100644
index 0000000..e0cdd1d
--- /dev/null
+++ b/contrib/wpa/src/wps/wps_er.c
@@ -0,0 +1,1663 @@
+/*
+ * Wi-Fi Protected Setup - External Registrar
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "base64.h"
+#include "uuid.h"
+#include "eloop.h"
+#include "httpread.h"
+#include "http_client.h"
+#include "http_server.h"
+#include "upnp_xml.h"
+#include "wps_i.h"
+#include "wps_upnp.h"
+#include "wps_upnp_i.h"
+#include "wps_er.h"
+
+
+static void wps_er_deinit_finish(void *eloop_data, void *user_ctx);
+static void wps_er_ap_timeout(void *eloop_data, void *user_ctx);
+static void wps_er_sta_timeout(void *eloop_data, void *user_ctx);
+static void wps_er_ap_process(struct wps_er_ap *ap, struct wpabuf *msg);
+static int wps_er_send_get_device_info(struct wps_er_ap *ap,
+ void (*m1_handler)(struct wps_er_ap *ap,
+ struct wpabuf *m1));
+
+
+static void wps_er_sta_event(struct wps_context *wps, struct wps_er_sta *sta,
+ enum wps_event event)
+{
+ union wps_event_data data;
+ struct wps_event_er_enrollee *ev = &data.enrollee;
+
+ if (wps->event_cb == NULL)
+ return;
+
+ os_memset(&data, 0, sizeof(data));
+ ev->uuid = sta->uuid;
+ ev->mac_addr = sta->addr;
+ ev->m1_received = sta->m1_received;
+ ev->config_methods = sta->config_methods;
+ ev->dev_passwd_id = sta->dev_passwd_id;
+ ev->pri_dev_type = sta->pri_dev_type;
+ ev->dev_name = sta->dev_name;
+ ev->manufacturer = sta->manufacturer;
+ ev->model_name = sta->model_name;
+ ev->model_number = sta->model_number;
+ ev->serial_number = sta->serial_number;
+ wps->event_cb(wps->cb_ctx, event, &data);
+}
+
+
+static struct wps_er_sta * wps_er_sta_get(struct wps_er_ap *ap, const u8 *addr)
+{
+ struct wps_er_sta *sta;
+ dl_list_for_each(sta, &ap->sta, struct wps_er_sta, list) {
+ if (os_memcmp(sta->addr, addr, ETH_ALEN) == 0)
+ return sta;
+ }
+ return NULL;
+}
+
+
+static void wps_er_sta_free(struct wps_er_sta *sta)
+{
+ wps_er_sta_event(sta->ap->er->wps, sta, WPS_EV_ER_ENROLLEE_REMOVE);
+ if (sta->wps)
+ wps_deinit(sta->wps);
+ os_free(sta->manufacturer);
+ os_free(sta->model_name);
+ os_free(sta->model_number);
+ os_free(sta->serial_number);
+ os_free(sta->dev_name);
+ http_client_free(sta->http);
+ eloop_cancel_timeout(wps_er_sta_timeout, sta, NULL);
+ os_free(sta->cred);
+ os_free(sta);
+}
+
+
+static void wps_er_sta_remove_all(struct wps_er_ap *ap)
+{
+ struct wps_er_sta *prev, *sta;
+ dl_list_for_each_safe(sta, prev, &ap->sta, struct wps_er_sta, list)
+ wps_er_sta_free(sta);
+}
+
+
+static struct wps_er_ap * wps_er_ap_get(struct wps_er *er,
+ struct in_addr *addr, const u8 *uuid)
+{
+ struct wps_er_ap *ap;
+ dl_list_for_each(ap, &er->ap, struct wps_er_ap, list) {
+ if ((addr == NULL || ap->addr.s_addr == addr->s_addr) &&
+ (uuid == NULL ||
+ os_memcmp(uuid, ap->uuid, WPS_UUID_LEN) == 0))
+ return ap;
+ }
+ return NULL;
+}
+
+
+static struct wps_er_ap * wps_er_ap_get_id(struct wps_er *er, unsigned int id)
+{
+ struct wps_er_ap *ap;
+ dl_list_for_each(ap, &er->ap, struct wps_er_ap, list) {
+ if (ap->id == id)
+ return ap;
+ }
+ return NULL;
+}
+
+
+static void wps_er_ap_event(struct wps_context *wps, struct wps_er_ap *ap,
+ enum wps_event event)
+{
+ union wps_event_data data;
+ struct wps_event_er_ap *evap = &data.ap;
+
+ if (wps->event_cb == NULL)
+ return;
+
+ os_memset(&data, 0, sizeof(data));
+ evap->uuid = ap->uuid;
+ evap->friendly_name = ap->friendly_name;
+ evap->manufacturer = ap->manufacturer;
+ evap->manufacturer_url = ap->manufacturer_url;
+ evap->model_description = ap->model_description;
+ evap->model_name = ap->model_name;
+ evap->model_number = ap->model_number;
+ evap->model_url = ap->model_url;
+ evap->serial_number = ap->serial_number;
+ evap->upc = ap->upc;
+ evap->pri_dev_type = ap->pri_dev_type;
+ evap->wps_state = ap->wps_state;
+ evap->mac_addr = ap->mac_addr;
+ wps->event_cb(wps->cb_ctx, event, &data);
+}
+
+
+static void wps_er_ap_free(struct wps_er_ap *ap)
+{
+ http_client_free(ap->http);
+ ap->http = NULL;
+
+ os_free(ap->location);
+ os_free(ap->friendly_name);
+ os_free(ap->manufacturer);
+ os_free(ap->manufacturer_url);
+ os_free(ap->model_description);
+ os_free(ap->model_name);
+ os_free(ap->model_number);
+ os_free(ap->model_url);
+ os_free(ap->serial_number);
+ os_free(ap->udn);
+ os_free(ap->upc);
+
+ os_free(ap->scpd_url);
+ os_free(ap->control_url);
+ os_free(ap->event_sub_url);
+
+ os_free(ap->ap_settings);
+
+ os_free(ap);
+}
+
+
+static void wps_er_ap_unsubscribed(struct wps_er *er, struct wps_er_ap *ap)
+{
+ wpa_printf(MSG_DEBUG, "WPS ER: Unsubscribed from AP %s (%s)",
+ inet_ntoa(ap->addr), ap->location);
+ dl_list_del(&ap->list);
+ wps_er_ap_free(ap);
+
+ if (er->deinitializing && dl_list_empty(&er->ap_unsubscribing)) {
+ eloop_cancel_timeout(wps_er_deinit_finish, er, NULL);
+ wps_er_deinit_finish(er, NULL);
+ }
+}
+
+
+static void wps_er_http_unsubscribe_cb(void *ctx, struct http_client *c,
+ enum http_client_event event)
+{
+ struct wps_er_ap *ap = ctx;
+
+ switch (event) {
+ case HTTP_CLIENT_OK:
+ wpa_printf(MSG_DEBUG, "WPS ER: Unsubscribed from events");
+ ap->subscribed = 0;
+ break;
+ case HTTP_CLIENT_FAILED:
+ case HTTP_CLIENT_INVALID_REPLY:
+ case HTTP_CLIENT_TIMEOUT:
+ wpa_printf(MSG_DEBUG, "WPS ER: Failed to unsubscribe from "
+ "events");
+ break;
+ }
+ http_client_free(ap->http);
+ ap->http = NULL;
+
+ /*
+ * Need to get rid of the AP entry regardless of whether we managed to
+ * unsubscribe cleanly or not.
+ */
+ wps_er_ap_unsubscribed(ap->er, ap);
+}
+
+
+static void wps_er_ap_unsubscribe(struct wps_er *er, struct wps_er_ap *ap)
+{
+ struct wpabuf *req;
+ struct sockaddr_in dst;
+ char *url, *path;
+ char sid[100];
+
+ if (ap->event_sub_url == NULL) {
+ wpa_printf(MSG_DEBUG, "WPS ER: No eventSubURL - cannot "
+ "subscribe");
+ goto fail;
+ }
+ if (ap->http) {
+ wpa_printf(MSG_DEBUG, "WPS ER: Pending HTTP request - cannot "
+ "send subscribe request");
+ goto fail;
+ }
+
+ url = http_client_url_parse(ap->event_sub_url, &dst, &path);
+ if (url == NULL) {
+ wpa_printf(MSG_DEBUG, "WPS ER: Failed to parse eventSubURL");
+ goto fail;
+ }
+
+ req = wpabuf_alloc(os_strlen(ap->event_sub_url) + 1000);
+ if (req == NULL) {
+ os_free(url);
+ goto fail;
+ }
+ uuid_bin2str(ap->sid, sid, sizeof(sid));
+ wpabuf_printf(req,
+ "UNSUBSCRIBE %s HTTP/1.1\r\n"
+ "HOST: %s:%d\r\n"
+ "SID: uuid:%s\r\n"
+ "\r\n",
+ path, inet_ntoa(dst.sin_addr), ntohs(dst.sin_port), sid);
+ os_free(url);
+ wpa_hexdump_ascii(MSG_MSGDUMP, "WPS ER: Unsubscription request",
+ wpabuf_head(req), wpabuf_len(req));
+
+ ap->http = http_client_addr(&dst, req, 1000,
+ wps_er_http_unsubscribe_cb, ap);
+ if (ap->http == NULL) {
+ wpabuf_free(req);
+ goto fail;
+ }
+ return;
+
+fail:
+ /*
+ * Need to get rid of the AP entry even when we fail to unsubscribe
+ * cleanly.
+ */
+ wps_er_ap_unsubscribed(ap->er, ap);
+}
+
+static void wps_er_ap_remove_entry(struct wps_er *er, struct wps_er_ap *ap)
+{
+ wpa_printf(MSG_DEBUG, "WPS ER: Removing AP entry for %s (%s)",
+ inet_ntoa(ap->addr), ap->location);
+ eloop_cancel_timeout(wps_er_ap_timeout, er, ap);
+ wps_er_sta_remove_all(ap);
+ wps_er_ap_event(er->wps, ap, WPS_EV_ER_AP_REMOVE);
+ http_client_free(ap->http);
+ ap->http = NULL;
+ if (ap->wps) {
+ wps_deinit(ap->wps);
+ ap->wps = NULL;
+ }
+
+ dl_list_del(&ap->list);
+ if (ap->subscribed) {
+ dl_list_add(&er->ap_unsubscribing, &ap->list);
+ wps_er_ap_unsubscribe(er, ap);
+ } else
+ wps_er_ap_free(ap);
+}
+
+
+static void wps_er_ap_timeout(void *eloop_data, void *user_ctx)
+{
+ struct wps_er *er = eloop_data;
+ struct wps_er_ap *ap = user_ctx;
+ wpa_printf(MSG_DEBUG, "WPS ER: AP advertisement timed out");
+ wps_er_ap_remove_entry(er, ap);
+}
+
+
+static int wps_er_get_sid(struct wps_er_ap *ap, char *sid)
+{
+ char *pos;
+ char txt[100];
+
+ if (!sid) {
+ wpa_printf(MSG_DEBUG, "WPS ER: No SID received from %s (%s)",
+ inet_ntoa(ap->addr), ap->location);
+ return -1;
+ }
+
+ pos = os_strstr(sid, "uuid:");
+ if (!pos) {
+ wpa_printf(MSG_DEBUG, "WPS ER: Invalid SID received from "
+ "%s (%s): '%s'", inet_ntoa(ap->addr), ap->location,
+ sid);
+ return -1;
+ }
+
+ pos += 5;
+ if (uuid_str2bin(pos, ap->sid) < 0) {
+ wpa_printf(MSG_DEBUG, "WPS ER: Invalid SID received from "
+ "%s (%s): '%s'", inet_ntoa(ap->addr), ap->location,
+ sid);
+ return -1;
+ }
+
+ uuid_bin2str(ap->sid, txt, sizeof(txt));
+ wpa_printf(MSG_DEBUG, "WPS ER: SID for subscription with %s (%s): %s",
+ inet_ntoa(ap->addr), ap->location, txt);
+
+ return 0;
+}
+
+
+static void wps_er_http_subscribe_cb(void *ctx, struct http_client *c,
+ enum http_client_event event)
+{
+ struct wps_er_ap *ap = ctx;
+
+ switch (event) {
+ case HTTP_CLIENT_OK:
+ wpa_printf(MSG_DEBUG, "WPS ER: Subscribed to events");
+ ap->subscribed = 1;
+ wps_er_get_sid(ap, http_client_get_hdr_line(c, "SID"));
+ wps_er_ap_event(ap->er->wps, ap, WPS_EV_ER_AP_ADD);
+ break;
+ case HTTP_CLIENT_FAILED:
+ case HTTP_CLIENT_INVALID_REPLY:
+ case HTTP_CLIENT_TIMEOUT:
+ wpa_printf(MSG_DEBUG, "WPS ER: Failed to subscribe to events");
+ break;
+ }
+ http_client_free(ap->http);
+ ap->http = NULL;
+}
+
+
+static void wps_er_subscribe(struct wps_er_ap *ap)
+{
+ struct wpabuf *req;
+ struct sockaddr_in dst;
+ char *url, *path;
+
+ if (ap->event_sub_url == NULL) {
+ wpa_printf(MSG_DEBUG, "WPS ER: No eventSubURL - cannot "
+ "subscribe");
+ return;
+ }
+ if (ap->http) {
+ wpa_printf(MSG_DEBUG, "WPS ER: Pending HTTP request - cannot "
+ "send subscribe request");
+ return;
+ }
+
+ url = http_client_url_parse(ap->event_sub_url, &dst, &path);
+ if (url == NULL) {
+ wpa_printf(MSG_DEBUG, "WPS ER: Failed to parse eventSubURL");
+ return;
+ }
+
+ req = wpabuf_alloc(os_strlen(ap->event_sub_url) + 1000);
+ if (req == NULL) {
+ os_free(url);
+ return;
+ }
+ wpabuf_printf(req,
+ "SUBSCRIBE %s HTTP/1.1\r\n"
+ "HOST: %s:%d\r\n"
+ "CALLBACK: <http://%s:%d/event/%u/%u>\r\n"
+ "NT: upnp:event\r\n"
+ "TIMEOUT: Second-%d\r\n"
+ "\r\n",
+ path, inet_ntoa(dst.sin_addr), ntohs(dst.sin_port),
+ ap->er->ip_addr_text, ap->er->http_port,
+ ap->er->event_id, ap->id, 1800);
+ os_free(url);
+ wpa_hexdump_ascii(MSG_MSGDUMP, "WPS ER: Subscription request",
+ wpabuf_head(req), wpabuf_len(req));
+
+ ap->http = http_client_addr(&dst, req, 1000, wps_er_http_subscribe_cb,
+ ap);
+ if (ap->http == NULL)
+ wpabuf_free(req);
+}
+
+
+static void wps_er_ap_get_m1(struct wps_er_ap *ap, struct wpabuf *m1)
+{
+ struct wps_parse_attr attr;
+
+ if (wps_parse_msg(m1, &attr) < 0) {
+ wpa_printf(MSG_DEBUG, "WPS ER: Failed to parse M1");
+ return;
+ }
+ if (attr.primary_dev_type)
+ os_memcpy(ap->pri_dev_type, attr.primary_dev_type, 8);
+ if (attr.wps_state)
+ ap->wps_state = *attr.wps_state;
+ if (attr.mac_addr)
+ os_memcpy(ap->mac_addr, attr.mac_addr, ETH_ALEN);
+
+ wps_er_subscribe(ap);
+}
+
+
+static void wps_er_get_device_info(struct wps_er_ap *ap)
+{
+ wps_er_send_get_device_info(ap, wps_er_ap_get_m1);
+}
+
+
+static void wps_er_parse_device_description(struct wps_er_ap *ap,
+ struct wpabuf *reply)
+{
+ /* Note: reply includes null termination after the buffer data */
+ const char *data = wpabuf_head(reply);
+ char *pos;
+
+ wpa_hexdump_ascii(MSG_MSGDUMP, "WPS ER: Device info",
+ wpabuf_head(reply), wpabuf_len(reply));
+
+ ap->friendly_name = xml_get_first_item(data, "friendlyName");
+ wpa_printf(MSG_DEBUG, "WPS ER: friendlyName='%s'", ap->friendly_name);
+
+ ap->manufacturer = xml_get_first_item(data, "manufacturer");
+ wpa_printf(MSG_DEBUG, "WPS ER: manufacturer='%s'", ap->manufacturer);
+
+ ap->manufacturer_url = xml_get_first_item(data, "manufacturerURL");
+ wpa_printf(MSG_DEBUG, "WPS ER: manufacturerURL='%s'",
+ ap->manufacturer_url);
+
+ ap->model_description = xml_get_first_item(data, "modelDescription");
+ wpa_printf(MSG_DEBUG, "WPS ER: modelDescription='%s'",
+ ap->model_description);
+
+ ap->model_name = xml_get_first_item(data, "modelName");
+ wpa_printf(MSG_DEBUG, "WPS ER: modelName='%s'", ap->model_name);
+
+ ap->model_number = xml_get_first_item(data, "modelNumber");
+ wpa_printf(MSG_DEBUG, "WPS ER: modelNumber='%s'", ap->model_number);
+
+ ap->model_url = xml_get_first_item(data, "modelURL");
+ wpa_printf(MSG_DEBUG, "WPS ER: modelURL='%s'", ap->model_url);
+
+ ap->serial_number = xml_get_first_item(data, "serialNumber");
+ wpa_printf(MSG_DEBUG, "WPS ER: serialNumber='%s'", ap->serial_number);
+
+ ap->udn = xml_get_first_item(data, "UDN");
+ wpa_printf(MSG_DEBUG, "WPS ER: UDN='%s'", ap->udn);
+ pos = os_strstr(ap->udn, "uuid:");
+ if (pos) {
+ pos += 5;
+ if (uuid_str2bin(pos, ap->uuid) < 0)
+ wpa_printf(MSG_DEBUG, "WPS ER: Invalid UUID in UDN");
+ }
+
+ ap->upc = xml_get_first_item(data, "UPC");
+ wpa_printf(MSG_DEBUG, "WPS ER: UPC='%s'", ap->upc);
+
+ ap->scpd_url = http_link_update(
+ xml_get_first_item(data, "SCPDURL"), ap->location);
+ wpa_printf(MSG_DEBUG, "WPS ER: SCPDURL='%s'", ap->scpd_url);
+
+ ap->control_url = http_link_update(
+ xml_get_first_item(data, "controlURL"), ap->location);
+ wpa_printf(MSG_DEBUG, "WPS ER: controlURL='%s'", ap->control_url);
+
+ ap->event_sub_url = http_link_update(
+ xml_get_first_item(data, "eventSubURL"), ap->location);
+ wpa_printf(MSG_DEBUG, "WPS ER: eventSubURL='%s'", ap->event_sub_url);
+}
+
+
+static void wps_er_http_dev_desc_cb(void *ctx, struct http_client *c,
+ enum http_client_event event)
+{
+ struct wps_er_ap *ap = ctx;
+ struct wpabuf *reply;
+ int ok = 0;
+
+ switch (event) {
+ case HTTP_CLIENT_OK:
+ reply = http_client_get_body(c);
+ if (reply == NULL)
+ break;
+ wps_er_parse_device_description(ap, reply);
+ ok = 1;
+ break;
+ case HTTP_CLIENT_FAILED:
+ case HTTP_CLIENT_INVALID_REPLY:
+ case HTTP_CLIENT_TIMEOUT:
+ wpa_printf(MSG_DEBUG, "WPS ER: Failed to fetch device info");
+ break;
+ }
+ http_client_free(ap->http);
+ ap->http = NULL;
+ if (ok)
+ wps_er_get_device_info(ap);
+}
+
+
+void wps_er_ap_add(struct wps_er *er, const u8 *uuid, struct in_addr *addr,
+ const char *location, int max_age)
+{
+ struct wps_er_ap *ap;
+
+ ap = wps_er_ap_get(er, addr, uuid);
+ if (ap) {
+ /* Update advertisement timeout */
+ eloop_cancel_timeout(wps_er_ap_timeout, er, ap);
+ eloop_register_timeout(max_age, 0, wps_er_ap_timeout, er, ap);
+ return;
+ }
+
+ ap = os_zalloc(sizeof(*ap));
+ if (ap == NULL)
+ return;
+ dl_list_init(&ap->sta);
+ ap->er = er;
+ ap->id = ++er->next_ap_id;
+ ap->location = os_strdup(location);
+ if (ap->location == NULL) {
+ os_free(ap);
+ return;
+ }
+ dl_list_add(&er->ap, &ap->list);
+
+ ap->addr.s_addr = addr->s_addr;
+ os_memcpy(ap->uuid, uuid, WPS_UUID_LEN);
+ eloop_register_timeout(max_age, 0, wps_er_ap_timeout, er, ap);
+
+ wpa_printf(MSG_DEBUG, "WPS ER: Added AP entry for %s (%s)",
+ inet_ntoa(ap->addr), ap->location);
+
+ /* Fetch device description */
+ ap->http = http_client_url(ap->location, NULL, 10000,
+ wps_er_http_dev_desc_cb, ap);
+}
+
+
+void wps_er_ap_remove(struct wps_er *er, struct in_addr *addr)
+{
+ struct wps_er_ap *ap;
+ dl_list_for_each(ap, &er->ap, struct wps_er_ap, list) {
+ if (ap->addr.s_addr == addr->s_addr) {
+ wps_er_ap_remove_entry(er, ap);
+ return;
+ }
+ }
+}
+
+
+static void wps_er_ap_remove_all(struct wps_er *er)
+{
+ struct wps_er_ap *prev, *ap;
+ dl_list_for_each_safe(ap, prev, &er->ap, struct wps_er_ap, list)
+ wps_er_ap_remove_entry(er, ap);
+}
+
+
+static void http_put_date(struct wpabuf *buf)
+{
+ wpabuf_put_str(buf, "Date: ");
+ format_date(buf);
+ wpabuf_put_str(buf, "\r\n");
+}
+
+
+static void wps_er_http_resp_not_found(struct http_request *req)
+{
+ struct wpabuf *buf;
+ buf = wpabuf_alloc(200);
+ if (buf == NULL) {
+ http_request_deinit(req);
+ return;
+ }
+
+ wpabuf_put_str(buf,
+ "HTTP/1.1 404 Not Found\r\n"
+ "Server: unspecified, UPnP/1.0, unspecified\r\n"
+ "Connection: close\r\n");
+ http_put_date(buf);
+ wpabuf_put_str(buf, "\r\n");
+ http_request_send_and_deinit(req, buf);
+}
+
+
+static void wps_er_http_resp_ok(struct http_request *req)
+{
+ struct wpabuf *buf;
+ buf = wpabuf_alloc(200);
+ if (buf == NULL) {
+ http_request_deinit(req);
+ return;
+ }
+
+ wpabuf_put_str(buf,
+ "HTTP/1.1 200 OK\r\n"
+ "Server: unspecified, UPnP/1.0, unspecified\r\n"
+ "Connection: close\r\n"
+ "Content-Length: 0\r\n");
+ http_put_date(buf);
+ wpabuf_put_str(buf, "\r\n");
+ http_request_send_and_deinit(req, buf);
+}
+
+
+static void wps_er_sta_timeout(void *eloop_data, void *user_ctx)
+{
+ struct wps_er_sta *sta = eloop_data;
+ wpa_printf(MSG_DEBUG, "WPS ER: STA entry timed out");
+ dl_list_del(&sta->list);
+ wps_er_sta_free(sta);
+}
+
+
+static struct wps_er_sta * wps_er_add_sta_data(struct wps_er_ap *ap,
+ const u8 *addr,
+ struct wps_parse_attr *attr,
+ int probe_req)
+{
+ struct wps_er_sta *sta = wps_er_sta_get(ap, addr);
+ int new_sta = 0;
+ int m1;
+
+ m1 = !probe_req && attr->msg_type && *attr->msg_type == WPS_M1;
+
+ if (sta == NULL) {
+ /*
+ * Only allow new STA entry to be added based on Probe Request
+ * or M1. This will filter out bogus events and anything that
+ * may have been ongoing at the time ER subscribed for events.
+ */
+ if (!probe_req && !m1)
+ return NULL;
+
+ sta = os_zalloc(sizeof(*sta));
+ if (sta == NULL)
+ return NULL;
+ os_memcpy(sta->addr, addr, ETH_ALEN);
+ sta->ap = ap;
+ dl_list_add(&ap->sta, &sta->list);
+ new_sta = 1;
+ }
+
+ if (m1)
+ sta->m1_received = 1;
+
+ if (attr->config_methods && (!probe_req || !sta->m1_received))
+ sta->config_methods = WPA_GET_BE16(attr->config_methods);
+ if (attr->uuid_e && (!probe_req || !sta->m1_received))
+ os_memcpy(sta->uuid, attr->uuid_e, WPS_UUID_LEN);
+ if (attr->primary_dev_type && (!probe_req || !sta->m1_received))
+ os_memcpy(sta->pri_dev_type, attr->primary_dev_type, 8);
+ if (attr->dev_password_id && (!probe_req || !sta->m1_received))
+ sta->dev_passwd_id = WPA_GET_BE16(attr->dev_password_id);
+
+ if (attr->manufacturer) {
+ os_free(sta->manufacturer);
+ sta->manufacturer = os_malloc(attr->manufacturer_len + 1);
+ if (sta->manufacturer) {
+ os_memcpy(sta->manufacturer, attr->manufacturer,
+ attr->manufacturer_len);
+ sta->manufacturer[attr->manufacturer_len] = '\0';
+ }
+ }
+
+ if (attr->model_name) {
+ os_free(sta->model_name);
+ sta->model_name = os_malloc(attr->model_name_len + 1);
+ if (sta->model_name) {
+ os_memcpy(sta->model_name, attr->model_name,
+ attr->model_name_len);
+ sta->model_name[attr->model_name_len] = '\0';
+ }
+ }
+
+ if (attr->model_number) {
+ os_free(sta->model_number);
+ sta->model_number = os_malloc(attr->model_number_len + 1);
+ if (sta->model_number) {
+ os_memcpy(sta->model_number, attr->model_number,
+ attr->model_number_len);
+ sta->model_number[attr->model_number_len] = '\0';
+ }
+ }
+
+ if (attr->serial_number) {
+ os_free(sta->serial_number);
+ sta->serial_number = os_malloc(attr->serial_number_len + 1);
+ if (sta->serial_number) {
+ os_memcpy(sta->serial_number, attr->serial_number,
+ attr->serial_number_len);
+ sta->serial_number[attr->serial_number_len] = '\0';
+ }
+ }
+
+ if (attr->dev_name) {
+ os_free(sta->dev_name);
+ sta->dev_name = os_malloc(attr->dev_name_len + 1);
+ if (sta->dev_name) {
+ os_memcpy(sta->dev_name, attr->dev_name,
+ attr->dev_name_len);
+ sta->dev_name[attr->dev_name_len] = '\0';
+ }
+ }
+
+ eloop_cancel_timeout(wps_er_sta_timeout, sta, NULL);
+ eloop_register_timeout(300, 0, wps_er_sta_timeout, sta, NULL);
+
+ if (m1 || new_sta)
+ wps_er_sta_event(ap->er->wps, sta, WPS_EV_ER_ENROLLEE_ADD);
+
+ return sta;
+}
+
+
+static void wps_er_process_wlanevent_probe_req(struct wps_er_ap *ap,
+ const u8 *addr,
+ struct wpabuf *msg)
+{
+ struct wps_parse_attr attr;
+
+ wpa_printf(MSG_DEBUG, "WPS ER: WLANEvent - Probe Request - from "
+ MACSTR, MAC2STR(addr));
+ wpa_hexdump_buf(MSG_MSGDUMP, "WPS ER: WLANEvent - Enrollee's message "
+ "(TLVs from Probe Request)", msg);
+
+ if (wps_parse_msg(msg, &attr) < 0) {
+ wpa_printf(MSG_DEBUG, "WPS ER: Failed to parse TLVs in "
+ "WLANEvent message");
+ return;
+ }
+
+ wps_er_add_sta_data(ap, addr, &attr, 1);
+}
+
+
+static void wps_er_http_put_wlan_response_cb(void *ctx, struct http_client *c,
+ enum http_client_event event)
+{
+ struct wps_er_sta *sta = ctx;
+
+ switch (event) {
+ case HTTP_CLIENT_OK:
+ wpa_printf(MSG_DEBUG, "WPS ER: PutWLANResponse OK");
+ break;
+ case HTTP_CLIENT_FAILED:
+ case HTTP_CLIENT_INVALID_REPLY:
+ case HTTP_CLIENT_TIMEOUT:
+ wpa_printf(MSG_DEBUG, "WPS ER: PutWLANResponse failed");
+ break;
+ }
+ http_client_free(sta->http);
+ sta->http = NULL;
+}
+
+
+static const char *soap_prefix =
+ "<?xml version=\"1.0\"?>\n"
+ "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" "
+ "s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n"
+ "<s:Body>\n";
+static const char *soap_postfix =
+ "</s:Body>\n</s:Envelope>\n";
+static const char *urn_wfawlanconfig =
+ "urn:schemas-wifialliance-org:service:WFAWLANConfig:1";
+
+static struct wpabuf * wps_er_soap_hdr(const struct wpabuf *msg,
+ const char *name, const char *arg_name,
+ const char *path,
+ const struct sockaddr_in *dst,
+ char **len_ptr, char **body_ptr)
+{
+ unsigned char *encoded;
+ size_t encoded_len;
+ struct wpabuf *buf;
+
+ if (msg) {
+ encoded = base64_encode(wpabuf_head(msg), wpabuf_len(msg),
+ &encoded_len);
+ if (encoded == NULL)
+ return NULL;
+ } else {
+ encoded = NULL;
+ encoded_len = 0;
+ }
+
+ buf = wpabuf_alloc(1000 + encoded_len);
+ if (buf == NULL) {
+ os_free(encoded);
+ return NULL;
+ }
+
+ wpabuf_printf(buf,
+ "POST %s HTTP/1.1\r\n"
+ "Host: %s:%d\r\n"
+ "Content-Type: text/xml; charset=\"utf-8\"\r\n"
+ "Content-Length: ",
+ path, inet_ntoa(dst->sin_addr), ntohs(dst->sin_port));
+
+ *len_ptr = wpabuf_put(buf, 0);
+ wpabuf_printf(buf,
+ " \r\n"
+ "SOAPACTION: \"%s#%s\"\r\n"
+ "\r\n",
+ urn_wfawlanconfig, name);
+
+ *body_ptr = wpabuf_put(buf, 0);
+
+ wpabuf_put_str(buf, soap_prefix);
+ wpabuf_printf(buf, "<u:%s xmlns:u=\"", name);
+ wpabuf_put_str(buf, urn_wfawlanconfig);
+ wpabuf_put_str(buf, "\">\n");
+ if (encoded) {
+ wpabuf_printf(buf, "<%s>%s</%s>\n",
+ arg_name, (char *) encoded, arg_name);
+ os_free(encoded);
+ }
+
+ return buf;
+}
+
+
+static void wps_er_soap_end(struct wpabuf *buf, const char *name,
+ char *len_ptr, char *body_ptr)
+{
+ char len_buf[10];
+ wpabuf_printf(buf, "</u:%s>\n", name);
+ wpabuf_put_str(buf, soap_postfix);
+ os_snprintf(len_buf, sizeof(len_buf), "%d",
+ (int) ((char *) wpabuf_put(buf, 0) - body_ptr));
+ os_memcpy(len_ptr, len_buf, os_strlen(len_buf));
+}
+
+
+static void wps_er_sta_send_msg(struct wps_er_sta *sta, struct wpabuf *msg)
+{
+ struct wpabuf *buf;
+ char *len_ptr, *body_ptr;
+ struct sockaddr_in dst;
+ char *url, *path;
+
+ if (sta->http) {
+ wpa_printf(MSG_DEBUG, "WPS ER: Pending HTTP request for STA - "
+ "ignore new request");
+ wpabuf_free(msg);
+ return;
+ }
+
+ if (sta->ap->control_url == NULL) {
+ wpa_printf(MSG_DEBUG, "WPS ER: No controlURL for AP");
+ wpabuf_free(msg);
+ return;
+ }
+
+ url = http_client_url_parse(sta->ap->control_url, &dst, &path);
+ if (url == NULL) {
+ wpa_printf(MSG_DEBUG, "WPS ER: Failed to parse controlURL");
+ wpabuf_free(msg);
+ return;
+ }
+
+ buf = wps_er_soap_hdr(msg, "PutWLANResponse", "NewMessage", path, &dst,
+ &len_ptr, &body_ptr);
+ wpabuf_free(msg);
+ os_free(url);
+ if (buf == NULL)
+ return;
+ wpabuf_printf(buf, "<NewWLANEventType>%d</NewWLANEventType>\n",
+ UPNP_WPS_WLANEVENT_TYPE_EAP);
+ wpabuf_printf(buf, "<NewWLANEventMAC>" MACSTR "</NewWLANEventMAC>\n",
+ MAC2STR(sta->addr));
+
+ wps_er_soap_end(buf, "PutWLANResponse", len_ptr, body_ptr);
+
+ sta->http = http_client_addr(&dst, buf, 1000,
+ wps_er_http_put_wlan_response_cb, sta);
+ if (sta->http == NULL)
+ wpabuf_free(buf);
+}
+
+
+static void wps_er_sta_process(struct wps_er_sta *sta, struct wpabuf *msg,
+ enum wsc_op_code op_code)
+{
+ enum wps_process_res res;
+
+ res = wps_process_msg(sta->wps, op_code, msg);
+ if (res == WPS_CONTINUE) {
+ struct wpabuf *next = wps_get_msg(sta->wps, &op_code);
+ if (next)
+ wps_er_sta_send_msg(sta, next);
+ } else {
+ wpa_printf(MSG_DEBUG, "WPS ER: Protocol run %s with the "
+ "enrollee (res=%d)",
+ res == WPS_DONE ? "succeeded" : "failed", res);
+ wps_deinit(sta->wps);
+ sta->wps = NULL;
+ if (res == WPS_DONE) {
+ /* Remove the STA entry after short timeout */
+ eloop_cancel_timeout(wps_er_sta_timeout, sta, NULL);
+ eloop_register_timeout(10, 0, wps_er_sta_timeout, sta,
+ NULL);
+ }
+ }
+}
+
+
+static void wps_er_sta_start(struct wps_er_sta *sta, struct wpabuf *msg)
+{
+ struct wps_config cfg;
+
+ if (sta->wps)
+ wps_deinit(sta->wps);
+
+ os_memset(&cfg, 0, sizeof(cfg));
+ cfg.wps = sta->ap->er->wps;
+ cfg.registrar = 1;
+ cfg.peer_addr = sta->addr;
+
+ sta->wps = wps_init(&cfg);
+ if (sta->wps == NULL)
+ return;
+ sta->wps->er = 1;
+ sta->wps->use_cred = sta->ap->ap_settings;
+ if (sta->ap->ap_settings) {
+ os_free(sta->cred);
+ sta->cred = os_malloc(sizeof(*sta->cred));
+ if (sta->cred) {
+ os_memcpy(sta->cred, sta->ap->ap_settings,
+ sizeof(*sta->cred));
+ sta->cred->cred_attr = NULL;
+ os_memcpy(sta->cred->mac_addr, sta->addr, ETH_ALEN);
+ sta->wps->use_cred = sta->cred;
+ }
+ }
+
+ wps_er_sta_process(sta, msg, WSC_MSG);
+}
+
+
+static void wps_er_process_wlanevent_eap(struct wps_er_ap *ap, const u8 *addr,
+ struct wpabuf *msg)
+{
+ struct wps_parse_attr attr;
+ struct wps_er_sta *sta;
+
+ wpa_printf(MSG_DEBUG, "WPS ER: WLANEvent - EAP - from " MACSTR,
+ MAC2STR(addr));
+ wpa_hexdump_buf(MSG_MSGDUMP, "WPS ER: WLANEvent - Enrollee's message "
+ "(TLVs from EAP-WSC)", msg);
+
+ if (wps_parse_msg(msg, &attr) < 0) {
+ wpa_printf(MSG_DEBUG, "WPS ER: Failed to parse TLVs in "
+ "WLANEvent message");
+ return;
+ }
+
+ sta = wps_er_add_sta_data(ap, addr, &attr, 0);
+ if (sta == NULL)
+ return;
+
+ if (attr.msg_type && *attr.msg_type == WPS_M1)
+ wps_er_sta_start(sta, msg);
+ else if (sta->wps) {
+ enum wsc_op_code op_code = WSC_MSG;
+ if (attr.msg_type) {
+ switch (*attr.msg_type) {
+ case WPS_WSC_ACK:
+ op_code = WSC_ACK;
+ break;
+ case WPS_WSC_NACK:
+ op_code = WSC_NACK;
+ break;
+ case WPS_WSC_DONE:
+ op_code = WSC_Done;
+ break;
+ }
+ }
+ wps_er_sta_process(sta, msg, op_code);
+ }
+}
+
+
+static void wps_er_process_wlanevent(struct wps_er_ap *ap,
+ struct wpabuf *event)
+{
+ u8 *data;
+ u8 wlan_event_type;
+ u8 wlan_event_mac[ETH_ALEN];
+ struct wpabuf msg;
+
+ wpa_hexdump(MSG_MSGDUMP, "WPS ER: Received WLANEvent",
+ wpabuf_head(event), wpabuf_len(event));
+ if (wpabuf_len(event) < 1 + 17) {
+ wpa_printf(MSG_DEBUG, "WPS ER: Too short WLANEvent");
+ return;
+ }
+
+ data = wpabuf_mhead(event);
+ wlan_event_type = data[0];
+ if (hwaddr_aton((char *) data + 1, wlan_event_mac) < 0) {
+ wpa_printf(MSG_DEBUG, "WPS ER: Invalid WLANEventMAC in "
+ "WLANEvent");
+ return;
+ }
+
+ wpabuf_set(&msg, data + 1 + 17, wpabuf_len(event) - (1 + 17));
+
+ switch (wlan_event_type) {
+ case 1:
+ wps_er_process_wlanevent_probe_req(ap, wlan_event_mac, &msg);
+ break;
+ case 2:
+ wps_er_process_wlanevent_eap(ap, wlan_event_mac, &msg);
+ break;
+ default:
+ wpa_printf(MSG_DEBUG, "WPS ER: Unknown WLANEventType %d",
+ wlan_event_type);
+ break;
+ }
+}
+
+
+static void wps_er_http_event(struct wps_er *er, struct http_request *req,
+ unsigned int ap_id)
+{
+ struct wps_er_ap *ap = wps_er_ap_get_id(er, ap_id);
+ struct wpabuf *event;
+ enum http_reply_code ret;
+
+ if (ap == NULL) {
+ wpa_printf(MSG_DEBUG, "WPS ER: HTTP event from unknown AP id "
+ "%u", ap_id);
+ wps_er_http_resp_not_found(req);
+ return;
+ }
+ wpa_printf(MSG_MSGDUMP, "WPS ER: HTTP event from AP id %u: %s",
+ ap_id, http_request_get_data(req));
+
+ event = xml_get_base64_item(http_request_get_data(req), "WLANEvent",
+ &ret);
+ if (event == NULL) {
+ wpa_printf(MSG_DEBUG, "WPS ER: Could not extract WLANEvent "
+ "from the event notification");
+ /*
+ * Reply with OK anyway to avoid getting unregistered from
+ * events.
+ */
+ wps_er_http_resp_ok(req);
+ return;
+ }
+
+ wps_er_process_wlanevent(ap, event);
+
+ wpabuf_free(event);
+ wps_er_http_resp_ok(req);
+}
+
+
+static void wps_er_http_notify(struct wps_er *er, struct http_request *req)
+{
+ char *uri = http_request_get_uri(req);
+
+ if (os_strncmp(uri, "/event/", 7) == 0) {
+ unsigned int event_id;
+ char *pos;
+ event_id = atoi(uri + 7);
+ if (event_id != er->event_id) {
+ wpa_printf(MSG_DEBUG, "WPS ER: HTTP event for an "
+ "unknown event id %u", event_id);
+ return;
+ }
+ pos = os_strchr(uri + 7, '/');
+ if (pos == NULL)
+ return;
+ pos++;
+ wps_er_http_event(er, req, atoi(pos));
+ } else {
+ wpa_printf(MSG_DEBUG, "WPS ER: Unknown HTTP NOTIFY for '%s'",
+ uri);
+ wps_er_http_resp_not_found(req);
+ }
+}
+
+
+static void wps_er_http_req(void *ctx, struct http_request *req)
+{
+ struct wps_er *er = ctx;
+ struct sockaddr_in *cli = http_request_get_cli_addr(req);
+ enum httpread_hdr_type type = http_request_get_type(req);
+ struct wpabuf *buf;
+
+ wpa_printf(MSG_DEBUG, "WPS ER: HTTP request: '%s' (type %d) from "
+ "%s:%d",
+ http_request_get_uri(req), type,
+ inet_ntoa(cli->sin_addr), ntohs(cli->sin_port));
+
+ switch (type) {
+ case HTTPREAD_HDR_TYPE_NOTIFY:
+ wps_er_http_notify(er, req);
+ break;
+ default:
+ wpa_printf(MSG_DEBUG, "WPS ER: Unsupported HTTP request type "
+ "%d", type);
+ buf = wpabuf_alloc(200);
+ if (buf == NULL) {
+ http_request_deinit(req);
+ return;
+ }
+ wpabuf_put_str(buf,
+ "HTTP/1.1 501 Unimplemented\r\n"
+ "Connection: close\r\n");
+ http_put_date(buf);
+ wpabuf_put_str(buf, "\r\n");
+ http_request_send_and_deinit(req, buf);
+ break;
+ }
+}
+
+
+struct wps_er *
+wps_er_init(struct wps_context *wps, const char *ifname)
+{
+ struct wps_er *er;
+ struct in_addr addr;
+
+ er = os_zalloc(sizeof(*er));
+ if (er == NULL)
+ return NULL;
+ dl_list_init(&er->ap);
+ dl_list_init(&er->ap_unsubscribing);
+
+ er->multicast_sd = -1;
+ er->ssdp_sd = -1;
+
+ os_strlcpy(er->ifname, ifname, sizeof(er->ifname));
+ er->wps = wps;
+ if (os_get_random((unsigned char *) &er->event_id,
+ sizeof(er->event_id)) < 0) {
+ wps_er_deinit(er, NULL, NULL);
+ return NULL;
+ }
+ /* Limit event_id to < 32 bits to avoid issues with atoi() */
+ er->event_id &= 0x0fffffff;
+
+ if (get_netif_info(ifname, &er->ip_addr, &er->ip_addr_text,
+ er->mac_addr)) {
+ wpa_printf(MSG_INFO, "WPS UPnP: Could not get IP/MAC address "
+ "for %s. Does it have IP address?", ifname);
+ wps_er_deinit(er, NULL, NULL);
+ return NULL;
+ }
+
+ if (wps_er_ssdp_init(er) < 0) {
+ wps_er_deinit(er, NULL, NULL);
+ return NULL;
+ }
+
+ addr.s_addr = er->ip_addr;
+ er->http_srv = http_server_init(&addr, -1, wps_er_http_req, er);
+ if (er->http_srv == NULL) {
+ wps_er_deinit(er, NULL, NULL);
+ return NULL;
+ }
+ er->http_port = http_server_get_port(er->http_srv);
+
+ wpa_printf(MSG_DEBUG, "WPS ER: Start (ifname=%s ip_addr=%s)",
+ er->ifname, er->ip_addr_text);
+
+ return er;
+}
+
+
+void wps_er_refresh(struct wps_er *er)
+{
+ struct wps_er_ap *ap;
+ struct wps_er_sta *sta;
+
+ dl_list_for_each(ap, &er->ap, struct wps_er_ap, list) {
+ wps_er_ap_event(er->wps, ap, WPS_EV_ER_AP_ADD);
+ dl_list_for_each(sta, &ap->sta, struct wps_er_sta, list)
+ wps_er_sta_event(er->wps, sta, WPS_EV_ER_ENROLLEE_ADD);
+ }
+
+ wps_er_send_ssdp_msearch(er);
+}
+
+
+static void wps_er_deinit_finish(void *eloop_data, void *user_ctx)
+{
+ struct wps_er *er = eloop_data;
+ void (*deinit_done_cb)(void *ctx);
+ void *deinit_done_ctx;
+
+ wpa_printf(MSG_DEBUG, "WPS ER: Finishing deinit");
+
+ deinit_done_cb = er->deinit_done_cb;
+ deinit_done_ctx = er->deinit_done_ctx;
+ os_free(er->ip_addr_text);
+ os_free(er);
+
+ if (deinit_done_cb)
+ deinit_done_cb(deinit_done_ctx);
+}
+
+
+void wps_er_deinit(struct wps_er *er, void (*cb)(void *ctx), void *ctx)
+{
+ if (er == NULL)
+ return;
+ http_server_deinit(er->http_srv);
+ wps_er_ap_remove_all(er);
+ wps_er_ssdp_deinit(er);
+ eloop_register_timeout(dl_list_empty(&er->ap_unsubscribing) ? 0 : 5, 0,
+ wps_er_deinit_finish, er, NULL);
+ wpa_printf(MSG_DEBUG, "WPS ER: Finish deinit from timeout");
+ er->deinitializing = 1;
+ er->deinit_done_cb = cb;
+ er->deinit_done_ctx = ctx;
+}
+
+
+static void wps_er_http_set_sel_reg_cb(void *ctx, struct http_client *c,
+ enum http_client_event event)
+{
+ struct wps_er_ap *ap = ctx;
+
+ switch (event) {
+ case HTTP_CLIENT_OK:
+ wpa_printf(MSG_DEBUG, "WPS ER: SetSelectedRegistrar OK");
+ break;
+ case HTTP_CLIENT_FAILED:
+ case HTTP_CLIENT_INVALID_REPLY:
+ case HTTP_CLIENT_TIMEOUT:
+ wpa_printf(MSG_DEBUG, "WPS ER: SetSelectedRegistrar failed");
+ break;
+ }
+ http_client_free(ap->http);
+ ap->http = NULL;
+}
+
+
+static void wps_er_send_set_sel_reg(struct wps_er_ap *ap, struct wpabuf *msg)
+{
+ struct wpabuf *buf;
+ char *len_ptr, *body_ptr;
+ struct sockaddr_in dst;
+ char *url, *path;
+
+ if (ap->control_url == NULL) {
+ wpa_printf(MSG_DEBUG, "WPS ER: No controlURL for AP");
+ return;
+ }
+
+ if (ap->http) {
+ wpa_printf(MSG_DEBUG, "WPS ER: Pending HTTP request for AP - "
+ "ignore new request");
+ return;
+ }
+
+ url = http_client_url_parse(ap->control_url, &dst, &path);
+ if (url == NULL) {
+ wpa_printf(MSG_DEBUG, "WPS ER: Failed to parse controlURL");
+ return;
+ }
+
+ buf = wps_er_soap_hdr(msg, "SetSelectedRegistrar", "NewMessage", path,
+ &dst, &len_ptr, &body_ptr);
+ os_free(url);
+ if (buf == NULL)
+ return;
+
+ wps_er_soap_end(buf, "SetSelectedRegistrar", len_ptr, body_ptr);
+
+ ap->http = http_client_addr(&dst, buf, 1000,
+ wps_er_http_set_sel_reg_cb, ap);
+ if (ap->http == NULL)
+ wpabuf_free(buf);
+}
+
+
+static int wps_er_build_selected_registrar(struct wpabuf *msg, int sel_reg)
+{
+ wpabuf_put_be16(msg, ATTR_SELECTED_REGISTRAR);
+ wpabuf_put_be16(msg, 1);
+ wpabuf_put_u8(msg, !!sel_reg);
+ return 0;
+}
+
+
+static int wps_er_build_dev_password_id(struct wpabuf *msg, u16 dev_passwd_id)
+{
+ wpabuf_put_be16(msg, ATTR_DEV_PASSWORD_ID);
+ wpabuf_put_be16(msg, 2);
+ wpabuf_put_be16(msg, dev_passwd_id);
+ return 0;
+}
+
+
+static int wps_er_build_sel_reg_config_methods(struct wpabuf *msg,
+ u16 sel_reg_config_methods)
+{
+ wpabuf_put_be16(msg, ATTR_SELECTED_REGISTRAR_CONFIG_METHODS);
+ wpabuf_put_be16(msg, 2);
+ wpabuf_put_be16(msg, sel_reg_config_methods);
+ return 0;
+}
+
+
+void wps_er_set_sel_reg(struct wps_er *er, int sel_reg, u16 dev_passwd_id,
+ u16 sel_reg_config_methods)
+{
+ struct wpabuf *msg;
+ struct wps_er_ap *ap;
+
+ msg = wpabuf_alloc(500);
+ if (msg == NULL)
+ return;
+
+ if (wps_build_version(msg) ||
+ wps_er_build_selected_registrar(msg, sel_reg) ||
+ wps_er_build_dev_password_id(msg, dev_passwd_id) ||
+ wps_er_build_sel_reg_config_methods(msg, sel_reg_config_methods)) {
+ wpabuf_free(msg);
+ return;
+ }
+
+ dl_list_for_each(ap, &er->ap, struct wps_er_ap, list)
+ wps_er_send_set_sel_reg(ap, msg);
+
+ wpabuf_free(msg);
+}
+
+
+int wps_er_pbc(struct wps_er *er, const u8 *uuid)
+{
+ if (er == NULL || er->wps == NULL)
+ return -1;
+
+ /*
+ * TODO: Should enable PBC mode only in a single AP based on which AP
+ * the Enrollee (uuid) is using. Now, we may end up enabling multiple
+ * APs in PBC mode which could result in session overlap at the
+ * Enrollee.
+ */
+ if (wps_registrar_button_pushed(er->wps->registrar))
+ return -1;
+
+ return 0;
+}
+
+
+static void wps_er_ap_settings_cb(void *ctx, const struct wps_credential *cred)
+{
+ struct wps_er_ap *ap = ctx;
+ wpa_printf(MSG_DEBUG, "WPS ER: AP Settings received");
+ os_free(ap->ap_settings);
+ ap->ap_settings = os_malloc(sizeof(*cred));
+ if (ap->ap_settings) {
+ os_memcpy(ap->ap_settings, cred, sizeof(*cred));
+ ap->ap_settings->cred_attr = NULL;
+ }
+
+ /* TODO: send info through ctrl_iface */
+}
+
+
+static void wps_er_http_put_message_cb(void *ctx, struct http_client *c,
+ enum http_client_event event)
+{
+ struct wps_er_ap *ap = ctx;
+ struct wpabuf *reply;
+ char *msg = NULL;
+
+ switch (event) {
+ case HTTP_CLIENT_OK:
+ wpa_printf(MSG_DEBUG, "WPS ER: PutMessage OK");
+ reply = http_client_get_body(c);
+ if (reply == NULL)
+ break;
+ msg = os_zalloc(wpabuf_len(reply) + 1);
+ if (msg == NULL)
+ break;
+ os_memcpy(msg, wpabuf_head(reply), wpabuf_len(reply));
+ break;
+ case HTTP_CLIENT_FAILED:
+ case HTTP_CLIENT_INVALID_REPLY:
+ case HTTP_CLIENT_TIMEOUT:
+ wpa_printf(MSG_DEBUG, "WPS ER: PutMessage failed");
+ if (ap->wps) {
+ wps_deinit(ap->wps);
+ ap->wps = NULL;
+ }
+ break;
+ }
+ http_client_free(ap->http);
+ ap->http = NULL;
+
+ if (msg) {
+ struct wpabuf *buf;
+ enum http_reply_code ret;
+ buf = xml_get_base64_item(msg, "NewOutMessage", &ret);
+ os_free(msg);
+ if (buf == NULL) {
+ wpa_printf(MSG_DEBUG, "WPS ER: Could not extract "
+ "NewOutMessage from PutMessage response");
+ return;
+ }
+ wps_er_ap_process(ap, buf);
+ wpabuf_free(buf);
+ }
+}
+
+
+static void wps_er_ap_put_message(struct wps_er_ap *ap,
+ const struct wpabuf *msg)
+{
+ struct wpabuf *buf;
+ char *len_ptr, *body_ptr;
+ struct sockaddr_in dst;
+ char *url, *path;
+
+ if (ap->http) {
+ wpa_printf(MSG_DEBUG, "WPS ER: Pending HTTP operation ongoing "
+ "with the AP - cannot continue learn");
+ return;
+ }
+
+ if (ap->control_url == NULL) {
+ wpa_printf(MSG_DEBUG, "WPS ER: No controlURL for AP");
+ return;
+ }
+
+ url = http_client_url_parse(ap->control_url, &dst, &path);
+ if (url == NULL) {
+ wpa_printf(MSG_DEBUG, "WPS ER: Failed to parse controlURL");
+ return;
+ }
+
+ buf = wps_er_soap_hdr(msg, "PutMessage", "NewInMessage", path, &dst,
+ &len_ptr, &body_ptr);
+ os_free(url);
+ if (buf == NULL)
+ return;
+
+ wps_er_soap_end(buf, "PutMessage", len_ptr, body_ptr);
+
+ ap->http = http_client_addr(&dst, buf, 10000,
+ wps_er_http_put_message_cb, ap);
+ if (ap->http == NULL)
+ wpabuf_free(buf);
+}
+
+
+static void wps_er_ap_process(struct wps_er_ap *ap, struct wpabuf *msg)
+{
+ enum wps_process_res res;
+
+ res = wps_process_msg(ap->wps, WSC_MSG, msg);
+ if (res == WPS_CONTINUE) {
+ enum wsc_op_code op_code;
+ struct wpabuf *next = wps_get_msg(ap->wps, &op_code);
+ if (next) {
+ wps_er_ap_put_message(ap, next);
+ wpabuf_free(next);
+ } else {
+ wpa_printf(MSG_DEBUG, "WPS ER: Failed to build "
+ "message");
+ wps_deinit(ap->wps);
+ ap->wps = NULL;
+ }
+ } else {
+ wpa_printf(MSG_DEBUG, "WPS ER: Failed to process message from "
+ "AP (res=%d)", res);
+ wps_deinit(ap->wps);
+ ap->wps = NULL;
+ }
+}
+
+
+static void wps_er_ap_learn_m1(struct wps_er_ap *ap, struct wpabuf *m1)
+{
+ struct wps_config cfg;
+
+ if (ap->wps) {
+ wpa_printf(MSG_DEBUG, "WPS ER: Protocol run already in "
+ "progress with this AP");
+ return;
+ }
+
+ os_memset(&cfg, 0, sizeof(cfg));
+ cfg.wps = ap->er->wps;
+ cfg.registrar = 1;
+ ap->wps = wps_init(&cfg);
+ if (ap->wps == NULL)
+ return;
+ ap->wps->ap_settings_cb = wps_er_ap_settings_cb;
+ ap->wps->ap_settings_cb_ctx = ap;
+
+ wps_er_ap_process(ap, m1);
+}
+
+
+static void wps_er_ap_learn(struct wps_er_ap *ap, const char *dev_info)
+{
+ struct wpabuf *info;
+ enum http_reply_code ret;
+
+ wpa_printf(MSG_DEBUG, "WPS ER: Received GetDeviceInfo response (M1) "
+ "from the AP");
+ info = xml_get_base64_item(dev_info, "NewDeviceInfo", &ret);
+ if (info == NULL) {
+ wpa_printf(MSG_DEBUG, "WPS ER: Could not extract "
+ "NewDeviceInfo from GetDeviceInfo response");
+ return;
+ }
+
+ ap->m1_handler(ap, info);
+ wpabuf_free(info);
+}
+
+
+static void wps_er_http_get_dev_info_cb(void *ctx, struct http_client *c,
+ enum http_client_event event)
+{
+ struct wps_er_ap *ap = ctx;
+ struct wpabuf *reply;
+ char *dev_info = NULL;
+
+ switch (event) {
+ case HTTP_CLIENT_OK:
+ wpa_printf(MSG_DEBUG, "WPS ER: GetDeviceInfo OK");
+ reply = http_client_get_body(c);
+ if (reply == NULL)
+ break;
+ dev_info = os_zalloc(wpabuf_len(reply) + 1);
+ if (dev_info == NULL)
+ break;
+ os_memcpy(dev_info, wpabuf_head(reply), wpabuf_len(reply));
+ break;
+ case HTTP_CLIENT_FAILED:
+ case HTTP_CLIENT_INVALID_REPLY:
+ case HTTP_CLIENT_TIMEOUT:
+ wpa_printf(MSG_DEBUG, "WPS ER: GetDeviceInfo failed");
+ break;
+ }
+ http_client_free(ap->http);
+ ap->http = NULL;
+
+ if (dev_info) {
+ wps_er_ap_learn(ap, dev_info);
+ os_free(dev_info);
+ }
+}
+
+
+static int wps_er_send_get_device_info(struct wps_er_ap *ap,
+ void (*m1_handler)(struct wps_er_ap *ap,
+ struct wpabuf *m1))
+{
+ struct wpabuf *buf;
+ char *len_ptr, *body_ptr;
+ struct sockaddr_in dst;
+ char *url, *path;
+
+ if (ap->http) {
+ wpa_printf(MSG_DEBUG, "WPS ER: Pending HTTP operation ongoing "
+ "with the AP - cannot get device info");
+ return -1;
+ }
+
+ if (ap->control_url == NULL) {
+ wpa_printf(MSG_DEBUG, "WPS ER: No controlURL for AP");
+ return -1;
+ }
+
+ url = http_client_url_parse(ap->control_url, &dst, &path);
+ if (url == NULL) {
+ wpa_printf(MSG_DEBUG, "WPS ER: Failed to parse controlURL");
+ return -1;
+ }
+
+ buf = wps_er_soap_hdr(NULL, "GetDeviceInfo", NULL, path, &dst,
+ &len_ptr, &body_ptr);
+ os_free(url);
+ if (buf == NULL)
+ return -1;
+
+ wps_er_soap_end(buf, "GetDeviceInfo", len_ptr, body_ptr);
+
+ ap->http = http_client_addr(&dst, buf, 10000,
+ wps_er_http_get_dev_info_cb, ap);
+ if (ap->http == NULL) {
+ wpabuf_free(buf);
+ return -1;
+ }
+
+ ap->m1_handler = m1_handler;
+
+ return 0;
+}
+
+
+int wps_er_learn(struct wps_er *er, const u8 *uuid, const u8 *pin,
+ size_t pin_len)
+{
+ struct wps_er_ap *ap;
+
+ if (er == NULL)
+ return -1;
+
+ ap = wps_er_ap_get(er, NULL, uuid);
+ if (ap == NULL) {
+ wpa_printf(MSG_DEBUG, "WPS ER: AP not found for learn "
+ "request");
+ return -1;
+ }
+ if (ap->wps) {
+ wpa_printf(MSG_DEBUG, "WPS ER: Pending operation ongoing "
+ "with the AP - cannot start learn");
+ return -1;
+ }
+
+ if (wps_er_send_get_device_info(ap, wps_er_ap_learn_m1) < 0)
+ return -1;
+
+ /* TODO: add PIN without SetSelectedRegistrar trigger to all APs */
+ wps_registrar_add_pin(er->wps->registrar, uuid, pin, pin_len, 0);
+
+ return 0;
+}
diff --git a/contrib/wpa/src/wps/wps_er.h b/contrib/wpa/src/wps/wps_er.h
new file mode 100644
index 0000000..b13b950
--- /dev/null
+++ b/contrib/wpa/src/wps/wps_er.h
@@ -0,0 +1,106 @@
+/*
+ * Wi-Fi Protected Setup - External Registrar
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef WPS_ER_H
+#define WPS_ER_H
+
+#include "utils/list.h"
+
+struct wps_er_sta {
+ struct dl_list list;
+ struct wps_er_ap *ap;
+ u8 addr[ETH_ALEN];
+ u16 config_methods;
+ u8 uuid[WPS_UUID_LEN];
+ u8 pri_dev_type[8];
+ u16 dev_passwd_id;
+ int m1_received;
+ char *manufacturer;
+ char *model_name;
+ char *model_number;
+ char *serial_number;
+ char *dev_name;
+ struct wps_data *wps;
+ struct http_client *http;
+ struct wps_credential *cred;
+};
+
+struct wps_er_ap {
+ struct dl_list list;
+ struct wps_er *er;
+ struct dl_list sta; /* list of STAs/Enrollees using this AP */
+ struct in_addr addr;
+ char *location;
+ struct http_client *http;
+ struct wps_data *wps;
+
+ u8 uuid[WPS_UUID_LEN];
+ u8 pri_dev_type[8];
+ u8 wps_state;
+ u8 mac_addr[ETH_ALEN];
+ char *friendly_name;
+ char *manufacturer;
+ char *manufacturer_url;
+ char *model_description;
+ char *model_name;
+ char *model_number;
+ char *model_url;
+ char *serial_number;
+ char *udn;
+ char *upc;
+
+ char *scpd_url;
+ char *control_url;
+ char *event_sub_url;
+
+ int subscribed;
+ u8 sid[WPS_UUID_LEN];
+ unsigned int id;
+
+ struct wps_credential *ap_settings;
+
+ void (*m1_handler)(struct wps_er_ap *ap, struct wpabuf *m1);
+};
+
+struct wps_er {
+ struct wps_context *wps;
+ char ifname[17];
+ u8 mac_addr[ETH_ALEN]; /* mac addr of network i.f. we use */
+ char *ip_addr_text; /* IP address of network i.f. we use */
+ unsigned ip_addr; /* IP address of network i.f. we use (host order) */
+ int multicast_sd;
+ int ssdp_sd;
+ struct dl_list ap;
+ struct dl_list ap_unsubscribing;
+ struct http_server *http_srv;
+ int http_port;
+ unsigned int next_ap_id;
+ unsigned int event_id;
+ int deinitializing;
+ void (*deinit_done_cb)(void *ctx);
+ void *deinit_done_ctx;
+};
+
+
+/* wps_er.c */
+void wps_er_ap_add(struct wps_er *er, const u8 *uuid, struct in_addr *addr,
+ const char *location, int max_age);
+void wps_er_ap_remove(struct wps_er *er, struct in_addr *addr);
+
+/* wps_er_ssdp.c */
+int wps_er_ssdp_init(struct wps_er *er);
+void wps_er_ssdp_deinit(struct wps_er *er);
+void wps_er_send_ssdp_msearch(struct wps_er *er);
+
+#endif /* WPS_ER_H */
diff --git a/contrib/wpa/src/wps/wps_er_ssdp.c b/contrib/wpa/src/wps/wps_er_ssdp.c
new file mode 100644
index 0000000..f108435
--- /dev/null
+++ b/contrib/wpa/src/wps/wps_er_ssdp.c
@@ -0,0 +1,198 @@
+/*
+ * Wi-Fi Protected Setup - External Registrar (SSDP)
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "uuid.h"
+#include "eloop.h"
+#include "wps_i.h"
+#include "wps_upnp.h"
+#include "wps_upnp_i.h"
+#include "wps_er.h"
+
+
+static void wps_er_ssdp_rx(int sd, void *eloop_ctx, void *sock_ctx)
+{
+ struct wps_er *er = eloop_ctx;
+ struct sockaddr_in addr; /* client address */
+ socklen_t addr_len;
+ int nread;
+ char buf[MULTICAST_MAX_READ], *pos, *pos2, *start;
+ int wfa = 0, byebye = 0;
+ int max_age = -1;
+ char *location = NULL;
+ u8 uuid[WPS_UUID_LEN];
+
+ addr_len = sizeof(addr);
+ nread = recvfrom(sd, buf, sizeof(buf) - 1, 0,
+ (struct sockaddr *) &addr, &addr_len);
+ if (nread <= 0)
+ return;
+ buf[nread] = '\0';
+
+ wpa_printf(MSG_DEBUG, "WPS ER: Received SSDP from %s",
+ inet_ntoa(addr.sin_addr));
+ wpa_hexdump_ascii(MSG_MSGDUMP, "WPS ER: Received SSDP contents",
+ (u8 *) buf, nread);
+
+ if (sd == er->multicast_sd) {
+ /* Reply to M-SEARCH */
+ if (os_strncmp(buf, "HTTP/1.1 200 OK", 15) != 0)
+ return; /* unexpected response header */
+ } else {
+ /* Unsolicited message (likely NOTIFY or M-SEARCH) */
+ if (os_strncmp(buf, "NOTIFY ", 7) != 0)
+ return; /* only process notifications */
+ }
+
+ os_memset(uuid, 0, sizeof(uuid));
+
+ for (start = buf; start && *start; start = pos) {
+ pos = os_strchr(start, '\n');
+ if (pos) {
+ if (pos[-1] == '\r')
+ pos[-1] = '\0';
+ *pos++ = '\0';
+ }
+ if (os_strstr(start, "schemas-wifialliance-org:device:"
+ "WFADevice:1"))
+ wfa = 1;
+ if (os_strstr(start, "schemas-wifialliance-org:service:"
+ "WFAWLANConfig:1"))
+ wfa = 1;
+ if (os_strncasecmp(start, "LOCATION:", 9) == 0) {
+ start += 9;
+ while (*start == ' ')
+ start++;
+ location = start;
+ } else if (os_strncasecmp(start, "NTS:", 4) == 0) {
+ if (os_strstr(start, "ssdp:byebye"))
+ byebye = 1;
+ } else if (os_strncasecmp(start, "CACHE-CONTROL:", 14) == 0) {
+ start += 9;
+ while (*start == ' ')
+ start++;
+ pos2 = os_strstr(start, "max-age=");
+ if (pos2 == NULL)
+ continue;
+ pos2 += 8;
+ max_age = atoi(pos2);
+ } else if (os_strncasecmp(start, "USN:", 4) == 0) {
+ start += 4;
+ pos2 = os_strstr(start, "uuid:");
+ if (pos2) {
+ pos2 += 5;
+ while (*pos2 == ' ')
+ pos2++;
+ if (uuid_str2bin(pos2, uuid) < 0) {
+ wpa_printf(MSG_DEBUG, "WPS ER: "
+ "Invalid UUID in USN: %s",
+ pos2);
+ return;
+ }
+ }
+ }
+ }
+
+ if (!wfa)
+ return; /* Not WPS advertisement/reply */
+
+ if (byebye) {
+ wps_er_ap_remove(er, &addr.sin_addr);
+ return;
+ }
+
+ if (!location)
+ return; /* Unknown location */
+
+ if (max_age < 1)
+ return; /* No max-age reported */
+
+ wpa_printf(MSG_DEBUG, "WPS ER: AP discovered: %s "
+ "(packet source: %s max-age: %d)",
+ location, inet_ntoa(addr.sin_addr), max_age);
+
+ wps_er_ap_add(er, uuid, &addr.sin_addr, location, max_age);
+}
+
+
+void wps_er_send_ssdp_msearch(struct wps_er *er)
+{
+ struct wpabuf *msg;
+ struct sockaddr_in dest;
+
+ msg = wpabuf_alloc(500);
+ if (msg == NULL)
+ return;
+
+ wpabuf_put_str(msg,
+ "M-SEARCH * HTTP/1.1\r\n"
+ "HOST: 239.255.255.250:1900\r\n"
+ "MAN: \"ssdp:discover\"\r\n"
+ "MX: 3\r\n"
+ "ST: urn:schemas-wifialliance-org:device:WFADevice:1"
+ "\r\n"
+ "\r\n");
+
+ os_memset(&dest, 0, sizeof(dest));
+ dest.sin_family = AF_INET;
+ dest.sin_addr.s_addr = inet_addr(UPNP_MULTICAST_ADDRESS);
+ dest.sin_port = htons(UPNP_MULTICAST_PORT);
+
+ if (sendto(er->multicast_sd, wpabuf_head(msg), wpabuf_len(msg), 0,
+ (struct sockaddr *) &dest, sizeof(dest)) < 0)
+ wpa_printf(MSG_DEBUG, "WPS ER: M-SEARCH sendto failed: "
+ "%d (%s)", errno, strerror(errno));
+
+ wpabuf_free(msg);
+}
+
+
+int wps_er_ssdp_init(struct wps_er *er)
+{
+ if (add_ssdp_network(er->ifname))
+ return -1;
+
+ er->multicast_sd = ssdp_open_multicast_sock(er->ip_addr);
+ if (er->multicast_sd < 0)
+ return -1;
+
+ er->ssdp_sd = ssdp_listener_open();
+ if (er->ssdp_sd < 0)
+ return -1;
+
+ if (eloop_register_sock(er->multicast_sd, EVENT_TYPE_READ,
+ wps_er_ssdp_rx, er, NULL) ||
+ eloop_register_sock(er->ssdp_sd, EVENT_TYPE_READ,
+ wps_er_ssdp_rx, er, NULL))
+ return -1;
+
+ wps_er_send_ssdp_msearch(er);
+
+ return 0;
+}
+
+
+void wps_er_ssdp_deinit(struct wps_er *er)
+{
+ if (er->multicast_sd >= 0) {
+ eloop_unregister_sock(er->multicast_sd, EVENT_TYPE_READ);
+ close(er->multicast_sd);
+ }
+ if (er->ssdp_sd >= 0) {
+ eloop_unregister_sock(er->ssdp_sd, EVENT_TYPE_READ);
+ close(er->ssdp_sd);
+ }
+}
diff --git a/contrib/wpa/src/wps/wps_i.h b/contrib/wpa/src/wps/wps_i.h
index 3317a2c..50e66f6 100644
--- a/contrib/wpa/src/wps/wps_i.h
+++ b/contrib/wpa/src/wps/wps_i.h
@@ -1,6 +1,6 @@
/*
* Wi-Fi Protected Setup - internal definitions
- * Copyright (c) 2008, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2008-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -34,6 +34,11 @@ struct wps_data {
*/
int registrar;
+ /**
+ * er - Whether the local end is an external registrar
+ */
+ int er;
+
enum {
/* Enrollee states */
SEND_M1, RECV_M2, SEND_M3, RECV_M4, SEND_M5, RECV_M6, SEND_M7,
@@ -99,6 +104,18 @@ struct wps_data {
u16 config_error;
int ext_reg;
+ int int_reg;
+
+ struct wps_credential *new_ap_settings;
+
+ void *dh_ctx;
+
+ void (*ap_settings_cb)(void *ctx, const struct wps_credential *cred);
+ void *ap_settings_cb_ctx;
+
+ struct wps_credential *use_cred;
+
+ int use_psk_key;
};
@@ -120,6 +137,8 @@ struct wps_parse_attr {
const u8 *assoc_state; /* 2 octets */
const u8 *config_error; /* 2 octets */
const u8 *dev_password_id; /* 2 octets */
+ const u8 *oob_dev_password; /* WPS_OOB_DEVICE_PASSWORD_ATTR_LEN (54)
+ * octets */
const u8 *os_version; /* 4 octets */
const u8 *wps_state; /* 1 octet */
const u8 *authenticator; /* WPS_AUTHENTICATOR_LEN (8) octets */
@@ -189,12 +208,17 @@ void wps_pwd_auth_fail_event(struct wps_context *wps, int enrollee, int part);
void wps_pbc_overlap_event(struct wps_context *wps);
void wps_pbc_timeout_event(struct wps_context *wps);
+extern struct oob_device_data oob_ufd_device_data;
+extern struct oob_device_data oob_nfc_device_data;
+extern struct oob_nfc_device_data oob_nfc_pn531_device_data;
+
/* wps_attr_parse.c */
int wps_parse_msg(const struct wpabuf *msg, struct wps_parse_attr *attr);
/* wps_attr_build.c */
int wps_build_public_key(struct wps_data *wps, struct wpabuf *msg);
int wps_build_req_type(struct wpabuf *msg, enum wps_request_type type);
+int wps_build_resp_type(struct wpabuf *msg, enum wps_response_type type);
int wps_build_config_methods(struct wpabuf *msg, u16 methods);
int wps_build_uuid_e(struct wpabuf *msg, const u8 *uuid);
int wps_build_dev_password_id(struct wpabuf *msg, u16 id);
@@ -211,6 +235,7 @@ int wps_build_auth_type_flags(struct wps_data *wps, struct wpabuf *msg);
int wps_build_encr_type_flags(struct wps_data *wps, struct wpabuf *msg);
int wps_build_conn_type_flags(struct wps_data *wps, struct wpabuf *msg);
int wps_build_assoc_state(struct wps_data *wps, struct wpabuf *msg);
+int wps_build_oob_dev_password(struct wpabuf *msg, struct wps_context *wps);
/* wps_attr_process.c */
int wps_process_authenticator(struct wps_data *wps, const u8 *authenticator,
@@ -235,7 +260,14 @@ struct wpabuf * wps_registrar_get_msg(struct wps_data *wps,
enum wps_process_res wps_registrar_process_msg(struct wps_data *wps,
enum wsc_op_code op_code,
const struct wpabuf *msg);
+int wps_build_cred(struct wps_data *wps, struct wpabuf *msg);
+int wps_device_store(struct wps_registrar *reg,
+ struct wps_device_data *dev, const u8 *uuid);
+void wps_registrar_selected_registrar_changed(struct wps_registrar *reg);
+/* ndef.c */
+struct wpabuf * ndef_parse_wifi(struct wpabuf *buf);
+struct wpabuf * ndef_build_wifi(struct wpabuf *buf);
static inline int wps_version_supported(const u8 *version)
{
diff --git a/contrib/wpa/src/wps/wps_nfc.c b/contrib/wpa/src/wps/wps_nfc.c
new file mode 100644
index 0000000..ff12000
--- /dev/null
+++ b/contrib/wpa/src/wps/wps_nfc.c
@@ -0,0 +1,117 @@
+/*
+ * NFC routines for Wi-Fi Protected Setup
+ * Copyright (c) 2009, Masashi Honma <honma@ictec.co.jp>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+#include "common.h"
+
+#include "wps/wps.h"
+#include "wps_i.h"
+
+
+struct wps_nfc_data {
+ struct oob_nfc_device_data *oob_nfc_dev;
+};
+
+
+static void * init_nfc(struct wps_context *wps,
+ struct oob_device_data *oob_dev, int registrar)
+{
+ struct oob_nfc_device_data *oob_nfc_dev;
+ struct wps_nfc_data *data;
+
+ oob_nfc_dev = wps_get_oob_nfc_device(oob_dev->device_name);
+ if (oob_nfc_dev == NULL) {
+ wpa_printf(MSG_ERROR, "WPS (NFC): Unknown NFC device (%s)",
+ oob_dev->device_name);
+ return NULL;
+ }
+
+ if (oob_nfc_dev->init_func(oob_dev->device_path) < 0)
+ return NULL;
+
+ data = os_zalloc(sizeof(*data));
+ if (data == NULL) {
+ wpa_printf(MSG_ERROR, "WPS (NFC): Failed to allocate "
+ "nfc data area");
+ return NULL;
+ }
+ data->oob_nfc_dev = oob_nfc_dev;
+ return data;
+}
+
+
+static struct wpabuf * read_nfc(void *priv)
+{
+ struct wps_nfc_data *data = priv;
+ struct wpabuf *wifi, *buf;
+ char *raw_data;
+ size_t len;
+
+ raw_data = data->oob_nfc_dev->read_func(&len);
+ if (raw_data == NULL)
+ return NULL;
+
+ wifi = wpabuf_alloc_copy(raw_data, len);
+ os_free(raw_data);
+ if (wifi == NULL) {
+ wpa_printf(MSG_ERROR, "WPS (NFC): Failed to allocate "
+ "nfc read area");
+ return NULL;
+ }
+
+ buf = ndef_parse_wifi(wifi);
+ wpabuf_free(wifi);
+ if (buf == NULL)
+ wpa_printf(MSG_ERROR, "WPS (NFC): Failed to unwrap");
+ return buf;
+}
+
+
+static int write_nfc(void *priv, struct wpabuf *buf)
+{
+ struct wps_nfc_data *data = priv;
+ struct wpabuf *wifi;
+ int ret;
+
+ wifi = ndef_build_wifi(buf);
+ if (wifi == NULL) {
+ wpa_printf(MSG_ERROR, "WPS (NFC): Failed to wrap");
+ return -1;
+ }
+
+ ret = data->oob_nfc_dev->write_func(wpabuf_mhead(wifi),
+ wpabuf_len(wifi));
+ wpabuf_free(wifi);
+ return ret;
+}
+
+
+static void deinit_nfc(void *priv)
+{
+ struct wps_nfc_data *data = priv;
+
+ data->oob_nfc_dev->deinit_func();
+
+ os_free(data);
+}
+
+
+struct oob_device_data oob_nfc_device_data = {
+ .device_name = NULL,
+ .device_path = NULL,
+ .init_func = init_nfc,
+ .read_func = read_nfc,
+ .write_func = write_nfc,
+ .deinit_func = deinit_nfc,
+};
diff --git a/contrib/wpa/src/wps/wps_nfc_pn531.c b/contrib/wpa/src/wps/wps_nfc_pn531.c
new file mode 100644
index 0000000..7e05e4d
--- /dev/null
+++ b/contrib/wpa/src/wps/wps_nfc_pn531.c
@@ -0,0 +1,113 @@
+/*
+ * NFC PN531 routines for Wi-Fi Protected Setup
+ * Copyright (c) 2009, Masashi Honma <honma@ictec.co.jp>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+#include "common.h"
+
+#include "wps/wps.h"
+#include "wps_i.h"
+
+#include "WpsNfcType.h"
+#include "WpsNfc.h"
+
+
+static int init_nfc_pn531(char *path)
+{
+ u32 ret;
+
+ ret = WpsNfcInit();
+ if (ret != WPS_NFCLIB_ERR_SUCCESS) {
+ wpa_printf(MSG_ERROR, "WPS (PN531): Failed to initialize "
+ "NFC Library: 0x%08x", ret);
+ return -1;
+ }
+
+ ret = WpsNfcOpenDevice((int8 *) path);
+ if (ret != WPS_NFCLIB_ERR_SUCCESS) {
+ wpa_printf(MSG_ERROR, "WPS (PN531): Failed to open "
+ "NFC Device(%s): 0x%08x", path, ret);
+ goto fail;
+ }
+
+ ret = WpsNfcTokenDiscovery();
+ if (ret != WPS_NFCLIB_ERR_SUCCESS) {
+ wpa_printf(MSG_ERROR, "WPS (PN531): Failed to discover "
+ "token: 0x%08x", ret);
+ WpsNfcCloseDevice();
+ goto fail;
+ }
+
+ return 0;
+
+fail:
+ WpsNfcDeinit();
+ return -1;
+}
+
+
+static void * read_nfc_pn531(size_t *size)
+{
+ uint32 len;
+ u32 ret;
+ int8 *data;
+
+ ret = WpsNfcRawReadToken(&data, &len);
+ if (ret != WPS_NFCLIB_ERR_SUCCESS) {
+ wpa_printf(MSG_ERROR, "WPS (PN531): Failed to read: 0x%08x",
+ ret);
+ return NULL;
+ }
+
+ *size = len;
+ return data;
+}
+
+
+static int write_nfc_pn531(void *data, size_t len)
+{
+ u32 ret;
+
+ ret = WpsNfcRawWriteToken(data, len);
+ if (ret != WPS_NFCLIB_ERR_SUCCESS) {
+ wpa_printf(MSG_ERROR, "WPS (PN531): Failed to write: 0x%08x",
+ ret);
+ return -1;
+ }
+
+ return 0;
+}
+
+
+static void deinit_nfc_pn531(void)
+{
+ u32 ret;
+
+ ret = WpsNfcCloseDevice();
+ if (ret != WPS_NFCLIB_ERR_SUCCESS)
+ wpa_printf(MSG_ERROR, "WPS (PN531): Failed to close "
+ "NFC Device: 0x%08x", ret);
+
+ ret = WpsNfcDeinit();
+ if (ret != WPS_NFCLIB_ERR_SUCCESS)
+ wpa_printf(MSG_ERROR, "WPS (PN531): Failed to deinitialize "
+ "NFC Library: 0x%08x", ret);
+}
+
+
+struct oob_nfc_device_data oob_nfc_pn531_device_data = {
+ .init_func = init_nfc_pn531,
+ .read_func = read_nfc_pn531,
+ .write_func = write_nfc_pn531,
+ .deinit_func = deinit_nfc_pn531,
+};
diff --git a/contrib/wpa/src/wps/wps_registrar.c b/contrib/wpa/src/wps/wps_registrar.c
index f34c9e9..81ddf3a 100644
--- a/contrib/wpa/src/wps/wps_registrar.c
+++ b/contrib/wpa/src/wps/wps_registrar.c
@@ -1,6 +1,6 @@
/*
* Wi-Fi Protected Setup - Registrar
- * Copyright (c) 2008, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2008-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -12,21 +12,25 @@
* See README and COPYING for more details.
*/
-#include "includes.h"
+#include "utils/includes.h"
-#include "common.h"
-#include "sha256.h"
-#include "base64.h"
-#include "ieee802_11_defs.h"
-#include "eloop.h"
+#include "utils/common.h"
+#include "utils/base64.h"
+#include "utils/eloop.h"
+#include "utils/uuid.h"
+#include "utils/list.h"
+#include "crypto/crypto.h"
+#include "crypto/sha256.h"
+#include "common/ieee802_11_defs.h"
#include "wps_i.h"
#include "wps_dev_attr.h"
#include "wps_upnp.h"
+#include "wps_upnp_i.h"
#define WPS_WORKAROUNDS
struct wps_uuid_pin {
- struct wps_uuid_pin *next;
+ struct dl_list list;
u8 uuid[WPS_UUID_LEN];
int wildcard_uuid;
u8 *pin;
@@ -45,16 +49,18 @@ static void wps_free_pin(struct wps_uuid_pin *pin)
}
-static void wps_free_pins(struct wps_uuid_pin *pins)
+static void wps_remove_pin(struct wps_uuid_pin *pin)
{
- struct wps_uuid_pin *pin, *prev;
+ dl_list_del(&pin->list);
+ wps_free_pin(pin);
+}
- pin = pins;
- while (pin) {
- prev = pin;
- pin = pin->next;
- wps_free_pin(prev);
- }
+
+static void wps_free_pins(struct dl_list *pins)
+{
+ struct wps_uuid_pin *pin, *prev;
+ dl_list_for_each_safe(pin, prev, pins, struct wps_uuid_pin, list)
+ wps_remove_pin(pin);
}
@@ -78,6 +84,13 @@ static void wps_free_pbc_sessions(struct wps_pbc_session *pbc)
}
+struct wps_registrar_device {
+ struct wps_registrar_device *next;
+ struct wps_device_data dev;
+ u8 uuid[WPS_UUID_LEN];
+};
+
+
struct wps_registrar {
struct wps_context *wps;
@@ -86,24 +99,33 @@ struct wps_registrar {
int (*new_psk_cb)(void *ctx, const u8 *mac_addr, const u8 *psk,
size_t psk_len);
- int (*set_ie_cb)(void *ctx, const u8 *beacon_ie, size_t beacon_ie_len,
- const u8 *probe_resp_ie, size_t probe_resp_ie_len);
+ int (*set_ie_cb)(void *ctx, struct wpabuf *beacon_ie,
+ struct wpabuf *probe_resp_ie);
void (*pin_needed_cb)(void *ctx, const u8 *uuid_e,
const struct wps_device_data *dev);
void (*reg_success_cb)(void *ctx, const u8 *mac_addr,
const u8 *uuid_e);
+ void (*set_sel_reg_cb)(void *ctx, int sel_reg, u16 dev_passwd_id,
+ u16 sel_reg_config_methods);
+ void (*enrollee_seen_cb)(void *ctx, const u8 *addr, const u8 *uuid_e,
+ const u8 *pri_dev_type, u16 config_methods,
+ u16 dev_password_id, u8 request_type,
+ const char *dev_name);
void *cb_ctx;
- struct wps_uuid_pin *pins;
+ struct dl_list pins;
struct wps_pbc_session *pbc_sessions;
int skip_cred_build;
struct wpabuf *extra_cred;
int disable_auto_conf;
+ int sel_reg_union;
int sel_reg_dev_password_id_override;
int sel_reg_config_methods_override;
int static_wep_only;
+ struct wps_registrar_device *devices;
+
int force_pbc_overlap;
};
@@ -114,6 +136,72 @@ static void wps_registrar_set_selected_timeout(void *eloop_ctx,
void *timeout_ctx);
+static void wps_free_devices(struct wps_registrar_device *dev)
+{
+ struct wps_registrar_device *prev;
+
+ while (dev) {
+ prev = dev;
+ dev = dev->next;
+ wps_device_data_free(&prev->dev);
+ os_free(prev);
+ }
+}
+
+
+static struct wps_registrar_device * wps_device_get(struct wps_registrar *reg,
+ const u8 *addr)
+{
+ struct wps_registrar_device *dev;
+
+ for (dev = reg->devices; dev; dev = dev->next) {
+ if (os_memcmp(dev->dev.mac_addr, addr, ETH_ALEN) == 0)
+ return dev;
+ }
+ return NULL;
+}
+
+
+static void wps_device_clone_data(struct wps_device_data *dst,
+ struct wps_device_data *src)
+{
+ os_memcpy(dst->mac_addr, src->mac_addr, ETH_ALEN);
+ os_memcpy(dst->pri_dev_type, src->pri_dev_type, WPS_DEV_TYPE_LEN);
+
+#define WPS_STRDUP(n) \
+ os_free(dst->n); \
+ dst->n = src->n ? os_strdup(src->n) : NULL
+
+ WPS_STRDUP(device_name);
+ WPS_STRDUP(manufacturer);
+ WPS_STRDUP(model_name);
+ WPS_STRDUP(model_number);
+ WPS_STRDUP(serial_number);
+#undef WPS_STRDUP
+}
+
+
+int wps_device_store(struct wps_registrar *reg,
+ struct wps_device_data *dev, const u8 *uuid)
+{
+ struct wps_registrar_device *d;
+
+ d = wps_device_get(reg, dev->mac_addr);
+ if (d == NULL) {
+ d = os_zalloc(sizeof(*d));
+ if (d == NULL)
+ return -1;
+ d->next = reg->devices;
+ reg->devices = d;
+ }
+
+ wps_device_clone_data(&d->dev, dev);
+ os_memcpy(d->uuid, uuid, WPS_UUID_LEN);
+
+ return 0;
+}
+
+
static void wps_registrar_add_pbc_session(struct wps_registrar *reg,
const u8 *addr, const u8 *uuid_e)
{
@@ -264,7 +352,7 @@ static int wps_build_ap_setup_locked(struct wps_context *wps,
static int wps_build_selected_registrar(struct wps_registrar *reg,
struct wpabuf *msg)
{
- if (!reg->selected_registrar)
+ if (!reg->sel_reg_union)
return 0;
wpa_printf(MSG_DEBUG, "WPS: * Selected Registrar");
wpabuf_put_be16(msg, ATTR_SELECTED_REGISTRAR);
@@ -278,7 +366,7 @@ static int wps_build_sel_reg_dev_password_id(struct wps_registrar *reg,
struct wpabuf *msg)
{
u16 id = reg->pbc ? DEV_PW_PUSHBUTTON : DEV_PW_DEFAULT;
- if (!reg->selected_registrar)
+ if (!reg->sel_reg_union)
return 0;
if (reg->sel_reg_dev_password_id_override >= 0)
id = reg->sel_reg_dev_password_id_override;
@@ -294,7 +382,7 @@ static int wps_build_sel_reg_config_methods(struct wps_registrar *reg,
struct wpabuf *msg)
{
u16 methods;
- if (!reg->selected_registrar)
+ if (!reg->sel_reg_union)
return 0;
methods = reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
if (reg->pbc)
@@ -314,7 +402,11 @@ static int wps_build_probe_config_methods(struct wps_registrar *reg,
struct wpabuf *msg)
{
u16 methods;
- methods = 0;
+ /*
+ * These are the methods that the AP supports as an Enrollee for adding
+ * external Registrars.
+ */
+ methods = reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
wpa_printf(MSG_DEBUG, "WPS: * Config Methods (%x)", methods);
wpabuf_put_be16(msg, ATTR_CONFIG_METHODS);
wpabuf_put_be16(msg, 2);
@@ -334,17 +426,6 @@ static int wps_build_config_methods_r(struct wps_registrar *reg,
}
-static int wps_build_resp_type(struct wps_registrar *reg, struct wpabuf *msg)
-{
- u8 resp = reg->wps->ap ? WPS_RESP_AP : WPS_RESP_REGISTRAR;
- wpa_printf(MSG_DEBUG, "WPS: * Response Type (%d)", resp);
- wpabuf_put_be16(msg, ATTR_RESPONSE_TYPE);
- wpabuf_put_be16(msg, 1);
- wpabuf_put_u8(msg, resp);
- return 0;
-}
-
-
/**
* wps_registrar_init - Initialize WPS Registrar data
* @wps: Pointer to longterm WPS context
@@ -365,11 +446,14 @@ wps_registrar_init(struct wps_context *wps,
if (reg == NULL)
return NULL;
+ dl_list_init(&reg->pins);
reg->wps = wps;
reg->new_psk_cb = cfg->new_psk_cb;
reg->set_ie_cb = cfg->set_ie_cb;
reg->pin_needed_cb = cfg->pin_needed_cb;
reg->reg_success_cb = cfg->reg_success_cb;
+ reg->set_sel_reg_cb = cfg->set_sel_reg_cb;
+ reg->enrollee_seen_cb = cfg->enrollee_seen_cb;
reg->cb_ctx = cfg->cb_ctx;
reg->skip_cred_build = cfg->skip_cred_build;
if (cfg->extra_cred) {
@@ -404,9 +488,10 @@ void wps_registrar_deinit(struct wps_registrar *reg)
return;
eloop_cancel_timeout(wps_registrar_pbc_timeout, reg, NULL);
eloop_cancel_timeout(wps_registrar_set_selected_timeout, reg, NULL);
- wps_free_pins(reg->pins);
+ wps_free_pins(&reg->pins);
wps_free_pbc_sessions(reg->pbc_sessions);
wpabuf_free(reg->extra_cred);
+ wps_free_devices(reg->devices);
os_free(reg);
}
@@ -446,8 +531,7 @@ int wps_registrar_add_pin(struct wps_registrar *reg, const u8 *uuid,
p->expiration.sec += timeout;
}
- p->next = reg->pins;
- reg->pins = p;
+ dl_list_add(&reg->pins, &p->list);
wpa_printf(MSG_DEBUG, "WPS: A new PIN configured (timeout=%d)",
timeout);
@@ -455,7 +539,7 @@ int wps_registrar_add_pin(struct wps_registrar *reg, const u8 *uuid,
wpa_hexdump_ascii_key(MSG_DEBUG, "WPS: PIN", pin, pin_len);
reg->selected_registrar = 1;
reg->pbc = 0;
- wps_set_ie(reg);
+ wps_registrar_selected_registrar_changed(reg);
eloop_cancel_timeout(wps_registrar_set_selected_timeout, reg, NULL);
eloop_register_timeout(WPS_PBC_WALK_TIME, 0,
wps_registrar_set_selected_timeout,
@@ -467,28 +551,18 @@ int wps_registrar_add_pin(struct wps_registrar *reg, const u8 *uuid,
static void wps_registrar_expire_pins(struct wps_registrar *reg)
{
- struct wps_uuid_pin *pin, *prev, *del;
+ struct wps_uuid_pin *pin, *prev;
struct os_time now;
os_get_time(&now);
- prev = NULL;
- pin = reg->pins;
- while (pin) {
+ dl_list_for_each_safe(pin, prev, &reg->pins, struct wps_uuid_pin, list)
+ {
if ((pin->flags & PIN_EXPIRES) &&
os_time_before(&pin->expiration, &now)) {
- if (prev == NULL)
- reg->pins = pin->next;
- else
- prev->next = pin->next;
- del = pin;
- pin = pin->next;
wpa_hexdump(MSG_DEBUG, "WPS: Expired PIN for UUID",
- del->uuid, WPS_UUID_LEN);
- wps_free_pin(del);
- continue;
+ pin->uuid, WPS_UUID_LEN);
+ wps_remove_pin(pin);
}
- prev = pin;
- pin = pin->next;
}
}
@@ -503,21 +577,14 @@ int wps_registrar_invalidate_pin(struct wps_registrar *reg, const u8 *uuid)
{
struct wps_uuid_pin *pin, *prev;
- prev = NULL;
- pin = reg->pins;
- while (pin) {
+ dl_list_for_each_safe(pin, prev, &reg->pins, struct wps_uuid_pin, list)
+ {
if (os_memcmp(pin->uuid, uuid, WPS_UUID_LEN) == 0) {
- if (prev == NULL)
- reg->pins = pin->next;
- else
- prev->next = pin->next;
wpa_hexdump(MSG_DEBUG, "WPS: Invalidated PIN for UUID",
pin->uuid, WPS_UUID_LEN);
- wps_free_pin(pin);
+ wps_remove_pin(pin);
return 0;
}
- prev = pin;
- pin = pin->next;
}
return -1;
@@ -527,49 +594,48 @@ int wps_registrar_invalidate_pin(struct wps_registrar *reg, const u8 *uuid)
static const u8 * wps_registrar_get_pin(struct wps_registrar *reg,
const u8 *uuid, size_t *pin_len)
{
- struct wps_uuid_pin *pin;
+ struct wps_uuid_pin *pin, *found = NULL;
wps_registrar_expire_pins(reg);
- pin = reg->pins;
- while (pin) {
+ dl_list_for_each(pin, &reg->pins, struct wps_uuid_pin, list) {
if (!pin->wildcard_uuid &&
- os_memcmp(pin->uuid, uuid, WPS_UUID_LEN) == 0)
+ os_memcmp(pin->uuid, uuid, WPS_UUID_LEN) == 0) {
+ found = pin;
break;
- pin = pin->next;
+ }
}
- if (!pin) {
+ if (!found) {
/* Check for wildcard UUIDs since none of the UUID-specific
* PINs matched */
- pin = reg->pins;
- while (pin) {
+ dl_list_for_each(pin, &reg->pins, struct wps_uuid_pin, list) {
if (pin->wildcard_uuid == 1) {
wpa_printf(MSG_DEBUG, "WPS: Found a wildcard "
"PIN. Assigned it for this UUID-E");
pin->wildcard_uuid = 2;
os_memcpy(pin->uuid, uuid, WPS_UUID_LEN);
+ found = pin;
break;
}
- pin = pin->next;
}
}
- if (!pin)
+ if (!found)
return NULL;
/*
* Lock the PIN to avoid attacks based on concurrent re-use of the PIN
* that could otherwise avoid PIN invalidations.
*/
- if (pin->flags & PIN_LOCKED) {
+ if (found->flags & PIN_LOCKED) {
wpa_printf(MSG_DEBUG, "WPS: Selected PIN locked - do not "
"allow concurrent re-use");
return NULL;
}
- *pin_len = pin->pin_len;
- pin->flags |= PIN_LOCKED;
- return pin->pin;
+ *pin_len = found->pin_len;
+ found->flags |= PIN_LOCKED;
+ return found->pin;
}
@@ -587,8 +653,7 @@ int wps_registrar_unlock_pin(struct wps_registrar *reg, const u8 *uuid)
{
struct wps_uuid_pin *pin;
- pin = reg->pins;
- while (pin) {
+ dl_list_for_each(pin, &reg->pins, struct wps_uuid_pin, list) {
if (os_memcmp(pin->uuid, uuid, WPS_UUID_LEN) == 0) {
if (pin->wildcard_uuid == 2) {
wpa_printf(MSG_DEBUG, "WPS: Invalidating used "
@@ -598,7 +663,6 @@ int wps_registrar_unlock_pin(struct wps_registrar *reg, const u8 *uuid)
pin->flags &= ~PIN_LOCKED;
return 0;
}
- pin = pin->next;
}
return -1;
@@ -609,7 +673,7 @@ static void wps_registrar_stop_pbc(struct wps_registrar *reg)
{
reg->selected_registrar = 0;
reg->pbc = 0;
- wps_set_ie(reg);
+ wps_registrar_selected_registrar_changed(reg);
}
@@ -644,7 +708,7 @@ int wps_registrar_button_pushed(struct wps_registrar *reg)
reg->force_pbc_overlap = 0;
reg->selected_registrar = 1;
reg->pbc = 1;
- wps_set_ie(reg);
+ wps_registrar_selected_registrar_changed(reg);
eloop_cancel_timeout(wps_registrar_pbc_timeout, reg, NULL);
eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wps_registrar_pbc_timeout,
@@ -660,12 +724,13 @@ static void wps_registrar_pbc_completed(struct wps_registrar *reg)
wps_registrar_stop_pbc(reg);
}
+
static void wps_registrar_pin_completed(struct wps_registrar *reg)
{
wpa_printf(MSG_DEBUG, "WPS: PIN completed using internal Registrar");
eloop_cancel_timeout(wps_registrar_set_selected_timeout, reg, NULL);
reg->selected_registrar = 0;
- wps_set_ie(reg);
+ wps_registrar_selected_registrar_changed(reg);
}
@@ -683,7 +748,6 @@ void wps_registrar_probe_req_rx(struct wps_registrar *reg, const u8 *addr,
const struct wpabuf *wps_data)
{
struct wps_parse_attr attr;
- u16 methods;
wpa_hexdump_buf(MSG_MSGDUMP,
"WPS: Probe Request with WPS data received",
@@ -703,8 +767,31 @@ void wps_registrar_probe_req_rx(struct wps_registrar *reg, const u8 *addr,
return;
}
- methods = WPA_GET_BE16(attr.config_methods);
- if (!(methods & WPS_CONFIG_PUSHBUTTON))
+ if (attr.dev_password_id == NULL) {
+ wpa_printf(MSG_DEBUG, "WPS: No Device Password Id attribute "
+ "in Probe Request");
+ return;
+ }
+
+ if (reg->enrollee_seen_cb && attr.uuid_e &&
+ attr.primary_dev_type && attr.request_type) {
+ char *dev_name = NULL;
+ if (attr.dev_name) {
+ dev_name = os_zalloc(attr.dev_name_len + 1);
+ if (dev_name) {
+ os_memcpy(dev_name, attr.dev_name,
+ attr.dev_name_len);
+ }
+ }
+ reg->enrollee_seen_cb(reg->cb_ctx, addr, attr.uuid_e,
+ attr.primary_dev_type,
+ WPA_GET_BE16(attr.config_methods),
+ WPA_GET_BE16(attr.dev_password_id),
+ *attr.request_type, dev_name);
+ os_free(dev_name);
+ }
+
+ if (WPA_GET_BE16(attr.dev_password_id) != DEV_PW_PUSHBUTTON)
return; /* Not PBC */
wpa_printf(MSG_DEBUG, "WPS: Probe Request for PBC received from "
@@ -754,17 +841,28 @@ static void wps_cb_reg_success(struct wps_registrar *reg, const u8 *mac_addr,
}
-static int wps_cb_set_ie(struct wps_registrar *reg,
- const struct wpabuf *beacon_ie,
- const struct wpabuf *probe_resp_ie)
+static int wps_cb_set_ie(struct wps_registrar *reg, struct wpabuf *beacon_ie,
+ struct wpabuf *probe_resp_ie)
{
- if (reg->set_ie_cb == NULL)
- return 0;
+ return reg->set_ie_cb(reg->cb_ctx, beacon_ie, probe_resp_ie);
+}
- return reg->set_ie_cb(reg->cb_ctx, wpabuf_head(beacon_ie),
- wpabuf_len(beacon_ie),
- wpabuf_head(probe_resp_ie),
- wpabuf_len(probe_resp_ie));
+
+static void wps_cb_set_sel_reg(struct wps_registrar *reg)
+{
+ u16 methods = 0;
+ if (reg->set_sel_reg_cb == NULL)
+ return;
+
+ if (reg->selected_registrar) {
+ methods = reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
+ if (reg->pbc)
+ methods |= WPS_CONFIG_PUSHBUTTON;
+ }
+
+ reg->set_sel_reg_cb(reg->cb_ctx, reg->selected_registrar,
+ reg->pbc ? DEV_PW_PUSHBUTTON : DEV_PW_DEFAULT,
+ methods);
}
@@ -804,7 +902,9 @@ static int wps_set_ie(struct wps_registrar *reg)
{
struct wpabuf *beacon;
struct wpabuf *probe;
- int ret;
+
+ if (reg->set_ie_cb == NULL)
+ return 0;
wpa_printf(MSG_DEBUG, "WPS: Build Beacon and Probe Response IEs");
@@ -829,7 +929,8 @@ static int wps_set_ie(struct wps_registrar *reg)
wps_build_selected_registrar(reg, probe) ||
wps_build_sel_reg_dev_password_id(reg, probe) ||
wps_build_sel_reg_config_methods(reg, probe) ||
- wps_build_resp_type(reg, probe) ||
+ wps_build_resp_type(probe, reg->wps->ap ? WPS_RESP_AP :
+ WPS_RESP_REGISTRAR) ||
wps_build_uuid_e(probe, reg->wps->uuid) ||
wps_build_device_attrs(&reg->wps->dev, probe) ||
wps_build_probe_config_methods(reg, probe) ||
@@ -870,11 +971,7 @@ static int wps_set_ie(struct wps_registrar *reg)
wpabuf_put_data(probe, ms_wps, sizeof(ms_wps));
}
- ret = wps_cb_set_ie(reg, beacon, probe);
- wpabuf_free(beacon);
- wpabuf_free(probe);
-
- return ret;
+ return wps_cb_set_ie(reg, beacon, probe);
}
@@ -992,7 +1089,7 @@ static int wps_build_r_snonce2(struct wps_data *wps, struct wpabuf *msg)
static int wps_build_cred_network_idx(struct wpabuf *msg,
- struct wps_credential *cred)
+ const struct wps_credential *cred)
{
wpa_printf(MSG_DEBUG, "WPS: * Network Index");
wpabuf_put_be16(msg, ATTR_NETWORK_INDEX);
@@ -1003,7 +1100,7 @@ static int wps_build_cred_network_idx(struct wpabuf *msg,
static int wps_build_cred_ssid(struct wpabuf *msg,
- struct wps_credential *cred)
+ const struct wps_credential *cred)
{
wpa_printf(MSG_DEBUG, "WPS: * SSID");
wpabuf_put_be16(msg, ATTR_SSID);
@@ -1014,7 +1111,7 @@ static int wps_build_cred_ssid(struct wpabuf *msg,
static int wps_build_cred_auth_type(struct wpabuf *msg,
- struct wps_credential *cred)
+ const struct wps_credential *cred)
{
wpa_printf(MSG_DEBUG, "WPS: * Authentication Type (0x%x)",
cred->auth_type);
@@ -1026,7 +1123,7 @@ static int wps_build_cred_auth_type(struct wpabuf *msg,
static int wps_build_cred_encr_type(struct wpabuf *msg,
- struct wps_credential *cred)
+ const struct wps_credential *cred)
{
wpa_printf(MSG_DEBUG, "WPS: * Encryption Type (0x%x)",
cred->encr_type);
@@ -1038,9 +1135,10 @@ static int wps_build_cred_encr_type(struct wpabuf *msg,
static int wps_build_cred_network_key(struct wpabuf *msg,
- struct wps_credential *cred)
+ const struct wps_credential *cred)
{
- wpa_printf(MSG_DEBUG, "WPS: * Network Key");
+ wpa_printf(MSG_DEBUG, "WPS: * Network Key (len=%d)",
+ (int) cred->key_len);
wpabuf_put_be16(msg, ATTR_NETWORK_KEY);
wpabuf_put_be16(msg, cred->key_len);
wpabuf_put_data(msg, cred->key, cred->key_len);
@@ -1049,7 +1147,7 @@ static int wps_build_cred_network_key(struct wpabuf *msg,
static int wps_build_cred_mac_addr(struct wpabuf *msg,
- struct wps_credential *cred)
+ const struct wps_credential *cred)
{
wpa_printf(MSG_DEBUG, "WPS: * MAC Address (" MACSTR ")",
MAC2STR(cred->mac_addr));
@@ -1061,7 +1159,7 @@ static int wps_build_cred_mac_addr(struct wpabuf *msg,
static int wps_build_credential(struct wpabuf *msg,
- struct wps_credential *cred)
+ const struct wps_credential *cred)
{
if (wps_build_cred_network_idx(msg, cred) ||
wps_build_cred_ssid(msg, cred) ||
@@ -1074,7 +1172,7 @@ static int wps_build_credential(struct wpabuf *msg,
}
-static int wps_build_cred(struct wps_data *wps, struct wpabuf *msg)
+int wps_build_cred(struct wps_data *wps, struct wpabuf *msg)
{
struct wpabuf *cred;
@@ -1082,6 +1180,10 @@ static int wps_build_cred(struct wps_data *wps, struct wpabuf *msg)
goto skip_cred_build;
wpa_printf(MSG_DEBUG, "WPS: * Credential");
+ if (wps->use_cred) {
+ os_memcpy(&wps->cred, wps->use_cred, sizeof(wps->cred));
+ goto use_provided;
+ }
os_memset(&wps->cred, 0, sizeof(wps->cred));
os_memcpy(wps->cred.ssid, wps->wps->ssid, wps->wps->ssid_len);
@@ -1149,6 +1251,12 @@ static int wps_build_cred(struct wps_data *wps, struct wpabuf *msg)
wps->new_psk, wps->new_psk_len);
os_memcpy(wps->cred.key, wps->new_psk, wps->new_psk_len);
wps->cred.key_len = wps->new_psk_len;
+ } else if (wps->use_psk_key && wps->wps->psk_set) {
+ char hex[65];
+ wpa_printf(MSG_DEBUG, "WPS: Use PSK format for Network Key");
+ wpa_snprintf_hex(hex, sizeof(hex), wps->wps->psk, 32);
+ os_memcpy(wps->cred.key, hex, 32 * 2);
+ wps->cred.key_len = 32 * 2;
} else if (wps->wps->network_key) {
os_memcpy(wps->cred.key, wps->wps->network_key,
wps->wps->network_key_len);
@@ -1174,6 +1282,7 @@ static int wps_build_cred(struct wps_data *wps, struct wpabuf *msg)
wps->cred.key_len = wps->new_psk_len * 2;
}
+use_provided:
cred = wpabuf_alloc(200);
if (cred == NULL)
return -1;
@@ -1246,6 +1355,7 @@ static struct wpabuf * wps_build_m2(struct wps_data *wps)
return NULL;
}
+ wps->int_reg = 1;
wps->state = RECV_M3;
return msg;
}
@@ -1379,8 +1489,8 @@ static struct wpabuf * wps_build_m8(struct wps_data *wps)
if (wps_build_version(msg) ||
wps_build_msg_type(msg, WPS_M8) ||
wps_build_enrollee_nonce(wps, msg) ||
- (wps->wps->ap && wps_build_cred(wps, plain)) ||
- (!wps->wps->ap && wps_build_ap_settings(wps, plain)) ||
+ ((wps->wps->ap || wps->er) && wps_build_cred(wps, plain)) ||
+ (!wps->wps->ap && !wps->er && wps_build_ap_settings(wps, plain)) ||
wps_build_key_wrap_auth(wps, plain) ||
wps_build_encr_settings(wps, msg, plain) ||
wps_build_authenticator(wps, msg)) {
@@ -1446,7 +1556,7 @@ struct wpabuf * wps_registrar_get_msg(struct wps_data *wps,
struct wpabuf *msg;
#ifdef CONFIG_WPS_UPNP
- if (wps->wps->wps_upnp) {
+ if (!wps->int_reg && wps->wps->wps_upnp) {
struct upnp_pending_message *p, *prev = NULL;
if (wps->ext_reg > 1)
wps_registrar_free_pending_m2(wps->wps);
@@ -1732,6 +1842,22 @@ static int wps_process_pubkey(struct wps_data *wps, const u8 *pk,
return -1;
}
+#ifdef CONFIG_WPS_OOB
+ if (wps->wps->oob_conf.pubkey_hash != NULL) {
+ const u8 *addr[1];
+ u8 hash[WPS_HASH_LEN];
+
+ addr[0] = pk;
+ sha256_vector(1, addr, &pk_len, hash);
+ if (os_memcmp(hash,
+ wpabuf_head(wps->wps->oob_conf.pubkey_hash),
+ WPS_OOB_PUBKEY_HASH_LEN) != 0) {
+ wpa_printf(MSG_ERROR, "WPS: Public Key hash error");
+ return -1;
+ }
+ }
+#endif /* CONFIG_WPS_OOB */
+
wpabuf_free(wps->dh_pubkey_e);
wps->dh_pubkey_e = wpabuf_alloc_copy(pk, pk_len);
if (wps->dh_pubkey_e == NULL)
@@ -1847,7 +1973,28 @@ static int wps_process_config_methods(struct wps_data *wps, const u8 *methods)
m = WPA_GET_BE16(methods);
- wpa_printf(MSG_DEBUG, "WPS: Enrollee Config Methods 0x%x", m);
+ wpa_printf(MSG_DEBUG, "WPS: Enrollee Config Methods 0x%x"
+ "%s%s%s%s%s%s%s%s%s", m,
+ m & WPS_CONFIG_USBA ? " [USBA]" : "",
+ m & WPS_CONFIG_ETHERNET ? " [Ethernet]" : "",
+ m & WPS_CONFIG_LABEL ? " [Label]" : "",
+ m & WPS_CONFIG_DISPLAY ? " [Display]" : "",
+ m & WPS_CONFIG_EXT_NFC_TOKEN ? " [Ext NFC Token]" : "",
+ m & WPS_CONFIG_INT_NFC_TOKEN ? " [Int NFC Token]" : "",
+ m & WPS_CONFIG_NFC_INTERFACE ? " [NFC]" : "",
+ m & WPS_CONFIG_PUSHBUTTON ? " [PBC]" : "",
+ m & WPS_CONFIG_KEYPAD ? " [Keypad]" : "");
+
+ if (!(m & WPS_CONFIG_DISPLAY) && !wps->use_psk_key) {
+ /*
+ * The Enrollee does not have a display so it is unlikely to be
+ * able to show the passphrase to a user and as such, could
+ * benefit from receiving PSK to reduce key derivation time.
+ */
+ wpa_printf(MSG_DEBUG, "WPS: Prefer PSK format key due to "
+ "Enrollee not supporting display");
+ wps->use_psk_key = 1;
+ }
return 0;
}
@@ -1928,7 +2075,8 @@ static enum wps_process_res wps_process_m1(struct wps_data *wps,
wps_process_os_version(&wps->peer_dev, attr->os_version))
return WPS_FAILURE;
- if (wps->dev_pw_id != DEV_PW_DEFAULT &&
+ if (wps->dev_pw_id < 0x10 &&
+ wps->dev_pw_id != DEV_PW_DEFAULT &&
wps->dev_pw_id != DEV_PW_USER_SPECIFIED &&
wps->dev_pw_id != DEV_PW_MACHINE_SPECIFIED &&
wps->dev_pw_id != DEV_PW_REGISTRAR_SPECIFIED &&
@@ -1940,6 +2088,16 @@ static enum wps_process_res wps_process_m1(struct wps_data *wps,
return WPS_CONTINUE;
}
+#ifdef CONFIG_WPS_OOB
+ if (wps->dev_pw_id >= 0x10 &&
+ wps->dev_pw_id != wps->wps->oob_dev_pw_id) {
+ wpa_printf(MSG_DEBUG, "WPS: OOB Device Password ID "
+ "%d mismatch", wps->dev_pw_id);
+ wps->state = SEND_M2D;
+ return WPS_CONTINUE;
+ }
+#endif /* CONFIG_WPS_OOB */
+
if (wps->dev_pw_id == DEV_PW_PUSHBUTTON) {
if (wps->wps->registrar->force_pbc_overlap ||
wps_registrar_pbc_overlap(wps->wps->registrar,
@@ -1957,6 +2115,23 @@ static enum wps_process_res wps_process_m1(struct wps_data *wps,
wps->pbc = 1;
}
+#ifdef WPS_WORKAROUNDS
+ /*
+ * It looks like Mac OS X 10.6.3 and 10.6.4 do not like Network Key in
+ * passphrase format. To avoid interop issues, force PSK format to be
+ * used.
+ */
+ if (!wps->use_psk_key &&
+ wps->peer_dev.manufacturer &&
+ os_strncmp(wps->peer_dev.manufacturer, "Apple ", 6) == 0 &&
+ wps->peer_dev.model_name &&
+ os_strcmp(wps->peer_dev.model_name, "AirPort") == 0) {
+ wpa_printf(MSG_DEBUG, "WPS: Workaround - Force Network Key in "
+ "PSK format");
+ wps->use_psk_key = 1;
+ }
+#endif /* WPS_WORKAROUNDS */
+
wps->state = SEND_M2;
return WPS_CONTINUE;
}
@@ -2073,10 +2248,23 @@ static void wps_sta_cred_cb(struct wps_data *wps)
}
+static void wps_cred_update(struct wps_credential *dst,
+ struct wps_credential *src)
+{
+ os_memcpy(dst->ssid, src->ssid, sizeof(dst->ssid));
+ dst->ssid_len = src->ssid_len;
+ dst->auth_type = src->auth_type;
+ dst->encr_type = src->encr_type;
+ dst->key_idx = src->key_idx;
+ os_memcpy(dst->key, src->key, sizeof(dst->key));
+ dst->key_len = src->key_len;
+}
+
+
static int wps_process_ap_settings_r(struct wps_data *wps,
struct wps_parse_attr *attr)
{
- if (wps->wps->ap)
+ if (wps->wps->ap || wps->er)
return 0;
/* AP Settings Attributes in M7 when Enrollee is an AP */
@@ -2085,21 +2273,24 @@ static int wps_process_ap_settings_r(struct wps_data *wps,
wpa_printf(MSG_INFO, "WPS: Received old AP configuration from AP");
-#if 0
- /*
- * TODO: Provide access to AP settings and allow changes before sending
- * out M8. For now, just copy the settings unchanged into M8.
- */
-
- return 0;
-#else
- /*
- * For now, use the AP PIN only to receive the current AP settings,
- * not to reconfigure the AP.
- */
- wps_sta_cred_cb(wps);
- return 1;
-#endif
+ if (wps->new_ap_settings) {
+ wpa_printf(MSG_INFO, "WPS: Update AP configuration based on "
+ "new settings");
+ wps_cred_update(&wps->cred, wps->new_ap_settings);
+ return 0;
+ } else {
+ /*
+ * Use the AP PIN only to receive the current AP settings, not
+ * to reconfigure the AP.
+ */
+ if (wps->ap_settings_cb) {
+ wps->ap_settings_cb(wps->ap_settings_cb_ctx,
+ &wps->cred);
+ return 1;
+ }
+ wps_sta_cred_cb(wps);
+ return 1;
+ }
}
@@ -2136,7 +2327,7 @@ static enum wps_process_res wps_process_m7(struct wps_data *wps,
decrypted = wps_decrypt_encr_settings(wps, attr->encr_settings,
attr->encr_settings_len);
if (decrypted == NULL) {
- wpa_printf(MSG_DEBUG, "WPS: Failed to decrypted Encrypted "
+ wpa_printf(MSG_DEBUG, "WPS: Failed to decrypt Encrypted "
"Settings attribute");
wps->state = SEND_WSC_NACK;
return WPS_CONTINUE;
@@ -2430,6 +2621,8 @@ static enum wps_process_res wps_process_wsc_done(struct wps_data *wps,
if (wps->wps->wps_upnp && wps->ext_reg) {
wpa_printf(MSG_DEBUG, "WPS: Negotiation using external "
"Registrar completed successfully");
+ wps_device_store(wps->wps->registrar, &wps->peer_dev,
+ wps->uuid_e);
return WPS_DONE;
}
#endif /* CONFIG_WPS_UPNP */
@@ -2448,6 +2641,8 @@ static enum wps_process_res wps_process_wsc_done(struct wps_data *wps,
}
wpa_printf(MSG_DEBUG, "WPS: Negotiation completed successfully");
+ wps_device_store(wps->wps->registrar, &wps->peer_dev,
+ wps->uuid_e);
if (wps->wps->wps_state == WPS_STATE_NOT_CONFIGURED && wps->new_psk &&
wps->wps->ap && !wps->wps->registrar->disable_auto_conf) {
@@ -2475,7 +2670,7 @@ static enum wps_process_res wps_process_wsc_done(struct wps_data *wps,
wps->new_psk = NULL;
}
- if (!wps->wps->ap)
+ if (!wps->wps->ap && !wps->er)
wps_sta_cred_cb(wps);
if (wps->new_psk) {
@@ -2580,61 +2775,126 @@ static void wps_registrar_set_selected_timeout(void *eloop_ctx,
{
struct wps_registrar *reg = eloop_ctx;
- wpa_printf(MSG_DEBUG, "WPS: SetSelectedRegistrar timed out - "
- "unselect Registrar");
+ wpa_printf(MSG_DEBUG, "WPS: Selected Registrar timeout - "
+ "unselect internal Registrar");
reg->selected_registrar = 0;
reg->pbc = 0;
- reg->sel_reg_dev_password_id_override = -1;
- reg->sel_reg_config_methods_override = -1;
- wps_set_ie(reg);
+ wps_registrar_selected_registrar_changed(reg);
+}
+
+
+#ifdef CONFIG_WPS_UPNP
+static void wps_registrar_sel_reg_add(struct wps_registrar *reg,
+ struct subscription *s)
+{
+ wpa_printf(MSG_DEBUG, "WPS: External Registrar selected (dev_pw_id=%d "
+ "config_methods=0x%x)",
+ s->dev_password_id, s->config_methods);
+ reg->sel_reg_union = 1;
+ if (reg->sel_reg_dev_password_id_override != DEV_PW_PUSHBUTTON)
+ reg->sel_reg_dev_password_id_override = s->dev_password_id;
+ if (reg->sel_reg_config_methods_override == -1)
+ reg->sel_reg_config_methods_override = 0;
+ reg->sel_reg_config_methods_override |= s->config_methods;
+}
+#endif /* CONFIG_WPS_UPNP */
+
+
+static void wps_registrar_sel_reg_union(struct wps_registrar *reg)
+{
+#ifdef CONFIG_WPS_UPNP
+ struct subscription *s;
+
+ if (reg->wps->wps_upnp == NULL)
+ return;
+
+ dl_list_for_each(s, &reg->wps->wps_upnp->subscriptions,
+ struct subscription, list) {
+ struct subscr_addr *sa;
+ sa = dl_list_first(&s->addr_list, struct subscr_addr, list);
+ if (sa) {
+ wpa_printf(MSG_DEBUG, "WPS: External Registrar %s:%d",
+ inet_ntoa(sa->saddr.sin_addr),
+ ntohs(sa->saddr.sin_port));
+ }
+ if (s->selected_registrar)
+ wps_registrar_sel_reg_add(reg, s);
+ else
+ wpa_printf(MSG_DEBUG, "WPS: External Registrar not "
+ "selected");
+ }
+#endif /* CONFIG_WPS_UPNP */
}
/**
- * wps_registrar_set_selected_registrar - Notification of SetSelectedRegistrar
+ * wps_registrar_selected_registrar_changed - SetSelectedRegistrar change
* @reg: Registrar data from wps_registrar_init()
- * @msg: Received message from SetSelectedRegistrar
- * Returns: 0 on success, -1 on failure
*
- * This function is called when an AP receives a SetSelectedRegistrar UPnP
- * message.
+ * This function is called when selected registrar state changes, e.g., when an
+ * AP receives a SetSelectedRegistrar UPnP message.
*/
-int wps_registrar_set_selected_registrar(struct wps_registrar *reg,
- const struct wpabuf *msg)
+void wps_registrar_selected_registrar_changed(struct wps_registrar *reg)
{
- struct wps_parse_attr attr;
-
- wpa_hexdump_buf(MSG_MSGDUMP, "WPS: SetSelectedRegistrar attributes",
- msg);
+ wpa_printf(MSG_DEBUG, "WPS: Selected registrar information changed");
- if (wps_parse_msg(msg, &attr) < 0)
- return -1;
- if (!wps_version_supported(attr.version)) {
- wpa_printf(MSG_DEBUG, "WPS: Unsupported SetSelectedRegistrar "
- "version 0x%x", attr.version ? *attr.version : 0);
- return -1;
- }
+ reg->sel_reg_union = reg->selected_registrar;
+ reg->sel_reg_dev_password_id_override = -1;
+ reg->sel_reg_config_methods_override = -1;
+ if (reg->selected_registrar) {
+ reg->sel_reg_config_methods_override =
+ reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
+ if (reg->pbc) {
+ reg->sel_reg_dev_password_id_override =
+ DEV_PW_PUSHBUTTON;
+ reg->sel_reg_config_methods_override |=
+ WPS_CONFIG_PUSHBUTTON;
+ }
+ wpa_printf(MSG_DEBUG, "WPS: Internal Registrar selected "
+ "(pbc=%d)", reg->pbc);
+ } else
+ wpa_printf(MSG_DEBUG, "WPS: Internal Registrar not selected");
- if (attr.selected_registrar == NULL ||
- *attr.selected_registrar == 0) {
- wpa_printf(MSG_DEBUG, "WPS: SetSelectedRegistrar: Disable "
- "Selected Registrar");
- eloop_cancel_timeout(wps_registrar_set_selected_timeout, reg,
- NULL);
- wps_registrar_set_selected_timeout(reg, NULL);
- return 0;
- }
+ wps_registrar_sel_reg_union(reg);
- reg->selected_registrar = 1;
- reg->sel_reg_dev_password_id_override = attr.dev_password_id ?
- WPA_GET_BE16(attr.dev_password_id) : DEV_PW_DEFAULT;
- reg->sel_reg_config_methods_override = attr.sel_reg_config_methods ?
- WPA_GET_BE16(attr.sel_reg_config_methods) : -1;
wps_set_ie(reg);
+ wps_cb_set_sel_reg(reg);
+}
- eloop_cancel_timeout(wps_registrar_set_selected_timeout, reg, NULL);
- eloop_register_timeout(WPS_PBC_WALK_TIME, 0,
- wps_registrar_set_selected_timeout,
- reg, NULL);
- return 0;
+
+int wps_registrar_get_info(struct wps_registrar *reg, const u8 *addr,
+ char *buf, size_t buflen)
+{
+ struct wps_registrar_device *d;
+ int len = 0, ret;
+ char uuid[40];
+ char devtype[WPS_DEV_TYPE_BUFSIZE];
+
+ d = wps_device_get(reg, addr);
+ if (d == NULL)
+ return 0;
+ if (uuid_bin2str(d->uuid, uuid, sizeof(uuid)))
+ return 0;
+
+ ret = os_snprintf(buf + len, buflen - len,
+ "wpsUuid=%s\n"
+ "wpsPrimaryDeviceType=%s\n"
+ "wpsDeviceName=%s\n"
+ "wpsManufacturer=%s\n"
+ "wpsModelName=%s\n"
+ "wpsModelNumber=%s\n"
+ "wpsSerialNumber=%s\n",
+ uuid,
+ wps_dev_type_bin2str(d->dev.pri_dev_type, devtype,
+ sizeof(devtype)),
+ d->dev.device_name ? d->dev.device_name : "",
+ d->dev.manufacturer ? d->dev.manufacturer : "",
+ d->dev.model_name ? d->dev.model_name : "",
+ d->dev.model_number ? d->dev.model_number : "",
+ d->dev.serial_number ? d->dev.serial_number : "");
+ if (ret < 0 || (size_t) ret >= buflen - len)
+ return len;
+ len += ret;
+
+ return len;
}
diff --git a/contrib/wpa/src/wps/wps_ufd.c b/contrib/wpa/src/wps/wps_ufd.c
new file mode 100644
index 0000000..1a911e1
--- /dev/null
+++ b/contrib/wpa/src/wps/wps_ufd.c
@@ -0,0 +1,235 @@
+/*
+ * UFD routines for Wi-Fi Protected Setup
+ * Copyright (c) 2009, Masashi Honma <honma@ictec.co.jp>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+#include "common.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <fcntl.h>
+#include <dirent.h>
+
+#include "wps/wps.h"
+#include "wps/wps_i.h"
+
+#ifdef CONFIG_NATIVE_WINDOWS
+#define UFD_DIR1 "%s\\SMRTNTKY"
+#define UFD_DIR2 UFD_DIR1 "\\WFAWSC"
+#define UFD_FILE UFD_DIR2 "\\%s"
+#else /* CONFIG_NATIVE_WINDOWS */
+#define UFD_DIR1 "%s/SMRTNTKY"
+#define UFD_DIR2 UFD_DIR1 "/WFAWSC"
+#define UFD_FILE UFD_DIR2 "/%s"
+#endif /* CONFIG_NATIVE_WINDOWS */
+
+
+struct wps_ufd_data {
+ int ufd_fd;
+};
+
+
+static int dev_pwd_e_file_filter(const struct dirent *entry)
+{
+ unsigned int prefix;
+ char ext[5];
+
+ if (sscanf(entry->d_name, "%8x.%4s", &prefix, ext) != 2)
+ return 0;
+ if (prefix == 0)
+ return 0;
+ if (os_strcasecmp(ext, "WFA") != 0)
+ return 0;
+
+ return 1;
+}
+
+
+static int wps_get_dev_pwd_e_file_name(char *path, char *file_name)
+{
+ struct dirent **namelist;
+ int i, file_num;
+
+ file_num = scandir(path, &namelist, &dev_pwd_e_file_filter,
+ alphasort);
+ if (file_num < 0) {
+ wpa_printf(MSG_ERROR, "WPS: OOB file not found: %d (%s)",
+ errno, strerror(errno));
+ return -1;
+ }
+ if (file_num == 0) {
+ wpa_printf(MSG_ERROR, "WPS: OOB file not found");
+ os_free(namelist);
+ return -1;
+ }
+ os_strlcpy(file_name, namelist[0]->d_name, 13);
+ for (i = 0; i < file_num; i++)
+ os_free(namelist[i]);
+ os_free(namelist);
+ return 0;
+}
+
+
+static int get_file_name(struct wps_context *wps, int registrar,
+ const char *path, char *file_name)
+{
+ switch (wps->oob_conf.oob_method) {
+ case OOB_METHOD_CRED:
+ os_snprintf(file_name, 13, "00000000.WSC");
+ break;
+ case OOB_METHOD_DEV_PWD_E:
+ if (registrar) {
+ char temp[128];
+ os_snprintf(temp, sizeof(temp), UFD_DIR2, path);
+ if (wps_get_dev_pwd_e_file_name(temp, file_name) < 0)
+ return -1;
+ } else {
+ u8 *mac_addr = wps->dev.mac_addr;
+
+ os_snprintf(file_name, 13, "%02X%02X%02X%02X.WFA",
+ mac_addr[2], mac_addr[3], mac_addr[4],
+ mac_addr[5]);
+ }
+ break;
+ case OOB_METHOD_DEV_PWD_R:
+ os_snprintf(file_name, 13, "00000000.WFA");
+ break;
+ default:
+ wpa_printf(MSG_ERROR, "WPS: Invalid USBA OOB method");
+ return -1;
+ }
+ return 0;
+}
+
+
+static int ufd_mkdir(const char *path)
+{
+ if (mkdir(path, S_IRWXU) < 0 && errno != EEXIST) {
+ wpa_printf(MSG_ERROR, "WPS (UFD): Failed to create directory "
+ "'%s': %d (%s)", path, errno, strerror(errno));
+ return -1;
+ }
+ return 0;
+}
+
+
+static void * init_ufd(struct wps_context *wps,
+ struct oob_device_data *oob_dev, int registrar)
+{
+ int write_f;
+ char temp[128];
+ char *path = oob_dev->device_path;
+ char filename[13];
+ struct wps_ufd_data *data;
+ int ufd_fd;
+
+ if (path == NULL)
+ return NULL;
+
+ write_f = wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_E ?
+ !registrar : registrar;
+
+ if (get_file_name(wps, registrar, path, filename) < 0) {
+ wpa_printf(MSG_ERROR, "WPS (UFD): Failed to get file name");
+ return NULL;
+ }
+
+ if (write_f) {
+ os_snprintf(temp, sizeof(temp), UFD_DIR1, path);
+ if (ufd_mkdir(temp))
+ return NULL;
+ os_snprintf(temp, sizeof(temp), UFD_DIR2, path);
+ if (ufd_mkdir(temp))
+ return NULL;
+ }
+
+ os_snprintf(temp, sizeof(temp), UFD_FILE, path, filename);
+ if (write_f)
+ ufd_fd = open(temp, O_WRONLY | O_CREAT | O_TRUNC,
+ S_IRUSR | S_IWUSR);
+ else
+ ufd_fd = open(temp, O_RDONLY);
+ if (ufd_fd < 0) {
+ wpa_printf(MSG_ERROR, "WPS (UFD): Failed to open %s: %s",
+ temp, strerror(errno));
+ return NULL;
+ }
+
+ data = os_zalloc(sizeof(*data));
+ if (data == NULL)
+ return NULL;
+ data->ufd_fd = ufd_fd;
+ return data;
+}
+
+
+static struct wpabuf * read_ufd(void *priv)
+{
+ struct wps_ufd_data *data = priv;
+ struct wpabuf *buf;
+ struct stat s;
+ size_t file_size;
+
+ if (fstat(data->ufd_fd, &s) < 0) {
+ wpa_printf(MSG_ERROR, "WPS (UFD): Failed to get file size");
+ return NULL;
+ }
+
+ file_size = s.st_size;
+ buf = wpabuf_alloc(file_size);
+ if (buf == NULL) {
+ wpa_printf(MSG_ERROR, "WPS (UFD): Failed to alloc read "
+ "buffer");
+ return NULL;
+ }
+
+ if (read(data->ufd_fd, wpabuf_mhead(buf), file_size) !=
+ (int) file_size) {
+ wpabuf_free(buf);
+ wpa_printf(MSG_ERROR, "WPS (UFD): Failed to read");
+ return NULL;
+ }
+ wpabuf_put(buf, file_size);
+ return buf;
+}
+
+
+static int write_ufd(void *priv, struct wpabuf *buf)
+{
+ struct wps_ufd_data *data = priv;
+
+ if (write(data->ufd_fd, wpabuf_mhead(buf), wpabuf_len(buf)) !=
+ (int) wpabuf_len(buf)) {
+ wpa_printf(MSG_ERROR, "WPS (UFD): Failed to write");
+ return -1;
+ }
+ return 0;
+}
+
+
+static void deinit_ufd(void *priv)
+{
+ struct wps_ufd_data *data = priv;
+ close(data->ufd_fd);
+ os_free(data);
+}
+
+
+struct oob_device_data oob_ufd_device_data = {
+ .device_name = NULL,
+ .device_path = NULL,
+ .init_func = init_ufd,
+ .read_func = read_ufd,
+ .write_func = write_ufd,
+ .deinit_func = deinit_ufd,
+};
diff --git a/contrib/wpa/src/wps/wps_upnp.c b/contrib/wpa/src/wps/wps_upnp.c
index 4c6aac2..f99b859 100644
--- a/contrib/wpa/src/wps/wps_upnp.c
+++ b/contrib/wpa/src/wps/wps_upnp.c
@@ -280,53 +280,18 @@ static void subscr_addr_delete(struct subscr_addr *a)
}
-/* subscr_addr_unlink -- unlink subscriber address from linked list */
-static void subscr_addr_unlink(struct subscription *s, struct subscr_addr *a)
-{
- struct subscr_addr **listp = &s->addr_list;
- s->n_addr--;
- a->next->prev = a->prev;
- a->prev->next = a->next;
- if (*listp == a) {
- if (a == a->next) {
- /* last in queue */
- *listp = NULL;
- assert(s->n_addr == 0);
- } else {
- *listp = a->next;
- }
- }
-}
-
-
/* subscr_addr_free_all -- unlink and delete list of subscriber addresses. */
static void subscr_addr_free_all(struct subscription *s)
{
- struct subscr_addr **listp = &s->addr_list;
- struct subscr_addr *a;
- while ((a = *listp) != NULL) {
- subscr_addr_unlink(s, a);
+ struct subscr_addr *a, *tmp;
+ dl_list_for_each_safe(a, tmp, &s->addr_list, struct subscr_addr, list)
+ {
+ dl_list_del(&a->list);
subscr_addr_delete(a);
}
}
-/* subscr_addr_link -- add subscriber address to list of addresses */
-static void subscr_addr_link(struct subscription *s, struct subscr_addr *a)
-{
- struct subscr_addr **listp = &s->addr_list;
- s->n_addr++;
- if (*listp == NULL) {
- *listp = a->next = a->prev = a;
- } else {
- a->next = *listp;
- a->prev = (*listp)->prev;
- a->prev->next = a;
- a->next->prev = a;
- }
-}
-
-
/* subscr_addr_add_url -- add address(es) for one url to subscription */
static void subscr_addr_add_url(struct subscription *s, const char *url)
{
@@ -403,7 +368,7 @@ static void subscr_addr_add_url(struct subscription *s, const char *url)
}
for (rp = result; rp; rp = rp->ai_next) {
/* Limit no. of address to avoid denial of service attack */
- if (s->n_addr >= MAX_ADDR_PER_SUBSCRIPTION) {
+ if (dl_list_len(&s->addr_list) >= MAX_ADDR_PER_SUBSCRIPTION) {
wpa_printf(MSG_INFO, "WPS UPnP: subscr_addr_add_url: "
"Ignoring excessive addresses");
break;
@@ -412,7 +377,6 @@ static void subscr_addr_add_url(struct subscription *s, const char *url)
a = os_zalloc(sizeof(*a) + alloc_len);
if (a == NULL)
continue;
- a->s = s;
mem = (void *) (a + 1);
a->domain_and_port = mem;
strcpy(mem, domain_and_port);
@@ -425,7 +389,7 @@ static void subscr_addr_add_url(struct subscription *s, const char *url)
os_memcpy(&a->saddr, rp->ai_addr, sizeof(a->saddr));
a->saddr.sin_port = htons(port);
- subscr_addr_link(s, a);
+ dl_list_add(&s->addr_list, &a->list);
a = NULL; /* don't free it below */
}
@@ -502,14 +466,14 @@ static void upnp_wps_device_send_event(struct upnp_wps_device_sm *sm)
/* Enqueue event message for all subscribers */
struct wpabuf *buf; /* holds event message */
int buf_size = 0;
- struct subscription *s;
+ struct subscription *s, *tmp;
/* Actually, utf-8 is the default, but it doesn't hurt to specify it */
const char *format_head =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<e:propertyset xmlns:e=\"urn:schemas-upnp-org:event-1-0\">\n";
const char *format_tail = "</e:propertyset>\n";
- if (sm->subscriptions == NULL) {
+ if (dl_list_empty(&sm->subscriptions)) {
/* optimize */
return;
}
@@ -531,19 +495,15 @@ static void upnp_wps_device_send_event(struct upnp_wps_device_sm *sm)
wpa_printf(MSG_MSGDUMP, "WPS UPnP: WLANEvent message:\n%s",
(char *) wpabuf_head(buf));
- s = sm->subscriptions;
- do {
+ dl_list_for_each_safe(s, tmp, &sm->subscriptions, struct subscription,
+ list) {
if (event_add(s, buf)) {
- struct subscription *s_old = s;
wpa_printf(MSG_INFO, "WPS UPnP: Dropping "
"subscriber due to event backlog");
- s = s_old->next;
- subscription_unlink(s_old);
- subscription_destroy(s_old);
- } else {
- s = s->next;
+ dl_list_del(&s->list);
+ subscription_destroy(s);
}
- } while (s != sm->subscriptions);
+ }
wpabuf_free(buf);
}
@@ -555,52 +515,15 @@ static void upnp_wps_device_send_event(struct upnp_wps_device_sm *sm)
* This is the result of an incoming HTTP over TCP SUBSCRIBE request.
*/
-/* subscription_unlink -- remove from the active list */
-void subscription_unlink(struct subscription *s)
-{
- struct upnp_wps_device_sm *sm = s->sm;
-
- if (s->next == s) {
- /* only one? */
- sm->subscriptions = NULL;
- } else {
- if (sm->subscriptions == s)
- sm->subscriptions = s->next;
- s->next->prev = s->prev;
- s->prev->next = s->next;
- }
- sm->n_subscriptions--;
-}
-
-
-/* subscription_link_to_end -- link to end of active list
- * (should have high expiry time!)
- */
-static void subscription_link_to_end(struct subscription *s)
-{
- struct upnp_wps_device_sm *sm = s->sm;
-
- if (sm->subscriptions) {
- s->next = sm->subscriptions;
- s->prev = s->next->prev;
- s->prev->next = s;
- s->next->prev = s;
- } else {
- sm->subscriptions = s->next = s->prev = s;
- }
- sm->n_subscriptions++;
-}
-
-
/* subscription_destroy -- destroy an unlinked subscription
* Be sure to unlink first if necessary.
*/
void subscription_destroy(struct subscription *s)
{
wpa_printf(MSG_DEBUG, "WPS UPnP: Destroy subscription %p", s);
- if (s->addr_list)
- subscr_addr_free_all(s);
+ subscr_addr_free_all(s);
event_delete_all(s);
+ upnp_er_remove_notification(s);
os_free(s);
}
@@ -608,10 +531,13 @@ void subscription_destroy(struct subscription *s)
/* subscription_list_age -- remove expired subscriptions */
static void subscription_list_age(struct upnp_wps_device_sm *sm, time_t now)
{
- struct subscription *s;
- while ((s = sm->subscriptions) != NULL && s->timeout_time < now) {
+ struct subscription *s, *tmp;
+ dl_list_for_each_safe(s, tmp, &sm->subscriptions,
+ struct subscription, list) {
+ if (s->timeout_time > now)
+ break;
wpa_printf(MSG_DEBUG, "WPS UPnP: Removing aged subscription");
- subscription_unlink(s);
+ dl_list_del(&s->list);
subscription_destroy(s);
}
}
@@ -623,17 +549,11 @@ static void subscription_list_age(struct upnp_wps_device_sm *sm, time_t now)
struct subscription * subscription_find(struct upnp_wps_device_sm *sm,
const u8 uuid[UUID_LEN])
{
- struct subscription *s0 = sm->subscriptions;
- struct subscription *s = s0;
-
- if (s0 == NULL)
- return NULL;
- do {
+ struct subscription *s;
+ dl_list_for_each(s, &sm->subscriptions, struct subscription, list) {
if (os_memcmp(s->uuid, uuid, UUID_LEN) == 0)
return s; /* Found match */
- s = s->next;
- } while (s != s0);
-
+ }
return NULL;
}
@@ -645,8 +565,11 @@ static struct wpabuf * build_fake_wsc_ack(void)
return NULL;
wpabuf_put_u8(msg, UPNP_WPS_WLANEVENT_TYPE_EAP);
wpabuf_put_str(msg, "00:00:00:00:00:00");
- wps_build_version(msg);
- wps_build_msg_type(msg, WPS_WSC_ACK);
+ if (wps_build_version(msg) ||
+ wps_build_msg_type(msg, WPS_WSC_ACK)) {
+ wpabuf_free(msg);
+ return NULL;
+ }
/* Enrollee Nonce */
wpabuf_put_be16(msg, ATTR_ENROLLEE_NONCE);
wpabuf_put_be16(msg, WPS_NONCE_LEN);
@@ -750,31 +673,34 @@ struct subscription * subscription_start(struct upnp_wps_device_sm *sm,
subscription_list_age(sm, now);
/* If too many subscriptions, remove oldest */
- if (sm->n_subscriptions >= MAX_SUBSCRIPTIONS) {
- s = sm->subscriptions;
+ if (dl_list_len(&sm->subscriptions) >= MAX_SUBSCRIPTIONS) {
+ s = dl_list_first(&sm->subscriptions, struct subscription,
+ list);
wpa_printf(MSG_INFO, "WPS UPnP: Too many subscriptions, "
"trashing oldest");
- subscription_unlink(s);
+ dl_list_del(&s->list);
subscription_destroy(s);
}
s = os_zalloc(sizeof(*s));
if (s == NULL)
return NULL;
+ dl_list_init(&s->addr_list);
+ dl_list_init(&s->event_queue);
s->sm = sm;
s->timeout_time = expire;
uuid_make(s->uuid);
subscr_addr_list_create(s, callback_urls);
/* Add to end of list, since it has the highest expiration time */
- subscription_link_to_end(s);
+ dl_list_add_tail(&sm->subscriptions, &s->list);
/* Queue up immediate event message (our last event)
* as required by UPnP spec.
*/
if (subscription_first_event(s)) {
wpa_printf(MSG_INFO, "WPS UPnP: Dropping subscriber due to "
"event backlog");
- subscription_unlink(s);
+ dl_list_del(&s->list);
subscription_destroy(s);
return NULL;
}
@@ -796,10 +722,10 @@ struct subscription * subscription_renew(struct upnp_wps_device_sm *sm,
if (s == NULL)
return NULL;
wpa_printf(MSG_DEBUG, "WPS UPnP: Subscription renewed");
- subscription_unlink(s);
+ dl_list_del(&s->list);
s->timeout_time = expire;
/* add back to end of list, since it now has highest expiry */
- subscription_link_to_end(s);
+ dl_list_add_tail(&sm->subscriptions, &s->list);
return s;
}
@@ -871,7 +797,7 @@ fail:
}
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
#include <sys/sysctl.h>
#include <net/route.h>
#include <net/if_dl.h>
@@ -921,12 +847,10 @@ static int eth_get(const char *device, u8 ea[ETH_ALEN])
* @ip_addr: Buffer for returning IP address in network byte order
* @ip_addr_text: Buffer for returning a pointer to allocated IP address text
* @mac: Buffer for returning MAC address
- * @mac_addr_text: Buffer for returning allocated MAC address text
* Returns: 0 on success, -1 on failure
*/
-static int get_netif_info(const char *net_if, unsigned *ip_addr,
- char **ip_addr_text, u8 mac[ETH_ALEN],
- char **mac_addr_text)
+int get_netif_info(const char *net_if, unsigned *ip_addr, char **ip_addr_text,
+ u8 mac[ETH_ALEN])
{
struct ifreq req;
int sock = -1;
@@ -934,8 +858,7 @@ static int get_netif_info(const char *net_if, unsigned *ip_addr,
struct in_addr in_addr;
*ip_addr_text = os_zalloc(16);
- *mac_addr_text = os_zalloc(18);
- if (*ip_addr_text == NULL || *mac_addr_text == NULL)
+ if (*ip_addr_text == NULL)
goto fail;
sock = socket(AF_INET, SOCK_DGRAM, 0);
@@ -961,7 +884,7 @@ static int get_netif_info(const char *net_if, unsigned *ip_addr,
goto fail;
}
os_memcpy(mac, req.ifr_addr.sa_data, 6);
-#elif defined(__FreeBSD__)
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
if (eth_get(net_if, mac) < 0) {
wpa_printf(MSG_ERROR, "WPS UPnP: Failed to get MAC address");
goto fail;
@@ -969,7 +892,6 @@ static int get_netif_info(const char *net_if, unsigned *ip_addr,
#else
#error MAC address fetch not implemented
#endif
- os_snprintf(*mac_addr_text, 18, MACSTR, MAC2STR(req.ifr_addr.sa_data));
close(sock);
return 0;
@@ -979,12 +901,29 @@ fail:
close(sock);
os_free(*ip_addr_text);
*ip_addr_text = NULL;
- os_free(*mac_addr_text);
- *mac_addr_text = NULL;
return -1;
}
+static void upnp_wps_free_msearchreply(struct dl_list *head)
+{
+ struct advertisement_state_machine *a, *tmp;
+ dl_list_for_each_safe(a, tmp, head, struct advertisement_state_machine,
+ list)
+ msearchreply_state_machine_stop(a);
+}
+
+
+static void upnp_wps_free_subscriptions(struct dl_list *head)
+{
+ struct subscription *s, *tmp;
+ dl_list_for_each_safe(s, tmp, head, struct subscription, list) {
+ dl_list_del(&s->list);
+ subscription_destroy(s);
+ }
+}
+
+
/**
* upnp_wps_device_stop - Stop WPS UPnP operations on an interface
* @sm: WPS UPnP state machine from upnp_wps_device_init()
@@ -996,25 +935,14 @@ void upnp_wps_device_stop(struct upnp_wps_device_sm *sm)
wpa_printf(MSG_DEBUG, "WPS UPnP: Stop device");
web_listener_stop(sm);
- while (sm->web_connections)
- web_connection_stop(sm->web_connections);
- while (sm->msearch_replies)
- msearchreply_state_machine_stop(sm->msearch_replies);
- while (sm->subscriptions) {
- struct subscription *s = sm->subscriptions;
- subscription_unlink(s);
- subscription_destroy(s);
- }
+ upnp_wps_free_msearchreply(&sm->msearch_replies);
+ upnp_wps_free_subscriptions(&sm->subscriptions);
advertisement_state_machine_stop(sm, 1);
event_send_stop_all(sm);
os_free(sm->wlanevent);
sm->wlanevent = NULL;
- os_free(sm->net_if);
- sm->net_if = NULL;
- os_free(sm->mac_addr_text);
- sm->mac_addr_text = NULL;
os_free(sm->ip_addr_text);
sm->ip_addr_text = NULL;
if (sm->multicast_sd >= 0)
@@ -1040,7 +968,6 @@ int upnp_wps_device_start(struct upnp_wps_device_sm *sm, char *net_if)
if (sm->started)
upnp_wps_device_stop(sm);
- sm->net_if = strdup(net_if);
sm->multicast_sd = -1;
sm->ssdp_sd = -1;
sm->started = 1;
@@ -1051,9 +978,8 @@ int upnp_wps_device_start(struct upnp_wps_device_sm *sm, char *net_if)
goto fail;
/* Determine which IP and mac address we're using */
- if (get_netif_info(net_if,
- &sm->ip_addr, &sm->ip_addr_text,
- sm->mac_addr, &sm->mac_addr_text)) {
+ if (get_netif_info(net_if, &sm->ip_addr, &sm->ip_addr_text,
+ sm->mac_addr)) {
wpa_printf(MSG_INFO, "WPS UPnP: Could not get IP/MAC address "
"for %s. Does it have IP address?", net_if);
goto fail;
@@ -1104,6 +1030,7 @@ void upnp_wps_device_deinit(struct upnp_wps_device_sm *sm)
wps_deinit(sm->peer.wps);
os_free(sm->root_dir);
os_free(sm->desc_url);
+ os_free(sm->ctx->ap_pin);
os_free(sm->ctx);
os_free(sm);
}
@@ -1131,6 +1058,8 @@ upnp_wps_device_init(struct upnp_wps_device_ctx *ctx, struct wps_context *wps,
sm->ctx = ctx;
sm->wps = wps;
sm->priv = priv;
+ dl_list_init(&sm->msearch_replies);
+ dl_list_init(&sm->subscriptions);
return sm;
}
@@ -1143,5 +1072,22 @@ upnp_wps_device_init(struct upnp_wps_device_ctx *ctx, struct wps_context *wps,
*/
int upnp_wps_subscribers(struct upnp_wps_device_sm *sm)
{
- return sm->subscriptions != NULL;
+ return !dl_list_empty(&sm->subscriptions);
+}
+
+
+int upnp_wps_set_ap_pin(struct upnp_wps_device_sm *sm, const char *ap_pin)
+{
+ if (sm == NULL)
+ return 0;
+
+ os_free(sm->ctx->ap_pin);
+ if (ap_pin) {
+ sm->ctx->ap_pin = os_strdup(ap_pin);
+ if (sm->ctx->ap_pin == NULL)
+ return -1;
+ } else
+ sm->ctx->ap_pin = NULL;
+
+ return 0;
}
diff --git a/contrib/wpa/src/wps/wps_upnp.h b/contrib/wpa/src/wps/wps_upnp.h
index 31b0556..06bc31f 100644
--- a/contrib/wpa/src/wps/wps_upnp.h
+++ b/contrib/wpa/src/wps/wps_upnp.h
@@ -25,29 +25,12 @@ enum upnp_wps_wlanevent_type {
};
struct upnp_wps_device_ctx {
- struct wpabuf * (*rx_req_get_device_info)(
- void *priv, struct upnp_wps_peer *peer);
- struct wpabuf * (*rx_req_put_message)(
- void *priv, struct upnp_wps_peer *peer,
- const struct wpabuf *msg);
- struct wpabuf * (*rx_req_get_ap_settings)(void *priv,
- const struct wpabuf *msg);
- int (*rx_req_set_ap_settings)(void *priv, const struct wpabuf *msg);
- int (*rx_req_del_ap_settings)(void *priv, const struct wpabuf *msg);
- struct wpabuf * (*rx_req_get_sta_settings)(void *priv,
- const struct wpabuf *msg);
- int (*rx_req_set_sta_settings)(void *priv, const struct wpabuf *msg);
- int (*rx_req_del_sta_settings)(void *priv, const struct wpabuf *msg);
int (*rx_req_put_wlan_response)(
void *priv, enum upnp_wps_wlanevent_type ev_type,
const u8 *mac_addr, const struct wpabuf *msg,
enum wps_msg_type msg_type);
- int (*rx_req_set_selected_registrar)(void *priv,
- const struct wpabuf *msg);
- int (*rx_req_reboot_ap)(void *priv, const struct wpabuf *msg);
- int (*rx_req_reset_ap)(void *priv, const struct wpabuf *msg);
- int (*rx_req_reboot_sta)(void *priv, const struct wpabuf *msg);
- int (*rx_req_reset_sta)(void *priv, const struct wpabuf *msg);
+
+ char *ap_pin;
};
struct upnp_wps_device_sm *
@@ -63,5 +46,6 @@ int upnp_wps_device_send_wlan_event(struct upnp_wps_device_sm *sm,
enum upnp_wps_wlanevent_type ev_type,
const struct wpabuf *msg);
int upnp_wps_subscribers(struct upnp_wps_device_sm *sm);
+int upnp_wps_set_ap_pin(struct upnp_wps_device_sm *sm, const char *ap_pin);
#endif /* WPS_UPNP_H */
diff --git a/contrib/wpa/src/wps/wps_upnp_ap.c b/contrib/wpa/src/wps/wps_upnp_ap.c
new file mode 100644
index 0000000..93746da
--- /dev/null
+++ b/contrib/wpa/src/wps/wps_upnp_ap.c
@@ -0,0 +1,80 @@
+/*
+ * Wi-Fi Protected Setup - UPnP AP functionality
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "eloop.h"
+#include "uuid.h"
+#include "wps_i.h"
+#include "wps_upnp.h"
+#include "wps_upnp_i.h"
+
+
+static void upnp_er_set_selected_timeout(void *eloop_ctx, void *timeout_ctx)
+{
+ struct subscription *s = eloop_ctx;
+ wpa_printf(MSG_DEBUG, "WPS: SetSelectedRegistrar from ER timed out");
+ s->selected_registrar = 0;
+ wps_registrar_selected_registrar_changed(s->reg);
+}
+
+
+int upnp_er_set_selected_registrar(struct wps_registrar *reg,
+ struct subscription *s,
+ const struct wpabuf *msg)
+{
+ struct wps_parse_attr attr;
+
+ wpa_hexdump_buf(MSG_MSGDUMP, "WPS: SetSelectedRegistrar attributes",
+ msg);
+
+ if (wps_parse_msg(msg, &attr) < 0)
+ return -1;
+ if (!wps_version_supported(attr.version)) {
+ wpa_printf(MSG_DEBUG, "WPS: Unsupported SetSelectedRegistrar "
+ "version 0x%x", attr.version ? *attr.version : 0);
+ return -1;
+ }
+
+ s->reg = reg;
+ eloop_cancel_timeout(upnp_er_set_selected_timeout, s, NULL);
+
+ if (attr.selected_registrar == NULL || *attr.selected_registrar == 0) {
+ wpa_printf(MSG_DEBUG, "WPS: SetSelectedRegistrar: Disable "
+ "Selected Registrar");
+ s->selected_registrar = 0;
+ } else {
+ s->selected_registrar = 1;
+ s->dev_password_id = attr.dev_password_id ?
+ WPA_GET_BE16(attr.dev_password_id) : DEV_PW_DEFAULT;
+ s->config_methods = attr.sel_reg_config_methods ?
+ WPA_GET_BE16(attr.sel_reg_config_methods) : -1;
+ eloop_register_timeout(WPS_PBC_WALK_TIME, 0,
+ upnp_er_set_selected_timeout, s, NULL);
+ }
+
+ wps_registrar_selected_registrar_changed(reg);
+
+ return 0;
+}
+
+
+void upnp_er_remove_notification(struct subscription *s)
+{
+ s->selected_registrar = 0;
+ eloop_cancel_timeout(upnp_er_set_selected_timeout, s, NULL);
+ if (s->reg)
+ wps_registrar_selected_registrar_changed(s->reg);
+}
diff --git a/contrib/wpa/src/wps/wps_upnp_event.c b/contrib/wpa/src/wps/wps_upnp_event.c
index 4122a87..ae5efdb 100644
--- a/contrib/wpa/src/wps/wps_upnp_event.c
+++ b/contrib/wpa/src/wps/wps_upnp_event.c
@@ -10,12 +10,11 @@
#include "includes.h"
#include <assert.h>
-#include <fcntl.h>
#include "common.h"
#include "eloop.h"
#include "uuid.h"
-#include "httpread.h"
+#include "http_client.h"
#include "wps_defs.h"
#include "wps_upnp.h"
#include "wps_upnp_i.h"
@@ -47,42 +46,25 @@
* TODO: As an optimization we could share data between subscribers.
*/
struct wps_event_ {
- struct wps_event_ *next;
- struct wps_event_ *prev; /* double linked list */
+ struct dl_list list;
struct subscription *s; /* parent */
unsigned subscriber_sequence; /* which event for this subscription*/
- int retry; /* which retry */
+ unsigned int retry; /* which retry */
struct subscr_addr *addr; /* address to connect to */
struct wpabuf *data; /* event data to send */
- /* The following apply while we are sending an event message. */
- int sd; /* -1 or socket descriptor for open connection */
- int sd_registered; /* nonzero if we must cancel registration */
- struct httpread *hread; /* NULL or open connection for event msg */
+ struct http_client *http_event;
};
-static void event_timeout_handler(void *eloop_data, void *user_ctx);
-
/* event_clean -- clean sockets etc. of event
* Leaves data, retry count etc. alone.
*/
static void event_clean(struct wps_event_ *e)
{
- if (e->s->current_event == e) {
- eloop_cancel_timeout(event_timeout_handler, NULL, e);
+ if (e->s->current_event == e)
e->s->current_event = NULL;
- }
- if (e->sd_registered) {
- eloop_unregister_sock(e->sd, EVENT_TYPE_WRITE);
- e->sd_registered = 0;
- }
- if (e->sd != -1) {
- close(e->sd);
- e->sd = -1;
- }
- if (e->hread)
- httpread_destroy(e->hread);
- e->hread = NULL;
+ http_client_free(e->http_event);
+ e->http_event = NULL;
}
@@ -102,63 +84,14 @@ static void event_delete(struct wps_event_ *e)
*/
static struct wps_event_ *event_dequeue(struct subscription *s)
{
- struct wps_event_ **event_head = &s->event_queue;
- struct wps_event_ *e = *event_head;
- if (e == NULL)
- return NULL;
- e->next->prev = e->prev;
- e->prev->next = e->next;
- if (*event_head == e) {
- if (e == e->next) {
- /* last in queue */
- *event_head = NULL;
- } else {
- *event_head = e->next;
- }
- }
- s->n_queue--;
- e->next = e->prev = NULL;
- /* but parent "s" is still valid */
+ struct wps_event_ *e;
+ e = dl_list_first(&s->event_queue, struct wps_event_, list);
+ if (e)
+ dl_list_del(&e->list);
return e;
}
-/* event_enqueue_at_end -- add event to end of queue */
-static void event_enqueue_at_end(struct subscription *s, struct wps_event_ *e)
-{
- struct wps_event_ **event_head = &s->event_queue;
- if (*event_head == NULL) {
- *event_head = e->next = e->prev = e;
- } else {
- e->next = *event_head;
- e->prev = e->next->prev;
- e->prev->next = e;
- e->next->prev = e;
- }
- s->n_queue++;
-}
-
-
-/* event_enqueue_at_begin -- add event to begin of queue
- * (appropriate for retrying event only)
- */
-static void event_enqueue_at_begin(struct subscription *s,
- struct wps_event_ *e)
-{
- struct wps_event_ **event_head = &s->event_queue;
- if (*event_head == NULL) {
- *event_head = e->next = e->prev = e;
- } else {
- e->prev = *event_head;
- e->next = e->prev->next;
- e->prev->next = e;
- e->next->prev = e;
- *event_head = e;
- }
- s->n_queue++;
-}
-
-
/* event_delete_all -- delete entire event queue and current event */
void event_delete_all(struct subscription *s)
{
@@ -187,114 +120,24 @@ static void event_retry(struct wps_event_ *e, int do_next_address)
if (do_next_address)
e->retry++;
- if (e->retry >= s->n_addr) {
+ if (e->retry >= dl_list_len(&s->addr_list)) {
wpa_printf(MSG_DEBUG, "WPS UPnP: Giving up on sending event "
"for %s", e->addr->domain_and_port);
return;
}
- event_enqueue_at_begin(s, e);
+ dl_list_add(&s->event_queue, &e->list);
event_send_all_later(sm);
}
-/* called if the overall event-sending process takes too long */
-static void event_timeout_handler(void *eloop_data, void *user_ctx)
+static struct wpabuf * event_build_message(struct wps_event_ *e)
{
- struct wps_event_ *e = user_ctx;
- struct subscription *s = e->s;
-
- assert(e == s->current_event);
-
- wpa_printf(MSG_DEBUG, "WPS UPnP: Event send timeout");
- event_retry(e, 1);
-}
-
-
-/* event_got_response_handler -- called back when http response is received. */
-static void event_got_response_handler(struct httpread *handle, void *cookie,
- enum httpread_event en)
-{
- struct wps_event_ *e = cookie;
- struct subscription *s = e->s;
- struct upnp_wps_device_sm *sm = s->sm;
- struct httpread *hread = e->hread;
- int reply_code = 0;
-
- assert(e == s->current_event);
- eloop_cancel_timeout(event_timeout_handler, NULL, e);
-
- if (en == HTTPREAD_EVENT_FILE_READY) {
- if (httpread_hdr_type_get(hread) == HTTPREAD_HDR_TYPE_REPLY) {
- reply_code = httpread_reply_code_get(hread);
- if (reply_code == HTTP_OK) {
- wpa_printf(MSG_DEBUG,
- "WPS UPnP: Got event reply OK from "
- "%s", e->addr->domain_and_port);
- event_delete(e);
- goto send_more;
- } else {
- wpa_printf(MSG_DEBUG, "WPS UPnP: Got event "
- "error reply code %d from %s",
- reply_code,
- e->addr->domain_and_port);
- goto bad;
- }
- } else {
- wpa_printf(MSG_DEBUG, "WPS UPnP: Got bogus event "
- "response %d from %s", en,
- e->addr->domain_and_port);
- }
- } else {
- wpa_printf(MSG_DEBUG, "WPS UPnP: Event response timeout/fail "
- "for %s", e->addr->domain_and_port);
- goto bad;
- }
- event_retry(e, 1);
- goto send_more;
-
-send_more:
- /* Schedule sending more if there is more to send */
- if (s->event_queue)
- event_send_all_later(sm);
- return;
-
-bad:
- /*
- * If other side doesn't like what we say, forget about them.
- * (There is no way to tell other side that we are dropping
- * them...).
- * Alternately, we could just do event_delete(e)
- */
- wpa_printf(MSG_DEBUG, "WPS UPnP: Deleting subscription due to errors");
- subscription_unlink(s);
- subscription_destroy(s);
-}
-
-
-/* event_send_tx_ready -- actually write event message
- *
- * Prequisite: subscription socket descriptor has become ready to
- * write (because connection to subscriber has been made).
- *
- * It is also possible that we are called because the connect has failed;
- * it is possible to test for this, or we can just go ahead and then
- * the write will fail.
- */
-static void event_send_tx_ready(int sock, void *eloop_ctx, void *sock_ctx)
-{
- struct wps_event_ *e = sock_ctx;
- struct subscription *s = e->s;
struct wpabuf *buf;
char *b;
- assert(e == s->current_event);
- assert(e->sd == sock);
-
buf = wpabuf_alloc(1000 + wpabuf_len(e->data));
- if (buf == NULL) {
- event_retry(e, 0);
- goto bad;
- }
+ if (buf == NULL)
+ return NULL;
wpabuf_printf(buf, "NOTIFY %s HTTP/1.1\r\n", e->addr->path);
wpabuf_put_str(buf, "SERVER: Unspecified, UPnP/1.0, Unspecified\r\n");
wpabuf_printf(buf, "HOST: %s\r\n", e->addr->domain_and_port);
@@ -303,7 +146,7 @@ static void event_send_tx_ready(int sock, void *eloop_ctx, void *sock_ctx)
"NTS: upnp:propchange\r\n");
wpabuf_put_str(buf, "SID: uuid:");
b = wpabuf_put(buf, 0);
- uuid_bin2str(s->uuid, b, 80);
+ uuid_bin2str(e->s->uuid, b, 80);
wpabuf_put(buf, os_strlen(b));
wpabuf_put_str(buf, "\r\n");
wpabuf_printf(buf, "SEQ: %u\r\n", e->subscriber_sequence);
@@ -311,45 +154,47 @@ static void event_send_tx_ready(int sock, void *eloop_ctx, void *sock_ctx)
(int) wpabuf_len(e->data));
wpabuf_put_str(buf, "\r\n"); /* terminating empty line */
wpabuf_put_buf(buf, e->data);
+ return buf;
+}
- /* Since the message size is pretty small, we should be
- * able to get the operating system to buffer what we give it
- * and not have to come back again later to write more...
- */
-#if 0
- /* we could: Turn blocking back on? */
- fcntl(e->sd, F_SETFL, 0);
-#endif
- wpa_printf(MSG_DEBUG, "WPS UPnP: Sending event to %s",
- e->addr->domain_and_port);
- if (send_wpabuf(e->sd, buf) < 0) {
- event_retry(e, 1);
- goto bad;
- }
- wpabuf_free(buf);
- buf = NULL;
- if (e->sd_registered) {
- e->sd_registered = 0;
- eloop_unregister_sock(e->sd, EVENT_TYPE_WRITE);
- }
- /* Set up to read the reply */
- e->hread = httpread_create(e->sd, event_got_response_handler,
- e /* cookie */,
- 0 /* no data expected */,
- EVENT_TIMEOUT_SEC);
- if (e->hread == NULL) {
- wpa_printf(MSG_ERROR, "WPS UPnP: httpread_create failed");
- event_retry(e, 0);
- goto bad;
- }
- return;
+static void event_http_cb(void *ctx, struct http_client *c,
+ enum http_client_event event)
+{
+ struct wps_event_ *e = ctx;
+ struct subscription *s = e->s;
-bad:
- /* Schedule sending more if there is more to send */
- if (s->event_queue)
- event_send_all_later(s->sm);
- wpabuf_free(buf);
+ switch (event) {
+ case HTTP_CLIENT_OK:
+ wpa_printf(MSG_DEBUG,
+ "WPS UPnP: Got event reply OK from "
+ "%s", e->addr->domain_and_port);
+ event_delete(e);
+
+ /* Schedule sending more if there is more to send */
+ if (!dl_list_empty(&s->event_queue))
+ event_send_all_later(s->sm);
+ break;
+ case HTTP_CLIENT_FAILED:
+ case HTTP_CLIENT_INVALID_REPLY:
+ wpa_printf(MSG_DEBUG, "WPS UPnP: Failed to send event to %s",
+ e->addr->domain_and_port);
+
+ /*
+ * If other side doesn't like what we say, forget about them.
+ * (There is no way to tell other side that we are dropping
+ * them...).
+ * Alternately, we could just do event_delete(e)
+ */
+ wpa_printf(MSG_DEBUG, "WPS UPnP: Deleting subscription due to "
+ "errors");
+ dl_list_del(&s->list);
+ subscription_destroy(s);
+ break;
+ case HTTP_CLIENT_TIMEOUT:
+ wpa_printf(MSG_DEBUG, "WPS UPnP: Event send timeout");
+ event_retry(e, 1);
+ }
}
@@ -376,57 +221,41 @@ bad:
static int event_send_start(struct subscription *s)
{
struct wps_event_ *e;
- int itry;
+ unsigned int itry;
+ struct wpabuf *buf;
/*
* Assume we are called ONLY with no current event and ONLY with
* nonempty event queue and ONLY with at least one address to send to.
*/
- assert(s->addr_list != NULL);
+ assert(!dl_list_empty(&s->addr_list));
assert(s->current_event == NULL);
- assert(s->event_queue != NULL);
+ assert(!dl_list_empty(&s->event_queue));
s->current_event = e = event_dequeue(s);
- /* Use address acc. to no. of retries */
- e->addr = s->addr_list;
- for (itry = 0; itry < e->retry; itry++)
- e->addr = e->addr->next;
-
- e->sd = socket(AF_INET, SOCK_STREAM, 0);
- if (e->sd < 0) {
- event_retry(e, 0);
+ /* Use address according to number of retries */
+ itry = 0;
+ dl_list_for_each(e->addr, &s->addr_list, struct subscr_addr, list)
+ if (itry++ == e->retry)
+ break;
+ if (itry < e->retry)
return -1;
- }
- /* set non-blocking so we don't sleep waiting for connection */
- if (fcntl(e->sd, F_SETFL, O_NONBLOCK) != 0) {
- event_retry(e, 0);
- return -1;
- }
- /*
- * Start the connect. It might succeed immediately but more likely will
- * return errno EINPROGRESS.
- */
- if (connect(e->sd, (struct sockaddr *) &e->addr->saddr,
- sizeof(e->addr->saddr))) {
- if (errno != EINPROGRESS) {
- event_retry(e, 1);
- return -1;
- }
- }
- /* Call back when ready for writing (or on failure...). */
- if (eloop_register_sock(e->sd, EVENT_TYPE_WRITE, event_send_tx_ready,
- NULL, e)) {
+
+ buf = event_build_message(e);
+ if (buf == NULL) {
event_retry(e, 0);
return -1;
}
- e->sd_registered = 1;
- /* Don't wait forever! */
- if (eloop_register_timeout(EVENT_TIMEOUT_SEC, 0, event_timeout_handler,
- NULL, e)) {
+
+ e->http_event = http_client_addr(&e->addr->saddr, buf, 0,
+ event_http_cb, e);
+ if (e->http_event == NULL) {
+ wpabuf_free(buf);
event_retry(e, 0);
return -1;
}
+
return 0;
}
@@ -435,32 +264,26 @@ static int event_send_start(struct subscription *s)
static void event_send_all_later_handler(void *eloop_data, void *user_ctx)
{
struct upnp_wps_device_sm *sm = user_ctx;
- struct subscription *s;
- struct subscription *s_old;
+ struct subscription *s, *tmp;
int nerrors = 0;
sm->event_send_all_queued = 0;
- s = sm->subscriptions;
- if (s == NULL)
- return;
- do {
- if (s->addr_list == NULL) {
+ dl_list_for_each_safe(s, tmp, &sm->subscriptions, struct subscription,
+ list) {
+ if (dl_list_empty(&s->addr_list)) {
/* if we've given up on all addresses */
wpa_printf(MSG_DEBUG, "WPS UPnP: Removing "
"subscription with no addresses");
- s_old = s;
- s = s_old->next;
- subscription_unlink(s_old);
- subscription_destroy(s_old);
+ dl_list_del(&s->list);
+ subscription_destroy(s);
} else {
if (s->current_event == NULL /* not busy */ &&
- s->event_queue != NULL /* more to do */) {
+ !dl_list_empty(&s->event_queue) /* more to do */) {
if (event_send_start(s))
nerrors++;
}
- s = s->next;
}
- } while (sm->subscriptions != NULL && s != sm->subscriptions);
+ }
if (nerrors) {
/* Try again later */
@@ -509,7 +332,7 @@ int event_add(struct subscription *s, const struct wpabuf *data)
{
struct wps_event_ *e;
- if (s->n_queue >= MAX_EVENTS_QUEUED) {
+ if (dl_list_len(&s->event_queue) >= MAX_EVENTS_QUEUED) {
wpa_printf(MSG_DEBUG, "WPS UPnP: Too many events queued for "
"subscriber");
return 1;
@@ -518,8 +341,8 @@ int event_add(struct subscription *s, const struct wpabuf *data)
e = os_zalloc(sizeof(*e));
if (e == NULL)
return 1;
+ dl_list_init(&e->list);
e->s = s;
- e->sd = -1;
e->data = wpabuf_dup(data);
if (e->data == NULL) {
os_free(e);
@@ -528,7 +351,7 @@ int event_add(struct subscription *s, const struct wpabuf *data)
e->subscriber_sequence = s->next_subscriber_sequence++;
if (s->next_subscriber_sequence == 0)
s->next_subscriber_sequence++;
- event_enqueue_at_end(s, e);
+ dl_list_add_tail(&s->event_queue, &e->list);
event_send_all_later(s->sm);
return 0;
}
diff --git a/contrib/wpa/src/wps/wps_upnp_i.h b/contrib/wpa/src/wps/wps_upnp_i.h
index ba4ec20..b31875a 100644
--- a/contrib/wpa/src/wps/wps_upnp_i.h
+++ b/contrib/wpa/src/wps/wps_upnp_i.h
@@ -11,6 +11,9 @@
#ifndef WPS_UPNP_I_H
#define WPS_UPNP_I_H
+#include "utils/list.h"
+#include "http.h"
+
#define UPNP_MULTICAST_ADDRESS "239.255.255.250" /* for UPnP multicasting */
#define UPNP_MULTICAST_PORT 1900 /* UDP port to monitor for UPnP */
@@ -25,25 +28,11 @@
#define UPNP_WPS_DEVICE_CONTROL_FILE "wps_control"
#define UPNP_WPS_DEVICE_EVENT_FILE "wps_event"
-
-struct web_connection;
-struct subscription;
-struct upnp_wps_device_sm;
+#define MULTICAST_MAX_READ 1600 /* max bytes we'll read for UPD request */
-enum http_reply_code {
- HTTP_OK = 200,
- HTTP_BAD_REQUEST = 400,
- UPNP_INVALID_ACTION = 401,
- UPNP_INVALID_ARGS = 402,
- HTTP_PRECONDITION_FAILED = 412,
- HTTP_INTERNAL_SERVER_ERROR = 500,
- HTTP_UNIMPLEMENTED = 501,
- UPNP_ACTION_FAILED = 501,
- UPNP_ARG_VALUE_INVALID = 600,
- UPNP_ARG_VALUE_OUT_OF_RANGE = 601,
- UPNP_OUT_OF_MEMORY = 603
-};
+struct upnp_wps_device_sm;
+struct wps_registrar;
enum advertisement_type_enum {
@@ -60,10 +49,7 @@ enum advertisement_type_enum {
* separate packets and spread out in time to avoid congestion.
*/
struct advertisement_state_machine {
- /* double-linked list */
- struct advertisement_state_machine *next;
- struct advertisement_state_machine *prev;
- struct upnp_wps_device_sm *sm; /* parent */
+ struct dl_list list;
enum advertisement_type_enum type;
int state;
int nerrors;
@@ -77,10 +63,7 @@ struct advertisement_state_machine {
* for a subscriber until we find one that seems to work.
*/
struct subscr_addr {
- /* double linked list */
- struct subscr_addr *next;
- struct subscr_addr *prev;
- struct subscription *s; /* parent */
+ struct dl_list list;
char *domain_and_port; /* domain and port part of url */
char *path; /* "filepath" part of url (from "mem") */
struct sockaddr_in saddr; /* address for doing connect */
@@ -93,9 +76,7 @@ struct subscr_addr {
* also have to age out subscribers unless they renew.
*/
struct subscription {
- /* double linked list */
- struct subscription *next;
- struct subscription *prev;
+ struct dl_list list;
struct upnp_wps_device_sm *sm; /* parent */
time_t timeout_time; /* when to age out the subscription */
unsigned next_subscriber_sequence; /* number our messages */
@@ -106,12 +87,16 @@ struct subscription {
*/
u8 uuid[UUID_LEN];
/* Linked list of address alternatives (rotate through on failure) */
- struct subscr_addr *addr_list;
- int n_addr; /* Number of addresses in list */
- struct wps_event_ *event_queue; /* Queued event messages. */
- int n_queue; /* How many events are queued */
+ struct dl_list addr_list;
+ struct dl_list event_queue; /* Queued event messages. */
struct wps_event_ *current_event; /* non-NULL if being sent (not in q)
*/
+
+ /* Information from SetSelectedRegistrar action */
+ u8 selected_registrar;
+ u16 dev_password_id;
+ u16 config_methods;
+ struct wps_registrar *reg;
};
@@ -128,8 +113,6 @@ struct upnp_wps_device_sm {
char *root_dir;
char *desc_url;
int started; /* nonzero if we are active */
- char *net_if; /* network interface we use */
- char *mac_addr_text; /* mac addr of network i.f. we use */
u8 mac_addr[ETH_ALEN]; /* mac addr of network i.f. we use */
char *ip_addr_text; /* IP address of network i.f. we use */
unsigned ip_addr; /* IP address of network i.f. we use (host order) */
@@ -138,16 +121,11 @@ struct upnp_wps_device_sm {
int ssdp_sd_registered; /* nonzero if we must unregister */
unsigned advertise_count; /* how many advertisements done */
struct advertisement_state_machine advertisement;
- struct advertisement_state_machine *msearch_replies;
- int n_msearch_replies; /* no. of pending M-SEARCH replies */
+ struct dl_list msearch_replies;
int web_port; /* our port that others get xml files from */
- int web_sd; /* socket to listen for web requests */
- int web_sd_registered; /* nonzero if we must cancel registration */
- struct web_connection *web_connections; /* linked list */
- int n_web_connections; /* no. of pending web connections */
+ struct http_server *web_srv;
/* Note: subscriptions are kept in expiry order */
- struct subscription *subscriptions; /* linked list */
- int n_subscriptions; /* no of current subscriptions */
+ struct dl_list subscriptions;
int event_send_all_queued; /* if we are scheduled to send events soon
*/
@@ -163,11 +141,12 @@ struct subscription * subscription_start(struct upnp_wps_device_sm *sm,
const char *callback_urls);
struct subscription * subscription_renew(struct upnp_wps_device_sm *sm,
const u8 uuid[UUID_LEN]);
-void subscription_unlink(struct subscription *s);
void subscription_destroy(struct subscription *s);
struct subscription * subscription_find(struct upnp_wps_device_sm *sm,
const u8 uuid[UUID_LEN]);
int send_wpabuf(int fd, struct wpabuf *buf);
+int get_netif_info(const char *net_if, unsigned *ip_addr, char **ip_addr_text,
+ u8 mac[ETH_ALEN]);
/* wps_upnp_ssdp.c */
void msearchreply_state_machine_stop(struct advertisement_state_machine *a);
@@ -176,11 +155,12 @@ void advertisement_state_machine_stop(struct upnp_wps_device_sm *sm,
int send_byebye);
void ssdp_listener_stop(struct upnp_wps_device_sm *sm);
int ssdp_listener_start(struct upnp_wps_device_sm *sm);
-int add_ssdp_network(char *net_if);
+int ssdp_listener_open(void);
+int add_ssdp_network(const char *net_if);
+int ssdp_open_multicast_sock(u32 ip_addr);
int ssdp_open_multicast(struct upnp_wps_device_sm *sm);
/* wps_upnp_web.c */
-void web_connection_stop(struct web_connection *c);
int web_listener_start(struct upnp_wps_device_sm *sm);
void web_listener_stop(struct upnp_wps_device_sm *sm);
@@ -190,4 +170,10 @@ void event_delete_all(struct subscription *s);
void event_send_all_later(struct upnp_wps_device_sm *sm);
void event_send_stop_all(struct upnp_wps_device_sm *sm);
+/* wps_upnp_ap.c */
+int upnp_er_set_selected_registrar(struct wps_registrar *reg,
+ struct subscription *s,
+ const struct wpabuf *msg);
+void upnp_er_remove_notification(struct subscription *s);
+
#endif /* WPS_UPNP_I_H */
diff --git a/contrib/wpa/src/wps/wps_upnp_ssdp.c b/contrib/wpa/src/wps/wps_upnp_ssdp.c
index c1dc99d..8505d05 100644
--- a/contrib/wpa/src/wps/wps_upnp_ssdp.c
+++ b/contrib/wpa/src/wps/wps_upnp_ssdp.c
@@ -24,7 +24,6 @@
#define UPNP_CACHE_SEC (UPNP_CACHE_SEC_MIN + 1) /* cache time we use */
#define UPNP_CACHE_SEC_MIN 1800 /* min cachable time per UPnP standard */
#define UPNP_ADVERTISE_REPEAT 2 /* no more than 3 */
-#define MULTICAST_MAX_READ 1600 /* max bytes we'll read for UPD request */
#define MAX_MSEARCH 20 /* max simultaneous M-SEARCH replies ongoing */
#define SSDP_TARGET "239.0.0.0"
#define SSDP_NETMASK "255.0.0.0"
@@ -131,14 +130,15 @@ static int str_starts(const char *str, const char *start)
* Note: next_advertisement is shared code with msearchreply_* functions
*/
static struct wpabuf *
-next_advertisement(struct advertisement_state_machine *a, int *islast)
+next_advertisement(struct upnp_wps_device_sm *sm,
+ struct advertisement_state_machine *a, int *islast)
{
struct wpabuf *msg;
char *NTString = "";
char uuid_string[80];
*islast = 0;
- uuid_bin2str(a->sm->wps->uuid, uuid_string, sizeof(uuid_string));
+ uuid_bin2str(sm->wps->uuid, uuid_string, sizeof(uuid_string));
msg = wpabuf_alloc(800); /* more than big enough */
if (msg == NULL)
goto fail;
@@ -172,7 +172,7 @@ next_advertisement(struct advertisement_state_machine *a, int *islast)
if (a->type != ADVERTISE_DOWN) {
/* Where others may get our XML files from */
wpabuf_printf(msg, "LOCATION: http://%s:%d/%s\r\n",
- a->sm->ip_addr_text, a->sm->web_port,
+ sm->ip_addr_text, sm->web_port,
UPNP_WPS_DEVICE_XML_FILE);
}
@@ -245,7 +245,6 @@ void advertisement_state_machine_stop(struct upnp_wps_device_sm *sm,
a->type = ADVERTISE_DOWN;
a->state = 0;
- a->sm = sm;
os_memset(&dest, 0, sizeof(dest));
dest.sin_family = AF_INET;
@@ -253,7 +252,7 @@ void advertisement_state_machine_stop(struct upnp_wps_device_sm *sm,
dest.sin_port = htons(UPNP_MULTICAST_PORT);
while (!islast) {
- msg = next_advertisement(a, &islast);
+ msg = next_advertisement(sm, a, &islast);
if (msg == NULL)
break;
if (sendto(sm->multicast_sd, wpabuf_head(msg), wpabuf_len(msg),
@@ -292,7 +291,7 @@ static void advertisement_state_machine_handler(void *eloop_data,
*/
wpa_printf(MSG_MSGDUMP, "WPS UPnP: Advertisement state=%d", a->state);
- msg = next_advertisement(a, &islast);
+ msg = next_advertisement(sm, a, &islast);
if (msg == NULL)
return;
@@ -357,7 +356,6 @@ int advertisement_state_machine_start(struct upnp_wps_device_sm *sm)
*/
a->type = ADVERTISE_DOWN;
a->state = 0;
- a->sm = sm;
/* (other fields not used here) */
/* First timeout should be random interval < 100 msec */
@@ -376,28 +374,15 @@ int advertisement_state_machine_start(struct upnp_wps_device_sm *sm)
* They are sent in response to a UDP M-SEARCH packet.
**************************************************************************/
-static void msearchreply_state_machine_handler(void *eloop_data,
- void *user_ctx);
-
-
/**
* msearchreply_state_machine_stop - Stop M-SEARCH reply state machine
* @a: Selected advertisement/reply state
*/
void msearchreply_state_machine_stop(struct advertisement_state_machine *a)
{
- struct upnp_wps_device_sm *sm = a->sm;
wpa_printf(MSG_DEBUG, "WPS UPnP: M-SEARCH stop");
- if (a->next == a) {
- sm->msearch_replies = NULL;
- } else {
- if (sm->msearch_replies == a)
- sm->msearch_replies = a->next;
- a->next->prev = a->prev;
- a->prev->next = a->next;
- }
+ dl_list_del(&a->list);
os_free(a);
- sm->n_msearch_replies--;
}
@@ -405,7 +390,7 @@ static void msearchreply_state_machine_handler(void *eloop_data,
void *user_ctx)
{
struct advertisement_state_machine *a = user_ctx;
- struct upnp_wps_device_sm *sm = a->sm;
+ struct upnp_wps_device_sm *sm = eloop_data;
struct wpabuf *msg;
int next_timeout_msec = 100;
int next_timeout_sec = 0;
@@ -423,7 +408,7 @@ static void msearchreply_state_machine_handler(void *eloop_data,
wpa_printf(MSG_MSGDUMP, "WPS UPnP: M-SEARCH reply state=%d (%s:%d)",
a->state, inet_ntoa(a->client.sin_addr),
ntohs(a->client.sin_port));
- msg = next_advertisement(a, &islast);
+ msg = next_advertisement(sm, a, &islast);
if (msg == NULL)
return;
@@ -477,10 +462,12 @@ static void msearchreply_state_machine_start(struct upnp_wps_device_sm *sm,
struct advertisement_state_machine *a;
int next_timeout_sec;
int next_timeout_msec;
+ int replies;
+ replies = dl_list_len(&sm->msearch_replies);
wpa_printf(MSG_DEBUG, "WPS UPnP: M-SEARCH reply start (%d "
- "outstanding)", sm->n_msearch_replies);
- if (sm->n_msearch_replies >= MAX_MSEARCH) {
+ "outstanding)", replies);
+ if (replies >= MAX_MSEARCH) {
wpa_printf(MSG_INFO, "WPS UPnP: Too many outstanding "
"M-SEARCH replies");
return;
@@ -491,7 +478,6 @@ static void msearchreply_state_machine_start(struct upnp_wps_device_sm *sm,
return;
a->type = MSEARCH_REPLY;
a->state = 0;
- a->sm = sm;
os_memcpy(&a->client, client, sizeof(*client));
/* Wait time depending on MX value */
next_timeout_msec = (1000 * mx * (os_random() & 0xFF)) >> 8;
@@ -504,15 +490,7 @@ static void msearchreply_state_machine_start(struct upnp_wps_device_sm *sm,
goto fail;
}
/* Remember for future cleanup */
- if (sm->msearch_replies) {
- a->next = sm->msearch_replies;
- a->prev = a->next->prev;
- a->prev->next = a;
- a->next->prev = a;
- } else {
- sm->msearch_replies = a->next = a->prev = a;
- }
- sm->n_msearch_replies++;
+ dl_list_add(&sm->msearch_replies, &a->list);
return;
fail:
@@ -546,7 +524,9 @@ fail:
static void ssdp_parse_msearch(struct upnp_wps_device_sm *sm,
struct sockaddr_in *client, const char *data)
{
+#ifndef CONFIG_NO_STDOUT_DEBUG
const char *start = data;
+#endif /* CONFIG_NO_STDOUT_DEBUG */
const char *end;
int got_host = 0;
int got_st = 0, st_match = 0;
@@ -688,7 +668,7 @@ bad:
* ssdp_listener_stop - Stop SSDP listered
* @sm: WPS UPnP state machine from upnp_wps_device_init()
*
- * This function stops the SSDP listerner that was started by calling
+ * This function stops the SSDP listener that was started by calling
* ssdp_listener_start().
*/
void ssdp_listener_stop(struct upnp_wps_device_sm *sm)
@@ -750,23 +730,16 @@ static void ssdp_listener_handler(int sd, void *eloop_ctx, void *sock_ctx)
}
-/**
- * ssdp_listener_start - Set up for receiving discovery (UDP) packets
- * @sm: WPS UPnP state machine from upnp_wps_device_init()
- * Returns: 0 on success, -1 on failure
- *
- * The SSDP listerner is stopped by calling ssdp_listener_stop().
- */
-int ssdp_listener_start(struct upnp_wps_device_sm *sm)
+int ssdp_listener_open(void)
{
- int sd = -1;
struct sockaddr_in addr;
struct ip_mreq mcast_addr;
int on = 1;
/* per UPnP spec, keep IP packet time to live (TTL) small */
unsigned char ttl = 4;
+ int sd;
- sm->ssdp_sd = sd = socket(AF_INET, SOCK_DGRAM, 0);
+ sd = socket(AF_INET, SOCK_DGRAM, 0);
if (sd < 0)
goto fail;
if (fcntl(sd, F_SETFL, O_NONBLOCK) != 0)
@@ -788,8 +761,29 @@ int ssdp_listener_start(struct upnp_wps_device_sm *sm)
if (setsockopt(sd, IPPROTO_IP, IP_MULTICAST_TTL,
&ttl, sizeof(ttl)))
goto fail;
- if (eloop_register_sock(sd, EVENT_TYPE_READ, ssdp_listener_handler,
- NULL, sm))
+
+ return sd;
+
+fail:
+ if (sd >= 0)
+ close(sd);
+ return -1;
+}
+
+
+/**
+ * ssdp_listener_start - Set up for receiving discovery (UDP) packets
+ * @sm: WPS UPnP state machine from upnp_wps_device_init()
+ * Returns: 0 on success, -1 on failure
+ *
+ * The SSDP listener is stopped by calling ssdp_listener_stop().
+ */
+int ssdp_listener_start(struct upnp_wps_device_sm *sm)
+{
+ sm->ssdp_sd = ssdp_listener_open();
+
+ if (eloop_register_sock(sm->ssdp_sd, EVENT_TYPE_READ,
+ ssdp_listener_handler, NULL, sm))
goto fail;
sm->ssdp_sd_registered = 1;
return 0;
@@ -813,7 +807,7 @@ fail:
* once after booting up, but it does not hurt to call this more frequently
* "to be safe".
*/
-int add_ssdp_network(char *net_if)
+int add_ssdp_network(const char *net_if)
{
#ifdef __linux__
int ret = -1;
@@ -829,7 +823,7 @@ int add_ssdp_network(char *net_if)
if (sock < 0)
goto fail;
- rt.rt_dev = net_if;
+ rt.rt_dev = (char *) net_if;
sin = aliasing_hide_typecast(&rt.rt_dst, struct sockaddr_in);
sin->sin_family = AF_INET;
sin->sin_port = 0;
@@ -864,19 +858,14 @@ fail:
}
-/**
- * ssdp_open_multicast - Open socket for sending multicast SSDP messages
- * @sm: WPS UPnP state machine from upnp_wps_device_init()
- * Returns: 0 on success, -1 on failure
- */
-int ssdp_open_multicast(struct upnp_wps_device_sm *sm)
+int ssdp_open_multicast_sock(u32 ip_addr)
{
- int sd = -1;
+ int sd;
/* per UPnP-arch-DeviceArchitecture, 1. Discovery, keep IP packet
* time to live (TTL) small */
unsigned char ttl = 4;
- sm->multicast_sd = sd = socket(AF_INET, SOCK_DGRAM, 0);
+ sd = socket(AF_INET, SOCK_DGRAM, 0);
if (sd < 0)
return -1;
@@ -886,7 +875,7 @@ int ssdp_open_multicast(struct upnp_wps_device_sm *sm)
#endif
if (setsockopt(sd, IPPROTO_IP, IP_MULTICAST_IF,
- &sm->ip_addr, sizeof(sm->ip_addr)))
+ &ip_addr, sizeof(ip_addr)))
return -1;
if (setsockopt(sd, IPPROTO_IP, IP_MULTICAST_TTL,
&ttl, sizeof(ttl)))
@@ -896,7 +885,7 @@ int ssdp_open_multicast(struct upnp_wps_device_sm *sm)
{
struct ip_mreq mreq;
mreq.imr_multiaddr.s_addr = inet_addr(UPNP_MULTICAST_ADDRESS);
- mreq.imr_interface.s_addr = sm->ip_addr;
+ mreq.imr_interface.s_addr = ip_addr;
wpa_printf(MSG_DEBUG, "WPS UPnP: Multicast addr 0x%x if addr "
"0x%x",
mreq.imr_multiaddr.s_addr,
@@ -917,5 +906,19 @@ int ssdp_open_multicast(struct upnp_wps_device_sm *sm)
* which aids debugging I suppose but isn't really necessary?
*/
+ return sd;
+}
+
+
+/**
+ * ssdp_open_multicast - Open socket for sending multicast SSDP messages
+ * @sm: WPS UPnP state machine from upnp_wps_device_init()
+ * Returns: 0 on success, -1 on failure
+ */
+int ssdp_open_multicast(struct upnp_wps_device_sm *sm)
+{
+ sm->multicast_sd = ssdp_open_multicast_sock(sm->ip_addr);
+ if (sm->multicast_sd < 0)
+ return -1;
return 0;
}
diff --git a/contrib/wpa/src/wps/wps_upnp_web.c b/contrib/wpa/src/wps/wps_upnp_web.c
index b637454..9a6b36e 100644
--- a/contrib/wpa/src/wps/wps_upnp_web.c
+++ b/contrib/wpa/src/wps/wps_upnp_web.c
@@ -9,16 +9,16 @@
*/
#include "includes.h"
-#include <fcntl.h>
#include "common.h"
#include "base64.h"
-#include "eloop.h"
#include "uuid.h"
#include "httpread.h"
+#include "http_server.h"
#include "wps_i.h"
#include "wps_upnp.h"
#include "wps_upnp_i.h"
+#include "upnp_xml.h"
/***************************************************************************
* Web connections (we serve pages of info about ourselves, handle
@@ -38,238 +38,6 @@ static const char *http_connection_close =
"Connection: close\r\n";
/*
- * Incoming web connections are recorded in this struct.
- * A web connection is a TCP connection to us, the server;
- * it is called a "web connection" because we use http and serve
- * data that looks like web pages.
- * State information is need to track the connection until we figure
- * out what they want and what we want to do about it.
- */
-struct web_connection {
- /* double linked list */
- struct web_connection *next;
- struct web_connection *prev;
- struct upnp_wps_device_sm *sm; /* parent */
- int sd; /* socket to read from */
- struct sockaddr_in cli_addr;
- int sd_registered; /* nonzero if we must cancel registration */
- struct httpread *hread; /* state machine for reading socket */
- int n_rcvd_data; /* how much data read so far */
- int done; /* internal flag, set when we've finished */
-};
-
-
-/*
- * XML parsing and formatting
- *
- * XML is a markup language based on unicode; usually (and in our case,
- * always!) based on utf-8. utf-8 uses a variable number of bytes per
- * character. utf-8 has the advantage that all non-ASCII unicode characters are
- * represented by sequences of non-ascii (high bit set) bytes, whereas ASCII
- * characters are single ascii bytes, thus we can use typical text processing.
- *
- * (One other interesting thing about utf-8 is that it is possible to look at
- * any random byte and determine if it is the first byte of a character as
- * versus a continuation byte).
- *
- * The base syntax of XML uses a few ASCII punctionation characters; any
- * characters that would appear in the payload data are rewritten using
- * sequences, e.g., &amp; for ampersand(&) and &lt for left angle bracket (<).
- * Five such escapes total (more can be defined but that does not apply to our
- * case). Thus we can safely parse for angle brackets etc.
- *
- * XML describes tree structures of tagged data, with each element beginning
- * with an opening tag <label> and ending with a closing tag </label> with
- * matching label. (There is also a self-closing tag <label/> which is supposed
- * to be equivalent to <label></label>, i.e., no payload, but we are unlikely
- * to see it for our purpose).
- *
- * Actually the opening tags are a little more complicated because they can
- * contain "attributes" after the label (delimited by ascii space or tab chars)
- * of the form attribute_label="value" or attribute_label='value'; as it turns
- * out we do not have to read any of these attributes, just ignore them.
- *
- * Labels are any sequence of chars other than space, tab, right angle bracket
- * (and ?), but may have an inner structure of <namespace><colon><plain_label>.
- * As it turns out, we can ignore the namespaces, in fact we can ignore the
- * entire tree hierarchy, because the plain labels we are looking for will be
- * unique (not in general, but for this application). We do however have to be
- * careful to skip over the namespaces.
- *
- * In generating XML we have to be more careful, but that is easy because
- * everything we do is pretty canned. The only real care to take is to escape
- * any special chars in our payload.
- */
-
-/**
- * xml_next_tag - Advance to next tag
- * @in: Input
- * @out: OUT: start of tag just after '<'
- * @out_tagname: OUT: start of name of tag, skipping namespace
- * @end: OUT: one after tag
- * Returns: 0 on success, 1 on failure
- *
- * A tag has form:
- * <left angle bracket><...><right angle bracket>
- * Within the angle brackets, there is an optional leading forward slash (which
- * makes the tag an ending tag), then an optional leading label (followed by
- * colon) and then the tag name itself.
- *
- * Note that angle brackets present in the original data must have been encoded
- * as &lt; and &gt; so they will not trouble us.
- */
-static int xml_next_tag(char *in, char **out, char **out_tagname,
- char **end)
-{
- while (*in && *in != '<')
- in++;
- if (*in != '<')
- return 1;
- *out = ++in;
- if (*in == '/')
- in++;
- *out_tagname = in; /* maybe */
- while (isalnum(*in) || *in == '-')
- in++;
- if (*in == ':')
- *out_tagname = ++in;
- while (*in && *in != '>')
- in++;
- if (*in != '>')
- return 1;
- *end = ++in;
- return 0;
-}
-
-
-/* xml_data_encode -- format data for xml file, escaping special characters.
- *
- * Note that we assume we are using utf8 both as input and as output!
- * In utf8, characters may be classed as follows:
- * 0xxxxxxx(2) -- 1 byte ascii char
- * 11xxxxxx(2) -- 1st byte of multi-byte char w/ unicode value >= 0x80
- * 110xxxxx(2) -- 1st byte of 2 byte sequence (5 payload bits here)
- * 1110xxxx(2) -- 1st byte of 3 byte sequence (4 payload bits here)
- * 11110xxx(2) -- 1st byte of 4 byte sequence (3 payload bits here)
- * 10xxxxxx(2) -- extension byte (6 payload bits per byte)
- * Some values implied by the above are however illegal because they
- * do not represent unicode chars or are not the shortest encoding.
- * Actually, we can almost entirely ignore the above and just do
- * text processing same as for ascii text.
- *
- * XML is written with arbitrary unicode characters, except that five
- * characters have special meaning and so must be escaped where they
- * appear in payload data... which we do here.
- */
-static void xml_data_encode(struct wpabuf *buf, const char *data, int len)
-{
- int i;
- for (i = 0; i < len; i++) {
- u8 c = ((u8 *) data)[i];
- if (c == '<') {
- wpabuf_put_str(buf, "&lt;");
- continue;
- }
- if (c == '>') {
- wpabuf_put_str(buf, "&gt;");
- continue;
- }
- if (c == '&') {
- wpabuf_put_str(buf, "&amp;");
- continue;
- }
- if (c == '\'') {
- wpabuf_put_str(buf, "&apos;");
- continue;
- }
- if (c == '"') {
- wpabuf_put_str(buf, "&quot;");
- continue;
- }
- /*
- * We could try to represent control characters using the
- * sequence: &#x; where x is replaced by a hex numeral, but not
- * clear why we would do this.
- */
- wpabuf_put_u8(buf, c);
- }
-}
-
-
-/* xml_add_tagged_data -- format tagged data as a new xml line.
- *
- * tag must not have any special chars.
- * data may have special chars, which are escaped.
- */
-static void xml_add_tagged_data(struct wpabuf *buf, const char *tag,
- const char *data)
-{
- wpabuf_printf(buf, "<%s>", tag);
- xml_data_encode(buf, data, os_strlen(data));
- wpabuf_printf(buf, "</%s>\n", tag);
-}
-
-
-/* A POST body looks something like (per upnp spec):
- * <?xml version="1.0"?>
- * <s:Envelope
- * xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
- * s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
- * <s:Body>
- * <u:actionName xmlns:u="urn:schemas-upnp-org:service:serviceType:v">
- * <argumentName>in arg value</argumentName>
- * other in args and their values go here, if any
- * </u:actionName>
- * </s:Body>
- * </s:Envelope>
- *
- * where :
- * s: might be some other namespace name followed by colon
- * u: might be some other namespace name followed by colon
- * actionName will be replaced according to action requested
- * schema following actionName will be WFA scheme instead
- * argumentName will be actual argument name
- * (in arg value) will be actual argument value
- */
-static int
-upnp_get_first_document_item(char *doc, const char *item, char **value)
-{
- const char *match = item;
- int match_len = os_strlen(item);
- char *tag;
- char *tagname;
- char *end;
-
- *value = NULL; /* default, bad */
-
- /*
- * This is crude: ignore any possible tag name conflicts and go right
- * to the first tag of this name. This should be ok for the limited
- * domain of UPnP messages.
- */
- for (;;) {
- if (xml_next_tag(doc, &tag, &tagname, &end))
- return 1;
- doc = end;
- if (!os_strncasecmp(tagname, match, match_len) &&
- *tag != '/' &&
- (tagname[match_len] == '>' ||
- !isgraph(tagname[match_len]))) {
- break;
- }
- }
- end = doc;
- while (*end && *end != '<')
- end++;
- *value = os_zalloc(1 + (end - doc));
- if (*value == NULL)
- return 1;
- os_memcpy(*value, doc, end - doc);
- return 0;
-}
-
-
-/*
* "Files" that we serve via HTTP. The format of these files is given by
* WFA WPS specifications. Extra white space has been removed to save space.
*/
@@ -305,76 +73,6 @@ static const char wps_scpd_xml[] =
"</argumentList>\n"
"</action>\n"
"<action>\n"
-"<name>GetAPSettings</name>\n"
-"<argumentList>\n"
-"<argument>\n"
-"<name>NewMessage</name>\n"
-"<direction>in</direction>\n"
-"<relatedStateVariable>Message</relatedStateVariable>\n"
-"</argument>\n"
-"<argument>\n"
-"<name>NewAPSettings</name>\n"
-"<direction>out</direction>\n"
-"<relatedStateVariable>APSettings</relatedStateVariable>\n"
-"</argument>\n"
-"</argumentList>\n"
-"</action>\n"
-"<action>\n"
-"<name>SetAPSettings</name>\n"
-"<argumentList>\n"
-"<argument>\n"
-"<name>APSettings</name>\n"
-"<direction>in</direction>\n"
-"<relatedStateVariable>APSettings</relatedStateVariable>\n"
-"</argument>\n"
-"</argumentList>\n"
-"</action>\n"
-"<action>\n"
-"<name>DelAPSettings</name>\n"
-"<argumentList>\n"
-"<argument>\n"
-"<name>NewAPSettings</name>\n"
-"<direction>in</direction>\n"
-"<relatedStateVariable>APSettings</relatedStateVariable>\n"
-"</argument>\n"
-"</argumentList>\n"
-"</action>\n"
-"<action>\n"
-"<name>GetSTASettings</name>\n"
-"<argumentList>\n"
-"<argument>\n"
-"<name>NewMessage</name>\n"
-"<direction>in</direction>\n"
-"<relatedStateVariable>Message</relatedStateVariable>\n"
-"</argument>\n"
-"<argument>\n"
-"<name>NewSTASettings</name>\n"
-"<direction>out</direction>\n"
-"<relatedStateVariable>STASettings</relatedStateVariable>\n"
-"</argument>\n"
-"</argumentList>\n"
-"</action>\n"
-"<action>\n"
-"<name>SetSTASettings</name>\n"
-"<argumentList>\n"
-"<argument>\n"
-"<name>NewSTASettings</name>\n"
-"<direction>out</direction>\n"
-"<relatedStateVariable>STASettings</relatedStateVariable>\n"
-"</argument>\n"
-"</argumentList>\n"
-"</action>\n"
-"<action>\n"
-"<name>DelSTASettings</name>\n"
-"<argumentList>\n"
-"<argument>\n"
-"<name>NewSTASettings</name>\n"
-"<direction>in</direction>\n"
-"<relatedStateVariable>STASettings</relatedStateVariable>\n"
-"</argument>\n"
-"</argumentList>\n"
-"</action>\n"
-"<action>\n"
"<name>PutWLANResponse</name>\n"
"<argumentList>\n"
"<argument>\n"
@@ -404,46 +102,6 @@ static const char wps_scpd_xml[] =
"</argument>\n"
"</argumentList>\n"
"</action>\n"
-"<action>\n"
-"<name>RebootAP</name>\n"
-"<argumentList>\n"
-"<argument>\n"
-"<name>NewAPSettings</name>\n"
-"<direction>in</direction>\n"
-"<relatedStateVariable>APSettings</relatedStateVariable>\n"
-"</argument>\n"
-"</argumentList>\n"
-"</action>\n"
-"<action>\n"
-"<name>ResetAP</name>\n"
-"<argumentList>\n"
-"<argument>\n"
-"<name>NewMessage</name>\n"
-"<direction>in</direction>\n"
-"<relatedStateVariable>Message</relatedStateVariable>\n"
-"</argument>\n"
-"</argumentList>\n"
-"</action>\n"
-"<action>\n"
-"<name>RebootSTA</name>\n"
-"<argumentList>\n"
-"<argument>\n"
-"<name>NewSTASettings</name>\n"
-"<direction>in</direction>\n"
-"<relatedStateVariable>APSettings</relatedStateVariable>\n"
-"</argument>\n"
-"</argumentList>\n"
-"</action>\n"
-"<action>\n"
-"<name>ResetSTA</name>\n"
-"<argumentList>\n"
-"<argument>\n"
-"<name>NewMessage</name>\n"
-"<direction>in</direction>\n"
-"<relatedStateVariable>Message</relatedStateVariable>\n"
-"</argument>\n"
-"</argumentList>\n"
-"</action>\n"
"</actionList>\n"
"<serviceStateTable>\n"
"<stateVariable sendEvents=\"no\">\n"
@@ -462,18 +120,10 @@ static const char wps_scpd_xml[] =
"<name>DeviceInfo</name>\n"
"<dataType>bin.base64</dataType>\n"
"</stateVariable>\n"
-"<stateVariable sendEvents=\"no\">\n"
-"<name>APSettings</name>\n"
-"<dataType>bin.base64</dataType>\n"
-"</stateVariable>\n"
"<stateVariable sendEvents=\"yes\">\n"
"<name>APStatus</name>\n"
"<dataType>ui1</dataType>\n"
"</stateVariable>\n"
-"<stateVariable sendEvents=\"no\">\n"
-"<name>STASettings</name>\n"
-"<dataType>bin.base64</dataType>\n"
-"</stateVariable>\n"
"<stateVariable sendEvents=\"yes\">\n"
"<name>STAStatus</name>\n"
"<dataType>ui1</dataType>\n"
@@ -588,27 +238,6 @@ static void format_wps_device_xml(struct upnp_wps_device_sm *sm,
}
-void web_connection_stop(struct web_connection *c)
-{
- struct upnp_wps_device_sm *sm = c->sm;
-
- httpread_destroy(c->hread);
- c->hread = NULL;
- close(c->sd);
- c->sd = -1;
- if (c->next == c) {
- sm->web_connections = NULL;
- } else {
- if (sm->web_connections == c)
- sm->web_connections = c->next;
- c->next->prev = c->prev;
- c->prev->next = c->next;
- }
- os_free(c);
- sm->n_web_connections--;
-}
-
-
static void http_put_reply_code(struct wpabuf *buf, enum http_reply_code code)
{
wpabuf_put_str(buf, "HTTP/1.1 ");
@@ -669,9 +298,9 @@ static void http_put_empty(struct wpabuf *buf, enum http_reply_code code)
* Per RFC 2616, content-length: is not required but connection:close
* would appear to be required (given that we will be closing it!).
*/
-static void web_connection_parse_get(struct web_connection *c, char *filename)
+static void web_connection_parse_get(struct upnp_wps_device_sm *sm,
+ struct http_request *hreq, char *filename)
{
- struct upnp_wps_device_sm *sm = c->sm;
struct wpabuf *buf; /* output buffer, allocated */
char *put_length_here;
char *body_start;
@@ -712,8 +341,10 @@ static void web_connection_parse_get(struct web_connection *c, char *filename)
wpa_printf(MSG_DEBUG, "WPS UPnP: HTTP GET file not found: %s",
filename);
buf = wpabuf_alloc(200);
- if (buf == NULL)
+ if (buf == NULL) {
+ http_request_deinit(hreq);
return;
+ }
wpabuf_put_str(buf,
"HTTP/1.1 404 Not Found\r\n"
"Connection: close\r\n");
@@ -727,8 +358,10 @@ static void web_connection_parse_get(struct web_connection *c, char *filename)
}
buf = wpabuf_alloc(1000 + extra_len);
- if (buf == NULL)
+ if (buf == NULL) {
+ http_request_deinit(hreq);
return;
+ }
wpabuf_put_str(buf,
"HTTP/1.1 200 OK\r\n"
@@ -765,38 +398,7 @@ static void web_connection_parse_get(struct web_connection *c, char *filename)
os_memcpy(put_length_here, len_buf, os_strlen(len_buf));
send_buf:
- send_wpabuf(c->sd, buf);
- wpabuf_free(buf);
-}
-
-
-static struct wpabuf * web_get_item(char *data, const char *name,
- enum http_reply_code *ret)
-{
- char *msg;
- struct wpabuf *buf;
- unsigned char *decoded;
- size_t len;
-
- if (upnp_get_first_document_item(data, name, &msg)) {
- *ret = UPNP_ARG_VALUE_INVALID;
- return NULL;
- }
-
- decoded = base64_decode((unsigned char *) msg, os_strlen(msg), &len);
- os_free(msg);
- if (decoded == NULL) {
- *ret = UPNP_OUT_OF_MEMORY;
- return NULL;
- }
-
- buf = wpabuf_alloc_ext_data(decoded, len);
- if (buf == NULL) {
- os_free(decoded);
- *ret = UPNP_OUT_OF_MEMORY;
- return NULL;
- }
- return buf;
+ http_request_send_and_deinit(hreq, buf);
}
@@ -805,11 +407,39 @@ web_process_get_device_info(struct upnp_wps_device_sm *sm,
struct wpabuf **reply, const char **replyname)
{
static const char *name = "NewDeviceInfo";
+ struct wps_config cfg;
+ struct upnp_wps_peer *peer = &sm->peer;
wpa_printf(MSG_DEBUG, "WPS UPnP: GetDeviceInfo");
- if (sm->ctx->rx_req_get_device_info == NULL)
+
+ if (sm->ctx->ap_pin == NULL)
return HTTP_INTERNAL_SERVER_ERROR;
- *reply = sm->ctx->rx_req_get_device_info(sm->priv, &sm->peer);
+
+ /*
+ * Request for DeviceInfo, i.e., M1 TLVs. This is a start of WPS
+ * registration over UPnP with the AP acting as an Enrollee. It should
+ * be noted that this is frequently used just to get the device data,
+ * i.e., there may not be any intent to actually complete the
+ * registration.
+ */
+
+ if (peer->wps)
+ wps_deinit(peer->wps);
+
+ os_memset(&cfg, 0, sizeof(cfg));
+ cfg.wps = sm->wps;
+ cfg.pin = (u8 *) sm->ctx->ap_pin;
+ cfg.pin_len = os_strlen(sm->ctx->ap_pin);
+ peer->wps = wps_init(&cfg);
+ if (peer->wps) {
+ enum wsc_op_code op_code;
+ *reply = wps_get_msg(peer->wps, &op_code);
+ if (*reply == NULL) {
+ wps_deinit(peer->wps);
+ peer->wps = NULL;
+ }
+ } else
+ *reply = NULL;
if (*reply == NULL) {
wpa_printf(MSG_INFO, "WPS UPnP: Failed to get DeviceInfo");
return HTTP_INTERNAL_SERVER_ERROR;
@@ -826,6 +456,8 @@ web_process_put_message(struct upnp_wps_device_sm *sm, char *data,
struct wpabuf *msg;
static const char *name = "NewOutMessage";
enum http_reply_code ret;
+ enum wps_process_res res;
+ enum wsc_op_code op_code;
/*
* PutMessage is used by external UPnP-based Registrar to perform WPS
@@ -833,104 +465,14 @@ web_process_put_message(struct upnp_wps_device_sm *sm, char *data,
* PutWLANResponse which is for proxying.
*/
wpa_printf(MSG_DEBUG, "WPS UPnP: PutMessage");
- if (sm->ctx->rx_req_put_message == NULL)
- return HTTP_INTERNAL_SERVER_ERROR;
- msg = web_get_item(data, "NewInMessage", &ret);
- if (msg == NULL)
- return ret;
- *reply = sm->ctx->rx_req_put_message(sm->priv, &sm->peer, msg);
- wpabuf_free(msg);
- if (*reply == NULL)
- return HTTP_INTERNAL_SERVER_ERROR;
- *replyname = name;
- return HTTP_OK;
-}
-
-
-static enum http_reply_code
-web_process_get_ap_settings(struct upnp_wps_device_sm *sm, char *data,
- struct wpabuf **reply, const char **replyname)
-{
- struct wpabuf *msg;
- static const char *name = "NewAPSettings";
- enum http_reply_code ret;
-
- wpa_printf(MSG_DEBUG, "WPS UPnP: GetAPSettings");
- if (sm->ctx->rx_req_get_ap_settings == NULL)
- return HTTP_INTERNAL_SERVER_ERROR;
- msg = web_get_item(data, "NewMessage", &ret);
- if (msg == NULL)
- return ret;
- *reply = sm->ctx->rx_req_get_ap_settings(sm->priv, msg);
- wpabuf_free(msg);
- if (*reply == NULL)
- return HTTP_INTERNAL_SERVER_ERROR;
- *replyname = name;
- return HTTP_OK;
-}
-
-
-static enum http_reply_code
-web_process_set_ap_settings(struct upnp_wps_device_sm *sm, char *data,
- struct wpabuf **reply, const char **replyname)
-{
- struct wpabuf *msg;
- enum http_reply_code ret;
-
- wpa_printf(MSG_DEBUG, "WPS UPnP: SetAPSettings");
- msg = web_get_item(data, "NewAPSettings", &ret);
- if (msg == NULL)
- return ret;
- if (!sm->ctx->rx_req_set_ap_settings ||
- sm->ctx->rx_req_set_ap_settings(sm->priv, msg)) {
- wpabuf_free(msg);
- return HTTP_INTERNAL_SERVER_ERROR;
- }
- wpabuf_free(msg);
- *replyname = NULL;
- *reply = NULL;
- return HTTP_OK;
-}
-
-
-static enum http_reply_code
-web_process_del_ap_settings(struct upnp_wps_device_sm *sm, char *data,
- struct wpabuf **reply, const char **replyname)
-{
- struct wpabuf *msg;
- enum http_reply_code ret;
-
- wpa_printf(MSG_DEBUG, "WPS UPnP: DelAPSettings");
- msg = web_get_item(data, "NewAPSettings", &ret);
- if (msg == NULL)
- return ret;
- if (!sm->ctx->rx_req_del_ap_settings ||
- sm->ctx->rx_req_del_ap_settings(sm->priv, msg)) {
- wpabuf_free(msg);
- return HTTP_INTERNAL_SERVER_ERROR;
- }
- wpabuf_free(msg);
- *replyname = NULL;
- *reply = NULL;
- return HTTP_OK;
-}
-
-
-static enum http_reply_code
-web_process_get_sta_settings(struct upnp_wps_device_sm *sm, char *data,
- struct wpabuf **reply, const char **replyname)
-{
- struct wpabuf *msg;
- static const char *name = "NewSTASettings";
- enum http_reply_code ret;
-
- wpa_printf(MSG_DEBUG, "WPS UPnP: GetSTASettings");
- if (sm->ctx->rx_req_get_sta_settings == NULL)
- return HTTP_INTERNAL_SERVER_ERROR;
- msg = web_get_item(data, "NewMessage", &ret);
+ msg = xml_get_base64_item(data, "NewInMessage", &ret);
if (msg == NULL)
return ret;
- *reply = sm->ctx->rx_req_get_sta_settings(sm->priv, msg);
+ res = wps_process_msg(sm->peer.wps, WSC_UPnP, msg);
+ if (res == WPS_FAILURE)
+ *reply = NULL;
+ else
+ *reply = wps_get_msg(sm->peer.wps, &op_code);
wpabuf_free(msg);
if (*reply == NULL)
return HTTP_INTERNAL_SERVER_ERROR;
@@ -940,52 +482,6 @@ web_process_get_sta_settings(struct upnp_wps_device_sm *sm, char *data,
static enum http_reply_code
-web_process_set_sta_settings(struct upnp_wps_device_sm *sm, char *data,
- struct wpabuf **reply, const char **replyname)
-{
- struct wpabuf *msg;
- enum http_reply_code ret;
-
- wpa_printf(MSG_DEBUG, "WPS UPnP: SetSTASettings");
- msg = web_get_item(data, "NewSTASettings", &ret);
- if (msg == NULL)
- return ret;
- if (!sm->ctx->rx_req_set_sta_settings ||
- sm->ctx->rx_req_set_sta_settings(sm->priv, msg)) {
- wpabuf_free(msg);
- return HTTP_INTERNAL_SERVER_ERROR;
- }
- wpabuf_free(msg);
- *replyname = NULL;
- *reply = NULL;
- return HTTP_OK;
-}
-
-
-static enum http_reply_code
-web_process_del_sta_settings(struct upnp_wps_device_sm *sm, char *data,
- struct wpabuf **reply, const char **replyname)
-{
- struct wpabuf *msg;
- enum http_reply_code ret;
-
- wpa_printf(MSG_DEBUG, "WPS UPnP: DelSTASettings");
- msg = web_get_item(data, "NewSTASettings", &ret);
- if (msg == NULL)
- return ret;
- if (!sm->ctx->rx_req_del_sta_settings ||
- sm->ctx->rx_req_del_sta_settings(sm->priv, msg)) {
- wpabuf_free(msg);
- return HTTP_INTERNAL_SERVER_ERROR;
- }
- wpabuf_free(msg);
- *replyname = NULL;
- *reply = NULL;
- return HTTP_OK;
-}
-
-
-static enum http_reply_code
web_process_put_wlan_response(struct upnp_wps_device_sm *sm, char *data,
struct wpabuf **reply, const char **replyname)
{
@@ -1002,22 +498,45 @@ web_process_put_wlan_response(struct upnp_wps_device_sm *sm, char *data,
*/
wpa_printf(MSG_DEBUG, "WPS UPnP: PutWLANResponse");
- msg = web_get_item(data, "NewMessage", &ret);
- if (msg == NULL)
+ msg = xml_get_base64_item(data, "NewMessage", &ret);
+ if (msg == NULL) {
+ wpa_printf(MSG_DEBUG, "WPS UPnP: Could not extract NewMessage "
+ "from PutWLANResponse");
return ret;
- if (upnp_get_first_document_item(data, "NewWLANEventType", &val)) {
+ }
+ val = xml_get_first_item(data, "NewWLANEventType");
+ if (val == NULL) {
+ wpa_printf(MSG_DEBUG, "WPS UPnP: No NewWLANEventType in "
+ "PutWLANResponse");
wpabuf_free(msg);
return UPNP_ARG_VALUE_INVALID;
}
ev_type = atol(val);
os_free(val);
- val = NULL;
- if (upnp_get_first_document_item(data, "NewWLANEventMAC", &val) ||
- hwaddr_aton(val, macaddr)) {
+ val = xml_get_first_item(data, "NewWLANEventMAC");
+ if (val == NULL) {
+ wpa_printf(MSG_DEBUG, "WPS UPnP: No NewWLANEventMAC in "
+ "PutWLANResponse");
wpabuf_free(msg);
- os_free(val);
return UPNP_ARG_VALUE_INVALID;
}
+ if (hwaddr_aton(val, macaddr)) {
+ wpa_printf(MSG_DEBUG, "WPS UPnP: Invalid NewWLANEventMAC in "
+ "PutWLANResponse: '%s'", val);
+ if (hwaddr_aton2(val, macaddr) > 0) {
+ /*
+ * At least some versions of Intel PROset seem to be
+ * using dot-deliminated MAC address format here.
+ */
+ wpa_printf(MSG_DEBUG, "WPS UPnP: Workaround - allow "
+ "incorrect MAC address format in "
+ "NewWLANEventMAC");
+ } else {
+ wpabuf_free(msg);
+ os_free(val);
+ return UPNP_ARG_VALUE_INVALID;
+ }
+ }
os_free(val);
if (ev_type == UPNP_WPS_WLANEVENT_TYPE_EAP) {
struct wps_parse_attr attr;
@@ -1044,112 +563,50 @@ web_process_put_wlan_response(struct upnp_wps_device_sm *sm, char *data,
}
-static enum http_reply_code
-web_process_set_selected_registrar(struct upnp_wps_device_sm *sm, char *data,
- struct wpabuf **reply,
- const char **replyname)
+static int find_er_addr(struct subscription *s, struct sockaddr_in *cli)
{
- struct wpabuf *msg;
- enum http_reply_code ret;
-
- wpa_printf(MSG_DEBUG, "WPS UPnP: SetSelectedRegistrar");
- msg = web_get_item(data, "NewMessage", &ret);
- if (msg == NULL)
- return ret;
- if (!sm->ctx->rx_req_set_selected_registrar ||
- sm->ctx->rx_req_set_selected_registrar(sm->priv, msg)) {
- wpabuf_free(msg);
- return HTTP_INTERNAL_SERVER_ERROR;
- }
- wpabuf_free(msg);
- *replyname = NULL;
- *reply = NULL;
- return HTTP_OK;
-}
-
+ struct subscr_addr *a;
-static enum http_reply_code
-web_process_reboot_ap(struct upnp_wps_device_sm *sm, char *data,
- struct wpabuf **reply, const char **replyname)
-{
- struct wpabuf *msg;
- enum http_reply_code ret;
-
- wpa_printf(MSG_DEBUG, "WPS UPnP: RebootAP");
- msg = web_get_item(data, "NewAPSettings", &ret);
- if (msg == NULL)
- return ret;
- if (!sm->ctx->rx_req_reboot_ap ||
- sm->ctx->rx_req_reboot_ap(sm->priv, msg)) {
- wpabuf_free(msg);
- return HTTP_INTERNAL_SERVER_ERROR;
+ dl_list_for_each(a, &s->addr_list, struct subscr_addr, list) {
+ if (cli->sin_addr.s_addr == a->saddr.sin_addr.s_addr)
+ return 1;
}
- wpabuf_free(msg);
- *replyname = NULL;
- *reply = NULL;
- return HTTP_OK;
+ return 0;
}
-static enum http_reply_code
-web_process_reset_ap(struct upnp_wps_device_sm *sm, char *data,
- struct wpabuf **reply, const char **replyname)
+static struct subscription * find_er(struct upnp_wps_device_sm *sm,
+ struct sockaddr_in *cli)
{
- struct wpabuf *msg;
- enum http_reply_code ret;
-
- wpa_printf(MSG_DEBUG, "WPS UPnP: ResetAP");
- msg = web_get_item(data, "NewMessage", &ret);
- if (msg == NULL)
- return ret;
- if (!sm->ctx->rx_req_reset_ap ||
- sm->ctx->rx_req_reset_ap(sm->priv, msg)) {
- wpabuf_free(msg);
- return HTTP_INTERNAL_SERVER_ERROR;
- }
- wpabuf_free(msg);
- *replyname = NULL;
- *reply = NULL;
- return HTTP_OK;
+ struct subscription *s;
+ dl_list_for_each(s, &sm->subscriptions, struct subscription, list)
+ if (find_er_addr(s, cli))
+ return s;
+ return NULL;
}
static enum http_reply_code
-web_process_reboot_sta(struct upnp_wps_device_sm *sm, char *data,
- struct wpabuf **reply, const char **replyname)
+web_process_set_selected_registrar(struct upnp_wps_device_sm *sm,
+ struct sockaddr_in *cli, char *data,
+ struct wpabuf **reply,
+ const char **replyname)
{
struct wpabuf *msg;
enum http_reply_code ret;
+ struct subscription *s;
- wpa_printf(MSG_DEBUG, "WPS UPnP: RebootSTA");
- msg = web_get_item(data, "NewSTASettings", &ret);
- if (msg == NULL)
- return ret;
- if (!sm->ctx->rx_req_reboot_sta ||
- sm->ctx->rx_req_reboot_sta(sm->priv, msg)) {
- wpabuf_free(msg);
- return HTTP_INTERNAL_SERVER_ERROR;
+ wpa_printf(MSG_DEBUG, "WPS UPnP: SetSelectedRegistrar");
+ s = find_er(sm, cli);
+ if (s == NULL) {
+ wpa_printf(MSG_DEBUG, "WPS UPnP: Ignore SetSelectedRegistrar "
+ "from unknown ER");
+ return UPNP_ACTION_FAILED;
}
- wpabuf_free(msg);
- *replyname = NULL;
- *reply = NULL;
- return HTTP_OK;
-}
-
-
-static enum http_reply_code
-web_process_reset_sta(struct upnp_wps_device_sm *sm, char *data,
- struct wpabuf **reply, const char **replyname)
-{
- struct wpabuf *msg;
- enum http_reply_code ret;
-
- wpa_printf(MSG_DEBUG, "WPS UPnP: ResetSTA");
- msg = web_get_item(data, "NewMessage", &ret);
+ msg = xml_get_base64_item(data, "NewMessage", &ret);
if (msg == NULL)
return ret;
- if (!sm->ctx->rx_req_reset_sta ||
- sm->ctx->rx_req_reset_sta(sm->priv, msg)) {
+ if (upnp_er_set_selected_registrar(sm->wps->registrar, s, msg)) {
wpabuf_free(msg);
return HTTP_INTERNAL_SERVER_ERROR;
}
@@ -1180,7 +637,7 @@ static const char *soap_error_postfix =
"</detail>\n"
"</s:Fault>\n";
-static void web_connection_send_reply(struct web_connection *c,
+static void web_connection_send_reply(struct http_request *req,
enum http_reply_code ret,
const char *action, int action_len,
const struct wpabuf *reply,
@@ -1208,8 +665,8 @@ static void web_connection_send_reply(struct web_connection *c,
if (buf == NULL) {
wpa_printf(MSG_INFO, "WPS UPnP: Cannot allocate reply to "
"POST");
- wpabuf_free(buf);
os_free(replydata);
+ http_request_deinit(req);
return;
}
@@ -1282,13 +739,12 @@ static void web_connection_send_reply(struct web_connection *c,
os_memcpy(put_length_here, len_buf, os_strlen(len_buf));
}
- send_wpabuf(c->sd, buf);
- wpabuf_free(buf);
+ http_request_send_and_deinit(req, buf);
}
-static const char * web_get_action(struct web_connection *c,
- const char *filename, size_t *action_len)
+static const char * web_get_action(struct http_request *req,
+ size_t *action_len)
{
const char *match;
int match_len;
@@ -1296,13 +752,8 @@ static const char * web_get_action(struct web_connection *c,
char *action;
*action_len = 0;
- if (os_strcasecmp(filename, UPNP_WPS_DEVICE_CONTROL_FILE)) {
- wpa_printf(MSG_INFO, "WPS UPnP: Invalid POST filename %s",
- filename);
- return NULL;
- }
/* The SOAPAction line of the header tells us what we want to do */
- b = httpread_hdr_line_get(c->hread, "SOAPAction:");
+ b = http_request_get_hdr_line(req, "SOAPAction:");
if (b == NULL)
return NULL;
if (*b == '"')
@@ -1349,70 +800,47 @@ static const char * web_get_action(struct web_connection *c,
* Per RFC 2616, content-length: is not required but connection:close
* would appear to be required (given that we will be closing it!).
*/
-static void web_connection_parse_post(struct web_connection *c,
+static void web_connection_parse_post(struct upnp_wps_device_sm *sm,
+ struct sockaddr_in *cli,
+ struct http_request *req,
const char *filename)
{
enum http_reply_code ret;
- struct upnp_wps_device_sm *sm = c->sm;
- char *data = httpread_data_get(c->hread); /* body of http msg */
- const char *action;
- size_t action_len;
+ char *data = http_request_get_data(req); /* body of http msg */
+ const char *action = NULL;
+ size_t action_len = 0;
const char *replyname = NULL; /* argument name for the reply */
struct wpabuf *reply = NULL; /* data for the reply */
+ if (os_strcasecmp(filename, UPNP_WPS_DEVICE_CONTROL_FILE)) {
+ wpa_printf(MSG_INFO, "WPS UPnP: Invalid POST filename %s",
+ filename);
+ ret = HTTP_NOT_FOUND;
+ goto bad;
+ }
+
ret = UPNP_INVALID_ACTION;
- action = web_get_action(c, filename, &action_len);
+ action = web_get_action(req, &action_len);
if (action == NULL)
goto bad;
- /*
- * There are quite a few possible actions. Although we appear to
- * support them all here, not all of them are necessarily supported by
- * callbacks at higher levels.
- */
if (!os_strncasecmp("GetDeviceInfo", action, action_len))
ret = web_process_get_device_info(sm, &reply, &replyname);
else if (!os_strncasecmp("PutMessage", action, action_len))
ret = web_process_put_message(sm, data, &reply, &replyname);
- else if (!os_strncasecmp("GetAPSettings", action, action_len))
- ret = web_process_get_ap_settings(sm, data, &reply,
- &replyname);
- else if (!os_strncasecmp("SetAPSettings", action, action_len))
- ret = web_process_set_ap_settings(sm, data, &reply,
- &replyname);
- else if (!os_strncasecmp("DelAPSettings", action, action_len))
- ret = web_process_del_ap_settings(sm, data, &reply,
- &replyname);
- else if (!os_strncasecmp("GetSTASettings", action, action_len))
- ret = web_process_get_sta_settings(sm, data, &reply,
- &replyname);
- else if (!os_strncasecmp("SetSTASettings", action, action_len))
- ret = web_process_set_sta_settings(sm, data, &reply,
- &replyname);
- else if (!os_strncasecmp("DelSTASettings", action, action_len))
- ret = web_process_del_sta_settings(sm, data, &reply,
- &replyname);
else if (!os_strncasecmp("PutWLANResponse", action, action_len))
ret = web_process_put_wlan_response(sm, data, &reply,
&replyname);
else if (!os_strncasecmp("SetSelectedRegistrar", action, action_len))
- ret = web_process_set_selected_registrar(sm, data, &reply,
+ ret = web_process_set_selected_registrar(sm, cli, data, &reply,
&replyname);
- else if (!os_strncasecmp("RebootAP", action, action_len))
- ret = web_process_reboot_ap(sm, data, &reply, &replyname);
- else if (!os_strncasecmp("ResetAP", action, action_len))
- ret = web_process_reset_ap(sm, data, &reply, &replyname);
- else if (!os_strncasecmp("RebootSTA", action, action_len))
- ret = web_process_reboot_sta(sm, data, &reply, &replyname);
- else if (!os_strncasecmp("ResetSTA", action, action_len))
- ret = web_process_reset_sta(sm, data, &reply, &replyname);
else
wpa_printf(MSG_INFO, "WPS UPnP: Unknown POST type");
bad:
if (ret != HTTP_OK)
wpa_printf(MSG_INFO, "WPS UPnP: POST failure ret=%d", ret);
- web_connection_send_reply(c, ret, action, action_len, reply,
+ web_connection_send_reply(req, ret, action, action_len, reply,
replyname);
wpabuf_free(reply);
}
@@ -1437,13 +865,13 @@ bad:
* Per RFC 2616, content-length: is not required but connection:close
* would appear to be required (given that we will be closing it!).
*/
-static void web_connection_parse_subscribe(struct web_connection *c,
+static void web_connection_parse_subscribe(struct upnp_wps_device_sm *sm,
+ struct http_request *req,
const char *filename)
{
- struct upnp_wps_device_sm *sm = c->sm;
struct wpabuf *buf;
char *b;
- char *hdr = httpread_hdr_get(c->hread);
+ char *hdr = http_request_get_hdr(req);
char *h;
char *match;
int match_len;
@@ -1457,8 +885,10 @@ static void web_connection_parse_subscribe(struct web_connection *c,
enum http_reply_code ret = HTTP_INTERNAL_SERVER_ERROR;
buf = wpabuf_alloc(1000);
- if (buf == NULL)
+ if (buf == NULL) {
+ http_request_deinit(req);
return;
+ }
/* Parse/validate headers */
h = hdr;
@@ -1599,9 +1029,8 @@ static void web_connection_parse_subscribe(struct web_connection *c,
/* And empty line to terminate header: */
wpabuf_put_str(buf, "\r\n");
- send_wpabuf(c->sd, buf);
- wpabuf_free(buf);
os_free(callback_urls);
+ http_request_send_and_deinit(req, buf);
return;
error:
@@ -1627,8 +1056,7 @@ error:
* 599 Too many subscriptions (not a standard HTTP error)
*/
http_put_empty(buf, ret);
- send_wpabuf(c->sd, buf);
- wpabuf_free(buf);
+ http_request_send_and_deinit(req, buf);
os_free(callback_urls);
}
@@ -1648,12 +1076,12 @@ error:
* Per RFC 2616, content-length: is not required but connection:close
* would appear to be required (given that we will be closing it!).
*/
-static void web_connection_parse_unsubscribe(struct web_connection *c,
+static void web_connection_parse_unsubscribe(struct upnp_wps_device_sm *sm,
+ struct http_request *req,
const char *filename)
{
- struct upnp_wps_device_sm *sm = c->sm;
struct wpabuf *buf;
- char *hdr = httpread_hdr_get(c->hread);
+ char *hdr = http_request_get_hdr(req);
char *h;
char *match;
int match_len;
@@ -1721,12 +1149,13 @@ static void web_connection_parse_unsubscribe(struct web_connection *c,
if (got_uuid) {
s = subscription_find(sm, uuid);
if (s) {
+ struct subscr_addr *sa;
+ sa = dl_list_first(&s->addr_list, struct subscr_addr,
+ list);
wpa_printf(MSG_DEBUG, "WPS UPnP: Unsubscribing %p %s",
- s,
- (s && s->addr_list &&
- s->addr_list->domain_and_port) ?
- s->addr_list->domain_and_port : "-null-");
- subscription_unlink(s);
+ s, (sa && sa->domain_and_port) ?
+ sa->domain_and_port : "-null-");
+ dl_list_del(&s->list);
subscription_destroy(s);
}
} else {
@@ -1740,40 +1169,42 @@ static void web_connection_parse_unsubscribe(struct web_connection *c,
send_msg:
buf = wpabuf_alloc(200);
- if (buf == NULL)
+ if (buf == NULL) {
+ http_request_deinit(req);
return;
+ }
http_put_empty(buf, ret);
- send_wpabuf(c->sd, buf);
- wpabuf_free(buf);
+ http_request_send_and_deinit(req, buf);
}
/* Send error in response to unknown requests */
-static void web_connection_unimplemented(struct web_connection *c)
+static void web_connection_unimplemented(struct http_request *req)
{
struct wpabuf *buf;
buf = wpabuf_alloc(200);
- if (buf == NULL)
+ if (buf == NULL) {
+ http_request_deinit(req);
return;
+ }
http_put_empty(buf, HTTP_UNIMPLEMENTED);
- send_wpabuf(c->sd, buf);
- wpabuf_free(buf);
+ http_request_send_and_deinit(req, buf);
}
/* Called when we have gotten an apparently valid http request.
*/
-static void web_connection_check_data(struct web_connection *c)
+static void web_connection_check_data(void *ctx, struct http_request *req)
{
- struct httpread *hread = c->hread;
- enum httpread_hdr_type htype = httpread_hdr_type_get(hread);
- /* char *data = httpread_data_get(hread); */
- char *filename = httpread_uri_get(hread);
+ struct upnp_wps_device_sm *sm = ctx;
+ enum httpread_hdr_type htype = http_request_get_type(req);
+ char *filename = http_request_get_uri(req);
+ struct sockaddr_in *cli = http_request_get_cli_addr(req);
- c->done = 1;
if (!filename) {
wpa_printf(MSG_INFO, "WPS UPnP: Could not get HTTP URI");
+ http_request_deinit(req);
return;
}
/* Trim leading slashes from filename */
@@ -1781,22 +1212,22 @@ static void web_connection_check_data(struct web_connection *c)
filename++;
wpa_printf(MSG_DEBUG, "WPS UPnP: Got HTTP request type %d from %s:%d",
- htype, inet_ntoa(c->cli_addr.sin_addr),
- htons(c->cli_addr.sin_port));
+ htype, inet_ntoa(cli->sin_addr), htons(cli->sin_port));
switch (htype) {
case HTTPREAD_HDR_TYPE_GET:
- web_connection_parse_get(c, filename);
+ web_connection_parse_get(sm, req, filename);
break;
case HTTPREAD_HDR_TYPE_POST:
- web_connection_parse_post(c, filename);
+ web_connection_parse_post(sm, cli, req, filename);
break;
case HTTPREAD_HDR_TYPE_SUBSCRIBE:
- web_connection_parse_subscribe(c, filename);
+ web_connection_parse_subscribe(sm, req, filename);
break;
case HTTPREAD_HDR_TYPE_UNSUBSCRIBE:
- web_connection_parse_unsubscribe(c, filename);
+ web_connection_parse_unsubscribe(sm, req, filename);
break;
+
/* We are not required to support M-POST; just plain
* POST is supposed to work, so we only support that.
* If for some reason we need to support M-POST, it is
@@ -1804,82 +1235,12 @@ static void web_connection_check_data(struct web_connection *c)
*/
default:
/* Send 501 for anything else */
- web_connection_unimplemented(c);
+ web_connection_unimplemented(req);
break;
}
}
-
-/* called back when we have gotten request */
-static void web_connection_got_file_handler(struct httpread *handle,
- void *cookie,
- enum httpread_event en)
-{
- struct web_connection *c = cookie;
-
- if (en == HTTPREAD_EVENT_FILE_READY)
- web_connection_check_data(c);
- web_connection_stop(c);
-}
-
-
-/* web_connection_start - Start web connection
- * @sm: WPS UPnP state machine from upnp_wps_device_init()
- * @sd: Socket descriptor
- * @addr: Client address
- *
- * The socket descriptor sd is handed over for ownership by the WPS UPnP
- * state machine.
- */
-static void web_connection_start(struct upnp_wps_device_sm *sm,
- int sd, struct sockaddr_in *addr)
-{
- struct web_connection *c = NULL;
-
- /* if too many connections, bail */
- if (sm->n_web_connections >= MAX_WEB_CONNECTIONS) {
- close(sd);
- return;
- }
-
- c = os_zalloc(sizeof(*c));
- if (c == NULL)
- return;
- os_memcpy(&c->cli_addr, addr, sizeof(c->cli_addr));
- c->sm = sm;
- c->sd = sd;
-#if 0
- /*
- * Setting non-blocking should not be necessary for read, and can mess
- * up sending where blocking might be better.
- */
- if (fcntl(sd, F_SETFL, O_NONBLOCK) != 0)
- break;
-#endif
- c->hread = httpread_create(c->sd, web_connection_got_file_handler,
- c /* cookie */,
- WEB_CONNECTION_MAX_READ,
- WEB_CONNECTION_TIMEOUT_SEC);
- if (c->hread == NULL)
- goto fail;
- if (sm->web_connections) {
- c->next = sm->web_connections;
- c->prev = c->next->prev;
- c->prev->next = c;
- c->next->prev = c;
- } else {
- sm->web_connections = c->next = c->prev = c;
- }
- sm->n_web_connections++;
- return;
-
-fail:
- if (c)
- web_connection_stop(c);
-}
-
-
/*
* Listening for web connections
* We have a single TCP listening port, and hand off connections as we get
@@ -1888,77 +1249,22 @@ fail:
void web_listener_stop(struct upnp_wps_device_sm *sm)
{
- if (sm->web_sd_registered) {
- sm->web_sd_registered = 0;
- eloop_unregister_sock(sm->web_sd, EVENT_TYPE_READ);
- }
- if (sm->web_sd >= 0)
- close(sm->web_sd);
- sm->web_sd = -1;
-}
-
-
-static void web_listener_handler(int sd, void *eloop_ctx, void *sock_ctx)
-{
- struct sockaddr_in addr;
- socklen_t addr_len = sizeof(addr);
- struct upnp_wps_device_sm *sm = sock_ctx;
- int new_sd;
-
- /* Create state for new connection */
- /* Remember so we can cancel if need be */
- new_sd = accept(sm->web_sd, (struct sockaddr *) &addr, &addr_len);
- if (new_sd < 0) {
- wpa_printf(MSG_ERROR, "WPS UPnP: web listener accept "
- "errno=%d (%s) web_sd=%d",
- errno, strerror(errno), sm->web_sd);
- return;
- }
- web_connection_start(sm, new_sd, &addr);
+ http_server_deinit(sm->web_srv);
+ sm->web_srv = NULL;
}
int web_listener_start(struct upnp_wps_device_sm *sm)
{
- struct sockaddr_in addr;
- int port;
-
- sm->web_sd = socket(AF_INET, SOCK_STREAM, 0);
- if (sm->web_sd < 0)
- goto fail;
- if (fcntl(sm->web_sd, F_SETFL, O_NONBLOCK) != 0)
- goto fail;
- port = 49152; /* first non-reserved port */
- for (;;) {
- os_memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_addr.s_addr = sm->ip_addr;
- addr.sin_port = htons(port);
- if (bind(sm->web_sd, (struct sockaddr *) &addr,
- sizeof(addr)) == 0)
- break;
- if (errno == EADDRINUSE) {
- /* search for unused port */
- if (++port == 65535)
- goto fail;
- continue;
- }
- goto fail;
+ struct in_addr addr;
+ addr.s_addr = sm->ip_addr;
+ sm->web_srv = http_server_init(&addr, -1, web_connection_check_data,
+ sm);
+ if (sm->web_srv == NULL) {
+ web_listener_stop(sm);
+ return -1;
}
- if (listen(sm->web_sd, 10 /* max backlog */) != 0)
- goto fail;
- if (fcntl(sm->web_sd, F_SETFL, O_NONBLOCK) != 0)
- goto fail;
- if (eloop_register_sock(sm->web_sd, EVENT_TYPE_READ,
- web_listener_handler, NULL, sm))
- goto fail;
- sm->web_sd_registered = 1;
- sm->web_port = port;
+ sm->web_port = http_server_get_port(sm->web_srv);
return 0;
-
-fail:
- /* Error */
- web_listener_stop(sm);
- return -1;
}
diff --git a/contrib/wpa/wpa_supplicant/.gitignore b/contrib/wpa/wpa_supplicant/.gitignore
new file mode 100644
index 0000000..e7e034c
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/.gitignore
@@ -0,0 +1,8 @@
+*.d
+.config
+eapol_test
+preauth_test
+wpa_cli
+wpa_passphrase
+wpa_supplicant
+wpa_priv
diff --git a/contrib/wpa/wpa_supplicant/ChangeLog b/contrib/wpa/wpa_supplicant/ChangeLog
index ab99514..56046c3 100644
--- a/contrib/wpa/wpa_supplicant/ChangeLog
+++ b/contrib/wpa/wpa_supplicant/ChangeLog
@@ -1,33 +1,151 @@
ChangeLog for wpa_supplicant
-2010-01-12 - v0.6.10
- * fixed SHA-256 based key derivation function to match with the
- standard when using CCMP (for IEEE 802.11r and IEEE 802.11w)
- (note: this breaks interoperability with previous version) [Bug 307]
- * changed driver_wext to disconnect at init/deinit to clear state
- * added explicit disconnect on 4-way handshake failures
- * added WPS workarounds for known interoperability issues with broken,
- deployed implementation
- * update IEEE 802.11w implementation to match with the published
- standard
- * do not send WPS M8 message when learning current AP configuration as
- an external Registrar
- * added a workaround for race condition between receive EAPOL frames
- and association events
- * fixed compilation with newer GnuTLS versions
- * fixed PKCS#12 use with OpenSSL 1.0.0
+2010-09-07 - v0.7.3
+ * fixed fallback from failed PMKSA caching into full EAP authentication
+ [Bug 355]
+ * fixed issue with early D-Bus signals during initialization
+ * fixed X.509 name handling in internal TLS
+ * fixed WPS ER to use corrent Enrollee MAC Address in Credential
+ * fixed scanning routines ot improve AP selection for WPS
+ * added WPS workaround for open networks
+ * fixed WPS Diffie-Hellman derivation to use correct public key length
+ * fixed wpa_supplicant AP mode operations to ignore Supplicant and
+ scan result events
+ * improved SME operations with nl80211
+ * fixed WPS ER event_id handling in some cases
+ * fixed some issues with bgscan simple to avoid unnecessary scans
+ * fixed issue with l2_packet_ndis overlapped writes corrupting stack
+ [Bug 328]
+ * updated WinPcap to the latest stable version 4.1.2 in Windows
+ installer
-2009-03-23 - v0.6.9
- * driver_ndis: add PAE group address to the multicast address list to
- fix wired IEEE 802.1X authentication
- * fixed IEEE 802.11r key derivation function to match with the standard
- (note: this breaks interoperability with previous version) [Bug 303]
+2010-04-18 - v0.7.2
+ * nl80211: fixed number of issues with roaming
+ * avoid unnecessary roaming if multiple APs with similar signal
+ strength are present in scan results
+ * add TLS client events and server probing to ease design of
+ automatic detection of EAP parameters
+ * add option for server certificate matching (SHA256 hash of the
+ certificate) instead of trusted CA certificate configuration
+ * bsd: Cleaned up driver wrapper and added various low-level
+ configuration options
+ * wpa_gui-qt4: do not show too frequent WPS AP available events as
+ tray messages
+ * TNC: fixed issues with fragmentation
+ * EAP-TNC: add Flags field into fragment acknowledgement (needed to
+ interoperate with other implementations; may potentially breaks
+ compatibility with older wpa_supplicant/hostapd versions)
+ * wpa_cli: added option for using a separate process to receive event
+ messages to reduce latency in showing these
+ (CFLAGS += -DCONFIG_WPA_CLI_FORK=y in .config to enable this)
+ * maximum BSS table size can now be configured (bss_max_count)
+ * BSSes to be included in the BSS table can be filtered based on
+ configured SSIDs to save memory (filter_ssids)
+ * fix number of issues with IEEE 802.11r/FT; this version is not
+ backwards compatible with old versions
+ * nl80211: add support for IEEE 802.11r/FT protocol (both over-the-air
+ and over-the-DS)
+ * add freq_list network configuration parameter to allow the AP
+ selection to filter out entries based on the operating channel
+ * add signal strength change events for bgscan; this allows more
+ dynamic changes to background scanning interval based on changes in
+ the signal strength with the current AP; this improves roaming within
+ ESS quite a bit, e.g., with bgscan="simple:30:-45:300" in the network
+ configuration block to request background scans less frequently when
+ signal strength remains good and to automatically trigger background
+ scans whenever signal strength drops noticeably
+ (this is currently only available with nl80211)
+ * add BSSID and reason code (if available) to disconnect event messages
+ * wpa_gui-qt4: more complete support for translating the GUI with
+ linguist and add German translation
+ * fix DH padding with internal crypto code (mainly, for WPS)
+ * do not trigger initial scan automatically anymore if there are no
+ enabled networks
-2009-02-15 - v0.6.8
+2010-01-16 - v0.7.1
+ * cleaned up driver wrapper API (struct wpa_driver_ops); the new API
+ is not fully backwards compatible, so out-of-tree driver wrappers
+ will need modifications
+ * cleaned up various module interfaces
+ * merge hostapd and wpa_supplicant developers' documentation into a
+ single document
+ * nl80211: use explicit deauthentication to clear cfg80211 state to
+ avoid issues when roaming between APs
+ * dbus: major design changes in the new D-Bus API
+ (fi.w1.wpa_supplicant1)
+ * nl80211: added support for IBSS networks
+ * added internal debugging mechanism with backtrace support and memory
+ allocation/freeing validation, etc. tests (CONFIG_WPA_TRACE=y)
+ * added WPS ER unsubscription command to more cleanly unregister from
+ receiving UPnP events when ER is terminated
+ * cleaned up AP mode operations to avoid need for virtual driver_ops
+ wrapper
+ * added BSS table to maintain more complete scan result information
+ over multiple scans (that may include only partial results)
+ * wpa_gui-qt4: update Peers dialog information more dynamically while
+ the dialog is kept open
+ * fixed PKCS#12 use with OpenSSL 1.0.0
+ * driver_wext: Added cfg80211-specific optimization to avoid some
+ unnecessary scans and to speed up association
+
+2009-11-21 - v0.7.0
* increased wpa_cli ping interval to 5 seconds and made this
configurable with a new command line options (-G<seconds>)
* fixed scan buffer processing with WEXT to handle up to 65535
byte result buffer (previously, limited to 32768 bytes)
+ * allow multiple driver wrappers to be specified on command line
+ (e.g., -Dnl80211,wext); the first one that is able to initialize the
+ interface will be used
+ * added support for multiple SSIDs per scan request to optimize
+ scan_ssid=1 operations in ap_scan=1 mode (i.e., search for hidden
+ SSIDs); this requires driver support and can currently be used only
+ with nl80211
+ * added support for WPS USBA out-of-band mechanism with USB Flash
+ Drives (UFD) (CONFIG_WPS_UFD=y)
+ * driver_ndis: add PAE group address to the multicast address list to
+ fix wired IEEE 802.1X authentication
+ * fixed IEEE 802.11r key derivation function to match with the standard
+ (note: this breaks interoperability with previous version) [Bug 303]
+ * added better support for drivers that allow separate authentication
+ and association commands (e.g., mac80211-based Linux drivers with
+ nl80211; SME in wpa_supplicant); this allows over-the-air FT protocol
+ to be used (IEEE 802.11r)
+ * fixed SHA-256 based key derivation function to match with the
+ standard when using CCMP (for IEEE 802.11r and IEEE 802.11w)
+ (note: this breaks interoperability with previous version) [Bug 307]
+ * use shared driver wrapper files with hostapd
+ * added AP mode functionality (CONFIG_AP=y) with mode=2 in the network
+ block; this can be used for open and WPA2-Personal networks
+ (optionally, with WPS); this links in parts of hostapd functionality
+ into wpa_supplicant
+ * wpa_gui-qt4: added new Peers dialog to show information about peers
+ (other devices, including APs and stations, etc. in the neighborhood)
+ * added support for WPS External Registrar functionality (configure APs
+ and enroll new devices); can be used with wpa_gui-qt4 Peers dialog
+ and wpa_cli commands wps_er_start, wps_er_stop, wps_er_pin,
+ wps_er_pbc, wps_er_learn
+ (this can also be used with a new 'none' driver wrapper if no
+ wireless device or IEEE 802.1X on wired is needed)
+ * driver_nl80211: multiple updates to provide support for new Linux
+ nl80211/mac80211 functionality
+ * updated management frame protection to use IEEE Std 802.11w-2009
+ * fixed number of small WPS issues and added workarounds to
+ interoperate with common deployed broken implementations
+ * added support for NFC out-of-band mechanism with WPS
+ * driver_ndis: fixed wired IEEE 802.1X authentication with PAE group
+ address frames
+ * added preliminary support for IEEE 802.11r RIC processing
+ * added support for specifying subset of enabled frequencies to scan
+ (scan_freq option in the network configuration block); this can speed
+ up scanning process considerably if it is known that only a small
+ subset of channels is actually used in the network (this is currently
+ supported only with -Dnl80211)
+ * added a workaround for race condition between receiving the
+ association event and the following EAPOL-Key
+ * added background scan and roaming infrastructure to allow
+ network-specific optimizations to be used to improve roaming within
+ an ESS (same SSID)
+ * added new DBus interface (fi.w1.wpa_supplicant1)
2009-01-06 - v0.6.7
* added support for Wi-Fi Protected Setup (WPS)
diff --git a/contrib/wpa/wpa_supplicant/Makefile b/contrib/wpa/wpa_supplicant/Makefile
index 5a88fb3..1d25623 100644
--- a/contrib/wpa/wpa_supplicant/Makefile
+++ b/contrib/wpa/wpa_supplicant/Makefile
@@ -10,10 +10,7 @@ export LIBDIR ?= /usr/local/lib/
export BINDIR ?= /usr/local/sbin/
CFLAGS += -I../src
-CFLAGS += -I../src/crypto
CFLAGS += -I../src/utils
-CFLAGS += -I../src/common
-CFLAGS += -I../src/rsn_supp
ALL=wpa_supplicant wpa_passphrase wpa_cli
@@ -29,7 +26,7 @@ verify_config:
fi
mkconfig:
- @if [ -e .config ]; then \
+ @if [ -f .config ]; then \
echo '.config exists - did not replace it'; \
exit 1; \
fi
@@ -42,21 +39,16 @@ install: all
$(MAKE) -C ../src install
OBJS = config.o
+OBJS += notify.o
+OBJS += bss.o
+OBJS += eap_register.o
OBJS += ../src/utils/common.o
OBJS += ../src/utils/wpa_debug.o
OBJS += ../src/utils/wpabuf.o
-OBJS += ../src/crypto/md5.o
-OBJS += ../src/crypto/rc4.o
-OBJS += ../src/crypto/md4.o
-OBJS += ../src/crypto/sha1.o
-OBJS += ../src/crypto/des.o
OBJS_p = wpa_passphrase.o
OBJS_p += ../src/utils/common.o
OBJS_p += ../src/utils/wpa_debug.o
-OBJS_p += ../src/crypto/md5.o
-OBJS_p += ../src/crypto/md4.o
-OBJS_p += ../src/crypto/sha1.o
-OBJS_p += ../src/crypto/des.o
+OBJS_p += ../src/utils/wpabuf.o
OBJS_c = wpa_cli.o ../src/common/wpa_ctrl.o
-include .config
@@ -77,6 +69,22 @@ OBJS += ../src/utils/os_$(CONFIG_OS).o
OBJS_p += ../src/utils/os_$(CONFIG_OS).o
OBJS_c += ../src/utils/os_$(CONFIG_OS).o
+ifdef CONFIG_WPA_TRACE
+CFLAGS += -DWPA_TRACE
+OBJS += ../src/utils/trace.o
+OBJS_p += ../src/utils/trace.o
+OBJS_c += ../src/utils/trace.o
+OBJS_c += ../src/utils/wpa_debug.o
+LDFLAGS += -rdynamic
+CFLAGS += -funwind-tables
+ifdef CONFIG_WPA_TRACE_BFD
+CFLAGS += -DWPA_TRACE_BFD
+LIBS += -lbfd
+LIBS_p += -lbfd
+LIBS_c += -lbfd
+endif
+endif
+
ifndef CONFIG_ELOOP
CONFIG_ELOOP=eloop
endif
@@ -119,128 +127,61 @@ ifdef CONFIG_NO_SCAN_PROCESSING
CFLAGS += -DCONFIG_NO_SCAN_PROCESSING
endif
-ifdef CONFIG_DRIVER_HOSTAP
-CFLAGS += -DCONFIG_DRIVER_HOSTAP
-OBJS_d += ../src/drivers/driver_hostap.o
-CONFIG_WIRELESS_EXTENSION=y
-endif
-
-ifdef CONFIG_DRIVER_WEXT
-CFLAGS += -DCONFIG_DRIVER_WEXT
-CONFIG_WIRELESS_EXTENSION=y
-endif
-
-ifdef CONFIG_DRIVER_NL80211
-CFLAGS += -DCONFIG_DRIVER_NL80211
-OBJS_d += ../src/drivers/driver_nl80211.o
-LIBS += -lnl
-ifdef CONFIG_CLIENT_MLME
-OBJS_d += ../src/drivers/radiotap.o
-endif
-endif
-
-ifdef CONFIG_DRIVER_PRISM54
-CFLAGS += -DCONFIG_DRIVER_PRISM54
-OBJS_d += ../src/drivers/driver_prism54.o
-CONFIG_WIRELESS_EXTENSION=y
-endif
-
-ifdef CONFIG_DRIVER_HERMES
-CFLAGS += -DCONFIG_DRIVER_HERMES
-OBJS_d += ../src/drivers/driver_hermes.o
-CONFIG_WIRELESS_EXTENSION=y
-endif
-
-ifdef CONFIG_DRIVER_MADWIFI
-CFLAGS += -DCONFIG_DRIVER_MADWIFI
-OBJS_d += ../src/drivers/driver_madwifi.o
-CONFIG_WIRELESS_EXTENSION=y
-endif
-
-ifdef CONFIG_DRIVER_ATMEL
-CFLAGS += -DCONFIG_DRIVER_ATMEL
-OBJS_d += ../src/drivers/driver_atmel.o
-CONFIG_WIRELESS_EXTENSION=y
-endif
-
-ifdef CONFIG_DRIVER_NDISWRAPPER
-CFLAGS += -DCONFIG_DRIVER_NDISWRAPPER
-OBJS_d += ../src/drivers/driver_ndiswrapper.o
-CONFIG_WIRELESS_EXTENSION=y
-endif
-
-ifdef CONFIG_DRIVER_RALINK
-CFLAGS += -DCONFIG_DRIVER_RALINK
-OBJS_d += ../src/drivers/driver_ralink.o
-endif
-
-ifdef CONFIG_DRIVER_BROADCOM
-CFLAGS += -DCONFIG_DRIVER_BROADCOM
-OBJS_d += ../src/drivers/driver_broadcom.o
-endif
-
-ifdef CONFIG_DRIVER_IPW
-CFLAGS += -DCONFIG_DRIVER_IPW
-OBJS_d += ../src/drivers/driver_ipw.o
-CONFIG_WIRELESS_EXTENSION=y
-endif
-
-ifdef CONFIG_DRIVER_BSD
-CFLAGS += -DCONFIG_DRIVER_BSD
-OBJS_d += ../src/drivers/driver_bsd.o
-ifndef CONFIG_L2_PACKET
-CONFIG_L2_PACKET=freebsd
-endif
-endif
-
-ifdef CONFIG_DRIVER_NDIS
-CFLAGS += -DCONFIG_DRIVER_NDIS
-OBJS_d += ../src/drivers/driver_ndis.o
-ifdef CONFIG_NDIS_EVENTS_INTEGRATED
-OBJS_d += ../src/drivers/driver_ndis_.o
-endif
-ifndef CONFIG_L2_PACKET
-CONFIG_L2_PACKET=pcap
-endif
-CONFIG_WINPCAP=y
-ifdef CONFIG_USE_NDISUIO
-CFLAGS += -DCONFIG_USE_NDISUIO
-endif
+ifdef CONFIG_IEEE80211W
+CFLAGS += -DCONFIG_IEEE80211W
+NEED_SHA256=y
+NEED_AES_OMAC1=y
endif
-ifdef CONFIG_DRIVER_WIRED
-CFLAGS += -DCONFIG_DRIVER_WIRED
-OBJS_d += ../src/drivers/driver_wired.o
+ifdef CONFIG_IEEE80211R
+CFLAGS += -DCONFIG_IEEE80211R
+OBJS += ../src/rsn_supp/wpa_ft.o
+NEED_80211_COMMON=y
+NEED_SHA256=y
+NEED_AES_OMAC1=y
endif
-ifdef CONFIG_DRIVER_TEST
-CFLAGS += -DCONFIG_DRIVER_TEST
-OBJS_d += ../src/drivers/driver_test.o
+ifdef CONFIG_PEERKEY
+CFLAGS += -DCONFIG_PEERKEY
endif
-ifdef CONFIG_DRIVER_OSX
-CFLAGS += -DCONFIG_DRIVER_OSX
-OBJS_d += ../src/drivers/driver_osx.o
-LDFLAGS += -framework CoreFoundation
-LDFLAGS += -F/System/Library/PrivateFrameworks -framework Apple80211
+ifndef CONFIG_NO_WPA
+OBJS += ../src/rsn_supp/wpa.o
+OBJS += ../src/rsn_supp/preauth.o
+OBJS += ../src/rsn_supp/pmksa_cache.o
+OBJS += ../src/rsn_supp/peerkey.o
+OBJS += ../src/rsn_supp/wpa_ie.o
+OBJS += ../src/common/wpa_common.o
+NEED_AES=y
+NEED_SHA1=y
+NEED_MD5=y
+NEED_RC4=y
+else
+CFLAGS += -DCONFIG_NO_WPA -DCONFIG_NO_WPA2
endif
-ifdef CONFIG_DRIVER_PS3
-CFLAGS += -DCONFIG_DRIVER_PS3 -m64
-OBJS_d += ../src/drivers/driver_ps3.o
-LDFLAGS += -m64
+ifdef CONFIG_IBSS_RSN
+NEED_RSN_AUTHENTICATOR=y
+CFLAGS += -DCONFIG_IBSS_RSN
+OBJS += ibss_rsn.o
endif
-ifdef CONFIG_DRIVER_IPHONE
-CFLAGS += -DCONFIG_DRIVER_IPHONE
-OBJS_d += ../src/drivers/driver_iphone.o
-OBJS_d += ../src/drivers/MobileApple80211.o
-LIBS += -framework CoreFoundation
+ifdef CONFIG_NO_WPA2
+CFLAGS += -DCONFIG_NO_WPA2
endif
-ifdef CONFIG_DRIVER_ROBOSWITCH
-CFLAGS += -DCONFIG_DRIVER_ROBOSWITCH
-OBJS_d += ../src/drivers/driver_roboswitch.o
+include ../src/drivers/drivers.mak
+ifdef CONFIG_AP
+OBJS_d += $(DRV_BOTH_OBJS)
+CFLAGS += $(DRV_BOTH_CFLAGS)
+LDFLAGS += $(DRV_BOTH_LDFLAGS)
+LIBS += $(DRV_BOTH_LIBS)
+else
+NEED_AP_MLME=
+OBJS_d += $(DRV_WPA_OBJS)
+CFLAGS += $(DRV_WPA_CFLAGS)
+LDFLAGS += $(DRV_WPA_LDFLAGS)
+LIBS += $(DRV_WPA_LIBS)
endif
ifndef CONFIG_L2_PACKET
@@ -276,7 +217,7 @@ EAPDYN += ../src/eap_peer/eap_tls.so
else
CFLAGS += -DEAP_TLS
OBJS += ../src/eap_peer/eap_tls.o
-OBJS_h += ../src/eap_server/eap_tls.o
+OBJS_h += ../src/eap_server/eap_server_tls.o
endif
TLS_FUNCS=y
CONFIG_IEEE8021X_EAPOL=y
@@ -291,7 +232,7 @@ else
CFLAGS += -DEAP_PEAP
OBJS += ../src/eap_peer/eap_peap.o
OBJS += ../src/eap_common/eap_peap_common.o
-OBJS_h += ../src/eap_server/eap_peap.o
+OBJS_h += ../src/eap_server/eap_server_peap.o
endif
TLS_FUNCS=y
CONFIG_IEEE8021X_EAPOL=y
@@ -305,7 +246,7 @@ EAPDYN += ../src/eap_peer/eap_ttls.so
else
CFLAGS += -DEAP_TTLS
OBJS += ../src/eap_peer/eap_ttls.o
-OBJS_h += ../src/eap_server/eap_ttls.o
+OBJS_h += ../src/eap_server/eap_server_ttls.o
endif
MS_FUNCS=y
TLS_FUNCS=y
@@ -321,7 +262,7 @@ EAPDYN += ../src/eap_peer/eap_md5.so
else
CFLAGS += -DEAP_MD5
OBJS += ../src/eap_peer/eap_md5.o
-OBJS_h += ../src/eap_server/eap_md5.o
+OBJS_h += ../src/eap_server/eap_server_md5.o
endif
CHAP=y
CONFIG_IEEE8021X_EAPOL=y
@@ -344,7 +285,7 @@ else
CFLAGS += -DEAP_MSCHAPv2
OBJS += ../src/eap_peer/eap_mschapv2.o
OBJS += ../src/eap_peer/mschapv2.o
-OBJS_h += ../src/eap_server/eap_mschapv2.o
+OBJS_h += ../src/eap_server/eap_server_mschapv2.o
endif
MS_FUNCS=y
CONFIG_IEEE8021X_EAPOL=y
@@ -358,7 +299,7 @@ EAPDYN += ../src/eap_peer/eap_gtc.so
else
CFLAGS += -DEAP_GTC
OBJS += ../src/eap_peer/eap_gtc.o
-OBJS_h += ../src/eap_server/eap_gtc.o
+OBJS_h += ../src/eap_server/eap_server_gtc.o
endif
CONFIG_IEEE8021X_EAPOL=y
endif
@@ -383,10 +324,11 @@ EAPDYN += ../src/eap_peer/eap_sim.so
else
CFLAGS += -DEAP_SIM
OBJS += ../src/eap_peer/eap_sim.o
-OBJS_h += ../src/eap_server/eap_sim.o
+OBJS_h += ../src/eap_server/eap_server_sim.o
endif
CONFIG_IEEE8021X_EAPOL=y
CONFIG_EAP_SIM_COMMON=y
+NEED_AES_CBC=y
endif
ifdef CONFIG_EAP_LEAP
@@ -410,10 +352,13 @@ EAPDYN += ../src/eap_peer/eap_psk.so
else
CFLAGS += -DEAP_PSK
OBJS += ../src/eap_peer/eap_psk.o ../src/eap_common/eap_psk_common.o
-OBJS_h += ../src/eap_server/eap_psk.o
+OBJS_h += ../src/eap_server/eap_server_psk.o
endif
CONFIG_IEEE8021X_EAPOL=y
NEED_AES=y
+NEED_AES_OMAC1=y
+NEED_AES_ENCBLOCK=y
+NEED_AES_EAX=y
endif
ifdef CONFIG_EAP_AKA
@@ -424,10 +369,11 @@ EAPDYN += ../src/eap_peer/eap_aka.so
else
CFLAGS += -DEAP_AKA
OBJS += ../src/eap_peer/eap_aka.o
-OBJS_h += ../src/eap_server/eap_aka.o
+OBJS_h += ../src/eap_server/eap_server_aka.o
endif
CONFIG_IEEE8021X_EAPOL=y
CONFIG_EAP_SIM_COMMON=y
+NEED_AES_CBC=y
endif
ifdef CONFIG_EAP_AKA_PRIME
@@ -457,7 +403,7 @@ else
CFLAGS += -DEAP_FAST
OBJS += ../src/eap_peer/eap_fast.o ../src/eap_peer/eap_fast_pac.o
OBJS += ../src/eap_common/eap_fast_common.o
-OBJS_h += ../src/eap_server/eap_fast.o
+OBJS_h += ../src/eap_server/eap_server_fast.o
endif
TLS_FUNCS=y
CONFIG_IEEE8021X_EAPOL=y
@@ -472,7 +418,7 @@ EAPDYN += ../src/eap_peer/eap_pax.so
else
CFLAGS += -DEAP_PAX
OBJS += ../src/eap_peer/eap_pax.o ../src/eap_common/eap_pax_common.o
-OBJS_h += ../src/eap_server/eap_pax.o
+OBJS_h += ../src/eap_server/eap_server_pax.o
endif
CONFIG_IEEE8021X_EAPOL=y
endif
@@ -485,7 +431,7 @@ EAPDYN += ../src/eap_peer/eap_sake.so
else
CFLAGS += -DEAP_SAKE
OBJS += ../src/eap_peer/eap_sake.o ../src/eap_common/eap_sake_common.o
-OBJS_h += ../src/eap_server/eap_sake.o
+OBJS_h += ../src/eap_server/eap_server_sake.o
endif
CONFIG_IEEE8021X_EAPOL=y
endif
@@ -498,13 +444,14 @@ EAPDYN += ../src/eap_peer/eap_gpsk.so
else
CFLAGS += -DEAP_GPSK
OBJS += ../src/eap_peer/eap_gpsk.o ../src/eap_common/eap_gpsk_common.o
-OBJS_h += ../src/eap_server/eap_gpsk.o
+OBJS_h += ../src/eap_server/eap_server_gpsk.o
endif
CONFIG_IEEE8021X_EAPOL=y
ifdef CONFIG_EAP_GPSK_SHA256
CFLAGS += -DEAP_GPSK_SHA256
endif
NEED_SHA256=y
+NEED_AES_OMAC1=y
endif
ifdef CONFIG_WPS
@@ -521,13 +468,46 @@ OBJS += ../src/wps/wps_attr_process.o
OBJS += ../src/wps/wps_dev_attr.o
OBJS += ../src/wps/wps_enrollee.o
OBJS += ../src/wps/wps_registrar.o
-OBJS_h += ../src/eap_server/eap_wsc.o
+OBJS_h += ../src/eap_server/eap_server_wsc.o
CONFIG_IEEE8021X_EAPOL=y
NEED_DH_GROUPS=y
NEED_SHA256=y
NEED_BASE64=y
-NEED_CRYPTO=y
NEED_80211_COMMON=y
+NEED_AES_CBC=y
+NEED_MODEXP=y
+
+ifdef CONFIG_WPS_UFD
+CFLAGS += -DCONFIG_WPS_UFD
+OBJS += ../src/wps/wps_ufd.o
+NEED_WPS_OOB=y
+endif
+
+ifdef CONFIG_WPS_NFC
+CFLAGS += -DCONFIG_WPS_NFC
+OBJS += ../src/wps/ndef.o
+OBJS += ../src/wps/wps_nfc.o
+NEED_WPS_OOB=y
+ifdef CONFIG_WPS_NFC_PN531
+PN531_PATH ?= /usr/local/src/nfc
+CFLAGS += -DCONFIG_WPS_NFC_PN531
+CFLAGS += -I${PN531_PATH}/inc
+OBJS += ../src/wps/wps_nfc_pn531.o
+LIBS += ${PN531_PATH}/lib/wpsnfc.dll
+LIBS += ${PN531_PATH}/lib/libnfc_mapping_pn53x.dll
+endif
+endif
+
+ifdef NEED_WPS_OOB
+CFLAGS += -DCONFIG_WPS_OOB
+endif
+
+ifdef CONFIG_WPS_ER
+CONFIG_WPS_UPNP=y
+CFLAGS += -DCONFIG_WPS_ER
+OBJS += ../src/wps/wps_er.o
+OBJS += ../src/wps/wps_er_ssdp.o
+endif
ifdef CONFIG_WPS_UPNP
CFLAGS += -DCONFIG_WPS_UPNP
@@ -535,7 +515,11 @@ OBJS += ../src/wps/wps_upnp.o
OBJS += ../src/wps/wps_upnp_ssdp.o
OBJS += ../src/wps/wps_upnp_web.o
OBJS += ../src/wps/wps_upnp_event.o
+OBJS += ../src/wps/wps_upnp_ap.o
+OBJS += ../src/wps/upnp_xml.o
OBJS += ../src/wps/httpread.o
+OBJS += ../src/wps/http_client.o
+OBJS += ../src/wps/http_server.o
endif
endif
@@ -550,12 +534,14 @@ else
CFLAGS += -DEAP_IKEV2
OBJS += ../src/eap_peer/eap_ikev2.o ../src/eap_peer/ikev2.o
OBJS += ../src/eap_common/eap_ikev2_common.o ../src/eap_common/ikev2_common.o
-OBJS_h += ../src/eap_server/eap_ikev2.o
+OBJS_h += ../src/eap_server/eap_server_ikev2.o
OBJS_h += ../src/eap_server/ikev2.o
endif
CONFIG_IEEE8021X_EAPOL=y
NEED_DH_GROUPS=y
NEED_DH_GROUPS_ALL=y
+NEED_MODEXP=y
+NEED_CIPHER=y
endif
ifdef CONFIG_EAP_VENDOR_TEST
@@ -565,7 +551,7 @@ EAPDYN += ../src/eap_peer/eap_vendor_test.so
else
CFLAGS += -DEAP_VENDOR_TEST
OBJS += ../src/eap_peer/eap_vendor_test.o
-OBJS_h += ../src/eap_server/eap_vendor_test.o
+OBJS_h += ../src/eap_server/eap_server_vendor_test.o
endif
CONFIG_IEEE8021X_EAPOL=y
endif
@@ -575,6 +561,8 @@ ifdef CONFIG_EAP_TNC
CFLAGS += -DEAP_TNC
OBJS += ../src/eap_peer/eap_tnc.o
OBJS += ../src/eap_peer/tncc.o
+OBJS_h += ../src/eap_server/eap_server_tnc.o
+OBJS_h += ../src/eap_server/tncs.o
NEED_BASE64=y
ifndef CONFIG_NATIVE_WINDOWS
ifndef CONFIG_DRIVER_BSD
@@ -586,18 +574,88 @@ endif
ifdef CONFIG_IEEE8021X_EAPOL
# IEEE 802.1X/EAPOL state machines (e.g., for RADIUS authentication)
CFLAGS += -DIEEE8021X_EAPOL
-OBJS += ../src/eapol_supp/eapol_supp_sm.o ../src/eap_peer/eap.o ../src/eap_common/eap_common.o ../src/eap_peer/eap_methods.o
+OBJS += ../src/eapol_supp/eapol_supp_sm.o
+OBJS += ../src/eap_peer/eap.o ../src/eap_peer/eap_methods.o
+NEED_EAP_COMMON=y
ifdef CONFIG_DYNAMIC_EAP_METHODS
CFLAGS += -DCONFIG_DYNAMIC_EAP_METHODS
LIBS += -ldl -rdynamic
endif
endif
+ifdef CONFIG_AP
+NEED_80211_COMMON=y
+NEED_EAP_COMMON=y
+NEED_RSN_AUTHENTICATOR=y
+CFLAGS += -DCONFIG_AP
+OBJS += ap.o
+CFLAGS += -DCONFIG_NO_RADIUS
+CFLAGS += -DCONFIG_NO_ACCOUNTING
+CFLAGS += -DCONFIG_NO_VLAN
+OBJS += ../src/ap/hostapd.o
+OBJS += ../src/ap/wpa_auth_glue.o
+OBJS += ../src/ap/utils.o
+OBJS += ../src/ap/authsrv.o
+OBJS += ../src/ap/ap_config.o
+OBJS += ../src/utils/ip_addr.o
+OBJS += ../src/ap/sta_info.o
+OBJS += ../src/ap/tkip_countermeasures.o
+OBJS += ../src/ap/ap_mlme.o
+OBJS += ../src/ap/ieee802_1x.o
+OBJS += ../src/eapol_auth/eapol_auth_sm.o
+OBJS += ../src/ap/ieee802_11_auth.o
+OBJS += ../src/ap/drv_callbacks.o
+OBJS += ../src/ap/ap_drv_ops.o
+ifdef CONFIG_CTRL_IFACE
+OBJS += ../src/ap/ctrl_iface_ap.o
+endif
+
+CFLAGS += -DEAP_SERVER -DEAP_SERVER_IDENTITY
+OBJS += ../src/eap_server/eap_server.o
+OBJS += ../src/eap_server/eap_server_identity.o
+OBJS += ../src/eap_server/eap_server_methods.o
+
+ifdef CONFIG_IEEE80211N
+CFLAGS += -DCONFIG_IEEE80211N
+endif
+
+ifdef NEED_AP_MLME
+OBJS += ../src/ap/beacon.o
+OBJS += ../src/ap/wmm.o
+OBJS += ../src/ap/ap_list.o
+OBJS += ../src/ap/ieee802_11.o
+OBJS += ../src/ap/hw_features.o
+ifdef CONFIG_IEEE80211N
+OBJS += ../src/ap/ieee802_11_ht.o
+endif
+CFLAGS += -DNEED_AP_MLME
+endif
+ifdef CONFIG_WPS
+CFLAGS += -DEAP_SERVER_WSC
+OBJS += ../src/ap/wps_hostapd.o
+OBJS += ../src/eap_server/eap_server_wsc.o
+endif
+endif
+
+ifdef NEED_RSN_AUTHENTICATOR
+CFLAGS += -DCONFIG_NO_RADIUS
+NEED_AES_WRAP=y
+OBJS += ../src/ap/wpa_auth.o
+OBJS += ../src/ap/wpa_auth_ie.o
+OBJS += ../src/ap/pmksa_cache_auth.o
+ifdef CONFIG_IEEE80211R
+OBJS += ../src/ap/wpa_auth_ft.o
+endif
+ifdef CONFIG_PEERKEY
+OBJS += ../src/ap/peerkey_auth.o
+endif
+endif
+
ifdef CONFIG_EAP_SERVER
CFLAGS += -DEAP_SERVER
-OBJS_h += ../src/eap_server/eap.o
-OBJS_h += ../src/eap_server/eap_identity.o
-OBJS_h += ../src/eap_server/eap_methods.o
+OBJS_h += ../src/eap_server/eap_server.o
+OBJS_h += ../src/eap_server/eap_server_identity.o
+OBJS_h += ../src/eap_server/eap_server_methods.o
endif
ifdef CONFIG_RADIUS_CLIENT
@@ -607,18 +665,19 @@ OBJS_h += ../src/radius/radius_client.o
endif
ifdef CONFIG_AUTHENTICATOR
-OBJS_h += ../hostapd/eapol_sm.o
-OBJS_h += ../hostapd/ieee802_1x.o
+OBJS_h += ../src/eapol_auth/eapol_auth_sm.o
+OBJS_h += ../src/ap/ieee802_1x.o
endif
ifdef CONFIG_WPA_AUTHENTICATOR
-OBJS_h += ../hostapd/wpa.o
-OBJS_h += ../hostapd/wpa_auth_ie.o
+OBJS_h += ../src/ap/wpa_auth.o
+OBJS_h += ../src/ap/wpa_auth_ie.o
+OBJS_h += ../src/ap/pmksa_cache_auth.o
ifdef CONFIG_IEEE80211R
-OBJS_h += ../hostapd/wpa_ft.o
+OBJS_h += ../src/ap/wpa_auth_ft.o
endif
ifdef CONFIG_PEERKEY
-OBJS_h += ../hostapd/peerkey.o
+OBJS_h += ../src/ap/peerkey_auth.o
endif
endif
@@ -647,149 +706,152 @@ NEED_MILENAGE=y
endif
ifdef NEED_MILENAGE
-OBJS += ../src/hlr_auc_gw/milenage.o
+OBJS += ../src/crypto/milenage.o
endif
-ifndef CONFIG_TLS
-CONFIG_TLS=openssl
+ifdef CONFIG_PKCS12
+CFLAGS += -DPKCS12_FUNCS
endif
-ifeq ($(CONFIG_TLS), internal)
-ifndef CONFIG_CRYPTO
-CONFIG_CRYPTO=internal
-endif
-endif
-ifeq ($(CONFIG_CRYPTO), libtomcrypt)
-CFLAGS += -DCONFIG_INTERNAL_X509
+ifdef CONFIG_SMARTCARD
+CFLAGS += -DCONFIG_SMARTCARD
endif
-ifeq ($(CONFIG_CRYPTO), internal)
-CFLAGS += -DCONFIG_INTERNAL_X509
+
+ifdef MS_FUNCS
+OBJS += ../src/crypto/ms_funcs.o
+NEED_DES=y
+NEED_MD4=y
endif
+ifdef CHAP
+OBJS += ../src/eap_common/chap.o
+endif
ifdef TLS_FUNCS
+NEED_DES=y
# Shared TLS functions (needed for EAP_TLS, EAP_PEAP, EAP_TTLS, and EAP_FAST)
-CFLAGS += -DEAP_TLS_FUNCS
OBJS += ../src/eap_peer/eap_tls_common.o
-OBJS_h += ../src/eap_server/eap_tls_common.o
+OBJS_h += ../src/eap_server/eap_server_tls_common.o
NEED_TLS_PRF=y
+endif
+
+ifndef CONFIG_TLS
+CONFIG_TLS=openssl
+endif
+
ifeq ($(CONFIG_TLS), openssl)
+ifdef TLS_FUNCS
CFLAGS += -DEAP_TLS_OPENSSL
OBJS += ../src/crypto/tls_openssl.o
-LIBS += -lssl -lcrypto
+LIBS += -lssl
+endif
+OBJS += ../src/crypto/crypto_openssl.o
+OBJS_p += ../src/crypto/crypto_openssl.o
+ifdef NEED_FIPS186_2_PRF
+OBJS += ../src/crypto/fips_prf_openssl.o
+endif
+LIBS += -lcrypto
LIBS_p += -lcrypto
endif
+
ifeq ($(CONFIG_TLS), gnutls)
+ifdef TLS_FUNCS
OBJS += ../src/crypto/tls_gnutls.o
-LIBS += -lgnutls -lgcrypt -lgpg-error
-LIBS_p += -lgcrypt
+LIBS += -lgnutls -lgpg-error
ifdef CONFIG_GNUTLS_EXTRA
CFLAGS += -DCONFIG_GNUTLS_EXTRA
LIBS += -lgnutls-extra
endif
endif
-ifeq ($(CONFIG_TLS), schannel)
-OBJS += ../src/crypto/tls_schannel.o
-endif
-ifeq ($(CONFIG_TLS), internal)
-OBJS += ../src/crypto/tls_internal.o
-OBJS += ../src/tls/tlsv1_common.o ../src/tls/tlsv1_record.o
-OBJS += ../src/tls/tlsv1_cred.o ../src/tls/tlsv1_client.o
-OBJS += ../src/tls/tlsv1_client_write.o ../src/tls/tlsv1_client_read.o
-OBJS += ../src/tls/asn1.o ../src/tls/rsa.o ../src/tls/x509v3.o
-OBJS_p += ../src/tls/asn1.o ../src/tls/rsa.o
-OBJS_p += ../src/crypto/rc4.o ../src/crypto/aes_wrap.o ../src/crypto/aes.o
-NEED_BASE64=y
-NEED_TLS_PRF=y
-CFLAGS += -DCONFIG_TLS_INTERNAL
-CFLAGS += -DCONFIG_TLS_INTERNAL_CLIENT
-ifeq ($(CONFIG_CRYPTO), internal)
-endif
-ifeq ($(CONFIG_CRYPTO), libtomcrypt)
-LIBS += -ltomcrypt -ltfm
-LIBS_p += -ltomcrypt -ltfm
-endif
+OBJS += ../src/crypto/crypto_gnutls.o
+OBJS_p += ../src/crypto/crypto_gnutls.o
+ifdef NEED_FIPS186_2_PRF
+OBJS += ../src/crypto/fips_prf_gnutls.o
endif
-ifeq ($(CONFIG_TLS), none)
-OBJS += ../src/crypto/tls_none.o
-CFLAGS += -DEAP_TLS_NONE
-CONFIG_INTERNAL_AES=y
-CONFIG_INTERNAL_SHA1=y
-CONFIG_INTERNAL_MD5=y
+LIBS += -lgcrypt
+LIBS_p += -lgcrypt
CONFIG_INTERNAL_SHA256=y
-endif
-ifdef CONFIG_SMARTCARD
-ifndef CONFIG_NATIVE_WINDOWS
-ifneq ($(CONFIG_L2_PACKET), freebsd)
-LIBS += -ldl
-endif
-endif
-endif
-NEED_CRYPTO=y
-else
-OBJS += ../src/crypto/tls_none.o
+CONFIG_INTERNAL_RC4=y
+CONFIG_INTERNAL_DH_GROUP5=y
endif
-ifdef CONFIG_PKCS12
-CFLAGS += -DPKCS12_FUNCS
-endif
-
-ifdef CONFIG_SMARTCARD
-CFLAGS += -DCONFIG_SMARTCARD
+ifeq ($(CONFIG_TLS), schannel)
+ifdef TLS_FUNCS
+OBJS += ../src/crypto/tls_schannel.o
endif
-
-ifdef MS_FUNCS
-OBJS += ../src/crypto/ms_funcs.o
-NEED_CRYPTO=y
+OBJS += ../src/crypto/crypto_cryptoapi.o
+OBJS_p += ../src/crypto/crypto_cryptoapi.o
+ifdef NEED_FIPS186_2_PRF
+OBJS += ../src/crypto/fips_prf_cryptoapi.o
endif
-
-ifdef CHAP
-OBJS += ../src/eap_common/chap.o
+CONFIG_INTERNAL_SHA256=y
+CONFIG_INTERNAL_RC4=y
+CONFIG_INTERNAL_DH_GROUP5=y
endif
-ifdef NEED_CRYPTO
-ifndef TLS_FUNCS
-ifeq ($(CONFIG_TLS), openssl)
-LIBS += -lcrypto
-LIBS_p += -lcrypto
+ifeq ($(CONFIG_TLS), nss)
+ifdef TLS_FUNCS
+OBJS += ../src/crypto/tls_nss.o
+LIBS += -lssl3
endif
-ifeq ($(CONFIG_TLS), gnutls)
-LIBS += -lgcrypt
-LIBS_p += -lgcrypt
+OBJS += ../src/crypto/crypto_nss.o
+OBJS_p += ../src/crypto/crypto_nss.o
+ifdef NEED_FIPS186_2_PRF
+OBJS += ../src/crypto/fips_prf_nss.o
endif
-ifeq ($(CONFIG_TLS), schannel)
+LIBS += -lnss3
+LIBS_p += -lnss3
+CONFIG_INTERNAL_MD4=y
+CONFIG_INTERNAL_DH_GROUP5=y
endif
+
ifeq ($(CONFIG_TLS), internal)
-ifeq ($(CONFIG_CRYPTO), libtomcrypt)
-LIBS += -ltomcrypt -ltfm
-LIBS_p += -ltomcrypt -ltfm
-endif
-endif
+ifndef CONFIG_CRYPTO
+CONFIG_CRYPTO=internal
endif
-ifeq ($(CONFIG_TLS), openssl)
-OBJS += ../src/crypto/crypto_openssl.o
-OBJS_p += ../src/crypto/crypto_openssl.o
-CONFIG_INTERNAL_SHA256=y
+ifdef TLS_FUNCS
+OBJS += ../src/crypto/crypto_internal-rsa.o
+OBJS += ../src/crypto/tls_internal.o
+OBJS += ../src/tls/tlsv1_common.o
+OBJS += ../src/tls/tlsv1_record.o
+OBJS += ../src/tls/tlsv1_cred.o
+OBJS += ../src/tls/tlsv1_client.o
+OBJS += ../src/tls/tlsv1_client_write.o
+OBJS += ../src/tls/tlsv1_client_read.o
+OBJS += ../src/tls/asn1.o
+OBJS += ../src/tls/rsa.o
+OBJS += ../src/tls/x509v3.o
+OBJS += ../src/tls/pkcs1.o
+OBJS += ../src/tls/pkcs5.o
+OBJS += ../src/tls/pkcs8.o
+NEED_SHA256=y
+NEED_BASE64=y
+NEED_TLS_PRF=y
+NEED_MODEXP=y
+NEED_CIPHER=y
+CFLAGS += -DCONFIG_TLS_INTERNAL_CLIENT
endif
-ifeq ($(CONFIG_TLS), gnutls)
-OBJS += ../src/crypto/crypto_gnutls.o
-OBJS_p += ../src/crypto/crypto_gnutls.o
-CONFIG_INTERNAL_SHA256=y
+ifdef NEED_CIPHER
+NEED_DES=y
+OBJS += ../src/crypto/crypto_internal-cipher.o
endif
-ifeq ($(CONFIG_TLS), schannel)
-OBJS += ../src/crypto/crypto_cryptoapi.o
-OBJS_p += ../src/crypto/crypto_cryptoapi.o
-CONFIG_INTERNAL_SHA256=y
+ifdef NEED_MODEXP
+OBJS += ../src/crypto/crypto_internal-modexp.o
+OBJS += ../src/tls/bignum.o
endif
-ifeq ($(CONFIG_TLS), internal)
ifeq ($(CONFIG_CRYPTO), libtomcrypt)
OBJS += ../src/crypto/crypto_libtomcrypt.o
OBJS_p += ../src/crypto/crypto_libtomcrypt.o
+LIBS += -ltomcrypt -ltfm
+LIBS_p += -ltomcrypt -ltfm
CONFIG_INTERNAL_SHA256=y
+CONFIG_INTERNAL_RC4=y
+CONFIG_INTERNAL_DH_GROUP5=y
endif
ifeq ($(CONFIG_CRYPTO), internal)
-OBJS += ../src/crypto/crypto_internal.o ../src/tls/bignum.o
-OBJS_p += ../src/crypto/crypto_internal.o ../src/tls/bignum.o
+OBJS += ../src/crypto/crypto_internal.o
+OBJS_p += ../src/crypto/crypto_internal.o
+NEED_AES_ENC=y
CFLAGS += -DCONFIG_CRYPTO_INTERNAL
ifdef CONFIG_INTERNAL_LIBTOMMATH
CFLAGS += -DCONFIG_INTERNAL_LIBTOMMATH
@@ -806,60 +868,159 @@ CONFIG_INTERNAL_SHA1=y
CONFIG_INTERNAL_MD4=y
CONFIG_INTERNAL_MD5=y
CONFIG_INTERNAL_SHA256=y
+CONFIG_INTERNAL_RC4=y
+CONFIG_INTERNAL_DH_GROUP5=y
endif
ifeq ($(CONFIG_CRYPTO), cryptoapi)
OBJS += ../src/crypto/crypto_cryptoapi.o
OBJS_p += ../src/crypto/crypto_cryptoapi.o
CFLAGS += -DCONFIG_CRYPTO_CRYPTOAPI
CONFIG_INTERNAL_SHA256=y
+CONFIG_INTERNAL_RC4=y
endif
endif
+
ifeq ($(CONFIG_TLS), none)
+ifdef TLS_FUNCS
+OBJS += ../src/crypto/tls_none.o
+CFLAGS += -DEAP_TLS_NONE
+CONFIG_INTERNAL_AES=y
+CONFIG_INTERNAL_SHA1=y
+CONFIG_INTERNAL_MD5=y
+endif
OBJS += ../src/crypto/crypto_none.o
OBJS_p += ../src/crypto/crypto_none.o
CONFIG_INTERNAL_SHA256=y
+CONFIG_INTERNAL_RC4=y
endif
-else
+
+ifdef TLS_FUNCS
+ifdef CONFIG_SMARTCARD
+ifndef CONFIG_NATIVE_WINDOWS
+ifneq ($(CONFIG_L2_PACKET), freebsd)
+LIBS += -ldl
+endif
+endif
+endif
+endif
+
+ifndef TLS_FUNCS
+OBJS += ../src/crypto/tls_none.o
+ifeq ($(CONFIG_TLS), internal)
CONFIG_INTERNAL_AES=y
CONFIG_INTERNAL_SHA1=y
CONFIG_INTERNAL_MD5=y
+CONFIG_INTERNAL_RC4=y
+endif
endif
+AESOBJS = # none so far (see below)
ifdef CONFIG_INTERNAL_AES
-CFLAGS += -DINTERNAL_AES
+AESOBJS += ../src/crypto/aes-internal.o ../src/crypto/aes-internal-dec.o
+endif
+
+AESOBJS += ../src/crypto/aes-unwrap.o
+ifdef NEED_AES_EAX
+AESOBJS += ../src/crypto/aes-eax.o
+NEED_AES_CTR=y
+endif
+ifdef NEED_AES_CTR
+AESOBJS += ../src/crypto/aes-ctr.o
+endif
+ifdef NEED_AES_ENCBLOCK
+AESOBJS += ../src/crypto/aes-encblock.o
+endif
+ifdef NEED_AES_OMAC1
+NEED_AES_ENC=y
+AESOBJS += ../src/crypto/aes-omac1.o
endif
+ifdef NEED_AES_WRAP
+NEED_AES_ENC=y
+AESOBJS += ../src/crypto/aes-wrap.o
+endif
+ifdef NEED_AES_CBC
+NEED_AES_ENC=y
+AESOBJS += ../src/crypto/aes-cbc.o
+endif
+ifdef NEED_AES_ENC
+ifdef CONFIG_INTERNAL_AES
+AESOBJS += ../src/crypto/aes-internal-enc.o
+endif
+endif
+ifdef NEED_AES
+OBJS += $(AESOBJS)
+endif
+
+ifdef NEED_SHA1
+SHA1OBJS += ../src/crypto/sha1.o
ifdef CONFIG_INTERNAL_SHA1
-CFLAGS += -DINTERNAL_SHA1
+SHA1OBJS += ../src/crypto/sha1-internal.o
+ifdef NEED_FIPS186_2_PRF
+SHA1OBJS += ../src/crypto/fips_prf_internal.o
endif
-ifdef CONFIG_INTERNAL_SHA256
-CFLAGS += -DINTERNAL_SHA256
endif
+ifndef CONFIG_NO_WPA_PASSPHRASE
+SHA1OBJS += ../src/crypto/sha1-pbkdf2.o
+endif
+ifdef NEED_T_PRF
+SHA1OBJS += ../src/crypto/sha1-tprf.o
+endif
+ifdef NEED_TLS_PRF
+SHA1OBJS += ../src/crypto/sha1-tlsprf.o
+endif
+endif
+
+MD5OBJS = ../src/crypto/md5.o
+ifdef NEED_MD5
ifdef CONFIG_INTERNAL_MD5
-CFLAGS += -DINTERNAL_MD5
+MD5OBJS += ../src/crypto/md5-internal.o
endif
+ifdef CONFIG_FIPS
+MD5OBJS += ../src/crypto/md5-non-fips.o
+endif
+OBJS += $(MD5OBJS)
+OBJS_p += $(MD5OBJS)
+endif
+
+ifdef NEED_MD4
ifdef CONFIG_INTERNAL_MD4
-CFLAGS += -DINTERNAL_MD4
+OBJS += ../src/crypto/md4-internal.o
endif
-ifdef CONFIG_INTERNAL_DES
-CFLAGS += -DINTERNAL_DES
endif
-ifdef CONFIG_IEEE80211R
-NEED_SHA256=y
+DESOBJS = # none needed when not internal
+ifdef NEED_DES
+ifdef CONFIG_INTERNAL_DES
+DESOBJS += ../src/crypto/des-internal.o
+endif
endif
-ifdef CONFIG_IEEE80211W
-CFLAGS += -DCONFIG_IEEE80211W
-NEED_SHA256=y
+ifdef NEED_RC4
+ifdef CONFIG_INTERNAL_RC4
+OBJS += ../src/crypto/rc4.o
+endif
endif
+SHA256OBJS = # none by default
ifdef NEED_SHA256
-OBJS += ../src/crypto/sha256.o
-CFLAGS += -DNEED_SHA256
+CFLAGS += -DCONFIG_SHA256
+SHA256OBJS += ../src/crypto/sha256.o
+ifdef CONFIG_INTERNAL_SHA256
+SHA256OBJS += ../src/crypto/sha256-internal.o
+endif
+OBJS += $(SHA256OBJS)
endif
-ifdef CONFIG_WIRELESS_EXTENSION
-OBJS_d += ../src/drivers/driver_wext.o
+ifdef NEED_DH_GROUPS
+OBJS += ../src/crypto/dh_groups.o
+endif
+ifdef NEED_DH_GROUPS_ALL
+CFLAGS += -DALL_DH_GROUPS
+endif
+ifdef CONFIG_INTERNAL_DH_GROUP5
+ifdef NEED_DH_GROUPS
+OBJS += ../src/crypto/dh_group5.o
+endif
endif
ifdef CONFIG_CTRL_IFACE
@@ -884,12 +1045,16 @@ OBJS += ctrl_iface.o ctrl_iface_$(CONFIG_CTRL_IFACE).o
endif
ifdef CONFIG_CTRL_IFACE_DBUS
-CFLAGS += -DCONFIG_CTRL_IFACE_DBUS -DDBUS_API_SUBJECT_TO_CHANGE
-OBJS += ctrl_iface_dbus.o ctrl_iface_dbus_handlers.o dbus_dict_helpers.o
+DBUS=y
+DBUS_CFLAGS += -DCONFIG_CTRL_IFACE_DBUS -DDBUS_API_SUBJECT_TO_CHANGE
+DBUS_OBJS += dbus/dbus_old.o dbus/dbus_old_handlers.o
+ifdef CONFIG_WPS
+DBUS_OBJS += dbus/dbus_old_handlers_wps.o
+endif
+DBUS_OBJS += dbus/dbus_dict_helpers.o
ifndef DBUS_LIBS
DBUS_LIBS := $(shell pkg-config --libs dbus-1)
endif
-LIBS += $(DBUS_LIBS)
ifndef DBUS_INCLUDE
DBUS_INCLUDE := $(shell pkg-config --cflags dbus-1)
endif
@@ -904,9 +1069,40 @@ DBUS_VERSION_MINOR=0
endif
DBUS_INCLUDE += -DDBUS_VERSION_MAJOR=$(DBUS_VERSION_MAJOR)
DBUS_INCLUDE += -DDBUS_VERSION_MINOR=$(DBUS_VERSION_MINOR)
-CFLAGS += $(DBUS_INCLUDE)
+DBUS_CFLAGS += $(DBUS_INCLUDE)
endif
+ifdef CONFIG_CTRL_IFACE_DBUS_NEW
+DBUS=y
+DBUS_CFLAGS += -DCONFIG_CTRL_IFACE_DBUS_NEW
+DBUS_OBJS ?= dbus/dbus_dict_helpers.o
+DBUS_OBJS += dbus/dbus_new_helpers.o
+DBUS_OBJS += dbus/dbus_new.o dbus/dbus_new_handlers.o
+ifdef CONFIG_WPS
+DBUS_OBJS += dbus/dbus_new_handlers_wps.o
+endif
+ifndef DBUS_LIBS
+DBUS_LIBS := $(shell pkg-config --libs dbus-1)
+endif
+ifndef DBUS_INCLUDE
+DBUS_INCLUDE := $(shell pkg-config --cflags dbus-1)
+endif
+ifdef CONFIG_CTRL_IFACE_DBUS_INTRO
+DBUS_OBJS += dbus/dbus_new_introspect.o
+DBUS_CFLAGS += -DCONFIG_CTRL_IFACE_DBUS_INTRO
+endif
+DBUS_CFLAGS += $(DBUS_INCLUDE)
+endif
+
+ifdef DBUS
+DBUS_CFLAGS += -DCONFIG_DBUS
+DBUS_OBJS += dbus/dbus_common.o
+endif
+
+OBJS += $(DBUS_OBJS)
+CFLAGS += $(DBUS_CFLAGS)
+LIBS += $(DBUS_LIBS)
+
ifdef CONFIG_READLINE
CFLAGS += -DCONFIG_READLINE
LIBS_c += -lncurses -lreadline
@@ -934,73 +1130,28 @@ ifdef CONFIG_IPV6
CFLAGS += -DCONFIG_IPV6
endif
-ifdef CONFIG_PEERKEY
-CFLAGS += -DCONFIG_PEERKEY
-endif
-
-ifdef CONFIG_IEEE80211R
-CFLAGS += -DCONFIG_IEEE80211R
-OBJS += ../src/rsn_supp/wpa_ft.o
-endif
-
-ifndef CONFIG_NO_WPA
-OBJS += ../src/rsn_supp/wpa.o
-OBJS += ../src/rsn_supp/preauth.o
-OBJS += ../src/rsn_supp/pmksa_cache.o
-OBJS += ../src/rsn_supp/peerkey.o
-OBJS += ../src/rsn_supp/wpa_ie.o
-OBJS += ../src/common/wpa_common.o
-NEED_AES=y
-else
-CFLAGS += -DCONFIG_NO_WPA -DCONFIG_NO_WPA2
-endif
-
-ifdef CONFIG_NO_WPA2
-CFLAGS += -DCONFIG_NO_WPA2
-endif
-
-ifdef CONFIG_NO_WPA_PASSPHRASE
-CFLAGS += -DCONFIG_NO_PBKDF2
-endif
-
-ifdef CONFIG_NO_AES_EXTRAS
-CFLAGS += -DCONFIG_NO_AES_WRAP
-CFLAGS += -DCONFIG_NO_AES_CTR -DCONFIG_NO_AES_OMAC1
-CFLAGS += -DCONFIG_NO_AES_EAX -DCONFIG_NO_AES_CBC
-CFLAGS += -DCONFIG_NO_AES_ENCRYPT
-CFLAGS += -DCONFIG_NO_AES_ENCRYPT_BLOCK
-endif
-
-ifdef NEED_AES
-OBJS += ../src/crypto/aes_wrap.o ../src/crypto/aes.o
-endif
-
-ifdef NEED_DH_GROUPS
-OBJS += ../src/crypto/dh_groups.o
-ifdef NEED_DH_GROUPS_ALL
-CFLAGS += -DALL_DH_GROUPS
-endif
-endif
-
-ifndef NEED_FIPS186_2_PRF
-CFLAGS += -DCONFIG_NO_FIPS186_2_PRF
+ifdef NEED_BASE64
+OBJS += ../src/utils/base64.o
endif
-ifndef NEED_T_PRF
-CFLAGS += -DCONFIG_NO_T_PRF
+ifdef NEED_SME
+NEED_80211_COMMON=y
+OBJS += sme.o
+CFLAGS += -DCONFIG_SME
endif
-ifndef NEED_TLS_PRF
-CFLAGS += -DCONFIG_NO_TLS_PRF
+ifdef CONFIG_CLIENT_MLME
+OBJS += mlme.o
+CFLAGS += -DCONFIG_CLIENT_MLME
+NEED_80211_COMMON=y
endif
-ifdef NEED_BASE64
-OBJS += ../src/utils/base64.o
+ifdef NEED_80211_COMMON
+OBJS += ../src/common/ieee802_11_common.o
endif
-ifdef CONFIG_CLIENT_MLME
-OBJS += mlme.o ../src/common/ieee802_11_common.o
-CFLAGS += -DCONFIG_CLIENT_MLME
+ifdef NEED_EAP_COMMON
+OBJS += ../src/eap_common/eap_common.o
endif
ifndef CONFIG_MAIN
@@ -1019,7 +1170,24 @@ ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
CFLAGS += -DCONFIG_DELAYED_MIC_ERROR_REPORT
endif
-OBJS += ../src/drivers/scan_helpers.o
+ifdef CONFIG_FIPS
+CFLAGS += -DCONFIG_FIPS
+endif
+
+OBJS += $(SHA1OBJS) $(DESOBJS)
+
+OBJS_p += $(SHA1OBJS)
+
+ifdef CONFIG_BGSCAN_SIMPLE
+CFLAGS += -DCONFIG_BGSCAN_SIMPLE
+OBJS += bgscan_simple.o
+NEED_BGSCAN=y
+endif
+
+ifdef NEED_BGSCAN
+CFLAGS += -DCONFIG_BGSCAN
+OBJS += bgscan.o
+endif
OBJS_wpa_rm := ctrl_iface.o mlme.o ctrl_iface_unix.o
OBJS_wpa := $(filter-out $(OBJS_wpa_rm),$(OBJS)) $(OBJS_h) tests/test_wpa.o
@@ -1028,13 +1196,17 @@ OBJS_wpa += tests/link_test.o
endif
OBJS_wpa += $(OBJS_l2)
OBJS += wpa_supplicant.o events.o blacklist.o wpas_glue.o scan.o
-OBJS_t := $(OBJS) $(OBJS_l2) eapol_test.o ../src/radius/radius.o ../src/radius/radius_client.o
+OBJS_t := $(OBJS) $(OBJS_l2) eapol_test.o
+OBJS_t += ../src/radius/radius_client.o
+OBJS_t += ../src/radius/radius.o
+ifndef CONFIG_AP
OBJS_t += ../src/utils/ip_addr.o
+endif
OBJS_t2 := $(OBJS) $(OBJS_l2) preauth_test.o
OBJS += $(CONFIG_MAIN).o
ifdef CONFIG_PRIVSEP
-OBJS_priv += $(OBJS_d) ../src/drivers/drivers.o ../src/drivers/scan_helpers.o
+OBJS_priv += $(OBJS_d) ../src/drivers/drivers.o
OBJS_priv += $(OBJS_l2)
OBJS_priv += ../src/utils/os_$(CONFIG_OS).o
OBJS_priv += ../src/utils/$(CONFIG_ELOOP).o
@@ -1043,14 +1215,17 @@ OBJS_priv += ../src/utils/wpa_debug.o
OBJS_priv += ../src/utils/wpabuf.o
OBJS_priv += wpa_priv.o
ifdef CONFIG_DRIVER_TEST
-OBJS_priv += ../src/crypto/sha1.o
-OBJS_priv += ../src/crypto/md5.o
+OBJS_priv += $(SHA1OBJS)
+OBJS_priv += $(MD5OBJS)
ifeq ($(CONFIG_TLS), openssl)
OBJS_priv += ../src/crypto/crypto_openssl.o
endif
ifeq ($(CONFIG_TLS), gnutls)
OBJS_priv += ../src/crypto/crypto_gnutls.o
endif
+ifeq ($(CONFIG_TLS), nss)
+OBJS_priv += ../src/crypto/crypto_nss.o
+endif
ifeq ($(CONFIG_TLS), internal)
ifeq ($(CONFIG_CRYPTO), libtomcrypt)
OBJS_priv += ../src/crypto/crypto_libtomcrypt.o
@@ -1084,10 +1259,18 @@ endif
dynamic_eap_methods: $(EAPDYN)
-wpa_priv: $(OBJS_priv)
+../src/drivers/build.wpa_supplicant:
+ @if [ -f ../src/drivers/build.hostapd ]; then \
+ $(MAKE) -C ../src/drivers clean; \
+ fi
+ @touch ../src/drivers/build.wpa_supplicant
+
+BCHECK=../src/drivers/build.wpa_supplicant
+
+wpa_priv: $(BCHECK) $(OBJS_priv)
$(LDO) $(LDFLAGS) -o wpa_priv $(OBJS_priv) $(LIBS)
-wpa_supplicant: .config $(OBJS) $(EXTRA_progs)
+wpa_supplicant: .config $(BCHECK) $(OBJS) $(EXTRA_progs)
$(LDO) $(LDFLAGS) -o wpa_supplicant $(OBJS) $(LIBS) $(EXTRALIBS)
eapol_test: .config $(OBJS_t)
@@ -1108,48 +1291,31 @@ link_test: $(OBJS) $(OBJS_h) tests/link_test.o
test_wpa: $(OBJS_wpa) $(OBJS_h)
$(LDO) $(LDFLAGS) -o test_wpa $(OBJS_wpa) $(LIBS)
-OBJSa=../src/tls/asn1_test.o ../src/tls/asn1.o ../src/tls/x509v3.o ../src/utils/common.o ../src/utils/wpa_debug.o ../src/utils/os_unix.o \
- ../src/crypto/crypto_$(CONFIG_CRYPTO).o ../src/crypto/md5.o ../src/crypto/sha1.o \
- ../src/crypto/rc4.o ../src/crypto/des.o ../src/crypto/aes_wrap.o \
- ../src/crypto/aes.o ../src/tls/bignum.o ../src/tls/rsa.o
-asn1_test: $(OBJSa)
- $(LDO) $(LDFLAGS) -o asn1_test $(OBJSa)
-
-OBJSx=tests/test_x509v3.o ../src/tls/asn1.o ../src/tls/x509v3.o \
- ../src/utils/common.o ../src/utils/wpa_debug.o ../src/utils/os_unix.o \
- ../src/crypto/crypto_$(CONFIG_CRYPTO).o \
- ../src/crypto/md5.o ../src/crypto/sha1.o ../src/crypto/aes.o \
- ../src/crypto/rc4.o ../src/crypto/des.o ../src/crypto/aes_wrap.o \
- ../src/crypto/sha256.o \
- ../src/tls/bignum.o ../src/tls/rsa.o
-test_x509v3: $(OBJSx)
- $(LDO) $(LDFLAGS) -o test_x509v3 $(OBJSx)
-
win_if_list: win_if_list.c
$(LDO) $(LDFLAGS) -o $@ win_if_list.c $(CFLAGS) $(LIBS_w)
eap_psk.so: ../src/eap_peer/eap_psk.c ../src/eap_common/eap_psk_common.c
- $(CC) -o $@ $(CFLAGS) -shared -rdynamic -fPIC $^ \
+ $(CC) $(LDFLAGS) -o $@ $(CFLAGS) -shared -rdynamic -fPIC $^ \
-Deap_peer_psk_register=eap_peer_method_dynamic_init
eap_pax.so: ../src/eap_peer/eap_pax.c ../src/eap_common/eap_pax_common.c
- $(CC) -o $@ $(CFLAGS) -shared -rdynamic -fPIC $^ \
+ $(CC) $(LDFLAGS) -o $@ $(CFLAGS) -shared -rdynamic -fPIC $^ \
-Deap_peer_pax_register=eap_peer_method_dynamic_init
eap_sake.so: ../src/eap_peer/eap_sake.c ../src/eap_common/eap_sake_common.c
- $(CC) -o $@ $(CFLAGS) -shared -rdynamic -fPIC $^ \
+ $(CC) $(LDFLAGS) -o $@ $(CFLAGS) -shared -rdynamic -fPIC $^ \
-Deap_peer_sake_register=eap_peer_method_dynamic_init
eap_wsc.so: ../src/eap_peer/eap_wsc.c ../src/eap_common/eap_wsc_common.c ../src/wps/wps.c
- $(CC) -o $@ $(CFLAGS) -shared -rdynamic -fPIC $^ \
+ $(CC) $(LDFLAGS) -o $@ $(CFLAGS) -shared -rdynamic -fPIC $^ \
-Deap_peer_wsc_register=eap_peer_method_dynamic_init
eap_ikev2.so: ../src/eap_peer/eap_ikev2.c ../src/eap_peer/ikev2.c ../src/eap_common/eap_ikev2_common.o ../src/eap_common/ikev2_common.c
- $(CC) -o $@ $(CFLAGS) -shared -rdynamic -fPIC $^ \
+ $(CC) $(LDFLAGS) -o $@ $(CFLAGS) -shared -rdynamic -fPIC $^ \
-Deap_peer_ikev2_register=eap_peer_method_dynamic_init
%.so: %.c
- $(CC) -o $@ $(CFLAGS) -shared -rdynamic -fPIC $< \
+ $(CC) $(LDFLAGS) -o $@ $(CFLAGS) -shared -rdynamic -fPIC $< \
-D$(*F:eap_%=eap_peer_%)_register=eap_peer_method_dynamic_init
Q=@
@@ -1188,81 +1354,27 @@ wpa_gui: wpa_gui/Makefile
wpa_gui-qt4/Makefile:
qmake -o wpa_gui-qt4/Makefile wpa_gui-qt4/wpa_gui.pro
-wpa_gui-qt4: wpa_gui-qt4/Makefile
+wpa_gui-qt4/lang/wpa_gui_de.qm: wpa_gui-qt4/lang/wpa_gui_de.ts
+ lrelease wpa_gui-qt4/wpa_gui.pro
+
+wpa_gui-qt4: wpa_gui-qt4/Makefile wpa_gui-qt4/lang/wpa_gui_de.qm
$(MAKE) -C wpa_gui-qt4
-TEST_MS_FUNCS_OBJS = ../src/crypto/crypto_openssl.o ../src/crypto/sha1.o ../src/crypto/md5.o \
- ../src/utils/os_unix.o ../src/crypto/rc4.o tests/test_ms_funcs.o
-test-ms_funcs: $(TEST_MS_FUNCS_OBJS)
- $(LDO) $(LDFLAGS) -o $@ $(TEST_MS_FUNCS_OBJS) $(LIBS) -lcrypto
- ./test-ms_funcs
- rm test-ms_funcs
-
-TEST_SHA1_OBJS = ../src/crypto/sha1.o ../src/crypto/md5.o tests/test_sha1.o #../src/crypto/crypto_openssl.o
-test-sha1: $(TEST_SHA1_OBJS)
- $(LDO) $(LDFLAGS) -o $@ $(TEST_SHA1_OBJS) $(LIBS)
- ./test-sha1
- rm test-sha1
-
-TEST_SHA256_OBJS = ../src/crypto/sha256.o ../src/crypto/md5.o tests/test_sha256.o ../src/utils/os_unix.o ../src/crypto/crypto_openssl.o
-test-sha256: $(TEST_SHA256_OBJS)
- $(LDO) $(LDFLAGS) -o $@ $(TEST_SHA256_OBJS) $(LIBS)
- ./test-sha256
- rm test-sha256
-
-TEST_AES_OBJS = ../src/crypto/aes_wrap.o ../src/crypto/aes.o tests/test_aes.o
-test-aes: $(TEST_AES_OBJS)
- $(LDO) $(LDFLAGS) -o $@ $(TEST_AES_OBJS) $(LIBS)
- ./test-aes
- rm test-aes
-
-TEST_EAP_SIM_COMMON_OBJS = ../src/crypto/sha1.o ../src/crypto/md5.o \
- ../src/crypto/aes_wrap.o ../src/utils/common.o ../src/utils/os_unix.o \
- ../src/utils/wpa_debug.o ../src/crypto/aes.o \
+TEST_EAP_SIM_COMMON_OBJS = $(SHA1OBJS) $(MD5OBJS) \
+ ../src/utils/common.o ../src/utils/os_unix.o \
+ ../src/utils/wpa_debug.o $(AESOBJS) \
tests/test_eap_sim_common.o
test-eap_sim_common: $(TEST_EAP_SIM_COMMON_OBJS)
- $(LDO) $(LDFLAGS) -o $@ $(TEST_AES_OBJS) $(LIBS)
+ $(LDO) $(LDFLAGS) -o $@ $(TEST_EAP_SIM_COMMON_OBJS) $(LIBS)
./test-eap_sim_common
rm test-eap_sim_common
-TEST_MD4_OBJS = ../src/crypto/md4.o tests/test_md4.o #../src/crypto/crypto_openssl.o
-test-md4: $(TEST_MD4_OBJS)
- $(LDO) $(LDFLAGS) -o $@ $(TEST_MD4_OBJS) $(LIBS)
- ./test-md4
- rm test-md4
-
-TEST_MD5_OBJS = ../src/crypto/md5.o tests/test_md5.o #../src/crypto/crypto_openssl.o
-test-md5: $(TEST_MD5_OBJS)
- $(LDO) $(LDFLAGS) -o $@ $(TEST_MD5_OBJS) $(LIBS)
- ./test-md5
- rm test-md5
-
-tests: test-ms_funcs test-sha1 test-aes test-eap_sim_common test-md4 test-md5
+tests: test-eap_sim_common
clean:
$(MAKE) -C ../src clean
+ $(MAKE) -C dbus clean
rm -f core *~ *.o *.d eap_*.so $(ALL) $(WINALL) eapol_test preauth_test
rm -f wpa_priv
-%.eps: %.fig
- fig2dev -L eps $*.fig $*.eps
-
-%.png: %.fig
- fig2dev -L png -m 3 $*.fig | pngtopnm | pnmscale 0.4 | pnmtopng \
- > $*.png
-
-docs-pics: doc/wpa_supplicant.png doc/wpa_supplicant.eps
-
-docs: docs-pics
- (cd ..; doxygen wpa_supplicant/doc/doxygen.full; cd wpa_supplicant)
- $(MAKE) -C doc/latex
- cp doc/latex/refman.pdf wpa_supplicant-devel.pdf
-
-docs-fast: docs-pics
- (cd ..; doxygen wpa_supplicant/doc/doxygen.fast; cd wpa_supplicant)
-
-clean-docs:
- rm -rf doc/latex doc/html
- rm -f doc/wpa_supplicant.{eps,png} wpa_supplicant-devel.pdf
-
-include $(OBJS:%.o=%.d)
diff --git a/contrib/wpa/wpa_supplicant/README b/contrib/wpa/wpa_supplicant/README
index b282150..45c8bae 100644
--- a/contrib/wpa/wpa_supplicant/README
+++ b/contrib/wpa/wpa_supplicant/README
@@ -1,7 +1,7 @@
WPA Supplicant
==============
-Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi> and contributors
+Copyright (c) 2003-2010, Jouni Malinen <j@w1.fi> and contributors
All Rights Reserved.
This program is dual-licensed under both the GPL version 2 and BSD
@@ -497,7 +497,7 @@ options:
-C = ctrl_interface parameter (only used if -c is not)
-i = interface name
-d = increase debugging verbosity (-dd even more)
- -D = driver name
+ -D = driver name (can be multiple drivers: nl80211,wext)
-f = Log output to default log location (normally /tmp)
-g = global ctrl_interface
-K = include keys (passwords, etc.) in debug output
@@ -541,6 +541,13 @@ enabled:
wpa_supplicant -c/etc/wpa_supplicant.conf -iwlan0 -d
+If the specific driver wrapper is not known beforehand, it is possible
+to specify multiple comma separated driver wrappers on the command
+line. wpa_supplicant will use the first driver wrapper that is able to
+initialize the interface.
+
+wpa_supplicant -Dnl80211,wext -c/etc/wpa_supplicant.conf -iwlan0
+
wpa_supplicant can control multiple interfaces (radios) either by
running one process for each interface separately or by running just
diff --git a/contrib/wpa/wpa_supplicant/README-WPS b/contrib/wpa/wpa_supplicant/README-WPS
index 6b826a7..8f0d0d6 100644
--- a/contrib/wpa/wpa_supplicant/README-WPS
+++ b/contrib/wpa/wpa_supplicant/README-WPS
@@ -61,7 +61,6 @@ configuration that includes WPS support and Linux wireless extensions
-based driver interface:
CONFIG_DRIVER_WEXT=y
-CONFIG_EAP=y
CONFIG_WPS=y
@@ -131,17 +130,29 @@ negotiation which will generate a new WPA PSK in the same way as the
PIN method described above.
-If the client wants to operate in the Registrar role to configure an
-AP, wpa_supplicant is notified over the control interface, e.g., with
+If the client wants to operate in the Registrar role to learn the
+current AP configuration and optionally, to configure an AP,
+wpa_supplicant is notified over the control interface, e.g., with
wpa_cli:
wpa_cli wps_reg <AP BSSID> <AP PIN>
(example: wpa_cli wps_reg 02:34:56:78:9a:bc 12345670)
-This is currently only used to fetch the current AP settings instead
-of actually changing them. The main difference with the wps_pin
-command is that wps_reg uses the AP PIN (e.g., from a label on the AP)
-instead of a PIN generated at the client.
+This is used to fetch the current AP settings instead of actually
+changing them. The main difference with the wps_pin command is that
+wps_reg uses the AP PIN (e.g., from a label on the AP) instead of a
+PIN generated at the client.
+
+In order to change the AP configuration, the new configuration
+parameters are given to the wps_reg command:
+
+wpa_cli wps_reg <AP BSSID> <AP PIN> <new SSID> <auth> <encr> <new key>
+examples:
+ wpa_cli wps_reg 02:34:56:78:9a:bc 12345670 testing WPA2PSK CCMP 12345678
+ wpa_cli wps_reg 02:34:56:78:9a:bc 12345670 clear OPEN NONE ""
+
+<auth> must be one of the following: OPEN WPAPSK WPA2PSK
+<encr> must be one of the following: NONE WEP TKIP CCMP
Scanning
diff --git a/contrib/wpa/wpa_supplicant/ap.c b/contrib/wpa/wpa_supplicant/ap.c
new file mode 100644
index 0000000..2b93984
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/ap.c
@@ -0,0 +1,481 @@
+/*
+ * WPA Supplicant - Basic AP mode support routines
+ * Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2009, Atheros Communications
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "utils/includes.h"
+
+#include "utils/common.h"
+#include "common/ieee802_11_defs.h"
+#include "ap/hostapd.h"
+#include "ap/ap_config.h"
+#ifdef NEED_AP_MLME
+#include "ap/ieee802_11.h"
+#endif /* NEED_AP_MLME */
+#include "ap/ieee802_1x.h"
+#include "ap/wps_hostapd.h"
+#include "ap/ctrl_iface_ap.h"
+#include "eap_common/eap_defs.h"
+#include "eap_server/eap_methods.h"
+#include "eap_common/eap_wsc_common.h"
+#include "wps/wps.h"
+#include "config_ssid.h"
+#include "config.h"
+#include "wpa_supplicant_i.h"
+#include "driver_i.h"
+#include "ap.h"
+
+
+static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid,
+ struct hostapd_config *conf)
+{
+ struct hostapd_bss_config *bss = &conf->bss[0];
+ int pairwise;
+
+ conf->driver = wpa_s->driver;
+
+ os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
+
+ if (ssid->frequency == 0) {
+ /* default channel 11 */
+ conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
+ conf->channel = 11;
+ } else if (ssid->frequency >= 2412 && ssid->frequency <= 2472) {
+ conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
+ conf->channel = (ssid->frequency - 2407) / 5;
+ } else if ((ssid->frequency >= 5180 && ssid->frequency <= 5240) ||
+ (ssid->frequency >= 5745 && ssid->frequency <= 5825)) {
+ conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
+ conf->channel = (ssid->frequency - 5000) / 5;
+ } else {
+ wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz",
+ ssid->frequency);
+ return -1;
+ }
+
+ /* TODO: enable HT if driver supports it;
+ * drop to 11b if driver does not support 11g */
+
+ if (ssid->ssid_len == 0) {
+ wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
+ return -1;
+ }
+ os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
+ bss->ssid.ssid[ssid->ssid_len] = '\0';
+ bss->ssid.ssid_len = ssid->ssid_len;
+ bss->ssid.ssid_set = 1;
+
+ if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
+ bss->wpa = ssid->proto;
+ bss->wpa_key_mgmt = ssid->key_mgmt;
+ bss->wpa_pairwise = ssid->pairwise_cipher;
+ if (ssid->passphrase) {
+ bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
+ } else if (ssid->psk_set) {
+ os_free(bss->ssid.wpa_psk);
+ bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
+ if (bss->ssid.wpa_psk == NULL)
+ return -1;
+ os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
+ bss->ssid.wpa_psk->group = 1;
+ }
+
+ /* Select group cipher based on the enabled pairwise cipher suites */
+ pairwise = 0;
+ if (bss->wpa & 1)
+ pairwise |= bss->wpa_pairwise;
+ if (bss->wpa & 2) {
+ if (bss->rsn_pairwise == 0)
+ bss->rsn_pairwise = bss->wpa_pairwise;
+ pairwise |= bss->rsn_pairwise;
+ }
+ if (pairwise & WPA_CIPHER_TKIP)
+ bss->wpa_group = WPA_CIPHER_TKIP;
+ else
+ bss->wpa_group = WPA_CIPHER_CCMP;
+
+ if (bss->wpa && bss->ieee802_1x)
+ bss->ssid.security_policy = SECURITY_WPA;
+ else if (bss->wpa)
+ bss->ssid.security_policy = SECURITY_WPA_PSK;
+ else if (bss->ieee802_1x) {
+ bss->ssid.security_policy = SECURITY_IEEE_802_1X;
+ bss->ssid.wep.default_len = bss->default_wep_key_len;
+ } else if (bss->ssid.wep.keys_set)
+ bss->ssid.security_policy = SECURITY_STATIC_WEP;
+ else
+ bss->ssid.security_policy = SECURITY_PLAINTEXT;
+
+#ifdef CONFIG_WPS
+ /*
+ * Enable WPS by default, but require user interaction to actually use
+ * it. Only the internal Registrar is supported.
+ */
+ bss->eap_server = 1;
+ bss->wps_state = 2;
+ bss->ap_setup_locked = 1;
+ if (wpa_s->conf->config_methods)
+ bss->config_methods = os_strdup(wpa_s->conf->config_methods);
+ if (wpa_s->conf->device_type)
+ bss->device_type = os_strdup(wpa_s->conf->device_type);
+#endif /* CONFIG_WPS */
+
+ return 0;
+}
+
+
+static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
+{
+}
+
+
+static int ap_probe_req_rx(void *ctx, const u8 *addr, const u8 *ie,
+ size_t ie_len)
+{
+ return 0;
+}
+
+
+static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
+ const u8 *uuid_e)
+{
+}
+
+
+int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid)
+{
+ struct wpa_driver_associate_params params;
+ struct hostapd_iface *hapd_iface;
+ struct hostapd_config *conf;
+ size_t i;
+
+ if (ssid->ssid == NULL || ssid->ssid_len == 0) {
+ wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
+ return -1;
+ }
+
+ wpa_supplicant_ap_deinit(wpa_s);
+
+ wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
+ wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
+
+ os_memset(&params, 0, sizeof(params));
+ params.ssid = ssid->ssid;
+ params.ssid_len = ssid->ssid_len;
+ switch (ssid->mode) {
+ case WPAS_MODE_INFRA:
+ params.mode = IEEE80211_MODE_INFRA;
+ break;
+ case WPAS_MODE_IBSS:
+ params.mode = IEEE80211_MODE_IBSS;
+ break;
+ case WPAS_MODE_AP:
+ params.mode = IEEE80211_MODE_AP;
+ break;
+ }
+ params.freq = ssid->frequency;
+
+ if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
+ wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
+ else
+ wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
+ params.key_mgmt_suite = key_mgmt2driver(wpa_s->key_mgmt);
+
+ if (ssid->pairwise_cipher & WPA_CIPHER_CCMP)
+ wpa_s->pairwise_cipher = WPA_CIPHER_CCMP;
+ else if (ssid->pairwise_cipher & WPA_CIPHER_TKIP)
+ wpa_s->pairwise_cipher = WPA_CIPHER_TKIP;
+ else if (ssid->pairwise_cipher & WPA_CIPHER_NONE)
+ wpa_s->pairwise_cipher = WPA_CIPHER_NONE;
+ else {
+ wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
+ "cipher.");
+ return -1;
+ }
+ params.pairwise_suite = cipher_suite2driver(wpa_s->pairwise_cipher);
+ params.group_suite = params.pairwise_suite;
+
+ if (wpa_drv_associate(wpa_s, &params) < 0) {
+ wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
+ return -1;
+ }
+
+ wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
+ if (hapd_iface == NULL)
+ return -1;
+ hapd_iface->owner = wpa_s;
+
+ wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
+ if (conf == NULL) {
+ wpa_supplicant_ap_deinit(wpa_s);
+ return -1;
+ }
+
+ if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
+ wpa_printf(MSG_ERROR, "Failed to create AP configuration");
+ wpa_supplicant_ap_deinit(wpa_s);
+ return -1;
+ }
+
+ hapd_iface->num_bss = conf->num_bss;
+ hapd_iface->bss = os_zalloc(conf->num_bss *
+ sizeof(struct hostapd_data *));
+ if (hapd_iface->bss == NULL) {
+ wpa_supplicant_ap_deinit(wpa_s);
+ return -1;
+ }
+
+ for (i = 0; i < conf->num_bss; i++) {
+ hapd_iface->bss[i] =
+ hostapd_alloc_bss_data(hapd_iface, conf,
+ &conf->bss[i]);
+ if (hapd_iface->bss[i] == NULL) {
+ wpa_supplicant_ap_deinit(wpa_s);
+ return -1;
+ }
+
+ hapd_iface->bss[i]->msg_ctx = wpa_s;
+ hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
+ hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
+ hostapd_register_probereq_cb(hapd_iface->bss[i],
+ ap_probe_req_rx, wpa_s);
+ hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
+ hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
+ }
+
+ os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
+ hapd_iface->bss[0]->driver = wpa_s->driver;
+ hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
+
+ if (hostapd_setup_interface(wpa_s->ap_iface)) {
+ wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
+ wpa_supplicant_ap_deinit(wpa_s);
+ return -1;
+ }
+
+ wpa_s->current_ssid = ssid;
+ os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
+ wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
+
+ if (wpa_s->ap_configured_cb)
+ wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
+ wpa_s->ap_configured_cb_data);
+
+ return 0;
+}
+
+
+void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
+{
+ if (wpa_s->ap_iface == NULL)
+ return;
+
+ wpa_s->current_ssid = NULL;
+ hostapd_interface_deinit(wpa_s->ap_iface);
+ hostapd_interface_free(wpa_s->ap_iface);
+ wpa_s->ap_iface = NULL;
+ wpa_drv_deinit_ap(wpa_s);
+}
+
+
+void ap_tx_status(void *ctx, const u8 *addr,
+ const u8 *buf, size_t len, int ack)
+{
+#ifdef NEED_AP_MLME
+ struct wpa_supplicant *wpa_s = ctx;
+ hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
+#endif /* NEED_AP_MLME */
+}
+
+
+void ap_rx_from_unknown_sta(void *ctx, const u8 *frame, size_t len)
+{
+#ifdef NEED_AP_MLME
+ struct wpa_supplicant *wpa_s = ctx;
+ const struct ieee80211_hdr *hdr =
+ (const struct ieee80211_hdr *) frame;
+ u16 fc = le_to_host16(hdr->frame_control);
+ ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], hdr->addr2,
+ (fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) ==
+ (WLAN_FC_TODS | WLAN_FC_FROMDS));
+#endif /* NEED_AP_MLME */
+}
+
+
+void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
+{
+#ifdef NEED_AP_MLME
+ struct wpa_supplicant *wpa_s = ctx;
+ struct hostapd_frame_info fi;
+ os_memset(&fi, 0, sizeof(fi));
+ fi.datarate = rx_mgmt->datarate;
+ fi.ssi_signal = rx_mgmt->ssi_signal;
+ ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
+ rx_mgmt->frame_len, &fi);
+#endif /* NEED_AP_MLME */
+}
+
+
+void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
+{
+#ifdef NEED_AP_MLME
+ struct wpa_supplicant *wpa_s = ctx;
+ ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
+#endif /* NEED_AP_MLME */
+}
+
+
+void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
+ const u8 *src_addr, const u8 *buf, size_t len)
+{
+ ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
+}
+
+
+#ifdef CONFIG_WPS
+
+int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid)
+{
+ if (!wpa_s->ap_iface)
+ return -1;
+ return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0]);
+}
+
+
+int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
+ const char *pin, char *buf, size_t buflen)
+{
+ int ret, ret_len = 0;
+
+ if (!wpa_s->ap_iface)
+ return -1;
+
+ if (pin == NULL) {
+ unsigned int rpin = wps_generate_pin();
+ ret_len = os_snprintf(buf, buflen, "%d", rpin);
+ pin = buf;
+ }
+
+ ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], "any", pin, 0);
+ if (ret)
+ return -1;
+ return ret_len;
+}
+
+#endif /* CONFIG_WPS */
+
+
+#ifdef CONFIG_CTRL_IFACE
+
+int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
+ char *buf, size_t buflen)
+{
+ if (wpa_s->ap_iface == NULL)
+ return -1;
+ return hostapd_ctrl_iface_sta_first(wpa_s->ap_iface->bss[0],
+ buf, buflen);
+}
+
+
+int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
+ char *buf, size_t buflen)
+{
+ if (wpa_s->ap_iface == NULL)
+ return -1;
+ return hostapd_ctrl_iface_sta(wpa_s->ap_iface->bss[0], txtaddr,
+ buf, buflen);
+}
+
+
+int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
+ char *buf, size_t buflen)
+{
+ if (wpa_s->ap_iface == NULL)
+ return -1;
+ return hostapd_ctrl_iface_sta_next(wpa_s->ap_iface->bss[0], txtaddr,
+ buf, buflen);
+}
+
+
+int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
+ size_t buflen, int verbose)
+{
+ char *pos = buf, *end = buf + buflen;
+ int ret;
+ struct hostapd_bss_config *conf;
+
+ if (wpa_s->ap_iface == NULL)
+ return -1;
+
+ conf = wpa_s->ap_iface->bss[0]->conf;
+ if (conf->wpa == 0)
+ return 0;
+
+ ret = os_snprintf(pos, end - pos,
+ "pairwise_cipher=%s\n"
+ "group_cipher=%s\n"
+ "key_mgmt=%s\n",
+ wpa_cipher_txt(conf->rsn_pairwise),
+ wpa_cipher_txt(conf->wpa_group),
+ wpa_key_mgmt_txt(conf->wpa_key_mgmt,
+ conf->wpa));
+ if (ret < 0 || ret >= end - pos)
+ return pos - buf;
+ pos += ret;
+ return pos - buf;
+}
+
+#endif /* CONFIG_CTRL_IFACE */
+
+
+int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
+ const u8 *addr)
+{
+ struct hostapd_data *hapd;
+ struct hostapd_bss_config *conf;
+
+ if (!wpa_s->ap_iface)
+ return -1;
+
+ if (addr)
+ wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
+ MAC2STR(addr));
+ else
+ wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
+
+ hapd = wpa_s->ap_iface->bss[0];
+ conf = hapd->conf;
+
+ os_free(conf->accept_mac);
+ conf->accept_mac = NULL;
+ conf->num_accept_mac = 0;
+ os_free(conf->deny_mac);
+ conf->deny_mac = NULL;
+ conf->num_deny_mac = 0;
+
+ if (addr == NULL) {
+ conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
+ return 0;
+ }
+
+ conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
+ conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
+ if (conf->accept_mac == NULL)
+ return -1;
+ os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
+ conf->num_accept_mac = 1;
+
+ return 0;
+}
diff --git a/contrib/wpa/wpa_supplicant/ap.h b/contrib/wpa/wpa_supplicant/ap.h
new file mode 100644
index 0000000..381a432
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/ap.h
@@ -0,0 +1,43 @@
+/*
+ * WPA Supplicant - Basic AP mode support routines
+ * Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2009, Atheros Communications
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef AP_H
+#define AP_H
+
+int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid);
+void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s);
+void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
+ const u8 *src_addr, const u8 *buf, size_t len);
+int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid);
+int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
+ const char *pin, char *buf, size_t buflen);
+int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
+ char *buf, size_t buflen);
+int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
+ char *buf, size_t buflen);
+int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
+ char *buf, size_t buflen);
+int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
+ size_t buflen, int verbose);
+void ap_tx_status(void *ctx, const u8 *addr,
+ const u8 *buf, size_t len, int ack);
+void ap_rx_from_unknown_sta(void *ctx, const u8 *frame, size_t len);
+void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt);
+void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok);
+int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
+ const u8 *addr);
+
+#endif /* AP_H */
diff --git a/contrib/wpa/wpa_supplicant/bgscan.c b/contrib/wpa/wpa_supplicant/bgscan.c
new file mode 100644
index 0000000..31b5d27
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/bgscan.c
@@ -0,0 +1,110 @@
+/*
+ * WPA Supplicant - background scan and roaming interface
+ * Copyright (c) 2009-2010, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "wpa_supplicant_i.h"
+#include "config_ssid.h"
+#include "bgscan.h"
+
+#ifdef CONFIG_BGSCAN_SIMPLE
+extern const struct bgscan_ops bgscan_simple_ops;
+#endif /* CONFIG_BGSCAN_SIMPLE */
+
+static const struct bgscan_ops * bgscan_modules[] = {
+#ifdef CONFIG_BGSCAN_SIMPLE
+ &bgscan_simple_ops,
+#endif /* CONFIG_BGSCAN_SIMPLE */
+ NULL
+};
+
+
+int bgscan_init(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
+{
+ const char *name = ssid->bgscan;
+ const char *params;
+ size_t nlen;
+ int i;
+ const struct bgscan_ops *ops = NULL;
+
+ bgscan_deinit(wpa_s);
+ if (name == NULL)
+ return 0;
+
+ params = os_strchr(name, ':');
+ if (params == NULL) {
+ params = "";
+ nlen = os_strlen(name);
+ } else {
+ nlen = params - name;
+ params++;
+ }
+
+ for (i = 0; bgscan_modules[i]; i++) {
+ if (os_strncmp(name, bgscan_modules[i]->name, nlen) == 0) {
+ ops = bgscan_modules[i];
+ break;
+ }
+ }
+
+ if (ops == NULL) {
+ wpa_printf(MSG_ERROR, "bgscan: Could not find module "
+ "matching the parameter '%s'", name);
+ return -1;
+ }
+
+ wpa_s->bgscan_priv = ops->init(wpa_s, params, ssid);
+ if (wpa_s->bgscan_priv == NULL)
+ return -1;
+ wpa_s->bgscan = ops;
+ wpa_printf(MSG_DEBUG, "bgscan: Initialized module '%s' with "
+ "parameters '%s'", ops->name, params);
+
+ return 0;
+}
+
+
+void bgscan_deinit(struct wpa_supplicant *wpa_s)
+{
+ if (wpa_s->bgscan && wpa_s->bgscan_priv) {
+ wpa_printf(MSG_DEBUG, "bgscan: Deinitializing module '%s'",
+ wpa_s->bgscan->name);
+ wpa_s->bgscan->deinit(wpa_s->bgscan_priv);
+ wpa_s->bgscan = NULL;
+ wpa_s->bgscan_priv = NULL;
+ }
+}
+
+
+int bgscan_notify_scan(struct wpa_supplicant *wpa_s)
+{
+ if (wpa_s->bgscan && wpa_s->bgscan_priv)
+ return wpa_s->bgscan->notify_scan(wpa_s->bgscan_priv);
+ return 0;
+}
+
+
+void bgscan_notify_beacon_loss(struct wpa_supplicant *wpa_s)
+{
+ if (wpa_s->bgscan && wpa_s->bgscan_priv)
+ wpa_s->bgscan->notify_beacon_loss(wpa_s->bgscan_priv);
+}
+
+
+void bgscan_notify_signal_change(struct wpa_supplicant *wpa_s, int above)
+{
+ if (wpa_s->bgscan && wpa_s->bgscan_priv)
+ wpa_s->bgscan->notify_signal_change(wpa_s->bgscan_priv, above);
+}
diff --git a/contrib/wpa/wpa_supplicant/bgscan.h b/contrib/wpa/wpa_supplicant/bgscan.h
new file mode 100644
index 0000000..69e99b6
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/bgscan.h
@@ -0,0 +1,69 @@
+/*
+ * WPA Supplicant - background scan and roaming interface
+ * Copyright (c) 2009-2010, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef BGSCAN_H
+#define BGSCAN_H
+
+struct wpa_supplicant;
+struct wpa_ssid;
+
+struct bgscan_ops {
+ const char *name;
+
+ void * (*init)(struct wpa_supplicant *wpa_s, const char *params,
+ const struct wpa_ssid *ssid);
+ void (*deinit)(void *priv);
+
+ int (*notify_scan)(void *priv);
+ void (*notify_beacon_loss)(void *priv);
+ void (*notify_signal_change)(void *priv, int above);
+};
+
+#ifdef CONFIG_BGSCAN
+
+int bgscan_init(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid);
+void bgscan_deinit(struct wpa_supplicant *wpa_s);
+int bgscan_notify_scan(struct wpa_supplicant *wpa_s);
+void bgscan_notify_beacon_loss(struct wpa_supplicant *wpa_s);
+void bgscan_notify_signal_change(struct wpa_supplicant *wpa_s, int above);
+
+#else /* CONFIG_BGSCAN */
+
+static inline int bgscan_init(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid)
+{
+ return 0;
+}
+
+static inline void bgscan_deinit(struct wpa_supplicant *wpa_s)
+{
+}
+
+static inline int bgscan_notify_scan(struct wpa_supplicant *wpa_s)
+{
+ return 0;
+}
+
+static inline void bgscan_notify_beacon_loss(struct wpa_supplicant *wpa_s)
+{
+}
+
+static inline void bgscan_notify_signal_change(struct wpa_supplicant *wpa_s,
+ int above)
+{
+}
+
+#endif /* CONFIG_BGSCAN */
+
+#endif /* BGSCAN_H */
diff --git a/contrib/wpa/wpa_supplicant/bgscan_simple.c b/contrib/wpa/wpa_supplicant/bgscan_simple.c
new file mode 100644
index 0000000..8e80b12
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/bgscan_simple.c
@@ -0,0 +1,230 @@
+/*
+ * WPA Supplicant - background scan and roaming module: simple
+ * Copyright (c) 2009-2010, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "eloop.h"
+#include "drivers/driver.h"
+#include "config_ssid.h"
+#include "wpa_supplicant_i.h"
+#include "driver_i.h"
+#include "scan.h"
+#include "bgscan.h"
+
+struct bgscan_simple_data {
+ struct wpa_supplicant *wpa_s;
+ const struct wpa_ssid *ssid;
+ int scan_interval;
+ int signal_threshold;
+ int short_interval; /* use if signal < threshold */
+ int long_interval; /* use if signal > threshold */
+ struct os_time last_bgscan;
+};
+
+
+static void bgscan_simple_timeout(void *eloop_ctx, void *timeout_ctx)
+{
+ struct bgscan_simple_data *data = eloop_ctx;
+ struct wpa_supplicant *wpa_s = data->wpa_s;
+ struct wpa_driver_scan_params params;
+
+ os_memset(&params, 0, sizeof(params));
+ params.num_ssids = 1;
+ params.ssids[0].ssid = data->ssid->ssid;
+ params.ssids[0].ssid_len = data->ssid->ssid_len;
+ params.freqs = data->ssid->scan_freq;
+
+ /*
+ * A more advanced bgscan module would learn about most like channels
+ * over time and request scans only for some channels (probing others
+ * every now and then) to reduce effect on the data connection.
+ */
+
+ wpa_printf(MSG_DEBUG, "bgscan simple: Request a background scan");
+ if (wpa_supplicant_trigger_scan(wpa_s, &params)) {
+ wpa_printf(MSG_DEBUG, "bgscan simple: Failed to trigger scan");
+ eloop_register_timeout(data->scan_interval, 0,
+ bgscan_simple_timeout, data, NULL);
+ } else
+ os_get_time(&data->last_bgscan);
+}
+
+
+static int bgscan_simple_get_params(struct bgscan_simple_data *data,
+ const char *params)
+{
+ const char *pos;
+
+ if (params == NULL)
+ return 0;
+
+ data->short_interval = atoi(params);
+
+ pos = os_strchr(params, ':');
+ if (pos == NULL)
+ return 0;
+ pos++;
+ data->signal_threshold = atoi(pos);
+ pos = os_strchr(pos, ':');
+ if (pos == NULL) {
+ wpa_printf(MSG_ERROR, "bgscan simple: Missing scan interval "
+ "for high signal");
+ return -1;
+ }
+ pos++;
+ data->long_interval = atoi(pos);
+
+ return 0;
+}
+
+
+static void * bgscan_simple_init(struct wpa_supplicant *wpa_s,
+ const char *params,
+ const struct wpa_ssid *ssid)
+{
+ struct bgscan_simple_data *data;
+
+ data = os_zalloc(sizeof(*data));
+ if (data == NULL)
+ return NULL;
+ data->wpa_s = wpa_s;
+ data->ssid = ssid;
+ if (bgscan_simple_get_params(data, params) < 0) {
+ os_free(data);
+ return NULL;
+ }
+ if (data->short_interval <= 0)
+ data->short_interval = 30;
+ if (data->long_interval <= 0)
+ data->long_interval = 30;
+
+ wpa_printf(MSG_DEBUG, "bgscan simple: Signal strength threshold %d "
+ "Short bgscan interval %d Long bgscan interval %d",
+ data->signal_threshold, data->short_interval,
+ data->long_interval);
+
+ if (data->signal_threshold &&
+ wpa_drv_signal_monitor(wpa_s, data->signal_threshold, 4) < 0) {
+ wpa_printf(MSG_ERROR, "bgscan simple: Failed to enable "
+ "signal strength monitoring");
+ }
+
+ data->scan_interval = data->short_interval;
+ eloop_register_timeout(data->scan_interval, 0, bgscan_simple_timeout,
+ data, NULL);
+
+ /*
+ * This function is called immediately after an association, so it is
+ * reasonable to assume that a scan was completed recently. This makes
+ * us skip an immediate new scan in cases where the current signal
+ * level is below the bgscan threshold.
+ */
+ os_get_time(&data->last_bgscan);
+
+ return data;
+}
+
+
+static void bgscan_simple_deinit(void *priv)
+{
+ struct bgscan_simple_data *data = priv;
+ eloop_cancel_timeout(bgscan_simple_timeout, data, NULL);
+ if (data->signal_threshold)
+ wpa_drv_signal_monitor(data->wpa_s, 0, 0);
+ os_free(data);
+}
+
+
+static int bgscan_simple_notify_scan(void *priv)
+{
+ struct bgscan_simple_data *data = priv;
+
+ wpa_printf(MSG_DEBUG, "bgscan simple: scan result notification");
+
+ eloop_cancel_timeout(bgscan_simple_timeout, data, NULL);
+ eloop_register_timeout(data->scan_interval, 0, bgscan_simple_timeout,
+ data, NULL);
+
+ /*
+ * A more advanced bgscan could process scan results internally, select
+ * the BSS and request roam if needed. This sample uses the existing
+ * BSS/ESS selection routine. Change this to return 1 if selection is
+ * done inside the bgscan module.
+ */
+
+ return 0;
+}
+
+
+static void bgscan_simple_notify_beacon_loss(void *priv)
+{
+ wpa_printf(MSG_DEBUG, "bgscan simple: beacon loss");
+ /* TODO: speed up background scanning */
+}
+
+
+static void bgscan_simple_notify_signal_change(void *priv, int above)
+{
+ struct bgscan_simple_data *data = priv;
+ int scan = 0;
+ struct os_time now;
+
+ if (data->short_interval == data->long_interval ||
+ data->signal_threshold == 0)
+ return;
+
+ wpa_printf(MSG_DEBUG, "bgscan simple: signal level changed "
+ "(above=%d)", above);
+ if (data->scan_interval == data->long_interval && !above) {
+ wpa_printf(MSG_DEBUG, "bgscan simple: Start using short "
+ "bgscan interval");
+ data->scan_interval = data->short_interval;
+ os_get_time(&now);
+ if (now.sec > data->last_bgscan.sec + 1)
+ scan = 1;
+ } else if (data->scan_interval == data->short_interval && above) {
+ wpa_printf(MSG_DEBUG, "bgscan simple: Start using long bgscan "
+ "interval");
+ data->scan_interval = data->long_interval;
+ eloop_cancel_timeout(bgscan_simple_timeout, data, NULL);
+ eloop_register_timeout(data->scan_interval, 0,
+ bgscan_simple_timeout, data, NULL);
+ } else if (!above) {
+ /*
+ * Signal dropped further 4 dB. Request a new scan if we have
+ * not yet scanned in a while.
+ */
+ os_get_time(&now);
+ if (now.sec > data->last_bgscan.sec + 10)
+ scan = 1;
+ }
+
+ if (scan) {
+ wpa_printf(MSG_DEBUG, "bgscan simple: Trigger immediate scan");
+ eloop_cancel_timeout(bgscan_simple_timeout, data, NULL);
+ eloop_register_timeout(0, 0, bgscan_simple_timeout, data,
+ NULL);
+ }
+}
+
+
+const struct bgscan_ops bgscan_simple_ops = {
+ .name = "simple",
+ .init = bgscan_simple_init,
+ .deinit = bgscan_simple_deinit,
+ .notify_scan = bgscan_simple_notify_scan,
+ .notify_beacon_loss = bgscan_simple_notify_beacon_loss,
+ .notify_signal_change = bgscan_simple_notify_signal_change,
+};
diff --git a/contrib/wpa/wpa_supplicant/bss.c b/contrib/wpa/wpa_supplicant/bss.c
new file mode 100644
index 0000000..e2ac230
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/bss.c
@@ -0,0 +1,606 @@
+/*
+ * BSS table
+ * Copyright (c) 2009-2010, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "utils/includes.h"
+
+#include "utils/common.h"
+#include "utils/eloop.h"
+#include "common/ieee802_11_defs.h"
+#include "drivers/driver.h"
+#include "wpa_supplicant_i.h"
+#include "config.h"
+#include "notify.h"
+#include "scan.h"
+#include "bss.h"
+
+
+/**
+ * WPA_BSS_EXPIRATION_PERIOD - Period of expiration run in seconds
+ */
+#define WPA_BSS_EXPIRATION_PERIOD 10
+
+/**
+ * WPA_BSS_EXPIRATION_AGE - BSS entry age after which it can be expired
+ *
+ * This value control the time in seconds after which a BSS entry gets removed
+ * if it has not been updated or is not in use.
+ */
+#define WPA_BSS_EXPIRATION_AGE 180
+
+/**
+ * WPA_BSS_EXPIRATION_SCAN_COUNT - Expire BSS after number of scans
+ *
+ * If the BSS entry has not been seen in this many scans, it will be removed.
+ * Value 1 means that the entry is removed after the first scan without the
+ * BSSID being seen. Larger values can be used to avoid BSS entries
+ * disappearing if they are not visible in every scan (e.g., low signal quality
+ * or interference).
+ */
+#define WPA_BSS_EXPIRATION_SCAN_COUNT 2
+
+#define WPA_BSS_FREQ_CHANGED_FLAG BIT(0)
+#define WPA_BSS_SIGNAL_CHANGED_FLAG BIT(1)
+#define WPA_BSS_PRIVACY_CHANGED_FLAG BIT(2)
+#define WPA_BSS_MODE_CHANGED_FLAG BIT(3)
+#define WPA_BSS_WPAIE_CHANGED_FLAG BIT(4)
+#define WPA_BSS_RSNIE_CHANGED_FLAG BIT(5)
+#define WPA_BSS_WPS_CHANGED_FLAG BIT(6)
+#define WPA_BSS_RATES_CHANGED_FLAG BIT(7)
+#define WPA_BSS_IES_CHANGED_FLAG BIT(8)
+
+
+static void wpa_bss_remove(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
+{
+ dl_list_del(&bss->list);
+ dl_list_del(&bss->list_id);
+ wpa_s->num_bss--;
+ wpa_printf(MSG_DEBUG, "BSS: Remove id %u BSSID " MACSTR " SSID '%s'",
+ bss->id, MAC2STR(bss->bssid),
+ wpa_ssid_txt(bss->ssid, bss->ssid_len));
+ wpas_notify_bss_removed(wpa_s, bss->bssid, bss->id);
+ os_free(bss);
+}
+
+
+struct wpa_bss * wpa_bss_get(struct wpa_supplicant *wpa_s, const u8 *bssid,
+ const u8 *ssid, size_t ssid_len)
+{
+ struct wpa_bss *bss;
+ dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
+ if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0 &&
+ bss->ssid_len == ssid_len &&
+ os_memcmp(bss->ssid, ssid, ssid_len) == 0)
+ return bss;
+ }
+ return NULL;
+}
+
+
+static void wpa_bss_copy_res(struct wpa_bss *dst, struct wpa_scan_res *src)
+{
+ os_time_t usec;
+
+ dst->flags = src->flags;
+ os_memcpy(dst->bssid, src->bssid, ETH_ALEN);
+ dst->freq = src->freq;
+ dst->beacon_int = src->beacon_int;
+ dst->caps = src->caps;
+ dst->qual = src->qual;
+ dst->noise = src->noise;
+ dst->level = src->level;
+ dst->tsf = src->tsf;
+
+ os_get_time(&dst->last_update);
+ dst->last_update.sec -= src->age / 1000;
+ usec = (src->age % 1000) * 1000;
+ if (dst->last_update.usec < usec) {
+ dst->last_update.sec--;
+ dst->last_update.usec += 1000000;
+ }
+ dst->last_update.usec -= usec;
+}
+
+
+static void wpa_bss_add(struct wpa_supplicant *wpa_s,
+ const u8 *ssid, size_t ssid_len,
+ struct wpa_scan_res *res)
+{
+ struct wpa_bss *bss;
+
+ bss = os_zalloc(sizeof(*bss) + res->ie_len + res->beacon_ie_len);
+ if (bss == NULL)
+ return;
+ bss->id = wpa_s->bss_next_id++;
+ bss->last_update_idx = wpa_s->bss_update_idx;
+ wpa_bss_copy_res(bss, res);
+ os_memcpy(bss->ssid, ssid, ssid_len);
+ bss->ssid_len = ssid_len;
+ bss->ie_len = res->ie_len;
+ bss->beacon_ie_len = res->beacon_ie_len;
+ os_memcpy(bss + 1, res + 1, res->ie_len + res->beacon_ie_len);
+
+ dl_list_add_tail(&wpa_s->bss, &bss->list);
+ dl_list_add_tail(&wpa_s->bss_id, &bss->list_id);
+ wpa_s->num_bss++;
+ wpa_printf(MSG_DEBUG, "BSS: Add new id %u BSSID " MACSTR " SSID '%s'",
+ bss->id, MAC2STR(bss->bssid), wpa_ssid_txt(ssid, ssid_len));
+ wpas_notify_bss_added(wpa_s, bss->bssid, bss->id);
+ if (wpa_s->num_bss > wpa_s->conf->bss_max_count) {
+ /* Remove the oldest entry */
+ wpa_bss_remove(wpa_s, dl_list_first(&wpa_s->bss,
+ struct wpa_bss, list));
+ }
+}
+
+
+static int are_ies_equal(const struct wpa_bss *old,
+ const struct wpa_scan_res *new, u32 ie)
+{
+ const u8 *old_ie, *new_ie;
+ struct wpabuf *old_ie_buff = NULL;
+ struct wpabuf *new_ie_buff = NULL;
+ int new_ie_len, old_ie_len, ret, is_multi;
+
+ switch (ie) {
+ case WPA_IE_VENDOR_TYPE:
+ old_ie = wpa_bss_get_vendor_ie(old, ie);
+ new_ie = wpa_scan_get_vendor_ie(new, ie);
+ is_multi = 0;
+ break;
+ case WPS_IE_VENDOR_TYPE:
+ old_ie_buff = wpa_bss_get_vendor_ie_multi(old, ie);
+ new_ie_buff = wpa_scan_get_vendor_ie_multi(new, ie);
+ is_multi = 1;
+ break;
+ case WLAN_EID_RSN:
+ case WLAN_EID_SUPP_RATES:
+ case WLAN_EID_EXT_SUPP_RATES:
+ old_ie = wpa_bss_get_ie(old, ie);
+ new_ie = wpa_scan_get_ie(new, ie);
+ is_multi = 0;
+ break;
+ default:
+ wpa_printf(MSG_DEBUG, "bss: %s: cannot compare IEs", __func__);
+ return 0;
+ }
+
+ if (is_multi) {
+ /* in case of multiple IEs stored in buffer */
+ old_ie = old_ie_buff ? wpabuf_head_u8(old_ie_buff) : NULL;
+ new_ie = new_ie_buff ? wpabuf_head_u8(new_ie_buff) : NULL;
+ old_ie_len = old_ie_buff ? wpabuf_len(old_ie_buff) : 0;
+ new_ie_len = new_ie_buff ? wpabuf_len(new_ie_buff) : 0;
+ } else {
+ /* in case of single IE */
+ old_ie_len = old_ie ? old_ie[1] + 2 : 0;
+ new_ie_len = new_ie ? new_ie[1] + 2 : 0;
+ }
+
+ ret = (old_ie_len == new_ie_len &&
+ os_memcmp(old_ie, new_ie, old_ie_len) == 0);
+
+ wpabuf_free(old_ie_buff);
+ wpabuf_free(new_ie_buff);
+
+ return ret;
+}
+
+
+static u32 wpa_bss_compare_res(const struct wpa_bss *old,
+ const struct wpa_scan_res *new)
+{
+ u32 changes = 0;
+ int caps_diff = old->caps ^ new->caps;
+
+ if (old->freq != new->freq)
+ changes |= WPA_BSS_FREQ_CHANGED_FLAG;
+
+ if (old->level != new->level)
+ changes |= WPA_BSS_SIGNAL_CHANGED_FLAG;
+
+ if (caps_diff & IEEE80211_CAP_PRIVACY)
+ changes |= WPA_BSS_PRIVACY_CHANGED_FLAG;
+
+ if (caps_diff & IEEE80211_CAP_IBSS)
+ changes |= WPA_BSS_MODE_CHANGED_FLAG;
+
+ if (old->ie_len == new->ie_len &&
+ os_memcmp(old + 1, new + 1, old->ie_len) == 0)
+ return changes;
+ changes |= WPA_BSS_IES_CHANGED_FLAG;
+
+ if (!are_ies_equal(old, new, WPA_IE_VENDOR_TYPE))
+ changes |= WPA_BSS_WPAIE_CHANGED_FLAG;
+
+ if (!are_ies_equal(old, new, WLAN_EID_RSN))
+ changes |= WPA_BSS_RSNIE_CHANGED_FLAG;
+
+ if (!are_ies_equal(old, new, WPS_IE_VENDOR_TYPE))
+ changes |= WPA_BSS_WPS_CHANGED_FLAG;
+
+ if (!are_ies_equal(old, new, WLAN_EID_SUPP_RATES) ||
+ !are_ies_equal(old, new, WLAN_EID_EXT_SUPP_RATES))
+ changes |= WPA_BSS_RATES_CHANGED_FLAG;
+
+ return changes;
+}
+
+
+static void notify_bss_changes(struct wpa_supplicant *wpa_s, u32 changes,
+ const struct wpa_bss *bss)
+{
+ if (changes & WPA_BSS_FREQ_CHANGED_FLAG)
+ wpas_notify_bss_freq_changed(wpa_s, bss->id);
+
+ if (changes & WPA_BSS_SIGNAL_CHANGED_FLAG)
+ wpas_notify_bss_signal_changed(wpa_s, bss->id);
+
+ if (changes & WPA_BSS_PRIVACY_CHANGED_FLAG)
+ wpas_notify_bss_privacy_changed(wpa_s, bss->id);
+
+ if (changes & WPA_BSS_MODE_CHANGED_FLAG)
+ wpas_notify_bss_mode_changed(wpa_s, bss->id);
+
+ if (changes & WPA_BSS_WPAIE_CHANGED_FLAG)
+ wpas_notify_bss_wpaie_changed(wpa_s, bss->id);
+
+ if (changes & WPA_BSS_RSNIE_CHANGED_FLAG)
+ wpas_notify_bss_rsnie_changed(wpa_s, bss->id);
+
+ if (changes & WPA_BSS_WPS_CHANGED_FLAG)
+ wpas_notify_bss_wps_changed(wpa_s, bss->id);
+
+ if (changes & WPA_BSS_IES_CHANGED_FLAG)
+ wpas_notify_bss_ies_changed(wpa_s, bss->id);
+
+ if (changes & WPA_BSS_RATES_CHANGED_FLAG)
+ wpas_notify_bss_rates_changed(wpa_s, bss->id);
+}
+
+
+static void wpa_bss_update(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
+ struct wpa_scan_res *res)
+{
+ u32 changes;
+
+ changes = wpa_bss_compare_res(bss, res);
+ bss->scan_miss_count = 0;
+ bss->last_update_idx = wpa_s->bss_update_idx;
+ wpa_bss_copy_res(bss, res);
+ /* Move the entry to the end of the list */
+ dl_list_del(&bss->list);
+ if (bss->ie_len + bss->beacon_ie_len >=
+ res->ie_len + res->beacon_ie_len) {
+ os_memcpy(bss + 1, res + 1, res->ie_len + res->beacon_ie_len);
+ bss->ie_len = res->ie_len;
+ bss->beacon_ie_len = res->beacon_ie_len;
+ } else {
+ struct wpa_bss *nbss;
+ struct dl_list *prev = bss->list_id.prev;
+ dl_list_del(&bss->list_id);
+ nbss = os_realloc(bss, sizeof(*bss) + res->ie_len +
+ res->beacon_ie_len);
+ if (nbss) {
+ bss = nbss;
+ os_memcpy(bss + 1, res + 1,
+ res->ie_len + res->beacon_ie_len);
+ bss->ie_len = res->ie_len;
+ bss->beacon_ie_len = res->beacon_ie_len;
+ }
+ dl_list_add(prev, &bss->list_id);
+ }
+ dl_list_add_tail(&wpa_s->bss, &bss->list);
+
+ notify_bss_changes(wpa_s, changes, bss);
+}
+
+
+static int wpa_bss_in_use(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
+{
+ return bss == wpa_s->current_bss ||
+ os_memcmp(bss->bssid, wpa_s->bssid, ETH_ALEN) == 0 ||
+ os_memcmp(bss->bssid, wpa_s->pending_bssid, ETH_ALEN) == 0;
+}
+
+
+void wpa_bss_update_start(struct wpa_supplicant *wpa_s)
+{
+ wpa_s->bss_update_idx++;
+ wpa_printf(MSG_DEBUG, "BSS: Start scan result update %u",
+ wpa_s->bss_update_idx);
+}
+
+
+void wpa_bss_update_scan_res(struct wpa_supplicant *wpa_s,
+ struct wpa_scan_res *res)
+{
+ const u8 *ssid;
+ struct wpa_bss *bss;
+
+ ssid = wpa_scan_get_ie(res, WLAN_EID_SSID);
+ if (ssid == NULL) {
+ wpa_printf(MSG_DEBUG, "BSS: No SSID IE included for " MACSTR,
+ MAC2STR(res->bssid));
+ return;
+ }
+ if (ssid[1] > 32) {
+ wpa_printf(MSG_DEBUG, "BSS: Too long SSID IE included for "
+ MACSTR, MAC2STR(res->bssid));
+ return;
+ }
+
+ /* TODO: add option for ignoring BSSes we are not interested in
+ * (to save memory) */
+ bss = wpa_bss_get(wpa_s, res->bssid, ssid + 2, ssid[1]);
+ if (bss == NULL)
+ wpa_bss_add(wpa_s, ssid + 2, ssid[1], res);
+ else
+ wpa_bss_update(wpa_s, bss, res);
+}
+
+
+static int wpa_bss_included_in_scan(const struct wpa_bss *bss,
+ const struct scan_info *info)
+{
+ int found;
+ size_t i;
+
+ if (info == NULL)
+ return 1;
+
+ if (info->num_freqs) {
+ found = 0;
+ for (i = 0; i < info->num_freqs; i++) {
+ if (bss->freq == info->freqs[i]) {
+ found = 1;
+ break;
+ }
+ }
+ if (!found)
+ return 0;
+ }
+
+ if (info->num_ssids) {
+ found = 0;
+ for (i = 0; i < info->num_ssids; i++) {
+ const struct wpa_driver_scan_ssid *s = &info->ssids[i];
+ if ((s->ssid == NULL || s->ssid_len == 0) ||
+ (s->ssid_len == bss->ssid_len &&
+ os_memcmp(s->ssid, bss->ssid, bss->ssid_len) ==
+ 0)) {
+ found = 1;
+ break;
+ }
+ }
+ if (!found)
+ return 0;
+ }
+
+ return 1;
+}
+
+
+void wpa_bss_update_end(struct wpa_supplicant *wpa_s, struct scan_info *info,
+ int new_scan)
+{
+ struct wpa_bss *bss, *n;
+
+ if (!new_scan)
+ return; /* do not expire entries without new scan */
+
+ dl_list_for_each_safe(bss, n, &wpa_s->bss, struct wpa_bss, list) {
+ if (wpa_bss_in_use(wpa_s, bss))
+ continue;
+ if (!wpa_bss_included_in_scan(bss, info))
+ continue; /* expire only BSSes that were scanned */
+ if (bss->last_update_idx < wpa_s->bss_update_idx)
+ bss->scan_miss_count++;
+ if (bss->scan_miss_count >= WPA_BSS_EXPIRATION_SCAN_COUNT) {
+ wpa_printf(MSG_DEBUG, "BSS: Expire BSS %u due to no "
+ "match in scan", bss->id);
+ wpa_bss_remove(wpa_s, bss);
+ }
+ }
+}
+
+
+static void wpa_bss_timeout(void *eloop_ctx, void *timeout_ctx)
+{
+ struct wpa_supplicant *wpa_s = eloop_ctx;
+ struct wpa_bss *bss, *n;
+ struct os_time t;
+
+ if (dl_list_empty(&wpa_s->bss))
+ return;
+
+ os_get_time(&t);
+ t.sec -= WPA_BSS_EXPIRATION_AGE;
+
+ dl_list_for_each_safe(bss, n, &wpa_s->bss, struct wpa_bss, list) {
+ if (wpa_bss_in_use(wpa_s, bss))
+ continue;
+
+ if (os_time_before(&bss->last_update, &t)) {
+ wpa_printf(MSG_DEBUG, "BSS: Expire BSS %u due to age",
+ bss->id);
+ wpa_bss_remove(wpa_s, bss);
+ } else
+ break;
+ }
+ eloop_register_timeout(WPA_BSS_EXPIRATION_PERIOD, 0,
+ wpa_bss_timeout, wpa_s, NULL);
+}
+
+
+int wpa_bss_init(struct wpa_supplicant *wpa_s)
+{
+ dl_list_init(&wpa_s->bss);
+ dl_list_init(&wpa_s->bss_id);
+ eloop_register_timeout(WPA_BSS_EXPIRATION_PERIOD, 0,
+ wpa_bss_timeout, wpa_s, NULL);
+ return 0;
+}
+
+
+void wpa_bss_deinit(struct wpa_supplicant *wpa_s)
+{
+ struct wpa_bss *bss, *n;
+ eloop_cancel_timeout(wpa_bss_timeout, wpa_s, NULL);
+ if (wpa_s->bss.next == NULL)
+ return; /* BSS table not yet initialized */
+ dl_list_for_each_safe(bss, n, &wpa_s->bss, struct wpa_bss, list)
+ wpa_bss_remove(wpa_s, bss);
+}
+
+
+struct wpa_bss * wpa_bss_get_bssid(struct wpa_supplicant *wpa_s,
+ const u8 *bssid)
+{
+ struct wpa_bss *bss;
+ dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
+ if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0)
+ return bss;
+ }
+ return NULL;
+}
+
+
+struct wpa_bss * wpa_bss_get_id(struct wpa_supplicant *wpa_s, unsigned int id)
+{
+ struct wpa_bss *bss;
+ dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
+ if (bss->id == id)
+ return bss;
+ }
+ return NULL;
+}
+
+
+const u8 * wpa_bss_get_ie(const struct wpa_bss *bss, u8 ie)
+{
+ const u8 *end, *pos;
+
+ pos = (const u8 *) (bss + 1);
+ end = pos + bss->ie_len;
+
+ while (pos + 1 < end) {
+ if (pos + 2 + pos[1] > end)
+ break;
+ if (pos[0] == ie)
+ return pos;
+ pos += 2 + pos[1];
+ }
+
+ return NULL;
+}
+
+
+const u8 * wpa_bss_get_vendor_ie(const struct wpa_bss *bss, u32 vendor_type)
+{
+ const u8 *end, *pos;
+
+ pos = (const u8 *) (bss + 1);
+ end = pos + bss->ie_len;
+
+ while (pos + 1 < end) {
+ if (pos + 2 + pos[1] > end)
+ break;
+ if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
+ vendor_type == WPA_GET_BE32(&pos[2]))
+ return pos;
+ pos += 2 + pos[1];
+ }
+
+ return NULL;
+}
+
+
+struct wpabuf * wpa_bss_get_vendor_ie_multi(const struct wpa_bss *bss,
+ u32 vendor_type)
+{
+ struct wpabuf *buf;
+ const u8 *end, *pos;
+
+ buf = wpabuf_alloc(bss->ie_len);
+ if (buf == NULL)
+ return NULL;
+
+ pos = (const u8 *) (bss + 1);
+ end = pos + bss->ie_len;
+
+ while (pos + 1 < end) {
+ if (pos + 2 + pos[1] > end)
+ break;
+ if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
+ vendor_type == WPA_GET_BE32(&pos[2]))
+ wpabuf_put_data(buf, pos + 2 + 4, pos[1] - 4);
+ pos += 2 + pos[1];
+ }
+
+ if (wpabuf_len(buf) == 0) {
+ wpabuf_free(buf);
+ buf = NULL;
+ }
+
+ return buf;
+}
+
+
+int wpa_bss_get_max_rate(const struct wpa_bss *bss)
+{
+ int rate = 0;
+ const u8 *ie;
+ int i;
+
+ ie = wpa_bss_get_ie(bss, WLAN_EID_SUPP_RATES);
+ for (i = 0; ie && i < ie[1]; i++) {
+ if ((ie[i + 2] & 0x7f) > rate)
+ rate = ie[i + 2] & 0x7f;
+ }
+
+ ie = wpa_bss_get_ie(bss, WLAN_EID_EXT_SUPP_RATES);
+ for (i = 0; ie && i < ie[1]; i++) {
+ if ((ie[i + 2] & 0x7f) > rate)
+ rate = ie[i + 2] & 0x7f;
+ }
+
+ return rate;
+}
+
+
+int wpa_bss_get_bit_rates(const struct wpa_bss *bss, u8 **rates)
+{
+ const u8 *ie, *ie2;
+ int i, j;
+ unsigned int len;
+ u8 *r;
+
+ ie = wpa_bss_get_ie(bss, WLAN_EID_SUPP_RATES);
+ ie2 = wpa_bss_get_ie(bss, WLAN_EID_EXT_SUPP_RATES);
+
+ len = (ie ? ie[1] : 0) + (ie2 ? ie2[1] : 0);
+
+ r = os_malloc(len);
+ if (!r)
+ return -1;
+
+ for (i = 0; ie && i < ie[1]; i++)
+ r[i] = ie[i + 2] & 0x7f;
+
+ for (j = 0; ie2 && j < ie2[1]; j++)
+ r[i + j] = ie2[j + 2] & 0x7f;
+
+ *rates = r;
+ return len;
+}
diff --git a/contrib/wpa/wpa_supplicant/bss.h b/contrib/wpa/wpa_supplicant/bss.h
new file mode 100644
index 0000000..1de4722
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/bss.h
@@ -0,0 +1,93 @@
+/*
+ * BSS table
+ * Copyright (c) 2009-2010, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef BSS_H
+#define BSS_H
+
+struct wpa_scan_res;
+
+#define WPA_BSS_QUAL_INVALID BIT(0)
+#define WPA_BSS_NOISE_INVALID BIT(1)
+#define WPA_BSS_LEVEL_INVALID BIT(2)
+#define WPA_BSS_LEVEL_DBM BIT(3)
+#define WPA_BSS_AUTHENTICATED BIT(4)
+#define WPA_BSS_ASSOCIATED BIT(5)
+
+/**
+ * struct wpa_bss - BSS table
+ * @list: List entry for struct wpa_supplicant::bss
+ * @list_id: List entry for struct wpa_supplicant::bss_id
+ * @id: Unique identifier for this BSS entry
+ * @scan_miss_count: Number of counts without seeing this BSS
+ * @flags: information flags about the BSS/IBSS (WPA_BSS_*)
+ * @last_update_idx: Index of the last scan update
+ * @bssid: BSSID
+ * @freq: frequency of the channel in MHz (e.g., 2412 = channel 1)
+ * @beacon_int: beacon interval in TUs (host byte order)
+ * @caps: capability information field in host byte order
+ * @qual: signal quality
+ * @noise: noise level
+ * @level: signal level
+ * @tsf: Timestamp of last Beacon/Probe Response frame
+ * @last_update: Time of the last update (i.e., Beacon or Probe Response RX)
+ * @ie_len: length of the following IE field in octets (from Probe Response)
+ * @beacon_ie_len: length of the following Beacon IE field in octets
+ *
+ * This structure is used to store information about neighboring BSSes in
+ * generic format. It is mainly updated based on scan results from the driver.
+ */
+struct wpa_bss {
+ struct dl_list list;
+ struct dl_list list_id;
+ unsigned int id;
+ unsigned int scan_miss_count;
+ unsigned int last_update_idx;
+ unsigned int flags;
+ u8 bssid[ETH_ALEN];
+ u8 ssid[32];
+ size_t ssid_len;
+ int freq;
+ u16 beacon_int;
+ u16 caps;
+ int qual;
+ int noise;
+ int level;
+ u64 tsf;
+ struct os_time last_update;
+ size_t ie_len;
+ size_t beacon_ie_len;
+ /* followed by ie_len octets of IEs */
+ /* followed by beacon_ie_len octets of IEs */
+};
+
+void wpa_bss_update_start(struct wpa_supplicant *wpa_s);
+void wpa_bss_update_scan_res(struct wpa_supplicant *wpa_s,
+ struct wpa_scan_res *res);
+void wpa_bss_update_end(struct wpa_supplicant *wpa_s, struct scan_info *info,
+ int new_scan);
+int wpa_bss_init(struct wpa_supplicant *wpa_s);
+void wpa_bss_deinit(struct wpa_supplicant *wpa_s);
+struct wpa_bss * wpa_bss_get(struct wpa_supplicant *wpa_s, const u8 *bssid,
+ const u8 *ssid, size_t ssid_len);
+struct wpa_bss * wpa_bss_get_bssid(struct wpa_supplicant *wpa_s,
+ const u8 *bssid);
+struct wpa_bss * wpa_bss_get_id(struct wpa_supplicant *wpa_s, unsigned int id);
+const u8 * wpa_bss_get_ie(const struct wpa_bss *bss, u8 ie);
+const u8 * wpa_bss_get_vendor_ie(const struct wpa_bss *bss, u32 vendor_type);
+struct wpabuf * wpa_bss_get_vendor_ie_multi(const struct wpa_bss *bss,
+ u32 vendor_type);
+int wpa_bss_get_max_rate(const struct wpa_bss *bss);
+int wpa_bss_get_bit_rates(const struct wpa_bss *bss, u8 **rates);
+
+#endif /* BSS_H */
diff --git a/contrib/wpa/wpa_supplicant/config.c b/contrib/wpa/wpa_supplicant/config.c
index 9a79374..7e2a5b4 100644
--- a/contrib/wpa/wpa_supplicant/config.c
+++ b/contrib/wpa/wpa_supplicant/config.c
@@ -15,8 +15,8 @@
#include "includes.h"
#include "common.h"
-#include "wpa.h"
-#include "sha1.h"
+#include "crypto/sha1.h"
+#include "rsn_supp/wpa.h"
#include "eap_peer/eap.h"
#include "config.h"
@@ -917,6 +917,130 @@ static char * wpa_config_write_auth_alg(const struct parse_data *data,
#endif /* NO_CONFIG_WRITE */
+static int * wpa_config_parse_freqs(const struct parse_data *data,
+ struct wpa_ssid *ssid, int line,
+ const char *value)
+{
+ int *freqs;
+ size_t used, len;
+ const char *pos;
+
+ used = 0;
+ len = 10;
+ freqs = os_zalloc((len + 1) * sizeof(int));
+ if (freqs == NULL)
+ return NULL;
+
+ pos = value;
+ while (pos) {
+ while (*pos == ' ')
+ pos++;
+ if (used == len) {
+ int *n;
+ size_t i;
+ n = os_realloc(freqs, (len * 2 + 1) * sizeof(int));
+ if (n == NULL) {
+ os_free(freqs);
+ return NULL;
+ }
+ for (i = len; i <= len * 2; i++)
+ n[i] = 0;
+ freqs = n;
+ len *= 2;
+ }
+
+ freqs[used] = atoi(pos);
+ if (freqs[used] == 0)
+ break;
+ used++;
+ pos = os_strchr(pos + 1, ' ');
+ }
+
+ return freqs;
+}
+
+
+static int wpa_config_parse_scan_freq(const struct parse_data *data,
+ struct wpa_ssid *ssid, int line,
+ const char *value)
+{
+ int *freqs;
+
+ freqs = wpa_config_parse_freqs(data, ssid, line, value);
+ if (freqs == NULL)
+ return -1;
+ os_free(ssid->scan_freq);
+ ssid->scan_freq = freqs;
+
+ return 0;
+}
+
+
+static int wpa_config_parse_freq_list(const struct parse_data *data,
+ struct wpa_ssid *ssid, int line,
+ const char *value)
+{
+ int *freqs;
+
+ freqs = wpa_config_parse_freqs(data, ssid, line, value);
+ if (freqs == NULL)
+ return -1;
+ os_free(ssid->freq_list);
+ ssid->freq_list = freqs;
+
+ return 0;
+}
+
+
+#ifndef NO_CONFIG_WRITE
+static char * wpa_config_write_freqs(const struct parse_data *data,
+ const int *freqs)
+{
+ char *buf, *pos, *end;
+ int i, ret;
+ size_t count;
+
+ if (freqs == NULL)
+ return NULL;
+
+ count = 0;
+ for (i = 0; freqs[i]; i++)
+ count++;
+
+ pos = buf = os_zalloc(10 * count + 1);
+ if (buf == NULL)
+ return NULL;
+ end = buf + 10 * count + 1;
+
+ for (i = 0; freqs[i]; i++) {
+ ret = os_snprintf(pos, end - pos, "%s%u",
+ i == 0 ? "" : " ", freqs[i]);
+ if (ret < 0 || ret >= end - pos) {
+ end[-1] = '\0';
+ return buf;
+ }
+ pos += ret;
+ }
+
+ return buf;
+}
+
+
+static char * wpa_config_write_scan_freq(const struct parse_data *data,
+ struct wpa_ssid *ssid)
+{
+ return wpa_config_write_freqs(data, ssid->scan_freq);
+}
+
+
+static char * wpa_config_write_freq_list(const struct parse_data *data,
+ struct wpa_ssid *ssid)
+{
+ return wpa_config_write_freqs(data, ssid->freq_list);
+}
+#endif /* NO_CONFIG_WRITE */
+
+
#ifdef IEEE8021X_EAPOL
static int wpa_config_parse_eap(const struct parse_data *data,
struct wpa_ssid *ssid, int line,
@@ -1317,6 +1441,8 @@ static const struct parse_data ssid_fields[] = {
{ FUNC(pairwise) },
{ FUNC(group) },
{ FUNC(auth_alg) },
+ { FUNC(scan_freq) },
+ { FUNC(freq_list) },
#ifdef IEEE8021X_EAPOL
{ FUNC(eap) },
{ STR_LENe(identity) },
@@ -1366,7 +1492,7 @@ static const struct parse_data ssid_fields[] = {
{ STRe(pac_file) },
{ INTe(fragment_size) },
#endif /* IEEE8021X_EAPOL */
- { INT_RANGE(mode, 0, 1) },
+ { INT_RANGE(mode, 0, 2) },
{ INT_RANGE(proactive_key_caching, 0, 1) },
{ INT_RANGE(disabled, 0, 1) },
{ STR(id_str) },
@@ -1376,7 +1502,8 @@ static const struct parse_data ssid_fields[] = {
{ INT_RANGE(peerkey, 0, 1) },
{ INT_RANGE(mixed_cell, 0, 1) },
{ INT_RANGE(frequency, 0, 10000) },
- { INT(wpa_ptk_rekey) }
+ { INT(wpa_ptk_rekey) },
+ { STR(bgscan) },
};
#undef OFFSET
@@ -1460,7 +1587,7 @@ int wpa_config_add_prio_network(struct wpa_config *config,
* configuration when a network is being added or removed. This is also called
* if a priority for a network is changed.
*/
-static int wpa_config_update_prio_list(struct wpa_config *config)
+int wpa_config_update_prio_list(struct wpa_config *config)
{
struct wpa_ssid *ssid;
int ret = 0;
@@ -1540,6 +1667,9 @@ void wpa_config_free_ssid(struct wpa_ssid *ssid)
eap_peer_config_free(&ssid->eap);
#endif /* IEEE8021X_EAPOL */
os_free(ssid->id_str);
+ os_free(ssid->scan_freq);
+ os_free(ssid->freq_list);
+ os_free(ssid->bgscan);
os_free(ssid);
}
@@ -1576,11 +1706,9 @@ void wpa_config_free(struct wpa_config *config)
os_free(config->ctrl_interface);
os_free(config->ctrl_interface_group);
-#ifdef EAP_TLS_OPENSSL
os_free(config->opensc_engine_path);
os_free(config->pkcs11_engine_path);
os_free(config->pkcs11_module_path);
-#endif /* EAP_TLS_OPENSSL */
os_free(config->driver_param);
os_free(config->device_name);
os_free(config->manufacturer);
@@ -1588,6 +1716,7 @@ void wpa_config_free(struct wpa_config *config)
os_free(config->model_number);
os_free(config->serial_number);
os_free(config->device_type);
+ os_free(config->config_methods);
os_free(config->pssid);
os_free(config);
}
@@ -1747,6 +1876,65 @@ int wpa_config_set(struct wpa_ssid *ssid, const char *var, const char *value,
}
+/**
+ * wpa_config_get_all - Get all options from network configuration
+ * @ssid: Pointer to network configuration data
+ * @get_keys: Determines if keys/passwords will be included in returned list
+ * Returns: %NULL terminated list of all set keys and their values in the form
+ * of [key1, val1, key2, val2, ... , NULL]
+ *
+ * This function can be used to get list of all configured network properties.
+ * The caller is responsible for freeing the returned list and all its
+ * elements.
+ */
+char ** wpa_config_get_all(struct wpa_ssid *ssid, int get_keys)
+{
+ const struct parse_data *field;
+ char *key, *value;
+ size_t i;
+ char **props;
+ int fields_num;
+
+ props = os_zalloc(sizeof(char *) * ((2 * NUM_SSID_FIELDS) + 1));
+ if (!props)
+ return NULL;
+
+ fields_num = 0;
+ for (i = 0; i < NUM_SSID_FIELDS; i++) {
+ field = &ssid_fields[i];
+ if (field->key_data && !get_keys)
+ continue;
+ value = field->writer(field, ssid);
+ if (value == NULL)
+ continue;
+ if (os_strlen(value) == 0) {
+ os_free(value);
+ continue;
+ }
+
+ key = os_strdup(field->name);
+ if (key == NULL) {
+ os_free(value);
+ goto err;
+ }
+
+ props[fields_num * 2] = key;
+ props[fields_num * 2 + 1] = value;
+
+ fields_num++;
+ }
+
+ return props;
+
+err:
+ value = *props;
+ while (value)
+ os_free(value++);
+ os_free(props);
+ return NULL;
+}
+
+
#ifndef NO_CONFIG_WRITE
/**
* wpa_config_get - Get a variable in network configuration
@@ -1943,6 +2131,7 @@ struct wpa_config * wpa_config_alloc_empty(const char *ctrl_interface,
config->eapol_version = DEFAULT_EAPOL_VERSION;
config->ap_scan = DEFAULT_AP_SCAN;
config->fast_reauth = DEFAULT_FAST_REAUTH;
+ config->bss_max_count = DEFAULT_BSS_MAX_COUNT;
if (ctrl_interface)
config->ctrl_interface = os_strdup(ctrl_interface);
diff --git a/contrib/wpa/wpa_supplicant/config.h b/contrib/wpa/wpa_supplicant/config.h
index 4484e91..754e4be 100644
--- a/contrib/wpa/wpa_supplicant/config.h
+++ b/contrib/wpa/wpa_supplicant/config.h
@@ -22,6 +22,7 @@
#define DEFAULT_AP_SCAN 1
#endif /* CONFIG_NO_SCAN_PROCESSING */
#define DEFAULT_FAST_REAUTH 1
+#define DEFAULT_BSS_MAX_COUNT 200
#include "config_ssid.h"
@@ -169,7 +170,6 @@ struct wpa_config {
*/
int fast_reauth;
-#ifdef EAP_TLS_OPENSSL
/**
* opensc_engine_path - Path to the OpenSSL engine for opensc
*
@@ -194,7 +194,6 @@ struct wpa_config {
* module is not loaded.
*/
char *pkcs11_module_path;
-#endif /* EAP_TLS_OPENSSL */
/**
* driver_param - Driver interface parameters
@@ -300,6 +299,16 @@ struct wpa_config {
char *device_type;
/**
+ * config_methods - Config Methods
+ *
+ * This is a space-separated list of supported WPS configuration
+ * methods. For example, "label display push_button keypad".
+ * Available methods: usba ethernet label display ext_nfc_token
+ * int_nfc_token nfc_interface push_button keypad.
+ */
+ char *config_methods;
+
+ /**
* os_version - OS Version (WPS)
* 4-octet operating system version number
*/
@@ -323,6 +332,19 @@ struct wpa_config {
* ctrl_iface to external program(s)
*/
int wps_cred_processing;
+
+ /**
+ * bss_max_count - Maximum number of BSS entries to keep in memory
+ */
+ unsigned int bss_max_count;
+
+ /**
+ * filter_ssids - SSID-based scan result filtering
+ *
+ * 0 = do not filter scan results
+ * 1 = only include configured SSIDs in scan results/BSS table
+ */
+ int filter_ssids;
};
@@ -336,11 +358,13 @@ int wpa_config_remove_network(struct wpa_config *config, int id);
void wpa_config_set_network_defaults(struct wpa_ssid *ssid);
int wpa_config_set(struct wpa_ssid *ssid, const char *var, const char *value,
int line);
+char ** wpa_config_get_all(struct wpa_ssid *ssid, int get_keys);
char * wpa_config_get(struct wpa_ssid *ssid, const char *var);
char * wpa_config_get_no_key(struct wpa_ssid *ssid, const char *var);
void wpa_config_update_psk(struct wpa_ssid *ssid);
int wpa_config_add_prio_network(struct wpa_config *config,
struct wpa_ssid *ssid);
+int wpa_config_update_prio_list(struct wpa_config *config);
const struct wpa_config_blob * wpa_config_get_blob(struct wpa_config *config,
const char *name);
void wpa_config_set_blob(struct wpa_config *config,
diff --git a/contrib/wpa/wpa_supplicant/config_file.c b/contrib/wpa/wpa_supplicant/config_file.c
index 29e494c..5f07045 100644
--- a/contrib/wpa/wpa_supplicant/config_file.c
+++ b/contrib/wpa/wpa_supplicant/config_file.c
@@ -434,11 +434,9 @@ static const struct global_parse_data global_fields[] = {
{ INT_RANGE(eapol_version, 1, 2) },
{ INT(ap_scan) },
{ INT(fast_reauth) },
-#ifdef EAP_TLS_OPENSSL
{ STR(opensc_engine_path) },
{ STR(pkcs11_engine_path) },
{ STR(pkcs11_module_path) },
-#endif /* EAP_TLS_OPENSSL */
{ STR(driver_param) },
{ INT(dot11RSNAConfigPMKLifetime) },
{ INT(dot11RSNAConfigPMKReauthThreshold) },
@@ -456,9 +454,12 @@ static const struct global_parse_data global_fields[] = {
{ STR_RANGE(serial_number, 0, 32) },
{ STR(device_type) },
{ FUNC(os_version) },
+ { STR(config_methods) },
{ INT_RANGE(wps_cred_processing, 0, 2) },
#endif /* CONFIG_WPS */
- { FUNC(country) }
+ { FUNC(country) },
+ { INT(bss_max_count) },
+ { INT_RANGE(filter_ssids, 0, 1) }
};
#undef FUNC
@@ -837,7 +838,6 @@ static void wpa_config_write_global(FILE *f, struct wpa_config *config)
fprintf(f, "ap_scan=%d\n", config->ap_scan);
if (config->fast_reauth != DEFAULT_FAST_REAUTH)
fprintf(f, "fast_reauth=%d\n", config->fast_reauth);
-#ifdef EAP_TLS_OPENSSL
if (config->opensc_engine_path)
fprintf(f, "opensc_engine_path=%s\n",
config->opensc_engine_path);
@@ -847,7 +847,6 @@ static void wpa_config_write_global(FILE *f, struct wpa_config *config)
if (config->pkcs11_module_path)
fprintf(f, "pkcs11_module_path=%s\n",
config->pkcs11_module_path);
-#endif /* EAP_TLS_OPENSSL */
if (config->driver_param)
fprintf(f, "driver_param=%s\n", config->driver_param);
if (config->dot11RSNAConfigPMKLifetime)
@@ -882,6 +881,8 @@ static void wpa_config_write_global(FILE *f, struct wpa_config *config)
if (WPA_GET_BE32(config->os_version))
fprintf(f, "os_version=%08x\n",
WPA_GET_BE32(config->os_version));
+ if (config->config_methods)
+ fprintf(f, "config_methods=%s\n", config->config_methods);
if (config->wps_cred_processing)
fprintf(f, "wps_cred_processing=%d\n",
config->wps_cred_processing);
@@ -890,6 +891,10 @@ static void wpa_config_write_global(FILE *f, struct wpa_config *config)
fprintf(f, "country=%c%c\n",
config->country[0], config->country[1]);
}
+ if (config->bss_max_count != DEFAULT_BSS_MAX_COUNT)
+ fprintf(f, "bss_max_count=%u\n", config->bss_max_count);
+ if (config->filter_ssids)
+ fprintf(f, "filter_ssids=%d\n", config->filter_ssids);
}
#endif /* CONFIG_NO_CONFIG_WRITE */
diff --git a/contrib/wpa/wpa_supplicant/config_ssid.h b/contrib/wpa/wpa_supplicant/config_ssid.h
index 5510639..25e87aa 100644
--- a/contrib/wpa/wpa_supplicant/config_ssid.h
+++ b/contrib/wpa/wpa_supplicant/config_ssid.h
@@ -15,7 +15,7 @@
#ifndef CONFIG_SSID_H
#define CONFIG_SSID_H
-#include "defs.h"
+#include "common/defs.h"
#include "eap_peer/eap_config.h"
#define MAX_SSID_LEN 32
@@ -271,6 +271,8 @@ struct wpa_ssid {
*
* 1 = IBSS (ad-hoc, peer-to-peer)
*
+ * 2 = AP (access point)
+ *
* Note: IBSS can only be used with key_mgmt NONE (plaintext and
* static WEP) and key_mgmt=WPA-NONE (fixed group key TKIP/CCMP). In
* addition, ap_scan has to be set to 2 for IBSS. WPA-None requires
@@ -278,7 +280,11 @@ struct wpa_ssid {
* pairwise=NONE, group=TKIP (or CCMP, but not both), and psk must also
* be set (either directly or using ASCII passphrase).
*/
- int mode;
+ enum wpas_mode {
+ WPAS_MODE_INFRA = 0,
+ WPAS_MODE_IBSS = 1,
+ WPAS_MODE_AP = 2,
+ } mode;
/**
* disabled - Whether this network is currently disabled
@@ -316,11 +322,7 @@ struct wpa_ssid {
* This value is used to configure policy for management frame
* protection (IEEE 802.11w). 0 = disabled, 1 = optional, 2 = required.
*/
- enum {
- NO_IEEE80211W = 0,
- IEEE80211W_OPTIONAL = 1,
- IEEE80211W_REQUIRED = 2
- } ieee80211w;
+ enum mfp_options ieee80211w;
#endif /* CONFIG_IEEE80211W */
/**
@@ -342,6 +344,35 @@ struct wpa_ssid {
* attacks against TKIP deficiencies.
*/
int wpa_ptk_rekey;
+
+ /**
+ * scan_freq - Array of frequencies to scan or %NULL for all
+ *
+ * This is an optional zero-terminated array of frequencies in
+ * megahertz (MHz) to include in scan requests when searching for this
+ * network. This can be used to speed up scanning when the network is
+ * known to not use all possible channels.
+ */
+ int *scan_freq;
+
+ /**
+ * bgscan - Background scan and roaming parameters or %NULL if none
+ *
+ * This is an optional set of parameters for background scanning and
+ * roaming within a network (ESS) in following format:
+ * <bgscan module name>:<module parameters>
+ */
+ char *bgscan;
+
+ /**
+ * freq_list - Array of allowed frequencies or %NULL for all
+ *
+ * This is an optional zero-terminated array of frequencies in
+ * megahertz (MHz) to allow for selecting the BSS. If set, scan results
+ * that do not match any of the specified frequencies are not
+ * considered when selecting a BSS.
+ */
+ int *freq_list;
};
#endif /* CONFIG_SSID_H */
diff --git a/contrib/wpa/wpa_supplicant/ctrl_iface.c b/contrib/wpa/wpa_supplicant/ctrl_iface.c
index 2b737bc..19fea29 100644
--- a/contrib/wpa/wpa_supplicant/ctrl_iface.c
+++ b/contrib/wpa/wpa_supplicant/ctrl_iface.c
@@ -1,6 +1,6 @@
/*
* WPA Supplicant / Control interface (shared code for all backends)
- * Copyright (c) 2004-2008, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2004-2010, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -12,23 +12,31 @@
* See README and COPYING for more details.
*/
-#include "includes.h"
+#include "utils/includes.h"
-#include "common.h"
-#include "eloop.h"
-#include "wpa.h"
-#include "config.h"
+#include "utils/common.h"
+#include "utils/eloop.h"
+#include "common/ieee802_11_defs.h"
+#include "common/wpa_ctrl.h"
+#include "eap_peer/eap.h"
#include "eapol_supp/eapol_supp_sm.h"
-#include "wpa_supplicant_i.h"
-#include "ctrl_iface.h"
+#include "rsn_supp/wpa.h"
+#include "rsn_supp/preauth.h"
+#include "rsn_supp/pmksa_cache.h"
#include "l2_packet/l2_packet.h"
-#include "preauth.h"
-#include "pmksa_cache.h"
-#include "wpa_ctrl.h"
-#include "eap_peer/eap.h"
-#include "ieee802_11_defs.h"
-#include "wps_supplicant.h"
#include "wps/wps.h"
+#include "config.h"
+#include "wpa_supplicant_i.h"
+#include "driver_i.h"
+#include "wps_supplicant.h"
+#include "ibss_rsn.h"
+#include "ap.h"
+#include "notify.h"
+#include "bss.h"
+#include "scan.h"
+#include "ctrl_iface.h"
+
+extern struct wpa_driver_ops *wpa_drivers[];
static int wpa_supplicant_global_iface_list(struct wpa_global *global,
char *buf, int len);
@@ -111,7 +119,7 @@ static int wpa_supplicant_ctrl_iface_stkstart(
if (hwaddr_aton(addr, peer)) {
wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
- "address '%s'", peer);
+ "address '%s'", addr);
return -1;
}
@@ -128,16 +136,24 @@ static int wpa_supplicant_ctrl_iface_ft_ds(
struct wpa_supplicant *wpa_s, char *addr)
{
u8 target_ap[ETH_ALEN];
+ struct wpa_bss *bss;
+ const u8 *mdie;
if (hwaddr_aton(addr, target_ap)) {
wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
- "address '%s'", target_ap);
+ "address '%s'", addr);
return -1;
}
wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
- return wpa_ft_start_over_ds(wpa_s->wpa, target_ap);
+ bss = wpa_bss_get_bssid(wpa_s, target_ap);
+ if (bss)
+ mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
+ else
+ mdie = NULL;
+
+ return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
}
#endif /* CONFIG_IEEE80211R */
@@ -146,18 +162,22 @@ static int wpa_supplicant_ctrl_iface_ft_ds(
static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
char *cmd)
{
- u8 bssid[ETH_ALEN];
+ u8 bssid[ETH_ALEN], *_bssid = bssid;
if (cmd == NULL || os_strcmp(cmd, "any") == 0)
- return wpas_wps_start_pbc(wpa_s, NULL);
-
- if (hwaddr_aton(cmd, bssid)) {
+ _bssid = NULL;
+ else if (hwaddr_aton(cmd, bssid)) {
wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
cmd);
return -1;
}
- return wpas_wps_start_pbc(wpa_s, bssid);
+#ifdef CONFIG_AP
+ if (wpa_s->ap_iface)
+ return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid);
+#endif /* CONFIG_AP */
+
+ return wpas_wps_start_pbc(wpa_s, _bssid);
}
@@ -181,6 +201,12 @@ static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
return -1;
}
+#ifdef CONFIG_AP
+ if (wpa_s->ap_iface)
+ return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
+ buf, buflen);
+#endif /* CONFIG_AP */
+
if (pin) {
ret = wpas_wps_start_pin(wpa_s, _bssid, pin);
if (ret < 0)
@@ -203,11 +229,41 @@ static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
}
+#ifdef CONFIG_WPS_OOB
+static int wpa_supplicant_ctrl_iface_wps_oob(struct wpa_supplicant *wpa_s,
+ char *cmd)
+{
+ char *path, *method, *name;
+
+ path = os_strchr(cmd, ' ');
+ if (path == NULL)
+ return -1;
+ *path++ = '\0';
+
+ method = os_strchr(path, ' ');
+ if (method == NULL)
+ return -1;
+ *method++ = '\0';
+
+ name = os_strchr(method, ' ');
+ if (name != NULL)
+ *name++ = '\0';
+
+ return wpas_wps_start_oob(wpa_s, cmd, path, method, name);
+}
+#endif /* CONFIG_WPS_OOB */
+
+
static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
char *cmd)
{
u8 bssid[ETH_ALEN], *_bssid = bssid;
char *pin;
+ char *new_ssid;
+ char *new_auth;
+ char *new_encr;
+ char *new_key;
+ struct wps_new_ap_settings ap;
pin = os_strchr(cmd, ' ');
if (pin == NULL)
@@ -222,11 +278,83 @@ static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
return -1;
}
- return wpas_wps_start_reg(wpa_s, _bssid, pin);
+ new_ssid = os_strchr(pin, ' ');
+ if (new_ssid == NULL)
+ return wpas_wps_start_reg(wpa_s, _bssid, pin, NULL);
+ *new_ssid++ = '\0';
+
+ new_auth = os_strchr(new_ssid, ' ');
+ if (new_auth == NULL)
+ return -1;
+ *new_auth++ = '\0';
+
+ new_encr = os_strchr(new_auth, ' ');
+ if (new_encr == NULL)
+ return -1;
+ *new_encr++ = '\0';
+
+ new_key = os_strchr(new_encr, ' ');
+ if (new_key == NULL)
+ return -1;
+ *new_key++ = '\0';
+
+ os_memset(&ap, 0, sizeof(ap));
+ ap.ssid_hex = new_ssid;
+ ap.auth = new_auth;
+ ap.encr = new_encr;
+ ap.key_hex = new_key;
+ return wpas_wps_start_reg(wpa_s, _bssid, pin, &ap);
+}
+
+
+#ifdef CONFIG_WPS_ER
+static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
+ char *cmd)
+{
+ char *uuid = cmd, *pin;
+ pin = os_strchr(uuid, ' ');
+ if (pin == NULL)
+ return -1;
+ *pin++ = '\0';
+ return wpas_wps_er_add_pin(wpa_s, uuid, pin);
}
+
+
+static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
+ char *cmd)
+{
+ char *uuid = cmd, *pin;
+ pin = os_strchr(uuid, ' ');
+ if (pin == NULL)
+ return -1;
+ *pin++ = '\0';
+ return wpas_wps_er_learn(wpa_s, uuid, pin);
+}
+#endif /* CONFIG_WPS_ER */
+
#endif /* CONFIG_WPS */
+#ifdef CONFIG_IBSS_RSN
+static int wpa_supplicant_ctrl_iface_ibss_rsn(
+ struct wpa_supplicant *wpa_s, char *addr)
+{
+ u8 peer[ETH_ALEN];
+
+ if (hwaddr_aton(addr, peer)) {
+ wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
+ "address '%s'", addr);
+ return -1;
+ }
+
+ wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
+ MAC2STR(peer));
+
+ return ibss_rsn_start(wpa_s->ibss_rsn, peer);
+}
+#endif /* CONFIG_IBSS_RSN */
+
+
static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
char *rsp)
{
@@ -355,8 +483,36 @@ static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
return pos - buf;
pos += ret;
}
+
+ switch (ssid->mode) {
+ case WPAS_MODE_INFRA:
+ ret = os_snprintf(pos, end - pos,
+ "mode=station\n");
+ break;
+ case WPAS_MODE_IBSS:
+ ret = os_snprintf(pos, end - pos,
+ "mode=IBSS\n");
+ break;
+ case WPAS_MODE_AP:
+ ret = os_snprintf(pos, end - pos,
+ "mode=AP\n");
+ break;
+ default:
+ ret = 0;
+ break;
+ }
+ if (ret < 0 || ret >= end - pos)
+ return pos - buf;
+ pos += ret;
}
+#ifdef CONFIG_AP
+ if (wpa_s->ap_iface) {
+ pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
+ end - pos,
+ verbose);
+ } else
+#endif /* CONFIG_AP */
pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
}
ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
@@ -616,18 +772,16 @@ static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
return pos;
}
-static char * wpa_supplicant_wps_ie_txt(char *pos, char *end,
- const struct wpa_scan_res *res)
-{
+
#ifdef CONFIG_WPS
- struct wpabuf *wps_ie;
+static char * wpa_supplicant_wps_ie_txt_buf(char *pos, char *end,
+ struct wpabuf *wps_ie)
+{
int ret;
const char *txt;
- wps_ie = wpa_scan_get_vendor_ie_multi(res, WPS_IE_VENDOR_TYPE);
if (wps_ie == NULL)
return pos;
-
if (wps_is_selected_pbc_registrar(wps_ie))
txt = "[WPS-PBC]";
else if (wps_is_selected_pin_registrar(wps_ie))
@@ -639,15 +793,27 @@ static char * wpa_supplicant_wps_ie_txt(char *pos, char *end,
if (ret >= 0 && ret < end - pos)
pos += ret;
wpabuf_free(wps_ie);
+ return pos;
+}
#endif /* CONFIG_WPS */
+
+static char * wpa_supplicant_wps_ie_txt(char *pos, char *end,
+ const struct wpa_bss *bss)
+{
+#ifdef CONFIG_WPS
+ struct wpabuf *wps_ie;
+ wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
+ return wpa_supplicant_wps_ie_txt_buf(pos, end, wps_ie);
+#else /* CONFIG_WPS */
return pos;
+#endif /* CONFIG_WPS */
}
/* Format one result on one text line into a buffer. */
static int wpa_supplicant_ctrl_iface_scan_result(
- const struct wpa_scan_res *res, char *buf, size_t buflen)
+ const struct wpa_bss *bss, char *buf, size_t buflen)
{
char *pos, *end;
int ret;
@@ -657,33 +823,38 @@ static int wpa_supplicant_ctrl_iface_scan_result(
end = buf + buflen;
ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
- MAC2STR(res->bssid), res->freq, res->level);
+ MAC2STR(bss->bssid), bss->freq, bss->level);
if (ret < 0 || ret >= end - pos)
return pos - buf;
pos += ret;
- ie = wpa_scan_get_vendor_ie(res, WPA_IE_VENDOR_TYPE);
+ ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
if (ie)
pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
- ie2 = wpa_scan_get_ie(res, WLAN_EID_RSN);
+ ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
if (ie2)
pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
- pos = wpa_supplicant_wps_ie_txt(pos, end, res);
- if (!ie && !ie2 && res->caps & IEEE80211_CAP_PRIVACY) {
+ pos = wpa_supplicant_wps_ie_txt(pos, end, bss);
+ if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
ret = os_snprintf(pos, end - pos, "[WEP]");
if (ret < 0 || ret >= end - pos)
return pos - buf;
pos += ret;
}
- if (res->caps & IEEE80211_CAP_IBSS) {
+ if (bss->caps & IEEE80211_CAP_IBSS) {
ret = os_snprintf(pos, end - pos, "[IBSS]");
if (ret < 0 || ret >= end - pos)
return pos - buf;
pos += ret;
}
+ if (bss->caps & IEEE80211_CAP_ESS) {
+ ret = os_snprintf(pos, end - pos, "[ESS]");
+ if (ret < 0 || ret >= end - pos)
+ return pos - buf;
+ pos += ret;
+ }
- ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
ret = os_snprintf(pos, end - pos, "\t%s",
- ie ? wpa_ssid_txt(ie + 2, ie[1]) : "");
+ wpa_ssid_txt(bss->ssid, bss->ssid_len));
if (ret < 0 || ret >= end - pos)
return pos - buf;
pos += ret;
@@ -701,13 +872,8 @@ static int wpa_supplicant_ctrl_iface_scan_results(
struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
{
char *pos, *end;
- struct wpa_scan_res *res;
+ struct wpa_bss *bss;
int ret;
- size_t i;
-
- if (wpa_s->scan_res == NULL &&
- wpa_supplicant_get_scan_results(wpa_s) < 0)
- return 0;
pos = buf;
end = buf + buflen;
@@ -717,9 +883,8 @@ static int wpa_supplicant_ctrl_iface_scan_results(
return pos - buf;
pos += ret;
- for (i = 0; i < wpa_s->scan_res->num; i++) {
- res = wpa_s->scan_res->res[i];
- ret = wpa_supplicant_ctrl_iface_scan_result(res, pos,
+ dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
+ ret = wpa_supplicant_ctrl_iface_scan_result(bss, pos,
end - pos);
if (ret < 0 || ret >= end - pos)
return pos - buf;
@@ -739,37 +904,20 @@ static int wpa_supplicant_ctrl_iface_select_network(
/* cmd: "<network id>" or "any" */
if (os_strcmp(cmd, "any") == 0) {
wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
- ssid = wpa_s->conf->ssid;
- while (ssid) {
- ssid->disabled = 0;
- ssid = ssid->next;
- }
- wpa_s->reassociate = 1;
- wpa_supplicant_req_scan(wpa_s, 0, 0);
- return 0;
- }
-
- id = atoi(cmd);
- wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
+ ssid = NULL;
+ } else {
+ id = atoi(cmd);
+ wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
- ssid = wpa_config_get_network(wpa_s->conf, id);
- if (ssid == NULL) {
- wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
- "id=%d", id);
- return -1;
+ ssid = wpa_config_get_network(wpa_s->conf, id);
+ if (ssid == NULL) {
+ wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
+ "network id=%d", id);
+ return -1;
+ }
}
- if (ssid != wpa_s->current_ssid && wpa_s->current_ssid)
- wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
-
- /* Mark all other networks disabled and trigger reassociation */
- ssid = wpa_s->conf->ssid;
- while (ssid) {
- ssid->disabled = id != ssid->id;
- ssid = ssid->next;
- }
- wpa_s->reassociate = 1;
- wpa_supplicant_req_scan(wpa_s, 0, 0);
+ wpa_supplicant_select_network(wpa_s, ssid);
return 0;
}
@@ -784,36 +932,19 @@ static int wpa_supplicant_ctrl_iface_enable_network(
/* cmd: "<network id>" or "all" */
if (os_strcmp(cmd, "all") == 0) {
wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
- ssid = wpa_s->conf->ssid;
- while (ssid) {
- if (ssid == wpa_s->current_ssid && ssid->disabled)
- wpa_s->reassociate = 1;
- ssid->disabled = 0;
- ssid = ssid->next;
- }
- if (wpa_s->reassociate)
- wpa_supplicant_req_scan(wpa_s, 0, 0);
- return 0;
- }
-
- id = atoi(cmd);
- wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
-
- ssid = wpa_config_get_network(wpa_s->conf, id);
- if (ssid == NULL) {
- wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
- "id=%d", id);
- return -1;
- }
+ ssid = NULL;
+ } else {
+ id = atoi(cmd);
+ wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
- if (wpa_s->current_ssid == NULL && ssid->disabled) {
- /*
- * Try to reassociate since there is no current configuration
- * and a new network was made available. */
- wpa_s->reassociate = 1;
- wpa_supplicant_req_scan(wpa_s, 0, 0);
+ ssid = wpa_config_get_network(wpa_s->conf, id);
+ if (ssid == NULL) {
+ wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
+ "network id=%d", id);
+ return -1;
+ }
}
- ssid->disabled = 0;
+ wpa_supplicant_enable_network(wpa_s, ssid);
return 0;
}
@@ -828,30 +959,19 @@ static int wpa_supplicant_ctrl_iface_disable_network(
/* cmd: "<network id>" or "all" */
if (os_strcmp(cmd, "all") == 0) {
wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
- ssid = wpa_s->conf->ssid;
- while (ssid) {
- ssid->disabled = 1;
- ssid = ssid->next;
- }
- if (wpa_s->current_ssid)
- wpa_supplicant_disassociate(wpa_s,
- WLAN_REASON_DEAUTH_LEAVING);
- return 0;
- }
-
- id = atoi(cmd);
- wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
+ ssid = NULL;
+ } else {
+ id = atoi(cmd);
+ wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
- ssid = wpa_config_get_network(wpa_s->conf, id);
- if (ssid == NULL) {
- wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
- "id=%d", id);
- return -1;
+ ssid = wpa_config_get_network(wpa_s->conf, id);
+ if (ssid == NULL) {
+ wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
+ "network id=%d", id);
+ return -1;
+ }
}
-
- if (ssid == wpa_s->current_ssid)
- wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
- ssid->disabled = 1;
+ wpa_supplicant_disable_network(wpa_s, ssid);
return 0;
}
@@ -868,6 +988,9 @@ static int wpa_supplicant_ctrl_iface_add_network(
ssid = wpa_config_add_network(wpa_s->conf);
if (ssid == NULL)
return -1;
+
+ wpas_notify_network_added(wpa_s, ssid);
+
ssid->disabled = 1;
wpa_config_set_network_defaults(ssid);
@@ -889,8 +1012,10 @@ static int wpa_supplicant_ctrl_iface_remove_network(
wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
ssid = wpa_s->conf->ssid;
while (ssid) {
+ struct wpa_ssid *remove_ssid = ssid;
id = ssid->id;
ssid = ssid->next;
+ wpas_notify_network_removed(wpa_s, remove_ssid);
wpa_config_remove_network(wpa_s->conf, id);
}
if (wpa_s->current_ssid) {
@@ -975,6 +1100,8 @@ static int wpa_supplicant_ctrl_iface_set_network(
value[0] == '"' && ssid->ssid_len) ||
(os_strcmp(name, "ssid") == 0 && ssid->passphrase))
wpa_config_update_psk(ssid);
+ else if (os_strcmp(name, "priority") == 0)
+ wpa_config_update_prio_list(wpa_s->conf);
return 0;
}
@@ -1361,36 +1488,49 @@ static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
{
u8 bssid[ETH_ALEN];
size_t i;
- struct wpa_scan_results *results;
- struct wpa_scan_res *bss;
+ struct wpa_bss *bss;
int ret;
char *pos, *end;
const u8 *ie, *ie2;
- if (wpa_s->scan_res == NULL &&
- wpa_supplicant_get_scan_results(wpa_s) < 0)
- return 0;
-
- results = wpa_s->scan_res;
- if (results == NULL)
- return 0;
-
- if (hwaddr_aton(cmd, bssid) == 0) {
- for (i = 0; i < results->num; i++) {
- if (os_memcmp(bssid, results->res[i]->bssid, ETH_ALEN)
- == 0)
- break;
+ if (os_strcmp(cmd, "FIRST") == 0)
+ bss = dl_list_first(&wpa_s->bss, struct wpa_bss, list);
+ else if (os_strncmp(cmd, "ID-", 3) == 0) {
+ i = atoi(cmd + 3);
+ bss = wpa_bss_get_id(wpa_s, i);
+ } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
+ i = atoi(cmd + 5);
+ bss = wpa_bss_get_id(wpa_s, i);
+ if (bss) {
+ struct dl_list *next = bss->list_id.next;
+ if (next == &wpa_s->bss_id)
+ bss = NULL;
+ else
+ bss = dl_list_entry(next, struct wpa_bss,
+ list_id);
}
- } else
+ } else if (hwaddr_aton(cmd, bssid) == 0)
+ bss = wpa_bss_get_bssid(wpa_s, bssid);
+ else {
+ struct wpa_bss *tmp;
i = atoi(cmd);
+ bss = NULL;
+ dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
+ {
+ if (i-- == 0) {
+ bss = tmp;
+ break;
+ }
+ }
+ }
- if (i >= results->num || results->res[i] == NULL)
- return 0; /* no match found */
+ if (bss == NULL)
+ return 0;
- bss = results->res[i];
pos = buf;
end = buf + buflen;
ret = os_snprintf(pos, end - pos,
+ "id=%u\n"
"bssid=" MACSTR "\n"
"freq=%d\n"
"beacon_int=%d\n"
@@ -1400,6 +1540,7 @@ static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
"level=%d\n"
"tsf=%016llu\n"
"ie=",
+ bss->id,
MAC2STR(bss->bssid), bss->freq, bss->beacon_int,
bss->caps, bss->qual, bss->noise, bss->level,
(unsigned long long) bss->tsf);
@@ -1425,10 +1566,10 @@ static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
return pos - buf;
pos += ret;
- ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
+ ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
if (ie)
pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
- ie2 = wpa_scan_get_ie(bss, WLAN_EID_RSN);
+ ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
if (ie2)
pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
pos = wpa_supplicant_wps_ie_txt(pos, end, bss);
@@ -1444,19 +1585,32 @@ static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
return pos - buf;
pos += ret;
}
+ if (bss->caps & IEEE80211_CAP_ESS) {
+ ret = os_snprintf(pos, end - pos, "[ESS]");
+ if (ret < 0 || ret >= end - pos)
+ return pos - buf;
+ pos += ret;
+ }
ret = os_snprintf(pos, end - pos, "\n");
if (ret < 0 || ret >= end - pos)
return pos - buf;
pos += ret;
- ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
ret = os_snprintf(pos, end - pos, "ssid=%s\n",
- ie ? wpa_ssid_txt(ie + 2, ie[1]) : "");
+ wpa_ssid_txt(bss->ssid, bss->ssid_len));
if (ret < 0 || ret >= end - pos)
return pos - buf;
pos += ret;
+#ifdef CONFIG_WPS
+ ie = (const u8 *) (bss + 1);
+ ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
+ if (ret < 0 || ret >= end - pos)
+ return pos - buf;
+ pos += ret;
+#endif /* CONFIG_WPS */
+
return pos - buf;
}
@@ -1465,10 +1619,71 @@ static int wpa_supplicant_ctrl_iface_ap_scan(
struct wpa_supplicant *wpa_s, char *cmd)
{
int ap_scan = atoi(cmd);
+ return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
+}
+
+
+static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
+{
+ u8 *bcast = (u8 *) "\xff\xff\xff\xff\xff\xff";
+
+ wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
+ /* MLME-DELETEKEYS.request */
+ wpa_drv_set_key(wpa_s, WPA_ALG_NONE, bcast, 0, 0, NULL, 0, NULL, 0);
+ wpa_drv_set_key(wpa_s, WPA_ALG_NONE, bcast, 1, 0, NULL, 0, NULL, 0);
+ wpa_drv_set_key(wpa_s, WPA_ALG_NONE, bcast, 2, 0, NULL, 0, NULL, 0);
+ wpa_drv_set_key(wpa_s, WPA_ALG_NONE, bcast, 3, 0, NULL, 0, NULL, 0);
+#ifdef CONFIG_IEEE80211W
+ wpa_drv_set_key(wpa_s, WPA_ALG_NONE, bcast, 4, 0, NULL, 0, NULL, 0);
+ wpa_drv_set_key(wpa_s, WPA_ALG_NONE, bcast, 5, 0, NULL, 0, NULL, 0);
+#endif /* CONFIG_IEEE80211W */
+
+ wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
+ 0);
+ /* MLME-SETPROTECTION.request(None) */
+ wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
+ MLME_SETPROTECTION_PROTECT_TYPE_NONE,
+ MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
+ wpa_sm_drop_sa(wpa_s->wpa);
+}
+
- if (ap_scan < 0 || ap_scan > 2)
+static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
+ char *addr)
+{
+ u8 bssid[ETH_ALEN];
+ struct wpa_bss *bss;
+ struct wpa_ssid *ssid = wpa_s->current_ssid;
+
+ if (hwaddr_aton(addr, bssid)) {
+ wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
+ "address '%s'", addr);
+ return -1;
+ }
+
+ wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
+
+ bss = wpa_bss_get_bssid(wpa_s, bssid);
+ if (!bss) {
+ wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
+ "from BSS table");
+ return -1;
+ }
+
+ /*
+ * TODO: Find best network configuration block from configuration to
+ * allow roaming to other networks
+ */
+
+ if (!ssid) {
+ wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
+ "configuration known for the target AP");
return -1;
- wpa_s->conf->ap_scan = ap_scan;
+ }
+
+ wpa_s->reassociate = 1;
+ wpa_supplicant_connect(wpa_s, bss, ssid);
+
return 0;
}
@@ -1517,7 +1732,8 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
reply_len = wpa_supplicant_ctrl_iface_status(
wpa_s, buf + 6, reply, reply_size);
} else if (os_strcmp(buf, "PMKSA") == 0) {
- reply_len = pmksa_cache_list(wpa_s->wpa, reply, reply_size);
+ reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
+ reply_size);
} else if (os_strncmp(buf, "SET ", 4) == 0) {
if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
reply_len = -1;
@@ -1561,10 +1777,37 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
reply,
reply_size);
+#ifdef CONFIG_WPS_OOB
+ } else if (os_strncmp(buf, "WPS_OOB ", 8) == 0) {
+ if (wpa_supplicant_ctrl_iface_wps_oob(wpa_s, buf + 8))
+ reply_len = -1;
+#endif /* CONFIG_WPS_OOB */
} else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
reply_len = -1;
+#ifdef CONFIG_WPS_ER
+ } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
+ if (wpas_wps_er_start(wpa_s))
+ reply_len = -1;
+ } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
+ if (wpas_wps_er_stop(wpa_s))
+ reply_len = -1;
+ } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
+ if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
+ reply_len = -1;
+ } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
+ if (wpas_wps_er_pbc(wpa_s, buf + 11))
+ reply_len = -1;
+ } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
+ if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
+ reply_len = -1;
+#endif /* CONFIG_WPS_ER */
#endif /* CONFIG_WPS */
+#ifdef CONFIG_IBSS_RSN
+ } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
+ if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
+ reply_len = -1;
+#endif /* CONFIG_IBSS_RSN */
} else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
{
if (wpa_supplicant_ctrl_iface_ctrl_rsp(
@@ -1576,7 +1819,7 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
if (wpa_supplicant_reload_configuration(wpa_s))
reply_len = -1;
} else if (os_strcmp(buf, "TERMINATE") == 0) {
- eloop_terminate();
+ wpa_supplicant_terminate_proc(wpa_s->global);
} else if (os_strncmp(buf, "BSSID ", 6) == 0) {
if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
reply_len = -1;
@@ -1586,7 +1829,8 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
} else if (os_strcmp(buf, "DISCONNECT") == 0) {
wpa_s->reassociate = 0;
wpa_s->disconnected = 1;
- wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
+ wpa_supplicant_deauthenticate(wpa_s,
+ WLAN_REASON_DEAUTH_LEAVING);
} else if (os_strcmp(buf, "SCAN") == 0) {
wpa_s->scan_req = 2;
wpa_supplicant_req_scan(wpa_s, 0, 0);
@@ -1634,6 +1878,25 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
} else if (os_strncmp(buf, "BSS ", 4) == 0) {
reply_len = wpa_supplicant_ctrl_iface_bss(
wpa_s, buf + 4, reply, reply_size);
+#ifdef CONFIG_AP
+ } else if (os_strcmp(buf, "STA-FIRST") == 0) {
+ reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
+ } else if (os_strncmp(buf, "STA ", 4) == 0) {
+ reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
+ reply_size);
+ } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
+ reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
+ reply_size);
+#endif /* CONFIG_AP */
+ } else if (os_strcmp(buf, "SUSPEND") == 0) {
+ wpas_notify_suspend(wpa_s->global);
+ } else if (os_strcmp(buf, "RESUME") == 0) {
+ wpas_notify_resume(wpa_s->global);
+ } else if (os_strcmp(buf, "DROP_SA") == 0) {
+ wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
+ } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
+ if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
+ reply_len = -1;
} else {
os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
reply_len = 16;
@@ -1765,11 +2028,11 @@ static int wpa_supplicant_global_iface_list(struct wpa_global *global,
struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
char *pos, *end;
- for (i = 0; wpa_supplicant_drivers[i]; i++) {
- struct wpa_driver_ops *drv = wpa_supplicant_drivers[i];
+ for (i = 0; wpa_drivers[i]; i++) {
+ struct wpa_driver_ops *drv = wpa_drivers[i];
if (drv->get_interfaces == NULL)
continue;
- tmp = drv->get_interfaces(global->drv_priv);
+ tmp = drv->get_interfaces(global->drv_priv[i]);
if (tmp == NULL)
continue;
@@ -1859,7 +2122,11 @@ char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
reply_len = wpa_supplicant_global_iface_interfaces(
global, reply, reply_size);
} else if (os_strcmp(buf, "TERMINATE") == 0) {
- eloop_terminate();
+ wpa_supplicant_terminate_proc(global);
+ } else if (os_strcmp(buf, "SUSPEND") == 0) {
+ wpas_notify_suspend(global);
+ } else if (os_strcmp(buf, "RESUME") == 0) {
+ wpas_notify_resume(global);
} else {
os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
reply_len = 16;
diff --git a/contrib/wpa/wpa_supplicant/ctrl_iface_named_pipe.c b/contrib/wpa/wpa_supplicant/ctrl_iface_named_pipe.c
index e8b53b1..5f7e24d 100644
--- a/contrib/wpa/wpa_supplicant/ctrl_iface_named_pipe.c
+++ b/contrib/wpa/wpa_supplicant/ctrl_iface_named_pipe.c
@@ -20,7 +20,7 @@
#include "eapol_supp/eapol_supp_sm.h"
#include "wpa_supplicant_i.h"
#include "ctrl_iface.h"
-#include "wpa_ctrl.h"
+#include "common/wpa_ctrl.h"
#ifdef __MINGW32_VERSION
/* mingw-w32api v3.1 does not yet include sddl.h, so define needed parts here
diff --git a/contrib/wpa/wpa_supplicant/ctrl_iface_udp.c b/contrib/wpa/wpa_supplicant/ctrl_iface_udp.c
index 18e4040..110ca4f 100644
--- a/contrib/wpa/wpa_supplicant/ctrl_iface_udp.c
+++ b/contrib/wpa/wpa_supplicant/ctrl_iface_udp.c
@@ -20,7 +20,7 @@
#include "eapol_supp/eapol_supp_sm.h"
#include "wpa_supplicant_i.h"
#include "ctrl_iface.h"
-#include "wpa_ctrl.h"
+#include "common/wpa_ctrl.h"
#define COOKIE_LEN 8
diff --git a/contrib/wpa/wpa_supplicant/ctrl_iface_unix.c b/contrib/wpa/wpa_supplicant/ctrl_iface_unix.c
index 2a62713..84ac760 100644
--- a/contrib/wpa/wpa_supplicant/ctrl_iface_unix.c
+++ b/contrib/wpa/wpa_supplicant/ctrl_iface_unix.c
@@ -1,6 +1,6 @@
/*
* WPA Supplicant / UNIX domain socket -based control interface
- * Copyright (c) 2004-2005, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -18,10 +18,11 @@
#include <grp.h>
#include <stddef.h>
-#include "common.h"
-#include "eloop.h"
-#include "config.h"
+#include "utils/common.h"
+#include "utils/eloop.h"
+#include "utils/list.h"
#include "eapol_supp/eapol_supp_sm.h"
+#include "config.h"
#include "wpa_supplicant_i.h"
#include "ctrl_iface.h"
@@ -35,7 +36,7 @@
* ctrl_iface_unix.c and should not be touched directly from other files.
*/
struct wpa_ctrl_dst {
- struct wpa_ctrl_dst *next;
+ struct dl_list list;
struct sockaddr_un addr;
socklen_t addrlen;
int debug_level;
@@ -46,7 +47,7 @@ struct wpa_ctrl_dst {
struct ctrl_iface_priv {
struct wpa_supplicant *wpa_s;
int sock;
- struct wpa_ctrl_dst *ctrl_dst;
+ struct dl_list ctrl_dst;
};
@@ -67,8 +68,7 @@ static int wpa_supplicant_ctrl_iface_attach(struct ctrl_iface_priv *priv,
os_memcpy(&dst->addr, from, sizeof(struct sockaddr_un));
dst->addrlen = fromlen;
dst->debug_level = MSG_INFO;
- dst->next = priv->ctrl_dst;
- priv->ctrl_dst = dst;
+ dl_list_add(&priv->ctrl_dst, &dst->list);
wpa_hexdump(MSG_DEBUG, "CTRL_IFACE monitor attached",
(u8 *) from->sun_path,
fromlen - offsetof(struct sockaddr_un, sun_path));
@@ -80,18 +80,14 @@ static int wpa_supplicant_ctrl_iface_detach(struct ctrl_iface_priv *priv,
struct sockaddr_un *from,
socklen_t fromlen)
{
- struct wpa_ctrl_dst *dst, *prev = NULL;
+ struct wpa_ctrl_dst *dst;
- dst = priv->ctrl_dst;
- while (dst) {
+ dl_list_for_each(dst, &priv->ctrl_dst, struct wpa_ctrl_dst, list) {
if (fromlen == dst->addrlen &&
os_memcmp(from->sun_path, dst->addr.sun_path,
fromlen - offsetof(struct sockaddr_un, sun_path))
== 0) {
- if (prev == NULL)
- priv->ctrl_dst = dst->next;
- else
- prev->next = dst->next;
+ dl_list_del(&dst->list);
os_free(dst);
wpa_hexdump(MSG_DEBUG, "CTRL_IFACE monitor detached",
(u8 *) from->sun_path,
@@ -99,8 +95,6 @@ static int wpa_supplicant_ctrl_iface_detach(struct ctrl_iface_priv *priv,
offsetof(struct sockaddr_un, sun_path));
return 0;
}
- prev = dst;
- dst = dst->next;
}
return -1;
}
@@ -115,8 +109,7 @@ static int wpa_supplicant_ctrl_iface_level(struct ctrl_iface_priv *priv,
wpa_printf(MSG_DEBUG, "CTRL_IFACE LEVEL %s", level);
- dst = priv->ctrl_dst;
- while (dst) {
+ dl_list_for_each(dst, &priv->ctrl_dst, struct wpa_ctrl_dst, list) {
if (fromlen == dst->addrlen &&
os_memcmp(from->sun_path, dst->addr.sun_path,
fromlen - offsetof(struct sockaddr_un, sun_path))
@@ -128,7 +121,6 @@ static int wpa_supplicant_ctrl_iface_level(struct ctrl_iface_priv *priv,
dst->debug_level = atoi(level);
return 0;
}
- dst = dst->next;
}
return -1;
@@ -274,6 +266,7 @@ wpa_supplicant_ctrl_iface_init(struct wpa_supplicant *wpa_s)
priv = os_zalloc(sizeof(*priv));
if (priv == NULL)
return NULL;
+ dl_list_init(&priv->ctrl_dst);
priv->wpa_s = wpa_s;
priv->sock = -1;
@@ -353,7 +346,7 @@ wpa_supplicant_ctrl_iface_init(struct wpa_supplicant *wpa_s)
}
os_memset(&addr, 0, sizeof(addr));
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
addr.sun_len = sizeof(addr);
#endif /* __FreeBSD__ */
addr.sun_family = AF_UNIX;
@@ -433,7 +426,7 @@ void wpa_supplicant_ctrl_iface_deinit(struct ctrl_iface_priv *priv)
char *fname;
char *buf, *dir = NULL, *gid_str = NULL;
eloop_unregister_read_sock(priv->sock);
- if (priv->ctrl_dst) {
+ if (!dl_list_empty(&priv->ctrl_dst)) {
/*
* Wait a second before closing the control socket if
* there are any attached monitors in order to allow
@@ -477,12 +470,9 @@ void wpa_supplicant_ctrl_iface_deinit(struct ctrl_iface_priv *priv)
}
free_dst:
- dst = priv->ctrl_dst;
- while (dst) {
- prev = dst;
- dst = dst->next;
- os_free(prev);
- }
+ dl_list_for_each_safe(dst, prev, &priv->ctrl_dst, struct wpa_ctrl_dst,
+ list)
+ os_free(dst);
os_free(priv);
}
@@ -506,8 +496,7 @@ static void wpa_supplicant_ctrl_iface_send(struct ctrl_iface_priv *priv,
struct msghdr msg;
struct iovec io[2];
- dst = priv->ctrl_dst;
- if (priv->sock < 0 || dst == NULL)
+ if (priv->sock < 0 || dl_list_empty(&priv->ctrl_dst))
return;
res = os_snprintf(levelstr, sizeof(levelstr), "<%d>", level);
@@ -522,8 +511,8 @@ static void wpa_supplicant_ctrl_iface_send(struct ctrl_iface_priv *priv,
msg.msg_iovlen = 2;
idx = 0;
- while (dst) {
- next = dst->next;
+ dl_list_for_each_safe(dst, next, &priv->ctrl_dst, struct wpa_ctrl_dst,
+ list) {
if (level >= dst->debug_level) {
wpa_hexdump(MSG_DEBUG, "CTRL_IFACE monitor send",
(u8 *) dst->addr.sun_path, dst->addrlen -
@@ -536,7 +525,9 @@ static void wpa_supplicant_ctrl_iface_send(struct ctrl_iface_priv *priv,
"%d - %s",
idx, errno, strerror(errno));
dst->errors++;
- if (dst->errors > 10 || _errno == ENOENT) {
+ if (dst->errors > 1000 ||
+ (_errno != ENOBUFS && dst->errors > 10) ||
+ _errno == ENOENT) {
wpa_supplicant_ctrl_iface_detach(
priv, &dst->addr,
dst->addrlen);
@@ -545,7 +536,6 @@ static void wpa_supplicant_ctrl_iface_send(struct ctrl_iface_priv *priv,
dst->errors = 0;
}
idx++;
- dst = next;
}
}
@@ -657,7 +647,7 @@ wpa_supplicant_global_ctrl_iface_init(struct wpa_global *global)
}
os_memset(&addr, 0, sizeof(addr));
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
addr.sun_len = sizeof(addr);
#endif /* __FreeBSD__ */
addr.sun_family = AF_UNIX;
diff --git a/contrib/wpa/wpa_supplicant/dbus/.gitignore b/contrib/wpa/wpa_supplicant/dbus/.gitignore
new file mode 100644
index 0000000..6db2468
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/dbus/.gitignore
@@ -0,0 +1 @@
+libwpadbus.a
diff --git a/contrib/wpa/wpa_supplicant/dbus/Makefile b/contrib/wpa/wpa_supplicant/dbus/Makefile
new file mode 100644
index 0000000..cfaf58d
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/dbus/Makefile
@@ -0,0 +1,84 @@
+all: libwpadbus.a
+
+clean:
+ rm -f *~ *.o *.d
+ rm -f libwpadbus.a
+
+install:
+ @echo Nothing to be made.
+
+ifndef CC
+CC=gcc
+endif
+
+ifndef CFLAGS
+CFLAGS = -MMD -O2 -Wall -g
+endif
+
+CFLAGS += -I../../src -I../../src/utils
+
+
+Q=@
+E=echo
+ifeq ($(V), 1)
+Q=
+E=true
+endif
+
+%.o: %.c
+ $(Q)$(CC) -c -o $@ $(CFLAGS) $<
+ @$(E) " CC " $<
+
+
+ifdef CONFIG_WPS
+CFLAGS += -DCONFIG_WPS
+endif
+
+CFLAGS += -DCONFIG_CTRL_IFACE_DBUS_NEW
+CFLAGS += -DCONFIG_CTRL_IFACE_DBUS
+
+ifndef DBUS_LIBS
+DBUS_LIBS := $(shell pkg-config --libs dbus-1)
+endif
+ifndef DBUS_INCLUDE
+DBUS_INCLUDE := $(shell pkg-config --cflags dbus-1)
+endif
+ifdef CONFIG_CTRL_IFACE_DBUS_INTRO
+CFLAGS += -DCONFIG_CTRL_IFACE_DBUS_INTRO
+DBUS_INCLUDE += $(shell xml2-config --cflags)
+DBUS_LIBS += $(shell xml2-config --libs)
+endif
+
+dbus_version=$(subst ., ,$(shell pkg-config --modversion dbus-1))
+DBUS_VERSION_MAJOR=$(word 1,$(dbus_version))
+DBUS_VERSION_MINOR=$(word 2,$(dbus_version))
+ifeq ($(DBUS_VERSION_MAJOR),)
+DBUS_VERSION_MAJOR=0
+endif
+ifeq ($(DBUS_VERSION_MINOR),)
+DBUS_VERSION_MINOR=0
+endif
+DBUS_INCLUDE += -DDBUS_VERSION_MAJOR=$(DBUS_VERSION_MAJOR)
+DBUS_INCLUDE += -DDBUS_VERSION_MINOR=$(DBUS_VERSION_MINOR)
+
+CFLAGS += $(DBUS_INCLUDE)
+
+LIB_OBJS= \
+ dbus_common.o \
+ dbus_old.o \
+ dbus_old_handlers.o \
+ dbus_new.o \
+ dbus_new_handlers.o \
+ dbus_new_helpers.o \
+ dbus_new_introspect.o \
+ dbus_dict_helpers.o
+
+ifdef CONFIG_WPS
+LIB_OBJS += dbus_old_handlers_wps.o
+LIB_OBJS += dbus_new_handlers_wps.o
+endif
+
+libwpadbus.a: $(LIB_OBJS)
+ $(AR) crT $@ $?
+
+-include $(OBJS:%.o=%.d)
diff --git a/contrib/wpa/wpa_supplicant/dbus-wpa_supplicant.conf b/contrib/wpa/wpa_supplicant/dbus/dbus-wpa_supplicant.conf
index 51a29e3..c091234 100644
--- a/contrib/wpa/wpa_supplicant/dbus-wpa_supplicant.conf
+++ b/contrib/wpa/wpa_supplicant/dbus/dbus-wpa_supplicant.conf
@@ -7,10 +7,21 @@
<allow send_destination="fi.epitest.hostap.WPASupplicant"/>
<allow send_interface="fi.epitest.hostap.WPASupplicant"/>
+
+ <allow own="fi.w1.wpa_supplicant1"/>
+
+ <allow send_destination="fi.w1.wpa_supplicant1"/>
+ <allow send_interface="fi.w1.wpa_supplicant1"/>
+ <allow receive_sender="fi.w1.wpa_supplicant1" receive_type="signal"/>
</policy>
<policy context="default">
<deny own="fi.epitest.hostap.WPASupplicant"/>
<deny send_destination="fi.epitest.hostap.WPASupplicant"/>
<deny send_interface="fi.epitest.hostap.WPASupplicant"/>
+
+ <deny own="fi.w1.wpa_supplicant1"/>
+ <deny send_destination="fi.w1.wpa_supplicant1"/>
+ <deny send_interface="fi.w1.wpa_supplicant1"/>
+ <deny receive_sender="fi.w1.wpa_supplicant1" receive_type="signal"/>
</policy>
</busconfig>
diff --git a/contrib/wpa/wpa_supplicant/dbus/dbus_common.c b/contrib/wpa/wpa_supplicant/dbus/dbus_common.c
new file mode 100644
index 0000000..5850636
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/dbus/dbus_common.c
@@ -0,0 +1,371 @@
+/*
+ * wpa_supplicant D-Bus control interface - common functionality
+ * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
+ * Copyright (c) 2009, Witold Sowa <witold.sowa@gmail.com>
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "utils/includes.h"
+#include <dbus/dbus.h>
+
+#include "utils/common.h"
+#include "utils/eloop.h"
+#include "dbus_common.h"
+#include "dbus_common_i.h"
+#include "dbus_new.h"
+#include "dbus_old.h"
+
+
+#ifndef SIGPOLL
+#ifdef SIGIO
+/*
+ * If we do not have SIGPOLL, try to use SIGIO instead. This is needed for
+ * FreeBSD.
+ */
+#define SIGPOLL SIGIO
+#endif
+#endif
+
+
+static void dispatch_data(DBusConnection *con)
+{
+ while (dbus_connection_get_dispatch_status(con) ==
+ DBUS_DISPATCH_DATA_REMAINS)
+ dbus_connection_dispatch(con);
+}
+
+
+/**
+ * dispatch_initial_dbus_messages - Dispatch initial dbus messages after
+ * claiming bus name
+ * @eloop_ctx: the DBusConnection to dispatch on
+ * @timeout_ctx: unused
+ *
+ * If clients are quick to notice that service claimed its bus name,
+ * there may have been messages that came in before initialization was
+ * all finished. Dispatch those here.
+ */
+static void dispatch_initial_dbus_messages(void *eloop_ctx, void *timeout_ctx)
+{
+ DBusConnection *con = eloop_ctx;
+ dispatch_data(con);
+}
+
+
+static void process_watch(struct wpas_dbus_priv *priv,
+ DBusWatch *watch, eloop_event_type type)
+{
+ dbus_connection_ref(priv->con);
+
+ priv->should_dispatch = 0;
+
+ if (type == EVENT_TYPE_READ)
+ dbus_watch_handle(watch, DBUS_WATCH_READABLE);
+ else if (type == EVENT_TYPE_WRITE)
+ dbus_watch_handle(watch, DBUS_WATCH_WRITABLE);
+ else if (type == EVENT_TYPE_EXCEPTION)
+ dbus_watch_handle(watch, DBUS_WATCH_ERROR);
+
+ if (priv->should_dispatch) {
+ dispatch_data(priv->con);
+ priv->should_dispatch = 0;
+ }
+
+ dbus_connection_unref(priv->con);
+}
+
+
+static void process_watch_exception(int sock, void *eloop_ctx, void *sock_ctx)
+{
+ process_watch(eloop_ctx, sock_ctx, EVENT_TYPE_EXCEPTION);
+}
+
+
+static void process_watch_read(int sock, void *eloop_ctx, void *sock_ctx)
+{
+ process_watch(eloop_ctx, sock_ctx, EVENT_TYPE_READ);
+}
+
+
+static void process_watch_write(int sock, void *eloop_ctx, void *sock_ctx)
+{
+ process_watch(eloop_ctx, sock_ctx, EVENT_TYPE_WRITE);
+}
+
+
+static dbus_bool_t add_watch(DBusWatch *watch, void *data)
+{
+ struct wpas_dbus_priv *priv = data;
+ unsigned int flags;
+ int fd;
+
+ if (!dbus_watch_get_enabled(watch))
+ return TRUE;
+
+ flags = dbus_watch_get_flags(watch);
+ fd = dbus_watch_get_unix_fd(watch);
+
+ eloop_register_sock(fd, EVENT_TYPE_EXCEPTION, process_watch_exception,
+ priv, watch);
+
+ if (flags & DBUS_WATCH_READABLE) {
+ eloop_register_sock(fd, EVENT_TYPE_READ, process_watch_read,
+ priv, watch);
+ }
+ if (flags & DBUS_WATCH_WRITABLE) {
+ eloop_register_sock(fd, EVENT_TYPE_WRITE, process_watch_write,
+ priv, watch);
+ }
+
+ dbus_watch_set_data(watch, priv, NULL);
+
+ return TRUE;
+}
+
+
+static void remove_watch(DBusWatch *watch, void *data)
+{
+ unsigned int flags;
+ int fd;
+
+ flags = dbus_watch_get_flags(watch);
+ fd = dbus_watch_get_unix_fd(watch);
+
+ eloop_unregister_sock(fd, EVENT_TYPE_EXCEPTION);
+
+ if (flags & DBUS_WATCH_READABLE)
+ eloop_unregister_sock(fd, EVENT_TYPE_READ);
+ if (flags & DBUS_WATCH_WRITABLE)
+ eloop_unregister_sock(fd, EVENT_TYPE_WRITE);
+
+ dbus_watch_set_data(watch, NULL, NULL);
+}
+
+
+static void watch_toggled(DBusWatch *watch, void *data)
+{
+ if (dbus_watch_get_enabled(watch))
+ add_watch(watch, data);
+ else
+ remove_watch(watch, data);
+}
+
+
+static void process_timeout(void *eloop_ctx, void *sock_ctx)
+{
+ DBusTimeout *timeout = sock_ctx;
+ dbus_timeout_handle(timeout);
+}
+
+
+static dbus_bool_t add_timeout(DBusTimeout *timeout, void *data)
+{
+ struct wpas_dbus_priv *priv = data;
+ if (!dbus_timeout_get_enabled(timeout))
+ return TRUE;
+
+ eloop_register_timeout(0, dbus_timeout_get_interval(timeout) * 1000,
+ process_timeout, priv, timeout);
+
+ dbus_timeout_set_data(timeout, priv, NULL);
+
+ return TRUE;
+}
+
+
+static void remove_timeout(DBusTimeout *timeout, void *data)
+{
+ struct wpas_dbus_priv *priv = data;
+ eloop_cancel_timeout(process_timeout, priv, timeout);
+ dbus_timeout_set_data(timeout, NULL, NULL);
+}
+
+
+static void timeout_toggled(DBusTimeout *timeout, void *data)
+{
+ if (dbus_timeout_get_enabled(timeout))
+ add_timeout(timeout, data);
+ else
+ remove_timeout(timeout, data);
+}
+
+
+static void process_wakeup_main(int sig, void *signal_ctx)
+{
+ struct wpas_dbus_priv *priv = signal_ctx;
+
+ if (sig != SIGPOLL || !priv->con)
+ return;
+
+ if (dbus_connection_get_dispatch_status(priv->con) !=
+ DBUS_DISPATCH_DATA_REMAINS)
+ return;
+
+ /* Only dispatch once - we do not want to starve other events */
+ dbus_connection_ref(priv->con);
+ dbus_connection_dispatch(priv->con);
+ dbus_connection_unref(priv->con);
+}
+
+
+/**
+ * wakeup_main - Attempt to wake our mainloop up
+ * @data: dbus control interface private data
+ *
+ * Try to wake up the main eloop so it will process
+ * dbus events that may have happened.
+ */
+static void wakeup_main(void *data)
+{
+ struct wpas_dbus_priv *priv = data;
+
+ /* Use SIGPOLL to break out of the eloop select() */
+ raise(SIGPOLL);
+ priv->should_dispatch = 1;
+}
+
+
+/**
+ * integrate_with_eloop - Register our mainloop integration with dbus
+ * @connection: connection to the system message bus
+ * @priv: a dbus control interface data structure
+ * Returns: 0 on success, -1 on failure
+ */
+static int integrate_with_eloop(struct wpas_dbus_priv *priv)
+{
+ if (!dbus_connection_set_watch_functions(priv->con, add_watch,
+ remove_watch, watch_toggled,
+ priv, NULL) ||
+ !dbus_connection_set_timeout_functions(priv->con, add_timeout,
+ remove_timeout,
+ timeout_toggled, priv,
+ NULL)) {
+ wpa_printf(MSG_ERROR, "dbus: Failed to set callback "
+ "functions");
+ return -1;
+ }
+
+ if (eloop_register_signal(SIGPOLL, process_wakeup_main, priv))
+ return -1;
+ dbus_connection_set_wakeup_main_function(priv->con, wakeup_main,
+ priv, NULL);
+
+ return 0;
+}
+
+
+static int wpas_dbus_init_common(struct wpas_dbus_priv *priv)
+{
+ DBusError error;
+ int ret = 0;
+
+ /* Get a reference to the system bus */
+ dbus_error_init(&error);
+ priv->con = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
+ if (!priv->con) {
+ wpa_printf(MSG_ERROR, "dbus: Could not acquire the system "
+ "bus: %s - %s", error.name, error.message);
+ ret = -1;
+ }
+ dbus_error_free(&error);
+
+ return ret;
+}
+
+
+static int wpas_dbus_init_common_finish(struct wpas_dbus_priv *priv)
+{
+ /* Tell dbus about our mainloop integration functions */
+ integrate_with_eloop(priv);
+
+ /*
+ * Dispatch initial DBus messages that may have come in since the bus
+ * name was claimed above. Happens when clients are quick to notice the
+ * service.
+ *
+ * FIXME: is there a better solution to this problem?
+ */
+ eloop_register_timeout(0, 50, dispatch_initial_dbus_messages,
+ priv->con, NULL);
+
+ return 0;
+}
+
+
+static void wpas_dbus_deinit_common(struct wpas_dbus_priv *priv)
+{
+ if (priv->con) {
+ eloop_cancel_timeout(dispatch_initial_dbus_messages,
+ priv->con, NULL);
+ dbus_connection_set_watch_functions(priv->con, NULL, NULL,
+ NULL, NULL, NULL);
+ dbus_connection_set_timeout_functions(priv->con, NULL, NULL,
+ NULL, NULL, NULL);
+ dbus_connection_unref(priv->con);
+ }
+
+ os_free(priv);
+}
+
+
+struct wpas_dbus_priv * wpas_dbus_init(struct wpa_global *global)
+{
+ struct wpas_dbus_priv *priv;
+
+ priv = os_zalloc(sizeof(*priv));
+ if (priv == NULL)
+ return NULL;
+ priv->global = global;
+
+ if (wpas_dbus_init_common(priv) < 0) {
+ wpas_dbus_deinit(priv);
+ return NULL;
+ }
+
+#ifdef CONFIG_CTRL_IFACE_DBUS_NEW
+ if (wpas_dbus_ctrl_iface_init(priv) < 0) {
+ wpas_dbus_deinit(priv);
+ return NULL;
+ }
+#endif /* CONFIG_CTRL_IFACE_DBUS_NEW */
+
+#ifdef CONFIG_CTRL_IFACE_DBUS
+ if (wpa_supplicant_dbus_ctrl_iface_init(priv) < 0) {
+ wpas_dbus_deinit(priv);
+ return NULL;
+ }
+#endif /* CONFIG_CTRL_IFACE_DBUS */
+
+ if (wpas_dbus_init_common_finish(priv) < 0) {
+ wpas_dbus_deinit(priv);
+ return NULL;
+ }
+
+ return priv;
+}
+
+
+void wpas_dbus_deinit(struct wpas_dbus_priv *priv)
+{
+ if (priv == NULL)
+ return;
+
+#ifdef CONFIG_CTRL_IFACE_DBUS_NEW
+ wpas_dbus_ctrl_iface_deinit(priv);
+#endif /* CONFIG_CTRL_IFACE_DBUS_NEW */
+
+#ifdef CONFIG_CTRL_IFACE_DBUS
+ /* TODO: is any deinit needed? */
+#endif /* CONFIG_CTRL_IFACE_DBUS */
+
+ wpas_dbus_deinit_common(priv);
+}
diff --git a/contrib/wpa/wpa_supplicant/dbus/dbus_common.h b/contrib/wpa/wpa_supplicant/dbus/dbus_common.h
new file mode 100644
index 0000000..50da09b
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/dbus/dbus_common.h
@@ -0,0 +1,26 @@
+/*
+ * wpa_supplicant D-Bus control interface - common definitions
+ * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
+ * Copyright (c) 2009, Witold Sowa <witold.sowa@gmail.com>
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef DBUS_COMMON_H
+#define DBUS_COMMON_H
+
+struct wpas_dbus_priv;
+struct wpa_global;
+
+struct wpas_dbus_priv * wpas_dbus_init(struct wpa_global *global);
+void wpas_dbus_deinit(struct wpas_dbus_priv *priv);
+
+#endif /* DBUS_COMMON_H */
diff --git a/contrib/wpa/wpa_supplicant/dbus/dbus_common_i.h b/contrib/wpa/wpa_supplicant/dbus/dbus_common_i.h
new file mode 100644
index 0000000..9dab1ee
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/dbus/dbus_common_i.h
@@ -0,0 +1,30 @@
+/*
+ * wpa_supplicant D-Bus control interface - internal definitions
+ * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
+ * Copyright (c) 2009, Witold Sowa <witold.sowa@gmail.com>
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef DBUS_COMMON_I_H
+#define DBUS_COMMON_I_H
+
+#include <dbus/dbus.h>
+
+struct wpas_dbus_priv {
+ DBusConnection *con;
+ int should_dispatch;
+ struct wpa_global *global;
+ u32 next_objid;
+ int dbus_new_initialized;
+};
+
+#endif /* DBUS_COMMON_I_H */
diff --git a/contrib/wpa/wpa_supplicant/dbus_dict_helpers.c b/contrib/wpa/wpa_supplicant/dbus/dbus_dict_helpers.c
index f93fc9d..b3aff40 100644
--- a/contrib/wpa/wpa_supplicant/dbus_dict_helpers.c
+++ b/contrib/wpa/wpa_supplicant/dbus/dbus_dict_helpers.c
@@ -69,7 +69,7 @@ dbus_bool_t wpa_dbus_dict_close_write(DBusMessageIter *iter,
}
-static const char * _wpa_get_type_as_string_from_type(const int type)
+const char * wpa_dbus_type_as_string(const int type)
{
switch(type) {
case DBUS_TYPE_BYTE:
@@ -140,7 +140,10 @@ static dbus_bool_t _wpa_dbus_add_dict_entry_basic(DBusMessageIter *iter_dict,
DBusMessageIter iter_dict_entry, iter_dict_val;
const char *type_as_string = NULL;
- type_as_string = _wpa_get_type_as_string_from_type(value_type);
+ if (key == NULL)
+ return FALSE;
+
+ type_as_string = wpa_dbus_type_as_string(value_type);
if (!type_as_string)
return FALSE;
@@ -218,7 +221,7 @@ static dbus_bool_t _wpa_dbus_add_dict_entry_byte_array(
dbus_bool_t wpa_dbus_dict_append_string(DBusMessageIter *iter_dict,
const char *key, const char *value)
{
- if (!key || !value)
+ if (!value)
return FALSE;
return _wpa_dbus_add_dict_entry_basic(iter_dict, key, DBUS_TYPE_STRING,
&value);
@@ -238,8 +241,6 @@ dbus_bool_t wpa_dbus_dict_append_string(DBusMessageIter *iter_dict,
dbus_bool_t wpa_dbus_dict_append_byte(DBusMessageIter *iter_dict,
const char *key, const char value)
{
- if (!key)
- return FALSE;
return _wpa_dbus_add_dict_entry_basic(iter_dict, key, DBUS_TYPE_BYTE,
&value);
}
@@ -258,8 +259,6 @@ dbus_bool_t wpa_dbus_dict_append_byte(DBusMessageIter *iter_dict,
dbus_bool_t wpa_dbus_dict_append_bool(DBusMessageIter *iter_dict,
const char *key, const dbus_bool_t value)
{
- if (!key)
- return FALSE;
return _wpa_dbus_add_dict_entry_basic(iter_dict, key,
DBUS_TYPE_BOOLEAN, &value);
}
@@ -279,8 +278,6 @@ dbus_bool_t wpa_dbus_dict_append_int16(DBusMessageIter *iter_dict,
const char *key,
const dbus_int16_t value)
{
- if (!key)
- return FALSE;
return _wpa_dbus_add_dict_entry_basic(iter_dict, key, DBUS_TYPE_INT16,
&value);
}
@@ -300,8 +297,6 @@ dbus_bool_t wpa_dbus_dict_append_uint16(DBusMessageIter *iter_dict,
const char *key,
const dbus_uint16_t value)
{
- if (!key)
- return FALSE;
return _wpa_dbus_add_dict_entry_basic(iter_dict, key, DBUS_TYPE_UINT16,
&value);
}
@@ -321,8 +316,6 @@ dbus_bool_t wpa_dbus_dict_append_int32(DBusMessageIter *iter_dict,
const char *key,
const dbus_int32_t value)
{
- if (!key)
- return FALSE;
return _wpa_dbus_add_dict_entry_basic(iter_dict, key, DBUS_TYPE_INT32,
&value);
}
@@ -342,8 +335,6 @@ dbus_bool_t wpa_dbus_dict_append_uint32(DBusMessageIter *iter_dict,
const char *key,
const dbus_uint32_t value)
{
- if (!key)
- return FALSE;
return _wpa_dbus_add_dict_entry_basic(iter_dict, key, DBUS_TYPE_UINT32,
&value);
}
@@ -363,8 +354,6 @@ dbus_bool_t wpa_dbus_dict_append_int64(DBusMessageIter *iter_dict,
const char *key,
const dbus_int64_t value)
{
- if (!key)
- return FALSE;
return _wpa_dbus_add_dict_entry_basic(iter_dict, key, DBUS_TYPE_INT64,
&value);
}
@@ -384,8 +373,6 @@ dbus_bool_t wpa_dbus_dict_append_uint64(DBusMessageIter *iter_dict,
const char *key,
const dbus_uint64_t value)
{
- if (!key)
- return FALSE;
return _wpa_dbus_add_dict_entry_basic(iter_dict, key, DBUS_TYPE_UINT64,
&value);
}
@@ -402,11 +389,8 @@ dbus_bool_t wpa_dbus_dict_append_uint64(DBusMessageIter *iter_dict,
*
*/
dbus_bool_t wpa_dbus_dict_append_double(DBusMessageIter *iter_dict,
- const char * key,
- const double value)
+ const char *key, const double value)
{
- if (!key)
- return FALSE;
return _wpa_dbus_add_dict_entry_basic(iter_dict, key, DBUS_TYPE_DOUBLE,
&value);
}
@@ -426,7 +410,7 @@ dbus_bool_t wpa_dbus_dict_append_object_path(DBusMessageIter *iter_dict,
const char *key,
const char *value)
{
- if (!key || !value)
+ if (!value)
return FALSE;
return _wpa_dbus_add_dict_entry_basic(iter_dict, key,
DBUS_TYPE_OBJECT_PATH, &value);
@@ -636,17 +620,14 @@ static dbus_bool_t _wpa_dbus_dict_entry_get_byte_array(
{
dbus_uint32_t count = 0;
dbus_bool_t success = FALSE;
- char *buffer;
+ char *buffer, *nbuffer;;
entry->bytearray_value = NULL;
entry->array_type = DBUS_TYPE_BYTE;
buffer = os_zalloc(BYTE_ARRAY_ITEM_SIZE * BYTE_ARRAY_CHUNK_SIZE);
- if (!buffer) {
- perror("_wpa_dbus_dict_entry_get_byte_array[dbus]: out of "
- "memory");
- goto done;
- }
+ if (!buffer)
+ return FALSE;
entry->bytearray_value = buffer;
entry->array_len = 0;
@@ -654,14 +635,17 @@ static dbus_bool_t _wpa_dbus_dict_entry_get_byte_array(
char byte;
if ((count % BYTE_ARRAY_CHUNK_SIZE) == 0 && count != 0) {
- buffer = realloc(buffer, BYTE_ARRAY_ITEM_SIZE *
- (count + BYTE_ARRAY_CHUNK_SIZE));
- if (buffer == NULL) {
- perror("_wpa_dbus_dict_entry_get_byte_array["
- "dbus] out of memory trying to "
- "retrieve the string array");
+ nbuffer = os_realloc(buffer, BYTE_ARRAY_ITEM_SIZE *
+ (count + BYTE_ARRAY_CHUNK_SIZE));
+ if (nbuffer == NULL) {
+ os_free(buffer);
+ wpa_printf(MSG_ERROR, "dbus: _wpa_dbus_dict_"
+ "entry_get_byte_array out of "
+ "memory trying to retrieve the "
+ "string array");
goto done;
}
+ buffer = nbuffer;
}
entry->bytearray_value = buffer;
@@ -673,7 +657,7 @@ static dbus_bool_t _wpa_dbus_dict_entry_get_byte_array(
/* Zero-length arrays are valid. */
if (entry->array_len == 0) {
- free(entry->bytearray_value);
+ os_free(entry->bytearray_value);
entry->bytearray_value = NULL;
}
@@ -693,17 +677,14 @@ static dbus_bool_t _wpa_dbus_dict_entry_get_string_array(
{
dbus_uint32_t count = 0;
dbus_bool_t success = FALSE;
- char **buffer;
+ char **buffer, **nbuffer;
entry->strarray_value = NULL;
entry->array_type = DBUS_TYPE_STRING;
buffer = os_zalloc(STR_ARRAY_ITEM_SIZE * STR_ARRAY_CHUNK_SIZE);
- if (buffer == NULL) {
- perror("_wpa_dbus_dict_entry_get_string_array[dbus] out of "
- "memory trying to retrieve a string array");
- goto done;
- }
+ if (buffer == NULL)
+ return FALSE;
entry->strarray_value = buffer;
entry->array_len = 0;
@@ -712,23 +693,26 @@ static dbus_bool_t _wpa_dbus_dict_entry_get_string_array(
char *str;
if ((count % STR_ARRAY_CHUNK_SIZE) == 0 && count != 0) {
- buffer = realloc(buffer, STR_ARRAY_ITEM_SIZE *
- (count + STR_ARRAY_CHUNK_SIZE));
- if (buffer == NULL) {
- perror("_wpa_dbus_dict_entry_get_string_array["
- "dbus] out of memory trying to "
- "retrieve the string array");
+ nbuffer = os_realloc(buffer, STR_ARRAY_ITEM_SIZE *
+ (count + STR_ARRAY_CHUNK_SIZE));
+ if (nbuffer == NULL) {
+ os_free(buffer);
+ wpa_printf(MSG_ERROR, "dbus: _wpa_dbus_dict_"
+ "entry_get_string_array out of "
+ "memory trying to retrieve the "
+ "string array");
goto done;
}
+ buffer = nbuffer;
}
entry->strarray_value = buffer;
dbus_message_iter_get_basic(iter, &value);
- str = strdup(value);
+ str = os_strdup(value);
if (str == NULL) {
- perror("_wpa_dbus_dict_entry_get_string_array[dbus] "
- "out of memory trying to duplicate the string "
- "array");
+ wpa_printf(MSG_ERROR, "dbus: _wpa_dbus_dict_entry_get_"
+ "string_array out of memory trying to "
+ "duplicate the string array");
goto done;
}
entry->strarray_value[count] = str;
@@ -738,7 +722,7 @@ static dbus_bool_t _wpa_dbus_dict_entry_get_string_array(
/* Zero-length arrays are valid. */
if (entry->array_len == 0) {
- free(entry->strarray_value);
+ os_free(entry->strarray_value);
entry->strarray_value = NULL;
}
@@ -781,87 +765,52 @@ static dbus_bool_t _wpa_dbus_dict_entry_get_array(
static dbus_bool_t _wpa_dbus_dict_fill_value_from_variant(
- struct wpa_dbus_dict_entry *entry, DBusMessageIter *iter_dict_val)
+ struct wpa_dbus_dict_entry *entry, DBusMessageIter *iter)
{
- dbus_bool_t success = TRUE;
+ const char *v;
switch (entry->type) {
- case DBUS_TYPE_STRING: {
- const char *v;
- dbus_message_iter_get_basic(iter_dict_val, &v);
- entry->str_value = strdup(v);
- break;
- }
- case DBUS_TYPE_BOOLEAN: {
- dbus_bool_t v;
- dbus_message_iter_get_basic(iter_dict_val, &v);
- entry->bool_value = v;
- break;
- }
- case DBUS_TYPE_BYTE: {
- char v;
- dbus_message_iter_get_basic(iter_dict_val, &v);
- entry->byte_value = v;
+ case DBUS_TYPE_OBJECT_PATH:
+ case DBUS_TYPE_STRING:
+ dbus_message_iter_get_basic(iter, &v);
+ entry->str_value = os_strdup(v);
+ if (entry->str_value == NULL)
+ return FALSE;
break;
- }
- case DBUS_TYPE_INT16: {
- dbus_int16_t v;
- dbus_message_iter_get_basic(iter_dict_val, &v);
- entry->int16_value = v;
+ case DBUS_TYPE_BOOLEAN:
+ dbus_message_iter_get_basic(iter, &entry->bool_value);
break;
- }
- case DBUS_TYPE_UINT16: {
- dbus_uint16_t v;
- dbus_message_iter_get_basic(iter_dict_val, &v);
- entry->uint16_value = v;
+ case DBUS_TYPE_BYTE:
+ dbus_message_iter_get_basic(iter, &entry->byte_value);
break;
- }
- case DBUS_TYPE_INT32: {
- dbus_int32_t v;
- dbus_message_iter_get_basic(iter_dict_val, &v);
- entry->int32_value = v;
+ case DBUS_TYPE_INT16:
+ dbus_message_iter_get_basic(iter, &entry->int16_value);
break;
- }
- case DBUS_TYPE_UINT32: {
- dbus_uint32_t v;
- dbus_message_iter_get_basic(iter_dict_val, &v);
- entry->uint32_value = v;
+ case DBUS_TYPE_UINT16:
+ dbus_message_iter_get_basic(iter, &entry->uint16_value);
break;
- }
- case DBUS_TYPE_INT64: {
- dbus_int64_t v;
- dbus_message_iter_get_basic(iter_dict_val, &v);
- entry->int64_value = v;
+ case DBUS_TYPE_INT32:
+ dbus_message_iter_get_basic(iter, &entry->int32_value);
break;
- }
- case DBUS_TYPE_UINT64: {
- dbus_uint64_t v;
- dbus_message_iter_get_basic(iter_dict_val, &v);
- entry->uint64_value = v;
+ case DBUS_TYPE_UINT32:
+ dbus_message_iter_get_basic(iter, &entry->uint32_value);
break;
- }
- case DBUS_TYPE_DOUBLE: {
- double v;
- dbus_message_iter_get_basic(iter_dict_val, &v);
- entry->double_value = v;
+ case DBUS_TYPE_INT64:
+ dbus_message_iter_get_basic(iter, &entry->int64_value);
break;
- }
- case DBUS_TYPE_OBJECT_PATH: {
- char *v;
- dbus_message_iter_get_basic(iter_dict_val, &v);
- entry->str_value = strdup(v);
+ case DBUS_TYPE_UINT64:
+ dbus_message_iter_get_basic(iter, &entry->uint64_value);
break;
- }
- case DBUS_TYPE_ARRAY: {
- success = _wpa_dbus_dict_entry_get_array(iter_dict_val, entry);
+ case DBUS_TYPE_DOUBLE:
+ dbus_message_iter_get_basic(iter, &entry->double_value);
break;
- }
+ case DBUS_TYPE_ARRAY:
+ return _wpa_dbus_dict_entry_get_array(iter, entry);
default:
- success = FALSE;
- break;
+ return FALSE;
}
- return success;
+ return TRUE;
}
@@ -933,10 +882,8 @@ error:
*/
dbus_bool_t wpa_dbus_dict_has_dict_entry(DBusMessageIter *iter_dict)
{
- if (!iter_dict) {
- perror("wpa_dbus_dict_has_dict_entry[dbus]: out of memory");
+ if (!iter_dict)
return FALSE;
- }
return dbus_message_iter_get_arg_type(iter_dict) ==
DBUS_TYPE_DICT_ENTRY;
}
@@ -956,17 +903,17 @@ void wpa_dbus_dict_entry_clear(struct wpa_dbus_dict_entry *entry)
switch (entry->type) {
case DBUS_TYPE_OBJECT_PATH:
case DBUS_TYPE_STRING:
- free(entry->str_value);
+ os_free(entry->str_value);
break;
case DBUS_TYPE_ARRAY:
switch (entry->array_type) {
case DBUS_TYPE_BYTE:
- free(entry->bytearray_value);
+ os_free(entry->bytearray_value);
break;
case DBUS_TYPE_STRING:
for (i = 0; i < entry->array_len; i++)
- free(entry->strarray_value[i]);
- free(entry->strarray_value);
+ os_free(entry->strarray_value[i]);
+ os_free(entry->strarray_value);
break;
}
break;
diff --git a/contrib/wpa/wpa_supplicant/dbus_dict_helpers.h b/contrib/wpa/wpa_supplicant/dbus/dbus_dict_helpers.h
index f873efc..eb31575 100644
--- a/contrib/wpa/wpa_supplicant/dbus_dict_helpers.h
+++ b/contrib/wpa/wpa_supplicant/dbus/dbus_dict_helpers.h
@@ -25,6 +25,8 @@ dbus_bool_t wpa_dbus_dict_open_write(DBusMessageIter *iter,
dbus_bool_t wpa_dbus_dict_close_write(DBusMessageIter *iter,
DBusMessageIter *iter_dict);
+const char * wpa_dbus_type_as_string(const int type);
+
dbus_bool_t wpa_dbus_dict_append_string(DBusMessageIter *iter_dict,
const char *key, const char *value);
diff --git a/contrib/wpa/wpa_supplicant/dbus/dbus_new.c b/contrib/wpa/wpa_supplicant/dbus/dbus_new.c
new file mode 100644
index 0000000..bdfbbac
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/dbus/dbus_new.c
@@ -0,0 +1,1562 @@
+/*
+ * WPA Supplicant / dbus-based control interface
+ * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
+ * Copyright (c) 2009-2010, Witold Sowa <witold.sowa@gmail.com>
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "wps/wps.h"
+#include "../config.h"
+#include "../wpa_supplicant_i.h"
+#include "../bss.h"
+#include "dbus_new_helpers.h"
+#include "dbus_dict_helpers.h"
+#include "dbus_new.h"
+#include "dbus_new_handlers.h"
+#include "dbus_common.h"
+#include "dbus_common_i.h"
+
+
+/**
+ * wpas_dbus_signal_interface - Send a interface related event signal
+ * @wpa_s: %wpa_supplicant network interface data
+ * @sig_name: signal name - InterfaceAdded or InterfaceRemoved
+ * @properties: Whether to add second argument with object properties
+ *
+ * Notify listeners about event related with interface
+ */
+static void wpas_dbus_signal_interface(struct wpa_supplicant *wpa_s,
+ const char *sig_name, int properties)
+{
+ struct wpas_dbus_priv *iface;
+ DBusMessage *msg;
+ DBusMessageIter iter, iter_dict;
+
+ iface = wpa_s->global->dbus;
+
+ /* Do nothing if the control interface is not turned on */
+ if (iface == NULL)
+ return;
+
+ msg = dbus_message_new_signal(WPAS_DBUS_NEW_PATH,
+ WPAS_DBUS_NEW_INTERFACE, sig_name);
+ if (msg == NULL)
+ return;
+
+ dbus_message_iter_init_append(msg, &iter);
+ if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
+ &wpa_s->dbus_new_path))
+ goto err;
+
+ if (properties) {
+ if (!wpa_dbus_dict_open_write(&iter, &iter_dict))
+ goto err;
+
+ wpa_dbus_get_object_properties(iface, wpa_s->dbus_new_path,
+ WPAS_DBUS_NEW_IFACE_INTERFACE,
+ &iter_dict);
+
+ if (!wpa_dbus_dict_close_write(&iter, &iter_dict))
+ goto err;
+ }
+
+ dbus_connection_send(iface->con, msg, NULL);
+ dbus_message_unref(msg);
+ return;
+
+err:
+ wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
+ dbus_message_unref(msg);
+}
+
+
+/**
+ * wpas_dbus_signal_interface_added - Send a interface created signal
+ * @wpa_s: %wpa_supplicant network interface data
+ *
+ * Notify listeners about creating new interface
+ */
+static void wpas_dbus_signal_interface_added(struct wpa_supplicant *wpa_s)
+{
+ wpas_dbus_signal_interface(wpa_s, "InterfaceAdded", TRUE);
+}
+
+
+/**
+ * wpas_dbus_signal_interface_removed - Send a interface removed signal
+ * @wpa_s: %wpa_supplicant network interface data
+ *
+ * Notify listeners about removing interface
+ */
+static void wpas_dbus_signal_interface_removed(struct wpa_supplicant *wpa_s)
+{
+ wpas_dbus_signal_interface(wpa_s, "InterfaceRemoved", FALSE);
+
+}
+
+
+/**
+ * wpas_dbus_signal_scan_done - send scan done signal
+ * @wpa_s: %wpa_supplicant network interface data
+ * @success: indicates if scanning succeed or failed
+ *
+ * Notify listeners about finishing a scan
+ */
+void wpas_dbus_signal_scan_done(struct wpa_supplicant *wpa_s, int success)
+{
+ struct wpas_dbus_priv *iface;
+ DBusMessage *msg;
+ dbus_bool_t succ;
+
+ iface = wpa_s->global->dbus;
+
+ /* Do nothing if the control interface is not turned on */
+ if (iface == NULL)
+ return;
+
+ msg = dbus_message_new_signal(wpa_s->dbus_new_path,
+ WPAS_DBUS_NEW_IFACE_INTERFACE,
+ "ScanDone");
+ if (msg == NULL)
+ return;
+
+ succ = success ? TRUE : FALSE;
+ if (dbus_message_append_args(msg, DBUS_TYPE_BOOLEAN, &succ,
+ DBUS_TYPE_INVALID))
+ dbus_connection_send(iface->con, msg, NULL);
+ else
+ wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
+ dbus_message_unref(msg);
+}
+
+
+/**
+ * wpas_dbus_signal_blob - Send a BSS related event signal
+ * @wpa_s: %wpa_supplicant network interface data
+ * @bss_obj_path: BSS object path
+ * @sig_name: signal name - BSSAdded or BSSRemoved
+ * @properties: Whether to add second argument with object properties
+ *
+ * Notify listeners about event related with BSS
+ */
+static void wpas_dbus_signal_bss(struct wpa_supplicant *wpa_s,
+ const char *bss_obj_path,
+ const char *sig_name, int properties)
+{
+ struct wpas_dbus_priv *iface;
+ DBusMessage *msg;
+ DBusMessageIter iter, iter_dict;
+
+ iface = wpa_s->global->dbus;
+
+ /* Do nothing if the control interface is not turned on */
+ if (iface == NULL)
+ return;
+
+ msg = dbus_message_new_signal(wpa_s->dbus_new_path,
+ WPAS_DBUS_NEW_IFACE_INTERFACE,
+ sig_name);
+ if (msg == NULL)
+ return;
+
+ dbus_message_iter_init_append(msg, &iter);
+ if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
+ &bss_obj_path))
+ goto err;
+
+ if (properties) {
+ if (!wpa_dbus_dict_open_write(&iter, &iter_dict))
+ goto err;
+
+ wpa_dbus_get_object_properties(iface, bss_obj_path,
+ WPAS_DBUS_NEW_IFACE_BSS,
+ &iter_dict);
+
+ if (!wpa_dbus_dict_close_write(&iter, &iter_dict))
+ goto err;
+ }
+
+ dbus_connection_send(iface->con, msg, NULL);
+ dbus_message_unref(msg);
+ return;
+
+err:
+ wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
+ dbus_message_unref(msg);
+}
+
+
+/**
+ * wpas_dbus_signal_bss_added - Send a BSS added signal
+ * @wpa_s: %wpa_supplicant network interface data
+ * @bss_obj_path: new BSS object path
+ *
+ * Notify listeners about adding new BSS
+ */
+static void wpas_dbus_signal_bss_added(struct wpa_supplicant *wpa_s,
+ const char *bss_obj_path)
+{
+ wpas_dbus_signal_bss(wpa_s, bss_obj_path, "BSSAdded", TRUE);
+}
+
+
+/**
+ * wpas_dbus_signal_bss_removed - Send a BSS removed signal
+ * @wpa_s: %wpa_supplicant network interface data
+ * @bss_obj_path: BSS object path
+ *
+ * Notify listeners about removing BSS
+ */
+static void wpas_dbus_signal_bss_removed(struct wpa_supplicant *wpa_s,
+ const char *bss_obj_path)
+{
+ wpas_dbus_signal_bss(wpa_s, bss_obj_path, "BSSRemoved", FALSE);
+}
+
+
+/**
+ * wpas_dbus_signal_blob - Send a blob related event signal
+ * @wpa_s: %wpa_supplicant network interface data
+ * @name: blob name
+ * @sig_name: signal name - BlobAdded or BlobRemoved
+ *
+ * Notify listeners about event related with blob
+ */
+static void wpas_dbus_signal_blob(struct wpa_supplicant *wpa_s,
+ const char *name, const char *sig_name)
+{
+ struct wpas_dbus_priv *iface;
+ DBusMessage *msg;
+
+ iface = wpa_s->global->dbus;
+
+ /* Do nothing if the control interface is not turned on */
+ if (iface == NULL)
+ return;
+
+ msg = dbus_message_new_signal(wpa_s->dbus_new_path,
+ WPAS_DBUS_NEW_IFACE_INTERFACE,
+ sig_name);
+ if (msg == NULL)
+ return;
+
+ if (dbus_message_append_args(msg, DBUS_TYPE_STRING, &name,
+ DBUS_TYPE_INVALID))
+ dbus_connection_send(iface->con, msg, NULL);
+ else
+ wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
+ dbus_message_unref(msg);
+}
+
+
+/**
+ * wpas_dbus_signal_blob_added - Send a blob added signal
+ * @wpa_s: %wpa_supplicant network interface data
+ * @name: blob name
+ *
+ * Notify listeners about adding a new blob
+ */
+void wpas_dbus_signal_blob_added(struct wpa_supplicant *wpa_s,
+ const char *name)
+{
+ wpas_dbus_signal_blob(wpa_s, name, "BlobAdded");
+}
+
+
+/**
+ * wpas_dbus_signal_blob_removed - Send a blob removed signal
+ * @wpa_s: %wpa_supplicant network interface data
+ * @name: blob name
+ *
+ * Notify listeners about removing blob
+ */
+void wpas_dbus_signal_blob_removed(struct wpa_supplicant *wpa_s,
+ const char *name)
+{
+ wpas_dbus_signal_blob(wpa_s, name, "BlobRemoved");
+}
+
+
+/**
+ * wpas_dbus_signal_network - Send a network related event signal
+ * @wpa_s: %wpa_supplicant network interface data
+ * @id: new network id
+ * @sig_name: signal name - NetworkAdded, NetworkRemoved or NetworkSelected
+ * @properties: determines if add second argument with object properties
+ *
+ * Notify listeners about event related with configured network
+ */
+static void wpas_dbus_signal_network(struct wpa_supplicant *wpa_s,
+ int id, const char *sig_name,
+ int properties)
+{
+ struct wpas_dbus_priv *iface;
+ DBusMessage *msg;
+ DBusMessageIter iter, iter_dict;
+ char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
+
+ iface = wpa_s->global->dbus;
+
+ /* Do nothing if the control interface is not turned on */
+ if (iface == NULL)
+ return;
+
+ os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
+ "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
+ wpa_s->dbus_new_path, id);
+
+ msg = dbus_message_new_signal(wpa_s->dbus_new_path,
+ WPAS_DBUS_NEW_IFACE_INTERFACE,
+ sig_name);
+ if (msg == NULL)
+ return;
+
+ dbus_message_iter_init_append(msg, &iter);
+ path = net_obj_path;
+ if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
+ &path))
+ goto err;
+
+ if (properties) {
+ if (!wpa_dbus_dict_open_write(&iter, &iter_dict))
+ goto err;
+
+ wpa_dbus_get_object_properties(iface, net_obj_path,
+ WPAS_DBUS_NEW_IFACE_NETWORK,
+ &iter_dict);
+
+ if (!wpa_dbus_dict_close_write(&iter, &iter_dict))
+ goto err;
+ }
+
+ dbus_connection_send(iface->con, msg, NULL);
+
+ dbus_message_unref(msg);
+ return;
+
+err:
+ wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
+ dbus_message_unref(msg);
+}
+
+
+/**
+ * wpas_dbus_signal_network_added - Send a network added signal
+ * @wpa_s: %wpa_supplicant network interface data
+ * @id: new network id
+ *
+ * Notify listeners about adding new network
+ */
+static void wpas_dbus_signal_network_added(struct wpa_supplicant *wpa_s,
+ int id)
+{
+ wpas_dbus_signal_network(wpa_s, id, "NetworkAdded", TRUE);
+}
+
+
+/**
+ * wpas_dbus_signal_network_removed - Send a network removed signal
+ * @wpa_s: %wpa_supplicant network interface data
+ * @id: network id
+ *
+ * Notify listeners about removing a network
+ */
+static void wpas_dbus_signal_network_removed(struct wpa_supplicant *wpa_s,
+ int id)
+{
+ wpas_dbus_signal_network(wpa_s, id, "NetworkRemoved", FALSE);
+}
+
+
+/**
+ * wpas_dbus_signal_network_selected - Send a network selected signal
+ * @wpa_s: %wpa_supplicant network interface data
+ * @id: network id
+ *
+ * Notify listeners about selecting a network
+ */
+void wpas_dbus_signal_network_selected(struct wpa_supplicant *wpa_s, int id)
+{
+ wpas_dbus_signal_network(wpa_s, id, "NetworkSelected", FALSE);
+}
+
+
+/**
+ * wpas_dbus_signal_network_enabled_changed - Signals Enabled property changes
+ * @wpa_s: %wpa_supplicant network interface data
+ * @ssid: configured network which Enabled property has changed
+ *
+ * Sends PropertyChanged signals containing new value of Enabled property
+ * for specified network
+ */
+void wpas_dbus_signal_network_enabled_changed(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid)
+{
+
+ char path[WPAS_DBUS_OBJECT_PATH_MAX];
+ os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
+ "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
+ wpa_s->dbus_new_path, ssid->id);
+
+ wpa_dbus_mark_property_changed(wpa_s->global->dbus, path,
+ WPAS_DBUS_NEW_IFACE_NETWORK, "Enabled");
+}
+
+
+#ifdef CONFIG_WPS
+
+/**
+ * wpas_dbus_signal_wps_event_success - Signals Success WPS event
+ * @wpa_s: %wpa_supplicant network interface data
+ *
+ * Sends Event dbus signal with name "success" and empty dict as arguments
+ */
+void wpas_dbus_signal_wps_event_success(struct wpa_supplicant *wpa_s)
+{
+
+ DBusMessage *msg;
+ DBusMessageIter iter, dict_iter;
+ struct wpas_dbus_priv *iface;
+ char *key = "success";
+
+ iface = wpa_s->global->dbus;
+
+ /* Do nothing if the control interface is not turned on */
+ if (iface == NULL)
+ return;
+
+ msg = dbus_message_new_signal(wpa_s->dbus_new_path,
+ WPAS_DBUS_NEW_IFACE_WPS, "Event");
+ if (msg == NULL)
+ return;
+
+ dbus_message_iter_init_append(msg, &iter);
+
+ if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
+ !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
+ !wpa_dbus_dict_close_write(&iter, &dict_iter))
+ wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
+ else
+ dbus_connection_send(iface->con, msg, NULL);
+
+ dbus_message_unref(msg);
+}
+
+
+/**
+ * wpas_dbus_signal_wps_event_fail - Signals Fail WPS event
+ * @wpa_s: %wpa_supplicant network interface data
+ *
+ * Sends Event dbus signal with name "fail" and dictionary containing
+ * "msg field with fail message number (int32) as arguments
+ */
+void wpas_dbus_signal_wps_event_fail(struct wpa_supplicant *wpa_s,
+ struct wps_event_fail *fail)
+{
+
+ DBusMessage *msg;
+ DBusMessageIter iter, dict_iter;
+ struct wpas_dbus_priv *iface;
+ char *key = "fail";
+
+ iface = wpa_s->global->dbus;
+
+ /* Do nothing if the control interface is not turned on */
+ if (iface == NULL)
+ return;
+
+ msg = dbus_message_new_signal(wpa_s->dbus_new_path,
+ WPAS_DBUS_NEW_IFACE_WPS, "Event");
+ if (msg == NULL)
+ return;
+
+ dbus_message_iter_init_append(msg, &iter);
+
+ if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
+ !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
+ !wpa_dbus_dict_append_int32(&dict_iter, "msg", fail->msg) ||
+ !wpa_dbus_dict_close_write(&iter, &dict_iter))
+ wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
+ else
+ dbus_connection_send(iface->con, msg, NULL);
+
+ dbus_message_unref(msg);
+}
+
+
+/**
+ * wpas_dbus_signal_wps_event_m2d - Signals M2D WPS event
+ * @wpa_s: %wpa_supplicant network interface data
+ *
+ * Sends Event dbus signal with name "m2d" and dictionary containing
+ * fields of wps_event_m2d structure.
+ */
+void wpas_dbus_signal_wps_event_m2d(struct wpa_supplicant *wpa_s,
+ struct wps_event_m2d *m2d)
+{
+
+ DBusMessage *msg;
+ DBusMessageIter iter, dict_iter;
+ struct wpas_dbus_priv *iface;
+ char *key = "m2d";
+
+ iface = wpa_s->global->dbus;
+
+ /* Do nothing if the control interface is not turned on */
+ if (iface == NULL)
+ return;
+
+ msg = dbus_message_new_signal(wpa_s->dbus_new_path,
+ WPAS_DBUS_NEW_IFACE_WPS, "Event");
+ if (msg == NULL)
+ return;
+
+ dbus_message_iter_init_append(msg, &iter);
+
+ if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
+ !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
+ !wpa_dbus_dict_append_uint16(&dict_iter, "config_methods",
+ m2d->config_methods) ||
+ !wpa_dbus_dict_append_byte_array(&dict_iter, "manufacturer",
+ (const char *) m2d->manufacturer,
+ m2d->manufacturer_len) ||
+ !wpa_dbus_dict_append_byte_array(&dict_iter, "model_name",
+ (const char *) m2d->model_name,
+ m2d->model_name_len) ||
+ !wpa_dbus_dict_append_byte_array(&dict_iter, "model_number",
+ (const char *) m2d->model_number,
+ m2d->model_number_len) ||
+ !wpa_dbus_dict_append_byte_array(&dict_iter, "serial_number",
+ (const char *)
+ m2d->serial_number,
+ m2d->serial_number_len) ||
+ !wpa_dbus_dict_append_byte_array(&dict_iter, "dev_name",
+ (const char *) m2d->dev_name,
+ m2d->dev_name_len) ||
+ !wpa_dbus_dict_append_byte_array(&dict_iter, "primary_dev_type",
+ (const char *)
+ m2d->primary_dev_type, 8) ||
+ !wpa_dbus_dict_append_uint16(&dict_iter, "config_error",
+ m2d->config_error) ||
+ !wpa_dbus_dict_append_uint16(&dict_iter, "dev_password_id",
+ m2d->dev_password_id) ||
+ !wpa_dbus_dict_close_write(&iter, &dict_iter))
+ wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
+ else
+ dbus_connection_send(iface->con, msg, NULL);
+
+ dbus_message_unref(msg);
+}
+
+
+/**
+ * wpas_dbus_signal_wps_cred - Signals new credentials
+ * @wpa_s: %wpa_supplicant network interface data
+ *
+ * Sends signal with credentials in directory argument
+ */
+void wpas_dbus_signal_wps_cred(struct wpa_supplicant *wpa_s,
+ const struct wps_credential *cred)
+{
+ DBusMessage *msg;
+ DBusMessageIter iter, dict_iter;
+ struct wpas_dbus_priv *iface;
+ char *auth_type[6]; /* we have six possible authorization types */
+ int at_num = 0;
+ char *encr_type[4]; /* we have four possible encryption types */
+ int et_num = 0;
+
+ iface = wpa_s->global->dbus;
+
+ /* Do nothing if the control interface is not turned on */
+ if (iface == NULL)
+ return;
+
+ msg = dbus_message_new_signal(wpa_s->dbus_new_path,
+ WPAS_DBUS_NEW_IFACE_WPS,
+ "Credentials");
+ if (msg == NULL)
+ return;
+
+ dbus_message_iter_init_append(msg, &iter);
+ if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
+ goto nomem;
+
+ if (cred->auth_type & WPS_AUTH_OPEN)
+ auth_type[at_num++] = "open";
+ if (cred->auth_type & WPS_AUTH_WPAPSK)
+ auth_type[at_num++] = "wpa-psk";
+ if (cred->auth_type & WPS_AUTH_SHARED)
+ auth_type[at_num++] = "shared";
+ if (cred->auth_type & WPS_AUTH_WPA)
+ auth_type[at_num++] = "wpa-eap";
+ if (cred->auth_type & WPS_AUTH_WPA2)
+ auth_type[at_num++] = "wpa2-eap";
+ if (cred->auth_type & WPS_AUTH_WPA2PSK)
+ auth_type[at_num++] =
+ "wpa2-psk";
+
+ if (cred->encr_type & WPS_ENCR_NONE)
+ encr_type[et_num++] = "none";
+ if (cred->encr_type & WPS_ENCR_WEP)
+ encr_type[et_num++] = "wep";
+ if (cred->encr_type & WPS_ENCR_TKIP)
+ encr_type[et_num++] = "tkip";
+ if (cred->encr_type & WPS_ENCR_AES)
+ encr_type[et_num++] = "aes";
+
+ if (wpa_s->current_ssid) {
+ if (!wpa_dbus_dict_append_byte_array(
+ &dict_iter, "BSSID",
+ (const char *) wpa_s->current_ssid->bssid,
+ ETH_ALEN))
+ goto nomem;
+ }
+
+ if (!wpa_dbus_dict_append_byte_array(&dict_iter, "SSID",
+ (const char *) cred->ssid,
+ cred->ssid_len) ||
+ !wpa_dbus_dict_append_string_array(&dict_iter, "AuthType",
+ (const char **) auth_type,
+ at_num) ||
+ !wpa_dbus_dict_append_string_array(&dict_iter, "EncrType",
+ (const char **) encr_type,
+ et_num) ||
+ !wpa_dbus_dict_append_byte_array(&dict_iter, "Key",
+ (const char *) cred->key,
+ cred->key_len) ||
+ !wpa_dbus_dict_append_uint32(&dict_iter, "KeyIndex",
+ cred->key_idx) ||
+ !wpa_dbus_dict_close_write(&iter, &dict_iter))
+ goto nomem;
+
+ dbus_connection_send(iface->con, msg, NULL);
+
+nomem:
+ dbus_message_unref(msg);
+}
+
+#endif /* CONFIG_WPS */
+
+
+/**
+ * wpas_dbus_signal_prop_changed - Signals change of property
+ * @wpa_s: %wpa_supplicant network interface data
+ * @property: indicates which property has changed
+ *
+ * Sends ProertyChanged signals with path, interface and arguments
+ * depending on which property has changed.
+ */
+void wpas_dbus_signal_prop_changed(struct wpa_supplicant *wpa_s,
+ enum wpas_dbus_prop property)
+{
+ WPADBusPropertyAccessor getter;
+ char *prop;
+
+ if (wpa_s->dbus_new_path == NULL)
+ return; /* Skip signal since D-Bus setup is not yet ready */
+
+ switch (property) {
+ case WPAS_DBUS_PROP_AP_SCAN:
+ getter = (WPADBusPropertyAccessor) wpas_dbus_getter_ap_scan;
+ prop = "ApScan";
+ break;
+ case WPAS_DBUS_PROP_SCANNING:
+ getter = (WPADBusPropertyAccessor) wpas_dbus_getter_scanning;
+ prop = "Scanning";
+ break;
+ case WPAS_DBUS_PROP_STATE:
+ getter = (WPADBusPropertyAccessor) wpas_dbus_getter_state;
+ prop = "State";
+ break;
+ case WPAS_DBUS_PROP_CURRENT_BSS:
+ getter = (WPADBusPropertyAccessor)
+ wpas_dbus_getter_current_bss;
+ prop = "CurrentBSS";
+ break;
+ case WPAS_DBUS_PROP_CURRENT_NETWORK:
+ getter = (WPADBusPropertyAccessor)
+ wpas_dbus_getter_current_network;
+ prop = "CurrentNetwork";
+ break;
+ default:
+ wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
+ __func__, property);
+ return;
+ }
+
+ wpa_dbus_mark_property_changed(wpa_s->global->dbus,
+ wpa_s->dbus_new_path,
+ WPAS_DBUS_NEW_IFACE_INTERFACE, prop);
+}
+
+
+/**
+ * wpas_dbus_bss_signal_prop_changed - Signals change of BSS property
+ * @wpa_s: %wpa_supplicant network interface data
+ * @property: indicates which property has changed
+ * @id: unique BSS identifier
+ *
+ * Sends PropertyChanged signals with path, interface, and arguments depending
+ * on which property has changed.
+ */
+void wpas_dbus_bss_signal_prop_changed(struct wpa_supplicant *wpa_s,
+ enum wpas_dbus_bss_prop property,
+ unsigned int id)
+{
+ char path[WPAS_DBUS_OBJECT_PATH_MAX];
+ char *prop;
+
+ switch (property) {
+ case WPAS_DBUS_BSS_PROP_SIGNAL:
+ prop = "Signal";
+ break;
+ case WPAS_DBUS_BSS_PROP_FREQ:
+ prop = "Frequency";
+ break;
+ case WPAS_DBUS_BSS_PROP_MODE:
+ prop = "Mode";
+ break;
+ case WPAS_DBUS_BSS_PROP_PRIVACY:
+ prop = "Privacy";
+ break;
+ case WPAS_DBUS_BSS_PROP_RATES:
+ prop = "Rates";
+ break;
+ case WPAS_DBUS_BSS_PROP_WPA:
+ prop = "WPA";
+ break;
+ case WPAS_DBUS_BSS_PROP_RSN:
+ prop = "RSN";
+ break;
+ case WPAS_DBUS_BSS_PROP_IES:
+ prop = "IEs";
+ break;
+ default:
+ wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
+ __func__, property);
+ return;
+ }
+
+ os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
+ "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
+ wpa_s->dbus_new_path, id);
+
+ wpa_dbus_mark_property_changed(wpa_s->global->dbus, path,
+ WPAS_DBUS_NEW_IFACE_BSS, prop);
+}
+
+
+/**
+ * wpas_dbus_signal_debug_level_changed - Signals change of debug param
+ * @global: wpa_global structure
+ *
+ * Sends ProertyChanged signals informing that debug level has changed.
+ */
+void wpas_dbus_signal_debug_level_changed(struct wpa_global *global)
+{
+ wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
+ WPAS_DBUS_NEW_INTERFACE,
+ "DebugLevel");
+}
+
+
+/**
+ * wpas_dbus_signal_debug_timestamp_changed - Signals change of debug param
+ * @global: wpa_global structure
+ *
+ * Sends ProertyChanged signals informing that debug timestamp has changed.
+ */
+void wpas_dbus_signal_debug_timestamp_changed(struct wpa_global *global)
+{
+ wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
+ WPAS_DBUS_NEW_INTERFACE,
+ "DebugTimestamp");
+}
+
+
+/**
+ * wpas_dbus_signal_debug_show_keys_changed - Signals change of debug param
+ * @global: wpa_global structure
+ *
+ * Sends ProertyChanged signals informing that debug show_keys has changed.
+ */
+void wpas_dbus_signal_debug_show_keys_changed(struct wpa_global *global)
+{
+ wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
+ WPAS_DBUS_NEW_INTERFACE,
+ "DebugShowKeys");
+}
+
+
+static void wpas_dbus_register(struct wpa_dbus_object_desc *obj_desc,
+ void *priv,
+ WPADBusArgumentFreeFunction priv_free,
+ const struct wpa_dbus_method_desc *methods,
+ const struct wpa_dbus_property_desc *properties,
+ const struct wpa_dbus_signal_desc *signals)
+{
+ int n;
+
+ obj_desc->user_data = priv;
+ obj_desc->user_data_free_func = priv_free;
+ obj_desc->methods = methods;
+ obj_desc->properties = properties;
+ obj_desc->signals = signals;
+
+ for (n = 0; properties && properties->dbus_property; properties++)
+ n++;
+
+ obj_desc->prop_changed_flags = os_zalloc(n);
+ if (!obj_desc->prop_changed_flags)
+ wpa_printf(MSG_DEBUG, "dbus: %s: can't register handlers",
+ __func__);
+}
+
+
+static const struct wpa_dbus_method_desc wpas_dbus_global_methods[] = {
+ { "CreateInterface", WPAS_DBUS_NEW_INTERFACE,
+ (WPADBusMethodHandler) &wpas_dbus_handler_create_interface,
+ {
+ { "args", "a{sv}", ARG_IN },
+ { "path", "o", ARG_OUT },
+ END_ARGS
+ }
+ },
+ { "RemoveInterface", WPAS_DBUS_NEW_INTERFACE,
+ (WPADBusMethodHandler) &wpas_dbus_handler_remove_interface,
+ {
+ { "path", "o", ARG_IN },
+ END_ARGS
+ }
+ },
+ { "GetInterface", WPAS_DBUS_NEW_INTERFACE,
+ (WPADBusMethodHandler) &wpas_dbus_handler_get_interface,
+ {
+ { "ifname", "s", ARG_IN },
+ { "path", "o", ARG_OUT },
+ END_ARGS
+ }
+ },
+ { NULL, NULL, NULL, { END_ARGS } }
+};
+
+static const struct wpa_dbus_property_desc wpas_dbus_global_properties[] = {
+ { "DebugLevel", WPAS_DBUS_NEW_INTERFACE, "s",
+ (WPADBusPropertyAccessor) wpas_dbus_getter_debug_level,
+ (WPADBusPropertyAccessor) wpas_dbus_setter_debug_level,
+ RW
+ },
+ { "DebugTimestamp", WPAS_DBUS_NEW_INTERFACE, "b",
+ (WPADBusPropertyAccessor) wpas_dbus_getter_debug_timestamp,
+ (WPADBusPropertyAccessor) wpas_dbus_setter_debug_timestamp,
+ RW
+ },
+ { "DebugShowKeys", WPAS_DBUS_NEW_INTERFACE, "b",
+ (WPADBusPropertyAccessor) wpas_dbus_getter_debug_show_keys,
+ (WPADBusPropertyAccessor) wpas_dbus_setter_debug_show_keys,
+ RW
+ },
+ { "Interfaces", WPAS_DBUS_NEW_INTERFACE, "ao",
+ (WPADBusPropertyAccessor) &wpas_dbus_getter_interfaces,
+ NULL,
+ R
+ },
+ { "EapMethods", WPAS_DBUS_NEW_INTERFACE, "as",
+ (WPADBusPropertyAccessor) wpas_dbus_getter_eap_methods,
+ NULL,
+ R
+ },
+ { NULL, NULL, NULL, NULL, NULL, 0 }
+};
+
+static const struct wpa_dbus_signal_desc wpas_dbus_global_signals[] = {
+ { "InterfaceAdded", WPAS_DBUS_NEW_INTERFACE,
+ {
+ { "path", "o", ARG_OUT },
+ { "properties", "a{sv}", ARG_OUT },
+ END_ARGS
+ }
+ },
+ { "InterfaceRemoved", WPAS_DBUS_NEW_INTERFACE,
+ {
+ { "path", "o", ARG_OUT },
+ END_ARGS
+ }
+ },
+ { "PropertiesChanged", WPAS_DBUS_NEW_INTERFACE,
+ {
+ { "properties", "a{sv}", ARG_OUT },
+ END_ARGS
+ }
+ },
+ { NULL, NULL, { END_ARGS } }
+};
+
+
+/**
+ * wpas_dbus_ctrl_iface_init - Initialize dbus control interface
+ * @global: Pointer to global data from wpa_supplicant_init()
+ * Returns: 0 on success or -1 on failure
+ *
+ * Initialize the dbus control interface for wpa_supplicantand and start
+ * receiving commands from external programs over the bus.
+ */
+int wpas_dbus_ctrl_iface_init(struct wpas_dbus_priv *priv)
+{
+ struct wpa_dbus_object_desc *obj_desc;
+ int ret;
+
+ obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
+ if (!obj_desc) {
+ wpa_printf(MSG_ERROR, "Not enough memory "
+ "to create object description");
+ return -1;
+ }
+
+ wpas_dbus_register(obj_desc, priv->global, NULL,
+ wpas_dbus_global_methods,
+ wpas_dbus_global_properties,
+ wpas_dbus_global_signals);
+
+ wpa_printf(MSG_DEBUG, "dbus: Register D-Bus object '%s'",
+ WPAS_DBUS_NEW_PATH);
+ ret = wpa_dbus_ctrl_iface_init(priv, WPAS_DBUS_NEW_PATH,
+ WPAS_DBUS_NEW_SERVICE,
+ obj_desc);
+ if (ret < 0)
+ free_dbus_object_desc(obj_desc);
+ else
+ priv->dbus_new_initialized = 1;
+
+ return ret;
+}
+
+
+/**
+ * wpas_dbus_ctrl_iface_deinit - Deinitialize dbus ctrl interface for
+ * wpa_supplicant
+ * @iface: Pointer to dbus private data from wpas_dbus_init()
+ *
+ * Deinitialize the dbus control interface that was initialized with
+ * wpas_dbus_ctrl_iface_init().
+ */
+void wpas_dbus_ctrl_iface_deinit(struct wpas_dbus_priv *iface)
+{
+ if (!iface->dbus_new_initialized)
+ return;
+ wpa_printf(MSG_DEBUG, "dbus: Unregister D-Bus object '%s'",
+ WPAS_DBUS_NEW_PATH);
+ dbus_connection_unregister_object_path(iface->con,
+ WPAS_DBUS_NEW_PATH);
+}
+
+
+static void wpa_dbus_free(void *ptr)
+{
+ os_free(ptr);
+}
+
+
+static const struct wpa_dbus_property_desc wpas_dbus_network_properties[] = {
+ { "Properties", WPAS_DBUS_NEW_IFACE_NETWORK, "a{sv}",
+ (WPADBusPropertyAccessor) wpas_dbus_getter_network_properties,
+ (WPADBusPropertyAccessor) wpas_dbus_setter_network_properties,
+ RW
+ },
+ { "Enabled", WPAS_DBUS_NEW_IFACE_NETWORK, "b",
+ (WPADBusPropertyAccessor) wpas_dbus_getter_enabled,
+ (WPADBusPropertyAccessor) wpas_dbus_setter_enabled,
+ RW
+ },
+ { NULL, NULL, NULL, NULL, NULL, 0 }
+};
+
+
+static const struct wpa_dbus_signal_desc wpas_dbus_network_signals[] = {
+ { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_NETWORK,
+ {
+ { "properties", "a{sv}", ARG_OUT },
+ END_ARGS
+ }
+ },
+ { NULL, NULL, { END_ARGS } }
+};
+
+
+/**
+ * wpas_dbus_register_network - Register a configured network with dbus
+ * @wpa_s: wpa_supplicant interface structure
+ * @ssid: network configuration data
+ * Returns: 0 on success, -1 on failure
+ *
+ * Registers network representing object with dbus
+ */
+int wpas_dbus_register_network(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid)
+{
+ struct wpas_dbus_priv *ctrl_iface;
+ struct wpa_dbus_object_desc *obj_desc;
+ struct network_handler_args *arg;
+ char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
+
+ /* Do nothing if the control interface is not turned on */
+ if (wpa_s == NULL || wpa_s->global == NULL)
+ return 0;
+ ctrl_iface = wpa_s->global->dbus;
+ if (ctrl_iface == NULL)
+ return 0;
+
+ os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
+ "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
+ wpa_s->dbus_new_path, ssid->id);
+
+ wpa_printf(MSG_DEBUG, "dbus: Register network object '%s'",
+ net_obj_path);
+ obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
+ if (!obj_desc) {
+ wpa_printf(MSG_ERROR, "Not enough memory "
+ "to create object description");
+ goto err;
+ }
+
+ /* allocate memory for handlers arguments */
+ arg = os_zalloc(sizeof(struct network_handler_args));
+ if (!arg) {
+ wpa_printf(MSG_ERROR, "Not enough memory "
+ "to create arguments for method");
+ goto err;
+ }
+
+ arg->wpa_s = wpa_s;
+ arg->ssid = ssid;
+
+ wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
+ wpas_dbus_network_properties,
+ wpas_dbus_network_signals);
+
+ if (wpa_dbus_register_object_per_iface(ctrl_iface, net_obj_path,
+ wpa_s->ifname, obj_desc))
+ goto err;
+
+ wpas_dbus_signal_network_added(wpa_s, ssid->id);
+
+ return 0;
+
+err:
+ free_dbus_object_desc(obj_desc);
+ return -1;
+}
+
+
+/**
+ * wpas_dbus_unregister_network - Unregister a configured network from dbus
+ * @wpa_s: wpa_supplicant interface structure
+ * @nid: network id
+ * Returns: 0 on success, -1 on failure
+ *
+ * Unregisters network representing object from dbus
+ */
+int wpas_dbus_unregister_network(struct wpa_supplicant *wpa_s, int nid)
+{
+ struct wpas_dbus_priv *ctrl_iface;
+ char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
+ int ret;
+
+ /* Do nothing if the control interface is not turned on */
+ if (wpa_s == NULL || wpa_s->global == NULL ||
+ wpa_s->dbus_new_path == NULL)
+ return 0;
+ ctrl_iface = wpa_s->global->dbus;
+ if (ctrl_iface == NULL)
+ return 0;
+
+ os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
+ "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
+ wpa_s->dbus_new_path, nid);
+
+ wpa_printf(MSG_DEBUG, "dbus: Unregister network object '%s'",
+ net_obj_path);
+ ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, net_obj_path);
+
+ if (!ret)
+ wpas_dbus_signal_network_removed(wpa_s, nid);
+
+ return ret;
+}
+
+
+static const struct wpa_dbus_property_desc wpas_dbus_bss_properties[] = {
+ { "SSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
+ (WPADBusPropertyAccessor) wpas_dbus_getter_bss_ssid,
+ NULL,
+ R
+ },
+ { "BSSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
+ (WPADBusPropertyAccessor) wpas_dbus_getter_bss_bssid,
+ NULL,
+ R
+ },
+ { "Privacy", WPAS_DBUS_NEW_IFACE_BSS, "b",
+ (WPADBusPropertyAccessor) wpas_dbus_getter_bss_privacy,
+ NULL,
+ R
+ },
+ { "Mode", WPAS_DBUS_NEW_IFACE_BSS, "s",
+ (WPADBusPropertyAccessor) wpas_dbus_getter_bss_mode,
+ NULL,
+ R
+ },
+ { "Signal", WPAS_DBUS_NEW_IFACE_BSS, "n",
+ (WPADBusPropertyAccessor) wpas_dbus_getter_bss_signal,
+ NULL,
+ R
+ },
+ { "Frequency", WPAS_DBUS_NEW_IFACE_BSS, "q",
+ (WPADBusPropertyAccessor) wpas_dbus_getter_bss_frequency,
+ NULL,
+ R
+ },
+ { "Rates", WPAS_DBUS_NEW_IFACE_BSS, "au",
+ (WPADBusPropertyAccessor) wpas_dbus_getter_bss_rates,
+ NULL,
+ R
+ },
+ { "WPA", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
+ (WPADBusPropertyAccessor) wpas_dbus_getter_bss_wpa,
+ NULL,
+ R
+ },
+ { "RSN", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
+ (WPADBusPropertyAccessor) wpas_dbus_getter_bss_rsn,
+ NULL,
+ R
+ },
+ { "IEs", WPAS_DBUS_NEW_IFACE_BSS, "ay",
+ (WPADBusPropertyAccessor) wpas_dbus_getter_bss_ies,
+ NULL,
+ R
+ },
+ { NULL, NULL, NULL, NULL, NULL, 0 }
+};
+
+
+static const struct wpa_dbus_signal_desc wpas_dbus_bss_signals[] = {
+ { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_BSS,
+ {
+ { "properties", "a{sv}", ARG_OUT },
+ END_ARGS
+ }
+ },
+ { NULL, NULL, { END_ARGS } }
+};
+
+
+/**
+ * wpas_dbus_unregister_bss - Unregister a scanned BSS from dbus
+ * @wpa_s: wpa_supplicant interface structure
+ * @bssid: scanned network bssid
+ * @id: unique BSS identifier
+ * Returns: 0 on success, -1 on failure
+ *
+ * Unregisters BSS representing object from dbus
+ */
+int wpas_dbus_unregister_bss(struct wpa_supplicant *wpa_s,
+ u8 bssid[ETH_ALEN], unsigned int id)
+{
+ struct wpas_dbus_priv *ctrl_iface;
+ char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
+
+ /* Do nothing if the control interface is not turned on */
+ if (wpa_s == NULL || wpa_s->global == NULL)
+ return 0;
+ ctrl_iface = wpa_s->global->dbus;
+ if (ctrl_iface == NULL)
+ return 0;
+
+ os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
+ "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
+ wpa_s->dbus_new_path, id);
+
+ wpa_printf(MSG_DEBUG, "dbus: Unregister BSS object '%s'",
+ bss_obj_path);
+ if (wpa_dbus_unregister_object_per_iface(ctrl_iface, bss_obj_path)) {
+ wpa_printf(MSG_ERROR, "dbus: Cannot unregister BSS object %s",
+ bss_obj_path);
+ return -1;
+ }
+
+ wpas_dbus_signal_bss_removed(wpa_s, bss_obj_path);
+
+ return 0;
+}
+
+
+/**
+ * wpas_dbus_register_bss - Register a scanned BSS with dbus
+ * @wpa_s: wpa_supplicant interface structure
+ * @bssid: scanned network bssid
+ * @id: unique BSS identifier
+ * Returns: 0 on success, -1 on failure
+ *
+ * Registers BSS representing object with dbus
+ */
+int wpas_dbus_register_bss(struct wpa_supplicant *wpa_s,
+ u8 bssid[ETH_ALEN], unsigned int id)
+{
+ struct wpas_dbus_priv *ctrl_iface;
+ struct wpa_dbus_object_desc *obj_desc;
+ char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
+ struct bss_handler_args *arg;
+
+ /* Do nothing if the control interface is not turned on */
+ if (wpa_s == NULL || wpa_s->global == NULL)
+ return 0;
+ ctrl_iface = wpa_s->global->dbus;
+ if (ctrl_iface == NULL)
+ return 0;
+
+ os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
+ "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
+ wpa_s->dbus_new_path, id);
+
+ obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
+ if (!obj_desc) {
+ wpa_printf(MSG_ERROR, "Not enough memory "
+ "to create object description");
+ goto err;
+ }
+
+ arg = os_zalloc(sizeof(struct bss_handler_args));
+ if (!arg) {
+ wpa_printf(MSG_ERROR, "Not enough memory "
+ "to create arguments for handler");
+ goto err;
+ }
+ arg->wpa_s = wpa_s;
+ arg->id = id;
+
+ wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
+ wpas_dbus_bss_properties,
+ wpas_dbus_bss_signals);
+
+ wpa_printf(MSG_DEBUG, "dbus: Register BSS object '%s'",
+ bss_obj_path);
+ if (wpa_dbus_register_object_per_iface(ctrl_iface, bss_obj_path,
+ wpa_s->ifname, obj_desc)) {
+ wpa_printf(MSG_ERROR,
+ "Cannot register BSSID dbus object %s.",
+ bss_obj_path);
+ goto err;
+ }
+
+ wpas_dbus_signal_bss_added(wpa_s, bss_obj_path);
+
+ return 0;
+
+err:
+ free_dbus_object_desc(obj_desc);
+ return -1;
+}
+
+
+static const struct wpa_dbus_method_desc wpas_dbus_interface_methods[] = {
+ { "Scan", WPAS_DBUS_NEW_IFACE_INTERFACE,
+ (WPADBusMethodHandler) &wpas_dbus_handler_scan,
+ {
+ { "args", "a{sv}", ARG_IN },
+ END_ARGS
+ }
+ },
+ { "Disconnect", WPAS_DBUS_NEW_IFACE_INTERFACE,
+ (WPADBusMethodHandler) &wpas_dbus_handler_disconnect,
+ {
+ END_ARGS
+ }
+ },
+ { "AddNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
+ (WPADBusMethodHandler) &wpas_dbus_handler_add_network,
+ {
+ { "args", "a{sv}", ARG_IN },
+ { "path", "o", ARG_OUT },
+ END_ARGS
+ }
+ },
+ { "RemoveNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
+ (WPADBusMethodHandler) &wpas_dbus_handler_remove_network,
+ {
+ { "path", "o", ARG_IN },
+ END_ARGS
+ }
+ },
+ { "SelectNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
+ (WPADBusMethodHandler) &wpas_dbus_handler_select_network,
+ {
+ { "path", "o", ARG_IN },
+ END_ARGS
+ }
+ },
+ { "AddBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
+ (WPADBusMethodHandler) &wpas_dbus_handler_add_blob,
+ {
+ { "name", "s", ARG_IN },
+ { "data", "ay", ARG_IN },
+ END_ARGS
+ }
+ },
+ { "GetBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
+ (WPADBusMethodHandler) &wpas_dbus_handler_get_blob,
+ {
+ { "name", "s", ARG_IN },
+ { "data", "ay", ARG_OUT },
+ END_ARGS
+ }
+ },
+ { "RemoveBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
+ (WPADBusMethodHandler) &wpas_dbus_handler_remove_blob,
+ {
+ { "name", "s", ARG_IN },
+ END_ARGS
+ }
+ },
+#ifdef CONFIG_WPS
+ { "Start", WPAS_DBUS_NEW_IFACE_WPS,
+ (WPADBusMethodHandler) &wpas_dbus_handler_wps_start,
+ {
+ { "args", "a{sv}", ARG_IN },
+ { "output", "a{sv}", ARG_OUT },
+ END_ARGS
+ }
+ },
+#endif /* CONFIG_WPS */
+ { NULL, NULL, NULL, { END_ARGS } }
+};
+
+static const struct wpa_dbus_property_desc wpas_dbus_interface_properties[] = {
+ { "Capabilities", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{sv}",
+ (WPADBusPropertyAccessor) wpas_dbus_getter_capabilities,
+ NULL, R
+ },
+ { "State", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
+ (WPADBusPropertyAccessor) wpas_dbus_getter_state,
+ NULL, R
+ },
+ { "Scanning", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
+ (WPADBusPropertyAccessor) wpas_dbus_getter_scanning,
+ NULL, R
+ },
+ { "ApScan", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
+ (WPADBusPropertyAccessor) wpas_dbus_getter_ap_scan,
+ (WPADBusPropertyAccessor) wpas_dbus_setter_ap_scan,
+ RW
+ },
+ { "Ifname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
+ (WPADBusPropertyAccessor) wpas_dbus_getter_ifname,
+ NULL, R
+ },
+ { "Driver", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
+ (WPADBusPropertyAccessor) wpas_dbus_getter_driver,
+ NULL, R
+ },
+ { "BridgeIfname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
+ (WPADBusPropertyAccessor) wpas_dbus_getter_bridge_ifname,
+ NULL, R
+ },
+ { "CurrentBSS", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
+ (WPADBusPropertyAccessor) wpas_dbus_getter_current_bss,
+ NULL, R
+ },
+ { "CurrentNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
+ (WPADBusPropertyAccessor) wpas_dbus_getter_current_network,
+ NULL, R
+ },
+ { "Blobs", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{say}",
+ (WPADBusPropertyAccessor) wpas_dbus_getter_blobs,
+ NULL, R
+ },
+ { "BSSs", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
+ (WPADBusPropertyAccessor) wpas_dbus_getter_bsss,
+ NULL, R
+ },
+ { "Networks", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
+ (WPADBusPropertyAccessor) wpas_dbus_getter_networks,
+ NULL, R
+ },
+#ifdef CONFIG_WPS
+ { "ProcessCredentials", WPAS_DBUS_NEW_IFACE_WPS, "b",
+ (WPADBusPropertyAccessor) wpas_dbus_getter_process_credentials,
+ (WPADBusPropertyAccessor) wpas_dbus_setter_process_credentials,
+ RW
+ },
+#endif /* CONFIG_WPS */
+ { NULL, NULL, NULL, NULL, NULL, 0 }
+};
+
+static const struct wpa_dbus_signal_desc wpas_dbus_interface_signals[] = {
+ { "ScanDone", WPAS_DBUS_NEW_IFACE_INTERFACE,
+ {
+ { "success", "b", ARG_OUT },
+ END_ARGS
+ }
+ },
+ { "BSSAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
+ {
+ { "path", "o", ARG_OUT },
+ { "properties", "a{sv}", ARG_OUT },
+ END_ARGS
+ }
+ },
+ { "BSSRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
+ {
+ { "path", "o", ARG_OUT },
+ END_ARGS
+ }
+ },
+ { "BlobAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
+ {
+ { "name", "s", ARG_OUT },
+ END_ARGS
+ }
+ },
+ { "BlobRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
+ {
+ { "name", "s", ARG_OUT },
+ END_ARGS
+ }
+ },
+ { "NetworkAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
+ {
+ { "path", "o", ARG_OUT },
+ { "properties", "a{sv}", ARG_OUT },
+ END_ARGS
+ }
+ },
+ { "NetworkRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
+ {
+ { "path", "o", ARG_OUT },
+ END_ARGS
+ }
+ },
+ { "NetworkSelected", WPAS_DBUS_NEW_IFACE_INTERFACE,
+ {
+ { "path", "o", ARG_OUT },
+ END_ARGS
+ }
+ },
+ { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_INTERFACE,
+ {
+ { "properties", "a{sv}", ARG_OUT },
+ END_ARGS
+ }
+ },
+#ifdef CONFIG_WPS
+ { "Event", WPAS_DBUS_NEW_IFACE_WPS,
+ {
+ { "name", "s", ARG_OUT },
+ { "args", "a{sv}", ARG_OUT },
+ END_ARGS
+ }
+ },
+ { "Credentials", WPAS_DBUS_NEW_IFACE_WPS,
+ {
+ { "credentials", "a{sv}", ARG_OUT },
+ END_ARGS
+ }
+ },
+ { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_WPS,
+ {
+ { "properties", "a{sv}", ARG_OUT },
+ END_ARGS
+ }
+ },
+#endif /* CONFIG_WPS */
+ { NULL, NULL, { END_ARGS } }
+};
+
+
+int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s)
+{
+
+ struct wpa_dbus_object_desc *obj_desc = NULL;
+ struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus;
+ int next;
+
+ /* Do nothing if the control interface is not turned on */
+ if (ctrl_iface == NULL)
+ return 0;
+
+ /* Create and set the interface's object path */
+ wpa_s->dbus_new_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
+ if (wpa_s->dbus_new_path == NULL)
+ return -1;
+ next = ctrl_iface->next_objid++;
+ os_snprintf(wpa_s->dbus_new_path, WPAS_DBUS_OBJECT_PATH_MAX,
+ WPAS_DBUS_NEW_PATH_INTERFACES "/%u",
+ next);
+
+ obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
+ if (!obj_desc) {
+ wpa_printf(MSG_ERROR, "Not enough memory "
+ "to create object description");
+ goto err;
+ }
+
+ wpas_dbus_register(obj_desc, wpa_s, NULL, wpas_dbus_interface_methods,
+ wpas_dbus_interface_properties,
+ wpas_dbus_interface_signals);
+
+ wpa_printf(MSG_DEBUG, "dbus: Register interface object '%s'",
+ wpa_s->dbus_new_path);
+ if (wpa_dbus_register_object_per_iface(ctrl_iface,
+ wpa_s->dbus_new_path,
+ wpa_s->ifname, obj_desc))
+ goto err;
+
+ wpas_dbus_signal_interface_added(wpa_s);
+
+ return 0;
+
+err:
+ os_free(wpa_s->dbus_new_path);
+ wpa_s->dbus_new_path = NULL;
+ free_dbus_object_desc(obj_desc);
+ return -1;
+}
+
+
+int wpas_dbus_unregister_interface(struct wpa_supplicant *wpa_s)
+{
+ struct wpas_dbus_priv *ctrl_iface;
+
+ /* Do nothing if the control interface is not turned on */
+ if (wpa_s == NULL || wpa_s->global == NULL)
+ return 0;
+ ctrl_iface = wpa_s->global->dbus;
+ if (ctrl_iface == NULL)
+ return 0;
+
+ wpa_printf(MSG_DEBUG, "dbus: Unregister interface object '%s'",
+ wpa_s->dbus_new_path);
+ if (wpa_dbus_unregister_object_per_iface(ctrl_iface,
+ wpa_s->dbus_new_path))
+ return -1;
+
+ wpas_dbus_signal_interface_removed(wpa_s);
+
+ os_free(wpa_s->dbus_new_path);
+ wpa_s->dbus_new_path = NULL;
+
+ return 0;
+}
diff --git a/contrib/wpa/wpa_supplicant/dbus/dbus_new.h b/contrib/wpa/wpa_supplicant/dbus/dbus_new.h
new file mode 100644
index 0000000..80ea98c
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/dbus/dbus_new.h
@@ -0,0 +1,234 @@
+/*
+ * WPA Supplicant / dbus-based control interface
+ * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
+ * Copyright (c) 2009-2010, Witold Sowa <witold.sowa@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef CTRL_IFACE_DBUS_NEW_H
+#define CTRL_IFACE_DBUS_NEW_H
+
+struct wpa_global;
+struct wpa_supplicant;
+struct wpa_ssid;
+struct wps_event_m2d;
+struct wps_event_fail;
+struct wps_credential;
+enum wpa_states;
+
+enum wpas_dbus_prop {
+ WPAS_DBUS_PROP_AP_SCAN,
+ WPAS_DBUS_PROP_SCANNING,
+ WPAS_DBUS_PROP_STATE,
+ WPAS_DBUS_PROP_CURRENT_BSS,
+ WPAS_DBUS_PROP_CURRENT_NETWORK,
+};
+
+enum wpas_dbus_bss_prop {
+ WPAS_DBUS_BSS_PROP_SIGNAL,
+ WPAS_DBUS_BSS_PROP_FREQ,
+ WPAS_DBUS_BSS_PROP_MODE,
+ WPAS_DBUS_BSS_PROP_PRIVACY,
+ WPAS_DBUS_BSS_PROP_RATES,
+ WPAS_DBUS_BSS_PROP_WPA,
+ WPAS_DBUS_BSS_PROP_RSN,
+ WPAS_DBUS_BSS_PROP_IES,
+};
+
+#define WPAS_DBUS_OBJECT_PATH_MAX 150
+
+#define WPAS_DBUS_NEW_SERVICE "fi.w1.wpa_supplicant1"
+#define WPAS_DBUS_NEW_PATH "/fi/w1/wpa_supplicant1"
+#define WPAS_DBUS_NEW_INTERFACE "fi.w1.wpa_supplicant1"
+
+#define WPAS_DBUS_NEW_PATH_INTERFACES WPAS_DBUS_NEW_PATH "/Interfaces"
+#define WPAS_DBUS_NEW_IFACE_INTERFACE WPAS_DBUS_NEW_INTERFACE ".Interface"
+#define WPAS_DBUS_NEW_IFACE_WPS WPAS_DBUS_NEW_IFACE_INTERFACE ".WPS"
+
+#define WPAS_DBUS_NEW_NETWORKS_PART "Networks"
+#define WPAS_DBUS_NEW_IFACE_NETWORK WPAS_DBUS_NEW_INTERFACE ".Network"
+
+#define WPAS_DBUS_NEW_BSSIDS_PART "BSSs"
+#define WPAS_DBUS_NEW_IFACE_BSS WPAS_DBUS_NEW_INTERFACE ".BSS"
+
+
+/* Errors */
+#define WPAS_DBUS_ERROR_UNKNOWN_ERROR \
+ WPAS_DBUS_NEW_INTERFACE ".UnknownError"
+#define WPAS_DBUS_ERROR_INVALID_ARGS \
+ WPAS_DBUS_NEW_INTERFACE ".InvalidArgs"
+
+#define WPAS_DBUS_ERROR_IFACE_EXISTS \
+ WPAS_DBUS_NEW_INTERFACE ".InterfaceExists"
+#define WPAS_DBUS_ERROR_IFACE_UNKNOWN \
+ WPAS_DBUS_NEW_INTERFACE ".InterfaceUnknown"
+
+#define WPAS_DBUS_ERROR_NOT_CONNECTED \
+ WPAS_DBUS_NEW_INTERFACE ".NotConnected"
+#define WPAS_DBUS_ERROR_NETWORK_UNKNOWN \
+ WPAS_DBUS_NEW_INTERFACE ".NetworkUnknown"
+
+#define WPAS_DBUS_ERROR_BLOB_EXISTS \
+ WPAS_DBUS_NEW_INTERFACE ".BlobExists"
+#define WPAS_DBUS_ERROR_BLOB_UNKNOWN \
+ WPAS_DBUS_NEW_INTERFACE ".BlobUnknown"
+
+
+#ifdef CONFIG_CTRL_IFACE_DBUS_NEW
+
+int wpas_dbus_ctrl_iface_init(struct wpas_dbus_priv *priv);
+void wpas_dbus_ctrl_iface_deinit(struct wpas_dbus_priv *iface);
+
+int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s);
+int wpas_dbus_unregister_interface(struct wpa_supplicant *wpa_s);
+void wpas_dbus_signal_prop_changed(struct wpa_supplicant *wpa_s,
+ enum wpas_dbus_prop property);
+void wpas_dbus_bss_signal_prop_changed(struct wpa_supplicant *wpa_s,
+ enum wpas_dbus_bss_prop property,
+ unsigned int id);
+void wpas_dbus_signal_network_enabled_changed(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid);
+void wpas_dbus_signal_network_selected(struct wpa_supplicant *wpa_s, int id);
+void wpas_dbus_signal_scan_done(struct wpa_supplicant *wpa_s, int success);
+void wpas_dbus_signal_wps_cred(struct wpa_supplicant *wpa_s,
+ const struct wps_credential *cred);
+void wpas_dbus_signal_wps_event_m2d(struct wpa_supplicant *wpa_s,
+ struct wps_event_m2d *m2d);
+void wpas_dbus_signal_wps_event_fail(struct wpa_supplicant *wpa_s,
+ struct wps_event_fail *fail);
+void wpas_dbus_signal_wps_event_success(struct wpa_supplicant *wpa_s);
+int wpas_dbus_register_network(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid);
+int wpas_dbus_unregister_network(struct wpa_supplicant *wpa_s, int nid);
+int wpas_dbus_unregister_bss(struct wpa_supplicant *wpa_s,
+ u8 bssid[ETH_ALEN], unsigned int id);
+int wpas_dbus_register_bss(struct wpa_supplicant *wpa_s,
+ u8 bssid[ETH_ALEN], unsigned int id);
+void wpas_dbus_signal_blob_added(struct wpa_supplicant *wpa_s,
+ const char *name);
+void wpas_dbus_signal_blob_removed(struct wpa_supplicant *wpa_s,
+ const char *name);
+void wpas_dbus_signal_debug_level_changed(struct wpa_global *global);
+void wpas_dbus_signal_debug_timestamp_changed(struct wpa_global *global);
+void wpas_dbus_signal_debug_show_keys_changed(struct wpa_global *global);
+
+#else /* CONFIG_CTRL_IFACE_DBUS_NEW */
+
+static inline int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s)
+{
+ return 0;
+}
+
+static inline int wpas_dbus_unregister_interface(struct wpa_supplicant *wpa_s)
+{
+ return 0;
+}
+
+#define wpas_dbus_signal_state_changed(w, n, o) do { } while (0)
+
+static inline void wpas_dbus_signal_prop_changed(struct wpa_supplicant *wpa_s,
+ enum wpas_dbus_prop property)
+{
+}
+
+static inline void wpas_dbus_bss_signal_prop_changed(
+ struct wpa_supplicant *wpa_s, enum wpas_dbus_bss_prop property,
+ unsigned int id)
+{
+}
+
+static inline void wpas_dbus_signal_network_enabled_changed(
+ struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
+{
+}
+
+static inline void wpas_dbus_signal_network_selected(
+ struct wpa_supplicant *wpa_s, int id)
+{
+}
+
+static inline void wpas_dbus_signal_scan_done(struct wpa_supplicant *wpa_s,
+ int success)
+{
+}
+
+static inline void wpas_dbus_signal_wps_cred(struct wpa_supplicant *wpa_s,
+ const struct wps_credential *cred)
+{
+}
+
+static inline void wpas_dbus_signal_wps_event_m2d(struct wpa_supplicant *wpa_s,
+ struct wps_event_m2d *m2d)
+{
+}
+
+static inline void wpas_dbus_signal_wps_event_fail(
+ struct wpa_supplicant *wpa_s, struct wps_event_fail *fail)
+{
+}
+
+static inline void wpas_dbus_signal_wps_event_success(
+ struct wpa_supplicant *wpa_s)
+{
+}
+
+static inline int wpas_dbus_register_network(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid)
+{
+ return 0;
+}
+
+static inline int wpas_dbus_unregister_network(struct wpa_supplicant *wpa_s,
+ int nid)
+{
+ return 0;
+}
+
+static inline int wpas_dbus_unregister_bss(struct wpa_supplicant *wpa_s,
+ u8 bssid[ETH_ALEN], unsigned int id)
+{
+ return 0;
+}
+
+static inline int wpas_dbus_register_bss(struct wpa_supplicant *wpa_s,
+ u8 bssid[ETH_ALEN], unsigned int id)
+{
+ return 0;
+}
+
+static inline void wpas_dbus_signal_blob_added(struct wpa_supplicant *wpa_s,
+ const char *name)
+{
+}
+
+static inline void wpas_dbus_signal_blob_removed(struct wpa_supplicant *wpa_s,
+ const char *name)
+{
+}
+
+static inline void wpas_dbus_signal_debug_level_changed(
+ struct wpa_global *global)
+{
+}
+
+static inline void wpas_dbus_signal_debug_timestamp_changed(
+ struct wpa_global *global)
+{
+}
+
+static inline void wpas_dbus_signal_debug_show_keys_changed(
+ struct wpa_global *global)
+{
+}
+
+#endif /* CONFIG_CTRL_IFACE_DBUS_NEW */
+
+#endif /* CTRL_IFACE_DBUS_H_NEW */
diff --git a/contrib/wpa/wpa_supplicant/dbus/dbus_new_handlers.c b/contrib/wpa/wpa_supplicant/dbus/dbus_new_handlers.c
new file mode 100644
index 0000000..e2b5e50
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/dbus/dbus_new_handlers.c
@@ -0,0 +1,2957 @@
+/*
+ * WPA Supplicant / dbus-based control interface
+ * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
+ * Copyright (c) 2009-2010, Witold Sowa <witold.sowa@gmail.com>
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "common/ieee802_11_defs.h"
+#include "eap_peer/eap_methods.h"
+#include "eapol_supp/eapol_supp_sm.h"
+#include "rsn_supp/wpa.h"
+#include "../config.h"
+#include "../wpa_supplicant_i.h"
+#include "../driver_i.h"
+#include "../notify.h"
+#include "../wpas_glue.h"
+#include "../bss.h"
+#include "../scan.h"
+#include "dbus_new_helpers.h"
+#include "dbus_new.h"
+#include "dbus_new_handlers.h"
+#include "dbus_dict_helpers.h"
+
+extern int wpa_debug_level;
+extern int wpa_debug_show_keys;
+extern int wpa_debug_timestamp;
+
+static const char *debug_strings[] = {
+ "msgdump", "debug", "info", "warning", "error", NULL
+};
+
+
+/**
+ * wpas_dbus_new_decompose_object_path - Decompose an interface object path into parts
+ * @path: The dbus object path
+ * @network: (out) the configured network this object path refers to, if any
+ * @bssid: (out) the scanned bssid this object path refers to, if any
+ * Returns: The object path of the network interface this path refers to
+ *
+ * For a given object path, decomposes the object path into object id, network,
+ * and BSSID parts, if those parts exist.
+ */
+static char * wpas_dbus_new_decompose_object_path(const char *path,
+ char **network,
+ char **bssid)
+{
+ const unsigned int dev_path_prefix_len =
+ strlen(WPAS_DBUS_NEW_PATH_INTERFACES "/");
+ char *obj_path_only;
+ char *next_sep;
+
+ /* Be a bit paranoid about path */
+ if (!path || os_strncmp(path, WPAS_DBUS_NEW_PATH_INTERFACES "/",
+ dev_path_prefix_len))
+ return NULL;
+
+ /* Ensure there's something at the end of the path */
+ if ((path + dev_path_prefix_len)[0] == '\0')
+ return NULL;
+
+ obj_path_only = os_strdup(path);
+ if (obj_path_only == NULL)
+ return NULL;
+
+ next_sep = os_strchr(obj_path_only + dev_path_prefix_len, '/');
+ if (next_sep != NULL) {
+ const char *net_part = os_strstr(
+ next_sep, WPAS_DBUS_NEW_NETWORKS_PART "/");
+ const char *bssid_part = os_strstr(
+ next_sep, WPAS_DBUS_NEW_BSSIDS_PART "/");
+
+ if (network && net_part) {
+ /* Deal with a request for a configured network */
+ const char *net_name = net_part +
+ os_strlen(WPAS_DBUS_NEW_NETWORKS_PART "/");
+ *network = NULL;
+ if (os_strlen(net_name))
+ *network = os_strdup(net_name);
+ } else if (bssid && bssid_part) {
+ /* Deal with a request for a scanned BSSID */
+ const char *bssid_name = bssid_part +
+ os_strlen(WPAS_DBUS_NEW_BSSIDS_PART "/");
+ if (strlen(bssid_name))
+ *bssid = os_strdup(bssid_name);
+ else
+ *bssid = NULL;
+ }
+
+ /* Cut off interface object path before "/" */
+ *next_sep = '\0';
+ }
+
+ return obj_path_only;
+}
+
+
+/**
+ * wpas_dbus_error_unknown_error - Return a new InvalidArgs error message
+ * @message: Pointer to incoming dbus message this error refers to
+ * @arg: Optional string appended to error message
+ * Returns: a dbus error message
+ *
+ * Convenience function to create and return an UnknownError
+ */
+DBusMessage * wpas_dbus_error_unknown_error(DBusMessage *message,
+ const char *arg)
+{
+ return dbus_message_new_error(message, WPAS_DBUS_ERROR_UNKNOWN_ERROR,
+ arg);
+}
+
+
+/**
+ * wpas_dbus_error_iface_unknown - Return a new invalid interface error message
+ * @message: Pointer to incoming dbus message this error refers to
+ * Returns: A dbus error message
+ *
+ * Convenience function to create and return an invalid interface error
+ */
+static DBusMessage * wpas_dbus_error_iface_unknown(DBusMessage *message)
+{
+ return dbus_message_new_error(message, WPAS_DBUS_ERROR_IFACE_UNKNOWN,
+ "wpa_supplicant knows nothing about "
+ "this interface.");
+}
+
+
+/**
+ * wpas_dbus_error_network_unknown - Return a new NetworkUnknown error message
+ * @message: Pointer to incoming dbus message this error refers to
+ * Returns: a dbus error message
+ *
+ * Convenience function to create and return an invalid network error
+ */
+static DBusMessage * wpas_dbus_error_network_unknown(DBusMessage *message)
+{
+ return dbus_message_new_error(message, WPAS_DBUS_ERROR_NETWORK_UNKNOWN,
+ "There is no such a network in this "
+ "interface.");
+}
+
+
+/**
+ * wpas_dbus_error_invalid_args - Return a new InvalidArgs error message
+ * @message: Pointer to incoming dbus message this error refers to
+ * Returns: a dbus error message
+ *
+ * Convenience function to create and return an invalid options error
+ */
+DBusMessage * wpas_dbus_error_invalid_args(DBusMessage *message,
+ const char *arg)
+{
+ DBusMessage *reply;
+
+ reply = dbus_message_new_error(message, WPAS_DBUS_ERROR_INVALID_ARGS,
+ "Did not receive correct message "
+ "arguments.");
+ if (arg != NULL)
+ dbus_message_append_args(reply, DBUS_TYPE_STRING, &arg,
+ DBUS_TYPE_INVALID);
+
+ return reply;
+}
+
+
+static const char *dont_quote[] = {
+ "key_mgmt", "proto", "pairwise", "auth_alg", "group", "eap",
+ "opensc_engine_path", "pkcs11_engine_path", "pkcs11_module_path",
+ "bssid", NULL
+};
+
+static dbus_bool_t should_quote_opt(const char *key)
+{
+ int i = 0;
+ while (dont_quote[i] != NULL) {
+ if (os_strcmp(key, dont_quote[i]) == 0)
+ return FALSE;
+ i++;
+ }
+ return TRUE;
+}
+
+/**
+ * get_iface_by_dbus_path - Get a new network interface
+ * @global: Pointer to global data from wpa_supplicant_init()
+ * @path: Pointer to a dbus object path representing an interface
+ * Returns: Pointer to the interface or %NULL if not found
+ */
+static struct wpa_supplicant * get_iface_by_dbus_path(
+ struct wpa_global *global, const char *path)
+{
+ struct wpa_supplicant *wpa_s;
+
+ for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
+ if (os_strcmp(wpa_s->dbus_new_path, path) == 0)
+ return wpa_s;
+ }
+ return NULL;
+}
+
+
+/**
+ * set_network_properties - Set properties of a configured network
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * @ssid: wpa_ssid structure for a configured network
+ * @iter: DBus message iterator containing dictionary of network
+ * properties to set.
+ * Returns: NULL when succeed or DBus error on failure
+ *
+ * Sets network configuration with parameters given id DBus dictionary
+ */
+static DBusMessage * set_network_properties(DBusMessage *message,
+ struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid,
+ DBusMessageIter *iter)
+{
+
+ struct wpa_dbus_dict_entry entry = { .type = DBUS_TYPE_STRING };
+ DBusMessage *reply = NULL;
+ DBusMessageIter iter_dict;
+
+ if (!wpa_dbus_dict_open_read(iter, &iter_dict))
+ return wpas_dbus_error_invalid_args(message, NULL);
+
+ while (wpa_dbus_dict_has_dict_entry(&iter_dict)) {
+ char *value = NULL;
+ size_t size = 50;
+ int ret;
+ if (!wpa_dbus_dict_get_entry(&iter_dict, &entry)) {
+ reply = wpas_dbus_error_invalid_args(message, NULL);
+ break;
+ }
+ if (entry.type == DBUS_TYPE_ARRAY &&
+ entry.array_type == DBUS_TYPE_BYTE) {
+ if (entry.array_len <= 0)
+ goto error;
+
+ size = entry.array_len * 2 + 1;
+ value = os_zalloc(size);
+ if (value == NULL)
+ goto error;
+
+ ret = wpa_snprintf_hex(value, size,
+ (u8 *) entry.bytearray_value,
+ entry.array_len);
+ if (ret <= 0)
+ goto error;
+ } else if (entry.type == DBUS_TYPE_STRING) {
+ if (should_quote_opt(entry.key)) {
+ size = os_strlen(entry.str_value);
+ if (size <= 0)
+ goto error;
+
+ size += 3;
+ value = os_zalloc(size);
+ if (value == NULL)
+ goto error;
+
+ ret = os_snprintf(value, size, "\"%s\"",
+ entry.str_value);
+ if (ret < 0 || (size_t) ret != (size - 1))
+ goto error;
+ } else {
+ value = os_strdup(entry.str_value);
+ if (value == NULL)
+ goto error;
+ }
+ } else if (entry.type == DBUS_TYPE_UINT32) {
+ value = os_zalloc(size);
+ if (value == NULL)
+ goto error;
+
+ ret = os_snprintf(value, size, "%u",
+ entry.uint32_value);
+ if (ret <= 0)
+ goto error;
+ } else if (entry.type == DBUS_TYPE_INT32) {
+ value = os_zalloc(size);
+ if (value == NULL)
+ goto error;
+
+ ret = os_snprintf(value, size, "%d",
+ entry.int32_value);
+ if (ret <= 0)
+ goto error;
+ } else
+ goto error;
+
+ if (wpa_config_set(ssid, entry.key, value, 0) < 0)
+ goto error;
+
+ if ((os_strcmp(entry.key, "psk") == 0 &&
+ value[0] == '"' && ssid->ssid_len) ||
+ (strcmp(entry.key, "ssid") == 0 && ssid->passphrase))
+ wpa_config_update_psk(ssid);
+ else if (os_strcmp(entry.key, "priority") == 0)
+ wpa_config_update_prio_list(wpa_s->conf);
+
+ os_free(value);
+ wpa_dbus_dict_entry_clear(&entry);
+ continue;
+
+ error:
+ os_free(value);
+ reply = wpas_dbus_error_invalid_args(message, entry.key);
+ wpa_dbus_dict_entry_clear(&entry);
+ break;
+ }
+
+ return reply;
+}
+
+
+/**
+ * wpas_dbus_simple_property_getter - Get basic type property
+ * @message: Pointer to incoming dbus message
+ * @type: DBus type of property (must be basic type)
+ * @val: pointer to place holding property value
+ * Returns: The DBus message containing response for Properties.Get call
+ * or DBus error message if error occurred.
+ *
+ * Generic getter for basic type properties. Type is required to be basic.
+ */
+DBusMessage * wpas_dbus_simple_property_getter(DBusMessage *message,
+ const int type, const void *val)
+{
+ DBusMessage *reply = NULL;
+ DBusMessageIter iter, variant_iter;
+
+ if (!dbus_type_is_basic(type)) {
+ wpa_printf(MSG_ERROR, "dbus: wpas_dbus_simple_property_getter:"
+ " given type is not basic");
+ return wpas_dbus_error_unknown_error(message, NULL);
+ }
+
+ if (message == NULL)
+ reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
+ else
+ reply = dbus_message_new_method_return(message);
+
+ if (reply != NULL) {
+ dbus_message_iter_init_append(reply, &iter);
+ if (!dbus_message_iter_open_container(
+ &iter, DBUS_TYPE_VARIANT,
+ wpa_dbus_type_as_string(type), &variant_iter) ||
+ !dbus_message_iter_append_basic(&variant_iter, type,
+ val) ||
+ !dbus_message_iter_close_container(&iter, &variant_iter)) {
+ wpa_printf(MSG_ERROR, "dbus: "
+ "wpas_dbus_simple_property_getter: out of "
+ "memory to put property value into "
+ "message");
+ dbus_message_unref(reply);
+ reply = dbus_message_new_error(message,
+ DBUS_ERROR_NO_MEMORY,
+ NULL);
+ }
+ } else {
+ wpa_printf(MSG_ERROR, "dbus: wpas_dbus_simple_property_getter:"
+ " out of memory to return property value");
+ reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+ }
+
+ return reply;
+}
+
+
+/**
+ * wpas_dbus_simple_property_setter - Set basic type property
+ * @message: Pointer to incoming dbus message
+ * @type: DBus type of property (must be basic type)
+ * @val: pointer to place where value being set will be stored
+ * Returns: NULL or DBus error message if error occurred.
+ *
+ * Generic setter for basic type properties. Type is required to be basic.
+ */
+DBusMessage * wpas_dbus_simple_property_setter(DBusMessage *message,
+ const int type, void *val)
+{
+ DBusMessageIter iter, variant_iter;
+
+ if (!dbus_type_is_basic(type)) {
+ wpa_printf(MSG_ERROR, "dbus: wpas_dbus_simple_property_setter:"
+ " given type is not basic");
+ return wpas_dbus_error_unknown_error(message, NULL);
+ }
+
+ if (!dbus_message_iter_init(message, &iter)) {
+ wpa_printf(MSG_ERROR, "dbus: wpas_dbus_simple_property_setter:"
+ " out of memory to return scanning state");
+ return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+ }
+
+ /* omit first and second argument and get value from third */
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_recurse(&iter, &variant_iter);
+
+ if (dbus_message_iter_get_arg_type(&variant_iter) != type) {
+ wpa_printf(MSG_DEBUG, "dbus: wpas_dbus_simple_property_setter:"
+ " wrong property type");
+ return wpas_dbus_error_invalid_args(message,
+ "wrong property type");
+ }
+ dbus_message_iter_get_basic(&variant_iter, val);
+
+ return NULL;
+}
+
+
+/**
+ * wpas_dbus_simple_array_property_getter - Get array type property
+ * @message: Pointer to incoming dbus message
+ * @type: DBus type of property array elements (must be basic type)
+ * @array: pointer to array of elements to put into response message
+ * @array_len: length of above array
+ * Returns: The DBus message containing response for Properties.Get call
+ * or DBus error message if error occurred.
+ *
+ * Generic getter for array type properties. Array elements type is
+ * required to be basic.
+ */
+DBusMessage * wpas_dbus_simple_array_property_getter(DBusMessage *message,
+ const int type,
+ const void *array,
+ size_t array_len)
+{
+ DBusMessage *reply = NULL;
+ DBusMessageIter iter, variant_iter, array_iter;
+ char type_str[] = "a?"; /* ? will be replaced with subtype letter; */
+ const char *sub_type_str;
+ size_t element_size, i;
+
+ if (!dbus_type_is_basic(type)) {
+ wpa_printf(MSG_ERROR, "dbus: "
+ "wpas_dbus_simple_array_property_getter: given "
+ "type is not basic");
+ return wpas_dbus_error_unknown_error(message, NULL);
+ }
+
+ sub_type_str = wpa_dbus_type_as_string(type);
+ type_str[1] = sub_type_str[0];
+
+ if (message == NULL)
+ reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
+ else
+ reply = dbus_message_new_method_return(message);
+ if (reply == NULL) {
+ wpa_printf(MSG_ERROR, "dbus: "
+ "wpas_dbus_simple_array_property_getter: out of "
+ "memory to create return message");
+ return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+ }
+
+ dbus_message_iter_init_append(reply, &iter);
+
+ if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
+ type_str, &variant_iter) ||
+ !dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
+ sub_type_str, &array_iter)) {
+ wpa_printf(MSG_ERROR, "dbus: "
+ "wpas_dbus_simple_array_property_getter: out of "
+ "memory to open container");
+ dbus_message_unref(reply);
+ return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+ }
+
+ switch(type) {
+ case DBUS_TYPE_BYTE:
+ case DBUS_TYPE_BOOLEAN:
+ element_size = 1;
+ break;
+ case DBUS_TYPE_INT16:
+ case DBUS_TYPE_UINT16:
+ element_size = sizeof(uint16_t);
+ break;
+ case DBUS_TYPE_INT32:
+ case DBUS_TYPE_UINT32:
+ element_size = sizeof(uint32_t);
+ break;
+ case DBUS_TYPE_INT64:
+ case DBUS_TYPE_UINT64:
+ element_size = sizeof(uint64_t);
+ break;
+ case DBUS_TYPE_DOUBLE:
+ element_size = sizeof(double);
+ break;
+ case DBUS_TYPE_STRING:
+ case DBUS_TYPE_OBJECT_PATH:
+ element_size = sizeof(char *);
+ break;
+ default:
+ wpa_printf(MSG_ERROR, "dbus: "
+ "wpas_dbus_simple_array_property_getter: "
+ "fatal: unknown element type");
+ element_size = 1;
+ break;
+ }
+
+ for (i = 0; i < array_len; i++) {
+ dbus_message_iter_append_basic(&array_iter, type,
+ array + i * element_size);
+ }
+
+ if (!dbus_message_iter_close_container(&variant_iter, &array_iter) ||
+ !dbus_message_iter_close_container(&iter, &variant_iter)) {
+ wpa_printf(MSG_ERROR, "dbus: "
+ "wpas_dbus_simple_array_property_getter: out of "
+ "memory to close container");
+ dbus_message_unref(reply);
+ return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+ }
+
+ return reply;
+}
+
+
+/**
+ * wpas_dbus_handler_create_interface - Request registration of a network iface
+ * @message: Pointer to incoming dbus message
+ * @global: %wpa_supplicant global data structure
+ * Returns: The object path of the new interface object,
+ * or a dbus error message with more information
+ *
+ * Handler function for "CreateInterface" method call. Handles requests
+ * by dbus clients to register a network interface that wpa_supplicant
+ * will manage.
+ */
+DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message,
+ struct wpa_global *global)
+{
+ DBusMessageIter iter_dict;
+ DBusMessage *reply = NULL;
+ DBusMessageIter iter;
+ struct wpa_dbus_dict_entry entry;
+ char *driver = NULL;
+ char *ifname = NULL;
+ char *bridge_ifname = NULL;
+
+ dbus_message_iter_init(message, &iter);
+
+ if (!wpa_dbus_dict_open_read(&iter, &iter_dict))
+ goto error;
+ while (wpa_dbus_dict_has_dict_entry(&iter_dict)) {
+ if (!wpa_dbus_dict_get_entry(&iter_dict, &entry))
+ goto error;
+ if (!strcmp(entry.key, "Driver") &&
+ (entry.type == DBUS_TYPE_STRING)) {
+ driver = os_strdup(entry.str_value);
+ wpa_dbus_dict_entry_clear(&entry);
+ if (driver == NULL)
+ goto error;
+ } else if (!strcmp(entry.key, "Ifname") &&
+ (entry.type == DBUS_TYPE_STRING)) {
+ ifname = os_strdup(entry.str_value);
+ wpa_dbus_dict_entry_clear(&entry);
+ if (ifname == NULL)
+ goto error;
+ } else if (!strcmp(entry.key, "BridgeIfname") &&
+ (entry.type == DBUS_TYPE_STRING)) {
+ bridge_ifname = os_strdup(entry.str_value);
+ wpa_dbus_dict_entry_clear(&entry);
+ if (bridge_ifname == NULL)
+ goto error;
+ } else {
+ wpa_dbus_dict_entry_clear(&entry);
+ goto error;
+ }
+ }
+
+ if (ifname == NULL)
+ goto error; /* Required Ifname argument missing */
+
+ /*
+ * Try to get the wpa_supplicant record for this iface, return
+ * an error if we already control it.
+ */
+ if (wpa_supplicant_get_iface(global, ifname) != NULL) {
+ reply = dbus_message_new_error(message,
+ WPAS_DBUS_ERROR_IFACE_EXISTS,
+ "wpa_supplicant already "
+ "controls this interface.");
+ } else {
+ struct wpa_supplicant *wpa_s;
+ struct wpa_interface iface;
+ os_memset(&iface, 0, sizeof(iface));
+ iface.driver = driver;
+ iface.ifname = ifname;
+ iface.bridge_ifname = bridge_ifname;
+ /* Otherwise, have wpa_supplicant attach to it. */
+ if ((wpa_s = wpa_supplicant_add_iface(global, &iface))) {
+ const char *path = wpa_s->dbus_new_path;
+ reply = dbus_message_new_method_return(message);
+ dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH,
+ &path, DBUS_TYPE_INVALID);
+ } else {
+ reply = wpas_dbus_error_unknown_error(
+ message, "wpa_supplicant couldn't grab this "
+ "interface.");
+ }
+ }
+
+out:
+ os_free(driver);
+ os_free(ifname);
+ os_free(bridge_ifname);
+ return reply;
+
+error:
+ reply = wpas_dbus_error_invalid_args(message, NULL);
+ goto out;
+}
+
+
+/**
+ * wpas_dbus_handler_remove_interface - Request deregistration of an interface
+ * @message: Pointer to incoming dbus message
+ * @global: wpa_supplicant global data structure
+ * Returns: a dbus message containing a UINT32 indicating success (1) or
+ * failure (0), or returns a dbus error message with more information
+ *
+ * Handler function for "removeInterface" method call. Handles requests
+ * by dbus clients to deregister a network interface that wpa_supplicant
+ * currently manages.
+ */
+DBusMessage * wpas_dbus_handler_remove_interface(DBusMessage *message,
+ struct wpa_global *global)
+{
+ struct wpa_supplicant *wpa_s;
+ char *path;
+ DBusMessage *reply = NULL;
+
+ dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+ DBUS_TYPE_INVALID);
+
+ wpa_s = get_iface_by_dbus_path(global, path);
+ if (wpa_s == NULL)
+ reply = wpas_dbus_error_iface_unknown(message);
+ else if (wpa_supplicant_remove_iface(global, wpa_s)) {
+ reply = wpas_dbus_error_unknown_error(
+ message, "wpa_supplicant couldn't remove this "
+ "interface.");
+ }
+
+ return reply;
+}
+
+
+/**
+ * wpas_dbus_handler_get_interface - Get the object path for an interface name
+ * @message: Pointer to incoming dbus message
+ * @global: %wpa_supplicant global data structure
+ * Returns: The object path of the interface object,
+ * or a dbus error message with more information
+ *
+ * Handler function for "getInterface" method call.
+ */
+DBusMessage * wpas_dbus_handler_get_interface(DBusMessage *message,
+ struct wpa_global *global)
+{
+ DBusMessage *reply = NULL;
+ const char *ifname;
+ const char *path;
+ struct wpa_supplicant *wpa_s;
+
+ dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &ifname,
+ DBUS_TYPE_INVALID);
+
+ wpa_s = wpa_supplicant_get_iface(global, ifname);
+ if (wpa_s == NULL)
+ return wpas_dbus_error_iface_unknown(message);
+
+ path = wpa_s->dbus_new_path;
+ reply = dbus_message_new_method_return(message);
+ if (reply == NULL)
+ return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+ if (!dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path,
+ DBUS_TYPE_INVALID)) {
+ dbus_message_unref(reply);
+ return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+ }
+
+ return reply;
+}
+
+
+/**
+ * wpas_dbus_getter_debug_level - Get debug level
+ * @message: Pointer to incoming dbus message
+ * @global: %wpa_supplicant global data structure
+ * Returns: DBus message with value of debug level
+ *
+ * Getter for "DebugLevel" property.
+ */
+DBusMessage * wpas_dbus_getter_debug_level(DBusMessage *message,
+ struct wpa_global *global)
+{
+ const char *str;
+ int idx = wpa_debug_level;
+ if (idx < 0)
+ idx = 0;
+ if (idx > 4)
+ idx = 4;
+ str = debug_strings[idx];
+ return wpas_dbus_simple_property_getter(message, DBUS_TYPE_STRING,
+ &str);
+}
+
+
+/**
+ * wpas_dbus_getter_debug_timestamp - Get debug timestamp
+ * @message: Pointer to incoming dbus message
+ * @global: %wpa_supplicant global data structure
+ * Returns: DBus message with value of debug timestamp
+ *
+ * Getter for "DebugTimestamp" property.
+ */
+DBusMessage * wpas_dbus_getter_debug_timestamp(DBusMessage *message,
+ struct wpa_global *global)
+{
+ return wpas_dbus_simple_property_getter(message, DBUS_TYPE_BOOLEAN,
+ &wpa_debug_timestamp);
+
+}
+
+
+/**
+ * wpas_dbus_getter_debug_show_keys - Get debug show keys
+ * @message: Pointer to incoming dbus message
+ * @global: %wpa_supplicant global data structure
+ * Returns: DBus message with value of debug show_keys
+ *
+ * Getter for "DebugShowKeys" property.
+ */
+DBusMessage * wpas_dbus_getter_debug_show_keys(DBusMessage *message,
+ struct wpa_global *global)
+{
+ return wpas_dbus_simple_property_getter(message, DBUS_TYPE_BOOLEAN,
+ &wpa_debug_show_keys);
+
+}
+
+/**
+ * wpas_dbus_setter_debug_level - Set debug level
+ * @message: Pointer to incoming dbus message
+ * @global: %wpa_supplicant global data structure
+ * Returns: %NULL or DBus error message
+ *
+ * Setter for "DebugLevel" property.
+ */
+DBusMessage * wpas_dbus_setter_debug_level(DBusMessage *message,
+ struct wpa_global *global)
+{
+ DBusMessage *reply;
+ const char *str = NULL;
+ int i, val = -1;
+
+ reply = wpas_dbus_simple_property_setter(message, DBUS_TYPE_STRING,
+ &str);
+ if (reply)
+ return reply;
+
+ for (i = 0; debug_strings[i]; i++)
+ if (os_strcmp(debug_strings[i], str) == 0) {
+ val = i;
+ break;
+ }
+
+ if (val < 0 ||
+ wpa_supplicant_set_debug_params(global, val, wpa_debug_timestamp,
+ wpa_debug_show_keys)) {
+ dbus_message_unref(reply);
+ return wpas_dbus_error_invalid_args(
+ message, "Wrong debug level value");
+ }
+
+ return NULL;
+}
+
+
+/**
+ * wpas_dbus_setter_debug_timestamp - Set debug timestamp
+ * @message: Pointer to incoming dbus message
+ * @global: %wpa_supplicant global data structure
+ * Returns: %NULL or DBus error message
+ *
+ * Setter for "DebugTimestamp" property.
+ */
+DBusMessage * wpas_dbus_setter_debug_timestamp(DBusMessage *message,
+ struct wpa_global *global)
+{
+ DBusMessage *reply;
+ dbus_bool_t val;
+
+ reply = wpas_dbus_simple_property_setter(message, DBUS_TYPE_BOOLEAN,
+ &val);
+ if (reply)
+ return reply;
+
+ wpa_supplicant_set_debug_params(global, wpa_debug_level, val ? 1 : 0,
+ wpa_debug_show_keys);
+
+ return NULL;
+}
+
+
+/**
+ * wpas_dbus_setter_debug_show_keys - Set debug show keys
+ * @message: Pointer to incoming dbus message
+ * @global: %wpa_supplicant global data structure
+ * Returns: %NULL or DBus error message
+ *
+ * Setter for "DebugShowKeys" property.
+ */
+DBusMessage * wpas_dbus_setter_debug_show_keys(DBusMessage *message,
+ struct wpa_global *global)
+{
+ DBusMessage *reply;
+ dbus_bool_t val;
+
+ reply = wpas_dbus_simple_property_setter(message, DBUS_TYPE_BOOLEAN,
+ &val);
+ if (reply)
+ return reply;
+
+ wpa_supplicant_set_debug_params(global, wpa_debug_level,
+ wpa_debug_timestamp,
+ val ? 1 : 0);
+
+ return NULL;
+}
+
+
+/**
+ * wpas_dbus_getter_interfaces - Request registered interfaces list
+ * @message: Pointer to incoming dbus message
+ * @global: %wpa_supplicant global data structure
+ * Returns: The object paths array containing registered interfaces
+ * objects paths or DBus error on failure
+ *
+ * Getter for "Interfaces" property. Handles requests
+ * by dbus clients to return list of registered interfaces objects
+ * paths
+ */
+DBusMessage * wpas_dbus_getter_interfaces(DBusMessage *message,
+ struct wpa_global *global)
+{
+ DBusMessage *reply = NULL;
+ struct wpa_supplicant *wpa_s;
+ const char **paths;
+ unsigned int i = 0, num = 0;
+
+ for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
+ num++;
+
+ paths = os_zalloc(num * sizeof(char*));
+ if (!paths) {
+ return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+ }
+
+ for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
+ paths[i] = wpa_s->dbus_new_path;
+
+ reply = wpas_dbus_simple_array_property_getter(message,
+ DBUS_TYPE_OBJECT_PATH,
+ paths, num);
+
+ os_free(paths);
+ return reply;
+}
+
+
+/**
+ * wpas_dbus_getter_eap_methods - Request supported EAP methods list
+ * @message: Pointer to incoming dbus message
+ * @nothing: not used argument. may be NULL or anything else
+ * Returns: The object paths array containing supported EAP methods
+ * represented by strings or DBus error on failure
+ *
+ * Getter for "EapMethods" property. Handles requests
+ * by dbus clients to return list of strings with supported EAP methods
+ */
+DBusMessage * wpas_dbus_getter_eap_methods(DBusMessage *message, void *nothing)
+{
+ DBusMessage *reply = NULL;
+ char **eap_methods;
+ size_t num_items = 0;
+
+ eap_methods = eap_get_names_as_string_array(&num_items);
+ if (!eap_methods) {
+ return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+ }
+
+ reply = wpas_dbus_simple_array_property_getter(message,
+ DBUS_TYPE_STRING,
+ eap_methods, num_items);
+
+ while (num_items)
+ os_free(eap_methods[--num_items]);
+ os_free(eap_methods);
+ return reply;
+}
+
+
+static int wpas_dbus_get_scan_type(DBusMessage *message, DBusMessageIter *var,
+ char **type, DBusMessage **reply)
+{
+ if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_STRING) {
+ wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
+ "Type must be a string");
+ *reply = wpas_dbus_error_invalid_args(
+ message, "Wrong Type value type. String required");
+ return -1;
+ }
+ dbus_message_iter_get_basic(var, type);
+ return 0;
+}
+
+
+static int wpas_dbus_get_scan_ssids(DBusMessage *message, DBusMessageIter *var,
+ struct wpa_driver_scan_params *params,
+ DBusMessage **reply)
+{
+ struct wpa_driver_scan_ssid *ssids = params->ssids;
+ size_t ssids_num = 0;
+ u8 *ssid;
+ DBusMessageIter array_iter, sub_array_iter;
+ char *val;
+ int len;
+
+ if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_ARRAY) {
+ wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: ssids "
+ "must be an array of arrays of bytes");
+ *reply = wpas_dbus_error_invalid_args(
+ message, "Wrong SSIDs value type. Array of arrays of "
+ "bytes required");
+ return -1;
+ }
+
+ dbus_message_iter_recurse(var, &array_iter);
+
+ if (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_ARRAY ||
+ dbus_message_iter_get_element_type(&array_iter) != DBUS_TYPE_BYTE)
+ {
+ wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: ssids "
+ "must be an array of arrays of bytes");
+ *reply = wpas_dbus_error_invalid_args(
+ message, "Wrong SSIDs value type. Array of arrays of "
+ "bytes required");
+ return -1;
+ }
+
+ while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_ARRAY)
+ {
+ if (ssids_num >= WPAS_MAX_SCAN_SSIDS) {
+ wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
+ "Too many ssids specified on scan dbus "
+ "call");
+ *reply = wpas_dbus_error_invalid_args(
+ message, "Too many ssids specified. Specify "
+ "at most four");
+ return -1;
+ }
+
+ dbus_message_iter_recurse(&array_iter, &sub_array_iter);
+
+ dbus_message_iter_get_fixed_array(&sub_array_iter, &val, &len);
+ if (len == 0) {
+ dbus_message_iter_next(&array_iter);
+ continue;
+ }
+
+ ssid = os_malloc(len);
+ if (ssid == NULL) {
+ wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
+ "out of memory. Cannot allocate memory for "
+ "SSID");
+ *reply = dbus_message_new_error(
+ message, DBUS_ERROR_NO_MEMORY, NULL);
+ return -1;
+ }
+ os_memcpy(ssid, val, len);
+ ssids[ssids_num].ssid = ssid;
+ ssids[ssids_num].ssid_len = len;
+
+ dbus_message_iter_next(&array_iter);
+ ssids_num++;
+ }
+
+ params->num_ssids = ssids_num;
+ return 0;
+}
+
+
+static int wpas_dbus_get_scan_ies(DBusMessage *message, DBusMessageIter *var,
+ struct wpa_driver_scan_params *params,
+ DBusMessage **reply)
+{
+ u8 *ies = NULL, *nies;
+ int ies_len = 0;
+ DBusMessageIter array_iter, sub_array_iter;
+ char *val;
+ int len;
+
+ if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_ARRAY) {
+ wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: ies must "
+ "be an array of arrays of bytes");
+ *reply = wpas_dbus_error_invalid_args(
+ message, "Wrong IEs value type. Array of arrays of "
+ "bytes required");
+ return -1;
+ }
+
+ dbus_message_iter_recurse(var, &array_iter);
+
+ if (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_ARRAY ||
+ dbus_message_iter_get_element_type(&array_iter) != DBUS_TYPE_BYTE)
+ {
+ wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: ies must "
+ "be an array of arrays of bytes");
+ *reply = wpas_dbus_error_invalid_args(
+ message, "Wrong IEs value type. Array required");
+ return -1;
+ }
+
+ while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_ARRAY)
+ {
+ dbus_message_iter_recurse(&array_iter, &sub_array_iter);
+
+ dbus_message_iter_get_fixed_array(&sub_array_iter, &val, &len);
+ if (len == 0) {
+ dbus_message_iter_next(&array_iter);
+ continue;
+ }
+
+ nies = os_realloc(ies, ies_len + len);
+ if (nies == NULL) {
+ wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
+ "out of memory. Cannot allocate memory for "
+ "IE");
+ os_free(ies);
+ *reply = dbus_message_new_error(
+ message, DBUS_ERROR_NO_MEMORY, NULL);
+ return -1;
+ }
+ ies = nies;
+ os_memcpy(ies + ies_len, val, len);
+ ies_len += len;
+
+ dbus_message_iter_next(&array_iter);
+ }
+
+ params->extra_ies = ies;
+ params->extra_ies_len = ies_len;
+ return 0;
+}
+
+
+static int wpas_dbus_get_scan_channels(DBusMessage *message,
+ DBusMessageIter *var,
+ struct wpa_driver_scan_params *params,
+ DBusMessage **reply)
+{
+ DBusMessageIter array_iter, sub_array_iter;
+ int *freqs = NULL, *nfreqs;
+ int freqs_num = 0;
+
+ if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_ARRAY) {
+ wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
+ "Channels must be an array of structs");
+ *reply = wpas_dbus_error_invalid_args(
+ message, "Wrong Channels value type. Array of structs "
+ "required");
+ return -1;
+ }
+
+ dbus_message_iter_recurse(var, &array_iter);
+
+ if (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_STRUCT) {
+ wpa_printf(MSG_DEBUG,
+ "wpas_dbus_handler_scan[dbus]: Channels must be an "
+ "array of structs");
+ *reply = wpas_dbus_error_invalid_args(
+ message, "Wrong Channels value type. Array of structs "
+ "required");
+ return -1;
+ }
+
+ while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_STRUCT)
+ {
+ int freq, width;
+
+ dbus_message_iter_recurse(&array_iter, &sub_array_iter);
+
+ if (dbus_message_iter_get_arg_type(&sub_array_iter) !=
+ DBUS_TYPE_UINT32) {
+ wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
+ "Channel must by specified by struct of "
+ "two UINT32s %c",
+ dbus_message_iter_get_arg_type(
+ &sub_array_iter));
+ *reply = wpas_dbus_error_invalid_args(
+ message, "Wrong Channel struct. Two UINT32s "
+ "required");
+ os_free(freqs);
+ return -1;
+ }
+ dbus_message_iter_get_basic(&sub_array_iter, &freq);
+
+ if (!dbus_message_iter_next(&sub_array_iter) ||
+ dbus_message_iter_get_arg_type(&sub_array_iter) !=
+ DBUS_TYPE_UINT32) {
+ wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
+ "Channel must by specified by struct of "
+ "two UINT32s");
+ *reply = wpas_dbus_error_invalid_args(
+ message,
+ "Wrong Channel struct. Two UINT32s required");
+ os_free(freqs);
+ return -1;
+ }
+
+ dbus_message_iter_get_basic(&sub_array_iter, &width);
+
+#define FREQS_ALLOC_CHUNK 32
+ if (freqs_num % FREQS_ALLOC_CHUNK == 0) {
+ nfreqs = os_realloc(freqs, sizeof(int) *
+ (freqs_num + FREQS_ALLOC_CHUNK));
+ if (nfreqs == NULL)
+ os_free(freqs);
+ freqs = nfreqs;
+ }
+ if (freqs == NULL) {
+ wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
+ "out of memory. can't allocate memory for "
+ "freqs");
+ *reply = dbus_message_new_error(
+ message, DBUS_ERROR_NO_MEMORY, NULL);
+ return -1;
+ }
+
+ freqs[freqs_num] = freq;
+
+ freqs_num++;
+ dbus_message_iter_next(&array_iter);
+ }
+
+ nfreqs = os_realloc(freqs,
+ sizeof(int) * (freqs_num + 1));
+ if (nfreqs == NULL)
+ os_free(freqs);
+ freqs = nfreqs;
+ if (freqs == NULL) {
+ wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
+ "out of memory. Can't allocate memory for freqs");
+ *reply = dbus_message_new_error(
+ message, DBUS_ERROR_NO_MEMORY, NULL);
+ return -1;
+ }
+ freqs[freqs_num] = 0;
+
+ params->freqs = freqs;
+ return 0;
+}
+
+
+/**
+ * wpas_dbus_handler_scan - Request a wireless scan on an interface
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * Returns: NULL indicating success or DBus error message on failure
+ *
+ * Handler function for "Scan" method call of a network device. Requests
+ * that wpa_supplicant perform a wireless scan as soon as possible
+ * on a particular wireless interface.
+ */
+DBusMessage * wpas_dbus_handler_scan(DBusMessage *message,
+ struct wpa_supplicant *wpa_s)
+{
+ DBusMessage *reply = NULL;
+ DBusMessageIter iter, dict_iter, entry_iter, variant_iter;
+ char *key = NULL, *type = NULL;
+ struct wpa_driver_scan_params params;
+ size_t i;
+
+ os_memset(&params, 0, sizeof(params));
+
+ dbus_message_iter_init(message, &iter);
+
+ dbus_message_iter_recurse(&iter, &dict_iter);
+
+ while (dbus_message_iter_get_arg_type(&dict_iter) ==
+ DBUS_TYPE_DICT_ENTRY) {
+ dbus_message_iter_recurse(&dict_iter, &entry_iter);
+ dbus_message_iter_get_basic(&entry_iter, &key);
+ dbus_message_iter_next(&entry_iter);
+ dbus_message_iter_recurse(&entry_iter, &variant_iter);
+
+ if (os_strcmp(key, "Type") == 0) {
+ if (wpas_dbus_get_scan_type(message, &variant_iter,
+ &type, &reply) < 0)
+ goto out;
+ } else if (os_strcmp(key, "SSIDs") == 0) {
+ if (wpas_dbus_get_scan_ssids(message, &variant_iter,
+ &params, &reply) < 0)
+ goto out;
+ } else if (os_strcmp(key, "IEs") == 0) {
+ if (wpas_dbus_get_scan_ies(message, &variant_iter,
+ &params, &reply) < 0)
+ goto out;
+ } else if (os_strcmp(key, "Channels") == 0) {
+ if (wpas_dbus_get_scan_channels(message, &variant_iter,
+ &params, &reply) < 0)
+ goto out;
+ } else {
+ wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
+ "Unknown argument %s", key);
+ reply = wpas_dbus_error_invalid_args(message, key);
+ goto out;
+ }
+
+ dbus_message_iter_next(&dict_iter);
+ }
+
+ if (!type) {
+ wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
+ "Scan type not specified");
+ reply = wpas_dbus_error_invalid_args(message, key);
+ goto out;
+ }
+
+ if (!os_strcmp(type, "passive")) {
+ if (params.num_ssids || params.extra_ies_len) {
+ wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
+ "SSIDs or IEs specified for passive scan.");
+ reply = wpas_dbus_error_invalid_args(
+ message, "You can specify only Channels in "
+ "passive scan");
+ goto out;
+ } else if (params.freqs && params.freqs[0]) {
+ /* wildcard ssid */
+ params.num_ssids++;
+ wpa_supplicant_trigger_scan(wpa_s, &params);
+ } else {
+ wpa_s->scan_req = 2;
+ wpa_supplicant_req_scan(wpa_s, 0, 0);
+ }
+ } else if (!os_strcmp(type, "active")) {
+ wpa_supplicant_trigger_scan(wpa_s, &params);
+ } else {
+ wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
+ "Unknown scan type: %s", type);
+ reply = wpas_dbus_error_invalid_args(message,
+ "Wrong scan type");
+ goto out;
+ }
+
+out:
+ for (i = 0; i < WPAS_MAX_SCAN_SSIDS; i++)
+ os_free((u8 *) params.ssids[i].ssid);
+ os_free((u8 *) params.extra_ies);
+ os_free(params.freqs);
+ return reply;
+}
+
+
+/*
+ * wpas_dbus_handler_disconnect - Terminate the current connection
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * Returns: NotConnected DBus error message if already not connected
+ * or NULL otherwise.
+ *
+ * Handler function for "Disconnect" method call of network interface.
+ */
+DBusMessage * wpas_dbus_handler_disconnect(DBusMessage *message,
+ struct wpa_supplicant *wpa_s)
+{
+ if (wpa_s->current_ssid != NULL) {
+ wpa_s->disconnected = 1;
+ wpa_supplicant_deauthenticate(wpa_s,
+ WLAN_REASON_DEAUTH_LEAVING);
+
+ return NULL;
+ }
+
+ return dbus_message_new_error(message, WPAS_DBUS_ERROR_NOT_CONNECTED,
+ "This interface is not connected");
+}
+
+
+/**
+ * wpas_dbus_new_iface_add_network - Add a new configured network
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * Returns: A dbus message containing the object path of the new network
+ *
+ * Handler function for "AddNetwork" method call of a network interface.
+ */
+DBusMessage * wpas_dbus_handler_add_network(DBusMessage *message,
+ struct wpa_supplicant *wpa_s)
+{
+ DBusMessage *reply = NULL;
+ DBusMessageIter iter;
+ struct wpa_ssid *ssid = NULL;
+ char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *path = path_buf;
+
+ dbus_message_iter_init(message, &iter);
+
+ ssid = wpa_config_add_network(wpa_s->conf);
+ if (ssid == NULL) {
+ wpa_printf(MSG_ERROR, "wpas_dbus_handler_add_network[dbus]: "
+ "can't add new interface.");
+ reply = wpas_dbus_error_unknown_error(
+ message,
+ "wpa_supplicant could not add "
+ "a network on this interface.");
+ goto err;
+ }
+ wpas_notify_network_added(wpa_s, ssid);
+ ssid->disabled = 1;
+ wpa_config_set_network_defaults(ssid);
+
+ reply = set_network_properties(message, wpa_s, ssid, &iter);
+ if (reply) {
+ wpa_printf(MSG_DEBUG, "wpas_dbus_handler_add_network[dbus]:"
+ "control interface couldn't set network "
+ "properties");
+ goto err;
+ }
+
+ /* Construct the object path for this network. */
+ os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
+ "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
+ wpa_s->dbus_new_path, ssid->id);
+
+ reply = dbus_message_new_method_return(message);
+ if (reply == NULL) {
+ reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+ goto err;
+ }
+ if (!dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path,
+ DBUS_TYPE_INVALID)) {
+ dbus_message_unref(reply);
+ reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+ goto err;
+ }
+
+ return reply;
+
+err:
+ if (ssid) {
+ wpas_notify_network_removed(wpa_s, ssid);
+ wpa_config_remove_network(wpa_s->conf, ssid->id);
+ }
+ return reply;
+}
+
+
+/**
+ * wpas_dbus_handler_remove_network - Remove a configured network
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * Returns: NULL on success or dbus error on failure
+ *
+ * Handler function for "RemoveNetwork" method call of a network interface.
+ */
+DBusMessage * wpas_dbus_handler_remove_network(DBusMessage *message,
+ struct wpa_supplicant *wpa_s)
+{
+ DBusMessage *reply = NULL;
+ const char *op;
+ char *iface = NULL, *net_id = NULL;
+ int id;
+ struct wpa_ssid *ssid;
+
+ dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &op,
+ DBUS_TYPE_INVALID);
+
+ /* Extract the network ID and ensure the network */
+ /* is actually a child of this interface */
+ iface = wpas_dbus_new_decompose_object_path(op, &net_id, NULL);
+ if (iface == NULL || os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
+ reply = wpas_dbus_error_invalid_args(message, op);
+ goto out;
+ }
+
+ id = strtoul(net_id, NULL, 10);
+ if (errno == EINVAL) {
+ reply = wpas_dbus_error_invalid_args(message, op);
+ goto out;
+ }
+
+ ssid = wpa_config_get_network(wpa_s->conf, id);
+ if (ssid == NULL) {
+ reply = wpas_dbus_error_network_unknown(message);
+ goto out;
+ }
+
+ wpas_notify_network_removed(wpa_s, ssid);
+
+ if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
+ wpa_printf(MSG_ERROR,
+ "wpas_dbus_handler_remove_network[dbus]: "
+ "error occurred when removing network %d", id);
+ reply = wpas_dbus_error_unknown_error(
+ message, "error removing the specified network on "
+ "this interface.");
+ goto out;
+ }
+
+ if (ssid == wpa_s->current_ssid)
+ wpa_supplicant_deauthenticate(wpa_s,
+ WLAN_REASON_DEAUTH_LEAVING);
+
+out:
+ os_free(iface);
+ os_free(net_id);
+ return reply;
+}
+
+
+/**
+ * wpas_dbus_handler_select_network - Attempt association with a network
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * Returns: NULL on success or dbus error on failure
+ *
+ * Handler function for "SelectNetwork" method call of network interface.
+ */
+DBusMessage * wpas_dbus_handler_select_network(DBusMessage *message,
+ struct wpa_supplicant *wpa_s)
+{
+ DBusMessage *reply = NULL;
+ const char *op;
+ char *iface = NULL, *net_id = NULL;
+ int id;
+ struct wpa_ssid *ssid;
+
+ dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &op,
+ DBUS_TYPE_INVALID);
+
+ /* Extract the network ID and ensure the network */
+ /* is actually a child of this interface */
+ iface = wpas_dbus_new_decompose_object_path(op, &net_id, NULL);
+ if (iface == NULL || os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
+ reply = wpas_dbus_error_invalid_args(message, op);
+ goto out;
+ }
+
+ id = strtoul(net_id, NULL, 10);
+ if (errno == EINVAL) {
+ reply = wpas_dbus_error_invalid_args(message, op);
+ goto out;
+ }
+
+ ssid = wpa_config_get_network(wpa_s->conf, id);
+ if (ssid == NULL) {
+ reply = wpas_dbus_error_network_unknown(message);
+ goto out;
+ }
+
+ /* Finally, associate with the network */
+ wpa_supplicant_select_network(wpa_s, ssid);
+
+out:
+ os_free(iface);
+ os_free(net_id);
+ return reply;
+}
+
+
+/**
+ * wpas_dbus_handler_add_blob - Store named binary blob (ie, for certificates)
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: %wpa_supplicant data structure
+ * Returns: A dbus message containing an error on failure or NULL on success
+ *
+ * Asks wpa_supplicant to internally store a binary blobs.
+ */
+DBusMessage * wpas_dbus_handler_add_blob(DBusMessage *message,
+ struct wpa_supplicant *wpa_s)
+{
+ DBusMessage *reply = NULL;
+ DBusMessageIter iter, array_iter;
+
+ char *blob_name;
+ u8 *blob_data;
+ int blob_len;
+ struct wpa_config_blob *blob = NULL;
+
+ dbus_message_iter_init(message, &iter);
+ dbus_message_iter_get_basic(&iter, &blob_name);
+
+ if (wpa_config_get_blob(wpa_s->conf, blob_name)) {
+ return dbus_message_new_error(message,
+ WPAS_DBUS_ERROR_BLOB_EXISTS,
+ NULL);
+ }
+
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_recurse(&iter, &array_iter);
+
+ dbus_message_iter_get_fixed_array(&array_iter, &blob_data, &blob_len);
+
+ blob = os_zalloc(sizeof(*blob));
+ if (!blob) {
+ reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+ goto err;
+ }
+
+ blob->data = os_malloc(blob_len);
+ if (!blob->data) {
+ reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+ goto err;
+ }
+ os_memcpy(blob->data, blob_data, blob_len);
+
+ blob->len = blob_len;
+ blob->name = os_strdup(blob_name);
+ if (!blob->name) {
+ reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+ goto err;
+ }
+
+ wpa_config_set_blob(wpa_s->conf, blob);
+ wpas_notify_blob_added(wpa_s, blob->name);
+
+ return reply;
+
+err:
+ if (blob) {
+ os_free(blob->name);
+ os_free(blob->data);
+ os_free(blob);
+ }
+ return reply;
+}
+
+
+/**
+ * wpas_dbus_handler_get_blob - Get named binary blob (ie, for certificates)
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: %wpa_supplicant data structure
+ * Returns: A dbus message containing array of bytes (blob)
+ *
+ * Gets one wpa_supplicant's binary blobs.
+ */
+DBusMessage * wpas_dbus_handler_get_blob(DBusMessage *message,
+ struct wpa_supplicant *wpa_s)
+{
+ DBusMessage *reply = NULL;
+ DBusMessageIter iter, array_iter;
+
+ char *blob_name;
+ const struct wpa_config_blob *blob;
+
+ dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &blob_name,
+ DBUS_TYPE_INVALID);
+
+ blob = wpa_config_get_blob(wpa_s->conf, blob_name);
+ if (!blob) {
+ return dbus_message_new_error(message,
+ WPAS_DBUS_ERROR_BLOB_UNKNOWN,
+ "Blob id not set");
+ }
+
+ reply = dbus_message_new_method_return(message);
+ if (!reply) {
+ reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+ goto out;
+ }
+
+ dbus_message_iter_init_append(reply, &iter);
+
+ if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+ DBUS_TYPE_BYTE_AS_STRING,
+ &array_iter)) {
+ dbus_message_unref(reply);
+ reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+ goto out;
+ }
+
+ if (!dbus_message_iter_append_fixed_array(&array_iter, DBUS_TYPE_BYTE,
+ &(blob->data), blob->len)) {
+ dbus_message_unref(reply);
+ reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+ goto out;
+ }
+
+ if (!dbus_message_iter_close_container(&iter, &array_iter)) {
+ dbus_message_unref(reply);
+ reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+ goto out;
+ }
+
+out:
+ return reply;
+}
+
+
+/**
+ * wpas_remove_handler_remove_blob - Remove named binary blob
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: %wpa_supplicant data structure
+ * Returns: NULL on success or dbus error
+ *
+ * Asks wpa_supplicant to internally remove a binary blobs.
+ */
+DBusMessage * wpas_dbus_handler_remove_blob(DBusMessage *message,
+ struct wpa_supplicant *wpa_s)
+{
+ DBusMessage *reply = NULL;
+ char *blob_name;
+
+ dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &blob_name,
+ DBUS_TYPE_INVALID);
+
+ if (wpa_config_remove_blob(wpa_s->conf, blob_name)) {
+ return dbus_message_new_error(message,
+ WPAS_DBUS_ERROR_BLOB_UNKNOWN,
+ "Blob id not set");
+ }
+ wpas_notify_blob_removed(wpa_s, blob_name);
+
+ return reply;
+
+}
+
+
+/**
+ * wpas_dbus_getter_capabilities - Return interface capabilities
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * Returns: A dbus message containing a dict of strings
+ *
+ * Getter for "Capabilities" property of an interface.
+ */
+DBusMessage * wpas_dbus_getter_capabilities(DBusMessage *message,
+ struct wpa_supplicant *wpa_s)
+{
+ DBusMessage *reply = NULL;
+ struct wpa_driver_capa capa;
+ int res;
+ DBusMessageIter iter, iter_dict;
+ DBusMessageIter iter_dict_entry, iter_dict_val, iter_array,
+ variant_iter;
+ const char *scans[] = { "active", "passive", "ssid" };
+ const char *modes[] = { "infrastructure", "ad-hoc", "ap" };
+ int n = sizeof(modes) / sizeof(char *);
+
+ if (message == NULL)
+ reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
+ else
+ reply = dbus_message_new_method_return(message);
+ if (!reply)
+ goto nomem;
+
+ dbus_message_iter_init_append(reply, &iter);
+ if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
+ "a{sv}", &variant_iter))
+ goto nomem;
+
+ if (!wpa_dbus_dict_open_write(&variant_iter, &iter_dict))
+ goto nomem;
+
+ res = wpa_drv_get_capa(wpa_s, &capa);
+
+ /***** pairwise cipher */
+ if (res < 0) {
+ const char *args[] = {"ccmp", "tkip", "none"};
+ if (!wpa_dbus_dict_append_string_array(
+ &iter_dict, "Pairwise", args,
+ sizeof(args) / sizeof(char*)))
+ goto nomem;
+ } else {
+ if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Pairwise",
+ &iter_dict_entry,
+ &iter_dict_val,
+ &iter_array))
+ goto nomem;
+
+ if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) {
+ if (!wpa_dbus_dict_string_array_add_element(
+ &iter_array, "ccmp"))
+ goto nomem;
+ }
+
+ if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) {
+ if (!wpa_dbus_dict_string_array_add_element(
+ &iter_array, "tkip"))
+ goto nomem;
+ }
+
+ if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
+ if (!wpa_dbus_dict_string_array_add_element(
+ &iter_array, "none"))
+ goto nomem;
+ }
+
+ if (!wpa_dbus_dict_end_string_array(&iter_dict,
+ &iter_dict_entry,
+ &iter_dict_val,
+ &iter_array))
+ goto nomem;
+ }
+
+ /***** group cipher */
+ if (res < 0) {
+ const char *args[] = {
+ "ccmp", "tkip", "wep104", "wep40"
+ };
+ if (!wpa_dbus_dict_append_string_array(
+ &iter_dict, "Group", args,
+ sizeof(args) / sizeof(char*)))
+ goto nomem;
+ } else {
+ if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Group",
+ &iter_dict_entry,
+ &iter_dict_val,
+ &iter_array))
+ goto nomem;
+
+ if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) {
+ if (!wpa_dbus_dict_string_array_add_element(
+ &iter_array, "ccmp"))
+ goto nomem;
+ }
+
+ if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) {
+ if (!wpa_dbus_dict_string_array_add_element(
+ &iter_array, "tkip"))
+ goto nomem;
+ }
+
+ if (capa.enc & WPA_DRIVER_CAPA_ENC_WEP104) {
+ if (!wpa_dbus_dict_string_array_add_element(
+ &iter_array, "wep104"))
+ goto nomem;
+ }
+
+ if (capa.enc & WPA_DRIVER_CAPA_ENC_WEP40) {
+ if (!wpa_dbus_dict_string_array_add_element(
+ &iter_array, "wep40"))
+ goto nomem;
+ }
+
+ if (!wpa_dbus_dict_end_string_array(&iter_dict,
+ &iter_dict_entry,
+ &iter_dict_val,
+ &iter_array))
+ goto nomem;
+ }
+
+ /***** key management */
+ if (res < 0) {
+ const char *args[] = {
+ "wpa-psk", "wpa-eap", "ieee8021x", "wpa-none",
+#ifdef CONFIG_WPS
+ "wps",
+#endif /* CONFIG_WPS */
+ "none"
+ };
+ if (!wpa_dbus_dict_append_string_array(
+ &iter_dict, "KeyMgmt", args,
+ sizeof(args) / sizeof(char*)))
+ goto nomem;
+ } else {
+ if (!wpa_dbus_dict_begin_string_array(&iter_dict, "KeyMgmt",
+ &iter_dict_entry,
+ &iter_dict_val,
+ &iter_array))
+ goto nomem;
+
+ if (!wpa_dbus_dict_string_array_add_element(&iter_array,
+ "none"))
+ goto nomem;
+
+ if (!wpa_dbus_dict_string_array_add_element(&iter_array,
+ "ieee8021x"))
+ goto nomem;
+
+ if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
+ WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
+ if (!wpa_dbus_dict_string_array_add_element(
+ &iter_array, "wpa-eap"))
+ goto nomem;
+
+ if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT)
+ if (!wpa_dbus_dict_string_array_add_element(
+ &iter_array, "wpa-ft-eap"))
+ goto nomem;
+
+/* TODO: Ensure that driver actually supports sha256 encryption. */
+#ifdef CONFIG_IEEE80211W
+ if (!wpa_dbus_dict_string_array_add_element(
+ &iter_array, "wpa-eap-sha256"))
+ goto nomem;
+#endif /* CONFIG_IEEE80211W */
+ }
+
+ if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
+ WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
+ if (!wpa_dbus_dict_string_array_add_element(
+ &iter_array, "wpa-psk"))
+ goto nomem;
+
+ if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK)
+ if (!wpa_dbus_dict_string_array_add_element(
+ &iter_array, "wpa-ft-psk"))
+ goto nomem;
+
+/* TODO: Ensure that driver actually supports sha256 encryption. */
+#ifdef CONFIG_IEEE80211W
+ if (!wpa_dbus_dict_string_array_add_element(
+ &iter_array, "wpa-psk-sha256"))
+ goto nomem;
+#endif /* CONFIG_IEEE80211W */
+ }
+
+ if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
+ if (!wpa_dbus_dict_string_array_add_element(
+ &iter_array, "wpa-none"))
+ goto nomem;
+ }
+
+
+#ifdef CONFIG_WPS
+ if (!wpa_dbus_dict_string_array_add_element(&iter_array,
+ "wps"))
+ goto nomem;
+#endif /* CONFIG_WPS */
+
+ if (!wpa_dbus_dict_end_string_array(&iter_dict,
+ &iter_dict_entry,
+ &iter_dict_val,
+ &iter_array))
+ goto nomem;
+ }
+
+ /***** WPA protocol */
+ if (res < 0) {
+ const char *args[] = { "rsn", "wpa" };
+ if (!wpa_dbus_dict_append_string_array(
+ &iter_dict, "Protocol", args,
+ sizeof(args) / sizeof(char*)))
+ goto nomem;
+ } else {
+ if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Protocol",
+ &iter_dict_entry,
+ &iter_dict_val,
+ &iter_array))
+ goto nomem;
+
+ if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
+ WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
+ if (!wpa_dbus_dict_string_array_add_element(
+ &iter_array, "rsn"))
+ goto nomem;
+ }
+
+ if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
+ WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
+ if (!wpa_dbus_dict_string_array_add_element(
+ &iter_array, "wpa"))
+ goto nomem;
+ }
+
+ if (!wpa_dbus_dict_end_string_array(&iter_dict,
+ &iter_dict_entry,
+ &iter_dict_val,
+ &iter_array))
+ goto nomem;
+ }
+
+ /***** auth alg */
+ if (res < 0) {
+ const char *args[] = { "open", "shared", "leap" };
+ if (!wpa_dbus_dict_append_string_array(
+ &iter_dict, "AuthAlg", args,
+ sizeof(args) / sizeof(char*)))
+ goto nomem;
+ } else {
+ if (!wpa_dbus_dict_begin_string_array(&iter_dict, "AuthAlg",
+ &iter_dict_entry,
+ &iter_dict_val,
+ &iter_array))
+ goto nomem;
+
+ if (capa.auth & (WPA_DRIVER_AUTH_OPEN)) {
+ if (!wpa_dbus_dict_string_array_add_element(
+ &iter_array, "open"))
+ goto nomem;
+ }
+
+ if (capa.auth & (WPA_DRIVER_AUTH_SHARED)) {
+ if (!wpa_dbus_dict_string_array_add_element(
+ &iter_array, "shared"))
+ goto nomem;
+ }
+
+ if (capa.auth & (WPA_DRIVER_AUTH_LEAP)) {
+ if (!wpa_dbus_dict_string_array_add_element(
+ &iter_array, "leap"))
+ goto nomem;
+ }
+
+ if (!wpa_dbus_dict_end_string_array(&iter_dict,
+ &iter_dict_entry,
+ &iter_dict_val,
+ &iter_array))
+ goto nomem;
+ }
+
+ /***** Scan */
+ if (!wpa_dbus_dict_append_string_array(&iter_dict, "Scan", scans,
+ sizeof(scans) / sizeof(char *)))
+ goto nomem;
+
+ /***** Modes */
+ if (res < 0 || !(capa.flags & WPA_DRIVER_FLAGS_AP))
+ n--; /* exclude ap mode if it is not supported by the driver */
+ if (!wpa_dbus_dict_append_string_array(&iter_dict, "Modes", modes, n))
+ goto nomem;
+
+ if (!wpa_dbus_dict_close_write(&variant_iter, &iter_dict))
+ goto nomem;
+ if (!dbus_message_iter_close_container(&iter, &variant_iter))
+ goto nomem;
+
+ return reply;
+
+nomem:
+ if (reply)
+ dbus_message_unref(reply);
+
+ return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY, NULL);
+}
+
+
+/**
+ * wpas_dbus_getter_state - Get interface state
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * Returns: A dbus message containing a STRING representing the current
+ * interface state
+ *
+ * Getter for "State" property.
+ */
+DBusMessage * wpas_dbus_getter_state(DBusMessage *message,
+ struct wpa_supplicant *wpa_s)
+{
+ DBusMessage *reply = NULL;
+ const char *str_state;
+ char *state_ls, *tmp;
+
+ str_state = wpa_supplicant_state_txt(wpa_s->wpa_state);
+
+ /* make state string lowercase to fit new DBus API convention
+ */
+ state_ls = tmp = os_strdup(str_state);
+ if (!tmp) {
+ return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+ }
+ while (*tmp) {
+ *tmp = tolower(*tmp);
+ tmp++;
+ }
+
+ reply = wpas_dbus_simple_property_getter(message, DBUS_TYPE_STRING,
+ &state_ls);
+
+ os_free(state_ls);
+
+ return reply;
+}
+
+
+/**
+ * wpas_dbus_new_iface_get_scanning - Get interface scanning state
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * Returns: A dbus message containing whether the interface is scanning
+ *
+ * Getter for "scanning" property.
+ */
+DBusMessage * wpas_dbus_getter_scanning(DBusMessage *message,
+ struct wpa_supplicant *wpa_s)
+{
+ dbus_bool_t scanning = wpa_s->scanning ? TRUE : FALSE;
+ return wpas_dbus_simple_property_getter(message, DBUS_TYPE_BOOLEAN,
+ &scanning);
+}
+
+
+/**
+ * wpas_dbus_getter_ap_scan - Control roaming mode
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * Returns: A message containong value of ap_scan variable
+ *
+ * Getter function for "ApScan" property.
+ */
+DBusMessage * wpas_dbus_getter_ap_scan(DBusMessage *message,
+ struct wpa_supplicant *wpa_s)
+{
+ dbus_uint32_t ap_scan = wpa_s->conf->ap_scan;
+ return wpas_dbus_simple_property_getter(message, DBUS_TYPE_UINT32,
+ &ap_scan);
+}
+
+
+/**
+ * wpas_dbus_setter_ap_scan - Control roaming mode
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * Returns: NULL
+ *
+ * Setter function for "ApScan" property.
+ */
+DBusMessage * wpas_dbus_setter_ap_scan(DBusMessage *message,
+ struct wpa_supplicant *wpa_s)
+{
+ DBusMessage *reply = NULL;
+ dbus_uint32_t ap_scan;
+
+ reply = wpas_dbus_simple_property_setter(message, DBUS_TYPE_UINT32,
+ &ap_scan);
+ if (reply)
+ return reply;
+
+ if (wpa_supplicant_set_ap_scan(wpa_s, ap_scan)) {
+ return wpas_dbus_error_invalid_args(
+ message, "ap_scan must equal 0, 1 or 2");
+ }
+ return NULL;
+}
+
+
+/**
+ * wpas_dbus_getter_ifname - Get interface name
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * Returns: A dbus message containing a name of network interface
+ * associated with with wpa_s
+ *
+ * Getter for "Ifname" property.
+ */
+DBusMessage * wpas_dbus_getter_ifname(DBusMessage *message,
+ struct wpa_supplicant *wpa_s)
+{
+ const char *ifname = wpa_s->ifname;
+ return wpas_dbus_simple_property_getter(message, DBUS_TYPE_STRING,
+ &ifname);
+}
+
+
+/**
+ * wpas_dbus_getter_driver - Get interface name
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * Returns: A dbus message containing a name of network interface
+ * driver associated with with wpa_s
+ *
+ * Getter for "Driver" property.
+ */
+DBusMessage * wpas_dbus_getter_driver(DBusMessage *message,
+ struct wpa_supplicant *wpa_s)
+{
+ const char *driver;
+
+ if (wpa_s->driver == NULL || wpa_s->driver->name == NULL) {
+ wpa_printf(MSG_DEBUG, "wpas_dbus_getter_driver[dbus]: "
+ "wpa_s has no driver set");
+ return wpas_dbus_error_unknown_error(message, NULL);
+ }
+
+ driver = wpa_s->driver->name;
+ return wpas_dbus_simple_property_getter(message, DBUS_TYPE_STRING,
+ &driver);
+}
+
+
+/**
+ * wpas_dbus_getter_current_bss - Get current bss object path
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * Returns: A dbus message containing a DBus object path to
+ * current BSS
+ *
+ * Getter for "CurrentBSS" property.
+ */
+DBusMessage * wpas_dbus_getter_current_bss(DBusMessage *message,
+ struct wpa_supplicant *wpa_s)
+{
+ DBusMessage *reply;
+ char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *bss_obj_path = path_buf;
+
+ if (wpa_s->current_bss)
+ os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
+ "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
+ wpa_s->dbus_new_path, wpa_s->current_bss->id);
+ else
+ os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "/");
+
+ reply = wpas_dbus_simple_property_getter(message,
+ DBUS_TYPE_OBJECT_PATH,
+ &bss_obj_path);
+
+ return reply;
+}
+
+
+/**
+ * wpas_dbus_getter_current_network - Get current network object path
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * Returns: A dbus message containing a DBus object path to
+ * current network
+ *
+ * Getter for "CurrentNetwork" property.
+ */
+DBusMessage * wpas_dbus_getter_current_network(DBusMessage *message,
+ struct wpa_supplicant *wpa_s)
+{
+ DBusMessage *reply;
+ char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *net_obj_path = path_buf;
+
+ if (wpa_s->current_ssid)
+ os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
+ "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
+ wpa_s->dbus_new_path, wpa_s->current_ssid->id);
+ else
+ os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "/");
+
+ reply = wpas_dbus_simple_property_getter(message,
+ DBUS_TYPE_OBJECT_PATH,
+ &net_obj_path);
+
+ return reply;
+}
+
+
+/**
+ * wpas_dbus_getter_bridge_ifname - Get interface name
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * Returns: A dbus message containing a name of bridge network
+ * interface associated with with wpa_s
+ *
+ * Getter for "BridgeIfname" property.
+ */
+DBusMessage * wpas_dbus_getter_bridge_ifname(DBusMessage *message,
+ struct wpa_supplicant *wpa_s)
+{
+ const char *bridge_ifname = NULL;
+
+ bridge_ifname = wpa_s->bridge_ifname;
+ if (bridge_ifname == NULL) {
+ wpa_printf(MSG_ERROR, "wpas_dbus_getter_bridge_ifname[dbus]: "
+ "wpa_s has no bridge interface name set");
+ return wpas_dbus_error_unknown_error(message, NULL);
+ }
+
+ return wpas_dbus_simple_property_getter(message, DBUS_TYPE_STRING,
+ &bridge_ifname);
+}
+
+
+/**
+ * wpas_dbus_getter_bsss - Get array of BSSs objects
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * Returns: a dbus message containing an array of all known BSS objects
+ * dbus paths
+ *
+ * Getter for "BSSs" property.
+ */
+DBusMessage * wpas_dbus_getter_bsss(DBusMessage *message,
+ struct wpa_supplicant *wpa_s)
+{
+ DBusMessage *reply = NULL;
+ struct wpa_bss *bss;
+ char **paths;
+ unsigned int i = 0;
+
+ paths = os_zalloc(wpa_s->num_bss * sizeof(char *));
+ if (!paths) {
+ return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+ }
+
+ /* Loop through scan results and append each result's object path */
+ dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
+ paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
+ if (paths[i] == NULL) {
+ reply = dbus_message_new_error(message,
+ DBUS_ERROR_NO_MEMORY,
+ NULL);
+ goto out;
+ }
+ /* Construct the object path for this BSS. */
+ os_snprintf(paths[i++], WPAS_DBUS_OBJECT_PATH_MAX,
+ "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
+ wpa_s->dbus_new_path, bss->id);
+ }
+
+ reply = wpas_dbus_simple_array_property_getter(message,
+ DBUS_TYPE_OBJECT_PATH,
+ paths, wpa_s->num_bss);
+
+out:
+ while (i)
+ os_free(paths[--i]);
+ os_free(paths);
+ return reply;
+}
+
+
+/**
+ * wpas_dbus_getter_networks - Get array of networks objects
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * Returns: a dbus message containing an array of all configured
+ * networks dbus object paths.
+ *
+ * Getter for "Networks" property.
+ */
+DBusMessage * wpas_dbus_getter_networks(DBusMessage *message,
+ struct wpa_supplicant *wpa_s)
+{
+ DBusMessage *reply = NULL;
+ struct wpa_ssid *ssid;
+ char **paths;
+ unsigned int i = 0, num = 0;
+
+ if (wpa_s->conf == NULL) {
+ wpa_printf(MSG_ERROR, "wpas_dbus_getter_networks[dbus]: "
+ "An error occurred getting networks list.");
+ return wpas_dbus_error_unknown_error(message, NULL);
+ }
+
+ for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next)
+ num++;
+
+ paths = os_zalloc(num * sizeof(char *));
+ if (!paths) {
+ return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+ }
+
+ /* Loop through configured networks and append object path of each */
+ for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
+ paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
+ if (paths[i] == NULL) {
+ reply = dbus_message_new_error(message,
+ DBUS_ERROR_NO_MEMORY,
+ NULL);
+ goto out;
+ }
+
+ /* Construct the object path for this network. */
+ os_snprintf(paths[i++], WPAS_DBUS_OBJECT_PATH_MAX,
+ "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
+ wpa_s->dbus_new_path, ssid->id);
+ }
+
+ reply = wpas_dbus_simple_array_property_getter(message,
+ DBUS_TYPE_OBJECT_PATH,
+ paths, num);
+
+out:
+ while (i)
+ os_free(paths[--i]);
+ os_free(paths);
+ return reply;
+}
+
+
+/**
+ * wpas_dbus_getter_blobs - Get all blobs defined for this interface
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * Returns: a dbus message containing a dictionary of pairs (blob_name, blob)
+ *
+ * Getter for "Blobs" property.
+ */
+DBusMessage * wpas_dbus_getter_blobs(DBusMessage *message,
+ struct wpa_supplicant *wpa_s)
+{
+ DBusMessage *reply = NULL;
+ DBusMessageIter iter, variant_iter, dict_iter, entry_iter, array_iter;
+ struct wpa_config_blob *blob;
+
+ if (message == NULL)
+ reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
+ else
+ reply = dbus_message_new_method_return(message);
+ if (!reply)
+ return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+
+ dbus_message_iter_init_append(reply, &iter);
+
+ if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
+ "a{say}", &variant_iter) ||
+ !dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
+ "{say}", &dict_iter)) {
+ dbus_message_unref(reply);
+ return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+ }
+
+ blob = wpa_s->conf->blobs;
+ while (blob) {
+ if (!dbus_message_iter_open_container(&dict_iter,
+ DBUS_TYPE_DICT_ENTRY,
+ NULL, &entry_iter) ||
+ !dbus_message_iter_append_basic(&entry_iter,
+ DBUS_TYPE_STRING,
+ &(blob->name)) ||
+ !dbus_message_iter_open_container(&entry_iter,
+ DBUS_TYPE_ARRAY,
+ DBUS_TYPE_BYTE_AS_STRING,
+ &array_iter) ||
+ !dbus_message_iter_append_fixed_array(&array_iter,
+ DBUS_TYPE_BYTE,
+ &(blob->data),
+ blob->len) ||
+ !dbus_message_iter_close_container(&entry_iter,
+ &array_iter) ||
+ !dbus_message_iter_close_container(&dict_iter,
+ &entry_iter)) {
+ dbus_message_unref(reply);
+ return dbus_message_new_error(message,
+ DBUS_ERROR_NO_MEMORY,
+ NULL);
+ }
+
+ blob = blob->next;
+ }
+
+ if (!dbus_message_iter_close_container(&variant_iter, &dict_iter) ||
+ !dbus_message_iter_close_container(&iter, &variant_iter)) {
+ dbus_message_unref(reply);
+ return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+ }
+
+ return reply;
+}
+
+
+/**
+ * wpas_dbus_getter_bss_bssid - Return the BSSID of a BSS
+ * @message: Pointer to incoming dbus message
+ * @bss: a pair of interface describing structure and bss's id
+ * Returns: a dbus message containing the bssid for the requested bss
+ *
+ * Getter for "BSSID" property.
+ */
+DBusMessage * wpas_dbus_getter_bss_bssid(DBusMessage *message,
+ struct bss_handler_args *bss)
+{
+ struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
+
+ if (!res) {
+ wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_bssid[dbus]: no "
+ "bss with id %d found", bss->id);
+ return NULL;
+ }
+
+ return wpas_dbus_simple_array_property_getter(message, DBUS_TYPE_BYTE,
+ res->bssid, ETH_ALEN);
+}
+
+
+/**
+ * wpas_dbus_getter_bss_ssid - Return the SSID of a BSS
+ * @message: Pointer to incoming dbus message
+ * @bss: a pair of interface describing structure and bss's id
+ * Returns: a dbus message containing the ssid for the requested bss
+ *
+ * Getter for "SSID" property.
+ */
+DBusMessage * wpas_dbus_getter_bss_ssid(DBusMessage *message,
+ struct bss_handler_args *bss)
+{
+ struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
+
+ if (!res) {
+ wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_ssid[dbus]: no "
+ "bss with id %d found", bss->id);
+ return NULL;
+ }
+
+ return wpas_dbus_simple_array_property_getter(message, DBUS_TYPE_BYTE,
+ res->ssid,
+ res->ssid_len);
+}
+
+
+/**
+ * wpas_dbus_getter_bss_privacy - Return the privacy flag of a BSS
+ * @message: Pointer to incoming dbus message
+ * @bss: a pair of interface describing structure and bss's id
+ * Returns: a dbus message containing the privacy flag value of requested bss
+ *
+ * Getter for "Privacy" property.
+ */
+DBusMessage * wpas_dbus_getter_bss_privacy(DBusMessage *message,
+ struct bss_handler_args *bss)
+{
+ struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
+ dbus_bool_t privacy;
+
+ if (!res) {
+ wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_privacy[dbus]: no "
+ "bss with id %d found", bss->id);
+ return NULL;
+ }
+
+ privacy = (res->caps & IEEE80211_CAP_PRIVACY) ? TRUE : FALSE;
+ return wpas_dbus_simple_property_getter(message, DBUS_TYPE_BOOLEAN,
+ &privacy);
+}
+
+
+/**
+ * wpas_dbus_getter_bss_mode - Return the mode of a BSS
+ * @message: Pointer to incoming dbus message
+ * @bss: a pair of interface describing structure and bss's id
+ * Returns: a dbus message containing the mode of requested bss
+ *
+ * Getter for "Mode" property.
+ */
+DBusMessage * wpas_dbus_getter_bss_mode(DBusMessage *message,
+ struct bss_handler_args *bss)
+{
+ struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
+ const char *mode;
+
+ if (!res) {
+ wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_mode[dbus]: no "
+ "bss with id %d found", bss->id);
+ return NULL;
+ }
+
+ if (res->caps & IEEE80211_CAP_IBSS)
+ mode = "ad-hoc";
+ else
+ mode = "infrastructure";
+
+ return wpas_dbus_simple_property_getter(message, DBUS_TYPE_STRING,
+ &mode);
+}
+
+
+/**
+ * wpas_dbus_getter_bss_level - Return the signal strength of a BSS
+ * @message: Pointer to incoming dbus message
+ * @bss: a pair of interface describing structure and bss's id
+ * Returns: a dbus message containing the signal strength of requested bss
+ *
+ * Getter for "Level" property.
+ */
+DBusMessage * wpas_dbus_getter_bss_signal(DBusMessage *message,
+ struct bss_handler_args *bss)
+{
+ struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
+
+ if (!res) {
+ wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_signal[dbus]: no "
+ "bss with id %d found", bss->id);
+ return NULL;
+ }
+
+ return wpas_dbus_simple_property_getter(message, DBUS_TYPE_INT16,
+ &res->level);
+}
+
+
+/**
+ * wpas_dbus_getter_bss_frequency - Return the frequency of a BSS
+ * @message: Pointer to incoming dbus message
+ * @bss: a pair of interface describing structure and bss's id
+ * Returns: a dbus message containing the frequency of requested bss
+ *
+ * Getter for "Frequency" property.
+ */
+DBusMessage * wpas_dbus_getter_bss_frequency(DBusMessage *message,
+ struct bss_handler_args *bss)
+{
+ struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
+
+ if (!res) {
+ wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_frequency[dbus]: "
+ "no bss with id %d found", bss->id);
+ return NULL;
+ }
+
+ return wpas_dbus_simple_property_getter(message, DBUS_TYPE_UINT16,
+ &res->freq);
+}
+
+
+static int cmp_u8s_desc(const void *a, const void *b)
+{
+ return (*(u8 *) b - *(u8 *) a);
+}
+
+
+/**
+ * wpas_dbus_getter_bss_rates - Return available bit rates of a BSS
+ * @message: Pointer to incoming dbus message
+ * @bss: a pair of interface describing structure and bss's id
+ * Returns: a dbus message containing sorted array of bit rates
+ *
+ * Getter for "Rates" property.
+ */
+DBusMessage * wpas_dbus_getter_bss_rates(DBusMessage *message,
+ struct bss_handler_args *bss)
+{
+ DBusMessage *reply;
+ struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
+ u8 *ie_rates = NULL;
+ u32 *real_rates;
+ int rates_num, i;
+
+ if (!res) {
+ wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_rates[dbus]: "
+ "no bss with id %d found", bss->id);
+ return NULL;
+ }
+
+ rates_num = wpa_bss_get_bit_rates(res, &ie_rates);
+ if (rates_num < 0)
+ return NULL;
+
+ qsort(ie_rates, rates_num, 1, cmp_u8s_desc);
+
+ real_rates = os_malloc(sizeof(u32) * rates_num);
+ if (!real_rates) {
+ os_free(ie_rates);
+ return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+ }
+
+ for (i = 0; i < rates_num; i++)
+ real_rates[i] = ie_rates[i] * 500000;
+
+ reply = wpas_dbus_simple_array_property_getter(message,
+ DBUS_TYPE_UINT32,
+ real_rates, rates_num);
+
+ os_free(ie_rates);
+ os_free(real_rates);
+ return reply;
+}
+
+
+static DBusMessage * wpas_dbus_get_bss_security_prop(
+ DBusMessage *message, struct wpa_ie_data *ie_data)
+{
+ DBusMessage *reply;
+ DBusMessageIter iter, iter_dict, variant_iter;
+ const char *group;
+ const char *pairwise[2]; /* max 2 pairwise ciphers is supported */
+ const char *key_mgmt[7]; /* max 7 key managements may be supported */
+ int n;
+
+ if (message == NULL)
+ reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
+ else
+ reply = dbus_message_new_method_return(message);
+ if (!reply)
+ goto nomem;
+
+ dbus_message_iter_init_append(reply, &iter);
+ if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
+ "a{sv}", &variant_iter))
+ goto nomem;
+
+ if (!wpa_dbus_dict_open_write(&variant_iter, &iter_dict))
+ goto nomem;
+
+ /* KeyMgmt */
+ n = 0;
+ if (ie_data->key_mgmt & WPA_KEY_MGMT_PSK)
+ key_mgmt[n++] = "wpa-psk";
+ if (ie_data->key_mgmt & WPA_KEY_MGMT_FT_PSK)
+ key_mgmt[n++] = "wpa-ft-psk";
+ if (ie_data->key_mgmt & WPA_KEY_MGMT_PSK_SHA256)
+ key_mgmt[n++] = "wpa-psk-sha256";
+ if (ie_data->key_mgmt & WPA_KEY_MGMT_IEEE8021X)
+ key_mgmt[n++] = "wpa-eap";
+ if (ie_data->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X)
+ key_mgmt[n++] = "wpa-ft-eap";
+ if (ie_data->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256)
+ key_mgmt[n++] = "wpa-eap-sha256";
+ if (ie_data->key_mgmt & WPA_KEY_MGMT_NONE)
+ key_mgmt[n++] = "wpa-none";
+
+ if (!wpa_dbus_dict_append_string_array(&iter_dict, "KeyMgmt",
+ key_mgmt, n))
+ goto nomem;
+
+ /* Group */
+ switch (ie_data->group_cipher) {
+ case WPA_CIPHER_WEP40:
+ group = "wep40";
+ break;
+ case WPA_CIPHER_TKIP:
+ group = "tkip";
+ break;
+ case WPA_CIPHER_CCMP:
+ group = "ccmp";
+ break;
+ case WPA_CIPHER_WEP104:
+ group = "wep104";
+ break;
+ default:
+ group = "";
+ break;
+ }
+
+ if (!wpa_dbus_dict_append_string(&iter_dict, "Group", group))
+ goto nomem;
+
+ /* Pairwise */
+ n = 0;
+ if (ie_data->pairwise_cipher & WPA_CIPHER_TKIP)
+ pairwise[n++] = "tkip";
+ if (ie_data->pairwise_cipher & WPA_CIPHER_CCMP)
+ pairwise[n++] = "ccmp";
+
+ if (!wpa_dbus_dict_append_string_array(&iter_dict, "Pairwise",
+ pairwise, n))
+ goto nomem;
+
+ /* Management group (RSN only) */
+ if (ie_data->proto == WPA_PROTO_RSN) {
+ switch (ie_data->mgmt_group_cipher) {
+#ifdef CONFIG_IEEE80211W
+ case WPA_CIPHER_AES_128_CMAC:
+ group = "aes128cmac";
+ break;
+#endif /* CONFIG_IEEE80211W */
+ default:
+ group = "";
+ break;
+ }
+
+ if (!wpa_dbus_dict_append_string(&iter_dict, "MgmtGroup",
+ group))
+ goto nomem;
+ }
+
+ if (!wpa_dbus_dict_close_write(&variant_iter, &iter_dict))
+ goto nomem;
+ if (!dbus_message_iter_close_container(&iter, &variant_iter))
+ goto nomem;
+
+ return reply;
+
+nomem:
+ if (reply)
+ dbus_message_unref(reply);
+
+ return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY, NULL);
+}
+
+
+/**
+ * wpas_dbus_getter_bss_wpa - Return the WPA options of a BSS
+ * @message: Pointer to incoming dbus message
+ * @bss: a pair of interface describing structure and bss's id
+ * Returns: a dbus message containing the WPA options of requested bss
+ *
+ * Getter for "WPA" property.
+ */
+DBusMessage * wpas_dbus_getter_bss_wpa(DBusMessage *message,
+ struct bss_handler_args *bss)
+{
+ struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
+ struct wpa_ie_data wpa_data;
+ const u8 *ie;
+
+ if (!res) {
+ wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_wpa[dbus]: no "
+ "bss with id %d found", bss->id);
+ return NULL;
+ }
+
+ os_memset(&wpa_data, 0, sizeof(wpa_data));
+ ie = wpa_bss_get_vendor_ie(res, WPA_IE_VENDOR_TYPE);
+ if (ie) {
+ if (wpa_parse_wpa_ie(ie, 2 + ie[1], &wpa_data) < 0)
+ return wpas_dbus_error_unknown_error(message,
+ "invalid WPA IE");
+ }
+
+ return wpas_dbus_get_bss_security_prop(message, &wpa_data);
+}
+
+
+/**
+ * wpas_dbus_getter_bss_rsn - Return the RSN options of a BSS
+ * @message: Pointer to incoming dbus message
+ * @bss: a pair of interface describing structure and bss's id
+ * Returns: a dbus message containing the RSN options of requested bss
+ *
+ * Getter for "RSN" property.
+ */
+DBusMessage * wpas_dbus_getter_bss_rsn(DBusMessage *message,
+ struct bss_handler_args *bss)
+{
+ struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
+ struct wpa_ie_data wpa_data;
+ const u8 *ie;
+
+ if (!res) {
+ wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_rsn[dbus]: no "
+ "bss with id %d found", bss->id);
+ return NULL;
+ }
+
+ os_memset(&wpa_data, 0, sizeof(wpa_data));
+ ie = wpa_bss_get_ie(res, WLAN_EID_RSN);
+ if (ie) {
+ if (wpa_parse_wpa_ie(ie, 2 + ie[1], &wpa_data) < 0)
+ return wpas_dbus_error_unknown_error(message,
+ "invalid RSN IE");
+ }
+
+ return wpas_dbus_get_bss_security_prop(message, &wpa_data);
+}
+
+
+/**
+ * wpas_dbus_getter_bss_ies - Return all IEs of a BSS
+ * @message: Pointer to incoming dbus message
+ * @bss: a pair of interface describing structure and bss's id
+ * Returns: a dbus message containing IEs byte array
+ *
+ * Getter for "IEs" property.
+ */
+DBusMessage * wpas_dbus_getter_bss_ies(DBusMessage *message,
+ struct bss_handler_args *bss)
+{
+ struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
+
+ if (!res) {
+ wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_ies[dbus]: no "
+ "bss with id %d found", bss->id);
+ return NULL;
+ }
+
+ return wpas_dbus_simple_array_property_getter(message, DBUS_TYPE_BYTE,
+ res + 1, res->ie_len);
+}
+
+
+/**
+ * wpas_dbus_getter_enabled - Check whether network is enabled or disabled
+ * @message: Pointer to incoming dbus message
+ * @wpas_dbus_setter_enabled: wpa_supplicant structure for a network interface
+ * and wpa_ssid structure for a configured network
+ * Returns: DBus message with boolean indicating state of configured network
+ * or DBus error on failure
+ *
+ * Getter for "enabled" property of a configured network.
+ */
+DBusMessage * wpas_dbus_getter_enabled(DBusMessage *message,
+ struct network_handler_args *net)
+{
+ dbus_bool_t enabled = net->ssid->disabled ? FALSE : TRUE;
+ return wpas_dbus_simple_property_getter(message, DBUS_TYPE_BOOLEAN,
+ &enabled);
+}
+
+
+/**
+ * wpas_dbus_setter_enabled - Mark a configured network as enabled or disabled
+ * @message: Pointer to incoming dbus message
+ * @wpas_dbus_setter_enabled: wpa_supplicant structure for a network interface
+ * and wpa_ssid structure for a configured network
+ * Returns: NULL indicating success or DBus error on failure
+ *
+ * Setter for "Enabled" property of a configured network.
+ */
+DBusMessage * wpas_dbus_setter_enabled(DBusMessage *message,
+ struct network_handler_args *net)
+{
+ DBusMessage *reply = NULL;
+
+ struct wpa_supplicant *wpa_s;
+ struct wpa_ssid *ssid;
+
+ dbus_bool_t enable;
+
+ reply = wpas_dbus_simple_property_setter(message, DBUS_TYPE_BOOLEAN,
+ &enable);
+
+ if (reply)
+ return reply;
+
+ wpa_s = net->wpa_s;
+ ssid = net->ssid;
+
+ if (enable)
+ wpa_supplicant_enable_network(wpa_s, ssid);
+ else
+ wpa_supplicant_disable_network(wpa_s, ssid);
+
+ return NULL;
+}
+
+
+/**
+ * wpas_dbus_getter_network_properties - Get options for a configured network
+ * @message: Pointer to incoming dbus message
+ * @net: wpa_supplicant structure for a network interface and
+ * wpa_ssid structure for a configured network
+ * Returns: DBus message with network properties or DBus error on failure
+ *
+ * Getter for "Properties" property of a configured network.
+ */
+DBusMessage * wpas_dbus_getter_network_properties(
+ DBusMessage *message, struct network_handler_args *net)
+{
+ DBusMessage *reply = NULL;
+ DBusMessageIter iter, variant_iter, dict_iter;
+ char **iterator;
+ char **props = wpa_config_get_all(net->ssid, 0);
+ if (!props)
+ return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+
+ if (message == NULL)
+ reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
+ else
+ reply = dbus_message_new_method_return(message);
+ if (!reply) {
+ reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+ goto out;
+ }
+
+ dbus_message_iter_init_append(reply, &iter);
+
+ if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
+ "a{sv}", &variant_iter) ||
+ !wpa_dbus_dict_open_write(&variant_iter, &dict_iter)) {
+ dbus_message_unref(reply);
+ reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+ goto out;
+ }
+
+ iterator = props;
+ while (*iterator) {
+ if (!wpa_dbus_dict_append_string(&dict_iter, *iterator,
+ *(iterator + 1))) {
+ dbus_message_unref(reply);
+ reply = dbus_message_new_error(message,
+ DBUS_ERROR_NO_MEMORY,
+ NULL);
+ goto out;
+ }
+ iterator += 2;
+ }
+
+
+ if (!wpa_dbus_dict_close_write(&variant_iter, &dict_iter) ||
+ !dbus_message_iter_close_container(&iter, &variant_iter)) {
+ dbus_message_unref(reply);
+ reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+ goto out;
+ }
+
+out:
+ iterator = props;
+ while (*iterator) {
+ os_free(*iterator);
+ iterator++;
+ }
+ os_free(props);
+ return reply;
+}
+
+
+/**
+ * wpas_dbus_setter_network_properties - Set options for a configured network
+ * @message: Pointer to incoming dbus message
+ * @net: wpa_supplicant structure for a network interface and
+ * wpa_ssid structure for a configured network
+ * Returns: NULL indicating success or DBus error on failure
+ *
+ * Setter for "Properties" property of a configured network.
+ */
+DBusMessage * wpas_dbus_setter_network_properties(
+ DBusMessage *message, struct network_handler_args *net)
+{
+ struct wpa_ssid *ssid = net->ssid;
+
+ DBusMessage *reply = NULL;
+ DBusMessageIter iter, variant_iter;
+
+ dbus_message_iter_init(message, &iter);
+
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_next(&iter);
+
+ dbus_message_iter_recurse(&iter, &variant_iter);
+
+ reply = set_network_properties(message, net->wpa_s, ssid,
+ &variant_iter);
+ if (reply)
+ wpa_printf(MSG_DEBUG, "dbus control interface couldn't set "
+ "network properties");
+
+ return reply;
+}
diff --git a/contrib/wpa/wpa_supplicant/dbus/dbus_new_handlers.h b/contrib/wpa/wpa_supplicant/dbus/dbus_new_handlers.h
new file mode 100644
index 0000000..3cdf9cb
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/dbus/dbus_new_handlers.h
@@ -0,0 +1,196 @@
+/*
+ * WPA Supplicant / dbus-based control interface
+ * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
+ * Copyright (c) 2009-2010, Witold Sowa <witold.sowa@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef CTRL_IFACE_DBUS_NEW_HANDLERS_H
+#define CTRL_IFACE_DBUS_NEW_HANDLERS_H
+
+struct network_handler_args {
+ struct wpa_supplicant *wpa_s;
+ struct wpa_ssid *ssid;
+};
+
+struct bss_handler_args {
+ struct wpa_supplicant *wpa_s;
+ unsigned int id;
+};
+
+DBusMessage * wpas_dbus_simple_property_getter(DBusMessage *message,
+ const int type,
+ const void *val);
+
+DBusMessage * wpas_dbus_simple_property_setter(DBusMessage *message,
+ const int type, void *val);
+
+DBusMessage * wpas_dbus_simple_array_property_getter(DBusMessage *message,
+ const int type,
+ const void *array,
+ size_t array_len);
+
+DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message,
+ struct wpa_global *global);
+
+DBusMessage * wpas_dbus_handler_remove_interface(DBusMessage *message,
+ struct wpa_global *global);
+
+DBusMessage * wpas_dbus_handler_get_interface(DBusMessage *message,
+ struct wpa_global *global);
+
+DBusMessage * wpas_dbus_getter_debug_level(DBusMessage *message,
+ struct wpa_global *global);
+
+DBusMessage * wpas_dbus_getter_debug_timestamp(DBusMessage *message,
+ struct wpa_global *global);
+
+DBusMessage * wpas_dbus_getter_debug_show_keys(DBusMessage *message,
+ struct wpa_global *global);
+
+DBusMessage * wpas_dbus_setter_debug_level(DBusMessage *message,
+ struct wpa_global *global);
+
+DBusMessage * wpas_dbus_setter_debug_timestamp(DBusMessage *message,
+ struct wpa_global *global);
+
+DBusMessage * wpas_dbus_setter_debug_show_keys(DBusMessage *message,
+ struct wpa_global *global);
+
+DBusMessage * wpas_dbus_getter_interfaces(DBusMessage *message,
+ struct wpa_global *global);
+
+DBusMessage * wpas_dbus_getter_eap_methods(DBusMessage *message,
+ void *nothing);
+
+DBusMessage * wpas_dbus_handler_scan(DBusMessage *message,
+ struct wpa_supplicant *wpa_s);
+
+DBusMessage * wpas_dbus_handler_disconnect(DBusMessage *message,
+ struct wpa_supplicant *wpa_s);
+
+DBusMessage * wpas_dbus_handler_add_network(DBusMessage *message,
+ struct wpa_supplicant *wpa_s);
+
+DBusMessage * wpas_dbus_handler_remove_network(DBusMessage *message,
+ struct wpa_supplicant *wpa_s);
+
+DBusMessage * wpas_dbus_handler_select_network(DBusMessage *message,
+ struct wpa_supplicant *wpa_s);
+
+DBusMessage * wpas_dbus_handler_add_blob(DBusMessage *message,
+ struct wpa_supplicant *wpa_s);
+
+DBusMessage * wpas_dbus_handler_get_blob(DBusMessage *message,
+ struct wpa_supplicant *wpa_s);
+
+DBusMessage * wpas_dbus_handler_remove_blob(DBusMessage *message,
+ struct wpa_supplicant *wpa_s);
+
+DBusMessage * wpas_dbus_getter_capabilities(DBusMessage *message,
+ struct wpa_supplicant *wpa_s);
+
+DBusMessage * wpas_dbus_getter_state(DBusMessage *message,
+ struct wpa_supplicant *wpa_s);
+
+DBusMessage * wpas_dbus_getter_scanning(DBusMessage *message,
+ struct wpa_supplicant *wpa_s);
+
+DBusMessage * wpas_dbus_getter_ap_scan(DBusMessage *message,
+ struct wpa_supplicant *wpa_s);
+
+DBusMessage * wpas_dbus_setter_ap_scan(DBusMessage *message,
+ struct wpa_supplicant *wpa_s);
+
+DBusMessage * wpas_dbus_getter_ifname(DBusMessage *message,
+ struct wpa_supplicant *wpa_s);
+
+DBusMessage * wpas_dbus_getter_driver(DBusMessage *message,
+ struct wpa_supplicant *wpa_s);
+
+DBusMessage * wpas_dbus_getter_bridge_ifname(DBusMessage *message,
+ struct wpa_supplicant *wpa_s);
+
+DBusMessage * wpas_dbus_getter_current_bss(DBusMessage *message,
+ struct wpa_supplicant *wpa_s);
+
+DBusMessage * wpas_dbus_getter_current_network(DBusMessage *message,
+ struct wpa_supplicant *wpa_s);
+
+DBusMessage * wpas_dbus_getter_bsss(DBusMessage *message,
+ struct wpa_supplicant *wpa_s);
+
+DBusMessage * wpas_dbus_getter_networks(DBusMessage *message,
+ struct wpa_supplicant *wpa_s);
+
+DBusMessage * wpas_dbus_getter_blobs(DBusMessage *message,
+ struct wpa_supplicant *bss);
+
+DBusMessage * wpas_dbus_getter_bss_bssid(DBusMessage *message,
+ struct bss_handler_args *bss);
+
+DBusMessage * wpas_dbus_getter_bss_ssid(DBusMessage *message,
+ struct bss_handler_args *bss);
+
+DBusMessage * wpas_dbus_getter_bss_privacy(DBusMessage *message,
+ struct bss_handler_args *bss);
+
+DBusMessage * wpas_dbus_getter_bss_mode(DBusMessage *message,
+ struct bss_handler_args *bss);
+
+DBusMessage * wpas_dbus_getter_bss_signal(DBusMessage *message,
+ struct bss_handler_args *bss);
+
+DBusMessage * wpas_dbus_getter_bss_frequency(DBusMessage *message,
+ struct bss_handler_args *bss);
+
+DBusMessage * wpas_dbus_getter_bss_rates(DBusMessage *message,
+ struct bss_handler_args *bss);
+
+DBusMessage * wpas_dbus_getter_bss_wpa(DBusMessage *message,
+ struct bss_handler_args *bss);
+
+DBusMessage * wpas_dbus_getter_bss_rsn(DBusMessage *message,
+ struct bss_handler_args *bss);
+
+DBusMessage * wpas_dbus_getter_bss_ies(DBusMessage *message,
+ struct bss_handler_args *bss);
+
+DBusMessage * wpas_dbus_getter_enabled(DBusMessage *message,
+ struct network_handler_args *net);
+
+DBusMessage * wpas_dbus_setter_enabled(DBusMessage *message,
+ struct network_handler_args *net);
+
+DBusMessage * wpas_dbus_getter_network_properties(
+ DBusMessage *message, struct network_handler_args *net);
+
+DBusMessage * wpas_dbus_setter_network_properties(
+ DBusMessage *message, struct network_handler_args *net);
+
+DBusMessage * wpas_dbus_handler_wps_start(DBusMessage *message,
+ struct wpa_supplicant *wpa_s);
+
+DBusMessage * wpas_dbus_getter_process_credentials(
+ DBusMessage *message, struct wpa_supplicant *wpa_s);
+
+DBusMessage * wpas_dbus_setter_process_credentials(
+ DBusMessage *message, struct wpa_supplicant *wpa_s);
+
+DBusMessage * wpas_dbus_getter_credentials(DBusMessage *message,
+ struct wpa_supplicant *wpa_s);
+
+DBusMessage * wpas_dbus_error_invalid_args(DBusMessage *message,
+ const char *arg);
+DBusMessage * wpas_dbus_error_unknown_error(DBusMessage *message,
+ const char *arg);
+
+#endif /* CTRL_IFACE_DBUS_HANDLERS_NEW_H */
diff --git a/contrib/wpa/wpa_supplicant/dbus/dbus_new_handlers_wps.c b/contrib/wpa/wpa_supplicant/dbus/dbus_new_handlers_wps.c
new file mode 100644
index 0000000..dc44a59
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/dbus/dbus_new_handlers_wps.c
@@ -0,0 +1,331 @@
+/*
+ * WPA Supplicant / dbus-based control interface (WPS)
+ * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
+ * Copyright (c) 2009, Witold Sowa <witold.sowa@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "../config.h"
+#include "../wpa_supplicant_i.h"
+#include "../wps_supplicant.h"
+#include "dbus_new_helpers.h"
+#include "dbus_new.h"
+#include "dbus_new_handlers.h"
+#include "dbus_dict_helpers.h"
+
+
+struct wps_start_params {
+ int role; /* 0 - not set, 1 - enrollee, 2 - registrar */
+ int type; /* 0 - not set, 1 - pin, 2 - pbc */
+ u8 *bssid;
+ char *pin;
+};
+
+
+static int wpas_dbus_handler_wps_role(DBusMessage *message,
+ DBusMessageIter *entry_iter,
+ struct wps_start_params *params,
+ DBusMessage **reply)
+{
+ DBusMessageIter variant_iter;
+ char *val;
+
+ dbus_message_iter_recurse(entry_iter, &variant_iter);
+ if (dbus_message_iter_get_arg_type(&variant_iter) !=
+ DBUS_TYPE_STRING) {
+ wpa_printf(MSG_DEBUG, "dbus: WPS.Start - Wrong Role type, "
+ "string required");
+ *reply = wpas_dbus_error_invalid_args(message,
+ "Role must be a string");
+ return -1;
+ }
+ dbus_message_iter_get_basic(&variant_iter, &val);
+ if (os_strcmp(val, "enrollee") == 0)
+ params->role = 1;
+ else if (os_strcmp(val, "registrar") == 0)
+ params->role = 2;
+ else {
+ wpa_printf(MSG_DEBUG, "dbus: WPS.Start - Uknown role %s", val);
+ *reply = wpas_dbus_error_invalid_args(message, val);
+ return -1;
+ }
+ return 0;
+}
+
+
+static int wpas_dbus_handler_wps_type(DBusMessage *message,
+ DBusMessageIter *entry_iter,
+ struct wps_start_params *params,
+ DBusMessage **reply)
+{
+ DBusMessageIter variant_iter;
+ char *val;
+
+ dbus_message_iter_recurse(entry_iter, &variant_iter);
+ if (dbus_message_iter_get_arg_type(&variant_iter) !=
+ DBUS_TYPE_STRING) {
+ wpa_printf(MSG_DEBUG, "dbus: WPS.Start - Wrong Type type, "
+ "string required");
+ *reply = wpas_dbus_error_invalid_args(message,
+ "Type must be a string");
+ return -1;
+ }
+ dbus_message_iter_get_basic(&variant_iter, &val);
+ if (os_strcmp(val, "pin") == 0)
+ params->type = 1;
+ else if (os_strcmp(val, "pbc") == 0)
+ params->type = 2;
+ else {
+ wpa_printf(MSG_DEBUG, "dbus: WPS.Start - Unknown type %s",
+ val);
+ *reply = wpas_dbus_error_invalid_args(message, val);
+ return -1;
+ }
+ return 0;
+}
+
+
+static int wpas_dbus_handler_wps_bssid(DBusMessage *message,
+ DBusMessageIter *entry_iter,
+ struct wps_start_params *params,
+ DBusMessage **reply)
+{
+ DBusMessageIter variant_iter, array_iter;
+ int len;
+
+ dbus_message_iter_recurse(entry_iter, &variant_iter);
+ if (dbus_message_iter_get_arg_type(&variant_iter) != DBUS_TYPE_ARRAY ||
+ dbus_message_iter_get_element_type(&variant_iter) !=
+ DBUS_TYPE_ARRAY) {
+ wpa_printf(MSG_DEBUG, "dbus: WPS.Start - Wrong Bssid type, "
+ "byte array required");
+ *reply = wpas_dbus_error_invalid_args(
+ message, "Bssid must be a byte array");
+ return -1;
+ }
+ dbus_message_iter_recurse(&variant_iter, &array_iter);
+ dbus_message_iter_get_fixed_array(&array_iter, &params->bssid, &len);
+ if (len != ETH_ALEN) {
+ wpa_printf(MSG_DEBUG, "dbus: WPS.Stsrt - Wrong Bssid length "
+ "%d", len);
+ *reply = wpas_dbus_error_invalid_args(message,
+ "Bssid is wrong length");
+ return -1;
+ }
+ return 0;
+}
+
+
+static int wpas_dbus_handler_wps_pin(DBusMessage *message,
+ DBusMessageIter *entry_iter,
+ struct wps_start_params *params,
+ DBusMessage **reply)
+{
+ DBusMessageIter variant_iter;
+
+ dbus_message_iter_recurse(entry_iter, &variant_iter);
+ if (dbus_message_iter_get_arg_type(&variant_iter) !=
+ DBUS_TYPE_STRING) {
+ wpa_printf(MSG_DEBUG, "dbus: WPS.Start - Wrong Pin type, "
+ "string required");
+ *reply = wpas_dbus_error_invalid_args(message,
+ "Pin must be a string");
+ return -1;
+ }
+ dbus_message_iter_get_basic(&variant_iter, &params->pin);
+ return 0;
+}
+
+
+static int wpas_dbus_handler_wps_start_entry(DBusMessage *message, char *key,
+ DBusMessageIter *entry_iter,
+ struct wps_start_params *params,
+ DBusMessage **reply)
+{
+ if (os_strcmp(key, "Role") == 0)
+ return wpas_dbus_handler_wps_role(message, entry_iter,
+ params, reply);
+ else if (os_strcmp(key, "Type") == 0)
+ return wpas_dbus_handler_wps_type(message, entry_iter,
+ params, reply);
+ else if (os_strcmp(key, "Bssid") == 0)
+ return wpas_dbus_handler_wps_bssid(message, entry_iter,
+ params, reply);
+ else if (os_strcmp(key, "Pin") == 0)
+ return wpas_dbus_handler_wps_pin(message, entry_iter,
+ params, reply);
+
+ wpa_printf(MSG_DEBUG, "dbus: WPS.Start - unknown key %s", key);
+ *reply = wpas_dbus_error_invalid_args(message, key);
+ return -1;
+}
+
+
+/**
+ * wpas_dbus_handler_wps_start - Start WPS configuration
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: %wpa_supplicant data structure
+ * Returns: DBus message dictionary on success or DBus error on failure
+ *
+ * Handler for "Start" method call. DBus dictionary argument contains
+ * information about role (enrollee or registrar), authorization method
+ * (pin or push button) and optionally pin and bssid. Returned message
+ * has a dictionary argument which may contain newly generated pin (optional).
+ */
+DBusMessage * wpas_dbus_handler_wps_start(DBusMessage *message,
+ struct wpa_supplicant *wpa_s)
+{
+ DBusMessage *reply = NULL;
+ DBusMessageIter iter, dict_iter, entry_iter;
+ struct wps_start_params params;
+ char *key;
+ char npin[9] = { '\0' };
+ int ret;
+
+ os_memset(&params, 0, sizeof(params));
+ dbus_message_iter_init(message, &iter);
+
+ dbus_message_iter_recurse(&iter, &dict_iter);
+ while (dbus_message_iter_get_arg_type(&dict_iter) ==
+ DBUS_TYPE_DICT_ENTRY) {
+ dbus_message_iter_recurse(&dict_iter, &entry_iter);
+
+ dbus_message_iter_get_basic(&entry_iter, &key);
+ dbus_message_iter_next(&entry_iter);
+
+ if (wpas_dbus_handler_wps_start_entry(message, key,
+ &entry_iter,
+ &params, &reply))
+ return reply;
+
+ dbus_message_iter_next(&dict_iter);
+ }
+
+ if (params.role == 0) {
+ wpa_printf(MSG_DEBUG, "dbus: WPS.Start - Role not specified");
+ return wpas_dbus_error_invalid_args(message,
+ "Role not specified");
+ } else if (params.role == 1 && params.type == 0) {
+ wpa_printf(MSG_DEBUG, "dbus: WPS.Start - Type not specified");
+ return wpas_dbus_error_invalid_args(message,
+ "Type not specified");
+ } else if (params.role == 2 && params.pin == NULL) {
+ wpa_printf(MSG_DEBUG, "dbus: WPS.Start - Pin required for "
+ "registrar role");
+ return wpas_dbus_error_invalid_args(
+ message, "Pin required for registrar role.");
+ }
+
+ if (params.role == 2)
+ ret = wpas_wps_start_reg(wpa_s, params.bssid, params.pin,
+ NULL);
+ else if (params.type == 1) {
+ ret = wpas_wps_start_pin(wpa_s, params.bssid, params.pin);
+ if (ret > 0)
+ os_snprintf(npin, sizeof(npin), "%08d", ret);
+ } else
+ ret = wpas_wps_start_pbc(wpa_s, params.bssid);
+
+ if (ret < 0) {
+ wpa_printf(MSG_DEBUG, "dbus: WPS.Start wpas_wps_failed in "
+ "role %s and key %s",
+ (params.role == 1 ? "enrollee" : "registrar"),
+ (params.type == 0 ? "" :
+ (params.type == 1 ? "pin" : "pbc")));
+ return wpas_dbus_error_unknown_error(message,
+ "WPS start failed");
+ }
+
+ reply = dbus_message_new_method_return(message);
+ if (!reply) {
+ return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+ }
+
+ dbus_message_iter_init_append(reply, &iter);
+ if (!wpa_dbus_dict_open_write(&iter, &dict_iter)) {
+ dbus_message_unref(reply);
+ return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+ }
+
+ if (os_strlen(npin) > 0) {
+ if (!wpa_dbus_dict_append_string(&dict_iter, "Pin", npin)) {
+ dbus_message_unref(reply);
+ return dbus_message_new_error(message,
+ DBUS_ERROR_NO_MEMORY,
+ NULL);
+ }
+ }
+
+ if (!wpa_dbus_dict_close_write(&iter, &dict_iter)) {
+ dbus_message_unref(reply);
+ return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+ }
+
+ return reply;
+}
+
+
+/**
+ * wpas_dbus_getter_process_credentials - Check if credentials are processed
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: %wpa_supplicant data structure
+ * Returns: DBus message with a boolean on success or DBus error on failure
+ *
+ * Getter for "ProcessCredentials" property. Returns returned boolean will be
+ * true if wps_cred_processing configuration field is not equal to 1 or false
+ * if otherwise.
+ */
+DBusMessage * wpas_dbus_getter_process_credentials(
+ DBusMessage *message, struct wpa_supplicant *wpa_s)
+{
+ dbus_bool_t process = (wpa_s->conf->wps_cred_processing != 1);
+ return wpas_dbus_simple_property_getter(message, DBUS_TYPE_BOOLEAN,
+ &process);
+}
+
+
+/**
+ * wpas_dbus_setter_process_credentials - Set credentials_processed conf param
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: %wpa_supplicant data structure
+ * Returns: NULL on success or DBus error on failure
+ *
+ * Setter for "ProcessCredentials" property. Sets credentials_processed on 2
+ * if boolean argument is true or on 1 if otherwise.
+ */
+DBusMessage * wpas_dbus_setter_process_credentials(
+ DBusMessage *message, struct wpa_supplicant *wpa_s)
+{
+ DBusMessage *reply = NULL;
+ dbus_bool_t process_credentials, old_pc;
+
+ reply = wpas_dbus_simple_property_setter(message, DBUS_TYPE_BOOLEAN,
+ &process_credentials);
+ if (reply)
+ return reply;
+
+ old_pc = (wpa_s->conf->wps_cred_processing != 1);
+ wpa_s->conf->wps_cred_processing = (process_credentials ? 2 : 1);
+
+ if ((wpa_s->conf->wps_cred_processing != 1) != old_pc)
+ wpa_dbus_mark_property_changed(wpa_s->global->dbus,
+ wpa_s->dbus_new_path,
+ WPAS_DBUS_NEW_IFACE_WPS,
+ "ProcessCredentials");
+
+ return NULL;
+}
diff --git a/contrib/wpa/wpa_supplicant/dbus/dbus_new_helpers.c b/contrib/wpa/wpa_supplicant/dbus/dbus_new_helpers.c
new file mode 100644
index 0000000..06749db
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/dbus/dbus_new_helpers.c
@@ -0,0 +1,875 @@
+/*
+ * WPA Supplicant / dbus-based control interface
+ * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
+ * Copyright (c) 2009, Witold Sowa <witold.sowa@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "utils/includes.h"
+
+#include "utils/common.h"
+#include "utils/eloop.h"
+#include "dbus_common.h"
+#include "dbus_common_i.h"
+#include "dbus_new.h"
+#include "dbus_new_helpers.h"
+
+
+/**
+ * recursive_iter_copy - Reads arguments from one iterator and
+ * writes to another recursively
+ * @from: iterator to read from
+ * @to: iterator to write to
+ *
+ * Copies one iterator's elements to another. If any element in
+ * iterator is of container type, its content is copied recursively
+ */
+static void recursive_iter_copy(DBusMessageIter *from, DBusMessageIter *to)
+{
+
+ char *subtype = NULL;
+ int type;
+
+ /* iterate over iterator to copy */
+ while ((type = dbus_message_iter_get_arg_type(from)) !=
+ DBUS_TYPE_INVALID) {
+
+ /* simply copy basic type entries */
+ if (dbus_type_is_basic(type)) {
+ if (dbus_type_is_fixed(type)) {
+ /*
+ * According to DBus documentation all
+ * fixed-length types are guaranteed to fit
+ * 8 bytes
+ */
+ dbus_uint64_t v;
+ dbus_message_iter_get_basic(from, &v);
+ dbus_message_iter_append_basic(to, type, &v);
+ } else {
+ char *v;
+ dbus_message_iter_get_basic(from, &v);
+ dbus_message_iter_append_basic(to, type, &v);
+ }
+ } else {
+ /* recursively copy container type entries */
+ DBusMessageIter write_subiter, read_subiter;
+
+ dbus_message_iter_recurse(from, &read_subiter);
+
+ if (type == DBUS_TYPE_VARIANT ||
+ type == DBUS_TYPE_ARRAY) {
+ subtype = dbus_message_iter_get_signature(
+ &read_subiter);
+ }
+
+ dbus_message_iter_open_container(to, type, subtype,
+ &write_subiter);
+
+ recursive_iter_copy(&read_subiter, &write_subiter);
+
+ dbus_message_iter_close_container(to, &write_subiter);
+ if (subtype)
+ dbus_free(subtype);
+ }
+
+ dbus_message_iter_next(from);
+ }
+}
+
+
+static unsigned int fill_dict_with_properties(
+ DBusMessageIter *dict_iter, const struct wpa_dbus_property_desc *props,
+ const char *interface, const void *user_data)
+{
+ DBusMessage *reply;
+ DBusMessageIter entry_iter, ret_iter;
+ unsigned int counter = 0;
+ const struct wpa_dbus_property_desc *dsc;
+
+ for (dsc = props; dsc && dsc->dbus_property; dsc++) {
+ if (!os_strncmp(dsc->dbus_interface, interface,
+ WPAS_DBUS_INTERFACE_MAX) &&
+ dsc->access != W && dsc->getter) {
+ reply = dsc->getter(NULL, user_data);
+ if (!reply)
+ continue;
+
+ if (dbus_message_get_type(reply) ==
+ DBUS_MESSAGE_TYPE_ERROR) {
+ dbus_message_unref(reply);
+ continue;
+ }
+
+ dbus_message_iter_init(reply, &ret_iter);
+
+ dbus_message_iter_open_container(dict_iter,
+ DBUS_TYPE_DICT_ENTRY,
+ NULL, &entry_iter);
+ dbus_message_iter_append_basic(
+ &entry_iter, DBUS_TYPE_STRING,
+ &dsc->dbus_property);
+
+ recursive_iter_copy(&ret_iter, &entry_iter);
+
+ dbus_message_iter_close_container(dict_iter,
+ &entry_iter);
+ dbus_message_unref(reply);
+ counter++;
+ }
+ }
+
+ return counter;
+}
+
+
+/**
+ * get_all_properties - Responds for GetAll properties calls on object
+ * @message: Message with GetAll call
+ * @interface: interface name which properties will be returned
+ * @property_dsc: list of object's properties
+ * Returns: Message with dict of variants as argument with properties values
+ *
+ * Iterates over all properties registered with object and execute getters
+ * of those, which are readable and which interface matches interface
+ * specified as argument. Returned message contains one dict argument
+ * with properties names as keys and theirs values as values.
+ */
+static DBusMessage * get_all_properties(
+ DBusMessage *message, char *interface,
+ struct wpa_dbus_object_desc *obj_dsc)
+{
+ /* Create and initialize the return message */
+ DBusMessage *reply = dbus_message_new_method_return(message);
+ DBusMessageIter iter, dict_iter;
+ int props_num;
+
+ dbus_message_iter_init_append(reply, &iter);
+
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+ DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+ DBUS_TYPE_STRING_AS_STRING
+ DBUS_TYPE_VARIANT_AS_STRING
+ DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
+ &dict_iter);
+
+ props_num = fill_dict_with_properties(&dict_iter, obj_dsc->properties,
+ interface, obj_dsc->user_data);
+
+ dbus_message_iter_close_container(&iter, &dict_iter);
+
+ if (props_num == 0) {
+ dbus_message_unref(reply);
+ reply = dbus_message_new_error(message,
+ DBUS_ERROR_INVALID_ARGS,
+ "No readable properties in "
+ "this interface");
+ }
+
+ return reply;
+}
+
+
+static int is_signature_correct(DBusMessage *message,
+ const struct wpa_dbus_method_desc *method_dsc)
+{
+ /* According to DBus documentation max length of signature is 255 */
+#define MAX_SIG_LEN 256
+ char registered_sig[MAX_SIG_LEN], *pos;
+ const char *sig = dbus_message_get_signature(message);
+ int ret;
+ const struct wpa_dbus_argument *arg;
+
+ pos = registered_sig;
+ *pos = '\0';
+
+ for (arg = method_dsc->args; arg && arg->name; arg++) {
+ if (arg->dir == ARG_IN) {
+ size_t blen = registered_sig + MAX_SIG_LEN - pos;
+ ret = os_snprintf(pos, blen, "%s", arg->type);
+ if (ret < 0 || (size_t) ret >= blen)
+ return 0;
+ pos += ret;
+ }
+ }
+
+ return !os_strncmp(registered_sig, sig, MAX_SIG_LEN);
+}
+
+
+static DBusMessage * properties_get_all(DBusMessage *message, char *interface,
+ struct wpa_dbus_object_desc *obj_dsc)
+{
+ if (os_strcmp(dbus_message_get_signature(message), "s") != 0)
+ return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
+ NULL);
+
+ return get_all_properties(message, interface, obj_dsc);
+}
+
+
+static DBusMessage * properties_get(DBusMessage *message,
+ const struct wpa_dbus_property_desc *dsc,
+ void *user_data)
+{
+ if (os_strcmp(dbus_message_get_signature(message), "ss"))
+ return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
+ NULL);
+
+ if (dsc->access != W && dsc->getter)
+ return dsc->getter(message, user_data);
+
+ return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
+ "Property is write-only");
+}
+
+
+static DBusMessage * properties_set(DBusMessage *message,
+ const struct wpa_dbus_property_desc *dsc,
+ void *user_data)
+{
+ if (os_strcmp(dbus_message_get_signature(message), "ssv"))
+ return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
+ NULL);
+
+ if (dsc->access != R && dsc->setter)
+ return dsc->setter(message, user_data);
+
+ return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
+ "Property is read-only");
+}
+
+
+static DBusMessage *
+properties_get_or_set(DBusMessage *message, DBusMessageIter *iter,
+ char *interface,
+ struct wpa_dbus_object_desc *obj_dsc)
+{
+ const struct wpa_dbus_property_desc *property_dsc;
+ char *property;
+ const char *method;
+
+ method = dbus_message_get_member(message);
+ property_dsc = obj_dsc->properties;
+
+ /* Second argument: property name (DBUS_TYPE_STRING) */
+ if (!dbus_message_iter_next(iter) ||
+ dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_STRING) {
+ return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
+ NULL);
+ }
+ dbus_message_iter_get_basic(iter, &property);
+
+ while (property_dsc && property_dsc->dbus_property) {
+ /* compare property names and
+ * interfaces */
+ if (!os_strncmp(property_dsc->dbus_property, property,
+ WPAS_DBUS_METHOD_SIGNAL_PROP_MAX) &&
+ !os_strncmp(property_dsc->dbus_interface, interface,
+ WPAS_DBUS_INTERFACE_MAX))
+ break;
+
+ property_dsc++;
+ }
+ if (property_dsc == NULL || property_dsc->dbus_property == NULL) {
+ wpa_printf(MSG_DEBUG, "no property handler for %s.%s on %s",
+ interface, property,
+ dbus_message_get_path(message));
+ return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
+ "No such property");
+ }
+
+ if (os_strncmp(WPA_DBUS_PROPERTIES_GET, method,
+ WPAS_DBUS_METHOD_SIGNAL_PROP_MAX) == 0)
+ return properties_get(message, property_dsc,
+ obj_dsc->user_data);
+
+ return properties_set(message, property_dsc, obj_dsc->user_data);
+}
+
+
+static DBusMessage * properties_handler(DBusMessage *message,
+ struct wpa_dbus_object_desc *obj_dsc)
+{
+ DBusMessageIter iter;
+ char *interface;
+ const char *method;
+
+ method = dbus_message_get_member(message);
+ dbus_message_iter_init(message, &iter);
+
+ if (!os_strncmp(WPA_DBUS_PROPERTIES_GET, method,
+ WPAS_DBUS_METHOD_SIGNAL_PROP_MAX) ||
+ !os_strncmp(WPA_DBUS_PROPERTIES_SET, method,
+ WPAS_DBUS_METHOD_SIGNAL_PROP_MAX) ||
+ !os_strncmp(WPA_DBUS_PROPERTIES_GETALL, method,
+ WPAS_DBUS_METHOD_SIGNAL_PROP_MAX)) {
+ /* First argument: interface name (DBUS_TYPE_STRING) */
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+ {
+ return dbus_message_new_error(message,
+ DBUS_ERROR_INVALID_ARGS,
+ NULL);
+ }
+
+ dbus_message_iter_get_basic(&iter, &interface);
+
+ if (!os_strncmp(WPA_DBUS_PROPERTIES_GETALL, method,
+ WPAS_DBUS_METHOD_SIGNAL_PROP_MAX)) {
+ /* GetAll */
+ return properties_get_all(message, interface, obj_dsc);
+ }
+ /* Get or Set */
+ return properties_get_or_set(message, &iter, interface,
+ obj_dsc);
+ }
+ return dbus_message_new_error(message, DBUS_ERROR_UNKNOWN_METHOD,
+ NULL);
+}
+
+
+static DBusMessage * msg_method_handler(DBusMessage *message,
+ struct wpa_dbus_object_desc *obj_dsc)
+{
+ const struct wpa_dbus_method_desc *method_dsc = obj_dsc->methods;
+ const char *method;
+ const char *msg_interface;
+
+ method = dbus_message_get_member(message);
+ msg_interface = dbus_message_get_interface(message);
+
+ /* try match call to any registered method */
+ while (method_dsc && method_dsc->dbus_method) {
+ /* compare method names and interfaces */
+ if (!os_strncmp(method_dsc->dbus_method, method,
+ WPAS_DBUS_METHOD_SIGNAL_PROP_MAX) &&
+ !os_strncmp(method_dsc->dbus_interface, msg_interface,
+ WPAS_DBUS_INTERFACE_MAX))
+ break;
+
+ method_dsc++;
+ }
+ if (method_dsc == NULL || method_dsc->dbus_method == NULL) {
+ wpa_printf(MSG_DEBUG, "no method handler for %s.%s on %s",
+ msg_interface, method,
+ dbus_message_get_path(message));
+ return dbus_message_new_error(message,
+ DBUS_ERROR_UNKNOWN_METHOD, NULL);
+ }
+
+ if (!is_signature_correct(message, method_dsc)) {
+ return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
+ NULL);
+ }
+
+ return method_dsc->method_handler(message,
+ obj_dsc->user_data);
+}
+
+
+/**
+ * message_handler - Handles incoming DBus messages
+ * @connection: DBus connection on which message was received
+ * @message: Received message
+ * @user_data: pointer to description of object to which message was sent
+ * Returns: Returns information whether message was handled or not
+ *
+ * Reads message interface and method name, then checks if they matches one
+ * of the special cases i.e. introspection call or properties get/getall/set
+ * methods and handles it. Else it iterates over registered methods list
+ * and tries to match method's name and interface to those read from message
+ * If appropriate method was found its handler function is called and
+ * response is sent. Otherwise, the DBUS_ERROR_UNKNOWN_METHOD error message
+ * will be sent.
+ */
+static DBusHandlerResult message_handler(DBusConnection *connection,
+ DBusMessage *message, void *user_data)
+{
+ struct wpa_dbus_object_desc *obj_dsc = user_data;
+ const char *method;
+ const char *path;
+ const char *msg_interface;
+ DBusMessage *reply;
+
+ /* get method, interface and path the message is addressed to */
+ method = dbus_message_get_member(message);
+ path = dbus_message_get_path(message);
+ msg_interface = dbus_message_get_interface(message);
+ if (!method || !path || !msg_interface)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ wpa_printf(MSG_MSGDUMP, "dbus: %s.%s (%s)",
+ msg_interface, method, path);
+
+ /* if message is introspection method call */
+ if (!os_strncmp(WPA_DBUS_INTROSPECTION_METHOD, method,
+ WPAS_DBUS_METHOD_SIGNAL_PROP_MAX) &&
+ !os_strncmp(WPA_DBUS_INTROSPECTION_INTERFACE, msg_interface,
+ WPAS_DBUS_INTERFACE_MAX)) {
+#ifdef CONFIG_CTRL_IFACE_DBUS_INTRO
+ reply = wpa_dbus_introspect(message, obj_dsc);
+#else /* CONFIG_CTRL_IFACE_DBUS_INTRO */
+ reply = dbus_message_new_error(
+ message, DBUS_ERROR_UNKNOWN_METHOD,
+ "wpa_supplicant was compiled without "
+ "introspection support.");
+#endif /* CONFIG_CTRL_IFACE_DBUS_INTRO */
+ } else if (!os_strncmp(WPA_DBUS_PROPERTIES_INTERFACE, msg_interface,
+ WPAS_DBUS_INTERFACE_MAX)) {
+ /* if message is properties method call */
+ reply = properties_handler(message, obj_dsc);
+ } else {
+ reply = msg_method_handler(message, obj_dsc);
+ }
+
+ /* If handler succeed returning NULL, reply empty message */
+ if (!reply)
+ reply = dbus_message_new_method_return(message);
+ if (reply) {
+ if (!dbus_message_get_no_reply(message))
+ dbus_connection_send(connection, reply, NULL);
+ dbus_message_unref(reply);
+ }
+
+ wpa_dbus_flush_all_changed_properties(connection);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+
+/**
+ * free_dbus_object_desc - Frees object description data structure
+ * @connection: DBus connection
+ * @obj_dsc: Object description to free
+ *
+ * Frees each of properties, methods and signals description lists and
+ * the object description structure itself.
+ */
+void free_dbus_object_desc(struct wpa_dbus_object_desc *obj_dsc)
+{
+ if (!obj_dsc)
+ return;
+
+ /* free handler's argument */
+ if (obj_dsc->user_data_free_func)
+ obj_dsc->user_data_free_func(obj_dsc->user_data);
+
+ os_free(obj_dsc->path);
+ os_free(obj_dsc->prop_changed_flags);
+ os_free(obj_dsc);
+}
+
+
+static void free_dbus_object_desc_cb(DBusConnection *connection, void *obj_dsc)
+{
+ free_dbus_object_desc(obj_dsc);
+}
+
+/**
+ * wpa_dbus_ctrl_iface_init - Initialize dbus control interface
+ * @application_data: Pointer to application specific data structure
+ * @dbus_path: DBus path to interface object
+ * @dbus_service: DBus service name to register with
+ * @messageHandler: a pointer to function which will handle dbus messages
+ * coming on interface
+ * Returns: 0 on success, -1 on failure
+ *
+ * Initialize the dbus control interface and start receiving commands from
+ * external programs over the bus.
+ */
+int wpa_dbus_ctrl_iface_init(struct wpas_dbus_priv *iface,
+ char *dbus_path, char *dbus_service,
+ struct wpa_dbus_object_desc *obj_desc)
+{
+ DBusError error;
+ int ret = -1;
+ DBusObjectPathVTable wpa_vtable = {
+ &free_dbus_object_desc_cb, &message_handler,
+ NULL, NULL, NULL, NULL
+ };
+
+ obj_desc->connection = iface->con;
+ obj_desc->path = os_strdup(dbus_path);
+
+ /* Register the message handler for the global dbus interface */
+ if (!dbus_connection_register_object_path(iface->con,
+ dbus_path, &wpa_vtable,
+ obj_desc)) {
+ wpa_printf(MSG_ERROR, "dbus: Could not set up message "
+ "handler");
+ return -1;
+ }
+
+ /* Register our service with the message bus */
+ dbus_error_init(&error);
+ switch (dbus_bus_request_name(iface->con, dbus_service,
+ 0, &error)) {
+ case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER:
+ ret = 0;
+ break;
+ case DBUS_REQUEST_NAME_REPLY_EXISTS:
+ case DBUS_REQUEST_NAME_REPLY_IN_QUEUE:
+ case DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER:
+ wpa_printf(MSG_ERROR, "dbus: Could not request service name: "
+ "already registered");
+ break;
+ default:
+ wpa_printf(MSG_ERROR, "dbus: Could not request service name: "
+ "%s %s", error.name, error.message);
+ break;
+ }
+ dbus_error_free(&error);
+
+ if (ret != 0)
+ return -1;
+
+ wpa_printf(MSG_DEBUG, "Providing DBus service '%s'.", dbus_service);
+
+ return 0;
+}
+
+
+/**
+ * wpa_dbus_register_object_per_iface - Register a new object with dbus
+ * @ctrl_iface: pointer to dbus private data
+ * @path: DBus path to object
+ * @ifname: interface name
+ * @obj_desc: description of object's methods, signals and properties
+ * Returns: 0 on success, -1 on error
+ *
+ * Registers a new interface with dbus and assigns it a dbus object path.
+ */
+int wpa_dbus_register_object_per_iface(
+ struct wpas_dbus_priv *ctrl_iface,
+ const char *path, const char *ifname,
+ struct wpa_dbus_object_desc *obj_desc)
+{
+ DBusConnection *con;
+
+ DBusObjectPathVTable vtable = {
+ &free_dbus_object_desc_cb, &message_handler,
+ NULL, NULL, NULL, NULL
+ };
+
+ /* Do nothing if the control interface is not turned on */
+ if (ctrl_iface == NULL)
+ return 0;
+
+ con = ctrl_iface->con;
+ obj_desc->connection = con;
+ obj_desc->path = os_strdup(path);
+
+ /* Register the message handler for the interface functions */
+ if (!dbus_connection_register_object_path(con, path, &vtable,
+ obj_desc)) {
+ wpa_printf(MSG_ERROR, "dbus: Could not set up message "
+ "handler for interface %s object %s", ifname, path);
+ return -1;
+ }
+
+ return 0;
+}
+
+
+static void flush_object_timeout_handler(void *eloop_ctx, void *timeout_ctx);
+
+
+/**
+ * wpa_dbus_unregister_object_per_iface - Unregisters DBus object
+ * @ctrl_iface: Pointer to dbus private data
+ * @path: DBus path to object which will be unregistered
+ * Returns: Zero on success and -1 on failure
+ *
+ * Unregisters DBus object given by its path
+ */
+int wpa_dbus_unregister_object_per_iface(
+ struct wpas_dbus_priv *ctrl_iface, const char *path)
+{
+ DBusConnection *con = ctrl_iface->con;
+ struct wpa_dbus_object_desc *obj_desc = NULL;
+
+ dbus_connection_get_object_path_data(con, path, (void **) &obj_desc);
+ if (!obj_desc) {
+ wpa_printf(MSG_ERROR, "dbus: %s: Could not obtain object's "
+ "private data: %s", __func__, path);
+ } else {
+ eloop_cancel_timeout(flush_object_timeout_handler, con,
+ obj_desc);
+ }
+
+ if (!dbus_connection_unregister_object_path(con, path))
+ return -1;
+
+ return 0;
+}
+
+
+static void put_changed_properties(const struct wpa_dbus_object_desc *obj_dsc,
+ const char *interface,
+ DBusMessageIter *dict_iter)
+{
+ DBusMessage *getter_reply;
+ DBusMessageIter prop_iter, entry_iter;
+ const struct wpa_dbus_property_desc *dsc;
+ int i;
+
+ for (dsc = obj_dsc->properties, i = 0; dsc && dsc->dbus_property;
+ dsc++, i++) {
+ if (obj_dsc->prop_changed_flags == NULL ||
+ !obj_dsc->prop_changed_flags[i])
+ continue;
+ if (os_strcmp(dsc->dbus_interface, interface) != 0)
+ continue;
+ obj_dsc->prop_changed_flags[i] = 0;
+
+ getter_reply = dsc->getter(NULL, obj_dsc->user_data);
+ if (!getter_reply ||
+ dbus_message_get_type(getter_reply) ==
+ DBUS_MESSAGE_TYPE_ERROR) {
+ wpa_printf(MSG_ERROR, "dbus: %s: Cannot get new value "
+ "of property %s", __func__,
+ dsc->dbus_property);
+ continue;
+ }
+
+ if (!dbus_message_iter_init(getter_reply, &prop_iter) ||
+ !dbus_message_iter_open_container(dict_iter,
+ DBUS_TYPE_DICT_ENTRY,
+ NULL, &entry_iter) ||
+ !dbus_message_iter_append_basic(&entry_iter,
+ DBUS_TYPE_STRING,
+ &dsc->dbus_property))
+ goto err;
+
+ recursive_iter_copy(&prop_iter, &entry_iter);
+
+ if (!dbus_message_iter_close_container(dict_iter, &entry_iter))
+ goto err;
+
+ dbus_message_unref(getter_reply);
+ }
+
+ return;
+
+err:
+ wpa_printf(MSG_ERROR, "dbus: %s: Cannot construct signal", __func__);
+}
+
+
+static void send_prop_changed_signal(
+ DBusConnection *con, const char *path, const char *interface,
+ const struct wpa_dbus_object_desc *obj_dsc)
+{
+ DBusMessage *msg;
+ DBusMessageIter signal_iter, dict_iter;
+
+ msg = dbus_message_new_signal(path, interface, "PropertiesChanged");
+ if (msg == NULL)
+ return;
+
+ dbus_message_iter_init_append(msg, &signal_iter);
+
+ if (!dbus_message_iter_open_container(&signal_iter, DBUS_TYPE_ARRAY,
+ "{sv}", &dict_iter))
+ goto err;
+
+ put_changed_properties(obj_dsc, interface, &dict_iter);
+
+ if (!dbus_message_iter_close_container(&signal_iter, &dict_iter))
+ goto err;
+
+ dbus_connection_send(con, msg, NULL);
+
+out:
+ dbus_message_unref(msg);
+ return;
+
+err:
+ wpa_printf(MSG_DEBUG, "dbus: %s: Failed to construct signal",
+ __func__);
+ goto out;
+}
+
+
+static void flush_object_timeout_handler(void *eloop_ctx, void *timeout_ctx)
+{
+ DBusConnection *con = eloop_ctx;
+ struct wpa_dbus_object_desc *obj_desc = timeout_ctx;
+
+ wpa_printf(MSG_DEBUG, "dbus: %s: Timeout - sending changed properties "
+ "of object %s", __func__, obj_desc->path);
+ wpa_dbus_flush_object_changed_properties(con, obj_desc->path);
+}
+
+
+static void recursive_flush_changed_properties(DBusConnection *con,
+ const char *path)
+{
+ char **objects = NULL;
+ char subobj_path[WPAS_DBUS_OBJECT_PATH_MAX];
+ int i;
+
+ wpa_dbus_flush_object_changed_properties(con, path);
+
+ if (!dbus_connection_list_registered(con, path, &objects))
+ goto out;
+
+ for (i = 0; objects[i]; i++) {
+ os_snprintf(subobj_path, WPAS_DBUS_OBJECT_PATH_MAX,
+ "%s/%s", path, objects[i]);
+ recursive_flush_changed_properties(con, subobj_path);
+ }
+
+out:
+ dbus_free_string_array(objects);
+}
+
+
+/**
+ * wpa_dbus_flush_all_changed_properties - Send all PropertiesChanged signals
+ * @con: DBus connection
+ *
+ * Traverses through all registered objects and sends PropertiesChanged for
+ * each properties.
+ */
+void wpa_dbus_flush_all_changed_properties(DBusConnection *con)
+{
+ recursive_flush_changed_properties(con, WPAS_DBUS_NEW_PATH);
+}
+
+
+/**
+ * wpa_dbus_flush_object_changed_properties - Send PropertiesChanged for object
+ * @con: DBus connection
+ * @path: path to a DBus object for which PropertiesChanged will be sent.
+ *
+ * Iterates over all properties registered with object and for each interface
+ * containing properties marked as changed, sends a PropertiesChanged signal
+ * containing names and new values of properties that have changed.
+ *
+ * You need to call this function after wpa_dbus_mark_property_changed()
+ * if you want to send PropertiesChanged signal immediately (i.e., without
+ * waiting timeout to expire). PropertiesChanged signal for an object is sent
+ * automatically short time after first marking property as changed. All
+ * PropertiesChanged signals are sent automatically after responding on DBus
+ * message, so if you marked a property changed as a result of DBus call
+ * (e.g., param setter), you usually do not need to call this function.
+ */
+void wpa_dbus_flush_object_changed_properties(DBusConnection *con,
+ const char *path)
+{
+ struct wpa_dbus_object_desc *obj_desc = NULL;
+ const struct wpa_dbus_property_desc *dsc;
+ int i;
+
+ dbus_connection_get_object_path_data(con, path, (void **) &obj_desc);
+ if (!obj_desc)
+ return;
+ eloop_cancel_timeout(flush_object_timeout_handler, con, obj_desc);
+
+ dsc = obj_desc->properties;
+ for (dsc = obj_desc->properties, i = 0; dsc && dsc->dbus_property;
+ dsc++, i++) {
+ if (obj_desc->prop_changed_flags == NULL ||
+ !obj_desc->prop_changed_flags[i])
+ continue;
+ send_prop_changed_signal(con, path, dsc->dbus_interface,
+ obj_desc);
+ }
+}
+
+
+#define WPA_DBUS_SEND_PROP_CHANGED_TIMEOUT 5000
+
+
+/**
+ * wpa_dbus_mark_property_changed - Mark a property as changed and
+ * @iface: dbus priv struct
+ * @path: path to DBus object which property has changed
+ * @interface: interface containing changed property
+ * @property: property name which has changed
+ *
+ * Iterates over all properties registered with an object and marks the one
+ * given in parameters as changed. All parameters registered for an object
+ * within a single interface will be aggregated together and sent in one
+ * PropertiesChanged signal when function
+ * wpa_dbus_flush_object_changed_properties() is called.
+ */
+void wpa_dbus_mark_property_changed(struct wpas_dbus_priv *iface,
+ const char *path, const char *interface,
+ const char *property)
+{
+ struct wpa_dbus_object_desc *obj_desc = NULL;
+ const struct wpa_dbus_property_desc *dsc;
+ int i = 0;
+
+ if (iface == NULL)
+ return;
+
+ dbus_connection_get_object_path_data(iface->con, path,
+ (void **) &obj_desc);
+ if (!obj_desc) {
+ wpa_printf(MSG_ERROR, "dbus: wpa_dbus_property_changed: "
+ "could not obtain object's private data: %s", path);
+ return;
+ }
+
+ for (dsc = obj_desc->properties; dsc && dsc->dbus_property; dsc++, i++)
+ if (os_strcmp(property, dsc->dbus_property) == 0 &&
+ os_strcmp(interface, dsc->dbus_interface) == 0) {
+ if (obj_desc->prop_changed_flags)
+ obj_desc->prop_changed_flags[i] = 1;
+ break;
+ }
+
+ if (!dsc || !dsc->dbus_property) {
+ wpa_printf(MSG_ERROR, "dbus: wpa_dbus_property_changed: "
+ "no property %s in object %s", property, path);
+ return;
+ }
+
+ if (!eloop_is_timeout_registered(flush_object_timeout_handler,
+ iface->con, obj_desc->path)) {
+ eloop_register_timeout(0, WPA_DBUS_SEND_PROP_CHANGED_TIMEOUT,
+ flush_object_timeout_handler,
+ iface->con, obj_desc);
+ }
+}
+
+
+/**
+ * wpa_dbus_get_object_properties - Put object's properties into dictionary
+ * @iface: dbus priv struct
+ * @path: path to DBus object which properties will be obtained
+ * @interface: interface name which properties will be obtained
+ * @dict_iter: correct, open DBus dictionary iterator.
+ *
+ * Iterates over all properties registered with object and execute getters
+ * of those, which are readable and which interface matches interface
+ * specified as argument. Obtained properties values are stored in
+ * dict_iter dictionary.
+ */
+void wpa_dbus_get_object_properties(struct wpas_dbus_priv *iface,
+ const char *path, const char *interface,
+ DBusMessageIter *dict_iter)
+{
+ struct wpa_dbus_object_desc *obj_desc = NULL;
+
+ dbus_connection_get_object_path_data(iface->con, path,
+ (void **) &obj_desc);
+ if (!obj_desc) {
+ wpa_printf(MSG_ERROR, "dbus: wpa_dbus_get_object_properties: "
+ "could not obtain object's private data: %s", path);
+ return;
+ }
+
+ fill_dict_with_properties(dict_iter, obj_desc->properties,
+ interface, obj_desc->user_data);
+}
diff --git a/contrib/wpa/wpa_supplicant/dbus/dbus_new_helpers.h b/contrib/wpa/wpa_supplicant/dbus/dbus_new_helpers.h
new file mode 100644
index 0000000..8db7a37
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/dbus/dbus_new_helpers.h
@@ -0,0 +1,147 @@
+/*
+ * WPA Supplicant / dbus-based control interface
+ * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
+ * Copyright (c) 2009, Witold Sowa <witold.sowa@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef WPA_DBUS_CTRL_H
+#define WPA_DBUS_CTRL_H
+
+#include <dbus/dbus.h>
+
+typedef DBusMessage * (* WPADBusMethodHandler)(DBusMessage *message,
+ void *user_data);
+typedef void (* WPADBusArgumentFreeFunction)(void *handler_arg);
+
+typedef DBusMessage * (* WPADBusPropertyAccessor)(DBusMessage *message,
+ const void *user_data);
+
+struct wpa_dbus_object_desc {
+ DBusConnection *connection;
+ char *path;
+
+ /* list of methods, properties and signals registered with object */
+ const struct wpa_dbus_method_desc *methods;
+ const struct wpa_dbus_signal_desc *signals;
+ const struct wpa_dbus_property_desc *properties;
+
+ /* property changed flags */
+ u8 *prop_changed_flags;
+
+ /* argument for method handlers and properties
+ * getter and setter functions */
+ void *user_data;
+ /* function used to free above argument */
+ WPADBusArgumentFreeFunction user_data_free_func;
+};
+
+enum dbus_prop_access { R, W, RW };
+
+enum dbus_arg_direction { ARG_IN, ARG_OUT };
+
+struct wpa_dbus_argument {
+ char *name;
+ char *type;
+ enum dbus_arg_direction dir;
+};
+
+#define END_ARGS { NULL, NULL, ARG_IN }
+
+/**
+ * struct wpa_dbus_method_desc - DBus method description
+ */
+struct wpa_dbus_method_desc {
+ /* method name */
+ const char *dbus_method;
+ /* method interface */
+ const char *dbus_interface;
+ /* method handling function */
+ WPADBusMethodHandler method_handler;
+ /* array of arguments */
+ struct wpa_dbus_argument args[3];
+};
+
+/**
+ * struct wpa_dbus_signal_desc - DBus signal description
+ */
+struct wpa_dbus_signal_desc {
+ /* signal name */
+ const char *dbus_signal;
+ /* signal interface */
+ const char *dbus_interface;
+ /* array of arguments */
+ struct wpa_dbus_argument args[3];
+};
+
+/**
+ * struct wpa_dbus_property_desc - DBus property description
+ */
+struct wpa_dbus_property_desc {
+ /* property name */
+ const char *dbus_property;
+ /* property interface */
+ const char *dbus_interface;
+ /* property type signature in DBus type notation */
+ const char *type;
+ /* property getter function */
+ WPADBusPropertyAccessor getter;
+ /* property setter function */
+ WPADBusPropertyAccessor setter;
+ /* property access permissions */
+ enum dbus_prop_access access;
+};
+
+
+#define WPAS_DBUS_OBJECT_PATH_MAX 150
+#define WPAS_DBUS_INTERFACE_MAX 150
+#define WPAS_DBUS_METHOD_SIGNAL_PROP_MAX 50
+
+#define WPA_DBUS_INTROSPECTION_INTERFACE "org.freedesktop.DBus.Introspectable"
+#define WPA_DBUS_INTROSPECTION_METHOD "Introspect"
+#define WPA_DBUS_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
+#define WPA_DBUS_PROPERTIES_GET "Get"
+#define WPA_DBUS_PROPERTIES_SET "Set"
+#define WPA_DBUS_PROPERTIES_GETALL "GetAll"
+
+void free_dbus_object_desc(struct wpa_dbus_object_desc *obj_dsc);
+
+int wpa_dbus_ctrl_iface_init(struct wpas_dbus_priv *iface, char *dbus_path,
+ char *dbus_service,
+ struct wpa_dbus_object_desc *obj_desc);
+
+int wpa_dbus_register_object_per_iface(
+ struct wpas_dbus_priv *ctrl_iface,
+ const char *path, const char *ifname,
+ struct wpa_dbus_object_desc *obj_desc);
+
+int wpa_dbus_unregister_object_per_iface(
+ struct wpas_dbus_priv *ctrl_iface,
+ const char *path);
+
+void wpa_dbus_get_object_properties(struct wpas_dbus_priv *iface,
+ const char *path, const char *interface,
+ DBusMessageIter *dict_iter);
+
+
+void wpa_dbus_flush_all_changed_properties(DBusConnection *con);
+
+void wpa_dbus_flush_object_changed_properties(DBusConnection *con,
+ const char *path);
+
+void wpa_dbus_mark_property_changed(struct wpas_dbus_priv *iface,
+ const char *path, const char *interface,
+ const char *property);
+
+DBusMessage * wpa_dbus_introspect(DBusMessage *message,
+ struct wpa_dbus_object_desc *obj_dsc);
+
+#endif /* WPA_DBUS_CTRL_H */
diff --git a/contrib/wpa/wpa_supplicant/dbus/dbus_new_introspect.c b/contrib/wpa/wpa_supplicant/dbus/dbus_new_introspect.c
new file mode 100644
index 0000000..c660c04
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/dbus/dbus_new_introspect.c
@@ -0,0 +1,278 @@
+/*
+ * wpa_supplicant - D-Bus introspection
+ * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
+ * Copyright (c) 2009, Witold Sowa <witold.sowa@gmail.com>
+ * Copyright (c) 2010, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "utils/includes.h"
+
+#include "utils/common.h"
+#include "utils/list.h"
+#include "utils/wpabuf.h"
+#include "dbus_common_i.h"
+#include "dbus_new_helpers.h"
+
+
+struct interfaces {
+ struct dl_list list;
+ char *dbus_interface;
+ struct wpabuf *xml;
+};
+
+
+static struct interfaces * add_interface(struct dl_list *list,
+ const char *dbus_interface)
+{
+ struct interfaces *iface;
+
+ dl_list_for_each(iface, list, struct interfaces, list) {
+ if (os_strcmp(iface->dbus_interface, dbus_interface) == 0)
+ return iface; /* already in the list */
+ }
+
+ iface = os_zalloc(sizeof(struct interfaces));
+ if (!iface)
+ return NULL;
+ iface->xml = wpabuf_alloc(3000);
+ if (iface->xml == NULL) {
+ os_free(iface);
+ return NULL;
+ }
+ wpabuf_printf(iface->xml, "<interface name=\"%s\">", dbus_interface);
+ dl_list_add_tail(list, &iface->list);
+ iface->dbus_interface = os_strdup(dbus_interface);
+ return iface;
+}
+
+
+static void add_arg(struct wpabuf *xml, const char *name, const char *type,
+ const char *direction)
+{
+ wpabuf_printf(xml, "<arg name=\"%s\"", name);
+ if (type)
+ wpabuf_printf(xml, " type=\"%s\"", type);
+ if (direction)
+ wpabuf_printf(xml, " direction=\"%s\"", direction);
+ wpabuf_put_str(xml, "/>");
+}
+
+
+static void add_entry(struct wpabuf *xml, const char *type, const char *name,
+ const struct wpa_dbus_argument *args, int include_dir)
+{
+ const struct wpa_dbus_argument *arg;
+
+ if (args == NULL || args->name == NULL) {
+ wpabuf_printf(xml, "<%s name=\"%s\"/>", type, name);
+ return;
+ }
+ wpabuf_printf(xml, "<%s name=\"%s\">", type, name);
+ for (arg = args; arg && arg->name; arg++) {
+ add_arg(xml, arg->name, arg->type,
+ include_dir ? (arg->dir == ARG_IN ? "in" : "out") :
+ NULL);
+ }
+ wpabuf_printf(xml, "</%s>", type);
+}
+
+
+static void add_property(struct wpabuf *xml,
+ const struct wpa_dbus_property_desc *dsc)
+{
+ wpabuf_printf(xml, "<property name=\"%s\" type=\"%s\" access=\"%s\"/>",
+ dsc->dbus_property, dsc->type,
+ (dsc->access == R ? "read" :
+ (dsc->access == W ? "write" : "readwrite")));
+}
+
+
+static void extract_interfaces_methods(
+ struct dl_list *list, const struct wpa_dbus_method_desc *methods)
+{
+ const struct wpa_dbus_method_desc *dsc;
+ struct interfaces *iface;
+ for (dsc = methods; dsc && dsc->dbus_method; dsc++) {
+ iface = add_interface(list, dsc->dbus_interface);
+ if (iface)
+ add_entry(iface->xml, "method", dsc->dbus_method,
+ dsc->args, 1);
+ }
+}
+
+
+static void extract_interfaces_signals(
+ struct dl_list *list, const struct wpa_dbus_signal_desc *signals)
+{
+ const struct wpa_dbus_signal_desc *dsc;
+ struct interfaces *iface;
+ for (dsc = signals; dsc && dsc->dbus_signal; dsc++) {
+ iface = add_interface(list, dsc->dbus_interface);
+ if (iface)
+ add_entry(iface->xml, "signal", dsc->dbus_signal,
+ dsc->args, 0);
+ }
+}
+
+
+static void extract_interfaces_properties(
+ struct dl_list *list, const struct wpa_dbus_property_desc *properties)
+{
+ const struct wpa_dbus_property_desc *dsc;
+ struct interfaces *iface;
+ for (dsc = properties; dsc && dsc->dbus_property; dsc++) {
+ iface = add_interface(list, dsc->dbus_interface);
+ if (iface)
+ add_property(iface->xml, dsc);
+ }
+}
+
+
+/**
+ * extract_interfaces - Extract interfaces from methods, signals and props
+ * @list: Interface list to be filled
+ * @obj_dsc: Description of object from which interfaces will be extracted
+ *
+ * Iterates over all methods, signals, and properties registered with an
+ * object and collects all declared DBus interfaces and create interfaces'
+ * node in XML root node for each. Returned list elements contain interface
+ * name and XML node of corresponding interface.
+ */
+static void extract_interfaces(struct dl_list *list,
+ struct wpa_dbus_object_desc *obj_dsc)
+{
+ extract_interfaces_methods(list, obj_dsc->methods);
+ extract_interfaces_signals(list, obj_dsc->signals);
+ extract_interfaces_properties(list, obj_dsc->properties);
+}
+
+
+static void add_interfaces(struct dl_list *list, struct wpabuf *xml)
+{
+ struct interfaces *iface, *n;
+ dl_list_for_each_safe(iface, n, list, struct interfaces, list) {
+ if (wpabuf_len(iface->xml) + 20 < wpabuf_tailroom(xml)) {
+ wpabuf_put_buf(xml, iface->xml);
+ wpabuf_put_str(xml, "</interface>");
+ }
+ dl_list_del(&iface->list);
+ wpabuf_free(iface->xml);
+ os_free(iface->dbus_interface);
+ os_free(iface);
+ }
+}
+
+
+static void add_child_nodes(struct wpabuf *xml, DBusConnection *con,
+ const char *path)
+{
+ char **children;
+ int i;
+
+ /* add child nodes to introspection tree */
+ dbus_connection_list_registered(con, path, &children);
+ for (i = 0; children[i]; i++)
+ wpabuf_printf(xml, "<node name=\"%s\"/>", children[i]);
+ dbus_free_string_array(children);
+}
+
+
+static void add_introspectable_interface(struct wpabuf *xml)
+{
+ wpabuf_printf(xml, "<interface name=\"%s\">"
+ "<method name=\"%s\">"
+ "<arg name=\"data\" type=\"s\" direction=\"out\"/>"
+ "</method>"
+ "</interface>",
+ WPA_DBUS_INTROSPECTION_INTERFACE,
+ WPA_DBUS_INTROSPECTION_METHOD);
+}
+
+
+static void add_properties_interface(struct wpabuf *xml)
+{
+ wpabuf_printf(xml, "<interface name=\"%s\">",
+ WPA_DBUS_PROPERTIES_INTERFACE);
+
+ wpabuf_printf(xml, "<method name=\"%s\">", WPA_DBUS_PROPERTIES_GET);
+ add_arg(xml, "interface", "s", "in");
+ add_arg(xml, "propname", "s", "in");
+ add_arg(xml, "value", "v", "out");
+ wpabuf_put_str(xml, "</method>");
+
+ wpabuf_printf(xml, "<method name=\"%s\">", WPA_DBUS_PROPERTIES_GETALL);
+ add_arg(xml, "interface", "s", "in");
+ add_arg(xml, "props", "a{sv}", "out");
+ wpabuf_put_str(xml, "</method>");
+
+ wpabuf_printf(xml, "<method name=\"%s\">", WPA_DBUS_PROPERTIES_SET);
+ add_arg(xml, "interface", "s", "in");
+ add_arg(xml, "propname", "s", "in");
+ add_arg(xml, "value", "v", "in");
+ wpabuf_put_str(xml, "</method>");
+
+ wpabuf_put_str(xml, "</interface>");
+}
+
+
+static void add_wpas_interfaces(struct wpabuf *xml,
+ struct wpa_dbus_object_desc *obj_dsc)
+{
+ struct dl_list ifaces;
+ dl_list_init(&ifaces);
+ extract_interfaces(&ifaces, obj_dsc);
+ add_interfaces(&ifaces, xml);
+}
+
+
+/**
+ * wpa_dbus_introspect - Responds for Introspect calls on object
+ * @message: Message with Introspect call
+ * @obj_dsc: Object description on which Introspect was called
+ * Returns: Message with introspection result XML string as only argument
+ *
+ * Iterates over all methods, signals and properties registered with
+ * object and generates introspection data for the object as XML string.
+ */
+DBusMessage * wpa_dbus_introspect(DBusMessage *message,
+ struct wpa_dbus_object_desc *obj_dsc)
+{
+
+ DBusMessage *reply;
+ struct wpabuf *xml;
+
+ xml = wpabuf_alloc(4000);
+ if (xml == NULL)
+ return NULL;
+
+ wpabuf_put_str(xml, "<?xml version=\"1.0\"?>\n");
+ wpabuf_put_str(xml, DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE);
+ wpabuf_put_str(xml, "<node>");
+
+ add_introspectable_interface(xml);
+ add_properties_interface(xml);
+ add_wpas_interfaces(xml, obj_dsc);
+ add_child_nodes(xml, obj_dsc->connection,
+ dbus_message_get_path(message));
+
+ wpabuf_put_str(xml, "</node>\n");
+
+ reply = dbus_message_new_method_return(message);
+ if (reply) {
+ const char *intro_str = wpabuf_head(xml);
+ dbus_message_append_args(reply, DBUS_TYPE_STRING, &intro_str,
+ DBUS_TYPE_INVALID);
+ }
+ wpabuf_free(xml);
+
+ return reply;
+}
diff --git a/contrib/wpa/wpa_supplicant/ctrl_iface_dbus.c b/contrib/wpa/wpa_supplicant/dbus/dbus_old.c
index 8e69f4d..7f25bf0 100644
--- a/contrib/wpa/wpa_supplicant/ctrl_iface_dbus.c
+++ b/contrib/wpa/wpa_supplicant/dbus/dbus_old.c
@@ -13,263 +13,18 @@
*/
#include "includes.h"
+#include <dbus/dbus.h>
#include "common.h"
#include "eloop.h"
-#include "config.h"
-#include "wpa_supplicant_i.h"
#include "wps/wps.h"
-#include "ctrl_iface_dbus.h"
-#include "ctrl_iface_dbus_handlers.h"
-
-#define _DBUS_VERSION (DBUS_VERSION_MAJOR << 8 | DBUS_VERSION_MINOR)
-#define DBUS_VER(major, minor) ((major) << 8 | (minor))
-
-#if _DBUS_VERSION < DBUS_VER(1,1)
-#define dbus_watch_get_unix_fd dbus_watch_get_fd
-#endif
-
-
-struct ctrl_iface_dbus_priv {
- DBusConnection *con;
- int should_dispatch;
- struct wpa_global *global;
-
- u32 next_objid;
-};
-
-
-static void process_watch(struct ctrl_iface_dbus_priv *iface,
- DBusWatch *watch, eloop_event_type type)
-{
- dbus_connection_ref(iface->con);
-
- iface->should_dispatch = 0;
-
- if (type == EVENT_TYPE_READ)
- dbus_watch_handle(watch, DBUS_WATCH_READABLE);
- else if (type == EVENT_TYPE_WRITE)
- dbus_watch_handle(watch, DBUS_WATCH_WRITABLE);
- else if (type == EVENT_TYPE_EXCEPTION)
- dbus_watch_handle(watch, DBUS_WATCH_ERROR);
-
- if (iface->should_dispatch) {
- while (dbus_connection_get_dispatch_status(iface->con) ==
- DBUS_DISPATCH_DATA_REMAINS)
- dbus_connection_dispatch(iface->con);
- iface->should_dispatch = 0;
- }
-
- dbus_connection_unref(iface->con);
-}
-
-
-static void process_watch_exception(int sock, void *eloop_ctx, void *sock_ctx)
-{
- process_watch(eloop_ctx, sock_ctx, EVENT_TYPE_EXCEPTION);
-}
-
-
-static void process_watch_read(int sock, void *eloop_ctx, void *sock_ctx)
-{
- process_watch(eloop_ctx, sock_ctx, EVENT_TYPE_READ);
-}
-
-
-static void process_watch_write(int sock, void *eloop_ctx, void *sock_ctx)
-{
- process_watch(eloop_ctx, sock_ctx, EVENT_TYPE_WRITE);
-}
-
-
-static void connection_setup_add_watch(struct ctrl_iface_dbus_priv *iface,
- DBusWatch *watch)
-{
- unsigned int flags;
- int fd;
-
- if (!dbus_watch_get_enabled(watch))
- return;
-
- flags = dbus_watch_get_flags(watch);
- fd = dbus_watch_get_unix_fd(watch);
-
- eloop_register_sock(fd, EVENT_TYPE_EXCEPTION, process_watch_exception,
- iface, watch);
-
- if (flags & DBUS_WATCH_READABLE) {
- eloop_register_sock(fd, EVENT_TYPE_READ, process_watch_read,
- iface, watch);
- }
- if (flags & DBUS_WATCH_WRITABLE) {
- eloop_register_sock(fd, EVENT_TYPE_WRITE, process_watch_write,
- iface, watch);
- }
-
- dbus_watch_set_data(watch, iface, NULL);
-}
-
-
-static void connection_setup_remove_watch(struct ctrl_iface_dbus_priv *iface,
- DBusWatch *watch)
-{
- unsigned int flags;
- int fd;
-
- flags = dbus_watch_get_flags(watch);
- fd = dbus_watch_get_unix_fd(watch);
-
- eloop_unregister_sock(fd, EVENT_TYPE_EXCEPTION);
-
- if (flags & DBUS_WATCH_READABLE)
- eloop_unregister_sock(fd, EVENT_TYPE_READ);
- if (flags & DBUS_WATCH_WRITABLE)
- eloop_unregister_sock(fd, EVENT_TYPE_WRITE);
-
- dbus_watch_set_data(watch, NULL, NULL);
-}
-
-
-static dbus_bool_t add_watch(DBusWatch *watch, void *data)
-{
- connection_setup_add_watch(data, watch);
- return TRUE;
-}
-
-
-static void remove_watch(DBusWatch *watch, void *data)
-{
- connection_setup_remove_watch(data, watch);
-}
-
-
-static void watch_toggled(DBusWatch *watch, void *data)
-{
- if (dbus_watch_get_enabled(watch))
- add_watch(watch, data);
- else
- remove_watch(watch, data);
-}
-
-
-static void process_timeout(void *eloop_ctx, void *sock_ctx)
-{
- DBusTimeout *timeout = sock_ctx;
-
- dbus_timeout_handle(timeout);
-}
-
-
-static void connection_setup_add_timeout(struct ctrl_iface_dbus_priv *iface,
- DBusTimeout *timeout)
-{
- if (!dbus_timeout_get_enabled(timeout))
- return;
-
- eloop_register_timeout(0, dbus_timeout_get_interval(timeout) * 1000,
- process_timeout, iface, timeout);
-
- dbus_timeout_set_data(timeout, iface, NULL);
-}
-
-
-static void connection_setup_remove_timeout(struct ctrl_iface_dbus_priv *iface,
- DBusTimeout *timeout)
-{
- eloop_cancel_timeout(process_timeout, iface, timeout);
- dbus_timeout_set_data(timeout, NULL, NULL);
-}
-
-
-static dbus_bool_t add_timeout(DBusTimeout *timeout, void *data)
-{
- if (!dbus_timeout_get_enabled(timeout))
- return TRUE;
-
- connection_setup_add_timeout(data, timeout);
-
- return TRUE;
-}
-
-
-static void remove_timeout(DBusTimeout *timeout, void *data)
-{
- connection_setup_remove_timeout(data, timeout);
-}
-
-
-static void timeout_toggled(DBusTimeout *timeout, void *data)
-{
- if (dbus_timeout_get_enabled(timeout))
- add_timeout(timeout, data);
- else
- remove_timeout(timeout, data);
-}
-
-
-static void process_wakeup_main(int sig, void *eloop_ctx, void *signal_ctx)
-{
- struct ctrl_iface_dbus_priv *iface = signal_ctx;
-
- if (sig != SIGPOLL || !iface->con)
- return;
-
- if (dbus_connection_get_dispatch_status(iface->con) !=
- DBUS_DISPATCH_DATA_REMAINS)
- return;
-
- /* Only dispatch once - we do not want to starve other events */
- dbus_connection_ref(iface->con);
- dbus_connection_dispatch(iface->con);
- dbus_connection_unref(iface->con);
-}
-
-
-/**
- * wakeup_main - Attempt to wake our mainloop up
- * @data: dbus control interface private data
- *
- * Try to wake up the main eloop so it will process
- * dbus events that may have happened.
- */
-static void wakeup_main(void *data)
-{
- struct ctrl_iface_dbus_priv *iface = data;
-
- /* Use SIGPOLL to break out of the eloop select() */
- raise(SIGPOLL);
- iface->should_dispatch = 1;
-}
-
-
-/**
- * connection_setup_wakeup_main - Tell dbus about our wakeup_main function
- * @iface: dbus control interface private data
- * Returns: 0 on success, -1 on failure
- *
- * Register our wakeup_main handler with dbus
- */
-static int connection_setup_wakeup_main(struct ctrl_iface_dbus_priv *iface)
-{
- if (eloop_register_signal(SIGPOLL, process_wakeup_main, iface))
- return -1;
-
- dbus_connection_set_wakeup_main_function(iface->con, wakeup_main,
- iface, NULL);
-
- return 0;
-}
-
-
-/**
- * wpa_supplicant_dbus_next_objid - Return next available object id
- * @iface: dbus control interface private data
- * Returns: Object id
- */
-u32 wpa_supplicant_dbus_next_objid (struct ctrl_iface_dbus_priv *iface)
-{
- return iface->next_objid++;
-}
+#include "../config.h"
+#include "../wpa_supplicant_i.h"
+#include "../bss.h"
+#include "dbus_old.h"
+#include "dbus_old_handlers.h"
+#include "dbus_common.h"
+#include "dbus_common_i.h"
/**
@@ -299,7 +54,7 @@ char * wpas_dbus_decompose_object_path(const char *path, char **network,
if ((path + dev_path_prefix_len)[0] == '\0')
return NULL;
- obj_path_only = strdup(path);
+ obj_path_only = os_strdup(path);
if (obj_path_only == NULL)
return NULL;
@@ -316,13 +71,13 @@ char * wpas_dbus_decompose_object_path(const char *path, char **network,
strlen(WPAS_DBUS_NETWORKS_PART "/");
*network = NULL;
if (strlen(net_name))
- *network = strdup(net_name);
+ *network = os_strdup(net_name);
} else if (bssid && bssid_part) {
/* Deal with a request for a scanned BSSID */
const char *bssid_name = bssid_part +
strlen(WPAS_DBUS_BSSIDS_PART "/");
if (strlen(bssid_name))
- *bssid = strdup(bssid_name);
+ *bssid = os_strdup(bssid_name);
else
*bssid = NULL;
}
@@ -421,45 +176,23 @@ static DBusMessage * wpas_dispatch_network_method(DBusMessage *message,
*/
static DBusMessage * wpas_dispatch_bssid_method(DBusMessage *message,
struct wpa_supplicant *wpa_s,
- const char *bssid)
+ const char *bssid_txt)
{
- DBusMessage *reply = NULL;
- const char *method = dbus_message_get_member(message);
- struct wpa_scan_res *res = NULL;
- size_t i;
+ u8 bssid[ETH_ALEN];
+ struct wpa_bss *bss;
- /* Ensure we actually have scan data */
- if (wpa_s->scan_res == NULL &&
- wpa_supplicant_get_scan_results(wpa_s) < 0) {
- reply = wpas_dbus_new_invalid_bssid_error(message);
- goto out;
- }
+ if (hexstr2bin(bssid_txt, bssid, ETH_ALEN) < 0)
+ return wpas_dbus_new_invalid_bssid_error(message);
- /* Find the bssid's scan data */
- for (i = 0; i < wpa_s->scan_res->num; i++) {
- struct wpa_scan_res *search_res = wpa_s->scan_res->res[i];
- char mac_str[18];
-
- memset(mac_str, 0, sizeof(mac_str));
- snprintf(mac_str, sizeof(mac_str) - 1, WPAS_DBUS_BSSID_FORMAT,
- MAC2STR(search_res->bssid));
- if (!strcmp(bssid, mac_str)) {
- res = search_res;
- break;
- }
- }
-
- if (!res) {
- reply = wpas_dbus_new_invalid_bssid_error(message);
- goto out;
- }
+ bss = wpa_bss_get_bssid(wpa_s, bssid);
+ if (bss == NULL)
+ return wpas_dbus_new_invalid_bssid_error(message);
/* Dispatch the method call against the scanned bssid */
- if (!strcmp(method, "properties"))
- reply = wpas_dbus_bssid_properties(message, wpa_s, res);
+ if (os_strcmp(dbus_message_get_member(message), "properties") == 0)
+ return wpas_dbus_bssid_properties(message, wpa_s, bss);
-out:
- return reply;
+ return NULL;
}
@@ -546,6 +279,14 @@ static DBusHandlerResult wpas_iface_message_handler(DBusConnection *connection,
reply = wpas_dbus_iface_set_blobs(message, wpa_s);
else if (!strcmp(method, "removeBlobs"))
reply = wpas_dbus_iface_remove_blobs(message, wpa_s);
+#ifdef CONFIG_WPS
+ else if (!os_strcmp(method, "wpsPbc"))
+ reply = wpas_dbus_iface_wps_pbc(message, wpa_s);
+ else if (!os_strcmp(method, "wpsPin"))
+ reply = wpas_dbus_iface_wps_pin(message, wpa_s);
+ else if (!os_strcmp(method, "wpsReg"))
+ reply = wpas_dbus_iface_wps_reg(message, wpa_s);
+#endif /* CONFIG_WPS */
}
/* If the message was handled, send back the reply */
@@ -556,9 +297,9 @@ static DBusHandlerResult wpas_iface_message_handler(DBusConnection *connection,
}
out:
- free(iface_obj_path);
- free(network);
- free(bssid);
+ os_free(iface_obj_path);
+ os_free(network);
+ os_free(bssid);
return reply ? DBUS_HANDLER_RESULT_HANDLED :
DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
@@ -578,7 +319,7 @@ out:
static DBusHandlerResult wpas_message_handler(DBusConnection *connection,
DBusMessage *message, void *user_data)
{
- struct ctrl_iface_dbus_priv *ctrl_iface = user_data;
+ struct wpas_dbus_priv *ctrl_iface = user_data;
const char *method;
const char *path;
const char *msg_interface;
@@ -632,31 +373,19 @@ static DBusHandlerResult wpas_message_handler(DBusConnection *connection,
*/
void wpa_supplicant_dbus_notify_scan_results(struct wpa_supplicant *wpa_s)
{
- struct ctrl_iface_dbus_priv *iface = wpa_s->global->dbus_ctrl_iface;
+ struct wpas_dbus_priv *iface = wpa_s->global->dbus;
DBusMessage *_signal;
- const char *path;
/* Do nothing if the control interface is not turned on */
if (iface == NULL)
return;
- path = wpa_supplicant_get_dbus_path(wpa_s);
- if (path == NULL) {
- perror("wpa_supplicant_dbus_notify_scan_results[dbus]: "
- "interface didn't have a dbus path");
- wpa_printf(MSG_ERROR,
- "wpa_supplicant_dbus_notify_scan_results[dbus]: "
- "interface didn't have a dbus path; can't send "
- "scan result signal.");
- return;
- }
- _signal = dbus_message_new_signal(path, WPAS_DBUS_IFACE_INTERFACE,
+ _signal = dbus_message_new_signal(wpa_s->dbus_path,
+ WPAS_DBUS_IFACE_INTERFACE,
"ScanResultsAvailable");
if (_signal == NULL) {
- perror("wpa_supplicant_dbus_notify_scan_results[dbus]: "
- "couldn't create dbus signal; likely out of memory");
- wpa_printf(MSG_ERROR, "dbus control interface: not enough "
- "memory to send scan results signal.");
+ wpa_printf(MSG_ERROR, "dbus: Not enough memory to send scan "
+ "results signal");
return;
}
dbus_connection_send(iface->con, _signal, NULL);
@@ -674,18 +403,20 @@ void wpa_supplicant_dbus_notify_scan_results(struct wpa_supplicant *wpa_s)
* Notify listeners that wpa_supplicant has changed state
*/
void wpa_supplicant_dbus_notify_state_change(struct wpa_supplicant *wpa_s,
- wpa_states new_state,
- wpa_states old_state)
+ enum wpa_states new_state,
+ enum wpa_states old_state)
{
- struct ctrl_iface_dbus_priv *iface;
+ struct wpas_dbus_priv *iface;
DBusMessage *_signal = NULL;
- const char *path;
const char *new_state_str, *old_state_str;
+ if (wpa_s->dbus_path == NULL)
+ return; /* Skip signal since D-Bus setup is not yet ready */
+
/* Do nothing if the control interface is not turned on */
if (wpa_s->global == NULL)
return;
- iface = wpa_s->global->dbus_ctrl_iface;
+ iface = wpa_s->global->dbus;
if (iface == NULL)
return;
@@ -693,36 +424,23 @@ void wpa_supplicant_dbus_notify_state_change(struct wpa_supplicant *wpa_s,
if (new_state == old_state)
return;
- path = wpa_supplicant_get_dbus_path(wpa_s);
- if (path == NULL) {
- perror("wpa_supplicant_dbus_notify_state_change[dbus]: "
- "interface didn't have a dbus path");
- wpa_printf(MSG_ERROR,
- "wpa_supplicant_dbus_notify_state_change[dbus]: "
- "interface didn't have a dbus path; can't send "
- "signal.");
- return;
- }
- _signal = dbus_message_new_signal(path, WPAS_DBUS_IFACE_INTERFACE,
+ _signal = dbus_message_new_signal(wpa_s->dbus_path,
+ WPAS_DBUS_IFACE_INTERFACE,
"StateChange");
if (_signal == NULL) {
- perror("wpa_supplicant_dbus_notify_state_change[dbus]: "
- "couldn't create dbus signal; likely out of memory");
wpa_printf(MSG_ERROR,
- "wpa_supplicant_dbus_notify_state_change[dbus]: "
- "couldn't create dbus signal; likely out of "
- "memory.");
+ "dbus: wpa_supplicant_dbus_notify_state_change: "
+ "could not create dbus signal; likely out of "
+ "memory");
return;
}
new_state_str = wpa_supplicant_state_txt(new_state);
old_state_str = wpa_supplicant_state_txt(old_state);
if (new_state_str == NULL || old_state_str == NULL) {
- perror("wpa_supplicant_dbus_notify_state_change[dbus]: "
- "couldn't convert state strings");
wpa_printf(MSG_ERROR,
- "wpa_supplicant_dbus_notify_state_change[dbus]: "
- "couldn't convert state strings.");
+ "dbus: wpa_supplicant_dbus_notify_state_change: "
+ "Could not convert state strings");
goto out;
}
@@ -730,12 +448,10 @@ void wpa_supplicant_dbus_notify_state_change(struct wpa_supplicant *wpa_s,
DBUS_TYPE_STRING, &new_state_str,
DBUS_TYPE_STRING, &old_state_str,
DBUS_TYPE_INVALID)) {
- perror("wpa_supplicant_dbus_notify_state_change[dbus]: "
- "not enough memory to construct state change signal.");
wpa_printf(MSG_ERROR,
- "wpa_supplicant_dbus_notify_state_change[dbus]: "
- "not enough memory to construct state change "
- "signal.");
+ "dbus: wpa_supplicant_dbus_notify_state_change: "
+ "Not enough memory to construct state change "
+ "signal");
goto out;
}
@@ -755,32 +471,20 @@ out:
*/
void wpa_supplicant_dbus_notify_scanning(struct wpa_supplicant *wpa_s)
{
- struct ctrl_iface_dbus_priv *iface = wpa_s->global->dbus_ctrl_iface;
+ struct wpas_dbus_priv *iface = wpa_s->global->dbus;
DBusMessage *_signal;
- const char *path;
dbus_bool_t scanning = wpa_s->scanning ? TRUE : FALSE;
/* Do nothing if the control interface is not turned on */
if (iface == NULL)
return;
- path = wpa_supplicant_get_dbus_path(wpa_s);
- if (path == NULL) {
- perror("wpa_supplicant_dbus_notify_scanning[dbus]: interface "
- "didn't have a dbus path");
- wpa_printf(MSG_ERROR,
- "%s[dbus]: interface didn't have a dbus path; "
- "can't send scanning signal.", __FUNCTION__);
- return;
- }
- _signal = dbus_message_new_signal(path, WPAS_DBUS_IFACE_INTERFACE,
+ _signal = dbus_message_new_signal(wpa_s->dbus_path,
+ WPAS_DBUS_IFACE_INTERFACE,
"Scanning");
if (_signal == NULL) {
- perror("wpa_supplicant_dbus_notify_scanning[dbus]: couldn't "
- "create dbus signal; likely out of memory");
- wpa_printf(MSG_ERROR, "%s[dbus]: dbus control interface: not "
- "enough memory to send scan results signal.",
- __FUNCTION__);
+ wpa_printf(MSG_ERROR, "dbus: Not enough memory to send scan "
+ "results signal");
return;
}
@@ -789,10 +493,8 @@ void wpa_supplicant_dbus_notify_scanning(struct wpa_supplicant *wpa_s)
DBUS_TYPE_INVALID)) {
dbus_connection_send(iface->con, _signal, NULL);
} else {
- perror("wpa_supplicant_dbus_notify_scanning[dbus]: not enough "
- "memory to construct signal.");
- wpa_printf(MSG_ERROR, "%s[dbus]: not enough memory to "
- "construct signal.", __FUNCTION__);
+ wpa_printf(MSG_ERROR, "dbus: Not enough memory to construct "
+ "signal");
}
dbus_message_unref(_signal);
}
@@ -802,36 +504,24 @@ void wpa_supplicant_dbus_notify_scanning(struct wpa_supplicant *wpa_s)
void wpa_supplicant_dbus_notify_wps_cred(struct wpa_supplicant *wpa_s,
const struct wps_credential *cred)
{
- struct ctrl_iface_dbus_priv *iface;
+ struct wpas_dbus_priv *iface;
DBusMessage *_signal = NULL;
- const char *path;
/* Do nothing if the control interface is not turned on */
if (wpa_s->global == NULL)
return;
- iface = wpa_s->global->dbus_ctrl_iface;
+ iface = wpa_s->global->dbus;
if (iface == NULL)
return;
- path = wpa_supplicant_get_dbus_path(wpa_s);
- if (path == NULL) {
- perror("wpa_supplicant_dbus_notify_wps_cred[dbus]: "
- "interface didn't have a dbus path");
- wpa_printf(MSG_ERROR,
- "wpa_supplicant_dbus_notify_wps_cred[dbus]: "
- "interface didn't have a dbus path; can't send "
- "signal.");
- return;
- }
- _signal = dbus_message_new_signal(path, WPAS_DBUS_IFACE_INTERFACE,
+ _signal = dbus_message_new_signal(wpa_s->dbus_path,
+ WPAS_DBUS_IFACE_INTERFACE,
"WpsCred");
if (_signal == NULL) {
- perror("wpa_supplicant_dbus_notify_wps_cred[dbus]: "
- "couldn't create dbus signal; likely out of memory");
wpa_printf(MSG_ERROR,
- "wpa_supplicant_dbus_notify_wps_cred[dbus]: "
- "couldn't create dbus signal; likely out of "
- "memory.");
+ "dbus: wpa_supplicant_dbus_notify_wps_cred: "
+ "Could not create dbus signal; likely out of "
+ "memory");
return;
}
@@ -839,11 +529,9 @@ void wpa_supplicant_dbus_notify_wps_cred(struct wpa_supplicant *wpa_s,
DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
&cred->cred_attr, cred->cred_attr_len,
DBUS_TYPE_INVALID)) {
- perror("wpa_supplicant_dbus_notify_wps_cred[dbus]: "
- "not enough memory to construct signal.");
wpa_printf(MSG_ERROR,
- "wpa_supplicant_dbus_notify_wps_cred[dbus]: "
- "not enough memory to construct signal.");
+ "dbus: wpa_supplicant_dbus_notify_wps_cred: "
+ "Not enough memory to construct signal");
goto out;
}
@@ -861,109 +549,28 @@ void wpa_supplicant_dbus_notify_wps_cred(struct wpa_supplicant *wpa_s,
/**
- * integrate_with_eloop - Register our mainloop integration with dbus
- * @connection: connection to the system message bus
- * @iface: a dbus control interface data structure
- * Returns: 0 on success, -1 on failure
- *
- * We register our mainloop integration functions with dbus here.
- */
-static int integrate_with_eloop(DBusConnection *connection,
- struct ctrl_iface_dbus_priv *iface)
-{
- if (!dbus_connection_set_watch_functions(connection, add_watch,
- remove_watch, watch_toggled,
- iface, NULL)) {
- perror("dbus_connection_set_watch_functions[dbus]");
- wpa_printf(MSG_ERROR, "Not enough memory to set up dbus.");
- return -1;
- }
-
- if (!dbus_connection_set_timeout_functions(connection, add_timeout,
- remove_timeout,
- timeout_toggled, iface,
- NULL)) {
- perror("dbus_connection_set_timeout_functions[dbus]");
- wpa_printf(MSG_ERROR, "Not enough memory to set up dbus.");
- return -1;
- }
-
- if (connection_setup_wakeup_main(iface) < 0) {
- perror("connection_setup_wakeup_main[dbus]");
- wpa_printf(MSG_ERROR, "Could not setup main wakeup function.");
- return -1;
- }
-
- return 0;
-}
-
-
-/**
- * dispatch_initial_dbus_messages - Dispatch initial dbus messages after
- * claiming bus name
- * @eloop_ctx: the DBusConnection to dispatch on
- * @timeout_ctx: unused
- *
- * If clients are quick to notice that wpa_supplicant claimed its bus name,
- * there may have been messages that came in before initialization was
- * all finished. Dispatch those here.
- */
-static void dispatch_initial_dbus_messages(void *eloop_ctx, void *timeout_ctx)
-{
- DBusConnection *con = eloop_ctx;
-
- while (dbus_connection_get_dispatch_status(con) ==
- DBUS_DISPATCH_DATA_REMAINS)
- dbus_connection_dispatch(con);
-}
-
-
-/**
* wpa_supplicant_dbus_ctrl_iface_init - Initialize dbus control interface
* @global: Pointer to global data from wpa_supplicant_init()
- * Returns: Pointer to dbus_ctrl_iface date or %NULL on failure
+ * Returns: 0 on success, -1 on failure
*
* Initialize the dbus control interface and start receiving commands from
* external programs over the bus.
*/
-struct ctrl_iface_dbus_priv *
-wpa_supplicant_dbus_ctrl_iface_init(struct wpa_global *global)
+int wpa_supplicant_dbus_ctrl_iface_init(struct wpas_dbus_priv *iface)
{
- struct ctrl_iface_dbus_priv *iface;
DBusError error;
int ret = -1;
DBusObjectPathVTable wpas_vtable = {
NULL, &wpas_message_handler, NULL, NULL, NULL, NULL
};
- iface = os_zalloc(sizeof(struct ctrl_iface_dbus_priv));
- if (iface == NULL)
- return NULL;
-
- iface->global = global;
-
- /* Get a reference to the system bus */
- dbus_error_init(&error);
- iface->con = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
- dbus_error_free(&error);
- if (!iface->con) {
- perror("dbus_bus_get[ctrl_iface_dbus]");
- wpa_printf(MSG_ERROR, "Could not acquire the system bus.");
- goto fail;
- }
-
- /* Tell dbus about our mainloop integration functions */
- if (integrate_with_eloop(iface->con, iface))
- goto fail;
-
/* Register the message handler for the global dbus interface */
if (!dbus_connection_register_object_path(iface->con,
WPAS_DBUS_PATH, &wpas_vtable,
iface)) {
- perror("dbus_connection_register_object_path[dbus]");
- wpa_printf(MSG_ERROR, "Could not set up DBus message "
- "handler.");
- goto fail;
+ wpa_printf(MSG_ERROR, "dbus: Could not set up message "
+ "handler");
+ return -1;
}
/* Register our service with the message bus */
@@ -976,67 +583,23 @@ wpa_supplicant_dbus_ctrl_iface_init(struct wpa_global *global)
case DBUS_REQUEST_NAME_REPLY_EXISTS:
case DBUS_REQUEST_NAME_REPLY_IN_QUEUE:
case DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER:
- perror("dbus_bus_request_name[dbus]");
- wpa_printf(MSG_ERROR, "Could not request DBus service name: "
- "already registered.");
+ wpa_printf(MSG_ERROR, "dbus: Could not request service name: "
+ "already registered");
break;
default:
- perror("dbus_bus_request_name[dbus]");
- wpa_printf(MSG_ERROR, "Could not request DBus service name: "
- "%s %s.", error.name, error.message);
+ wpa_printf(MSG_ERROR, "dbus: Could not request service name: "
+ "%s %s", error.name, error.message);
break;
}
dbus_error_free(&error);
if (ret != 0)
- goto fail;
+ return -1;
wpa_printf(MSG_DEBUG, "Providing DBus service '" WPAS_DBUS_SERVICE
"'.");
- /*
- * Dispatch initial DBus messages that may have come in since the bus
- * name was claimed above. Happens when clients are quick to notice the
- * wpa_supplicant service.
- *
- * FIXME: is there a better solution to this problem?
- */
- eloop_register_timeout(0, 50, dispatch_initial_dbus_messages,
- iface->con, NULL);
-
- return iface;
-
-fail:
- wpa_supplicant_dbus_ctrl_iface_deinit(iface);
- return NULL;
-}
-
-
-/**
- * wpa_supplicant_dbus_ctrl_iface_deinit - Deinitialize dbus ctrl interface
- * @iface: Pointer to dbus private data from
- * wpa_supplicant_dbus_ctrl_iface_init()
- *
- * Deinitialize the dbus control interface that was initialized with
- * wpa_supplicant_dbus_ctrl_iface_init().
- */
-void wpa_supplicant_dbus_ctrl_iface_deinit(struct ctrl_iface_dbus_priv *iface)
-{
- if (iface == NULL)
- return;
-
- if (iface->con) {
- eloop_cancel_timeout(dispatch_initial_dbus_messages,
- iface->con, NULL);
- dbus_connection_set_watch_functions(iface->con, NULL, NULL,
- NULL, NULL, NULL);
- dbus_connection_set_timeout_functions(iface->con, NULL, NULL,
- NULL, NULL, NULL);
- dbus_connection_unref(iface->con);
- }
-
- memset(iface, 0, sizeof(struct ctrl_iface_dbus_priv));
- free(iface);
+ return 0;
}
@@ -1049,49 +612,37 @@ void wpa_supplicant_dbus_ctrl_iface_deinit(struct ctrl_iface_dbus_priv *iface)
*/
int wpas_dbus_register_iface(struct wpa_supplicant *wpa_s)
{
- struct ctrl_iface_dbus_priv *ctrl_iface =
- wpa_s->global->dbus_ctrl_iface;
+ struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus;
DBusConnection * con;
u32 next;
DBusObjectPathVTable vtable = {
NULL, &wpas_iface_message_handler, NULL, NULL, NULL, NULL
};
- char *path;
- int ret = -1;
/* Do nothing if the control interface is not turned on */
if (ctrl_iface == NULL)
return 0;
con = ctrl_iface->con;
- next = wpa_supplicant_dbus_next_objid(ctrl_iface);
+ next = ctrl_iface->next_objid++;
/* Create and set the interface's object path */
- path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
- if (path == NULL)
+ wpa_s->dbus_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
+ if (wpa_s->dbus_path == NULL)
return -1;
- snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
- WPAS_DBUS_PATH_INTERFACES "/%u",
- next);
- if (wpa_supplicant_set_dbus_path(wpa_s, path)) {
- wpa_printf(MSG_DEBUG,
- "Failed to set dbus path for interface %s",
- wpa_s->ifname);
- goto out;
- }
+ os_snprintf(wpa_s->dbus_path, WPAS_DBUS_OBJECT_PATH_MAX,
+ WPAS_DBUS_PATH_INTERFACES "/%u",
+ next);
/* Register the message handler for the interface functions */
- if (!dbus_connection_register_fallback(con, path, &vtable, wpa_s)) {
- perror("wpas_dbus_register_iface [dbus]");
- wpa_printf(MSG_ERROR, "Could not set up DBus message "
- "handler for interface %s.", wpa_s->ifname);
- goto out;
+ if (!dbus_connection_register_fallback(con, wpa_s->dbus_path, &vtable,
+ wpa_s)) {
+ wpa_printf(MSG_ERROR, "dbus: Could not set up message "
+ "handler for interface %s", wpa_s->ifname);
+ return -1;
}
- ret = 0;
-out:
- free(path);
- return ret;
+ return 0;
}
@@ -1104,24 +655,21 @@ out:
*/
int wpas_dbus_unregister_iface(struct wpa_supplicant *wpa_s)
{
- struct ctrl_iface_dbus_priv *ctrl_iface;
+ struct wpas_dbus_priv *ctrl_iface;
DBusConnection *con;
- const char *path;
/* Do nothing if the control interface is not turned on */
if (wpa_s == NULL || wpa_s->global == NULL)
return 0;
- ctrl_iface = wpa_s->global->dbus_ctrl_iface;
+ ctrl_iface = wpa_s->global->dbus;
if (ctrl_iface == NULL)
return 0;
con = ctrl_iface->con;
- path = wpa_supplicant_get_dbus_path(wpa_s);
-
- if (!dbus_connection_unregister_object_path(con, path))
+ if (!dbus_connection_unregister_object_path(con, wpa_s->dbus_path))
return -1;
- free(wpa_s->dbus_path);
+ os_free(wpa_s->dbus_path);
wpa_s->dbus_path = NULL;
return 0;
@@ -1145,33 +693,3 @@ struct wpa_supplicant * wpa_supplicant_get_iface_by_dbus_path(
}
return NULL;
}
-
-
-/**
- * wpa_supplicant_set_dbus_path - Assign a dbus path to an interface
- * @wpa_s: wpa_supplicant interface structure
- * @path: dbus path to set on the interface
- * Returns: 0 on succes, -1 on error
- */
-int wpa_supplicant_set_dbus_path(struct wpa_supplicant *wpa_s,
- const char *path)
-{
- u32 len = strlen (path);
- if (len >= WPAS_DBUS_OBJECT_PATH_MAX)
- return -1;
- if (wpa_s->dbus_path)
- return -1;
- wpa_s->dbus_path = strdup(path);
- return 0;
-}
-
-
-/**
- * wpa_supplicant_get_dbus_path - Get an interface's dbus path
- * @wpa_s: %wpa_supplicant interface structure
- * Returns: Interface's dbus object path, or %NULL on error
- */
-const char * wpa_supplicant_get_dbus_path(struct wpa_supplicant *wpa_s)
-{
- return wpa_s->dbus_path;
-}
diff --git a/contrib/wpa/wpa_supplicant/ctrl_iface_dbus.h b/contrib/wpa/wpa_supplicant/dbus/dbus_old.h
index 059a373..a9840c2 100644
--- a/contrib/wpa/wpa_supplicant/ctrl_iface_dbus.h
+++ b/contrib/wpa/wpa_supplicant/dbus/dbus_old.h
@@ -19,18 +19,6 @@ struct wps_credential;
#ifdef CONFIG_CTRL_IFACE_DBUS
-#ifndef SIGPOLL
-#ifdef SIGIO
-/*
- * If we do not have SIGPOLL, try to use SIGIO instead. This is needed for
- * FreeBSD.
- */
-#define SIGPOLL SIGIO
-#endif
-#endif
-
-#include <dbus/dbus.h>
-
#define WPAS_DBUS_OBJECT_PATH_MAX 150
#define WPAS_DBUS_SERVICE "fi.epitest.hostap.WPASupplicant"
@@ -74,19 +62,24 @@ struct wps_credential;
#define WPAS_ERROR_REMOVE_NETWORK_ERROR \
WPAS_DBUS_IFACE_INTERFACE ".RemoveNetworkError"
+#define WPAS_ERROR_WPS_PBC_ERROR \
+ WPAS_DBUS_IFACE_INTERFACE ".WpsPbcError"
+#define WPAS_ERROR_WPS_PIN_ERROR \
+ WPAS_DBUS_IFACE_INTERFACE ".WpsPinError"
+#define WPAS_ERROR_WPS_REG_ERROR \
+ WPAS_DBUS_IFACE_INTERFACE ".WpsRegError"
+
#define WPAS_DBUS_BSSID_FORMAT "%02x%02x%02x%02x%02x%02x"
struct wpa_global;
struct wpa_supplicant;
-struct ctrl_iface_dbus_priv *
-wpa_supplicant_dbus_ctrl_iface_init(struct wpa_global *global);
-void wpa_supplicant_dbus_ctrl_iface_deinit(struct ctrl_iface_dbus_priv *iface);
+int wpa_supplicant_dbus_ctrl_iface_init(struct wpas_dbus_priv *iface);
void wpa_supplicant_dbus_notify_scan_results(struct wpa_supplicant *wpa_s);
void wpa_supplicant_dbus_notify_scanning(struct wpa_supplicant *wpa_s);
void wpa_supplicant_dbus_notify_state_change(struct wpa_supplicant *wpa_s,
- wpa_states new_state,
- wpa_states old_state);
+ enum wpa_states new_state,
+ enum wpa_states old_state);
void wpa_supplicant_dbus_notify_wps_cred(struct wpa_supplicant *wpa_s,
const struct wps_credential *cred);
@@ -98,30 +91,11 @@ int wpas_dbus_unregister_iface(struct wpa_supplicant *wpa_s);
/* Methods internal to the dbus control interface */
-u32 wpa_supplicant_dbus_next_objid(struct ctrl_iface_dbus_priv *iface);
-
-int wpa_supplicant_set_dbus_path(struct wpa_supplicant *wpa_s,
- const char *path);
-const char *wpa_supplicant_get_dbus_path(struct wpa_supplicant *wpa_s);
struct wpa_supplicant * wpa_supplicant_get_iface_by_dbus_path(
struct wpa_global *global, const char *path);
-DBusMessage * wpas_dbus_new_invalid_iface_error(DBusMessage *message);
-DBusMessage * wpas_dbus_new_invalid_network_error(DBusMessage *message);
-
#else /* CONFIG_CTRL_IFACE_DBUS */
-static inline struct ctrl_iface_dbus_priv *
-wpa_supplicant_dbus_ctrl_iface_init(struct wpa_global *global)
-{
- return (struct ctrl_iface_dbus_priv *) 1;
-}
-
-static inline void
-wpa_supplicant_dbus_ctrl_iface_deinit(struct ctrl_iface_dbus_priv *iface)
-{
-}
-
static inline void
wpa_supplicant_dbus_notify_scan_results(struct wpa_supplicant *wpa_s)
{
@@ -132,12 +106,7 @@ wpa_supplicant_dbus_notify_scanning(struct wpa_supplicant *wpa_s)
{
}
-static inline void
-wpa_supplicant_dbus_notify_state_change(struct wpa_supplicant *wpa_s,
- wpa_states new_state,
- wpa_states old_state)
-{
-}
+#define wpa_supplicant_dbus_notify_state_change(w,n,o) do { } while (0)
static inline void
wpa_supplicant_dbus_notify_wps_cred(struct wpa_supplicant *wpa_s,
diff --git a/contrib/wpa/wpa_supplicant/ctrl_iface_dbus_handlers.c b/contrib/wpa/wpa_supplicant/dbus/dbus_old_handlers.c
index d3250d3..d914697 100644
--- a/contrib/wpa/wpa_supplicant/ctrl_iface_dbus_handlers.c
+++ b/contrib/wpa/wpa_supplicant/dbus/dbus_old_handlers.c
@@ -13,18 +13,23 @@
*/
#include "includes.h"
+#include <dbus/dbus.h>
#include "common.h"
-#include "config.h"
-#include "wpa_supplicant_i.h"
-#include "ctrl_iface_dbus.h"
-#include "ctrl_iface_dbus_handlers.h"
#include "eap_peer/eap_methods.h"
-#include "dbus_dict_helpers.h"
-#include "ieee802_11_defs.h"
-#include "wpas_glue.h"
+#include "common/ieee802_11_defs.h"
#include "eapol_supp/eapol_supp_sm.h"
-#include "wpa.h"
+#include "rsn_supp/wpa.h"
+#include "../config.h"
+#include "../wpa_supplicant_i.h"
+#include "../driver_i.h"
+#include "../notify.h"
+#include "../wpas_glue.h"
+#include "../bss.h"
+#include "../scan.h"
+#include "dbus_old.h"
+#include "dbus_old_handlers.h"
+#include "dbus_dict_helpers.h"
extern int wpa_debug_level;
extern int wpa_debug_show_keys;
@@ -37,14 +42,14 @@ extern int wpa_debug_timestamp;
*
* Convenience function to create and return an invalid options error
*/
-static DBusMessage * wpas_dbus_new_invalid_opts_error(DBusMessage *message,
- const char *arg)
+DBusMessage * wpas_dbus_new_invalid_opts_error(DBusMessage *message,
+ const char *arg)
{
DBusMessage *reply;
reply = dbus_message_new_error(message, WPAS_ERROR_INVALID_OPTS,
- "Did not receive correct message "
- "arguments.");
+ "Did not receive correct message "
+ "arguments.");
if (arg != NULL)
dbus_message_append_args(reply, DBUS_TYPE_STRING, &arg,
DBUS_TYPE_INVALID);
@@ -61,7 +66,7 @@ static DBusMessage * wpas_dbus_new_invalid_opts_error(DBusMessage *message,
*
* Convenience function to create and return a success reply message
*/
-static DBusMessage * wpas_dbus_new_success_reply(DBusMessage *message)
+DBusMessage * wpas_dbus_new_success_reply(DBusMessage *message)
{
DBusMessage *reply;
unsigned int success = 1;
@@ -73,15 +78,6 @@ static DBusMessage * wpas_dbus_new_success_reply(DBusMessage *message)
}
-static void wpas_dbus_free_wpa_interface(struct wpa_interface *iface)
-{
- free((char *) iface->driver);
- free((char *) iface->driver_param);
- free((char *) iface->confname);
- free((char *) iface->bridge_ifname);
-}
-
-
/**
* wpas_dbus_global_add_interface - Request registration of a network interface
* @message: Pointer to incoming dbus message
@@ -96,13 +92,14 @@ static void wpas_dbus_free_wpa_interface(struct wpa_interface *iface)
DBusMessage * wpas_dbus_global_add_interface(DBusMessage *message,
struct wpa_global *global)
{
- struct wpa_interface iface;
char *ifname = NULL;
+ char *driver = NULL;
+ char *driver_param = NULL;
+ char *confname = NULL;
+ char *bridge_ifname = NULL;
DBusMessage *reply = NULL;
DBusMessageIter iter;
- memset(&iface, 0, sizeof(iface));
-
dbus_message_iter_init(message, &iter);
/* First argument: interface name (DBUS_TYPE_STRING)
@@ -111,9 +108,8 @@ DBusMessage * wpas_dbus_global_add_interface(DBusMessage *message,
if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
goto error;
dbus_message_iter_get_basic(&iter, &ifname);
- if (!strlen(ifname))
+ if (!os_strlen(ifname))
goto error;
- iface.ifname = ifname;
/* Second argument: dict of options */
if (dbus_message_iter_next(&iter)) {
@@ -127,29 +123,32 @@ DBusMessage * wpas_dbus_global_add_interface(DBusMessage *message,
goto error;
if (!strcmp(entry.key, "driver") &&
(entry.type == DBUS_TYPE_STRING)) {
- iface.driver = strdup(entry.str_value);
- if (iface.driver == NULL)
+ driver = os_strdup(entry.str_value);
+ wpa_dbus_dict_entry_clear(&entry);
+ if (driver == NULL)
goto error;
} else if (!strcmp(entry.key, "driver-params") &&
(entry.type == DBUS_TYPE_STRING)) {
- iface.driver_param = strdup(entry.str_value);
- if (iface.driver_param == NULL)
+ driver_param = os_strdup(entry.str_value);
+ wpa_dbus_dict_entry_clear(&entry);
+ if (driver_param == NULL)
goto error;
} else if (!strcmp(entry.key, "config-file") &&
(entry.type == DBUS_TYPE_STRING)) {
- iface.confname = strdup(entry.str_value);
- if (iface.confname == NULL)
+ confname = os_strdup(entry.str_value);
+ wpa_dbus_dict_entry_clear(&entry);
+ if (confname == NULL)
goto error;
} else if (!strcmp(entry.key, "bridge-ifname") &&
(entry.type == DBUS_TYPE_STRING)) {
- iface.bridge_ifname = strdup(entry.str_value);
- if (iface.bridge_ifname == NULL)
+ bridge_ifname = os_strdup(entry.str_value);
+ wpa_dbus_dict_entry_clear(&entry);
+ if (bridge_ifname == NULL)
goto error;
} else {
wpa_dbus_dict_entry_clear(&entry);
goto error;
}
- wpa_dbus_dict_entry_clear(&entry);
}
}
@@ -157,16 +156,23 @@ DBusMessage * wpas_dbus_global_add_interface(DBusMessage *message,
* Try to get the wpa_supplicant record for this iface, return
* an error if we already control it.
*/
- if (wpa_supplicant_get_iface(global, iface.ifname) != NULL) {
+ if (wpa_supplicant_get_iface(global, ifname) != NULL) {
reply = dbus_message_new_error(message,
WPAS_ERROR_EXISTS_ERROR,
"wpa_supplicant already "
"controls this interface.");
} else {
struct wpa_supplicant *wpa_s;
+ struct wpa_interface iface;
+ os_memset(&iface, 0, sizeof(iface));
+ iface.ifname = ifname;
+ iface.driver = driver;
+ iface.driver_param = driver_param;
+ iface.confname = confname;
+ iface.bridge_ifname = bridge_ifname;
/* Otherwise, have wpa_supplicant attach to it. */
if ((wpa_s = wpa_supplicant_add_iface(global, &iface))) {
- const char *path = wpa_supplicant_get_dbus_path(wpa_s);
+ const char *path = wpa_s->dbus_path;
reply = dbus_message_new_method_return(message);
dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH,
&path, DBUS_TYPE_INVALID);
@@ -178,12 +184,17 @@ DBusMessage * wpas_dbus_global_add_interface(DBusMessage *message,
"interface.");
}
}
- wpas_dbus_free_wpa_interface(&iface);
+
+out:
+ os_free(driver);
+ os_free(driver_param);
+ os_free(confname);
+ os_free(bridge_ifname);
return reply;
error:
- wpas_dbus_free_wpa_interface(&iface);
- return wpas_dbus_new_invalid_opts_error(message, NULL);
+ reply = wpas_dbus_new_invalid_opts_error(message, NULL);
+ goto out;
}
@@ -263,15 +274,7 @@ DBusMessage * wpas_dbus_global_get_interface(DBusMessage *message,
goto out;
}
- path = wpa_supplicant_get_dbus_path(wpa_s);
- if (path == NULL) {
- reply = dbus_message_new_error(message,
- WPAS_ERROR_INTERNAL_ERROR,
- "an internal error occurred "
- "getting the interface.");
- goto out;
- }
-
+ path = wpa_s->dbus_path;
reply = dbus_message_new_method_return(message);
dbus_message_append_args(reply,
DBUS_TYPE_OBJECT_PATH, &path,
@@ -281,6 +284,7 @@ out:
return reply;
}
+
/**
* wpas_dbus_global_set_debugparams- Set the debug params
* @message: Pointer to incoming dbus message
@@ -304,29 +308,21 @@ DBusMessage * wpas_dbus_global_set_debugparams(DBusMessage *message,
DBUS_TYPE_BOOLEAN, &debug_timestamp,
DBUS_TYPE_BOOLEAN, &debug_show_keys,
DBUS_TYPE_INVALID)) {
- reply = wpas_dbus_new_invalid_opts_error(message, NULL);
- goto out;
+ return wpas_dbus_new_invalid_opts_error(message, NULL);
}
- /* check for allowed debuglevels */
- if (debug_level != MSG_MSGDUMP &&
- debug_level != MSG_DEBUG &&
- debug_level != MSG_INFO &&
- debug_level != MSG_WARNING &&
- debug_level != MSG_ERROR) {
- reply = wpas_dbus_new_invalid_opts_error(message, NULL);
- goto out;
+ if (wpa_supplicant_set_debug_params(global, debug_level,
+ debug_timestamp ? 1 : 0,
+ debug_show_keys ? 1 : 0)) {
+ return wpas_dbus_new_invalid_opts_error(message, NULL);
}
- wpa_debug_level = debug_level;
- wpa_debug_timestamp = debug_timestamp ? 1 : 0;
- wpa_debug_show_keys = debug_show_keys ? 1 : 0;
reply = wpas_dbus_new_success_reply(message);
-out:
return reply;
}
+
/**
* wpas_dbus_iface_scan - Request a wireless scan on an interface
* @message: Pointer to incoming dbus message
@@ -363,16 +359,7 @@ DBusMessage * wpas_dbus_iface_scan_results(DBusMessage *message,
DBusMessage *reply = NULL;
DBusMessageIter iter;
DBusMessageIter sub_iter;
- size_t i;
-
- /* Ensure we've actually got scan results to return */
- if (wpa_s->scan_res == NULL &&
- wpa_supplicant_get_scan_results(wpa_s) < 0) {
- reply = dbus_message_new_error(message, WPAS_ERROR_SCAN_ERROR,
- "An error ocurred getting scan "
- "results.");
- goto out;
- }
+ struct wpa_bss *bss;
/* Create and initialize the return message */
reply = dbus_message_new_method_return(message);
@@ -382,35 +369,23 @@ DBusMessage * wpas_dbus_iface_scan_results(DBusMessage *message,
&sub_iter);
/* Loop through scan results and append each result's object path */
- for (i = 0; i < wpa_s->scan_res->num; i++) {
- struct wpa_scan_res *res = wpa_s->scan_res->res[i];
- char *path;
-
- path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
- if (path == NULL) {
- perror("wpas_dbus_iface_scan_results[dbus]: out of "
- "memory.");
- wpa_printf(MSG_ERROR, "dbus control interface: not "
- "enough memory to send scan results "
- "signal.");
- break;
- }
+ dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
+ char path_buf[WPAS_DBUS_OBJECT_PATH_MAX];
+ char *path = path_buf;
+
/* Construct the object path for this network. Note that ':'
* is not a valid character in dbus object paths.
*/
- snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
- "%s/" WPAS_DBUS_BSSIDS_PART "/"
- WPAS_DBUS_BSSID_FORMAT,
- wpa_supplicant_get_dbus_path(wpa_s),
- MAC2STR(res->bssid));
+ os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
+ "%s/" WPAS_DBUS_BSSIDS_PART "/"
+ WPAS_DBUS_BSSID_FORMAT,
+ wpa_s->dbus_path, MAC2STR(bss->bssid));
dbus_message_iter_append_basic(&sub_iter,
DBUS_TYPE_OBJECT_PATH, &path);
- free(path);
}
dbus_message_iter_close_container(&iter, &sub_iter);
-out:
return reply;
}
@@ -427,9 +402,9 @@ out:
*/
DBusMessage * wpas_dbus_bssid_properties(DBusMessage *message,
struct wpa_supplicant *wpa_s,
- struct wpa_scan_res *res)
+ struct wpa_bss *bss)
{
- DBusMessage *reply = NULL;
+ DBusMessage *reply;
DBusMessageIter iter, iter_dict;
const u8 *ie;
@@ -441,11 +416,11 @@ DBusMessage * wpas_dbus_bssid_properties(DBusMessage *message,
goto error;
if (!wpa_dbus_dict_append_byte_array(&iter_dict, "bssid",
- (const char *) res->bssid,
+ (const char *) bss->bssid,
ETH_ALEN))
goto error;
- ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
+ ie = wpa_bss_get_ie(bss, WLAN_EID_SSID);
if (ie) {
if (!wpa_dbus_dict_append_byte_array(&iter_dict, "ssid",
(const char *) (ie + 2),
@@ -453,7 +428,7 @@ DBusMessage * wpas_dbus_bssid_properties(DBusMessage *message,
goto error;
}
- ie = wpa_scan_get_vendor_ie(res, WPA_IE_VENDOR_TYPE);
+ ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
if (ie) {
if (!wpa_dbus_dict_append_byte_array(&iter_dict, "wpaie",
(const char *) ie,
@@ -461,7 +436,7 @@ DBusMessage * wpas_dbus_bssid_properties(DBusMessage *message,
goto error;
}
- ie = wpa_scan_get_ie(res, WLAN_EID_RSN);
+ ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
if (ie) {
if (!wpa_dbus_dict_append_byte_array(&iter_dict, "rsnie",
(const char *) ie,
@@ -469,7 +444,7 @@ DBusMessage * wpas_dbus_bssid_properties(DBusMessage *message,
goto error;
}
- ie = wpa_scan_get_vendor_ie(res, WPS_IE_VENDOR_TYPE);
+ ie = wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE);
if (ie) {
if (!wpa_dbus_dict_append_byte_array(&iter_dict, "wpsie",
(const char *) ie,
@@ -477,22 +452,25 @@ DBusMessage * wpas_dbus_bssid_properties(DBusMessage *message,
goto error;
}
- if (res->freq) {
+ if (bss->freq) {
if (!wpa_dbus_dict_append_int32(&iter_dict, "frequency",
- res->freq))
+ bss->freq))
goto error;
}
if (!wpa_dbus_dict_append_uint16(&iter_dict, "capabilities",
- res->caps))
+ bss->caps))
goto error;
- if (!wpa_dbus_dict_append_int32(&iter_dict, "quality", res->qual))
+ if (!(bss->flags & WPA_BSS_QUAL_INVALID) &&
+ !wpa_dbus_dict_append_int32(&iter_dict, "quality", bss->qual))
goto error;
- if (!wpa_dbus_dict_append_int32(&iter_dict, "noise", res->noise))
+ if (!(bss->flags & WPA_BSS_NOISE_INVALID) &&
+ !wpa_dbus_dict_append_int32(&iter_dict, "noise", bss->noise))
goto error;
- if (!wpa_dbus_dict_append_int32(&iter_dict, "level", res->level))
+ if (!(bss->flags & WPA_BSS_LEVEL_INVALID) &&
+ !wpa_dbus_dict_append_int32(&iter_dict, "level", bss->level))
goto error;
if (!wpa_dbus_dict_append_int32(&iter_dict, "maxrate",
- wpa_scan_get_max_rate(res) * 500000))
+ wpa_bss_get_max_rate(bss) * 500000))
goto error;
if (!wpa_dbus_dict_close_write(&iter, &iter_dict))
@@ -552,8 +530,8 @@ DBusMessage * wpas_dbus_iface_capabilities(DBusMessage *message,
/* free returned method array */
while (eap_methods[i])
- free(eap_methods[i++]);
- free(eap_methods);
+ os_free(eap_methods[i++]);
+ os_free(eap_methods);
if (!success)
goto error;
@@ -810,17 +788,7 @@ DBusMessage * wpas_dbus_iface_add_network(DBusMessage *message,
{
DBusMessage *reply = NULL;
struct wpa_ssid *ssid;
- char *path = NULL;
-
- path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
- if (path == NULL) {
- perror("wpas_dbus_iface_scan_results[dbus]: out of "
- "memory.");
- wpa_printf(MSG_ERROR, "dbus control interface: not "
- "enough memory to send scan results "
- "signal.");
- goto out;
- }
+ char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *path = path_buf;
ssid = wpa_config_add_network(wpa_s->conf);
if (ssid == NULL) {
@@ -830,21 +798,20 @@ DBusMessage * wpas_dbus_iface_add_network(DBusMessage *message,
"a network on this interface.");
goto out;
}
+ wpas_notify_network_added(wpa_s, ssid);
ssid->disabled = 1;
wpa_config_set_network_defaults(ssid);
/* Construct the object path for this network. */
- snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
- "%s/" WPAS_DBUS_NETWORKS_PART "/%d",
- wpa_supplicant_get_dbus_path(wpa_s),
- ssid->id);
+ os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
+ "%s/" WPAS_DBUS_NETWORKS_PART "/%d",
+ wpa_s->dbus_path, ssid->id);
reply = dbus_message_new_method_return(message);
dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH,
&path, DBUS_TYPE_INVALID);
out:
- free(path);
return reply;
}
@@ -880,8 +847,9 @@ DBusMessage * wpas_dbus_iface_remove_network(DBusMessage *message,
reply = wpas_dbus_new_invalid_network_error(message);
goto out;
}
+
/* Ensure the network is actually a child of this interface */
- if (strcmp(iface, wpa_supplicant_get_dbus_path(wpa_s)) != 0) {
+ if (os_strcmp(iface, wpa_s->dbus_path) != 0) {
reply = wpas_dbus_new_invalid_network_error(message);
goto out;
}
@@ -893,6 +861,8 @@ DBusMessage * wpas_dbus_iface_remove_network(DBusMessage *message,
goto out;
}
+ wpas_notify_network_removed(wpa_s, ssid);
+
if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
reply = dbus_message_new_error(message,
WPAS_ERROR_REMOVE_NETWORK_ERROR,
@@ -902,12 +872,13 @@ DBusMessage * wpas_dbus_iface_remove_network(DBusMessage *message,
}
if (ssid == wpa_s->current_ssid)
- wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
+ wpa_supplicant_deauthenticate(wpa_s,
+ WLAN_REASON_DEAUTH_LEAVING);
reply = wpas_dbus_new_success_reply(message);
out:
- free(iface);
- free(net_id);
+ os_free(iface);
+ os_free(net_id);
return reply;
}
@@ -918,6 +889,7 @@ static const char *dont_quote[] = {
"bssid", NULL
};
+
static dbus_bool_t should_quote_opt(const char *key)
{
int i = 0;
@@ -929,6 +901,7 @@ static dbus_bool_t should_quote_opt(const char *key)
return TRUE;
}
+
/**
* wpas_dbus_iface_set_network - Set options for a configured network
* @message: Pointer to incoming dbus message
@@ -976,13 +949,13 @@ DBusMessage * wpas_dbus_iface_set_network(DBusMessage *message,
if (value == NULL)
goto error;
ret = wpa_snprintf_hex(value, size,
- (u8 *) entry.bytearray_value,
- entry.array_len);
+ (u8 *) entry.bytearray_value,
+ entry.array_len);
if (ret <= 0)
goto error;
} else if (entry.type == DBUS_TYPE_STRING) {
if (should_quote_opt(entry.key)) {
- size = strlen(entry.str_value);
+ size = os_strlen(entry.str_value);
/* Zero-length option check */
if (size <= 0)
goto error;
@@ -990,12 +963,12 @@ DBusMessage * wpas_dbus_iface_set_network(DBusMessage *message,
value = os_zalloc(size);
if (value == NULL)
goto error;
- ret = snprintf(value, size, "\"%s\"",
- entry.str_value);
+ ret = os_snprintf(value, size, "\"%s\"",
+ entry.str_value);
if (ret < 0 || (size_t) ret != (size - 1))
goto error;
} else {
- value = strdup(entry.str_value);
+ value = os_strdup(entry.str_value);
if (value == NULL)
goto error;
}
@@ -1003,14 +976,16 @@ DBusMessage * wpas_dbus_iface_set_network(DBusMessage *message,
value = os_zalloc(size);
if (value == NULL)
goto error;
- ret = snprintf(value, size, "%u", entry.uint32_value);
+ ret = os_snprintf(value, size, "%u",
+ entry.uint32_value);
if (ret <= 0)
goto error;
} else if (entry.type == DBUS_TYPE_INT32) {
value = os_zalloc(size);
if (value == NULL)
goto error;
- ret = snprintf(value, size, "%d", entry.int32_value);
+ ret = os_snprintf(value, size, "%d",
+ entry.int32_value);
if (ret <= 0)
goto error;
} else
@@ -1019,17 +994,19 @@ DBusMessage * wpas_dbus_iface_set_network(DBusMessage *message,
if (wpa_config_set(ssid, entry.key, value, 0) < 0)
goto error;
- if ((strcmp(entry.key, "psk") == 0 &&
+ if ((os_strcmp(entry.key, "psk") == 0 &&
value[0] == '"' && ssid->ssid_len) ||
- (strcmp(entry.key, "ssid") == 0 && ssid->passphrase))
+ (os_strcmp(entry.key, "ssid") == 0 && ssid->passphrase))
wpa_config_update_psk(ssid);
+ else if (os_strcmp(entry.key, "priority") == 0)
+ wpa_config_update_prio_list(wpa_s->conf);
- free(value);
+ os_free(value);
wpa_dbus_dict_entry_clear(&entry);
continue;
error:
- free(value);
+ os_free(value);
reply = wpas_dbus_new_invalid_opts_error(message, entry.key);
wpa_dbus_dict_entry_clear(&entry);
break;
@@ -1057,16 +1034,7 @@ DBusMessage * wpas_dbus_iface_enable_network(DBusMessage *message,
struct wpa_supplicant *wpa_s,
struct wpa_ssid *ssid)
{
- if (wpa_s->current_ssid == NULL && ssid->disabled) {
- /*
- * Try to reassociate since there is no current configuration
- * and a new network was made available.
- */
- wpa_s->reassociate = 1;
- wpa_supplicant_req_scan(wpa_s, 0, 0);
- }
- ssid->disabled = 0;
-
+ wpa_supplicant_enable_network(wpa_s, ssid);
return wpas_dbus_new_success_reply(message);
}
@@ -1085,10 +1053,7 @@ DBusMessage * wpas_dbus_iface_disable_network(DBusMessage *message,
struct wpa_supplicant *wpa_s,
struct wpa_ssid *ssid)
{
- if (ssid == wpa_s->current_ssid)
- wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
- ssid->disabled = 1;
-
+ wpa_supplicant_disable_network(wpa_s, ssid);
return wpas_dbus_new_success_reply(message);
}
@@ -1111,17 +1076,10 @@ DBusMessage * wpas_dbus_iface_select_network(DBusMessage *message,
char *iface_obj_path = NULL;
char *network = NULL;
- if (strlen(dbus_message_get_signature(message)) == 0) {
+ if (os_strlen(dbus_message_get_signature(message)) == 0) {
/* Any network */
- ssid = wpa_s->conf->ssid;
- while (ssid) {
- ssid->disabled = 0;
- ssid = ssid->next;
- }
- wpa_s->reassociate = 1;
- wpa_supplicant_req_scan(wpa_s, 0, 0);
+ ssid = NULL;
} else {
- const char *obj_path;
int nid;
if (!dbus_message_get_args(message, NULL,
@@ -1141,8 +1099,7 @@ DBusMessage * wpas_dbus_iface_select_network(DBusMessage *message,
goto out;
}
/* Ensure the object path really points to this interface */
- obj_path = wpa_supplicant_get_dbus_path(wpa_s);
- if (strcmp(iface_obj_path, obj_path) != 0) {
+ if (os_strcmp(iface_obj_path, wpa_s->dbus_path) != 0) {
reply = wpas_dbus_new_invalid_network_error(message);
goto out;
}
@@ -1158,29 +1115,16 @@ DBusMessage * wpas_dbus_iface_select_network(DBusMessage *message,
reply = wpas_dbus_new_invalid_network_error(message);
goto out;
}
-
- /* Finally, associate with the network */
- if (ssid != wpa_s->current_ssid && wpa_s->current_ssid)
- wpa_supplicant_disassociate(
- wpa_s, WLAN_REASON_DEAUTH_LEAVING);
-
- /* Mark all other networks disabled and trigger reassociation
- */
- ssid = wpa_s->conf->ssid;
- while (ssid) {
- ssid->disabled = (nid != ssid->id);
- ssid = ssid->next;
- }
- wpa_s->disconnected = 0;
- wpa_s->reassociate = 1;
- wpa_supplicant_req_scan(wpa_s, 0, 0);
}
+ /* Finally, associate with the network */
+ wpa_supplicant_select_network(wpa_s, ssid);
+
reply = wpas_dbus_new_success_reply(message);
out:
- free(iface_obj_path);
- free(network);
+ os_free(iface_obj_path);
+ os_free(network);
return reply;
}
@@ -1198,7 +1142,7 @@ DBusMessage * wpas_dbus_iface_disconnect(DBusMessage *message,
struct wpa_supplicant *wpa_s)
{
wpa_s->disconnected = 1;
- wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
+ wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
return wpas_dbus_new_success_reply(message);
}
@@ -1225,11 +1169,11 @@ DBusMessage * wpas_dbus_iface_set_ap_scan(DBusMessage *message,
goto out;
}
- if (ap_scan > 2) {
+ if (wpa_supplicant_set_ap_scan(wpa_s, ap_scan)) {
reply = wpas_dbus_new_invalid_opts_error(message, NULL);
goto out;
}
- wpa_s->conf->ap_scan = ap_scan;
+
reply = wpas_dbus_new_success_reply(message);
out:
@@ -1286,14 +1230,12 @@ DBusMessage * wpas_dbus_iface_set_smartcard_modules(
wpa_dbus_dict_entry_clear(&entry);
}
-#ifdef EAP_TLS_OPENSSL
os_free(wpa_s->conf->opensc_engine_path);
wpa_s->conf->opensc_engine_path = opensc_engine_path;
os_free(wpa_s->conf->pkcs11_engine_path);
wpa_s->conf->pkcs11_engine_path = pkcs11_engine_path;
os_free(wpa_s->conf->pkcs11_module_path);
wpa_s->conf->pkcs11_module_path = pkcs11_module_path;
-#endif /* EAP_TLS_OPENSSL */
wpa_sm_set_eapol(wpa_s->wpa, NULL);
eapol_sm_deinit(wpa_s->eapol);
@@ -1310,6 +1252,7 @@ error:
return wpas_dbus_new_invalid_opts_error(message, NULL);
}
+
/**
* wpas_dbus_iface_get_state - Get interface state
* @message: Pointer to incoming dbus message
@@ -1355,10 +1298,8 @@ DBusMessage * wpas_dbus_iface_get_scanning(DBusMessage *message,
dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &scanning,
DBUS_TYPE_INVALID);
} else {
- perror("wpas_dbus_iface_get_scanning[dbus]: out of "
- "memory.");
- wpa_printf(MSG_ERROR, "dbus control interface: not enough "
- "memory to return scanning state.");
+ wpa_printf(MSG_ERROR, "dbus: Not enough memory to return "
+ "scanning state");
}
return reply;
@@ -1438,8 +1379,11 @@ DBusMessage * wpas_dbus_iface_set_blobs(DBusMessage *message,
}
/* Success */
- wpa_config_remove_blob(wpa_s->conf, blob->name);
+ if (!wpa_config_remove_blob(wpa_s->conf, blob->name))
+ wpas_notify_blob_removed(wpa_s, blob->name);
wpa_config_set_blob(wpa_s->conf, blob);
+ wpas_notify_blob_added(wpa_s, blob->name);
+
wpa_dbus_dict_entry_clear(&entry);
}
wpa_dbus_dict_entry_clear(&entry);
@@ -1458,7 +1402,7 @@ DBusMessage * wpas_dbus_iface_set_blobs(DBusMessage *message,
* Asks wpa_supplicant to remove one or more previously stored binary blobs.
*/
DBusMessage * wpas_dbus_iface_remove_blobs(DBusMessage *message,
- struct wpa_supplicant *wpa_s)
+ struct wpa_supplicant *wpa_s)
{
DBusMessageIter iter, array;
char *err_msg = NULL;
@@ -1474,18 +1418,19 @@ DBusMessage * wpas_dbus_iface_remove_blobs(DBusMessage *message,
const char *name;
dbus_message_iter_get_basic(&array, &name);
- if (!strlen(name))
+ if (!os_strlen(name))
err_msg = "Invalid blob name.";
if (wpa_config_remove_blob(wpa_s->conf, name) != 0)
err_msg = "Error removing blob.";
+ else
+ wpas_notify_blob_removed(wpa_s, name);
dbus_message_iter_next(&array);
}
- if (err_msg) {
+ if (err_msg)
return dbus_message_new_error(message, WPAS_ERROR_REMOVE_ERROR,
err_msg);
- }
return wpas_dbus_new_success_reply(message);
}
diff --git a/contrib/wpa/wpa_supplicant/ctrl_iface_dbus_handlers.h b/contrib/wpa/wpa_supplicant/dbus/dbus_old_handlers.h
index 376d835..65e876f 100644
--- a/contrib/wpa/wpa_supplicant/ctrl_iface_dbus_handlers.h
+++ b/contrib/wpa/wpa_supplicant/dbus/dbus_old_handlers.h
@@ -15,9 +15,10 @@
#ifndef CTRL_IFACE_DBUS_HANDLERS_H
#define CTRL_IFACE_DBUS_HANDLERS_H
-#ifdef CONFIG_CTRL_IFACE_DBUS
+struct wpa_bss;
DBusMessage * wpas_dbus_new_invalid_iface_error(DBusMessage *message);
+DBusMessage * wpas_dbus_new_invalid_network_error(DBusMessage *message);
DBusMessage * wpas_dbus_global_add_interface(DBusMessage *message,
struct wpa_global *global);
@@ -39,7 +40,7 @@ DBusMessage * wpas_dbus_iface_scan_results(DBusMessage *message,
DBusMessage * wpas_dbus_bssid_properties(DBusMessage *message,
struct wpa_supplicant *wpa_s,
- struct wpa_scan_res *res);
+ struct wpa_bss *bss);
DBusMessage * wpas_dbus_iface_capabilities(DBusMessage *message,
struct wpa_supplicant *wpa_s);
@@ -86,7 +87,18 @@ DBusMessage * wpas_dbus_iface_set_blobs(DBusMessage *message,
DBusMessage * wpas_dbus_iface_remove_blobs(DBusMessage *message,
struct wpa_supplicant *wpa_s);
-#endif /* CONFIG_CTRL_IFACE_DBUS */
+DBusMessage * wpas_dbus_iface_wps_pbc(DBusMessage *message,
+ struct wpa_supplicant *wpa_s);
+
+DBusMessage * wpas_dbus_iface_wps_pin(DBusMessage *message,
+ struct wpa_supplicant *wpa_s);
+
+DBusMessage * wpas_dbus_iface_wps_reg(DBusMessage *message,
+ struct wpa_supplicant *wpa_s);
+
+DBusMessage * wpas_dbus_new_success_reply(DBusMessage *message);
+DBusMessage * wpas_dbus_new_invalid_opts_error(DBusMessage *message,
+ const char *arg);
#endif /* CTRL_IFACE_DBUS_HANDLERS_H */
diff --git a/contrib/wpa/wpa_supplicant/dbus/dbus_old_handlers_wps.c b/contrib/wpa/wpa_supplicant/dbus/dbus_old_handlers_wps.c
new file mode 100644
index 0000000..b5879f3
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/dbus/dbus_old_handlers_wps.c
@@ -0,0 +1,161 @@
+/*
+ * WPA Supplicant / dbus-based control interface (WPS)
+ * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+#include <dbus/dbus.h>
+
+#include "common.h"
+#include "../config.h"
+#include "../wpa_supplicant_i.h"
+#include "../wps_supplicant.h"
+#include "dbus_old.h"
+#include "dbus_old_handlers.h"
+
+/**
+ * wpas_dbus_iface_wps_pbc - Request credentials using WPS PBC method
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: %wpa_supplicant data structure
+ * Returns: A dbus message containing a UINT32 indicating success (1) or
+ * failure (0)
+ *
+ * Handler function for "wpsPbc" method call
+ */
+DBusMessage * wpas_dbus_iface_wps_pbc(DBusMessage *message,
+ struct wpa_supplicant *wpa_s)
+{
+ char *arg_bssid = NULL;
+ u8 bssid[ETH_ALEN];
+ int ret = 0;
+
+ if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg_bssid,
+ DBUS_TYPE_INVALID))
+ return wpas_dbus_new_invalid_opts_error(message, NULL);
+
+ if (!os_strcmp(arg_bssid, "any"))
+ ret = wpas_wps_start_pbc(wpa_s, NULL);
+ else if (!hwaddr_aton(arg_bssid, bssid))
+ ret = wpas_wps_start_pbc(wpa_s, bssid);
+ else {
+ return wpas_dbus_new_invalid_opts_error(message,
+ "Invalid BSSID");
+ }
+
+ if (ret < 0) {
+ return dbus_message_new_error(message,
+ WPAS_ERROR_WPS_PBC_ERROR,
+ "Could not start PBC "
+ "negotiation");
+ }
+
+ return wpas_dbus_new_success_reply(message);
+}
+
+
+/**
+ * wpas_dbus_iface_wps_pin - Establish the PIN number of the enrollee
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: %wpa_supplicant data structure
+ * Returns: A dbus message containing a UINT32 indicating success (1) or
+ * failure (0)
+ *
+ * Handler function for "wpsPin" method call
+ */
+DBusMessage * wpas_dbus_iface_wps_pin(DBusMessage *message,
+ struct wpa_supplicant *wpa_s)
+{
+ DBusMessage *reply = NULL;
+ char *arg_bssid;
+ char *pin = NULL;
+ u8 bssid[ETH_ALEN], *_bssid = NULL;
+ int ret = 0;
+
+ if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg_bssid,
+ DBUS_TYPE_STRING, &pin, DBUS_TYPE_INVALID))
+ return wpas_dbus_new_invalid_opts_error(message, NULL);
+
+ if (!os_strcmp(arg_bssid, "any"))
+ _bssid = NULL;
+ else if (!hwaddr_aton(arg_bssid, bssid))
+ _bssid = bssid;
+ else {
+ return wpas_dbus_new_invalid_opts_error(message,
+ "Invalid BSSID");
+ }
+
+ if (os_strlen(pin) > 0)
+ ret = wpas_wps_start_pin(wpa_s, _bssid, pin);
+ else
+ ret = wpas_wps_start_pin(wpa_s, _bssid, NULL);
+
+ if (ret < 0) {
+ return dbus_message_new_error(message,
+ WPAS_ERROR_WPS_PIN_ERROR,
+ "Could not init PIN");
+ }
+
+ reply = dbus_message_new_method_return(message);
+ if (reply == NULL)
+ return NULL;
+
+ if (ret == 0) {
+ dbus_message_append_args(reply, DBUS_TYPE_STRING, &pin,
+ DBUS_TYPE_INVALID);
+ } else {
+ char npin[9];
+ os_snprintf(npin, sizeof(npin), "%08d", ret);
+ dbus_message_append_args(reply, DBUS_TYPE_STRING, &npin,
+ DBUS_TYPE_INVALID);
+ }
+ return reply;
+}
+
+
+/**
+ * wpas_dbus_iface_wps_reg - Request credentials using the PIN of the AP
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: %wpa_supplicant data structure
+ * Returns: A dbus message containing a UINT32 indicating success (1) or
+ * failure (0)
+ *
+ * Handler function for "wpsReg" method call
+ */
+DBusMessage * wpas_dbus_iface_wps_reg(DBusMessage *message,
+ struct wpa_supplicant *wpa_s)
+{
+ char *arg_bssid;
+ char *pin = NULL;
+ u8 bssid[ETH_ALEN];
+ int ret = 0;
+
+ if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg_bssid,
+ DBUS_TYPE_STRING, &pin, DBUS_TYPE_INVALID))
+ return wpas_dbus_new_invalid_opts_error(message, NULL);
+
+ if (!os_strcmp(arg_bssid, "any"))
+ ret = wpas_wps_start_reg(wpa_s, NULL, pin, NULL);
+ else if (!hwaddr_aton(arg_bssid, bssid))
+ ret = wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
+ else {
+ return wpas_dbus_new_invalid_opts_error(message,
+ "Invalid BSSID");
+ }
+
+ if (ret < 0) {
+ return dbus_message_new_error(message,
+ WPAS_ERROR_WPS_PBC_ERROR,
+ "Could not request credentials");
+ }
+
+ return wpas_dbus_new_success_reply(message);
+}
diff --git a/contrib/wpa/wpa_supplicant/dbus-wpa_supplicant.service b/contrib/wpa/wpa_supplicant/dbus/fi.epitest.hostap.WPASupplicant.service
index a9ce1ec..a9ce1ec 100644
--- a/contrib/wpa/wpa_supplicant/dbus-wpa_supplicant.service
+++ b/contrib/wpa/wpa_supplicant/dbus/fi.epitest.hostap.WPASupplicant.service
diff --git a/contrib/wpa/wpa_supplicant/dbus/fi.w1.wpa_supplicant1.service b/contrib/wpa/wpa_supplicant/dbus/fi.w1.wpa_supplicant1.service
new file mode 100644
index 0000000..df78471
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/dbus/fi.w1.wpa_supplicant1.service
@@ -0,0 +1,4 @@
+[D-BUS Service]
+Name=fi.w1.wpa_supplicant1
+Exec=/sbin/wpa_supplicant -u
+User=root
diff --git a/contrib/wpa/wpa_supplicant/defconfig b/contrib/wpa/wpa_supplicant/defconfig
index 4d0aa8a..8c32cb3 100644
--- a/contrib/wpa/wpa_supplicant/defconfig
+++ b/contrib/wpa/wpa_supplicant/defconfig
@@ -55,11 +55,6 @@ CONFIG_DRIVER_HOSTAP=y
# Set include directory to the madwifi source tree
#CFLAGS += -I../../madwifi
-# Driver interface for Prism54 driver
-# (Note: Prism54 is not yet supported, i.e., this will not work as-is and is
-# for developers only)
-#CONFIG_DRIVER_PRISM54=y
-
# Driver interface for ndiswrapper
# Deprecated; use CONFIG_DRIVER_WEXT=y instead.
#CONFIG_DRIVER_NDISWRAPPER=y
@@ -92,6 +87,8 @@ CONFIG_DRIVER_WEXT=y
#CONFIG_DRIVER_BSD=y
#CFLAGS += -I/usr/local/include
#LIBS += -L/usr/local/lib
+#LIBS_p += -L/usr/local/lib
+#LIBS_c += -L/usr/local/lib
# Driver interface for Windows NDIS
#CONFIG_DRIVER_NDIS=y
@@ -112,12 +109,20 @@ CONFIG_DRIVER_WEXT=y
# Driver interface for development testing
#CONFIG_DRIVER_TEST=y
+# Include client MLME (management frame processing) for test driver
+# This can be used to test MLME operations in hostapd with the test interface.
+# space.
+#CONFIG_CLIENT_MLME=y
+
# Driver interface for wired Ethernet drivers
CONFIG_DRIVER_WIRED=y
# Driver interface for the Broadcom RoboSwitch family
#CONFIG_DRIVER_ROBOSWITCH=y
+# Driver interface for no driver (e.g., WPS ER only)
+#CONFIG_DRIVER_NONE=y
+
# Enable IEEE 802.1X Supplicant (automatically included if any EAP method is
# included)
CONFIG_IEEE8021X_EAPOL=y
@@ -241,11 +246,6 @@ CONFIG_CTRL_IFACE=y
# wpa_passphrase). This saves about 0.5 kB in code size.
#CONFIG_NO_WPA_PASSPHRASE=y
-# Remove AES extra functions. This can be used to reduce code size by about
-# 1.5 kB by removing extra AES modes that are not needed for commonly used
-# client configurations (they are needed for some EAP types).
-#CONFIG_NO_AES_EXTRAS=y
-
# Disable scan result processing (ap_mode=1) to save code size by about 1 kB.
# This can be used if ap_scan=1 mode is never enabled.
#CONFIG_NO_SCAN_PROCESSING=y
@@ -340,9 +340,17 @@ CONFIG_PEERKEY=y
#CONFIG_NDIS_EVENTS_INTEGRATED=y
#PLATFORMSDKLIB="/opt/Program Files/Microsoft Platform SDK/Lib"
-# Add support for DBus control interface
+# Add support for old DBus control interface
+# (fi.epitest.hostap.WPASupplicant)
#CONFIG_CTRL_IFACE_DBUS=y
+# Add support for new DBus control interface
+# (fi.w1.hostap.wpa_supplicant1)
+#CONFIG_CTRL_IFACE_DBUS_NEW=y
+
+# Add introspection support for new DBus control interface
+#CONFIG_CTRL_IFACE_DBUS_INTRO=y
+
# Add support for loading EAP methods dynamically as shared libraries.
# When this option is enabled, each EAP method can be either included
# statically (CONFIG_EAP_<method>=y) or dynamically (CONFIG_EAP_<method>=dyn).
@@ -364,13 +372,6 @@ CONFIG_PEERKEY=y
# amount of memory/flash.
#CONFIG_DYNAMIC_EAP_METHODS=y
-# Include client MLME (management frame processing).
-# This can be used to move MLME processing of Linux mac80211 stack into user
-# space. Please note that this is currently only available with
-# driver_nl80211.c and only with a modified version of Linux kernel and
-# wpa_supplicant.
-#CONFIG_CLIENT_MLME=y
-
# IEEE Std 802.11r-2008 (Fast BSS Transition)
#CONFIG_IEEE80211R=y
@@ -383,3 +384,21 @@ CONFIG_PEERKEY=y
# Enable mitigation against certain attacks against TKIP by delaying Michael
# MIC error reports by a random amount of time between 0 and 60 seconds
#CONFIG_DELAYED_MIC_ERROR_REPORT=y
+
+# Enable tracing code for developer debugging
+# This tracks use of memory allocations and other registrations and reports
+# incorrect use with a backtrace of call (or allocation) location.
+#CONFIG_WPA_TRACE=y
+# For BSD, comment out these.
+#LIBS += -lexecinfo
+#LIBS_p += -lexecinfo
+#LIBS_c += -lexecinfo
+
+# Use libbfd to get more details for developer debugging
+# This enables use of libbfd to get more detailed symbols for the backtraces
+# generated by CONFIG_WPA_TRACE=y.
+#CONFIG_WPA_TRACE_BFD=y
+# For BSD, comment out these.
+#LIBS += -lbfd -liberty -lz
+#LIBS_p += -lbfd -liberty -lz
+#LIBS_c += -lbfd -liberty -lz
diff --git a/contrib/wpa/wpa_supplicant/doc/code_structure.doxygen b/contrib/wpa/wpa_supplicant/doc/code_structure.doxygen
deleted file mode 100644
index 6398ff3..0000000
--- a/contrib/wpa/wpa_supplicant/doc/code_structure.doxygen
+++ /dev/null
@@ -1,322 +0,0 @@
-/**
-\page code_structure Structure of the source code
-
-[ \ref wpa_supplicant_core "wpa_supplicant core functionality" |
-\ref generic_helper_func "Generic helper functions" |
-\ref crypto_func "Cryptographic functions" |
-\ref tls_func "TLS library" |
-\ref configuration "Configuration" |
-\ref ctrl_iface "Control interface" |
-\ref wpa_code "WPA supplicant" |
-\ref eap_peer "EAP peer" |
-\ref eapol_supp "EAPOL supplicant" |
-\ref win_port "Windows port" |
-\ref test_programs "Test programs" ]
-
-%wpa_supplicant implementation is divided into number of independent
-modules. Core code includes functionality for controlling the network
-selection, association, and configuration. Independent modules include
-WPA code (key handshake, PMKSA caching, pre-authentication), EAPOL
-state machine, and EAP state machine and methods. In addition, there
-are number of separate files for generic helper functions.
-
-Both WPA and EAPOL/EAP state machines can be used separately in other
-programs than %wpa_supplicant. As an example, the included test
-programs eapol_test and preauth_test are using these modules.
-
-\ref driver_wrapper "Driver interface API" is defined in driver.h and
-all hardware/driver dependent functionality is implemented in
-driver_*.c.
-
-
-\section wpa_supplicant_core wpa_supplicant core functionality
-
-wpa_supplicant.c
- Program initialization, main control loop
-
-main.c
- main() for UNIX-like operating systems and MinGW (Windows); this
- uses command line arguments to configure wpa_supplicant
-
-events.c
- Driver event processing; wpa_supplicant_event() and related functions
-
-wpa_supplicant_i.h
- Internal definitions for %wpa_supplicant core; should not be
- included into independent modules
-
-
-\section generic_helper_func Generic helper functions
-
-%wpa_supplicant uses generic helper functions some of which are shared
-with with hostapd. The following C files are currently used:
-
-eloop.c and eloop.h
- Event loop (select() loop with registerable timeouts, socket read
- callbacks, and signal callbacks)
-
-common.c and common.h
- Common helper functions
-
-defs.h
- Definitions shared by multiple files
-
-l2_packet.h, l2_packet_linux.c, and l2_packet_pcap.c
- Layer 2 (link) access wrapper (includes native Linux implementation
- and wrappers for libdnet/libpcap). A new l2_packet implementation
- may need to be added when porting to new operating systems that are
- not supported by libdnet/libpcap. Makefile can be used to select which
- l2_packet implementation is included. l2_packet_linux.c uses Linux
- packet sockets and l2_packet_pcap.c has a more portable version using
- libpcap and libdnet.
-
-pcsc_funcs.c and pcsc_funcs.h
- Wrapper for PC/SC lite SIM and smart card readers
-
-priv_netlink.h
- Private version of netlink definitions from Linux kernel header files;
- this could be replaced with C library header file once suitable
- version becomes commonly available
-
-version.h
- Version number definitions
-
-wireless_copy.h
- Private version of Linux wireless extensions definitions from kernel
- header files; this could be replaced with C library header file once
- suitable version becomes commonly available
-
-
-\section crypto_func Cryptographic functions
-
-md5.c and md5.h
- MD5 (replaced with a crypto library if TLS support is included)
- HMAC-MD5 (keyed checksum for message authenticity validation)
-
-rc4.c and rc4.h
- RC4 (broadcast/default key encryption)
-
-sha1.c and sha1.h
- SHA-1 (replaced with a crypto library if TLS support is included)
- HMAC-SHA-1 (keyed checksum for message authenticity validation)
- PRF-SHA-1 (pseudorandom (key/nonce generation) function)
- PBKDF2-SHA-1 (ASCII passphrase to shared secret)
- T-PRF (for EAP-FAST)
- TLS-PRF (RFC 2246)
-
-sha256.c and sha256.h
- SHA-256 (replaced with a crypto library if TLS support is included)
-
-aes_wrap.c, aes_wrap.h, aes.c
- AES (replaced with a crypto library if TLS support is included),
- AES Key Wrap Algorithm with 128-bit KEK, RFC3394 (broadcast/default
- key encryption),
- One-Key CBC MAC (OMAC1) hash with AES-128,
- AES-128 CTR mode encryption,
- AES-128 EAX mode encryption/decryption,
- AES-128 CBC
-
-crypto.h
- Definition of crypto library wrapper
-
-crypto_openssl.c
- Wrapper functions for libcrypto (OpenSSL)
-
-crypto_internal.c
- Wrapper functions for internal crypto implementation
-
-crypto_gnutls.c
- Wrapper functions for libgcrypt (used by GnuTLS)
-
-ms_funcs.c and ms_funcs.h
- Helper functions for MSCHAPV2 and LEAP
-
-tls.h
- Definition of TLS library wrapper
-
-tls_none.c
- Dummy implementation of TLS library wrapper for cases where TLS
- functionality is not included.
-
-tls_openssl.c
- TLS library wrapper for openssl
-
-tls_internal.c
- TLS library for internal TLS implementation
-
-tls_gnutls.c
- TLS library wrapper for GnuTLS
-
-
-\section tls_func TLS library
-
-asn1.c and asn1.h
- ASN.1 DER parsing
-
-bignum.c and bignum.h
- Big number math
-
-rsa.c and rsa.h
- RSA
-
-x509v3.c and x509v3.h
- X.509v3 certificate parsing and processing
-
-tlsv1_client.c, tlsv1_client.h
- TLSv1 client (RFC 2246)
-
-tlsv1_client_i.h
- Internal structures for TLSv1 client
-
-tlsv1_client_read.c
- TLSv1 client: read handshake messages
-
-tlsv1_client_write.c
- TLSv1 client: write handshake messages
-
-tlsv1_common.c and tlsv1_common.h
- Common TLSv1 routines and definitions
-
-tlsv1_cred.c and tlsv1_cred.h
- TLSv1 credentials
-
-tlsv1_record.c and tlsv1_record.h
- TLSv1 record protocol
-
-
-\section configuration Configuration
-
-config_ssid.h
- Definition of per network configuration items
-
-config.h
- Definition of the %wpa_supplicant configuration
-
-config.c
- Configuration parser and common functions
-
-config_file.c
- Configuration backend for text files (e.g., wpa_supplicant.conf)
-
-config_winreg.c
- Configuration backend for Windows registry
-
-
-\section ctrl_iface Control interface
-
-%wpa_supplicant has a \ref ctrl_iface_page "control interface"
-that can be used to get status
-information and manage operations from external programs. An example
-command line interface (wpa_cli) and GUI (wpa_gui) for this interface
-are included in the %wpa_supplicant distribution.
-
-ctrl_iface.c and ctrl_iface.h
- %wpa_supplicant-side of the control interface
-
-ctrl_iface_unix.c
- UNIX domain sockets -based control interface backend
-
-ctrl_iface_udp.c
- UDP sockets -based control interface backend
-
-ctrl_iface_named_pipe.c
- Windows named pipes -based control interface backend
-
-wpa_ctrl.c and wpa_ctrl.h
- Library functions for external programs to provide access to the
- %wpa_supplicant control interface
-
-wpa_cli.c
- Example program for using %wpa_supplicant control interface
-
-
-\section wpa_code WPA supplicant
-
-wpa.c and wpa.h
- WPA state machine and 4-Way/Group Key Handshake processing
-
-preauth.c and preauth.h
- PMKSA caching and pre-authentication (RSN/WPA2)
-
-wpa_i.h
- Internal definitions for WPA code; not to be included to other modules.
-
-\section eap_peer EAP peer
-
-\ref eap_module "EAP peer implementation" is a separate module that
-can be used by other programs than just %wpa_supplicant.
-
-eap.c and eap.h
- EAP state machine and method interface
-
-eap_defs.h
- Common EAP definitions
-
-eap_i.h
- Internal definitions for EAP state machine and EAP methods; not to be
- included in other modules
-
-eap_sim_common.c and eap_sim_common.h
- Common code for EAP-SIM and EAP-AKA
-
-eap_tls_common.c and eap_tls_common.h
- Common code for EAP-PEAP, EAP-TTLS, and EAP-FAST
-
-eap_tlv.c and eap_tlv.h
- EAP-TLV code for EAP-PEAP and EAP-FAST
-
-eap_ttls.c and eap_ttls.h
- EAP-TTLS
-
-eap_pax.c, eap_pax_common.h, eap_pax_common.c
- EAP-PAX
-
-eap_psk.c, eap_psk_common.h, eap_psk_common.c
- EAP-PSK (note: this is not needed for WPA-PSK)
-
-eap_sake.c, eap_sake_common.h, eap_sake_common.c
- EAP-SAKE
-
-eap_gpsk.c, eap_gpsk_common.h, eap_gpsk_common.c
- EAP-GPSK
-
-eap_aka.c, eap_fast.c, eap_gtc.c, eap_leap.c, eap_md5.c, eap_mschapv2.c,
-eap_otp.c, eap_peap.c, eap_sim.c, eap_tls.c
- Other EAP method implementations
-
-
-\section eapol_supp EAPOL supplicant
-
-eapol_supp_sm.c and eapol_supp_sm.h
- EAPOL supplicant state machine and IEEE 802.1X processing
-
-
-\section win_port Windows port
-
-ndis_events.c
- Code for receiving NdisMIndicateStatus() events and delivering them to
- %wpa_supplicant driver_ndis.c in more easier to use form
-
-win_if_list.c
- External program for listing current network interface
-
-
-\section test_programs Test programs
-
-radius_client.c and radius_client.h
- RADIUS authentication client implementation for eapol_test
-
-radius.c and radius.h
- RADIUS message processing for eapol_test
-
-eapol_test.c
- Standalone EAP testing tool with integrated RADIUS authentication
- client
-
-preauth_test.c
- Standalone RSN pre-authentication tool
-
-wpa_passphrase.c
- WPA ASCII passphrase to PSK conversion
-
-*/
diff --git a/contrib/wpa/wpa_supplicant/doc/ctrl_iface.doxygen b/contrib/wpa/wpa_supplicant/doc/ctrl_iface.doxygen
deleted file mode 100644
index e908e0f..0000000
--- a/contrib/wpa/wpa_supplicant/doc/ctrl_iface.doxygen
+++ /dev/null
@@ -1,481 +0,0 @@
-/**
-\page ctrl_iface_page Control interface
-
-%wpa_supplicant implements a control interface that can be used by
-external programs to control the operations of the %wpa_supplicant
-daemon and to get status information and event notifications. There is
-a small C library, in a form of a single C file, wpa_ctrl.c, that
-provides helper functions to facilitate the use of the control
-interface. External programs can link this file into them and then use
-the library functions documented in wpa_ctrl.h to interact with
-%wpa_supplicant. This library can also be used with C++. wpa_cli.c and
-wpa_gui are example programs using this library.
-
-There are multiple mechanisms for inter-process communication. For
-example, Linux version of %wpa_supplicant is using UNIX domain sockets
-for the control interface and Windows version UDP sockets. The use of
-the functions defined in wpa_ctrl.h can be used to hide the details of
-the used IPC from external programs.
-
-
-\section using_ctrl_iface Using the control interface
-
-External programs, e.g., a GUI or a configuration utility, that need to
-communicate with %wpa_supplicant should link in wpa_ctrl.c. This
-allows them to use helper functions to open connection to the control
-interface with wpa_ctrl_open() and to send commands with
-wpa_ctrl_request().
-
-%wpa_supplicant uses the control interface for two types of communication:
-commands and unsolicited event messages. Commands are a pair of
-messages, a request from the external program and a response from
-%wpa_supplicant. These can be executed using wpa_ctrl_request().
-Unsolicited event messages are sent by %wpa_supplicant to the control
-interface connection without specific request from the external program
-for receiving each message. However, the external program needs to
-attach to the control interface with wpa_ctrl_attach() to receive these
-unsolicited messages.
-
-If the control interface connection is used both for commands and
-unsolicited event messages, there is potential for receiving an
-unsolicited message between the command request and response.
-wpa_ctrl_request() caller will need to supply a callback, msg_cb,
-for processing these messages. Often it is easier to open two
-control interface connections by calling wpa_ctrl_open() twice and
-then use one of the connections for commands and the other one for
-unsolicited messages. This way command request/response pairs will
-not be broken by unsolicited messages. wpa_cli is an example of how
-to use only one connection for both purposes and wpa_gui demonstrates
-how to use two separate connections.
-
-Once the control interface connection is not needed anymore, it should
-be closed by calling wpa_ctrl_close(). If the connection was used for
-unsolicited event messages, it should be first detached by calling
-wpa_ctrl_detach().
-
-
-\section ctrl_iface_cmds Control interface commands
-
-Following commands can be used with wpa_ctrl_request():
-
-\subsection ctrl_iface_PING PING
-
-This command can be used to test whether %wpa_supplicant is replying
-to the control interface commands. The expected reply is \c PONG if the
-connection is open and %wpa_supplicant is processing commands.
-
-
-\subsection ctrl_iface_MIB MIB
-
-Request a list of MIB variables (dot1x, dot11). The output is a text
-block with each line in \c variable=value format. For example:
-
-\verbatim
-dot11RSNAOptionImplemented=TRUE
-dot11RSNAPreauthenticationImplemented=TRUE
-dot11RSNAEnabled=FALSE
-dot11RSNAPreauthenticationEnabled=FALSE
-dot11RSNAConfigVersion=1
-dot11RSNAConfigPairwiseKeysSupported=5
-dot11RSNAConfigGroupCipherSize=128
-dot11RSNAConfigPMKLifetime=43200
-dot11RSNAConfigPMKReauthThreshold=70
-dot11RSNAConfigNumberOfPTKSAReplayCounters=1
-dot11RSNAConfigSATimeout=60
-dot11RSNAAuthenticationSuiteSelected=00-50-f2-2
-dot11RSNAPairwiseCipherSelected=00-50-f2-4
-dot11RSNAGroupCipherSelected=00-50-f2-4
-dot11RSNAPMKIDUsed=
-dot11RSNAAuthenticationSuiteRequested=00-50-f2-2
-dot11RSNAPairwiseCipherRequested=00-50-f2-4
-dot11RSNAGroupCipherRequested=00-50-f2-4
-dot11RSNAConfigNumberOfGTKSAReplayCounters=0
-dot11RSNA4WayHandshakeFailures=0
-dot1xSuppPaeState=5
-dot1xSuppHeldPeriod=60
-dot1xSuppAuthPeriod=30
-dot1xSuppStartPeriod=30
-dot1xSuppMaxStart=3
-dot1xSuppSuppControlledPortStatus=Authorized
-dot1xSuppBackendPaeState=2
-dot1xSuppEapolFramesRx=0
-dot1xSuppEapolFramesTx=440
-dot1xSuppEapolStartFramesTx=2
-dot1xSuppEapolLogoffFramesTx=0
-dot1xSuppEapolRespFramesTx=0
-dot1xSuppEapolReqIdFramesRx=0
-dot1xSuppEapolReqFramesRx=0
-dot1xSuppInvalidEapolFramesRx=0
-dot1xSuppEapLengthErrorFramesRx=0
-dot1xSuppLastEapolFrameVersion=0
-dot1xSuppLastEapolFrameSource=00:00:00:00:00:00
-\endverbatim
-
-
-\subsection ctrl_iface_STATUS STATUS
-
-Request current WPA/EAPOL/EAP status information. The output is a text
-block with each line in \c variable=value format. For example:
-
-\verbatim
-bssid=02:00:01:02:03:04
-ssid=test network
-pairwise_cipher=CCMP
-group_cipher=CCMP
-key_mgmt=WPA-PSK
-wpa_state=COMPLETED
-ip_address=192.168.1.21
-Supplicant PAE state=AUTHENTICATED
-suppPortStatus=Authorized
-EAP state=SUCCESS
-\endverbatim
-
-
-\subsection ctrl_iface_STATUS-VERBOSE STATUS-VERBOSE
-
-Same as STATUS, but with more verbosity (i.e., more \c variable=value pairs).
-
-\verbatim
-bssid=02:00:01:02:03:04
-ssid=test network
-id=0
-pairwise_cipher=CCMP
-group_cipher=CCMP
-key_mgmt=WPA-PSK
-wpa_state=COMPLETED
-ip_address=192.168.1.21
-Supplicant PAE state=AUTHENTICATED
-suppPortStatus=Authorized
-heldPeriod=60
-authPeriod=30
-startPeriod=30
-maxStart=3
-portControl=Auto
-Supplicant Backend state=IDLE
-EAP state=SUCCESS
-reqMethod=0
-methodState=NONE
-decision=COND_SUCC
-ClientTimeout=60
-\endverbatim
-
-
-\subsection ctrl_iface_PMKSA PMKSA
-
-Show PMKSA cache
-
-\verbatim
-Index / AA / PMKID / expiration (in seconds) / opportunistic
-1 / 02:00:01:02:03:04 / 000102030405060708090a0b0c0d0e0f / 41362 / 0
-2 / 02:00:01:33:55:77 / 928389281928383b34afb34ba4212345 / 362 / 1
-\endverbatim
-
-
-\subsection ctrl_iface_SET SET <variable> <value>
-
-Set variables:
-- EAPOL::heldPeriod
-- EAPOL::authPeriod
-- EAPOL::startPeriod
-- EAPOL::maxStart
-- dot11RSNAConfigPMKLifetime
-- dot11RSNAConfigPMKReauthThreshold
-- dot11RSNAConfigSATimeout
-
-Example command:
-\verbatim
-SET EAPOL::heldPeriod 45
-\endverbatim
-
-
-\subsection ctrl_iface_LOGON LOGON
-
-IEEE 802.1X EAPOL state machine logon.
-
-
-\subsection ctrl_iface_LOGOFF LOGOFF
-
-IEEE 802.1X EAPOL state machine logoff.
-
-
-\subsection ctrl_iface_REASSOCIATE REASSOCIATE
-
-Force reassociation.
-
-
-\subsection ctrl_iface_RECONNECT RECONNECT
-
-Connect if disconnected (i.e., like \c REASSOCIATE, but only connect
-if in disconnected state).
-
-
-\subsection ctrl_iface_PREAUTH PREAUTH <BSSID>
-
-Start pre-authentication with the given BSSID.
-
-
-\subsection ctrl_iface_ATTACH ATTACH
-
-Attach the connection as a monitor for unsolicited events. This can
-be done with wpa_ctrl_attach().
-
-
-\subsection ctrl_iface_DETACH DETACH
-
-Detach the connection as a monitor for unsolicited events. This can
-be done with wpa_ctrl_detach().
-
-
-\subsection ctrl_iface_LEVEL LEVEL <debug level>
-
-Change debug level.
-
-
-\subsection ctrl_iface_RECONFIGURE RECONFIGURE
-
-Force %wpa_supplicant to re-read its configuration data.
-
-
-\subsection ctrl_iface_TERMINATE TERMINATE
-
-Terminate %wpa_supplicant process.
-
-
-\subsection ctrl_iface_BSSID BSSID <network id> <BSSID>
-
-Set preferred BSSID for a network. Network id can be received from the
-\c LIST_NETWORKS command output.
-
-
-\subsection ctrl_iface_LIST_NETWORKS LIST_NETWORKS
-
-List configured networks.
-
-\verbatim
-network id / ssid / bssid / flags
-0 example network any [CURRENT]
-\endverbatim
-
-(note: fields are separated with tabs)
-
-
-\subsection ctrl_iface_DISCONNECT DISCONNECT
-
-Disconnect and wait for \c REASSOCIATE or \c RECONNECT command before
-connecting.
-
-
-\subsection ctrl_iface_SCAN SCAN
-
-Request a new BSS scan.
-
-
-\subsection ctrl_iface_SCAN_RESULTS SCAN_RESULTS
-
-Get the latest scan results.
-
-\verbatim
-bssid / frequency / signal level / flags / ssid
-00:09:5b:95:e0:4e 2412 208 [WPA-PSK-CCMP] jkm private
-02:55:24:33:77:a3 2462 187 [WPA-PSK-TKIP] testing
-00:09:5b:95:e0:4f 2412 209 jkm guest
-\endverbatim
-
-(note: fields are separated with tabs)
-
-
-\subsection ctrl_iface_BSS BSS
-
-Get detailed per-BSS scan results. \c BSS command can be used to
-iterate through scan results one BSS at a time and to fetch all
-information from the found BSSes. This provides access to the same
-data that is available through \c SCAN_RESULTS but in a way that
-avoids problems with large number of scan results not fitting in the
-ctrl_iface messages.
-
-There are two options for selecting the BSS with the \c BSS command:
-"BSS <idx>" requests information for the BSS identified by the index
-(0 .. size-1) in the scan results table and "BSS <BSSID>" requests
-information for the given BSS (based on BSSID in 00:01:02:03:04:05
-format).
-
-BSS information is presented in following format. Please note that new
-fields may be added to this field=value data, so the ctrl_iface user
-should be prepared to ignore values it does not understand.
-
-\verbatim
-bssid=00:09:5b:95:e0:4e
-freq=2412
-beacon_int=0
-capabilities=0x0011
-qual=51
-noise=161
-level=212
-tsf=0000000000000000
-ie=000b6a6b6d2070726976617465010180dd180050f20101000050f20401000050f20401000050f2020000
-ssid=jkm private
-\endverbatim
-
-
-
-\subsection ctrl_iface_SELECT_NETWORK SELECT_NETWORK <network id>
-
-Select a network (disable others). Network id can be received from the
-\c LIST_NETWORKS command output.
-
-
-\subsection ctrl_iface_ENABLE_NETWORK ENABLE_NETWORK <network id>
-
-Enable a network. Network id can be received from the
-\c LIST_NETWORKS command output. Special network id \c all can be
-used to enable all network.
-
-
-\subsection ctrl_iface_DISABLE_NETWORK DISABLE_NETWORK <network id>
-
-Disable a network. Network id can be received from the
-\c LIST_NETWORKS command output. Special network id \c all can be
-used to disable all network.
-
-
-\subsection ctrl_iface_ADD_NETWORK ADD_NETWORK
-
-Add a new network. This command creates a new network with empty
-configuration. The new network is disabled and once it has been
-configured it can be enabled with \c ENABLE_NETWORK command. \c ADD_NETWORK
-returns the network id of the new network or FAIL on failure.
-
-
-\subsection ctrl_iface_REMOVE_NETWORK REMOVE_NETWORK <network id>
-
-Remove a network. Network id can be received from the
-\c LIST_NETWORKS command output. Special network id \c all can be
-used to remove all network.
-
-
-\subsection ctrl_iface_SET_NETWORK SET_NETWORK <network id> <variable> <value>
-
-Set network variables. Network id can be received from the
-\c LIST_NETWORKS command output.
-
-This command uses the same variables and data formats as the
-configuration file. See example wpa_supplicant.conf for more details.
-
-- ssid (network name, SSID)
-- psk (WPA passphrase or pre-shared key)
-- key_mgmt (key management protocol)
-- identity (EAP identity)
-- password (EAP password)
-- ...
-
-
-\subsection ctrl_iface_GET_NETWORK GET_NETWORK <network id> <variable>
-
-Get network variables. Network id can be received from the
-\c LIST_NETWORKS command output.
-
-
-\subsection ctrl_iface_SAVE_CONFIG SAVE_CONFIG
-
-Save the current configuration.
-
-
-\section ctrl_iface_interactive Interactive requests
-
-If %wpa_supplicant needs additional information during authentication
-(e.g., password), it will use a specific prefix, \c CTRL-REQ-
-(\a WPA_CTRL_REQ macro) in an unsolicited event message. An external
-program, e.g., a GUI, can provide such information by using
-\c CTRL-RSP- (\a WPA_CTRL_RSP macro) prefix in a command with matching
-field name.
-
-The following fields can be requested in this way from the user:
-- IDENTITY (EAP identity/user name)
-- PASSWORD (EAP password)
-- NEW_PASSWORD (New password if the server is requesting password change)
-- PIN (PIN code for accessing a SIM or smartcard)
-- OTP (one-time password; like password, but the value is used only once)
-- PASSPHRASE (passphrase for a private key file)
-
-\verbatim
-CTRL-REQ-<field name>-<network id>-<human readable text>
-CTRL-RSP-<field name>-<network id>-<value>
-\endverbatim
-
-For example, request from %wpa_supplicant:
-\verbatim
-CTRL-REQ-PASSWORD-1-Password needed for SSID test-network
-\endverbatim
-
-And a matching reply from the GUI:
-\verbatim
-CTRL-RSP-PASSWORD-1-secret
-\endverbatim
-
-
-\subsection ctrl_iface_GET_CAPABILITY GET_CAPABILITY <option> [strict]
-
-Get list of supported functionality (eap, pairwise, group,
-proto). Supported functionality is shown as space separate lists of
-values used in the same format as in %wpa_supplicant configuration.
-If optional argument, 'strict', is added, only the values that the
-driver claims to explicitly support are included. Without this, all
-available capabilities are included if the driver does not provide
-a mechanism for querying capabilities.
-
-Example request/reply pairs:
-
-\verbatim
-GET_CAPABILITY eap
-AKA FAST GTC LEAP MD5 MSCHAPV2 OTP PAX PEAP PSK SIM TLS TTLS
-\endverbatim
-
-\verbatim
-GET_CAPABILITY pairwise
-CCMP TKIP NONE
-\endverbatim
-
-\verbatim
-GET_CAPABILITY pairwise strict
-\endverbatim
-
-\verbatim
-GET_CAPABILITY group
-CCMP TKIP WEP104 WEP40
-\endverbatim
-
-\verbatim
-GET_CAPABILITY key_mgmt
-WPA-PSK WPA-EAP IEEE8021X NONE
-\endverbatim
-
-\verbatim
-GET_CAPABILITY proto
-RSN WPA
-\endverbatim
-
-\verbatim
-GET_CAPABILITY auth_alg
-OPEN SHARED LEAP
-\endverbatim
-
-
-\subsection ctrl_iface_AP_SCAN AP_SCAN <ap_scan value>
-
-Change ap_scan value:
-0 = no scanning,
-1 = %wpa_supplicant requests scans and uses scan results to select the AP,
-2 = %wpa_supplicant does not use scanning and just requests driver to
-associate and take care of AP selection
-
-
-\subsection ctrl_iface_INTERFACES INTERFACES
-
-List configured interfaces.
-
-\verbatim
-wlan0
-eth0
-\endverbatim
-
-*/
diff --git a/contrib/wpa/wpa_supplicant/doc/docbook/.gitignore b/contrib/wpa/wpa_supplicant/doc/docbook/.gitignore
new file mode 100644
index 0000000..8c3945c
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/doc/docbook/.gitignore
@@ -0,0 +1,6 @@
+manpage.links
+manpage.refs
+*.8
+*.5
+*.html
+*.pdf
diff --git a/contrib/wpa/wpa_supplicant/doc/docbook/wpa_background.8 b/contrib/wpa/wpa_supplicant/doc/docbook/wpa_background.8
index 81f771e..19162a3 100644
--- a/contrib/wpa/wpa_supplicant/doc/docbook/wpa_background.8
+++ b/contrib/wpa/wpa_supplicant/doc/docbook/wpa_background.8
@@ -3,7 +3,7 @@
.\" <http://shell.ipoline.com/~elmert/comp/docbook2X/>
.\" Please send any bug reports, improvements, comments, patches,
.\" etc. to Steve Cheng <steve@ggi-project.org>.
-.TH "WPA_BACKGROUND" "8" "12 January 2010" "" ""
+.TH "WPA_BACKGROUND" "8" "07 September 2010" "" ""
.SH NAME
wpa_background \- Background information on Wi-Fi Protected Access and IEEE 802.11i
diff --git a/contrib/wpa/wpa_supplicant/doc/docbook/wpa_cli.8 b/contrib/wpa/wpa_supplicant/doc/docbook/wpa_cli.8
index 286cf06..e22fc92 100644
--- a/contrib/wpa/wpa_supplicant/doc/docbook/wpa_cli.8
+++ b/contrib/wpa/wpa_supplicant/doc/docbook/wpa_cli.8
@@ -3,7 +3,7 @@
.\" <http://shell.ipoline.com/~elmert/comp/docbook2X/>
.\" Please send any bug reports, improvements, comments, patches,
.\" etc. to Steve Cheng <steve@ggi-project.org>.
-.TH "WPA_CLI" "8" "12 January 2010" "" ""
+.TH "WPA_CLI" "8" "07 September 2010" "" ""
.SH NAME
wpa_cli \- WPA command line client
diff --git a/contrib/wpa/wpa_supplicant/doc/docbook/wpa_gui.8 b/contrib/wpa/wpa_supplicant/doc/docbook/wpa_gui.8
index 66a279d..f58a894 100644
--- a/contrib/wpa/wpa_supplicant/doc/docbook/wpa_gui.8
+++ b/contrib/wpa/wpa_supplicant/doc/docbook/wpa_gui.8
@@ -3,7 +3,7 @@
.\" <http://shell.ipoline.com/~elmert/comp/docbook2X/>
.\" Please send any bug reports, improvements, comments, patches,
.\" etc. to Steve Cheng <steve@ggi-project.org>.
-.TH "WPA_GUI" "8" "12 January 2010" "" ""
+.TH "WPA_GUI" "8" "07 September 2010" "" ""
.SH NAME
wpa_gui \- WPA Graphical User Interface
diff --git a/contrib/wpa/wpa_supplicant/doc/docbook/wpa_passphrase.8 b/contrib/wpa/wpa_supplicant/doc/docbook/wpa_passphrase.8
index d1d1800..945c1c0 100644
--- a/contrib/wpa/wpa_supplicant/doc/docbook/wpa_passphrase.8
+++ b/contrib/wpa/wpa_supplicant/doc/docbook/wpa_passphrase.8
@@ -3,7 +3,7 @@
.\" <http://shell.ipoline.com/~elmert/comp/docbook2X/>
.\" Please send any bug reports, improvements, comments, patches,
.\" etc. to Steve Cheng <steve@ggi-project.org>.
-.TH "WPA_PASSPHRASE" "8" "12 January 2010" "" ""
+.TH "WPA_PASSPHRASE" "8" "07 September 2010" "" ""
.SH NAME
wpa_passphrase \- Generate a WPA PSK from an ASCII passphrase for a SSID
diff --git a/contrib/wpa/wpa_supplicant/doc/docbook/wpa_priv.8 b/contrib/wpa/wpa_supplicant/doc/docbook/wpa_priv.8
index a5fa2ea..05ad983 100644
--- a/contrib/wpa/wpa_supplicant/doc/docbook/wpa_priv.8
+++ b/contrib/wpa/wpa_supplicant/doc/docbook/wpa_priv.8
@@ -3,7 +3,7 @@
.\" <http://shell.ipoline.com/~elmert/comp/docbook2X/>
.\" Please send any bug reports, improvements, comments, patches,
.\" etc. to Steve Cheng <steve@ggi-project.org>.
-.TH "WPA_PRIV" "8" "12 January 2010" "" ""
+.TH "WPA_PRIV" "8" "07 September 2010" "" ""
.SH NAME
wpa_priv \- wpa_supplicant privilege separation helper
diff --git a/contrib/wpa/wpa_supplicant/doc/docbook/wpa_supplicant.8 b/contrib/wpa/wpa_supplicant/doc/docbook/wpa_supplicant.8
index 69b8d2b..3334d0c 100644
--- a/contrib/wpa/wpa_supplicant/doc/docbook/wpa_supplicant.8
+++ b/contrib/wpa/wpa_supplicant/doc/docbook/wpa_supplicant.8
@@ -3,7 +3,7 @@
.\" <http://shell.ipoline.com/~elmert/comp/docbook2X/>
.\" Please send any bug reports, improvements, comments, patches,
.\" etc. to Steve Cheng <steve@ggi-project.org>.
-.TH "WPA_SUPPLICANT" "8" "12 January 2010" "" ""
+.TH "WPA_SUPPLICANT" "8" "07 September 2010" "" ""
.SH NAME
wpa_supplicant \- Wi-Fi Protected Access client and IEEE 802.1X supplicant
@@ -283,8 +283,8 @@ Increase debugging verbosity (\fB-dd\fR even
more).
.TP
\fB-D driver\fR
-Driver to use. (Per interface, see the available options
-below.)
+Driver to use (can be multiple drivers: nl80211,wext).
+(Per interface, see the available options below.)
.TP
\fB-f output file\fR
Log output to specified file instead of stdout.
@@ -352,6 +352,18 @@ wpa_supplicant -c/etc/wpa_supplicant.conf -iwlan0 -d
.fi
.RE
.PP
+If the specific driver wrapper is not known beforehand, it is
+possible to specify multiple comma separated driver wrappers on the command
+line. \fBwpa_supplicant\fR will use the first driver
+wrapper that is able to initialize the interface.
+.sp
+.RS
+
+.nf
+wpa_supplicant -Dnl80211,wext -c/etc/wpa_supplicant.conf -iwlan0
+.fi
+.RE
+.PP
\fBwpa_supplicant\fR can control multiple
interfaces (radios) either by running one process for each
interface separately or by running just one process and list of
diff --git a/contrib/wpa/wpa_supplicant/doc/docbook/wpa_supplicant.conf.5 b/contrib/wpa/wpa_supplicant/doc/docbook/wpa_supplicant.conf.5
index 796d891..6371965 100644
--- a/contrib/wpa/wpa_supplicant/doc/docbook/wpa_supplicant.conf.5
+++ b/contrib/wpa/wpa_supplicant/doc/docbook/wpa_supplicant.conf.5
@@ -3,7 +3,7 @@
.\" <http://shell.ipoline.com/~elmert/comp/docbook2X/>
.\" Please send any bug reports, improvements, comments, patches,
.\" etc. to Steve Cheng <steve@ggi-project.org>.
-.TH "WPA_SUPPLICANT.CONF" "5" "12 January 2010" "" ""
+.TH "WPA_SUPPLICANT.CONF" "5" "07 September 2010" "" ""
.SH NAME
wpa_supplicant.conf \- configuration file for wpa_supplicant
diff --git a/contrib/wpa/wpa_supplicant/doc/docbook/wpa_supplicant.sgml b/contrib/wpa/wpa_supplicant/doc/docbook/wpa_supplicant.sgml
index 9798ced..3aae51b 100644
--- a/contrib/wpa/wpa_supplicant/doc/docbook/wpa_supplicant.sgml
+++ b/contrib/wpa/wpa_supplicant/doc/docbook/wpa_supplicant.sgml
@@ -388,8 +388,8 @@
<varlistentry>
<term>-D driver</term>
<listitem>
- <para>Driver to use. (Per interface, see the available options
- below.)</para>
+ <para>Driver to use (can be multiple drivers: nl80211,wext).
+ (Per interface, see the available options below.)</para>
</listitem>
</varlistentry>
@@ -509,6 +509,15 @@ wpa_supplicant -B -c/etc/wpa_supplicant.conf -iwlan0
wpa_supplicant -c/etc/wpa_supplicant.conf -iwlan0 -d
</programlisting></blockquote>
+ <para>If the specific driver wrapper is not known beforehand, it is
+ possible to specify multiple comma separated driver wrappers on the command
+ line. <command>wpa_supplicant</command> will use the first driver
+ wrapper that is able to initialize the interface.</para>
+
+<blockquote><programlisting>
+wpa_supplicant -Dnl80211,wext -c/etc/wpa_supplicant.conf -iwlan0
+</programlisting></blockquote>
+
<para><command>wpa_supplicant</command> can control multiple
interfaces (radios) either by running one process for each
interface separately or by running just one process and list of
diff --git a/contrib/wpa/wpa_supplicant/doc/doxygen.fast b/contrib/wpa/wpa_supplicant/doc/doxygen.fast
deleted file mode 100644
index c6012a9..0000000
--- a/contrib/wpa/wpa_supplicant/doc/doxygen.fast
+++ /dev/null
@@ -1,239 +0,0 @@
-# Doxyfile 1.4.4
-
-#---------------------------------------------------------------------------
-# Project related configuration options
-#---------------------------------------------------------------------------
-PROJECT_NAME = wpa_supplicant
-PROJECT_NUMBER = 0.6.x
-OUTPUT_DIRECTORY = wpa_supplicant/doc
-CREATE_SUBDIRS = NO
-OUTPUT_LANGUAGE = English
-BRIEF_MEMBER_DESC = YES
-REPEAT_BRIEF = YES
-ABBREVIATE_BRIEF = "The $name class" \
- "The $name widget" \
- "The $name file" \
- is \
- provides \
- specifies \
- contains \
- represents \
- a \
- an \
- the
-ALWAYS_DETAILED_SEC = NO
-INLINE_INHERITED_MEMB = NO
-FULL_PATH_NAMES = YES
-STRIP_FROM_PATH =
-STRIP_FROM_INC_PATH =
-SHORT_NAMES = NO
-JAVADOC_AUTOBRIEF = NO
-MULTILINE_CPP_IS_BRIEF = NO
-DETAILS_AT_TOP = NO
-INHERIT_DOCS = YES
-DISTRIBUTE_GROUP_DOC = NO
-SEPARATE_MEMBER_PAGES = NO
-TAB_SIZE = 8
-ALIASES =
-OPTIMIZE_OUTPUT_FOR_C = YES
-OPTIMIZE_OUTPUT_JAVA = NO
-SUBGROUPING = YES
-#---------------------------------------------------------------------------
-# Build related configuration options
-#---------------------------------------------------------------------------
-EXTRACT_ALL = NO
-EXTRACT_PRIVATE = NO
-EXTRACT_STATIC = NO
-EXTRACT_LOCAL_CLASSES = YES
-EXTRACT_LOCAL_METHODS = NO
-HIDE_UNDOC_MEMBERS = NO
-HIDE_UNDOC_CLASSES = NO
-HIDE_FRIEND_COMPOUNDS = NO
-HIDE_IN_BODY_DOCS = NO
-INTERNAL_DOCS = NO
-CASE_SENSE_NAMES = YES
-HIDE_SCOPE_NAMES = NO
-SHOW_INCLUDE_FILES = YES
-INLINE_INFO = YES
-SORT_MEMBER_DOCS = YES
-SORT_BRIEF_DOCS = NO
-SORT_BY_SCOPE_NAME = NO
-GENERATE_TODOLIST = YES
-GENERATE_TESTLIST = YES
-GENERATE_BUGLIST = YES
-GENERATE_DEPRECATEDLIST= YES
-ENABLED_SECTIONS =
-MAX_INITIALIZER_LINES = 30
-SHOW_USED_FILES = YES
-SHOW_DIRECTORIES = YES
-FILE_VERSION_FILTER =
-#---------------------------------------------------------------------------
-# configuration options related to warning and progress messages
-#---------------------------------------------------------------------------
-QUIET = NO
-WARNINGS = YES
-WARN_IF_UNDOCUMENTED = NO
-WARN_IF_DOC_ERROR = YES
-WARN_NO_PARAMDOC = YES
-WARN_FORMAT = "$file:$line: $text"
-WARN_LOGFILE =
-#---------------------------------------------------------------------------
-# configuration options related to the input files
-#---------------------------------------------------------------------------
-INPUT = wpa_supplicant \
- src/common \
- src/crypto \
- src/drivers \
- src/eap_common \
- src/eapol_supp \
- src/eap_peer \
- src/l2_packet \
- src/rsn_supp \
- src/tls \
- src/utils \
- src/wps
-FILE_PATTERNS = *.c *.h *.cpp *.m *.doxygen
-RECURSIVE = YES
-EXCLUDE = wpa_supplicant/wpa_gui
-EXCLUDE_SYMLINKS = NO
-EXCLUDE_PATTERNS = */.moc/* */.ui/*
-EXAMPLE_PATH =
-EXAMPLE_PATTERNS = *
-EXAMPLE_RECURSIVE = NO
-IMAGE_PATH = wpa_supplicant/doc
-INPUT_FILTER = kerneldoc2doxygen.pl
-FILTER_PATTERNS =
-FILTER_SOURCE_FILES = YES
-#---------------------------------------------------------------------------
-# configuration options related to source browsing
-#---------------------------------------------------------------------------
-SOURCE_BROWSER = YES
-INLINE_SOURCES = NO
-STRIP_CODE_COMMENTS = YES
-REFERENCED_BY_RELATION = NO
-REFERENCES_RELATION = NO
-VERBATIM_HEADERS = NO
-#---------------------------------------------------------------------------
-# configuration options related to the alphabetical class index
-#---------------------------------------------------------------------------
-ALPHABETICAL_INDEX = YES
-COLS_IN_ALPHA_INDEX = 3
-IGNORE_PREFIX =
-#---------------------------------------------------------------------------
-# configuration options related to the HTML output
-#---------------------------------------------------------------------------
-GENERATE_HTML = YES
-HTML_OUTPUT = html
-HTML_FILE_EXTENSION = .html
-HTML_HEADER =
-HTML_FOOTER =
-HTML_STYLESHEET =
-HTML_ALIGN_MEMBERS = YES
-GENERATE_HTMLHELP = NO
-CHM_FILE =
-HHC_LOCATION =
-GENERATE_CHI = NO
-BINARY_TOC = NO
-TOC_EXPAND = NO
-DISABLE_INDEX = NO
-ENUM_VALUES_PER_LINE = 4
-GENERATE_TREEVIEW = NO
-TREEVIEW_WIDTH = 250
-#---------------------------------------------------------------------------
-# configuration options related to the LaTeX output
-#---------------------------------------------------------------------------
-GENERATE_LATEX = NO
-LATEX_OUTPUT = latex
-LATEX_CMD_NAME = latex
-MAKEINDEX_CMD_NAME = makeindex
-COMPACT_LATEX = NO
-PAPER_TYPE = a4wide
-EXTRA_PACKAGES =
-LATEX_HEADER =
-PDF_HYPERLINKS = YES
-USE_PDFLATEX = YES
-LATEX_BATCHMODE = NO
-LATEX_HIDE_INDICES = NO
-#---------------------------------------------------------------------------
-# configuration options related to the RTF output
-#---------------------------------------------------------------------------
-GENERATE_RTF = NO
-RTF_OUTPUT = rtf
-COMPACT_RTF = NO
-RTF_HYPERLINKS = NO
-RTF_STYLESHEET_FILE =
-RTF_EXTENSIONS_FILE =
-#---------------------------------------------------------------------------
-# configuration options related to the man page output
-#---------------------------------------------------------------------------
-GENERATE_MAN = NO
-MAN_OUTPUT = man
-MAN_EXTENSION = .3
-MAN_LINKS = NO
-#---------------------------------------------------------------------------
-# configuration options related to the XML output
-#---------------------------------------------------------------------------
-GENERATE_XML = NO
-XML_OUTPUT = xml
-XML_SCHEMA =
-XML_DTD =
-XML_PROGRAMLISTING = YES
-#---------------------------------------------------------------------------
-# configuration options for the AutoGen Definitions output
-#---------------------------------------------------------------------------
-GENERATE_AUTOGEN_DEF = NO
-#---------------------------------------------------------------------------
-# configuration options related to the Perl module output
-#---------------------------------------------------------------------------
-GENERATE_PERLMOD = NO
-PERLMOD_LATEX = NO
-PERLMOD_PRETTY = YES
-PERLMOD_MAKEVAR_PREFIX =
-#---------------------------------------------------------------------------
-# Configuration options related to the preprocessor
-#---------------------------------------------------------------------------
-ENABLE_PREPROCESSING = YES
-MACRO_EXPANSION = NO
-EXPAND_ONLY_PREDEF = NO
-SEARCH_INCLUDES = YES
-INCLUDE_PATH =
-INCLUDE_FILE_PATTERNS =
-PREDEFINED = IEEE8021X_EAPOL CONFIG_CTRL_IFACE
-EXPAND_AS_DEFINED =
-SKIP_FUNCTION_MACROS = YES
-#---------------------------------------------------------------------------
-# Configuration::additions related to external references
-#---------------------------------------------------------------------------
-TAGFILES =
-GENERATE_TAGFILE =
-ALLEXTERNALS = NO
-EXTERNAL_GROUPS = YES
-PERL_PATH = /usr/bin/perl
-#---------------------------------------------------------------------------
-# Configuration options related to the dot tool
-#---------------------------------------------------------------------------
-CLASS_DIAGRAMS = NO
-HIDE_UNDOC_RELATIONS = YES
-HAVE_DOT = NO
-CLASS_GRAPH = YES
-COLLABORATION_GRAPH = YES
-GROUP_GRAPHS = YES
-UML_LOOK = NO
-TEMPLATE_RELATIONS = NO
-INCLUDE_GRAPH = YES
-INCLUDED_BY_GRAPH = YES
-CALL_GRAPH = YES
-GRAPHICAL_HIERARCHY = YES
-DIRECTORY_GRAPH = NO
-DOT_IMAGE_FORMAT = png
-DOT_PATH =
-DOTFILE_DIRS =
-MAX_DOT_GRAPH_DEPTH = 1000
-DOT_TRANSPARENT = NO
-DOT_MULTI_TARGETS = NO
-GENERATE_LEGEND = YES
-DOT_CLEANUP = YES
-#---------------------------------------------------------------------------
-# Configuration::additions related to the search engine
-#---------------------------------------------------------------------------
-SEARCHENGINE = NO
diff --git a/contrib/wpa/wpa_supplicant/doc/doxygen.full b/contrib/wpa/wpa_supplicant/doc/doxygen.full
deleted file mode 100644
index 6884c62..0000000
--- a/contrib/wpa/wpa_supplicant/doc/doxygen.full
+++ /dev/null
@@ -1,239 +0,0 @@
-# Doxyfile 1.4.4
-
-#---------------------------------------------------------------------------
-# Project related configuration options
-#---------------------------------------------------------------------------
-PROJECT_NAME = wpa_supplicant
-PROJECT_NUMBER = 0.6.x
-OUTPUT_DIRECTORY = wpa_supplicant/doc
-CREATE_SUBDIRS = NO
-OUTPUT_LANGUAGE = English
-BRIEF_MEMBER_DESC = YES
-REPEAT_BRIEF = YES
-ABBREVIATE_BRIEF = "The $name class" \
- "The $name widget" \
- "The $name file" \
- is \
- provides \
- specifies \
- contains \
- represents \
- a \
- an \
- the
-ALWAYS_DETAILED_SEC = NO
-INLINE_INHERITED_MEMB = NO
-FULL_PATH_NAMES = YES
-STRIP_FROM_PATH =
-STRIP_FROM_INC_PATH =
-SHORT_NAMES = NO
-JAVADOC_AUTOBRIEF = NO
-MULTILINE_CPP_IS_BRIEF = NO
-DETAILS_AT_TOP = NO
-INHERIT_DOCS = YES
-DISTRIBUTE_GROUP_DOC = NO
-SEPARATE_MEMBER_PAGES = NO
-TAB_SIZE = 8
-ALIASES =
-OPTIMIZE_OUTPUT_FOR_C = YES
-OPTIMIZE_OUTPUT_JAVA = NO
-SUBGROUPING = YES
-#---------------------------------------------------------------------------
-# Build related configuration options
-#---------------------------------------------------------------------------
-EXTRACT_ALL = NO
-EXTRACT_PRIVATE = NO
-EXTRACT_STATIC = NO
-EXTRACT_LOCAL_CLASSES = YES
-EXTRACT_LOCAL_METHODS = NO
-HIDE_UNDOC_MEMBERS = NO
-HIDE_UNDOC_CLASSES = NO
-HIDE_FRIEND_COMPOUNDS = NO
-HIDE_IN_BODY_DOCS = NO
-INTERNAL_DOCS = NO
-CASE_SENSE_NAMES = YES
-HIDE_SCOPE_NAMES = NO
-SHOW_INCLUDE_FILES = YES
-INLINE_INFO = YES
-SORT_MEMBER_DOCS = YES
-SORT_BRIEF_DOCS = NO
-SORT_BY_SCOPE_NAME = NO
-GENERATE_TODOLIST = YES
-GENERATE_TESTLIST = YES
-GENERATE_BUGLIST = YES
-GENERATE_DEPRECATEDLIST= YES
-ENABLED_SECTIONS =
-MAX_INITIALIZER_LINES = 30
-SHOW_USED_FILES = YES
-SHOW_DIRECTORIES = YES
-FILE_VERSION_FILTER =
-#---------------------------------------------------------------------------
-# configuration options related to warning and progress messages
-#---------------------------------------------------------------------------
-QUIET = NO
-WARNINGS = YES
-WARN_IF_UNDOCUMENTED = NO
-WARN_IF_DOC_ERROR = YES
-WARN_NO_PARAMDOC = YES
-WARN_FORMAT = "$file:$line: $text"
-WARN_LOGFILE =
-#---------------------------------------------------------------------------
-# configuration options related to the input files
-#---------------------------------------------------------------------------
-INPUT = wpa_supplicant \
- src/common \
- src/crypto \
- src/drivers \
- src/eap_common \
- src/eapol_supp \
- src/eap_peer \
- src/l2_packet \
- src/rsn_supp \
- src/tls \
- src/utils \
- src/wps
-FILE_PATTERNS = *.c *.h *.cpp *.m *.doxygen
-RECURSIVE = YES
-EXCLUDE = wpa_supplicant/wpa_gui
-EXCLUDE_SYMLINKS = NO
-EXCLUDE_PATTERNS = */.moc/* */.ui/*
-EXAMPLE_PATH =
-EXAMPLE_PATTERNS = *
-EXAMPLE_RECURSIVE = NO
-IMAGE_PATH = wpa_supplicant/doc
-INPUT_FILTER = kerneldoc2doxygen.pl
-FILTER_PATTERNS =
-FILTER_SOURCE_FILES = YES
-#---------------------------------------------------------------------------
-# configuration options related to source browsing
-#---------------------------------------------------------------------------
-SOURCE_BROWSER = YES
-INLINE_SOURCES = NO
-STRIP_CODE_COMMENTS = YES
-REFERENCED_BY_RELATION = NO
-REFERENCES_RELATION = NO
-VERBATIM_HEADERS = NO
-#---------------------------------------------------------------------------
-# configuration options related to the alphabetical class index
-#---------------------------------------------------------------------------
-ALPHABETICAL_INDEX = YES
-COLS_IN_ALPHA_INDEX = 3
-IGNORE_PREFIX =
-#---------------------------------------------------------------------------
-# configuration options related to the HTML output
-#---------------------------------------------------------------------------
-GENERATE_HTML = YES
-HTML_OUTPUT = html
-HTML_FILE_EXTENSION = .html
-HTML_HEADER =
-HTML_FOOTER =
-HTML_STYLESHEET =
-HTML_ALIGN_MEMBERS = YES
-GENERATE_HTMLHELP = NO
-CHM_FILE =
-HHC_LOCATION =
-GENERATE_CHI = NO
-BINARY_TOC = NO
-TOC_EXPAND = NO
-DISABLE_INDEX = NO
-ENUM_VALUES_PER_LINE = 4
-GENERATE_TREEVIEW = NO
-TREEVIEW_WIDTH = 250
-#---------------------------------------------------------------------------
-# configuration options related to the LaTeX output
-#---------------------------------------------------------------------------
-GENERATE_LATEX = YES
-LATEX_OUTPUT = latex
-LATEX_CMD_NAME = latex
-MAKEINDEX_CMD_NAME = makeindex
-COMPACT_LATEX = NO
-PAPER_TYPE = a4wide
-EXTRA_PACKAGES =
-LATEX_HEADER =
-PDF_HYPERLINKS = YES
-USE_PDFLATEX = YES
-LATEX_BATCHMODE = NO
-LATEX_HIDE_INDICES = NO
-#---------------------------------------------------------------------------
-# configuration options related to the RTF output
-#---------------------------------------------------------------------------
-GENERATE_RTF = NO
-RTF_OUTPUT = rtf
-COMPACT_RTF = NO
-RTF_HYPERLINKS = NO
-RTF_STYLESHEET_FILE =
-RTF_EXTENSIONS_FILE =
-#---------------------------------------------------------------------------
-# configuration options related to the man page output
-#---------------------------------------------------------------------------
-GENERATE_MAN = NO
-MAN_OUTPUT = man
-MAN_EXTENSION = .3
-MAN_LINKS = NO
-#---------------------------------------------------------------------------
-# configuration options related to the XML output
-#---------------------------------------------------------------------------
-GENERATE_XML = NO
-XML_OUTPUT = xml
-XML_SCHEMA =
-XML_DTD =
-XML_PROGRAMLISTING = YES
-#---------------------------------------------------------------------------
-# configuration options for the AutoGen Definitions output
-#---------------------------------------------------------------------------
-GENERATE_AUTOGEN_DEF = NO
-#---------------------------------------------------------------------------
-# configuration options related to the Perl module output
-#---------------------------------------------------------------------------
-GENERATE_PERLMOD = NO
-PERLMOD_LATEX = NO
-PERLMOD_PRETTY = YES
-PERLMOD_MAKEVAR_PREFIX =
-#---------------------------------------------------------------------------
-# Configuration options related to the preprocessor
-#---------------------------------------------------------------------------
-ENABLE_PREPROCESSING = YES
-MACRO_EXPANSION = NO
-EXPAND_ONLY_PREDEF = NO
-SEARCH_INCLUDES = YES
-INCLUDE_PATH =
-INCLUDE_FILE_PATTERNS =
-PREDEFINED = IEEE8021X_EAPOL CONFIG_CTRL_IFACE
-EXPAND_AS_DEFINED =
-SKIP_FUNCTION_MACROS = YES
-#---------------------------------------------------------------------------
-# Configuration::additions related to external references
-#---------------------------------------------------------------------------
-TAGFILES =
-GENERATE_TAGFILE =
-ALLEXTERNALS = NO
-EXTERNAL_GROUPS = YES
-PERL_PATH = /usr/bin/perl
-#---------------------------------------------------------------------------
-# Configuration options related to the dot tool
-#---------------------------------------------------------------------------
-CLASS_DIAGRAMS = NO
-HIDE_UNDOC_RELATIONS = YES
-HAVE_DOT = YES
-CLASS_GRAPH = YES
-COLLABORATION_GRAPH = YES
-GROUP_GRAPHS = YES
-UML_LOOK = NO
-TEMPLATE_RELATIONS = NO
-INCLUDE_GRAPH = YES
-INCLUDED_BY_GRAPH = YES
-CALL_GRAPH = YES
-GRAPHICAL_HIERARCHY = YES
-DIRECTORY_GRAPH = NO
-DOT_IMAGE_FORMAT = png
-DOT_PATH =
-DOTFILE_DIRS =
-MAX_DOT_GRAPH_DEPTH = 1000
-DOT_TRANSPARENT = NO
-DOT_MULTI_TARGETS = NO
-GENERATE_LEGEND = YES
-DOT_CLEANUP = YES
-#---------------------------------------------------------------------------
-# Configuration::additions related to the search engine
-#---------------------------------------------------------------------------
-SEARCHENGINE = YES
diff --git a/contrib/wpa/wpa_supplicant/doc/driver_wrapper.doxygen b/contrib/wpa/wpa_supplicant/doc/driver_wrapper.doxygen
deleted file mode 100644
index 28aea50..0000000
--- a/contrib/wpa/wpa_supplicant/doc/driver_wrapper.doxygen
+++ /dev/null
@@ -1,180 +0,0 @@
-/**
-\page driver_wrapper Driver wrapper implementation (driver.h, drivers.c)
-
-All hardware and driver dependent functionality is in separate C files
-that implement defined wrapper functions. Other parts
-of the %wpa_supplicant are designed to be hardware, driver, and operating
-system independent.
-
-Driver wrappers need to implement whatever calls are used in the
-target operating system/driver for controlling wireless LAN
-devices. As an example, in case of Linux, these are mostly some glue
-code and ioctl() calls and netlink message parsing for Linux Wireless
-Extensions (WE). Since features required for WPA were added only recently to
-Linux Wireless Extensions (in version 18), some driver specific code is used
-in number of driver interface implementations. These driver dependent parts
-can be replaced with generic code in driver_wext.c once the target driver
-includes full support for WE-18. After that, all Linux drivers, at
-least in theory, could use the same driver wrapper code.
-
-A driver wrapper needs to implement some or all of the functions
-defined in driver.h. These functions are registered by filling struct
-wpa_driver_ops with function pointers. Hardware independent parts of
-%wpa_supplicant will call these functions to control the driver/wlan
-card. In addition, support for driver events is required. The event
-callback function, wpa_supplicant_event(), and its parameters are
-documented in driver.h. In addition, a pointer to the 'struct
-wpa_driver_ops' needs to be registered in drivers.c file.
-
-When porting to other operating systems, the driver wrapper should be
-modified to use the native interface of the target OS. It is possible
-that some extra requirements for the interface between the driver
-wrapper and generic %wpa_supplicant code are discovered during porting
-to a new operating system. These will be addressed on case by case
-basis by modifying the interface and updating the other driver
-wrappers for this. The goal is to avoid changing this interface
-without very good reasons in order to limit the number of changes
-needed to other wrappers and hardware independent parts of
-%wpa_supplicant. When changes are required, recommended way is to
-make them in backwards compatible way that allows existing driver
-interface implementations to be compiled without any modification.
-
-Generic Linux Wireless Extensions functions are implemented in
-driver_wext.c. All Linux driver wrappers can use these when the kernel
-driver supports the generic ioctl()s and wireless events. Driver
-specific functions are implemented in separate C files, e.g.,
-driver_hostap.c. These files need to define struct wpa_driver_ops
-entry that will be used in wpa_supplicant.c when calling driver
-functions. struct wpa_driver_ops entries are registered in drivers.c.
-
-In general, it is likely to be useful to first take a look at couple
-of driver interface examples before starting on implementing a new
-one. driver_hostap.c and driver_wext.c include a complete
-implementation for Linux drivers that use %wpa_supplicant-based control
-of WPA IE and roaming. driver_ndis.c (with help from driver_ndis_.c)
-is an example of a complete interface for Windows NDIS interface for
-drivers that generate WPA IE themselves and decide when to roam. These
-example implementations include full support for all security modes.
-
-
-\section driver_req Driver requirements for WPA
-
-WPA introduces new requirements for the device driver. At least some
-of these need to be implemented in order to provide enough support for
-%wpa_supplicant.
-
-\subsection driver_tkip_ccmp TKIP/CCMP
-
-WPA requires that the pairwise cipher suite (encryption algorithm for
-unicast data packets) is TKIP or CCMP. These are new encryption
-protocols and thus, the driver will need to be modified to support
-them. Depending on the used wlan hardware, some parts of these may be
-implemented by the hardware/firmware.
-
-Specification for both TKIP and CCMP is available from IEEE (IEEE
-802.11i amendment). Fully functional, hardware independent
-implementation of both encryption protocols is also available in Host
-AP driver (driver/modules/hostap_{tkip,ccmp}.c). In addition, Linux 2.6
-kernel tree has generic implementations for WEP, TKIP, and CCMP that can
-be used in Linux drivers.
-
-The driver will also need to provide configuration mechanism to allow
-user space programs to configure TKIP and CCMP. Linux Wireless Extensions
-v18 added support for configuring these algorithms and
-individual/non-default keys. If the target kernel does not include WE-18,
-private ioctls can be used to provide similar functionality.
-
-\subsection driver_roaming Roaming control and scanning support
-
-%wpa_supplicant can optionally control AP selection based on the
-information received from Beacon and/or Probe Response frames
-(ap_scan=1 mode in configuration). This means that the driver should
-support external control for scan process. In case of Linux, use of
-new Wireless Extensions scan support (i.e., 'iwlist wlan0 scan') is
-recommended. The current driver wrapper (driver_wext.c) uses this for
-scan results.
-
-Scan results must also include the WPA information element. Support for
-this was added in WE-18. With older versions, a custom event can be used
-to provide the full WPA IE (including element id and length) as a hex
-string that is included in the scan results.
-
-%wpa_supplicant needs to also be able to request the driver to
-associate with a specific BSS. Current Host AP driver and matching
-driver_hostap.c wrapper uses following sequence for this
-request. Similar/identical mechanism should be usable also with other
-drivers.
-
-- set WPA IE for AssocReq with private ioctl
-- set SSID with SIOCSIWESSID
-- set channel/frequency with SIOCSIWFREQ
-- set BSSID with SIOCSIWAP
- (this last ioctl will trigger the driver to request association)
-
-\subsection driver_wpa_ie WPA IE generation
-
-%wpa_supplicant selects which cipher suites and key management suites
-are used. Based on this information, it generates a WPA IE. This is
-provided to the driver interface in the associate call. This does not
-match with Windows NDIS drivers which generate the WPA IE
-themselves.
-
-%wpa_supplicant allows Windows NDIS-like behavior by providing the
-selected cipher and key management suites in the associate call. If
-the driver generates its own WPA IE and that differs from the one
-generated by %wpa_supplicant, the driver has to inform %wpa_supplicant
-about the used WPA IE (i.e., the one it used in (Re)Associate
-Request). This notification is done using EVENT_ASSOCINFO event (see
-driver.h). %wpa_supplicant is normally configured to use
-ap_scan=2 mode with drivers that control WPA IE generation and roaming.
-
-\subsection driver_events Driver events
-
-%wpa_supplicant needs to receive event callbacks when certain events
-occur (association, disassociation, Michael MIC failure, scan results
-available, PMKSA caching candidate). These events and the callback
-details are defined in driver.h (wpa_supplicant_event() function
-and enum wpa_event_type).
-
-On Linux, association and disassociation can use existing Wireless
-Extensions event that is reporting new AP with SIOCGIWAP
-event. Similarly, completion of a scan can be reported with SIOCGIWSCAN
-event.
-
-Michael MIC failure event was added in WE-18. Older versions of Wireless
-Extensions will need to use a custom event. Host AP driver used a custom
-event with following contents: MLME-MICHAELMICFAILURE.indication(keyid=#
-broadcast/unicast addr=addr2). This is the recommended format until
-the driver can be moved to use WE-18 mechanism.
-
-\subsection driver_wext_summary Summary of Linux Wireless Extensions use
-
-AP selection depends on ap_scan configuration:
-
-ap_scan=1:
-
-- %wpa_supplicant requests scan with SIOCSIWSCAN
-- driver reports scan complete with wireless event SIOCGIWSCAN
-- %wpa_supplicant reads scan results with SIOCGIWSCAN (multiple call if
- a larget buffer is needed)
-- %wpa_supplicant decides which AP to use based on scan results
-- %wpa_supplicant configures driver to associate with the selected BSS
- (SIOCSIWMODE, SIOCSIWGENIE, SIOCSIWAUTH, SIOCSIWFREQ,
- SIOCSIWESSID, SIOCSIWAP)
-
-ap_scan=2:
-
-- %wpa_supplicant configures driver to associate with an SSID
- (SIOCSIWMODE, SIOCSIWGENIE, SIOCSIWAUTH, SIOCSIWESSID)
-
-
-After this, both modes use similar steps:
-
-- optionally (or required for drivers that generate WPA/RSN IE for
- (Re)AssocReq), driver reports association parameters (AssocReq IEs)
- with wireless event IWEVASSOCREQIE (and optionally IWEVASSOCRESPIE)
-- driver reports association with wireless event SIOCGIWAP
-- %wpa_supplicant takes care of EAPOL frame handling (validating
- information from associnfo and if needed, from scan results if WPA/RSN
- IE from the Beacon frame is not reported through associnfo)
-*/
diff --git a/contrib/wpa/wpa_supplicant/doc/eap.doxygen b/contrib/wpa/wpa_supplicant/doc/eap.doxygen
deleted file mode 100644
index 0646128..0000000
--- a/contrib/wpa/wpa_supplicant/doc/eap.doxygen
+++ /dev/null
@@ -1,87 +0,0 @@
-/**
-\page eap_module EAP peer implementation
-
-Extensible Authentication Protocol (EAP) is an authentication framework
-defined in RFC 3748. %wpa_supplicant uses a separate code module for EAP
-peer implementation. This module was designed to use only a minimal set
-of direct function calls (mainly, to debug/event functions) in order for
-it to be usable in other programs. The design of the EAP
-implementation is based loosely on RFC 4137. The state machine is
-defined in this RFC and so is the interface between the peer state
-machine and methods. As such, this RFC provides useful information for
-understanding the EAP peer implementation in %wpa_supplicant.
-
-Some of the terminology used in EAP state machine is referring to
-EAPOL (IEEE 802.1X), but there is no strict requirement on the lower
-layer being IEEE 802.1X if EAP module is built for other programs than
-%wpa_supplicant. These terms should be understood to refer to the
-lower layer as defined in RFC 4137.
-
-
-\section adding_eap_methods Adding EAP methods
-
-Each EAP method is implemented as a separate module, usually as one C
-file named eap_<name of the method>.c, e.g., eap_md5.c. All EAP
-methods use the same interface between the peer state machine and
-method specific functions. This allows new EAP methods to be added
-without modifying the core EAP state machine implementation.
-
-New EAP methods need to be registered by adding them into the build
-(Makefile) and the EAP method registration list in the
-eap_peer_register_methods() function of eap_methods.c. Each EAP
-method should use a build-time configuration option, e.g., EAP_TLS, in
-order to make it possible to select which of the methods are included
-in the build.
-
-EAP methods must implement the interface defined in eap_i.h. struct
-eap_method defines the needed function pointers that each EAP method
-must provide. In addition, the EAP type and name are registered using
-this structure. This interface is based on section 4.4 of RFC 4137.
-
-It is recommended that the EAP methods would use generic helper
-functions, eap_msg_alloc() and eap_hdr_validate() when processing
-messages. This allows code sharing and can avoid missing some of the
-needed validation steps for received packets. In addition, these
-functions make it easier to change between expanded and legacy EAP
-header, if needed.
-
-When adding an EAP method that uses a vendor specific EAP type
-(Expanded Type as defined in RFC 3748, Chapter 5.7), the new method
-must be registered by passing vendor id instead of EAP_VENDOR_IETF to
-eap_peer_method_alloc(). These methods must not try to emulate
-expanded types by registering a legacy EAP method for type 254. See
-eap_vendor_test.c for an example of an EAP method implementation that
-is implemented as an expanded type.
-
-
-\section used_eap_library Using EAP implementation as a library
-
-The Git repository has an eap_example directory that contains an
-example showing how EAP peer and server code from %wpa_supplicant and
-hostapd can be used as a library. The example program initializes both
-an EAP server and an EAP peer entities and then runs through an
-EAP-PEAP/MSCHAPv2 authentication.
-
-eap_example_peer.c shows the initialization and glue code needed to
-control the EAP peer implementation. eap_example_server.c does the
-same for EAP server. eap_example.c is an example that ties in both the
-EAP server and client parts to allow an EAP authentication to be
-shown.
-
-In this example, the EAP messages are passed between the server and
-the peer are passed by direct function calls within the same process.
-In practice, server and peer functionalities would likely reside in
-separate devices and the EAP messages would be transmitted between the
-devices based on an external protocol. For example, in IEEE 802.11
-uses IEEE 802.1X EAPOL state machines to control the transmission of
-EAP messages and WiMax supports optional PMK EAP authentication
-mechanism that transmits EAP messages as defined in IEEE 802.16e.
-
-The EAP library links in number of helper functions from src/utils and
-src/crypto directories. Most of these are suitable as-is, but it may
-be desirable to replace the debug output code in src/utils/wpa_debug.c
-by dropping this file from the library and re-implementing the
-functions there in a way that better fits in with the main
-application.
-
-*/
diff --git a/contrib/wpa/wpa_supplicant/doc/kerneldoc2doxygen.pl b/contrib/wpa/wpa_supplicant/doc/kerneldoc2doxygen.pl
deleted file mode 100755
index 61bc367..0000000
--- a/contrib/wpa/wpa_supplicant/doc/kerneldoc2doxygen.pl
+++ /dev/null
@@ -1,134 +0,0 @@
-#!/usr/bin/perl -w
-#
-##########################################################################
-# Convert kernel-doc style comments to Doxygen comments.
-##########################################################################
-#
-# This script reads a C source file from stdin, and writes
-# to stdout. Normal usage:
-#
-# $ mv file.c file.c.gtkdoc
-# $ kerneldoc2doxygen.pl <file.c.gtkdoc >file.c
-#
-# Or to do the same thing with multiple files:
-# $ perl -i.gtkdoc kerneldoc2doxygen.pl *.c *.h
-#
-# This script may also be suitable for use as a Doxygen input filter,
-# but that has not been tested.
-#
-# Back up your source files before using this script!!
-#
-##########################################################################
-# Copyright (C) 2003 Jonathan Foster <jon@jon-foster.co.uk>
-# Copyright (C) 2005-2008 Jouni Malinen <j@w1.fi>
-# (modified for kerneldoc format used in wpa_supplicant)
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License version 2 as
-# published by the Free Software Foundation.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-# or look at http://www.gnu.org/licenses/gpl.html
-##########################################################################
-
-
-##########################################################################
-#
-# This function converts a single comment from gtk-doc to Doxygen format.
-# The parameter does not include the opening or closing lines
-# (i.e. given a comment like this:
-# "/**\n"
-# " * FunctionName:\n"
-# " * @foo: This describes the foo parameter\n"
-# " * @bar: This describes the bar parameter\n"
-# " * @Returns: This describes the return value\n"
-# " *\n"
-# " * This describes the function.\n"
-# " */\n"
-# This function gets:
-# " * FunctionName:\n"
-# " * @foo: This describes the foo parameter\n"
-# " * @bar: This describes the bar parameter\n"
-# " * @Returns: This describes the return value\n"
-# " *\n"
-# " * This describes the function.\n"
-# And it returns:
-# " * This describes the function.\n"
-# " *\n"
-# " * @param foo This describes the foo parameter\n"
-# " * @param bar This describes the bar parameter\n"
-# " * @return This describes the return value\n"
-# )
-#
-sub fixcomment {
- $t = $_[0];
-
- # wpa_supplicant -> %wpa_supplicant except for struct wpa_supplicant
- $t =~ s/struct wpa_supplicant/struct STRUCTwpa_supplicant/sg;
- $t =~ s/ wpa_supplicant/ \%wpa_supplicant/sg;
- $t =~ s/struct STRUCTwpa_supplicant/struct wpa_supplicant/sg;
-
- # " * func: foo" --> "\brief foo\n"
- # " * struct bar: foo" --> "\brief foo\n"
- # If this fails, not a kernel-doc comment ==> return unmodified.
- ($t =~ s/^[\t ]*\*[\t ]*(struct )?([^ \t\n]*) - ([^\n]*)/\\brief $3\n/s)
- or return $t;
-
- # " * Returns: foo" --> "\return foo"
- $t =~ s/\n[\t ]*\*[\t ]*Returns:/\n\\return/sig;
-
- # " * @foo: bar" --> "\param foo bar"
- # Handle two common typos: No ":", or "," instead of ":".
- $t =~ s/\n[\t ]*\*[\t ]*\@([^ :,]*)[:,]?[\t ]*/\n\\param $1 /sg;
-
- return $t;
-}
-
-##########################################################################
-# Start of main code
-
-# Read entire stdin into memory - one multi-line string.
-$_ = do { local $/; <> };
-
-s{^/\*\n \*}{/\*\* \\file\n\\brief};
-s{ \* Copyright}{\\par Copyright\nCopyright};
-
-# Fix any comments like "/*************" so they don't match.
-# "/***" ===> "/* *"
-s{/\*\*\*}{/\* \*}gs;
-
-# The main comment-detection code.
-s{
- ( # $1 = Open comment
- /\*\* # Open comment
- (?!\*) # Do not match /*** (redundant due to fixup above).
- [\t ]*\n? # If 1st line is whitespace, match the lot (including the newline).
- )
- (.*?) # $2 = Body of comment (multi-line)
- ( # $3 = Close comment
- ( # If possible, match the whitespace before the close-comment
- (?<=\n) # This part only matches after a newline
- [\t ]* # Eat whitespace
- )?
- \*/ # Close comment
- )
- }
- {
- $1 . fixcomment($2) . $3
- }gesx;
-# ^^^^ Modes: g - Global, match all occurances.
-# e - Evaluate the replacement as an expression.
-# s - Single-line - allows the pattern to match across newlines.
-# x - eXtended pattern, ignore embedded whitespace
-# and allow comments.
-
-# Write results to stdout
-print $_;
-
diff --git a/contrib/wpa/wpa_supplicant/doc/mainpage.doxygen b/contrib/wpa/wpa_supplicant/doc/mainpage.doxygen
deleted file mode 100644
index ed63f27..0000000
--- a/contrib/wpa/wpa_supplicant/doc/mainpage.doxygen
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
-\mainpage Developers' documentation for wpa_supplicant
-
-%wpa_supplicant is a WPA Supplicant for Linux, BSD and Windows with
-support for WPA and WPA2 (IEEE 802.11i / RSN). Supplicant is the IEEE
-802.1X/WPA component that is used in the client stations. It
-implements key negotiation with a WPA Authenticator and it can optionally
-control roaming and IEEE 802.11 authentication/association of the wlan
-driver.
-
-The goal of this documentation and comments in the source code is to
-give enough information for other developers to understand how
-%wpa_supplicant has been implemented, how it can be modified, how new
-drivers can be supported, and how %wpa_supplicant can be ported to
-other operating systems. If any information is missing, feel free to
-contact Jouni Malinen <j@w1.fi> for more
-information. Contributions as patch files are also very welcome at the
-same address. Please note that %wpa_supplicant is licensed under dual
-license, GPLv2 or BSD at user's choice. All contributions to
-%wpa_supplicant are expected to use compatible licensing terms.
-
-The source code and read-only access to %wpa_supplicant Git repository
-is available from the project home page at
-http://w1.fi/wpa_supplicant/. This developers' documentation
-is also available as a PDF file from
-http://w1.fi/wpa_supplicant/wpa_supplicant-devel.pdf .
-
-The design goal for %wpa_supplicant was to use hardware, driver, and
-OS independent, portable C code for all WPA functionality. The source
-code is divided into separate C files as shown on the \ref
-code_structure "code structure page". All hardware/driver specific
-functionality is in separate files that implement a \ref
-driver_wrapper "well-defined driver API". Information about porting
-to different target boards and operating systems is available on
-the \ref porting "porting page".
-
-EAPOL (IEEE 802.1X) state machines are implemented as a separate
-module that interacts with \ref eap_module "EAP peer implementation".
-In addition to programs aimed at normal production use,
-%wpa_supplicant source tree includes number of \ref testing_tools
-"testing and development tools" that make it easier to test the
-programs without having to setup a full test setup with wireless
-cards. These tools can also be used to implement automatic test
-suites.
-
-%wpa_supplicant implements a
-\ref ctrl_iface_page "control interface" that can be used by
-external programs to control the operations of the %wpa_supplicant
-daemon and to get status information and event notifications. There is
-a small C library that provides helper functions to facilitate the use of the
-control interface. This library can also be used with C++.
-
-\image html wpa_supplicant.png "wpa_supplicant modules"
-\image latex wpa_supplicant.eps "wpa_supplicant modules" width=15cm
-
-*/
diff --git a/contrib/wpa/wpa_supplicant/doc/porting.doxygen b/contrib/wpa/wpa_supplicant/doc/porting.doxygen
deleted file mode 100644
index 7ea6a34..0000000
--- a/contrib/wpa/wpa_supplicant/doc/porting.doxygen
+++ /dev/null
@@ -1,208 +0,0 @@
-/**
-\page porting Porting to different target boards and operating systems
-
-%wpa_supplicant was designed to be easily portable to different
-hardware (board, CPU) and software (OS, drivers) targets. It is
-already used with number of operating systems and numerous wireless
-card models and drivers. The main %wpa_supplicant repository includes
-support for Linux, FreeBSD, and Windows. In addition, the code has been
-ported to number of other operating systems like VxWorks, PalmOS,
-Windows CE, and Windows Mobile. On the hardware
-side, %wpa_supplicant is used on various systems: desktops, laptops,
-PDAs, and embedded devices with CPUs including x86, PowerPC,
-arm/xscale, and MIPS. Both big and little endian configurations are
-supported.
-
-
-\section ansi_c_extra Extra functions on top of ANSI C
-
-%wpa_supplicant is mostly using ANSI C functions that are available on
-most targets. However, couple of additional functions that are common
-on modern UNIX systems are used. Number of these are listed with
-prototypes in common.h (the \verbatim #ifdef CONFIG_ANSI_C_EXTRA \endverbatim
-block). These functions may need to be implemented or at least defined
-as macros to native functions in the target OS or C library.
-
-Many of the common ANSI C functions are used through a wrapper
-definitions in os.h to allow these to be replaced easily with a
-platform specific version in case standard C libraries are not
-available. In addition, os.h defines couple of common platform
-specific functions that are implemented in os_unix.c for UNIX like
-targets and in os_win32.c for Win32 API. If the target platform does
-not support either of these examples, a new os_*.c file may need to be
-added.
-
-Unless OS_NO_C_LIB_DEFINES is defined, the standard ANSI C and POSIX
-functions are used by defining the os_*() wrappers to use them
-directly in order to avoid extra cost in size and speed. If the target
-platform needs different versions of the functions, os.h can be
-modified to define the suitable macros or alternatively,
-OS_NO_C_LIB_DEFINES may be defined for the build and the wrapper
-functions can then be implemented in a new os_*.c wrapper file.
-
-common.h defines number of helper macros for handling integers of
-different size and byte order. Suitable version of these definitions
-may need to be added for the target platform.
-
-
-\section configuration_backend Configuration backend
-
-%wpa_supplicant implements a configuration interface that allows the
-backend to be easily replaced in order to read configuration data from
-a suitable source depending on the target platform. config.c
-implements the generic code that can be shared with all configuration
-backends. Each backend is implemented in its own config_*.c file.
-
-The included config_file.c backend uses a text file for configuration
-and config_winreg.c uses Windows registry. These files can be used as
-an example for a new configuration backend if the target platform uses
-different mechanism for configuration parameters. In addition,
-config_none.c can be used as an empty starting point for building a
-new configuration backend.
-
-
-\section driver_iface_porting Driver interface
-
-Unless the target OS and driver is already supported, most porting
-projects have to implement a driver wrapper. This may be done by
-adding a new driver interface module or modifying an existing module
-(driver_*.c) if the new target is similar to one of them. \ref
-driver_wrapper "Driver wrapper implementation" describes the details
-of the driver interface and discusses the tasks involved in porting
-this part of %wpa_supplicant.
-
-
-\section l2_packet_porting l2_packet (link layer access)
-
-%wpa_supplicant needs to have access to sending and receiving layer 2
-(link layer) packets with two Ethertypes: EAP-over-LAN (EAPOL) 0x888e
-and RSN pre-authentication 0x88c7. l2_packet.h defines the interfaces
-used for this in the core %wpa_supplicant implementation.
-
-If the target operating system supports a generic mechanism for link
-layer access, that is likely the best mechanism for providing the
-needed functionality for %wpa_supplicant. Linux packet socket is an
-example of such a generic mechanism. If this is not available, a
-separate interface may need to be implemented to the network stack or
-driver. This is usually an intermediate or protocol driver that is
-operating between the device driver and the OS network stack. If such
-a mechanism is not feasible, the interface can also be implemented
-directly in the device driver.
-
-The main %wpa_supplicant repository includes l2_packet implementations
-for Linux using packet sockets (l2_packet_linux.c), more portable
-version using libpcap/libdnet libraries (l2_packet_pcap.c; this
-supports WinPcap, too), and FreeBSD specific version of libpcap
-interface (l2_packet_freebsd.c).
-
-If the target operating system is supported by libpcap (receiving) and
-libdnet (sending), l2_packet_pcap.c can likely be used with minimal or
-no changes. If this is not a case or a proprietary interface for link
-layer is required, a new l2_packet module may need to be
-added. Alternatively, struct wpa_driver_ops::send_eapol() handler can
-be used to override the l2_packet library if the link layer access is
-integrated with the driver interface implementation.
-
-
-\section eloop_porting Event loop
-
-%wpa_supplicant uses a single process/thread model and an event loop
-to provide callbacks on events (registered timeout, received packet,
-signal). eloop.h defines the event loop interface. eloop.c is an
-implementation of such an event loop using select() and sockets. This
-is suitable for most UNIX/POSIX systems. When porting to other
-operating systems, it may be necessary to replace that implementation
-with OS specific mechanisms that provide similar functionality.
-
-
-\section ctrl_iface_porting Control interface
-
-%wpa_supplicant uses a \ref ctrl_iface_page "control interface"
-to allow external processed
-to get status information and to control the operations. Currently,
-this is implemented with socket based communication; both UNIX domain
-sockets and UDP sockets are supported. If the target OS does not
-support sockets, this interface will likely need to be modified to use
-another mechanism like message queues. The control interface is
-optional component, so it is also possible to run %wpa_supplicant
-without porting this part.
-
-The %wpa_supplicant side of the control interface is implemented in
-ctrl_iface.c. Matching client side is implemented as a control
-interface library in wpa_ctrl.c.
-
-
-\section entry_point Program entry point
-
-%wpa_supplicant defines a set of functions that can be used to
-initialize main supplicant processing. Each operating system has a
-mechanism for starting new processing or threads. This is usually a
-function with a specific set of arguments and calling convention. This
-function is responsible on initializing %wpa_supplicant.
-
-main.c includes an entry point for UNIX-like operating system, i.e.,
-main() function that uses command line arguments for setting
-parameters for %wpa_supplicant. When porting to other operating
-systems, similar OS-specific entry point implementation is needed. It
-can be implemented in a new file that is then linked with
-%wpa_supplicant instead of main.o. main.c is also a good example on
-how the initialization process should be done.
-
-The supplicant initialization functions are defined in
-wpa_supplicant_i.h. In most cases, the entry point function should
-start by fetching configuration parameters. After this, a global
-%wpa_supplicant context is initialized with a call to
-wpa_supplicant_init(). After this, existing network interfaces can be
-added with wpa_supplicant_add_iface(). wpa_supplicant_run() is then
-used to start the main event loop. Once this returns at program
-termination time, wpa_supplicant_deinit() is used to release global
-context data.
-
-wpa_supplicant_add_iface() and wpa_supplicant_remove_iface() can be
-used dynamically to add and remove interfaces based on when
-%wpa_supplicant processing is needed for them. This can be done, e.g.,
-when hotplug network adapters are being inserted and ejected. It is
-also possible to do this when a network interface is being
-enabled/disabled if it is desirable that %wpa_supplicant processing
-for the interface is fully enabled/disabled at the same time.
-
-
-\section simple_build Simple build example
-
-One way to start a porting project is to begin with a very simple
-build of %wpa_supplicant with WPA-PSK support and once that is
-building correctly, start adding features.
-
-Following command can be used to build very simple version of
-%wpa_supplicant:
-
-\verbatim
-cc -o wpa_supplicant config.c eloop.c common.c md5.c rc4.c sha1.c \
- config_none.c l2_packet_none.c tls_none.c wpa.c preauth.c \
- aes_wrap.c wpa_supplicant.c events.c main_none.c drivers.c
-\endverbatim
-
-The end result is not really very useful since it uses empty functions
-for configuration parsing and layer 2 packet access and does not
-include a driver interface. However, this is a good starting point
-since the build is complete in the sense that all functions are
-present and this is easy to configure to a build system by just
-including the listed C files.
-
-Once this version can be build successfully, the end result can be
-made functional by adding a proper program entry point (main*.c),
-driver interface (driver_*.c and matching CONFIG_DRIVER_* define for
-registration in drivers.c), configuration parser/writer (config_*.c),
-and layer 2 packet access implementation (l2_packet_*.c). After these
-components have been added, the end result should be a working
-WPA/WPA2-PSK enabled supplicant.
-
-After the basic functionality has been verified to work, more features
-can be added by linking in more files and defining C pre-processor
-defines. Currently, the best source of information for what options
-are available and which files needs to be included is in the Makefile
-used for building the supplicant with make. Similar configuration will
-be needed for build systems that either use different type of make
-tool or a GUI-based project configuration.
-
-*/
diff --git a/contrib/wpa/wpa_supplicant/doc/testing_tools.doxygen b/contrib/wpa/wpa_supplicant/doc/testing_tools.doxygen
deleted file mode 100644
index a2ae0c2..0000000
--- a/contrib/wpa/wpa_supplicant/doc/testing_tools.doxygen
+++ /dev/null
@@ -1,295 +0,0 @@
-/**
-\page testing_tools Testing and development tools
-
-[ \ref eapol_test "eapol_test" |
-\ref preauth_test "preauth_test" |
-\ref driver_test "driver_test" |
-\ref unit_tests "Unit tests" ]
-
-%wpa_supplicant source tree includes number of testing and development
-tools that make it easier to test the programs without having to setup
-a full test setup with wireless cards. In addition, these tools can be
-used to implement automatic tests suites.
-
-\section eapol_test eapol_test - EAP peer and RADIUS client testing
-
-eapol_test is a program that links together the same EAP peer
-implementation that %wpa_supplicant is using and the RADIUS
-authentication client code from hostapd. In addition, it has minimal
-glue code to combine these two components in similar ways to IEEE
-802.1X/EAPOL Authenticator state machines. In other words, it
-integrates IEEE 802.1X Authenticator (normally, an access point) and
-IEEE 802.1X Supplicant (normally, a wireless client) together to
-generate a single program that can be used to test EAP methods without
-having to setup an access point and a wireless client.
-
-The main uses for eapol_test are in interoperability testing of EAP
-methods against RADIUS servers and in development testing for new EAP
-methods. It can be easily used to automate EAP testing for
-interoperability and regression since the program can be run from
-shell scripts without require additional test components apart from a
-RADIUS server. For example, the automated EAP tests described in
-eap_testing.txt are implemented with eapol_test. Similarly, eapol_test
-could be used to implement an automated regression test suite for a
-RADIUS authentication server.
-
-eapol_test uses the same build time configuration file, .config, as
-%wpa_supplicant. This file is used to select which EAP methods are
-included in eapol_test. This program is not built with the default
-Makefile target, so a separate make command needs to be used to
-compile the tool:
-
-\verbatim
-make eapol_test
-\endverbatim
-
-The resulting eapol_test binary has following command like options:
-
-\verbatim
-usage:
-eapol_test [-nWS] -c<conf> [-a<AS IP>] [-p<AS port>] [-s<AS secret>] \
- [-r<count>] [-t<timeout>] [-C<Connect-Info>] \
- [-M<client MAC address>]
-eapol_test scard
-eapol_test sim <PIN> <num triplets> [debug]
-
-options:
- -c<conf> = configuration file
- -a<AS IP> = IP address of the authentication server, default 127.0.0.1
- -p<AS port> = UDP port of the authentication server, default 1812
- -s<AS secret> = shared secret with the authentication server, default 'radius'
- -r<count> = number of re-authentications
- -W = wait for a control interface monitor before starting
- -S = save configuration after authentiation
- -n = no MPPE keys expected
- -t<timeout> = sets timeout in seconds (default: 30 s)
- -C<Connect-Info> = RADIUS Connect-Info (default: CONNECT 11Mbps 802.11b)
- -M<client MAC address> = Set own MAC address (Calling-Station-Id,
- default: 02:00:00:00:00:01)
-\endverbatim
-
-
-As an example,
-\verbatim
-eapol_test -ctest.conf -a127.0.0.1 -p1812 -ssecret -r1
-\endverbatim
-tries to complete EAP authentication based on the network
-configuration from test.conf against the RADIUS server running on the
-local host. A re-authentication is triggered to test fast
-re-authentication. The configuration file uses the same format for
-network blocks as %wpa_supplicant.
-
-
-\section preauth_test preauth_test - WPA2 pre-authentication and EAP peer testing
-
-preauth_test is similar to eapol_test in the sense that in combines
-EAP peer implementation with something else, in this case, with WPA2
-pre-authentication. This tool can be used to test pre-authentication
-based on the code that %wpa_supplicant is using. As such, it tests
-both the %wpa_supplicant implementation and the functionality of an
-access point.
-
-preauth_test is built with:
-
-\verbatim
-make preauth_test
-\endverbatim
-
-and it uses following command line arguments:
-
-\verbatim
-usage: preauth_test <conf> <target MAC address> <ifname>
-\endverbatim
-
-For example,
-\verbatim
-preauth_test test.conf 02:11:22:33:44:55 eth0
-\endverbatim
-would use network configuration from test.conf to try to complete
-pre-authentication with AP using BSSID 02:11:22:33:44:55. The
-pre-authentication packets would be sent using the eth0 interface.
-
-
-\section driver_test driver_test - driver interface for testing wpa_supplicant
-
-%wpa_supplicant was designed to support number of different ways to
-communicate with a network device driver. This design uses \ref
-driver_wrapper "driver interface API" and number of driver interface
-implementations. One of these is driver_test.c, i.e., a test driver
-interface that is actually not using any drivers. Instead, it provides
-a mechanism for running %wpa_supplicant without having to have a
-device driver or wireless LAN hardware for that matter.
-
-driver_test can be used to talk directly with hostapd's driver_test
-component to create a test setup where one or more clients and access
-points can be tested within one test host and without having to have
-multiple wireless cards. This makes it easier to test the core code in
-%wpa_supplicant, and hostapd for that matter. Since driver_test uses
-the same driver API than any other driver interface implementation,
-the core code of %wpa_supplicant and hostapd can be tested with the
-same coverage as one would get when using real wireless cards. The
-only area that is not tested is the driver interface implementation
-(driver_*.c).
-
-Having the possibility to use simulated network components makes it
-much easier to do development testing while adding new features and to
-reproduce reported bugs. As such, it is often easiest to just do most
-of the development and bug fixing without using real hardware. Once
-the driver_test setup has been used to implement a new feature or fix
-a bug, the end result can be verified with wireless LAN cards. In many
-cases, this may even be unnecessary, depending on what area the
-feature/bug is relating to. Of course, changes to driver interfaces
-will still require use of real hardware.
-
-Since multiple components can be run within a single host, testing of
-complex network configuration, e.g., large number of clients
-association with an access point, becomes quite easy. All the tests
-can also be automated without having to resort to complex test setup
-using remote access to multiple computers.
-
-driver_test can be included in the %wpa_supplicant build in the same
-way as any other driver interface, i.e., by adding the following line
-into .config:
-
-\verbatim
-CONFIG_DRIVER_TEST=y
-\endverbatim
-
-When running %wpa_supplicant, the test interface is selected by using
-\a -Dtest command line argument. The interface name (\a -i argument)
-can be selected arbitrarily, i.e., it does not need to match with any
-existing network interface. The interface name is used to generate a
-MAC address, so when using multiple clients, each should use a
-different interface, e.g., \a sta1, \a sta2, and so on.
-
-%wpa_supplicant and hostapd are configured in the same way as they
-would be for normal use. Following example shows a simple test setup
-for WPA-PSK.
-
-hostapd is configured with following psk-test.conf configuration file:
-
-\verbatim
-driver=test
-
-interface=ap1
-logger_stdout=-1
-logger_stdout_level=0
-debug=2
-dump_file=/tmp/hostapd.dump
-
-test_socket=/tmp/Test/ap1
-
-ssid=jkm-test-psk
-
-wpa=1
-wpa_key_mgmt=WPA-PSK
-wpa_pairwise=TKIP
-wpa_passphrase=12345678
-\endverbatim
-
-and started with following command:
-
-\verbatim
-hostapd psk-test.conf
-\endverbatim
-
-%wpa_supplicant uses following configuration file:
-
-\verbatim
-driver_param=test_socket=/tmp/Test/ap1
-
-network={
- ssid="jkm-test-psk"
- key_mgmt=WPA-PSK
- psk="12345678"
-}
-\endverbatim
-
-%wpa_supplicant can then be started with following command:
-
-\verbatim
-wpa_supplicant -Dtest -cpsk-test.conf -ista1 -ddK
-\endverbatim
-
-If run without debug information, i.e., with
-
-\verbatim
-wpa_supplicant -Dtest -cpsk-test.conf -ista1
-\endverbatim
-
-%wpa_supplicant completes authentication and prints following events:
-
-\verbatim
-Trying to associate with 02:b8:a6:62:08:5a (SSID='jkm-test-psk' freq=0 MHz)
-Associated with 02:b8:a6:62:08:5a
-WPA: Key negotiation completed with 02:b8:a6:62:08:5a [PTK=TKIP GTK=TKIP]
-CTRL-EVENT-CONNECTED - Connection to 02:b8:a6:62:08:5a completed (auth)
-\endverbatim
-
-If test setup is using multiple clients, it is possible to run
-multiple %wpa_supplicant processes. Alternatively, the support for
-multiple interfaces can be used with just one process to save some
-resources on single-CPU systems. For example, following command runs
-two clients:
-
-\verbatim
-./wpa_supplicant -Dtest -cpsk-test.conf -ista1 \
- -N -Dtest -cpsk-test.conf -ista2
-\endverbatim
-
-This shows following event log:
-
-\verbatim
-Trying to associate with 02:b8:a6:62:08:5a (SSID='jkm-test-psk' freq=0 MHz)
-Associated with 02:b8:a6:62:08:5a
-WPA: Key negotiation completed with 02:b8:a6:62:08:5a [PTK=TKIP GTK=TKIP]
-CTRL-EVENT-CONNECTED - Connection to 02:b8:a6:62:08:5a completed (auth)
-Trying to associate with 02:b8:a6:62:08:5a (SSID='jkm-test-psk' freq=0 MHz)
-Associated with 02:b8:a6:62:08:5a
-WPA: Key negotiation completed with 02:b8:a6:62:08:5a [PTK=TKIP GTK=TKIP]
-CTRL-EVENT-CONNECTED - Connection to 02:b8:a6:62:08:5a completed (auth)
-\endverbatim
-
-hostapd shows this with following events:
-
-\verbatim
-ap1: STA 02:b5:64:63:30:63 IEEE 802.11: associated
-ap1: STA 02:b5:64:63:30:63 WPA: pairwise key handshake completed (WPA)
-ap1: STA 02:b5:64:63:30:63 WPA: group key handshake completed (WPA)
-ap1: STA 02:2a:c4:18:5b:f3 IEEE 802.11: associated
-ap1: STA 02:2a:c4:18:5b:f3 WPA: pairwise key handshake completed (WPA)
-ap1: STA 02:2a:c4:18:5b:f3 WPA: group key handshake completed (WPA)
-\endverbatim
-
-By default, driver_param is simulating a driver that uses the WPA/RSN
-IE generated by %wpa_supplicant. Driver-generated IE and AssocInfo
-events can be tested by adding \a use_associnfo=1 to the \a driver_param
-line in the configuration file. For example:
-
-\verbatim
-driver_param=test_socket=/tmp/Test/ap1 use_associnfo=1
-\endverbatim
-
-
-\section unit_tests Unit tests
-
-Number of the components (.c files) used in %wpa_supplicant define
-their own unit tests for automated validation of the basic
-functionality. Most of the tests for cryptographic algorithms are
-using standard test vectors to validate functionality. These tests can
-be useful especially when verifying port to a new CPU target.
-
-In most cases, these tests are implemented in the end of the same file
-with functions that are normally commented out, but ca be included by
-defining a pre-processor variable when building the file separately.
-The details of the needed build options are included in the Makefile
-(test-* targets). All automated unit tests can be run with
-
-\verbatim
-make tests
-\endverbatim
-
-This make target builds and runs each test and terminates with zero
-exit code if all tests were completed successfully.
-
-*/
diff --git a/contrib/wpa/wpa_supplicant/doc/wpa_supplicant.fig b/contrib/wpa/wpa_supplicant/doc/wpa_supplicant.fig
deleted file mode 100644
index 06abfb5..0000000
--- a/contrib/wpa/wpa_supplicant/doc/wpa_supplicant.fig
+++ /dev/null
@@ -1,247 +0,0 @@
-#FIG 3.2
-Landscape
-Center
-Inches
-Letter
-100.00
-Single
--2
-1200 2
-6 1875 4050 2925 4350
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 1875 4050 2925 4050 2925 4350 1875 4350 1875 4050
-4 0 0 50 -1 0 12 0.0000 4 180 735 2025 4275 l2_packet\001
--6
-6 3450 1200 4275 1500
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 3450 1200 4275 1200 4275 1500 3450 1500 3450 1200
-4 0 0 50 -1 0 12 0.0000 4 180 585 3600 1425 wpa_cli\001
--6
-6 4725 1200 5925 1500
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 4725 1200 5925 1200 5925 1500 4725 1500 4725 1200
-4 0 0 50 -1 0 12 0.0000 4 135 1005 4800 1425 GUI frontend\001
--6
-6 6000 2700 7200 3225
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 6000 2700 7200 2700 7200 3225 6000 3225 6000 2700
-4 0 0 50 -1 0 12 0.0000 4 135 975 6075 2925 WPA/WPA2\001
-4 0 0 50 -1 0 12 0.0000 4 135 1065 6075 3150 state machine\001
--6
-6 6000 4950 7200 5475
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 6000 4950 7200 4950 7200 5475 6000 5475 6000 4950
-4 0 0 50 -1 0 12 0.0000 4 135 360 6075 5175 EAP\001
-4 0 0 50 -1 0 12 0.0000 4 135 1065 6075 5400 state machine\001
--6
-6 8700 3000 9375 3300
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 8700 3000 9375 3000 9375 3300 8700 3300 8700 3000
-4 0 0 50 -1 0 12 0.0000 4 150 480 8775 3225 crypto\001
--6
-6 4350 3900 5025 4425
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 4350 3900 5025 3900 5025 4425 4350 4425 4350 3900
-4 0 0 50 -1 0 12 0.0000 4 105 420 4500 4125 event\001
-4 0 0 50 -1 0 12 0.0000 4 180 315 4500 4350 loop\001
--6
-6 4275 2550 5100 2850
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 4275 2550 5100 2550 5100 2850 4275 2850 4275 2550
-4 0 0 50 -1 0 12 0.0000 4 135 450 4425 2775 ctrl i/f\001
--6
-6 6000 3900 7200 4425
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 6000 3900 7200 3900 7200 4425 6000 4425 6000 3900
-4 0 0 50 -1 0 12 0.0000 4 135 600 6075 4125 EAPOL\001
-4 0 0 50 -1 0 12 0.0000 4 135 1065 6075 4350 state machine\001
--6
-6 1800 6000 7800 8100
-6 1800 6000 7800 7200
-6 1800 6900 2700 7200
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 1800 6900 2700 6900 2700 7200 1800 7200 1800 6900
-4 0 0 50 -1 0 12 0.0000 4 105 375 1875 7125 wext\001
--6
-6 4725 6900 5625 7200
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 4725 6900 5625 6900 5625 7200 4725 7200 4725 6900
-4 0 0 50 -1 0 12 0.0000 4 135 555 4800 7125 hermes\001
--6
-6 6675 6900 7800 7200
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 6675 6900 7800 6900 7800 7200 6675 7200 6675 6900
-4 0 0 50 -1 0 12 0.0000 4 180 930 6750 7125 ndiswrapper\001
--6
-6 5700 6900 6600 7200
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 5700 6900 6600 6900 6600 7200 5700 7200 5700 6900
-4 0 0 50 -1 0 12 0.0000 4 135 420 5775 7125 atmel\001
--6
-6 4275 6000 5100 6300
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 4275 6000 5100 6000 5100 6300 4275 6300 4275 6000
-4 0 0 50 -1 0 12 0.0000 4 135 630 4350 6225 driver i/f\001
--6
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 2775 6900 3675 6900 3675 7200 2775 7200 2775 6900
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 3750 6900 4650 6900 4650 7200 3750 7200 3750 6900
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 4
- 2250 6900 2250 6600 7200 6600 7200 6900
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 3225 6900 3225 6600
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 4200 6900 4200 6600
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 5175 6900 5175 6600
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 6150 6900 6150 6600
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 4650 6600 4650 6300
-4 0 0 50 -1 0 12 0.0000 4 180 510 2850 7125 hostap\001
-4 0 0 50 -1 0 12 0.0000 4 135 600 3825 7125 madwifi\001
--6
-6 3525 7800 5775 8100
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 3525 7800 5775 7800 5775 8100 3525 8100 3525 7800
-4 0 0 50 -1 0 12 0.0000 4 135 2145 3600 8025 kernel network device driver\001
--6
-2 1 1 1 0 7 50 -1 -1 4.000 0 0 -1 0 0 2
- 2250 7200 4200 7800
-2 1 1 1 0 7 50 -1 -1 4.000 0 0 -1 0 0 2
- 7200 7200 5100 7800
--6
-6 9600 3000 10275 3300
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 9600 3000 10275 3000 10275 3300 9600 3300 9600 3000
-4 0 0 50 -1 0 12 0.0000 4 135 315 9750 3225 TLS\001
--6
-6 8100 4425 10425 7350
-6 8175 4725 9225 5025
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 8175 4725 9225 4725 9225 5025 8175 5025 8175 4725
-4 0 0 50 -1 0 12 0.0000 4 135 735 8250 4950 EAP-TLS\001
--6
-6 9300 4725 10350 5025
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 9300 4725 10350 4725 10350 5025 9300 5025 9300 4725
-4 0 0 50 -1 0 12 0.0000 4 135 810 9375 4950 EAP-MD5\001
--6
-6 8175 5100 9225 5400
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 8175 5100 9225 5100 9225 5400 8175 5400 8175 5100
-4 0 0 50 -1 0 12 0.0000 4 135 885 8250 5325 EAP-PEAP\001
--6
-6 9300 5100 10350 5400
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 9300 5100 10350 5100 10350 5400 9300 5400 9300 5100
-4 0 0 50 -1 0 12 0.0000 4 135 840 9375 5325 EAP-TTLS\001
--6
-6 8175 5475 9225 5775
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 8175 5475 9225 5475 9225 5775 8175 5775 8175 5475
-4 0 0 50 -1 0 12 0.0000 4 135 780 8250 5700 EAP-GTC\001
--6
-6 9300 5475 10350 5775
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 9300 5475 10350 5475 10350 5775 9300 5775 9300 5475
-4 0 0 50 -1 0 12 0.0000 4 135 765 9375 5700 EAP-OTP\001
--6
-6 8175 5850 9225 6150
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 8175 5850 9225 5850 9225 6150 8175 6150 8175 5850
-4 0 0 50 -1 0 12 0.0000 4 135 750 8250 6075 EAP-SIM\001
--6
-6 9300 6225 10350 6525
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 9300 6225 10350 6225 10350 6525 9300 6525 9300 6225
-4 0 0 50 -1 0 12 0.0000 4 135 465 9375 6450 LEAP\001
--6
-6 8175 6225 9225 6525
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 8175 6225 9225 6225 9225 6525 8175 6525 8175 6225
-4 0 0 50 -1 0 12 0.0000 4 135 765 8250 6450 EAP-PSK\001
--6
-6 9300 5850 10350 6150
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 9300 5850 10350 5850 10350 6150 9300 6150 9300 5850
-4 0 0 50 -1 0 12 0.0000 4 135 825 9375 6075 EAP-AKA\001
--6
-6 8175 6975 9675 7275
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 8175 6975 9675 6975 9675 7275 8175 7275 8175 6975
-4 0 0 50 -1 0 12 0.0000 4 135 1365 8250 7200 EAP-MSCHAPv2\001
--6
-6 9300 6600 10350 6900
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 9300 6600 10350 6600 10350 6900 9300 6900 9300 6600
-4 0 0 50 -1 0 12 0.0000 4 135 870 9375 6825 EAP-FAST\001
--6
-6 8175 6600 9225 6900
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 8175 6600 9225 6600 9225 6900 8175 6900 8175 6600
-4 0 0 50 -1 0 12 0.0000 4 135 795 8250 6825 EAP-PAX\001
--6
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 8100 7350 10425 7350 10425 4425 8100 4425 8100 7350
-4 0 0 50 -1 0 12 0.0000 4 135 1050 8700 4650 EAP methods\001
--6
-6 2775 5025 4050 5325
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 2775 5025 4050 5025 4050 5325 2775 5325 2775 5025
-4 0 0 50 -1 0 12 0.0000 4 135 990 2925 5250 driver events\001
--6
-6 2775 3150 4050 3450
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 2775 3150 4050 3150 4050 3450 2775 3450 2775 3150
-4 0 0 50 -1 0 12 0.0000 4 180 990 2925 3375 configuration\001
--6
-2 1 1 1 0 7 50 -1 -1 3.000 0 0 -1 0 0 2
- 1275 4200 1875 4200
-2 1 1 1 0 7 50 -1 -1 4.000 0 0 -1 0 0 2
- 4500 2550 3900 1500
-2 1 1 1 0 7 50 -1 -1 4.000 0 0 -1 0 0 2
- 4800 2550 5400 1500
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 2925 4200 4350 4200
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 5025 3900 6000 3000
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 5025 4200 6000 4200
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 4650 6000 4650 4425
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 6600 4425 6600 4950
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 6600 3225 6600 3900
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 7200 5250 8100 5250
-2 1 0 1 2 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 9075 4425 9075 3300
-2 1 0 1 2 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 7200 3000 8700 3150
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 4650 3900 4650 2850
-2 1 0 1 2 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 7200 4125 8700 3300
-2 1 0 1 2 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 6000 4350 5025 6000
-2 1 0 1 2 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 6000 3150 4875 6000
-2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
- 1500 2100 10800 2100 10800 7500 1500 7500 1500 2100
-2 1 0 1 2 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 9900 4425 9900 3300
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 1
- 4350 3900
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 4350 3900 4050 3450
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
- 4350 4425 4050 5025
-4 0 0 50 -1 0 12 0.0000 4 135 915 375 3975 EAPOL and\001
-4 0 0 50 -1 0 12 0.0000 4 180 630 375 4200 pre-auth\001
-4 0 0 50 -1 0 12 0.0000 4 180 810 375 4425 ethertypes\001
-4 0 0 50 -1 0 12 0.0000 4 135 1050 375 4650 from/to kernel\001
-4 0 0 50 -1 0 12 0.0000 4 135 1920 3675 1875 frontend control interface\001
-4 0 0 50 -1 2 14 0.0000 4 210 1440 1637 2371 wpa_supplicant\001
diff --git a/contrib/wpa/wpa_supplicant/driver_i.h b/contrib/wpa/wpa_supplicant/driver_i.h
new file mode 100644
index 0000000..a70aa6a
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/driver_i.h
@@ -0,0 +1,494 @@
+/*
+ * wpa_supplicant - Internal driver interface wrappers
+ * Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef DRIVER_I_H
+#define DRIVER_I_H
+
+#include "drivers/driver.h"
+
+/* driver_ops */
+static inline void * wpa_drv_init(struct wpa_supplicant *wpa_s,
+ const char *ifname)
+{
+ if (wpa_s->driver->init2)
+ return wpa_s->driver->init2(wpa_s, ifname,
+ wpa_s->global_drv_priv);
+ if (wpa_s->driver->init) {
+ return wpa_s->driver->init(wpa_s, ifname);
+ }
+ return NULL;
+}
+
+static inline void wpa_drv_deinit(struct wpa_supplicant *wpa_s)
+{
+ if (wpa_s->driver->deinit)
+ wpa_s->driver->deinit(wpa_s->drv_priv);
+}
+
+static inline int wpa_drv_set_param(struct wpa_supplicant *wpa_s,
+ const char *param)
+{
+ if (wpa_s->driver->set_param)
+ return wpa_s->driver->set_param(wpa_s->drv_priv, param);
+ return 0;
+}
+
+static inline int wpa_drv_set_countermeasures(struct wpa_supplicant *wpa_s,
+ int enabled)
+{
+ if (wpa_s->driver->set_countermeasures) {
+ return wpa_s->driver->set_countermeasures(wpa_s->drv_priv,
+ enabled);
+ }
+ return -1;
+}
+
+static inline int wpa_drv_authenticate(struct wpa_supplicant *wpa_s,
+ struct wpa_driver_auth_params *params)
+{
+ if (wpa_s->driver->authenticate)
+ return wpa_s->driver->authenticate(wpa_s->drv_priv, params);
+ return -1;
+}
+
+static inline int wpa_drv_associate(struct wpa_supplicant *wpa_s,
+ struct wpa_driver_associate_params *params)
+{
+ if (wpa_s->driver->associate) {
+ return wpa_s->driver->associate(wpa_s->drv_priv, params);
+ }
+ return -1;
+}
+
+static inline int wpa_drv_scan(struct wpa_supplicant *wpa_s,
+ struct wpa_driver_scan_params *params)
+{
+ if (wpa_s->driver->scan2)
+ return wpa_s->driver->scan2(wpa_s->drv_priv, params);
+ return -1;
+}
+
+static inline struct wpa_scan_results * wpa_drv_get_scan_results2(
+ struct wpa_supplicant *wpa_s)
+{
+ if (wpa_s->driver->get_scan_results2)
+ return wpa_s->driver->get_scan_results2(wpa_s->drv_priv);
+ return NULL;
+}
+
+static inline int wpa_drv_get_bssid(struct wpa_supplicant *wpa_s, u8 *bssid)
+{
+ if (wpa_s->driver->get_bssid) {
+ return wpa_s->driver->get_bssid(wpa_s->drv_priv, bssid);
+ }
+ return -1;
+}
+
+static inline int wpa_drv_get_ssid(struct wpa_supplicant *wpa_s, u8 *ssid)
+{
+ if (wpa_s->driver->get_ssid) {
+ return wpa_s->driver->get_ssid(wpa_s->drv_priv, ssid);
+ }
+ return -1;
+}
+
+static inline int wpa_drv_set_key(struct wpa_supplicant *wpa_s,
+ enum wpa_alg alg, const u8 *addr,
+ int key_idx, int set_tx,
+ const u8 *seq, size_t seq_len,
+ const u8 *key, size_t key_len)
+{
+ if (wpa_s->driver->set_key) {
+ wpa_s->keys_cleared = 0;
+ return wpa_s->driver->set_key(wpa_s->ifname, wpa_s->drv_priv,
+ alg, addr, key_idx, set_tx,
+ seq, seq_len, key, key_len);
+ }
+ return -1;
+}
+
+static inline int wpa_drv_deauthenticate(struct wpa_supplicant *wpa_s,
+ const u8 *addr, int reason_code)
+{
+ if (wpa_s->driver->deauthenticate) {
+ return wpa_s->driver->deauthenticate(wpa_s->drv_priv, addr,
+ reason_code);
+ }
+ return -1;
+}
+
+static inline int wpa_drv_disassociate(struct wpa_supplicant *wpa_s,
+ const u8 *addr, int reason_code)
+{
+ if (wpa_s->driver->disassociate) {
+ return wpa_s->driver->disassociate(wpa_s->drv_priv, addr,
+ reason_code);
+ }
+ return -1;
+}
+
+static inline int wpa_drv_add_pmkid(struct wpa_supplicant *wpa_s,
+ const u8 *bssid, const u8 *pmkid)
+{
+ if (wpa_s->driver->add_pmkid) {
+ return wpa_s->driver->add_pmkid(wpa_s->drv_priv, bssid, pmkid);
+ }
+ return -1;
+}
+
+static inline int wpa_drv_remove_pmkid(struct wpa_supplicant *wpa_s,
+ const u8 *bssid, const u8 *pmkid)
+{
+ if (wpa_s->driver->remove_pmkid) {
+ return wpa_s->driver->remove_pmkid(wpa_s->drv_priv, bssid,
+ pmkid);
+ }
+ return -1;
+}
+
+static inline int wpa_drv_flush_pmkid(struct wpa_supplicant *wpa_s)
+{
+ if (wpa_s->driver->flush_pmkid) {
+ return wpa_s->driver->flush_pmkid(wpa_s->drv_priv);
+ }
+ return -1;
+}
+
+static inline int wpa_drv_get_capa(struct wpa_supplicant *wpa_s,
+ struct wpa_driver_capa *capa)
+{
+ if (wpa_s->driver->get_capa) {
+ return wpa_s->driver->get_capa(wpa_s->drv_priv, capa);
+ }
+ return -1;
+}
+
+static inline void wpa_drv_poll(struct wpa_supplicant *wpa_s)
+{
+ if (wpa_s->driver->poll) {
+ wpa_s->driver->poll(wpa_s->drv_priv);
+ }
+}
+
+static inline const char * wpa_drv_get_ifname(struct wpa_supplicant *wpa_s)
+{
+ if (wpa_s->driver->get_ifname) {
+ return wpa_s->driver->get_ifname(wpa_s->drv_priv);
+ }
+ return NULL;
+}
+
+static inline const u8 * wpa_drv_get_mac_addr(struct wpa_supplicant *wpa_s)
+{
+ if (wpa_s->driver->get_mac_addr) {
+ return wpa_s->driver->get_mac_addr(wpa_s->drv_priv);
+ }
+ return NULL;
+}
+
+static inline int wpa_drv_send_eapol(struct wpa_supplicant *wpa_s,
+ const u8 *dst, u16 proto,
+ const u8 *data, size_t data_len)
+{
+ if (wpa_s->driver->send_eapol)
+ return wpa_s->driver->send_eapol(wpa_s->drv_priv, dst, proto,
+ data, data_len);
+ return -1;
+}
+
+static inline int wpa_drv_set_operstate(struct wpa_supplicant *wpa_s,
+ int state)
+{
+ if (wpa_s->driver->set_operstate)
+ return wpa_s->driver->set_operstate(wpa_s->drv_priv, state);
+ return 0;
+}
+
+static inline int wpa_drv_mlme_setprotection(struct wpa_supplicant *wpa_s,
+ const u8 *addr, int protect_type,
+ int key_type)
+{
+ if (wpa_s->driver->mlme_setprotection)
+ return wpa_s->driver->mlme_setprotection(wpa_s->drv_priv, addr,
+ protect_type,
+ key_type);
+ return 0;
+}
+
+static inline struct hostapd_hw_modes *
+wpa_drv_get_hw_feature_data(struct wpa_supplicant *wpa_s, u16 *num_modes,
+ u16 *flags)
+{
+ if (wpa_s->driver->get_hw_feature_data)
+ return wpa_s->driver->get_hw_feature_data(wpa_s->drv_priv,
+ num_modes, flags);
+ return NULL;
+}
+
+static inline int wpa_drv_set_channel(struct wpa_supplicant *wpa_s,
+ enum hostapd_hw_mode phymode, int chan,
+ int freq)
+{
+ if (wpa_s->driver->set_channel)
+ return wpa_s->driver->set_channel(wpa_s->drv_priv, phymode,
+ chan, freq);
+ return -1;
+}
+
+static inline int wpa_drv_set_ssid(struct wpa_supplicant *wpa_s,
+ const u8 *ssid, size_t ssid_len)
+{
+ if (wpa_s->driver->set_ssid) {
+ return wpa_s->driver->set_ssid(wpa_s->drv_priv, ssid,
+ ssid_len);
+ }
+ return -1;
+}
+
+static inline int wpa_drv_set_bssid(struct wpa_supplicant *wpa_s,
+ const u8 *bssid)
+{
+ if (wpa_s->driver->set_bssid) {
+ return wpa_s->driver->set_bssid(wpa_s->drv_priv, bssid);
+ }
+ return -1;
+}
+
+static inline int wpa_drv_set_country(struct wpa_supplicant *wpa_s,
+ const char *alpha2)
+{
+ if (wpa_s->driver->set_country)
+ return wpa_s->driver->set_country(wpa_s->drv_priv, alpha2);
+ return 0;
+}
+
+static inline int wpa_drv_send_mlme(struct wpa_supplicant *wpa_s,
+ const u8 *data, size_t data_len)
+{
+ if (wpa_s->driver->send_mlme)
+ return wpa_s->driver->send_mlme(wpa_s->drv_priv,
+ data, data_len);
+ return -1;
+}
+
+static inline int wpa_drv_mlme_add_sta(struct wpa_supplicant *wpa_s,
+ const u8 *addr, const u8 *supp_rates,
+ size_t supp_rates_len)
+{
+ if (wpa_s->driver->mlme_add_sta)
+ return wpa_s->driver->mlme_add_sta(wpa_s->drv_priv, addr,
+ supp_rates, supp_rates_len);
+ return -1;
+}
+
+static inline int wpa_drv_mlme_remove_sta(struct wpa_supplicant *wpa_s,
+ const u8 *addr)
+{
+ if (wpa_s->driver->mlme_remove_sta)
+ return wpa_s->driver->mlme_remove_sta(wpa_s->drv_priv, addr);
+ return -1;
+}
+
+static inline int wpa_drv_update_ft_ies(struct wpa_supplicant *wpa_s,
+ const u8 *md,
+ const u8 *ies, size_t ies_len)
+{
+ if (wpa_s->driver->update_ft_ies)
+ return wpa_s->driver->update_ft_ies(wpa_s->drv_priv, md,
+ ies, ies_len);
+ return -1;
+}
+
+static inline int wpa_drv_send_ft_action(struct wpa_supplicant *wpa_s,
+ u8 action, const u8 *target_ap,
+ const u8 *ies, size_t ies_len)
+{
+ if (wpa_s->driver->send_ft_action)
+ return wpa_s->driver->send_ft_action(wpa_s->drv_priv, action,
+ target_ap, ies, ies_len);
+ return -1;
+}
+
+static inline int wpa_drv_set_beacon(struct wpa_supplicant *wpa_s,
+ const u8 *head, size_t head_len,
+ const u8 *tail, size_t tail_len,
+ int dtim_period, int beacon_int)
+{
+ if (wpa_s->driver->set_beacon)
+ return wpa_s->driver->set_beacon(wpa_s->drv_priv, head,
+ head_len, tail, tail_len,
+ dtim_period, beacon_int);
+ return -1;
+}
+
+static inline int wpa_drv_sta_add(struct wpa_supplicant *wpa_s,
+ struct hostapd_sta_add_params *params)
+{
+ if (wpa_s->driver->sta_add)
+ return wpa_s->driver->sta_add(wpa_s->drv_priv, params);
+ return -1;
+}
+
+static inline int wpa_drv_sta_remove(struct wpa_supplicant *wpa_s,
+ const u8 *addr)
+{
+ if (wpa_s->driver->sta_remove)
+ return wpa_s->driver->sta_remove(wpa_s->drv_priv, addr);
+ return -1;
+}
+
+static inline int wpa_drv_hapd_send_eapol(struct wpa_supplicant *wpa_s,
+ const u8 *addr, const u8 *data,
+ size_t data_len, int encrypt,
+ const u8 *own_addr)
+{
+ if (wpa_s->driver->hapd_send_eapol)
+ return wpa_s->driver->hapd_send_eapol(wpa_s->drv_priv, addr,
+ data, data_len, encrypt,
+ own_addr);
+ return -1;
+}
+
+static inline int wpa_drv_sta_set_flags(struct wpa_supplicant *wpa_s,
+ const u8 *addr, int total_flags,
+ int flags_or, int flags_and)
+{
+ if (wpa_s->driver->sta_set_flags)
+ return wpa_s->driver->sta_set_flags(wpa_s->drv_priv, addr,
+ total_flags, flags_or,
+ flags_and);
+ return -1;
+}
+
+static inline int wpa_drv_set_supp_port(struct wpa_supplicant *wpa_s,
+ int authorized)
+{
+ if (wpa_s->driver->set_supp_port) {
+ return wpa_s->driver->set_supp_port(wpa_s->drv_priv,
+ authorized);
+ }
+ return 0;
+}
+
+static inline int wpa_drv_send_action(struct wpa_supplicant *wpa_s,
+ unsigned int freq,
+ const u8 *dst, const u8 *src,
+ const u8 *bssid,
+ const u8 *data, size_t data_len)
+{
+ if (wpa_s->driver->send_action)
+ return wpa_s->driver->send_action(wpa_s->drv_priv, freq,
+ dst, src, bssid, data,
+ data_len);
+ return -1;
+}
+
+static inline int wpa_drv_if_add(struct wpa_supplicant *wpa_s,
+ enum wpa_driver_if_type type,
+ const char *ifname, const u8 *addr,
+ void *bss_ctx, char *force_ifname,
+ u8 *if_addr)
+{
+ if (wpa_s->driver->if_add)
+ return wpa_s->driver->if_add(wpa_s->drv_priv, type, ifname,
+ addr, bss_ctx, NULL, force_ifname,
+ if_addr);
+ return -1;
+}
+
+static inline int wpa_drv_if_remove(struct wpa_supplicant *wpa_s,
+ enum wpa_driver_if_type type,
+ const char *ifname)
+{
+ if (wpa_s->driver->if_remove)
+ return wpa_s->driver->if_remove(wpa_s->drv_priv, type, ifname);
+ return -1;
+}
+
+static inline int wpa_drv_remain_on_channel(struct wpa_supplicant *wpa_s,
+ unsigned int freq,
+ unsigned int duration)
+{
+ if (wpa_s->driver->remain_on_channel)
+ return wpa_s->driver->remain_on_channel(wpa_s->drv_priv, freq,
+ duration);
+ return -1;
+}
+
+static inline int wpa_drv_cancel_remain_on_channel(
+ struct wpa_supplicant *wpa_s)
+{
+ if (wpa_s->driver->cancel_remain_on_channel)
+ return wpa_s->driver->cancel_remain_on_channel(
+ wpa_s->drv_priv);
+ return -1;
+}
+
+static inline int wpa_drv_probe_req_report(struct wpa_supplicant *wpa_s,
+ int report)
+{
+ if (wpa_s->driver->probe_req_report)
+ return wpa_s->driver->probe_req_report(wpa_s->drv_priv,
+ report);
+ return -1;
+}
+
+static inline int wpa_drv_disable_11b_rates(struct wpa_supplicant *wpa_s,
+ int disabled)
+{
+ if (wpa_s->driver->disable_11b_rates)
+ return wpa_s->driver->disable_11b_rates(wpa_s->drv_priv,
+ disabled);
+ return -1;
+}
+
+static inline int wpa_drv_deinit_ap(struct wpa_supplicant *wpa_s)
+{
+ if (wpa_s->driver->deinit_ap)
+ return wpa_s->driver->deinit_ap(wpa_s->drv_priv);
+ return 0;
+}
+
+static inline void wpa_drv_suspend(struct wpa_supplicant *wpa_s)
+{
+ if (wpa_s->driver->suspend)
+ wpa_s->driver->suspend(wpa_s->drv_priv);
+}
+
+static inline void wpa_drv_resume(struct wpa_supplicant *wpa_s)
+{
+ if (wpa_s->driver->resume)
+ wpa_s->driver->resume(wpa_s->drv_priv);
+}
+
+static inline int wpa_drv_signal_monitor(struct wpa_supplicant *wpa_s,
+ int threshold, int hysteresis)
+{
+ if (wpa_s->driver->signal_monitor)
+ return wpa_s->driver->signal_monitor(wpa_s->drv_priv,
+ threshold, hysteresis);
+ return -1;
+}
+
+static inline int wpa_drv_set_ap_wps_ie(struct wpa_supplicant *wpa_s,
+ const struct wpabuf *beacon,
+ const struct wpabuf *proberesp)
+{
+ if (!wpa_s->driver->set_ap_wps_ie)
+ return -1;
+ return wpa_s->driver->set_ap_wps_ie(wpa_s->drv_priv, beacon,
+ proberesp);
+}
+
+#endif /* DRIVER_I_H */
diff --git a/contrib/wpa/wpa_supplicant/eap_register.c b/contrib/wpa/wpa_supplicant/eap_register.c
new file mode 100644
index 0000000..f668874
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/eap_register.c
@@ -0,0 +1,235 @@
+/*
+ * EAP method registration
+ * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "eap_peer/eap_methods.h"
+#include "eap_server/eap_methods.h"
+
+
+/**
+ * eap_register_methods - Register statically linked EAP methods
+ * Returns: 0 on success, -1 or -2 on failure
+ *
+ * This function is called at program initialization to register all EAP
+ * methods that were linked in statically.
+ */
+int eap_register_methods(void)
+{
+ int ret = 0;
+
+#ifdef EAP_MD5
+ if (ret == 0)
+ ret = eap_peer_md5_register();
+#endif /* EAP_MD5 */
+
+#ifdef EAP_TLS
+ if (ret == 0)
+ ret = eap_peer_tls_register();
+#endif /* EAP_TLS */
+
+#ifdef EAP_MSCHAPv2
+ if (ret == 0)
+ ret = eap_peer_mschapv2_register();
+#endif /* EAP_MSCHAPv2 */
+
+#ifdef EAP_PEAP
+ if (ret == 0)
+ ret = eap_peer_peap_register();
+#endif /* EAP_PEAP */
+
+#ifdef EAP_TTLS
+ if (ret == 0)
+ ret = eap_peer_ttls_register();
+#endif /* EAP_TTLS */
+
+#ifdef EAP_GTC
+ if (ret == 0)
+ ret = eap_peer_gtc_register();
+#endif /* EAP_GTC */
+
+#ifdef EAP_OTP
+ if (ret == 0)
+ ret = eap_peer_otp_register();
+#endif /* EAP_OTP */
+
+#ifdef EAP_SIM
+ if (ret == 0)
+ ret = eap_peer_sim_register();
+#endif /* EAP_SIM */
+
+#ifdef EAP_LEAP
+ if (ret == 0)
+ ret = eap_peer_leap_register();
+#endif /* EAP_LEAP */
+
+#ifdef EAP_PSK
+ if (ret == 0)
+ ret = eap_peer_psk_register();
+#endif /* EAP_PSK */
+
+#ifdef EAP_AKA
+ if (ret == 0)
+ ret = eap_peer_aka_register();
+#endif /* EAP_AKA */
+
+#ifdef EAP_AKA_PRIME
+ if (ret == 0)
+ ret = eap_peer_aka_prime_register();
+#endif /* EAP_AKA_PRIME */
+
+#ifdef EAP_FAST
+ if (ret == 0)
+ ret = eap_peer_fast_register();
+#endif /* EAP_FAST */
+
+#ifdef EAP_PAX
+ if (ret == 0)
+ ret = eap_peer_pax_register();
+#endif /* EAP_PAX */
+
+#ifdef EAP_SAKE
+ if (ret == 0)
+ ret = eap_peer_sake_register();
+#endif /* EAP_SAKE */
+
+#ifdef EAP_GPSK
+ if (ret == 0)
+ ret = eap_peer_gpsk_register();
+#endif /* EAP_GPSK */
+
+#ifdef EAP_WSC
+ if (ret == 0)
+ ret = eap_peer_wsc_register();
+#endif /* EAP_WSC */
+
+#ifdef EAP_IKEV2
+ if (ret == 0)
+ ret = eap_peer_ikev2_register();
+#endif /* EAP_IKEV2 */
+
+#ifdef EAP_VENDOR_TEST
+ if (ret == 0)
+ ret = eap_peer_vendor_test_register();
+#endif /* EAP_VENDOR_TEST */
+
+#ifdef EAP_TNC
+ if (ret == 0)
+ ret = eap_peer_tnc_register();
+#endif /* EAP_TNC */
+
+
+#ifdef EAP_SERVER_IDENTITY
+ if (ret == 0)
+ ret = eap_server_identity_register();
+#endif /* EAP_SERVER_IDENTITY */
+
+#ifdef EAP_SERVER_MD5
+ if (ret == 0)
+ ret = eap_server_md5_register();
+#endif /* EAP_SERVER_MD5 */
+
+#ifdef EAP_SERVER_TLS
+ if (ret == 0)
+ ret = eap_server_tls_register();
+#endif /* EAP_SERVER_TLS */
+
+#ifdef EAP_SERVER_MSCHAPV2
+ if (ret == 0)
+ ret = eap_server_mschapv2_register();
+#endif /* EAP_SERVER_MSCHAPV2 */
+
+#ifdef EAP_SERVER_PEAP
+ if (ret == 0)
+ ret = eap_server_peap_register();
+#endif /* EAP_SERVER_PEAP */
+
+#ifdef EAP_SERVER_TLV
+ if (ret == 0)
+ ret = eap_server_tlv_register();
+#endif /* EAP_SERVER_TLV */
+
+#ifdef EAP_SERVER_GTC
+ if (ret == 0)
+ ret = eap_server_gtc_register();
+#endif /* EAP_SERVER_GTC */
+
+#ifdef EAP_SERVER_TTLS
+ if (ret == 0)
+ ret = eap_server_ttls_register();
+#endif /* EAP_SERVER_TTLS */
+
+#ifdef EAP_SERVER_SIM
+ if (ret == 0)
+ ret = eap_server_sim_register();
+#endif /* EAP_SERVER_SIM */
+
+#ifdef EAP_SERVER_AKA
+ if (ret == 0)
+ ret = eap_server_aka_register();
+#endif /* EAP_SERVER_AKA */
+
+#ifdef EAP_SERVER_AKA_PRIME
+ if (ret == 0)
+ ret = eap_server_aka_prime_register();
+#endif /* EAP_SERVER_AKA_PRIME */
+
+#ifdef EAP_SERVER_PAX
+ if (ret == 0)
+ ret = eap_server_pax_register();
+#endif /* EAP_SERVER_PAX */
+
+#ifdef EAP_SERVER_PSK
+ if (ret == 0)
+ ret = eap_server_psk_register();
+#endif /* EAP_SERVER_PSK */
+
+#ifdef EAP_SERVER_SAKE
+ if (ret == 0)
+ ret = eap_server_sake_register();
+#endif /* EAP_SERVER_SAKE */
+
+#ifdef EAP_SERVER_GPSK
+ if (ret == 0)
+ ret = eap_server_gpsk_register();
+#endif /* EAP_SERVER_GPSK */
+
+#ifdef EAP_SERVER_VENDOR_TEST
+ if (ret == 0)
+ ret = eap_server_vendor_test_register();
+#endif /* EAP_SERVER_VENDOR_TEST */
+
+#ifdef EAP_SERVER_FAST
+ if (ret == 0)
+ ret = eap_server_fast_register();
+#endif /* EAP_SERVER_FAST */
+
+#ifdef EAP_SERVER_WSC
+ if (ret == 0)
+ ret = eap_server_wsc_register();
+#endif /* EAP_SERVER_WSC */
+
+#ifdef EAP_SERVER_IKEV2
+ if (ret == 0)
+ ret = eap_server_ikev2_register();
+#endif /* EAP_SERVER_IKEV2 */
+
+#ifdef EAP_SERVER_TNC
+ if (ret == 0)
+ ret = eap_server_tnc_register();
+#endif /* EAP_SERVER_TNC */
+
+ return ret;
+}
diff --git a/contrib/wpa/wpa_supplicant/eapol_test.c b/contrib/wpa/wpa_supplicant/eapol_test.c
index b188549..4eed854 100644
--- a/contrib/wpa/wpa_supplicant/eapol_test.c
+++ b/contrib/wpa/wpa_supplicant/eapol_test.c
@@ -23,7 +23,7 @@
#include "eapol_supp/eapol_supp_sm.h"
#include "eap_peer/eap.h"
#include "eloop.h"
-#include "wpa.h"
+#include "rsn_supp/wpa.h"
#include "eap_peer/eap_i.h"
#include "wpa_supplicant_i.h"
#include "radius/radius.h"
@@ -35,7 +35,7 @@
extern int wpa_debug_level;
extern int wpa_debug_show_keys;
-struct wpa_driver_ops *wpa_supplicant_drivers[] = { NULL };
+struct wpa_driver_ops *wpa_drivers[] = { NULL };
struct extra_radius_attr {
@@ -263,7 +263,8 @@ static void ieee802_1x_encapsulate_radius(struct eapol_test_data *e,
/* State attribute must be copied if and only if this packet is
* Access-Request reply to the previous Access-Challenge */
- if (e->last_recv_radius && e->last_recv_radius->hdr->code ==
+ if (e->last_recv_radius &&
+ radius_msg_get_hdr(e->last_recv_radius)->code ==
RADIUS_CODE_ACCESS_CHALLENGE) {
int res = radius_msg_copy_attr(msg, e->last_recv_radius,
RADIUS_ATTR_STATE);
@@ -283,7 +284,6 @@ static void ieee802_1x_encapsulate_radius(struct eapol_test_data *e,
fail:
radius_msg_free(msg);
- os_free(msg);
}
@@ -404,11 +404,9 @@ static int test_eapol(struct eapol_test_data *e, struct wpa_supplicant *wpa_s,
ctx->eapol_send = eapol_test_eapol_send;
ctx->set_config_blob = eapol_test_set_config_blob;
ctx->get_config_blob = eapol_test_get_config_blob;
-#ifdef EAP_TLS_OPENSSL
ctx->opensc_engine_path = wpa_s->conf->opensc_engine_path;
ctx->pkcs11_engine_path = wpa_s->conf->pkcs11_engine_path;
ctx->pkcs11_module_path = wpa_s->conf->pkcs11_module_path;
-#endif /* EAP_TLS_OPENSSL */
wpa_s->eapol = eapol_sm_init(ctx);
if (wpa_s->eapol == NULL) {
@@ -442,10 +440,8 @@ static void test_eapol_clean(struct eapol_test_data *e,
radius_client_deinit(e->radius);
os_free(e->last_eap_radius);
- if (e->last_recv_radius) {
- radius_msg_free(e->last_recv_radius);
- os_free(e->last_recv_radius);
- }
+ radius_msg_free(e->last_recv_radius);
+ e->last_recv_radius = NULL;
os_free(e->eap_identity);
e->eap_identity = NULL;
eapol_sm_deinit(wpa_s->eapol);
@@ -669,10 +665,11 @@ ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
void *data)
{
struct eapol_test_data *e = data;
+ struct radius_hdr *hdr = radius_msg_get_hdr(msg);
/* RFC 2869, Ch. 5.13: valid Message-Authenticator attribute MUST be
* present when packet contains an EAP-Message attribute */
- if (msg->hdr->code == RADIUS_CODE_ACCESS_REJECT &&
+ if (hdr->code == RADIUS_CODE_ACCESS_REJECT &&
radius_msg_get_attr(msg, RADIUS_ATTR_MESSAGE_AUTHENTICATOR, NULL,
0) < 0 &&
radius_msg_get_attr(msg, RADIUS_ATTR_EAP_MESSAGE, NULL, 0) < 0) {
@@ -686,9 +683,9 @@ ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
return RADIUS_RX_UNKNOWN;
}
- if (msg->hdr->code != RADIUS_CODE_ACCESS_ACCEPT &&
- msg->hdr->code != RADIUS_CODE_ACCESS_REJECT &&
- msg->hdr->code != RADIUS_CODE_ACCESS_CHALLENGE) {
+ if (hdr->code != RADIUS_CODE_ACCESS_ACCEPT &&
+ hdr->code != RADIUS_CODE_ACCESS_REJECT &&
+ hdr->code != RADIUS_CODE_ACCESS_CHALLENGE) {
printf("Unknown RADIUS message code\n");
return RADIUS_RX_UNKNOWN;
}
@@ -696,14 +693,10 @@ ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
e->radius_identifier = -1;
wpa_printf(MSG_DEBUG, "RADIUS packet matching with station");
- if (e->last_recv_radius) {
- radius_msg_free(e->last_recv_radius);
- os_free(e->last_recv_radius);
- }
-
+ radius_msg_free(e->last_recv_radius);
e->last_recv_radius = msg;
- switch (msg->hdr->code) {
+ switch (hdr->code) {
case RADIUS_CODE_ACCESS_ACCEPT:
e->radius_access_accept_received = 1;
ieee802_1x_get_keys(e, msg, req, shared_secret,
@@ -716,9 +709,9 @@ ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
ieee802_1x_decapsulate_radius(e);
- if ((msg->hdr->code == RADIUS_CODE_ACCESS_ACCEPT &&
+ if ((hdr->code == RADIUS_CODE_ACCESS_ACCEPT &&
e->eapol_test_num_reauths < 0) ||
- msg->hdr->code == RADIUS_CODE_ACCESS_REJECT) {
+ hdr->code == RADIUS_CODE_ACCESS_REJECT) {
eloop_terminate();
}
@@ -956,10 +949,9 @@ static int scard_get_triplets(int argc, char *argv[])
}
-static void eapol_test_terminate(int sig, void *eloop_ctx,
- void *signal_ctx)
+static void eapol_test_terminate(int sig, void *signal_ctx)
{
- struct wpa_supplicant *wpa_s = eloop_ctx;
+ struct wpa_supplicant *wpa_s = signal_ctx;
wpa_msg(wpa_s, MSG_INFO, "Signal %d received - terminating", sig);
eloop_terminate();
}
@@ -1130,12 +1122,12 @@ int main(int argc, char *argv[])
return -1;
}
- if (eap_peer_register_methods()) {
+ if (eap_register_methods()) {
wpa_printf(MSG_ERROR, "Failed to register EAP methods");
return -1;
}
- if (eloop_init(&wpa_s)) {
+ if (eloop_init()) {
wpa_printf(MSG_ERROR, "Failed to initialize event loop");
return -1;
}
@@ -1178,8 +1170,8 @@ int main(int argc, char *argv[])
eloop_register_timeout(timeout, 0, eapol_test_timeout, &eapol_test,
NULL);
eloop_register_timeout(0, 0, send_eap_request_identity, &wpa_s, NULL);
- eloop_register_signal_terminate(eapol_test_terminate, NULL);
- eloop_register_signal_reconfig(eapol_test_terminate, NULL);
+ eloop_register_signal_terminate(eapol_test_terminate, &wpa_s);
+ eloop_register_signal_reconfig(eapol_test_terminate, &wpa_s);
eloop_run();
eloop_cancel_timeout(eapol_test_timeout, &eapol_test, NULL);
diff --git a/contrib/wpa/wpa_supplicant/events.c b/contrib/wpa/wpa_supplicant/events.c
index 63002a4..85dcfb2 100644
--- a/contrib/wpa/wpa_supplicant/events.c
+++ b/contrib/wpa/wpa_supplicant/events.c
@@ -1,6 +1,6 @@
/*
* WPA Supplicant - Driver event processing
- * Copyright (c) 2003-2008, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2003-2010, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -16,27 +16,35 @@
#include "common.h"
#include "eapol_supp/eapol_supp_sm.h"
-#include "wpa.h"
+#include "rsn_supp/wpa.h"
#include "eloop.h"
-#include "drivers/driver.h"
#include "config.h"
#include "l2_packet/l2_packet.h"
#include "wpa_supplicant_i.h"
+#include "driver_i.h"
#include "pcsc_funcs.h"
-#include "preauth.h"
-#include "pmksa_cache.h"
-#include "wpa_ctrl.h"
+#include "rsn_supp/preauth.h"
+#include "rsn_supp/pmksa_cache.h"
+#include "common/wpa_ctrl.h"
#include "eap_peer/eap.h"
-#include "ctrl_iface_dbus.h"
-#include "ieee802_11_defs.h"
+#include "ap/hostapd.h"
+#include "notify.h"
+#include "common/ieee802_11_defs.h"
#include "blacklist.h"
#include "wpas_glue.h"
#include "wps_supplicant.h"
+#include "ibss_rsn.h"
+#include "sme.h"
+#include "bgscan.h"
+#include "ap.h"
+#include "bss.h"
+#include "mlme.h"
+#include "scan.h"
static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
{
- struct wpa_ssid *ssid;
+ struct wpa_ssid *ssid, *old_ssid;
if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
return 0;
@@ -72,9 +80,12 @@ static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
eapol_sm_invalidate_cached_session(wpa_s->eapol);
+ old_ssid = wpa_s->current_ssid;
wpa_s->current_ssid = ssid;
wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
wpa_supplicant_initiate_eapol(wpa_s);
+ if (old_ssid != wpa_s->current_ssid)
+ wpas_notify_network_changed(wpa_s);
return 0;
}
@@ -96,9 +107,16 @@ static void wpa_supplicant_stop_countermeasures(void *eloop_ctx,
void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
{
+ int bssid_changed;
+
wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
+ bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
os_memset(wpa_s->bssid, 0, ETH_ALEN);
os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
+ wpa_s->current_bss = NULL;
+ if (bssid_changed)
+ wpas_notify_bssid_changed(wpa_s);
+
eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
@@ -322,7 +340,7 @@ static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
#ifdef CONFIG_IEEE80211W
if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
- ssid->ieee80211w == IEEE80211W_REQUIRED) {
+ ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) {
wpa_printf(MSG_DEBUG, " skip RSN IE - no mgmt frame "
"protection");
break;
@@ -376,8 +394,23 @@ static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
}
-static struct wpa_scan_res *
+static int freq_allowed(int *freqs, int freq)
+{
+ int i;
+
+ if (freqs == NULL)
+ return 1;
+
+ for (i = 0; freqs[i]; i++)
+ if (freqs[i] == freq)
+ return 1;
+ return 0;
+}
+
+
+static struct wpa_bss *
wpa_supplicant_select_bss_wpa(struct wpa_supplicant *wpa_s,
+ struct wpa_scan_results *scan_res,
struct wpa_ssid *group,
struct wpa_ssid **selected_ssid)
{
@@ -388,10 +421,10 @@ wpa_supplicant_select_bss_wpa(struct wpa_supplicant *wpa_s,
const u8 *ie;
wpa_printf(MSG_DEBUG, "Try to find WPA-enabled AP");
- for (i = 0; i < wpa_s->scan_res->num; i++) {
+ for (i = 0; i < scan_res->num; i++) {
const u8 *ssid_;
u8 wpa_ie_len, rsn_ie_len, ssid_len;
- bss = wpa_s->scan_res->res[i];
+ bss = scan_res->res[i];
ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
ssid_ = ie ? ie + 2 : (u8 *) "";
@@ -458,12 +491,18 @@ wpa_supplicant_select_bss_wpa(struct wpa_supplicant *wpa_s,
if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
continue;
+ if (!freq_allowed(ssid->freq_list, bss->freq)) {
+ wpa_printf(MSG_DEBUG, " skip - "
+ "frequency not allowed");
+ continue;
+ }
+
wpa_printf(MSG_DEBUG, " selected WPA AP "
MACSTR " ssid='%s'",
MAC2STR(bss->bssid),
wpa_ssid_txt(ssid_, ssid_len));
*selected_ssid = ssid;
- return bss;
+ return wpa_bss_get(wpa_s, bss->bssid, ssid_, ssid_len);
}
}
@@ -471,8 +510,9 @@ wpa_supplicant_select_bss_wpa(struct wpa_supplicant *wpa_s,
}
-static struct wpa_scan_res *
+static struct wpa_bss *
wpa_supplicant_select_bss_non_wpa(struct wpa_supplicant *wpa_s,
+ struct wpa_scan_results *scan_res,
struct wpa_ssid *group,
struct wpa_ssid **selected_ssid)
{
@@ -483,10 +523,10 @@ wpa_supplicant_select_bss_non_wpa(struct wpa_supplicant *wpa_s,
const u8 *ie;
wpa_printf(MSG_DEBUG, "Try to find non-WPA AP");
- for (i = 0; i < wpa_s->scan_res->num; i++) {
+ for (i = 0; i < scan_res->num; i++) {
const u8 *ssid_;
u8 wpa_ie_len, rsn_ie_len, ssid_len;
- bss = wpa_s->scan_res->res[i];
+ bss = scan_res->res[i];
ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
ssid_ = ie ? ie + 2 : (u8 *) "";
@@ -584,12 +624,18 @@ wpa_supplicant_select_bss_non_wpa(struct wpa_supplicant *wpa_s,
continue;
}
+ if (!freq_allowed(ssid->freq_list, bss->freq)) {
+ wpa_printf(MSG_DEBUG, " skip - "
+ "frequency not allowed");
+ continue;
+ }
+
wpa_printf(MSG_DEBUG, " selected non-WPA AP "
MACSTR " ssid='%s'",
MAC2STR(bss->bssid),
wpa_ssid_txt(ssid_, ssid_len));
*selected_ssid = ssid;
- return bss;
+ return wpa_bss_get(wpa_s, bss->bssid, ssid_, ssid_len);
}
}
@@ -597,70 +643,43 @@ wpa_supplicant_select_bss_non_wpa(struct wpa_supplicant *wpa_s,
}
-static struct wpa_scan_res *
-wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s, struct wpa_ssid *group,
+static struct wpa_bss *
+wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
+ struct wpa_scan_results *scan_res,
+ struct wpa_ssid *group,
struct wpa_ssid **selected_ssid)
{
- struct wpa_scan_res *selected;
+ struct wpa_bss *selected;
wpa_printf(MSG_DEBUG, "Selecting BSS from priority group %d",
group->priority);
/* First, try to find WPA-enabled AP */
- selected = wpa_supplicant_select_bss_wpa(wpa_s, group, selected_ssid);
+ selected = wpa_supplicant_select_bss_wpa(wpa_s, scan_res, group,
+ selected_ssid);
if (selected)
return selected;
/* If no WPA-enabled AP found, try to find non-WPA AP, if configuration
* allows this. */
- return wpa_supplicant_select_bss_non_wpa(wpa_s, group, selected_ssid);
+ return wpa_supplicant_select_bss_non_wpa(wpa_s, scan_res, group,
+ selected_ssid);
}
-static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s)
+static struct wpa_bss *
+wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
+ struct wpa_scan_results *scan_res,
+ struct wpa_ssid **selected_ssid)
{
- int prio, timeout;
- struct wpa_scan_res *selected = NULL;
- struct wpa_ssid *ssid = NULL;
-
- wpa_supplicant_notify_scanning(wpa_s, 0);
-
- if (wpa_supplicant_get_scan_results(wpa_s) < 0) {
- if (wpa_s->conf->ap_scan == 2)
- return;
- wpa_printf(MSG_DEBUG, "Failed to get scan results - try "
- "scanning again");
- timeout = 1;
- goto req_scan;
- }
-
- /*
- * Don't post the results if this was the initial cached
- * and there were no results.
- */
- if (wpa_s->scan_res_tried == 1 && wpa_s->conf->ap_scan == 1 &&
- wpa_s->scan_res->num == 0) {
- wpa_msg(wpa_s, MSG_DEBUG, "Cached scan results are "
- "empty - not posting");
- } else {
- wpa_printf(MSG_DEBUG, "New scan results available");
- wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
- wpa_supplicant_dbus_notify_scan_results(wpa_s);
- wpas_wps_notify_scan_results(wpa_s);
- }
-
- if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
- return;
-
- if (wpa_s->disconnected) {
- wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
- return;
- }
+ struct wpa_bss *selected = NULL;
+ int prio;
while (selected == NULL) {
for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
selected = wpa_supplicant_select_bss(
- wpa_s, wpa_s->conf->pssid[prio], &ssid);
+ wpa_s, scan_res, wpa_s->conf->pssid[prio],
+ selected_ssid);
if (selected)
break;
}
@@ -670,55 +689,18 @@ static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s)
"and try again");
wpa_blacklist_clear(wpa_s);
wpa_s->blacklist_cleared++;
- } else if (selected == NULL) {
+ } else if (selected == NULL)
break;
- }
}
- if (selected) {
- if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
- wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
- "PBC session overlap");
- timeout = 10;
- goto req_scan;
- }
-
- /* Do not trigger new association unless the BSSID has changed
- * or if reassociation is requested. If we are in process of
- * associating with the selected BSSID, do not trigger new
- * attempt. */
- if (wpa_s->reassociate ||
- (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
- (wpa_s->wpa_state != WPA_ASSOCIATING ||
- os_memcmp(selected->bssid, wpa_s->pending_bssid,
- ETH_ALEN) != 0))) {
- if (wpa_supplicant_scard_init(wpa_s, ssid)) {
- wpa_supplicant_req_scan(wpa_s, 10, 0);
- return;
- }
- wpa_supplicant_associate(wpa_s, selected, ssid);
- } else {
- wpa_printf(MSG_DEBUG, "Already associated with the "
- "selected AP.");
- }
- rsn_preauth_scan_results(wpa_s->wpa, wpa_s->scan_res);
- } else {
- wpa_printf(MSG_DEBUG, "No suitable AP found.");
- timeout = 5;
- goto req_scan;
- }
+ return selected;
+}
- return;
-req_scan:
- if (wpa_s->scan_res_tried == 1 && wpa_s->conf->ap_scan == 1) {
- /*
- * Quick recovery if the initial scan results were not
- * complete when fetched before the first scan request.
- */
- wpa_s->scan_res_tried++;
- timeout = 0;
- } else if (!wpa_supplicant_enabled_networks(wpa_s->conf)) {
+static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
+ int timeout_sec, int timeout_usec)
+{
+ if (!wpa_supplicant_enabled_networks(wpa_s->conf)) {
/*
* No networks are enabled; short-circuit request so
* we don't wait timeout seconds before transitioning
@@ -727,16 +709,264 @@ req_scan:
wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
return;
}
- wpa_supplicant_req_scan(wpa_s, timeout, 0);
+ wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
+}
+
+
+void wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
+ struct wpa_bss *selected,
+ struct wpa_ssid *ssid)
+{
+ if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
+ wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
+ "PBC session overlap");
+ wpa_supplicant_req_new_scan(wpa_s, 10, 0);
+ return;
+ }
+
+ /*
+ * Do not trigger new association unless the BSSID has changed or if
+ * reassociation is requested. If we are in process of associating with
+ * the selected BSSID, do not trigger new attempt.
+ */
+ if (wpa_s->reassociate ||
+ (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
+ (wpa_s->wpa_state != WPA_ASSOCIATING ||
+ os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
+ 0))) {
+ if (wpa_supplicant_scard_init(wpa_s, ssid)) {
+ wpa_supplicant_req_new_scan(wpa_s, 10, 0);
+ return;
+ }
+ wpa_supplicant_associate(wpa_s, selected, ssid);
+ } else {
+ wpa_printf(MSG_DEBUG, "Already associated with the selected "
+ "AP");
+ }
+}
+
+
+static struct wpa_ssid *
+wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
+{
+ int prio;
+ struct wpa_ssid *ssid;
+
+ for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
+ for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
+ {
+ if (ssid->disabled)
+ continue;
+ if (ssid->mode == IEEE80211_MODE_IBSS ||
+ ssid->mode == IEEE80211_MODE_AP)
+ return ssid;
+ }
+ }
+ return NULL;
+}
+
+
+/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
+ * on BSS added and BSS changed events */
+static void wpa_supplicant_rsn_preauth_scan_results(
+ struct wpa_supplicant *wpa_s, struct wpa_scan_results *scan_res)
+{
+ int i;
+
+ if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
+ return;
+
+ for (i = scan_res->num - 1; i >= 0; i--) {
+ const u8 *ssid, *rsn;
+ struct wpa_scan_res *r;
+
+ r = scan_res->res[i];
+
+ ssid = wpa_scan_get_ie(r, WLAN_EID_SSID);
+ if (ssid == NULL)
+ continue;
+
+ rsn = wpa_scan_get_ie(r, WLAN_EID_RSN);
+ if (rsn == NULL)
+ continue;
+
+ rsn_preauth_scan_result(wpa_s->wpa, r->bssid, ssid, rsn);
+ }
+
+}
+
+
+static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
+ struct wpa_bss *selected,
+ struct wpa_ssid *ssid,
+ struct wpa_scan_results *scan_res)
+{
+ size_t i;
+ struct wpa_scan_res *current_bss = NULL;
+ int min_diff;
+
+ if (wpa_s->reassociate)
+ return 1; /* explicit request to reassociate */
+ if (wpa_s->wpa_state < WPA_ASSOCIATED)
+ return 1; /* we are not associated; continue */
+ if (wpa_s->current_ssid == NULL)
+ return 1; /* unknown current SSID */
+ if (wpa_s->current_ssid != ssid)
+ return 1; /* different network block */
+
+ for (i = 0; i < scan_res->num; i++) {
+ struct wpa_scan_res *res = scan_res->res[i];
+ const u8 *ie;
+ if (os_memcmp(res->bssid, wpa_s->bssid, ETH_ALEN) != 0)
+ continue;
+
+ ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
+ if (ie == NULL)
+ continue;
+ if (ie[1] != wpa_s->current_ssid->ssid_len ||
+ os_memcmp(ie + 2, wpa_s->current_ssid->ssid, ie[1]) != 0)
+ continue;
+ current_bss = res;
+ break;
+ }
+
+ if (!current_bss)
+ return 1; /* current BSS not seen in scan results */
+
+ wpa_printf(MSG_DEBUG, "Considering within-ESS reassociation");
+ wpa_printf(MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
+ MAC2STR(current_bss->bssid), current_bss->level);
+ wpa_printf(MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
+ MAC2STR(selected->bssid), selected->level);
+
+ if (wpa_s->current_ssid->bssid_set &&
+ os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
+ 0) {
+ wpa_printf(MSG_DEBUG, "Allow reassociation - selected BSS has "
+ "preferred BSSID");
+ return 1;
+ }
+
+ min_diff = 2;
+ if (current_bss->level < 0) {
+ if (current_bss->level < -85)
+ min_diff = 1;
+ else if (current_bss->level < -80)
+ min_diff = 2;
+ else if (current_bss->level < -75)
+ min_diff = 3;
+ else if (current_bss->level < -70)
+ min_diff = 4;
+ else
+ min_diff = 5;
+ }
+ if (abs(current_bss->level - selected->level) < min_diff) {
+ wpa_printf(MSG_DEBUG, "Skip roam - too small difference in "
+ "signal level");
+ return 0;
+ }
+
+ return 1;
+}
+
+
+static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
+ union wpa_event_data *data)
+{
+ struct wpa_bss *selected;
+ struct wpa_ssid *ssid = NULL;
+ struct wpa_scan_results *scan_res;
+ int ap = 0;
+
+#ifdef CONFIG_AP
+ if (wpa_s->ap_iface)
+ ap = 1;
+#endif /* CONFIG_AP */
+
+ wpa_supplicant_notify_scanning(wpa_s, 0);
+
+ scan_res = wpa_supplicant_get_scan_results(wpa_s,
+ data ? &data->scan_info :
+ NULL, 1);
+ if (scan_res == NULL) {
+ if (wpa_s->conf->ap_scan == 2 || ap)
+ return;
+ wpa_printf(MSG_DEBUG, "Failed to get scan results - try "
+ "scanning again");
+ wpa_supplicant_req_new_scan(wpa_s, 1, 0);
+ return;
+ }
+
+ if (wpa_s->scan_res_handler) {
+ wpa_s->scan_res_handler(wpa_s, scan_res);
+ wpa_s->scan_res_handler = NULL;
+ wpa_scan_results_free(scan_res);
+ return;
+ }
+
+ if (ap) {
+ wpa_printf(MSG_DEBUG, "Ignore scan results in AP mode");
+ wpa_scan_results_free(scan_res);
+ return;
+ }
+
+ wpa_printf(MSG_DEBUG, "New scan results available");
+ wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
+ wpas_notify_scan_results(wpa_s);
+
+ wpas_notify_scan_done(wpa_s, 1);
+
+ if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
+ wpa_scan_results_free(scan_res);
+ return;
+ }
+
+ if (wpa_s->disconnected) {
+ wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
+ wpa_scan_results_free(scan_res);
+ return;
+ }
+
+ if (bgscan_notify_scan(wpa_s) == 1) {
+ wpa_scan_results_free(scan_res);
+ return;
+ }
+
+ wpa_supplicant_rsn_preauth_scan_results(wpa_s, scan_res);
+
+ selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid);
+
+ if (selected) {
+ int skip;
+ skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid,
+ scan_res);
+ wpa_scan_results_free(scan_res);
+ if (skip)
+ return;
+ wpa_supplicant_connect(wpa_s, selected, ssid);
+ } else {
+ wpa_scan_results_free(scan_res);
+ wpa_printf(MSG_DEBUG, "No suitable network found");
+ ssid = wpa_supplicant_pick_new_network(wpa_s);
+ if (ssid) {
+ wpa_printf(MSG_DEBUG, "Setup a new network");
+ wpa_supplicant_associate(wpa_s, NULL, ssid);
+ } else {
+ int timeout_sec = 5;
+ int timeout_usec = 0;
+ wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
+ timeout_usec);
+ }
+ }
}
#endif /* CONFIG_NO_SCAN_PROCESSING */
-static void wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
- union wpa_event_data *data)
+static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
+ union wpa_event_data *data)
{
int l, len, found = 0, wpa_found, rsn_found;
- u8 *p;
+ const u8 *p;
wpa_printf(MSG_DEBUG, "Association info event");
if (data->assoc_info.req_ies)
@@ -749,6 +979,8 @@ static void wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
wpa_hexdump(MSG_DEBUG, "beacon_ies",
data->assoc_info.beacon_ies,
data->assoc_info.beacon_ies_len);
+ if (data->assoc_info.freq)
+ wpa_printf(MSG_DEBUG, "freq=%u MHz", data->assoc_info.freq);
p = data->assoc_info.req_ies;
l = data->assoc_info.req_ies_len;
@@ -776,6 +1008,50 @@ static void wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
if (!found && data->assoc_info.req_ies)
wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
+#ifdef CONFIG_IEEE80211R
+#ifdef CONFIG_SME
+ if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
+ u8 bssid[ETH_ALEN];
+ if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
+ wpa_ft_validate_reassoc_resp(wpa_s->wpa,
+ data->assoc_info.resp_ies,
+ data->assoc_info.resp_ies_len,
+ bssid) < 0) {
+ wpa_printf(MSG_DEBUG, "FT: Validation of "
+ "Reassociation Response failed");
+ wpa_supplicant_deauthenticate(
+ wpa_s, WLAN_REASON_INVALID_IE);
+ return -1;
+ }
+ }
+
+ p = data->assoc_info.resp_ies;
+ l = data->assoc_info.resp_ies_len;
+
+ /* Go through the IEs and make a copy of the MDIE, if present. */
+ while (p && l >= 2) {
+ len = p[1] + 2;
+ if (len > l) {
+ wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
+ p, l);
+ break;
+ }
+ if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
+ p[1] >= MOBILITY_DOMAIN_ID_LEN) {
+ wpa_s->sme.ft_used = 1;
+ os_memcpy(wpa_s->sme.mobility_domain, p + 2,
+ MOBILITY_DOMAIN_ID_LEN);
+ break;
+ }
+ l -= len;
+ p += len;
+ }
+#endif /* CONFIG_SME */
+
+ wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
+ data->assoc_info.resp_ies_len);
+#endif /* CONFIG_IEEE80211R */
+
/* WPA/RSN IE from Beacon/ProbeResp */
p = data->assoc_info.beacon_ies;
l = data->assoc_info.beacon_ies_len;
@@ -813,6 +1089,10 @@ static void wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
if (wpa_found || rsn_found)
wpa_s->ap_ies_from_associnfo = 1;
+
+ wpa_s->assoc_freq = data->assoc_info.freq;
+
+ return 0;
}
@@ -820,21 +1100,38 @@ static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
union wpa_event_data *data)
{
u8 bssid[ETH_ALEN];
- int ft_completed = wpa_ft_is_completed(wpa_s->wpa);
+ int ft_completed;
+ int bssid_changed;
+ struct wpa_driver_capa capa;
+
+#ifdef CONFIG_AP
+ if (wpa_s->ap_iface) {
+ hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
+ data->assoc_info.addr,
+ data->assoc_info.req_ies,
+ data->assoc_info.req_ies_len);
+ return;
+ }
+#endif /* CONFIG_AP */
- if (data)
- wpa_supplicant_event_associnfo(wpa_s, data);
+ ft_completed = wpa_ft_is_completed(wpa_s->wpa);
+ if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
+ return;
wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
- if (wpa_s->use_client_mlme)
+ if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
os_memcpy(bssid, wpa_s->bssid, ETH_ALEN);
- if (wpa_s->use_client_mlme ||
+ if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) ||
(wpa_drv_get_bssid(wpa_s, bssid) >= 0 &&
os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0)) {
wpa_msg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
MACSTR, MAC2STR(bssid));
+ bssid_changed = os_memcmp(wpa_s->bssid, bssid, ETH_ALEN);
os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
+ if (bssid_changed)
+ wpas_notify_bssid_changed(wpa_s);
+
if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
wpa_clear_keys(wpa_s, bssid);
}
@@ -843,8 +1140,24 @@ static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
wpa_s, WLAN_REASON_DEAUTH_LEAVING);
return;
}
+ if (wpa_s->current_ssid) {
+ struct wpa_bss *bss = NULL;
+ struct wpa_ssid *ssid = wpa_s->current_ssid;
+ if (ssid->ssid_len > 0)
+ bss = wpa_bss_get(wpa_s, bssid,
+ ssid->ssid, ssid->ssid_len);
+ if (!bss)
+ bss = wpa_bss_get_bssid(wpa_s, bssid);
+ if (bss)
+ wpa_s->current_bss = bss;
+ }
}
+#ifdef CONFIG_SME
+ os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
+ wpa_s->sme.prev_bssid_set = 1;
+#endif /* CONFIG_SME */
+
wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
if (wpa_s->current_ssid) {
/* When using scanning (ap_scan=1), SIM PC/SC interface can be
@@ -854,7 +1167,8 @@ static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
}
wpa_sm_notify_assoc(wpa_s->wpa, bssid);
- l2_packet_notify_auth_start(wpa_s->l2);
+ if (wpa_s->l2)
+ l2_packet_notify_auth_start(wpa_s->l2);
/*
* Set portEnabled first to FALSE in order to get EAP state machine out
@@ -874,7 +1188,9 @@ static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
wpa_s->eapol_received = 0;
if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
- wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
+ wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
+ (wpa_s->current_ssid &&
+ wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
wpa_supplicant_cancel_auth_timeout(wpa_s);
wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
} else if (!ft_completed) {
@@ -883,7 +1199,7 @@ static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
}
wpa_supplicant_cancel_scan(wpa_s);
- if (wpa_s->driver_4way_handshake &&
+ if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
/*
* We are done; the driver will take care of RSN 4-way
@@ -913,12 +1229,47 @@ static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
wpabuf_free(wpa_s->pending_eapol_rx);
wpa_s->pending_eapol_rx = NULL;
}
+
+#ifdef CONFIG_BGSCAN
+ if (wpa_s->current_ssid != wpa_s->bgscan_ssid) {
+ bgscan_deinit(wpa_s);
+ if (wpa_s->current_ssid && wpa_s->current_ssid->bgscan) {
+ if (bgscan_init(wpa_s, wpa_s->current_ssid)) {
+ wpa_printf(MSG_DEBUG, "Failed to initialize "
+ "bgscan");
+ /*
+ * Live without bgscan; it is only used as a
+ * roaming optimization, so the initial
+ * connection is not affected.
+ */
+ } else
+ wpa_s->bgscan_ssid = wpa_s->current_ssid;
+ } else
+ wpa_s->bgscan_ssid = NULL;
+ }
+#endif /* CONFIG_BGSCAN */
+
+ if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
+ wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
+ wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
+ capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
+ /* Set static WEP keys again */
+ wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
+ }
}
-static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s)
+static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
+ u16 reason_code)
{
const u8 *bssid;
+#ifdef CONFIG_SME
+ int authenticating;
+ u8 prev_pending_bssid[ETH_ALEN];
+
+ authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
+ os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
+#endif /* CONFIG_SME */
if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
/*
@@ -943,13 +1294,31 @@ static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s)
bssid = wpa_s->pending_bssid;
wpa_blacklist_add(wpa_s, bssid);
wpa_sm_notify_disassoc(wpa_s->wpa);
- wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "- Disconnect event - "
- "remove keys");
+ wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
+ " reason=%d",
+ MAC2STR(bssid), reason_code);
if (wpa_supplicant_dynamic_keys(wpa_s)) {
+ wpa_printf(MSG_DEBUG, "Disconnect event - remove keys");
wpa_s->keys_cleared = 0;
wpa_clear_keys(wpa_s, wpa_s->bssid);
}
wpa_supplicant_mark_disassoc(wpa_s);
+ bgscan_deinit(wpa_s);
+ wpa_s->bgscan_ssid = NULL;
+#ifdef CONFIG_SME
+ if (authenticating &&
+ (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
+ /*
+ * mac80211-workaround to force deauth on failed auth cmd,
+ * requires us to remain in authenticating state to allow the
+ * second authentication attempt to be continued properly.
+ */
+ wpa_printf(MSG_DEBUG, "SME: Allow pending authentication to "
+ "proceed after disconnection event");
+ wpa_supplicant_set_state(wpa_s, WPA_AUTHENTICATING);
+ os_memcpy(wpa_s->pending_bssid, prev_pending_bssid, ETH_ALEN);
+ }
+#endif /* CONFIG_SME */
}
@@ -1072,6 +1441,7 @@ static int any_interfaces(struct wpa_supplicant *head)
}
#endif /* CONFIG_TERMINATE_ONLASTIF */
+
static void
wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
union wpa_event_data *data)
@@ -1129,31 +1499,128 @@ wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
data->ft_ies.ies_len,
data->ft_ies.ft_action,
- data->ft_ies.target_ap) < 0) {
+ data->ft_ies.target_ap,
+ data->ft_ies.ric_ies,
+ data->ft_ies.ric_ies_len) < 0) {
/* TODO: prevent MLME/driver from trying to associate? */
}
}
#endif /* CONFIG_IEEE80211R */
-void wpa_supplicant_event(void *ctx, wpa_event_type event,
+#ifdef CONFIG_IBSS_RSN
+static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
+ union wpa_event_data *data)
+{
+ if (data == NULL)
+ return;
+ ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
+}
+#endif /* CONFIG_IBSS_RSN */
+
+
+#ifdef CONFIG_IEEE80211R
+static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
+ size_t len)
+{
+ const u8 *sta_addr, *target_ap_addr;
+ u16 status;
+
+ wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
+ if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
+ return; /* only SME case supported for now */
+ if (len < 1 + 2 * ETH_ALEN + 2)
+ return;
+ if (data[0] != 2)
+ return; /* Only FT Action Response is supported for now */
+ sta_addr = data + 1;
+ target_ap_addr = data + 1 + ETH_ALEN;
+ status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
+ wpa_printf(MSG_DEBUG, "FT: Received FT Action Response: STA " MACSTR
+ " TargetAP " MACSTR " status %u",
+ MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
+
+ if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
+ wpa_printf(MSG_DEBUG, "FT: Foreign STA Address " MACSTR
+ " in FT Action Response", MAC2STR(sta_addr));
+ return;
+ }
+
+ if (status) {
+ wpa_printf(MSG_DEBUG, "FT: FT Action Response indicates "
+ "failure (status code %d)", status);
+ /* TODO: report error to FT code(?) */
+ return;
+ }
+
+ if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
+ len - (1 + 2 * ETH_ALEN + 2), 1,
+ target_ap_addr, NULL, 0) < 0)
+ return;
+
+#ifdef CONFIG_SME
+ {
+ struct wpa_bss *bss;
+ bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
+ if (bss)
+ wpa_s->sme.freq = bss->freq;
+ wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
+ sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
+ WLAN_AUTH_FT);
+ }
+#endif /* CONFIG_SME */
+}
+#endif /* CONFIG_IEEE80211R */
+
+
+void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
union wpa_event_data *data)
{
struct wpa_supplicant *wpa_s = ctx;
+ u16 reason_code = 0;
switch (event) {
+ case EVENT_AUTH:
+ sme_event_auth(wpa_s, data);
+ break;
case EVENT_ASSOC:
wpa_supplicant_event_assoc(wpa_s, data);
break;
case EVENT_DISASSOC:
- wpa_supplicant_event_disassoc(wpa_s);
+ wpa_printf(MSG_DEBUG, "Disassociation notification");
+#ifdef CONFIG_AP
+ if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
+ hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
+ data->disassoc_info.addr);
+ break;
+ }
+#endif /* CONFIG_AP */
+ if (data)
+ reason_code = data->deauth_info.reason_code;
+ if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
+ sme_event_disassoc(wpa_s, data);
+ /* fall through */
+ case EVENT_DEAUTH:
+ if (event == EVENT_DEAUTH) {
+ wpa_printf(MSG_DEBUG, "Deauthentication notification");
+ if (data)
+ reason_code = data->deauth_info.reason_code;
+ }
+#ifdef CONFIG_AP
+ if (wpa_s->ap_iface && data && data->deauth_info.addr) {
+ hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
+ data->deauth_info.addr);
+ break;
+ }
+#endif /* CONFIG_AP */
+ wpa_supplicant_event_disassoc(wpa_s, reason_code);
break;
case EVENT_MICHAEL_MIC_FAILURE:
wpa_supplicant_event_michael_mic_failure(wpa_s, data);
break;
#ifndef CONFIG_NO_SCAN_PROCESSING
case EVENT_SCAN_RESULTS:
- wpa_supplicant_event_scan_results(wpa_s);
+ wpa_supplicant_event_scan_results(wpa_s, data);
break;
#endif /* CONFIG_NO_SCAN_PROCESSING */
case EVENT_ASSOCINFO:
@@ -1175,6 +1642,86 @@ void wpa_supplicant_event(void *ctx, wpa_event_type event,
wpa_supplicant_event_ft_response(wpa_s, data);
break;
#endif /* CONFIG_IEEE80211R */
+#ifdef CONFIG_IBSS_RSN
+ case EVENT_IBSS_RSN_START:
+ wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
+ break;
+#endif /* CONFIG_IBSS_RSN */
+ case EVENT_ASSOC_REJECT:
+ sme_event_assoc_reject(wpa_s, data);
+ break;
+ case EVENT_AUTH_TIMED_OUT:
+ sme_event_auth_timed_out(wpa_s, data);
+ break;
+ case EVENT_ASSOC_TIMED_OUT:
+ sme_event_assoc_timed_out(wpa_s, data);
+ break;
+#ifdef CONFIG_AP
+ case EVENT_TX_STATUS:
+ if (wpa_s->ap_iface == NULL)
+ break;
+ switch (data->tx_status.type) {
+ case WLAN_FC_TYPE_MGMT:
+ ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
+ data->tx_status.data_len,
+ data->tx_status.stype,
+ data->tx_status.ack);
+ break;
+ case WLAN_FC_TYPE_DATA:
+ ap_tx_status(wpa_s, data->tx_status.dst,
+ data->tx_status.data,
+ data->tx_status.data_len,
+ data->tx_status.ack);
+ break;
+ }
+ break;
+ case EVENT_RX_FROM_UNKNOWN:
+ if (wpa_s->ap_iface == NULL)
+ break;
+ ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.frame,
+ data->rx_from_unknown.len);
+ break;
+ case EVENT_RX_MGMT:
+ if (wpa_s->ap_iface == NULL)
+ break;
+ ap_mgmt_rx(wpa_s, &data->rx_mgmt);
+ break;
+#endif /* CONFIG_AP */
+ case EVENT_RX_ACTION:
+ wpa_printf(MSG_DEBUG, "Received Action frame: SA=" MACSTR
+ " Category=%u DataLen=%d freq=%d MHz",
+ MAC2STR(data->rx_action.sa),
+ data->rx_action.category, (int) data->rx_action.len,
+ data->rx_action.freq);
+#ifdef CONFIG_IEEE80211R
+ if (data->rx_action.category == WLAN_ACTION_FT) {
+ ft_rx_action(wpa_s, data->rx_action.data,
+ data->rx_action.len);
+ break;
+ }
+#endif /* CONFIG_IEEE80211R */
+ break;
+#ifdef CONFIG_CLIENT_MLME
+ case EVENT_MLME_RX: {
+ struct ieee80211_rx_status rx_status;
+ os_memset(&rx_status, 0, sizeof(rx_status));
+ rx_status.freq = data->mlme_rx.freq;
+ rx_status.channel = data->mlme_rx.channel;
+ rx_status.ssi = data->mlme_rx.ssi;
+ ieee80211_sta_rx(wpa_s, data->mlme_rx.buf, data->mlme_rx.len,
+ &rx_status);
+ break;
+ }
+#endif /* CONFIG_CLIENT_MLME */
+ case EVENT_EAPOL_RX:
+ wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
+ data->eapol_rx.data,
+ data->eapol_rx.data_len);
+ break;
+ case EVENT_SIGNAL_CHANGE:
+ bgscan_notify_signal_change(
+ wpa_s, data->signal_change.above_threshold);
+ break;
default:
wpa_printf(MSG_INFO, "Unknown event %d", event);
break;
diff --git a/contrib/wpa/wpa_supplicant/examples/60_wpa_supplicant b/contrib/wpa/wpa_supplicant/examples/60_wpa_supplicant
new file mode 100755
index 0000000..39bd8e0
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/examples/60_wpa_supplicant
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+# /etc/pm/sleep.d/60_wpa_supplicant
+# Action script to notify wpa_supplicant of pm-action events.
+
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
+
+WPACLI=wpa_cli
+
+case "$1" in
+ suspend|hibernate)
+ $WPACLI suspend
+ ;;
+ resume|thaw)
+ $WPACLI resume
+ ;;
+esac
+
+exit 0
diff --git a/contrib/wpa/wpa_supplicant/examples/wpas-dbus-new-getall.py b/contrib/wpa/wpa_supplicant/examples/wpas-dbus-new-getall.py
new file mode 100755
index 0000000..03da187
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/examples/wpas-dbus-new-getall.py
@@ -0,0 +1,59 @@
+#!/usr/bin/python
+
+import dbus
+import sys, os
+import time
+import gobject
+
+def main():
+ bus = dbus.SystemBus()
+ wpas_obj = bus.get_object("fi.w1.wpa_supplicant1",
+ "/fi/w1/wpa_supplicant1")
+ props = wpas_obj.GetAll("fi.w1.wpa_supplicant1",
+ dbus_interface=dbus.PROPERTIES_IFACE)
+ print "GetAll(fi.w1.wpa_supplicant1, /fi/w1/wpa_supplicant1):"
+ print props
+
+ if len(sys.argv) != 2:
+ os._exit(1)
+
+ ifname = sys.argv[1]
+
+ wpas = dbus.Interface(wpas_obj, "fi.w1.wpa_supplicant1")
+ path = wpas.GetInterface(ifname)
+ if_obj = bus.get_object("fi.w1.wpa_supplicant1", path)
+ props = if_obj.GetAll("fi.w1.wpa_supplicant1.Interface",
+ dbus_interface=dbus.PROPERTIES_IFACE)
+ print
+ print "GetAll(fi.w1.wpa_supplicant1.Interface, %s):" % (path)
+ print props
+
+ props = if_obj.GetAll("fi.w1.wpa_supplicant1.Interface.WPS",
+ dbus_interface=dbus.PROPERTIES_IFACE)
+ print
+ print "GetAll(fi.w1.wpa_supplicant1.Interface.WPS, %s):" % (path)
+ print props
+
+ res = if_obj.Get("fi.w1.wpa_supplicant1.Interface", 'BSSs',
+ dbus_interface=dbus.PROPERTIES_IFACE)
+ if len(res) > 0:
+ bss_obj = bus.get_object("fi.w1.wpa_supplicant1", res[0])
+ props = bss_obj.GetAll("fi.w1.wpa_supplicant1.BSS",
+ dbus_interface=dbus.PROPERTIES_IFACE)
+ print
+ print "GetAll(fi.w1.wpa_supplicant1.BSS, %s):" % (res[0])
+ print props
+
+ res = if_obj.Get("fi.w1.wpa_supplicant1.Interface", 'Networks',
+ dbus_interface=dbus.PROPERTIES_IFACE)
+ if len(res) > 0:
+ net_obj = bus.get_object("fi.w1.wpa_supplicant1", res[0])
+ props = net_obj.GetAll("fi.w1.wpa_supplicant1.Network",
+ dbus_interface=dbus.PROPERTIES_IFACE)
+ print
+ print "GetAll(fi.w1.wpa_supplicant1.Network, %s):" % (res[0])
+ print props
+
+if __name__ == "__main__":
+ main()
+
diff --git a/contrib/wpa/wpa_supplicant/examples/wpas-dbus-new-signals.py b/contrib/wpa/wpa_supplicant/examples/wpas-dbus-new-signals.py
new file mode 100755
index 0000000..b040e0a
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/examples/wpas-dbus-new-signals.py
@@ -0,0 +1,203 @@
+#!/usr/bin/python
+
+import dbus
+import sys, os
+import time
+import gobject
+from dbus.mainloop.glib import DBusGMainLoop
+
+WPAS_DBUS_SERVICE = "fi.w1.wpa_supplicant1"
+WPAS_DBUS_INTERFACE = "fi.w1.wpa_supplicant1"
+WPAS_DBUS_OPATH = "/fi/w1/wpa_supplicant1"
+
+WPAS_DBUS_INTERFACES_INTERFACE = "fi.w1.wpa_supplicant1.Interface"
+WPAS_DBUS_INTERFACES_OPATH = "/fi/w1/wpa_supplicant1/Interfaces"
+WPAS_DBUS_BSS_INTERFACE = "fi.w1.wpa_supplicant1.BSS"
+WPAS_DBUS_NETWORK_INTERFACE = "fi.w1.wpa_supplicant1.Network"
+
+def byte_array_to_string(s):
+ import urllib
+ r = ""
+ for c in s:
+ if c >= 32 and c < 127:
+ r += "%c" % c
+ else:
+ r += urllib.quote(chr(c))
+ return r
+
+def list_interfaces(wpas_obj):
+ ifaces = wpas_obj.Get(WPAS_DBUS_INTERFACE, 'Interfaces',
+ dbus_interface=dbus.PROPERTIES_IFACE)
+ for path in ifaces:
+ if_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
+ ifname = if_obj.Get(WPAS_DBUS_INTERFACES_INTERFACE, 'Ifname',
+ dbus_interface=dbus.PROPERTIES_IFACE)
+ print ifname
+
+def interfaceAdded(interface, properties):
+ print "InterfaceAdded(%s): Ifname=%s" % (interface, properties['Ifname'])
+
+def interfaceRemoved(interface):
+ print "InterfaceRemoved(%s)" % (interface)
+
+def propertiesChanged(properties):
+ for i in properties:
+ print "PropertiesChanged: %s=%s" % (i, properties[i])
+
+def showBss(bss):
+ net_obj = bus.get_object(WPAS_DBUS_SERVICE, bss)
+ net = dbus.Interface(net_obj, WPAS_DBUS_BSS_INTERFACE)
+
+ # Convert the byte-array for SSID and BSSID to printable strings
+ val = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'BSSID',
+ dbus_interface=dbus.PROPERTIES_IFACE)
+ bssid = ""
+ for item in val:
+ bssid = bssid + ":%02x" % item
+ bssid = bssid[1:]
+ val = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'SSID',
+ dbus_interface=dbus.PROPERTIES_IFACE)
+ ssid = byte_array_to_string(val)
+
+ val = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'WPAIE',
+ dbus_interface=dbus.PROPERTIES_IFACE)
+ wpa = "no"
+ if val != None:
+ wpa = "yes"
+ val = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'RSNIE',
+ dbus_interface=dbus.PROPERTIES_IFACE)
+ wpa2 = "no"
+ if val != None:
+ wpa2 = "yes"
+ freq = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'Frequency',
+ dbus_interface=dbus.PROPERTIES_IFACE)
+ signal = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'Signal',
+ dbus_interface=dbus.PROPERTIES_IFACE)
+ val = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'Rates',
+ dbus_interface=dbus.PROPERTIES_IFACE)
+ if len(val) > 0:
+ maxrate = val[0] / 1000000
+ else:
+ maxrate = 0
+
+ print " %s :: ssid='%s' wpa=%s wpa2=%s signal=%d rate=%d freq=%d" % (bssid, ssid, wpa, wpa2, signal, maxrate, freq)
+
+def scanDone(success):
+ gobject.MainLoop().quit()
+ print "Scan done: success=%s" % success
+
+def scanDone2(success, path=None):
+ print "Scan done: success=%s [path=%s]" % (success, path)
+
+def bssAdded(bss, properties):
+ print "BSS added: %s" % (bss)
+ showBss(bss)
+
+def bssRemoved(bss):
+ print "BSS removed: %s" % (bss)
+
+def blobAdded(blob):
+ print "BlobAdded(%s)" % (blob)
+
+def blobRemoved(blob):
+ print "BlobRemoved(%s)" % (blob)
+
+def networkAdded(network, properties):
+ print "NetworkAdded(%s)" % (network)
+
+def networkRemoved(network):
+ print "NetworkRemoved(%s)" % (network)
+
+def networkSelected(network):
+ print "NetworkSelected(%s)" % (network)
+
+def propertiesChangedInterface(properties):
+ for i in properties:
+ print "PropertiesChanged(interface): %s=%s" % (i, properties[i])
+
+def propertiesChangedBss(properties):
+ for i in properties:
+ print "PropertiesChanged(BSS): %s=%s" % (i, properties[i])
+
+def propertiesChangedNetwork(properties):
+ for i in properties:
+ print "PropertiesChanged(Network): %s=%s" % (i, properties[i])
+
+def main():
+ dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+ global bus
+ bus = dbus.SystemBus()
+ wpas_obj = bus.get_object(WPAS_DBUS_SERVICE, WPAS_DBUS_OPATH)
+
+ if len(sys.argv) != 2:
+ list_interfaces(wpas_obj)
+ os._exit(1)
+
+ wpas = dbus.Interface(wpas_obj, WPAS_DBUS_INTERFACE)
+ bus.add_signal_receiver(interfaceAdded,
+ dbus_interface=WPAS_DBUS_INTERFACE,
+ signal_name="InterfaceAdded")
+ bus.add_signal_receiver(interfaceRemoved,
+ dbus_interface=WPAS_DBUS_INTERFACE,
+ signal_name="InterfaceRemoved")
+ bus.add_signal_receiver(propertiesChanged,
+ dbus_interface=WPAS_DBUS_INTERFACE,
+ signal_name="PropertiesChanged")
+
+ ifname = sys.argv[1]
+ path = wpas.GetInterface(ifname)
+ if_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
+ iface = dbus.Interface(if_obj, WPAS_DBUS_INTERFACES_INTERFACE)
+ iface.connect_to_signal("ScanDone", scanDone2,
+ path_keyword='path')
+
+ bus.add_signal_receiver(scanDone,
+ dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
+ signal_name="ScanDone",
+ path=path)
+ bus.add_signal_receiver(bssAdded,
+ dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
+ signal_name="BSSAdded",
+ path=path)
+ bus.add_signal_receiver(bssRemoved,
+ dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
+ signal_name="BSSRemoved",
+ path=path)
+ bus.add_signal_receiver(blobAdded,
+ dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
+ signal_name="BlobAdded",
+ path=path)
+ bus.add_signal_receiver(blobRemoved,
+ dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
+ signal_name="BlobRemoved",
+ path=path)
+ bus.add_signal_receiver(networkAdded,
+ dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
+ signal_name="NetworkAdded",
+ path=path)
+ bus.add_signal_receiver(networkRemoved,
+ dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
+ signal_name="NetworkRemoved",
+ path=path)
+ bus.add_signal_receiver(networkSelected,
+ dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
+ signal_name="NetworkSelected",
+ path=path)
+ bus.add_signal_receiver(propertiesChangedInterface,
+ dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
+ signal_name="PropertiesChanged",
+ path=path)
+
+ bus.add_signal_receiver(propertiesChangedBss,
+ dbus_interface=WPAS_DBUS_BSS_INTERFACE,
+ signal_name="PropertiesChanged")
+
+ bus.add_signal_receiver(propertiesChangedNetwork,
+ dbus_interface=WPAS_DBUS_NETWORK_INTERFACE,
+ signal_name="PropertiesChanged")
+
+ gobject.MainLoop().run()
+
+if __name__ == "__main__":
+ main()
+
diff --git a/contrib/wpa/wpa_supplicant/examples/wpas-dbus-new-wps.py b/contrib/wpa/wpa_supplicant/examples/wpas-dbus-new-wps.py
new file mode 100755
index 0000000..b886385
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/examples/wpas-dbus-new-wps.py
@@ -0,0 +1,80 @@
+#!/usr/bin/python
+
+import dbus
+import sys, os
+import time
+import gobject
+from dbus.mainloop.glib import DBusGMainLoop
+
+WPAS_DBUS_SERVICE = "fi.w1.wpa_supplicant1"
+WPAS_DBUS_INTERFACE = "fi.w1.wpa_supplicant1"
+WPAS_DBUS_OPATH = "/fi/w1/wpa_supplicant1"
+
+WPAS_DBUS_INTERFACES_INTERFACE = "fi.w1.wpa_supplicant1.Interface"
+WPAS_DBUS_WPS_INTERFACE = "fi.w1.wpa_supplicant1.Interface.WPS"
+
+def propertiesChanged(properties):
+ if properties.has_key("State"):
+ print "PropertiesChanged: State: %s" % (properties["State"])
+
+def scanDone(success):
+ print "Scan done: success=%s" % success
+
+def bssAdded(bss, properties):
+ print "BSS added: %s" % (bss)
+
+def bssRemoved(bss):
+ print "BSS removed: %s" % (bss)
+
+def wpsEvent(name, args):
+ print "WPS event: %s" % (name)
+ print args
+
+def credentials(cred):
+ print "WPS credentials: %s" % (cred)
+
+def main():
+ dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+ global bus
+ bus = dbus.SystemBus()
+ wpas_obj = bus.get_object(WPAS_DBUS_SERVICE, WPAS_DBUS_OPATH)
+
+ if len(sys.argv) != 2:
+ print "Missing ifname argument"
+ os._exit(1)
+
+ wpas = dbus.Interface(wpas_obj, WPAS_DBUS_INTERFACE)
+ bus.add_signal_receiver(scanDone,
+ dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
+ signal_name="ScanDone")
+ bus.add_signal_receiver(bssAdded,
+ dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
+ signal_name="BSSAdded")
+ bus.add_signal_receiver(bssRemoved,
+ dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
+ signal_name="BSSRemoved")
+ bus.add_signal_receiver(propertiesChanged,
+ dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
+ signal_name="PropertiesChanged")
+ bus.add_signal_receiver(wpsEvent,
+ dbus_interface=WPAS_DBUS_WPS_INTERFACE,
+ signal_name="Event")
+ bus.add_signal_receiver(credentials,
+ dbus_interface=WPAS_DBUS_WPS_INTERFACE,
+ signal_name="Credentials")
+
+ ifname = sys.argv[1]
+
+ path = wpas.GetInterface(ifname)
+ if_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
+ if_obj.Set(WPAS_DBUS_WPS_INTERFACE, 'ProcessCredentials',
+ dbus.Boolean(1),
+ dbus_interface=dbus.PROPERTIES_IFACE)
+ wps = dbus.Interface(if_obj, WPAS_DBUS_WPS_INTERFACE)
+ wps.Start({'Role': 'enrollee', 'Type': 'pbc'})
+
+ gobject.MainLoop().run()
+
+if __name__ == "__main__":
+ main()
+
diff --git a/contrib/wpa/wpa_supplicant/examples/wpas-dbus-new.py b/contrib/wpa/wpa_supplicant/examples/wpas-dbus-new.py
new file mode 100755
index 0000000..25072ce
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/examples/wpas-dbus-new.py
@@ -0,0 +1,149 @@
+#!/usr/bin/python
+
+import dbus
+import sys, os
+import time
+import gobject
+from dbus.mainloop.glib import DBusGMainLoop
+
+WPAS_DBUS_SERVICE = "fi.w1.wpa_supplicant1"
+WPAS_DBUS_INTERFACE = "fi.w1.wpa_supplicant1"
+WPAS_DBUS_OPATH = "/fi/w1/wpa_supplicant1"
+
+WPAS_DBUS_INTERFACES_INTERFACE = "fi.w1.wpa_supplicant1.Interface"
+WPAS_DBUS_INTERFACES_OPATH = "/fi/w1/wpa_supplicant1/Interfaces"
+WPAS_DBUS_BSS_INTERFACE = "fi.w1.wpa_supplicant1.BSS"
+
+def byte_array_to_string(s):
+ import urllib
+ r = ""
+ for c in s:
+ if c >= 32 and c < 127:
+ r += "%c" % c
+ else:
+ r += urllib.quote(chr(c))
+ return r
+
+def list_interfaces(wpas_obj):
+ ifaces = wpas_obj.Get(WPAS_DBUS_INTERFACE, 'Interfaces',
+ dbus_interface=dbus.PROPERTIES_IFACE)
+ for path in ifaces:
+ if_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
+ ifname = if_obj.Get(WPAS_DBUS_INTERFACES_INTERFACE, 'Ifname',
+ dbus_interface=dbus.PROPERTIES_IFACE)
+ print ifname
+
+def propertiesChanged(properties):
+ if properties.has_key("State"):
+ print "PropertiesChanged: State: %s" % (properties["State"])
+
+def showBss(bss):
+ net_obj = bus.get_object(WPAS_DBUS_SERVICE, bss)
+ net = dbus.Interface(net_obj, WPAS_DBUS_BSS_INTERFACE)
+
+ # Convert the byte-array for SSID and BSSID to printable strings
+ val = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'BSSID',
+ dbus_interface=dbus.PROPERTIES_IFACE)
+ bssid = ""
+ for item in val:
+ bssid = bssid + ":%02x" % item
+ bssid = bssid[1:]
+ val = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'SSID',
+ dbus_interface=dbus.PROPERTIES_IFACE)
+ ssid = byte_array_to_string(val)
+
+ val = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'WPA',
+ dbus_interface=dbus.PROPERTIES_IFACE)
+ wpa = "no"
+ if len(val["KeyMgmt"]) > 0:
+ wpa = "yes"
+ val = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'RSN',
+ dbus_interface=dbus.PROPERTIES_IFACE)
+ wpa2 = "no"
+ if len(val["KeyMgmt"]) > 0:
+ wpa2 = "yes"
+ freq = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'Frequency',
+ dbus_interface=dbus.PROPERTIES_IFACE)
+ signal = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'Signal',
+ dbus_interface=dbus.PROPERTIES_IFACE)
+ val = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'Rates',
+ dbus_interface=dbus.PROPERTIES_IFACE)
+ if len(val) > 0:
+ maxrate = val[0] / 1000000
+ else:
+ maxrate = 0
+
+ print " %s :: ssid='%s' wpa=%s wpa2=%s signal=%d rate=%d freq=%d" % (bssid, ssid, wpa, wpa2, signal, maxrate, freq)
+
+def scanDone(success):
+ print "Scan done: success=%s" % success
+
+ res = if_obj.Get(WPAS_DBUS_INTERFACES_INTERFACE, 'BSSs',
+ dbus_interface=dbus.PROPERTIES_IFACE)
+
+ print "Scanned wireless networks:"
+ for opath in res:
+ print opath
+ showBss(opath)
+
+def bssAdded(bss, properties):
+ print "BSS added: %s" % (bss)
+ showBss(bss)
+
+def bssRemoved(bss):
+ print "BSS removed: %s" % (bss)
+
+def main():
+ dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+ global bus
+ bus = dbus.SystemBus()
+ wpas_obj = bus.get_object(WPAS_DBUS_SERVICE, WPAS_DBUS_OPATH)
+
+ if len(sys.argv) != 2:
+ list_interfaces(wpas_obj)
+ os._exit(1)
+
+ wpas = dbus.Interface(wpas_obj, WPAS_DBUS_INTERFACE)
+ bus.add_signal_receiver(scanDone,
+ dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
+ signal_name="ScanDone")
+ bus.add_signal_receiver(bssAdded,
+ dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
+ signal_name="BSSAdded")
+ bus.add_signal_receiver(bssRemoved,
+ dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
+ signal_name="BSSRemoved")
+ bus.add_signal_receiver(propertiesChanged,
+ dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
+ signal_name="PropertiesChanged")
+
+ ifname = sys.argv[1]
+
+ # See if wpa_supplicant already knows about this interface
+ path = None
+ try:
+ path = wpas.GetInterface(ifname)
+ except dbus.DBusException, exc:
+ if not str(exc).startswith("fi.w1.wpa_supplicant1.InterfaceUnknown:"):
+ raise exc
+ try:
+ path = wpas.CreateInterface({'Ifname': ifname, 'Driver': 'test'})
+ time.sleep(1)
+
+ except dbus.DBusException, exc:
+ if not str(exc).startswith("fi.w1.wpa_supplicant1.InterfaceExists:"):
+ raise exc
+
+ global if_obj
+ if_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
+ global iface
+ iface = dbus.Interface(if_obj, WPAS_DBUS_INTERFACES_INTERFACE)
+ iface.Scan({'Type': 'active'})
+
+ gobject.MainLoop().run()
+
+ wpas.RemoveInterface(dbus.ObjectPath(path))
+
+if __name__ == "__main__":
+ main()
+
diff --git a/contrib/wpa/wpa_supplicant/ibss_rsn.c b/contrib/wpa/wpa_supplicant/ibss_rsn.c
new file mode 100644
index 0000000..0e33253
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/ibss_rsn.c
@@ -0,0 +1,510 @@
+/*
+ * wpa_supplicant - IBSS RSN
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "l2_packet/l2_packet.h"
+#include "rsn_supp/wpa.h"
+#include "rsn_supp/wpa_ie.h"
+#include "ap/wpa_auth.h"
+#include "wpa_supplicant_i.h"
+#include "driver_i.h"
+#include "ibss_rsn.h"
+
+
+static void ibss_rsn_free(struct ibss_rsn_peer *peer)
+{
+ wpa_auth_sta_deinit(peer->auth);
+ wpa_sm_deinit(peer->supp);
+ os_free(peer);
+}
+
+
+static void supp_set_state(void *ctx, enum wpa_states state)
+{
+ struct ibss_rsn_peer *peer = ctx;
+ peer->supp_state = state;
+}
+
+
+static int supp_ether_send(void *ctx, const u8 *dest, u16 proto, const u8 *buf,
+ size_t len)
+{
+ struct ibss_rsn_peer *peer = ctx;
+ struct wpa_supplicant *wpa_s = peer->ibss_rsn->wpa_s;
+
+ wpa_printf(MSG_DEBUG, "SUPP: %s(dest=" MACSTR " proto=0x%04x "
+ "len=%lu)",
+ __func__, MAC2STR(dest), proto, (unsigned long) len);
+
+ if (wpa_s->l2)
+ return l2_packet_send(wpa_s->l2, dest, proto, buf, len);
+
+ return wpa_drv_send_eapol(wpa_s, dest, proto, buf, len);
+}
+
+
+static u8 * supp_alloc_eapol(void *ctx, u8 type, const void *data,
+ u16 data_len, size_t *msg_len, void **data_pos)
+{
+ struct ieee802_1x_hdr *hdr;
+
+ wpa_printf(MSG_DEBUG, "SUPP: %s(type=%d data_len=%d)",
+ __func__, type, data_len);
+
+ *msg_len = sizeof(*hdr) + data_len;
+ hdr = os_malloc(*msg_len);
+ if (hdr == NULL)
+ return NULL;
+
+ hdr->version = 2;
+ hdr->type = type;
+ hdr->length = host_to_be16(data_len);
+
+ if (data)
+ os_memcpy(hdr + 1, data, data_len);
+ else
+ os_memset(hdr + 1, 0, data_len);
+
+ if (data_pos)
+ *data_pos = hdr + 1;
+
+ return (u8 *) hdr;
+}
+
+
+static int supp_get_beacon_ie(void *ctx)
+{
+ struct ibss_rsn_peer *peer = ctx;
+
+ wpa_printf(MSG_DEBUG, "SUPP: %s", __func__);
+ /* TODO: get correct RSN IE */
+ return wpa_sm_set_ap_rsn_ie(peer->supp,
+ (u8 *) "\x30\x14\x01\x00"
+ "\x00\x0f\xac\x04"
+ "\x01\x00\x00\x0f\xac\x04"
+ "\x01\x00\x00\x0f\xac\x02"
+ "\x00\x00", 22);
+}
+
+
+static int supp_set_key(void *ctx, enum wpa_alg alg,
+ const u8 *addr, int key_idx, int set_tx,
+ const u8 *seq, size_t seq_len,
+ const u8 *key, size_t key_len)
+{
+ struct ibss_rsn_peer *peer = ctx;
+
+ wpa_printf(MSG_DEBUG, "SUPP: %s(alg=%d addr=" MACSTR " key_idx=%d "
+ "set_tx=%d)",
+ __func__, alg, MAC2STR(addr), key_idx, set_tx);
+ wpa_hexdump(MSG_DEBUG, "SUPP: set_key - seq", seq, seq_len);
+ wpa_hexdump_key(MSG_DEBUG, "SUPP: set_key - key", key, key_len);
+
+ if (key_idx == 0) {
+ /*
+ * In IBSS RSN, the pairwise key from the 4-way handshake
+ * initiated by the peer with highest MAC address is used.
+ */
+ if (os_memcmp(peer->ibss_rsn->wpa_s->own_addr, peer->addr,
+ ETH_ALEN) > 0) {
+ wpa_printf(MSG_DEBUG, "SUPP: Do not use this PTK");
+ return 0;
+ }
+ }
+
+ return wpa_drv_set_key(peer->ibss_rsn->wpa_s, alg, addr, key_idx,
+ set_tx, seq, seq_len, key, key_len);
+}
+
+
+static void * supp_get_network_ctx(void *ctx)
+{
+ struct ibss_rsn_peer *peer = ctx;
+ return wpa_supplicant_get_ssid(peer->ibss_rsn->wpa_s);
+}
+
+
+static int supp_mlme_setprotection(void *ctx, const u8 *addr,
+ int protection_type, int key_type)
+{
+ wpa_printf(MSG_DEBUG, "SUPP: %s(addr=" MACSTR " protection_type=%d "
+ "key_type=%d)",
+ __func__, MAC2STR(addr), protection_type, key_type);
+ return 0;
+}
+
+
+static void supp_cancel_auth_timeout(void *ctx)
+{
+ wpa_printf(MSG_DEBUG, "SUPP: %s", __func__);
+}
+
+
+int ibss_rsn_supp_init(struct ibss_rsn_peer *peer, const u8 *own_addr,
+ const u8 *psk)
+{
+ struct wpa_sm_ctx *ctx = os_zalloc(sizeof(*ctx));
+ if (ctx == NULL)
+ return -1;
+
+ ctx->ctx = peer;
+ ctx->msg_ctx = peer->ibss_rsn->wpa_s;
+ ctx->set_state = supp_set_state;
+ ctx->ether_send = supp_ether_send;
+ ctx->get_beacon_ie = supp_get_beacon_ie;
+ ctx->alloc_eapol = supp_alloc_eapol;
+ ctx->set_key = supp_set_key;
+ ctx->get_network_ctx = supp_get_network_ctx;
+ ctx->mlme_setprotection = supp_mlme_setprotection;
+ ctx->cancel_auth_timeout = supp_cancel_auth_timeout;
+ peer->supp = wpa_sm_init(ctx);
+ if (peer->supp == NULL) {
+ wpa_printf(MSG_DEBUG, "SUPP: wpa_sm_init() failed");
+ return -1;
+ }
+
+ wpa_sm_set_own_addr(peer->supp, own_addr);
+ wpa_sm_set_param(peer->supp, WPA_PARAM_RSN_ENABLED, 1);
+ wpa_sm_set_param(peer->supp, WPA_PARAM_PROTO, WPA_PROTO_RSN);
+ wpa_sm_set_param(peer->supp, WPA_PARAM_PAIRWISE, WPA_CIPHER_CCMP);
+ wpa_sm_set_param(peer->supp, WPA_PARAM_GROUP, WPA_CIPHER_CCMP);
+ wpa_sm_set_param(peer->supp, WPA_PARAM_KEY_MGMT, WPA_KEY_MGMT_PSK);
+ wpa_sm_set_pmk(peer->supp, psk, PMK_LEN);
+
+ peer->supp_ie_len = sizeof(peer->supp_ie);
+ if (wpa_sm_set_assoc_wpa_ie_default(peer->supp, peer->supp_ie,
+ &peer->supp_ie_len) < 0) {
+ wpa_printf(MSG_DEBUG, "SUPP: wpa_sm_set_assoc_wpa_ie_default()"
+ " failed");
+ return -1;
+ }
+
+ wpa_sm_notify_assoc(peer->supp, peer->addr);
+
+ return 0;
+}
+
+
+static void auth_logger(void *ctx, const u8 *addr, logger_level level,
+ const char *txt)
+{
+ if (addr)
+ wpa_printf(MSG_DEBUG, "AUTH: " MACSTR " - %s",
+ MAC2STR(addr), txt);
+ else
+ wpa_printf(MSG_DEBUG, "AUTH: %s", txt);
+}
+
+
+static const u8 * auth_get_psk(void *ctx, const u8 *addr, const u8 *prev_psk)
+{
+ struct ibss_rsn *ibss_rsn = ctx;
+ wpa_printf(MSG_DEBUG, "AUTH: %s (addr=" MACSTR " prev_psk=%p)",
+ __func__, MAC2STR(addr), prev_psk);
+ if (prev_psk)
+ return NULL;
+ return ibss_rsn->psk;
+}
+
+
+static int auth_send_eapol(void *ctx, const u8 *addr, const u8 *data,
+ size_t data_len, int encrypt)
+{
+ struct ibss_rsn *ibss_rsn = ctx;
+ struct wpa_supplicant *wpa_s = ibss_rsn->wpa_s;
+
+ wpa_printf(MSG_DEBUG, "AUTH: %s(addr=" MACSTR " data_len=%lu "
+ "encrypt=%d)",
+ __func__, MAC2STR(addr), (unsigned long) data_len, encrypt);
+
+ if (wpa_s->l2)
+ return l2_packet_send(wpa_s->l2, addr, ETH_P_EAPOL, data,
+ data_len);
+
+ return wpa_drv_send_eapol(wpa_s, addr, ETH_P_EAPOL, data, data_len);
+}
+
+
+static int auth_set_key(void *ctx, int vlan_id, enum wpa_alg alg,
+ const u8 *addr, int idx, u8 *key, size_t key_len)
+{
+ struct ibss_rsn *ibss_rsn = ctx;
+ u8 seq[6];
+
+ os_memset(seq, 0, sizeof(seq));
+
+ if (addr) {
+ wpa_printf(MSG_DEBUG, "AUTH: %s(alg=%d addr=" MACSTR
+ " key_idx=%d)",
+ __func__, alg, MAC2STR(addr), idx);
+ } else {
+ wpa_printf(MSG_DEBUG, "AUTH: %s(alg=%d key_idx=%d)",
+ __func__, alg, idx);
+ }
+ wpa_hexdump_key(MSG_DEBUG, "AUTH: set_key - key", key, key_len);
+
+ if (idx == 0) {
+ /*
+ * In IBSS RSN, the pairwise key from the 4-way handshake
+ * initiated by the peer with highest MAC address is used.
+ */
+ if (addr == NULL ||
+ os_memcmp(ibss_rsn->wpa_s->own_addr, addr, ETH_ALEN) < 0) {
+ wpa_printf(MSG_DEBUG, "AUTH: Do not use this PTK");
+ return 0;
+ }
+ }
+
+ return wpa_drv_set_key(ibss_rsn->wpa_s, alg, addr, idx,
+ 1, seq, 6, key, key_len);
+}
+
+
+static int ibss_rsn_auth_init_group(struct ibss_rsn *ibss_rsn,
+ const u8 *own_addr)
+{
+ struct wpa_auth_config conf;
+ struct wpa_auth_callbacks cb;
+
+ wpa_printf(MSG_DEBUG, "AUTH: Initializing group state machine");
+
+ os_memset(&conf, 0, sizeof(conf));
+ conf.wpa = 2;
+ conf.wpa_key_mgmt = WPA_KEY_MGMT_PSK;
+ conf.wpa_pairwise = WPA_CIPHER_CCMP;
+ conf.rsn_pairwise = WPA_CIPHER_CCMP;
+ conf.wpa_group = WPA_CIPHER_CCMP;
+ conf.eapol_version = 2;
+
+ os_memset(&cb, 0, sizeof(cb));
+ cb.ctx = ibss_rsn;
+ cb.logger = auth_logger;
+ cb.send_eapol = auth_send_eapol;
+ cb.get_psk = auth_get_psk;
+ cb.set_key = auth_set_key;
+
+ ibss_rsn->auth_group = wpa_init(own_addr, &conf, &cb);
+ if (ibss_rsn->auth_group == NULL) {
+ wpa_printf(MSG_DEBUG, "AUTH: wpa_init() failed");
+ return -1;
+ }
+
+ return 0;
+}
+
+
+static int ibss_rsn_auth_init(struct ibss_rsn *ibss_rsn,
+ struct ibss_rsn_peer *peer)
+{
+ peer->auth = wpa_auth_sta_init(ibss_rsn->auth_group, peer->addr);
+ if (peer->auth == NULL) {
+ wpa_printf(MSG_DEBUG, "AUTH: wpa_auth_sta_init() failed");
+ return -1;
+ }
+
+ /* TODO: get peer RSN IE with Probe Request */
+ if (wpa_validate_wpa_ie(ibss_rsn->auth_group, peer->auth,
+ (u8 *) "\x30\x14\x01\x00"
+ "\x00\x0f\xac\x04"
+ "\x01\x00\x00\x0f\xac\x04"
+ "\x01\x00\x00\x0f\xac\x02"
+ "\x00\x00", 22, NULL, 0) !=
+ WPA_IE_OK) {
+ wpa_printf(MSG_DEBUG, "AUTH: wpa_validate_wpa_ie() failed");
+ return -1;
+ }
+
+ if (wpa_auth_sm_event(peer->auth, WPA_ASSOC))
+ return -1;
+
+ if (wpa_auth_sta_associated(ibss_rsn->auth_group, peer->auth))
+ return -1;
+
+ return 0;
+}
+
+
+int ibss_rsn_start(struct ibss_rsn *ibss_rsn, const u8 *addr)
+{
+ struct ibss_rsn_peer *peer;
+
+ wpa_printf(MSG_DEBUG, "RSN: Starting IBSS Authenticator and "
+ "Supplicant for peer " MACSTR, MAC2STR(addr));
+
+ peer = os_zalloc(sizeof(*peer));
+ if (peer == NULL)
+ return -1;
+
+ peer->ibss_rsn = ibss_rsn;
+ os_memcpy(peer->addr, addr, ETH_ALEN);
+
+ if (ibss_rsn_supp_init(peer, ibss_rsn->wpa_s->own_addr, ibss_rsn->psk)
+ < 0) {
+ ibss_rsn_free(peer);
+ return -1;
+ }
+
+ if (ibss_rsn_auth_init(ibss_rsn, peer) < 0) {
+ ibss_rsn_free(peer);
+ return -1;
+ }
+
+ peer->next = ibss_rsn->peers;
+ ibss_rsn->peers = peer;
+
+ return 0;
+}
+
+
+struct ibss_rsn * ibss_rsn_init(struct wpa_supplicant *wpa_s)
+{
+ struct ibss_rsn *ibss_rsn;
+
+ ibss_rsn = os_zalloc(sizeof(*ibss_rsn));
+ if (ibss_rsn == NULL)
+ return NULL;
+ ibss_rsn->wpa_s = wpa_s;
+
+ if (ibss_rsn_auth_init_group(ibss_rsn, wpa_s->own_addr) < 0) {
+ ibss_rsn_deinit(ibss_rsn);
+ return NULL;
+ }
+
+ return ibss_rsn;
+}
+
+
+void ibss_rsn_deinit(struct ibss_rsn *ibss_rsn)
+{
+ struct ibss_rsn_peer *peer, *prev;
+
+ if (ibss_rsn == NULL)
+ return;
+
+ peer = ibss_rsn->peers;
+ while (peer) {
+ prev = peer;
+ peer = peer->next;
+ ibss_rsn_free(prev);
+ }
+
+ wpa_deinit(ibss_rsn->auth_group);
+ os_free(ibss_rsn);
+
+}
+
+
+static int ibss_rsn_eapol_dst_supp(const u8 *buf, size_t len)
+{
+ const struct ieee802_1x_hdr *hdr;
+ const struct wpa_eapol_key *key;
+ u16 key_info;
+ size_t plen;
+
+ /* TODO: Support other EAPOL packets than just EAPOL-Key */
+
+ if (len < sizeof(*hdr) + sizeof(*key))
+ return -1;
+
+ hdr = (const struct ieee802_1x_hdr *) buf;
+ key = (const struct wpa_eapol_key *) (hdr + 1);
+ plen = be_to_host16(hdr->length);
+
+ if (hdr->version < EAPOL_VERSION) {
+ /* TODO: backwards compatibility */
+ }
+ if (hdr->type != IEEE802_1X_TYPE_EAPOL_KEY) {
+ wpa_printf(MSG_DEBUG, "RSN: EAPOL frame (type %u) discarded, "
+ "not a Key frame", hdr->type);
+ return -1;
+ }
+ if (plen > len - sizeof(*hdr) || plen < sizeof(*key)) {
+ wpa_printf(MSG_DEBUG, "RSN: EAPOL frame payload size %lu "
+ "invalid (frame size %lu)",
+ (unsigned long) plen, (unsigned long) len);
+ return -1;
+ }
+
+ if (key->type != EAPOL_KEY_TYPE_RSN) {
+ wpa_printf(MSG_DEBUG, "RSN: EAPOL-Key type (%d) unknown, "
+ "discarded", key->type);
+ return -1;
+ }
+
+ key_info = WPA_GET_BE16(key->key_info);
+
+ return !!(key_info & WPA_KEY_INFO_ACK);
+}
+
+
+static int ibss_rsn_process_rx_eapol(struct ibss_rsn *ibss_rsn,
+ struct ibss_rsn_peer *peer,
+ const u8 *buf, size_t len)
+{
+ int supp;
+ u8 *tmp;
+
+ supp = ibss_rsn_eapol_dst_supp(buf, len);
+ if (supp < 0)
+ return -1;
+
+ tmp = os_malloc(len);
+ if (tmp == NULL)
+ return -1;
+ os_memcpy(tmp, buf, len);
+ if (supp) {
+ wpa_printf(MSG_DEBUG, "RSN: IBSS RX EAPOL for Supplicant");
+ wpa_sm_rx_eapol(peer->supp, peer->addr, tmp, len);
+ } else {
+ wpa_printf(MSG_DEBUG, "RSN: IBSS RX EAPOL for Authenticator");
+ wpa_receive(ibss_rsn->auth_group, peer->auth, tmp, len);
+ }
+ os_free(tmp);
+
+ return 1;
+}
+
+
+int ibss_rsn_rx_eapol(struct ibss_rsn *ibss_rsn, const u8 *src_addr,
+ const u8 *buf, size_t len)
+{
+ struct ibss_rsn_peer *peer;
+
+ for (peer = ibss_rsn->peers; peer; peer = peer->next) {
+ if (os_memcmp(src_addr, peer->addr, ETH_ALEN) == 0)
+ return ibss_rsn_process_rx_eapol(ibss_rsn, peer,
+ buf, len);
+ }
+
+ if (ibss_rsn_eapol_dst_supp(buf, len) > 0) {
+ /*
+ * Create new IBSS peer based on an EAPOL message from the peer
+ * Authenticator.
+ */
+ if (ibss_rsn_start(ibss_rsn, src_addr) < 0)
+ return -1;
+ return ibss_rsn_process_rx_eapol(ibss_rsn, ibss_rsn->peers,
+ buf, len);
+ }
+
+ return 0;
+}
+
+
+void ibss_rsn_set_psk(struct ibss_rsn *ibss_rsn, const u8 *psk)
+{
+ os_memcpy(ibss_rsn->psk, psk, PMK_LEN);
+}
diff --git a/contrib/wpa/wpa_supplicant/ibss_rsn.h b/contrib/wpa/wpa_supplicant/ibss_rsn.h
new file mode 100644
index 0000000..11e63ad
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/ibss_rsn.h
@@ -0,0 +1,49 @@
+/*
+ * wpa_supplicant - IBSS RSN
+ * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef IBSS_RSN_H
+#define IBSS_RSN_H
+
+struct ibss_rsn;
+
+struct ibss_rsn_peer {
+ struct ibss_rsn_peer *next;
+ struct ibss_rsn *ibss_rsn;
+
+ u8 addr[ETH_ALEN];
+
+ struct wpa_sm *supp;
+ enum wpa_states supp_state;
+ u8 supp_ie[80];
+ size_t supp_ie_len;
+
+ struct wpa_state_machine *auth;
+};
+
+struct ibss_rsn {
+ struct wpa_supplicant *wpa_s;
+ struct wpa_authenticator *auth_group;
+ struct ibss_rsn_peer *peers;
+ u8 psk[PMK_LEN];
+};
+
+
+struct ibss_rsn * ibss_rsn_init(struct wpa_supplicant *wpa_s);
+void ibss_rsn_deinit(struct ibss_rsn *ibss_rsn);
+int ibss_rsn_start(struct ibss_rsn *ibss_rsn, const u8 *addr);
+int ibss_rsn_rx_eapol(struct ibss_rsn *ibss_rsn, const u8 *src_addr,
+ const u8 *buf, size_t len);
+void ibss_rsn_set_psk(struct ibss_rsn *ibss_rsn, const u8 *psk);
+
+#endif /* IBSS_RSN_H */
diff --git a/contrib/wpa/wpa_supplicant/main.c b/contrib/wpa/wpa_supplicant/main.c
index 1f413f1..c0aa59c 100644
--- a/contrib/wpa/wpa_supplicant/main.c
+++ b/contrib/wpa/wpa_supplicant/main.c
@@ -19,6 +19,9 @@
#include "common.h"
#include "wpa_supplicant_i.h"
+#include "driver_i.h"
+
+extern struct wpa_driver_ops *wpa_drivers[];
static void usage(void)
@@ -26,23 +29,12 @@ static void usage(void)
int i;
printf("%s\n\n%s\n"
"usage:\n"
- " wpa_supplicant [-BddhKLqq"
-#ifdef CONFIG_DEBUG_SYSLOG
- "s"
-#endif /* CONFIG_DEBUG_SYSLOG */
- "t"
-#ifdef CONFIG_CTRL_IFACE_DBUS
- "u"
-#endif /* CONFIG_CTRL_IFACE_DBUS */
- "vW] [-P<pid file>] "
+ " wpa_supplicant [-BddhKLqqstuvW] [-P<pid file>] "
"[-g<global ctrl>] \\\n"
" -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] "
"[-p<driver_param>] \\\n"
- " [-b<br_ifname>]"
-#ifdef CONFIG_DEBUG_FILE
- " [-f<debug file>]"
-#endif /* CONFIG_DEBUG_FILE */
- " \\\n"
+ " [-b<br_ifname>] [-f<debug file>] \\\n"
+ " [-o<override driver>] [-O<override ctrl>] \\\n"
" [-N -i<ifname> -c<conf> [-C<ctrl>] "
"[-D<driver>] \\\n"
" [-p<driver_param>] [-b<br_ifname>] ...]\n"
@@ -50,10 +42,10 @@ static void usage(void)
"drivers:\n",
wpa_supplicant_version, wpa_supplicant_license);
- for (i = 0; wpa_supplicant_drivers[i]; i++) {
+ for (i = 0; wpa_drivers[i]; i++) {
printf(" %s = %s\n",
- wpa_supplicant_drivers[i]->name,
- wpa_supplicant_drivers[i]->desc);
+ wpa_drivers[i]->name,
+ wpa_drivers[i]->desc);
}
#ifndef CONFIG_NO_STDOUT_DEBUG
@@ -64,32 +56,33 @@ static void usage(void)
" -C = ctrl_interface parameter (only used if -c is not)\n"
" -i = interface name\n"
" -d = increase debugging verbosity (-dd even more)\n"
- " -D = driver name\n"
+ " -D = driver name (can be multiple drivers: nl80211,wext)\n");
#ifdef CONFIG_DEBUG_FILE
- " -f = log output to debug file instead of stdout\n"
+ printf(" -f = log output to debug file instead of stdout\n");
#endif /* CONFIG_DEBUG_FILE */
- " -g = global ctrl_interface\n"
- " -K = include keys (passwords, etc.) in debug output\n"
+ printf(" -g = global ctrl_interface\n"
+ " -K = include keys (passwords, etc.) in debug output\n");
#ifdef CONFIG_DEBUG_SYSLOG
- " -s = log output to syslog instead of stdout\n"
+ printf(" -s = log output to syslog instead of stdout\n");
#endif /* CONFIG_DEBUG_SYSLOG */
- " -t = include timestamp in debug messages\n"
+ printf(" -t = include timestamp in debug messages\n"
" -h = show this help text\n"
- " -L = show license (GPL and BSD)\n");
- printf(" -p = driver parameters\n"
+ " -L = show license (GPL and BSD)\n"
+ " -o = override driver parameter for new interfaces\n"
+ " -O = override ctrl_interface parameter for new interfaces\n"
+ " -p = driver parameters\n"
" -P = PID file\n"
- " -q = decrease debugging verbosity (-qq even less)\n"
-#ifdef CONFIG_CTRL_IFACE_DBUS
- " -u = enable DBus control interface\n"
-#endif /* CONFIG_CTRL_IFACE_DBUS */
- " -v = show version\n"
+ " -q = decrease debugging verbosity (-qq even less)\n");
+#ifdef CONFIG_DBUS
+ printf(" -u = enable DBus control interface\n");
+#endif /* CONFIG_DBUS */
+ printf(" -v = show version\n"
" -W = wait for a control interface monitor before starting\n"
" -N = start describing new interface\n");
printf("example:\n"
" wpa_supplicant -D%s -iwlan0 -c/etc/wpa_supplicant.conf\n",
- wpa_supplicant_drivers[i] ?
- wpa_supplicant_drivers[i]->name : "wext");
+ wpa_drivers[i] ? wpa_drivers[i]->name : "wext");
#endif /* CONFIG_NO_STDOUT_DEBUG */
}
@@ -150,7 +143,7 @@ int main(int argc, char *argv[])
wpa_supplicant_fd_workaround();
for (;;) {
- c = getopt(argc, argv, "b:Bc:C:D:df:g:hi:KLNp:P:qstuvW");
+ c = getopt(argc, argv, "b:Bc:C:D:df:g:hi:KLNo:O:p:P:qstuvW");
if (c < 0)
break;
switch (c) {
@@ -201,6 +194,12 @@ int main(int argc, char *argv[])
license();
exitcode = 0;
goto out;
+ case 'o':
+ params.override_driver = optarg;
+ break;
+ case 'O':
+ params.override_ctrl_interface = optarg;
+ break;
case 'p':
iface->driver_param = optarg;
break;
@@ -219,11 +218,11 @@ int main(int argc, char *argv[])
case 't':
params.wpa_debug_timestamp++;
break;
-#ifdef CONFIG_CTRL_IFACE_DBUS
+#ifdef CONFIG_DBUS
case 'u':
params.dbus_ctrl_interface = 1;
break;
-#endif /* CONFIG_CTRL_IFACE_DBUS */
+#endif /* CONFIG_DBUS */
case 'v':
printf("%s\n", wpa_supplicant_version);
exitcode = 0;
diff --git a/contrib/wpa/wpa_supplicant/mlme.c b/contrib/wpa/wpa_supplicant/mlme.c
index 9885e19..eb60ac5 100644
--- a/contrib/wpa/wpa_supplicant/mlme.c
+++ b/contrib/wpa/wpa_supplicant/mlme.c
@@ -20,10 +20,11 @@
#include "eloop.h"
#include "config_ssid.h"
#include "wpa_supplicant_i.h"
-#include "wpa.h"
-#include "drivers/driver.h"
-#include "ieee802_11_defs.h"
-#include "ieee802_11_common.h"
+#include "notify.h"
+#include "driver_i.h"
+#include "rsn_supp/wpa.h"
+#include "common/ieee802_11_defs.h"
+#include "common/ieee802_11_common.h"
#include "mlme.h"
@@ -94,14 +95,17 @@ static int ieee80211_sta_find_ibss(struct wpa_supplicant *wpa_s);
static int ieee80211_sta_wep_configured(struct wpa_supplicant *wpa_s);
static void ieee80211_sta_timer(void *eloop_ctx, void *timeout_ctx);
static void ieee80211_sta_scan_timer(void *eloop_ctx, void *timeout_ctx);
+static void ieee80211_build_tspec(struct wpabuf *buf);
+static int ieee80211_sta_set_probe_req_ie(struct wpa_supplicant *wpa_s,
+ const u8 *ies, size_t ies_len);
static int ieee80211_sta_set_channel(struct wpa_supplicant *wpa_s,
- wpa_hw_mode phymode, int chan,
+ enum hostapd_hw_mode phymode, int chan,
int freq)
{
size_t i;
- struct wpa_hw_modes *mode;
+ struct hostapd_hw_modes *mode;
for (i = 0; i < wpa_s->mlme.num_modes; i++) {
mode = &wpa_s->mlme.modes[i];
@@ -116,8 +120,6 @@ static int ieee80211_sta_set_channel(struct wpa_supplicant *wpa_s,
}
-
-#if 0 /* FIX */
static int ecw2cw(int ecw)
{
int cw = 1;
@@ -127,15 +129,15 @@ static int ecw2cw(int ecw)
}
return cw - 1;
}
-#endif
static void ieee80211_sta_wmm_params(struct wpa_supplicant *wpa_s,
- u8 *wmm_param, size_t wmm_param_len)
+ const u8 *wmm_param, size_t wmm_param_len)
{
size_t left;
int count;
- u8 *pos;
+ const u8 *pos;
+ u8 wmm_acm;
if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
return;
@@ -147,54 +149,42 @@ static void ieee80211_sta_wmm_params(struct wpa_supplicant *wpa_s,
pos = wmm_param + 8;
left = wmm_param_len - 8;
-#if 0 /* FIX */
wmm_acm = 0;
for (; left >= 4; left -= 4, pos += 4) {
int aci = (pos[0] >> 5) & 0x03;
int acm = (pos[0] >> 4) & 0x01;
- int queue;
+ int aifs, cw_max, cw_min, burst_time;
switch (aci) {
- case 1:
- queue = IEEE80211_TX_QUEUE_DATA3;
+ case 1: /* AC_BK */
if (acm)
- wmm_acm |= BIT(1) | BIT(2);
+ wmm_acm |= BIT(1) | BIT(2); /* BK/- */
break;
- case 2:
- queue = IEEE80211_TX_QUEUE_DATA1;
+ case 2: /* AC_VI */
if (acm)
- wmm_acm |= BIT(4) | BIT(5);
+ wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
break;
- case 3:
- queue = IEEE80211_TX_QUEUE_DATA0;
+ case 3: /* AC_VO */
if (acm)
- wmm_acm |= BIT(6) | BIT(7);
+ wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
break;
- case 0:
+ case 0: /* AC_BE */
default:
- queue = IEEE80211_TX_QUEUE_DATA2;
if (acm)
- wpa_s->mlme.wmm_acm |= BIT(0) | BIT(3);
+ wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
break;
}
- params.aifs = pos[0] & 0x0f;
- params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
- params.cw_min = ecw2cw(pos[1] & 0x0f);
+ aifs = pos[0] & 0x0f;
+ cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
+ cw_min = ecw2cw(pos[1] & 0x0f);
/* TXOP is in units of 32 usec; burst_time in 0.1 ms */
- params.burst_time = (pos[2] | (pos[3] << 8)) * 32 / 100;
- wpa_printf(MSG_DEBUG, "MLME: WMM queue=%d aci=%d acm=%d "
- "aifs=%d cWmin=%d cWmax=%d burst=%d",
- queue, aci, acm, params.aifs, params.cw_min,
- params.cw_max, params.burst_time);
- /* TODO: handle ACM (block TX, fallback to next lowest allowed
- * AC for now) */
- if (local->hw->conf_tx(local->mdev, queue, &params)) {
- wpa_printf(MSG_DEBUG, "MLME: failed to set TX queue "
- "parameters for queue %d", queue);
- }
+ burst_time = (pos[2] | (pos[3] << 8)) * 32 / 100;
+ wpa_printf(MSG_DEBUG, "MLME: WMM aci=%d acm=%d aifs=%d "
+ "cWmin=%d cWmax=%d burst=%d",
+ aci, acm, aifs, cw_min, cw_max, burst_time);
+ /* TODO: driver configuration */
}
-#endif
}
@@ -214,6 +204,7 @@ static void ieee80211_set_associated(struct wpa_supplicant *wpa_s, int assoc)
data.assoc_info.req_ies_len = wpa_s->mlme.assocreq_ies_len;
data.assoc_info.resp_ies = wpa_s->mlme.assocresp_ies;
data.assoc_info.resp_ies_len = wpa_s->mlme.assocresp_ies_len;
+ data.assoc_info.freq = wpa_s->mlme.freq;
wpa_supplicant_event(wpa_s, EVENT_ASSOC, &data);
} else {
wpa_supplicant_event(wpa_s, EVENT_DISASSOC, NULL);
@@ -230,8 +221,8 @@ static int ieee80211_sta_tx(struct wpa_supplicant *wpa_s, const u8 *buf,
static void ieee80211_send_auth(struct wpa_supplicant *wpa_s,
- int transaction, u8 *extra, size_t extra_len,
- int encrypt)
+ int transaction, const u8 *extra,
+ size_t extra_len, int encrypt)
{
u8 *buf;
size_t len;
@@ -352,7 +343,7 @@ static void ieee80211_send_assoc(struct wpa_supplicant *wpa_s)
blen = 0;
capab = wpa_s->mlme.capab;
- if (wpa_s->mlme.phymode == WPA_MODE_IEEE80211G) {
+ if (wpa_s->mlme.phymode == HOSTAPD_MODE_IEEE80211G) {
capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME |
WLAN_CAPABILITY_SHORT_PREAMBLE;
}
@@ -403,20 +394,16 @@ static void ieee80211_send_assoc(struct wpa_supplicant *wpa_s)
blen += len + 2;
*pos++ = WLAN_EID_SUPP_RATES;
*pos++ = len;
- for (i = 0; i < len; i++) {
- int rate = wpa_s->mlme.curr_rates[i].rate;
- *pos++ = (u8) (rate / 5);
- }
+ for (i = 0; i < len; i++)
+ *pos++ = (u8) (wpa_s->mlme.curr_rates[i] / 5);
if (wpa_s->mlme.num_curr_rates > len) {
pos = buf + blen;
blen += wpa_s->mlme.num_curr_rates - len + 2;
*pos++ = WLAN_EID_EXT_SUPP_RATES;
*pos++ = wpa_s->mlme.num_curr_rates - len;
- for (i = len; i < wpa_s->mlme.num_curr_rates; i++) {
- int rate = wpa_s->mlme.curr_rates[i].rate;
- *pos++ = (u8) (rate / 5);
- }
+ for (i = len; i < wpa_s->mlme.num_curr_rates; i++)
+ *pos++ = (u8) (wpa_s->mlme.curr_rates[i] / 5);
}
if (wpa_s->mlme.extra_ie && wpa_s->mlme.auth_alg != WLAN_AUTH_FT) {
@@ -683,7 +670,6 @@ static void ieee80211_send_probe_req(struct wpa_supplicant *wpa_s,
supp_rates[0] = WLAN_EID_SUPP_RATES;
supp_rates[1] = 0;
for (i = 0; i < wpa_s->mlme.num_curr_rates; i++) {
- struct wpa_rate_data *rate = &wpa_s->mlme.curr_rates[i];
if (esupp_rates) {
pos = buf + len;
len++;
@@ -699,7 +685,7 @@ static void ieee80211_send_probe_req(struct wpa_supplicant *wpa_s,
len++;
supp_rates[1]++;
}
- *pos++ = rate->rate / 5;
+ *pos++ = wpa_s->mlme.curr_rates[i] / 5;
}
if (wpa_s->mlme.extra_probe_ie) {
@@ -768,7 +754,7 @@ static void ieee80211_rx_mgmt_auth(struct wpa_supplicant *wpa_s,
u16 auth_alg, auth_transaction, status_code;
int adhoc;
- adhoc = ssid && ssid->mode == 1;
+ adhoc = ssid && ssid->mode == WPAS_MODE_IBSS;
if (wpa_s->mlme.state != IEEE80211_AUTHENTICATE && !adhoc) {
wpa_printf(MSG_DEBUG, "MLME: authentication frame received "
@@ -841,12 +827,11 @@ static void ieee80211_rx_mgmt_auth(struct wpa_supplicant *wpa_s,
u8 algs[num_algs];
int i, pos;
algs[0] = algs[1] = algs[2] = 0xff;
- if (wpa_s->mlme.auth_algs & IEEE80211_AUTH_ALG_OPEN)
+ if (wpa_s->mlme.auth_algs & WPA_AUTH_ALG_OPEN)
algs[0] = WLAN_AUTH_OPEN;
- if (wpa_s->mlme.auth_algs &
- IEEE80211_AUTH_ALG_SHARED_KEY)
+ if (wpa_s->mlme.auth_algs & WPA_AUTH_ALG_SHARED)
algs[1] = WLAN_AUTH_SHARED_KEY;
- if (wpa_s->mlme.auth_algs & IEEE80211_AUTH_ALG_LEAP)
+ if (wpa_s->mlme.auth_algs & WPA_AUTH_ALG_LEAP)
algs[2] = WLAN_AUTH_LEAP;
if (wpa_s->mlme.auth_alg == WLAN_AUTH_OPEN)
pos = 0;
@@ -890,12 +875,36 @@ static void ieee80211_rx_mgmt_auth(struct wpa_supplicant *wpa_s,
case WLAN_AUTH_FT:
{
union wpa_event_data data;
+ struct wpabuf *ric = NULL;
os_memset(&data, 0, sizeof(data));
data.ft_ies.ies = mgmt->u.auth.variable;
data.ft_ies.ies_len = len -
(mgmt->u.auth.variable - (u8 *) mgmt);
os_memcpy(data.ft_ies.target_ap, wpa_s->bssid, ETH_ALEN);
+ if (os_strcmp(wpa_s->driver->name, "test") == 0 &&
+ wpa_s->mlme.wmm_enabled) {
+ ric = wpabuf_alloc(200);
+ if (ric) {
+ /* Build simple RIC-Request: RDIE | TSPEC */
+
+ /* RIC Data (RDIE) */
+ wpabuf_put_u8(ric, WLAN_EID_RIC_DATA);
+ wpabuf_put_u8(ric, 4);
+ wpabuf_put_u8(ric, 0); /* RDIE Identifier */
+ wpabuf_put_u8(ric, 1); /* Resource Descriptor
+ * Count */
+ wpabuf_put_le16(ric, 0); /* Status Code */
+
+ /* WMM TSPEC */
+ ieee80211_build_tspec(ric);
+
+ data.ft_ies.ric_ies = wpabuf_head(ric);
+ data.ft_ies.ric_ies_len = wpabuf_len(ric);
+ }
+ }
+
wpa_supplicant_event(wpa_s, EVENT_FT_RESPONSE, &data);
+ wpabuf_free(ric);
ieee80211_auth_completed(wpa_s);
break;
}
@@ -987,42 +996,63 @@ static void ieee80211_rx_mgmt_disassoc(struct wpa_supplicant *wpa_s,
}
-static int ieee80211_ft_assoc_resp(struct wpa_supplicant *wpa_s,
- struct ieee802_11_elems *elems)
+static void ieee80211_build_tspec(struct wpabuf *buf)
{
-#ifdef CONFIG_IEEE80211R
- const u8 *mobility_domain = NULL;
- const u8 *r0kh_id = NULL;
- size_t r0kh_id_len = 0;
- const u8 *r1kh_id = NULL;
- struct rsn_ftie *hdr;
- const u8 *pos, *end;
-
- if (elems->mdie && elems->mdie_len >= MOBILITY_DOMAIN_ID_LEN)
- mobility_domain = elems->mdie;
- if (elems->ftie && elems->ftie_len >= sizeof(struct rsn_ftie)) {
- end = elems->ftie + elems->ftie_len;
- hdr = (struct rsn_ftie *) elems->ftie;
- pos = (const u8 *) (hdr + 1);
- while (pos + 1 < end) {
- if (pos + 2 + pos[1] > end)
- break;
- if (pos[0] == FTIE_SUBELEM_R1KH_ID &&
- pos[1] == FT_R1KH_ID_LEN)
- r1kh_id = pos + 2;
- else if (pos[0] == FTIE_SUBELEM_R0KH_ID &&
- pos[1] >= 1 && pos[1] <= FT_R0KH_ID_MAX_LEN) {
- r0kh_id = pos + 2;
- r0kh_id_len = pos[1];
- }
- pos += 2 + pos[1];
- }
- }
- return wpa_sm_set_ft_params(wpa_s->wpa, mobility_domain, r0kh_id,
- r0kh_id_len, r1kh_id);
-#else /* CONFIG_IEEE80211R */
- return 0;
-#endif /* CONFIG_IEEE80211R */
+ struct wmm_tspec_element *tspec;
+ int tid, up;
+
+ tspec = wpabuf_put(buf, sizeof(*tspec));
+ tspec->eid = WLAN_EID_VENDOR_SPECIFIC;
+ tspec->length = sizeof(*tspec) - 2;
+ tspec->oui[0] = 0x00;
+ tspec->oui[1] = 0x50;
+ tspec->oui[2] = 0xf2;
+ tspec->oui_type = 2;
+ tspec->oui_subtype = 2;
+ tspec->version = 1;
+
+ tid = 1;
+ up = 6; /* Voice */
+ tspec->ts_info[0] = (tid << 1) |
+ (WMM_TSPEC_DIRECTION_BI_DIRECTIONAL << 5) |
+ BIT(7);
+ tspec->ts_info[1] = up << 3;
+ tspec->nominal_msdu_size = host_to_le16(1530);
+ tspec->mean_data_rate = host_to_le32(128000); /* bits per second */
+ tspec->minimum_phy_rate = host_to_le32(6000000);
+ tspec->surplus_bandwidth_allowance = host_to_le16(0x3000); /* 150% */
+}
+
+
+static void ieee80211_tx_addts(struct wpa_supplicant *wpa_s)
+{
+ struct wpabuf *buf;
+ struct ieee80211_mgmt *mgmt;
+ size_t alen;
+
+ wpa_printf(MSG_DEBUG, "MLME: Send ADDTS Request for Voice TSPEC");
+ mgmt = NULL;
+ alen = mgmt->u.action.u.wmm_action.variable - (u8 *) mgmt;
+
+ buf = wpabuf_alloc(alen + sizeof(struct wmm_tspec_element));
+ if (buf == NULL)
+ return;
+
+ mgmt = wpabuf_put(buf, alen);
+ os_memcpy(mgmt->da, wpa_s->bssid, ETH_ALEN);
+ os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
+ os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN);
+ mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
+ WLAN_FC_STYPE_ACTION);
+ mgmt->u.action.category = WLAN_ACTION_WMM;
+ mgmt->u.action.u.wmm_action.action_code = WMM_ACTION_CODE_ADDTS_REQ;
+ mgmt->u.action.u.wmm_action.dialog_token = 1;
+ mgmt->u.action.u.wmm_action.status_code = 0;
+
+ ieee80211_build_tspec(buf);
+
+ ieee80211_sta_tx(wpa_s, wpabuf_head(buf), wpabuf_len(buf));
+ wpabuf_free(buf);
}
@@ -1125,7 +1155,8 @@ static void ieee80211_rx_mgmt_assoc_resp(struct wpa_supplicant *wpa_s,
"Resp failed");
return;
}
- } else if (ieee80211_ft_assoc_resp(wpa_s, &elems) < 0)
+ } else if (wpa_sm_set_ft_params(wpa_s->wpa, pos,
+ len - (pos - (u8 *) mgmt)) < 0)
return;
wpa_printf(MSG_DEBUG, "MLME: associated");
@@ -1172,16 +1203,17 @@ static void ieee80211_rx_mgmt_assoc_resp(struct wpa_supplicant *wpa_s,
"netstack");
}
-#if 0 /* FIX? */
- sta->assoc_ap = 1;
-
- if (elems.wmm && wpa_s->mlme.wmm_enabled) {
- sta->flags |= WLAN_STA_WMM;
+ if (elems.wmm && wpa_s->mlme.wmm_enabled)
ieee80211_sta_wmm_params(wpa_s, elems.wmm, elems.wmm_len);
- }
-#endif
ieee80211_associated(wpa_s);
+
+ if (wpa_s->mlme.auth_alg != WLAN_AUTH_FT &&
+ os_strcmp(wpa_s->driver->name, "test") == 0 &&
+ elems.wmm && wpa_s->mlme.wmm_enabled) {
+ /* Test WMM-AC - send ADDTS for WMM TSPEC */
+ ieee80211_tx_addts(wpa_s);
+ }
}
@@ -1528,8 +1560,8 @@ static void ieee80211_bss_info(struct wpa_supplicant *wpa_s,
bss->channel = channel;
bss->freq = wpa_s->mlme.freq;
if (channel != wpa_s->mlme.channel &&
- (wpa_s->mlme.phymode == WPA_MODE_IEEE80211G ||
- wpa_s->mlme.phymode == WPA_MODE_IEEE80211B) &&
+ (wpa_s->mlme.phymode == HOSTAPD_MODE_IEEE80211G ||
+ wpa_s->mlme.phymode == HOSTAPD_MODE_IEEE80211B) &&
channel >= 1 && channel <= 14) {
static const int freq_list[] = {
2412, 2417, 2422, 2427, 2432, 2437, 2442,
@@ -1614,7 +1646,7 @@ static void ieee80211_rx_mgmt_probe_req(struct wpa_supplicant *wpa_s,
u8 *pos, *end;
struct wpa_ssid *ssid = wpa_s->current_ssid;
- adhoc = ssid && ssid->mode == 1;
+ adhoc = ssid && ssid->mode == WPAS_MODE_IBSS;
if (!adhoc || wpa_s->mlme.state != IEEE80211_IBSS_JOINED ||
len < 24 + 2 || wpa_s->mlme.probe_resp == NULL)
@@ -1807,6 +1839,119 @@ static void ieee80211_rx_mgmt_sa_query_action(
#endif /* CONFIG_IEEE80211W */
+static void dump_tspec(struct wmm_tspec_element *tspec)
+{
+ int up, psb, dir, tid;
+ u16 val;
+
+ up = (tspec->ts_info[1] >> 3) & 0x07;
+ psb = (tspec->ts_info[1] >> 2) & 0x01;
+ dir = (tspec->ts_info[0] >> 5) & 0x03;
+ tid = (tspec->ts_info[0] >> 1) & 0x0f;
+ wpa_printf(MSG_DEBUG, "WMM: TS Info: UP=%d PSB=%d Direction=%d TID=%d",
+ up, psb, dir, tid);
+ val = le_to_host16(tspec->nominal_msdu_size);
+ wpa_printf(MSG_DEBUG, "WMM: Nominal MSDU Size: %d%s",
+ val & 0x7fff, val & 0x8000 ? " (fixed)" : "");
+ wpa_printf(MSG_DEBUG, "WMM: Mean Data Rate: %u bps",
+ le_to_host32(tspec->mean_data_rate));
+ wpa_printf(MSG_DEBUG, "WMM: Minimum PHY Rate: %u bps",
+ le_to_host32(tspec->minimum_phy_rate));
+ val = le_to_host16(tspec->surplus_bandwidth_allowance);
+ wpa_printf(MSG_DEBUG, "WMM: Surplus Bandwidth Allowance: %u.%04u",
+ val >> 13, 10000 * (val & 0x1fff) / 0x2000);
+ val = le_to_host16(tspec->medium_time);
+ wpa_printf(MSG_DEBUG, "WMM: Medium Time: %u (= %u usec/sec)",
+ val, 32 * val);
+}
+
+
+static int is_wmm_tspec(const u8 *ie, size_t len)
+{
+ const struct wmm_tspec_element *tspec;
+
+ if (len < sizeof(*tspec))
+ return 0;
+
+ tspec = (const struct wmm_tspec_element *) ie;
+ if (tspec->eid != WLAN_EID_VENDOR_SPECIFIC ||
+ tspec->length < sizeof(*tspec) - 2 ||
+ tspec->oui[0] != 0x00 || tspec->oui[1] != 0x50 ||
+ tspec->oui[2] != 0xf2 || tspec->oui_type != 2 ||
+ tspec->oui_subtype != 2 || tspec->version != 1)
+ return 0;
+
+ return 1;
+}
+
+
+static void ieee80211_rx_addts_resp(
+ struct wpa_supplicant *wpa_s, struct ieee80211_mgmt *mgmt, size_t len,
+ size_t var_len)
+{
+ struct wmm_tspec_element *tspec;
+
+ wpa_printf(MSG_DEBUG, "WMM: Received ADDTS Response");
+ wpa_hexdump(MSG_MSGDUMP, "WMM: ADDTS Response IE(s)",
+ mgmt->u.action.u.wmm_action.variable, var_len);
+ if (!is_wmm_tspec(mgmt->u.action.u.wmm_action.variable, var_len))
+ return;
+ tspec = (struct wmm_tspec_element *)
+ mgmt->u.action.u.wmm_action.variable;
+ dump_tspec(tspec);
+}
+
+
+static void ieee80211_rx_delts(
+ struct wpa_supplicant *wpa_s, struct ieee80211_mgmt *mgmt, size_t len,
+ size_t var_len)
+{
+ struct wmm_tspec_element *tspec;
+
+ wpa_printf(MSG_DEBUG, "WMM: Received DELTS");
+ wpa_hexdump(MSG_MSGDUMP, "WMM: DELTS IE(s)",
+ mgmt->u.action.u.wmm_action.variable, var_len);
+ if (!is_wmm_tspec(mgmt->u.action.u.wmm_action.variable, var_len))
+ return;
+ tspec = (struct wmm_tspec_element *)
+ mgmt->u.action.u.wmm_action.variable;
+ dump_tspec(tspec);
+}
+
+
+static void ieee80211_rx_mgmt_wmm_action(
+ struct wpa_supplicant *wpa_s, struct ieee80211_mgmt *mgmt, size_t len,
+ struct ieee80211_rx_status *rx_status)
+{
+ size_t alen;
+
+ alen = mgmt->u.action.u.wmm_action.variable - (u8 *) mgmt;
+ if (len < alen) {
+ wpa_printf(MSG_DEBUG, "WMM: Received Action frame too short");
+ return;
+ }
+
+ wpa_printf(MSG_DEBUG, "WMM: Received Action frame: Action Code %d, "
+ "Dialog Token %d, Status Code %d",
+ mgmt->u.action.u.wmm_action.action_code,
+ mgmt->u.action.u.wmm_action.dialog_token,
+ mgmt->u.action.u.wmm_action.status_code);
+
+ switch (mgmt->u.action.u.wmm_action.action_code) {
+ case WMM_ACTION_CODE_ADDTS_RESP:
+ ieee80211_rx_addts_resp(wpa_s, mgmt, len, len - alen);
+ break;
+ case WMM_ACTION_CODE_DELTS:
+ ieee80211_rx_delts(wpa_s, mgmt, len, len - alen);
+ break;
+ default:
+ wpa_printf(MSG_DEBUG, "WMM: Unsupported Action Code %d",
+ mgmt->u.action.u.wmm_action.action_code);
+ break;
+ }
+}
+
+
static void ieee80211_rx_mgmt_action(struct wpa_supplicant *wpa_s,
struct ieee80211_mgmt *mgmt,
size_t len,
@@ -1828,6 +1973,17 @@ static void ieee80211_rx_mgmt_action(struct wpa_supplicant *wpa_s,
ieee80211_rx_mgmt_sa_query_action(wpa_s, mgmt, len, rx_status);
break;
#endif /* CONFIG_IEEE80211W */
+ case WLAN_ACTION_WMM:
+ ieee80211_rx_mgmt_wmm_action(wpa_s, mgmt, len, rx_status);
+ break;
+ case WLAN_ACTION_PUBLIC:
+ if (wpa_s->mlme.public_action_cb) {
+ wpa_s->mlme.public_action_cb(
+ wpa_s->mlme.public_action_cb_ctx,
+ (u8 *) mgmt, len, rx_status->freq);
+ return;
+ }
+ break;
default:
wpa_printf(MSG_DEBUG, "MLME: unknown Action Category %d",
mgmt->u.action.category);
@@ -1947,6 +2103,8 @@ static void ieee80211_sta_expire(struct wpa_supplicant *wpa_s)
static void ieee80211_sta_merge_ibss(struct wpa_supplicant *wpa_s)
{
+ struct wpa_driver_scan_params params;
+
ieee80211_reschedule_timer(wpa_s, IEEE80211_IBSS_MERGE_INTERVAL);
ieee80211_sta_expire(wpa_s);
@@ -1955,7 +2113,11 @@ static void ieee80211_sta_merge_ibss(struct wpa_supplicant *wpa_s)
wpa_printf(MSG_DEBUG, "MLME: No active IBSS STAs - trying to scan for "
"other IBSS networks with same SSID (merge)");
- ieee80211_sta_req_scan(wpa_s, wpa_s->mlme.ssid, wpa_s->mlme.ssid_len);
+ os_memset(&params, 0, sizeof(params));
+ params.ssids[0].ssid = wpa_s->mlme.ssid;
+ params.ssids[0].ssid_len = wpa_s->mlme.ssid_len;
+ params.num_ssids = wpa_s->mlme.ssid_len ? 1 : 0;
+ ieee80211_sta_req_scan(wpa_s, &params);
}
@@ -2000,7 +2162,7 @@ static void ieee80211_sta_timer(void *eloop_ctx, void *timeout_ctx)
static void ieee80211_sta_new_auth(struct wpa_supplicant *wpa_s)
{
struct wpa_ssid *ssid = wpa_s->current_ssid;
- if (ssid && ssid->mode != 0)
+ if (ssid && ssid->mode != WPAS_MODE_INFRA)
return;
#if 0 /* FIX */
@@ -2013,11 +2175,11 @@ static void ieee80211_sta_new_auth(struct wpa_supplicant *wpa_s)
wpa_s->mlme.wmm_last_param_set = -1; /* allow any WMM update */
- if (wpa_s->mlme.auth_algs & IEEE80211_AUTH_ALG_OPEN)
+ if (wpa_s->mlme.auth_algs & WPA_AUTH_ALG_OPEN)
wpa_s->mlme.auth_alg = WLAN_AUTH_OPEN;
- else if (wpa_s->mlme.auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
+ else if (wpa_s->mlme.auth_algs & WPA_AUTH_ALG_SHARED)
wpa_s->mlme.auth_alg = WLAN_AUTH_SHARED_KEY;
- else if (wpa_s->mlme.auth_algs & IEEE80211_AUTH_ALG_LEAP)
+ else if (wpa_s->mlme.auth_algs & WPA_AUTH_ALG_LEAP)
wpa_s->mlme.auth_alg = WLAN_AUTH_LEAP;
else
wpa_s->mlme.auth_alg = WLAN_AUTH_OPEN;
@@ -2057,7 +2219,7 @@ static int ieee80211_ibss_allowed(struct wpa_supplicant *wpa_s)
static int ieee80211_sta_join_ibss(struct wpa_supplicant *wpa_s,
struct ieee80211_sta_bss *bss)
{
- int res = 0, rates, done = 0;
+ int res = 0, rates, done = 0, bssid_changed;
struct ieee80211_mgmt *mgmt;
#if 0 /* FIX */
struct ieee80211_tx_control control;
@@ -2076,7 +2238,10 @@ static int ieee80211_sta_join_ibss(struct wpa_supplicant *wpa_s,
local->hw->reset_tsf(local->mdev);
}
#endif
+ bssid_changed = os_memcmp(wpa_s->bssid, bss->bssid, ETH_ALEN);
os_memcpy(wpa_s->bssid, bss->bssid, ETH_ALEN);
+ if (bssid_changed)
+ wpas_notify_bssid_changed(wpa_s);
#if 0 /* FIX */
local->conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10;
@@ -2207,7 +2372,7 @@ static int ieee80211_sta_join_ibss(struct wpa_supplicant *wpa_s,
if (local->conf.phymode == MODE_ATHEROS_TURBO)
rate *= 2;
for (j = 0; j < local->num_curr_rates; j++)
- if (local->curr_rates[j].rate == rate)
+ if (local->curr_rates[j] == rate)
rates |= BIT(j);
}
wpa_s->mlme.supp_rates_bits = rates;
@@ -2276,7 +2441,7 @@ static int ieee80211_sta_create_ibss(struct wpa_supplicant *wpa_s)
pos = bss->supp_rates;
#if 0 /* FIX */
for (i = 0; i < local->num_curr_rates; i++) {
- int rate = local->curr_rates[i].rate;
+ int rate = local->curr_rates[i];
if (local->conf.phymode == MODE_ATHEROS_TURBO)
rate /= 2;
*pos++ = (u8) (rate / 5);
@@ -2392,11 +2557,17 @@ int ieee80211_sta_associate(struct wpa_supplicant *wpa_s,
struct wpa_driver_associate_params *params)
{
struct ieee80211_sta_bss *bss;
+ int bssid_changed;
wpa_s->mlme.bssid_set = 0;
wpa_s->mlme.freq = params->freq;
if (params->bssid) {
+ bssid_changed = os_memcmp(wpa_s->bssid, params->bssid,
+ ETH_ALEN);
os_memcpy(wpa_s->bssid, params->bssid, ETH_ALEN);
+ if (bssid_changed)
+ wpas_notify_bssid_changed(wpa_s);
+
if (!is_zero_ether_addr(params->bssid))
wpa_s->mlme.bssid_set = 1;
bss = ieee80211_bss_get(wpa_s, wpa_s->bssid);
@@ -2463,7 +2634,7 @@ int ieee80211_sta_associate(struct wpa_supplicant *wpa_s,
ieee80211_sta_set_channel(wpa_s, wpa_s->mlme.phymode,
wpa_s->mlme.channel, wpa_s->mlme.freq);
- if (params->mode == 1 && !wpa_s->mlme.bssid_set) {
+ if (params->mode == WPAS_MODE_IBSS && !wpa_s->mlme.bssid_set) {
os_get_time(&wpa_s->mlme.ibss_join_req);
wpa_s->mlme.state = IEEE80211_IBSS_SEARCH;
return ieee80211_sta_find_ibss(wpa_s);
@@ -2503,14 +2674,14 @@ static int ieee80211_active_scan(struct wpa_supplicant *wpa_s)
int c;
for (m = 0; m < wpa_s->mlme.num_modes; m++) {
- struct wpa_hw_modes *mode = &wpa_s->mlme.modes[m];
+ struct hostapd_hw_modes *mode = &wpa_s->mlme.modes[m];
if ((int) mode->mode != (int) wpa_s->mlme.phymode)
continue;
for (c = 0; c < mode->num_channels; c++) {
- struct wpa_channel_data *chan = &mode->channels[c];
- if (chan->flag & WPA_CHAN_W_SCAN &&
+ struct hostapd_channel_data *chan = &mode->channels[c];
+ if (!(chan->flag & HOSTAPD_CHAN_DISABLED) &&
chan->chan == wpa_s->mlme.channel) {
- if (chan->flag & WPA_CHAN_W_ACTIVE_SCAN)
+ if (!(chan->flag & HOSTAPD_CHAN_PASSIVE_SCAN))
return 1;
break;
}
@@ -2524,8 +2695,8 @@ static int ieee80211_active_scan(struct wpa_supplicant *wpa_s)
static void ieee80211_sta_scan_timer(void *eloop_ctx, void *timeout_ctx)
{
struct wpa_supplicant *wpa_s = eloop_ctx;
- struct wpa_hw_modes *mode;
- struct wpa_channel_data *chan;
+ struct hostapd_hw_modes *mode;
+ struct hostapd_channel_data *chan;
int skip = 0;
int timeout = 0;
struct wpa_ssid *ssid = wpa_s->current_ssid;
@@ -2564,12 +2735,23 @@ static void ieee80211_sta_scan_timer(void *eloop_ctx, void *timeout_ctx)
}
skip = !(wpa_s->mlme.hw_modes & (1 << mode->mode));
chan = &mode->channels[wpa_s->mlme.scan_channel_idx];
- if (!(chan->flag & WPA_CHAN_W_SCAN) ||
- (adhoc && !(chan->flag & WPA_CHAN_W_IBSS)) ||
- (wpa_s->mlme.hw_modes & (1 << WPA_MODE_IEEE80211G) &&
- mode->mode == WPA_MODE_IEEE80211B &&
+ if ((chan->flag & HOSTAPD_CHAN_DISABLED) ||
+ (adhoc && (chan->flag & HOSTAPD_CHAN_NO_IBSS)) ||
+ (wpa_s->mlme.hw_modes & (1 << HOSTAPD_MODE_IEEE80211G) &&
+ mode->mode == HOSTAPD_MODE_IEEE80211B &&
wpa_s->mlme.scan_skip_11b))
skip = 1;
+ if (!skip && wpa_s->mlme.scan_freqs) {
+ int i, found = 0;
+ for (i = 0; wpa_s->mlme.scan_freqs[i]; i++) {
+ if (wpa_s->mlme.scan_freqs[i] == chan->freq) {
+ found = 1;
+ break;
+ }
+ }
+ if (!found)
+ skip = 1;
+ }
if (!skip) {
wpa_printf(MSG_MSGDUMP,
@@ -2623,9 +2805,12 @@ static void ieee80211_sta_scan_timer(void *eloop_ctx, void *timeout_ctx)
}
-int ieee80211_sta_req_scan(struct wpa_supplicant *wpa_s, const u8 *ssid,
- size_t ssid_len)
+int ieee80211_sta_req_scan(struct wpa_supplicant *wpa_s,
+ struct wpa_driver_scan_params *params)
{
+ const u8 *ssid = params->ssids[0].ssid;
+ size_t ssid_len = params->ssids[0].ssid_len;
+
if (ssid_len > MAX_SSID_LEN)
return -1;
@@ -2654,6 +2839,21 @@ int ieee80211_sta_req_scan(struct wpa_supplicant *wpa_s, const u8 *ssid,
wpa_printf(MSG_DEBUG, "MLME: starting scan");
+ ieee80211_sta_set_probe_req_ie(wpa_s, params->extra_ies,
+ params->extra_ies_len);
+
+ os_free(wpa_s->mlme.scan_freqs);
+ if (params->freqs) {
+ int i;
+ for (i = 0; params->freqs[i]; i++)
+ ;
+ wpa_s->mlme.scan_freqs = os_malloc((i + 1) * sizeof(int));
+ if (wpa_s->mlme.scan_freqs)
+ os_memcpy(wpa_s->mlme.scan_freqs, params->freqs,
+ (i + 1) * sizeof(int));
+ } else
+ wpa_s->mlme.scan_freqs = NULL;
+
ieee80211_sta_save_oper_chan(wpa_s);
wpa_s->mlme.sta_scanning = 1;
@@ -2830,7 +3030,7 @@ void ieee80211_sta_rx(struct wpa_supplicant *wpa_s, const u8 *buf, size_t len,
}
-void ieee80211_sta_free_hw_features(struct wpa_hw_modes *hw_features,
+void ieee80211_sta_free_hw_features(struct hostapd_hw_modes *hw_features,
size_t num_hw_features)
{
size_t i;
@@ -2861,9 +3061,11 @@ int ieee80211_sta_init(struct wpa_supplicant *wpa_s)
wpa_s->mlme.num_modes = num_modes;
- wpa_s->mlme.hw_modes = 1 << WPA_MODE_IEEE80211A;
- wpa_s->mlme.hw_modes |= 1 << WPA_MODE_IEEE80211B;
- wpa_s->mlme.hw_modes |= 1 << WPA_MODE_IEEE80211G;
+ wpa_s->mlme.hw_modes = 1 << HOSTAPD_MODE_IEEE80211A;
+ wpa_s->mlme.hw_modes |= 1 << HOSTAPD_MODE_IEEE80211B;
+ wpa_s->mlme.hw_modes |= 1 << HOSTAPD_MODE_IEEE80211G;
+
+ wpa_s->mlme.wmm_enabled = 1;
return 0;
}
@@ -2889,6 +3091,9 @@ void ieee80211_sta_deinit(struct wpa_supplicant *wpa_s)
wpa_s->mlme.ft_ies = NULL;
wpa_s->mlme.ft_ies_len = 0;
#endif /* CONFIG_IEEE80211R */
+
+ os_free(wpa_s->mlme.scan_freqs);
+ wpa_s->mlme.scan_freqs = NULL;
}
@@ -2972,8 +3177,8 @@ int ieee80211_sta_send_ft_action(struct wpa_supplicant *wpa_s, u8 action,
#endif /* CONFIG_IEEE80211R */
-int ieee80211_sta_set_probe_req_ie(struct wpa_supplicant *wpa_s, const u8 *ies,
- size_t ies_len)
+static int ieee80211_sta_set_probe_req_ie(struct wpa_supplicant *wpa_s,
+ const u8 *ies, size_t ies_len)
{
os_free(wpa_s->mlme.extra_probe_ie);
wpa_s->mlme.extra_probe_ie = NULL;
diff --git a/contrib/wpa/wpa_supplicant/mlme.h b/contrib/wpa/wpa_supplicant/mlme.h
index cc58a5b..5db3665 100644
--- a/contrib/wpa/wpa_supplicant/mlme.h
+++ b/contrib/wpa/wpa_supplicant/mlme.h
@@ -19,19 +19,25 @@
struct wpa_supplicant;
+struct ieee80211_rx_status {
+ int freq;
+ int channel;
+ int ssi;
+};
+
#ifdef CONFIG_CLIENT_MLME
int ieee80211_sta_init(struct wpa_supplicant *wpa_s);
void ieee80211_sta_deinit(struct wpa_supplicant *wpa_s);
-int ieee80211_sta_req_scan(struct wpa_supplicant *wpa_s, const u8 *ssid,
- size_t ssid_len);
+int ieee80211_sta_req_scan(struct wpa_supplicant *wpa_s,
+ struct wpa_driver_scan_params *params);
int ieee80211_sta_deauthenticate(struct wpa_supplicant *wpa_s, u16 reason);
int ieee80211_sta_disassociate(struct wpa_supplicant *wpa_s, u16 reason);
int ieee80211_sta_associate(struct wpa_supplicant *wpa_s,
struct wpa_driver_associate_params *params);
int ieee80211_sta_get_ssid(struct wpa_supplicant *wpa_s, u8 *ssid,
size_t *len);
-void ieee80211_sta_free_hw_features(struct wpa_hw_modes *hw_features,
+void ieee80211_sta_free_hw_features(struct hostapd_hw_modes *hw_features,
size_t num_hw_features);
void ieee80211_sta_rx(struct wpa_supplicant *wpa_s, const u8 *buf, size_t len,
struct ieee80211_rx_status *rx_status);
@@ -42,8 +48,6 @@ int ieee80211_sta_update_ft_ies(struct wpa_supplicant *wpa_s, const u8 *md,
int ieee80211_sta_send_ft_action(struct wpa_supplicant *wpa_s, u8 action,
const u8 *target_ap,
const u8 *ies, size_t ies_len);
-int ieee80211_sta_set_probe_req_ie(struct wpa_supplicant *wpa_s, const u8 *ies,
- size_t ies_len);
#else /* CONFIG_CLIENT_MLME */
@@ -57,7 +61,7 @@ static inline void ieee80211_sta_deinit(struct wpa_supplicant *wpa_s)
}
static inline int ieee80211_sta_req_scan(struct wpa_supplicant *wpa_s,
- const u8 *ssid, size_t ssid_len)
+ struct wpa_driver_scan_params *params)
{
return -1;
}
@@ -88,7 +92,7 @@ static inline int ieee80211_sta_get_ssid(struct wpa_supplicant *wpa_s,
}
static inline void
-ieee80211_sta_free_hw_features(struct wpa_hw_modes *hw_features,
+ieee80211_sta_free_hw_features(struct hostapd_hw_modes *hw_features,
size_t num_hw_features)
{
}
@@ -120,13 +124,6 @@ ieee80211_sta_send_ft_action(struct wpa_supplicant *wpa_s, u8 action,
return -1;
}
-static inline int
-ieee80211_sta_set_probe_req_ie(struct wpa_supplicant *wpa_s, const u8 *ies,
- size_t ies_len)
-{
- return -1;
-}
-
#endif /* CONFIG_CLIENT_MLME */
#endif /* MLME_H */
diff --git a/contrib/wpa/wpa_supplicant/nmake.mak b/contrib/wpa/wpa_supplicant/nmake.mak
index 5e39c11..80e0ac8 100644
--- a/contrib/wpa/wpa_supplicant/nmake.mak
+++ b/contrib/wpa/wpa_supplicant/nmake.mak
@@ -28,7 +28,6 @@ CFLAGS = $(CFLAGS) /DCONFIG_NDIS_EVENTS_INTEGRATED
CFLAGS = $(CFLAGS) /DCONFIG_ANSI_C_EXTRA
CFLAGS = $(CFLAGS) /DCONFIG_WINPCAP
CFLAGS = $(CFLAGS) /DIEEE8021X_EAPOL
-CFLAGS = $(CFLAGS) /DEAP_TLS_FUNCS
CFLAGS = $(CFLAGS) /DPKCS12_FUNCS
CFLAGS = $(CFLAGS) /DEAP_MD5
CFLAGS = $(CFLAGS) /DEAP_TLS
@@ -48,8 +47,8 @@ CFLAGS = $(CFLAGS) /DPCSC_FUNCS
CFLAGS = $(CFLAGS) /DCONFIG_CTRL_IFACE
CFLAGS = $(CFLAGS) /DCONFIG_CTRL_IFACE_NAMED_PIPE
CFLAGS = $(CFLAGS) /DCONFIG_DRIVER_NDIS
-CFLAGS = $(CFLAGS) /I..\src /I..\src\utils /I..\src\common /I..\src\crypto
-CFLAGS = $(CFLAGS) /I..\src\rsn_supp /I..\src\eapol_supp /I.
+CFLAGS = $(CFLAGS) /I..\src /I..\src\utils
+CFLAGS = $(CFLAGS) /I.
CFLAGS = $(CFLAGS) /DWIN32
CFLAGS = $(CFLAGS) /Fo$(OBJDIR)\\ /c
CFLAGS = $(CFLAGS) /W3
@@ -64,9 +63,16 @@ OBJS = \
$(OBJDIR)\os_win32.obj \
$(OBJDIR)\eloop_win.obj \
$(OBJDIR)\sha1.obj \
+ $(OBJDIR)\sha1-tlsprf.obj \
+ $(OBJDIR)\sha1-pbkdf2.obj \
$(OBJDIR)\md5.obj \
- $(OBJDIR)\rc4.obj \
- $(OBJDIR)\aes_wrap.obj \
+ $(OBJDIR)\aes-cbc.obj \
+ $(OBJDIR)\aes-ctr.obj \
+ $(OBJDIR)\aes-eax.obj \
+ $(OBJDIR)\aes-encblock.obj \
+ $(OBJDIR)\aes-omac1.obj \
+ $(OBJDIR)\aes-unwrap.obj \
+ $(OBJDIR)\aes-wrap.obj \
$(OBJDIR)\common.obj \
$(OBJDIR)\wpa_debug.obj \
$(OBJDIR)\wpabuf.obj \
@@ -111,12 +117,15 @@ OBJS = \
$(OBJDIR)\blacklist.obj \
$(OBJDIR)\scan.obj \
$(OBJDIR)\wpas_glue.obj \
+ $(OBJDIR)\eap_register.obj \
$(OBJDIR)\config.obj \
$(OBJDIR)\l2_packet_winpcap.obj \
$(OBJDIR)\tls_openssl.obj \
$(OBJDIR)\ms_funcs.obj \
$(OBJDIR)\crypto_openssl.obj \
+ $(OBJDIR)\fips_prf_openssl.obj \
$(OBJDIR)\pcsc_funcs.obj \
+ $(OBJDIR)\notify.obj \
$(OBJDIR)\ndis_events.obj
# OBJS = $(OBJS) $(OBJDIR)\eap_fast.obj
@@ -148,9 +157,12 @@ OBJS_c = \
OBJS_p = \
$(OBJDIR)\os_win32.obj \
$(OBJDIR)\common.obj \
+ $(OBJDIR)\wpa_debug.obj \
+ $(OBJDIR)\wpabuf.obj \
$(OBJDIR)\sha1.obj \
$(OBJDIR)\md5.obj \
$(OBJDIR)\crypto_openssl.obj \
+ $(OBJDIR)\sha1-pbkdf2.obj \
$(OBJDIR)\wpa_passphrase.obj
LIBS = wbemuuid.lib libcmt.lib kernel32.lib uuid.lib ole32.lib oleaut32.lib \
diff --git a/contrib/wpa/wpa_supplicant/notify.c b/contrib/wpa/wpa_supplicant/notify.c
new file mode 100644
index 0000000..ac65b4f
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/notify.c
@@ -0,0 +1,339 @@
+/*
+ * wpa_supplicant - Event notifications
+ * Copyright (c) 2009-2010, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "utils/includes.h"
+
+#include "utils/common.h"
+#include "common/wpa_ctrl.h"
+#include "config.h"
+#include "wpa_supplicant_i.h"
+#include "wps_supplicant.h"
+#include "dbus/dbus_common.h"
+#include "dbus/dbus_old.h"
+#include "dbus/dbus_new.h"
+#include "driver_i.h"
+#include "scan.h"
+#include "notify.h"
+
+int wpas_notify_supplicant_initialized(struct wpa_global *global)
+{
+#ifdef CONFIG_DBUS
+ if (global->params.dbus_ctrl_interface) {
+ global->dbus = wpas_dbus_init(global);
+ if (global->dbus == NULL)
+ return -1;
+ }
+#endif /* CONFIG_DBUS */
+
+ return 0;
+}
+
+
+void wpas_notify_supplicant_deinitialized(struct wpa_global *global)
+{
+#ifdef CONFIG_DBUS
+ if (global->dbus)
+ wpas_dbus_deinit(global->dbus);
+#endif /* CONFIG_DBUS */
+}
+
+
+int wpas_notify_iface_added(struct wpa_supplicant *wpa_s)
+{
+ if (wpas_dbus_register_iface(wpa_s))
+ return -1;
+
+ if (wpas_dbus_register_interface(wpa_s))
+ return -1;
+
+ return 0;
+}
+
+
+void wpas_notify_iface_removed(struct wpa_supplicant *wpa_s)
+{
+ /* unregister interface in old DBus ctrl iface */
+ wpas_dbus_unregister_iface(wpa_s);
+
+ /* unregister interface in new DBus ctrl iface */
+ wpas_dbus_unregister_interface(wpa_s);
+}
+
+
+void wpas_notify_state_changed(struct wpa_supplicant *wpa_s,
+ enum wpa_states new_state,
+ enum wpa_states old_state)
+{
+ /* notify the old DBus API */
+ wpa_supplicant_dbus_notify_state_change(wpa_s, new_state,
+ old_state);
+
+ /* notify the new DBus API */
+ wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_STATE);
+}
+
+
+void wpas_notify_network_changed(struct wpa_supplicant *wpa_s)
+{
+ wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_CURRENT_NETWORK);
+}
+
+
+void wpas_notify_ap_scan_changed(struct wpa_supplicant *wpa_s)
+{
+ wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_AP_SCAN);
+}
+
+
+void wpas_notify_bssid_changed(struct wpa_supplicant *wpa_s)
+{
+ wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_CURRENT_BSS);
+}
+
+
+void wpas_notify_network_enabled_changed(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid)
+{
+ wpas_dbus_signal_network_enabled_changed(wpa_s, ssid);
+}
+
+
+void wpas_notify_network_selected(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid)
+{
+ wpas_dbus_signal_network_selected(wpa_s, ssid->id);
+}
+
+
+void wpas_notify_scanning(struct wpa_supplicant *wpa_s)
+{
+ /* notify the old DBus API */
+ wpa_supplicant_dbus_notify_scanning(wpa_s);
+
+ /* notify the new DBus API */
+ wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_SCANNING);
+}
+
+
+void wpas_notify_scan_done(struct wpa_supplicant *wpa_s, int success)
+{
+ wpas_dbus_signal_scan_done(wpa_s, success);
+}
+
+
+void wpas_notify_scan_results(struct wpa_supplicant *wpa_s)
+{
+ /* notify the old DBus API */
+ wpa_supplicant_dbus_notify_scan_results(wpa_s);
+
+ wpas_wps_notify_scan_results(wpa_s);
+}
+
+
+void wpas_notify_wps_credential(struct wpa_supplicant *wpa_s,
+ const struct wps_credential *cred)
+{
+#ifdef CONFIG_WPS
+ /* notify the old DBus API */
+ wpa_supplicant_dbus_notify_wps_cred(wpa_s, cred);
+ /* notify the new DBus API */
+ wpas_dbus_signal_wps_cred(wpa_s, cred);
+#endif /* CONFIG_WPS */
+}
+
+
+void wpas_notify_wps_event_m2d(struct wpa_supplicant *wpa_s,
+ struct wps_event_m2d *m2d)
+{
+#ifdef CONFIG_WPS
+ wpas_dbus_signal_wps_event_m2d(wpa_s, m2d);
+#endif /* CONFIG_WPS */
+}
+
+
+void wpas_notify_wps_event_fail(struct wpa_supplicant *wpa_s,
+ struct wps_event_fail *fail)
+{
+#ifdef CONFIG_WPS
+ wpas_dbus_signal_wps_event_fail(wpa_s, fail);
+#endif /* CONFIG_WPS */
+}
+
+
+void wpas_notify_wps_event_success(struct wpa_supplicant *wpa_s)
+{
+#ifdef CONFIG_WPS
+ wpas_dbus_signal_wps_event_success(wpa_s);
+#endif /* CONFIG_WPS */
+}
+
+
+void wpas_notify_network_added(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid)
+{
+ wpas_dbus_register_network(wpa_s, ssid);
+}
+
+
+void wpas_notify_network_removed(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid)
+{
+ wpas_dbus_unregister_network(wpa_s, ssid->id);
+}
+
+
+void wpas_notify_bss_added(struct wpa_supplicant *wpa_s,
+ u8 bssid[], unsigned int id)
+{
+ wpas_dbus_register_bss(wpa_s, bssid, id);
+ wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_BSS_ADDED "%u " MACSTR,
+ id, MAC2STR(bssid));
+}
+
+
+void wpas_notify_bss_removed(struct wpa_supplicant *wpa_s,
+ u8 bssid[], unsigned int id)
+{
+ wpas_dbus_unregister_bss(wpa_s, bssid, id);
+ wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_BSS_REMOVED "%u " MACSTR,
+ id, MAC2STR(bssid));
+}
+
+
+void wpas_notify_bss_freq_changed(struct wpa_supplicant *wpa_s,
+ unsigned int id)
+{
+ wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_FREQ, id);
+}
+
+
+void wpas_notify_bss_signal_changed(struct wpa_supplicant *wpa_s,
+ unsigned int id)
+{
+ wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_SIGNAL,
+ id);
+}
+
+
+void wpas_notify_bss_privacy_changed(struct wpa_supplicant *wpa_s,
+ unsigned int id)
+{
+ wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_PRIVACY,
+ id);
+}
+
+
+void wpas_notify_bss_mode_changed(struct wpa_supplicant *wpa_s,
+ unsigned int id)
+{
+ wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_MODE, id);
+}
+
+
+void wpas_notify_bss_wpaie_changed(struct wpa_supplicant *wpa_s,
+ unsigned int id)
+{
+ wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_WPA, id);
+}
+
+
+void wpas_notify_bss_rsnie_changed(struct wpa_supplicant *wpa_s,
+ unsigned int id)
+{
+ wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_RSN, id);
+}
+
+
+void wpas_notify_bss_wps_changed(struct wpa_supplicant *wpa_s,
+ unsigned int id)
+{
+}
+
+
+void wpas_notify_bss_ies_changed(struct wpa_supplicant *wpa_s,
+ unsigned int id)
+{
+ wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_IES, id);
+}
+
+
+void wpas_notify_bss_rates_changed(struct wpa_supplicant *wpa_s,
+ unsigned int id)
+{
+ wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_RATES, id);
+}
+
+
+void wpas_notify_blob_added(struct wpa_supplicant *wpa_s, const char *name)
+{
+ wpas_dbus_signal_blob_added(wpa_s, name);
+}
+
+
+void wpas_notify_blob_removed(struct wpa_supplicant *wpa_s, const char *name)
+{
+ wpas_dbus_signal_blob_removed(wpa_s, name);
+}
+
+
+void wpas_notify_debug_level_changed(struct wpa_global *global)
+{
+ wpas_dbus_signal_debug_level_changed(global);
+}
+
+
+void wpas_notify_debug_timestamp_changed(struct wpa_global *global)
+{
+ wpas_dbus_signal_debug_timestamp_changed(global);
+}
+
+
+void wpas_notify_debug_show_keys_changed(struct wpa_global *global)
+{
+ wpas_dbus_signal_debug_show_keys_changed(global);
+}
+
+
+void wpas_notify_suspend(struct wpa_global *global)
+{
+ struct wpa_supplicant *wpa_s;
+
+ os_get_time(&global->suspend_time);
+ wpa_printf(MSG_DEBUG, "System suspend notification");
+ for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
+ wpa_drv_suspend(wpa_s);
+}
+
+
+void wpas_notify_resume(struct wpa_global *global)
+{
+ struct os_time now;
+ int slept;
+ struct wpa_supplicant *wpa_s;
+
+ if (global->suspend_time.sec == 0)
+ slept = -1;
+ else {
+ os_get_time(&now);
+ slept = now.sec - global->suspend_time.sec;
+ }
+ wpa_printf(MSG_DEBUG, "System resume notification (slept %d seconds)",
+ slept);
+
+ for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
+ wpa_drv_resume(wpa_s);
+ if (wpa_s->wpa_state == WPA_DISCONNECTED)
+ wpa_supplicant_req_scan(wpa_s, 0, 100000);
+ }
+}
diff --git a/contrib/wpa/wpa_supplicant/notify.h b/contrib/wpa/wpa_supplicant/notify.h
new file mode 100644
index 0000000..2e70bdb
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/notify.h
@@ -0,0 +1,81 @@
+/*
+ * wpa_supplicant - Event notifications
+ * Copyright (c) 2009-2010, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef NOTIFY_H
+#define NOTIFY_H
+
+struct wps_credential;
+struct wps_event_m2d;
+struct wps_event_fail;
+
+int wpas_notify_supplicant_initialized(struct wpa_global *global);
+void wpas_notify_supplicant_deinitialized(struct wpa_global *global);
+int wpas_notify_iface_added(struct wpa_supplicant *wpa_s);
+void wpas_notify_iface_removed(struct wpa_supplicant *wpa_s);
+void wpas_notify_state_changed(struct wpa_supplicant *wpa_s,
+ enum wpa_states new_state,
+ enum wpa_states old_state);
+void wpas_notify_network_changed(struct wpa_supplicant *wpa_s);
+void wpas_notify_ap_scan_changed(struct wpa_supplicant *wpa_s);
+void wpas_notify_bssid_changed(struct wpa_supplicant *wpa_s);
+void wpas_notify_network_enabled_changed(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid);
+void wpas_notify_network_selected(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid);
+void wpas_notify_scanning(struct wpa_supplicant *wpa_s);
+void wpas_notify_scan_done(struct wpa_supplicant *wpa_s, int success);
+void wpas_notify_scan_results(struct wpa_supplicant *wpa_s);
+void wpas_notify_wps_credential(struct wpa_supplicant *wpa_s,
+ const struct wps_credential *cred);
+void wpas_notify_wps_event_m2d(struct wpa_supplicant *wpa_s,
+ struct wps_event_m2d *m2d);
+void wpas_notify_wps_event_fail(struct wpa_supplicant *wpa_s,
+ struct wps_event_fail *fail);
+void wpas_notify_wps_event_success(struct wpa_supplicant *wpa_s);
+void wpas_notify_network_added(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid);
+void wpas_notify_network_removed(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid);
+void wpas_notify_bss_added(struct wpa_supplicant *wpa_s, u8 bssid[],
+ unsigned int id);
+void wpas_notify_bss_removed(struct wpa_supplicant *wpa_s, u8 bssid[],
+ unsigned int id);
+void wpas_notify_bss_freq_changed(struct wpa_supplicant *wpa_s,
+ unsigned int id);
+void wpas_notify_bss_signal_changed(struct wpa_supplicant *wpa_s,
+ unsigned int id);
+void wpas_notify_bss_privacy_changed(struct wpa_supplicant *wpa_s,
+ unsigned int id);
+void wpas_notify_bss_mode_changed(struct wpa_supplicant *wpa_s,
+ unsigned int id);
+void wpas_notify_bss_wpaie_changed(struct wpa_supplicant *wpa_s,
+ unsigned int id);
+void wpas_notify_bss_rsnie_changed(struct wpa_supplicant *wpa_s,
+ unsigned int id);
+void wpas_notify_bss_wps_changed(struct wpa_supplicant *wpa_s,
+ unsigned int id);
+void wpas_notify_bss_ies_changed(struct wpa_supplicant *wpa_s,
+ unsigned int id);
+void wpas_notify_bss_rates_changed(struct wpa_supplicant *wpa_s,
+ unsigned int id);
+void wpas_notify_blob_added(struct wpa_supplicant *wpa_s, const char *name);
+void wpas_notify_blob_removed(struct wpa_supplicant *wpa_s, const char *name);
+
+void wpas_notify_debug_level_changed(struct wpa_global *global);
+void wpas_notify_debug_timestamp_changed(struct wpa_global *global);
+void wpas_notify_debug_show_keys_changed(struct wpa_global *global);
+void wpas_notify_suspend(struct wpa_global *global);
+void wpas_notify_resume(struct wpa_global *global);
+
+#endif /* NOTIFY_H */
diff --git a/contrib/wpa/wpa_supplicant/preauth_test.c b/contrib/wpa/wpa_supplicant/preauth_test.c
index 86307a8..d38a6bb 100644
--- a/contrib/wpa/wpa_supplicant/preauth_test.c
+++ b/contrib/wpa/wpa_supplicant/preauth_test.c
@@ -22,20 +22,21 @@
#include "config.h"
#include "eapol_supp/eapol_supp_sm.h"
#include "eloop.h"
-#include "wpa.h"
+#include "rsn_supp/wpa.h"
#include "eap_peer/eap.h"
#include "wpa_supplicant_i.h"
#include "l2_packet/l2_packet.h"
#include "ctrl_iface.h"
#include "pcsc_funcs.h"
-#include "preauth.h"
-#include "pmksa_cache.h"
+#include "rsn_supp/preauth.h"
+#include "rsn_supp/pmksa_cache.h"
+#include "drivers/driver.h"
extern int wpa_debug_level;
extern int wpa_debug_show_keys;
-struct wpa_driver_ops *wpa_supplicant_drivers[] = { NULL };
+struct wpa_driver_ops *wpa_drivers[] = { NULL };
struct preauth_test_data {
@@ -90,14 +91,14 @@ static u8 * _wpa_alloc_eapol(void *wpa_s, u8 type,
}
-static void _wpa_supplicant_set_state(void *ctx, wpa_states state)
+static void _wpa_supplicant_set_state(void *ctx, enum wpa_states state)
{
struct wpa_supplicant *wpa_s = ctx;
wpa_s->wpa_state = state;
}
-static wpa_states _wpa_supplicant_get_state(void *ctx)
+static enum wpa_states _wpa_supplicant_get_state(void *ctx)
{
struct wpa_supplicant *wpa_s = ctx;
return wpa_s->wpa_state;
@@ -138,7 +139,7 @@ static int wpa_supplicant_get_bssid(void *wpa_s, u8 *bssid)
}
-static int wpa_supplicant_set_key(void *wpa_s, wpa_alg alg,
+static int wpa_supplicant_set_key(void *wpa_s, enum wpa_alg alg,
const u8 *addr, int key_idx, int set_tx,
const u8 *seq, size_t seq_len,
const u8 *key, size_t key_len)
@@ -239,6 +240,7 @@ static void wpa_init_conf(struct wpa_supplicant *wpa_s, const char *ifname)
assert(ctx != NULL);
ctx->ctx = wpa_s;
+ ctx->msg_ctx = wpa_s;
ctx->set_state = _wpa_supplicant_set_state;
ctx->get_state = _wpa_supplicant_get_state;
ctx->deauthenticate = _wpa_supplicant_deauthenticate;
@@ -275,10 +277,9 @@ static void wpa_init_conf(struct wpa_supplicant *wpa_s, const char *ifname)
}
-static void eapol_test_terminate(int sig, void *eloop_ctx,
- void *signal_ctx)
+static void eapol_test_terminate(int sig, void *signal_ctx)
{
- struct wpa_supplicant *wpa_s = eloop_ctx;
+ struct wpa_supplicant *wpa_s = signal_ctx;
wpa_msg(wpa_s, MSG_INFO, "Signal %d received - terminating", sig);
eloop_terminate();
}
@@ -310,12 +311,12 @@ int main(int argc, char *argv[])
return -1;
}
- if (eap_peer_register_methods()) {
+ if (eap_register_methods()) {
wpa_printf(MSG_ERROR, "Failed to register EAP methods");
return -1;
}
- if (eloop_init(&wpa_s)) {
+ if (eloop_init()) {
wpa_printf(MSG_ERROR, "Failed to initialize event loop");
return -1;
}
@@ -352,8 +353,8 @@ int main(int argc, char *argv[])
eloop_register_timeout(30, 0, eapol_test_timeout, &preauth_test, NULL);
eloop_register_timeout(0, 100000, eapol_test_poll, &wpa_s, NULL);
- eloop_register_signal_terminate(eapol_test_terminate, NULL);
- eloop_register_signal_reconfig(eapol_test_terminate, NULL);
+ eloop_register_signal_terminate(eapol_test_terminate, &wpa_s);
+ eloop_register_signal_reconfig(eapol_test_terminate, &wpa_s);
eloop_run();
if (preauth_test.auth_timed_out)
diff --git a/contrib/wpa/wpa_supplicant/scan.c b/contrib/wpa/wpa_supplicant/scan.c
index 8cb7a42..edc8c83 100644
--- a/contrib/wpa/wpa_supplicant/scan.c
+++ b/contrib/wpa/wpa_supplicant/scan.c
@@ -1,6 +1,6 @@
/*
* WPA Supplicant - Scanning
- * Copyright (c) 2003-2008, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2003-2010, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -12,15 +12,19 @@
* See README and COPYING for more details.
*/
-#include "includes.h"
+#include "utils/includes.h"
-#include "common.h"
-#include "eloop.h"
+#include "utils/common.h"
+#include "utils/eloop.h"
+#include "common/ieee802_11_defs.h"
#include "config.h"
#include "wpa_supplicant_i.h"
+#include "driver_i.h"
#include "mlme.h"
#include "wps_supplicant.h"
-#include "ctrl_iface_dbus.h"
+#include "notify.h"
+#include "bss.h"
+#include "scan.h"
static void wpa_supplicant_gen_assoc_event(struct wpa_supplicant *wpa_s)
@@ -32,8 +36,11 @@ static void wpa_supplicant_gen_assoc_event(struct wpa_supplicant *wpa_s)
if (ssid == NULL)
return;
- if (wpa_s->current_ssid == NULL)
+ if (wpa_s->current_ssid == NULL) {
wpa_s->current_ssid = ssid;
+ if (wpa_s->current_ssid != NULL)
+ wpas_notify_network_changed(wpa_s);
+ }
wpa_supplicant_initiate_eapol(wpa_s);
wpa_printf(MSG_DEBUG, "Already associated with a configured network - "
"generating associated event");
@@ -79,18 +86,170 @@ int wpa_supplicant_enabled_networks(struct wpa_config *conf)
}
+static void wpa_supplicant_assoc_try(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid)
+{
+ while (ssid) {
+ if (!ssid->disabled)
+ break;
+ ssid = ssid->next;
+ }
+
+ /* ap_scan=2 mode - try to associate with each SSID. */
+ if (ssid == NULL) {
+ wpa_printf(MSG_DEBUG, "wpa_supplicant_scan: Reached "
+ "end of scan list - go back to beginning");
+ wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN;
+ wpa_supplicant_req_scan(wpa_s, 0, 0);
+ return;
+ }
+ if (ssid->next) {
+ /* Continue from the next SSID on the next attempt. */
+ wpa_s->prev_scan_ssid = ssid;
+ } else {
+ /* Start from the beginning of the SSID list. */
+ wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN;
+ }
+ wpa_supplicant_associate(wpa_s, NULL, ssid);
+}
+
+
+static int int_array_len(const int *a)
+{
+ int i;
+ for (i = 0; a && a[i]; i++)
+ ;
+ return i;
+}
+
+
+static void int_array_concat(int **res, const int *a)
+{
+ int reslen, alen, i;
+ int *n;
+
+ reslen = int_array_len(*res);
+ alen = int_array_len(a);
+
+ n = os_realloc(*res, (reslen + alen + 1) * sizeof(int));
+ if (n == NULL) {
+ os_free(*res);
+ *res = NULL;
+ return;
+ }
+ for (i = 0; i <= alen; i++)
+ n[reslen + i] = a[i];
+ *res = n;
+}
+
+
+static int freq_cmp(const void *a, const void *b)
+{
+ int _a = *(int *) a;
+ int _b = *(int *) b;
+
+ if (_a == 0)
+ return 1;
+ if (_b == 0)
+ return -1;
+ return _a - _b;
+}
+
+
+static void int_array_sort_unique(int *a)
+{
+ int alen;
+ int i, j;
+
+ if (a == NULL)
+ return;
+
+ alen = int_array_len(a);
+ qsort(a, alen, sizeof(int), freq_cmp);
+
+ i = 0;
+ j = 1;
+ while (a[i] && a[j]) {
+ if (a[i] == a[j]) {
+ j++;
+ continue;
+ }
+ a[++i] = a[j++];
+ }
+ if (a[i])
+ i++;
+ a[i] = 0;
+}
+
+
+int wpa_supplicant_trigger_scan(struct wpa_supplicant *wpa_s,
+ struct wpa_driver_scan_params *params)
+{
+ int ret;
+
+ wpa_supplicant_notify_scanning(wpa_s, 1);
+
+ if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
+ ret = ieee80211_sta_req_scan(wpa_s, params);
+ else
+ ret = wpa_drv_scan(wpa_s, params);
+
+ if (ret) {
+ wpa_supplicant_notify_scanning(wpa_s, 0);
+ wpas_notify_scan_done(wpa_s, 0);
+ } else
+ wpa_s->scan_runs++;
+
+ return ret;
+}
+
+
+static struct wpa_driver_scan_filter *
+wpa_supplicant_build_filter_ssids(struct wpa_config *conf, size_t *num_ssids)
+{
+ struct wpa_driver_scan_filter *ssids;
+ struct wpa_ssid *ssid;
+ size_t count;
+
+ *num_ssids = 0;
+ if (!conf->filter_ssids)
+ return NULL;
+
+ for (count = 0, ssid = conf->ssid; ssid; ssid = ssid->next) {
+ if (ssid->ssid && ssid->ssid_len)
+ count++;
+ }
+ if (count == 0)
+ return NULL;
+ ssids = os_zalloc(count * sizeof(struct wpa_driver_scan_filter));
+ if (ssids == NULL)
+ return NULL;
+
+ for (ssid = conf->ssid; ssid; ssid = ssid->next) {
+ if (!ssid->ssid || !ssid->ssid_len)
+ continue;
+ os_memcpy(ssids[*num_ssids].ssid, ssid->ssid, ssid->ssid_len);
+ ssids[*num_ssids].ssid_len = ssid->ssid_len;
+ (*num_ssids)++;
+ }
+
+ return ssids;
+}
+
+
static void wpa_supplicant_scan(void *eloop_ctx, void *timeout_ctx)
{
struct wpa_supplicant *wpa_s = eloop_ctx;
struct wpa_ssid *ssid;
int scan_req = 0, ret;
struct wpabuf *wps_ie = NULL;
- const u8 *extra_ie = NULL;
- size_t extra_ie_len = 0;
- int wps = 0;
#ifdef CONFIG_WPS
+ int wps = 0;
enum wps_request_type req_type = WPS_REQ_ENROLLEE_INFO;
#endif /* CONFIG_WPS */
+ struct wpa_driver_scan_params params;
+ size_t max_ssids;
+ enum wpa_states prev_state;
if (wpa_s->disconnected && !wpa_s->scan_req) {
wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
@@ -103,14 +262,13 @@ static void wpa_supplicant_scan(void *eloop_ctx, void *timeout_ctx)
wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
return;
}
- scan_req = wpa_s->scan_req;
- wpa_s->scan_req = 0;
if (wpa_s->conf->ap_scan != 0 &&
- wpa_s->driver && IS_WIRED(wpa_s->driver)) {
+ (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED)) {
wpa_printf(MSG_DEBUG, "Using wired authentication - "
"overriding ap_scan configuration");
wpa_s->conf->ap_scan = 0;
+ wpas_notify_ap_scan_changed(wpa_s);
}
if (wpa_s->conf->ap_scan == 0) {
@@ -118,12 +276,32 @@ static void wpa_supplicant_scan(void *eloop_ctx, void *timeout_ctx)
return;
}
+ if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) ||
+ wpa_s->conf->ap_scan == 2)
+ max_ssids = 1;
+ else {
+ max_ssids = wpa_s->max_scan_ssids;
+ if (max_ssids > WPAS_MAX_SCAN_SSIDS)
+ max_ssids = WPAS_MAX_SCAN_SSIDS;
+ }
+
+#ifdef CONFIG_WPS
+ wps = wpas_wps_in_use(wpa_s->conf, &req_type);
+#endif /* CONFIG_WPS */
+
+ scan_req = wpa_s->scan_req;
+ wpa_s->scan_req = 0;
+
+ os_memset(&params, 0, sizeof(params));
+
+ prev_state = wpa_s->wpa_state;
if (wpa_s->wpa_state == WPA_DISCONNECTED ||
wpa_s->wpa_state == WPA_INACTIVE)
wpa_supplicant_set_state(wpa_s, WPA_SCANNING);
+ /* Find the starting point from which to continue scanning */
ssid = wpa_s->conf->ssid;
- if (wpa_s->prev_scan_ssid != BROADCAST_SSID_SCAN) {
+ if (wpa_s->prev_scan_ssid != WILDCARD_SSID_SCAN) {
while (ssid) {
if (ssid == wpa_s->prev_scan_ssid) {
ssid = ssid->next;
@@ -132,91 +310,111 @@ static void wpa_supplicant_scan(void *eloop_ctx, void *timeout_ctx)
ssid = ssid->next;
}
}
- while (ssid) {
- if (!ssid->disabled &&
- (ssid->scan_ssid || wpa_s->conf->ap_scan == 2))
- break;
- ssid = ssid->next;
- }
- if (scan_req != 2 && wpa_s->conf->ap_scan == 2) {
+ if (scan_req != 2 && (wpa_s->conf->ap_scan == 2 ||
+ wpa_s->connect_without_scan)) {
+ wpa_s->connect_without_scan = 0;
+ wpa_supplicant_assoc_try(wpa_s, ssid);
+ return;
+ } else if (wpa_s->conf->ap_scan == 2) {
/*
- * ap_scan=2 mode - try to associate with each SSID instead of
- * scanning for each scan_ssid=1 network.
+ * User-initiated scan request in ap_scan == 2; scan with
+ * wildcard SSID.
*/
- if (ssid == NULL) {
- wpa_printf(MSG_DEBUG, "wpa_supplicant_scan: Reached "
- "end of scan list - go back to beginning");
- wpa_s->prev_scan_ssid = BROADCAST_SSID_SCAN;
- wpa_supplicant_req_scan(wpa_s, 0, 0);
- return;
+ ssid = NULL;
+ } else {
+ struct wpa_ssid *start = ssid, *tssid;
+ int freqs_set = 0;
+ if (ssid == NULL && max_ssids > 1)
+ ssid = wpa_s->conf->ssid;
+ while (ssid) {
+ if (!ssid->disabled && ssid->scan_ssid) {
+ wpa_hexdump_ascii(MSG_DEBUG, "Scan SSID",
+ ssid->ssid, ssid->ssid_len);
+ params.ssids[params.num_ssids].ssid =
+ ssid->ssid;
+ params.ssids[params.num_ssids].ssid_len =
+ ssid->ssid_len;
+ params.num_ssids++;
+ if (params.num_ssids + 1 >= max_ssids)
+ break;
+ }
+ ssid = ssid->next;
+ if (ssid == start)
+ break;
+ if (ssid == NULL && max_ssids > 1 &&
+ start != wpa_s->conf->ssid)
+ ssid = wpa_s->conf->ssid;
}
- if (ssid->next) {
- /* Continue from the next SSID on the next attempt. */
- wpa_s->prev_scan_ssid = ssid;
- } else {
- /* Start from the beginning of the SSID list. */
- wpa_s->prev_scan_ssid = BROADCAST_SSID_SCAN;
+
+ for (tssid = wpa_s->conf->ssid; tssid; tssid = tssid->next) {
+ if (tssid->disabled)
+ continue;
+ if ((params.freqs || !freqs_set) && tssid->scan_freq) {
+ int_array_concat(&params.freqs,
+ tssid->scan_freq);
+ } else {
+ os_free(params.freqs);
+ params.freqs = NULL;
+ }
+ freqs_set = 1;
}
- wpa_supplicant_associate(wpa_s, NULL, ssid);
- return;
+ int_array_sort_unique(params.freqs);
}
- wpa_printf(MSG_DEBUG, "Starting AP scan (%s SSID)",
- ssid ? "specific": "broadcast");
if (ssid) {
- wpa_hexdump_ascii(MSG_DEBUG, "Scan SSID",
- ssid->ssid, ssid->ssid_len);
wpa_s->prev_scan_ssid = ssid;
- } else
- wpa_s->prev_scan_ssid = BROADCAST_SSID_SCAN;
+ if (max_ssids > 1) {
+ wpa_printf(MSG_DEBUG, "Include wildcard SSID in the "
+ "scan request");
+ params.num_ssids++;
+ }
+ wpa_printf(MSG_DEBUG, "Starting AP scan for specific SSID(s)");
+ } else {
+ wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN;
+ params.num_ssids++;
+ wpa_printf(MSG_DEBUG, "Starting AP scan for wildcard SSID");
+ }
#ifdef CONFIG_WPS
- wps = wpas_wps_in_use(wpa_s->conf, &req_type);
-#endif /* CONFIG_WPS */
-
- if (wpa_s->scan_res_tried == 0 && wpa_s->conf->ap_scan == 1 &&
- !wpa_s->use_client_mlme && wps != 2) {
- wpa_s->scan_res_tried++;
- wpa_s->scan_req = scan_req;
- wpa_printf(MSG_DEBUG, "Trying to get current scan results "
- "first without requesting a new scan to speed up "
- "initial association");
- wpa_supplicant_event(wpa_s, EVENT_SCAN_RESULTS, NULL);
- return;
+ if (params.freqs == NULL && wpa_s->after_wps && wpa_s->wps_freq) {
+ /*
+ * Optimize post-provisioning scan based on channel used
+ * during provisioning.
+ */
+ wpa_printf(MSG_DEBUG, "WPS: Scan only frequency %u MHz that "
+ "was used during provisioning", wpa_s->wps_freq);
+ params.freqs = os_zalloc(2 * sizeof(int));
+ if (params.freqs)
+ params.freqs[0] = wpa_s->wps_freq;
+ wpa_s->after_wps--;
}
-#ifdef CONFIG_WPS
if (wps) {
wps_ie = wps_build_probe_req_ie(wps == 2, &wpa_s->wps->dev,
wpa_s->wps->uuid, req_type);
if (wps_ie) {
- extra_ie = wpabuf_head(wps_ie);
- extra_ie_len = wpabuf_len(wps_ie);
+ params.extra_ies = wpabuf_head(wps_ie);
+ params.extra_ies_len = wpabuf_len(wps_ie);
}
}
#endif /* CONFIG_WPS */
- wpa_supplicant_notify_scanning(wpa_s, 1);
+ params.filter_ssids = wpa_supplicant_build_filter_ssids(
+ wpa_s->conf, &params.num_filter_ssids);
- if (wpa_s->use_client_mlme) {
- ieee80211_sta_set_probe_req_ie(wpa_s, extra_ie, extra_ie_len);
- ret = ieee80211_sta_req_scan(wpa_s, ssid ? ssid->ssid : NULL,
- ssid ? ssid->ssid_len : 0);
- } else {
- wpa_drv_set_probe_req_ie(wpa_s, extra_ie, extra_ie_len);
- ret = wpa_drv_scan(wpa_s, ssid ? ssid->ssid : NULL,
- ssid ? ssid->ssid_len : 0);
- }
+ ret = wpa_supplicant_trigger_scan(wpa_s, &params);
wpabuf_free(wps_ie);
+ os_free(params.freqs);
+ os_free(params.filter_ssids);
if (ret) {
wpa_printf(MSG_WARNING, "Failed to initiate AP scan.");
- wpa_supplicant_notify_scanning(wpa_s, 0);
- wpa_supplicant_req_scan(wpa_s, 10, 0);
- } else
- wpa_s->scan_runs++;
+ if (prev_state != wpa_s->wpa_state)
+ wpa_supplicant_set_state(wpa_s, prev_state);
+ wpa_supplicant_req_scan(wpa_s, 1, 0);
+ }
}
@@ -279,7 +477,213 @@ void wpa_supplicant_notify_scanning(struct wpa_supplicant *wpa_s,
{
if (wpa_s->scanning != scanning) {
wpa_s->scanning = scanning;
- wpa_supplicant_dbus_notify_scanning(wpa_s);
+ wpas_notify_scanning(wpa_s);
+ }
+}
+
+
+static int wpa_scan_get_max_rate(const struct wpa_scan_res *res)
+{
+ int rate = 0;
+ const u8 *ie;
+ int i;
+
+ ie = wpa_scan_get_ie(res, WLAN_EID_SUPP_RATES);
+ for (i = 0; ie && i < ie[1]; i++) {
+ if ((ie[i + 2] & 0x7f) > rate)
+ rate = ie[i + 2] & 0x7f;
+ }
+
+ ie = wpa_scan_get_ie(res, WLAN_EID_EXT_SUPP_RATES);
+ for (i = 0; ie && i < ie[1]; i++) {
+ if ((ie[i + 2] & 0x7f) > rate)
+ rate = ie[i + 2] & 0x7f;
+ }
+
+ return rate;
+}
+
+
+const u8 * wpa_scan_get_ie(const struct wpa_scan_res *res, u8 ie)
+{
+ const u8 *end, *pos;
+
+ pos = (const u8 *) (res + 1);
+ end = pos + res->ie_len;
+
+ while (pos + 1 < end) {
+ if (pos + 2 + pos[1] > end)
+ break;
+ if (pos[0] == ie)
+ return pos;
+ pos += 2 + pos[1];
+ }
+
+ return NULL;
+}
+
+
+const u8 * wpa_scan_get_vendor_ie(const struct wpa_scan_res *res,
+ u32 vendor_type)
+{
+ const u8 *end, *pos;
+
+ pos = (const u8 *) (res + 1);
+ end = pos + res->ie_len;
+
+ while (pos + 1 < end) {
+ if (pos + 2 + pos[1] > end)
+ break;
+ if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
+ vendor_type == WPA_GET_BE32(&pos[2]))
+ return pos;
+ pos += 2 + pos[1];
+ }
+
+ return NULL;
+}
+
+
+struct wpabuf * wpa_scan_get_vendor_ie_multi(const struct wpa_scan_res *res,
+ u32 vendor_type)
+{
+ struct wpabuf *buf;
+ const u8 *end, *pos;
+
+ buf = wpabuf_alloc(res->ie_len);
+ if (buf == NULL)
+ return NULL;
+
+ pos = (const u8 *) (res + 1);
+ end = pos + res->ie_len;
+
+ while (pos + 1 < end) {
+ if (pos + 2 + pos[1] > end)
+ break;
+ if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
+ vendor_type == WPA_GET_BE32(&pos[2]))
+ wpabuf_put_data(buf, pos + 2 + 4, pos[1] - 4);
+ pos += 2 + pos[1];
+ }
+
+ if (wpabuf_len(buf) == 0) {
+ wpabuf_free(buf);
+ buf = NULL;
+ }
+
+ return buf;
+}
+
+
+/* Compare function for sorting scan results. Return >0 if @b is considered
+ * better. */
+static int wpa_scan_result_compar(const void *a, const void *b)
+{
+ struct wpa_scan_res **_wa = (void *) a;
+ struct wpa_scan_res **_wb = (void *) b;
+ struct wpa_scan_res *wa = *_wa;
+ struct wpa_scan_res *wb = *_wb;
+ int wpa_a, wpa_b, maxrate_a, maxrate_b;
+
+ /* WPA/WPA2 support preferred */
+ wpa_a = wpa_scan_get_vendor_ie(wa, WPA_IE_VENDOR_TYPE) != NULL ||
+ wpa_scan_get_ie(wa, WLAN_EID_RSN) != NULL;
+ wpa_b = wpa_scan_get_vendor_ie(wb, WPA_IE_VENDOR_TYPE) != NULL ||
+ wpa_scan_get_ie(wb, WLAN_EID_RSN) != NULL;
+
+ if (wpa_b && !wpa_a)
+ return 1;
+ if (!wpa_b && wpa_a)
+ return -1;
+
+ /* privacy support preferred */
+ if ((wa->caps & IEEE80211_CAP_PRIVACY) == 0 &&
+ (wb->caps & IEEE80211_CAP_PRIVACY))
+ return 1;
+ if ((wa->caps & IEEE80211_CAP_PRIVACY) &&
+ (wb->caps & IEEE80211_CAP_PRIVACY) == 0)
+ return -1;
+
+ /* best/max rate preferred if signal level close enough XXX */
+ if ((wa->level && wb->level && abs(wb->level - wa->level) < 5) ||
+ (wa->qual && wb->qual && abs(wb->qual - wa->qual) < 10)) {
+ maxrate_a = wpa_scan_get_max_rate(wa);
+ maxrate_b = wpa_scan_get_max_rate(wb);
+ if (maxrate_a != maxrate_b)
+ return maxrate_b - maxrate_a;
+ }
+
+ /* use freq for channel preference */
+
+ /* all things being equal, use signal level; if signal levels are
+ * identical, use quality values since some drivers may only report
+ * that value and leave the signal level zero */
+ if (wb->level == wa->level)
+ return wb->qual - wa->qual;
+ return wb->level - wa->level;
+}
+
+
+/**
+ * wpa_supplicant_get_scan_results - Get scan results
+ * @wpa_s: Pointer to wpa_supplicant data
+ * @info: Information about what was scanned or %NULL if not available
+ * @new_scan: Whether a new scan was performed
+ * Returns: Scan results, %NULL on failure
+ *
+ * This function request the current scan results from the driver and updates
+ * the local BSS list wpa_s->bss. The caller is responsible for freeing the
+ * results with wpa_scan_results_free().
+ */
+struct wpa_scan_results *
+wpa_supplicant_get_scan_results(struct wpa_supplicant *wpa_s,
+ struct scan_info *info, int new_scan)
+{
+ struct wpa_scan_results *scan_res;
+ size_t i;
+
+ if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
+ scan_res = ieee80211_sta_get_scan_results(wpa_s);
+ else
+ scan_res = wpa_drv_get_scan_results2(wpa_s);
+ if (scan_res == NULL) {
+ wpa_printf(MSG_DEBUG, "Failed to get scan results");
+ return NULL;
}
+
+ qsort(scan_res->res, scan_res->num, sizeof(struct wpa_scan_res *),
+ wpa_scan_result_compar);
+
+ wpa_bss_update_start(wpa_s);
+ for (i = 0; i < scan_res->num; i++)
+ wpa_bss_update_scan_res(wpa_s, scan_res->res[i]);
+ wpa_bss_update_end(wpa_s, info, new_scan);
+
+ return scan_res;
}
+
+int wpa_supplicant_update_scan_results(struct wpa_supplicant *wpa_s)
+{
+ struct wpa_scan_results *scan_res;
+ scan_res = wpa_supplicant_get_scan_results(wpa_s, NULL, 0);
+ if (scan_res == NULL)
+ return -1;
+ wpa_scan_results_free(scan_res);
+
+ return 0;
+}
+
+
+void wpa_scan_results_free(struct wpa_scan_results *res)
+{
+ size_t i;
+
+ if (res == NULL)
+ return;
+
+ for (i = 0; i < res->num; i++)
+ os_free(res->res[i]);
+ os_free(res->res);
+ os_free(res);
+}
diff --git a/contrib/wpa/wpa_supplicant/scan.h b/contrib/wpa/wpa_supplicant/scan.h
new file mode 100644
index 0000000..441fdbb
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/scan.h
@@ -0,0 +1,37 @@
+/*
+ * WPA Supplicant - Scanning
+ * Copyright (c) 2003-2010, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef SCAN_H
+#define SCAN_H
+
+int wpa_supplicant_enabled_networks(struct wpa_config *conf);
+void wpa_supplicant_req_scan(struct wpa_supplicant *wpa_s, int sec, int usec);
+void wpa_supplicant_cancel_scan(struct wpa_supplicant *wpa_s);
+void wpa_supplicant_notify_scanning(struct wpa_supplicant *wpa_s,
+ int scanning);
+struct wpa_driver_scan_params;
+int wpa_supplicant_trigger_scan(struct wpa_supplicant *wpa_s,
+ struct wpa_driver_scan_params *params);
+struct wpa_scan_results *
+wpa_supplicant_get_scan_results(struct wpa_supplicant *wpa_s,
+ struct scan_info *info, int new_scan);
+int wpa_supplicant_update_scan_results(struct wpa_supplicant *wpa_s);
+const u8 * wpa_scan_get_ie(const struct wpa_scan_res *res, u8 ie);
+const u8 * wpa_scan_get_vendor_ie(const struct wpa_scan_res *res,
+ u32 vendor_type);
+struct wpabuf * wpa_scan_get_vendor_ie_multi(const struct wpa_scan_res *res,
+ u32 vendor_type);
+void wpa_scan_results_free(struct wpa_scan_results *res);
+
+#endif /* SCAN_H */
diff --git a/contrib/wpa/wpa_supplicant/sme.c b/contrib/wpa/wpa_supplicant/sme.c
new file mode 100644
index 0000000..5604e97
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/sme.c
@@ -0,0 +1,490 @@
+/*
+ * wpa_supplicant - SME
+ * Copyright (c) 2009-2010, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "common/ieee802_11_defs.h"
+#include "common/ieee802_11_common.h"
+#include "eapol_supp/eapol_supp_sm.h"
+#include "common/wpa_common.h"
+#include "rsn_supp/wpa.h"
+#include "rsn_supp/pmksa_cache.h"
+#include "config.h"
+#include "wpa_supplicant_i.h"
+#include "driver_i.h"
+#include "wpas_glue.h"
+#include "wps_supplicant.h"
+#include "notify.h"
+#include "blacklist.h"
+#include "bss.h"
+#include "scan.h"
+#include "sme.h"
+
+void sme_authenticate(struct wpa_supplicant *wpa_s,
+ struct wpa_bss *bss, struct wpa_ssid *ssid)
+{
+ struct wpa_driver_auth_params params;
+ struct wpa_ssid *old_ssid;
+#ifdef CONFIG_IEEE80211R
+ const u8 *ie;
+#endif /* CONFIG_IEEE80211R */
+#ifdef CONFIG_IEEE80211R
+ const u8 *md = NULL;
+#endif /* CONFIG_IEEE80211R */
+ int i, bssid_changed;
+
+ if (bss == NULL) {
+ wpa_printf(MSG_ERROR, "SME: No scan result available for the "
+ "network");
+ return;
+ }
+
+ wpa_s->current_bss = bss;
+
+ os_memset(&params, 0, sizeof(params));
+ wpa_s->reassociate = 0;
+
+ params.freq = bss->freq;
+ params.bssid = bss->bssid;
+ params.ssid = bss->ssid;
+ params.ssid_len = bss->ssid_len;
+
+ if (wpa_s->sme.ssid_len != params.ssid_len ||
+ os_memcmp(wpa_s->sme.ssid, params.ssid, params.ssid_len) != 0)
+ wpa_s->sme.prev_bssid_set = 0;
+
+ wpa_s->sme.freq = params.freq;
+ os_memcpy(wpa_s->sme.ssid, params.ssid, params.ssid_len);
+ wpa_s->sme.ssid_len = params.ssid_len;
+
+ params.auth_alg = WPA_AUTH_ALG_OPEN;
+#ifdef IEEE8021X_EAPOL
+ if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
+ if (ssid->leap) {
+ if (ssid->non_leap == 0)
+ params.auth_alg = WPA_AUTH_ALG_LEAP;
+ else
+ params.auth_alg |= WPA_AUTH_ALG_LEAP;
+ }
+ }
+#endif /* IEEE8021X_EAPOL */
+ wpa_printf(MSG_DEBUG, "Automatic auth_alg selection: 0x%x",
+ params.auth_alg);
+ if (ssid->auth_alg) {
+ params.auth_alg = ssid->auth_alg;
+ wpa_printf(MSG_DEBUG, "Overriding auth_alg selection: 0x%x",
+ params.auth_alg);
+ }
+
+ for (i = 0; i < NUM_WEP_KEYS; i++) {
+ if (ssid->wep_key_len[i])
+ params.wep_key[i] = ssid->wep_key[i];
+ params.wep_key_len[i] = ssid->wep_key_len[i];
+ }
+ params.wep_tx_keyidx = ssid->wep_tx_keyidx;
+
+ bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
+ os_memset(wpa_s->bssid, 0, ETH_ALEN);
+ os_memcpy(wpa_s->pending_bssid, bss->bssid, ETH_ALEN);
+ if (bssid_changed)
+ wpas_notify_bssid_changed(wpa_s);
+
+ if ((wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE) ||
+ wpa_bss_get_ie(bss, WLAN_EID_RSN)) &&
+ (ssid->key_mgmt & (WPA_KEY_MGMT_IEEE8021X | WPA_KEY_MGMT_PSK |
+ WPA_KEY_MGMT_FT_IEEE8021X |
+ WPA_KEY_MGMT_FT_PSK |
+ WPA_KEY_MGMT_IEEE8021X_SHA256 |
+ WPA_KEY_MGMT_PSK_SHA256))) {
+ int try_opportunistic;
+ try_opportunistic = ssid->proactive_key_caching &&
+ (ssid->proto & WPA_PROTO_RSN);
+ if (pmksa_cache_set_current(wpa_s->wpa, NULL, bss->bssid,
+ wpa_s->current_ssid,
+ try_opportunistic) == 0)
+ eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
+ wpa_s->sme.assoc_req_ie_len = sizeof(wpa_s->sme.assoc_req_ie);
+ if (wpa_supplicant_set_suites(wpa_s, bss, ssid,
+ wpa_s->sme.assoc_req_ie,
+ &wpa_s->sme.assoc_req_ie_len)) {
+ wpa_printf(MSG_WARNING, "SME: Failed to set WPA key "
+ "management and encryption suites");
+ return;
+ }
+ } else if (ssid->key_mgmt &
+ (WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_IEEE8021X |
+ WPA_KEY_MGMT_WPA_NONE | WPA_KEY_MGMT_FT_PSK |
+ WPA_KEY_MGMT_FT_IEEE8021X | WPA_KEY_MGMT_PSK_SHA256 |
+ WPA_KEY_MGMT_IEEE8021X_SHA256)) {
+ wpa_s->sme.assoc_req_ie_len = sizeof(wpa_s->sme.assoc_req_ie);
+ if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
+ wpa_s->sme.assoc_req_ie,
+ &wpa_s->sme.assoc_req_ie_len)) {
+ wpa_printf(MSG_WARNING, "SME: Failed to set WPA key "
+ "management and encryption suites (no scan "
+ "results)");
+ return;
+ }
+#ifdef CONFIG_WPS
+ } else if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
+ struct wpabuf *wps_ie;
+ wps_ie = wps_build_assoc_req_ie(wpas_wps_get_req_type(ssid));
+ if (wps_ie && wpabuf_len(wps_ie) <=
+ sizeof(wpa_s->sme.assoc_req_ie)) {
+ wpa_s->sme.assoc_req_ie_len = wpabuf_len(wps_ie);
+ os_memcpy(wpa_s->sme.assoc_req_ie, wpabuf_head(wps_ie),
+ wpa_s->sme.assoc_req_ie_len);
+ } else
+ wpa_s->sme.assoc_req_ie_len = 0;
+ wpabuf_free(wps_ie);
+ wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
+#endif /* CONFIG_WPS */
+ } else {
+ wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
+ wpa_s->sme.assoc_req_ie_len = 0;
+ }
+
+#ifdef CONFIG_IEEE80211R
+ ie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
+ if (ie && ie[1] >= MOBILITY_DOMAIN_ID_LEN)
+ md = ie + 2;
+ wpa_sm_set_ft_params(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0);
+ if (md) {
+ /* Prepare for the next transition */
+ wpa_ft_prepare_auth_request(wpa_s->wpa, ie);
+ }
+
+ if (md && ssid->key_mgmt & (WPA_KEY_MGMT_FT_PSK |
+ WPA_KEY_MGMT_FT_IEEE8021X)) {
+ if (wpa_s->sme.assoc_req_ie_len + 5 <
+ sizeof(wpa_s->sme.assoc_req_ie)) {
+ struct rsn_mdie *mdie;
+ u8 *pos = wpa_s->sme.assoc_req_ie +
+ wpa_s->sme.assoc_req_ie_len;
+ *pos++ = WLAN_EID_MOBILITY_DOMAIN;
+ *pos++ = sizeof(*mdie);
+ mdie = (struct rsn_mdie *) pos;
+ os_memcpy(mdie->mobility_domain, md,
+ MOBILITY_DOMAIN_ID_LEN);
+ mdie->ft_capab = md[MOBILITY_DOMAIN_ID_LEN];
+ wpa_s->sme.assoc_req_ie_len += 5;
+ }
+
+ if (wpa_s->sme.ft_used &&
+ os_memcmp(md, wpa_s->sme.mobility_domain, 2) == 0 &&
+ wpa_sm_has_ptk(wpa_s->wpa)) {
+ wpa_printf(MSG_DEBUG, "SME: Trying to use FT "
+ "over-the-air");
+ params.auth_alg = WPA_AUTH_ALG_FT;
+ params.ie = wpa_s->sme.ft_ies;
+ params.ie_len = wpa_s->sme.ft_ies_len;
+ }
+ }
+#endif /* CONFIG_IEEE80211R */
+
+#ifdef CONFIG_IEEE80211W
+ wpa_s->sme.mfp = ssid->ieee80211w;
+ if (ssid->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
+ const u8 *rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
+ struct wpa_ie_data _ie;
+ if (rsn && wpa_parse_wpa_ie(rsn, 2 + rsn[1], &_ie) == 0 &&
+ _ie.capabilities &
+ (WPA_CAPABILITY_MFPC | WPA_CAPABILITY_MFPR)) {
+ wpa_printf(MSG_DEBUG, "WPA: Selected AP supports MFP: "
+ "require MFP");
+ wpa_s->sme.mfp = MGMT_FRAME_PROTECTION_REQUIRED;
+ }
+ }
+#endif /* CONFIG_IEEE80211W */
+
+ wpa_supplicant_cancel_scan(wpa_s);
+
+ wpa_msg(wpa_s, MSG_INFO, "Trying to authenticate with " MACSTR
+ " (SSID='%s' freq=%d MHz)", MAC2STR(params.bssid),
+ wpa_ssid_txt(params.ssid, params.ssid_len), params.freq);
+
+ wpa_clear_keys(wpa_s, bss->bssid);
+ wpa_supplicant_set_state(wpa_s, WPA_AUTHENTICATING);
+ old_ssid = wpa_s->current_ssid;
+ wpa_s->current_ssid = ssid;
+ wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
+ wpa_supplicant_initiate_eapol(wpa_s);
+ if (old_ssid != wpa_s->current_ssid)
+ wpas_notify_network_changed(wpa_s);
+
+ wpa_s->sme.auth_alg = params.auth_alg;
+ if (wpa_drv_authenticate(wpa_s, &params) < 0) {
+ wpa_msg(wpa_s, MSG_INFO, "Authentication request to the "
+ "driver failed");
+ wpa_supplicant_req_scan(wpa_s, 1, 0);
+ return;
+ }
+
+ /* TODO: add timeout on authentication */
+
+ /*
+ * Association will be started based on the authentication event from
+ * the driver.
+ */
+}
+
+
+void sme_event_auth(struct wpa_supplicant *wpa_s, union wpa_event_data *data)
+{
+ struct wpa_ssid *ssid = wpa_s->current_ssid;
+
+ if (ssid == NULL) {
+ wpa_printf(MSG_DEBUG, "SME: Ignore authentication event when "
+ "network is not selected");
+ return;
+ }
+
+ if (wpa_s->wpa_state != WPA_AUTHENTICATING) {
+ wpa_printf(MSG_DEBUG, "SME: Ignore authentication event when "
+ "not in authenticating state");
+ return;
+ }
+
+ if (os_memcmp(wpa_s->pending_bssid, data->auth.peer, ETH_ALEN) != 0) {
+ wpa_printf(MSG_DEBUG, "SME: Ignore authentication with "
+ "unexpected peer " MACSTR,
+ MAC2STR(data->auth.peer));
+ return;
+ }
+
+ wpa_printf(MSG_DEBUG, "SME: Authentication response: peer=" MACSTR
+ " auth_type=%d status_code=%d",
+ MAC2STR(data->auth.peer), data->auth.auth_type,
+ data->auth.status_code);
+ wpa_hexdump(MSG_MSGDUMP, "SME: Authentication response IEs",
+ data->auth.ies, data->auth.ies_len);
+
+ if (data->auth.status_code != WLAN_STATUS_SUCCESS) {
+ wpa_printf(MSG_DEBUG, "SME: Authentication failed (status "
+ "code %d)", data->auth.status_code);
+
+ if (data->auth.status_code !=
+ WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG ||
+ wpa_s->sme.auth_alg == data->auth.auth_type ||
+ wpa_s->current_ssid->auth_alg == WPA_AUTH_ALG_LEAP)
+ return;
+
+ switch (data->auth.auth_type) {
+ case WLAN_AUTH_OPEN:
+ wpa_s->current_ssid->auth_alg = WPA_AUTH_ALG_SHARED;
+
+ wpa_printf(MSG_DEBUG, "SME: Trying SHARED auth");
+ wpa_supplicant_associate(wpa_s, wpa_s->current_bss,
+ wpa_s->current_ssid);
+ return;
+
+ case WLAN_AUTH_SHARED_KEY:
+ wpa_s->current_ssid->auth_alg = WPA_AUTH_ALG_LEAP;
+
+ wpa_printf(MSG_DEBUG, "SME: Trying LEAP auth");
+ wpa_supplicant_associate(wpa_s, wpa_s->current_bss,
+ wpa_s->current_ssid);
+ return;
+
+ default:
+ return;
+ }
+ }
+
+#ifdef CONFIG_IEEE80211R
+ if (data->auth.auth_type == WLAN_AUTH_FT) {
+ union wpa_event_data edata;
+ os_memset(&edata, 0, sizeof(edata));
+ edata.ft_ies.ies = data->auth.ies;
+ edata.ft_ies.ies_len = data->auth.ies_len;
+ os_memcpy(edata.ft_ies.target_ap, data->auth.peer, ETH_ALEN);
+ wpa_supplicant_event(wpa_s, EVENT_FT_RESPONSE, &edata);
+ }
+#endif /* CONFIG_IEEE80211R */
+
+ sme_associate(wpa_s, ssid->mode, data->auth.peer,
+ data->auth.auth_type);
+}
+
+
+void sme_associate(struct wpa_supplicant *wpa_s, enum wpas_mode mode,
+ const u8 *bssid, u16 auth_type)
+{
+ struct wpa_driver_associate_params params;
+ struct ieee802_11_elems elems;
+
+ os_memset(&params, 0, sizeof(params));
+ params.bssid = bssid;
+ params.ssid = wpa_s->sme.ssid;
+ params.ssid_len = wpa_s->sme.ssid_len;
+ params.freq = wpa_s->sme.freq;
+ params.wpa_ie = wpa_s->sme.assoc_req_ie_len ?
+ wpa_s->sme.assoc_req_ie : NULL;
+ params.wpa_ie_len = wpa_s->sme.assoc_req_ie_len;
+#ifdef CONFIG_IEEE80211R
+ if (auth_type == WLAN_AUTH_FT && wpa_s->sme.ft_ies) {
+ params.wpa_ie = wpa_s->sme.ft_ies;
+ params.wpa_ie_len = wpa_s->sme.ft_ies_len;
+ }
+#endif /* CONFIG_IEEE80211R */
+ params.mode = mode;
+ params.mgmt_frame_protection = wpa_s->sme.mfp;
+ if (wpa_s->sme.prev_bssid_set)
+ params.prev_bssid = wpa_s->sme.prev_bssid;
+
+ wpa_msg(wpa_s, MSG_INFO, "Trying to associate with " MACSTR
+ " (SSID='%s' freq=%d MHz)", MAC2STR(params.bssid),
+ params.ssid ? wpa_ssid_txt(params.ssid, params.ssid_len) : "",
+ params.freq);
+
+ wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATING);
+
+ if (params.wpa_ie == NULL ||
+ ieee802_11_parse_elems(params.wpa_ie, params.wpa_ie_len, &elems, 0)
+ < 0) {
+ wpa_printf(MSG_DEBUG, "SME: Could not parse own IEs?!");
+ os_memset(&elems, 0, sizeof(elems));
+ }
+ if (elems.rsn_ie)
+ wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, elems.rsn_ie - 2,
+ elems.rsn_ie_len + 2);
+ else if (elems.wpa_ie)
+ wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, elems.wpa_ie - 2,
+ elems.wpa_ie_len + 2);
+ else
+ wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
+
+ if (wpa_drv_associate(wpa_s, &params) < 0) {
+ wpa_msg(wpa_s, MSG_INFO, "Association request to the driver "
+ "failed");
+ wpa_supplicant_req_scan(wpa_s, 5, 0);
+ return;
+ }
+
+ /* TODO: add timeout on association */
+}
+
+
+int sme_update_ft_ies(struct wpa_supplicant *wpa_s, const u8 *md,
+ const u8 *ies, size_t ies_len)
+{
+ if (md == NULL || ies == NULL) {
+ wpa_printf(MSG_DEBUG, "SME: Remove mobility domain");
+ os_free(wpa_s->sme.ft_ies);
+ wpa_s->sme.ft_ies = NULL;
+ wpa_s->sme.ft_ies_len = 0;
+ wpa_s->sme.ft_used = 0;
+ return 0;
+ }
+
+ os_memcpy(wpa_s->sme.mobility_domain, md, MOBILITY_DOMAIN_ID_LEN);
+ wpa_hexdump(MSG_DEBUG, "SME: FT IEs", ies, ies_len);
+ os_free(wpa_s->sme.ft_ies);
+ wpa_s->sme.ft_ies = os_malloc(ies_len);
+ if (wpa_s->sme.ft_ies == NULL)
+ return -1;
+ os_memcpy(wpa_s->sme.ft_ies, ies, ies_len);
+ wpa_s->sme.ft_ies_len = ies_len;
+ return 0;
+}
+
+
+void sme_event_assoc_reject(struct wpa_supplicant *wpa_s,
+ union wpa_event_data *data)
+{
+ int bssid_changed;
+ int timeout = 5000;
+
+ wpa_printf(MSG_DEBUG, "SME: Association with " MACSTR " failed: "
+ "status code %d", MAC2STR(wpa_s->pending_bssid),
+ data->assoc_reject.status_code);
+
+ bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
+
+ /*
+ * For now, unconditionally terminate the previous authentication. In
+ * theory, this should not be needed, but mac80211 gets quite confused
+ * if the authentication is left pending.. Some roaming cases might
+ * benefit from using the previous authentication, so this could be
+ * optimized in the future.
+ */
+ if (wpa_drv_deauthenticate(wpa_s, wpa_s->pending_bssid,
+ WLAN_REASON_DEAUTH_LEAVING) < 0) {
+ wpa_msg(wpa_s, MSG_INFO,
+ "Deauth request to the driver failed");
+ }
+ wpa_s->sme.prev_bssid_set = 0;
+
+ if (wpa_blacklist_add(wpa_s, wpa_s->pending_bssid) == 0) {
+ struct wpa_blacklist *b;
+ b = wpa_blacklist_get(wpa_s, wpa_s->pending_bssid);
+ if (b && b->count < 3) {
+ /*
+ * Speed up next attempt if there could be other APs
+ * that could accept association.
+ */
+ timeout = 100;
+ }
+ }
+ wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
+ os_memset(wpa_s->bssid, 0, ETH_ALEN);
+ os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
+ if (bssid_changed)
+ wpas_notify_bssid_changed(wpa_s);
+
+ /*
+ * TODO: if more than one possible AP is available in scan results,
+ * could try the other ones before requesting a new scan.
+ */
+ wpa_supplicant_req_scan(wpa_s, timeout / 1000,
+ 1000 * (timeout % 1000));
+}
+
+
+void sme_event_auth_timed_out(struct wpa_supplicant *wpa_s,
+ union wpa_event_data *data)
+{
+ wpa_printf(MSG_DEBUG, "SME: Authentication timed out");
+ wpa_supplicant_req_scan(wpa_s, 5, 0);
+}
+
+
+void sme_event_assoc_timed_out(struct wpa_supplicant *wpa_s,
+ union wpa_event_data *data)
+{
+ wpa_printf(MSG_DEBUG, "SME: Association timed out");
+ wpa_supplicant_mark_disassoc(wpa_s);
+ wpa_supplicant_req_scan(wpa_s, 5, 0);
+}
+
+
+void sme_event_disassoc(struct wpa_supplicant *wpa_s,
+ union wpa_event_data *data)
+{
+ wpa_printf(MSG_DEBUG, "SME: Disassociation event received");
+ if (wpa_s->sme.prev_bssid_set &&
+ !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)) {
+ /*
+ * cfg80211/mac80211 can get into somewhat confused state if
+ * the AP only disassociates us and leaves us in authenticated
+ * state. For now, force the state to be cleared to avoid
+ * confusing errors if we try to associate with the AP again.
+ */
+ wpa_printf(MSG_DEBUG, "SME: Deauthenticate to clear driver "
+ "state");
+ wpa_drv_deauthenticate(wpa_s, wpa_s->sme.prev_bssid,
+ WLAN_REASON_DEAUTH_LEAVING);
+ }
+}
diff --git a/contrib/wpa/wpa_supplicant/sme.h b/contrib/wpa/wpa_supplicant/sme.h
new file mode 100644
index 0000000..3ec8cc9
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/sme.h
@@ -0,0 +1,78 @@
+/*
+ * wpa_supplicant - SME
+ * Copyright (c) 2009-2010, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef SME_H
+#define SME_H
+
+#ifdef CONFIG_SME
+
+void sme_authenticate(struct wpa_supplicant *wpa_s,
+ struct wpa_bss *bss, struct wpa_ssid *ssid);
+void sme_associate(struct wpa_supplicant *wpa_s, enum wpas_mode mode,
+ const u8 *bssid, u16 auth_type);
+void sme_event_auth(struct wpa_supplicant *wpa_s, union wpa_event_data *data);
+int sme_update_ft_ies(struct wpa_supplicant *wpa_s, const u8 *md,
+ const u8 *ies, size_t ies_len);
+void sme_event_assoc_reject(struct wpa_supplicant *wpa_s,
+ union wpa_event_data *data);
+void sme_event_auth_timed_out(struct wpa_supplicant *wpa_s,
+ union wpa_event_data *data);
+void sme_event_assoc_timed_out(struct wpa_supplicant *wpa_s,
+ union wpa_event_data *data);
+void sme_event_disassoc(struct wpa_supplicant *wpa_s,
+ union wpa_event_data *data);
+
+#else /* CONFIG_SME */
+
+static inline void sme_authenticate(struct wpa_supplicant *wpa_s,
+ struct wpa_bss *bss,
+ struct wpa_ssid *ssid)
+{
+}
+
+static inline void sme_event_auth(struct wpa_supplicant *wpa_s,
+ union wpa_event_data *data)
+{
+}
+
+static inline int sme_update_ft_ies(struct wpa_supplicant *wpa_s, const u8 *md,
+ const u8 *ies, size_t ies_len)
+{
+ return -1;
+}
+
+
+static inline void sme_event_assoc_reject(struct wpa_supplicant *wpa_s,
+ union wpa_event_data *data)
+{
+}
+
+static inline void sme_event_auth_timed_out(struct wpa_supplicant *wpa_s,
+ union wpa_event_data *data)
+{
+}
+
+static inline void sme_event_assoc_timed_out(struct wpa_supplicant *wpa_s,
+ union wpa_event_data *data)
+{
+}
+
+static inline void sme_event_disassoc(struct wpa_supplicant *wpa_s,
+ union wpa_event_data *data)
+{
+}
+
+#endif /* CONFIG_SME */
+
+#endif /* SME_H */
diff --git a/contrib/wpa/wpa_supplicant/tests/test_aes.c b/contrib/wpa/wpa_supplicant/tests/test_aes.c
deleted file mode 100644
index 38a9cf5..0000000
--- a/contrib/wpa/wpa_supplicant/tests/test_aes.c
+++ /dev/null
@@ -1,307 +0,0 @@
-/*
- * Test program for AES
- * Copyright (c) 2003-2006, Jouni Malinen <j@w1.fi>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
- */
-
-#include "includes.h"
-
-#include "common.h"
-#include "crypto.h"
-#include "aes_wrap.h"
-
-#define BLOCK_SIZE 16
-
-static void test_aes_perf(void)
-{
-#if 0 /* this did not seem to work with new compiler?! */
-#ifdef __i386__
-#define rdtscll(val) \
- __asm__ __volatile__("rdtsc" : "=A" (val))
- const int num_iters = 10;
- int i;
- unsigned int start, end;
- u8 key[16], pt[16], ct[16];
- void *ctx;
-
- printf("keySetupEnc:");
- for (i = 0; i < num_iters; i++) {
- rdtscll(start);
- ctx = aes_encrypt_init(key, 16);
- rdtscll(end);
- aes_encrypt_deinit(ctx);
- printf(" %d", end - start);
- }
- printf("\n");
-
- printf("Encrypt:");
- ctx = aes_encrypt_init(key, 16);
- for (i = 0; i < num_iters; i++) {
- rdtscll(start);
- aes_encrypt(ctx, pt, ct);
- rdtscll(end);
- printf(" %d", end - start);
- }
- aes_encrypt_deinit(ctx);
- printf("\n");
-#endif /* __i386__ */
-#endif
-}
-
-
-static int test_eax(void)
-{
- u8 msg[] = { 0xF7, 0xFB };
- u8 key[] = { 0x91, 0x94, 0x5D, 0x3F, 0x4D, 0xCB, 0xEE, 0x0B,
- 0xF4, 0x5E, 0xF5, 0x22, 0x55, 0xF0, 0x95, 0xA4 };
- u8 nonce[] = { 0xBE, 0xCA, 0xF0, 0x43, 0xB0, 0xA2, 0x3D, 0x84,
- 0x31, 0x94, 0xBA, 0x97, 0x2C, 0x66, 0xDE, 0xBD };
- u8 hdr[] = { 0xFA, 0x3B, 0xFD, 0x48, 0x06, 0xEB, 0x53, 0xFA };
- u8 cipher[] = { 0x19, 0xDD, 0x5C, 0x4C, 0x93, 0x31, 0x04, 0x9D,
- 0x0B, 0xDA, 0xB0, 0x27, 0x74, 0x08, 0xF6, 0x79,
- 0x67, 0xE5 };
- u8 data[sizeof(msg)], tag[BLOCK_SIZE];
-
- memcpy(data, msg, sizeof(msg));
- if (aes_128_eax_encrypt(key, nonce, sizeof(nonce), hdr, sizeof(hdr),
- data, sizeof(data), tag)) {
- printf("AES-128 EAX mode encryption failed\n");
- return 1;
- }
- if (memcmp(data, cipher, sizeof(data)) != 0) {
- printf("AES-128 EAX mode encryption returned invalid cipher "
- "text\n");
- return 1;
- }
- if (memcmp(tag, cipher + sizeof(data), BLOCK_SIZE) != 0) {
- printf("AES-128 EAX mode encryption returned invalid tag\n");
- return 1;
- }
-
- if (aes_128_eax_decrypt(key, nonce, sizeof(nonce), hdr, sizeof(hdr),
- data, sizeof(data), tag)) {
- printf("AES-128 EAX mode decryption failed\n");
- return 1;
- }
- if (memcmp(data, msg, sizeof(data)) != 0) {
- printf("AES-128 EAX mode decryption returned invalid plain "
- "text\n");
- return 1;
- }
-
- return 0;
-}
-
-
-static int test_cbc(void)
-{
- struct cbc_test_vector {
- u8 key[16];
- u8 iv[16];
- u8 plain[32];
- u8 cipher[32];
- size_t len;
- } vectors[] = {
- {
- { 0x06, 0xa9, 0x21, 0x40, 0x36, 0xb8, 0xa1, 0x5b,
- 0x51, 0x2e, 0x03, 0xd5, 0x34, 0x12, 0x00, 0x06 },
- { 0x3d, 0xaf, 0xba, 0x42, 0x9d, 0x9e, 0xb4, 0x30,
- 0xb4, 0x22, 0xda, 0x80, 0x2c, 0x9f, 0xac, 0x41 },
- "Single block msg",
- { 0xe3, 0x53, 0x77, 0x9c, 0x10, 0x79, 0xae, 0xb8,
- 0x27, 0x08, 0x94, 0x2d, 0xbe, 0x77, 0x18, 0x1a },
- 16
- },
- {
- { 0xc2, 0x86, 0x69, 0x6d, 0x88, 0x7c, 0x9a, 0xa0,
- 0x61, 0x1b, 0xbb, 0x3e, 0x20, 0x25, 0xa4, 0x5a },
- { 0x56, 0x2e, 0x17, 0x99, 0x6d, 0x09, 0x3d, 0x28,
- 0xdd, 0xb3, 0xba, 0x69, 0x5a, 0x2e, 0x6f, 0x58 },
- { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
- 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f },
- { 0xd2, 0x96, 0xcd, 0x94, 0xc2, 0xcc, 0xcf, 0x8a,
- 0x3a, 0x86, 0x30, 0x28, 0xb5, 0xe1, 0xdc, 0x0a,
- 0x75, 0x86, 0x60, 0x2d, 0x25, 0x3c, 0xff, 0xf9,
- 0x1b, 0x82, 0x66, 0xbe, 0xa6, 0xd6, 0x1a, 0xb1 },
- 32
- }
- };
- int ret = 0;
- u8 *buf;
- unsigned int i;
-
- for (i = 0; i < sizeof(vectors) / sizeof(vectors[0]); i++) {
- struct cbc_test_vector *tv = &vectors[i];
- buf = malloc(tv->len);
- if (buf == NULL) {
- ret++;
- break;
- }
- memcpy(buf, tv->plain, tv->len);
- aes_128_cbc_encrypt(tv->key, tv->iv, buf, tv->len);
- if (memcmp(buf, tv->cipher, tv->len) != 0) {
- printf("AES-CBC encrypt %d failed\n", i);
- ret++;
- }
- memcpy(buf, tv->cipher, tv->len);
- aes_128_cbc_decrypt(tv->key, tv->iv, buf, tv->len);
- if (memcmp(buf, tv->plain, tv->len) != 0) {
- printf("AES-CBC decrypt %d failed\n", i);
- ret++;
- }
- free(buf);
- }
-
- return ret;
-}
-
-
-/* OMAC1 AES-128 test vectors from
- * http://csrc.nist.gov/CryptoToolkit/modes/proposedmodes/omac/omac-ad.pdf
- * which are same as the examples from NIST SP800-38B
- * http://csrc.nist.gov/CryptoToolkit/modes/800-38_Series_Publications/SP800-38B.pdf
- */
-
-struct omac1_test_vector {
- u8 k[16];
- u8 msg[64];
- int msg_len;
- u8 tag[16];
-};
-
-static struct omac1_test_vector test_vectors[] =
-{
- {
- { 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
- 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c },
- { },
- 0,
- { 0xbb, 0x1d, 0x69, 0x29, 0xe9, 0x59, 0x37, 0x28,
- 0x7f, 0xa3, 0x7d, 0x12, 0x9b, 0x75, 0x67, 0x46 }
- },
- {
- { 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
- 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c },
- { 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
- 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a},
- 16,
- { 0x07, 0x0a, 0x16, 0xb4, 0x6b, 0x4d, 0x41, 0x44,
- 0xf7, 0x9b, 0xdd, 0x9d, 0xd0, 0x4a, 0x28, 0x7c }
- },
- {
- { 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
- 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c },
- { 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
- 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
- 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
- 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
- 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11 },
- 40,
- { 0xdf, 0xa6, 0x67, 0x47, 0xde, 0x9a, 0xe6, 0x30,
- 0x30, 0xca, 0x32, 0x61, 0x14, 0x97, 0xc8, 0x27 }
- },
- {
- { 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
- 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c },
- { 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
- 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
- 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
- 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
- 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
- 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
- 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
- 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 },
- 64,
- { 0x51, 0xf0, 0xbe, 0xbf, 0x7e, 0x3b, 0x9d, 0x92,
- 0xfc, 0x49, 0x74, 0x17, 0x79, 0x36, 0x3c, 0xfe }
- },
-};
-
-
-int main(int argc, char *argv[])
-{
- u8 kek[] = {
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
- };
- u8 plain[] = {
- 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
- 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
- };
- u8 crypt[] = {
- 0x1F, 0xA6, 0x8B, 0x0A, 0x81, 0x12, 0xB4, 0x47,
- 0xAE, 0xF3, 0x4B, 0xD8, 0xFB, 0x5A, 0x7B, 0x82,
- 0x9D, 0x3E, 0x86, 0x23, 0x71, 0xD2, 0xCF, 0xE5
- };
- u8 result[24];
- int ret = 0;
- unsigned int i;
- struct omac1_test_vector *tv;
-
- if (aes_wrap(kek, 2, plain, result)) {
- printf("AES-WRAP-128-128 reported failure\n");
- ret++;
- }
- if (memcmp(result, crypt, 24) != 0) {
- printf("AES-WRAP-128-128 failed\n");
- ret++;
- }
- if (aes_unwrap(kek, 2, crypt, result)) {
- printf("AES-UNWRAP-128-128 reported failure\n");
- ret++;
- }
- if (memcmp(result, plain, 16) != 0) {
- printf("AES-UNWRAP-128-128 failed\n");
- ret++;
- for (i = 0; i < 16; i++)
- printf(" %02x", result[i]);
- printf("\n");
- }
-
- test_aes_perf();
-
- for (i = 0; i < sizeof(test_vectors) / sizeof(test_vectors[0]); i++) {
- tv = &test_vectors[i];
- omac1_aes_128(tv->k, tv->msg, tv->msg_len, result);
- if (memcmp(result, tv->tag, 16) != 0) {
- printf("OMAC1-AES-128 test vector %d failed\n", i);
- ret++;
- }
-
- if (tv->msg_len > 1) {
- const u8 *addr[2];
- size_t len[2];
-
- addr[0] = tv->msg;
- len[0] = 1;
- addr[1] = tv->msg + 1;
- len[1] = tv->msg_len - 1;
-
- omac1_aes_128_vector(tv->k, 2, addr, len, result);
- if (memcmp(result, tv->tag, 16) != 0) {
- printf("OMAC1-AES-128(vector) test vector %d "
- "failed\n", i);
- ret++;
- }
- }
- }
-
- ret += test_eax();
-
- ret += test_cbc();
-
- if (ret)
- printf("FAILED!\n");
-
- return ret;
-}
diff --git a/contrib/wpa/wpa_supplicant/tests/test_eap_sim_common.c b/contrib/wpa/wpa_supplicant/tests/test_eap_sim_common.c
index ee3eee4..deb19f6 100644
--- a/contrib/wpa/wpa_supplicant/tests/test_eap_sim_common.c
+++ b/contrib/wpa/wpa_supplicant/tests/test_eap_sim_common.c
@@ -12,7 +12,7 @@
* See README and COPYING for more details.
*/
-#include "eap_sim_common.c"
+#include "eap_common/eap_sim_common.c"
static int test_eap_sim_prf(void)
diff --git a/contrib/wpa/wpa_supplicant/tests/test_md4.c b/contrib/wpa/wpa_supplicant/tests/test_md4.c
deleted file mode 100644
index e92e9a5..0000000
--- a/contrib/wpa/wpa_supplicant/tests/test_md4.c
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Test program for MD4 (test vectors from RFC 1320)
- * Copyright (c) 2006, Jouni Malinen <j@w1.fi>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
- */
-
-#include "includes.h"
-
-#include "common.h"
-#include "crypto.h"
-
-int main(int argc, char *argv[])
-{
- struct {
- char *data;
- u8 *hash;
- } tests[] = {
- {
- "",
- "\x31\xd6\xcf\xe0\xd1\x6a\xe9\x31"
- "\xb7\x3c\x59\xd7\xe0\xc0\x89\xc0"
- },
- {
- "a",
- "\xbd\xe5\x2c\xb3\x1d\xe3\x3e\x46"
- "\x24\x5e\x05\xfb\xdb\xd6\xfb\x24"
- },
- {
- "abc",
- "\xa4\x48\x01\x7a\xaf\x21\xd8\x52"
- "\x5f\xc1\x0a\xe8\x7a\xa6\x72\x9d"
- },
- {
- "message digest",
- "\xd9\x13\x0a\x81\x64\x54\x9f\xe8"
- "\x18\x87\x48\x06\xe1\xc7\x01\x4b"
- },
- {
- "abcdefghijklmnopqrstuvwxyz",
- "\xd7\x9e\x1c\x30\x8a\xa5\xbb\xcd"
- "\xee\xa8\xed\x63\xdf\x41\x2d\xa9"
- },
- {
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
- "0123456789",
- "\x04\x3f\x85\x82\xf2\x41\xdb\x35"
- "\x1c\xe6\x27\xe1\x53\xe7\xf0\xe4"
- },
- {
- "12345678901234567890123456789012345678901234567890"
- "123456789012345678901234567890",
- "\xe3\x3b\x4d\xdc\x9c\x38\xf2\x19"
- "\x9c\x3e\x7b\x16\x4f\xcc\x05\x36"
- }
- };
- unsigned int i;
- u8 hash[16];
- const u8 *addr[2];
- size_t len[2];
- int errors = 0;
-
- for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
- printf("MD4 test case %d:", i);
-
- addr[0] = tests[i].data;
- len[0] = strlen(tests[i].data);
- md4_vector(1, addr, len, hash);
- if (memcmp(hash, tests[i].hash, 16) != 0) {
- printf(" FAIL");
- errors++;
- } else
- printf(" OK");
-
- if (len[0]) {
- addr[0] = tests[i].data;
- len[0] = strlen(tests[i].data);
- addr[1] = tests[i].data + 1;
- len[1] = strlen(tests[i].data) - 1;
- md4_vector(1, addr, len, hash);
- if (memcmp(hash, tests[i].hash, 16) != 0) {
- printf(" FAIL");
- errors++;
- } else
- printf(" OK");
- }
-
- printf("\n");
- }
-
- return errors;
-}
diff --git a/contrib/wpa/wpa_supplicant/tests/test_md5.c b/contrib/wpa/wpa_supplicant/tests/test_md5.c
deleted file mode 100644
index d8fb41e..0000000
--- a/contrib/wpa/wpa_supplicant/tests/test_md5.c
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Test program for MD5 (test vectors from RFC 1321)
- * Copyright (c) 2006, Jouni Malinen <j@w1.fi>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
- */
-
-#include "includes.h"
-
-#include "common.h"
-#include "crypto.h"
-
-int main(int argc, char *argv[])
-{
- struct {
- char *data;
- u8 *hash;
- } tests[] = {
- {
- "",
- "\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04"
- "\xe9\x80\x09\x98\xec\xf8\x42\x7e"
- },
- {
- "a",
- "\x0c\xc1\x75\xb9\xc0\xf1\xb6\xa8"
- "\x31\xc3\x99\xe2\x69\x77\x26\x61"
- },
- {
- "abc",
- "\x90\x01\x50\x98\x3c\xd2\x4f\xb0"
- "\xd6\x96\x3f\x7d\x28\xe1\x7f\x72"
- },
- {
- "message digest",
- "\xf9\x6b\x69\x7d\x7c\xb7\x93\x8d"
- "\x52\x5a\x2f\x31\xaa\xf1\x61\xd0"
- },
- {
- "abcdefghijklmnopqrstuvwxyz",
- "\xc3\xfc\xd3\xd7\x61\x92\xe4\x00"
- "\x7d\xfb\x49\x6c\xca\x67\xe1\x3b"
- },
- {
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
- "0123456789",
- "\xd1\x74\xab\x98\xd2\x77\xd9\xf5"
- "\xa5\x61\x1c\x2c\x9f\x41\x9d\x9f"
- },
- {
- "12345678901234567890123456789012345678901234567890"
- "123456789012345678901234567890",
- "\x57\xed\xf4\xa2\x2b\xe3\xc9\x55"
- "\xac\x49\xda\x2e\x21\x07\xb6\x7a"
- }
- };
- unsigned int i;
- u8 hash[16];
- const u8 *addr[2];
- size_t len[2];
- int errors = 0;
-
- for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
- printf("MD5 test case %d:", i);
-
- addr[0] = tests[i].data;
- len[0] = strlen(tests[i].data);
- md5_vector(1, addr, len, hash);
- if (memcmp(hash, tests[i].hash, 16) != 0) {
- printf(" FAIL");
- errors++;
- } else
- printf(" OK");
-
- if (len[0]) {
- addr[0] = tests[i].data;
- len[0] = strlen(tests[i].data);
- addr[1] = tests[i].data + 1;
- len[1] = strlen(tests[i].data) - 1;
- md5_vector(1, addr, len, hash);
- if (memcmp(hash, tests[i].hash, 16) != 0) {
- printf(" FAIL");
- errors++;
- } else
- printf(" OK");
- }
-
- printf("\n");
- }
-
- return errors;
-}
diff --git a/contrib/wpa/wpa_supplicant/tests/test_ms_funcs.c b/contrib/wpa/wpa_supplicant/tests/test_ms_funcs.c
deleted file mode 100644
index 09b53c4..0000000
--- a/contrib/wpa/wpa_supplicant/tests/test_ms_funcs.c
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Test program for ms_funcs
- * Copyright (c) 2003-2006, Jouni Malinen <j@w1.fi>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
- */
-
-#include "ms_funcs.c"
-
-
-int main(int argc, char *argv[])
-{
- /* Test vector from RFC2759 example */
- u8 *username = "User";
- u8 *password = "clientPass";
- u8 auth_challenge[] = {
- 0x5B, 0x5D, 0x7C, 0x7D, 0x7B, 0x3F, 0x2F, 0x3E,
- 0x3C, 0x2C, 0x60, 0x21, 0x32, 0x26, 0x26, 0x28
- };
- u8 peer_challenge[] = {
- 0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A,
- 0x28, 0x29, 0x5F, 0x2B, 0x3A, 0x33, 0x7C, 0x7E
- };
- u8 challenge[] = { 0xD0, 0x2E, 0x43, 0x86, 0xBC, 0xE9, 0x12, 0x26 };
- u8 password_hash[] = {
- 0x44, 0xEB, 0xBA, 0x8D, 0x53, 0x12, 0xB8, 0xD6,
- 0x11, 0x47, 0x44, 0x11, 0xF5, 0x69, 0x89, 0xAE
- };
- u8 nt_response[] = {
- 0x82, 0x30, 0x9E, 0xCD, 0x8D, 0x70, 0x8B, 0x5E,
- 0xA0, 0x8F, 0xAA, 0x39, 0x81, 0xCD, 0x83, 0x54,
- 0x42, 0x33, 0x11, 0x4A, 0x3D, 0x85, 0xD6, 0xDF
- };
- u8 password_hash_hash[] = {
- 0x41, 0xC0, 0x0C, 0x58, 0x4B, 0xD2, 0xD9, 0x1C,
- 0x40, 0x17, 0xA2, 0xA1, 0x2F, 0xA5, 0x9F, 0x3F
- };
- u8 authenticator_response[] = {
- 0x40, 0x7A, 0x55, 0x89, 0x11, 0x5F, 0xD0, 0xD6,
- 0x20, 0x9F, 0x51, 0x0F, 0xE9, 0xC0, 0x45, 0x66,
- 0x93, 0x2C, 0xDA, 0x56
- };
- u8 master_key[] = {
- 0xFD, 0xEC, 0xE3, 0x71, 0x7A, 0x8C, 0x83, 0x8C,
- 0xB3, 0x88, 0xE5, 0x27, 0xAE, 0x3C, 0xDD, 0x31
- };
- u8 send_start_key[] = {
- 0x8B, 0x7C, 0xDC, 0x14, 0x9B, 0x99, 0x3A, 0x1B,
- 0xA1, 0x18, 0xCB, 0x15, 0x3F, 0x56, 0xDC, 0xCB
- };
- u8 buf[32];
-
- int errors = 0;
-
- printf("Testing ms_funcs.c\n");
-
- challenge_hash(peer_challenge, auth_challenge,
- username, strlen(username),
- buf);
- if (memcmp(challenge, buf, sizeof(challenge)) != 0) {
- printf("challenge_hash failed\n");
- errors++;
- }
-
- nt_password_hash(password, strlen(password), buf);
- if (memcmp(password_hash, buf, sizeof(password_hash)) != 0) {
- printf("nt_password_hash failed\n");
- errors++;
- }
-
- generate_nt_response(auth_challenge, peer_challenge,
- username, strlen(username),
- password, strlen(password),
- buf);
- if (memcmp(nt_response, buf, sizeof(nt_response)) != 0) {
- printf("generate_nt_response failed\n");
- errors++;
- }
-
- hash_nt_password_hash(password_hash, buf);
- if (memcmp(password_hash_hash, buf, sizeof(password_hash_hash)) != 0) {
- printf("hash_nt_password_hash failed\n");
- errors++;
- }
-
- generate_authenticator_response(password, strlen(password),
- peer_challenge, auth_challenge,
- username, strlen(username),
- nt_response, buf);
- if (memcmp(authenticator_response, buf, sizeof(authenticator_response))
- != 0) {
- printf("generate_authenticator_response failed\n");
- errors++;
- }
-
- get_master_key(password_hash_hash, nt_response, buf);
- if (memcmp(master_key, buf, sizeof(master_key)) != 0) {
- printf("get_master_key failed\n");
- errors++;
- }
-
- get_asymetric_start_key(master_key, buf, sizeof(send_start_key), 1, 1);
- if (memcmp(send_start_key, buf, sizeof(send_start_key)) != 0) {
- printf("get_asymetric_start_key failed\n");
- errors++;
- }
-
- if (errors)
- printf("FAILED! %d errors\n", errors);
-
- return errors;
-}
diff --git a/contrib/wpa/wpa_supplicant/tests/test_sha1.c b/contrib/wpa/wpa_supplicant/tests/test_sha1.c
deleted file mode 100644
index d2e6a99..0000000
--- a/contrib/wpa/wpa_supplicant/tests/test_sha1.c
+++ /dev/null
@@ -1,347 +0,0 @@
-/*
- * Test program for SHA1 and MD5
- * Copyright (c) 2003-2006, Jouni Malinen <j@w1.fi>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
- */
-
-#include "includes.h"
-
-#include "common.h"
-#include "sha1.h"
-#include "md5.h"
-#include "crypto.h"
-
-
-static int test_eap_fast(void)
-{
- /* RFC 4851, Appendix B.1 */
- const u8 pac_key[] = {
- 0x0B, 0x97, 0x39, 0x0F, 0x37, 0x51, 0x78, 0x09,
- 0x81, 0x1E, 0xFD, 0x9C, 0x6E, 0x65, 0x94, 0x2B,
- 0x63, 0x2C, 0xE9, 0x53, 0x89, 0x38, 0x08, 0xBA,
- 0x36, 0x0B, 0x03, 0x7C, 0xD1, 0x85, 0xE4, 0x14
- };
- const u8 seed[] = {
- 0x3F, 0xFB, 0x11, 0xC4, 0x6C, 0xBF, 0xA5, 0x7A,
- 0x54, 0x40, 0xDA, 0xE8, 0x22, 0xD3, 0x11, 0xD3,
- 0xF7, 0x6D, 0xE4, 0x1D, 0xD9, 0x33, 0xE5, 0x93,
- 0x70, 0x97, 0xEB, 0xA9, 0xB3, 0x66, 0xF4, 0x2A,
- 0x00, 0x00, 0x00, 0x02, 0x6A, 0x66, 0x43, 0x2A,
- 0x8D, 0x14, 0x43, 0x2C, 0xEC, 0x58, 0x2D, 0x2F,
- 0xC7, 0x9C, 0x33, 0x64, 0xBA, 0x04, 0xAD, 0x3A,
- 0x52, 0x54, 0xD6, 0xA5, 0x79, 0xAD, 0x1E, 0x00
- };
- const u8 master_secret[] = {
- 0x4A, 0x1A, 0x51, 0x2C, 0x01, 0x60, 0xBC, 0x02,
- 0x3C, 0xCF, 0xBC, 0x83, 0x3F, 0x03, 0xBC, 0x64,
- 0x88, 0xC1, 0x31, 0x2F, 0x0B, 0xA9, 0xA2, 0x77,
- 0x16, 0xA8, 0xD8, 0xE8, 0xBD, 0xC9, 0xD2, 0x29,
- 0x38, 0x4B, 0x7A, 0x85, 0xBE, 0x16, 0x4D, 0x27,
- 0x33, 0xD5, 0x24, 0x79, 0x87, 0xB1, 0xC5, 0xA2
- };
- const u8 key_block[] = {
- 0x59, 0x59, 0xBE, 0x8E, 0x41, 0x3A, 0x77, 0x74,
- 0x8B, 0xB2, 0xE5, 0xD3, 0x60, 0xAC, 0x4D, 0x35,
- 0xDF, 0xFB, 0xC8, 0x1E, 0x9C, 0x24, 0x9C, 0x8B,
- 0x0E, 0xC3, 0x1D, 0x72, 0xC8, 0x84, 0x9D, 0x57,
- 0x48, 0x51, 0x2E, 0x45, 0x97, 0x6C, 0x88, 0x70,
- 0xBE, 0x5F, 0x01, 0xD3, 0x64, 0xE7, 0x4C, 0xBB,
- 0x11, 0x24, 0xE3, 0x49, 0xE2, 0x3B, 0xCD, 0xEF,
- 0x7A, 0xB3, 0x05, 0x39, 0x5D, 0x64, 0x8A, 0x44,
- 0x11, 0xB6, 0x69, 0x88, 0x34, 0x2E, 0x8E, 0x29,
- 0xD6, 0x4B, 0x7D, 0x72, 0x17, 0x59, 0x28, 0x05,
- 0xAF, 0xF9, 0xB7, 0xFF, 0x66, 0x6D, 0xA1, 0x96,
- 0x8F, 0x0B, 0x5E, 0x06, 0x46, 0x7A, 0x44, 0x84,
- 0x64, 0xC1, 0xC8, 0x0C, 0x96, 0x44, 0x09, 0x98,
- 0xFF, 0x92, 0xA8, 0xB4, 0xC6, 0x42, 0x28, 0x71
- };
- const u8 sks[] = {
- 0xD6, 0x4B, 0x7D, 0x72, 0x17, 0x59, 0x28, 0x05,
- 0xAF, 0xF9, 0xB7, 0xFF, 0x66, 0x6D, 0xA1, 0x96,
- 0x8F, 0x0B, 0x5E, 0x06, 0x46, 0x7A, 0x44, 0x84,
- 0x64, 0xC1, 0xC8, 0x0C, 0x96, 0x44, 0x09, 0x98,
- 0xFF, 0x92, 0xA8, 0xB4, 0xC6, 0x42, 0x28, 0x71
- };
- const u8 isk[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
- };
- const u8 imck[] = {
- 0x16, 0x15, 0x3C, 0x3F, 0x21, 0x55, 0xEF, 0xD9,
- 0x7F, 0x34, 0xAE, 0xC8, 0x1A, 0x4E, 0x66, 0x80,
- 0x4C, 0xC3, 0x76, 0xF2, 0x8A, 0xA9, 0x6F, 0x96,
- 0xC2, 0x54, 0x5F, 0x8C, 0xAB, 0x65, 0x02, 0xE1,
- 0x18, 0x40, 0x7B, 0x56, 0xBE, 0xEA, 0xA7, 0xC5,
- 0x76, 0x5D, 0x8F, 0x0B, 0xC5, 0x07, 0xC6, 0xB9,
- 0x04, 0xD0, 0x69, 0x56, 0x72, 0x8B, 0x6B, 0xB8,
- 0x15, 0xEC, 0x57, 0x7B
- };
- const u8 msk[] = {
- 0x4D, 0x83, 0xA9, 0xBE, 0x6F, 0x8A, 0x74, 0xED,
- 0x6A, 0x02, 0x66, 0x0A, 0x63, 0x4D, 0x2C, 0x33,
- 0xC2, 0xDA, 0x60, 0x15, 0xC6, 0x37, 0x04, 0x51,
- 0x90, 0x38, 0x63, 0xDA, 0x54, 0x3E, 0x14, 0xB9,
- 0x27, 0x99, 0x18, 0x1E, 0x07, 0xBF, 0x0F, 0x5A,
- 0x5E, 0x3C, 0x32, 0x93, 0x80, 0x8C, 0x6C, 0x49,
- 0x67, 0xED, 0x24, 0xFE, 0x45, 0x40, 0xA0, 0x59,
- 0x5E, 0x37, 0xC2, 0xE9, 0xD0, 0x5D, 0x0A, 0xE3
- };
- const u8 emsk[] = {
- 0x3A, 0xD4, 0xAB, 0xDB, 0x76, 0xB2, 0x7F, 0x3B,
- 0xEA, 0x32, 0x2C, 0x2B, 0x74, 0xF4, 0x28, 0x55,
- 0xEF, 0x2D, 0xBA, 0x78, 0xC9, 0x57, 0x2F, 0x0D,
- 0x06, 0xCD, 0x51, 0x7C, 0x20, 0x93, 0x98, 0xA9,
- 0x76, 0xEA, 0x70, 0x21, 0xD7, 0x0E, 0x25, 0x54,
- 0x97, 0xED, 0xB2, 0x8A, 0xF6, 0xED, 0xFD, 0x0A,
- 0x2A, 0xE7, 0xA1, 0x58, 0x90, 0x10, 0x50, 0x44,
- 0xB3, 0x82, 0x85, 0xDB, 0x06, 0x14, 0xD2, 0xF9
- };
- /* RFC 4851, Appendix B.2 */
- u8 tlv[] = {
- 0x80, 0x0C, 0x00, 0x38, 0x00, 0x01, 0x01, 0x00,
- 0xD8, 0x6A, 0x8C, 0x68, 0x3C, 0x32, 0x31, 0xA8,
- 0x56, 0x63, 0xB6, 0x40, 0x21, 0xFE, 0x21, 0x14,
- 0x4E, 0xE7, 0x54, 0x20, 0x79, 0x2D, 0x42, 0x62,
- 0xC9, 0xBF, 0x53, 0x7F, 0x54, 0xFD, 0xAC, 0x58,
- 0x43, 0x24, 0x6E, 0x30, 0x92, 0x17, 0x6D, 0xCF,
- 0xE6, 0xE0, 0x69, 0xEB, 0x33, 0x61, 0x6A, 0xCC,
- 0x05, 0xC5, 0x5B, 0xB7
- };
- const u8 compound_mac[] = {
- 0x43, 0x24, 0x6E, 0x30, 0x92, 0x17, 0x6D, 0xCF,
- 0xE6, 0xE0, 0x69, 0xEB, 0x33, 0x61, 0x6A, 0xCC,
- 0x05, 0xC5, 0x5B, 0xB7
- };
- u8 buf[512];
- const u8 *simck, *cmk;
- int errors = 0;
-
- printf("EAP-FAST test cases\n");
-
- printf("- T-PRF (SHA1) test case / master_secret\n");
- sha1_t_prf(pac_key, sizeof(pac_key), "PAC to master secret label hash",
- seed, sizeof(seed), buf, sizeof(master_secret));
- if (memcmp(master_secret, buf, sizeof(master_secret)) != 0) {
- printf("T-PRF test - FAILED!\n");
- errors++;
- }
-
- printf("- PRF (TLS, SHA1/MD5) test case / key_block\n");
- tls_prf(master_secret, sizeof(master_secret), "key expansion",
- seed, sizeof(seed), buf, sizeof(key_block));
- if (memcmp(key_block, buf, sizeof(key_block)) != 0) {
- printf("PRF test - FAILED!\n");
- errors++;
- }
-
- printf("- T-PRF (SHA1) test case / IMCK\n");
- sha1_t_prf(sks, sizeof(sks), "Inner Methods Compound Keys",
- isk, sizeof(isk), buf, sizeof(imck));
- if (memcmp(imck, buf, sizeof(imck)) != 0) {
- printf("T-PRF test - FAILED!\n");
- errors++;
- }
-
- simck = imck;
- cmk = imck + 40;
-
- printf("- T-PRF (SHA1) test case / MSK\n");
- sha1_t_prf(simck, 40, "Session Key Generating Function",
- (u8 *) "", 0, buf, sizeof(msk));
- if (memcmp(msk, buf, sizeof(msk)) != 0) {
- printf("T-PRF test - FAILED!\n");
- errors++;
- }
-
- printf("- T-PRF (SHA1) test case / EMSK\n");
- sha1_t_prf(simck, 40, "Extended Session Key Generating Function",
- (u8 *) "", 0, buf, sizeof(msk));
- if (memcmp(emsk, buf, sizeof(emsk)) != 0) {
- printf("T-PRF test - FAILED!\n");
- errors++;
- }
-
- printf("- Compound MAC test case\n");
- memset(tlv + sizeof(tlv) - 20, 0, 20);
- hmac_sha1(cmk, 20, tlv, sizeof(tlv), tlv + sizeof(tlv) - 20);
- if (memcmp(tlv + sizeof(tlv) - 20, compound_mac, sizeof(compound_mac))
- != 0) {
- printf("Compound MAC test - FAILED!\n");
- errors++;
- }
-
- return errors;
-}
-
-
-static u8 key0[] =
-{
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
- 0x0b, 0x0b, 0x0b, 0x0b
-};
-static u8 data0[] = "Hi There";
-static u8 prf0[] =
-{
- 0xbc, 0xd4, 0xc6, 0x50, 0xb3, 0x0b, 0x96, 0x84,
- 0x95, 0x18, 0x29, 0xe0, 0xd7, 0x5f, 0x9d, 0x54,
- 0xb8, 0x62, 0x17, 0x5e, 0xd9, 0xf0, 0x06, 0x06,
- 0xe1, 0x7d, 0x8d, 0xa3, 0x54, 0x02, 0xff, 0xee,
- 0x75, 0xdf, 0x78, 0xc3, 0xd3, 0x1e, 0x0f, 0x88,
- 0x9f, 0x01, 0x21, 0x20, 0xc0, 0x86, 0x2b, 0xeb,
- 0x67, 0x75, 0x3e, 0x74, 0x39, 0xae, 0x24, 0x2e,
- 0xdb, 0x83, 0x73, 0x69, 0x83, 0x56, 0xcf, 0x5a
-};
-
-static u8 key1[] = "Jefe";
-static u8 data1[] = "what do ya want for nothing?";
-static u8 prf1[] =
-{
- 0x51, 0xf4, 0xde, 0x5b, 0x33, 0xf2, 0x49, 0xad,
- 0xf8, 0x1a, 0xeb, 0x71, 0x3a, 0x3c, 0x20, 0xf4,
- 0xfe, 0x63, 0x14, 0x46, 0xfa, 0xbd, 0xfa, 0x58,
- 0x24, 0x47, 0x59, 0xae, 0x58, 0xef, 0x90, 0x09,
- 0xa9, 0x9a, 0xbf, 0x4e, 0xac, 0x2c, 0xa5, 0xfa,
- 0x87, 0xe6, 0x92, 0xc4, 0x40, 0xeb, 0x40, 0x02,
- 0x3e, 0x7b, 0xab, 0xb2, 0x06, 0xd6, 0x1d, 0xe7,
- 0xb9, 0x2f, 0x41, 0x52, 0x90, 0x92, 0xb8, 0xfc
-};
-
-
-static u8 key2[] =
-{
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa
-};
-static u8 data2[] =
-{
- 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
- 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
- 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
- 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
- 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
- 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
- 0xdd, 0xdd
-};
-static u8 prf2[] =
-{
- 0xe1, 0xac, 0x54, 0x6e, 0xc4, 0xcb, 0x63, 0x6f,
- 0x99, 0x76, 0x48, 0x7b, 0xe5, 0xc8, 0x6b, 0xe1,
- 0x7a, 0x02, 0x52, 0xca, 0x5d, 0x8d, 0x8d, 0xf1,
- 0x2c, 0xfb, 0x04, 0x73, 0x52, 0x52, 0x49, 0xce,
- 0x9d, 0xd8, 0xd1, 0x77, 0xea, 0xd7, 0x10, 0xbc,
- 0x9b, 0x59, 0x05, 0x47, 0x23, 0x91, 0x07, 0xae,
- 0xf7, 0xb4, 0xab, 0xd4, 0x3d, 0x87, 0xf0, 0xa6,
- 0x8f, 0x1c, 0xbd, 0x9e, 0x2b, 0x6f, 0x76, 0x07
-};
-
-
-struct passphrase_test {
- char *passphrase;
- char *ssid;
- char psk[32];
-};
-
-static struct passphrase_test passphrase_tests[] =
-{
- {
- "password",
- "IEEE",
- {
- 0xf4, 0x2c, 0x6f, 0xc5, 0x2d, 0xf0, 0xeb, 0xef,
- 0x9e, 0xbb, 0x4b, 0x90, 0xb3, 0x8a, 0x5f, 0x90,
- 0x2e, 0x83, 0xfe, 0x1b, 0x13, 0x5a, 0x70, 0xe2,
- 0x3a, 0xed, 0x76, 0x2e, 0x97, 0x10, 0xa1, 0x2e
- }
- },
- {
- "ThisIsAPassword",
- "ThisIsASSID",
- {
- 0x0d, 0xc0, 0xd6, 0xeb, 0x90, 0x55, 0x5e, 0xd6,
- 0x41, 0x97, 0x56, 0xb9, 0xa1, 0x5e, 0xc3, 0xe3,
- 0x20, 0x9b, 0x63, 0xdf, 0x70, 0x7d, 0xd5, 0x08,
- 0xd1, 0x45, 0x81, 0xf8, 0x98, 0x27, 0x21, 0xaf
- }
- },
- {
- "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
- "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ",
- {
- 0xbe, 0xcb, 0x93, 0x86, 0x6b, 0xb8, 0xc3, 0x83,
- 0x2c, 0xb7, 0x77, 0xc2, 0xf5, 0x59, 0x80, 0x7c,
- 0x8c, 0x59, 0xaf, 0xcb, 0x6e, 0xae, 0x73, 0x48,
- 0x85, 0x00, 0x13, 0x00, 0xa9, 0x81, 0xcc, 0x62
- }
- },
-};
-
-#define NUM_PASSPHRASE_TESTS \
-(sizeof(passphrase_tests) / sizeof(passphrase_tests[0]))
-
-
-int main(int argc, char *argv[])
-{
- u8 res[512];
- int ret = 0;
- unsigned int i;
-
- printf("PRF-SHA1 test cases:\n");
-
- sha1_prf(key0, sizeof(key0), "prefix", data0, sizeof(data0) - 1,
- res, sizeof(prf0));
- if (memcmp(res, prf0, sizeof(prf0)) == 0)
- printf("Test case 0 - OK\n");
- else {
- printf("Test case 0 - FAILED!\n");
- ret++;
- }
-
- sha1_prf(key1, sizeof(key1) - 1, "prefix", data1, sizeof(data1) - 1,
- res, sizeof(prf1));
- if (memcmp(res, prf1, sizeof(prf1)) == 0)
- printf("Test case 1 - OK\n");
- else {
- printf("Test case 1 - FAILED!\n");
- ret++;
- }
-
- sha1_prf(key2, sizeof(key2), "prefix", data2, sizeof(data2),
- res, sizeof(prf2));
- if (memcmp(res, prf2, sizeof(prf2)) == 0)
- printf("Test case 2 - OK\n");
- else {
- printf("Test case 2 - FAILED!\n");
- ret++;
- }
-
- ret += test_eap_fast();
-
- printf("PBKDF2-SHA1 Passphrase test cases:\n");
- for (i = 0; i < NUM_PASSPHRASE_TESTS; i++) {
- u8 psk[32];
- struct passphrase_test *test = &passphrase_tests[i];
- pbkdf2_sha1(test->passphrase,
- test->ssid, strlen(test->ssid),
- 4096, psk, 32);
- if (memcmp(psk, test->psk, 32) == 0)
- printf("Test case %d - OK\n", i);
- else {
- printf("Test case %d - FAILED!\n", i);
- ret++;
- }
- }
-
- return ret;
-}
diff --git a/contrib/wpa/wpa_supplicant/tests/test_sha256.c b/contrib/wpa/wpa_supplicant/tests/test_sha256.c
deleted file mode 100644
index 7dc460d..0000000
--- a/contrib/wpa/wpa_supplicant/tests/test_sha256.c
+++ /dev/null
@@ -1,331 +0,0 @@
-/*
- * Test program for SHA256
- * Copyright (c) 2006, Jouni Malinen <j@w1.fi>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
- */
-
-#include "includes.h"
-
-#include "common.h"
-#include "sha256.h"
-#include "crypto.h"
-
-struct {
- char *data;
- u8 hash[32];
-} tests[] = {
- {
- "abc",
- {
- 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea,
- 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23,
- 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c,
- 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad
- }
- },
- {
- "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
- {
- 0x24, 0x8d, 0x6a, 0x61, 0xd2, 0x06, 0x38, 0xb8,
- 0xe5, 0xc0, 0x26, 0x93, 0x0c, 0x3e, 0x60, 0x39,
- 0xa3, 0x3c, 0xe4, 0x59, 0x64, 0xff, 0x21, 0x67,
- 0xf6, 0xec, 0xed, 0xd4, 0x19, 0xdb, 0x06, 0xc1
- }
- }
-};
-
-struct hmac_test {
- u8 key[80];
- size_t key_len;
- u8 data[128];
- size_t data_len;
- u8 hash[32];
-} hmac_tests[] = {
- /* draft-ietf-ipsec-ciph-sha-256-01.txt */
- {
- {
- 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
- 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
- 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
- 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20
- },
- 32,
- "abc", 3,
- {
- 0xa2, 0x1b, 0x1f, 0x5d, 0x4c, 0xf4, 0xf7, 0x3a,
- 0x4d, 0xd9, 0x39, 0x75, 0x0f, 0x7a, 0x06, 0x6a,
- 0x7f, 0x98, 0xcc, 0x13, 0x1c, 0xb1, 0x6a, 0x66,
- 0x92, 0x75, 0x90, 0x21, 0xcf, 0xab, 0x81, 0x81
- }
- },
- {
- {
- 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
- 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
- 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
- 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20
- },
- 32,
- "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
- 56,
- {
- 0x10, 0x4f, 0xdc, 0x12, 0x57, 0x32, 0x8f, 0x08,
- 0x18, 0x4b, 0xa7, 0x31, 0x31, 0xc5, 0x3c, 0xae,
- 0xe6, 0x98, 0xe3, 0x61, 0x19, 0x42, 0x11, 0x49,
- 0xea, 0x8c, 0x71, 0x24, 0x56, 0x69, 0x7d, 0x30
- }
- },
- {
- {
- 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
- 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
- 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
- 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20
- },
- 32,
- "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
- "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
- 112,
- {
- 0x47, 0x03, 0x05, 0xfc, 0x7e, 0x40, 0xfe, 0x34,
- 0xd3, 0xee, 0xb3, 0xe7, 0x73, 0xd9, 0x5a, 0xab,
- 0x73, 0xac, 0xf0, 0xfd, 0x06, 0x04, 0x47, 0xa5,
- 0xeb, 0x45, 0x95, 0xbf, 0x33, 0xa9, 0xd1, 0xa3
- }
- },
- {
- {
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b
- },
- 32,
- "Hi There",
- 8,
- {
- 0x19, 0x8a, 0x60, 0x7e, 0xb4, 0x4b, 0xfb, 0xc6,
- 0x99, 0x03, 0xa0, 0xf1, 0xcf, 0x2b, 0xbd, 0xc5,
- 0xba, 0x0a, 0xa3, 0xf3, 0xd9, 0xae, 0x3c, 0x1c,
- 0x7a, 0x3b, 0x16, 0x96, 0xa0, 0xb6, 0x8c, 0xf7
- }
- },
- {
- "Jefe",
- 4,
- "what do ya want for nothing?",
- 28,
- {
- 0x5b, 0xdc, 0xc1, 0x46, 0xbf, 0x60, 0x75, 0x4e,
- 0x6a, 0x04, 0x24, 0x26, 0x08, 0x95, 0x75, 0xc7,
- 0x5a, 0x00, 0x3f, 0x08, 0x9d, 0x27, 0x39, 0x83,
- 0x9d, 0xec, 0x58, 0xb9, 0x64, 0xec, 0x38, 0x43
- }
- },
- {
- {
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa
- },
- 32,
- {
- 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
- 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
- 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
- 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
- 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
- 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
- 0xdd, 0xdd
- },
- 50,
- {
- 0xcd, 0xcb, 0x12, 0x20, 0xd1, 0xec, 0xcc, 0xea,
- 0x91, 0xe5, 0x3a, 0xba, 0x30, 0x92, 0xf9, 0x62,
- 0xe5, 0x49, 0xfe, 0x6c, 0xe9, 0xed, 0x7f, 0xdc,
- 0x43, 0x19, 0x1f, 0xbd, 0xe4, 0x5c, 0x30, 0xb0
- }
- },
- {
- {
- 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
- 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
- 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
- 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
- 0x21, 0x22, 0x23, 0x24, 0x25
- },
- 37,
- {
- 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
- 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
- 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
- 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
- 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
- 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
- 0xcd, 0xcd
- },
- 50,
- {
- 0xd4, 0x63, 0x3c, 0x17, 0xf6, 0xfb, 0x8d, 0x74,
- 0x4c, 0x66, 0xde, 0xe0, 0xf8, 0xf0, 0x74, 0x55,
- 0x6e, 0xc4, 0xaf, 0x55, 0xef, 0x07, 0x99, 0x85,
- 0x41, 0x46, 0x8e, 0xb4, 0x9b, 0xd2, 0xe9, 0x17
- }
- },
- {
- {
- 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
- 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
- 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
- 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c
- },
- 32,
- "Test With Truncation",
- 20,
- {
- 0x75, 0x46, 0xaf, 0x01, 0x84, 0x1f, 0xc0, 0x9b,
- 0x1a, 0xb9, 0xc3, 0x74, 0x9a, 0x5f, 0x1c, 0x17,
- 0xd4, 0xf5, 0x89, 0x66, 0x8a, 0x58, 0x7b, 0x27,
- 0x00, 0xa9, 0xc9, 0x7c, 0x11, 0x93, 0xcf, 0x42
- }
- },
- {
- {
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa
- },
- 80,
- "Test Using Larger Than Block-Size Key - Hash Key First",
- 54,
- {
- 0x69, 0x53, 0x02, 0x5e, 0xd9, 0x6f, 0x0c, 0x09,
- 0xf8, 0x0a, 0x96, 0xf7, 0x8e, 0x65, 0x38, 0xdb,
- 0xe2, 0xe7, 0xb8, 0x20, 0xe3, 0xdd, 0x97, 0x0e,
- 0x7d, 0xdd, 0x39, 0x09, 0x1b, 0x32, 0x35, 0x2f
- }
- },
- {
- {
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa
- },
- 80,
- "Test Using Larger Than Block-Size Key and Larger Than One "
- "Block-Size Data",
- 73,
- {
- 0x63, 0x55, 0xac, 0x22, 0xe8, 0x90, 0xd0, 0xa3,
- 0xc8, 0x48, 0x1a, 0x5c, 0xa4, 0x82, 0x5b, 0xc8,
- 0x84, 0xd3, 0xe7, 0xa1, 0xff, 0x98, 0xa2, 0xfc,
- 0x2a, 0xc7, 0xd8, 0xe0, 0x64, 0xc3, 0xb2, 0xe6
- }
- }
-};
-
-
-int main(int argc, char *argv[])
-{
-
- unsigned int i;
- u8 hash[32];
- const u8 *addr[2];
- size_t len[2];
- int errors = 0;
-
- for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
- printf("SHA256 test case %d:", i + 1);
-
- addr[0] = (u8 *) tests[i].data;
- len[0] = strlen(tests[i].data);
- sha256_vector(1, addr, len, hash);
- if (memcmp(hash, tests[i].hash, 32) != 0) {
- printf(" FAIL");
- errors++;
- } else
- printf(" OK");
-
- if (len[0]) {
- addr[0] = (u8 *) tests[i].data;
- len[0] = 1;
- addr[1] = (u8 *) tests[i].data + 1;
- len[1] = strlen(tests[i].data) - 1;
- sha256_vector(2, addr, len, hash);
- if (memcmp(hash, tests[i].hash, 32) != 0) {
- printf(" FAIL");
- errors++;
- } else
- printf(" OK");
- }
-
- printf("\n");
- }
-
- for (i = 0; i < sizeof(hmac_tests) / sizeof(hmac_tests[0]); i++) {
- struct hmac_test *t = &hmac_tests[i];
- printf("HMAC-SHA256 test case %d:", i + 1);
-
- hmac_sha256(t->key, t->key_len, t->data, t->data_len, hash);
- if (memcmp(hash, t->hash, 32) != 0) {
- printf(" FAIL");
- errors++;
- } else
- printf(" OK");
-
- addr[0] = t->data;
- len[0] = t->data_len;
- hmac_sha256_vector(t->key, t->key_len, 1, addr, len, hash);
- if (memcmp(hash, t->hash, 32) != 0) {
- printf(" FAIL");
- errors++;
- } else
- printf(" OK");
-
- if (len[0]) {
- addr[0] = t->data;
- len[0] = 1;
- addr[1] = t->data + 1;
- len[1] = t->data_len - 1;
- hmac_sha256_vector(t->key, t->key_len, 2, addr, len,
- hash);
- if (memcmp(hash, t->hash, 32) != 0) {
- printf(" FAIL");
- errors++;
- } else
- printf(" OK");
- }
-
- printf("\n");
- }
-
- printf("Test IEEE 802.11r KDF\n");
- sha256_prf((u8 *) "abc", 3, "KDF test", (u8 *) "data", 4,
- hash, sizeof(hash));
- /* TODO: add proper test case for this */
-
- return errors;
-}
diff --git a/contrib/wpa/wpa_supplicant/tests/test_wpa.c b/contrib/wpa/wpa_supplicant/tests/test_wpa.c
index 74bb5f8..7947137 100644
--- a/contrib/wpa/wpa_supplicant/tests/test_wpa.c
+++ b/contrib/wpa/wpa_supplicant/tests/test_wpa.c
@@ -16,10 +16,10 @@
#include "common.h"
#include "eloop.h"
-#include "ieee802_11_defs.h"
-#include "config.h"
-#include "wpa.h"
-#include "wpa_ie.h"
+#include "common/ieee802_11_defs.h"
+#include "../config.h"
+#include "rsn_supp/wpa.h"
+#include "rsn_supp/wpa_ie.h"
#include "../hostapd/wpa.h"
@@ -51,14 +51,6 @@ struct wpa {
};
-static struct wpa_ssid * supp_get_ssid(void *ctx)
-{
- struct wpa *wpa = ctx;
- wpa_printf(MSG_DEBUG, "SUPP: %s", __func__);
- return &wpa->ssid;
-}
-
-
static int supp_get_bssid(void *ctx, u8 *bssid)
{
struct wpa *wpa = ctx;
@@ -68,7 +60,7 @@ static int supp_get_bssid(void *ctx, u8 *bssid)
}
-static void supp_set_state(void *ctx, wpa_states state)
+static void supp_set_state(void *ctx, enum wpa_states state)
{
wpa_printf(MSG_DEBUG, "SUPP: %s(state=%d)", __func__, state);
}
@@ -151,7 +143,7 @@ static int supp_get_beacon_ie(void *ctx)
}
-static int supp_set_key(void *ctx, wpa_alg alg,
+static int supp_set_key(void *ctx, enum wpa_alg alg,
const u8 *addr, int key_idx, int set_tx,
const u8 *seq, size_t seq_len,
const u8 *key, size_t key_len)
@@ -175,12 +167,6 @@ static int supp_mlme_setprotection(void *ctx, const u8 *addr,
}
-static void supp_cancel_scan(void *ctx)
-{
- wpa_printf(MSG_DEBUG, "SUPP: %s", __func__);
-}
-
-
static void supp_cancel_auth_timeout(void *ctx)
{
wpa_printf(MSG_DEBUG, "SUPP: %s", __func__);
@@ -194,15 +180,14 @@ static int supp_init(struct wpa *wpa)
return -1;
ctx->ctx = wpa;
+ ctx->msg_ctx = wpa;
ctx->set_state = supp_set_state;
- ctx->get_ssid = supp_get_ssid;
ctx->get_bssid = supp_get_bssid;
ctx->ether_send = supp_ether_send;
ctx->get_beacon_ie = supp_get_beacon_ie;
ctx->alloc_eapol = supp_alloc_eapol;
ctx->set_key = supp_set_key;
ctx->mlme_setprotection = supp_mlme_setprotection;
- ctx->cancel_scan = supp_cancel_scan;
ctx->cancel_auth_timeout = supp_cancel_auth_timeout;
wpa->supp = wpa_sm_init(ctx);
if (wpa->supp == NULL) {
@@ -366,7 +351,7 @@ int main(int argc, char *argv[])
wpa_debug_level = 0;
wpa_debug_show_keys = 1;
- if (eloop_init(&wpa)) {
+ if (eloop_init()) {
wpa_printf(MSG_ERROR, "Failed to initialize event loop");
return -1;
}
diff --git a/contrib/wpa/wpa_supplicant/tests/test_x509v3.c b/contrib/wpa/wpa_supplicant/tests/test_x509v3.c
deleted file mode 100644
index c472c8a..0000000
--- a/contrib/wpa/wpa_supplicant/tests/test_x509v3.c
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Testing tool for X.509v3 routines
- * Copyright (c) 2006-2007, Jouni Malinen <j@w1.fi>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
- */
-
-#include "includes.h"
-
-#include "common.h"
-#include "tls/asn1.h"
-#include "tls/x509v3.h"
-
-extern int wpa_debug_level;
-
-
-int main(int argc, char *argv[])
-{
- char *buf;
- size_t len;
- struct x509_certificate *certs = NULL, *last = NULL, *cert;
- int i, reason;
-
- wpa_debug_level = 0;
-
- if (argc < 3 || strcmp(argv[1], "-v") != 0) {
- printf("usage: test_x509v3 -v <cert1.der> <cert2.der> ..\n");
- return -1;
- }
-
- for (i = 2; i < argc; i++) {
- printf("Reading: %s\n", argv[i]);
- buf = os_readfile(argv[i], &len);
- if (buf == NULL) {
- printf("Failed to read '%s'\n", argv[i]);
- return -1;
- }
-
- cert = x509_certificate_parse((u8 *) buf, len);
- if (cert == NULL) {
- printf("Failed to parse X.509 certificate\n");
- return -1;
- }
-
- free(buf);
-
- if (certs == NULL)
- certs = cert;
- else
- last->next = cert;
- last = cert;
- }
-
- printf("\n\nValidating certificate chain\n");
- if (x509_certificate_chain_validate(last, certs, &reason) < 0) {
- printf("\nCertificate chain validation failed: %d\n", reason);
- return -1;
- }
- printf("\nCertificate chain is valid\n");
-
- return 0;
-}
diff --git a/contrib/wpa/wpa_supplicant/tests/test_x509v3_nist.sh b/contrib/wpa/wpa_supplicant/tests/test_x509v3_nist.sh
deleted file mode 100755
index c33e362..0000000
--- a/contrib/wpa/wpa_supplicant/tests/test_x509v3_nist.sh
+++ /dev/null
@@ -1,144 +0,0 @@
-#!/bin/sh
-
-# X.509 Path Validation Test Suite, Version 1.07
-# http://csrc.nist.gov/pki/testing/x509paths_old.html
-# http://csrc.nist.gov/pki/testing/x509tests.tgz
-
-if [ -z "$1" ]; then
- echo "usage: $0 <path to X509tests directory>"
- exit 1
-fi
-
-TESTS=$1
-
-if [ ! -d $TESTS ]; then
- echo "Not a directory: $TESTS"
- exit 1
-fi
-
-X509TEST="./test_x509v3 -v"
-TMPOUT=test_x509v3_nist.out
-
-# TODO: add support for validating CRLs
-
-END="End Certificate "
-ROOT="Trust Anchor "
-ICA="Intermediate Certificate "
-
-SUCCESS=""
-FAILURE=""
-
-function run_test
-{
- NUM=$1
- RES=$2
- shift 2
- $X509TEST "$@" > $TMPOUT.$NUM
- VALRES=$?
- OK=0
- if [ $RES -eq 0 ]; then
- # expecting success
- if [ $VALRES -eq 0 ]; then
- OK=1
- else
- echo "test$NUM failed - expected validation success"
- OK=0
- fi
- else
- # expecting failure
- if [ $VALRES -eq 0 ]; then
- echo "test$NUM failed - expected validation failure"
- OK=0
- else
- REASON=`grep "Certificate chain validation failed: " $TMPOUT.$NUM`
- if [ $? -eq 0 ]; then
- REASONNUM=`echo "$REASON" | colrm 1 37`
- if [ $REASONNUM -eq $RES ]; then
- OK=1
- else
- echo "test$NUM failed - expected validation result $RES; result was $REASONNUM"
- OK=0
- fi
- else
- echo "test$NUM failed - expected validation failure; other type of error detected"
- OK=0
- fi
- fi
- fi
- if [ $OK -eq 1 ]; then
- rm $TMPOUT.$NUM
- SUCCESS="$SUCCESS $NUM"
- else
- FAILURE="$FAILURE $NUM"
- fi
-}
-
-P=$TESTS/test
-
-run_test 1 0 "${P}1/${END}CP.01.01.crt" "${P}1/${ROOT}CP.01.01.crt"
-run_test 2 1 "${P}2/${END}CP.01.02.crt" "${P}2/${ICA}CP.01.02.crt" "${P}2/${ROOT}CP.01.01.crt"
-run_test 3 1 "${P}3/${END}CP.01.03.crt" "${P}3/${ICA}CP.01.03.crt" "${P}3/${ROOT}CP.01.01.crt"
-run_test 4 0 "${P}4/${END}CP.02.01.crt" "${P}4/${ICA}2 CP.02.01.crt" "${P}4/${ICA}1 CP.02.01.crt" "${P}4/${ROOT}CP.01.01.crt"
-run_test 5 4 "${P}5/${END}CP.02.02.crt" "${P}5/${ICA}CP.02.02.crt" "${P}5/${ROOT}CP.01.01.crt"
-run_test 6 4 "${P}6/${END}CP.02.03.crt" "${P}6/${ICA}CP.02.03.crt" "${P}6/${ROOT}CP.01.01.crt"
-run_test 7 0 "${P}7/${END}CP.02.04.crt" "${P}7/${ICA}CP.02.04.crt" "${P}7/${ROOT}CP.01.01.crt"
-run_test 8 4 "${P}8/${END}CP.02.05.crt" "${P}8/${ICA}CP.02.05.crt" "${P}8/${ROOT}CP.01.01.crt"
-run_test 9 4 "${P}9/${END}CP.03.01.crt" "${P}9/${ICA}CP.03.01.crt" "${P}9/${ROOT}CP.01.01.crt"
-run_test 10 4 "${P}10/${END}CP.03.02.crt" "${P}10/${ICA}CP.03.02.crt" "${P}10/${ROOT}CP.01.01.crt"
-run_test 11 4 "${P}11/${END}CP.03.03.crt" "${P}11/${ICA}CP.03.03.crt" "${P}11/${ROOT}CP.01.01.crt"
-run_test 12 0 "${P}12/${END}CP.03.04.crt" "${P}12/${ICA}CP.03.04.crt" "${P}12/${ROOT}CP.01.01.crt"
-run_test 13 5 "${P}13/${END}CP.04.01.crt" "${P}13/${ICA}CP.04.01.crt" "${P}13/${ROOT}CP.01.01.crt"
-run_test 14 5 "${P}14/${END}CP.04.02.crt" "${P}14/${ICA}CP.04.02.crt" "${P}14/${ROOT}CP.01.01.crt"
-run_test 15 0 "${P}15/${END}CP.04.03.crt" "${P}15/${ICA}CP.04.03.crt" "${P}15/${ROOT}CP.01.01.crt"
-run_test 16 0 "${P}16/${END}CP.04.04.crt" "${P}16/${ICA}CP.04.04.crt" "${P}16/${ROOT}CP.01.01.crt"
-run_test 17 0 "${P}17/${END}CP.04.05.crt" "${P}17/${ICA}CP.04.05.crt" "${P}17/${ROOT}CP.01.01.crt"
-run_test 18 0 "${P}18/${END}CP.04.06.crt" "${P}18/${ICA}CP.04.06.crt" "${P}18/${ROOT}CP.01.01.crt"
-run_test 19 1 "${P}19/${END}CP.05.01.crt" "${P}19/${ICA}CP.05.01.crt" "${P}19/${ROOT}CP.01.01.crt"
-run_test 20 3 "${P}20/${END}CP.06.01.crt" "${P}20/${ICA}CP.06.01.crt" "${P}20/${ROOT}CP.01.01.crt"
-run_test 21 3 "${P}21/${END}CP.06.02.crt" "${P}21/${ICA}CP.06.02.crt" "${P}21/${ROOT}CP.01.01.crt"
-run_test 22 1 "${P}22/${END}IC.01.01.crt" "${P}22/${ICA}IC.01.01.crt" "${P}22/${ROOT}CP.01.01.crt"
-run_test 23 1 "${P}23/${END}IC.02.01.crt" "${P}23/${ICA}IC.02.01.crt" "${P}23/${ROOT}CP.01.01.crt"
-run_test 24 0 "${P}24/${END}IC.02.02.crt" "${P}24/${ICA}IC.02.02.crt" "${P}24/${ROOT}CP.01.01.crt"
-run_test 25 1 "${P}25/${END}IC.02.03.crt" "${P}25/${ICA}IC.02.03.crt" "${P}25/${ROOT}CP.01.01.crt"
-run_test 26 0 "${P}26/${END}IC.02.04.crt" "${P}26/${ICA}IC.02.04.crt" "${P}26/${ROOT}CP.01.01.crt"
-run_test 27 0 "${P}27/${END}IC.04.01.crt" "${P}27/${ICA}IC.04.01.crt" "${P}27/${ROOT}CP.01.01.crt"
-run_test 28 1 "${P}28/${END}IC.05.01.crt" "${P}28/${ICA}IC.05.01.crt" "${P}28/${ROOT}CP.01.01.crt"
-run_test 29 1 "${P}29/${END}IC.05.02.crt" "${P}29/${ICA}IC.05.02.crt" "${P}29/${ROOT}CP.01.01.crt"
-run_test 30 0 "${P}30/${END}IC.05.03.crt" "${P}30/${ICA}IC.05.03.crt" "${P}30/${ROOT}CP.01.01.crt"
-run_test 31 1 "${P}31/${END}IC.06.01.crt" "${P}31/${ICA}IC.06.01.crt" "${P}31/${ROOT}CP.01.01.crt"
-run_test 32 1 "${P}32/${END}IC.06.02.crt" "${P}32/${ICA}IC.06.02.crt" "${P}32/${ROOT}CP.01.01.crt"
-run_test 33 0 "${P}33/${END}IC.06.03.crt" "${P}33/${ICA}IC.06.03.crt" "${P}33/${ROOT}CP.01.01.crt"
-run_test 34 0 "${P}34/${END}PP.01.01.crt" "${P}34/${ICA}PP.01.01.crt" "${P}34/${ROOT}CP.01.01.crt"
-run_test 35 0 "${P}35/${END}PP.01.02.crt" "${P}35/${ICA}PP.01.02.crt" "${P}35/${ROOT}CP.01.01.crt"
-run_test 36 0 "${P}36/${END}PP.01.03.crt" "${P}36/${ICA}2 PP.01.03.crt" "${P}36/${ICA}1 PP.01.03.crt" "${P}36/${ROOT}CP.01.01.crt"
-run_test 37 0 "${P}37/${END}PP.01.04.crt" "${P}37/${ICA}2 PP.01.04.crt" "${P}37/${ICA}1 PP.01.04.crt" "${P}37/${ROOT}CP.01.01.crt"
-run_test 38 0 "${P}38/${END}PP.01.05.crt" "${P}38/${ICA}2 PP.01.05.crt" "${P}38/${ICA}1 PP.01.05.crt" "${P}38/${ROOT}CP.01.01.crt"
-run_test 39 0 "${P}39/${END}PP.01.06.crt" "${P}39/${ICA}3 PP.01.06.crt" "${P}39/${ICA}2 PP.01.06.crt" "${P}39/${ICA}1 PP.01.06.crt" "${P}39/${ROOT}CP.01.01.crt"
-run_test 40 0 "${P}40/${END}PP.01.07.crt" "${P}40/${ICA}3 PP.01.07.crt" "${P}40/${ICA}2 PP.01.07.crt" "${P}40/${ICA}1 PP.01.07.crt" "${P}40/${ROOT}CP.01.01.crt"
-run_test 41 0 "${P}41/${END}PP.01.08.crt" "${P}41/${ICA}3 PP.01.08.crt" "${P}41/${ICA}2 PP.01.08.crt" "${P}41/${ICA}1 PP.01.08.crt" "${P}41/${ROOT}CP.01.01.crt"
-run_test 42 0 "${P}42/${END}PP.01.09.crt" "${P}42/${ICA}4 PP.01.09.crt" "${P}42/${ICA}3 PP.01.09.crt" "${P}42/${ICA}2 PP.01.09.crt" "${P}42/${ICA}1 PP.01.09.crt" "${P}42/${ROOT}CP.01.01.crt"
-run_test 43 0 "${P}43/${END}PP.06.01.crt" "${P}43/${ICA}4 PP.06.01.crt" "${P}43/${ICA}3 PP.06.01.crt" "${P}43/${ICA}2 PP.06.01.crt" "${P}43/${ICA}1 PP.06.01.crt" "${P}43/${ROOT}CP.01.01.crt"
-run_test 44 0 "${P}44/${END}PP.06.02.crt" "${P}44/${ICA}4 PP.06.02.crt" "${P}44/${ICA}3 PP.06.02.crt" "${P}44/${ICA}2 PP.06.02.crt" "${P}44/${ICA}1 PP.06.02.crt" "${P}44/${ROOT}CP.01.01.crt"
-run_test 45 0 "${P}45/${END}PP.06.03.crt" "${P}45/${ICA}4 PP.06.03.crt" "${P}45/${ICA}3 PP.06.03.crt" "${P}45/${ICA}2 PP.06.03.crt" "${P}45/${ICA}1 PP.06.03.crt" "${P}45/${ROOT}CP.01.01.crt"
-run_test 46 0 "${P}46/${END}PP.06.04.crt" "${P}46/${ICA}4 PP.06.04.crt" "${P}46/${ICA}3 PP.06.04.crt" "${P}46/${ICA}2 PP.06.04.crt" "${P}46/${ICA}1 PP.06.04.crt" "${P}46/${ROOT}CP.01.01.crt"
-run_test 47 0 "${P}47/${END}PP.06.05.crt" "${P}47/${ICA}4 PP.06.05.crt" "${P}47/${ICA}3 PP.06.05.crt" "${P}47/${ICA}2 PP.06.05.crt" "${P}47/${ICA}1 PP.06.05.crt" "${P}47/${ROOT}CP.01.01.crt"
-run_test 48 0 "${P}48/${END}PP.08.01.crt" "${P}48/${ICA}PP.08.01.crt" "${P}48/${ROOT}CP.01.01.crt"
-run_test 49 0 "${P}49/${END}PP.08.02.crt" "${P}49/${ICA}PP.08.02.crt" "${P}49/${ROOT}CP.01.01.crt"
-run_test 50 0 "${P}50/${END}PP.08.03.crt" "${P}50/${ICA}PP.08.03.crt" "${P}50/${ROOT}CP.01.01.crt"
-run_test 51 0 "${P}51/${END}PP.08.04.crt" "${P}51/${ICA}PP.08.04.crt" "${P}51/${ROOT}CP.01.01.crt"
-run_test 52 0 "${P}52/${END}PP.08.05.crt" "${P}52/${ICA}PP.08.05.crt" "${P}52/${ROOT}CP.01.01.crt"
-run_test 53 0 "${P}53/${END}PP.08.06.crt" "${P}53/${ICA}PP.08.06.crt" "${P}53/${ROOT}CP.01.01.crt"
-run_test 54 1 "${P}54/${END}PL.01.01.crt" "${P}54/${ICA}2 PL.01.01.crt" "${P}54/${ICA}1 PL.01.01.crt" "${P}54/${ROOT}CP.01.01.crt"
-run_test 55 1 "${P}55/${END}PL.01.02.crt" "${P}55/${ICA}2 PL.01.02.crt" "${P}55/${ICA}1 PL.01.02.crt" "${P}55/${ROOT}CP.01.01.crt"
-run_test 56 0 "${P}56/${END}PL.01.03.crt" "${P}56/${ICA}PL.01.03.crt" "${P}56/${ROOT}CP.01.01.crt"
-run_test 57 0 "${P}57/${END}PL.01.04.crt" "${P}57/${ICA}PL.01.04.crt" "${P}57/${ROOT}CP.01.01.crt"
-run_test 58 1 "${P}58/${END}PL.01.05.crt" "${P}58/${ICA}3 PL.01.05.crt" "${P}58/${ICA}2 PL.01.05.crt" "${P}58/${ICA}1 PL.01.05.crt" "${P}58/${ROOT}CP.01.01.crt"
-run_test 59 1 "${P}59/${END}PL.01.06.crt" "${P}59/${ICA}3 PL.01.06.crt" "${P}59/${ICA}2 PL.01.06.crt" "${P}59/${ICA}1 PL.01.06.crt" "${P}59/${ROOT}CP.01.01.crt"
-run_test 60 1 "${P}60/${END}PL.01.07.crt" "${P}60/${ICA}4 PL.01.07.crt" "${P}60/${ICA}3 PL.01.07.crt" "${P}60/${ICA}2 PL.01.07.crt" "${P}60/${ICA}1 PL.01.07.crt" "${P}60/${ROOT}CP.01.01.crt"
-run_test 61 1 "${P}61/${END}PL.01.08.crt" "${P}61/${ICA}4 PL.01.08.crt" "${P}61/${ICA}3 PL.01.08.crt" "${P}61/${ICA}2 PL.01.08.crt" "${P}61/${ICA}1 PL.01.08.crt" "${P}61/${ROOT}CP.01.01.crt"
-run_test 62 0 "${P}62/${END}PL.01.09.crt" "${P}62/${ICA}4 PL.01.09.crt" "${P}62/${ICA}3 PL.01.09.crt" "${P}62/${ICA}2 PL.01.09.crt" "${P}62/${ICA}1 PL.01.09.crt" "${P}62/${ROOT}CP.01.01.crt"
-run_test 63 0 "${P}63/${END}PL.01.10.crt" "${P}63/${ICA}4 PL.01.10.crt" "${P}63/${ICA}3 PL.01.10.crt" "${P}63/${ICA}2 PL.01.10.crt" "${P}63/${ICA}1 PL.01.10.crt" "${P}63/${ROOT}CP.01.01.crt"
-
-
-echo "Successful tests:$SUCCESS"
-echo "Failed tests:$FAILURE"
diff --git a/contrib/wpa/wpa_supplicant/tests/test_x509v3_nist2.sh b/contrib/wpa/wpa_supplicant/tests/test_x509v3_nist2.sh
deleted file mode 100755
index 0be29b7..0000000
--- a/contrib/wpa/wpa_supplicant/tests/test_x509v3_nist2.sh
+++ /dev/null
@@ -1,165 +0,0 @@
-#!/bin/sh
-
-# Public Key Interoperability Test Suite (PKITS)
-# http://csrc.nist.gov/pki/testing/x509paths.html
-# http://csrc.nist.gov/pki/testing/PKITS_data.zip
-
-if [ -z "$1" ]; then
- echo "usage: $0 <path to root test directory>"
- exit 1
-fi
-
-TESTS=$1
-
-if [ ! -d $TESTS ]; then
- echo "Not a directory: $TESTS"
- exit 1
-fi
-
-X509TEST="$PWD/test_x509v3 -v"
-TMPOUT="$PWD/test_x509v3_nist2.out"
-
-# TODO: add support for validating CRLs
-
-SUCCESS=""
-FAILURE=""
-
-function run_test
-{
- NUM=$1
- RES=$2
- shift 2
- $X509TEST "$@" TrustAnchorRootCertificate.crt > $TMPOUT.$NUM
- VALRES=$?
- OK=0
- if [ $RES -eq 0 ]; then
- # expecting success
- if [ $VALRES -eq 0 ]; then
- OK=1
- else
- echo "$NUM failed - expected validation success"
- OK=0
- fi
- else
- # expecting failure
- if [ $VALRES -eq 0 ]; then
- echo "$NUM failed - expected validation failure"
- OK=0
- else
- REASON=`grep "Certificate chain validation failed: " $TMPOUT.$NUM`
- if [ $? -eq 0 ]; then
- REASONNUM=`echo "$REASON" | colrm 1 37`
- if [ $REASONNUM -eq $RES ]; then
- OK=1
- else
- echo "$NUM failed - expected validation result $RES; result was $REASONNUM"
- OK=0
- fi
- else
- echo "$NUM failed - expected validation failure; other type of error detected"
- OK=0
- fi
- fi
- fi
- if [ $OK -eq 1 ]; then
- rm $TMPOUT.$NUM
- SUCCESS="$SUCCESS $NUM"
- else
- FAILURE="$FAILURE $NUM"
- fi
-}
-
-pushd $TESTS/certs
-
-run_test 4.1.1 0 ValidCertificatePathTest1EE.crt GoodCACert.crt
-run_test 4.1.2 1 InvalidCASignatureTest2EE.crt BadSignedCACert.crt
-run_test 4.1.3 1 InvalidEESignatureTest3EE.crt GoodCACert.crt
-
-run_test 4.2.1 4 InvalidCAnotBeforeDateTest1EE.crt BadnotBeforeDateCACert.crt
-run_test 4.2.2 4 InvalidEEnotBeforeDateTest2EE.crt GoodCACert.crt
-run_test 4.2.3 0 Validpre2000UTCnotBeforeDateTest3EE.crt GoodCACert.crt
-run_test 4.2.4 0 ValidGeneralizedTimenotBeforeDateTest4EE.crt GoodCACert.crt
-run_test 4.2.5 4 InvalidCAnotAfterDateTest5EE.crt BadnotAfterDateCACert.crt
-run_test 4.2.6 4 InvalidEEnotAfterDateTest6EE.crt GoodCACert.crt
-run_test 4.2.7 4 Invalidpre2000UTCEEnotAfterDateTest7EE.crt GoodCACert.crt
-run_test 4.2.8 0 ValidGeneralizedTimenotAfterDateTest8EE.crt GoodCACert.crt
-
-run_test 4.3.1 5 InvalidNameChainingTest1EE.crt GoodCACert.crt
-run_test 4.3.2 5 InvalidNameChainingOrderTest2EE.crt NameOrderingCACert.crt
-run_test 4.3.3 0 ValidNameChainingWhitespaceTest3EE.crt GoodCACert.crt
-run_test 4.3.4 0 ValidNameChainingWhitespaceTest4EE.crt GoodCACert.crt
-run_test 4.3.5 0 ValidNameChainingCapitalizationTest5EE.crt GoodCACert.crt
-run_test 4.3.6 0 ValidNameUIDsTest6EE.crt UIDCACert.crt
-run_test 4.3.7 0 ValidRFC3280MandatoryAttributeTypesTest7EE.crt RFC3280MandatoryAttributeTypesCACert.crt
-run_test 4.3.8 0 ValidRFC3280OptionalAttributeTypesTest8EE.crt RFC3280OptionalAttributeTypesCACert.crt
-run_test 4.3.9 0 ValidUTF8StringEncodedNamesTest9EE.crt UTF8StringEncodedNamesCACert.crt
-run_test 4.3.10 0 ValidRolloverfromPrintableStringtoUTF8StringTest10EE.crt RolloverfromPrintableStringtoUTF8StringCACert.crt
-run_test 4.3.11 0 ValidUTF8StringCaseInsensitiveMatchTest11EE.crt UTF8StringCaseInsensitiveMatchCACert.crt
-
-run_test 4.4.1 1 InvalidMissingCRLTest1EE.crt NoCRLCACert.crt
-# skip rest of 4.4.x tests since CRLs are not yet supported
-
-run_test 4.5.1 0 ValidBasicSelfIssuedOldWithNewTest1EE.crt BasicSelfIssuedNewKeyOldWithNewCACert.crt BasicSelfIssuedNewKeyCACert.crt
-run_test 4.5.2 3 InvalidBasicSelfIssuedOldWithNewTest2EE.crt BasicSelfIssuedNewKeyOldWithNewCACert.crt BasicSelfIssuedNewKeyCACert.crt
-run_test 4.5.3 0 ValidBasicSelfIssuedNewWithOldTest3EE.crt BasicSelfIssuedOldKeyNewWithOldCACert.crt BasicSelfIssuedOldKeyCACert.crt
-run_test 4.5.4 0 ValidBasicSelfIssuedNewWithOldTest4EE.crt BasicSelfIssuedOldKeyNewWithOldCACert.crt BasicSelfIssuedOldKeyCACert.crt
-run_test 4.5.5 3 InvalidBasicSelfIssuedNewWithOldTest5EE.crt BasicSelfIssuedOldKeyNewWithOldCACert.crt BasicSelfIssuedOldKeyCACert.crt
-run_test 4.5.6 0 ValidBasicSelfIssuedCRLSigningKeyTest6EE.crt BasicSelfIssuedCRLSigningKeyCRLCert.crt BasicSelfIssuedCRLSigningKeyCACert.crt
-run_test 4.5.7 3 InvalidBasicSelfIssuedCRLSigningKeyTest7EE.crt BasicSelfIssuedCRLSigningKeyCRLCert.crt BasicSelfIssuedCRLSigningKeyCACert.crt
-run_test 4.5.8 1 InvalidBasicSelfIssuedCRLSigningKeyTest8EE.crt BasicSelfIssuedCRLSigningKeyCRLCert.crt BasicSelfIssuedCRLSigningKeyCACert.crt
-
-run_test 4.6.1 1 InvalidMissingbasicConstraintsTest1EE.crt MissingbasicConstraintsCACert.crt
-run_test 4.6.2 1 InvalidcAFalseTest2EE.crt basicConstraintsCriticalcAFalseCACert.crt
-run_test 4.6.3 1 InvalidcAFalseTest3EE.crt basicConstraintsNotCriticalcAFalseCACert.crt
-run_test 4.6.4 0 ValidbasicConstraintsNotCriticalTest4EE.crt basicConstraintsNotCriticalCACert.crt
-run_test 4.6.5 1 InvalidpathLenConstraintTest5EE.crt pathLenConstraint0subCACert.crt pathLenConstraint0CACert.crt
-run_test 4.6.6 1 InvalidpathLenConstraintTest6EE.crt pathLenConstraint0subCACert.crt pathLenConstraint0CACert.crt
-run_test 4.6.7 0 ValidpathLenConstraintTest7EE.crt pathLenConstraint0CACert.crt
-run_test 4.6.8 0 ValidpathLenConstraintTest8EE.crt pathLenConstraint0CACert.crt
-run_test 4.6.9 1 InvalidpathLenConstraintTest9EE.crt pathLenConstraint6subsubCA00Cert.crt pathLenConstraint6subCA0Cert.crt pathLenConstraint6CACert.crt
-run_test 4.6.10 1 InvalidpathLenConstraintTest10EE.crt pathLenConstraint6subsubCA00Cert.crt pathLenConstraint6subCA0Cert.crt pathLenConstraint6CACert.crt
-run_test 4.6.11 1 InvalidpathLenConstraintTest11EE.crt pathLenConstraint6subsubsubCA11XCert.crt pathLenConstraint6subsubCA11Cert.crt pathLenConstraint6subCA1Cert.crt pathLenConstraint6CACert.crt
-run_test 4.6.12 1 InvalidpathLenConstraintTest12EE.crt pathLenConstraint6subsubsubCA11XCert.crt pathLenConstraint6subsubCA11Cert.crt pathLenConstraint6subCA1Cert.crt pathLenConstraint6CACert.crt
-run_test 4.6.13 0 ValidpathLenConstraintTest13EE.crt pathLenConstraint6subsubsubCA41XCert.crt pathLenConstraint6subsubCA41Cert.crt pathLenConstraint6subCA4Cert.crt pathLenConstraint6CACert.crt
-run_test 4.6.14 0 ValidpathLenConstraintTest14EE.crt pathLenConstraint6subsubsubCA41XCert.crt pathLenConstraint6subsubCA41Cert.crt pathLenConstraint6subCA4Cert.crt pathLenConstraint6CACert.crt
-run_test 4.6.15 0 ValidSelfIssuedpathLenConstraintTest15EE.crt pathLenConstraint0SelfIssuedCACert.crt pathLenConstraint0CACert.crt
-run_test 4.6.16 1 InvalidSelfIssuedpathLenConstraintTest16EE.crt pathLenConstraint0subCA2Cert.crt pathLenConstraint0SelfIssuedCACert.crt pathLenConstraint0CACert.crt
-run_test 4.6.17 0 ValidSelfIssuedpathLenConstraintTest17EE.crt pathLenConstraint1SelfIssuedsubCACert.crt pathLenConstraint1subCACert.crt pathLenConstraint1SelfIssuedCACert.crt pathLenConstraint1CACert.crt
-
-run_test 4.7.1 1 InvalidkeyUsageCriticalkeyCertSignFalseTest1EE.crt keyUsageCriticalkeyCertSignFalseCACert.crt
-run_test 4.7.2 1 InvalidkeyUsageNotCriticalkeyCertSignFalseTest2EE.crt keyUsageNotCriticalkeyCertSignFalseCACert.crt
-run_test 4.7.3 0 ValidkeyUsageNotCriticalTest3EE.crt keyUsageNotCriticalCACert.crt
-run_test 4.7.4 1 InvalidkeyUsageCriticalcRLSignFalseTest4EE.crt keyUsageCriticalcRLSignFalseCACert.crt
-run_test 4.7.5 1 InvalidkeyUsageNotCriticalcRLSignFalseTest5EE.crt keyUsageNotCriticalcRLSignFalseCACert.crt
-
-run_test 4.8.1 0 ValidCertificatePathTest1EE.crt GoodCACert.crt
-run_test 4.8.2 0 AllCertificatesNoPoliciesTest2EE.crt NoPoliciesCACert.crt
-run_test 4.8.3 0 DifferentPoliciesTest3EE.crt PoliciesP2subCACert.crt GoodCACert.crt
-run_test 4.8.4 0 DifferentPoliciesTest4EE.crt GoodsubCACert.crt GoodCACert.crt
-run_test 4.8.5 0 DifferentPoliciesTest5EE.crt PoliciesP2subCA2Cert.crt GoodCACert.crt
-run_test 4.8.6 0 OverlappingPoliciesTest6EE.crt PoliciesP1234subsubCAP123P12Cert.crt PoliciesP1234subCAP123Cert.crt PoliciesP1234CACert.crt
-run_test 4.8.7 0 DifferentPoliciesTest7EE.crt PoliciesP123subsubCAP12P1Cert.crt PoliciesP123subCAP12Cert.crt PoliciesP123CACert.crt
-run_test 4.8.8 0 DifferentPoliciesTest8EE.crt PoliciesP12subsubCAP1P2Cert.crt PoliciesP12subCAP1Cert.crt PoliciesP12CACert.crt
-run_test 4.8.9 0 DifferentPoliciesTest9EE.crt PoliciesP123subsubsubCAP12P2P1Cert.crt PoliciesP123subsubCAP12P2Cert.crt PoliciesP123subCAP12Cert.crt PoliciesP123CACert.crt
-run_test 4.8.10 0 AllCertificatesSamePoliciesTest10EE.crt PoliciesP12CACert.crt
-run_test 4.8.11 0 AllCertificatesanyPolicyTest11EE.crt anyPolicyCACert.crt
-run_test 4.8.12 0 DifferentPoliciesTest12EE.crt PoliciesP3CACert.crt
-run_test 4.8.13 0 AllCertificatesSamePoliciesTest13EE.crt PoliciesP123CACert.crt
-run_test 4.8.14 0 AnyPolicyTest14EE.crt anyPolicyCACert.crt
-run_test 4.8.15 0 UserNoticeQualifierTest15EE.crt
-run_test 4.8.16 0 UserNoticeQualifierTest16EE.crt GoodCACert.crt
-run_test 4.8.17 0 UserNoticeQualifierTest17EE.crt GoodCACert.crt
-run_test 4.8.18 0 UserNoticeQualifierTest18EE.crt PoliciesP12CACert.crt
-run_test 4.8.19 0 UserNoticeQualifierTest19EE.crt TrustAnchorRootCertificate.crt
-run_test 4.8.20 0 CPSPointerQualifierTest20EE.crt GoodCACert.crt
-
-if false; then
-# DSA tests
-run_test 4.1.4 0 ValidDSASignaturesTest4EE.crt DSACACert.crt
-fi
-
-popd
-
-
-echo "Successful tests:$SUCCESS"
-echo "Failed tests:$FAILURE"
diff --git a/contrib/wpa/wpa_supplicant/todo.txt b/contrib/wpa/wpa_supplicant/todo.txt
index a02a937..b84cccc 100644
--- a/contrib/wpa/wpa_supplicant/todo.txt
+++ b/contrib/wpa/wpa_supplicant/todo.txt
@@ -1,7 +1,4 @@
To do:
-- hostap: try other roaming modes
- NOTE: current mode (manual roaming) does not really roam at all..
- Firmware did not notice the current AP disappearing..
- add support for WPA with ap_scan=0 (update selected cipher etc. based on
AssocInfo; make sure these match with configuration)
- consider closing smart card / PCSC connection when EAP-SIM/EAP-AKA
@@ -35,8 +32,6 @@ To do:
- EAP-POTP/RSA SecurID profile (RFC 4793)
- document wpa_gui build and consider adding it to 'make install'
- test madwifi with pairwise=TKIP group=WEP104
-- possibility to link in WPA Authenticator state machine to wpa_supplicant
- (new PeerKey handshake, WPA2/IEEE 802.11 (RSN) IBSS)
- consider merging hostapd and wpa_supplicant PMKSA cache implementations
- consider redesigning pending EAP requests (identity/password/otp from
ctrl_iface) by moving the retrying of the previous request into EAP
@@ -59,6 +54,9 @@ To do:
could very well be done before EAP has been started
- try to work around race in receiving association event and first EAPOL
message
+- try to work around race in configuring PTK and sending msg 4/4 (some NDIS
+ drivers with ndiswrapper end up not being able to complete 4-way handshake
+ in some cases; extra delay before setting the key seems to help)
- add wpa_secure_memzero() macro and secure implementation (volatile u8*) to
clear memory; this would be used to clear temporary buffers containing
private data (e.g., keys); the macro can be defined to NOP in order to save
@@ -72,18 +70,13 @@ To do:
- add support for fetching full user cert chain from Windows certificate
stores even when there are intermediate CA certs that are not in the
configured ca_cert store (e.g., ROOT) (they could be, e.g., in CA store)
-
-
-0.6.x branch:
- clean up common.[ch]
- change TLS/crypto library interface to use a structure of function
pointers and helper inline functions (like driver_ops) instead of
requiring every TLS wrapper to implement all functions
- add support for encrypted configuration fields (e.g., password, psk,
passphrase, pin)
-- wpa_gui: add support for setting and showing priority, auth_alg
- (open/shared for static WEP)
-
+- wpa_gui: add support for setting and showing priority
- cleanup TLS/PEAP/TTLS/FAST fragmentation: both the handshake and Appl. Data
phases should be able to use the same functions for this;
the last step in processing sent should be this code and rest of the code
diff --git a/contrib/wpa/wpa_supplicant/wpa_cli.c b/contrib/wpa/wpa_supplicant/wpa_cli.c
index 7de6534..162a0b8 100644
--- a/contrib/wpa/wpa_supplicant/wpa_cli.c
+++ b/contrib/wpa/wpa_supplicant/wpa_cli.c
@@ -1,6 +1,6 @@
/*
* WPA Supplicant - command line interface for wpa_supplicant daemon
- * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2004-2010, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -23,15 +23,18 @@
#include <readline/readline.h>
#include <readline/history.h>
#endif /* CONFIG_READLINE */
+#ifdef CONFIG_WPA_CLI_FORK
+#include <sys/wait.h>
+#endif /* CONFIG_WPA_CLI_FORK */
-#include "wpa_ctrl.h"
+#include "common/wpa_ctrl.h"
#include "common.h"
-#include "version.h"
+#include "common/version.h"
static const char *wpa_cli_version =
"wpa_cli v" VERSION_STR "\n"
-"Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi> and contributors";
+"Copyright (c) 2004-2010, Jouni Malinen <j@w1.fi> and contributors";
static const char *wpa_cli_license =
@@ -87,6 +90,10 @@ static const char *wpa_cli_full_license =
"\n";
static struct wpa_ctrl *ctrl_conn;
+static struct wpa_ctrl *mon_conn;
+#ifdef CONFIG_WPA_CLI_FORK
+static pid_t mon_pid = 0;
+#endif /* CONFIG_WPA_CLI_FORK */
static int wpa_cli_quit = 0;
static int wpa_cli_attached = 0;
static int wpa_cli_connected = 0;
@@ -96,6 +103,7 @@ static char *ctrl_ifname = NULL;
static const char *pid_file = NULL;
static const char *action_file = NULL;
static int ping_interval = 5;
+static int interactive = 0;
static void print_help();
@@ -119,32 +127,126 @@ static void usage(void)
}
-static struct wpa_ctrl * wpa_cli_open_connection(const char *ifname)
+#ifdef CONFIG_WPA_CLI_FORK
+static int in_query = 0;
+
+static void wpa_cli_monitor_sig(int sig)
+{
+ if (sig == SIGUSR1)
+ in_query = 1;
+ else if (sig == SIGUSR2)
+ in_query = 0;
+}
+
+static void wpa_cli_monitor(void)
+{
+ char buf[256];
+ size_t len = sizeof(buf) - 1;
+ struct timeval tv;
+ fd_set rfds;
+
+ signal(SIGUSR1, wpa_cli_monitor_sig);
+ signal(SIGUSR2, wpa_cli_monitor_sig);
+
+ while (mon_conn) {
+ int s = wpa_ctrl_get_fd(mon_conn);
+ tv.tv_sec = 5;
+ tv.tv_usec = 0;
+ FD_ZERO(&rfds);
+ FD_SET(s, &rfds);
+ if (select(s + 1, &rfds, NULL, NULL, &tv) < 0) {
+ if (errno == EINTR)
+ continue;
+ perror("select");
+ break;
+ }
+ if (mon_conn == NULL)
+ break;
+ if (FD_ISSET(s, &rfds)) {
+ len = sizeof(buf) - 1;
+ int res = wpa_ctrl_recv(mon_conn, buf, &len);
+ if (res < 0) {
+ perror("wpa_ctrl_recv");
+ break;
+ }
+ buf[len] = '\0';
+ if (in_query)
+ printf("\r");
+ printf("%s\n", buf);
+ kill(getppid(), SIGUSR1);
+ }
+ }
+}
+#endif /* CONFIG_WPA_CLI_FORK */
+
+
+static int wpa_cli_open_connection(const char *ifname, int attach)
{
#if defined(CONFIG_CTRL_IFACE_UDP) || defined(CONFIG_CTRL_IFACE_NAMED_PIPE)
ctrl_conn = wpa_ctrl_open(ifname);
- return ctrl_conn;
+ if (ctrl_conn == NULL)
+ return -1;
+
+ if (attach && interactive)
+ mon_conn = wpa_ctrl_open(ifname);
+ else
+ mon_conn = NULL;
#else /* CONFIG_CTRL_IFACE_UDP || CONFIG_CTRL_IFACE_NAMED_PIPE */
char *cfile;
int flen, res;
if (ifname == NULL)
- return NULL;
+ return -1;
flen = os_strlen(ctrl_iface_dir) + os_strlen(ifname) + 2;
cfile = os_malloc(flen);
if (cfile == NULL)
- return NULL;
+ return -1L;
res = os_snprintf(cfile, flen, "%s/%s", ctrl_iface_dir, ifname);
if (res < 0 || res >= flen) {
os_free(cfile);
- return NULL;
+ return -1;
}
ctrl_conn = wpa_ctrl_open(cfile);
+ if (ctrl_conn == NULL) {
+ os_free(cfile);
+ return -1;
+ }
+
+ if (attach && interactive)
+ mon_conn = wpa_ctrl_open(cfile);
+ else
+ mon_conn = NULL;
os_free(cfile);
- return ctrl_conn;
#endif /* CONFIG_CTRL_IFACE_UDP || CONFIG_CTRL_IFACE_NAMED_PIPE */
+
+ if (mon_conn) {
+ if (wpa_ctrl_attach(mon_conn) == 0) {
+ wpa_cli_attached = 1;
+ } else {
+ printf("Warning: Failed to attach to "
+ "wpa_supplicant.\n");
+ return -1;
+ }
+
+#ifdef CONFIG_WPA_CLI_FORK
+ {
+ pid_t p = fork();
+ if (p < 0) {
+ perror("fork");
+ return -1;
+ }
+ if (p == 0) {
+ wpa_cli_monitor();
+ exit(0);
+ } else
+ mon_pid = p;
+ }
+#endif /* CONFIG_WPA_CLI_FORK */
+ }
+
+ return 0;
}
@@ -153,12 +255,25 @@ static void wpa_cli_close_connection(void)
if (ctrl_conn == NULL)
return;
+#ifdef CONFIG_WPA_CLI_FORK
+ if (mon_pid) {
+ int status;
+ kill(mon_pid, SIGPIPE);
+ wait(&status);
+ mon_pid = 0;
+ }
+#endif /* CONFIG_WPA_CLI_FORK */
+
if (wpa_cli_attached) {
- wpa_ctrl_detach(ctrl_conn);
+ wpa_ctrl_detach(interactive ? mon_conn : ctrl_conn);
wpa_cli_attached = 0;
}
wpa_ctrl_close(ctrl_conn);
ctrl_conn = NULL;
+ if (mon_conn) {
+ wpa_ctrl_close(mon_conn);
+ mon_conn = NULL;
+ }
}
@@ -446,19 +561,85 @@ static int wpa_cli_cmd_wps_pin(struct wpa_ctrl *ctrl, int argc, char *argv[])
}
+#ifdef CONFIG_WPS_OOB
+static int wpa_cli_cmd_wps_oob(struct wpa_ctrl *ctrl, int argc, char *argv[])
+{
+ char cmd[256];
+ int res;
+
+ if (argc != 3 && argc != 4) {
+ printf("Invalid WPS_OOB command: need three or four "
+ "arguments:\n"
+ "- DEV_TYPE: use 'ufd' or 'nfc'\n"
+ "- PATH: path of OOB device like '/mnt'\n"
+ "- METHOD: OOB method 'pin-e' or 'pin-r', "
+ "'cred'\n"
+ "- DEV_NAME: (only for NFC) device name like "
+ "'pn531'\n");
+ return -1;
+ }
+
+ if (argc == 3)
+ res = os_snprintf(cmd, sizeof(cmd), "WPS_OOB %s %s %s",
+ argv[0], argv[1], argv[2]);
+ else
+ res = os_snprintf(cmd, sizeof(cmd), "WPS_OOB %s %s %s %s",
+ argv[0], argv[1], argv[2], argv[3]);
+ if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
+ printf("Too long WPS_OOB command.\n");
+ return -1;
+ }
+ return wpa_ctrl_command(ctrl, cmd);
+}
+#endif /* CONFIG_WPS_OOB */
+
+
static int wpa_cli_cmd_wps_reg(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
char cmd[256];
int res;
- if (argc != 2) {
+ if (argc == 2)
+ res = os_snprintf(cmd, sizeof(cmd), "WPS_REG %s %s",
+ argv[0], argv[1]);
+ else if (argc == 6) {
+ char ssid_hex[2 * 32 + 1];
+ char key_hex[2 * 64 + 1];
+ int i;
+
+ ssid_hex[0] = '\0';
+ for (i = 0; i < 32; i++) {
+ if (argv[2][i] == '\0')
+ break;
+ os_snprintf(&ssid_hex[i * 2], 3, "%02x", argv[2][i]);
+ }
+
+ key_hex[0] = '\0';
+ for (i = 0; i < 64; i++) {
+ if (argv[5][i] == '\0')
+ break;
+ os_snprintf(&key_hex[i * 2], 3, "%02x", argv[5][i]);
+ }
+
+ res = os_snprintf(cmd, sizeof(cmd),
+ "WPS_REG %s %s %s %s %s %s",
+ argv[0], argv[1], ssid_hex, argv[3], argv[4],
+ key_hex);
+ } else {
printf("Invalid WPS_REG command: need two arguments:\n"
"- BSSID: use 'any' to select any\n"
"- AP PIN\n");
+ printf("Alternatively, six arguments can be used to "
+ "reconfigure the AP:\n"
+ "- BSSID: use 'any' to select any\n"
+ "- AP PIN\n"
+ "- new SSID\n"
+ "- new auth (OPEN, WPAPSK, WPA2PSK)\n"
+ "- new encr (NONE, WEP, TKIP, CCMP)\n"
+ "- new key\n");
return -1;
}
- res = os_snprintf(cmd, sizeof(cmd), "WPS_REG %s %s", argv[0], argv[1]);
if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
printf("Too long WPS_REG command.\n");
return -1;
@@ -467,6 +648,110 @@ static int wpa_cli_cmd_wps_reg(struct wpa_ctrl *ctrl, int argc, char *argv[])
}
+static int wpa_cli_cmd_wps_er_start(struct wpa_ctrl *ctrl, int argc,
+ char *argv[])
+{
+ return wpa_ctrl_command(ctrl, "WPS_ER_START");
+
+}
+
+
+static int wpa_cli_cmd_wps_er_stop(struct wpa_ctrl *ctrl, int argc,
+ char *argv[])
+{
+ return wpa_ctrl_command(ctrl, "WPS_ER_STOP");
+
+}
+
+
+static int wpa_cli_cmd_wps_er_pin(struct wpa_ctrl *ctrl, int argc,
+ char *argv[])
+{
+ char cmd[256];
+ int res;
+
+ if (argc != 2) {
+ printf("Invalid WPS_ER_PIN command: need two arguments:\n"
+ "- UUID: use 'any' to select any\n"
+ "- PIN: Enrollee PIN\n");
+ return -1;
+ }
+
+ res = os_snprintf(cmd, sizeof(cmd), "WPS_ER_PIN %s %s",
+ argv[0], argv[1]);
+ if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
+ printf("Too long WPS_ER_PIN command.\n");
+ return -1;
+ }
+ return wpa_ctrl_command(ctrl, cmd);
+}
+
+
+static int wpa_cli_cmd_wps_er_pbc(struct wpa_ctrl *ctrl, int argc,
+ char *argv[])
+{
+ char cmd[256];
+ int res;
+
+ if (argc != 1) {
+ printf("Invalid WPS_ER_PBC command: need one argument:\n"
+ "- UUID: Specify the Enrollee\n");
+ return -1;
+ }
+
+ res = os_snprintf(cmd, sizeof(cmd), "WPS_ER_PBC %s",
+ argv[0]);
+ if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
+ printf("Too long WPS_ER_PBC command.\n");
+ return -1;
+ }
+ return wpa_ctrl_command(ctrl, cmd);
+}
+
+
+static int wpa_cli_cmd_wps_er_learn(struct wpa_ctrl *ctrl, int argc,
+ char *argv[])
+{
+ char cmd[256];
+ int res;
+
+ if (argc != 2) {
+ printf("Invalid WPS_ER_LEARN command: need two arguments:\n"
+ "- UUID: specify which AP to use\n"
+ "- PIN: AP PIN\n");
+ return -1;
+ }
+
+ res = os_snprintf(cmd, sizeof(cmd), "WPS_ER_LEARN %s %s",
+ argv[0], argv[1]);
+ if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
+ printf("Too long WPS_ER_LEARN command.\n");
+ return -1;
+ }
+ return wpa_ctrl_command(ctrl, cmd);
+}
+
+
+static int wpa_cli_cmd_ibss_rsn(struct wpa_ctrl *ctrl, int argc, char *argv[])
+{
+ char cmd[256];
+ int res;
+
+ if (argc != 1) {
+ printf("Invalid IBSS_RSN command: needs one argument "
+ "(Peer STA MAC address)\n");
+ return -1;
+ }
+
+ res = os_snprintf(cmd, sizeof(cmd), "IBSS_RSN %s", argv[0]);
+ if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
+ printf("Too long IBSS_RSN command.\n");
+ return -1;
+ }
+ return wpa_ctrl_command(ctrl, cmd);
+}
+
+
static int wpa_cli_cmd_level(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
char cmd[256];
@@ -990,14 +1275,8 @@ static int wpa_cli_cmd_interface(struct wpa_ctrl *ctrl, int argc, char *argv[])
os_free(ctrl_ifname);
ctrl_ifname = os_strdup(argv[0]);
- if (wpa_cli_open_connection(ctrl_ifname)) {
+ if (wpa_cli_open_connection(ctrl_ifname, 1)) {
printf("Connected to interface '%s.\n", ctrl_ifname);
- if (wpa_ctrl_attach(ctrl_conn) == 0) {
- wpa_cli_attached = 1;
- } else {
- printf("Warning: Failed to attach to "
- "wpa_supplicant.\n");
- }
} else {
printf("Could not connect to interface '%s' - re-trying\n",
ctrl_ifname);
@@ -1078,6 +1357,109 @@ static int wpa_cli_cmd_interface_list(struct wpa_ctrl *ctrl, int argc,
}
+#ifdef CONFIG_AP
+static int wpa_cli_cmd_sta(struct wpa_ctrl *ctrl, int argc, char *argv[])
+{
+ char buf[64];
+ if (argc != 1) {
+ printf("Invalid 'sta' command - exactly one argument, STA "
+ "address, is required.\n");
+ return -1;
+ }
+ os_snprintf(buf, sizeof(buf), "STA %s", argv[0]);
+ return wpa_ctrl_command(ctrl, buf);
+}
+
+
+static int wpa_ctrl_command_sta(struct wpa_ctrl *ctrl, char *cmd,
+ char *addr, size_t addr_len)
+{
+ char buf[4096], *pos;
+ size_t len;
+ int ret;
+
+ if (ctrl_conn == NULL) {
+ printf("Not connected to hostapd - command dropped.\n");
+ return -1;
+ }
+ len = sizeof(buf) - 1;
+ ret = wpa_ctrl_request(ctrl, cmd, strlen(cmd), buf, &len,
+ wpa_cli_msg_cb);
+ if (ret == -2) {
+ printf("'%s' command timed out.\n", cmd);
+ return -2;
+ } else if (ret < 0) {
+ printf("'%s' command failed.\n", cmd);
+ return -1;
+ }
+
+ buf[len] = '\0';
+ if (memcmp(buf, "FAIL", 4) == 0)
+ return -1;
+ printf("%s", buf);
+
+ pos = buf;
+ while (*pos != '\0' && *pos != '\n')
+ pos++;
+ *pos = '\0';
+ os_strlcpy(addr, buf, addr_len);
+ return 0;
+}
+
+
+static int wpa_cli_cmd_all_sta(struct wpa_ctrl *ctrl, int argc, char *argv[])
+{
+ char addr[32], cmd[64];
+
+ if (wpa_ctrl_command_sta(ctrl, "STA-FIRST", addr, sizeof(addr)))
+ return 0;
+ do {
+ os_snprintf(cmd, sizeof(cmd), "STA-NEXT %s", addr);
+ } while (wpa_ctrl_command_sta(ctrl, cmd, addr, sizeof(addr)) == 0);
+
+ return -1;
+}
+#endif /* CONFIG_AP */
+
+
+static int wpa_cli_cmd_suspend(struct wpa_ctrl *ctrl, int argc, char *argv[])
+{
+ return wpa_ctrl_command(ctrl, "SUSPEND");
+}
+
+
+static int wpa_cli_cmd_resume(struct wpa_ctrl *ctrl, int argc, char *argv[])
+{
+ return wpa_ctrl_command(ctrl, "RESUME");
+}
+
+
+static int wpa_cli_cmd_drop_sa(struct wpa_ctrl *ctrl, int argc, char *argv[])
+{
+ return wpa_ctrl_command(ctrl, "DROP_SA");
+}
+
+
+static int wpa_cli_cmd_roam(struct wpa_ctrl *ctrl, int argc, char *argv[])
+{
+ char cmd[128];
+ int res;
+
+ if (argc != 1) {
+ printf("Invalid ROAM command: needs one argument "
+ "(target AP's BSSID)\n");
+ return -1;
+ }
+
+ res = os_snprintf(cmd, sizeof(cmd), "ROAM %s", argv[0]);
+ if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
+ printf("Too long ROAM command.\n");
+ return -1;
+ }
+ return wpa_ctrl_command(ctrl, cmd);
+}
+
+
enum wpa_cli_cmd_flags {
cli_cmd_flag_none = 0x00,
cli_cmd_flag_sensitive = 0x01
@@ -1238,9 +1620,49 @@ static struct wpa_cli_cmd wpa_cli_commands[] = {
cli_cmd_flag_sensitive,
"<BSSID> [PIN] = start WPS PIN method (returns PIN, if not "
"hardcoded)" },
+#ifdef CONFIG_WPS_OOB
+ { "wps_oob", wpa_cli_cmd_wps_oob,
+ cli_cmd_flag_sensitive,
+ "<DEV_TYPE> <PATH> <METHOD> [DEV_NAME] = start WPS OOB" },
+#endif /* CONFIG_WPS_OOB */
{ "wps_reg", wpa_cli_cmd_wps_reg,
cli_cmd_flag_sensitive,
"<BSSID> <AP PIN> = start WPS Registrar to configure an AP" },
+ { "wps_er_start", wpa_cli_cmd_wps_er_start,
+ cli_cmd_flag_none,
+ "= start Wi-Fi Protected Setup External Registrar" },
+ { "wps_er_stop", wpa_cli_cmd_wps_er_stop,
+ cli_cmd_flag_none,
+ "= stop Wi-Fi Protected Setup External Registrar" },
+ { "wps_er_pin", wpa_cli_cmd_wps_er_pin,
+ cli_cmd_flag_sensitive,
+ "<UUID> <PIN> = add an Enrollee PIN to External Registrar" },
+ { "wps_er_pbc", wpa_cli_cmd_wps_er_pbc,
+ cli_cmd_flag_none,
+ "<UUID> = accept an Enrollee PBC using External Registrar" },
+ { "wps_er_learn", wpa_cli_cmd_wps_er_learn,
+ cli_cmd_flag_sensitive,
+ "<UUID> <PIN> = learn AP configuration" },
+ { "ibss_rsn", wpa_cli_cmd_ibss_rsn,
+ cli_cmd_flag_none,
+ "<addr> = request RSN authentication with <addr> in IBSS" },
+#ifdef CONFIG_AP
+ { "sta", wpa_cli_cmd_sta,
+ cli_cmd_flag_none,
+ "<addr> = get information about an associated station (AP)" },
+ { "all_sta", wpa_cli_cmd_all_sta,
+ cli_cmd_flag_none,
+ "= get information about all associated stations (AP)" },
+#endif /* CONFIG_AP */
+ { "suspend", wpa_cli_cmd_suspend, cli_cmd_flag_none,
+ "= notification of suspend/hibernate" },
+ { "resume", wpa_cli_cmd_resume, cli_cmd_flag_none,
+ "= notification of resume/thaw" },
+ { "drop_sa", wpa_cli_cmd_drop_sa, cli_cmd_flag_none,
+ "= drop SA without deauth/disassoc (test command)" },
+ { "roam", wpa_cli_cmd_roam,
+ cli_cmd_flag_none,
+ "<addr> = roam to the specified BSS" },
{ NULL, NULL, cli_cmd_flag_none, NULL }
};
@@ -1448,16 +1870,7 @@ static void wpa_cli_action_cb(char *msg, size_t len)
static void wpa_cli_reconnect(void)
{
wpa_cli_close_connection();
- ctrl_conn = wpa_cli_open_connection(ctrl_ifname);
- if (ctrl_conn) {
- printf("Connection to wpa_supplicant re-established\n");
- if (wpa_ctrl_attach(ctrl_conn) == 0) {
- wpa_cli_attached = 1;
- } else {
- printf("Warning: Failed to attach to "
- "wpa_supplicant.\n");
- }
- }
+ wpa_cli_open_connection(ctrl_ifname, 1);
}
@@ -1478,9 +1891,13 @@ static void wpa_cli_recv_pending(struct wpa_ctrl *ctrl, int in_read,
wpa_cli_action_process(buf);
else {
if (in_read && first)
- printf("\n");
+ printf("\r");
first = 0;
printf("%s\n", buf);
+#ifdef CONFIG_READLINE
+ rl_on_new_line();
+ rl_redisplay();
+#endif /* CONFIG_READLINE */
}
} else {
printf("Could not read pending message.\n");
@@ -1510,7 +1927,7 @@ static char * wpa_cli_cmd_gen(const char *text, int state)
while ((cmd = wpa_cli_commands[i].cmd)) {
i++;
if (os_strncasecmp(cmd, text, len) == 0)
- return os_strdup(cmd);
+ return strdup(cmd);
}
return NULL;
@@ -1519,14 +1936,60 @@ static char * wpa_cli_cmd_gen(const char *text, int state)
static char * wpa_cli_dummy_gen(const char *text, int state)
{
+ int i;
+
+ for (i = 0; wpa_cli_commands[i].cmd; i++) {
+ const char *cmd = wpa_cli_commands[i].cmd;
+ size_t len = os_strlen(cmd);
+ if (os_strncasecmp(rl_line_buffer, cmd, len) == 0 &&
+ rl_line_buffer[len] == ' ') {
+ printf("\n%s\n", wpa_cli_commands[i].usage);
+ rl_on_new_line();
+ rl_redisplay();
+ break;
+ }
+ }
+
+ rl_attempted_completion_over = 1;
+ return NULL;
+}
+
+
+static char * wpa_cli_status_gen(const char *text, int state)
+{
+ static int i, len;
+ char *options[] = {
+ "verbose", NULL
+ };
+ char *t;
+
+ if (state == 0) {
+ i = 0;
+ len = os_strlen(text);
+ }
+
+ while ((t = options[i])) {
+ i++;
+ if (os_strncasecmp(t, text, len) == 0)
+ return strdup(t);
+ }
+
+ rl_attempted_completion_over = 1;
return NULL;
}
static char ** wpa_cli_completion(const char *text, int start, int end)
{
- return rl_completion_matches(text, start == 0 ?
- wpa_cli_cmd_gen : wpa_cli_dummy_gen);
+ char * (*func)(const char *text, int state);
+
+ if (start == 0)
+ func = wpa_cli_cmd_gen;
+ else if (os_strncasecmp(rl_line_buffer, "status ", 7) == 0)
+ func = wpa_cli_status_gen;
+ else
+ func = wpa_cli_dummy_gen;
+ return rl_completion_matches(text, func);
}
#endif /* CONFIG_READLINE */
@@ -1563,10 +2026,14 @@ static void wpa_cli_interactive(void)
#endif /* CONFIG_READLINE */
do {
- wpa_cli_recv_pending(ctrl_conn, 0, 0);
+ wpa_cli_recv_pending(mon_conn, 0, 0);
#ifndef CONFIG_NATIVE_WINDOWS
alarm(ping_interval);
#endif /* CONFIG_NATIVE_WINDOWS */
+#ifdef CONFIG_WPA_CLI_FORK
+ if (mon_pid)
+ kill(mon_pid, SIGUSR1);
+#endif /* CONFIG_WPA_CLI_FORK */
#ifdef CONFIG_READLINE
cmd = readline("> ");
if (cmd && *cmd) {
@@ -1587,7 +2054,7 @@ static void wpa_cli_interactive(void)
#endif /* CONFIG_NATIVE_WINDOWS */
if (cmd == NULL)
break;
- wpa_cli_recv_pending(ctrl_conn, 0, 0);
+ wpa_cli_recv_pending(mon_conn, 0, 0);
pos = cmd;
while (*pos != '\0') {
if (*pos == '\n') {
@@ -1621,7 +2088,11 @@ static void wpa_cli_interactive(void)
wpa_request(ctrl_conn, argc, argv);
if (cmd != cmdbuf)
- os_free(cmd);
+ free(cmd);
+#ifdef CONFIG_WPA_CLI_FORK
+ if (mon_pid)
+ kill(mon_pid, SIGUSR2);
+#endif /* CONFIG_WPA_CLI_FORK */
} while (!wpa_cli_quit);
#ifdef CONFIG_READLINE
@@ -1711,6 +2182,17 @@ static void wpa_cli_terminate(int sig)
}
+#ifdef CONFIG_WPA_CLI_FORK
+static void wpa_cli_usr1(int sig)
+{
+#ifdef CONFIG_READLINE
+ rl_on_new_line();
+ rl_redisplay();
+#endif /* CONFIG_READLINE */
+}
+#endif /* CONFIG_WPA_CLI_FORK */
+
+
#ifndef CONFIG_NATIVE_WINDOWS
static void wpa_cli_alarm(int sig)
{
@@ -1721,8 +2203,8 @@ static void wpa_cli_alarm(int sig)
}
if (!ctrl_conn)
wpa_cli_reconnect();
- if (ctrl_conn)
- wpa_cli_recv_pending(ctrl_conn, 1, 0);
+ if (mon_conn)
+ wpa_cli_recv_pending(mon_conn, 1, 0);
alarm(ping_interval);
}
#endif /* CONFIG_NATIVE_WINDOWS */
@@ -1785,7 +2267,6 @@ static char * wpa_cli_get_default_ifname(void)
int main(int argc, char *argv[])
{
- int interactive;
int warning_displayed = 0;
int c;
int daemonize = 0;
@@ -1852,31 +2333,6 @@ int main(int argc, char *argv[])
}
}
- for (; !global;) {
- if (ctrl_ifname == NULL)
- ctrl_ifname = wpa_cli_get_default_ifname();
- ctrl_conn = wpa_cli_open_connection(ctrl_ifname);
- if (ctrl_conn) {
- if (warning_displayed)
- printf("Connection established.\n");
- break;
- }
-
- if (!interactive) {
- perror("Failed to connect to wpa_supplicant - "
- "wpa_ctrl_open");
- return -1;
- }
-
- if (!warning_displayed) {
- printf("Could not connect to wpa_supplicant - "
- "re-trying\n");
- warning_displayed = 1;
- }
- os_sleep(1, 0);
- continue;
- }
-
#ifndef _WIN32_WCE
signal(SIGINT, wpa_cli_terminate);
signal(SIGTERM, wpa_cli_terminate);
@@ -1884,15 +2340,45 @@ int main(int argc, char *argv[])
#ifndef CONFIG_NATIVE_WINDOWS
signal(SIGALRM, wpa_cli_alarm);
#endif /* CONFIG_NATIVE_WINDOWS */
+#ifdef CONFIG_WPA_CLI_FORK
+ signal(SIGUSR1, wpa_cli_usr1);
+#endif /* CONFIG_WPA_CLI_FORK */
+
+ if (ctrl_ifname == NULL)
+ ctrl_ifname = wpa_cli_get_default_ifname();
+
+ if (interactive) {
+ for (; !global;) {
+ if (wpa_cli_open_connection(ctrl_ifname, 1) == 0) {
+ if (warning_displayed)
+ printf("Connection established.\n");
+ break;
+ }
- if (interactive || action_file) {
- if (wpa_ctrl_attach(ctrl_conn) == 0) {
- wpa_cli_attached = 1;
- } else {
- printf("Warning: Failed to attach to "
- "wpa_supplicant.\n");
- if (!interactive)
+ if (!warning_displayed) {
+ printf("Could not connect to wpa_supplicant - "
+ "re-trying\n");
+ warning_displayed = 1;
+ }
+ os_sleep(1, 0);
+ continue;
+ }
+ } else {
+ if (!global &&
+ wpa_cli_open_connection(ctrl_ifname, 0) < 0) {
+ perror("Failed to connect to wpa_supplicant - "
+ "wpa_ctrl_open");
+ return -1;
+ }
+
+ if (action_file) {
+ if (wpa_ctrl_attach(ctrl_conn) == 0) {
+ wpa_cli_attached = 1;
+ } else {
+ printf("Warning: Failed to attach to "
+ "wpa_supplicant.\n");
return -1;
+ }
}
}
diff --git a/contrib/wpa/wpa_supplicant/wpa_passphrase.c b/contrib/wpa/wpa_supplicant/wpa_passphrase.c
index 96b0c32..67465aa 100644
--- a/contrib/wpa/wpa_supplicant/wpa_passphrase.c
+++ b/contrib/wpa/wpa_supplicant/wpa_passphrase.c
@@ -15,7 +15,7 @@
#include "includes.h"
#include "common.h"
-#include "sha1.h"
+#include "crypto/sha1.h"
int main(int argc, char *argv[])
diff --git a/contrib/wpa/wpa_supplicant/wpa_priv.c b/contrib/wpa/wpa_supplicant/wpa_priv.c
index 4ff0284..d2a991b 100644
--- a/contrib/wpa/wpa_supplicant/wpa_priv.c
+++ b/contrib/wpa/wpa_supplicant/wpa_priv.c
@@ -21,19 +21,11 @@
#include "common.h"
#include "eloop.h"
-#include "version.h"
+#include "common/version.h"
#include "drivers/driver.h"
#include "l2_packet/l2_packet.h"
-#include "privsep_commands.h"
-#include "ieee802_11_defs.h"
-
-#ifndef ETH_P_EAPOL
-#define ETH_P_EAPOL 0x888e
-#endif
-
-#ifndef ETH_P_RSN_PREAUTH
-#define ETH_P_RSN_PREAUTH 0x88c7
-#endif
+#include "common/privsep_commands.h"
+#include "common/ieee802_11_defs.h"
struct wpa_priv_interface {
@@ -59,8 +51,6 @@ static void wpa_priv_cmd_register(struct wpa_priv_interface *iface,
{
if (iface->drv_priv) {
wpa_printf(MSG_DEBUG, "Cleaning up forgotten driver instance");
- if (iface->driver->set_wpa)
- iface->driver->set_wpa(iface->drv_priv, 0);
if (iface->driver->deinit)
iface->driver->deinit(iface->drv_priv);
iface->drv_priv = NULL;
@@ -93,9 +83,6 @@ static void wpa_priv_cmd_register(struct wpa_priv_interface *iface,
iface->driver->set_param(iface->drv_priv, NULL) < 0) {
wpa_printf(MSG_ERROR, "Driver interface rejected param");
}
-
- if (iface->driver->set_wpa)
- iface->driver->set_wpa(iface->drv_priv, 1);
}
@@ -103,8 +90,6 @@ static void wpa_priv_cmd_unregister(struct wpa_priv_interface *iface,
struct sockaddr_un *from)
{
if (iface->drv_priv) {
- if (iface->driver->set_wpa)
- iface->driver->set_wpa(iface->drv_priv, 0);
if (iface->driver->deinit)
iface->driver->deinit(iface->drv_priv);
iface->drv_priv = NULL;
@@ -113,26 +98,23 @@ static void wpa_priv_cmd_unregister(struct wpa_priv_interface *iface,
}
-static void wpa_priv_cmd_set_wpa(struct wpa_priv_interface *iface,
- char *buf, size_t len)
-{
- if (iface->drv_priv == NULL || len != sizeof(int))
- return;
-
- if (iface->driver->set_wpa)
- iface->driver->set_wpa(iface->drv_priv, *((int *) buf));
-}
-
-
static void wpa_priv_cmd_scan(struct wpa_priv_interface *iface,
char *buf, size_t len)
{
+ struct wpa_driver_scan_params params;
+
if (iface->drv_priv == NULL)
return;
- if (iface->driver->scan)
- iface->driver->scan(iface->drv_priv, len ? (u8 *) buf : NULL,
- len);
+ os_memset(&params, 0, sizeof(params));
+ if (len) {
+ params.ssids[0].ssid = (u8 *) buf;
+ params.ssids[0].ssid_len = len;
+ params.num_ssids = 1;
+ }
+
+ if (iface->driver->scan2)
+ iface->driver->scan2(iface->drv_priv, &params);
}
@@ -182,104 +164,6 @@ fail:
}
-static void wpa_priv_send_old_scan_results(struct wpa_priv_interface *iface,
- struct sockaddr_un *from)
-{
-#define SCAN_AP_LIMIT 128
- int i, res, val;
- struct wpa_scan_result *results = NULL;
- u8 *buf = NULL, *pos, *end;
- struct wpa_scan_res nres;
-
- results = os_malloc(SCAN_AP_LIMIT * sizeof(*results));
- if (results == NULL)
- goto fail;
-
- res = iface->driver->get_scan_results(iface->drv_priv, results,
- SCAN_AP_LIMIT);
- if (res < 0 || res > SCAN_AP_LIMIT)
- goto fail;
-
- buf = os_malloc(60000);
- if (buf == NULL)
- goto fail;
- pos = buf;
- end = buf + 60000;
- os_memcpy(pos, &res, sizeof(int));
- pos += sizeof(int);
-
- os_memset(&nres, 0, sizeof(nres));
- for (i = 0; i < res; i++) {
- struct wpa_scan_result *r = &results[i];
- size_t ie_len;
-
- ie_len = 2 + r->ssid_len + r->rsn_ie_len + r->wpa_ie_len;
- if (r->maxrate)
- ie_len += 3;
- if (r->mdie_present)
- ie_len += 5;
-
- val = sizeof(nres) + ie_len;
- if (end - pos < (int) sizeof(int) + val)
- break;
- os_memcpy(pos, &val, sizeof(int));
- pos += sizeof(int);
-
- os_memcpy(nres.bssid, r->bssid, ETH_ALEN);
- nres.freq = r->freq;
- nres.caps = r->caps;
- nres.qual = r->qual;
- nres.noise = r->noise;
- nres.level = r->level;
- nres.tsf = r->tsf;
- nres.ie_len = ie_len;
-
- os_memcpy(pos, &nres, sizeof(nres));
- pos += sizeof(nres);
-
- /* SSID IE */
- *pos++ = WLAN_EID_SSID;
- *pos++ = r->ssid_len;
- os_memcpy(pos, r->ssid, r->ssid_len);
- pos += r->ssid_len;
-
- if (r->maxrate) {
- /* Fake Supported Rate IE to include max rate */
- *pos++ = WLAN_EID_SUPP_RATES;
- *pos++ = 1;
- *pos++ = r->maxrate;
- }
-
- if (r->rsn_ie_len) {
- os_memcpy(pos, r->rsn_ie, r->rsn_ie_len);
- pos += r->rsn_ie_len;
- }
-
- if (r->mdie_present) {
- os_memcpy(pos, r->mdie, 5);
- pos += 5;
- }
-
- if (r->wpa_ie_len) {
- os_memcpy(pos, r->wpa_ie, r->wpa_ie_len);
- pos += r->wpa_ie_len;
- }
- }
-
- sendto(iface->fd, buf, pos - buf, 0, (struct sockaddr *) from,
- sizeof(*from));
-
- os_free(buf);
- os_free(results);
- return;
-
-fail:
- os_free(buf);
- os_free(results);
- sendto(iface->fd, "", 0, 0, (struct sockaddr *) from, sizeof(*from));
-}
-
-
static void wpa_priv_cmd_get_scan_results(struct wpa_priv_interface *iface,
struct sockaddr_un *from)
{
@@ -288,8 +172,6 @@ static void wpa_priv_cmd_get_scan_results(struct wpa_priv_interface *iface,
if (iface->driver->get_scan_results2)
wpa_priv_get_scan_results2(iface, from);
- else if (iface->driver->get_scan_results)
- wpa_priv_send_old_scan_results(iface, from);
else
sendto(iface->fd, "", 0, 0, (struct sockaddr *) from,
sizeof(*from));
@@ -405,7 +287,8 @@ static void wpa_priv_cmd_set_key(struct wpa_priv_interface *iface,
params = buf;
- res = iface->driver->set_key(iface->drv_priv, params->alg,
+ res = iface->driver->set_key(iface->ifname, iface->drv_priv,
+ params->alg,
params->addr, params->key_idx,
params->set_tx,
params->seq_len ? params->seq : NULL,
@@ -564,17 +447,6 @@ static void wpa_priv_cmd_l2_send(struct wpa_priv_interface *iface,
}
-static void wpa_priv_cmd_set_mode(struct wpa_priv_interface *iface,
- void *buf, size_t len)
-{
- if (iface->drv_priv == NULL || iface->driver->set_mode == NULL ||
- len != sizeof(int))
- return;
-
- iface->driver->set_mode(iface->drv_priv, *((int *) buf));
-}
-
-
static void wpa_priv_cmd_set_country(struct wpa_priv_interface *iface,
char *buf)
{
@@ -621,9 +493,6 @@ static void wpa_priv_receive(int sock, void *eloop_ctx, void *sock_ctx)
case PRIVSEP_CMD_UNREGISTER:
wpa_priv_cmd_unregister(iface, &from);
break;
- case PRIVSEP_CMD_SET_WPA:
- wpa_priv_cmd_set_wpa(iface, cmd_buf, cmd_len);
- break;
case PRIVSEP_CMD_SCAN:
wpa_priv_cmd_scan(iface, cmd_buf, cmd_len);
break;
@@ -657,9 +526,6 @@ static void wpa_priv_receive(int sock, void *eloop_ctx, void *sock_ctx)
case PRIVSEP_CMD_L2_SEND:
wpa_priv_cmd_l2_send(iface, &from, cmd_buf, cmd_len);
break;
- case PRIVSEP_CMD_SET_MODE:
- wpa_priv_cmd_set_mode(iface, cmd_buf, cmd_len);
- break;
case PRIVSEP_CMD_SET_COUNTRY:
pos = cmd_buf;
if (pos + cmd_len >= buf + sizeof(buf))
@@ -692,7 +558,7 @@ static void wpa_priv_interface_deinit(struct wpa_priv_interface *iface)
}
-extern struct wpa_driver_ops *wpa_supplicant_drivers[];
+extern struct wpa_driver_ops *wpa_drivers[];
static struct wpa_priv_interface *
wpa_priv_interface_init(const char *dir, const char *params)
@@ -721,10 +587,10 @@ wpa_priv_interface_init(const char *dir, const char *params)
os_memcpy(iface->driver_name, params, len);
iface->driver_name[len] = '\0';
- for (i = 0; wpa_supplicant_drivers[i]; i++) {
+ for (i = 0; wpa_drivers[i]; i++) {
if (os_strcmp(iface->driver_name,
- wpa_supplicant_drivers[i]->name) == 0) {
- iface->driver = wpa_supplicant_drivers[i];
+ wpa_drivers[i]->name) == 0) {
+ iface->driver = wpa_drivers[i];
break;
}
}
@@ -1049,52 +915,6 @@ void wpa_supplicant_rx_eapol(void *ctx, const u8 *src_addr,
}
-#ifdef CONFIG_CLIENT_MLME
-void wpa_supplicant_sta_free_hw_features(struct wpa_hw_modes *hw_features,
- size_t num_hw_features)
-{
- size_t i;
-
- if (hw_features == NULL)
- return;
-
- for (i = 0; i < num_hw_features; i++) {
- os_free(hw_features[i].channels);
- os_free(hw_features[i].rates);
- }
-
- os_free(hw_features);
-}
-
-
-void wpa_supplicant_sta_rx(void *ctx, const u8 *buf, size_t len,
- struct ieee80211_rx_status *rx_status)
-{
- struct wpa_priv_interface *iface = ctx;
- struct msghdr msg;
- struct iovec io[3];
- int event = PRIVSEP_EVENT_STA_RX;
-
- wpa_printf(MSG_DEBUG, "STA RX from driver");
- io[0].iov_base = &event;
- io[0].iov_len = sizeof(event);
- io[1].iov_base = (u8 *) rx_status;
- io[1].iov_len = sizeof(*rx_status);
- io[2].iov_base = (u8 *) buf;
- io[2].iov_len = len;
-
- os_memset(&msg, 0, sizeof(msg));
- msg.msg_iov = io;
- msg.msg_iovlen = 3;
- msg.msg_name = &iface->drv_addr;
- msg.msg_namelen = sizeof(iface->drv_addr);
-
- if (sendmsg(iface->fd, &msg, 0) < 0)
- perror("sendmsg(wpas_socket)");
-}
-#endif /* CONFIG_CLIENT_MLME */
-
-
static void wpa_priv_terminate(int sig, void *eloop_ctx, void *signal_ctx)
{
wpa_printf(MSG_DEBUG, "wpa_priv termination requested");
@@ -1180,7 +1000,7 @@ int main(int argc, char *argv[])
wpa_printf(MSG_DEBUG, "wpa_priv control directory: '%s'", ctrl_dir);
- if (eloop_init(NULL)) {
+ if (eloop_init()) {
wpa_printf(MSG_ERROR, "Failed to initialize event loop");
goto out;
}
diff --git a/contrib/wpa/wpa_supplicant/wpa_supplicant.c b/contrib/wpa/wpa_supplicant/wpa_supplicant.c
index 54bbcd9..37a539d 100644
--- a/contrib/wpa/wpa_supplicant/wpa_supplicant.c
+++ b/contrib/wpa/wpa_supplicant/wpa_supplicant.c
@@ -1,6 +1,6 @@
/*
* WPA Supplicant
- * Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2003-2010, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -21,28 +21,35 @@
#include "common.h"
#include "eapol_supp/eapol_supp_sm.h"
#include "eap_peer/eap.h"
-#include "wpa.h"
+#include "eap_server/eap_methods.h"
+#include "rsn_supp/wpa.h"
#include "eloop.h"
-#include "drivers/driver.h"
#include "config.h"
#include "l2_packet/l2_packet.h"
#include "wpa_supplicant_i.h"
+#include "driver_i.h"
#include "ctrl_iface.h"
-#include "ctrl_iface_dbus.h"
#include "pcsc_funcs.h"
-#include "version.h"
-#include "preauth.h"
-#include "pmksa_cache.h"
-#include "wpa_ctrl.h"
+#include "common/version.h"
+#include "rsn_supp/preauth.h"
+#include "rsn_supp/pmksa_cache.h"
+#include "common/wpa_ctrl.h"
#include "mlme.h"
-#include "ieee802_11_defs.h"
+#include "common/ieee802_11_defs.h"
#include "blacklist.h"
#include "wpas_glue.h"
#include "wps_supplicant.h"
+#include "ibss_rsn.h"
+#include "sme.h"
+#include "ap.h"
+#include "notify.h"
+#include "bgscan.h"
+#include "bss.h"
+#include "scan.h"
const char *wpa_supplicant_version =
"wpa_supplicant v" VERSION_STR "\n"
-"Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi> and contributors";
+"Copyright (c) 2003-2010, Jouni Malinen <j@w1.fi> and contributors";
const char *wpa_supplicant_license =
"This program is free software. You can distribute it and/or modify it\n"
@@ -111,10 +118,10 @@ const char *wpa_supplicant_full_license5 =
extern int wpa_debug_level;
extern int wpa_debug_show_keys;
extern int wpa_debug_timestamp;
+extern struct wpa_driver_ops *wpa_drivers[];
/* Configure default/group WEP keys for static WEP */
-static int wpa_set_wep_keys(struct wpa_supplicant *wpa_s,
- struct wpa_ssid *ssid)
+int wpa_set_wep_keys(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
{
int i, set = 0;
@@ -138,13 +145,13 @@ static int wpa_supplicant_set_wpa_none_key(struct wpa_supplicant *wpa_s,
{
u8 key[32];
size_t keylen;
- wpa_alg alg;
+ enum wpa_alg alg;
u8 seq[6] = { 0 };
/* IBSS/WPA-None uses only one key (Group) for both receiving and
* sending unicast and multicast packets. */
- if (ssid->mode != IEEE80211_MODE_IBSS) {
+ if (ssid->mode != WPAS_MODE_IBSS) {
wpa_printf(MSG_INFO, "WPA: Invalid mode %d (not IBSS/ad-hoc) "
"for WPA-None", ssid->mode);
return -1;
@@ -211,7 +218,7 @@ void wpa_supplicant_req_auth_timeout(struct wpa_supplicant *wpa_s,
int sec, int usec)
{
if (wpa_s->conf && wpa_s->conf->ap_scan == 0 &&
- wpa_s->driver && IS_WIRED(wpa_s->driver))
+ (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED))
return;
wpa_msg(wpa_s, MSG_DEBUG, "Setting authentication timeout: %d sec "
@@ -250,6 +257,21 @@ void wpa_supplicant_initiate_eapol(struct wpa_supplicant *wpa_s)
struct eapol_config eapol_conf;
struct wpa_ssid *ssid = wpa_s->current_ssid;
+#ifdef CONFIG_IBSS_RSN
+ if (ssid->mode == WPAS_MODE_IBSS &&
+ wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
+ wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE) {
+ /*
+ * RSN IBSS authentication is per-STA and we can disable the
+ * per-BSSID EAPOL authentication.
+ */
+ eapol_sm_notify_portControl(wpa_s->eapol, ForceAuthorized);
+ eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
+ eapol_sm_notify_eap_fail(wpa_s->eapol, FALSE);
+ return;
+ }
+#endif /* CONFIG_IBSS_RSN */
+
eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
eapol_sm_notify_eap_fail(wpa_s->eapol, FALSE);
@@ -271,9 +293,8 @@ void wpa_supplicant_initiate_eapol(struct wpa_supplicant *wpa_s)
EAPOL_REQUIRE_KEY_BROADCAST;
}
- if (wpa_s->conf && wpa_s->driver && IS_WIRED(wpa_s->driver)) {
+ if (wpa_s->conf && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED))
eapol_conf.required_keys = 0;
- }
}
if (wpa_s->conf)
eapol_conf.fast_reauth = wpa_s->conf->fast_reauth;
@@ -342,6 +363,7 @@ void wpa_supplicant_set_non_wpa_policy(struct wpa_supplicant *wpa_s,
static void wpa_supplicant_cleanup(struct wpa_supplicant *wpa_s)
{
+ bgscan_deinit(wpa_s);
scard_deinit(wpa_s->scard);
wpa_s->scard = NULL;
wpa_sm_set_scard_ctx(wpa_s->wpa, NULL);
@@ -358,6 +380,9 @@ static void wpa_supplicant_cleanup(struct wpa_supplicant *wpa_s)
wpa_s->ctrl_iface = NULL;
}
if (wpa_s->conf != NULL) {
+ struct wpa_ssid *ssid;
+ for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next)
+ wpas_notify_network_removed(wpa_s, ssid);
wpa_config_free(wpa_s->conf);
wpa_s->conf = NULL;
}
@@ -376,8 +401,7 @@ static void wpa_supplicant_cleanup(struct wpa_supplicant *wpa_s)
wpa_s->wpa = NULL;
wpa_blacklist_clear(wpa_s);
- wpa_scan_results_free(wpa_s->scan_res);
- wpa_s->scan_res = NULL;
+ wpa_bss_deinit(wpa_s);
wpa_supplicant_cancel_scan(wpa_s);
wpa_supplicant_cancel_auth_timeout(wpa_s);
@@ -388,6 +412,21 @@ static void wpa_supplicant_cleanup(struct wpa_supplicant *wpa_s)
wpabuf_free(wpa_s->pending_eapol_rx);
wpa_s->pending_eapol_rx = NULL;
+
+#ifdef CONFIG_IBSS_RSN
+ ibss_rsn_deinit(wpa_s->ibss_rsn);
+ wpa_s->ibss_rsn = NULL;
+#endif /* CONFIG_IBSS_RSN */
+
+#ifdef CONFIG_SME
+ os_free(wpa_s->sme.ft_ies);
+ wpa_s->sme.ft_ies = NULL;
+ wpa_s->sme.ft_ies_len = 0;
+#endif /* CONFIG_SME */
+
+#ifdef CONFIG_AP
+ wpa_supplicant_ap_deinit(wpa_s);
+#endif /* CONFIG_AP */
}
@@ -443,7 +482,7 @@ void wpa_clear_keys(struct wpa_supplicant *wpa_s, const u8 *addr)
* @state: State (wpa_state; WPA_*)
* Returns: The state name as a printable text string
*/
-const char * wpa_supplicant_state_txt(int state)
+const char * wpa_supplicant_state_txt(enum wpa_states state)
{
switch (state) {
case WPA_DISCONNECTED:
@@ -452,6 +491,8 @@ const char * wpa_supplicant_state_txt(int state)
return "INACTIVE";
case WPA_SCANNING:
return "SCANNING";
+ case WPA_AUTHENTICATING:
+ return "AUTHENTICATING";
case WPA_ASSOCIATING:
return "ASSOCIATING";
case WPA_ASSOCIATED:
@@ -476,8 +517,11 @@ const char * wpa_supplicant_state_txt(int state)
* This function is called whenever the connection state changes, e.g.,
* association is completed for WPA/WPA2 4-Way Handshake is started.
*/
-void wpa_supplicant_set_state(struct wpa_supplicant *wpa_s, wpa_states state)
+void wpa_supplicant_set_state(struct wpa_supplicant *wpa_s,
+ enum wpa_states state)
{
+ enum wpa_states old_state = wpa_s->wpa_state;
+
wpa_printf(MSG_DEBUG, "State: %s -> %s",
wpa_supplicant_state_txt(wpa_s->wpa_state),
wpa_supplicant_state_txt(state));
@@ -485,9 +529,6 @@ void wpa_supplicant_set_state(struct wpa_supplicant *wpa_s, wpa_states state)
if (state != WPA_SCANNING)
wpa_supplicant_notify_scanning(wpa_s, 0);
- wpa_supplicant_dbus_notify_state_change(wpa_s, state,
- wpa_s->wpa_state);
-
if (state == WPA_COMPLETED && wpa_s->new_connection) {
#if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
struct wpa_ssid *ssid = wpa_s->current_ssid;
@@ -501,35 +542,60 @@ void wpa_supplicant_set_state(struct wpa_supplicant *wpa_s, wpa_states state)
wpa_s->new_connection = 0;
wpa_s->reassociated_connection = 1;
wpa_drv_set_operstate(wpa_s, 1);
+ wpa_s->after_wps = 0;
} else if (state == WPA_DISCONNECTED || state == WPA_ASSOCIATING ||
state == WPA_ASSOCIATED) {
wpa_s->new_connection = 1;
wpa_drv_set_operstate(wpa_s, 0);
}
wpa_s->wpa_state = state;
+
+ if (wpa_s->wpa_state != old_state)
+ wpas_notify_state_changed(wpa_s, wpa_s->wpa_state, old_state);
+}
+
+
+void wpa_supplicant_terminate_proc(struct wpa_global *global)
+{
+ int pending = 0;
+#ifdef CONFIG_WPS
+ struct wpa_supplicant *wpa_s = global->ifaces;
+ while (wpa_s) {
+ if (wpas_wps_terminate_pending(wpa_s) == 1)
+ pending = 1;
+ wpa_s = wpa_s->next;
+ }
+#endif /* CONFIG_WPS */
+ if (pending)
+ return;
+ eloop_terminate();
}
-static void wpa_supplicant_terminate(int sig, void *eloop_ctx,
- void *signal_ctx)
+static void wpa_supplicant_terminate(int sig, void *signal_ctx)
{
- struct wpa_global *global = eloop_ctx;
+ struct wpa_global *global = signal_ctx;
struct wpa_supplicant *wpa_s;
for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_TERMINATING "- signal %d "
"received", sig);
}
- eloop_terminate();
+ wpa_supplicant_terminate_proc(global);
}
static void wpa_supplicant_clear_status(struct wpa_supplicant *wpa_s)
{
+ enum wpa_states old_state = wpa_s->wpa_state;
+
wpa_s->pairwise_cipher = 0;
wpa_s->group_cipher = 0;
wpa_s->mgmt_group_cipher = 0;
wpa_s->key_mgmt = 0;
wpa_s->wpa_state = WPA_DISCONNECTED;
+
+ if (wpa_s->wpa_state != old_state)
+ wpas_notify_state_changed(wpa_s, wpa_s->wpa_state, old_state);
}
@@ -547,7 +613,10 @@ static void wpa_supplicant_clear_status(struct wpa_supplicant *wpa_s)
int wpa_supplicant_reload_configuration(struct wpa_supplicant *wpa_s)
{
struct wpa_config *conf;
+ struct wpa_ssid *old_ssid;
int reconf_ctrl;
+ int old_ap_scan;
+
if (wpa_s->confname == NULL)
return -1;
conf = wpa_config_read(wpa_s->confname);
@@ -568,7 +637,11 @@ int wpa_supplicant_reload_configuration(struct wpa_supplicant *wpa_s)
}
eapol_sm_invalidate_cached_session(wpa_s->eapol);
+ old_ssid = wpa_s->current_ssid;
wpa_s->current_ssid = NULL;
+ if (old_ssid != wpa_s->current_ssid)
+ wpas_notify_network_changed(wpa_s);
+
/*
* TODO: should notify EAPOL SM about changes in opensc_engine_path,
* pkcs11_engine_path, pkcs11_module_path.
@@ -584,8 +657,13 @@ int wpa_supplicant_reload_configuration(struct wpa_supplicant *wpa_s)
wpa_sm_set_config(wpa_s->wpa, NULL);
wpa_sm_set_fast_reauth(wpa_s->wpa, wpa_s->conf->fast_reauth);
rsn_preauth_deinit(wpa_s->wpa);
+
+ old_ap_scan = wpa_s->conf->ap_scan;
wpa_config_free(wpa_s->conf);
wpa_s->conf = conf;
+ if (old_ap_scan != wpa_s->conf->ap_scan)
+ wpas_notify_ap_scan_changed(wpa_s);
+
if (reconf_ctrl)
wpa_s->ctrl_iface = wpa_supplicant_ctrl_iface_init(wpa_s);
@@ -597,21 +675,20 @@ int wpa_supplicant_reload_configuration(struct wpa_supplicant *wpa_s)
}
-static void wpa_supplicant_reconfig(int sig, void *eloop_ctx,
- void *signal_ctx)
+static void wpa_supplicant_reconfig(int sig, void *signal_ctx)
{
- struct wpa_global *global = eloop_ctx;
+ struct wpa_global *global = signal_ctx;
struct wpa_supplicant *wpa_s;
wpa_printf(MSG_DEBUG, "Signal %d received - reconfiguring", sig);
for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
if (wpa_supplicant_reload_configuration(wpa_s) < 0) {
- eloop_terminate();
+ wpa_supplicant_terminate_proc(global);
}
}
}
-static wpa_cipher cipher_suite2driver(int cipher)
+enum wpa_cipher cipher_suite2driver(int cipher)
{
switch (cipher) {
case WPA_CIPHER_NONE:
@@ -629,7 +706,7 @@ static wpa_cipher cipher_suite2driver(int cipher)
}
-static wpa_key_mgmt key_mgmt2driver(int key_mgmt)
+enum wpa_key_mgmt key_mgmt2driver(int key_mgmt)
{
switch (key_mgmt) {
case WPA_KEY_MGMT_NONE:
@@ -693,7 +770,7 @@ static int wpa_supplicant_suites_from_ai(struct wpa_supplicant *wpa_s,
#ifdef CONFIG_IEEE80211W
if (!(ie->capabilities & WPA_CAPABILITY_MFPC) &&
- ssid->ieee80211w == IEEE80211W_REQUIRED) {
+ ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) {
wpa_msg(wpa_s, MSG_INFO, "WPA: Driver associated with an AP "
"that does not support management frame protection - "
"reject");
@@ -720,8 +797,7 @@ static int wpa_supplicant_suites_from_ai(struct wpa_supplicant *wpa_s,
* available).
*/
int wpa_supplicant_set_suites(struct wpa_supplicant *wpa_s,
- struct wpa_scan_res *bss,
- struct wpa_ssid *ssid,
+ struct wpa_bss *bss, struct wpa_ssid *ssid,
u8 *wpa_ie, size_t *wpa_ie_len)
{
struct wpa_ie_data ie;
@@ -729,8 +805,8 @@ int wpa_supplicant_set_suites(struct wpa_supplicant *wpa_s,
const u8 *bss_wpa, *bss_rsn;
if (bss) {
- bss_wpa = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
- bss_rsn = wpa_scan_get_ie(bss, WLAN_EID_RSN);
+ bss_wpa = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
+ bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
} else
bss_wpa = bss_rsn = NULL;
@@ -763,7 +839,7 @@ int wpa_supplicant_set_suites(struct wpa_supplicant *wpa_s,
ie.key_mgmt = ssid->key_mgmt;
#ifdef CONFIG_IEEE80211W
ie.mgmt_group_cipher =
- ssid->ieee80211w != NO_IEEE80211W ?
+ ssid->ieee80211w != NO_MGMT_FRAME_PROTECTION ?
WPA_CIPHER_AES_128_CMAC : 0;
#endif /* CONFIG_IEEE80211W */
wpa_printf(MSG_DEBUG, "WPA: Set cipher suites based "
@@ -870,7 +946,7 @@ int wpa_supplicant_set_suites(struct wpa_supplicant *wpa_s,
#ifdef CONFIG_IEEE80211W
sel = ie.mgmt_group_cipher;
- if (ssid->ieee80211w == NO_IEEE80211W ||
+ if (ssid->ieee80211w == NO_MGMT_FRAME_PROTECTION ||
!(ie.capabilities & WPA_CAPABILITY_MFPC))
sel = 0;
if (sel & WPA_CIPHER_AES_128_CMAC) {
@@ -883,6 +959,7 @@ int wpa_supplicant_set_suites(struct wpa_supplicant *wpa_s,
}
wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP,
wpa_s->mgmt_group_cipher);
+ wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP, ssid->ieee80211w);
#endif /* CONFIG_IEEE80211W */
if (wpa_sm_set_assoc_wpa_ie_default(wpa_s->wpa, wpa_ie, wpa_ie_len)) {
@@ -909,37 +986,62 @@ int wpa_supplicant_set_suites(struct wpa_supplicant *wpa_s,
* This function is used to request %wpa_supplicant to associate with a BSS.
*/
void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
- struct wpa_scan_res *bss, struct wpa_ssid *ssid)
+ struct wpa_bss *bss, struct wpa_ssid *ssid)
{
u8 wpa_ie[80];
size_t wpa_ie_len;
- int use_crypt, ret, i;
- int algs = AUTH_ALG_OPEN_SYSTEM;
- wpa_cipher cipher_pairwise, cipher_group;
+ int use_crypt, ret, i, bssid_changed;
+ int algs = WPA_AUTH_ALG_OPEN;
+ enum wpa_cipher cipher_pairwise, cipher_group;
struct wpa_driver_associate_params params;
int wep_keys_set = 0;
struct wpa_driver_capa capa;
int assoc_failed = 0;
+ struct wpa_ssid *old_ssid;
+
+ if (ssid->mode == WPAS_MODE_AP) {
+#ifdef CONFIG_AP
+ if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP)) {
+ wpa_printf(MSG_INFO, "Driver does not support AP "
+ "mode");
+ return;
+ }
+ wpa_supplicant_create_ap(wpa_s, ssid);
+ wpa_s->current_bss = bss;
+#else /* CONFIG_AP */
+ wpa_printf(MSG_ERROR, "AP mode support not included in the "
+ "build");
+#endif /* CONFIG_AP */
+ return;
+ }
+
+ if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
+ ssid->mode == IEEE80211_MODE_INFRA) {
+ sme_authenticate(wpa_s, bss, ssid);
+ return;
+ }
wpa_s->reassociate = 0;
if (bss) {
#ifdef CONFIG_IEEE80211R
- const u8 *md = NULL;
+ const u8 *ie, *md = NULL;
#endif /* CONFIG_IEEE80211R */
- const u8 *ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
wpa_msg(wpa_s, MSG_INFO, "Trying to associate with " MACSTR
" (SSID='%s' freq=%d MHz)", MAC2STR(bss->bssid),
- ie ? wpa_ssid_txt(ie + 2, ie[1]) : "", bss->freq);
+ wpa_ssid_txt(bss->ssid, bss->ssid_len), bss->freq);
+ bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
os_memset(wpa_s->bssid, 0, ETH_ALEN);
os_memcpy(wpa_s->pending_bssid, bss->bssid, ETH_ALEN);
+ if (bssid_changed)
+ wpas_notify_bssid_changed(wpa_s);
#ifdef CONFIG_IEEE80211R
- ie = wpa_scan_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
+ ie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
if (ie && ie[1] >= MOBILITY_DOMAIN_ID_LEN)
md = ie + 2;
- wpa_sm_set_ft_params(wpa_s->wpa, md, NULL, 0, NULL);
+ wpa_sm_set_ft_params(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0);
if (md) {
/* Prepare for the next transition */
- wpa_ft_prepare_auth_request(wpa_s->wpa);
+ wpa_ft_prepare_auth_request(wpa_s->wpa, ie);
}
#endif /* CONFIG_IEEE80211R */
#ifdef CONFIG_WPS
@@ -964,37 +1066,25 @@ void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
* previous association. */
wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
- if (wpa_drv_set_mode(wpa_s, ssid->mode)) {
- wpa_printf(MSG_WARNING, "Failed to set operating mode");
- assoc_failed = 1;
- }
-
#ifdef IEEE8021X_EAPOL
if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
if (ssid->leap) {
if (ssid->non_leap == 0)
- algs = AUTH_ALG_LEAP;
+ algs = WPA_AUTH_ALG_LEAP;
else
- algs |= AUTH_ALG_LEAP;
+ algs |= WPA_AUTH_ALG_LEAP;
}
}
#endif /* IEEE8021X_EAPOL */
wpa_printf(MSG_DEBUG, "Automatic auth_alg selection: 0x%x", algs);
if (ssid->auth_alg) {
- algs = 0;
- if (ssid->auth_alg & WPA_AUTH_ALG_OPEN)
- algs |= AUTH_ALG_OPEN_SYSTEM;
- if (ssid->auth_alg & WPA_AUTH_ALG_SHARED)
- algs |= AUTH_ALG_SHARED_KEY;
- if (ssid->auth_alg & WPA_AUTH_ALG_LEAP)
- algs |= AUTH_ALG_LEAP;
+ algs = ssid->auth_alg;
wpa_printf(MSG_DEBUG, "Overriding auth_alg selection: 0x%x",
algs);
}
- wpa_drv_set_auth_alg(wpa_s, algs);
- if (bss && (wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE) ||
- wpa_scan_get_ie(bss, WLAN_EID_RSN)) &&
+ if (bss && (wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE) ||
+ wpa_bss_get_ie(bss, WLAN_EID_RSN)) &&
(ssid->key_mgmt & (WPA_KEY_MGMT_IEEE8021X | WPA_KEY_MGMT_PSK |
WPA_KEY_MGMT_FT_IEEE8021X |
WPA_KEY_MGMT_FT_PSK |
@@ -1081,20 +1171,19 @@ void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
wpa_supplicant_set_wpa_none_key(wpa_s, ssid);
}
- wpa_drv_set_drop_unencrypted(wpa_s, use_crypt);
wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATING);
os_memset(&params, 0, sizeof(params));
if (bss) {
- const u8 *ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
params.bssid = bss->bssid;
- params.ssid = ie ? ie + 2 : (u8 *) "";
- params.ssid_len = ie ? ie[1] : 0;
+ params.ssid = bss->ssid;
+ params.ssid_len = bss->ssid_len;
params.freq = bss->freq;
} else {
params.ssid = ssid->ssid;
params.ssid_len = ssid->ssid_len;
}
- if (ssid->mode == 1 && ssid->frequency > 0 && params.freq == 0)
+ if (ssid->mode == WPAS_MODE_IBSS && ssid->frequency > 0 &&
+ params.freq == 0)
params.freq = ssid->frequency; /* Initial channel for IBSS */
params.wpa_ie = wpa_ie;
params.wpa_ie_len = wpa_ie_len;
@@ -1110,7 +1199,7 @@ void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
}
params.wep_tx_keyidx = ssid->wep_tx_keyidx;
- if (wpa_s->driver_4way_handshake &&
+ if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
(params.key_mgmt_suite == KEY_MGMT_PSK ||
params.key_mgmt_suite == KEY_MGMT_FT_PSK)) {
params.passphrase = ssid->passphrase;
@@ -1118,20 +1207,12 @@ void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
params.psk = ssid->psk;
}
+ params.drop_unencrypted = use_crypt;
+
#ifdef CONFIG_IEEE80211W
- switch (ssid->ieee80211w) {
- case NO_IEEE80211W:
- params.mgmt_frame_protection = NO_MGMT_FRAME_PROTECTION;
- break;
- case IEEE80211W_OPTIONAL:
- params.mgmt_frame_protection = MGMT_FRAME_PROTECTION_OPTIONAL;
- break;
- case IEEE80211W_REQUIRED:
- params.mgmt_frame_protection = MGMT_FRAME_PROTECTION_REQUIRED;
- break;
- }
- if (ssid->ieee80211w != NO_IEEE80211W && bss) {
- const u8 *rsn = wpa_scan_get_ie(bss, WLAN_EID_RSN);
+ params.mgmt_frame_protection = ssid->ieee80211w;
+ if (ssid->ieee80211w != NO_MGMT_FRAME_PROTECTION && bss) {
+ const u8 *rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
struct wpa_ie_data ie;
if (rsn && wpa_parse_wpa_ie(rsn, 2 + rsn[1], &ie) == 0 &&
ie.capabilities &
@@ -1144,7 +1225,7 @@ void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
}
#endif /* CONFIG_IEEE80211W */
- if (wpa_s->use_client_mlme)
+ if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
ret = ieee80211_sta_associate(wpa_s, &params);
else
ret = wpa_drv_associate(wpa_s, &params);
@@ -1164,16 +1245,27 @@ void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
* management. */
wpa_supplicant_cancel_auth_timeout(wpa_s);
wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
+#ifdef CONFIG_IBSS_RSN
+ } else if (ssid->mode == WPAS_MODE_IBSS &&
+ wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
+ wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE) {
+ ibss_rsn_set_psk(wpa_s->ibss_rsn, ssid->psk);
+ /*
+ * RSN IBSS authentication is per-STA and we can disable the
+ * per-BSSID authentication.
+ */
+ wpa_supplicant_cancel_auth_timeout(wpa_s);
+#endif /* CONFIG_IBSS_RSN */
} else {
/* Timeout for IEEE 802.11 authentication and association */
int timeout = 60;
if (assoc_failed) {
/* give IBSS a bit more time */
- timeout = ssid->mode ? 10 : 5;
+ timeout = ssid->mode == WPAS_MODE_IBSS ? 10 : 5;
} else if (wpa_s->conf->ap_scan == 1) {
/* give IBSS a bit more time */
- timeout = ssid->mode ? 20 : 10;
+ timeout = ssid->mode == WPAS_MODE_IBSS ? 20 : 10;
}
wpa_supplicant_req_auth_timeout(wpa_s, timeout, 0);
}
@@ -1191,9 +1283,13 @@ void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
*/
eapol_sm_invalidate_cached_session(wpa_s->eapol);
}
+ old_ssid = wpa_s->current_ssid;
wpa_s->current_ssid = ssid;
+ wpa_s->current_bss = bss;
wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
wpa_supplicant_initiate_eapol(wpa_s);
+ if (old_ssid != wpa_s->current_ssid)
+ wpas_notify_network_changed(wpa_s);
}
@@ -1208,9 +1304,11 @@ void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
void wpa_supplicant_disassociate(struct wpa_supplicant *wpa_s,
int reason_code)
{
+ struct wpa_ssid *old_ssid;
u8 *addr = NULL;
+
if (!is_zero_ether_addr(wpa_s->bssid)) {
- if (wpa_s->use_client_mlme)
+ if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
ieee80211_sta_disassociate(wpa_s, reason_code);
else
wpa_drv_disassociate(wpa_s, wpa_s->bssid, reason_code);
@@ -1218,9 +1316,14 @@ void wpa_supplicant_disassociate(struct wpa_supplicant *wpa_s,
}
wpa_clear_keys(wpa_s, addr);
wpa_supplicant_mark_disassoc(wpa_s);
+ old_ssid = wpa_s->current_ssid;
wpa_s->current_ssid = NULL;
+ wpa_s->current_bss = NULL;
wpa_sm_set_config(wpa_s->wpa, NULL);
eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
+ if (old_ssid != wpa_s->current_ssid)
+ wpas_notify_network_changed(wpa_s);
+ eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL);
}
@@ -1235,9 +1338,11 @@ void wpa_supplicant_disassociate(struct wpa_supplicant *wpa_s,
void wpa_supplicant_deauthenticate(struct wpa_supplicant *wpa_s,
int reason_code)
{
+ struct wpa_ssid *old_ssid;
u8 *addr = NULL;
+
if (!is_zero_ether_addr(wpa_s->bssid)) {
- if (wpa_s->use_client_mlme)
+ if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
ieee80211_sta_deauthenticate(wpa_s, reason_code);
else
wpa_drv_deauthenticate(wpa_s, wpa_s->bssid,
@@ -1246,156 +1351,215 @@ void wpa_supplicant_deauthenticate(struct wpa_supplicant *wpa_s,
}
wpa_clear_keys(wpa_s, addr);
wpa_supplicant_mark_disassoc(wpa_s);
+ old_ssid = wpa_s->current_ssid;
wpa_s->current_ssid = NULL;
+ wpa_s->current_bss = NULL;
wpa_sm_set_config(wpa_s->wpa, NULL);
eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
+ if (old_ssid != wpa_s->current_ssid)
+ wpas_notify_network_changed(wpa_s);
+ eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL);
}
-static int wpa_supplicant_get_scan_results_old(struct wpa_supplicant *wpa_s)
+/**
+ * wpa_supplicant_enable_network - Mark a configured network as enabled
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * @ssid: wpa_ssid structure for a configured network or %NULL
+ *
+ * Enables the specified network or all networks if no network specified.
+ */
+void wpa_supplicant_enable_network(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid)
{
-#define SCAN_AP_LIMIT 128
- struct wpa_scan_result *results;
- int num, i;
- struct wpa_scan_results *res;
-
- results = os_malloc(SCAN_AP_LIMIT * sizeof(struct wpa_scan_result));
- if (results == NULL) {
- wpa_printf(MSG_WARNING, "Failed to allocate memory for scan "
- "results");
- return -1;
- }
+ struct wpa_ssid *other_ssid;
+ int was_disabled;
- num = wpa_drv_get_scan_results(wpa_s, results, SCAN_AP_LIMIT);
- wpa_printf(MSG_DEBUG, "Scan results: %d", num);
- if (num < 0) {
- wpa_printf(MSG_DEBUG, "Failed to get scan results");
- os_free(results);
- return -1;
- }
- if (num > SCAN_AP_LIMIT) {
- wpa_printf(MSG_INFO, "Not enough room for all APs (%d < %d)",
- num, SCAN_AP_LIMIT);
- num = SCAN_AP_LIMIT;
- }
+ if (ssid == NULL) {
+ other_ssid = wpa_s->conf->ssid;
+ while (other_ssid) {
+ if (other_ssid == wpa_s->current_ssid &&
+ other_ssid->disabled)
+ wpa_s->reassociate = 1;
- wpa_scan_results_free(wpa_s->scan_res);
- wpa_s->scan_res = NULL;
+ was_disabled = other_ssid->disabled;
- /* Convert old scan result data structure to the new one */
- res = os_zalloc(sizeof(*res));
- if (res == NULL) {
- os_free(results);
- return -1;
- }
- res->res = os_zalloc(num * sizeof(struct wpa_scan_res *));
- if (res->res == NULL) {
- os_free(results);
- os_free(res);
- return -1;
+ other_ssid->disabled = 0;
+
+ if (was_disabled != other_ssid->disabled)
+ wpas_notify_network_enabled_changed(
+ wpa_s, other_ssid);
+
+ other_ssid = other_ssid->next;
+ }
+ if (wpa_s->reassociate)
+ wpa_supplicant_req_scan(wpa_s, 0, 0);
+ } else if (ssid->disabled) {
+ if (wpa_s->current_ssid == NULL) {
+ /*
+ * Try to reassociate since there is no current
+ * configuration and a new network was made available.
+ */
+ wpa_s->reassociate = 1;
+ wpa_supplicant_req_scan(wpa_s, 0, 0);
+ }
+
+ was_disabled = ssid->disabled;
+
+ ssid->disabled = 0;
+
+ if (was_disabled != ssid->disabled)
+ wpas_notify_network_enabled_changed(wpa_s, ssid);
}
+}
+
- for (i = 0; i < num; i++) {
- struct wpa_scan_result *bss = &results[i];
- struct wpa_scan_res *r;
- size_t ie_len;
- u8 *pos;
+/**
+ * wpa_supplicant_disable_network - Mark a configured network as disabled
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * @ssid: wpa_ssid structure for a configured network or %NULL
+ *
+ * Disables the specified network or all networks if no network specified.
+ */
+void wpa_supplicant_disable_network(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid)
+{
+ struct wpa_ssid *other_ssid;
+ int was_disabled;
- ie_len = 2 + bss->ssid_len + bss->rsn_ie_len + bss->wpa_ie_len;
- if (bss->maxrate)
- ie_len += 3;
- if (bss->mdie_present)
- ie_len += 5;
+ if (ssid == NULL) {
+ other_ssid = wpa_s->conf->ssid;
+ while (other_ssid) {
+ was_disabled = other_ssid->disabled;
- r = os_zalloc(sizeof(*r) + ie_len);
- if (r == NULL)
- break;
+ other_ssid->disabled = 1;
- os_memcpy(r->bssid, bss->bssid, ETH_ALEN);
- r->freq = bss->freq;
- r->caps = bss->caps;
- r->qual = bss->qual;
- r->noise = bss->noise;
- r->level = bss->level;
- r->tsf = bss->tsf;
- r->ie_len = ie_len;
-
- pos = (u8 *) (r + 1);
-
- /* SSID IE */
- *pos++ = WLAN_EID_SSID;
- *pos++ = bss->ssid_len;
- os_memcpy(pos, bss->ssid, bss->ssid_len);
- pos += bss->ssid_len;
-
- if (bss->maxrate) {
- /* Fake Supported Rate IE to include max rate */
- *pos++ = WLAN_EID_SUPP_RATES;
- *pos++ = 1;
- *pos++ = bss->maxrate;
- }
+ if (was_disabled != other_ssid->disabled)
+ wpas_notify_network_enabled_changed(
+ wpa_s, other_ssid);
- if (bss->rsn_ie_len) {
- os_memcpy(pos, bss->rsn_ie, bss->rsn_ie_len);
- pos += bss->rsn_ie_len;
+ other_ssid = other_ssid->next;
}
+ if (wpa_s->current_ssid)
+ wpa_supplicant_disassociate(
+ wpa_s, WLAN_REASON_DEAUTH_LEAVING);
+ } else {
+ if (ssid == wpa_s->current_ssid)
+ wpa_supplicant_disassociate(
+ wpa_s, WLAN_REASON_DEAUTH_LEAVING);
- if (bss->mdie_present) {
- os_memcpy(pos, bss->mdie, 5);
- pos += 5;
- }
+ was_disabled = ssid->disabled;
- if (bss->wpa_ie_len) {
- os_memcpy(pos, bss->wpa_ie, bss->wpa_ie_len);
- pos += bss->wpa_ie_len;
- }
+ ssid->disabled = 1;
- res->res[res->num++] = r;
+ if (was_disabled != ssid->disabled)
+ wpas_notify_network_enabled_changed(wpa_s, ssid);
}
+}
- os_free(results);
- wpa_s->scan_res = res;
- return 0;
+/**
+ * wpa_supplicant_select_network - Attempt association with a network
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * @ssid: wpa_ssid structure for a configured network or %NULL for any network
+ */
+void wpa_supplicant_select_network(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid)
+{
+
+ struct wpa_ssid *other_ssid;
+
+ if (ssid && ssid != wpa_s->current_ssid && wpa_s->current_ssid)
+ wpa_supplicant_disassociate(
+ wpa_s, WLAN_REASON_DEAUTH_LEAVING);
+
+ /*
+ * Mark all other networks disabled or mark all networks enabled if no
+ * network specified.
+ */
+ other_ssid = wpa_s->conf->ssid;
+ while (other_ssid) {
+ int was_disabled = other_ssid->disabled;
+
+ other_ssid->disabled = ssid ? (ssid->id != other_ssid->id) : 0;
+
+ if (was_disabled != other_ssid->disabled)
+ wpas_notify_network_enabled_changed(wpa_s, other_ssid);
+
+ other_ssid = other_ssid->next;
+ }
+ wpa_s->disconnected = 0;
+ wpa_s->reassociate = 1;
+ wpa_supplicant_req_scan(wpa_s, 0, 0);
+
+ if (ssid)
+ wpas_notify_network_selected(wpa_s, ssid);
}
/**
- * wpa_supplicant_get_scan_results - Get scan results
- * @wpa_s: Pointer to wpa_supplicant data
- * Returns: 0 on success, -1 on failure
+ * wpa_supplicant_set_ap_scan - Set AP scan mode for interface
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * @ap_scan: AP scan mode
+ * Returns: 0 if succeed or -1 if ap_scan has an invalid value
*
- * This function is request the current scan results from the driver and stores
- * a local copy of the results in wpa_s->scan_res.
*/
-int wpa_supplicant_get_scan_results(struct wpa_supplicant *wpa_s)
+int wpa_supplicant_set_ap_scan(struct wpa_supplicant *wpa_s, int ap_scan)
{
- int ret;
-
- if (wpa_s->use_client_mlme) {
- wpa_scan_results_free(wpa_s->scan_res);
- wpa_s->scan_res = ieee80211_sta_get_scan_results(wpa_s);
- if (wpa_s->scan_res == NULL) {
- wpa_printf(MSG_DEBUG, "Failed to get scan results");
- ret = -1;
- } else
- ret = 0;
- } else if (wpa_s->driver->get_scan_results2 == NULL)
- ret = wpa_supplicant_get_scan_results_old(wpa_s);
- else {
- wpa_scan_results_free(wpa_s->scan_res);
- wpa_s->scan_res = wpa_drv_get_scan_results2(wpa_s);
- if (wpa_s->scan_res == NULL) {
- wpa_printf(MSG_DEBUG, "Failed to get scan results");
- ret = -1;
- } else
- ret = 0;
- }
- if (wpa_s->scan_res)
- wpa_scan_sort_results(wpa_s->scan_res);
+ int old_ap_scan;
+
+ if (ap_scan < 0 || ap_scan > 2)
+ return -1;
+
+ old_ap_scan = wpa_s->conf->ap_scan;
+ wpa_s->conf->ap_scan = ap_scan;
+
+ if (old_ap_scan != wpa_s->conf->ap_scan)
+ wpas_notify_ap_scan_changed(wpa_s);
+
+ return 0;
+}
+
+
+/**
+ * wpa_supplicant_set_debug_params - Set global debug params
+ * @global: wpa_global structure
+ * @debug_level: debug level
+ * @debug_timestamp: determines if show timestamp in debug data
+ * @debug_show_keys: determines if show keys in debug data
+ * Returns: 0 if succeed or -1 if debug_level has wrong value
+ */
+int wpa_supplicant_set_debug_params(struct wpa_global *global, int debug_level,
+ int debug_timestamp, int debug_show_keys)
+{
+
+ int old_level, old_timestamp, old_show_keys;
+
+ /* check for allowed debuglevels */
+ if (debug_level != MSG_MSGDUMP &&
+ debug_level != MSG_DEBUG &&
+ debug_level != MSG_INFO &&
+ debug_level != MSG_WARNING &&
+ debug_level != MSG_ERROR)
+ return -1;
+
+ old_level = wpa_debug_level;
+ old_timestamp = wpa_debug_timestamp;
+ old_show_keys = wpa_debug_show_keys;
+
+ wpa_debug_level = debug_level;
+ wpa_debug_timestamp = debug_timestamp ? 1 : 0;
+ wpa_debug_show_keys = debug_show_keys ? 1 : 0;
- return ret;
+ if (wpa_debug_level != old_level)
+ wpas_notify_debug_level_changed(global);
+ if (wpa_debug_timestamp != old_timestamp)
+ wpas_notify_debug_timestamp_changed(global);
+ if (wpa_debug_show_keys != old_show_keys)
+ wpas_notify_debug_show_keys_changed(global);
+
+ return 0;
}
@@ -1413,7 +1577,7 @@ struct wpa_ssid * wpa_supplicant_get_ssid(struct wpa_supplicant *wpa_s)
u8 bssid[ETH_ALEN];
int wired;
- if (wpa_s->use_client_mlme) {
+ if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) {
if (ieee80211_sta_get_ssid(wpa_s, ssid, &ssid_len)) {
wpa_printf(MSG_WARNING, "Could not read SSID from "
"MLME.");
@@ -1429,15 +1593,15 @@ struct wpa_ssid * wpa_supplicant_get_ssid(struct wpa_supplicant *wpa_s)
ssid_len = res;
}
- if (wpa_s->use_client_mlme)
+ if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
os_memcpy(bssid, wpa_s->bssid, ETH_ALEN);
else if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
wpa_printf(MSG_WARNING, "Could not read BSSID from driver.");
return NULL;
}
- wired = wpa_s->conf->ap_scan == 0 && wpa_s->driver &&
- IS_WIRED(wpa_s->driver);
+ wired = wpa_s->conf->ap_scan == 0 &&
+ (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED);
entry = wpa_s->conf->ssid;
while (entry) {
@@ -1466,11 +1630,13 @@ static int wpa_supplicant_set_driver(struct wpa_supplicant *wpa_s,
const char *name)
{
int i;
+ size_t len;
+ const char *pos;
if (wpa_s == NULL)
return -1;
- if (wpa_supplicant_drivers[0] == NULL) {
+ if (wpa_drivers[0] == NULL) {
wpa_printf(MSG_ERROR, "No driver interfaces build into "
"wpa_supplicant.");
return -1;
@@ -1478,24 +1644,45 @@ static int wpa_supplicant_set_driver(struct wpa_supplicant *wpa_s,
if (name == NULL) {
/* default to first driver in the list */
- wpa_s->driver = wpa_supplicant_drivers[0];
+ wpa_s->driver = wpa_drivers[0];
wpa_s->global_drv_priv = wpa_s->global->drv_priv[0];
return 0;
}
- for (i = 0; wpa_supplicant_drivers[i]; i++) {
- if (os_strcmp(name, wpa_supplicant_drivers[i]->name) == 0) {
- wpa_s->driver = wpa_supplicant_drivers[i];
+ pos = os_strchr(name, ',');
+ if (pos)
+ len = pos - name;
+ else
+ len = os_strlen(name);
+ for (i = 0; wpa_drivers[i]; i++) {
+ if (os_strlen(wpa_drivers[i]->name) == len &&
+ os_strncmp(name, wpa_drivers[i]->name, len) ==
+ 0) {
+ wpa_s->driver = wpa_drivers[i];
wpa_s->global_drv_priv = wpa_s->global->drv_priv[i];
return 0;
}
}
- wpa_printf(MSG_ERROR, "Unsupported driver '%s'.\n", name);
+ wpa_printf(MSG_ERROR, "Unsupported driver '%s'.", name);
return -1;
}
+/**
+ * wpa_supplicant_rx_eapol - Deliver a received EAPOL frame to wpa_supplicant
+ * @ctx: Context pointer (wpa_s); this is the ctx variable registered
+ * with struct wpa_driver_ops::init()
+ * @src_addr: Source address of the EAPOL frame
+ * @buf: EAPOL data starting from the EAPOL header (i.e., no Ethernet header)
+ * @len: Length of the EAPOL data
+ *
+ * This function is called for each received EAPOL frame. Most driver
+ * interfaces rely on more generic OS mechanism for receiving frames through
+ * l2_packet, but if such a mechanism is not available, the driver wrapper may
+ * take care of received EAPOL frames and deliver them to the core supplicant
+ * code by calling this function.
+ */
void wpa_supplicant_rx_eapol(void *ctx, const u8 *src_addr,
const u8 *buf, size_t len)
{
@@ -1525,6 +1712,13 @@ void wpa_supplicant_rx_eapol(void *ctx, const u8 *src_addr,
return;
}
+#ifdef CONFIG_AP
+ if (wpa_s->ap_iface) {
+ wpa_supplicant_ap_rx_eapol(wpa_s, src_addr, buf, len);
+ return;
+ }
+#endif /* CONFIG_AP */
+
if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE) {
wpa_printf(MSG_DEBUG, "Ignored received EAPOL frame since "
"no key management is configured");
@@ -1532,9 +1726,11 @@ void wpa_supplicant_rx_eapol(void *ctx, const u8 *src_addr,
}
if (wpa_s->eapol_received == 0 &&
- (!wpa_s->driver_4way_handshake ||
+ (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) ||
!wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
- wpa_s->wpa_state != WPA_COMPLETED)) {
+ wpa_s->wpa_state != WPA_COMPLETED) &&
+ (wpa_s->current_ssid == NULL ||
+ wpa_s->current_ssid->mode != IEEE80211_MODE_IBSS)) {
/* Timeout for completing IEEE 802.1X and WPA authentication */
wpa_supplicant_req_auth_timeout(
wpa_s,
@@ -1551,6 +1747,14 @@ void wpa_supplicant_rx_eapol(void *ctx, const u8 *src_addr,
return;
}
+#ifdef CONFIG_IBSS_RSN
+ if (wpa_s->current_ssid &&
+ wpa_s->current_ssid->mode == WPAS_MODE_IBSS) {
+ ibss_rsn_rx_eapol(wpa_s->ibss_rsn, src_addr, buf, len);
+ return;
+ }
+#endif /* CONFIG_IBSS_RSN */
+
/* Source address of the incoming EAPOL frame could be compared to the
* current BSSID. However, it is possible that a centralized
* Authenticator could be using another MAC address than the BSSID of
@@ -1562,7 +1766,7 @@ void wpa_supplicant_rx_eapol(void *ctx, const u8 *src_addr,
eapol_sm_rx_eapol(wpa_s->eapol, src_addr, buf, len) > 0)
return;
wpa_drv_poll(wpa_s);
- if (!wpa_s->driver_4way_handshake)
+ if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE))
wpa_sm_rx_eapol(wpa_s->wpa, src_addr, buf, len);
else if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
/*
@@ -1576,21 +1780,6 @@ void wpa_supplicant_rx_eapol(void *ctx, const u8 *src_addr,
}
-void wpa_supplicant_sta_free_hw_features(struct wpa_hw_modes *hw_features,
- size_t num_hw_features)
-{
- ieee80211_sta_free_hw_features(hw_features, num_hw_features);
-}
-
-
-void wpa_supplicant_sta_rx(void *ctx, const u8 *buf, size_t len,
- struct ieee80211_rx_status *rx_status)
-{
- struct wpa_supplicant *wpa_s = ctx;
- ieee80211_sta_rx(wpa_s, buf, len, rx_status);
-}
-
-
/**
* wpa_supplicant_driver_init - Initialize driver interface parameters
* @wpa_s: Pointer to wpa_supplicant data
@@ -1641,37 +1830,21 @@ int wpa_supplicant_driver_init(struct wpa_supplicant *wpa_s)
}
}
- /* Backwards compatibility call to set_wpa() handler. This is called
- * only just after init and just before deinit, so these handler can be
- * used to implement same functionality. */
- if (wpa_drv_set_wpa(wpa_s, 1) < 0) {
- struct wpa_driver_capa capa;
- if (wpa_drv_get_capa(wpa_s, &capa) < 0 ||
- !(capa.flags & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
- WPA_DRIVER_CAPA_KEY_MGMT_WPA2))) {
- wpa_printf(MSG_DEBUG, "Driver does not support WPA.");
- /* Continue to allow non-WPA modes to be used. */
- } else {
- wpa_printf(MSG_ERROR, "Failed to enable WPA in the "
- "driver.");
- return -1;
- }
- }
-
wpa_clear_keys(wpa_s, NULL);
/* Make sure that TKIP countermeasures are not left enabled (could
* happen if wpa_supplicant is killed during countermeasures. */
wpa_drv_set_countermeasures(wpa_s, 0);
- wpa_drv_set_drop_unencrypted(wpa_s, 1);
-
wpa_printf(MSG_DEBUG, "RSN: flushing PMKID list in the driver");
wpa_drv_flush_pmkid(wpa_s);
- wpa_s->prev_scan_ssid = BROADCAST_SSID_SCAN;
- wpa_supplicant_req_scan(wpa_s, interface_count, 100000);
- interface_count++;
+ wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN;
+ if (wpa_supplicant_enabled_networks(wpa_s->conf)) {
+ wpa_supplicant_req_scan(wpa_s, interface_count, 100000);
+ interface_count++;
+ } else
+ wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
return 0;
}
@@ -1692,6 +1865,7 @@ static struct wpa_supplicant * wpa_supplicant_alloc(void)
if (wpa_s == NULL)
return NULL;
wpa_s->scan_req = 1;
+ wpa_s->new_connection = 1;
return wpa_s;
}
@@ -1700,6 +1874,9 @@ static struct wpa_supplicant * wpa_supplicant_alloc(void)
static int wpa_supplicant_init_iface(struct wpa_supplicant *wpa_s,
struct wpa_interface *iface)
{
+ const char *ifname, *driver;
+ struct wpa_driver_capa capa;
+
wpa_printf(MSG_DEBUG, "Initializing interface '%s' conf '%s' driver "
"'%s' ctrl_interface '%s' bridge '%s'", iface->ifname,
iface->confname ? iface->confname : "N/A",
@@ -1707,10 +1884,6 @@ static int wpa_supplicant_init_iface(struct wpa_supplicant *wpa_s,
iface->ctrl_interface ? iface->ctrl_interface : "N/A",
iface->bridge_ifname ? iface->bridge_ifname : "N/A");
- if (wpa_supplicant_set_driver(wpa_s, iface->driver) < 0) {
- return -1;
- }
-
if (iface->confname) {
#ifdef CONFIG_BACKEND_FILE
wpa_s->confname = os_rel2abs_path(iface->confname);
@@ -1778,18 +1951,6 @@ static int wpa_supplicant_init_iface(struct wpa_supplicant *wpa_s,
sizeof(wpa_s->bridge_ifname));
}
- return 0;
-}
-
-
-static int wpa_supplicant_init_iface2(struct wpa_supplicant *wpa_s)
-{
- const char *ifname;
- struct wpa_driver_capa capa;
-
- wpa_printf(MSG_DEBUG, "Initializing interface (2) '%s'",
- wpa_s->ifname);
-
/* RSNA Supplicant Key Management - INITIALIZE */
eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
@@ -1798,8 +1959,21 @@ static int wpa_supplicant_init_iface2(struct wpa_supplicant *wpa_s)
* L2 receive handler so that association events are processed before
* EAPOL-Key packets if both become available for the same select()
* call. */
+ driver = iface->driver;
+next_driver:
+ if (wpa_supplicant_set_driver(wpa_s, driver) < 0)
+ return -1;
+
wpa_s->drv_priv = wpa_drv_init(wpa_s, wpa_s->ifname);
if (wpa_s->drv_priv == NULL) {
+ const char *pos;
+ pos = driver ? os_strchr(driver, ',') : NULL;
+ if (pos) {
+ wpa_printf(MSG_DEBUG, "Failed to initialize driver "
+ "interface - try next driver wrapper");
+ driver = pos + 1;
+ goto next_driver;
+ }
wpa_printf(MSG_ERROR, "Failed to initialize driver interface");
return -1;
}
@@ -1848,6 +2022,18 @@ static int wpa_supplicant_init_iface2(struct wpa_supplicant *wpa_s)
return -1;
}
+ if (wpa_drv_get_capa(wpa_s, &capa) == 0) {
+ wpa_s->drv_flags = capa.flags;
+ if (capa.flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) {
+ if (ieee80211_sta_init(wpa_s))
+ return -1;
+ }
+ wpa_s->max_scan_ssids = capa.max_scan_ssids;
+ wpa_s->max_remain_on_chan = capa.max_remain_on_chan;
+ }
+ if (wpa_s->max_remain_on_chan == 0)
+ wpa_s->max_remain_on_chan = 1000;
+
if (wpa_supplicant_driver_init(wpa_s) < 0)
return -1;
@@ -1880,43 +2066,37 @@ static int wpa_supplicant_init_iface2(struct wpa_supplicant *wpa_s)
return -1;
}
- if (wpa_drv_get_capa(wpa_s, &capa) == 0) {
- if (capa.flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) {
- wpa_s->use_client_mlme = 1;
- if (ieee80211_sta_init(wpa_s))
- return -1;
- }
- if (capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE)
- wpa_s->driver_4way_handshake = 1;
+#ifdef CONFIG_IBSS_RSN
+ wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
+ if (!wpa_s->ibss_rsn) {
+ wpa_printf(MSG_DEBUG, "Failed to init IBSS RSN");
+ return -1;
}
+#endif /* CONFIG_IBSS_RSN */
+
+ if (wpa_bss_init(wpa_s) < 0)
+ return -1;
return 0;
}
-static void wpa_supplicant_deinit_iface(struct wpa_supplicant *wpa_s)
+static void wpa_supplicant_deinit_iface(struct wpa_supplicant *wpa_s,
+ int notify)
{
if (wpa_s->drv_priv) {
wpa_supplicant_deauthenticate(wpa_s,
WLAN_REASON_DEAUTH_LEAVING);
- /* Backwards compatibility call to set_wpa() handler. This is
- * called only just after init and just before deinit, so these
- * handler can be used to implement same functionality. */
- if (wpa_drv_set_wpa(wpa_s, 0) < 0) {
- wpa_printf(MSG_ERROR, "Failed to disable WPA in the "
- "driver.");
- }
-
- wpa_drv_set_drop_unencrypted(wpa_s, 0);
wpa_drv_set_countermeasures(wpa_s, 0);
wpa_clear_keys(wpa_s, NULL);
}
- wpas_dbus_unregister_iface(wpa_s);
-
wpa_supplicant_cleanup(wpa_s);
+ if (notify)
+ wpas_notify_iface_removed(wpa_s);
+
if (wpa_s->drv_priv)
wpa_drv_deinit(wpa_s);
}
@@ -1938,6 +2118,8 @@ struct wpa_supplicant * wpa_supplicant_add_iface(struct wpa_global *global,
struct wpa_interface *iface)
{
struct wpa_supplicant *wpa_s;
+ struct wpa_interface t_iface;
+ struct wpa_ssid *ssid;
if (global == NULL || iface == NULL)
return NULL;
@@ -1948,22 +2130,39 @@ struct wpa_supplicant * wpa_supplicant_add_iface(struct wpa_global *global,
wpa_s->global = global;
- if (wpa_supplicant_init_iface(wpa_s, iface) ||
- wpa_supplicant_init_iface2(wpa_s)) {
+ t_iface = *iface;
+ if (global->params.override_driver) {
+ wpa_printf(MSG_DEBUG, "Override interface parameter: driver "
+ "('%s' -> '%s')",
+ iface->driver, global->params.override_driver);
+ t_iface.driver = global->params.override_driver;
+ }
+ if (global->params.override_ctrl_interface) {
+ wpa_printf(MSG_DEBUG, "Override interface parameter: "
+ "ctrl_interface ('%s' -> '%s')",
+ iface->ctrl_interface,
+ global->params.override_ctrl_interface);
+ t_iface.ctrl_interface =
+ global->params.override_ctrl_interface;
+ }
+ if (wpa_supplicant_init_iface(wpa_s, &t_iface)) {
wpa_printf(MSG_DEBUG, "Failed to add interface %s",
iface->ifname);
- wpa_supplicant_deinit_iface(wpa_s);
+ wpa_supplicant_deinit_iface(wpa_s, 0);
os_free(wpa_s);
return NULL;
}
- /* Register the interface with the dbus control interface */
- if (wpas_dbus_register_iface(wpa_s)) {
- wpa_supplicant_deinit_iface(wpa_s);
+ /* Notify the control interfaces about new iface */
+ if (wpas_notify_iface_added(wpa_s)) {
+ wpa_supplicant_deinit_iface(wpa_s, 1);
os_free(wpa_s);
return NULL;
}
+ for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next)
+ wpas_notify_network_added(wpa_s, ssid);
+
wpa_s->next = global->ifaces;
global->ifaces = wpa_s;
@@ -2003,7 +2202,7 @@ int wpa_supplicant_remove_iface(struct wpa_global *global,
wpa_printf(MSG_DEBUG, "Removing interface %s", wpa_s->ifname);
- wpa_supplicant_deinit_iface(wpa_s);
+ wpa_supplicant_deinit_iface(wpa_s, 1);
os_free(wpa_s);
return 0;
@@ -2050,7 +2249,7 @@ struct wpa_global * wpa_supplicant_init(struct wpa_params *params)
if (params->wpa_debug_syslog)
wpa_debug_open_syslog();
- ret = eap_peer_register_methods();
+ ret = eap_register_methods();
if (ret) {
wpa_printf(MSG_ERROR, "Failed to register EAP methods");
if (ret == -2)
@@ -2070,6 +2269,12 @@ struct wpa_global * wpa_supplicant_init(struct wpa_params *params)
if (params->ctrl_interface)
global->params.ctrl_interface =
os_strdup(params->ctrl_interface);
+ if (params->override_driver)
+ global->params.override_driver =
+ os_strdup(params->override_driver);
+ if (params->override_ctrl_interface)
+ global->params.override_ctrl_interface =
+ os_strdup(params->override_ctrl_interface);
wpa_debug_level = global->params.wpa_debug_level =
params->wpa_debug_level;
wpa_debug_show_keys = global->params.wpa_debug_show_keys =
@@ -2077,7 +2282,7 @@ struct wpa_global * wpa_supplicant_init(struct wpa_params *params)
wpa_debug_timestamp = global->params.wpa_debug_timestamp =
params->wpa_debug_timestamp;
- if (eloop_init(global)) {
+ if (eloop_init()) {
wpa_printf(MSG_ERROR, "Failed to initialize event loop");
wpa_supplicant_deinit(global);
return NULL;
@@ -2089,16 +2294,12 @@ struct wpa_global * wpa_supplicant_init(struct wpa_params *params)
return NULL;
}
- if (global->params.dbus_ctrl_interface) {
- global->dbus_ctrl_iface =
- wpa_supplicant_dbus_ctrl_iface_init(global);
- if (global->dbus_ctrl_iface == NULL) {
- wpa_supplicant_deinit(global);
- return NULL;
- }
+ if (wpas_notify_supplicant_initialized(global)) {
+ wpa_supplicant_deinit(global);
+ return NULL;
}
- for (i = 0; wpa_supplicant_drivers[i]; i++)
+ for (i = 0; wpa_drivers[i]; i++)
global->drv_count++;
if (global->drv_count == 0) {
wpa_printf(MSG_ERROR, "No drivers enabled");
@@ -2110,13 +2311,13 @@ struct wpa_global * wpa_supplicant_init(struct wpa_params *params)
wpa_supplicant_deinit(global);
return NULL;
}
- for (i = 0; wpa_supplicant_drivers[i]; i++) {
- if (!wpa_supplicant_drivers[i]->global_init)
+ for (i = 0; wpa_drivers[i]; i++) {
+ if (!wpa_drivers[i]->global_init)
continue;
- global->drv_priv[i] = wpa_supplicant_drivers[i]->global_init();
+ global->drv_priv[i] = wpa_drivers[i]->global_init();
if (global->drv_priv[i] == NULL) {
wpa_printf(MSG_ERROR, "Failed to initialize driver "
- "'%s'", wpa_supplicant_drivers[i]->name);
+ "'%s'", wpa_drivers[i]->name);
wpa_supplicant_deinit(global);
return NULL;
}
@@ -2150,8 +2351,8 @@ int wpa_supplicant_run(struct wpa_global *global)
wpa_s->ctrl_iface);
}
- eloop_register_signal_terminate(wpa_supplicant_terminate, NULL);
- eloop_register_signal_reconfig(wpa_supplicant_reconfig, NULL);
+ eloop_register_signal_terminate(wpa_supplicant_terminate, global);
+ eloop_register_signal_reconfig(wpa_supplicant_reconfig, global);
eloop_run();
@@ -2178,15 +2379,18 @@ void wpa_supplicant_deinit(struct wpa_global *global)
if (global->ctrl_iface)
wpa_supplicant_global_ctrl_iface_deinit(global->ctrl_iface);
- if (global->dbus_ctrl_iface)
- wpa_supplicant_dbus_ctrl_iface_deinit(global->dbus_ctrl_iface);
+
+ wpas_notify_supplicant_deinitialized(global);
eap_peer_unregister_methods();
+#ifdef CONFIG_AP
+ eap_server_unregister_methods();
+#endif /* CONFIG_AP */
- for (i = 0; wpa_supplicant_drivers[i] && global->drv_priv; i++) {
+ for (i = 0; wpa_drivers[i] && global->drv_priv; i++) {
if (!global->drv_priv[i])
continue;
- wpa_supplicant_drivers[i]->global_deinit(global->drv_priv[i]);
+ wpa_drivers[i]->global_deinit(global->drv_priv[i]);
}
os_free(global->drv_priv);
@@ -2197,6 +2401,8 @@ void wpa_supplicant_deinit(struct wpa_global *global)
os_free(global->params.pid_file);
}
os_free(global->params.ctrl_interface);
+ os_free(global->params.override_driver);
+ os_free(global->params.override_ctrl_interface);
os_free(global);
wpa_debug_close_syslog();
diff --git a/contrib/wpa/wpa_supplicant/wpa_supplicant.conf b/contrib/wpa/wpa_supplicant/wpa_supplicant.conf
index f5143c8..1b175ad 100644
--- a/contrib/wpa/wpa_supplicant/wpa_supplicant.conf
+++ b/contrib/wpa/wpa_supplicant/wpa_supplicant.conf
@@ -78,7 +78,9 @@ eapol_version=1
# allow the driver to take care of AP scanning and selection and use
# wpa_supplicant just to process EAPOL frames based on IEEE 802.11 association
# information from the driver.
-# 1: wpa_supplicant initiates scanning and AP selection
+# 1: wpa_supplicant initiates scanning and AP selection; if no APs matching to
+# the currently enabled networks are found, a new network (IBSS or AP mode
+# operation) may be initialized (if configured) (default)
# 0: driver takes care of scanning, AP selection, and IEEE 802.11 association
# parameters (e.g., WPA IE generation); this mode can also be used with
# non-WPA drivers when using IEEE 802.1X mode; do not try to associate with
@@ -93,6 +95,10 @@ eapol_version=1
# key_mgmt, pairwise, group, proto variables
#
# For use in FreeBSD with the wlan module ap_scan must be set to 1.
+# When using IBSS or AP mode, ap_scan=2 mode can force the new network to be
+# created immediately regardless of scan results. ap_scan=1 mode will first try
+# to scan for existing networks and only if no matches with the enabled
+# networks are found, a new IBSS or AP mode network is created.
ap_scan=1
# EAP fast re-authentication
@@ -181,6 +187,12 @@ fast_reauth=1
# 4-octet operating system version number (hex string)
#os_version=01020300
+# Config Methods
+# List of the supported configuration methods
+# Available methods: usba ethernet label display ext_nfc_token int_nfc_token
+# nfc_interface push_button keypad
+#config_methods=label display push_button keypad
+
# Credential processing
# 0 = process received credentials internally (default)
# 1 = do not process received credentials; just pass them over ctrl_iface to
@@ -189,6 +201,20 @@ fast_reauth=1
# to external program(s)
#wps_cred_processing=0
+# Maximum number of BSS entries to keep in memory
+# Default: 200
+# This can be used to limit memory use on the BSS entries (cached scan
+# results). A larger value may be needed in environments that have huge number
+# of APs when using ap_scan=1 mode.
+#bss_max_count=200
+
+
+# filter_ssids - SSID-based scan result filtering
+# 0 = do not filter scan results (default)
+# 1 = only include configured SSIDs in scan results/BSS table
+#filter_ssids=0
+
+
# network block
#
# Each network (usually AP's sharing the same SSID) is configured as a separate
@@ -233,9 +259,10 @@ fast_reauth=1
# mode: IEEE 802.11 operation mode
# 0 = infrastructure (Managed) mode, i.e., associate with an AP (default)
# 1 = IBSS (ad-hoc, peer-to-peer)
+# 2 = AP (access point)
# Note: IBSS can only be used with key_mgmt NONE (plaintext and static WEP)
-# and key_mgmt=WPA-NONE (fixed group key TKIP/CCMP). In addition, ap_scan has
-# to be set to 2 for IBSS. WPA-None requires following network block options:
+# and key_mgmt=WPA-NONE (fixed group key TKIP/CCMP). WPA-None requires
+# following network block options:
# proto=WPA, key_mgmt=WPA-NONE, pairwise=NONE, group=TKIP (or CCMP, but not
# both), and psk must also be set.
#
@@ -246,6 +273,17 @@ fast_reauth=1
# an IBSS network with the configured SSID is already present, the frequency of
# the network will be used instead of this configured value.
#
+# scan_freq: List of frequencies to scan
+# Space-separated list of frequencies in MHz to scan when searching for this
+# BSS. If the subset of channels used by the network is known, this option can
+# be used to optimize scanning to not occur on channels that the network does
+# not use. Example: scan_freq=2412 2437 2462
+#
+# freq_list: Array of allowed frequencies
+# Space-separated list of frequencies in MHz to allow for selecting the BSS. If
+# set, scan results that do not match any of the specified frequencies are not
+# considered when selecting a BSS.
+#
# proto: list of accepted protocols
# WPA = WPA/IEEE 802.11i/D3.0
# RSN = WPA2/IEEE 802.11i (also WPA2 can be used as an alias for RSN)
@@ -362,6 +400,16 @@ fast_reauth=1
# a trusted CA certificate should always be configured when using
# EAP-TLS/TTLS/PEAP. Full path should be used since working directory may
# change when wpa_supplicant is run in the background.
+#
+# Alternatively, this can be used to only perform matching of the server
+# certificate (SHA-256 hash of the DER encoded X.509 certificate). In
+# this case, the possible CA certificates in the server certificate chain
+# are ignored and only the server certificate is verified. This is
+# configured with the following format:
+# hash:://server/sha256/cert_hash_in_hex
+# For example: "hash://server/sha256/
+# 5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca6a"
+#
# On Windows, trusted CA certificates can be loaded from the system
# certificate store by setting this to cert_store://<name>, e.g.,
# ca_cert="cert_store://CA" or ca_cert="cert_store://ROOT".
diff --git a/contrib/wpa/wpa_supplicant/wpa_supplicant.nsi b/contrib/wpa/wpa_supplicant/wpa_supplicant.nsi
index 2783ca3..b9f0162 100644
--- a/contrib/wpa/wpa_supplicant/wpa_supplicant.nsi
+++ b/contrib/wpa/wpa_supplicant/wpa_supplicant.nsi
@@ -13,8 +13,8 @@ Page InstFiles
section -Prerequisites
SetOutPath $INSTDIR\Prerequisites
MessageBox MB_YESNO "Install WinPcap?" /SD IDYES IDNO endWinPcap
- File "/opt/Qt-Win/files/WinPcap_4_0_2.exe"
- ExecWait "$INSTDIR\Prerequisites\WinPcap_4_0_2.exe"
+ File "/opt/Qt-Win/files/WinPcap_4_1_2.exe"
+ ExecWait "$INSTDIR\Prerequisites\WinPcap_4_1_2.exe"
Goto endWinPcap
endWinPcap:
sectionEnd
@@ -24,6 +24,7 @@ section
setOutPath $INSTDIR
File wpa_gui.exe
+ File wpa_gui_de.qm
File wpa_cli.exe
File COPYING
File README
@@ -36,6 +37,7 @@ section
File wpasvc.exe
File /opt/Qt-Win/files/mingwm10.dll
+ File /opt/Qt-Win/files/libgcc_s_dw2-1.dll
File /opt/Qt-Win/files/QtCore4.dll
File /opt/Qt-Win/files/QtGui4.dll
@@ -82,6 +84,7 @@ section "uninstall"
DeleteRegKey HKLM "Software\wpa_supplicant"
delete "$INSTDIR\wpa_gui.exe"
+ delete "$INSTDIR\wpa_gui_de.qm"
delete "$INSTDIR\wpa_cli.exe"
delete "$INSTDIR\COPYING"
delete "$INSTDIR\README"
@@ -94,10 +97,11 @@ section "uninstall"
delete "$INSTDIR\wpasvc.exe"
delete "$INSTDIR\mingwm10.dll"
+ delete "$INSTDIR\libgcc_s_dw2-1.dll"
delete "$INSTDIR\QtCore4.dll"
delete "$INSTDIR\QtGui4.dll"
- delete "$INSTDIR\Prerequisites\WinPcap_4_0_2.exe"
+ delete "$INSTDIR\Prerequisites\WinPcap_4_1_2.exe"
rmdir "$INSTDIR\Prerequisites"
rmdir "$INSTDIR"
diff --git a/contrib/wpa/wpa_supplicant/wpa_supplicant_i.h b/contrib/wpa/wpa_supplicant/wpa_supplicant_i.h
index 248ada5..6c36a1a 100644
--- a/contrib/wpa/wpa_supplicant/wpa_supplicant_i.h
+++ b/contrib/wpa/wpa_supplicant/wpa_supplicant_i.h
@@ -1,6 +1,6 @@
/*
* wpa_supplicant - Internal definitions
- * Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2003-2010, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -15,7 +15,8 @@
#ifndef WPA_SUPPLICANT_I_H
#define WPA_SUPPLICANT_I_H
-#include "drivers/driver.h"
+#include "utils/list.h"
+#include "common/defs.h"
extern const char *wpa_supplicant_version;
extern const char *wpa_supplicant_license;
@@ -27,12 +28,12 @@ extern const char *wpa_supplicant_full_license4;
extern const char *wpa_supplicant_full_license5;
#endif /* CONFIG_NO_STDOUT_DEBUG */
-extern struct wpa_driver_ops *wpa_supplicant_drivers[];
-
-
-struct wpa_scan_result;
struct wpa_sm;
struct wpa_supplicant;
+struct ibss_rsn;
+struct scan_info;
+struct wpa_bss;
+struct wpa_scan_results;
/*
* Forward declarations of private structures used within the ctrl_iface
@@ -41,7 +42,7 @@ struct wpa_supplicant;
*/
struct ctrl_iface_priv;
struct ctrl_iface_global_priv;
-struct ctrl_iface_dbus_priv;
+struct wpas_dbus_priv;
/**
* struct wpa_interface - Parameters for wpa_supplicant_add_iface()
@@ -160,7 +161,25 @@ struct wpa_params {
/**
* wpa_debug_syslog - Enable log output through syslog
*/
- const char *wpa_debug_syslog;
+ int wpa_debug_syslog;
+
+ /**
+ * override_driver - Optional driver parameter override
+ *
+ * This parameter can be used to override the driver parameter in
+ * dynamic interface addition to force a specific driver wrapper to be
+ * used instead.
+ */
+ char *override_driver;
+
+ /**
+ * override_ctrl_interface - Optional ctrl_interface override
+ *
+ * This parameter can be used to override the ctrl_interface parameter
+ * in dynamic interface addition to force a control interface to be
+ * created.
+ */
+ char *override_ctrl_interface;
};
/**
@@ -173,9 +192,10 @@ struct wpa_global {
struct wpa_supplicant *ifaces;
struct wpa_params params;
struct ctrl_iface_global_priv *ctrl_iface;
- struct ctrl_iface_dbus_priv *dbus_ctrl_iface;
+ struct wpas_dbus_priv *dbus;
void **drv_priv;
size_t drv_count;
+ struct os_time suspend_time;
};
@@ -195,7 +215,7 @@ struct wpa_client_mlme {
size_t extra_ie_len;
u8 *extra_probe_ie; /* to be added to the end of ProbeReq */
size_t extra_probe_ie_len;
- wpa_key_mgmt key_mgmt;
+ enum wpa_key_mgmt key_mgmt;
/* The last AssocReq/Resp IEs */
u8 *assocreq_ies, *assocresp_ies;
@@ -216,10 +236,8 @@ struct wpa_client_mlme {
struct os_time last_probe;
-#define IEEE80211_AUTH_ALG_OPEN BIT(0)
-#define IEEE80211_AUTH_ALG_SHARED_KEY BIT(1)
-#define IEEE80211_AUTH_ALG_LEAP BIT(2)
- unsigned int auth_algs; /* bitfield of allowed auth algs */
+ unsigned int auth_algs; /* bitfield of allowed auth algs
+ * (WPA_AUTH_ALG_*) */
int auth_alg; /* currently used IEEE 802.11 authentication algorithm */
int auth_transaction;
@@ -241,6 +259,7 @@ struct wpa_client_mlme {
u8 scan_ssid[32];
size_t scan_ssid_len;
int scan_skip_11b;
+ int *scan_freqs;
struct ieee80211_sta_bss *sta_bss_list;
#define STA_HASH_SIZE 256
@@ -249,13 +268,13 @@ struct wpa_client_mlme {
int cts_protect_erp_frames;
- int phymode; /* current mode; WPA_MODE_IEEE80211A, .. */
- struct wpa_hw_modes *modes;
+ enum hostapd_hw_mode phymode; /* current mode */
+ struct hostapd_hw_modes *modes;
size_t num_modes;
unsigned int hw_modes; /* bitfield of allowed hardware modes;
- * (1 << MODE_*) */
+ * (1 << HOSTAPD_MODE_*) */
int num_curr_rates;
- struct wpa_rate_data *curr_rates;
+ int *curr_rates;
int freq; /* The current frequency in MHz */
int channel; /* The current IEEE 802.11 channel number */
@@ -265,6 +284,10 @@ struct wpa_client_mlme {
size_t ft_ies_len;
#endif /* CONFIG_IEEE80211R */
+ void (*public_action_cb)(void *ctx, const u8 *buf, size_t len,
+ int freq);
+ void *public_action_cb_ctx;
+
#else /* CONFIG_CLIENT_MLME */
int dummy; /* to keep MSVC happy */
#endif /* CONFIG_CLIENT_MLME */
@@ -288,6 +311,9 @@ struct wpa_supplicant {
#ifdef CONFIG_CTRL_IFACE_DBUS
char *dbus_path;
#endif /* CONFIG_CTRL_IFACE_DBUS */
+#ifdef CONFIG_CTRL_IFACE_DBUS_NEW
+ char *dbus_new_path;
+#endif /* CONFIG_CTRL_IFACE_DBUS_NEW */
char bridge_ifname[16];
char *confname;
@@ -301,7 +327,9 @@ struct wpa_supplicant {
int disconnected; /* all connections disabled; i.e., do no reassociate
* before this has been cleared */
struct wpa_ssid *current_ssid;
+ struct wpa_bss *current_bss;
int ap_ies_from_associnfo;
+ unsigned int assoc_freq;
/* Selected configuration (based on Beacon/ProbeResp WPA IE) */
int pairwise_cipher;
@@ -314,13 +342,19 @@ struct wpa_supplicant {
struct wpa_ssid *prev_scan_ssid; /* previously scanned SSID;
* NULL = not yet initialized (start
- * with broadcast SSID)
- * BROADCAST_SSID_SCAN = broadcast
+ * with wildcard SSID)
+ * WILDCARD_SSID_SCAN = wildcard
* SSID was used in the previous scan
*/
-#define BROADCAST_SSID_SCAN ((struct wpa_ssid *) 1)
+#define WILDCARD_SSID_SCAN ((struct wpa_ssid *) 1)
- struct wpa_scan_results *scan_res;
+ void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
+ struct wpa_scan_results *scan_res);
+ struct dl_list bss; /* struct wpa_bss::list */
+ struct dl_list bss_id; /* struct wpa_bss::list_id */
+ size_t num_bss;
+ unsigned int bss_update_idx;
+ unsigned int bss_next_id;
struct wpa_driver_ops *driver;
int interface_removed; /* whether the network interface has been
@@ -330,7 +364,7 @@ struct wpa_supplicant {
struct ctrl_iface_priv *ctrl_iface;
- wpa_states wpa_state;
+ enum wpa_states wpa_state;
int scanning;
int new_connection;
int reassociated_connection;
@@ -348,15 +382,12 @@ struct wpa_supplicant {
int scan_req; /* manual scan request; this forces a scan even if there
* are no enabled networks in the configuration */
- int scan_res_tried; /* whether ap_scan=1 mode has tried to fetch scan
- * results without a new scan request; this is used
- * to speed up the first association if the driver
- * has already available scan results. */
int scan_runs; /* number of scan runs since WPS was started */
struct wpa_client_mlme mlme;
- int use_client_mlme;
- int driver_4way_handshake;
+ unsigned int drv_flags;
+ int max_scan_ssids;
+ unsigned int max_remain_on_chan;
int pending_mic_error_report;
int pending_mic_error_pairwise;
@@ -364,34 +395,72 @@ struct wpa_supplicant {
struct wps_context *wps;
int wps_success; /* WPS success event received */
+ struct wps_er *wps_er;
int blacklist_cleared;
struct wpabuf *pending_eapol_rx;
struct os_time pending_eapol_rx_time;
u8 pending_eapol_rx_src[ETH_ALEN];
+
+ struct ibss_rsn *ibss_rsn;
+
+#ifdef CONFIG_SME
+ struct {
+ u8 ssid[32];
+ size_t ssid_len;
+ int freq;
+ u8 assoc_req_ie[80];
+ size_t assoc_req_ie_len;
+ int mfp;
+ int ft_used;
+ u8 mobility_domain[2];
+ u8 *ft_ies;
+ size_t ft_ies_len;
+ u8 prev_bssid[ETH_ALEN];
+ int prev_bssid_set;
+ int auth_alg;
+ } sme;
+#endif /* CONFIG_SME */
+
+#ifdef CONFIG_AP
+ struct hostapd_iface *ap_iface;
+ void (*ap_configured_cb)(void *ctx, void *data);
+ void *ap_configured_cb_ctx;
+ void *ap_configured_cb_data;
+#endif /* CONFIG_AP */
+
+ struct wpa_ssid *bgscan_ssid;
+ const struct bgscan_ops *bgscan;
+ void *bgscan_priv;
+
+ int connect_without_scan;
+
+ int after_wps;
+ unsigned int wps_freq;
};
/* wpa_supplicant.c */
+int wpa_set_wep_keys(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid);
+
int wpa_supplicant_reload_configuration(struct wpa_supplicant *wpa_s);
-const char * wpa_supplicant_state_txt(int state);
+const char * wpa_supplicant_state_txt(enum wpa_states state);
int wpa_supplicant_driver_init(struct wpa_supplicant *wpa_s);
int wpa_supplicant_set_suites(struct wpa_supplicant *wpa_s,
- struct wpa_scan_res *bss,
- struct wpa_ssid *ssid,
+ struct wpa_bss *bss, struct wpa_ssid *ssid,
u8 *wpa_ie, size_t *wpa_ie_len);
void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
- struct wpa_scan_res *bss,
+ struct wpa_bss *bss,
struct wpa_ssid *ssid);
void wpa_supplicant_set_non_wpa_policy(struct wpa_supplicant *wpa_s,
struct wpa_ssid *ssid);
void wpa_supplicant_initiate_eapol(struct wpa_supplicant *wpa_s);
-int wpa_supplicant_get_scan_results(struct wpa_supplicant *wpa_s);
void wpa_clear_keys(struct wpa_supplicant *wpa_s, const u8 *addr);
void wpa_supplicant_req_auth_timeout(struct wpa_supplicant *wpa_s,
int sec, int usec);
-void wpa_supplicant_set_state(struct wpa_supplicant *wpa_s, wpa_states state);
+void wpa_supplicant_set_state(struct wpa_supplicant *wpa_s,
+ enum wpa_states state);
struct wpa_ssid * wpa_supplicant_get_ssid(struct wpa_supplicant *wpa_s);
void wpa_supplicant_cancel_auth_timeout(struct wpa_supplicant *wpa_s);
void wpa_supplicant_deauthenticate(struct wpa_supplicant *wpa_s,
@@ -399,6 +468,18 @@ void wpa_supplicant_deauthenticate(struct wpa_supplicant *wpa_s,
void wpa_supplicant_disassociate(struct wpa_supplicant *wpa_s,
int reason_code);
+void wpa_supplicant_enable_network(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid);
+void wpa_supplicant_disable_network(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid);
+void wpa_supplicant_select_network(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid);
+int wpa_supplicant_set_ap_scan(struct wpa_supplicant *wpa_s,
+ int ap_scan);
+int wpa_supplicant_set_debug_params(struct wpa_global *global,
+ int debug_level, int debug_timestamp,
+ int debug_show_keys);
+
void wpa_show_license(void);
struct wpa_supplicant * wpa_supplicant_add_iface(struct wpa_global *global,
@@ -413,366 +494,19 @@ void wpa_supplicant_deinit(struct wpa_global *global);
int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
struct wpa_ssid *ssid);
-
-/* scan.c */
-int wpa_supplicant_enabled_networks(struct wpa_config *conf);
-void wpa_supplicant_req_scan(struct wpa_supplicant *wpa_s, int sec, int usec);
-void wpa_supplicant_cancel_scan(struct wpa_supplicant *wpa_s);
-void wpa_supplicant_notify_scanning(struct wpa_supplicant *wpa_s,
- int scanning);
+void wpa_supplicant_terminate_proc(struct wpa_global *global);
+void wpa_supplicant_rx_eapol(void *ctx, const u8 *src_addr,
+ const u8 *buf, size_t len);
+enum wpa_key_mgmt key_mgmt2driver(int key_mgmt);
+enum wpa_cipher cipher_suite2driver(int cipher);
/* events.c */
void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s);
+void wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
+ struct wpa_bss *selected,
+ struct wpa_ssid *ssid);
-/* driver_ops */
-static inline void * wpa_drv_init(struct wpa_supplicant *wpa_s,
- const char *ifname)
-{
- if (wpa_s->driver->init2)
- return wpa_s->driver->init2(wpa_s, ifname,
- wpa_s->global_drv_priv);
- if (wpa_s->driver->init) {
- return wpa_s->driver->init(wpa_s, ifname);
- }
- return NULL;
-}
-
-static inline void wpa_drv_deinit(struct wpa_supplicant *wpa_s)
-{
- if (wpa_s->driver->deinit)
- wpa_s->driver->deinit(wpa_s->drv_priv);
-}
-
-static inline int wpa_drv_set_param(struct wpa_supplicant *wpa_s,
- const char *param)
-{
- if (wpa_s->driver->set_param)
- return wpa_s->driver->set_param(wpa_s->drv_priv, param);
- return 0;
-}
-
-static inline int wpa_drv_set_drop_unencrypted(struct wpa_supplicant *wpa_s,
- int enabled)
-{
- if (wpa_s->driver->set_drop_unencrypted) {
- return wpa_s->driver->set_drop_unencrypted(wpa_s->drv_priv,
- enabled);
- }
- return -1;
-}
-
-static inline int wpa_drv_set_countermeasures(struct wpa_supplicant *wpa_s,
- int enabled)
-{
- if (wpa_s->driver->set_countermeasures) {
- return wpa_s->driver->set_countermeasures(wpa_s->drv_priv,
- enabled);
- }
- return -1;
-}
-
-static inline int wpa_drv_set_auth_alg(struct wpa_supplicant *wpa_s,
- int auth_alg)
-{
- if (wpa_s->driver->set_auth_alg) {
- return wpa_s->driver->set_auth_alg(wpa_s->drv_priv,
- auth_alg);
- }
- return -1;
-}
-
-static inline int wpa_drv_set_wpa(struct wpa_supplicant *wpa_s, int enabled)
-{
- if (wpa_s->driver->set_wpa) {
- return wpa_s->driver->set_wpa(wpa_s->drv_priv, enabled);
- }
- return 0;
-}
-
-static inline int wpa_drv_set_mode(struct wpa_supplicant *wpa_s, int mode)
-{
- if (wpa_s->driver->set_mode) {
- return wpa_s->driver->set_mode(wpa_s->drv_priv, mode);
- }
- return 0;
-}
-
-static inline int wpa_drv_associate(struct wpa_supplicant *wpa_s,
- struct wpa_driver_associate_params *params)
-{
- if (wpa_s->driver->associate) {
- return wpa_s->driver->associate(wpa_s->drv_priv, params);
- }
- return -1;
-}
-
-static inline int wpa_drv_scan(struct wpa_supplicant *wpa_s, const u8 *ssid,
- size_t ssid_len)
-{
- if (wpa_s->driver->scan) {
- return wpa_s->driver->scan(wpa_s->drv_priv, ssid, ssid_len);
- }
- return -1;
-}
-
-static inline int wpa_drv_get_scan_results(struct wpa_supplicant *wpa_s,
- struct wpa_scan_result *results,
- size_t max_size)
-{
- if (wpa_s->driver->get_scan_results) {
- return wpa_s->driver->get_scan_results(wpa_s->drv_priv,
- results, max_size);
- }
- return -1;
-}
-
-static inline struct wpa_scan_results * wpa_drv_get_scan_results2(
- struct wpa_supplicant *wpa_s)
-{
- if (wpa_s->driver->get_scan_results2)
- return wpa_s->driver->get_scan_results2(wpa_s->drv_priv);
- return NULL;
-}
-
-static inline int wpa_drv_get_bssid(struct wpa_supplicant *wpa_s, u8 *bssid)
-{
- if (wpa_s->driver->get_bssid) {
- return wpa_s->driver->get_bssid(wpa_s->drv_priv, bssid);
- }
- return -1;
-}
-
-static inline int wpa_drv_get_ssid(struct wpa_supplicant *wpa_s, u8 *ssid)
-{
- if (wpa_s->driver->get_ssid) {
- return wpa_s->driver->get_ssid(wpa_s->drv_priv, ssid);
- }
- return -1;
-}
-
-static inline int wpa_drv_set_key(struct wpa_supplicant *wpa_s, wpa_alg alg,
- const u8 *addr, int key_idx, int set_tx,
- const u8 *seq, size_t seq_len,
- const u8 *key, size_t key_len)
-{
- if (wpa_s->driver->set_key) {
- wpa_s->keys_cleared = 0;
- return wpa_s->driver->set_key(wpa_s->drv_priv, alg, addr,
- key_idx, set_tx, seq, seq_len,
- key, key_len);
- }
- return -1;
-}
-
-static inline int wpa_drv_deauthenticate(struct wpa_supplicant *wpa_s,
- const u8 *addr, int reason_code)
-{
- if (wpa_s->driver->deauthenticate) {
- return wpa_s->driver->deauthenticate(wpa_s->drv_priv, addr,
- reason_code);
- }
- return -1;
-}
-
-static inline int wpa_drv_disassociate(struct wpa_supplicant *wpa_s,
- const u8 *addr, int reason_code)
-{
- if (wpa_s->driver->disassociate) {
- return wpa_s->driver->disassociate(wpa_s->drv_priv, addr,
- reason_code);
- }
- return -1;
-}
-
-static inline int wpa_drv_add_pmkid(struct wpa_supplicant *wpa_s,
- const u8 *bssid, const u8 *pmkid)
-{
- if (wpa_s->driver->add_pmkid) {
- return wpa_s->driver->add_pmkid(wpa_s->drv_priv, bssid, pmkid);
- }
- return -1;
-}
-
-static inline int wpa_drv_remove_pmkid(struct wpa_supplicant *wpa_s,
- const u8 *bssid, const u8 *pmkid)
-{
- if (wpa_s->driver->remove_pmkid) {
- return wpa_s->driver->remove_pmkid(wpa_s->drv_priv, bssid,
- pmkid);
- }
- return -1;
-}
-
-static inline int wpa_drv_flush_pmkid(struct wpa_supplicant *wpa_s)
-{
- if (wpa_s->driver->flush_pmkid) {
- return wpa_s->driver->flush_pmkid(wpa_s->drv_priv);
- }
- return -1;
-}
-
-static inline int wpa_drv_get_capa(struct wpa_supplicant *wpa_s,
- struct wpa_driver_capa *capa)
-{
- if (wpa_s->driver->get_capa) {
- return wpa_s->driver->get_capa(wpa_s->drv_priv, capa);
- }
- return -1;
-}
-
-static inline void wpa_drv_poll(struct wpa_supplicant *wpa_s)
-{
- if (wpa_s->driver->poll) {
- wpa_s->driver->poll(wpa_s->drv_priv);
- }
-}
-
-static inline const char * wpa_drv_get_ifname(struct wpa_supplicant *wpa_s)
-{
- if (wpa_s->driver->get_ifname) {
- return wpa_s->driver->get_ifname(wpa_s->drv_priv);
- }
- return NULL;
-}
-
-static inline const u8 * wpa_drv_get_mac_addr(struct wpa_supplicant *wpa_s)
-{
- if (wpa_s->driver->get_mac_addr) {
- return wpa_s->driver->get_mac_addr(wpa_s->drv_priv);
- }
- return NULL;
-}
-
-static inline int wpa_drv_send_eapol(struct wpa_supplicant *wpa_s,
- const u8 *dst, u16 proto,
- const u8 *data, size_t data_len)
-{
- if (wpa_s->driver->send_eapol)
- return wpa_s->driver->send_eapol(wpa_s->drv_priv, dst, proto,
- data, data_len);
- return -1;
-}
-
-static inline int wpa_drv_set_operstate(struct wpa_supplicant *wpa_s,
- int state)
-{
- if (wpa_s->driver->set_operstate)
- return wpa_s->driver->set_operstate(wpa_s->drv_priv, state);
- return 0;
-}
-
-static inline int wpa_drv_mlme_setprotection(struct wpa_supplicant *wpa_s,
- const u8 *addr, int protect_type,
- int key_type)
-{
- if (wpa_s->driver->mlme_setprotection)
- return wpa_s->driver->mlme_setprotection(wpa_s->drv_priv, addr,
- protect_type,
- key_type);
- return 0;
-}
-
-static inline struct wpa_hw_modes *
-wpa_drv_get_hw_feature_data(struct wpa_supplicant *wpa_s, u16 *num_modes,
- u16 *flags)
-{
- if (wpa_s->driver->get_hw_feature_data)
- return wpa_s->driver->get_hw_feature_data(wpa_s->drv_priv,
- num_modes, flags);
- return NULL;
-}
-
-static inline int wpa_drv_set_channel(struct wpa_supplicant *wpa_s,
- wpa_hw_mode phymode, int chan,
- int freq)
-{
- if (wpa_s->driver->set_channel)
- return wpa_s->driver->set_channel(wpa_s->drv_priv, phymode,
- chan, freq);
- return -1;
-}
-
-static inline int wpa_drv_set_ssid(struct wpa_supplicant *wpa_s,
- const u8 *ssid, size_t ssid_len)
-{
- if (wpa_s->driver->set_ssid) {
- return wpa_s->driver->set_ssid(wpa_s->drv_priv, ssid,
- ssid_len);
- }
- return -1;
-}
-
-static inline int wpa_drv_set_bssid(struct wpa_supplicant *wpa_s,
- const u8 *bssid)
-{
- if (wpa_s->driver->set_bssid) {
- return wpa_s->driver->set_bssid(wpa_s->drv_priv, bssid);
- }
- return -1;
-}
-
-static inline int wpa_drv_set_country(struct wpa_supplicant *wpa_s,
- const char *alpha2)
-{
- if (wpa_s->driver->set_country)
- return wpa_s->driver->set_country(wpa_s->drv_priv, alpha2);
- return 0;
-}
-
-static inline int wpa_drv_send_mlme(struct wpa_supplicant *wpa_s,
- const u8 *data, size_t data_len)
-{
- if (wpa_s->driver->send_mlme)
- return wpa_s->driver->send_mlme(wpa_s->drv_priv,
- data, data_len);
- return -1;
-}
-
-static inline int wpa_drv_mlme_add_sta(struct wpa_supplicant *wpa_s,
- const u8 *addr, const u8 *supp_rates,
- size_t supp_rates_len)
-{
- if (wpa_s->driver->mlme_add_sta)
- return wpa_s->driver->mlme_add_sta(wpa_s->drv_priv, addr,
- supp_rates, supp_rates_len);
- return -1;
-}
-
-static inline int wpa_drv_mlme_remove_sta(struct wpa_supplicant *wpa_s,
- const u8 *addr)
-{
- if (wpa_s->driver->mlme_remove_sta)
- return wpa_s->driver->mlme_remove_sta(wpa_s->drv_priv, addr);
- return -1;
-}
-
-static inline int wpa_drv_update_ft_ies(struct wpa_supplicant *wpa_s,
- const u8 *md,
- const u8 *ies, size_t ies_len)
-{
- if (wpa_s->driver->update_ft_ies)
- return wpa_s->driver->update_ft_ies(wpa_s->drv_priv, md,
- ies, ies_len);
- return -1;
-}
-
-static inline int wpa_drv_send_ft_action(struct wpa_supplicant *wpa_s,
- u8 action, const u8 *target_ap,
- const u8 *ies, size_t ies_len)
-{
- if (wpa_s->driver->send_ft_action)
- return wpa_s->driver->send_ft_action(wpa_s->drv_priv, action,
- target_ap, ies, ies_len);
- return -1;
-}
-
-static inline int wpa_drv_set_probe_req_ie(struct wpa_supplicant *wpa_s,
- const u8 *ies, size_t ies_len)
-{
- if (wpa_s->driver->set_probe_req_ie)
- return wpa_s->driver->set_probe_req_ie(wpa_s->drv_priv, ies,
- ies_len);
- return -1;
-}
+/* eap_register.c */
+int eap_register_methods(void);
#endif /* WPA_SUPPLICANT_I_H */
diff --git a/contrib/wpa/wpa_supplicant/wpas_glue.c b/contrib/wpa/wpa_supplicant/wpas_glue.c
index fc72cb8..4af0cd0 100644
--- a/contrib/wpa/wpa_supplicant/wpas_glue.c
+++ b/contrib/wpa/wpa_supplicant/wpas_glue.c
@@ -16,18 +16,22 @@
#include "common.h"
#include "eapol_supp/eapol_supp_sm.h"
-#include "wpa.h"
+#include "rsn_supp/wpa.h"
#include "eloop.h"
#include "config.h"
#include "l2_packet/l2_packet.h"
-#include "wpa_common.h"
+#include "common/wpa_common.h"
#include "wpa_supplicant_i.h"
-#include "pmksa_cache.h"
+#include "driver_i.h"
+#include "rsn_supp/pmksa_cache.h"
#include "mlme.h"
-#include "ieee802_11_defs.h"
-#include "wpa_ctrl.h"
+#include "sme.h"
+#include "common/ieee802_11_defs.h"
+#include "common/wpa_ctrl.h"
#include "wpas_glue.h"
#include "wps_supplicant.h"
+#include "bss.h"
+#include "scan.h"
#ifndef CONFIG_NO_CONFIG_BLOBS
@@ -241,7 +245,7 @@ static void wpa_supplicant_eapol_cb(struct eapol_sm *eapol, int success,
wpa_supplicant_req_auth_timeout(wpa_s, 2, 0);
}
- if (!success || !wpa_s->driver_4way_handshake)
+ if (!success || !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE))
return;
if (!wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt))
@@ -298,35 +302,29 @@ static void wpa_supplicant_notify_eapol_done(void *ctx)
static int wpa_get_beacon_ie(struct wpa_supplicant *wpa_s)
{
- size_t i;
int ret = 0;
- struct wpa_scan_res *curr = NULL;
+ struct wpa_bss *curr = NULL, *bss;
struct wpa_ssid *ssid = wpa_s->current_ssid;
const u8 *ie;
- if (wpa_s->scan_res == NULL)
- return -1;
-
- for (i = 0; i < wpa_s->scan_res->num; i++) {
- struct wpa_scan_res *r = wpa_s->scan_res->res[i];
- if (os_memcmp(r->bssid, wpa_s->bssid, ETH_ALEN) != 0)
+ dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
+ if (os_memcmp(bss->bssid, wpa_s->bssid, ETH_ALEN) != 0)
continue;
- ie = wpa_scan_get_ie(r, WLAN_EID_SSID);
if (ssid == NULL ||
- ((ie && ie[1] == ssid->ssid_len &&
- os_memcmp(ie + 2, ssid->ssid, ssid->ssid_len) == 0) ||
+ ((bss->ssid_len == ssid->ssid_len &&
+ os_memcmp(bss->ssid, ssid->ssid, ssid->ssid_len) == 0) ||
ssid->ssid_len == 0)) {
- curr = r;
+ curr = bss;
break;
}
}
if (curr) {
- ie = wpa_scan_get_vendor_ie(curr, WPA_IE_VENDOR_TYPE);
+ ie = wpa_bss_get_vendor_ie(curr, WPA_IE_VENDOR_TYPE);
if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0))
ret = -1;
- ie = wpa_scan_get_ie(curr, WLAN_EID_RSN);
+ ie = wpa_bss_get_ie(curr, WLAN_EID_RSN);
if (wpa_sm_set_ap_rsn_ie(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0))
ret = -1;
} else {
@@ -346,9 +344,8 @@ static int wpa_supplicant_get_beacon_ie(void *ctx)
/* No WPA/RSN IE found in the cached scan results. Try to get updated
* scan results from the driver. */
- if (wpa_supplicant_get_scan_results(wpa_s) < 0) {
+ if (wpa_supplicant_update_scan_results(wpa_s) < 0)
return -1;
- }
return wpa_get_beacon_ie(wpa_s);
}
@@ -375,7 +372,7 @@ static void _wpa_supplicant_cancel_auth_timeout(void *wpa_s)
}
-static void _wpa_supplicant_set_state(void *wpa_s, wpa_states state)
+static void _wpa_supplicant_set_state(void *wpa_s, enum wpa_states state)
{
wpa_supplicant_set_state(wpa_s, state);
}
@@ -386,13 +383,13 @@ static void _wpa_supplicant_set_state(void *wpa_s, wpa_states state)
* @wpa_s: Pointer to wpa_supplicant data
* Returns: The current connection state (WPA_*)
*/
-static wpa_states wpa_supplicant_get_state(struct wpa_supplicant *wpa_s)
+static enum wpa_states wpa_supplicant_get_state(struct wpa_supplicant *wpa_s)
{
return wpa_s->wpa_state;
}
-static wpa_states _wpa_supplicant_get_state(void *wpa_s)
+static enum wpa_states _wpa_supplicant_get_state(void *wpa_s)
{
return wpa_supplicant_get_state(wpa_s);
}
@@ -423,7 +420,7 @@ static void * wpa_supplicant_get_network_ctx(void *wpa_s)
static int wpa_supplicant_get_bssid(void *ctx, u8 *bssid)
{
struct wpa_supplicant *wpa_s = ctx;
- if (wpa_s->use_client_mlme) {
+ if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) {
os_memcpy(bssid, wpa_s->bssid, ETH_ALEN);
return 0;
}
@@ -431,7 +428,7 @@ static int wpa_supplicant_get_bssid(void *ctx, u8 *bssid)
}
-static int wpa_supplicant_set_key(void *_wpa_s, wpa_alg alg,
+static int wpa_supplicant_set_key(void *_wpa_s, enum wpa_alg alg,
const u8 *addr, int key_idx, int set_tx,
const u8 *seq, size_t seq_len,
const u8 *key, size_t key_len)
@@ -474,8 +471,10 @@ static int wpa_supplicant_update_ft_ies(void *ctx, const u8 *md,
const u8 *ies, size_t ies_len)
{
struct wpa_supplicant *wpa_s = ctx;
- if (wpa_s->use_client_mlme)
+ if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
return ieee80211_sta_update_ft_ies(wpa_s, md, ies, ies_len);
+ if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
+ return sme_update_ft_ies(wpa_s, md, ies, ies_len);
return wpa_drv_update_ft_ies(wpa_s, md, ies, ies_len);
}
@@ -485,16 +484,41 @@ static int wpa_supplicant_send_ft_action(void *ctx, u8 action,
const u8 *ies, size_t ies_len)
{
struct wpa_supplicant *wpa_s = ctx;
- if (wpa_s->use_client_mlme)
+ if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
return ieee80211_sta_send_ft_action(wpa_s, action, target_ap,
ies, ies_len);
return wpa_drv_send_ft_action(wpa_s, action, target_ap, ies, ies_len);
}
+
+
+static int wpa_supplicant_mark_authenticated(void *ctx, const u8 *target_ap)
+{
+ struct wpa_supplicant *wpa_s = ctx;
+ struct wpa_driver_auth_params params;
+ struct wpa_bss *bss;
+
+ if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
+ return -1;
+
+ bss = wpa_bss_get_bssid(wpa_s, target_ap);
+ if (bss == NULL)
+ return -1;
+
+ os_memset(&params, 0, sizeof(params));
+ params.bssid = target_ap;
+ params.freq = bss->freq;
+ params.ssid = bss->ssid;
+ params.ssid_len = bss->ssid_len;
+ params.auth_alg = WPA_AUTH_ALG_FT;
+ params.local_state_change = 1;
+ return wpa_drv_authenticate(wpa_s, &params);
+}
#endif /* CONFIG_IEEE80211R */
#endif /* CONFIG_NO_WPA */
+#ifdef IEEE8021X_EAPOL
#if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
static void wpa_supplicant_eap_param_needed(void *ctx, const char *field,
const char *txt)
@@ -533,6 +557,24 @@ static void wpa_supplicant_eap_param_needed(void *ctx, const char *field,
#endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
+static void wpa_supplicant_port_cb(void *ctx, int authorized)
+{
+ struct wpa_supplicant *wpa_s = ctx;
+#ifdef CONFIG_AP
+ if (wpa_s->ap_iface) {
+ wpa_printf(MSG_DEBUG, "AP mode active - skip EAPOL Supplicant "
+ "port status: %s",
+ authorized ? "Authorized" : "Unauthorized");
+ return;
+ }
+#endif /* CONFIG_AP */
+ wpa_printf(MSG_DEBUG, "EAPOL: Supplicant port status: %s",
+ authorized ? "Authorized" : "Unauthorized");
+ wpa_drv_set_supp_port(wpa_s, authorized);
+}
+#endif /* IEEE8021X_EAPOL */
+
+
int wpa_supplicant_init_eapol(struct wpa_supplicant *wpa_s)
{
#ifdef IEEE8021X_EAPOL
@@ -553,13 +595,12 @@ int wpa_supplicant_init_eapol(struct wpa_supplicant *wpa_s)
ctx->set_config_blob = wpa_supplicant_set_config_blob;
ctx->get_config_blob = wpa_supplicant_get_config_blob;
ctx->aborted_cached = wpa_supplicant_aborted_cached;
-#ifdef EAP_TLS_OPENSSL
ctx->opensc_engine_path = wpa_s->conf->opensc_engine_path;
ctx->pkcs11_engine_path = wpa_s->conf->pkcs11_engine_path;
ctx->pkcs11_module_path = wpa_s->conf->pkcs11_module_path;
-#endif /* EAP_TLS_OPENSSL */
ctx->wps = wpa_s->wps;
ctx->eap_param_needed = wpa_supplicant_eap_param_needed;
+ ctx->port_cb = wpa_supplicant_port_cb;
ctx->cb = wpa_supplicant_eapol_cb;
ctx->cb_ctx = wpa_s;
wpa_s->eapol = eapol_sm_init(ctx);
@@ -586,6 +627,7 @@ int wpa_supplicant_init_wpa(struct wpa_supplicant *wpa_s)
}
ctx->ctx = wpa_s;
+ ctx->msg_ctx = wpa_s;
ctx->set_state = _wpa_supplicant_set_state;
ctx->get_state = _wpa_supplicant_get_state;
ctx->deauthenticate = _wpa_supplicant_deauthenticate;
@@ -607,6 +649,7 @@ int wpa_supplicant_init_wpa(struct wpa_supplicant *wpa_s)
#ifdef CONFIG_IEEE80211R
ctx->update_ft_ies = wpa_supplicant_update_ft_ies;
ctx->send_ft_action = wpa_supplicant_send_ft_action;
+ ctx->mark_authenticated = wpa_supplicant_mark_authenticated;
#endif /* CONFIG_IEEE80211R */
wpa_s->wpa = wpa_sm_init(ctx);
diff --git a/contrib/wpa/wpa_supplicant/wps_supplicant.c b/contrib/wpa/wpa_supplicant/wps_supplicant.c
index 9422b1b..ba94d33 100644
--- a/contrib/wpa/wpa_supplicant/wps_supplicant.c
+++ b/contrib/wpa/wpa_supplicant/wps_supplicant.c
@@ -1,6 +1,6 @@
/*
* wpa_supplicant / WPS integration
- * Copyright (c) 2008, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2008-2010, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -15,18 +15,23 @@
#include "includes.h"
#include "common.h"
-#include "ieee802_11_defs.h"
-#include "wpa_common.h"
-#include "config.h"
-#include "eap_peer/eap.h"
-#include "wpa_supplicant_i.h"
#include "eloop.h"
#include "uuid.h"
-#include "wpa_ctrl.h"
-#include "ctrl_iface_dbus.h"
+#include "crypto/dh_group5.h"
+#include "common/ieee802_11_defs.h"
+#include "common/ieee802_11_common.h"
+#include "common/wpa_common.h"
+#include "common/wpa_ctrl.h"
#include "eap_common/eap_wsc_common.h"
+#include "eap_peer/eap.h"
+#include "rsn_supp/wpa.h"
+#include "config.h"
+#include "wpa_supplicant_i.h"
+#include "driver_i.h"
+#include "notify.h"
#include "blacklist.h"
-#include "wpa.h"
+#include "bss.h"
+#include "scan.h"
#include "wps_supplicant.h"
@@ -67,6 +72,8 @@ int wpas_wps_eapol_cb(struct wpa_supplicant *wpa_s)
"try to associate with the received credential");
wpa_supplicant_deauthenticate(wpa_s,
WLAN_REASON_DEAUTH_LEAVING);
+ wpa_s->after_wps = 5;
+ wpa_s->wps_freq = wpa_s->assoc_freq;
wpa_s->reassociate = 1;
wpa_supplicant_req_scan(wpa_s, 0, 0);
return 1;
@@ -90,8 +97,7 @@ static void wpas_wps_security_workaround(struct wpa_supplicant *wpa_s,
const struct wps_credential *cred)
{
struct wpa_driver_capa capa;
- size_t i;
- struct wpa_scan_res *bss;
+ struct wpa_bss *bss;
const u8 *ie;
struct wpa_ie_data adv;
int wpa2 = 0, ccmp = 0;
@@ -107,38 +113,22 @@ static void wpas_wps_security_workaround(struct wpa_supplicant *wpa_s,
if (wpa_drv_get_capa(wpa_s, &capa))
return; /* Unknown what driver supports */
- if (wpa_supplicant_get_scan_results(wpa_s) || wpa_s->scan_res == NULL)
- return; /* Could not get scan results for checking advertised
- * parameters */
-
- for (i = 0; i < wpa_s->scan_res->num; i++) {
- bss = wpa_s->scan_res->res[i];
- if (os_memcmp(bss->bssid, cred->mac_addr, ETH_ALEN) != 0)
- continue;
- ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
- if (ie == NULL)
- continue;
- if (ie[1] != ssid->ssid_len || ssid->ssid == NULL ||
- os_memcmp(ie + 2, ssid->ssid, ssid->ssid_len) != 0)
- continue;
-
- wpa_printf(MSG_DEBUG, "WPS: AP found from scan results");
- break;
- }
-
- if (i == wpa_s->scan_res->num) {
- wpa_printf(MSG_DEBUG, "WPS: The AP was not found from scan "
- "results - use credential as-is");
+ bss = wpa_bss_get(wpa_s, cred->mac_addr, ssid->ssid, ssid->ssid_len);
+ if (bss == NULL) {
+ wpa_printf(MSG_DEBUG, "WPS: The AP was not found from BSS "
+ "table - use credential as-is");
return;
}
- ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
+ wpa_printf(MSG_DEBUG, "WPS: AP found from BSS table");
+
+ ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
if (ie && wpa_parse_wpa_ie(ie, 2 + ie[1], &adv) == 0) {
wpa2 = 1;
if (adv.pairwise_cipher & WPA_CIPHER_CCMP)
ccmp = 1;
} else {
- ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
+ ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
if (ie && wpa_parse_wpa_ie(ie, 2 + ie[1], &adv) == 0 &&
adv.pairwise_cipher & WPA_CIPHER_CCMP)
ccmp = 1;
@@ -200,7 +190,8 @@ static int wpa_supplicant_wps_cred(void *ctx,
WPS_EVENT_CRED_RECEIVED, buf);
os_free(buf);
}
- wpa_supplicant_dbus_notify_wps_cred(wpa_s, cred);
+
+ wpas_notify_wps_credential(wpa_s, cred);
} else
wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_CRED_RECEIVED);
@@ -253,6 +244,7 @@ static int wpa_supplicant_wps_cred(void *ctx,
ssid = wpa_config_add_network(wpa_s->conf);
if (ssid == NULL)
return -1;
+ wpas_notify_network_added(wpa_s, ssid);
}
wpa_config_set_network_defaults(ssid);
@@ -385,6 +377,7 @@ static void wpa_supplicant_wps_event_m2d(struct wpa_supplicant *wpa_s,
wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_M2D
"dev_password_id=%d config_error=%d",
m2d->dev_password_id, m2d->config_error);
+ wpas_notify_wps_event_m2d(wpa_s, m2d);
}
@@ -393,6 +386,7 @@ static void wpa_supplicant_wps_event_fail(struct wpa_supplicant *wpa_s,
{
wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_FAIL "msg=%d", fail->msg);
wpas_clear_wps(wpa_s);
+ wpas_notify_wps_event_fail(wpa_s, fail);
}
@@ -400,6 +394,77 @@ static void wpa_supplicant_wps_event_success(struct wpa_supplicant *wpa_s)
{
wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_SUCCESS);
wpa_s->wps_success = 1;
+ wpas_notify_wps_event_success(wpa_s);
+}
+
+
+static void wpa_supplicant_wps_event_er_ap_add(struct wpa_supplicant *wpa_s,
+ struct wps_event_er_ap *ap)
+{
+ char uuid_str[100];
+ char dev_type[WPS_DEV_TYPE_BUFSIZE];
+
+ uuid_bin2str(ap->uuid, uuid_str, sizeof(uuid_str));
+ if (ap->pri_dev_type)
+ wps_dev_type_bin2str(ap->pri_dev_type, dev_type,
+ sizeof(dev_type));
+ else
+ dev_type[0] = '\0';
+
+ wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_AP_ADD "%s " MACSTR
+ " pri_dev_type=%s wps_state=%d |%s|%s|%s|%s|%s|%s|",
+ uuid_str, MAC2STR(ap->mac_addr), dev_type, ap->wps_state,
+ ap->friendly_name ? ap->friendly_name : "",
+ ap->manufacturer ? ap->manufacturer : "",
+ ap->model_description ? ap->model_description : "",
+ ap->model_name ? ap->model_name : "",
+ ap->manufacturer_url ? ap->manufacturer_url : "",
+ ap->model_url ? ap->model_url : "");
+}
+
+
+static void wpa_supplicant_wps_event_er_ap_remove(struct wpa_supplicant *wpa_s,
+ struct wps_event_er_ap *ap)
+{
+ char uuid_str[100];
+ uuid_bin2str(ap->uuid, uuid_str, sizeof(uuid_str));
+ wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_AP_REMOVE "%s", uuid_str);
+}
+
+
+static void wpa_supplicant_wps_event_er_enrollee_add(
+ struct wpa_supplicant *wpa_s, struct wps_event_er_enrollee *enrollee)
+{
+ char uuid_str[100];
+ char dev_type[WPS_DEV_TYPE_BUFSIZE];
+
+ uuid_bin2str(enrollee->uuid, uuid_str, sizeof(uuid_str));
+ if (enrollee->pri_dev_type)
+ wps_dev_type_bin2str(enrollee->pri_dev_type, dev_type,
+ sizeof(dev_type));
+ else
+ dev_type[0] = '\0';
+
+ wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_ENROLLEE_ADD "%s " MACSTR
+ " M1=%d config_methods=0x%x dev_passwd_id=%d pri_dev_type=%s "
+ "|%s|%s|%s|%s|%s|",
+ uuid_str, MAC2STR(enrollee->mac_addr), enrollee->m1_received,
+ enrollee->config_methods, enrollee->dev_passwd_id, dev_type,
+ enrollee->dev_name ? enrollee->dev_name : "",
+ enrollee->manufacturer ? enrollee->manufacturer : "",
+ enrollee->model_name ? enrollee->model_name : "",
+ enrollee->model_number ? enrollee->model_number : "",
+ enrollee->serial_number ? enrollee->serial_number : "");
+}
+
+
+static void wpa_supplicant_wps_event_er_enrollee_remove(
+ struct wpa_supplicant *wpa_s, struct wps_event_er_enrollee *enrollee)
+{
+ char uuid_str[100];
+ uuid_bin2str(enrollee->uuid, uuid_str, sizeof(uuid_str));
+ wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_ENROLLEE_REMOVE "%s " MACSTR,
+ uuid_str, MAC2STR(enrollee->mac_addr));
}
@@ -423,6 +488,20 @@ static void wpa_supplicant_wps_event(void *ctx, enum wps_event event,
break;
case WPS_EV_PBC_TIMEOUT:
break;
+ case WPS_EV_ER_AP_ADD:
+ wpa_supplicant_wps_event_er_ap_add(wpa_s, &data->ap);
+ break;
+ case WPS_EV_ER_AP_REMOVE:
+ wpa_supplicant_wps_event_er_ap_remove(wpa_s, &data->ap);
+ break;
+ case WPS_EV_ER_ENROLLEE_ADD:
+ wpa_supplicant_wps_event_er_enrollee_add(wpa_s,
+ &data->enrollee);
+ break;
+ case WPS_EV_ER_ENROLLEE_REMOVE:
+ wpa_supplicant_wps_event_er_enrollee_remove(wpa_s,
+ &data->enrollee);
+ break;
}
}
@@ -440,7 +519,7 @@ enum wps_request_type wpas_wps_get_req_type(struct wpa_ssid *ssid)
static void wpas_clear_wps(struct wpa_supplicant *wpa_s)
{
int id;
- struct wpa_ssid *ssid;
+ struct wpa_ssid *ssid, *remove_ssid = NULL;
eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL);
@@ -448,14 +527,20 @@ static void wpas_clear_wps(struct wpa_supplicant *wpa_s)
ssid = wpa_s->conf->ssid;
while (ssid) {
if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
- if (ssid == wpa_s->current_ssid)
+ if (ssid == wpa_s->current_ssid) {
wpa_s->current_ssid = NULL;
+ if (ssid != NULL)
+ wpas_notify_network_changed(wpa_s);
+ }
id = ssid->id;
+ remove_ssid = ssid;
} else
id = -1;
ssid = ssid->next;
- if (id >= 0)
+ if (id >= 0) {
+ wpas_notify_network_removed(wpa_s, remove_ssid);
wpa_config_remove_network(wpa_s->conf, id);
+ }
}
}
@@ -477,45 +562,35 @@ static struct wpa_ssid * wpas_wps_add_network(struct wpa_supplicant *wpa_s,
ssid = wpa_config_add_network(wpa_s->conf);
if (ssid == NULL)
return NULL;
+ wpas_notify_network_added(wpa_s, ssid);
wpa_config_set_network_defaults(ssid);
if (wpa_config_set(ssid, "key_mgmt", "WPS", 0) < 0 ||
wpa_config_set(ssid, "eap", "WSC", 0) < 0 ||
wpa_config_set(ssid, "identity", registrar ?
"\"" WSC_ID_REGISTRAR "\"" :
"\"" WSC_ID_ENROLLEE "\"", 0) < 0) {
+ wpas_notify_network_removed(wpa_s, ssid);
wpa_config_remove_network(wpa_s->conf, ssid->id);
return NULL;
}
if (bssid) {
- size_t i;
+ struct wpa_bss *bss;
int count = 0;
os_memcpy(ssid->bssid, bssid, ETH_ALEN);
ssid->bssid_set = 1;
- /* Try to get SSID from scan results */
- if (wpa_s->scan_res == NULL &&
- wpa_supplicant_get_scan_results(wpa_s) < 0)
- return ssid; /* Could not find any scan results */
-
- for (i = 0; i < wpa_s->scan_res->num; i++) {
- const u8 *ie;
- struct wpa_scan_res *res;
-
- res = wpa_s->scan_res->res[i];
- if (os_memcmp(bssid, res->bssid, ETH_ALEN) != 0)
+ dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
+ if (os_memcmp(bssid, bss->bssid, ETH_ALEN) != 0)
continue;
- ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
- if (ie == NULL)
- break;
os_free(ssid->ssid);
- ssid->ssid = os_malloc(ie[1]);
+ ssid->ssid = os_malloc(bss->ssid_len);
if (ssid->ssid == NULL)
break;
- os_memcpy(ssid->ssid, ie + 2, ie[1]);
- ssid->ssid_len = ie[1];
+ os_memcpy(ssid->ssid, bss->ssid, bss->ssid_len);
+ ssid->ssid_len = bss->ssid_len;
wpa_hexdump_ascii(MSG_DEBUG, "WPS: Picked SSID from "
"scan results",
ssid->ssid, ssid->ssid_len);
@@ -543,7 +618,10 @@ static void wpas_wps_reassoc(struct wpa_supplicant *wpa_s,
/* Mark all other networks disabled and trigger reassociation */
ssid = wpa_s->conf->ssid;
while (ssid) {
+ int was_disabled = ssid->disabled;
ssid->disabled = ssid != selected;
+ if (was_disabled != ssid->disabled)
+ wpas_notify_network_enabled_changed(wpa_s, ssid);
ssid = ssid->next;
}
wpa_s->disconnected = 0;
@@ -574,7 +652,7 @@ int wpas_wps_start_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
const char *pin)
{
struct wpa_ssid *ssid;
- char val[30];
+ char val[128];
unsigned int rpin = 0;
wpas_clear_wps(wpa_s);
@@ -595,11 +673,63 @@ int wpas_wps_start_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
}
+#ifdef CONFIG_WPS_OOB
+int wpas_wps_start_oob(struct wpa_supplicant *wpa_s, char *device_type,
+ char *path, char *method, char *name)
+{
+ struct wps_context *wps = wpa_s->wps;
+ struct oob_device_data *oob_dev;
+
+ oob_dev = wps_get_oob_device(device_type);
+ if (oob_dev == NULL)
+ return -1;
+ oob_dev->device_path = path;
+ oob_dev->device_name = name;
+ wps->oob_conf.oob_method = wps_get_oob_method(method);
+
+ if (wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_E) {
+ /*
+ * Use pre-configured DH keys in order to be able to write the
+ * key hash into the OOB file.
+ */
+ wpabuf_free(wps->dh_pubkey);
+ wpabuf_free(wps->dh_privkey);
+ wps->dh_privkey = NULL;
+ wps->dh_pubkey = NULL;
+ dh5_free(wps->dh_ctx);
+ wps->dh_ctx = dh5_init(&wps->dh_privkey, &wps->dh_pubkey);
+ wps->dh_pubkey = wpabuf_zeropad(wps->dh_pubkey, 192);
+ if (wps->dh_ctx == NULL || wps->dh_pubkey == NULL) {
+ wpa_printf(MSG_ERROR, "WPS: Failed to initialize "
+ "Diffie-Hellman handshake");
+ return -1;
+ }
+ }
+
+ if (wps->oob_conf.oob_method == OOB_METHOD_CRED)
+ wpas_clear_wps(wpa_s);
+
+ if (wps_process_oob(wps, oob_dev, 0) < 0)
+ return -1;
+
+ if ((wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_E ||
+ wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_R) &&
+ wpas_wps_start_pin(wpa_s, NULL,
+ wpabuf_head(wps->oob_conf.dev_password)) < 0)
+ return -1;
+
+ return 0;
+}
+#endif /* CONFIG_WPS_OOB */
+
+
int wpas_wps_start_reg(struct wpa_supplicant *wpa_s, const u8 *bssid,
- const char *pin)
+ const char *pin, struct wps_new_ap_settings *settings)
{
struct wpa_ssid *ssid;
- char val[30];
+ char val[200];
+ char *pos, *end;
+ int res;
if (!pin)
return -1;
@@ -607,7 +737,24 @@ int wpas_wps_start_reg(struct wpa_supplicant *wpa_s, const u8 *bssid,
ssid = wpas_wps_add_network(wpa_s, 1, bssid);
if (ssid == NULL)
return -1;
- os_snprintf(val, sizeof(val), "\"pin=%s\"", pin);
+ pos = val;
+ end = pos + sizeof(val);
+ res = os_snprintf(pos, end - pos, "\"pin=%s", pin);
+ if (res < 0 || res >= end - pos)
+ return -1;
+ pos += res;
+ if (settings) {
+ res = os_snprintf(pos, end - pos, " new_ssid=%s new_auth=%s "
+ "new_encr=%s new_key=%s",
+ settings->ssid_hex, settings->auth,
+ settings->encr, settings->key_hex);
+ if (res < 0 || res >= end - pos)
+ return -1;
+ pos += res;
+ }
+ res = os_snprintf(pos, end - pos, "\"");
+ if (res < 0 || res >= end - pos)
+ return -1;
wpa_config_set(ssid, "phase1", val, 0);
eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
wpa_s, NULL);
@@ -634,20 +781,36 @@ static void wpas_wps_pin_needed_cb(void *ctx, const u8 *uuid_e,
{
char uuid[40], txt[400];
int len;
+ char devtype[WPS_DEV_TYPE_BUFSIZE];
if (uuid_bin2str(uuid_e, uuid, sizeof(uuid)))
return;
wpa_printf(MSG_DEBUG, "WPS: PIN needed for UUID-E %s", uuid);
len = os_snprintf(txt, sizeof(txt), "WPS-EVENT-PIN-NEEDED %s " MACSTR
- " [%s|%s|%s|%s|%s|%d-%08X-%d]",
+ " [%s|%s|%s|%s|%s|%s]",
uuid, MAC2STR(dev->mac_addr), dev->device_name,
dev->manufacturer, dev->model_name,
dev->model_number, dev->serial_number,
- dev->categ, dev->oui, dev->sub_categ);
+ wps_dev_type_bin2str(dev->pri_dev_type, devtype,
+ sizeof(devtype)));
if (len > 0 && len < (int) sizeof(txt))
wpa_printf(MSG_INFO, "%s", txt);
}
+static void wpas_wps_set_sel_reg_cb(void *ctx, int sel_reg, u16 dev_passwd_id,
+ u16 sel_reg_config_methods)
+{
+#ifdef CONFIG_WPS_ER
+ struct wpa_supplicant *wpa_s = ctx;
+
+ if (wpa_s->wps_er == NULL)
+ return;
+ wps_er_set_sel_reg(wpa_s->wps_er, sel_reg, dev_passwd_id,
+ sel_reg_config_methods);
+#endif /* CONFIG_WPS_ER */
+}
+
+
int wpas_wps_init(struct wpa_supplicant *wpa_s)
{
struct wps_context *wps;
@@ -666,32 +829,14 @@ int wpas_wps_init(struct wpa_supplicant *wpa_s)
wps->dev.model_name = wpa_s->conf->model_name;
wps->dev.model_number = wpa_s->conf->model_number;
wps->dev.serial_number = wpa_s->conf->serial_number;
- if (wpa_s->conf->device_type) {
- char *pos;
- u8 oui[4];
- /* <categ>-<OUI>-<subcateg> */
- wps->dev.categ = atoi(wpa_s->conf->device_type);
- pos = os_strchr(wpa_s->conf->device_type, '-');
- if (pos == NULL) {
- wpa_printf(MSG_ERROR, "WPS: Invalid device_type");
- os_free(wps);
- return -1;
- }
- pos++;
- if (hexstr2bin(pos, oui, 4)) {
- wpa_printf(MSG_ERROR, "WPS: Invalid device_type OUI");
- os_free(wps);
- return -1;
- }
- wps->dev.oui = WPA_GET_BE32(oui);
- pos = os_strchr(pos, '-');
- if (pos == NULL) {
- wpa_printf(MSG_ERROR, "WPS: Invalid device_type");
- os_free(wps);
- return -1;
- }
- pos++;
- wps->dev.sub_categ = atoi(pos);
+ wps->config_methods =
+ wps_config_methods_str2bin(wpa_s->conf->config_methods);
+ if (wpa_s->conf->device_type &&
+ wps_dev_type_str2bin(wpa_s->conf->device_type,
+ wps->dev.pri_dev_type) < 0) {
+ wpa_printf(MSG_ERROR, "WPS: Invalid device_type");
+ os_free(wps);
+ return -1;
}
wps->dev.os_version = WPA_GET_BE32(wpa_s->conf->os_version);
wps->dev.rf_bands = WPS_RF_24GHZ | WPS_RF_50GHZ; /* TODO: config */
@@ -709,6 +854,7 @@ int wpas_wps_init(struct wpa_supplicant *wpa_s)
os_memset(&rcfg, 0, sizeof(rcfg));
rcfg.new_psk_cb = wpas_wps_new_psk_cb;
rcfg.pin_needed_cb = wpas_wps_pin_needed_cb;
+ rcfg.set_sel_reg_cb = wpas_wps_set_sel_reg_cb;
rcfg.cb_ctx = wpa_s;
wps->registrar = wps_registrar_init(wps, &rcfg);
@@ -731,7 +877,16 @@ void wpas_wps_deinit(struct wpa_supplicant *wpa_s)
if (wpa_s->wps == NULL)
return;
+#ifdef CONFIG_WPS_ER
+ wps_er_deinit(wpa_s->wps_er, NULL, NULL);
+ wpa_s->wps_er = NULL;
+#endif /* CONFIG_WPS_ER */
+
wps_registrar_deinit(wpa_s->wps->registrar);
+ wpabuf_free(wpa_s->wps->dh_pubkey);
+ wpabuf_free(wpa_s->wps->dh_privkey);
+ wpabuf_free(wpa_s->wps->oob_conf.pubkey_hash);
+ wpabuf_free(wpa_s->wps->oob_conf.dev_password);
os_free(wpa_s->wps->network_key);
os_free(wpa_s->wps);
wpa_s->wps = NULL;
@@ -841,30 +996,28 @@ int wpas_wps_ssid_wildcard_ok(struct wpa_supplicant *wpa_s,
int wpas_wps_scan_pbc_overlap(struct wpa_supplicant *wpa_s,
- struct wpa_scan_res *selected,
- struct wpa_ssid *ssid)
+ struct wpa_bss *selected, struct wpa_ssid *ssid)
{
const u8 *sel_uuid, *uuid;
- size_t i;
struct wpabuf *wps_ie;
int ret = 0;
+ struct wpa_bss *bss;
if (!eap_is_wps_pbc_enrollee(&ssid->eap))
return 0;
/* Make sure that only one AP is in active PBC mode */
- wps_ie = wpa_scan_get_vendor_ie_multi(selected, WPS_IE_VENDOR_TYPE);
+ wps_ie = wpa_bss_get_vendor_ie_multi(selected, WPS_IE_VENDOR_TYPE);
if (wps_ie)
sel_uuid = wps_get_uuid_e(wps_ie);
else
sel_uuid = NULL;
- for (i = 0; i < wpa_s->scan_res->num; i++) {
- struct wpa_scan_res *bss = wpa_s->scan_res->res[i];
+ dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
struct wpabuf *ie;
if (bss == selected)
continue;
- ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
+ ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
if (!ie)
continue;
if (!wps_is_selected_pbc_registrar(ie)) {
@@ -892,23 +1045,25 @@ int wpas_wps_scan_pbc_overlap(struct wpa_supplicant *wpa_s,
void wpas_wps_notify_scan_results(struct wpa_supplicant *wpa_s)
{
- size_t i;
+ struct wpa_bss *bss;
if (wpa_s->disconnected || wpa_s->wpa_state >= WPA_ASSOCIATED)
return;
- for (i = 0; i < wpa_s->scan_res->num; i++) {
- struct wpa_scan_res *bss = wpa_s->scan_res->res[i];
+ dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
struct wpabuf *ie;
- ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
+ ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
if (!ie)
continue;
if (wps_is_selected_pbc_registrar(ie))
- wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE_PBC);
+ wpa_msg_ctrl(wpa_s, MSG_INFO,
+ WPS_EVENT_AP_AVAILABLE_PBC);
else if (wps_is_selected_pin_registrar(ie))
- wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE_PIN);
+ wpa_msg_ctrl(wpa_s, MSG_INFO,
+ WPS_EVENT_AP_AVAILABLE_PIN);
else
- wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE);
+ wpa_msg_ctrl(wpa_s, MSG_INFO,
+ WPS_EVENT_AP_AVAILABLE);
wpabuf_free(ie);
break;
}
@@ -926,3 +1081,105 @@ int wpas_wps_searching(struct wpa_supplicant *wpa_s)
return 0;
}
+
+
+int wpas_wps_scan_result_text(const u8 *ies, size_t ies_len, char *buf,
+ char *end)
+{
+ struct wpabuf *wps_ie;
+ int ret;
+
+ wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len, WPS_DEV_OUI_WFA);
+ if (wps_ie == NULL)
+ return 0;
+
+ ret = wps_attr_text(wps_ie, buf, end);
+ wpabuf_free(wps_ie);
+ return ret;
+}
+
+
+int wpas_wps_er_start(struct wpa_supplicant *wpa_s)
+{
+#ifdef CONFIG_WPS_ER
+ if (wpa_s->wps_er) {
+ wps_er_refresh(wpa_s->wps_er);
+ return 0;
+ }
+ wpa_s->wps_er = wps_er_init(wpa_s->wps, wpa_s->ifname);
+ if (wpa_s->wps_er == NULL)
+ return -1;
+ return 0;
+#else /* CONFIG_WPS_ER */
+ return 0;
+#endif /* CONFIG_WPS_ER */
+}
+
+
+int wpas_wps_er_stop(struct wpa_supplicant *wpa_s)
+{
+#ifdef CONFIG_WPS_ER
+ wps_er_deinit(wpa_s->wps_er, NULL, NULL);
+ wpa_s->wps_er = NULL;
+#endif /* CONFIG_WPS_ER */
+ return 0;
+}
+
+
+#ifdef CONFIG_WPS_ER
+int wpas_wps_er_add_pin(struct wpa_supplicant *wpa_s, const char *uuid,
+ const char *pin)
+{
+ u8 u[UUID_LEN];
+ int any = 0;
+
+ if (os_strcmp(uuid, "any") == 0)
+ any = 1;
+ else if (uuid_str2bin(uuid, u))
+ return -1;
+ return wps_registrar_add_pin(wpa_s->wps->registrar, any ? NULL : u,
+ (const u8 *) pin, os_strlen(pin), 300);
+}
+
+
+int wpas_wps_er_pbc(struct wpa_supplicant *wpa_s, const char *uuid)
+{
+ u8 u[UUID_LEN];
+
+ if (uuid_str2bin(uuid, u))
+ return -1;
+ return wps_er_pbc(wpa_s->wps_er, u);
+}
+
+
+int wpas_wps_er_learn(struct wpa_supplicant *wpa_s, const char *uuid,
+ const char *pin)
+{
+ u8 u[UUID_LEN];
+
+ if (uuid_str2bin(uuid, u))
+ return -1;
+ return wps_er_learn(wpa_s->wps_er, u, (const u8 *) pin,
+ os_strlen(pin));
+}
+
+
+static void wpas_wps_terminate_cb(void *ctx)
+{
+ wpa_printf(MSG_DEBUG, "WPS ER: Terminated");
+ eloop_terminate();
+}
+#endif /* CONFIG_WPS_ER */
+
+
+int wpas_wps_terminate_pending(struct wpa_supplicant *wpa_s)
+{
+#ifdef CONFIG_WPS_ER
+ if (wpa_s->wps_er) {
+ wps_er_deinit(wpa_s->wps_er, wpas_wps_terminate_cb, wpa_s);
+ wpa_s->wps_er = NULL;
+ return 1;
+ }
+#endif /* CONFIG_WPS_ER */
+ return 0;
+}
diff --git a/contrib/wpa/wpa_supplicant/wps_supplicant.h b/contrib/wpa/wpa_supplicant/wps_supplicant.h
index 8f81dc4..ba2fb16 100644
--- a/contrib/wpa/wpa_supplicant/wps_supplicant.h
+++ b/contrib/wpa/wpa_supplicant/wps_supplicant.h
@@ -1,6 +1,6 @@
/*
* wpa_supplicant / WPS integration
- * Copyright (c) 2008, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2008-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -15,11 +15,22 @@
#ifndef WPS_SUPPLICANT_H
#define WPS_SUPPLICANT_H
+struct wpa_scan_res;
+
#ifdef CONFIG_WPS
#include "wps/wps.h"
#include "wps/wps_defs.h"
+struct wpa_bss;
+
+struct wps_new_ap_settings {
+ const char *ssid_hex;
+ const char *auth;
+ const char *encr;
+ const char *key_hex;
+};
+
int wpas_wps_init(struct wpa_supplicant *wpa_s);
void wpas_wps_deinit(struct wpa_supplicant *wpa_s);
int wpas_wps_eapol_cb(struct wpa_supplicant *wpa_s);
@@ -27,17 +38,28 @@ enum wps_request_type wpas_wps_get_req_type(struct wpa_ssid *ssid);
int wpas_wps_start_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid);
int wpas_wps_start_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
const char *pin);
+int wpas_wps_start_oob(struct wpa_supplicant *wpa_s, char *device_type,
+ char *path, char *method, char *name);
int wpas_wps_start_reg(struct wpa_supplicant *wpa_s, const u8 *bssid,
- const char *pin);
+ const char *pin, struct wps_new_ap_settings *settings);
int wpas_wps_ssid_bss_match(struct wpa_supplicant *wpa_s,
struct wpa_ssid *ssid, struct wpa_scan_res *bss);
int wpas_wps_ssid_wildcard_ok(struct wpa_supplicant *wpa_s,
struct wpa_ssid *ssid, struct wpa_scan_res *bss);
int wpas_wps_scan_pbc_overlap(struct wpa_supplicant *wpa_s,
- struct wpa_scan_res *selected,
- struct wpa_ssid *ssid);
+ struct wpa_bss *selected, struct wpa_ssid *ssid);
void wpas_wps_notify_scan_results(struct wpa_supplicant *wpa_s);
int wpas_wps_searching(struct wpa_supplicant *wpa_s);
+int wpas_wps_scan_result_text(const u8 *ies, size_t ies_len, char *pos,
+ char *end);
+int wpas_wps_er_start(struct wpa_supplicant *wpa_s);
+int wpas_wps_er_stop(struct wpa_supplicant *wpa_s);
+int wpas_wps_er_add_pin(struct wpa_supplicant *wpa_s, const char *uuid,
+ const char *pin);
+int wpas_wps_er_pbc(struct wpa_supplicant *wpa_s, const char *uuid);
+int wpas_wps_er_learn(struct wpa_supplicant *wpa_s, const char *uuid,
+ const char *pin);
+int wpas_wps_terminate_pending(struct wpa_supplicant *wpa_s);
#else /* CONFIG_WPS */
@@ -75,7 +97,7 @@ static inline int wpas_wps_ssid_wildcard_ok(struct wpa_supplicant *wpa_s,
}
static inline int wpas_wps_scan_pbc_overlap(struct wpa_supplicant *wpa_s,
- struct wpa_scan_res *selected,
+ struct wpa_bss *selected,
struct wpa_ssid *ssid)
{
return 0;
diff --git a/contrib/wpa/wpa_supplicant/xcode/wpa_supplicant.xcodeproj/project.pbxproj b/contrib/wpa/wpa_supplicant/xcode/wpa_supplicant.xcodeproj/project.pbxproj
new file mode 100644
index 0000000..6fea81b
--- /dev/null
+++ b/contrib/wpa/wpa_supplicant/xcode/wpa_supplicant.xcodeproj/project.pbxproj
@@ -0,0 +1,513 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 45;
+ objects = {
+
+/* Begin PBXBuildFile section */
+ 881EED0F10DC14EF009E449F /* eap_register.c in Sources */ = {isa = PBXBuildFile; fileRef = 881EED0E10DC14EF009E449F /* eap_register.c */; };
+ 8853CB17109F385C00358CEF /* libpcap.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 8853CB16109F385C00358CEF /* libpcap.dylib */; };
+ 8853CB1B109F389800358CEF /* libcrypto.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 8853CB1A109F389800358CEF /* libcrypto.dylib */; };
+ 8853CB1F109F38BD00358CEF /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8853CB1E109F38BD00358CEF /* CoreFoundation.framework */; };
+ 8853CB2E109F3A3900358CEF /* scan_helpers.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CB2D109F3A3900358CEF /* scan_helpers.c */; };
+ 8853CB32109F3A9400358CEF /* wpa_common.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CB31109F3A9400358CEF /* wpa_common.c */; };
+ 8853CB36109F3AC700358CEF /* md5.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CB35109F3AC700358CEF /* md5.c */; };
+ 8853CB3C109F3B5800358CEF /* Apple80211.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8853CB3B109F3B5800358CEF /* Apple80211.framework */; };
+ 8853CBFB109F4C6E00358CEF /* eap_gtc.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CBEC109F4C6E00358CEF /* eap_gtc.c */; };
+ 8853CBFC109F4C6E00358CEF /* eap_leap.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CBED109F4C6E00358CEF /* eap_leap.c */; };
+ 8853CBFD109F4C6E00358CEF /* eap_md5.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CBEE109F4C6E00358CEF /* eap_md5.c */; };
+ 8853CBFE109F4C6E00358CEF /* eap_methods.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CBEF109F4C6E00358CEF /* eap_methods.c */; };
+ 8853CBFF109F4C6E00358CEF /* eap_mschapv2.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CBF0109F4C6E00358CEF /* eap_mschapv2.c */; };
+ 8853CC00109F4C6E00358CEF /* eap_otp.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CBF1109F4C6E00358CEF /* eap_otp.c */; };
+ 8853CC01109F4C6E00358CEF /* eap_peap.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CBF2109F4C6E00358CEF /* eap_peap.c */; };
+ 8853CC02109F4C6E00358CEF /* eap_tls_common.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CBF3109F4C6E00358CEF /* eap_tls_common.c */; };
+ 8853CC03109F4C6E00358CEF /* eap_tls.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CBF4109F4C6E00358CEF /* eap_tls.c */; };
+ 8853CC04109F4C6E00358CEF /* eap_tnc.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CBF5109F4C6E00358CEF /* eap_tnc.c */; };
+ 8853CC05109F4C6E00358CEF /* eap_ttls.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CBF6109F4C6E00358CEF /* eap_ttls.c */; };
+ 8853CC06109F4C6E00358CEF /* eap_wsc.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CBF7109F4C6E00358CEF /* eap_wsc.c */; };
+ 8853CC07109F4C6E00358CEF /* eap.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CBF8109F4C6E00358CEF /* eap.c */; };
+ 8853CC08109F4C6E00358CEF /* mschapv2.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CBF9109F4C6E00358CEF /* mschapv2.c */; };
+ 8853CC09109F4C6E00358CEF /* tncc.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CBFA109F4C6E00358CEF /* tncc.c */; };
+ 8853CC0E109F4CA100358CEF /* ctrl_iface_unix.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CC0C109F4CA100358CEF /* ctrl_iface_unix.c */; };
+ 8853CC0F109F4CA100358CEF /* ctrl_iface.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CC0D109F4CA100358CEF /* ctrl_iface.c */; };
+ 8853CC11109F4CC800358CEF /* eapol_supp_sm.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CC10109F4CC800358CEF /* eapol_supp_sm.c */; };
+ 8853CC18109F4D0800358CEF /* chap.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CC14109F4D0800358CEF /* chap.c */; };
+ 8853CC19109F4D0800358CEF /* eap_common.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CC15109F4D0800358CEF /* eap_common.c */; };
+ 8853CC1A109F4D0800358CEF /* eap_peap_common.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CC16109F4D0800358CEF /* eap_peap_common.c */; };
+ 8853CC1B109F4D0800358CEF /* eap_wsc_common.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CC17109F4D0800358CEF /* eap_wsc_common.c */; };
+ 8853CC26109F4D3500358CEF /* wps_attr_build.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CC1E109F4D3500358CEF /* wps_attr_build.c */; };
+ 8853CC27109F4D3500358CEF /* wps_attr_parse.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CC1F109F4D3500358CEF /* wps_attr_parse.c */; };
+ 8853CC28109F4D3500358CEF /* wps_attr_process.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CC20109F4D3500358CEF /* wps_attr_process.c */; };
+ 8853CC29109F4D3500358CEF /* wps_common.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CC21109F4D3500358CEF /* wps_common.c */; };
+ 8853CC2A109F4D3500358CEF /* wps_dev_attr.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CC22109F4D3500358CEF /* wps_dev_attr.c */; };
+ 8853CC2B109F4D3500358CEF /* wps_enrollee.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CC23109F4D3500358CEF /* wps_enrollee.c */; };
+ 8853CC2C109F4D3500358CEF /* wps_registrar.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CC24109F4D3500358CEF /* wps_registrar.c */; };
+ 8853CC2D109F4D3500358CEF /* wps.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CC25109F4D3500358CEF /* wps.c */; };
+ 8853CC34109F4DE200358CEF /* ms_funcs.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CC32109F4DE200358CEF /* ms_funcs.c */; };
+ 8853CC35109F4DE200358CEF /* tls_openssl.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CC33109F4DE200358CEF /* tls_openssl.c */; };
+ 8853CC3C109F4E1D00358CEF /* libssl.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 8853CC3B109F4E1D00358CEF /* libssl.dylib */; };
+ 8853CC40109F4E3A00358CEF /* wps_supplicant.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CC3F109F4E3A00358CEF /* wps_supplicant.c */; };
+ 8853CC44109F4E6200358CEF /* uuid.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CC43109F4E6200358CEF /* uuid.c */; };
+ 8853CC48109F4E8700358CEF /* ieee802_11_common.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CC47109F4E8700358CEF /* ieee802_11_common.c */; };
+ 8853CC4E109F4ED500358CEF /* sha256.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CC4C109F4ED500358CEF /* sha256.c */; };
+ 8853CC53109F4F3500358CEF /* aes-cbc.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CC51109F4F3500358CEF /* aes-cbc.c */; };
+ 8853CC54109F4F3500358CEF /* sha1-tlsprf.c in Sources */ = {isa = PBXBuildFile; fileRef = 8853CC52109F4F3500358CEF /* sha1-tlsprf.c */; };
+ 88950831109F2FAB004FB35D /* blacklist.c in Sources */ = {isa = PBXBuildFile; fileRef = 88950828109F2FAB004FB35D /* blacklist.c */; };
+ 88950832109F2FAB004FB35D /* config_file.c in Sources */ = {isa = PBXBuildFile; fileRef = 88950829109F2FAB004FB35D /* config_file.c */; };
+ 88950833109F2FAB004FB35D /* config.c in Sources */ = {isa = PBXBuildFile; fileRef = 8895082A109F2FAB004FB35D /* config.c */; };
+ 88950834109F2FAB004FB35D /* events.c in Sources */ = {isa = PBXBuildFile; fileRef = 8895082B109F2FAB004FB35D /* events.c */; };
+ 88950835109F2FAB004FB35D /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = 8895082C109F2FAB004FB35D /* main.c */; };
+ 88950836109F2FAB004FB35D /* notify.c in Sources */ = {isa = PBXBuildFile; fileRef = 8895082D109F2FAB004FB35D /* notify.c */; };
+ 88950837109F2FAB004FB35D /* scan.c in Sources */ = {isa = PBXBuildFile; fileRef = 8895082E109F2FAB004FB35D /* scan.c */; };
+ 88950838109F2FAB004FB35D /* wpa_supplicant.c in Sources */ = {isa = PBXBuildFile; fileRef = 8895082F109F2FAB004FB35D /* wpa_supplicant.c */; };
+ 88950839109F2FAB004FB35D /* wpas_glue.c in Sources */ = {isa = PBXBuildFile; fileRef = 88950830109F2FAB004FB35D /* wpas_glue.c */; };
+ 88950840109F301A004FB35D /* base64.c in Sources */ = {isa = PBXBuildFile; fileRef = 8895083A109F301A004FB35D /* base64.c */; };
+ 88950841109F301A004FB35D /* common.c in Sources */ = {isa = PBXBuildFile; fileRef = 8895083B109F301A004FB35D /* common.c */; };
+ 88950842109F301A004FB35D /* eloop.c in Sources */ = {isa = PBXBuildFile; fileRef = 8895083C109F301A004FB35D /* eloop.c */; };
+ 88950843109F301A004FB35D /* os_unix.c in Sources */ = {isa = PBXBuildFile; fileRef = 8895083D109F301A004FB35D /* os_unix.c */; };
+ 88950844109F301A004FB35D /* wpa_debug.c in Sources */ = {isa = PBXBuildFile; fileRef = 8895083E109F301A004FB35D /* wpa_debug.c */; };
+ 88950845109F301A004FB35D /* wpabuf.c in Sources */ = {isa = PBXBuildFile; fileRef = 8895083F109F301A004FB35D /* wpabuf.c */; };
+ 88950864109F32D1004FB35D /* peerkey.c in Sources */ = {isa = PBXBuildFile; fileRef = 8895085F109F32D1004FB35D /* peerkey.c */; };
+ 88950865109F32D1004FB35D /* pmksa_cache.c in Sources */ = {isa = PBXBuildFile; fileRef = 88950860109F32D1004FB35D /* pmksa_cache.c */; };
+ 88950866109F32D1004FB35D /* preauth.c in Sources */ = {isa = PBXBuildFile; fileRef = 88950861109F32D1004FB35D /* preauth.c */; };
+ 88950867109F32D1004FB35D /* wpa_ie.c in Sources */ = {isa = PBXBuildFile; fileRef = 88950862109F32D1004FB35D /* wpa_ie.c */; };
+ 88950868109F32D1004FB35D /* wpa.c in Sources */ = {isa = PBXBuildFile; fileRef = 88950863109F32D1004FB35D /* wpa.c */; };
+ 8895086C109F3316004FB35D /* l2_packet_freebsd.c in Sources */ = {isa = PBXBuildFile; fileRef = 8895086B109F3316004FB35D /* l2_packet_freebsd.c */; };
+ 88950871109F3367004FB35D /* aes-unwrap.c in Sources */ = {isa = PBXBuildFile; fileRef = 8895086D109F3367004FB35D /* aes-unwrap.c */; };
+ 88950872109F3367004FB35D /* crypto_openssl.c in Sources */ = {isa = PBXBuildFile; fileRef = 8895086E109F3367004FB35D /* crypto_openssl.c */; };
+ 88950873109F3367004FB35D /* sha1-pbkdf2.c in Sources */ = {isa = PBXBuildFile; fileRef = 8895086F109F3367004FB35D /* sha1-pbkdf2.c */; };
+ 88950874109F3367004FB35D /* sha1.c in Sources */ = {isa = PBXBuildFile; fileRef = 88950870109F3367004FB35D /* sha1.c */; };
+ 88950885109F3538004FB35D /* driver_osx.m in Sources */ = {isa = PBXBuildFile; fileRef = 88950883109F3538004FB35D /* driver_osx.m */; };
+ 88950886109F3538004FB35D /* drivers.c in Sources */ = {isa = PBXBuildFile; fileRef = 88950884109F3538004FB35D /* drivers.c */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXCopyFilesBuildPhase section */
+ 8DD76FAF0486AB0100D96B5E /* CopyFiles */ = {
+ isa = PBXCopyFilesBuildPhase;
+ buildActionMask = 8;
+ dstPath = /usr/share/man/man1/;
+ dstSubfolderSpec = 0;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 1;
+ };
+/* End PBXCopyFilesBuildPhase section */
+
+/* Begin PBXFileReference section */
+ 881EED0E10DC14EF009E449F /* eap_register.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = eap_register.c; path = ../eap_register.c; sourceTree = SOURCE_ROOT; };
+ 8853CB16109F385C00358CEF /* libpcap.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libpcap.dylib; path = usr/lib/libpcap.dylib; sourceTree = SDKROOT; };
+ 8853CB1A109F389800358CEF /* libcrypto.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libcrypto.dylib; path = usr/lib/libcrypto.dylib; sourceTree = SDKROOT; };
+ 8853CB1E109F38BD00358CEF /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; };
+ 8853CB2D109F3A3900358CEF /* scan_helpers.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = scan_helpers.c; path = ../../src/drivers/scan_helpers.c; sourceTree = SOURCE_ROOT; };
+ 8853CB31109F3A9400358CEF /* wpa_common.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = wpa_common.c; path = ../../src/common/wpa_common.c; sourceTree = SOURCE_ROOT; };
+ 8853CB35109F3AC700358CEF /* md5.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = md5.c; path = ../../src/crypto/md5.c; sourceTree = SOURCE_ROOT; };
+ 8853CB3B109F3B5800358CEF /* Apple80211.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Apple80211.framework; path = /System/Library/PrivateFrameworks/Apple80211.framework; sourceTree = "<absolute>"; };
+ 8853CBEC109F4C6E00358CEF /* eap_gtc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = eap_gtc.c; path = ../../src/eap_peer/eap_gtc.c; sourceTree = SOURCE_ROOT; };
+ 8853CBED109F4C6E00358CEF /* eap_leap.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = eap_leap.c; path = ../../src/eap_peer/eap_leap.c; sourceTree = SOURCE_ROOT; };
+ 8853CBEE109F4C6E00358CEF /* eap_md5.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = eap_md5.c; path = ../../src/eap_peer/eap_md5.c; sourceTree = SOURCE_ROOT; };
+ 8853CBEF109F4C6E00358CEF /* eap_methods.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = eap_methods.c; path = ../../src/eap_peer/eap_methods.c; sourceTree = SOURCE_ROOT; };
+ 8853CBF0109F4C6E00358CEF /* eap_mschapv2.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = eap_mschapv2.c; path = ../../src/eap_peer/eap_mschapv2.c; sourceTree = SOURCE_ROOT; };
+ 8853CBF1109F4C6E00358CEF /* eap_otp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = eap_otp.c; path = ../../src/eap_peer/eap_otp.c; sourceTree = SOURCE_ROOT; };
+ 8853CBF2109F4C6E00358CEF /* eap_peap.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = eap_peap.c; path = ../../src/eap_peer/eap_peap.c; sourceTree = SOURCE_ROOT; };
+ 8853CBF3109F4C6E00358CEF /* eap_tls_common.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = eap_tls_common.c; path = ../../src/eap_peer/eap_tls_common.c; sourceTree = SOURCE_ROOT; };
+ 8853CBF4109F4C6E00358CEF /* eap_tls.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = eap_tls.c; path = ../../src/eap_peer/eap_tls.c; sourceTree = SOURCE_ROOT; };
+ 8853CBF5109F4C6E00358CEF /* eap_tnc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = eap_tnc.c; path = ../../src/eap_peer/eap_tnc.c; sourceTree = SOURCE_ROOT; };
+ 8853CBF6109F4C6E00358CEF /* eap_ttls.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = eap_ttls.c; path = ../../src/eap_peer/eap_ttls.c; sourceTree = SOURCE_ROOT; };
+ 8853CBF7109F4C6E00358CEF /* eap_wsc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = eap_wsc.c; path = ../../src/eap_peer/eap_wsc.c; sourceTree = SOURCE_ROOT; };
+ 8853CBF8109F4C6E00358CEF /* eap.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = eap.c; path = ../../src/eap_peer/eap.c; sourceTree = SOURCE_ROOT; };
+ 8853CBF9109F4C6E00358CEF /* mschapv2.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = mschapv2.c; path = ../../src/eap_peer/mschapv2.c; sourceTree = SOURCE_ROOT; };
+ 8853CBFA109F4C6E00358CEF /* tncc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = tncc.c; path = ../../src/eap_peer/tncc.c; sourceTree = SOURCE_ROOT; };
+ 8853CC0C109F4CA100358CEF /* ctrl_iface_unix.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = ctrl_iface_unix.c; path = ../ctrl_iface_unix.c; sourceTree = SOURCE_ROOT; };
+ 8853CC0D109F4CA100358CEF /* ctrl_iface.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = ctrl_iface.c; path = ../ctrl_iface.c; sourceTree = SOURCE_ROOT; };
+ 8853CC10109F4CC800358CEF /* eapol_supp_sm.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = eapol_supp_sm.c; path = ../../src/eapol_supp/eapol_supp_sm.c; sourceTree = SOURCE_ROOT; };
+ 8853CC14109F4D0800358CEF /* chap.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = chap.c; path = ../../src/eap_common/chap.c; sourceTree = SOURCE_ROOT; };
+ 8853CC15109F4D0800358CEF /* eap_common.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = eap_common.c; path = ../../src/eap_common/eap_common.c; sourceTree = SOURCE_ROOT; };
+ 8853CC16109F4D0800358CEF /* eap_peap_common.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = eap_peap_common.c; path = ../../src/eap_common/eap_peap_common.c; sourceTree = SOURCE_ROOT; };
+ 8853CC17109F4D0800358CEF /* eap_wsc_common.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = eap_wsc_common.c; path = ../../src/eap_common/eap_wsc_common.c; sourceTree = SOURCE_ROOT; };
+ 8853CC1E109F4D3500358CEF /* wps_attr_build.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = wps_attr_build.c; path = ../../src/wps/wps_attr_build.c; sourceTree = SOURCE_ROOT; };
+ 8853CC1F109F4D3500358CEF /* wps_attr_parse.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = wps_attr_parse.c; path = ../../src/wps/wps_attr_parse.c; sourceTree = SOURCE_ROOT; };
+ 8853CC20109F4D3500358CEF /* wps_attr_process.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = wps_attr_process.c; path = ../../src/wps/wps_attr_process.c; sourceTree = SOURCE_ROOT; };
+ 8853CC21109F4D3500358CEF /* wps_common.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = wps_common.c; path = ../../src/wps/wps_common.c; sourceTree = SOURCE_ROOT; };
+ 8853CC22109F4D3500358CEF /* wps_dev_attr.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = wps_dev_attr.c; path = ../../src/wps/wps_dev_attr.c; sourceTree = SOURCE_ROOT; };
+ 8853CC23109F4D3500358CEF /* wps_enrollee.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = wps_enrollee.c; path = ../../src/wps/wps_enrollee.c; sourceTree = SOURCE_ROOT; };
+ 8853CC24109F4D3500358CEF /* wps_registrar.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = wps_registrar.c; path = ../../src/wps/wps_registrar.c; sourceTree = SOURCE_ROOT; };
+ 8853CC25109F4D3500358CEF /* wps.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = wps.c; path = ../../src/wps/wps.c; sourceTree = SOURCE_ROOT; };
+ 8853CC32109F4DE200358CEF /* ms_funcs.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = ms_funcs.c; path = ../../src/crypto/ms_funcs.c; sourceTree = SOURCE_ROOT; };
+ 8853CC33109F4DE200358CEF /* tls_openssl.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = tls_openssl.c; path = ../../src/crypto/tls_openssl.c; sourceTree = SOURCE_ROOT; };
+ 8853CC3B109F4E1D00358CEF /* libssl.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libssl.dylib; path = usr/lib/libssl.dylib; sourceTree = SDKROOT; };
+ 8853CC3F109F4E3A00358CEF /* wps_supplicant.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = wps_supplicant.c; path = ../wps_supplicant.c; sourceTree = SOURCE_ROOT; };
+ 8853CC43109F4E6200358CEF /* uuid.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = uuid.c; path = ../../src/utils/uuid.c; sourceTree = SOURCE_ROOT; };
+ 8853CC47109F4E8700358CEF /* ieee802_11_common.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = ieee802_11_common.c; path = ../../src/common/ieee802_11_common.c; sourceTree = SOURCE_ROOT; };
+ 8853CC4C109F4ED500358CEF /* sha256.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = sha256.c; path = ../../src/crypto/sha256.c; sourceTree = SOURCE_ROOT; };
+ 8853CC51109F4F3500358CEF /* aes-cbc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = "aes-cbc.c"; path = "../../src/crypto/aes-cbc.c"; sourceTree = SOURCE_ROOT; };
+ 8853CC52109F4F3500358CEF /* sha1-tlsprf.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = "sha1-tlsprf.c"; path = "../../src/crypto/sha1-tlsprf.c"; sourceTree = SOURCE_ROOT; };
+ 88950828109F2FAB004FB35D /* blacklist.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = blacklist.c; path = ../../wpa_supplicant/blacklist.c; sourceTree = SOURCE_ROOT; };
+ 88950829109F2FAB004FB35D /* config_file.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = config_file.c; path = ../../wpa_supplicant/config_file.c; sourceTree = SOURCE_ROOT; };
+ 8895082A109F2FAB004FB35D /* config.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = config.c; path = ../../wpa_supplicant/config.c; sourceTree = SOURCE_ROOT; };
+ 8895082B109F2FAB004FB35D /* events.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = events.c; path = ../../wpa_supplicant/events.c; sourceTree = SOURCE_ROOT; };
+ 8895082C109F2FAB004FB35D /* main.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = main.c; path = ../../wpa_supplicant/main.c; sourceTree = SOURCE_ROOT; };
+ 8895082D109F2FAB004FB35D /* notify.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = notify.c; path = ../../wpa_supplicant/notify.c; sourceTree = SOURCE_ROOT; };
+ 8895082E109F2FAB004FB35D /* scan.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = scan.c; path = ../../wpa_supplicant/scan.c; sourceTree = SOURCE_ROOT; };
+ 8895082F109F2FAB004FB35D /* wpa_supplicant.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = wpa_supplicant.c; path = ../../wpa_supplicant/wpa_supplicant.c; sourceTree = SOURCE_ROOT; };
+ 88950830109F2FAB004FB35D /* wpas_glue.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = wpas_glue.c; path = ../../wpa_supplicant/wpas_glue.c; sourceTree = SOURCE_ROOT; };
+ 8895083A109F301A004FB35D /* base64.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = base64.c; path = ../../src/utils/base64.c; sourceTree = SOURCE_ROOT; };
+ 8895083B109F301A004FB35D /* common.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = common.c; path = ../../src/utils/common.c; sourceTree = SOURCE_ROOT; };
+ 8895083C109F301A004FB35D /* eloop.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = eloop.c; path = ../../src/utils/eloop.c; sourceTree = SOURCE_ROOT; };
+ 8895083D109F301A004FB35D /* os_unix.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = os_unix.c; path = ../../src/utils/os_unix.c; sourceTree = SOURCE_ROOT; };
+ 8895083E109F301A004FB35D /* wpa_debug.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = wpa_debug.c; path = ../../src/utils/wpa_debug.c; sourceTree = SOURCE_ROOT; };
+ 8895083F109F301A004FB35D /* wpabuf.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = wpabuf.c; path = ../../src/utils/wpabuf.c; sourceTree = SOURCE_ROOT; };
+ 8895085F109F32D1004FB35D /* peerkey.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = peerkey.c; path = ../../src/rsn_supp/peerkey.c; sourceTree = SOURCE_ROOT; };
+ 88950860109F32D1004FB35D /* pmksa_cache.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pmksa_cache.c; path = ../../src/rsn_supp/pmksa_cache.c; sourceTree = SOURCE_ROOT; };
+ 88950861109F32D1004FB35D /* preauth.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = preauth.c; path = ../../src/rsn_supp/preauth.c; sourceTree = SOURCE_ROOT; };
+ 88950862109F32D1004FB35D /* wpa_ie.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = wpa_ie.c; path = ../../src/rsn_supp/wpa_ie.c; sourceTree = SOURCE_ROOT; };
+ 88950863109F32D1004FB35D /* wpa.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = wpa.c; path = ../../src/rsn_supp/wpa.c; sourceTree = SOURCE_ROOT; };
+ 8895086B109F3316004FB35D /* l2_packet_freebsd.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = l2_packet_freebsd.c; path = ../../src/l2_packet/l2_packet_freebsd.c; sourceTree = SOURCE_ROOT; };
+ 8895086D109F3367004FB35D /* aes-unwrap.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = "aes-unwrap.c"; path = "../../src/crypto/aes-unwrap.c"; sourceTree = SOURCE_ROOT; };
+ 8895086E109F3367004FB35D /* crypto_openssl.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = crypto_openssl.c; path = ../../src/crypto/crypto_openssl.c; sourceTree = SOURCE_ROOT; };
+ 8895086F109F3367004FB35D /* sha1-pbkdf2.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = "sha1-pbkdf2.c"; path = "../../src/crypto/sha1-pbkdf2.c"; sourceTree = SOURCE_ROOT; };
+ 88950870109F3367004FB35D /* sha1.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = sha1.c; path = ../../src/crypto/sha1.c; sourceTree = SOURCE_ROOT; };
+ 88950883109F3538004FB35D /* driver_osx.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = driver_osx.m; path = ../../src/drivers/driver_osx.m; sourceTree = SOURCE_ROOT; };
+ 88950884109F3538004FB35D /* drivers.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = drivers.c; path = ../../src/drivers/drivers.c; sourceTree = SOURCE_ROOT; };
+ 8DD76FB20486AB0100D96B5E /* wpa_supplicant */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = wpa_supplicant; sourceTree = BUILT_PRODUCTS_DIR; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+ 8DD76FAD0486AB0100D96B5E /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 8853CB17109F385C00358CEF /* libpcap.dylib in Frameworks */,
+ 8853CB1B109F389800358CEF /* libcrypto.dylib in Frameworks */,
+ 8853CB1F109F38BD00358CEF /* CoreFoundation.framework in Frameworks */,
+ 8853CB3C109F3B5800358CEF /* Apple80211.framework in Frameworks */,
+ 8853CC3C109F4E1D00358CEF /* libssl.dylib in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+ 08FB7794FE84155DC02AAC07 /* wpa_supplicant */ = {
+ isa = PBXGroup;
+ children = (
+ 08FB7795FE84155DC02AAC07 /* Source */,
+ C6A0FF2B0290797F04C91782 /* Documentation */,
+ 1AB674ADFE9D54B511CA2CBB /* Products */,
+ 8853CB16109F385C00358CEF /* libpcap.dylib */,
+ 8853CB1A109F389800358CEF /* libcrypto.dylib */,
+ 8853CB1E109F38BD00358CEF /* CoreFoundation.framework */,
+ 8853CB3B109F3B5800358CEF /* Apple80211.framework */,
+ 8853CC3B109F4E1D00358CEF /* libssl.dylib */,
+ );
+ name = wpa_supplicant;
+ sourceTree = "<group>";
+ };
+ 08FB7795FE84155DC02AAC07 /* Source */ = {
+ isa = PBXGroup;
+ children = (
+ 881EED0E10DC14EF009E449F /* eap_register.c */,
+ 8853CC51109F4F3500358CEF /* aes-cbc.c */,
+ 8853CC52109F4F3500358CEF /* sha1-tlsprf.c */,
+ 8853CC4C109F4ED500358CEF /* sha256.c */,
+ 8853CC47109F4E8700358CEF /* ieee802_11_common.c */,
+ 8853CC43109F4E6200358CEF /* uuid.c */,
+ 8853CC3F109F4E3A00358CEF /* wps_supplicant.c */,
+ 8853CC32109F4DE200358CEF /* ms_funcs.c */,
+ 8853CC33109F4DE200358CEF /* tls_openssl.c */,
+ 8853CC1E109F4D3500358CEF /* wps_attr_build.c */,
+ 8853CC1F109F4D3500358CEF /* wps_attr_parse.c */,
+ 8853CC20109F4D3500358CEF /* wps_attr_process.c */,
+ 8853CC21109F4D3500358CEF /* wps_common.c */,
+ 8853CC22109F4D3500358CEF /* wps_dev_attr.c */,
+ 8853CC23109F4D3500358CEF /* wps_enrollee.c */,
+ 8853CC24109F4D3500358CEF /* wps_registrar.c */,
+ 8853CC25109F4D3500358CEF /* wps.c */,
+ 8853CC14109F4D0800358CEF /* chap.c */,
+ 8853CC15109F4D0800358CEF /* eap_common.c */,
+ 8853CC16109F4D0800358CEF /* eap_peap_common.c */,
+ 8853CC17109F4D0800358CEF /* eap_wsc_common.c */,
+ 8853CC10109F4CC800358CEF /* eapol_supp_sm.c */,
+ 8853CC0C109F4CA100358CEF /* ctrl_iface_unix.c */,
+ 8853CC0D109F4CA100358CEF /* ctrl_iface.c */,
+ 8853CBEC109F4C6E00358CEF /* eap_gtc.c */,
+ 8853CBED109F4C6E00358CEF /* eap_leap.c */,
+ 8853CBEE109F4C6E00358CEF /* eap_md5.c */,
+ 8853CBEF109F4C6E00358CEF /* eap_methods.c */,
+ 8853CBF0109F4C6E00358CEF /* eap_mschapv2.c */,
+ 8853CBF1109F4C6E00358CEF /* eap_otp.c */,
+ 8853CBF2109F4C6E00358CEF /* eap_peap.c */,
+ 8853CBF3109F4C6E00358CEF /* eap_tls_common.c */,
+ 8853CBF4109F4C6E00358CEF /* eap_tls.c */,
+ 8853CBF5109F4C6E00358CEF /* eap_tnc.c */,
+ 8853CBF6109F4C6E00358CEF /* eap_ttls.c */,
+ 8853CBF7109F4C6E00358CEF /* eap_wsc.c */,
+ 8853CBF8109F4C6E00358CEF /* eap.c */,
+ 8853CBF9109F4C6E00358CEF /* mschapv2.c */,
+ 8853CBFA109F4C6E00358CEF /* tncc.c */,
+ 8853CB35109F3AC700358CEF /* md5.c */,
+ 8853CB31109F3A9400358CEF /* wpa_common.c */,
+ 8853CB2D109F3A3900358CEF /* scan_helpers.c */,
+ 88950883109F3538004FB35D /* driver_osx.m */,
+ 88950884109F3538004FB35D /* drivers.c */,
+ 8895086D109F3367004FB35D /* aes-unwrap.c */,
+ 8895086E109F3367004FB35D /* crypto_openssl.c */,
+ 8895086F109F3367004FB35D /* sha1-pbkdf2.c */,
+ 88950870109F3367004FB35D /* sha1.c */,
+ 8895086B109F3316004FB35D /* l2_packet_freebsd.c */,
+ 8895085F109F32D1004FB35D /* peerkey.c */,
+ 88950860109F32D1004FB35D /* pmksa_cache.c */,
+ 88950861109F32D1004FB35D /* preauth.c */,
+ 88950862109F32D1004FB35D /* wpa_ie.c */,
+ 88950863109F32D1004FB35D /* wpa.c */,
+ 8895083A109F301A004FB35D /* base64.c */,
+ 8895083B109F301A004FB35D /* common.c */,
+ 8895083C109F301A004FB35D /* eloop.c */,
+ 8895083D109F301A004FB35D /* os_unix.c */,
+ 8895083E109F301A004FB35D /* wpa_debug.c */,
+ 8895083F109F301A004FB35D /* wpabuf.c */,
+ 88950828109F2FAB004FB35D /* blacklist.c */,
+ 88950829109F2FAB004FB35D /* config_file.c */,
+ 8895082A109F2FAB004FB35D /* config.c */,
+ 8895082B109F2FAB004FB35D /* events.c */,
+ 8895082C109F2FAB004FB35D /* main.c */,
+ 8895082D109F2FAB004FB35D /* notify.c */,
+ 8895082E109F2FAB004FB35D /* scan.c */,
+ 8895082F109F2FAB004FB35D /* wpa_supplicant.c */,
+ 88950830109F2FAB004FB35D /* wpas_glue.c */,
+ );
+ name = Source;
+ sourceTree = "<group>";
+ };
+ 1AB674ADFE9D54B511CA2CBB /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ 8DD76FB20486AB0100D96B5E /* wpa_supplicant */,
+ );
+ name = Products;
+ sourceTree = "<group>";
+ };
+ C6A0FF2B0290797F04C91782 /* Documentation */ = {
+ isa = PBXGroup;
+ children = (
+ );
+ name = Documentation;
+ sourceTree = "<group>";
+ };
+/* End PBXGroup section */
+
+/* Begin PBXNativeTarget section */
+ 8DD76FA90486AB0100D96B5E /* wpa_supplicant */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 1DEB928508733DD80010E9CD /* Build configuration list for PBXNativeTarget "wpa_supplicant" */;
+ buildPhases = (
+ 8DD76FAB0486AB0100D96B5E /* Sources */,
+ 8DD76FAD0486AB0100D96B5E /* Frameworks */,
+ 8DD76FAF0486AB0100D96B5E /* CopyFiles */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = wpa_supplicant;
+ productInstallPath = "$(HOME)/bin";
+ productName = wpa_supplicant;
+ productReference = 8DD76FB20486AB0100D96B5E /* wpa_supplicant */;
+ productType = "com.apple.product-type.tool";
+ };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+ 08FB7793FE84155DC02AAC07 /* Project object */ = {
+ isa = PBXProject;
+ buildConfigurationList = 1DEB928908733DD80010E9CD /* Build configuration list for PBXProject "wpa_supplicant" */;
+ compatibilityVersion = "Xcode 3.1";
+ hasScannedForEncodings = 1;
+ mainGroup = 08FB7794FE84155DC02AAC07 /* wpa_supplicant */;
+ projectDirPath = "";
+ projectRoot = "";
+ targets = (
+ 8DD76FA90486AB0100D96B5E /* wpa_supplicant */,
+ );
+ };
+/* End PBXProject section */
+
+/* Begin PBXSourcesBuildPhase section */
+ 8DD76FAB0486AB0100D96B5E /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 88950831109F2FAB004FB35D /* blacklist.c in Sources */,
+ 88950832109F2FAB004FB35D /* config_file.c in Sources */,
+ 88950833109F2FAB004FB35D /* config.c in Sources */,
+ 88950834109F2FAB004FB35D /* events.c in Sources */,
+ 88950835109F2FAB004FB35D /* main.c in Sources */,
+ 88950836109F2FAB004FB35D /* notify.c in Sources */,
+ 88950837109F2FAB004FB35D /* scan.c in Sources */,
+ 88950838109F2FAB004FB35D /* wpa_supplicant.c in Sources */,
+ 88950839109F2FAB004FB35D /* wpas_glue.c in Sources */,
+ 88950840109F301A004FB35D /* base64.c in Sources */,
+ 88950841109F301A004FB35D /* common.c in Sources */,
+ 88950842109F301A004FB35D /* eloop.c in Sources */,
+ 88950843109F301A004FB35D /* os_unix.c in Sources */,
+ 88950844109F301A004FB35D /* wpa_debug.c in Sources */,
+ 88950845109F301A004FB35D /* wpabuf.c in Sources */,
+ 88950864109F32D1004FB35D /* peerkey.c in Sources */,
+ 88950865109F32D1004FB35D /* pmksa_cache.c in Sources */,
+ 88950866109F32D1004FB35D /* preauth.c in Sources */,
+ 88950867109F32D1004FB35D /* wpa_ie.c in Sources */,
+ 88950868109F32D1004FB35D /* wpa.c in Sources */,
+ 8895086C109F3316004FB35D /* l2_packet_freebsd.c in Sources */,
+ 88950871109F3367004FB35D /* aes-unwrap.c in Sources */,
+ 88950872109F3367004FB35D /* crypto_openssl.c in Sources */,
+ 88950873109F3367004FB35D /* sha1-pbkdf2.c in Sources */,
+ 88950874109F3367004FB35D /* sha1.c in Sources */,
+ 88950885109F3538004FB35D /* driver_osx.m in Sources */,
+ 88950886109F3538004FB35D /* drivers.c in Sources */,
+ 8853CB2E109F3A3900358CEF /* scan_helpers.c in Sources */,
+ 8853CB32109F3A9400358CEF /* wpa_common.c in Sources */,
+ 8853CB36109F3AC700358CEF /* md5.c in Sources */,
+ 8853CBFB109F4C6E00358CEF /* eap_gtc.c in Sources */,
+ 8853CBFC109F4C6E00358CEF /* eap_leap.c in Sources */,
+ 8853CBFD109F4C6E00358CEF /* eap_md5.c in Sources */,
+ 8853CBFE109F4C6E00358CEF /* eap_methods.c in Sources */,
+ 8853CBFF109F4C6E00358CEF /* eap_mschapv2.c in Sources */,
+ 8853CC00109F4C6E00358CEF /* eap_otp.c in Sources */,
+ 8853CC01109F4C6E00358CEF /* eap_peap.c in Sources */,
+ 8853CC02109F4C6E00358CEF /* eap_tls_common.c in Sources */,
+ 8853CC03109F4C6E00358CEF /* eap_tls.c in Sources */,
+ 8853CC04109F4C6E00358CEF /* eap_tnc.c in Sources */,
+ 8853CC05109F4C6E00358CEF /* eap_ttls.c in Sources */,
+ 8853CC06109F4C6E00358CEF /* eap_wsc.c in Sources */,
+ 8853CC07109F4C6E00358CEF /* eap.c in Sources */,
+ 8853CC08109F4C6E00358CEF /* mschapv2.c in Sources */,
+ 8853CC09109F4C6E00358CEF /* tncc.c in Sources */,
+ 8853CC0E109F4CA100358CEF /* ctrl_iface_unix.c in Sources */,
+ 8853CC0F109F4CA100358CEF /* ctrl_iface.c in Sources */,
+ 8853CC11109F4CC800358CEF /* eapol_supp_sm.c in Sources */,
+ 8853CC18109F4D0800358CEF /* chap.c in Sources */,
+ 8853CC19109F4D0800358CEF /* eap_common.c in Sources */,
+ 8853CC1A109F4D0800358CEF /* eap_peap_common.c in Sources */,
+ 8853CC1B109F4D0800358CEF /* eap_wsc_common.c in Sources */,
+ 8853CC26109F4D3500358CEF /* wps_attr_build.c in Sources */,
+ 8853CC27109F4D3500358CEF /* wps_attr_parse.c in Sources */,
+ 8853CC28109F4D3500358CEF /* wps_attr_process.c in Sources */,
+ 8853CC29109F4D3500358CEF /* wps_common.c in Sources */,
+ 8853CC2A109F4D3500358CEF /* wps_dev_attr.c in Sources */,
+ 8853CC2B109F4D3500358CEF /* wps_enrollee.c in Sources */,
+ 8853CC2C109F4D3500358CEF /* wps_registrar.c in Sources */,
+ 8853CC2D109F4D3500358CEF /* wps.c in Sources */,
+ 8853CC34109F4DE200358CEF /* ms_funcs.c in Sources */,
+ 8853CC35109F4DE200358CEF /* tls_openssl.c in Sources */,
+ 8853CC40109F4E3A00358CEF /* wps_supplicant.c in Sources */,
+ 8853CC44109F4E6200358CEF /* uuid.c in Sources */,
+ 8853CC48109F4E8700358CEF /* ieee802_11_common.c in Sources */,
+ 8853CC4E109F4ED500358CEF /* sha256.c in Sources */,
+ 8853CC53109F4F3500358CEF /* aes-cbc.c in Sources */,
+ 8853CC54109F4F3500358CEF /* sha1-tlsprf.c in Sources */,
+ 881EED0F10DC14EF009E449F /* eap_register.c in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin XCBuildConfiguration section */
+ 1DEB928608733DD80010E9CD /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ COPY_PHASE_STRIP = NO;
+ FRAMEWORK_SEARCH_PATHS = (
+ "$(inherited)",
+ "\"$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks\"",
+ );
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_ENABLE_FIX_AND_CONTINUE = YES;
+ GCC_MODEL_TUNING = G5;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ INSTALL_PATH = /usr/local/bin;
+ PRODUCT_NAME = wpa_supplicant;
+ };
+ name = Debug;
+ };
+ 1DEB928708733DD80010E9CD /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+ FRAMEWORK_SEARCH_PATHS = (
+ "$(inherited)",
+ "\"$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks\"",
+ );
+ GCC_MODEL_TUNING = G5;
+ INSTALL_PATH = /usr/local/bin;
+ PRODUCT_NAME = wpa_supplicant;
+ };
+ name = Release;
+ };
+ 1DEB928A08733DD80010E9CD /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
+ FRAMEWORK_SEARCH_PATHS = /System/Library/PrivateFrameworks;
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ HEADER_SEARCH_PATHS = (
+ ../../src,
+ ../../src/utils,
+ );
+ ONLY_ACTIVE_ARCH = YES;
+ OTHER_CFLAGS = "-DCONFIG_XCODE_DEFAULTS";
+ PREBINDING = NO;
+ PRELINK_LIBS = "";
+ RUN_CLANG_STATIC_ANALYZER = YES;
+ SDKROOT = macosx10.6;
+ };
+ name = Debug;
+ };
+ 1DEB928B08733DD80010E9CD /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
+ FRAMEWORK_SEARCH_PATHS = /System/Library/PrivateFrameworks;
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ HEADER_SEARCH_PATHS = (
+ ../../src,
+ ../../src/utils,
+ );
+ OTHER_CFLAGS = "-DCONFIG_XCODE_DEFAULTS";
+ PREBINDING = NO;
+ SDKROOT = macosx10.6;
+ };
+ name = Release;
+ };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+ 1DEB928508733DD80010E9CD /* Build configuration list for PBXNativeTarget "wpa_supplicant" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 1DEB928608733DD80010E9CD /* Debug */,
+ 1DEB928708733DD80010E9CD /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ 1DEB928908733DD80010E9CD /* Build configuration list for PBXProject "wpa_supplicant" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 1DEB928A08733DD80010E9CD /* Debug */,
+ 1DEB928B08733DD80010E9CD /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+/* End XCConfigurationList section */
+ };
+ rootObject = 08FB7793FE84155DC02AAC07 /* Project object */;
+}
OpenPOWER on IntegriCloud