|
1 // Copyright (c) 2003-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 "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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // avdtpMediaMultiplexing.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalTechnology |
|
21 */ |
|
22 |
|
23 #include <bluetoothav.h> |
|
24 #include "gavdpinterface.h" |
|
25 |
|
26 |
|
27 EXPORT_C void TAvdtpMultiplexingCapability::Parse(const TDesC8& aPtr) |
|
28 { |
|
29 // The following code uses a TUint8* as a TTSID* and TTCID*. If the |
|
30 // size of either of these were to change (they are currently defined |
|
31 // as TUint8) this could cause alignment errors on hardware. |
|
32 __ASSERT_COMPILE(sizeof(TTSID) == 1); |
|
33 __ASSERT_COMPILE(sizeof(TTCID) == 1); |
|
34 |
|
35 // Maxlength of iCID's iSID's plus 1 for iFrag and 1 for array size/last element adjustment |
|
36 TInt maxLength = iSIDs.Count()+iCIDs.Count()+2; |
|
37 __ASSERT_DEBUG(aPtr.Length()>2 && aPtr.Length()<maxLength, Panic(EInvalidCapabilityDataLength)); // the parse broke if this is less than 3, |
|
38 // but if there are 8 or more bytes we could overflow the iSIDs & iCIDs arrays. |
|
39 static const TUint8 KFragOffset = 7; |
|
40 iFrag = static_cast<TBool>(aPtr[0]>>KFragOffset); |
|
41 |
|
42 // parsing here means we have to leave it up to the user of this class |
|
43 // to have found configuration before determining semantics of the array |
|
44 // of IDs, the air configuration alone is *impossible* to tell what the |
|
45 // second entry is (either reporting or recovery) |
|
46 TInt arrayIndex=0; |
|
47 for (TInt packetIndex=1; packetIndex<=aPtr.Length()-sizeof(TTCID); packetIndex+=sizeof(TTSID)+sizeof(TTCID)) |
|
48 { |
|
49 iSIDs[arrayIndex] = *static_cast<const TTSID*>(aPtr.Mid(packetIndex, sizeof(TTSID)).Ptr()); |
|
50 iCIDs[arrayIndex] = *static_cast<const TTCID*>(aPtr.Mid(packetIndex+sizeof(TTSID), sizeof(TTCID)).Ptr()); |
|
51 arrayIndex++; |
|
52 } |
|
53 } |
|
54 |
|
55 EXPORT_C /*virtual*/ TInt TAvdtpMultiplexingCapability::AsProtocol(RBuf8& aBuffer) const |
|
56 { |
|
57 TInt losc = 3; // min - frag octet + media ids |
|
58 |
|
59 __ASSERT_DEBUG(iCIDs[0]!=KInvalidTCID && iSIDs[0]!=KInvalidTSID, /*Panic(EAVDTPBadMuxConfiguration)*/User::Invariant()); |
|
60 |
|
61 // tsid and tcid must either both be valid or not |
|
62 __ASSERT_DEBUG((iCIDs[1]!=KInvalidTCID && iSIDs[1]!=KInvalidTSID) || |
|
63 (iCIDs[1]==KInvalidTCID && iSIDs[1]==KInvalidTSID), /*Panic(EAVDTPBadMuxConfiguration)*/User::Invariant()); |
|
64 |
|
65 // tsid and tcid must either both be valid or not |
|
66 __ASSERT_DEBUG((iCIDs[2]!=KInvalidTCID && iSIDs[2]!=KInvalidTSID) || |
|
67 (iCIDs[2]==KInvalidTCID && iSIDs[2]==KInvalidTSID), /*Panic(EAVDTPBadMuxConfiguration)*/User::Invariant()); |
|
68 |
|
69 // check to see how many entries will be made - can just use say CID to test |
|
70 if (iCIDs[1]!=KInvalidTCID) |
|
71 { |
|
72 losc+=2; |
|
73 } |
|
74 |
|
75 if (iCIDs[2]!=KInvalidTCID) |
|
76 { |
|
77 losc+=2; |
|
78 } |
|
79 |
|
80 // set LOSC for building header |
|
81 iLOSC=losc; |
|
82 TInt ret = AddHeader(aBuffer); |
|
83 |
|
84 if (ret==KErrNone) |
|
85 { |
|
86 aBuffer.Append(iFrag ? 0x80 : 0x00); |
|
87 |
|
88 //only append in set ones - must always have media |
|
89 for (TInt arrayIndex=0; arrayIndex<=iCIDs.Count()-1; arrayIndex++) |
|
90 { |
|
91 // test either CID, or SID for whether to put in capability |
|
92 if (iCIDs[arrayIndex]!=KInvalidTCID) |
|
93 { |
|
94 aBuffer.Append(reinterpret_cast<const TUint8*>(&iSIDs[arrayIndex]),sizeof(TTSID)); |
|
95 aBuffer.Append(reinterpret_cast<const TUint8*>(&iCIDs[arrayIndex]),sizeof(TTCID)); |
|
96 } |
|
97 } |
|
98 } |
|
99 |
|
100 return ret; |
|
101 } |
|
102 |
|
103 |
|
104 EXPORT_C void TAvdtpMultiplexingCapability::Reset() |
|
105 { |
|
106 for (TInt arrayIndex=0; arrayIndex<=iCIDs.Count()-1; arrayIndex++) |
|
107 { |
|
108 iSIDs[arrayIndex] = KInvalidTSID; |
|
109 iCIDs[arrayIndex] = KInvalidTCID; |
|
110 } |
|
111 } |
|
112 |
|
113 |