|
1 /* |
|
2 * Copyright (c) 2002-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: This class handles service connections. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <obexbttransportinfo.h> |
|
21 #include "obexsmbtconnection.h" |
|
22 #include "debug.h" |
|
23 |
|
24 _LIT( KBTProtocol, "RFCOMM" ); |
|
25 |
|
26 |
|
27 // ================= MEMBER FUNCTIONS ======================= |
|
28 |
|
29 // --------------------------------------------------------- |
|
30 // C++ default constructor can NOT contain any code, that |
|
31 // might leave. |
|
32 // --------------------------------------------------------- |
|
33 // |
|
34 CObexSMBtConnection::CObexSMBtConnection() |
|
35 { |
|
36 } |
|
37 // --------------------------------------------------------- |
|
38 // Constructor |
|
39 // --------------------------------------------------------- |
|
40 // |
|
41 CObexSMBtConnection::CObexSMBtConnection(TAny* aInitParams) |
|
42 :iImplementationInfo((CImplementationInformation *)aInitParams), |
|
43 iBtDiscovery(NULL) |
|
44 { |
|
45 } |
|
46 // --------------------------------------------------------- |
|
47 // Destructor |
|
48 // --------------------------------------------------------- |
|
49 // |
|
50 CObexSMBtConnection::~CObexSMBtConnection() |
|
51 { |
|
52 // Cleanup |
|
53 FLOG(_L("[SRCS]\tserver\tCSrcsBtConnection::~CSrcsBtConnection begin")); |
|
54 |
|
55 if(iPasskey) |
|
56 { |
|
57 iPasskey->Cancel(); |
|
58 FLOG(_L("[SRCS]\tserver\tCSrcsBtConnection::~CSrcsBtConnection passkey query cancelled.")); |
|
59 } |
|
60 |
|
61 if ( iBtDiscovery ) |
|
62 { |
|
63 iBtDiscovery->DeleteSdpRecord( iSDPHandle ); |
|
64 delete iBtDiscovery; |
|
65 } |
|
66 |
|
67 FTRACE( FPrint( _L( "[SRCS] CSrcsBtConnection::~CSrcsBtConnection: UnregisterSDPSettingsL" ) ) ); |
|
68 |
|
69 |
|
70 if(iServer) |
|
71 { |
|
72 iServer->Stop(); |
|
73 FLOG(_L("[SRCS]\tserver\tCSrcsBtConnection::~CSrcsBtConnection obex server stopped.")); |
|
74 } |
|
75 // Delete OBEX Server |
|
76 if (iServer) |
|
77 { |
|
78 delete iServer; |
|
79 FLOG(_L("[SRCS]\tserver\tCSrcsBtConnection::~CSrcsBtConnection obex server deleted.")); |
|
80 iServer = NULL; |
|
81 } |
|
82 |
|
83 // Delete passkey |
|
84 delete iPasskey; |
|
85 FLOG(_L("[SRCS]\tserver\tCSrcsBtConnection::~CSrcsBtConnection iPasskey deleted.")); |
|
86 iPasskey = NULL; |
|
87 |
|
88 // Delete Service Controller callback |
|
89 delete iController; |
|
90 FLOG(_L("[SRCS]\tserver\tCSrcsBtConnection::~CSrcsBtConnection service controller deleted.")); |
|
91 iController = NULL; |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------- |
|
95 // NewL |
|
96 // --------------------------------------------------------- |
|
97 // |
|
98 CObexSMBtConnection* CObexSMBtConnection::NewL(TAny* aInitParams) |
|
99 { |
|
100 FLOG(_L("[SRCS]\tserver\tCSrcsBtConnection: NewL")); |
|
101 CObexSMBtConnection* self = new (ELeave) CObexSMBtConnection(aInitParams); |
|
102 CleanupStack::PushL(self); |
|
103 self->ConstructL(); |
|
104 CleanupStack::Pop(); |
|
105 return self; |
|
106 } |
|
107 |
|
108 |
|
109 // --------------------------------------------------------- |
|
110 // ConstructL |
|
111 // Method to create BT connections. |
|
112 // --------------------------------------------------------- |
|
113 // |
|
114 void CObexSMBtConnection::ConstructL() |
|
115 { |
|
116 TLex8 lex; |
|
117 // Create service controller implementation object |
|
118 iController = CSrcsInterface::NewL(iImplementationInfo->ImplementationUid()); |
|
119 |
|
120 FLOG(_L("[SRCS] CSrcsBtConnection: ConstructL: CSrcsInterface::NewL\t")); |
|
121 iController->SetMediaType( ESrcsMediaBT ); |
|
122 // parsing opaque_data in iImplementationInfo |
|
123 TPtrC8 res_string = iImplementationInfo->OpaqueData(); |
|
124 |
|
125 CObexUtilsOpaqueData res_data(res_string); |
|
126 |
|
127 TBuf8<KObexUtilsMaxOpaqueDataStringLen> op_LocalWho; |
|
128 TUint op_Protocol, op_Authenticate, op_Authorise, op_Encrypt; |
|
129 TUint op_ReceiveMtu(KSRCSDefaultReceiveMtu), op_TransmitMtu(KSRCSDefaultTransmitMtu); |
|
130 |
|
131 // skip 1st entry: USB interface string descriptor |
|
132 User::LeaveIfError ( res_data.GetString(op_LocalWho) ); |
|
133 |
|
134 // get 2nd entry: OBEX local who |
|
135 User::LeaveIfError ( res_data.GetString(op_LocalWho) ); |
|
136 |
|
137 // get 3rd to 7th entry |
|
138 |
|
139 // All service ID should be strings ! |
|
140 TBuf8<KObexUtilsMaxOpaqueDataStringLen> serviceUUID; |
|
141 User::LeaveIfError ( res_data.GetString(serviceUUID) ); |
|
142 |
|
143 FTRACE(FPrint(_L("[SRCS] CObexSMBtConnection::ConstructL() serviceUUID Length %d"), serviceUUID.Length())); |
|
144 |
|
145 if (serviceUUID.Length() < 6) |
|
146 { |
|
147 User::Leave( KErrArgument ); |
|
148 } |
|
149 |
|
150 lex.Assign(serviceUUID); |
|
151 |
|
152 User::LeaveIfError ( res_data.GetNumber(op_Protocol) ); |
|
153 User::LeaveIfError ( res_data.GetNumber(op_Authenticate) ); |
|
154 User::LeaveIfError ( res_data.GetNumber(op_Authorise) ); |
|
155 User::LeaveIfError ( res_data.GetNumber(op_Encrypt) ); |
|
156 |
|
157 // Get OBEX packet size: |
|
158 if( res_data.GetNumber(op_ReceiveMtu) != KErrNone ) |
|
159 { |
|
160 op_ReceiveMtu = KSRCSDefaultReceiveMtu; // restore default value in case it is modified; |
|
161 FLOG(_L("[SRCS] CSrcsBtConnection: ConstructL: op_ReceiveMtu not specified.\t")); |
|
162 } |
|
163 |
|
164 if( res_data.GetNumber(op_TransmitMtu) != KErrNone ) |
|
165 { |
|
166 op_TransmitMtu = KSRCSDefaultTransmitMtu; // restore default value in case it is modified; |
|
167 FLOG(_L("[SRCS] CSrcsBtConnection: ConstructL: op_TransmitMtu not specified.\t")); |
|
168 } |
|
169 |
|
170 FLOG(_L("[SRCS] CSrcsBtConnection: ConstructL: Successfully get all data from opaque_data.\t")); |
|
171 |
|
172 // Create CBTEngDiscovery |
|
173 |
|
174 FLOG(_L("[SRCS] CSrcsBtConnection: ConstructL: CBTConnection::NewL\t")); |
|
175 |
|
176 // For handling Obex Passkey note |
|
177 iPasskey = CObexSMPasskey::NewL(); |
|
178 FLOG(_L("[SRCS] CSrcsBtConnection: ConstructL: CSrcsPasskey::NewL\t")); |
|
179 |
|
180 // For showing Error Notes |
|
181 // iErrorUi = CErrorUI::NewL(); |
|
182 |
|
183 // set up the protocol stack... |
|
184 TObexBluetoothProtocolInfo aObexBluetoothProtocolInfo; |
|
185 aObexBluetoothProtocolInfo.iTransport = KBTProtocol ; |
|
186 |
|
187 // Configure security setting |
|
188 FLOG(_L("[SRCS] CSrcsBtConnection: ConstructL: Setting Security\t")); |
|
189 TBTServiceSecurity sec; |
|
190 sec.SetAuthentication(op_Authenticate); |
|
191 sec.SetAuthorisation(op_Authorise); |
|
192 sec.SetEncryption(op_Encrypt); |
|
193 |
|
194 TUint32 serviceUID; |
|
195 lex.Inc(2); |
|
196 lex.Val(serviceUID,EHex); |
|
197 sec.SetUid(TUid::Uid(serviceUID)); |
|
198 aObexBluetoothProtocolInfo.iAddr.SetSecurity(sec); |
|
199 if (serviceUUID.Length() == 34) |
|
200 { |
|
201 TUint32 HH; TUint32 HL; TUint32 LH; TUint32 LL; |
|
202 lex = serviceUUID.Mid(2, 8); |
|
203 lex.Val(HH, EHex); |
|
204 lex = serviceUUID.Mid(10, 8); |
|
205 lex.Val(HL, EHex); |
|
206 lex = serviceUUID.Mid(18, 8); |
|
207 lex.Val(LH, EHex); |
|
208 lex = serviceUUID.Mid(26, 8); |
|
209 lex.Val(LL, EHex); |
|
210 iServiceUUID = TUUID(HH, HL, LH, LL); |
|
211 } |
|
212 else |
|
213 { |
|
214 iServiceUUID = TUUID(serviceUID); |
|
215 } |
|
216 |
|
217 // Configure Obex packet size |
|
218 TObexProtocolPolicy aObexProtocolPolicy; |
|
219 aObexProtocolPolicy.SetReceiveMtu( static_cast<TUint16>(op_ReceiveMtu) ); |
|
220 aObexProtocolPolicy.SetTransmitMtu( static_cast<TUint16>(op_TransmitMtu) ); |
|
221 FTRACE(FPrint(_L("[SRCS] CSrcsBtConnection: ConstructL: op_ReceiveMtu[%x] op_TransmitMtu[%x]"), |
|
222 aObexProtocolPolicy.ReceiveMtu(), aObexProtocolPolicy.TransmitMtu() )); |
|
223 |
|
224 // try to find a available channel to start OBEX server. |
|
225 TUint channel=KRfcommPassiveAutoBind; |
|
226 |
|
227 aObexBluetoothProtocolInfo.iAddr.SetPort( channel ); |
|
228 TRAPD(err,iServer = CObexServer::NewL(aObexBluetoothProtocolInfo, aObexProtocolPolicy);) |
|
229 // Try to start server on this channel |
|
230 if ( err == KErrNone ) |
|
231 { |
|
232 err=iController->SetObexServer( iServer ); |
|
233 if ( err == KErrNone ) |
|
234 { |
|
235 // Set authentication handler |
|
236 iServer->SetCallBack( *this ); |
|
237 //If there is "local who" field, set it to OBEX server. |
|
238 if(op_LocalWho.Size()) |
|
239 { |
|
240 User::LeaveIfError ( iServer->SetLocalWho( op_LocalWho ) ); |
|
241 FLOG(_L("[SRCS] CSrcsBtConnection: ConstructL: SetLocalWho\t")); |
|
242 } |
|
243 FLOG(_L("[SRCS] CSrcsBtConnection: ConstructL: SetObexServer\t")); |
|
244 |
|
245 // Register SDP settings |
|
246 |
|
247 TObexBtTransportInfo *info=(TObexBtTransportInfo*)iServer->TransportInfo(); |
|
248 channel=info->iAddr.Port(); |
|
249 FTRACE(FPrint(_L("[SRCS] CSrcsBtConnection: ConstructL: CObexServer started on channel %d"), channel)); |
|
250 iBtDiscovery = CBTEngDiscovery::NewL(); |
|
251 User::LeaveIfError ( iBtDiscovery->RegisterSdpRecord(iServiceUUID, channel, iSDPHandle )); |
|
252 } |
|
253 else |
|
254 { |
|
255 // Failed to start Obex server. Delete server and try again |
|
256 FLOG(_L("[SRCS] CSrcsBtConnection: ConstructL: Failed to start Obex server. Delete server and try again.\t")); |
|
257 delete iServer; |
|
258 iServer = NULL; |
|
259 } |
|
260 } |
|
261 if ( !iServer ) |
|
262 { |
|
263 // Server did not start. |
|
264 FLOG(_L("[SRCS] CSrcsBtConnection: ConstructL: Failed to start Obex server. Leave now! \t")); |
|
265 User::Leave( KErrGeneral ); |
|
266 } |
|
267 |
|
268 } |
|
269 |
|
270 // --------------------------------------------------------- |
|
271 // GetUserPasswordL(const TDesC& ) |
|
272 // Purpose: Get the Obex password from user with ObexPasskeyNotifier |
|
273 // Parameters: |
|
274 // Return value: |
|
275 // --------------------------------------------------------- |
|
276 // |
|
277 void CObexSMBtConnection::GetUserPasswordL( const TDesC& ) |
|
278 { |
|
279 FLOG( _L( "[SRCS] CSrcsBtConnection: GetUserPassword\t" ) ); |
|
280 iPasskey->StartPassKeyRequestL( iServer ); |
|
281 } |
|
282 |
|
283 // --------------------------------------------------------- |
|
284 // Check if OBEX service is still active. |
|
285 // @return ETrue: OBEX service is still active. |
|
286 // EFalse: OBEX service is inactive. |
|
287 // --------------------------------------------------------- |
|
288 // |
|
289 TBool CObexSMBtConnection::IsOBEXActive() |
|
290 { |
|
291 FLOG( _L( "[SRCS] CSrcsBtConnection: IsOBEXActive\t" ) ); |
|
292 return ETrue; |
|
293 } |
|
294 |
|
295 // End of file |