|
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 <e32math.h> |
|
17 #include <utf.h> |
|
18 #include <es_sock.h> |
|
19 #include <bt_sock.h> |
|
20 #include <btsdp.h> |
|
21 #include "ipcinternals.h" |
|
22 #include "sdpkey.h" |
|
23 #include "sdputil.h" |
|
24 #include "SDPDatabase.h" |
|
25 #include "DataEncoder.h" |
|
26 #include "SDPAttribute.h" |
|
27 #include "EncoderVisitor.h" |
|
28 #include "ExtractorVisitor.h" |
|
29 #include "agtypes.h" |
|
30 #include "agutil.h" |
|
31 #include "ProtocolWrapper.h" |
|
32 |
|
33 |
|
34 |
|
35 /************************************************************************/ |
|
36 // |
|
37 // SDP agent client API |
|
38 // (only exists as an exported API for porting purposes) |
|
39 // |
|
40 /************************************************************************/ |
|
41 |
|
42 |
|
43 RSdpAgent::RSdpAgent() |
|
44 :iRequestBuf(0), iResultSize(0) |
|
45 /** |
|
46 Constructer: |
|
47 Set the HBufC pointer iRequestBuf to NULL (This is an 'R' class). |
|
48 Set the TPckg iResultSize to package nothing. |
|
49 **/ |
|
50 { |
|
51 } |
|
52 |
|
53 TInt RSdpAgent::Open(RSdpSession& aSession) |
|
54 /** |
|
55 Open a NetDatabase session on ESock using SDP over Bluetooth. |
|
56 **/ |
|
57 { |
|
58 return iNetDb.Open(aSession,KBTAddrFamily,KSDP); |
|
59 } |
|
60 |
|
61 void RSdpAgent::Close() |
|
62 /** |
|
63 Free iRequestBuf. |
|
64 Close RNetDatabase. |
|
65 **/ |
|
66 { |
|
67 delete iRequestBuf; |
|
68 iRequestBuf = 0; |
|
69 iNetDb.Close(); |
|
70 } |
|
71 |
|
72 TBool RSdpAgent::IsOpen() |
|
73 { |
|
74 return iNetDb.SubSessionHandle()==0?EFalse:ETrue; |
|
75 } |
|
76 |
|
77 void RSdpAgent::Connect(TBTDevAddr aRemoteAddr, TRequestStatus& aStatus) |
|
78 /** |
|
79 Ask to connect to remote device. |
|
80 **/ |
|
81 { |
|
82 TSDPConnectQuery connQ; |
|
83 |
|
84 connQ.iQueryType = KSDPConnectQuery; |
|
85 connQ.iAddr = aRemoteAddr; |
|
86 |
|
87 iResultSize.Set(0,0,0); |
|
88 iConnectBuf = connQ; |
|
89 iNetDb.Query(iConnectBuf, iResultSize, aStatus); |
|
90 } |
|
91 |
|
92 void RSdpAgent::SdpSearchRequestL(TInt& aResultSize, |
|
93 CSdpAttrValueDES& aUUIDList, |
|
94 TUint16 aMaxRecCount, |
|
95 const TDesC8& aContState, |
|
96 TRequestStatus& aStatus) |
|
97 /** |
|
98 Ask for a service search using a list attribute value (CSdpAttrValueDES). |
|
99 THIS FUNCTION SHOULD NEVER BE EXPORTED AS IS...a general |
|
100 list attribute value is open to misuse. |
|
101 The reply to this function is to send the SIZE of the response back |
|
102 in the aResultSize parameter. Once this is done the user of this class |
|
103 can set up a buffer big enough to collect the response from server side. |
|
104 **/ |
|
105 { |
|
106 TSDPEncodedKeyBuf key; |
|
107 if(aContState.Length() > KSdpContinuationStateMaxLength) |
|
108 { |
|
109 User::Leave(KErrArgument); |
|
110 } |
|
111 key().iQueryType = KSDPEncodedQuery | KSDPBufferResult; |
|
112 key().iPduId = EServiceSearchRequest; |
|
113 |
|
114 TUint size = TElementEncoder::EncodedSize(ETypeDES, aUUIDList.DataSize()); |
|
115 delete iRequestBuf; |
|
116 iRequestBuf = 0; |
|
117 iRequestBuf = HBufC8::NewL(sizeof(key)+size+2+1+KSdpContinuationStateMaxLength); |
|
118 TPtr8 ptr = iRequestBuf->Des(); |
|
119 |
|
120 // Build the request PDU |
|
121 ptr.Copy(key); |
|
122 TElementEncoder ee(ptr); |
|
123 CAttrEncoderVisitor::EncodeAttributeL(ee, aUUIDList); |
|
124 TBuf8<2> sbuf; |
|
125 sbuf.SetMax(); |
|
126 BigEndian::Put16(&sbuf[0], aMaxRecCount); // Maximum Service record count |
|
127 ptr.Append(sbuf); |
|
128 ptr.Append((TUint8)aContState.Length()); |
|
129 ptr.Append(aContState); |
|
130 |
|
131 iResultSize.Set(TPckg<TInt>(aResultSize)); |
|
132 iResultSize.SetMax(); |
|
133 iNetDb.Query(*iRequestBuf, iResultSize, aStatus); |
|
134 } |
|
135 |
|
136 |
|
137 void RSdpAgent::SdpSearchRequestL(TInt& aResultSize, |
|
138 CSdpSearchPattern& aUUIDFilter, |
|
139 TUint16 aMaxRecCount, |
|
140 const TDesC8& aContState, |
|
141 TRequestStatus& aStatus) |
|
142 /** |
|
143 Ask for a service search using a UUID search pattern (CSdpSearchPattern). |
|
144 THIS FUNCTION SHOULD MAY BE EXPORTED (UNLIKE THE OTHER "SdpSearchRequestL") |
|
145 AT SOME FUTURE DATE. |
|
146 The reply to this function is to send the SIZE of the response back |
|
147 in the aResultSize parameter. Once this is done the user of this class |
|
148 can set up a buffer big enough to collect the response from server side. |
|
149 **/ |
|
150 { |
|
151 CSdpAttrValueDES* avEquiv = CSdpAttrValueDES::NewDESL(0); |
|
152 CleanupStack::PushL(avEquiv); |
|
153 MSdpElementBuilder* bldr = avEquiv->StartListL(); |
|
154 for (TInt i = 0; i < aUUIDFilter.Count(); ++i) |
|
155 { |
|
156 TUUID uuid = aUUIDFilter.At(i); |
|
157 bldr = bldr->BuildUUIDL(uuid); |
|
158 } |
|
159 bldr->EndListL(); |
|
160 CSdpAttrValueDES* avEquivT = CSdpAttrValueDES::NewDESL(0); |
|
161 CleanupStack::PushL(avEquivT); |
|
162 avEquivT->StartListL() |
|
163 ->BuildUUIDL(0x1100) |
|
164 ->BuildUUIDL(0x1101) |
|
165 ->BuildUUIDL(0x1102) |
|
166 ->EndListL(); |
|
167 |
|
168 SdpSearchRequestL(aResultSize, *avEquiv, aMaxRecCount, aContState, aStatus); |
|
169 CleanupStack::PopAndDestroy(); //avEquivT |
|
170 CleanupStack::PopAndDestroy(); //avEquiv |
|
171 } |
|
172 |
|
173 |
|
174 void RSdpAgent::SdpAttributeRequestL(TInt& aResultSize, |
|
175 TSdpServRecordHandle aHandle, |
|
176 TUint16 aMaxAttrByteCount, |
|
177 CSdpAttrIdMatchList& aMatchList, |
|
178 const TDesC8& aContState, |
|
179 TRequestStatus& aStatus) |
|
180 /** |
|
181 Ask for an attribute request using an ID match list (CSdpAttrIdMatchList). |
|
182 The reply to this function is to send the SIZE of the response back |
|
183 in the aResultSize parameter. Once this is done the user of this class |
|
184 can set up a buffer big enough to collect the response from server side. |
|
185 **/ |
|
186 { |
|
187 if(aContState.Length() > KSdpContinuationStateMaxLength) |
|
188 { |
|
189 User::Leave(KErrArgument); |
|
190 } |
|
191 |
|
192 __ASSERT_ALWAYS(aMaxAttrByteCount >= 7, AgPanic(ESdpAgentBadResultLength)); |
|
193 |
|
194 TSDPEncodedKeyBuf key; |
|
195 key().iQueryType = KSDPEncodedQuery | KSDPBufferResult; |
|
196 key().iPduId = EServiceAttributeRequest; |
|
197 |
|
198 TUint size = TElementEncoder::EncodedSize(ETypeDES, aMatchList.Count() * 5); |
|
199 delete iRequestBuf; |
|
200 iRequestBuf = 0; |
|
201 iRequestBuf = HBufC8::NewL(size + 4 + 2 + KSdpContinuationStateMaxLength + 1); |
|
202 TPtr8 ptr = iRequestBuf->Des(); |
|
203 |
|
204 TElementEncoder ee(ptr); |
|
205 |
|
206 // Build the request PDU |
|
207 ptr.Copy(key); |
|
208 TBuf8<6> sbuf(6); |
|
209 BigEndian::Put32(&sbuf[0], aHandle); // Record handle |
|
210 BigEndian::Put16(&sbuf[4], TUint16(aMaxAttrByteCount)); // Max byte count |
|
211 ptr.Append(sbuf); |
|
212 aMatchList.EncodeL(ee); // AttrID list |
|
213 ptr.Append((TUint8)aContState.Length()); |
|
214 ptr.Append(aContState); |
|
215 |
|
216 iResultSize.Set(TPckg<TInt>(aResultSize)); |
|
217 iResultSize.SetMax(); |
|
218 iNetDb.Query(*iRequestBuf, iResultSize, aStatus); |
|
219 } |
|
220 |
|
221 TInt RSdpAgent::RetrieveResult(TDes8& aResult) |
|
222 /** |
|
223 On completion of a service search or attribute request RSdpAgent |
|
224 is sent the size of the response by the server. To obtain the actual |
|
225 result (buffered in the server) a user needs to call this function. |
|
226 NB. This is a synchronous request. |
|
227 **/ |
|
228 { |
|
229 TPckgBuf<TUint> key(KSDPRetrieveResultQuery); |
|
230 return iNetDb.Query(key, aResult); |
|
231 } |
|
232 |
|
233 void RSdpAgent::Cancel() |
|
234 /** |
|
235 Pass "Cancel" call up to RNetDatabase. |
|
236 **/ |
|
237 { |
|
238 iNetDb.Cancel(); |
|
239 } |
|
240 |
|
241 |
|
242 |