LCOV - code coverage report
Current view: top level - os_stub/spdm_device_secret_lib_sample - event.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 88.1 % 42 37
Test Date: 2025-08-24 08:11:14 Functions: 100.0 % 3 3

            Line data    Source code
       1              : /**
       2              :  *  Copyright Notice:
       3              :  *  Copyright 2024 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 <stdarg.h>
       8              : #include <stddef.h>
       9              : #include <setjmp.h>
      10              : #include <stdint.h>
      11              : #include <stdlib.h>
      12              : #include <stdio.h>
      13              : #include <assert.h>
      14              : #include <string.h>
      15              : 
      16              : #include <base.h>
      17              : #include "library/memlib.h"
      18              : #include "spdm_device_secret_lib_internal.h"
      19              : #include "internal/libspdm_common_lib.h"
      20              : 
      21              : uint32_t g_supported_event_groups_list_len = 8;
      22              : uint8_t g_event_group_count = 1;
      23              : bool g_event_all_subscribe = false;
      24              : bool g_event_all_unsubscribe = false;
      25              : uint32_t g_event_count = 1;
      26              : bool g_generate_event_list_error = false;
      27              : 
      28              : #if LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP
      29            1 : bool libspdm_event_get_types(
      30              :     void *spdm_context,
      31              :     spdm_version_number_t spdm_version,
      32              :     uint32_t session_id,
      33              :     void *supported_event_groups_list,
      34              :     uint32_t *supported_event_groups_list_len,
      35              :     uint8_t *event_group_count)
      36              : {
      37            1 :     *supported_event_groups_list_len = g_supported_event_groups_list_len;
      38              : 
      39            9 :     for (uint32_t index = 0; index < *supported_event_groups_list_len; index++)
      40              :     {
      41            8 :         ((char *)supported_event_groups_list)[index] = (char)index;
      42              :     }
      43              : 
      44            1 :     *event_group_count = g_event_group_count;
      45              : 
      46            1 :     return true;
      47              : }
      48              : 
      49            3 : bool libspdm_event_subscribe(
      50              :     void *spdm_context,
      51              :     spdm_version_number_t spdm_version,
      52              :     uint32_t session_id,
      53              :     uint8_t subscribe_type,
      54              :     uint8_t subscribe_event_group_count,
      55              :     uint32_t subscribe_list_len,
      56              :     const void *subscribe_list)
      57              : {
      58            3 :     switch (subscribe_type) {
      59            1 :     case LIBSPDM_EVENT_SUBSCRIBE_ALL:
      60            1 :         if ((subscribe_list_len != 0) || (subscribe_list != NULL)) {
      61            0 :             return false;
      62              :         }
      63            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
      64              :                        "Subscribing to all events for session ID 0x%x.\n", session_id));
      65            1 :         g_event_all_subscribe = true;
      66            1 :         g_event_all_unsubscribe = false;
      67            1 :         return true;
      68            1 :     case LIBSPDM_EVENT_SUBSCRIBE_NONE:
      69            1 :         if ((subscribe_list_len != 0) || (subscribe_list != NULL)) {
      70            0 :             return false;
      71              :         }
      72            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
      73              :                        "Unsubscribing from all events for session ID 0x%x.\n", session_id));
      74            1 :         g_event_all_subscribe = false;
      75            1 :         g_event_all_unsubscribe = true;
      76            1 :         return true;
      77            1 :     case LIBSPDM_EVENT_SUBSCRIBE_LIST:
      78            1 :         if ((subscribe_list_len == 0) || (subscribe_list == NULL)) {
      79            0 :             return false;
      80              :         }
      81            1 :         break;
      82            0 :     default:
      83            0 :         return false;
      84              :     }
      85              : 
      86            1 :     g_event_all_subscribe = false;
      87            1 :     g_event_all_unsubscribe = false;
      88              : 
      89            1 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
      90              :                    "subscribe_event_group_count == %d, subscribe_list_len = %d\n",
      91              :                    subscribe_event_group_count, subscribe_list_len));
      92              : 
      93           19 :     for (uint32_t index = 0; index < subscribe_list_len; index++) {
      94           18 :         printf("%02x ", ((const char *)subscribe_list)[index]);
      95              :     }
      96            1 :     printf("\n");
      97              : 
      98            1 :     return true;
      99              : }
     100              : 
     101            2 : bool libspdm_generate_event_list(
     102              :     void *spdm_context,
     103              :     spdm_version_number_t spdm_version,
     104              :     uint32_t session_id,
     105              :     uint32_t *event_count,
     106              :     size_t *events_list_size,
     107              :     void *events_list)
     108              : {
     109            2 :     if (g_generate_event_list_error) {
     110            1 :         return false;
     111              :     }
     112              : 
     113            1 :     *event_count = g_event_count;
     114              : 
     115         4601 :     for (uint32_t index = 0; index < *events_list_size; index++)
     116              :     {
     117         4600 :         ((char *)events_list)[index] = (char)index;
     118              :     }
     119              : 
     120            1 :     return true;
     121              : }
     122              : #endif /* LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP */
        

Generated by: LCOV version 2.0-1