Skip to content

Commit

Permalink
modules: hostap: Add mode check for disconnect
Browse files Browse the repository at this point in the history
This way we reject disconnect in AP mode and ap disable in STA mode,
though both have same functionality we treat them differently to keep
it clean.

Signed-off-by: Chaitanya Tata <[email protected]>
  • Loading branch information
krish2718 authored and nordicjm committed Jan 8, 2024
1 parent 5025f81 commit 3b0161d
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions modules/hostap/src/supp_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ static int wpas_add_and_config_network(struct wpa_supplicant *wpa_s,
return ret;
}

static int wpas_disconnect_network(const struct device *dev)
static int wpas_disconnect_network(const struct device *dev, int cur_mode)
{
int ret = 0;
struct net_if *iface = net_if_lookup_by_dev(dev);
Expand All @@ -419,10 +419,15 @@ static int wpas_disconnect_network(const struct device *dev)

k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER);

if (wpa_s->current_ssid && wpa_s->current_ssid->mode == WPAS_MODE_AP) {
is_ap = true;
if (!wpa_s->current_ssid || wpa_s->current_ssid->mode != cur_mode) {
ret = -EBUSY;
wpa_printf(MSG_ERROR, "Interface %s is not in %s mode", dev->name,
cur_mode == WPAS_MODE_INFRA ? "STA" : "AP");
goto out;
}

is_ap = (cur_mode == WPAS_MODE_AP);

wpa_supp_api_ctrl.dev = dev;
wpa_supp_api_ctrl.requested_op = DISCONNECT;
_wpa_cli_cmd_v("disconnect");
Expand Down Expand Up @@ -506,7 +511,7 @@ int z_wpa_supplicant_connect(const struct device *dev,

int z_wpa_supplicant_disconnect(const struct device *dev)
{
return wpas_disconnect_network(dev);
return wpas_disconnect_network(dev, WPAS_MODE_INFRA);
}

int z_wpa_supplicant_status(const struct device *dev,
Expand Down Expand Up @@ -810,7 +815,7 @@ int z_wpa_supplicant_ap_disable(const struct device *dev)
goto out;
}

ret = wpas_disconnect_network(dev);
ret = wpas_disconnect_network(dev, WPAS_MODE_AP);
if (ret) {
wpa_printf(MSG_ERROR, "Failed to disconnect from network");
goto out;
Expand Down

0 comments on commit 3b0161d

Please sign in to comment.