TcgStorageCoreLib.h 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309
  1. /** @file
  2. Public API for the Tcg Core library to perform the lowest level TCG Data encoding.
  3. (TCG Storage Architecture Core Specification, Version 2.01, Revision 1.00,
  4. https://trustedcomputinggroup.org/tcg-storage-architecture-core-specification/)
  5. Check http://trustedcomputinggroup.org for latest specification updates.
  6. Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
  7. SPDX-License-Identifier: BSD-2-Clause-Patent
  8. **/
  9. #ifndef _TCG_CORE_H_
  10. #define _TCG_CORE_H_
  11. #include <IndustryStandard/TcgStorageCore.h>
  12. #define ERROR_CHECK(arg) \
  13. { \
  14. TCG_RESULT ret = (arg); \
  15. if (ret != TcgResultSuccess) { \
  16. DEBUG ((DEBUG_INFO, "ERROR_CHECK failed at %a:%u\n", __FILE__, __LINE__)); \
  17. return ret; \
  18. } \
  19. }
  20. #define METHOD_STATUS_ERROR_CHECK(arg, failRet) \
  21. if ((arg) != TCG_METHOD_STATUS_CODE_SUCCESS) { \
  22. DEBUG ((DEBUG_INFO, "Method Status error: 0x%02X (%a)\n", arg, TcgMethodStatusString(arg))); \
  23. return (failRet); \
  24. }
  25. #define NULL_CHECK(arg) \
  26. do { \
  27. if ((arg) == NULL) { \
  28. DEBUG ((DEBUG_INFO, "NULL_CHECK(%a) failed at %a:%u\n", #arg, __FILE__, __LINE__)); \
  29. return TcgResultFailureNullPointer; \
  30. } \
  31. } while (0)
  32. #pragma pack(1)
  33. /**
  34. Tcg result codes.
  35. The result code indicates if the Tcg function call was successful or not
  36. **/
  37. typedef enum {
  38. //
  39. // This is the return result upon successful completion of a Tcg function call
  40. //
  41. TcgResultSuccess,
  42. //
  43. // This is the return "catchall" result for the failure of a Tcg function call
  44. //
  45. TcgResultFailure,
  46. //
  47. // This is the return result if a required parameter was Null for a Tcg function call
  48. //
  49. TcgResultFailureNullPointer,
  50. //
  51. // This is the return result if a required buffersize was 0 for a Tcg function call
  52. //
  53. TcgResultFailureZeroSize,
  54. //
  55. // This is the return result if a Tcg function call was executed out of order.
  56. // For instance, starting a Tcg subpacket before starting its Tcg packet.
  57. //
  58. TcgResultFailureInvalidAction,
  59. //
  60. // This is the return result if the buffersize provided is not big enough to add a requested Tcg encoded item.
  61. //
  62. TcgResultFailureBufferTooSmall,
  63. //
  64. // This is the return result for a Tcg parse function if the end of the parsed Buffer is reached, yet Data is still attempted to be retrieved.
  65. // For instance, attempting to retrieve another Tcg token from the Buffer after it has reached the end of the Tcg subpacket payload.
  66. //
  67. TcgResultFailureEndBuffer,
  68. //
  69. // This is the return result for a Tcg parse function if the Tcg Token item requested is not the expected type.
  70. // For instance, the caller requested to receive an integer and the Tcg token was a byte sequence.
  71. //
  72. TcgResultFailureInvalidType,
  73. } TCG_RESULT;
  74. //
  75. // Structure that is used to build the Tcg ComPacket. It contains the start Buffer pointer and the current position of the
  76. // Tcg ComPacket, current Tcg Packet and Tcg SubPacket. This structure must be initialized
  77. // by calling tcgInitTcgCreateStruct before it is used as parameter to any other Tcg function.
  78. // This structure should NOT be directly modified by the client of this library.
  79. //
  80. // NOTE: WE MAY MAKE THIS AN ABSTRACT STRUCTURE WITH A DEFINED SIZE AND KEEP THE VARIABLES
  81. // INTERNAL AND ONLY KNOWN TO THE TCG LIBRARY
  82. //
  83. // tcgInitTcgCreateStruct
  84. //
  85. typedef struct {
  86. //
  87. // Buffer allocated and freed by the client of the Tcg library.
  88. // This is the Buffer that shall contain the final Tcg encoded compacket.
  89. //
  90. VOID *Buffer;
  91. //
  92. // Size of the Buffer provided.
  93. //
  94. UINT32 BufferSize;
  95. //
  96. //Pointer to the start of the Tcg ComPacket. It should point to a location within Buffer.
  97. //
  98. TCG_COM_PACKET *ComPacket;
  99. //
  100. // Current Tcg Packet that is being created. It should point to a location within Buffer.
  101. //
  102. TCG_PACKET *CurPacket;
  103. //
  104. // Current Tcg SubPacket that is being created. It should point to a location within Buffer.
  105. //
  106. TCG_SUB_PACKET *CurSubPacket;
  107. //
  108. // Flag used to indicate if the Buffer of the structure should be filled out.
  109. // This is intended to be used to support a use-case where the client of library
  110. // can perform all the desired tcg calls to determine what the actual Size of the final compacket will be.
  111. // Then the client can allocate the required Buffer Size and re-run the tcg calls.
  112. // THIS MAY NOT BE IMPLEMENTED... REQUIRES MORE THOUGHT BECAUSE YOU CANNOT SOLVE ISSUE FOR RECEIVE
  113. //
  114. BOOLEAN DryRun;
  115. } TCG_CREATE_STRUCT;
  116. //
  117. // Structure that is used to parse the Tcg response received. It contains the response Buffer pointer
  118. // and the current position of the Tcg ComPacket, current Tcg Packet and Tcg SubPacket being parsed.
  119. // This structure must be initialized by calling tcgInitTcgParseStruct before it is used as parameter to any other Tcg parse function.
  120. // This structure should NOT be directly modified by the client of this library.
  121. //
  122. // NOTE: WE MAY MAKE THIS AN ABSTRACT STRUCTURE WITH A DEFINED SIZE AND KEEP THE VARIABLES
  123. // INTERNAL AND ONLY KNOWN TO THE TCG LIBRARY
  124. //
  125. // @sa tcgInitTcgParseStruct
  126. //
  127. typedef struct {
  128. //
  129. // Buffer allocated and freed by the client of the Tcg library.
  130. // This is the Buffer that contains the Tcg response to decode/parse.
  131. //
  132. const VOID* Buffer;
  133. //
  134. //Size of the Buffer provided.
  135. //
  136. UINT32 BufferSize;
  137. //
  138. // Pointer to the start of the Tcg ComPacket. It should point to a location within Buffer.
  139. //
  140. TCG_COM_PACKET *ComPacket;
  141. //
  142. // Current Tcg Packet that is being created. It should point to a location within Buffer.
  143. //
  144. TCG_PACKET *CurPacket;
  145. //
  146. // Current Tcg SubPacket that is being created. It should point to a location within Buffer.
  147. //
  148. TCG_SUB_PACKET *CurSubPacket;
  149. //
  150. // Current pointer within the current subpacket payload.
  151. //
  152. UINT8 *CurPtr;
  153. } TCG_PARSE_STRUCT ;
  154. //
  155. // Structure that is used to represent a Tcg Token that is retrieved by Tcg parse functions.
  156. //
  157. typedef struct {
  158. //
  159. // Describes the type of Tcg token the Hdr start points to.
  160. //
  161. TCG_TOKEN_TYPE Type;
  162. //
  163. // Pointer to the beginning of the Header of the Tcg token
  164. //
  165. UINT8 *HdrStart;
  166. } TCG_TOKEN ;
  167. /**
  168. Required to be called before calling any other Tcg functions with the TCG_CREATE_STRUCT.
  169. Initializes the packet variables to NULL. Additionally, the buffer will be memset.
  170. @param[in/out] CreateStruct Structure to initialize
  171. @param[in] Buffer Buffer allocated by client of library. It will contain the Tcg encoded packet. This cannot be null.
  172. @param[in] BufferSize Size of buffer provided. It cannot be 0.
  173. **/
  174. TCG_RESULT
  175. EFIAPI
  176. TcgInitTcgCreateStruct(
  177. TCG_CREATE_STRUCT *CreateStruct,
  178. VOID *Buffer,
  179. UINT32 BufferSize
  180. );
  181. /**
  182. Encodes the ComPacket header to the data structure.
  183. @param[in/out] CreateStruct Structure to initialize
  184. @param[in] ComId ComID of the Tcg ComPacket.
  185. @param[in] ComIdExtension ComID Extension of the Tcg ComPacket.
  186. **/
  187. TCG_RESULT
  188. EFIAPI
  189. TcgStartComPacket(
  190. TCG_CREATE_STRUCT *CreateStruct,
  191. UINT16 ComId,
  192. UINT16 ComIdExtension
  193. );
  194. /**
  195. Starts a new ComPacket in the Data structure.
  196. @param[in/out] CreateStruct Structure used to add Tcg Packet
  197. @param[in] Tsn Packet Tper session number
  198. @param[in] Hsn Packet Host session number
  199. @param[in] SeqNumber Packet Sequence Number
  200. @param[in] AckType Packet Acknowledge Type
  201. @param[in] Ack Packet Acknowledge
  202. **/
  203. TCG_RESULT
  204. EFIAPI
  205. TcgStartPacket(
  206. TCG_CREATE_STRUCT *CreateStruct,
  207. UINT32 Tsn,
  208. UINT32 Hsn,
  209. UINT32 SeqNumber,
  210. UINT16 AckType,
  211. UINT32 Ack
  212. );
  213. /**
  214. Starts a new SubPacket in the Data structure.
  215. @param[in/out] CreateStruct Structure used to start Tcg SubPacket
  216. @param[in] Kind SubPacket kind
  217. **/
  218. TCG_RESULT
  219. EFIAPI
  220. TcgStartSubPacket(
  221. TCG_CREATE_STRUCT *CreateStruct,
  222. UINT16 Kind
  223. );
  224. /**
  225. Ends the current SubPacket in the Data structure. This function will also perform the 4-byte padding
  226. required for Subpackets.
  227. @param[in/out] CreateStruct Structure used to end the current Tcg SubPacket
  228. **/
  229. TCG_RESULT
  230. EFIAPI
  231. TcgEndSubPacket(
  232. TCG_CREATE_STRUCT *CreateStruct
  233. );
  234. /**
  235. Ends the current Packet in the Data structure.
  236. @param[in/out] CreateStruct Structure used to end the current Tcg Packet
  237. **/
  238. TCG_RESULT
  239. EFIAPI
  240. TcgEndPacket(
  241. TCG_CREATE_STRUCT *CreateStruct
  242. );
  243. /**
  244. Ends the ComPacket in the Data structure and ret
  245. @param[in/out] CreateStruct Structure used to end the Tcg ComPacket
  246. @param[in/out] Size Describes the Size of the entire ComPacket (Header and payload). Filled out by function.
  247. **/
  248. TCG_RESULT
  249. EFIAPI
  250. TcgEndComPacket(
  251. TCG_CREATE_STRUCT *CreateStruct,
  252. UINT32 *Size
  253. );
  254. /**
  255. Adds a single raw token byte to the Data structure.
  256. @param[in/out] CreateStruct Structure used to add the byte
  257. @param [in] Byte Byte to add
  258. **/
  259. TCG_RESULT
  260. EFIAPI
  261. TcgAddRawByte(
  262. TCG_CREATE_STRUCT *CreateStruct,
  263. UINT8 Byte
  264. );
  265. /**
  266. Adds the Data parameter as a byte sequence to the Data structure.
  267. @param [in/out] CreateStruct Structure used to add the byte sequence
  268. @param[in] Data Byte sequence that will be encoded and copied into Data structure
  269. @param[in] DataSize Length of Data provided
  270. @param[in] Continued TRUE if byte sequence is continued or
  271. FALSE if the Data contains the entire byte sequence to be encoded
  272. **/
  273. TCG_RESULT
  274. EFIAPI
  275. TcgAddByteSequence(
  276. TCG_CREATE_STRUCT *CreateStruct,
  277. const VOID *Data,
  278. UINT32 DataSize,
  279. BOOLEAN Continued
  280. );
  281. /**
  282. Adds an arbitrary-Length integer to the Data structure.
  283. The integer will be encoded using the shortest possible atom.
  284. @param[in/out] CreateStruct Structure used to add the integer
  285. @param[in] Data Integer in host byte order that will be encoded and copied into Data structure
  286. @param[in] DataSize Length in bytes of the Data provided
  287. @param[in] SignedInteger TRUE if the integer is signed or FALSE if the integer is unsigned
  288. **/
  289. TCG_RESULT
  290. EFIAPI
  291. TcgAddInteger(
  292. TCG_CREATE_STRUCT *CreateStruct,
  293. const VOID *Data,
  294. UINT32 DataSize,
  295. BOOLEAN SignedInteger
  296. );
  297. /**
  298. Adds an 8-bit unsigned integer to the Data structure.
  299. @param[in/out] CreateStruct Structure used to add the integer
  300. @param[in] Value Integer Value to add
  301. **/
  302. TCG_RESULT
  303. EFIAPI
  304. TcgAddUINT8(
  305. TCG_CREATE_STRUCT *CreateStruct,
  306. UINT8 Value
  307. );
  308. /**
  309. Adds a 16-bit unsigned integer to the Data structure.
  310. @param[in/out] CreateStruct Structure used to add the integer
  311. @param[in] Value Integer Value to add
  312. **/
  313. TCG_RESULT
  314. EFIAPI
  315. TcgAddUINT16 (
  316. TCG_CREATE_STRUCT *CreateStruct,
  317. UINT16 Value
  318. );
  319. /**
  320. Adds a 32-bit unsigned integer to the Data structure.
  321. @param[in/out] CreateStruct Structure used to add the integer
  322. @param[in] Value Integer Value to add
  323. **/
  324. TCG_RESULT
  325. EFIAPI
  326. TcgAddUINT32(
  327. TCG_CREATE_STRUCT *CreateStruct,
  328. UINT32 Value
  329. );
  330. /**
  331. Adds a 64-bit unsigned integer to the Data structure.
  332. @param[in/out] CreateStruct Structure used to add the integer
  333. @param[in] Value Integer Value to add
  334. **/
  335. TCG_RESULT
  336. EFIAPI
  337. TcgAddUINT64(
  338. TCG_CREATE_STRUCT *CreateStruct,
  339. UINT64 Value
  340. );
  341. /**
  342. Adds a BOOLEAN to the Data structure.
  343. @param[in/out] CreateStruct Structure used to add the integer
  344. @param[in] Value BOOLEAN Value to add
  345. **/
  346. TCG_RESULT
  347. EFIAPI
  348. TcgAddBOOLEAN(
  349. TCG_CREATE_STRUCT *CreateStruct,
  350. BOOLEAN Value
  351. );
  352. /**
  353. Add tcg uid info.
  354. @param [in/out] CreateStruct Structure used to add the integer
  355. @param Uid Input uid info.
  356. @retval return the action result.
  357. **/
  358. TCG_RESULT
  359. EFIAPI
  360. TcgAddTcgUid(
  361. TCG_CREATE_STRUCT *CreateStruct,
  362. TCG_UID Uid
  363. );
  364. /**
  365. Adds a Start List token to the Data structure.
  366. @param[in/out] CreateStruct Structure used to add the token
  367. **/
  368. TCG_RESULT
  369. EFIAPI
  370. TcgAddStartList(
  371. TCG_CREATE_STRUCT *CreateStruct
  372. );
  373. /**
  374. Adds an End List token to the Data structure.
  375. @param [in/out] CreateStruct Structure used to add the token
  376. **/
  377. TCG_RESULT
  378. EFIAPI
  379. TcgAddEndList(
  380. TCG_CREATE_STRUCT *CreateStruct
  381. );
  382. /**
  383. Adds a Start Name token to the Data structure.
  384. @param[in/out] CreateStruct Structure used to add the token
  385. **/
  386. TCG_RESULT
  387. EFIAPI
  388. TcgAddStartName(
  389. TCG_CREATE_STRUCT *CreateStruct
  390. );
  391. /**
  392. Adds an End Name token to the Data structure.
  393. @param [in/out] CreateStruct Structure used to add the token
  394. **/
  395. TCG_RESULT
  396. EFIAPI
  397. TcgAddEndName(
  398. TCG_CREATE_STRUCT *CreateStruct
  399. );
  400. /**
  401. Adds a Call token to the Data structure.
  402. @param [in/out] CreateStruct Structure used to add the token
  403. **/
  404. TCG_RESULT
  405. EFIAPI
  406. TcgAddCall(
  407. TCG_CREATE_STRUCT *CreateStruct
  408. );
  409. /**
  410. Adds an End of Data token to the Data structure.
  411. @param[in/out] CreateStruct Structure used to add the token
  412. **/
  413. TCG_RESULT
  414. EFIAPI
  415. TcgAddEndOfData(
  416. TCG_CREATE_STRUCT *CreateStruct
  417. );
  418. /**
  419. Adds an End of Session token to the Data structure.
  420. @param [in/out] CreateStruct Structure used to add the token
  421. **/
  422. TCG_RESULT
  423. EFIAPI
  424. TcgAddEndOfSession(
  425. TCG_CREATE_STRUCT *CreateStruct
  426. );
  427. /**
  428. Adds a Start Transaction token to the Data structure.
  429. @param [in/out] CreateStruct Structure used to add the token
  430. **/
  431. TCG_RESULT
  432. EFIAPI
  433. TcgAddStartTransaction(
  434. TCG_CREATE_STRUCT *CreateStruct
  435. );
  436. /**
  437. Adds an End Transaction token to the Data structure.
  438. @param[in/out] CreateStruct Structure used to add the token
  439. **/
  440. TCG_RESULT
  441. EFIAPI
  442. TcgAddEndTransaction(
  443. TCG_CREATE_STRUCT *CreateStruct
  444. );
  445. /**
  446. Initial the tcg parse stucture.
  447. @param ParseStruct Input parse structure.
  448. @param Buffer Input buffer data.
  449. @param BufferSize Input buffer size.
  450. @retval return the action result.
  451. **/
  452. TCG_RESULT
  453. EFIAPI
  454. TcgInitTcgParseStruct(
  455. TCG_PARSE_STRUCT *ParseStruct,
  456. const VOID *Buffer,
  457. UINT32 BufferSize
  458. );
  459. /**
  460. Get next token info.
  461. @param ParseStruct Input parse structure info.
  462. @param TcgToken return the tcg token info.
  463. @retval return the action result.
  464. **/
  465. TCG_RESULT
  466. EFIAPI
  467. TcgGetNextToken(
  468. TCG_PARSE_STRUCT *ParseStruct,
  469. TCG_TOKEN *TcgToken
  470. );
  471. /**
  472. Get next token Type.
  473. @param ParseStruct Input parse structure.
  474. @param Type Input the type need to check.
  475. @retval return the action result.
  476. **/
  477. TCG_RESULT
  478. EFIAPI
  479. TcgGetNextTokenType(
  480. TCG_PARSE_STRUCT *ParseStruct,
  481. TCG_TOKEN_TYPE Type
  482. );
  483. /**
  484. Get atom info.
  485. @param TcgToken Input token info.
  486. @param HeaderLength return the header length.
  487. @param DataLength return the data length.
  488. @param ByteOrInt return the atom Type.
  489. @param SignOrCont return the sign or count info.
  490. @retval return the action result.
  491. **/
  492. TCG_RESULT
  493. EFIAPI
  494. TcgGetAtomInfo(
  495. const TCG_TOKEN *TcgToken,
  496. UINT32 *HeaderLength,
  497. UINT32 *DataLength,
  498. UINT8 *ByteOrInt,
  499. UINT8 *SignOrCont
  500. );
  501. /**
  502. Get token byte sequence.
  503. @param TcgToken Input token info.
  504. @param Length Input the length info.
  505. @retval Return the value data.
  506. **/
  507. UINT8*
  508. EFIAPI
  509. TcgGetTokenByteSequence(
  510. const TCG_TOKEN *TcgToken,
  511. UINT32 *Length
  512. );
  513. /**
  514. Get token specified value.
  515. @param TcgToken Input token info.
  516. @param Value return the value.
  517. @retval return the action result.
  518. **/
  519. TCG_RESULT
  520. EFIAPI
  521. TcgGetTokenUINT64(
  522. const TCG_TOKEN *TcgToken,
  523. UINT64 *Value
  524. );
  525. /**
  526. Get next specify value.
  527. @param ParseStruct Input parse structure.
  528. @param Value Return value.
  529. @retval return the action result.
  530. **/
  531. TCG_RESULT
  532. EFIAPI
  533. TcgGetNextUINT8(
  534. TCG_PARSE_STRUCT *ParseStruct,
  535. UINT8 *Value
  536. );
  537. /**
  538. Get next specify value.
  539. @param ParseStruct Input parse structure.
  540. @param Value Return value.
  541. @retval return the action result.
  542. **/
  543. TCG_RESULT
  544. EFIAPI
  545. TcgGetNextUINT16(
  546. TCG_PARSE_STRUCT *ParseStruct,
  547. UINT16 *Value
  548. );
  549. /**
  550. Get next specify value.
  551. @param ParseStruct Input parse structure.
  552. @param Value Return value.
  553. @retval return the action result.
  554. **/
  555. TCG_RESULT
  556. EFIAPI
  557. TcgGetNextUINT32(
  558. TCG_PARSE_STRUCT *ParseStruct,
  559. UINT32 *Value
  560. );
  561. /**
  562. Get next specify value.
  563. @param ParseStruct Input parse structure.
  564. @param Value Return value.
  565. @retval return the action result.
  566. **/
  567. TCG_RESULT
  568. EFIAPI
  569. TcgGetNextUINT64(
  570. TCG_PARSE_STRUCT *ParseStruct,
  571. UINT64 *Value
  572. );
  573. /**
  574. Get next specify value.
  575. @param ParseStruct Input parse structure.
  576. @param Value Return value.
  577. @retval return the action result.
  578. **/
  579. TCG_RESULT
  580. EFIAPI
  581. TcgGetNextBOOLEAN(
  582. TCG_PARSE_STRUCT *ParseStruct,
  583. BOOLEAN *Value
  584. );
  585. /**
  586. Get next tcg uid info.
  587. @param ParseStruct Input parse structure.
  588. @param Uid Get the uid info.
  589. @retval return the action result.
  590. **/
  591. TCG_RESULT
  592. EFIAPI
  593. TcgGetNextTcgUid(
  594. TCG_PARSE_STRUCT *ParseStruct,
  595. TCG_UID *Uid
  596. );
  597. /**
  598. Get next byte sequence.
  599. @param ParseStruct Input parse structure.
  600. @param Data return the data.
  601. @param Length return the length.
  602. @retval return the action result.
  603. **/
  604. TCG_RESULT
  605. EFIAPI
  606. TcgGetNextByteSequence(
  607. TCG_PARSE_STRUCT *ParseStruct,
  608. const VOID **Data,
  609. UINT32 *Length
  610. );
  611. /**
  612. Get next start list.
  613. @param ParseStruct Input parse structure.
  614. @retval return the action result.
  615. **/
  616. TCG_RESULT
  617. EFIAPI
  618. TcgGetNextStartList(
  619. TCG_PARSE_STRUCT *ParseStruct
  620. );
  621. /**
  622. Get next end list.
  623. @param ParseStruct Input parse structure.
  624. @retval return the action result.
  625. **/
  626. TCG_RESULT
  627. EFIAPI
  628. TcgGetNextEndList(
  629. TCG_PARSE_STRUCT *ParseStruct
  630. );
  631. /**
  632. Get next start name.
  633. @param ParseStruct Input parse structure.
  634. @retval return the action result.
  635. **/
  636. TCG_RESULT
  637. EFIAPI
  638. TcgGetNextStartName(
  639. TCG_PARSE_STRUCT *ParseStruct
  640. );
  641. /**
  642. Get next end name.
  643. @param ParseStruct Input parse structure.
  644. @retval return the action result.
  645. **/
  646. TCG_RESULT
  647. EFIAPI
  648. TcgGetNextEndName(
  649. TCG_PARSE_STRUCT *ParseStruct
  650. );
  651. /**
  652. Get next call.
  653. @param ParseStruct Input parse structure.
  654. @retval return the action result.
  655. **/
  656. TCG_RESULT
  657. EFIAPI
  658. TcgGetNextCall(
  659. TCG_PARSE_STRUCT *ParseStruct
  660. );
  661. /**
  662. Get next end data.
  663. @param ParseStruct Input parse structure.
  664. @retval return the action result.
  665. **/
  666. TCG_RESULT
  667. EFIAPI
  668. TcgGetNextEndOfData(
  669. TCG_PARSE_STRUCT *ParseStruct
  670. );
  671. /**
  672. Get next end of session.
  673. @param ParseStruct Input parse structure.
  674. @retval return the action result.
  675. **/
  676. TCG_RESULT
  677. EFIAPI
  678. TcgGetNextEndOfSession(
  679. TCG_PARSE_STRUCT *ParseStruct
  680. );
  681. /**
  682. Get next start transaction.
  683. @param ParseStruct Input parse structure.
  684. @retval return the action result.
  685. **/
  686. TCG_RESULT
  687. EFIAPI
  688. TcgGetNextStartTransaction(
  689. TCG_PARSE_STRUCT *ParseStruct
  690. );
  691. /**
  692. Get next end transaction.
  693. @param ParseStruct Input parse structure.
  694. @retval return the action result.
  695. **/
  696. TCG_RESULT
  697. EFIAPI
  698. TcgGetNextEndTransaction(
  699. TCG_PARSE_STRUCT *ParseStruct
  700. );
  701. // end of parse functions
  702. typedef
  703. BOOLEAN
  704. (EFIAPI* TCG_LEVEL0_ENUM_CALLBACK) (
  705. const TCG_LEVEL0_DISCOVERY_HEADER *DiscoveryHeader,
  706. TCG_LEVEL0_FEATURE_DESCRIPTOR_HEADER *Feature,
  707. UINTN FeatureSize, // includes header
  708. VOID *Context
  709. );
  710. /**
  711. Adds call token and method Header (invoking id, and method id).
  712. @param CreateStruct The input create structure.
  713. @param InvokingId Invoking id.
  714. @param MethodId Method id.
  715. **/
  716. TCG_RESULT
  717. EFIAPI
  718. TcgStartMethodCall(
  719. TCG_CREATE_STRUCT *CreateStruct,
  720. TCG_UID InvokingId,
  721. TCG_UID MethodId
  722. );
  723. /**
  724. Adds START LIST token.
  725. @param CreateStruct The input create structure.
  726. **/
  727. TCG_RESULT
  728. EFIAPI
  729. TcgStartParameters(
  730. TCG_CREATE_STRUCT *CreateStruct
  731. );
  732. /**
  733. Adds END LIST token.
  734. @param CreateStruct The input create structure.
  735. **/
  736. TCG_RESULT
  737. EFIAPI
  738. TcgEndParameters(
  739. TCG_CREATE_STRUCT *CreateStruct
  740. );
  741. /**
  742. Adds END Data token and method list.
  743. @param CreateStruct The input create structure.
  744. **/
  745. TCG_RESULT
  746. EFIAPI
  747. TcgEndMethodCall(
  748. TCG_CREATE_STRUCT *CreateStruct
  749. );
  750. /**
  751. Adds Start Session call to the data structure. This creates the entire ComPacket structure and
  752. returns the size of the entire compacket in the size parameter.
  753. @param [in/out] CreateStruct Structure used to add the start session call
  754. @param [in/out] Size Describes the size of the entire ComPacket (header and payload). Filled out by function.
  755. @param [in] ComId ComID for the ComPacket
  756. @param [in] ComIdExtension Extended ComID for the ComPacket
  757. @param [in] HostSessionId Host Session ID
  758. @param [in] SpId Security Provider to start session with
  759. @param [in] Write Write option for start session. TRUE = start session requests write access
  760. @param [in] HostChallengeLength Length of the host challenge. Length should be 0 if hostChallenge is NULL
  761. @param [in] HostChallenge Host challenge for Host Signing Authority. If NULL, then no Host Challenge shall be sent.
  762. @param [in] HostSigningAuthority Host Signing Authority used for start session. If NULL, then no Host Signing Authority shall be sent.
  763. **/
  764. TCG_RESULT
  765. EFIAPI
  766. TcgCreateStartSession(
  767. TCG_CREATE_STRUCT *CreateStruct,
  768. UINT32 *Size,
  769. UINT16 ComId,
  770. UINT16 ComIdExtension,
  771. UINT32 HostSessionId,
  772. TCG_UID SpId,
  773. BOOLEAN Write,
  774. UINT32 HostChallengeLength,
  775. const VOID *HostChallenge,
  776. TCG_UID HostSigningAuthority
  777. );
  778. /**
  779. Creates ComPacket with a Method call that sets the PIN column for the row specified.
  780. This assumes a start session has already been opened with the desired SP.
  781. @param [in/out] CreateStruct Structure used to add method call.
  782. @param [in/out] Size Describes the size of the entire ComPacket (header and payload). Filled out by function.
  783. @param [in] ComId ComID for the ComPacket
  784. @param [in] ComIdExtension Extended ComID for the ComPacket
  785. @param [in] TperSession Tper Session ID for the Packet
  786. @param [in] HostSession Host Session ID for the Packet
  787. @param [in] SidRow UID of row of current SP to set PIN column
  788. @param [in] Password value of PIN to set
  789. @param [in] PasswordSize Size of PIN
  790. **/
  791. TCG_RESULT
  792. EFIAPI
  793. TcgCreateSetCPin(
  794. TCG_CREATE_STRUCT *CreateStruct,
  795. UINT32 *Size,
  796. UINT16 ComId,
  797. UINT16 ComIdExtension,
  798. UINT32 TperSession,
  799. UINT32 HostSession,
  800. TCG_UID SidRow,
  801. const VOID *Password,
  802. UINT32 PasswordSize
  803. );
  804. /**
  805. Creates ComPacket with a Method call that sets the "Enabled" column for the row specified using the value specified.
  806. This assumes a start session has already been opened with the desired SP.
  807. @param [in/out] CreateStruct Structure used to add method call
  808. @param [in/out] Size Describes the size of the entire ComPacket (header and payload). Filled out by function.
  809. @param [in] ComId ComID for the ComPacket
  810. @param [in] ComIdExtension Extended ComID for the ComPacket
  811. @param [in] TperSession Tper Session ID for the Packet
  812. @param [in] HostSession Host Session ID for the Packet
  813. @param [in] AuthorityUid Authority UID to modify the "Enabled" column for
  814. @param [in] Enabled Value to set the "Enabled" column to
  815. **/
  816. TCG_RESULT
  817. EFIAPI
  818. TcgSetAuthorityEnabled(
  819. TCG_CREATE_STRUCT *CreateStruct,
  820. UINT32 *Size,
  821. UINT16 ComId,
  822. UINT16 ComIdExtension,
  823. UINT32 TperSession,
  824. UINT32 HostSession,
  825. TCG_UID AuthorityUid,
  826. BOOLEAN Enabled
  827. );
  828. /**
  829. Creates ComPacket with EndSession.
  830. This assumes a start session has already been opened.
  831. @param [in/out] CreateStruct Structure used to add Endsession
  832. @param [in/out] Size Describes the size of the entire ComPacket (header and payload). Filled out by function.
  833. @param [in] ComId ComID for the ComPacket
  834. @param [in] ComIdExtension Extended ComID for the ComPacket
  835. @param [in] HostSessionId Host Session ID for the Packet
  836. @param [in] TpSessionId Tper Session ID for the Packet
  837. **/
  838. TCG_RESULT
  839. EFIAPI
  840. TcgCreateEndSession(
  841. TCG_CREATE_STRUCT *CreateStruct,
  842. UINT32 *Size,
  843. UINT16 ComId,
  844. UINT16 ComIdExtension,
  845. UINT32 HostSessionId,
  846. UINT32 TpSessionId
  847. );
  848. /**
  849. Retrieves human-readable token type name.
  850. @param[in] Type Token type to retrieve
  851. **/
  852. CHAR8*
  853. EFIAPI
  854. TcgTokenTypeString(
  855. TCG_TOKEN_TYPE Type
  856. );
  857. /**
  858. Returns the method status of the current subpacket. Does not affect the current position
  859. in the ComPacket. In other words, it can be called whenever you have a valid SubPacket.
  860. @param [in/out] ParseStruct Structure used to parse received TCG response
  861. @param [in/out] MethodStatus Method status retrieved of the current SubPacket
  862. **/
  863. TCG_RESULT
  864. EFIAPI
  865. TcgGetMethodStatus(
  866. const TCG_PARSE_STRUCT *ParseStruct,
  867. UINT8 *MethodStatus
  868. );
  869. /**
  870. Returns a human-readable string representing a method status return code.
  871. @param[in] MethodStatus Method status to translate to a string
  872. @retval return the string info.
  873. **/
  874. CHAR8*
  875. EFIAPI
  876. TcgMethodStatusString(
  877. UINT8 MethodStatus
  878. );
  879. /**
  880. Retrieves the comID and Extended comID of the ComPacket in the Tcg response.
  881. It is intended to be used to confirm the received Tcg response is intended for user that received it.
  882. @param [in] ParseStruct Structure used to parse received TCG response.
  883. @param [in/out] ComId comID retrieved from received ComPacket.
  884. @param [in/out] ComIdExtension Extended comID retrieved from received ComPacket
  885. **/
  886. TCG_RESULT
  887. EFIAPI
  888. TcgGetComIds(
  889. const TCG_PARSE_STRUCT *ParseStruct,
  890. UINT16 *ComId,
  891. UINT16 *ComIdExtension
  892. );
  893. /**
  894. Checks if the ComIDs of the response match the expected values.
  895. @param[in] ParseStruct Structure used to parse received TCG response
  896. @param[in] ExpectedComId Expected comID
  897. @param[in] ExpectedComIdExtension Expected extended comID
  898. **/
  899. TCG_RESULT
  900. EFIAPI
  901. TcgCheckComIds(
  902. const TCG_PARSE_STRUCT *ParseStruct,
  903. UINT16 ExpectedComId,
  904. UINT16 ExpectedComIdExtension
  905. );
  906. /**
  907. Parses the Sync Session response contained in the parseStruct to retrieve Tper session ID. If the Sync Session response
  908. parameters do not match the comID, extended ComID and host session ID then a failure is returned.
  909. @param[in/out] ParseStruct Structure used to parse received TCG response, contains Sync Session response.
  910. @param[in] ComId Expected ComID that is compared to actual ComID of response
  911. @param[in] ComIdExtension Expected Extended ComID that is compared to actual Extended ComID of response
  912. @param[in] HostSessionId Expected Host Session ID that is compared to actual Host Session ID of response
  913. @param[in/out] TperSessionId Tper Session ID retrieved from the Sync Session response.
  914. **/
  915. TCG_RESULT
  916. EFIAPI
  917. TcgParseSyncSession(
  918. const TCG_PARSE_STRUCT *ParseStruct,
  919. UINT16 ComId,
  920. UINT16 ComIdExtension,
  921. UINT32 HostSessionId,
  922. UINT32 *TperSessionId
  923. );
  924. /**
  925. Create set ace.
  926. @param CreateStruct Input create structure.
  927. @param Size size info.
  928. @param ComId ComId info.
  929. @param ComIdExtension ComId extension info.
  930. @param TperSession Tper session data.
  931. @param HostSession Host session data.
  932. @param AceRow Ace row info.
  933. @param Authority1 Authority 1 info.
  934. @param LogicalOperator Logiccal operator info.
  935. @param Authority2 Authority 2 info.
  936. @retval Return the action result.
  937. **/
  938. TCG_RESULT
  939. EFIAPI
  940. TcgCreateSetAce(
  941. TCG_CREATE_STRUCT *CreateStruct,
  942. UINT32 *Size,
  943. UINT16 ComId,
  944. UINT16 ComIdExtension,
  945. UINT32 TperSession,
  946. UINT32 HostSession,
  947. TCG_UID AceRow,
  948. TCG_UID Authority1,
  949. BOOLEAN LogicalOperator,
  950. TCG_UID Authority2
  951. );
  952. /**
  953. Enum level 0 discovery.
  954. @param DiscoveryHeader Discovery header.
  955. @param Callback Callback function.
  956. @param Context The context for the function.
  957. @retval return true if the callback return TRUE, else return FALSE.
  958. **/
  959. BOOLEAN
  960. EFIAPI
  961. TcgEnumLevel0Discovery(
  962. const TCG_LEVEL0_DISCOVERY_HEADER *DiscoveryHeader,
  963. TCG_LEVEL0_ENUM_CALLBACK Callback,
  964. VOID *Context
  965. );
  966. /**
  967. Get Feature code from the header.
  968. @param DiscoveryHeader The discovery header.
  969. @param FeatureCode return the Feature code.
  970. @param FeatureSize return the Feature size.
  971. @retval return the Feature code data.
  972. **/
  973. TCG_LEVEL0_FEATURE_DESCRIPTOR_HEADER*
  974. EFIAPI
  975. TcgGetFeature(
  976. const TCG_LEVEL0_DISCOVERY_HEADER *DiscoveryHeader,
  977. UINT16 FeatureCode,
  978. UINTN *FeatureSize
  979. );
  980. /**
  981. Determines if the protocol provided is part of the provided supported protocol list.
  982. @param[in] ProtocolList Supported protocol list to investigate
  983. @param[in] Protocol Protocol value to determine if supported
  984. @return TRUE = protocol is supported, FALSE = protocol is not supported
  985. **/
  986. BOOLEAN
  987. EFIAPI
  988. TcgIsProtocolSupported(
  989. const TCG_SUPPORTED_SECURITY_PROTOCOLS *ProtocolList,
  990. UINT16 Protocol
  991. );
  992. /**
  993. Determines if the Locking Feature "Locked" bit is set in the level 0 discovery response.
  994. @param[in] Discovery Level 0 discovery response
  995. @return TRUE = Locked is set, FALSE = Locked is false
  996. **/
  997. BOOLEAN
  998. EFIAPI
  999. TcgIsLocked(
  1000. const TCG_LEVEL0_DISCOVERY_HEADER *Discovery
  1001. );
  1002. #pragma pack()
  1003. #endif // _TCG_CORE_H_