00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00023 #include <kern_priv.h>
00024 #include "driver1.h"
00025 #include "driver1_dev.h"
00026
00027 _LIT(KDriver1PanicCategory,"Driver1");
00028
00029
00030
00031
00032
00037 DECLARE_STANDARD_LDD()
00038 {
00039 return new DDriver1Factory;
00040 }
00041
00045 DDriver1Factory::DDriver1Factory()
00046 {
00047
00048 iVersion=RDriver1::VersionRequired();
00049
00050 iParseMask=KDeviceAllowPhysicalDevice;
00051 }
00052
00059 TInt DDriver1Factory::Install()
00060 {
00061 return SetName(&RDriver1::Name());
00062 }
00063
00067 DDriver1Factory::~DDriver1Factory()
00068 {
00069 }
00070
00076 void DDriver1Factory::GetCaps(TDes8& aDes) const
00077 {
00078
00079 RDriver1::TCaps caps;
00080 caps.iVersion = iVersion;
00081
00082 Kern::InfoCopy(aDes,(TUint8*)&caps,sizeof(caps));
00083 }
00084
00093 TInt DDriver1Factory::Create(DLogicalChannelBase*& aChannel)
00094 {
00095 aChannel=new DDriver1Channel;
00096 if(!aChannel)
00097 return KErrNoMemory;
00098
00099 return KErrNone;
00100 }
00101
00105 DDriver1Channel::DDriver1Channel()
00106 : iSendDataDfc(SendDataDfc, this, 1),
00107 iReceiveDataDfc(ReceiveDataDfc, this, 1)
00108 {
00109
00110 iClient=&Kern::CurrentThread();
00111
00112
00113
00114
00115 iClient->Open();
00116 }
00117
00128 TInt DDriver1Channel::DoCreate(TInt , const TDesC8* , const TVersion& aVer)
00129 {
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 if(!Kern::CurrentThreadHasCapability(ECapabilityMultimediaDD,__PLATSEC_DIAGNOSTIC_STRING("Checked by DRIVER1")))
00144 return KErrPermissionDenied;
00145
00146
00147 if (!Kern::QueryVersionSupported(RDriver1::VersionRequired(),aVer))
00148 return KErrNotSupported;
00149
00150
00151 SetDfcQ(Kern::DfcQue0());
00152 iMsgQ.Receive();
00153
00154
00155 iSendDataDfc.SetDfcQ(iDfcQ);
00156 iReceiveDataDfc.SetDfcQ(iDfcQ);
00157
00158
00159 Pdd()->iLdd=this;
00160
00161
00162 return KErrNone;
00163 }
00164
00168 DDriver1Channel::~DDriver1Channel()
00169 {
00170
00171 DoCancel(RDriver1::EAllRequests);
00172
00173 Kern::SafeClose((DObject*&)iClient,NULL);
00174 }
00175
00183 TInt DDriver1Channel::RequestUserHandle(DThread* aThread, TOwnerType aType)
00184 {
00185
00186 if (aType!=EOwnerThread || aThread!=iClient)
00187 return KErrAccessDenied;
00188 return KErrNone;
00189 }
00190
00202 void DDriver1Channel::HandleMsg(TMessageBase* aMsg)
00203 {
00204 TThreadMessage& m=*(TThreadMessage*)aMsg;
00205
00206
00207 TInt id=m.iValue;
00208
00209
00210 if (id==(TInt)ECloseMsg)
00211 {
00212
00213 DoCancel(RDriver1::EAllRequests);
00214 m.Complete(KErrNone, EFalse);
00215 return;
00216 }
00217
00218 if (id==KMaxTInt)
00219 {
00220
00221 DoCancel(m.Int0());
00222 m.Complete(KErrNone,ETrue);
00223 return;
00224 }
00225
00226 if (id<0)
00227 {
00228
00229 TRequestStatus* pS=(TRequestStatus*)m.Ptr0();
00230 TInt r=DoRequest(~id,pS,m.Ptr1(),m.Ptr2());
00231 if (r!=KErrNone)
00232 Kern::RequestComplete(iClient,pS,r);
00233 m.Complete(KErrNone,ETrue);
00234 }
00235 else
00236 {
00237
00238 TInt r=DoControl(id,m.Ptr0(),m.Ptr1());
00239 m.Complete(r,ETrue);
00240 }
00241 }
00242
00250 TInt DDriver1Channel::DoControl(TInt aFunction, TAny* a1, TAny* a2)
00251 {
00252 (void)a2;
00253
00254 TInt r;
00255
00256 switch (aFunction)
00257 {
00258 case RDriver1::EGetConfig:
00259 r = GetConfig((TDes8*)a1);
00260 break;
00261
00262 case RDriver1::ESetConfig:
00263 r = SetConfig((const TDesC8*)a1);
00264 break;
00265
00266 default:
00267 r = KErrNotSupported;
00268 break;
00269 }
00270
00271 return r;
00272 }
00273
00282 TInt DDriver1Channel::DoRequest(TInt aReqNo, TRequestStatus* aStatus, TAny* a1, TAny* a2)
00283 {
00284 (void)a2;
00285
00286 TInt r;
00287
00288 switch(aReqNo)
00289 {
00290 case RDriver1::ESendData:
00291 r=SendData(aStatus,(const TDesC8*)a1);
00292 break;
00293
00294 case RDriver1::EReceiveData:
00295 r=ReceiveData(aStatus,(TDes8*)a1);
00296 break;
00297
00298 default:
00299 r = KErrNotSupported;
00300 break;
00301 }
00302
00303 return r;
00304 }
00305
00310 void DDriver1Channel::DoCancel(TUint aMask)
00311 {
00312 if(aMask&(1<<RDriver1::ESendData))
00313 SendDataCancel();
00314 if(aMask&(1<<RDriver1::EReceiveData))
00315 ReceiveDataCancel();
00316 }
00317
00318
00319
00320
00321
00326 TInt DDriver1Channel::GetConfig(TDes8* aConfigBuf)
00327 {
00328
00329 RDriver1::TConfig config;
00330 CurrentConfig(config);
00331
00332
00333 TPtrC8 ptr((const TUint8*)&config,sizeof(config));
00334 return Kern::ThreadDesWrite(iClient,aConfigBuf,ptr,0,KTruncateToMaxLength,NULL);
00335 }
00336
00341 TInt DDriver1Channel::SetConfig(const TDesC8* aConfigBuf)
00342 {
00343
00344 if(iSendDataStatus || iReceiveDataStatus)
00345 return KErrInUse;
00346
00347
00348 RDriver1::TConfig config;
00349 CurrentConfig(config);
00350
00351
00352
00353
00354
00355
00356 TPtr8 ptr((TUint8*)&config,sizeof(config));
00357 TInt r=Kern::ThreadDesRead(iClient,aConfigBuf,ptr,0);
00358 if(r!=KErrNone)
00359 return r;
00360
00361
00362
00363 if(config.iPddBufferSize && config.iPddBufferSize!=Pdd()->BufferSize())
00364 return KErrArgument;
00365
00366 if(config.iMaxSendDataSize && config.iMaxSendDataSize!=iSendDataBuffer.MaxSize())
00367 return KErrArgument;
00368
00369 if(config.iMaxReceiveDataSize && config.iMaxReceiveDataSize!=iReceiveDataBuffer.MaxSize())
00370 return KErrArgument;
00371
00372 r=Pdd()->SetSpeed(config.iSpeed);
00373 if(r!=KErrNone)
00374 return r;
00375
00376 return r;
00377 }
00378
00383 void DDriver1Channel::CurrentConfig(RDriver1::TConfig& aConfig)
00384 {
00385 aConfig.iSpeed = Pdd()->Speed();
00386 aConfig.iPddBufferSize = Pdd()->BufferSize();
00387 aConfig.iMaxSendDataSize = iSendDataBuffer.MaxSize();
00388 aConfig.iMaxReceiveDataSize = iReceiveDataBuffer.MaxSize();
00389 }
00390
00391
00392
00393
00394
00402 TInt DDriver1Channel::SendData(TRequestStatus* aStatus,const TDesC8* aData)
00403 {
00404
00405 if(iSendDataStatus)
00406 {
00407 Kern::ThreadKill(iClient,EExitPanic,ERequestAlreadyPending,KDriver1PanicCategory);
00408 return KErrInUse;
00409 }
00410
00411
00412 TInt r=Kern::ThreadDesRead(iClient,aData,iSendDataBuffer,0);
00413 if(r!=KErrNone)
00414 return r;
00415
00416
00417 r=Pdd()->SendData(iSendDataBuffer);
00418 if(r!=KErrNone)
00419 return r;
00420
00421
00422 iSendDataStatus = aStatus;
00423 return KErrNone;
00424 }
00425
00429 void DDriver1Channel::SendDataCancel()
00430 {
00431 if(iSendDataStatus)
00432 {
00433
00434 Pdd()->SendDataCancel();
00435
00436 iSendDataDfc.Cancel();
00437
00438 Kern::RequestComplete(iClient,iSendDataStatus,KErrCancel);
00439 }
00440 }
00441
00445 void DDriver1Channel::SendDataComplete(TInt aResult)
00446 {
00447
00448 iSendDataResult = aResult;
00449
00450 iSendDataDfc.Add();
00451 }
00452
00457 void DDriver1Channel::SendDataDfc(TAny* aPtr)
00458 {
00459 ((DDriver1Channel*)aPtr)->DoSendDataComplete();
00460 }
00461
00465 void DDriver1Channel::DoSendDataComplete()
00466 {
00467 TInt result = iSendDataResult;
00468
00469 Kern::RequestComplete(iClient,iSendDataStatus,result);
00470 }
00471
00472
00473
00474
00475
00482 TInt DDriver1Channel::ReceiveData(TRequestStatus* aStatus,TDes8* aPtr)
00483 {
00484
00485 if(iReceiveDataStatus)
00486 {
00487 Kern::ThreadKill(iClient,EExitPanic,ERequestAlreadyPending,KDriver1PanicCategory);
00488 return KErrInUse;
00489 }
00490
00491
00492 TInt r=Pdd()->ReceiveData(iReceiveDataBuffer);
00493 if(r!=KErrNone)
00494 return r;
00495
00496
00497 iReceiveDataStatus = aStatus;
00498 iReceiveDataDescriptor = aPtr;
00499 return KErrNone;
00500 }
00501
00505 void DDriver1Channel::ReceiveDataCancel()
00506 {
00507 if(iReceiveDataStatus)
00508 {
00509
00510 Pdd()->ReceiveDataCancel();
00511
00512 iReceiveDataDfc.Cancel();
00513
00514 iReceiveDataDescriptor = NULL;
00515
00516 Kern::RequestComplete(iClient,iReceiveDataStatus,KErrCancel);
00517 }
00518 }
00519
00523 void DDriver1Channel::ReceiveDataComplete(TInt aResult)
00524 {
00525
00526 iReceiveDataResult = aResult;
00527
00528 iReceiveDataDfc.Add();
00529 }
00530
00535 void DDriver1Channel::ReceiveDataDfc(TAny* aPtr)
00536 {
00537 ((DDriver1Channel*)aPtr)->DoReceiveDataComplete();
00538 }
00539
00543 void DDriver1Channel::DoReceiveDataComplete()
00544 {
00545
00546 TInt result=Kern::ThreadDesWrite(iClient,iReceiveDataDescriptor,iReceiveDataBuffer,0);
00547
00548
00549 iReceiveDataDescriptor = NULL;
00550
00551
00552 if(iReceiveDataResult!=KErrNone)
00553 result = iReceiveDataResult;
00554
00555
00556 Kern::RequestComplete(iClient,iReceiveDataStatus,result);
00557 }
00558