public int createAssociateRequestMessage(IsoConnectionParameters isoParameters, byte[] buffer, int bufIndex, byte[] payload, int payloadLength) { int authValueLength; int authValueStringLength = 0; int passwordLength = 0; int contentLength = 0; /* application context name */ contentLength += 9; int calledAEQualifierLength = 0; if (isoParameters.remoteApTitleLen > 0) { /* called AP title */ contentLength += (4 + isoParameters.remoteApTitleLen); calledAEQualifierLength = IsoUtil.BerEncoder_UInt32determineEncodedSize((uint)isoParameters.remoteAEQualifier); /* called AP qualifier */ contentLength += (4 + calledAEQualifierLength); // Добавки Несговорова contentLength += 5; contentLength += 5; } int callingAEQualifierLength = 0; if (isoParameters.localApTitleLen > 0) { /* calling AP title */ contentLength += (4 + isoParameters.localApTitleLen); callingAEQualifierLength = IsoUtil.BerEncoder_UInt32determineEncodedSize((uint)isoParameters.localAEQualifier); /* calling AP qualifier */ contentLength += (4 + callingAEQualifierLength); // Добавки Несговорова contentLength += 5; contentLength += 5; } if (isoParameters.acseAuthParameter != null) { /* sender ACSE requirements */ contentLength += 4; /* mechanism name */ contentLength += 5; /* authentication value */ if (isoParameters.acseAuthParameter.mechanism == AcseAuthenticationMechanism.ACSE_AUTH_PASSWORD) { contentLength += 2; //if (authParameter.value.password.passwordLength == 0) passwordLength = isoParameters.acseAuthParameter.passwordLength; authValueStringLength = IsoUtil.BerEncoder_determineLengthSize((uint)passwordLength); contentLength += passwordLength + authValueStringLength; authValueLength = IsoUtil.BerEncoder_determineLengthSize((uint)(passwordLength + authValueStringLength + 1)); contentLength += authValueLength; } else { contentLength += 2; } } /* user information */ int userInfoLength = 0; /* single ASN1 type tag */ userInfoLength += payloadLength; userInfoLength += 1; userInfoLength += IsoUtil.BerEncoder_determineLengthSize((uint)payloadLength); // Добавки Несговорова userInfoLength += 2; userInfoLength += 2; /* indirect reference */ userInfoLength += 1; userInfoLength += 2; /* association data */ int assocDataLength = userInfoLength; userInfoLength += IsoUtil.BerEncoder_determineLengthSize((uint)assocDataLength); userInfoLength += 1; /* user information */ int userInfoLen = userInfoLength; userInfoLength += IsoUtil.BerEncoder_determineLengthSize((uint)userInfoLength); userInfoLength += 1; contentLength += userInfoLength; int bufPos = 0; bufPos = IsoUtil.BerEncoder_encodeTL(0x60, (uint)contentLength, buffer, bufPos); /* application context name */ bufPos = IsoUtil.BerEncoder_encodeTL(0xa1, 7, buffer, bufPos); bufPos = IsoUtil.BerEncoder_encodeTL(0x06, 5, buffer, bufPos); //memcpy(buffer + bufPos, appContextNameMms, 5); appContextNameMms.CopyTo(buffer, bufPos); bufPos += 5; if (isoParameters.remoteApTitleLen > 0) { /* called AP title */ bufPos = IsoUtil.BerEncoder_encodeTL(0xa2, (uint)isoParameters.remoteApTitleLen + 2, buffer, bufPos); bufPos = IsoUtil.BerEncoder_encodeTL(0x06, (uint)isoParameters.remoteApTitleLen, buffer, bufPos); //memcpy(buffer + bufPos, isoParameters.remoteApTitle, isoParameters.remoteApTitleLen); isoParameters.remoteApTitle.CopyTo(buffer, bufPos); bufPos += isoParameters.remoteApTitleLen; /* called AE qualifier */ bufPos = IsoUtil.BerEncoder_encodeTL(0xa3, (uint)calledAEQualifierLength + 2, buffer, bufPos); bufPos = IsoUtil.BerEncoder_encodeTL(0x02, (uint)calledAEQualifierLength, buffer, bufPos); bufPos = IsoUtil.BerEncoder_encodeUInt32((uint)isoParameters.remoteAEQualifier, buffer, bufPos); } if (isoParameters.localApTitleLen > 0) { /* calling AP title */ bufPos = IsoUtil.BerEncoder_encodeTL(0xa6, (uint)isoParameters.localApTitleLen + 2, buffer, bufPos); bufPos = IsoUtil.BerEncoder_encodeTL(0x06, (uint)isoParameters.localApTitleLen, buffer, bufPos); //memcpy(buffer + bufPos, isoParameters.localApTitle, isoParameters.localApTitleLen); isoParameters.localApTitle.CopyTo(buffer, bufPos); bufPos += isoParameters.localApTitleLen; /* calling AE qualifier */ bufPos = IsoUtil.BerEncoder_encodeTL(0xa7, (uint)callingAEQualifierLength + 2, buffer, bufPos); bufPos = IsoUtil.BerEncoder_encodeTL(0x02, (uint)callingAEQualifierLength, buffer, bufPos); bufPos = IsoUtil.BerEncoder_encodeUInt32((uint)isoParameters.localAEQualifier, buffer, bufPos); // Добавки Несговорова bufPos = IsoUtil.BerEncoder_encodeTL(0xa4, (uint)calledAEQualifierLength + 2, buffer, bufPos); bufPos = IsoUtil.BerEncoder_encodeTL(0x02, (uint)calledAEQualifierLength, buffer, bufPos); bufPos = IsoUtil.BerEncoder_encodeUInt32(0, buffer, bufPos); bufPos = IsoUtil.BerEncoder_encodeTL(0xa5, (uint)calledAEQualifierLength + 2, buffer, bufPos); bufPos = IsoUtil.BerEncoder_encodeTL(0x02, (uint)calledAEQualifierLength, buffer, bufPos); bufPos = IsoUtil.BerEncoder_encodeUInt32(0, buffer, bufPos); } if (isoParameters.acseAuthParameter != null) { /* sender requirements */ bufPos = IsoUtil.BerEncoder_encodeTL(0x8a, 2, buffer, bufPos); buffer[bufPos++] = 0x04; if (isoParameters.acseAuthParameter.mechanism == AcseAuthenticationMechanism.ACSE_AUTH_PASSWORD) { buffer[bufPos++] = requirements_authentication[0]; bufPos = IsoUtil.BerEncoder_encodeTL(0x8b, 3, buffer, bufPos); //memcpy(buffer + bufPos, auth_mech_password_oid, 3); auth_mech_password_oid.CopyTo(buffer, bufPos); bufPos += 3; /* authentication value */ bufPos = IsoUtil.BerEncoder_encodeTL(0xac, (uint)(authValueStringLength + passwordLength + 1), buffer, bufPos); bufPos = IsoUtil.BerEncoder_encodeTL(0x80, (uint)passwordLength, buffer, bufPos); //memcpy(buffer + bufPos, authParameter.paswordOctetString, passwordLength); isoParameters.acseAuthParameter.paswordOctetString.CopyTo(buffer, bufPos); bufPos += passwordLength; } else { /* AUTH_NONE */ buffer[bufPos++] = 0; } } /* user information */ bufPos = IsoUtil.BerEncoder_encodeTL(0xbe, (uint)userInfoLen, buffer, bufPos); /* association data */ bufPos = IsoUtil.BerEncoder_encodeTL(0x28, (uint)assocDataLength, buffer, bufPos); // Добавка Несговорова bufPos = IsoUtil.BerEncoder_encodeTL(0x06, 2, buffer, bufPos); buffer[bufPos++] = 0x51; buffer[bufPos++] = 0x01; /* indirect-reference */ bufPos = IsoUtil.BerEncoder_encodeTL(0x02, 1, buffer, bufPos); buffer[bufPos++] = 3; /* single ASN1 type */ bufPos = IsoUtil.BerEncoder_encodeTL(0xa0, (uint)payloadLength, buffer, bufPos); /*writeBuffer.partLength = bufPos; * writeBuffer.length = bufPos + payload.length; * writeBuffer.nextPart = payload;*/ Array.Copy(payload, 0, buffer, bufPos, payloadLength); return(bufPos + payloadLength); }
public int createAssociateResponseMessage(byte acseResult, byte[] buffer, int bufIndex, byte[] payload, int payloadLength) { int appContextLength = 9; int resultLength = 5; int resultDiagnosticLength = 5; int fixedContentLength = appContextLength + resultLength + resultDiagnosticLength; int variableContentLength = 0; int assocDataLength; int userInfoLength; int nextRefLength; /* single ASN1 type tag */ variableContentLength += payloadLength; variableContentLength += 1; variableContentLength += IsoUtil.BerEncoder_determineLengthSize((uint)payloadLength); /* indirect reference */ nextRefLength = IsoUtil.BerEncoder_UInt32determineEncodedSize((uint)nextReference); variableContentLength += nextRefLength; variableContentLength += 2; /* association data */ assocDataLength = variableContentLength; variableContentLength += IsoUtil.BerEncoder_determineLengthSize((uint)assocDataLength); variableContentLength += 1; /* user information */ userInfoLength = variableContentLength; variableContentLength += IsoUtil.BerEncoder_determineLengthSize((uint)userInfoLength); variableContentLength += 1; variableContentLength += 2; int contentLength = fixedContentLength + variableContentLength; int bufPos = 0; bufPos = IsoUtil.BerEncoder_encodeTL(0x61, (uint)contentLength, buffer, bufPos); /* application context name */ bufPos = IsoUtil.BerEncoder_encodeTL(0xa1, 7, buffer, bufPos); bufPos = IsoUtil.BerEncoder_encodeTL(0x06, 5, buffer, bufPos); //memcpy(buffer + bufPos, appContextNameMms, 5); appContextNameMms.CopyTo(buffer, bufPos); bufPos += 5; /* result */ bufPos = IsoUtil.BerEncoder_encodeTL(0xa2, 3, buffer, bufPos); bufPos = IsoUtil.BerEncoder_encodeTL(0x02, 1, buffer, bufPos); buffer[bufPos++] = acseResult; /* result source diagnostics */ bufPos = IsoUtil.BerEncoder_encodeTL(0xa3, 5, buffer, bufPos); bufPos = IsoUtil.BerEncoder_encodeTL(0xa1, 3, buffer, bufPos); bufPos = IsoUtil.BerEncoder_encodeTL(0x02, 1, buffer, bufPos); buffer[bufPos++] = 0; /* user information */ bufPos = IsoUtil.BerEncoder_encodeTL(0xbe, (uint)userInfoLength, buffer, bufPos); /* association data */ bufPos = IsoUtil.BerEncoder_encodeTL(0x28, (uint)assocDataLength, buffer, bufPos); /* indirect-reference */ bufPos = IsoUtil.BerEncoder_encodeTL(0x02, (uint)nextRefLength, buffer, bufPos); bufPos = IsoUtil.BerEncoder_encodeUInt32((uint)nextReference, buffer, bufPos); /* single ASN1 type */ bufPos = IsoUtil.BerEncoder_encodeTL(0xa0, (uint)payloadLength, buffer, bufPos); /*writeBuffer.partLength = bufPos; * writeBuffer.length = bufPos + payloadLength; * writeBuffer.nextPart = payload;*/ Array.Copy(payload, 0, buffer, bufPos, payloadLength); return(bufPos + payloadLength); }