hostap: Implement AP mode events
These events are used by AP mode, tied to AP-ENABLED and AP-DISABLED events in the hostapd/wpa_supplicant. Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no> Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
This commit is contained in:
parent
ce85b6ce0a
commit
3bf20deec0
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/net/wifi_mgmt.h>
|
||||
|
||||
#include "includes.h"
|
||||
#include "common.h"
|
||||
|
@ -490,6 +491,8 @@ out:
|
|||
static int wpas_disconnect_network(const struct device *dev)
|
||||
{
|
||||
struct net_if *iface = net_if_lookup_by_dev(dev);
|
||||
struct wpa_supplicant *wpa_s;
|
||||
bool is_ap = false;
|
||||
int ret = 0;
|
||||
|
||||
if (!iface) {
|
||||
|
@ -498,8 +501,19 @@ static int wpas_disconnect_network(const struct device *dev)
|
|||
return ret;
|
||||
}
|
||||
|
||||
wpa_s = get_wpa_s_handle(dev);
|
||||
if (!wpa_s) {
|
||||
ret = -1;
|
||||
wpa_printf(MSG_ERROR, "Interface %s not found", dev->name);
|
||||
goto out;
|
||||
}
|
||||
|
||||
k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER);
|
||||
|
||||
if (wpa_s->current_ssid && wpa_s->current_ssid->mode == WPAS_MODE_AP) {
|
||||
is_ap = true;
|
||||
}
|
||||
|
||||
wpas_api_ctrl.dev = dev;
|
||||
wpas_api_ctrl.requested_op = DISCONNECT;
|
||||
|
||||
|
@ -518,8 +532,17 @@ out:
|
|||
wpa_supp_restart_status_work();
|
||||
|
||||
ret = wait_for_disconnect_complete(dev);
|
||||
|
||||
wifi_mgmt_raise_disconnect_complete_event(iface, ret);
|
||||
#ifdef CONFIG_AP
|
||||
if (is_ap) {
|
||||
supplicant_send_wifi_mgmt_ap_status(wpa_s,
|
||||
NET_EVENT_WIFI_CMD_AP_DISABLE_RESULT,
|
||||
ret == 0 ? WIFI_STATUS_AP_SUCCESS : WIFI_STATUS_AP_FAIL);
|
||||
} else {
|
||||
#else
|
||||
{
|
||||
#endif /* CONFIG_AP */
|
||||
wifi_mgmt_raise_disconnect_complete_event(iface, ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -192,9 +192,20 @@ int supplicant_send_wifi_mgmt_conn_event(void *ctx, int status_code)
|
|||
{
|
||||
struct wpa_supplicant *wpa_s = ctx;
|
||||
int status = wpas_to_wifi_mgmt_conn_status(status_code);
|
||||
enum net_event_wifi_cmd event;
|
||||
|
||||
if (!wpa_s || !wpa_s->current_ssid) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (wpa_s->current_ssid->mode == WPAS_MODE_AP) {
|
||||
event = NET_EVENT_WIFI_CMD_AP_ENABLE_RESULT;
|
||||
} else {
|
||||
event = NET_EVENT_WIFI_CMD_CONNECT_RESULT;
|
||||
}
|
||||
|
||||
return supplicant_send_wifi_mgmt_event(wpa_s->ifname,
|
||||
NET_EVENT_WIFI_CMD_CONNECT_RESULT,
|
||||
event,
|
||||
(void *)&status,
|
||||
sizeof(int));
|
||||
}
|
||||
|
@ -205,10 +216,22 @@ int supplicant_send_wifi_mgmt_disc_event(void *ctx, int reason_code)
|
|||
int status = wpas_to_wifi_mgmt_diconn_status(reason_code);
|
||||
enum net_event_wifi_cmd event;
|
||||
|
||||
if (!wpa_s || !wpa_s->current_ssid) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (wpa_s->wpa_state >= WPA_COMPLETED) {
|
||||
event = NET_EVENT_WIFI_CMD_DISCONNECT_RESULT;
|
||||
if (wpa_s->current_ssid->mode == WPAS_MODE_AP) {
|
||||
event = NET_EVENT_WIFI_CMD_AP_DISABLE_RESULT;
|
||||
} else {
|
||||
event = NET_EVENT_WIFI_CMD_DISCONNECT_RESULT;
|
||||
}
|
||||
} else {
|
||||
event = NET_EVENT_WIFI_CMD_CONNECT_RESULT;
|
||||
if (wpa_s->current_ssid->mode == WPAS_MODE_AP) {
|
||||
event = NET_EVENT_WIFI_CMD_AP_ENABLE_RESULT;
|
||||
} else {
|
||||
event = NET_EVENT_WIFI_CMD_CONNECT_RESULT;
|
||||
}
|
||||
}
|
||||
|
||||
return supplicant_send_wifi_mgmt_event(wpa_s->ifname,
|
||||
|
@ -217,6 +240,21 @@ int supplicant_send_wifi_mgmt_disc_event(void *ctx, int reason_code)
|
|||
sizeof(int));
|
||||
}
|
||||
|
||||
#ifdef CONFIG_AP
|
||||
int supplicant_send_wifi_mgmt_ap_status(void *ctx,
|
||||
enum net_event_wifi_cmd event,
|
||||
enum wifi_ap_status ap_status)
|
||||
{
|
||||
struct wpa_supplicant *wpa_s = ctx;
|
||||
int status = ap_status;
|
||||
|
||||
return supplicant_send_wifi_mgmt_event(wpa_s->ifname,
|
||||
event,
|
||||
(void *)&status,
|
||||
sizeof(int));
|
||||
}
|
||||
#endif /* CONFIG_AP */
|
||||
|
||||
int supplicant_send_wifi_mgmt_event(const char *ifname, enum net_event_wifi_cmd event,
|
||||
void *supplicant_status, size_t len)
|
||||
{
|
||||
|
@ -240,6 +278,16 @@ int supplicant_send_wifi_mgmt_event(const char *ifname, enum net_event_wifi_cmd
|
|||
iface,
|
||||
*(int *)supplicant_status);
|
||||
break;
|
||||
#ifdef CONFIG_AP
|
||||
case NET_EVENT_WIFI_CMD_AP_ENABLE_RESULT:
|
||||
wifi_mgmt_raise_ap_enable_result_event(iface,
|
||||
*(int *)supplicant_status);
|
||||
break;
|
||||
case NET_EVENT_WIFI_CMD_AP_DISABLE_RESULT:
|
||||
wifi_mgmt_raise_ap_disable_result_event(iface,
|
||||
*(int *)supplicant_status);
|
||||
break;
|
||||
#endif /* CONFIG_AP */
|
||||
case NET_EVENT_SUPPLICANT_CMD_INT_EVENT:
|
||||
event_data.data = &data;
|
||||
if (supplicant_process_status(&event_data, (char *)supplicant_status) > 0) {
|
||||
|
|
|
@ -55,6 +55,12 @@ int supplicant_generate_state_event(const char *ifname,
|
|||
int supplicant_send_wifi_mgmt_conn_event(void *ctx, int status_code);
|
||||
int supplicant_send_wifi_mgmt_disc_event(void *ctx, int reason_code);
|
||||
|
||||
#ifdef CONFIG_AP
|
||||
int supplicant_send_wifi_mgmt_ap_status(void *ctx,
|
||||
enum net_event_wifi_cmd event,
|
||||
enum wifi_ap_status);
|
||||
#endif /* CONFIG_AP */
|
||||
|
||||
#define REASON_CODE_LEN 18
|
||||
#define NM_WIFI_EVENT_STR_LEN 64
|
||||
#define ETH_ALEN 6
|
||||
|
|
Loading…
Reference in a new issue