2 *******************************************************************
4 * Copyright 2015 Samsung Electronics All Rights Reserved.
6 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
20 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
23 package org.iotivity.base;
25 import java.util.List;
26 import java.util.EnumSet;
29 public class OcSecureResource {
31 private OcSecureResource(long nativeHandle) {
32 this.mNativeHandle = nativeHandle;
36 * Method to Start Ownership Transfer of an un-owned device.
38 * @param DoOwnershipTransferListener Callback function, which will be called after
39 * completion of ownership Transfer.
42 public native void doOwnershipTransfer(DoOwnershipTransferListener doOwnershipTransferListener)
46 * Method removes device credential from all devices in subnet
49 * @param RemoveDeviceListener Callback function, which will be called after
50 * completion of removing device.
53 public native void removeDevice(int timeout, RemoveDeviceListener removeDeviceListener)
57 * Method removes the credential & relationship between the two devices.
59 * @param jobject Second device
60 * @param UnlinkDevicesListener Callback function, which will be called after
61 * completion of removing device.
64 public native void unlinkDevices(Object device2, UnlinkDevicesListener unlinkDevicesListener)
68 * Method removes the credential & relationship between the two devices.
70 * @param EnumSet<CredType> OR'ed Cred Types
71 * @param KeySize keySize
72 * @param Object Second device
73 * @param ProvisionCredentialsListener Callback function, which will be called after
74 * completion of removing device.
77 public void provisionCredentials(EnumSet<CredType> credTypeSet, KeySize keysize, Object device2,
78 ProvisionCredentialsListener provisionCredentialsListener) throws OcException {
81 for (CredType credType : CredType.values()) {
82 if (credTypeSet.contains(credType))
83 credTypeInt |= credType.getValue();
85 this.provisionCredentials1(credTypeInt, keysize.getValue(),
86 device2, provisionCredentialsListener);
88 private native void provisionCredentials1(int type, int keySize, Object device2,
89 ProvisionCredentialsListener provisionCredentialsListener)
93 * Method to provision the Trust certificate chain to secured device.
95 * @param EnumSet<CredType> OR'ed Cred Types
97 * @param ProvisionTrustCertChainListener Callback function, which will be called after
98 * proviosion trust certificate chain.
101 public void provisionTrustCertChain(EnumSet<CredType> credTypeSet, int credId,
102 ProvisionTrustCertChainListener provisionTrustCertChainListener) throws OcException {
105 for (CredType credType : CredType.values()) {
106 if (credTypeSet.contains(credType))
107 credTypeInt |= credType.getValue();
109 this.provisionTrustCertChain1(credTypeInt, credId,
110 provisionTrustCertChainListener);
112 private native void provisionTrustCertChain1(int credType, int credId,
113 ProvisionTrustCertChainListener provisionTrustCertChainListener)
117 * Method send ACL information to resource.
120 * @param ProvisionAclListener Callback function, which will be called after
121 * completion of removing device.
122 * @throws OcException
124 public native void provisionACL(Object acl, ProvisionAclListener provisionACLListener)
129 * Method provisions credentials between two devices and ACLs for the devices who
132 * @param EnumSet<CredType> OR'ed Cred Types
133 * @param KeySize keySize
134 * @param Object First acl
135 * @param Object Second device
136 * @param Object Second acl
137 * @param ProvisionPairwiseDevicesListener Callback function, which will be called after
138 * completion of removing device.
139 * @throws OcException
141 public void provisionPairwiseDevices(EnumSet<CredType> credTypeSet, KeySize keysize, Object acl1,
142 Object device2, Object acl2,
143 ProvisionPairwiseDevicesListener provisionPairwiseDevicesListener) throws OcException {
146 for (CredType credType : CredType.values()) {
147 if (credTypeSet.contains(credType))
148 credTypeInt |= credType.getValue();
150 this.provisionPairwiseDevices1(credTypeInt, keysize.getValue(), acl1, device2,
151 acl2, provisionPairwiseDevicesListener);
153 private native void provisionPairwiseDevices1(int type, int keySize, Object acl1,
154 Object device2, Object acl2,
155 ProvisionPairwiseDevicesListener provisionPairwiseDevicesListener) throws OcException;
158 * Method to configure resource for direct pairing
160 * @param pin pin number
161 * @param pdacls Array of Device Pairing Access Control List
162 * @param type List of supported OcPrmType
163 * @param edp enable (1) / disable (0)
164 * @param ProvisionDirectPairing Callback function, which will be called after completion
166 * @throws OcException
169 public void doProvisionDirectPairing(String pin, OicSecPdAcl[] pdacls, List<OcPrmType> type,
170 boolean edp , ProvisionDirectPairingListener provisionDirectPairingListener)
173 int[] typeArray = new int[type.size()];
175 for (OcPrmType ocPrmType:type) {
176 typeArray[i++] = ocPrmType.getValue();
179 this.provisionDirectPairing(pin, pdacls, typeArray, (edp?1:0),
180 provisionDirectPairingListener);
183 private native void provisionDirectPairing(String pin, OicSecPdAcl[] pdacls, int[] type,
184 int edp , ProvisionDirectPairingListener provisionDirectPairingListener)
188 * provisionDirectPairingListener can be registered with doOwnershipTransfer
190 * Listener notified asynchronously.
192 public interface ProvisionDirectPairingListener {
193 public void provisionDirectPairingListener(List<ProvisionResult> provisionResultList,
198 * doOwnershipTransferListener can be registered with doOwnershipTransfer
200 * Listener notified asynchronously.
202 public interface DoOwnershipTransferListener {
203 public void doOwnershipTransferListener(List<ProvisionResult> provisionResultList,
208 * removeDeviceListener can be registered with removeDeviceListener
210 * Listener notified asynchronously.
212 public interface RemoveDeviceListener {
213 public void removeDeviceListener(List<ProvisionResult> provisionResultList,
218 * unlinkDevicesListener can be registered with unlinkDevicesListener
220 * Listener notified asynchronously.
222 public interface UnlinkDevicesListener {
223 public void unlinkDevicesListener(List<ProvisionResult> provisionResultList,
228 * provisionCredentialsListener can be registered with provisionCredentialsListener
230 * Listener notified asynchronously.
232 public interface ProvisionCredentialsListener {
233 public void provisionCredentialsListener(List<ProvisionResult> provisionResultList,
238 * provisionTrustCertChainListener can be registered with ProvisionTrustCertChainListener
240 * Listener notified asynchronously.
242 public interface ProvisionTrustCertChainListener {
243 public void provisionTrustCertChainListener(List<ProvisionResult> provisionResultList,
248 * provisionAclListener can be registered with provisionAclListener
250 * Listener notified asynchronously.
252 public interface ProvisionAclListener {
253 public void provisionAclListener(List<ProvisionResult> provisionResultList,
258 * provisionPairwiseDevicesListener can be registered with provisionPairwiseDevicesListener
260 * Listener notified asynchronously.
262 public interface ProvisionPairwiseDevicesListener {
263 public void provisionPairwiseDevicesListener(List<ProvisionResult> provisionResultList,
267 /** Method to get List of device ID of devices linked with invoking device.
269 * @return Sring List List of device id's of linked devices.
271 public native List<String> getLinkedDevices();
274 * Method to get IP address of sercure discovered device.
275 * @return Stringified IP address.
277 public native String getIpAddr();
280 * Method to get device id of a device.
281 * @return Device ID of the selected device.
283 public native String getDeviceID();
286 * Method to get device status (ON/OFF) of a device.
290 public DeviceStatus getDeviceStatus() throws OcException {
291 return DeviceStatus.convertDeviceStatus(this.deviceStatus());
293 public native int deviceStatus() throws OcException;
296 * Method to get device ownership (OWNED/UNOWNED) status.
297 * @return OWNED/UNOWNED
300 public OwnedStatus getOwnedStatus() throws OcException {
301 return OwnedStatus.convertOwnedStatus(this.ownedStatus());
303 public native int ownedStatus() throws OcException;
306 protected void finalize() throws Throwable {
311 private native void dispose();
313 private long mNativeHandle;