First public contribution.
1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32/include/d32usbc.h
15 // User side class definitions for USB Device support.
30 #include <d32usbcshared.h>
34 /** @internalComponent
38 ETransferTypeReadData,
39 ETransferTypeReadPacket,
42 ETransferTypeReadOneOrMore,
43 ETransferTypeReadUntilShort
47 /** Available endpoints. At most only these are available per interface.
62 /** Bandwidth indicators for an Interface
64 @see RDevUsbcClient::SetInterface()
66 enum TUsbcBandwidthPriority
68 /** Economical OUT buffering. */
69 EUsbcBandwidthOUTDefault = 0x00,
70 /** More memory than Default for OUT buffering. */
71 EUsbcBandwidthOUTPlus1 = 0x01,
72 /** More memory than Plus1 for OUT buffering. */
73 EUsbcBandwidthOUTPlus2 = 0x02,
74 /** Maximum memory for OUT buffering.
75 Use this value for high volume USB High-speed
76 data transfers only, otherwise memory will be wasted.
78 EUsbcBandwidthOUTMaximum = 0x03,
80 /** Economical IN buffering */
81 EUsbcBandwidthINDefault = 0x00,
82 /** More memory than Default for IN buffering */
83 EUsbcBandwidthINPlus1 = 0x10,
84 /** More memory than Plus1 for IN buffering */
85 EUsbcBandwidthINPlus2 = 0x20,
86 /** Maximum memory for IN buffering.
87 Use this value for high volume USB High-speed
88 data transfers only, otherwise memory will be wasted.
90 EUsbcBandwidthINMaximum = 0x30
99 /** Bit positions of endpoints.
101 @see RDevUsbcClient::EndpointStatusNotify()
102 @see RDevUsbcClient::EndpointTransferCancel()
104 Bit position of endpoint0.
106 const TUint KUsbcEndpoint0Bit = 1<<EEndpoint0;
107 /** Bit position of endpoint1.
109 const TUint KUsbcEndpoint1Bit = 1<<EEndpoint1;
110 /** Bit position of endpoint2.
112 const TUint KUsbcEndpoint2Bit = 1<<EEndpoint2;
113 /** Bit position of endpoint3.
115 const TUint KUsbcEndpoint3Bit = 1<<EEndpoint3;
116 /** Bit position of endpoint4.
118 const TUint KUsbcEndpoint4Bit = 1<<EEndpoint4;
119 /** Bit position of endpoint5.
121 const TUint KUsbcEndpoint5Bit = 1<<EEndpoint5;
130 /** This must be filled in prior to a call to RDevUsbcClient::SetInterface().
132 class TUsbcInterfaceInfo
135 TUsbcInterfaceInfo(TInt aClass=0, TInt aSubClass=0, TInt aProtocol=0,
136 TDesC16* aString=NULL, TUint aTotalEndpoints=0);
138 /** The class, subclass and protocol that this interface supports. */
139 TUsbcClassInfo iClass;
140 /** The description string for the interface. Used to construct the interface string descriptor. */
141 const TDesC16* iString;
142 /** Total number of endpoints being requested (0-5). Endpoint 0 should not be included in this number. */
143 TUint iTotalEndpointsUsed;
144 /** Desired properties of the endpoints requested.
145 Do NOT include endpoint 0.
146 APIs use endpoint numbers that are offsets into this array.
148 TUsbcEndpointInfo iEndpointData[KMaxEndpointsPerClient];
149 /** 32 flag bits used for specifying miscellaneous Interface features.
150 Currently defined are:
151 - KUsbcInterfaceInfo_NoEp0RequestsPlease = 0x00000001
153 TUint32 iFeatureWord;
157 /** Package buffer for a TUsbcInterfaceInfo object.
159 @see TUsbcInterfaceInfo
161 typedef TPckgBuf<TUsbcInterfaceInfo> TUsbcInterfaceInfoBuf;
164 /** The user side handle to the USB client driver.
166 class RDevUsbcClient : public RBusLogicalChannel
169 /** @internalComponent */
172 EMajorVersionNumber = 0,
173 EMinorVersionNumber = 1,
174 EBuildVersionNumber = KE32BuildVersionNumber
179 // Positive requests.
181 ERequestEp1 = EEndpoint1,
182 ERequestEp2 = EEndpoint2,
183 ERequestEp3 = EEndpoint3,
184 ERequestEp4 = EEndpoint4,
185 ERequestEp5 = EEndpoint5,
187 ERequestAlternateDeviceStatusNotify = 7,
188 ERequestReEnumerate = 8,
189 ERequestEndpointStatusNotify = 9,
190 // The cancel TRequest's are interpreted as bitmaps. As they're not mixed
191 // with the previous ones, it doesn't matter if they have the same absolute
193 ERequestEp0Cancel = 1<<ERequestEp0,
194 ERequestEp1Cancel = 1<<ERequestEp1,
195 ERequestEp2Cancel = 1<<ERequestEp2,
196 ERequestEp3Cancel = 1<<ERequestEp3,
197 ERequestEp4Cancel = 1<<ERequestEp4,
198 ERequestEp5Cancel = 1<<ERequestEp5,
199 ERequestUnusedCancel = 1<<ERequestUnused,
200 ERequestAllCancel = (ERequestEp0Cancel | ERequestEp1Cancel |
201 ERequestEp2Cancel | ERequestEp3Cancel |
202 ERequestEp4Cancel | ERequestEp5Cancel |
203 ERequestUnusedCancel),
204 ERequestAlternateDeviceStatusNotifyCancel = 1<<ERequestAlternateDeviceStatusNotify,
205 ERequestReEnumerateCancel = 1<<ERequestReEnumerate,
206 ERequestEndpointStatusNotifyCancel = 1<<ERequestEndpointStatusNotify,
207 ERequestOtgFeaturesNotify = 10,
208 ERequestOtgFeaturesNotifyCancel = 1<<ERequestOtgFeaturesNotify,
213 // Changing the order of these enums will break BC.
214 EControlEndpointZeroRequestError, // 0
215 EControlEndpointCaps,
217 EControlGetAlternateSetting,
218 EControlDeviceStatus,
219 EControlEndpointStatus,
220 EControlSetInterface,
221 EControlReleaseInterface,
222 EControlQueryReceiveBuffer,
223 EControlSendEp0StatusPacket, // 9
225 EControlHaltEndpoint, // 10
226 EControlClearHaltEndpoint,
227 EControlSetDeviceControl,
228 EControlReleaseDeviceControl,
229 EControlEndpointZeroMaxPacketSizes,
230 EControlSetEndpointZeroMaxPacketSize,
231 EControlGetDeviceDescriptor,
232 EControlSetDeviceDescriptor,
233 EControlGetDeviceDescriptorSize,
234 EControlGetConfigurationDescriptor, // 19
236 EControlSetConfigurationDescriptor, // 20
237 EControlGetConfigurationDescriptorSize,
238 EControlGetInterfaceDescriptor,
239 EControlSetInterfaceDescriptor,
240 EControlGetInterfaceDescriptorSize,
241 EControlGetEndpointDescriptor,
242 EControlSetEndpointDescriptor,
243 EControlGetEndpointDescriptorSize,
244 EControlGetCSInterfaceDescriptor,
245 EControlSetCSInterfaceDescriptor, // 29
247 EControlGetCSInterfaceDescriptorSize, // 30
248 EControlGetCSEndpointDescriptor,
249 EControlSetCSEndpointDescriptor,
250 EControlGetCSEndpointDescriptorSize,
251 EControlSignalRemoteWakeup,
252 EControlGetStringDescriptorLangId,
253 EControlSetStringDescriptorLangId,
254 EControlGetManufacturerStringDescriptor,
255 EControlSetManufacturerStringDescriptor,
256 EControlRemoveManufacturerStringDescriptor, // 39
258 EControlGetProductStringDescriptor, // 40
259 EControlSetProductStringDescriptor,
260 EControlRemoveProductStringDescriptor,
261 EControlGetSerialNumberStringDescriptor,
262 EControlSetSerialNumberStringDescriptor,
263 EControlRemoveSerialNumberStringDescriptor,
264 EControlGetConfigurationStringDescriptor,
265 EControlSetConfigurationStringDescriptor,
266 EControlRemoveConfigurationStringDescriptor,
267 EControlDeviceDisconnectFromHost, // 49
269 EControlDeviceConnectToHost, // 50
270 EControlDevicePowerUpUdc,
271 EControlDumpRegisters,
272 EControlSetInterface1, // (not used)
273 EControlAllocateEndpointResource,
274 EControlDeAllocateEndpointResource,
275 EControlQueryEndpointResourceUse,
276 EControlGetEndpointZeroMaxPacketSize,
277 EControlGetDeviceQualifierDescriptor,
278 EControlSetDeviceQualifierDescriptor, // 59
280 EControlGetOtherSpeedConfigurationDescriptor, // 60
281 EControlSetOtherSpeedConfigurationDescriptor,
282 EControlCurrentlyUsingHighSpeed,
283 EControlSetStringDescriptor,
284 EControlGetStringDescriptor,
285 EControlRemoveStringDescriptor,
286 EControlSetOtgDescriptor,
287 EControlGetOtgDescriptor,
288 EControlGetOtgFeatures
293 #ifndef __KERNEL_MODE__
297 @param aUnit This should be 0 (zero).
299 @return KErrNone if successful.
301 inline TInt Open(TInt aUnit);
303 inline TVersion VersionRequired() const;
305 /** Stalls ep0 to signal command fault to the host.
307 @return KErrNone if successful.
309 inline TInt EndpointZeroRequestError();
311 /** Retrieves the capabilities of all the endpoints on the device.
313 Suggested use is as follows:
316 TUsbcEndpointData data[KUsbcMaxEndpoints];
317 TPtr8 dataPtr(reinterpret_cast<TUint8*>(data), sizeof(data), sizeof(data));
318 ret = usbPort.EndpointCaps(dataPtr);
321 @param aEpCapsBuf a descriptor encapsulating an array of TUsbcEndpointData.
323 @return KErrNone if successful.
325 inline TInt EndpointCaps(TDes8& aEpCapsBuf);
327 /** Retrieves the capabilities of the USB device.
331 @param aDevCapsBuf a TUsbDeviceCaps object.
333 @return KErrNone if successful.
335 inline TInt DeviceCaps(TUsbDeviceCaps& aDevCapsBuf);
337 /** Copies the current alternate setting for this interface into aInterfaceNumber
338 For USB Interfaces whose main interface is active, this will be 0 (zero).
340 @param aInterfaceNumber current alternate setting for this interface is copied into this.
342 @return KErrNone if successful.
344 inline TInt GetAlternateSetting(TInt& aInterfaceNumber);
346 /** Copies the current device status into aDeviceStatus.
348 @param aDeviceStatus current device status is copied into this.
350 @return KErrNone if successful
352 inline TInt DeviceStatus(TUsbcDeviceState& aDeviceStatus);
354 /** Copies the current endpoint status into aEndpointStatus.
356 @param aEndpoint endpoint number valid for the current alternate setting.
357 @param aEndpointStatus the current endpoint status, might be stalled, not stalled or unknown.
359 @return KErrNone if successful.
361 inline TInt EndpointStatus(TEndpointNumber aEndpoint, TEndpointState& aEndpointStatus);
363 /** Copies the number of bytes available in the aEndpoint read buffer into aNumberOfBytes.
365 @param aEndpoint endpoint number valid for the current alternate setting.
366 @param aNumberOfBytes number of bytes available in the aEndpoint read buffer.
368 @return KErrNone if successful.
370 inline TInt QueryReceiveBuffer(TEndpointNumber aEndpoint, TInt& aNumberOfBytes);
372 /** Requests that a zero length status packet be sent to the host in response
373 to a class or vendor specific ep0 SETUP packet.
375 @return KErrNone if successful.
377 inline TInt SendEp0StatusPacket();
379 /** Stalls endpoint aEndpoint, usually to indicate an error condition with a previous command.
380 The host will normally send a SET_FEATURE command on ep0 to acknowledge and clear the stall.
382 @return KErrNone if successful.
384 inline TInt HaltEndpoint(TEndpointNumber aEndpoint);
386 /** Clears the stall condition on endpoint aEndpoint. This is inluded for symmetry and test purposes.
388 @return KErrNone if successful.
390 inline TInt ClearHaltEndpoint(TEndpointNumber aEndpoint);
392 /** Requests that device control be allocated to this channel.
394 @return KErrNone if successful.
396 inline TInt SetDeviceControl();
398 /** Relinquishes device control previously allocated to this channel.
400 @return KErrNone if successful.
402 inline TInt ReleaseDeviceControl();
404 /** Returns a bitmap of available ep0 maximum packet sizes.
406 @return bitmap of available ep0 maximum packet sizes.
408 inline TUint EndpointZeroMaxPacketSizes();
410 /** Requests that a maximum packet size of aMaxPacketSize be set on ep0.
412 @param aMaxPacketSize The maximum packet size.
414 @return KErrNone if successful.
416 inline TInt SetEndpointZeroMaxPacketSize(TInt aMaxPacketSize);
418 /** Queries the current maximum packet size on ep0.
420 @return The currently set maximum packet size on ep0.
422 inline TInt GetEndpointZeroMaxPacketSize();
424 /** Copies the current device descriptor into aDeviceDescriptor.
426 @param aDeviceDescriptor Receives the current device descriptor.
428 @return KErrNone if successful.
430 inline TInt GetDeviceDescriptor(TDes8& aDeviceDescriptor);
432 /** Sets the contents of aDeviceDescriptor to be the current device descriptor.
434 @param aDeviceDescriptor contains the device descriptor.
436 @return KErrNone if successful.
438 inline TInt SetDeviceDescriptor(const TDesC8& aDeviceDescriptor);
440 /** Gets the size of the current device descriptor. This is unlikely to be anything other than 9.
442 @param aSize receives the size of the current device descriptor.
444 @return KErrNone if successful.
446 inline TInt GetDeviceDescriptorSize(TInt& aSize);
448 /** Copies the current configuration descriptor into aConfigurationDescriptor.
450 @param aConfigurationDescriptor Receives the current configuration descriptor.
452 @return KErrNone if successful.
454 inline TInt GetConfigurationDescriptor(TDes8& aConfigurationDescriptor);
456 /** Sets the contents of aConfigurationDescriptor to be the current configuration descriptor.
458 @param aConfigurationDescriptor contains the configuration descriptor.
460 @return KErrNone if successful.
462 inline TInt SetConfigurationDescriptor(const TDesC8& aConfigurationDescriptor);
464 /** Gets the size of the current configuration descriptor.
466 @param aSize receives the size of the current configuration descriptor.
468 @return KErrNone if successful.
470 inline TInt GetConfigurationDescriptorSize(TInt& aSize);
472 /** Copies the interface descriptor into aInterfaceDescriptor for the interface with alternate
473 setting aSettingNumber, 0 for the main interface.
475 @param aSettingNumber Alternate setting number on the interface, 0 for the main interface.
476 @param aInterfaceDescriptor Receives the interface descriptor.
478 @return KErrNone if successful.
480 inline TInt GetInterfaceDescriptor(TInt aSettingNumber, TDes8& aInterfaceDescriptor);
482 /** Sets the interface descriptor contained in aInterfaceDescriptor for the interface with
483 alternate setting aSettingNumber, 0 for the main interface, for transmission to the host
486 @param aSettingNumber Alternate setting number on the interface, 0 for the main interface.
487 @param aInterfaceDescriptor Contains the interface descriptor to be set.
489 @return KErrNone if successful.
491 inline TInt SetInterfaceDescriptor(TInt aSettingNumber, const TDesC8& aInterfaceDescriptor);
493 /** Copies the size of the interface descriptor for the interface with alternate
494 setting aSettingNumber, 0 for the main interface, into aSize.
496 @param aSettingNumber The alternate setting.
497 @param aSize receives the size of the interface descriptor.
499 @return KErrNone if successful.
501 inline TInt GetInterfaceDescriptorSize(TInt aSettingNumber, TInt& aSize);
503 /** Copies the endpoint descriptor for logical endpoint number aEndpointNumber into aEndpointDescriptor
504 for the interface with alternate setting aSettingNumber, 0 for the main interface.
506 @param aSettingNumber Alternate setting number on the interface, 0 for the main interface.
507 @param aEndpointNumber.
508 @param aEndpointDescriptor Receives the endpoint descriptor.
510 @return KErrNone if successful.
512 inline TInt GetEndpointDescriptor(TInt aSettingNumber, TInt aEndpointNumber, TDes8& aEndpointDescriptor);
514 /** Sets the endpoint descriptor for logical endpoint number aEndpointNumber contained in
515 aEndpointDescriptor for the interface with alternate setting aSettingNumber, 0 for the main interface,
516 for transmission to the host during enumeration.
518 @param aSettingNumber Alternate setting number on the interface, 0 for the main interface.
519 @param aEndpointNumber Valid endpoint number on this interface.
520 @param aEndpointDescriptor Contains the endpoint descriptor to be set.
522 @return KErrNone if successful.
524 inline TInt SetEndpointDescriptor(TInt aSettingNumber, TInt aEndpointNumber,
525 const TDesC8& aEndpointDescriptor);
527 /** Copies the size of the endpoint descriptor for logical endpoint number aEndpointNumber for the
528 interface with alternate setting aSettingNumber, 0 for the main interface, into aSize.
530 @param aSettingNumber Alternate setting number on the interface, 0 for the main interface.
531 @param aEndpointNumber Valid endpoint number on this interface.
532 @param aSize receives the size of the endpoint descriptor.
534 @return KErrNone if successful.
536 inline TInt GetEndpointDescriptorSize(TInt aSettingNumber, TInt aEndpointNumber, TInt& aSize);
538 /** Get OTG descriptor size
540 @param aSize TInt reference which contains OTG descriptor size on return
542 inline void GetOtgDescriptorSize(TInt& aSize);
544 /** Get OTG descriptor of USB on-the-go feature
546 @param aOtgDesc User-side buffer to store copy of descriptor
548 @return KErrNone if successful
550 inline TInt GetOtgDescriptor(TDes8& aOtgDesc);
552 /** Set OTG descriptor by user to enable/disable USB on-the-go feature
554 @param aOtgDesc Descriptor buffer containing OTG features
556 @return KErrNone if successful
558 inline TInt SetOtgDescriptor(const TDesC8& aOtgDesc);
560 /** Copies the current device_qualifier descriptor into aDescriptor.
562 @param aDescriptor Receives the current device_qualifier descriptor.
564 @return KErrNone if successful.
566 inline TInt GetDeviceQualifierDescriptor(TDes8& aDescriptor);
568 /** Sets the device_qualifier descriptor to the contents of aDescriptor.
570 @param aDescriptor contains the new device_qualifier descriptor.
572 @return KErrNone if successful.
574 inline TInt SetDeviceQualifierDescriptor(const TDesC8& aDescriptor);
576 /** Copies the current other_speed_configuration descriptor into aDescriptor.
578 @param aDescriptor Receives the current other_speed_configuration descriptor.
580 @return KErrNone if successful.
582 inline TInt GetOtherSpeedConfigurationDescriptor(TDes8& aDescriptor);
584 /** Sets the other_speed_configuration descriptor to the contents of aDescriptor.
586 @param aDescriptor contains the new other_speed_configuration descriptor.
588 @return KErrNone if successful.
590 inline TInt SetOtherSpeedConfigurationDescriptor(const TDesC8& aDescriptor);
592 /** Copies the class specific interface descriptor block into aInterfaceDescriptor for the interface
593 with alternate setting aSettingNumber, 0 for the main interface.
595 @param aSettingNumber Alternate setting number on the interface, 0 for the main interface.
596 @param aInterfaceDescriptor Contains the interface descriptor to be set.
598 @return KErrNone if successful.
600 inline TInt GetCSInterfaceDescriptorBlock(TInt aSettingNumber, TDes8& aInterfaceDescriptor);
602 /** aSettingNumber is the alternate interface setting, 0 for the main interface, that the descriptor block
603 aDes should be attached to. aDes is a block of data containing at least one class specific descriptor
604 for transmission during enumeration after the class interface descriptor (or alternate interface
605 descriptor) has been sent, but before the endpoint descriptors belonging to this interface are sent.
606 aDes may contain as many descriptors as are necessary or only 1. SetCSInterfaceDescriptorBlock()
607 should be called at any time after SetInterface() has been called to establish a main interface or an
608 alternate interface. More than one call may be made - the data blocks will be concatenated prior to
609 sending. No checking or validation of the contents of aDes will be made and it is the caller's
610 responsibility to ensure that the data supplied is correct and appropriate to the interface identified
613 @param aSettingNumber Alternate setting number on the interface, 0 for the main interface.
614 @param aInterfaceDescriptor Contains the interface descriptor to be set.
616 @return KErrNone if successful.
618 inline TInt SetCSInterfaceDescriptorBlock(TInt aSettingNumber, const TDesC8& aInterfaceDescriptor);
620 /** Copies the size of the class specific interface descriptor block for the interface with alternate
621 setting aSettingNumber, 0 for the main interface, into aSize.
623 @param aSettingNumber The alternate setting number.
624 @param aSize receives the size of the interface descriptor.
626 @return KErrNone if successful.
628 inline TInt GetCSInterfaceDescriptorBlockSize(TInt aSettingNumber, TInt& aSize);
630 /** Copies the class specific endpoint descriptor for logical endpoint number aEndpointNumber
631 into aEndpointDescriptor for the interface with alternate setting aSettingNumber, 0 for the main
634 @param aSettingNumber Alternate setting number on the interface, 0 for the main interface.
635 @param aEndpointNumber Valid endpoint number on this interface.
636 @param aEndpointDescriptor Receives the endpoint descriptor.
638 @return KErrNone if successful.
640 inline TInt GetCSEndpointDescriptorBlock(TInt aSettingNumber, TInt aEndpointNumber,
641 TDes8& aEndpointDescriptor);
643 /** Sets the class specific endpoint descriptor for logical endpoint number aEndpointNumber contained in
644 aEndpointDescriptor for the interface with alternate setting aSettingNumber, 0 for the main interface,
645 for transmission to the host during enumeration.
647 @param aSettingNumber Alternate setting number on the interface, 0 for the main interface.
648 @param aEndpointNumber Valid endpoint number on this interface.
649 @param aEndpointDescriptor Contains the endpoint descriptor to be set.
651 @return KErrNone if successful.
653 inline TInt SetCSEndpointDescriptorBlock(TInt aSettingNumber, TInt aEndpointNumber,
654 const TDesC8& aEndpointDescriptor);
656 /** Copies the size of the class specific endpoint descriptor block for logical endpoint number
657 aEndpointNumber for the interface with alternate setting aSettingNumber, 0 for the main interface,
660 @param aSettingNumber Alternate setting number on the interface, 0 for the main interface.
661 @param aEndpointNumber Valid endpoint number on this interface.
662 @param aSize On return, contains the size of the class specific endpoint descriptor block.
664 @return KErrNone if successful.
666 inline TInt GetCSEndpointDescriptorBlockSize(TInt aSettingNumber, TInt aEndpointNumber, TInt& aSize);
668 /** Generates a Remote Wakeup bus condition
669 The capability of the device to generate Remote Wakeup signalling is enquired in
670 RDevUsbcClient::DeviceCaps.
672 @return KErrNone if this signalling is possible and the signal has been generated.
674 inline TInt SignalRemoteWakeup();
676 /** Simulates a physical removal of the USB cable by disabling the D+/- pull-ups.The iConnect member of
677 TUsbDeviceCapsV01, returned by RDevUsbcClient::DeviceCaps(), indicates whether this functionality is
680 @return KErrNone if successful.
682 inline TInt DeviceDisconnectFromHost();
684 /** Simulates a physical insertion of the USB cable by enabling the D+/- pull-ups.The iConnect member
685 of TUsbDeviceCapsV01, returned by RDevUsbcClient::DeviceCaps(), indicates whether this functionality
688 @return KErrNone if successful.
690 inline TInt DeviceConnectToHost();
692 /** Powers up the UDC and connects it to the bus if one or more interfaces exist.
694 @return KErrNone if UDC successfully powered up, KErrNotReady if no
695 interfaces have been registered yet, KErrHardwareNotAvailable if UDC
696 couldn't be activated.
698 inline TInt PowerUpUdc();
700 /** Enquires about the current operating speed of the UDC.
702 @return ETrue if the UDC is currently operating at High speed, EFalse otherwise.
704 inline TBool CurrentlyUsingHighSpeed();
706 /** Allocates the use of aResource to aEndpoint. it will be used from when the current bus transfer has been
709 @param aResource is typically some rationed hardware resource or possibly specifies a type of endpoint
710 behaviour. aResource is not a bitmap and TEndpointResource values should not be combined.
711 @param aEndpoint The endpoint number to which the resource is to be allocated.
713 @return KErrNone if successful, KErrInUse if the resource is already consumed and cannot be allocated,
714 KErrNotSupported if the endpoint does not support the resource requested.
716 @publishedPartner @deprecated
718 @see TUsbcEndpointInfo
720 inline TInt AllocateEndpointResource(TInt aEndpoint, TUsbcEndpointResource aResource);
722 /** Deallocates the use of aResource aEndpoint or ends a specified endpoint behaviour.
724 @param aResource is typically some rationed hardware resource or possibly specifies a type of endpoint
725 behaviour. aResource is not a bitmap and TEndpointResource values should not be combined.
726 @param aEndpoint The endpoint number from which the resource is to be removed.
728 @return KErrNone if the resource has been successfully deallocated, KErrNotSupported if the endpoint
729 does not support the resource requested.
731 @publishedPartner @deprecated
733 @see TUsbcEndpointInfo
735 inline TInt DeAllocateEndpointResource(TInt aEndpoint, TUsbcEndpointResource aResource);
737 /** Queries endpoint resource use.
739 @param aResource is typically some rationed hardware resource or possibly specifies a type of endpoint
740 behaviour. aResource is not a bitmap and TEndpointResource values should not be combined.
741 @param aEndpoint The endpoint number at which the resource is to be queried.
743 @return ETrue is the specified resource is in use at the endpoint and EFalse if not.
745 inline TBool QueryEndpointResourceUse(TInt aEndpoint, TUsbcEndpointResource aResource);
747 /** Request (i.e. claim for this channel) up to five endpoints and set the class type for this USB
748 interface. 'aInterfaceData' is a package buffer which describes the interface and all the endpoints
749 being requested by the driver for this interface.
751 @param aInterfaceNumber Distinguishes between alternate interfaces. If these are not be used then this
752 should always be zero. If this parameter is used, then its value must be one more than that of the
753 proceeding alternate interface.
754 @param aInterfaceData a package buffer which describes the interface and all the endpoints being
755 requested by the driver for this interface.
756 @param aBandwidthPriority is a bitmap combining the required IN and OUT priorities. Values are in the
757 range [0,3] from the lowest priority bandwidth, 0, to the highest 3 and are separately specified for
758 IN and OUT endpoints. Interfaces requiring higher bandwidth are allocated significantly more buffering
759 than low bandwidth interfaces. Interfaces should not be given a higher bandwidth priority than they
762 @return KErrInUse if any of the endpoints being requested have already been claimed by another channel
763 KErrNotSupported if an endpoint with all of the specified properties is not supported on this
764 platform. KErrNoMemory if insufficient memory is available to complete the operation.
766 inline TInt SetInterface(TInt aInterfaceNumber, TUsbcInterfaceInfoBuf& aInterfaceData,
767 TUint32 aBandwidthPriority =
768 (EUsbcBandwidthOUTDefault | EUsbcBandwidthINDefault));
770 /** Release an interface previously claimed by this channel. Alternate interfaces need to be released
771 in strict descending order, starting with the last (i.e. highest numbered) one.
772 It is not necessary to release an interface that wasn't successfully requested.
774 @param aInterfaceNumber Specifies the alternate setting number 'aInterfaceNum' of the interface to be
777 @return KErrNone if successful. KErrArgument if the alternate setting doesn't exist or is released out
780 inline TInt ReleaseInterface(TInt aInterfaceNumber);
782 /** Copies the current string descriptor language ID (LANGID) code into the aLangId argument. Even though
783 the USB spec allows for the existence of a whole array of LANGID codes, we only support one.
785 @param aLangId receives the LANGID code.
787 @return KErrNone if successful, KErrArgument if problem with argument (memory cannot be written to, etc.).
789 inline TInt GetStringDescriptorLangId(TUint16& aLangId);
791 /** Sets the string descriptor language ID (LANGID). Even though the USB spec allows for the existence of
792 a whole array of LANGID codes, we only support one.
794 @param aLangId the LANGID code to be set.
796 @return KErrNone if successful.
798 inline TInt SetStringDescriptorLangId(TUint16 aLangId);
800 /** Copies the string descriptor identified by the iManufacturer index field of the Standard Device
801 Descriptor into the aString argument.
803 @param aString receives manufacturer string.
805 @return KErrNone if successful, KErrArgument if MaxLength of aString is too small to hold the entire
806 descriptor, KErrNotFound if the string descriptor couldn't be found.
808 inline TInt GetManufacturerStringDescriptor(TDes16& aString);
810 /** Sets the string descriptor identified by the iManufacturer index field of the Standard Device
811 Descriptor to the aString argument.
813 @param aString Contains the new manufacturer string descriptor.
815 @return KErrNone if successful, KErrNoMemory if no memory is available to store the new string from
816 aString (in which case the old string descriptor will be preserved).
818 inline TInt SetManufacturerStringDescriptor(const TDesC16& aString);
820 /** Removes (deletes) the string descriptor identified by the iManufacturer index field of the Standard
821 Device Descriptor and sets that field to zero.
823 @return KErrNone if successful, KErrNotFound if the string descriptor couldn't be found.
825 inline TInt RemoveManufacturerStringDescriptor();
827 /** Retrieves the string descriptor identified by the iProduct index field of the Standard Device
828 Descriptor into the aString argument.
830 @param aString receives product string.
832 @return KErrNone if successful, KErrArgument if MaxLength of aString is too small to hold the entire
833 descriptor, KErrNotFound if the string descriptor couldn't be found.
835 inline TInt GetProductStringDescriptor(TDes16& aString);
837 /** Sets the string descriptor identified by the iProduct index field of the Standard Device Descriptor to
838 the aString argument.
840 @param aString Contains the new product string descriptor.
842 @return KErrNone if successful, KErrNoMemory if no memory is available to store the new string from
843 aString (in which case the old string descriptor will be preserved).
845 inline TInt SetProductStringDescriptor(const TDesC16& aString);
847 /** Removes (deletes) the string descriptor identified by the iProduct index field of the Standard Device
848 Descriptor and sets that field to zero.
850 @return KErrNone if successful, KErrNotFound if the string descriptor couldn't be found.
852 inline TInt RemoveProductStringDescriptor();
854 /** Retrieves the string descriptor identified by the iSerialNumber index field of the Standard Device
855 Descriptor into the aString argument.
857 @param aString receives product string.
859 @return KErrNone if successful, KErrArgument if MaxLength of aString is too small to hold the entire
860 descriptor, KErrNotFound if the string descriptor couldn't be found.
862 inline TInt GetSerialNumberStringDescriptor(TDes16& aString);
864 /** Sets the string descriptor identified by the iSerialNumber index field of the Standard Device
865 Descriptor to the aString argument.
867 @param aString Contains the new serial number string descriptor.
869 @return KErrNone if successful, KErrNoMemory if no memory is available to store the new string from
870 aString (in which case the old string descriptor will be preserved).
872 inline TInt SetSerialNumberStringDescriptor(const TDesC16& aString);
874 /** Removes (deletes) the string descriptor identified by the iSerialNumber index field of the Standard
875 Device Descriptor and sets that field to zero.
877 @return KErrNone if successful, KErrNotFound if the string descriptor couldn't be found.
879 inline TInt RemoveSerialNumberStringDescriptor();
881 /** Retrieves the string descriptor identified by the iConfiguration index field of the (first) Standard
882 Configuration Descriptor into the aString argument.
884 @param aString receives configuration string.
886 @return KErrNone if successful, KErrArgument if MaxLength of aString is too small to hold the entire
887 descriptor, KErrNotFound if the string descriptor couldn't be found.
889 inline TInt GetConfigurationStringDescriptor(TDes16& aString);
891 /** Sets the string descriptor identified by the iConfiguration index field of the Standard Configuration
892 Descriptor to the aString argument.
894 @param aString Contains the new serial number string descriptor.
896 @return KErrNone if successful, KErrNoMemory if no memory is available to store the new string from
897 aString (in which case the old string descriptor will be preserved).
899 inline TInt SetConfigurationStringDescriptor(const TDesC16& aString);
901 /** Removes (deletes) the string descriptor identified by the iConfiguration index field of the Standard
902 Configuration Descriptor and sets that field to zero.
904 @return KErrNone if successful, KErrNotFound if the string descriptor couldn't be found.
906 inline TInt RemoveConfigurationStringDescriptor();
908 /** Copies the string of the USB string descriptor at the specified index in the string descriptor array
909 into the aString argument.
911 Although this function can also be used for it, for querying most standard string descriptors
912 there exists a set of dedicated access functions.
914 @see RDevUsbcClient::GetStringDescriptorLangId
915 @see RDevUsbcClient::GetManufacturerStringDescriptor
916 @see RDevUsbcClient::GetProductStringDescriptor
917 @see RDevUsbcClient::GetSerialNumberStringDescriptor
918 @see RDevUsbcClient::GetConfigurationStringDescriptor
920 @param aIndex The position of the string descriptor in the string descriptor array.
921 @param aString The target location for the string descriptor copy.
923 @return KErrNone if successful, KErrNotFound if no string descriptor exists at the specified index,
924 KErrArgument if MaxLength() of aString is too small to hold the entire descriptor.
926 inline TInt GetStringDescriptor(TUint8 aIndex, TDes16& aString);
928 /** Sets the aString argument to be the string of a USB string descriptor at the specified index in the
929 string descriptor array. If a string descriptor already exists at that position then its string will
932 Care should be taken, when choosing aIndex, not to inadvertently overwrite one of the standard
933 string descriptors. For their manipulation there exists a set of dedicated access functions.
935 @see RDevUsbcClient::SetStringDescriptorLangId
936 @see RDevUsbcClient::SetManufacturerStringDescriptor
937 @see RDevUsbcClient::SetProductStringDescriptor
938 @see RDevUsbcClient::SetSerialNumberStringDescriptor
939 @see RDevUsbcClient::SetConfigurationStringDescriptor
941 @param aIndex The position of the string descriptor in the string descriptor array.
942 @param aString Contains the string descriptor to be set.
944 @return KErrNone if successful, KErrArgument if aIndex is invalid, KErrNoMemory if no memory
945 is available to store the new string (an existing descriptor at that index will be preserved).
947 inline TInt SetStringDescriptor(TUint8 aIndex, const TDesC16& aString);
949 /** Removes (deletes) the USB string descriptor at the specified index in the string descriptor array.
950 The position in the array of other string descriptors is not affected.
952 Care should be taken, when choosing aIndex, not to inadvertently delete a standard string descriptor
953 (also because index references from non-string descriptors would be invalidated). For the deletion
954 of most standard string descriptors there exists a set of dedicated functions.
956 @see RDevUsbcClient::RemoveManufacturerStringDescriptor
957 @see RDevUsbcClient::RemoveProductStringDescriptor
958 @see RDevUsbcClient::RemoveSerialNumberStringDescriptor
959 @see RDevUsbcClient::RemoveConfigurationStringDescriptor
961 @param aIndex The position of the string descriptor in the string descriptor array.
963 @return KErrNone if successful, KErrNotFound if no string descriptor exists at the specified index.
965 inline TInt RemoveStringDescriptor(TUint8 aIndex);
967 /** Asynchronously read data from endpoint 'aEndpoint' into the descriptor 'aDes'.
968 Request completes when the specified number of bytes is received, length taken from max. length of
971 @param aStatus The request status.
972 @param aEndpoint The endpoint number to read from.
973 @param aDes Descriptor to receive the data.
975 inline void Read(TRequestStatus& aStatus, TEndpointNumber aEndpoint, TDes8& aDes);
977 /** Asynchronously read data from endpoint 'aEndpoint' into the descriptor 'aDes'.
978 Request completes when the specified number of bytes is received.
980 @param aStatus The request status.
981 @param aEndpoint The endpoint number to read from.
982 @param aDes Descriptor to receive the data.
983 @param aLen The number of bytes to read.
985 inline void Read(TRequestStatus& aStatus, TEndpointNumber aEndpoint, TDes8& aDes, TInt aLen);
987 /** Asynchronously read an entire packet of data from endpoint 'aEndpoint' into the descriptor 'aDes'.
988 If a packet has previously been partly read. then only the remainder of the packet will be returned.
989 The request should be for the maximum packet size of the endpoint. If less data is requested, then
990 after this read completes the remainder of the data in the packet will be discarded and the next read
991 will start from the next available packet.
992 Request completes when either a complete packet is received or the length of the packet currently
993 being received exceeds 'aMaxLen'.
995 @param aStatus The request status.
996 @param aEndpoint The endpoint number to read from.
997 @param aDes Descriptor to receive the data.
1000 inline void ReadPacket(TRequestStatus& aStatus, TEndpointNumber aEndpoint, TDes8& aDes, TInt aMaxLen);
1002 /** Asynchronously read data from endpoint 'aEndpoint' into the descriptor 'aDes'.
1003 Request completes when the specified number of bytes is received (in first version,
1004 length taken from max. length of descriptor).
1006 @param aStatus The request status.
1007 @param aEndpoint The endpoint number to read from.
1008 @param aDes Descriptor to receive the data.
1010 inline void ReadUntilShort(TRequestStatus& aStatus, TEndpointNumber aEndpoint, TDes8& aDes);
1012 /** Asynchronously read data from endpoint 'aEndpoint' into the descriptor 'aDes'.
1013 Request completes when the specified number of bytes is received (in first version,
1014 length taken from max. length of descriptor).
1016 @param aStatus The request status.
1017 @param aEndpoint The endpoint number to read from.
1018 @param aDes Descriptor to receive the data.
1019 @param aLen The number of bytes to receive.
1021 inline void ReadUntilShort(TRequestStatus& aStatus, TEndpointNumber aEndpoint, TDes8& aDes, TInt aLen);
1023 /** Asynchronously read data from endpoint 'aEndpoint' into the descriptor 'aDes'. The request completes
1024 when the specified number of bytes is received, length taken from max. length of descriptor or a
1025 packet whose size is smaller than the endpoint's maximum packet size is received.
1027 @param aStatus The request status.
1028 @param aEndpoint The endpoint number to read from.
1029 @param aDes Descriptor to receive the data.
1031 inline void ReadOneOrMore(TRequestStatus& aStatus, TEndpointNumber aEndpoint, TDes8& aDes);
1033 /** Asynchronously read data from endpoint 'aEndpoint' into the descriptor 'aDes'. The request completes
1034 when the specified number of bytes is received, or a packet whose size is smaller than the endpoint's
1035 maximum packet size is received.
1037 @param aStatus The request status.
1038 @param aEndpoint The endpoint number to read from.
1039 @param aDes Descriptor to receive the data.
1040 @param aLen The number of bytes to receive.
1042 inline void ReadOneOrMore(TRequestStatus& aStatus, TEndpointNumber aEndpoint, TDes8& aDes, TInt aLen);
1044 /** Cancels an outstanding read request. The request will complete with whatever data is available.
1046 inline void ReadCancel(TEndpointNumber aEndpoint);
1048 /** Asynchronously write 'aLen' bytes of data to endpoint 'aEndpoint' from descriptor 'aDes'. 'aZlpRequired'
1049 (optional) signals that ZLP termination may be required.
1051 @param aStatus The request status.
1052 @param aEndpoint The endpoint number to write to.
1053 @param aDes Descriptor to provide the data.
1054 @param aLen The number of bytes of data to be written.
1055 @param aZlpRequired True, if ZLP termination is required; false, otherwise.
1057 inline void Write(TRequestStatus& aStatus, TEndpointNumber aEndpoint, const TDesC8& aDes, TInt aLen,
1058 TBool aZlpRequired=EFalse);
1060 /** Cancels an outstanding write request on endpoint aEndpoint.
1062 @param aEndpoint The endpoint number whose write is to be cancelled.
1064 inline void WriteCancel(TEndpointNumber aEndpoint);
1066 /** Cancels any transfer on any endpoint specified in aEndpointMask.
1069 // Cancel transfer requests on endpoints 1, 2 & 3
1070 usbPort.EndpointTransferCancel(KUsbcEndpoint1Bit | KUsbcEndpoint2Bit | KUsbcEndpoint3Bit);
1073 @param aEndpointMask bitmap of the endpoints.
1075 inline void EndpointTransferCancel(TUint aEndpointMask);
1077 /** Register for notification when a change of the Interface alternate setting or the USB Controller's
1078 current state occurs. When the alternate setting or the Controller state changes, then the
1079 asynchronous function completes and the current alternate setting number or Controller state is
1080 written back to aValue. If the KUsbAlternateSetting bit is set then the remaining bits are the
1081 alternate setting number. Otherwise aValue is interpreted as a TUsbcDeviceState.
1083 @see TUsbcDeviceState
1085 @param aStatus The request status.
1086 @param aValue Receives the alternate setting number or Controller state.
1088 inline void AlternateDeviceStatusNotify(TRequestStatus& aStatus, TUint& aValue);
1090 /** Completes an AlternateDeviceStatusNotify request. If a request has previously been made then the
1091 status variable is updated with the current device state.
1093 inline void AlternateDeviceStatusNotifyCancel();
1095 /** If the channel has changed the grouping of endpoints between interfaces or changed the interface class
1096 type from the defaults then it is necessary to force a re-enumeration. This will typically involve the
1097 Symbian OS device initiating a disconnection and re-connection. This is an asynchronous operation
1098 which will complete when the Controller is successfully configured by the host, i.e. has achieved
1099 EUsbcDeviceStateConfigured. Since it is not known if the operation has failed, at the same time that
1100 a ReEnumerate request is made, a timer should be set up to complete after approximately 5 seconds. It
1101 can be assumed that if the operation has not completed after this time interval then it will not
1104 @param aStatus The request status.
1106 inline void ReEnumerate(TRequestStatus& aStatus);
1108 /** Cancels an outstanding ReEnumerate() request.
1110 inline void ReEnumerateCancel();
1112 /** Register for notification when a change in stall status of any of the interface's endpoints occurs,
1113 but not ep0. When a change in stall status occurs, then the asynchronous function completes and the
1114 current stall state is written back to 'aEndpointStatus' as a bit map: Only stall state changes caused
1115 by SET_FEATURE and CLEAR_FEATURE standard commands on ep0 will be notified when this function
1116 completes. After this request completes the request should be re-issued to obtain future
1119 @param aStatus The request status.
1120 @param aEndpointMask a bitmap of the endpoints stall status. This is filled in when the call completes
1121 bit 1 represents the interface's virtual endpoint 1, (KUsbcEndpoint1Bit)
1122 bit 2 represents the interface's virtual endpoint 2, (KUsbcEndpoint2Bit) etc.
1123 bit value 0 - not stalled,
1124 bit value 1 - stalled.
1126 inline void EndpointStatusNotify(TRequestStatus& aStatus, TUint& aEndpointMask);
1128 /** Completes an endpoint status notify request.
1130 inline void EndpointStatusNotifyCancel();
1132 /** Get current on-the-go features relating to the ability of device/host pair to
1133 perform OTG role swap.
1135 @param aFeatures On return it contanis features the device currently has
1136 bit 2 represents b_hnp_enable, (KUsbOtgAttr_B_HnpEnable)
1137 bit 3 represents a_hnp_support, (KUsbOtgAttr_A_HnpSupport)
1138 bit 4 represents a_alt_hnp_support, (KUsbOtgAttr_A_AltHnpSupport)
1139 @return KErrNone if successful, KErrNotSupported if OTG is not supported by
1140 this device, otherwise system-wide error returns
1142 inline TInt GetOtgFeatures(TUint8& aFeatures);
1144 /** Register for notification on USB on-the-go features' change. If any OTG feature
1145 is changed, request completes and current feature value is filled in aValue.
1147 @param aStatus Request status object
1148 @param aValue On request completion, it contains current OTG feature value
1150 inline void OtgFeaturesNotify(TRequestStatus& aStatus, TUint8& aValue);
1152 /** Cancel pending OTG feature request.
1154 inline void OtgFeaturesNotifyCancel();
1156 #endif // #ifndef __KERNEL_MODE__
1160 #include <d32usbc.inl>
1163 #endif // __D32USBC_H__