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