Direct-BT  2.3.1
Direct-BT - Direct Bluetooth Programming.
PairingMode.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  */
25 package org.direct_bt;
26 
27 /**
28  * Bluetooth secure pairing mode
29  * <pre>
30  * BT Core Spec v5.2: Vol 1, Part A, 5 Security Overview
31  * BT Core Spec v5.2: Vol 1, Part A, 5.4 LE SECURITY
32  * BT Core Spec v5.2: Vol 3, Part H (SM): 2.3.5.1 Selecting key generation method Table 2.8
33  * </pre>
34  * <p>
35  * See {@link #get(byte)} for its native integer mapping.
36  * </p>
37  * @see SMPPairingState
38  * @since 2.1.0
39  */
40 public enum PairingMode {
41  /** No pairing mode, implying no secure connections, no encryption and no MITM protection. */
42  NONE ((byte)0),
43  /** Pairing mode in negotiating, i.e. Pairing Feature Exchange in progress. */
44  NEGOTIATING ((byte)1),
45  /** Just Works. Random key exchange with encryption but no MITM protection. */
46  JUST_WORKS ((byte)2),
47  /** Passkey Entry input by initiator. Responder produces and display artifact. A known digit sequence (PIN) must be given as a secret to be validated on the device. Random key exchange with additional secret (PIN) and encryption and MITM protection. */
48  PASSKEY_ENTRY_ini ((byte)3),
49  /** Passkey Entry input by responder. Initiator produces and display artifact. A known digit sequence (PIN) must be given as a secret to be validated on the device. Random key exchange with additional secret (PIN) and encryption and MITM protection. */
50  PASSKEY_ENTRY_res ((byte)4),
51  /** Visual comparison of digit sequence (PIN) input by initiator, shown on both devices. Responder produces and display artifact. Random key exchange with additional secret (PIN) and encryption and MITM protection. */
53  /** Visual comparison of digit sequence (PIN) input by responder, shown on both devices. Initiator produces and displays artifact. Random key exchange with additional secret (PIN) and encryption and MITM protection. */
55  /** Utilizing a second factor secret to be used as a secret, e.g. NFC field. Random key exchange with additional secret (2FA) and encryption and potential MITM protection. */
56  OUT_OF_BAND ((byte)7),
57  /** Reusing encryption keys from previous pairing. */
58  PRE_PAIRED ((byte)8);
59 
60  public final byte value;
61 
62  /**
63  * Maps the specified name to a constant of PairingMode.
64  * <p>
65  * Implementation simply returns {@link #valueOf(String)}.
66  * This maps the constant names itself to their respective constant.
67  * </p>
68  * @param name the string name to be mapped to a constant of this enum type.
69  * @return the corresponding constant of this enum type.
70  * @throws IllegalArgumentException if the specified name can't be mapped to a constant of this enum type
71  * as described above.
72  */
73  public static PairingMode get(final String name) throws IllegalArgumentException {
74  return valueOf(name);
75  }
76 
77  /**
78  * Maps the specified integer value to a constant of {@link PairingMode}.
79  * @param value the integer value to be mapped to a constant of this enum type.
80  * @return the corresponding constant of this enum type, using {@link #NONE} if not supported.
81  */
82  public static PairingMode get(final byte value) {
83  switch(value) {
84  case (byte) 0x01: return NEGOTIATING;
85  case (byte) 0x02: return JUST_WORKS;
86  case (byte) 0x03: return PASSKEY_ENTRY_ini;
87  case (byte) 0x04: return PASSKEY_ENTRY_res;
88  case (byte) 0x05: return NUMERIC_COMPARE_ini;
89  case (byte) 0x06: return NUMERIC_COMPARE_res;
90  case (byte) 0x07: return OUT_OF_BAND;
91  case (byte) 0x08: return PRE_PAIRED;
92  default: return NONE;
93  }
94  }
95 
96  PairingMode(final byte v) {
97  value = v;
98  }
99 }
org.direct_bt.PairingMode.PRE_PAIRED
PRE_PAIRED
Reusing encryption keys from previous pairing.
Definition: PairingMode.java:58
org.direct_bt.PairingMode.JUST_WORKS
JUST_WORKS
Just Works.
Definition: PairingMode.java:46
org.direct_bt.PairingMode.NUMERIC_COMPARE_ini
NUMERIC_COMPARE_ini
Visual comparison of digit sequence (PIN) input by initiator, shown on both devices.
Definition: PairingMode.java:52
org.direct_bt.PairingMode
Bluetooth secure pairing mode.
Definition: PairingMode.java:40
org.direct_bt.PairingMode.PASSKEY_ENTRY_res
PASSKEY_ENTRY_res
Passkey Entry input by responder.
Definition: PairingMode.java:50
org.direct_bt.PairingMode.NONE
NONE
No pairing mode, implying no secure connections, no encryption and no MITM protection.
Definition: PairingMode.java:42
org.direct_bt.PairingMode.PairingMode
PairingMode(final byte v)
Definition: PairingMode.java:96
org.direct_bt.PairingMode.NUMERIC_COMPARE_res
NUMERIC_COMPARE_res
Visual comparison of digit sequence (PIN) input by responder, shown on both devices.
Definition: PairingMode.java:54
org.direct_bt.PairingMode.NEGOTIATING
NEGOTIATING
Pairing mode in negotiating, i.e.
Definition: PairingMode.java:44
org.direct_bt.PairingMode.OUT_OF_BAND
OUT_OF_BAND
Utilizing a second factor secret to be used as a secret, e.g.
Definition: PairingMode.java:56
org.direct_bt.PairingMode.value
final byte value
Definition: PairingMode.java:60
org.direct_bt.PairingMode.PASSKEY_ENTRY_ini
PASSKEY_ENTRY_ini
Passkey Entry input by initiator.
Definition: PairingMode.java:48