1
/* $Id: VBoxGuestR3LibHostChannel.cpp $ */
3
* VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Host Channel.
7
* Copyright (C) 2012 Oracle Corporation
9
* This file is part of VirtualBox Open Source Edition (OSE), as
10
* available from http://www.virtualbox.org. This file is free software;
11
* you can redistribute it and/or modify it under the terms of the GNU
12
* General Public License (GPL) as published by the Free Software
13
* Foundation, in version 2 as it comes in the "COPYING" file of the
14
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17
* The contents of this file may alternatively be used under the terms
18
* of the Common Development and Distribution License Version 1.0
19
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20
* VirtualBox OSE distribution, in which case the provisions of the
21
* CDDL are applicable instead of those of the GPL.
23
* You may elect to license modified versions of this file under the
24
* terms and conditions of either the GPL or the CDDL or both.
30
#include <VBox/HostServices/VBoxHostChannel.h>
32
#include "VBGLR3Internal.h"
35
VBGLR3DECL(int) VbglR3HostChannelInit(uint32_t *pu32HGCMClientId)
37
VBoxGuestHGCMConnectInfo connectInfo;
40
connectInfo.result = VERR_WRONG_ORDER;
41
connectInfo.Loc.type = VMMDevHGCMLoc_LocalHost_Existing;
42
strcpy(connectInfo.Loc.u.host.achName, "VBoxHostChannel");
43
connectInfo.u32ClientID = 0;
45
int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CONNECT, &connectInfo, sizeof(connectInfo));
49
rc = connectInfo.result;
53
*pu32HGCMClientId = connectInfo.u32ClientID;
60
VBGLR3DECL(void) VbglR3HostChannelTerm(uint32_t u32HGCMClientId)
62
VBoxGuestHGCMDisconnectInfo disconnectInfo;
63
disconnectInfo.result = VERR_WRONG_ORDER;
64
disconnectInfo.u32ClientID = u32HGCMClientId;
66
vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_DISCONNECT, &disconnectInfo, sizeof(disconnectInfo));
69
VBGLR3DECL(int) VbglR3HostChannelAttach(uint32_t *pu32ChannelHandle,
70
uint32_t u32HGCMClientId,
74
/* Make a heap copy of the name, because HGCM can not use some of other memory types. */
75
size_t cbName = strlen(pszName) + 1;
76
char *pszCopy = (char *)RTMemAlloc(cbName);
79
return VERR_NO_MEMORY;
82
memcpy(pszCopy, pszName, cbName);
84
VBoxHostChannelAttach parms;
86
parms.hdr.result = VERR_WRONG_ORDER;
87
parms.hdr.u32ClientID = u32HGCMClientId;
88
parms.hdr.u32Function = VBOX_HOST_CHANNEL_FN_ATTACH;
91
VbglHGCMParmPtrSet(&parms.name, pszCopy, (uint32_t)cbName);
92
VbglHGCMParmUInt32Set(&parms.flags, u32Flags);
93
VbglHGCMParmUInt32Set(&parms.handle, 0);
95
int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(parms)), &parms, sizeof(parms));
99
rc = parms.hdr.result;
102
*pu32ChannelHandle = parms.handle.u.value32;
111
VBGLR3DECL(void) VbglR3HostChannelDetach(uint32_t u32ChannelHandle,
112
uint32_t u32HGCMClientId)
114
VBoxHostChannelDetach parms;
116
parms.hdr.result = VERR_WRONG_ORDER;
117
parms.hdr.u32ClientID = u32HGCMClientId;
118
parms.hdr.u32Function = VBOX_HOST_CHANNEL_FN_DETACH;
119
parms.hdr.cParms = 1;
121
VbglHGCMParmUInt32Set(&parms.handle, u32ChannelHandle);
123
vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(parms)), &parms, sizeof(parms));
126
VBGLR3DECL(int) VbglR3HostChannelSend(uint32_t u32ChannelHandle,
127
uint32_t u32HGCMClientId,
131
VBoxHostChannelSend parms;
133
parms.hdr.result = VERR_WRONG_ORDER;
134
parms.hdr.u32ClientID = u32HGCMClientId;
135
parms.hdr.u32Function = VBOX_HOST_CHANNEL_FN_SEND;
136
parms.hdr.cParms = 2;
138
VbglHGCMParmUInt32Set(&parms.handle, u32ChannelHandle);
139
VbglHGCMParmPtrSet(&parms.data, pvData, cbData);
141
int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(parms)), &parms, sizeof(parms));
145
rc = parms.hdr.result;
151
VBGLR3DECL(int) VbglR3HostChannelRecv(uint32_t u32ChannelHandle,
152
uint32_t u32HGCMClientId,
155
uint32_t *pu32SizeReceived,
156
uint32_t *pu32SizeRemaining)
158
VBoxHostChannelRecv parms;
160
parms.hdr.result = VERR_WRONG_ORDER;
161
parms.hdr.u32ClientID = u32HGCMClientId;
162
parms.hdr.u32Function = VBOX_HOST_CHANNEL_FN_RECV;
163
parms.hdr.cParms = 4;
165
VbglHGCMParmUInt32Set(&parms.handle, u32ChannelHandle);
166
VbglHGCMParmPtrSet(&parms.data, pvData, cbData);
167
VbglHGCMParmUInt32Set(&parms.sizeReceived, 0);
168
VbglHGCMParmUInt32Set(&parms.sizeRemaining, 0);
170
int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(parms)), &parms, sizeof(parms));
174
rc = parms.hdr.result;
178
*pu32SizeReceived = parms.sizeReceived.u.value32;
179
*pu32SizeRemaining = parms.sizeRemaining.u.value32;
186
VBGLR3DECL(int) VbglR3HostChannelControl(uint32_t u32ChannelHandle,
187
uint32_t u32HGCMClientId,
193
uint32_t *pu32SizeDataReturned)
195
VBoxHostChannelControl parms;
197
parms.hdr.result = VERR_WRONG_ORDER;
198
parms.hdr.u32ClientID = u32HGCMClientId;
199
parms.hdr.u32Function = VBOX_HOST_CHANNEL_FN_CONTROL;
200
parms.hdr.cParms = 5;
202
VbglHGCMParmUInt32Set(&parms.handle, u32ChannelHandle);
203
VbglHGCMParmUInt32Set(&parms.code, u32Code);
204
VbglHGCMParmPtrSet(&parms.parm, pvParm, cbParm);
205
VbglHGCMParmPtrSet(&parms.data, pvData, cbData);
206
VbglHGCMParmUInt32Set(&parms.sizeDataReturned, 0);
208
int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(parms)), &parms, sizeof(parms));
212
rc = parms.hdr.result;
216
*pu32SizeDataReturned = parms.sizeDataReturned.u.value32;
223
VBGLR3DECL(int) VbglR3HostChannelEventWait(uint32_t *pu32ChannelHandle,
224
uint32_t u32HGCMClientId,
225
uint32_t *pu32EventId,
228
uint32_t *pu32SizeReturned)
230
VBoxHostChannelEventWait parms;
232
parms.hdr.result = VERR_WRONG_ORDER;
233
parms.hdr.u32ClientID = u32HGCMClientId;
234
parms.hdr.u32Function = VBOX_HOST_CHANNEL_FN_EVENT_WAIT;
235
parms.hdr.cParms = 4;
237
VbglHGCMParmUInt32Set(&parms.handle, 0);
238
VbglHGCMParmUInt32Set(&parms.id, 0);
239
VbglHGCMParmPtrSet(&parms.parm, pvParm, cbParm);
240
VbglHGCMParmUInt32Set(&parms.sizeReturned, 0);
242
int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(parms)), &parms, sizeof(parms));
246
rc = parms.hdr.result;
250
*pu32ChannelHandle = parms.handle.u.value32;
251
*pu32EventId = parms.id.u.value32;
252
*pu32SizeReturned = parms.sizeReturned.u.value32;
259
VBGLR3DECL(int) VbglR3HostChannelEventCancel(uint32_t u32ChannelHandle,
260
uint32_t u32HGCMClientId)
262
VBoxHostChannelEventCancel parms;
264
parms.hdr.result = VERR_WRONG_ORDER;
265
parms.hdr.u32ClientID = u32HGCMClientId;
266
parms.hdr.u32Function = VBOX_HOST_CHANNEL_FN_EVENT_CANCEL;
267
parms.hdr.cParms = 0;
269
int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(parms)), &parms, sizeof(parms));
273
rc = parms.hdr.result;
279
VBGLR3DECL(int) VbglR3HostChannelQuery(const char *pszName,
280
uint32_t u32HGCMClientId,
286
uint32_t *pu32SizeDataReturned)
288
/* Make a heap copy of the name, because HGCM can not use some of other memory types. */
289
size_t cbName = strlen(pszName) + 1;
290
char *pszCopy = (char *)RTMemAlloc(cbName);
293
return VERR_NO_MEMORY;
296
memcpy(pszCopy, pszName, cbName);
298
VBoxHostChannelQuery parms;
300
parms.hdr.result = VERR_WRONG_ORDER;
301
parms.hdr.u32ClientID = u32HGCMClientId;
302
parms.hdr.u32Function = VBOX_HOST_CHANNEL_FN_QUERY;
303
parms.hdr.cParms = 5;
305
VbglHGCMParmPtrSet(&parms.name, pszCopy, (uint32_t)cbName);
306
VbglHGCMParmUInt32Set(&parms.code, u32Code);
307
VbglHGCMParmPtrSet(&parms.parm, pvParm, cbParm);
308
VbglHGCMParmPtrSet(&parms.data, pvData, cbData);
309
VbglHGCMParmUInt32Set(&parms.sizeDataReturned, 0);
311
int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(parms)), &parms, sizeof(parms));
315
rc = parms.hdr.result;
319
*pu32SizeDataReturned = parms.sizeDataReturned.u.value32;