|
1 // Copyright (c) 2000-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 // |
|
15 |
|
16 #include <btsdp.h> |
|
17 #include "reqhandler.h" |
|
18 #include "pduhandler.h" |
|
19 #include "DataEncoder.h" |
|
20 #include "sdpconsts.h" |
|
21 |
|
22 |
|
23 CSdpSearchPattern* CSdpPDUHandler::UUIDListLC(const TDesC8& aPdu, const TInt aNextSize, TInt& aLen, TInt& aRem, TInt& aCount) |
|
24 /** |
|
25 Unpack UUID list from request PDU and extracts a 16 bit value following. |
|
26 Parameter format is |
|
27 @verbatim |
|
28 Search UUID list descriptor DesC |
|
29 Next chunk size TInt (but always 2) |
|
30 Descriptor length returned TInt |
|
31 Remaining length returned TInt |
|
32 Next 2 bytes are returned as TInt |
|
33 @endverbatim |
|
34 |
|
35 Method will leave if there are parsing problems, or the remaining |
|
36 PDU is smaller than next size. |
|
37 Returns : |
|
38 @verbatim |
|
39 UUID list CSdpSearchPattern object |
|
40 total byte length TInt |
|
41 number of bytes unparsed TInt |
|
42 the 16 bit value extracted TInt |
|
43 @endverbatim |
|
44 |
|
45 **/ |
|
46 { |
|
47 CSdpSearchPattern* pattern = CSdpSearchPattern::NewL(); |
|
48 CleanupStack::PushL(pattern); |
|
49 |
|
50 CElementParser* parser = CElementParser::NewL(pattern); |
|
51 CleanupStack::PushL(parser); |
|
52 |
|
53 aLen = aPdu.Length(); |
|
54 aRem = parser->ParseElementsL(aPdu); |
|
55 CleanupStack::PopAndDestroy(/*parser*/); |
|
56 |
|
57 if (aRem < aNextSize) |
|
58 { |
|
59 User::Leave(KErrArgument); |
|
60 } |
|
61 aCount = BigEndian::Get16(&aPdu[aLen-aRem]); |
|
62 aRem -= aNextSize; |
|
63 return pattern; |
|
64 } |
|
65 |
|
66 |
|
67 |
|
68 CSdpAttrIdMatchList* CSdpPDUHandler::AttrListLC(const TDesC8& aPdu, TInt& aRem) |
|
69 /** |
|
70 Unpack attribute/range list from request PDU. |
|
71 Parameter format is |
|
72 @verbatim |
|
73 Search attrib list descriptor DesC |
|
74 Remaining length returned TInt |
|
75 @endverbatim |
|
76 |
|
77 Method will leave if the remaining PDU is smaller than next size. |
|
78 Returns : |
|
79 @verbatim |
|
80 the attribute list CSdpAttrIdMatchList object |
|
81 number of bytes unparsed TInt. |
|
82 @endverbatim |
|
83 |
|
84 |
|
85 **/ |
|
86 { |
|
87 CSdpAttrIdMatchList* attributeMatchList = CSdpAttrIdMatchList::NewL(); |
|
88 CleanupStack::PushL(attributeMatchList); |
|
89 |
|
90 CElementParser* parser = CElementParser::NewL(attributeMatchList); |
|
91 CleanupStack::PushL(parser); |
|
92 |
|
93 aRem = parser->ParseElementsL(aPdu); |
|
94 CleanupStack::PopAndDestroy(/*parser*/); |
|
95 return attributeMatchList; |
|
96 |
|
97 } |
|
98 |
|
99 |
|
100 TBool CSdpPDUHandler::ContinuationL(const TDesC8& aPdu, const TInt aLen, const TInt aRem) |
|
101 /** |
|
102 Check the continuation. This code will change |
|
103 @verbatim |
|
104 Current request descriptor DesC |
|
105 Current request length TInt |
|
106 Unparsed length TInt |
|
107 @endverbatim |
|
108 |
|
109 Method will leave if the remaining PDU is smaller than any continuation |
|
110 Returns : |
|
111 @verbatim |
|
112 dummy continuation length TInt. |
|
113 |
|
114 @endverbatim |
|
115 **/ |
|
116 { |
|
117 if (aRem < KContStateHeader || |
|
118 aPdu[aLen-aRem] > KSdpContinuationStateLength || |
|
119 aPdu[aLen-aRem] + KContStateHeader != aRem) |
|
120 { |
|
121 User::Leave(KErrArgument); |
|
122 } |
|
123 TPtrC8 contState = aPdu.Right(aRem-KContStateHeader); |
|
124 if(contState.Length() != 0) |
|
125 { |
|
126 if(contState.Length() != KSdpContinuationStateLength) |
|
127 { |
|
128 User::Leave(KErrUnknown); // Causes "Bad cont State" error |
|
129 } |
|
130 iContinuation = BigEndian::Get32(&contState[KContContOff]); |
|
131 iLength = BigEndian::Get32(&contState[KContTotOff]); |
|
132 iCRC = BigEndian::Get16(&contState[KContCrcOff]); |
|
133 if (iLength < iContinuation) |
|
134 { |
|
135 User::Leave(KErrUnknown); // Causes "Bad cont State" error |
|
136 } |
|
137 return ETrue; // we have a continuation situation |
|
138 } |
|
139 return 0; |
|
140 } |
|
141 |
|
142 |
|
143 void CSdpPDUHandler::CompleteOPL(TDes8& aPdu, const TDesC8& aWritePdu, const TInt aMaxAttrCount) |
|
144 /** |
|
145 Verifies the size of the response parameters |
|
146 and writes out correct length for the attributes. |
|
147 @verbatim |
|
148 response descriptor DesC |
|
149 written area (attributes) DesC |
|
150 maximum byte count TInt |
|
151 @endverbatim |
|
152 |
|
153 Method will leave if response is bigger than requested or allowed for. |
|
154 Returns nothing |
|
155 |
|
156 **/ |
|
157 { |
|
158 TUint16 finalLength = (TUint16)aWritePdu.Length(); |
|
159 if (finalLength > aMaxAttrCount) User::Leave(KErrNoMemory); |
|
160 aPdu.SetLength(KRspAttributeCountSize + finalLength + KContStateHeader); |
|
161 BigEndian::Put16(&aPdu[KRspAttrCountOffset], finalLength); |
|
162 // now need to update the DES size |
|
163 if (iDesSize == 3) |
|
164 { |
|
165 BigEndian::Put16(&aPdu[KRspAttributeListOffset+1], (unsigned short)(finalLength-iDesSize)); |
|
166 } |
|
167 else if (iDesSize == 2) |
|
168 { |
|
169 if (finalLength > 0xff) User::Leave(KErrNoMemory); |
|
170 aPdu[KRspAttributeListOffset+1] = (unsigned char)((finalLength&0xff)-iDesSize); |
|
171 } |
|
172 else User::Leave(KErrUnknown); // perhaps this should be a panic |
|
173 aPdu[aPdu.Length()-1] = 0; // FIXME: Put contState here |
|
174 } |
|
175 |
|
176 TUint32 CSdpPDUHandler::ContinuationOffset() |
|
177 { |
|
178 return iContinuation; |
|
179 } |
|
180 |
|
181 TUint32 CSdpPDUHandler::FullLength() |
|
182 { |
|
183 return iLength; |
|
184 } |
|
185 |
|
186 TUint16 CSdpPDUHandler::ReqCRC() |
|
187 { |
|
188 return iCRC; |
|
189 } |
|
190 |
|
191 // specific test for DES headers only |
|
192 TInt CSdpPDUHandler::DesSize(TUint aDataSize) |
|
193 { |
|
194 TInt lDesSize; |
|
195 lDesSize = (aDataSize > KMaxTwoByteDESSize) ? KThreeByteDESSize : KTwoByteDESSize; |
|
196 lDesSize = (aDataSize > KMaxThreeByteDESSize) ? KFiveByteDESSize : lDesSize; |
|
197 return lDesSize; |
|
198 } |
|
199 |