Skip to content

Commit

Permalink
[nrf fromlist] wifi: ap: Add status events
Browse files Browse the repository at this point in the history
These events communicate the status of AP mode operations (enable or
disable) with few pre-defined enumerations.

Upstream PR: zephyrproject-rtos/zephyr#67015

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
(cherry picked from commit af9dc97)
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
  • Loading branch information
krish2718 authored and de-nordic committed Jan 9, 2024
1 parent c0ea30d commit 15fe6c5
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 4 deletions.
47 changes: 47 additions & 0 deletions include/zephyr/net/wifi_mgmt.h
Expand Up @@ -180,6 +180,10 @@ enum net_event_wifi_cmd {
NET_EVENT_WIFI_CMD_RAW_SCAN_RESULT,
/** Disconnect complete */
NET_EVENT_WIFI_CMD_DISCONNECT_COMPLETE,
/** AP mode enable result */
NET_EVENT_WIFI_CMD_AP_ENABLE_RESULT,
/** AP mode disable result */
NET_EVENT_WIFI_CMD_AP_DISABLE_RESULT,
};

#define NET_EVENT_WIFI_SCAN_RESULT \
Expand Down Expand Up @@ -209,6 +213,12 @@ enum net_event_wifi_cmd {
#define NET_EVENT_WIFI_DISCONNECT_COMPLETE \
(_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_DISCONNECT_COMPLETE)

#define NET_EVENT_WIFI_AP_ENABLE_RESULT \
(_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_AP_ENABLE_RESULT)

#define NET_EVENT_WIFI_AP_DISABLE_RESULT \
(_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_AP_DISABLE_RESULT)

/**
* @brief Wi-Fi structure to uniquely identify a band-channel pair
*/
Expand Down Expand Up @@ -351,12 +361,35 @@ enum wifi_disconn_reason {
WIFI_REASON_DISCONN_INACTIVITY,
};

/** Wi-Fi AP mode result codes. To be overlaid on top of \ref wifi_status
* in the AP mode enable or disable result event for detailed status.
*/
enum wifi_ap_status {
/** AP mode enable or disable successful */
WIFI_STATUS_AP_SUCCESS = 0,
/** AP mode enable or disable failed - generic failure */
WIFI_STATUS_AP_FAIL,
/** AP mode enable failed - channel not supported */
WIFI_STATUS_AP_CHANNEL_NOT_SUPPORTED,
/** AP mode enable failed - channel not allowed */
WIFI_STATUS_AP_CHANNEL_NOT_ALLOWED,
/** AP mode enable failed - SSID not allowed */
WIFI_STATUS_AP_SSID_NOT_ALLOWED,
/** AP mode enable failed - authentication type not supported */
WIFI_STATUS_AP_AUTH_TYPE_NOT_SUPPORTED,
/** AP mode enable failed - operation not supported */
WIFI_STATUS_AP_OP_NOT_SUPPORTED,
/** AP mode enable failed - operation not permitted */
WIFI_STATUS_AP_OP_NOT_PERMITTED,
};

/** Generic Wi-Fi status for commands and events */
struct wifi_status {
union {
int status;
enum wifi_conn_status conn_status;
enum wifi_disconn_reason disconn_reason;
enum wifi_ap_status ap_status;
};
};

Expand Down Expand Up @@ -802,6 +835,20 @@ void wifi_mgmt_raise_raw_scan_result_event(struct net_if *iface,
*/
void wifi_mgmt_raise_disconnect_complete_event(struct net_if *iface, int status);

/** Wi-Fi management AP mode enable result event
*
* @param iface Network interface
* @param status AP mode enable result status
*/
void wifi_mgmt_raise_ap_enable_result_event(struct net_if *iface, enum wifi_ap_status status);

/** Wi-Fi management AP mode disable result event
*
* @param iface Network interface
* @param status AP mode disable result status
*/
void wifi_mgmt_raise_ap_disable_result_event(struct net_if *iface, enum wifi_ap_status status);

/**
* @}
*/
Expand Down
24 changes: 24 additions & 0 deletions subsys/net/l2/wifi/wifi_mgmt.c
Expand Up @@ -707,3 +707,27 @@ void wifi_mgmt_raise_disconnect_complete_event(struct net_if *iface,
iface, &cnx_status,
sizeof(struct wifi_status));
}

void wifi_mgmt_raise_ap_enable_result_event(struct net_if *iface,
enum wifi_ap_status status)
{
struct wifi_status cnx_status = {
.status = status,
};

net_mgmt_event_notify_with_info(NET_EVENT_WIFI_AP_ENABLE_RESULT,
iface, &cnx_status,
sizeof(enum wifi_ap_status));
}

void wifi_mgmt_raise_ap_disable_result_event(struct net_if *iface,
enum wifi_ap_status status)
{
struct wifi_status cnx_status = {
.status = status,
};

net_mgmt_event_notify_with_info(NET_EVENT_WIFI_AP_DISABLE_RESULT,
iface, &cnx_status,
sizeof(enum wifi_ap_status));
}
41 changes: 37 additions & 4 deletions subsys/net/l2/wifi/wifi_shell.c
Expand Up @@ -33,7 +33,9 @@ LOG_MODULE_REGISTER(net_wifi_shell, LOG_LEVEL_INF);
NET_EVENT_WIFI_CONNECT_RESULT |\
NET_EVENT_WIFI_DISCONNECT_RESULT | \
NET_EVENT_WIFI_TWT |\
NET_EVENT_WIFI_RAW_SCAN_RESULT)
NET_EVENT_WIFI_RAW_SCAN_RESULT |\
NET_EVENT_WIFI_AP_ENABLE_RESULT |\
NET_EVENT_WIFI_AP_DISABLE_RESULT)

#ifdef CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS_ONLY
#define WIFI_SHELL_MGMT_EVENTS (WIFI_SHELL_MGMT_EVENTS_COMMON)
Expand Down Expand Up @@ -300,6 +302,32 @@ static void handle_wifi_twt_event(struct net_mgmt_event_callback *cb)
}
}

static void handle_wifi_ap_enable_result(struct net_mgmt_event_callback *cb)
{
const struct wifi_status *status =
(const struct wifi_status *)cb->info;

if (status->status) {
print(context.sh, SHELL_WARNING,
"AP enable request failed (%d)\n", status->status);
} else {
print(context.sh, SHELL_NORMAL, "AP enabled\n");
}
}

static void handle_wifi_ap_disable_result(struct net_mgmt_event_callback *cb)
{
const struct wifi_status *status =
(const struct wifi_status *)cb->info;

if (status->status) {
print(context.sh, SHELL_WARNING,
"AP disable request failed (%d)\n", status->status);
} else {
print(context.sh, SHELL_NORMAL, "AP disabled\n");
}
}

static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb,
uint32_t mgmt_event, struct net_if *iface)
{
Expand All @@ -324,6 +352,12 @@ static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb,
handle_wifi_raw_scan_result(cb);
break;
#endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS */
case NET_EVENT_WIFI_AP_ENABLE_RESULT:
handle_wifi_ap_enable_result(cb);
break;
case NET_EVENT_WIFI_AP_DISABLE_RESULT:
handle_wifi_ap_disable_result(cb);
break;
default:
break;
}
Expand Down Expand Up @@ -1112,7 +1146,7 @@ static int cmd_wifi_ap_enable(const struct shell *sh, size_t argc,
return -ENOEXEC;
}

shell_fprintf(sh, SHELL_NORMAL, "AP mode enabled\n");
shell_fprintf(sh, SHELL_NORMAL, "AP mode enable requested\n");

return 0;
}
Expand All @@ -1129,8 +1163,7 @@ static int cmd_wifi_ap_disable(const struct shell *sh, size_t argc,
return -ENOEXEC;
}

shell_fprintf(sh, SHELL_NORMAL, "AP mode disabled\n");

shell_fprintf(sh, SHELL_NORMAL, "AP mode disable requested\n");
return 0;
}

Expand Down

0 comments on commit 15fe6c5

Please sign in to comment.