Skip to contentSkip to conversation

Netlink patch.

PATCH In review Alok 2 participants 3 messages Nov 6, 2008 – Nov 7, 2008

Subsystems (2)
lore
Share & tools
lore

Alok

author
#0 lore raw

PATCH 1/1 Netlink patch.

Hi Marcel,

Attaching a patch which implements a generic netlink command GET_DEVLIST(HCIGETDEVLIST).

1. Will the netlink plugin expose an API like int hci_get_devlist(struct hci_dev_list_req *dl) ?

2. If netlink registration fails would we fallback to raw sockets in the plugin ?

Let me know if anything in the patch needs modification.

Thanks,
Alok.

Quoted 1 line

From 6033fdc20d549e8b67dea76e3a644fd0d4a7e1d9 Mon Sep 17 00:00:00 2001

From: Alok Barsode <[email protected]>
Date: Thu, 6 Nov 2008 17:33:05 +0530
Subject: [PATCH] Adding netlink support to bluetooth.
Adding files netlink.c and netlink.h to net/bluetooth for netlink support. Adding support for GET_DEVLIST.

---
 include/net/bluetooth/bluetooth.h |    3 +
 net/bluetooth/Makefile            |    2 +-
 net/bluetooth/af_bluetooth.c      |    6 ++
 net/bluetooth/netlink.c           |  122 +++++++++++++++++++++++++++++++++++++
 net/bluetooth/netlink.h           |   30 +++++++++
 5 files changed, 162 insertions(+), 1 deletions(-)
 create mode 100644 net/bluetooth/netlink.c
 create mode 100644 net/bluetooth/netlink.h
include/net/bluetooth/bluetooth.h +3 -0
index 6f8418b..b02c7aa 100644
@@ -178,4 +178,7 @@ extern void bt_sysfs_cleanup(void);
 
 extern struct class *bt_class;
 
+extern int nlbluetooth_init(void);
+extern void nlbluetooth_cleanup(void);
+
 #endif /* __BLUETOOTH_H */
net/bluetooth/Makefile +1 -1
index d1e433f..f014d48 100644
@@ -10,4 +10,4 @@ obj-$(CONFIG_BT_BNEP)	+= bnep/
 obj-$(CONFIG_BT_CMTP)	+= cmtp/
 obj-$(CONFIG_BT_HIDP)	+= hidp/
 
-bluetooth-objs := af_bluetooth.o hci_core.o hci_conn.o hci_event.o hci_sock.o hci_sysfs.o lib.o
+bluetooth-objs := af_bluetooth.o hci_core.o hci_conn.o hci_event.o hci_sock.o hci_sysfs.o lib.o netlink.o
net/bluetooth/af_bluetooth.c +6 -0
index 8907eff..b6487dc 100644
@@ -436,6 +436,10 @@ static int __init bt_init(void)
 	if (err < 0)
 		return err;
 
+	err = nlbluetooth_init();
+	if (err < 0)
+		return err;
+
 	err = sock_register(&bt_sock_family_ops);
 	if (err < 0) {
 		bt_sysfs_cleanup();
@@ -456,6 +460,8 @@ static void __exit bt_exit(void)
 	sock_unregister(PF_BLUETOOTH);
 
 	bt_sysfs_cleanup();
+
+	nlbluetooth_cleanup();
 }
 
 subsys_initcall(bt_init);
net/bluetooth/netlink.c new file +122 -0

122 lines not on this page · raw message

net/bluetooth/netlink.h new file +30 -0
new file mode 100644
index 0000000..2b81037
@@ -0,0 +1,30 @@
+/*
+ * This is the netlink-based bluetooth interface.
+ *
+ * Copyright 2008 Alok Barsode <[email protected]>
+ */
+#ifndef __NETLINK_H
+#define __NETLINK_H
+
+#define VERSION 1
+
+enum nlbluetooth_attr {
+	NLBLUETOOTH_ATTR_UNSPEC,
+	NLBLUETOOTH_ATTR_DEVID,
+	NLBLUETOOTH_ATTR_DEVNUM,
+	NLBLUETOOTH_ATTR_DEVOPT,
+	NLBLUETOOTH_ATTR_DEVLIST,
+	/* Add attributes here */
+	__NLBLUETOOTH_ATTR_MAX,
+	NLBLUETOOTH_ATTR_MAX  =  __NLBLUETOOTH_ATTR_MAX - 1
+};
+
+enum nlbluetooth_cmds {
+	NLBLUETOOTH_CMD_UNSPEC,
+	NLBLUETOOTH_CMD_GET_DEVLIST,
+	/* Add command here */
+	__NLBLUETOOTH_CMD_MAX,
+	NLBLUETOOTH_CMD_MAX  = __NLBLUETOOTH_CMD_MAX - 1
+};
+
+#endif /* __NETLINK_H */
Signature · 1 line
1.5.4.3
#1 lore raw

Hi Alok,

Quoted 4 lines · ext Alok

Hi Marcel,

Attaching a patch which implements a generic netlink command GET_DEVLIST(HCIGETDEVLIST).

I don't know anything about netlink stuff but I'll give some generic comments :)

+
+ if (info->attrs[NLBLUETOOTH_ATTR_DEVNUM]) {
+ dev_num = nla_get_u16(info->attrs[NLBLUETOOTH_ATTR_DEVNUM]);
+ if (!dev_num)
+ return -EINVAL;
+ } else
+ return -EINVAL;
+

I would prefer this kind code paths. Easier to read.

	if (!info->attrs[NLBLUETOOTH_ATTR_DEVNUM])
		return -EINVAL;

	dev_num = nla_get_u16(info->attrs[NLBLUETOOTH_ATTR_DEVNUM]);
	if (!dev_num)
		return -EINVAL;

+ msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
+
+ if (!msg)
+ return -ENOBUFS;
+
+ hdr = genlmsg_put(msg, 0, info->snd_seq+1, &nlbluetooth_fam, 0, NLBLUETOOTH_CMD_GET_DEVLIST);
+
+ if (hdr == NULL)
+ return -ENOMEM;

Is msg left unfreed here?

+
+ nl_list = nla_nest_start(msg, NLBLUETOOTH_ATTR_DEVLIST);
+ if (!nl_list)
+ goto nla_put_failure;

And here? I cannot find skb_free or friends from genlmsg_cancel() path.

Signature · 1 line
Ville
author
#2 lore raw

PATCH 1/1 Netlink patch.(modified)

Hi Marcel,

Attaching a modified netlink patch.
Forgot to free the buffer :) Thanks to ville for spotting it.

-Alok.

Quoted 1 line

From 7e3014a5514fa009ba40a95a9a86723564cc5302 Mon Sep 17 00:00:00 2001

From: Alok Barsode <[email protected]>
Date: Fri, 7 Nov 2008 12:06:43 +0530
Subject: [PATCH] Adding netlink support to bluetooth.
Adding files netlink.c and netlink.h to net/bluetooth for netlink support. Adding support for GET_DEVLIST.

---
 include/net/bluetooth/bluetooth.h |    3 +
 net/bluetooth/Makefile            |    2 +-
 net/bluetooth/af_bluetooth.c      |    6 ++
 net/bluetooth/netlink.c           |  124 +++++++++++++++++++++++++++++++++++++
 net/bluetooth/netlink.h           |   30 +++++++++
 5 files changed, 164 insertions(+), 1 deletions(-)
 create mode 100644 net/bluetooth/netlink.c
 create mode 100644 net/bluetooth/netlink.h
include/net/bluetooth/bluetooth.h +3 -0
index 6f8418b..b02c7aa 100644
@@ -178,4 +178,7 @@ extern void bt_sysfs_cleanup(void);
 
 extern struct class *bt_class;
 
+extern int nlbluetooth_init(void);
+extern void nlbluetooth_cleanup(void);
+
 #endif /* __BLUETOOTH_H */
net/bluetooth/Makefile +1 -1
index d1e433f..f014d48 100644
@@ -10,4 +10,4 @@ obj-$(CONFIG_BT_BNEP)	+= bnep/
 obj-$(CONFIG_BT_CMTP)	+= cmtp/
 obj-$(CONFIG_BT_HIDP)	+= hidp/
 
-bluetooth-objs := af_bluetooth.o hci_core.o hci_conn.o hci_event.o hci_sock.o hci_sysfs.o lib.o
+bluetooth-objs := af_bluetooth.o hci_core.o hci_conn.o hci_event.o hci_sock.o hci_sysfs.o lib.o netlink.o
net/bluetooth/af_bluetooth.c +6 -0
index 8907eff..b6487dc 100644
@@ -436,6 +436,10 @@ static int __init bt_init(void)
 	if (err < 0)
 		return err;
 
+	err = nlbluetooth_init();
+	if (err < 0)
+		return err;
+
 	err = sock_register(&bt_sock_family_ops);
 	if (err < 0) {
 		bt_sysfs_cleanup();
@@ -456,6 +460,8 @@ static void __exit bt_exit(void)
 	sock_unregister(PF_BLUETOOTH);
 
 	bt_sysfs_cleanup();
+
+	nlbluetooth_cleanup();
 }
 
 subsys_initcall(bt_init);
net/bluetooth/netlink.c new file +124 -0

124 lines not on this page · raw message

net/bluetooth/netlink.h new file +30 -0
new file mode 100644
index 0000000..2b81037
@@ -0,0 +1,30 @@
+/*
+ * This is the netlink-based bluetooth interface.
+ *
+ * Copyright 2008 Alok Barsode <[email protected]>
+ */
+#ifndef __NETLINK_H
+#define __NETLINK_H
+
+#define VERSION 1
+
+enum nlbluetooth_attr {
+	NLBLUETOOTH_ATTR_UNSPEC,
+	NLBLUETOOTH_ATTR_DEVID,
+	NLBLUETOOTH_ATTR_DEVNUM,
+	NLBLUETOOTH_ATTR_DEVOPT,
+	NLBLUETOOTH_ATTR_DEVLIST,
+	/* Add attributes here */
+	__NLBLUETOOTH_ATTR_MAX,
+	NLBLUETOOTH_ATTR_MAX  =  __NLBLUETOOTH_ATTR_MAX - 1
+};
+
+enum nlbluetooth_cmds {
+	NLBLUETOOTH_CMD_UNSPEC,
+	NLBLUETOOTH_CMD_GET_DEVLIST,
+	/* Add command here */
+	__NLBLUETOOTH_CMD_MAX,
+	NLBLUETOOTH_CMD_MAX  = __NLBLUETOOTH_CMD_MAX - 1
+};
+
+#endif /* __NETLINK_H */
Signature · 1 line
1.5.4.3