|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "bluetoothremotedevice.h" |
|
20 #include "fs_methodcall.h" |
|
21 #include "javajniutils.h" |
|
22 |
|
23 namespace java |
|
24 { |
|
25 namespace bluetooth |
|
26 { |
|
27 |
|
28 /** |
|
29 * Returns ETrue if SecurityId matches. Otherwise returns EFalse |
|
30 */ |
|
31 OS_EXPORT TBool BluetoothRemoteDevice::getSecurityProperty(TInt8 aSecurityId, |
|
32 TInt64 &aRemoteDevAddress) |
|
33 { |
|
34 JELOG2(EJavaBluetooth); |
|
35 RBTRegServ bTRegistryServ; |
|
36 RBTRegistry btRegistry; |
|
37 TBool retVal = EFalse; |
|
38 |
|
39 TBTNamelessDevice device; |
|
40 TInt err = KErrNone; |
|
41 |
|
42 err = bTRegistryServ.Connect(); |
|
43 if (KErrNone != err) |
|
44 return EFalse; |
|
45 |
|
46 err = btRegistry.Open(bTRegistryServ); |
|
47 if (KErrNone != err) |
|
48 return EFalse; |
|
49 |
|
50 err = getRemoteDevice(btRegistry, device, aRemoteDevAddress); |
|
51 |
|
52 if (KErrNone == err) |
|
53 { |
|
54 if (REMOTE_AUTHENTICATED == aSecurityId) |
|
55 { |
|
56 retVal = device.IsPaired(); |
|
57 } |
|
58 else if (device.IsValidGlobalSecurity()) |
|
59 { |
|
60 TBTDeviceSecurity globalSecurity(device.GlobalSecurity()); |
|
61 |
|
62 switch (aSecurityId) |
|
63 { |
|
64 case REMOTE_AUTHORIZED: |
|
65 retVal = !globalSecurity.NoAuthorise() |
|
66 && !globalSecurity.Banned(); |
|
67 break; |
|
68 case REMOTE_ENCRYPT: |
|
69 retVal = globalSecurity.Encrypt(); |
|
70 break; |
|
71 case REMOTE_BANNED: |
|
72 retVal = globalSecurity.Banned(); |
|
73 break; |
|
74 case REMOTE_TRUSTED: |
|
75 retVal = !globalSecurity.Banned() |
|
76 && !globalSecurity.NoAuthenticate() |
|
77 && globalSecurity.NoAuthorise(); |
|
78 break; |
|
79 } |
|
80 } |
|
81 } |
|
82 |
|
83 btRegistry.Close(); |
|
84 bTRegistryServ.Close(); |
|
85 |
|
86 LOG2(EJavaBluetooth, EInfo, |
|
87 "- BluetoothRemoteDevice::getSecurityProperty %d:%d", aSecurityId, |
|
88 retVal); |
|
89 |
|
90 return retVal; |
|
91 } |
|
92 |
|
93 TInt BluetoothRemoteDevice::getRemoteDevice(RBTRegistry& aBtRegistry, |
|
94 TBTNamelessDevice& aDevice, TInt64 &aRemoteDevAddress) |
|
95 { |
|
96 JELOG2(EJavaBluetooth); |
|
97 TRequestStatus status; |
|
98 const TBTDevAddr deviceAddress(aRemoteDevAddress); |
|
99 |
|
100 aDevice.SetAddress(deviceAddress); |
|
101 |
|
102 aBtRegistry.GetDevice(aDevice, status); |
|
103 User::WaitForRequest(status); |
|
104 |
|
105 TInt result = status.Int(); |
|
106 |
|
107 LOG1(EJavaBluetooth, EInfo, "- BluetoothRemoteDevice::getRemoteDevice %d", |
|
108 result); |
|
109 return result; |
|
110 } |
|
111 |
|
112 } //end namespace bluetooth |
|
113 } //end namespace java |