Пример #1
0
        public int createConnectSpdu(IsoConnectionParameters isoParameters, byte[] buffer, byte[] payload, int payloadLength)
        {
            int offset = 0;
            int lengthOffset;

            buffer[offset++] = 13; /* CONNECT SPDU */
            lengthOffset     = offset;
            offset++;              /* Skip byte for length - fill it later */

            calledSessionSelector  = isoParameters.remoteSSelector;
            callingSessionSelector = isoParameters.localSSelector;

            offset = encodeConnectAcceptItem(buffer, offset, 0);

            offset = encodeSessionRequirement(buffer, offset);

            offset = encodeCallingSessionSelector(buffer, offset);

            offset = encodeCalledSessionSelector(buffer, offset);

            offset = encodeSessionUserData(buffer, offset, (byte)payloadLength);

            int spduLength = (offset - lengthOffset - 1) + payloadLength;

            buffer[lengthOffset] = (byte)spduLength;

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

            return(payloadLength + offset);
        }
Пример #2
0
 void Reset(IsoConnectionParameters cp)
 {
     m_COTP_dstref = 0x0000;
     m_COTP_srcref = 0x0008;
     m_COTP_option = 0x00;
     options       = new CotpOptions(cp);
 }
Пример #3
0
 public int createConnectPdu(IsoConnectionParameters parameters, byte[] buffer, byte[] payload, int payloadLength)
 {
     acseContextId = 1;
     mmsContextId  = 3;
     callingPresentationSelector = parameters.localPSelector;
     calledPresentationSelector  = parameters.remotePSelector;
     return(createConnectPdu(buffer, payload, payloadLength));
 }
Пример #4
0
 public CotpOptions(IsoConnectionParameters cp)
 {
     if (cp == null)
     {
         tSelDst  = new TSelector(2, 0x0001);
         tSelSrc  = new TSelector(2, 0x0000);
         tpduSize = 0x0a;    // 1024 byte max PDU size
     }
     else
     {
         tSelDst  = cp.remoteTSelector;
         tSelSrc  = cp.localTSelector;
         tpduSize = 0x0a;    // 1024 byte max PDU size
     }
 }
Пример #5
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);
        }
Пример #6
0
 public int Start(IsoConnectionParameters par)
 {
     isoParameters   = par;
     restart_allowed = true;
     return(Start());
 }
Пример #7
0
 public IsoCotp(IsoConnectionParameters cp)
 {
     Reset(cp);
 }