Skip to content

Commit d6f2f43

Browse files
committed
net: wifi: shell: enhance consistency in code style
Enhancing code consistency provides cognitive leverage with the following changes: - Unified the order of declaration for `opt`, `opt_index`, `state`, and `long_options`. - Unified the wrapping of `getopt_long` calls, regardless of the length of the `options` string. - Renamed `option_index` to `opt_index` for consistency. Signed-off-by: Pisit Sawangvonganan <[email protected]>
1 parent be356a1 commit d6f2f43

File tree

1 file changed

+28
-27
lines changed

1 file changed

+28
-27
lines changed

subsys/net/l2/wifi/wifi_shell.c

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ static struct {
5757

5858
union {
5959
struct {
60-
6160
uint8_t connecting: 1;
6261
uint8_t disconnecting: 1;
6362
uint8_t _unused: 6;
@@ -453,11 +452,9 @@ static int __wifi_args_to_params(const struct shell *sh, size_t argc, char *argv
453452
struct wifi_connect_req_params *params,
454453
enum wifi_iface_mode iface_mode)
455454
{
456-
char *endptr;
457-
int idx = 1;
458-
struct getopt_state *state;
459455
int opt;
460-
bool secure_connection = false;
456+
int opt_index = 0;
457+
struct getopt_state *state;
461458
static const struct option long_options[] = {
462459
{"ssid", required_argument, 0, 's'},
463460
{"passphrase", required_argument, 0, 'p'},
@@ -469,7 +466,9 @@ static int __wifi_args_to_params(const struct shell *sh, size_t argc, char *argv
469466
{"timeout", required_argument, 0, 't'},
470467
{"help", no_argument, 0, 'h'},
471468
{0, 0, 0, 0}};
472-
int opt_index = 0;
469+
char *endptr;
470+
int idx = 1;
471+
bool secure_connection = false;
473472
uint8_t band;
474473
const uint8_t all_bands[] = {
475474
WIFI_FREQ_BAND_2_4_GHZ,
@@ -488,7 +487,7 @@ static int __wifi_args_to_params(const struct shell *sh, size_t argc, char *argv
488487
params->mfp = WIFI_MFP_OPTIONAL;
489488

490489
while ((opt = getopt_long(argc, argv, "s:p:k:w:b:c:m:t:h",
491-
long_options, &opt_index)) != -1) {
490+
long_options, &opt_index)) != -1) {
492491
state = getopt_state_get();
493492
switch (opt) {
494493
case 's':
@@ -667,8 +666,9 @@ static int wifi_scan_args_to_params(const struct shell *sh,
667666
struct wifi_scan_params *params,
668667
bool *do_scan)
669668
{
670-
struct getopt_state *state;
671669
int opt;
670+
int opt_index = 0;
671+
struct getopt_state *state;
672672
static const struct option long_options[] = {
673673
{"type", required_argument, 0, 't'},
674674
{"bands", required_argument, 0, 'b'},
@@ -679,13 +679,13 @@ static int wifi_scan_args_to_params(const struct shell *sh,
679679
{"chans", required_argument, 0, 'c'},
680680
{"help", no_argument, 0, 'h'},
681681
{0, 0, 0, 0}};
682-
int opt_index = 0;
683682
int val;
684683
int opt_num = 0;
685684

686685
*do_scan = true;
687686

688-
while ((opt = getopt_long(argc, argv, "t:b:a:p:s:m:c:h", long_options, &opt_index)) != -1) {
687+
while ((opt = getopt_long(argc, argv, "t:b:a:p:s:m:c:h",
688+
long_options, &opt_index)) != -1) {
689689
state = getopt_state_get();
690690
switch (opt) {
691691
case 't':
@@ -1398,17 +1398,18 @@ static int cmd_wifi_ap_sta_disconnect(const struct shell *sh, size_t argc,
13981398
static int wifi_ap_config_args_to_params(const struct shell *sh, size_t argc, char *argv[],
13991399
struct wifi_ap_config_params *params)
14001400
{
1401-
struct getopt_state *state;
14021401
int opt;
1402+
int opt_index = 0;
1403+
struct getopt_state *state;
14031404
static const struct option long_options[] = {
14041405
{"max_inactivity", required_argument, 0, 'i'},
14051406
{"max_num_sta", required_argument, 0, 's'},
14061407
{"help", no_argument, 0, 'h'},
14071408
{0, 0, 0, 0}};
1408-
int opt_index = 0;
14091409
long val;
14101410

1411-
while ((opt = getopt_long(argc, argv, "i:s:h", long_options, &opt_index)) != -1) {
1411+
while ((opt = getopt_long(argc, argv, "i:s:h",
1412+
long_options, &opt_index)) != -1) {
14121413
state = getopt_state_get();
14131414
switch (opt) {
14141415
case 'i':
@@ -1640,9 +1641,8 @@ void parse_mode_args_to_params(const struct shell *sh, int argc,
16401641
bool *do_mode_oper)
16411642
{
16421643
int opt;
1643-
int option_index = 0;
1644+
int opt_index = 0;
16441645
struct getopt_state *state;
1645-
16461646
static const struct option long_options[] = {
16471647
{"if-index", optional_argument, 0, 'i'},
16481648
{"sta", no_argument, 0, 's'},
@@ -1653,7 +1653,8 @@ void parse_mode_args_to_params(const struct shell *sh, int argc,
16531653
{"help", no_argument, 0, 'h'},
16541654
{0, 0, 0, 0}};
16551655

1656-
while ((opt = getopt_long(argc, argv, "i:smtpakgh", long_options, &option_index)) != -1) {
1656+
while ((opt = getopt_long(argc, argv, "i:smtpakgh",
1657+
long_options, &opt_index)) != -1) {
16571658
state = getopt_state_get();
16581659
switch (opt) {
16591660
case 's':
@@ -1742,17 +1743,17 @@ void parse_channel_args_to_params(const struct shell *sh, int argc,
17421743
bool *do_channel_oper)
17431744
{
17441745
int opt;
1745-
int option_index = 0;
1746+
int opt_index = 0;
17461747
struct getopt_state *state;
1747-
17481748
static const struct option long_options[] = {
17491749
{"if-index", optional_argument, 0, 'i'},
17501750
{"channel", required_argument, 0, 'c'},
17511751
{"get", no_argument, 0, 'g'},
17521752
{"help", no_argument, 0, 'h'},
17531753
{0, 0, 0, 0}};
17541754

1755-
while ((opt = getopt_long(argc, argv, "i:c:gh", long_options, &option_index)) != -1) {
1755+
while ((opt = getopt_long(argc, argv, "i:c:gh",
1756+
long_options, &opt_index)) != -1) {
17561757
state = getopt_state_get();
17571758
switch (opt) {
17581759
case 'c':
@@ -1840,9 +1841,8 @@ void parse_filter_args_to_params(const struct shell *sh, int argc,
18401841
bool *do_filter_oper)
18411842
{
18421843
int opt;
1843-
int option_index = 0;
1844+
int opt_index = 0;
18441845
struct getopt_state *state;
1845-
18461846
static const struct option long_options[] = {
18471847
{"if-index", optional_argument, 0, 'i'},
18481848
{"capture-len", optional_argument, 0, 'b'},
@@ -1854,7 +1854,8 @@ void parse_filter_args_to_params(const struct shell *sh, int argc,
18541854
{"help", no_argument, 0, 'h'},
18551855
{0, 0, 0, 0}};
18561856

1857-
while ((opt = getopt_long(argc, argv, "i:b:amcdgh", long_options, &option_index)) != -1) {
1857+
while ((opt = getopt_long(argc, argv, "i:b:amcdgh",
1858+
long_options, &opt_index)) != -1) {
18581859
state = getopt_state_get();
18591860
switch (opt) {
18601861
case 'a':
@@ -1980,7 +1981,7 @@ static int parse_dpp_args_auth_init(const struct shell *sh, size_t argc, char *a
19801981
int ret = 0;
19811982

19821983
while ((opt = getopt_long(argc, argv, "p:r:c:m:s:",
1983-
long_options, &opt_index)) != -1) {
1984+
long_options, &opt_index)) != -1) {
19841985
state = getopt_state_get();
19851986
switch (opt) {
19861987
case 'p':
@@ -2025,7 +2026,7 @@ static int parse_dpp_args_chirp(const struct shell *sh, size_t argc, char *argv[
20252026
int ret = 0;
20262027

20272028
while ((opt = getopt_long(argc, argv, "i:f:",
2028-
long_options, &opt_index)) != -1) {
2029+
long_options, &opt_index)) != -1) {
20292030
state = getopt_state_get();
20302031
switch (opt) {
20312032
case 'i':
@@ -2061,7 +2062,7 @@ static int parse_dpp_args_listen(const struct shell *sh, size_t argc, char *argv
20612062
int ret = 0;
20622063

20632064
while ((opt = getopt_long(argc, argv, "r:f:",
2064-
long_options, &opt_index)) != -1) {
2065+
long_options, &opt_index)) != -1) {
20652066
state = getopt_state_get();
20662067
switch (opt) {
20672068
case 'r':
@@ -2099,7 +2100,7 @@ static int parse_dpp_args_btstrap_gen(const struct shell *sh, size_t argc, char
20992100
int ret = 0;
21002101

21012102
while ((opt = getopt_long(argc, argv, "t:o:h:a:",
2102-
long_options, &opt_index)) != -1) {
2103+
long_options, &opt_index)) != -1) {
21032104
state = getopt_state_get();
21042105
switch (opt) {
21052106
case 't':
@@ -2160,7 +2161,7 @@ static int parse_dpp_args_set_config_param(const struct shell *sh, size_t argc,
21602161
int ret = 0;
21612162

21622163
while ((opt = getopt_long(argc, argv, "p:r:c:m:s:",
2163-
long_options, &opt_index)) != -1) {
2164+
long_options, &opt_index)) != -1) {
21642165
state = getopt_state_get();
21652166
switch (opt) {
21662167
case 'c':

0 commit comments

Comments
 (0)