VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest2.cpp@ 51224

Last change on this file since 51224 was 41722, checked in by vboxsync, 13 years ago

Additions/common/VBoxGuest: fixed copyright dates and licence headers and removed a copyright text that is not relevant to this code.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.8 KB
Line 
1/* $Id: VBoxGuest2.cpp 41722 2012-06-14 19:49:31Z vboxsync $ */
2/** @file
3 * VBoxGuest - Guest Additions Driver, bits shared with the windows code.
4 */
5
6/*
7 * Copyright (C) 2011-2012 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 * 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.
22 *
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.
25 */
26
27/*******************************************************************************
28* Header Files *
29*******************************************************************************/
30#include <iprt/string.h>
31#include <VBox/err.h>
32#include <VBox/log.h>
33#include <VBox/VBoxGuestLib.h>
34#include <VBox/version.h>
35#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
36# include "revision-generated.h"
37#endif
38#include "VBoxGuest2.h"
39
40/** @todo Remove and merge this file with VBoxGuest.cpp when the Windows driver
41 * also will be built from the common sources. */
42
43/**
44 * Report the guest information to the host.
45 *
46 * @returns IPRT status code.
47 * @param enmOSType The OS type to report.
48 */
49int VBoxGuestReportGuestInfo(VBOXOSTYPE enmOSType)
50{
51 /*
52 * Allocate and fill in the two guest info reports.
53 */
54 VMMDevReportGuestInfo2 *pReqInfo2 = NULL;
55 VMMDevReportGuestInfo *pReqInfo1 = NULL;
56 int rc = VbglGRAlloc((VMMDevRequestHeader **)&pReqInfo2, sizeof (VMMDevReportGuestInfo2), VMMDevReq_ReportGuestInfo2);
57 Log(("VBoxGuestReportGuestInfo: VbglGRAlloc VMMDevReportGuestInfo2 completed with rc=%Rrc\n", rc));
58 if (RT_SUCCESS(rc))
59 {
60 pReqInfo2->guestInfo.additionsMajor = VBOX_VERSION_MAJOR;
61 pReqInfo2->guestInfo.additionsMinor = VBOX_VERSION_MINOR;
62 pReqInfo2->guestInfo.additionsBuild = VBOX_VERSION_BUILD;
63 pReqInfo2->guestInfo.additionsRevision = VBOX_SVN_REV;
64 pReqInfo2->guestInfo.additionsFeatures = 0; /* (no features defined yet) */
65 RTStrCopy(pReqInfo2->guestInfo.szName, sizeof(pReqInfo2->guestInfo.szName), VBOX_VERSION_STRING);
66
67 rc = VbglGRAlloc((VMMDevRequestHeader **)&pReqInfo1, sizeof (VMMDevReportGuestInfo), VMMDevReq_ReportGuestInfo);
68 Log(("VBoxGuestReportGuestInfo: VbglGRAlloc VMMDevReportGuestInfo completed with rc=%Rrc\n", rc));
69 if (RT_SUCCESS(rc))
70 {
71 pReqInfo1->guestInfo.interfaceVersion = VMMDEV_VERSION;
72 pReqInfo1->guestInfo.osType = enmOSType;
73
74 /*
75 * There are two protocols here:
76 * 1. Info2 + Info1. Supported by >=3.2.51.
77 * 2. Info1 and optionally Info2. The old protocol.
78 *
79 * We try protocol 1 first. It will fail with VERR_NOT_SUPPORTED
80 * if not supported by the VMMDev (message ordering requirement).
81 */
82 rc = VbglGRPerform(&pReqInfo2->header);
83 Log(("VBoxGuestReportGuestInfo: VbglGRPerform VMMDevReportGuestInfo2 completed with rc=%Rrc\n", rc));
84 if (RT_SUCCESS(rc))
85 {
86 rc = VbglGRPerform(&pReqInfo1->header);
87 Log(("VBoxGuestReportGuestInfo: VbglGRPerform VMMDevReportGuestInfo completed with rc=%Rrc\n", rc));
88 }
89 else if ( rc == VERR_NOT_SUPPORTED
90 || rc == VERR_NOT_IMPLEMENTED)
91 {
92 rc = VbglGRPerform(&pReqInfo1->header);
93 Log(("VBoxGuestReportGuestInfo: VbglGRPerform VMMDevReportGuestInfo completed with rc=%Rrc\n", rc));
94 if (RT_SUCCESS(rc))
95 {
96 rc = VbglGRPerform(&pReqInfo2->header);
97 Log(("VBoxGuestReportGuestInfo: VbglGRPerform VMMDevReportGuestInfo2 completed with rc=%Rrc\n", rc));
98 if (rc == VERR_NOT_IMPLEMENTED)
99 rc = VINF_SUCCESS;
100 }
101 }
102 VbglGRFree(&pReqInfo1->header);
103 }
104 VbglGRFree(&pReqInfo2->header);
105 }
106
107 return rc;
108}
109
110
111/**
112 * Report the guest driver status to the host.
113 *
114 * @returns IPRT status code.
115 * @param fActive Flag whether the driver is now active or not.
116 */
117int VBoxGuestReportDriverStatus(bool fActive)
118{
119 /*
120 * Report guest status of the VBox driver to the host.
121 */
122 VMMDevReportGuestStatus *pReq2 = NULL;
123 int rc = VbglGRAlloc((VMMDevRequestHeader **)&pReq2, sizeof(*pReq2), VMMDevReq_ReportGuestStatus);
124 Log(("VBoxGuestReportDriverStatus: VbglGRAlloc VMMDevReportGuestStatus completed with rc=%Rrc\n", rc));
125 if (RT_SUCCESS(rc))
126 {
127 pReq2->guestStatus.facility = VBoxGuestFacilityType_VBoxGuestDriver;
128 pReq2->guestStatus.status = fActive ?
129 VBoxGuestFacilityStatus_Active
130 : VBoxGuestFacilityStatus_Inactive;
131 pReq2->guestStatus.flags = 0;
132 rc = VbglGRPerform(&pReq2->header);
133 Log(("VBoxGuestReportDriverStatus: VbglGRPerform VMMDevReportGuestStatus completed with fActive=%d, rc=%Rrc\n",
134 fActive ? 1 : 0, rc));
135 if (rc == VERR_NOT_IMPLEMENTED) /* Compatibility with older hosts. */
136 rc = VINF_SUCCESS;
137 VbglGRFree(&pReq2->header);
138 }
139
140 return rc;
141}
142
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette