2 RFCOMM implementation for Linux Bluetooth stack (BlueZ).
3 Copyright (C) 2002 Maxim Krasnyansky <maxk@qualcomm.com>
4 Copyright (C) 2002 Marcel Holtmann <marcel@holtmann.org>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License version 2 as
8 published by the Free Software Foundation;
10 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
11 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
13 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
14 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
15 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
20 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
21 SOFTWARE IS DISCLAIMED.
27 * $Id: tty.c,v 1.24 2002/10/03 01:54:38 holtmann Exp $
30 #include <linux/config.h>
31 #include <linux/module.h>
33 #include <linux/tty.h>
34 #include <linux/tty_driver.h>
35 #include <linux/tty_flip.h>
37 #include <linux/slab.h>
38 #include <linux/skbuff.h>
40 #include <net/bluetooth/bluetooth.h>
41 #include <net/bluetooth/rfcomm.h>
43 #ifndef CONFIG_BT_RFCOMM_DEBUG
48 #define RFCOMM_TTY_MAGIC 0x6d02 /* magic number for rfcomm struct */
49 #define RFCOMM_TTY_PORTS RFCOMM_MAX_DEV /* whole lotta rfcomm devices */
50 #define RFCOMM_TTY_MAJOR 216 /* device node major id of the usb/bluetooth.c driver */
51 #define RFCOMM_TTY_MINOR 0
53 static struct tty_driver *rfcomm_tty_driver;
56 struct list_head list;
71 struct rfcomm_dlc *dlc;
72 struct tty_struct *tty;
73 wait_queue_head_t wait;
74 struct tasklet_struct wakeup_task;
79 static LIST_HEAD(rfcomm_dev_list);
80 static rwlock_t rfcomm_dev_lock = RW_LOCK_UNLOCKED;
82 static void rfcomm_dev_data_ready(struct rfcomm_dlc *dlc, struct sk_buff *skb);
83 static void rfcomm_dev_state_change(struct rfcomm_dlc *dlc, int err);
84 static void rfcomm_dev_modem_status(struct rfcomm_dlc *dlc, u8 v24_sig);
86 static void rfcomm_tty_wakeup(unsigned long arg);
88 /* ---- Device functions ---- */
89 static void rfcomm_dev_destruct(struct rfcomm_dev *dev)
91 struct rfcomm_dlc *dlc = dev->dlc;
93 BT_DBG("dev %p dlc %p", dev, dlc);
96 /* Detach DLC if it's owned by this dev */
97 if (dlc->owner == dev)
99 rfcomm_dlc_unlock(dlc);
103 tty_unregister_device(rfcomm_tty_driver, dev->id);
105 /* Refcount should only hit zero when called from rfcomm_dev_del()
106 which will have taken us off the list. Everything else are
108 BUG_ON(!list_empty(&dev->list));
112 /* It's safe to call module_put() here because socket still
113 holds reference to this module. */
114 module_put(THIS_MODULE);
117 static inline void rfcomm_dev_hold(struct rfcomm_dev *dev)
119 atomic_inc(&dev->refcnt);
122 static inline void rfcomm_dev_put(struct rfcomm_dev *dev)
124 /* The reason this isn't actually a race, as you no
125 doubt have a little voice screaming at you in your
126 head, is that the refcount should never actually
127 reach zero unless the device has already been taken
128 off the list, in rfcomm_dev_del(). And if that's not
129 true, we'll hit the BUG() in rfcomm_dev_destruct()
131 if (atomic_dec_and_test(&dev->refcnt))
132 rfcomm_dev_destruct(dev);
135 static struct rfcomm_dev *__rfcomm_dev_get(int id)
137 struct rfcomm_dev *dev;
140 list_for_each(p, &rfcomm_dev_list) {
141 dev = list_entry(p, struct rfcomm_dev, list);
149 static inline struct rfcomm_dev *rfcomm_dev_get(int id)
151 struct rfcomm_dev *dev;
153 read_lock(&rfcomm_dev_lock);
155 dev = __rfcomm_dev_get(id);
157 rfcomm_dev_hold(dev);
159 read_unlock(&rfcomm_dev_lock);
164 static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc)
166 struct rfcomm_dev *dev;
167 struct list_head *head = &rfcomm_dev_list, *p;
170 BT_DBG("id %d channel %d", req->dev_id, req->channel);
172 dev = kmalloc(sizeof(struct rfcomm_dev), GFP_KERNEL);
175 memset(dev, 0, sizeof(struct rfcomm_dev));
177 write_lock_bh(&rfcomm_dev_lock);
179 if (req->dev_id < 0) {
182 list_for_each(p, &rfcomm_dev_list) {
183 if (list_entry(p, struct rfcomm_dev, list)->id != dev->id)
190 dev->id = req->dev_id;
192 list_for_each(p, &rfcomm_dev_list) {
193 struct rfcomm_dev *entry = list_entry(p, struct rfcomm_dev, list);
195 if (entry->id == dev->id) {
200 if (entry->id > dev->id - 1)
207 if ((dev->id < 0) || (dev->id > RFCOMM_MAX_DEV - 1)) {
212 sprintf(dev->name, "rfcomm%d", dev->id);
214 list_add(&dev->list, head);
215 atomic_set(&dev->refcnt, 1);
217 bacpy(&dev->src, &req->src);
218 bacpy(&dev->dst, &req->dst);
219 dev->channel = req->channel;
221 dev->flags = req->flags &
222 ((1 << RFCOMM_RELEASE_ONHUP) | (1 << RFCOMM_REUSE_DLC));
224 init_waitqueue_head(&dev->wait);
225 tasklet_init(&dev->wakeup_task, rfcomm_tty_wakeup, (unsigned long) dev);
227 rfcomm_dlc_lock(dlc);
228 dlc->data_ready = rfcomm_dev_data_ready;
229 dlc->state_change = rfcomm_dev_state_change;
230 dlc->modem_status = rfcomm_dev_modem_status;
234 rfcomm_dlc_unlock(dlc);
236 /* It's safe to call __module_get() here because socket already
237 holds reference to this module. */
238 __module_get(THIS_MODULE);
241 write_unlock_bh(&rfcomm_dev_lock);
248 tty_register_device(rfcomm_tty_driver, dev->id, NULL);
253 static void rfcomm_dev_del(struct rfcomm_dev *dev)
255 BT_DBG("dev %p", dev);
257 write_lock_bh(&rfcomm_dev_lock);
258 list_del_init(&dev->list);
259 write_unlock_bh(&rfcomm_dev_lock);
264 /* ---- Send buffer ---- */
265 static inline unsigned int rfcomm_room(struct rfcomm_dlc *dlc)
267 /* We can't let it be zero, because we don't get a callback
268 when tx_credits becomes nonzero, hence we'd never wake up */
269 return dlc->mtu * (dlc->tx_credits?:1);
272 static void rfcomm_wfree(struct sk_buff *skb)
274 struct rfcomm_dev *dev = (void *) skb->sk;
275 atomic_sub(skb->truesize, &dev->wmem_alloc);
276 if (test_bit(RFCOMM_TTY_ATTACHED, &dev->flags))
277 tasklet_schedule(&dev->wakeup_task);
281 static inline void rfcomm_set_owner_w(struct sk_buff *skb, struct rfcomm_dev *dev)
283 rfcomm_dev_hold(dev);
284 atomic_add(skb->truesize, &dev->wmem_alloc);
285 skb->sk = (void *) dev;
286 skb->destructor = rfcomm_wfree;
289 static struct sk_buff *rfcomm_wmalloc(struct rfcomm_dev *dev, unsigned long size, int priority)
291 if (atomic_read(&dev->wmem_alloc) < rfcomm_room(dev->dlc)) {
292 struct sk_buff *skb = alloc_skb(size, priority);
294 rfcomm_set_owner_w(skb, dev);
301 /* ---- Device IOCTLs ---- */
303 #define NOCAP_FLAGS ((1 << RFCOMM_REUSE_DLC) | (1 << RFCOMM_RELEASE_ONHUP))
305 static int rfcomm_create_dev(struct sock *sk, unsigned long arg)
307 struct rfcomm_dev_req req;
308 struct rfcomm_dlc *dlc;
311 if (copy_from_user(&req, (void *) arg, sizeof(req)))
314 BT_DBG("sk %p dev_id %id flags 0x%x", sk, req.dev_id, req.flags);
316 if (req.flags != NOCAP_FLAGS && !capable(CAP_NET_ADMIN))
319 if (req.flags & (1 << RFCOMM_REUSE_DLC)) {
320 /* Socket must be connected */
321 if (sk->sk_state != BT_CONNECTED)
324 dlc = rfcomm_pi(sk)->dlc;
325 rfcomm_dlc_hold(dlc);
327 dlc = rfcomm_dlc_alloc(GFP_KERNEL);
332 id = rfcomm_dev_add(&req, dlc);
338 if (req.flags & (1 << RFCOMM_REUSE_DLC)) {
339 /* DLC is now used by device.
340 * Socket must be disconnected */
341 sk->sk_state = BT_CLOSED;
347 static int rfcomm_release_dev(unsigned long arg)
349 struct rfcomm_dev_req req;
350 struct rfcomm_dev *dev;
352 if (copy_from_user(&req, (void *) arg, sizeof(req)))
355 BT_DBG("dev_id %id flags 0x%x", req.dev_id, req.flags);
357 if (!(dev = rfcomm_dev_get(req.dev_id)))
360 if (dev->flags != NOCAP_FLAGS && !capable(CAP_NET_ADMIN)) {
365 if (req.flags & (1 << RFCOMM_HANGUP_NOW))
366 rfcomm_dlc_close(dev->dlc, 0);
373 static int rfcomm_get_dev_list(unsigned long arg)
375 struct rfcomm_dev_list_req *dl;
376 struct rfcomm_dev_info *di;
378 int n = 0, size, err;
383 if (get_user(dev_num, (u16 *) arg))
386 if (!dev_num || dev_num > (PAGE_SIZE * 4) / sizeof(*di))
389 size = sizeof(*dl) + dev_num * sizeof(*di);
391 if (!(dl = kmalloc(size, GFP_KERNEL)))
396 read_lock_bh(&rfcomm_dev_lock);
398 list_for_each(p, &rfcomm_dev_list) {
399 struct rfcomm_dev *dev = list_entry(p, struct rfcomm_dev, list);
400 (di + n)->id = dev->id;
401 (di + n)->flags = dev->flags;
402 (di + n)->state = dev->dlc->state;
403 (di + n)->channel = dev->channel;
404 bacpy(&(di + n)->src, &dev->src);
405 bacpy(&(di + n)->dst, &dev->dst);
410 read_unlock_bh(&rfcomm_dev_lock);
413 size = sizeof(*dl) + n * sizeof(*di);
415 err = copy_to_user((void *) arg, dl, size);
418 return err ? -EFAULT : 0;
421 static int rfcomm_get_dev_info(unsigned long arg)
423 struct rfcomm_dev *dev;
424 struct rfcomm_dev_info di;
429 if (copy_from_user(&di, (void *)arg, sizeof(di)))
432 if (!(dev = rfcomm_dev_get(di.id)))
435 di.flags = dev->flags;
436 di.channel = dev->channel;
437 di.state = dev->dlc->state;
438 bacpy(&di.src, &dev->src);
439 bacpy(&di.dst, &dev->dst);
441 if (copy_to_user((void *)arg, &di, sizeof(di)))
448 int rfcomm_dev_ioctl(struct sock *sk, unsigned int cmd, unsigned long arg)
450 BT_DBG("cmd %d arg %ld", cmd, arg);
453 case RFCOMMCREATEDEV:
454 return rfcomm_create_dev(sk, arg);
456 case RFCOMMRELEASEDEV:
457 return rfcomm_release_dev(arg);
459 case RFCOMMGETDEVLIST:
460 return rfcomm_get_dev_list(arg);
462 case RFCOMMGETDEVINFO:
463 return rfcomm_get_dev_info(arg);
469 /* ---- DLC callbacks ---- */
470 static void rfcomm_dev_data_ready(struct rfcomm_dlc *dlc, struct sk_buff *skb)
472 struct rfcomm_dev *dev = dlc->owner;
473 struct tty_struct *tty;
475 if (!dev || !(tty = dev->tty)) {
480 BT_DBG("dlc %p tty %p len %d", dlc, tty, skb->len);
482 if (test_bit(TTY_DONT_FLIP, &tty->flags)) {
484 for (i = 0; i < skb->len; i++) {
485 if (tty->flip.count >= TTY_FLIPBUF_SIZE)
486 tty_flip_buffer_push(tty);
488 tty_insert_flip_char(tty, skb->data[i], 0);
490 tty_flip_buffer_push(tty);
492 tty->ldisc.receive_buf(tty, skb->data, NULL, skb->len);
497 static void rfcomm_dev_state_change(struct rfcomm_dlc *dlc, int err)
499 struct rfcomm_dev *dev = dlc->owner;
503 BT_DBG("dlc %p dev %p err %d", dlc, dev, err);
506 wake_up_interruptible(&dev->wait);
508 if (dlc->state == BT_CLOSED) {
510 if (test_bit(RFCOMM_RELEASE_ONHUP, &dev->flags)) {
511 rfcomm_dev_hold(dev);
514 /* We have to drop DLC lock here, otherwise
515 rfcomm_dev_put() will dead lock if it's
516 the last reference. */
517 rfcomm_dlc_unlock(dlc);
519 rfcomm_dlc_lock(dlc);
522 tty_hangup(dev->tty);
526 static void rfcomm_dev_modem_status(struct rfcomm_dlc *dlc, u8 v24_sig)
528 struct rfcomm_dev *dev = dlc->owner;
532 BT_DBG("dlc %p dev %p v24_sig 0x%02x", dlc, dev, v24_sig);
535 ((v24_sig & RFCOMM_V24_RTC) ? (TIOCM_DSR | TIOCM_DTR) : 0) |
536 ((v24_sig & RFCOMM_V24_RTR) ? (TIOCM_RTS | TIOCM_CTS) : 0) |
537 ((v24_sig & RFCOMM_V24_IC) ? TIOCM_RI : 0) |
538 ((v24_sig & RFCOMM_V24_DV) ? TIOCM_CD : 0);
541 /* ---- TTY functions ---- */
542 static void rfcomm_tty_wakeup(unsigned long arg)
544 struct rfcomm_dev *dev = (void *) arg;
545 struct tty_struct *tty = dev->tty;
549 BT_DBG("dev %p tty %p", dev, tty);
551 if (test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags) && tty->ldisc.write_wakeup)
552 (tty->ldisc.write_wakeup)(tty);
554 wake_up_interruptible(&tty->write_wait);
555 #ifdef SERIAL_HAVE_POLL_WAIT
556 wake_up_interruptible(&tty->poll_wait);
560 static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
562 DECLARE_WAITQUEUE(wait, current);
563 struct rfcomm_dev *dev;
564 struct rfcomm_dlc *dlc;
569 BT_DBG("tty %p id %d", tty, id);
571 /* We don't leak this refcount. For reasons which are not entirely
572 clear, the TTY layer will call our ->close() method even if the
573 open fails. We decrease the refcount there, and decreasing it
574 here too would cause breakage. */
575 dev = rfcomm_dev_get(id);
579 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst), dev->channel, dev->opened);
581 if (dev->opened++ != 0)
586 /* Attach TTY and open DLC */
588 rfcomm_dlc_lock(dlc);
589 tty->driver_data = dev;
591 rfcomm_dlc_unlock(dlc);
592 set_bit(RFCOMM_TTY_ATTACHED, &dev->flags);
594 err = rfcomm_dlc_open(dlc, &dev->src, &dev->dst, dev->channel);
598 /* Wait for DLC to connect */
599 add_wait_queue(&dev->wait, &wait);
601 set_current_state(TASK_INTERRUPTIBLE);
603 if (dlc->state == BT_CLOSED) {
608 if (dlc->state == BT_CONNECTED)
611 if (signal_pending(current)) {
618 set_current_state(TASK_RUNNING);
619 remove_wait_queue(&dev->wait, &wait);
624 static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
626 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
630 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc, dev->opened);
632 if (--dev->opened == 0) {
633 /* Close DLC and dettach TTY */
634 rfcomm_dlc_close(dev->dlc, 0);
636 clear_bit(RFCOMM_TTY_ATTACHED, &dev->flags);
637 tasklet_kill(&dev->wakeup_task);
639 rfcomm_dlc_lock(dev->dlc);
640 tty->driver_data = NULL;
642 rfcomm_dlc_unlock(dev->dlc);
648 static int rfcomm_tty_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count)
650 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
651 struct rfcomm_dlc *dlc = dev->dlc;
653 int err = 0, sent = 0, size;
655 BT_DBG("tty %p from_user %d count %d", tty, from_user, count);
658 size = min_t(uint, count, dlc->mtu);
661 skb = rfcomm_wmalloc(dev, size + RFCOMM_SKB_RESERVE, GFP_KERNEL);
663 skb = rfcomm_wmalloc(dev, size + RFCOMM_SKB_RESERVE, GFP_ATOMIC);
668 skb_reserve(skb, RFCOMM_SKB_HEAD_RESERVE);
671 copy_from_user(skb_put(skb, size), buf + sent, size);
673 memcpy(skb_put(skb, size), buf + sent, size);
675 if ((err = rfcomm_dlc_send(dlc, skb)) < 0) {
684 return sent ? sent : err;
687 static int rfcomm_tty_write_room(struct tty_struct *tty)
689 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
692 BT_DBG("tty %p", tty);
694 room = rfcomm_room(dev->dlc) - atomic_read(&dev->wmem_alloc);
700 static int rfcomm_tty_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd, unsigned long arg)
702 BT_DBG("tty %p cmd 0x%02x", tty, cmd);
706 BT_DBG("TCGETS is not supported");
710 BT_DBG("TCSETS is not supported");
714 BT_DBG("TIOCMIWAIT");
718 BT_DBG("TIOCGICOUNT");
722 BT_ERR("TIOCGSERIAL is not supported");
726 BT_ERR("TIOCSSERIAL is not supported");
730 BT_ERR("TIOCSERGSTRUCT is not supported");
734 BT_ERR("TIOCSERGETLSR is not supported");
738 BT_ERR("TIOCSERCONFIG is not supported");
742 return -ENOIOCTLCMD; /* ioctls which we must ignore */
749 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
751 static void rfcomm_tty_set_termios(struct tty_struct *tty, struct termios *old)
753 BT_DBG("tty %p", tty);
755 if ((tty->termios->c_cflag == old->c_cflag) &&
756 (RELEVANT_IFLAG(tty->termios->c_iflag) == RELEVANT_IFLAG(old->c_iflag)))
759 /* handle turning off CRTSCTS */
760 if ((old->c_cflag & CRTSCTS) && !(tty->termios->c_cflag & CRTSCTS)) {
761 BT_DBG("turning off CRTSCTS");
765 static void rfcomm_tty_throttle(struct tty_struct *tty)
767 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
769 BT_DBG("tty %p dev %p", tty, dev);
771 rfcomm_dlc_throttle(dev->dlc);
774 static void rfcomm_tty_unthrottle(struct tty_struct *tty)
776 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
778 BT_DBG("tty %p dev %p", tty, dev);
780 rfcomm_dlc_unthrottle(dev->dlc);
783 static int rfcomm_tty_chars_in_buffer(struct tty_struct *tty)
785 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
786 struct rfcomm_dlc *dlc = dev->dlc;
788 BT_DBG("tty %p dev %p", tty, dev);
790 if (skb_queue_len(&dlc->tx_queue))
796 static void rfcomm_tty_flush_buffer(struct tty_struct *tty)
798 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
802 BT_DBG("tty %p dev %p", tty, dev);
804 skb_queue_purge(&dev->dlc->tx_queue);
806 if (test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags) && tty->ldisc.write_wakeup)
807 tty->ldisc.write_wakeup(tty);
810 static void rfcomm_tty_send_xchar(struct tty_struct *tty, char ch)
812 BT_DBG("tty %p ch %c", tty, ch);
815 static void rfcomm_tty_wait_until_sent(struct tty_struct *tty, int timeout)
817 BT_DBG("tty %p timeout %d", tty, timeout);
820 static void rfcomm_tty_hangup(struct tty_struct *tty)
822 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
826 BT_DBG("tty %p dev %p", tty, dev);
828 rfcomm_tty_flush_buffer(tty);
830 if (test_bit(RFCOMM_RELEASE_ONHUP, &dev->flags))
834 static int rfcomm_tty_read_proc(char *buf, char **start, off_t offset, int len, int *eof, void *unused)
839 static int rfcomm_tty_tiocmget(struct tty_struct *tty, struct file *filp)
841 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
843 BT_DBG("tty %p dev %p", tty, dev);
845 return dev->modem_status;
848 static int rfcomm_tty_tiocmset(struct tty_struct *tty, struct file *filp, unsigned int set, unsigned int clear)
850 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
851 struct rfcomm_dlc *dlc = dev->dlc;
854 BT_DBG("tty %p dev %p set 0x%02x clear 0x%02x", tty, dev, set, clear);
856 rfcomm_dlc_get_modem_status(dlc, &v24_sig);
858 if (set & TIOCM_DSR || set & TIOCM_DTR)
859 v24_sig |= RFCOMM_V24_RTC;
860 if (set & TIOCM_RTS || set & TIOCM_CTS)
861 v24_sig |= RFCOMM_V24_RTR;
863 v24_sig |= RFCOMM_V24_IC;
865 v24_sig |= RFCOMM_V24_DV;
867 if (clear & TIOCM_DSR || clear & TIOCM_DTR)
868 v24_sig &= ~RFCOMM_V24_RTC;
869 if (clear & TIOCM_RTS || clear & TIOCM_CTS)
870 v24_sig &= ~RFCOMM_V24_RTR;
871 if (clear & TIOCM_RI)
872 v24_sig &= ~RFCOMM_V24_IC;
873 if (clear & TIOCM_CD)
874 v24_sig &= ~RFCOMM_V24_DV;
876 rfcomm_dlc_set_modem_status(dlc, v24_sig);
881 /* ---- TTY structure ---- */
883 static struct tty_operations rfcomm_ops = {
884 .open = rfcomm_tty_open,
885 .close = rfcomm_tty_close,
886 .write = rfcomm_tty_write,
887 .write_room = rfcomm_tty_write_room,
888 .chars_in_buffer = rfcomm_tty_chars_in_buffer,
889 .flush_buffer = rfcomm_tty_flush_buffer,
890 .ioctl = rfcomm_tty_ioctl,
891 .throttle = rfcomm_tty_throttle,
892 .unthrottle = rfcomm_tty_unthrottle,
893 .set_termios = rfcomm_tty_set_termios,
894 .send_xchar = rfcomm_tty_send_xchar,
895 .hangup = rfcomm_tty_hangup,
896 .wait_until_sent = rfcomm_tty_wait_until_sent,
897 .read_proc = rfcomm_tty_read_proc,
898 .tiocmget = rfcomm_tty_tiocmget,
899 .tiocmset = rfcomm_tty_tiocmset,
902 int rfcomm_init_ttys(void)
904 rfcomm_tty_driver = alloc_tty_driver(RFCOMM_TTY_PORTS);
905 if (!rfcomm_tty_driver)
908 rfcomm_tty_driver->owner = THIS_MODULE;
909 rfcomm_tty_driver->driver_name = "rfcomm";
910 rfcomm_tty_driver->devfs_name = "bluetooth/rfcomm/";
911 rfcomm_tty_driver->name = "rfcomm";
912 rfcomm_tty_driver->major = RFCOMM_TTY_MAJOR;
913 rfcomm_tty_driver->minor_start = RFCOMM_TTY_MINOR;
914 rfcomm_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
915 rfcomm_tty_driver->subtype = SERIAL_TYPE_NORMAL;
916 rfcomm_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_NO_DEVFS;
917 rfcomm_tty_driver->init_termios = tty_std_termios;
918 rfcomm_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
919 tty_set_operations(rfcomm_tty_driver, &rfcomm_ops);
921 if (tty_register_driver(rfcomm_tty_driver)) {
922 BT_ERR("Can't register RFCOMM TTY driver");
923 put_tty_driver(rfcomm_tty_driver);
927 BT_INFO("RFCOMM TTY layer initialized");
932 void rfcomm_cleanup_ttys(void)
934 tty_unregister_driver(rfcomm_tty_driver);
935 put_tty_driver(rfcomm_tty_driver);