eapol/eapol_framework/eapol_symbian/am/common/symbian/eap_am_trace_symbian.cpp
branchRCL_3
changeset 46 c74b3d9f6b9e
parent 45 bad0cc58d154
equal deleted inserted replaced
45:bad0cc58d154 46:c74b3d9f6b9e
     1 /*
     1 /*
     2 * Copyright (c) 2001-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2001-2005 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:  Trace functions on Symbian.
    14 * Description:  EAP and WLAN authentication protocols.
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 /*
    18 /*
    19 * %version: 16 %
    19 * %version: 7.1.3 %
    20 */
    20 */
    21 
    21 
    22 #include "EapTraceSymbian.h"
    22 #if defined(_DEBUG) || defined(DEBUG)
    23 #include "eap_tools.h"
    23 
    24 
    24 #include "eap_am_trace_symbian.h"
    25 const TInt KMaxBufferSize = 512;
    25 
    26 
    26 const TInt KMaxBufferSize = 256;
    27 //-------------------------------------------------------------------------
    27 
    28 
    28 u8_t octet_to_ascii(i32_t octet)
    29 TUint8 octet_to_ascii(i32_t octet)
       
    30 {
    29 {
    31 	if (0 <= octet && octet <= 9)
    30 	if (0 <= octet && octet <= 9)
    32 	{
    31 	{
    33 		return static_cast<TUint8>('0' + octet);
    32 		return static_cast<u8_t>('0' + octet);
    34 	}
    33 	}
    35 	else if (10 <= octet && octet <= 16)
    34 	else if (10 <= octet && octet <= 16)
    36 	{
    35 	{
    37 		return static_cast<TUint8>('a' + (octet-10u));
    36 		return static_cast<u8_t>('a' + (octet-10u));
    38 	}
    37 	}
    39 	else
    38 	else
    40 	{
    39 	{
    41 		return 0;
    40 		return 0;
    42 	}
    41 	}
    43 }
    42 }
    44 
    43 
    45 //-------------------------------------------------------------------------
    44 void formatted_print(eap_format_string format, ...)
    46 
       
    47 void formatted_print(const char * const format, ...)
       
    48 {
    45 {
    49 	EAP_UNREFERENCED_PARAMETER(format);
    46 	EAP_UNREFERENCED_PARAMETER(format);
    50 
    47 
    51 #if defined(USE_EAP_TRACE) || defined(USE_EAP_TRACE_ALWAYS)
    48 #if defined(USE_EAP_TRACE) || defined(USE_EAP_TRACE_ALWAYS)
    52 
    49 
    77 	TPtr8 m_args_buf = args_buf->Des();
    74 	TPtr8 m_args_buf = args_buf->Des();
    78 	TPtr8 m_format_buf = format_buf->Des();
    75 	TPtr8 m_format_buf = format_buf->Des();
    79 	TPtr8 m_trace_buf = trace_buf->Des();
    76 	TPtr8 m_trace_buf = trace_buf->Des();
    80 	TPtr16 m_trace_buf_16 = trace_buf_16->Des();
    77 	TPtr16 m_trace_buf_16 = trace_buf_16->Des();
    81 
    78 
    82 	VA_LIST args = {0, };
    79 	VA_LIST args;
    83 	VA_START(args, format);
    80 	VA_START(args, format);
    84 	m_format_buf.Copy((const TUint8 *)format);
    81 	m_format_buf.Copy((const TUint8 *)format);
    85 	
    82 	
    86 	m_args_buf.FormatList(m_format_buf, args);
    83 	m_args_buf.FormatList(m_format_buf, args);
    87 	m_trace_buf.Append(m_args_buf);			
    84 	m_trace_buf.Append(m_args_buf);			
   112 		m_trace_buf_16.Copy(m_trace_buf);
   109 		m_trace_buf_16.Copy(m_trace_buf);
   113 
   110 
   114 		#if defined(USE_EAP_HARDWARE_TRACE_RAW_PRINT)
   111 		#if defined(USE_EAP_HARDWARE_TRACE_RAW_PRINT)
   115 			RDebug::RawPrint(m_trace_buf_16);
   112 			RDebug::RawPrint(m_trace_buf_16);
   116 		#else
   113 		#else
   117 			RDebug::Print(_L("%S"), &m_trace_buf_16);
   114 			formatted_print(_L("%S"), &m_trace_buf_16);
   118 		#endif //#if defined(USE_EAP_HARDWARE_TRACE_RAW_PRINT)
   115 		#endif //#if defined(USE_EAP_HARDWARE_TRACE_RAW_PRINT)
   119 	}
   116 	}
   120 
   117 
   121 #endif //#if defined(USE_EAP_HARDWARE_TRACE)
   118 #endif //#if defined(USE_EAP_HARDWARE_TRACE)
   122 
   119 
   127 
   124 
   128 #endif //#if defined(USE_EAP_TRACE) || defined(USE_EAP_TRACE_ALWAYS)
   125 #endif //#if defined(USE_EAP_TRACE) || defined(USE_EAP_TRACE_ALWAYS)
   129 
   126 
   130 }
   127 }
   131 
   128 
   132 //-------------------------------------------------------------------------
   129 
   133 
   130 void trace_data(
   134 EXPORT_C void eap_trace_data_symbian(
   131 	eap_const_string prefix,
   135 	const char * const prefix,
       
   136 	const void * const p_data,
   132 	const void * const p_data,
   137 	const TUint data_length)
   133 	const u32_t data_length)
   138 {
   134 {
   139 
   135 
   140 	TUint8* m_tmp_buffer = NULL;	
   136 	u8_t* m_tmp_buffer = NULL;	
   141 	TUint8* m_tmp_ascii_buffer = NULL;
   137 	u8_t* m_tmp_ascii_buffer = NULL;
   142 		
   138 		
   143 	m_tmp_buffer = new TUint8[KMaxBufferSize];	
   139 	m_tmp_buffer = new u8_t[KMaxBufferSize];	
   144 	m_tmp_ascii_buffer = new TUint8[KMaxBufferSize];
   140 	m_tmp_ascii_buffer = new u8_t[KMaxBufferSize];
   145 		
   141 		
   146 	if( m_tmp_buffer == NULL || m_tmp_ascii_buffer == NULL)
   142 	if( m_tmp_buffer == NULL || m_tmp_ascii_buffer == NULL)
   147 	{
   143 	{
   148 		// Not enough memory.
   144 		// Not enough memory.
   149 		RDebug::Print(_L("trace_data: ERROR - Not enough Memory!\n"));
   145 		RDebug::Print(_L("trace_data: ERROR - Not enough Memory!\n"));
   152 		delete [] m_tmp_ascii_buffer;
   148 		delete [] m_tmp_ascii_buffer;
   153 		
   149 		
   154 		return;
   150 		return;
   155 	}
   151 	}
   156 
   152 
   157 	TUint8 *cursor = m_tmp_buffer;
   153 	u8_t *cursor = m_tmp_buffer;
   158 	TUint8 *cursor_ascii = m_tmp_ascii_buffer;
   154 	u8_t *cursor_ascii = m_tmp_ascii_buffer;
   159 	
   155 	
   160 	const TUint8 *data = reinterpret_cast<const TUint8 *>(p_data);
   156 	const u8_t *data = reinterpret_cast<const u8_t *>(p_data);
   161 	TUint ind;
   157 	u32_t ind;
   162 	bool must_print = false;
   158 	bool must_print = false;
   163 	TUint data_start = 0u;
   159 	u32_t data_start = 0u;
   164 
   160 
   165 	const TUint EAP_DATA_TRACE_BYTE_GROUP_SIZE = 1;
   161 	const u32_t EAP_DATA_TRACE_BYTE_GROUP_SIZE = 1;
   166 	TUint byte_group_size = EAP_DATA_TRACE_BYTE_GROUP_SIZE;
   162 	u32_t byte_group_size = EAP_DATA_TRACE_BYTE_GROUP_SIZE;
   167 
   163 
   168 #if !defined(USE_EAP_DEBUG_TRACE)
   164 #if !defined(USE_EAP_DEBUG_TRACE)
   169 	// This does not trace the pointer of the data.
   165 	// This does not trace the pointer of the data.
   170 	formatted_print(
   166 	formatted_print(
   171 		"%s: data: %d (0x%x) bytes\n",
   167 		"%s: data: %d (0x%x) bytes\n",
   248 			m_tmp_ascii_buffer);
   244 			m_tmp_ascii_buffer);
   249 	}
   245 	}
   250 	
   246 	
   251 	delete [] m_tmp_buffer;
   247 	delete [] m_tmp_buffer;
   252 	delete [] m_tmp_ascii_buffer;
   248 	delete [] m_tmp_ascii_buffer;
   253 
   249 }
   254 #if !defined(USE_EAP_DEBUG_TRACE)
   250 
   255 	// This does not trace the pointer of the data.
       
   256 	formatted_print(
       
   257 		"%s: data ends: %d (0x%x) bytes\n",
       
   258 		prefix,
       
   259 		data_length,
       
   260 		data_length);
       
   261 #else
       
   262 	formatted_print(
       
   263 		"%s: data ends 0x%08x: %d (0x%x) bytes\n",
       
   264 		prefix,
       
   265 		p_data,
       
   266 		data_length,
       
   267 		data_length);
       
   268 #endif
   251 #endif
   269 
   252 
   270 }
       
   271 
       
   272 //-------------------------------------------------------------------------
       
   273 // End of file
   253 // End of file