Part Number:CC3235S
我有一个wifi信号(ssid:NETGEAR47_5G,信道:52)
我将国家码设置成RS,并开启如下信道(36,40,44,48,52,56,60,64),可以正常连接上wifi。
此时我再将国家码设置为CN,并将信道设置为(36,40,44,48,149,153,157,161,165),断开wifi并重新连接,还是会连接上信道为52的wifi。
此时我用以下代码读取的已开启wifi信道参数为0x1f0000f,按道理说并不会连接上52信道的wifi。
并且在此之后,我再将国家码设置为ZA,并开启(36,40,44,48,100,104,108,112,116,120,124,128,132,136,140)信道,还是能连上52信道的wifi。
_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);
下面是我的部分代码,主要是test_wifi函数,在获取到ip地址后,会将test_wifi_flag设置为1,使test_wifi可以进入下一步
static int test_wifi_step = 0; int test_wifi_flag = 1; void enable_5g(_u8Enabled5GStatus)// 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); } }//重点在于这一段,其他的是设置持久化的//在这里设置国家码 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 1234 56 78910111213 141516//36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132,////1718192021 22232425 26272829//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,64ScanParamConfig5G.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); } } //重点在于这一段,其他的是设置持久化的//在这里设置wifi的扫描信道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;//第一次设置国家码为RStest_wifi_step = 1;}else if(test_wifi_step == 1){str = (_u8 *)code_2;//第一次设置国家码为CNtest_wifi_step = 2;}else{continue;}UART_PRINT("[test_wifi] config country code\r\n"); if(str[0]) { set_wifi_country_code((_u8*)str);//设置国家码 set_scan_param_5g((char*)str); //设置5Gwifi的扫描信道}UART_PRINT("[test_wifi] end config country code\r\n"); RetVal = sl_WlanProfileDel(SL_WLAN_DEL_ALL_PROFILES);//删除所有保存过的wifi信号 if (RetVal < 0) { UART_PRINT("profiledel failed\n\r"); } memset(key, 0, _KEY_LEN_SIZE_); strncpy(key, passwd, _KEY_MAX_LEN_);//添加wifi连接 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");//先关闭wifi自动连接、断开wifisl_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);//设置wifi自动连接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; }
看着像是曾经开启过的wifi信道会一直开启,但实际上并不是,因为我先将国家码以及信道设置为CN,此时可以连接上149信道的wifi;但我断开wifi并将国家码设置为JP,就连不上149信道的wifi了
Andrew lin:
希望能得到大家的回复
,
Kevin Qiu1:
AP模式在所有country code都不支持52信道
DFS channels 在AP 或 P2P GO mode都是不支持的
,
Andrew lin:
谢谢回复,但我的是sta模式
,
Kevin Qiu1:
将country code设为PK试一下
,
Andrew lin:
我的问题不是在于149信道,而是52信道。如果我在串口烧录固件之后直接设置国家码为ZA,并设置相应信道,就无法连接52信道的wifi。但是一旦我将国家码设置为RS并且连接过52信道的wifi,后面无论我再将国家码改成ZA还是CN,都可以连接上52信道的wifi了。直到我再次串口烧录程序
,
Kevin Qiu1:
看来是连接后自动将连接信息保存到flash中了,没有擦除flash前就会自动之前连接过的信道
,
Andrew lin:
我确实设置了保存到flash,但是我是每次更改国家码和信道都会写入flash,因此我设置国家码为ZA之后,根据我的信道配置是不能连接52信道的,但是他还是连接上了。
,
Andrew lin:
请问有其他人遇到类似的问题吗,是不是设置国家码的api对RS有特殊处理?
,
Kevin Qiu1:
Andrew lin 说:是不是设置国家码的api对RS有特殊处理?
没有特殊处理
有没有试过我上面说的将country code设为PK
,
Andrew lin_r:
设置为PK的确可以连接。现在我发现了更加通用的一种情况:串口烧录之后,设置国家码为CN,此时可以连接149信道。再将国家码设置为US,并且禁用149信道,还是可以连接上149的wifi。
,
Kevin Qiu1:
将country code设为PK之前的52信道还能连接吗
,
Andrew lin_r:
我还以为你说的设置为PK是连接149信道,连接52信道的话是失败的
,
Kevin Qiu1:
可能是因为PK没有DFS,52信道不在它的列表中,所以连接失败
你设置的其他country code都在DFS中包含了52信道,只要之前连接了52信道 ,之后将启用该信道
我看你已经在英文论坛发了帖子,我将关闭这个帖子,之后关注英文论坛Kobi的回复