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 | // setError VirtualBoxSupportErrorInfoImplBase which
|
---|
190 | // is a parent class of NetworAdapter in the COM flavored version
|
---|
191 | // return setError (E_INVALIDARG,
|
---|
192 | // tr ("Invalid file descriptor: %ld"), tapFileDescriptor);
|
---|
193 |
|
---|
194 | return S_OK;
|
---|
195 |
|
---|
196 | }
|
---|
197 |
|
---|
198 | AutoLock alock(this);
|
---|
199 | // CHECK_READY();
|
---|
200 |
|
---|
201 | // CHECK_MACHINE_MUTABILITY (mParent);
|
---|
202 |
|
---|
203 | if (mData.mTAPFD != (RTFILE) tapFileDescriptor)
|
---|
204 | {
|
---|
205 | // mData.backup();
|
---|
206 | mData.mTAPFD = tapFileDescriptor;
|
---|
207 |
|
---|
208 | /* notify parent */
|
---|
209 | alock.unlock();
|
---|
210 | mParent->onNetworkAdapterChange(this);
|
---|
211 | }
|
---|
212 |
|
---|
213 | return S_OK;
|
---|
214 |
|
---|
215 | }
|
---|
216 |
|
---|
217 | STDMETHODIMP
|
---|
218 | NetworkAdapter::COMGETTER(TAPSetupApplication)(BSTR *tapSetupApplication)
|
---|
219 | {
|
---|
220 | if (!tapSetupApplication)
|
---|
221 | return E_POINTER;
|
---|
222 | AutoLock alock(this);
|
---|
223 | // CHECK_READY();
|
---|
224 |
|
---|
225 | /* we don't have to be in TAP mode to support this call */
|
---|
226 | mData.mTAPSetupApplication.cloneTo(tapSetupApplication);
|
---|
227 |
|
---|
228 | return S_OK;
|
---|
229 |
|
---|
230 | }
|
---|
231 |
|
---|
232 | STDMETHODIMP
|
---|
233 | NetworkAdapter::COMSETTER(TAPSetupApplication)(INPTR BSTR tapSetupApplication)
|
---|
234 | {
|
---|
235 | AssertMsg(0,("Not implemented yet\n"));
|
---|
236 | return 0;
|
---|
237 | }
|
---|
238 |
|
---|
239 | STDMETHODIMP
|
---|
240 | NetworkAdapter::COMGETTER(TAPTerminateApplication)(BSTR *tapTerminateApplication)
|
---|
241 | {
|
---|
242 | AssertMsg(0,("Not implemented yet\n"));
|
---|
243 | return 0;
|
---|
244 | }
|
---|
245 |
|
---|
246 | STDMETHODIMP
|
---|
247 | NetworkAdapter::COMSETTER(TAPTerminateApplication)(INPTR BSTR tapTerminateApplication)
|
---|
248 | {
|
---|
249 | AssertMsg(0,("Not implemented yet\n"));
|
---|
250 | return 0;
|
---|
251 | }
|
---|
252 |
|
---|
253 | STDMETHODIMP
|
---|
254 | NetworkAdapter::COMGETTER(InternalNetwork)(BSTR *internalNetwork)
|
---|
255 | {
|
---|
256 | AssertMsg(0,("Not implemented yet\n"));
|
---|
257 | return 0;
|
---|
258 | }
|
---|
259 | STDMETHODIMP
|
---|
260 | NetworkAdapter::COMSETTER(InternalNetwork)(INPTR BSTR internalNetwork)
|
---|
261 | {
|
---|
262 | AssertMsg(0,("Not implemented yet\n"));
|
---|
263 | return 0;
|
---|
264 | }
|
---|
265 | STDMETHODIMP
|
---|
266 | NetworkAdapter::COMGETTER(CableConnected)(BOOL *connected)
|
---|
267 | {
|
---|
268 | if (!connected)
|
---|
269 | return E_POINTER;
|
---|
270 |
|
---|
271 | AutoLock alock(this);
|
---|
272 | // CHECK_READY();
|
---|
273 |
|
---|
274 | *connected = mData.mCableConnected;
|
---|
275 | return S_OK;
|
---|
276 |
|
---|
277 | }
|
---|
278 | STDMETHODIMP
|
---|
279 | NetworkAdapter::COMSETTER(CableConnected)(BOOL connected)
|
---|
280 | {
|
---|
281 | AssertMsg(0,("Not implemented yet\n"));
|
---|
282 | return 0;
|
---|
283 | }
|
---|
284 | STDMETHODIMP
|
---|
285 | NetworkAdapter::COMGETTER(TraceEnabled)(BOOL *enabled)
|
---|
286 | {
|
---|
287 | AssertMsg(0,("Not implemented yet\n"));
|
---|
288 | return 0;
|
---|
289 | }
|
---|
290 | STDMETHODIMP
|
---|
291 | NetworkAdapter::COMSETTER(TraceEnabled)(BOOL enabled)
|
---|
292 | {
|
---|
293 | AssertMsg(0,("Not implemented yet\n"));
|
---|
294 | return 0;
|
---|
295 | }
|
---|
296 |
|
---|
297 | // INetworkAdapter methods
|
---|
298 | STDMETHODIMP
|
---|
299 | NetworkAdapter::AttachToNAT()
|
---|
300 | {
|
---|
301 | AssertMsg(0,("Not implemented yet\n"));
|
---|
302 | return 0;
|
---|
303 | }
|
---|
304 | STDMETHODIMP
|
---|
305 | NetworkAdapter::AttachToBridgedInterface()
|
---|
306 | {
|
---|
307 | AssertMsg(0,("Not implemented yet\n"));
|
---|
308 | return 0;
|
---|
309 | }
|
---|
310 | STDMETHODIMP
|
---|
311 | NetworkAdapter::AttachToInternalNetwork()
|
---|
312 | {
|
---|
313 | AssertMsg(0,("Not implemented yet\n"));
|
---|
314 | return 0;
|
---|
315 | }
|
---|
316 | STDMETHODIMP
|
---|
317 | NetworkAdapter::Detach()
|
---|
318 | {
|
---|
319 | AssertMsg(0,("Not implemented yet\n"));
|
---|
320 | return 0;
|
---|
321 | }
|
---|
322 |
|
---|
323 | void
|
---|
324 | NetworkAdapter::detach()
|
---|
325 | {
|
---|
326 | AssertMsg(0,("Not implemented yet\n"));
|
---|
327 | }
|
---|
328 |
|
---|
329 | void
|
---|
330 | NetworkAdapter::generateMACAddress()
|
---|
331 | {
|
---|
332 | AssertMsg(0,("Not implemented yet\n"));
|
---|
333 | }
|
---|