1/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 */
5
6#ifndef CRAS_BT_DEVICE_H_
7#define CRAS_BT_DEVICE_H_
8
9#include <dbus/dbus.h>
10
11struct cras_bt_adapter;
12struct cras_bt_device;
13struct cras_iodev;
14struct cras_timer;
15
16enum cras_bt_device_profile {
17	CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE	= (1 << 0),
18	CRAS_BT_DEVICE_PROFILE_A2DP_SINK	= (1 << 1),
19	CRAS_BT_DEVICE_PROFILE_AVRCP_REMOTE	= (1 << 2),
20	CRAS_BT_DEVICE_PROFILE_AVRCP_TARGET	= (1 << 3),
21	CRAS_BT_DEVICE_PROFILE_HFP_HANDSFREE	= (1 << 4),
22	CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY	= (1 << 5),
23	CRAS_BT_DEVICE_PROFILE_HSP_HEADSET	= (1 << 6),
24	CRAS_BT_DEVICE_PROFILE_HSP_AUDIOGATEWAY = (1 << 7)
25};
26
27enum cras_bt_device_profile cras_bt_device_profile_from_uuid(const char *uuid);
28
29struct cras_bt_device *cras_bt_device_create(DBusConnection *conn,
30					     const char *object_path);
31void cras_bt_device_destroy(struct cras_bt_device *device);
32void cras_bt_device_reset();
33
34struct cras_bt_device *cras_bt_device_get(const char *object_path);
35size_t cras_bt_device_get_list(struct cras_bt_device ***device_list_out);
36
37const char *cras_bt_device_object_path(const struct cras_bt_device *device);
38struct cras_bt_adapter *cras_bt_device_adapter(
39	const struct cras_bt_device *device);
40const char *cras_bt_device_address(const struct cras_bt_device *device);
41const char *cras_bt_device_name(const struct cras_bt_device *device);
42int cras_bt_device_paired(const struct cras_bt_device *device);
43int cras_bt_device_trusted(const struct cras_bt_device *device);
44int cras_bt_device_connected(const struct cras_bt_device *device);
45
46void cras_bt_device_update_properties(struct cras_bt_device *device,
47				      DBusMessageIter *properties_array_iter,
48				      DBusMessageIter *invalidated_array_iter);
49
50/* Sets the append_iodev_cb to bt device. */
51void cras_bt_device_set_append_iodev_cb(struct cras_bt_device *device,
52					void (*cb)(void *data));
53
54/* Checks if profile is claimed supported by the device. */
55int cras_bt_device_supports_profile(const struct cras_bt_device *device,
56				    enum cras_bt_device_profile profile);
57
58/* Sets if the BT audio device should use hardware volume.
59 * Args:
60 *    device - The remote bluetooth audio device.
61 *    use_hardware_volume - Set to true to indicate hardware volume
62 *        is preferred over software volume.
63 */
64void cras_bt_device_set_use_hardware_volume(struct cras_bt_device *device,
65					    int use_hardware_volume);
66
67/* Gets if the BT audio device should use hardware volume. */
68int cras_bt_device_get_use_hardware_volume(struct cras_bt_device *device);
69
70/* Forces disconnect the bt device. Used when handling audio error
71 * that we want to make the device be completely disconnected from
72 * host to reflect the state that an error has occurred.
73 * Args:
74 *    conn - The dbus connection.
75 *    device - The bt device to disconnect.
76 */
77int cras_bt_device_disconnect(DBusConnection *conn,
78			      struct cras_bt_device *device);
79
80/* Gets the SCO socket for the device.
81 * Args:
82 *     device - The device object to get SCO socket for.
83 */
84int cras_bt_device_sco_connect(struct cras_bt_device *device);
85
86/* Queries the preffered mtu value for SCO socket. */
87int cras_bt_device_sco_mtu(struct cras_bt_device *device, int sco_socket);
88
89/* Appends an iodev to bt device.
90 * Args:
91 *    device - The device to append iodev to.
92 *    iodev - The iodev to add.
93 *    profile - The profile of the iodev about to add.
94 */
95void cras_bt_device_append_iodev(struct cras_bt_device *device,
96				 struct cras_iodev *iodev,
97				 enum cras_bt_device_profile profile);
98
99/* Removes an iodev from bt device.
100 * Args:
101 *    device - The device to remove iodev from.
102 *    iodev - The iodev to remove.
103 */
104void cras_bt_device_rm_iodev(struct cras_bt_device *device,
105			     struct cras_iodev *iodev);
106
107/* Gets the active profile of the bt device. */
108int cras_bt_device_get_active_profile(const struct cras_bt_device *device);
109
110/* Sets the active profile of the bt device. */
111void cras_bt_device_set_active_profile(struct cras_bt_device *device,
112				       unsigned int profile);
113
114/* Switches profile after the active profile of bt device has changed and
115 * enables bt iodev immediately. This function is used for profile switching
116 * at iodev open.
117 * Args:
118 *    device - The bluetooth device.
119 *    bt_iodev - The iodev triggers the reactivaion.
120 */
121int cras_bt_device_switch_profile_enable_dev(struct cras_bt_device *device,
122					     struct cras_iodev *bt_iodev);
123
124/* Switches profile after the active profile of bt device has changed. This
125 * function is used when we want to switch profile without changing the
126 * iodev's status.
127 * Args:
128 *    device - The bluetooth device.
129 *    bt_iodev - The iodev triggers the reactivaion.
130 */
131int cras_bt_device_switch_profile(struct cras_bt_device *device,
132				  struct cras_iodev *bt_iodev);
133
134/* Calls this function when the buffer size of an underlying profile iodev
135 * has changed and update it for the virtual bt iodev. */
136void cras_bt_device_iodev_buffer_size_changed(struct cras_bt_device *device);
137
138void cras_bt_device_start_monitor();
139
140/* Checks if the device has an iodev for A2DP. */
141int cras_bt_device_has_a2dp(struct cras_bt_device *device);
142
143/* Returns true if and only if device has an iodev for A2DP and the bt device
144 * is not opening for audio capture.
145 */
146int cras_bt_device_can_switch_to_a2dp(struct cras_bt_device *device);
147
148/* Updates the volume to bt_device when a volume change event is reported. */
149void cras_bt_device_update_hardware_volume(struct cras_bt_device *device,
150					   int volume);
151
152/* Notifies bt_device that a2dp connection is configured. */
153void cras_bt_device_a2dp_configured(struct cras_bt_device *device);
154
155/* Cancels any scheduled suspension of device. */
156int cras_bt_device_cancel_suspend(struct cras_bt_device *device);
157
158/* Schedules device to suspend after given delay. */
159int cras_bt_device_schedule_suspend(struct cras_bt_device *device,
160				    unsigned int msec);
161
162/* Notifies bt device that audio gateway is initialized.
163 * Args:
164 *   device - The bluetooth device.
165 * Returns:
166 *   0 on success, error code otherwise.
167 */
168int cras_bt_device_audio_gateway_initialized(struct cras_bt_device *device);
169
170#endif /* CRAS_BT_DEVICE_H_ */
171