os/boardsupport/emulator/emulatorbsp/specific/ethernet.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// wins\specific\ethernet.cpp
sl@0
    15
// PDD for the Ethernet under the windows emulator
sl@0
    16
// 
sl@0
    17
//
sl@0
    18
sl@0
    19
/**
sl@0
    20
 @file wins/specific/ethernet.cpp
sl@0
    21
*/
sl@0
    22
sl@0
    23
sl@0
    24
#include <ethernet.h>
sl@0
    25
#include "nk_priv.h"
sl@0
    26
#include "nk_plat.h"
sl@0
    27
#include <property.h>
sl@0
    28
sl@0
    29
#include "pcap.h"
sl@0
    30
sl@0
    31
sl@0
    32
/** @addtogroup enet Ethernet Drivers
sl@0
    33
 *  Kernel Ethernet Support
sl@0
    34
 */
sl@0
    35
sl@0
    36
/** @addtogroup enet_pdd Driver PDD's
sl@0
    37
 * @ingroup enet
sl@0
    38
 */
sl@0
    39
sl@0
    40
/** @addtogroup enet_byplatform Ethernet support by platform
sl@0
    41
 * @ingroup enet
sl@0
    42
 */
sl@0
    43
sl@0
    44
/** @addtogroup enet_wins WINS (Emulator) Ethernet support
sl@0
    45
 * @ingroup enet_byplatform
sl@0
    46
 */
sl@0
    47
sl@0
    48
sl@0
    49
// strings potentially written to ethernet.ini by netcards.exe
sl@0
    50
#define	KEpocIniEthSpeed10Mbps	"10Mbps"
sl@0
    51
#define	KEpocIniEthSpeed100Mbps	"100Mbps"
sl@0
    52
sl@0
    53
// entries in epoc.ini file:
sl@0
    54
#define	KEpocIniEthSpeedEntry	"ETHER_SPEED"
sl@0
    55
#define	KEpocIniEthNIFEntry	"ETHER_NIF"
sl@0
    56
#define	KEpocIniEthMACEntry	"ETHER_MAC"
sl@0
    57
sl@0
    58
#define KEthDrvPanicCategory "D32ETHER"
sl@0
    59
sl@0
    60
#define KLocalDriverNameMax				256
sl@0
    61
sl@0
    62
#define PCAP_FILTER "ether dst %x:%x:%x:%x:%x:%x or ether multicast and ether src not %x:%x:%x:%x:%x:%x"
sl@0
    63
sl@0
    64
_LIT(KPddName, "Ethernet.Wins");
sl@0
    65
sl@0
    66
// needs ldd version..
sl@0
    67
const TInt KMinimumLddMajorVersion=1;
sl@0
    68
const TInt KMinimumLddMinorVersion=0;
sl@0
    69
const TInt KMinimumLddBuild=122;
sl@0
    70
sl@0
    71
/** @addtogroup enet_windows Windows Emulator Ethernet Pdd
sl@0
    72
 * @ingroup enet_pdd
sl@0
    73
 * @ingroup enet_wins
sl@0
    74
 * @{
sl@0
    75
 */
sl@0
    76
sl@0
    77
/**
sl@0
    78
 * The Windows specific Ethernet physical device (factory) class 
sl@0
    79
 * @internalTechnology belongs to PDD which sits internally in kernel 
sl@0
    80
 */
sl@0
    81
class DDriverEthernet : public DPhysicalDevice
sl@0
    82
    {
sl@0
    83
public:
sl@0
    84
sl@0
    85
    /**
sl@0
    86
     * The constructor
sl@0
    87
     * Sets the drivers version number. Limits possible
sl@0
    88
	 * number of units to one only (unit 0)
sl@0
    89
     */
sl@0
    90
    DDriverEthernet();
sl@0
    91
sl@0
    92
    /**
sl@0
    93
     * Inherited from DPhysicalDevice.
sl@0
    94
	 * Install the driver by setting it's name
sl@0
    95
	 * @return KErrNone on success, other error code on failure
sl@0
    96
     */
sl@0
    97
    virtual TInt Install();
sl@0
    98
sl@0
    99
    /**
sl@0
   100
     * Inherited from DPhysicalDevice.
sl@0
   101
	 * Get the Capabilites of the driver
sl@0
   102
     * NOT supported but required as implementation of
sl@0
   103
	 * pure virtual in base class
sl@0
   104
     */
sl@0
   105
    virtual void GetCaps(TDes8 &aDes) const;
sl@0
   106
sl@0
   107
    /**
sl@0
   108
     * Inherited from DPhysicalDevice.
sl@0
   109
	 * Create a channel to a device
sl@0
   110
	 * @param aChannel a reference to a newly created channel object
sl@0
   111
	 * @param aUnit a unit for which the channel is being created
sl@0
   112
	 * @param anInfo pointer to a descriptor with additional info (may be NULL)
sl@0
   113
	 * @param aVer a requested version
sl@0
   114
     * @return KErrNone on success, other error code on failure
sl@0
   115
     */
sl@0
   116
    virtual TInt Create(DBase*& aChannel, TInt aUnit, 
sl@0
   117
						const TDesC8* anInfo, const TVersion &aVer);
sl@0
   118
sl@0
   119
    /**
sl@0
   120
     * Inherited from DPhysicalDevice.
sl@0
   121
	 * Validate that the info supplied would create a valid channel
sl@0
   122
	 * @param aUnit a unit for which validation is to be done
sl@0
   123
	 * @param anInfo pointer to a descriptor with additional info (may be NULL)
sl@0
   124
	 * @param aVer a version to be validated
sl@0
   125
     * @return KErrNone if valid, KErrNotSupported otherwise
sl@0
   126
	 */
sl@0
   127
    virtual TInt Validate(TInt aUnit, const TDesC8* anInfo, const TVersion &aVer);
sl@0
   128
	};
sl@0
   129
sl@0
   130
sl@0
   131
/**
sl@0
   132
 * The WINS specific Ethernet channel class for the libpcap library
sl@0
   133
 * @internalTechnology belongs to PDD which sits internally in kernel 
sl@0
   134
 */
sl@0
   135
class DEthernetWins : public DEthernet
sl@0
   136
    {
sl@0
   137
sl@0
   138
	/**
sl@0
   139
     * The Worker Thread
sl@0
   140
     * @param aDEthernetWins Pointer to this object
sl@0
   141
     * @return Should never return
sl@0
   142
     */
sl@0
   143
    friend TInt WorkThread(DEthernetWins * aDEthernetWins);
sl@0
   144
sl@0
   145
public:
sl@0
   146
sl@0
   147
	enum TWinsEtherPanic
sl@0
   148
	{
sl@0
   149
	EBadMacAddress = 1, // means bad MAC address in ini file or entry for it missing or ini file missing
sl@0
   150
	ENoNetInterface, // means entry for network interface name missing in ini file or ini file missing
sl@0
   151
	EPcapNull	// means Wpcap couldn't be initialised - potentially not installed or name of network interface in ini file wrong
sl@0
   152
	};
sl@0
   153
sl@0
   154
    /**
sl@0
   155
     * The Constructor.
sl@0
   156
     */
sl@0
   157
    DEthernetWins();
sl@0
   158
sl@0
   159
    /**
sl@0
   160
     * The Destructor.
sl@0
   161
     */
sl@0
   162
    ~DEthernetWins();
sl@0
   163
sl@0
   164
	/**
sl@0
   165
     * The Isr plays a role of the pcap callback.
sl@0
   166
     * Do NOT call the function directly
sl@0
   167
     * @param thisObject a pointer to this object
sl@0
   168
     * @param header the received packet's pcap header
sl@0
   169
     * @param pkt_data the received packet
sl@0
   170
	 * @post new packet is copied to LDD's RX buffers' queue
sl@0
   171
	 */
sl@0
   172
    static void Isr(u_char *thisObject,   
sl@0
   173
                     const struct pcap_pkthdr *header, 
sl@0
   174
                     const u_char *pkt_data);
sl@0
   175
sl@0
   176
    /**
sl@0
   177
     * The DoCreate Method.
sl@0
   178
     * Sets up the channel as part of the object creation
sl@0
   179
     * and retrieves the MAC address from epoc.ini file.
sl@0
   180
	 * Also creates wpcap handler and thread for wpcap loop.
sl@0
   181
	 * @pre epoc32\\data\\epoc.ini must exist with entries: "ETHER-NIF=..", "ETHER-MAC=..", "ETHER-SPEED=.."
sl@0
   182
	 * @param aUnit a unit for which the channel is being created
sl@0
   183
	 * @panic D32ETHER reason: (1) can't get proper MAC address (2) can't get
sl@0
   184
	 * network interface name (3) can't initialise wpcap
sl@0
   185
	 * @return KErrNone on success, other error code on failure
sl@0
   186
	 */
sl@0
   187
    TInt DoCreate(TInt aUnit); 
sl@0
   188
sl@0
   189
    /**
sl@0
   190
     * DEthernet implementation.
sl@0
   191
	 * Start the receiver.
sl@0
   192
     * Resumes pcap thread. Sets status to ready.
sl@0
   193
	 * @return KErrNone on success or suitable error code on failure
sl@0
   194
     */
sl@0
   195
    virtual TInt Start();
sl@0
   196
sl@0
   197
    /**
sl@0
   198
     * DEthernet implementation.
sl@0
   199
	 * Stop the receiver.
sl@0
   200
     * @param aMode possible values are: EStopNormal (=0), EStopEmergency (=1)
sl@0
   201
	 * @post pcap thread suspended, status set to not ready
sl@0
   202
     */
sl@0
   203
    virtual void Stop(TStopMode aMode);
sl@0
   204
sl@0
   205
    /**
sl@0
   206
     * DEthernet implementation.
sl@0
   207
	 * Validates a new configuration - should be called before Configure()
sl@0
   208
     * @param aConfig is the configuration to be validated
sl@0
   209
     * @return KErrNone if aConfig valid, KErrNotSupported otherwise
sl@0
   210
     * @see Configure()
sl@0
   211
     */
sl@0
   212
    virtual TInt ValidateConfig(const TEthernetConfigV01 &aConfig) const;
sl@0
   213
sl@0
   214
    /**
sl@0
   215
     * DEthernet implementation.
sl@0
   216
	 * Configure the PDD and pcap library
sl@0
   217
     * Reconfigure the library using the new configuration supplied.
sl@0
   218
	 * Sets pcap filter to read only frames with destination address set to
sl@0
   219
	 * broadcast, multicast or MAC addresss from defaultConfig.
sl@0
   220
     * This will not change the MAC address.
sl@0
   221
     * @param aConfig The new configuration
sl@0
   222
	 * @return KErrNone on success, suitable error code otherwise
sl@0
   223
     * @see ValidateConfig()
sl@0
   224
     * @see MacConfigure()
sl@0
   225
     */
sl@0
   226
    virtual TInt Configure(TEthernetConfigV01 &aConfig);
sl@0
   227
sl@0
   228
    /**
sl@0
   229
     * DEthernet implementation.
sl@0
   230
	 * Change the MAC address - writes new MAC address in defaultConfig.
sl@0
   231
	 * If new settings are to have any effect then pcap filter
sl@0
   232
	 * ought to be set again which is done by 'Configure()'
sl@0
   233
	 * @param aConfig a configuration structure containing the new MAC
sl@0
   234
     * @see Configure()
sl@0
   235
     */
sl@0
   236
    virtual void MacConfigure(TEthernetConfigV01 &aConfig);
sl@0
   237
sl@0
   238
	/**
sl@0
   239
     * DEthernet implementation.
sl@0
   240
	 * Get the current config from defaultConfig member varaiable
sl@0
   241
	 * which is assumed to be up to date.
sl@0
   242
     * Fills in the following fields:
sl@0
   243
     * The Transmit Speed
sl@0
   244
     * The Duplex Setting
sl@0
   245
     * The MAC address
sl@0
   246
     * @param aConfig is a TEthernetConfigV01 reference that will be filled in
sl@0
   247
     */
sl@0
   248
    virtual void GetConfig(TEthernetConfigV01 &aConfig) const;
sl@0
   249
sl@0
   250
	/**
sl@0
   251
     * DEthernet implementation.
sl@0
   252
	 * Dummy method, required as pure virtual in base class
sl@0
   253
     */
sl@0
   254
    virtual void CheckConfig(TEthernetConfigV01 &aConfig);
sl@0
   255
sl@0
   256
	/**
sl@0
   257
     * DEthernet implementation.
sl@0
   258
	 * Should query the capabilites.
sl@0
   259
     * NOT supported but required as pure virtual in base class
sl@0
   260
     */
sl@0
   261
    virtual void Caps(TDes8 &aCaps) const;
sl@0
   262
sl@0
   263
    /**
sl@0
   264
     * DEthernet implementation.
sl@0
   265
	 * Transmit data via wpcap
sl@0
   266
     * @param aBuffer reference to the data to be sent
sl@0
   267
     * @return KErrNone on success, other error code on failure
sl@0
   268
     */
sl@0
   269
    virtual TInt Send(TBuf8<KMaxEthernetPacket+32> &aBuffer);
sl@0
   270
sl@0
   271
    /**
sl@0
   272
     * DEthernet implementation.
sl@0
   273
	 * Retrieve data
sl@0
   274
     * Pull the received data out of the pcap library and into the supplied buffer. 
sl@0
   275
     * Need to be told if the buffer is OK 
sl@0
   276
     * @param aBuffer Reference to the buffer to be used to store the data in
sl@0
   277
     * @param okToUse Bool to indicate if the buffer is usable
sl@0
   278
     * @return KErrNone on success, other error code on failure
sl@0
   279
     */
sl@0
   280
    virtual TInt ReceiveFrame(TBuf8<KMaxEthernetPacket+32> &aBuffer, TBool okToUse);
sl@0
   281
sl@0
   282
	/**
sl@0
   283
     * DEthernet implementation.
sl@0
   284
	 * Disables all IRQ's 
sl@0
   285
     * @return The IRQ level before it was changed
sl@0
   286
     * @see RestoreIrqs()
sl@0
   287
     */
sl@0
   288
    virtual TInt DisableIrqs();
sl@0
   289
sl@0
   290
    /**
sl@0
   291
     * DEthernet implementation.
sl@0
   292
	 * Restore the IRQ's to the supplied level
sl@0
   293
	 * @param aIrq The level to set the irqs to.
sl@0
   294
     * @see DisableIrqs()
sl@0
   295
     */
sl@0
   296
    virtual void RestoreIrqs(TInt aIrq);
sl@0
   297
sl@0
   298
	/**
sl@0
   299
     * DEthernet implementation.
sl@0
   300
	 * Return the DFC Queue that this device should use
sl@0
   301
     * @param aUnit a channel's unit number (ignored - only one unit possible)
sl@0
   302
     * @return a DFC Queue to use
sl@0
   303
     */
sl@0
   304
    virtual TDfcQue* DfcQ(TInt aUnit);
sl@0
   305
    
sl@0
   306
		
sl@0
   307
private:
sl@0
   308
 	static TBool DEthernetWins::IsTcp(TDesC8 &aFrame);
sl@0
   309
 	static TInt DEthernetWins::GetTcpAckNumber(TDesC8 &frame);
sl@0
   310
 	static TInt DEthernetWins::GetTcpSeqNumber(TDesC8 &frame);
sl@0
   311
	/**
sl@0
   312
     * Read network interface to be used from configuration file. Panic if
sl@0
   313
	 * pre-conditions are not satisfied.
sl@0
   314
	 * @pre epoc32\\data\\epoc.ini must exist with entry: "ETHER-NIF=existing_nif_name"
sl@0
   315
	 * @post network interface name put in a member variable: iNetInterfaceName
sl@0
   316
	 * @panic D32ETHER reason: (2) can't get network interface name 
sl@0
   317
     */
sl@0
   318
	void  SetDriverName();
sl@0
   319
sl@0
   320
	/**
sl@0
   321
	 * Read MAC address from a configuration file and put it
sl@0
   322
	 * into defaultConfig member variable checking before if the
sl@0
   323
	 * one from the file is correct. Panic if pre-conditions are not satisfied
sl@0
   324
	 * (although in case when MAC address is improper).
sl@0
   325
	 * @pre epoc32\\data\\epoc.ini must exist with entry: "ETHER-MAC=proper_mac_address"
sl@0
   326
	 * @panic D32ETHER reason:  EBadMacAddress
sl@0
   327
	 * @return KErrNone on success (panics on failure)
sl@0
   328
	 */
sl@0
   329
	TInt SetMacAddress();
sl@0
   330
sl@0
   331
    
sl@0
   332
private:
sl@0
   333
sl@0
   334
    /**
sl@0
   335
     * The handle to the pcap interface - wpcap specific
sl@0
   336
     */
sl@0
   337
    pcap_t * iPcapPtr;
sl@0
   338
sl@0
   339
    /**
sl@0
   340
     * Saved received packet information - wpcap specific:
sl@0
   341
	 * pointer to a structure that holds general information about the packet:
sl@0
   342
	 * the time in which it was sniffed, the length of this packet, 
sl@0
   343
	 * and the length of his specific portion (in case it is fragmented)
sl@0
   344
     */
sl@0
   345
    const struct pcap_pkthdr * iPcapHeader; 
sl@0
   346
sl@0
   347
    /**
sl@0
   348
     * Saved receive packet data - wpcap specific
sl@0
   349
     */
sl@0
   350
    const u_char * iPcapPktData;
sl@0
   351
sl@0
   352
    /**
sl@0
   353
     * Id of the receiver - wpcap thread
sl@0
   354
     */
sl@0
   355
    unsigned long iWorkerThreadId;
sl@0
   356
sl@0
   357
	/**
sl@0
   358
     * Contains the handle to wpcap thread. 
sl@0
   359
     */
sl@0
   360
	HANDLE				iThreadHandle;
sl@0
   361
sl@0
   362
    /**
sl@0
   363
     * Stores the unit number (only one interface possible in 
sl@0
   364
	 * this implementation, so it will have value "0")
sl@0
   365
     */
sl@0
   366
    TInt  iUnit;
sl@0
   367
	
sl@0
   368
    /**
sl@0
   369
     * Is ETrue if the chip has been fully configured and is ready
sl@0
   370
	 * for receiving frames. Is set to ETrue in Start(), to EFalse
sl@0
   371
	 * in Stop(). Initialized in constructor as EFalse.
sl@0
   372
     */
sl@0
   373
    TBool iReady;
sl@0
   374
sl@0
   375
    /**
sl@0
   376
     * Contains the default/current configuration of the driver.
sl@0
   377
	 * Updated whenever configuration is to be changed.
sl@0
   378
     */
sl@0
   379
    TEthernetConfigV01 defaultConfig;
sl@0
   380
sl@0
   381
	/**
sl@0
   382
     * Contains the network interface name to be used 
sl@0
   383
	 * @see SetDriverName()
sl@0
   384
     */
sl@0
   385
	char	iNetInterfaceName[KLocalDriverNameMax];
sl@0
   386
	
sl@0
   387
    };
sl@0
   388
sl@0
   389
/** @} */ // End of wins ethernet pdd
sl@0
   390
sl@0
   391
sl@0
   392
 
sl@0
   393
DDriverEthernet::DDriverEthernet()
sl@0
   394
// Constructor
sl@0
   395
    {
sl@0
   396
    __KTRACE_OPT(KHARDWARE, Kern::Printf("DDriverEthernet::DDriverEthernet()"));
sl@0
   397
    iUnitsMask=0x1;	// support unit 0 only
sl@0
   398
    iVersion=TVersion(KEthernetMajorVersionNumber,
sl@0
   399
                      KEthernetMinorVersionNumber,
sl@0
   400
                      KEthernetBuildVersionNumber);
sl@0
   401
	
sl@0
   402
	}
sl@0
   403
sl@0
   404
sl@0
   405
TInt DDriverEthernet::Install()
sl@0
   406
// Install the driver
sl@0
   407
    {
sl@0
   408
    __KTRACE_OPT(KHARDWARE, Kern::Printf("DDriverEthernet::Install()"));
sl@0
   409
    return SetName(&KPddName);
sl@0
   410
    }
sl@0
   411
sl@0
   412
sl@0
   413
void GetWinsEthernetsCaps(TDes8 &aCaps, TInt aUnit=0)
sl@0
   414
    {
sl@0
   415
    __KTRACE_OPT(KHARDWARE, Kern::Printf("GetWinsEthernetsCaps(TDes8 &aCaps, TInt aUnit)"));
sl@0
   416
    TEthernetCaps capsBuf;
sl@0
   417
	
sl@0
   418
	aUnit=0;
sl@0
   419
sl@0
   420
    aCaps.FillZ(aCaps.MaxLength());
sl@0
   421
    aCaps=capsBuf.Left(Min(capsBuf.Length(),aCaps.MaxLength()));
sl@0
   422
    }
sl@0
   423
sl@0
   424
void PanicFromWinsEtherDrv(TInt aReason)
sl@0
   425
	{
sl@0
   426
	Kern::Fault(KEthDrvPanicCategory, aReason);
sl@0
   427
	}
sl@0
   428
sl@0
   429
void DDriverEthernet::GetCaps(TDes8 &aDes) const
sl@0
   430
// Return the driver's capabilities
sl@0
   431
    {
sl@0
   432
    __KTRACE_OPT(KHARDWARE, Kern::Printf("DDriverEthernet::GetCaps(TDes8 &aDes) const"));
sl@0
   433
    GetWinsEthernetsCaps(aDes);	
sl@0
   434
    }
sl@0
   435
sl@0
   436
sl@0
   437
TInt DDriverEthernet::Create(DBase*& aChannel, 
sl@0
   438
                             TInt aUnit, 
sl@0
   439
                             const TDesC8* aInfo, 
sl@0
   440
                             const TVersion& aVer)
sl@0
   441
// Create a driver
sl@0
   442
    {
sl@0
   443
    __KTRACE_OPT(KHARDWARE, 
sl@0
   444
		Kern::Printf("DDriverEthernet::Create(DBase*& aChannel, TInt aUnit, const TDesC8* nInfo, const TVersion& aVer)"));
sl@0
   445
	
sl@0
   446
    TInt ret;
sl@0
   447
sl@0
   448
	ret = Validate( aUnit, aInfo, aVer);
sl@0
   449
	if ( KErrNone != ret )
sl@0
   450
		return ret;
sl@0
   451
sl@0
   452
	ret = KErrNoMemory;
sl@0
   453
sl@0
   454
	DEthernetWins* ptrPdd = new DEthernetWins;
sl@0
   455
sl@0
   456
	
sl@0
   457
	if ( ptrPdd )
sl@0
   458
        {
sl@0
   459
        ret = ptrPdd->DoCreate(aUnit);
sl@0
   460
        if ( ret != KErrNone)
sl@0
   461
			{
sl@0
   462
            delete ptrPdd;
sl@0
   463
			}	
sl@0
   464
		else
sl@0
   465
			aChannel = ptrPdd;
sl@0
   466
        }
sl@0
   467
sl@0
   468
	
sl@0
   469
    return ret;
sl@0
   470
    }
sl@0
   471
sl@0
   472
sl@0
   473
TInt DDriverEthernet::Validate(TInt aUnit, 
sl@0
   474
                               const TDesC8* /*aInfo*/, 
sl@0
   475
                               const TVersion& aVer)
sl@0
   476
//	Validate the requested configuration
sl@0
   477
    {
sl@0
   478
    __KTRACE_OPT(KHARDWARE, Kern::Printf("DDriverEthernet::Validate(TInt aUnit, const TDesC8* /*aInfo*/, const TVersion& aVer)"));
sl@0
   479
    if ((!Kern::QueryVersionSupported(iVersion,aVer)) || 
sl@0
   480
        (!Kern::QueryVersionSupported(aVer,TVersion(KMinimumLddMajorVersion,
sl@0
   481
                                                    KMinimumLddMinorVersion,
sl@0
   482
                                                    KMinimumLddBuild))))
sl@0
   483
		{
sl@0
   484
        return KErrNotSupported;
sl@0
   485
		}
sl@0
   486
    
sl@0
   487
	if (aUnit != 0)
sl@0
   488
		{
sl@0
   489
        return KErrNotSupported;
sl@0
   490
		}
sl@0
   491
sl@0
   492
	return KErrNone;
sl@0
   493
    }
sl@0
   494
sl@0
   495
sl@0
   496
DEthernetWins::DEthernetWins()
sl@0
   497
// Constructor
sl@0
   498
	{
sl@0
   499
    __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::DEthernetWins()"));
sl@0
   500
sl@0
   501
    iReady = EFalse;
sl@0
   502
    
sl@0
   503
	// set default configuration - must be set before DoCreate gets called
sl@0
   504
	defaultConfig.iEthSpeed  = KEthSpeedUnknown;
sl@0
   505
    defaultConfig.iEthDuplex = KEthDuplexUnknown;
sl@0
   506
							
sl@0
   507
	// MAC address initially set to NULL
sl@0
   508
	defaultConfig.iEthAddress[0] = 0; 
sl@0
   509
    defaultConfig.iEthAddress[1] = 0; 
sl@0
   510
    defaultConfig.iEthAddress[2] = 0; 
sl@0
   511
	defaultConfig.iEthAddress[3] = 0; 
sl@0
   512
    defaultConfig.iEthAddress[4] = 0; 
sl@0
   513
    defaultConfig.iEthAddress[5] = 0; 
sl@0
   514
	
sl@0
   515
	iNetInterfaceName[0] = '\0';
sl@0
   516
sl@0
   517
	// wpcap
sl@0
   518
	iPcapPtr = NULL;
sl@0
   519
sl@0
   520
	}
sl@0
   521
sl@0
   522
DEthernetWins::~DEthernetWins()
sl@0
   523
// Destructor
sl@0
   524
	{
sl@0
   525
    __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::~DEthernetWins()"));
sl@0
   526
sl@0
   527
	if (iPcapPtr)
sl@0
   528
		{
sl@0
   529
		pcap_close(iPcapPtr);
sl@0
   530
		iPcapPtr = NULL;
sl@0
   531
		}
sl@0
   532
  
sl@0
   533
	}
sl@0
   534
sl@0
   535
sl@0
   536
TInt DEthernetWins::DoCreate(TInt aUnit)//, const TDesC8* /*anInfo*/)
sl@0
   537
// Sets up the PDD
sl@0
   538
	{
sl@0
   539
	__KTRACE_OPT(KHARDWARE, 
sl@0
   540
		Kern::Printf("DEthernetWins::DoCreate(TInt aUnit, const TDesC8* /*anInfo*/)"));
sl@0
   541
   
sl@0
   542
	iUnit = aUnit;
sl@0
   543
sl@0
   544
	TInt ret = KErrNone;
sl@0
   545
sl@0
   546
	SetMacAddress(); // will panic if can't get proper MAC address
sl@0
   547
sl@0
   548
	const char* speedProperty = Property::GetString(KEpocIniEthSpeedEntry);
sl@0
   549
sl@0
   550
	if( (NULL==speedProperty) ? 0 : (0 == strcmp( speedProperty, KEpocIniEthSpeed10Mbps )) )
sl@0
   551
		{
sl@0
   552
		defaultConfig.iEthSpeed = KEthSpeed10BaseT;
sl@0
   553
		}
sl@0
   554
	else if ( (NULL==speedProperty) ? 0 : (0 == strcmp( speedProperty, KEpocIniEthSpeed100Mbps )) )
sl@0
   555
		{
sl@0
   556
		defaultConfig.iEthSpeed = KEthSpeed100BaseTX;
sl@0
   557
		}
sl@0
   558
sl@0
   559
	SetDriverName();
sl@0
   560
sl@0
   561
	char errPcap[PCAP_ERRBUF_SIZE];
sl@0
   562
sl@0
   563
	if( iPcapPtr == NULL )
sl@0
   564
		{
sl@0
   565
		
sl@0
   566
		if((iPcapPtr = pcap_open_live( iNetInterfaceName,
sl@0
   567
									   2000, 
sl@0
   568
                                      1, 
sl@0
   569
                                      20, 
sl@0
   570
                                      errPcap)) != NULL)
sl@0
   571
			{
sl@0
   572
	 	    
sl@0
   573
			if ((iThreadHandle = CreateThread(NULL,
sl@0
   574
                                           0,
sl@0
   575
                                           (LPTHREAD_START_ROUTINE)WorkThread,
sl@0
   576
                                           this,
sl@0
   577
                                           CREATE_SUSPENDED,
sl@0
   578
                                           &iWorkerThreadId)) != NULL)
sl@0
   579
				{
sl@0
   580
    			ret = Configure(defaultConfig);
sl@0
   581
				}
sl@0
   582
			else
sl@0
   583
				{
sl@0
   584
				__KTRACE_OPT(KHARDWARE, Kern::Printf("CreateThread() failed to create worker thread"));
sl@0
   585
				ret = KErrBadHandle; 
sl@0
   586
				}
sl@0
   587
			}
sl@0
   588
		else
sl@0
   589
			{
sl@0
   590
		    __KTRACE_OPT(KHARDWARE, Kern::Printf("pcap_open_live() failed to open"));
sl@0
   591
			//ret = KErrCouldNotConnect;
sl@0
   592
			PanicFromWinsEtherDrv( EPcapNull );
sl@0
   593
			}
sl@0
   594
    
sl@0
   595
		}
sl@0
   596
	
sl@0
   597
    if(ret != KErrNone)
sl@0
   598
		{
sl@0
   599
		// Failed to init all so tidy up
sl@0
   600
		if( iPcapPtr )
sl@0
   601
			{
sl@0
   602
			pcap_close(iPcapPtr);
sl@0
   603
			iPcapPtr = NULL;
sl@0
   604
			}
sl@0
   605
		__KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::DoCreate() returned with ERROR"));
sl@0
   606
		return ret;
sl@0
   607
		}
sl@0
   608
sl@0
   609
sl@0
   610
    __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::DoCreate %2x:%2x:%2x:%2x:%2x:%2x",
sl@0
   611
                                         defaultConfig.iEthAddress[0], 
sl@0
   612
                                         defaultConfig.iEthAddress[1],
sl@0
   613
                                         defaultConfig.iEthAddress[2], 
sl@0
   614
                                         defaultConfig.iEthAddress[3],
sl@0
   615
                                         defaultConfig.iEthAddress[4], 
sl@0
   616
                                         defaultConfig.iEthAddress[5]));
sl@0
   617
sl@0
   618
	return ret;
sl@0
   619
	}
sl@0
   620
sl@0
   621
sl@0
   622
void  DEthernetWins::SetDriverName()
sl@0
   623
	{
sl@0
   624
	__KTRACE_OPT(KHARDWARE, 
sl@0
   625
		Kern::Printf("DEthernetWins::SetDriverName()"));
sl@0
   626
sl@0
   627
	const char* property = Property::GetString(KEpocIniEthNIFEntry);
sl@0
   628
sl@0
   629
	__ASSERT_ALWAYS( (NULL != property),
sl@0
   630
		PanicFromWinsEtherDrv(ENoNetInterface) );
sl@0
   631
sl@0
   632
	memcpy( iNetInterfaceName, property, strlen(property) );
sl@0
   633
	}
sl@0
   634
sl@0
   635
sl@0
   636
TInt DEthernetWins::SetMacAddress()
sl@0
   637
// reads MAC address from epoc.ini file and writes into defaultConfig
sl@0
   638
	{
sl@0
   639
	
sl@0
   640
	__KTRACE_OPT(KHARDWARE, 
sl@0
   641
		Kern::Printf("DEthernetWins::SetMacAddress()"));
sl@0
   642
sl@0
   643
	TUint8 tempAddress[6];
sl@0
   644
sl@0
   645
	const char *tempBuffer = Property::GetString(KEpocIniEthMACEntry);
sl@0
   646
sl@0
   647
	__ASSERT_ALWAYS( ((tempBuffer != NULL) && (strlen(tempBuffer) >= 6)),
sl@0
   648
		PanicFromWinsEtherDrv(EBadMacAddress) );
sl@0
   649
sl@0
   650
sl@0
   651
	TBuf<20> validCharsLower(_L("0123456789abcdef"));
sl@0
   652
	TBuf<20> validCharsUpper(_L("0123456789ABCDEF"));
sl@0
   653
	TUint8 value;
sl@0
   654
	TUint8 upper=0;
sl@0
   655
	TChar c;
sl@0
   656
	TInt pos; 
sl@0
   657
	TInt i;
sl@0
   658
	for( i=0; i<6; i++)
sl@0
   659
		{
sl@0
   660
		c = tempBuffer[2*i];
sl@0
   661
		if(((pos = validCharsLower.Locate(c)) == KErrNotFound) &&
sl@0
   662
			((pos = validCharsUpper.Locate(c)) == KErrNotFound))
sl@0
   663
			{
sl@0
   664
			PanicFromWinsEtherDrv( EBadMacAddress );
sl@0
   665
			}
sl@0
   666
		upper = (TUint8)pos;
sl@0
   667
		c = tempBuffer[(2*i)+1];
sl@0
   668
		if( ((pos = validCharsLower.Locate(c)) == KErrNotFound) &&
sl@0
   669
			((pos = validCharsUpper.Locate(c)) == KErrNotFound) )
sl@0
   670
			{
sl@0
   671
			PanicFromWinsEtherDrv( EBadMacAddress );
sl@0
   672
			}
sl@0
   673
sl@0
   674
		value = (TUint8)pos;
sl@0
   675
		value = (TUint8)((upper<<4) | value);
sl@0
   676
		tempAddress[i] = value;
sl@0
   677
		}
sl@0
   678
sl@0
   679
	for( i=0; i<6; i++ )
sl@0
   680
		{
sl@0
   681
		defaultConfig.iEthAddress[i] = tempAddress[i];
sl@0
   682
		}
sl@0
   683
sl@0
   684
	return KErrNone;
sl@0
   685
sl@0
   686
	}
sl@0
   687
sl@0
   688
sl@0
   689
TDfcQue* DEthernetWins::DfcQ(TInt /*aUnit*/)
sl@0
   690
// Return the DFC queue to be used for this device
sl@0
   691
	{
sl@0
   692
    __KTRACE_OPT(KHARDWARE, 
sl@0
   693
		Kern::Printf("DEthernetWins::DfcQ(TInt )"));
sl@0
   694
    return Kern::DfcQue0();
sl@0
   695
	}
sl@0
   696
sl@0
   697
sl@0
   698
TInt DEthernetWins::Start()
sl@0
   699
// Start receiving frames
sl@0
   700
	{
sl@0
   701
    __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::Start()"));
sl@0
   702
sl@0
   703
	TInt32 ret;
sl@0
   704
	
sl@0
   705
	// Start thread
sl@0
   706
	// ResumeThread() - from MSDN help:
sl@0
   707
	// This function decrements a threadís suspend count. 
sl@0
   708
	// When the suspend count is decremented to zero, 
sl@0
   709
	// the execution of the thread is resumed. 
sl@0
   710
	// Return value: The threadís previous suspend count indicates success. 0xFFFFFFFF indicates failure
sl@0
   711
	ret = ResumeThread( iThreadHandle );
sl@0
   712
	if( (0xFFFFFFFF == ret) )//|| (ret > 1) )
sl@0
   713
		return KErrGeneral;
sl@0
   714
	
sl@0
   715
    iReady = ETrue;
sl@0
   716
sl@0
   717
    return KErrNone;
sl@0
   718
	}
sl@0
   719
sl@0
   720
sl@0
   721
void DEthernetWins::Stop(TStopMode aMode)
sl@0
   722
// Stop receiving frames
sl@0
   723
	{
sl@0
   724
    __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::Stop(TStopMode aMode)"));
sl@0
   725
sl@0
   726
	
sl@0
   727
    switch (aMode)
sl@0
   728
		{
sl@0
   729
        case EStopNormal:
sl@0
   730
        case EStopEmergency:
sl@0
   731
			SuspendThread(iThreadHandle);
sl@0
   732
			iReady = EFalse;
sl@0
   733
			break;
sl@0
   734
		default:
sl@0
   735
			SuspendThread(iThreadHandle);
sl@0
   736
			iReady = EFalse;
sl@0
   737
			break;
sl@0
   738
		}
sl@0
   739
sl@0
   740
	}
sl@0
   741
sl@0
   742
sl@0
   743
TInt DEthernetWins::ValidateConfig(const TEthernetConfigV01 &aConfig) const
sl@0
   744
// Validate a config structure.
sl@0
   745
	{
sl@0
   746
    __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::ValidateConfig(const TEthernetConfigV01 &aConfig) const"));
sl@0
   747
    switch(aConfig.iEthSpeed)
sl@0
   748
        {
sl@0
   749
        case KEthSpeedUnknown:
sl@0
   750
		case KEthSpeedAuto: 
sl@0
   751
        case KEthSpeed10BaseT:
sl@0
   752
        case KEthSpeed100BaseTX:
sl@0
   753
			break;
sl@0
   754
        default:		
sl@0
   755
        	return KErrNotSupported;
sl@0
   756
        }
sl@0
   757
sl@0
   758
    switch(aConfig.iEthDuplex)
sl@0
   759
        {
sl@0
   760
        case KEthDuplexUnknown:
sl@0
   761
		case KEthDuplexAuto:
sl@0
   762
        case KEthDuplexHalf:
sl@0
   763
        case KEthDuplexFull:
sl@0
   764
			break;
sl@0
   765
        default:
sl@0
   766
        	return KErrNotSupported;
sl@0
   767
        }
sl@0
   768
sl@0
   769
    return KErrNone;
sl@0
   770
	}
sl@0
   771
sl@0
   772
sl@0
   773
void DEthernetWins::CheckConfig(TEthernetConfigV01& /*aConfig*/)
sl@0
   774
// dummy implementation of pure virtual function
sl@0
   775
	{
sl@0
   776
    __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::CheckConfig(TEthernetConfigV01& aConfig)"));
sl@0
   777
	}
sl@0
   778
sl@0
   779
TInt DEthernetWins::Send(TBuf8<KMaxEthernetPacket+32> &aBuffer)
sl@0
   780
	{
sl@0
   781
    __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::Send(TBuf8<KMaxEthernetPacket+32> &aBuffer)"));
sl@0
   782
    TUint16 * dataP = (TUint16 *)aBuffer.Ptr();
sl@0
   783
    TUint16 length = TUint16(aBuffer.Length());
sl@0
   784
sl@0
   785
	TInt ret;
sl@0
   786
sl@0
   787
    if (iPcapPtr)
sl@0
   788
	    {
sl@0
   789
		__KTRACE_OPT2(KHARDWARE, KSCRATCH, Kern::Printf("  >pdd tx: sending tcp seq=%u ack=%u", GetTcpSeqNumber(aBuffer), GetTcpAckNumber(aBuffer) ));
sl@0
   790
        if(pcap_sendpacket(iPcapPtr, (unsigned char *)dataP, length))
sl@0
   791
		    {
sl@0
   792
            __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::Send - pcap_sendpacket() failed "));
sl@0
   793
sl@0
   794
		    ret = KErrWrite; 
sl@0
   795
	        }
sl@0
   796
        else
sl@0
   797
		    {
sl@0
   798
            __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::Send: \n*** completed pcap_sendpacket() ***\n"));
sl@0
   799
            ret = KErrNone;
sl@0
   800
            }
sl@0
   801
		}
sl@0
   802
    else
sl@0
   803
		{
sl@0
   804
        __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::Send() pcap adapter NOT open\n"));
sl@0
   805
        ret = KErrNotReady; 
sl@0
   806
		}
sl@0
   807
    
sl@0
   808
    return ret;
sl@0
   809
	}
sl@0
   810
sl@0
   811
sl@0
   812
TInt DEthernetWins::DisableIrqs()
sl@0
   813
// Disable normal interrupts
sl@0
   814
	{
sl@0
   815
    __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::DisableIrqs()"));
sl@0
   816
    return NKern::DisableInterrupts(1);
sl@0
   817
	}
sl@0
   818
sl@0
   819
sl@0
   820
void DEthernetWins::RestoreIrqs(TInt aLevel)
sl@0
   821
// Restore normal interrupts
sl@0
   822
	{
sl@0
   823
    __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::RestoreIrqs(TInt aLevel)"));
sl@0
   824
    NKern::RestoreInterrupts(aLevel);
sl@0
   825
	}
sl@0
   826
sl@0
   827
sl@0
   828
void DEthernetWins::MacConfigure(TEthernetConfigV01 &aConfig)
sl@0
   829
	{
sl@0
   830
    __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::MacConfigure(TEthernetConfigV01 &aConfig)"));
sl@0
   831
    defaultConfig.iEthAddress[0] = aConfig.iEthAddress[0]; 
sl@0
   832
	defaultConfig.iEthAddress[1] = aConfig.iEthAddress[1];
sl@0
   833
	defaultConfig.iEthAddress[2] = aConfig.iEthAddress[2];
sl@0
   834
	defaultConfig.iEthAddress[3] = aConfig.iEthAddress[3];
sl@0
   835
	defaultConfig.iEthAddress[4] = aConfig.iEthAddress[4];
sl@0
   836
	defaultConfig.iEthAddress[5] = aConfig.iEthAddress[5];
sl@0
   837
	}
sl@0
   838
sl@0
   839
sl@0
   840
TInt DEthernetWins::Configure(TEthernetConfigV01 & /*aConfig*/)
sl@0
   841
// Set a wpcap filter
sl@0
   842
	{
sl@0
   843
sl@0
   844
	__KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::Configure(TEthernetConfigV01 &aConfig)"));
sl@0
   845
	
sl@0
   846
    char errPcap[PCAP_ERRBUF_SIZE];
sl@0
   847
	TInt ret = KErrNone;
sl@0
   848
    char filter[128];
sl@0
   849
    struct bpf_program fcode;
sl@0
   850
    bpf_u_int32 SubNet,NetMask;
sl@0
   851
sl@0
   852
	//obtain the subnet
sl@0
   853
    pcap_lookupnet(	iNetInterfaceName, &SubNet, &NetMask, errPcap);
sl@0
   854
sl@0
   855
    sprintf(filter, 
sl@0
   856
            PCAP_FILTER, //pcap_filter, 
sl@0
   857
            defaultConfig.iEthAddress[0],
sl@0
   858
            defaultConfig.iEthAddress[1],
sl@0
   859
            defaultConfig.iEthAddress[2],
sl@0
   860
            defaultConfig.iEthAddress[3],
sl@0
   861
            defaultConfig.iEthAddress[4],
sl@0
   862
            defaultConfig.iEthAddress[5],
sl@0
   863
            defaultConfig.iEthAddress[0],
sl@0
   864
            defaultConfig.iEthAddress[1],
sl@0
   865
            defaultConfig.iEthAddress[2],
sl@0
   866
            defaultConfig.iEthAddress[3],
sl@0
   867
            defaultConfig.iEthAddress[4],
sl@0
   868
            defaultConfig.iEthAddress[5]);
sl@0
   869
sl@0
   870
sl@0
   871
	//compile the filter
sl@0
   872
    if( 0 != pcap_compile(iPcapPtr, &fcode, filter, 1, NetMask) )
sl@0
   873
		{
sl@0
   874
		// failed to compile:
sl@0
   875
		__KTRACE_OPT(KHARDWARE, Kern::Printf("pcap_compile() failed"));
sl@0
   876
		ret = KErrUnknown; 
sl@0
   877
		}
sl@0
   878
	else
sl@0
   879
		{
sl@0
   880
		// compiled successfully: set the filter
sl@0
   881
		if( 0 != pcap_setfilter(iPcapPtr, &fcode))
sl@0
   882
			{
sl@0
   883
			__KTRACE_OPT(KHARDWARE, Kern::Printf("pcap_setfilter() failed"));
sl@0
   884
			ret = KErrUnknown; 
sl@0
   885
			}
sl@0
   886
		}
sl@0
   887
sl@0
   888
    return ret; 
sl@0
   889
	}
sl@0
   890
sl@0
   891
sl@0
   892
void DEthernetWins::GetConfig(TEthernetConfigV01 &aConfig) const
sl@0
   893
// Get the current config from defaultConfig member
sl@0
   894
	{
sl@0
   895
    __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::GetConfig(TEthernetConfigV01 &aConfig) const"));
sl@0
   896
    aConfig = defaultConfig;
sl@0
   897
	}
sl@0
   898
sl@0
   899
sl@0
   900
void DEthernetWins::Caps(TDes8 &aCaps) const
sl@0
   901
// return PDD's capabilites
sl@0
   902
    {
sl@0
   903
    __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::Caps(TDes8 &aCaps) const"));
sl@0
   904
    GetWinsEthernetsCaps(aCaps,iUnit); 
sl@0
   905
    }
sl@0
   906
sl@0
   907
sl@0
   908
void DEthernetWins::Isr( u_char *thisObject,  
sl@0
   909
                       	const struct pcap_pkthdr *header, 
sl@0
   910
                        const u_char *pkt_data)
sl@0
   911
// pcap callback fuction
sl@0
   912
	{
sl@0
   913
    __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::Isr()"));
sl@0
   914
sl@0
   915
	DEthernetWins& thisPdd = *(DEthernetWins*) thisObject;
sl@0
   916
    	
sl@0
   917
	StartOfInterrupt();
sl@0
   918
sl@0
   919
	thisPdd.iPcapHeader = header;
sl@0
   920
	thisPdd.iPcapPktData = pkt_data;
sl@0
   921
sl@0
   922
    thisPdd.ReceiveIsr();
sl@0
   923
	
sl@0
   924
	EndOfInterrupt();
sl@0
   925
sl@0
   926
    return;
sl@0
   927
	}
sl@0
   928
sl@0
   929
sl@0
   930
TInt DEthernetWins::ReceiveFrame(TBuf8<KMaxEthernetPacket+32> &aBuffer, TBool okToUse)
sl@0
   931
	{
sl@0
   932
    __KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetWins::ReceiveFrame(TBuf8<KMaxEthernetPacket+32> &aBuffer)"));
sl@0
   933
sl@0
   934
	// If no buffer available dump frame
sl@0
   935
    if(!okToUse)
sl@0
   936
		{
sl@0
   937
        return KErrGeneral;
sl@0
   938
		}
sl@0
   939
sl@0
   940
    aBuffer.Copy(iPcapPktData, iPcapHeader->len);
sl@0
   941
    aBuffer.SetLength(iPcapHeader->len);
sl@0
   942
	__KTRACE_OPT2(KHARDWARE, KSCRATCH, Kern::Printf("  >pdd rx: tcp seq=%u ack=%u", GetTcpSeqNumber(aBuffer), GetTcpAckNumber(aBuffer) ));
sl@0
   943
    
sl@0
   944
	return KErrNone;
sl@0
   945
	}
sl@0
   946
sl@0
   947
#ifdef _DEBUG
sl@0
   948
const TUint8 ETHER2_TYPE_IP_MSB = 0x08;
sl@0
   949
const TUint8 ETHER2_TYPE_IP_LSB = 0x00;
sl@0
   950
const TUint8 IP_TYPE_TCP        = 0x06;
sl@0
   951
sl@0
   952
TBool DEthernetWins::IsTcp(TDesC8 &aFrame)
sl@0
   953
	{
sl@0
   954
 	return (aFrame[12] == ETHER2_TYPE_IP_MSB && aFrame[13] == ETHER2_TYPE_IP_LSB && aFrame[23] == IP_TYPE_TCP);
sl@0
   955
	}
sl@0
   956
sl@0
   957
TInt DEthernetWins::GetTcpSeqNumber(TDesC8 &aFrame)
sl@0
   958
	{
sl@0
   959
 	TInt seqNum = 0;
sl@0
   960
 	if (IsTcp(aFrame))
sl@0
   961
 		seqNum = aFrame[38] << 24 | aFrame[39] << 16 | aFrame[40] << 8| aFrame[41];
sl@0
   962
 	return seqNum;
sl@0
   963
 	}
sl@0
   964
sl@0
   965
TInt DEthernetWins::GetTcpAckNumber(TDesC8 &aFrame)
sl@0
   966
 	{
sl@0
   967
 	TInt ackNum = 0;
sl@0
   968
 	if (IsTcp(aFrame))
sl@0
   969
 		ackNum = aFrame[42] << 24 | aFrame[43] << 16 | aFrame[44] << 8| aFrame[45];
sl@0
   970
 	return ackNum;
sl@0
   971
 	}
sl@0
   972
#endif
sl@0
   973
sl@0
   974
TInt WorkThread(DEthernetWins * aDEthernetWins)
sl@0
   975
	{
sl@0
   976
    __KTRACE_OPT(KHARDWARE, Kern::Printf("WorkThread(DEthernetWins * aDEthernetWins)"));
sl@0
   977
sl@0
   978
    return pcap_loop(aDEthernetWins->iPcapPtr, 0, DEthernetWins::Isr, (unsigned char *)aDEthernetWins);
sl@0
   979
	}
sl@0
   980
sl@0
   981
/**
sl@0
   982
 * @addtogroup enet_windows
sl@0
   983
 * @{
sl@0
   984
 */
sl@0
   985
sl@0
   986
/**
sl@0
   987
 * Real entry point from the Kernel: return a new driver
sl@0
   988
 * (Macro wrapping: EXPORT_C DPhysicalDevice *CreatePhysicalDevice() )
sl@0
   989
 */
sl@0
   990
DECLARE_STANDARD_PDD()
sl@0
   991
	{
sl@0
   992
	return new DDriverEthernet;
sl@0
   993
	}
sl@0
   994
sl@0
   995
sl@0
   996
/** @} */ // end of windows group