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