All of lore.kernel.org
 help / color / mirror / Atom feed
From: Frederic Danis <frederic.danis@linux.intel.com>
To: linux-bluetooth@vger.kernel.org
Subject: [RFC 1/5] Bluetooth: hci_uart: Add HCIUARTSETDEVTYPE ioctl
Date: Thu,  2 Apr 2015 16:37:32 +0200	[thread overview]
Message-ID: <1427985456-31536-2-git-send-email-frederic.danis@linux.intel.com> (raw)
In-Reply-To: <1427985456-31536-1-git-send-email-frederic.danis@linux.intel.com>

This allows user space application to set the correct vendor specific
setup function.

Signed-off-by: Frederic Danis <frederic.danis@linux.intel.com>
---
 drivers/bluetooth/hci_ldisc.c | 50 +++++++++++++++++++++++++++++++++++++++++++
 drivers/bluetooth/hci_uart.h  |  4 ++++
 2 files changed, 54 insertions(+)

diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
index 1363dc6..cb7fcc6 100644
--- a/drivers/bluetooth/hci_ldisc.c
+++ b/drivers/bluetooth/hci_ldisc.c
@@ -467,9 +467,19 @@ static int hci_uart_register_dev(struct hci_uart *hu)
 	return 0;
 }
 
+struct hci_uart_devtype_t {
+	char type[HCI_UART_DEVTYPE_SIZE];
+	int (*setup)(struct hci_uart *hu);
+};
+
+struct hci_uart_devtype_t devtypes[] = {
+		{ "", 0 }
+};
+
 static int hci_uart_set_proto(struct hci_uart *hu, int id)
 {
 	struct hci_uart_proto *p;
+	int i;
 	int err;
 
 	p = hci_uart_get_proto(id);
@@ -482,6 +492,13 @@ static int hci_uart_set_proto(struct hci_uart *hu, int id)
 
 	hu->proto = p;
 
+	/* Select vendor specific setup */
+	hu->proto->setup = NULL;
+	for (i = 0; devtypes[i].type[0]; i++) {
+		if (!strcmp(devtypes[i].type, hu->dev_type))
+			hu->proto->setup = devtypes[i].setup;
+	}
+
 	err = hci_uart_register_dev(hu);
 	if (err) {
 		p->close(hu);
@@ -507,6 +524,33 @@ static int hci_uart_set_flags(struct hci_uart *hu, unsigned long flags)
 	return 0;
 }
 
+static int hci_tty_ioctl_set_devtype(struct hci_uart *hu, unsigned int cmd,
+							unsigned long arg)
+{
+	unsigned int size = _IOC_SIZE(cmd);
+	char dev_type[HCI_UART_DEVTYPE_SIZE];
+	int i;
+	bool found = false;
+
+	if (size > HCI_UART_DEVTYPE_SIZE)
+		return -EINVAL;
+
+	if (copy_from_user(dev_type, (void __user *)arg, size))
+		return -EFAULT;
+
+	for (i = 0; devtypes[i].type[0]; i++) {
+		if (!strcmp(devtypes[i].type, dev_type))
+			found = true;
+	}
+
+	if (!found)
+		return -EINVAL;
+
+	strncpy(hu->dev_type, dev_type, size);
+
+	return 0;
+}
+
 /* hci_uart_tty_ioctl()
  *
  *    Process IOCTL system call for the tty device.
@@ -565,6 +609,12 @@ static int hci_uart_tty_ioctl(struct tty_struct *tty, struct file * file,
 	case HCIUARTGETFLAGS:
 		return hu->hdev_flags;
 
+	case HCIUARTSETDEVTYPE:
+		err = hci_tty_ioctl_set_devtype(hu, cmd, arg);
+		if (err)
+			return err;
+		break;
+
 	default:
 		err = n_tty_ioctl_helper(tty, file, cmd, arg);
 		break;
diff --git a/drivers/bluetooth/hci_uart.h b/drivers/bluetooth/hci_uart.h
index 074ed29..bd56409 100644
--- a/drivers/bluetooth/hci_uart.h
+++ b/drivers/bluetooth/hci_uart.h
@@ -33,6 +33,7 @@
 #define HCIUARTGETDEVICE	_IOR('U', 202, int)
 #define HCIUARTSETFLAGS		_IOW('U', 203, int)
 #define HCIUARTGETFLAGS		_IOR('U', 204, int)
+#define HCIUARTSETDEVTYPE	_IOW('U', 205, int)
 
 /* UART protocols */
 #define HCI_UART_MAX_PROTO	6
@@ -50,6 +51,8 @@
 #define HCI_UART_INIT_PENDING	3
 #define HCI_UART_EXT_CONFIG	4
 
+#define HCI_UART_DEVTYPE_SIZE	32
+
 struct hci_uart;
 
 struct hci_uart_proto {
@@ -68,6 +71,7 @@ struct hci_uart {
 	struct hci_dev		*hdev;
 	unsigned long		flags;
 	unsigned long		hdev_flags;
+	char			dev_type[HCI_UART_DEVTYPE_SIZE];
 
 	struct work_struct	init_ready;
 	struct work_struct	write_work;
-- 
1.9.1


  reply	other threads:[~2015-04-02 14:37 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-02 14:37 [RFC 0/5] Move HCI UART vendor specific setup to kernel Frederic Danis
2015-04-02 14:37 ` Frederic Danis [this message]
2015-04-02 14:57   ` [RFC 1/5] Bluetooth: hci_uart: Add HCIUARTSETDEVTYPE ioctl Marcel Holtmann
2015-04-02 14:37 ` [RFC 2/5] Bluetooth: hci_uart: Add BCM specific setup function Frederic Danis
2015-04-02 14:37 ` [RFC 3/5] Bluetooth: hci_uart: Add HCIUARTSETBAUDRATE ioctl Frederic Danis
2015-04-02 15:12   ` Marcel Holtmann
2015-04-03 10:54   ` Peter Hurley
2015-04-03 12:49     ` Frederic Danis
2015-04-03 13:45       ` Peter Hurley
2015-04-03 13:56         ` Peter Hurley
2015-04-03 14:18         ` Loic Poulain
2015-04-03 15:45           ` Peter Hurley
2015-04-03 17:39             ` Marcel Holtmann
2015-04-04 23:05               ` Peter Hurley
2015-04-04 23:35                 ` Marcel Holtmann
2015-04-05  1:22                   ` Peter Hurley
2015-04-05  2:29                     ` Marcel Holtmann
2015-04-10 12:07                       ` Peter Hurley
2015-04-10 16:07                         ` Marcel Holtmann
2015-04-10 16:45                           ` Peter Hurley
2015-04-10 16:58                             ` Marcel Holtmann
2015-04-02 14:37 ` [RFC 4/5] tty: Re-add external interface for tty_set_termios() Frederic Danis
2015-04-02 15:08   ` Marcel Holtmann
2015-04-02 14:37 ` [RFC 5/5] Bluetooth: hci_uart: Add BCM specific UART speed management Frederic Danis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1427985456-31536-2-git-send-email-frederic.danis@linux.intel.com \
    --to=frederic.danis@linux.intel.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.