[BugFix][API-1295 1296 1302]fix get error password from wpa_supplicant.config file
Affected branch:MR3.0-xx && GSW3.0
Affected module:wifi
Is it addected on both ZXIC and MTK: only MTK
Self-test: Yes
Doc Update: No
Change-Id: If21a220bd2aad147ca387c200ad2ccf9f90b9ebd
diff --git a/lib/liblynq-wifi6/libwifi6.c b/lib/liblynq-wifi6/libwifi6.c
index 5f02cff..6802432 100755
--- a/lib/liblynq-wifi6/libwifi6.c
+++ b/lib/liblynq-wifi6/libwifi6.c
@@ -776,7 +776,7 @@
CHECK_WPA_CTRL(CTRL_STA);
sprintf(LYNQ_DISABLE_CMD,"DISABLE_NETWORK %d",networkid);
- RLOGD("LYNQ_DISABLE_CMD is:%d\n",LYNQ_DISABLE_CMD);
+ RLOGD("LYNQ_DISABLE_CMD is:%s\n",LYNQ_DISABLE_CMD);
DO_OK_FAIL_REQUEST(LYNQ_DISABLE_CMD);
return 0;
@@ -792,7 +792,7 @@
sprintf(LYNQ_ENABLE_CMD,"ENABLE_NETWORK %d",networkid);
- RLOGD("LYNQ_ENABLE_CMD is:%d\n",LYNQ_ENABLE_CMD);
+ RLOGD("LYNQ_ENABLE_CMD is:%s\n",LYNQ_ENABLE_CMD);
DO_OK_FAIL_REQUEST(LYNQ_ENABLE_CMD);
return 0;
@@ -2943,20 +2943,199 @@
return 0;
}
+/**
+* buff data
+* buff_len size of buff
+* idx sta
+* *ap ap info for find ssid && password
+* password return password
+*
+*/
+static int lynq_sta_ssid_password_auth_get(char * buff,int buff_len,lynq_wifi_index_e idx, ap_info_s *ap,char *password) { // @todo
+
+ int ret, network_len, i, ssid_len,curr_auth;
+ int count, index,org_index;
+ char *split_lines[128] = {0};
+ char *p, *ssid, *ssid_end_flag,*ptr;
+ char tmp_ssid[128]={0};
+ char tmp_auth[24]={0};
+
+ org_index = 0;
+ network_len = 0;
+ p = NULL;
+
+ CHECK_IDX(idx, CTRL_STA);
+
+ while(1){
+ network_len = 0;
+ p == NULL;
+ for(; org_index < buff_len; org_index ++)
+ {
+ for(; org_index < buff_len; org_index ++)
+ {
+ if (memcmp(buff + org_index, "network={", 9) != 0)
+ {
+ continue;
+ }
+ p = buff + org_index + 9;
+
+ for (; org_index < buff_len; org_index ++ )
+ {
+ if (buff[org_index] != '}')
+ {
+ continue;
+ }
+ buff[org_index] = '\0';
+ break;
+ }
+ network_len = buff + org_index - p;
+ break;
+ }
+
+ if (p == NULL)
+ {
+ RLOGD("not find dest info %s(),line %dERROR",__func__,__LINE__);
+ return -1;
+ }
+
+ ssid = strstr(p, "ssid=");
+ if (ssid != NULL) {
+ ssid += strlen("ssid=");
+ if (ssid[0] == '\"')
+ {
+ if (memcmp(ssid + 1, ap->ap_ssid, strlen(ap->ap_ssid)) == 0 && ssid[strlen(ap->ap_ssid) + 1] == '\"')
+ {
+ RLOGD("-----curr_get ssid form config is %s",ssid);
+ break;
+ }
+ RLOGD("-----countine to find dest ssid %s ---curr_get ssid from config is %s",ap->ap_ssid,ssid);
+ }
+ else
+ {
+ ssid_end_flag = strstr(ssid, "\n");
+ if (ssid_end_flag != NULL)
+ {
+ ssid_len = (ssid_end_flag - ssid) / 2;
+ for(i=0; i<ssid_len; i++)
+ {
+ tmp_ssid[i] = inner_convert_char(ssid[i*2]) << 4 | inner_convert_char(ssid[i*2 + 1]);
+ }
+ if (memcmp(tmp_ssid, ap->ap_ssid, ssid_len) == 0)
+ {
+ RLOGD("curr_ssid is(from config) ---- %s ap_info ssid --->",tmp_ssid,ap->ap_ssid);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ if (org_index >= buff_len || NULL == p || network_len <= 0)
+ {
+
+ if (buff != NULL)
+ RLOGD("not find dest ssid %s(),line %dERROR",__func__,__LINE__);
+ return -1;
+ }
+
+ count = lynq_split(p, network_len, '\n', split_lines);
+ ret = -1;
+ for( index=0; index < count; index++ )
+ {
+ p = strstr(split_lines[index], "key_mgmt=");
+ RLOGD("current p str ------- %s",p);
+ if(p != NULL)
+ {
+ p += 9;
+ if(memcmp(p,"SAE",3) == 0)
+ {
+ curr_auth = 5;
+ }else if(memcmp(p,"WPA-PSK SAE",11) == 0)
+ {
+ curr_auth = 4;
+ }else if(memcmp(p,"WPA-PSK",7) == 0 )
+ {
+ curr_auth = 3;
+ }else if(memcmp(p,"NONE",4) == 0 )
+ {
+ curr_auth = 0;
+ }else{
+ curr_auth = 1;
+ }
+ RLOGD("************curret_get_auth is %d ssid is %s",curr_auth,ap->ap_ssid);
+ if( curr_auth < 1 || curr_auth > 6)
+ {
+ ret = -1;
+ }
+ break;
+ }
+ }
+ if( curr_auth == 0)
+ {
+ return 0;
+ }else if(curr_auth == ap->auth || ap->auth <= 3 && curr_auth <= 3 && curr_auth != -1 )
+ {
+ for(index=0; index < count; index++)
+ {
+ /*get psw info*/
+
+ p = strstr(split_lines[index], "psk=");
+ if (p != NULL)
+ {
+ p += 4;
+ if (*p == '\"')
+ {
+ p++;
+ }
+ }
+ else if (NULL != (p = strstr(split_lines[index], "wep_key0=")))
+ {
+ p += 9;
+ if (*p == '\"')
+ {
+ p++;
+ }
+ }
+ else
+ {
+ continue;
+ }
+
+ if (*p == '\"')
+ p++;
+ strncpy(password, p, 64);
+ p = password;
+ while(password - p < 64 && *password != '\0')
+ {
+ if (*password == '\"')
+ {
+ *password = '\0';
+ RLOGD("---------password------- p:: %s",p);
+ ret = 0;
+ break;
+ }
+ password++;
+ }
+ break;
+ }
+ break;
+ }
+ }
+
+ return ret;
+}
+
+
+
int lynq_sta_ssid_password_get(lynq_wifi_index_e idx, ap_info_s *ap, char *password) { // @todo
FILE * fp;
- int len, ret, network_len, i, ssid_len;
- int count, index;
- char *split_lines[128] = {0};
- char *buff, *p, *ssid, *ssid_end_flag;
- char tmp_ssid[128]={0};
+ int len, ret;
+ char *info_buff;
RLOGD("enter lynq_sta_ssid_password_get");
- network_len = 0;
- p = NULL;
- buff = NULL;
-
+ info_buff = NULL;
CHECK_IDX(idx, CTRL_STA);
if (NULL == password)
@@ -2974,138 +3153,35 @@
fseek(fp, 0, SEEK_END);
len = ftell(fp);
- buff = malloc(len + 1);
+ info_buff = malloc(len + 1);
- if (buff == NULL)
+ if (info_buff == NULL)
{
RLOGE("[lynq_sta_ssid_password_get] malloc memory [%d] fail\n", len);
return -1;
}
fseek(fp, 0, SEEK_SET);
- len = fread(buff, 1, len, fp);
+ len = fread(info_buff, 1, len, fp);
fclose(fp);
- for(index=0; index < len; index ++)
+
+ ret= lynq_sta_ssid_password_auth_get(info_buff,len,0, ap,password);
+
+ if(ret == 0)
{
- for(; index < len; index ++)
- {
- if (memcmp(buff + index, "network={", 9) != 0)
- {
- continue;
- }
- p = buff + index + 9;
- for (; index < len; index ++ )
- {
- if (buff[index] != '}')
- {
- continue;
- }
- buff[index] = '\0';
- break;
- }
- network_len = buff + index - p;
- break;
- }
-
- if (p == NULL)
- {
- if (buff != NULL)
- {
- free(buff);
- }
-
- return -1;
- }
-
- ssid = strstr(p, "ssid=");
- if (ssid != NULL) {
- ssid += strlen("ssid=");
- if (ssid[0] == '\"')
- {
- if (memcmp(ssid + 1, ap->ap_ssid, strlen(ap->ap_ssid)) == 0 && ssid[strlen(ap->ap_ssid) + 1] == '\"')
- break;
- }
- else
- {
- ssid_end_flag = strstr(ssid, "\n");
- if (ssid_end_flag != NULL)
- {
- ssid_len = (ssid_end_flag - ssid) / 2;
- for(i=0; i<ssid_len; i++)
- {
- tmp_ssid[i] = inner_convert_char(ssid[i*2]) << 4 | inner_convert_char(ssid[i*2 + 1]);
- }
- if (memcmp(tmp_ssid, ap->ap_ssid, ssid_len) == 0)
- break;
- }
- }
- }
-
+ RLOGD("lynq_sta_ssid_password_auth_get pass return ssid :%s psw is %s",ap->ap_ssid,password);
+ free(info_buff);
+ return 0;
}
-
- if (index >= len || NULL == p || network_len <= 0)
- {
- if (buff != NULL)
- {
- free(buff);
- }
+ else{
+ free(info_buff);
return -1;
}
- count = lynq_split(p, network_len, '\n', split_lines);
-
- ret = -1;
- for(index=0; index < count; index++)
- {
- p = strstr(split_lines[index], "psk=");
- if (p != NULL)
- {
- p += 4;
- if (*p == '\"')
- {
- p++;
- }
- }
- else if (NULL != (p = strstr(split_lines[index], "wep_key0=")))
- {
- p += 9;
- if (*p == '\"')
- {
- p++;
- }
- }
- else
- {
- continue;
- }
-
- if (*p == '\"')
- p++;
- strncpy(password, p, 64);
-
- p = password;
- while(password - p < 64 && *password != '\0')
- {
- if (*password == '\"')
- {
- *password = '\0';
- break;
- }
- password++;
- }
- ret = 0;
- break;
- } //end for(index=0; index < count; index++)
-
- if (buff != NULL)
- {
- free(buff);
- }
-
- return ret;
}
+
static int inner_set_sta_ssid(int net_no, char *sta_ssid)
{
char lynq_wifi_ssid_cmd[80]={0};