Browse Source

wifi: shell: Return text description of connection error

If "wifi connect" fails, tell user why in textual format.
This helps debugging connectivity issues.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
pull/87707/head
Jukka Rissanen 4 months ago committed by Benjamin Cabé
parent
commit
92da8cb69f
  1. 30
      include/zephyr/net/wifi.h
  2. 27
      include/zephyr/net/wifi_mgmt.h
  3. 18
      subsys/net/l2/wifi/wifi_mgmt.c
  4. 4
      subsys/net/l2/wifi/wifi_shell.c

30
include/zephyr/net/wifi.h

@ -38,6 +38,33 @@ @@ -38,6 +38,33 @@
extern "C" {
#endif
/** @brief Wi-Fi connect result codes. To be overlaid on top of \ref wifi_status
* in the connect result event for detailed status.
*/
enum wifi_conn_status {
/** Connection successful */
WIFI_STATUS_CONN_SUCCESS = 0,
/** Connection failed - generic failure */
WIFI_STATUS_CONN_FAIL,
/** Connection failed - wrong password
* Few possible reasons for 4-way handshake failure that we can guess are as follows:
* 1) Incorrect key
* 2) EAPoL frames lost causing timeout
*
* #1 is the likely cause, so, we convey to the user that it is due to
* Wrong passphrase/password.
*/
WIFI_STATUS_CONN_WRONG_PASSWORD,
/** Connection timed out */
WIFI_STATUS_CONN_TIMEOUT,
/** Connection failed - AP not found */
WIFI_STATUS_CONN_AP_NOT_FOUND,
/** Last connection status */
WIFI_STATUS_CONN_LAST_STATUS,
/** Connection disconnected status */
WIFI_STATUS_DISCONN_FIRST_STATUS = WIFI_STATUS_CONN_LAST_STATUS,
};
/** @brief IEEE 802.11 security types. */
enum wifi_security_type {
/** No security. */
@ -708,6 +735,9 @@ enum wifi_ap_config_param { @@ -708,6 +735,9 @@ enum wifi_ap_config_param {
WIFI_AP_CONFIG_PARAM_VHT_CAPAB = BIT(4),
};
/** Helper function to get user-friendly status name for the status code. */
const char *wifi_conn_status_txt(enum wifi_conn_status status);
#ifdef __cplusplus
}
#endif

27
include/zephyr/net/wifi_mgmt.h

@ -587,33 +587,6 @@ struct wifi_connect_req_params { @@ -587,33 +587,6 @@ struct wifi_connect_req_params {
enum wifi_frequency_bandwidths bandwidth;
};
/** @brief Wi-Fi connect result codes. To be overlaid on top of \ref wifi_status
* in the connect result event for detailed status.
*/
enum wifi_conn_status {
/** Connection successful */
WIFI_STATUS_CONN_SUCCESS = 0,
/** Connection failed - generic failure */
WIFI_STATUS_CONN_FAIL,
/** Connection failed - wrong password
* Few possible reasons for 4-way handshake failure that we can guess are as follows:
* 1) Incorrect key
* 2) EAPoL frames lost causing timeout
*
* #1 is the likely cause, so, we convey to the user that it is due to
* Wrong passphrase/password.
*/
WIFI_STATUS_CONN_WRONG_PASSWORD,
/** Connection timed out */
WIFI_STATUS_CONN_TIMEOUT,
/** Connection failed - AP not found */
WIFI_STATUS_CONN_AP_NOT_FOUND,
/** Last connection status */
WIFI_STATUS_CONN_LAST_STATUS,
/** Connection disconnected status */
WIFI_STATUS_DISCONN_FIRST_STATUS = WIFI_STATUS_CONN_LAST_STATUS,
};
/** @brief Wi-Fi disconnect reason codes. To be overlaid on top of \ref wifi_status
* in the disconnect result event for detailed reason.
*/

18
subsys/net/l2/wifi/wifi_mgmt.c

@ -333,6 +333,24 @@ const char *wifi_ps_exit_strategy_txt(enum wifi_ps_exit_strategy ps_exit_strateg @@ -333,6 +333,24 @@ const char *wifi_ps_exit_strategy_txt(enum wifi_ps_exit_strategy ps_exit_strateg
}
}
const char *wifi_conn_status_txt(enum wifi_conn_status status)
{
switch (status) {
case WIFI_STATUS_CONN_SUCCESS:
return "Connection successful";
case WIFI_STATUS_CONN_FAIL:
return "Connection failed";
case WIFI_STATUS_CONN_WRONG_PASSWORD:
return "Wrong password";
case WIFI_STATUS_CONN_TIMEOUT:
return "Connection timeout";
case WIFI_STATUS_CONN_AP_NOT_FOUND:
return "AP not found";
default:
return "UNKNOWN";
}
}
static const struct wifi_mgmt_ops *const get_wifi_api(struct net_if *iface)
{
const struct device *dev = net_if_get_device(iface);

4
subsys/net/l2/wifi/wifi_shell.c

@ -315,7 +315,9 @@ static void handle_wifi_connect_result(struct net_mgmt_event_callback *cb) @@ -315,7 +315,9 @@ static void handle_wifi_connect_result(struct net_mgmt_event_callback *cb)
const struct shell *sh = context.sh;
if (status->status) {
PR_WARNING("Connection request failed (%d)\n", status->status);
PR_WARNING("Connection request failed (%s/%d)\n",
wifi_conn_status_txt(status->status),
status->status);
} else {
PR("Connected\n");
}

Loading…
Cancel
Save