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