mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-24 16:57:21 +00:00
Allow passing TPM device path in the environment.
Review URL: http://codereview.chromium.org/3032055
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
@@ -111,12 +112,19 @@ void TlclCloseDevice(void) {
|
||||
|
||||
|
||||
void TlclOpenDevice(void) {
|
||||
char* device_path;
|
||||
|
||||
if (tpm_fd >= 0)
|
||||
return; /* Already open */
|
||||
|
||||
tpm_fd = open(TPM_DEVICE_PATH, O_RDWR);
|
||||
device_path = getenv("TPM_DEVICE_PATH");
|
||||
if (device_path == NULL) {
|
||||
device_path = TPM_DEVICE_PATH;
|
||||
}
|
||||
|
||||
tpm_fd = open(device_path, O_RDWR);
|
||||
if (tpm_fd < 0) {
|
||||
error("cannot open TPM device %s: %s\n", TPM_DEVICE_PATH, strerror(errno));
|
||||
error("cannot open TPM device %s: %s\n", device_path, strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,14 +13,15 @@
|
||||
* This also enables the TPM if it is disabled, and activates it if it is
|
||||
* deactivated.
|
||||
*
|
||||
* Exit status: 0 for normal, 1 for errors (see syslog), 2 for normal but needs
|
||||
* reboot.
|
||||
* Exit status always 0. Prints "reboot" to request reboot, "fail" for errors,
|
||||
* "success" when everything worked.
|
||||
*/
|
||||
|
||||
#include "tlcl.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include "tlcl.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
uint32_t result;
|
||||
uint8_t disable, deactivated;
|
||||
@@ -33,34 +34,41 @@ int main(int argc, char* argv[]) {
|
||||
result = TlclSelfTestFull();
|
||||
if (result != 0) {
|
||||
syslog(pri, "TPM selftest failed with code 0x%x\n", result);
|
||||
return 1;
|
||||
printf("fail\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/* Optional one-time enabling of TPM. */
|
||||
result = TlclAssertPhysicalPresence();
|
||||
if (result != 0) {
|
||||
syslog(pri, "TPM assertpp failed with code 0x%x\n", result);
|
||||
return 1;
|
||||
printf("fail\n");
|
||||
return 0;
|
||||
}
|
||||
result = TlclGetFlags(&disable, &deactivated, NULL);
|
||||
if (result != 0) {
|
||||
syslog(pri, "TPM getflags failed with code 0x%x\n", result);
|
||||
return 1;
|
||||
printf("fail\n");
|
||||
return 0;
|
||||
}
|
||||
if (disable) {
|
||||
result = TlclSetEnable();
|
||||
if (result != 0) {
|
||||
syslog(pri, "TPM physical enable failed with code 0x%x\n", result);
|
||||
return 1;
|
||||
printf("fail\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (deactivated) {
|
||||
result = TlclSetDeactivated(0);
|
||||
if (result != 0) {
|
||||
syslog(pri, "TPM physical activate failed with code 0x%x\n", result);
|
||||
return 1;
|
||||
printf("fail\n");
|
||||
} else {
|
||||
printf("reboot\n");
|
||||
}
|
||||
return 2; /* needs reboot */
|
||||
return 0; /* needs reboot */
|
||||
}
|
||||
printf("success\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user