📄 q931pdu.cpp
字号:
"Unknown", "International number", "National number", "Network specific number", "Subscriber number", "Reserved", "Abbreviated number", "Reserved for extension" }; int i = Byte[0]&0x70; i >>= 4; char buf[80]; int typeOfNumber = Byte[0]&0x70; FormatBits(buf, 6,4, typeOfNumber); wsprintf(buf+8," = Type of number - %s", str[typeOfNumber >> 4]); AttachPropertyInstanceEx(hFrame, hProperty, 1 , (void*)Byte, strlen(buf)+1 , buf , 0, 2, 0 );}TableEntry numberingPlanTable[] = { {0x00,"Unknown"}, {0x01,"ISDN/telephony numbering plan (Recommendation E.164)"}, {0x03,"Data numbering plan (Recommendation X.121)"}, {0x04,"Telex numbering plan (Recommendation F.69)"}, {0x08,"National standard numbering plan"}, {0x09,"Private numbering plan"}};void AttachPartyNumber_NumberingPlanIndication( HFRAME hFrame, HPROPERTY hProperty, const unsigned char* Byte ){ char buf[120]; int numberingPlan = Byte[0]& 0x0F; FormatBits(buf, 3 , 0, numberingPlan); wsprintf(buf+8, " = Numbering plan indication - %s", FindString(numberingPlan)); AttachPropertyInstanceEx(hFrame, hProperty, 1 , (void*)Byte, strlen(buf)+1 , buf , 0, 2, 0 );}voidAttachPartyNumber_PresentationIndicator( HFRAME hFrame, HPROPERTY hProperty, const unsigned char* Byte ){ char buf[100]; const char* presentationStr[] = { "Presentation allowed", "Presentation restricted", "Number not available due to interworking", "Reserved" }; wsprintf(buf, ".%d%d..... = Presentation Indicator - %s", (Byte[0] & 0x40) > 1 , (Byte[0] & 0x20) > 1, presentationStr[(Byte[0] & 0x60) >> 5]); AttachPropertyInstanceEx(hFrame, hProperty, 1 ,(void*)Byte, strlen(buf)+1 , buf , 0, 2, 0 );}voidAttachPartyNumber_ScreeningIndicator( HFRAME hFrame, HPROPERTY hProperty, const unsigned char* Byte ){ char buf[100]; const char* ScreeningStr[] = { "User-provided, not screened", "User-provided, verified and passed", "User-provided, verified and failed", "Network provided" }; wsprintf(buf, "......%d%d = Screening Indicator - %s", (Byte[0] & 0x02) > 1 , (Byte[0] & 0x01) , ScreeningStr[Byte[0] & 0x03 ]); AttachPropertyInstanceEx(hFrame, hProperty, 1 ,(void*)Byte, strlen(buf)+1 , buf , 0, 2, 0 );}void AttachNumberDigits(HFRAME hFrame, HPROPERTY hProperty, const unsigned char* Byte, int length){ char buf[100]; int size; strcpy(buf,"Number Digits = \""); size = strlen(buf); memcpy(buf+size, Byte, length ); size += length ; buf[size++] = '"'; buf[size] = 0; AttachPropertyInstanceEx(hFrame, hProperty, length , (void*)Byte, strlen(buf)+1 , buf , 0, 2, 0 );}voidAttachPartyNumber( HFRAME hFrame, HPROPERTY hProperty, const unsigned char* Byte ){ AttachExtensionIndicator(hFrame, hProperty, Byte+2, BOTH); AttachPartyNumber_TypeOfNumber(hFrame, hProperty, Byte+2); AttachPartyNumber_NumberingPlanIndication(hFrame, hProperty, Byte+2); int offset = 3; if( (Byte[2] & 0x80) == 0) { offset++; AttachExtensionIndicator(hFrame, hProperty, Byte+3, FORCE_1); AttachPartyNumber_PresentationIndicator(hFrame, hProperty, Byte+3); AttachPartyNumber_ScreeningIndicator(hFrame, hProperty, Byte+3); } AttachNumberDigits(hFrame, hProperty, Byte + offset, Byte[1] - offset +2);}void CalledPartyNumberInformationElement::attachContent(HFRAME hFrame, HPROPERTY hProperty) const{ AttachPartyNumber(hFrame, hProperty, data);}void CallingPartyNumberInformationElement::attachContent(HFRAME hFrame, HPROPERTY hProperty) const{ AttachPartyNumber(hFrame, hProperty, data);}void ConnectedPartyNumberInformationElement::attachContent(HFRAME hFrame, HPROPERTY hProperty) const{ AttachPartyNumber(hFrame, hProperty, data);}void ProgressInformationElement::attachContent(HFRAME hFrame, HPROPERTY hProperty) const{ AttachExtensionIndicator(hFrame, hProperty, data+2, FORCE_1); AttachCodingStandard(hFrame, hProperty, data+2); AttachLocation(hFrame, hProperty, data+2); AttachExtensionIndicator(hFrame, hProperty, data+3, FORCE_1); const char* str[] = { "", "Call is not end-to-end ISDN; further call progress information may be available in?band", "Destination address is non ISDN", "Origination address is non ISDN", "Call has returned to the ISDN", "Interworking has occurred and has resulted in a telecommunication service change", "", "", "In-band information or an appropriate pattern is now available" }; char buf [120]; const char* description = ""; if ((data[3] & 0x80) < 8) description = str[data[3] & 0x80]; wsprintf(buf, "Progress description = 0x%02x %s",description); AttachPropertyInstanceEx(hFrame, hProperty, 1 ,(void*) (data+3), strlen(buf)+1 , buf , 0, 2, 0 );}TableEntry informationTransferCapabilityTable[] ={ {0x01,"Speech"}, {0x08,"Unrestricted digital information"}, {0x09,"Restricted digital information"}, {0x10,"3.1 kHz audio"}, {0x11,"Unrestricted digital information with tones/announcements"}, {0x18,"Video"},};TableEntry transferRateTable[] = { {0x00,"This code shall be used for packet mode calls"}, {0x10,"64 kbit/s"}, {0x11,"2 * 64 kbit/s"}, {0x13,"384 kbit/s"}, {0x15,"1536 kbit/s"}, {0x17,"1920 kbit/s"}, {0x18,"Multirate (64 kbit/s base rate)"}};TableEntry userInformationLayer1ProtocolTable[] = { {0x01,"CCITT standardized rate adaption V.110 and X.30"}, {0x02,"Recommendation G.711 U-law"}, {0x03,"Recommendation G.711 A-law"}, {0x04,"Recommendation G.721 32 kbit/s ADPCM and Recommendation I.460"}, {0x05,"Recommendations H.221 and H.242"}, {0x07,"Non-CCITT standardized rate adaption."}, {0x08,"CCITT standardized rate adaption V.120"}, {0x09,"CCITT standardized rate adaption X.31 HDLC flag stuffing"}};void BearerCapabilityInformationElement::attachContent(HFRAME hFrame, HPROPERTY hProperty) const{ int len = data[1]; const unsigned char* cur = data+2; AttachExtensionIndicator(hFrame, hProperty, cur, FORCE_1); AttachCodingStandard(hFrame, hProperty, cur); int informationTransferCapability = (*cur) & 0x1f; char buf[150]; FormatBits(buf, 4, 0, informationTransferCapability); wsprintf(buf+8, " = Information transfer capability (0x%02x) - %s" , informationTransferCapability , FindString(informationTransferCapability)); AttachPropertyInstanceEx(hFrame, hProperty, 1 ,(void*) cur, strlen(buf)+1 , buf , 0, 2, 0 ); AttachExtensionIndicator(hFrame, hProperty, ++cur, FORCE_1); const char* transferModeStr[] = {"Circuit mode", "Error" ,"Packet mode", "Error"}; int transferMode = (*cur) & 0x60 ; FormatBits(buf, 6,5, transferMode); wsprintf(buf+8, " = %s", transferModeStr[transferMode >> 5]); AttachPropertyInstanceEx(hFrame, hProperty, 1 ,(void*) cur, strlen(buf)+1 , buf , 0, 2, 0 ); static const char* transferRateStr = "Reserved"; int transferRate = (*cur) & 0x1F; FormatBits(buf, 4, 0, transferRate); wsprintf(buf+8, " = Transfer Rate - %s", FindString(transferRate)); AttachPropertyInstanceEx(hFrame, hProperty, 1 ,(void*) cur, strlen(buf)+1 , buf , 0, 2, 0 ); if (transferRate == 0x18) // multirate, octet 4.1* shall be present { AttachExtensionIndicator(hFrame, hProperty, ++cur, FORCE_1); int rateMultiplier = (*cur) & 0x7F; FormatBits(buf, 6, 0, rateMultiplier); wsprintf(buf+8, " = Rate Multiplier - %d", rateMultiplier); AttachPropertyInstanceEx(hFrame, hProperty, 1 ,(void*) cur, strlen(buf)+1 , buf , 0, 2, 0 ); } if (cur - data <= len) // octet 5* present { AttachExtensionIndicator(hFrame, hProperty, ++cur, BOTH); int layer1ID = (*cur) & 0x60; FormatBits(buf, 6, 5, layer1ID); wsprintf(buf+8, " = Layer 1 Identifer - shall be 01"); AttachPropertyInstanceEx(hFrame, hProperty, 1 ,(void*) cur, strlen(buf)+1 , buf , 0, 2, 0 ); const char* userInformationLayer1ProtocolStr = "Reserved"; int userInformationLayer1Protocol = (*cur) & 0x1F; FormatBits(buf, 4, 0, userInformationLayer1Protocol); wsprintf(buf+8, " = %s", FindString(userInformationLayer1Protocol)); AttachPropertyInstanceEx(hFrame, hProperty, 1 ,(void*) cur, strlen(buf)+1 , buf , 0, 2, 0 ); }}TableEntry callStateTable[] = { {0x00,"Null"}, {0x01,"Call initiated"}, {0x02,"Overlap sending"}, {0x03,"Outgoing call proceeding"}, {0x04,"Call delivered"}, {0x06,"Call present"}, {0x07,"Call received"}, {0x08,"Connect request"}, {0x09,"Incoming call proceeding"}, {0x10,"Active"}, {0x11,"Disconnect request"}, {0x12,"Disconnect indication"}, {0x15,"Suspend request"}, {0x17,"Resume request"}, {0x19,"Release request"}, {0x22,"Call abort"}, {0x25,"Overlap receiving"}, {0x3D,"Restart request"}, {0x3E,"Restart"}};void CallStateInformationElement::attachContent(HFRAME hFrame, HPROPERTY hProperty) const{ AttachCodingStandard(hFrame, hProperty, data+2, 7); const char* callStateStr = "Undefined"; int callState = data[2] & 0x3F; char buf[100]; FormatBits(buf, 6, 0, callState); wsprintf(buf+8, " = Call State - %s", FindString(callState)); AttachPropertyInstanceEx(hFrame, hProperty, 1 ,(void*) (data+2), strlen(buf)+1 , buf , 0, 2, 0 );}void SignalInformationElement::attachContent(HFRAME hFrame, HPROPERTY hProperty) const{ static const char* SignalStrTable[] = { "Dial tone on", "Ring back tone on", "Intercept tone on", "Network congestion tone on", "Busy tone on", "Confirm tone on", "Answer tone on", "Call waiting tone", "Off-hook warning tone", "Preemption tone on" }; char signalStrBuf[30]; const char* signalStr = "Reserved"; int signalValue = data[2]; if ( signalValue < 10) signalStr = SignalStrTable[signalValue]; else if (signalValue == 0x3F) signalStr = "Tones off"; else if ((signalValue & 0xF8) == 0x60) { wsprintf(signalStrBuf, "Alerting on - pattern %d", signalValue & 0x07); signalStr = signalStrBuf; } else if (signalValue == 0x4F) signalStr = "Alerting off"; char buf[80]; wsprintf(buf,"Signal Value = %d (%s)", signalValue, signalStr); AttachPropertyInstanceEx(hFrame, hProperty, 1 ,(void*) (data+2), strlen(buf)+1 , buf , 0, 2, 0 );}Q931PDU::Q931PDU(){}Q931PDU::~Q931PDU(){}bool Q931PDU::accept(Q931Decoder& strm) { data = strm.data; if (strm.size < 5) return FALSE; if (data[0] != 0x08 || data[1] != 0x02) return FALSE; if (getMessageTypeName() == NULL) return FALSE; strm.offset = 5; while (true) { InformationElement* element = InformationElement::Build(strm); if (element != NULL) { ieList.push_back(element); if (strcmp(element->getName(), "User-User") == 0) { UserUserInformationElement* uuie = static_cast<UserUserInformationElement*>(element); if (uuie->decodeIE()) break; else return FALSE; } } else break; } return strm.size >= (len = strm.offset);}void Q931PDU::attachProperties(HFRAME hFrame, HPROPERTY hProperty){ char buf[80]; wsprintf(buf,"Q.931 %s (Length = %d)", getMessageTypeName(), len); AttachPropertyInstanceEx(hFrame, hProperty, len , (void*)data, strlen(buf) + 1, buf , 0, 0, 0); AttachPropertyInstanceEx(hFrame, hProperty, 5, (void*)data, 19, "Fixed Q.931 Header", 0, 1, 0); char* discriminatorStr = "Protocol Discriminator = 0x08"; AttachPropertyInstanceEx(hFrame, hProperty, 1, (void*)data, strlen(discriminatorStr)+1, discriminatorStr, 0, 2, 0); AttachPropertyInstanceEx(hFrame, hProperty, 3,(void*)(data+1), 15, "Call Reference", 0, 2, 0); AttachPropertyInstanceEx(hFrame, hProperty, 1,(void*) (data+1), 26, "Call Reference Length = 2", 0, 3, 0); if (data[2] & 0x80) AttachPropertyInstanceEx(hFrame, hProperty, 1, (void*) (data+2), 28, "1....... = Destination Side", 0, 3, 0); else AttachPropertyInstanceEx(hFrame, hProperty, 1,(void*) (data+2), 28, "0....... = Originating Side", 0, 3, 0); FormatBits(buf, 6,0, data[2]); buf[8] = ' '; FormatBits(buf+9, 7, 0, data[3]); wsprintf(buf+17, " = Call Reference Value - 0x%04x", (data[2] & 0x7F) << 8 | data[3] ); AttachPropertyInstanceEx(hFrame, hProperty, 2, (void*)(data+2), strlen(buf)+1, buf, 0, 3, 0); wsprintf(buf, "Message Type = 0x%02x (%s)", data[4], getMessageTypeName()); AttachPropertyInstanceEx(hFrame, hProperty, 2, (void*)(data+4), strlen(buf)+1, buf, 0, 3, 0); IEList::iterator b = ieList.begin(), e = ieList.end(); for ( ; b!= e; ++b) { InformationElement* element = *b; element->attachProperties(hFrame, hProperty); }}TableEntry msgTable[] = { {0x00,"Escape"}, {0x01,"Alerting"}, {0x02,"CallProceeding"}, {0x03,"Progress"}, {0x05,"Setup"}, {0x07,"Connect"}, {0x0d,"SetupAck"}, {0x0f,"ConnectAck"}, {0x5a,"ReleaseComplete"}, {0x62,"Facility"}, {0x75,"StatusEnquiry"}, {0x7b,"Information"}, {0x7d,"Status"}};const char* Q931PDU::getMessageTypeName() const{ int msg = data[4]; return FindString(msg);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -