/*      XAPP coding test function head file     */
/*      created by Liu Wei 2006-01-13           */
/*      Version 1.0                                     */
/*      -------------------------------------   */

#include "xapp_main.h"

#ifndef _XAPP_CODING_TEST_

#define _XAPP_CODING_TEST_

struct mapp_struct
{
     struct MapOprSrv_struct map_opr;
     struct MapOprData_struct data_ptr;
     //struct MapOprData_struct data_ptr_bak;
     struct MapComSrv_struct com_ptr;
};

typedef struct _CAP_Message
{
     unsigned char msgLength[2];        /* unsigned char0 is the higher part */
     unsigned char msgServiceCode;      /* fixed as 0xAF */
     unsigned char port_id[3];  /* unsigned char 0 is the higher part,unsigned char 1 is the lower part ,and unsigned char 2 is reserved */
     unsigned char dialogue_id[3];
     unsigned char msgOperaCode;        /* message type code ,e.g , InitialDP = 0x00 */
     unsigned char msgOperaType;        /* 1/2/3/4 = request, indicate, response, confirm */
     unsigned char msgContent[CAP_CONTENT_LEN];
     /* if the message if cap operation ,then the first unsigned char of msgContent is invoke id */
}
CAP_Message, *PCAP_Message;

struct capp_struct
{
     struct CapArg cap_opr;
     struct MapOprData_struct data_ptr;
     struct MapComSrv_struct com_ptr;
     //CAP_Message capmsg;
};

struct test_xapp_struct
{
     int  sock;
     u8   fsm_state;
     u8   did;
     u8   invoke_id;
     u8   xapp_type;
     u8   ms_mode;
     u8   test_result;
     u8   operation_type;
     u8   local_ssn;
     u8   peer_ssn;
     u8   peer_state;
     u32  wait_time;
     struct SCCP_ADDRESS local_add;
     struct SCCP_ADDRESS peer_add;
     union
     {
          struct mapp_struct mapp;
          struct capp_struct capp;
     }
     xapp;
}
test_xapp;

enum XAPP_TEST_OP test_cmd;
int  bcd_hton(BYTE * netbcd, const BYTE * hostbcd, BYTE max_octet);
int  bcd_ntoh(BYTE * hostbcd, const BYTE * netbcd, BYTE max_octet);
void isdn_aton(u8 *normal_isdn,u8 *anti_isdn);
void imsi_aton(u8 *normal_imsi,u8 *anti_imsi);
void imsi_ntos(u8 *str_imsi,u8 *normal_imsi);
void imsi_ston(u8 *normal_imsi,u8 *str_imsi);
void isdn_ntos(u8 *str_isdn,u8 *normal_isdn);
void imsi_ntoa(u8 *anti_imsi,u8 *normal_imsi);

void isdn_ntoa(u8 * anti_isdn, u8 * normal_isdn);
u8 isdn_ston(u8 *normal_isdn,u8 *str_isdn);

void xapp_set_sccpadd(u8 ssn, u8 * gtt_num, struct SCCP_ADDRESS *sccp_add);

int  build_xapp_msg();
int  extract_xapp_msg();

u8   get_mapp_open(struct MapComSrv_struct *com_ptr, u8 ssn);
u8   send_mapp_comdata(struct MapComSrv_struct *com_ptr, u8 DelimiterFlag);
u8   recv_mapp_comdata(struct MapComSrv_struct *com_ptr, u32 did);
int  send_mapp_oprdata(struct MapOprData_struct *opr_ptr, u8 DelimiterFlag);
int  recv_mapp_oprdata(struct MapOprData_struct *opr_ptr, u32 did);

int  send_mapp_open_req(WORD dialog_id);
int  send_mapp_open_conf();
int  send_mapp_close(WORD dialog_id);

u8   get_capp_open(struct MapComSrv_struct *com_ptr, u8 ssn);
u8   send_capp_comdata(struct MapComSrv_struct *com_ptr, u8 DelimiterFlag);
u8   recv_capp_comdata(struct MapComSrv_struct *com_ptr, u32 did);
int  send_capp_oprdata(struct MapOprData_struct *opr_ptr, u8 DelimiterFlag);
int  recv_capp_oprdata(struct MapOprData_struct *opr_ptr, u32 did);
int  send_capp_open_req(unsigned char acn, unsigned char acn_v, unsigned short dlgid);
void send_capp_open_conf(unsigned char acn, unsigned char acn_v, unsigned short dlgid);
void send_capp_close(unsigned short dlgid);

void extract_sri();

#endif
