|
|
@@ -6,6 +6,7 @@
|
|
|
#include <sys/stat.h>
|
|
|
#include <unistd.h>
|
|
|
#include "elog.h"
|
|
|
+#include "string.h"
|
|
|
|
|
|
|
|
|
|
|
|
@@ -60,16 +61,87 @@ static int check_file(const char * path)
|
|
|
}
|
|
|
return FILE_OK;
|
|
|
}
|
|
|
-
|
|
|
+static void clear_ch(char *buff,int lenth,char ch)
|
|
|
+{
|
|
|
+ for(int i= 0; i < lenth;i++)
|
|
|
+ {
|
|
|
+ if(buff[i] == ch)
|
|
|
+ {
|
|
|
+ buff[i] = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
|
|
|
static void radius_get_config(char *buff,radius_config_t *radius)
|
|
|
{
|
|
|
|
|
|
+ char temp[64] = {0};
|
|
|
+ ////get ap_scan=
|
|
|
+ char *p_str = strstr(buff,"ap_scan=");
|
|
|
+ char *p_endle = strchr(p_str,'\n');
|
|
|
+ p_str +=8;
|
|
|
+ memcpy(temp,p_str,p_endle-p_str);
|
|
|
+ radius->ap_scan = atoi(temp);
|
|
|
|
|
|
+ //get key_mgmt
|
|
|
+ memset(temp,0,64);
|
|
|
+ p_str = strstr(buff,"key_mgmt=");
|
|
|
+ p_endle = strchr(p_str,'\n');
|
|
|
+ p_str +=9;
|
|
|
+ memcpy(temp,p_str,p_endle-p_str);
|
|
|
+ memcpy(radius->key_mgmt,temp,p_endle-p_str);
|
|
|
+
|
|
|
+ //get eap
|
|
|
+ memset(temp,0,64);
|
|
|
+ p_str = strstr(buff,"eap=");
|
|
|
+ p_endle = strchr(p_str,'\n');
|
|
|
+ p_str +=4;
|
|
|
+ memcpy(temp,p_str,p_endle-p_str);
|
|
|
+ memcpy(radius->eap,temp,p_endle-p_str);
|
|
|
+
|
|
|
+ //get user
|
|
|
+ memset(temp,0,64);
|
|
|
+ p_str = strstr(buff,"identity=\"");
|
|
|
+ p_endle = strchr(p_str,'\n');
|
|
|
+ p_str +=10;
|
|
|
|
|
|
+ memcpy(temp,p_str,p_endle-p_str);
|
|
|
+ clear_ch(temp,64,'\"');
|
|
|
|
|
|
+ memcpy(radius->user,temp,p_endle-p_str);
|
|
|
|
|
|
+ //get password
|
|
|
+ memset(temp,0,64);
|
|
|
+ p_str = strstr(buff,"password=\"");
|
|
|
+ p_endle = strchr(p_str,'\n');
|
|
|
+
|
|
|
+ p_str +=10;
|
|
|
+ memcpy(temp,p_str,p_endle-p_str);
|
|
|
+ clear_ch(temp,64,'\"');
|
|
|
+ memcpy(radius->password,temp,p_endle-p_str);
|
|
|
+
|
|
|
+
|
|
|
+ ////get peaplabel
|
|
|
+ memset(temp,0,64);
|
|
|
+ p_str = strstr(buff,"peaplabel=");
|
|
|
+ p_endle = strchr(p_str,'\n');
|
|
|
+
|
|
|
+ p_str +=10;
|
|
|
+
|
|
|
+ memcpy(temp,p_str,p_endle-p_str);
|
|
|
+ clear_ch(temp,64,'\"');
|
|
|
+ radius->peaplable = atoi(temp);
|
|
|
+
|
|
|
+ //get auth
|
|
|
+ memset(temp,0,64);
|
|
|
+ p_str = strstr(buff,"auth=");
|
|
|
+ p_endle = strchr(p_str,'\n');
|
|
|
+
|
|
|
+ p_str +=5;
|
|
|
+ memcpy(temp,p_str,p_endle-p_str);
|
|
|
+ clear_ch(temp,64,'\"');
|
|
|
+ memcpy(radius->auth,temp,p_endle-p_str);
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -95,6 +167,8 @@ int radius_init()
|
|
|
//检查文件
|
|
|
int fd = 0;
|
|
|
char temp[1024] = {0};
|
|
|
+
|
|
|
+ radius.status = misc->radius;
|
|
|
int ret = check_file(RADIUS_CONF);
|
|
|
if(FILE_OK != ret)
|
|
|
{
|
|
|
@@ -109,7 +183,6 @@ int radius_init()
|
|
|
int size = write(fd,temp,strlen(temp));
|
|
|
close (fd);
|
|
|
sync();
|
|
|
-
|
|
|
}
|
|
|
if(misc->radius == 0)
|
|
|
{
|
|
|
@@ -117,11 +190,115 @@ int radius_init()
|
|
|
goto failed;
|
|
|
}
|
|
|
fd = open(RADIUS_CONF,O_RDONLY,0777);
|
|
|
+ if(fd < 0)
|
|
|
+ {
|
|
|
+ LOGE("radius open conf failed!!\n");
|
|
|
+ goto failed;
|
|
|
+ }
|
|
|
+ int size = read(fd,temp,1024);
|
|
|
+
|
|
|
+ close(fd);
|
|
|
|
|
|
+ radius_get_config(temp,&radius);
|
|
|
+ ////////////////////////////////////////////////////////////////
|
|
|
|
|
|
+ memset(temp,0,1024);
|
|
|
|
|
|
+ sprintf(temp,"wpa_supplicant -i eth0 -c %s -D wired -B",RADIUS_CONF);
|
|
|
+
|
|
|
+ ret = system(temp);
|
|
|
+ if(ret)
|
|
|
+ {
|
|
|
+ LOGE("radius init failed!!\n");
|
|
|
+ }
|
|
|
return 0;
|
|
|
|
|
|
failed:
|
|
|
return -1;
|
|
|
-}
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+int radius_deinit()
|
|
|
+{
|
|
|
+ FILE *fp;
|
|
|
+ int pid=0;
|
|
|
+ char buf[20]={0};
|
|
|
+ char command[200];
|
|
|
+
|
|
|
+ snprintf(command, sizeof(command), "ps -ef | grep -v grep | grep -w -c %s", "wpa_supplicant");
|
|
|
+
|
|
|
+ fp = popen(command, "r");
|
|
|
+ if (fp == NULL) {
|
|
|
+ LOGE("execute %s failed: %s", command, strerror(errno));
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (fgets(buf, sizeof(buf), fp)) {
|
|
|
+ pid = atoi(buf);
|
|
|
+ }
|
|
|
+ pclose(fp);
|
|
|
+ if(pid)
|
|
|
+ {
|
|
|
+ #if (CHIP_TYPE == CHIP_T113i)
|
|
|
+ system("killall wpa_supplicant");
|
|
|
+ #endif
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+int radius_config(radius_config_t* cfg)
|
|
|
+{
|
|
|
+ MiscInfo_t *misc=get_misc();
|
|
|
+ radius.status = cfg->status;
|
|
|
+ paras_save();
|
|
|
+
|
|
|
+ if(cfg->status == 0)
|
|
|
+ {
|
|
|
+ system("killall wpa_supplicant");
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(memcmp(cfg->user,&radius.user,sizeof(radius.user)) != 0 || memcmp(cfg->password,&radius.password,sizeof(radius.password)) != 0 )
|
|
|
+ {
|
|
|
+ char temp[1024];
|
|
|
+ memset(radius.user,0,sizeof(radius.user));
|
|
|
+ memset(radius.password,0,sizeof(radius.password));
|
|
|
+
|
|
|
+ memcpy(radius.user,cfg->user,strlen(cfg->user));
|
|
|
+ memcpy(radius.password,cfg->password,strlen(cfg->password));
|
|
|
+
|
|
|
+ sprintf(temp,CONFIG_FILE,radius.ap_scan,
|
|
|
+ radius.key_mgmt,radius.eap,radius.user,radius.password,radius.peaplable,radius.auth);
|
|
|
+ int fd = open(RADIUS_CONF,O_CREAT|O_TRUNC|O_RDWR,0777);
|
|
|
+ if(fd < 0)
|
|
|
+ {
|
|
|
+ LOGE("radius create conf failed!!\n");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ int size = write(fd,temp,strlen(temp));
|
|
|
+ close (fd);
|
|
|
+ sync();
|
|
|
+
|
|
|
+ //kill
|
|
|
+ #if (CHIP_TYPE == CHIP_T113i)
|
|
|
+ system("killall wpa_supplicant");
|
|
|
+ sleep(2);
|
|
|
+ memset(temp,0,1024);
|
|
|
+
|
|
|
+ sprintf(temp,"wpa_supplicant -i eth0 -c %s -D wired -B",RADIUS_CONF);
|
|
|
+ int ret = system(temp);
|
|
|
+ if(ret)
|
|
|
+ {
|
|
|
+ LOGE("radius init failed!!\n");
|
|
|
+ }
|
|
|
+ #endif
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+radius_config_t radius_get()
|
|
|
+{
|
|
|
+ return radius;
|
|
|
+}
|