
/********************************************************************/
/*Title:        scoc.c                                                                                                  */
/*Descr:        SCCP Connection-Oriented Control                                                */
/*Author:       Liang Hanxi                                                                                             */
/*Create:       2002-2-19                                                                                               */
/*Modify:       2003-5-9                                                                                                */

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

/*===========import================*/
extern int scrc_route ( Intra_Msg * pIntraMsg, BOOL ForceAnsi );
extern int build_msg ( BYTE * buf, Intra_Msg * intramsg, BYTE NetID, BYTE ansi_flag );  //sccpmsg.c
extern int parse_msg ( BYTE * buf, Intra_Msg * intramsg, int len, BYTE NetID, BYTE ansi_flag ); //sccpmsg.c

/*===========export================*/
int scrc2scoc ( Intra_Msg * intramsg, BYTE AnsiFlag );
int scoc_store ( up_message * sccpmsg );

/*
int scrc2scoc ( Intra_Msg * intramsg, BYTE AnsiFlag )
{
    up_message mtp3msg;

    mtp3msg.len = build_msg ( mtp3msg.msgList, intramsg, intramsg->NetID, AnsiFlag );
    mtp3msg.dest_ip = intramsg->CDA.ip;
    mtp3msg.dpc = intramsg->DPC;
    mtp3msg.opc = intramsg->OPC;
    mtp3msg.sio = intramsg->NetID * 0x40 + 3;
    mtp3msg.cic[0] = intramsg->SLS;
    mtp3msg.link = intramsg->link;

    scoc_store ( &mtp3msg );
    return 1;
}
*/
/*
   int scoc_store ( up_message * sccpmsg )
   {
   up_message *pmsg;

   SccpCsta[SccpCstaInd].utilization[4 - 3]++;
   spLogDebug ( SCCPDB_AIF, "MSC <== SCCP: CO Message. opc=%x,sio=%02x", sccpmsg->opc, sccpmsg->sio );
   spShowBCD ( SCCPDB_AIF, ( BYTE * ) sccpmsg, ( sccpmsg->len + 17 ) % 256 );

   pmsg = &ScocBuf.msgin[ScocBuf.rcvsub[0]];
   memcpy ( pmsg, sccpmsg, sizeof ( up_message ) );

   ScocBuf.rcvsub[0] = ( ScocBuf.rcvsub[0] + 1 ) % SS_MSG_NUM;
   if( ScocBuf.rcvsub[0] == ScocBuf.rcvsub[1] )
   ScocBuf.rcvsub[1] = ( ScocBuf.rcvsub[1] + 1 ) % SS_MSG_NUM;

   sccpmsg_st.msg_mtp_scoc++;
   return 1;
   }
 */

/******************************************************************/

/*==================    User Interface----->      ================*/

/******************************************************************/
/*
   int scoc_send ( up_message * pmsg )
   {
   BYTE ntype;
   BOOL ForceAnsi = 0;

   ntype = pmsg->msgList[0];

   spLogDebug ( SCCPDB_AIF, "MSC ==> SCCP: CO/UDT Message. opc=%x,sio=%02x,type=%d", pmsg->opc, pmsg->sio, ntype );
   spShowBCD ( SCCPDB_AIF, ( BYTE * ) pmsg, ( pmsg->len + 17 ) % 256 );
   SccpCsta[SccpCstaInd].utilization[0]++;
   switch ( ntype )
   {
   case CR_MSG:
   SccpCsta[SccpCstaInd].quality[4]++;
   break;
   case CC_MSG:
   break;
   case DT1_MSG:
   SccpCsta[SccpCstaInd].utilization[10 - 3]++;
   break;
   case DT2_MSG:
   SccpCsta[SccpCstaInd].utilization[12 - 3]++;
   break;
   }
   if( ntype == CR_MSG || ntype == UDT_MSG )
   {
   Intra_Msg outmsg;
   BYTE NetID = pmsg->sio / 0x40;

   memset ( &outmsg, 0, sizeof ( Intra_Msg ) );

   ForceAnsi = ( pmsg->sio >> 4 ) & 1;
   parse_msg ( pmsg->msgList, &outmsg, pmsg->len, NetID, ForceAnsi );

   outmsg.CDA.ip = INADDR_NONE;
   outmsg.OPC = pmsg->opc;
   outmsg.DPC = pmsg->dpc;
   outmsg.SLS = pmsg->cic[0];

   outmsg.NetID = outmsg.CGA.NetID = outmsg.CDA.NetID = NetID;
   return scrc_route ( &outmsg, ForceAnsi );
   }
   else
   {
   return sccp_to_mtp3 ( pmsg );
   }

   }

   int scoc_receive ( up_message * sccpmsg )
   {
   up_message *pmsg;

   if( ScocBuf.rcvsub[0] == ScocBuf.rcvsub[1] )
   return 0;
   pmsg = &ScocBuf.msgin[ScocBuf.rcvsub[1]];
   memcpy ( sccpmsg, pmsg, sizeof ( up_message ) );
   ScocBuf.rcvsub[1] = ( ScocBuf.rcvsub[1] + 1 ) % SS_MSG_NUM;
   sccpmsg_st.msg_scoc_up++;
   return 1;
   }
 */
