2000-09-11 15:49:10 +00:00
|
|
|
/*
|
|
|
|
|
* Control Interface - Hardware
|
2007-10-15 10:24:55 +02:00
|
|
|
* Copyright (c) 1998,1999,2000 by Jaroslav Kysela <perex@perex.cz>
|
2000-09-11 15:49:10 +00:00
|
|
|
* Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or modify
|
2001-12-30 09:22:54 +00:00
|
|
|
* it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
* published by the Free Software Foundation; either version 2.1 of
|
2000-09-11 15:49:10 +00:00
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2001-12-30 09:22:54 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2000-09-11 15:49:10 +00:00
|
|
|
*
|
2001-12-30 09:22:54 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2000-09-11 15:49:10 +00:00
|
|
|
* License along with this library; if not, write to the Free Software
|
2017-11-14 14:29:26 +01:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2000-09-11 15:49:10 +00:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <unistd.h>
|
2001-02-09 11:20:31 +00:00
|
|
|
#include <signal.h>
|
2000-09-11 15:49:10 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
#include "control_local.h"
|
|
|
|
|
|
2001-10-24 14:14:11 +00:00
|
|
|
#ifndef PIC
|
|
|
|
|
/* entry for static linking */
|
|
|
|
|
const char *_snd_module_control_hw = "";
|
|
|
|
|
#endif
|
|
|
|
|
|
2001-02-09 11:20:31 +00:00
|
|
|
#ifndef F_SETSIG
|
|
|
|
|
#define F_SETSIG 10
|
|
|
|
|
#endif
|
|
|
|
|
|
2005-05-24 14:14:28 +00:00
|
|
|
#ifndef DOC_HIDDEN
|
2006-02-27 10:03:19 +00:00
|
|
|
#define SNDRV_FILE_CONTROL ALSA_DEVICE_DIRECTORY "controlC%i"
|
2006-09-17 22:06:46 +02:00
|
|
|
#define SNDRV_CTL_VERSION_MAX SNDRV_PROTOCOL_VERSION(2, 0, 4)
|
2000-09-11 15:49:10 +00:00
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
int card;
|
|
|
|
|
int fd;
|
2006-09-17 22:06:46 +02:00
|
|
|
unsigned int protocol;
|
2000-09-11 15:49:10 +00:00
|
|
|
} snd_ctl_hw_t;
|
2005-05-24 14:14:28 +00:00
|
|
|
#endif /* DOC_HIDDEN */
|
2000-09-11 15:49:10 +00:00
|
|
|
|
|
|
|
|
static int snd_ctl_hw_close(snd_ctl_t *handle)
|
|
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_ctl_hw_t *hw = handle->private_data;
|
2000-09-11 15:49:10 +00:00
|
|
|
int res;
|
|
|
|
|
res = close(hw->fd) < 0 ? -errno : 0;
|
|
|
|
|
free(hw);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2001-02-09 11:20:31 +00:00
|
|
|
static int snd_ctl_hw_nonblock(snd_ctl_t *handle, int nonblock)
|
|
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_ctl_hw_t *hw = handle->private_data;
|
2001-02-09 11:20:31 +00:00
|
|
|
long flags;
|
|
|
|
|
int fd = hw->fd;
|
|
|
|
|
if ((flags = fcntl(fd, F_GETFL)) < 0) {
|
|
|
|
|
SYSERR("F_GETFL failed");
|
|
|
|
|
return -errno;
|
|
|
|
|
}
|
|
|
|
|
if (nonblock)
|
|
|
|
|
flags |= O_NONBLOCK;
|
|
|
|
|
else
|
|
|
|
|
flags &= ~O_NONBLOCK;
|
|
|
|
|
if (fcntl(fd, F_SETFL, flags) < 0) {
|
|
|
|
|
SYSERR("F_SETFL for O_NONBLOCK failed");
|
|
|
|
|
return -errno;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int snd_ctl_hw_async(snd_ctl_t *ctl, int sig, pid_t pid)
|
|
|
|
|
{
|
|
|
|
|
long flags;
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_ctl_hw_t *hw = ctl->private_data;
|
2001-02-09 11:20:31 +00:00
|
|
|
int fd = hw->fd;
|
|
|
|
|
|
|
|
|
|
if ((flags = fcntl(fd, F_GETFL)) < 0) {
|
|
|
|
|
SYSERR("F_GETFL failed");
|
|
|
|
|
return -errno;
|
|
|
|
|
}
|
|
|
|
|
if (sig >= 0)
|
|
|
|
|
flags |= O_ASYNC;
|
|
|
|
|
else
|
|
|
|
|
flags &= ~O_ASYNC;
|
|
|
|
|
if (fcntl(fd, F_SETFL, flags) < 0) {
|
|
|
|
|
SYSERR("F_SETFL for O_ASYNC failed");
|
|
|
|
|
return -errno;
|
|
|
|
|
}
|
|
|
|
|
if (sig < 0)
|
|
|
|
|
return 0;
|
2001-10-18 12:33:45 +00:00
|
|
|
if (fcntl(fd, F_SETSIG, (long)sig) < 0) {
|
2001-02-09 11:20:31 +00:00
|
|
|
SYSERR("F_SETSIG failed");
|
|
|
|
|
return -errno;
|
|
|
|
|
}
|
2001-10-18 12:33:45 +00:00
|
|
|
if (fcntl(fd, F_SETOWN, (long)pid) < 0) {
|
2001-02-09 11:20:31 +00:00
|
|
|
SYSERR("F_SETOWN failed");
|
|
|
|
|
return -errno;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-02-13 21:29:30 +00:00
|
|
|
static int snd_ctl_hw_subscribe_events(snd_ctl_t *handle, int subscribe)
|
2000-09-11 15:49:10 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_ctl_hw_t *hw = handle->private_data;
|
2001-02-13 21:29:30 +00:00
|
|
|
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_SUBSCRIBE_EVENTS, &subscribe) < 0) {
|
|
|
|
|
SYSERR("SNDRV_CTL_IOCTL_SUBSCRIBE_EVENTS failed");
|
|
|
|
|
return -errno;
|
|
|
|
|
}
|
2008-09-30 14:44:12 +02:00
|
|
|
return 0;
|
2001-02-13 21:29:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int snd_ctl_hw_card_info(snd_ctl_t *handle, snd_ctl_card_info_t *info)
|
|
|
|
|
{
|
|
|
|
|
snd_ctl_hw_t *hw = handle->private_data;
|
2001-02-14 08:26:33 +00:00
|
|
|
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_CARD_INFO, info) < 0) {
|
2001-02-13 21:29:30 +00:00
|
|
|
SYSERR("SNDRV_CTL_IOCTL_CARD_INFO failed");
|
2000-09-11 15:49:10 +00:00
|
|
|
return -errno;
|
2001-02-14 08:26:33 +00:00
|
|
|
}
|
2000-09-11 15:49:10 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-02-09 11:20:31 +00:00
|
|
|
static int snd_ctl_hw_elem_list(snd_ctl_t *handle, snd_ctl_elem_list_t *list)
|
2000-09-11 15:49:10 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_ctl_hw_t *hw = handle->private_data;
|
2001-02-09 11:20:31 +00:00
|
|
|
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_ELEM_LIST, list) < 0)
|
2000-09-11 15:49:10 +00:00
|
|
|
return -errno;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-02-09 11:20:31 +00:00
|
|
|
static int snd_ctl_hw_elem_info(snd_ctl_t *handle, snd_ctl_elem_info_t *info)
|
2000-09-11 15:49:10 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_ctl_hw_t *hw = handle->private_data;
|
2001-02-09 11:20:31 +00:00
|
|
|
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_ELEM_INFO, info) < 0)
|
2000-09-11 15:49:10 +00:00
|
|
|
return -errno;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2003-10-21 17:39:14 +00:00
|
|
|
static int snd_ctl_hw_elem_add(snd_ctl_t *handle, snd_ctl_elem_info_t *info)
|
|
|
|
|
{
|
|
|
|
|
snd_ctl_hw_t *hw = handle->private_data;
|
2011-10-07 22:46:51 +02:00
|
|
|
|
|
|
|
|
if (info->type == SNDRV_CTL_ELEM_TYPE_ENUMERATED &&
|
|
|
|
|
hw->protocol < SNDRV_PROTOCOL_VERSION(2, 0, 7))
|
|
|
|
|
return -ENXIO;
|
|
|
|
|
|
2003-10-21 17:39:14 +00:00
|
|
|
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_ELEM_ADD, info) < 0)
|
|
|
|
|
return -errno;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int snd_ctl_hw_elem_replace(snd_ctl_t *handle, snd_ctl_elem_info_t *info)
|
|
|
|
|
{
|
|
|
|
|
snd_ctl_hw_t *hw = handle->private_data;
|
2011-10-07 22:46:51 +02:00
|
|
|
|
|
|
|
|
if (info->type == SNDRV_CTL_ELEM_TYPE_ENUMERATED &&
|
|
|
|
|
hw->protocol < SNDRV_PROTOCOL_VERSION(2, 0, 7))
|
|
|
|
|
return -ENXIO;
|
|
|
|
|
|
2003-10-21 17:39:14 +00:00
|
|
|
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_ELEM_REPLACE, info) < 0)
|
|
|
|
|
return -errno;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int snd_ctl_hw_elem_remove(snd_ctl_t *handle, snd_ctl_elem_id_t *id)
|
|
|
|
|
{
|
|
|
|
|
snd_ctl_hw_t *hw = handle->private_data;
|
|
|
|
|
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_ELEM_REMOVE, id) < 0)
|
|
|
|
|
return -errno;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-02-11 15:45:35 +00:00
|
|
|
static int snd_ctl_hw_elem_read(snd_ctl_t *handle, snd_ctl_elem_value_t *control)
|
2000-09-11 15:49:10 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_ctl_hw_t *hw = handle->private_data;
|
2001-02-09 11:20:31 +00:00
|
|
|
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_ELEM_READ, control) < 0)
|
2000-09-11 15:49:10 +00:00
|
|
|
return -errno;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-02-11 15:45:35 +00:00
|
|
|
static int snd_ctl_hw_elem_write(snd_ctl_t *handle, snd_ctl_elem_value_t *control)
|
2000-09-11 15:49:10 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_ctl_hw_t *hw = handle->private_data;
|
2001-02-09 11:20:31 +00:00
|
|
|
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_ELEM_WRITE, control) < 0)
|
2000-09-11 15:49:10 +00:00
|
|
|
return -errno;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-19 13:53:39 +00:00
|
|
|
static int snd_ctl_hw_elem_lock(snd_ctl_t *handle, snd_ctl_elem_id_t *id)
|
|
|
|
|
{
|
|
|
|
|
snd_ctl_hw_t *hw = handle->private_data;
|
|
|
|
|
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_ELEM_LOCK, id) < 0)
|
|
|
|
|
return -errno;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int snd_ctl_hw_elem_unlock(snd_ctl_t *handle, snd_ctl_elem_id_t *id)
|
|
|
|
|
{
|
|
|
|
|
snd_ctl_hw_t *hw = handle->private_data;
|
|
|
|
|
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_ELEM_UNLOCK, id) < 0)
|
|
|
|
|
return -errno;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2006-07-05 17:42:16 +02:00
|
|
|
static int snd_ctl_hw_elem_tlv(snd_ctl_t *handle, int op_flag,
|
|
|
|
|
unsigned int numid,
|
|
|
|
|
unsigned int *tlv, unsigned int tlv_size)
|
|
|
|
|
{
|
2018-08-17 11:12:27 +08:00
|
|
|
unsigned int inum;
|
2006-07-05 17:42:16 +02:00
|
|
|
snd_ctl_hw_t *hw = handle->private_data;
|
2012-11-26 17:54:29 +01:00
|
|
|
struct snd_ctl_tlv *xtlv;
|
2006-07-05 17:42:16 +02:00
|
|
|
|
2006-09-17 22:06:46 +02:00
|
|
|
/* we don't support TLV on protocol ver 2.0.3 or earlier */
|
|
|
|
|
if (hw->protocol < SNDRV_PROTOCOL_VERSION(2, 0, 4))
|
|
|
|
|
return -ENXIO;
|
|
|
|
|
|
2006-07-05 17:42:16 +02:00
|
|
|
switch (op_flag) {
|
|
|
|
|
case -1: inum = SNDRV_CTL_IOCTL_TLV_COMMAND; break;
|
|
|
|
|
case 0: inum = SNDRV_CTL_IOCTL_TLV_READ; break;
|
|
|
|
|
case 1: inum = SNDRV_CTL_IOCTL_TLV_WRITE; break;
|
|
|
|
|
default: return -EINVAL;
|
|
|
|
|
}
|
2012-11-26 17:54:29 +01:00
|
|
|
xtlv = malloc(sizeof(struct snd_ctl_tlv) + tlv_size);
|
2006-07-05 17:42:16 +02:00
|
|
|
if (xtlv == NULL)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
xtlv->numid = numid;
|
|
|
|
|
xtlv->length = tlv_size;
|
|
|
|
|
memcpy(xtlv->tlv, tlv, tlv_size);
|
|
|
|
|
if (ioctl(hw->fd, inum, xtlv) < 0) {
|
|
|
|
|
free(xtlv);
|
|
|
|
|
return -errno;
|
|
|
|
|
}
|
|
|
|
|
if (op_flag == 0) {
|
2018-05-15 21:36:35 +09:00
|
|
|
unsigned int size;
|
|
|
|
|
size = xtlv->tlv[SNDRV_CTL_TLVO_LEN] + 2 * sizeof(unsigned int);
|
|
|
|
|
if (size > tlv_size) {
|
2014-01-22 00:12:50 +04:00
|
|
|
free(xtlv);
|
2006-07-05 17:42:16 +02:00
|
|
|
return -EFAULT;
|
2014-01-22 00:12:50 +04:00
|
|
|
}
|
2018-05-15 21:36:35 +09:00
|
|
|
memcpy(tlv, xtlv->tlv, size);
|
2006-07-05 17:42:16 +02:00
|
|
|
}
|
|
|
|
|
free(xtlv);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-11-30 19:17:55 +00:00
|
|
|
static int snd_ctl_hw_hwdep_next_device(snd_ctl_t *handle, int * device)
|
|
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_ctl_hw_t *hw = handle->private_data;
|
2001-01-29 14:27:53 +00:00
|
|
|
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_HWDEP_NEXT_DEVICE, device) < 0)
|
2000-11-30 19:17:55 +00:00
|
|
|
return -errno;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-11 15:49:10 +00:00
|
|
|
static int snd_ctl_hw_hwdep_info(snd_ctl_t *handle, snd_hwdep_info_t * info)
|
|
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_ctl_hw_t *hw = handle->private_data;
|
2001-01-29 14:27:53 +00:00
|
|
|
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_HWDEP_INFO, info) < 0)
|
2000-09-11 15:49:10 +00:00
|
|
|
return -errno;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-11-30 19:17:55 +00:00
|
|
|
static int snd_ctl_hw_pcm_next_device(snd_ctl_t *handle, int * device)
|
|
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_ctl_hw_t *hw = handle->private_data;
|
2001-01-29 14:27:53 +00:00
|
|
|
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_PCM_NEXT_DEVICE, device) < 0)
|
2000-11-30 19:17:55 +00:00
|
|
|
return -errno;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-11 15:49:10 +00:00
|
|
|
static int snd_ctl_hw_pcm_info(snd_ctl_t *handle, snd_pcm_info_t * info)
|
|
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_ctl_hw_t *hw = handle->private_data;
|
2001-01-29 14:27:53 +00:00
|
|
|
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_PCM_INFO, info) < 0)
|
2000-09-11 15:49:10 +00:00
|
|
|
return -errno;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int snd_ctl_hw_pcm_prefer_subdevice(snd_ctl_t *handle, int subdev)
|
|
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_ctl_hw_t *hw = handle->private_data;
|
2001-01-29 14:27:53 +00:00
|
|
|
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_PCM_PREFER_SUBDEVICE, &subdev) < 0)
|
2000-09-11 15:49:10 +00:00
|
|
|
return -errno;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-11-30 19:17:55 +00:00
|
|
|
static int snd_ctl_hw_rawmidi_next_device(snd_ctl_t *handle, int * device)
|
|
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_ctl_hw_t *hw = handle->private_data;
|
2001-01-29 14:27:53 +00:00
|
|
|
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_RAWMIDI_NEXT_DEVICE, device) < 0)
|
2000-11-30 19:17:55 +00:00
|
|
|
return -errno;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-11 15:49:10 +00:00
|
|
|
static int snd_ctl_hw_rawmidi_info(snd_ctl_t *handle, snd_rawmidi_info_t * info)
|
|
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_ctl_hw_t *hw = handle->private_data;
|
2001-01-29 14:27:53 +00:00
|
|
|
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_RAWMIDI_INFO, info) < 0)
|
2000-09-11 15:49:10 +00:00
|
|
|
return -errno;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-10-30 12:15:18 +00:00
|
|
|
static int snd_ctl_hw_rawmidi_prefer_subdevice(snd_ctl_t *handle, int subdev)
|
|
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_ctl_hw_t *hw = handle->private_data;
|
2001-01-29 14:27:53 +00:00
|
|
|
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_RAWMIDI_PREFER_SUBDEVICE, &subdev) < 0)
|
2000-10-30 12:15:18 +00:00
|
|
|
return -errno;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-09-26 13:57:04 +00:00
|
|
|
static int snd_ctl_hw_set_power_state(snd_ctl_t *handle, unsigned int state)
|
|
|
|
|
{
|
|
|
|
|
snd_ctl_hw_t *hw = handle->private_data;
|
|
|
|
|
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_POWER, &state) < 0)
|
|
|
|
|
return -errno;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int snd_ctl_hw_get_power_state(snd_ctl_t *handle, unsigned int *state)
|
|
|
|
|
{
|
|
|
|
|
snd_ctl_hw_t *hw = handle->private_data;
|
|
|
|
|
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_POWER_STATE, state) < 0)
|
|
|
|
|
return -errno;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-11 15:49:10 +00:00
|
|
|
static int snd_ctl_hw_read(snd_ctl_t *handle, snd_ctl_event_t *event)
|
|
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_ctl_hw_t *hw = handle->private_data;
|
2001-02-09 11:20:31 +00:00
|
|
|
ssize_t res = read(hw->fd, event, sizeof(*event));
|
|
|
|
|
if (res <= 0)
|
2001-02-11 17:46:03 +00:00
|
|
|
return -errno;
|
2008-09-30 14:43:14 +02:00
|
|
|
if (CHECK_SANITY(res != sizeof(*event))) {
|
|
|
|
|
SNDMSG("snd_ctl_hw_read: read size error (req:%d, got:%d)\n",
|
|
|
|
|
sizeof(*event), res);
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
2001-02-09 11:20:31 +00:00
|
|
|
return 1;
|
2000-09-11 15:49:10 +00:00
|
|
|
}
|
|
|
|
|
|
2008-11-21 20:26:12 +01:00
|
|
|
static const snd_ctl_ops_t snd_ctl_hw_ops = {
|
2003-07-25 17:02:00 +00:00
|
|
|
.close = snd_ctl_hw_close,
|
|
|
|
|
.nonblock = snd_ctl_hw_nonblock,
|
|
|
|
|
.async = snd_ctl_hw_async,
|
|
|
|
|
.subscribe_events = snd_ctl_hw_subscribe_events,
|
|
|
|
|
.card_info = snd_ctl_hw_card_info,
|
|
|
|
|
.element_list = snd_ctl_hw_elem_list,
|
|
|
|
|
.element_info = snd_ctl_hw_elem_info,
|
2003-10-21 17:39:14 +00:00
|
|
|
.element_add = snd_ctl_hw_elem_add,
|
|
|
|
|
.element_replace = snd_ctl_hw_elem_replace,
|
|
|
|
|
.element_remove = snd_ctl_hw_elem_remove,
|
2003-07-25 17:02:00 +00:00
|
|
|
.element_read = snd_ctl_hw_elem_read,
|
|
|
|
|
.element_write = snd_ctl_hw_elem_write,
|
|
|
|
|
.element_lock = snd_ctl_hw_elem_lock,
|
|
|
|
|
.element_unlock = snd_ctl_hw_elem_unlock,
|
2006-07-05 17:42:16 +02:00
|
|
|
.element_tlv = snd_ctl_hw_elem_tlv,
|
2003-07-25 17:02:00 +00:00
|
|
|
.hwdep_next_device = snd_ctl_hw_hwdep_next_device,
|
|
|
|
|
.hwdep_info = snd_ctl_hw_hwdep_info,
|
|
|
|
|
.pcm_next_device = snd_ctl_hw_pcm_next_device,
|
|
|
|
|
.pcm_info = snd_ctl_hw_pcm_info,
|
|
|
|
|
.pcm_prefer_subdevice = snd_ctl_hw_pcm_prefer_subdevice,
|
|
|
|
|
.rawmidi_next_device = snd_ctl_hw_rawmidi_next_device,
|
|
|
|
|
.rawmidi_info = snd_ctl_hw_rawmidi_info,
|
|
|
|
|
.rawmidi_prefer_subdevice = snd_ctl_hw_rawmidi_prefer_subdevice,
|
|
|
|
|
.set_power_state = snd_ctl_hw_set_power_state,
|
|
|
|
|
.get_power_state = snd_ctl_hw_get_power_state,
|
|
|
|
|
.read = snd_ctl_hw_read,
|
2000-09-11 15:49:10 +00:00
|
|
|
};
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
int snd_ctl_hw_open(snd_ctl_t **handle, const char *name, int card, int mode)
|
2000-09-11 15:49:10 +00:00
|
|
|
{
|
|
|
|
|
int fd, ver;
|
2006-02-27 10:03:19 +00:00
|
|
|
char filename[sizeof(SNDRV_FILE_CONTROL) + 10];
|
2001-03-26 12:45:48 +00:00
|
|
|
int fmode;
|
2000-09-11 15:49:10 +00:00
|
|
|
snd_ctl_t *ctl;
|
|
|
|
|
snd_ctl_hw_t *hw;
|
2001-06-20 20:52:12 +00:00
|
|
|
int err;
|
2000-09-11 15:49:10 +00:00
|
|
|
|
|
|
|
|
*handle = NULL;
|
|
|
|
|
|
2013-05-24 17:21:15 +02:00
|
|
|
if (CHECK_SANITY(card < 0 || card >= SND_MAX_CARDS)) {
|
2008-09-30 14:43:14 +02:00
|
|
|
SNDMSG("Invalid card index %d", card);
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
2001-01-29 14:27:53 +00:00
|
|
|
sprintf(filename, SNDRV_FILE_CONTROL, card);
|
2002-12-04 14:36:39 +00:00
|
|
|
if (mode & SND_CTL_READONLY)
|
|
|
|
|
fmode = O_RDONLY;
|
|
|
|
|
else
|
|
|
|
|
fmode = O_RDWR;
|
2001-03-26 12:45:48 +00:00
|
|
|
if (mode & SND_CTL_NONBLOCK)
|
|
|
|
|
fmode |= O_NONBLOCK;
|
|
|
|
|
if (mode & SND_CTL_ASYNC)
|
|
|
|
|
fmode |= O_ASYNC;
|
2005-02-11 16:35:24 +00:00
|
|
|
fd = snd_open_device(filename, fmode);
|
2005-01-26 10:50:28 +00:00
|
|
|
if (fd < 0) {
|
2000-09-11 15:49:10 +00:00
|
|
|
snd_card_load(card);
|
2005-02-11 16:35:24 +00:00
|
|
|
fd = snd_open_device(filename, fmode);
|
2005-01-26 10:50:28 +00:00
|
|
|
if (fd < 0)
|
2000-09-11 15:49:10 +00:00
|
|
|
return -errno;
|
|
|
|
|
}
|
2001-01-29 14:27:53 +00:00
|
|
|
if (ioctl(fd, SNDRV_CTL_IOCTL_PVERSION, &ver) < 0) {
|
2003-02-04 13:35:59 +00:00
|
|
|
err = -errno;
|
2000-09-11 15:49:10 +00:00
|
|
|
close(fd);
|
2003-02-04 13:35:59 +00:00
|
|
|
return err;
|
2000-09-11 15:49:10 +00:00
|
|
|
}
|
2001-01-29 14:27:53 +00:00
|
|
|
if (SNDRV_PROTOCOL_INCOMPATIBLE(ver, SNDRV_CTL_VERSION_MAX)) {
|
2000-09-11 15:49:10 +00:00
|
|
|
close(fd);
|
|
|
|
|
return -SND_ERROR_INCOMPATIBLE_VERSION;
|
|
|
|
|
}
|
|
|
|
|
hw = calloc(1, sizeof(snd_ctl_hw_t));
|
|
|
|
|
if (hw == NULL) {
|
|
|
|
|
close(fd);
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
}
|
|
|
|
|
hw->card = card;
|
|
|
|
|
hw->fd = fd;
|
2006-09-17 22:06:46 +02:00
|
|
|
hw->protocol = ver;
|
2001-06-20 20:52:12 +00:00
|
|
|
|
|
|
|
|
err = snd_ctl_new(&ctl, SND_CTL_TYPE_HW, name);
|
|
|
|
|
if (err < 0) {
|
|
|
|
|
close(fd);
|
|
|
|
|
free(hw);
|
2011-06-03 17:27:27 +02:00
|
|
|
return err;
|
2001-06-20 20:52:12 +00:00
|
|
|
}
|
2000-09-11 15:49:10 +00:00
|
|
|
ctl->ops = &snd_ctl_hw_ops;
|
2001-02-11 15:45:35 +00:00
|
|
|
ctl->private_data = hw;
|
2001-06-20 20:52:12 +00:00
|
|
|
ctl->poll_fd = fd;
|
2000-09-11 15:49:10 +00:00
|
|
|
*handle = ctl;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-09 17:14:22 +00:00
|
|
|
int _snd_ctl_hw_open(snd_ctl_t **handlep, char *name, snd_config_t *root ATTRIBUTE_UNUSED, snd_config_t *conf, int mode)
|
2000-10-14 10:31:34 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_config_iterator_t i, next;
|
2000-10-14 10:31:34 +00:00
|
|
|
long card = -1;
|
2001-02-06 23:48:10 +00:00
|
|
|
const char *str;
|
2000-10-14 10:31:34 +00:00
|
|
|
int err;
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_config_for_each(i, next, conf) {
|
2001-02-07 11:34:33 +00:00
|
|
|
snd_config_t *n = snd_config_iterator_entry(i);
|
2001-11-19 08:14:21 +00:00
|
|
|
const char *id;
|
|
|
|
|
if (snd_config_get_id(n, &id) < 0)
|
|
|
|
|
continue;
|
2015-04-30 14:52:35 +02:00
|
|
|
if (_snd_conf_generic_id(id))
|
2000-10-14 10:31:34 +00:00
|
|
|
continue;
|
2001-02-07 11:34:33 +00:00
|
|
|
if (strcmp(id, "card") == 0) {
|
|
|
|
|
err = snd_config_get_integer(n, &card);
|
2000-10-14 10:31:34 +00:00
|
|
|
if (err < 0) {
|
2001-02-07 11:34:33 +00:00
|
|
|
err = snd_config_get_string(n, &str);
|
2000-10-14 10:31:34 +00:00
|
|
|
if (err < 0)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
card = snd_card_get_index(str);
|
|
|
|
|
if (card < 0)
|
|
|
|
|
return card;
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
if (card < 0)
|
|
|
|
|
return -EINVAL;
|
2005-06-09 17:14:22 +00:00
|
|
|
return snd_ctl_hw_open(handlep, name, card, mode);
|
2000-10-14 10:31:34 +00:00
|
|
|
}
|
2001-10-24 14:14:11 +00:00
|
|
|
SND_DLSYM_BUILD_VERSION(_snd_ctl_hw_open, SND_CONTROL_DLSYM_VERSION);
|