Merge "Merge 'security-basecamp' branch into master with CBOR"
[platform/upstream/iotivity.git] / android / android_api / base / src / main / java / org / iotivity / base / OcConnectivityFlags.java
1 /*
2  * //******************************************************************
3  * //
4  * // Copyright 2015 Intel Corporation.
5  * //
6  * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7  * //
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
11  * //
12  * //      http://www.apache.org/licenses/LICENSE-2.0
13  * //
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.
19  * //
20  * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21  */
22
23 package org.iotivity.base;
24
25 import java.security.InvalidParameterException;
26 public enum OcConnectivityFlags {
27     OC_DEFAULT_FLAGS (0),
28     // Insecure transport is the default (subject to change)
29     OC_FLAG_SECURE     (1 << 4), // secure the transport path
30
31     // IPv4 & IPv6 autoselection is the default
32     OC_IP_USE_V6       (1 << 5), // IP adapter only
33     OC_IP_USE_V4       (1 << 6), // IP adapter only
34
35     // Link-Local multicast is the default multicast scope for IPv6.
36     // These are placed here to correspond to the IPv6 address bits.
37     OC_SCOPE_INTERFACE (0x1), // IPv6 Interface-Local scope (loopback)
38     OC_SCOPE_LINK      (0x2), // IPv6 Link-Local scope (default)
39     OC_SCOPE_REALM     (0x3), // IPv6 Realm-Local scope
40     OC_SCOPE_ADMIN     (0x4), // IPv6 Admin-Local scope
41     OC_SCOPE_SITE      (0x5), // IPv6 Site-Local scope
42     OC_SCOPE_ORG       (0x8), // IPv6 Organization-Local scope
43     OC_SCOPE_GLOBAL    (0xE), // IPv6 Global scope
44     ;
45     private int value;
46
47     private OcConnectivityFlags(int value) {
48         this.value = value;
49     }
50
51     public int getValue() {
52         return this.value;
53     }
54
55     public static OcConnectivityFlags get(int val) {
56         for (OcConnectivityType v : OcConnectivityType.values()) {
57             for (OcConnectivityFlags f : OcConnectivityFlags.values()) {
58                 int value = v.getValue() + f.getValue();
59                 if (value == val)
60                     return f;
61             }
62         }
63         throw new InvalidParameterException("Unexpected OcConnectivityFlags value:" + val);
64     }
65 }