32
|
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 "obexsmirdaconnection.h"
|
|
23 |
#include "debug.h"
|
|
24 |
#include "obexutilsopaquedata.h"
|
|
25 |
|
|
26 |
const TUint16 KMaxMtuSize = 0x7FFF; // 32kB-1
|
|
27 |
|
|
28 |
// ================= MEMBER FUNCTIONS =======================
|
|
29 |
|
|
30 |
// ---------------------------------------------------------
|
|
31 |
// C++ default constructor can NOT contain any code, that
|
|
32 |
// might leave.
|
|
33 |
// ---------------------------------------------------------
|
|
34 |
//
|
|
35 |
CObexSMIrDAConnection::CObexSMIrDAConnection()
|
|
36 |
{
|
|
37 |
}
|
|
38 |
// ---------------------------------------------------------
|
|
39 |
// Constructor
|
|
40 |
// ---------------------------------------------------------
|
|
41 |
//
|
|
42 |
CObexSMIrDAConnection::CObexSMIrDAConnection(TAny* aInitParams)
|
|
43 |
:iImplementationInfo((CImplementationInformation *)aInitParams)
|
|
44 |
{
|
|
45 |
}
|
|
46 |
|
|
47 |
// ---------------------------------------------------------
|
|
48 |
// Destructor
|
|
49 |
// ---------------------------------------------------------
|
|
50 |
//
|
|
51 |
CObexSMIrDAConnection::~CObexSMIrDAConnection()
|
|
52 |
{
|
|
53 |
// Cleanup
|
|
54 |
FLOG(_L("[SRCS]\tserver\tCSrcsIrDAConnection::~CSrcsIrDAConnection"));
|
|
55 |
if(iServer)
|
|
56 |
{
|
|
57 |
iServer->Stop();
|
|
58 |
FLOG(_L("[SRCS]\tserver\tCSrcsIrDAConnection::~CSrcsIrDAConnection: OBEX server stopped."));
|
|
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 |
FLOG(_L("[SRCS]\tserver\tCSrcsIrDAConnection::~CSrcsIrDAConnection: service controller deleted."));
|
|
72 |
iController = NULL;
|
|
73 |
|
|
74 |
FLOG(_L("[SRCS]\tserver\tCSrcsIrDAConnection::~CSrcsIrDAConnection finished."));
|
|
75 |
}
|
|
76 |
|
|
77 |
// ---------------------------------------------------------
|
|
78 |
// NewL
|
|
79 |
// ---------------------------------------------------------
|
|
80 |
//
|
|
81 |
CObexSMIrDAConnection* CObexSMIrDAConnection::NewL(TAny* aInitParams)
|
|
82 |
{
|
|
83 |
FLOG(_L("[SRCS]\tserver\tCSrcsIrDAConnection: NewL"));
|
|
84 |
CObexSMIrDAConnection* self = new (ELeave) CObexSMIrDAConnection(aInitParams);
|
|
85 |
CleanupStack::PushL(self);
|
|
86 |
self->ConstructL();
|
|
87 |
CleanupStack::Pop();
|
|
88 |
return self;
|
|
89 |
}
|
|
90 |
|
|
91 |
|
|
92 |
// ---------------------------------------------------------
|
|
93 |
// ConstructL
|
|
94 |
// Method to create IrDA connections.
|
|
95 |
// ---------------------------------------------------------
|
|
96 |
//
|
|
97 |
void CObexSMIrDAConnection::ConstructL()
|
|
98 |
{
|
|
99 |
|
|
100 |
// Create service controller implementation object
|
|
101 |
iController = CSrcsInterface::NewL(iImplementationInfo->ImplementationUid());
|
|
102 |
FLOG(_L("[SRCS] CSrcsIrDAConnection: ConstructL: CSrcsInterface::NewL\t"));
|
|
103 |
|
|
104 |
iController->SetMediaType( ESrcsMediaIrDA );
|
|
105 |
|
|
106 |
//Start service controller state machine.
|
|
107 |
iController->IsOBEXActive();
|
|
108 |
|
|
109 |
// parsing opaque_data in iImplementationInfo
|
|
110 |
TPtrC8 res_string = iImplementationInfo->OpaqueData();
|
|
111 |
|
|
112 |
CObexUtilsOpaqueData res_data(res_string);
|
|
113 |
TBuf8<KObexUtilsMaxOpaqueDataStringLen> op_StringDesc, op_LocalWho, op_SkipStr;
|
|
114 |
TUint op_SkipInt; //used to skip certain fields
|
|
115 |
TUint op_ReceiveMtu(KSRCSDefaultReceiveMtu), op_TransmitMtu(KSRCSDefaultTransmitMtu);
|
|
116 |
|
|
117 |
// get 1st entry: USB interface string descriptor
|
|
118 |
User::LeaveIfError ( res_data.GetString(op_StringDesc) );
|
|
119 |
|
|
120 |
// get 2nd entry: OBEX local who
|
|
121 |
User::LeaveIfError ( res_data.GetString(op_LocalWho) );
|
|
122 |
|
|
123 |
// skip 3rd to 7th entry
|
|
124 |
// All service ID should be strings !
|
|
125 |
res_data.GetString(op_SkipStr);
|
|
126 |
res_data.GetNumber(op_SkipInt);
|
|
127 |
res_data.GetNumber(op_SkipInt);
|
|
128 |
res_data.GetNumber(op_SkipInt);
|
|
129 |
res_data.GetNumber(op_SkipInt);
|
|
130 |
|
|
131 |
// Get OBEX packet size:
|
|
132 |
if( res_data.GetNumber(op_ReceiveMtu) != KErrNone )
|
|
133 |
{
|
|
134 |
op_ReceiveMtu = KSRCSDefaultReceiveMtu; // restore default value in case it is modified;
|
|
135 |
FLOG(_L("[SRCS] CSrcsIrDAConnection: ConstructL: op_ReceiveMtu not specified.\t"));
|
|
136 |
}
|
|
137 |
|
|
138 |
if( res_data.GetNumber(op_TransmitMtu) != KErrNone )
|
|
139 |
{
|
|
140 |
op_TransmitMtu = KSRCSDefaultTransmitMtu; // restore default value in case it is modified;
|
|
141 |
FLOG(_L("[SRCS] CSrcsIrDAConnection: ConstructL: op_TransmitMtu not specified.\t"));
|
|
142 |
}
|
|
143 |
//limit max mtu size to 32kB-1
|
|
144 |
if (op_ReceiveMtu>KMaxMtuSize)
|
|
145 |
{
|
|
146 |
op_ReceiveMtu=KMaxMtuSize;
|
|
147 |
}
|
|
148 |
if (op_TransmitMtu>KMaxMtuSize)
|
|
149 |
{
|
|
150 |
op_TransmitMtu=KMaxMtuSize;
|
|
151 |
}
|
|
152 |
|
|
153 |
FLOG(_L("[SRCS] CSrcsIrDAConnection: ConstructL: Successfully get all data from opaque_data.\t"));
|
|
154 |
|
|
155 |
// set up the protocol stack...
|
|
156 |
TObexIrProtocolInfo aInfo;
|
|
157 |
|
|
158 |
aInfo.iTransport = KObexIrTTPProtocol; //"IrTinyTP" from obex.h
|
|
159 |
aInfo.iClassName.Copy(op_StringDesc);
|
|
160 |
aInfo.iAttributeName = _L8("IrDA:TinyTP:LsapSel");;
|
|
161 |
|
|
162 |
// Configure Obex packet size
|
|
163 |
TObexProtocolPolicy aObexProtocolPolicy;
|
|
164 |
aObexProtocolPolicy.SetReceiveMtu( static_cast<TUint16>(op_ReceiveMtu) );
|
|
165 |
aObexProtocolPolicy.SetTransmitMtu( static_cast<TUint16>(op_TransmitMtu) );
|
|
166 |
FTRACE(FPrint(_L("[SRCS] CSrcsIrDAConnection: ConstructL: op_ReceiveMtu[%x] op_TransmitMtu[%x]"),
|
|
167 |
aObexProtocolPolicy.ReceiveMtu(), aObexProtocolPolicy.TransmitMtu() ));
|
|
168 |
|
|
169 |
// try to find a available port to start OBEX server.
|
|
170 |
TUint port=KAutoBindLSAP;
|
|
171 |
// create obex server
|
|
172 |
|
|
173 |
aInfo.iAddr.SetPort( port );
|
|
174 |
TRAPD(err,iServer = CObexServer::NewL(aInfo, aObexProtocolPolicy);)
|
|
175 |
|
|
176 |
// Try to start server on this port
|
|
177 |
if ( err == KErrNone )
|
|
178 |
{
|
|
179 |
FLOG(_L("[SRCS] CSrcsIrDAConnection: ConstructL: SetObexServer\t"));
|
|
180 |
err=iController->SetObexServer( iServer );
|
|
181 |
FTRACE(FPrint(_L("[SRCS] CSrcsIrDAConnection: ConstructL: CObexServer started on port %d"), port));
|
|
182 |
|
|
183 |
if (err!=KErrNone)
|
|
184 |
{
|
|
185 |
// Failed to start Obex server. Delete server and try again
|
|
186 |
delete iServer;
|
|
187 |
iServer = NULL;
|
|
188 |
}
|
|
189 |
}
|
|
190 |
|
|
191 |
|
|
192 |
if ( !iServer )
|
|
193 |
{
|
|
194 |
// Server did not start.
|
|
195 |
FLOG(_L("[SRCS] CSrcsIrDAConnection: ConstructL: Failed to start Obex server\t"));
|
|
196 |
User::Leave( KErrGeneral );
|
|
197 |
}
|
|
198 |
else
|
|
199 |
{
|
|
200 |
// if there is "local who" field
|
|
201 |
if(op_LocalWho.Size())
|
|
202 |
{
|
|
203 |
User::LeaveIfError ( iServer->SetLocalWho( op_LocalWho ) );
|
|
204 |
FLOG(_L("[SRCS] CSrcsIrDAConnection: ConstructL: SetLocalWho"));
|
|
205 |
}
|
|
206 |
}
|
|
207 |
}
|
|
208 |
|
|
209 |
// ---------------------------------------------------------
|
|
210 |
// GetUserPasswordL(const TDesC& )
|
|
211 |
// Purpose: Get the Obex password from user with ObexPasskeyNotifier
|
|
212 |
// Parameters:
|
|
213 |
// Return value:
|
|
214 |
// ---------------------------------------------------------
|
|
215 |
//
|
|
216 |
void CObexSMIrDAConnection::GetUserPasswordL( const TDesC& )
|
|
217 |
{
|
|
218 |
FLOG( _L( "[SRCS] CSrcsIrDAConnection: GetUserPassword\t" ) );
|
|
219 |
}
|
|
220 |
|
|
221 |
// ---------------------------------------------------------
|
|
222 |
// Check if OBEX service is still active.
|
|
223 |
// @return ETrue: OBEX service is still active.
|
|
224 |
// EFalse: OBEX service is inactive.
|
|
225 |
// ---------------------------------------------------------
|
|
226 |
//
|
|
227 |
|
|
228 |
TBool CObexSMIrDAConnection::IsOBEXActive()
|
|
229 |
{
|
|
230 |
FLOG( _L( "[SRCS] CSrcsIrDAConnection: IsOBEXActive\t" ) );
|
|
231 |
return iController->IsOBEXActive();
|
|
232 |
}
|
|
233 |
|
|
234 |
// End of file
|