1 /* 2 * Copyright (c) 2024 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 APPSPAWN_CLIENT_MSG_H 17 #define APPSPAWN_CLIENT_MSG_H 18 19 #include <stdint.h> 20 #include <stdio.h> 21 #include <stdlib.h> 22 23 #include "appspawn.h" 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 #define NWEBSPAWN_SOCKET_NAME "NWebSpawn" 30 #define APPSPAWN_SOCKET_NAME "AppSpawn" 31 #define KEEPALIVE_NAME "keepalive" 32 33 #define APPSPAWN_ALIGN(len) (((len) + 0x03) & (~0x03)) 34 #define APPSPAWN_TLV_NAME_LEN 32 35 #define MAX_MSG_BLOCK_LEN (4 * 1024) 36 #define RECV_BLOCK_LEN 1024 37 #define MAX_MSG_TOTAL_LENGTH (64 * 1024) 38 #define EXTRAINFO_TOTAL_LENGTH_MAX (32 * 1024) 39 #define MAX_TLV_COUNT 128 40 #define APPSPAWN_MSG_MAGIC 0xEF201234 41 42 #define APP_LEN_PROC_NAME 256 // process name length 43 #define APP_LEN_BUNDLE_NAME 256 // bundle name length 44 #define APP_LEN_SO_PATH 256 // load so lib 45 #define APP_APL_MAX_LEN 32 46 #define APP_RENDER_CMD_MAX_LEN 2048 47 #define APP_OWNER_ID_LEN 64 48 49 typedef enum { 50 TLV_BUNDLE_INFO = 0, 51 TLV_MSG_FLAGS, 52 TLV_DAC_INFO, 53 TLV_DOMAIN_INFO, 54 TLV_OWNER_INFO, 55 TLV_ACCESS_TOKEN_INFO, 56 TLV_PERMISSION, 57 TLV_INTERNET_INFO, 58 TLV_RENDER_TERMINATION_INFO, 59 TLV_MAX 60 } AppSpawnMsgTlvType; 61 62 #define DATA_TYPE_STRING 1 63 64 #if defined(__clang__) 65 # pragma clang diagnostic push 66 # pragma clang diagnostic ignored "-Wextern-c-compat" 67 #elif defined(__GNUC__) 68 # pragma GCC diagnostic push 69 # pragma GCC diagnostic ignored "-Wextern-c-compat" 70 #elif defined(_MSC_VER) 71 # pragma warning(push) 72 #endif 73 74 #pragma pack(4) 75 typedef AppDacInfo AppSpawnMsgDacInfo; 76 77 typedef struct { 78 uint16_t tlvLen; 79 uint16_t tlvType; 80 } AppSpawnTlv; 81 82 typedef struct { 83 uint16_t tlvLen; // 对齐后的长度 84 uint16_t tlvType; 85 uint16_t dataLen; // 数据的长度 86 uint16_t dataType; 87 char tlvName[APPSPAWN_TLV_NAME_LEN]; 88 } AppSpawnTlvExt; 89 90 typedef struct { 91 uint32_t count; 92 uint32_t flags[0]; 93 } AppSpawnMsgFlags; 94 95 typedef struct { 96 uint64_t accessTokenIdEx; 97 } AppSpawnMsgAccessToken; 98 99 typedef struct { 100 char ownerId[0]; // app identifier id 101 } AppSpawnMsgOwnerId; 102 103 typedef struct { 104 uint8_t setAllowInternet; 105 uint8_t allowInternet; // hap sockect allowed 106 uint8_t res[2]; 107 } AppSpawnMsgInternetInfo; 108 109 typedef struct { 110 uint32_t hapFlags; 111 char apl[0]; 112 } AppSpawnMsgDomainInfo; 113 114 typedef struct { 115 uint32_t bundleIndex; 116 char bundleName[0]; // process name 117 } AppSpawnMsgBundleInfo; 118 119 typedef struct TagAppSpawnMsg { 120 uint32_t magic; 121 uint32_t msgType; 122 uint32_t msgLen; 123 uint32_t msgId; 124 uint32_t tlvCount; 125 char processName[APP_LEN_PROC_NAME]; 126 } AppSpawnMsg; 127 128 typedef struct { 129 AppSpawnMsg msgHdr; 130 AppSpawnResult result; 131 } AppSpawnResponseMsg; 132 #pragma pack() 133 134 #if defined(__clang__) 135 # pragma clang diagnostic pop 136 #elif defined(__GNUC__) 137 # pragma GCC diagnostic pop 138 #elif defined(_MSC_VER) 139 # pragma warning(pop) 140 #endif 141 142 #ifdef __cplusplus 143 } 144 #endif 145 #endif // APPSPAWN_CLIENT_MSG_H 146