1f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray/*
2f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray * Copyright (C) 2015, The Android Open Source Project
3f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray *
4f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray * Licensed under the Apache License, Version 2.0 (the "License");
5f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray * you may not use this file except in compliance with the License.
6f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray * You may obtain a copy of the License at
7f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray *
8f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray *     http://www.apache.org/licenses/LICENSE-2.0
9f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray *
10f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray * Unless required by applicable law or agreed to in writing, software
11f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray * distributed under the License is distributed on an "AS IS" BASIS,
12f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray * See the License for the specific language governing permissions and
14f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray * limitations under the License.
15f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray */
16f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray
17f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray/**
18f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray * Binder IPC interface for interacting with Bluetooth GATT server-role
19f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray * features.
20f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray */
21f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Ugurayinterface IBluetoothGattServer {
22f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray  /**
23f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * Registers a client application with this interface. This creates a unique
24f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * GATT server instance for the application that will contain the GATT
25f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * services belonging to the calling application. A special interface ID will
26f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * be returned in a callback to the application that can be used to perform
27f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * GATT server operations. Returns false in case of an error.
28f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   */
29f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray  boolean registerServer(in IBluetoothGattServerCallback callback);
30f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray
31f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray  /**
32f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * Unregisters a previously registered server with interface ID |server_if|.
33f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   */
34f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray  void unregisterServer(in int server_if);
35f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray
36f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray  /**
37f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * Unregisters all previously registered servers.
38f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   */
39f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray  void unregisterAll();
40f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray
41f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray  /**
42f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * Begins a new GATT service declaration. This will execute synchronously and
43f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * create a new service range. This can be followed by calls to populate the
44f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * service range with attributes. The started service won't be published and
45f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * made discoverable to remote devices until a successful call to
46f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * endServiceDeclaration.
47f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   *
48f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * The created service will be assigned a unique identifier that can be used
49f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * by the caller to distinguish between different services. This will be
50f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * returned in |out_id| in case of success. Returns false in case of failure,
51f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * e.g. a service declaration is already in progress.
52f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   */
53f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray  boolean beginServiceDeclaration(in int server_if, in boolean is_primary,
54f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray                                  in ParcelUuid uuid,
55f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray                                  out GattIdentifier out_id);
56f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray
57f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray  /**
58f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * Adds a characteristic entry to a previously started service declaration.
59f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * Returns false in case of failure, e.g. if no service declaration was
60f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * started. Returns the uniquely assigned characteristic identifier in
61f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * |out_id| in the case of success.
62f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   */
63f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray  boolean addCharacteristic(in int server_if, in ParcelUuid uuid,
64f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray                            in int properties, in int permissions,
65f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray                            out GattIdentifier out_id);
66f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray
67f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray  /**
68f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * Adds a characteristic descriptor entry to a previously started service
69f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * declaration. Returns false in case of failure, e.g. if no service
70f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * declaration was started or if the declaration does not contain a
71f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * characteristic that can own this descriptor. Returns the uniquely assigned
72f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * descriptor identifier in |out_id| in the case of success.
73f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   */
74f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray  boolean addDescriptor(in int server_if, in ParcelUuid uuid,
75f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray                        in int permissions,
76f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray                        out GattIdentifier out_id);
77f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray
78f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray  /**
79f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * Ends a previously started service declaration and asynchronously publishes
80f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * the service in the underlying attribute database. Returns false in case of
81f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * an asynchronous failure, e.g. if no service declaration was started or
82f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * there is a pending call to endServiceDeclaration. Otherwise returns true
83f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * and reports the result of the operation asynchronously in
84f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * IBluetoothGattServerCallback.onServiceAdded.
85f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   */
86f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray  boolean endServiceDeclaration(in int server_if);
87f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray
88f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray  /**
89f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * Sends a response to a currently pending read or write request. The request
90f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * will be propagated to the application via IBluetoothGattServerCallback with
91f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * a unique |request_id| which must be passed to this method along with the
92f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * |device_address| of the device that the request originated from.
93f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   *
94f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * The |status| field should contain the result of the operation. In the case
95f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * of success, the application should pass in "0". Otherwise this should
96f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * contain an ATT protocol error code.
97f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   */
98f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray  boolean sendResponse(in int server_if, in String device_address,
99f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray                       in int request_id, in int status,
100f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray                       in int offset, in byte[] value);
101f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray
102f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray  /**
103f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * Sends a handle-value notification or indication to the device with the
104f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * given address for the characteristic with the given identifier. |confirm|
105f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * should be set to true, if a handle-value indication should be sent, which
106f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * will remain pending until the remote device sends a handle-value
107f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * confirmation. Returns false if a call to this method is pending. Otherwise
108f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * reports the result asynchronously in
109f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   * IBluetoothGattServerCallback.onNotificationSent.
110f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray   */
111f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray  boolean sendNotification(in int server_if, in String device_address,
112f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray                           in GattIdentifier characteristic_id,
113f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray                           in boolean confirm, in byte[] value);
114f6fc0c48c2b4c8a9965f0f86275896da386ebdb2Arman Uguray}
115