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 "trksrvserver.h"
|
|
19 |
|
|
20 |
// System includes
|
|
21 |
#include <e32base.h>
|
|
22 |
#include <e32debug.h>
|
|
23 |
|
|
24 |
// User includes
|
|
25 |
#include "trksrvsession.h"
|
|
26 |
|
|
27 |
|
|
28 |
// Type definitions
|
|
29 |
|
|
30 |
// Constants
|
|
31 |
#define METROTRK_SID 0x200170BB
|
|
32 |
// Enumerations
|
|
33 |
|
|
34 |
// Classes referenced
|
|
35 |
|
|
36 |
//Only include these in the secured platform
|
|
37 |
#include "trksrvcmdcodes.h"
|
|
38 |
|
|
39 |
const TUint KRangeCount = 2;
|
|
40 |
|
|
41 |
const TInt KOpCodeRanges[KRangeCount] =
|
|
42 |
{
|
|
43 |
KCapabilityCustomCheck,
|
|
44 |
ETrkCmdCodeLast,
|
|
45 |
};
|
|
46 |
|
|
47 |
|
|
48 |
const TUint8 KElementsIndex[KRangeCount] =
|
|
49 |
{
|
|
50 |
CPolicyServer::ECustomCheck, //Custom check for the MetroTrk SID 0 - ETrkCmdCodeLast
|
|
51 |
CPolicyServer::ENotSupported, //Not Supported ETrkCmdCodeLast-End
|
|
52 |
};
|
|
53 |
|
|
54 |
const CPolicyServer::TPolicy KTrkServerPolicy =
|
|
55 |
{
|
|
56 |
CPolicyServer::EAlwaysPass, //specifies all connect attempts should pass
|
|
57 |
KRangeCount,
|
|
58 |
KOpCodeRanges,
|
|
59 |
KElementsIndex, // what each range is compared to
|
|
60 |
NULL // what policies range is compared to
|
|
61 |
};
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
//
|
|
66 |
// CTrkSrvServer (source)
|
|
67 |
//
|
|
68 |
|
|
69 |
//
|
|
70 |
// CTrkSrvServer::CTrkSrvServer()
|
|
71 |
//
|
|
72 |
// Constructor
|
|
73 |
//
|
|
74 |
CTrkSrvServer::CTrkSrvServer(CTrkDebugManager* aTrkDebugMgr)
|
|
75 |
#ifdef EKA2
|
|
76 |
:CPolicyServer(CActive::EPriorityHigh, KTrkServerPolicy),
|
|
77 |
#else
|
|
78 |
:CServer2(CActive::EPriorityHigh),
|
|
79 |
#endif
|
|
80 |
iTrkDebugMgr(aTrkDebugMgr)
|
|
81 |
{
|
|
82 |
}
|
|
83 |
|
|
84 |
//
|
|
85 |
// CTrkSrvServer::~CTrkSrvServer()
|
|
86 |
//
|
|
87 |
// Destructor
|
|
88 |
//
|
|
89 |
CTrkSrvServer::~CTrkSrvServer()
|
|
90 |
{
|
|
91 |
// In order to prevent access violations as the server
|
|
92 |
// shuts down, we inform all sessions that the server is
|
|
93 |
// about to be destroyed
|
|
94 |
iSessionIter.SetToFirst();
|
|
95 |
//
|
|
96 |
CTrkSrvSession* session = static_cast<CTrkSrvSession*>(iSessionIter++);
|
|
97 |
while (session)
|
|
98 |
{
|
|
99 |
session->HandleServerDestruction();
|
|
100 |
session = static_cast<CTrkSrvSession*>(iSessionIter++);
|
|
101 |
}
|
|
102 |
}
|
|
103 |
|
|
104 |
//
|
|
105 |
// CTrkSrvServer::ConstructL()
|
|
106 |
//
|
|
107 |
// Second level construction
|
|
108 |
//
|
|
109 |
void CTrkSrvServer::ConstructL()
|
|
110 |
{
|
|
111 |
// Calling StartL here won't actually allow any connections
|
|
112 |
// to be created until the active scheduler has a chance to run. However, the
|
|
113 |
// call below will leave should there already be a started Trk server instance.
|
|
114 |
//
|
|
115 |
StartL(KTrkServerName);
|
|
116 |
}
|
|
117 |
|
|
118 |
//
|
|
119 |
// CTrkSrvServer::NewLC()
|
|
120 |
//
|
|
121 |
// Creates an instance of CTrkSrvServer.
|
|
122 |
//
|
|
123 |
CTrkSrvServer* CTrkSrvServer::NewLC(CTrkDebugManager* aTrkDebugMgr)
|
|
124 |
{
|
|
125 |
CTrkSrvServer* self = new(ELeave) CTrkSrvServer(aTrkDebugMgr);
|
|
126 |
CleanupStack::PushL(self);
|
|
127 |
self->ConstructL();
|
|
128 |
return self;
|
|
129 |
}
|
|
130 |
|
|
131 |
//
|
|
132 |
// CTrkSrvServer::NewSessionL()
|
|
133 |
//
|
|
134 |
// Creates a new session.
|
|
135 |
// Called by the IPC framework everytime a client creates a new session.
|
|
136 |
// Returns a CTrkSrvSession object.
|
|
137 |
//
|
|
138 |
CSession2* CTrkSrvServer::NewSessionL(const TVersion& aVersion,const RMessage2& /*aMessage*/) const
|
|
139 |
{
|
|
140 |
// Check client version is correct
|
|
141 |
const TVersion trkServerVersion(KTrkServerMajorVN, KTrkServerMinorVN, KTrkServerBuildVN);
|
|
142 |
if (!User::QueryVersionSupported(trkServerVersion, aVersion))
|
|
143 |
User::Leave(KErrNotSupported);
|
|
144 |
|
|
145 |
// Create new session
|
|
146 |
CTrkSrvSession* session = CTrkSrvSession::NewL(iTrkDebugMgr);
|
|
147 |
return session;
|
|
148 |
}
|
|
149 |
|
|
150 |
//
|
|
151 |
// CTrkSrvServer::RunError()
|
|
152 |
//
|
|
153 |
// Handles all the errors when handling a client request.
|
|
154 |
// Called by the IPC framework whenever a leave occurs when handling a client request.
|
|
155 |
// Returns KErrNone to complete the error handling.
|
|
156 |
//
|
|
157 |
TInt CTrkSrvServer::RunError(TInt aError)
|
|
158 |
{
|
|
159 |
// A bad descriptor error implies a badly programmed client, so panic it;
|
|
160 |
// otherwise report the error to the client
|
|
161 |
if (aError == KErrBadDescriptor)
|
|
162 |
{
|
|
163 |
Message().Panic(KServerIntiatedSessionPanic, ETrkServerInitiatedClientPanicBadDescriptor);
|
|
164 |
}
|
|
165 |
else
|
|
166 |
{
|
|
167 |
Message().Complete(aError);
|
|
168 |
}
|
|
169 |
|
|
170 |
// The leave will result in an early return from CServer2::RunL(), skipping
|
|
171 |
// the call to request another message. So do that now in order to keep the
|
|
172 |
// server running.
|
|
173 |
ReStart();
|
|
174 |
|
|
175 |
// Indicate that we've handled the error fully
|
|
176 |
return KErrNone;
|
|
177 |
}
|
|
178 |
|
|
179 |
#ifdef EKA2
|
|
180 |
//
|
|
181 |
// CTrkSrvServer::CustomSecurityCheckL()
|
|
182 |
//
|
|
183 |
// The only security check that is done is to check for the cleint securid
|
|
184 |
// Returns EFail or EPass
|
|
185 |
//
|
|
186 |
CPolicyServer::TCustomResult CTrkSrvServer::CustomSecurityCheckL(const RMessage2& aMsg, TInt& /*aAction*/, TSecurityInfo& /*aMissing*/)
|
|
187 |
{
|
|
188 |
CPolicyServer::TCustomResult returnValue = CPolicyServer::EFail;
|
|
189 |
|
|
190 |
TSecureId ClientSID = aMsg.SecureId();
|
|
191 |
// We only permit MetroTrk to use this server. So we check
|
|
192 |
// for MetroTrk's SIDs. If its not MetroTrk's SIDs, then the security check fails.
|
|
193 |
if ((KTrkAppUid == ClientSID) || (KTrkExeUid == ClientSID))
|
|
194 |
{
|
|
195 |
returnValue = CPolicyServer::EPass;
|
|
196 |
}
|
|
197 |
return(returnValue);
|
|
198 |
}
|
|
199 |
#endif
|