Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
EInfoReport.java
Go to the documentation of this file.
1/**
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2022 Gothel Software e.K.
4 * Copyright (c) 2022 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
26package org.direct_bt;
27
28import java.nio.ByteOrder;
29import java.util.List;
30import java.util.Map;
31
32import org.jau.net.EUI48;
33
34/**
35 * Collection of 'Extended Advertising Data' (EAD), 'Advertising Data' (AD)
36 * or 'Extended Inquiry Response' (EIR) information.
37 *
38 * References:
39 *
40 * - BT Core Spec v5.2: Vol 4, Part E, 7.7.65.2 LE Advertising Report event
41 * - BT Core Spec v5.2: Vol 4, Part E, 7.7.65.13 LE Extended Advertising Report event
42 * - BT Core Spec v5.2: Vol 3, Part C, 11 ADVERTISING AND SCAN RESPONSE DATA FORMAT
43 * - BT Core Spec v5.2: Vol 3, Part C, 8 EXTENDED INQUIRY RESPONSE DATA FORMAT
44 * - BT Core Spec Supplement v9, Part A: Section 1 + 2 Examples, p25..
45 * - [Assigned Numbers - Generic Access Profile](https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile/)
46 *
47 * @since 2.5.3
48 */
49public final class EInfoReport implements AutoCloseable, Cloneable
50{
51 private volatile long nativeInstance;
52 /* pp */ long getNativeInstance() { return nativeInstance; }
53
54 public enum Source {
55 /** Not Available */
56 NA( 0 ),
57 /** (Extended) Advertising Data (AD or EAD) Indication Variant, i.e. initial passive scan data. */
58 AD_IND( 1 ),
59 /** (Extended) Advertising Data (AD or EAD) Scan Response, i.e. optional active scanning data after AD_IND. */
61 /** Extended Inquiry Response (EIR) */
62 EIR( 3 ),
63 /** Extended Inquiry Response (EIR) from Kernel Mgmt */
65
66 Source(final int v) {
67 value = v;
68 }
69 public final int value;
70
71 /**
72 * Maps the specified integer value to a constant of {@link Source}.
73 * @param value the integer value to be mapped to a constant of this enum type.
74 * @return the corresponding constant of this enum type, using {@link #NA} if not supported.
75 */
76 public static Source get(final int value) {
77 switch(value) {
78 case 1: return AD_IND;
79 case 2: return AD_SCAN_RSP;
80 case 3: return EIR;
81 case 4: return EIR_MGMT;
82 default: return NA;
83 }
84 }
85 }
86
87 /**
88 * New independent EInfoReport instance
89 */
90 public EInfoReport() {
91 nativeInstance = ctorImpl1();
92 }
93 private native long ctorImpl1();
94
95 /**
96 * New EInfoReport instance reusing shared managed EInfoReport object
97 * @param nativeInstanceOther native pointer to shared managed EInfoReport object `std::shared_ptr<EInfoReport>`
98 */
99 /* pp */ EInfoReport(final long nativeInstanceOther) {
100 nativeInstance = ctorImpl2(nativeInstanceOther);
101 }
102 private native long ctorImpl2(final long nativeInstanceOther);
103
104 /**
105 * Replace the native shared managed EInfoReport object
106 * @param nativeInstanceOther native pointer to shared managed EInfoReport object `std::shared_ptr<EInfoReport>`
107 */
108 /* pp */ final void replaces_native(final long nativeInstanceOther) {
109 replaces_nativeImpl(nativeInstanceOther);
110 }
111 private native void replaces_nativeImpl(final long nativeInstanceOther);
112
113 @Override
115 final EInfoReport n = new EInfoReport();
116 n.set(this);
117 return n;
118 }
119
120 @Override
121 public void close() {
122 final long handle;
123 synchronized( this ) {
124 handle = nativeInstance;
125 nativeInstance = 0;
126 }
127 if( 0 != handle ) {
128 dtorImpl(handle);
129 }
130 }
131 private static native void dtorImpl(final long nativeInstance);
132
133 @Override
134 public void finalize() {
135 close();
136 }
137
138 /**
139 * Reset all data fields.
140 */
141 public final native void clear();
142
143 /**
144 * Merge all fields from given EInfoReport if set and different.
145 * @param eir
146 * @return The changed fields, i.e. EIRDataType bit field
147 */
148 public final EIRDataTypeSet set(final EInfoReport eir) {
149 return new EIRDataTypeSet(setImpl(eir));
150 }
151 private native int setImpl(final EInfoReport eir);
152
153 // public native void setSource(Source s);
154 // public native void setTimestamp(uint64_t ts);
155 // public native void setEvtType(AD_PDU_Type et);
156 // public native void setExtEvtType(EAD_Event_Type eadt);
157 public final void setAddressType(final BDAddressType at) {
158 setAddressTypeImpl(at.value);
159 }
160 private native void setAddressTypeImpl(final byte at);
161
162 public final void setAddress(final EUI48 a) {
163 setAddressImpl(a.b);
164 }
165 private native void setAddressImpl(final byte[] a);
166
167 public native void setRSSI(final byte v);
168 public native void setTxPower(final byte v);
169
170 public final void setFlags(final GAPFlags f) {
171 setFlagsImpl(f.mask);
172 }
173 private native void setFlagsImpl(final byte f);
174
175 public final void addFlag(final GAPFlags.Bit f) {
176 addFlagImpl(f.value);
177 }
178 private native void addFlagImpl(final byte f);
179
180 public native void setName(final String name);
181 public native void setShortName(final String name_short);
182
183 // public native void setManufactureSpecificData(const ManufactureSpecificData& msd_);
184 public native void addService(final String uuid);
185 public native void setServicesComplete(final boolean v);
186 public native void setDeviceClass(final int c);
187 // public native void setAppearance(AppearanceCat a);
188 // public native void setHash(const uint8_t * h);
189 // public native void setRandomizer(const uint8_t * r);
190 public native void setDeviceID(final short source, final short vendor, final short product, final short version);
191
192 /**
193 * Set slave connection interval range.
194 *
195 * Bluetooth Supplement, Part A, section 1.9
196 *
197 * @param min conn_interval_min in units of 1.25ms, default value 10 for 12.5ms; Value range [6 .. 3200] for [7.5ms .. 4000ms]
198 * @param max conn_interval_max in units of 1.25ms, default value 24 for 30.0ms; Value range [6 .. 3200] for [7.5ms .. 4000ms]
199 */
200 public native void setConnInterval(final short min, final short max);
201
202 public final Source getSource() { return Source.get( getSourceImpl() ); }
203 private native int getSourceImpl();
204
205 public native long getTimestamp();
206
208 return new EIRDataTypeSet(getEIRDataMaskImpl());
209 }
210 private native int getEIRDataMaskImpl();
211
212 public final boolean isSet(final EIRDataTypeSet.DataType bit) { return getEIRDataMask().isSet(bit); }
213
214 // public native AD_PDU_Type getEvtType();
215 // public native EAD_Event_Type getExtEvtType();
216 public final GAPFlags getFlags() {
217 return new GAPFlags(getFlagsImpl());
218 }
219 private native byte getFlagsImpl();
220
221 public native byte getADAddressType();
222
224 return BDAddressType.get(getAddressTypeImpl());
225 }
226 private native byte getAddressTypeImpl();
227
228 public final EUI48 getAddress() {
229 return new EUI48(getAddressImpl(), ByteOrder.nativeOrder());
230 }
231 private native byte[/*6*/] getAddressImpl();
232
233 public native String getName();
234 public native String getShortName();
235 public native byte getRSSI();
236 public native byte getTxPower();
237
238 /**
239 * Returns a map containing manufacturer specific advertisement data.
240 * An entry has a uint16_t key (company) and an array of bytes (data).
241 * @return manufacturer specific advertisement data.
242 */
243 public native Map<Short, byte[]> getManufacturerData();
244
245 public native List<String> getServices();
246 public native boolean getServicesComplete();
247
248 public native int getDeviceClass();
249 // public native AppearanceCat getAppearance();
250 // public native jau::TROOctets & getHash();
251 // public native jau::TROOctets & getRandomizer();
252 public native short getDeviceIDSource();
253 public native short getDeviceIDVendor();
254 public native short getDeviceIDProduct();
255 public native short getDeviceIDVersion();
256
257 /**
258 * Get slave connection interval range.
259 *
260 * Bluetooth Supplement, Part A, section 1.9
261 *
262 * @param min conn_interval_min in units of 1.25ms, default value 10 for 12.5ms; Value range [6 .. 3200] for [7.5ms .. 4000ms]
263 * @param max conn_interval_max in units of 1.25ms, default value 24 for 30.0ms; Value range [6 .. 3200] for [7.5ms .. 4000ms]
264 */
265 public native void getConnInterval(final short minmax[/*2*/]);
266
267 public native String getDeviceIDModalias();
268 public native String eirDataMaskToString();
269 public native String toString(final boolean includeServices);
270
271 @Override
272 public final String toString() { return toString(true); }
273}
Bit mask of 'Extended Inquiry Response' (EIR) data fields, indicating a set of related data.
boolean isSet(final DataType bit)
Collection of 'Extended Advertising Data' (EAD), 'Advertising Data' (AD) or 'Extended Inquiry Respons...
final EIRDataTypeSet set(final EInfoReport eir)
Merge all fields from given EInfoReport if set and different.
final void setAddress(final EUI48 a)
native String eirDataMaskToString()
final boolean isSet(final EIRDataTypeSet.DataType bit)
native short getDeviceIDProduct()
native Map< Short, byte[]> getManufacturerData()
Returns a map containing manufacturer specific advertisement data.
final EIRDataTypeSet getEIRDataMask()
final BDAddressType getAddressType()
native byte getADAddressType()
native void setTxPower(final byte v)
native void setConnInterval(final short min, final short max)
Set slave connection interval range.
native String toString(final boolean includeServices)
native String getDeviceIDModalias()
final void setFlags(final GAPFlags f)
final void addFlag(final GAPFlags.Bit f)
native String getName()
native long getTimestamp()
native void setShortName(final String name_short)
native short getDeviceIDVendor()
native void setName(final String name)
native void getConnInterval(final short minmax[])
Get slave connection interval range.
native short getDeviceIDSource()
final native void clear()
Reset all data fields.
native void setDeviceID(final short source, final short vendor, final short product, final short version)
native void setServicesComplete(final boolean v)
native List< String > getServices()
native boolean getServicesComplete()
native String getShortName()
native int getDeviceClass()
native void setDeviceClass(final int c)
EInfoReport()
New independent EInfoReport instance.
native void addService(final String uuid)
native short getDeviceIDVersion()
final void setAddressType(final BDAddressType at)
final GAPFlags getFlags()
native byte getTxPower()
native void setRSSI(final byte v)
Bit mask of 'Extended Inquiry Response' (EIR) data fields, indicating a set of related data.
Definition: GAPFlags.java:35
Bluetooth address type constants.
static BDAddressType get(final String name)
Maps the specified name to a constant of BDAddressType.
Each enum represents a 'Extended Inquiry Response' (EIR) data field type bit.
EIR
Extended Inquiry Response (EIR)
static Source get(final int value)
Maps the specified integer value to a constant of Source.
AD_IND
(Extended) Advertising Data (AD or EAD) Indication Variant, i.e.
EIR_MGMT
Extended Inquiry Response (EIR) from Kernel Mgmt.
AD_SCAN_RSP
(Extended) Advertising Data (AD or EAD) Scan Response, i.e.
Each enum represents a 'Extended Inquiry Response' (EIR) data field type bit.
Definition: GAPFlags.java:45