LCOV - code coverage report
Current view: top level - library/spdm_responder_lib - libspdm_rsp_encap_send_event.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 75.0 % 48 36
Test Date: 2025-08-24 08:11:14 Functions: 100.0 % 2 2

            Line data    Source code
       1              : /**
       2              :  *  Copyright Notice:
       3              :  *  Copyright 2025 DMTF. All rights reserved.
       4              :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
       5              :  **/
       6              : 
       7              : #include "internal/libspdm_responder_lib.h"
       8              : 
       9              : #if (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) && (LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP)
      10              : 
      11            2 : libspdm_return_t libspdm_get_encap_request_send_event(
      12              :     libspdm_context_t *spdm_context,
      13              :     size_t *encap_request_size,
      14              :     void *encap_request)
      15              : {
      16              :     spdm_send_event_request_t *spdm_request;
      17              :     uint32_t session_id;
      18              :     uint32_t event_count;
      19              :     size_t events_list_size;
      20              : 
      21            2 :     spdm_request = encap_request;
      22              : 
      23            2 :     if (spdm_context->last_spdm_request_session_id_valid) {
      24              :         libspdm_session_info_t *session_info;
      25              :         libspdm_session_state_t session_state;
      26              : 
      27            2 :         session_id = spdm_context->last_spdm_request_session_id;
      28            2 :         session_info = libspdm_get_session_info_via_session_id(spdm_context, session_id);
      29              : 
      30            2 :         if (session_info == NULL) {
      31            0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
      32              :         }
      33              : 
      34            2 :         session_state = libspdm_secured_message_get_session_state(
      35              :             session_info->secured_message_context);
      36              : 
      37            2 :         if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
      38            0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
      39              :         }
      40              :     } else {
      41            0 :         return LIBSPDM_STATUS_ERROR_PEER;
      42              :     }
      43              : 
      44            2 :     spdm_request->header.spdm_version = libspdm_get_connection_version(spdm_context);
      45            2 :     spdm_request->header.request_response_code = SPDM_SEND_EVENT;
      46            2 :     spdm_request->header.param1 = 0;
      47            2 :     spdm_request->header.param2 = 0;
      48              : 
      49            2 :     events_list_size = *encap_request_size - sizeof(spdm_send_event_request_t);
      50              : 
      51            2 :     if (!libspdm_generate_event_list(spdm_context, libspdm_get_connection_version(spdm_context),
      52              :                                      session_id, &event_count, &events_list_size,
      53            2 :                                      (uint8_t *)(spdm_request + 1))) {
      54            1 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
      55              :     }
      56              : 
      57            1 :     LIBSPDM_ASSERT(event_count != 0);
      58            1 :     LIBSPDM_ASSERT(events_list_size != 0);
      59              : 
      60            1 :     spdm_request->event_count = event_count;
      61              : 
      62            1 :     return LIBSPDM_STATUS_SUCCESS;
      63              : }
      64              : 
      65            2 : libspdm_return_t libspdm_process_encap_response_event_ack(
      66              :     libspdm_context_t *spdm_context, size_t encap_response_size,
      67              :     const void *encap_response, bool *need_continue)
      68              : {
      69              :     libspdm_return_t status;
      70              :     const spdm_event_ack_response_t *spdm_response;
      71              :     size_t spdm_response_size;
      72              :     uint32_t session_id;
      73              : 
      74            2 :     if (spdm_context->last_spdm_request_session_id_valid) {
      75              :         libspdm_session_info_t *session_info;
      76              :         libspdm_session_state_t session_state;
      77              : 
      78            2 :         session_id = spdm_context->last_spdm_request_session_id;
      79            2 :         session_info = libspdm_get_session_info_via_session_id(spdm_context, session_id);
      80              : 
      81            2 :         if (session_info == NULL) {
      82            0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
      83              :         }
      84              : 
      85            2 :         session_state = libspdm_secured_message_get_session_state(
      86              :             session_info->secured_message_context);
      87              : 
      88            2 :         if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
      89            0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
      90              :         }
      91              :     } else {
      92            0 :         return LIBSPDM_STATUS_ERROR_PEER;
      93              :     }
      94              : 
      95            2 :     spdm_response = encap_response;
      96            2 :     spdm_response_size = encap_response_size;
      97              : 
      98            2 :     if (spdm_response->header.spdm_version != libspdm_get_connection_version(spdm_context)) {
      99            1 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
     100              :     }
     101              : 
     102            1 :     if (spdm_response->header.request_response_code == SPDM_ERROR) {
     103            0 :         status = libspdm_handle_encap_error_response_main(
     104            0 :             spdm_context, spdm_response->header.param1);
     105            0 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
     106            0 :             return status;
     107              :         }
     108            1 :     } else if (spdm_response->header.request_response_code != SPDM_EVENT_ACK) {
     109            0 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
     110              :     }
     111              : 
     112            1 :     if (spdm_response_size != sizeof(spdm_event_ack_response_t)) {
     113            0 :         return LIBSPDM_STATUS_INVALID_MSG_SIZE;
     114              :     }
     115              : 
     116            1 :     *need_continue = false;
     117              : 
     118            1 :     return LIBSPDM_STATUS_SUCCESS;
     119              : }
     120              : 
     121              : #endif /* (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) && (LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP) */
        

Generated by: LCOV version 2.0-1