|
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Methods, data structures and constants common to Feature Registry Setup EXE |
|
15 // and Public API DLL, including private panic method. |
|
16 // |
|
17 // |
|
18 |
|
19 #ifndef FEATREGCMN_H |
|
20 #define FEATREGCMN_H |
|
21 |
|
22 #include <e32std.h> |
|
23 #include <e32property.h> |
|
24 #include <f32file.h> |
|
25 #include <featregpan.h> |
|
26 |
|
27 _LIT(KFeatureConfigFile,"_:\\private\\102744CA\\featreg.cfg"); |
|
28 typedef TBuf<32> TConfigFileName; |
|
29 |
|
30 _LIT(KFeatRegSetupExe, "z:\\sys\\bin\\featregsetup.exe"); |
|
31 |
|
32 //match pattern when searching for the file |
|
33 //note that for core image the file will be featreg.cfg |
|
34 //and for other rofs section it will be in the format featreg.cfg[x-y] |
|
35 //whwere x is the rom image id and y is currently set to 0(unused) |
|
36 _LIT(KFeatregMatchPattern,"featreg.cfg*"); |
|
37 _LIT(KFeatregRomPrivatePath,"z:\\private\\102744CA\\"); |
|
38 |
|
39 // feature registry data is currently kept in an RProperty with category and key: |
|
40 const TUid KFeaturePropCat = { 0x102744CA }; |
|
41 const TUint KFeaturePropKey = 0; |
|
42 // if property with KFeaturePropCat and following key is defined, featregsetup.exe |
|
43 // looks for config info in its c: private data cage instead of z: (for tests only): |
|
44 const TUint KFeatRegConfigTestKey = 1; |
|
45 |
|
46 /** |
|
47 This function will try to find and open all the "featreg.cfg" files from the path specified |
|
48 process them in the order of increasing rom image id before copying the aggregate content |
|
49 into the buffer aBuf |
|
50 */ |
|
51 GLREF_C TInt ReadMultipleFeatureFileToBuf(RFs& aFs,const TDesC& aPath,RBuf8& aBuf); |
|
52 |
|
53 /** |
|
54 * First block of data in feature config file and resulting binary property: |
|
55 * says how many individual feature entries and "default-supported" ranges follow. |
|
56 * Config data is invalid if header is not present, or it does not predict size |
|
57 * of feature config file/property. |
|
58 */ |
|
59 class TFeatureHeader |
|
60 { |
|
61 public: |
|
62 TUint32 iTypePrefix; // must be equal to validTypePrefix |
|
63 TUint32 iVersionNumber; // zero is the only valid version number |
|
64 TUint32 iFeatureEntryCount; |
|
65 TUint32 iFeatureRangeCount; |
|
66 |
|
67 inline TUint32 PredictedPropertySize() const; |
|
68 inline void SetInvalid(); |
|
69 inline TBool IsInvalid() const; |
|
70 inline TBool IsInvalidOrBadSize(TUint32 aActualPropertySize) const; |
|
71 }; |
|
72 |
|
73 // First 4 bytes of config file: ASCII f-e-a-t. Stored in TUint32 in little endian, i.e. reverse order |
|
74 const TUint32 validTypePrefix = 0x74616566; |
|
75 const TUint32 invalidTypePrefix = 0; // must not equal validTypePrefix |
|
76 |
|
77 /** |
|
78 * Second block of data in feature config file and resulting binary property: |
|
79 * header.iFeatureEntryCount * TFeatureEntry |
|
80 * If a feature UID is listed, bits in its status word control the following: |
|
81 * - bit 0 (0x1): if set, feature is present, if not, feature is not present |
|
82 * - bit 1 (0x2): if set, feature is upgradable in this ROM configuration |
|
83 * - bits 2-31: reserved for future use & must be zero |
|
84 * Config data is invalid if these are not listed from lowest to highest UID with |
|
85 * no repeats. |
|
86 */ |
|
87 struct TFeatureEntry |
|
88 { |
|
89 TUint32 iUid; |
|
90 TUint32 iInfo; |
|
91 }; |
|
92 |
|
93 /** |
|
94 * Third/last block of data in feature config file and resulting binary property: |
|
95 * header.iFeatureRangeCount * TFeatureRange |
|
96 * Features with UIDs in these "default-supported" ranges are supported unless |
|
97 * they are individually listed in the "entry" block as not supported. |
|
98 * Config data is invalid if any ranges have iLowUid higher than iHighUid. |
|
99 */ |
|
100 struct TFeatureRange |
|
101 { |
|
102 TUint32 iLowUid; |
|
103 TUint32 iHighUid; |
|
104 }; |
|
105 |
|
106 GLREF_C void Panic(TFeatRegPanic aReason); |
|
107 |
|
108 |
|
109 // ------------------------------------------------------------------------- // |
|
110 // Methods, data structures and constants common to Feature Registry Setup EXE |
|
111 // and Public API DLL, including private panic method. |
|
112 // ------------------------------------------------------------------------- // |
|
113 |
|
114 |
|
115 /** |
|
116 Construct config file path for the system drive. |
|
117 @param aFileName On completion will contain the full path and filename. |
|
118 */ |
|
119 inline void GetSystemDrivePath(TConfigFileName& aFileName) |
|
120 { |
|
121 aFileName.Copy(KFeatureConfigFile); |
|
122 aFileName[0] = 'A' + static_cast<TInt>(RFs::GetSystemDrive()); |
|
123 } |
|
124 |
|
125 |
|
126 |
|
127 /** returns the total size of the property that is predicted by the counts |
|
128 in the header. Confirm !IsInvalid() before using otherwise numerical |
|
129 overflow may occur */ |
|
130 inline TUint32 TFeatureHeader::PredictedPropertySize() const |
|
131 { |
|
132 return sizeof(TFeatureHeader) + |
|
133 + iFeatureEntryCount * sizeof(TFeatureEntry) |
|
134 + iFeatureRangeCount * sizeof(TFeatureRange); |
|
135 } |
|
136 |
|
137 /** sets invalid values in the header that API will report as corrupt regardless |
|
138 of what data is provided with it */ |
|
139 inline void TFeatureHeader::SetInvalid() |
|
140 { |
|
141 iTypePrefix = invalidTypePrefix; |
|
142 iVersionNumber = 1; // i.e. not zero |
|
143 // note total size of feature property may not exceed these constants, |
|
144 // so they are definitely invalid |
|
145 iFeatureEntryCount = RProperty::KMaxLargePropertySize + 1; |
|
146 iFeatureRangeCount = RProperty::KMaxLargePropertySize + 1; |
|
147 } |
|
148 |
|
149 /** asks whether the header contains invalid values irrespective of data size |
|
150 See also IsInvalidOrBadSize() below */ |
|
151 inline TBool TFeatureHeader::IsInvalid() const |
|
152 { |
|
153 // pretty safe to assume RProperty::KMaxLargePropertySize will not |
|
154 // ever be large enough to cause overflow problems |
|
155 return (iTypePrefix != validTypePrefix) |
|
156 || (iVersionNumber != 0) |
|
157 || (iFeatureEntryCount > RProperty::KMaxLargePropertySize) |
|
158 || (iFeatureRangeCount > RProperty::KMaxLargePropertySize) |
|
159 || (PredictedPropertySize() > RProperty::KMaxLargePropertySize); |
|
160 } |
|
161 |
|
162 /** asks whether aActualPropertySize is in the valid range, header is invalid or |
|
163 mismatch between property size predicted by the header and that supplied */ |
|
164 inline TBool TFeatureHeader::IsInvalidOrBadSize(TUint32 aActualPropertySize) const |
|
165 { |
|
166 return (aActualPropertySize < sizeof(TFeatureHeader)) |
|
167 || (aActualPropertySize > RProperty::KMaxLargePropertySize) |
|
168 || IsInvalid() |
|
169 || (PredictedPropertySize() != aActualPropertySize); |
|
170 } |
|
171 |
|
172 |
|
173 #endif |