• 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 80
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 
46 #define ATRET_FAILED 1
47 #define ATRET_SUCCESS 0
48 
49 #define DCAPS_KEY_NAME  "dcaps"
50 #define PERMS_KEY_NAME  "permissions"
51 #define ACLS_KEY_NAME  "nativeAcls"
52 #define TOKENID_KEY_NAME "tokenId"
53 #define TOKEN_ATTR_KEY_NAME "tokenAttr"
54 #define APL_KEY_NAME "APL"
55 #define VERSION_KEY_NAME "version"
56 #define PROCESS_KEY_NAME "processName"
57 #define HDC_PROCESS_NAME "hdcd"
58 
59 #define SYSTEM_CORE 3
60 #define SYSTEM_BASIC 2
61 #define NORMAL 1
62 
63 #define INVALID_TOKEN_ID 0
64 typedef unsigned int NativeAtId;
65 typedef unsigned int NativeAtAttr;
66 
67 typedef struct {
68     unsigned int tokenUniqueId : 20;
69     unsigned int reserved : 7;
70     unsigned int type : 2;
71     unsigned int version : 3;
72 } AtInnerInfo;
73 
74 typedef struct {
75     NativeAtId tokenId;
76     NativeAtAttr tokenAttr;
77 } NativeAtIdEx;
78 
79 typedef struct TokenList {
80     NativeAtId tokenId;
81     int32_t apl;
82     char *dcaps[MAX_DCAPS_NUM];
83     char *perms[MAX_PERM_NUM];
84     char *acls[MAX_PERM_NUM];
85     int32_t dcapsNum;
86     int32_t permsNum;
87     int32_t aclsNum;
88     char processName[MAX_PROCESS_NAME_LEN + 1];
89     struct TokenList *next;
90 } NativeTokenList;
91 
92 typedef struct StrArrayAttribute {
93     int32_t maxStrNum;
94     uint32_t maxStrLen;
95     const char *strKey;
96 } StrArrayAttr;
97 
98 extern int32_t GetFileBuff(const char *cfg, char **retBuff);
99 extern int32_t AtlibInit(void);
100 #ifdef __cplusplus
101 }
102 #endif
103 
104 #endif // NATIVE_TOKEN_H