kernel/eka/drivers/usbho/usbdescriptors/usbdescriptors.cpp
changeset 273 6a75fa55495f
parent 189 a5496987b1da
equal deleted inserted replaced
271:dc268b18d709 273:6a75fa55495f
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
  1128 	{
  1128 	{
  1129 	TUsbOTGDescriptor* ret = NULL;
  1129 	TUsbOTGDescriptor* ret = NULL;
  1130 	// Only cast if correctly indentified as otg descriptor
  1130 	// Only cast if correctly indentified as otg descriptor
  1131 	if(	aOriginal &&
  1131 	if(	aOriginal &&
  1132 		aOriginal->ibDescriptorType == EOTG &&
  1132 		aOriginal->ibDescriptorType == EOTG &&
  1133 		aOriginal->ibLength == TUsbOTGDescriptor::KSizeInOctets &&
  1133 		TUsbOTGDescriptor::IsValidOTGDescriptorLength( aOriginal->ibLength ) &&
  1134 		aOriginal->iRecognisedAndParsed == ERecognised)
  1134 		aOriginal->iRecognisedAndParsed == ERecognised)
  1135 		{
  1135 		{
  1136 		ret = static_cast<TUsbOTGDescriptor*>(aOriginal);
  1136 		ret = static_cast<TUsbOTGDescriptor*>(aOriginal);
  1137 		}
  1137 		}
  1138 	return ret;
  1138 	return ret;
  1155     // However this function just extracts the bit rather than attempting to
  1155     // However this function just extracts the bit rather than attempting to
  1156     // fix up a broken device.  Devices broken in this way wouldn't be expected on
  1156     // fix up a broken device.  Devices broken in this way wouldn't be expected on
  1157     // the TPL.
  1157     // the TPL.
  1158     return (ParseTUint8(iBlob, EbmAttributes) & 0x01) == 0x01;
  1158     return (ParseTUint8(iBlob, EbmAttributes) & 0x01) == 0x01;
  1159     }
  1159     }
  1160 	
  1160 
       
  1161 EXPORT_C TUint16 TUsbOTGDescriptor::BcdOTG() const
       
  1162 	{
       
  1163     TUint16 bcdOTG = 0x0000;
       
  1164     if ( iBlob[EbmLength] > TUsbOTGDescriptor::KSizeInOctets )
       
  1165 	    {
       
  1166         bcdOTG = ( iBlob[EbcdOTG] ) | ( iBlob[EbcdOTG + 1] << 8 );
       
  1167 	    }
       
  1168     return bcdOTG;
       
  1169 	}
       
  1170 
  1161 /**
  1171 /**
  1162 The parsing routine for OTG descriptors.
  1172 The parsing routine for OTG descriptors.
  1163 
  1173 
  1164 @internalComponent
  1174 @internalComponent
  1165 */
  1175 */
  1166 /*static*/ TUsbOTGDescriptor* TUsbOTGDescriptor::ParseL(TPtrC8& aUsbDes, TUsbGenericDescriptor* /*aPreviousDesc*/)
  1176 /*static*/ TUsbOTGDescriptor* TUsbOTGDescriptor::ParseL(TPtrC8& aUsbDes, TUsbGenericDescriptor* /*aPreviousDesc*/)
  1167 	{
  1177 	{
  1168 	TUsbOTGDescriptor* endDes = NULL;
  1178 	TUsbOTGDescriptor* endDes = NULL;
  1169 
  1179 
       
  1180 	TUint8 descriptorLength = aUsbDes[KbLengthOffset];
  1170 	const TInt KMinOTGDesDecisionLength = 2;
  1181 	const TInt KMinOTGDesDecisionLength = 2;
  1171 	if(	aUsbDes.Length() >= KMinOTGDesDecisionLength &&
  1182 	if(	aUsbDes.Length() >= KMinOTGDesDecisionLength &&
  1172 		aUsbDes[KbDescriptorTypeOffset] == EOTG &&
  1183 		aUsbDes[KbDescriptorTypeOffset] == EOTG &&
  1173 		aUsbDes[KbLengthOffset] == TUsbOTGDescriptor::KSizeInOctets)
  1184 		TUsbOTGDescriptor::IsValidOTGDescriptorLength( descriptorLength ) )
  1174 		{
  1185 		{
  1175 		// Robustness check - check the length field is valid, and that we have enough data.
  1186 		// Robustness check - check the length field is valid, and that we have enough data.
  1176 		if(aUsbDes.Length() < TUsbOTGDescriptor::KSizeInOctets)
  1187 		if(aUsbDes.Length() < descriptorLength)
  1177 			{
  1188 			{
  1178 			User::Leave(KErrCorrupt);
  1189 			User::Leave(KErrCorrupt);
  1179 			}
  1190 			}
  1180 
  1191 
  1181 		// Looks ok to be an OTG descriptor.
  1192 		// Looks ok to be an OTG descriptor.
  1182 		endDes = new(ELeave) TUsbOTGDescriptor;
  1193 		endDes = new(ELeave) TUsbOTGDescriptor;
  1183 		// Set the standard fields
  1194 		// Set the standard fields
  1184 		endDes->ibLength = TUsbOTGDescriptor::KSizeInOctets;
  1195 		endDes->ibLength = descriptorLength;
  1185 		endDes->ibDescriptorType = EOTG;
  1196 		endDes->ibDescriptorType = EOTG;
  1186 		// Set the blob appropriately
  1197 		// Set the blob appropriately
  1187 		endDes->iBlob.Set(aUsbDes.Left(TUsbOTGDescriptor::KSizeInOctets));
  1198 		endDes->iBlob.Set(aUsbDes.Left(descriptorLength));
  1188 
  1199 
  1189 		// Null the pointers
  1200 		// Null the pointers
  1190 		endDes->iFirstChild = NULL;
  1201 		endDes->iFirstChild = NULL;
  1191 		endDes->iNextPeer = NULL;
  1202 		endDes->iNextPeer = NULL;
  1192 		endDes->iParent = NULL;
  1203 		endDes->iParent = NULL;
  1193 		
  1204 		
  1194 		endDes->iRecognisedAndParsed = ERecognised;
  1205 		endDes->iRecognisedAndParsed = ERecognised;
  1195 
  1206 
  1196 		// Update the data-left-to-parse Symbian descriptor
  1207 		// Update the data-left-to-parse Symbian descriptor
  1197 		aUsbDes.Set(aUsbDes.Mid(TUsbOTGDescriptor::KSizeInOctets));
  1208 		aUsbDes.Set(aUsbDes.Mid(descriptorLength));
  1198 		}
  1209 		}
  1199 
  1210 
  1200 	return endDes;
  1211 	return endDes;
  1201 	}
  1212 	}
  1202 
  1213 
  1230 		// Any other descriptors are ignored.
  1241 		// Any other descriptors are ignored.
  1231 		return EFalse;
  1242 		return EFalse;
  1232 		}
  1243 		}
  1233 	}
  1244 	}
  1234 
  1245 
       
  1246 /**
       
  1247 @internalComponent
       
  1248 */
       
  1249 /*static*/ TBool TUsbOTGDescriptor::IsValidOTGDescriptorLength(TUint8 aLength)
       
  1250 	{
       
  1251     TBool ret = EFalse;
       
  1252     const TUint8 KOTG13DescriptorLength = 3; //OTG1.3 
       
  1253     const TUint8 KOTG20DescriptorLength = 5; //OTG2.0
       
  1254     if ( ( aLength == KOTG13DescriptorLength ) || ( aLength == KOTG20DescriptorLength ) )
       
  1255         {
       
  1256         ret = ETrue;
       
  1257         }
       
  1258     return ret;
       
  1259 	}
  1235 
  1260 
  1236 // ----------------------
  1261 // ----------------------
  1237 // TUsbStringDescriptor
  1262 // TUsbStringDescriptor
  1238 // See section 9.6.7 of the USB 2.0 specification.
  1263 // See section 9.6.7 of the USB 2.0 specification.
  1239 // ----------------------
  1264 // ----------------------