selfcare init
This commit is contained in:
53
proxy_c/smcli_client/Makefile
Normal file
53
proxy_c/smcli_client/Makefile
Normal file
@@ -0,0 +1,53 @@
|
||||
|
||||
MODULE = client
|
||||
TYPE = plat
|
||||
|
||||
DBUG_FLAGS_ADD =
|
||||
RELS_FLAGS_ADD =
|
||||
|
||||
##Default commonly as below
|
||||
|
||||
BUILD = lib
|
||||
CFG = debug
|
||||
|
||||
|
||||
PLT_LIB = -DDEBUG
|
||||
|
||||
APP_LIB =
|
||||
LIB_ADD =
|
||||
|
||||
SRC_PATH = ./src
|
||||
INC_PATH = ./src/include
|
||||
PLT_PATH = ../../plat
|
||||
APP_PATH = ../../mss
|
||||
|
||||
OBJ_ADD =
|
||||
TEST_OBJ_PATH =
|
||||
|
||||
PREPROC_CMD =
|
||||
POSTPROC_CMD =
|
||||
|
||||
##---------------------------------------------------------------------##
|
||||
##--------------------------------------
|
||||
##
|
||||
## Make configuration(Customer define)
|
||||
##
|
||||
##--------------------------------------
|
||||
|
||||
## CCFLAG_SWITCH = on/off => gcc flag show on/off
|
||||
## COVER_NEED = yes/no => PTF cover report needed
|
||||
## COVER_REPORT_PATH = [path ] => PTF cover report path
|
||||
|
||||
CCFLAG_SWITCH = off
|
||||
COVER_NEED = no
|
||||
COVER_REPORT_PATH = ./output
|
||||
|
||||
##---------------------------------------------------------------------##
|
||||
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## include makefile.rules (Do not change)
|
||||
##
|
||||
##--------------------------------------
|
||||
include ./scripts/Makefile.rules
|
||||
342
proxy_c/smcli_client/scripts/Makefile.rules
Normal file
342
proxy_c/smcli_client/scripts/Makefile.rules
Normal file
@@ -0,0 +1,342 @@
|
||||
|
||||
##----------------------------------------------------------##
|
||||
## ##
|
||||
## Universal Makefile Rules ##
|
||||
## ##
|
||||
## Created : Wei Liu 07/03/07 ##
|
||||
## Revision: [Last]Wei Liu 07/07/07 ##
|
||||
## ##
|
||||
##----------------------------------------------------------##
|
||||
|
||||
|
||||
UMAKE_VERSION := V2.0
|
||||
|
||||
##-------------------------------------
|
||||
##
|
||||
## Work Directory : /usr/local/include
|
||||
## Default Target : all
|
||||
##
|
||||
##-------------------------------------
|
||||
default: all
|
||||
.PHONY: all clean rebuild test indent splint doc \
|
||||
dir config check bk lsbk rmbk unzip umakever usage\
|
||||
FORCE
|
||||
.SUFFIXES:
|
||||
|
||||
umakever:
|
||||
@echo "Universal Makefile (UMake) Version: $(UMAKE_VERSION)"
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## Makefile CFG defination check
|
||||
##
|
||||
##--------------------------------------
|
||||
|
||||
ifeq "$(MODULE)" ""
|
||||
$(error Please input the module name (MODULE = )in makefile. )
|
||||
endif
|
||||
|
||||
ifeq "$(CFG)" ""
|
||||
CFG=debug
|
||||
$(warnning No configuration specified for CFG. Defaulting to $(MODULE) - debug. )
|
||||
endif
|
||||
|
||||
ifeq "$(BUILD)" ""
|
||||
BUILD=lib
|
||||
$(warnning No configuration specified for BUILD. Defaulting to create lib$(MODULE).a. )
|
||||
endif
|
||||
|
||||
ifeq "$(SRC_PATH)" ""
|
||||
SRC_PATH=.
|
||||
$(warnning No configuration specified for SRC_PATH. Defaulting to ./. )
|
||||
endif
|
||||
|
||||
COVER_NEED ?= no
|
||||
PLT_PATH ?= ../../plat
|
||||
APP_PATH ?= ../../app
|
||||
TYPE ?= plat
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## Gcc Flag for debug or release
|
||||
##
|
||||
##--------------------------------------
|
||||
CC := gcc
|
||||
GCC_CFLAGS := -Wall -MM
|
||||
AR_LINK := ar -r
|
||||
|
||||
RELS_FLAGS_ADD += -DNDEBUG
|
||||
RELEASE_CFLAGS += -g -Wall -I. $(RELS_FLAGS_ADD) -I/usr/include/mysql -L/usr/lib64/mysql -lmysqlclient
|
||||
RELEASE_LINK_CFLAGS = -g $(RELS_FLAGS_ADD) -o
|
||||
DEBUG_CFLAGS += -g -Wall -rdynamic -DDEBUG -I. $(DBUG_FLAGS_ADD) -I/usr/include/mysql -L/usr/lib64/mysql -lmysqlclient -I/usr/include/openssl
|
||||
DEBUG_LINK_CFLAGS = -g -rdynamic -DDEBUG -o
|
||||
|
||||
ifeq "$(COVER_NEED)" "yes"
|
||||
DEBUG_CFLAGS += -fprofile-arcs -ftest-coverage -pg
|
||||
endif
|
||||
|
||||
GCC_CFLAGS=$(DEBUG_CFLAGS)
|
||||
GCC_LINK_CFLAGS=$(DEBUG_LINK_CFLAGS)
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## Project setting
|
||||
##
|
||||
##--------------------------------------
|
||||
OBJDIR:=./obj
|
||||
LIBDIR:=./lib
|
||||
UTDIR :=./ut
|
||||
DOCDIR:=./doc
|
||||
DIRBUILD=$(OBJDIR)
|
||||
|
||||
ifeq "$(BUILD)" "lib"
|
||||
BINDIR:=./bin
|
||||
OUTFILE=$(LIBDIR)/lib$(MODULE).a
|
||||
DIRNEED=$(UTDIR) $(DOCDIR)
|
||||
DIRBUILD+=$(LIBDIR)
|
||||
else
|
||||
BINDIR:=.
|
||||
OUTFILE=$(BINDIR)/$(MODULE)
|
||||
DIRNEED=
|
||||
DIRBUILD+=$(BINDIR)
|
||||
endif
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## source , object and dependencies files
|
||||
##
|
||||
##--------------------------------------
|
||||
|
||||
SRC_SUBDIR := $(shell find $(SRC_PATH) -type d)
|
||||
|
||||
vpath %.c $(SRC_SUBDIR)
|
||||
vpath %.o $(OBJDIR)
|
||||
vpath %.d $(OBJDIR)
|
||||
|
||||
SRC_FULL_PATH = $(foreach dir,$(SRC_SUBDIR),$(wildcard $(dir)/*.c))
|
||||
SRC_FILES = $(foreach file, $(notdir $(SRC_FULL_PATH)) ,$(OBJDIR)/$(file))
|
||||
COMMON_OBJ = $(SRC_FILES:%.c=%.o)
|
||||
|
||||
TEST_OBJ_PATH ?= ../../obj
|
||||
|
||||
TEST_OBJ = $(foreach dir,$(TEST_OBJ_PATH),$(wildcard $(dir)/*.o))
|
||||
|
||||
OBJ=$(COMMON_OBJ) $(OBJ_ADD)
|
||||
ALL_OBJ := $(OBJ) $(TEST_OBJ)
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## Lib setting
|
||||
##
|
||||
##--------------------------------------
|
||||
|
||||
ifeq "$(COVER_NEED)" "yes"
|
||||
LIBCOVER=-lgcov
|
||||
endif
|
||||
|
||||
MODULE_PLT_LIB=$(foreach lib,$(PLT_LIB), -L$(PLT_PATH)/$(lib)/lib/ -l$(lib) )
|
||||
MODULE_PLT_LIB+=-lm
|
||||
|
||||
|
||||
MODULE_APP_LIB=$(foreach lib,$(APP_LIB),-L$(APP_PATH)/$(lib)/lib -l$(lib))
|
||||
|
||||
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## Rules
|
||||
##
|
||||
##--------------------------------------
|
||||
CCFLAG_SWITCH ?= off
|
||||
CC_COMPILE =$(CC) $(GCC_CFLAGS) -c $< -o $@
|
||||
CC_PRG_LINK=$(CC) $(GCC_LINK_CFLAGS) $(OUTFILE) $(ALL_OBJ) $(LIBCOVER) $(MODULE_APP_LIB) $(MODULE_PLT_LIB) $(LIB_ADD)
|
||||
CC_LIB_LINK=$(AR_LINK) $(OUTFILE) $(ALL_OBJ)
|
||||
|
||||
COMPILE=$(CC_COMPILE)
|
||||
PRG_LINK=$(CC_PRG_LINK)
|
||||
LIB_LINK=$(CC_LIB_LINK)
|
||||
|
||||
ifeq "$(BUILD)" "exef"
|
||||
LINK=$(PRG_LINK)
|
||||
else
|
||||
LINK=$(LIB_LINK)
|
||||
endif
|
||||
|
||||
# Build rules
|
||||
|
||||
all: preproc start dir $(ALL_OBJ) #prtdebug
|
||||
@echo Linking :$(OUTFILE)
|
||||
ifeq "$(CCFLAG_SWITCH)" "off"
|
||||
@$(LINK)
|
||||
else
|
||||
$(LINK)
|
||||
endif
|
||||
@$(POSTPROC_CMD)
|
||||
@echo -e "\n================================================================================\n"
|
||||
|
||||
sinclude $(DEPENDS)
|
||||
|
||||
release : CC_COMPILE =$(CC) $(RELEASE_CFLAGS) -c $< -o $@
|
||||
release : CC_PRG_LINK=$(CC) $(RELEASE_LINK_CFLAGS) $(OUTFILE) $(ALL_OBJ) $(MODULE_APP_LIB) $(MODULE_PLT_LIB) $(LIB_ADD)
|
||||
release : all
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## Make command to use for dependencies
|
||||
##
|
||||
##--------------------------------------
|
||||
|
||||
MAKE :=make
|
||||
RM :=rm
|
||||
MKDIR :=mkdir
|
||||
|
||||
preproc:
|
||||
@$(PREPROC_CMD)
|
||||
|
||||
start:
|
||||
@echo -e "\n================================================================================\n"
|
||||
@echo "[Building Project]: $(notdir $(MODULE))"
|
||||
ifeq "$(CCFLAG_SWITCH)" "off"
|
||||
@echo "Show Gcc Flags switch = OFF"
|
||||
endif
|
||||
|
||||
prtdebug:
|
||||
@echo "$(MODULE)-$(BUILD)[$(CFG)] build source file:" "$(SRC_FULL_PATH)"
|
||||
@echo SRC_SUBDIR: $(SRC_SUBDIR)
|
||||
@echo SRC_FULL_PATH : $(SRC_FULL_PATH)
|
||||
@echo SRC_FILES : $(SRC_FILES)
|
||||
@echo ALL_OBJ : $(ALL_OBJ)
|
||||
@echo LIB:$(MODULE_PLT_LIB)
|
||||
@echo PLT_LIB: $(PLT_LIB)
|
||||
@echo CCFLAG_SWITCH :$(CCFLAG_SWITCH)
|
||||
|
||||
config: dir
|
||||
|
||||
dir:
|
||||
@$(foreach dir,$(DIRNEED),$(MKDIR) -p $(DIRNEED) --mode=0777; )
|
||||
@$(foreach dir,$(DIRBUILD),$(MKDIR) -p $(dir) --mode=0777; )
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## Make Rebuild and clean
|
||||
##
|
||||
##--------------------------------------
|
||||
|
||||
ifneq "$(PROJ)" ""
|
||||
FRIEND_PROJ := $(shell )
|
||||
endif
|
||||
|
||||
jumprebuild:
|
||||
ifneq "$(PROJ)" ""
|
||||
@cd $(FRIEND_PROJ); mak rebuild ; cd -
|
||||
endif
|
||||
|
||||
# Rebuild this project
|
||||
rebuild: jumprebuild cleanall all
|
||||
|
||||
# Clean this project and all dependencies
|
||||
cleanall: clean
|
||||
|
||||
# Clean this project
|
||||
clean:
|
||||
@echo -e "||--------------------------------------------------------------- "
|
||||
@echo -e "|| Umake clean gcc , lcov, doxygen generated and temporary files. "
|
||||
@echo -e "||--------------------------------------------------------------- "
|
||||
@$(RM) -rf $(OBJDIR) $(OUTFILE) $(COVER_REPORT_PATH) ./doc/doxygen.conf ./doc/html ./doc/latex ./doc/rtf $(foreach dir,$(SRC_SUBDIR),$(dir)/*~)
|
||||
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## indent Makefile.indent
|
||||
##
|
||||
##--------------------------------------
|
||||
include Makefile.indent
|
||||
|
||||
indent:
|
||||
@chmod 777 $(SRC_FULL_PATH)
|
||||
@echo ===================================Indent START=================================
|
||||
@echo
|
||||
@echo "[Indent source file ]: $(SRC_FULL_PATH)"
|
||||
$(call MAKE_INDENT , $(SRC_FULL_PATH))
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## splint makefile.splint
|
||||
##
|
||||
##--------------------------------------
|
||||
include Makefile.splint
|
||||
|
||||
SPLINT_FLAG_SWITCH ?= off
|
||||
|
||||
splint:
|
||||
@chmod 777 $(SRC_FULL_PATH)
|
||||
@echo =================================Splint START==================================
|
||||
@echo
|
||||
ifeq "$(SPLINT_FLAG_SWITCH)" "on"
|
||||
@echo "[Splint flags ]: $(SPLINT_FLAGS)"
|
||||
endif
|
||||
@echo "[Lint Clean Project]: $(notdir $(MODULE))"
|
||||
$(call MAKE_SPLINT, $(SRC_FULL_PATH))
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## doc Makefile.doxygen
|
||||
##
|
||||
##--------------------------------------
|
||||
include Makefile.doxygen
|
||||
|
||||
doc:
|
||||
@chmod 777 $(SRC_FULL_PATH)
|
||||
@echo ==================================Doxygen START=================================
|
||||
@echo
|
||||
$(call MAKE_DOC, $(SRC_FULL_PATH))
|
||||
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## backup Makefile.backup
|
||||
##
|
||||
##--------------------------------------
|
||||
include Makefile.backup
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## cov Makefile.cov
|
||||
##
|
||||
##--------------------------------------
|
||||
include Makefile.cov
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## usage Makefile.usage
|
||||
##
|
||||
##--------------------------------------
|
||||
include Makefile.usage
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## Make dependencies
|
||||
##
|
||||
##--------------------------------------
|
||||
|
||||
$(OBJDIR)/%.d:%.c
|
||||
@$(CC) $< -MM -MD -o $@
|
||||
|
||||
$(OBJDIR)/%.o:%.c
|
||||
|
||||
ifeq "$(CCFLAG_SWITCH)" "off"
|
||||
@echo -e "building: $(notdir $@) \t\t\t\t please wait ..."
|
||||
@$(COMPILE)
|
||||
else
|
||||
$(COMPILE)
|
||||
endif
|
||||
|
||||
DEPENDS=$(COMMON_OBJ:.o=.d)
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## Make force
|
||||
##
|
||||
##--------------------------------------
|
||||
FORCE:
|
||||
|
||||
492
proxy_c/smcli_client/src/client.c
Normal file
492
proxy_c/smcli_client/src/client.c
Normal file
@@ -0,0 +1,492 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "./include/client.h"
|
||||
|
||||
#define CLIENT_CFG "./conf/smcli_client.cfg"
|
||||
|
||||
_client_param_t client_cfg;
|
||||
|
||||
static int smcli_cmd_res=0;
|
||||
static char smcli_result[256];
|
||||
|
||||
int client_read_conf()
|
||||
{
|
||||
char s[80],s1[80];
|
||||
int len;
|
||||
unsigned char conf_state=0xFF;
|
||||
FILE *fpConf;
|
||||
|
||||
memset(&client_cfg, 0x00, sizeof(_client_param_t));
|
||||
|
||||
fpConf = fopen(CLIENT_CFG,"rb");
|
||||
|
||||
if(fpConf == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
strcpy(s,"");
|
||||
strcpy(s1,"");
|
||||
while(fgets(s,1024,fpConf) !=(char *)0)
|
||||
{
|
||||
if( (int *)strchr(s,'#') !=NULL) continue;
|
||||
if( !strlen(s) ) continue;
|
||||
len = strlen(s);
|
||||
if(len < 2) continue;
|
||||
|
||||
if(s[len-1] == 0x0d ||s[len-1] == 0x0a)
|
||||
{
|
||||
if(s[len-2] == 0x0d ||s[len-2] == 0x0a)
|
||||
{
|
||||
s[len-2] = 0;
|
||||
len -= 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
s[len-1] = 0;
|
||||
len -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
if(!strncasecmp(s,"[EMS]",5))
|
||||
{
|
||||
conf_state = 0;
|
||||
continue;
|
||||
}
|
||||
else if(!strncasecmp(s,"[HSS]",5))
|
||||
{
|
||||
conf_state = 1;
|
||||
continue;
|
||||
}
|
||||
else if(!strncasecmp(s,"[AUC]",5))
|
||||
{
|
||||
conf_state = 2;
|
||||
continue;
|
||||
}
|
||||
else if(!strncasecmp(s,"[VMS]",5))
|
||||
{
|
||||
conf_state = 3;
|
||||
continue;
|
||||
}
|
||||
else if(!strncasecmp(s,"[Provision]",11))
|
||||
{
|
||||
conf_state = 4;
|
||||
continue;
|
||||
}
|
||||
|
||||
switch(conf_state)
|
||||
{
|
||||
case 0:
|
||||
if(strncasecmp(s,"ems0_ip=",8)==0)
|
||||
{
|
||||
client_cfg.ems_servers.host0_enable = 1;
|
||||
strcpy(client_cfg.ems_servers.host0_ip, &s[8]);
|
||||
//host_ip = inet_addr(&s[8]);
|
||||
}
|
||||
else if(strncasecmp(s,"ems0_port=",10)==0)
|
||||
{
|
||||
client_cfg.ems_servers.host0_port = atoi(&s[10]);
|
||||
}
|
||||
else if(strncasecmp(s,"ems1_ip=",8)==0)
|
||||
{
|
||||
client_cfg.ems_servers.host1_enable = 1;
|
||||
strcpy(client_cfg.ems_servers.host1_ip, &s[8]);
|
||||
//host_ip = inet_addr(&s[8]);
|
||||
}
|
||||
else if(strncasecmp(s,"ems1_port=",10)==0)
|
||||
{
|
||||
client_cfg.ems_servers.host1_port = atoi(&s[10]);
|
||||
}
|
||||
else if(strncasecmp(s,"user_name=",10)==0)
|
||||
{
|
||||
strcpy(client_cfg.ems_servers.user_name, &s[10]);
|
||||
}
|
||||
else if(strncasecmp(s,"password=", 9)==0)
|
||||
{
|
||||
strcpy(client_cfg.ems_servers.password, &s[9]);
|
||||
}
|
||||
else if(strncasecmp(s,"connect_hss=",12)==0)
|
||||
{
|
||||
client_cfg.connect_configured[SYS_T_HSS] = 1;
|
||||
strcpy(client_cfg.connect_command[SYS_T_HSS], &s[12]);
|
||||
}
|
||||
else if(strncasecmp(s,"connect_auc=",12)==0)
|
||||
{
|
||||
client_cfg.connect_configured[SYS_T_AUC] = 1;
|
||||
strcpy(client_cfg.connect_command[SYS_T_AUC], &s[12]);
|
||||
}
|
||||
else if(strncasecmp(s,"connect_vms=",12)==0)
|
||||
{
|
||||
client_cfg.connect_configured[SYS_T_VMS] = 1;
|
||||
strcpy(client_cfg.connect_command[SYS_T_VMS], &s[12]);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
strcpy(client_cfg.cli_command[SYS_T_HSS], s);
|
||||
break;
|
||||
case 2:
|
||||
strcpy(client_cfg.cli_command[SYS_T_AUC], s);
|
||||
break;
|
||||
case 3:
|
||||
strcpy(client_cfg.cli_command[SYS_T_VMS], s);
|
||||
break;
|
||||
case 4:
|
||||
if(strncasecmp(s,"enable", 6) == 0)
|
||||
{
|
||||
client_cfg.provsioning_flag = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fpConf);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int rest_provsioning_enabled()
|
||||
{
|
||||
return client_cfg.provsioning_flag;
|
||||
}
|
||||
|
||||
int smcli_reset_result()
|
||||
{
|
||||
smcli_cmd_res = 0;
|
||||
}
|
||||
|
||||
int smcli_get_result(char* result_des)
|
||||
{
|
||||
if(smcli_cmd_res != 0)
|
||||
strcpy(result_des, smcli_result);
|
||||
|
||||
return smcli_cmd_res;
|
||||
}
|
||||
|
||||
int smcli_connect_ems()
|
||||
{
|
||||
if(client_cfg.ems_servers.host0_enable)
|
||||
tcp_connect_server(client_cfg.ems_servers.host0_ip, client_cfg.ems_servers.host0_port);
|
||||
else if(client_cfg.ems_servers.host1_enable)
|
||||
tcp_connect_server(client_cfg.ems_servers.host1_ip, client_cfg.ems_servers.host1_port);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void smcli_send_user_name_pwd(int flag)
|
||||
{
|
||||
char user_name[128];
|
||||
char password[128];
|
||||
|
||||
if(flag == 0)
|
||||
{
|
||||
sprintf(user_name, "%s\r\n", client_cfg.ems_servers.user_name);
|
||||
tcp_send_msg(user_name, strlen(user_name));
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(password, "%s\r\n", client_cfg.ems_servers.password);
|
||||
tcp_send_msg(password, strlen(password));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void smcli_connect_cn_nodes(int sys_type)
|
||||
{
|
||||
char command[128];
|
||||
|
||||
sprintf(command, "%s\r\n", client_cfg.connect_command[sys_type]);
|
||||
tcp_send_msg(command, strlen(command));
|
||||
|
||||
}
|
||||
|
||||
void smcli_send_command(char *command)
|
||||
{
|
||||
tcp_send_msg(command, strlen(command));
|
||||
|
||||
smcli_reset_result();
|
||||
|
||||
}
|
||||
|
||||
void crm_create_vms_account(char *number)
|
||||
{
|
||||
char cli_command[1024];
|
||||
|
||||
sprintf(cli_command,"create vmsSubscriber -msisdn %s", number);
|
||||
|
||||
smcli_send_command(cli_command);
|
||||
}
|
||||
|
||||
void crm_prov_hlr_auc_vms_account(char sub_data[][1024])
|
||||
{//PRE_ID, IMSI, SERVICE_NBR, KI, OPC, ACCT_TYPE,CUST_ID, ACCT_ID, PRD_INST_ID, MOBILE_TYPE, VMS_FLAG
|
||||
char cli_command[1024];
|
||||
|
||||
if(1)//HLR
|
||||
{
|
||||
sprintf(cli_command,"create subscriber -imsi %s -msisdn %s -eps_user_tpl def_eps -impi %s@ims.mnc010.mcc505.3gppnetwork.org",
|
||||
sub_data[2], sub_data[3], sub_data[2]);
|
||||
|
||||
smcli_send_command(cli_command);
|
||||
}
|
||||
|
||||
sleep(2);
|
||||
if(1)
|
||||
{
|
||||
if(sub_data[5][0] == 0)
|
||||
sprintf(cli_command,"create aucSubscriber -imsi %s -ki %s", sub_data[2], sub_data[4]);
|
||||
else
|
||||
sprintf(cli_command,"create aucSubscriber -imsi %s -ki %s -opc %s", sub_data[2], sub_data[4], sub_data[5]);
|
||||
|
||||
smcli_send_command(cli_command);
|
||||
}
|
||||
|
||||
sleep(2);
|
||||
|
||||
if(atoi(sub_data[10]))//VMS enabled
|
||||
{
|
||||
crm_create_vms_account(sub_data[3]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int smcli_link_fsm()
|
||||
{
|
||||
u_char recvbuf[1024];
|
||||
int len = 0;
|
||||
|
||||
int state = 0;
|
||||
|
||||
state = client_cfg.smcli_link_state;
|
||||
|
||||
switch(state)
|
||||
{
|
||||
case 0: //do nothing
|
||||
break;
|
||||
case 1:
|
||||
len = tcp_recv_msg(recvbuf);
|
||||
if(len>0)
|
||||
{
|
||||
if(strstr(recvbuf, "username:"))
|
||||
{
|
||||
smcli_send_user_name_pwd(0);
|
||||
}
|
||||
|
||||
//if(strstr(recvbuf, "Welcome to"))
|
||||
client_cfg.smcli_link_state = 2;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
len = tcp_recv_msg(recvbuf);
|
||||
if(len>0)
|
||||
{
|
||||
if(strstr(recvbuf, "username:"))
|
||||
{
|
||||
smcli_send_user_name_pwd(0);
|
||||
}
|
||||
else if(strstr(recvbuf,"password:"))
|
||||
{
|
||||
smcli_send_user_name_pwd(1);
|
||||
client_cfg.smcli_link_state = 3;
|
||||
client_cfg.smcli_verified = 1;
|
||||
}
|
||||
else if(strstr(recvbuf, "Login incorrect"))
|
||||
{
|
||||
printf("error username/password\r\n");
|
||||
exit(128);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
len = tcp_recv_msg(recvbuf);
|
||||
if(len>0)
|
||||
{
|
||||
if(strstr(recvbuf,"CLI>")) //login succeed
|
||||
{
|
||||
client_cfg.smcli_link_state = 10;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 10:
|
||||
if(client_cfg.connect_configured[SYS_T_HSS])
|
||||
{
|
||||
smcli_connect_cn_nodes(SYS_T_HSS);
|
||||
client_cfg.smcli_link_state = 11;
|
||||
}
|
||||
else
|
||||
{
|
||||
client_cfg.smcli_link_state = 20;
|
||||
}
|
||||
|
||||
break;
|
||||
case 11:
|
||||
len = tcp_recv_msg(recvbuf);
|
||||
if(len>0)
|
||||
{
|
||||
if(strstr(recvbuf,"Login incorrec"))
|
||||
{
|
||||
printf("connect hlr failed\r\n");
|
||||
}
|
||||
client_cfg.smcli_link_state = 12;
|
||||
}
|
||||
break;
|
||||
case 12:
|
||||
len = tcp_recv_msg(recvbuf);
|
||||
if(len>0)
|
||||
{
|
||||
if(strstr(recvbuf,"CLI>")) //input mode
|
||||
{
|
||||
client_cfg.smcli_link_state = 20;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 20:
|
||||
if(client_cfg.connect_configured[SYS_T_AUC])
|
||||
{
|
||||
smcli_connect_cn_nodes(SYS_T_AUC);
|
||||
client_cfg.smcli_link_state = 21;
|
||||
}
|
||||
else
|
||||
{
|
||||
client_cfg.smcli_link_state = 30;
|
||||
}
|
||||
break;
|
||||
case 21:
|
||||
len = tcp_recv_msg(recvbuf);
|
||||
if(len>0)
|
||||
{
|
||||
if(strstr(recvbuf,"Login incorrec") )
|
||||
{
|
||||
printf("connect auc failed\r\n");
|
||||
}
|
||||
client_cfg.smcli_link_state = 22;
|
||||
}
|
||||
break;
|
||||
case 22:
|
||||
len = tcp_recv_msg(recvbuf);
|
||||
if(len>0)
|
||||
{
|
||||
if(strstr(recvbuf,"CLI>")) //input mode
|
||||
{
|
||||
client_cfg.smcli_link_state = 30;//100;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 30:
|
||||
if(client_cfg.connect_configured[SYS_T_VMS])
|
||||
{
|
||||
smcli_connect_cn_nodes(SYS_T_VMS);
|
||||
client_cfg.smcli_link_state = 31;
|
||||
}
|
||||
else
|
||||
{
|
||||
client_cfg.smcli_link_state = 100;
|
||||
}
|
||||
|
||||
break;
|
||||
case 31:
|
||||
len = tcp_recv_msg(recvbuf);
|
||||
if(len>0)
|
||||
{
|
||||
if(strstr(recvbuf,"Login incorrec") )
|
||||
{
|
||||
printf("connect vms failed\r\n");
|
||||
}
|
||||
client_cfg.smcli_link_state = 32;
|
||||
}
|
||||
break;
|
||||
case 32:
|
||||
len = tcp_recv_msg(recvbuf);
|
||||
if(len>0)
|
||||
{
|
||||
if(strstr(recvbuf,"CLI>")) //input mode
|
||||
{
|
||||
client_cfg.smcli_link_state = 100;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 100://normal state, can handle cli command
|
||||
len = tcp_recv_msg(recvbuf);
|
||||
if(len>6)
|
||||
{
|
||||
if(strstr(recvbuf,"Login incorrect"))
|
||||
{
|
||||
printf("smcli link is discounneted\r\n");
|
||||
client_cfg.smcli_link_state = 1;
|
||||
|
||||
smcli_cmd_res = 2;
|
||||
strcpy(smcli_result, recvbuf);
|
||||
}
|
||||
else if(strstr(recvbuf, "success"))
|
||||
{
|
||||
smcli_cmd_res = 1;
|
||||
strcpy(smcli_result, recvbuf);
|
||||
}
|
||||
else
|
||||
{
|
||||
smcli_cmd_res = 2;
|
||||
strcpy(smcli_result, recvbuf);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
void smlci_connection_check()
|
||||
{
|
||||
if(client_cfg.client_connected == 1)
|
||||
return;
|
||||
|
||||
if(is_tcp_connected()>=0)
|
||||
{
|
||||
client_cfg.client_connected = 1;
|
||||
client_cfg.smcli_link_state = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void smcli_connection_is_broken()
|
||||
{
|
||||
client_cfg.client_connected = 0;
|
||||
|
||||
client_cfg.smcli_link_state = 0;
|
||||
client_cfg.smcli_verified = 0;
|
||||
|
||||
}
|
||||
|
||||
int smcli_client_thread(void *param)
|
||||
{
|
||||
static int smcli_timer= 0;
|
||||
|
||||
client_read_conf();
|
||||
|
||||
smcli_connect_ems();
|
||||
|
||||
while(1)
|
||||
{
|
||||
if(smcli_timer % 10000)
|
||||
{
|
||||
tcp_check_connection();
|
||||
|
||||
smlci_connection_check();
|
||||
smcli_timer = 0;
|
||||
}
|
||||
|
||||
smcli_link_fsm();
|
||||
|
||||
smcli_timer ++;
|
||||
usleep(10000);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
50
proxy_c/smcli_client/src/include/client.h
Normal file
50
proxy_c/smcli_client/src/include/client.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#ifndef _SMCLI_CLIENT_H
|
||||
#define _SMCLI_CLIENT_H
|
||||
|
||||
#define CLI_COMMAND_LEN 8192
|
||||
#define CONNECT_COMMAND_LEN 128
|
||||
|
||||
typedef enum ACCT_TYPE
|
||||
{
|
||||
ACCT_T_MOBILE,
|
||||
ACCT_T_PSTN,
|
||||
ACCT_T_ADSL,
|
||||
}_ACCT_TYPE;
|
||||
|
||||
typedef enum SYS_TYPE
|
||||
{
|
||||
SYS_T_EMS,
|
||||
SYS_T_HSS,
|
||||
SYS_T_AUC,
|
||||
SYS_T_VMS,
|
||||
SYS_T_PSTN,
|
||||
SYS_T_ADSL,
|
||||
SYS_T_MAX,
|
||||
}_SYS_TYPE;
|
||||
|
||||
typedef struct server_param_t
|
||||
{
|
||||
u_char host0_enable;
|
||||
char host0_ip[16];
|
||||
u_short host0_port;
|
||||
u_char host1_enable;
|
||||
char host1_ip[16];
|
||||
u_short host1_port;
|
||||
char user_name[16];
|
||||
char password[16];
|
||||
}server_param_t;
|
||||
|
||||
|
||||
typedef struct client_param_t
|
||||
{
|
||||
int client_connected;
|
||||
int smcli_verified;
|
||||
int smcli_link_state;
|
||||
int provsioning_flag;
|
||||
server_param_t ems_servers;
|
||||
char connect_configured[SYS_T_MAX];
|
||||
char connect_command[SYS_T_MAX][CONNECT_COMMAND_LEN];
|
||||
char cli_command[SYS_T_MAX][CLI_COMMAND_LEN];
|
||||
}_client_param_t;
|
||||
|
||||
#endif
|
||||
143
proxy_c/smcli_client/src/tcp_client.c
Normal file
143
proxy_c/smcli_client/src/tcp_client.c
Normal file
@@ -0,0 +1,143 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
#include <netdb.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#define BUF_SIZE 1024
|
||||
|
||||
#define RES_LENGTH 10240
|
||||
|
||||
static int client_fd=0;
|
||||
static int client_connect_flag = -1;
|
||||
static char server_ip[16];
|
||||
static short server_port;
|
||||
|
||||
int connect_socket(char * server,int serverPort);
|
||||
int send_msg(int sockfd,char * sendBuff);
|
||||
char * recv_msg(int sockfd);
|
||||
int close_socket(int sockfd);
|
||||
|
||||
int init_socketfd()
|
||||
{
|
||||
int sockfd = -1;
|
||||
|
||||
if((sockfd=socket(AF_INET,SOCK_STREAM,0))<0){
|
||||
herror("Init socket error!");
|
||||
}
|
||||
|
||||
return sockfd;
|
||||
}
|
||||
|
||||
void tcp_init_client_fd()
|
||||
{
|
||||
client_fd = init_socketfd();
|
||||
|
||||
}
|
||||
|
||||
void tcp_connect_server(char *ip, u_short port)
|
||||
{
|
||||
tcp_init_client_fd();
|
||||
|
||||
strcpy(server_ip, ip);
|
||||
server_port = port;
|
||||
client_connect_flag = connect_socket(ip, port);
|
||||
}
|
||||
|
||||
int is_tcp_connected()
|
||||
{
|
||||
return client_connect_flag;
|
||||
}
|
||||
|
||||
/* * ********************************************************/
|
||||
int connect_socket(char * server,int serverPort)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
struct hostent * phost;
|
||||
|
||||
bzero(&addr,sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(serverPort);
|
||||
addr.sin_addr.s_addr = inet_addr(server);
|
||||
|
||||
if(addr.sin_addr.s_addr == INADDR_NONE){
|
||||
phost = (struct hostent*)gethostbyname(server);
|
||||
if(phost==NULL){
|
||||
herror("Init socket s_addr error!");
|
||||
return -1;
|
||||
}
|
||||
addr.sin_addr.s_addr =((struct in_addr*)phost->h_addr)->s_addr;
|
||||
}
|
||||
if(connect(client_fd,(struct sockaddr*)&addr, sizeof(addr))<0)
|
||||
{
|
||||
// perror("Connect server fail!");
|
||||
return -1; //0<><30>ʾ<EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD>-1<><31>ʾʧ<CABE><CAA7>
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int tcp_send_msg( u_char *sendbuf, short len)
|
||||
{
|
||||
int sendSize=0;
|
||||
|
||||
if((sendSize=send(client_fd,sendbuf,len,MSG_NOSIGNAL))<=0){
|
||||
close_socket(client_fd);
|
||||
herror("Send msg error!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return sendSize;
|
||||
}
|
||||
|
||||
int tcp_recv_msg(u_char *recvbuf)
|
||||
{
|
||||
int recLenth=0;
|
||||
|
||||
if(( recLenth=recv(client_fd,recvbuf, BUF_SIZE,0))==-1 )
|
||||
{
|
||||
close_socket(client_fd);
|
||||
return -1;
|
||||
}
|
||||
if(recLenth == 0)
|
||||
{
|
||||
close_socket(client_fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if( recLenth>0)
|
||||
recvbuf[recLenth] = 0;
|
||||
return recLenth;
|
||||
}
|
||||
|
||||
int tcp_check_connection()
|
||||
{
|
||||
if(client_connect_flag == -1)
|
||||
{
|
||||
client_connect_flag = connect_socket(server_ip, server_port);
|
||||
}
|
||||
|
||||
return client_connect_flag;
|
||||
}
|
||||
|
||||
/**************************************************
|
||||
*<2A>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD>
|
||||
* **********************************************/
|
||||
int close_socket(int sockfd)
|
||||
{
|
||||
client_connect_flag = -1;
|
||||
close(sockfd);
|
||||
|
||||
smcli_connection_is_broken();
|
||||
|
||||
tcp_init_client_fd();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user