0
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 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 the License "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:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
#include "mmodematobserver.h"
|
|
21 |
#include "rmodematcontroller.h"
|
|
22 |
#include "modematclientsrv.h"
|
|
23 |
#include "modemattrace.h"
|
|
24 |
#include "catcommandreq.h"
|
|
25 |
#include "cunsoliciteddatareq.h"
|
|
26 |
#include "csignalindreq.h"
|
|
27 |
#include "ccommandmodereq.h"
|
|
28 |
|
|
29 |
_LIT( KATExtSrvExe, "modematcontroller.exe" );
|
|
30 |
const TUid KATExtSrvUid3 = { 0x2001FCB1 };
|
|
31 |
|
|
32 |
static TInt StartServer();
|
|
33 |
|
|
34 |
EXPORT_C RModemAtController::RModemAtController() :
|
|
35 |
iAtRequest( NULL ),
|
|
36 |
iUnsolicitedDataReq( NULL ),
|
|
37 |
iSignalIndReq( NULL ),
|
|
38 |
iCommandModeReq( NULL )
|
|
39 |
{
|
|
40 |
C_TRACE((_L("RModemAtController::RModemAtController()")));
|
|
41 |
}
|
|
42 |
|
|
43 |
EXPORT_C RModemAtController::~RModemAtController()
|
|
44 |
{
|
|
45 |
C_TRACE((_L("RModemAtController::~RModemAtController()")));
|
|
46 |
if( iUnsolicitedDataReq || iAtRequest || iSignalIndReq || iCommandModeReq )
|
|
47 |
{
|
|
48 |
User::Panic( _L("NotCompleted"), 0 );
|
|
49 |
}
|
|
50 |
#ifdef _DEBUG
|
|
51 |
RThread thisRt;
|
|
52 |
TInt count = thisRt.RequestCount();
|
|
53 |
C_TRACE((_L(">RequestCount %d "), count));
|
|
54 |
#endif
|
|
55 |
|
|
56 |
#ifdef _DEBUG
|
|
57 |
count = thisRt.RequestCount();
|
|
58 |
C_TRACE((_L("<RequestCount %d "), count));
|
|
59 |
#endif
|
|
60 |
}
|
|
61 |
|
|
62 |
|
|
63 |
EXPORT_C TInt RModemAtController::Connect(
|
|
64 |
TATPluginInterface aInterface,
|
|
65 |
TDesC8& aClientName,
|
|
66 |
MAtControllerObserver* aObserver )
|
|
67 |
{
|
|
68 |
C_TRACE((_L("RModemAtController::Connect( aInterface: %d, aObserver: 0x%x)"), aInterface, aObserver));
|
|
69 |
DUMP_MESSAGE( aClientName);
|
|
70 |
#ifdef _DEBUG
|
|
71 |
RThread thisRt;
|
|
72 |
TInt count = thisRt.RequestCount();
|
|
73 |
C_TRACE((_L(">RequestCount %d "), count));
|
|
74 |
#endif
|
|
75 |
TVersion version( KServerMajorVersionNumber,
|
|
76 |
KServerMinorVersionNumber,
|
|
77 |
KServerBuildVersionNumber );
|
|
78 |
|
|
79 |
iObserver = aObserver;
|
|
80 |
iConnectedIf = aInterface;
|
|
81 |
TInt retVal = CreateSession( KATExtSrvName, version);
|
|
82 |
if ( retVal != KErrNone && retVal != KErrAlreadyExists )
|
|
83 |
{
|
|
84 |
C_TRACE((_L("RModemAtController::Connect StartServer")));
|
|
85 |
retVal = StartServer();
|
|
86 |
if ( retVal == KErrNone || retVal==KErrAlreadyExists )
|
|
87 |
{
|
|
88 |
retVal = CreateSession( KATExtSrvName, version );
|
|
89 |
}
|
|
90 |
}
|
|
91 |
|
|
92 |
C_TRACE((_L("RModemAtController::Connect CreateSession returned: %d "), retVal));
|
|
93 |
|
|
94 |
if ( retVal == KErrNone || retVal == KErrAlreadyExists )
|
|
95 |
{
|
|
96 |
TInt ifUid = aInterface;
|
|
97 |
retVal = SendReceive( EATExtSetExtensionInterface, TIpcArgs(ifUid, &aClientName) );
|
|
98 |
|
|
99 |
if( aInterface == ECommonPlugin )
|
|
100 |
{
|
|
101 |
ReceiveSignalInd();
|
|
102 |
GetCommandMode();
|
|
103 |
}
|
|
104 |
|
|
105 |
C_TRACE((_L("RModemAtController::Connect EATExtSetExtensionInterface returned: %d "), retVal));
|
|
106 |
if( retVal == KErrAlreadyExists )
|
|
107 |
{
|
|
108 |
C_TRACE( _L("RModemAtController::Connect Modem is already connected, session is ok") );
|
|
109 |
retVal = KErrNone;
|
|
110 |
}
|
|
111 |
if( retVal == KErrServerTerminated)
|
|
112 |
{
|
|
113 |
C_TRACE( _L("RModemAtController::Connect Connection failed, server has terminated") );
|
|
114 |
}
|
|
115 |
}
|
|
116 |
|
|
117 |
if ( retVal != KErrNone )
|
|
118 |
{
|
|
119 |
C_TRACE( _L("RModemAtController::Connect Closing session") );
|
|
120 |
Close();
|
|
121 |
}
|
|
122 |
#ifdef _DEBUG
|
|
123 |
count = thisRt.RequestCount();
|
|
124 |
C_TRACE((_L("<RequestCount %d "), count));
|
|
125 |
#endif
|
|
126 |
return retVal;
|
|
127 |
}
|
|
128 |
|
|
129 |
EXPORT_C TInt RModemAtController::Disconnect()
|
|
130 |
{
|
|
131 |
C_TRACE((_L("RModemAtController::Disconnect()")));
|
|
132 |
|
|
133 |
#ifdef _DEBUG
|
|
134 |
RThread thisRt;
|
|
135 |
TInt count = thisRt.RequestCount();
|
|
136 |
C_TRACE((_L(">RequestCount %d "), count));
|
|
137 |
#endif
|
|
138 |
|
|
139 |
C_TRACE((_L("RModemAtController session base handle: %d "), Handle()));
|
|
140 |
if( Handle() )
|
|
141 |
{
|
|
142 |
C_TRACE((_L("RModemAtController::Disconnect() remove pipe")));
|
|
143 |
SendReceiveRemovePipe();
|
|
144 |
}
|
|
145 |
|
|
146 |
ReceiveSignalIndCancel( );
|
|
147 |
GetCommandModeCancel();
|
|
148 |
ReceiveUnsolicitedResultCancel();
|
|
149 |
HandleATCommandCancel();
|
|
150 |
|
|
151 |
Close();
|
|
152 |
|
|
153 |
#ifdef _DEBUG
|
|
154 |
count = thisRt.RequestCount();
|
|
155 |
C_TRACE((_L("<RequestCount %d "), count));
|
|
156 |
#endif
|
|
157 |
|
|
158 |
return KErrNone;
|
|
159 |
}
|
|
160 |
|
|
161 |
EXPORT_C TInt RModemAtController::HandleATCommand(const TDesC8& aCommand, TDes8& aResponse )
|
|
162 |
{
|
|
163 |
C_TRACE((_L("RModemAtController::HandleATCommand") ));
|
|
164 |
DUMP_MESSAGE( aCommand);
|
|
165 |
if( iAtRequest )
|
|
166 |
{
|
|
167 |
TRACE_ASSERT_ALWAYS;
|
|
168 |
return KErrAlreadyExists;
|
|
169 |
}
|
|
170 |
|
|
171 |
TRAPD( err, iAtRequest = new (ELeave)CAtCommandReq( this, aCommand, aResponse) );
|
|
172 |
ASSERT_PANIC_ALWAYS( err == KErrNone );
|
|
173 |
return KErrNone;
|
|
174 |
}
|
|
175 |
|
|
176 |
EXPORT_C TInt RModemAtController::HandleATCommandCancel()
|
|
177 |
{
|
|
178 |
C_TRACE((_L("RModemAtController::HandleATCommandCancel")));
|
|
179 |
if( iAtRequest )
|
|
180 |
{
|
|
181 |
C_TRACE((_L("Cancelling...") ));
|
|
182 |
iAtRequest->Cancel();
|
|
183 |
delete iAtRequest;
|
|
184 |
iAtRequest=NULL;
|
|
185 |
}
|
|
186 |
return KErrNone;
|
|
187 |
}
|
|
188 |
|
|
189 |
EXPORT_C TInt RModemAtController::ReceiveSignalInd()
|
|
190 |
{
|
|
191 |
C_TRACE((_L("RModemAtController::ReceiveSignalInd")));
|
|
192 |
if( iSignalIndReq )
|
|
193 |
{
|
|
194 |
TRACE_ASSERT_ALWAYS;
|
|
195 |
return KErrAlreadyExists;
|
|
196 |
}
|
|
197 |
TRAPD( err, iSignalIndReq = new (ELeave) CSignalIndReq( this ) );
|
|
198 |
ASSERT_PANIC_ALWAYS( err == KErrNone );
|
|
199 |
return KErrNone;
|
|
200 |
}
|
|
201 |
|
|
202 |
|
|
203 |
EXPORT_C TInt RModemAtController::ReceiveSignalIndCancel( )
|
|
204 |
{
|
|
205 |
C_TRACE((_L("RModemAtController::ReceiveSignalIndCancel")));
|
|
206 |
if( iSignalIndReq )
|
|
207 |
{
|
|
208 |
C_TRACE((_L("Canceling...") ));
|
|
209 |
iSignalIndReq->Cancel();
|
|
210 |
delete iSignalIndReq;
|
|
211 |
iSignalIndReq = NULL; //iSignalIndReq will delete itself when cancelled
|
|
212 |
}
|
|
213 |
return KErrNone;
|
|
214 |
}
|
|
215 |
|
|
216 |
EXPORT_C TInt RModemAtController::ReceiveUnsolicitedResult( TDes8& aResult )
|
|
217 |
{
|
|
218 |
C_TRACE((_L("RModemAtController::ReceiveUnsolicitedResult")));
|
|
219 |
if( iUnsolicitedDataReq )
|
|
220 |
{
|
|
221 |
TRACE_ASSERT_ALWAYS;
|
|
222 |
return KErrAlreadyExists;
|
|
223 |
}
|
|
224 |
TRAPD( err, iUnsolicitedDataReq = new (ELeave) CUnsolicitedDataReq( this, aResult ) );
|
|
225 |
ASSERT_PANIC_ALWAYS( err == KErrNone );
|
|
226 |
return KErrNone;
|
|
227 |
}
|
|
228 |
|
|
229 |
EXPORT_C TInt RModemAtController::ReceiveUnsolicitedResultCancel( )
|
|
230 |
{
|
|
231 |
C_TRACE((_L("RModemAtController::ReceiveUnsolicitedResultCancel")));
|
|
232 |
if( iUnsolicitedDataReq )
|
|
233 |
{
|
|
234 |
C_TRACE((_L("Canceling...")));
|
|
235 |
iUnsolicitedDataReq->Cancel();
|
|
236 |
delete iUnsolicitedDataReq;
|
|
237 |
iUnsolicitedDataReq = NULL;
|
|
238 |
}
|
|
239 |
return KErrNone;
|
|
240 |
}
|
|
241 |
|
|
242 |
EXPORT_C TInt RModemAtController::GetNvramStatus(TDesC8& aCommand, TDes8& aResponse )
|
|
243 |
{
|
|
244 |
C_TRACE((_L("RModemAtController::GetNvramStatus")));
|
|
245 |
aResponse = _L8(""); //ensure, that response buffer is empty
|
|
246 |
TInt status = SendReceive( EModemATGetNvramStatus, TIpcArgs(&aCommand, &aResponse));
|
|
247 |
return status;
|
|
248 |
}
|
|
249 |
|
|
250 |
|
|
251 |
EXPORT_C TInt RModemAtController::GetCommandMode()
|
|
252 |
{
|
|
253 |
C_TRACE((_L("RModemAtController::GetCommandMode")));
|
|
254 |
|
|
255 |
if( iCommandModeReq )
|
|
256 |
{
|
|
257 |
TRACE_ASSERT_ALWAYS;
|
|
258 |
return KErrAlreadyExists;
|
|
259 |
}
|
|
260 |
TRAPD( err, iCommandModeReq = new (ELeave) CCommandModeReq( this ) );
|
|
261 |
ASSERT_PANIC_ALWAYS( err == KErrNone );
|
|
262 |
return KErrNone;
|
|
263 |
}
|
|
264 |
|
|
265 |
EXPORT_C TInt RModemAtController::GetCommandModeCancel()
|
|
266 |
{
|
|
267 |
C_TRACE((_L("RModemAtController::GetCommandMode")));
|
|
268 |
if( iCommandModeReq )
|
|
269 |
{
|
|
270 |
C_TRACE((_L("Canceling...")));
|
|
271 |
iCommandModeReq->Cancel();
|
|
272 |
delete iCommandModeReq;
|
|
273 |
iCommandModeReq = NULL;
|
|
274 |
}
|
|
275 |
return KErrNone;
|
|
276 |
}
|
|
277 |
|
|
278 |
EXPORT_C TInt RModemAtController::RemovePipe()
|
|
279 |
{
|
|
280 |
C_TRACE((_L("RModemAtController::RemovePipe")));
|
|
281 |
SendReceiveRemovePipe();
|
|
282 |
return KErrNone;
|
|
283 |
}
|
|
284 |
|
|
285 |
//called by reqs
|
|
286 |
|
|
287 |
void RModemAtController::SendReceiveATCommand( const TDesC8& aCommand,
|
|
288 |
TDes8& aResponse,
|
|
289 |
TRequestStatus& aStatus )
|
|
290 |
{
|
|
291 |
C_TRACE((_L("RModemAtController::SendReceiveATCommand acommand len=%d aresponse len=%d"), aCommand.Length(), aResponse.Length() ));
|
|
292 |
SendReceive( EModemATHandleCommand, TIpcArgs(&aCommand, &aResponse), aStatus);
|
|
293 |
}
|
|
294 |
|
|
295 |
void RModemAtController::SendReceiveUnsolicitedResult( TDes8& aResponse,TRequestStatus& aStatus)
|
|
296 |
{
|
|
297 |
C_TRACE((_L("RModemAtController::SendReceiveUnsolicitedResult")));
|
|
298 |
SendReceive( EReceiveUnsolicitedResult, TIpcArgs(&aResponse), aStatus);
|
|
299 |
}
|
|
300 |
|
|
301 |
void RModemAtController::SendReceiveUnsolicitedResulCancel()
|
|
302 |
{
|
|
303 |
C_TRACE((_L("RModemAtController::SendReceiveUnsolicitedResulCancel")));
|
|
304 |
TInt i = 0;
|
|
305 |
SendReceive( EReceiveUnsolicitedResultCancel, TIpcArgs(i) );
|
|
306 |
}
|
|
307 |
|
|
308 |
void RModemAtController::SendReceiveSignalInd(TRequestStatus& aStatus)
|
|
309 |
{
|
|
310 |
C_TRACE((_L("RModemAtController::SendReceiveSignalInd()")));
|
|
311 |
TInt value = 0;
|
|
312 |
SendReceive( EModemATReceiveSignalInd, TIpcArgs(&value),aStatus);
|
|
313 |
}
|
|
314 |
|
|
315 |
void RModemAtController::SendReceiveAtCommandCancel()
|
|
316 |
{
|
|
317 |
C_TRACE((_L("RModemAtController::SendReceiveAtCommandCancel()")));
|
|
318 |
TInt i=0;
|
|
319 |
SendReceive( EModemATHandleCommandCancel,TIpcArgs(i));
|
|
320 |
}
|
|
321 |
|
|
322 |
void RModemAtController::SignalIndReceived( TInt aErr )
|
|
323 |
{
|
|
324 |
C_TRACE((_L("RModemAtController::SignalIndReceived(%d)"), aErr));
|
|
325 |
iObserver->HandleSignalIndication( aErr );
|
|
326 |
}
|
|
327 |
|
|
328 |
void RModemAtController::SendReceiveSignalIndCancel()
|
|
329 |
{
|
|
330 |
C_TRACE((_L("RModemAtController::SendReceiveSignalIndCancel()")));
|
|
331 |
TInt value = 0;
|
|
332 |
SendReceive( EModemATReceiveSignalIndCancel, TIpcArgs(&value));
|
|
333 |
}
|
|
334 |
|
|
335 |
void RModemAtController::ATCommandResponseReceived( TInt aErr )
|
|
336 |
{
|
|
337 |
C_TRACE((_L("RModemAtController::ATCommandResponseReceived(%d)"), aErr));
|
|
338 |
iObserver->HandleATCommandCompleted(aErr);
|
|
339 |
iAtRequest = NULL;
|
|
340 |
}
|
|
341 |
|
|
342 |
void RModemAtController::UnsolicitedResultReceived( TInt aErr )
|
|
343 |
{
|
|
344 |
C_TRACE((_L("RModemAtController::UnsolicitedResultReceived(%d)"), aErr));
|
|
345 |
iObserver->HandleUnsolicitedResultReceived( aErr );
|
|
346 |
}
|
|
347 |
|
|
348 |
void RModemAtController::SendReceiveCommandMode(TDes8& aResponse, TRequestStatus& aStatus)
|
|
349 |
{
|
|
350 |
C_TRACE((_L("RModemAtController::SendReceiveCommandMode()")));
|
|
351 |
SendReceive( EModemATCommandMode, TIpcArgs(&aResponse), aStatus);
|
|
352 |
}
|
|
353 |
|
|
354 |
void RModemAtController::SendReceiveCommandModeCancel()
|
|
355 |
{
|
|
356 |
C_TRACE((_L("RModemAtController::SendReceiveCommandModeCancel()")));
|
|
357 |
TInt value = 0;
|
|
358 |
SendReceive( EModemATCommandModeCancel, TIpcArgs(&value));
|
|
359 |
}
|
|
360 |
|
|
361 |
void RModemAtController::CommandModeChanged( TInt aErr, TCommandMode aMode )
|
|
362 |
{
|
|
363 |
C_TRACE((_L("RModemAtController::CommandModeChanged(%d, %d)"), aErr, aMode));
|
|
364 |
iObserver->HandleCommandModeChanged( aErr, aMode );
|
|
365 |
}
|
|
366 |
|
|
367 |
TInt StartServer()
|
|
368 |
{
|
|
369 |
C_TRACE((_L("RModemAtController::StartServer()")));
|
|
370 |
const TUidType serverUid( KNullUid, KNullUid, KATExtSrvUid3 );
|
|
371 |
RProcess server;
|
|
372 |
TInt retTemp = server.Create( KATExtSrvExe, KNullDesC, serverUid );
|
|
373 |
server.SetPriority( EPriorityHigh );
|
|
374 |
if ( retTemp != KErrNone )
|
|
375 |
{
|
|
376 |
return retTemp;
|
|
377 |
}
|
|
378 |
TRequestStatus status;
|
|
379 |
server.Rendezvous( status );
|
|
380 |
if ( status != KRequestPending )
|
|
381 |
{
|
|
382 |
server.Kill( 0 );
|
|
383 |
}
|
|
384 |
else
|
|
385 |
{
|
|
386 |
server.Resume();
|
|
387 |
}
|
|
388 |
User::WaitForRequest( status );
|
|
389 |
C_TRACE((_L("Server started, code %d"), status.Int()));
|
|
390 |
retTemp = ( server.ExitType() == EExitPanic ) ? KErrGeneral : status.Int();
|
|
391 |
server.Close();
|
|
392 |
return retTemp;
|
|
393 |
}
|
|
394 |
|
|
395 |
void RModemAtController::SendReceiveRemovePipe()
|
|
396 |
{
|
|
397 |
C_TRACE((_L(">>RModemAtController::SendReceiveRemovePipe()")));
|
|
398 |
TInt value = 0;
|
|
399 |
TRequestStatus removePipeStatus = KRequestPending;
|
|
400 |
SendReceive( EModemAtRemovePipe, TIpcArgs(&value), removePipeStatus);
|
|
401 |
User::WaitForRequest( removePipeStatus );
|
|
402 |
C_TRACE((_L("<<RModemAtController::SendReceiveRemovePipe()")));
|
|
403 |
}
|
|
404 |
|