|
1 // Copyright (c) 1997-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 // sdpclientcsy.cpp - all the sdp parser code |
|
15 // |
|
16 // |
|
17 |
|
18 #include <bluetooth/logger.h> |
|
19 #include <cs_port.h> |
|
20 #include "btcomm.h" |
|
21 #include "sdpclientcsy.h" |
|
22 #include <es_sock.h> |
|
23 #include <e32cons.h> |
|
24 #include <bt_sock.h> |
|
25 |
|
26 #ifdef __FLOG_ACTIVE |
|
27 _LIT8(KLogComponent, LOG_COMPONENT_BT_COMM); |
|
28 #endif |
|
29 |
|
30 // RFComm specific attribute 'snatcher' objects for the SDP attribute query |
|
31 // CRFCommAttribs |
|
32 CRFCommAttribs* CRFCommAttribs::NewL(MSdpElementBuilder* /*aParent*/) |
|
33 { |
|
34 CRFCommAttribs* cl=new (ELeave) CRFCommAttribs; |
|
35 return cl; |
|
36 } |
|
37 |
|
38 CRFCommAttribs::CRFCommAttribs() |
|
39 { |
|
40 } |
|
41 |
|
42 CRFCommAttribs::~CRFCommAttribs() |
|
43 { |
|
44 delete iPortAttrib; |
|
45 } |
|
46 |
|
47 MSdpElementBuilder* CRFCommAttribs::StartListL() |
|
48 { |
|
49 return this; |
|
50 } |
|
51 |
|
52 MSdpElementBuilder* CRFCommAttribs::EndListL() |
|
53 { |
|
54 return this; |
|
55 } |
|
56 |
|
57 MSdpElementBuilder* CRFCommAttribs::BuildUintL(const TDesC8& /*aInt*/) |
|
58 { |
|
59 return this; |
|
60 } |
|
61 |
|
62 MSdpElementBuilder* CRFCommAttribs::BuildDESL() |
|
63 { |
|
64 return this; |
|
65 } |
|
66 |
|
67 |
|
68 MSdpElementBuilder* CRFCommAttribs::BuildUUIDL(const TUUID& aUUID) |
|
69 /** |
|
70 Go and get RFComm UUID info. |
|
71 */ |
|
72 { |
|
73 #ifdef _DEBUG |
|
74 TBuf8<40> desUUID; |
|
75 desUUID = aUUID.ShortestForm(); |
|
76 TBuf<40> readableUUID; |
|
77 readableUUID.Copy(desUUID); |
|
78 |
|
79 LOG1(_L("CRFCommAttribs::BuildUUIDL(%S) main entry\n"), &readableUUID); |
|
80 #endif |
|
81 if (iPortAttrib!=NULL) |
|
82 { |
|
83 LOG(_L("iPortAttrib already exists, returning it.")); |
|
84 return iPortAttrib; // i.e go to the get RFComm port 'snatching' state |
|
85 // although this will not always be correct, but suits us for now |
|
86 } |
|
87 if(aUUID==TUUID(TUint16(KSDPRFCommUUID))) |
|
88 { |
|
89 #ifdef _DEBUG |
|
90 LOG1(_L("CRFCommAttribs::BuildUUIDL(%S) if =RFCOMMUUID\n"), &readableUUID); |
|
91 #endif |
|
92 iRfcommUUID=TUUID(aUUID); |
|
93 LOG(_L("CRFCommPortAttribs NewL")); |
|
94 iPortAttrib = CRFCommPortAttrib::NewL(this); |
|
95 LOG(_L("CRFCommPortAttribs - NewL survived")); |
|
96 return iPortAttrib; |
|
97 } |
|
98 |
|
99 LOG2(_L("CRFCommAttribs - return this = 0x%08x, iPortAttrib = 0x%08x"), this, iPortAttrib); |
|
100 return this; |
|
101 } |
|
102 |
|
103 void CRFCommAttribs::Print(TUint /*aIndent*/) |
|
104 { |
|
105 } |
|
106 |
|
107 TInt CRFCommAttribs::GetRFCommPort(TUint8& aServerChannel) |
|
108 { |
|
109 if (!iPortAttrib) |
|
110 { |
|
111 // the SDP response was syntactically correct, but semantically wrong |
|
112 // so we'd never have created the iPortAttrib object |
|
113 return KErrNotFound; |
|
114 } |
|
115 else |
|
116 { |
|
117 aServerChannel = iPortAttrib->GetRFCommPort(); |
|
118 return KErrNone; |
|
119 } |
|
120 } |
|
121 |
|
122 // CRFCommPortAttrib |
|
123 |
|
124 CRFCommPortAttrib* CRFCommPortAttrib::NewL(MSdpElementBuilder* aParent) |
|
125 { |
|
126 CRFCommPortAttrib* cl=new (ELeave) CRFCommPortAttrib(aParent); |
|
127 return cl; |
|
128 } |
|
129 |
|
130 CRFCommPortAttrib::CRFCommPortAttrib(MSdpElementBuilder* aParent) : iParent(aParent) |
|
131 { |
|
132 } |
|
133 |
|
134 CRFCommPortAttrib::~CRFCommPortAttrib() |
|
135 { |
|
136 } |
|
137 |
|
138 |
|
139 MSdpElementBuilder* CRFCommPortAttrib::BuildUintL(const TDesC8& aUint) |
|
140 { |
|
141 if(aUint.Length() > 4) // 4 being the 32bit TUint byte size |
|
142 User::Leave(KErrArgument); |
|
143 iPort=static_cast<TUint8>(GetUint(aUint)); |
|
144 |
|
145 if(iPort<(TUint)KMinRfcommServerChannel || iPort>(TUint)KMaxRfcommServerChannel) //30 is max RFComm port |
|
146 { |
|
147 User::Leave(KErrArgument); |
|
148 } |
|
149 |
|
150 return iParent; |
|
151 } |
|
152 |
|
153 TUint CRFCommPortAttrib::GetUint(const TDesC8& aData) |
|
154 { |
|
155 switch(aData.Length()) |
|
156 { |
|
157 case 0: |
|
158 return 0; |
|
159 case 1: |
|
160 return aData[0]; |
|
161 case 2: |
|
162 return BigEndian::Get16(aData.Ptr()); |
|
163 case 4: |
|
164 return BigEndian::Get32(aData.Ptr()); |
|
165 default: |
|
166 //ParsePanic(EGetUintBadDescriptorLength); //FIXME |
|
167 return 0; |
|
168 } |
|
169 } |
|
170 |
|
171 TUint8 CRFCommPortAttrib::GetRFCommPort() |
|
172 { |
|
173 return iPort; |
|
174 } |
|
175 |
|
176 //this builder checks to see if the UUID is in the Service Class ID list attribute |
|
177 CRFCommClass* CRFCommClass::NewL(const TUUID& aUUID) |
|
178 { |
|
179 CRFCommClass* cl=new (ELeave) CRFCommClass(aUUID); |
|
180 return cl; |
|
181 } |
|
182 |
|
183 CRFCommClass::CRFCommClass(const TUUID& aUUID) |
|
184 : iUUID(aUUID), iNService(EFalse) |
|
185 { |
|
186 } |
|
187 |
|
188 CRFCommClass::~CRFCommClass() |
|
189 { |
|
190 } |
|
191 |
|
192 MSdpElementBuilder* CRFCommClass::StartListL() |
|
193 { |
|
194 return this; |
|
195 } |
|
196 |
|
197 MSdpElementBuilder* CRFCommClass::EndListL() |
|
198 { |
|
199 return this; |
|
200 } |
|
201 |
|
202 MSdpElementBuilder* CRFCommClass::BuildUintL(const TDesC8& /*aInt*/) |
|
203 { |
|
204 return this; |
|
205 } |
|
206 |
|
207 MSdpElementBuilder* CRFCommClass::BuildDESL() |
|
208 { |
|
209 return this; |
|
210 } |
|
211 |
|
212 |
|
213 MSdpElementBuilder* CRFCommClass::BuildUUIDL(const TUUID& aUUID) |
|
214 /** |
|
215 The meat, if the UUID is in the service class list then this is the record we want. |
|
216 */ |
|
217 { |
|
218 if(aUUID==iUUID) |
|
219 { |
|
220 iNService=ETrue; |
|
221 } |
|
222 return this; |
|
223 } |
|
224 |
|
225 TBool CRFCommClass::InService() |
|
226 { |
|
227 return iNService; |
|
228 } |