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