/* * check the name id of the given hwdep handle */ static int check_hwinfo(snd_hwdep_t *hw, const char *id) { snd_hwdep_info_t *info; int err; snd_hwdep_info_alloca(&info); if ((err = snd_hwdep_info(hw, info)) < 0) return err; if (strcmp(snd_hwdep_info_get_id(info), id)) return -ENODEV; return 0; /* ok */ }
static int snd_hwdep_control_ioctl(struct snd_card *card, struct snd_ctl_file * control, unsigned int cmd, unsigned long arg) { switch (cmd) { case SNDRV_CTL_IOCTL_HWDEP_NEXT_DEVICE: { int device; if (get_user(device, (int __user *)arg)) return -EFAULT; mutex_lock(®ister_mutex); if (device < 0) device = 0; else if (device < SNDRV_MINOR_HWDEPS) device++; else device = SNDRV_MINOR_HWDEPS; while (device < SNDRV_MINOR_HWDEPS) { if (snd_hwdep_search(card, device)) break; device++; } if (device >= SNDRV_MINOR_HWDEPS) device = -1; mutex_unlock(®ister_mutex); if (put_user(device, (int __user *)arg)) return -EFAULT; return 0; } case SNDRV_CTL_IOCTL_HWDEP_INFO: { struct snd_hwdep_info __user *info = (struct snd_hwdep_info __user *)arg; int device, err; struct snd_hwdep *hwdep; if (get_user(device, &info->device)) return -EFAULT; mutex_lock(®ister_mutex); hwdep = snd_hwdep_search(card, device); if (hwdep) err = snd_hwdep_info(hwdep, info); else err = -ENXIO; mutex_unlock(®ister_mutex); return err; } } return -ENOIOCTLCMD; }
static int init(void) { const char* device; snd_hwdep_info_t* info; struct pollfd pollfd; int err; device = drv.device; if (!device || !*device) { device = search_device(); if (!device) { logprintf(LIRC_ERROR, "device not found"); return 0; } } err = snd_hwdep_open(&hwdep, device, SND_HWDEP_OPEN_READ); if (err < 0) { logprintf(LIRC_ERROR, "cannot open %s: %s", device, snd_strerror(err)); return 0; } snd_hwdep_info_alloca(&info); err = snd_hwdep_info(hwdep, info); if (err < 0) { snd_hwdep_close(hwdep); logprintf(LIRC_ERROR, "cannot get hwdep info: %s", snd_strerror(err)); return 0; } if (snd_hwdep_info_get_iface(info) != SND_HWDEP_IFACE_SB_RC) { snd_hwdep_close(hwdep); logprintf(LIRC_ERROR, "%s is not a Sound Blaster remote control device", device); return 0; } err = snd_hwdep_poll_descriptors(hwdep, &pollfd, 1); if (err < 0) { snd_hwdep_close(hwdep); logprintf(LIRC_ERROR, "cannot get file descriptor: %s", snd_strerror(err)); return 0; } if (err != 1) { snd_hwdep_close(hwdep); logprintf(LIRC_ERROR, "invalid number of file descriptors (%d): %s", err, snd_strerror(err)); return 0; } drv.fd = pollfd.fd; return 1; }
static long snd_hwdep_ioctl(struct file * file, unsigned int cmd, unsigned long arg) { snd_hwdep_t *hw = file->private_data; void __user *argp = (void __user *)arg; switch (cmd) { case SNDRV_HWDEP_IOCTL_PVERSION: return put_user(SNDRV_HWDEP_VERSION, (int __user *)argp); case SNDRV_HWDEP_IOCTL_INFO: return snd_hwdep_info(hw, argp); case SNDRV_HWDEP_IOCTL_DSP_STATUS: return snd_hwdep_dsp_status(hw, argp); case SNDRV_HWDEP_IOCTL_DSP_LOAD: return snd_hwdep_dsp_load(hw, argp); } if (hw->ops.ioctl) return hw->ops.ioctl(hw, file, cmd, arg); return -ENOTTY; }
static int snd_hwdep_control_ioctl(snd_card_t * card, snd_ctl_file_t * control, unsigned int cmd, unsigned long arg) { unsigned int tmp; tmp = card->number * SNDRV_MINOR_HWDEPS; switch (cmd) { case SNDRV_CTL_IOCTL_HWDEP_NEXT_DEVICE: { int device; if (get_user(device, (int __user *)arg)) return -EFAULT; device = device < 0 ? 0 : device + 1; while (device < SNDRV_MINOR_HWDEPS) { if (snd_hwdep_devices[tmp + device]) break; device++; } if (device >= SNDRV_MINOR_HWDEPS) device = -1; if (put_user(device, (int __user *)arg)) return -EFAULT; return 0; } case SNDRV_CTL_IOCTL_HWDEP_INFO: { snd_hwdep_info_t __user *info = (snd_hwdep_info_t __user *)arg; int device; snd_hwdep_t *hwdep; if (get_user(device, &info->device)) return -EFAULT; if (device < 0 || device >= SNDRV_MINOR_HWDEPS) return -ENXIO; hwdep = snd_hwdep_devices[tmp + device]; if (hwdep == NULL) return -ENXIO; return snd_hwdep_info(hwdep, info); } } return -ENOIOCTLCMD; }