• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2012 The Chromium OS 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 /*
7  * Messages sent between the server and clients.
8  */
9 #ifndef CRAS_MESSAGES_H_
10 #define CRAS_MESSAGES_H_
11 
12 #include <stdint.h>
13 
14 #include "cras_iodev_info.h"
15 #include "cras_types.h"
16 
17 /* Rev when message format changes. If new messages are added, or message ID
18  * values change. */
19 #define CRAS_PROTO_VER 5
20 #define CRAS_SERV_MAX_MSG_SIZE 256
21 #define CRAS_CLIENT_MAX_MSG_SIZE 256
22 #define CRAS_MAX_HOTWORD_MODELS 243
23 #define CRAS_MAX_REMIX_CHANNELS 32
24 #define CRAS_MAX_TEST_DATA_LEN 224
25 #define CRAS_AEC_DUMP_FILE_NAME_LEN 128
26 
27 /* Message IDs. */
28 enum CRAS_SERVER_MESSAGE_ID {
29 	/* Client -> Server*/
30 	CRAS_SERVER_CONNECT_STREAM,
31 	CRAS_SERVER_DISCONNECT_STREAM,
32 	CRAS_SERVER_SWITCH_STREAM_TYPE_IODEV, /* Unused */
33 	CRAS_SERVER_SET_SYSTEM_VOLUME,
34 	CRAS_SERVER_SET_SYSTEM_MUTE,
35 	CRAS_SERVER_SET_USER_MUTE,
36 	CRAS_SERVER_SET_SYSTEM_MUTE_LOCKED,
37 	CRAS_SERVER_SET_SYSTEM_CAPTURE_GAIN,
38 	CRAS_SERVER_SET_SYSTEM_CAPTURE_MUTE,
39 	CRAS_SERVER_SET_SYSTEM_CAPTURE_MUTE_LOCKED,
40 	CRAS_SERVER_SET_NODE_ATTR,
41 	CRAS_SERVER_SELECT_NODE,
42 	CRAS_SERVER_RELOAD_DSP,
43 	CRAS_SERVER_DUMP_DSP_INFO,
44 	CRAS_SERVER_DUMP_AUDIO_THREAD,
45 	CRAS_SERVER_DUMP_SNAPSHOTS,
46 	CRAS_SERVER_ADD_ACTIVE_NODE,
47 	CRAS_SERVER_RM_ACTIVE_NODE,
48 	CRAS_SERVER_ADD_TEST_DEV,
49 	CRAS_SERVER_TEST_DEV_COMMAND,
50 	CRAS_SERVER_SUSPEND,
51 	CRAS_SERVER_RESUME,
52 	CRAS_CONFIG_GLOBAL_REMIX,
53 	CRAS_SERVER_GET_HOTWORD_MODELS,
54 	CRAS_SERVER_SET_HOTWORD_MODEL,
55 	CRAS_SERVER_REGISTER_NOTIFICATION,
56 	CRAS_SERVER_SET_AEC_DUMP,
57 	CRAS_SERVER_RELOAD_AEC_CONFIG,
58 	CRAS_SERVER_DUMP_BT,
59 	CRAS_SERVER_SET_BT_WBS_ENABLED,
60 	CRAS_SERVER_GET_ATLOG_FD,
61 };
62 
63 enum CRAS_CLIENT_MESSAGE_ID {
64 	/* Server -> Client */
65 	CRAS_CLIENT_CONNECTED,
66 	CRAS_CLIENT_STREAM_CONNECTED,
67 	CRAS_CLIENT_AUDIO_DEBUG_INFO_READY,
68 	CRAS_CLIENT_GET_HOTWORD_MODELS_READY,
69 	/* System status messages */
70 	CRAS_CLIENT_OUTPUT_VOLUME_CHANGED,
71 	CRAS_CLIENT_OUTPUT_MUTE_CHANGED,
72 	CRAS_CLIENT_CAPTURE_GAIN_CHANGED,
73 	CRAS_CLIENT_CAPTURE_MUTE_CHANGED,
74 	CRAS_CLIENT_NODES_CHANGED,
75 	CRAS_CLIENT_ACTIVE_NODE_CHANGED,
76 	CRAS_CLIENT_OUTPUT_NODE_VOLUME_CHANGED,
77 	CRAS_CLIENT_NODE_LEFT_RIGHT_SWAPPED_CHANGED,
78 	CRAS_CLIENT_INPUT_NODE_GAIN_CHANGED,
79 	CRAS_CLIENT_NUM_ACTIVE_STREAMS_CHANGED,
80 	/* Server -> Client */
81 	CRAS_CLIENT_ATLOG_FD_READY,
82 };
83 
84 /* Messages that control the server. These are sent from the client to affect
85  * and action on the server. */
86 struct __attribute__((__packed__)) cras_server_message {
87 	uint32_t length;
88 	enum CRAS_SERVER_MESSAGE_ID id;
89 };
90 
91 /* Messages that control the client. These are sent from the server to affect
92  * and action on the client. */
93 struct __attribute__((__packed__)) cras_client_message {
94 	uint32_t length;
95 	enum CRAS_CLIENT_MESSAGE_ID id;
96 };
97 
98 /*
99  * Messages from client to server.
100  */
101 
102 /* Sent by a client to connect a stream to the server. */
103 struct __attribute__((__packed__)) cras_connect_message {
104 	struct cras_server_message header;
105 	uint32_t proto_version;
106 	enum CRAS_STREAM_DIRECTION direction; /* input/output/loopback */
107 	cras_stream_id_t stream_id; /* unique id for this stream */
108 	enum CRAS_STREAM_TYPE stream_type; /* media, or call, etc. */
109 	uint32_t buffer_frames; /* Buffer size in frames. */
110 	uint32_t cb_threshold; /* callback client when this much is left */
111 	uint32_t flags;
112 	struct cras_audio_format_packed format; /* rate, channel, sample size */
113 	uint32_t dev_idx; /* device to attach stream, 0 if none */
114 	uint64_t effects; /* Bit map of requested effects. */
115 	enum CRAS_CLIENT_TYPE client_type; /* chrome, or arc, etc. */
116 	uint32_t client_shm_size; /* Size of client-provided samples shm, if any */
117 };
118 
119 /*
120  * Old version of connect message without 'cras_type' and 'client_shm_size'
121  * defined.
122  * Used to check against when receiving invalid size of connect message.
123  * Expected to have proto_version set to 3.
124  * TODO(yuhsuan): remove when all clients migrate to latest libcras.
125  */
126 struct __attribute__((__packed__)) cras_connect_message_old {
127 	struct cras_server_message header;
128 	uint32_t proto_version;
129 	enum CRAS_STREAM_DIRECTION direction; /* input/output/loopback */
130 	cras_stream_id_t stream_id; /* unique id for this stream */
131 	enum CRAS_STREAM_TYPE stream_type; /* media, or call, etc. */
132 	uint32_t buffer_frames; /* Buffer size in frames. */
133 	uint32_t cb_threshold; /* callback client when this much is left */
134 	uint32_t flags;
135 	struct cras_audio_format_packed format; /* rate, channel, sample size */
136 	uint32_t dev_idx; /* device to attach stream, 0 if none */
137 	uint64_t effects; /* Bit map of requested effects. */
138 };
139 
cras_fill_connect_message(struct cras_connect_message * m,enum CRAS_STREAM_DIRECTION direction,cras_stream_id_t stream_id,enum CRAS_STREAM_TYPE stream_type,enum CRAS_CLIENT_TYPE client_type,size_t buffer_frames,size_t cb_threshold,uint32_t flags,uint64_t effects,struct cras_audio_format format,uint32_t dev_idx,uint32_t client_shm_size)140 static inline void cras_fill_connect_message(
141 	struct cras_connect_message *m, enum CRAS_STREAM_DIRECTION direction,
142 	cras_stream_id_t stream_id, enum CRAS_STREAM_TYPE stream_type,
143 	enum CRAS_CLIENT_TYPE client_type, size_t buffer_frames,
144 	size_t cb_threshold, uint32_t flags, uint64_t effects,
145 	struct cras_audio_format format, uint32_t dev_idx,
146 	uint32_t client_shm_size)
147 {
148 	m->proto_version = CRAS_PROTO_VER;
149 	m->direction = direction;
150 	m->stream_id = stream_id;
151 	m->stream_type = stream_type;
152 	m->buffer_frames = buffer_frames;
153 	m->cb_threshold = cb_threshold;
154 	m->flags = flags;
155 	m->effects = effects;
156 	pack_cras_audio_format(&m->format, &format);
157 	m->dev_idx = dev_idx;
158 	m->client_type = client_type;
159 	m->client_shm_size = client_shm_size;
160 	m->header.id = CRAS_SERVER_CONNECT_STREAM;
161 	m->header.length = sizeof(struct cras_connect_message);
162 }
163 
164 /* Sent by a client to remove a stream from the server. */
165 struct __attribute__((__packed__)) cras_disconnect_stream_message {
166 	struct cras_server_message header;
167 	cras_stream_id_t stream_id;
168 };
169 static inline void
cras_fill_disconnect_stream_message(struct cras_disconnect_stream_message * m,cras_stream_id_t stream_id)170 cras_fill_disconnect_stream_message(struct cras_disconnect_stream_message *m,
171 				    cras_stream_id_t stream_id)
172 {
173 	m->stream_id = stream_id;
174 	m->header.id = CRAS_SERVER_DISCONNECT_STREAM;
175 	m->header.length = sizeof(struct cras_disconnect_stream_message);
176 }
177 
178 /* Move streams of "type" to the iodev at "iodev_idx". */
179 struct __attribute__((__packed__)) cras_switch_stream_type_iodev {
180 	struct cras_server_message header;
181 	enum CRAS_STREAM_TYPE stream_type;
182 	uint32_t iodev_idx;
183 };
184 
185 /* Set the system volume. */
186 struct __attribute__((__packed__)) cras_set_system_volume {
187 	struct cras_server_message header;
188 	uint32_t volume;
189 };
cras_fill_set_system_volume(struct cras_set_system_volume * m,size_t volume)190 static inline void cras_fill_set_system_volume(struct cras_set_system_volume *m,
191 					       size_t volume)
192 {
193 	m->volume = volume;
194 	m->header.id = CRAS_SERVER_SET_SYSTEM_VOLUME;
195 	m->header.length = sizeof(*m);
196 }
197 
198 /* Sets the capture gain. */
199 struct __attribute__((__packed__)) cras_set_system_capture_gain {
200 	struct cras_server_message header;
201 	int32_t gain;
202 };
203 static inline void
cras_fill_set_system_capture_gain(struct cras_set_system_capture_gain * m,long gain)204 cras_fill_set_system_capture_gain(struct cras_set_system_capture_gain *m,
205 				  long gain)
206 {
207 	m->gain = gain;
208 	m->header.id = CRAS_SERVER_SET_SYSTEM_CAPTURE_GAIN;
209 	m->header.length = sizeof(*m);
210 }
211 
212 /* Set the system mute state. */
213 struct __attribute__((__packed__)) cras_set_system_mute {
214 	struct cras_server_message header;
215 	int32_t mute; /* 0 = un-mute, 1 = mute. */
216 };
cras_fill_set_system_mute(struct cras_set_system_mute * m,int mute)217 static inline void cras_fill_set_system_mute(struct cras_set_system_mute *m,
218 					     int mute)
219 {
220 	m->mute = mute;
221 	m->header.id = CRAS_SERVER_SET_SYSTEM_MUTE;
222 	m->header.length = sizeof(*m);
223 }
cras_fill_set_user_mute(struct cras_set_system_mute * m,int mute)224 static inline void cras_fill_set_user_mute(struct cras_set_system_mute *m,
225 					   int mute)
226 {
227 	m->mute = mute;
228 	m->header.id = CRAS_SERVER_SET_USER_MUTE;
229 	m->header.length = sizeof(*m);
230 }
231 static inline void
cras_fill_set_system_mute_locked(struct cras_set_system_mute * m,int locked)232 cras_fill_set_system_mute_locked(struct cras_set_system_mute *m, int locked)
233 {
234 	m->mute = locked;
235 	m->header.id = CRAS_SERVER_SET_SYSTEM_MUTE_LOCKED;
236 	m->header.length = sizeof(*m);
237 }
238 static inline void
cras_fill_set_system_capture_mute(struct cras_set_system_mute * m,int mute)239 cras_fill_set_system_capture_mute(struct cras_set_system_mute *m, int mute)
240 {
241 	m->mute = mute;
242 	m->header.id = CRAS_SERVER_SET_SYSTEM_CAPTURE_MUTE;
243 	m->header.length = sizeof(*m);
244 }
245 static inline void
cras_fill_set_system_capture_mute_locked(struct cras_set_system_mute * m,int locked)246 cras_fill_set_system_capture_mute_locked(struct cras_set_system_mute *m,
247 					 int locked)
248 {
249 	m->mute = locked;
250 	m->header.id = CRAS_SERVER_SET_SYSTEM_CAPTURE_MUTE_LOCKED;
251 	m->header.length = sizeof(*m);
252 }
253 
254 /* Set an attribute of an ionode. */
255 struct __attribute__((__packed__)) cras_set_node_attr {
256 	struct cras_server_message header;
257 	cras_node_id_t node_id;
258 	enum ionode_attr attr;
259 	int32_t value;
260 };
cras_fill_set_node_attr(struct cras_set_node_attr * m,cras_node_id_t node_id,enum ionode_attr attr,int value)261 static inline void cras_fill_set_node_attr(struct cras_set_node_attr *m,
262 					   cras_node_id_t node_id,
263 					   enum ionode_attr attr, int value)
264 {
265 	m->header.id = CRAS_SERVER_SET_NODE_ATTR;
266 	m->node_id = node_id;
267 	m->attr = attr;
268 	m->value = value;
269 	m->header.length = sizeof(*m);
270 }
271 
272 /* Set an attribute of an ionode. */
273 struct __attribute__((__packed__)) cras_select_node {
274 	struct cras_server_message header;
275 	enum CRAS_STREAM_DIRECTION direction;
276 	cras_node_id_t node_id;
277 };
cras_fill_select_node(struct cras_select_node * m,enum CRAS_STREAM_DIRECTION direction,cras_node_id_t node_id)278 static inline void cras_fill_select_node(struct cras_select_node *m,
279 					 enum CRAS_STREAM_DIRECTION direction,
280 					 cras_node_id_t node_id)
281 {
282 	m->header.id = CRAS_SERVER_SELECT_NODE;
283 	m->direction = direction;
284 	m->node_id = node_id;
285 	m->header.length = sizeof(*m);
286 }
287 
288 /* Add an active ionode. */
289 struct __attribute__((__packed__)) cras_add_active_node {
290 	struct cras_server_message header;
291 	enum CRAS_STREAM_DIRECTION direction;
292 	cras_node_id_t node_id;
293 };
294 static inline void
cras_fill_add_active_node(struct cras_add_active_node * m,enum CRAS_STREAM_DIRECTION direction,cras_node_id_t node_id)295 cras_fill_add_active_node(struct cras_add_active_node *m,
296 			  enum CRAS_STREAM_DIRECTION direction,
297 			  cras_node_id_t node_id)
298 {
299 	m->header.id = CRAS_SERVER_ADD_ACTIVE_NODE;
300 	m->direction = direction;
301 	m->node_id = node_id;
302 	m->header.length = sizeof(*m);
303 }
304 
305 /* Remove an active ionode. */
306 struct __attribute__((__packed__)) cras_rm_active_node {
307 	struct cras_server_message header;
308 	enum CRAS_STREAM_DIRECTION direction;
309 	cras_node_id_t node_id;
310 };
311 static inline void
cras_fill_rm_active_node(struct cras_rm_active_node * m,enum CRAS_STREAM_DIRECTION direction,cras_node_id_t node_id)312 cras_fill_rm_active_node(struct cras_rm_active_node *m,
313 			 enum CRAS_STREAM_DIRECTION direction,
314 			 cras_node_id_t node_id)
315 {
316 	m->header.id = CRAS_SERVER_RM_ACTIVE_NODE;
317 	m->direction = direction;
318 	m->node_id = node_id;
319 	m->header.length = sizeof(*m);
320 }
321 
322 /* Reload the dsp configuration. */
323 struct __attribute__((__packed__)) cras_reload_dsp {
324 	struct cras_server_message header;
325 };
cras_fill_reload_dsp(struct cras_reload_dsp * m)326 static inline void cras_fill_reload_dsp(struct cras_reload_dsp *m)
327 {
328 	m->header.id = CRAS_SERVER_RELOAD_DSP;
329 	m->header.length = sizeof(*m);
330 }
331 
332 /* Dump current dsp information to syslog. */
333 struct __attribute__((__packed__)) cras_dump_dsp_info {
334 	struct cras_server_message header;
335 };
336 
cras_fill_dump_dsp_info(struct cras_dump_dsp_info * m)337 static inline void cras_fill_dump_dsp_info(struct cras_dump_dsp_info *m)
338 {
339 	m->header.id = CRAS_SERVER_DUMP_DSP_INFO;
340 	m->header.length = sizeof(*m);
341 }
342 
343 /* Dump current audio thread information to syslog. */
344 struct __attribute__((__packed__)) cras_dump_audio_thread {
345 	struct cras_server_message header;
346 };
347 
cras_fill_dump_audio_thread(struct cras_dump_audio_thread * m)348 static inline void cras_fill_dump_audio_thread(struct cras_dump_audio_thread *m)
349 {
350 	m->header.id = CRAS_SERVER_DUMP_AUDIO_THREAD;
351 	m->header.length = sizeof(*m);
352 }
353 
354 struct __attribute__((__packed__)) cras_get_atlog_fd {
355 	struct cras_server_message header;
356 };
357 
cras_fill_get_atlog_fd(struct cras_get_atlog_fd * m)358 static inline void cras_fill_get_atlog_fd(struct cras_get_atlog_fd *m)
359 {
360 	m->header.id = CRAS_SERVER_GET_ATLOG_FD;
361 	m->header.length = sizeof(*m);
362 }
363 
364 /* Dump bluetooth events and state changes. */
365 struct __attribute__((__packed__)) cras_dump_bt {
366 	struct cras_server_message header;
367 };
368 
cras_fill_dump_bt(struct cras_dump_bt * m)369 static inline void cras_fill_dump_bt(struct cras_dump_bt *m)
370 {
371 	m->header.id = CRAS_SERVER_DUMP_BT;
372 	m->header.length = sizeof(*m);
373 }
374 
375 /* Dump current audio thread snapshots to shard memory with the client. */
376 struct __attribute__((__packed__)) cras_dump_snapshots {
377 	struct cras_server_message header;
378 };
379 
cras_fill_dump_snapshots(struct cras_dump_snapshots * m)380 static inline void cras_fill_dump_snapshots(struct cras_dump_snapshots *m)
381 {
382 	m->header.id = CRAS_SERVER_DUMP_SNAPSHOTS;
383 	m->header.length = sizeof(*m);
384 }
385 
386 /* Add a test device. */
387 struct __attribute__((__packed__)) cras_add_test_dev {
388 	struct cras_server_message header;
389 	enum TEST_IODEV_TYPE type;
390 };
391 
cras_fill_add_test_dev(struct cras_add_test_dev * m,enum TEST_IODEV_TYPE type)392 static inline void cras_fill_add_test_dev(struct cras_add_test_dev *m,
393 					  enum TEST_IODEV_TYPE type)
394 {
395 	m->header.id = CRAS_SERVER_ADD_TEST_DEV;
396 	m->header.length = sizeof(*m);
397 	m->type = type;
398 }
399 
400 /* Command a test device. */
401 struct __attribute__((__packed__)) cras_test_dev_command {
402 	struct cras_server_message header;
403 	unsigned int command;
404 	unsigned int iodev_idx;
405 	unsigned int data_len;
406 	uint8_t data[CRAS_MAX_TEST_DATA_LEN];
407 };
408 
cras_fill_test_dev_command(struct cras_test_dev_command * m,unsigned int iodev_idx,enum CRAS_TEST_IODEV_CMD command,unsigned int data_len,const uint8_t * data)409 static inline void cras_fill_test_dev_command(struct cras_test_dev_command *m,
410 					      unsigned int iodev_idx,
411 					      enum CRAS_TEST_IODEV_CMD command,
412 					      unsigned int data_len,
413 					      const uint8_t *data)
414 {
415 	m->header.id = CRAS_SERVER_TEST_DEV_COMMAND;
416 	m->header.length = sizeof(*m) + data_len;
417 	m->iodev_idx = iodev_idx;
418 	m->command = command;
419 	m->data_len = data_len;
420 	memcpy(m->data, data, data_len);
421 }
422 
cras_fill_suspend_message(struct cras_server_message * m,int is_suspend)423 static inline void cras_fill_suspend_message(struct cras_server_message *m,
424 					     int is_suspend)
425 {
426 	m->id = is_suspend ? CRAS_SERVER_SUSPEND : CRAS_SERVER_RESUME;
427 	m->length = sizeof(*m);
428 }
429 
430 /*
431  * Configures the global remix converter.
432  * `num_channels` must be less than `CRAS_MAX_REMIX_CHANNELS`.
433  */
434 struct __attribute__((__packed__)) cras_config_global_remix {
435 	struct cras_server_message header;
436 	unsigned int num_channels;
437 	float coefficient[CRAS_MAX_REMIX_CHANNELS];
438 };
439 
440 static inline void
cras_fill_config_global_remix_command(struct cras_config_global_remix * m,unsigned int num_channels,float * coeff,unsigned int count)441 cras_fill_config_global_remix_command(struct cras_config_global_remix *m,
442 				      unsigned int num_channels, float *coeff,
443 				      unsigned int count)
444 {
445 	m->header.id = CRAS_CONFIG_GLOBAL_REMIX;
446 	m->header.length = sizeof(*m) + count * sizeof(*coeff);
447 	m->num_channels = num_channels;
448 	memcpy(m->coefficient, coeff, count * sizeof(*coeff));
449 }
450 
451 /* Get supported hotword models. */
452 struct __attribute__((__packed__)) cras_get_hotword_models {
453 	struct cras_server_message header;
454 	cras_node_id_t node_id;
455 };
456 
457 static inline void
cras_fill_get_hotword_models_message(struct cras_get_hotword_models * m,cras_node_id_t node_id)458 cras_fill_get_hotword_models_message(struct cras_get_hotword_models *m,
459 				     cras_node_id_t node_id)
460 {
461 	m->header.id = CRAS_SERVER_GET_HOTWORD_MODELS;
462 	m->header.length = sizeof(*m);
463 	m->node_id = node_id;
464 }
465 
466 /* Set desired hotword model. */
467 struct __attribute__((__packed__)) cras_set_hotword_model {
468 	struct cras_server_message header;
469 	cras_node_id_t node_id;
470 	char model_name[CRAS_MAX_HOTWORD_MODEL_NAME_SIZE];
471 };
472 
473 static inline void
cras_fill_set_hotword_model_message(struct cras_set_hotword_model * m,cras_node_id_t node_id,const char * model_name)474 cras_fill_set_hotword_model_message(struct cras_set_hotword_model *m,
475 				    cras_node_id_t node_id,
476 				    const char *model_name)
477 {
478 	m->header.id = CRAS_SERVER_SET_HOTWORD_MODEL;
479 	m->header.length = sizeof(*m);
480 	m->node_id = node_id;
481 	memcpy(m->model_name, model_name, CRAS_MAX_HOTWORD_MODEL_NAME_SIZE);
482 }
483 
484 /* Set aec dump to start or stop. */
485 struct __attribute__((__packed__)) cras_set_aec_dump {
486 	struct cras_server_message header;
487 	cras_stream_id_t stream_id;
488 	unsigned int start;
489 };
490 
cras_fill_set_aec_dump_message(struct cras_set_aec_dump * m,cras_stream_id_t stream_id,unsigned int start)491 static inline void cras_fill_set_aec_dump_message(struct cras_set_aec_dump *m,
492 						  cras_stream_id_t stream_id,
493 						  unsigned int start)
494 {
495 	m->header.id = CRAS_SERVER_SET_AEC_DUMP;
496 	m->header.length = sizeof(*m);
497 	m->stream_id = stream_id;
498 	m->start = start;
499 }
500 
501 /* Reload the aec configuration. */
502 struct __attribute__((__packed__)) cras_reload_aec_config {
503 	struct cras_server_message header;
504 };
cras_fill_reload_aec_config(struct cras_reload_aec_config * m)505 static inline void cras_fill_reload_aec_config(struct cras_reload_aec_config *m)
506 {
507 	m->header.id = CRAS_SERVER_RELOAD_AEC_CONFIG;
508 	m->header.length = sizeof(*m);
509 }
510 
511 /* Sets the flag to enable or disable bluetooth wideband speech feature. */
512 struct __attribute__((__packed__)) cras_set_bt_wbs_enabled {
513 	struct cras_server_message header;
514 	unsigned int enabled;
515 };
516 static inline void
cras_fill_set_bt_wbs_enabled(struct cras_set_bt_wbs_enabled * m,unsigned int enabled)517 cras_fill_set_bt_wbs_enabled(struct cras_set_bt_wbs_enabled *m,
518 			     unsigned int enabled)
519 {
520 	m->header.id = CRAS_SERVER_SET_BT_WBS_ENABLED;
521 	m->header.length = sizeof(*m);
522 	m->enabled = enabled;
523 }
524 
525 struct __attribute__((__packed__)) cras_register_notification {
526 	struct cras_server_message header;
527 	uint32_t msg_id;
528 	int do_register;
529 };
530 static inline void
cras_fill_register_notification_message(struct cras_register_notification * m,enum CRAS_CLIENT_MESSAGE_ID msg_id,int do_register)531 cras_fill_register_notification_message(struct cras_register_notification *m,
532 					enum CRAS_CLIENT_MESSAGE_ID msg_id,
533 					int do_register)
534 {
535 	m->header.id = CRAS_SERVER_REGISTER_NOTIFICATION;
536 	m->header.length = sizeof(*m);
537 	m->msg_id = msg_id;
538 	m->do_register = do_register;
539 }
540 
541 /*
542  * Messages sent from server to client.
543  */
544 
545 /* Reply from the server indicating that the client has connected. */
546 struct __attribute__((__packed__)) cras_client_connected {
547 	struct cras_client_message header;
548 	uint32_t client_id;
549 };
cras_fill_client_connected(struct cras_client_connected * m,size_t client_id)550 static inline void cras_fill_client_connected(struct cras_client_connected *m,
551 					      size_t client_id)
552 {
553 	m->client_id = client_id;
554 	m->header.id = CRAS_CLIENT_CONNECTED;
555 	m->header.length = sizeof(struct cras_client_connected);
556 }
557 
558 /*
559  * Reply from server that a stream has been successfully added.
560  * Two file descriptors are added, input shm followed by out shm.
561  *
562  * samples_shm_size is shm_max_size for old clients.
563  * TODO(fletcherw) remove comment once all clients are on CRAS_PROTO_VER >= 3.
564  */
565 struct __attribute__((__packed__)) cras_client_stream_connected {
566 	struct cras_client_message header;
567 	int32_t err;
568 	cras_stream_id_t stream_id;
569 	struct cras_audio_format_packed format;
570 	uint32_t samples_shm_size;
571 	uint64_t effects;
572 };
573 
574 static inline void
cras_fill_client_stream_connected(struct cras_client_stream_connected * m,int err,cras_stream_id_t stream_id,struct cras_audio_format * format,size_t samples_shm_size,uint64_t effects)575 cras_fill_client_stream_connected(struct cras_client_stream_connected *m,
576 				  int err, cras_stream_id_t stream_id,
577 				  struct cras_audio_format *format,
578 				  size_t samples_shm_size, uint64_t effects)
579 {
580 	m->err = err;
581 	m->stream_id = stream_id;
582 	pack_cras_audio_format(&m->format, format);
583 	m->samples_shm_size = samples_shm_size;
584 	m->effects = effects;
585 	m->header.id = CRAS_CLIENT_STREAM_CONNECTED;
586 	m->header.length = sizeof(struct cras_client_stream_connected);
587 }
588 
589 /* Sent from server to client when audio debug information is requested. */
590 struct __attribute__((__packed__)) cras_client_audio_debug_info_ready {
591 	struct cras_client_message header;
592 };
cras_fill_client_audio_debug_info_ready(struct cras_client_audio_debug_info_ready * m)593 static inline void cras_fill_client_audio_debug_info_ready(
594 	struct cras_client_audio_debug_info_ready *m)
595 {
596 	m->header.id = CRAS_CLIENT_AUDIO_DEBUG_INFO_READY;
597 	m->header.length = sizeof(*m);
598 }
599 
600 struct __attribute__((__packed__)) cras_client_atlog_fd_ready {
601 	struct cras_client_message header;
602 };
603 
604 static inline void
cras_fill_client_atlog_fd_ready(struct cras_client_atlog_fd_ready * m)605 cras_fill_client_atlog_fd_ready(struct cras_client_atlog_fd_ready *m)
606 {
607 	m->header.id = CRAS_CLIENT_ATLOG_FD_READY;
608 	m->header.length = sizeof(*m);
609 }
610 
611 /* Sent from server to client when hotword models info is ready. */
612 struct __attribute__((__packed__)) cras_client_get_hotword_models_ready {
613 	struct cras_client_message header;
614 	int32_t hotword_models_size;
615 	uint8_t hotword_models[CRAS_MAX_HOTWORD_MODELS + 1];
616 };
cras_fill_client_get_hotword_models_ready(struct cras_client_get_hotword_models_ready * m,const char * hotword_models,size_t hotword_models_size)617 static inline void cras_fill_client_get_hotword_models_ready(
618 	struct cras_client_get_hotword_models_ready *m,
619 	const char *hotword_models, size_t hotword_models_size)
620 {
621 	m->header.id = CRAS_CLIENT_GET_HOTWORD_MODELS_READY;
622 	m->header.length = sizeof(*m);
623 	m->hotword_models_size = hotword_models_size;
624 	/* Copy string data with terminator. */
625 	if (hotword_models) {
626 		strncpy((char *)m->hotword_models, hotword_models,
627 			CRAS_MAX_HOTWORD_MODELS);
628 		m->hotword_models[CRAS_MAX_HOTWORD_MODELS] = '\0';
629 	}
630 }
631 
632 /* System status messages sent from server to client when state changes. */
633 struct __attribute__((__packed__)) cras_client_volume_changed {
634 	struct cras_client_message header;
635 	int32_t volume;
636 };
637 static inline void
cras_fill_client_output_volume_changed(struct cras_client_volume_changed * m,int32_t volume)638 cras_fill_client_output_volume_changed(struct cras_client_volume_changed *m,
639 				       int32_t volume)
640 {
641 	m->header.id = CRAS_CLIENT_OUTPUT_VOLUME_CHANGED;
642 	m->header.length = sizeof(*m);
643 	m->volume = volume;
644 }
645 static inline void
cras_fill_client_capture_gain_changed(struct cras_client_volume_changed * m,int32_t gain)646 cras_fill_client_capture_gain_changed(struct cras_client_volume_changed *m,
647 				      int32_t gain)
648 {
649 	m->header.id = CRAS_CLIENT_CAPTURE_GAIN_CHANGED;
650 	m->header.length = sizeof(*m);
651 	m->volume = gain;
652 }
653 
654 struct __attribute__((__packed__)) cras_client_mute_changed {
655 	struct cras_client_message header;
656 	int32_t muted;
657 	int32_t user_muted;
658 	int32_t mute_locked;
659 };
660 static inline void
cras_fill_client_output_mute_changed(struct cras_client_mute_changed * m,int32_t muted,int32_t user_muted,int32_t mute_locked)661 cras_fill_client_output_mute_changed(struct cras_client_mute_changed *m,
662 				     int32_t muted, int32_t user_muted,
663 				     int32_t mute_locked)
664 {
665 	m->header.id = CRAS_CLIENT_OUTPUT_MUTE_CHANGED;
666 	m->header.length = sizeof(*m);
667 	m->muted = muted;
668 	m->user_muted = user_muted;
669 	m->mute_locked = mute_locked;
670 }
671 static inline void
cras_fill_client_capture_mute_changed(struct cras_client_mute_changed * m,int32_t muted,int32_t mute_locked)672 cras_fill_client_capture_mute_changed(struct cras_client_mute_changed *m,
673 				      int32_t muted, int32_t mute_locked)
674 {
675 	m->header.id = CRAS_CLIENT_CAPTURE_MUTE_CHANGED;
676 	m->header.length = sizeof(*m);
677 	m->muted = muted;
678 	m->user_muted = 0;
679 	m->mute_locked = mute_locked;
680 }
681 
682 struct __attribute__((__packed__)) cras_client_nodes_changed {
683 	struct cras_client_message header;
684 };
685 static inline void
cras_fill_client_nodes_changed(struct cras_client_nodes_changed * m)686 cras_fill_client_nodes_changed(struct cras_client_nodes_changed *m)
687 {
688 	m->header.id = CRAS_CLIENT_NODES_CHANGED;
689 	m->header.length = sizeof(*m);
690 }
691 
692 struct __attribute__((__packed__)) cras_client_active_node_changed {
693 	struct cras_client_message header;
694 	uint32_t direction;
695 	cras_node_id_t node_id;
696 };
697 static inline void
cras_fill_client_active_node_changed(struct cras_client_active_node_changed * m,enum CRAS_STREAM_DIRECTION direction,cras_node_id_t node_id)698 cras_fill_client_active_node_changed(struct cras_client_active_node_changed *m,
699 				     enum CRAS_STREAM_DIRECTION direction,
700 				     cras_node_id_t node_id)
701 {
702 	m->header.id = CRAS_CLIENT_ACTIVE_NODE_CHANGED;
703 	m->header.length = sizeof(*m);
704 	m->direction = direction;
705 	m->node_id = node_id;
706 };
707 
708 struct __attribute__((__packed__)) cras_client_node_value_changed {
709 	struct cras_client_message header;
710 	cras_node_id_t node_id;
711 	int32_t value;
712 };
cras_fill_client_output_node_volume_changed(struct cras_client_node_value_changed * m,cras_node_id_t node_id,int32_t volume)713 static inline void cras_fill_client_output_node_volume_changed(
714 	struct cras_client_node_value_changed *m, cras_node_id_t node_id,
715 	int32_t volume)
716 {
717 	m->header.id = CRAS_CLIENT_OUTPUT_NODE_VOLUME_CHANGED;
718 	m->header.length = sizeof(*m);
719 	m->node_id = node_id;
720 	m->value = volume;
721 };
cras_fill_client_node_left_right_swapped_changed(struct cras_client_node_value_changed * m,cras_node_id_t node_id,int swapped)722 static inline void cras_fill_client_node_left_right_swapped_changed(
723 	struct cras_client_node_value_changed *m, cras_node_id_t node_id,
724 	int swapped)
725 {
726 	m->header.id = CRAS_CLIENT_NODE_LEFT_RIGHT_SWAPPED_CHANGED;
727 	m->header.length = sizeof(*m);
728 	m->node_id = node_id;
729 	m->value = swapped;
730 };
cras_fill_client_input_node_gain_changed(struct cras_client_node_value_changed * m,cras_node_id_t node_id,int32_t gain)731 static inline void cras_fill_client_input_node_gain_changed(
732 	struct cras_client_node_value_changed *m, cras_node_id_t node_id,
733 	int32_t gain)
734 {
735 	m->header.id = CRAS_CLIENT_INPUT_NODE_GAIN_CHANGED;
736 	m->header.length = sizeof(*m);
737 	m->node_id = node_id;
738 	m->value = gain;
739 };
740 
741 struct __attribute__((__packed__)) cras_client_num_active_streams_changed {
742 	struct cras_client_message header;
743 	uint32_t direction;
744 	uint32_t num_active_streams;
745 };
cras_fill_client_num_active_streams_changed(struct cras_client_num_active_streams_changed * m,enum CRAS_STREAM_DIRECTION direction,uint32_t num_active_streams)746 static inline void cras_fill_client_num_active_streams_changed(
747 	struct cras_client_num_active_streams_changed *m,
748 	enum CRAS_STREAM_DIRECTION direction, uint32_t num_active_streams)
749 {
750 	m->header.id = CRAS_CLIENT_NUM_ACTIVE_STREAMS_CHANGED;
751 	m->header.length = sizeof(*m);
752 	m->direction = direction;
753 	m->num_active_streams = num_active_streams;
754 };
755 
756 /*
757  * Messages specific to passing audio between client and server
758  */
759 enum CRAS_AUDIO_MESSAGE_ID {
760 	AUDIO_MESSAGE_REQUEST_DATA,
761 	AUDIO_MESSAGE_DATA_READY,
762 	AUDIO_MESSAGE_DATA_CAPTURED,
763 	NUM_AUDIO_MESSAGES
764 };
765 
766 struct __attribute__((__packed__)) audio_message {
767 	enum CRAS_AUDIO_MESSAGE_ID id;
768 	int32_t error;
769 	uint32_t frames; /* number of samples per channel */
770 };
771 
772 #endif /* CRAS_MESSAGES_H_ */
773