parent
c5a00823a5
commit
71c642a4f9
|
@ -35,6 +35,10 @@
|
|||
/*static routing*/
|
||||
#define STATIC_ROUTING_CONFIG_MODULE 0x00000009
|
||||
|
||||
/*4G config*/
|
||||
#define LTE_CONFIG_MODULE 0x00000007
|
||||
|
||||
|
||||
/************************* 模块定义结束 **********************/
|
||||
|
||||
/************************ config id定义 **********************/
|
||||
|
@ -74,6 +78,8 @@
|
|||
|
||||
#define STATIC_ROUTING_CONFIG (uint64)((uint64)STATIC_ROUTING_CONFIG_MODULE<<32|1)
|
||||
#define GET_ALL_ROUTING_INFO (uint64)((uint64)STATIC_ROUTING_CONFIG_MODULE<<32|2)
|
||||
|
||||
#define LTE_CONFIG (uint64)((uint64)LTE_CONFIG_MODULE<<32|1)
|
||||
/************************ config id定义 end**********************/
|
||||
|
||||
#endif
|
||||
|
|
|
@ -33,7 +33,6 @@ typedef unsigned int ret_code;
|
|||
/* NETCONFIG_MODULE 0x00010000 ~ 0x0001ffff*/
|
||||
#define RET_IPINVALID (unsigned int)((unsigned int)NETCONFIG_MODULE<<16|1)
|
||||
#define RET_BRNAMEERR (unsigned int)((unsigned int)NETCONFIG_MODULE<<16|2)
|
||||
#define RET_NETMASKERR (unsigned int)((unsigned int)NETCONFIG_MODULE<<16|3)
|
||||
|
||||
/* VLANCONFIG_MODULE 0x00050000 ~ 0x0005ffff*/
|
||||
#define RET_VIDNUM_INVALID (unsigned int)((unsigned int)VLAN_CONFIG_MODULE<<16|1)
|
||||
|
@ -59,6 +58,18 @@ typedef unsigned int ret_code;
|
|||
#define RET_GATEWAY_ERR (unsigned int)((unsigned int)STATIC_ROUTING_CONFIG_MODULE<<16|9)
|
||||
#define RET_GW_DEV_ERR (unsigned int)((unsigned int)STATIC_ROUTING_CONFIG_MODULE<<16|10)
|
||||
|
||||
/* LTE_CONFIG_MODULE 0x00100000 ~ 0x0010ffff*/
|
||||
#define RET_EXEC_SHELL_ERR (unsigned int)((unsigned int)LTE_CONFIG_MODULE<<16|1)
|
||||
#define RET_NULL_INPUT_ERR (unsigned int)((unsigned int)LTE_CONFIG_MODULE<<16|2)
|
||||
#define RET_LTE_NO_MATCH_ERR (unsigned int)((unsigned int)LTE_CONFIG_MODULE<<16|3)
|
||||
#define RET_NO_LTE_MODULE_ERR (unsigned int)((unsigned int)LTE_CONFIG_MODULE<<16|4)
|
||||
#define RET_ALREADY_START_ERR (unsigned int)((unsigned int)LTE_CONFIG_MODULE<<16|5)
|
||||
#define RET_ALREADY_STOP_ERR (unsigned int)((unsigned int)LTE_CONFIG_MODULE<<16|6)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define ERR_STR_LEN 64
|
||||
|
||||
/* 错误码描述 */
|
||||
|
@ -84,7 +95,6 @@ typedef unsigned int ret_code;
|
|||
\
|
||||
{ RET_IPINVALID, "IpInvalid"},\
|
||||
{ RET_BRNAMEERR, "BrNameInvalid"},\
|
||||
{ RET_NETMASKERR, "NetMaskInvalid"},\
|
||||
\
|
||||
{ RET_VIDNUM_INVALID, "VidNumInvalid"},\
|
||||
{ RET_VID_INVALID, "VidValueInvalid"},\
|
||||
|
@ -106,7 +116,14 @@ typedef unsigned int ret_code;
|
|||
{ RET_VERSION_ERR, "InvalidProtocol"},\
|
||||
{ RET_DESTIP_ERR, "InvalidDestIP"},\
|
||||
{ RET_GATEWAY_ERR, "InvalidGateway"},\
|
||||
{ RET_GW_DEV_ERR, "Gateway&DevEmpty"}\
|
||||
{ RET_GW_DEV_ERR, "Gateway&DevEmpty"},\
|
||||
\
|
||||
{ RET_EXEC_SHELL_ERR, "CantExecShell"},\
|
||||
{ RET_NULL_INPUT_ERR, "EmptyInput"},\
|
||||
{ RET_LTE_NO_MATCH_ERR, "LTENoMatch"},\
|
||||
{ RET_NO_LTE_MODULE_ERR, "NoLTEModule"},\
|
||||
{ RET_ALREADY_START_ERR, "AlreadyStart"},\
|
||||
{ RET_ALREADY_STOP_ERR, "AlreadyStop"}\
|
||||
}
|
||||
|
||||
struct err_disc {
|
||||
|
|
|
@ -71,6 +71,7 @@ COMMON_SRCS = configserver.c \
|
|||
dhcp_shared_network_config.c \
|
||||
dhcp_subnet_config.c\
|
||||
static_routing_config/static_routing_config.c
|
||||
LTE_config/LTE_config.c
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,473 @@
|
|||
#include "configm.h"
|
||||
#include "rpc.h"
|
||||
#include "parsefile.h"
|
||||
#include "LTE_config.h"
|
||||
|
||||
int g_action = 0;
|
||||
|
||||
ret_code compare(char *result)
|
||||
{
|
||||
if(NULL == result)
|
||||
{
|
||||
return RET_NULL_INPUT_ERR;
|
||||
}
|
||||
|
||||
if(strcmp(result,"lte no match") == 0)
|
||||
{
|
||||
return RET_LTE_NO_MATCH_ERR;
|
||||
}
|
||||
|
||||
else if(strcmp(result,"no found lte module") == 0)
|
||||
{
|
||||
return RET_NO_LTE_MODULE_ERR;
|
||||
}
|
||||
|
||||
else if(strcmp(result,"4g init done") == 0)
|
||||
{
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
return RET_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ret_code LTE_config_init(void)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
char result[RESULT_LENGTH] = {0};
|
||||
FILE *f = NULL;
|
||||
f = popen(INIT_CMD,"r");
|
||||
|
||||
if (NULL == f)
|
||||
{
|
||||
rpc_log_info("execuate cmd fail\n");
|
||||
return RET_EXEC_SHELL_ERR;
|
||||
}
|
||||
|
||||
fseek(f,0,SEEK_SET);
|
||||
|
||||
while(fgets(result,sizeof(result),f) != NULL)
|
||||
{
|
||||
ret = compare(result);
|
||||
memset(result,sizeof(result),0);
|
||||
fseek(f,0,SEEK_CUR);
|
||||
}
|
||||
|
||||
pclose(f);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
{
|
||||
"operate":set,
|
||||
"action":start
|
||||
}
|
||||
|
||||
{
|
||||
"operate":getall
|
||||
}
|
||||
*/
|
||||
|
||||
ret_code LTE_json_parse(pointer input, uint *conf_type, int action)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
if(NULL == input)
|
||||
{
|
||||
return RET_NULL_INPUT_ERR;
|
||||
}
|
||||
|
||||
cJSON *json_obj = cJSON_Parse(input);
|
||||
|
||||
if(NULL == json_obj)
|
||||
{
|
||||
rpc_log_info("json obj is NULL \n");
|
||||
return RET_EMPTY_STRING;
|
||||
}
|
||||
|
||||
rpc_json_print(json_obj);
|
||||
|
||||
cJSON *operate = cJSON_GetObjectItem(json_obj,"operate");
|
||||
|
||||
if((NULL == operate) || (NULL == (operate->valuestring)))
|
||||
{
|
||||
cJSON_Delete(json_obj);
|
||||
return RET_EMPTY_STRING;
|
||||
}
|
||||
|
||||
if(strcmp(operate->valuestring,"set") == 0)
|
||||
{
|
||||
*conf_type = CM_CONFIG_SET;
|
||||
}
|
||||
if(strcmp(operate->valuestring,"getall") == 0)
|
||||
{
|
||||
*conf_type = CM_CONFIG_GET_ALL;
|
||||
}
|
||||
else
|
||||
{
|
||||
cJSON_Delete(json_obj);
|
||||
return RET_INPUTERR;
|
||||
}
|
||||
|
||||
cJSON *action_type;
|
||||
action_type = cJSON_GetObjectItem(json_obj,"action");
|
||||
if((NULL == action_type) || (NULL == (action_type->valuestring)))
|
||||
{
|
||||
cJSON_Delete(json_obj);
|
||||
return RET_NULL_INPUT_ERR;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(strcmp(action_type->valuestring,"start") == 0)
|
||||
{
|
||||
g_action = START;
|
||||
}
|
||||
else if(strcmp(action_type->valuestring,"restart") == 0)
|
||||
{
|
||||
g_action = RESTART;
|
||||
}
|
||||
else if(strcmp(action_type->valuestring,"stop") == 0)
|
||||
{
|
||||
g_action = STOP;
|
||||
}
|
||||
else if(strcmp(action_type->valuestring,"status") == 0)
|
||||
{
|
||||
g_action = STATUS;
|
||||
}
|
||||
else
|
||||
{
|
||||
cJSON_Delete(json_obj);
|
||||
return RET_INPUTERR;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void killpid()
|
||||
{
|
||||
char pid[10] =
{0};
|
||||
char cmd[20] = {0};
|
||||
int pid_int;
|
||||
FILE *fp = NULL;
|
||||
fp = popen(GETPID,"r");
|
||||
if(NULL == fp)
|
||||
{
|
||||
rpc_log_info("can not get pid\n");
|
||||
return;
|
||||
}
|
||||
fgets(pid,sizeof(pid),fp);
|
||||
sscanf(pid,"%d",&pid_int);
|
||||
sprintf(cmd,"kill %d",pid_int);
|
||||
system(cmd);
|
||||
pclose(fp);
|
||||
|
||||
}
|
||||
|
||||
ret_code start_lte()
|
||||
{
|
||||
char result[RESULT_LENGTH] = {0};
|
||||
int i = 0;
|
||||
|
||||
FILE *f = NULL;
|
||||
f = popen(START_CMD,"r");
|
||||
|
||||
if (NULL == f)
|
||||
{
|
||||
rpc_log_info("execuate cmd fail\n");
|
||||
return RET_EXEC_SHELL_ERR;
|
||||
}
|
||||
|
||||
fseek(f,0,SEEK_SET);
|
||||
|
||||
fgets(result,sizeof(result),f);
|
||||
|
||||
if(strcmp(result,"not install lte! ") == 0)
|
||||
{
|
||||
pclose(f);
|
||||
return RET_NO_LTE_MODULE_ERR;
|
||||
}
|
||||
|
||||
else if(strcmp(result,"pppd apparently already active, start aborted!") == 0)
|
||||
{
|
||||
pclose(f);
|
||||
return RET_ALREADY_START_ERR;
|
||||
}
|
||||
else if(strcmp(result,"start pppd ppp0") == 0)
|
||||
{
|
||||
while(i < 120)
|
||||
{
|
||||
if(access(file_path,0) != 0)
|
||||
{
|
||||
sleep(1000);
|
||||
i
++;
|
||||
}
|
||||
else
|
||||
{
|
||||
pclose(f);
|
||||
return RET_OK;
|
||||
}
|
||||
}
|
||||
|
||||
pclose(f);
|
||||
//ɱËÀ½ø³Ì
|
||||
killpid;
|
||||
rpc_log_info("please check the sim card\n");
|
||||
return RET_EXEC_SHELL_ERR;
|
||||
}
|
||||
else
|
||||
{
|
||||
pclose(f);
|
||||
return RET_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
ret_code stop_lte()
|
||||
{
|
||||
char result[RESULT_LENGTH] = {0};
|
||||
|
||||
FILE *f = NULL;
|
||||
f = popen(STOP_CMD,"r");
|
||||
|
||||
if (NULL == f)
|
||||
{
|
||||
rpc_log_info("execuate cmd fail\n");
|
||||
return RET_EXEC_SHELL_ERR;
|
||||
}
|
||||
|
||||
fseek(f,0,SEEK_SET);
|
||||
|
||||
fgets(result,sizeof(result),f);
|
||||
|
||||
if(strcmp(result,"pppd may be sotped already") == 0)
|
||||
{
|
||||
pclose(f);
|
||||
return RET_ALREADY_STOP_ERR;
|
||||
}
|
||||
|
||||
else if((strcmp(result,"stop pppd ppp0") == 0) && access(file_path,0) != 0)
|
||||
{
|
||||
pclose(f);
|
||||
return RET_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
pclose(f);
|
||||
return RET_UNKNOWN;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ret_code restart_lte()
|
||||
{
|
||||
char result[RESULT_LENGTH] = {0};
|
||||
int i = 0;
|
||||
|
||||
FILE *f = NULL;
|
||||
f = popen(RESTART_CMD,"r");
|
||||
|
||||
if (NULL == f)
|
||||
{
|
||||
rpc_log_info("execuate cmd fail\n");
|
||||
return RET_EXEC_SHELL_ERR;
|
||||
}
|
||||
|
||||
fseek(f,0,SEEK_SET);
|
||||
fgets(result,sizeof(result),f);
|
||||
memset(result,0,sizeof(result));
|
||||
fseek(f,0,SEEK_CUR);
|
||||
fgets(result,sizeof(result),f);
|
||||
|
||||
if(strcmp(result,"not install lte! ") == 0)
|
||||
{
|
||||
pclose(f);
|
||||
return RET_NO_LTE_MODULE_ERR;
|
||||
}
|
||||
|
||||
else if(strcmp(result,"pppd apparently already active, start aborted!") == 0)
|
||||
{
|
||||
pclose(f);
|
||||
return RET_ALREADY_START_ERR;
|
||||
}
|
||||
else if(strcmp(result,"start pppd ppp0") == 0)
|
||||
{
|
||||
while(i < 120)
|
||||
{
|
||||
if(access(file_path,0) != 0)
|
||||
{
|
||||
sleep(1000);
|
||||
i
++;
|
||||
}
|
||||
else
|
||||
{
|
||||
pclose(f);
|
||||
return RET_OK;
|
||||
}
|
||||
}
|
||||
pclose(f);
|
||||
//ɱËÀ½ø³Ì
|
||||
killpid;
|
||||
rpc_log_info("please check the sim card\n");
|
||||
return RET_EXEC_SHELL_ERR;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
pclose(f);
|
||||
return RET_UNKNOWN;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ret_code lte_to_json(char *status, int connect_time, pointer output, int *output_len)
|
||||
{
|
||||
if(NULL == status || NULL == output || NULL == output_len)
|
||||
{
|
||||
return RET_NULL_INPUT_ERR;
|
||||
}
|
||||
|
||||
ret_code ret = RET_OK;
|
||||
cJSON *ret_root = cJSON_CreateObject();
|
||||
if(ret_root == NULL)
|
||||
{
|
||||
cJSON_Delete(ret_root);
|
||||
return RET_EMPTY_STRING;
|
||||
}
|
||||
|
||||
cJSON_AddStringToObject(ret_root,"status", status);
|
||||
|
||||
if(connect_time != 0)
|
||||
{
|
||||
cJSON_AddNumberToObject(ret_root,"connect_time",connect_time);
|
||||
}
|
||||
|
||||
rpc_json_print(ret_root);
|
||||
|
||||
char *status_info = cJSON_PrintUnformatted(ret_root);
|
||||
*output_len = strlen(status_info) + 1;
|
||||
memcpy(output, status_info, *output_len);
|
||||
|
||||
free(status_info);
|
||||
cJSON_Delete(ret_root);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret_code status_lte(pointer output, int *output_len)
|
||||
{
|
||||
if((NULL == output) || (NULL == output_len))
|
||||
{
|
||||
return RET_INPUTERR;
|
||||
}
|
||||
|
||||
char result[RESULT_LENGTH] = {0};
|
||||
char status[STATUS_LENGTH] = {0};
|
||||
int connect_time = 0;
|
||||
ret_code ret = RET_OK;
|
||||
|
||||
FILE *f = NULL;
|
||||
f = popen(STATUS_CMD,"r");
|
||||
if(NULL == f)
|
||||
{
|
||||
rpc_log_info("execuate cmd fail\n");
|
||||
return RET_EXEC_SHELL_ERR;
|
||||
}
|
||||
|
||||
fgets(result,sizeof(result),f);
|
||||
if(strstr(result,"off") != NULL)
|
||||
{
|
||||
strcpy(status,"off");
|
||||
//·â×°json
|
||||
ret = lte_to_json(status,connect_time,output,output_len);
|
||||
pclose(f);
|
||||
return ret;
|
||||
}
|
||||
else if(strstr(result,"on") != NULL)
|
||||
{
|
||||
strcpy(status,"on");
|
||||
memcpy(result,0,sizeof(result));
|
||||
fgets(result,sizeof(result),f);
|
||||
sscanf(result,"ppp_keep_time=%d",&connect_time);
|
||||
ret = lte_to_json(status,connect_time,output,output_len);
|
||||
pclose(f);
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
pclose(f);
|
||||
return RET_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
ret_code LTE_config_chk(uint source, uint *config_type,
|
||||
pointer input, int *input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
if((NULL == config_type) || (NULL == input) || (NULL == input_len) || (NULL == output_len))
|
||||
{
|
||||
return RET_NULL_INPUT_ERR;
|
||||
}
|
||||
|
||||
ret_code ret = RET_OK;
|
||||
//int action = 0;
|
||||
|
||||
ret = LTE_json_parse(input,config_type,g_action);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret_code LTE_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
|
||||
if(config_type == CM_CONFIG_SET)
|
||||
{
|
||||
switch(g_action){
|
||||
case START:
|
||||
ret = start_lte();
|
||||
break;
|
||||
case RESTART:
|
||||
ret = restart_lte();
|
||||
break;
|
||||
case STOP:
|
||||
ret = stop_lte();
|
||||
break;
|
||||
default:
|
||||
ret = RET_INPUTERR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
ret = RET_INPUTERR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
ret_code LTE_config_get_all(uint source,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
if((NULL == output) || (NULL == output_len))
|
||||
{
|
||||
return RET_INPUTERR;
|
||||
}
|
||||
|
||||
ret_code ret = RET_OK;
|
||||
|
||||
*output_len = 0;
|
||||
ret = status_lte(output, output_len);
|
||||
|
||||
rpc_log_info("status is %s\n",(char *)output);
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
#ifndef LTE_CONFIG_H_
|
||||
#define LTE_CONFIG_H_
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#define INIT_CMD "./ppp-4G init"
|
||||
#define START_CMD "./ppp-4G start"
|
||||
#define STOP_CMD "./ppp-4G stop"
|
||||
#define RESTART_CMD "./ppp-4G restart"
|
||||
#define STATUS_CMD "./ppp-4G status"
|
||||
#define file_path "/var/run/ppp0.pid"
|
||||
#define GETPID "pgrep ppp-4g"
|
||||
#define START 1
|
||||
#define RESTART 2
|
||||
#define STOP 3
|
||||
#define STATUS 4
|
||||
#define RESULT_LENGTH 60
|
||||
#define ACTION_LENGTH 10
|
||||
#define STATUS_LENGTH 5
|
||||
|
||||
ret_code LTE_config_init(void);
|
||||
|
||||
ret_code LTE_config_chk(uint source, uint *config_type,
|
||||
pointer input, int *input_len,
|
||||
pointer output, int *output_len);
|
||||
|
||||
ret_code LTE_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
|
||||
ret_code LTE_config_get_all(uint source,
|
||||
pointer output, int *output_len);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
#include "vlan_config.h"
|
||||
#include "dhcp_lib.h"
|
||||
#include "static_routing.h"
|
||||
|
||||
#include "LTE_config.h"
|
||||
|
||||
#define RET_CODE_LEN 16
|
||||
#define RET_MSG_LEN 128
|
||||
|
@ -38,7 +38,11 @@
|
|||
{ \
|
||||
DHCP_CONFIG_MODULE, \
|
||||
dhcp_config_init \
|
||||
} \
|
||||
}, \
|
||||
{ \
|
||||
LTE_CONFIG_MODULE, \
|
||||
LTE_config_init \
|
||||
} \
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -213,7 +217,7 @@
|
|||
FALSE, \
|
||||
nat_config_chk, \
|
||||
nat_config_proc, \
|
||||
nat_config_get, \
|
||||
NULL, \
|
||||
nat_config_get_all \
|
||||
},\
|
||||
{\
|
||||
|
@ -296,6 +300,15 @@
|
|||
NULL, \
|
||||
NULL, \
|
||||
all_routing_get_all \
|
||||
},\
|
||||
{\
|
||||
LTE_CONFIG, \
|
||||
CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \
|
||||
FALSE, \
|
||||
LTE_config_chk, \
|
||||
LTE_config_proc, \
|
||||
NULL, \
|
||||
LTE_config_get_all \
|
||||
}\
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue