1 | /* $Id: VBoxGuest2.cpp 31661 2010-08-13 15:49:24Z 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 | * Important: VMMDev *awaits* a VMMDevReportGuestInfo or VMMDevReportGuestInfo2 message
|
---|
41 | * first in order to accept all other VMMDev messages! Otherwise you'd get
|
---|
42 | * a VERR_NOT_SUPPORTED error.
|
---|
43 | */
|
---|
44 | VMMDevReportGuestInfo2 *pReq = NULL;
|
---|
45 | int rc = VbglGRAlloc((VMMDevRequestHeader **)&pReq, sizeof (VMMDevReportGuestInfo2), VMMDevReq_ReportGuestInfo2);
|
---|
46 | Log(("VBoxGuestReportGuestInfo: VbglGRAlloc VMMDevReportGuestInfo2 completed with rc=%Rrc\n", rc));
|
---|
47 | if (RT_SUCCESS(rc))
|
---|
48 | {
|
---|
49 | pReq->guestInfo.additionsMajor = VBOX_VERSION_MAJOR;
|
---|
50 | pReq->guestInfo.additionsMinor = VBOX_VERSION_MINOR;
|
---|
51 | pReq->guestInfo.additionsBuild = VBOX_VERSION_BUILD;
|
---|
52 | pReq->guestInfo.additionsRevision = VBOX_SVN_REV;
|
---|
53 | pReq->guestInfo.additionsFeatures = 0; /* Not (never?) used. */
|
---|
54 | RTStrCopy(pReq->guestInfo.szName, sizeof(pReq->guestInfo.szName), VBOX_VERSION_STRING);
|
---|
55 |
|
---|
56 | rc = VbglGRPerform(&pReq->header);
|
---|
57 | Log(("VBoxGuestReportGuestInfo: VbglGRPerform VMMDevReportGuestInfo2 completed with rc=%Rrc\n", rc));
|
---|
58 | if (rc == VERR_NOT_IMPLEMENTED) /* Compatibility with older hosts. */
|
---|
59 | rc = VINF_SUCCESS;
|
---|
60 | VbglGRFree(&pReq->header);
|
---|
61 | }
|
---|
62 |
|
---|
63 | /*
|
---|
64 | * VMMDevReportGuestInfo acts as a beacon and signals the host that all guest information is
|
---|
65 | * now complete. So always send this report last!
|
---|
66 | */
|
---|
67 | if (RT_SUCCESS(rc))
|
---|
68 | {
|
---|
69 | VMMDevReportGuestInfo *pReq3 = NULL;
|
---|
70 | rc = VbglGRAlloc((VMMDevRequestHeader **)&pReq3, sizeof (VMMDevReportGuestInfo), VMMDevReq_ReportGuestInfo);
|
---|
71 | Log(("VBoxGuestReportGuestInfo: VbglGRAlloc VMMDevReportGuestInfo completed with rc=%Rrc\n", rc));
|
---|
72 | if (RT_SUCCESS(rc))
|
---|
73 | {
|
---|
74 | pReq3->guestInfo.interfaceVersion = VMMDEV_VERSION;
|
---|
75 | pReq3->guestInfo.osType = enmOSType;
|
---|
76 |
|
---|
77 | rc = VbglGRPerform(&pReq3->header);
|
---|
78 | Log(("VBoxGuestReportGuestInfo: VbglGRPerform VMMDevReportGuestInfo completed with rc=%Rrc\n", rc));
|
---|
79 | VbglGRFree(&pReq3->header);
|
---|
80 | }
|
---|
81 | }
|
---|
82 |
|
---|
83 | return rc;
|
---|
84 | }
|
---|
85 |
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Report the guest driver status to the host.
|
---|
89 | *
|
---|
90 | * @returns IPRT status code.
|
---|
91 | * @param fActive Flag whether the driver is now active or not.
|
---|
92 | */
|
---|
93 | int VBoxGuestReportDriverStatus(bool fActive)
|
---|
94 | {
|
---|
95 | /*
|
---|
96 | * Report guest status of the VBox driver to the host.
|
---|
97 | */
|
---|
98 | VMMDevReportGuestStatus *pReq2 = NULL;
|
---|
99 | int rc = VbglGRAlloc((VMMDevRequestHeader **)&pReq2, sizeof(*pReq2), VMMDevReq_ReportGuestStatus);
|
---|
100 | Log(("VBoxGuestReportDriverStatus: VbglGRAlloc VMMDevReportGuestStatus completed with rc=%Rrc\n", rc));
|
---|
101 | if (RT_SUCCESS(rc))
|
---|
102 | {
|
---|
103 | pReq2->guestStatus.facility = VBoxGuestStatusFacility_VBoxGuestDriver;
|
---|
104 | pReq2->guestStatus.status = fActive ?
|
---|
105 | VBoxGuestStatusCurrent_Active
|
---|
106 | : VBoxGuestStatusCurrent_Inactive;
|
---|
107 | pReq2->guestStatus.flags = 0;
|
---|
108 | rc = VbglGRPerform(&pReq2->header);
|
---|
109 | Log(("VBoxGuestReportDriverStatus: VbglGRPerform VMMDevReportGuestStatus completed with fActive=%d, rc=%Rrc\n",
|
---|
110 | rc, fActive ? 1 : 0));
|
---|
111 | if (rc == VERR_NOT_IMPLEMENTED) /* Compatibility with older hosts. */
|
---|
112 | rc = VINF_SUCCESS;
|
---|
113 | VbglGRFree(&pReq2->header);
|
---|
114 | }
|
---|
115 |
|
---|
116 | return rc;
|
---|
117 | }
|
---|
118 |
|
---|