Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
BTSecurityLevel.java
Go to the documentation of this file.
1/**
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2020 Gothel Software e.K.
4 * Copyright (c) 2020 ZAFENA AB
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25package org.direct_bt;
26
27/**
28 * Bluetooth Security Level.
29 * <p>
30 * This BTSecurityLevel is natively compatible
31 * with Linux/BlueZ's BT_SECURITY values 1-4.
32 * </p>
33 * <p>
34 * See {@link #get(byte)} for its native integer mapping.
35 * </p>
36 * @since 2.1.0
37 */
38public enum BTSecurityLevel {
39 /** Security Level not set, value 0. */
40 UNSET ((byte)0),
41 /** No encryption and no authentication. Also known as BT_SECURITY_LOW, value 1. */
42 NONE ((byte)1),
43 /** Encryption and no authentication (no MITM). Also known as BT_SECURITY_MEDIUM, value 2. */
44 ENC_ONLY ((byte)2),
45 /** Encryption and authentication (MITM). Also known as BT_SECURITY_HIGH, value 3. */
46 ENC_AUTH ((byte)3),
47 /** Authenticated Secure Connections. Also known as BT_SECURITY_FIPS, value 4. */
48 ENC_AUTH_FIPS ((byte)4);
49
50 public final byte value;
51
52 /**
53 * Maps the specified name to a constant of BTSecurityLevel.
54 * <p>
55 * Implementation simply returns {@link #valueOf(String)}.
56 * This maps the constant names itself to their respective constant.
57 * </p>
58 * @param name the string name to be mapped to a constant of this enum type.
59 * @return the corresponding constant of this enum type.
60 * @throws IllegalArgumentException if the specified name can't be mapped to a constant of this enum type
61 * as described above.
62 */
63 public static BTSecurityLevel get(final String name) throws IllegalArgumentException {
64 return valueOf(name);
65 }
66
67 /**
68 * Maps the specified integer value to a constant of {@link BTSecurityLevel}.
69 * @param value the integer value to be mapped to a constant of this enum type.
70 * @return the corresponding constant of this enum type, using {@link #UNSET} if not supported.
71 */
72 public static BTSecurityLevel get(final byte value) {
73 switch(value) {
74 case (byte)0x01: return NONE;
75 case (byte)0x02: return ENC_ONLY;
76 case (byte)0x03: return ENC_AUTH;
77 case (byte)0x04: return ENC_AUTH_FIPS;
78 default: return UNSET;
79 }
80 }
81
82 BTSecurityLevel(final byte v) {
83 value = v;
84 }
85}
Bluetooth Security Level.
UNSET
Security Level not set, value 0.
NONE
No encryption and no authentication.
ENC_ONLY
Encryption and no authentication (no MITM).
ENC_AUTH_FIPS
Authenticated Secure Connections.
ENC_AUTH
Encryption and authentication (MITM).