Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
SMPPairingState.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 * SMP Pairing Process state definition
29 * <pre>
30 * Vol 3, Part H (SM): APPENDIX C MESSAGE SEQUENCE CHARTS
31 * </pre>
32 * <p>
33 * See {@link #get(byte)} for its native integer mapping.
34 * </p>
35 * @see PairingMode
36 * @since 2.1.0
37 */
38public enum SMPPairingState {
39 /** No pairing in process. Current {@link PairingMode} shall be {@link PairingMode#NONE}. */
40 NONE((byte)0),
41
42 /** Pairing failed. Current {@link PairingMode} shall be {@link PairingMode#NONE}. */
43 FAILED((byte)1),
44
45 /**
46 * Phase 0: Pairing requested by responding (slave) device via SMPSecurityReqMsg.<br>
47 * Signals initiating (host) device to start the Pairing Feature Exchange.<br>
48 * Current {@link PairingMode} shall be {@link PairingMode#NEGOTIATING}.
49 */
51
52 /**
53 * Phase 1: Pairing requested by initiating (master) device via SMPPairingMsg.<br>
54 * Starts the Pairing Feature Exchange.<br>
55 * Current {@link PairingMode} shall be {@link PairingMode#NEGOTIATING}.
56 */
58
59 /**
60 * Phase 1: Pairing responded by responding (slave) device via SMPPairingMsg.<br>
61 * Completes the Pairing Feature Exchange. Optional user input shall be given for Phase 2.<br>
62 * Current {@link PairingMode} shall be set to a definitive value.
63 */
65
66 /** Phase 2: Authentication (MITM) PASSKEY expected, see {@link PairingMode#PASSKEY_ENTRY_ini} */
68 /** Phase 2: Authentication (MITM) Numeric Comparison Reply expected, see {@link PairingMode#NUMERIC_COMPARE_ini} */
70 /**
71 * Phase 2: Authentication (MITM) PASSKEY has been produced (this device is responder, peripheral GATT server) and shall be displayed for the remote device, see {@link PairingMode#NUMERIC_COMPARE_ini}.<br>
72 * User application shall display {@link BTDevice#getResponderSMPPassKeyString()}.
73 */
75 /** Phase 2: Authentication (MITM) OOB data expected, see {@link PairingMode#OUT_OF_BAND} */
76 OOB_EXPECTED((byte)8),
77
78 /** Phase 3: Key & value distribution started after SMPPairConfirmMsg or SMPPairPubKeyMsg (LE Secure Connection) exchange between initiating (master) and responding (slave) device. */
80
81 /**
82 * Phase 3: Key & value distribution completed by responding (slave) device sending SMPIdentInfoMsg (#1) , SMPIdentAddrInfoMsg (#2) or SMPSignInfoMsg (#3),<br>
83 * depending on the key distribution field SMPKeyDistFormat SMPPairingMsg::getInitKeyDist() and SMPPairingMsg::getRespKeyDist().
84 * <p>
85 * The link is assumed to be encrypted from here on and {@link AdapterStatusListener#deviceReady(BluetoothDevice, long)} gets called on all listener.
86 * </p>
87 */
88 COMPLETED((byte)10);
89
90 public final byte value;
91
92 /**
93 * Maps the specified name to a constant of {@link SMPPairingState}.
94 * <p>
95 * Implementation simply returns {@link #valueOf(String)}.
96 * This maps the constant names itself to their respective constant.
97 * </p>
98 * @param name the string name to be mapped to a constant of this enum type.
99 * @return the corresponding constant of this enum type.
100 * @throws IllegalArgumentException if the specified name can't be mapped to a constant of this enum type
101 * as described above.
102 */
103 public static SMPPairingState get(final String name) throws IllegalArgumentException {
104 return valueOf(name);
105 }
106
107 /**
108 * Maps the specified integer value to a constant of {@link SMPPairingState}.
109 * @param value the integer value to be mapped to a constant of this enum type.
110 * @return the corresponding constant of this enum type, using {@link #NONE} if not supported.
111 */
112 public static SMPPairingState get(final byte value) {
113 switch(value) {
114 case (byte) 0x01: return FAILED;
115 case (byte) 0x02: return REQUESTED_BY_RESPONDER;
116 case (byte) 0x03: return FEATURE_EXCHANGE_STARTED;
117 case (byte) 0x04: return FEATURE_EXCHANGE_COMPLETED;
118 case (byte) 0x05: return PASSKEY_EXPECTED;
119 case (byte) 0x06: return NUMERIC_COMPARE_EXPECTED;
120 case (byte) 0x07: return PASSKEY_NOTIFY;
121 case (byte) 0x08: return OOB_EXPECTED;
122 case (byte) 0x09: return KEY_DISTRIBUTION;
123 case (byte) 0x0a: return COMPLETED;
124 default: return NONE;
125 }
126 }
127
128 SMPPairingState(final byte v) {
129 value = v;
130 }
131}
SMP Pairing Process state definition.
NONE
No pairing in process.
FEATURE_EXCHANGE_COMPLETED
Phase 1: Pairing responded by responding (slave) device via SMPPairingMsg.
REQUESTED_BY_RESPONDER
Phase 0: Pairing requested by responding (slave) device via SMPSecurityReqMsg.
OOB_EXPECTED
Phase 2: Authentication (MITM) OOB data expected, see PairingMode#OUT_OF_BAND.
PASSKEY_EXPECTED
Phase 2: Authentication (MITM) PASSKEY expected, see PairingMode#PASSKEY_ENTRY_ini.
COMPLETED
Phase 3: Key & value distribution completed by responding (slave) device sending SMPIdentInfoMsg (#1)...
NUMERIC_COMPARE_EXPECTED
Phase 2: Authentication (MITM) Numeric Comparison Reply expected, see PairingMode#NUMERIC_COMPARE_ini...
KEY_DISTRIBUTION
Phase 3: Key & value distribution started after SMPPairConfirmMsg or SMPPairPubKeyMsg (LE Secure Conn...
FEATURE_EXCHANGE_STARTED
Phase 1: Pairing requested by initiating (master) device via SMPPairingMsg.
PASSKEY_NOTIFY
Phase 2: Authentication (MITM) PASSKEY has been produced (this device is responder,...