-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.c
65 lines (54 loc) · 1.2 KB
/
test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<string.h>
#include<fcntl.h>
#define TPMMAX 4096
unsigned int TPM_Transmit(unsigned char *blob){
int tpmfp;
int len;
unsigned int size;
tpmfp = open("/dev/tpm", O_RDWR);
size = (unsigned int *)&blob[2];
len = write(tpmfp, blob, size);
len = read(tpmfp, blob, TPMMAX);
close(tpmfp);
return ((unsigned int *)&blob[6]);
}
unsigned int TPM_Reset(){
unsigned char blob[TPMMAX]={0,193,0,0,0,10,0,0,0,90};
return TPM_Transmit(blob);
}
unsigned int TPM_GetCapability_Version(){
unsigned char blob[TPMMAX] = {0, 193, 0, 0, 0, 18, 0, 0, 0, 101, 0, 0, 0, 6, 0, 0, 0, 0};
return (TPM_Transmit(blob));
}
void test(){
int tpmfp;
if((tpmfp = open("/dev/tpm0", O_RDWR)) < 0){
printf("tpmfp:%d\n", tpmfp);
printf("Unable to open /dev/tpm0\n");
return;
}
close(tpmfp);
}
void test_tpm_reset(){
int ret;
if((ret = TPM_Reset())){
exit(-2);
}
}
/*void test_tpm_pcrread(){
int ret;
if((ret = TPM_PcrRead(0L, pcrvalue))){
printf("TPM Pcr read failed, error %s\n", TPM_GetErrMsg(ret));
exit(-3);
}
}
*/
int main(){
//test();
//test_tpm_reset();
printf("\nTPM version is ========\n%u\n", TPM_GetCapability_Version());
return 0;
}