8000 Fix Crash when wifi scan API is called while mode = STA and AP connected · daq-tools/pycom-micropython@aa2b127 · GitHub
[go: up one dir, main page]

Skip to content

Commit aa2b127

Browse files
author
iwahdan88
committed
Fix Crash when wifi scan API is called while mode = STA and AP connected
1 parent cae8fad commit aa2b127

File tree

1 file changed

+61
-58
lines changed

1 file changed

+61
-58
lines changed

esp32/mods/modwlan.c

Lines changed: 61 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,97 +1372,100 @@ STATIC mp_obj_t wlan_scan(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *
13721372
mp_buffer_info_t bufinfo;
13731373
mp_obj_t *stime;
13741374
size_t stimelen;
1375-
if(args[0].u_obj == mp_const_none && args[1].u_obj == mp_const_none && args[2].u_obj == mp_const_none && args[3].u_obj == mp_const_none && args[4].u_obj == mp_const_none && args[5].u_obj == mp_const_none)
1375+
1376+
1377+
if(args[0].u_obj != mp_const_none)
13761378
{
1377-
ptr_config = NULL;
1379+
scan_config.ssid = (uint8_t*)mp_obj_str_get_str(args[0].u_obj);
13781380
}
1379-
else
1381+
1382+
if(args[1].u_obj != mp_const_none)
13801383
{
1381-
if(args[0].u_obj != mp_const_none)
1384+
if(MP_OBJ_IS_TYPE(args[1].u_obj, &mp_type_bytes))
13821385
{
1383-
scan_config.ssid = (uint8_t*)mp_obj_str_get_str(args[0].u_obj);
1386+
mp_get_buffer_raise(args[1].u_obj, &bufinfo, MP_BUFFER_READ);
1387+
scan_config.bssid = bufinfo.buf;
13841388
}
1385-
1386-
if(args[1].u_obj != mp_const_none)
1389+
else
13871390
{
1388-
if(MP_OBJ_IS_TYPE(args[1].u_obj, &mp_type_bytes))
1389-
{
1390-
mp_get_buffer_raise(args[1].u_obj, &bufinfo, MP_BUFFER_READ);
1391-
scan_config.bssid = bufinfo.buf;
1392-
}
1393-
else
1394-
{
1395-
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "invalid bssid"));
1396-
}
1391+
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "invalid bssid"));
13971392
}
1393+
}
13981394

1399-
if(args[2].u_obj != mp_const_none)
1400-
{
1401-
scan_config.channel = mp_obj_get_int(args[2].u_obj);
1402-
}
1395+
if(args[2].u_obj != mp_const_none)
1396+
{
1397+
scan_config.channel = mp_obj_get_int(args[2].u_obj);
1398+
}
1399+
1400+
if(args[3].u_obj != mp_const_none)
1401+
{
1402+
scan_config.show_hidden = mp_obj_get_int(args[3].u_obj) >= 1;
1403+
}
14031404

1404-
if(args[3].u_obj != mp_const_none)
1405+
if(args[4].u_obj != mp_const_none)
1406+
{
1407+
if((wifi_scan_type_t)(mp_obj_get_int(args[4].u_obj)) == WIFI_SCAN_TYPE_PASSIVE)
14051408
{
1406-
scan_config.show_hidden = mp_obj_get_int(args[3].u_obj) >= 1;
1409+
scan_config.scan_type = WIFI_SCAN_TYPE_PASSIVE;
14071410
}
1408-
1409-
if(args[4].u_obj != mp_const_none)
1411+
else
14101412
{
1411-
if((wifi_scan_type_t)(mp_obj_get_int(args[4].u_obj)) == WIFI_SCAN_TYPE_PASSIVE)
1412-
{
1413-
scan_config.scan_type = WIFI_SCAN_TYPE_PASSIVE;
1414-
}
1415-
else
1416-
{
1417-
scan_config.scan_type = WIFI_SCAN_TYPE_ACTIVE;
1418-
}
1413+
scan_config.scan_type = WIFI_SCAN_TYPE_ACTIVE;
14191414
}
1415+
}
1416+
else if(wlan_obj.mode == WIFI_MODE_STA && !wlan_obj.disconnected)
1417+
{
1418+
scan_config< 8000 /span>.scan_type = WIFI_SCAN_TYPE_PASSIVE;
1419+
}
1420+
else
1421+
{
1422+
// Nothing
1423+
}
14201424

1421-
if(args[5].u_obj != mp_const_none)
1425+
if(args[5].u_obj != mp_const_none)
1426+
{
1427+
if(MP_OBJ_IS_TYPE(args[5].u_obj, &mp_type_tuple) && scan_config.scan_type == WIFI_SCAN_TYPE_ACTIVE)
14221428
{
1423-
if(MP_OBJ_IS_TYPE(args[5].u_obj, &mp_type_tuple) && scan_config.scan_type == WIFI_SCAN_TYPE_ACTIVE)
1424-
{
1425-
mp_obj_get_array(args[5].u_obj, &stimelen, &stime);
1429+
mp_obj_get_array(args[5].u_obj, &stimelen, &stime);
14261430

1427-
if(stimelen != 0 && stimelen <= 2)
1431+
if(stimelen != 0 && stimelen <= 2)
1432+
{
1433+
if(stimelen == 2 && scan_config.scan_type == WIFI_SCAN_TYPE_ACTIVE)
14281434
{
1429-
if(stimelen == 2 && scan_config.scan_type == WIFI_SCAN_TYPE_ACTIVE)
1430-
{
1431-
scan_config.scan_time.active.min = mp_obj_get_int(stime[0]);
1432-
scan_config.scan_time.active.max = mp_obj_get_int(stime[1]);
1433-
}
1434-
else
1435-
{
1436-
goto scan_time_err;
1437-
}
1435+
scan_config.scan_time.active.min = mp_obj_get_int(stime[0]);
1436+
scan_config.scan_time.active.max = mp_obj_get_int(stime[1]);
14381437
}
14391438
else
14401439
{
14411440
goto scan_time_err;
14421441
}
14431442
}
1444-
else if(MP_OBJ_IS_INT(args[5].u_obj) && scan_config.scan_type == WIFI_SCAN_TYPE_PASSIVE)
1443+
else
14451444
{
1446-
uint32_t passive = mp_obj_get_int(args[5].u_obj);
1445+
goto scan_time_err;
1446+
}
1447+
}
1448+
else if(MP_OBJ_IS_INT(args[5].u_obj) && scan_config.scan_type == WIFI_SCAN_TYPE_PASSIVE)
1449+
{
1450+
uint32_t passive = mp_obj_get_int(args[5].u_obj);
14471451

1448-
if(passive >= 0)
1449-
{
1450-
scan_config.scan_time.passive = mp_obj_get_int(args[5].u_obj);
1451-
}
1452-
else
1453-
{
1454-
goto scan_time_err;
1455-
}
1452+
if(passive >= 0)
1453+
{
1454+
scan_config.scan_time.passive = mp_obj_get_int(args[5].u_obj);
14561455
}
14571456
else
14581457
{
14591458
goto scan_time_err;
14601459
}
14611460
}
1462-
1463-
ptr_config = &scan_config;
1461+
else
1462+
{
1463+
goto scan_time_err;
1464+
}
14641465
}
14651466

1467+
ptr_config = &scan_config;
1468+
14661469
// check for the correct wlan mode
14671470
if (wlan_obj.mode == WIFI_MODE_AP) {
14681471
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_os_request_not_possible));

0 commit comments

Comments
 (0)
0