Coverage Report

Created: 2025-07-11 07:00

/src/ibmswtpm2/src/ntc2.c
Line
Count
Source (jump to first uncovered line)
1
/********************************************************************************/
2
/*                    */
3
/*      Nuvoton Proprietary Command Emulation     */
4
/*           Written by Ken Goldman       */
5
/*           IBM Thomas J. Watson Research Center     */
6
/*        $Id: ntc2.c 1055 2017-08-08 20:30:09Z kgoldman $      */
7
/*                    */
8
/* (c) Copyright IBM Corporation 2015, 2017         */
9
/*                    */
10
/* All rights reserved.               */
11
/*                    */
12
/* Redistribution and use in source and binary forms, with or without   */
13
/* modification, are permitted provided that the following conditions are */
14
/* met:                   */
15
/*                    */
16
/* Redistributions of source code must retain the above copyright notice, */
17
/* this list of conditions and the following disclaimer.      */
18
/*                    */
19
/* Redistributions in binary form must reproduce the above copyright    */
20
/* notice, this list of conditions and the following disclaimer in the    */
21
/* documentation and/or other materials provided with the distribution.   */
22
/*                    */
23
/* Neither the names of the IBM Corporation nor the names of its    */
24
/* contributors may be used to endorse or promote products derived from   */
25
/* this software without specific prior written permission.     */
26
/*                    */
27
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS    */
28
/* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT    */
29
/* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR  */
30
/* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT   */
31
/* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
32
/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT   */
33
/* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  */
34
/* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY  */
35
/* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT    */
36
/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE  */
37
/* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.   */
38
/********************************************************************************/
39
40
/* This emulation does not store the configuration in NV memory.  Thus, it does not persist.
41
 */
42
43
#include "ntc2_fp.h"
44
45
/* config state has some required or default values */
46
47
static NTC2_CFG_STRUCT ntc2state = {
48
    .i2cLoc1_2  = 0xff,
49
    .i2cLoc3_4  = 0xff,
50
    .AltCfg   =   0x13,
51
    .Direction  =   0x00,
52
    .PullUp   =     0xff,
53
    .PushPull   =     0xff,
54
    .CFG_A  =     0xff,
55
    .CFG_B  =     0xff,
56
    .CFG_C  =     0xff,
57
    .CFG_D  =     0xff,
58
    .CFG_E  =     0xff,
59
    .CFG_F  =     0xff,
60
    .CFG_G  =     0xff,
61
    .CFG_H  =     0xff,
62
    .CFG_I  =     0xff,
63
    .CFG_J  =     0xff,
64
    .IsValid  =     0xaa,
65
    .IsLocked   =   0xff
66
};
67
68
TPM_RC
69
NTC2_PreConfig(NTC2_PreConfig_In *in)
70
0
{
71
    // Input Validation
72
0
    if (ntc2state.IsLocked == 0xaa) {
73
0
  return TPM_RC_DISABLED;
74
0
    }
75
0
    ntc2state = in->preConfig;
76
0
    ntc2state.IsLocked = 0xff;  /* cannot be set by PreConfig */
77
0
    return TPM_RC_SUCCESS;
78
0
}
79
80
TPM_RC
81
NTC2_LockPreConfig(void)
82
0
{
83
0
    ntc2state.IsLocked = 0xaa;
84
0
    return TPM_RC_SUCCESS;
85
0
}
86
87
TPM_RC
88
NTC2_GetConfig(NTC2_GetConfig_Out *out)
89
0
{
90
0
    out->preConfig = ntc2state;
91
0
    return TPM_RC_SUCCESS;
92
0
}