|
1 // Copyright (c) 1999-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 // |
|
15 |
|
16 #ifndef BTREGISTRYDB_H |
|
17 #define BTREGISTRYDB_H |
|
18 |
|
19 class CSecurityDecryptBase; |
|
20 class CSecurityEncryptBase; |
|
21 |
|
22 #include <d32dbms.h> |
|
23 #include <btdevice.h> |
|
24 #include <btmanclient.h> |
|
25 #include <f32file.h> |
|
26 #include <bamatch.h> |
|
27 #include <btdefcommport.h> |
|
28 #include <bt_subscribe.h> |
|
29 #include "btmanclientserver.h" |
|
30 |
|
31 const static TInt KArrayGranularity=8; |
|
32 const static TInt KMaxConstraintLen=40; |
|
33 static const TUid KBTManServerUid = {0x100069cc}; |
|
34 |
|
35 // DB, Table names |
|
36 |
|
37 // KBTRegsitryDatabaseSecure should not be accessed directly |
|
38 // Use TBTRegistryDatabaseSecure class instead |
|
39 _LIT(KBTRegistryDatabaseSecure, "btregistry"); |
|
40 _LIT(KBTRegistryDatabaseSecurePolicy, "secure[100069cc]"); |
|
41 _LIT(KPersistTable, "PersistData"); |
|
42 _LIT(KDeviceTable, "DeviceData"); |
|
43 _LIT(KCSYTable, "BTCOMMData"); |
|
44 _LIT(KMetaTable, "MetaData"); |
|
45 |
|
46 // values |
|
47 _LIT8(KDefaultLocalName, "Symbian Device"); |
|
48 |
|
49 // Local device (aka Persistance) table schema |
|
50 // Post-JS, we only need to persist what users can change |
|
51 // and this will involve fewer ioctls. |
|
52 // The Link Mgr will actively set the appropriate values based on |
|
53 // what the clients have requested of it - so when the stack goes |
|
54 // and therefore by definition, all the clients have closed their sockets |
|
55 // then next time something starts the values will be set by the stack |
|
56 _LIT(KPersistColName_CoD, "CoD"); |
|
57 _LIT(KPersistColName_ScanEnable, "ScanEnable"); |
|
58 _LIT(KPersistColName_LocalName, "LocalName"); |
|
59 _LIT(KPersistColName_PowerSettings, "PowerSettings"); |
|
60 _LIT(KPersistColName_AFHChannelAssessmentMode, "AFHChannelAssessmentMode"); |
|
61 _LIT(KPersistColName_LimitedDiscoverable, "LimitedDiscoverable"); |
|
62 _LIT(KPersistColName_AcceptPairedOnlyMode, "AcceptPairedOnlyMode"); |
|
63 |
|
64 // CSY table schema |
|
65 _LIT(KBTCOMMColName_Port, "Port"); |
|
66 _LIT(KBTCOMMColName_ServiceUUID, "ServiceUUID"); |
|
67 _LIT(KBTCOMMColName_Security, "Security"); |
|
68 _LIT(KBTCOMMColName_ServiceName, "ServiceName"); |
|
69 |
|
70 // Remote device table schema |
|
71 |
|
72 _LIT(KDeviceColName_CoD, "CoD"); |
|
73 _LIT(KDeviceColName_CoD_MajorDev, "CoDMajorDev"); |
|
74 _LIT(KDeviceColName_CoD_MinorDev, "CoDMinorDev"); |
|
75 _LIT(KDeviceColName_CoD_Service, "CoDService"); |
|
76 _LIT(KDeviceColName_BluetoothName, "BluetoothName"); |
|
77 _LIT(KDeviceColName_FriendlyName, "FriendlyName"); |
|
78 _LIT(KDeviceColName_LinkKey, "LinkKey"); |
|
79 _LIT(KDeviceColName_LinkKeyType, "LinkKeyType"); |
|
80 _LIT(KDeviceColName_PassKey, "PassKey"); |
|
81 _LIT(KDeviceColName_PageScanMode, "PageScanMode"); |
|
82 _LIT(KDeviceColName_PageScanPeriodMode, "PageScanPeriodMode"); // not used in connection |
|
83 _LIT(KDeviceColName_PageScanRepMode, "PageScanRepetitionMode"); |
|
84 _LIT(KDeviceColName_LastSeen, "LastSeen"); |
|
85 _LIT(KDeviceColName_LastUsed, "LastConnected"); |
|
86 _LIT(KDeviceColName_GlobalSecSecurity, "GlobalSecurity"); |
|
87 _LIT(KDeviceColName_GlobalSecPasskeyLen, "GlobalPasskeyMinLength"); |
|
88 _LIT(KDeviceColName_UiCookie, "UiCookie"); |
|
89 |
|
90 |
|
91 // Meta table schema - DONT Change this otherwise we may lose version information |
|
92 _LIT(KMetaColName_VersionMajor, "MajorVersion"); |
|
93 _LIT(KMetaColName_VersionMinor, "MinorVersion"); |
|
94 |
|
95 // Columns common to all tables |
|
96 _LIT(KColName_DeviceAddress, "DeviceAddress"); |
|
97 _LIT(KColName_ProcessSID, "ProcessSID"); |
|
98 |
|
99 |
|
100 // |
|
101 |
|
102 const TUint32 KRegistryDBVersionMajor = 1; |
|
103 const TUint32 KRegistryDBVersionMinor = 2; |
|
104 // Version history: |
|
105 // 1.0 - Baseline |
|
106 // 1.1 - Adjusted the Time/Date fields for 64 bit integers (remote device table). |
|
107 // 1.2 - Added additional fields Link-key type and UI cookie (remote device table). |
|
108 |
|
109 // Useful SQL literals |
|
110 _LIT(KSQLIsNotNull, " IS NOT NULL"); |
|
111 _LIT(KSQLCommaSpace, ", "); |
|
112 _LIT(KSQLQuote, "'"); |
|
113 _LIT(KSQLHash, "#"); |
|
114 _LIT(KSQLEqual, "="); |
|
115 _LIT(KSQLGreaterEqual, ">="); |
|
116 _LIT(KSQLAnd, " AND "); |
|
117 _LIT(KSQLOr, " OR "); |
|
118 _LIT(KSQLLike, " LIKE "); |
|
119 _LIT(KSQLOpenParentheses, "("); |
|
120 _LIT(KSQLCloseParentheses, ")"); |
|
121 |
|
122 _LIT(KSQLSelectAllConstrained, "select * from %S WHERE %S"); |
|
123 _LIT(KSQLSelectAll, "select * from %S"); |
|
124 |
|
125 _LIT(KSQLWhere, "WHERE"); |
|
126 |
|
127 |
|
128 enum TBTRegistryDBPanic |
|
129 { |
|
130 ECorruptDeviceEntry, |
|
131 ENotOneLocalDeviceEntry, |
|
132 ETooManyLocalDeviceEntries, |
|
133 ETooManyRemoteDeviceEntries, |
|
134 EDeviceNotFound, |
|
135 EBadNameToUpdate, |
|
136 EMetaTableBroken, |
|
137 EColumnNotFound, |
|
138 EBTManColSetError, |
|
139 }; |
|
140 |
|
141 |
|
142 // forward declarations |
|
143 class RBTDbQuery; |
|
144 |
|
145 NONSHARABLE_CLASS(CBTRegistry) : public CBase |
|
146 /** |
|
147 Does all the work with DBMS. Stateless, so clients pass their views on the DB |
|
148 for this class to use on their behalf. |
|
149 **/ |
|
150 { |
|
151 public: |
|
152 static CBTRegistry* NewL(); |
|
153 ~CBTRegistry(); |
|
154 RDbView* OpenViewL(const TDesC& aSQLQuery, TDbBookmark& aBookmark); //opens and transfers ownership |
|
155 RDbView* OpenViewL(const RBTDbQuery& aQuery, TDbBookmark& aBookmark); //opens and transfers ownership |
|
156 RDbView* OpenDeviceL(const TBTDevAddr& aAddr, TDbBookmark& aBookmark); |
|
157 RDbView* OpenNullViewL(); |
|
158 TDbColNo ColumnNoL(const TDesC& aColName, const RDbRowSet& aRowSet); |
|
159 // for remote device table |
|
160 TBool DevicePresentL(const TBTDevAddr& aAddress); |
|
161 |
|
162 void CreateDeviceL(const CBTDevice& aDetails, TBool aStoreUiCookie, const TSecureId& aClientSID); |
|
163 |
|
164 const TBTNamelessDevice* GetNextNamelessDeviceLC(RDbRowSet& aRowSet, TDbBookmark& aBookmark, TBool includeKeys); |
|
165 CBTDevice* GetNextDeviceL(RDbRowSet& aRowSet, TDbBookmark& aBookmark, TBool includeLinkKey); |
|
166 const TUid CreatingProcessUidL(RDbRowSet& aRowSet); |
|
167 void UpdateDeviceL(RDbRowSet& aRowSet, const CBTDevice& aDevice); |
|
168 void UnpairL(RDbRowSet& aRowSet); |
|
169 void UnpairViewL(RDbRowSet& aRowSet); |
|
170 |
|
171 void DeleteViewL(RDbRowSet& aRowSet, TBool aDeleteAll, const TSecureId& aSecureId); |
|
172 |
|
173 void UpdateNameL(const TBTDevAddr& aAddress, const TDesC8& aName, TBTManServerRequest aRequest); |
|
174 // for local device table |
|
175 TBTLocalDevice* GetLocalDeviceLC(); |
|
176 void UpdateLocalDeviceL(const TBTLocalDevice& aDevice); |
|
177 // CSY table |
|
178 const TBTCommPortSettings* GetCommPortSettingsLC(const TBTCommPortSettings& aPort); |
|
179 |
|
180 void AddCommPortSettingsL(const TBTCommPortSettings& aSettings, const TSecureId& aClientSID); |
|
181 |
|
182 void UpdateCommPortSettingsL(RDbView& aView, const TBTCommPortSettings& aSettings); |
|
183 void DeleteCommPortSettingsL(RDbView& aCommPortSettingsView); |
|
184 RDbView* OpenCommPortLC(const TBTCommPortSettings& aSettings); |
|
185 RDbView* OpenCommPortL(const TBTCommPortSettings& aSettings); |
|
186 |
|
187 private: |
|
188 RDbTable* OpenTableL(const TDesC& aTable); // opens and transfers ownership |
|
189 RDbTable* OpenPersistTableL(); // opens and transfers ownership |
|
190 RDbTable* OpenDeviceTableL(); // opens and transfers ownership |
|
191 RDbTable* OpenCSYTableL(); // opens and transfers ownership |
|
192 void SetMetaDataL(); |
|
193 void ValidateMetaTableL(); |
|
194 void ValidatePersistTableL(); |
|
195 void CreateMetaTableL(); |
|
196 void CreateDeviceTableL(); |
|
197 void CreateCSYTableL(); |
|
198 void CreatePersistTableL(); |
|
199 void CreateRegistryL(); |
|
200 void OpenRegistryL(); |
|
201 void PurgeDebugLinkKeysL(); |
|
202 void SetDeviceL(RDbRowSet& aRowSet, const CBTDevice& aDevice, TBool aIgnoreUiCookie = EFalse); |
|
203 void IncrementRowL(RDbRowSet& aRowSet, TDbBookmark& aBookmark); |
|
204 void GetRowL(RDbRowSet& aRowSet, const TDbBookmark& aBookmark); |
|
205 void GetNamelessDetailsL(TBTNamelessDevice& aDevice, RDbRowSet& aRowSet, TBool includeKeys); |
|
206 void PutCommPortSettingsInTableL(RDbRowSet& aRowSet, const TBTCommPortSettings& aSettings); |
|
207 void CleanPutL(RDbRowSet& aRowSet); |
|
208 void ConstructL(); |
|
209 CBTRegistry(); |
|
210 void DeleteCorruptRegistryL(); |
|
211 void SetupDefaultRegistryL(); |
|
212 void GetDefaultDeviceFromIniL(TBTLocalDevice& aDevice); |
|
213 TBool FindVar(const TDesC8& aPtr, const TDesC8& aVarName, TPtrC8& aResult) const; |
|
214 TBool FindVar(const TDesC8& aPtr, const TDesC8& aVarName, TInt& aResult) const; |
|
215 TInt SetDeviceName(const TDesC& aDeviceName, TBTLocalDevice& aDevice); |
|
216 TBool SetDeviceNameFromIniFile(TBTLocalDevice& aDevice, RBuf8& bufPtr); |
|
217 private: |
|
218 RDbNamedDatabase iDB; |
|
219 RDbs iDBMSServer; |
|
220 }; |
|
221 |
|
222 |
|
223 NONSHARABLE_CLASS(RBTDbQuery) |
|
224 /** |
|
225 Encapsulates SQL Queries. |
|
226 Provides utility functions escaping certain characters, and formatting functions |
|
227 **/ |
|
228 { |
|
229 public: |
|
230 RBTDbQuery(); |
|
231 void FindDeviceL(const TBTDevAddr& aBDAddr); |
|
232 void FindCommPortL(TUint32 aUnitNumber); |
|
233 void MatchLinkKeyTypeL(TBTLinkKeyType aLinkKeyType); |
|
234 void SearchL(const TBTRegistrySearch& aSearch); |
|
235 const TDesC& QueryBuf() const; |
|
236 TPtrC ConstraintBuf() const; |
|
237 void Close(); |
|
238 private: |
|
239 const TPtrC QuoteEscapeLC(const TBTDevAddr& aBDAddr) const; |
|
240 const TPtrC QuoteEscapeLC(const TDesC& aBDAddr) const; |
|
241 void ExtendForAnotherTokenL(RTextBuf& aSQLBuf, TUint aMask); |
|
242 private: |
|
243 RTextBuf iQueryBuf; |
|
244 }; |
|
245 |
|
246 |
|
247 NONSHARABLE_CLASS(TBTRegistryDatabaseSecure) |
|
248 /** |
|
249 Defines location of BT registry database |
|
250 **/ |
|
251 { |
|
252 public: |
|
253 TBTRegistryDatabaseSecure(); |
|
254 const TDesC& operator()() const; |
|
255 |
|
256 private: |
|
257 TBuf<KMaxFileName> iBuf; |
|
258 }; |
|
259 |
|
260 #endif |