1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox frontends: Basic Frontend (BFE):
|
---|
4 | * Implementation of NetworkAdapter class
|
---|
5 | *
|
---|
6 | * This is adapted from frontends/VirtualBox/NetworkAdapter.cpp.
|
---|
7 | */
|
---|
8 |
|
---|
9 | /*
|
---|
10 | * Copyright (C) 2006-2007 Oracle Corporation
|
---|
11 | *
|
---|
12 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
13 | * available from http://www.virtualbox.org. This file is free software;
|
---|
14 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
15 | * General Public License (GPL) as published by the Free Software
|
---|
16 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
17 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
18 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
19 | */
|
---|
20 |
|
---|
21 |
|
---|
22 |
|
---|
23 | #include <VBox/err.h>
|
---|
24 | #include <iprt/assert.h>
|
---|
25 |
|
---|
26 | #include <NetworkAdapterImpl.h>
|
---|
27 | #include <NATDriver.h>
|
---|
28 | #include <COMDefs.h>
|
---|
29 | #include <ConsoleImpl.h>
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Returns the host interface the adapter is attached to
|
---|
33 | *
|
---|
34 | * @returns COM status code
|
---|
35 | * @param hostInterface address of result string
|
---|
36 | */
|
---|
37 | STDMETHODIMP NetworkAdapter::COMGETTER(HostInterface)(BSTR *hostInterface)
|
---|
38 | {
|
---|
39 | if (!hostInterface)
|
---|
40 | return E_POINTER;
|
---|
41 | AutoLock alock(this);
|
---|
42 | // CHECK_READY();
|
---|
43 |
|
---|
44 | // mData->mHostInterface.cloneTo(hostInterface);
|
---|
45 | mData.mHostInterface.cloneTo(hostInterface);
|
---|
46 |
|
---|
47 | return S_OK;
|
---|
48 | }
|
---|
49 |
|
---|
50 | NetworkAdapter::NetworkAdapter()
|
---|
51 | {
|
---|
52 | RTCritSectInit(&mCritSec);
|
---|
53 | }
|
---|
54 |
|
---|
55 |
|
---|
56 | NetworkAdapter::~NetworkAdapter()
|
---|
57 | {
|
---|
58 | }
|
---|
59 |
|
---|
60 | int
|
---|
61 | NetworkAdapter::init (Console *parent, ULONG slot)
|
---|
62 | {
|
---|
63 | mParent = parent;
|
---|
64 | mData.mSlot = slot;
|
---|
65 | return S_OK;
|
---|
66 | }
|
---|
67 |
|
---|
68 |
|
---|
69 | STDMETHODIMP
|
---|
70 | NetworkAdapter::COMGETTER(Slot)(ULONG *slot)
|
---|
71 | {
|
---|
72 | if (!slot)
|
---|
73 | return E_POINTER;
|
---|
74 |
|
---|
75 | AutoLock alock (this);
|
---|
76 | // CHECK_READY();
|
---|
77 |
|
---|
78 | *slot = mData.mSlot;
|
---|
79 | return S_OK;
|
---|
80 | }
|
---|
81 |
|
---|
82 |
|
---|
83 | STDMETHODIMP
|
---|
84 | NetworkAdapter::COMGETTER(Enabled)(bool *enabled)
|
---|
85 | {
|
---|
86 | if (!enabled)
|
---|
87 | return E_POINTER;
|
---|
88 |
|
---|
89 | AutoLock alock (this);
|
---|
90 | // CHECK_READY();
|
---|
91 |
|
---|
92 | *enabled = mData.mEnabled;
|
---|
93 | return S_OK;
|
---|
94 | }
|
---|
95 |
|
---|
96 |
|
---|
97 | STDMETHODIMP
|
---|
98 | NetworkAdapter::COMSETTER(Enabled)(BOOL enabled)
|
---|
99 | {
|
---|
100 | AutoLock alock(this);
|
---|
101 | // CHECK_READY();
|
---|
102 |
|
---|
103 | // CHECK_MACHINE_MUTABILITY (mParent);
|
---|
104 |
|
---|
105 | if (mData.mEnabled != enabled)
|
---|
106 | {
|
---|
107 | // mData.backup();
|
---|
108 | mData.mEnabled = enabled;
|
---|
109 |
|
---|
110 | /* notify parent */
|
---|
111 | alock.unlock();
|
---|
112 | mParent->onNetworkAdapterChange (this);
|
---|
113 | }
|
---|
114 |
|
---|
115 | return S_OK;
|
---|
116 | }
|
---|
117 |
|
---|
118 | STDMETHODIMP
|
---|
119 | NetworkAdapter::COMGETTER(MACAddress)(BSTR *macAddress)
|
---|
120 | {
|
---|
121 | AssertMsg(0,("Not implemented yet\n"));
|
---|
122 | return 0;
|
---|
123 | }
|
---|
124 |
|
---|
125 | STDMETHODIMP
|
---|
126 | NetworkAdapter::COMSETTER(MACAddress)(INPTR BSTR macAddress)
|
---|
127 | {
|
---|
128 | AssertMsg(0,("Not implemented yet\n"));
|
---|
129 | return 0;
|
---|
130 | }
|
---|
131 |
|
---|
132 |
|
---|
133 | STDMETHODIMP
|
---|
134 | NetworkAdapter::COMSETTER(HostInterface)(INPTR BSTR hostInterface)
|
---|
135 | {
|
---|
136 | #ifdef RT_OS_LINUX
|
---|
137 | // empty strings are not allowed as path names
|
---|
138 | if (hostInterface && !(*hostInterface))
|
---|
139 | return E_INVALIDARG;
|
---|
140 | #endif
|
---|
141 |
|
---|
142 |
|
---|
143 | AutoLock alock(this);
|
---|
144 | // CHECK_READY();
|
---|
145 |
|
---|
146 | // CHECK_MACHINE_MUTABILITY (mParent);
|
---|
147 |
|
---|
148 | if (mData.mHostInterface != hostInterface)
|
---|
149 | {
|
---|
150 | // mData.backup();
|
---|
151 | mData.mHostInterface = hostInterface;
|
---|
152 |
|
---|
153 | /* notify parent */
|
---|
154 | alock.unlock();
|
---|
155 | mParent->onNetworkAdapterChange(this);
|
---|
156 | }
|
---|
157 |
|
---|
158 | return S_OK;
|
---|
159 | }
|
---|
160 |
|
---|
161 |
|
---|
162 |
|
---|
163 | STDMETHODIMP
|
---|
164 | NetworkAdapter::COMGETTER(TAPFileDescriptor)(LONG *tapFileDescriptor)
|
---|
165 | {
|
---|
166 | if (!tapFileDescriptor)
|
---|
167 | return E_POINTER;
|
---|
168 |
|
---|
169 | AutoLock alock(this);
|
---|
170 | // CHECK_READY();
|
---|
171 |
|
---|
172 | *tapFileDescriptor = mData.mTAPFD;
|
---|
173 |
|
---|
174 | return S_OK;
|
---|
175 |
|
---|
176 | }
|
---|
177 |
|
---|
178 | STDMETHODIMP
|
---|
179 | NetworkAdapter::COMSETTER(TAPFileDescriptor)(LONG tapFileDescriptor)
|
---|
180 | {
|
---|
181 | /*
|
---|
182 | * Validate input.
|
---|
183 | */
|
---|
184 | RTFILE tapFD = tapFileDescriptor;
|
---|
185 | if (tapFD != NIL_RTFILE && (LONG)tapFD != tapFileDescriptor)
|
---|
186 | {
|
---|
187 | AssertMsgFailed(("Invalid file descriptor: %ld.\n", tapFileDescriptor));
|
---|
188 |
|
---|
189 | return setError (E_INVALIDARG,
|
---|
190 | tr ("Invalid file descriptor: %ld"), tapFileDescriptor);
|
---|
191 | }
|
---|
192 |
|
---|
193 | AutoLock alock(this);
|
---|
194 | // CHECK_READY();
|
---|
195 |
|
---|
196 | // CHECK_MACHINE_MUTABILITY (mParent);
|
---|
197 |
|
---|
198 | if (mData.mTAPFD != (RTFILE) tapFileDescriptor)
|
---|
199 | {
|
---|
200 | // mData.backup();
|
---|
201 | mData.mTAPFD = tapFileDescriptor;
|
---|
202 |
|
---|
203 | /* notify parent */
|
---|
204 | alock.unlock();
|
---|
205 | mParent->onNetworkAdapterChange(this);
|
---|
206 | }
|
---|
207 |
|
---|
208 | return S_OK;
|
---|
209 |
|
---|
210 | }
|
---|
211 |
|
---|
212 | STDMETHODIMP
|
---|
213 | NetworkAdapter::COMGETTER(TAPSetupApplication)(BSTR *tapSetupApplication)
|
---|
214 | {
|
---|
215 | if (!tapSetupApplication)
|
---|
216 | return E_POINTER;
|
---|
217 | AutoLock alock(this);
|
---|
218 | // CHECK_READY();
|
---|
219 |
|
---|
220 | /* we don't have to be in TAP mode to support this call */
|
---|
221 | mData.mTAPSetupApplication.cloneTo(tapSetupApplication);
|
---|
222 |
|
---|
223 | return S_OK;
|
---|
224 |
|
---|
225 | }
|
---|
226 |
|
---|
227 | STDMETHODIMP
|
---|
228 | NetworkAdapter::COMSETTER(TAPSetupApplication)(INPTR BSTR tapSetupApplication)
|
---|
229 | {
|
---|
230 | AssertMsg(0,("Not implemented yet\n"));
|
---|
231 | return 0;
|
---|
232 | }
|
---|
233 |
|
---|
234 | STDMETHODIMP
|
---|
235 | NetworkAdapter::COMGETTER(TAPTerminateApplication)(BSTR *tapTerminateApplication)
|
---|
236 | {
|
---|
237 | AssertMsg(0,("Not implemented yet\n"));
|
---|
238 | return 0;
|
---|
239 | }
|
---|
240 |
|
---|
241 | STDMETHODIMP
|
---|
242 | NetworkAdapter::COMSETTER(TAPTerminateApplication)(INPTR BSTR tapTerminateApplication)
|
---|
243 | {
|
---|
244 | AssertMsg(0,("Not implemented yet\n"));
|
---|
245 | return 0;
|
---|
246 | }
|
---|
247 |
|
---|
248 | STDMETHODIMP
|
---|
249 | NetworkAdapter::COMGETTER(InternalNetwork)(BSTR *internalNetwork)
|
---|
250 | {
|
---|
251 | AssertMsg(0,("Not implemented yet\n"));
|
---|
252 | return 0;
|
---|
253 | }
|
---|
254 | STDMETHODIMP
|
---|
255 | NetworkAdapter::COMSETTER(InternalNetwork)(INPTR BSTR internalNetwork)
|
---|
256 | {
|
---|
257 | AssertMsg(0,("Not implemented yet\n"));
|
---|
258 | return 0;
|
---|
259 | }
|
---|
260 | STDMETHODIMP
|
---|
261 | NetworkAdapter::COMGETTER(CableConnected)(BOOL *connected)
|
---|
262 | {
|
---|
263 | if (!connected)
|
---|
264 | return E_POINTER;
|
---|
265 |
|
---|
266 | AutoLock alock(this);
|
---|
267 | // CHECK_READY();
|
---|
268 |
|
---|
269 | *connected = mData.mCableConnected;
|
---|
270 | return S_OK;
|
---|
271 |
|
---|
272 | }
|
---|
273 | STDMETHODIMP
|
---|
274 | NetworkAdapter::COMSETTER(CableConnected)(BOOL connected)
|
---|
275 | {
|
---|
276 | AssertMsg(0,("Not implemented yet\n"));
|
---|
277 | return 0;
|
---|
278 | }
|
---|
279 | STDMETHODIMP
|
---|
280 | NetworkAdapter::COMGETTER(TraceEnabled)(BOOL *enabled)
|
---|
281 | {
|
---|
282 | AssertMsg(0,("Not implemented yet\n"));
|
---|
283 | return 0;
|
---|
284 | }
|
---|
285 | STDMETHODIMP
|
---|
286 | NetworkAdapter::COMSETTER(TraceEnabled)(BOOL enabled)
|
---|
287 | {
|
---|
288 | AssertMsg(0,("Not implemented yet\n"));
|
---|
289 | return 0;
|
---|
290 | }
|
---|
291 |
|
---|
292 | // INetworkAdapter methods
|
---|
293 | STDMETHODIMP
|
---|
294 | NetworkAdapter::AttachToNAT()
|
---|
295 | {
|
---|
296 | AssertMsg(0,("Not implemented yet\n"));
|
---|
297 | return 0;
|
---|
298 | }
|
---|
299 | STDMETHODIMP
|
---|
300 | NetworkAdapter::AttachToBridgedInterface()
|
---|
301 | {
|
---|
302 | AssertMsg(0,("Not implemented yet\n"));
|
---|
303 | return 0;
|
---|
304 | }
|
---|
305 | STDMETHODIMP
|
---|
306 | NetworkAdapter::AttachToInternalNetwork()
|
---|
307 | {
|
---|
308 | AssertMsg(0,("Not implemented yet\n"));
|
---|
309 | return 0;
|
---|
310 | }
|
---|
311 | STDMETHODIMP
|
---|
312 | NetworkAdapter::Detach()
|
---|
313 | {
|
---|
314 | AssertMsg(0,("Not implemented yet\n"));
|
---|
315 | return 0;
|
---|
316 | }
|
---|
317 |
|
---|
318 | void
|
---|
319 | NetworkAdapter::detach()
|
---|
320 | {
|
---|
321 | AssertMsg(0,("Not implemented yet\n"));
|
---|
322 | }
|
---|
323 |
|
---|
324 | void
|
---|
325 | NetworkAdapter::generateMACAddress()
|
---|
326 | {
|
---|
327 | AssertMsg(0,("Not implemented yet\n"));
|
---|
328 | }
|
---|