LCOV - code coverage report
Current view: top level - unit_test/test_spdm_responder - capabilities.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 376 376
Test Date: 2025-10-12 08:10:56 Functions: 100.0 % 28 28

            Line data    Source code
       1              : /**
       2              :  *  Copyright Notice:
       3              :  *  Copyright 2021-2025 DMTF. All rights reserved.
       4              :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
       5              :  **/
       6              : 
       7              : #include "spdm_unit_test.h"
       8              : #include "internal/libspdm_responder_lib.h"
       9              : 
      10              : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request1 = {
      11              :     {
      12              :         SPDM_MESSAGE_VERSION_10,
      13              :         SPDM_GET_CAPABILITIES,
      14              :     },
      15              : };
      16              : /* version 1.0 message consists of only header (size 0x04).
      17              :  * However, spdm_get_capabilities_request_t has a size of 0x0c.
      18              :  * Therefore, sending a v1.0 request with this structure results in a wrong size request.
      19              :  * size information was corrected to reflect the actual size of a get_capabilities 1.0 message.*/
      20              : size_t m_libspdm_get_capabilities_request1_size = sizeof(spdm_message_header_t);
      21              : 
      22              : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request2 = {
      23              :     {
      24              :         SPDM_MESSAGE_VERSION_10,
      25              :         SPDM_GET_CAPABILITIES,
      26              :     },
      27              : };
      28              : size_t m_libspdm_get_capabilities_request2_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
      29              : 
      30              : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request4 = {
      31              :     {
      32              :         SPDM_MESSAGE_VERSION_11,
      33              :         SPDM_GET_CAPABILITIES,
      34              :     }, /*header*/
      35              :     0x00, /*reserved*/
      36              :     0x01, /*ct_exponent*/
      37              :     0x0000, /*reserved, 2 bytes*/
      38              :     (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | /*flags*/
      39              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
      40              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP |
      41              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP |
      42              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
      43              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
      44              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER |
      45              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP |
      46              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP |
      47              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP |
      48              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
      49              : };
      50              : size_t m_libspdm_get_capabilities_request4_size =
      51              :     sizeof(m_libspdm_get_capabilities_request4) -
      52              :     sizeof(m_libspdm_get_capabilities_request4.data_transfer_size) -
      53              :     sizeof(m_libspdm_get_capabilities_request4.max_spdm_msg_size);
      54              : 
      55              : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request5 = {
      56              :     {
      57              :         SPDM_MESSAGE_VERSION_11,
      58              :         SPDM_GET_CAPABILITIES,
      59              :     }, /*header*/
      60              :     0x00, /*reserved*/
      61              :     0x01, /*ct_exponent*/
      62              :     0x0000, /*reserved, 2 bytes*/
      63              :     (0x01 | SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | /*flags*/
      64              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
      65              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP |
      66              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP |
      67              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
      68              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
      69              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER |
      70              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP |
      71              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP |
      72              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP |
      73              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
      74              : };
      75              : size_t m_libspdm_get_capabilities_request5_size =
      76              :     sizeof(m_libspdm_get_capabilities_request5) -
      77              :     sizeof(m_libspdm_get_capabilities_request5.data_transfer_size) -
      78              :     sizeof(m_libspdm_get_capabilities_request5.max_spdm_msg_size);
      79              : 
      80              : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request6 = {
      81              :     {
      82              :         SPDM_MESSAGE_VERSION_11,
      83              :         SPDM_GET_CAPABILITIES,
      84              :     }, /*header*/
      85              :     0x00, /*reserved*/
      86              :     0x01, /*ct_exponent*/
      87              :     0x0000, /*reserved, 2 bytes*/
      88              :     (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG |
      89              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | /*flags*/
      90              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
      91              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP |
      92              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP |
      93              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
      94              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
      95              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER |
      96              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP |
      97              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP |
      98              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP |
      99              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
     100              : };
     101              : size_t m_libspdm_get_capabilities_request6_size =
     102              :     sizeof(m_libspdm_get_capabilities_request6) -
     103              :     sizeof(m_libspdm_get_capabilities_request6.data_transfer_size) -
     104              :     sizeof(m_libspdm_get_capabilities_request6.max_spdm_msg_size);
     105              : 
     106              : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request7 = {
     107              :     {
     108              :         SPDM_MESSAGE_VERSION_11,
     109              :         SPDM_GET_CAPABILITIES,
     110              :     }, /*header*/
     111              :     0x00, /*reserved*/
     112              :     LIBSPDM_MAX_CT_EXPONENT + 1, /*Illegal ct_exponent*/
     113              :     0x0000, /*reserved, 2 bytes*/
     114              :     (0x100000 | SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | /*flags*/
     115              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
     116              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP |
     117              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP |
     118              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
     119              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
     120              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER |
     121              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP |
     122              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP |
     123              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP |
     124              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
     125              : };
     126              : size_t m_libspdm_get_capabilities_request7_size =
     127              :     sizeof(m_libspdm_get_capabilities_request7) -
     128              :     sizeof(m_libspdm_get_capabilities_request7.data_transfer_size) -
     129              :     sizeof(m_libspdm_get_capabilities_request7.max_spdm_msg_size);
     130              : 
     131              : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request8 = {
     132              :     {
     133              :         SPDM_MESSAGE_VERSION_11,
     134              :         SPDM_GET_CAPABILITIES,
     135              :     }, /*header*/
     136              :     0x00, /*reserved*/
     137              :     0x01, /*ct_exponent*/
     138              :     0x0000, /*reserved, 2 bytes*/
     139              :     (0x100000 | SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | /*flags*/
     140              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
     141              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP |
     142              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP |
     143              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
     144              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
     145              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER |
     146              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP |
     147              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP |
     148              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP |
     149              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
     150              : };
     151              : size_t m_libspdm_get_capabilities_request8_size =
     152              :     sizeof(m_libspdm_get_capabilities_request8) -
     153              :     sizeof(m_libspdm_get_capabilities_request8.data_transfer_size) -
     154              :     sizeof(m_libspdm_get_capabilities_request8.max_spdm_msg_size);
     155              : 
     156              : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request9 = {
     157              :     {
     158              :         SPDM_MESSAGE_VERSION_11,
     159              :         SPDM_GET_CAPABILITIES,
     160              :     }, /*header*/
     161              :     0x00, /*reserved*/
     162              :     0x01, /*ct_exponent*/
     163              :     0x0000, /*reserved, 2 bytes*/
     164              :     (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PUB_KEY_ID_CAP |
     165              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | /*flags*/
     166              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
     167              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP |
     168              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP |
     169              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
     170              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
     171              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER |
     172              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP |
     173              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP |
     174              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP |
     175              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
     176              : };
     177              : size_t m_libspdm_get_capabilities_request9_size =
     178              :     sizeof(m_libspdm_get_capabilities_request9) -
     179              :     sizeof(m_libspdm_get_capabilities_request9.data_transfer_size) -
     180              :     sizeof(m_libspdm_get_capabilities_request9.max_spdm_msg_size);
     181              : 
     182              : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request10 = {
     183              :     {
     184              :         SPDM_MESSAGE_VERSION_11,
     185              :         SPDM_GET_CAPABILITIES,
     186              :     }, /*header*/
     187              :     0x00, /*reserved*/
     188              :     0x01, /*ct_exponent*/
     189              :     0x0000, /*reserved, 2 bytes*/
     190              :     (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | /*flags*/
     191              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
     192              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP |
     193              : 
     194              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
     195              : 
     196              : 
     197              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP |
     198              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP |
     199              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP |
     200              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
     201              : };
     202              : size_t m_libspdm_get_capabilities_request10_size =
     203              :     sizeof(m_libspdm_get_capabilities_request10) -
     204              :     sizeof(m_libspdm_get_capabilities_request10.data_transfer_size) -
     205              :     sizeof(m_libspdm_get_capabilities_request10.max_spdm_msg_size);
     206              : 
     207              : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request11 = {
     208              :     {
     209              :         SPDM_MESSAGE_VERSION_11,
     210              :         SPDM_GET_CAPABILITIES,
     211              :     }, /*header*/
     212              :     0x00, /*reserved*/
     213              :     0x01, /*ct_exponent*/
     214              :     0x0000, /*reserved, 2 bytes*/
     215              :     (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | /*flags*/
     216              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
     217              : 
     218              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP |
     219              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
     220              : 
     221              : 
     222              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP |
     223              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP |
     224              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP |
     225              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
     226              : };
     227              : size_t m_libspdm_get_capabilities_request11_size =
     228              :     sizeof(m_libspdm_get_capabilities_request11) -
     229              :     sizeof(m_libspdm_get_capabilities_request11.data_transfer_size) -
     230              :     sizeof(m_libspdm_get_capabilities_request11.max_spdm_msg_size);
     231              : 
     232              : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request12 = {
     233              :     {
     234              :         SPDM_MESSAGE_VERSION_11,
     235              :         SPDM_GET_CAPABILITIES,
     236              :     }, /*header*/
     237              :     0x00, /*reserved*/
     238              :     0x01, /*ct_exponent*/
     239              :     0x0000, /*reserved, 2 bytes*/
     240              :     (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | /*flags*/
     241              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
     242              : 
     243              : 
     244              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
     245              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
     246              : 
     247              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP |
     248              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP |
     249              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP
     250              : 
     251              :     )
     252              : };
     253              : size_t m_libspdm_get_capabilities_request12_size =
     254              :     sizeof(m_libspdm_get_capabilities_request12) -
     255              :     sizeof(m_libspdm_get_capabilities_request12.data_transfer_size) -
     256              :     sizeof(m_libspdm_get_capabilities_request12.max_spdm_msg_size);
     257              : 
     258              : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request13 = {
     259              :     {
     260              :         SPDM_MESSAGE_VERSION_11,
     261              :         SPDM_GET_CAPABILITIES,
     262              :     }, /*header*/
     263              :     0x00, /*reserved*/
     264              :     0x01, /*ct_exponent*/
     265              :     0x0000, /*reserved, 2 bytes*/
     266              :     (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | /*flags*/
     267              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
     268              : 
     269              : 
     270              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
     271              : 
     272              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER |
     273              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP |
     274              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP |
     275              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP
     276              : 
     277              :     )
     278              : };
     279              : size_t m_libspdm_get_capabilities_request13_size =
     280              :     sizeof(m_libspdm_get_capabilities_request13) -
     281              :     sizeof(m_libspdm_get_capabilities_request13.data_transfer_size) -
     282              :     sizeof(m_libspdm_get_capabilities_request13.max_spdm_msg_size);
     283              : 
     284              : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request14 = {
     285              :     {
     286              :         SPDM_MESSAGE_VERSION_11,
     287              :         SPDM_GET_CAPABILITIES,
     288              :     }, /*header*/
     289              :     0x00, /*reserved*/
     290              :     0x01, /*ct_exponent*/
     291              :     0x0000, /*reserved, 2 bytes*/
     292              :     (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | /*flags*/
     293              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
     294              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP |
     295              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP |
     296              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
     297              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
     298              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER |
     299              : 
     300              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP |
     301              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP |
     302              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
     303              : };
     304              : size_t m_libspdm_get_capabilities_request14_size =
     305              :     sizeof(m_libspdm_get_capabilities_request14) -
     306              :     sizeof(m_libspdm_get_capabilities_request14.data_transfer_size) -
     307              :     sizeof(m_libspdm_get_capabilities_request14.max_spdm_msg_size);
     308              : 
     309              : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request15 = {
     310              :     {
     311              :         SPDM_MESSAGE_VERSION_11,
     312              :         SPDM_GET_CAPABILITIES,
     313              :     }, /*header*/
     314              :     0x00, /*reserved*/
     315              :     0x01, /*ct_exponent*/
     316              :     0x0000, /*reserved, 2 bytes*/
     317              :     (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | /*flags*/
     318              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
     319              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP |
     320              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP |
     321              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
     322              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
     323              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER |
     324              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP |
     325              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP |
     326              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP |
     327              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP |
     328              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PUB_KEY_ID_CAP)
     329              : };
     330              : size_t m_libspdm_get_capabilities_request15_size =
     331              :     sizeof(m_libspdm_get_capabilities_request15) -
     332              :     sizeof(m_libspdm_get_capabilities_request15.data_transfer_size) -
     333              :     sizeof(m_libspdm_get_capabilities_request15.max_spdm_msg_size);
     334              : 
     335              : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request16 = {
     336              :     {
     337              :         SPDM_MESSAGE_VERSION_11,
     338              :         SPDM_GET_CAPABILITIES,
     339              :     }, /*header*/
     340              :     0x00, /*reserved*/
     341              :     0x01, /*ct_exponent*/
     342              :     0x0000, /*reserved, 2 bytes*/
     343              :     (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | /*flags*/
     344              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
     345              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP |
     346              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP |
     347              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
     348              : 
     349              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER |
     350              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP |
     351              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP |
     352              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP |
     353              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
     354              : };
     355              : size_t m_libspdm_get_capabilities_request16_size =
     356              :     sizeof(m_libspdm_get_capabilities_request16) -
     357              :     sizeof(m_libspdm_get_capabilities_request16.data_transfer_size) -
     358              :     sizeof(m_libspdm_get_capabilities_request16.max_spdm_msg_size);
     359              : 
     360              : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request17 = {
     361              :     {
     362              :         SPDM_MESSAGE_VERSION_11,
     363              :         SPDM_GET_CAPABILITIES,
     364              :     }, /*header*/
     365              :     0x00, /*reserved*/
     366              :     0x01, /*ct_exponent*/
     367              :     0x0000, /*reserved, 2 bytes*/
     368              :     (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | /*flags*/
     369              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
     370              : 
     371              : 
     372              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
     373              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
     374              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER |
     375              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP |
     376              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP |
     377              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP |
     378              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
     379              : };
     380              : size_t m_libspdm_get_capabilities_request17_size =
     381              :     sizeof(m_libspdm_get_capabilities_request17) -
     382              :     sizeof(m_libspdm_get_capabilities_request17.data_transfer_size) -
     383              :     sizeof(m_libspdm_get_capabilities_request17.max_spdm_msg_size);
     384              : 
     385              : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request18 = {
     386              :     {
     387              :         SPDM_MESSAGE_VERSION_11,
     388              :         SPDM_GET_CAPABILITIES,
     389              :     }, /*header*/
     390              :     0x00, /*reserved*/
     391              :     0x01, /*ct_exponent*/
     392              :     0x0000, /*reserved, 2 bytes*/
     393              :     ( /*flags*/
     394              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
     395              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP |
     396              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP |
     397              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
     398              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
     399              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER |
     400              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP |
     401              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP |
     402              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP |
     403              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP |
     404              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PUB_KEY_ID_CAP)
     405              : };
     406              : size_t m_libspdm_get_capabilities_request18_size =
     407              :     sizeof(m_libspdm_get_capabilities_request18) -
     408              :     sizeof(m_libspdm_get_capabilities_request18.data_transfer_size) -
     409              :     sizeof(m_libspdm_get_capabilities_request18.max_spdm_msg_size);
     410              : 
     411              : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request19 = {
     412              :     {
     413              :         SPDM_MESSAGE_VERSION_12,
     414              :         SPDM_GET_CAPABILITIES,
     415              :     }, /*header*/
     416              :     0x00, /*reserved*/
     417              :     0x01, /*ct_exponent*/
     418              :     0x0000, /*reserved, 2 bytes*/
     419              :     (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP|
     420              :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ALIAS_CERT_CAP),
     421              :     LIBSPDM_DATA_TRANSFER_SIZE,
     422              :     LIBSPDM_MAX_SPDM_MSG_SIZE,
     423              : };
     424              : size_t m_libspdm_get_capabilities_request19_size = sizeof(m_libspdm_get_capabilities_request19);
     425              : 
     426              : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request25 = {
     427              :     {
     428              :         SPDM_MESSAGE_VERSION_12,
     429              :         SPDM_GET_CAPABILITIES,
     430              :     }, /*header*/
     431              :     0x00, /*reserved*/
     432              :     0x01, /*ct_exponent*/
     433              :     0x0000, /*reserved, 2 bytes*/
     434              :     0,
     435              :     LIBSPDM_DATA_TRANSFER_SIZE - 1,
     436              :     LIBSPDM_MAX_SPDM_MSG_SIZE,
     437              : };
     438              : size_t m_libspdm_get_capabilities_request25_size = sizeof(m_libspdm_get_capabilities_request25);
     439              : 
     440              : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request26 = {
     441              :     {
     442              :         SPDM_MESSAGE_VERSION_12,
     443              :         SPDM_GET_CAPABILITIES,
     444              :     }, /*header*/
     445              :     0x00, /*reserved*/
     446              :     0x01, /*ct_exponent*/
     447              :     0x0000, /*reserved, 2 bytes*/
     448              :     (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP|
     449              :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ALIAS_CERT_CAP),
     450              :     LIBSPDM_DATA_TRANSFER_SIZE,
     451              :     LIBSPDM_DATA_TRANSFER_SIZE - 1,
     452              : };
     453              : size_t m_libspdm_get_capabilities_request26_size = sizeof(m_libspdm_get_capabilities_request26);
     454              : 
     455              : 
     456              : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request27 = {
     457              :     {
     458              :         SPDM_MESSAGE_VERSION_13,
     459              :         SPDM_GET_CAPABILITIES,
     460              :     },
     461              :     0x00, /*reserved*/
     462              :     0x01, /*ct_exponent*/
     463              :     0x0000, /*reserved, 2 bytes*/
     464              :     SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP |
     465              :     SPDM_GET_CAPABILITIES_REQUEST_FLAGS_EP_INFO_CAP_SIG |
     466              :     SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MULTI_KEY_CAP_ONLY,
     467              :     LIBSPDM_DATA_TRANSFER_SIZE,
     468              :     LIBSPDM_MAX_SPDM_MSG_SIZE,
     469              : };
     470              : size_t m_libspdm_get_capabilities_request27_size = sizeof(m_libspdm_get_capabilities_request27);
     471              : 
     472              : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request28 = {
     473              :     {
     474              :         SPDM_MESSAGE_VERSION_13,
     475              :         SPDM_GET_CAPABILITIES,
     476              :         0x01,
     477              :     },
     478              :     0x00, /*reserved*/
     479              :     0x01, /*ct_exponent*/
     480              :     0x0000, /*reserved, 2 bytes*/
     481              :     SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP |
     482              :     SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP |
     483              :     SPDM_GET_CAPABILITIES_REQUEST_FLAGS_EP_INFO_CAP_SIG |
     484              :     SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MULTI_KEY_CAP_ONLY,
     485              :     LIBSPDM_DATA_TRANSFER_SIZE,
     486              :     LIBSPDM_MAX_SPDM_MSG_SIZE,
     487              : };
     488              : size_t m_libspdm_get_capabilities_request28_size = sizeof(m_libspdm_get_capabilities_request28);
     489              : 
     490            1 : static void rsp_capabilities_case1(void **state)
     491              : {
     492              :     libspdm_return_t status;
     493              :     libspdm_test_context_t *spdm_test_context;
     494              :     libspdm_context_t *spdm_context;
     495              :     size_t response_size;
     496              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     497              :     spdm_capabilities_response_t *spdm_response;
     498              : 
     499            1 :     spdm_test_context = *state;
     500            1 :     spdm_context = spdm_test_context->spdm_context;
     501            1 :     spdm_test_context->case_id = 0x1;
     502            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
     503              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     504              :     spdm_context->transcript.message_m.buffer_size =
     505              :         spdm_context->transcript.message_m.max_buffer_size;
     506              : #endif
     507              : 
     508            1 :     response_size = sizeof(response);
     509            1 :     status = libspdm_get_response_capabilities(
     510              :         spdm_context, m_libspdm_get_capabilities_request1_size,
     511              :         &m_libspdm_get_capabilities_request1, &response_size, response);
     512            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     513            1 :     assert_int_equal(response_size, sizeof(spdm_capabilities_response_t) -
     514              :                      sizeof(spdm_response->data_transfer_size) -
     515              :                      sizeof(spdm_response->max_spdm_msg_size));
     516            1 :     spdm_response = (void *)response;
     517            1 :     assert_int_equal(m_libspdm_get_capabilities_request1.header.spdm_version,
     518              :                      spdm_response->header.spdm_version);
     519            1 :     assert_int_equal(spdm_response->header.request_response_code,
     520              :                      SPDM_CAPABILITIES);
     521              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     522              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
     523              : #endif
     524            1 : }
     525              : 
     526            1 : static void rsp_capabilities_case2(void **state)
     527              : {
     528              :     libspdm_return_t status;
     529              :     libspdm_test_context_t *spdm_test_context;
     530              :     libspdm_context_t *spdm_context;
     531              :     size_t response_size;
     532              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     533              :     spdm_capabilities_response_t *spdm_response;
     534              : 
     535            1 :     spdm_test_context = *state;
     536            1 :     spdm_context = spdm_test_context->spdm_context;
     537            1 :     spdm_test_context->case_id = 0x2;
     538            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
     539              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     540              :     spdm_context->transcript.message_m.buffer_size =
     541              :         spdm_context->transcript.message_m.max_buffer_size;
     542              : #endif
     543              : 
     544            1 :     response_size = sizeof(response);
     545            1 :     status = libspdm_get_response_capabilities(
     546              :         spdm_context, m_libspdm_get_capabilities_request2_size,
     547              :         &m_libspdm_get_capabilities_request2, &response_size, response);
     548            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     549            1 :     assert_int_equal(response_size, sizeof(spdm_capabilities_response_t) -
     550              :                      sizeof(spdm_response->data_transfer_size) -
     551              :                      sizeof(spdm_response->max_spdm_msg_size));
     552            1 :     spdm_response = (void *)response;
     553            1 :     assert_int_equal(m_libspdm_get_capabilities_request2.header.spdm_version,
     554              :                      spdm_response->header.spdm_version);
     555            1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_CAPABILITIES);
     556              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     557              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
     558              : #endif
     559            1 : }
     560              : 
     561            1 : static void rsp_capabilities_case3(void **state)
     562              : {
     563              :     libspdm_return_t status;
     564              :     libspdm_test_context_t *spdm_test_context;
     565              :     libspdm_context_t *spdm_context;
     566              :     size_t response_size;
     567              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     568              :     spdm_capabilities_response_t *spdm_response;
     569              : 
     570            1 :     spdm_test_context = *state;
     571            1 :     spdm_context = spdm_test_context->spdm_context;
     572            1 :     spdm_test_context->case_id = 0x3;
     573            1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_BUSY;
     574            1 :     spdm_context->connection_info.connection_state =
     575              :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
     576              : 
     577            1 :     response_size = sizeof(response);
     578            1 :     status = libspdm_get_response_capabilities(
     579              :         spdm_context, m_libspdm_get_capabilities_request1_size,
     580              :         &m_libspdm_get_capabilities_request1, &response_size, response);
     581            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     582            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
     583            1 :     spdm_response = (void *)response;
     584            1 :     assert_int_equal(m_libspdm_get_capabilities_request1.header.spdm_version,
     585              :                      spdm_response->header.spdm_version);
     586            1 :     assert_int_equal(spdm_response->header.request_response_code,
     587              :                      SPDM_ERROR);
     588            1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_BUSY);
     589            1 :     assert_int_equal(spdm_response->header.param2, 0);
     590            1 :     assert_int_equal(spdm_context->response_state,
     591              :                      LIBSPDM_RESPONSE_STATE_BUSY);
     592            1 : }
     593              : 
     594            1 : static void rsp_capabilities_case4(void **state)
     595              : {
     596              :     libspdm_return_t status;
     597              :     libspdm_test_context_t *spdm_test_context;
     598              :     libspdm_context_t *spdm_context;
     599              :     size_t response_size;
     600              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     601              :     spdm_capabilities_response_t *spdm_response;
     602              : 
     603            1 :     spdm_test_context = *state;
     604            1 :     spdm_context = spdm_test_context->spdm_context;
     605            1 :     spdm_test_context->case_id = 0x4;
     606            1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NEED_RESYNC;
     607            1 :     spdm_context->connection_info.connection_state =
     608              :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
     609              : 
     610            1 :     response_size = sizeof(response);
     611            1 :     status = libspdm_get_response_capabilities(
     612              :         spdm_context, m_libspdm_get_capabilities_request1_size,
     613              :         &m_libspdm_get_capabilities_request1, &response_size, response);
     614            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     615            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
     616            1 :     spdm_response = (void *)response;
     617            1 :     assert_int_equal(m_libspdm_get_capabilities_request1.header.spdm_version,
     618              :                      spdm_response->header.spdm_version);
     619            1 :     assert_int_equal(spdm_response->header.request_response_code,
     620              :                      SPDM_ERROR);
     621            1 :     assert_int_equal(spdm_response->header.param1,
     622              :                      SPDM_ERROR_CODE_REQUEST_RESYNCH);
     623            1 :     assert_int_equal(spdm_response->header.param2, 0);
     624            1 :     assert_int_equal(spdm_context->response_state,
     625              :                      LIBSPDM_RESPONSE_STATE_NEED_RESYNC);
     626            1 : }
     627              : 
     628            1 : static void rsp_capabilities_case6(void **state)
     629              : {
     630              :     libspdm_return_t status;
     631              :     libspdm_test_context_t *spdm_test_context;
     632              :     libspdm_context_t *spdm_context;
     633              :     size_t response_size;
     634              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     635              :     spdm_capabilities_response_t *spdm_response;
     636              : 
     637            1 :     spdm_test_context = *state;
     638            1 :     spdm_context = spdm_test_context->spdm_context;
     639            1 :     spdm_test_context->case_id = 0x6;
     640            1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
     641            1 :     spdm_context->connection_info.connection_state =
     642              :         LIBSPDM_CONNECTION_STATE_NOT_STARTED;
     643              : 
     644            1 :     response_size = sizeof(response);
     645            1 :     status = libspdm_get_response_capabilities(
     646              :         spdm_context, m_libspdm_get_capabilities_request1_size,
     647              :         &m_libspdm_get_capabilities_request1, &response_size, response);
     648            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     649            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
     650            1 :     spdm_response = (void *)response;
     651            1 :     assert_int_equal(m_libspdm_get_capabilities_request1.header.spdm_version,
     652              :                      spdm_response->header.spdm_version);
     653            1 :     assert_int_equal(spdm_response->header.request_response_code,
     654              :                      SPDM_ERROR);
     655            1 :     assert_int_equal(spdm_response->header.param1,
     656              :                      SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
     657            1 :     assert_int_equal(spdm_response->header.param2, 0);
     658            1 : }
     659              : 
     660              : /**
     661              :  * Test 7: Requester sets a CTExponent value that is larger than LIBSPDM_MAX_CT_EXPONENT.
     662              :  * Expected behavior: returns with error code SPDM_ERROR_CODE_INVALID_REQUEST.
     663              :  **/
     664            1 : static void rsp_capabilities_case7(void **state)
     665              : {
     666              :     libspdm_return_t status;
     667              :     libspdm_test_context_t *spdm_test_context;
     668              :     libspdm_context_t *spdm_context;
     669              :     size_t response_size;
     670              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     671              :     spdm_capabilities_response_t *spdm_response;
     672              : 
     673            1 :     spdm_test_context = *state;
     674            1 :     spdm_context = spdm_test_context->spdm_context;
     675            1 :     spdm_test_context->case_id = 0x7;
     676            1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
     677            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
     678              : 
     679            1 :     response_size = sizeof(response);
     680            1 :     status = libspdm_get_response_capabilities(
     681              :         spdm_context, m_libspdm_get_capabilities_request7_size,
     682              :         &m_libspdm_get_capabilities_request7, &response_size, response);
     683            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     684            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
     685            1 :     spdm_response = (void *)response;
     686            1 :     assert_int_equal(m_libspdm_get_capabilities_request7.header.spdm_version,
     687              :                      spdm_response->header.spdm_version);
     688            1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
     689            1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
     690            1 :     assert_int_equal(spdm_response->header.param2, 0);
     691            1 : }
     692              : 
     693            1 : static void rsp_capabilities_case8(void **state)
     694              : {
     695              :     libspdm_return_t status;
     696              :     libspdm_test_context_t *spdm_test_context;
     697              :     libspdm_context_t *spdm_context;
     698              :     size_t response_size;
     699              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     700              :     spdm_capabilities_response_t *spdm_response;
     701              : 
     702            1 :     spdm_test_context = *state;
     703            1 :     spdm_context = spdm_test_context->spdm_context;
     704            1 :     spdm_test_context->case_id = 0x8;
     705            1 :     spdm_context->connection_info.connection_state =
     706              :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
     707              : 
     708            1 :     response_size = sizeof(response);
     709            1 :     status = libspdm_get_response_capabilities(
     710              :         spdm_context, m_libspdm_get_capabilities_request4_size,
     711              :         &m_libspdm_get_capabilities_request4, &response_size, response);
     712            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     713            1 :     assert_int_equal(response_size, sizeof(spdm_capabilities_response_t) -
     714              :                      sizeof(spdm_response->data_transfer_size) -
     715              :                      sizeof(spdm_response->max_spdm_msg_size));
     716            1 :     spdm_response = (void *)response;
     717            1 :     assert_int_equal(m_libspdm_get_capabilities_request4.header.spdm_version,
     718              :                      spdm_response->header.spdm_version);
     719            1 :     assert_int_equal(spdm_response->header.request_response_code,
     720              :                      SPDM_CAPABILITIES);
     721            1 : }
     722              : 
     723            1 : static void rsp_capabilities_case9(void **state)
     724              : {
     725              :     libspdm_return_t status;
     726              :     libspdm_test_context_t *spdm_test_context;
     727              :     libspdm_context_t *spdm_context;
     728              :     size_t response_size;
     729              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     730              :     spdm_capabilities_response_t *spdm_response;
     731              : 
     732            1 :     spdm_test_context = *state;
     733            1 :     spdm_context = spdm_test_context->spdm_context;
     734            1 :     spdm_test_context->case_id = 0x9;
     735            1 :     spdm_context->connection_info.connection_state =
     736              :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
     737              : 
     738            1 :     response_size = sizeof(response);
     739            1 :     status = libspdm_get_response_capabilities(
     740              :         spdm_context, m_libspdm_get_capabilities_request5_size,
     741              :         &m_libspdm_get_capabilities_request5, &response_size, response);
     742            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     743            1 :     assert_int_equal(response_size, sizeof(spdm_capabilities_response_t) -
     744              :                      sizeof(spdm_response->data_transfer_size) -
     745              :                      sizeof(spdm_response->max_spdm_msg_size));
     746            1 :     spdm_response = (void *)response;
     747            1 :     assert_int_equal(m_libspdm_get_capabilities_request4.header.spdm_version,
     748              :                      spdm_response->header.spdm_version);
     749            1 :     assert_int_equal(spdm_response->header.request_response_code,
     750              :                      SPDM_CAPABILITIES);
     751            1 : }
     752              : 
     753            1 : static void rsp_capabilities_case10(void **state)
     754              : {
     755            1 : }
     756              : 
     757            1 : static void rsp_capabilities_case11(void **state)
     758              : {
     759            1 : }
     760              : 
     761            1 : static void rsp_capabilities_case12(void **state)
     762              : {
     763            1 : }
     764              : 
     765            1 : static void rsp_capabilities_case13(void **state)
     766              : {
     767              :     libspdm_return_t status;
     768              :     libspdm_test_context_t *spdm_test_context;
     769              :     libspdm_context_t *spdm_context;
     770              :     size_t response_size;
     771              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     772              :     spdm_capabilities_response_t *spdm_response;
     773              : 
     774            1 :     spdm_test_context = *state;
     775            1 :     spdm_context = spdm_test_context->spdm_context;
     776            1 :     spdm_test_context->case_id = 0xd;
     777            1 :     spdm_context->connection_info.connection_state =
     778              :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
     779              : 
     780            1 :     response_size = sizeof(response);
     781            1 :     status = libspdm_get_response_capabilities(
     782              :         spdm_context, m_libspdm_get_capabilities_request9_size,
     783              :         &m_libspdm_get_capabilities_request9, &response_size, response);
     784            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     785            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
     786            1 :     spdm_response = (void *)response;
     787            1 :     assert_int_equal(m_libspdm_get_capabilities_request9.header.spdm_version,
     788              :                      spdm_response->header.spdm_version);
     789            1 :     assert_int_equal(spdm_response->header.request_response_code,
     790              :                      SPDM_ERROR);
     791            1 :     assert_int_equal(spdm_response->header.param1,
     792              :                      SPDM_ERROR_CODE_INVALID_REQUEST);
     793            1 :     assert_int_equal(spdm_response->header.param2, 0);
     794            1 : }
     795              : 
     796            1 : static void rsp_capabilities_case14(void **state)
     797              : {
     798              :     libspdm_return_t status;
     799              :     libspdm_test_context_t *spdm_test_context;
     800              :     libspdm_context_t *spdm_context;
     801              :     size_t response_size;
     802              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     803              :     spdm_capabilities_response_t *spdm_response;
     804              : 
     805            1 :     spdm_test_context = *state;
     806            1 :     spdm_context = spdm_test_context->spdm_context;
     807            1 :     spdm_test_context->case_id = 0xe;
     808            1 :     spdm_context->connection_info.connection_state =
     809              :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
     810              : 
     811            1 :     response_size = sizeof(response);
     812            1 :     status = libspdm_get_response_capabilities(
     813              :         spdm_context, m_libspdm_get_capabilities_request10_size,
     814              :         &m_libspdm_get_capabilities_request10, &response_size, response);
     815            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     816            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
     817            1 :     spdm_response = (void *)response;
     818            1 :     assert_int_equal(m_libspdm_get_capabilities_request10.header.spdm_version,
     819              :                      spdm_response->header.spdm_version);
     820            1 :     assert_int_equal(spdm_response->header.request_response_code,
     821              :                      SPDM_ERROR);
     822            1 :     assert_int_equal(spdm_response->header.param1,
     823              :                      SPDM_ERROR_CODE_INVALID_REQUEST);
     824            1 :     assert_int_equal(spdm_response->header.param2, 0);
     825            1 : }
     826              : 
     827            1 : static void rsp_capabilities_case15(void **state)
     828              : {
     829              :     libspdm_return_t status;
     830              :     libspdm_test_context_t *spdm_test_context;
     831              :     libspdm_context_t *spdm_context;
     832              :     size_t response_size;
     833              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     834              :     spdm_capabilities_response_t *spdm_response;
     835              : 
     836            1 :     spdm_test_context = *state;
     837            1 :     spdm_context = spdm_test_context->spdm_context;
     838            1 :     spdm_test_context->case_id = 0xf;
     839            1 :     spdm_context->connection_info.connection_state =
     840              :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
     841              : 
     842            1 :     response_size = sizeof(response);
     843            1 :     status = libspdm_get_response_capabilities(
     844              :         spdm_context, m_libspdm_get_capabilities_request11_size,
     845              :         &m_libspdm_get_capabilities_request11, &response_size, response);
     846            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     847            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
     848            1 :     spdm_response = (void *)response;
     849            1 :     assert_int_equal(m_libspdm_get_capabilities_request11.header.spdm_version,
     850              :                      spdm_response->header.spdm_version);
     851            1 :     assert_int_equal(spdm_response->header.request_response_code,
     852              :                      SPDM_ERROR);
     853            1 :     assert_int_equal(spdm_response->header.param1,
     854              :                      SPDM_ERROR_CODE_INVALID_REQUEST);
     855            1 :     assert_int_equal(spdm_response->header.param2, 0);
     856            1 : }
     857              : 
     858            1 : static void rsp_capabilities_case16(void **state)
     859              : {
     860              :     libspdm_return_t status;
     861              :     libspdm_test_context_t *spdm_test_context;
     862              :     libspdm_context_t *spdm_context;
     863              :     size_t response_size;
     864              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     865              :     spdm_capabilities_response_t *spdm_response;
     866              : 
     867            1 :     spdm_test_context = *state;
     868            1 :     spdm_context = spdm_test_context->spdm_context;
     869            1 :     spdm_test_context->case_id = 0x10;
     870            1 :     spdm_context->connection_info.connection_state =
     871              :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
     872              : 
     873            1 :     response_size = sizeof(response);
     874            1 :     status = libspdm_get_response_capabilities(
     875              :         spdm_context, m_libspdm_get_capabilities_request12_size,
     876              :         &m_libspdm_get_capabilities_request12, &response_size, response);
     877            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     878            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
     879            1 :     spdm_response = (void *)response;
     880            1 :     assert_int_equal(m_libspdm_get_capabilities_request12.header.spdm_version,
     881              :                      spdm_response->header.spdm_version);
     882            1 :     assert_int_equal(spdm_response->header.request_response_code,
     883              :                      SPDM_ERROR);
     884            1 :     assert_int_equal(spdm_response->header.param1,
     885              :                      SPDM_ERROR_CODE_INVALID_REQUEST);
     886            1 :     assert_int_equal(spdm_response->header.param2, 0);
     887            1 : }
     888              : 
     889            1 : static void rsp_capabilities_case17(void **state)
     890              : {
     891              :     libspdm_return_t status;
     892              :     libspdm_test_context_t *spdm_test_context;
     893              :     libspdm_context_t *spdm_context;
     894              :     size_t response_size;
     895              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     896              :     spdm_capabilities_response_t *spdm_response;
     897              : 
     898            1 :     spdm_test_context = *state;
     899            1 :     spdm_context = spdm_test_context->spdm_context;
     900            1 :     spdm_test_context->case_id = 0x11;
     901            1 :     spdm_context->connection_info.connection_state =
     902              :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
     903              : 
     904            1 :     response_size = sizeof(response);
     905            1 :     status = libspdm_get_response_capabilities(
     906              :         spdm_context, m_libspdm_get_capabilities_request13_size,
     907              :         &m_libspdm_get_capabilities_request13, &response_size, response);
     908            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     909            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
     910            1 :     spdm_response = (void *)response;
     911            1 :     assert_int_equal(m_libspdm_get_capabilities_request13.header.spdm_version,
     912              :                      spdm_response->header.spdm_version);
     913            1 :     assert_int_equal(spdm_response->header.request_response_code,
     914              :                      SPDM_ERROR);
     915            1 :     assert_int_equal(spdm_response->header.param1,
     916              :                      SPDM_ERROR_CODE_INVALID_REQUEST);
     917            1 :     assert_int_equal(spdm_response->header.param2, 0);
     918            1 : }
     919              : 
     920            1 : static void rsp_capabilities_case18(void **state)
     921              : {
     922              :     libspdm_return_t status;
     923              :     libspdm_test_context_t *spdm_test_context;
     924              :     libspdm_context_t *spdm_context;
     925              :     size_t response_size;
     926              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     927              :     spdm_capabilities_response_t *spdm_response;
     928              : 
     929            1 :     spdm_test_context = *state;
     930            1 :     spdm_context = spdm_test_context->spdm_context;
     931            1 :     spdm_test_context->case_id = 0x12;
     932            1 :     spdm_context->connection_info.connection_state =
     933              :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
     934              : 
     935            1 :     libspdm_reset_message_a(spdm_context);
     936              : 
     937            1 :     response_size = sizeof(response);
     938            1 :     status = libspdm_get_response_capabilities(
     939              :         spdm_context, m_libspdm_get_capabilities_request14_size,
     940              :         &m_libspdm_get_capabilities_request14, &response_size, response);
     941            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     942            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
     943            1 :     spdm_response = (void *)response;
     944            1 :     assert_int_equal(m_libspdm_get_capabilities_request14.header.spdm_version,
     945              :                      spdm_response->header.spdm_version);
     946            1 :     assert_int_equal(spdm_response->header.request_response_code,
     947              :                      SPDM_ERROR);
     948            1 :     assert_int_equal(spdm_response->header.param1,
     949              :                      SPDM_ERROR_CODE_INVALID_REQUEST);
     950            1 :     assert_int_equal(spdm_response->header.param2, 0);
     951            1 : }
     952              : 
     953            1 : static void rsp_capabilities_case19(void **state)
     954              : {
     955              :     libspdm_return_t status;
     956              :     libspdm_test_context_t *spdm_test_context;
     957              :     libspdm_context_t *spdm_context;
     958              :     size_t response_size;
     959              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     960              :     spdm_capabilities_response_t *spdm_response;
     961              : 
     962            1 :     spdm_test_context = *state;
     963            1 :     spdm_context = spdm_test_context->spdm_context;
     964            1 :     spdm_test_context->case_id = 0x13;
     965            1 :     spdm_context->connection_info.connection_state =
     966              :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
     967              : 
     968            1 :     response_size = sizeof(response);
     969            1 :     status = libspdm_get_response_capabilities(
     970              :         spdm_context, m_libspdm_get_capabilities_request15_size,
     971              :         &m_libspdm_get_capabilities_request15, &response_size, response);
     972            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     973            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
     974            1 :     spdm_response = (void *)response;
     975            1 :     assert_int_equal(m_libspdm_get_capabilities_request15.header.spdm_version,
     976              :                      spdm_response->header.spdm_version);
     977            1 :     assert_int_equal(spdm_response->header.request_response_code,
     978              :                      SPDM_ERROR);
     979            1 :     assert_int_equal(spdm_response->header.param1,
     980              :                      SPDM_ERROR_CODE_INVALID_REQUEST);
     981            1 :     assert_int_equal(spdm_response->header.param2, 0);
     982            1 : }
     983              : 
     984            1 : static void rsp_capabilities_case20(void **state)
     985              : {
     986              :     libspdm_return_t status;
     987              :     libspdm_test_context_t *spdm_test_context;
     988              :     libspdm_context_t *spdm_context;
     989              :     size_t response_size;
     990              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     991              :     spdm_capabilities_response_t *spdm_response;
     992              : 
     993            1 :     spdm_test_context = *state;
     994            1 :     spdm_context = spdm_test_context->spdm_context;
     995            1 :     spdm_test_context->case_id = 0x14;
     996            1 :     spdm_context->connection_info.connection_state =
     997              :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
     998              : 
     999            1 :     response_size = sizeof(response);
    1000            1 :     status = libspdm_get_response_capabilities(
    1001              :         spdm_context, m_libspdm_get_capabilities_request16_size,
    1002              :         &m_libspdm_get_capabilities_request16, &response_size, response);
    1003            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1004            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
    1005            1 :     spdm_response = (void *)response;
    1006            1 :     assert_int_equal(m_libspdm_get_capabilities_request16.header.spdm_version,
    1007              :                      spdm_response->header.spdm_version);
    1008            1 :     assert_int_equal(spdm_response->header.request_response_code,
    1009              :                      SPDM_ERROR);
    1010            1 :     assert_int_equal(spdm_response->header.param1,
    1011              :                      SPDM_ERROR_CODE_INVALID_REQUEST);
    1012            1 :     assert_int_equal(spdm_response->header.param2, 0);
    1013            1 : }
    1014              : 
    1015            1 : static void rsp_capabilities_case21(void **state)
    1016              : {
    1017            1 : }
    1018              : 
    1019            1 : static void rsp_capabilities_case22(void **state)
    1020              : {
    1021              :     libspdm_return_t status;
    1022              :     libspdm_test_context_t *spdm_test_context;
    1023              :     libspdm_context_t *spdm_context;
    1024              :     size_t response_size;
    1025              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
    1026              :     spdm_capabilities_response_t *spdm_response;
    1027              : 
    1028            1 :     spdm_test_context = *state;
    1029            1 :     spdm_context = spdm_test_context->spdm_context;
    1030            1 :     spdm_test_context->case_id = 0x16;
    1031            1 :     spdm_context->connection_info.connection_state =
    1032              :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1033              : 
    1034            1 :     response_size = sizeof(response);
    1035            1 :     status = libspdm_get_response_capabilities(
    1036              :         spdm_context, m_libspdm_get_capabilities_request18_size,
    1037              :         &m_libspdm_get_capabilities_request18, &response_size, response);
    1038            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1039            1 :     assert_int_equal(response_size, sizeof(spdm_capabilities_response_t) -
    1040              :                      sizeof(spdm_response->data_transfer_size) -
    1041              :                      sizeof(spdm_response->max_spdm_msg_size));
    1042            1 :     spdm_response = (void *)response;
    1043            1 :     assert_int_equal(m_libspdm_get_capabilities_request18.header.spdm_version,
    1044              :                      spdm_response->header.spdm_version);
    1045            1 :     assert_int_equal(spdm_response->header.request_response_code,
    1046              :                      SPDM_CAPABILITIES);
    1047            1 : }
    1048              : 
    1049            1 : static void rsp_capabilities_case23(void **state)
    1050              : {
    1051              :     libspdm_return_t status;
    1052              :     libspdm_test_context_t *spdm_test_context;
    1053              :     libspdm_context_t *spdm_context;
    1054              :     size_t response_size;
    1055              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
    1056              :     spdm_capabilities_response_t *spdm_response;
    1057              :     size_t arbitrary_size;
    1058              : 
    1059            1 :     spdm_test_context = *state;
    1060            1 :     spdm_context = spdm_test_context->spdm_context;
    1061            1 :     spdm_test_context->case_id = 0x17;
    1062            1 :     spdm_context->connection_info.connection_state =
    1063              :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1064              : 
    1065              :     /*filling A with arbitrary data*/
    1066            1 :     arbitrary_size = 10;
    1067            1 :     libspdm_set_mem(spdm_context->transcript.message_a.buffer, arbitrary_size, (uint8_t) 0xFF);
    1068            1 :     spdm_context->transcript.message_a.buffer_size = arbitrary_size;
    1069              : 
    1070            1 :     response_size = sizeof(response);
    1071            1 :     status = libspdm_get_response_capabilities(
    1072              :         spdm_context, m_libspdm_get_capabilities_request4_size,
    1073              :         &m_libspdm_get_capabilities_request4, &response_size, response);
    1074            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1075            1 :     assert_int_equal(response_size, sizeof(spdm_capabilities_response_t) -
    1076              :                      sizeof(spdm_response->data_transfer_size) -
    1077              :                      sizeof(spdm_response->max_spdm_msg_size));
    1078            1 :     spdm_response = (void *)response;
    1079            1 :     assert_int_equal(m_libspdm_get_capabilities_request4.header.spdm_version,
    1080              :                      spdm_response->header.spdm_version);
    1081            1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_CAPABILITIES);
    1082              : 
    1083            1 :     assert_int_equal(spdm_context->transcript.message_a.buffer_size,
    1084              :                      arbitrary_size + m_libspdm_get_capabilities_request4_size + response_size);
    1085            1 :     assert_memory_equal(spdm_context->transcript.message_a.buffer + arbitrary_size,
    1086              :                         &m_libspdm_get_capabilities_request4,
    1087              :                         m_libspdm_get_capabilities_request4_size);
    1088            1 :     assert_memory_equal(spdm_context->transcript.message_a.buffer + arbitrary_size +
    1089              :                         m_libspdm_get_capabilities_request4_size,
    1090              :                         response, response_size);
    1091            1 : }
    1092              : 
    1093            1 : static void rsp_capabilities_case24(void **state)
    1094              : {
    1095              :     libspdm_return_t status;
    1096              :     libspdm_test_context_t *spdm_test_context;
    1097              :     libspdm_context_t *spdm_context;
    1098              :     size_t response_size;
    1099              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
    1100              :     spdm_capabilities_response_t *spdm_response;
    1101              : 
    1102            1 :     spdm_test_context = *state;
    1103            1 :     spdm_context = spdm_test_context->spdm_context;
    1104            1 :     spdm_test_context->case_id = 0x18;
    1105            1 :     spdm_context->connection_info.connection_state =
    1106              :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1107              : 
    1108            1 :     response_size = sizeof(response);
    1109            1 :     status = libspdm_get_response_capabilities(
    1110              :         spdm_context, m_libspdm_get_capabilities_request19_size,
    1111              :         &m_libspdm_get_capabilities_request19, &response_size, response);
    1112            1 :     assert_int_equal(spdm_context->connection_info.capability.max_spdm_msg_size,
    1113              :                      m_libspdm_get_capabilities_request19.max_spdm_msg_size);
    1114            1 :     assert_int_equal(spdm_context->connection_info.capability.data_transfer_size,
    1115              :                      m_libspdm_get_capabilities_request19.data_transfer_size);
    1116            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1117            1 :     assert_int_equal(response_size, sizeof(spdm_capabilities_response_t));
    1118            1 :     spdm_response = (void *)response;
    1119            1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
    1120            1 :     assert_int_equal(spdm_response->header.request_response_code,
    1121              :                      SPDM_CAPABILITIES);
    1122            1 :     assert_int_equal(spdm_response->data_transfer_size, LIBSPDM_DATA_TRANSFER_SIZE);
    1123            1 :     assert_int_equal(spdm_response->max_spdm_msg_size, LIBSPDM_MAX_SPDM_MSG_SIZE);
    1124            1 : }
    1125              : 
    1126            1 : static void rsp_capabilities_case25(void **state)
    1127              : {
    1128              :     libspdm_return_t status;
    1129              :     libspdm_test_context_t *spdm_test_context;
    1130              :     libspdm_context_t *spdm_context;
    1131              :     size_t response_size;
    1132              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
    1133              :     spdm_capabilities_response_t *spdm_response;
    1134              : 
    1135            1 :     spdm_test_context = *state;
    1136            1 :     spdm_context = spdm_test_context->spdm_context;
    1137            1 :     spdm_test_context->case_id = 0x19;
    1138            1 :     spdm_context->connection_info.connection_state =
    1139              :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1140              : 
    1141            1 :     response_size = sizeof(response);
    1142            1 :     status = libspdm_get_response_capabilities(
    1143              :         spdm_context, m_libspdm_get_capabilities_request25_size,
    1144              :         &m_libspdm_get_capabilities_request25, &response_size, response);
    1145            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1146            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
    1147            1 :     spdm_response = (void *)response;
    1148            1 :     assert_int_equal(m_libspdm_get_capabilities_request25.header.spdm_version,
    1149              :                      spdm_response->header.spdm_version);
    1150            1 :     assert_int_equal(spdm_response->header.request_response_code,
    1151              :                      SPDM_ERROR);
    1152            1 :     assert_int_equal(spdm_response->header.param1,
    1153              :                      SPDM_ERROR_CODE_INVALID_REQUEST);
    1154            1 :     assert_int_equal(spdm_response->header.param2, 0);
    1155            1 : }
    1156              : 
    1157            1 : static void rsp_capabilities_case26(void **state)
    1158              : {
    1159              :     libspdm_return_t status;
    1160              :     libspdm_test_context_t *spdm_test_context;
    1161              :     libspdm_context_t *spdm_context;
    1162              :     size_t response_size;
    1163              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
    1164              :     spdm_capabilities_response_t *spdm_response;
    1165              : 
    1166            1 :     spdm_test_context = *state;
    1167            1 :     spdm_context = spdm_test_context->spdm_context;
    1168            1 :     spdm_test_context->case_id = 0x1A;
    1169            1 :     spdm_context->connection_info.connection_state =
    1170              :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1171              : 
    1172            1 :     response_size = sizeof(response);
    1173            1 :     status = libspdm_get_response_capabilities(
    1174              :         spdm_context, m_libspdm_get_capabilities_request26_size,
    1175              :         &m_libspdm_get_capabilities_request26, &response_size, response);
    1176            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1177            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
    1178            1 :     spdm_response = (void *)response;
    1179            1 :     assert_int_equal(m_libspdm_get_capabilities_request26.header.spdm_version,
    1180              :                      spdm_response->header.spdm_version);
    1181            1 :     assert_int_equal(spdm_response->header.request_response_code,
    1182              :                      SPDM_ERROR);
    1183            1 :     assert_int_equal(spdm_response->header.param1,
    1184              :                      SPDM_ERROR_CODE_INVALID_REQUEST);
    1185            1 :     assert_int_equal(spdm_response->header.param2, 0);
    1186            1 : }
    1187              : 
    1188            1 : static void rsp_capabilities_case27(void **state)
    1189              : {
    1190              :     libspdm_return_t status;
    1191              :     libspdm_test_context_t *spdm_test_context;
    1192              :     libspdm_context_t *spdm_context;
    1193              :     size_t response_size;
    1194              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
    1195              :     spdm_capabilities_response_t *spdm_response;
    1196              : 
    1197            1 :     spdm_test_context = *state;
    1198            1 :     spdm_context = spdm_test_context->spdm_context;
    1199            1 :     spdm_test_context->case_id = 0x1B;
    1200            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1201              : 
    1202            1 :     response_size = sizeof(response);
    1203            1 :     status = libspdm_get_response_capabilities(
    1204              :         spdm_context, m_libspdm_get_capabilities_request27_size,
    1205              :         &m_libspdm_get_capabilities_request27, &response_size, response);
    1206              : 
    1207            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1208            1 :     assert_int_equal(response_size, sizeof(spdm_capabilities_response_t));
    1209            1 :     spdm_response = (void *)response;
    1210            1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_13);
    1211            1 :     assert_int_equal(spdm_response->header.request_response_code,
    1212              :                      SPDM_CAPABILITIES);
    1213            1 :     assert_int_equal(spdm_response->data_transfer_size, LIBSPDM_DATA_TRANSFER_SIZE);
    1214            1 :     assert_int_equal(spdm_response->max_spdm_msg_size, LIBSPDM_MAX_SPDM_MSG_SIZE);
    1215            1 :     assert_int_equal(spdm_context->connection_info.capability.flags,
    1216              :                      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP |
    1217              :                      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_EP_INFO_CAP_SIG |
    1218              :                      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MULTI_KEY_CAP_ONLY);
    1219            1 : }
    1220              : 
    1221            1 : static void rsp_capabilities_case28(void **state)
    1222              : {
    1223              :     libspdm_return_t status;
    1224              :     libspdm_test_context_t *spdm_test_context;
    1225              :     libspdm_context_t *spdm_context;
    1226              :     size_t response_size;
    1227              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
    1228              :     spdm_capabilities_response_t *spdm_response;
    1229              : 
    1230            1 :     spdm_test_context = *state;
    1231            1 :     spdm_context = spdm_test_context->spdm_context;
    1232            1 :     spdm_test_context->case_id = 0x1C;
    1233            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1234              : 
    1235            1 :     spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    1236            1 :     spdm_context->local_context.algorithm.other_params_support = 0;
    1237            1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    1238            1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    1239            1 :     spdm_context->local_context.algorithm.mel_spec = SPDM_MEL_SPECIFICATION_DMTF;
    1240            1 :     spdm_context->local_context.capability.flags =
    1241              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP |
    1242              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MULTI_KEY_CAP_ONLY;
    1243              : 
    1244            1 :     spdm_context->connection_info.capability.flags |=
    1245              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
    1246            1 :     spdm_context->connection_info.capability.flags |=
    1247              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
    1248            1 :     spdm_context->connection_info.capability.flags |=
    1249              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
    1250              : 
    1251            1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
    1252            1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
    1253            1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
    1254            1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
    1255              : 
    1256            1 :     response_size = sizeof(response);
    1257            1 :     status = libspdm_get_response_capabilities(
    1258              :         spdm_context, m_libspdm_get_capabilities_request28_size,
    1259              :         &m_libspdm_get_capabilities_request28, &response_size, response);
    1260            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1261            1 :     assert_int_equal(response_size, sizeof(spdm_capabilities_response_t) +
    1262              :                      sizeof(spdm_supported_algorithms_block_t) +
    1263              :                      4 * sizeof(spdm_negotiate_algorithms_common_struct_table_t));
    1264            1 :     spdm_response = (void *)response;
    1265            1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_13);
    1266            1 :     assert_int_equal(spdm_response->header.request_response_code,
    1267              :                      SPDM_CAPABILITIES);
    1268            1 :     assert_int_equal(spdm_response->data_transfer_size, LIBSPDM_DATA_TRANSFER_SIZE);
    1269            1 :     assert_int_equal(spdm_response->max_spdm_msg_size, LIBSPDM_MAX_SPDM_MSG_SIZE);
    1270            1 :     assert_int_equal(spdm_context->connection_info.capability.flags,
    1271              :                      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP |
    1272              :                      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP |
    1273              :                      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_EP_INFO_CAP_SIG |
    1274              :                      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MULTI_KEY_CAP_ONLY);
    1275            1 : }
    1276              : 
    1277            1 : int libspdm_rsp_capabilities_test(void)
    1278              : {
    1279            1 :     const struct CMUnitTest test_cases[] = {
    1280              :         /* Success Case*/
    1281              :         cmocka_unit_test(rsp_capabilities_case1),
    1282              :         /* Success case where request size is larger than actual message. */
    1283              :         cmocka_unit_test(rsp_capabilities_case2),
    1284              :         /* response_state: LIBSPDM_RESPONSE_STATE_BUSY*/
    1285              :         cmocka_unit_test(rsp_capabilities_case3),
    1286              :         /* response_state: LIBSPDM_RESPONSE_STATE_NEED_RESYNC*/
    1287              :         cmocka_unit_test(rsp_capabilities_case4),
    1288              :         /* connection_state Check*/
    1289              :         cmocka_unit_test(rsp_capabilities_case6),
    1290              :         /* Invalid requester capabilities flag (random flag)*/
    1291              :         cmocka_unit_test(rsp_capabilities_case7),
    1292              :         /* V1.1 Success case, all possible flags set*/
    1293              :         cmocka_unit_test(rsp_capabilities_case8),
    1294              :         /* Requester capabilities flag bit 0 is set. reserved value should ne ignored*/
    1295              :         cmocka_unit_test(rsp_capabilities_case9),
    1296              :         /* Can be populated with new test. */
    1297              :         cmocka_unit_test(rsp_capabilities_case10),
    1298              :         /* Can be populated with new test. */
    1299              :         cmocka_unit_test(rsp_capabilities_case11),
    1300              :         /* Can be populated with new test. */
    1301              :         cmocka_unit_test(rsp_capabilities_case12),
    1302              :         /* pub_key_id_cap and cert_cap set (flags are mutually exclusive)*/
    1303              :         cmocka_unit_test(rsp_capabilities_case13),
    1304              :         /* encrypt_cap set and key_ex_cap and psk_cap cleared (encrypt_cap demands key_ex_cap or psk_cap to be set)*/
    1305              :         cmocka_unit_test(rsp_capabilities_case14),
    1306              :         /* mac_cap set and key_ex_cap and psk_cap cleared (mac_cap demands key_ex_cap or psk_cap to be set)*/
    1307              :         cmocka_unit_test(rsp_capabilities_case15),
    1308              :         /* key_ex_cap set and encrypt_cap and mac_cap cleared (key_ex_cap demands encrypt_cap or mac_cap to be set)*/
    1309              :         cmocka_unit_test(rsp_capabilities_case16),
    1310              :         /* psk_cap set and encrypt_cap and mac_cap cleared (psk_cap demands encrypt_cap or mac_cap to be set)*/
    1311              :         cmocka_unit_test(rsp_capabilities_case17),
    1312              :         /* encap_cap cleared and MUT_AUTH set (MUT_AUTH demands encap_cap to be set)*/
    1313              :         cmocka_unit_test(rsp_capabilities_case18),
    1314              :         /* cert_cap set and pub_key_id_cap set (pub_key_id_cap demands cert_cap to be cleared)*/
    1315              :         cmocka_unit_test(rsp_capabilities_case19),
    1316              :         /* key_ex_cap cleared and handshake_in_the_clear_cap set (handshake_in_the_clear_cap demands key_ex_cap to be set)*/
    1317              :         cmocka_unit_test(rsp_capabilities_case20),
    1318              :         /* Open test case */
    1319              :         cmocka_unit_test(rsp_capabilities_case21),
    1320              :         /* cert_cap cleared and pub_key_id_cap set (pub_key_id_cap demands cert_cap to be cleared)*/
    1321              :         cmocka_unit_test(rsp_capabilities_case22),
    1322              :         /* Buffer verification*/
    1323              :         cmocka_unit_test(rsp_capabilities_case23),
    1324              :         /* V1.2 Success case, all possible flags set*/
    1325              :         cmocka_unit_test(rsp_capabilities_case24),
    1326              :         /* CHUNK_CAP == 0 and data_transfer_size != max_spdm_msg_size should result in error. */
    1327              :         cmocka_unit_test(rsp_capabilities_case25),
    1328              :         /* MaxSPDMmsgSize is less than DataTransferSize, then should result in error. */
    1329              :         cmocka_unit_test(rsp_capabilities_case26),
    1330              :         /* Success Case , capability supports MULTI_KEY_CAP */
    1331              :         cmocka_unit_test(rsp_capabilities_case27),
    1332              :         /* Success Case, GET_CAPABILITIES with param1[0] set and CHUNK_CAP enabled */
    1333              :         cmocka_unit_test(rsp_capabilities_case28),
    1334              :     };
    1335              : 
    1336            1 :     libspdm_test_context_t test_context = {
    1337              :         LIBSPDM_TEST_CONTEXT_VERSION,
    1338              :         false,
    1339              :     };
    1340              : 
    1341            1 :     libspdm_setup_test_context(&test_context);
    1342              : 
    1343            1 :     return cmocka_run_group_tests(test_cases,
    1344              :                                   libspdm_unit_test_group_setup,
    1345              :                                   libspdm_unit_test_group_teardown);
    1346              : }
        

Generated by: LCOV version 2.0-1