Skip to content

Commit a004a85

Browse files
ajayparidacarlescufi
authored andcommitted
net: shell: Check connection & capabilities in any TWT operation
Connection status & AP capabilities checked before any TWT operation is initiated. Signed-off-by: Ajay Parida <[email protected]>
1 parent f47b537 commit a004a85

File tree

4 files changed

+88
-8
lines changed

4 files changed

+88
-8
lines changed

include/zephyr/net/wifi.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,4 +336,41 @@ enum wifi_twt_setup_resp_status {
336336
WIFI_TWT_RESP_NOT_RECEIVED,
337337
};
338338

339+
enum wifi_twt_fail_reason {
340+
WIFI_TWT_FAIL_UNSPECIFIED,
341+
WIFI_TWT_FAIL_CMD_EXEC_FAIL,
342+
WIFI_TWT_FAIL_OPERATION_NOT_SUPPORTED,
343+
WIFI_TWT_FAIL_UNABLE_TO_GET_IFACE_STATUS,
344+
WIFI_TWT_FAIL_DEVICE_NOT_CONNECTED,
345+
WIFI_TWT_FAIL_PEER_NOT_HE_CAPAB,
346+
WIFI_TWT_FAIL_PEER_NOT_TWT_CAPAB,
347+
WIFI_TWT_FAIL_OPERATION_IN_PROGRESS,
348+
WIFI_TWT_FAIL_INVALID_FLOW_ID,
349+
};
350+
351+
static const char * const twt_err_code_tbl[] = {
352+
[WIFI_TWT_FAIL_UNSPECIFIED] = "Unspecfied",
353+
[WIFI_TWT_FAIL_CMD_EXEC_FAIL] = "Command Execution failed",
354+
[WIFI_TWT_FAIL_OPERATION_NOT_SUPPORTED] =
355+
"Operation not supported",
356+
[WIFI_TWT_FAIL_UNABLE_TO_GET_IFACE_STATUS] =
357+
"Unable to get iface status",
358+
[WIFI_TWT_FAIL_DEVICE_NOT_CONNECTED] =
359+
"Device not connected",
360+
[WIFI_TWT_FAIL_PEER_NOT_HE_CAPAB] = "Peer not HE capable",
361+
[WIFI_TWT_FAIL_PEER_NOT_TWT_CAPAB] = "Peer not TWT capable",
362+
[WIFI_TWT_FAIL_OPERATION_IN_PROGRESS] =
363+
"Operation already in progress",
364+
[WIFI_TWT_FAIL_INVALID_FLOW_ID] =
365+
"Invalid negotiated flow id",
366+
};
367+
368+
static inline const char *get_twt_err_code_str(int16_t err_no)
369+
{
370+
if ((err_no) < ARRAY_SIZE(twt_err_code_tbl)) {
371+
return twt_err_code_tbl[err_no];
372+
}
373+
374+
return "<unknown>";
375+
}
339376
#endif /* ZEPHYR_INCLUDE_NET_WIFI_H_ */

include/zephyr/net/wifi_mgmt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ struct wifi_iface_status {
187187
int rssi;
188188
unsigned char dtim_period;
189189
unsigned short beacon_interval;
190+
bool twt_capable;
190191
};
191192

192193
struct wifi_ps_params {
@@ -226,6 +227,7 @@ struct wifi_twt_params {
226227
bool teardown_all;
227228
} teardown;
228229
};
230+
enum wifi_twt_fail_reason fail_reason;
229231
};
230232

231233
/* Flow ID is only 3 bits */

subsys/net/l2/wifi/wifi_mgmt.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,43 @@ static int wifi_set_twt(uint32_t mgmt_request, struct net_if *iface,
277277
struct net_wifi_mgmt_offload *off_api =
278278
(struct net_wifi_mgmt_offload *) dev->api;
279279
struct wifi_twt_params *twt_params = data;
280+
struct wifi_iface_status info = { 0 };
280281

281282
if (off_api == NULL || off_api->set_twt == NULL) {
283+
twt_params->fail_reason =
284+
WIFI_TWT_FAIL_OPERATION_NOT_SUPPORTED;
282285
return -ENOTSUP;
283286
}
284287

288+
if (net_mgmt(NET_REQUEST_WIFI_IFACE_STATUS, iface, &info,
289+
sizeof(struct wifi_iface_status))) {
290+
twt_params->fail_reason =
291+
WIFI_TWT_FAIL_UNABLE_TO_GET_IFACE_STATUS;
292+
goto fail;
293+
}
294+
295+
if (info.state != WIFI_STATE_COMPLETED) {
296+
twt_params->fail_reason =
297+
WIFI_TWT_FAIL_DEVICE_NOT_CONNECTED;
298+
goto fail;
299+
}
300+
301+
if (info.link_mode < WIFI_6) {
302+
twt_params->fail_reason =
303+
WIFI_TWT_FAIL_PEER_NOT_HE_CAPAB;
304+
goto fail;
305+
}
306+
307+
if (!info.twt_capable) {
308+
twt_params->fail_reason =
309+
WIFI_TWT_FAIL_PEER_NOT_TWT_CAPAB;
310+
goto fail;
311+
}
312+
285313
return off_api->set_twt(dev, twt_params);
314+
fail:
315+
return -ENOEXEC;
316+
286317
}
287318

288319
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_TWT, wifi_set_twt);

subsys/net/l2/wifi/wifi_shell.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,8 @@ static int cmd_wifi_status(const struct shell *sh, size_t argc, char *argv[])
376376
shell_fprintf(sh, SHELL_NORMAL, "RSSI: %d\n", status.rssi);
377377
shell_fprintf(sh, SHELL_NORMAL, "Beacon Interval: %d\n", status.beacon_interval);
378378
shell_fprintf(sh, SHELL_NORMAL, "DTIM: %d\n", status.dtim_period);
379+
shell_fprintf(sh, SHELL_NORMAL, "TWT: %s\n",
380+
status.twt_capable ? "Supported" : "Not supported");
379381
}
380382

381383
return 0;
@@ -606,9 +608,11 @@ static int cmd_wifi_twt_setup_quick(const struct shell *sh, size_t argc,
606608
return -EINVAL;
607609

608610
if (net_mgmt(NET_REQUEST_WIFI_TWT, iface, &params, sizeof(params))) {
609-
shell_fprintf(sh, SHELL_WARNING, "%s with %s failed\n",
611+
shell_fprintf(sh, SHELL_WARNING, "%s with %s failed, reason : %s\n",
610612
wifi_twt_operation2str[params.operation],
611-
wifi_twt_negotiation_type2str[params.negotiation_type]);
613+
wifi_twt_negotiation_type2str[params.negotiation_type],
614+
get_twt_err_code_str(params.fail_reason));
615+
612616
return -ENOEXEC;
613617
}
614618

@@ -660,9 +664,11 @@ static int cmd_wifi_twt_setup(const struct shell *sh, size_t argc,
660664
params.setup_cmd = setup_cmd;
661665

662666
if (net_mgmt(NET_REQUEST_WIFI_TWT, iface, &params, sizeof(params))) {
663-
shell_fprintf(sh, SHELL_WARNING, "%s with %s failed\n",
667+
shell_fprintf(sh, SHELL_WARNING, "%s with %s failed. reason : %s\n",
664668
wifi_twt_operation2str[params.operation],
665-
wifi_twt_negotiation_type2str[params.negotiation_type]);
669+
wifi_twt_negotiation_type2str[params.negotiation_type],
670+
get_twt_err_code_str(params.fail_reason));
671+
666672
return -ENOEXEC;
667673
}
668674

@@ -704,9 +710,11 @@ static int cmd_wifi_twt_teardown(const struct shell *sh, size_t argc,
704710
return -EINVAL;
705711

706712
if (net_mgmt(NET_REQUEST_WIFI_TWT, iface, &params, sizeof(params))) {
707-
shell_fprintf(sh, SHELL_WARNING, "%s with %s failed\n",
713+
shell_fprintf(sh, SHELL_WARNING, "%s with %s failed, reason : %s\n",
708714
wifi_twt_operation2str[params.operation],
709-
wifi_twt_negotiation_type2str[params.negotiation_type]);
715+
wifi_twt_negotiation_type2str[params.negotiation_type],
716+
get_twt_err_code_str(params.fail_reason));
717+
710718
return -ENOEXEC;
711719
}
712720

@@ -729,9 +737,11 @@ static int cmd_wifi_twt_teardown_all(const struct shell *sh, size_t argc,
729737
params.teardown.teardown_all = 1;
730738

731739
if (net_mgmt(NET_REQUEST_WIFI_TWT, iface, &params, sizeof(params))) {
732-
shell_fprintf(sh, SHELL_WARNING, "%s with %s failed\n",
740+
shell_fprintf(sh, SHELL_WARNING, "%s with %s failed, reason : %s\n",
733741
wifi_twt_operation2str[params.operation],
734-
wifi_twt_negotiation_type2str[params.negotiation_type]);
742+
wifi_twt_negotiation_type2str[params.negotiation_type],
743+
get_twt_err_code_str(params.fail_reason));
744+
735745
return -ENOEXEC;
736746
}
737747

0 commit comments

Comments
 (0)