1 /*
2  * The Initial Developer of the Original Code is Intel Corporation.
3  * Portions created by Intel Corporation are Copyright (C) 2007 Intel Corporation.
4  * All Rights Reserved.
5  * trousers - An open source TCG Software Stack
6  *
7  * Author: james.xu@intel.com Rossey.liu@intel.com
8  *
9  */
10 
11 #ifndef _OBJ_NVSTORE_H_
12 #define _OBJ_NVSTORE_H_
13 
14 #ifdef TSS_BUILD_NV
15 
16 #define MAX_PUBLIC_DATA_SIZE 1024
17 #define TSS_LOCALITY_MASK 0x1f
18 
19 typedef struct objNV_DATA_PUBLIC
20 {
21 	TPM_STRUCTURE_TAG tag;
22 	TPM_NV_INDEX nvIndex;
23 	TPM_NV_ATTRIBUTES permission;
24 	TPM_BOOL bReadSTClear;
25 	TPM_BOOL bWriteSTClear;
26 	TPM_BOOL bWriteDefine;
27 	UINT32 dataSize;
28 }NV_DATA_PUBLIC;
29 
30 /* structures */
31 struct tr_nvstore_obj {
32 	TPM_STRUCTURE_TAG tag;
33 	TPM_NV_INDEX nvIndex;
34 	TPM_NV_ATTRIBUTES permission;
35 	TPM_BOOL bReadSTClear;
36 	TPM_BOOL bWriteSTClear;
37 	TPM_BOOL bWriteDefine;
38 	UINT32 dataSize;
39 	TSS_HPOLICY policy;
40 };
41 
42 /* obj_nv.c */
43 void       nvstore_free(void *data);
44 TSS_RESULT obj_nvstore_add(TSS_HCONTEXT, TSS_HOBJECT *);
45 TSS_BOOL   obj_is_nvstore(TSS_HOBJECT tspContext);
46 TSS_RESULT obj_nvstore_remove(TSS_HOBJECT, TSS_HCONTEXT);
47 TSS_RESULT obj_nvstore_get_tsp_context(TSS_HNVSTORE, TSS_HCONTEXT *);
48 TSS_RESULT obj_nvstore_set_index(TSS_HNVSTORE, UINT32);
49 TSS_RESULT obj_nvstore_get_index(TSS_HNVSTORE, UINT32 *);
50 TSS_RESULT obj_nvstore_set_datasize(TSS_HNVSTORE, UINT32);
51 TSS_RESULT obj_nvstore_get_datasize(TSS_HNVSTORE, UINT32 *);
52 TSS_RESULT obj_nvstore_set_permission(TSS_HNVSTORE, UINT32);
53 TSS_RESULT obj_nvstore_get_permission_from_tpm(TSS_HNVSTORE hNvstore, UINT32 * permission);
54 TSS_RESULT obj_nvstore_get_permission(TSS_HNVSTORE, UINT32 *);
55 TSS_RESULT obj_nvstore_set_policy(TSS_HNVSTORE, TSS_HPOLICY);
56 TSS_RESULT obj_nvstore_get_policy(TSS_HNVSTORE, UINT32, TSS_HPOLICY *);
57 TSS_RESULT obj_nvstore_get_datapublic(TSS_HNVSTORE, UINT32 *, BYTE *);
58 TSS_RESULT obj_nvstore_get_readdigestatrelease(TSS_HNVSTORE, UINT32 *, BYTE **);
59 TSS_RESULT obj_nvstore_get_readpcrselection(TSS_HNVSTORE, UINT32 *, BYTE **);
60 TSS_RESULT obj_nvstore_get_writedigestatrelease(TSS_HNVSTORE, UINT32 *, BYTE **);
61 TSS_RESULT obj_nvstore_get_writepcrselection(TSS_HNVSTORE, UINT32 *, BYTE **);
62 TSS_RESULT obj_nvstore_get_state_readstclear(TSS_HNVSTORE, UINT32 *);
63 TSS_RESULT obj_nvstore_get_state_writedefine(TSS_HNVSTORE, UINT32 *);
64 TSS_RESULT obj_nvstore_get_state_writestclear(TSS_HNVSTORE, UINT32 *);
65 TSS_RESULT obj_nvstore_get_readlocalityatrelease(TSS_HNVSTORE, UINT32 *);
66 TSS_RESULT obj_nvstore_get_writelocalityatrelease(TSS_HNVSTORE, UINT32 *);
67 TSS_RESULT obj_nvstore_create_pcrshortinfo(TSS_HNVSTORE, TSS_HPCRS, UINT32 *, BYTE **);
68 
69 #define NVSTORE_LIST_DECLARE		struct obj_list nvstore_list
70 #define NVSTORE_LIST_DECLARE_EXTERN	extern struct obj_list nvstore_list
71 #define NVSTORE_LIST_INIT()		tspi_list_init(&nvstore_list)
72 #define NVSTORE_LIST_CONNECT(a,b)	obj_connectContext_list(&nvstore_list, a, b)
73 #define NVSTORE_LIST_CLOSE(a)		obj_list_close(&nvstore_list, &nvstore_free, a)
74 #else
75 #define NVSTORE_LIST_DECLARE
76 #define NVSTORE_LIST_DECLARE_EXTERN
77 #define NVSTORE_LIST_INIT()
78 #define NVSTORE_LIST_CONNECT(a,b)
79 #define NVSTORE_LIST_CLOSE(a)
80 #endif
81 #endif
82 
83