Skip to content

Commit 7d19539

Browse files
ndrs-pstnashif
authored andcommitted
net: wifi: shell: enhance consistency in cmd_wifi_dpp_ap_auth_init
The `cmd_wifi_dpp_ap_auth_init` function was added but is not yet aligned with others. This update enhances consistency with the following changes: - Unified the order of declaration for `opt`, `opt_index`, `state`, and `long_options`. - Wrapped lines in the `long_options` declaration to prevent them from extending too far to the right. - Applied `struct option` as `static const` - Unified the wrapping of `getopt_long` calls, regardless of the length of the `options` string. - Using `getopt_state` to access `optarg` and also `optopt` offers a better alternative to direct global access. Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
1 parent 3756429 commit 7d19539

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

subsys/net/l2/wifi/wifi_shell.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2579,24 +2579,27 @@ static int cmd_wifi_dpp_ap_qr_code(const struct shell *sh, size_t argc, char *ar
25792579

25802580
static int cmd_wifi_dpp_ap_auth_init(const struct shell *sh, size_t argc, char *argv[])
25812581
{
2582-
int ret = 0;
2583-
struct net_if *iface = net_if_get_wifi_sap();
2584-
struct wifi_dpp_params params = {0};
25852582
int opt;
25862583
int opt_index = 0;
25872584
struct getopt_state *state;
2588-
static struct option long_options[] = {{"peer", required_argument, 0, 'p'}, {0, 0, 0, 0}};
2585+
static const struct option long_options[] = {
2586+
{"peer", required_argument, 0, 'p'},
2587+
{0, 0, 0, 0}};
2588+
int ret = 0;
2589+
struct net_if *iface = net_if_get_wifi_sap();
2590+
struct wifi_dpp_params params = {0};
25892591

25902592
params.action = WIFI_DPP_AUTH_INIT;
25912593

2592-
while ((opt = getopt_long(argc, argv, "p:", long_options, &opt_index)) != -1) {
2594+
while ((opt = getopt_long(argc, argv, "p:",
2595+
long_options, &opt_index)) != -1) {
25932596
state = getopt_state_get();
25942597
switch (opt) {
25952598
case 'p':
2596-
params.auth_init.peer = shell_strtol(optarg, 10, &ret);
2599+
params.auth_init.peer = shell_strtol(state->optarg, 10, &ret);
25972600
break;
25982601
default:
2599-
PR_ERROR("Invalid option %c\n", optopt);
2602+
PR_ERROR("Invalid option %c\n", state->optopt);
26002603
return -EINVAL;
26012604
}
26022605

0 commit comments

Comments
 (0)