|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // server side exmaple of how to use the abstract server framework |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32debug.h> |
|
19 #include "lbsdevloggermacros.h" |
|
20 |
|
21 #include "lbsnrhprivacycontrollerserver.h" |
|
22 #include "lbsnrhx3pserver.h" |
|
23 #include "opensessionparams.h" |
|
24 #include "lbsnrhserverdata.h" |
|
25 #include "lbsnrhmessageenums.h" |
|
26 |
|
27 const TInt KLbsLogQueueSize = 30; |
|
28 |
|
29 // |
|
30 // Security policy data structures |
|
31 // |
|
32 |
|
33 const TUint myRangeCount = 7; |
|
34 |
|
35 const TInt myRanges[myRangeCount] = |
|
36 { |
|
37 0, //range is 0-1 inclusive |
|
38 ESecureSubSessionBaseClose, //range is 2 to (ENrhPrivacyControllerSubSessionFirstMessageId - 1) |
|
39 ENrhPrivacyControllerRegister, // Register a MLbsPrivacyObserver for callbacks |
|
40 ENrhPrivacyControllerResponse, // All other CLbsPrivacyController functions |
|
41 ENrhPrivacyControllerSubSessionLastMessageId, // Range between last privacy handler message |
|
42 // and first X3P message. |
|
43 EX3pSubSessionFirstMessageId, // All X3P messages |
|
44 EX3pSubSessionLastMessageId // Remaining messages. |
|
45 }; |
|
46 const TUint8 myElementsIndex[myRangeCount] = |
|
47 { |
|
48 CPolicyServer::ECustomCheck, |
|
49 CPolicyServer::ENotSupported, |
|
50 0, |
|
51 1, |
|
52 CPolicyServer::ENotSupported, |
|
53 2, |
|
54 CPolicyServer::ENotSupported |
|
55 }; |
|
56 |
|
57 const CPolicyServer::TPolicyElement myElements[] = |
|
58 { |
|
59 {_INIT_SECURITY_POLICY_C2(ECapabilityLocation, ECapabilityReadDeviceData), CPolicyServer::EFailClient}, |
|
60 {_INIT_SECURITY_POLICY_C2(ECapabilityLocation, ECapabilityWriteDeviceData), CPolicyServer::EFailClient}, |
|
61 {_INIT_SECURITY_POLICY_C2(ECapabilityLocation, ECapabilityNetworkServices), CPolicyServer::EFailClient} |
|
62 }; |
|
63 |
|
64 const CPolicyServer::TPolicy myPolicy = |
|
65 { |
|
66 CPolicyServer::EAlwaysPass, //specifies all connect attempts should pass |
|
67 myRangeCount, |
|
68 myRanges, |
|
69 myElementsIndex, |
|
70 myElements, |
|
71 }; |
|
72 |
|
73 // |
|
74 // Server Framework Function Implementations |
|
75 // |
|
76 |
|
77 MCreateServerImpl* CSecureASBase::GetImplLC() |
|
78 { |
|
79 CNrhServerImpl* impl = new(ELeave) CNrhServerImpl(); |
|
80 CleanupStack::PushL(impl); |
|
81 return impl; |
|
82 } |
|
83 |
|
84 void CNrhServerImpl::CreateServerLC(TServerStartParams& aParams) |
|
85 { |
|
86 CNrhServer* s = new(ELeave) CNrhServer(CActive::EPriorityStandard, myPolicy); |
|
87 CleanupStack::PushL(s); |
|
88 s->ConstructL(aParams.GetServerName()); |
|
89 // leave the server object on the CS |
|
90 } |
|
91 |
|
92 // |
|
93 // CNrhServer |
|
94 // |
|
95 |
|
96 RLbsLogger CNrhServer::iLogger; |
|
97 |
|
98 CNrhServer::CNrhServer(TInt aPriority, const CPolicyServer::TPolicy& aSecurityPolicy) |
|
99 : CSecureServerBase(aPriority, aSecurityPolicy), |
|
100 iVersion(KNrhServerMajorVersionNumber, |
|
101 KNrhServerMinorVersionNumber, |
|
102 KNrhServerBuildVersionNumber) |
|
103 { |
|
104 } |
|
105 |
|
106 CNrhServer::~CNrhServer() |
|
107 { |
|
108 iLogger.Close(); |
|
109 |
|
110 iX3pObserver = NULL; |
|
111 iPrivacyObserver = NULL; |
|
112 |
|
113 delete iNetworkRequestHandler; |
|
114 delete iCloseDownRequestDetector; |
|
115 } |
|
116 |
|
117 void CNrhServer::ConstructL(const TDesC& aServerName) |
|
118 { |
|
119 StartL(aServerName); |
|
120 BaseConstructL(EFalse); // MUST BE CALLED. No shutdown timer. Makes the NRH a perm. server |
|
121 |
|
122 // Create the monitor which detects a closedown signal from |
|
123 // the LBS Root Process. |
|
124 iCloseDownRequestDetector = CLbsCloseDownRequestDetector::NewL( |
|
125 this, |
|
126 KLbsNetRequestHandlerUid); |
|
127 |
|
128 iNetworkRequestHandler = CLbsNetworkRequestHandler::NewL(this); |
|
129 |
|
130 iLogger.Open(KLbsLogQueueSize); |
|
131 } |
|
132 |
|
133 CSession2* CNrhServer::DoNewSessionL(const TVersion& /*aVersion*/, const RMessage2& /*aMessage*/) const |
|
134 { |
|
135 return new (ELeave) CNrhServerSession(); // version number already checked at this point |
|
136 } |
|
137 |
|
138 |
|
139 TVersion CNrhServer::GetServerVersion() const |
|
140 { |
|
141 return iVersion; |
|
142 } |
|
143 |
|
144 /** |
|
145 Security policies used for custom security check below: |
|
146 */ |
|
147 static _LIT_SECURITY_POLICY_C1(KLocationPolicy, ECapabilityLocation); |
|
148 static _LIT_SECURITY_POLICY_C1(KReadDeviceDataPolicy, ECapabilityReadDeviceData); |
|
149 static _LIT_SECURITY_POLICY_C1(KNetworkServicesPolicy, ECapabilityNetworkServices); |
|
150 |
|
151 |
|
152 /** |
|
153 Perform a custom security check. |
|
154 |
|
155 A custom security check is only needed for the sub-session connect |
|
156 message. The reason is that the two type of sub-sessions the NRH supports |
|
157 (X3P and privacy controller) have different PlatSec capabilities to |
|
158 create them. |
|
159 |
|
160 @param aMsg The message to check. |
|
161 @param aAction A reference to the action to take if the security check fails. |
|
162 @param aMissing A reference to the list of security attributes missing from the checked process. |
|
163 |
|
164 @return Enum specifying the result of the security check. |
|
165 */ |
|
166 CPolicyServer::TCustomResult CNrhServer::CustomSecurityCheckL(const RMessage2 &aMsg, TInt& /*aAction*/, TSecurityInfo& /*aMissing*/) |
|
167 { |
|
168 LBSLOG(ELogP1, "CNrhServer::CustomSecurityCheckL() Begin\n"); |
|
169 |
|
170 TNrhSubSessionType subSessType; |
|
171 TPckg<TNrhSubSessionType> subSessTypeBuf(subSessType); |
|
172 MessageUtils::Read(aMsg, 0, subSessTypeBuf); // data is always in slot zero |
|
173 |
|
174 // Capabilities to check depend on the type of sub-session |
|
175 CPolicyServer::TCustomResult result(EFail); |
|
176 switch (subSessType) |
|
177 { |
|
178 case ENrhSubSessionPrivacyController: |
|
179 { |
|
180 if (KLocationPolicy().CheckPolicy(aMsg) |
|
181 && KReadDeviceDataPolicy.CheckPolicy(aMsg)) |
|
182 { |
|
183 LBSLOG(ELogP1, "CNrhServer::CustomSecurityCheckL() End (PASS)\n"); |
|
184 result = EPass; |
|
185 } |
|
186 break; |
|
187 } |
|
188 case ENrhSubSessionX3P: |
|
189 { |
|
190 if (KLocationPolicy().CheckPolicy(aMsg) |
|
191 && KNetworkServicesPolicy().CheckPolicy(aMsg)) |
|
192 { |
|
193 LBSLOG(ELogP1, "CNrhServer::CustomSecurityCheckL() End (PASS)\n"); |
|
194 result = EPass; |
|
195 } |
|
196 break; |
|
197 } |
|
198 case ENrhSubSessionUnknown: |
|
199 default: |
|
200 { |
|
201 LBSLOG(ELogP1, "CNrhServer::CustomSecurityCheckL() End (FAIL)\n"); |
|
202 result = EFail; |
|
203 break; |
|
204 } |
|
205 } |
|
206 |
|
207 return result; |
|
208 } |
|
209 |
|
210 /* Called when LbsRoot has requested that the NRH should |
|
211 closedown. |
|
212 */ |
|
213 void CNrhServer::OnProcessCloseDown() |
|
214 { |
|
215 CActiveScheduler::Stop(); |
|
216 } |
|
217 |
|
218 MX3pHandlerNotifier* CNrhServer::X3pObserver() const |
|
219 { |
|
220 return(iX3pObserver); |
|
221 } |
|
222 |
|
223 void CNrhServer::SetPrivacyServerObserver(MPrivacyHandlerObserver* aObserver) |
|
224 { |
|
225 iPrivacyObserver = aObserver; |
|
226 } |
|
227 |
|
228 MPrivacyHandlerObserver* CNrhServer::PrivacyObserver() const |
|
229 { |
|
230 return(iPrivacyObserver); |
|
231 } |
|
232 |
|
233 CLbsAdmin* CNrhServer::Admin() const |
|
234 { |
|
235 return iNetworkRequestHandler->Admin(); |
|
236 } |
|
237 |
|
238 RLbsNetworkRegistrationStatus& CNrhServer::NetworkRegistrationStatus() |
|
239 { |
|
240 return iNetworkRequestHandler->NetworkRegistrationStatus(); |
|
241 } |
|
242 |
|
243 void CNrhServer::SetX3pServerObserver(MX3pHandlerNotifier* aObserver) |
|
244 { |
|
245 iX3pObserver = aObserver; |
|
246 } |
|
247 |
|
248 CNrhServerSession::~CNrhServerSession() |
|
249 { |
|
250 } |
|
251 |
|
252 // called by the CServer2 code to complete construction of the session |
|
253 void CNrhServerSession::CreateL() |
|
254 { |
|
255 CSecureSessionSubSessionBase::CreateL(); // MUST do this |
|
256 } |
|
257 |
|
258 void CNrhServerSession::ServiceMessageL(const RMessage2& /*aMessage*/) |
|
259 { |
|
260 // Got a message from the client |
|
261 } |
|
262 |
|
263 void CNrhServerSession::ServiceMessageError(const RMessage2& /*aMessage*/, const TInt /*aError*/) |
|
264 { |
|
265 // service leaves from the above in here |
|
266 } |
|
267 |
|
268 |
|
269 //------------------------------------------------------------------ |
|
270 |
|
271 MSubSessionImpl* CSubSessionBase::GetImplL(const RMessage2& aMessage) |
|
272 { |
|
273 // Read in the subsession type |
|
274 TNrhSubSessionType subSessType; |
|
275 TPckg<TNrhSubSessionType> subSessTypeBuf(subSessType); |
|
276 MessageUtils::Read(aMessage, 0, subSessTypeBuf); // data is always in slot zero |
|
277 |
|
278 // Create the subsession, depending on the type requested |
|
279 MSubSessionImpl* subSession(NULL); |
|
280 switch (subSessType) |
|
281 { |
|
282 case ENrhSubSessionPrivacyController: |
|
283 { |
|
284 subSession = CNrhPrivacyServerSubsession::NewL(); |
|
285 break; |
|
286 } |
|
287 case ENrhSubSessionX3P: |
|
288 { |
|
289 subSession = CNrhX3pServerSubsession::NewL(CNrhServer::iLogger); |
|
290 break; |
|
291 } |
|
292 case ENrhSubSessionUnknown: |
|
293 default: |
|
294 { |
|
295 _LIT(KPanicNrhServer, "Unknown SubSession Type"); |
|
296 MessageUtils::PanicClient(aMessage, KPanicNrhServer, 0); |
|
297 break; |
|
298 } |
|
299 } |
|
300 |
|
301 return subSession; |
|
302 } |
|
303 |