//////////////////////////////////////////////////
//Title    : sccp_func.h
//Auhtor   : Liu Wei
//Desc     : SCCP function decl   
//Created  : 2007-04-22
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////

/* sccp.c */
void sccp_init(void);
void sccp_init_serial_number(BYTE *Serial);
void sccp_timer(void);
void sccp_reset(void);
int AddToIpList(DWORD ip, BYTE ssn);
int CollectLocalInfo(void);
int sccp_mnp_register(BYTE flag, BYTE routing_method, BYTE usertype);
int spSetGttAddr(u8 uGtType, u8 uSSN, u8 *uGtNum, struct SCCP_ADDRESS *pSpAddr);

/* sccp_debug.c */
void spLogDebug_setup(void);
void spLogDebug_timer(void);
int parsecmd(char *cmdstr);
int sccp_filter_msg(SCCP_ADDR *pSrcAddr, SCCP_ADDR *pDstAddr);
void spLogDebug_info(BYTE npage, BYTE nline, BYTE *pt, BYTE len);
void spLogDebug_csta(BYTE npage, int instance);
void spLogDebug_local(BYTE npage, BYTE nline);
void spLogDebug_related(BYTE npage, BYTE nline);
void spLogDebug_buffer(BYTE npage);
void spLogDebug_errorCapture(BYTE npage, BYTE nline);
void spLogDebug_WatchDog(BYTE npage);
void sccp_list_route(void);
void sccp_put_capture_logs(BYTE person, BYTE *pictures, int len);

/* sccp_func.c */
int ParseLine(char *str, char (*row)[128], int maxrow);
int GetEnt(FILE *fp, char *key, char *str);
BOOL isco(Intra_Msg *intramsg);
BOOL iscl(Intra_Msg *intramsg);
BOOL iscr(Intra_Msg *intramsg);

/* sccp_gtt.c */
int BuildRouteIndex(void);
u_short SelectRoute(BYTE *pDigits, BYTE DigitsLen);
int GetACNInfo(SCCP_ADDR *pAddr, BYTE **pAcnInfo);
void TranslateGT(SCCP_ADDR *pAddr, SCCP_ROUTE *pRoute);
int AddRoute(BYTE *pStartDigits, BYTE *pEndDigits, BYTE DigitsLen, u_short index);
int AddLargerNode(SCCP_ROUTE_NODE *pNode, BYTE *pDigits, BYTE DigitsLen, u_short index);
int AddLessNode(SCCP_ROUTE_NODE *pNode, BYTE *pDigits, BYTE DigitsLen, u_short index);
SCCP_ROUTE_NODE *NewNode(void);
int CheckGT(BYTE np, BYTE tt, BYTE *gt, BYTE gt_len);

/* sccp_mib.c */
void sccpmib_init(void);
void sccp_sethb(void);
int sccp_setmib(BYTE oidlen, DWORD *oid, BYTE *pdata, WORD datalen);
int sccp_getmib(BYTE oidlen, DWORD *oid, BYTE *pdata, BYTE *vartype);
void sccp_OMCIP_detect(DWORD ip);
void sccp_trapcallback(BYTE oidlen, DWORD *oid, BYTE *pdata, WORD len, snmp_addr *addr);

/* sccp_msg.c */
int build_msg(BYTE *buf, Intra_Msg *intramsg, BYTE NetID, BYTE ansi_flag);
int parse_msg(BYTE *buf, Intra_Msg *intramsg, int len, BYTE NetID, BYTE ansi_flag);
int parse_oparam(BYTE *buf, int len, Intra_Msg *intramsg, BYTE NetID, BYTE ansi_flag);
int encode_int(BYTE *buf, unsigned int val, BYTE len);
unsigned int decode_int(BYTE *buf, BYTE len);
int encode_addr(BYTE *buf, SCCP_ADDR *addr, BYTE NetID);
int decode_addr(BYTE *buf, SCCP_ADDR *addr, BYTE NetID);
int encode_addr_Ansi(BYTE *buf, SCCP_ADDR *addr);
int decode_addr_Ansi(BYTE *buf, SCCP_ADDR *addr);

/* sclc.c */
int scrc2sclc(Intra_Msg *pIntraMsg);
int sclc_rf(Intra_Msg *pIntraMsg);
int scmg2sclc(Intra_Msg *pIntraMsg);
int sclc_send(SCLC_MSG *pmsg);
int sclc_receive(SCLC_MSG *pmsg, BYTE usertype);
void sclc_timer(void);
int sclc_mnp_send(SCLC_MSG *pmsg);
int SegmentingMsg(Intra_Msg *pIntraMsg);
int RecvXUDTMsg(Intra_Msg *pIntraMsg, BYTE nbuf);
int CheckSegUnID(Intra_Msg *pIntraMsg);
int RsmRegMsg(SCLC_MSG *pmsg, SCCP_SegMsgBuf *pSegMsgbuf, Intra_Msg *pIntraMsg);

/* sccp_param.c */
int GetMSISDNOfSSN(BYTE ssn, BYTE *msisdn);
int sccp_GetSSNType(BYTE ssn);
int sccp_loadparam(void);
void sccp_saveparam(void);
int sccp_setparam(DWORD *oid, BYTE *pdata, WORD datalen);
int sccp_getparam(DWORD *oid, BYTE *pdata, BYTE *vartype);
int SccpGetLocalIP(void);
int ParseLocalNode(char *str);
void ParseRouteInfo(char *str);
void ParseRLSSN(char *str);

/* scmg.c */
void localssn_timer(void);
int sclc2scmg(Intra_Msg *intramsg);
BOOL CheckAvail(SCCP_ADDR *addr);
BYTE ssn_status(int spc, BYTE ssn, BYTE NetID);
void spac(int spc, BYTE NetID);
void sppc(int spc, BYTE NetID);
void spcc(int spc, BYTE NetID);
int register_ssn(BYTE ssn, BYTE usertype);
void ssac(int spc, BYTE ssn, BYTE NetID, BOOL relay);
void sscc(int spc, BYTE ssn, BYTE NetID);
int stop_ssn(BYTE ssn);
void sspc(int spc, BYTE ssn, BYTE NetID, BOOL relay);
void sst_timer(void);
void lcst(int spc, BYTE ssn, BYTE ntype, BYTE NetID);
void bcst(BYTE ssn, BYTE ntype);
void bcst_relay(int spc, BYTE ssn, BYTE ntype, BYTE NetID);
int build_scmgmsg(BYTE *data, BYTE type, int spc, BYTE ssn, BYTE NetID);
int parse_scmgmsg(BYTE *data, BYTE *type, int *spc, BYTE *ssn, BYTE NetID);

/* scrc.c */
void scrc_timer(void);
int scrc_route(Intra_Msg *pIntraMsg, BOOL ForceAnsi);
int scrc_mnp_route(Intra_Msg *pIntraMsg, BOOL ForceAnsi);
int send_msg(Intra_Msg *pIntraMsg, BYTE ansi_flag);
int scrc_rf(Intra_Msg *pIntraMsg, BYTE AnsiFlag);
DWORD SelectIPOfSSN(BYTE ssn, BYTE sls, BOOL from_mtp);

/* scoc_fsm.c */
void coFsm (  );

/* scoc_func.c */
void coInit ( u32 sysID, u32 localIP, u32 alterIP  );
void cr2coFailHandle(Intra_Msg *pIntraMsg, u8 uAnsiFlag, u8 uMsgtype);
int cr2co(Intra_Msg *pIntraMsg, u8 uAnsiFlag);
void co2cr(u16 wConnId, u8 uMsgType);
void co2ul(u16 wConnId, u8 uPri);
void co2scmg(void);
void co2co(u16 wConnId, u8 uPri);
int spCheckAudit(void);
int coNewCS(u16 wConnId, SCCP_ADDR *pAddr);
void coFreeCS(u16 wConnId);
void coFillCS(SP_PriPoolEle *pPri);
int coCheckCS(u16 wConnId, u8 uCState, u8 uSide);
void coTimerOut(u16 wConnId, u8 uPri);
void coTimerMng(void);
int coNewConnId(u8 uPri);
int coGetConnId(u8 *pSLR);
extern int coCheckResource (  );
void spWatchDogStatic(u8 uDebugStaticMask);

/* sccp_log.c */
void spLog(char *info);
void spShowAddr(SCCP_ADDR *pAddr, const char *sAddrName);
void spLogDebug(DWORD mask, const char *fmt, ...);
void spShowErr(int checkFlag, char * str);
void spShowBCD(DWORD mask, BYTE *buf, int len);
void spLogSeg(SCCP_SegMsgBuf *pSegMsgbuf);
void spShowMsg(DWORD mask, const char *pDesc, Intra_Msg *pIntraMsg);
void spShowPrimitive(SP_UiPriPara *pUiPriParam, u8 uDirection);
void spLogStateError(u16 wConnId, u8 uErrCode);
void spLogTimerOut(u16 wConnId, u8 uTimerID);
void spShowUserData(SP_UiPriPara *pPri);

/* scoc_pool.c */
void spPoolInit(void);
int spPoolGet(SP_PriPoolEle *pPri, CO_Pool *pCoPool);
int spPoolPut(SP_PriPoolEle *pPri, CO_Pool *pCoPool);
