kernel/eka/drivers/usbcc/descriptors.cpp
changeset 149 d9f1e5bfe28c
parent 0 a41df078684a
child 253 d37db4dcc88d
equal deleted inserted replaced
135:5e441a173c63 149:d9f1e5bfe28c
  2091 		__KTRACE_OPT(KUSB, Kern::Printf("  Descriptor #%d requested but not available", aIndex));
  2091 		__KTRACE_OPT(KUSB, Kern::Printf("  Descriptor #%d requested but not available", aIndex));
  2092 		return 0;
  2092 		return 0;
  2093 		}
  2093 		}
  2094 	return iDescriptors[aIndex]->GetDescriptorData(iEp0_TxBuf, KUsbcBufSz_Ep0Tx);
  2094 	return iDescriptors[aIndex]->GetDescriptorData(iEp0_TxBuf, KUsbcBufSz_Ep0Tx);
  2095 	}
  2095 	}
  2096 
  2096 	
  2097 
  2097 	
  2098 //
  2098 //
  2099 // Put the current Configuration or Other_Speed_Configuration descriptor + all the following
  2099 // Put the current Configuration or Other_Speed_Configuration descriptor + all the following
  2100 // descriptors in the Ep0 Tx buffer.
  2100 // descriptors in the Ep0 Tx buffer.
  2101 // Only used for Ep0 standard requests, so target buffer can be hard-wired.
  2101 // Only used for Ep0 standard requests, so target buffer can be hard-wired.
  2102 //
  2102 //
  2110 		// This is always an error: We should always have a Configuration descriptor and we should never
  2110 		// This is always an error: We should always have a Configuration descriptor and we should never
  2111 		// get asked for the Other_Speed_Configuration descriptor if we don't have one (9.6.2).
  2111 		// get asked for the Other_Speed_Configuration descriptor if we don't have one (9.6.2).
  2112 		__KTRACE_OPT(KPANIC, Kern::Printf("  Warning: Descriptor %d requested but not available", aIndex));
  2112 		__KTRACE_OPT(KPANIC, Kern::Printf("  Warning: Descriptor %d requested but not available", aIndex));
  2113 		return 0;
  2113 		return 0;
  2114 		}
  2114 		}
  2115 	const TInt count = iDescriptors.Count();
  2115 		
       
  2116 	const TInt count = iDescriptors.Count();	
  2116 	TInt copied = 0;
  2117 	TInt copied = 0;
  2117 	TUint8* buf = iEp0_TxBuf;
  2118 	TUint8* buf = iEp0_TxBuf;
  2118 	for (TInt i = aIndex; i < count; i++)
  2119 	// pos == count is used so that otg descriptor is added to the end of returned descriptors
  2119 		{
  2120 	for (TInt pos = aIndex; pos < count + 1; pos++)
  2120 		TUsbcDescriptorBase* const ptr = iDescriptors[i];
  2121 		{
  2121 		if ((aIndex == KDescPosition_OtherSpeedConfig) && (i == KDescPosition_Config))
  2122 			
       
  2123 		if ((aIndex == KDescPosition_OtherSpeedConfig) && (pos == KDescPosition_Config))
  2122 			{
  2124 			{
  2123 			// Skip Config descriptor when returning Other_Speed_Config
  2125 			// Skip Config descriptor when returning Other_Speed_Config
  2124 			continue;
  2126 			continue;
  2125 			}
  2127 			}
  2126 		if ((i == KDescPosition_Otg) && (iDescriptors[i] == NULL))
  2128 			
  2127 			{
  2129 		if (pos == KDescPosition_Otg) 
  2128 			__KTRACE_OPT(KUSB, Kern::Printf("  no OTG descriptor -> next"));
  2130 			{
       
  2131 			// Skip otg descriptor just now. add it when pos is count, so that OTG are added at the end
  2129 			continue;
  2132 			continue;
  2130 			}
  2133 			}
       
  2134 						
       
  2135 		TUsbcDescriptorBase* ptr = NULL;	
       
  2136 		if (pos == count)
       
  2137 			{
       
  2138 				if (iDescriptors[KDescPosition_Otg] == NULL)
       
  2139 					{
       
  2140 					// Skip since there is no otg descriptor
       
  2141 					__KTRACE_OPT(KUSB, Kern::Printf("  no otg descriptor"));
       
  2142 					continue;				
       
  2143 					}
       
  2144 				else
       
  2145 					{
       
  2146 					// add otg to the end of returned descriptors
       
  2147 					ptr = iDescriptors[KDescPosition_Otg];
       
  2148 					}
       
  2149 			}
       
  2150 		else
       
  2151 			{
       
  2152 			ptr = iDescriptors[pos];
       
  2153 			}
       
  2154 
  2131 		// We need to edit endpoint descriptors on the fly because we have only one copy
  2155 		// We need to edit endpoint descriptors on the fly because we have only one copy
  2132 		// of each and that copy has to contain different information, depending on the
  2156 		// of each and that copy has to contain different information, depending on the
  2133 		// current speed and the type of descriptor requested.
  2157 		// current speed and the type of descriptor requested.
  2134 		if (ptr->Type() == KUsbDescType_Endpoint)
  2158 		if (ptr->Type() == KUsbDescType_Endpoint)
  2135 			{
  2159 			{
  2141 			else
  2165 			else
  2142 				{
  2166 				{
  2143 				ptr->UpdateFs();
  2167 				ptr->UpdateFs();
  2144 				}
  2168 				}
  2145 			}
  2169 			}
       
  2170 
  2146 		__KTRACE_OPT(KUSB, Kern::Printf("  desc[%02d]: type = 0x%02x size = %d ",
  2171 		__KTRACE_OPT(KUSB, Kern::Printf("  desc[%02d]: type = 0x%02x size = %d ",
  2147 										i, ptr->Type(), ptr->Size()));
  2172 										pos, ptr->Type(), ptr->Size()));				
  2148 		const TInt size = ptr->GetDescriptorData(buf, KUsbcBufSz_Ep0Tx - copied);
  2173 		const TInt size = ptr->GetDescriptorData(buf, KUsbcBufSz_Ep0Tx - copied);
  2149 		if (size == 0)
  2174 		if (size == 0)
  2150 			{
  2175 			{
       
  2176 			
  2151 			__KTRACE_OPT(KPANIC,
  2177 			__KTRACE_OPT(KPANIC,
  2152 						 Kern::Printf("  Error: No Tx buffer space to copy this descriptor -> exiting"));
  2178 						 Kern::Printf("  Error: No Tx buffer space to copy this descriptor -> exiting"));
  2153 			break;
  2179 			break;
  2154 			}
  2180 			}
  2155 		copied += size;
  2181 		copied += size;
  2159 						 Kern::Printf("  Error: No Tx buffer space left -> stopping here"));
  2185 						 Kern::Printf("  Error: No Tx buffer space left -> stopping here"));
  2160 			break;
  2186 			break;
  2161 			}
  2187 			}
  2162 		buf += size;
  2188 		buf += size;
  2163 		}
  2189 		}
       
  2190 		
       
  2191 		
  2164 	__KTRACE_OPT(KUSB, Kern::Printf("  copied %d bytes", copied));
  2192 	__KTRACE_OPT(KUSB, Kern::Printf("  copied %d bytes", copied));
  2165 	return copied;
  2193 	return copied;
  2166 	}
  2194 	}
  2167 
  2195 
  2168 
  2196