|
1 // Copyright (c) 2004-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 // Implementation of CSBEServer class. |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 */ |
|
21 |
|
22 #include <e32std.h> |
|
23 #include <e32base.h> |
|
24 #include "sbeclientserver.h" |
|
25 #include "sbeserver.h" |
|
26 #include "sbesession.h" |
|
27 #include <connect/panic.h> |
|
28 #include "sbedataownermanager.h" |
|
29 #include "sblog.h" |
|
30 //#include <stdlib.h> |
|
31 |
|
32 namespace conn |
|
33 { |
|
34 |
|
35 |
|
36 /** Secure Backup Engine security request ranges |
|
37 |
|
38 This is a breakdown of the SBE requests into ranges |
|
39 for security checking purposes. |
|
40 |
|
41 @internalComponent |
|
42 */ |
|
43 const TInt mySBERanges[] = {0,23}; |
|
44 |
|
45 /** Secure Backup Engine range count |
|
46 |
|
47 The number of different security ranges for SBEs request numbers |
|
48 |
|
49 @internalComponent |
|
50 */ |
|
51 const TUint mySBERangeCount = sizeof(mySBERanges)/sizeof(mySBERanges[0]); |
|
52 |
|
53 /** Secure Backup Engine security action array |
|
54 |
|
55 An array with a one-to-one mapping with the range array |
|
56 specifiying what security action to take for each server request. |
|
57 |
|
58 @internalComponent |
|
59 */ |
|
60 const TUint8 mySBEElementsIndex[mySBERangeCount] = |
|
61 { |
|
62 0, |
|
63 CPolicyServer::ENotSupported, |
|
64 }; |
|
65 |
|
66 /** |
|
67 @internalComponent |
|
68 */ |
|
69 const CPolicyServer::TPolicyElement mySBEElements[] = |
|
70 { |
|
71 {_INIT_SECURITY_POLICY_C2(ECapabilityWriteDeviceData,ECapabilityReadDeviceData) |
|
72 , CPolicyServer::EFailClient}, |
|
73 }; |
|
74 |
|
75 /** |
|
76 @internalComponent |
|
77 */ |
|
78 const CPolicyServer::TPolicy mySBEPolicy = |
|
79 { |
|
80 0, |
|
81 mySBERangeCount, |
|
82 mySBERanges, |
|
83 mySBEElementsIndex, |
|
84 mySBEElements, |
|
85 }; |
|
86 |
|
87 CSBEServer::CSBEServer(CDataOwnerManager* aDOM) |
|
88 : CPolicyServer(EPriorityNormal,mySBEPolicy), iDOM(aDOM) |
|
89 /** |
|
90 Class constructor |
|
91 */ |
|
92 { |
|
93 __ASSERT_DEBUG(aDOM, Panic(KErrArgument)); |
|
94 } |
|
95 |
|
96 CSBEServer::~CSBEServer() |
|
97 /** |
|
98 Class destructor |
|
99 */ |
|
100 { |
|
101 iGlobalSharedHeap.Close(); |
|
102 delete iGSHInterface; |
|
103 } |
|
104 |
|
105 CSBEServer* CSBEServer::NewLC(CDataOwnerManager* aDOM) |
|
106 /** |
|
107 Constructs a new instance of the CSBEServer, calls ConstructL, |
|
108 and returns it to the caller leaving it on the cleanup stack. |
|
109 |
|
110 @return The new instance of CSBEServer. |
|
111 */ |
|
112 { |
|
113 CSBEServer* pSelf = new (ELeave) CSBEServer(aDOM); |
|
114 CleanupStack::PushL(pSelf); |
|
115 pSelf->ConstructL(); |
|
116 return pSelf; |
|
117 } |
|
118 |
|
119 void CSBEServer::ConstructL() |
|
120 /** |
|
121 Construct this instance of CSBEServer. |
|
122 */ |
|
123 { |
|
124 AllocateGlobalSharedHeapL(); |
|
125 |
|
126 iGSHInterface = CHeapWrapper::NewL(); |
|
127 |
|
128 // Initialise the locked flag to be unlock |
|
129 iGSHInterface->ResetHeap(iGlobalSharedHeap); |
|
130 // |
|
131 // Start the server and a timer to stop it if nothing happens. |
|
132 StartL(KSBEServerName); |
|
133 iShutdown.ConstructL(); |
|
134 #ifndef _DEBUG |
|
135 iShutdown.Start(); |
|
136 #endif |
|
137 } |
|
138 |
|
139 void CSBEServer::AllocateGlobalSharedHeapL() |
|
140 /** |
|
141 Attempts to allocate the GSH. If initial attempts fail, it tries to allocate with |
|
142 progressively smaller chunk sizes |
|
143 */ |
|
144 { |
|
145 TInt attemptedSize; |
|
146 TInt retryCount; |
|
147 TInt redFactor; |
|
148 iDOM->Config().HeapValues(attemptedSize, retryCount, redFactor); |
|
149 |
|
150 TInt result = KErrNone; |
|
151 |
|
152 for (; retryCount > 0; retryCount--) |
|
153 { |
|
154 result = iGlobalSharedHeap.CreateGlobal(KNullDesC, attemptedSize, attemptedSize); |
|
155 |
|
156 if (result == KErrNone) |
|
157 { |
|
158 // We have succesfully allocated a GSH |
|
159 break; |
|
160 } |
|
161 else |
|
162 { |
|
163 // Reduce the size of the GSH by a scale factor |
|
164 attemptedSize = attemptedSize / redFactor; |
|
165 } |
|
166 } |
|
167 |
|
168 User::LeaveIfError(result); |
|
169 } |
|
170 |
|
171 void CSBEServer::AddSession() |
|
172 /** Increments the server session count. |
|
173 |
|
174 The server will shutdown when its |
|
175 session count drops to zero. |
|
176 */ |
|
177 { |
|
178 ++iSessionCount; |
|
179 iShutdown.Cancel(); |
|
180 } |
|
181 |
|
182 void CSBEServer::DropSession() |
|
183 /** Decrements the server session count. |
|
184 |
|
185 The server will shutdown when its |
|
186 session count drops to zero. |
|
187 */ |
|
188 { |
|
189 if(--iSessionCount == 0) |
|
190 { |
|
191 iShutdown.Start(); |
|
192 } |
|
193 } |
|
194 |
|
195 |
|
196 CSession2* CSBEServer::NewSessionL(const TVersion& aVersion, |
|
197 const RMessage2& /*aMessage*/) const |
|
198 /** Constructs a new SBE server session. |
|
199 |
|
200 Querys the supplied version infomation from the client |
|
201 with that of this server, and leaves if they are incompatable. |
|
202 |
|
203 @param aVersion The clients version information |
|
204 @param aMessage Is ignored |
|
205 @return A new instance of CSBESession |
|
206 @leave KErrNotSupported if the version passed in aVersion is not the same as this one |
|
207 */ |
|
208 { |
|
209 TVersion thisVersion(KSBEMajorVersionNumber, |
|
210 KSBEMinorVersionNumber, |
|
211 KSBEBuildVersionNumber); |
|
212 |
|
213 if (!User::QueryVersionSupported(thisVersion, aVersion)) |
|
214 { |
|
215 User::Leave(KErrNotSupported); |
|
216 } |
|
217 |
|
218 return new (ELeave) CSBESession(); |
|
219 } |
|
220 |
|
221 TInt CSBEServer::RunError(TInt aError) |
|
222 /** Called when this active objects RunL leaves. |
|
223 |
|
224 May be due to a bad client or the server itself. In either |
|
225 case, complete the last outstanding message with the error |
|
226 code and continue handling client requests. |
|
227 |
|
228 @param aError Standard Symbian OS error code |
|
229 @return The error code to be passed back to the active scheduler framework. |
|
230 */ |
|
231 { |
|
232 // |
|
233 // A Bad descriptor is a bad client - panic it. |
|
234 if(aError == KErrBadDescriptor) |
|
235 { |
|
236 PanicClient(KErrBadDescriptor); |
|
237 } |
|
238 |
|
239 // |
|
240 // Complete the message and continue handling requests. |
|
241 Message().Complete(aError); |
|
242 ReStart(); |
|
243 return KErrNone; |
|
244 } |
|
245 |
|
246 |
|
247 void CSBEServer::PanicClient(TInt aPanic) const |
|
248 /** Panic a client. |
|
249 |
|
250 @param aPanic The panic code. |
|
251 */ |
|
252 { |
|
253 __DEBUGGER() |
|
254 _LIT(KPanicCategory,"SBE Server"); |
|
255 RThread client; |
|
256 Message().Client(client); |
|
257 client.Panic(KPanicCategory, aPanic); |
|
258 } |
|
259 |
|
260 } // end namespace |