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 send ACL information to resource.
96 * @param ProvisionAclListener Callback function, which will be called after
97 * completion of removing device.
100 public native void provisionACL(Object acl, ProvisionAclListener provisionACLListener)
105 * Method provisions credentials between two devices and ACLs for the devices who
108 * @param EnumSet<CredType> OR'ed Cred Types
109 * @param KeySize keySize
110 * @param Object First acl
111 * @param Object Second device
112 * @param Object Second acl
113 * @param ProvisionPairwiseDevicesListener Callback function, which will be called after
114 * completion of removing device.
115 * @throws OcException
117 public void provisionPairwiseDevices(EnumSet<CredType> credTypeSet, KeySize keysize, Object acl1,
118 Object device2, Object acl2,
119 ProvisionPairwiseDevicesListener provisionPairwiseDevicesListener) throws OcException {
122 for (CredType credType : CredType.values()) {
123 if (credTypeSet.contains(credType))
124 credTypeInt |= credType.getValue();
126 this.provisionPairwiseDevices1(credTypeInt, keysize.getValue(), acl1, device2,
127 acl2, provisionPairwiseDevicesListener);
129 private native void provisionPairwiseDevices1(int type, int keySize, Object acl1,
130 Object device2, Object acl2,
131 ProvisionPairwiseDevicesListener provisionPairwiseDevicesListener) throws OcException;
134 * Method to configure resource for direct pairing
136 * @param pin pin number
137 * @param pdacls Array of Device Pairing Access Control List
138 * @param type List of supported OcPrmType
139 * @param edp enable (1) / disable (0)
140 * @param ProvisionDirectPairing Callback function, which will be called after completion
142 * @throws OcException
145 public void doProvisionDirectPairing(String pin, OicSecPdAcl[] pdacls, List<OcPrmType> type,
146 boolean edp , ProvisionDirectPairingListener provisionDirectPairingListener)
149 int[] typeArray = new int[type.size()];
151 for (OcPrmType ocPrmType:type) {
152 typeArray[i++] = ocPrmType.getValue();
155 this.provisionDirectPairing(pin, pdacls, typeArray, (edp?1:0),
156 provisionDirectPairingListener);
159 private native void provisionDirectPairing(String pin, OicSecPdAcl[] pdacls, int[] type,
160 int edp , ProvisionDirectPairingListener provisionDirectPairingListener)
164 * provisionDirectPairingListener can be registered with doOwnershipTransfer
166 * Listener notified asynchronously.
168 public interface ProvisionDirectPairingListener {
169 public void provisionDirectPairingListener(List<ProvisionResult> provisionResultList,
174 * doOwnershipTransferListener can be registered with doOwnershipTransfer
176 * Listener notified asynchronously.
178 public interface DoOwnershipTransferListener {
179 public void doOwnershipTransferListener(List<ProvisionResult> provisionResultList,
184 * removeDeviceListener can be registered with removeDeviceListener
186 * Listener notified asynchronously.
188 public interface RemoveDeviceListener {
189 public void removeDeviceListener(List<ProvisionResult> provisionResultList,
194 * unlinkDevicesListener can be registered with unlinkDevicesListener
196 * Listener notified asynchronously.
198 public interface UnlinkDevicesListener {
199 public void unlinkDevicesListener(List<ProvisionResult> provisionResultList,
204 * provisionCredentialsListener can be registered with provisionCredentialsListener
206 * Listener notified asynchronously.
208 public interface ProvisionCredentialsListener {
209 public void provisionCredentialsListener(List<ProvisionResult> provisionResultList,
214 * provisionAclListener can be registered with provisionAclListener
216 * Listener notified asynchronously.
218 public interface ProvisionAclListener {
219 public void provisionAclListener(List<ProvisionResult> provisionResultList,
224 * provisionPairwiseDevicesListener can be registered with provisionPairwiseDevicesListener
226 * Listener notified asynchronously.
228 public interface ProvisionPairwiseDevicesListener {
229 public void provisionPairwiseDevicesListener(List<ProvisionResult> provisionResultList,
233 /** Method to get List of device ID of devices linked with invoking device.
235 * @return Sring List List of device id's of linked devices.
237 public native List<String> getLinkedDevices();
240 * Method to get IP address of sercure discovered device.
241 * @return Stringified IP address.
243 public native String getIpAddr();
246 * Method to get device id of a device.
247 * @return Device ID of the selected device.
249 public native String getDeviceID();
252 * Method to get device status (ON/OFF) of a device.
256 public DeviceStatus getDeviceStatus() throws OcException {
257 return DeviceStatus.convertDeviceStatus(this.deviceStatus());
259 public native int deviceStatus() throws OcException;
262 * Method to get device ownership (OWNED/UNOWNED) status.
263 * @return OWNED/UNOWNED
266 public OwnedStatus getOwnedStatus() throws OcException {
267 return OwnedStatus.convertOwnedStatus(this.ownedStatus());
269 public native int ownedStatus() throws OcException;
272 protected void finalize() throws Throwable {
277 private native void dispose();
279 private long mNativeHandle;