frsmId is signed value in some IEDs.

In GE Relay, the frsmId is signed, not unsigned.
pull/11/head
yiqifeiyang 8 years ago
parent 38b7e9284c
commit 888d97a3a0

@ -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)
{

@ -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);

@ -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;

Loading…
Cancel
Save