@@ -134,6 +134,7 @@ static int cmd_add_network(const struct shell *shell, size_t argc, char *argv[])
134134 char bands_str [MAX_BANDS_STR_LEN ] = {0 };
135135 size_t offset = 0 ;
136136 long channel ;
137+ long mfp = WIFI_MFP_OPTIONAL ;
137138
138139 while ((opt = getopt_long (argc , argv , "s:p:k:w:b:c:m:t:a:K:h" , long_options , & opt_index )) !=
139140 -1 ) {
@@ -220,16 +221,21 @@ static int cmd_add_network(const struct shell *shell, size_t argc, char *argv[])
220221 case 'w' :
221222 if (creds .header .type == WIFI_SECURITY_TYPE_NONE ||
222223 creds .header .type == WIFI_SECURITY_TYPE_WPA_PSK ) {
223- shell_error (shell , "MFP not supported for security type %s\n " ,
224+ shell_error (shell , "MFP not supported for security type %s" ,
224225 wifi_security_txt (creds .header .type ));
226+ return - ENOTSUP ;
227+ }
228+ mfp = strtol (state -> optarg , & endptr , 10 );
229+ if (* endptr != '\0' ) {
230+ shell_error (shell , "Invalid IEEE 802.11w value: %s" , state -> optarg );
225231 return - EINVAL ;
226232 }
227- if (! strncmp ( state -> optarg , "disabled" , 8 ) ) {
233+ if (mfp == WIFI_MFP_DISABLE ) {
228234 creds .header .flags |= WIFI_CREDENTIALS_FLAG_MFP_DISABLED ;
229- } else if (! strncmp ( state -> optarg , "required" , 8 ) ) {
235+ } else if (mfp == WIFI_MFP_REQUIRED ) {
230236 creds .header .flags |= WIFI_CREDENTIALS_FLAG_MFP_REQUIRED ;
231- } else {
232- shell_error (shell , "Invalid IEEE 802.11w value: %s\n " ,
237+ } else if ( mfp > 2 ) {
238+ shell_error (shell , "Invalid IEEE 802.11w value: %s" ,
233239 state -> optarg );
234240 return - EINVAL ;
235241 }
0 commit comments