|
1 /* |
|
2 * Copyright (c) 2007 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: Implementation of CGbaServerSession |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32svr.h> |
|
20 #include "GbaSession.h" |
|
21 #include "bootstrap.h" |
|
22 #include "GBALogger.h" |
|
23 //Constants |
|
24 const TInt KMessageIndex0 = 0; |
|
25 const TInt KMessageIndex1 = 1; |
|
26 |
|
27 // --------------------------------------------------------------------------- |
|
28 // CGbaServerSession* CGbaServerSession::NewL() |
|
29 // --------------------------------------------------------------------------- |
|
30 // |
|
31 CGbaServerSession* CGbaServerSession::NewL() |
|
32 { |
|
33 CGbaServerSession* self=new(ELeave) CGbaServerSession; |
|
34 CleanupStack::PushL(self); |
|
35 self->ConstructL(); |
|
36 CleanupStack::Pop(self); |
|
37 return self; |
|
38 } |
|
39 |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // CGbaServerSession::ConstructL() |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 void CGbaServerSession::ConstructL() |
|
46 { |
|
47 i3GPPBootstrap = C3GPPBootstrap::NewL( this ); |
|
48 } |
|
49 |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // CGbaServerSession::CGbaServerSession() |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 CGbaServerSession::CGbaServerSession() |
|
56 { |
|
57 // Implementation not required |
|
58 } |
|
59 |
|
60 |
|
61 // --------------------------------------------------------------------------- |
|
62 // CGbaServerSession::~CGbaServerSession() |
|
63 // --------------------------------------------------------------------------- |
|
64 // |
|
65 CGbaServerSession::~CGbaServerSession() |
|
66 { |
|
67 GBA_TRACE_DEBUG(("CGbaServerSession destructor")); |
|
68 Server()->DecrementSessions(); |
|
69 GBA_TRACE_DEBUG((" delete state machine")); |
|
70 delete i3GPPBootstrap; |
|
71 } |
|
72 |
|
73 |
|
74 // --------------------------------------------------------------------------- |
|
75 // CGbaServerSession::ServiceL() |
|
76 // --------------------------------------------------------------------------- |
|
77 // |
|
78 void CGbaServerSession::ServiceL(const RMessage2& aMessage) |
|
79 { |
|
80 GBA_TRACE_DEBUG(("CGbaServerSession::ServiceL")); |
|
81 switch (aMessage.Function()) |
|
82 { |
|
83 case EGbaServRequestBootstrap: |
|
84 { |
|
85 GBA_TRACE_DEBUG(("Request bootstrap")); |
|
86 RequestBootstrapL(aMessage); |
|
87 } |
|
88 break ; |
|
89 |
|
90 case EGbaServIsGBAUSupported: |
|
91 { |
|
92 GBA_TRACE_DEBUG(("Check is GBA-U supported")); |
|
93 TBool isGBAUSupported = i3GPPBootstrap->GBAUAvailabilityL(); |
|
94 |
|
95 if ( isGBAUSupported ) |
|
96 { |
|
97 GBA_TRACE_DEBUG(("GBA-U is available")); |
|
98 } |
|
99 else |
|
100 { |
|
101 GBA_TRACE_DEBUG(("GBA-U is not available")); |
|
102 } |
|
103 |
|
104 const TPckgC<TBool> pckg( isGBAUSupported ); |
|
105 aMessage.Write( KMessageIndex0, pckg ); |
|
106 aMessage.Complete( KErrNone ); |
|
107 } |
|
108 break; |
|
109 |
|
110 case EGbaServCancelRequestBootstrap : |
|
111 { |
|
112 GBA_TRACE_DEBUG(("Cancelling bootstrapping")); |
|
113 if ( i3GPPBootstrap->GetState() != C3GPPBootstrap::EIdle ) |
|
114 { |
|
115 i3GPPBootstrap->CancelBootstrap(); |
|
116 // complete original bootstrapping |
|
117 iMessage.Complete(KErrCancel); |
|
118 // complete the message for canceling |
|
119 aMessage.Complete(KErrNone); |
|
120 } |
|
121 else |
|
122 { |
|
123 aMessage.Complete(KErrNone); |
|
124 } |
|
125 } |
|
126 break ; |
|
127 |
|
128 case EGbaServWriteOption : |
|
129 { |
|
130 GBA_TRACE_DEBUG(("CGbaServerSession::ServiceL EGbaServWriteOption")); |
|
131 |
|
132 //Get the dictionary store UID |
|
133 TUid uid = TUid::Uid(aMessage.Int0()); |
|
134 |
|
135 //First get the length of descriptor |
|
136 TInt length = aMessage.GetDesLength(1); |
|
137 |
|
138 // If bigger than 256, |
|
139 // we think it is an attack. |
|
140 if ( length <= 0 || length > KMaxURLLength ) |
|
141 { |
|
142 aMessage.Complete( KErrBadDescriptor ); |
|
143 break; |
|
144 } |
|
145 |
|
146 //read the content |
|
147 HBufC8 *buf = HBufC8::NewLC( length ); |
|
148 TPtr8 ptrbuf = buf->Des(); |
|
149 aMessage.Read(KMessageIndex1,ptrbuf,0); |
|
150 |
|
151 Server()->WriteOptionL( uid,*buf ); |
|
152 aMessage.Complete( KErrNone ); |
|
153 CleanupStack::PopAndDestroy( buf ); |
|
154 } |
|
155 break; |
|
156 |
|
157 default : |
|
158 { |
|
159 GBA_TRACE_DEBUG(("Unexpected request")); |
|
160 aMessage.Complete(KErrArgument); |
|
161 } |
|
162 |
|
163 } |
|
164 } |
|
165 |
|
166 |
|
167 // --------------------------------------------------------------------------- |
|
168 // CGbaServerSession::RequestBootstrapL() |
|
169 // --------------------------------------------------------------------------- |
|
170 // |
|
171 void CGbaServerSession::RequestBootstrapL(const RMessage2& aMessage) |
|
172 { |
|
173 if ( i3GPPBootstrap->GetState() != C3GPPBootstrap::EIdle ) |
|
174 { |
|
175 // We're already busy |
|
176 aMessage.Complete(KErrInUse); |
|
177 return; |
|
178 } |
|
179 else |
|
180 { |
|
181 // Keep a copy of message - for use later |
|
182 iMessage = aMessage ; |
|
183 |
|
184 TPtr8 inputPtr(reinterpret_cast <TUint8*>(&iGbaInputParams), sizeof(TGBABootstrapInputParams), sizeof(TGBABootstrapInputParams)); |
|
185 |
|
186 //Sanity checking |
|
187 //First get the length of descriptor |
|
188 TInt inputDesLength = aMessage.GetDesLength(0); |
|
189 |
|
190 // if the length is not eqaul to the size of gba credentails |
|
191 // return bad descriptor |
|
192 if ( inputDesLength != sizeof(TGBABootstrapInputParams)) |
|
193 { |
|
194 aMessage.Complete( KErrBadDescriptor ); |
|
195 return; |
|
196 } |
|
197 |
|
198 aMessage.Read(KMessageIndex0,inputPtr,0); |
|
199 |
|
200 //Initialize bootstrap process using the state machine |
|
201 i3GPPBootstrap->InitializeL(); |
|
202 } |
|
203 } |
|
204 |
|
205 |
|
206 // --------------------------------------------------------------------------- |
|
207 // CGbaServerSession::StateMachineCallBack() |
|
208 // bootstrap state machine call back function |
|
209 // Copy the credentail back to client and complete the RMessage |
|
210 // If something wrong, complete RMessage with error value |
|
211 // --------------------------------------------------------------------------- |
|
212 // |
|
213 void CGbaServerSession::StateMachineCallBack( TInt aError ) |
|
214 { |
|
215 if ( i3GPPBootstrap->GetState() != C3GPPBootstrap::EIdle ) |
|
216 { |
|
217 if ( aError == KErrNone ) |
|
218 { |
|
219 GBA_TRACE_DEBUG(("B-TID to be sent")); |
|
220 GBA_TRACE_DEBUG(iGbaOutputParams.iBTID); |
|
221 GBA_TRACE_DEBUG(("KsNAF to be sent")); |
|
222 GBA_TRACE_DEBUG_BINARY(iGbaOutputParams.iKNAF); |
|
223 // Write the obtained Gba Bootstrap Creds data back to the client |
|
224 TPtr8 gbaBuffer(NULL,0,0); |
|
225 gbaBuffer.Set(reinterpret_cast <TUint8*>(&iGbaOutputParams), sizeof(TGBABootstrapOutputParams), sizeof(TGBABootstrapOutputParams)); |
|
226 TInt res = iMessage.Write(KMessageIndex1, gbaBuffer,0); |
|
227 GBA_TRACE_DEBUG_NUM(("writing message to client with return value = %d."),res); |
|
228 iMessage.Complete( res ); |
|
229 } |
|
230 else |
|
231 { |
|
232 GBA_TRACE_DEBUG((" Didn't get bootstrap credentails, pass error back")); |
|
233 // send error message to client |
|
234 iMessage.Complete( aError ); |
|
235 } |
|
236 |
|
237 } |
|
238 } |
|
239 |
|
240 |
|
241 |
|
242 // --------------------------------------------------------------------------- |
|
243 // CGbaServerSession::CreateL() |
|
244 // --------------------------------------------------------------------------- |
|
245 // |
|
246 void CGbaServerSession::CreateL() |
|
247 { |
|
248 Server()->IncrementSessions(); |
|
249 } |
|
250 |
|
251 |
|
252 // --------------------------------------------------------------------------- |
|
253 // CGbaServerSession::Server() |
|
254 // --------------------------------------------------------------------------- |
|
255 // |
|
256 CGbaServer* CGbaServerSession::Server() |
|
257 { |
|
258 return static_cast<CGbaServer*>(const_cast<CServer2*>(CSession2::Server())); |
|
259 } |
|
260 //EOF |
|
261 |