I have a wifi signal (SSID: NETGEAR47_5G, channel: 52)
I set the country code to RS, and open the following channels (36,40,44,48,52,56,60,64). Wifi can be connected normally.
At this time I'll set the country code for CN, and set the channel to 36,40,44,48,149,153,157,161,165 , disconnect the wifi and reconnect. Still got wi-fi on channel 52.
At this time, I read the enabled wifi channel parameter 0x1F0000F with the following code, which is not supposed to connect to the wifi channel 52.
And after that, I'll set the country code for ZA,and open channel(36,40,44,48,100,104,108,112,116,120,124,128,132,136,140). Still got wi-fi on channel 52.
_u16 Option = SL_WLAN_GENERAL_PARAM_OPT_SCAN_PARAMS_5G; _u16 OptionLen = sizeof(SlWlanScanParam5GCommand_t); sl_WlanGet(SL_WLAN_CFG_GENERAL_PARAM_ID, &Option, &OptionLen, (_u8 *)&cur_ScanParamConfig5G);
The following is part of my code, mainly test_wifi function, after getting the IP address, will test_wifi_flag set to 1, so that test_wifi can enter the next step
static int test_wifi_step = 0; int test_wifi_flag = 1; void enable_5g(_u8 Enabled5GStatus)// 0 disable 1 enable { _u16 Option = SL_WLAN_GENERAL_PARAM_OPT_ENABLE_5G; _u16 OptionLen = sizeof(_u8); sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, Option, OptionLen, (_u8 *)&Enabled5GStatus); } int set_wifi_country_code(_u8 *str) { int32_t RetVal; _u8 configOpt = SL_DEVICE_GENERAL_PERSISTENT; _u16 plen=1; _u8 persistent = 0; unsigned char country_code[5]; unsigned short config_len = 5; unsigned short configopt = SL_WLAN_GENERAL_PARAM_OPT_COUNTRY_CODE; RetVal = sl_WlanGet(SL_WLAN_CFG_GENERAL_PARAM_ID, &configopt, &config_len, country_code); UART_PRINT("sl_WlanGet ret_val:%d config_len:%d country_code:%s\r\n", RetVal, config_len, country_code); if (RetVal < 0 || (strcmp((char *)str, (char *)country_code) != 0)) { RetVal = sl_DeviceGet(SL_DEVICE_GENERAL, &configOpt, &plen, (_u8*)(&persistent)); if(RetVal < 0) { UART_PRINT("sl_DeviceGet failed, RetVal = %d\n\r", RetVal); } if(persistent != 1) { persistent = 1; RetVal = sl_DeviceSet(SL_DEVICE_GENERAL, SL_DEVICE_GENERAL_PERSISTENT, 1, (_u8*)(&persistent)); if(RetVal < 0) { UART_PRINT("sl_DeviceSet failed, RetVal = %d\n\r", RetVal); } } //*********Set the country code here************ RetVal = sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, SL_WLAN_GENERAL_PARAM_OPT_COUNTRY_CODE, 2, str); if (RetVal < 0) { UART_PRINT("sl_WlanSet country_code %s failed, RetVal = %d\n\r",str, RetVal); } else { UART_PRINT("sl_WlanSet country_code success, RetVal = %d, country code:%s\n\r", RetVal, str); } RetVal = sl_DeviceGet(SL_DEVICE_GENERAL, &configOpt, &plen, (_u8*)(&persistent)); if(RetVal < 0) { UART_PRINT("sl_DeviceGet failed, RetVal = %d\n\r", RetVal); } if(persistent != 0) { persistent = 0; RetVal = sl_DeviceSet(SL_DEVICE_GENERAL, SL_DEVICE_GENERAL_PERSISTENT, 1, (_u8*)(&persistent)); if(RetVal < 0) { UART_PRINT("sl_DeviceSet failed, RetVal = %d\n\r", RetVal); } } } return 0; } void set_scan_param_5g(const char *contrycode) { SlWlanScanParam5GCommand_t ScanParamConfig5G,cur_ScanParamConfig5G; _u16 Option = SL_WLAN_GENERAL_PARAM_OPT_SCAN_PARAMS_5G; _u16 OptionLen = sizeof(SlWlanScanParam5GCommand_t); int ret_val; _u8 configOpt = SL_DEVICE_GENERAL_PERSISTENT; _u16 plen=1; _u8 persistent = 0; // 5.0G channels bits order: // // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 //36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, // //17 18 19 20 21 22 23 24 25 26 27 28 29 //136, 140, 144, 149, 153, 157, 161, 165, 169, 184, 188, 192, 196 if(strcmp(contrycode,"RS")==0) { //enable: 36,40,44,48,52,56,60,64 ScanParamConfig5G.ChannelsMask = (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7); }else if(strcmp(contrycode,"ZA")==0) { //disable: 52,56,60,64 ScanParamConfig5G.ChannelsMask = 0x0007ffff; //禁用140以上的信道,不包括140 ScanParamConfig5G.ChannelsMask &= ~((1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)); }else if(strcmp(contrycode,"NO")==0) { //enable: 36, 40, 44, 48 ScanParamConfig5G.ChannelsMask = (1<<0)|(1<<1)|(1<<2)|(1<<3); }else if(strcmp(contrycode,"JP")==0) { //enable: 36,40,44,48,184,188,192,196 ScanParamConfig5G.ChannelsMask = (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<26)|(1<<27)|(1<<28)|(1<<29); } else if(strcmp(contrycode,"00")!=0) { //enable: 36, 40, 44, 48, 149, 153, 157, 161, 165 ScanParamConfig5G.ChannelsMask = (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<20)|(1<<21)|(1<<22)|(1<<23)|(1<<24); }else { ScanParamConfig5G.ChannelsMask = 0xffffffff; } ScanParamConfig5G.RssiThreshold = -95; ret_val = sl_WlanGet(SL_WLAN_CFG_GENERAL_PARAM_ID, &Option, &OptionLen, (_u8 *)&cur_ScanParamConfig5G); if(ret_val < 0) { UART_PRINT("set_scan_param_5g error ret_val = %d\n\r", ret_val); return; } UART_PRINT("cur_ScanParamConfig5G.ChannelsMask = 0x%x, ScanParamConfig5G.ChannelsMask = 0x%x\n\r", cur_ScanParamConfig5G.ChannelsMask, ScanParamConfig5G.ChannelsMask); if(cur_ScanParamConfig5G.ChannelsMask != ScanParamConfig5G.ChannelsMask) { ret_val = sl_DeviceGet(SL_DEVICE_GENERAL, &configOpt, &plen, (_u8*)(&persistent)); if(ret_val < 0) { UART_PRINT("sl_DeviceGet failed, RetVal = %d\n\r", ret_val); } if(persistent != 1) { persistent = 1; ret_val = sl_DeviceSet(SL_DEVICE_GENERAL, SL_DEVICE_GENERAL_PERSISTENT, 1, (_u8*)(&persistent)); if(ret_val < 0) { UART_PRINT("sl_DeviceSet failed, RetVal = %d\n\r", ret_val); } } //*********Set the wifi channel here*********** ret_val = sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, Option, OptionLen, (_u8 *)&ScanParamConfig5G); if(ret_val < 0) { UART_PRINT("set_scan_param_5g error ret_val = %d\n\r", ret_val); } ret_val = sl_DeviceGet(SL_DEVICE_GENERAL, &configOpt, &plen, (_u8*)(&persistent)); if(ret_val < 0) { UART_PRINT("sl_DeviceGet failed, RetVal = %d\n\r", ret_val); } if(persistent != 0) { persistent = 0; ret_val = sl_DeviceSet(SL_DEVICE_GENERAL, SL_DEVICE_GENERAL_PERSISTENT, 1, (_u8*)(&persistent)); if(ret_val < 0) { UART_PRINT("sl_DeviceSet failed, RetVal = %d\n\r", ret_val); } } UART_PRINT("change ChannelsMask success\n\r"); } } int test_wifi() { SlWlanSecParams_t secParams; int32_t RetVal; _u8 *str; unsigned char policy_val = 0; unsigned char connect_policy = 0; unsigned char connect_policy_len = 1; static char key[_KEY_LEN_SIZE_]; char code_1[] = "RS",code_2[] = "CN"; char ssid[] = "NETGEAR47-5G"; char passwd[] = "wideteapot110"; enable_5g(1); for(;;){ check_watchdog(); if (test_wifi_flag) { UART_PRINT("[test_wifi] flag = %d,step = %d\r\n",test_wifi_flag,test_wifi_step); test_wifi_flag = 0; if(test_wifi_step == 0){ str = (_u8 *)code_1; //step1:set country code to RS test_wifi_step = 1; }else if(test_wifi_step == 1){ str = (_u8 *)code_2; //step2:set country code to CN test_wifi_step = 2; }else{ continue; } UART_PRINT("[test_wifi] config country code\r\n"); if(str[0]) { set_wifi_country_code((_u8*)str); //set country code set_scan_param_5g((char*)str); //set 5Ghz wifi channel } UART_PRINT("[test_wifi] end config country code\r\n"); RetVal = sl_WlanProfileDel(SL_WLAN_DEL_ALL_PROFILES); //Delete all wifi connections if (RetVal < 0) { UART_PRINT("profiledel failed\n\r"); } memset(key, 0, _KEY_LEN_SIZE_); strncpy(key, passwd, _KEY_MAX_LEN_); //add wifi connection memset(&secParams, 0, sizeof(SlWlanSecParams_t)); secParams.Key = (signed char *)key; secParams.KeyLen = strlen((char const *)key); secParams.Type = SL_WLAN_SEC_TYPE_WPA_WPA2; RetVal = sl_WlanProfileAdd((signed char const *)ssid, strlen((char *)ssid), 0, &secParams, 0, 1, 0); if (RetVal < 0) { UART_PRINT("sl_WlanProfileAdd(SL_SEC_TYPE_WPA_WPA2) failed,error code=%d\n\r", RetVal); } UART_PRINT("[test_wifi] disconnect wifi\r\n"); //close auto connect,Disconnect the wifi sl_WlanPolicySet(SL_WLAN_POLICY_CONNECTION, SL_WLAN_CONNECTION_POLICY(0, 0, 0, 0),NULL,0); sl_WlanDisconnect(); for(int i=0;i<5;i++){ msleep(500); } sl_Stop(0); sl_Start(NULL,NULL,NULL); //set wifi auto connection sl_WlanPolicyGet(SL_WLAN_POLICY_CONNECTION, &connect_policy,NULL, &connect_policy_len); UART_PRINT("[test_wifi] get policy:%d\r\n",connect_policy); if ((RetVal < 0) || (connect_policy != SL_WLAN_CONNECTION_POLICY(1, 0, 0, 0))) { UART_PRINT("[test_wifi] set auto connect\r\n"); /**/ connect_policy = SL_WLAN_CONNECTION_POLICY(1, 0, 0, 0); if (sl_WlanPolicySet(SL_WLAN_POLICY_CONNECTION, connect_policy, &policy_val, 1) < 0) { UART_PRINT("sl_WlanPolicySet failed\n\r"); } } UART_PRINT("[test_wifi] end config\r\n"); } } return 0; }
It looks like the wifi channel that was opened will always be open, but in fact it is not, because I set the country code and channel to CN first, and then I can connect to the wifi of channel 149. But WHEN I disconnect wifi and set the country code to JP, I can't connect to wifi on channel 149