/* 
** CDMA 2000 project, SMPP module
**
** File name: smpp_mib.c
** Written by Li Long at 2004-12-6
** CVS $Id: smpp_mib.c,v0.1 2004-12-6 17:03:14 lilong Exp $
**
*/

#include "./include/smpp.h"
#include "./include/smpp_ext.h"
#include "../../../plat/snmp/src/include/macro.h"

void	smpp_mibInit();
int		smpp_setMib(BYTE oidlen, DWORD *oid, BYTE *pData,WORD datalen);
int		smpp_getMib(BYTE oidlen, DWORD *oid, BYTE *pData,BYTE *vartype);
int 	smpp_get_system(u32 column, u32 *instance, u8 *pdata, u8 *vartype);
int 	smpp_set_system(u32 column, u32 *instance, u8 *pdata, u16 datalen);
int 	smpp_get_link(u32 column, u32 *instance, u8 *pdata, u8 *vartype);
int 	smpp_set_link(u32 column, u32 *instance, u8 *pdata, u16 datalen);
int 	smpp_getnext_link(u32 *instance);
int 	smpp_enable_link();
static u8	smpp_param_flag=0;//0:unchange 1:changed

/*
void smpp_set_smsc_param(BYTE *ptr, DWORD linkNo) {
	DWORD	smpp_param_oid[20] = {1,3,6,1,4,1,1373,1,3,3,5,2,2};
	
	smpp_param_oid[13] = linkNo;
	smpp_param_oid[14] = 0;
	set_response(15, smpp_param_oid, ptr, 25);
}
*/



int smpp_setMib(BYTE oidlen, DWORD *oid, BYTE *pData,WORD datalen)
{
	BYTE		len = 0;
	DWORD		instance;
	SMPP_PARAM	*pParam;

	smpp_param_flag = 1;

	switch(oid[SMPP_OIDLEN]) {
	case 1:		//Mesurement
		return (-1);
	case 2:		//Configuration
		instance	= oid[SMPP_OIDLEN+2];
		if (instance > MAX_SMPP_LINK)	return -1;
		pParam		= &smpp_param[instance];
		switch(oid[SMPP_OIDLEN+1]) {
		case 1:
			pParam->link_enable	= pData[0];
			len = 1;
			//link type
			pParam->link_type	= pData[1];
			len += 1;
			//server type
			pParam->server_type	= pData[2];
			len += 1;
			//session type
			pParam->session_type	= pData[3];
			len += 1;
			//system id
			memset(pParam->sys_id, 0, SMPP_SYSID_LEN);	//16
			memcpy(pParam->sys_id, pData+len, SMPP_SYSID_LEN);	
			pParam->sys_id[SMPP_SYSID_LEN]	= '\0';
			len += SMPP_SYSID_LEN;
			//password
			memset(pParam->password, 0, SMPP_PASSWD_LEN);	//9
			memcpy(pParam->password, pData+len, SMPP_PASSWD_LEN);
			pParam->password[SMPP_PASSWD_LEN]	= '\0';
			len += SMPP_PASSWD_LEN;
			//system type
			memset(pParam->system_type, 0, SMPP_SYSTYPE_LEN);	//13
			memcpy(pParam->system_type, pData+len, SMPP_SYSTYPE_LEN);
			pParam->system_type[SMPP_SYSTYPE_LEN]	= '\0';
			len += SMPP_SYSTYPE_LEN;
			//local gtt
			memset(pParam->localGTT, 0, SMPP_GTT_LEN);	//16
			memcpy(pParam->localGTT, pData+len, SMPP_GTT_LEN);
			pParam->localGTT[SMPP_GTT_LEN]	= '\0';
			len += SMPP_GTT_LEN;
			//remote gtt
			memset(pParam->remoteGTT, 0, SMPP_GTT_LEN);
			memcpy(pParam->remoteGTT, pData+len, SMPP_GTT_LEN);
			pParam->remoteGTT[SMPP_GTT_LEN]	= '\0';
			len += SMPP_GTT_LEN;
			//local ip
			memcpy(&pParam->local_ip, pData+len, 4);
			len += 4;
			//remote ip
			memcpy(&pParam->remote_ip, pData+len, 4);
			len += 4;
			//session init timer
			pParam->session_init_timer	= bcdtou32(pData+len, 4);
			len += 4;
			// enquire link timer
			pParam->enquire_link_timer	= bcdtou32(pData+len, 4);
			len += 4;
			//inactivity timer
			pParam->inactivity_timer	= bcdtou32(pData+len, 4);
			len += 4;
			//response timer
			pParam->response_timer	= bcdtou32(pData+len, 4);
			len += 4;
			//remote service number
			memset(pParam->service_number, 0, 8);
			memcpy(pParam->service_number, pData+len, 8);
			len += 8;			
			pParam->localSSN	= pData[len];
			len += 1;
			pParam->remoteSSN	= pData[len];
			len += 1;						
			break;
		default:
			return (-1);
		}
		break;
	case 3:		//Status
		switch (oid[SMPP_OIDLEN + 1]) {
		case 1:			//version, read only
			return -1;
		case 2:			//command
			switch (pData[0]) {
			case 0:		//reset
				smpp_reset();
				break;
			case 1:		//load
				smpp_loadParam();
				break;
			case 2:		//save
				smpp_writeParam();
				break;
			}
			return 1;
		case 3:			//status, read only
			return -1;
		}
		break;
	default:
		break;
	}
	return datalen;
}

int smpp_getMib(BYTE oidlen, DWORD *oid, BYTE *pData, BYTE *vartype)
{
	int				len=0, datalen = -1;
	DWORD			instance;
	SMPP_PARAM		*pParam;

	switch(oid[SMPP_OIDLEN])
	{
	case 1:	//Measurement		
		break;
	case 2:	//Configuration
		instance	= oid[SMPP_OIDLEN+2];
		if (instance > MAX_SMPP_LINK)	return -1;
		pParam		= &smpp_param[instance];
		switch(oid[SMPP_OIDLEN+1])
		{
		case 1:	//smpp parameter
			//link enable
			pData[0]	= pParam->link_enable;
			len = 1;
			//link type
			pData[1]	= pParam->link_type;
			len += 1;
			//server type
			pData[2]	= pParam->server_type;
			len += 1;
			//session type
			pData[3]	= pParam->session_type;
			len += 1;
			//system id
			memcpy(pData+len, pParam->sys_id, SMPP_SYSID_LEN);
			len += SMPP_SYSID_LEN;
			//password
			memcpy(pData+len, pParam->password, SMPP_PASSWD_LEN);
			len += SMPP_PASSWD_LEN;
			//system type
			memcpy(pData+len, pParam->system_type, SMPP_SYSTYPE_LEN);
			len += SMPP_SYSTYPE_LEN;
			//local gtt
			memcpy(pData+len, pParam->localGTT, SMPP_GTT_LEN);
			len += SMPP_GTT_LEN;
			//remote gtt
			memcpy(pData+len, pParam->remoteGTT, SMPP_GTT_LEN);
			len += SMPP_GTT_LEN;
			//local ip
			memcpy(pData+len, &pParam->local_ip, 4);
			len += 4;
			//remote ip 
			memcpy(pData+len, &pParam->remote_ip, 4);
			len += 4;
			//session init timer
			u32tobyte(pData+len, pParam->session_init_timer);
			len += 4;
			//enquire link timer
			u32tobyte(pData+len, pParam->enquire_link_timer);
			len += 4;
			//inactivity timer
			u32tobyte(pData+len, pParam->inactivity_timer);
			len += 4;
			//response timer
			u32tobyte(pData+len, pParam->response_timer);
			len += 4;
			//remote service number
			memcpy(pData+len, &pParam->service_number, 8);
			len += 8;
			pData[len]	= pParam->localSSN;
			len += 1;
			pData[len]	= pParam->remoteSSN;
			len += 1;			
			*vartype	= 4;
			datalen 	= len;
			break;
		default:
			break;
		}
		break;
	case 3:	//Status
		break;
	default:
		break;
	}

	return datalen;
}

int smpp_parseLine(char *str, char (*row)[128], int maxrow)
{
	char		*pstr = str;
	int 		len, index = 0, i;
	BOOL		black = 0;

	len = strlen(str);
	for(i = 0; i < len && index < maxrow; i++)
	{
		if(isspace(str[i]))
		{
			if(black == 0)
				pstr = str + i + 1;
			else
			{
				str[i] = '\0';
				if(strlen(pstr) > 128)
					pstr[127] = 0;
				sprintf(row[index++], "%s", pstr);
				pstr = str + i + 1;	
			}
			black = 0;
		}
		else
			black = 1;
	}
	if(black == 1)
	{
		if(strlen(pstr) > 128)
			pstr[127] = 0;
		sprintf(row[index++], "%s", pstr);
	}
	return index;
}

int smpp_loadParam()
{
	FILE	*fp;
	char	str[512] = "\0", *pChr;
	char	info[19][128];
	int		rtn;
	int		ver[3];
	BYTE	linkNo;

	fp = fopen(SMPP_CONF_FILE, "r");
 	if (fp == NULL)
	{
		printf("SMPP init parameters....search %s FAILED\n",SMPP_CONF_FILE);
		return	FAILURE;
	}

	while (fgets(str, 512, fp) != NULL) {
		if ((pChr = strchr(str, '#')) != NULL) {
			if((pChr = strstr(pChr,"SMPP Config file"))!=NULL)
			{
				if ((pChr = strchr(pChr, 'R')) != NULL)
				{
					ver[0] = atoi(pChr+1);
					ver[1] = atoi(pChr+3);
					ver[2] = atoi(pChr+5);
				}
			}
			continue;
		}

		rtn = smpp_parseLine(str, info, 19);
		if (rtn < 17) {
			//smpp_debug(SCCPDB_ERR, "<001>Invalid line in Local_Node Table, field count = %d", rtn);
			printf("Invalid line in ./conf/smpp.conf table, field count = %d\n", rtn);
			return FALSE;
		}
		else if(rtn < 19) 
		{	
			sprintf(info[17],"0");
			sprintf(info[18],"0");
		}

		linkNo	= atoi(info[0]);
		smpp_param[linkNo].link_enable	= atoi(info[1]);
		smpp_param[linkNo].link_type	= atoi(info[2]);
		smpp_param[linkNo].server_type	= atoi(info[3]);
		smpp_param[linkNo].session_type	= atoi(info[4]);

		if (strncmp(info[5], "--", 2) == 0)
			strcpy(smpp_param[linkNo].sys_id, "");
		else
			sprintf(smpp_param[linkNo].sys_id, "%s", info[5]);

		if (strncmp(info[6], "--", 2) == 0)
			strcpy(smpp_param[linkNo].password, "");
		else
			sprintf(smpp_param[linkNo].password, "%s", info[6]);

		if (strncmp(info[7], "--", 2) == 0)
			strcpy(smpp_param[linkNo].system_type, "");
		else
			sprintf(smpp_param[linkNo].system_type, "%s",	info[7]);
		
		if (strncmp(info[8], "--", 2) == 0)
			strcpy(smpp_param[linkNo].localGTT, "");
		else
			sprintf(smpp_param[linkNo].localGTT,    "%s",	info[8]);
		
		if (strncmp(info[9], "--", 2) == 0)
			strcpy(smpp_param[linkNo].remoteGTT, "");
		else
			sprintf(smpp_param[linkNo].remoteGTT,   "%s",	info[9]);

		smpp_param[linkNo].local_ip				= inet_addr(info[10]);
		smpp_param[linkNo].remote_ip			= inet_addr(info[11]);
		smpp_param[linkNo].session_init_timer	= atol(info[12]);
		smpp_param[linkNo].enquire_link_timer	= atol(info[13]);
		smpp_param[linkNo].inactivity_timer		= atol(info[14]);
		smpp_param[linkNo].response_timer		= atol(info[15]);

		if (strncmp(info[16], "--", 2) == 0)
			strcpy(smpp_param[linkNo].service_number, "");
		else
			sprintf(smpp_param[linkNo].service_number, "%s", info[16]);
			
		smpp_param[linkNo].localSSN	= atoi(info[17]);
		smpp_param[linkNo].remoteSSN	= atoi(info[18]);	
		
		if(ver[2] == 1)
			if(smpp_param[linkNo].link_enable & 0x01)
				smpp_param[linkNo].link_enable = 0x81;
		/*
		printf("link %d: link_enable=%d, link_type=%d; session_type=%d; sys_id=%s; password=%s; \
			system_type=%s; localGTT=%s; retmoteGTT=%s; local_ip=%s; remote ip=%s; \
			session init timer=%d; enquire link timer=%d; inactivity timer=%d; response timer=%d \
			remote service number: %s\n",
			linkNo, smpp_param[linkNo].link_enable, smpp_param[linkNo].link_type, smpp_param[linkNo].session_type, smpp_param[linkNo].sys_id, smpp_param[linkNo].password,
			smpp_param[linkNo].system_type, smpp_param[linkNo].localGTT, smpp_param[linkNo].remoteGTT, info[8], info[9],
			smpp_param[linkNo].session_init_timer,  smpp_param[linkNo].enquire_link_timer, smpp_param[linkNo].inactivity_timer, smpp_param[linkNo].response_timer, 
			smpp_param[linkNo].service_number
		);
		*/
	}
	fclose(fp);
	return TRUE;
}

int smpp_writeParam()
{
	FILE *fp;
	int i;
	struct in_addr	addr;

	if((fp = fopen(SMPP_CONF_FILE,"w")) == NULL)
		return	FAILURE;

	fprintf(fp,"#SMPP Config file (%s)\n",SMPP_MODULE_VERSION);
	fprintf(fp,"#Copy this file to ./conf/smpp.conf to set global options\n");
	fprintf(fp,"#No   lkEn   lkType   serverType sessionType   sysID   pwd   sysType   LGTT   RGTT   LIP   RIP   sessionTimer   enqTimer   inactTimer   rspTimer   ServiceNum   localSSN   remoteSSN\n");
	for(i=0; i< MAX_SMPP_LINK; i++)
	{
		fprintf(fp,"%d   ", i);
		fprintf(fp,"%d   ", smpp_param[i].link_enable);
		fprintf(fp,"%d   ", smpp_param[i].link_type);
		fprintf(fp,"%d   ", smpp_param[i].server_type);
		fprintf(fp,"%d   ", smpp_param[i].session_type);

		if (smpp_param[i].sys_id[0] == 0)
			strcpy(smpp_param[i].sys_id, "--");

		fprintf(fp,"%s   ", smpp_param[i].sys_id);

		if (smpp_param[i].password[0] == 0)
			strcpy(smpp_param[i].password, "--");

		fprintf(fp,"%s   ", smpp_param[i].password);

		if (smpp_param[i].system_type[0] == 0)
			fprintf(fp,"%s   ", "--");
		else
			fprintf(fp,"%s   ", smpp_param[i].system_type);

		if (smpp_param[i].localGTT[0] == 0)
			strcpy(smpp_param[i].localGTT, "--");
		fprintf(fp,"%s   ", smpp_param[i].localGTT);

		if (smpp_param[i].remoteGTT[0] == 0)
			strcpy(smpp_param[i].remoteGTT, "--");
		fprintf(fp,"%s   ", smpp_param[i].remoteGTT);

		addr.s_addr	= smpp_param[i].local_ip;
		fprintf(fp,"%s   ", inet_ntoa(addr));

		addr.s_addr	= smpp_param[i].remote_ip;
		fprintf(fp,"%s   ", inet_ntoa(addr));

		fprintf(fp,"%u   ", smpp_param[i].session_init_timer);
		fprintf(fp,"%u   ", smpp_param[i].enquire_link_timer);
		fprintf(fp,"%u   ", smpp_param[i].inactivity_timer);
		fprintf(fp,"%u   ", smpp_param[i].response_timer);

		if (smpp_param[i].service_number[0] == 0)
			strcpy(smpp_param[i].service_number, "--");
		fprintf(fp, "%s   ", smpp_param[i].service_number);
		
		fprintf(fp,"%d   ", smpp_param[i].localSSN);
		fprintf(fp,"%d\n", smpp_param[i].remoteSSN);
	}
	fclose(fp);
	
	return TRUE;
}

void smpp_checkParam()
{
	if(smpp_param_flag)
	{
		smpp_writeParam();
		smpp_param_flag=0;		
	}
}


int smpp_enable_link()
{
	int i;
	for (i=0; i<MAX_SMPP_LINK; i++)
	{
		if ((smpp_param[i].link_enable&0x80)==0)
		{
			smpp_param[i].link_enable = 0x80;
			memset(smpp_param[i].service_number,0,8);
			smpp_param[i].link_type	= SMPP_UDP;
			smpp_param[i].server_type = SMPP_CLIENT;
			smpp_param[i].session_type = BIND_TX;
			memset(smpp_param[i].sys_id,0,SMPP_SYSID_LEN);
			memset(smpp_param[i].password,0,SMPP_PASSWD_LEN);
			memset(smpp_param[i].system_type,0,SMPP_SYSTYPE_LEN);
			memset(smpp_param[i].localGTT,0,SMPP_GTT_LEN);
			memset(smpp_param[i].remoteGTT,0,SMPP_GTT_LEN);
			strcpy(smpp_param[i].sys_id,"--");
			strcpy(smpp_param[i].password,"--");
			strcpy(smpp_param[i].system_type, "--");
			sprintf(smpp_param[i].localGTT,"%s","--");
			sprintf(smpp_param[i].remoteGTT,"%s","--");
			strcpy(smpp_param[i].service_number, "--");		
			smpp_param[i].local_ip = 0;
			smpp_param[i].remote_ip = 0;
			smpp_param[i].session_init_timer = 5;
			smpp_param[i].enquire_link_timer = 10;
			smpp_param[i].inactivity_timer = 5;
			smpp_param[i].response_timer = 5;
			smpp_param[i].localSSN = 0;
			smpp_param[i].remoteSSN = 0;
			return i;
		}
	}
	return -1;
}


int smpp_getnext_link(u32 *instance)
{
	int i;
	for (i=*instance; i<MAX_SMPP_LINK; i++)
	{		
		if (smpp_param[i].link_enable&0x80)
		{	
			*instance = i;
			return 1;
		}
	}	
	return 0;
}

int smpp_set_link(u32 column, u32 *instance, u8 *pdata, u16 datalen)
{
	SMPP_PARAM	*pParam;
	int 	ret;

	smpp_param_flag = 1;

	if(column	==	1)
	{
		ret = smpp_enable_link();
		if(ret == -1)
		{	
			strcpy((char*)pdata,"Maximum Link is 32.");
			return -2;
		}
		else
		{	
			pdata[0] = ret;
			return datalen;
		}
	}

	if (instance[0] >= MAX_SMPP_LINK)	
		return -1;
	pParam = &smpp_param[instance[0]];
	
	switch(column) 
	{
		case 2:	//remote service number
			if (datalen > 8)
				return -1;						
			memset(pParam->service_number,0,8);
			SET_OCTETSTRING(pParam->service_number, datalen);
			break;			
		case 3:	//link type
			SET_INTEGER(pParam->link_type);
			break;
		case 4:	//server type
			SET_INTEGER(pParam->server_type);
			break;
		case 5:	//session type
			SET_INTEGER(pParam->session_type);
			break;
		case 6:	//system id
			if (datalen > SMPP_SYSID_LEN)
				return -1;	
			memset(pParam->sys_id,0,SMPP_SYSID_LEN);
			SET_OCTETSTRING(pParam->sys_id, datalen);			
			break;
		case 7:	//password
			if (datalen > SMPP_PASSWD_LEN)
				return -1;	
			memset(pParam->password,0,SMPP_PASSWD_LEN);
			SET_OCTETSTRING(pParam->password, datalen);						
			break;
		case 8:	//system type
			if (datalen > SMPP_SYSTYPE_LEN)
				return -1;	
			memset(pParam->system_type,0,SMPP_SYSTYPE_LEN);
			SET_OCTETSTRING(pParam->system_type, datalen);					
			break;
		case 9:	//local gtt
			if (datalen > SMPP_GTT_LEN)
				return -1;	
			memset(pParam->localGTT,0,SMPP_GTT_LEN);
			SET_OCTETSTRING(pParam->localGTT, datalen);						
			break;
		case 10:	//remote gtt
			if (datalen > SMPP_GTT_LEN)
				return -1;	
			memset(pParam->remoteGTT,0,SMPP_GTT_LEN);
			SET_OCTETSTRING(pParam->remoteGTT, datalen);									
			break;
		case 11:	//local ip
			SET_IP(&pParam->local_ip);	
			break;
		case 12:	//remote ip
			SET_IP(&pParam->remote_ip);
			break;
		case 13:	//session init timer
			SET_INTEGER(pParam->session_init_timer);
			break;
		case 14:	// enquire link timer
			SET_INTEGER(pParam->enquire_link_timer);
			break;
		case 15:	//inactivity timer
			SET_INTEGER(pParam->inactivity_timer);
			break;
		case 16:	//response timer
			SET_INTEGER(pParam->response_timer);			
			break;
		case 17:	
			SET_INTEGER(pParam->localSSN);
			break;
		case 18:	
			SET_INTEGER(pParam->remoteSSN);
			break;
		case 19://enable/disable flag
		{
			u8 temp8;
			SET_U8(temp8);
			temp8 &= 0x01;
			if(temp8 == 1)//enable
				pParam->link_enable |= 0x01;
			else
			{
				pParam->link_enable &= ~0x01;
				init_link(instance[0]);
			}
			break;			
		}
		case 20://delete
		{
			u8 temp8;
			SET_U8(temp8);
			if(temp8 == 6)//delete
			{	
				pParam->link_enable = 0;
				init_link(instance[0]);
			}
			break;
		}
		default:
			break;
	}
	return datalen;
}

int smpp_get_link(u32 column, u32 *instance, u8 *pdata, u8 *vartype)
{
	int				datalen = -1;
	SMPP_PARAM		*pParam;

	if (instance[0] >= MAX_SMPP_LINK)	
		return -1;
	pParam		= &smpp_param[instance[0]];
	switch(column)
	{
		case 1:	//index
			GET_INTEGER(instance[0]);
			break;	
		case 2:	//remote service number  (LinkAlias)
			if((datalen = strlen(pParam->service_number)) > 8)
				datalen = 8;
			GET_OCTETSTRING(pParam->service_number, datalen);
			break;				
		case 3:	//link type
			GET_INTEGER(pParam->link_type);
			break;
		case 4:	//server type
			GET_INTEGER(pParam->server_type);
			break;
		case 5:	//session type
			GET_INTEGER(pParam->session_type);
			break;
		case 6:	//system id
			if((datalen = strlen(pParam->sys_id)) > SMPP_SYSID_LEN)
				datalen = SMPP_SYSID_LEN;									
			GET_OCTETSTRING(pParam->sys_id, datalen);
			break;	
		case 7:	//password
			if((datalen = strlen(pParam->password)) > SMPP_PASSWD_LEN)
				datalen = SMPP_PASSWD_LEN;									
			GET_OCTETSTRING(pParam->password, datalen);
			break;	
		case 8:	//system type
			if((datalen = strlen(pParam->system_type)) > SMPP_SYSTYPE_LEN)
				datalen = SMPP_SYSTYPE_LEN;						
			GET_OCTETSTRING(pParam->system_type, datalen);
			break;	
		case 9:	//local gtt
			if((datalen = strlen(pParam->localGTT)) > SMPP_GTT_LEN)
				datalen = SMPP_GTT_LEN;						
			GET_OCTETSTRING(pParam->localGTT, datalen);
			break;	
		case 10:	//remote gtt
			if((datalen = strlen(pParam->remoteGTT)) > SMPP_GTT_LEN)
				datalen = SMPP_GTT_LEN;			
			GET_OCTETSTRING(pParam->remoteGTT, datalen);		
			break;	
		case 11:	//local ip
			GET_IP(&pParam->local_ip);		
			break;	
		case 12:	//remote ip 
			GET_IP(&pParam->remote_ip);		
			break;	
		case 13:	//session init timer
			GET_INTEGER(pParam->session_init_timer);
			break;	
		case 14:	//enquire link timer
			GET_INTEGER(pParam->enquire_link_timer);
			break;	
		case 15:	//inactivity timer
			GET_INTEGER(pParam->inactivity_timer);
			break;	
		case 16:	//response timer
			GET_INTEGER(pParam->response_timer);
			break;	
		case 17:	
			GET_INTEGER(pParam->localSSN);
			break;	
		case 18:	
			GET_INTEGER(pParam->remoteSSN);
			break;
		case 19:	//enable flag
			GET_U8(pParam->link_enable&0x01);
			break;			
		case 20:	//link enable			
			GET_U8(1);
			break;			
		default:
			break;
	}
	return datalen;
}
int smpp_get_system(u32 column, u32 *instance, u8 *pdata, u8 *vartype)
{
	int	datalen = -1;
	
	GET_OCTETSTRING(" ",1);
	return datalen;
}

int smpp_set_system(u32 column, u32 *instance, u8 *pdata, u16 datalen)
{
	switch(column)
	{
		case 1:
			switch (pdata[0]) 
			{
				case 0:		//reset
					smpp_reset();
					break;
				case 1:		//load
					smpp_loadParam();
					break;
				case 2:		//save
					smpp_writeParam();
					break;
			}
	}
	return datalen;
}

static struct snmp_table_profile smpp_tables[] = {
	/****** Parameter table ******/
	{
		.name = "system",
		.index.len = 13,
		.index.oid = {1, 3, 6, 1, 4, 1, 1373, 2, 3, 2, 18, 2, 1},//1.3.6.1.4.1.1373.2.3.2.18.2.1
		.column = {0},
		.level = 0,
		.get_instance = NULL,
		.get_resp = smpp_get_system,
		.set_resp = smpp_set_system
	},
	{
		.name = "smpp link",
		.index.len = 14,
		.index.oid = {1, 3, 6, 1, 4, 1, 1373, 2, 3, 2, 18, 2, 2, 1},//1.3.6.1.4.1.1373.2.3.2.18.2.2.1
		.column = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 0},
		.level = 1,
		.get_instance = smpp_getnext_link,
		.get_resp = smpp_get_link,
		.set_resp = smpp_set_link
	},
};

static struct snmp_register smpp_register = {
	.name = "SMPP",
	.prefix_len = 11,
	.prefix_oid = {1, 3, 6, 1, 4, 1, 1373, 2, 3, 2, 18},
	.num_of_table = sizeof(smpp_tables)/sizeof(struct snmp_table_profile),
	.table = smpp_tables,
	.default_get_resp = smpp_getMib,
	.default_set_resp = smpp_setMib
};


void smpp_mibInit()
{
	int 	i;
//	DWORD	oid[20] = SMPP_OID;

	for (i=0; i<MAX_SMPP_LINK; i++) {
		linkAttachFlag[i]	= 0;
		smpp_TCPClientFlag[i]	= 0;
		smpp_param[i].link_enable	= 0;
		smpp_param[i].link_type	= SMPP_UDP;
		smpp_param[i].server_type = SMPP_CLIENT;
		smpp_param[i].session_type = BIND_TX;
		smpp_param[i].localSSN = 0;
		smpp_param[i].remoteSSN = 0;
		strcpy(smpp_param[i].sys_id,"Test");
		strcpy(smpp_param[i].password,"123456");
		strcpy(smpp_param[i].system_type, "GSM");
		sprintf(smpp_param[i].localGTT,"%s","--");
		sprintf(smpp_param[i].remoteGTT,"%s","--");
		smpp_param[i].local_ip			= 0;
		smpp_param[i].remote_ip			= 0;
		smpp_param[i].session_init_timer= 5;
		smpp_param[i].enquire_link_timer= 10;
		smpp_param[i].inactivity_timer	= 5;
		smpp_param[i].response_timer	= 5;
		strcpy(smpp_param[i].service_number, "--");
		smpp_link[i].seq_num			= 0;

		Mysock.Sockets[i]				= 0;
	}

//	inquire_setmsg(SMPP_OIDLEN, oid, smpp_setMib);
//	inquire_getmsg(SMPP_OIDLEN, oid, smpp_getMib);
	
	register_snmp_table(&smpp_register);

}

