diff --git a/src/mms/asn1/ber_decode.c b/src/mms/asn1/ber_decode.c index 7eca9308..00e82133 100644 --- a/src/mms/asn1/ber_decode.c +++ b/src/mms/asn1/ber_decode.c @@ -82,6 +82,43 @@ BerDecoder_decodeUint32(uint8_t* buffer, int intlen, int bufPos) { return value; } +int32_t +BerDecoder_decodeInt32(uint8_t* buffer, int intlen, int bufPos) +{ + int32_t value = 0; + + int flag = buffer[bufPos]&0x80;//flag=1表示负数,flag=0表示正数 + + int i=0; + + if(flag) + { + for(i=0;i<4;i++) + { + value<<=8; + if(i<4-intlen) + { + value+=0xff; + } + else + { + value+=buffer[bufPos + i-(4-intlen)]; + } + } + } + else + { + for (i = 0; i < intlen; i++) + { + value <<= 8; + value += buffer[bufPos + i]; + } + } + + return value; +} + + float BerDecoder_decodeFloat(uint8_t* buffer, int bufPos) { diff --git a/src/mms/inc_private/ber_decode.h b/src/mms/inc_private/ber_decode.h index 258f6a21..8bdbcc3e 100644 --- a/src/mms/inc_private/ber_decode.h +++ b/src/mms/inc_private/ber_decode.h @@ -34,6 +34,9 @@ BerDecoder_decodeString(uint8_t* buffer, int strlen, int bufPos, int maxBufPos); uint32_t BerDecoder_decodeUint32(uint8_t* buffer, int intlen, int bufPos); +int32_t +BerDecoder_decodeInt32(uint8_t* buffer, int intlen, int bufPos); + float BerDecoder_decodeFloat(uint8_t* buffer, int bufPos); diff --git a/src/mms/iso_mms/client/mms_client_files.c b/src/mms/iso_mms/client/mms_client_files.c index a6603ebc..b0e75494 100644 --- a/src/mms/iso_mms/client/mms_client_files.c +++ b/src/mms/iso_mms/client/mms_client_files.c @@ -212,7 +212,7 @@ mmsClient_handleFileReadRequest( uint32_t invokeId, ByteBuffer* response) { - int32_t frsmId = (int32_t) BerDecoder_decodeUint32(buffer, maxBufPos - bufPos, bufPos); + int32_t frsmId = BerDecoder_decodeInt32(buffer, maxBufPos - bufPos, bufPos); if (DEBUG_MMS_CLIENT) printf("MMS_CLIENT: mmsClient_handleFileReadRequest read request for frsmId: %i\n", frsmId); @@ -232,7 +232,7 @@ mmsClient_handleFileCloseRequest( uint32_t invokeId, ByteBuffer* response) { - int32_t frsmId = (int32_t) BerDecoder_decodeUint32(buffer, maxBufPos - bufPos, bufPos); + int32_t frsmId = BerDecoder_decodeInt32(buffer, maxBufPos - bufPos, bufPos); MmsFileReadStateMachine* frsm = getFrsm(connection, frsmId); @@ -698,7 +698,7 @@ mmsMsg_parseFileOpenResponse(uint8_t* buffer, int bufPos, int maxBufPos, int32_t switch (tag) { case 0x80: /* frsmId */ - *frsmId = (int32_t) BerDecoder_decodeUint32(buffer, length, bufPos); + *frsmId = BerDecoder_decodeInt32(buffer, length, bufPos); bufPos += length; break;