]> git.basschouten.com Git - openhab-addons.git/blob
a1186c082a34509e68bac300add0f1ff02b69536
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.bluetooth.bluegiga.internal.eir;
14
15 import java.util.HashMap;
16 import java.util.Map;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19
20 /**
21  * Assigned numbers are used in GAP for inquiry response, EIR data type values, manufacturer-specific data, advertising
22  * data, low energy UUIDs and appearance characteristics, and class of device.
23  *
24  * https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile
25  *
26  * @author Chris Jackson - Initial contribution
27  *
28  */
29 @NonNullByDefault
30 public enum EirDataType {
31     /**
32      * Default unknown value
33      */
34     UNKNOWN(-1),
35     NONE(0),
36
37     EIR_FLAGS(0x01),
38     EIR_SVC_UUID16_INCOMPLETE(0x02),
39     EIR_SVC_UUID16_COMPLETE(0x03),
40     EIR_SVC_UUID32_INCOMPLETE(0x04),
41     EIR_SVC_UUID32_COMPLETE(0x05),
42     EIR_SVC_UUID128_INCOMPLETE(0x06),
43     EIR_SVC_UUID128_COMPLETE(0x07),
44     EIR_NAME_SHORT(0x08),
45     EIR_NAME_LONG(0x09),
46     EIR_TXPOWER(0x0A),
47     EIR_DEVICE_CLASS(0x0D),
48     EIR_SIMPLE_PAIRING_RANDOMIZER(0x0F),
49     EIR_SECMAN_TK_VALUE(0x10),
50     EIR_SECMAN_OOB_FLAGS(0x11),
51     EIR_SLAVEINTERVALRANGE(0x12),
52     EIR_SVC_SOLICIT_UUID16(0x14),
53     EIR_SVC_SOLICIT_UUID128(0x15),
54     EIR_SVC_DATA_UUID16(0x16),
55     EIR_PUBLIC_TARGET_ADDR(0x17),
56     EIR_RANDOM_TARGET_ADDR(0x18),
57     EIR_APPEARANCE(0x19),
58     EIR_ADVERTISING_INTERVAL(0x1A),
59     EIR_LE_DEVICE_ADDRESS(0x1B),
60     EIR_LE_ROLE(0x1C),
61     EIR_SIMPLE_PAIRING_HASH(0x1D),
62     EIR_SVC_SOLICIT_UUID32(0x1F),
63     EIR_SVC_DATA_UUID32(0x20),
64     EIR_SVC_DATA_UUID128(0x21),
65     EIR_LE_SEC_CONFIRMATION_VALUE(0x22),
66     EIR_LE_CONNECTION_RANDOM_VALUE(0x23),
67     EIR_URI(0x24),
68     EIR_INDOOR_POSITIONING(0x25),
69     EIR_LE_SUPPORTED_FEATURES(0x27),
70     EIR_MANUFACTURER_SPECIFIC(0xFF);
71
72     /**
73      * A mapping between the integer code and its corresponding type to
74      * facilitate lookup by code.
75      */
76     private static Map<Integer, EirDataType> codeMapping = new HashMap<>();
77
78     private int key;
79
80     private EirDataType(int key) {
81         this.key = key;
82     }
83
84     private static void initMapping() {
85         for (EirDataType s : values()) {
86             codeMapping.put(s.key, s);
87         }
88     }
89
90     /**
91      * Lookup function based on the type code. Returns null if the code does not exist.
92      *
93      * @param bluetoothAddressType
94      *            the code to lookup
95      * @return enumeration value.
96      */
97     @SuppressWarnings({ "null", "unused" })
98     public static EirDataType getEirPacketType(int eirDataType) {
99         if (codeMapping.isEmpty()) {
100             initMapping();
101         }
102
103         return codeMapping.getOrDefault(eirDataType, UNKNOWN);
104     }
105
106     /**
107      * Returns the Bluetooth protocol defined value for this enum
108      *
109      * @return the EIR Data type key
110      */
111     public int getKey() {
112         return key;
113     }
114 }