📄 isupptl.cpp
字号:
}
}
// Calculate the length of PDU.
len = pPdu - pdu;
return pdu;
}
char * CIsupPdu::ComposeJoyitApi(UINT16& len)
{
char * pPdu = NULL;
char pdu[MAX_MSGLEN] = { 0 };
UINT8 pos = 0;
UINT16 l;
int i;
UINT16 msgType = GetMessageType( );
UINT8 noIe = 2; // = NoIe( );
// Make up API header.
memcpy(pdu, Header, sizeof(SInterApiHead));
pos += sizeof(SInterApiHead);
// #### Add 2005-10-30, by Wujianjin. ###
// Construct the FIX information element first.
// UINT8 pt = GetProtocolType( );
// if ((MOD_TUPAPI == pt)
// || (MOD_ISUPAPI == pt)
// || (MOD_Q931API == pt))
// { // Construct the fix ie first.
// Message index.
CIeBase * pIe;
pIe = GetIE(PSG_IE_MSGTYPE);
if ((pIe != NULL)
&& (pIe->id != IE_NOT_EXIST))
{
pdu[pos++] = pIe->id;
pdu[pos++] = pIe->len;
memcpy(pdu+pos, pIe->GetIeData(l), pIe->len);
pos += pIe->len;
}
else
{ // Not exist, I will get it from mType.
pdu[pos++] = PSG_IE_MSGTYPE;
pdu[pos++] = 2;
// memcpy(pdu+pos, &mType, 2);
memcpy(pdu+pos, &msgType, 2);
pos += 2;
}
if (pIe != NULL)
{
DelIE(PSG_IE_MSGTYPE);
}
// Circuit structure.
pIe = GetIE(PSG_IE_CIR_STRUCT);
if ((pIe != NULL)
&& (pIe->id != IE_NOT_EXIST))
{
pdu[pos++] = pIe->id;
pdu[pos++] = pIe->len;
memcpy(pdu+pos, pIe->GetIeData(l), pIe->len);
pos += pIe->len;
}
else
{ // Exception handle.
// return pPdu;
pdu[pos ++] = PSG_IE_CIR_STRUCT;
pdu[pos ++] = sizeof(SCircuitStructIE);
SCircuitStructIE chn;
chn.pcmId = GetPcm( );
chn.tsId = GetTs( );
memcpy(pdu+pos, &chn, sizeof(SCircuitStructIE));
pos += sizeof(SCircuitStructIE);
}
if (pIe != NULL)
{
DelIE(PSG_IE_CIR_STRUCT);
}
// Circuit group indicator.
pIe = GetIE(PSG_IE_CG_IND);
if ((pIe != NULL)
&& (pIe->id != IE_NOT_EXIST))
{
pdu[pos++] = pIe->id;
pdu[pos++] = pIe->len;
memcpy(pdu+pos, pIe->GetIeData(l), pIe->len);
pos += pIe->len;
++ noIe;
}
if (pIe != NULL)
{
DelIE(PSG_IE_CG_IND);
}
// }
// ### End 2005-10-30 ###
// Make up all other IEs.
for (i=0; i<NoIe( ); ++i)
{
/*
if ((PSG_IE_L3_SGM == IE[i].id)
|| (PSG_IE_L3_SNDCMP == IE[i].id)
|| (PSG_IE_L3_MOREDATA == IE[i].id)
|| (PSG_IE_L3_CR == IE[i].id)
|| (PSG_IE_L3_PTLDCM == IE[i].id)
|| (PSG_IE_L3_CHNID == IE[i].id))
{
// noIe --;
continue;
}
*/
pdu[pos++] = IE[i].id;
pdu[pos++] = IE[i].len;
noIe ++;
if ((pos + IE[i].len) >= MAX_MSGLEN)
{ // Message too long.
printf("Joyit API too long. mType:0x%04X\n", msgType);
break;
}
memcpy(pdu+pos, IE[i].GetIeData(l), IE[i].len);
pos += IE[i].len;
}
// Allocate memory for this PDU.
// if (i == IeCounter)
// {
pPdu = new char[pos];
if (pPdu != NULL)
{
((SInterApiHead *)pdu)->primType = GetPrimitiveType( ); // Modify 2005-10-27, by Wujianjin.
((SInterApiHead *)pdu)->noie = noIe;;
// ((SJoyitApiHead *)pdu)->PktLength = pos;
memcpy(pPdu, pdu, pos);
len = pos;
}
else
{ // Out of memory.
printf("Make up Joyit API out of memory. mType:0x%04X\n", msgType);
}
// }
return pPdu;
}
// ========================================================================
unsigned short CIsupPdu::UnwrapCalledPartyNumber(unsigned char *src,unsigned short len,unsigned char *dst)
{
unsigned short ln;
SCCalledPartyNumber_H * pCd;
char oe;
memcpy(dst, src, sizeof(SCCalledPartyNumber_H)); // Copy the head.
pCd = (SCCalledPartyNumber_H *)dst; // src;
oe = pCd->oe; // Odd / Even.
dst += sizeof(SCCalledPartyNumber_H);
src += sizeof(SCCalledPartyNumber_H);
ln = sizeof(SCCalledPartyNumber_H);
// Extend the adress signals.
for (int i=sizeof(SCCalledPartyNumber_H); i<len; i++)
{
unsigned char digits;
digits = *src;
digits &= 0x0F; // Lower digit.
ln ++;
*dst ++ = digits;
digits = *src;
digits >>= 4; // Higher digit.
ln ++;
*dst ++ = digits;
src ++;
}
if (oe)
{ // If the address number is odd, then discard the last digits.
ln --;
}
return ln;
}
unsigned short CIsupPdu::UnwrapSubsequentNumber(unsigned char *src, unsigned short len, unsigned char *dst)
{
unsigned short ln;
SSubsequentNumber_H * pSn;
char oe;
memcpy(dst, src, sizeof(SSubsequentNumber_H)); // Copy the head.
pSn = (SSubsequentNumber_H *)dst; // src;
oe = pSn->oe; // Odd / Even.
dst += sizeof(SSubsequentNumber_H);
src += sizeof(SSubsequentNumber_H);
ln = sizeof(SSubsequentNumber_H);
// Extend the adress signals.
for (int i=sizeof(SSubsequentNumber_H); i<len; i++)
{
unsigned char digits;
digits = *src;
digits &= 0x0F; // Lower digit.
ln ++;
*dst ++ = digits;
digits = *src;
digits >>= 4; // Higher digit.
ln ++;
*dst ++ = digits;
src ++;
}
if (oe)
{ // If the address number is odd, then discard the last digits.
ln --;
}
return ln;
}
unsigned short CIsupPdu::UnwrapCallingPartyNumber(unsigned char *src,unsigned short len,unsigned char *dst)
{
unsigned short ln;
SECallingPartyNumber_H * pCg;
char oe;
memcpy(dst, src, sizeof(SECallingPartyNumber_H)); // Copy the head.
pCg = (SECallingPartyNumber_H *)dst; // src;
oe = pCg->oe; // Odd / Even.
dst += sizeof(SECallingPartyNumber_H);
src += sizeof(SECallingPartyNumber_H);
ln = sizeof(SECallingPartyNumber_H);
// Extend the adress signals.
for (int i=sizeof(SECallingPartyNumber_H); i<len; i++)
{
unsigned char digits;
digits = *src;
digits &= 0x0F; // Lower digit.
ln ++;
*dst ++ = digits;
digits = *src;
digits >>= 4; // Higher digit.
ln ++;
*dst ++ = digits;
src ++;
}
if (oe)
{ // If the address number is odd, then discard the last digits.
ln --;
}
if (*(--dst) == 0x0F) // If the last digit is stop digit.
{
ln --;
// dst --;
pCg->oe = (oe) ? 0 : 1;
}
return ln;
}
unsigned short CIsupPdu::UnwrapGenericNumber(unsigned char *src, unsigned short len, unsigned char *dst)
{
unsigned short ln;
SCGenericNumber_H* pGn;
char oe;
memcpy(dst, src, sizeof(SCGenericNumber_H)); // Copy the head.
pGn = (SCGenericNumber_H *)dst; // src;
oe = pGn->oe; // Odd / Even.
dst += sizeof(SCGenericNumber_H);
src += sizeof(SCGenericNumber_H);
ln = sizeof(SCGenericNumber_H);
// Extend the adress signals.
for (int i=sizeof(SCGenericNumber_H); i<len; i++)
{
unsigned char digits;
digits = *src;
digits &= 0x0F; // Lower digit.
ln ++;
*dst ++ = digits;
digits = *src;
digits >>= 4; // Higher digit.
ln ++;
*dst ++ = digits;
src ++;
}
if (oe)
{ // If the address number is odd, then discard the last digits.
ln --;
}
return ln;
}
unsigned short CIsupPdu::UnwrapOthersNumber(unsigned char *src, unsigned short len, unsigned char *dst)
{
return UnwrapCalledPartyNumber(src, len, dst);
}
// ============================================================================
unsigned short CIsupPdu::WrapCalledPartyNumber(unsigned char *src, unsigned short len, unsigned char *dst)
{
SCCalledPartyNumber_H * pCd;
unsigned short ln;
memcpy(dst, src, sizeof(SCCalledPartyNumber_H));
pCd = (SCCalledPartyNumber_H *)dst; // src;
dst += sizeof(SCCalledPartyNumber_H);
src += sizeof(SCCalledPartyNumber_H);
ln = sizeof(SCCalledPartyNumber_H);
for (int i=sizeof(SCCalledPartyNumber_H); i<len; i += 2)
{
unsigned char digit;
digit = *src++;
*dst = (digit & 0x0F);
digit = *src++;
*dst |= (digit << 4);
dst ++;
ln ++;
}
pCd->oe = (len-sizeof(SCCalledPartyNumber_H)) % 2;
if (pCd->oe)
{ // Odd
dst --;
(*dst) &= 0x0F; // Set the last digit as filler.
}
return ln;
}
unsigned short CIsupPdu::WrapSubsequentNumber(unsigned char *src, unsigned short len, unsigned char *dst)
{
SSubsequentNumber_H * pSn;
unsigned short ln;
memcpy(dst, src, sizeof(SSubsequentNumber_H));
pSn = (SSubsequentNumber_H *)dst; // src;
dst += sizeof(SSubsequentNumber_H);
src += sizeof(SSubsequentNumber_H);
ln = sizeof(SSubsequentNumber_H);
for (int i=sizeof(SSubsequentNumber_H); i<len; i += 2)
{
unsigned char digit;
digit = *src++;
*dst = (digit & 0x0F);
digit = *src++;
*dst |= (digit << 4);
dst ++;
ln ++;
}
pSn->oe = (len-sizeof(SSubsequentNumber_H)) % 2;
if (pSn->oe)
{ // Odd
dst --;
(*dst) &= 0x0F; // Set the last digit as filler.
}
return ln;
}
unsigned short CIsupPdu::WrapCallingPartyNumber(unsigned char *src,unsigned short len,unsigned char *dst)
{
SCCalledPartyNumber_H * pCg;
unsigned short ln;
memcpy(dst, src, sizeof(SCCallingPartyNumber_H));
pCg = (SCCalledPartyNumber_H *)dst; // src;
dst += sizeof(SCCallingPartyNumber_H);
src += sizeof(SCCallingPartyNumber_H);
ln = sizeof(SCCallingPartyNumber_H);
for (int i=sizeof(SCCallingPartyNumber_H); i<len; i += 2)
{
unsigned char digit;
digit = *src++;
*dst = (digit & 0x0F);
digit = *src++;
*dst |= (digit << 4);
dst ++;
ln ++;
}
if (*(-- src) != 0x0F)
{ // If PDK/HOST are not add the stop digits then ISUP will add it.
pCg->oe = (len-sizeof(SCCallingPartyNumber_H)) % 2;
if (pCg->oe)
{
dst --;
(*dst) |= 0xF0;
pCg->oe = OE_EVEN;
dst ++;
}
else
{
ln++;
(*dst) = 0x0F;
pCg->oe = OE_ODD;
dst ++;
}
}
if (pCg->oe)
{ // Odd
dst --;
(*dst) &= 0x0F; // Set the last digit as filler.
}
return ln;
}
unsigned short CIsupPdu::WrapGenericNumber(unsigned char *src, unsigned short len, unsigned char *dst)
{
SCGenericNumber_H * pGn;
unsigned short ln;
memcpy(dst, src, sizeof(SCGenericNumber_H));
pGn = (SCGenericNumber_H *)dst; // src;
dst += sizeof(SCGenericNumber_H);
src += sizeof(SCGenericNumber_H);
ln = sizeof(SCGenericNumber_H);
for (int i=sizeof(SCGenericNumber_H); i<len; i += 2)
{
unsigned char digit;
digit = *src++;
*dst = digit & 0x0F;
digit = *src++;
*dst |= digit << 4;
dst ++;
ln ++;
}
pGn->oe = (len - sizeof(SCGenericNumber_H)) % 2;
if (pGn->oe)
{ // Odd
dst --;
(*dst) &= 0x0F; // Set the last digit as filler.
}
return ln;
}
unsigned short CIsupPdu::WrapOthersNumber(unsigned char *src, unsigned short len, unsigned char *dst)
{
return WrapCalledPartyNumber(src, len, dst);
}
UINT16 CIsupPdu::WhatPrimitive(UINT16 mType, UINT8 ri) // Input Joyit API message type, return what Joyit API primitive type belong to.
{ // ri = 0 Indication; ri = 1; Request.
UINT16 pType;
switch (mType)
{
case PSG_MSG_ISUP_IAM:
pType = (ri) ? PSG_CC_SETUP_REQ : PSG_CC_SETUP_IND;
break;
case PSG_MSG_ISUP_ACM:
pType = (ri) ? PSG_CC_AC_REQ : PSG_CC_AC_IND;
break;
case PSG_MSG_ISUP_ANM:
case PSG_MSG_ISUP_CON:
pType = (ri) ? PSG_CC_ANSWER_REQ : PSG_CC_ANSWER_IND;
break;
case PSG_MSG_ISUP_REL:
pType = (ri) ? PSG_CC_RELEASE_REQ : PSG_CC_RELEASE_IND;
break;
case PSG_MSG_ISUP_RLC:
if (rlcType)
{
pType = (ri) ? PSG_CC_CIRCUIT_REQ : PSG_CC_CIRCUIT_IND;
}
else
{
pType = (ri) ? PSG_CC_RELEASE_REQ : PSG_CC_RELEASE_IND;
}
break;
case PSG_MSG_ISUP_BLO:
case PSG_MSG_ISUP_GRS:
case PSG_MSG_ISUP_GRA:
case PSG_MSG_ISUP_CGU:
case PSG_MSG_ISUP_CGB:
case PSG_MSG_ISUP_CGUA:
case PSG_MSG_ISUP_CGBA:
case PSG_MSG_ISUP_BLA:
case PSG_MSG_ISUP_HBLO:
case PSG_MSG_ISUP_HBLA:
case PSG_MSG_ISUP_UBL:
case PSG_MSG_ISUP_HUBL:
case PSG_MSG_ISUP_UBA:
case PSG_MSG_ISUP_HUBA:
case PSG_MSG_ISUP_RSC:
pType = (ri) ? PSG_CC_CIRCUIT_REQ : PSG_CC_CIRCUIT_IND;
break;
default:
pType = (ri) ? PSG_CC_EVENT_REQ : PSG_CC_EVENT_IND;
} // End of switch(mType)
SetPrimitiveType(pType);
return pType;
}
// ------------------------------------------------------------------------
//
// Revision list.
// ==============
//
// 1.0, 2005-08-20, Wu jianjin
// Initial version.
//
// ------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -