diff options
Diffstat (limited to 'tinySIGCOMP/src/tcomp_nackinfo.c')
-rwxr-xr-x | tinySIGCOMP/src/tcomp_nackinfo.c | 259 |
1 files changed, 129 insertions, 130 deletions
diff --git a/tinySIGCOMP/src/tcomp_nackinfo.c b/tinySIGCOMP/src/tcomp_nackinfo.c index fb7b58c..64515df 100755 --- a/tinySIGCOMP/src/tcomp_nackinfo.c +++ b/tinySIGCOMP/src/tcomp_nackinfo.c @@ -2,19 +2,19 @@ * Copyright (C) 2010-2011 Mamadou Diop. * * Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. * @@ -49,139 +49,139 @@ field is set to 0. /** Creates new NACK object */ tcomp_nackinfo_t* tcomp_nackinfo_create() { - tcomp_nackinfo_t *nackinfo; - if((nackinfo = tsk_object_new(tcomp_nackinfo_def_t))){ - nackinfo->version = NACK_VERSION; - nackinfo->details = tcomp_buffer_create_null(); - } - return nackinfo; + tcomp_nackinfo_t *nackinfo; + if((nackinfo = tsk_object_new(tcomp_nackinfo_def_t))) { + nackinfo->version = NACK_VERSION; + nackinfo->details = tcomp_buffer_create_null(); + } + return nackinfo; } -int tcomp_nackinfo_write(tcomp_buffer_handle_t* buffer, - uint8_t reasonCode, - uint8_t opCode, - int16_t memory_address_of_instruction, - const void* sigCompMessagePtr, tsk_size_t sigCompMessageSize, - tcomp_buffer_handle_t* lpDetails, - uint16_t udvm_size, - uint8_t cpbValue) +int tcomp_nackinfo_write(tcomp_buffer_handle_t* buffer, + uint8_t reasonCode, + uint8_t opCode, + int16_t memory_address_of_instruction, + const void* sigCompMessagePtr, tsk_size_t sigCompMessageSize, + tcomp_buffer_handle_t* lpDetails, + uint16_t udvm_size, + uint8_t cpbValue) { - tsk_sha1context_t sha; - uint8_t *nackbuffer_ptr; - - if(!buffer || !sigCompMessagePtr || !sigCompMessageSize){ - TSK_DEBUG_ERROR("Invalid parameter"); - return -1; - } - - tcomp_buffer_allocBuff(buffer, INDEX_NACK_SHA1 + TSK_SHA1_DIGEST_SIZE); - if(!(nackbuffer_ptr = tcomp_buffer_getBuffer(buffer))){ - TSK_DEBUG_ERROR("NACK buffer is null"); - return -2; - } - - nackbuffer_ptr[INDEX_NACK_HEADER] = 0xf8; - nackbuffer_ptr[INDEX_NACK_VERSION] = NACK_VERSION; - nackbuffer_ptr[INDEX_NACK_REASON_CODE] = reasonCode; - nackbuffer_ptr[INDEX_NACK_OPCODE] = opCode; - nackbuffer_ptr[INDEX_NACK_PC] = (memory_address_of_instruction >> 8); - nackbuffer_ptr[INDEX_NACK_PC + 1] = (memory_address_of_instruction & 0x00ff); - - // SHA-1(message) computation - tsk_sha1reset(&sha); - tsk_sha1input(&sha, sigCompMessagePtr, sigCompMessageSize); - tsk_sha1result(&sha, &nackbuffer_ptr[INDEX_NACK_SHA1]); - + tsk_sha1context_t sha; + uint8_t *nackbuffer_ptr; + + if(!buffer || !sigCompMessagePtr || !sigCompMessageSize) { + TSK_DEBUG_ERROR("Invalid parameter"); + return -1; + } + + tcomp_buffer_allocBuff(buffer, INDEX_NACK_SHA1 + TSK_SHA1_DIGEST_SIZE); + if(!(nackbuffer_ptr = tcomp_buffer_getBuffer(buffer))) { + TSK_DEBUG_ERROR("NACK buffer is null"); + return -2; + } + + nackbuffer_ptr[INDEX_NACK_HEADER] = 0xf8; + nackbuffer_ptr[INDEX_NACK_VERSION] = NACK_VERSION; + nackbuffer_ptr[INDEX_NACK_REASON_CODE] = reasonCode; + nackbuffer_ptr[INDEX_NACK_OPCODE] = opCode; + nackbuffer_ptr[INDEX_NACK_PC] = (memory_address_of_instruction >> 8); + nackbuffer_ptr[INDEX_NACK_PC + 1] = (memory_address_of_instruction & 0x00ff); + + // SHA-1(message) computation + tsk_sha1reset(&sha); + tsk_sha1input(&sha, sigCompMessagePtr, sigCompMessageSize); + tsk_sha1result(&sha, &nackbuffer_ptr[INDEX_NACK_SHA1]); + #if 0 - { - int i; - TSK_DEBUG_INFO("Create NACK with id:"); - for(i = 0; i < TSK_SHA1_DIGEST_SIZE; ++i){ - printf("%x ", nackbuffer_ptr[INDEX_NACK_SHA1 + i]); - } - printf("\n"); - } + { + int i; + TSK_DEBUG_INFO("Create NACK with id:"); + for(i = 0; i < TSK_SHA1_DIGEST_SIZE; ++i) { + printf("%x ", nackbuffer_ptr[INDEX_NACK_SHA1 + i]); + } + printf("\n"); + } #endif - // Details - if(lpDetails && tcomp_buffer_getSize(lpDetails)){ - tcomp_buffer_appendBuff(buffer, tcomp_buffer_getBuffer(lpDetails), tcomp_buffer_getSize(lpDetails)); - } - else if(reasonCode == NACK_BYTECODES_TOO_LARGE){ - tcomp_buffer_appendBuff(buffer, &udvm_size, 2); - } - else if(reasonCode == NACK_CYCLES_EXHAUSTED){ - tcomp_buffer_appendBuff(buffer, &cpbValue, 1); - } + // Details + if(lpDetails && tcomp_buffer_getSize(lpDetails)) { + tcomp_buffer_appendBuff(buffer, tcomp_buffer_getBuffer(lpDetails), tcomp_buffer_getSize(lpDetails)); + } + else if(reasonCode == NACK_BYTECODES_TOO_LARGE) { + tcomp_buffer_appendBuff(buffer, &udvm_size, 2); + } + else if(reasonCode == NACK_CYCLES_EXHAUSTED) { + tcomp_buffer_appendBuff(buffer, &cpbValue, 1); + } - return 0; + return 0; } -int tcomp_nackinfo_write_2(tcomp_buffer_handle_t* buffer, - uint8_t reasonCode, - uint8_t opCode, - int16_t memory_address_of_instruction, - const tcomp_message_t* sigCompMessage, - tcomp_buffer_handle_t* lpDetails, - uint16_t udvm_size, - uint8_t cpbValue) +int tcomp_nackinfo_write_2(tcomp_buffer_handle_t* buffer, + uint8_t reasonCode, + uint8_t opCode, + int16_t memory_address_of_instruction, + const tcomp_message_t* sigCompMessage, + tcomp_buffer_handle_t* lpDetails, + uint16_t udvm_size, + uint8_t cpbValue) { - return tcomp_nackinfo_write(buffer, - reasonCode, - opCode, - memory_address_of_instruction, - sigCompMessage->startPtr, sigCompMessage->totalSize, - lpDetails, - udvm_size, - cpbValue); + return tcomp_nackinfo_write(buffer, + reasonCode, + opCode, + memory_address_of_instruction, + sigCompMessage->startPtr, sigCompMessage->totalSize, + lpDetails, + udvm_size, + cpbValue); } -int tcomp_nackinfo_write_3(tcomp_buffer_handle_t* buffer, - uint8_t reasonCode, - const void* sigCompMessagePtr, tsk_size_t sigCompMessageSize) +int tcomp_nackinfo_write_3(tcomp_buffer_handle_t* buffer, + uint8_t reasonCode, + const void* sigCompMessagePtr, tsk_size_t sigCompMessageSize) { - return tcomp_nackinfo_write(buffer, - reasonCode, - OPCODE_UNKNOWN, - PC_UNKNOWN, - sigCompMessagePtr, sigCompMessageSize, - tsk_null, - 0, - 0); + return tcomp_nackinfo_write(buffer, + reasonCode, + OPCODE_UNKNOWN, + PC_UNKNOWN, + sigCompMessagePtr, sigCompMessageSize, + tsk_null, + 0, + 0); } -int tcomp_nackinfo_write_4(tcomp_buffer_handle_t* buffer, - uint8_t reasonCode, - const tcomp_message_t* sigCompMessage) +int tcomp_nackinfo_write_4(tcomp_buffer_handle_t* buffer, + uint8_t reasonCode, + const tcomp_message_t* sigCompMessage) { - return tcomp_nackinfo_write_2(buffer, - reasonCode, - OPCODE_UNKNOWN, - PC_UNKNOWN, - sigCompMessage, - tsk_null, - 0, - 0); + return tcomp_nackinfo_write_2(buffer, + reasonCode, + OPCODE_UNKNOWN, + PC_UNKNOWN, + sigCompMessage, + tsk_null, + 0, + 0); } const char* tcomp_nackinfo_get_description(const tcomp_buffer_handle_t* buffer) { - uint8_t reasonCode; - if(!buffer){ - TSK_DEBUG_ERROR("Invalid parameter"); - return tsk_null; - } - if(tcomp_buffer_getSize(buffer) < 3){ - TSK_DEBUG_ERROR("Too short"); - return tsk_null; - } - reasonCode = *((const uint8_t*)tcomp_buffer_getBufferAtPos(buffer, 3)); - if(reasonCode >= (sizeof(TCOMP_NACK_DESCRIPTIONS)/sizeof(TCOMP_NACK_DESCRIPTIONS[0]))){ - TSK_DEBUG_ERROR("%d not valid as reasonCode", (int32_t)reasonCode); - return tsk_null; - } - return TCOMP_NACK_DESCRIPTIONS[reasonCode].desc; + uint8_t reasonCode; + if(!buffer) { + TSK_DEBUG_ERROR("Invalid parameter"); + return tsk_null; + } + if(tcomp_buffer_getSize(buffer) < 3) { + TSK_DEBUG_ERROR("Too short"); + return tsk_null; + } + reasonCode = *((const uint8_t*)tcomp_buffer_getBufferAtPos(buffer, 3)); + if(reasonCode >= (sizeof(TCOMP_NACK_DESCRIPTIONS)/sizeof(TCOMP_NACK_DESCRIPTIONS[0]))) { + TSK_DEBUG_ERROR("%d not valid as reasonCode", (int32_t)reasonCode); + return tsk_null; + } + return TCOMP_NACK_DESCRIPTIONS[reasonCode].desc; } //======================================================== @@ -195,10 +195,10 @@ const char* tcomp_nackinfo_get_description(const tcomp_buffer_handle_t* buffer) */ static tsk_object_t* tcomp_nackinfo_ctor(tsk_object_t *self, va_list* app) { - tcomp_nackinfo_t *nackinfo = self; - if(nackinfo){ - } - return self; + tcomp_nackinfo_t *nackinfo = self; + if(nackinfo) { + } + return self; } /* @@ -208,20 +208,19 @@ static tsk_object_t* tcomp_nackinfo_ctor(tsk_object_t *self, va_list* app) */ static tsk_object_t* tcomp_nackinfo_dtor(tsk_object_t* self) { - tcomp_nackinfo_t *nackinfo = self; - if(nackinfo){ - TSK_OBJECT_SAFE_FREE(nackinfo->details); - } - return self; + tcomp_nackinfo_t *nackinfo = self; + if(nackinfo) { + TSK_OBJECT_SAFE_FREE(nackinfo->details); + } + return self; } -static const tsk_object_def_t tcomp_nackinfo_def_s = -{ - sizeof(tcomp_nackinfo_t), - tcomp_nackinfo_ctor, - tcomp_nackinfo_dtor, - tsk_null +static const tsk_object_def_t tcomp_nackinfo_def_s = { + sizeof(tcomp_nackinfo_t), + tcomp_nackinfo_ctor, + tcomp_nackinfo_dtor, + tsk_null }; const tsk_object_def_t* tcomp_nackinfo_def_t = &tcomp_nackinfo_def_s; |