|
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 // Generic functions associated with all Bluetooth socket addresses |
|
15 // |
|
16 // |
|
17 |
|
18 #include <bluetooth/logger.h> |
|
19 #include <bt_sock.h> |
|
20 |
|
21 #ifdef __FLOG_ACTIVE |
|
22 _LIT8(KLogComponent, LOG_COMPONENT_BTLIB); |
|
23 #endif |
|
24 |
|
25 #ifdef _DEBUG |
|
26 PANICCATEGORY("BtLib"); |
|
27 #endif |
|
28 |
|
29 enum TBTSockPanics |
|
30 { |
|
31 EUnfinishedBusiness = 0, |
|
32 EBadArgument = 1, |
|
33 EBadRequest = 2, |
|
34 EBTExportedMethodMovedDLL =3, |
|
35 }; |
|
36 void Panic(TBTSockPanics aCode) |
|
37 { |
|
38 _LIT(KPanicName, "BTSock"); |
|
39 User::Panic(KPanicName, aCode); |
|
40 } |
|
41 |
|
42 EXPORT_C TBTSockAddr::TBTSockAddr() |
|
43 /** |
|
44 Constructor |
|
45 @publishedAll |
|
46 @released |
|
47 */ |
|
48 { |
|
49 SetFamily(KBTAddrFamily); |
|
50 SetUserLen(sizeof(SBTAddrSecurity)); |
|
51 AddressPtr().FillZ(); |
|
52 |
|
53 // set default security |
|
54 TBTServiceSecurity defaultSec; |
|
55 defaultSec.SetAuthorisation(EFalse); |
|
56 defaultSec.SetAuthentication(EMitmNotRequired); |
|
57 defaultSec.SetDenied(EFalse); |
|
58 defaultSec.SetEncryption(EFalse); |
|
59 defaultSec.SetPasskeyMinLength(0); |
|
60 |
|
61 BTAddrSecStruct().iSecurity = defaultSec; |
|
62 } |
|
63 |
|
64 EXPORT_C TBTSockAddr::TBTSockAddr(const TSockAddr &aAddr) |
|
65 /** |
|
66 Constructor taking socket address baseclass reference. Rather like a copy constructor |
|
67 |
|
68 Copies the port number and the entirety of the user data, which conatins |
|
69 the Bluetooth Address and Security Settings |
|
70 |
|
71 The family type is set to KBTAddrFamily |
|
72 @param aAddr a previously filled TSockAddr |
|
73 @publishedAll |
|
74 @released |
|
75 */ |
|
76 { |
|
77 SetFamily(KBTAddrFamily); |
|
78 SetPort(aAddr.Port()); |
|
79 SetUserLen(sizeof(SBTAddrSecurity)); |
|
80 // Copy the user data |
|
81 // The strange cast is to get at UserPtr() while ensuring |
|
82 // that the compiler does not try and create a temporary |
|
83 Mem::Copy(UserPtr(), (*static_cast<const TBTSockAddr*>(&aAddr)).UserPtr(), GetUserLen()); |
|
84 } |
|
85 |
|
86 EXPORT_C TBTDevAddr TBTSockAddr::BTAddr() const |
|
87 /** |
|
88 Getter |
|
89 @return The device address specified by this Socket address |
|
90 @publishedAll |
|
91 @released |
|
92 */ |
|
93 { |
|
94 return BTAddrSecStruct().iAddress; |
|
95 } |
|
96 |
|
97 EXPORT_C void TBTSockAddr::SetBTAddr(const TBTDevAddr& aRemote) |
|
98 /** |
|
99 Sets BT address from a TBTDevAddr. |
|
100 @param aRemote Bluetooth device address of remote device |
|
101 @publishedAll |
|
102 @released |
|
103 */ |
|
104 { |
|
105 BTAddrSecStruct().iAddress = aRemote; |
|
106 } |
|
107 |
|
108 EXPORT_C void TBTSockAddr::SetSecurity(const TBTServiceSecurity& aSecurity) |
|
109 /** |
|
110 Setter |
|
111 Care needs to be taken when setting outgoing security as if a device in the system |
|
112 is using pre-Bluetooth v2.1 hardware then connection attempts may fail. |
|
113 @param aSecurity reference to const TBTServiceSecurity holding security settings |
|
114 @publishedAll |
|
115 @released |
|
116 */ |
|
117 { |
|
118 BTAddrSecStruct().iSecurity = aSecurity; |
|
119 } |
|
120 |
|
121 |
|
122 EXPORT_C TAny* TBTSockAddr::EndBTSockAddrPtr() const |
|
123 { |
|
124 return UserPtr()+sizeof(SBTAddrSecurity); |
|
125 } |
|
126 |
|
127 TBTSockAddr::SBTAddrSecurity& TBTSockAddr::BTAddrSecStruct() const |
|
128 { |
|
129 return *reinterpret_cast<SBTAddrSecurity*>(UserPtr()); |
|
130 } |
|
131 |
|
132 TPtr8 TBTSockAddr::AddressPtr() const |
|
133 { |
|
134 return BTAddrSecStruct().iAddress.Des(); |
|
135 } |
|
136 |
|
137 EXPORT_C TBTServiceSecurity TBTSockAddr::BTSecurity() const |
|
138 /** |
|
139 Getter |
|
140 @return Security settings |
|
141 */ |
|
142 { |
|
143 return BTAddrSecStruct().iSecurity; |
|
144 } |
|
145 |
|
146 EXPORT_C TBTSockAddr& TBTSockAddr::Cast(const TSockAddr &aAddr) |
|
147 /** |
|
148 Utility function to downcast a TSockAddr to a TBTSockAddr |
|
149 @return TBTSockAddr reference |
|
150 */ |
|
151 { |
|
152 return *((TBTSockAddr*)&aAddr); |
|
153 } |
|
154 |
|
155 /****** Inquiry Socket Addresses *****/ |
|
156 |
|
157 /** Constructor for TInquirySockAddr object |
|
158 */ |
|
159 EXPORT_C TInquirySockAddr::TInquirySockAddr() |
|
160 { |
|
161 SetFamily(KBTAddrFamily); |
|
162 SetUserLen(sizeof(SInquiryAddr)); |
|
163 AddressPtr().FillZ(); |
|
164 SetVersion(TVersion(1, 1, 0)); |
|
165 } |
|
166 |
|
167 /** Constructor taking socket address base class reference. Rather like a copy constructor |
|
168 |
|
169 Copies the port number and the entirety of the user data, which contains |
|
170 the Bluetooth Address |
|
171 |
|
172 The family type is set to KBTAddrFamily |
|
173 @param aAddr a previously filled TSockAddr |
|
174 */ |
|
175 EXPORT_C TInquirySockAddr::TInquirySockAddr(const TSockAddr &aAddr) |
|
176 { |
|
177 SetFamily(KBTAddrFamily); |
|
178 SetUserLen(sizeof(SInquiryAddr)); |
|
179 AddressPtr().Copy((*static_cast<const TInquirySockAddr*>(&aAddr)).AddressPtr()); |
|
180 SetPort(aAddr.Port()); |
|
181 InquiryAddrStruct() = TInquirySockAddr::Cast(aAddr).InquiryAddrStruct(); |
|
182 SetVersion(TVersion(1, 1, 0)); |
|
183 } |
|
184 |
|
185 /** Getter. |
|
186 @return The device address specified by this Socket address. |
|
187 */ |
|
188 EXPORT_C TBTDevAddr TInquirySockAddr::BTAddr() const |
|
189 { |
|
190 return InquiryAddrStruct().iAddress; |
|
191 } |
|
192 /** Setter. |
|
193 @param aRemote is bluetooth device address |
|
194 */ |
|
195 EXPORT_C void TInquirySockAddr::SetBTAddr(const TBTDevAddr& aRemote) |
|
196 { |
|
197 InquiryAddrStruct().iAddress = aRemote; |
|
198 } |
|
199 |
|
200 /** Utility function to downcast a TSockAddr to a TInquirySockAddr |
|
201 @param aAddr Represents an end point address |
|
202 @return Socket address used for inquiries |
|
203 */ |
|
204 EXPORT_C TInquirySockAddr& TInquirySockAddr::Cast(const TSockAddr &aAddr) |
|
205 { |
|
206 return *((TInquirySockAddr *)&aAddr); |
|
207 } |
|
208 |
|
209 /** Getter for major service class of the device |
|
210 @return The major service class of device |
|
211 */ |
|
212 EXPORT_C TUint16 TInquirySockAddr::MajorServiceClass() const |
|
213 { |
|
214 return InquiryAddrStruct().iMajorServiceClass; |
|
215 } |
|
216 |
|
217 /** Sets major service class of the device |
|
218 @param aClass is major service class to be assigned |
|
219 */ |
|
220 EXPORT_C void TInquirySockAddr::SetMajorServiceClass(TUint16 aClass) |
|
221 { |
|
222 InquiryAddrStruct().iMajorServiceClass=aClass; |
|
223 } |
|
224 |
|
225 /** Getter for major device class |
|
226 @return The major class of device |
|
227 */ |
|
228 EXPORT_C TUint8 TInquirySockAddr::MajorClassOfDevice() const |
|
229 { |
|
230 return InquiryAddrStruct().iMajorDeviceClass; |
|
231 } |
|
232 |
|
233 /** Sets major device class |
|
234 @param aClass is major class of device to be assigned |
|
235 */ |
|
236 EXPORT_C void TInquirySockAddr::SetMajorClassOfDevice(TUint8 aClass) |
|
237 { |
|
238 InquiryAddrStruct().iMajorDeviceClass=aClass; |
|
239 } |
|
240 |
|
241 /** Getter for minor device class |
|
242 @return The minor class of device |
|
243 */ |
|
244 EXPORT_C TUint8 TInquirySockAddr::MinorClassOfDevice() const |
|
245 { |
|
246 return InquiryAddrStruct().iMinorDeviceClass; |
|
247 } |
|
248 |
|
249 /** Sets minor device class |
|
250 @param aClass is minor device class to be assigned |
|
251 */ |
|
252 EXPORT_C void TInquirySockAddr::SetMinorClassOfDevice(TUint8 aClass) |
|
253 { |
|
254 InquiryAddrStruct().iMinorDeviceClass=aClass; |
|
255 } |
|
256 |
|
257 /** Getter for Inquiry Access Code |
|
258 @return Inquiry Access Code |
|
259 */ |
|
260 EXPORT_C TUint TInquirySockAddr::IAC() const |
|
261 { |
|
262 return InquiryAddrStruct().iIAC; |
|
263 } |
|
264 |
|
265 /** Sets the Inquiry Access Code |
|
266 @param aIAC is Inquiry Access Code to be assigned |
|
267 */ |
|
268 EXPORT_C void TInquirySockAddr::SetIAC(const TUint aIAC) |
|
269 { |
|
270 InquiryAddrStruct().iIAC=aIAC; |
|
271 } |
|
272 |
|
273 /** Utility function to get the host resolve action option |
|
274 @return action which can be KHostResInquiry and/or KHostResName |
|
275 */ |
|
276 EXPORT_C TUint8 TInquirySockAddr::Action() const |
|
277 { |
|
278 return InquiryAddrStruct().iActionFlags; |
|
279 } |
|
280 |
|
281 /** Utility function to set the host resolve action option |
|
282 @param aFlags can be KHostResInquiry and/or KHostResName |
|
283 */ |
|
284 EXPORT_C void TInquirySockAddr::SetAction(TUint8 aFlags) |
|
285 { |
|
286 InquiryAddrStruct().iActionFlags=aFlags; |
|
287 } |
|
288 |
|
289 /** Utility function to get SInquiryAddr |
|
290 @return SInquiryAddr class contained within the TInquirySockAddr |
|
291 */ |
|
292 EXPORT_C TInt8 TInquirySockAddr::Rssi() const |
|
293 { |
|
294 return InquiryAddrStruct().iRssi; |
|
295 } |
|
296 |
|
297 EXPORT_C void TInquirySockAddr::SetRssi(const TInt8 aRssi) |
|
298 { |
|
299 InquiryAddrStruct().iRssi=aRssi; |
|
300 } |
|
301 |
|
302 EXPORT_C TUint8 TInquirySockAddr::ResultFlags() const |
|
303 { |
|
304 return InquiryAddrStruct().iResultFlags; |
|
305 } |
|
306 |
|
307 EXPORT_C void TInquirySockAddr::SetResultFlags(TUint8 aResultFlags) |
|
308 { |
|
309 InquiryAddrStruct().iResultFlags=aResultFlags; |
|
310 } |
|
311 |
|
312 |
|
313 TInquirySockAddr::SInquiryAddr& TInquirySockAddr::InquiryAddrStruct() const |
|
314 { |
|
315 return *reinterpret_cast<SInquiryAddr*>(UserPtr()); // this class' data at end of superclass |
|
316 } |
|
317 |
|
318 /** Getter |
|
319 @return bluetooth device address |
|
320 */ |
|
321 TPtr8 TInquirySockAddr::AddressPtr() const |
|
322 { |
|
323 return InquiryAddrStruct().iAddress.Des(); |
|
324 } |
|
325 |
|
326 /** Getter |
|
327 @return version information |
|
328 */ |
|
329 EXPORT_C TVersion TInquirySockAddr::Version() const |
|
330 { |
|
331 TInt major = InquiryAddrStruct().iFormatTypeField >> 6; |
|
332 TInt minor = InquiryAddrStruct().iFormatTypeField >> 4; |
|
333 minor &= 0x03; // 0011 |
|
334 return TVersion(major, minor, 0); // build number unused and returned as zero |
|
335 } |
|
336 |
|
337 /** |
|
338 Sets a version number. Only the major and minor numbers of the TVersion parameter are used. Both these must be <=3. |
|
339 @param aVersion TVersion specifying version number to be assigned |
|
340 @internalComponent |
|
341 */ |
|
342 void TInquirySockAddr::SetVersion(TVersion aVersion) |
|
343 { |
|
344 // N.B. TVersion's iBuild number is not used |
|
345 TInt major = aVersion.iMajor; |
|
346 TInt minor = aVersion.iMinor; |
|
347 ASSERT_DEBUG(major<=3 && minor<=3); // since we only want to use 2 bits for each major/minor number in iFormatTypeField |
|
348 major = major << 6; |
|
349 minor = minor << 4; |
|
350 TUint8 version = major | minor; // MMmmbb00, where M = major, m = minor, b = build (not used) |
|
351 InquiryAddrStruct().iFormatTypeField &= 0x0F; // 0000 1111 - set first 4 bits to 0 (erase) |
|
352 InquiryAddrStruct().iFormatTypeField |= version; // set version information from aVersion |
|
353 } |
|
354 |
|
355 /** Getter |
|
356 @return Format Type Field number |
|
357 */ |
|
358 EXPORT_C TUint8 TInquirySockAddr::FormatTypeField() const |
|
359 { |
|
360 // only the 2 least significant bits of iFormatTypeField are used (the other bits are used for version information) |
|
361 return (InquiryAddrStruct().iFormatTypeField & 0x03); |
|
362 } |
|
363 |
|
364 /** Sets the Format Type Field number. This is defined as a 2 bit value and so must be <=3. |
|
365 @param aType is Format Type Field number to be assigned |
|
366 @internalComponent |
|
367 */ |
|
368 void TInquirySockAddr::SetFormatTypeField(TUint8 aType) |
|
369 { |
|
370 InquiryAddrStruct().iFormatTypeField &= 0xFC; // 1111 1100 - set last 2 bits to 0 (erase) |
|
371 InquiryAddrStruct().iFormatTypeField |= (aType & 0x03); // 0000 0011 - set last 2 bits of iFormatTypeField to those in aFlags |
|
372 } |
|
373 |
|
374 |
|
375 /************ Service Security ************/ |
|
376 |
|
377 EXPORT_C TBTServiceSecurity::TBTServiceSecurity(const TBTServiceSecurity& aService) |
|
378 /** |
|
379 Copy constructor |
|
380 @publishedAll |
|
381 @released |
|
382 */ |
|
383 { |
|
384 iUid = aService.Uid(); |
|
385 iSecurityRequirements = aService.iSecurityRequirements; |
|
386 } |
|
387 |
|
388 EXPORT_C TBTServiceSecurity::TBTServiceSecurity() |
|
389 /** |
|
390 Default constructor. |
|
391 Sets all member data to 0. |
|
392 @publishedAll |
|
393 @released |
|
394 */ |
|
395 { |
|
396 iUid.iUid = 0; |
|
397 } |
|
398 |
|
399 EXPORT_C void TBTServiceSecurity::SetUid(TUid aUid) |
|
400 /** |
|
401 Set Uid of the service - used opaquely by Bluetooth system. |
|
402 |
|
403 When a security procedure is initiated the Uid may be given to the notifier framework. |
|
404 The notifier can then use the Uid to produce a displayable string |
|
405 detailing the service to which the security procudure pertains. |
|
406 @param aUid |
|
407 The uid of the service. This is not the Bluetooth UUID, |
|
408 but is a Symbian-allocated Uid. |
|
409 @publishedAll |
|
410 @released |
|
411 */ |
|
412 { |
|
413 iUid = aUid; |
|
414 } |
|
415 |
|
416 |
|
417 EXPORT_C void TBTServiceSecurity::SetAuthentication(TBool aPreference) |
|
418 /** |
|
419 Sets whether or not any connections to this service need to be authenticated. |
|
420 |
|
421 Authentication involves the comparison of a stored link key. If no link key |
|
422 has been generated and stored (e.g. the remote device has never been authenticated before) |
|
423 then the user will be asked to enter a pin code (a process known as pairing). |
|
424 If authentication fails, the connection will not be permitted. |
|
425 |
|
426 For Bluetooth v2.1 and onward this has slightly changed in that pin code entry is not neccessary |
|
427 to generate a link key. Because of this, this API has been deprecated, users of this API are |
|
428 encouraged to migrate to the alterative SetAuthentication method which specifies the level of |
|
429 Man-in-the-Middle protection required for the service. |
|
430 |
|
431 @see TBTServiceSecurity::SetAuthentication(TBluetoothMitmProtection aPreference) |
|
432 |
|
433 @param aPreference if aPreference = EFalse then the Bluetooth stack will not perform pairing on Bluetooth v2.0 |
|
434 and earlier connections. |
|
435 @publishedAll |
|
436 @deprecated The TBTServiceSecurity::SetAuthentication(TBluetoothMitmProtection) |
|
437 function should be used instead. |
|
438 */ |
|
439 { |
|
440 iSecurityRequirements.SetAuthentication(aPreference); |
|
441 } |
|
442 |
|
443 EXPORT_C void TBTServiceSecurity::SetAuthorisation(TBool aPreference) |
|
444 /** |
|
445 Sets whether or not any connections to this service need to be authorised. |
|
446 |
|
447 A dialog will be presented to the user alerting them of the connection. This will |
|
448 occur for every connection to this service unless the user has explicitly expressed |
|
449 their trust for the remote device during a previous connection. |
|
450 Note: it should not be assumed that the UI will support the setting up of trust for remote devices. |
|
451 @param aPreference. |
|
452 if aPreference = ETrue then the Bluetooth stack will perform authorisation |
|
453 @publishedAll |
|
454 @released |
|
455 */ |
|
456 { |
|
457 iSecurityRequirements.SetAuthorisation(aPreference); |
|
458 } |
|
459 |
|
460 EXPORT_C void TBTServiceSecurity::SetEncryption(TBool aPreference) |
|
461 /** |
|
462 Sets whether or not any connections to this service need to be encrypted. |
|
463 |
|
464 Authentication must precede encryption, therefore it is recommended that SetAuthentication(ETrue) |
|
465 is also called. |
|
466 If encryption fails, the connection will not be permitted. |
|
467 @param aPreference. |
|
468 if aPreference = ETrue then the Bluetooth stack will perform encryption |
|
469 @publishedAll |
|
470 @released |
|
471 */ |
|
472 { |
|
473 iSecurityRequirements.SetEncryption(aPreference); |
|
474 } |
|
475 |
|
476 EXPORT_C void TBTServiceSecurity::SetDenied(TBool aPreference) |
|
477 /** |
|
478 Sets whether or not connections to this service are being denied to all but specified devices. |
|
479 |
|
480 @param aPreference. if aPreference = ETrue then the Bluetooth stack will deny the connection |
|
481 @see per device overrides - service can be reached by only selected devices using this method |
|
482 @publishedAll |
|
483 @released |
|
484 */ |
|
485 { |
|
486 iSecurityRequirements.SetDenied(aPreference); |
|
487 } |
|
488 |
|
489 EXPORT_C TInt TBTServiceSecurity::SetPasskeyMinLength(TUint aPasskeyMinLength) |
|
490 /** |
|
491 Sets the minimum of passkey length for connection. |
|
492 |
|
493 @param aPasskeyMinLength. if aPreference = 0, no minimal length requirement. |
|
494 According to BT spec aPasskeyMinLength <= 16 |
|
495 @publishedAll |
|
496 @released |
|
497 */ |
|
498 { |
|
499 return iSecurityRequirements.SetPasskeyMinLength(aPasskeyMinLength); |
|
500 } |
|
501 |
|
502 /** |
|
503 Sets the level of authentication needed for any connections to this service. |
|
504 |
|
505 Authentication involves the comparison of a stored link key. If no link key |
|
506 has been generated and stored or one has been stored but is of an insufficient |
|
507 level of authentication then pairing will be performed. |
|
508 |
|
509 For Bluetooth v2.0 and earlier pairing involves the user entering the same pin code |
|
510 for both devices involved in the connection to this service. |
|
511 |
|
512 For Bluetooth v2.1 and onward pairing can be performed in one of four ways. Some of which |
|
513 involve the user of the Symbian OS device, some of which do not. The pairing performed |
|
514 is dependant on a number of factors including the input and output capabilities of the devices |
|
515 and the level of authentication (Man-in-the-Middle protection) required. |
|
516 |
|
517 If authentication fails, or succeeds but with an insufficient level of Man-in-the-Middle |
|
518 protection, the connection will not be permitted. |
|
519 |
|
520 @param aPreference The level of Man-in-the-Middle protection required for authentication. |
|
521 @publishedAll |
|
522 @released |
|
523 */ |
|
524 EXPORT_C void TBTServiceSecurity::SetAuthentication(TBluetoothMitmProtection aPreference) |
|
525 { |
|
526 iSecurityRequirements.SetAuthentication(aPreference); |
|
527 } |
|
528 |
|
529 /** |
|
530 Getter - return the level of Man-in-the-middle protection required this service. |
|
531 |
|
532 @return The level of Man-in-the-Middle protection required for authentication. |
|
533 @publishedAll |
|
534 @released |
|
535 */ |
|
536 EXPORT_C TBluetoothMitmProtection TBTServiceSecurity::MitmProtection() const |
|
537 { |
|
538 return iSecurityRequirements.MitmProtection(); |
|
539 } |
|
540 |
|
541 EXPORT_C TBool TBTServiceSecurity::AuthorisationRequired() const |
|
542 /** |
|
543 Getter - return whether authorisation is required for this service |
|
544 |
|
545 This function is only appropriate for when the Bluetooth v2.0 and earlier |
|
546 authentication specification function is used. Once migrated to the new MITM level |
|
547 setting this function will not return a useful result, the MitmProtection function |
|
548 should be used instead. |
|
549 |
|
550 @see TBTServiceSecurity::MitmProtection |
|
551 |
|
552 @return EAuthorise if authorisation is required, zero otherwise |
|
553 @publishedAll |
|
554 @released |
|
555 */ |
|
556 { |
|
557 return iSecurityRequirements.AuthorisationRequired(); |
|
558 } |
|
559 |
|
560 EXPORT_C TBool TBTServiceSecurity::EncryptionRequired() const |
|
561 /** |
|
562 Getter - return whether encryption is required for this service. |
|
563 @return EEncrypt if encryption is required, zero otherwise |
|
564 @publishedAll |
|
565 @released |
|
566 */ |
|
567 { |
|
568 return iSecurityRequirements.EncryptionRequired(); |
|
569 } |
|
570 |
|
571 EXPORT_C TBool TBTServiceSecurity::AuthenticationRequired() const |
|
572 /** |
|
573 Getter - return whether authentication is required for this service. |
|
574 @return EAuthenticate if authentication is required, zero otherwise |
|
575 @publishedAll |
|
576 @deprecated The TBTServiceSecurity::MitmProtection function should |
|
577 be used instead. |
|
578 */ |
|
579 { |
|
580 return iSecurityRequirements.AuthenticationRequired(); |
|
581 } |
|
582 |
|
583 EXPORT_C TBool TBTServiceSecurity::Denied() const |
|
584 /** |
|
585 Getter - return whether denied for this service. |
|
586 @return EDenied if denied, zero otherwise |
|
587 @publishedAll |
|
588 @released |
|
589 */ |
|
590 { |
|
591 return iSecurityRequirements.Denied(); |
|
592 } |
|
593 |
|
594 EXPORT_C TUint TBTServiceSecurity::PasskeyMinLength() const |
|
595 /** |
|
596 Getter - return minimal passkey length requirement |
|
597 @return 0 - no passkey length requirement. 1..16 |
|
598 @publishedAll |
|
599 @released |
|
600 */ |
|
601 { |
|
602 return iSecurityRequirements.PasskeyMinLength(); |
|
603 } |
|
604 |
|
605 EXPORT_C TUid TBTServiceSecurity::Uid() const |
|
606 /** |
|
607 Getter - return Uid for this service. |
|
608 @return Uid |
|
609 @publishedAll |
|
610 @released |
|
611 */ |
|
612 { |
|
613 return iUid; |
|
614 } |
|
615 |
|
616 // |
|
617 |
|
618 EXPORT_C TBTAccessRequirements::TBTAccessRequirements() |
|
619 /** Constructor |
|
620 */ |
|
621 { |
|
622 iRequirements = 0; |
|
623 iPasskeyMinLength = 0; |
|
624 } |
|
625 |
|
626 EXPORT_C void TBTAccessRequirements::SetAuthentication(TBool aPreference) |
|
627 /** Sets the authentication requirement of this class. |
|
628 @param aPreference If true authentification is added to the requirements. |
|
629 @deprecated The TBTAccessRequirements::SetAuthentication(TBluetoothMitmProtection) |
|
630 function should be used instead. |
|
631 */ |
|
632 { |
|
633 if (aPreference) |
|
634 iRequirements |= EAuthenticate; |
|
635 else |
|
636 iRequirements &= ~EAuthenticate; |
|
637 } |
|
638 |
|
639 EXPORT_C void TBTAccessRequirements::SetAuthorisation(TBool aPreference) |
|
640 /** Sets the authorisation requirement of this class. |
|
641 @param aPreference If true authorisation is added to the requirements. |
|
642 */ |
|
643 { |
|
644 if (aPreference) |
|
645 iRequirements |= EAuthorise; |
|
646 else |
|
647 iRequirements &= ~EAuthorise; |
|
648 } |
|
649 |
|
650 EXPORT_C void TBTAccessRequirements::SetEncryption(TBool aPreference) |
|
651 /** Sets the encryption requirement of this class. |
|
652 @param aPreference If true encryption is added to the requirements. |
|
653 */ |
|
654 { |
|
655 if (aPreference) |
|
656 iRequirements |= EEncrypt; |
|
657 else |
|
658 iRequirements &= ~EEncrypt; |
|
659 } |
|
660 |
|
661 EXPORT_C void TBTAccessRequirements::SetDenied(TBool aPreference) |
|
662 /** Sets the denied requirement of this class. |
|
663 If this is set no connects will be accepted unless specified in the |
|
664 device overrides. |
|
665 @param aPreference If true the denied attribute is added to the requirements. |
|
666 */ |
|
667 { |
|
668 if (aPreference) |
|
669 iRequirements |= EDenied; |
|
670 else |
|
671 iRequirements &= ~EDenied; |
|
672 } |
|
673 |
|
674 EXPORT_C TInt TBTAccessRequirements::SetPasskeyMinLength(TUint aPasskeyMinLength) |
|
675 /** Sets the minimal length requrement for passkey |
|
676 If it is between 1..16 SecurityManager will check the length of passkey |
|
677 @param aPasskeyMinLength If this is set to 0, means no minimal length requirement. |
|
678 1..16 is the valid range. |
|
679 >16 Not valid, we set to 0 |
|
680 */ |
|
681 { |
|
682 if (1<=aPasskeyMinLength && aPasskeyMinLength<=KHCIPINCodeSize) |
|
683 { |
|
684 iPasskeyMinLength = aPasskeyMinLength; |
|
685 return KErrNone; |
|
686 } |
|
687 else |
|
688 { |
|
689 iPasskeyMinLength = 0; |
|
690 return KErrOverflow; |
|
691 } |
|
692 } |
|
693 |
|
694 /** Sets the Man-in-the-Middle requirements for authentication of this class. |
|
695 @param aPreference The level of Man-in-the-Middle protection required for authentication. |
|
696 */ |
|
697 EXPORT_C void TBTAccessRequirements::SetAuthentication(TBluetoothMitmProtection aPreference) |
|
698 { |
|
699 iRequirements &= ~EMitm; |
|
700 switch(aPreference) |
|
701 { |
|
702 case EMitmNotRequired: |
|
703 iRequirements |= EAccessRequirementsMitmNotRequired; |
|
704 break; |
|
705 case EMitmDesired: |
|
706 iRequirements |= EAccessRequirementsMitmDesired; |
|
707 break; |
|
708 case EMitmRequired: |
|
709 iRequirements |= EAccessRequirementsMitmRequired; |
|
710 break; |
|
711 } |
|
712 } |
|
713 |
|
714 EXPORT_C TBool TBTAccessRequirements::AuthenticationRequired() const |
|
715 /** Getter for the authentification attribute. |
|
716 @return EAuthenticate if authentification is a required attribute, zero otherwise. |
|
717 @deprecated The TBTAccessRequirements::MitmProtection function should |
|
718 be used instead. |
|
719 */ |
|
720 { |
|
721 // We derive whether authentication will be requested based on the computed |
|
722 // MITM requirements. |
|
723 switch(MitmProtection()) |
|
724 { |
|
725 case EMitmNotRequired: |
|
726 break; |
|
727 case EMitmDesired: |
|
728 // fall-through |
|
729 case EMitmRequired: |
|
730 return EAuthenticate; |
|
731 } |
|
732 return EFalse; |
|
733 } |
|
734 |
|
735 EXPORT_C TBool TBTAccessRequirements::AuthorisationRequired() const |
|
736 /** Getter for the authorisation attribute. |
|
737 @return EAuthorise if authorisation is a required attribute, zero otherwise. |
|
738 */ |
|
739 { |
|
740 return (iRequirements & EAuthorise); |
|
741 } |
|
742 |
|
743 EXPORT_C TBool TBTAccessRequirements::EncryptionRequired() const |
|
744 /** Getter for the encryption attribute. |
|
745 @return EEncrypt if encryption is a required attribute, zero otherwise. |
|
746 */ |
|
747 { |
|
748 return (iRequirements & EEncrypt); |
|
749 } |
|
750 |
|
751 EXPORT_C TBool TBTAccessRequirements::Denied() const |
|
752 /** Getter for the denied attribute. |
|
753 @return EDenied if denied is a required attribute, zero otherwise. |
|
754 */ |
|
755 { |
|
756 return (iRequirements & EDenied); |
|
757 } |
|
758 |
|
759 EXPORT_C TUint TBTAccessRequirements::PasskeyMinLength() const |
|
760 /** Getter for the minimal passkey length |
|
761 @return 1..16 means set. 0 means - no requirement for minimal passkey length |
|
762 */ |
|
763 { |
|
764 return iPasskeyMinLength; |
|
765 } |
|
766 |
|
767 EXPORT_C TBool TBTAccessRequirements::operator==(const TBTAccessRequirements& aRequirements) const |
|
768 /** Equals operator. |
|
769 @param aRequirements The instance being compared. |
|
770 @return True if the requirements specified in this instance match those of the instance passed in the argument. |
|
771 */ |
|
772 { |
|
773 return (iRequirements == aRequirements.iRequirements && iPasskeyMinLength == aRequirements.iPasskeyMinLength ); |
|
774 } |
|
775 |
|
776 /** Getter for the Man-in-the-Middle protection requirements. |
|
777 @return The level of Man-in-the-Middle protection required for authentication. |
|
778 */ |
|
779 EXPORT_C TBluetoothMitmProtection TBTAccessRequirements::MitmProtection() const |
|
780 { |
|
781 TBluetoothMitmProtection ret = EMitmNotRequired; |
|
782 switch (iRequirements & EMitm) |
|
783 { |
|
784 case EAccessRequirementsMitmUndefined: |
|
785 { |
|
786 ret = EMitmNotRequired; |
|
787 if(iRequirements & EAuthenticate) |
|
788 { |
|
789 // This constant represents at what point the minimum pin code length |
|
790 // requirements indicates a serious desire for strong protection. |
|
791 const TInt KStrongPinLengthLengthThreshold = KHCIPINCodeSize; |
|
792 if(PasskeyMinLength() >= KStrongPinLengthLengthThreshold) |
|
793 { |
|
794 ret = EMitmRequired; |
|
795 } |
|
796 else |
|
797 { |
|
798 ret = EMitmDesired; |
|
799 } |
|
800 } |
|
801 break; |
|
802 } |
|
803 case EAccessRequirementsMitmNotRequired: |
|
804 { |
|
805 ret = EMitmNotRequired; |
|
806 break; |
|
807 } |
|
808 case EAccessRequirementsMitmDesired: |
|
809 { |
|
810 ret = EMitmDesired; |
|
811 break; |
|
812 } |
|
813 case EAccessRequirementsMitmRequired: |
|
814 { |
|
815 ret = EMitmRequired; |
|
816 break; |
|
817 } |
|
818 } |
|
819 return ret; |
|
820 } |