Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <linux/module.h> // included for all kernel modules
- #include <linux/kernel.h> // included for KERN_INFO
- #include <linux/init.h> // included for __init and __exit macros
- #include <linux/tty.h>
- MODULE_LICENSE("GPL");
- MODULE_AUTHOR("Okash");
- MODULE_DESCRIPTION("Speakup Test");
- static int speakup_test_open(struct tty_struct *tty)
- {
- int rv;
- pr_warn("speakup_test_open(): tty->name: %s; tty->ldisc->ops->name: %s\n",
- tty->name, tty->ldisc->ops->name);
- rv = tty->ops->write(tty, "hi ldisc\n", 9);
- pr_warn("speakup_test_open(): done writing. rv=%d\n", rv);
- return 0;
- }
- static void speakup_test_close(struct tty_struct *tty)
- {
- pr_warn("speakup_test_close()\n");
- }
- static struct tty_ldisc_ops hello_ldisc_ops = {
- .owner = THIS_MODULE,
- .magic = TTY_LDISC_MAGIC,
- .name = "speakup_test_ldisc",
- .open = speakup_test_open,
- .close = speakup_test_close,
- };
- static struct tty_struct *tty;
- static int __init speakup_test_init(void)
- {
- int ret = 0;
- ret = tty_register_ldisc(N_SPEAKUP, &hello_ldisc_ops);
- if (ret) {
- pr_err("speakup_test_init(): Error registering line discipline.\n");
- return ret;
- }
- tty = tty_open_by_driver(MKDEV(4, 64), NULL, NULL);
- if (IS_ERR(tty))
- return PTR_ERR(tty);
- printk("got tty %p\n", tty);
- if (tty->ops->open)
- ret = tty->ops->open(tty, NULL);
- else
- ret = -ENODEV;
- /* to be put in ldisc open */
- if (tty->ops->write == NULL)
- ret = -EOPNOTSUPP;
- /* */
- if (ret) {
- tty_unlock(tty);
- return ret;
- }
- clear_bit(TTY_HUPPED, &tty->flags);
- tty_unlock(tty);
- tty_set_ldisc(tty, N_SPEAKUP);
- tty->ops->write(tty, "test\n", 5);
- return ret;
- }
- static void __exit speakup_test_cleanup(void)
- {
- /* Very much like tty_release, perhaps the tty_release code should be moved to a function which only takes (tty,filp) and we'd call it with (tty,NULL) */
- int idx;
- tty_lock(tty);
- idx = tty->index;
- #if 0
- if (tty_release_checks(tty, idx)) {
- tty_unlock(tty);
- return 0;
- }
- #endif
- if (tty->ops->close)
- tty->ops->close(tty, NULL);
- tty_unlock(tty);
- #if 0
- tty_flush_works(tty);
- #endif
- #if 0
- mutex_lock(&tty_mutex);
- release_tty(tty, idx);
- mutex_unlock(&tty_mutex);
- #endif
- printk("exit\n");
- }
- module_init(speakup_test_init);
- module_exit(speakup_test_cleanup);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement