|
1 /* |
|
2 * Copyright (c) 2001-2005 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 the License "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: EAP and WLAN authentication protocols. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #if defined(_DEBUG) || defined(DEBUG) |
|
20 |
|
21 #include "eap_am_trace_symbian.h" |
|
22 |
|
23 const TInt KMaxBufferSize = 256; |
|
24 |
|
25 u8_t octet_to_ascii(i32_t octet) |
|
26 { |
|
27 if (0 <= octet && octet <= 9) |
|
28 { |
|
29 return static_cast<u8_t>('0' + octet); |
|
30 } |
|
31 else if (10 <= octet && octet <= 16) |
|
32 { |
|
33 return static_cast<u8_t>('a' + (octet-10u)); |
|
34 } |
|
35 else |
|
36 { |
|
37 return 0; |
|
38 } |
|
39 } |
|
40 |
|
41 void formatted_print(eap_format_string format, ...) |
|
42 { |
|
43 EAP_UNREFERENCED_PARAMETER(format); |
|
44 |
|
45 #if defined(USE_EAP_TRACE) || defined(USE_EAP_TRACE_ALWAYS) |
|
46 |
|
47 HBufC8* args_buf = NULL; |
|
48 HBufC8* format_buf = NULL; |
|
49 HBufC8* trace_buf = NULL; |
|
50 HBufC16* trace_buf_16 = NULL; |
|
51 |
|
52 TRAPD(error, |
|
53 args_buf= HBufC8::NewL(KMaxBufferSize); |
|
54 format_buf= HBufC8::NewL(KMaxBufferSize); |
|
55 trace_buf= HBufC8::NewL(KMaxBufferSize); |
|
56 trace_buf_16= HBufC16::NewL(KMaxBufferSize); ); |
|
57 |
|
58 if(error != KErrNone) |
|
59 { |
|
60 // Not enough memory. |
|
61 RDebug::Print(_L("formatted_print: ERROR - Not enough Memory!\n")); |
|
62 |
|
63 delete args_buf; |
|
64 delete format_buf; |
|
65 delete trace_buf; |
|
66 delete trace_buf_16; |
|
67 |
|
68 return; |
|
69 } |
|
70 |
|
71 TPtr8 m_args_buf = args_buf->Des(); |
|
72 TPtr8 m_format_buf = format_buf->Des(); |
|
73 TPtr8 m_trace_buf = trace_buf->Des(); |
|
74 TPtr16 m_trace_buf_16 = trace_buf_16->Des(); |
|
75 |
|
76 VA_LIST args; |
|
77 VA_START(args, format); |
|
78 m_format_buf.Copy((const TUint8 *)format); |
|
79 |
|
80 m_args_buf.FormatList(m_format_buf, args); |
|
81 m_trace_buf.Append(m_args_buf); |
|
82 VA_END(args); |
|
83 |
|
84 #if defined(USE_EAP_HARDWARE_TRACE) |
|
85 |
|
86 { |
|
87 #if !defined(USE_EAP_HARDWARE_TRACE_RAW_PRINT) |
|
88 { |
|
89 TInt length = m_trace_buf.Length(); |
|
90 if (length >= 2ul) |
|
91 { |
|
92 --length; |
|
93 const TUint8 *last_char = m_trace_buf.Ptr() + length; |
|
94 |
|
95 if (last_char != 0 |
|
96 && *last_char == '\n') |
|
97 { |
|
98 // This removes the ending new line character. |
|
99 // formatted_print() will write new line automatically. |
|
100 m_trace_buf.SetLength(length); |
|
101 } |
|
102 } |
|
103 } |
|
104 #endif //#if !defined(USE_EAP_HARDWARE_TRACE_RAW_PRINT) |
|
105 |
|
106 m_trace_buf_16.Copy(m_trace_buf); |
|
107 |
|
108 #if defined(USE_EAP_HARDWARE_TRACE_RAW_PRINT) |
|
109 RDebug::RawPrint(m_trace_buf_16); |
|
110 #else |
|
111 formatted_print(_L("%S"), &m_trace_buf_16); |
|
112 #endif //#if defined(USE_EAP_HARDWARE_TRACE_RAW_PRINT) |
|
113 } |
|
114 |
|
115 #endif //#if defined(USE_EAP_HARDWARE_TRACE) |
|
116 |
|
117 delete args_buf; |
|
118 delete format_buf; |
|
119 delete trace_buf; |
|
120 delete trace_buf_16; |
|
121 |
|
122 #endif //#if defined(USE_EAP_TRACE) || defined(USE_EAP_TRACE_ALWAYS) |
|
123 |
|
124 } |
|
125 |
|
126 |
|
127 void trace_data( |
|
128 eap_const_string prefix, |
|
129 const void * const p_data, |
|
130 const u32_t data_length) |
|
131 { |
|
132 |
|
133 u8_t* m_tmp_buffer = NULL; |
|
134 u8_t* m_tmp_ascii_buffer = NULL; |
|
135 |
|
136 m_tmp_buffer = new u8_t[KMaxBufferSize]; |
|
137 m_tmp_ascii_buffer = new u8_t[KMaxBufferSize]; |
|
138 |
|
139 if( m_tmp_buffer == NULL || m_tmp_ascii_buffer == NULL) |
|
140 { |
|
141 // Not enough memory. |
|
142 RDebug::Print(_L("trace_data: ERROR - Not enough Memory!\n")); |
|
143 |
|
144 delete [] m_tmp_buffer; |
|
145 delete [] m_tmp_ascii_buffer; |
|
146 |
|
147 return; |
|
148 } |
|
149 |
|
150 u8_t *cursor = m_tmp_buffer; |
|
151 u8_t *cursor_ascii = m_tmp_ascii_buffer; |
|
152 |
|
153 const u8_t *data = reinterpret_cast<const u8_t *>(p_data); |
|
154 u32_t ind; |
|
155 bool must_print = false; |
|
156 u32_t data_start = 0u; |
|
157 |
|
158 const u32_t EAP_DATA_TRACE_BYTE_GROUP_SIZE = 1; |
|
159 u32_t byte_group_size = EAP_DATA_TRACE_BYTE_GROUP_SIZE; |
|
160 |
|
161 #if !defined(USE_EAP_DEBUG_TRACE) |
|
162 // This does not trace the pointer of the data. |
|
163 formatted_print( |
|
164 "%s: data: %d (0x%x) bytes\n", |
|
165 prefix, |
|
166 data_length, |
|
167 data_length); |
|
168 #else |
|
169 formatted_print( |
|
170 "%s: data 0x%08x: %d (0x%x) bytes\n", |
|
171 prefix, |
|
172 p_data, |
|
173 data_length, |
|
174 data_length); |
|
175 #endif |
|
176 |
|
177 if (p_data == 0) |
|
178 { |
|
179 delete [] m_tmp_buffer; |
|
180 delete [] m_tmp_ascii_buffer; |
|
181 |
|
182 return; |
|
183 } |
|
184 |
|
185 for (ind = 0u; ind < data_length; ind++) |
|
186 { |
|
187 if ((cursor-m_tmp_buffer)+5u >= KMaxBufferSize) |
|
188 { |
|
189 must_print = true; |
|
190 formatted_print( |
|
191 "ERROR: eap_am_tools_c::trace_data local buffer (%d bytes) too small.\n", |
|
192 KMaxBufferSize); |
|
193 break; |
|
194 } |
|
195 |
|
196 |
|
197 if (ind > 0u |
|
198 && (ind % 16) == 0) |
|
199 { |
|
200 *cursor++ = 0; |
|
201 *cursor_ascii++ = 0; |
|
202 |
|
203 formatted_print( |
|
204 "%s: 0x%04x: %-48s |%-16s|\n", |
|
205 prefix, |
|
206 data_start, |
|
207 m_tmp_buffer, |
|
208 m_tmp_ascii_buffer); |
|
209 |
|
210 cursor = m_tmp_buffer; |
|
211 cursor_ascii = m_tmp_ascii_buffer; |
|
212 must_print = false; |
|
213 data_start = ind; |
|
214 } |
|
215 |
|
216 *cursor_ascii++ = (*data >= 32 && *data < 128) ? *data : '.'; |
|
217 |
|
218 *cursor++ = octet_to_ascii(((*data) & 0xf0) >> 4); |
|
219 *cursor++ = octet_to_ascii(((*data) & 0x0f)); |
|
220 data++; |
|
221 |
|
222 if (ind > 0u |
|
223 && ((ind+1) % byte_group_size) == 0 |
|
224 || byte_group_size == 1ul) |
|
225 { |
|
226 *cursor++ = ' '; |
|
227 } |
|
228 |
|
229 must_print = true; |
|
230 } |
|
231 |
|
232 if (must_print == true) |
|
233 { |
|
234 *cursor++ = 0; |
|
235 *cursor_ascii = 0; |
|
236 formatted_print( |
|
237 "%s: 0x%04x: %-48s |%-16s|\n", |
|
238 prefix, |
|
239 data_start, |
|
240 m_tmp_buffer, |
|
241 m_tmp_ascii_buffer); |
|
242 } |
|
243 |
|
244 delete [] m_tmp_buffer; |
|
245 delete [] m_tmp_ascii_buffer; |
|
246 } |
|
247 |
|
248 #endif |
|
249 |
|
250 // End of file |