static uint32_t TPM_ReceiveCharDev(int sock_fd, struct tpm_buffer *tb) { uint32_t rc = 0; uint32_t paramSize = 0; unsigned char *buffer = tb->buffer; #ifndef USE_PARTIAL_READ /* read the whole packet */ if (rc == 0) { int nread; nread = read(sock_fd, tb->buffer, tb->size); if (nread < 0) { rc = ERR_IO; } else { tb->used = nread; } } #endif #ifdef USE_PARTIAL_READ /* read the tag and paramSize */ if (rc == 0) { rc = TPM_ReceiveBytes(sock_fd, buffer, TPM_U16_SIZE + TPM_U32_SIZE); } #endif /* extract the paramSize */ if (rc == 0) { paramSize = LOAD32(buffer, TPM_PARAMSIZE_OFFSET); if (paramSize > TPM_MAX_BUFF_SIZE) { printf("TPM_ReceiveCharDev: paramSize %u greater than %u\n", paramSize, TPM_MAX_BUFF_SIZE); rc = ERR_BAD_RESP; } } #ifdef USE_PARTIAL_READ /* read the rest of the packet */ if (rc == 0) { rc = TPM_ReceiveBytes(sock_fd, buffer + TPM_U16_SIZE + TPM_U32_SIZE, paramSize - (TPM_U16_SIZE + TPM_U32_SIZE)); } #endif /* read the TPM return code from the packet */ if (rc == 0) { showBuff(buffer, "TPM_ReceiveCharDev: From TPM"); tb->used = paramSize; tpm_buffer_load32(tb, TPM_RETURN_OFFSET, &rc); } return rc; }
static uint32_t TPM_ReceiveSocket(int sock_fd, struct tpm_buffer *tb) { uint32_t rc = 0; uint32_t paramSize = 0; uint32_t addsize = 0; unsigned char *buffer = tb->buffer; if (TPM_LowLevel_Use_VTPM()) addsize = sizeof(uint32_t); /* read the tag and paramSize */ if (rc == 0) { rc = TPM_ReceiveBytes(sock_fd, buffer, addsize + TPM_U16_SIZE + TPM_U32_SIZE); } /* extract the paramSize */ if (rc == 0) { paramSize = LOAD32(buffer, addsize + TPM_PARAMSIZE_OFFSET); if (paramSize > TPM_MAX_BUFF_SIZE) { printf ("TPM_ReceiveSocket: ERROR: paramSize %u greater than %u\n", paramSize, TPM_MAX_BUFF_SIZE); rc = ERR_BAD_RESP; } } /* read the rest of the packet */ if (rc == 0) { rc = TPM_ReceiveBytes(sock_fd, buffer + addsize + TPM_U16_SIZE + TPM_U32_SIZE, paramSize - (TPM_U16_SIZE + TPM_U32_SIZE)); } /* read the TPM return code from the packet */ if (rc == 0) { showBuff(buffer, "TPM_ReceiveSocket: From TPM"); rc = LOAD32(buffer, addsize + TPM_RETURN_OFFSET); tb->used = addsize + paramSize; } return rc; }