Ejemplo n.º 1
0
        int encodeUserData(byte[] buffer, int bufPos, byte[] payload, int payloadLength, bool encode, byte contextId)
        {
            int encodedDataSetLength = 3; /* presentation-selector */

            /* presentation-data */
            encodedDataSetLength += payloadLength + 1;
            encodedDataSetLength += IsoUtil.BerEncoder_determineLengthSize((uint)payloadLength);

            int fullyEncodedDataLength = encodedDataSetLength;

            fullyEncodedDataLength += IsoUtil.BerEncoder_determineLengthSize((uint)encodedDataSetLength) + 1;

            if (encode)
            {
                /* fully-encoded-data */
                bufPos = IsoUtil.BerEncoder_encodeTL(0x61, (uint)fullyEncodedDataLength, buffer, bufPos);
                bufPos = IsoUtil.BerEncoder_encodeTL(0x30, (uint)encodedDataSetLength, buffer, bufPos);

                /* presentation-selector acse */
                bufPos           = IsoUtil.BerEncoder_encodeTL(0x02, 1, buffer, bufPos);
                buffer[bufPos++] = contextId;

                /* presentation-data (= acse payload) */
                bufPos = IsoUtil.BerEncoder_encodeTL(0xa0, (uint)payloadLength, buffer, bufPos);

                return(bufPos);
            }
            else
            {
                int encodedUserDataLength = fullyEncodedDataLength + 1;
                encodedUserDataLength += IsoUtil.BerEncoder_determineLengthSize((uint)fullyEncodedDataLength);

                return(encodedUserDataLength);
            }
        }
Ejemplo n.º 2
0
        public int createUserDataACSE(byte[] buffer, byte[] payload, int payloadLength)
        {
            int bufPos = 0;

            int userDataLengthFieldSize = IsoUtil.BerEncoder_determineLengthSize((uint)payloadLength);

            int pdvListLength = payloadLength + (userDataLengthFieldSize + 4);

            int pdvListLengthFieldSize = IsoUtil.BerEncoder_determineLengthSize((uint)pdvListLength);
            int presentationLength     = pdvListLength + (pdvListLengthFieldSize + 1);

            bufPos = IsoUtil.BerEncoder_encodeTL(0x61, (uint)presentationLength, buffer, bufPos);

            bufPos = IsoUtil.BerEncoder_encodeTL(0x30, (uint)pdvListLength, buffer, bufPos);

            buffer[bufPos++] = (byte)0x02;
            buffer[bufPos++] = (byte)0x01;
            buffer[bufPos++] = (byte)acseContextId; /* ACSE context id */

            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);
        }
Ejemplo n.º 3
0
        int encodeAcceptBer(byte[] buffer, int bufPos)
        {
            bufPos           = IsoUtil.BerEncoder_encodeTL(0x30, 7, buffer, bufPos);
            bufPos           = IsoUtil.BerEncoder_encodeTL(0x80, 1, buffer, bufPos);
            buffer[bufPos++] = 0;
            bufPos           = IsoUtil.BerEncoder_encodeTL(0x81, 2, buffer, bufPos);
            buffer[bufPos++] = 0x51;
            buffer[bufPos++] = 0x01;

            return(bufPos);
        }
Ejemplo n.º 4
0
        public int createCpaMessage(byte[] buffer, byte[] payload, int payloadLength)
        {
            int contentLength = 0;

            /* mode-selector */
            contentLength += 5;

            int normalModeLength = 0;

            normalModeLength += 6;  /* responding-presentation-selector */

            normalModeLength += 20; /* context-definition-result-list */

            normalModeLength += encodeUserData(null, 0, payload, payloadLength, false, acseContextId);

            contentLength += normalModeLength;

            contentLength += IsoUtil.BerEncoder_determineLengthSize((uint)normalModeLength) + 1;

            int bufPos = 0;

            bufPos = IsoUtil.BerEncoder_encodeTL(0x31, (uint)contentLength, buffer, bufPos);

            /* mode-selector */
            bufPos           = IsoUtil.BerEncoder_encodeTL(0xa0, 3, buffer, bufPos);
            bufPos           = IsoUtil.BerEncoder_encodeTL(0x80, 1, buffer, bufPos);
            buffer[bufPos++] = 1; /* 1 = normal-mode */

            /* normal-mode-parameters */
            bufPos = IsoUtil.BerEncoder_encodeTL(0xa2, (uint)normalModeLength, buffer, bufPos);

            /* responding-presentation-selector */
            bufPos = IsoUtil.BerEncoder_encodeTL(0x83, 4, buffer, bufPos);
            //memcpy(buffer + bufPos, calledPresentationSelector, 4);
            def_calledPresentationSelector.CopyTo(buffer, bufPos);
            bufPos += 4;

            /* context-definition-result-list */
            bufPos = IsoUtil.BerEncoder_encodeTL(0xa5, 18, buffer, bufPos);
            bufPos = encodeAcceptBer(buffer, bufPos); /* accept for acse */
            bufPos = encodeAcceptBer(buffer, bufPos); /* accept for mms */

            /* encode user data */
            bufPos = encodeUserData(buffer, bufPos, payload, payloadLength, true, acseContextId);

            /*writeBuffer->partLength = bufPos;
             * writeBuffer->length = bufPos + payload->length;
             * writeBuffer->nextPart = payload;*/

            Array.Copy(payload, 0, buffer, bufPos, payloadLength);
            return(bufPos + payloadLength);
        }
Ejemplo n.º 5
0
        public int createAbortUserMessage(byte[] buffer, byte[] payload, int payloadLength)
        {
            int contentLength = 0;

            contentLength = +encodeUserData(null, 0, payload, payloadLength, false, acseContextId);

            contentLength += IsoUtil.BerEncoder_determineLengthSize((uint)contentLength) + 1;

            int bufPos = 0;

            bufPos = IsoUtil.BerEncoder_encodeTL(0xa0, (uint)contentLength, buffer, bufPos);

            /* encode user data */
            bufPos = encodeUserData(buffer, bufPos, payload, payloadLength, true, acseContextId);

            /*writeBuffer->partLength = bufPos;
             * writeBuffer->length = bufPos + payload->length;
             * writeBuffer->nextPart = payload;*/

            Array.Copy(payload, 0, buffer, bufPos, payloadLength);
            return(bufPos + payloadLength);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        int createConnectPdu(byte[] buffer, byte[] payload, int payloadLength)
        {
            int contentLength = 0;

            /* mode-selector */
            contentLength += 5;

            int normalModeLength = 0;

            /* called- and calling-presentation-selector */
            normalModeLength += 12;

            int pclLength = 35;

            normalModeLength += pclLength;

            normalModeLength += encodeUserData(null, 0, payload, payloadLength, false, acseContextId);

            normalModeLength += 2;

            contentLength += normalModeLength; // + 2;

            contentLength += 1 + IsoUtil.BerEncoder_determineLengthSize((uint)normalModeLength);

            int bufPos = 0;

            bufPos = IsoUtil.BerEncoder_encodeTL(0x31, (uint)contentLength, buffer, bufPos);

            /* mode-selector */
            bufPos           = IsoUtil.BerEncoder_encodeTL(0xa0, 3, buffer, bufPos);
            bufPos           = IsoUtil.BerEncoder_encodeTL(0x80, 1, buffer, bufPos);
            buffer[bufPos++] = 1; /* 1 = normal-mode */

            /* normal-mode-parameters */
            bufPos = IsoUtil.BerEncoder_encodeTL(0xa2, (uint)normalModeLength, buffer, bufPos);

            /* calling-presentation-selector */
            bufPos           = IsoUtil.BerEncoder_encodeTL(0x81, 4, buffer, bufPos);
            buffer[bufPos++] = (byte)((callingPresentationSelector >> 24) & 0xff);
            buffer[bufPos++] = (byte)((callingPresentationSelector >> 16) & 0xff);
            buffer[bufPos++] = (byte)((callingPresentationSelector >> 8) & 0xff);
            buffer[bufPos++] = (byte)(callingPresentationSelector & 0xff);

            /* called-presentation-selector */
            bufPos           = IsoUtil.BerEncoder_encodeTL(0x82, 4, buffer, bufPos);
            buffer[bufPos++] = (byte)((calledPresentationSelector >> 24) & 0xff);
            buffer[bufPos++] = (byte)((calledPresentationSelector >> 16) & 0xff);
            buffer[bufPos++] = (byte)((calledPresentationSelector >> 8) & 0xff);
            buffer[bufPos++] = (byte)(calledPresentationSelector & 0xff);

            /* presentation-context-id list */
            bufPos = IsoUtil.BerEncoder_encodeTL(0xa4, 35, buffer, bufPos);

            /* acse context list item */
            bufPos = IsoUtil.BerEncoder_encodeTL(0x30, 15, buffer, bufPos);

            bufPos           = IsoUtil.BerEncoder_encodeTL(0x02, 1, buffer, bufPos);
            buffer[bufPos++] = 1;

            bufPos = IsoUtil.BerEncoder_encodeTL(0x06, 4, buffer, bufPos);
            //memcpy(buffer + bufPos, asn_id_as_acse, 4);
            asn_id_as_acse.CopyTo(buffer, bufPos);
            bufPos += 4;

            bufPos = IsoUtil.BerEncoder_encodeTL(0x30, 4, buffer, bufPos);
            bufPos = IsoUtil.BerEncoder_encodeTL(0x06, 2, buffer, bufPos);
            //memcpy(buffer + bufPos, ber_id, 2);
            ber_id.CopyTo(buffer, bufPos);
            bufPos += 2;

            /* mms context list item */
            bufPos = IsoUtil.BerEncoder_encodeTL(0x30, 16, buffer, bufPos);

            bufPos           = IsoUtil.BerEncoder_encodeTL(0x02, 1, buffer, bufPos);
            buffer[bufPos++] = 3;

            bufPos = IsoUtil.BerEncoder_encodeTL(0x06, 5, buffer, bufPos);
            //memcpy(buffer + bufPos, asn_id_mms, 5);
            asn_id_mms.CopyTo(buffer, bufPos);
            bufPos += 5;

            bufPos = IsoUtil.BerEncoder_encodeTL(0x30, 4, buffer, bufPos);
            bufPos = IsoUtil.BerEncoder_encodeTL(0x06, 2, buffer, bufPos);
            //memcpy(buffer + bufPos, ber_id, 2);
            ber_id.CopyTo(buffer, bufPos);
            bufPos += 2;

            /* encode user data */
            bufPos = encodeUserData(buffer, bufPos, payload, payloadLength, true, acseContextId);

            Array.Copy(payload, 0, buffer, bufPos, payloadLength);

            /*
             * writeBuffer->partLength = bufPos;
             * writeBuffer->length = bufPos + payload->length;
             * writeBuffer->nextPart = payload;*/
            return(bufPos + payloadLength);
        }