]> git.basschouten.com Git - openhab-addons.git/blob
0158b3d23f3487667375a6c2b72ba6f34dfbaf5d
[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 import org.eclipse.jdt.annotation.Nullable;
20
21 /**
22  * Assigned numbers are used in GAP for inquiry response, EIR data type values, manufacturer-specific data, advertising
23  * data, low energy UUIDs and appearance characteristics, and class of device.
24  *
25  * https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile
26  *
27  * @author Chris Jackson - Initial contribution
28  *
29  */
30 @NonNullByDefault
31 public enum EirDataType {
32     /**
33      * Default unknown value
34      */
35     UNKNOWN(-1),
36     NONE(0),
37
38     EIR_FLAGS(0x01),
39     EIR_SVC_UUID16_INCOMPLETE(0x02),
40     EIR_SVC_UUID16_COMPLETE(0x03),
41     EIR_SVC_UUID32_INCOMPLETE(0x04),
42     EIR_SVC_UUID32_COMPLETE(0x05),
43     EIR_SVC_UUID128_INCOMPLETE(0x06),
44     EIR_SVC_UUID128_COMPLETE(0x07),
45     EIR_NAME_SHORT(0x08),
46     EIR_NAME_LONG(0x09),
47     EIR_TXPOWER(0x0A),
48     EIR_DEVICE_CLASS(0x0D),
49     EIR_SIMPLE_PAIRING_RANDOMIZER(0x0F),
50     EIR_SECMAN_TK_VALUE(0x10),
51     EIR_SECMAN_OOB_FLAGS(0x11),
52     EIR_SLAVEINTERVALRANGE(0x12),
53     EIR_SVC_SOLICIT_UUID16(0x14),
54     EIR_SVC_SOLICIT_UUID128(0x15),
55     EIR_SVC_DATA_UUID16(0x16),
56     EIR_PUBLIC_TARGET_ADDR(0x17),
57     EIR_RANDOM_TARGET_ADDR(0x18),
58     EIR_APPEARANCE(0x19),
59     EIR_ADVERTISING_INTERVAL(0x1A),
60     EIR_LE_DEVICE_ADDRESS(0x1B),
61     EIR_LE_ROLE(0x1C),
62     EIR_SIMPLE_PAIRING_HASH(0x1D),
63     EIR_SVC_SOLICIT_UUID32(0x1F),
64     EIR_SVC_DATA_UUID32(0x20),
65     EIR_SVC_DATA_UUID128(0x21),
66     EIR_LE_SEC_CONFIRMATION_VALUE(0x22),
67     EIR_LE_CONNECTION_RANDOM_VALUE(0x23),
68     EIR_URI(0x24),
69     EIR_INDOOR_POSITIONING(0x25),
70     EIR_LE_SUPPORTED_FEATURES(0x27),
71     EIR_MANUFACTURER_SPECIFIC(0xFF);
72
73     /**
74      * A mapping between the integer code and its corresponding type to
75      * facilitate lookup by code.
76      */
77     private static @Nullable Map<Integer, EirDataType> codeMapping;
78
79     private int key;
80
81     private EirDataType(int key) {
82         this.key = key;
83     }
84
85     /**
86      * Lookup function based on the type code. Returns {@link UNKNOWN} if the code does not exist.
87      *
88      * @param eirDataType
89      *            the code to lookup
90      * @return enumeration value.
91      */
92     public static EirDataType getEirPacketType(int eirDataType) {
93         Map<Integer, EirDataType> localCodeMapping = codeMapping;
94         if (localCodeMapping == null) {
95             localCodeMapping = new HashMap<>();
96             for (EirDataType s : values()) {
97                 localCodeMapping.put(s.key, s);
98             }
99             codeMapping = localCodeMapping;
100         }
101
102         return localCodeMapping.getOrDefault(eirDataType, UNKNOWN);
103     }
104
105     /**
106      * Returns the Bluetooth protocol defined value for this enum
107      *
108      * @return the EIR Data type key
109      */
110     public int getKey() {
111         return key;
112     }
113 }