1 /* |
|
2 * Copyright (c) 2001-2010 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: Expanded EAP-type on Symbian. |
|
15 * |
|
16 */ |
|
17 |
|
18 /* |
|
19 * %version: 16 % |
|
20 */ |
|
21 |
|
22 #include <EapExpandedType.h> |
|
23 #include "EapTraceSymbian.h" |
|
24 #include "eap_expanded_type.h" |
|
25 |
|
26 //-------------------------------------------------- |
|
27 |
|
28 #if defined(USE_EAP_EXPANDED_TYPE_TRACES) |
|
29 |
|
30 #define EXPANDED_TYPE_EAP_TRACE EAP_TRACE_DEBUG_SYMBIAN |
|
31 |
|
32 #define EXPANDED_TYPE_EAP_TRACE_DATA EAP_TRACE_DATA_DEBUG_SYMBIAN |
|
33 |
|
34 #define EXPANDED_TYPE_EAP_TRACE_RETURN_STRING EAP_TRACE_RETURN_STRING_SYMBIAN |
|
35 |
|
36 #else |
|
37 |
|
38 #define EXPANDED_TYPE_EAP_TRACE(_parameter_list_) |
|
39 |
|
40 #define EXPANDED_TYPE_EAP_TRACE_DATA(_parameter_list_) |
|
41 |
|
42 #define EXPANDED_TYPE_EAP_TRACE_RETURN_STRING(_parameter_list_) |
|
43 |
|
44 #endif //#if defined(USE_EAP_EXPANDED_TYPE_TRACES) |
|
45 |
|
46 //-------------------------------------------------- |
|
47 |
|
48 EAP_FUNC_EXPORT TEapExpandedType::TEapExpandedType() |
|
49 { |
|
50 EXPANDED_TYPE_EAP_TRACE_DATA( |
|
51 (EAPL("TEapExpandedType::TEapExpandedType(): EapExpandedTypeNone"), |
|
52 &EapExpandedTypeNone, |
|
53 sizeof(EapExpandedTypeNone))); |
|
54 |
|
55 EXPANDED_TYPE_EAP_TRACE_RETURN_STRING(_L("returns: TEapExpandedType::TEapExpandedType()\n")); |
|
56 |
|
57 EXPANDED_TYPE_EAP_TRACE_DATA( |
|
58 (EAPL("TEapExpandedType::TEapExpandedType(): EapExpandedTypeNone.GetType()"), |
|
59 EapExpandedTypeNone.GetType(), |
|
60 sizeof(*(EapExpandedTypeNone.GetType())))); |
|
61 |
|
62 iValue.Copy(*(EapExpandedTypeNone.GetType())); |
|
63 |
|
64 EXPANDED_TYPE_EAP_TRACE_DATA( |
|
65 (EAPL("TEapExpandedType::TEapExpandedType()"), |
|
66 iValue.Ptr(), |
|
67 iValue.Length())); |
|
68 } |
|
69 |
|
70 //-------------------------------------------------- |
|
71 |
|
72 EAP_FUNC_EXPORT TEapExpandedType::~TEapExpandedType() |
|
73 { |
|
74 EAP_STATIC_ASSERT(sizeof(TConstEapExpandedTypeTemplate<KEapExpandedTypeLength>) == sizeof(TBufC8<KEapExpandedTypeLength>)); |
|
75 } |
|
76 |
|
77 //-------------------------------------------------- |
|
78 |
|
79 EAP_FUNC_EXPORT TEapExpandedType::TEapExpandedType(const TEapExpandedType * const init) |
|
80 { |
|
81 EXPANDED_TYPE_EAP_TRACE_RETURN_STRING(_L("returns: TEapExpandedType::TEapExpandedType(const TEapExpandedType * const init)\n")); |
|
82 |
|
83 iValue.Copy(init->GetValue()); |
|
84 |
|
85 EXPANDED_TYPE_EAP_TRACE_DATA( |
|
86 (EAPL("TEapExpandedType::TEapExpandedType()"), |
|
87 iValue.Ptr(), |
|
88 iValue.Length())); |
|
89 } |
|
90 |
|
91 //-------------------------------------------------- |
|
92 |
|
93 EAP_FUNC_EXPORT TEapExpandedType::TEapExpandedType(const TEapExpandedType & init) |
|
94 { |
|
95 EXPANDED_TYPE_EAP_TRACE_RETURN_STRING(_L("returns: TEapExpandedType::TEapExpandedType(const TEapExpandedType & init)\n")); |
|
96 |
|
97 iValue.Copy(init.GetValue()); |
|
98 |
|
99 EXPANDED_TYPE_EAP_TRACE_DATA( |
|
100 (EAPL("TEapExpandedType::TEapExpandedType()"), |
|
101 iValue.Ptr(), |
|
102 iValue.Length())); |
|
103 } |
|
104 |
|
105 //-------------------------------------------------- |
|
106 |
|
107 EAP_FUNC_EXPORT TEapExpandedType::TEapExpandedType(const TBufC8<KEapExpandedTypeLength> & init) |
|
108 { |
|
109 EXPANDED_TYPE_EAP_TRACE_RETURN_STRING(_L("returns: TEapExpandedType::TEapExpandedType(const TBufC8<KEapExpandedTypeLength> & init)\n")); |
|
110 |
|
111 iValue.Copy(init); |
|
112 |
|
113 EXPANDED_TYPE_EAP_TRACE_DATA( |
|
114 (EAPL("TEapExpandedType::TEapExpandedType()"), |
|
115 iValue.Ptr(), |
|
116 iValue.Length())); |
|
117 } |
|
118 |
|
119 //-------------------------------------------------- |
|
120 |
|
121 EAP_FUNC_EXPORT TEapExpandedType::TEapExpandedType(const TDesC8 & init) |
|
122 { |
|
123 EXPANDED_TYPE_EAP_TRACE_RETURN_STRING(_L("returns: TEapExpandedType::TEapExpandedType(const TDesC8 & init)\n")); |
|
124 |
|
125 iValue.Copy(init); |
|
126 |
|
127 EXPANDED_TYPE_EAP_TRACE_DATA( |
|
128 (EAPL("TEapExpandedType::TEapExpandedType()"), |
|
129 iValue.Ptr(), |
|
130 iValue.Length())); |
|
131 } |
|
132 |
|
133 //-------------------------------------------------- |
|
134 |
|
135 EAP_FUNC_EXPORT const TBuf8<KEapExpandedTypeLength> & TEapExpandedType::GetValue() const |
|
136 { |
|
137 return iValue; |
|
138 } |
|
139 |
|
140 //-------------------------------------------------- |
|
141 |
|
142 EAP_FUNC_EXPORT TInt TEapExpandedType::SetValue( |
|
143 const void * const data, |
|
144 const TUint data_length) |
|
145 { |
|
146 EXPANDED_TYPE_EAP_TRACE_DATA( |
|
147 (EAPL("TEapExpandedType::SetValue(const void * const data, const TUint data_length)"), |
|
148 data, |
|
149 data_length)); |
|
150 |
|
151 EXPANDED_TYPE_EAP_TRACE_RETURN_STRING(_L("returns: TEapExpandedType::SetValue()\n")); |
|
152 |
|
153 if (data == 0 |
|
154 || data_length > iValue.MaxSize()) |
|
155 { |
|
156 return KErrArgument; |
|
157 } |
|
158 |
|
159 iValue.Copy(reinterpret_cast<const TUint8 *> (data), static_cast<TInt>(data_length)); |
|
160 |
|
161 EXPANDED_TYPE_EAP_TRACE_DATA( |
|
162 (EAPL("TEapExpandedType::SetValue(const void * const data, const TUint data_length)"), |
|
163 iValue.Ptr(), |
|
164 iValue.Length())); |
|
165 |
|
166 return KErrNone; |
|
167 } |
|
168 |
|
169 //-------------------------------------------------- |
|
170 |
|
171 EAP_FUNC_EXPORT TInt TEapExpandedType::SetValue( |
|
172 const TUint vendor_id, |
|
173 const TUint vendor_type) |
|
174 { |
|
175 const u32_t expanded_vendor = (0xfe000000 | static_cast<u32_t>(vendor_id)); |
|
176 const TUint net_ord_vendor = eap_htonl(expanded_vendor); |
|
177 const TUint net_ord_type = eap_htonl(vendor_type); |
|
178 |
|
179 EXPANDED_TYPE_EAP_TRACE((_L("TEapExpandedType::SetValue(): vendor_id=0x%08x, vendor_type=0x%08x, expanded_vendor=0x%08x, net_ord_vendor=0x%08x, net_ord_type=0x%08x\n"), |
|
180 vendor_id, |
|
181 vendor_type, |
|
182 expanded_vendor, |
|
183 net_ord_vendor, |
|
184 net_ord_type)); |
|
185 |
|
186 EXPANDED_TYPE_EAP_TRACE_RETURN_STRING(_L("returns: TEapExpandedType::SetValue()\n")); |
|
187 |
|
188 if ((sizeof(vendor_id)+sizeof(vendor_type)) > iValue.MaxSize()) |
|
189 { |
|
190 return KErrArgument; |
|
191 } |
|
192 |
|
193 iValue.Copy(reinterpret_cast<const TUint8 *>(&net_ord_vendor), sizeof(net_ord_vendor)); |
|
194 iValue.Append(reinterpret_cast<const TUint8 *>(&net_ord_type), sizeof(net_ord_type)); |
|
195 |
|
196 EXPANDED_TYPE_EAP_TRACE_DATA( |
|
197 (EAPL("TEapExpandedType::SetValue()"), |
|
198 iValue.Ptr(), |
|
199 iValue.Length())); |
|
200 |
|
201 return KErrNone; |
|
202 } |
|
203 |
|
204 //-------------------------------------------------- |
|
205 |
|
206 EAP_FUNC_EXPORT TUint TEapExpandedType::GetVendorId() const |
|
207 { |
|
208 const TUint * const aHostOrderVendorId = reinterpret_cast<const TUint *>(iValue.Ptr()); |
|
209 |
|
210 // Masks off the leading octet 0xfe. |
|
211 const u32_t VENDOR_ID_MASK = 0x00ffffff; |
|
212 return eap_ntohl(*aHostOrderVendorId) & VENDOR_ID_MASK; |
|
213 } |
|
214 |
|
215 //-------------------------------------------------- |
|
216 |
|
217 EAP_FUNC_EXPORT TUint TEapExpandedType::GetVendorType() const |
|
218 { |
|
219 const TUint * const aHostOrderVendorType = reinterpret_cast<const TUint *>(iValue.Ptr() + sizeof(TUint)); |
|
220 |
|
221 return eap_ntohl(*aHostOrderVendorType); |
|
222 } |
|
223 |
|
224 //-------------------------------------------------- |
|
225 |
|
226 EAP_FUNC_EXPORT TEapExpandedType &TEapExpandedType::operator = (const TEapExpandedType &right_type_value) |
|
227 { |
|
228 if (this == &right_type_value) |
|
229 { |
|
230 return *this; |
|
231 } |
|
232 |
|
233 iValue.Copy(right_type_value.GetValue()); |
|
234 |
|
235 EXPANDED_TYPE_EAP_TRACE_DATA( |
|
236 (EAPL("TEapExpandedType::operator ="), |
|
237 iValue.Ptr(), |
|
238 iValue.Length())); |
|
239 |
|
240 return *this; |
|
241 } |
|
242 |
|
243 //-------------------------------------------------- |
|
244 |
|
245 EAP_FUNC_EXPORT TEapExpandedType &TEapExpandedType::operator = (const TBufC8<KEapExpandedTypeLength> &right_type_value) |
|
246 { |
|
247 iValue.Copy(right_type_value); |
|
248 |
|
249 EXPANDED_TYPE_EAP_TRACE_DATA( |
|
250 (EAPL("TEapExpandedType::operator ="), |
|
251 iValue.Ptr(), |
|
252 iValue.Length())); |
|
253 |
|
254 return *this; |
|
255 } |
|
256 |
|
257 //-------------------------------------------------- |
|
258 |
|
259 EAP_FUNC_EXPORT TEapExpandedType &TEapExpandedType::operator = (const TDesC8 &right_type_value) |
|
260 { |
|
261 ASSERT(right_type_value.Length() == KEapExpandedTypeLength); |
|
262 |
|
263 iValue.Copy(right_type_value); |
|
264 |
|
265 EXPANDED_TYPE_EAP_TRACE_DATA( |
|
266 (EAPL("TEapExpandedType::operator ="), |
|
267 iValue.Ptr(), |
|
268 iValue.Length())); |
|
269 |
|
270 return *this; |
|
271 } |
|
272 |
|
273 //-------------------------------------------------- |
|
274 |
|
275 EAP_FUNC_EXPORT TInt TEapExpandedType::Compare(const TEapExpandedType &right_type_value) const |
|
276 { |
|
277 for (TUint ind = 0ul; ind < KEapExpandedTypeLength; ++ind) |
|
278 { |
|
279 const TUint8 left = iValue[ind]; |
|
280 const TUint8 right = right_type_value.GetValue()[ind]; |
|
281 |
|
282 if (left != right) |
|
283 { |
|
284 return iValue[ind] - right_type_value.GetValue()[ind]; |
|
285 } |
|
286 } |
|
287 |
|
288 return 0; |
|
289 } |
|
290 |
|
291 //-------------------------------------------------- |
|
292 |
|
293 EAP_FUNC_EXPORT bool TEapExpandedType::operator == (const TEapExpandedType &right_type_value) const |
|
294 { |
|
295 return Compare(right_type_value) == 0; |
|
296 } |
|
297 |
|
298 //-------------------------------------------------- |
|
299 |
|
300 EAP_FUNC_EXPORT bool TEapExpandedType::operator != (const TEapExpandedType &right_type_value) const |
|
301 { |
|
302 return Compare(right_type_value) != 0; |
|
303 } |
|
304 |
|
305 //-------------------------------------------------- |
|
306 // End of file |
|