0001
0002
0003
0004 #include <linux/module.h>
0005
0006 #include <net/bluetooth/bluetooth.h>
0007 #include <net/bluetooth/hci_core.h>
0008
0009 static struct class *bt_class;
0010
0011 static void bt_link_release(struct device *dev)
0012 {
0013 struct hci_conn *conn = to_hci_conn(dev);
0014 kfree(conn);
0015 }
0016
0017 static const struct device_type bt_link = {
0018 .name = "link",
0019 .release = bt_link_release,
0020 };
0021
0022
0023
0024
0025
0026
0027 static int __match_tty(struct device *dev, void *data)
0028 {
0029 return !strncmp(dev_name(dev), "rfcomm", 6);
0030 }
0031
0032 void hci_conn_init_sysfs(struct hci_conn *conn)
0033 {
0034 struct hci_dev *hdev = conn->hdev;
0035
0036 BT_DBG("conn %p", conn);
0037
0038 conn->dev.type = &bt_link;
0039 conn->dev.class = bt_class;
0040 conn->dev.parent = &hdev->dev;
0041
0042 device_initialize(&conn->dev);
0043 }
0044
0045 void hci_conn_add_sysfs(struct hci_conn *conn)
0046 {
0047 struct hci_dev *hdev = conn->hdev;
0048
0049 BT_DBG("conn %p", conn);
0050
0051 dev_set_name(&conn->dev, "%s:%d", hdev->name, conn->handle);
0052
0053 if (device_add(&conn->dev) < 0) {
0054 bt_dev_err(hdev, "failed to register connection device");
0055 return;
0056 }
0057
0058 hci_dev_hold(hdev);
0059 }
0060
0061 void hci_conn_del_sysfs(struct hci_conn *conn)
0062 {
0063 struct hci_dev *hdev = conn->hdev;
0064
0065 if (!device_is_registered(&conn->dev))
0066 return;
0067
0068 while (1) {
0069 struct device *dev;
0070
0071 dev = device_find_child(&conn->dev, NULL, __match_tty);
0072 if (!dev)
0073 break;
0074 device_move(dev, NULL, DPM_ORDER_DEV_LAST);
0075 put_device(dev);
0076 }
0077
0078 device_del(&conn->dev);
0079
0080 hci_dev_put(hdev);
0081 }
0082
0083 static void bt_host_release(struct device *dev)
0084 {
0085 struct hci_dev *hdev = to_hci_dev(dev);
0086
0087 if (hci_dev_test_flag(hdev, HCI_UNREGISTER))
0088 hci_release_dev(hdev);
0089 else
0090 kfree(hdev);
0091 module_put(THIS_MODULE);
0092 }
0093
0094 static const struct device_type bt_host = {
0095 .name = "host",
0096 .release = bt_host_release,
0097 };
0098
0099 void hci_init_sysfs(struct hci_dev *hdev)
0100 {
0101 struct device *dev = &hdev->dev;
0102
0103 dev->type = &bt_host;
0104 dev->class = bt_class;
0105
0106 __module_get(THIS_MODULE);
0107 device_initialize(dev);
0108 }
0109
0110 int __init bt_sysfs_init(void)
0111 {
0112 bt_class = class_create(THIS_MODULE, "bluetooth");
0113
0114 return PTR_ERR_OR_ZERO(bt_class);
0115 }
0116
0117 void bt_sysfs_cleanup(void)
0118 {
0119 class_destroy(bt_class);
0120 }