q931ptl.cpp
来自「ABis无线接口全套资料」· C++ 代码 · 共 1,320 行 · 第 1/3 页
CPP
1,320 行
case Q931_IE_SHIFT:
case Q931_IE_CNGL:
case Q931_IE_RPTIND: // Modify 2005-10-31, by Wujianjin.
// pdu[pos] = (pdu[pos] << 4 | IE[i].data);
pdu[pos] |= (IE[i].data & 0x0F);
pos++;
break;
case Q931_IE_SNDCMP:
case Q931_IE_MOREDATA:
pos++;
break;
case Q931_IE_CLDPRTNUM: // Convert numberic digit to IA5.
case Q931_IE_CLNPRTNUM: // Convert numberic digit to IA5.
case Q931_IE_RN: // Convert numberic digit to IA5.
if (Q931_IE_CLDPRTNUM == (UINT8)pdu[pos])
{
char * pData = IE[i].GetIeData(l);
for (int k=1; k<IE[i].len; ++k)
{
if (11 == pData[k]) // *
{
pData[k] = '*';
}
else if (12 == pData[k]) // #
{
pData[k] = '#';
}
else
{
pData[k] += '0';
}
}
}
else if (Q931_IE_CLNPRTNUM == (UINT8)pdu[pos])
{
char * pData = IE[i].GetIeData(l);
int k = (pData[0] & 0x80) ? 1 : 2;
for (; k<IE[i].len; ++k)
{
if (11 == pData[k]) // *
{
pData[k] = '*';
}
else if (12 == pData[k]) // #
{
pData[k] = '#';
}
else
{
pData[k] += '0';
}
}
}
else if (Q931_IE_RN == (UINT8)pdu[pos])
{ // ?????
char * pData = IE[i].GetIeData(l);
int k=0;
while (! (pData[k] & 0x80))
{
k++;
}
for (k+=1; k<IE[i].len; ++k)
{
if (11 == pData[k]) // *
{
pData[k] = '*';
}
else if (12 == pData[k]) // #
{
pData[k] = '#';
}
else
{
pData[k] += '0';
}
}
}
default:
pos++;
pdu[pos++] = IE[i].len;
memcpy(pdu+pos, IE[i].GetIeData(l), IE[i].len);
pos += IE[i].len;
}
if ((pos + IE[i].len) >= MAX_MSGLEN)
{ // Message too long.
printf("Q931 Msg too long. mType:0x%04X\n", mt);
break;
}
};
*/
// Allocate memory for this PDU.
// if (i == noie)
// {
pPdu = new unsigned char[pos];
if (pPdu != NULL)
{
((SQ931MsgHead *)pdu)->msgType = mt;
memcpy(pPdu, pdu, pos);
len = pos;
}
else
{ // Out of memory.
printf("Make up Q931 Msg out of memory. mType:0x%04X\n", mt);
}
// }
}
delete pdu; // Add 2005-12-06, by Wujianjin. Release the memory that has been allocated at entry point.
return (char *)pPdu;
}
UINT16 CQ931Pdu::WhatPrimitive(UINT16 mType, UINT8 ir)
{
UINT16 pType;
switch (mType)
{
case PSG_MSG_Q931_SETUP:
pType = (ir) ? PSG_CC_SETUP_REQ : PSG_CC_SETUP_IND;
break;
case PSG_MSG_Q931_ALERTING:
pType = (ir) ? PSG_CC_AC_REQ : PSG_CC_AC_IND;
break;
case PSG_MSG_Q931_CONNECT:
pType = (ir) ? PSG_CC_ANSWER_REQ : PSG_CC_ANSWER_IND;
break;
case PSG_MSG_Q931_DISCONNECT:
case PSG_MSG_Q931_RELEASE:
pType = (ir) ? PSG_CC_RELEASE_REQ : PSG_CC_RELEASE_IND;
break;
case PSG_MSG_Q931_RELEASE_COM:
pType = PSG_CC_RELEASE_IND;
break;
case PSG_MSG_Q931_RESTART:
// case PSG_MSG_Q931_FAIL:
pType = (ir) ? PSG_CC_CIRCUIT_REQ : PSG_CC_CIRCUIT_IND;
break;
default:
pType = (ir) ? PSG_CC_EVENT_REQ : PSG_CC_EVENT_IND;
} // End of switch(mType)
SetPrimitiveType(pType);
return pType;
}
UINT8 CQ931Pdu::GetCallFlag( )
{ // Only useable in Q931 PDU after unpacked the PDU.
UINT8 cf = 0;
if (lengthOfCallReference > 0)
{
cf = ((SQ931MsgHead *)Header)->flag1;
}
return cf;
}
UINT16 CQ931Pdu::GetCallReference( )
{ // Only useable in Q931 PDU after unpacked the PDU.
UINT16 cr = 0;
switch (lengthOfCallReference)
{
case 0:
break;
case 1:
cr = ((SQ931MsgHead_CR2 *)Header)->crv1;
break;
case 2:
cr = (((SQ931MsgHead_CR3 *)Header)->crv2 << 7) | (((SQ931MsgHead_CR3 *)Header)->crv1);
break;
/*
case 3: // ?????
break;
*/
default:
break;
} // End of switch (lengthOfCallReference)
return cr;
}
char * CQ931Pdu::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 = GetPri( );
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) // Delete 2005-11-21, by Wujianjin.
|| (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;
}
/*
void CQ931Pdu::SortIeAscending( )
{
unsigned char q931Ie[MAX_IE];
unsigned char isRepeat[MAX_IE];
unsigned char noExistIe[MAX_IE];
unsigned char totalIe, totalNei;
unsigned char i;
totalIe = NoIe( );
totalNei = 0;
memset(q931Ie, 0xFF, MAX_IE*sizeof(unsigned char));
memset(isRepeat, 0, MAX_IE*sizeof(unsigned char));
for (i=0; i<totalIe; ++i)
{
unsigned char id = ToQ931Ie(IE[i].id);
if (IE_NOT_EXIST == id)
{
noExistIe[totalNei++] = i; // IE[i].id;
}
else
{
if (0xFF == q931Ie[id])
{
q931Ie[id] = i;
}
else
{ // It is repeat IE.
isRepeat[id] ++; // Calculate the repeat times.
}
}
}
// Re-range all IE.
CIeBase TempIE[MAX_IE];
unsigned char tCnt;
tCnt = 0;
for (i=0; i<MAX_IE; ++i)
{
if (q931Ie[i] != 0xFF)
{
memcpy(&TempIE[tCnt++], &IE[q931Ie[i]], sizeof(CIeBase));
// Copy the repeat IE.
for (char k=0; k<isRepeat[i]; ++k)
{
UINT8 index;
index = GetIEindex(IE[q931Ie[i]].id, k);
if (index != IE_NOT_EXIST)
{
memcpy(&TempIE[tCnt++], &IE[index], sizeof(CIeBase));
}
}
}
}
for (i=0; i<totalNei; i++)
{
memcpy(&TempIE[tCnt++], &IE[noExistIe[i]], sizeof(CIeBase));
}
if (tCnt != totalIe)
{ // Exception handle.
Print("PDU construct error in IE sort ascending. mType: %d", GetMessageType( ));
}
// memcpy(&IE, &TempIE, sizeof(CIeBase)*tCnt);
for (i=0; i<tCnt; ++i)
{
memcpy(&IE[i], &TempIE[i], sizeof(CIeBase));
}
// Re-assign Ieid2Index
ReconstructIndex( );
}
*/
// ------------------------------------------------------------------------
//
// Revision list.
// ==============
//
// 1.0, 2005-09-19, Zhu Minyu
// Initial version.
// 1.1, 2005-10-26, Wu jianjin.
// Add Inter API message compose and decompose function.
// ------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?