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