1 /* 2 * Copyright 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.bluetooth.gatt; 18 19 import android.bluetooth.BluetoothDevice; 20 import android.os.RemoteException; 21 22 import java.util.ArrayList; 23 import java.util.List; 24 25 /** 26 * GATT Profile Native Interface to/from JNI. 27 */ 28 public class GattNativeInterface { 29 private static final String TAG = GattNativeInterface.class.getSimpleName(); 30 31 static { classInitNative()32 classInitNative(); 33 } 34 35 private static GattNativeInterface sInterface; 36 private static final Object INSTANCE_LOCK = new Object(); 37 38 private GattService mGattService; 39 GattNativeInterface()40 private GattNativeInterface() {} 41 getGattService()42 GattService getGattService() { 43 return mGattService; 44 } 45 46 /** 47 * This class is a singleton because native library should only be loaded once 48 * 49 * @return default instance 50 */ getInstance()51 public static GattNativeInterface getInstance() { 52 synchronized (INSTANCE_LOCK) { 53 if (sInterface == null) { 54 sInterface = new GattNativeInterface(); 55 } 56 } 57 return sInterface; 58 } 59 60 61 /* Callbacks */ 62 onScanResult(int eventType, int addressType, String address, int primaryPhy, int secondaryPhy, int advertisingSid, int txPower, int rssi, int periodicAdvInt, byte[] advData, String originalAddress)63 void onScanResult(int eventType, int addressType, String address, int primaryPhy, 64 int secondaryPhy, int advertisingSid, int txPower, int rssi, int periodicAdvInt, 65 byte[] advData, String originalAddress) { 66 getGattService().onScanResult(eventType, addressType, address, primaryPhy, secondaryPhy, 67 advertisingSid, txPower, rssi, periodicAdvInt, advData, originalAddress); 68 } 69 onScannerRegistered(int status, int scannerId, long uuidLsb, long uuidMsb)70 void onScannerRegistered(int status, int scannerId, long uuidLsb, long uuidMsb) 71 throws RemoteException { 72 getGattService().onScannerRegistered(status, scannerId, uuidLsb, uuidMsb); 73 } 74 onClientRegistered(int status, int clientIf, long uuidLsb, long uuidMsb)75 void onClientRegistered(int status, int clientIf, long uuidLsb, long uuidMsb) 76 throws RemoteException { 77 getGattService().onClientRegistered(status, clientIf, uuidLsb, uuidMsb); 78 } 79 onConnected(int clientIf, int connId, int status, String address)80 void onConnected(int clientIf, int connId, int status, String address) throws RemoteException { 81 getGattService().onConnected(clientIf, connId, status, address); 82 } 83 onDisconnected(int clientIf, int connId, int status, String address)84 void onDisconnected(int clientIf, int connId, int status, String address) 85 throws RemoteException { 86 getGattService().onDisconnected(clientIf, connId, status, address); 87 } 88 onClientPhyUpdate(int connId, int txPhy, int rxPhy, int status)89 void onClientPhyUpdate(int connId, int txPhy, int rxPhy, int status) throws RemoteException { 90 getGattService().onClientPhyUpdate(connId, txPhy, rxPhy, status); 91 } 92 onClientPhyRead(int clientIf, String address, int txPhy, int rxPhy, int status)93 void onClientPhyRead(int clientIf, String address, int txPhy, int rxPhy, int status) 94 throws RemoteException { 95 getGattService().onClientPhyRead(clientIf, address, txPhy, rxPhy, status); 96 } 97 onClientConnUpdate(int connId, int interval, int latency, int timeout, int status)98 void onClientConnUpdate(int connId, int interval, int latency, int timeout, int status) 99 throws RemoteException { 100 getGattService().onClientConnUpdate(connId, interval, latency, timeout, status); 101 } 102 onServiceChanged(int connId)103 void onServiceChanged(int connId) throws RemoteException { 104 getGattService().onServiceChanged(connId); 105 } 106 onClientSubrateChange(int connId, int subrateFactor, int latency, int contNum, int timeout, int status)107 void onClientSubrateChange(int connId, int subrateFactor, int latency, int contNum, int timeout, 108 int status) throws RemoteException { 109 getGattService().onClientSubrateChange(connId, subrateFactor, latency, contNum, timeout, 110 status); 111 } 112 onServerPhyUpdate(int connId, int txPhy, int rxPhy, int status)113 void onServerPhyUpdate(int connId, int txPhy, int rxPhy, int status) throws RemoteException { 114 getGattService().onServerPhyUpdate(connId, txPhy, rxPhy, status); 115 } 116 onServerPhyRead(int serverIf, String address, int txPhy, int rxPhy, int status)117 void onServerPhyRead(int serverIf, String address, int txPhy, int rxPhy, int status) 118 throws RemoteException { 119 getGattService().onServerPhyRead(serverIf, address, txPhy, rxPhy, status); 120 } 121 onServerConnUpdate(int connId, int interval, int latency, int timeout, int status)122 void onServerConnUpdate(int connId, int interval, int latency, int timeout, int status) 123 throws RemoteException { 124 getGattService().onServerConnUpdate(connId, interval, latency, timeout, status); 125 } 126 onServerSubrateChange(int connId, int subrateFactor, int latency, int contNum, int timeout, int status)127 void onServerSubrateChange(int connId, int subrateFactor, int latency, int contNum, int timeout, 128 int status) 129 throws RemoteException { 130 getGattService().onServerSubrateChange(connId, subrateFactor, latency, contNum, timeout, 131 status); 132 } 133 onSearchCompleted(int connId, int status)134 void onSearchCompleted(int connId, int status) throws RemoteException { 135 getGattService().onSearchCompleted(connId, status); 136 } 137 getSampleGattDbElement()138 GattDbElement getSampleGattDbElement() { 139 return getGattService().getSampleGattDbElement(); 140 } 141 onGetGattDb(int connId, ArrayList<GattDbElement> db)142 void onGetGattDb(int connId, ArrayList<GattDbElement> db) throws RemoteException { 143 getGattService().onGetGattDb(connId, db); 144 } 145 onRegisterForNotifications(int connId, int status, int registered, int handle)146 void onRegisterForNotifications(int connId, int status, int registered, int handle) { 147 getGattService().onRegisterForNotifications(connId, status, registered, handle); 148 } 149 onNotify(int connId, String address, int handle, boolean isNotify, byte[] data)150 void onNotify(int connId, String address, int handle, boolean isNotify, byte[] data) 151 throws RemoteException { 152 getGattService().onNotify(connId, address, handle, isNotify, data); 153 } 154 onReadCharacteristic(int connId, int status, int handle, byte[] data)155 void onReadCharacteristic(int connId, int status, int handle, byte[] data) 156 throws RemoteException { 157 getGattService().onReadCharacteristic(connId, status, handle, data); 158 } 159 onWriteCharacteristic(int connId, int status, int handle, byte[] data)160 void onWriteCharacteristic(int connId, int status, int handle, byte[] data) 161 throws RemoteException { 162 getGattService().onWriteCharacteristic(connId, status, handle, data); 163 } 164 onExecuteCompleted(int connId, int status)165 void onExecuteCompleted(int connId, int status) throws RemoteException { 166 getGattService().onExecuteCompleted(connId, status); 167 } 168 onReadDescriptor(int connId, int status, int handle, byte[] data)169 void onReadDescriptor(int connId, int status, int handle, byte[] data) throws RemoteException { 170 getGattService().onReadDescriptor(connId, status, handle, data); 171 } 172 onWriteDescriptor(int connId, int status, int handle, byte[] data)173 void onWriteDescriptor(int connId, int status, int handle, byte[] data) throws RemoteException { 174 getGattService().onWriteDescriptor(connId, status, handle, data); 175 } 176 onReadRemoteRssi(int clientIf, String address, int rssi, int status)177 void onReadRemoteRssi(int clientIf, String address, int rssi, int status) 178 throws RemoteException { 179 getGattService().onReadRemoteRssi(clientIf, address, rssi, status); 180 } 181 onScanFilterEnableDisabled(int action, int status, int clientIf)182 void onScanFilterEnableDisabled(int action, int status, int clientIf) { 183 getGattService().onScanFilterEnableDisabled(action, status, clientIf); 184 } 185 onScanFilterParamsConfigured(int action, int status, int clientIf, int availableSpace)186 void onScanFilterParamsConfigured(int action, int status, int clientIf, int availableSpace) { 187 getGattService().onScanFilterParamsConfigured(action, status, clientIf, availableSpace); 188 } 189 onScanFilterConfig(int action, int status, int clientIf, int filterType, int availableSpace)190 void onScanFilterConfig(int action, int status, int clientIf, int filterType, 191 int availableSpace) { 192 getGattService().onScanFilterConfig(action, status, clientIf, filterType, availableSpace); 193 } 194 onBatchScanStorageConfigured(int status, int clientIf)195 void onBatchScanStorageConfigured(int status, int clientIf) { 196 getGattService().onBatchScanStorageConfigured(status, clientIf); 197 } 198 onBatchScanStartStopped(int startStopAction, int status, int clientIf)199 void onBatchScanStartStopped(int startStopAction, int status, int clientIf) { 200 getGattService().onBatchScanStartStopped(startStopAction, status, clientIf); 201 } 202 onBatchScanReports(int status, int scannerId, int reportType, int numRecords, byte[] recordData)203 void onBatchScanReports(int status, int scannerId, int reportType, int numRecords, 204 byte[] recordData) throws RemoteException { 205 getGattService().onBatchScanReports(status, scannerId, reportType, numRecords, recordData); 206 } 207 onBatchScanThresholdCrossed(int clientIf)208 void onBatchScanThresholdCrossed(int clientIf) { 209 getGattService().onBatchScanThresholdCrossed(clientIf); 210 } 211 createOnTrackAdvFoundLostObject(int clientIf, int advPktLen, byte[] advPkt, int scanRspLen, byte[] scanRsp, int filtIndex, int advState, int advInfoPresent, String address, int addrType, int txPower, int rssiValue, int timeStamp)212 AdvtFilterOnFoundOnLostInfo createOnTrackAdvFoundLostObject(int clientIf, int advPktLen, 213 byte[] advPkt, int scanRspLen, byte[] scanRsp, int filtIndex, int advState, 214 int advInfoPresent, String address, int addrType, int txPower, int rssiValue, 215 int timeStamp) { 216 return getGattService().createOnTrackAdvFoundLostObject(clientIf, advPktLen, advPkt, 217 scanRspLen, scanRsp, filtIndex, advState, advInfoPresent, address, addrType, 218 txPower, rssiValue, timeStamp); 219 } 220 onTrackAdvFoundLost(AdvtFilterOnFoundOnLostInfo trackingInfo)221 void onTrackAdvFoundLost(AdvtFilterOnFoundOnLostInfo trackingInfo) throws RemoteException { 222 getGattService().onTrackAdvFoundLost(trackingInfo); 223 } 224 onScanParamSetupCompleted(int status, int scannerId)225 void onScanParamSetupCompleted(int status, int scannerId) throws RemoteException { 226 getGattService().onScanParamSetupCompleted(status, scannerId); 227 } 228 onConfigureMTU(int connId, int status, int mtu)229 void onConfigureMTU(int connId, int status, int mtu) throws RemoteException { 230 getGattService().onConfigureMTU(connId, status, mtu); 231 } 232 onClientCongestion(int connId, boolean congested)233 void onClientCongestion(int connId, boolean congested) throws RemoteException { 234 getGattService().onClientCongestion(connId, congested); 235 } 236 237 /* Server callbacks */ 238 onServerRegistered(int status, int serverIf, long uuidLsb, long uuidMsb)239 void onServerRegistered(int status, int serverIf, long uuidLsb, long uuidMsb) 240 throws RemoteException { 241 getGattService().onServerRegistered(status, serverIf, uuidLsb, uuidMsb); 242 } 243 onServiceAdded(int status, int serverIf, List<GattDbElement> service)244 void onServiceAdded(int status, int serverIf, List<GattDbElement> service) 245 throws RemoteException { 246 getGattService().onServiceAdded(status, serverIf, service); 247 } 248 onServiceStopped(int status, int serverIf, int srvcHandle)249 void onServiceStopped(int status, int serverIf, int srvcHandle) throws RemoteException { 250 getGattService().onServiceStopped(status, serverIf, srvcHandle); 251 } 252 onServiceDeleted(int status, int serverIf, int srvcHandle)253 void onServiceDeleted(int status, int serverIf, int srvcHandle) { 254 getGattService().onServiceDeleted(status, serverIf, srvcHandle); 255 } 256 onClientConnected(String address, boolean connected, int connId, int serverIf)257 void onClientConnected(String address, boolean connected, int connId, int serverIf) 258 throws RemoteException { 259 getGattService().onClientConnected(address, connected, connId, serverIf); 260 } 261 onServerReadCharacteristic(String address, int connId, int transId, int handle, int offset, boolean isLong)262 void onServerReadCharacteristic(String address, int connId, int transId, int handle, int offset, 263 boolean isLong) throws RemoteException { 264 getGattService().onServerReadCharacteristic(address, connId, transId, handle, offset, 265 isLong); 266 } 267 onServerReadDescriptor(String address, int connId, int transId, int handle, int offset, boolean isLong)268 void onServerReadDescriptor(String address, int connId, int transId, int handle, int offset, 269 boolean isLong) throws RemoteException { 270 getGattService().onServerReadDescriptor(address, connId, transId, handle, offset, isLong); 271 } 272 onServerWriteCharacteristic(String address, int connId, int transId, int handle, int offset, int length, boolean needRsp, boolean isPrep, byte[] data)273 void onServerWriteCharacteristic(String address, int connId, int transId, int handle, 274 int offset, int length, boolean needRsp, boolean isPrep, byte[] data) 275 throws RemoteException { 276 getGattService().onServerWriteCharacteristic(address, connId, transId, handle, offset, 277 length, needRsp, isPrep, data); 278 } 279 onServerWriteDescriptor(String address, int connId, int transId, int handle, int offset, int length, boolean needRsp, boolean isPrep, byte[] data)280 void onServerWriteDescriptor(String address, int connId, int transId, int handle, int offset, 281 int length, boolean needRsp, boolean isPrep, byte[] data) throws RemoteException { 282 getGattService().onServerWriteDescriptor(address, connId, transId, handle, offset, length, 283 needRsp, isPrep, data); 284 } 285 onExecuteWrite(String address, int connId, int transId, int execWrite)286 void onExecuteWrite(String address, int connId, int transId, int execWrite) 287 throws RemoteException { 288 getGattService().onExecuteWrite(address, connId, transId, execWrite); 289 } 290 onResponseSendCompleted(int status, int attrHandle)291 void onResponseSendCompleted(int status, int attrHandle) { 292 getGattService().onResponseSendCompleted(status, attrHandle); 293 } 294 onNotificationSent(int connId, int status)295 void onNotificationSent(int connId, int status) throws RemoteException { 296 getGattService().onNotificationSent(connId, status); 297 } 298 onServerCongestion(int connId, boolean congested)299 void onServerCongestion(int connId, boolean congested) throws RemoteException { 300 getGattService().onServerCongestion(connId, congested); 301 } 302 onMtuChanged(int connId, int mtu)303 void onMtuChanged(int connId, int mtu) throws RemoteException { 304 getGattService().onMtuChanged(connId, mtu); 305 } 306 307 /* Native methods */ classInitNative()308 private static native void classInitNative(); initializeNative()309 private native void initializeNative(); cleanupNative()310 private native void cleanupNative(); gattClientGetDeviceTypeNative(String address)311 private native int gattClientGetDeviceTypeNative(String address); gattClientRegisterAppNative(long appUuidLsb, long appUuidMsb, boolean eattSupport)312 private native void gattClientRegisterAppNative(long appUuidLsb, long appUuidMsb, 313 boolean eattSupport); gattClientUnregisterAppNative(int clientIf)314 private native void gattClientUnregisterAppNative(int clientIf); gattClientConnectNative(int clientIf, String address, int addressType, boolean isDirect, int transport, boolean opportunistic, int initiatingPhys)315 private native void gattClientConnectNative(int clientIf, String address, int addressType, 316 boolean isDirect, int transport, boolean opportunistic, int initiatingPhys); gattClientDisconnectNative(int clientIf, String address, int connId)317 private native void gattClientDisconnectNative(int clientIf, String address, int connId); gattClientSetPreferredPhyNative(int clientIf, String address, int txPhy, int rxPhy, int phyOptions)318 private native void gattClientSetPreferredPhyNative(int clientIf, String address, int txPhy, 319 int rxPhy, int phyOptions); gattClientReadPhyNative(int clientIf, String address)320 private native void gattClientReadPhyNative(int clientIf, String address); gattClientRefreshNative(int clientIf, String address)321 private native void gattClientRefreshNative(int clientIf, String address); gattClientSearchServiceNative(int connId, boolean searchAll, long serviceUuidLsb, long serviceUuidMsb)322 private native void gattClientSearchServiceNative(int connId, boolean searchAll, 323 long serviceUuidLsb, long serviceUuidMsb); gattClientDiscoverServiceByUuidNative(int connId, long serviceUuidLsb, long serviceUuidMsb)324 private native void gattClientDiscoverServiceByUuidNative(int connId, long serviceUuidLsb, 325 long serviceUuidMsb); gattClientGetGattDbNative(int connId)326 private native void gattClientGetGattDbNative(int connId); gattClientReadCharacteristicNative(int connId, int handle, int authReq)327 private native void gattClientReadCharacteristicNative(int connId, int handle, int authReq); gattClientReadUsingCharacteristicUuidNative(int connId, long uuidMsb, long uuidLsb, int sHandle, int eHandle, int authReq)328 private native void gattClientReadUsingCharacteristicUuidNative(int connId, long uuidMsb, 329 long uuidLsb, int sHandle, int eHandle, int authReq); gattClientReadDescriptorNative(int connId, int handle, int authReq)330 private native void gattClientReadDescriptorNative(int connId, int handle, int authReq); gattClientWriteCharacteristicNative(int connId, int handle, int writeType, int authReq, byte[] value)331 private native void gattClientWriteCharacteristicNative(int connId, int handle, int writeType, 332 int authReq, byte[] value); gattClientWriteDescriptorNative(int connId, int handle, int authReq, byte[] value)333 private native void gattClientWriteDescriptorNative(int connId, int handle, int authReq, 334 byte[] value); gattClientExecuteWriteNative(int connId, boolean execute)335 private native void gattClientExecuteWriteNative(int connId, boolean execute); gattClientRegisterForNotificationsNative(int clientIf, String address, int handle, boolean enable)336 private native void gattClientRegisterForNotificationsNative(int clientIf, String address, 337 int handle, boolean enable); gattClientReadRemoteRssiNative(int clientIf, String address)338 private native void gattClientReadRemoteRssiNative(int clientIf, String address); gattClientConfigureMTUNative(int connId, int mtu)339 private native void gattClientConfigureMTUNative(int connId, int mtu); gattConnectionParameterUpdateNative(int clientIf, String address, int minInterval, int maxInterval, int latency, int timeout, int minConnectionEventLen, int maxConnectionEventLen)340 private native void gattConnectionParameterUpdateNative(int clientIf, String address, 341 int minInterval, int maxInterval, int latency, int timeout, int minConnectionEventLen, 342 int maxConnectionEventLen); gattServerRegisterAppNative(long appUuidLsb, long appUuidMsb, boolean eattSupport)343 private native void gattServerRegisterAppNative(long appUuidLsb, long appUuidMsb, 344 boolean eattSupport); gattServerUnregisterAppNative(int serverIf)345 private native void gattServerUnregisterAppNative(int serverIf); gattServerConnectNative(int serverIf, String address, boolean isDirect, int transport)346 private native void gattServerConnectNative(int serverIf, String address, boolean isDirect, 347 int transport); gattServerDisconnectNative(int serverIf, String address, int connId)348 private native void gattServerDisconnectNative(int serverIf, String address, int connId); gattServerSetPreferredPhyNative(int clientIf, String address, int txPhy, int rxPhy, int phyOptions)349 private native void gattServerSetPreferredPhyNative(int clientIf, String address, int txPhy, 350 int rxPhy, int phyOptions); gattServerReadPhyNative(int clientIf, String address)351 private native void gattServerReadPhyNative(int clientIf, String address); gattServerAddServiceNative(int serverIf, List<GattDbElement> service)352 private native void gattServerAddServiceNative(int serverIf, List<GattDbElement> service); gattServerStopServiceNative(int serverIf, int svcHandle)353 private native void gattServerStopServiceNative(int serverIf, int svcHandle); gattServerDeleteServiceNative(int serverIf, int svcHandle)354 private native void gattServerDeleteServiceNative(int serverIf, int svcHandle); gattServerSendIndicationNative(int serverIf, int attrHandle, int connId, byte[] val)355 private native void gattServerSendIndicationNative(int serverIf, int attrHandle, int connId, 356 byte[] val); gattServerSendNotificationNative(int serverIf, int attrHandle, int connId, byte[] val)357 private native void gattServerSendNotificationNative(int serverIf, int attrHandle, int connId, 358 byte[] val); gattServerSendResponseNative(int serverIf, int connId, int transId, int status, int handle, int offset, byte[] val, int authReq)359 private native void gattServerSendResponseNative(int serverIf, int connId, int transId, 360 int status, int handle, int offset, byte[] val, int authReq); gattSubrateRequestNative(int clientIf, String address, int subrateMin, int subrateMax, int maxLatency, int contNumber, int supervisionTimeout)361 private native void gattSubrateRequestNative(int clientIf, String address, int subrateMin, 362 int subrateMax, int maxLatency, int contNumber, int supervisionTimeout); gattTestNative(int command, long uuid1Lsb, long uuid1Msb, String bda1, int p1, int p2, int p3, int p4, int p5)363 private native void gattTestNative(int command, long uuid1Lsb, long uuid1Msb, String bda1, 364 int p1, int p2, int p3, int p4, int p5); 365 366 /** 367 * Initialize the native interface and native components 368 */ init(GattService gattService)369 public void init(GattService gattService) { 370 mGattService = gattService; 371 initializeNative(); 372 } 373 374 /** 375 * Clean up the native interface and native components 376 */ cleanup()377 public void cleanup() { 378 cleanupNative(); 379 mGattService = null; 380 } 381 382 /** 383 * Get the type of Bluetooth device 384 * 385 * @param address address of the Bluetooth device 386 * @return type of Bluetooth device 0 for BR/EDR, 1 for BLE, 2 for DUAL mode (To be confirmed) 387 */ gattClientGetDeviceType(String address)388 public int gattClientGetDeviceType(String address) { 389 return gattClientGetDeviceTypeNative(address); 390 } 391 392 /** 393 * Register the given client 394 * It will invoke {@link #onClientRegistered(int, int, long, long)}. 395 */ gattClientRegisterApp(long appUuidLsb, long appUuidMsb, boolean eattSupport)396 public void gattClientRegisterApp(long appUuidLsb, long appUuidMsb, boolean eattSupport) { 397 gattClientRegisterAppNative(appUuidLsb, appUuidMsb, eattSupport); 398 } 399 400 /** 401 * Unregister the client 402 */ gattClientUnregisterApp(int clientIf)403 public void gattClientUnregisterApp(int clientIf) { 404 gattClientUnregisterAppNative(clientIf); 405 } 406 407 /** 408 * Connect to the remote Gatt server 409 * @see {@link BluetoothDevice#connectGatt} for parameters. 410 */ gattClientConnect(int clientIf, String address, int addressType, boolean isDirect, int transport, boolean opportunistic, int initiatingPhys)411 public void gattClientConnect(int clientIf, String address, int addressType, 412 boolean isDirect, int transport, boolean opportunistic, int initiatingPhys) { 413 gattClientConnectNative(clientIf, address, addressType, isDirect, transport, 414 opportunistic, initiatingPhys); 415 } 416 417 /** 418 * Disconnect from the remote Gatt server 419 */ gattClientDisconnect(int clientIf, String address, int connId)420 public void gattClientDisconnect(int clientIf, String address, int connId) { 421 gattClientDisconnectNative(clientIf, address, connId); 422 } 423 424 /** 425 * Set the preferred connection PHY for the client 426 */ gattClientSetPreferredPhy(int clientIf, String address, int txPhy, int rxPhy, int phyOptions)427 public void gattClientSetPreferredPhy(int clientIf, String address, int txPhy, 428 int rxPhy, int phyOptions) { 429 gattClientSetPreferredPhyNative(clientIf, address, txPhy, rxPhy, phyOptions); 430 } 431 432 /** 433 * Read the current transmitter PHY and receiver PHY of the client 434 */ gattClientReadPhy(int clientIf, String address)435 public void gattClientReadPhy(int clientIf, String address) { 436 gattClientReadPhyNative(clientIf, address); 437 } 438 439 /** 440 * Clear the internal cache and force a refresh of the services from the remote device 441 */ gattClientRefresh(int clientIf, String address)442 public void gattClientRefresh(int clientIf, String address) { 443 gattClientRefreshNative(clientIf, address); 444 } 445 446 /** 447 * Discover GATT services 448 */ gattClientSearchService(int connId, boolean searchAll, long serviceUuidLsb, long serviceUuidMsb)449 public void gattClientSearchService(int connId, boolean searchAll, long serviceUuidLsb, 450 long serviceUuidMsb) { 451 gattClientSearchServiceNative(connId, searchAll, serviceUuidLsb, serviceUuidMsb); 452 } 453 454 /** 455 * Discover the GATT service by the given UUID 456 */ gattClientDiscoverServiceByUuid(int connId, long serviceUuidLsb, long serviceUuidMsb)457 public void gattClientDiscoverServiceByUuid(int connId, long serviceUuidLsb, 458 long serviceUuidMsb) { 459 gattClientDiscoverServiceByUuidNative(connId, serviceUuidLsb, serviceUuidMsb); 460 } 461 462 /** 463 * Get GATT DB of the remote device 464 */ gattClientGetGattDb(int connId)465 public void gattClientGetGattDb(int connId) { 466 gattClientGetGattDbNative(connId); 467 } 468 469 /** 470 * Read a characteristic by the given handle 471 */ gattClientReadCharacteristic(int connId, int handle, int authReq)472 public void gattClientReadCharacteristic(int connId, int handle, int authReq) { 473 gattClientReadCharacteristicNative(connId, handle, authReq); 474 } 475 476 477 /** 478 * Read a characteristic by the given UUID 479 */ gattClientReadUsingCharacteristicUuid(int connId, long uuidMsb, long uuidLsb, int sHandle, int eHandle, int authReq)480 public void gattClientReadUsingCharacteristicUuid(int connId, long uuidMsb, 481 long uuidLsb, int sHandle, int eHandle, int authReq) { 482 gattClientReadUsingCharacteristicUuidNative(connId, uuidMsb, uuidLsb, sHandle, eHandle, 483 authReq); 484 } 485 486 /** 487 * Read a descriptor by the given handle 488 */ gattClientReadDescriptor(int connId, int handle, int authReq)489 public void gattClientReadDescriptor(int connId, int handle, int authReq) { 490 gattClientReadDescriptorNative(connId, handle, authReq); 491 } 492 493 /** 494 * Write a characteristic by the given handle 495 */ gattClientWriteCharacteristic(int connId, int handle, int writeType, int authReq, byte[] value)496 public void gattClientWriteCharacteristic(int connId, int handle, int writeType, 497 int authReq, byte[] value) { 498 gattClientWriteCharacteristicNative(connId, handle, writeType, authReq, value); 499 } 500 501 /** 502 * Write a descriptor by the given handle 503 */ gattClientWriteDescriptor(int connId, int handle, int authReq, byte[] value)504 public void gattClientWriteDescriptor(int connId, int handle, int authReq, 505 byte[] value) { 506 gattClientWriteDescriptorNative(connId, handle, authReq, value); 507 } 508 509 /** 510 * Execute a reliable write transaction 511 * @param connId 512 * @param execute 513 */ gattClientExecuteWrite(int connId, boolean execute)514 public void gattClientExecuteWrite(int connId, boolean execute) { 515 gattClientExecuteWriteNative(connId, execute); 516 } 517 518 /** 519 * Register notification for the characteristic 520 */ gattClientRegisterForNotifications(int clientIf, String address, int handle, boolean enable)521 public void gattClientRegisterForNotifications(int clientIf, String address, 522 int handle, boolean enable) { 523 gattClientRegisterForNotificationsNative(clientIf, address, handle, enable); 524 } 525 526 /** 527 * Read the RSSI for a connected remote device 528 * @param clientIf 529 * @param address 530 */ gattClientReadRemoteRssi(int clientIf, String address)531 public void gattClientReadRemoteRssi(int clientIf, String address) { 532 gattClientReadRemoteRssiNative(clientIf, address); 533 } 534 535 /** 536 * Configure MTU size used for the connection 537 */ gattClientConfigureMTU(int connId, int mtu)538 public void gattClientConfigureMTU(int connId, int mtu) { 539 gattClientConfigureMTUNative(connId, mtu); 540 } 541 542 /** 543 * Update connection parameter. 544 */ gattConnectionParameterUpdate(int clientIf, String address, int minInterval, int maxInterval, int latency, int timeout, int minConnectionEventLen, int maxConnectionEventLen)545 public void gattConnectionParameterUpdate(int clientIf, String address, 546 int minInterval, int maxInterval, int latency, int timeout, int minConnectionEventLen, 547 int maxConnectionEventLen) { 548 gattConnectionParameterUpdateNative(clientIf, address, minInterval, maxInterval, latency, 549 timeout, minConnectionEventLen, maxConnectionEventLen); 550 } 551 552 /** 553 * Update connection parameter. 554 */ gattSubrateRequest(int clientIf, String address, int subrateMin, int subrateMax, int maxLatency, int contNumber, int supervisionTimeout)555 public void gattSubrateRequest(int clientIf, String address, int subrateMin, int subrateMax, 556 int maxLatency, int contNumber, int supervisionTimeout) { 557 gattSubrateRequestNative(clientIf, address, subrateMin, subrateMax, maxLatency, contNumber, 558 supervisionTimeout); 559 } 560 561 /** 562 * Register GATT server 563 */ gattServerRegisterApp(long appUuidLsb, long appUuidMsb, boolean eattSupport)564 public void gattServerRegisterApp(long appUuidLsb, long appUuidMsb, boolean eattSupport) { 565 gattServerRegisterAppNative(appUuidLsb, appUuidMsb, eattSupport); 566 } 567 568 /** 569 * Unregister GATT server 570 */ gattServerUnregisterApp(int serverIf)571 public void gattServerUnregisterApp(int serverIf) { 572 gattServerUnregisterAppNative(serverIf); 573 } 574 575 /** 576 * Connect to a remote device as a GATT server role 577 */ gattServerConnect(int serverIf, String address, boolean isDirect, int transport)578 public void gattServerConnect(int serverIf, String address, boolean isDirect, 579 int transport) { 580 gattServerConnectNative(serverIf, address, isDirect, transport); 581 } 582 583 /** 584 * Disconnects from a remote device as a GATT server role 585 */ gattServerDisconnect(int serverIf, String address, int connId)586 public void gattServerDisconnect(int serverIf, String address, int connId) { 587 gattServerDisconnectNative(serverIf, address, connId); 588 } 589 590 /** 591 * Set the preferred connection PHY as a GATT server role 592 */ gattServerSetPreferredPhy(int clientIf, String address, int txPhy, int rxPhy, int phyOptions)593 public void gattServerSetPreferredPhy(int clientIf, String address, int txPhy, 594 int rxPhy, int phyOptions) { 595 gattServerSetPreferredPhyNative(clientIf, address, txPhy, rxPhy, phyOptions); 596 } 597 598 /** 599 * Read the current transmitter PHY and receiver PHY of the connection 600 */ gattServerReadPhy(int clientIf, String address)601 public void gattServerReadPhy(int clientIf, String address) { 602 gattServerReadPhyNative(clientIf, address); 603 } 604 605 /** 606 * Add a service to the list of services to be hosted. 607 */ gattServerAddService(int serverIf, List<GattDbElement> service)608 public void gattServerAddService(int serverIf, List<GattDbElement> service) { 609 gattServerAddServiceNative(serverIf, service); 610 } 611 612 /** 613 * Stop a service 614 */ gattServerStopService(int serverIf, int svcHandle)615 public void gattServerStopService(int serverIf, int svcHandle) { 616 gattServerStopServiceNative(serverIf, svcHandle); 617 } 618 619 /** 620 * Removes a service from the list of services to be provided 621 */ gattServerDeleteService(int serverIf, int svcHandle)622 public void gattServerDeleteService(int serverIf, int svcHandle) { 623 gattServerDeleteServiceNative(serverIf, svcHandle); 624 } 625 626 /** 627 * Send an indication of the characteristic 628 */ gattServerSendIndication(int serverIf, int attrHandle, int connId, byte[] val)629 public void gattServerSendIndication(int serverIf, int attrHandle, int connId, 630 byte[] val) { 631 gattServerSendIndicationNative(serverIf, attrHandle, connId, val); 632 } 633 634 /** 635 * Send a notification of the characteristic 636 */ gattServerSendNotification(int serverIf, int attrHandle, int connId, byte[] val)637 public void gattServerSendNotification(int serverIf, int attrHandle, int connId, 638 byte[] val) { 639 gattServerSendNotificationNative(serverIf, attrHandle, connId, val); 640 } 641 642 /** 643 * Send a response as a GATT server role 644 */ gattServerSendResponse(int serverIf, int connId, int transId, int status, int handle, int offset, byte[] val, int authReq)645 public void gattServerSendResponse(int serverIf, int connId, int transId, 646 int status, int handle, int offset, byte[] val, int authReq) { 647 gattServerSendResponseNative(serverIf, connId, transId, status, handle, offset, val, 648 authReq); 649 } 650 651 /** 652 * Send a test command 653 */ gattTest(int command, long uuid1Lsb, long uuid1Msb, String bda1, int p1, int p2, int p3, int p4, int p5)654 public void gattTest(int command, long uuid1Lsb, long uuid1Msb, String bda1, 655 int p1, int p2, int p3, int p4, int p5) { 656 gattTestNative(command, uuid1Lsb, uuid1Msb, bda1, p1, p2, p3, p4, p5); 657 } 658 } 659 660