OLD | NEW |
1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
4 */ | 4 */ |
5 | 5 |
6 /* A lightweight TPM command library. | 6 /* A lightweight TPM command library. |
7 * | 7 * |
8 * The general idea is that TPM commands are array of bytes whose fields are | 8 * The general idea is that TPM commands are array of bytes whose fields are |
9 * mostly compile-time constant. The goal is to build much of the commands at | 9 * mostly compile-time constant. The goal is to build much of the commands at |
10 * compile time (or build time) and change some of the fields at run time as | 10 * compile time (or build time) and change some of the fields at run time as |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 *((uint8_t*)tpm_physicalsetdeactivated_cmd.deactivated) = flag; | 343 *((uint8_t*)tpm_physicalsetdeactivated_cmd.deactivated) = flag; |
344 return Send(tpm_physicalsetdeactivated_cmd.buffer); | 344 return Send(tpm_physicalsetdeactivated_cmd.buffer); |
345 } | 345 } |
346 | 346 |
347 uint32_t TlclGetFlags(uint8_t* disable, uint8_t* deactivated) { | 347 uint32_t TlclGetFlags(uint8_t* disable, uint8_t* deactivated) { |
348 uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE]; | 348 uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE]; |
349 TPM_PERMANENT_FLAGS* pflags; | 349 TPM_PERMANENT_FLAGS* pflags; |
350 uint32_t result; | 350 uint32_t result; |
351 uint32_t size; | 351 uint32_t size; |
352 | 352 |
353 SendReceive(tpm_getcapability_cmd.buffer, response, sizeof(response)); | 353 SendReceive(tpm_getflags_cmd.buffer, response, sizeof(response)); |
354 result = TpmReturnCode(response); | 354 result = TpmReturnCode(response); |
355 if (result != TPM_SUCCESS) { | 355 if (result != TPM_SUCCESS) { |
356 return result; | 356 return result; |
357 } | 357 } |
358 FromTpmUint32(response + kTpmResponseHeaderLength, &size); | 358 FromTpmUint32(response + kTpmResponseHeaderLength, &size); |
359 assert(size == sizeof(TPM_PERMANENT_FLAGS)); | 359 assert(size == sizeof(TPM_PERMANENT_FLAGS)); |
360 pflags = | 360 pflags = |
361 (TPM_PERMANENT_FLAGS*) (response + kTpmResponseHeaderLength + sizeof(size)); | 361 (TPM_PERMANENT_FLAGS*) (response + kTpmResponseHeaderLength + sizeof(size)); |
362 *disable = pflags->disable; | 362 *disable = pflags->disable; |
363 *deactivated = pflags->deactivated; | 363 *deactivated = pflags->deactivated; |
364 return result; | 364 return result; |
365 } | 365 } |
366 | 366 |
367 uint32_t TlclSetGlobalLock(void) { | 367 uint32_t TlclSetGlobalLock(void) { |
368 uint32_t x; | 368 uint32_t x; |
369 return TlclWrite(TPM_NV_INDEX0, (uint8_t*) &x, 0); | 369 return TlclWrite(TPM_NV_INDEX0, (uint8_t*) &x, 0); |
370 } | 370 } |
371 | 371 |
372 uint32_t TlclExtend(int pcr_num, uint8_t* in_digest, uint8_t* out_digest) { | 372 uint32_t TlclExtend(int pcr_num, uint8_t* in_digest, uint8_t* out_digest) { |
373 uint8_t response[kTpmResponseHeaderLength + kPcrDigestLength]; | 373 uint8_t response[kTpmResponseHeaderLength + kPcrDigestLength]; |
374 ToTpmUint32(tpm_extend_cmd.pcrNum, pcr_num); | 374 ToTpmUint32(tpm_extend_cmd.pcrNum, pcr_num); |
375 memcpy(tpm_extend_cmd.inDigest, in_digest, kPcrDigestLength); | 375 memcpy(tpm_extend_cmd.inDigest, in_digest, kPcrDigestLength); |
376 SendReceive(tpm_extend_cmd.buffer, response, sizeof(response)); | 376 SendReceive(tpm_extend_cmd.buffer, response, sizeof(response)); |
377 memcpy(out_digest, response + kTpmResponseHeaderLength, kPcrDigestLength); | 377 memcpy(out_digest, response + kTpmResponseHeaderLength, kPcrDigestLength); |
378 return TpmReturnCode(response); | 378 return TpmReturnCode(response); |
379 } | 379 } |
| 380 |
| 381 uint32_t TlclGetPermissions(uint32_t index, uint32_t* permissions) { |
| 382 uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE]; |
| 383 uint8_t* nvdata; |
| 384 uint32_t result; |
| 385 uint32_t size; |
| 386 |
| 387 ToTpmUint32(tpm_getpermissions_cmd.index, index); |
| 388 SendReceive(tpm_getpermissions_cmd.buffer, response, sizeof(response)); |
| 389 result = TpmReturnCode(response); |
| 390 if (result != TPM_SUCCESS) { |
| 391 return result; |
| 392 } |
| 393 nvdata = response + kTpmResponseHeaderLength + sizeof(size); |
| 394 FromTpmUint32(nvdata + kNvDataPublicPermissionsOffset, permissions); |
| 395 return result; |
| 396 } |
OLD | NEW |