|
1 /* |
|
2 * Copyright (c) 2006-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 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: Class for parsing and generating echo test frames. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "core_frame_echo_test.h" |
|
20 #include "core_tools.h" |
|
21 #include "am_debug.h" |
|
22 |
|
23 // ======== MEMBER FUNCTIONS ======== |
|
24 |
|
25 const u16_t CORE_FRAME_ECHO_TEST_LENGTH = 16; |
|
26 const u16_t CORE_FRAME_ECHO_TOKEN_INDEX = 14; |
|
27 |
|
28 // --------------------------------------------------------------------------- |
|
29 // --------------------------------------------------------------------------- |
|
30 // |
|
31 core_frame_echo_test_c* core_frame_echo_test_c::instance( |
|
32 const core_frame_ethernet_c& frame ) |
|
33 { |
|
34 DEBUG( "core_frame_echo_test_c::instance()" ); |
|
35 |
|
36 if ( frame.data_length() < CORE_FRAME_ECHO_TEST_LENGTH ) |
|
37 { |
|
38 DEBUG( "core_frame_echo_test_c::instance() - not a valid echo test frame, frame is too short" ); |
|
39 |
|
40 return NULL; |
|
41 } |
|
42 |
|
43 core_frame_echo_test_c* instance = new core_frame_echo_test_c( |
|
44 frame.data_length(), |
|
45 frame.data(), |
|
46 0 ); |
|
47 if ( !instance ) |
|
48 { |
|
49 DEBUG( "core_frame_echo_test_c::instance() - unable to create an instance" ); |
|
50 |
|
51 return NULL; |
|
52 } |
|
53 |
|
54 return instance; |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 core_frame_echo_test_c* core_frame_echo_test_c::instance( |
|
61 const core_mac_address_s& destination, |
|
62 const core_mac_address_s& source, |
|
63 u16_t token ) |
|
64 { |
|
65 const u8_t max_data_length = CORE_FRAME_ECHO_TEST_LENGTH; |
|
66 |
|
67 u8_t* buffer = new u8_t[max_data_length]; |
|
68 if ( !buffer ) |
|
69 { |
|
70 DEBUG( "core_frame_echo_test_c::instance() - unable create the internal buffer" ); |
|
71 return NULL; |
|
72 } |
|
73 |
|
74 core_frame_echo_test_c* instance = |
|
75 new core_frame_echo_test_c( 0, buffer, max_data_length ); |
|
76 if ( !instance ) |
|
77 { |
|
78 DEBUG( "core_frame_echo_test_c::instance() - unable to create an instance" ); |
|
79 delete[] buffer; |
|
80 buffer = NULL; |
|
81 |
|
82 return NULL; |
|
83 } |
|
84 |
|
85 instance->generate( |
|
86 destination, |
|
87 source, |
|
88 token ); |
|
89 |
|
90 return instance; |
|
91 } |
|
92 |
|
93 // --------------------------------------------------------------------------- |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 core_frame_echo_test_c::~core_frame_echo_test_c() |
|
97 { |
|
98 DEBUG( "core_frame_echo_test_c::~core_frame_echo_test_c()" ); |
|
99 } |
|
100 |
|
101 // --------------------------------------------------------------------------- |
|
102 // --------------------------------------------------------------------------- |
|
103 // |
|
104 u16_t core_frame_echo_test_c::token() const |
|
105 { |
|
106 return core_tools_c::get_u16_big_endian( data_m, CORE_FRAME_ECHO_TOKEN_INDEX ); |
|
107 } |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 void core_frame_echo_test_c::generate( |
|
113 const core_mac_address_s& destination, |
|
114 const core_mac_address_s& source, |
|
115 u16_t token ) |
|
116 { |
|
117 ASSERT( !data_length_m ); |
|
118 ASSERT( max_data_length_m ); |
|
119 |
|
120 // Ethernet header |
|
121 core_frame_ethernet_c::generate( |
|
122 destination, |
|
123 source, |
|
124 core_frame_ethernet_c::core_ethernet_type_test ); |
|
125 |
|
126 // Token |
|
127 u16_t temp16 = core_tools_c::convert_host_to_big_endian( |
|
128 token ); |
|
129 core_tools_c::copy( |
|
130 &data_m[data_length_m], |
|
131 reinterpret_cast<u8_t*>( &temp16 ), |
|
132 sizeof( temp16 ) ); |
|
133 data_length_m += sizeof( temp16 ); |
|
134 } |
|
135 |
|
136 // --------------------------------------------------------------------------- |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 core_frame_echo_test_c::core_frame_echo_test_c( |
|
140 u16_t data_length, |
|
141 const u8_t* data, |
|
142 u16_t max_data_length ) : |
|
143 core_frame_ethernet_c( data_length, data, max_data_length ) |
|
144 { |
|
145 DEBUG( "core_frame_echo_test_c::core_frame_echo_test()" ); |
|
146 } |