
/**************************************************/
/*Title:  sccpparam.c                             */
/*Descr:  sccp parameter management               */
/*Author: Liang Hanxi                             */
/*Create: 2002-5-7                                */

/**************************************************/
#include "./include/sccp.h"

/*===========export================*/
int sccp_loadparam (  );
void sccp_saveparam (  );
int sccp_setparam ( DWORD * oid, BYTE * pdata, WORD datalen );
int sccp_getparam ( DWORD * oid, BYTE * pdata, BYTE * vartype );

/*===========import================*/
extern int Str2Digits ( BYTE * pDigits, char *pStr, int DigitsLen );
extern int Str2Bcd ( BYTE * pBcd, char *pStr, int maxLen );
extern int Str2Array ( BYTE * pArray, char *str, int ArrayLen );
extern int Bcd2Digits ( BYTE * pDigits, BYTE * pBcd, int maxLen );
extern int BcdLen ( BYTE * pBcd, int maxLen );
extern int ParseLine ( char *str, char ( *row )[128], int maxrow );

extern void spLogDebug ( DWORD mask, const char *fmt, ... );

/*===========private================*/
static int SccpGetLocalIP (  );
int ParseLocalNode ( char *str );
static void ParseRouteInfo ( char *str );
static void ParseRLSSN ( char *str );
static void ParseGTTAttributeOMC ( char *str );

/* by simon at 23/9/26 */
extern int RelatedSSNNum;
extern RL_SSN RelatedSSN[SCCP_RLSSN_NUM];
extern SCOC_BUF ScocBuf;
extern SCCP_ROUTE RouteList[SCCP_ROUTE_NUM];
extern LOCAL_SSN LocalSSN[256];
extern SCCP_ROUTE RouteList[SCCP_ROUTE_NUM];
extern SCCP_OPT SCCP_Param;
extern int RelatedSPCNum;
extern RL_SPC RelatedSPC[SCCP_RLSPC_NUM];
extern GTTATT_OMC GTTAttribute[SCCP_ROUTE_NUM];
extern SCCP_CSTA SccpCsta[96];
extern DWORD SccpCstaInd;
extern SCCP_Capture_Buf SCCPCapBuf;

int GetMSISDNOfSSN ( BYTE ssn, BYTE * msisdn )
{
    int len;

    len = Bcd2Digits ( msisdn, LocalSSN[ssn].msisdn, MAX_DIGITS ) % ( MAX_DIGITS + 1 );
//    memset ( msisdn + len, 0xFF, MAX_DIGITS - len );
    memset ( msisdn + len, 0xFF, 8 - len );
    return len;
}

int sccp_GetSSNType ( BYTE ssn )
{
    return mtp3_ansiFlag ( LocalSSN[ssn].NetID );
}

int sccp_loadparam (  )
{
    FILE *fp;
    int i, j;
    char str[200] = "\0", *pChr, *pKey;
    BYTE state = 0;

    SccpGetLocalIP (  );
    for ( i = 0; i < 256; i++ )
    {
        LocalSSN[i].status[0] = LocalSSN[i].status[1] = 0;
        LocalSSN[i].ip[0] = LocalSSN[i].ip[1] = 0xFFFFFFFF;
        LocalSSN[i].local = 0;
        LocalSSN[i].NetID = 0;
        memset ( LocalSSN[i].msisdn, 0xFF, MAX_DIGITS );
    }
	for ( i = 0; i < SCCP_ROUTE_NUM; i++)
	{
		memset ( &RouteList[i], 0, sizeof ( SCCP_ROUTE ) );
		memset ( RouteList[i].StartDigits, 0xFF, MAX_DIGITS * 2 );
		memset ( RouteList[i].ReplaceDigits, 0xFF, MAX_DIGITS );
		memset ( RouteList[i].acn_ver, 0x02, 48 );
	}

    RelatedSSNNum = 0;

    fp = fopen ( SCCP_CONF_FILE, "r" );
    if( fp == NULL )
    {
        printf ( "GTT Initializing: Config File %s not found\n", SCCP_CONF_FILE );
        return -1;
    }

    while ( fgets ( str, 200, fp ) != NULL )
    {
        if( ( pChr = strchr ( str, '#' ) ) != NULL )
            pChr[0] = '\0';

        if( ( pKey = strstr ( str, "[" ) ) != NULL )
        {
            if( ( pKey = strstr ( str, "[Local Node]" ) ) != NULL )
                state = 1;
            else if( ( pKey = strstr ( str, "[GTT_Table]" ) ) != NULL )
                state = 2;
            else if( ( pKey = strstr ( str, "[RL_SSN]" ) ) != NULL )
                state = 3;
            else if( ( pKey = strstr ( str, "[GTT_ATTRIBUTE]" ) ) != NULL )
                state = 4;
            continue;
        }
        switch ( state )
        {
        case 0:
            continue;
        case 1:
            if( strlen ( str ) < 8 )
                continue;
            ParseLocalNode ( str );
            break;
        case 2:
            if( strlen ( str ) < 15 )
                continue;
            ParseRouteInfo ( str );
            break;
        case 3:
            if( strlen ( str ) < 3 )
                continue;
            ParseRLSSN ( str );
            break;
        case 4:
            ParseGTTAttributeOMC ( str );
            break;
        }
    }
    fclose ( fp );

    //Load Related SPC===========>
    RelatedSPCNum = 0;
    for ( i = 0; i < RelatedSSNNum; i++ )
    {
        for ( j = 0; j < RelatedSPCNum && j < SCCP_RLSPC_NUM; j++ )
        {
            if( RelatedSPC[j].DPC == RelatedSSN[i].DPC && RelatedSPC[j].NetID == RelatedSSN[i].NetID )
                continue;

            RelatedSPC[RelatedSPCNum].DPC = RelatedSSN[i].DPC;
            RelatedSPC[RelatedSPCNum].NetID = RelatedSSN[i].NetID;
            RelatedSPC[RelatedSPCNum].status = 1;
            RelatedSPCNum++;
        }
    }

    return 1;
}

void sccp_saveparam (  )
{
    struct in_addr addr;
    SCCP_ROUTE *pRoute;
    FILE *fp;
    int i;
    char str1[128], str2[64], host0[24], host1[24], *pCh = NULL;
    char cNP[8], cTT[8];

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

    fprintf ( fp, "#SCCP Config file (R%dV%d_%02d)\r\n\r\n", SCCP_Param.version[0], SCCP_Param.version[1], SCCP_Param.version[2] );

    fprintf ( fp, "[Local Node]\r\n\
#ssn NetID msisdn          ip0             ip1\r\n" );
    for ( i = 2; i < 256; i++ )
    {
        if( LocalSSN[i].status[0] == 0 && LocalSSN[i].status[1] == 0 )
            continue;

        if( LocalSSN[i].ip[0] > 0 && LocalSSN[i].ip[0] != 0xFFFFFFFF )
        {
            /*                      if (LocalSSN[i].ip[0] == SCCP_Param.ip)
               {
               sprintf(host0,"localhost");
               }
               else */
            {
                addr.s_addr = LocalSSN[i].ip[0];
                strcpy ( host0, inet_ntoa ( addr ) );
            }
        }
        else
            strcpy ( host0, "-" );
        if( LocalSSN[i].ip[1] > 0 && LocalSSN[i].ip[1] != 0xFFFFFFFF )
        {
            /*                      if (LocalSSN[i].ip[1] == SCCP_Param.ip)
               {
               sprintf(host1,"localhost");
               }
               else */
            {
                addr.s_addr = LocalSSN[i].ip[1];
                strcpy ( host1, inet_ntoa ( addr ) );
            }
        }
        else
            strcpy ( host1, "-" );

        Bcd2Str ( str1, LocalSSN[i].msisdn, LocalSSN[i].msisdn_len % MAX_DIGITS );
        if( ( pCh = strchr ( str1, 'F' ) ) != NULL )
            *pCh = 0;

        if( strlen ( str1 ) == 0 )
            strcpy ( str1, "-" );

        fprintf ( fp, "%-4d %-5d %-15s %-15s %-15s\r\n", i, LocalSSN[i].NetID, str1, host0, host1 );
    }

    fprintf ( fp, "[GTT_Table]\r\n" "#No EN NP TT StartDigits     EndDigits       NI SPC  SSN RI AI S E N Rep\r\n" );
    for ( i = 0; i < SCCP_ROUTE_NUM; i++ )
    {
//Commented by Roy Jiang for the disabled GTT entries
//        if( RouteList[i].avail == 0 )
//            continue;
        pRoute = &RouteList[i];
        if( pRoute->len > 0 )
        {

            Bcd2Str ( str1, pRoute->StartDigits, pRoute->len % MAX_DIGITS );
            if( ( pCh = strchr ( str1, 'F' ) ) != NULL )
                *pCh = 0;
            Bcd2Str ( str2, pRoute->EndDigits, pRoute->len % MAX_DIGITS );
            if( ( pCh = strchr ( str2, 'F' ) ) != NULL )
                *pCh = 0;
        }
        else
        {
            strcpy ( str1, "-" );
            strcpy ( str2, "-" );
        }

        if( pRoute->NP == 0 )
            sprintf ( cNP, "-" );
        else
            sprintf ( cNP, "%d", pRoute->NP );

        if( pRoute->TT == 0 )
            sprintf ( cTT, "-" );
        else
            sprintf ( cTT, "%d", pRoute->TT );

        fprintf ( fp, "%-3d %d %s %s %-15s %-15s %d %02X%02X%02X %d  %d  %d  ", i, RouteList[i].avail, cNP, cTT, str1, str2, pRoute->NetID, pRoute->DPC[0], pRoute->DPC[1], pRoute->DPC[2], pRoute->SSN, pRoute->RI,
                  pRoute->AI );
        if( pRoute->convert )
        {
            Bcd2Str ( str1, pRoute->ReplaceDigits, pRoute->replace_len % MAX_DIGITS );
            if( ( pCh = strchr ( str1, 'F' ) ) != NULL )
                *pCh = 0;
            fprintf ( fp, "%-1d% -1d %-1d %-15s\r\n", pRoute->ReplaceStart, pRoute->ReplaceEnd, pRoute->OutNP, str1 );
        }
        else
            fprintf ( fp, "\r\n" );
    }

    fprintf ( fp, "\r\n[RL_SSN]\r\n#NetID  DPC      SSN\r\n " );
    for ( i = 0; i < RelatedSSNNum; i++ )
    {
        if( RelatedSSN[i].status == 0 )
            continue;
        fprintf ( fp, "%-5d 0x%-6X %-d\r\n", RelatedSSN[i].NetID, RelatedSSN[i].DPC, RelatedSSN[i].SSN );
    }

    fprintf ( fp, "\r\n[GTT_ATTRIBUTE]\r\nIdx\r\n " );
    for ( i = 0; i < 256; i++ )
    {
        if( RouteList[i].avail == 0 )
            continue;
        Bcd2Str ( str1, GTTAttribute[i].attribute, SCCP_MAX_GTT_ATTRIBUTE * 2 );
        fprintf ( fp, "%-3d %s\r\n", i, str1 );
    }
    fclose ( fp );

}

int sccp_setparam ( DWORD * oid, BYTE * pdata, WORD datalen )
{
    SCCP_ROUTE *pRoute;
    RL_SSN *pRLSSN;
    LOCAL_SSN *pLocalSSN;
    LOCAL_SSN OldLocalSSN;
    u_short instance, i;

    instance = oid[1];
    switch ( oid[0] )
    {
    case 1:
        spLogDebug ( SCCPDB_SNMP, "Set Local Node. ssn = %d", instance );
        if( instance >= 256 )
            return -1;

        pLocalSSN = &LocalSSN[instance];

        /* copy the old important parameter */
        OldLocalSSN.NetID = pLocalSSN->NetID;
        OldLocalSSN.ip[0] = pLocalSSN->ip[0];
        OldLocalSSN.ip[1] = pLocalSSN->ip[1];
        /* copy the old important parameter */

        pLocalSSN->NetID = pdata[0];
        memcpy ( &pLocalSSN->msisdn, pdata + 1, MAX_DIGITS );
        memcpy ( &pLocalSSN->ip[0], pdata + MAX_DIGITS + 1, 8 );
        LocalSSN[instance].msisdn_len = ( BcdLen ( LocalSSN[instance].msisdn, MAX_DIGITS ) + 1 ) / 2;

        /* if old and new important parameter are same then return */
        if( OldLocalSSN.NetID == pLocalSSN->NetID && OldLocalSSN.ip[0] == pLocalSSN->ip[0] && OldLocalSSN.ip[1] == pLocalSSN->ip[1] )
            return 19;
        /* if old and new important parameter are same then return */

        LocalSSN[instance].local = 0;
        LocalSSN[instance].status[0] = LocalSSN[instance].status[1] = 0;
        if( LocalSSN[instance].ip[0] > 0 && LocalSSN[instance].ip[0] != 0xFFFFFFFF )
        {
            if( LocalSSN[instance].ip[0] == SCCP_Param.ip )
            {
                LocalSSN[instance].status[0] = 1;
                LocalSSN[instance].local = 1;
            }
            else
            {
                LocalSSN[instance].status[0] = 3;
                LocalSSN[instance].timeout[0] = T_hbrecv;
            }
        }
        if( LocalSSN[instance].ip[1] > 0 && LocalSSN[instance].ip[1] != 0xFFFFFFFF )
        {
            if( LocalSSN[instance].ip[1] == SCCP_Param.ip )
            {
                LocalSSN[instance].status[1] = 1;
                LocalSSN[instance].local = 2;
            }
            else
            {
                LocalSSN[instance].status[1] = 3;
                LocalSSN[instance].timeout[1] = T_hbrecv;
            }
        }

        SCCP_Param.T_reset = 100;
        return 19;
    case 2:                    //GTT Table
        spLogDebug ( SCCPDB_SNMP, "Set GTT Table.instance=%d", instance );
        if( instance >= SCCP_ROUTE_NUM )
            return -1;

        SCCP_Param.T_reset = 100;       //2s

        pRoute = &RouteList[instance];
        memcpy ( pRoute, pdata, 43 );

        pRoute->len = ( BcdLen ( pRoute->StartDigits, MAX_DIGITS ) + 1 ) / 2;
        pRoute->replace_len = ( BcdLen ( pRoute->ReplaceDigits, MAX_DIGITS ) + 1 ) / 2;
        if( pRoute->ReplaceStart >= 1 && pRoute->ReplaceStart <= pRoute->ReplaceEnd )
        	pRoute->convert = 1;
        else
            pRoute->convert = 0;
        SCCP_Param.T_reset = 100;
        return 43;
    case 3:
        spLogDebug ( SCCPDB_SNMP, "Set related subsystem.instance=%d", instance );
        if( instance >= SCCP_RLSSN_NUM )
            return -1;
        pRLSSN = &RelatedSSN[instance];
        if( pdata[0] > 0 )
        {
            pRLSSN->status = 1;
            pRLSSN->NetID = pdata[1];
            pRLSSN->DPC = pdata[2] * 0x10000 + pdata[3] * 0x100 + pdata[4];
            pRLSSN->SSN = pdata[5];

            for ( i = 0; i < RelatedSPCNum; i++ )
            {
                if( RelatedSPC[i].DPC == pRLSSN->DPC && RelatedSPC[i].NetID == pRLSSN->NetID )
                    continue;

                RelatedSPC[RelatedSPCNum].DPC = pRLSSN->DPC;
                RelatedSPC[RelatedSPCNum].NetID = pRLSSN->NetID;
                RelatedSPC[RelatedSPCNum].status = 1;
                RelatedSPCNum++;
            }

            if( instance + 1 > RelatedSSNNum )
                RelatedSSNNum = instance + 1;
        }
        else
        {
            pRLSSN->status = 0;
            if( instance == RelatedSSNNum - 1 )
                while ( RelatedSSN[RelatedSSNNum - 1].status == 0 && RelatedSSNNum > 0 )
                    RelatedSSNNum--;
        }
        return 6;
    case 4:                    //GTT Attribute for omc
        if( instance >= SCCP_ROUTE_NUM )
            return -1;
        memcpy ( &GTTAttribute[instance], pdata, SCCP_MAX_GTT_ATTRIBUTE );
        return SCCP_MAX_GTT_ATTRIBUTE;
    default:
        break;
    }
    return -1;
}

int sccp_getparam ( DWORD * oid, BYTE * pdata, BYTE * vartype )
{
    SCCP_ROUTE *pRoute;
    RL_SSN *pRLSSN;
    LOCAL_SSN *pLocalSSN;
    int instance;

    instance = oid[1];
    switch ( oid[0] )
    {
    case 1:
        spLogDebug ( SCCPDB_SNMP, "get Local Node.ssn=%ld\n", instance );
        if( instance >= 256 )
            return -1;
        pLocalSSN = &LocalSSN[instance];
        pdata[0] = pLocalSSN->NetID;
        memcpy ( pdata + 1, &pLocalSSN->msisdn, MAX_DIGITS );
        memcpy ( pdata + MAX_DIGITS + 1, &pLocalSSN->ip[0], 8 );
        *vartype = 4;
        return 19;
    case 2:                    //GTT Table
        spLogDebug ( SCCPDB_SNMP, "get gtt table.instance=%ld\n", instance );
        if( instance >= SCCP_ROUTE_NUM )
            return -1;
        *vartype = 4;

        pRoute = &RouteList[instance];
        memcpy ( pdata, pRoute, 43 );
        return 43;
    case 3:
        spLogDebug ( SCCPDB_SNMP, "Get related subsystem.instance=%d", instance );
        if( instance > RelatedSSNNum )
            return -1;
        pRLSSN = &RelatedSSN[instance];
        *vartype = 4;
        if( pRLSSN->status == 0 )
            return -1;
        pdata[0] = 1;
        pdata[1] = pRLSSN->NetID;
        pdata[2] = ( pRLSSN->DPC >> 16 ) & 0xFF;
        pdata[3] = ( pRLSSN->DPC >> 8 ) & 0xFF;
        pdata[4] = pRLSSN->DPC & 0xFF;
        pdata[5] = pRLSSN->SSN;
        return 6;
    case 4:                    //GTT Attribute
        spLogDebug ( SCCPDB_SNMP, "get gtt attribute table.instance=%ld\n", instance );
        if( instance >= SCCP_ROUTE_NUM )
            return -1;
        *vartype = 4;

        memcpy ( pdata, &GTTAttribute[instance], SCCP_MAX_GTT_ATTRIBUTE );
        return SCCP_MAX_GTT_ATTRIBUTE;
    default:
        break;
    }
    return -1;
}

/*+++++++++++++++++++++++++++++++++++++++ */
//Private function========================>
/*+++++++++++++++++++++++++++++++++++++++ */
int SccpGetLocalIP (  )
{
    struct hostent *hptr;
    struct in_addr *inaddr;
    char hostname[40] = "\0";

    if( ( gethostname ( hostname, -1 ) ) != 0 )
        return -1;

    if( ( hptr = gethostbyname ( hostname ) ) == NULL )
        return -1;

    if( hptr->h_addr_list[0] != NULL )
    {
        inaddr = ( struct in_addr * ) hptr->h_addr_list[0];
        SCCP_Param.ip = inaddr->s_addr;
    }
    return 1;
}

int ParseLocalNode ( char *str )
{
    char info[5][128];
    int rtn;
    BYTE ssn;

    rtn = ParseLine ( str, info, 5 );
    if( rtn < 3 )
    {
        spLogDebug ( SCCPDB_ERR, "<001>Invalid line in Local_Node Table, field count = %d", rtn );
        return 0;
    }

    ssn = atoi ( info[0] );
    LocalSSN[ssn].NetID = atoi ( info[1] ) % 4;
    LocalSSN[ssn].msisdn_len = Str2Bcd ( LocalSSN[ssn].msisdn, info[2], MAX_DIGITS );

    if( rtn < 4 || strstr ( info[3], "-" ) != NULL )
        LocalSSN[ssn].ip[0] = 0xFFFFFFFF;
    /*      else if (strstr(info[3],"localhost") != NULL)
       LocalSSN[ssn].ip[0] = SCCP_Param.ip; */
    else
        LocalSSN[ssn].ip[0] = inet_addr ( info[3] );

    if( rtn < 5 || strstr ( info[4], "-" ) != NULL )
        LocalSSN[ssn].ip[1] = 0xFFFFFFFF;
    /*      else if (strstr(info[4],"localhost") != NULL)
       LocalSSN[ssn].ip[1] = SCCP_Param.ip; */
    else
        LocalSSN[ssn].ip[1] = inet_addr ( info[4] );

    /*      if (rtn >= 5)
       LocalSSN[ssn].ANSIFlag = atoi(info[5]); */

    LocalSSN[ssn].local = 0;
    LocalSSN[ssn].status[0] = LocalSSN[ssn].status[1] = 0;
    if( LocalSSN[ssn].ip[0] > 0 && LocalSSN[ssn].ip[0] != 0xFFFFFFFF )
    {
        if( LocalSSN[ssn].ip[0] == SCCP_Param.ip )
        {
            LocalSSN[ssn].status[0] = 1;
            LocalSSN[ssn].local = 1;
        }
        else
        {
            LocalSSN[ssn].status[0] = 3;
            LocalSSN[ssn].timeout[0] = T_hbrecv;
        }
    }

    if( LocalSSN[ssn].ip[1] > 0 && LocalSSN[ssn].ip[1] != 0xFFFFFFFF )
    {
        if( LocalSSN[ssn].ip[1] == SCCP_Param.ip )
        {
            LocalSSN[ssn].status[1] = 1;
            LocalSSN[ssn].local = 2;
        }
        else
        {
            LocalSSN[ssn].status[1] = 3;
            LocalSSN[ssn].timeout[1] = T_hbrecv;
        }
    }
    else
    {
        LocalSSN[ssn].status[1] = 0;
    }

    return 1;
}

void ParseRouteInfo ( char *str )
{
    int spc;
    char info[15][128];
    u_short index, rtn;
    BYTE offset = 0;
    BYTE ConfVer;               //configure file version

    SCCP_ROUTE *pRoute;

    rtn = ParseLine ( str, info, 15 );
    if( rtn < 8 )
    {
        spLogDebug ( SCCPDB_ERR, "<002>Invalid line in GTT Table, field count = %d", rtn );
        return;
    }

	if ( (rtn == 11 ) || ( rtn == 15 ) )
		ConfVer = 3;			//has EN
    else if( ( rtn == 10 ) || ( rtn == 14 ) )
        ConfVer = 2;            //has TT and AI
    else if( ( rtn == 9 ) || ( rtn == 13 ) )
        ConfVer = 1;            //has AI
    else
        ConfVer = 0;            //without TT and AI

    index = atoi ( info[offset++] );    //0
    if( index >= SCCP_ROUTE_NUM )
    {
        spLogDebug ( SCCPDB_ERR, "<003>invalid index in GTT Table, index = %d", index );
        return;
    }
    pRoute = &RouteList[index];
	if ( ConfVer == 3 )
	    pRoute->avail = atoi ( info[offset++] );    //1
	else
		pRoute->avail = 1;

    if( strstr ( info[offset], "-" ) != NULL )  //2
        pRoute->NP = 0;
    else
        pRoute->NP = atoi ( info[offset] );     //2
    offset++;
    if( ConfVer >= 2 )
    {
        if( strstr ( info[offset], "-" ) != NULL )      //3
            pRoute->TT = 0;
        else
            pRoute->TT = atoi ( info[offset] ); //3
        offset++;
    }
    else
        pRoute->TT = 0;

    memset ( pRoute->StartDigits, 0xFF, MAX_DIGITS * 2 );
    Str2Bcd ( pRoute->StartDigits, info[offset++], MAX_DIGITS );        //4
    pRoute->len = Str2Bcd ( pRoute->EndDigits, info[offset++], MAX_DIGITS );    //5

    pRoute->NetID = atoi ( info[offset++] ) % 4;        //6
    spc = strtol ( info[offset++], NULL, 16 );  //7
    pRoute->DPC[0] = spc >> 16;
    pRoute->DPC[1] = spc >> 8;
    pRoute->DPC[2] = spc;

    pRoute->SSN = atoi ( info[offset++] );      //8
    pRoute->RI = atoi ( info[offset++] );       //9

    /* daniel */
    if( ConfVer > 0 )
        pRoute->AI = atoi ( info[offset++] ) & 7;       //10
    else
        pRoute->AI = 7;

    if( rtn < 13 )
    {
        pRoute->convert = 0;
        return;
    }

    /* daniel */
    pRoute->ReplaceStart = atoi ( info[offset++] );     //11
    pRoute->ReplaceEnd = atoi ( info[offset++] );       //12
    pRoute->OutNP = atoi ( info[offset++] );    //13
    if( pRoute->ReplaceStart < 1 || pRoute->ReplaceStart > pRoute->ReplaceEnd )
        pRoute->convert = 0;
    else
    {
        memset ( pRoute->ReplaceDigits, 0xFF, MAX_DIGITS );
        pRoute->replace_len = Str2Bcd ( pRoute->ReplaceDigits, info[offset++], MAX_DIGITS );    //14
	pRoute->convert = 1;
    }

    return;
}

void ParseRLSSN ( char *str )
{
    RL_SSN *pRLSSN = NULL;
    char info[3][128];
    int rtn;
    BYTE NetID;
    int spc;

    rtn = ParseLine ( str, info, 3 );
    if( rtn < 3 )
    {
        spLogDebug ( SCCPDB_ERR, "<004>Invalid line in RL_SSN Table, field count = %d", rtn );
        return;
    }

    pRLSSN = &RelatedSSN[RelatedSSNNum];

    pRLSSN->status = 0;
    NetID = pRLSSN->NetID = atoi ( info[0] ) % 4;
    spc = pRLSSN->DPC = strtol ( info[1], NULL, 16 );
    pRLSSN->SSN = atoi ( info[2] );
    pRLSSN->SST = 1;
    pRLSSN->timeout = T_sst;
    if( SCCP_Param.spc[NetID] == spc )
        return;
    pRLSSN->status = ST_Disable;
    RelatedSSNNum = ( RelatedSSNNum + 1 ) % SCCP_RLSSN_NUM;
}

static void ParseGTTAttributeOMC ( char *str )
{
    GTTATT_OMC *pGTTAtt = NULL;
    char info[3][128];
    int rtn;
    BYTE index;

    rtn = ParseLine ( str, info, 3 );
    if( rtn < 2 )
    {
        spLogDebug ( SCCPDB_ERR, "<004>Invalid line in GTT Attribute Table, field count = %d", rtn );
        return;
    }
    index = atoi ( info[0] );
    pGTTAtt = &GTTAttribute[index];
    Str2Bcd ( pGTTAtt->attribute, info[1], SCCP_MAX_GTT_ATTRIBUTE * 2 );
}
