Skip to content

Commit d0043e4

Browse files
committed
Add doxygen docs to fwTPM and new public headers
1 parent c371610 commit d0043e4

8 files changed

Lines changed: 437 additions & 41 deletions

File tree

docs/Doxyfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,12 @@ INPUT = ./docs/README.md \
873873
./hal/README.md \
874874
./wolftpm/tpm2.h \
875875
./wolftpm/tpm2_wrap.h \
876+
./wolftpm/tpm2_crypto.h \
877+
./wolftpm/fwtpm/fwtpm.h \
878+
./wolftpm/fwtpm/fwtpm_command.h \
879+
./wolftpm/fwtpm/fwtpm_io.h \
880+
./wolftpm/fwtpm/fwtpm_tis.h \
881+
./wolftpm/fwtpm/fwtpm_nv.h \
876882
./hal/tpm_io.h
877883

878884
# This tag can be used to specify the character encoding of the source files

wolftpm/fwtpm/fwtpm.h

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,14 +564,88 @@ typedef struct FWTPM_CTX {
564564
#endif
565565
} FWTPM_CTX;
566566

567-
/* Public API */
567+
/** @defgroup wolfTPM_fwTPM wolfTPM fwTPM (Firmware TPM)
568+
*
569+
* Public API for the wolfTPM firmware TPM (fwTPM) software TPM 2.0
570+
* implementation. fwTPM is a portable TPM server that speaks the
571+
* TCG TPM 2.0 command protocol and can run alongside or in place of
572+
* a hardware TPM. Transports are pluggable (sockets, TIS shared memory,
573+
* SPI/UART on embedded targets) via HAL callbacks. Storage (NV) and
574+
* clock are also pluggable so the same core can run on Linux and
575+
* bare-metal microcontrollers.
576+
*/
577+
578+
/*!
579+
\ingroup wolfTPM_fwTPM
580+
\brief Initialize a fwTPM context. Seeds the RNG, clears TPM state,
581+
and prepares the context for FWTPM_NV_Init / FWTPM_IO_Init.
582+
583+
\return 0 on success
584+
\return TPM_RC_MEMORY if RNG initialization fails
585+
586+
\param ctx pointer to caller-allocated FWTPM_CTX (must be zeroed)
587+
588+
\sa FWTPM_Cleanup
589+
\sa FWTPM_NV_SetHAL
590+
\sa FWTPM_Clock_SetHAL
591+
*/
568592
WOLFTPM_API int FWTPM_Init(FWTPM_CTX* ctx);
593+
594+
/*!
595+
\ingroup wolfTPM_fwTPM
596+
\brief Release resources held by a fwTPM context. Zeros all
597+
hierarchy seeds, session keys, and sensitive auth values before
598+
freeing. Safe to call on a partially-initialized context.
599+
600+
\return 0 on success
601+
602+
\param ctx pointer to an initialized FWTPM_CTX
603+
604+
\sa FWTPM_Init
605+
*/
569606
WOLFTPM_API int FWTPM_Cleanup(FWTPM_CTX* ctx);
607+
608+
/*!
609+
\ingroup wolfTPM_fwTPM
610+
\brief Return a pointer to the compile-time fwTPM version string
611+
(e.g. "0.1.0").
612+
613+
\return pointer to a static, null-terminated version string
614+
*/
570615
WOLFTPM_API const char* FWTPM_GetVersionString(void);
571616

572-
/* Clock HAL API */
617+
/*!
618+
\ingroup wolfTPM_fwTPM
619+
\brief Register a platform clock source for fwTPM. On embedded
620+
targets this allows the TPM clock (TPM2_ReadClock / TPM2_ClockSet)
621+
to advance from a hardware timer. When no HAL is registered,
622+
FWTPM_Clock_GetMs returns ctx->clockOffset only.
623+
624+
\return 0 on success
625+
\return BAD_FUNC_ARG if ctx is NULL
626+
627+
\param ctx pointer to an initialized FWTPM_CTX
628+
\param get_ms callback returning milliseconds-since-boot; may be NULL
629+
to clear a previously registered HAL
630+
\param halCtx opaque context passed back to get_ms
631+
632+
\sa FWTPM_Clock_GetMs
633+
*/
573634
WOLFTPM_API int FWTPM_Clock_SetHAL(FWTPM_CTX* ctx,
574635
UINT64 (*get_ms)(void* halCtx), void* halCtx);
636+
637+
/*!
638+
\ingroup wolfTPM_fwTPM
639+
\brief Get the current TPM clock value in milliseconds. Returns
640+
ctx->clockOffset plus (if registered) the value from the clock HAL.
641+
642+
\return current clock value in milliseconds
643+
\return 0 if ctx is NULL
644+
645+
\param ctx pointer to an initialized FWTPM_CTX
646+
647+
\sa FWTPM_Clock_SetHAL
648+
*/
575649
WOLFTPM_API UINT64 FWTPM_Clock_GetMs(FWTPM_CTX* ctx);
576650

577651
#ifdef __cplusplus

wolftpm/fwtpm/fwtpm_command.h

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,28 @@
3030
extern "C" {
3131
#endif
3232

33-
/* Process a TPM command buffer and produce a response buffer.
34-
* cmdBuf/cmdSize: input command (big-endian TPM packet)
35-
* rspBuf/rspSize: output response buffer and resulting size
36-
* locality: the locality from the transport layer
37-
* Returns TPM_RC_SUCCESS on successful processing (response may contain error RC)
38-
*/
33+
/*!
34+
\ingroup wolfTPM_fwTPM
35+
\brief Process one TPM 2.0 command. Parses the header from cmdBuf,
36+
dispatches the command, and writes a wire-format response into
37+
rspBuf. The return value signals transport-level success: a failure
38+
at the TPM command level (e.g. TPM_RC_AUTH_FAIL) is encoded inside
39+
the response and still returns TPM_RC_SUCCESS here.
40+
41+
\return TPM_RC_SUCCESS on successful processing (inspect response
42+
header for the TPM-level return code)
43+
\return negative on fatal transport/parse error
44+
45+
\param ctx pointer to an initialized FWTPM_CTX
46+
\param cmdBuf input command buffer (big-endian TPM packet)
47+
\param cmdSize size of cmdBuf in bytes
48+
\param rspBuf output response buffer (caller-allocated)
49+
\param rspSize in: capacity of rspBuf; out: bytes written
50+
\param locality TPM locality (0-4) reported by the transport
51+
52+
\sa FWTPM_IO_ServerLoop
53+
\sa FWTPM_TIS_ServerLoop
54+
*/
3955
WOLFTPM_API int FWTPM_ProcessCommand(FWTPM_CTX* ctx,
4056
const byte* cmdBuf, int cmdSize,
4157
byte* rspBuf, int* rspSize, int locality);

wolftpm/fwtpm/fwtpm_io.h

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,71 @@
4949
/* FWTPM_IO_CTX is defined in fwtpm.h (included above) */
5050

5151
#ifndef WOLFTPM_FWTPM_TIS
52-
/* Set IO HAL callbacks (optional - socket transport only) */
52+
/*!
53+
\ingroup wolfTPM_fwTPM
54+
\brief Register a custom socket-transport HAL. Call before
55+
FWTPM_IO_Init to replace the default POSIX socket implementation
56+
(e.g. for a mocked or in-process transport).
57+
58+
\return 0 on success
59+
\return BAD_FUNC_ARG if ctx or hal is NULL
60+
61+
\param ctx pointer to an initialized FWTPM_CTX
62+
\param hal pointer to a caller-populated FWTPM_IO_HAL
63+
64+
\sa FWTPM_IO_Init
65+
*/
5366
WOLFTPM_API int FWTPM_IO_SetHAL(FWTPM_CTX* ctx, FWTPM_IO_HAL* hal);
5467
#endif
5568

56-
/* Initialize transport (sockets by default, or custom HAL) */
69+
/*!
70+
\ingroup wolfTPM_fwTPM
71+
\brief Initialize the fwTPM transport. When no HAL has been
72+
registered, binds default TCP sockets on ctx->cmdPort and
73+
ctx->platPort.
74+
75+
\return 0 on success
76+
\return negative on socket/bind error
77+
78+
\param ctx pointer to an initialized FWTPM_CTX
79+
80+
\sa FWTPM_IO_Cleanup
81+
\sa FWTPM_IO_ServerLoop
82+
*/
5783
WOLFTPM_API int FWTPM_IO_Init(FWTPM_CTX* ctx);
5884

59-
/* Cleanup sockets */
85+
/*!
86+
\ingroup wolfTPM_fwTPM
87+
\brief Release transport resources (close sockets / release HAL).
88+
89+
\param ctx pointer to an initialized FWTPM_CTX
90+
91+
\sa FWTPM_IO_Init
92+
*/
6093
WOLFTPM_API void FWTPM_IO_Cleanup(FWTPM_CTX* ctx);
6194

62-
/* Main server loop - blocks until ctx->running is cleared or stop requested */
95+
/*!
96+
\ingroup wolfTPM_fwTPM
97+
\brief Run the main fwTPM server loop. Blocks until ctx->running
98+
is cleared (by FWTPM_IO_RequestStop or a signal handler).
99+
100+
\return 0 on clean shutdown
101+
\return negative on fatal transport error
102+
103+
\param ctx pointer to an initialized FWTPM_CTX
104+
105+
\sa FWTPM_IO_RequestStop
106+
*/
63107
WOLFTPM_API int FWTPM_IO_ServerLoop(FWTPM_CTX* ctx);
64108

65-
/* Async-signal-safe: request the server loop to exit. Safe to call from
66-
* a signal handler — only sets a volatile sig_atomic_t flag that the
67-
* main loop polls. */
109+
/*!
110+
\ingroup wolfTPM_fwTPM
111+
\brief Request the server loop to exit. Async-signal-safe: only
112+
sets a volatile sig_atomic_t flag that the loop polls, so this is
113+
safe to call from a signal handler.
114+
115+
\sa FWTPM_IO_ServerLoop
116+
*/
68117
WOLFTPM_API void FWTPM_IO_RequestStop(void);
69118

70119
#ifdef __cplusplus

0 commit comments

Comments
 (0)