|
1 /* |
|
2 * Copyright (c) 2002-2006 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: Implementation of the ScanList class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "hssscanlist.h" |
|
21 #include "hssscanoffsets.h" |
|
22 |
|
23 // ================= MEMBER FUNCTIONS ======================= |
|
24 |
|
25 // --------------------------------------------------------------------------- |
|
26 // |
|
27 // --------------------------------------------------------------------------- |
|
28 // |
|
29 HssScanList::HssScanList():count_m( 0 ), size_m( 0 ) |
|
30 { |
|
31 } |
|
32 |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 // --------------------------------------------------------------------------- |
|
36 // |
|
37 TUint32 HssScanList::Append( TUint32 size, const HssScanFrame* data_pointer ) |
|
38 { |
|
39 |
|
40 if( AddPadding( size ) >= ( HSS_SCAN_LIST_DATA_SIZE - size_m ) ) |
|
41 { |
|
42 |
|
43 return HSS_APPEND_FAILED_NO_MEMORY; |
|
44 } |
|
45 |
|
46 TUint8* dst = data_m + size_m; |
|
47 const TUint8* src = data_pointer; |
|
48 const TUint8* end = data_pointer + size; |
|
49 |
|
50 for ( ; src < end; ++dst, ++src ) |
|
51 { |
|
52 *dst = *src; |
|
53 } |
|
54 |
|
55 // The checking has to been done after copying it to the buffer |
|
56 // due it relies the buffers limits. |
|
57 if ( CheckData( data_m + size_m ) ) |
|
58 { // Add data only if it is valid. |
|
59 size_m += AddPadding( size ); |
|
60 ++count_m; |
|
61 } |
|
62 |
|
63 return size_m; |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 TUint32 HssScanList::Append( TUint32 size ) |
|
71 { |
|
72 |
|
73 if ( CheckData( data_m + size_m ) ) |
|
74 { // Add data only if it is valid. |
|
75 size_m += AddPadding( size ); |
|
76 ++count_m; |
|
77 } |
|
78 |
|
79 return size_m; |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 |
|
87 TBool HssScanList::CheckData( HssScanFrame* data ) const |
|
88 { |
|
89 // Check that the data is at the range. |
|
90 if ( data < data_m || |
|
91 data > data_m + size_m || |
|
92 size_m + sizeof( TUint16 ) > HSS_SCAN_LIST_DATA_SIZE ) |
|
93 { |
|
94 return false; |
|
95 } |
|
96 |
|
97 // Calculate the length of the data. |
|
98 TUint16 size = static_cast<TUint16>( *( reinterpret_cast<const TUint32*>( data + LENGTH_OFFSET ) ) + CNTRL_HEADER_LEN); |
|
99 |
|
100 // Check that the whole data fits to the buffer. |
|
101 if ( data + size > data_m + HSS_SCAN_LIST_DATA_SIZE ) |
|
102 { |
|
103 return false; |
|
104 } |
|
105 |
|
106 const TUint8* currentIE; |
|
107 |
|
108 // Search mandatory IEs. |
|
109 for ( TUint i = 0; i < HSS_MANDATORY_IE_LIST_SIZE; ++i ) |
|
110 { |
|
111 // Go through all IEs. |
|
112 for ( currentIE = data + BODY_OFFSET; |
|
113 ; // No condition here -- it is in the loop. |
|
114 currentIE += *( currentIE + 1 ) + 2 ) |
|
115 { |
|
116 if ( currentIE < data + size ) |
|
117 { // Still searching... |
|
118 if ( *currentIE == HSS_MANDATORY_IE_LIST[i] ) |
|
119 { // We have a match! Lets find out the next one. |
|
120 break; |
|
121 } |
|
122 } |
|
123 else |
|
124 { // The IE was not found. |
|
125 return false; |
|
126 } |
|
127 } |
|
128 } |
|
129 // Data is ok. |
|
130 return true; |
|
131 } |