1 | /* $Id: display-ipc.h 96407 2022-08-22 17:43:14Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Guest Additions - DRM IPC communication core function definitions.
|
---|
4 | *
|
---|
5 | * Definitions for IPC communication in between VBoxDRMClient and VBoxClient.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2006-2022 Oracle and/or its affiliates.
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox base platform packages, as
|
---|
12 | * available from https://www.virtualbox.org.
|
---|
13 | *
|
---|
14 | * This program is free software; you can redistribute it and/or
|
---|
15 | * modify it under the terms of the GNU General Public License
|
---|
16 | * as published by the Free Software Foundation, in version 3 of the
|
---|
17 | * License.
|
---|
18 | *
|
---|
19 | * This program is distributed in the hope that it will be useful, but
|
---|
20 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
22 | * General Public License for more details.
|
---|
23 | *
|
---|
24 | * You should have received a copy of the GNU General Public License
|
---|
25 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
26 | *
|
---|
27 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
28 | */
|
---|
29 |
|
---|
30 | #ifndef GA_INCLUDED_SRC_x11_VBoxClient_display_ipc_h
|
---|
31 | #define GA_INCLUDED_SRC_x11_VBoxClient_display_ipc_h
|
---|
32 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
33 | # pragma once
|
---|
34 | #endif
|
---|
35 |
|
---|
36 | # include <iprt/assert.h>
|
---|
37 | # include <iprt/localipc.h>
|
---|
38 | # include <iprt/critsect.h>
|
---|
39 | # include <iprt/list.h>
|
---|
40 |
|
---|
41 | /** Name of DRM IPC server.*/
|
---|
42 | # define VBOX_DRMIPC_SERVER_NAME "DRMIpcServer"
|
---|
43 | /** A user group which is allowed to connect to IPC server. */
|
---|
44 | #define VBOX_DRMIPC_USER_GROUP "vboxdrmipc"
|
---|
45 | /** Time in milliseconds to wait for host events. */
|
---|
46 | #define VBOX_DRMIPC_RX_TIMEOUT_MS (500)
|
---|
47 | /** Time in milliseconds to relax in between unsuccessful connect attempts. */
|
---|
48 | #define VBOX_DRMIPC_RX_RELAX_MS (500)
|
---|
49 | /** Size of RX buffer for IPC communication. */
|
---|
50 | #define VBOX_DRMIPC_RX_BUFFER_SIZE (1024)
|
---|
51 | /** Maximum amount of TX messages which can be queued. */
|
---|
52 | #define VBOX_DRMIPC_TX_QUEUE_SIZE (64)
|
---|
53 | /** Maximum number of physical monitor configurations we can process. */
|
---|
54 | #define VBOX_DRMIPC_MONITORS_MAX (32)
|
---|
55 |
|
---|
56 | /** Rectangle structure for geometry of a single screen. */
|
---|
57 | struct VBOX_DRMIPC_VMWRECT
|
---|
58 | {
|
---|
59 | /** Monitor X offset. */
|
---|
60 | int32_t x;
|
---|
61 | /** Monitor Y offset. */
|
---|
62 | int32_t y;
|
---|
63 | /** Monitor width. */
|
---|
64 | uint32_t w;
|
---|
65 | /** Monitor height. */
|
---|
66 | uint32_t h;
|
---|
67 | };
|
---|
68 | AssertCompileSize(struct VBOX_DRMIPC_VMWRECT, 16);
|
---|
69 |
|
---|
70 | /** List of IPC commands issued by client to server. */
|
---|
71 | typedef enum VBOXDRMIPCSRVCMD
|
---|
72 | {
|
---|
73 | /** Separate server and client commands by starting index. */
|
---|
74 | VBOXDRMIPCSRVCMD_INVALID = 0x00,
|
---|
75 | /** Client reports list of current display offsets. */
|
---|
76 | VBOXDRMIPCSRVCMD_REPORT_DISPLAY_OFFSETS,
|
---|
77 | /** Termination of commands list. */
|
---|
78 | VBOXDRMIPCSRVCMD_MAX
|
---|
79 | } VBOXDRMIPCSRVCMD;
|
---|
80 |
|
---|
81 | /** List of IPC commands issued by server to client. */
|
---|
82 | typedef enum VBOXDRMIPCCLTCMD
|
---|
83 | {
|
---|
84 | /** Separate server and client commands by starting index. */
|
---|
85 | VBOXDRMIPCCLTCMD_INVALID = 0x7F,
|
---|
86 | /** Server requests client to set primary screen. */
|
---|
87 | VBOXDRMIPCCLTCMD_SET_PRIMARY_DISPLAY,
|
---|
88 | /** Termination of commands list. */
|
---|
89 | VBOXDRMIPCCLTCMD_MAX
|
---|
90 | } VBOXDRMIPCCLTCMD;
|
---|
91 |
|
---|
92 | /** IPC command header. */
|
---|
93 | typedef struct VBOX_DRMIPC_COMMAND_HEADER
|
---|
94 | {
|
---|
95 | /** IPC command structure checksum, includes header and payload. */
|
---|
96 | uint64_t u64Crc;
|
---|
97 | /** IPC command identificator (opaque). */
|
---|
98 | uint8_t idCmd;
|
---|
99 | /** Size of payload data. */
|
---|
100 | uint64_t cbData;
|
---|
101 |
|
---|
102 | } VBOX_DRMIPC_COMMAND_HEADER;
|
---|
103 |
|
---|
104 | /** Pointer to IPC command header. */
|
---|
105 | typedef VBOX_DRMIPC_COMMAND_HEADER *PVBOX_DRMIPC_COMMAND_HEADER;
|
---|
106 |
|
---|
107 | /** IPC command VBOXDRMIPCCLTCMD_SET_PRIMARY_DISPLAY payload. */
|
---|
108 | typedef struct VBOX_DRMIPC_COMMAND_SET_PRIMARY_DISPLAY
|
---|
109 | {
|
---|
110 | /* IPC command header. */
|
---|
111 | VBOX_DRMIPC_COMMAND_HEADER Hdr;
|
---|
112 | /** ID of display to be set as primary. */
|
---|
113 | uint32_t idDisplay;
|
---|
114 |
|
---|
115 | } VBOX_DRMIPC_COMMAND_SET_PRIMARY_DISPLAY;
|
---|
116 |
|
---|
117 | /** Pointer to IPC command DRMIPCCOMMAND_SET_PRIMARY_DISPLAY payload. */
|
---|
118 | typedef VBOX_DRMIPC_COMMAND_SET_PRIMARY_DISPLAY *PVBOX_DRMIPC_COMMAND_SET_PRIMARY_DISPLAY;
|
---|
119 |
|
---|
120 | /** IPC command VBOXDRMIPCSRVCMD_REPORT_DISPLAY_OFFSETS payload. */
|
---|
121 | typedef struct VBOX_DRMIPC_COMMAND_REPORT_DISPLAY_OFFSETS
|
---|
122 | {
|
---|
123 | /* IPC command header. */
|
---|
124 | VBOX_DRMIPC_COMMAND_HEADER Hdr;
|
---|
125 | /** Number of displays which have changed offsets. */
|
---|
126 | uint32_t cDisplays;
|
---|
127 | /** Offsets data. */
|
---|
128 | struct VBOX_DRMIPC_VMWRECT aDisplays[VBOX_DRMIPC_MONITORS_MAX];
|
---|
129 | } VBOX_DRMIPC_COMMAND_REPORT_DISPLAY_OFFSETS;
|
---|
130 |
|
---|
131 | /** Pointer to IPC command DRMIPCCOMMAND_SET_PRIMARY_DISPLAY payload. */
|
---|
132 | typedef VBOX_DRMIPC_COMMAND_REPORT_DISPLAY_OFFSETS *PVBOX_DRMIPC_COMMAND_REPORT_DISPLAY_OFFSETS;
|
---|
133 |
|
---|
134 | /** DRM IPC TX list entry. */
|
---|
135 | typedef struct VBOX_DRMIPC_TX_LIST_ENTRY
|
---|
136 | {
|
---|
137 | /** The list node. */
|
---|
138 | RTLISTNODE Node;
|
---|
139 | /* IPC command header. */
|
---|
140 | VBOX_DRMIPC_COMMAND_HEADER Hdr;
|
---|
141 | } VBOX_DRMIPC_TX_LIST_ENTRY;
|
---|
142 |
|
---|
143 | /** Pointer to DRM IPC TX list entry. */
|
---|
144 | typedef VBOX_DRMIPC_TX_LIST_ENTRY *PVBOX_DRMIPC_TX_LIST_ENTRY;
|
---|
145 |
|
---|
146 | /**
|
---|
147 | * A callback function which is called by IPC client session thread when new message arrives.
|
---|
148 | *
|
---|
149 | * @returns IPRT status code.
|
---|
150 | * @param idCmd Command ID to be executed (opaque).
|
---|
151 | * @param pvData Command specific argument data.
|
---|
152 | * @param cbData Size of command argument data as received over IPC.
|
---|
153 | */
|
---|
154 | typedef DECLCALLBACKTYPE(int, FNDRMIPCRXCB, (uint8_t idCmd, void *pvData, uint32_t cbData));
|
---|
155 |
|
---|
156 | /** Pointer to FNDRMIPCRXCB. */
|
---|
157 | typedef FNDRMIPCRXCB *PFNDRMIPCRXCB;
|
---|
158 |
|
---|
159 | /** IPC session private data. */
|
---|
160 | typedef struct VBOX_DRMIPC_CLIENT
|
---|
161 | {
|
---|
162 | /** Thread handle which dispatches this IPC client session. */
|
---|
163 | RTTHREAD hThread;
|
---|
164 | /** IPC session handle. */
|
---|
165 | RTLOCALIPCSESSION hClientSession;
|
---|
166 | /** TX message queue mutex. */
|
---|
167 | RTCRITSECT CritSect;
|
---|
168 | /** TX message queue (accessed under critsect). */
|
---|
169 | VBOX_DRMIPC_TX_LIST_ENTRY TxList;
|
---|
170 | /** Maximum number of messages which can be queued to TX message queue. */
|
---|
171 | uint32_t cTxListCapacity;
|
---|
172 | /** Actual number of messages currently queued to TX message queue (accessed under critsect). */
|
---|
173 | uint32_t cTxListSize;
|
---|
174 | /** IPC RX callback. */
|
---|
175 | PFNDRMIPCRXCB pfnRxCb;
|
---|
176 | } VBOX_DRMIPC_CLIENT;
|
---|
177 |
|
---|
178 | /** Pointer to IPC session private data. */
|
---|
179 | typedef VBOX_DRMIPC_CLIENT *PVBOX_DRMIPC_CLIENT;
|
---|
180 |
|
---|
181 | /** Static initializer for VBOX_DRMIPC_CLIENT. */
|
---|
182 | #define VBOX_DRMIPC_CLIENT_INITIALIZER { NIL_RTTHREAD, 0, 0, 0, 0, 0, 0 }
|
---|
183 |
|
---|
184 | /**
|
---|
185 | * Initialize IPC client private data.
|
---|
186 | *
|
---|
187 | * @return IPRT status code.
|
---|
188 | * @param pClient IPC client private data to be initialized.
|
---|
189 | * @param hThread A thread which server IPC client connection.
|
---|
190 | * @param hClientSession IPC session handle obtained from RTLocalIpcSessionXXX().
|
---|
191 | * @param cTxListCapacity Maximum number of messages which can be queued for TX for this IPC session.
|
---|
192 | * @param pfnRxCb IPC RX callback function pointer.
|
---|
193 | */
|
---|
194 | RTDECL(int) vbDrmIpcClientInit(PVBOX_DRMIPC_CLIENT pClient, RTTHREAD hThread, RTLOCALIPCSESSION hClientSession,
|
---|
195 | uint32_t cTxListCapacity, PFNDRMIPCRXCB pfnRxCb);
|
---|
196 |
|
---|
197 | /**
|
---|
198 | * Releases IPC client private data resources.
|
---|
199 | *
|
---|
200 | * @return IPRT status code.
|
---|
201 | * @param pClient IPC session private data to be initialized.
|
---|
202 | */
|
---|
203 | RTDECL(int) vbDrmIpcClientReleaseResources(PVBOX_DRMIPC_CLIENT pClient);
|
---|
204 |
|
---|
205 | /**
|
---|
206 | * Verify if remote IPC peer corresponds to a process which is running
|
---|
207 | * from allowed user.
|
---|
208 | *
|
---|
209 | * @return IPRT status code.
|
---|
210 | * @param hClientSession IPC session handle.
|
---|
211 | */
|
---|
212 | RTDECL(int) vbDrmIpcAuth(RTLOCALIPCSESSION hClientSession);
|
---|
213 |
|
---|
214 | /**
|
---|
215 | * Common function for both IPC server and client which is responsible
|
---|
216 | * for handling IPC communication flow.
|
---|
217 | *
|
---|
218 | * @return IPRT status code.
|
---|
219 | * @param pClient IPC connection private data.
|
---|
220 | */
|
---|
221 | RTDECL(int) vbDrmIpcConnectionHandler(PVBOX_DRMIPC_CLIENT pClient);
|
---|
222 |
|
---|
223 | /**
|
---|
224 | * Request remote IPC peer to set primary display.
|
---|
225 | *
|
---|
226 | * @return IPRT status code.
|
---|
227 | * @param pClient IPC session private data.
|
---|
228 | * @param idDisplay ID of display to be set as primary.
|
---|
229 | */
|
---|
230 | RTDECL(int) vbDrmIpcSetPrimaryDisplay(PVBOX_DRMIPC_CLIENT pClient, uint32_t idDisplay);
|
---|
231 |
|
---|
232 | /**
|
---|
233 | * Report to IPC server that display layout offsets have been changed (called by IPC client).
|
---|
234 | *
|
---|
235 | * @return IPRT status code.
|
---|
236 | * @param pClient IPC session private data.
|
---|
237 | * @param cDisplays Number of monitors which have offsets changed.
|
---|
238 | * @param aDisplays Offsets data.
|
---|
239 | */
|
---|
240 | RTDECL(int) vbDrmIpcReportDisplayOffsets(PVBOX_DRMIPC_CLIENT pClient, uint32_t cDisplays, struct VBOX_DRMIPC_VMWRECT *aDisplays);
|
---|
241 |
|
---|
242 | #endif /* !GA_INCLUDED_SRC_x11_VBoxClient_display_ipc_h */
|
---|