📄 tpm_reset.c
字号:
/* * The Initial Developer of the Original Code is International * Business Machines Corporation. Portions created by IBM * Corporation are Copyright (C) 2005 International Business * Machines Corporation. All Rights Reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the Common Public License as published by * IBM Corporation; either version 1 of the License, or (at your option) * any later version. * * This program 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 * Common Public License for more details. * * You should have received a copy of the Common Public License * along with this program; if not, a copy can be viewed at * http://www.opensource.org/licenses/cpl1.0.php. */#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>#include <errno.h>#include <string.h>int main() { char reset[] = { 0, 193, /* TPM_TAG_RQU_COMMAND */ 0, 0, 0, 10, /* length */ 0, 0, 0, 90 /* TPM_ORD_Reset */ }; int fd; int err; int rc = 1; fd = open( "/dev/tpm0", O_RDWR ); if ( fd < 0 ) { printf( "Unable to open the device.\n" ); goto out; } err = write( fd, reset, sizeof(reset) ); if ( err != sizeof( reset ) ){ printf( "Error occured while writing the reset command: %d\n", errno ); goto out; } err = read( fd, reset, sizeof(reset) ); if ( err != 10 ) { printf( "Error occured while reading the reset result: %d %d %s\n", err, errno, strerror(errno)); goto out; } /* ENDIANESS ISSUES HERE */ //memcpy( &err, startup+6, 4 ); //for PPC64 memcpy( &err+3, reset+6, 1); memcpy( &err+2, reset+7, 1); memcpy( &err+1, reset+8, 1); memcpy( &err, reset+9, 1); if ( err == 38 ) { printf( "TPM not started.\n" ); goto out; } if ( err != 0 ) { printf( "TPM Error occured: %d\n", err ); goto out; } rc = 0; printf( "Reset successful\n" );out: close(fd); return rc;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -