I am currently writing a Linux Kernel module that will create a virtual Midi device so that a user-space program can send midi signals to any DAW-like software. I found a wonderful function to help me in my task: int register_sound_midi(const struct file_operations * fops, int dev)
. The problem is that this function ceased to exist after Kernel Version 4.15. From V15 to V16 the register and unregister functions just disappear. I'm now dumbfounded on how to register a fake midi device from the kernel in versions post 4.15. How can I register a midi device in versions of Kernel post 4.15? Is it possible to make the module backwards compatible with older kernel versions?
Current Code:
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/sound.h>
#include <sound/core.h>
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Module to create dummy midi devices.");
MODULE_VERSION("0.01");
static int dummy_midi_open(struct inode *, struct file *);
static int dummy_midi_release(struct inode *, struct file *);
static ssize_t dummy_midi_read(struct file *, char *, size_t, loff_t *);
static ssize_t dummy_midi_write(struct file *, const char *, size_t, loff_t *);
static struct file_operations dummy_midi_fops = {
.owner = THIS_MODULE,
.read = dummy_midi_read,
.write = dummy_midi_write,
.open = dummy_midi_open,
.release = dummy_midi_release
};
static int minor;
static int dummy_midi_open(struct inode *midi_inode, struct file *midi_file)
{
printk(KERN_INFO"Open\n");
return 0;
}
static int dummy_midi_release(struct inode *midi_inode, struct file *midi_file)
{
printk(KERN_INFO"Release\n");
return 0;
}
static ssize_t dummy_midi_read(struct file *filp, char *buf, size_t count, loff_t *f_pos)
{
printk(KERN_INFO"Read\n");
return 0;
}
static ssize_t dummy_midi_write(struct file *filp, const char *buf, size_t count, loff_t *f_pos)
{
printk(KERN_INFO"Write\n");
return 0;
}
static int __init midimodule_init(void)
{
printk(KERN_INFO"Initializing Module\n");
minor = register_sound_midi(&dummy_midi_fops,-1);
printk(KERN_INFO"Registered MIDI Device: %d\n",minor);
return 0;
}
static void __exit midimodule_exit(void)
{
printk(KERN_INFO"Leaving now\n");
unregister_sound_midi(minor);
printk(KERN_INFO"Unregistered MIDI Device: %d\n",minor);
}
module_init(midimodule_init);
module_exit(midimodule_exit);