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 "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 |
#include "toolssrvserver.h"
|
|
19 |
|
|
20 |
// System includes
|
|
21 |
#include <e32base.h>
|
|
22 |
|
|
23 |
// User includes
|
|
24 |
#include "toolssrvsession.h"
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
// Type definitions
|
|
29 |
|
|
30 |
// Constants
|
|
31 |
#define METROTRK_SID 0x200170BB
|
|
32 |
// Enumerations
|
|
33 |
|
|
34 |
// Classes referenced
|
|
35 |
|
|
36 |
#ifdef EKA2
|
|
37 |
//Only include these in the secured platform
|
|
38 |
#include "ToolsCmdCodes.h"
|
|
39 |
|
|
40 |
const TUint KRangeCount = 2;
|
|
41 |
|
|
42 |
const TInt KOpCodeRanges[KRangeCount] =
|
|
43 |
{
|
|
44 |
KCapabilityCustomCheck,
|
|
45 |
EToolsCmdCodeLast,
|
|
46 |
};
|
|
47 |
|
|
48 |
|
|
49 |
const TUint8 KElementsIndex[KRangeCount] =
|
|
50 |
{
|
|
51 |
CPolicyServer::ECustomCheck, //Custom check for the MetroTrk SID 0 - EToolsCmdCodeLast
|
|
52 |
CPolicyServer::ENotSupported, //Not Supported EToolsCmdCodeLast-End
|
|
53 |
};
|
|
54 |
|
|
55 |
const CPolicyServer::TPolicyElement KPolicyElements[] =
|
|
56 |
{
|
|
57 |
{_INIT_SECURITY_POLICY_S0(METROTRK_SID), CPolicyServer::EFailClient},
|
|
58 |
};
|
|
59 |
|
|
60 |
const CPolicyServer::TPolicy KToolsServerPolicy =
|
|
61 |
{
|
|
62 |
CPolicyServer::EAlwaysPass, //specifies all connect attempts should pass
|
|
63 |
KRangeCount,
|
|
64 |
KOpCodeRanges,
|
|
65 |
KElementsIndex, // what each range is compared to
|
|
66 |
KPolicyElements // what policies range is compared to
|
|
67 |
};
|
|
68 |
|
|
69 |
#endif
|
|
70 |
|
|
71 |
|
|
72 |
//
|
|
73 |
// CToolsSrvServer (source)
|
|
74 |
//
|
|
75 |
|
|
76 |
//
|
|
77 |
// CToolsSrvServer::CToolsSrvServer()
|
|
78 |
//
|
|
79 |
// Constructor
|
|
80 |
//
|
|
81 |
CToolsSrvServer::CToolsSrvServer()
|
|
82 |
#ifdef EKA2
|
|
83 |
:CPolicyServer(CActive::EPriorityHigh, KToolsServerPolicy),
|
|
84 |
#else
|
|
85 |
:CServer2(CActive::EPriorityHigh),
|
|
86 |
#endif
|
|
87 |
iSessionCount(0)
|
|
88 |
{
|
|
89 |
}
|
|
90 |
|
|
91 |
//
|
|
92 |
// CToolsSrvServer::~CToolsSrvServer()
|
|
93 |
//
|
|
94 |
// Destructor
|
|
95 |
//
|
|
96 |
CToolsSrvServer::~CToolsSrvServer()
|
|
97 |
{
|
|
98 |
// In order to prevent access violations as the server
|
|
99 |
// shuts down, we inform all sessions that the server is
|
|
100 |
// about to be destroyed
|
|
101 |
iSessionIter.SetToFirst();
|
|
102 |
//
|
|
103 |
CToolsSrvSession* session = static_cast<CToolsSrvSession*>(iSessionIter++);
|
|
104 |
while (session)
|
|
105 |
{
|
|
106 |
session->HandleServerDestruction();
|
|
107 |
session = static_cast<CToolsSrvSession*>(iSessionIter++);
|
|
108 |
}
|
|
109 |
if(iLaunchManager)
|
|
110 |
delete iLaunchManager;
|
|
111 |
|
|
112 |
}
|
|
113 |
|
|
114 |
//
|
|
115 |
// CToolsSrvServer::ConstructL()
|
|
116 |
//
|
|
117 |
// Second level construction
|
|
118 |
//
|
|
119 |
void CToolsSrvServer::ConstructL()
|
|
120 |
{
|
|
121 |
// Calling StartL here won't actually allow any connections
|
|
122 |
// to be created until the active scheduler has a chance to run. However, the
|
|
123 |
// call below will leave should there already be a started Tools server instance.
|
|
124 |
//
|
|
125 |
StartL(KToolsServerName);
|
|
126 |
//Launching the tools
|
|
127 |
iLaunchManager = CToolsLaunchMgr::NewL();
|
|
128 |
if (iLaunchManager)
|
|
129 |
iLaunchManager->Launch();
|
|
130 |
}
|
|
131 |
|
|
132 |
//
|
|
133 |
// CToolsSrvServer::NewLC()
|
|
134 |
//
|
|
135 |
// Creates an instance of CToolsSrvServer.
|
|
136 |
//
|
|
137 |
CToolsSrvServer* CToolsSrvServer::NewLC()
|
|
138 |
{
|
|
139 |
CToolsSrvServer* self = new(ELeave) CToolsSrvServer();
|
|
140 |
CleanupStack::PushL(self);
|
|
141 |
self->ConstructL();
|
|
142 |
return self;
|
|
143 |
}
|
|
144 |
|
|
145 |
//
|
|
146 |
// CToolsSrvServer::NewSessionL()
|
|
147 |
//
|
|
148 |
// Creates a new session.
|
|
149 |
// Called by the IPC framework everytime a client creates a new session.
|
|
150 |
// Returns a CToolsSrvSession object.
|
|
151 |
//
|
|
152 |
CSession2* CToolsSrvServer::NewSessionL(const TVersion& aVersion,const RMessage2& /*aMessage*/) const
|
|
153 |
{
|
|
154 |
// Check client version is correct
|
|
155 |
const TVersion ToolsServerVersion(KToolsServerMajorVN, KToolsServerMinorVN, KToolsServerBuildVN);
|
|
156 |
if (!User::QueryVersionSupported(ToolsServerVersion, aVersion))
|
|
157 |
User::Leave(KErrNotSupported);
|
|
158 |
|
|
159 |
// Create new session
|
|
160 |
CToolsSrvSession* session = CToolsSrvSession::NewL();
|
|
161 |
return session;
|
|
162 |
}
|
|
163 |
|
|
164 |
//
|
|
165 |
// CToolsSrvServer::RunError()
|
|
166 |
//
|
|
167 |
// Handles all the errors when handling a client request.
|
|
168 |
// Called by the IPC framework whenever a leave occurs when handling a client request.
|
|
169 |
// Returns KErrNone to complete the error handling.
|
|
170 |
//
|
|
171 |
TInt CToolsSrvServer::RunError(TInt aError)
|
|
172 |
{
|
|
173 |
// A bad descriptor error implies a badly programmed client, so panic it;
|
|
174 |
// otherwise report the error to the client
|
|
175 |
if (aError == KErrBadDescriptor)
|
|
176 |
{
|
|
177 |
Message().Panic(KServerIntiatedSessionPanic, EToolsServerInitiatedClientPanicBadDescriptor);
|
|
178 |
}
|
|
179 |
else
|
|
180 |
{
|
|
181 |
Message().Complete(aError);
|
|
182 |
}
|
|
183 |
|
|
184 |
// The leave will result in an early return from CServer2::RunL(), skipping
|
|
185 |
// the call to request another message. So do that now in order to keep the
|
|
186 |
// server running.
|
|
187 |
ReStart();
|
|
188 |
|
|
189 |
// Indicate that we've handled the error fully
|
|
190 |
return KErrNone;
|
|
191 |
}
|
|
192 |
|
|
193 |
#ifdef EKA2
|
|
194 |
//
|
|
195 |
// CToolsSrvServer::CustomSecurityCheckL()
|
|
196 |
//
|
|
197 |
// The only security check that is done is to check for the cleint securid
|
|
198 |
// Returns EFail or EPass
|
|
199 |
//
|
|
200 |
CPolicyServer::TCustomResult CToolsSrvServer::CustomSecurityCheckL(const RMessage2& aMsg, TInt& /*aAction*/, TSecurityInfo& /*aMissing*/)
|
|
201 |
{
|
|
202 |
CPolicyServer::TCustomResult returnValue = CPolicyServer::EFail;
|
|
203 |
|
|
204 |
TSecureId ClientSID = aMsg.SecureId();
|
|
205 |
// We only permit MetroTrk to use this server. So we check
|
|
206 |
// for MetroTrk's SIDs. If its not MetroTrk's SIDs, then the security check fails.
|
|
207 |
if ((KTrkServerUid == ClientSID) || (KTraceServerUid == ClientSID) || (KToolsClientUid == ClientSID))
|
|
208 |
{
|
|
209 |
returnValue = CPolicyServer::EPass;
|
|
210 |
}
|
|
211 |
return(returnValue);
|
|
212 |
}
|
|
213 |
#endif
|
|
214 |
|
|
215 |
|
|
216 |
/**
|
|
217 |
Decrements the server's count of how many sessions are connected to it and
|
|
218 |
starts the shutdown timer if there are no sessions connected
|
|
219 |
*/
|
|
220 |
void CToolsSrvServer::SessionClosed()
|
|
221 |
{
|
|
222 |
if(--iSessionCount < 1)
|
|
223 |
{
|
|
224 |
|
|
225 |
}
|
|
226 |
}
|
|
227 |
|
|
228 |
/**
|
|
229 |
Increments the servers count of how many sessions are connected to it and
|
|
230 |
cancels the shutdown timer if it is running
|
|
231 |
*/
|
|
232 |
void CToolsSrvServer::SessionOpened()
|
|
233 |
{
|
|
234 |
iSessionCount++;
|
|
235 |
|
|
236 |
}
|
|
237 |
/*
|
|
238 |
* To get the USB connection status
|
|
239 |
*
|
|
240 |
*/
|
|
241 |
TConnectionStatus CToolsSrvServer::GetUsbConnStatus()
|
|
242 |
{
|
|
243 |
return(iLaunchManager->GetUsbConnStatus());
|
|
244 |
|
|
245 |
}
|