Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wifi: TWT improvements #82312

Merged
merged 4 commits into from
Dec 16, 2024
Merged

wifi: TWT improvements #82312

merged 4 commits into from
Dec 16, 2024

Conversation

Rex-Chen-NXP
Copy link
Contributor

@Rex-Chen-NXP Rex-Chen-NXP commented Nov 29, 2024

A. Add two new parameters for TWT setup
B. Fix TWT quick setup: Add default exponent value
C. Add Broadcast TWT feature support for AP
D. Convert TWT command to use getopt

@krish2718
Copy link
Collaborator

Please update the title and add description to explain these set of changes.

@Rex-Chen-NXP Rex-Chen-NXP changed the title Main twt twt support for zephyr L2 cmd Nov 29, 2024
@Rex-Chen-NXP
Copy link
Contributor Author

Please update the title and add description to explain these set of changes.

Yes, of course, updated title and changes details , changes info also in separated PRs commit mesg

@Rex-Chen-NXP
Copy link
Contributor Author

Hi @krish2718 @jukkar
Could you help to review?

MaochenWang1
MaochenWang1 previously approved these changes Dec 2, 2024
@@ -3184,15 +3200,16 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_twt_ops,
"<setup_cmd: 0: Request, 1: Suggest, 2: Demand>\n"
"<dialog_token: 1-255> <flow_id: 0-7> <responder: 0/1> <trigger: 0/1> <implicit:0/1> "
"<announce: 0/1> <twt_wake_interval: 1-262144us> <twt_interval: 1us-2^31us>.\n"
"<twt_wake_ahead_duration>: 0us-2^31us>\n",
"<twt_wake_ahead_duration>: 0us-2^31us>\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are getting now quite many positional parameters for these commands and it looks like not very user friendly way to implement this. Could this changed to use parameter "keywords", so something like -s, --setup <cmd> .... so like what we have in other commands?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, of course, will implement as comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jukkar Updated as comment, could you review again?

MaochenWang1
MaochenWang1 previously approved these changes Dec 3, 2024
@Rex-Chen-NXP
Copy link
Contributor Author

Hi @krish2718 @jukkar
Could you help review.
Thanks!

params.negotiation_type = (enum wifi_twt_negotiation_type)value;
case 'c':
if (!parse_number(sh, &value, state->optarg, NULL,
WIFI_TWT_SETUP_CMD_REQUEST, WIFI_TWT_SETUP_CMD_DEMAND)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit, but the indentation is wrong here and also for the other added lines.
So here the code should look like

			if (!parse_number(sh, &value, state->optarg, NULL,
					  WIFI_TWT_SETUP_CMD_REQUEST,
					  WIFI_TWT_SETUP_CMD_DEMAND)) {

Is it possible to adjust your editor to indent the lines automatically?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, all updated as comment

params.dialog_token = (uint8_t)value;
case 'f':
if (!parse_number(sh, &value, state->optarg, NULL, 0,
(WIFI_MAX_TWT_FLOWS - 1))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated as comment

params.setup.announce = (bool)value;
case 'w':
if (!parse_number(sh, &value, state->optarg, NULL, 1,
WIFI_MAX_TWT_WAKE_INTERVAL_US)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated as comment

params.setup.twt_wake_interval = (uint32_t)value;
case 'i':
if (!parse_number(sh, &value, state->optarg, NULL, 1,
WIFI_MAX_TWT_INTERVAL_US)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated as comment

return -EINVAL;
case 'D':
if (!parse_number(sh, &value, state->optarg, NULL, 0,
WIFI_MAX_TWT_WAKE_AHEAD_DURATION_US)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated as comment


case 'e':
if (!parse_number(sh, &value, state->optarg, NULL, 0,
WIFI_MAX_TWT_EXPONENT)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated as comment

@krish2718
Copy link
Collaborator

Hi @krish2718 @jukkar I want to insert other discussion about parameters usage of twt setup cmd. The below two usage items, from the value range and spec description , 'twt_wake_interval' should named as 'TWT Wake Duration', and 'twt_interval' should calculated from TWT Wake Interval(TWT Wake Interval Mantissa) and Exponent, so name as 'TWT Wake Interval' will be suitable. A. <twt_wake_interval: 1-262144us> B. <twt_interval: 1us-2^31us>
As I didn't find description about 'twt_interval' from spec, if my above suggestion and understanding is error, pls tell me. If you agree, I will raise other PR to change the usage after this PR merged. Thanks.

Please see https://github.com/zephyrproject-rtos/zephyr/pull/82312/files#r1875537287 , it's about keeping UI simple.

Sure, even if we don't use exponent, but the range of 'twt_wake_interval' is matched with 'TWT Wake Duration', so should we change the usage to 'TWT Wake Duration', twt_wake_interval make user confuse.

twt_wake_interval is mapped to Nominal Minimum TWT Wake Duration field and in 802.11ax-2021, the max value is https://github.com/zephyrproject-rtos/zephyr/blob/main/include/zephyr/net/wifi_mgmt.h#L765 i.e., Wake Duration Unit subfield == 1 and Nominal Minimum TWT Wake Duration field == 256 , can you please let me know how the range is incorrect? Please note that depending on the user value, the Wake Duration Unit subfield == 1 is auto-encoded to 0/1 in the driver/firmware.

Yes, I mean why don't named as 'TWT Wake Duration' directly?

Sure we can rename it to twt_wake_duration. But it would be a breaking API change.

Okay, will raise PR later after this PR merged.

Please note we have to follow the rules here for any stable API https://docs.zephyrproject.org/latest/develop/api/api_lifecycle.html but I guess there aren't many users of TWT, so, not sure if we should call it stable or not. @jukkar WDYT?

@Rex-Chen-NXP
Copy link
Contributor Author

Hi @krish2718 @jukkar @MaochenWang1
Follow @krish2718 comment to remove teardown changes, and there is no conclusion of 'exponent ', so keep exponent as shell input.

@krish2718
Copy link
Collaborator

Hi @krish2718 @jukkar @MaochenWang1
Follow @krish2718 comment to remove teardown changes, and there is no conclusion of 'exponent ', so keep exponent as shell input.

Should we add both the options? If the user gives time we derive (exponent, mantissa) and if the user gives (exponent, mantissa) we use it directly, WDYT?

@Rex-Chen-NXP
Copy link
Contributor Author

Hi @krish2718 @jukkar @MaochenWang1
Follow @krish2718 comment to remove teardown changes, and there is no conclusion of 'exponent ', so keep exponent as shell input.

Should we add both the options? If the user gives time we derive (exponent, mantissa) and if the user gives (exponent, mantissa) we use it directly, WDYT?

My concern is exist multiple sets of exponent and mantissa derived from a given time, and the time calculated from the derived exponent and mantissa may not equal to the given time. Customer may complain about why time set not as expectation.

@krish2718
Copy link
Collaborator

Hi @krish2718 @jukkar @MaochenWang1
Follow @krish2718 comment to remove teardown changes, and there is no conclusion of 'exponent ', so keep exponent as shell input.

Should we add both the options? If the user gives time we derive (exponent, mantissa) and if the user gives (exponent, mantissa) we use it directly, WDYT?

My concern is exist multiple sets of exponent and mantissa derived from a given time, and the time calculated from the derived exponent and mantissa may not equal to the given time. Customer may complain about why time set not as expectation.

We share the (exponent, mantissa) in the frame to the AP, so, at least AP and STA will have the same time. Anyways giving both options is better we can leave it to the users to choose the appropriate one, no?

@Rex-Chen-NXP
Copy link
Contributor Author

Rex-Chen-NXP commented Dec 10, 2024

Hi @krish2718 @jukkar @MaochenWang1
Follow @krish2718 comment to remove teardown changes, and there is no conclusion of 'exponent ', so keep exponent as shell input.

Should we add both the options? If the user gives time we derive (exponent, mantissa) and if the user gives (exponent, mantissa) we use it directly, WDYT?

My concern is exist multiple sets of exponent and mantissa derived from a given time, and the time calculated from the derived exponent and mantissa may not equal to the given time. Customer may complain about why time set not as expectation.

We share the (exponent, mantissa) in the frame to the AP, so, at least AP and STA will have the same time. Anyways giving both options is better we can leave it to the users to choose the appropriate one, no?

Okay, how can we derive a set of exponent and mantissa from a given time with high accuracy, is there any algorithm for refer?

@krish2718
Copy link
Collaborator

Hi @krish2718 @jukkar @MaochenWang1
Follow @krish2718 comment to remove teardown changes, and there is no conclusion of 'exponent ', so keep exponent as shell input.

Should we add both the options? If the user gives time we derive (exponent, mantissa) and if the user gives (exponent, mantissa) we use it directly, WDYT?

My concern is exist multiple sets of exponent and mantissa derived from a given time, and the time calculated from the derived exponent and mantissa may not equal to the given time. Customer may complain about why time set not as expectation.

We share the (exponent, mantissa) in the frame to the AP, so, at least AP and STA will have the same time. Anyways giving both options is better we can leave it to the users to choose the appropriate one, no?

Okay, how can we derive a set of exponent and mantissa from a given time with high accuracy, is there any algorithm for refer?

We took the simpler approach: https://github.com/zephyrproject-rtos/zephyr/blob/main/drivers/wifi/nrf_wifi/src/wifi_mgmt.c#L250

@krish2718
Copy link
Collaborator

Hi @krish2718 @jukkar @MaochenWang1
Follow @krish2718 comment to remove teardown changes, and there is no conclusion of 'exponent ', so keep exponent as shell input.

Should we add both the options? If the user gives time we derive (exponent, mantissa) and if the user gives (exponent, mantissa) we use it directly, WDYT?

My concern is exist multiple sets of exponent and mantissa derived from a given time, and the time calculated from the derived exponent and mantissa may not equal to the given time. Customer may complain about why time set not as expectation.

We share the (exponent, mantissa) in the frame to the AP, so, at least AP and STA will have the same time. Anyways giving both options is better we can leave it to the users to choose the appropriate one, no?

Okay, how can we derive a set of exponent and mantissa from a given time with high accuracy, is there any algorithm for refer?

We took the simpler approach: https://github.com/zephyrproject-rtos/zephyr/blob/main/drivers/wifi/nrf_wifi/src/wifi_mgmt.c#L250

Sonnet 3.5 gave this for binary scaling input.

def convert_time_to_mantissa_exponent(time_ms):
    """
    Convert time in milliseconds to mantissa and exponent representation
    
    Args:
        time_ms (float): Time in milliseconds
    
    Returns:
        tuple: (mantissa, exponent)
    """
    # Start with base-2 exponent of 0
    exponent = 0
    mantissa = time_ms
    
    # Reduce mantissa by dividing by 2 and incrementing exponent
    while mantissa > 255:  # Typical max mantissa value
        mantissa /= 2
        exponent += 1
    
    return (int(mantissa), exponent)

# Example usage
time = 50  # milliseconds
mantissa, exponent = convert_time_to_mantissa_exponent(time)
print(f"Original time: {time}ms")
print(f"Mantissa: {mantissa}")
print(f"Exponent: {exponent}")
print(f"Reconstructed time: {mantissa * (2 ** exponent)}ms")

@Rex-Chen-NXP
Copy link
Contributor Author

Hi @krish2718 @jukkar @MaochenWang1
Follow @krish2718 comment to remove teardown changes, and there is no conclusion of 'exponent ', so keep exponent as shell input.

Should we add both the options? If the user gives time we derive (exponent, mantissa) and if the user gives (exponent, mantissa) we use it directly, WDYT?

My concern is exist multiple sets of exponent and mantissa derived from a given time, and the time calculated from the derived exponent and mantissa may not equal to the given time. Customer may complain about why time set not as expectation.

We share the (exponent, mantissa) in the frame to the AP, so, at least AP and STA will have the same time. Anyways giving both options is better we can leave it to the users to choose the appropriate one, no?

Okay, how can we derive a set of exponent and mantissa from a given time with high accuracy, is there any algorithm for refer?

We took the simpler approach: https://github.com/zephyrproject-rtos/zephyr/blob/main/drivers/wifi/nrf_wifi/src/wifi_mgmt.c#L250

Sonnet 3.5 gave this for binary scaling input.

def convert_time_to_mantissa_exponent(time_ms):
    """
    Convert time in milliseconds to mantissa and exponent representation
    
    Args:
        time_ms (float): Time in milliseconds
    
    Returns:
        tuple: (mantissa, exponent)
    """
    # Start with base-2 exponent of 0
    exponent = 0
    mantissa = time_ms
    
    # Reduce mantissa by dividing by 2 and incrementing exponent
    while mantissa > 255:  # Typical max mantissa value
        mantissa /= 2
        exponent += 1
    
    return (int(mantissa), exponent)

# Example usage
time = 50  # milliseconds
mantissa, exponent = convert_time_to_mantissa_exponent(time)
print(f"Original time: {time}ms")
print(f"Mantissa: {mantissa}")
print(f"Exponent: {exponent}")
print(f"Reconstructed time: {mantissa * (2 ** exponent)}ms")

Thanks for sharing, as Nordic driver implemented the convert of (exponent, mantissa, interval) , and need interval as argv, to compatible Nordic's exist implementation, the shell should prepare all of parameters(exponent, mantissa, interval) according to the input (exponent, mantissa) or interval, right? If you agree, I will make change.

@decsny decsny removed their request for review December 10, 2024 14:31
@Rex-Chen-NXP
Copy link
Contributor Author

Hi @krish2718 @jukkar @MaochenWang1
Follow @krish2718 comments to support both interval or (exponent, mantissa) as input parameters, format check pass in local, test pass base on RW612 board, could help review after CI check pass?

subsys/net/l2/wifi/wifi_shell.c Outdated Show resolved Hide resolved
subsys/net/l2/wifi/wifi_shell.c Outdated Show resolved Hide resolved
@Rex-Chen-NXP Rex-Chen-NXP force-pushed the main_twt branch 2 times, most recently from 9b152d2 to 117b20d Compare December 11, 2024 09:13
Enhance the parse parameters code for twt.

Signed-off-by: Rex Chen <[email protected]>
Add btwt_setup cmd for sap.

Signed-off-by: Rex Chen <[email protected]>
Add two parameters for twt setup.

Signed-off-by: Rex Chen <[email protected]>
The default exponent is 0, will cause twt setup quick failed,
set exponent value derived from twt interval to fix it.

Signed-off-by: Rex Chen <[email protected]>
@Rex-Chen-NXP
Copy link
Contributor Author

Hi @krish2718 @jukkar
As CI check failed early, I rebased for PR, could you help review?

@Rex-Chen-NXP
Copy link
Contributor Author

Hi @jukkar @dleach02
Could you help review and merge PR?

@kartben kartben merged commit ab948b0 into zephyrproject-rtos:main Dec 16, 2024
25 checks passed
@Rex-Chen-NXP Rex-Chen-NXP deleted the main_twt branch December 17, 2024 03:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants