LCOV - code coverage report
Current view: top level - unit_test/test_spdm_requester/error_test - get_capabilities_err.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 98.2 % 1071 1052
Test Date: 2026-02-22 08:11:49 Functions: 100.0 % 44 44

            Line data    Source code
       1              : /**
       2              :  *  Copyright Notice:
       3              :  *  Copyright 2021-2026 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_requester_lib.h"
       9              : 
      10              : #define LIBSPDM_DEFAULT_CAPABILITY_FLAG \
      11              :     (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | \
      12              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP)
      13              : 
      14              : #define LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11 \
      15              :     (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | \
      16              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP | \
      17              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP | \
      18              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP | \
      19              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP | \
      20              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP | \
      21              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER | \
      22              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP | \
      23              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP | \
      24              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP | \
      25              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
      26              : 
      27              : #define LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_12  SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP
      28              : 
      29              : #define LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 \
      30              :     (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CACHE_CAP | \
      31              :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP | \
      32              :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP | \
      33              :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG | \
      34              :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_FRESH_CAP | \
      35              :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP | \
      36              :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP | \
      37              :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP | \
      38              :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP | \
      39              :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT | \
      40              :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP | \
      41              :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP | \
      42              :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_UPD_CAP | \
      43              :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
      44              : 
      45              : #define LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_12 \
      46              :     (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP | \
      47              :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | \
      48              :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ALIAS_CERT_CAP | \
      49              :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP)
      50              : 
      51           56 : static libspdm_return_t send_message(
      52              :     void *spdm_context, size_t request_size, const void *request, uint64_t timeout)
      53              : {
      54              :     libspdm_test_context_t *spdm_test_context;
      55              : 
      56           56 :     spdm_test_context = libspdm_get_test_context();
      57           56 :     switch (spdm_test_context->case_id) {
      58            1 :     case 0x1:
      59            1 :         return LIBSPDM_STATUS_SEND_FAIL;
      60            1 :     case 0x2:
      61            1 :         return LIBSPDM_STATUS_SUCCESS;
      62            1 :     case 0x3:
      63            1 :         return LIBSPDM_STATUS_SUCCESS;
      64            1 :     case 0x4:
      65            1 :         return LIBSPDM_STATUS_SUCCESS;
      66            1 :     case 0x5:
      67            1 :         return LIBSPDM_STATUS_SUCCESS;
      68            1 :     case 0x6:
      69            1 :         return LIBSPDM_STATUS_SUCCESS;
      70            1 :     case 0x7:
      71            1 :         return LIBSPDM_STATUS_SUCCESS;
      72            1 :     case 0x8:
      73            1 :         return LIBSPDM_STATUS_SUCCESS;
      74            1 :     case 0x9:
      75            1 :         return LIBSPDM_STATUS_SUCCESS;
      76            1 :     case 0xa:
      77            1 :         return LIBSPDM_STATUS_SUCCESS;
      78            1 :     case 0xb:
      79            1 :         return LIBSPDM_STATUS_SUCCESS;
      80            1 :     case 0xc:
      81            1 :         return LIBSPDM_STATUS_SUCCESS;
      82            1 :     case 0xd:
      83            1 :         return LIBSPDM_STATUS_SUCCESS;
      84            1 :     case 0xe:
      85            1 :         return LIBSPDM_STATUS_SUCCESS;
      86            1 :     case 0xf:
      87            1 :         return LIBSPDM_STATUS_SUCCESS;
      88            1 :     case 0x10:
      89            1 :         return LIBSPDM_STATUS_SUCCESS;
      90            1 :     case 0x11:
      91            1 :         return LIBSPDM_STATUS_SUCCESS;
      92            1 :     case 0x12:
      93            1 :         return LIBSPDM_STATUS_SUCCESS;
      94            1 :     case 0x13:
      95            1 :         return LIBSPDM_STATUS_SUCCESS;
      96            1 :     case 0x14:
      97            1 :         return LIBSPDM_STATUS_SUCCESS;
      98            1 :     case 0x15:
      99            1 :         return LIBSPDM_STATUS_SUCCESS;
     100            1 :     case 0x16:
     101            1 :         return LIBSPDM_STATUS_SUCCESS;
     102            1 :     case 0x17:
     103            1 :         return LIBSPDM_STATUS_SUCCESS;
     104            1 :     case 0x18:
     105            1 :         return LIBSPDM_STATUS_SUCCESS;
     106            1 :     case 0x19:
     107            1 :         return LIBSPDM_STATUS_SUCCESS;
     108            1 :     case 0x1a:
     109            1 :         return LIBSPDM_STATUS_SUCCESS;
     110            1 :     case 0x1b:
     111            1 :         return LIBSPDM_STATUS_SUCCESS;
     112            1 :     case 0x1c:
     113            1 :         return LIBSPDM_STATUS_SUCCESS;
     114           18 :     case 0x1d:
     115           18 :         return LIBSPDM_STATUS_SUCCESS;
     116            1 :     case 0x1E:
     117            1 :         return LIBSPDM_STATUS_SUCCESS;
     118            1 :     case 0x1F:
     119            1 :         return LIBSPDM_STATUS_SUCCESS;
     120            1 :     case 0x20:
     121            1 :         return LIBSPDM_STATUS_SUCCESS;
     122            1 :     case 0x21:
     123            1 :         return LIBSPDM_STATUS_SUCCESS;
     124            1 :     case 0x22:
     125            1 :         return LIBSPDM_STATUS_SUCCESS;
     126            1 :     case 0x23:
     127            1 :         return LIBSPDM_STATUS_SUCCESS;
     128            1 :     case 0x24:
     129            1 :         return LIBSPDM_STATUS_SUCCESS;
     130            1 :     case 0x25:
     131            1 :         return LIBSPDM_STATUS_SUCCESS;
     132            1 :     case 0x26:
     133            1 :         return LIBSPDM_STATUS_SUCCESS;
     134            1 :     case 0x27:
     135            1 :         return LIBSPDM_STATUS_SUCCESS;
     136            0 :     default:
     137            0 :         return LIBSPDM_STATUS_SEND_FAIL;
     138              :     }
     139              : }
     140              : 
     141           54 : static libspdm_return_t receive_message(
     142              :     void *spdm_context, size_t *response_size, void **response, uint64_t timeout)
     143              : {
     144              :     libspdm_test_context_t *spdm_test_context;
     145              : 
     146           54 :     spdm_test_context = libspdm_get_test_context();
     147           54 :     switch (spdm_test_context->case_id) {
     148            0 :     case 0x1:
     149            0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
     150              : 
     151            1 :     case 0x2: {
     152              :         spdm_capabilities_response_t *spdm_response;
     153              :         size_t spdm_response_size;
     154              :         size_t transport_header_size;
     155              : 
     156            1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
     157            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     158            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     159              : 
     160            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     161            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     162            1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
     163            1 :         spdm_response->header.param1 = 0;
     164            1 :         spdm_response->header.param2 = 0;
     165            1 :         spdm_response->ct_exponent = 0;
     166            1 :         spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_FRESH_CAP;
     167              : 
     168            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     169              :                                               false, spdm_response_size,
     170              :                                               spdm_response,
     171              :                                               response_size, response);
     172              :     }
     173            1 :         return LIBSPDM_STATUS_SUCCESS;
     174              : 
     175            0 :     case 0x3: {
     176              :         spdm_capabilities_response_t *spdm_response;
     177              :         size_t spdm_response_size;
     178              :         size_t transport_header_size;
     179              : 
     180            0 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
     181            0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     182            0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     183              : 
     184            0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     185            0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     186            0 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
     187            0 :         spdm_response->header.param1 = 0;
     188            0 :         spdm_response->header.param2 = 0;
     189            0 :         spdm_response->ct_exponent = 0;
     190            0 :         spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
     191              : 
     192            0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     193              :                                               false, spdm_response_size,
     194              :                                               spdm_response,
     195              :                                               response_size, response);
     196              :     }
     197            0 :         return LIBSPDM_STATUS_SUCCESS;
     198              : 
     199            1 :     case 0x4: {
     200              :         spdm_error_response_t *spdm_response;
     201              :         size_t spdm_response_size;
     202              :         size_t transport_header_size;
     203              : 
     204            1 :         spdm_response_size = sizeof(spdm_error_response_t);
     205            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     206            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     207              : 
     208            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     209            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     210            1 :         spdm_response->header.request_response_code = SPDM_ERROR;
     211            1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
     212            1 :         spdm_response->header.param2 = 0;
     213              : 
     214            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     215              :                                               false, spdm_response_size,
     216              :                                               spdm_response,
     217              :                                               response_size, response);
     218              :     }
     219            1 :         return LIBSPDM_STATUS_SUCCESS;
     220              : 
     221            1 :     case 0x5: {
     222              :         spdm_error_response_t *spdm_response;
     223              :         size_t spdm_response_size;
     224              :         size_t transport_header_size;
     225              : 
     226            1 :         spdm_response_size = sizeof(spdm_error_response_t);
     227            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     228            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     229              : 
     230            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     231            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     232            1 :         spdm_response->header.request_response_code = SPDM_ERROR;
     233            1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
     234            1 :         spdm_response->header.param2 = 0;
     235              : 
     236            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     237              :                                               false, spdm_response_size,
     238              :                                               spdm_response,
     239              :                                               response_size, response);
     240              :     }
     241            1 :         return LIBSPDM_STATUS_SUCCESS;
     242              : 
     243            1 :     case 0x6: {
     244              :         spdm_capabilities_response_t *spdm_response;
     245              :         size_t spdm_response_size;
     246              :         size_t transport_header_size;
     247              : 
     248            1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
     249            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     250            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     251              : 
     252            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     253            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     254            1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
     255            1 :         spdm_response->header.param1 = 0;
     256            1 :         spdm_response->header.param2 = 0;
     257            1 :         spdm_response->ct_exponent = 0;
     258            1 :         spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG |
     259              :                                SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
     260              : 
     261            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     262              :                                               false, spdm_response_size,
     263              :                                               spdm_response,
     264              :                                               response_size, response);
     265              :     }
     266            1 :         return LIBSPDM_STATUS_SUCCESS;
     267              : 
     268            1 :     case 0x7: {
     269              :         spdm_error_response_t *spdm_response;
     270              :         size_t spdm_response_size;
     271              :         size_t transport_header_size;
     272              : 
     273            1 :         spdm_response_size = sizeof(spdm_error_response_t);
     274            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     275            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     276              : 
     277            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     278            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     279            1 :         spdm_response->header.request_response_code = SPDM_ERROR;
     280            1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
     281            1 :         spdm_response->header.param2 = 0;
     282              : 
     283            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     284              :                                               false, spdm_response_size,
     285              :                                               spdm_response,
     286              :                                               response_size, response);
     287              :     }
     288            1 :         return LIBSPDM_STATUS_SUCCESS;
     289              : 
     290            1 :     case 0x8: {
     291              :         spdm_error_response_data_response_not_ready_t *spdm_response;
     292              :         size_t spdm_response_size;
     293              :         size_t transport_header_size;
     294              : 
     295            1 :         spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
     296            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     297            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     298              : 
     299            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     300            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     301            1 :         spdm_response->header.request_response_code = SPDM_ERROR;
     302            1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_RESPONSE_NOT_READY;
     303            1 :         spdm_response->header.param2 = 0;
     304            1 :         spdm_response->extend_error_data.rd_exponent = 1;
     305            1 :         spdm_response->extend_error_data.rd_tm = 2;
     306            1 :         spdm_response->extend_error_data.request_code = SPDM_GET_CAPABILITIES;
     307            1 :         spdm_response->extend_error_data.token = 0;
     308              : 
     309            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     310              :                                               false, spdm_response_size,
     311              :                                               spdm_response,
     312              :                                               response_size, response);
     313              :     }
     314            1 :         return LIBSPDM_STATUS_SUCCESS;
     315              : 
     316            1 :     case 0x9: {
     317              :         spdm_capabilities_response_t *spdm_response;
     318              :         size_t spdm_response_size;
     319              :         size_t transport_header_size;
     320              : 
     321            1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
     322            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     323            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     324              : 
     325            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     326            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     327            1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
     328            1 :         spdm_response->header.param1 = 0;
     329            1 :         spdm_response->header.param2 = 0;
     330            1 :         spdm_response->ct_exponent = 0;
     331            1 :         spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP;
     332              : 
     333            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     334              :                                               false, spdm_response_size,
     335              :                                               spdm_response,
     336              :                                               response_size, response);
     337              :     }
     338            1 :         return LIBSPDM_STATUS_SUCCESS;
     339              : 
     340            1 :     case 0xa: {
     341              :         spdm_capabilities_response_t *spdm_response;
     342              :         size_t spdm_response_size;
     343              :         size_t transport_header_size;
     344              : 
     345            1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
     346            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     347            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     348              : 
     349            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     350            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     351            1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
     352            1 :         spdm_response->header.param1 = 0;
     353            1 :         spdm_response->header.param2 = 0;
     354            1 :         spdm_response->ct_exponent = 0;
     355            1 :         spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
     356              : 
     357            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     358              :                                               false, spdm_response_size,
     359              :                                               spdm_response,
     360              :                                               response_size, response);
     361              :     }
     362            1 :         return LIBSPDM_STATUS_SUCCESS;
     363              : 
     364            1 :     case 0xb: {
     365              :         spdm_capabilities_response_t *spdm_response;
     366              :         size_t spdm_response_size;
     367              :         size_t transport_header_size;
     368              : 
     369            1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
     370            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     371            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     372              : 
     373            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     374            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     375            1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
     376            1 :         spdm_response->header.param1 = 0;
     377            1 :         spdm_response->header.param2 = 0;
     378            1 :         spdm_response->ct_exponent = 0;
     379            1 :         spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
     380              : 
     381            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     382              :                                               false, spdm_response_size,
     383              :                                               spdm_response,
     384              :                                               response_size, response);
     385              :     }
     386            1 :         return LIBSPDM_STATUS_SUCCESS;
     387              : 
     388            1 :     case 0xc: {
     389              :         spdm_capabilities_response_t *spdm_response;
     390              :         size_t spdm_response_size;
     391              :         size_t transport_header_size;
     392              : 
     393            1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
     394            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     395            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     396              : 
     397            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     398            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     399            1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
     400            1 :         spdm_response->header.param1 = 0;
     401            1 :         spdm_response->header.param2 = 0;
     402            1 :         spdm_response->ct_exponent = 0;
     403            1 :         spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
     404              : 
     405            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     406              :                                               false, spdm_response_size,
     407              :                                               spdm_response,
     408              :                                               response_size, response);
     409              :     }
     410            1 :         return LIBSPDM_STATUS_SUCCESS;
     411              : 
     412            1 :     case 0xd: {
     413              :         spdm_capabilities_response_t *spdm_response;
     414              :         size_t spdm_response_size;
     415              :         size_t transport_header_size;
     416              : 
     417            1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
     418            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     419            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     420              : 
     421            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     422            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     423            1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
     424            1 :         spdm_response->header.param1 = 0;
     425            1 :         spdm_response->header.param2 = 0;
     426              : 
     427            1 :         libspdm_transport_test_encode_message(
     428              :             spdm_context, NULL, false, false,
     429              :             sizeof(spdm_message_header_t), spdm_response,
     430              :             response_size, response);
     431              :     }
     432            1 :         return LIBSPDM_STATUS_SUCCESS;
     433              : 
     434            1 :     case 0xe: {
     435              :         spdm_capabilities_response_t *spdm_response;
     436              :         size_t spdm_response_size;
     437              :         size_t transport_header_size;
     438              : 
     439            1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
     440            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     441            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     442              : 
     443            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     444            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     445            1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
     446            1 :         spdm_response->header.param1 = 0;
     447            1 :         spdm_response->header.param2 = 0;
     448            1 :         spdm_response->ct_exponent = 0;
     449            1 :         spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
     450              : 
     451            1 :         libspdm_transport_test_encode_message(
     452              :             spdm_context, NULL, false, false,
     453              :             sizeof(spdm_capabilities_response_t) + sizeof(uint8_t), spdm_response,
     454              :             response_size, response);
     455              :     }
     456            1 :         return LIBSPDM_STATUS_INVALID_MSG_SIZE;
     457              : 
     458            1 :     case 0xf: {
     459              :         spdm_capabilities_response_t *spdm_response;
     460              :         size_t spdm_response_size;
     461              :         size_t transport_header_size;
     462              : 
     463            1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
     464            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     465            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     466              : 
     467            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     468            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     469            1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
     470            1 :         spdm_response->header.param1 = 0;
     471            1 :         spdm_response->header.param2 = 0;
     472            1 :         spdm_response->ct_exponent = 0;
     473            1 :         spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
     474              : 
     475            1 :         libspdm_transport_test_encode_message(
     476              :             spdm_context, NULL, false, false,
     477              :             sizeof(spdm_capabilities_response_t) - sizeof(uint8_t), spdm_response,
     478              :             response_size, response);
     479              :     }
     480            1 :         return LIBSPDM_STATUS_INVALID_MSG_SIZE;
     481              : 
     482            1 :     case 0x10: {
     483              :         spdm_capabilities_response_t *spdm_response;
     484              :         size_t spdm_response_size;
     485              :         size_t transport_header_size;
     486              : 
     487            1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
     488            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     489            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     490              : 
     491            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     492            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     493            1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
     494            1 :         spdm_response->header.param1 = 0;
     495            1 :         spdm_response->header.param2 = 0;
     496            1 :         spdm_response->ct_exponent = 0;
     497            1 :         spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
     498              :                                SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
     499              : 
     500            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     501              :                                               false, spdm_response_size,
     502              :                                               spdm_response,
     503              :                                               response_size, response);
     504              :     }
     505            1 :         return LIBSPDM_STATUS_SUCCESS;
     506              : 
     507            1 :     case 0x11: {
     508              :         spdm_capabilities_response_t *spdm_response;
     509              :         size_t spdm_response_size;
     510              :         size_t transport_header_size;
     511              : 
     512            1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
     513            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     514            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     515              : 
     516            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     517            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     518            1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
     519            1 :         spdm_response->header.param1 = 0;
     520            1 :         spdm_response->header.param2 = 0;
     521            1 :         spdm_response->ct_exponent = 0;
     522            1 :         spdm_response->flags =
     523              :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
     524              :             (0xFFFFFFFF ^
     525              :              (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
     526              :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP |
     527              :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP));
     528              : 
     529            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     530              :                                               false, spdm_response_size,
     531              :                                               spdm_response,
     532              :                                               response_size, response);
     533              :     }
     534            1 :         return LIBSPDM_STATUS_SUCCESS;
     535              : 
     536            1 :     case 0x12: {
     537              :         spdm_capabilities_response_t *spdm_response;
     538              :         size_t spdm_response_size;
     539              :         size_t transport_header_size;
     540              : 
     541            1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
     542            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     543            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     544              : 
     545            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     546            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     547            1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
     548            1 :         spdm_response->header.param1 = 0;
     549            1 :         spdm_response->header.param2 = 0;
     550            1 :         spdm_response->ct_exponent = 0;
     551            1 :         spdm_response->flags =
     552              :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
     553              :             (0xFFFFFFFF ^
     554              :              (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP |
     555              :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
     556              :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP |
     557              :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP));
     558              : 
     559            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     560              :                                               false, spdm_response_size,
     561              :                                               spdm_response,
     562              :                                               response_size, response);
     563              :     }
     564            1 :         return LIBSPDM_STATUS_SUCCESS;
     565              : 
     566            1 :     case 0x13: {
     567              :         spdm_capabilities_response_t *spdm_response;
     568              :         size_t spdm_response_size;
     569              :         size_t transport_header_size;
     570              : 
     571            1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
     572            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     573            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     574              : 
     575            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     576            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     577            1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
     578            1 :         spdm_response->header.param1 = 0;
     579            1 :         spdm_response->header.param2 = 0;
     580            1 :         spdm_response->ct_exponent = 0;
     581            1 :         spdm_response->flags =
     582              :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
     583              :             (0xFFFFFFFF ^
     584              :              (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP |
     585              :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
     586              :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP |
     587              :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP));
     588            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     589              :                                               false, spdm_response_size,
     590              :                                               spdm_response,
     591              :                                               response_size, response);
     592              :     }
     593            1 :         return LIBSPDM_STATUS_SUCCESS;
     594              : 
     595            1 :     case 0x14: {
     596              :         spdm_capabilities_response_t *spdm_response;
     597              :         size_t spdm_response_size;
     598              :         size_t transport_header_size;
     599              : 
     600            1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
     601            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     602            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     603              : 
     604            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     605            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     606            1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
     607            1 :         spdm_response->header.param1 = 0;
     608            1 :         spdm_response->header.param2 = 0;
     609            1 :         spdm_response->ct_exponent = 0;
     610            1 :         spdm_response->flags =
     611              :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
     612              :             (0xFFFFFFFF ^
     613              :              (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP |
     614              :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP |
     615              :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP));
     616              : 
     617            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     618              :                                               false, spdm_response_size,
     619              :                                               spdm_response,
     620              :                                               response_size, response);
     621              :     }
     622            1 :         return LIBSPDM_STATUS_SUCCESS;
     623              : 
     624            1 :     case 0x15: {
     625              :         spdm_capabilities_response_t *spdm_response;
     626              :         size_t spdm_response_size;
     627              :         size_t transport_header_size;
     628              : 
     629            1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
     630            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     631            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     632              : 
     633            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     634            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     635            1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
     636            1 :         spdm_response->header.param1 = 0;
     637            1 :         spdm_response->header.param2 = 0;
     638            1 :         spdm_response->ct_exponent = 0;
     639            1 :         spdm_response->flags =
     640              :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
     641              :             (0xFFFFFFFF ^
     642              :              (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP |
     643              :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP |
     644              :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP |
     645              :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP));
     646              : 
     647            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     648              :                                               false, spdm_response_size,
     649              :                                               spdm_response,
     650              :                                               response_size, response);
     651              :     }
     652            1 :         return LIBSPDM_STATUS_SUCCESS;
     653              : 
     654              : 
     655            1 :     case 0x16: {
     656              :         spdm_capabilities_response_t *spdm_response;
     657              :         size_t spdm_response_size;
     658              :         size_t transport_header_size;
     659              : 
     660            1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
     661            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     662            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     663              : 
     664            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     665            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     666            1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
     667            1 :         spdm_response->header.param1 = 0;
     668            1 :         spdm_response->header.param2 = 0;
     669            1 :         spdm_response->ct_exponent = 0;
     670            1 :         spdm_response->flags =
     671              :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
     672              :             (0xFFFFFFFF ^
     673              :              (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP |
     674              :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP |
     675              :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
     676              :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP));
     677              : 
     678            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     679              :                                               false, spdm_response_size,
     680              :                                               spdm_response,
     681              :                                               response_size, response);
     682              :     }
     683            1 :         return LIBSPDM_STATUS_SUCCESS;
     684              : 
     685            1 :     case 0x17: {
     686              :         spdm_capabilities_response_t *spdm_response;
     687              :         size_t spdm_response_size;
     688              :         size_t transport_header_size;
     689              : 
     690            1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
     691            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     692            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     693              : 
     694            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     695            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     696            1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
     697            1 :         spdm_response->header.param1 = 0;
     698            1 :         spdm_response->header.param2 = 0;
     699            1 :         spdm_response->ct_exponent = 0;
     700            1 :         spdm_response->flags =
     701              :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
     702              :             (0xFFFFFFFF ^ (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP));
     703              : 
     704            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     705              :                                               false, spdm_response_size,
     706              :                                               spdm_response,
     707              :                                               response_size, response);
     708              :     }
     709            1 :         return LIBSPDM_STATUS_SUCCESS;
     710              : 
     711            1 :     case 0x18: {
     712              :         spdm_capabilities_response_t *spdm_response;
     713              :         size_t spdm_response_size;
     714              :         size_t transport_header_size;
     715              : 
     716            1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
     717            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     718            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     719              : 
     720            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     721            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     722            1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
     723            1 :         spdm_response->header.param1 = 0;
     724            1 :         spdm_response->header.param2 = 0;
     725            1 :         spdm_response->ct_exponent = 0;
     726            1 :         spdm_response->flags =
     727              :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
     728              :             (0xFFFFFFFF ^ (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP));
     729              : 
     730            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     731              :                                               false, spdm_response_size,
     732              :                                               spdm_response,
     733              :                                               response_size, response);
     734              :     }
     735            1 :         return LIBSPDM_STATUS_SUCCESS;
     736              : 
     737            1 :     case 0x19: {
     738              :         spdm_capabilities_response_t *spdm_response;
     739              :         size_t spdm_response_size;
     740              :         size_t transport_header_size;
     741              : 
     742            1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
     743            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     744            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     745              : 
     746            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     747            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     748            1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
     749            1 :         spdm_response->header.param1 = 0;
     750            1 :         spdm_response->header.param2 = 0;
     751            1 :         spdm_response->ct_exponent = 0;
     752            1 :         spdm_response->flags =
     753              :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
     754              :             (0xFFFFFFFF ^
     755              :              (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP |
     756              :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP |
     757              :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP));
     758              : 
     759            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     760              :                                               false, spdm_response_size,
     761              :                                               spdm_response,
     762              :                                               response_size, response);
     763              :     }
     764            1 :         return LIBSPDM_STATUS_SUCCESS;
     765              : 
     766            1 :     case 0x1a: {
     767              :         spdm_capabilities_response_t *spdm_response;
     768              :         size_t spdm_response_size;
     769              :         size_t transport_header_size;
     770              : 
     771            1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
     772            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     773            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     774              : 
     775            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     776            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     777            1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
     778            1 :         spdm_response->header.param1 = 0;
     779            1 :         spdm_response->header.param2 = 0;
     780            1 :         spdm_response->ct_exponent = 0;
     781            1 :         spdm_response->flags =
     782              :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 |
     783              :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PUB_KEY_ID_CAP;
     784              : 
     785            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     786              :                                               false, spdm_response_size,
     787              :                                               spdm_response,
     788              :                                               response_size, response);
     789              :     }
     790            1 :         return LIBSPDM_STATUS_SUCCESS;
     791              : 
     792            1 :     case 0x1b: {
     793              :         spdm_capabilities_response_t *spdm_response;
     794              :         size_t spdm_response_size;
     795              :         size_t transport_header_size;
     796              : 
     797            1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
     798            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     799            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     800              : 
     801            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     802            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     803            1 :         spdm_response->header.request_response_code = SPDM_GET_CAPABILITIES;
     804            1 :         spdm_response->header.param1 = 0;
     805            1 :         spdm_response->header.param2 = 0;
     806            1 :         spdm_response->ct_exponent = 0;
     807            1 :         spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11;
     808              : 
     809            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     810              :                                               false, spdm_response_size,
     811              :                                               spdm_response,
     812              :                                               response_size, response);
     813              :     }
     814            1 :         return LIBSPDM_STATUS_SUCCESS;
     815              : 
     816            1 :     case 0x1c: {
     817              :         spdm_capabilities_response_t *spdm_response;
     818              :         size_t spdm_response_size;
     819              :         size_t transport_header_size;
     820              : 
     821            1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
     822            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     823            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     824              : 
     825            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     826            1 :         spdm_response->header.spdm_version = 0xFF;
     827            1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
     828            1 :         spdm_response->header.param1 = 0;
     829            1 :         spdm_response->header.param2 = 0;
     830            1 :         spdm_response->ct_exponent = 0;
     831            1 :         spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11;
     832              : 
     833            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     834              :                                               false, spdm_response_size,
     835              :                                               spdm_response,
     836              :                                               response_size, response);
     837              :     }
     838            1 :         return LIBSPDM_STATUS_SUCCESS;
     839              : 
     840           18 :     case 0x1d: {
     841              :         static uint16_t error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
     842              : 
     843              :         spdm_error_response_t *spdm_response;
     844              :         size_t spdm_response_size;
     845              :         size_t transport_header_size;
     846              : 
     847           18 :         spdm_response_size = sizeof(spdm_error_response_t);
     848           18 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     849           18 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     850              : 
     851           18 :         if(error_code <= 0xff) {
     852           18 :             libspdm_zero_mem(spdm_response, spdm_response_size);
     853           18 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     854           18 :             spdm_response->header.request_response_code = SPDM_ERROR;
     855           18 :             spdm_response->header.param1 = (uint8_t) error_code;
     856           18 :             spdm_response->header.param2 = 0;
     857              : 
     858           18 :             libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
     859              :                                                    spdm_response_size, spdm_response,
     860              :                                                    response_size, response);
     861              :         }
     862              : 
     863           18 :         error_code++;
     864           18 :         if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
     865            1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
     866              :         }
     867              :         /* skip some reserved error codes (0d to 3e) */
     868           18 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) {
     869            1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
     870              :         }
     871              :         /* skip response not ready, request resync, and some reserved codes (44 to fc) */
     872           18 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) {
     873            1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
     874              :         }
     875              :     }
     876           18 :         return LIBSPDM_STATUS_SUCCESS;
     877              : 
     878            1 :     case 0x1e: {
     879              :         spdm_capabilities_response_t *spdm_response;
     880              :         size_t spdm_response_size;
     881              :         size_t transport_header_size;
     882              : 
     883            1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
     884            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     885            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     886              : 
     887            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     888            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
     889            1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
     890            1 :         spdm_response->header.param1 = 0;
     891            1 :         spdm_response->header.param2 = 0;
     892            1 :         spdm_response->ct_exponent = 0;
     893            1 :         spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ALIAS_CERT_CAP;
     894              : 
     895            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     896              :                                               false, spdm_response_size,
     897              :                                               spdm_response,
     898              :                                               response_size, response);
     899              :     }
     900            1 :         return LIBSPDM_STATUS_SUCCESS;
     901              : 
     902            1 :     case 0x1F:
     903            1 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
     904              : 
     905            1 :     case 0x20: {
     906              :         spdm_capabilities_response_t *spdm_response;
     907              :         size_t spdm_response_size;
     908              :         size_t transport_header_size;
     909              : 
     910            1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
     911            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     912            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     913              : 
     914            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     915            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
     916            1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
     917            1 :         spdm_response->header.param1 = 0;
     918            1 :         spdm_response->header.param2 = 0;
     919            1 :         spdm_response->ct_exponent = 0;
     920            1 :         spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CSR_CAP;
     921              : 
     922            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     923              :                                               false, spdm_response_size,
     924              :                                               spdm_response,
     925              :                                               response_size, response);
     926              :     }
     927            1 :         return LIBSPDM_STATUS_SUCCESS;
     928              : 
     929            1 :     case 0x21: {
     930              :         spdm_capabilities_response_t *spdm_response;
     931              :         size_t spdm_response_size;
     932              :         size_t transport_header_size;
     933              : 
     934            1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
     935            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     936            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     937              : 
     938            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     939            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
     940            1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
     941            1 :         spdm_response->header.param1 = 0;
     942            1 :         spdm_response->header.param2 = 0;
     943            1 :         spdm_response->ct_exponent = 0;
     944            1 :         spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_INSTALL_RESET_CAP;
     945            1 :         spdm_response->data_transfer_size = LIBSPDM_DATA_TRANSFER_SIZE;
     946            1 :         spdm_response->max_spdm_msg_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
     947            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     948              :                                               false, spdm_response_size,
     949              :                                               spdm_response,
     950              :                                               response_size, response);
     951              :     }
     952            1 :         return LIBSPDM_STATUS_SUCCESS;
     953            1 :     case 0x22: {
     954              :         spdm_capabilities_response_t *spdm_response;
     955              :         size_t spdm_response_size;
     956              :         size_t transport_header_size;
     957              : 
     958            1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
     959            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     960            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     961              : 
     962            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     963            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
     964            1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
     965            1 :         spdm_response->header.param1 = 0;
     966            1 :         spdm_response->header.param2 = 0;
     967            1 :         spdm_response->ct_exponent = 0;
     968            1 :         spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
     969            1 :         spdm_response->data_transfer_size = LIBSPDM_DATA_TRANSFER_SIZE;
     970            1 :         spdm_response->max_spdm_msg_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
     971              : 
     972            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     973              :                                               false, spdm_response_size,
     974              :                                               spdm_response,
     975              :                                               response_size, response);
     976              :     }
     977            1 :         return LIBSPDM_STATUS_SUCCESS;
     978              : 
     979            1 :     case 0x23: {
     980              :         spdm_capabilities_response_t *spdm_response;
     981              :         size_t spdm_response_size;
     982              :         size_t transport_header_size;
     983              : 
     984            1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
     985            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     986            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     987              : 
     988            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
     989            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
     990            1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
     991            1 :         spdm_response->header.param1 = 0;
     992            1 :         spdm_response->header.param2 = 0;
     993            1 :         spdm_response->ct_exponent = 0;
     994            1 :         spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
     995            1 :         spdm_response->data_transfer_size = 0;
     996            1 :         spdm_response->max_spdm_msg_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
     997              : 
     998            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     999              :                                               false, spdm_response_size,
    1000              :                                               spdm_response,
    1001              :                                               response_size, response);
    1002              :     }
    1003            1 :         return LIBSPDM_STATUS_SUCCESS;
    1004              : 
    1005            1 :     case 0x24: {
    1006              :         spdm_capabilities_response_t *spdm_response;
    1007              :         size_t spdm_response_size;
    1008              :         size_t transport_header_size;
    1009              : 
    1010            1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
    1011            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1012            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1013              : 
    1014            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
    1015            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
    1016            1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
    1017            1 :         spdm_response->header.param1 = 0;
    1018            1 :         spdm_response->header.param2 = 0;
    1019            1 :         spdm_response->ct_exponent = 0;
    1020            1 :         spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
    1021            1 :         spdm_response->data_transfer_size = LIBSPDM_DATA_TRANSFER_SIZE - 1;
    1022            1 :         spdm_response->max_spdm_msg_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
    1023              : 
    1024            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1025              :                                               false, spdm_response_size,
    1026              :                                               spdm_response,
    1027              :                                               response_size, response);
    1028              :     }
    1029            1 :         return LIBSPDM_STATUS_SUCCESS;
    1030              : 
    1031            1 :     case 0x25: {
    1032              :         spdm_capabilities_response_t *spdm_response;
    1033              :         size_t spdm_response_size;
    1034              :         size_t transport_header_size;
    1035              : 
    1036            1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
    1037            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1038            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1039              : 
    1040            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
    1041            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
    1042            1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
    1043            1 :         spdm_response->header.param1 = 0;
    1044            1 :         spdm_response->header.param2 = 0;
    1045            1 :         spdm_response->ct_exponent = 0;
    1046            1 :         spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_12;
    1047            1 :         spdm_response->data_transfer_size = LIBSPDM_DATA_TRANSFER_SIZE;
    1048            1 :         spdm_response->max_spdm_msg_size = LIBSPDM_DATA_TRANSFER_SIZE - 1;
    1049              : 
    1050            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1051              :                                               false, spdm_response_size,
    1052              :                                               spdm_response,
    1053              :                                               response_size, response);
    1054              :     }
    1055            1 :         return LIBSPDM_STATUS_SUCCESS;
    1056              : 
    1057            1 :     case 0x26: {
    1058              :         spdm_capabilities_response_t *spdm_response;
    1059              :         size_t spdm_response_size;
    1060              :         size_t transport_header_size;
    1061              : 
    1062            1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
    1063            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1064            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1065              : 
    1066            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
    1067            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
    1068            1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
    1069            1 :         spdm_response->header.param1 = 0;
    1070            1 :         spdm_response->header.param2 = 0;
    1071            1 :         spdm_response->ct_exponent = LIBSPDM_MAX_CT_EXPONENT + 1;
    1072            1 :         spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_12;
    1073            1 :         spdm_response->data_transfer_size = LIBSPDM_DATA_TRANSFER_SIZE;
    1074            1 :         spdm_response->max_spdm_msg_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
    1075              : 
    1076            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1077              :                                               false, spdm_response_size,
    1078              :                                               spdm_response,
    1079              :                                               response_size, response);
    1080              :     }
    1081            1 :         return LIBSPDM_STATUS_SUCCESS;
    1082              : 
    1083            1 :     case 0x27: {
    1084              :         spdm_capabilities_response_t *spdm_response;
    1085              :         size_t spdm_response_size;
    1086              :         size_t transport_header_size;
    1087              : 
    1088            1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
    1089            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1090            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1091              : 
    1092            1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
    1093            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
    1094            1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
    1095            1 :         spdm_response->header.param1 = 0;
    1096            1 :         spdm_response->header.param2 = 0;
    1097            1 :         spdm_response->ct_exponent = LIBSPDM_MAX_CT_EXPONENT;
    1098              :         /* CERT_CAP needs to be set if these capabilities are set. */
    1099            1 :         spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EP_INFO_CAP_SIG |
    1100              :                                SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MULTI_KEY_CAP_ONLY |
    1101              :                                SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_GET_KEY_PAIR_INFO_CAP;
    1102            1 :         spdm_response->data_transfer_size = LIBSPDM_DATA_TRANSFER_SIZE;
    1103            1 :         spdm_response->max_spdm_msg_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
    1104              : 
    1105            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1106              :                                               false, spdm_response_size,
    1107              :                                               spdm_response,
    1108              :                                               response_size, response);
    1109              :     }
    1110            1 :         return LIBSPDM_STATUS_SUCCESS;
    1111              : 
    1112            0 :     default:
    1113            0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
    1114              :     }
    1115              : }
    1116              : 
    1117            1 : static void libspdm_test_requester_get_capabilities_err_case1(void **state)
    1118              : {
    1119              :     libspdm_return_t status;
    1120              :     libspdm_test_context_t *spdm_test_context;
    1121              :     libspdm_context_t *spdm_context;
    1122              : 
    1123            1 :     spdm_test_context = *state;
    1124            1 :     spdm_context = spdm_test_context->spdm_context;
    1125            1 :     spdm_test_context->case_id = 0x1;
    1126            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
    1127              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1128            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1129              : 
    1130            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1131            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
    1132            1 :     status = libspdm_get_capabilities(spdm_context);
    1133            1 :     assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL);
    1134            1 : }
    1135              : 
    1136              : /**
    1137              :  * Test 2: Responder sets MEAS_FRESH_CAP but does not set MEAS_CAP.
    1138              :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
    1139              :  **/
    1140            1 : static void libspdm_test_requester_get_capabilities_err_case2(void **state)
    1141              : {
    1142              :     libspdm_return_t status;
    1143              :     libspdm_test_context_t *spdm_test_context;
    1144              :     libspdm_context_t *spdm_context;
    1145              : 
    1146            1 :     spdm_test_context = *state;
    1147            1 :     spdm_context = spdm_test_context->spdm_context;
    1148            1 :     spdm_test_context->case_id = 0x2;
    1149            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
    1150              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1151            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1152              : 
    1153            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1154            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
    1155            1 :     status = libspdm_get_capabilities(spdm_context);
    1156            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    1157            1 : }
    1158              : 
    1159            1 : static void libspdm_test_requester_get_capabilities_err_case3(void **state)
    1160              : {
    1161              :     libspdm_return_t status;
    1162              :     libspdm_test_context_t *spdm_test_context;
    1163              :     libspdm_context_t *spdm_context;
    1164              : 
    1165            1 :     spdm_test_context = *state;
    1166            1 :     spdm_context = spdm_test_context->spdm_context;
    1167            1 :     spdm_test_context->case_id = 0x3;
    1168            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
    1169              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1170            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NOT_STARTED;
    1171              : 
    1172            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1173            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
    1174            1 :     status = libspdm_get_capabilities(spdm_context);
    1175            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_STATE_LOCAL);
    1176            1 : }
    1177              : 
    1178            1 : static void libspdm_test_requester_get_capabilities_err_case4(void **state)
    1179              : {
    1180              :     libspdm_return_t status;
    1181              :     libspdm_test_context_t *spdm_test_context;
    1182              :     libspdm_context_t *spdm_context;
    1183              : 
    1184            1 :     spdm_test_context = *state;
    1185            1 :     spdm_context = spdm_test_context->spdm_context;
    1186            1 :     spdm_test_context->case_id = 0x4;
    1187            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
    1188              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1189            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1190              : 
    1191            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1192            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
    1193            1 :     status = libspdm_get_capabilities(spdm_context);
    1194            1 :     assert_int_equal(status, LIBSPDM_STATUS_ERROR_PEER);
    1195            1 : }
    1196              : 
    1197            1 : static void libspdm_test_requester_get_capabilities_err_case5(void **state)
    1198              : {
    1199              :     libspdm_return_t status;
    1200              :     libspdm_test_context_t *spdm_test_context;
    1201              :     libspdm_context_t *spdm_context;
    1202              : 
    1203            1 :     spdm_test_context = *state;
    1204            1 :     spdm_context = spdm_test_context->spdm_context;
    1205            1 :     spdm_test_context->case_id = 0x5;
    1206            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
    1207              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1208            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1209              : 
    1210            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1211            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
    1212            1 :     status = libspdm_get_capabilities(spdm_context);
    1213            1 :     assert_int_equal(status, LIBSPDM_STATUS_BUSY_PEER);
    1214            1 : }
    1215              : 
    1216              : /**
    1217              :  * Test 6: Responder sets illegal SPDM 1.0 combination of MEAS_CAP (no signature), CERT_CAP,
    1218              :  *         and CHAL_CAP.
    1219              :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
    1220              :  **/
    1221            1 : static void libspdm_test_requester_get_capabilities_err_case6(void **state)
    1222              : {
    1223              :     libspdm_return_t status;
    1224              :     libspdm_test_context_t *spdm_test_context;
    1225              :     libspdm_context_t *spdm_context;
    1226              : 
    1227            1 :     spdm_test_context = *state;
    1228            1 :     spdm_context = spdm_test_context->spdm_context;
    1229            1 :     spdm_test_context->case_id = 0x6;
    1230            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
    1231              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1232            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1233              : 
    1234            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1235            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
    1236            1 :     status = libspdm_get_capabilities(spdm_context);
    1237            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    1238            1 : }
    1239              : 
    1240            1 : static void libspdm_test_requester_get_capabilities_err_case7(void **state)
    1241              : {
    1242              :     libspdm_return_t status;
    1243              :     libspdm_test_context_t *spdm_test_context;
    1244              :     libspdm_context_t *spdm_context;
    1245              : 
    1246            1 :     spdm_test_context = *state;
    1247            1 :     spdm_context = spdm_test_context->spdm_context;
    1248            1 :     spdm_test_context->case_id = 0x7;
    1249            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
    1250              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1251            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1252              : 
    1253            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1254            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
    1255            1 :     status = libspdm_get_capabilities(spdm_context);
    1256            1 :     assert_int_equal(status, LIBSPDM_STATUS_RESYNCH_PEER);
    1257            1 :     assert_int_equal(spdm_context->connection_info.connection_state,
    1258              :                      LIBSPDM_CONNECTION_STATE_NOT_STARTED);
    1259            1 : }
    1260              : 
    1261            1 : static void libspdm_test_requester_get_capabilities_err_case8(void **state)
    1262              : {
    1263              :     libspdm_return_t status;
    1264              :     libspdm_test_context_t *spdm_test_context;
    1265              :     libspdm_context_t *spdm_context;
    1266              : 
    1267            1 :     spdm_test_context = *state;
    1268            1 :     spdm_context = spdm_test_context->spdm_context;
    1269            1 :     spdm_test_context->case_id = 0x8;
    1270            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
    1271              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1272            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1273              : 
    1274            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1275            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
    1276            1 :     status = libspdm_get_capabilities(spdm_context);
    1277            1 :     assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
    1278            1 : }
    1279              : 
    1280              : /**
    1281              :  * Test 9: Responder returns a Reserved MEAS_CAP value.
    1282              :  * Expected behavior: returns a status of LIBSPDM_STATUS_INVALID_MSG_FIELD.
    1283              :  **/
    1284            1 : static void libspdm_test_requester_get_capabilities_err_case9(void **state)
    1285              : {
    1286              :     libspdm_return_t status;
    1287              :     libspdm_test_context_t *spdm_test_context;
    1288              :     libspdm_context_t *spdm_context;
    1289              : 
    1290            1 :     spdm_test_context = *state;
    1291            1 :     spdm_context = spdm_test_context->spdm_context;
    1292            1 :     spdm_test_context->case_id = 0x9;
    1293            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
    1294              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1295            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1296              : 
    1297            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1298            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
    1299            1 :     status = libspdm_get_capabilities(spdm_context);
    1300            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    1301            1 : }
    1302              : 
    1303              : /**
    1304              :  * Test 10: Responder sets illegal SPDM 1.0 combination of MEAS_CAP (with signature), CERT_CAP,
    1305              :  *          and CHAL_CAP.
    1306              :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
    1307              :  **/
    1308            1 : static void libspdm_test_requester_get_capabilities_err_case10(void **state)
    1309              : {
    1310              :     libspdm_return_t status;
    1311              :     libspdm_test_context_t *spdm_test_context;
    1312              :     libspdm_context_t *spdm_context;
    1313              : 
    1314            1 :     spdm_test_context = *state;
    1315            1 :     spdm_context = spdm_test_context->spdm_context;
    1316            1 :     spdm_test_context->case_id = 0xa;
    1317            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
    1318              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1319            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1320              : 
    1321            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1322            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
    1323            1 :     status = libspdm_get_capabilities(spdm_context);
    1324            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    1325            1 : }
    1326              : 
    1327              : /**
    1328              :  * Test 11: Responder sets illegal 1.1/1.2 PSK_CAP value (3).
    1329              :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
    1330              :  **/
    1331            1 : static void libspdm_test_requester_get_capabilities_err_case11(void **state)
    1332              : {
    1333              :     libspdm_return_t status;
    1334              :     libspdm_test_context_t *spdm_test_context;
    1335              :     libspdm_context_t *spdm_context;
    1336              : 
    1337            1 :     spdm_test_context = *state;
    1338            1 :     spdm_context = spdm_test_context->spdm_context;
    1339            1 :     spdm_test_context->case_id = 0xb;
    1340            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    1341              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1342            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1343              : 
    1344            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1345            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
    1346            1 :     status = libspdm_get_capabilities(spdm_context);
    1347            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    1348            1 : }
    1349              : 
    1350              : /**
    1351              :  * Test 11: Responder sets illegal 1.1/1.2 combination of values.
    1352              :  *          CERT_CAP enabled.
    1353              :  *          CHAL_CAP and KEY_EX_CAP disabled.
    1354              :  *          MEAS_CAP with signature is disabled.
    1355              :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
    1356              :  **/
    1357            1 : static void libspdm_test_requester_get_capabilities_err_case12(void **state)
    1358              : {
    1359              :     libspdm_return_t status;
    1360              :     libspdm_test_context_t *spdm_test_context;
    1361              :     libspdm_context_t *spdm_context;
    1362              : 
    1363            1 :     spdm_test_context = *state;
    1364            1 :     spdm_context = spdm_test_context->spdm_context;
    1365            1 :     spdm_test_context->case_id = 0xc;
    1366            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    1367              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1368            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1369              : 
    1370            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1371            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
    1372            1 :     status = libspdm_get_capabilities(spdm_context);
    1373            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    1374            1 : }
    1375              : 
    1376            1 : static void libspdm_test_requester_get_capabilities_err_case13(void **state)
    1377              : {
    1378              :     libspdm_return_t status;
    1379              :     libspdm_test_context_t *spdm_test_context;
    1380              :     libspdm_context_t *spdm_context;
    1381              : 
    1382            1 :     spdm_test_context = *state;
    1383            1 :     spdm_context = spdm_test_context->spdm_context;
    1384            1 :     spdm_test_context->case_id = 0xd;
    1385            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
    1386              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1387            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1388              : 
    1389            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1390            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
    1391            1 :     status = libspdm_get_capabilities(spdm_context);
    1392            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
    1393            1 : }
    1394              : 
    1395            1 : static void libspdm_test_requester_get_capabilities_err_case14(void **state)
    1396              : {
    1397              :     libspdm_return_t status;
    1398              :     libspdm_test_context_t *spdm_test_context;
    1399              :     libspdm_context_t *spdm_context;
    1400              : 
    1401            1 :     spdm_test_context = *state;
    1402            1 :     spdm_context = spdm_test_context->spdm_context;
    1403            1 :     spdm_test_context->case_id = 0xe;
    1404            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
    1405              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1406            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1407              : 
    1408            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1409            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
    1410            1 :     status = libspdm_get_capabilities(spdm_context);
    1411            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
    1412            1 : }
    1413              : 
    1414            1 : static void libspdm_test_requester_get_capabilities_err_case15(void **state)
    1415              : {
    1416              :     libspdm_return_t status;
    1417              :     libspdm_test_context_t *spdm_test_context;
    1418              :     libspdm_context_t *spdm_context;
    1419              : 
    1420            1 :     spdm_test_context = *state;
    1421            1 :     spdm_context = spdm_test_context->spdm_context;
    1422            1 :     spdm_test_context->case_id = 0xf;
    1423            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
    1424              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1425            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1426              : 
    1427            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1428            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
    1429            1 :     status = libspdm_get_capabilities(spdm_context);
    1430            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
    1431            1 : }
    1432              : 
    1433              : /**
    1434              :  * Test 16: Responder sets illegal 1.1/1.2 combination of values.
    1435              :  *          CERT_CAP and PUB_KEY_ID_CAP disabled.
    1436              :  *          At least one of CHAL_CAP, KEY_EX_CAP, MEAS_CAP (with signature), or MUT_AUTH_CAP
    1437              :  *          is enabled.
    1438              :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
    1439              :  **/
    1440            1 : static void libspdm_test_requester_get_capabilities_err_case16(void **state)
    1441              : {
    1442              :     libspdm_return_t status;
    1443              :     libspdm_test_context_t *spdm_test_context;
    1444              :     libspdm_context_t *spdm_context;
    1445              : 
    1446            1 :     spdm_test_context = *state;
    1447            1 :     spdm_context = spdm_test_context->spdm_context;
    1448            1 :     spdm_test_context->case_id = 0x10;
    1449            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    1450              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1451            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1452              : 
    1453            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1454            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
    1455            1 :     status = libspdm_get_capabilities(spdm_context);
    1456            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    1457            1 : }
    1458              : 
    1459            1 : static void libspdm_test_requester_get_capabilities_err_case17(void **state)
    1460              : {
    1461              :     libspdm_return_t status;
    1462              :     libspdm_test_context_t *spdm_test_context;
    1463              :     libspdm_context_t *spdm_context;
    1464              : 
    1465            1 :     spdm_test_context = *state;
    1466            1 :     spdm_context = spdm_test_context->spdm_context;
    1467            1 :     spdm_test_context->case_id = 0x11;
    1468            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    1469              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1470            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1471              : 
    1472            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1473            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
    1474            1 :     status = libspdm_get_capabilities(spdm_context);
    1475            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    1476              :     /*assert_int_equal (spdm_context->connection_info.capability.ct_exponent, 0);
    1477              :      * assert_int_equal (spdm_context->connection_info.capability.flags, LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 & (0xFFFFFFFF^(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)));*/
    1478            1 : }
    1479              : 
    1480            1 : static void libspdm_test_requester_get_capabilities_err_case18(void **state)
    1481              : {
    1482              :     libspdm_return_t status;
    1483              :     libspdm_test_context_t *spdm_test_context;
    1484              :     libspdm_context_t *spdm_context;
    1485              : 
    1486            1 :     spdm_test_context = *state;
    1487            1 :     spdm_context = spdm_test_context->spdm_context;
    1488            1 :     spdm_test_context->case_id = 0x12;
    1489            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    1490              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1491            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1492              : 
    1493            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1494            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
    1495            1 :     status = libspdm_get_capabilities(spdm_context);
    1496            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    1497              :     /*assert_int_equal (spdm_context->connection_info.capability.ct_exponent, 0);
    1498              :      * assert_int_equal (spdm_context->connection_info.capability.flags, LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 & (0xFFFFFFFF^(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)));*/
    1499            1 : }
    1500              : 
    1501            1 : static void libspdm_test_requester_get_capabilities_err_case19(void **state)
    1502              : {
    1503              :     libspdm_return_t status;
    1504              :     libspdm_test_context_t *spdm_test_context;
    1505              :     libspdm_context_t *spdm_context;
    1506              : 
    1507            1 :     spdm_test_context = *state;
    1508            1 :     spdm_context = spdm_test_context->spdm_context;
    1509            1 :     spdm_test_context->case_id = 0x13;
    1510            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    1511              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1512            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1513            1 :     libspdm_reset_message_a(spdm_context);
    1514              : 
    1515            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1516            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
    1517            1 :     status = libspdm_get_capabilities(spdm_context);
    1518            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    1519              :     /*assert_int_equal (spdm_context->connection_info.capability.ct_exponent, 0);
    1520              :      * assert_int_equal (spdm_context->connection_info.capability.flags, LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 & (0xFFFFFFFF^(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)));*/
    1521            1 : }
    1522              : 
    1523            1 : static void libspdm_test_requester_get_capabilities_err_case20(void **state)
    1524              : {
    1525              :     libspdm_return_t status;
    1526              :     libspdm_test_context_t *spdm_test_context;
    1527              :     libspdm_context_t *spdm_context;
    1528              : 
    1529            1 :     spdm_test_context = *state;
    1530            1 :     spdm_context = spdm_test_context->spdm_context;
    1531            1 :     spdm_test_context->case_id = 0x14;
    1532            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    1533              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1534            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1535            1 :     libspdm_reset_message_a(spdm_context);
    1536              : 
    1537            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1538            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
    1539            1 :     status = libspdm_get_capabilities(spdm_context);
    1540            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    1541            1 : }
    1542              : 
    1543            1 : static void libspdm_test_requester_get_capabilities_err_case21(void **state)
    1544              : {
    1545              :     libspdm_return_t status;
    1546              :     libspdm_test_context_t *spdm_test_context;
    1547              :     libspdm_context_t *spdm_context;
    1548              : 
    1549            1 :     spdm_test_context = *state;
    1550            1 :     spdm_context = spdm_test_context->spdm_context;
    1551            1 :     spdm_test_context->case_id = 0x15;
    1552            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    1553              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1554            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1555            1 :     libspdm_reset_message_a(spdm_context);
    1556              : 
    1557            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1558            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
    1559            1 :     status = libspdm_get_capabilities(spdm_context);
    1560            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    1561            1 : }
    1562              : 
    1563            1 : static void libspdm_test_requester_get_capabilities_err_case22(void **state)
    1564              : {
    1565              :     libspdm_return_t status;
    1566              :     libspdm_test_context_t *spdm_test_context;
    1567              :     libspdm_context_t *spdm_context;
    1568              : 
    1569            1 :     spdm_test_context = *state;
    1570            1 :     spdm_context = spdm_test_context->spdm_context;
    1571            1 :     spdm_test_context->case_id = 0x16;
    1572            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    1573              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1574            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1575            1 :     libspdm_reset_message_a(spdm_context);
    1576              : 
    1577            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1578            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
    1579            1 :     status = libspdm_get_capabilities(spdm_context);
    1580            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    1581            1 : }
    1582              : 
    1583            1 : static void libspdm_test_requester_get_capabilities_err_case23(void **state)
    1584              : {
    1585              :     libspdm_return_t status;
    1586              :     libspdm_test_context_t *spdm_test_context;
    1587              :     libspdm_context_t *spdm_context;
    1588              : 
    1589            1 :     spdm_test_context = *state;
    1590            1 :     spdm_context = spdm_test_context->spdm_context;
    1591            1 :     spdm_test_context->case_id = 0x17;
    1592            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    1593              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1594            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1595            1 :     libspdm_reset_message_a(spdm_context);
    1596              : 
    1597            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1598            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
    1599            1 :     status = libspdm_get_capabilities(spdm_context);
    1600            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    1601              :     /*assert_int_equal (spdm_context->connection_info.capability.ct_exponent, 0);
    1602              :      * assert_int_equal (spdm_context->connection_info.capability.flags, LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 & (0xFFFFFFFF^(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP)));*/
    1603            1 : }
    1604              : 
    1605            1 : static void libspdm_test_requester_get_capabilities_err_case24(void **state)
    1606              : {
    1607              :     libspdm_return_t status;
    1608              :     libspdm_test_context_t *spdm_test_context;
    1609              :     libspdm_context_t *spdm_context;
    1610              : 
    1611            1 :     spdm_test_context = *state;
    1612            1 :     spdm_context = spdm_test_context->spdm_context;
    1613            1 :     spdm_test_context->case_id = 0x18;
    1614            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    1615              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1616            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1617            1 :     libspdm_reset_message_a(spdm_context);
    1618              : 
    1619            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1620            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
    1621            1 :     status = libspdm_get_capabilities(spdm_context);
    1622            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    1623              :     /*assert_int_equal (spdm_context->connection_info.capability.ct_exponent, 0);
    1624              :      * assert_int_equal (spdm_context->connection_info.capability.flags, LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 & (0xFFFFFFFF^(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP)));*/
    1625            1 : }
    1626              : 
    1627            1 : static void libspdm_test_requester_get_capabilities_err_case25(void **state)
    1628              : {
    1629              :     libspdm_return_t status;
    1630              :     libspdm_test_context_t *spdm_test_context;
    1631              :     libspdm_context_t *spdm_context;
    1632              : 
    1633            1 :     spdm_test_context = *state;
    1634            1 :     spdm_context = spdm_test_context->spdm_context;
    1635            1 :     spdm_test_context->case_id = 0x19;
    1636            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    1637              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1638            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1639            1 :     libspdm_reset_message_a(spdm_context);
    1640              : 
    1641            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1642            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
    1643            1 :     status = libspdm_get_capabilities(spdm_context);
    1644            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    1645            1 : }
    1646              : 
    1647            1 : static void libspdm_test_requester_get_capabilities_err_case26(void **state)
    1648              : {
    1649              :     libspdm_return_t status;
    1650              :     libspdm_test_context_t *spdm_test_context;
    1651              :     libspdm_context_t *spdm_context;
    1652              : 
    1653            1 :     spdm_test_context = *state;
    1654            1 :     spdm_context = spdm_test_context->spdm_context;
    1655            1 :     spdm_test_context->case_id = 0x1a;
    1656            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    1657              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1658            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1659            1 :     libspdm_reset_message_a(spdm_context);
    1660              : 
    1661            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1662            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
    1663            1 :     status = libspdm_get_capabilities(spdm_context);
    1664            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    1665              :     /*assert_int_equal (spdm_context->connection_info.capability.ct_exponent, 0);
    1666              :      * assert_int_equal (spdm_context->connection_info.capability.flags, LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PUB_KEY_ID_CAP);*/
    1667            1 : }
    1668              : 
    1669            1 : static void libspdm_test_requester_get_capabilities_err_case27(void **state)
    1670              : {
    1671              :     libspdm_return_t status;
    1672              :     libspdm_test_context_t *spdm_test_context;
    1673              :     libspdm_context_t *spdm_context;
    1674              : 
    1675            1 :     spdm_test_context = *state;
    1676            1 :     spdm_context = spdm_test_context->spdm_context;
    1677            1 :     spdm_test_context->case_id = 0x1b;
    1678            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    1679              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1680            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1681            1 :     libspdm_reset_message_a(spdm_context);
    1682              : 
    1683            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1684            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
    1685            1 :     status = libspdm_get_capabilities(spdm_context);
    1686            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    1687            1 : }
    1688              : 
    1689            1 : static void libspdm_test_requester_get_capabilities_err_case28(void **state)
    1690              : {
    1691              :     libspdm_return_t status;
    1692              :     libspdm_test_context_t *spdm_test_context;
    1693              :     libspdm_context_t *spdm_context;
    1694              : 
    1695            1 :     spdm_test_context = *state;
    1696            1 :     spdm_context = spdm_test_context->spdm_context;
    1697            1 :     spdm_test_context->case_id = 0x1c;
    1698            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    1699              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1700            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1701            1 :     libspdm_reset_message_a(spdm_context);
    1702              : 
    1703            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1704            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
    1705            1 :     status = libspdm_get_capabilities(spdm_context);
    1706            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    1707            1 : }
    1708              : 
    1709            1 : static void libspdm_test_requester_get_capabilities_err_case29(void **state) {
    1710              :     libspdm_return_t status;
    1711              :     libspdm_test_context_t    *spdm_test_context;
    1712              :     libspdm_context_t  *spdm_context;
    1713              :     uint16_t error_code;
    1714              : 
    1715            1 :     spdm_test_context = *state;
    1716            1 :     spdm_context = spdm_test_context->spdm_context;
    1717            1 :     spdm_test_context->case_id = 0x1d;
    1718            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    1719              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1720            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1721            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
    1722              : 
    1723            1 :     error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
    1724           19 :     while(error_code <= 0xff) {
    1725           18 :         spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1726           18 :         libspdm_reset_message_a(spdm_context);
    1727              : 
    1728           18 :         status = libspdm_get_capabilities (spdm_context);
    1729           18 :         LIBSPDM_ASSERT_INT_EQUAL_CASE (status, LIBSPDM_STATUS_ERROR_PEER, error_code);
    1730              : 
    1731           18 :         error_code++;
    1732           18 :         if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
    1733            1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
    1734              :         }
    1735              :         /* skip some reserved error codes (0d to 3e) */
    1736           18 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) {
    1737            1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
    1738              :         }
    1739              :         /* skip response not ready, request resync, and some reserved codes (44 to fc) */
    1740           18 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) {
    1741            1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
    1742              :         }
    1743              :     }
    1744            1 : }
    1745              : 
    1746              : /**
    1747              :  * Test 30: Responder sets illegal 1.2 combination of values.
    1748              :  *          CERT_CAP is disabled.
    1749              :  *          ALIAS_CERT_CAP is enabled.
    1750              :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
    1751              :  **/
    1752            1 : static void libspdm_test_requester_get_capabilities_err_case30(void **state)
    1753              : {
    1754              :     libspdm_return_t status;
    1755              :     libspdm_test_context_t *spdm_test_context;
    1756              :     libspdm_context_t *spdm_context;
    1757              : 
    1758            1 :     spdm_test_context = *state;
    1759            1 :     spdm_context = spdm_test_context->spdm_context;
    1760            1 :     spdm_test_context->case_id = 0x1E;
    1761            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
    1762              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1763            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1764              : 
    1765            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1766            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
    1767            1 :     status = libspdm_get_capabilities(spdm_context);
    1768            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    1769            1 : }
    1770              : 
    1771            1 : static void libspdm_test_requester_get_capabilities_err_case31(void **state)
    1772              : {
    1773              :     libspdm_return_t status;
    1774              :     libspdm_test_context_t *spdm_test_context;
    1775              :     libspdm_context_t *spdm_context;
    1776              : 
    1777            1 :     spdm_test_context = *state;
    1778            1 :     spdm_context = spdm_test_context->spdm_context;
    1779            1 :     spdm_test_context->case_id = 0x1F;
    1780            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
    1781              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1782            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1783            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1784            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
    1785            1 :     status = libspdm_get_capabilities(spdm_context);
    1786            1 :     assert_int_equal(status, LIBSPDM_STATUS_RECEIVE_FAIL);
    1787            1 : }
    1788              : 
    1789              : /**
    1790              :  * Test 32: Responder sets illegal 1.2 combination of values.
    1791              :  *          CSR_CAP is enabled.
    1792              :  *          SET_CERT_CAP is disabled.
    1793              :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
    1794              :  **/
    1795            1 : static void libspdm_test_requester_get_capabilities_err_case32(void **state)
    1796              : {
    1797              :     libspdm_return_t status;
    1798              :     libspdm_test_context_t *spdm_test_context;
    1799              :     libspdm_context_t *spdm_context;
    1800              : 
    1801            1 :     spdm_test_context = *state;
    1802            1 :     spdm_context = spdm_test_context->spdm_context;
    1803            1 :     spdm_test_context->case_id = 0x20;
    1804            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
    1805              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1806            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1807              : 
    1808            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1809            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
    1810            1 :     status = libspdm_get_capabilities(spdm_context);
    1811            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    1812            1 : }
    1813              : 
    1814              : /**
    1815              :  * Test 33: Responder sets illegal 1.2 combination of values.
    1816              :  *          CERT_INSTALL_RESET_CAP is enabled.
    1817              :  *          CSR_CAP and SET_CERT_CAP are disabled.
    1818              :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
    1819              :  **/
    1820            1 : static void libspdm_test_requester_get_capabilities_err_case33(void **state)
    1821              : {
    1822              :     libspdm_return_t status;
    1823              :     libspdm_test_context_t *spdm_test_context;
    1824              :     libspdm_context_t *spdm_context;
    1825              : 
    1826            1 :     spdm_test_context = *state;
    1827            1 :     spdm_context = spdm_test_context->spdm_context;
    1828            1 :     spdm_test_context->case_id = 0x21;
    1829            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
    1830              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1831            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1832              : 
    1833            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1834            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
    1835            1 :     status = libspdm_get_capabilities(spdm_context);
    1836            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    1837            1 : }
    1838              : 
    1839            1 : static void libspdm_test_requester_get_capabilities_err_case34(void **state)
    1840              : {
    1841              :     libspdm_return_t status;
    1842              :     libspdm_test_context_t *spdm_test_context;
    1843              :     libspdm_context_t *spdm_context;
    1844              : 
    1845            1 :     spdm_test_context = *state;
    1846            1 :     spdm_context = spdm_test_context->spdm_context;
    1847            1 :     spdm_test_context->case_id = 0x22;
    1848              : 
    1849            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
    1850              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1851            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1852            1 :     spdm_context->transcript.message_a.buffer_size =
    1853            1 :         spdm_context->transcript.message_a.max_buffer_size;
    1854            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1855            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
    1856            1 :     status = libspdm_get_capabilities(spdm_context);
    1857            1 :     assert_int_equal(status, LIBSPDM_STATUS_BUFFER_FULL);
    1858              : 
    1859            1 :     spdm_context->transcript.message_a.buffer_size = 0;
    1860            1 : }
    1861              : 
    1862              : /**
    1863              :  * Test 35: Unable to acquire sender buffer.
    1864              :  * Expected behavior: returns with status LIBSPDM_STATUS_ACQUIRE_FAIL.
    1865              :  **/
    1866            1 : static void libspdm_test_requester_get_capabilities_err_case35(void **state)
    1867              : {
    1868              :     libspdm_return_t status;
    1869              :     libspdm_test_context_t *spdm_test_context;
    1870              :     libspdm_context_t *spdm_context;
    1871              : 
    1872            1 :     spdm_test_context = *state;
    1873            1 :     spdm_context = spdm_test_context->spdm_context;
    1874            1 :     spdm_test_context->case_id = 0x3;
    1875            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
    1876              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1877            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1878              : 
    1879            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1880            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
    1881              : 
    1882            1 :     libspdm_force_error (LIBSPDM_ERR_ACQUIRE_SENDER_BUFFER);
    1883            1 :     status = libspdm_get_capabilities(spdm_context);
    1884            1 :     libspdm_release_error (LIBSPDM_ERR_ACQUIRE_SENDER_BUFFER);
    1885              : 
    1886            1 :     assert_int_equal(status, LIBSPDM_STATUS_ACQUIRE_FAIL);
    1887            1 : }
    1888              : 
    1889              : /**
    1890              :  * Test 36: Unable to acquire receiver buffer.
    1891              :  * Expected behavior: returns with status LIBSPDM_STATUS_ACQUIRE_FAIL.
    1892              :  **/
    1893            1 : static void libspdm_test_requester_get_capabilities_err_case36(void **state)
    1894              : {
    1895              :     libspdm_return_t status;
    1896              :     libspdm_test_context_t *spdm_test_context;
    1897              :     libspdm_context_t *spdm_context;
    1898              : 
    1899            1 :     spdm_test_context = *state;
    1900            1 :     spdm_context = spdm_test_context->spdm_context;
    1901            1 :     spdm_test_context->case_id = 0x3;
    1902            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
    1903              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1904            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1905              : 
    1906            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1907            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
    1908              : 
    1909            1 :     libspdm_force_error (LIBSPDM_ERR_ACQUIRE_RECEIVER_BUFFER);
    1910            1 :     status = libspdm_get_capabilities(spdm_context);
    1911            1 :     libspdm_release_error (LIBSPDM_ERR_ACQUIRE_RECEIVER_BUFFER);
    1912              : 
    1913            1 :     assert_int_equal(status, LIBSPDM_STATUS_ACQUIRE_FAIL);
    1914            1 : }
    1915              : 
    1916              : /**
    1917              :  * Test 37: Responder sets illegal DataTransferSize that is less than MinDataTransferSize.
    1918              :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
    1919              :  **/
    1920            1 : static void libspdm_test_requester_get_capabilities_err_case37(void **state)
    1921              : {
    1922              :     libspdm_return_t status;
    1923              :     libspdm_test_context_t *spdm_test_context;
    1924              :     libspdm_context_t *spdm_context;
    1925              : 
    1926            1 :     spdm_test_context = *state;
    1927            1 :     spdm_context = spdm_test_context->spdm_context;
    1928            1 :     spdm_test_context->case_id = 0x23;
    1929            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
    1930              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1931            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1932              : 
    1933            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1934            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
    1935              : 
    1936            1 :     status = libspdm_get_capabilities(spdm_context);
    1937              : 
    1938            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    1939            1 : }
    1940              : 
    1941              : /**
    1942              :  * Test 38: Responder does not support chunking but also does not set DataTransferSize equal
    1943              :  *          to MaxSPDMmsgSize.
    1944              :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
    1945              :  **/
    1946            1 : static void libspdm_test_requester_get_capabilities_err_case38(void **state)
    1947              : {
    1948              :     libspdm_return_t status;
    1949              :     libspdm_test_context_t *spdm_test_context;
    1950              :     libspdm_context_t *spdm_context;
    1951              : 
    1952            1 :     spdm_test_context = *state;
    1953            1 :     spdm_context = spdm_test_context->spdm_context;
    1954            1 :     spdm_test_context->case_id = 0x24;
    1955            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
    1956              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1957            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1958              : 
    1959            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1960            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
    1961              : 
    1962            1 :     status = libspdm_get_capabilities(spdm_context);
    1963              : 
    1964            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    1965            1 : }
    1966              : 
    1967              : /**
    1968              :  * Test 39: Responder sets illegal MaxSPDMmsgSize that is less than DataTransferSize.
    1969              :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
    1970              :  **/
    1971            1 : static void libspdm_test_requester_get_capabilities_err_case39(void **state)
    1972              : {
    1973              :     libspdm_return_t status;
    1974              :     libspdm_test_context_t *spdm_test_context;
    1975              :     libspdm_context_t *spdm_context;
    1976              : 
    1977            1 :     spdm_test_context = *state;
    1978            1 :     spdm_context = spdm_test_context->spdm_context;
    1979            1 :     spdm_test_context->case_id = 0x25;
    1980            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
    1981              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1982            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    1983              : 
    1984            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    1985            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
    1986              : 
    1987            1 :     status = libspdm_get_capabilities(spdm_context);
    1988              : 
    1989            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    1990            1 : }
    1991              : 
    1992              : /**
    1993              :  * Test 40: Responder returns a CTExponent value that is larger than LIBSPDM_MAX_CT_EXPONENT.
    1994              :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
    1995              :  **/
    1996            1 : static void libspdm_test_requester_get_capabilities_err_case40(void **state)
    1997              : {
    1998              :     libspdm_return_t status;
    1999              :     libspdm_test_context_t *spdm_test_context;
    2000              :     libspdm_context_t *spdm_context;
    2001              : 
    2002            1 :     spdm_test_context = *state;
    2003            1 :     spdm_context = spdm_test_context->spdm_context;
    2004            1 :     spdm_test_context->case_id = 0x26;
    2005            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
    2006              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    2007            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    2008              : 
    2009            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    2010            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
    2011              : 
    2012            1 :     status = libspdm_get_capabilities(spdm_context);
    2013              : 
    2014            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    2015            1 : }
    2016              : 
    2017              : /**
    2018              :  * Test 41: Responder sets MULTI_KEY_CAP but does not set CERT_CAP.
    2019              :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
    2020              :  **/
    2021            1 : static void libspdm_test_requester_get_capabilities_err_case41(void **state)
    2022              : {
    2023              :     libspdm_return_t status;
    2024              :     libspdm_test_context_t *spdm_test_context;
    2025              :     libspdm_context_t *spdm_context;
    2026              : 
    2027            1 :     spdm_test_context = *state;
    2028            1 :     spdm_context = spdm_test_context->spdm_context;
    2029            1 :     spdm_test_context->case_id = 0x27;
    2030            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
    2031              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    2032            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
    2033              : 
    2034            1 :     spdm_context->local_context.capability.ct_exponent = 0;
    2035            1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
    2036              : 
    2037            1 :     status = libspdm_get_capabilities(spdm_context);
    2038              : 
    2039            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    2040            1 : }
    2041              : 
    2042            1 : int libspdm_req_get_capabilities_error_test(void)
    2043              : {
    2044            1 :     const struct CMUnitTest test_cases[] = {
    2045              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case1),
    2046              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case2),
    2047              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case3),
    2048              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case4),
    2049              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case5),
    2050              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case6),
    2051              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case7),
    2052              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case8),
    2053              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case9),
    2054              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case10),
    2055              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case11),
    2056              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case12),
    2057              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case13),
    2058              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case14),
    2059              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case15),
    2060              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case16),
    2061              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case17),
    2062              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case18),
    2063              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case19),
    2064              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case20),
    2065              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case21),
    2066              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case22),
    2067              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case23),
    2068              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case24),
    2069              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case25),
    2070              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case26),
    2071              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case27),
    2072              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case28),
    2073              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case29),
    2074              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case30),
    2075              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case31),
    2076              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case32),
    2077              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case33),
    2078              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case34),
    2079              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case35),
    2080              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case36),
    2081              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case37),
    2082              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case38),
    2083              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case39),
    2084              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case40),
    2085              :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case41),
    2086              :     };
    2087              : 
    2088            1 :     libspdm_test_context_t test_context = {
    2089              :         LIBSPDM_TEST_CONTEXT_VERSION,
    2090              :         true,
    2091              :         send_message,
    2092              :         receive_message,
    2093              :     };
    2094              : 
    2095            1 :     libspdm_setup_test_context(&test_context);
    2096              : 
    2097            1 :     return cmocka_run_group_tests(test_cases,
    2098              :                                   libspdm_unit_test_group_setup,
    2099              :                                   libspdm_unit_test_group_teardown);
    2100              : }
        

Generated by: LCOV version 2.0-1