|
1 /* |
|
2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "RequestHeader.h" |
|
19 |
|
20 const TDesC8& TUsbRequestHdr::Des() |
|
21 /** |
|
22 * This function packs the TUsbRequestHdr class into a descriptor with the |
|
23 * correct byte alignment for transmission on the USB bus. |
|
24 * |
|
25 * @return Correctly-aligned buffer. NB The buffer returned is a member of |
|
26 * this class and has the same lifetime. |
|
27 */ |
|
28 { |
|
29 iBuffer.SetLength(KUsbRequestHdrSize); |
|
30 |
|
31 iBuffer[0] = iRequestType; |
|
32 iBuffer[1] = iRequest; |
|
33 iBuffer[2] = static_cast<TUint8>(iValue & 0x00ff); |
|
34 iBuffer[3] = static_cast<TUint8>((iValue & 0xff00) >> 8); |
|
35 iBuffer[4] = static_cast<TUint8>(iIndex & 0x00ff); |
|
36 iBuffer[5] = static_cast<TUint8>((iIndex & 0xff00) >> 8); |
|
37 iBuffer[6] = static_cast<TUint8>(iLength & 0x00ff); |
|
38 iBuffer[7] = static_cast<TUint8>((iLength & 0xff00) >> 8); |
|
39 |
|
40 return iBuffer; |
|
41 } |
|
42 |
|
43 TInt TUsbRequestHdr::Decode(const TDesC8& aBuffer, TUsbRequestHdr& aTarget) |
|
44 /** |
|
45 * This function unpacks into the TUsbRequestHdr class from a descriptor with |
|
46 * the alignment that would be introduced on the USB bus. |
|
47 * |
|
48 * @param aBuffer Input buffer |
|
49 * @param aTarget Unpacked header. |
|
50 * @return Error. |
|
51 */ |
|
52 { |
|
53 if (aBuffer.Length() < static_cast<TInt>(KUsbRequestHdrSize)) |
|
54 return KErrGeneral; |
|
55 |
|
56 aTarget.iRequestType = aBuffer[0]; |
|
57 aTarget.iRequest = aBuffer[1]; |
|
58 aTarget.iValue = static_cast<TUint16>(aBuffer[2] + (aBuffer[3] << 8)); |
|
59 aTarget.iIndex = static_cast<TUint16>(aBuffer[4] + (aBuffer[5] << 8)); |
|
60 aTarget.iLength = static_cast<TUint16>(aBuffer[6] + (aBuffer[7] << 8)); |
|
61 return KErrNone; |
|
62 } |
|
63 |
|
64 TBool TUsbRequestHdr::IsDataResponseRequired() const |
|
65 /** |
|
66 * This function determines whether data is required by the host in response |
|
67 * to a message header. |
|
68 * @return TBool Flag indicating whether a data response required. |
|
69 */ |
|
70 { |
|
71 return (iRequestType & 0x80) ? ETrue : EFalse; |
|
72 } |
|
73 |
|
74 // |
|
75 // End of file |