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