1 | /* $Id: VBoxGuest2.cpp 32187 2010-09-02 08:34:18Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxGuest - Guest Additions Driver, bits shared with the windows code.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010 Oracle Corporation
|
---|
8 | *
|
---|
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.
|
---|
16 | */
|
---|
17 |
|
---|
18 | /*******************************************************************************
|
---|
19 | * Header Files *
|
---|
20 | *******************************************************************************/
|
---|
21 | #include <iprt/string.h>
|
---|
22 | #include <VBox/err.h>
|
---|
23 | #include <VBox/log.h>
|
---|
24 | #include <VBox/VBoxGuestLib.h>
|
---|
25 | #include <VBox/version.h>
|
---|
26 | #if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
|
---|
27 | # include "revision-generated.h"
|
---|
28 | #endif
|
---|
29 |
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Report the guest information to the host.
|
---|
33 | *
|
---|
34 | * @returns IPRT status code.
|
---|
35 | * @param enmOSType The OS type to report.
|
---|
36 | */
|
---|
37 | int VBoxGuestReportGuestInfo(VBOXOSTYPE enmOSType)
|
---|
38 | {
|
---|
39 | /*
|
---|
40 | * Allocate and fill in the two guest info reports.
|
---|
41 | */
|
---|
42 | VMMDevReportGuestInfo2 *pReqInfo2 = NULL;
|
---|
43 | VMMDevReportGuestInfo *pReqInfo1 = NULL;
|
---|
44 | int rc = VbglGRAlloc((VMMDevRequestHeader **)&pReqInfo2, sizeof (VMMDevReportGuestInfo2), VMMDevReq_ReportGuestInfo2);
|
---|
45 | Log(("VBoxGuestReportGuestInfo: VbglGRAlloc VMMDevReportGuestInfo2 completed with rc=%Rrc\n", rc));
|
---|
46 | if (RT_SUCCESS(rc))
|
---|
47 | {
|
---|
48 | pReqInfo2->guestInfo.additionsMajor = VBOX_VERSION_MAJOR;
|
---|
49 | pReqInfo2->guestInfo.additionsMinor = VBOX_VERSION_MINOR;
|
---|
50 | pReqInfo2->guestInfo.additionsBuild = VBOX_VERSION_BUILD;
|
---|
51 | pReqInfo2->guestInfo.additionsRevision = VBOX_SVN_REV;
|
---|
52 | pReqInfo2->guestInfo.additionsFeatures = 0; /* (no features defined yet) */
|
---|
53 | RTStrCopy(pReqInfo2->guestInfo.szName, sizeof(pReqInfo2->guestInfo.szName), VBOX_VERSION_STRING);
|
---|
54 |
|
---|
55 | rc = VbglGRAlloc((VMMDevRequestHeader **)&pReqInfo1, sizeof (VMMDevReportGuestInfo), VMMDevReq_ReportGuestInfo);
|
---|
56 | Log(("VBoxGuestReportGuestInfo: VbglGRAlloc VMMDevReportGuestInfo completed with rc=%Rrc\n", rc));
|
---|
57 | if (RT_SUCCESS(rc))
|
---|
58 | {
|
---|
59 | pReqInfo1->guestInfo.interfaceVersion = VMMDEV_VERSION;
|
---|
60 | pReqInfo1->guestInfo.osType = enmOSType;
|
---|
61 |
|
---|
62 | /*
|
---|
63 | * There are two protocols here:
|
---|
64 | * 1. Info2 + Info1. Supported by >=3.2.51.
|
---|
65 | * 2. Info1 and optionally Info2. The old protocol.
|
---|
66 | *
|
---|
67 | * We try protocol 1 first. It will fail with VERR_NOT_SUPPORTED
|
---|
68 | * if not supported by the VMMDev (message ordering requirement).
|
---|
69 | */
|
---|
70 | rc = VbglGRPerform(&pReqInfo2->header);
|
---|
71 | Log(("VBoxGuestReportGuestInfo: VbglGRPerform VMMDevReportGuestInfo2 completed with rc=%Rrc\n", rc));
|
---|
72 | if (RT_SUCCESS(rc))
|
---|
73 | {
|
---|
74 | rc = VbglGRPerform(&pReqInfo1->header);
|
---|
75 | Log(("VBoxGuestReportGuestInfo: VbglGRPerform VMMDevReportGuestInfo completed with rc=%Rrc\n", rc));
|
---|
76 | }
|
---|
77 | else if ( rc == VERR_NOT_SUPPORTED
|
---|
78 | || rc == VERR_NOT_IMPLEMENTED)
|
---|
79 | {
|
---|
80 | rc = VbglGRPerform(&pReqInfo1->header);
|
---|
81 | Log(("VBoxGuestReportGuestInfo: VbglGRPerform VMMDevReportGuestInfo completed with rc=%Rrc\n", rc));
|
---|
82 | if (RT_SUCCESS(rc))
|
---|
83 | {
|
---|
84 | rc = VbglGRPerform(&pReqInfo2->header);
|
---|
85 | Log(("VBoxGuestReportGuestInfo: VbglGRPerform VMMDevReportGuestInfo2 completed with rc=%Rrc\n", rc));
|
---|
86 | if (rc == VERR_NOT_IMPLEMENTED)
|
---|
87 | rc = VINF_SUCCESS;
|
---|
88 | }
|
---|
89 | }
|
---|
90 | VbglGRFree(&pReqInfo1->header);
|
---|
91 | }
|
---|
92 | VbglGRFree(&pReqInfo2->header);
|
---|
93 | }
|
---|
94 |
|
---|
95 | return rc;
|
---|
96 | }
|
---|
97 |
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * Report the guest driver status to the host.
|
---|
101 | *
|
---|
102 | * @returns IPRT status code.
|
---|
103 | * @param fActive Flag whether the driver is now active or not.
|
---|
104 | */
|
---|
105 | int VBoxGuestReportDriverStatus(bool fActive)
|
---|
106 | {
|
---|
107 | /*
|
---|
108 | * Report guest status of the VBox driver to the host.
|
---|
109 | */
|
---|
110 | VMMDevReportGuestStatus *pReq2 = NULL;
|
---|
111 | int rc = VbglGRAlloc((VMMDevRequestHeader **)&pReq2, sizeof(*pReq2), VMMDevReq_ReportGuestStatus);
|
---|
112 | Log(("VBoxGuestReportDriverStatus: VbglGRAlloc VMMDevReportGuestStatus completed with rc=%Rrc\n", rc));
|
---|
113 | if (RT_SUCCESS(rc))
|
---|
114 | {
|
---|
115 | pReq2->guestStatus.facility = VBoxGuestStatusFacility_VBoxGuestDriver;
|
---|
116 | pReq2->guestStatus.status = fActive ?
|
---|
117 | VBoxGuestStatusCurrent_Active
|
---|
118 | : VBoxGuestStatusCurrent_Inactive;
|
---|
119 | pReq2->guestStatus.flags = 0;
|
---|
120 | rc = VbglGRPerform(&pReq2->header);
|
---|
121 | Log(("VBoxGuestReportDriverStatus: VbglGRPerform VMMDevReportGuestStatus completed with fActive=%d, rc=%Rrc\n",
|
---|
122 | rc, fActive ? 1 : 0));
|
---|
123 | if (rc == VERR_NOT_IMPLEMENTED) /* Compatibility with older hosts. */
|
---|
124 | rc = VINF_SUCCESS;
|
---|
125 | VbglGRFree(&pReq2->header);
|
---|
126 | }
|
---|
127 |
|
---|
128 | return rc;
|
---|
129 | }
|
---|
130 |
|
---|