[BugFix][API-810][wifi]fix wifi can't change country code
Change-Id: I95597b53937890b0619299e8e2bfe0cc92d97aae
diff --git a/lib/liblynq-wifi6/libwifi6.c b/lib/liblynq-wifi6/libwifi6.c
index 4a3c6c9..e529fd5 100755
--- a/lib/liblynq-wifi6/libwifi6.c
+++ b/lib/liblynq-wifi6/libwifi6.c
@@ -3472,28 +3472,78 @@
return 0;
}
-int lynq_set_country_code(lynq_wifi_index_e idx, char * country_code) {
-// const char * cmd_str = "GET country";
-// CHECK_IDX(idx, CTRL_AP);
-// CHECK_WPA_CTRL(CTRL_STA);
+static int check_and_init_uci_config(char * country_code)
+{
+ FILE * fp;
+ int is_different = 0;
+ const char * creat_uci_cmd ="uci set lynq_uci.lynq_wifi_country_code='lynq_wifi_country_code'";
+ const char * commit_cmd ="uci commit";
+ char set_country_cmd[MAX_CMD];
+ char lynq_cmd_ret[MAX_CMD]={0};
-// DO_REQUEST(cmd_str);
-// printf("result %s\n", cmd_reply);
-
- if (country_code == NULL || *country_code == '\0')
+ if((fp=popen("uci get lynq_uci.lynq_wifi_country_code.code","r"))==NULL)
{
- RLOGD("bad country code\n");
+ RLOGE("popen error!,create now");
+
+ system(creat_uci_cmd);
+ sprintf(set_country_cmd, "uci set lynq_uci.lynq_wifi_country_code.code='%s'",country_code);
+ system(set_country_cmd);
+ system(commit_cmd);
+ is_different = 1;
+
+ if((fp=popen("uci get lynq_uci.lynq_wifi_country_code.code","r"))==NULL)
+ {
+ return -1;
+ }
+ }
+
+ if((fread(lynq_cmd_ret,sizeof(lynq_cmd_ret),1,fp))<0 )
+ {
+ RLOGE("fread fail!");
+ fclose(fp);
return -1;
}
- char lynq_country_cmd[MAX_CMD];
- sprintf(lynq_country_cmd, "wl country %s", country_code);
- if (system(lynq_country_cmd) == 0)
+ if ( strncmp(lynq_cmd_ret,country_code,2) != 0 )
{
- return 0;
+ RLOGE("get country code for uci %s,input cpuntry code is:%s\n",lynq_cmd_ret,country_code);
+ is_different = 1;
}
- return -1;
+ fclose(fp);
+ return is_different;
+
+}
+
+int lynq_set_country_code(lynq_wifi_index_e idx, char * country_code) {
+ char check_current_code[10];
+ int ret,is_different;
+
+ if (country_code == NULL || *country_code == '\0')
+ {
+ RLOGE("bad country code\n");
+ return -1;
+ }
+
+ is_different = check_and_init_uci_config(country_code);
+ if( is_different < 0 )
+ {
+ RLOGE("init set uci fail\n");
+ return -1;
+ }
+
+ ret = lynq_get_country_code(idx,check_current_code);
+ if( ret == 0 && (is_different == 1 || strcmp(check_current_code, country_code) != 0))
+ {
+ ret = lynq_wifi_disable();
+ if(ret != 0 )
+ {
+ RLOGE("berfore set country,find bcmdhd insmod,remod fail\n");
+ return -1;
+ }
+ }
+
+ return 0;
}
int lynq_get_connect_ap_mac(lynq_wifi_index_e idx,char *mac)