|
1 /* |
|
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 /** @file wins/specific/ethernet.cpp |
|
22 * PDD for the Ethernet under the windows emulator |
|
23 */ |
|
24 |
|
25 #include <e32cmn.h> |
|
26 |
|
27 #include "wintap.h" |
|
28 |
|
29 #ifdef _WIN32_WINNT |
|
30 #undef _WIN32_WINNT |
|
31 #endif |
|
32 |
|
33 #include <ethernet.h> |
|
34 #include <nk_priv.h> |
|
35 #include <nk_plat.h> |
|
36 #include <property.h> |
|
37 |
|
38 #define OUTPUT_ERROR(_x) //OutputError(_x) |
|
39 /* |
|
40 void OutputError(const char * aErrString) |
|
41 { |
|
42 unsigned long error; |
|
43 TCHAR* Buffer[512]; |
|
44 |
|
45 error = GetLastError(); |
|
46 |
|
47 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,NULL,error,LANG_NEUTRAL,Buffer,256,NULL); |
|
48 |
|
49 __KTRACE_OPT(KHARDWARE, Kern::Printf("%S", aErrString)); |
|
50 __KTRACE_OPT(KHARDWARE, Kern::Printf(" -> ")); |
|
51 __KTRACE_OPT(KHARDWARE, Kern::Printf("%S", Buffer)); |
|
52 } |
|
53 */ |
|
54 |
|
55 /** @addtogroup enet Ethernet Drivers |
|
56 * Kernel Ethernet Support |
|
57 */ |
|
58 |
|
59 /** @addtogroup enet_pdd Driver PDD's |
|
60 * @ingroup enet |
|
61 */ |
|
62 |
|
63 /** @addtogroup enet_byplatform Ethernet support by platform |
|
64 * @ingroup enet |
|
65 */ |
|
66 |
|
67 /** @addtogroup enet_wins WINS (Emulator) Ethernet support |
|
68 * @ingroup enet_byplatform |
|
69 */ |
|
70 |
|
71 |
|
72 // strings potentially written to epoc.ini by netcards.exe |
|
73 #define KEpocIniEthSpeed10Mbps "10Mbps" |
|
74 #define KEpocIniEthSpeed100Mbps "100Mbps" |
|
75 |
|
76 // entries in epoc.ini file: |
|
77 #define KEpocIniEthSpeedEntry "ETHER_SPEED" |
|
78 #define KEpocIniEthNIFEntry "ETHER_NIF" |
|
79 #define KEpocIniEthMACEntry "ETHER_MAC" |
|
80 |
|
81 #define KEthDrvPanicCategory "D32ETHER" |
|
82 |
|
83 #define KLocalDriverNameMax 256 |
|
84 |
|
85 // Figure this out later |
|
86 _LIT(KPddName, "Ethernet.Wins"); |
|
87 |
|
88 // needs ldd version.. |
|
89 const TInt KMinimumLddMajorVersion=1; |
|
90 const TInt KMinimumLddMinorVersion=0; |
|
91 const TInt KMinimumLddBuild=122; |
|
92 |
|
93 /** @addtogroup enet_windows Windows Emulator Ethernet Pdd |
|
94 * @ingroup enet_pdd |
|
95 * @ingroup enet_wins |
|
96 * @{ |
|
97 */ |
|
98 |
|
99 /** |
|
100 * The Windows specific Ethernet physical device (factory) class |
|
101 * @internalTechnology belongs to PDD which sits internally in kernel |
|
102 */ |
|
103 class DDriverEthernet : public DPhysicalDevice |
|
104 { |
|
105 public: |
|
106 |
|
107 /** |
|
108 * The constructor |
|
109 * Sets the drivers version number. Limits possible |
|
110 * number of units to one only (unit 0) |
|
111 */ |
|
112 DDriverEthernet(); |
|
113 |
|
114 /** |
|
115 * Inherited from DPhysicalDevice. |
|
116 * Install the driver by setting it's name |
|
117 * @return KErrNone on success, other error code on failure |
|
118 */ |
|
119 virtual TInt Install(); |
|
120 |
|
121 /** |
|
122 * Inherited from DPhysicalDevice. |
|
123 * Get the Capabilites of the driver |
|
124 * NOT supported but required as implementation of |
|
125 * pure virtual in base class |
|
126 */ |
|
127 virtual void GetCaps(TDes8 &aDes) const; |
|
128 |
|
129 /** |
|
130 * Inherited from DPhysicalDevice. |
|
131 * Create a channel to a device |
|
132 * @param aChannel a reference to a newly created channel object |
|
133 * @param aUnit a unit for which the channel is being created |
|
134 * @param anInfo pointer to a descriptor with additional info (may be NULL) |
|
135 * @param aVer a requested version |
|
136 * @return KErrNone on success, other error code on failure |
|
137 */ |
|
138 virtual TInt Create(DBase*& aChannel, TInt aUnit, |
|
139 const TDesC8* anInfo, const TVersion &aVer); |
|
140 |
|
141 /** |
|
142 * Inherited from DPhysicalDevice. |
|
143 * Validate that the info supplied would create a valid channel |
|
144 * @param aUnit a unit for which validation is not used |
|
145 * @param anInfo pointer to a descriptor with additional info (may be NULL) |
|
146 * @param aVer a version to be validated |
|
147 * @return KErrNone if valid, KErrNotSupported otherwise |
|
148 */ |
|
149 virtual TInt Validate(TInt aUnit, const TDesC8* anInfo, const TVersion &aVer); |
|
150 }; |
|
151 |
|
152 |
|
153 /** |
|
154 * The WINS specific Ethernet channel class for the libpcap library |
|
155 * @internalTechnology belongs to PDD which sits internally in kernel |
|
156 */ |
|
157 class DEthernetWins : public DEthernet |
|
158 { |
|
159 friend void Isr(void const* aObject, TInt aErr, u_char* pkt_data, DWORD* aLength); |
|
160 |
|
161 public: |
|
162 |
|
163 enum TWinsEtherPanic |
|
164 { |
|
165 EBadMacAddress = 1, // means bad MAC address in ini file or entry for it missing or ini file missing |
|
166 ENoNetInterface, // means entry for network interface name missing in ini file or ini file missing |
|
167 EPcapNull // means Wpcap couldn't be initialised - potentially not installed or name of network interface in ini file wrong |
|
168 }; |
|
169 |
|
170 /** |
|
171 * The Constructor. |
|
172 */ |
|
173 DEthernetWins(); |
|
174 |
|
175 /** |
|
176 * The Destructor. |
|
177 */ |
|
178 ~DEthernetWins(); |
|
179 |
|
180 /** |
|
181 * The DoCreate Method. |
|
182 * Sets up the channel as part of the object creation |
|
183 * and retrieves the MAC address from epoc.ini file. |
|
184 * Also creates wpcap handler and thread for wpcap loop. |
|
185 * @pre epoc32\\data\\epoc.ini must exist with entries: "ETHER-NIF=..", "ETHER-MAC=..", "ETHER-SPEED=.." |
|
186 * @param aUnit a unit for which the channel is being created |
|
187 * @panic D32ETHER reason: (1) can't get proper MAC address (2) can't get |
|
188 * network interface name (3) can't initialise wpcap |
|
189 * @return KErrNone on success, other error code on failure |
|
190 */ |
|
191 TInt DoCreate(TInt aUnit); |
|
192 |
|
193 /** |
|
194 * DEthernet implementation. |
|
195 * Start the receiver. |
|
196 * Resumes pcap thread. Sets status to ready. |
|
197 * @return KErrNone on success or suitable error code on failure |
|
198 */ |
|
199 virtual TInt Start(); |
|
200 |
|
201 /** |
|
202 * DEthernet implementation. |
|
203 * Stop the receiver. |
|
204 * @param aMode possible values are: EStopNormal (=0), EStopEmergency (=1) |
|
205 * @post pcap thread suspended, status set to not ready |
|
206 */ |
|
207 virtual void Stop(TStopMode aMode); |
|
208 |
|
209 /** |
|
210 * DEthernet implementation. |
|
211 * Validates a new configuration - should be called before Configure() |
|
212 * @param aConfig is the configuration to be validated |
|
213 * @return KErrNone if aConfig valid, KErrNotSupported otherwise |
|
214 * @see Configure() |
|
215 */ |
|
216 virtual TInt ValidateConfig(const TEthernetConfigV01 &aConfig) const; |
|
217 |
|
218 /** |
|
219 * DEthernet implementation. |
|
220 * Configure the PDD and pcap library |
|
221 * Reconfigure the library using the new configuration supplied. |
|
222 * Sets pcap filter to read only frames with destination address set to |
|
223 * broadcast, multicast or MAC addresss from defaultConfig. |
|
224 * This will not change the MAC address. |
|
225 * @param aConfig The new configuration |
|
226 * @return KErrNone on success, suitable error code otherwise |
|
227 * @see ValidateConfig() |
|
228 * @see MacConfigure() |
|
229 */ |
|
230 virtual TInt Configure(TEthernetConfigV01 &aConfig); |
|
231 |
|
232 /** |
|
233 * DEthernet implementation. |
|
234 * Change the MAC address - writes new MAC address in defaultConfig. |
|
235 * If new settings are to have any effect then pcap filter |
|
236 * ought to be set again which is done by 'Configure()' |
|
237 * @param aConfig a configuration structure containing the new MAC |
|
238 * @see Configure() |
|
239 */ |
|
240 virtual void MacConfigure(TEthernetConfigV01 &aConfig); |
|
241 |
|
242 /** |
|
243 * DEthernet implementation. |
|
244 * Get the current config from defaultConfig member varaiable |
|
245 * which is assumed to be up to date. |
|
246 * Fills in the following fields: |
|
247 * The Transmit Speed |
|
248 * The Duplex Setting |
|
249 * The MAC address |
|
250 * @param aConfig is a TEthernetConfigV01 reference that will be filled in |
|
251 */ |
|
252 virtual void GetConfig(TEthernetConfigV01 &aConfig) const; |
|
253 |
|
254 /** |
|
255 * DEthernet implementation. |
|
256 * Dummy method, required as pure virtual in base class |
|
257 */ |
|
258 virtual void CheckConfig(TEthernetConfigV01 &aConfig); |
|
259 |
|
260 /** |
|
261 * DEthernet implementation. |
|
262 * Should query the capabilites. |
|
263 * NOT supported but required as pure virtual in base class |
|
264 */ |
|
265 virtual void Caps(TDes8 &aCaps) const; |
|
266 |
|
267 /** |
|
268 * DEthernet implementation. |
|
269 * Transmit data via wpcap |
|
270 * @param aBuffer reference to the data to be sent |
|
271 * @return KErrNone on success, other error code on failure |
|
272 */ |
|
273 virtual TInt Send(TBuf8<KMaxEthernetPacket+32> &aBuffer); |
|
274 |
|
275 /** |
|
276 * DEthernet implementation. |
|
277 * Retrieve data |
|
278 * Pull the received data out of the pcap library and into the supplied buffer. |
|
279 * Need to be told if the buffer is OK |
|
280 * @param aBuffer Reference to the buffer to be used to store the data in |
|
281 * @param okToUse Bool to indicate if the buffer is usable |
|
282 * @return KErrNone on success, other error code on failure |
|
283 */ |
|
284 virtual TInt ReceiveFrame(TBuf8<KMaxEthernetPacket+32> &aBuffer, TBool okToUse); |
|
285 |
|
286 /** |
|
287 * DEthernet implementation. |
|
288 * Disables all IRQ's |
|
289 * @return The IRQ level before it was changed |
|
290 * @see RestoreIrqs() |
|
291 */ |
|
292 virtual TInt DisableIrqs(); |
|
293 |
|
294 /** |
|
295 * DEthernet implementation. |
|
296 * Restore the IRQ's to the supplied level |
|
297 * @param aIrq The level to set the irqs to. |
|
298 * @see DisableIrqs() |
|
299 */ |
|
300 virtual void RestoreIrqs(TInt aIrq); |
|
301 |
|
302 /** |
|
303 * DEthernet implementation. |
|
304 * Return the DFC Queue that this device should use |
|
305 * @param aUnit a channel's unit number (ignored - only one unit possible) |
|
306 * @return a DFC Queue to use |
|
307 */ |
|
308 virtual TDfcQue* DfcQ(TInt aUnit); |
|
309 |
|
310 private: |
|
311 |
|
312 /** |
|
313 * Read network interface to be used from configuration file. Panic if |
|
314 * pre-conditions are not satisfied. |
|
315 * @pre epoc32\\data\\epoc.ini must exist with entry: "ETHER-NIF=existing_nif_name" |
|
316 * @post network interface name put in a member variable: iNetInterfaceName |
|
317 * @panic D32ETHER reason: (2) can't get network interface name |
|
318 */ |
|
319 void SetDriverName(); |
|
320 |
|
321 /** |
|
322 * Read MAC address from a configuration file and put it |
|
323 * into defaultConfig member variable checking before if the |
|
324 * one from the file is correct. Panic if pre-conditions are not satisfied |
|
325 * (although in case when MAC address is improper). |
|
326 * @pre epoc32\\data\\epoc.ini must exist with entry: "ETHER-MAC=proper_mac_address" |
|
327 * @panic D32ETHER reason: (3) can't initialise wpcap |
|
328 * @return KErrNone on success (panics on failure) |
|
329 */ |
|
330 TInt GetIfName(); |
|
331 |
|
332 private: |
|
333 |
|
334 HANDLE iWinTapHandle; |
|
335 |
|
336 PACKET iWritePacket; |
|
337 PACKET iReadPacket; |
|
338 /** |
|
339 * Id of the receiver - wpcap thread |
|
340 */ |
|
341 unsigned long iWorkerThreadId; |
|
342 |
|
343 /** |
|
344 * Contains the handle to wpcap thread. |
|
345 */ |
|
346 HANDLE iThreadHandle; |
|
347 |
|
348 /** |
|
349 * Stores the unit number (only one interface possible in |
|
350 * this implementation, so it will have value "0") |
|
351 */ |
|
352 TInt iUnit; |
|
353 |
|
354 /** |
|
355 * Is ETrue if the chip has been fully configured and is ready |
|
356 * for receiving frames. Is set to ETrue in Start(), to EFalse |
|
357 * in Stop(). Initialized in constructor as EFalse. |
|
358 */ |
|
359 TBool iReady; |
|
360 |
|
361 /** |
|
362 * Contains the default/current configuration of the driver. |
|
363 * Updated whenever configuration is to be changed. |
|
364 */ |
|
365 TEthernetConfigV01 defaultConfig; |
|
366 |
|
367 /** |
|
368 * Contains the network interface name to be used |
|
369 * @see SetDriverName() |
|
370 */ |
|
371 char iNetInterfaceName[KLocalDriverNameMax]; |
|
372 }; |
|
373 |
|
374 /** @} */ // End of wins ethernet pdd |
|
375 |
|
376 |
|
377 |
|
378 DDriverEthernet::DDriverEthernet() |
|
379 // Constructor |
|
380 { |
|
381 __KTRACE_OPT(KHARDWARE, Kern::Printf("DDriverEthernet::DDriverEthernet()")); |
|
382 iUnitsMask=0x1; // support unit 0 only |
|
383 iVersion=TVersion(KEthernetMajorVersionNumber, |
|
384 KEthernetMinorVersionNumber, |
|
385 KEthernetBuildVersionNumber); |
|
386 |
|
387 } |
|
388 |
|
389 |
|
390 TInt DDriverEthernet::Install() |
|
391 // Install the driver |
|
392 { |
|
393 __KTRACE_OPT(KHARDWARE, Kern::Printf("DDriverEthernet::Install()")); |
|
394 return SetName(&KPddName); |
|
395 } |
|
396 |
|
397 |
|
398 void GetWinsEthernetsCaps(TDes8 &aCaps, TInt aUnit=0) |
|
399 { |
|
400 __KTRACE_OPT(KHARDWARE, Kern::Printf("GetWinsEthernetsCaps(TDes8 &aCaps, TInt aUnit)")); |
|
401 TEthernetCaps capsBuf; |
|
402 |
|
403 aUnit=0; |
|
404 |
|
405 aCaps.FillZ(aCaps.MaxLength()); |
|
406 aCaps=capsBuf.Left(Min(capsBuf.Length(),aCaps.MaxLength())); |
|
407 } |
|
408 |
|
409 void PanicFromWinsEtherDrv(TInt aReason) |
|
410 { |
|
411 Kern::Fault(KEthDrvPanicCategory, aReason); |
|
412 } |
|
413 |
|
414 void DDriverEthernet::GetCaps(TDes8 &aDes) const |
|
415 // Return the driver's capabilities |
|
416 { |
|
417 __KTRACE_OPT(KHARDWARE, Kern::Printf("DDriverEthernet::GetCaps(TDes8 &aDes) const")); |
|
418 GetWinsEthernetsCaps(aDes); |
|
419 } |
|
420 |
|
421 |
|
422 TInt DDriverEthernet::Create(DBase*& aChannel, |
|
423 TInt aUnit, |
|
424 const TDesC8* aInfo, |
|
425 const TVersion& aVer) |
|
426 // Create a driver |
|
427 { |
|
428 __KTRACE_OPT(KHARDWARE, |
|
429 Kern::Printf("DDriverEthernet::Create(DBase*& aChannel, TInt aUnit, const TDesC8* nInfo, const TVersion& aVer)")); |
|
430 |
|
431 TInt ret; |
|
432 |
|
433 ret = Validate( aUnit, aInfo, aVer); |
|
434 if ( KErrNone != ret ) |
|
435 return ret; |
|
436 |
|
437 ret = KErrNoMemory; |
|
438 |
|
439 DEthernetWins* ptrPdd = new DEthernetWins; |
|
440 |
|
441 if ( ptrPdd ) |
|
442 { |
|
443 ret = ptrPdd->DoCreate(aUnit); |
|
444 if ( ret != KErrNone) |
|
445 { |
|
446 delete ptrPdd; |
|
447 } |
|
448 else |
|
449 aChannel = ptrPdd; |
|
450 } |
|
451 |
|
452 |
|
453 return ret; |
|
454 } |
|
455 |
|
456 |
|
457 TInt DDriverEthernet::Validate(TInt aUnit, |
|
458 const TDesC8* /*aInfo*/, |
|
459 const TVersion& aVer) |
|
460 // Validate the requested configuration |
|
461 { |
|
462 __KTRACE_OPT(KHARDWARE, Kern::Printf("DDriverEthernet::Validate(TInt aUnit, const TDesC8* /*aInfo*/, const TVersion& aVer)")); |
|
463 if ((!Kern::QueryVersionSupported(iVersion,aVer)) || |
|
464 (!Kern::QueryVersionSupported(aVer,TVersion(KMinimumLddMajorVersion, |
|
465 KMinimumLddMinorVersion, |
|
466 KMinimumLddBuild)))) |
|
467 { |
|
468 return KErrNotSupported; |
|
469 } |
|
470 |
|
471 if (aUnit != 0) |
|
472 { |
|
473 return KErrNotSupported; |
|
474 } |
|
475 |
|
476 return KErrNone; |
|
477 } |
|
478 |
|
479 |
|
480 DEthernetWins::DEthernetWins() |
|
481 // Constructor |
|
482 { |
|
483 __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::DEthernetWins()")); |
|
484 |
|
485 iReady = EFalse; |
|
486 |
|
487 // set default configuration - must be set before DoCreate gets called |
|
488 defaultConfig.iEthSpeed = KEthSpeedUnknown; |
|
489 defaultConfig.iEthDuplex = KEthDuplexUnknown; |
|
490 |
|
491 // MAC address initially set to NULL |
|
492 defaultConfig.iEthAddress[0] = 0; |
|
493 defaultConfig.iEthAddress[1] = 0; |
|
494 defaultConfig.iEthAddress[2] = 0; |
|
495 defaultConfig.iEthAddress[3] = 0; |
|
496 defaultConfig.iEthAddress[4] = 0; |
|
497 defaultConfig.iEthAddress[5] = 0; |
|
498 |
|
499 iNetInterfaceName[0] = '\0'; |
|
500 } |
|
501 |
|
502 TDfcQue* DEthernetWins::DfcQ(TInt /*aUnit*/) |
|
503 // Return the DFC queue to be used for this device |
|
504 { |
|
505 __KTRACE_OPT(KHARDWARE, |
|
506 Kern::Printf("DEthernetWins::DfcQ(TInt )")); |
|
507 return Kern::DfcQue0(); |
|
508 } |
|
509 |
|
510 |
|
511 TInt DEthernetWins::Start() |
|
512 // Start receiving frames |
|
513 { |
|
514 __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::Start()")); |
|
515 |
|
516 TInt32 ret; |
|
517 |
|
518 // Start thread |
|
519 // ResumeThread() - from MSDN help: |
|
520 // This function decrements a thread’s suspend count. |
|
521 // When the suspend count is decremented to zero, |
|
522 // the execution of the thread is resumed. |
|
523 // Return value: The thread’s previous suspend count indicates success. 0xFFFFFFFF indicates failure |
|
524 ret = ResumeThread( iThreadHandle ); |
|
525 if( (0xFFFFFFFF == ret) )//|| (ret > 1) ) |
|
526 return KErrGeneral; |
|
527 |
|
528 iReady = ETrue; |
|
529 |
|
530 return KErrNone; |
|
531 } |
|
532 |
|
533 |
|
534 void DEthernetWins::Stop(TStopMode aMode) |
|
535 // Stop receiving frames |
|
536 { |
|
537 __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::Stop(TStopMode aMode)")); |
|
538 |
|
539 |
|
540 switch (aMode) |
|
541 { |
|
542 case EStopNormal: |
|
543 case EStopEmergency: |
|
544 SuspendThread(iThreadHandle); |
|
545 iReady = EFalse; |
|
546 break; |
|
547 default: |
|
548 SuspendThread(iThreadHandle); |
|
549 iReady = EFalse; |
|
550 break; |
|
551 } |
|
552 |
|
553 } |
|
554 |
|
555 |
|
556 TInt DEthernetWins::ValidateConfig(const TEthernetConfigV01 &aConfig) const |
|
557 // Validate a config structure. |
|
558 { |
|
559 __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::ValidateConfig(const TEthernetConfigV01 &aConfig) const")); |
|
560 switch(aConfig.iEthSpeed) |
|
561 { |
|
562 case KEthSpeedUnknown: |
|
563 case KEthSpeedAuto: |
|
564 case KEthSpeed10BaseT: |
|
565 case KEthSpeed100BaseTX: |
|
566 break; |
|
567 default: |
|
568 return KErrNotSupported; |
|
569 } |
|
570 |
|
571 switch(aConfig.iEthDuplex) |
|
572 { |
|
573 case KEthDuplexUnknown: |
|
574 case KEthDuplexAuto: |
|
575 case KEthDuplexHalf: |
|
576 case KEthDuplexFull: |
|
577 break; |
|
578 default: |
|
579 return KErrNotSupported; |
|
580 } |
|
581 |
|
582 return KErrNone; |
|
583 } |
|
584 |
|
585 |
|
586 void DEthernetWins::CheckConfig(TEthernetConfigV01& /*aConfig*/) |
|
587 // dummy implementation of pure virtual function |
|
588 { |
|
589 __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::CheckConfig(TEthernetConfigV01& aConfig)")); |
|
590 } |
|
591 |
|
592 TInt DEthernetWins::DisableIrqs() |
|
593 // Disable normal interrupts |
|
594 { |
|
595 __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::DisableIrqs()")); |
|
596 return NKern::DisableInterrupts(1); |
|
597 } |
|
598 |
|
599 |
|
600 void DEthernetWins::RestoreIrqs(TInt aLevel) |
|
601 // Restore normal interrupts |
|
602 { |
|
603 __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::RestoreIrqs(TInt aLevel)")); |
|
604 NKern::RestoreInterrupts(aLevel); |
|
605 } |
|
606 |
|
607 |
|
608 void DEthernetWins::MacConfigure(TEthernetConfigV01 &aConfig) |
|
609 { |
|
610 __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::MacConfigure(TEthernetConfigV01 &aConfig)")); |
|
611 defaultConfig.iEthAddress[0] = aConfig.iEthAddress[0]; |
|
612 defaultConfig.iEthAddress[1] = aConfig.iEthAddress[1]; |
|
613 defaultConfig.iEthAddress[2] = aConfig.iEthAddress[2]; |
|
614 defaultConfig.iEthAddress[3] = aConfig.iEthAddress[3]; |
|
615 defaultConfig.iEthAddress[4] = aConfig.iEthAddress[4]; |
|
616 defaultConfig.iEthAddress[5] = aConfig.iEthAddress[5]; |
|
617 } |
|
618 |
|
619 |
|
620 TInt DEthernetWins::Configure(TEthernetConfigV01 & /*aConfig*/) |
|
621 // Set a wpcap filter |
|
622 { |
|
623 |
|
624 __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::Configure(TEthernetConfigV01 &aConfig)")); |
|
625 |
|
626 return KErrNone; |
|
627 } |
|
628 |
|
629 |
|
630 void DEthernetWins::GetConfig(TEthernetConfigV01 &aConfig) const |
|
631 // Get the current config from defaultConfig member |
|
632 { |
|
633 __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::GetConfig(TEthernetConfigV01 &aConfig) const")); |
|
634 aConfig = defaultConfig; |
|
635 } |
|
636 |
|
637 |
|
638 void DEthernetWins::Caps(TDes8 &aCaps) const |
|
639 // return PDD's capabilites |
|
640 { |
|
641 __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::Caps(TDes8 &aCaps) const")); |
|
642 GetWinsEthernetsCaps(aCaps,iUnit); |
|
643 } |
|
644 |
|
645 TInt DEthernetWins::ReceiveFrame(TBuf8<KMaxEthernetPacket+32> &aBuffer, TBool okToUse) |
|
646 { |
|
647 __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::ReceiveFrame(TBuf8<KMaxEthernetPacket+32> &aBuffer)")); |
|
648 |
|
649 // If no buffer available dump frame |
|
650 if(!okToUse) |
|
651 { |
|
652 return KErrGeneral; |
|
653 } |
|
654 |
|
655 aBuffer.Copy((u_char*)iReadPacket.Buffer, iReadPacket.Length); |
|
656 aBuffer.SetLength(iReadPacket.Length); |
|
657 |
|
658 return KErrNone; |
|
659 } |
|
660 |
|
661 /** |
|
662 * @addtogroup enet_windows |
|
663 * @{ |
|
664 */ |
|
665 |
|
666 /** |
|
667 * Real entry point from the Kernel: return a new driver |
|
668 * (Macro wrapping: EXPORT_C DPhysicalDevice *CreatePhysicalDevice() ) |
|
669 */ |
|
670 DECLARE_STANDARD_PDD() |
|
671 { |
|
672 return new DDriverEthernet; |
|
673 } |
|
674 |
|
675 /** @} */ // end of windows group |
|
676 |
|
677 /** |
|
678 * |
|
679 * The start of most EtherTap specific routines |
|
680 * |
|
681 **/ |
|
682 |
|
683 TInt DEthernetWins::DoCreate(TInt aUnit)//, const TDesC8* /*anInfo*/) |
|
684 // Sets up the PDD |
|
685 { |
|
686 __KTRACE_OPT(KHARDWARE, |
|
687 Kern::Printf("DEthernetWins::DoCreate(TInt aUnit, const TDesC8* /*anInfo*/)")); |
|
688 |
|
689 iUnit = aUnit; |
|
690 |
|
691 SetIsr(this, &Isr); |
|
692 |
|
693 IP_ADAPTER_INFO adapterinfo; |
|
694 |
|
695 TInt ret = InitDriver(iWinTapHandle, iThreadHandle, iWritePacket, adapterinfo); |
|
696 |
|
697 const char* speedProperty = Property::GetString(KEpocIniEthSpeedEntry); |
|
698 |
|
699 if( (NULL==speedProperty) ? 0 : (0 == strcmp( speedProperty, KEpocIniEthSpeed10Mbps )) ) |
|
700 { |
|
701 defaultConfig.iEthSpeed = KEthSpeed10BaseT; |
|
702 } |
|
703 else if ( (NULL==speedProperty) ? 0 : (0 == strcmp( speedProperty, KEpocIniEthSpeed100Mbps )) ) |
|
704 { |
|
705 defaultConfig.iEthSpeed = KEthSpeed100BaseTX; |
|
706 } |
|
707 |
|
708 defaultConfig.iEthAddress[0] = adapterinfo.Address[0]; |
|
709 defaultConfig.iEthAddress[1] = adapterinfo.Address[1]; |
|
710 defaultConfig.iEthAddress[2] = (TUint8)(adapterinfo.Address[2] + 2); |
|
711 defaultConfig.iEthAddress[3] = adapterinfo.Address[3]; |
|
712 defaultConfig.iEthAddress[4] = adapterinfo.Address[4]; |
|
713 defaultConfig.iEthAddress[5] = adapterinfo.Address[5]; |
|
714 |
|
715 __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::DoCreate %2x:%2x:%2x:%2x:%2x:%2x", |
|
716 defaultConfig.iEthAddress[0], |
|
717 defaultConfig.iEthAddress[1], |
|
718 defaultConfig.iEthAddress[2], |
|
719 defaultConfig.iEthAddress[3], |
|
720 defaultConfig.iEthAddress[4], |
|
721 defaultConfig.iEthAddress[5])); |
|
722 |
|
723 return ret; |
|
724 } |
|
725 |
|
726 DEthernetWins::~DEthernetWins() |
|
727 // Destructor |
|
728 { |
|
729 __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::~DEthernetWins()")); |
|
730 |
|
731 DoClose(iWinTapHandle, iThreadHandle, iWritePacket); |
|
732 } |
|
733 |
|
734 TInt DEthernetWins::Send(TBuf8<KMaxEthernetPacket+32> &aBuffer) |
|
735 { |
|
736 __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::Send(TBuf8<KMaxEthernetPacket+32> &aBuffer)")); |
|
737 iWritePacket.Length = aBuffer.Length(); |
|
738 iWritePacket.Buffer = (void *)aBuffer.Ptr(); |
|
739 |
|
740 return DoSend(iWritePacket, iWinTapHandle); |
|
741 } |
|
742 |
|
743 void Isr(void const* aObject, TInt aErr, u_char* pkt_data, DWORD* aLength) |
|
744 { |
|
745 __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::Isr() with error %d", aErr)); |
|
746 |
|
747 //dummy line to avoid warning |
|
748 if(aErr!=KErrNone){}; |
|
749 |
|
750 DEthernetWins* eth = (DEthernetWins*)aObject; |
|
751 StartOfInterrupt(); |
|
752 |
|
753 eth->iReadPacket.Length = *aLength; |
|
754 eth->iReadPacket.Buffer = pkt_data; |
|
755 |
|
756 eth->ReceiveIsr(); |
|
757 |
|
758 EndOfInterrupt(); |
|
759 |
|
760 return; |
|
761 } |