bluetooth: Protect from a misbehaving bluetoothd
[platform/upstream/pulseaudio.git] / src / modules / bluetooth / bluez5-util.h
1 #ifndef foobluez5utilhfoo
2 #define foobluez5utilhfoo
3
4 /***
5   This file is part of PulseAudio.
6
7   Copyright 2008-2013 João Paulo Rechi Vita
8
9   PulseAudio is free software; you can redistribute it and/or modify
10   it under the terms of the GNU Lesser General Public License as
11   published by the Free Software Foundation; either version 2.1 of the
12   License, or (at your option) any later version.
13
14   PulseAudio is distributed in the hope that it will be useful, but
15   WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17   General Public License for more details.
18
19   You should have received a copy of the GNU Lesser General Public
20   License along with PulseAudio; if not, write to the Free Software
21   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22   USA.
23 ***/
24
25 #include <pulsecore/core.h>
26
27 #define PA_BLUETOOTH_UUID_A2DP_SOURCE "0000110a-0000-1000-8000-00805f9b34fb"
28 #define PA_BLUETOOTH_UUID_A2DP_SINK   "0000110b-0000-1000-8000-00805f9b34fb"
29
30 typedef struct pa_bluetooth_transport pa_bluetooth_transport;
31 typedef struct pa_bluetooth_device pa_bluetooth_device;
32 typedef struct pa_bluetooth_adapter pa_bluetooth_adapter;
33 typedef struct pa_bluetooth_discovery pa_bluetooth_discovery;
34
35 typedef enum pa_bluetooth_hook {
36     PA_BLUETOOTH_HOOK_DEVICE_CONNECTION_CHANGED,          /* Call data: pa_bluetooth_device */
37     PA_BLUETOOTH_HOOK_TRANSPORT_STATE_CHANGED,            /* Call data: pa_bluetooth_transport */
38     PA_BLUETOOTH_HOOK_MAX
39 } pa_bluetooth_hook_t;
40
41 typedef enum profile {
42     PA_BLUETOOTH_PROFILE_A2DP_SINK,
43     PA_BLUETOOTH_PROFILE_A2DP_SOURCE,
44     PA_BLUETOOTH_PROFILE_OFF
45 } pa_bluetooth_profile_t;
46 #define PA_BLUETOOTH_PROFILE_COUNT PA_BLUETOOTH_PROFILE_OFF
47
48 typedef enum pa_bluetooth_transport_state {
49     PA_BLUETOOTH_TRANSPORT_STATE_DISCONNECTED,
50     PA_BLUETOOTH_TRANSPORT_STATE_IDLE,
51     PA_BLUETOOTH_TRANSPORT_STATE_PLAYING
52 } pa_bluetooth_transport_state_t;
53
54 typedef int (*pa_bluetooth_transport_acquire_cb)(pa_bluetooth_transport *t, bool optional, size_t *imtu, size_t *omtu);
55 typedef void (*pa_bluetooth_transport_release_cb)(pa_bluetooth_transport *t);
56
57 struct pa_bluetooth_transport {
58     pa_bluetooth_device *device;
59
60     char *owner;
61     char *path;
62     pa_bluetooth_profile_t profile;
63
64     uint8_t codec;
65     uint8_t *config;
66     size_t config_size;
67
68     pa_bluetooth_transport_state_t state;
69
70     pa_bluetooth_transport_acquire_cb acquire;
71     pa_bluetooth_transport_release_cb release;
72     void *userdata;
73 };
74
75 struct pa_bluetooth_device {
76     pa_bluetooth_discovery *discovery;
77     pa_bluetooth_adapter *adapter;
78
79     int device_info_valid;      /* 0: no results yet; 1: good results; -1: bad results ... */
80
81     /* Device information */
82     char *path;
83     char *adapter_path;
84     char *alias;
85     char *address;
86     uint32_t class_of_device;
87     pa_hashmap *uuids;
88
89     pa_bluetooth_transport *transports[PA_BLUETOOTH_PROFILE_COUNT];
90 };
91
92 struct pa_bluetooth_adapter {
93     pa_bluetooth_discovery *discovery;
94     char *path;
95     char *address;
96 };
97
98 pa_bluetooth_transport *pa_bluetooth_transport_new(pa_bluetooth_device *d, const char *owner, const char *path,
99                                                    pa_bluetooth_profile_t p, const uint8_t *config, size_t size);
100
101 void pa_bluetooth_transport_put(pa_bluetooth_transport *t);
102 void pa_bluetooth_transport_free(pa_bluetooth_transport *t);
103
104 bool pa_bluetooth_device_any_transport_connected(const pa_bluetooth_device *d);
105
106 pa_bluetooth_device* pa_bluetooth_discovery_get_device_by_path(pa_bluetooth_discovery *y, const char *path);
107 pa_bluetooth_device* pa_bluetooth_discovery_get_device_by_address(pa_bluetooth_discovery *y, const char *remote, const char *local);
108
109 pa_hook* pa_bluetooth_discovery_hook(pa_bluetooth_discovery *y, pa_bluetooth_hook_t hook);
110
111 const char *pa_bluetooth_profile_to_string(pa_bluetooth_profile_t profile);
112
113 pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *core);
114 pa_bluetooth_discovery* pa_bluetooth_discovery_ref(pa_bluetooth_discovery *y);
115 void pa_bluetooth_discovery_unref(pa_bluetooth_discovery *y);
116 #endif