|
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: KMD event logger |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <vpnlogmessages.rsg> |
|
21 #include "eventviewer.h" |
|
22 #include "ikedebug.h" |
|
23 #include "vpnclientuids.h" |
|
24 |
|
25 // CLASS HEADER |
|
26 #include "kmdeventlogger.h" |
|
27 |
|
28 // ======== MEMBER FUNCTIONS ======== |
|
29 |
|
30 // --------------------------------------------------------------------------- |
|
31 // Two-phased constructor. |
|
32 // --------------------------------------------------------------------------- |
|
33 // |
|
34 CKmdEventLogger* CKmdEventLogger::NewL( MIkeDebug& aDebug ) |
|
35 { |
|
36 CKmdEventLogger* self = new ( ELeave ) CKmdEventLogger( aDebug ); |
|
37 CleanupStack::PushL( self ); |
|
38 self->ConstructL(); |
|
39 CleanupStack::Pop( self ); |
|
40 return self; |
|
41 } |
|
42 |
|
43 // --------------------------------------------------------------------------- |
|
44 // Destructor. |
|
45 // --------------------------------------------------------------------------- |
|
46 // |
|
47 CKmdEventLogger::~CKmdEventLogger() |
|
48 { |
|
49 iEventMediator.Close(); |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // Constructor. |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 CKmdEventLogger::CKmdEventLogger( MIkeDebug& aDebug ) |
|
57 : iDebug( aDebug ) |
|
58 { |
|
59 } |
|
60 |
|
61 // --------------------------------------------------------------------------- |
|
62 // Second phase construction. |
|
63 // --------------------------------------------------------------------------- |
|
64 // |
|
65 void CKmdEventLogger::ConstructL() |
|
66 { |
|
67 User::LeaveIfError( iEventMediator.Connect() ); |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // From class MKmdEventLoggerIf |
|
72 // Writes event to event log. |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 void CKmdEventLogger::LogEvent( TLogCategory aCategory, |
|
76 TInt aMsgId, |
|
77 TInt aStatus, |
|
78 TUint32 aVpnIapId, |
|
79 const TInetAddr* aGwIp, |
|
80 const TInetAddr* aLocalAddr ) |
|
81 { |
|
82 TUid uid = TUid::Uid( KUidKmdServer ); |
|
83 |
|
84 TBuf<40> ipAddr16; |
|
85 TBuf8<40> ipAddr; |
|
86 TBuf8<40> localIpAddr; |
|
87 TIapName vpnAccessPointName; |
|
88 TInt addrIndex = KErrNotFound; |
|
89 TInt iapIndex = KErrNotFound; |
|
90 TInt statusIndex = KErrNotFound; |
|
91 TInt realIpIndex = KErrNotFound; |
|
92 TInt desCount = 0; |
|
93 TUint8* pointers[4]; |
|
94 TInt lengths[4]; |
|
95 |
|
96 switch ( aMsgId ) |
|
97 { |
|
98 case R_VPN_MSG_VPN_GW_NO_RESP: |
|
99 case R_VPN_MSG_VPN_GW_AUTH_FAIL: |
|
100 case R_VPN_MSG_VPN_GW_AUTH_OK: |
|
101 addrIndex = 0; |
|
102 iapIndex = 1; |
|
103 break; |
|
104 |
|
105 case R_VPN_MSG_VPN_GW_ERR_RESP_RECEIVED: |
|
106 case R_VPN_MSG_SENT_ERROR_RESPONSE: |
|
107 addrIndex = 0; |
|
108 iapIndex = 1; |
|
109 statusIndex = 2; |
|
110 break; |
|
111 |
|
112 case R_VPN_MSG_DATA_DROPPED_DUE_POLICY: |
|
113 addrIndex = 0; |
|
114 statusIndex = 1; |
|
115 break; |
|
116 |
|
117 case R_VPN_MSG_ADDR_INFO_FOR_VPN_AP: |
|
118 iapIndex = 0; |
|
119 addrIndex = 1; |
|
120 realIpIndex = 2; |
|
121 statusIndex = 3; |
|
122 break; |
|
123 |
|
124 case R_VPN_MSG_REAL_IAP_ACT_FAILED: |
|
125 realIpIndex = 0; |
|
126 iapIndex = 1; |
|
127 statusIndex = 2; |
|
128 break; |
|
129 |
|
130 default: |
|
131 break; |
|
132 } |
|
133 |
|
134 if ( addrIndex != KErrNotFound ) |
|
135 { |
|
136 desCount ++; |
|
137 pointers[addrIndex] = (TUint8*)ipAddr.Ptr(); |
|
138 if ( aGwIp ) |
|
139 { |
|
140 aGwIp->Output(ipAddr16); |
|
141 ipAddr.Copy(ipAddr16); |
|
142 lengths[addrIndex] = ipAddr.Length(); |
|
143 } |
|
144 else |
|
145 { |
|
146 lengths[addrIndex] = 0; |
|
147 } |
|
148 } |
|
149 |
|
150 if ( statusIndex != KErrNotFound ) |
|
151 { |
|
152 desCount ++; |
|
153 pointers[statusIndex] = (TUint8*)&aStatus; |
|
154 lengths[statusIndex] = sizeof(aStatus); |
|
155 } |
|
156 |
|
157 if ( iapIndex != KErrNotFound ) |
|
158 { |
|
159 // |
|
160 // VPN IAP id shall be converted to VPN access point name using |
|
161 // eventviewer API. |
|
162 // |
|
163 desCount ++; |
|
164 pointers[iapIndex] = (TUint8*)vpnAccessPointName.Ptr(); |
|
165 if ( aVpnIapId != 0 ) |
|
166 { |
|
167 EventViewer::GetIapName(aVpnIapId, vpnAccessPointName); |
|
168 lengths[iapIndex] = vpnAccessPointName.Length(); |
|
169 } |
|
170 else |
|
171 { |
|
172 lengths[iapIndex] = 0; |
|
173 } |
|
174 } |
|
175 |
|
176 if ( realIpIndex != KErrNotFound ) |
|
177 { |
|
178 desCount ++; |
|
179 pointers[realIpIndex] = (TUint8*)localIpAddr.Ptr(); |
|
180 ipAddr16.SetLength(0); |
|
181 if ( aLocalAddr != NULL ) |
|
182 { |
|
183 aLocalAddr->Output(ipAddr16); |
|
184 } |
|
185 localIpAddr.Copy(ipAddr16); |
|
186 lengths[realIpIndex] = localIpAddr.Length(); |
|
187 } |
|
188 |
|
189 TInt ret( KErrNone ); |
|
190 |
|
191 switch ( desCount ) |
|
192 { |
|
193 case 0: |
|
194 { |
|
195 ret = iEventMediator.ReportLogEvent( uid, |
|
196 aCategory, |
|
197 aMsgId, |
|
198 0 ); |
|
199 } |
|
200 break; |
|
201 |
|
202 case 1: |
|
203 { |
|
204 TPtr8 parm1(pointers[0], lengths[0], lengths[0]); |
|
205 ret = iEventMediator.ReportLogEvent( uid, |
|
206 aCategory, |
|
207 aMsgId, |
|
208 1, |
|
209 &parm1 ); |
|
210 } |
|
211 break; |
|
212 |
|
213 case 2: |
|
214 { |
|
215 TPtr8 parm1(pointers[0], lengths[0], lengths[0]); |
|
216 TPtr8 parm2(pointers[1], lengths[1], lengths[1]); |
|
217 ret = iEventMediator.ReportLogEvent( uid, |
|
218 aCategory, |
|
219 aMsgId, |
|
220 2, |
|
221 &parm1, |
|
222 &parm2 ); |
|
223 } |
|
224 break; |
|
225 |
|
226 case 3: |
|
227 { |
|
228 TPtr8 parm1(pointers[0], lengths[0], lengths[0]); |
|
229 TPtr8 parm2(pointers[1], lengths[1], lengths[1]); |
|
230 TPtr8 parm3(pointers[2], lengths[2], lengths[2]); |
|
231 ret = iEventMediator.ReportLogEvent( uid, |
|
232 aCategory, |
|
233 aMsgId, |
|
234 3, |
|
235 &parm1, |
|
236 &parm2, |
|
237 &parm3 ); |
|
238 } |
|
239 break; |
|
240 |
|
241 case 4: |
|
242 { |
|
243 TPtr8 parm1(pointers[0], lengths[0], lengths[0]); |
|
244 TPtr8 parm2(pointers[1], lengths[1], lengths[1]); |
|
245 TPtr8 parm3(pointers[2], lengths[2], lengths[2]); |
|
246 TPtr8 parm4(pointers[3], lengths[3], lengths[3]); |
|
247 ret = iEventMediator.ReportLogEvent( uid, |
|
248 aCategory, |
|
249 aMsgId, |
|
250 4, |
|
251 &parm1, |
|
252 &parm2, |
|
253 &parm3, |
|
254 &parm4 ); |
|
255 } |
|
256 break; |
|
257 |
|
258 default: |
|
259 ret = ret; |
|
260 break; |
|
261 |
|
262 } |
|
263 |
|
264 DEBUG_LOG3( _L("Logging event %x with %d parameters, report status = %d"), |
|
265 aMsgId, desCount, ret ); |
|
266 |
|
267 } |
|
268 |
|
269 // --------------------------------------------------------------------------- |
|
270 // From class MKmdEventLoggerIf |
|
271 // Writes event to event log. |
|
272 // --------------------------------------------------------------------------- |
|
273 // |
|
274 void CKmdEventLogger::LogEvent( TKmdLogCategory aCategory, |
|
275 TInt aMsgId, |
|
276 TInt aStatus, |
|
277 TUint32 aVpnIapId, |
|
278 const TInetAddr* aGwIp, |
|
279 const TInetAddr* aLocalAddr ) |
|
280 { |
|
281 TLogCategory logCategory; |
|
282 switch ( aCategory ) |
|
283 { |
|
284 case KLogInfo: |
|
285 logCategory = EInfo; |
|
286 break; |
|
287 case KLogWarning: |
|
288 logCategory = EWarning; |
|
289 break; |
|
290 case KLogError: |
|
291 logCategory = EError; |
|
292 break; |
|
293 default: |
|
294 logCategory = EDebug; |
|
295 break; |
|
296 } |
|
297 |
|
298 LogEvent( logCategory, |
|
299 aMsgId, |
|
300 aStatus, |
|
301 aVpnIapId, |
|
302 aGwIp, |
|
303 aLocalAddr ); |
|
304 } |
|
305 |