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