📄 x25function.c
字号:
if (s_BscConnectInfo[nTid].DownlinkStatus==BSC_STEADY)
{
HangupConnectNOWAIT(s_BscConnectInfo[nTid].X25DownlinkHandle,NULL, NULL ,NULL,0);
Del_Port_lsn(nTid,0);
s_BscConnectInfo[nTid].DownlinkStatus=BSC_DISCONNECT;
}
goto exit_thred;
}
}
/* 需要退出连接 */
if (s_BscConnectInfo[nTid].ConnectOpen==OFF)
{
if (s_BscConnectInfo[nTid].DownlinkStatus==BSC_STEADY)
{
HangupConnectNOWAIT(s_BscConnectInfo[nTid].X25DownlinkHandle,NULL, NULL ,NULL,0);
Del_Port_lsn(nTid,0);
s_BscConnectInfo[nTid].DownlinkStatus=BSC_DISCONNECT;
}
goto exit_thred;
}
/* 发送消息类型 */
s_BscConnectInfo[nTid].MessageType=s_BSCMessage.cMessage[0];
/* 保存该消息的Pid */
memcpy(&s_BscConnectInfo[nTid].s_Pid,&s_BSCMessage.s_Pid,sizeof(PID_t));
len=X25NoWaitSendData(s_BscConnectInfo[nTid].X25DownlinkHandle,&s_BSCMessage.cMessage[0],s_BSCMessage.iLen ,XD_NOTO,nTid);
if (len<=0)
{
printf("x25 Send Message Error!\n");
goto exit_thred;
}
if(s_BscConnectInfo[nTid].MessageType!=CBSE_RESET)
{
memset(ReceiveBuf,0,MESSAGE_LEN);
/* 接收结果 */
if ((len=X25NoWaitRecvData(s_BscConnectInfo[nTid].X25DownlinkHandle , ReceiveBuf ,XD_NOTO,nTid))<=0)
{
printf("X25 Receive data Error,RemoteAddr=%s\n",s_BscConnectInfo[nTid].BscAddr);
goto exit_thred;
}
else
{
Process_BSC_Message(ReceiveBuf,len,nTid);
}
}
else
{
/* 等待 */
Sleep(5000);
}
}
exit_thred:
/* 发送队列清空 */
CloseHandle(s_BscConnectInfo[nTid].s_X25SendMessageBuf.MsgFull);
CloseHandle(s_BscConnectInfo[nTid].s_X25SendMessageBuf.MsgEmpty);
CloseHandle(s_BscConnectInfo[nTid].s_X25SendMessageBuf.MsgMutex);
memset(&s_BscConnectInfo[nTid].s_X25SendMessageBuf,0,sizeof(X25_SEND_MESSAGE_BUF_t));
#ifdef DEBUG_PRINT
printf("Send Thread exit,BSCID=%d\n",*(unsigned short *)s_BscConnectInfo[nTid].BscIdentifier);
#endif
/* 退出发送线程告警 */
#ifdef OPEN_WARNING
memset(cWarningDescription,0,sizeof(WARNING_DESC_LEN));
sprintf(cWarningDescription,"X25发送线程退出,发送队列清空,BSCID=%d",*((unsigned short *)s_BscConnectInfo[nTid].BscIdentifier));
SendWarningToOmp(LINK_WARNING,X25_OUTPUT_QUEUE,cWarningDescription);
#endif
/* 告警 */
#ifdef OPEN_WARNING
memset(cWarningDescription,0,sizeof(WARNING_DESC_LEN));
sprintf(cWarningDescription,"下行连路断连,BSCID=%d",*((unsigned short *)s_BscConnectInfo[nTid].BscIdentifier));
SendWarningToOmp(LINK_WARNING,BSC_LINK,cWarningDescription);
#endif
if(s_BscConnectInfo[nTid].DownlinkStatus==BSC_STEADY)
{
s_BscConnectInfo[nTid].DownlinkStatus=BSC_DISCONNECT;
HangupConnectNOWAIT(s_BscConnectInfo[nTid].X25DownlinkHandle,NULL, NULL ,NULL,0);
Del_Port_lsn(nTid,0);
}
ExitThread(1);
}
/* 将消息加入X25发送消息队列中 */
int X25AppendCBESendMessage(BSCMESSAGE_t *s_BSCMessage,int Tid)
{
unsigned int iLoading;
#ifdef OPEN_WARNING
unsigned char cWarningDescription[WARNING_DESC_LEN];
#endif
if (s_BscConnectInfo[Tid].DownlinkStatus==BSC_DISCONNECT)
{
/* 发送告警给OMP */
#ifdef OPEN_WARNING
memset(cWarningDescription,0,WARNING_DESC_LEN);
sprintf(cWarningDescription,"BSC未连接,无法发送消息,BSCID=%d",*(unsigned short *)&s_BscConnectInfo[Tid].BscIdentifier[0]);
SendWarningToOmp(LINK_WARNING,X25_OUTPUT_QUEUE,cWarningDescription);
#endif
return FAILURE;
}
/* 缓冲区负荷控制 */
iLoading=X25MSG_QUEUE_SIZE-10;
if (s_BscConnectInfo[Tid].s_X25SendMessageBuf.iMsgCount>=iLoading)
{
/* sys告警 */
#ifdef OPEN_WARNING
memset(cWarningDescription,0,WARNING_DESC_LEN);
sprintf(cWarningDescription,"X25发送队列过负荷,无法加入新消息,BSCID=%d",*(unsigned short *)&s_BscConnectInfo[Tid].BscIdentifier[0]);
SendWarningToOmp(LINK_WARNING,X25_OUTPUT_QUEUE,cWarningDescription);
#endif
return FAILURE;
}
// if (s_BscConnectInfo[Tid].s_X25SendMessageBuf.iMsgCount==X25MSG_QUEUE_SIZE)
// {
/* 发送告警给OMP */
// memset(cWarningDescription,0,WARNING_DESC_LEN);
// sprintf(cWarningDescription,"X25发送队列已满,无法加入新消息,BSCID=%d",*(unsigned short *)&s_BscConnectInfo[Tid].BscIdentifier[0]);
// SendWarningToOmp(LINK_WARNING,X25_OUTPUT_QUEUE,cWarningDescription);
// return FAILURE;
// }
WaitForSingleObject(s_BscConnectInfo[Tid].s_X25SendMessageBuf.MsgEmpty,INFINITE);
WaitForSingleObject(s_BscConnectInfo[Tid].s_X25SendMessageBuf.MsgMutex,INFINITE);
memcpy(&s_BscConnectInfo[Tid].s_X25SendMessageBuf.s_Message[s_BscConnectInfo[Tid].s_X25SendMessageBuf.iTail],s_BSCMessage,sizeof(BSCMESSAGE_t));
if (++s_BscConnectInfo[Tid].s_X25SendMessageBuf.iTail==X25MSG_QUEUE_SIZE)
{
s_BscConnectInfo[Tid].s_X25SendMessageBuf.iTail = 0;
s_BscConnectInfo[Tid].s_X25SendMessageBuf.iMsgCount++;
}
ReleaseMutex(s_BscConnectInfo[Tid].s_X25SendMessageBuf.MsgMutex);
ReleaseSemaphore(s_BscConnectInfo[Tid].s_X25SendMessageBuf.MsgFull,1,NULL);
return SUCCESS;
}
/* 将消息加入X25发送消息队列中,优先级高 */
int X25AppendCBESendMessagePriority(BSCMESSAGE_t *s_BSCMessage,int Tid)
{
#ifdef OPEN_WARNING
unsigned char cWarningDescription[WARNING_DESC_LEN];
#endif
if (s_BscConnectInfo[Tid].DownlinkStatus==BSC_DISCONNECT)
{
/* 发送告警给OMP */
#ifdef OPEN_WARNING
memset(cWarningDescription,0,WARNING_DESC_LEN);
sprintf(cWarningDescription,"BSC未连接,无法发送消息,BSCID=%d",*(unsigned short *)&s_BscConnectInfo[Tid].BscIdentifier[0]);
SendWarningToOmp(LINK_WARNING,X25_OUTPUT_QUEUE,cWarningDescription);
#endif
return FAILURE;
}
if (s_BscConnectInfo[Tid].s_X25SendMessageBuf.iMsgCount==X25MSG_QUEUE_SIZE)
{
/* 发送告警给OMP */
#ifdef OPEN_WARNING
memset(cWarningDescription,0,WARNING_DESC_LEN);
sprintf(cWarningDescription,"X25发送队列已满,无法加入新消息,BSCID=%d",*(unsigned short *)&s_BscConnectInfo[Tid].BscIdentifier[0]);
SendWarningToOmp(LINK_WARNING,X25_OUTPUT_QUEUE,cWarningDescription);
#endif
return FAILURE;
}
WaitForSingleObject(s_BscConnectInfo[Tid].s_X25SendMessageBuf.MsgEmpty,INFINITE);
WaitForSingleObject(s_BscConnectInfo[Tid].s_X25SendMessageBuf.MsgMutex,INFINITE);
memcpy(&s_BscConnectInfo[Tid].s_X25SendMessageBuf.s_Message[s_BscConnectInfo[Tid].s_X25SendMessageBuf.iTail],s_BSCMessage,sizeof(BSCMESSAGE_t));
if (++s_BscConnectInfo[Tid].s_X25SendMessageBuf.iTail==X25MSG_QUEUE_SIZE)
{
s_BscConnectInfo[Tid].s_X25SendMessageBuf.iTail = 0;
s_BscConnectInfo[Tid].s_X25SendMessageBuf.iMsgCount++;
}
ReleaseMutex(s_BscConnectInfo[Tid].s_X25SendMessageBuf.MsgMutex);
ReleaseSemaphore(s_BscConnectInfo[Tid].s_X25SendMessageBuf.MsgFull,1,NULL);
return SUCCESS;
}
/* 从X25发送消息缓冲区中取出一条消息信息
WaitTime_len: 等待时长ms
* 返回
<0: 超时
>1: 成功
*/
int X25GetCBESendMsg(BSCMESSAGE_t *s_BSCMessage,int Tid, int WaitTime_len)
{
if (WaitForSingleObject(s_BscConnectInfo[Tid].s_X25SendMessageBuf.MsgFull,WaitTime_len)==WAIT_TIMEOUT)
{
return FAILURE;
}
WaitForSingleObject(s_BscConnectInfo[Tid].s_X25SendMessageBuf.MsgMutex,INFINITE);
memcpy(s_BSCMessage, &s_BscConnectInfo[Tid].s_X25SendMessageBuf.s_Message[s_BscConnectInfo[Tid].s_X25SendMessageBuf.iHead],sizeof(BSCMESSAGE_t));
if (++s_BscConnectInfo[Tid].s_X25SendMessageBuf.iHead==X25MSG_QUEUE_SIZE)
{
s_BscConnectInfo[Tid].s_X25SendMessageBuf.iHead = 0;
s_BscConnectInfo[Tid].s_X25SendMessageBuf.iMsgCount--;
}
ReleaseMutex(s_BscConnectInfo[Tid].s_X25SendMessageBuf.MsgMutex);
ReleaseSemaphore(s_BscConnectInfo[Tid].s_X25SendMessageBuf.MsgEmpty,1,NULL);
return SUCCESS;
}
/* 检查绑定参数 */
int Process_VBind_init(VBIND_t *s_VBind)
{
/* 名字 */
if (s_VBind->p_Name.bFlag==EXIST)
{
/* 操作员名 */
if (s_VBind->p_Name.s_Operate.bFlag==EXIST)
{
if (s_VBind->p_Name.s_Operate.clength>20)
{
return OPERATOR_LEN_ERROR;
}
}
/* 双边协议 */
if (s_VBind->p_Name.s_BilateralAgreem.bFlag==EXIST)
{
if (s_VBind->p_Name.s_BilateralAgreem.clength>20)
{
return BILATERALAGREEM_LEN_ERROR;
}
}
/* 数据网络地址 */
if (s_VBind->p_Name.s_DataNetWorkAddress.bFlag==EXIST)
{
if (s_VBind->p_Name.s_DataNetWorkAddress.clength>15)
{
return DATANETWORKADDRESS_LEN_ERROR;
}
}
}
/* 口令 */
if (s_VBind->p_PassWord.bFlag==EXIST)
{
if (s_VBind->p_PassWord.clength>20)
{
return PASSWORD_LEN_ERROR;
}
}
return SUCCESS;
}
/*
* 将字串地址转为7字节压缩地址,放在后面
*/
void AddrStringTo7Compress(char *LpAddr,unsigned char *LpCompressAddrBuf)
{
int len;
int i;
unsigned char lowbit;
int posi;
unsigned char buf[7];
unsigned char TempByte;
memset(buf,0,7);
len=strlen(LpAddr);
lowbit=1;
posi=6;
/* 从后往前压缩地址 */
for(i=len-1;i>=0;i--)
{
if (lowbit==1)
{
buf[posi]=*(LpAddr+i)-48;
lowbit=0;
}
else
{
TempByte=*(LpAddr+i)-48;
TempByte=TempByte<<4;
buf[posi]=buf[posi]|TempByte;
lowbit=1;
posi--;
}
}
memcpy(LpCompressAddrBuf,buf,7);
}
/* 接受上行X25数据 */
void X25UplinkRecieveData(int *Tid)
{
int nTid;
int Len;
unsigned char ReceiveBuf[MESSAGE_LEN];
#ifdef OPEN_WARNING
unsigned char cWarningDescription[WARNING_DESC_LEN];
#endif
nTid=*Tid;
for(;;)
{
/* 连接关闭,退出线程 */
if(s_BscConnectInfo[nTid].ConnectOpen==OFF)
{
goto end_thread;
}
Len=X25NoWaitRecvData(s_BscConnectInfo[nTid].X25UpLinkHandle , ReceiveBuf,2,nTid);
if(Len==FAILURE)
// if(Len<0)
{
goto end_thread;
}
while(Len==RECV_TIME_OUT)
{
if(s_BscConnectInfo[nTid].ConnectOpen==OFF)
{
goto end_thread;
}
Len=X25NoWaitRecvData(s_BscConnectInfo[nTid].X25UpLinkHandle , ReceiveBuf,2 ,nTid);
if(Len==FAILURE)
{
goto end_thread;
}
}
/* 处理Restart和FailureIndicater */
Process_BSC_Message(ReceiveBuf,Len,nTid);
}
end_thread:
if(s_BscConnectInfo[nTid].UplinkStatus==BSC_STEADY)
{
Del_Port_lsn(nTid,1);
/* 释放链路 */
HangupConnectNOWAIT(s_BscConnectInfo[nTid].X25UpLinkHandle,NULL, NULL ,NULL,0);
s_BscConnectInfo[nTid].UplinkStatus=BSC_DISCONNECT;
}
#ifdef DEBUG_PRINT
printf("X25 Uplink Recv thread Exit,RemoteAddr=%s\n",s_BscConnectInfo[nTid].BscAddr);
#endif
/* 告警 */
#ifdef OPEN_WARNING
memset(cWarningDescription,0,sizeof(WARNING_DESC_LEN));
sprintf(cWarningDescription,"上行链路断连,BSCID=%d",
*(unsigned short *)&s_BscConnectInfo[nTid].BscIdentifier[0]);
SendWarningToOmp(LINK_WARNING,BSC_LINK,cWarningDescription);
#endif
ExitThread(1);
}
/*
* 保存新建虚链路的X25卡中的端口号和逻辑会话号
* port: X25卡中的端口号
* lsn: 逻辑会话号
* Tid: 对应Bsc连接信息数组的偏移量
* IfUplink: 0下行链路;1上行链路
*/
void Add_Port_lsn(unsigned int port,unsigned int lsn,int Tid,unsigned char IfUplink)
{
memcpy(BscX25_Port_Lsn[Tid].BscAddr,s_BscConnectInfo[Tid].BscAddr,BSC_ADDR_LEN);
BscX25_Port_Lsn[Tid].BscAddr[BSC_ADDR_LEN]=0;
if (IfUplink==1)
{
BscX25_Port_Lsn[Tid].UplinkFlag=1;
BscX25_Port_Lsn[Tid].UplinkPort=port;
BscX25_Port_Lsn[Tid].UplinkLsn=lsn;
}
else
{
BscX25_Port_Lsn[Tid].DownlinkFlag=1;
BscX25_Port_Lsn[Tid].DownlinkPort=port;
BscX25_Port_Lsn[Tid].DownlinkLsn=lsn;
}
fseek(f_port_lsn,0,SEEK_SET);
/* 全写入文件 */
fwrite(&BscX25_Port_Lsn[0],sizeof(X25_PORT_LSN_t),MAX_BSC_CONNECT,f_port_lsn);
fflush(f_port_lsn);
}
/*
* 删除新建虚链路的X25卡中的端口号和逻辑会话号
* Tid: 对应Bsc连接信息数组的偏移量
* IfUplink: 0下行链路;1上行链路;2全清0
*/
void Del_Port_lsn(int Tid,unsigned char IfUplink)
{
if (IfUplink==1)
{
BscX25_Port_Lsn[Tid].UplinkFlag=0;
}
if (IfUplink==0)
{
BscX25_Port_Lsn[Tid].DownlinkFlag=0;
}
if (IfUplink==2)
{
memset(&BscX25_Port_Lsn[0],0,sizeof(X25_PORT_LSN_t)*MAX_BSC_CONNECT);
}
fseek(f_port_lsn,0,SEEK_SET);
/* 全写入文件 */
fwrite(&BscX25_Port_Lsn[0],sizeof(X25_PORT_LSN_t),MAX_BSC_CONNECT,f_port_lsn);
fflush(f_port_lsn);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -