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: 85.7 % 35 30
Test Date: 2025-06-29 08:09:00 Functions: 100.0 % 2 2

            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              : 
      26              : #if LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP
      27            1 : bool libspdm_event_get_types(
      28              :     void *spdm_context,
      29              :     spdm_version_number_t spdm_version,
      30              :     uint32_t session_id,
      31              :     void *supported_event_groups_list,
      32              :     uint32_t *supported_event_groups_list_len,
      33              :     uint8_t *event_group_count)
      34              : {
      35            1 :     *supported_event_groups_list_len = g_supported_event_groups_list_len;
      36              : 
      37            9 :     for (uint32_t index = 0; index < *supported_event_groups_list_len; index++)
      38              :     {
      39            8 :         ((char *)supported_event_groups_list)[index] = (char)index;
      40              :     }
      41              : 
      42            1 :     *event_group_count = g_event_group_count;
      43              : 
      44            1 :     return true;
      45              : }
      46              : 
      47            3 : bool libspdm_event_subscribe(
      48              :     void *spdm_context,
      49              :     spdm_version_number_t spdm_version,
      50              :     uint32_t session_id,
      51              :     uint8_t subscribe_type,
      52              :     uint8_t subscribe_event_group_count,
      53              :     uint32_t subscribe_list_len,
      54              :     const void *subscribe_list)
      55              : {
      56            3 :     switch (subscribe_type) {
      57            1 :     case LIBSPDM_EVENT_SUBSCRIBE_ALL:
      58            1 :         if ((subscribe_list_len != 0) || (subscribe_list != NULL)) {
      59            0 :             return false;
      60              :         }
      61            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
      62              :                        "Subscribing to all events for session ID 0x%x.\n", session_id));
      63            1 :         g_event_all_subscribe = true;
      64            1 :         g_event_all_unsubscribe = false;
      65            1 :         return true;
      66            1 :     case LIBSPDM_EVENT_SUBSCRIBE_NONE:
      67            1 :         if ((subscribe_list_len != 0) || (subscribe_list != NULL)) {
      68            0 :             return false;
      69              :         }
      70            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
      71              :                        "Unsubscribing from all events for session ID 0x%x.\n", session_id));
      72            1 :         g_event_all_subscribe = false;
      73            1 :         g_event_all_unsubscribe = true;
      74            1 :         return true;
      75            1 :     case LIBSPDM_EVENT_SUBSCRIBE_LIST:
      76            1 :         if ((subscribe_list_len == 0) || (subscribe_list == NULL)) {
      77            0 :             return false;
      78              :         }
      79            1 :         break;
      80            0 :     default:
      81            0 :         return false;
      82              :     }
      83              : 
      84            1 :     g_event_all_subscribe = false;
      85            1 :     g_event_all_unsubscribe = false;
      86              : 
      87            1 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
      88              :                    "subscribe_event_group_count == %d, subscribe_list_len = %d\n",
      89              :                    subscribe_event_group_count, subscribe_list_len));
      90              : 
      91           19 :     for (uint32_t index = 0; index < subscribe_list_len; index++) {
      92           18 :         printf("%02x ", ((const char *)subscribe_list)[index]);
      93              :     }
      94            1 :     printf("\n");
      95              : 
      96            1 :     return true;
      97              : }
      98              : #endif /* LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP */
        

Generated by: LCOV version 2.0-1