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.Arrays;
28 import java.util.EnumSet;
31 * OcProvisionig represents functions corresponding to the provisioing of
34 public class OcProvisioning {
37 * Method to Intialize Provisioning Manager.This will load the provisioning
38 * Manager's persistent database.
40 * @param dbPath dbPath file path of the sqlite3 db.
43 public static native void provisionInit(String dbPath) throws OcException;
46 * Method to Discover un-owned devices in its subnet.Un-owned devices need
47 * to be owned by calling ownershipTransferCBdata.
49 * @param timeout Timeout in sec.Time to listen for responses before
50 * returining the Array.
51 * @return Array of OcSecureResource class objects.
54 public static List<OcSecureResource> discoverUnownedDevices(int timeout) throws OcException {
55 return Arrays.asList(OcProvisioning.discoverUnownedDevices1(timeout));
57 private static native OcSecureResource[] discoverUnownedDevices1(int timeout) throws OcException;
60 * Method to Discover owned devices in its subnet.
62 * @param timeout Timeout in sec.Time to listen for responses before
63 * returining the Array.
64 * @return Array of OcSecureResource class objects.
67 public static List<OcSecureResource> discoverOwnedDevices(int timeout) throws OcException {
68 return Arrays.asList(OcProvisioning.discoverOwnedDevices1(timeout));
70 private static native OcSecureResource[] discoverOwnedDevices1(int timeout) throws OcException;
73 * API for registering Ownership transfer methods for a particular
76 * @param type OxmType ownership transfer type.
79 public static void SetownershipTransferCBdata(OxmType type,
80 PinCallbackListener pinCallbackListener) throws OcException
82 OcProvisioning.ownershipTransferCBdata(type.getValue(), pinCallbackListener);
85 private static native void ownershipTransferCBdata(int oxmType, PinCallbackListener pinCallbackListener);
87 public static interface PinCallbackListener {
88 public String pinCallbackListener();
92 * Server API to set Callback for Displaying stack generated PIN.
94 * @param DisplayPinListener Pin callback Listener to be registered.
97 public static native void setDisplayPinListener(DisplayPinListener displayPinListener)
100 public static interface DisplayPinListener {
101 public void displayPinListener(String Pin);
105 * API to Set callback for displaying verifNum in verified Just-Works.
107 *@param DisplayNumListener callback Listener to be registered for
108 displaying VerifyNUm.
111 public static native void setDisplayNumListener(
112 DisplayNumListener displayNumListener) throws OcException;
114 public static interface DisplayNumListener {
115 public int displayNumListener(String verifyNum);
119 * API to unregister DisplayNumListener Listener
121 *@return 0 on success, 1 on failure
124 public static native int unsetDisplayNumListener() throws OcException;
127 * API to Set callback for getting user confirmation in verified
130 *@param ConfirmNumListener callback Listener to be registered for getting user confirmation.
133 public static native void setConfirmNumListener(ConfirmNumListener
134 confirmNumListener) throws OcException;
136 public static interface ConfirmNumListener {
137 public int confirmNumListener();
141 * API to unregister ConfirmMutualVerifyNum Listener
143 *@return 0 on success, 1 on failure
146 public static native int unsetConfirmNumListener() throws OcException;
149 * API to set options for Mutual Verified Just-works
150 * Default is for both screen PIN display and get user confirmation.
153 public static int setMVJustWorksOptions(EnumSet<MVJustWorksOptionMask> optionMask) throws OcException {
155 int optionMaskInt = 0;
157 for (MVJustWorksOptionMask ops : MVJustWorksOptionMask.values()) {
158 if (optionMask.contains(ops))
159 optionMaskInt |= ops.getValue();
161 return setMVJustWorksOptions0(optionMaskInt);
164 private static native int setMVJustWorksOptions0(int optionsMask) throws OcException;
167 * Method to get Array of owned and un-owned devices in the current subnet.
169 * @param timeout timeout in sec for the API to return.
170 * @retrun Array of OcSecureResource class objects.
172 * @throws OcException
174 public static List<OcSecureResource> getDeviceStatusList(int timeout) throws OcException {
175 return Arrays.asList(OcProvisioning.getDeviceStatusList1(timeout));
177 private static native OcSecureResource[] getDeviceStatusList1(int timeout) throws OcException;
180 * Method to save the Trust certificate chain to SVR.
182 * @param byte[] trustCertChain
183 * @param EncodingType encodingType
184 * @throws OcException
186 public static int saveTrustCertChain(byte[] trustCertChain, EncodingType encodingType) throws OcException {
187 return saveTrustCertChain1(trustCertChain,encodingType.getValue());
189 private static native int saveTrustCertChain1(byte[] trustCertChain, int encodingType)
193 * Method to save pin type.
195 * @param pinSize Byte Len of Random pin.
196 * @param pinType Enumset of pin, see PinType for enums
197 * @throws OcException
199 public static int setPinType(int pinSize, EnumSet<PinType> pinType) throws OcException {
203 for (PinType ops : PinType.values()) {
204 if (pinType.contains(ops))
205 pinTypeInt |= ops.getValue();
207 return setPinType0(pinSize, pinTypeInt);
209 private static native int setPinType0(int pinSize, int pinType) throws OcException;
212 * Method to save the seed value to generate device UUID
214 * @param seed buffer of seed value
215 * @throws OcException
217 public static int setDeviceIdSeed(byte[] seed) throws OcException {
218 return setDeviceIdSeed1(seed);
220 private static native int setDeviceIdSeed1(byte[] seed)
224 * API to save ACL, having multiple ACE's
229 public static native void saveACL(Object acl) throws OcException;
232 * API to do self ownership transfer.
236 public static native void doSelfOwnershiptransfer() throws OcException;