kernel/eka/drivers/usbcc/chapter9.cpp
branchRCL_3
changeset 22 2f92ad2dc5db
parent 0 a41df078684a
child 26 c734af59ce98
equal deleted inserted replaced
21:e7d2d738d3c2 22:2f92ad2dc5db
   304 			}
   304 			}
   305 		}
   305 		}
   306 	else
   306 	else
   307 		{
   307 		{
   308 		// Type mask != KUsbRequestType_TypeStd => class- or vendor-specific request
   308 		// Type mask != KUsbRequestType_TypeStd => class- or vendor-specific request
   309 		iEp0ReceivedNonStdRequest = ETrue;
   309         iEp0ReceivedNonStdRequest = ETrue;
   310 		const DBase* client = NULL;
   310 		const DBase* client = NULL;
   311 		switch (packet.iRequestType & KUsbRequestType_DestMask)
   311 		switch (packet.iRequestType & KUsbRequestType_DestMask)
   312 			{ // Recipient
   312 			{ // Recipient
   313 		case KUsbRequestType_DestDevice:
   313 		case KUsbRequestType_DestDevice:
   314 			client = iEp0DeviceControl;
   314 			client = iEp0DeviceControl;
   315 			break;
   315 			break;
   316 		case KUsbRequestType_DestIfc:
   316 		case KUsbRequestType_DestIfc:
       
   317 		    //Add this mutex to protect the interface set data structure
       
   318 		    if (NKern::CurrentContext() == EThread)
       
   319 		        {
       
   320 		        NKern::FMWait(&iMutex);
       
   321 		        }
   317 			if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateConfigured)
   322 			if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateConfigured)
   318 				{
   323 				{
   319 				__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Invalid device state"));
   324 				__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Invalid device state"));
   320 				}
   325 				}
   321 			else
   326 			else
   322 				{
   327 				{
   323 				const TUsbcInterfaceSet* const ifcset_ptr =
   328 				const TUsbcInterfaceSet* const ifcset_ptr =
   324 					InterfaceNumber2InterfacePointer(packet.iIndex);
   329 					InterfaceNumber2InterfacePointer(packet.iIndex);
   325 				if (ifcset_ptr)
   330 				//In some rare case, ifcset_ptr is not NULL but the ifcset_ptr->iInterfaces.Count() is 0,
       
   331 				//so panic will happen when excute the following line. so I add the conditon
       
   332 				//0 != ifcset_ptr->iInterfaces.Count() here.
       
   333 				if (ifcset_ptr && 0 != ifcset_ptr->iInterfaces.Count())
   326 					{
   334 					{
   327 					if (ifcset_ptr->CurrentInterface()->iNoEp0Requests)
   335 					if (ifcset_ptr->CurrentInterface()->iNoEp0Requests)
   328 						{
   336 						{
   329 						__KTRACE_OPT(KUSB, Kern::Printf("  Recipient says: NoEp0RequestsPlease"));
   337 						__KTRACE_OPT(KUSB, Kern::Printf("  Recipient says: NoEp0RequestsPlease"));
   330 						}
   338 						}
   337 					{
   345 					{
   338 					__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Interface 0x%02x does not exist",
   346 					__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Interface 0x%02x does not exist",
   339 													  packet.iIndex));
   347 													  packet.iIndex));
   340 					}
   348 					}
   341 				}
   349 				}
       
   350 	        if (NKern::CurrentContext() == EThread)
       
   351 	            {
       
   352                 NKern::FMSignal(&iMutex);
       
   353 	            }
   342 			break;
   354 			break;
   343 		case KUsbRequestType_DestEp:
   355 		case KUsbRequestType_DestEp:
       
   356 		    //Add this mutex to protect the interface set data structure
       
   357 	        if (NKern::CurrentContext() == EThread)
       
   358 	            {
       
   359                 NKern::FMWait(&iMutex);
       
   360 	            }
   344 			if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateConfigured)
   361 			if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateConfigured)
   345 				{
   362 				{
   346 				__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Invalid device state"));
   363 				__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Invalid device state"));
   347 				}
   364 				}
   348 			else if (EndpointExists(packet.iIndex) == EFalse)
   365 			else if (EndpointExists(packet.iIndex) == EFalse)
   362 				else
   379 				else
   363 					{
   380 					{
   364 					client = ifcset_ptr->iClientId;
   381 					client = ifcset_ptr->iClientId;
   365 					}
   382 					}
   366 				}
   383 				}
       
   384             if (NKern::CurrentContext() == EThread)
       
   385                 {
       
   386                 NKern::FMSignal(&iMutex);
       
   387                 }
   367 			break;
   388 			break;
   368 		default:
   389 		default:
   369 			__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Other or Unknown recipient"));
   390 			__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Other or Unknown recipient"));
   370 			break;
   391 			break;
   371 			}
   392 			}
  1229 		ep->iPEndpoint->iLEndpoint = NULL;
  1250 		ep->iPEndpoint->iLEndpoint = NULL;
  1230 		}
  1251 		}
  1231 	if (aIfcSet->CurrentInterface() != 0)
  1252 	if (aIfcSet->CurrentInterface() != 0)
  1232 		{
  1253 		{
  1233 		__KTRACE_OPT(KUSB, Kern::Printf("  Resetting alternate interface setting to 0"));
  1254 		__KTRACE_OPT(KUSB, Kern::Printf("  Resetting alternate interface setting to 0"));
       
  1255 		//Add this mutex to protect the interface set data structure
       
  1256 		if (NKern::CurrentContext() == EThread)
       
  1257 		    {
       
  1258             NKern::FMWait(&iMutex);
       
  1259 		    }
       
  1260         
  1234 		aIfcSet->iCurrentInterface = 0;
  1261 		aIfcSet->iCurrentInterface = 0;
       
  1262 	    if (NKern::CurrentContext() == EThread)
       
  1263 	        {
       
  1264             NKern::FMSignal(&iMutex);
       
  1265 	        }		
  1235 		}
  1266 		}
  1236 	return;
  1267 	return;
  1237 	}
  1268 	}
  1238 
  1269 
  1239 
  1270