hc
2024-05-10 10ebd8556b7990499c896a550e3d416b444211e6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
 * BlueALSA - ctl-proto.h
 * Copyright (c) 2016-2018 Arkadiusz Bokowy
 *
 * This file is a part of bluez-alsa.
 *
 * This project is licensed under the terms of the MIT license.
 *
 */
 
#ifndef BLUEALSA_SHARED_CTLPROTO_H_
#define BLUEALSA_SHARED_CTLPROTO_H_
 
#if HAVE_CONFIG_H
# include "config.h"
#endif
 
#include <stdint.h>
#include <bluetooth/bluetooth.h>
 
/* Location where the control socket and pipes are stored. */
#define BLUEALSA_RUN_STATE_DIR RUN_STATE_DIR "/bluealsa"
/* Version of the controller communication protocol. */
#define BLUEALSA_CRL_PROTO_VERSION 0x0300
 
enum ba_command {
   BA_COMMAND_PING,
   BA_COMMAND_SUBSCRIBE,
   BA_COMMAND_LIST_DEVICES,
   BA_COMMAND_LIST_TRANSPORTS,
   BA_COMMAND_TRANSPORT_GET,
   BA_COMMAND_TRANSPORT_SET_DELAY,
   BA_COMMAND_TRANSPORT_SET_VOLUME,
   BA_COMMAND_PCM_OPEN,
   BA_COMMAND_PCM_CLOSE,
   BA_COMMAND_PCM_PAUSE,
   BA_COMMAND_PCM_RESUME,
   BA_COMMAND_PCM_DRAIN,
   BA_COMMAND_RFCOMM_SEND,
   __BA_COMMAND_MAX
};
 
enum ba_status_code {
   BA_STATUS_CODE_SUCCESS = 0,
   BA_STATUS_CODE_ERROR_UNKNOWN,
   BA_STATUS_CODE_DEVICE_NOT_FOUND,
   BA_STATUS_CODE_STREAM_NOT_FOUND,
   BA_STATUS_CODE_DEVICE_BUSY,
   BA_STATUS_CODE_FORBIDDEN,
   BA_STATUS_CODE_PONG,
};
 
enum ba_event {
   BA_EVENT_TRANSPORT_ADDED   = 1 << 0,
   BA_EVENT_TRANSPORT_CHANGED = 1 << 1,
   BA_EVENT_TRANSPORT_REMOVED = 1 << 2,
   BA_EVENT_UPDATE_BATTERY    = 1 << 3,
   BA_EVENT_UPDATE_VOLUME     = 1 << 4,
};
 
enum ba_pcm_type {
   BA_PCM_TYPE_NULL = 0,
   BA_PCM_TYPE_A2DP,
   BA_PCM_TYPE_SCO,
};
 
enum ba_pcm_stream {
   BA_PCM_STREAM_PLAYBACK,
   BA_PCM_STREAM_CAPTURE,
   /* Special stream type returned by the LIST_TRANSPORTS command to indicate,
    * that given transport can act as a playback and capture device. In order
    * to open PCM for such a transport, one has to provide one of PLAYBACK or
    * CAPTURE stream types. */
   BA_PCM_STREAM_DUPLEX,
};
 
struct __attribute__ ((packed)) ba_request {
 
   enum ba_command command;
 
   /* selected device address */
   bdaddr_t addr;
 
   /* requested transport type */
   enum ba_pcm_type type;
   enum ba_pcm_stream stream;
 
   union {
 
       /* bit-mask with event subscriptions
        * used by BA_COMMAND_SUBSCRIBE */
       enum ba_event events;
 
       /* transport delay
        * used by BA_COMMAND_TRANSPORT_SET_DELAY */
       uint16_t delay;
 
       /* transport volume fields
        * used by BA_COMMAND_TRANSPORT_SET_VOLUME */
       struct {
           uint8_t ch1_muted:1;
           uint8_t ch1_volume:7;
           uint8_t ch2_muted:1;
           uint8_t ch2_volume:7;
       };
 
       /* RFCOMM command string to send
        * used by BA_COMMAND_RFCOMM_SEND */
       char rfcomm_command[32];
 
   };
 
};
 
/**
 * Single byte status message send by the controller at the end of every
 * response. This message contains the overall request status, which could
 * indicate either success or error. */
struct __attribute__ ((packed)) ba_msg_status {
   uint8_t code;
};
 
struct __attribute__ ((packed)) ba_msg_event {
   /* bit-mask with events */
   enum ba_event mask;
};
 
struct __attribute__ ((packed)) ba_msg_device {
 
   /* device address */
   bdaddr_t addr;
   /* name obtained from the Bluetooth device itself */
   char name[32];
 
   /* determine whether battery is available */
   uint8_t battery:1;
   /* device battery level in range [0, 100] */
   uint8_t battery_level:7;
 
};
 
struct __attribute__ ((packed)) ba_msg_transport {
 
   /* device address for which the transport is created */
   bdaddr_t addr;
 
   /* selected profile and audio codec */
   enum ba_pcm_type type;
   enum ba_pcm_stream stream;
   uint8_t codec;
 
   /* number of audio channels */
   uint8_t channels;
   /* used sampling frequency */
   uint32_t sampling;
 
   /* Levels for channel 1 (left) and 2 (right). These fields are also
    * used for SCO. In such a case channel 1 and 2 is responsible for
    * respectively playback and capture. */
   uint8_t ch1_muted:1;
   uint8_t ch1_volume:7;
   uint8_t ch2_muted:1;
   uint8_t ch2_volume:7;
 
   /* transport delay in 1/10 of millisecond */
   uint16_t delay;
 
};
 
#endif