|
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 #include <btdevice.h> |
|
17 #include <utf.h> |
|
18 |
|
19 inline void __BTDEBUGGER() |
|
20 // needed to call __DEBUGGER inside an __ASSERT |
|
21 { |
|
22 __DEBUGGER() |
|
23 } |
|
24 |
|
25 #define __BT_BITMASK__(length) ((1 << (length)) - 1) |
|
26 |
|
27 enum TBTDeviceClassV1 |
|
28 { |
|
29 EMajorServiceLength = 11, |
|
30 EMajorDeviceLength = 5, |
|
31 EMinorDeviceLength = 6, |
|
32 EFormatTypeLength = 2, |
|
33 EMajorServiceMask = __BT_BITMASK__(EMajorServiceLength), |
|
34 EMajorDeviceMask = __BT_BITMASK__(EMajorDeviceLength), |
|
35 EMinorDeviceMask = __BT_BITMASK__(EMinorDeviceLength), |
|
36 EFormatTypeMask = __BT_BITMASK__(EFormatTypeLength) |
|
37 }; |
|
38 /** Push an object onto the cleanupstack. |
|
39 |
|
40 @param aBTDeviceArray "The CBTDeviceArray object to be pushed onto the cleanupstack. |
|
41 @leave This method will leave if an error occurs. |
|
42 **/ |
|
43 EXPORT_C void BTDeviceArrayCleanupStack::PushL(CBTDeviceArray* aBTDeviceArray) |
|
44 { |
|
45 CleanupStack::PushL(TCleanupItem(&BTDeviceArrayCleanupStack::ResetAndDestroy, (TAny*)aBTDeviceArray)); |
|
46 } |
|
47 |
|
48 /** Method used by the cleanup stack to reset and destroy the array. |
|
49 |
|
50 @param aBTDeviceArray "The array to be reset and destroyed" |
|
51 **/ |
|
52 void BTDeviceArrayCleanupStack::ResetAndDestroy(TAny* aBTDeviceArray) |
|
53 { |
|
54 CBTDeviceArray* array = static_cast<CBTDeviceArray*>(aBTDeviceArray); |
|
55 array->ResetAndDestroy(); |
|
56 delete array; |
|
57 } |
|
58 |
|
59 /** |
|
60 Convert a narrow TBTDeviceName8 to a wide TBTDeviceName. Uses utf8->unicode conversion. |
|
61 @param aName "The name to be converted" |
|
62 @return "The converted name" |
|
63 @leave "This method will leave if an error occurs with the utf8->unicode conversion" |
|
64 **/ |
|
65 EXPORT_C TBTDeviceName BTDeviceNameConverter::ToUnicodeL(const TBTDeviceName8& aName) |
|
66 |
|
67 { |
|
68 TBTDeviceName ret; |
|
69 User::LeaveIfError(CnvUtfConverter::ConvertToUnicodeFromUtf8(ret, aName)); |
|
70 return ret; |
|
71 } |
|
72 |
|
73 /** |
|
74 Convert a wide TBTDeviceName to a narrow TBTDeviceName8. Uses unicode->utf8 conversion. |
|
75 @param aName "The name to be converted" |
|
76 @return "The converted name" |
|
77 @leave "This method will leave if an error occurs with the unicode->utf8 conversion" |
|
78 **/ |
|
79 EXPORT_C TBTDeviceName8 BTDeviceNameConverter::ToUTF8L(const TBTDeviceName& aName) |
|
80 { |
|
81 TBTDeviceName8 ret; |
|
82 User::LeaveIfError(CnvUtfConverter::ConvertFromUnicodeToUtf8(ret, aName)); |
|
83 return ret; |
|
84 } |
|
85 |
|
86 /** |
|
87 Constructor. |
|
88 Initialises the device class to 0. |
|
89 **/ |
|
90 EXPORT_C TBTDeviceClass::TBTDeviceClass() : |
|
91 iDeviceClass(0) |
|
92 { |
|
93 } |
|
94 |
|
95 /** |
|
96 Constructor |
|
97 @param aDeviceClass The initial device class |
|
98 **/ |
|
99 EXPORT_C TBTDeviceClass::TBTDeviceClass(TUint32 aDeviceClass) : |
|
100 iDeviceClass(aDeviceClass) |
|
101 { |
|
102 } |
|
103 |
|
104 /** |
|
105 Constructor taking separate fields for combination into device class |
|
106 |
|
107 Construct a Class of Device using format #1 as per the |
|
108 <a href="https://www.bluetooth.org/foundry/assignnumb/document/baseband">baseband |
|
109 assigned numbers</a>. |
|
110 |
|
111 Note that this is a 24-bit field which we store in a 32-bit integer. |
|
112 @param aMajorServiceClass The major service class for the device. |
|
113 @param aMajorDeviceClass The major device class. |
|
114 @param aMinorDevice The minor device class. |
|
115 */ |
|
116 EXPORT_C TBTDeviceClass::TBTDeviceClass(TUint16 aMajorServiceClass, TUint8 aMajorDeviceClass, |
|
117 TUint8 aMinorDeviceClass) : |
|
118 iDeviceClass(0) |
|
119 { |
|
120 iDeviceClass = (aMajorServiceClass & EMajorServiceMask); // [00000000]0000000000000xxxxxxxxxxx |
|
121 iDeviceClass <<= EMajorDeviceLength; // [00000000]00000000xxxxxxxxxxx00000 |
|
122 |
|
123 iDeviceClass |= (aMajorDeviceClass & EMajorDeviceMask); // [00000000]00000000xxxxxxxxxxxyyyyy |
|
124 iDeviceClass <<= EMinorDeviceLength; // [00000000]00xxxxxxxxxxxyyyyy000000 |
|
125 |
|
126 iDeviceClass |= (aMinorDeviceClass & EMinorDeviceMask);// [00000000]00xxxxxxxxxxxyyyyyzzzzzz |
|
127 iDeviceClass <<= EFormatTypeLength; // [00000000]xxxxxxxxxxxyyyyyzzzzzz00 |
|
128 } |
|
129 |
|
130 /** |
|
131 Getter for major service class |
|
132 @return The MajorServerClass |
|
133 |
|
134 Currently we only support CoD format #1. |
|
135 */ |
|
136 EXPORT_C TUint16 TBTDeviceClass::MajorServiceClass() const |
|
137 { |
|
138 if ((iDeviceClass & EFormatTypeMask) != 0x00) |
|
139 { |
|
140 return 0; |
|
141 } |
|
142 |
|
143 TUint32 servClass = iDeviceClass >> (EMajorDeviceLength + |
|
144 EMinorDeviceLength + |
|
145 EFormatTypeLength); |
|
146 |
|
147 return static_cast<TUint16>(servClass & EMajorServiceMask); |
|
148 } |
|
149 |
|
150 /** |
|
151 Getter for major device class |
|
152 @return The MajorDeviceClass |
|
153 |
|
154 Currently we only support CoD format #1. |
|
155 */ |
|
156 EXPORT_C TUint8 TBTDeviceClass::MajorDeviceClass() const |
|
157 { |
|
158 if ((iDeviceClass & EFormatTypeMask) != 0x00) |
|
159 { |
|
160 return 0; |
|
161 } |
|
162 |
|
163 TUint32 majClass = iDeviceClass >> (EMinorDeviceLength + EFormatTypeLength); |
|
164 |
|
165 return static_cast<TUint8>(majClass & EMajorDeviceMask); |
|
166 } |
|
167 |
|
168 /** |
|
169 Getter for minor device class |
|
170 @return The MinorDeviceClass |
|
171 |
|
172 Currently we only support CoD format #1. |
|
173 */ |
|
174 EXPORT_C TUint8 TBTDeviceClass::MinorDeviceClass() const |
|
175 { |
|
176 if ((iDeviceClass & EFormatTypeMask) != 0x00) |
|
177 { |
|
178 return 0; |
|
179 } |
|
180 |
|
181 TUint32 minClass = iDeviceClass >> (EFormatTypeLength); |
|
182 |
|
183 return static_cast<TUint8>(minClass & EMinorDeviceMask); |
|
184 } |
|
185 |
|
186 /** |
|
187 Getter for whole device class |
|
188 @return The DeviceClass |
|
189 */ |
|
190 EXPORT_C TUint32 TBTDeviceClass::DeviceClass() const |
|
191 { |
|
192 return iDeviceClass; |
|
193 } |
|
194 |
|
195 /** |
|
196 Comparison operator |
|
197 @param aDeviceClass the instance with which this is compared |
|
198 @return ETrue if device classes are equal, otherwise false |
|
199 */ |
|
200 EXPORT_C TBool TBTDeviceClass::operator==(const TBTDeviceClass& aDeviceClass) const |
|
201 { |
|
202 TBool retval = (iDeviceClass==aDeviceClass.DeviceClass()); |
|
203 return retval; |
|
204 } |
|
205 |
|
206 /** |
|
207 Assignment operator |
|
208 @param aDeviceClass the instance from which this is assigned |
|
209 @return this Device Class |
|
210 */ |
|
211 EXPORT_C TBTDeviceClass& TBTDeviceClass::operator=(const TBTDeviceClass& aDeviceClass) |
|
212 { |
|
213 if (this != &aDeviceClass) |
|
214 { |
|
215 iDeviceClass = aDeviceClass.DeviceClass(); |
|
216 } |
|
217 return *this; |
|
218 } |
|
219 |
|
220 /** |
|
221 Extenalize this object to a stream. |
|
222 @param aStream The stream object to which the class data will be written. |
|
223 @leave This method will leave if an error occurs. |
|
224 */ |
|
225 EXPORT_C void TBTDeviceClass::ExternalizeL(RWriteStream& aStream) const |
|
226 { |
|
227 aStream.WriteUint32L(KStreamVersion); |
|
228 aStream.WriteUint32L(iDeviceClass); |
|
229 } |
|
230 |
|
231 /** |
|
232 Internalize this object from a stream. |
|
233 @param aStream The stream object containing the data with which to internalize this object. |
|
234 @leave This method will leave if an error occurs. |
|
235 */ |
|
236 EXPORT_C void TBTDeviceClass::InternalizeL(RReadStream& aStream) |
|
237 { |
|
238 TUint32 version = aStream.ReadUint32L(); |
|
239 static_cast<void>(version); // Currently only one valid version. |
|
240 iDeviceClass = aStream.ReadUint32L(); |
|
241 } |
|
242 |
|
243 |
|
244 //==================================================================== |
|
245 |
|
246 /** |
|
247 Constructor. |
|
248 */ |
|
249 EXPORT_C TBTNamelessDevice::TBTNamelessDevice() |
|
250 : iSetMask(0) |
|
251 , iLinkKeyType(ELinkKeyCombination) |
|
252 { |
|
253 } |
|
254 |
|
255 /** |
|
256 Constructor. Use NewL() or NewLC() to create an object of this type instead of this constructor. |
|
257 */ |
|
258 CBTDevice::CBTDevice() |
|
259 { |
|
260 } |
|
261 |
|
262 /** |
|
263 Two-phase default constructor |
|
264 Create an empty device. The object will be placed on the cleanupstack and must be removed by the caller. |
|
265 @return CBTDevice |
|
266 @leave This method will leave if an error occurs. |
|
267 */ |
|
268 EXPORT_C CBTDevice* CBTDevice::NewLC() |
|
269 { |
|
270 CBTDevice* self = new(ELeave) CBTDevice(); |
|
271 CleanupStack::PushL(self); |
|
272 self->ConstructL(); |
|
273 return self; |
|
274 } |
|
275 |
|
276 /** |
|
277 Two-phase default constructor |
|
278 Create an empty device. |
|
279 @return The new CBTDevice object. |
|
280 @leave This method will leave if an error occurs. |
|
281 */ |
|
282 EXPORT_C CBTDevice* CBTDevice::NewL() |
|
283 { |
|
284 CBTDevice* self = CBTDevice::NewLC(); |
|
285 CleanupStack::Pop(); //self |
|
286 return self; |
|
287 } |
|
288 |
|
289 /** |
|
290 Two-phase constructor |
|
291 @param aBDAddr the address of the device to which this class refers |
|
292 @return The new CBTDevice object. The object will be left on the cleanupstack. |
|
293 @leave This method will leave if an error occurs. |
|
294 */ |
|
295 EXPORT_C CBTDevice* CBTDevice::NewLC(const TBTDevAddr& aBDAddr) |
|
296 { |
|
297 CBTDevice* self = new(ELeave) CBTDevice; |
|
298 CleanupStack::PushL(self); |
|
299 self->ConstructL(aBDAddr); |
|
300 return self; |
|
301 } |
|
302 |
|
303 /** |
|
304 Two-phase constructor |
|
305 Create a device and set its address. |
|
306 @param aBDAddr the address of the device to which this class refers |
|
307 @return The new CBTDevice object. |
|
308 @leave This method will leave if an error occurs. |
|
309 */ |
|
310 EXPORT_C CBTDevice* CBTDevice::NewL(const TBTDevAddr& aBDAddr) |
|
311 { |
|
312 CBTDevice* self = CBTDevice::NewLC(aBDAddr); |
|
313 CleanupStack::Pop(); //self |
|
314 return self; |
|
315 } |
|
316 |
|
317 /** |
|
318 Two-phase copy constructor |
|
319 Create a device based on the smaller nameless device |
|
320 @param aNamelessDevice the device to copy |
|
321 @return this Device |
|
322 @leave This method will leave if an error occurs. |
|
323 */ |
|
324 EXPORT_C CBTDevice* CBTDevice::NewL(const TBTNamelessDevice& aNamelessDevice) |
|
325 { |
|
326 CBTDevice* self = CBTDevice::NewLC(aNamelessDevice); |
|
327 CleanupStack::Pop(); //self |
|
328 return self; |
|
329 } |
|
330 |
|
331 /** |
|
332 Two-phase copy constructor |
|
333 Create a device based on the smaller nameless device |
|
334 @param aNamelessDevice the device to copy |
|
335 @return this Device, placed on the cleanupstack. |
|
336 @leave This method will leave if an error occurs. |
|
337 */ |
|
338 EXPORT_C CBTDevice* CBTDevice::NewLC(const TBTNamelessDevice& aNamelessDevice) |
|
339 { |
|
340 CBTDevice* self = new(ELeave) CBTDevice(); |
|
341 CleanupStack::PushL(self); |
|
342 self->ConstructL(aNamelessDevice); |
|
343 return self; |
|
344 } |
|
345 |
|
346 void CBTDevice::ConstructL() |
|
347 { |
|
348 CommonConstructL(); |
|
349 } |
|
350 |
|
351 void CBTDevice::ConstructL(const TBTDevAddr& aDevAddr) |
|
352 { |
|
353 CommonConstructL(); |
|
354 iDevice.SetAddress(aDevAddr); |
|
355 } |
|
356 |
|
357 void CBTDevice::ConstructL(const TBTNamelessDevice& aNamelessDevice) |
|
358 { |
|
359 CommonConstructL(); |
|
360 iDevice.Update(aNamelessDevice); |
|
361 } |
|
362 |
|
363 void CBTDevice::CommonConstructL() |
|
364 { |
|
365 } |
|
366 |
|
367 |
|
368 /** |
|
369 Destructor. |
|
370 */ |
|
371 EXPORT_C CBTDevice::~CBTDevice() |
|
372 { |
|
373 delete iDeviceName; |
|
374 delete iFriendlyName; |
|
375 } |
|
376 |
|
377 /** |
|
378 Copies the contents of this into a new CBTDevice object. |
|
379 @leave This method will leave if an error occurs. |
|
380 */ |
|
381 EXPORT_C CBTDevice* CBTDevice::CopyL() const |
|
382 { |
|
383 CBTDevice* newDevice = CBTDevice::NewLC(); |
|
384 |
|
385 if (IsValidBDAddr()) |
|
386 newDevice->SetDeviceAddress(BDAddr()); |
|
387 if (IsValidDeviceName()) |
|
388 newDevice->SetDeviceNameL(DeviceName()); |
|
389 if (IsValidFriendlyName()) |
|
390 newDevice->SetFriendlyNameL(FriendlyName()); |
|
391 if (IsValidDeviceClass()) |
|
392 newDevice->SetDeviceClass(DeviceClass()); |
|
393 if(IsValidLinkKey()) |
|
394 newDevice->SetLinkKey(LinkKey(),LinkKeyType()); |
|
395 if (IsValidGlobalSecurity()) |
|
396 newDevice->SetGlobalSecurity(GlobalSecurity()); |
|
397 if (iDevice.IsValidPageScanRepMode()) |
|
398 newDevice->AsNamelessDevice().SetPageScanRepMode(iDevice.PageScanRepMode()); |
|
399 if (iDevice.IsValidPageScanMode()) |
|
400 newDevice->AsNamelessDevice().SetPageScanMode(iDevice.PageScanMode()); |
|
401 if (iDevice.IsValidPageScanPeriodMode()) |
|
402 newDevice->AsNamelessDevice().SetPageScanPeriodMode(iDevice.PageScanPeriodMode()); |
|
403 if (iDevice.IsValidClockOffset()) |
|
404 newDevice->AsNamelessDevice().SetClockOffset(iDevice.ClockOffset()); |
|
405 if (IsValidSeen()) |
|
406 newDevice->SetSeen(Seen()); |
|
407 if (IsValidUsed()) |
|
408 newDevice->SetUsed(Used()); |
|
409 if (IsValidPassKey()) |
|
410 newDevice->SetPassKey(PassKey()); |
|
411 if (IsValidPaired()) |
|
412 { |
|
413 if (!IsPaired()) |
|
414 { |
|
415 newDevice->SetPaired(EFalse); |
|
416 } |
|
417 else if (!IsValidLinkKey()) |
|
418 { |
|
419 newDevice->SetPaired(LinkKeyType()); // If link key is valid then "paired" status is already set. |
|
420 } |
|
421 } |
|
422 if (IsValidUiCookie()) |
|
423 newDevice->SetUiCookie(UiCookie()); |
|
424 |
|
425 CleanupStack::Pop(newDevice); |
|
426 |
|
427 return newDevice; |
|
428 } |
|
429 |
|
430 /** |
|
431 Update 'this' with valid details of aDevice, leaving already present settings |
|
432 @param aDevice The device details to be used to update this device. |
|
433 @publishedPartner |
|
434 @released |
|
435 */ |
|
436 EXPORT_C void TBTNamelessDevice::Update(const TBTNamelessDevice& aDevice) |
|
437 { |
|
438 if (aDevice.IsValidAddress()) |
|
439 SetAddress(aDevice.Address()); |
|
440 |
|
441 if (aDevice.IsValidDeviceClass()) |
|
442 SetDeviceClass(aDevice.DeviceClass()); |
|
443 |
|
444 if (aDevice.IsValidLinkKey()) |
|
445 SetLinkKey(aDevice.LinkKey(), aDevice.LinkKeyType()); |
|
446 |
|
447 if (aDevice.IsValidGlobalSecurity()) |
|
448 SetGlobalSecurity(aDevice.GlobalSecurity()); |
|
449 |
|
450 if (aDevice.IsValidPageScanRepMode()) |
|
451 SetPageScanRepMode(aDevice.PageScanRepMode()); |
|
452 |
|
453 if (aDevice.IsValidPageScanMode()) |
|
454 SetPageScanMode(aDevice.PageScanMode()); |
|
455 |
|
456 if (aDevice.IsValidPageScanPeriodMode()) |
|
457 SetPageScanPeriodMode(aDevice.PageScanPeriodMode()); |
|
458 |
|
459 if (aDevice.IsValidClockOffset()) |
|
460 SetClockOffset(aDevice.ClockOffset()); |
|
461 |
|
462 if (aDevice.IsValidSeen()) |
|
463 SetSeen(aDevice.Seen()); |
|
464 |
|
465 if (aDevice.IsValidUsed()) |
|
466 SetUsed(aDevice.Used()); |
|
467 |
|
468 if (aDevice.IsValidPassKey()) |
|
469 SetPassKey(aDevice.PassKey()); |
|
470 |
|
471 if(aDevice.IsValidPaired()) |
|
472 { |
|
473 if (!aDevice.IsPaired()) |
|
474 { |
|
475 SetPaired(EFalse); |
|
476 } |
|
477 else if (!aDevice.IsValidLinkKey()) |
|
478 { |
|
479 SetPaired(aDevice.LinkKeyType()); // If link key is valid then "paired" status is already set. |
|
480 } |
|
481 } |
|
482 |
|
483 if(aDevice.IsValidUiCookie()) |
|
484 SetUiCookie(aDevice.UiCookie()); |
|
485 |
|
486 } |
|
487 |
|
488 |
|
489 /** |
|
490 Compare the attributes of aDevice to *this and return a bitfield of matching attributes. |
|
491 @see TBTDeviceSet |
|
492 @publishedPartner |
|
493 @released |
|
494 @return bit field indicating what attributes of aDevice are equal to self |
|
495 */ |
|
496 EXPORT_C TUint TBTNamelessDevice::CompareTo(const TBTNamelessDevice& aDevice) const |
|
497 { |
|
498 TUint retval = EAllNamelessProperties; |
|
499 |
|
500 //Check that data is valid before comparing values: |
|
501 //if both valid, values must equate |
|
502 //if both invalid, treat as equal regardless of values |
|
503 if (!((IsValidAddress() && aDevice.IsValidAddress() && (Address()==aDevice.Address())) |
|
504 || (!IsValidAddress() && !aDevice.IsValidAddress()))) |
|
505 { |
|
506 retval &= ~EAddress; |
|
507 } |
|
508 if (!((IsValidDeviceClass() && aDevice.IsValidDeviceClass() && (DeviceClass()==aDevice.DeviceClass())) |
|
509 || (!IsValidDeviceClass() && !aDevice.IsValidDeviceClass()))) |
|
510 { |
|
511 retval &= ~EDeviceClass; |
|
512 } |
|
513 if (!((IsValidLinkKey() && aDevice.IsValidLinkKey() && (LinkKey()==aDevice.LinkKey()) && (LinkKeyType() == aDevice.LinkKeyType())) |
|
514 || (!IsValidLinkKey() && !aDevice.IsValidLinkKey()))) |
|
515 { |
|
516 retval &= ~ELinkKey; |
|
517 } |
|
518 |
|
519 if (!((IsValidPageScanRepMode() && aDevice.IsValidPageScanRepMode() |
|
520 && (PageScanRepMode()==aDevice.PageScanRepMode())) |
|
521 || (!IsValidPageScanRepMode() && !aDevice.IsValidPageScanRepMode()))) |
|
522 { |
|
523 retval &= ~EPageScanRepMode; |
|
524 } |
|
525 |
|
526 if (!((IsValidPageScanMode() && aDevice.IsValidPageScanMode() |
|
527 && (PageScanMode() == aDevice.PageScanMode())) |
|
528 || (!IsValidPageScanMode() && !aDevice.IsValidPageScanMode()))) |
|
529 { |
|
530 retval &= ~EPageScanMode; |
|
531 } |
|
532 |
|
533 if (!((IsValidPageScanPeriodMode() && aDevice.IsValidPageScanPeriodMode() |
|
534 && (PageScanPeriodMode() == aDevice.PageScanPeriodMode())) |
|
535 || (!IsValidPageScanPeriodMode() && !aDevice.IsValidPageScanPeriodMode()))) |
|
536 { |
|
537 retval &= ~EPageScanPeriodMode; |
|
538 } |
|
539 |
|
540 if (!((IsValidClockOffset() && aDevice.IsValidClockOffset() |
|
541 && (ClockOffset() == aDevice.ClockOffset())) |
|
542 || (!IsValidClockOffset() && !aDevice.IsValidClockOffset()))) |
|
543 { |
|
544 retval &= ~EClockOffset; |
|
545 } |
|
546 |
|
547 if (!((IsValidSeen() && aDevice.IsValidSeen() |
|
548 && (static_cast<TTime>(Seen()) == static_cast<TTime>(aDevice.Seen()))) |
|
549 ||(!IsValidSeen() && !aDevice.IsValidSeen()))) |
|
550 { |
|
551 retval &= ~ESeen; |
|
552 } |
|
553 |
|
554 if (!((IsValidUsed() && aDevice.IsValidUsed() |
|
555 && (static_cast<TTime>(Used()) == static_cast<TTime>(aDevice.Used()))) |
|
556 ||(!IsValidUsed() && !aDevice.IsValidUsed()))) |
|
557 { |
|
558 retval &= ~EUsed; |
|
559 } |
|
560 |
|
561 if (!((IsValidGlobalSecurity() && aDevice.IsValidGlobalSecurity() |
|
562 && (GlobalSecurity() == aDevice.GlobalSecurity())) |
|
563 ||(!IsValidGlobalSecurity() && !aDevice.IsValidGlobalSecurity()))) |
|
564 { |
|
565 retval &= ~EGlobalSecurity; |
|
566 } |
|
567 |
|
568 if (!((IsValidPassKey() && aDevice.IsValidPassKey() && (PassKey()() == aDevice.PassKey()())) |
|
569 || (!IsValidPassKey() && !aDevice.IsValidPassKey()))) |
|
570 { |
|
571 retval &= ~EPassKey; |
|
572 } |
|
573 |
|
574 if(!((IsValidPaired() && aDevice.IsValidPaired() && (IsPaired() == aDevice.IsPaired()) |
|
575 && (!IsPaired() || (LinkKeyType() == aDevice.LinkKeyType()))) |
|
576 ||(!IsValidPaired() && !aDevice.IsValidPaired()))) |
|
577 { |
|
578 // This is slightly more complex than other cases because of the way link key type |
|
579 // and "paired" are bound together. |
|
580 retval &= ~EIsPaired; |
|
581 } |
|
582 |
|
583 if (!((IsValidUiCookie() && aDevice.IsValidUiCookie() |
|
584 && (UiCookie()==aDevice.UiCookie())) |
|
585 || (!IsValidUiCookie() && !aDevice.IsValidUiCookie()))) |
|
586 { |
|
587 retval &= ~EUiCookie; |
|
588 } |
|
589 |
|
590 return retval; |
|
591 } |
|
592 |
|
593 /** |
|
594 @publishedPartner |
|
595 @released |
|
596 |
|
597 Compare aDevice with this. |
|
598 @param aDevice The device to compare with this. |
|
599 @return ETrue if they match, EFalse if not. |
|
600 */ |
|
601 EXPORT_C TBool TBTNamelessDevice::operator==(const TBTNamelessDevice& aDevice) const |
|
602 { |
|
603 return CompareTo(aDevice)==EAllNamelessProperties ? ETrue : EFalse; |
|
604 } |
|
605 |
|
606 /** |
|
607 @publishedPartner |
|
608 @released |
|
609 |
|
610 Compare aDevice with this. |
|
611 @param aDevice The device to compare with this. |
|
612 @return EFalse if they match, ETrue if not. |
|
613 */ |
|
614 EXPORT_C TBool TBTNamelessDevice::operator!=(const TBTNamelessDevice& aDevice) const |
|
615 { |
|
616 return !(*this==aDevice); |
|
617 } |
|
618 |
|
619 /** |
|
620 Compiler generated operator= is ok for this class, but ARM compiler warns |
|
621 @publishedPartner |
|
622 @released |
|
623 @param aDevice The device to copy. |
|
624 @return this Nameless Device |
|
625 */ |
|
626 EXPORT_C TBTNamelessDevice& TBTNamelessDevice::operator=(const TBTNamelessDevice& aDevice) |
|
627 { |
|
628 Update(aDevice); |
|
629 return *this; |
|
630 } |
|
631 |
|
632 /** |
|
633 Get the device address. |
|
634 @return The device address this refers to |
|
635 */ |
|
636 EXPORT_C const TBTDevAddr& TBTNamelessDevice::Address() const |
|
637 { |
|
638 return iBDAddr; |
|
639 } |
|
640 |
|
641 /** |
|
642 Returns the name of the device |
|
643 @return The device name. If the device has no name, a zero-length descriptor will be returned. |
|
644 */ |
|
645 EXPORT_C const TDesC8& CBTDevice::DeviceName() const |
|
646 { |
|
647 if (iDeviceName) |
|
648 { |
|
649 return *iDeviceName; |
|
650 } |
|
651 else |
|
652 { |
|
653 return KNullDesC8; |
|
654 } |
|
655 } |
|
656 |
|
657 /** |
|
658 Returns the friendly name of the device |
|
659 @return The friendly name. If the device has no friendly name, a zero-length descriptor will be returned. |
|
660 */ |
|
661 EXPORT_C const TDesC& CBTDevice::FriendlyName() const |
|
662 { |
|
663 if (iFriendlyName) |
|
664 { |
|
665 return *iFriendlyName; |
|
666 } |
|
667 else |
|
668 { |
|
669 return KNullDesC; |
|
670 } |
|
671 } |
|
672 |
|
673 /** |
|
674 Returns the class of the device |
|
675 @return The device class. |
|
676 */ |
|
677 EXPORT_C const TBTDeviceClass& TBTNamelessDevice::DeviceClass() const |
|
678 { |
|
679 return iDeviceClass; |
|
680 } |
|
681 |
|
682 /** |
|
683 @internalAll |
|
684 @released |
|
685 Return the link key. |
|
686 @return the link key |
|
687 */ |
|
688 EXPORT_C const TBTLinkKey& TBTNamelessDevice::LinkKey() const |
|
689 { |
|
690 return iLinkKey; |
|
691 } |
|
692 |
|
693 /** |
|
694 @publishedPartner |
|
695 @released |
|
696 Return the link key type. |
|
697 @return the link key type |
|
698 */ |
|
699 EXPORT_C TBTLinkKeyType TBTNamelessDevice::LinkKeyType() const |
|
700 { |
|
701 return iLinkKeyType; |
|
702 } |
|
703 |
|
704 |
|
705 /** |
|
706 Retrieve the global security settings. |
|
707 @return The Global security settings for all services used by this device |
|
708 */ |
|
709 EXPORT_C const TBTDeviceSecurity& TBTNamelessDevice::GlobalSecurity() const |
|
710 { |
|
711 return iGlobalSecurity; |
|
712 } |
|
713 |
|
714 /** |
|
715 @internalAll |
|
716 @released |
|
717 @return The Page Scan Repitition Mode of the device |
|
718 */ |
|
719 EXPORT_C TUint8 TBTNamelessDevice::PageScanRepMode() const |
|
720 { |
|
721 return iBasebandParams.iPageScanRepetitionMode; |
|
722 } |
|
723 |
|
724 /** |
|
725 @internalAll |
|
726 @released |
|
727 @return The Page Scan Mode of the device |
|
728 */ |
|
729 EXPORT_C TUint8 TBTNamelessDevice::PageScanMode() const |
|
730 { |
|
731 return iBasebandParams.iPageScanMode; |
|
732 } |
|
733 |
|
734 /** |
|
735 @return the Page Scan Period Mode of the device |
|
736 @internalAll |
|
737 @released |
|
738 */ |
|
739 EXPORT_C TUint8 TBTNamelessDevice::PageScanPeriodMode() const |
|
740 { |
|
741 return iBasebandParams.iPageScanPeriodMode; |
|
742 } |
|
743 |
|
744 /** |
|
745 @return the ClockOffSet of the device |
|
746 @internalAll |
|
747 @released |
|
748 */ |
|
749 EXPORT_C TUint16 TBTNamelessDevice::ClockOffset() const |
|
750 { |
|
751 return iBasebandParams.iClockOffset; |
|
752 } |
|
753 |
|
754 /** |
|
755 Return the time when this device was last seen. |
|
756 Note that this is currently not support by the bluetooth stack. |
|
757 Only the time when the device was last _used_ can is stored. |
|
758 @return TTime of when device last seen |
|
759 */ |
|
760 EXPORT_C const TTime& TBTNamelessDevice::Seen() const |
|
761 { |
|
762 return iSeen; |
|
763 } |
|
764 |
|
765 /** |
|
766 Return the time when the device was last used. |
|
767 @return TTime of when device last connected to |
|
768 */ |
|
769 EXPORT_C const TTime& TBTNamelessDevice::Used() const |
|
770 { |
|
771 return iUsed; |
|
772 } |
|
773 |
|
774 /** |
|
775 Return the PIN code. |
|
776 @return TBTPinCode |
|
777 */ |
|
778 EXPORT_C const TBTPinCode& TBTNamelessDevice::PassKey() const |
|
779 { |
|
780 return iPassKey; |
|
781 } |
|
782 |
|
783 /** |
|
784 Check whether the device is paired |
|
785 @return ETrue = Paired |
|
786 */ |
|
787 EXPORT_C TBool TBTNamelessDevice::IsPaired() const |
|
788 { |
|
789 return iPaired; |
|
790 } |
|
791 |
|
792 /** |
|
793 Set the bluetooth device address. |
|
794 @param aBDAddr the address of the device |
|
795 */ |
|
796 EXPORT_C void TBTNamelessDevice::SetAddress(const TBTDevAddr& aBDAddr) |
|
797 { |
|
798 iBDAddr = aBDAddr; |
|
799 iSetMask |= EAddress; |
|
800 } |
|
801 |
|
802 /** |
|
803 Set the device class. |
|
804 @param aDeviceClass the deviceclass of the device |
|
805 */ |
|
806 EXPORT_C void TBTNamelessDevice::SetDeviceClass(TBTDeviceClass aDeviceClass) |
|
807 { |
|
808 iDeviceClass = aDeviceClass; |
|
809 iSetMask |= EDeviceClass; |
|
810 } |
|
811 |
|
812 /** |
|
813 @publishedPartner |
|
814 @released |
|
815 Set the link key. |
|
816 @param aLinkkey the link key of the device |
|
817 */ |
|
818 EXPORT_C void TBTNamelessDevice::SetLinkKey(const TBTLinkKey& aLinkKey) |
|
819 { |
|
820 SetLinkKey(aLinkKey, ELinkKeyCombination); |
|
821 } |
|
822 |
|
823 /** |
|
824 @publishedPartner |
|
825 @released |
|
826 Set the link key. |
|
827 @param aLinkkey the link key of the device |
|
828 @param aLinkKeyType the link key type of the device |
|
829 */ |
|
830 EXPORT_C void TBTNamelessDevice::SetLinkKey(const TBTLinkKey& aLinkKey, TBTLinkKeyType aLinkKeyType) |
|
831 { |
|
832 iLinkKey.Copy(aLinkKey); |
|
833 iSetMask |= ELinkKey; |
|
834 SetPaired(aLinkKeyType); |
|
835 } |
|
836 |
|
837 |
|
838 /** |
|
839 Ensure that the previously known link key is discarded |
|
840 @publishedPartner |
|
841 @released |
|
842 */ |
|
843 EXPORT_C void TBTNamelessDevice::DeleteLinkKey() |
|
844 { |
|
845 iSetMask &= ~ELinkKey; |
|
846 iSetMask &= ~EIsPaired; |
|
847 } |
|
848 |
|
849 /** |
|
850 Set the page scan repetition mode. |
|
851 @param aPageScanRepMode the PSRM of the device |
|
852 @internalAll |
|
853 @released |
|
854 */ |
|
855 EXPORT_C void TBTNamelessDevice::SetPageScanRepMode(TUint8 aPageScanRepMode) |
|
856 { |
|
857 iBasebandParams.iPageScanRepetitionMode = aPageScanRepMode; |
|
858 iSetMask |= EPageScanRepMode; |
|
859 } |
|
860 |
|
861 /** |
|
862 Set the page scan mode. |
|
863 @param aPageScanMode the PSM of the device |
|
864 @internalAll |
|
865 @released |
|
866 */ |
|
867 EXPORT_C void TBTNamelessDevice::SetPageScanMode(TUint8 aPageScanMode) |
|
868 { |
|
869 iBasebandParams.iPageScanMode = aPageScanMode; |
|
870 iSetMask |= EPageScanMode; |
|
871 } |
|
872 |
|
873 /** |
|
874 Set the page scan period mode. |
|
875 @param aPageScanPeriodMode the PSPM of the device |
|
876 @internalAll |
|
877 @released |
|
878 */ |
|
879 EXPORT_C void TBTNamelessDevice::SetPageScanPeriodMode(TUint8 aPageScanPeriodMode) |
|
880 { |
|
881 iBasebandParams.iPageScanPeriodMode = aPageScanPeriodMode; |
|
882 iSetMask |= EPageScanPeriodMode; |
|
883 } |
|
884 |
|
885 /** |
|
886 Set the clock offset. |
|
887 @param aClockOffset the clockoffset for the device |
|
888 @internalAll |
|
889 @released |
|
890 */ |
|
891 EXPORT_C void TBTNamelessDevice::SetClockOffset(TUint16 aClockOffset) |
|
892 { |
|
893 iBasebandParams.iClockOffset = aClockOffset; |
|
894 iSetMask |= EClockOffset; |
|
895 } |
|
896 |
|
897 |
|
898 /** |
|
899 Set the Global security settings for all services used by this device |
|
900 @param aSetting the security override of the device |
|
901 */ |
|
902 EXPORT_C void TBTNamelessDevice::SetGlobalSecurity(const TBTDeviceSecurity& aSetting) |
|
903 { |
|
904 iGlobalSecurity = aSetting; |
|
905 iSetMask |= EGlobalSecurity; |
|
906 } |
|
907 |
|
908 /** |
|
909 Set when last seen in inquiry (not supported by stack at present) |
|
910 @param aDateTime The date/time stamp. |
|
911 */ |
|
912 EXPORT_C void TBTNamelessDevice::SetSeen(const TTime& aDateTime) |
|
913 { |
|
914 iSeen = aDateTime; |
|
915 iSetMask |= ESeen; |
|
916 } |
|
917 |
|
918 /** |
|
919 Set when the device last connected from or to. |
|
920 @param aDateTime The date/time stamp. |
|
921 */ |
|
922 EXPORT_C void TBTNamelessDevice::SetUsed(const TTime& aDateTime) |
|
923 { |
|
924 iUsed = aDateTime; |
|
925 iSetMask |= EUsed; |
|
926 } |
|
927 |
|
928 /** |
|
929 Set whether the device is paired. |
|
930 This function should not be used any more, instead the overload with a link key type |
|
931 should be used. |
|
932 @see TBTNamelessDevice::SetPaired(TBTLinkKeyType aLinkKeyType) |
|
933 @param aPaired whether the device is paired |
|
934 */ |
|
935 EXPORT_C void TBTNamelessDevice::SetPaired(TBool aPaired) |
|
936 { |
|
937 SetPaired(ELinkKeyCombination); |
|
938 iPaired = aPaired; |
|
939 } |
|
940 |
|
941 /** |
|
942 Set the link key type because the device is paired |
|
943 @param aLinkKeyType the link key type |
|
944 */ |
|
945 EXPORT_C void TBTNamelessDevice::SetPaired(TBTLinkKeyType aLinkKeyType) |
|
946 { |
|
947 iSetMask |= EIsPaired; |
|
948 iLinkKeyType = aLinkKeyType; |
|
949 iPaired = ETrue; |
|
950 } |
|
951 |
|
952 /** |
|
953 Set PIN code for device |
|
954 @param aPassKey used for pairing |
|
955 */ |
|
956 EXPORT_C void TBTNamelessDevice::SetPassKey(const TBTPinCode& aPassKey) |
|
957 { |
|
958 iPassKey = aPassKey; |
|
959 iSetMask |= EPassKey; |
|
960 } |
|
961 |
|
962 |
|
963 /** |
|
964 Denotes whether the device address has been set. |
|
965 @return ETrue = The address of the device been set |
|
966 */ |
|
967 EXPORT_C TBool TBTNamelessDevice::IsValidAddress() const |
|
968 { |
|
969 return (iSetMask & EAddress); |
|
970 } |
|
971 |
|
972 /** |
|
973 Denotes whether the device class has been set. |
|
974 @return ETrue = The class of the device been set |
|
975 */ |
|
976 EXPORT_C TBool TBTNamelessDevice::IsValidDeviceClass() const |
|
977 { |
|
978 return (iSetMask & EDeviceClass); |
|
979 } |
|
980 |
|
981 /** |
|
982 Denotes whether the link key has been set. |
|
983 @return ETrue = The link key of the device been set |
|
984 */ |
|
985 EXPORT_C TBool TBTNamelessDevice::IsValidLinkKey() const |
|
986 { |
|
987 return (iSetMask & ELinkKey); |
|
988 } |
|
989 |
|
990 /** |
|
991 Denotes whether the global security settings have been set. |
|
992 @return ETrue = The global security settings of the device been set |
|
993 */ |
|
994 EXPORT_C TBool TBTNamelessDevice::IsValidGlobalSecurity() const |
|
995 { |
|
996 return (iSetMask & EGlobalSecurity); |
|
997 } |
|
998 |
|
999 /** |
|
1000 Denotes whether the page scan repition mode has been set. |
|
1001 @return ETrue = The pagescanrepetitionmode of the device been set |
|
1002 */ |
|
1003 EXPORT_C TBool TBTNamelessDevice::IsValidPageScanRepMode() const |
|
1004 { |
|
1005 return (iSetMask & EPageScanRepMode); |
|
1006 } |
|
1007 |
|
1008 /** |
|
1009 Denotes whether the page scan mode has been set. |
|
1010 @return ETrue = The pagescanmode of the device been set |
|
1011 */ |
|
1012 EXPORT_C TBool TBTNamelessDevice::IsValidPageScanMode() const |
|
1013 { |
|
1014 return (iSetMask & EPageScanMode); |
|
1015 } |
|
1016 |
|
1017 /** |
|
1018 Denotes whether the page scan period mode has been set. |
|
1019 @return ETrue = The pagescanperiodmode of the device been set |
|
1020 */ |
|
1021 EXPORT_C TBool TBTNamelessDevice::IsValidPageScanPeriodMode() const |
|
1022 { |
|
1023 return (iSetMask & EPageScanPeriodMode); |
|
1024 } |
|
1025 |
|
1026 /** |
|
1027 Denotes whether the clock offset has been set. |
|
1028 @return ETrue = The clockoffset of the device been set |
|
1029 */ |
|
1030 EXPORT_C TBool TBTNamelessDevice::IsValidClockOffset() const |
|
1031 { |
|
1032 return (iSetMask & EClockOffset); |
|
1033 } |
|
1034 |
|
1035 /** |
|
1036 Denotes whether the time last seen has been set. |
|
1037 @return ETrue = The time last seen has been set |
|
1038 */ |
|
1039 EXPORT_C TBool TBTNamelessDevice::IsValidSeen() const |
|
1040 { |
|
1041 return (iSetMask & ESeen); |
|
1042 } |
|
1043 |
|
1044 /** |
|
1045 Denotes whether the time last used has been set. |
|
1046 @return ETrue = The time last used has been set |
|
1047 */ |
|
1048 EXPORT_C TBool TBTNamelessDevice::IsValidUsed() const |
|
1049 { |
|
1050 return (iSetMask & EUsed); |
|
1051 } |
|
1052 |
|
1053 /** |
|
1054 Denote whether is paired has been set |
|
1055 @return Etrue = whether is paired has been set |
|
1056 */ |
|
1057 EXPORT_C TBool TBTNamelessDevice::IsValidPaired() const |
|
1058 { |
|
1059 return iSetMask & EIsPaired; |
|
1060 } |
|
1061 |
|
1062 /** |
|
1063 Denotes whether the PassKey has been set. |
|
1064 @return ETrue = The PassKey of the device been set |
|
1065 */ |
|
1066 EXPORT_C TBool TBTNamelessDevice::IsValidPassKey() const |
|
1067 { |
|
1068 return iSetMask & EPassKey; |
|
1069 } |
|
1070 |
|
1071 /** |
|
1072 @return the PassKey length |
|
1073 @released |
|
1074 */ |
|
1075 EXPORT_C TUint TBTNamelessDevice::PassKeyLength() const |
|
1076 { |
|
1077 return iPassKey().iLength; |
|
1078 } |
|
1079 |
|
1080 /** |
|
1081 Denotes whether the UI Cookie has been set. |
|
1082 @return ETrue = The UI Cookie for the device been set |
|
1083 @publishedPartner |
|
1084 @released |
|
1085 */ |
|
1086 EXPORT_C TBool TBTNamelessDevice::IsValidUiCookie() const |
|
1087 { |
|
1088 return iSetMask & EUiCookie; |
|
1089 } |
|
1090 |
|
1091 /** |
|
1092 Sets the UI Cookie for the device. The format of the cookie is |
|
1093 specific to the UI using the field. |
|
1094 @param aUiCookie The 32bit cookie value. |
|
1095 @publishedPartner |
|
1096 @released |
|
1097 */ |
|
1098 EXPORT_C void TBTNamelessDevice::SetUiCookie(TUint32 aUiCookie) |
|
1099 { |
|
1100 iUiCookie = aUiCookie; |
|
1101 iSetMask |= EUiCookie; |
|
1102 } |
|
1103 |
|
1104 /** |
|
1105 Returns the UI Cookie value associated with the device. The format |
|
1106 of the cookie is specific to the UI using the field. |
|
1107 @return The 32bit cookie value. |
|
1108 @publishedPartner |
|
1109 @released |
|
1110 */ |
|
1111 EXPORT_C TUint32 TBTNamelessDevice::UiCookie() const |
|
1112 { |
|
1113 return iUiCookie; |
|
1114 } |
|
1115 |
|
1116 |
|
1117 // |
|
1118 |
|
1119 /** Set the device name. |
|
1120 @param aName device name |
|
1121 @leave This method will leave if an error occurs. |
|
1122 @internalAll |
|
1123 @released |
|
1124 */ |
|
1125 EXPORT_C void CBTDevice::SetDeviceNameL(const TDesC8& aName) |
|
1126 { |
|
1127 if (iDeviceName) |
|
1128 { |
|
1129 // scrub the present one |
|
1130 delete iDeviceName; |
|
1131 iDeviceName = NULL; |
|
1132 } |
|
1133 iDeviceName = HBufC8::NewL(aName.Length()); //device names are always 8bit |
|
1134 *iDeviceName = aName; |
|
1135 iDevice.iSetMask |= EDeviceName; |
|
1136 |
|
1137 } |
|
1138 |
|
1139 /** Set the friendly name. |
|
1140 @param aName friendly name of the device |
|
1141 @leave This method will leave if an error occurs. |
|
1142 */ |
|
1143 EXPORT_C void CBTDevice::SetFriendlyNameL(const TDesC& aName) |
|
1144 { |
|
1145 if (iFriendlyName) |
|
1146 { |
|
1147 // scrub the present one |
|
1148 delete iFriendlyName; |
|
1149 iFriendlyName = NULL; |
|
1150 } |
|
1151 iFriendlyName = HBufC::NewL(aName.Length()); |
|
1152 *iFriendlyName = aName; |
|
1153 iDevice.iSetMask |= static_cast<TUint>(EFriendlyName); |
|
1154 } |
|
1155 |
|
1156 /** Has the name of the device been set? |
|
1157 @return ETrue=>device name has been set, otherwise EFalse |
|
1158 */ |
|
1159 EXPORT_C TBool CBTDevice::IsValidDeviceName() const |
|
1160 { |
|
1161 return (iDevice.iSetMask & static_cast<TUint>(EDeviceName)); |
|
1162 } |
|
1163 |
|
1164 /** Has the friendly name of the device been set? |
|
1165 @return ETrue=>device name has been set, otherwise EFalse |
|
1166 */ |
|
1167 EXPORT_C TBool CBTDevice::IsValidFriendlyName() const |
|
1168 { |
|
1169 return (iDevice.iSetMask & static_cast<TUint>(EFriendlyName)); |
|
1170 } |
|
1171 |
|
1172 /** |
|
1173 Equality operator |
|
1174 @param aDevice instance against which this is compared |
|
1175 @return ETrue if aDevice==this |
|
1176 */ |
|
1177 EXPORT_C TBool CBTDevice::operator==(const CBTDevice& aDevice) const |
|
1178 { |
|
1179 return (CompareTo(aDevice) == (EAllNameProperties | TBTNamelessDevice::EAllNamelessProperties)) ? ETrue: EFalse; |
|
1180 } |
|
1181 |
|
1182 /** |
|
1183 Inequality operator |
|
1184 @param aDevice instance against which this is compared |
|
1185 @return ETrue if aDevice!=this |
|
1186 */ |
|
1187 EXPORT_C TBool CBTDevice::operator!=(const CBTDevice& aDevice) const |
|
1188 { |
|
1189 return !(*this==aDevice); |
|
1190 } |
|
1191 |
|
1192 /** |
|
1193 Externalise this object to aStream. |
|
1194 @param aStream The stream to which this object will be written. |
|
1195 @leave This method will leave if an error occurs. |
|
1196 */ |
|
1197 EXPORT_C void CBTDevice::ExternalizeL(RWriteStream& aStream) const |
|
1198 { |
|
1199 aStream.WriteUint32L(KStreamVersion); |
|
1200 aStream << BDAddr().Des(); |
|
1201 aStream << DeviceName(); |
|
1202 aStream << FriendlyName(); |
|
1203 |
|
1204 DeviceClass().ExternalizeL(aStream); |
|
1205 aStream << LinkKey(); |
|
1206 aStream << PassKey(); |
|
1207 GlobalSecurity().ExternalizeL(aStream); |
|
1208 iDevice.iBasebandParams.ExternalizeL(aStream); |
|
1209 |
|
1210 TPckg<TTime> seenPtr(Seen()); |
|
1211 aStream << seenPtr; |
|
1212 |
|
1213 TPckg<TTime> usedPtr(Used()); |
|
1214 aStream << usedPtr; |
|
1215 |
|
1216 aStream.WriteUint32L(iDevice.iSetMask); |
|
1217 |
|
1218 aStream.WriteUint32L(static_cast<TUint32>(IsPaired())); |
|
1219 aStream.WriteUint32L(static_cast<TUint32>(LinkKeyType())); |
|
1220 aStream.WriteUint32L(UiCookie()); |
|
1221 } |
|
1222 |
|
1223 /** |
|
1224 Internalize this object from aStream. |
|
1225 @param aStream The stream from which this object shall be internalized. |
|
1226 @leave This method will leave if an error occurs. |
|
1227 */ |
|
1228 EXPORT_C void CBTDevice::InternalizeL(RReadStream& aStream) |
|
1229 { |
|
1230 TUint32 version = aStream.ReadUint32L(); |
|
1231 static_cast<void>(version); // Currently only one valid version. |
|
1232 TPtr8 addr (iDevice.iBDAddr.Des()); |
|
1233 aStream >> addr; |
|
1234 |
|
1235 iDeviceName = HBufC8::NewL(aStream, KMaxBluetoothNameLen); |
|
1236 iFriendlyName = HBufC16::NewL(aStream, KMaxFriendlyNameLen); |
|
1237 |
|
1238 iDevice.iDeviceClass.InternalizeL(aStream); |
|
1239 aStream >> iDevice.iLinkKey; |
|
1240 aStream >> iDevice.iPassKey; |
|
1241 iDevice.iGlobalSecurity.InternalizeL(aStream); |
|
1242 |
|
1243 iDevice.iBasebandParams.InternalizeL(aStream); |
|
1244 |
|
1245 TPckg<TTime> seenPtr(iDevice.iSeen); |
|
1246 aStream >> seenPtr; |
|
1247 |
|
1248 TPckg<TTime> usedPtr(iDevice.iUsed); |
|
1249 aStream >> usedPtr; |
|
1250 |
|
1251 iDevice.iSetMask = aStream.ReadUint32L(); |
|
1252 |
|
1253 iDevice.iPaired = static_cast<TBool>(aStream.ReadUint32L()); |
|
1254 iDevice.iLinkKeyType = static_cast<TBTLinkKeyType>(aStream.ReadUint32L()); |
|
1255 iDevice.iUiCookie = aStream.ReadUint32L(); |
|
1256 } |
|
1257 |
|
1258 /** |
|
1259 Compares two devices. |
|
1260 @param aDevice instance against which this is compared |
|
1261 @return bit field (values of TBTDeviceComparisonResult) describing the similarities. |
|
1262 */ |
|
1263 EXPORT_C TUint CBTDevice::CompareTo(const CBTDevice& aDevice) const |
|
1264 { |
|
1265 TUint retval = (iDevice.CompareTo(aDevice.AsNamelessDevice()) | static_cast<TUint>(EAllNameProperties)); |
|
1266 |
|
1267 if (!((IsValidDeviceName() && aDevice.IsValidDeviceName() && (*iDeviceName==aDevice.DeviceName())) |
|
1268 || (!IsValidDeviceName() && !aDevice.IsValidDeviceName()))) |
|
1269 { |
|
1270 retval &= ~EDeviceName; |
|
1271 } |
|
1272 if (!((IsValidFriendlyName() && aDevice.IsValidFriendlyName() && (*iFriendlyName==aDevice.FriendlyName())) |
|
1273 || (!IsValidFriendlyName() && !aDevice.IsValidFriendlyName()))) |
|
1274 { |
|
1275 retval &= ~EFriendlyName; |
|
1276 } |
|
1277 return retval; |
|
1278 } |
|
1279 |
|
1280 /** |
|
1281 Effectively operator=, but can leave. |
|
1282 @param aDevice The device details to assign to this object. |
|
1283 @leave This method will leave if an error occurs. |
|
1284 */ |
|
1285 EXPORT_C void CBTDevice::AssignL(CBTDevice& aDevice) |
|
1286 { |
|
1287 // set the super class bits |
|
1288 aDevice.iDevice.Update(AsNamelessDevice()); |
|
1289 |
|
1290 // now the derived class |
|
1291 if (IsValidDeviceName()) |
|
1292 aDevice.SetDeviceNameL(DeviceName()); |
|
1293 if (IsValidFriendlyName()) |
|
1294 aDevice.SetFriendlyNameL(FriendlyName()); |
|
1295 } |
|
1296 |
|
1297 /** |
|
1298 Copies the contents of aDevice into *this |
|
1299 @param aDevice copied into *this |
|
1300 @leave This method will leave if an error occurs. |
|
1301 */ |
|
1302 EXPORT_C void CBTDevice::UpdateL(const CBTDevice& aDevice) |
|
1303 { |
|
1304 iDevice.Update(aDevice.AsNamelessDevice()); |
|
1305 |
|
1306 if (aDevice.IsValidDeviceName()) |
|
1307 SetDeviceNameL(aDevice.DeviceName()); |
|
1308 else |
|
1309 iDevice.iSetMask &= ~EDeviceName; |
|
1310 |
|
1311 if (aDevice.IsValidFriendlyName()) |
|
1312 SetFriendlyNameL(aDevice.FriendlyName()); |
|
1313 else |
|
1314 iDevice.iSetMask &= ~EFriendlyName; |
|
1315 } |
|
1316 |
|
1317 |
|
1318 /** |
|
1319 Get the TBTNamelessDevice portion of this. |
|
1320 @return the TBTNamelessDevice portion of this |
|
1321 */ |
|
1322 EXPORT_C TBTNamelessDevice& CBTDevice::AsNamelessDevice() |
|
1323 { |
|
1324 return iDevice; |
|
1325 } |
|
1326 |
|
1327 /** |
|
1328 Get the TBTNamelessDevice portion of this. |
|
1329 @return the TBTNamelessDevice portion of this |
|
1330 */ |
|
1331 EXPORT_C const TBTNamelessDevice& CBTDevice::AsNamelessDevice() const |
|
1332 { |
|
1333 return iDevice; |
|
1334 } |
|
1335 |
|
1336 // |
|
1337 |
|
1338 //TBTNamelessDevice facades |
|
1339 //in 7.0s |
|
1340 |
|
1341 /** |
|
1342 Get the device address. |
|
1343 @return the address of the device. |
|
1344 */ |
|
1345 EXPORT_C const TBTDevAddr& CBTDevice::BDAddr() const |
|
1346 { |
|
1347 return iDevice.Address(); |
|
1348 } |
|
1349 |
|
1350 /** |
|
1351 Get the device class. |
|
1352 @return the device class |
|
1353 */ |
|
1354 EXPORT_C TBTDeviceClass CBTDevice::DeviceClass() const |
|
1355 { |
|
1356 return iDevice.DeviceClass(); |
|
1357 } |
|
1358 |
|
1359 /** |
|
1360 Get the link key. |
|
1361 @return the link key |
|
1362 */ |
|
1363 EXPORT_C const TBTLinkKey& CBTDevice::LinkKey() const |
|
1364 { |
|
1365 return iDevice.LinkKey(); |
|
1366 } |
|
1367 |
|
1368 /** |
|
1369 @publishedPartner |
|
1370 Get the link key type. |
|
1371 @return the link key type |
|
1372 */ |
|
1373 EXPORT_C TBTLinkKeyType CBTDevice::LinkKeyType() const |
|
1374 { |
|
1375 return iDevice.LinkKeyType(); |
|
1376 } |
|
1377 |
|
1378 |
|
1379 /** |
|
1380 Get the global security settings. |
|
1381 @return the global security overrides of this device |
|
1382 */ |
|
1383 EXPORT_C const TBTDeviceSecurity CBTDevice::GlobalSecurity() const |
|
1384 { |
|
1385 return iDevice.iGlobalSecurity; |
|
1386 } |
|
1387 |
|
1388 /** |
|
1389 Set the device address. |
|
1390 @param aBDAddr the address of the device |
|
1391 */ |
|
1392 EXPORT_C void CBTDevice::SetDeviceAddress(const TBTDevAddr& aBDAddr) |
|
1393 { |
|
1394 iDevice.SetAddress(aBDAddr); |
|
1395 } |
|
1396 |
|
1397 /** |
|
1398 Set the device class. |
|
1399 @param aDeviceClass the device class of the device |
|
1400 */ |
|
1401 EXPORT_C void CBTDevice::SetDeviceClass(TBTDeviceClass aDeviceClass) |
|
1402 { |
|
1403 iDevice.SetDeviceClass(aDeviceClass); |
|
1404 } |
|
1405 |
|
1406 /** |
|
1407 Set the link key. |
|
1408 @param aLinkKey the link key of the device |
|
1409 @internalAll |
|
1410 @released |
|
1411 */ |
|
1412 EXPORT_C void CBTDevice::SetLinkKey(const TBTLinkKey& aLinkKey) |
|
1413 { |
|
1414 iDevice.SetLinkKey(aLinkKey); |
|
1415 } |
|
1416 |
|
1417 /** |
|
1418 Set the link key type of the device. |
|
1419 @param aLinkKey the link key of the device |
|
1420 @param aLinkKeyType the link key type of the device |
|
1421 @internalAll |
|
1422 @released |
|
1423 */ |
|
1424 EXPORT_C void CBTDevice::SetLinkKey(const TBTLinkKey& aLinkKey, TBTLinkKeyType aLinkKeyType) |
|
1425 { |
|
1426 iDevice.SetLinkKey(aLinkKey,aLinkKeyType); |
|
1427 } |
|
1428 |
|
1429 /** |
|
1430 Set the global security settings. |
|
1431 @param aSetting the security override of the device |
|
1432 */ |
|
1433 EXPORT_C void CBTDevice::SetGlobalSecurity(const TBTDeviceSecurity& aSetting) |
|
1434 { |
|
1435 iDevice.SetGlobalSecurity(aSetting); |
|
1436 } |
|
1437 |
|
1438 /** |
|
1439 Ensure that the previously known link key is discarded |
|
1440 */ |
|
1441 EXPORT_C void CBTDevice::DeleteLinkKey() |
|
1442 { |
|
1443 iDevice.DeleteLinkKey(); |
|
1444 } |
|
1445 |
|
1446 /** |
|
1447 Denotes whether the device address has been set. |
|
1448 @return ETrue if address has been set |
|
1449 */ |
|
1450 EXPORT_C TBool CBTDevice::IsValidBDAddr() const |
|
1451 { |
|
1452 return iDevice.IsValidAddress(); |
|
1453 } |
|
1454 |
|
1455 /** |
|
1456 Denotes whether the device class has been set. |
|
1457 @return ETrue if DeviceClass has been set |
|
1458 */ |
|
1459 EXPORT_C TBool CBTDevice::IsValidDeviceClass() const |
|
1460 { |
|
1461 return iDevice.IsValidDeviceClass(); |
|
1462 } |
|
1463 |
|
1464 /** |
|
1465 Denotes whether the link key has been set, and hence whether this is a paired device. |
|
1466 @return ETrue if link key has been set |
|
1467 */ |
|
1468 EXPORT_C TBool CBTDevice::IsValidLinkKey() const |
|
1469 { |
|
1470 return iDevice.IsValidLinkKey(); |
|
1471 } |
|
1472 |
|
1473 /** |
|
1474 Denotes whether the global security settings have been set. |
|
1475 @return ETrue if security override has been set |
|
1476 */ |
|
1477 EXPORT_C TBool CBTDevice::IsValidGlobalSecurity() const |
|
1478 { |
|
1479 return iDevice.IsValidGlobalSecurity(); |
|
1480 } |
|
1481 |
|
1482 /** |
|
1483 Get the time when the device was last seen. Note that this feature is not yet implemented in the |
|
1484 bluetooth stack, and the method CBTDevice::Used() should be used instead. |
|
1485 @return The time when the device was last seen. |
|
1486 */ |
|
1487 EXPORT_C const TTime& CBTDevice::Seen() const |
|
1488 { |
|
1489 return iDevice.Seen(); |
|
1490 } |
|
1491 |
|
1492 /** |
|
1493 Get the time when the device was last connected to. |
|
1494 @return The time when the device was last used. |
|
1495 */ |
|
1496 EXPORT_C const TTime& CBTDevice::Used() const |
|
1497 { |
|
1498 return iDevice.Used(); |
|
1499 } |
|
1500 |
|
1501 /** |
|
1502 Set the time when the device was last used. |
|
1503 @param aDateTime The time when the device was last used. |
|
1504 */ |
|
1505 EXPORT_C void CBTDevice::SetUsed(const TTime& aDateTime) |
|
1506 { |
|
1507 iDevice.SetUsed(aDateTime); |
|
1508 } |
|
1509 |
|
1510 /** |
|
1511 Set the time when the device was last seen. |
|
1512 @param aDateTime The time when the device was last seen. |
|
1513 */ |
|
1514 EXPORT_C void CBTDevice::SetSeen(const TTime& aDateTime) |
|
1515 { |
|
1516 iDevice.SetSeen(aDateTime); |
|
1517 } |
|
1518 |
|
1519 |
|
1520 /** |
|
1521 Denotes whether the time last used has been set. |
|
1522 @return ETrue if time last used has been set |
|
1523 */ |
|
1524 EXPORT_C TBool CBTDevice::IsValidUsed() const |
|
1525 { |
|
1526 return iDevice.IsValidUsed(); |
|
1527 } |
|
1528 |
|
1529 /** |
|
1530 Denotes whether the time last seen has been set. |
|
1531 @return ETrue if time last seen has been set |
|
1532 */ |
|
1533 EXPORT_C TBool CBTDevice::IsValidSeen() const |
|
1534 { |
|
1535 return iDevice.IsValidSeen(); |
|
1536 } |
|
1537 /** |
|
1538 Check whether the device is paired. |
|
1539 @return ETrue if the device is paired. |
|
1540 */ |
|
1541 EXPORT_C TBool CBTDevice::IsPaired() const |
|
1542 { |
|
1543 return iDevice.IsPaired(); |
|
1544 } |
|
1545 |
|
1546 /** |
|
1547 Set whether the device is paired; |
|
1548 This function should no longer be used, the overloaded SetPaired function should be used. |
|
1549 @see CBTDevice::SetPaired(TBTLinkKeyType aLinkKeyType) |
|
1550 @param aPaired Whether the device is paired |
|
1551 */ |
|
1552 EXPORT_C void CBTDevice::SetPaired(TBool aPaired) |
|
1553 { |
|
1554 iDevice.SetPaired(aPaired); |
|
1555 } |
|
1556 |
|
1557 /** |
|
1558 Set whether the link key type when the device is paired; |
|
1559 @param aLinkKeyType the link key type of the paired device |
|
1560 */ |
|
1561 EXPORT_C void CBTDevice::SetPaired(TBTLinkKeyType aLinkKeyType) |
|
1562 { |
|
1563 iDevice.SetPaired(aLinkKeyType); |
|
1564 } |
|
1565 |
|
1566 |
|
1567 /** |
|
1568 Denotes whether the device is paired has been set. |
|
1569 @return ETrue if whether the device is paired has been set. |
|
1570 */ |
|
1571 EXPORT_C TBool CBTDevice::IsValidPaired() const |
|
1572 { |
|
1573 return iDevice.IsValidPaired(); |
|
1574 } |
|
1575 |
|
1576 /** |
|
1577 Set the passkey. |
|
1578 @param aPassKey the PIN code of the device |
|
1579 @internalAll |
|
1580 @released |
|
1581 */ |
|
1582 EXPORT_C void CBTDevice::SetPassKey(const TBTPinCode& aPassKey) |
|
1583 { |
|
1584 iDevice.SetPassKey(aPassKey); |
|
1585 } |
|
1586 |
|
1587 /** |
|
1588 Get the PIN code |
|
1589 @return The PIN code |
|
1590 */ |
|
1591 EXPORT_C const TBTPinCode& CBTDevice::PassKey() const |
|
1592 { |
|
1593 return iDevice.PassKey(); |
|
1594 } |
|
1595 |
|
1596 /** |
|
1597 Denotes whether the PIN code has been set. |
|
1598 @return ETrue if whether the PIN code has been set. |
|
1599 */ |
|
1600 EXPORT_C TBool CBTDevice::IsValidPassKey() const |
|
1601 { |
|
1602 return iDevice.IsValidPassKey(); |
|
1603 } |
|
1604 |
|
1605 /** |
|
1606 Get the PIN code length |
|
1607 @return The PIN code length |
|
1608 */ |
|
1609 EXPORT_C TUint CBTDevice::PassKeyLength() const |
|
1610 { |
|
1611 return iDevice.PassKeyLength(); |
|
1612 } |
|
1613 |
|
1614 /** |
|
1615 Denotes whether the UI Cookie has been set. |
|
1616 @return ETrue = The UI Cookie for the device been set |
|
1617 @publishedPartner |
|
1618 @released |
|
1619 */ |
|
1620 EXPORT_C TBool CBTDevice::IsValidUiCookie() const |
|
1621 { |
|
1622 return iDevice.IsValidUiCookie(); |
|
1623 } |
|
1624 |
|
1625 /** |
|
1626 Sets the UI Cookie for the device. The format of the cookie is |
|
1627 specific to the UI using the field. |
|
1628 @param aUiCookie The 32bit cookie value. |
|
1629 @publishedPartner |
|
1630 @released |
|
1631 */ |
|
1632 EXPORT_C void CBTDevice::SetUiCookie(TUint32 aUiCookie) |
|
1633 { |
|
1634 iDevice.SetUiCookie(aUiCookie); |
|
1635 } |
|
1636 |
|
1637 /** |
|
1638 Returns the UI Cookie value associated with the device. The format |
|
1639 of the cookie is specific to the UI using the field. |
|
1640 @return The 32bit cookie value. |
|
1641 @publishedPartner |
|
1642 @released |
|
1643 */ |
|
1644 EXPORT_C TUint32 CBTDevice::UiCookie() const |
|
1645 { |
|
1646 return iDevice.UiCookie(); |
|
1647 } |
|
1648 |
|
1649 |
|
1650 |
|
1651 // |
|
1652 |
|
1653 |
|
1654 |
|
1655 /** |
|
1656 Constructor |
|
1657 */ |
|
1658 EXPORT_C TBTDeviceSecurity::TBTDeviceSecurity() |
|
1659 : iSecurity(0) |
|
1660 , iPasskeyMinLength(0) |
|
1661 { |
|
1662 } |
|
1663 |
|
1664 /** |
|
1665 Constructor with userdefined security |
|
1666 @param aSecurity bitfield describing security settings |
|
1667 @see SecurityValue() |
|
1668 */ |
|
1669 EXPORT_C TBTDeviceSecurity::TBTDeviceSecurity(TUint8 aSecurity) |
|
1670 : iSecurity(aSecurity) |
|
1671 , iPasskeyMinLength(0) |
|
1672 { |
|
1673 } |
|
1674 |
|
1675 /** |
|
1676 Constructor with userdefined security |
|
1677 @param aSecurity bitfield describing security settings |
|
1678 @param aPasskeyMinLength 0..16 |
|
1679 @see SecurityValue() |
|
1680 */ |
|
1681 EXPORT_C TBTDeviceSecurity::TBTDeviceSecurity(TUint8 aSecurity, TUint aPasskeyMinLength) |
|
1682 : iSecurity(aSecurity) |
|
1683 , iPasskeyMinLength(aPasskeyMinLength) |
|
1684 { |
|
1685 } |
|
1686 |
|
1687 /** |
|
1688 Constructor with user-defined security |
|
1689 @param aNoAuthenticate Use ETrue if connections with this device should not be authenticated. |
|
1690 @param aNoAuthorise Use ETrue if connections with this device should not be authorised - ie the device is trusted. |
|
1691 @param aEncrypt Use ETrue if connections with this device should be encrypted |
|
1692 @param aBanned Use ETrue if connections with this device should not be allowed |
|
1693 */ |
|
1694 EXPORT_C TBTDeviceSecurity::TBTDeviceSecurity(TBool aNoAuthenticate, TBool aNoAuthorise, TBool aEncrypt, TBool aBanned) |
|
1695 { |
|
1696 iSecurity = 0; |
|
1697 if ( aNoAuthenticate ) |
|
1698 iSecurity |= ENoAuthenticate; |
|
1699 if ( aNoAuthorise ) |
|
1700 iSecurity |= ENoAuthorise; |
|
1701 if (aEncrypt) |
|
1702 iSecurity |= EEncrypt; |
|
1703 if (aBanned) |
|
1704 iSecurity |= EBanned; |
|
1705 } |
|
1706 |
|
1707 /** |
|
1708 Constructor with user-defined security |
|
1709 @param aMitmRequirements Use TBTDeviceSecurity::EMitmRequired if connections with this device should require MITM protection. |
|
1710 @param aNoAuthorise Use ETrue if connections with this device should not be authorised - ie the device is trusted. |
|
1711 @param aEncrypt Use ETrue if connections with this device should be encrypted |
|
1712 @param aBanned Use ETrue if connections with this device should not be allowed |
|
1713 */ |
|
1714 EXPORT_C TBTDeviceSecurity::TBTDeviceSecurity(TBTDeviceSecurity::TMitmRequired aMitmRequirements, TBool aNoAuthorise, TBool aEncrypt, TBool aBanned) |
|
1715 { |
|
1716 iSecurity = 0; |
|
1717 if ( aMitmRequirements == EMitmRequired ) |
|
1718 iSecurity |= EMitmProtectionRequired; |
|
1719 if ( aNoAuthorise ) |
|
1720 iSecurity |= ENoAuthorise; |
|
1721 if (aEncrypt) |
|
1722 iSecurity |= EEncrypt; |
|
1723 if (aBanned) |
|
1724 iSecurity |= EBanned; |
|
1725 } |
|
1726 |
|
1727 /** |
|
1728 Set (no) authentication |
|
1729 @param aDecision ETrue=>don't authenticate, EFalse=>authenticate |
|
1730 */ |
|
1731 EXPORT_C void TBTDeviceSecurity::SetNoAuthenticate(TBool aDecision) |
|
1732 { |
|
1733 if (aDecision) |
|
1734 iSecurity |= ENoAuthenticate; |
|
1735 else |
|
1736 iSecurity &= ~ENoAuthenticate; |
|
1737 } |
|
1738 |
|
1739 /** |
|
1740 Specifies the man-in-the-middle requirements on a security service. |
|
1741 @param aDecision EMitmRequired if MITM protection is required for connections for a particular |
|
1742 device, EMitmUnspecified otherwise to use the default service requirements. |
|
1743 */ |
|
1744 EXPORT_C void TBTDeviceSecurity::SetMitmRequirements(TBTDeviceSecurity::TMitmRequired aDecision) |
|
1745 { |
|
1746 if (aDecision == EMitmRequired) |
|
1747 iSecurity |= EMitmProtectionRequired; |
|
1748 else |
|
1749 iSecurity &= ~EMitmProtectionRequired; |
|
1750 } |
|
1751 |
|
1752 /** |
|
1753 Set (no) authorisation (=make trusted) |
|
1754 @param aDecision ETrue=>don't authorise, EFalse=>authorise |
|
1755 */ |
|
1756 EXPORT_C void TBTDeviceSecurity::SetNoAuthorise(TBool aDecision) |
|
1757 { |
|
1758 if (aDecision) |
|
1759 iSecurity |= ENoAuthorise; |
|
1760 else |
|
1761 iSecurity &= ~ENoAuthorise; |
|
1762 } |
|
1763 |
|
1764 /** |
|
1765 Set encryption |
|
1766 @param aDecision ETrue=>encrypt, EFalse=>don't encrypt |
|
1767 */ |
|
1768 EXPORT_C void TBTDeviceSecurity::SetEncrypt(TBool aDecision) |
|
1769 { |
|
1770 if (aDecision) |
|
1771 iSecurity |= EEncrypt; |
|
1772 else |
|
1773 iSecurity &= ~EEncrypt; |
|
1774 } |
|
1775 |
|
1776 /** |
|
1777 Set banned |
|
1778 @param aDecision ETrue=>device is banned, EFalse=>device allowed |
|
1779 */ |
|
1780 EXPORT_C void TBTDeviceSecurity::SetBanned(TBool aDecision) |
|
1781 { |
|
1782 if (aDecision) |
|
1783 iSecurity |= EBanned; |
|
1784 else |
|
1785 iSecurity &= ~EBanned; |
|
1786 } |
|
1787 |
|
1788 /** |
|
1789 Determine whether connections to this device should not be authenticated. |
|
1790 @return ETrue=>don't authenticate, EFalse=>authenticate |
|
1791 */ |
|
1792 EXPORT_C TBool TBTDeviceSecurity::NoAuthenticate() const |
|
1793 { |
|
1794 if ( iSecurity & ENoAuthenticate ) |
|
1795 return ETrue; |
|
1796 else |
|
1797 return EFalse; |
|
1798 } |
|
1799 |
|
1800 /** |
|
1801 Determine whether connections to this device should have MITM protection. |
|
1802 @return TBTDeviceSecurity::EMitmRequired=>require MITM protection, TBTDeviceSecurity::EMitmUnspecified=>unspecified MITM protection requirement. |
|
1803 */ |
|
1804 EXPORT_C TBTDeviceSecurity::TMitmRequired TBTDeviceSecurity::MitmRequirements() const |
|
1805 { |
|
1806 if ( iSecurity & EMitmProtectionRequired ) |
|
1807 return EMitmRequired; |
|
1808 else |
|
1809 return EMitmUnspecified; |
|
1810 } |
|
1811 |
|
1812 /** |
|
1813 Determine whether connections to this device should not be authorised. |
|
1814 @return ETrue=>don't authorise, EFalse=>authorisation |
|
1815 */ |
|
1816 EXPORT_C TBool TBTDeviceSecurity::NoAuthorise() const |
|
1817 { |
|
1818 if ( iSecurity & ENoAuthorise ) |
|
1819 return ETrue; |
|
1820 else |
|
1821 return EFalse; |
|
1822 } |
|
1823 |
|
1824 /** |
|
1825 Determine whether connections to this device should be encrypted. |
|
1826 @return ETrue=>encrypt, EFalse=>don't encrypt |
|
1827 */ |
|
1828 EXPORT_C TBool TBTDeviceSecurity::Encrypt() const |
|
1829 { |
|
1830 if ( iSecurity & EEncrypt ) |
|
1831 return ETrue; |
|
1832 else |
|
1833 return EFalse; |
|
1834 } |
|
1835 |
|
1836 /** |
|
1837 Determine whether connections to this device should be banned. |
|
1838 @return ETrue=>banned, EFalse=>not banned |
|
1839 */ |
|
1840 EXPORT_C TBool TBTDeviceSecurity::Banned() const |
|
1841 { |
|
1842 if ( iSecurity & EBanned ) |
|
1843 return ETrue; |
|
1844 else |
|
1845 return EFalse; |
|
1846 } |
|
1847 |
|
1848 /** |
|
1849 Get the raw security settings. |
|
1850 @return 8 bit unsigned value of security settings |
|
1851 */ |
|
1852 EXPORT_C TUint8 TBTDeviceSecurity::SecurityValue() const |
|
1853 { |
|
1854 return iSecurity; |
|
1855 } |
|
1856 |
|
1857 /** |
|
1858 Set the raw security settings. |
|
1859 @param aDeviceSecurity 8 bit settings of security |
|
1860 */ |
|
1861 EXPORT_C void TBTDeviceSecurity::SetSecurityValue(TUint8 aValue) |
|
1862 { |
|
1863 iSecurity = aValue; |
|
1864 } |
|
1865 |
|
1866 /** |
|
1867 Set passkey min length. |
|
1868 @param aPasskeyMinLength:0..16 |
|
1869 */ |
|
1870 EXPORT_C TInt TBTDeviceSecurity::SetPasskeyMinLength(TUint aPasskeyMinLength) |
|
1871 { |
|
1872 if (1<=aPasskeyMinLength && aPasskeyMinLength<=KHCIPINCodeSize) |
|
1873 { |
|
1874 iPasskeyMinLength = aPasskeyMinLength; |
|
1875 return KErrNone; |
|
1876 } |
|
1877 else |
|
1878 { |
|
1879 iPasskeyMinLength = 0; |
|
1880 return KErrOverflow; |
|
1881 } |
|
1882 } |
|
1883 |
|
1884 /** |
|
1885 Get passkey min length. |
|
1886 @return TUint passkey min length |
|
1887 */ |
|
1888 EXPORT_C TUint TBTDeviceSecurity::PasskeyMinLength() const |
|
1889 { |
|
1890 return iPasskeyMinLength; |
|
1891 } |
|
1892 |
|
1893 /** |
|
1894 Comparison operator |
|
1895 @param aDeviceSecurity instance of class with which to compare |
|
1896 @return ETrue if instances equal |
|
1897 */ |
|
1898 EXPORT_C TBool TBTDeviceSecurity::operator==(const TBTDeviceSecurity& aSetting) const |
|
1899 { |
|
1900 if ( iSecurity == aSetting.iSecurity && iPasskeyMinLength == aSetting.iPasskeyMinLength ) |
|
1901 return ETrue; |
|
1902 else |
|
1903 return EFalse; |
|
1904 } |
|
1905 |
|
1906 /** |
|
1907 Inequality operator |
|
1908 @param aDeviceSecurity instance of class with which to compare |
|
1909 @return ETrue if instances not equal |
|
1910 */ |
|
1911 EXPORT_C TBool TBTDeviceSecurity::operator!=(const TBTDeviceSecurity& aSetting) const |
|
1912 { |
|
1913 return !(*this==aSetting); |
|
1914 } |
|
1915 |
|
1916 |
|
1917 /** |
|
1918 Externalise object. |
|
1919 @param aStream The stream to which the object shall be externalised. |
|
1920 @leave This method will leave if an error occurs. |
|
1921 */ |
|
1922 EXPORT_C void TBTDeviceSecurity::ExternalizeL(RWriteStream& aStream) const |
|
1923 { |
|
1924 aStream.WriteUint32L(KStreamVersion); |
|
1925 aStream.WriteUint8L(iSecurity); |
|
1926 aStream.WriteUint32L(iPasskeyMinLength); |
|
1927 } |
|
1928 |
|
1929 /** |
|
1930 Internalise object. |
|
1931 @param aStream The stream from which the object shall be internalised. |
|
1932 @leave This method will leave if an error occurs. |
|
1933 */ |
|
1934 EXPORT_C void TBTDeviceSecurity::InternalizeL(RReadStream& aStream) |
|
1935 { |
|
1936 TUint32 version = aStream.ReadUint32L(); |
|
1937 static_cast<void>(version); // Currently only one valid version. |
|
1938 iSecurity = aStream.ReadUint8L(); |
|
1939 iPasskeyMinLength = aStream.ReadUint32L(); |
|
1940 } |
|
1941 |
|
1942 |
|
1943 /** |
|
1944 Constructor |
|
1945 @param aDevice The device to which the security applies |
|
1946 @param aSecuritySettings The settings for the device |
|
1947 @see TBTDeviceSecurity |
|
1948 */ |
|
1949 EXPORT_C TBTServiceSecurityPerDevice::TBTServiceSecurityPerDevice(const TBTDevAddr& aAddress, const TBTDeviceSecurity& aSecSettings) |
|
1950 : iDeviceAddress(aAddress), iDeviceSecurity(aSecSettings) |
|
1951 { |
|
1952 } |
|
1953 |
|
1954 /** |
|
1955 Constructor |
|
1956 */ |
|
1957 EXPORT_C TBTServiceSecurityPerDevice::TBTServiceSecurityPerDevice() |
|
1958 { |
|
1959 } |
|
1960 |
|
1961 |
|
1962 /** |
|
1963 Copy constructor. |
|
1964 @param aData The object to be copied. |
|
1965 */ |
|
1966 EXPORT_C TBTServiceSecurityPerDevice::TBTServiceSecurityPerDevice(const TBTServiceSecurityPerDevice& aData) : |
|
1967 iDeviceAddress(aData.iDeviceAddress), iDeviceSecurity(aData.iDeviceSecurity) |
|
1968 { |
|
1969 } |
|
1970 |
|
1971 |
|
1972 /** |
|
1973 Reset the device security |
|
1974 @param aSecuritySettings the new security settings |
|
1975 */ |
|
1976 EXPORT_C void TBTServiceSecurityPerDevice::SetDeviceSecurity(const TBTDeviceSecurity& aSecuritySettings) |
|
1977 { |
|
1978 iDeviceSecurity = aSecuritySettings; |
|
1979 } |
|
1980 |
|
1981 /** |
|
1982 Reset device address |
|
1983 @param aAddress The new address |
|
1984 */ |
|
1985 EXPORT_C void TBTServiceSecurityPerDevice::SetAddress(const TBTDevAddr& aAddress) |
|
1986 { |
|
1987 iDeviceAddress = aAddress; |
|
1988 } |
|
1989 |
|
1990 /** |
|
1991 Get the device security. |
|
1992 @return The device security |
|
1993 */ |
|
1994 EXPORT_C const TBTDeviceSecurity& TBTServiceSecurityPerDevice::DeviceSecurity() const |
|
1995 { |
|
1996 return iDeviceSecurity; |
|
1997 } |
|
1998 |
|
1999 /** |
|
2000 Get the device address. |
|
2001 @return The device address |
|
2002 */ |
|
2003 EXPORT_C const TBTDevAddr& TBTServiceSecurityPerDevice::DeviceAddress() const |
|
2004 { |
|
2005 return iDeviceAddress; |
|
2006 } |
|
2007 |
|
2008 /** |
|
2009 Assignment operator |
|
2010 @param aServiceSecurityPerDevice The instance to which this will be assigned |
|
2011 */ |
|
2012 EXPORT_C void TBTServiceSecurityPerDevice::operator=(const TBTServiceSecurityPerDevice& aData) |
|
2013 { |
|
2014 iDeviceAddress = aData.iDeviceAddress; |
|
2015 iDeviceSecurity = aData.iDeviceSecurity; |
|
2016 } |
|
2017 |
|
2018 /** |
|
2019 Equality operator |
|
2020 @param aServiceSecurityPerDevice The instance to which this will be compared |
|
2021 @return ETrue if this equals aServiceSecurityPerDevice |
|
2022 */ |
|
2023 EXPORT_C TBool TBTServiceSecurityPerDevice::operator==(const TBTServiceSecurityPerDevice& aService) const |
|
2024 { |
|
2025 if (( iDeviceAddress == aService.iDeviceAddress) && (iDeviceSecurity == aService.iDeviceSecurity )) |
|
2026 return ETrue; |
|
2027 else |
|
2028 return EFalse; |
|
2029 } |
|
2030 |
|
2031 /** |
|
2032 Inequality operator |
|
2033 @param aServiceSecurityPerDevice The instance to which this will be compared |
|
2034 @return ETrue if this does not equal aServiceSecurityPerDevice |
|
2035 */ |
|
2036 EXPORT_C TBool TBTServiceSecurityPerDevice::operator!=(const TBTServiceSecurityPerDevice& aService) const |
|
2037 { |
|
2038 return !(*this==aService); |
|
2039 } |
|
2040 |
|
2041 /** |
|
2042 Externalise object. |
|
2043 @param aStream The stream to which the object shall be externalized. |
|
2044 @leave This method will leave if an error occurs. |
|
2045 */ |
|
2046 EXPORT_C void TBTServiceSecurityPerDevice::ExternalizeL(RWriteStream& aStream) const |
|
2047 { |
|
2048 aStream.WriteUint32L(KStreamVersion); |
|
2049 iDeviceSecurity.ExternalizeL(aStream); |
|
2050 aStream.WriteL(iDeviceAddress.Des()); |
|
2051 } |
|
2052 |
|
2053 /** |
|
2054 Internalise object. |
|
2055 @param aStream The stream from which the object shall be internalized. |
|
2056 @leave This method will leave if an error occurs. |
|
2057 */ |
|
2058 EXPORT_C void TBTServiceSecurityPerDevice::InternalizeL(RReadStream& aStream) |
|
2059 { |
|
2060 TUint32 version = aStream.ReadUint32L(); |
|
2061 static_cast<void>(version); // Currently only one valid version. |
|
2062 iDeviceSecurity.InternalizeL(aStream); |
|
2063 |
|
2064 TPtr8 addr (iDeviceAddress.Des()); |
|
2065 aStream >> addr; |
|
2066 } |
|
2067 |
|
2068 /** |
|
2069 Externalise object. |
|
2070 @param aStream The stream to which the object shall be externalized. |
|
2071 @leave This method will leave if an error occurs. |
|
2072 */ |
|
2073 void TBTNamelessDevice::TBTBasebandParameters::ExternalizeL(RWriteStream& aStream) const |
|
2074 { |
|
2075 aStream.WriteUint32L(KStreamVersion); |
|
2076 aStream.WriteUint8L(iPageScanRepetitionMode); |
|
2077 aStream.WriteUint8L(iPageScanMode); |
|
2078 aStream.WriteUint8L(iPageScanPeriodMode); |
|
2079 aStream.WriteUint16L(iClockOffset); |
|
2080 } |
|
2081 |
|
2082 /** |
|
2083 Internalise object. |
|
2084 @param aStream The stream from which the object shall be internalized. |
|
2085 @leave This method will leave if an error occurs. |
|
2086 */ |
|
2087 void TBTNamelessDevice::TBTBasebandParameters::InternalizeL(RReadStream& aStream) |
|
2088 /** |
|
2089 Internalise class |
|
2090 */ |
|
2091 { |
|
2092 TUint32 version = aStream.ReadUint32L(); |
|
2093 static_cast<void>(version); // Currently only one version is available |
|
2094 iPageScanRepetitionMode = aStream.ReadUint8L(); |
|
2095 iPageScanMode = aStream.ReadUint8L(); |
|
2096 iPageScanPeriodMode = aStream.ReadUint8L(); |
|
2097 iClockOffset = aStream.ReadUint16L(); |
|
2098 } |
|
2099 |
|
2100 |
|
2101 // AFH Host Channel Classification |
|
2102 |
|
2103 const TUint8 KNumBitIndexBits=3; |
|
2104 const TUint8 KBitsInByte=1<<KNumBitIndexBits; |
|
2105 const TUint8 KBitIndexBitsMask=KBitsInByte-1; |
|
2106 |
|
2107 |
|
2108 /** Constructor |
|
2109 |
|
2110 @see TBuf8 |
|
2111 */ |
|
2112 EXPORT_C TBTAFHHostChannelClassification::TBTAFHHostChannelClassification() |
|
2113 : TBuf8<KHCIAFHHostChannelClassificationSize>() |
|
2114 { |
|
2115 Reset(); |
|
2116 } |
|
2117 |
|
2118 |
|
2119 /**Resets descriptor to default value |
|
2120 |
|
2121 The default value is that in which there are no bad channels in 79 channel set. |
|
2122 Note: most significant bit is reserved and set to zero. |
|
2123 */ |
|
2124 EXPORT_C void TBTAFHHostChannelClassification::Reset() |
|
2125 { |
|
2126 Fill(0xff,KHCIAFHHostChannelClassificationSize); |
|
2127 (*this)[0] &= ~(1<<(KBitsInByte-1)); //set most significant reserved bit to 0 |
|
2128 } |
|
2129 |
|
2130 |
|
2131 /**Check that this AFH host channel classification conforms to the spec. |
|
2132 |
|
2133 Checks that at least 20 channels are NOT set to bad, as |
|
2134 required in Bluetooth specification. |
|
2135 Also checks length is ten bytes. |
|
2136 |
|
2137 @return an error (KErrNone if this is valid) |
|
2138 */ |
|
2139 EXPORT_C TInt TBTAFHHostChannelClassification::Validate() const |
|
2140 { |
|
2141 if(Length()<KHCIAFHHostChannelClassificationSize) |
|
2142 { |
|
2143 return KErrNotSupported; |
|
2144 } |
|
2145 if(Length()>KHCIAFHHostChannelClassificationSize) |
|
2146 { |
|
2147 return KErrNotSupported; |
|
2148 } |
|
2149 |
|
2150 TUint8 bitCounter = NumUnknownsWithinRange(0, KAFHNumChannels-1); |
|
2151 if(bitCounter<KAFHMinUnknownChannels) |
|
2152 { |
|
2153 return KErrUnderflow; |
|
2154 } |
|
2155 |
|
2156 return KErrNone; |
|
2157 } |
|
2158 |
|
2159 |
|
2160 /**Set a channel in this TBTAFHHostChannelClassification as 'bad' or busy. |
|
2161 |
|
2162 Channels are represented by the bits in the TBTAFHHostChannelClassification descriptor. |
|
2163 The most significant leftmost bit is always set to 0. |
|
2164 The next most significant bit represents channel 78 |
|
2165 The least significant rightmost bit represents channel 0 |
|
2166 SetChannelBad unsets (i.e. sets to 0) the bit specified by |
|
2167 the parameter 'aChannel'. |
|
2168 |
|
2169 @param aChannel The number (in the range [0,78]) of the channel to be set as bad |
|
2170 @return an error (KErrNone implies success) |
|
2171 */ |
|
2172 EXPORT_C TInt TBTAFHHostChannelClassification::SetChannelBad(TUint8 aChannel) |
|
2173 { |
|
2174 return SetChannelRangeBad(aChannel, aChannel); |
|
2175 } |
|
2176 |
|
2177 |
|
2178 /**Set a range of channels in this TBTAFHHostChannelClassification as 'bad' or busy. |
|
2179 |
|
2180 Channels are represented by the bits in the TBTAFHHostChannelClassification descriptor. |
|
2181 The most significant leftmost bit is always set to 0. |
|
2182 The next most significant bit represents channel 78 |
|
2183 The least significant rightmost bit represents channel 0 |
|
2184 SetChannelRangeBad unsets (i.e. sets to 0) all bits in the range |
|
2185 ['aChannelRangeLowest','aChannelRangeHighest'], that is all bits |
|
2186 between and including the bit repesenting 'aChannelRangeLowest' and |
|
2187 the bit representing 'aChannelRangeHighest'. |
|
2188 |
|
2189 @param aChannelRangeLowest The lowest channel number representing a channel to be set as bad |
|
2190 @param aChannelRangeHighest The highest channel number representing a channel to be set as bad |
|
2191 @return an error (KErrNone implies success) |
|
2192 */ |
|
2193 EXPORT_C TInt TBTAFHHostChannelClassification::SetChannelRangeBad(const TUint8 aChannelRangeLowest, const TUint8 aChannelRangeHighest) |
|
2194 { |
|
2195 __ASSERT_DEBUG(aChannelRangeLowest <= aChannelRangeHighest, User::Panic(_L("AFH Bad Channel Range"), KErrArgument)); |
|
2196 if(aChannelRangeLowest > aChannelRangeHighest) |
|
2197 { |
|
2198 return KErrArgument; |
|
2199 } |
|
2200 //count how many 'unknowns' exist outside range to be set as 'bad' |
|
2201 TUint8 bitCounter = static_cast<TUint8>(NumUnknownsWithinRange(0, KAFHNumChannels-1) |
|
2202 - NumUnknownsWithinRange(aChannelRangeLowest, aChannelRangeHighest)); //cast because msvc6 complains otherwise |
|
2203 if(bitCounter<KAFHMinUnknownChannels) |
|
2204 { |
|
2205 return KErrUnderflow; |
|
2206 } |
|
2207 TInt ret = KErrNone; |
|
2208 for(TUint8 i=aChannelRangeLowest;i<=aChannelRangeHighest; ++i) |
|
2209 { |
|
2210 ret = DoSetChannelBad(i); |
|
2211 if(ret!=KErrNone) |
|
2212 { |
|
2213 return ret; |
|
2214 } |
|
2215 } |
|
2216 return KErrNone; |
|
2217 } |
|
2218 |
|
2219 TInt TBTAFHHostChannelClassification::BitByteIndices(TUint8& aByteIndex, TUint8& aBitIndex, const TUint8 aChannel) const |
|
2220 //Actually set 'aChannel' as bad. |
|
2221 { |
|
2222 __ASSERT_DEBUG(aChannel<KAFHNumChannels, User::Panic(_L("AFH Bad Channel Number"), KErrArgument)); |
|
2223 //Numbering bytes from left of descriptor, bits from right of byte, we have:- |
|
2224 //aChannel = 79 -> byte 0, bit 7 most significant bit (reserved 0) |
|
2225 //aChannel = 78 -> byte 0, bit 6 |
|
2226 //aChannel = 77 -> byte 0, bit 5 |
|
2227 //aChannel = 72 -> byte 0, bit 0 |
|
2228 //aChannel = 71 -> byte 1, bit 7 |
|
2229 //aChannel = 0 -> byte 9, bit 0 least significant bit |
|
2230 // referred in spec to bit 0 |
|
2231 //Extract byte index from 'aChannel' (right to left) |
|
2232 aByteIndex = static_cast<TUint8>(aChannel >> KNumBitIndexBits); //cast because msvc6 complains otherwise |
|
2233 //Change to go left to right |
|
2234 aByteIndex = static_cast<TUint8>(KHCIAFHHostChannelClassificationSize - 1 - aByteIndex); //cast because msvc6 complains otherwise |
|
2235 //Extract bit index from 'aChannel' |
|
2236 aBitIndex = static_cast<TUint8>(aChannel & KBitIndexBitsMask); //cast because msvc6 complains otherwise |
|
2237 if(aByteIndex>=KHCIAFHHostChannelClassificationSize||aBitIndex>=KBitsInByte) |
|
2238 { |
|
2239 #ifdef __DEBUG |
|
2240 __BTDEBUGGER(); |
|
2241 #endif |
|
2242 return KErrArgument; |
|
2243 } |
|
2244 return KErrNone; |
|
2245 } |
|
2246 |
|
2247 TInt TBTAFHHostChannelClassification::DoSetChannelBad(const TUint8 aChannel) |
|
2248 //Actually set 'aChannel' as bad. |
|
2249 { |
|
2250 __ASSERT_DEBUG(aChannel<KAFHNumChannels, User::Panic(_L("AFH Bad Channel Number"), KErrArgument)); |
|
2251 TUint8 byteIndex; |
|
2252 TUint8 bitIndex; |
|
2253 TInt ret = BitByteIndices(byteIndex, bitIndex, aChannel); |
|
2254 if(ret==KErrNone) |
|
2255 { |
|
2256 (*this)[byteIndex] &= ~(1<<bitIndex); //Set bad channel bit to zero |
|
2257 } |
|
2258 return ret; |
|
2259 } |
|
2260 |
|
2261 TUint8 TBTAFHHostChannelClassification::NumUnknownsWithinRange(const TUint8 aChannelRangeLowest, const TUint8 aChannelRangeHighest) const |
|
2262 //Count bits set to 1 within range |
|
2263 { |
|
2264 TUint8 bitCounter = 0; |
|
2265 for(TUint8 i = aChannelRangeLowest;i<=aChannelRangeHighest;++i) |
|
2266 { |
|
2267 TUint8 byteIndex; |
|
2268 TUint8 bitIndex; |
|
2269 TInt ret = BitByteIndices(byteIndex, bitIndex, i); |
|
2270 if(ret==KErrNone) |
|
2271 { |
|
2272 if((*this)[byteIndex] & 1<<bitIndex) |
|
2273 { |
|
2274 bitCounter++; |
|
2275 } |
|
2276 } |
|
2277 } |
|
2278 return bitCounter; |
|
2279 } |
|
2280 |
|
2281 |
|
2282 |
|
2283 // local device |
|
2284 |
|
2285 /** |
|
2286 Constructor |
|
2287 */ |
|
2288 EXPORT_C TBTLocalDevice::TBTLocalDevice() |
|
2289 :iSetMask(0), iSimpleSettings(0) |
|
2290 //NB Zeroing iSimpleSettings is not strictly necessary but helps with debugging. |
|
2291 { |
|
2292 } |
|
2293 |
|
2294 /** |
|
2295 Get the address of the local device. |
|
2296 @return Address of local device |
|
2297 */ |
|
2298 EXPORT_C const TBTDevAddr& TBTLocalDevice::Address() const |
|
2299 { |
|
2300 return iAddress; |
|
2301 } |
|
2302 |
|
2303 /** |
|
2304 Get the device class. |
|
2305 @return DeviceClass (as uint32) |
|
2306 @see TBTDeviceClass constructor |
|
2307 */ |
|
2308 EXPORT_C TUint32 TBTLocalDevice::DeviceClass() const |
|
2309 { |
|
2310 return iCod; |
|
2311 } |
|
2312 |
|
2313 /** |
|
2314 Get the device name. |
|
2315 @return name of local device |
|
2316 */ |
|
2317 EXPORT_C const TDesC8& TBTLocalDevice::DeviceName() const |
|
2318 { |
|
2319 return iLocalName; |
|
2320 } |
|
2321 |
|
2322 /** |
|
2323 Get the scanning mode. |
|
2324 @return the scanning of the local device |
|
2325 */ |
|
2326 EXPORT_C THCIScanEnable TBTLocalDevice::ScanEnable() const |
|
2327 { |
|
2328 return iScanEnable; |
|
2329 } |
|
2330 |
|
2331 /** |
|
2332 Get the limited discoverable mode. |
|
2333 @return ETrue if local device is limited discoverable, otherwise EFalse |
|
2334 */ |
|
2335 EXPORT_C TBool TBTLocalDevice::LimitedDiscoverable() const |
|
2336 { |
|
2337 return iLimitedDiscoverable; |
|
2338 } |
|
2339 |
|
2340 /** |
|
2341 Get the power setting. |
|
2342 @return The power setting of the local device |
|
2343 @released |
|
2344 */ |
|
2345 EXPORT_C TUint8 TBTLocalDevice::PowerSetting() const |
|
2346 { |
|
2347 return iPowerSetting; |
|
2348 } |
|
2349 |
|
2350 /** |
|
2351 Get the AFH channel assessment mode. |
|
2352 @return ETrue if local device has AFHChannelModeAssessment switched on (i.e. available for use), otherwise EFalse |
|
2353 */ |
|
2354 EXPORT_C TBool TBTLocalDevice::AFHChannelAssessmentMode() const |
|
2355 { |
|
2356 return (iSimpleSettings & EAFHChannelAssessmentModeValue)?ETrue:EFalse; |
|
2357 } |
|
2358 |
|
2359 /** |
|
2360 Get the setting for whether to accept all incoming connections or |
|
2361 just those from paired devices. Note this is in fact a setting in the stack not the controller. |
|
2362 @return ETrue if local device is set only to accept incoming connections from paired devices, otherwise EFalse |
|
2363 */ |
|
2364 EXPORT_C TBool TBTLocalDevice::AcceptPairedOnlyMode() const |
|
2365 { |
|
2366 return (iSimpleSettings & EAcceptPairedOnlyModeValue)?ETrue:EFalse; |
|
2367 } |
|
2368 |
|
2369 /** |
|
2370 Set the device address. |
|
2371 @param aAddr the local device address |
|
2372 */ |
|
2373 EXPORT_C void TBTLocalDevice::SetAddress(const TBTDevAddr& aAddr) |
|
2374 { |
|
2375 iAddress = aAddr; |
|
2376 iSetMask |= EAddress; |
|
2377 } |
|
2378 |
|
2379 /** |
|
2380 Set the device class. |
|
2381 @param aCod the local device class |
|
2382 */ |
|
2383 EXPORT_C void TBTLocalDevice::SetDeviceClass(TUint32 aCod) |
|
2384 { |
|
2385 iCod = aCod; |
|
2386 iSetMask |= ECoD; |
|
2387 } |
|
2388 |
|
2389 /** |
|
2390 Set the device name. |
|
2391 @param aName the local device name |
|
2392 */ |
|
2393 EXPORT_C void TBTLocalDevice::SetDeviceName(const TDesC8& aName) |
|
2394 { |
|
2395 iLocalName = aName; |
|
2396 iSetMask |= EDeviceName; |
|
2397 } |
|
2398 |
|
2399 /** |
|
2400 Enable local device scanning. |
|
2401 @param aEnable the local device scanning |
|
2402 */ |
|
2403 EXPORT_C void TBTLocalDevice::SetScanEnable(THCIScanEnable aEnable) |
|
2404 { |
|
2405 iScanEnable = aEnable; |
|
2406 iSetMask |= EScanEnable; |
|
2407 } |
|
2408 |
|
2409 /** |
|
2410 Set limited discoverable mode. |
|
2411 @param aOn the local device limited discoverable-ness |
|
2412 */ |
|
2413 EXPORT_C void TBTLocalDevice::SetLimitedDiscoverable(TBool aOn) |
|
2414 { |
|
2415 iLimitedDiscoverable = aOn; |
|
2416 iSetMask |= ELimitedDiscoverable; |
|
2417 } |
|
2418 |
|
2419 /** |
|
2420 Set the power setting. |
|
2421 @param aPowerSetting the local device power setting |
|
2422 */ |
|
2423 EXPORT_C void TBTLocalDevice::SetPowerSetting(TUint8 aPowerSetting) |
|
2424 { |
|
2425 iPowerSetting = aPowerSetting; |
|
2426 iSetMask |= EPowerSetting; |
|
2427 } |
|
2428 |
|
2429 /** |
|
2430 Set the AFH channel assessment mode. |
|
2431 @param aOn the local device channel assessment mode is switched on (available for use) |
|
2432 */ |
|
2433 EXPORT_C void TBTLocalDevice::SetAFHChannelAssessmentMode(TBool aOn) |
|
2434 { |
|
2435 if(aOn) |
|
2436 { |
|
2437 iSimpleSettings |= EAFHChannelAssessmentModeValue; |
|
2438 } |
|
2439 else |
|
2440 { |
|
2441 iSimpleSettings &= ~EAFHChannelAssessmentModeValue; |
|
2442 } |
|
2443 |
|
2444 iSetMask |= EAFHChannelAssessmentMode; |
|
2445 } |
|
2446 |
|
2447 /** |
|
2448 Set the paired device only mode. This is a stack setting which makes |
|
2449 the decision as to whether to accept connection requests ONLY from |
|
2450 paired devices (rejecting connection requests from unpaired devices). |
|
2451 @param aOn the local stack will ONLY accept connection requests from paired devices |
|
2452 */ |
|
2453 EXPORT_C void TBTLocalDevice::SetAcceptPairedOnlyMode(TBool aOn) |
|
2454 { |
|
2455 if(aOn) |
|
2456 { |
|
2457 iSimpleSettings |= EAcceptPairedOnlyModeValue; |
|
2458 } |
|
2459 else |
|
2460 { |
|
2461 iSimpleSettings &= ~EAcceptPairedOnlyModeValue; |
|
2462 } |
|
2463 |
|
2464 iSetMask |= EAcceptPairedOnlyMode; |
|
2465 } |
|
2466 |
|
2467 /** |
|
2468 Denotes whether the address has been set. |
|
2469 @return ETrue if Address has been set |
|
2470 */ |
|
2471 EXPORT_C TBool TBTLocalDevice::IsValidAddress() const |
|
2472 { |
|
2473 return (iSetMask & EAddress); |
|
2474 } |
|
2475 |
|
2476 /** |
|
2477 Denotes whether the device class has been set. |
|
2478 @return ETrue if DeviceClass has been set |
|
2479 */ |
|
2480 EXPORT_C TBool TBTLocalDevice::IsValidDeviceClass() const |
|
2481 { |
|
2482 return (iSetMask & ECoD); |
|
2483 } |
|
2484 |
|
2485 /** |
|
2486 Denotes whether the device name has been set. |
|
2487 @return ETrue if DeviceName has been set |
|
2488 */ |
|
2489 EXPORT_C TBool TBTLocalDevice::IsValidDeviceName() const |
|
2490 { |
|
2491 return (iSetMask & EDeviceName); |
|
2492 } |
|
2493 |
|
2494 /** |
|
2495 Denotes whether the scan enable has been set. |
|
2496 @return ETrue if ScanEnable has been set |
|
2497 */ |
|
2498 EXPORT_C TBool TBTLocalDevice::IsValidScanEnable() const |
|
2499 { |
|
2500 return (iSetMask & EScanEnable); |
|
2501 } |
|
2502 |
|
2503 /** |
|
2504 Denotes whether the limited discoverable mode has been set. |
|
2505 @return ETrue if LimitedDiscoverble has been set |
|
2506 */ |
|
2507 EXPORT_C TBool TBTLocalDevice::IsValidLimitedDiscoverable() const |
|
2508 { |
|
2509 return (iSetMask & ELimitedDiscoverable); |
|
2510 } |
|
2511 |
|
2512 /** |
|
2513 Denotes whether the power setting has been set. |
|
2514 @return ETrue if Power setting has been set |
|
2515 */ |
|
2516 EXPORT_C TBool TBTLocalDevice::IsValidPowerSetting() const |
|
2517 { |
|
2518 return (iSetMask & EPowerSetting); |
|
2519 } |
|
2520 |
|
2521 /** |
|
2522 Denotes whether the AFH channel assessment mode has been set. |
|
2523 @return ETrue if AFH channel assessment mode has been set |
|
2524 */ |
|
2525 EXPORT_C TBool TBTLocalDevice::IsValidAFHChannelAssessmentMode() const |
|
2526 { |
|
2527 return (iSetMask & EAFHChannelAssessmentMode); |
|
2528 } |
|
2529 |
|
2530 /** |
|
2531 Denotes whether "Accept Paired Only Mode" has been set. |
|
2532 @return ETrue if "Accept Paired Only Mode" has been set |
|
2533 */ |
|
2534 EXPORT_C TBool TBTLocalDevice::IsValidAcceptPairedOnlyMode() const |
|
2535 { |
|
2536 return (iSetMask & EAcceptPairedOnlyMode); |
|
2537 } |
|
2538 |