1 // Copyright 2017 The Fuchsia 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 #include <stdio.h>
6 #include <unistd.h>
7 #include <fcntl.h>
8 #include <string.h>
9 #include <zircon/device/audio-codec.h>
10 
cmd_enable(const char * dev,bool enable)11 static int cmd_enable(const char* dev, bool enable) {
12     int fd = open(dev, O_RDONLY);
13     if (fd < 0) {
14         printf("Error opening %s\n", dev);
15         return fd;
16     }
17 
18     ssize_t rc = ioctl_audio_codec_enable(fd, &enable);
19     if (rc < 0) {
20         printf("Error enabling for %s (rc %zd)\n", dev, rc);
21         close(fd);
22         goto out;
23     }
24 
25 out:
26     close(fd);
27     return rc;
28 }
29 
main(int argc,const char ** argv)30 int main(int argc, const char** argv) {
31     int rc = 0;
32     const char *cmd = argc > 1 ? argv[1] : NULL;
33     if (cmd) {
34         if (!strcmp(cmd, "help")) {
35             goto usage;
36         } else if (!strcmp(cmd, "enable")) {
37             if (argc < 3) goto usage;
38             rc = cmd_enable(argv[2], true);
39         } else if (!strcmp(cmd, "disable")) {
40             if (argc < 3) goto usage;
41             rc = cmd_enable(argv[2], false);
42         } else {
43             printf("Unrecognized command %s!\n", cmd);
44             goto usage;
45         }
46     } else {
47         goto usage;
48     }
49     return rc;
50 usage:
51     printf("Usage:\n");
52     printf("%s\n", argv[0]);
53     printf("%s enable <codecdev>\n", argv[0]);
54     printf("%s disable <codecdev>\n", argv[0]);
55     return 0;
56 }
57