Files
svc.ems/plat/mtp3/src/mtpmib.c
2024-09-27 15:39:34 +08:00

2599 lines
63 KiB
C

#include "../../public/src/include/pub_include.h"
#include "../../snmp/src/include/snmp.h"
#include "../../snmp/src/include/heartbeat.h"
#include "./include/mtp3.h"
#ifdef _INCLUDE_M2UA
#include "../../m2ua/src/include/m2ua.h"
#endif
#include "./include/mtpstm.h"
#include "./include/mtpext.h"
#include "./include/mtpfunc.h"
/*@ignore@*/
char mtpconfile[] = {"./conf/mtp3.conf"};
FILE *mtpfpConf;
char MTP_OBJECT_LKA[20]={"[LINK ATTRIBUTE]\n"};
char MTP_OBJECT_NSP[80]={"[NATIONAL NETWORK SP]\n"};
char MTP_OBJECT_NSSP[80]={"[NATIONAL NETWORK SPARE SP]\n"};
char MTP_OBJECT_ISP[80]={"[INTERNATIONAL NETWORK SP]\n"};
char MTP_OBJECT_ISSP[80]={"[INTERNATIONAL NETWORK SPARE SP]\n"};
char MTP_OBJECT_LSA[40]={"[LINKSET ATTRIBUTE]\n"};
char MTP_OBJECT_LSP[20]={"[LOCAL SP]\n"};
char MTP_OBJECT_SNL[40]={"[SERVICE NETWORK SP LEN]\n"};
char MTP_OBJECT_SG[40]={"[SG ATTRIBUTES]\n"};
char MTP_OBJECT_MTP3LITE_PORT[40]={"[MTP3LITE TCP PORT]"};
long atol(const char *nptr);
void hmrt_tcoc_update_routing_tables(BYTE chl);
void hmrt_tcbc_update_routing_tables(BYTE chl);
void update_timer(int link);
BOOL Alinkset_status(BYTE routine);
BOOL Nlinkset_status(BYTE routine);
void mark_normal_linkset_available(BYTE *routine);
void mark_alternative_linkset_unavailable(BYTE *routine);
void mark_alternative_linkset_available(BYTE *routine);
void mark_normal_linkset_unavailable(BYTE *routine);
void mark_dstSP_inaccessible(BYTE *routine);
void hmrt_tfrc_update_routing_tables(BYTE dst, BYTE nw);
void otherMTP3_managed_link_unavailable(BYTE chl);
void mtp3_reload_data();
int MTP3_LinkIP_List(DWORD IP,BYTE mode);
void deactive_mtp3lite_lk(BYTE link);
//extern from sccp/sccpfun.c
extern ull Bcd2Ull(BYTE *pBcd, int BcdLen);
extern int ParseLine(char *str, char (*row)[128], int maxrow);
extern int Str2Bcd(BYTE *pBcd, char *pStr, int maxLen);
extern void deactive_m3ua_lk(BYTE link);
static u32 mtp3_primomcip=0; // primary omc ip address
static u32 mtp3_secdomcip=0; // secondary omc ip address
static u32 mtp2_object_id[] = {1,3,6,1,4,1,1373,1,3,1,1,3};
#define MTP2_PREOID_LEN 12
void mtp3_send_mtp2_alarm(WORD component,BYTE alarm)
{
snmp_pdu snmp_buf;
snmp_addr snmp_addr;
time_t cur_time;
u8 *buf;
snmp_addr.remote_port = 4957;
snmp_addr.local_port = 4957;
snmp_addr.broadcast = 0;
snmp_buf.pdu_type = 7;
snmp_buf.var_num = 1;
memcpy(snmp_buf.var[0].oid, mtp2_object_id, MTP2_PREOID_LEN*4);
snmp_buf.var[0].oid[MTP2_PREOID_LEN] = 4;
snmp_buf.var[0].oidlen = MTP2_PREOID_LEN + 1;
snmp_buf.var[0].vartype = 4;
buf = snmp_buf.var[0].msg;
buf[0] = mtp2_module; // system id
buf[1] = mtp2_systemid;
cur_time = time(NULL);
buf[2] = cur_time >> 24; // time stamp
buf[3] = cur_time >> 16;
buf[4] = cur_time >> 8;
buf[5] = cur_time;
// byte 6--13 16 LED status (green continuous: 0x09, yellow continuous: 0x0a)
buf[6] = 0x99;
if (alarm != 0)
buf[7] = 0xaf;
else
buf[7] = 0x9f;
memset(buf+8, 0xff, 6);
buf[14] = component>>8; // first byte of component id
buf[15] = component&255; // second byte of component id
buf[16] = alarm; // alarm level
buf[17] = 0;
buf[18] = 0;//length 1
buf[19] = 0;//component id
buf[20] = 0;//component id
buf[21] = 0;
buf[22] = 20;//length 2
// memcpy(buf+30, hlr_vm_ptr->sys_param.hlr_seqnum, HLR_SEQNUM_LEN);
// snmp_buf.var[0].msglen = 37 + HLR_SEQNUM_LEN;
snmp_buf.var[0].msglen = 23;
// snmp_addr.remote_ip = 0x81ea12ac;
if (mtp3_primomcip != 0)
{
snmp_addr.remote_ip = mtp3_primomcip;
snmp_send(&snmp_buf, &snmp_addr);
}
if (mtp3_secdomcip != 0)
{
snmp_addr.remote_ip = mtp3_secdomcip;
snmp_send(&snmp_buf, &snmp_addr);
}
}
int Mtp3BinSearchIndex(BYTE low, BYTE high,ull key, BYTE nw)
{
mtp3DPCIndex *sort_rec = &mtp3SortRoutine.nw[nw];
static int mid;
static long long midvalue;
if(low>high)
{
// LogErr("BinSearchIndex ERR,low=%d,high=%d,key=%lld",low,high,key);
return low;
}
if(high == low+1 )
{
if(key<=sort_rec->dpc[low])
return low;
else if(key<=sort_rec->dpc[high])
return high;
else
return high+1;
}
if(low == high)
{
if(key<=sort_rec->dpc[low])
return low;
else
return low+1;
}
mid = (low + high)/2;
midvalue = sort_rec->dpc[mid];
if(key == midvalue)
{
return mid;
}
else if(key<midvalue)
{
return Mtp3BinSearchIndex(low, mid,key,nw);
}
else
{
return Mtp3BinSearchIndex(mid,high,key,nw);
}
}
int Mtp3BinSearchValue(BYTE low, BYTE high,BYTE nw,ull key)
{
mtp3DPCIndex *sort_rec = &mtp3SortRoutine.nw[nw];
static int mid;
static long long midvalue;
if(low>high)
{
// LogErr("BinSearchIndex ERR,low=%d,high=%d,key=%lld",low,high,key);
return -1;
}
if (sort_rec->sortedNum <= 0)
return -1;
if (high > sort_rec->sortedNum-1)
high = sort_rec->sortedNum-1;
if(high == low+1 )
{
if(key==sort_rec->dpc[low])
return low;
else if(key==sort_rec->dpc[high])
return high;
else
return -1;
}
if(low == high)
{
if(key==sort_rec->dpc[low])
return low;
else
return -1;
}
mid = (low + high)/2;
midvalue = sort_rec->dpc[mid];
if(key == midvalue)
{
return mid;
}
else if(key<midvalue)
{
return Mtp3BinSearchValue(low, mid,nw,key);
}
else
{
return Mtp3BinSearchValue(mid,high,nw,key);
}
}
int Mtp3AddSortRec(BYTE nw,DWORD dpc, DWORD real_index, DWORD opc)
{
mtp3DPCIndex *sort_rec = &mtp3SortRoutine.nw[nw];
int index1;
ull opc_dpc=0;
if (sort_rec->sortedNum > 256 - 1)
{
mtp3SortRoutine.nw[nw].sortedNum = 256 - 1;
return 0;
}
if(opc == mtp3_para->nw[nw].opc14 && (pc_length(nw)==MTP3_14BIT_PC))
opc = 0;
else if(opc == mtp3_para->nw[nw].opc24 && (pc_length(nw)==MTP3_24BIT_PC))
opc = 0;
opc_dpc = opc;
opc_dpc = (opc_dpc<<32)|dpc;
if(sort_rec->sortedNum == 0)
{
index1 = 0;
sort_rec->dpc[index1] = opc_dpc;
sort_rec->sortedNum = 1;
sort_rec->index[index1] = real_index;
return 1;
}
else
{
index1 = Mtp3BinSearchValue(0,255,nw,opc_dpc);
if (index1>=0 && index1 < sort_rec->sortedNum)//already has this record
return 0;
while(sort_rec->dpc[0] > sort_rec->dpc[sort_rec->sortedNum - 1])
sort_rec->sortedNum = (sort_rec->sortedNum - 1) % 256;
//LogErr("--AddSortRec,start BinSearchIndex key=%lld",key);
index1 = Mtp3BinSearchIndex(0,sort_rec->sortedNum-1,opc_dpc,nw);
if (index1 >= sort_rec->sortedNum)
{
if (sort_rec->sortedNum >= 256-1)
{
return 0;
}
sort_rec->dpc[sort_rec->sortedNum] = opc_dpc;
sort_rec->index[sort_rec->sortedNum] = real_index;
sort_rec->sortedNum ++;
}
// LogErr("---AddSortRec: index1=%d,store_i=%d,old_key=%lld",index1,index,sort_rec[index1].key);
}
if (sort_rec->dpc[index1] != opc_dpc)
{// insert a item
int moveNum = (sort_rec->sortedNum-index1) % 256;
if (sort_rec->sortedNum >= 256)
{
return 0;
}
memmove(&sort_rec->dpc[index1+1],&sort_rec->dpc[index1],moveNum*sizeof(ull));
memmove(&sort_rec->index[index1+1],&sort_rec->index[index1],moveNum*sizeof(DWORD));
sort_rec->dpc[index1]=opc_dpc;
sort_rec->index[index1]=real_index;
sort_rec->sortedNum ++;
return 1;
}
//LogErr("--rearrange:%lld,%lld,%lld",sort_rec[index1-1].key,key,sort_rec[index1+1].key);
return 1;
}
int Mtp3DeleteRecord(ull key,BYTE nw) //VLR_RECORD vlr_record)
{
mtp3DPCIndex *sort_rec = &mtp3SortRoutine.nw[nw];
// long long imsi=key;
DWORD MoveNum;
int index=-1;
if (sort_rec->sortedNum == 0)
{
return 0;
}
index = Mtp3BinSearchValue(0,255,nw,key);
// index = BinSearchIndex(1,vlr_record_number,key);
if(index<0 || index>=sort_rec->sortedNum)
{
// LogMsg("VLR--ERROR!Delete Record index=%ld",index);
return 0;
}
MoveNum = (sort_rec->sortedNum-index) % 256;
memmove(&sort_rec->dpc[index],&sort_rec->dpc[index+1],MoveNum*sizeof(ull));
memmove(&sort_rec->index[index],&sort_rec->index[index+1],MoveNum*sizeof(DWORD));
// LogErr("----After del %lld,%lld,%lld",sort_rec[index-1].key,sort_rec[index].key,sort_rec[index+1].key);
sort_rec->dpc[sort_rec->sortedNum]=0;
sort_rec->index[sort_rec->sortedNum]=0;
sort_rec->sortedNum--;
return 1;
}
BYTE mtp_encode_integer(BYTE *buf,DWORD val,BYTE value_len)
{
if(val<128)
{
if (value_len == 4)
{
buf[0] = 0;
buf[1] = 0;
buf[2]=val;
return 3;
}
else
{
buf[0] = val;
return 1;
}
}
else if(val<0x8000)
{
if (value_len == 4)
{
buf[0] = 0;
buf[1]=val >>8;
buf[2]=val & 0xFF;
return 3;
}
else
{
buf[0]=val;
return 1;
}
}
else if(val <0x800000)
{
buf[0]=val >>16;
buf[1]=(val & 0xFF00)>>8;
buf[2]=val & 0xFF;
return 3;
}
// else if(val <0x80000000)
else
{
buf[0]=(val & 0xFF0000)>>16;
buf[1]=(val & 0xFF00)>>8;
buf[2]=val & 0xFF;
return 3;
}
}
int mtp3_reset_sccp()
{
DWORD oid[20] = {1,3,6,1,4,1,1373,2,3,2,3,3,2};//SCCP_OID
BYTE value=0;
return set_response(13,oid,&value,1);
}
void del_1dst_from_table(ls_info *ls, BYTE dpc_place, BYTE ud_select)
{
BYTE dst_num;
int i;
switch (ud_select)
{
case UPDATE_NLS:
dst_num = ls->influ_dstnum_asNLS;
if (dst_num == 0)
return;
ls->influ_dstnum_asNLS --;
for (i=0; i<dst_num; i++)
{
if (ls->influ_dstplace_intable_asNLS[i] == dpc_place)
{
memcpy(&ls->influ_dstplace_intable_asNLS[i],
&ls->influ_dstplace_intable_asNLS[i+1],dst_num-i-1);
ls->influ_dstplace_intable_asNLS[dst_num-1] = 0;
return;
}
}
break;
case 1:
dst_num = ls->influ_dstnum_asALS;
if (dst_num == 0)
return;
ls->influ_dstnum_asALS --;
for (i=0; i<dst_num; i++)
{
if (ls->influ_dstplace_intable_asALS[i] == dpc_place)
{
memcpy(&ls->influ_dstplace_intable_asALS[i],
&ls->influ_dstplace_intable_asALS[i+1],dst_num-i-1);
ls->influ_dstplace_intable_asALS[dst_num-1] = 0;
return;
}
}
break;
}
}
void add_1dst_to_table(ls_info *ls, BYTE place,BYTE ud_select)
{
BYTE dst_num;
switch (ud_select)
{
case UPDATE_NLS:
dst_num = ls->influ_dstnum_asNLS;
ls->influ_dstplace_intable_asNLS[dst_num] = place;
ls->influ_dstnum_asNLS = dst_num + 1;
break;
case UPDATE_ALS:
dst_num = ls->influ_dstnum_asALS;
ls->influ_dstplace_intable_asALS[dst_num] = place;
ls->influ_dstnum_asALS = dst_num + 1;
break;
}
}
void scan_conf_right_or_not(BYTE nw)
{
static BYTE index=0;
BYTE nls;
BYTE lsnw;
return;
nls = mtp3_para->nw[nw].normal_ls[index];
if (nls < 128)
{
lsnw = mtp3_para->ls_pro[nls] & 3;
if ((lsnw != nw) && (mtp3_para->nw[nw].dpc[index] != 0))
printf("configure error,nw %d,dpc=%lx normal linkset belong to network %d\n",nw,mtp3_para->nw[nw].dpc[index],lsnw);
}
index ++;
}
void mtp3lite_upd_route_status(BYTE chl, BYTE flag)
{
ls_info *ls;
int i;
BYTE dpc_index, lsno, nw;
lsno = mtp3_para->lk[chl].e1_to_linkset;
if (lsno >= 0x80)
return;
ls = &mtp3.ls[lsno];
nw = mtp3_para->ls_pro[lsno] & 3;
for (i = 0; i < ls->influ_dstnum_asNLS; i++)
{
dpc_index = ls->influ_dstplace_intable_asNLS[i];
if (!flag)
mark_normal_linkset_unavailable(&mtp3.nw[nw].routine[dpc_index]);
else
mark_normal_linkset_available(&mtp3.nw[nw].routine[dpc_index]);
if ((mtp3.nw[nw].routine[dpc_index] & 0x0f) == 0x0a)// all road unavailable
mark_dstSP_inaccessible(&mtp3.nw[nw].routine[dpc_index]);
hmrt_tfrc_update_routing_tables(dpc_index,nw);
}
}
void change_the_whole_ls(BYTE lsno,BYTE oldnw,BYTE nw)
{
ls_info *ls;
int i;
nw_para *nwpara;
BYTE *routine;
BYTE ls_available;
BYTE dpc_index;
int added=0;
ull opc_dpc=0;
ls = &mtp3.ls[lsno];
// printf("oldnw = %d,newnw=%d\n",oldnw,nw);
for (i=0;i<ls->influ_dstnum_asNLS;i++)
{
dpc_index = ls->influ_dstplace_intable_asNLS[i];
mark_normal_linkset_unavailable(&mtp3.nw[oldnw].routine[dpc_index]);
if ((mtp3.nw[oldnw].routine[dpc_index] & 0x0f) == 0x0a)// all road unavailable
mark_dstSP_inaccessible(&mtp3.nw[oldnw].routine[dpc_index]);
hmrt_tfrc_update_routing_tables(dpc_index,oldnw);
ls->influ_dstplace_intable_asNLS[i] = 0xff;
opc_dpc = mtp3_para->nw[oldnw].opc[dpc_index];
opc_dpc = (opc_dpc<<32)| mtp3_para->nw[oldnw].dpc[dpc_index];
Mtp3DeleteRecord(opc_dpc, oldnw);
}
for (i=0;i<ls->influ_dstnum_asALS;i++)
{
dpc_index = ls->influ_dstplace_intable_asALS[i];
mark_alternative_linkset_unavailable(&mtp3.nw[oldnw].routine[dpc_index]);
if ((mtp3.nw[oldnw].routine[dpc_index] & 0x0f) == 0x0a)// all road unavailable
mark_dstSP_inaccessible(&mtp3.nw[oldnw].routine[dpc_index]);
hmrt_tfrc_update_routing_tables(dpc_index,oldnw);
ls->influ_dstplace_intable_asALS[i] = 0xff;
opc_dpc = mtp3_para->nw[oldnw].opc[dpc_index];
opc_dpc = (opc_dpc<<32) | mtp3_para->nw[oldnw].dpc[dpc_index];
Mtp3DeleteRecord(opc_dpc,oldnw);
}
ls->influ_dstnum_asNLS = 0;
ls->influ_dstnum_asALS = 0;
if (mtp3.ls[lsno].links_available_t > 0)
ls_available = TRUE;
else
ls_available = FALSE;
nwpara = &mtp3_para->nw[nw];
for (i=0;i<256;i++)
{
if (nwpara->dpc[i] == 0)
continue;
routine = &mtp3.nw[nw].routine[i];
if (nwpara->normal_ls[i] == lsno)
{
if (ls_available == TRUE)
mark_normal_linkset_available(routine);
else
mark_normal_linkset_unavailable(routine);
add_1dst_to_table(&mtp3.ls[lsno],i,UPDATE_NLS);
Mtp3AddSortRec(nw,nwpara->dpc[i], i, nwpara->opc[i]);//??-
added = 1;
}
if ((nwpara->alternative_ls[i] == lsno) &&
(nwpara->normal_ls[i] < 128) )
{
if (ls_available == TRUE)
mark_alternative_linkset_available(routine);
else
mark_alternative_linkset_unavailable(routine);
add_1dst_to_table(&mtp3.ls[lsno],i,UPDATE_ALS);
if (!added)
Mtp3AddSortRec(nw,nwpara->dpc[i], i, nwpara->opc[i]);//??-
}
hmrt_tfrc_update_routing_tables(i,nw);
added=0;
}
}
void update_ls_influence_dst_table(BYTE nw, long dst, BYTE place, BYTE nls, BYTE als, DWORD rc, long opc)//??-
{
BYTE *routine;
DWORD pc_new, rc_new, opc_new;
BYTE nls_old;
BYTE als_old;
DWORD pc_old;
BYTE nlsnw;
BYTE alsnw;
ull opc_dpc_new=0, opc_dpc_old=0;
pc_new = decode_integer((BYTE*)&dst,4);
rc_new = decode_integer((BYTE*)&rc,4);
opc_new = decode_integer((BYTE*)&opc,4);
routine = &mtp3.nw[nw].routine[place];
nls_old = mtp3_para->nw[nw].normal_ls[place];
als_old = mtp3_para->nw[nw].alternative_ls[place];
pc_old = mtp3_para->nw[nw].dpc[place];
nlsnw = mtp3_para->ls_pro[nls] & 3;
alsnw = mtp3_para->ls_pro[als] & 3;
if ((pc_old == pc_new) &&
(nls_old == nls) &&
(als_old == als) &&
(mtp3_para->nw[nw].rc[place] == rc_new)&&
(mtp3_para->nw[nw].opc[place] == opc_new))
return;
/*
if(opc_new == 0 && pc_new != 0)
{
if(pc_length(nw) == MTP3_24BIT_PC)
opc_new = mtp3_para->nw[nw].opc24;
else
opc_new = mtp3_para->nw[nw].opc14;
}
*/
opc_dpc_new = opc_new;
opc_dpc_new = (opc_dpc_new<<32)|pc_new;
opc_dpc_old = mtp3_para->nw[nw].opc[place];
opc_dpc_old = (opc_dpc_old<<32)|pc_old;
if (pc_old > 0)
Mtp3DeleteRecord(opc_dpc_old,nw);//delect this pc from sort table //??-
if (pc_new > 0)
{
if ((nls<128 && nlsnw == nw) || (als<128 && alsnw==nw))
{
Mtp3AddSortRec(nw,pc_new,place, opc_new);//add this new pc to the sort table //??-
}
}
if ( (nls != nls_old) ||
(als != als_old) )
{
if ((nls < 128) &&
(nlsnw == nw))
{
if (mtp3.ls[nls].links_available_t > 0)
mark_normal_linkset_available(routine);
else
mark_normal_linkset_unavailable(routine);
if (nls != nls_old)
add_1dst_to_table(&mtp3.ls[nls],place,UPDATE_NLS);
}
else
mark_normal_linkset_unavailable(routine);
if ((als < 128) &&
(nls < 128) &&// if one spc doesn't has normal linkset,it can not has alternative linkset
(alsnw == nw))
{
if (mtp3.ls[als].links_available_t > 0)
mark_alternative_linkset_available(routine);
else
mark_alternative_linkset_unavailable(routine);
if ((als != als_old) || (nls_old > 127) )
{
// printf("renew alternative linkset %d,num=%d\n",als,mtp3.ls[als].influ_dstnum_asALS);
add_1dst_to_table(&mtp3.ls[als],place,UPDATE_ALS);
// printf("renew alternative linkset %d,num=%d\n",als,mtp3.ls[als].influ_dstnum_asALS);
}
}
else
mark_alternative_linkset_unavailable(routine);
if ((mtp3.nw[nw].routine[place] & 0x0f) == 0x0a)
mark_dstSP_inaccessible(routine);
hmrt_tfrc_update_routing_tables(place,nw);
mtp3_para->nw[nw].dpc[place] = pc_new;
mtp3_para->nw[nw].opc[place] = opc_new;
mtp3_para->nw[nw].normal_ls[place] = nls;
mtp3_para->nw[nw].alternative_ls[place] = als;
if ( (nls_old < 128) &&
(nls_old != nls) )
del_1dst_from_table(&mtp3.ls[nls_old],place,UPDATE_NLS);
if ( (als_old < 128) &&
(als_old != als) )
del_1dst_from_table(&mtp3.ls[als_old],place,UPDATE_ALS);
}
if (mtp3_para->ls_op_pc[nls] == pc_new)
mtp3.ls[nls].adjacent_sp_place = place;
mtp3_para->nw[nw].dpc[place] = pc_new;
mtp3_para->nw[nw].opc[place] = opc_new;
mtp3_para->nw[nw].rc[place] = rc_new;
}
int mtp3_write_parameter()
{
int i,j;
int ix4;
mtpfpConf = fopen(mtpconfile,"w");
if (mtpfpConf == NULL)
return -1;
fprintf(mtpfpConf,"#MTP3 CONFIGURE FILE\n");
fprintf(mtpfpConf,"\n");
fprintf(mtpfpConf,"[SERVICE NETWORK SP LEN]\n");
fprintf(mtpfpConf,"[%02x]\n",mtp3_para->nw_pro);
fprintf(mtpfpConf,"\n");
fprintf(mtpfpConf,"[MTP3LITE TCP PORT]\n");
fprintf(mtpfpConf,"[%04x]\n",mtp3_para->mtp3lite_port);
fprintf(mtpfpConf,"\n");
fprintf(mtpfpConf,"[LOCAL SP]\n");
fprintf(mtpfpConf,"[%06lx]\t[%06lx]\t[%06lx]\t[%06lx]\t\n",mtp3_para->nw[0].opc14,
mtp3_para->nw[1].opc14,mtp3_para->nw[2].opc14,mtp3_para->nw[3].opc14);
fprintf(mtpfpConf,"[%06lx]\t[%06lx]\t[%06lx]\t[%06lx]\t\n",mtp3_para->nw[0].opc24,
mtp3_para->nw[1].opc24,mtp3_para->nw[2].opc24,mtp3_para->nw[3].opc24);
fprintf(mtpfpConf,"\n");
/* e1 to linkset */
fprintf(mtpfpConf,"[LINK ATTRIBUTE]\n");
for (i=0; i<64; i++)
{
ix4 = i*4;
for (j=0; j<4; j++)
{
fprintf(mtpfpConf,"[%02x.%02x.%08lx.%02x.%02x.%02x.%08lx.%02x.%02x.%08lx]\t",mtp3_para->lk[ix4+j].e1_to_linkset,
mtp3_para->lk[ix4+j].e1_to_slc,mtp3_para->lk[ix4+j].e1_to_mtp3,mtp3_para->lk[ix4+j].e1_lk_type,mtp3_para->lk[ix4+j].e1_to_sg,mtp3_para->lk[ix4+j].e1_to_iid,
mtp3_para->lk[ix4+j].remote_ip,mtp3_para->lk[ix4+j].inactive,mtp3_para->lk[ix4+j].inactive_tm,mtp3_para->lk[ix4+j].e1_to_alterMTP3);
}
fprintf(mtpfpConf,"\n");
}
fprintf(mtpfpConf,"\n");
/* linkset remote sp */
fprintf(mtpfpConf,"[LINKSET ATTRIBUTE]\n");
for (i=0; i<32; i++)
{
ix4 = i*4;
for (j=0; j<4; j++)
{
if (1)
{
char ls_reserved[128]={0};
char temp[16];
int k;
for (k=0;k<16;k++)
{
sprintf(temp,"%02x",mtp3_para->ls_reserved[ix4+j][k]);
strcat(ls_reserved,temp);
}
fprintf(mtpfpConf,"[%06lx.%02x.%-16s.%08lx]\t",mtp3_para->ls_op_pc[ix4+j],mtp3_para->ls_pro[ix4+j],ls_reserved, mtp3_para->ls_opc[ix4+j]);
}
}
fprintf(mtpfpConf,"\n");
}
fprintf(mtpfpConf,"\n");
/* SG */
fprintf(mtpfpConf, "[SG ATTRIBUTES]\n");
for (i = 0; i < 64; i++)
{
ix4 = i * 4;
for (j = 0; j < 4; j++)
{
fprintf(mtpfpConf, "[%02X.%02X.%02X.%08lX]\t", mtp3_para->sg[ix4+j].enable, mtp3_para->sg[ix4+j].server,
mtp3_para->sg[ix4+j].data_ack, mtp3_para->sg[ix4+j].ip);
}
fprintf(mtpfpConf, "\n");
}
fprintf(mtpfpConf, "\n");
/* NATIONAL NETWORK SP */
fprintf(mtpfpConf,"[NATIONAL NETWORK SP]\n");
for (i=0; i<64; i++)
{
ix4 = i*4;
for (j=0; j<4; j++)
{
fprintf(mtpfpConf,"[%06lx.%02x.%02x.%08lx.%08lx]\t",mtp3_para->nw[2].dpc[ix4+j],mtp3_para->nw[2].normal_ls[ix4+j],
mtp3_para->nw[2].alternative_ls[ix4+j], mtp3_para->nw[2].rc[ix4+j], mtp3_para->nw[2].opc[ix4+j]);
}
fprintf(mtpfpConf,"\n");
}
fprintf(mtpfpConf,"\n");
/* NATIONAL NETWORK SPARE SP */
fprintf(mtpfpConf,"[NATIONAL NETWORK SPARE SP]\n");
for (i=0; i<64; i++)
{
ix4 = i*4;
for (j=0; j<4; j++)
{
fprintf(mtpfpConf,"[%06lx.%02x.%02x.%08lx.%08lx]\t",mtp3_para->nw[3].dpc[ix4+j],mtp3_para->nw[3].normal_ls[ix4+j],
mtp3_para->nw[3].alternative_ls[ix4+j], mtp3_para->nw[3].rc[ix4+j], mtp3_para->nw[3].opc[ix4+j]);
}
fprintf(mtpfpConf,"\n");
}
fprintf(mtpfpConf,"\n");
/* INTERNATIONAL NETWORK SP */
fprintf(mtpfpConf,"[INTERNATIONAL NETWORK SP]\n");
for (i=0; i<64; i++)
{
ix4 = i*4;
for (j=0; j<4; j++)
{
fprintf(mtpfpConf,"[%06lx.%02x.%02x.%08lx.%08lx]\t",mtp3_para->nw[0].dpc[ix4+j],mtp3_para->nw[0].normal_ls[ix4+j],
mtp3_para->nw[0].alternative_ls[ix4+j], mtp3_para->nw[0].rc[ix4+j], mtp3_para->nw[0].opc[ix4+j]);
}
fprintf(mtpfpConf,"\n");
}
fprintf(mtpfpConf,"\n");
/* INTERNATIONAL NETWORK SP */
fprintf(mtpfpConf,"[INTERNATIONAL NETWORK SPARE SP]\n");
for (i=0; i<64; i++)
{
ix4 = i*4;
for (j=0; j<4; j++)
{
fprintf(mtpfpConf,"[%06lx.%02x.%02x.%08lx.%08lx]\t",mtp3_para->nw[1].dpc[ix4+j],mtp3_para->nw[1].normal_ls[ix4+j],
mtp3_para->nw[1].alternative_ls[ix4+j], mtp3_para->nw[1].rc[ix4+j], mtp3_para->nw[1].opc[ix4+j]);
}
fprintf(mtpfpConf,"\n");
}
fprintf(mtpfpConf,"\n");
fprintf(mtpfpConf,"[LOCAL ACN]\n");
for(i=0;i<MAX_ACN_NUM;i++)
{
fprintf(mtpfpConf,"%02x",mtp3_para->localAcn[i]);
}
fprintf(mtpfpConf,"\n\n");
fprintf(mtpfpConf,"[INTERNATIONAL NETWORK ACN]\n");
for (i=0; i<256; i++)
{
for (j=0;j<MAX_ACN_NUM;j++)
{
fprintf(mtpfpConf,"%02x",mtp3_para->nw[0].acn[i][j]);
}
fprintf(mtpfpConf,"\n");
}
fprintf(mtpfpConf,"\n");
fprintf(mtpfpConf,"[INTERNATIONAL NETWORK SPARE ACN]\n");
for (i=0; i<256; i++)
{
for (j=0;j<MAX_ACN_NUM;j++)
{
fprintf(mtpfpConf,"%02x",mtp3_para->nw[1].acn[i][j]);
}
fprintf(mtpfpConf,"\n");
}
fprintf(mtpfpConf,"\n");
fprintf(mtpfpConf,"[NATIONAL NETWORK ACN]\n");
for (i=0; i<256; i++)
{
for (j=0;j<MAX_ACN_NUM;j++)
{
fprintf(mtpfpConf,"%02x",mtp3_para->nw[2].acn[i][j]);
}
fprintf(mtpfpConf,"\n");
}
fprintf(mtpfpConf,"\n");
fprintf(mtpfpConf,"[NATIONAL NETWORK SPARE ACN]\n");
for (i=0; i<256; i++)
{
for (j=0;j<MAX_ACN_NUM;j++)
{
fprintf(mtpfpConf,"%02x",mtp3_para->nw[3].acn[i][j]);
}
fprintf(mtpfpConf,"\n");
}
fprintf(mtpfpConf,"\n");
fclose(mtpfpConf);
return 1;
}
static int issquare(char c)
{
if ((c=='[') || (c==']') || (c==' ') || (c=='\t'))
return 1;
return 0;
}
static int isdot(char c)
{
if ((c=='.'))
return 1;
return 0;
}
int ParseLineWithSquare(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(issquare(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 ParseLineWithDot(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(isdot(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 ReadMtp3NetworkPara(char *s)
{
char LineInfo[1][128];
int rtn;
rtn = ParseLineWithSquare(s, LineInfo, 1);
mtp3_para->nw_pro = strtoll(LineInfo[0],NULL,16);
return 1;
}
int ReadMtp3LitePortPara(char *s)
{
char LineInfo[1][128];
int rtn;
rtn = ParseLineWithSquare(s, LineInfo, 1);
mtp3_para->mtp3lite_port = strtoll(LineInfo[0],NULL,16);
return 1;
}
int ReadMtp3OPCPara(char *s)
{
char LineInfo[8][128];
int rtn;
int instance;
static int Base=0;
rtn = ParseLineWithSquare(s, LineInfo, 4);//each line four links
if (Base==0)
{
for (instance=0;instance<4;instance++)
{
mtp3_para->nw[instance].opc14 = strtoll(LineInfo[instance],NULL,16);
}
}
else
{
for (instance=0;instance<4;instance++)
{
mtp3_para->nw[instance].opc24 = strtoll(LineInfo[instance],NULL,16);
}
}
Base++;
if (Base > 1)
{
Base = 0;
return 1;
}
return 0;
}
int ReadMtp3LinkPara(char *s)
{
char LineInfo[8][128];
char DetailInfo[10][128];
int rtn;
int Instance;
static int Base=0;
DWORD mtp3ip;
rtn = ParseLineWithSquare(s, LineInfo, 4);//each line four links
for (Instance=0;Instance<4;Instance++)
{
rtn = ParseLineWithDot(LineInfo[Instance],DetailInfo,10);
mtp3_para->lk[Base+Instance].e1_to_linkset = strtoll(DetailInfo[0],NULL,16);
mtp3_para->lk[Base+Instance].e1_to_slc = strtoll(DetailInfo[1],NULL,16);
mtp3ip = strtoll(DetailInfo[2],NULL,16);
if (rtn == 3)
{
if (mtp3ip == 0xff)
mtp3_para->lk[Base+Instance].e1_to_mtp3 = 0xffffffff;
else
mtp3_para->lk[Base+Instance].e1_to_mtp3 = 0x010012ac | ((mtp3ip & 0xff) << 16);
mtp3_para->lk[Base+Instance].e1_lk_type = 0x01;
mtp3_para->lk[Base+Instance].e1_to_alterMTP3 = 0xffffffff;
}
else
{
mtp3_para->lk[Base+Instance].e1_to_mtp3 = mtp3ip;
mtp3_para->lk[Base+Instance].e1_lk_type = strtoll(DetailInfo[3],NULL,16);
mtp3_para->lk[Base+Instance].e1_to_sg = strtoll(DetailInfo[4],NULL,16);
mtp3_para->lk[Base+Instance].e1_to_iid = strtoll(DetailInfo[5],NULL,16);
mtp3_para->lk[Base+Instance].remote_ip = strtoll(DetailInfo[6],NULL,16);
mtp3_para->lk[Base+Instance].inactive = strtoll(DetailInfo[7],NULL,16);
mtp3_para->lk[Base+Instance].inactive_tm = strtoll(DetailInfo[8],NULL,16);
mtp3_para->lk[Base+Instance].e1_to_alterMTP3 = strtoll(DetailInfo[9],NULL,16);
if(mtp3_para->lk[Base+Instance].e1_to_alterMTP3 == mtp3_para->lk[Base+Instance].e1_to_mtp3)
{
mtp3_para->lk[Base+Instance].e1_to_alterMTP3 = 0xffffffff;
}
}
#ifdef _INCLUDE_M2UA
set_m2ua_link(Base+Instance, (BYTE *) &mtp3_para->lk[Base+Instance]);
#endif
}
Base+=4;
if (Base >= 256)
{
Base = 0;
return 1;
}
return 0;
}
int ReadMtp3LinksetPara(char *s)
{
char LineInfo[8][128];
char DetailInfo[10][128];
int rtn;
int Instance;
static int Base=0;
memset(DetailInfo, 0, sizeof(DetailInfo));
rtn = ParseLineWithSquare(s, LineInfo, 4);//each line four linksets
for (Instance=0;Instance<4;Instance++)
{
rtn = ParseLineWithDot(LineInfo[Instance],DetailInfo,4);
mtp3_para->ls_op_pc[Base+Instance] = strtoll(DetailInfo[0],NULL,16);
mtp3_para->ls_pro[Base+Instance] = strtoll(DetailInfo[1],NULL,16);
if (rtn == 3)
Str2Bcd(mtp3_para->ls_reserved[Base+Instance],DetailInfo[2],16);
mtp3_para->ls_opc[Base+Instance] = strtoll(DetailInfo[3],NULL,16);
}
Base+=4;
if (Base >= 128)
{
Base = 0;
return 1;
}
return 0;
}
int ReadMtp3SGPara(char *s)
{
char LineInfo[8][128];
char DetailInfo[10][128];
int rtn;
int Instance;
static int Base=0;
rtn = ParseLineWithSquare(s, LineInfo, 4);//each line four linksets
for (Instance=0;Instance<4;Instance++)
{
rtn = ParseLineWithDot(LineInfo[Instance],DetailInfo,4);
mtp3_para->sg[Base+Instance].enable = strtoll(DetailInfo[0],NULL,16);
mtp3_para->sg[Base+Instance].server = strtoll(DetailInfo[1],NULL,16);
mtp3_para->sg[Base+Instance].data_ack = strtoll(DetailInfo[2],NULL,16);
mtp3_para->sg[Base+Instance].ip = strtoll(DetailInfo[3],NULL,16);
#ifdef _INCLUDE_M2UA
set_m2ua_sg(Base+Instance, (BYTE *) &mtp3_para->sg[Base+Instance]);
#endif
}
Base+=4;
if (Base >= 256)
{
Base = 0;
return 1;
}
return 0;
}
int ReadMtp3NATPara(char *s)
{
char LineInfo[8][128];
char DetailInfo[10][128];
int rtn;
int Instance;
static int Base=0;
memset(DetailInfo, 0, sizeof(DetailInfo));
rtn = ParseLineWithSquare(s, LineInfo, 4);//each line four linksets
for (Instance=0;Instance<4;Instance++)
{
rtn = ParseLineWithDot(LineInfo[Instance],DetailInfo,5);//4);//3);
mtp3_para->nw[2].dpc[Base+Instance] = strtoll(DetailInfo[0],NULL,16);
mtp3_para->nw[2].normal_ls[Base+Instance] = strtoll(DetailInfo[1],NULL,16);
mtp3_para->nw[2].alternative_ls[Base+Instance] = strtoll(DetailInfo[2],NULL,16);
mtp3_para->nw[2].rc[Base+Instance] = strtoll(DetailInfo[3],NULL,16);
mtp3_para->nw[2].opc[Base+Instance] = strtoll(DetailInfo[4],NULL,16);
}
Base+=4;
if (Base >= 256)
{
Base = 0;
return 1;
}
return 0;
}
int ReadMtp3NATsPara(char *s)
{
char LineInfo[8][128];
char DetailInfo[10][128];
int rtn;
int Instance;
static int Base=0;
memset(DetailInfo, 0, sizeof(DetailInfo));
rtn = ParseLineWithSquare(s, LineInfo, 4);//each line four linksets
for (Instance=0;Instance<4;Instance++)
{
rtn = ParseLineWithDot(LineInfo[Instance],DetailInfo,5);
mtp3_para->nw[3].dpc[Base+Instance] = strtoll(DetailInfo[0],NULL,16);
mtp3_para->nw[3].normal_ls[Base+Instance] = strtoll(DetailInfo[1],NULL,16);
mtp3_para->nw[3].alternative_ls[Base+Instance] = strtoll(DetailInfo[2],NULL,16);
mtp3_para->nw[3].rc[Base+Instance] = strtoll(DetailInfo[3],NULL,16);
mtp3_para->nw[3].opc[Base+Instance] = strtoll(DetailInfo[4],NULL,16);
}
Base+=4;
if (Base >= 256)
{
Base = 0;
return 1;
}
return 0;
}
int ReadMtp3INTPara(char *s)
{
char LineInfo[8][128];
char DetailInfo[10][128];
int rtn;
int Instance;
static int Base=0;
memset(DetailInfo, 0, sizeof(DetailInfo));
rtn = ParseLineWithSquare(s, LineInfo, 4);//each line four linksets
for (Instance=0;Instance<4;Instance++)
{
rtn = ParseLineWithDot(LineInfo[Instance],DetailInfo,5);
mtp3_para->nw[0].dpc[Base+Instance] = strtoll(DetailInfo[0],NULL,16);
mtp3_para->nw[0].normal_ls[Base+Instance] = strtoll(DetailInfo[1],NULL,16);
mtp3_para->nw[0].alternative_ls[Base+Instance] = strtoll(DetailInfo[2],NULL,16);
mtp3_para->nw[0].rc[Base+Instance] = strtoll(DetailInfo[3],NULL,16);
mtp3_para->nw[0].opc[Base+Instance] = strtoll(DetailInfo[4],NULL,16);
}
Base+=4;
if (Base >= 256)
{
Base = 0;
return 1;
}
return 0;
}
int ReadMtp3INTsPara(char *s)
{
char LineInfo[8][128];
char DetailInfo[10][128];
int rtn;
int Instance;
static int Base=0;
memset(DetailInfo, 0, sizeof(DetailInfo));
rtn = ParseLineWithSquare(s, LineInfo, 4);//each line four linksets
for (Instance=0;Instance<4;Instance++)
{
rtn = ParseLineWithDot(LineInfo[Instance],DetailInfo,5);
mtp3_para->nw[1].dpc[Base+Instance] = strtoll(DetailInfo[0],NULL,16);
mtp3_para->nw[1].normal_ls[Base+Instance] = strtoll(DetailInfo[1],NULL,16);
mtp3_para->nw[1].alternative_ls[Base+Instance] = strtoll(DetailInfo[2],NULL,16);
mtp3_para->nw[1].rc[Base+Instance] = strtoll(DetailInfo[3],NULL,16);
mtp3_para->nw[1].opc[Base+Instance] = strtoll(DetailInfo[4],NULL,16);
}
Base+=4;
if (Base >= 256)
{
Base = 0;
return 1;
}
return 0;
}
int ReadMtp3LocalACNPara(char *s)
{
char LineInfo[1][128];
int rtn;
rtn = ParseLine(s, LineInfo, 1);//each line four linksets
AsciiToBcd(mtp3_para->localAcn,LineInfo[0],MAX_ACN_NUM*2);
return 1;
}
int ReadMtp3INTACNPara(char *s)
{
char LineInfo[1][128];
int rtn;
static int Base=0;
rtn = ParseLine(s, LineInfo, 1);//each line four linksets
AsciiToBcd(mtp3_para->nw[0].acn[Base],LineInfo[0],MAX_ACN_NUM*2);
Base++;
if (Base >= 256)
{
Base = 0;
return 1;
}
return 0;
}
int ReadMtp3INTsACNPara(char *s)
{
char LineInfo[1][128];
int rtn;
static int Base=0;
rtn = ParseLine(s, LineInfo, 1);//each line four linksets
AsciiToBcd(mtp3_para->nw[1].acn[Base],LineInfo[0],MAX_ACN_NUM*2);
Base++;
if (Base >= 256)
{
Base = 0;
return 1;
}
return 0;
}
int ReadMtp3NATACNPara(char *s)
{
char LineInfo[1][128];
int rtn;
static int Base=0;
rtn = ParseLine(s, LineInfo, 1);//each line four linksets
AsciiToBcd(mtp3_para->nw[2].acn[Base],LineInfo[0],MAX_ACN_NUM*2);
Base++;
if (Base >= 256)
{
Base = 0;
return 1;
}
return 0;
}
int ReadMtp3NATSACNPara(char *s)
{
char LineInfo[1][128];
int rtn;
static int Base=0;
rtn = ParseLine(s, LineInfo, 1);//each line four linksets
AsciiToBcd(mtp3_para->nw[3].acn[Base],LineInfo[0],MAX_ACN_NUM*2);
Base++;
if (Base >= 256)
{
Base = 0;
return 1;
}
return 0;
}
void mtp3_readpara_from_disk()
{
char s[1024]={0};
int len;
BYTE state = 0;
FILE *fp;
fp = fopen(mtpconfile,"rb");
if (fp==NULL)
{
printf("mtp3 config file %s missed!!\n",mtpconfile);
return;
}
s[0] = 0;
while ( fgets(s,1024,fp) != (char *)0 )
{
if ( (int *)strchr(s,'#') != NULL ) continue;
if ( (len=strlen(s))==0 ) continue;
if ( strstr(s,"[SERVICE NETWORK SP LEN]") != NULL )
{
state = 1;
continue;
}
else if ( strstr(s,"[MTP3LITE TCP PORT]") != NULL )
{
state = 2;
continue;
}
else if ( strstr(s,"[LOCAL SP]") != NULL )
{
state = 3;
continue;
}
else if ( strstr(s,"[LINK ATTRIBUTE]") != NULL )
{
state = 4;
continue;
}
else if ( strstr(s,"[LINKSET ATTRIBUTE]") != NULL )
{
state = 5;
continue;
}
else if ( strstr(s,"[SG ATTRIBUTES]") != NULL )
{
state = 6;
continue;
}
else if ( strstr(s,"[NATIONAL NETWORK SP]") != NULL )
{
state = 7;
continue;
}
else if ( strstr(s,"[NATIONAL NETWORK SPARE SP]") != NULL )
{
state = 8;
continue;
}
else if ( strstr(s,"[INTERNATIONAL NETWORK SP]") != NULL )
{
state = 9;
continue;
}
else if ( strstr(s,"[INTERNATIONAL NETWORK SPARE SP]") != NULL )
{
state = 10;
continue;
}
else if ( strstr(s,"[LOCAL ACN]") != NULL )
{
state = 11;
continue;
}
else if ( strstr(s,"[INTERNATIONAL NETWORK ACN]") != NULL )
{
state = 12;
continue;
}
else if ( strstr(s,"[INTERNATIONAL NETWORK SPARE ACN]") != NULL )
{
state = 13;
continue;
}
else if ( strstr(s,"[NATIONAL NETWORK ACN]") != NULL )
{
state = 14;
continue;
}
else if ( strstr(s,"[NATIONAL NETWORK SPARE ACN]") != NULL )
{
state = 15;
continue;
}
switch (state)
{
case 1:
if (ReadMtp3NetworkPara(s))
state = 0;
break;
case 2:
if (ReadMtp3LitePortPara(s))
state = 0;
break;
case 3:
if (ReadMtp3OPCPara(s))
state = 0;
break;
case 4:
if (ReadMtp3LinkPara(s))
state = 0;
break;
case 5:
if (ReadMtp3LinksetPara(s))
state = 0;
break;
case 6:
if (ReadMtp3SGPara(s))
state = 0;
break;
case 7:
if (ReadMtp3NATPara(s))
state = 0;
break;
case 8:
if (ReadMtp3NATsPara(s))
state = 0;
break;
case 9:
if (ReadMtp3INTPara(s))
state = 0;
break;
case 10:
if (ReadMtp3INTsPara(s))
state = 0;
break;
case 11:
if (ReadMtp3LocalACNPara(s))
state = 0;
break;
case 12:
if (ReadMtp3INTACNPara(s))
state = 0;
break;
case 13:
if (ReadMtp3INTsACNPara(s))
state = 0;
break;
case 14:
if (ReadMtp3NATACNPara(s))
state = 0;
break;
case 15:
if (ReadMtp3NATSACNPara(s))
state = 0;
break;
default:
break;
}
}
fclose(fp);
}
void mtp3_setlink_to_IDLE(BYTE link)
{
BYTE oldls;
BYTE oldslc;
DWORD oldip;
BYTE oldtp;
oldls = mtp3_para->lk[link].e1_to_linkset;
oldslc = mtp3_para->lk[link].e1_to_slc;
oldip = mtp3_para->lk[link].e1_to_mtp3;
oldtp = mtp3_para->lk[link].e1_lk_type;
if (mtp3ObjState.link_l3_state[link] == AVAILABLE)
{
if ((MTP3_LINK_TYPE(link) == LKTYPE_MTP3_LITE) && // Not MTP3LITE
(mtp3_para->lk[link].e1_lk_type & 0x01)) // Enabled
{//sccp lite link
deactive_mtp3lite_lk(link);
}
else if((MTP3_LINK_TYPE(link) == LKTYPE_M3UA) && // Not M3UA
(mtp3_para->lk[link].e1_lk_type & 0x01)) // Enabled
{//sccp lite link
deactive_m3ua_lk(link);
}
else
{
mtp3ObjInput.sltc_input[link] = SLTC_STOP;
sltc_proc(link);
init_lsac_state[link] = TRUE;
lsac_proc(link);
init_tlac_state[link] = TRUE;
tlac_proc(link);
if (mtp3ObjState.link_l3_state[link] == AVAILABLE)
otherMTP3_managed_link_unavailable(link);
mtp3ObjState.link_l2_state[link] = UNAVAILABLE;
mtp3ObjState.link_l3_state[link] = UNAVAILABLE;
}
}
if (mtp3ObjState.lk_configured[link] == PARA_CONFIGURED)
{
mtp3.ls[oldls].linksNum_configured--;
ls_slc[oldls*16+oldslc] = 0xff;
update_sls_to_link_table(oldls);
}
mtp3ObjState.lk_configured[link] = PARA_NOT_CONFIGURED;
// printf("link %d update para,new ls=%d,new slc = %d,new ip=%lx\n",link,newls,newslc,newip);
}
int mtp_setmib(BYTE oidlen, DWORD *oid, BYTE *pdata,WORD datalen)
{
int instance;
DWORD pc;
BYTE command;
int ls;
int slc;
DWORD ip;
DWORD ip1;
int tp;
int i;
DWORD oldpc, opc, oldopc;
BYTE old_lsnw;
BYTE new_lsnw;
DWORD oldpar, rc;
BOOL para_changed=0;
if ( oidlen < MTP3_OID_LEN)
{
printf("set failed,object id length not correct\n");
return -1;
}
if ( oid[MTP3_OID_LEN] == 2 )/* configure */
{
switch (oid[MTP3_OID_LEN+1])
{
case 1:/* sp/stp */
break;
case 2:/* 14/24bit (for four service networks) */
oldpar = mtp3_para->nw_pro;
mtp3_para->nw_pro = decode_integer(pdata,datalen);
if (oldpar != mtp3_para->nw_pro)
mtp3_reset_sccp();
return 1;
case 3:/* opc */
memcpy(&pc,pdata,4);
pc = pc << 8;
switch (oid[MTP3_OID_LEN+2])
{
case 1:
oldpar = mtp3_para->nw[0].opc14;
mtp3_para->nw[0].opc14 = decode_integer((BYTE*)&pc,4);
if (oldpar != mtp3_para->nw[0].opc14)
{
mtp3_reset_sccp();
mtp3_delete_opc(0, mtp3_para->nw[0].opc14);
}
return 3;
case 2:
oldpar = mtp3_para->nw[1].opc14;
mtp3_para->nw[1].opc14 = decode_integer((BYTE*)&pc,4);
if (oldpar != mtp3_para->nw[1].opc14)
{
mtp3_reset_sccp();
mtp3_delete_opc(1, mtp3_para->nw[1].opc14);
}
return 3;
case 3:
oldpar = mtp3_para->nw[2].opc14;
mtp3_para->nw[2].opc14 = decode_integer((BYTE*)&pc,4);
if (oldpar != mtp3_para->nw[2].opc14)
{
mtp3_reset_sccp();
mtp3_delete_opc(2, mtp3_para->nw[2].opc14);
}
return 3;
case 4:
oldpar = mtp3_para->nw[3].opc14;
mtp3_para->nw[3].opc14 = decode_integer((BYTE*)&pc,4);
if (oldpar != mtp3_para->nw[3].opc14)
{
mtp3_reset_sccp();
mtp3_delete_opc(3, mtp3_para->nw[3].opc14);
}
return 3;
case 5:
oldpar = mtp3_para->nw[0].opc24;
mtp3_para->nw[0].opc24 = decode_integer((BYTE*)&pc,4);
if (oldpar != mtp3_para->nw[0].opc24)
{
mtp3_reset_sccp();
mtp3_delete_opc(0, mtp3_para->nw[0].opc24);
}
return 3;
case 6:
oldpar = mtp3_para->nw[1].opc24;
mtp3_para->nw[1].opc24 = decode_integer((BYTE*)&pc,4);
if (oldpar != mtp3_para->nw[1].opc24)
{
mtp3_reset_sccp();
mtp3_delete_opc(1, mtp3_para->nw[1].opc24);
}
return 3;
case 7:
oldpar = mtp3_para->nw[2].opc24;
mtp3_para->nw[2].opc24 = decode_integer((BYTE*)&pc,4);
if (oldpar != mtp3_para->nw[2].opc24)
{
mtp3_reset_sccp();
mtp3_delete_opc(2, mtp3_para->nw[2].opc24);
}
return 3;
case 8:
oldpar = mtp3_para->nw[3].opc24;
mtp3_para->nw[3].opc24 = decode_integer((BYTE*)&pc,4);
if (oldpar != mtp3_para->nw[3].opc24)
{
mtp3_reset_sccp();
mtp3_delete_opc(3, mtp3_para->nw[3].opc24);
}
return 3;
default:
return -1;
}
break;
case 4:/* linkset */
instance = oid[MTP3_OID_LEN+3];
if (instance > 127)
return -1;
switch (oid[MTP3_OID_LEN+2])
{
case 1:
oldpc = mtp3_para->ls_op_pc[instance];
old_lsnw = mtp3_para->ls_pro[instance] & 3;
if(datalen>=24)
{
memcpy(&opc, &pdata[20], 4);
opc = ntohl(opc);
}
oldopc = mtp3_para->ls_opc[instance];
mtp3_para->ls_opc[instance]=opc;
new_lsnw = pdata[3] & 3;
memcpy(&pc,pdata,4);
pc = pc << 8;
mtp3_para->ls_op_pc[instance] = decode_integer((BYTE*)&pc,4);
/* linkset adjacent sp */
mtp3_para->ls_pro[instance] = pdata[3];
memcpy(&mtp3_para->ls_reserved[instance],&pdata[4],16);
if (old_lsnw != new_lsnw)
{
change_the_whole_ls(instance,old_lsnw,new_lsnw);
}
if ((oldpc != mtp3_para->ls_op_pc[instance]) ||
(old_lsnw != new_lsnw)||(oldopc != mtp3_para->ls_opc[instance]) )
{
pc = mtp3_para->ls_op_pc[instance];
for (i=0;i<256;i++)
{
if (mtp3_para->nw[new_lsnw].dpc[i] == pc && mtp3_para->nw[new_lsnw].opc[i] == opc)
{
mtp3.ls[instance].adjacent_sp_place = i;
return 24;
}
}
// printf("not found pc in table\n");
mtp3.ls[instance].adjacent_sp_place = 0xffff;
}
return 24;
default:
return -1;
}
break;
case 5:/* link */
instance = oid[MTP3_OID_LEN+3];
switch (oid[MTP3_OID_LEN+2])
{
case 1:/* e1 to linkset */
ls = pdata[0];
slc = pdata[1];
memcpy(&ip,&pdata[2],4);
memcpy(&ip1,&pdata[15],4);
// ip = pdata[2];
tp = pdata[6];
if(ip == ip1 && ip1 != 0xffffff)
{//ip can not be same as ip1
ip1 = 0xffffffff;
memcpy(&pdata[15], &ip1, 4);
}
if (ls!=mtp3_para->lk[instance].e1_to_linkset || slc!=mtp3_para->lk[instance].e1_to_slc
|| ip!=mtp3_para->lk[instance].e1_to_mtp3 || ip1!=mtp3_para->lk[instance].e1_to_alterMTP3
|| tp != mtp3_para->lk[instance].e1_lk_type)
{
mtp3_setlink_to_IDLE(instance);
para_changed = 1;
}
if (datalen<19)
memcpy((BYTE *)&mtp3_para->lk[instance].e1_to_linkset, pdata, 15);
else
memcpy((BYTE *)&mtp3_para->lk[instance].e1_to_linkset, pdata, 19);
mtp3ObjState.link_type[instance] = mtp3_para->lk[instance].e1_lk_type;
if (para_changed)
{
if (update_ls_slc_table(instance) == 1)
{
update_sls_to_link_table(ls);
MTP3_LinkIP_List(mtp3_para->lk[instance].e1_to_mtp3,1);
MTP3_LinkIP_List(mtp3_para->lk[instance].e1_to_alterMTP3,1);
}
}
#ifdef _INCLUDE_M2UA
set_m2ua_link(instance & 0xff, pdata);
#endif
return 19;
case 2:/* link command */
mtp3ObjState.lk_command[instance] = pdata[0];
if (mtp3ObjState.lk_mtp3[instance] != mtp3_localip)
return 1;
if (MTP3_LINK_TYPE(instance) == LKTYPE_MTP3_LITE)
{
if (pdata[0]==0)//disable
deactive_mtp3lite_lk(instance);
return 1;
}
else if (MTP3_LINK_TYPE(instance) == LKTYPE_M3UA)
{
if (pdata[0]==0)//disable
deactive_m3ua_lk(instance);
return 1;
}
else
{
command = pdata[0];
if (command < 2)
{
mtp3ObjInput.lsac_input_from_mgmt[instance] = command;
return 1;
}
else if (command < 4)
{
mtp3ObjInput.tlac_input_from_mgmt[instance] = command - 1;
return 1;
}
else
return -1;
}
case 3:/* MTP3LITE TCP Port */
mtp3_para->mtp3lite_port = pdata[1];
mtp3_para->mtp3lite_port = (mtp3_para->mtp3lite_port << 8) | pdata[0];
return 2;
default:
return -1;
}
break;
case 6:/* routine table */
instance = oid[MTP3_OID_LEN+3];
memcpy(&pc,pdata,4);
memcpy(&rc,&pdata[5],4);
pc = pc << 8;
memcpy(&opc, &pdata[9], 4);
if ((oid[MTP3_OID_LEN+2] > 4) || (oid[MTP3_OID_LEN+2] < 1))
return -1;
update_ls_influence_dst_table((oid[MTP3_OID_LEN+2]-1),pc,instance,pdata[3],pdata[4], rc, opc);
return 13;
case 7:/* dpc->acn */
instance = oid[MTP3_OID_LEN+3];
if (oid[MTP3_OID_LEN+2] == 1)
{
memcpy(mtp3_para->localAcn,pdata,MAX_ACN_NUM);
}
else if ((oid[MTP3_OID_LEN+2] > 1) && (oid[MTP3_OID_LEN+2] < 6))
{
memcpy(mtp3_para->nw[oid[MTP3_OID_LEN+2]-2].acn[instance],pdata,MAX_ACN_NUM);
}
else
return -1;
return MAX_ACN_NUM;
case 8:/* timer */
instance = oid[MTP3_OID_LEN+3];
switch (oid[MTP3_OID_LEN+2])
{
case 1:/* link timer */
memcpy(&mtp3_para->lt[instance].t1,pdata,10);
update_timer(instance);
return 10;
default:
return -1;
}
return -1;
case 9:/* sg */
instance = oid[MTP3_OID_LEN+2];
memcpy(&mtp3_para->sg[instance],pdata,7);
#ifdef _INCLUDE_M2UA
set_m2ua_sg(instance & 0xff, pdata);
return 7;
#else
return 7;
#endif
default:
return -1;
}
return -1;
}
else if (oid[MTP3_OID_LEN] == 3)/* status */
{
switch (oid[MTP3_OID_LEN+1])
{
case 7:
case 8:/* command */
switch (pdata[0])
{
case 1:
reset_mtp3();
break;
case 2:
printf("save parameter\n");
return mtp3_write_parameter();
break;
case 3://load data
mtp3_reload_data();
break;
default:
break;
}
return 1;
default:
return -1;
}
}
else
return -1;
}
void mtp3_data_reverse(BYTE *pdata,BYTE *csta,BYTE len,BYTE data_type)
{
int i;
int j=0;
for (i=0; i<len; i++)
{
if ( (i % data_type) ==0 )
j = i;
pdata[i] = csta[data_type - i%data_type - 1 + j];
}
}
void second_to_min(BYTE object,BYTE portion_num,BYTE instance)
{// change the duration(second) to duration(min)
BYTE temp;
int i;
switch (object)
{
case 0:
for (i=3;i<7;i++)
{
temp = mtp3_measure.measure[portion_num].lk_measure1[instance][i];
temp = (temp + 3) / 6;
if (temp > 15)
temp = 15;
mtp3_measure.measure[portion_num].lk_measure1[instance][i] = temp;
}
break;
case 1:
temp = mtp3_measure.measure[portion_num].ls_measure[instance][0];
temp = (temp + 3) / 6;
if (temp > 15)
temp = 15;
mtp3_measure.measure[portion_num].ls_measure[instance][0] = temp;
temp = mtp3_measure.measure[portion_num].ls_measure[instance][6];
temp = (temp + 3) / 6;
if (temp > 15)
temp = 15;
mtp3_measure.measure[portion_num].ls_measure[instance][6] = temp;
break;
default:
break;
}
}
int mtp_getmib(BYTE oidlen, DWORD *oid, BYTE *pdata,BYTE *vartype)
{
/* 1.3.6.1.4.1.1373.1.1.2.2.2.2 */
unsigned int instance;
BYTE portion_num=0;
DWORD timestamp;
DWORD get_rc=0;
if ( oidlen < 12 )
{
printf("get fail,object id not correct\n");
return -1;
}
if ( oid[MTP3_OID_LEN] == 2 )/* configure */
{
switch (oid[MTP3_OID_LEN+1])
{
case 1:/* sp/stp */
return -1;
case 2:/* 14/24bit (for four service networks) */
*vartype = 4;
return mtp_encode_integer(pdata,mtp3_para->nw_pro,1);
case 3:/* opc */
*vartype = 4;
switch (oid[MTP3_OID_LEN+2])
{
case 1:
return mtp_encode_integer(pdata,mtp3_para->nw[0].opc14,4);
case 2:
return mtp_encode_integer(pdata,mtp3_para->nw[1].opc14,4);
case 3:
return mtp_encode_integer(pdata,mtp3_para->nw[2].opc14,4);
case 4:
return mtp_encode_integer(pdata,mtp3_para->nw[3].opc14,4);
case 5:
return mtp_encode_integer(pdata,mtp3_para->nw[0].opc24,4);
case 6:
return mtp_encode_integer(pdata,mtp3_para->nw[1].opc24,4);
case 7:
return mtp_encode_integer(pdata,mtp3_para->nw[2].opc24,4);
case 8:
return mtp_encode_integer(pdata,mtp3_para->nw[3].opc24,4);
default:
return -1;
}
return -1;
case 4:/* linkset */
instance = oid[MTP3_OID_LEN+3];
*vartype = 4;
switch (oid[MTP3_OID_LEN+2])
{
case 1:
mtp_encode_integer(pdata,mtp3_para->ls_op_pc[instance],4);
pdata[3] = mtp3_para->ls_pro[instance];
memcpy(&pdata[4],&mtp3_para->ls_reserved[instance],16);
get_rc = htonl(mtp3_para->ls_opc[instance]);
memcpy(&pdata[20], &get_rc, 4);
return 24;
/* linkset adjacent sp */
default:
return -1;
}
return -1;
case 5:/* link */
instance = oid[MTP3_OID_LEN+3];
*vartype = 4;
switch (oid[MTP3_OID_LEN+2])
{
case 1:/* e1 to linkset */
memcpy(pdata,&mtp3_para->lk[instance].e1_to_linkset,19);
return 19;
case 2:
memcpy(pdata,&mtp3ObjState.lk_command[instance],1);
return 1;
case 3:
pdata[0] = mtp3_para->mtp3lite_port;
pdata[1] = mtp3_para->mtp3lite_port >> 8;
return 2;
default:
return -1;
}
return -1;
case 6:/* internation network routine table */
instance = oid[MTP3_OID_LEN+3];
*vartype = 4;
switch (oid[MTP3_OID_LEN+2])
{
case 1:
mtp_encode_integer(pdata,mtp3_para->nw[0].dpc[instance],4);
memcpy(&pdata[3],&mtp3_para->nw[0].normal_ls[instance],1);
memcpy(&pdata[4],&mtp3_para->nw[0].alternative_ls[instance],1);
get_rc = htonl(mtp3_para->nw[0].rc[instance]);
memcpy(&pdata[5], &get_rc, 4);
get_rc = htonl(mtp3_para->nw[0].opc[instance]);
memcpy(&pdata[9], &get_rc, 4);
return 13;
case 2:
mtp_encode_integer(pdata,mtp3_para->nw[1].dpc[instance],4);
memcpy(&pdata[3],&mtp3_para->nw[1].normal_ls[instance],1);
memcpy(&pdata[4],&mtp3_para->nw[1].alternative_ls[instance],1);
get_rc = htonl(mtp3_para->nw[1].rc[instance]);
memcpy(&pdata[5], &get_rc, 4);
get_rc = htonl(mtp3_para->nw[1].opc[instance]);
memcpy(&pdata[9], &get_rc, 4);
return 13;
case 3:
mtp_encode_integer(pdata,mtp3_para->nw[2].dpc[instance], 4);
memcpy(&pdata[3],&mtp3_para->nw[2].normal_ls[instance],1);
memcpy(&pdata[4],&mtp3_para->nw[2].alternative_ls[instance],1);
get_rc = htonl(mtp3_para->nw[2].rc[instance]);
memcpy(&pdata[5], &get_rc, 4);
get_rc = htonl(mtp3_para->nw[2].opc[instance]);
memcpy(&pdata[9], &get_rc, 4);
return 13;
case 4:
mtp_encode_integer(pdata,mtp3_para->nw[3].dpc[instance],4);
memcpy(&pdata[3],&mtp3_para->nw[3].normal_ls[instance],1);
memcpy(&pdata[4],&mtp3_para->nw[3].alternative_ls[instance],1);
get_rc = htonl(mtp3_para->nw[3].rc[instance]);
memcpy(&pdata[5], &get_rc, 4);
get_rc = htonl(mtp3_para->nw[3].opc[instance]);
memcpy(&pdata[9], &get_rc, 4);
return 13;
default:
return -1;
}
return -1;
case 7:
instance = oid[MTP3_OID_LEN+3];
*vartype = 4;
if (oid[MTP3_OID_LEN+2] == 1)
{
memcpy(pdata,mtp3_para->localAcn,MAX_ACN_NUM);
}
else if ((oid[MTP3_OID_LEN+2] > 1) && (oid[MTP3_OID_LEN+2] < 6))
{
memcpy(pdata,mtp3_para->nw[oid[MTP3_OID_LEN+2]-2].acn[instance],MAX_ACN_NUM);
}
else
return -1;
return MAX_ACN_NUM;
case 8:
instance = oid[MTP3_OID_LEN+3];
*vartype = 4;
switch (oid[MTP3_OID_LEN+2])
{
case 1:/* link timer */
memcpy(pdata,&mtp3_para->lt[instance].t1,10);
return 10;
default:
return -1;
}
return -1;
case 9:/* SG */
instance = oid[MTP3_OID_LEN+2];
*vartype = 4;
memcpy(pdata,&mtp3_para->sg[instance],7);
return 7;
default:
return -1;
}
return -1;
}
else if (oid[MTP3_OID_LEN] == 3)/* status */
{
*vartype = 4;
switch (oid[MTP3_OID_LEN+1])
{
case 1:/* link status */
return mtp_encode_integer(pdata,mtp3ObjState.link_l3_state[oid[MTP3_OID_LEN+2]],1);
case 2:/* linkset status */
instance= oid[MTP3_OID_LEN+2];
if (instance > 127)
return -1;
if (mtp3.ls[instance].links_available > 0)
pdata[0] = 1;
else
pdata[0] = 0;
return 1;
case 3:/* international network routine */
return mtp_encode_integer(pdata,mtp3.nw[0].routine[oid[MTP3_OID_LEN+2]],1);
case 4:/* international network spare routine */
return mtp_encode_integer(pdata,mtp3.nw[1].routine[oid[MTP3_OID_LEN+2]],1);
case 5:/* national network routine */
return mtp_encode_integer(pdata,mtp3.nw[2].routine[oid[MTP3_OID_LEN+2]],1);
case 6:/* national network spare routine */
return mtp_encode_integer(pdata,mtp3.nw[3].routine[oid[MTP3_OID_LEN+2]],1);
case 7:/* version */
memcpy(pdata,mtp3_heartbeat.version,3);
return 3;
default:
return -1;
}
}
else if (oid[MTP3_OID_LEN] == 1)/* measurement */
{
switch (oid[MTP3_OID_LEN+1])
{
case 1:/* MTP signalling link faults and performance */
*vartype = 4;
instance = oid[MTP3_OID_LEN+2];
if (instance > 8)
return -1;
portion_num = oid[MTP3_OID_LEN+3];
if ( (portion_num > 95) ||
(portion_num == mtp3_csta_p) )
return -1;
timestamp = mtp3_measure.measure[portion_num].time_stamp;
if (timestamp == 0)
return 0;
second_to_min(0,portion_num,instance);
mtp3_data_reverse(pdata,(BYTE*)&timestamp,4,4);
mtp3_data_reverse(&pdata[4],(BYTE*)&mtp3_measure.measure[portion_num].lk_measure1[instance],36,4);
return 40;
case 2:/* Signalling link availability */
return -1;
case 3:/* Signalling link set and route set availability */
*vartype = 4;
instance = oid[MTP3_OID_LEN+2];
if (instance > 127)
return -1;
portion_num = oid[MTP3_OID_LEN+3];
/* if ( (portion_num > 95) ||
(portion_num == mtp3_csta_p) )
return -1;*/
timestamp = mtp3_measure.measure[portion_num].time_stamp;
/* if (timestamp == 0)
return 0;*/
second_to_min(1,portion_num,instance);
mtp3_data_reverse(pdata,(BYTE*)&timestamp,4,4);
mtp3_data_reverse(&pdata[4],(BYTE*)&mtp3_measure.measure[portion_num].ls_measure[instance],32,4);
return 36;
case 5:/* Signalling traffic distribution */
switch (oid[MTP3_OID_LEN+2])
{
case 1:/* total traffic */
*vartype = 4;
instance = oid[MTP3_OID_LEN+3];
portion_num = oid[MTP3_OID_LEN+4];
if ( (portion_num > 95) ||
(portion_num == mtp3_csta_p) )
return -1;
/* if (instance < 8)
{
timestamp = mtp3_measure.measure[portion_num].time_stamp;
if (timestamp == 0)
return 0;
mtp3_data_reverse(pdata,(BYTE*)&timestamp,4,4);
mtp3_data_reverse(&pdata[4],(BYTE*)&mtp3_measure.measure[portion_num].tf_measure1[instance-1],80,4);
return 84;
}*/
else if (instance < 14)
{
timestamp = mtp3_measure.measure[portion_num].time_stamp;
if (timestamp == 0)
return 0;
mtp3_data_reverse(pdata,(BYTE*)&timestamp,4,4);
mtp3_data_reverse(&pdata[4],(BYTE*)&mtp3_measure.measure[portion_num].tf_measure2[instance-8],80,4);
return 84;
}
else
return -1;
default:
return -1;
}
return -1;
case 6:/* error */
*vartype = 4;
portion_num = oid[MTP3_OID_LEN+2];
if ( (portion_num > 95) ||
(portion_num == mtp3_csta_p) )
return -1;
timestamp = mtp3_measure.measure[portion_num].time_stamp;
if (timestamp == 0)
return 0;
mtp3_data_reverse(pdata,(BYTE*)&timestamp,4,4);
mtp3_data_reverse(&pdata[4],(BYTE*)mtp3_measure.measure[portion_num].tf_measure5,12,4);
return 16;
default:
return -1;
}
}
else
return -1;
}
void set_led(BYTE nled,BYTE ncolor);
//void set_alarm(BYTE component_id,BYTE alarm_code);
//void set_status(BYTE component_id,BYTE info_len,BYTE *info);
void set_heartbeat(BYTE reason,BYTE object)
{
BYTE place;
BYTE temp;
place = object/4;
temp = (object % 4)*2;
switch (reason)
{
case ALARM_LINK_UNAVAILABLE:
mtp3_heartbeat.link_state[place] &= (~(3<<temp));
break;
case ALARM_LINK_AVAILABLE:
mtp3_heartbeat.link_state[place] &= (~(3<<temp));
mtp3_heartbeat.link_state[place] |= (1<<temp);
break;
case ALARM_LINK_INHIBIT:
mtp3_heartbeat.link_state[place] = (mtp3_heartbeat.link_state[place] & (~(3<<temp))) | (1<<(temp+1));
break;
case ALARM_LS_UNAVAILABLE:
mtp3_heartbeat.linkset_state[place] &= (~(3<<temp));
break;
case ALARM_LS_AVAILABLE:
mtp3_heartbeat.linkset_state[place] &= (~(3<<temp));
mtp3_heartbeat.linkset_state[place] |= (1<<temp);
break;
case ALARM_LS_INHIBIT:
break;
case NORMAL_HEARTBEAT:
break;
}
set_status(MTP3_COMPONENT_ID,MTP3_HB_LEN,(BYTE*)&mtp3_heartbeat.version);
}
void mtp3_send_alarm(WORD component_id,BYTE alarm_code)
{
mtp3_heartbeat.state = 1;
set_led(3,9);
set_alarm(component_id,alarm_code);
// set_status(MTP3_COMPONENT_ID,MTP3_HB_LEN,(BYTE*)&mtp3_heartbeat.version);
}
void otherMTP3_managed_link_available(BYTE chl)
{
/* WORD lsno;
ls_info *ls;
lsno = mtp3_para->lk[chl].e1_to_linkset;
ls = &mtp3.ls[lsno];*/
mtp3ObjState.link_l2_state[chl] = MTP2_STATE_WORKING;
mtp3ObjInput.tsrc_input_from_tlac[chl] = TSRC_TLAC_LINK_AVAILABLE;
tsrc_proc(chl);
/* ls->links_available++;*/
hmrt_tcbc_update_routing_tables(chl);
}
void otherMTP3_managed_link_unavailable(BYTE chl)
{
/* WORD lsno;
ls_info *ls;
lsno = mtp3_para->lk[chl].e1_to_linkset;
ls = &mtp3.ls[lsno];*/
mtp3ObjInput.tsrc_input_from_tlac[chl] = TSRC_TLAC_LINK_UNAVAILABLE;
tsrc_proc(chl);
/* ls->links_available--;*/
hmrt_tcoc_update_routing_tables(chl);
// mtp3ObjState.tlac_state[chl] = TLAC_UNAVAILABLE_STATE;
/*init init_tlac_state*/
init_tlac_state[chl] = TRUE;
tlac_proc(chl);
init_lsac_state[chl] = TRUE;
lsac_proc(chl);
}
int sys_mtp3_table(DWORD ip)
{
int empty;
int i;
if (ip==0)
return -1;
empty = -1;
for (i=0;i<MAX_MTP3_NUM;i++)
{
if (MTP3IPMng.mtp3_flag_ip[i] == 0)
{
if (empty < 0)
empty = i;
}
if (MTP3IPMng.mtp3_flag_ip[i] == ip)
return i;
}
if (empty >= 0)
return empty;
return -1;
}
void master_MTP3(BYTE link,BYTE masterMTP3,DWORD srcIP)
{
DWORD NMTP3;
DWORD AMTP3;
masterMTP3 = masterMTP3 & 1;
NMTP3 = mtp3_para->lk[link].e1_to_mtp3;
AMTP3 = mtp3_para->lk[link].e1_to_alterMTP3;
if (srcIP==NMTP3)
{
if (masterMTP3)
mtp3ObjState.lk_NMTP3_ok[link] |= 1;
else
mtp3ObjState.lk_NMTP3_ok[link] &= 0xf0;
}
else if (srcIP==AMTP3)
{
if (masterMTP3)
mtp3ObjState.lk_AMTP3_ok[link] |= 1;
else
mtp3ObjState.lk_AMTP3_ok[link] &= 0xf0;
}
}
void trap_platform (BYTE oid_len,DWORD *oid_ptr,BYTE *msg_ptr,WORD msg_len,snmp_addr *addr)
{
heartbeat_msg *phbmsg = (heartbeat_msg *)msg_ptr;
BYTE *pstatus = phbmsg->info;
heartbeat_compoent_of_mtp3 *phbmtp3 = NULL;
WORD mtp3len=0;
int i,j,pos = 2; //component_id=0:iptrans;
BYTE newHeartbeat=0;
int chl;
BYTE chl_state;
DWORD remote_ip;
int temp;
struct in_addr in;
in.s_addr = addr->remote_ip;
mtp3_debug(MTP3DB_PFHB,"get platform heartbeat from %s",inet_ntoa(in));
if (msg_len > 128)
mtp3_showbuf(MTP3DB_PFHB,msg_ptr,128);
else
mtp3_showbuf(MTP3DB_PFHB,msg_ptr,msg_len);
remote_ip = addr->remote_ip;
if ((temp=sys_mtp3_table(remote_ip)) >= 0)
{
MTP3IPMng.mtp3_flag_new[temp] = 1;
MTP3IPMng.mtp3_flag_ip[temp] = remote_ip;
}
if ( remote_ip == mtp3_localip )/* heartbeat from itself */
return;
if ((temp=MTP3_LinkIP_List(remote_ip,0))<0)
return;
if (sizeof(struct heartbeat_msg) >= (INFO_LEN + 18))
newHeartbeat = 1;
if (!newHeartbeat)
{//old version heartbeat, length and component_id are one octet
pos = 1;
pos += pstatus[pos]+1; //length of iptrans status
pos++; //component_id=1:MTP3
mtp3len = pstatus[pos];
pos++; //length of mtp3 hb
if (pstatus[pos-1] != 1)//not mtp3 component
return;
}
else
{//new version heartbeat, length and component_id are 2 octets
pos ++; //length is 2 octets
pos += pstatus[pos]+1; //length of iptrans status
pos ++; //component_id=1:mtp3
pos ++; //component_id is 2 octets
if (pstatus[pos-1] != 1)//not mtp3 component
return;
mtp3len = pstatus[pos]*256+pstatus[pos+1];
pos ++; //length of mtp3 hb
pos ++; //length is 2 octets
}
phbmtp3 = (heartbeat_compoent_of_mtp3*)&pstatus[pos];
if (mtp3len > MTP3_HB_LEN || mtp3len < (MTP3_HB_LEN-34))
return;
for (i=0; i<64; i++)
{
temp = phbmtp3->link_state[i];
for (j=0; j<4; j++)
{
chl = i*4+j;
chl_state = (temp >> (j*2)) & 3;
if ( (mtp3ObjState.lk_mtp3[chl] == remote_ip) &&
(mtp3ObjState.link_l3_state[chl] != chl_state) )
{
if ( mtp3ObjState.lk_configured[chl] != PARA_CONFIGURED )
{
continue;
}
switch (chl_state)
{
case UNAVAILABLE:
if (mtp3ObjState.link_l3_state[chl] == INHIBITED)
{
mtp3_debug(MTP3DB_EVENT,"link %d L3 state changed from INHIBITED to UNAVAILABLE,invoke by %s",chl,inet_ntoa(in));
mtp3ObjState.link_l3_state[chl] = UNAVAILABLE;
}
else
{
mtp3_debug(MTP3DB_EVENT,"link %d L3 out of service,invoke by %s",chl,inet_ntoa(in));
otherMTP3_managed_link_unavailable(chl);
}
break;
case AVAILABLE:
mtp3_debug(MTP3DB_EVENT,"link %d L3 in service,invoke by %s",chl,inet_ntoa(in));
otherMTP3_managed_link_available(chl);
break;
case INHIBITED:
mtp3_debug(MTP3DB_EVENT,"link %d L3 inhibited,invoke by %s",chl,inet_ntoa(in));
if (mtp3ObjState.link_l3_state[chl] == AVAILABLE)
otherMTP3_managed_link_unavailable(chl);
mtp3ObjState.link_l3_state[chl] = INHIBITED;
break;
default:
break;
}
}
}
}
if (mtp3len > 100)
{
for (i=0;i<32;i++)
{
for (j=0; j<8; j++)
{
chl = i*8+j;
master_MTP3(chl,(phbmtp3->masterMTP3[i]>>j),remote_ip);
}
}
if (mtp3len > 132)
{
MTP3IPMng.LinkIPSubSta[temp][0] = phbmtp3->SubState[0];
MTP3IPMng.LinkIPSubSta[temp][1] = phbmtp3->SubState[1];
}
else
{
MTP3IPMng.LinkIPSubSta[temp][0] = 0xff;
MTP3IPMng.LinkIPSubSta[temp][1] = 0xff;
}
}
else
{
MTP3IPMng.LinkIPSubSta[temp][0] = 0xff;
MTP3IPMng.LinkIPSubSta[temp][1] = 0xff;
}
}
void trap_mtp2 (BYTE oid_len,DWORD *oid_ptr,BYTE *msg_ptr,WORD msg_len,snmp_addr *addr)
{
int i;
mtp2_heartbeat *mtp2;
BYTE offset;
BYTE new_l2_state;
BYTE chl;
BYTE ls;
BYTE module_id;
struct in_addr in;
in.s_addr = addr->remote_ip;
mtp3_debug(MTP3DB_PRIMITIVE_MSG,"get MTP2 heartbeat from %s",inet_ntoa(in));
mtp3_showbuf(MTP3DB_PRIMITIVE_MSG,msg_ptr,msg_len);
mtp2 = (mtp2_heartbeat*)msg_ptr;
module_id = (mtp2->systemid & 1)*16+mtp2->moduleid;
if (module_id > 31)
return;
mtp2_flag_new[module_id] = 1;
offset = module_id << 3;
for ( i=0; i<8; i++ )
{
chl = offset + i;
mtp3ObjState.link_l1_state[chl] = (mtp2->l1_state >> i) & 1;
new_l2_state = mtp2->l2_state[i];/* e1 l2 state from mtp2 */
if ( (mtp3ObjState.lk_configured[chl] == PARA_NOT_CONFIGURED) ||
(mtp3ObjState.lk_mtp3[chl] != mtp3_localip) )
continue;
if ( new_l2_state != mtp3ObjState.link_l2_state[chl] )
{
ls = mtp3_para->lk[chl].e1_to_linkset;
if (new_l2_state == MTP2_STATE_WORKING)/* link from unavailable->available */
{
current_measure->lk_measure1[chl][2]++;/* restoration */
mtp3_debug(MTP3DB_EVENT,"link %d L2 in service",chl);
mtp3ObjInput.lsac_input_from_l2[chl] = LSAC_L2_IN_SERVICE;
}
else if (mtp3ObjState.link_l2_state[chl] == MTP2_STATE_WORKING)/* link from available->unavailable */
{
local_change_over[chl]++;
mtp3_debug(MTP3DB_EVENT,"link %d L2 out of service",chl);
mtp3ObjInput.lsac_input_from_l2[chl] = LSAC_L2_OUT_OF_SERVICE;
if ( mtp2->retrieved_bsnt[i] < 128 )
local_bsnt_retrievable[chl] = TRUE;
else
{
// mtp3_debug(MTP3_DEBUG_LOG,"Link %d BSNT RETRIEVE FAILED",chl);
local_bsnt_retrievable[chl] = FALSE;
}
mtp3ObjInput.sltc_input[chl] = SLTC_STOP;
sltc_proc(chl);
}
}
mtp3ObjState.link_l2_state[chl] = new_l2_state;
if ( (mtp2->e1_dstip[i]+32 != ((mtp3ObjState.lk_mtp3[chl] >> 16) & 0xff)) &&
(mtp3ObjState.lk_configured[chl] == PARA_CONFIGURED) )
send_command_to_mtp2(chl,MTP2_ACTIVE_LINK);/* give this port a correct ip */
retrieved_bsnt[chl] = mtp2->retrieved_bsnt[i];
}
if (mtp2->alarm_code == 3)
{
mtp2_buf_full[mtp2->alarm_component]++;
}
}
void mtp3_dealtrap(BYTE oid_len,DWORD *oid_ptr,BYTE *msg_ptr,WORD msg_len,snmp_addr *addr)
{
DWORD mtp2_oid[20] = MTP2_HB_OID;
DWORD platform_oid[20] = PLATFORM_HB_OID;
DWORD omc_oid[20] = MTP3_OMC_OID;
if (memcmp(&oid_ptr[9],&mtp2_oid[9],16)==0)
{
trap_mtp2 (oid_len,oid_ptr,msg_ptr,msg_len,addr);
}
else if (memcmp(&oid_ptr[9],&platform_oid[9],8)==0)
{
trap_platform(oid_len,oid_ptr,msg_ptr,msg_len,addr);
}
else if (memcmp(oid_ptr,omc_oid,MTP3_OMC_OID_LEN*sizeof(DWORD))==0)
{//omc heartbeat
if ((mtp3_para->MTP3SerialNum==0) ||//support old version, do not have serial number
(Bcd2Ull(&msg_ptr[39],MTP3_SERNUM_LEN)==mtp3_para->MTP3SerialNum) )
{
switch(msg_ptr[0])
{
case 0:
mtp3_primomcip = addr->remote_ip;
break;
case 1:
mtp3_secdomcip = addr->remote_ip;
break;
default:
break;
}
}
}
}
void mtp_snmp_init()
{
DWORD mib_oid[20] = MTP3_OID;
snmp_init(4957);
heartbeat_init(0xff);
inquire_setmsg(MTP3_OID_LEN,mib_oid, mtp_setmib);
inquire_getmsg(MTP3_OID_LEN,mib_oid, mtp_getmib);
// inquire_trapmsg(trapcall trap_mtp2)/* mtp2 heartbeat */
inquire_trapmsg(mtp3_dealtrap);
// rob_trapmsg(MTP2_HBOID_LEN,mtp2_oid,trap_mtp2);
}
/*@end@*/