• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef _TEE_AGENT_H
17 #define _TEE_AGENT_H
18 
19 #include <stdint.h>
20 #include <stdio.h>
21 
22 #define AGENT_FS_ID 0x46536673
23 #define AGENT_MISC_ID 0x4d495343
24 
25 #define FILE_NAME_MAX_BUF       256
26 #define USEC_PER_MSEC 1000
27 #define K_BYTES 1024
28 #define TIME_START_YEAR 1900
29 
30 /* static func declare */
31 typedef enum {
32     SEC_OPEN,
33     SEC_CLOSE,
34     SEC_READ,
35     SEC_WRITE,
36     SEC_SEEK,
37     SEC_REMOVE,
38     SEC_TRUNCATE,
39     SEC_RENAME,
40     SEC_CREATE,
41     SEC_INFO,
42     SEC_ACCESS,
43     SEC_ACCESS2,
44     SEC_FSYNC,
45     SEC_CP,
46     SEC_DISKUSAGE,
47     SEC_DELETE_ALL,
48     SEC_MAX
49 } FsCmdType;
50 
51 typedef enum {
52     SEC_GET_TIME,
53     MISC_CMD_MAX
54 } MiscCmdType;
55 
56 enum {
57     SEC_WRITE_SLOG,
58     SEC_WRITE_SSA,
59 };
60 
61 struct SecStorageType {
62     FsCmdType cmd; /* for s to n */
63     int32_t ret;   /* fxxx call's return */
64     int32_t ret2;  /* fread: end-of-file or error;fwrite:the sendor is SSA or SLOG */
65     uint32_t userId;
66     uint32_t magic;
67     uint32_t error;
68     union Args1 {
69         struct {
70             char mode[4];
71             uint32_t nameLen;
72             uint32_t name[1]; /* change name[0] --> name[1], for pc-lint */
73         } Open;
74         struct {
75             int32_t fd;
76         } Close;
77         struct {
78             int32_t fd;
79             uint32_t count;
80             uint32_t buffer[1]; /* the same as name[0] --> name[1] */
81         } Read;
82         struct {
83             int32_t fd;
84             uint32_t count;
85             uint32_t buffer[1];
86         } Write;
87         struct {
88             int32_t fd;
89             int32_t offset;
90             uint32_t whence;
91         } Seek;
92         struct {
93             uint32_t nameLen;
94             uint32_t name[1];
95         } Remove;
96         struct {
97             uint32_t len;
98             uint32_t nameLen;
99             uint32_t name[1];
100         } Truncate;
101         struct {
102             uint32_t oldNameLen;
103             uint32_t newNameLen;
104             uint32_t buffer[1]; /* old_name + new_name */
105         } Rename;
106         struct {
107             uint32_t fromPathLen;
108             uint32_t toPathLen;
109             uint32_t buffer[1]; /* from_path+to_path */
110         } Cp;
111         struct {
112             char mode[4];
113             uint32_t nameLen;
114             uint32_t name[1];
115         } Create;
116         struct {
117             int32_t fd;
118             uint32_t curPos;
119             uint32_t fileLen;
120         } Info;
121         struct {
122             int mode;
123             uint32_t nameLen;
124             uint32_t name[1];
125         } Access;
126         struct {
127             int32_t fd;
128         } Fsync;
129         struct {
130             uint32_t secStorage;
131             uint32_t data;
132         } DiskUsage;
133         struct {
134             uint32_t pathLen;
135             uint32_t path[1];
136         } DeleteAll;
137     } Args;
138 };
139 
140 struct MiscControlType {
141     MiscCmdType cmd; /* for s to n */
142     int32_t ret;
143     int32_t magic;
144     union Args2 {
145         struct {
146             uint32_t seconds;
147             uint32_t millis;
148             char timeStr[30];
149         } GetTime;
150     } Args;
151 };
152 
153 struct OpenedFile {
154     FILE *file;
155     struct OpenedFile *next;
156     struct OpenedFile *prev;
157 };
158 #endif
159