netdev: Always require handshake_state with netdev_connect
This commit is contained in:
parent
d93a44a3f0
commit
9c6643b773
|
@ -677,10 +677,12 @@ void device_connect_network(struct device *device, struct network *network,
|
||||||
enum security security = network_get_security(network);
|
enum security security = network_get_security(network);
|
||||||
struct wiphy *wiphy = device->wiphy;
|
struct wiphy *wiphy = device->wiphy;
|
||||||
struct l_dbus *dbus = dbus_get_bus();
|
struct l_dbus *dbus = dbus_get_bus();
|
||||||
struct handshake_state *hs = NULL;
|
struct handshake_state *hs;
|
||||||
bool add_mde = false;
|
bool add_mde = false;
|
||||||
uint8_t *mde;
|
uint8_t *mde;
|
||||||
|
|
||||||
|
hs = handshake_state_new(netdev_get_ifindex(device->netdev));
|
||||||
|
|
||||||
if (security == SECURITY_PSK || security == SECURITY_8021X) {
|
if (security == SECURITY_PSK || security == SECURITY_8021X) {
|
||||||
struct ie_rsn_info bss_info;
|
struct ie_rsn_info bss_info;
|
||||||
uint8_t rsne_buf[256];
|
uint8_t rsne_buf[256];
|
||||||
|
@ -718,8 +720,6 @@ void device_connect_network(struct device *device, struct network *network,
|
||||||
} else if (info.group_management_cipher != 0)
|
} else if (info.group_management_cipher != 0)
|
||||||
info.mfpc = true;
|
info.mfpc = true;
|
||||||
|
|
||||||
hs = handshake_state_new(netdev_get_ifindex(device->netdev));
|
|
||||||
|
|
||||||
ssid = network_get_ssid(network);
|
ssid = network_get_ssid(network);
|
||||||
handshake_state_set_ssid(hs, (void *) ssid, strlen(ssid));
|
handshake_state_set_ssid(hs, (void *) ssid, strlen(ssid));
|
||||||
|
|
||||||
|
@ -758,7 +758,6 @@ void device_connect_network(struct device *device, struct network *network,
|
||||||
mde[1] = 3;
|
mde[1] = 3;
|
||||||
memcpy(mde + 2, bss->mde, 3);
|
memcpy(mde + 2, bss->mde, 3);
|
||||||
|
|
||||||
if (hs)
|
|
||||||
handshake_state_set_mde(hs, mde);
|
handshake_state_set_mde(hs, mde);
|
||||||
} else
|
} else
|
||||||
mde = NULL;
|
mde = NULL;
|
||||||
|
@ -768,7 +767,6 @@ void device_connect_network(struct device *device, struct network *network,
|
||||||
if (netdev_connect(device->netdev, bss, hs, mde,
|
if (netdev_connect(device->netdev, bss, hs, mde,
|
||||||
device_netdev_event,
|
device_netdev_event,
|
||||||
device_connect_cb, device) < 0) {
|
device_connect_cb, device) < 0) {
|
||||||
if (hs)
|
|
||||||
handshake_state_free(hs);
|
handshake_state_free(hs);
|
||||||
|
|
||||||
l_free(mde);
|
l_free(mde);
|
||||||
|
|
16
src/netdev.c
16
src/netdev.c
|
@ -1067,6 +1067,7 @@ static void netdev_connect_event(struct l_genl_msg *msg,
|
||||||
const uint16_t *status_code = NULL;
|
const uint16_t *status_code = NULL;
|
||||||
const uint8_t *ies = NULL;
|
const uint8_t *ies = NULL;
|
||||||
size_t ies_len;
|
size_t ies_len;
|
||||||
|
bool is_rsn = netdev->handshake->own_ie != NULL;
|
||||||
|
|
||||||
l_debug("");
|
l_debug("");
|
||||||
|
|
||||||
|
@ -1139,10 +1140,10 @@ static void netdev_connect_event(struct l_genl_msg *msg,
|
||||||
* in a non-RSN (12.4.2 vs. 12.4.3).
|
* in a non-RSN (12.4.2 vs. 12.4.3).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (netdev->mde && !netdev->handshake && fte)
|
if (netdev->mde && !is_rsn && fte)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (netdev->mde && netdev->handshake) {
|
if (netdev->mde && is_rsn) {
|
||||||
struct ie_ft_info ft_info;
|
struct ie_ft_info ft_info;
|
||||||
uint8_t zeros[32];
|
uint8_t zeros[32];
|
||||||
|
|
||||||
|
@ -1275,6 +1276,7 @@ static struct l_genl_msg *netdev_build_cmd_connect(struct netdev *netdev,
|
||||||
struct l_genl_msg *msg;
|
struct l_genl_msg *msg;
|
||||||
struct iovec iov[2];
|
struct iovec iov[2];
|
||||||
int iov_elems = 0;
|
int iov_elems = 0;
|
||||||
|
bool is_rsn = hs->own_ie != NULL;
|
||||||
|
|
||||||
msg = l_genl_msg_new_sized(NL80211_CMD_CONNECT, 512);
|
msg = l_genl_msg_new_sized(NL80211_CMD_CONNECT, 512);
|
||||||
l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &netdev->index);
|
l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &netdev->index);
|
||||||
|
@ -1288,7 +1290,7 @@ static struct l_genl_msg *netdev_build_cmd_connect(struct netdev *netdev,
|
||||||
if (bss->capability & IE_BSS_CAP_PRIVACY)
|
if (bss->capability & IE_BSS_CAP_PRIVACY)
|
||||||
l_genl_msg_append_attr(msg, NL80211_ATTR_PRIVACY, 0, NULL);
|
l_genl_msg_append_attr(msg, NL80211_ATTR_PRIVACY, 0, NULL);
|
||||||
|
|
||||||
if (hs) {
|
if (is_rsn) {
|
||||||
uint32_t nl_cipher;
|
uint32_t nl_cipher;
|
||||||
uint32_t nl_akm;
|
uint32_t nl_akm;
|
||||||
uint32_t wpa_version;
|
uint32_t wpa_version;
|
||||||
|
@ -1330,12 +1332,10 @@ static struct l_genl_msg *netdev_build_cmd_connect(struct netdev *netdev,
|
||||||
|
|
||||||
l_genl_msg_append_attr(msg, NL80211_ATTR_CONTROL_PORT, 0, NULL);
|
l_genl_msg_append_attr(msg, NL80211_ATTR_CONTROL_PORT, 0, NULL);
|
||||||
|
|
||||||
if (hs->own_ie) {
|
|
||||||
iov[iov_elems].iov_base = (void *) hs->own_ie;
|
iov[iov_elems].iov_base = (void *) hs->own_ie;
|
||||||
iov[iov_elems].iov_len = hs->own_ie[1] + 2;
|
iov[iov_elems].iov_len = hs->own_ie[1] + 2;
|
||||||
iov_elems += 1;
|
iov_elems += 1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (mde) {
|
if (mde) {
|
||||||
iov[iov_elems].iov_base = (void *) mde;
|
iov[iov_elems].iov_base = (void *) mde;
|
||||||
|
@ -1377,10 +1377,8 @@ static int netdev_connect_common(struct netdev *netdev,
|
||||||
if (mde)
|
if (mde)
|
||||||
netdev->mde = l_memdup(mde, mde[1] + 2);
|
netdev->mde = l_memdup(mde, mde[1] + 2);
|
||||||
|
|
||||||
if (hs) {
|
|
||||||
handshake_state_set_authenticator_address(hs, bss->addr);
|
handshake_state_set_authenticator_address(hs, bss->addr);
|
||||||
handshake_state_set_supplicant_address(hs, netdev->addr);
|
handshake_state_set_supplicant_address(hs, netdev->addr);
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -1393,7 +1391,7 @@ int netdev_connect(struct netdev *netdev, struct scan_bss *bss,
|
||||||
{
|
{
|
||||||
struct l_genl_msg *cmd_connect;
|
struct l_genl_msg *cmd_connect;
|
||||||
struct eapol_sm *sm = NULL;
|
struct eapol_sm *sm = NULL;
|
||||||
bool is_rsn = hs != NULL;
|
bool is_rsn = hs->own_ie != NULL;
|
||||||
|
|
||||||
if (netdev->connected)
|
if (netdev->connected)
|
||||||
return -EISCONN;
|
return -EISCONN;
|
||||||
|
@ -1427,7 +1425,7 @@ int netdev_connect_wsc(struct netdev *netdev, struct scan_bss *bss,
|
||||||
if (netdev->connected)
|
if (netdev->connected)
|
||||||
return -EISCONN;
|
return -EISCONN;
|
||||||
|
|
||||||
cmd_connect = netdev_build_cmd_connect(netdev, bss, NULL, NULL);
|
cmd_connect = netdev_build_cmd_connect(netdev, bss, hs, NULL);
|
||||||
if (!cmd_connect)
|
if (!cmd_connect)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue