|
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 |
|
20 // INCLUDE FILES |
|
21 |
|
22 #include "obexsmusbconnection.h" |
|
23 #include "debug.h" |
|
24 #include <d32usbc.h> |
|
25 #include "obexutilsopaquedata.h" |
|
26 #include <centralrepository.h> |
|
27 #include "obexservicemanprivatecrkeys.h" |
|
28 |
|
29 // ================= MEMBER FUNCTIONS ======================= |
|
30 |
|
31 // --------------------------------------------------------- |
|
32 // C++ default constructor can NOT contain any code, that |
|
33 // might leave. |
|
34 // --------------------------------------------------------- |
|
35 // |
|
36 CObexSMUsbConnection::CObexSMUsbConnection() |
|
37 { |
|
38 } |
|
39 // --------------------------------------------------------- |
|
40 // Constructor |
|
41 // --------------------------------------------------------- |
|
42 // |
|
43 CObexSMUsbConnection::CObexSMUsbConnection(TAny* aInitParams) |
|
44 :iImplementationInfo((CImplementationInformation *)aInitParams) |
|
45 { |
|
46 } |
|
47 |
|
48 // --------------------------------------------------------- |
|
49 // Destructor |
|
50 // --------------------------------------------------------- |
|
51 // |
|
52 CObexSMUsbConnection::~CObexSMUsbConnection() |
|
53 { |
|
54 // Cleanup |
|
55 FLOG(_L("[SRCS] CSrcsUsbConnection: StopObexServer")); |
|
56 if(iServer) |
|
57 { |
|
58 iServer->Stop(); |
|
59 } |
|
60 |
|
61 // Delete OBEX Server |
|
62 if (iServer) |
|
63 { |
|
64 delete iServer; |
|
65 FLOG(_L("[SRCS]\tserver\tCSrcsBtConnection::~CSrcsBtConnection obex server deleted.")); |
|
66 iServer = NULL; |
|
67 } |
|
68 |
|
69 // Delete Service Controller callback |
|
70 delete iController; |
|
71 iController = NULL; |
|
72 |
|
73 FLOG(_L("[SRCS] CSrcsUsbConnection: ~CSrcsUsbConnection: Completed\t")); |
|
74 } |
|
75 |
|
76 // --------------------------------------------------------- |
|
77 // NewL |
|
78 // --------------------------------------------------------- |
|
79 // |
|
80 CObexSMUsbConnection* CObexSMUsbConnection::NewL(TAny* aInitParams) |
|
81 { |
|
82 FLOG(_L("[SRCS]\tserver\tCSrcsUsbConnection: NewL")); |
|
83 CObexSMUsbConnection* self = new (ELeave) CObexSMUsbConnection(aInitParams); |
|
84 CleanupStack::PushL(self); |
|
85 self->ConstructL(); |
|
86 CleanupStack::Pop(); |
|
87 return self; |
|
88 } |
|
89 |
|
90 |
|
91 // --------------------------------------------------------- |
|
92 // ConstructL |
|
93 // Method to create BT connections. |
|
94 // --------------------------------------------------------- |
|
95 // |
|
96 void CObexSMUsbConnection::ConstructL() |
|
97 { |
|
98 // Create service controller implementation object |
|
99 iController = CSrcsInterface::NewL(iImplementationInfo->ImplementationUid()); |
|
100 FLOG(_L("[SRCS] CSrcsUsbConnection: ConstructL: CSrcsInterface::NewL\t")); |
|
101 |
|
102 iController->SetMediaType( ESrcsMediaUSB ); |
|
103 |
|
104 // parsing opaque_data in iImplementationInfo |
|
105 TPtrC8 res_string = iImplementationInfo->OpaqueData(); |
|
106 |
|
107 CObexUtilsOpaqueData res_data(res_string); |
|
108 TBuf8<KObexUtilsMaxOpaqueDataStringLen> op_StringDesc, op_LocalWho, op_SkipStr; |
|
109 TUint op_SkipInt; //used to skip certain fields |
|
110 TUint op_ReceiveMtu(KSRCSDefaultReceiveMtu), op_TransmitMtu(KSRCSDefaultTransmitMtu); |
|
111 // get 1st entry: USB interface string descriptor |
|
112 User::LeaveIfError ( res_data.GetString(op_StringDesc) ); |
|
113 // get 2nd entry: OBEX local who |
|
114 User::LeaveIfError ( res_data.GetString(op_LocalWho) ); |
|
115 // skip 3rd to 7th entry |
|
116 // All service ID should be strings ! |
|
117 res_data.GetString(op_SkipStr); |
|
118 res_data.GetNumber(op_SkipInt); |
|
119 res_data.GetNumber(op_SkipInt); |
|
120 res_data.GetNumber(op_SkipInt); |
|
121 res_data.GetNumber(op_SkipInt); |
|
122 |
|
123 // Get OBEX packet size: |
|
124 if( res_data.GetNumber(op_ReceiveMtu) != KErrNone ) |
|
125 { |
|
126 op_ReceiveMtu = KSRCSDefaultReceiveMtu; // restore default value in case it is modified; |
|
127 FLOG(_L("[SRCS] CSrcsUsbConnection: ConstructL: op_ReceiveMtu not specified.\t")); |
|
128 } |
|
129 |
|
130 if( res_data.GetNumber(op_TransmitMtu) != KErrNone ) |
|
131 { |
|
132 op_TransmitMtu = KSRCSDefaultTransmitMtu; // restore default value in case it is modified; |
|
133 FLOG(_L("[SRCS] CSrcsUsbConnection: ConstructL: op_TransmitMtu not specified.\t")); |
|
134 } |
|
135 |
|
136 FLOG(_L("[SRCS] CSrcsUsbConnection: ConstructL: Successfully get all data from opaque_data.\t")); |
|
137 |
|
138 // Get OBEX usb dma usage |
|
139 CRepository* cenrep = NULL; |
|
140 TRAP_IGNORE(cenrep = CRepository::NewL(KCRUidObexServiceMan)); |
|
141 TInt dmaUsage = EObexUsbDmaInUse; |
|
142 if (cenrep) |
|
143 { |
|
144 cenrep->Get(KObexUsbDmaUsage, dmaUsage); |
|
145 delete cenrep; |
|
146 } |
|
147 |
|
148 // set up the protocol stack... |
|
149 TObexUsbProtocolInfoV2 obexUsbProtocolInfo; |
|
150 obexUsbProtocolInfo.iTransport = KObexUsbProtocolV2; |
|
151 obexUsbProtocolInfo.iInterfaceStringDescriptor.Copy(op_StringDesc); |
|
152 if(dmaUsage == EObexUsbDmaInUse) |
|
153 { |
|
154 obexUsbProtocolInfo.iDmaOnInEndpoint = ETrue; |
|
155 obexUsbProtocolInfo.iDmaOnOutEndpoint = ETrue; |
|
156 } |
|
157 else |
|
158 { |
|
159 obexUsbProtocolInfo.iDmaOnInEndpoint = EFalse; |
|
160 obexUsbProtocolInfo.iDmaOnOutEndpoint = EFalse; |
|
161 } |
|
162 obexUsbProtocolInfo.iBandwidthPriority = EUsbcBandwidthOUTPlus2 | EUsbcBandwidthINPlus2; |
|
163 |
|
164 |
|
165 |
|
166 // Configure Obex packet size |
|
167 TObexProtocolPolicy aObexProtocolPolicy; |
|
168 aObexProtocolPolicy.SetReceiveMtu( static_cast<TUint16>(op_ReceiveMtu) ); |
|
169 aObexProtocolPolicy.SetTransmitMtu( static_cast<TUint16>(op_TransmitMtu) ); |
|
170 FTRACE(FPrint(_L("[SRCS] CSrcsUsbConnection: ConstructL: op_ReceiveMtu[%x] op_TransmitMtu[%x]"), |
|
171 aObexProtocolPolicy.ReceiveMtu(), aObexProtocolPolicy.TransmitMtu() )); |
|
172 |
|
173 // Try to create OBEX server |
|
174 iServer = CObexServer::NewL(obexUsbProtocolInfo, aObexProtocolPolicy); |
|
175 FLOG(_L("[SRCS] CSrcsUsbConnection: ConstructL: CObexServer::NewL")); |
|
176 |
|
177 |
|
178 |
|
179 FLOG(_L("[SRCS] CSrcsUsbConnection: ConstructL: iServer->Start")); |
|
180 |
|
181 FLOG(_L("[SRCS] CSrcsUsbConnection: ConstructL: SetObexServer\t")); |
|
182 // Try to start server |
|
183 User::LeaveIfError ( iController->SetObexServer( iServer )); |
|
184 |
|
185 |
|
186 // we do not accept Obex passkey for USB transport, so do NOT set callback. |
|
187 // iServer->SetCallBack( *this ); |
|
188 |
|
189 // if there is "local who" field |
|
190 if(op_LocalWho.Size()) |
|
191 { |
|
192 User::LeaveIfError ( iServer->SetLocalWho( op_LocalWho ) ); |
|
193 FLOG(_L("[SRCS] CSrcsUsbConnection: ConstructL: SetLocalWho")); |
|
194 } |
|
195 } |
|
196 |
|
197 // --------------------------------------------------------- |
|
198 // GetUserPasswordL(const TDesC& ) |
|
199 // Purpose: Get the Obex password from user with ObexPasskeyNotifier |
|
200 // Parameters: |
|
201 // Return value: |
|
202 // --------------------------------------------------------- |
|
203 // |
|
204 void CObexSMUsbConnection::GetUserPasswordL( const TDesC& ) |
|
205 { |
|
206 FLOG( _L( "[SRCS] CSrcsUsbConnection: GetUserPassword\t" ) ); |
|
207 } |
|
208 |
|
209 // --------------------------------------------------------- |
|
210 // Check if OBEX service is still active. |
|
211 // @return ETrue: OBEX service is still active. |
|
212 // EFalse: OBEX service is inactive. |
|
213 // --------------------------------------------------------- |
|
214 // |
|
215 |
|
216 TBool CObexSMUsbConnection::IsOBEXActive() |
|
217 { |
|
218 FLOG( _L( "[SRCS] CSrcsUsbConnection: IsOBEXActive\t" ) ); |
|
219 return ETrue; |
|
220 } |
|
221 |
|
222 // End of file |