• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 NATIVE_TOKEN_H
17 #define NATIVE_TOKEN_H
18 
19 #include <stdint.h>
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 #define MAX_PROCESS_NAME_LEN 256
26 #define TOKEN_ID_CFG_FILE_PATH "/data/service/el0/access_token/nativetoken.json"
27 #define TOKEN_ID_CFG_FILE_LOCK_PATH "/data/service/el0/access_token/nativetoken.json.lock"
28 #define TOKEN_ID_CFG_DIR_PATH "/data/service/el0/access_token"
29 #define TOKEN_NATIVE_TYPE 1
30 #define TOKEN_SHELL_TYPE 2
31 #define DEFAULT_AT_VERSION 1
32 #define TRANSFER_KEY_WORDS "NativeTokenInfo"
33 #define MAX_JSON_FILE_LEN 1024000
34 #define MAX_DCAPS_NUM 32
35 #define MAX_DCAP_LEN 1024
36 #define MAX_PERM_NUM 1024
37 #define MAX_PERM_LEN 256
38 #define MAX_PARAMTER_LEN 128
39 #define SYSTEM_PROP_NATIVE_RECEPTOR "rw.nativetoken.receptor.startup"
40 #define PATH_MAX_LEN 4096
41 #define MAX_RETRY_TIMES 1000
42 #define TOKEN_RANDOM_MASK ((1 << 20) - 1)
43 #define MAX_RETRY_LOCK_TIMES 10
44 #define SLEEP_TIME (500*1000)
45 #define MAX_MALLOC_SIZE 8192
46 
47 #define ATRET_FAILED 1
48 #define ATRET_SUCCESS 0
49 
50 #define DCAPS_KEY_NAME  "dcaps"
51 #define PERMS_KEY_NAME  "permissions"
52 #define ACLS_KEY_NAME  "nativeAcls"
53 #define TOKENID_KEY_NAME "tokenId"
54 #define TOKEN_ATTR_KEY_NAME "tokenAttr"
55 #define APL_KEY_NAME "APL"
56 #define VERSION_KEY_NAME "version"
57 #define PROCESS_KEY_NAME "processName"
58 #define HDC_PROCESS_NAME "hdcd"
59 
60 #define SYSTEM_CORE 3
61 #define SYSTEM_BASIC 2
62 #define NORMAL 1
63 
64 #define INVALID_TOKEN_ID 0
65 typedef unsigned int NativeAtId;
66 typedef unsigned int NativeAtAttr;
67 
68 typedef struct {
69     unsigned int tokenUniqueId : 20;
70     unsigned int reserved : 7;
71     unsigned int type : 2;
72     unsigned int version : 3;
73 } AtInnerInfo;
74 
75 typedef struct {
76     NativeAtId tokenId;
77     NativeAtAttr tokenAttr;
78 } NativeAtIdEx;
79 
80 typedef struct TokenList {
81     NativeAtId tokenId;
82     int32_t apl;
83     char **dcaps;
84     char **perms;
85     char **acls;
86     int32_t dcapsNum;
87     int32_t permsNum;
88     int32_t aclsNum;
89     char processName[MAX_PROCESS_NAME_LEN + 1];
90     struct TokenList *next;
91 } NativeTokenList;
92 
93 typedef struct StrArrayAttribute {
94     int32_t maxStrNum;
95     uint32_t maxStrLen;
96     const char *strKey;
97 } StrArrayAttr;
98 
99 extern uint32_t GetFileBuff(const char *cfg, char **retBuff);
100 extern uint32_t AtlibInit(void);
101 #ifdef __cplusplus
102 }
103 #endif
104 
105 #endif // NATIVE_TOKEN_H
106