os/kernelhwsrv/kerneltest/e32test/examples/driver1/driver1_ldd.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2003-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 the License "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
//
sl@0
    15
sl@0
    16
/**
sl@0
    17
 @file Example Logical Device Driver
sl@0
    18
 @publishedPartner
sl@0
    19
 @released
sl@0
    20
*/
sl@0
    21
sl@0
    22
#include <kernel/kern_priv.h>
sl@0
    23
#include "driver1.h"
sl@0
    24
#include "driver1_dev.h"
sl@0
    25
sl@0
    26
_LIT(KDriver1PanicCategory,"Driver1");
sl@0
    27
sl@0
    28
sl@0
    29
//
sl@0
    30
// DDriver1Factory
sl@0
    31
//
sl@0
    32
sl@0
    33
/**
sl@0
    34
  Standard export function for LDDs. This creates a DLogicalDevice derived object,
sl@0
    35
  in this case, our DDriver1Factory
sl@0
    36
*/
sl@0
    37
DECLARE_STANDARD_LDD()
sl@0
    38
	{
sl@0
    39
	return new DDriver1Factory;
sl@0
    40
	}
sl@0
    41
sl@0
    42
/**
sl@0
    43
  Constructor
sl@0
    44
*/
sl@0
    45
DDriver1Factory::DDriver1Factory()
sl@0
    46
	{
sl@0
    47
	// Set version number for this device
sl@0
    48
	iVersion=RDriver1::VersionRequired();
sl@0
    49
	// Indicate that we work with a PDD
sl@0
    50
	iParseMask=KDeviceAllowPhysicalDevice;
sl@0
    51
	}
sl@0
    52
sl@0
    53
sl@0
    54
/**
sl@0
    55
  Second stage constructor for DDriver1Factory.
sl@0
    56
  This must at least set a name for the driver object.
sl@0
    57
sl@0
    58
  @return KErrNone if successful, otherwise one of the other system wide error codes.
sl@0
    59
*/
sl@0
    60
TInt DDriver1Factory::Install()
sl@0
    61
	{
sl@0
    62
	return SetName(&RDriver1::Name());
sl@0
    63
	}
sl@0
    64
sl@0
    65
sl@0
    66
/**
sl@0
    67
     Destructor
sl@0
    68
   */
sl@0
    69
DDriver1Factory::~DDriver1Factory()
sl@0
    70
   	{
sl@0
    71
   	}
sl@0
    72
sl@0
    73
sl@0
    74
/**
sl@0
    75
  Return the drivers capabilities.
sl@0
    76
  Called in the response to an RDevice::GetCaps() request.
sl@0
    77
sl@0
    78
  @param aDes User-side descriptor to write capabilities information into
sl@0
    79
*/
sl@0
    80
void DDriver1Factory::GetCaps(TDes8& aDes) const
sl@0
    81
	{
sl@0
    82
	// Create a capabilities object
sl@0
    83
	RDriver1::TCaps caps;
sl@0
    84
	caps.iVersion = iVersion;
sl@0
    85
	// Write it back to user memory
sl@0
    86
	Kern::InfoCopy(aDes,(TUint8*)&caps,sizeof(caps));
sl@0
    87
	}
sl@0
    88
sl@0
    89
/**
sl@0
    90
  Called by the kernel's device driver framework to create a Logical Channel.
sl@0
    91
  This is called in the context of the user thread (client) which requested the creation of a Logical Channel
sl@0
    92
  (E.g. through a call to RBusLogicalChannel::DoCreate)
sl@0
    93
  The thread is in a critical section.
sl@0
    94
sl@0
    95
  @param aChannel Set to point to the created Logical Channel
sl@0
    96
sl@0
    97
  @return KErrNone if successful, otherwise one of the other system wide error codes.
sl@0
    98
*/
sl@0
    99
TInt DDriver1Factory::Create(DLogicalChannelBase*& aChannel)
sl@0
   100
	{
sl@0
   101
	aChannel=new DDriver1Channel;
sl@0
   102
	if(!aChannel)
sl@0
   103
		return KErrNoMemory;
sl@0
   104
sl@0
   105
	return KErrNone;
sl@0
   106
	}
sl@0
   107
sl@0
   108
//
sl@0
   109
// Logical Channel
sl@0
   110
//
sl@0
   111
sl@0
   112
/**
sl@0
   113
  Constructor
sl@0
   114
*/
sl@0
   115
DDriver1Channel::DDriver1Channel()
sl@0
   116
	:	iSendDataDfc(SendDataDfc, this, 1),        // DFC is priority '1'
sl@0
   117
		iReceiveDataDfc(ReceiveDataDfc, this, 1)   // DFC is priority '1'
sl@0
   118
	{
sl@0
   119
	// Get pointer to client threads DThread object
sl@0
   120
	iClient=&Kern::CurrentThread();
sl@0
   121
sl@0
   122
	// Open a reference on client thread so it's control block can't dissapear until
sl@0
   123
	// this driver has finished with it.
sl@0
   124
	// Note, this call to Open can't fail since its the thread we are currently running in
sl@0
   125
	iClient->Open();
sl@0
   126
	}
sl@0
   127
sl@0
   128
/**
sl@0
   129
  Second stage constructor called by the kernel's device driver framework.
sl@0
   130
  This is called in the context of the user thread (client) which requested the creation of a Logical Channel
sl@0
   131
  (E.g. through a call to RBusLogicalChannel::DoCreate)
sl@0
   132
  The thread is in a critical section.
sl@0
   133
sl@0
   134
  @param aUnit The unit argument supplied by the client to RBusLogicalChannel::DoCreate
sl@0
   135
  @param aInfo The info argument supplied by the client to RBusLogicalChannel::DoCreate
sl@0
   136
  @param aVer The version argument supplied by the client to RBusLogicalChannel::DoCreate
sl@0
   137
sl@0
   138
  @return KErrNone if successful, otherwise one of the other system wide error codes.
sl@0
   139
*/
sl@0
   140
TInt DDriver1Channel::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& aVer)
sl@0
   141
	{
sl@0
   142
	// Check Platform Security capabilities of client thread (if required).
sl@0
   143
	//
sl@0
   144
	// Here we handle the simple case where:
sl@0
   145
	// 1. The device driver can only have one client thread
sl@0
   146
	// 2. The security policy is the binary all-or-nothing policy.
sl@0
   147
	//    E.g. "If you have the right capability you can do anything with the driver
sl@0
   148
	//    and if you don't have the capability you can't do anything"
sl@0
   149
	// 
sl@0
   150
	// If only some functionality of the driver is restricted, then the security check should
sl@0
   151
	// go elsewhere. E.g. in DoRequest/DoControl. In that case Kern::CurrentThreadHasCapability
sl@0
   152
	// shouldn't be used because the 'current thread' isn't the client.
sl@0
   153
	//
sl@0
   154
	// In this example we do a check here for ECapability_None (which always passes)...
sl@0
   155
	if(!Kern::CurrentThreadHasCapability(ECapability_None,__PLATSEC_DIAGNOSTIC_STRING("Checked by DRIVER1")))
sl@0
   156
		return KErrPermissionDenied;
sl@0
   157
sl@0
   158
	// Check version
sl@0
   159
	if (!Kern::QueryVersionSupported(RDriver1::VersionRequired(),aVer))
sl@0
   160
		return KErrNotSupported;
sl@0
   161
sl@0
   162
	// Setup LDD for receiving client messages
sl@0
   163
	SetDfcQ(((DDevice1PddFactory*)iPhysicalDevice)->iDfcQ);
sl@0
   164
	iMsgQ.Receive();
sl@0
   165
sl@0
   166
	// Associate DFCs with the same queue we set above to receive client messages on
sl@0
   167
	iSendDataDfc.SetDfcQ(iDfcQ);
sl@0
   168
	iReceiveDataDfc.SetDfcQ(iDfcQ);
sl@0
   169
sl@0
   170
	// Give PDD a pointer to this channel
sl@0
   171
	Pdd()->iLdd=this;
sl@0
   172
sl@0
   173
	// Done
sl@0
   174
	return KErrNone;
sl@0
   175
	}
sl@0
   176
sl@0
   177
/**
sl@0
   178
  Destructor
sl@0
   179
*/
sl@0
   180
DDriver1Channel::~DDriver1Channel()
sl@0
   181
	{
sl@0
   182
	// Cancel all processing that we may be doing
sl@0
   183
	DoCancel(RDriver1::EAllRequests);
sl@0
   184
	// Close our reference on the client thread
sl@0
   185
	Kern::SafeClose((DObject*&)iClient,NULL);
sl@0
   186
	}
sl@0
   187
sl@0
   188
/**
sl@0
   189
  Called when a user thread requests a handle to this channel.
sl@0
   190
*/
sl@0
   191
TInt DDriver1Channel::RequestUserHandle(DThread* aThread, TOwnerType aType)
sl@0
   192
	{
sl@0
   193
	// Make sure that only our client can get a handle
sl@0
   194
	if (aType!=EOwnerThread || aThread!=iClient)
sl@0
   195
		return KErrAccessDenied;
sl@0
   196
	return KErrNone;
sl@0
   197
	}
sl@0
   198
sl@0
   199
/**
sl@0
   200
  Process a message for this logical channel.
sl@0
   201
  This function is called in the context of a DFC thread.
sl@0
   202
sl@0
   203
  @param aMessage The message to process.
sl@0
   204
	              The iValue member of this distinguishes the message type:
sl@0
   205
	              iValue==ECloseMsg, channel close message
sl@0
   206
	              iValue==KMaxTInt, a 'DoCancel' message
sl@0
   207
	              iValue>=0, a 'DoControl' message with function number equal to iValue
sl@0
   208
	              iValue<0, a 'DoRequest' message with function number equal to ~iValue
sl@0
   209
*/
sl@0
   210
void DDriver1Channel::HandleMsg(TMessageBase* aMsg)
sl@0
   211
	{
sl@0
   212
	TThreadMessage& m=*(TThreadMessage*)aMsg;
sl@0
   213
sl@0
   214
	// Get message type
sl@0
   215
	TInt id=m.iValue;
sl@0
   216
sl@0
   217
	// Decode the message type and dispatch it to the relevent handler function...
sl@0
   218
sl@0
   219
	if (id==(TInt)ECloseMsg)
sl@0
   220
		{
sl@0
   221
		// Channel Close
sl@0
   222
		DoCancel(RDriver1::EAllRequests);
sl@0
   223
		m.Complete(KErrNone, EFalse);
sl@0
   224
		return;
sl@0
   225
		}
sl@0
   226
sl@0
   227
	if (id==KMaxTInt)
sl@0
   228
		{
sl@0
   229
		// DoCancel
sl@0
   230
		DoCancel(m.Int0());
sl@0
   231
		m.Complete(KErrNone,ETrue);
sl@0
   232
		return;
sl@0
   233
		}
sl@0
   234
sl@0
   235
	if (id<0)
sl@0
   236
		{
sl@0
   237
		// DoRequest
sl@0
   238
		TRequestStatus* pS=(TRequestStatus*)m.Ptr0();
sl@0
   239
		TInt r=DoRequest(~id,pS,m.Ptr1(),m.Ptr2());
sl@0
   240
		if (r!=KErrNone)
sl@0
   241
			Kern::RequestComplete(iClient,pS,r);
sl@0
   242
		m.Complete(KErrNone,ETrue);
sl@0
   243
		}
sl@0
   244
	else
sl@0
   245
		{
sl@0
   246
		// DoControl
sl@0
   247
		TInt r=DoControl(id,m.Ptr0(),m.Ptr1());
sl@0
   248
		m.Complete(r,ETrue);
sl@0
   249
		}
sl@0
   250
	}
sl@0
   251
sl@0
   252
/**
sl@0
   253
  Process synchronous 'control' requests
sl@0
   254
*/
sl@0
   255
TInt DDriver1Channel::DoControl(TInt aFunction, TAny* a1, TAny* a2)
sl@0
   256
	{
sl@0
   257
	(void)a2;   // a2 not used in this example
sl@0
   258
sl@0
   259
	TInt r;
sl@0
   260
sl@0
   261
	switch (aFunction)
sl@0
   262
		{
sl@0
   263
		case RDriver1::EGetConfig:
sl@0
   264
			r = GetConfig((TDes8*)a1);
sl@0
   265
			break;
sl@0
   266
sl@0
   267
		case RDriver1::ESetConfig:
sl@0
   268
			r = SetConfig((const TDesC8*)a1);
sl@0
   269
			break;
sl@0
   270
sl@0
   271
		default:
sl@0
   272
			r = KErrNotSupported;
sl@0
   273
			break;
sl@0
   274
		}
sl@0
   275
sl@0
   276
	return r;
sl@0
   277
	}
sl@0
   278
sl@0
   279
/**
sl@0
   280
  Process asynchronous requests.
sl@0
   281
*/
sl@0
   282
TInt DDriver1Channel::DoRequest(TInt aReqNo, TRequestStatus* aStatus, TAny* a1, TAny* a2)
sl@0
   283
	{
sl@0
   284
	(void)a2;   // a2 not used in this example
sl@0
   285
sl@0
   286
	TInt r;
sl@0
   287
sl@0
   288
	switch(aReqNo)
sl@0
   289
		{
sl@0
   290
		case RDriver1::ESendData:
sl@0
   291
			r=SendData(aStatus,(const TDesC8*)a1);
sl@0
   292
			break;
sl@0
   293
sl@0
   294
		case RDriver1::EReceiveData:
sl@0
   295
			// Example Platform Security capability check which tests the
sl@0
   296
			// client for ECapability_None (which always passes)...
sl@0
   297
			if(iClient->HasCapability(ECapability_None,__PLATSEC_DIAGNOSTIC_STRING("Checked by DRIVER1")))
sl@0
   298
				r=ReceiveData(aStatus,(TDes8*)a1);
sl@0
   299
			else
sl@0
   300
				r=KErrPermissionDenied;
sl@0
   301
			break;
sl@0
   302
sl@0
   303
		default:
sl@0
   304
			r = KErrNotSupported;
sl@0
   305
			break;
sl@0
   306
		}
sl@0
   307
sl@0
   308
	return r;
sl@0
   309
	}
sl@0
   310
sl@0
   311
/**
sl@0
   312
  Process cancelling of asynchronous requests.
sl@0
   313
*/
sl@0
   314
void DDriver1Channel::DoCancel(TUint aMask)
sl@0
   315
	{
sl@0
   316
	if(aMask&(1<<RDriver1::ESendData))
sl@0
   317
		SendDataCancel();
sl@0
   318
	if(aMask&(1<<RDriver1::EReceiveData))
sl@0
   319
		ReceiveDataCancel();
sl@0
   320
	}
sl@0
   321
sl@0
   322
//
sl@0
   323
// Methods for processing configuration control messages
sl@0
   324
//
sl@0
   325
sl@0
   326
/**
sl@0
   327
  Process a GetConfig control message. This writes the current driver configuration to a
sl@0
   328
  RDriver1::TConfigBuf supplied by the client.
sl@0
   329
*/
sl@0
   330
TInt DDriver1Channel::GetConfig(TDes8* aConfigBuf)
sl@0
   331
	{
sl@0
   332
	// Create a structure giving the current configuration
sl@0
   333
	RDriver1::TConfig config;
sl@0
   334
	CurrentConfig(config);
sl@0
   335
sl@0
   336
	// Write the config to the client
sl@0
   337
	TPtrC8 ptr((const TUint8*)&config,sizeof(config));
sl@0
   338
	return Kern::ThreadDesWrite(iClient,aConfigBuf,ptr,0,KTruncateToMaxLength,NULL);
sl@0
   339
	}
sl@0
   340
sl@0
   341
/**
sl@0
   342
  Process a SetConfig control message. This sets the driver configuration using a
sl@0
   343
  RDriver1::TConfigBuf supplied by the client.
sl@0
   344
*/
sl@0
   345
TInt DDriver1Channel::SetConfig(const TDesC8* aConfigBuf)
sl@0
   346
	{
sl@0
   347
	// Don't allow configuration changes whilst we're busy
sl@0
   348
	if(iSendDataStatus || iReceiveDataStatus)
sl@0
   349
		return KErrInUse;
sl@0
   350
sl@0
   351
	// Create a config structure.
sl@0
   352
	RDriver1::TConfig config;
sl@0
   353
	CurrentConfig(config);
sl@0
   354
sl@0
   355
	// Note: We have filled config with the current settings, this is to allow
sl@0
   356
	// backwards compatibility when a client gives us an old (and shorter) version
sl@0
   357
	// of the config structure.
sl@0
   358
sl@0
   359
	// Read the config structure from client
sl@0
   360
	TPtr8 ptr((TUint8*)&config,sizeof(config));
sl@0
   361
	TInt r=Kern::ThreadDesRead(iClient,aConfigBuf,ptr,0);
sl@0
   362
	if(r!=KErrNone)
sl@0
   363
		return r;
sl@0
   364
sl@0
   365
	// Use config data to setup the driver. Checking that parameters which aren't settable
sl@0
   366
	// either contain the correct values or are zero (meaning 'default')
sl@0
   367
	if(config.iPddBufferSize && config.iPddBufferSize!=Pdd()->BufferSize())
sl@0
   368
		return KErrArgument;
sl@0
   369
sl@0
   370
	if(config.iMaxSendDataSize && config.iMaxSendDataSize!=iSendDataBuffer.MaxSize())
sl@0
   371
		return KErrArgument;
sl@0
   372
sl@0
   373
	if(config.iMaxReceiveDataSize && config.iMaxReceiveDataSize!=iReceiveDataBuffer.MaxSize())
sl@0
   374
		return KErrArgument;
sl@0
   375
sl@0
   376
	r=Pdd()->SetSpeed(config.iSpeed);
sl@0
   377
	if(r!=KErrNone)
sl@0
   378
		return r;
sl@0
   379
sl@0
   380
	return r;
sl@0
   381
	}
sl@0
   382
sl@0
   383
/**
sl@0
   384
  Fill a TConfig with the drivers current configuration.
sl@0
   385
*/
sl@0
   386
void DDriver1Channel::CurrentConfig(RDriver1::TConfig& aConfig)
sl@0
   387
	{
sl@0
   388
	aConfig.iSpeed = Pdd()->Speed();
sl@0
   389
	aConfig.iPddBufferSize = Pdd()->BufferSize();
sl@0
   390
	aConfig.iMaxSendDataSize = iSendDataBuffer.MaxSize();
sl@0
   391
	aConfig.iMaxReceiveDataSize = iReceiveDataBuffer.MaxSize();
sl@0
   392
	}
sl@0
   393
sl@0
   394
//
sl@0
   395
// Methods for processing 'SendData'
sl@0
   396
//
sl@0
   397
sl@0
   398
/**
sl@0
   399
  Start processing a SendData request.
sl@0
   400
*/
sl@0
   401
TInt DDriver1Channel::SendData(TRequestStatus* aStatus,const TDesC8* aData)
sl@0
   402
	{
sl@0
   403
	// Check that a 'SendData' isn't already in progress
sl@0
   404
	if(iSendDataStatus)
sl@0
   405
		{
sl@0
   406
		Kern::ThreadKill(iClient,EExitPanic,ERequestAlreadyPending,KDriver1PanicCategory);
sl@0
   407
		return KErrInUse;
sl@0
   408
		}
sl@0
   409
sl@0
   410
	// Read data from client into our buffer
sl@0
   411
	TInt r=Kern::ThreadDesRead(iClient,aData,iSendDataBuffer,0);
sl@0
   412
	if(r!=KErrNone)
sl@0
   413
		return r;
sl@0
   414
sl@0
   415
	// Give data to PDD so that it can do the work
sl@0
   416
	r=Pdd()->SendData(iSendDataBuffer);
sl@0
   417
	if(r!=KErrNone)
sl@0
   418
		return r;
sl@0
   419
sl@0
   420
	// Save the client request status and return
sl@0
   421
	iSendDataStatus = aStatus;
sl@0
   422
	return KErrNone;
sl@0
   423
	}
sl@0
   424
sl@0
   425
/**
sl@0
   426
  Cancel a SendData request.
sl@0
   427
*/
sl@0
   428
void DDriver1Channel::SendDataCancel()
sl@0
   429
	{
sl@0
   430
	if(iSendDataStatus)
sl@0
   431
		{
sl@0
   432
		// Tell PDD to stop processing the request
sl@0
   433
		Pdd()->SendDataCancel();
sl@0
   434
		// Cancel DFC
sl@0
   435
		iSendDataDfc.Cancel();
sl@0
   436
		// Complete clients request
sl@0
   437
		Kern::RequestComplete(iClient,iSendDataStatus,KErrCancel);
sl@0
   438
		}
sl@0
   439
	}
sl@0
   440
sl@0
   441
/**
sl@0
   442
  Called by PDD from ISR to indicate that a SendData operation has completed.
sl@0
   443
*/
sl@0
   444
void DDriver1Channel::SendDataComplete(TInt aResult)
sl@0
   445
	{
sl@0
   446
	// Save result code
sl@0
   447
	iSendDataResult = aResult;
sl@0
   448
	// Queue DFC
sl@0
   449
	iSendDataDfc.Add();
sl@0
   450
	}
sl@0
   451
sl@0
   452
/**
sl@0
   453
  DFC callback which gets triggered after the PDD has signalled that SendData completed.
sl@0
   454
  This just casts aPtr and calls DoSendDataComplete().
sl@0
   455
*/
sl@0
   456
void DDriver1Channel::SendDataDfc(TAny* aPtr)
sl@0
   457
	{
sl@0
   458
	((DDriver1Channel*)aPtr)->DoSendDataComplete();
sl@0
   459
	}
sl@0
   460
sl@0
   461
/**
sl@0
   462
  Called from a DFC after the PDD has signalled that SendData completed.
sl@0
   463
*/
sl@0
   464
void DDriver1Channel::DoSendDataComplete()
sl@0
   465
	{
sl@0
   466
	TInt result = iSendDataResult;
sl@0
   467
	// Complete clients request
sl@0
   468
	Kern::RequestComplete(iClient,iSendDataStatus,result);
sl@0
   469
	}
sl@0
   470
sl@0
   471
//
sl@0
   472
// Methods for processing 'ReceiveData'
sl@0
   473
//
sl@0
   474
sl@0
   475
/**
sl@0
   476
  Start processing a ReceiveData request.
sl@0
   477
*/
sl@0
   478
TInt DDriver1Channel::ReceiveData(TRequestStatus* aStatus,TDes8* aPtr)
sl@0
   479
	{
sl@0
   480
	// Check that a 'ReceiveData' isn't already in progress
sl@0
   481
	if(iReceiveDataStatus)
sl@0
   482
		{
sl@0
   483
		Kern::ThreadKill(iClient,EExitPanic,ERequestAlreadyPending,KDriver1PanicCategory);
sl@0
   484
		return KErrInUse;
sl@0
   485
		}
sl@0
   486
sl@0
   487
	// Ask PDD for data
sl@0
   488
	TInt r=Pdd()->ReceiveData(iReceiveDataBuffer);
sl@0
   489
	if(r!=KErrNone)
sl@0
   490
		return r;
sl@0
   491
sl@0
   492
	// Save the client request status and descriptor before returning
sl@0
   493
	iReceiveDataStatus = aStatus;
sl@0
   494
	iReceiveDataDescriptor = aPtr;
sl@0
   495
	return KErrNone;
sl@0
   496
	}
sl@0
   497
sl@0
   498
/**
sl@0
   499
  Cancel a ReceiveData request.
sl@0
   500
*/
sl@0
   501
void DDriver1Channel::ReceiveDataCancel()
sl@0
   502
	{
sl@0
   503
	if(iReceiveDataStatus)
sl@0
   504
		{
sl@0
   505
		// Tell PDD to stop processing the request
sl@0
   506
		Pdd()->ReceiveDataCancel();
sl@0
   507
		// Cancel DFC
sl@0
   508
		iReceiveDataDfc.Cancel();
sl@0
   509
		// Finished with client descriptor, so NULL it to help detect coding errors
sl@0
   510
		iReceiveDataDescriptor = NULL;
sl@0
   511
		// Complete clients request
sl@0
   512
		Kern::RequestComplete(iClient,iReceiveDataStatus,KErrCancel);
sl@0
   513
		}
sl@0
   514
	}
sl@0
   515
sl@0
   516
/**
sl@0
   517
  Called by PDD from ISR to indicate that a ReceiveData operation has completed.
sl@0
   518
*/
sl@0
   519
void DDriver1Channel::ReceiveDataComplete(TInt aResult)
sl@0
   520
	{
sl@0
   521
	// Save result code
sl@0
   522
	iReceiveDataResult = aResult;
sl@0
   523
	// Queue DFC
sl@0
   524
	iReceiveDataDfc.Add();
sl@0
   525
	}
sl@0
   526
sl@0
   527
/**
sl@0
   528
  DFC Callback which gets triggered after the PDD has signalled that ReceiveData completed.
sl@0
   529
  This just casts aPtr and calls DoReceiveDataComplete().
sl@0
   530
*/
sl@0
   531
void DDriver1Channel::ReceiveDataDfc(TAny* aPtr)
sl@0
   532
	{
sl@0
   533
	((DDriver1Channel*)aPtr)->DoReceiveDataComplete();
sl@0
   534
	}
sl@0
   535
sl@0
   536
/**
sl@0
   537
  Called from a DFC after the PDD has signalled that ReceiveData completed.
sl@0
   538
*/
sl@0
   539
void DDriver1Channel::DoReceiveDataComplete()
sl@0
   540
	{
sl@0
   541
	// Write data to client from our buffer
sl@0
   542
	TInt result=Kern::ThreadDesWrite(iClient,iReceiveDataDescriptor,iReceiveDataBuffer,0);
sl@0
   543
sl@0
   544
	// Finished with client descriptor, so NULL it to help detect coding errors
sl@0
   545
	iReceiveDataDescriptor = NULL;
sl@0
   546
sl@0
   547
	// Use result code from PDD if it was an error
sl@0
   548
	if(iReceiveDataResult!=KErrNone)
sl@0
   549
		result = iReceiveDataResult;
sl@0
   550
sl@0
   551
	// Complete clients request
sl@0
   552
	Kern::RequestComplete(iClient,iReceiveDataStatus,result);
sl@0
   553
	}
sl@0
   554