Commit 139a19e4 authored by Evgeniy Polyakov's avatar Evgeniy Polyakov Committed by Greg Kroah-Hartman

[PATCH] w1: Netlink update - changed event generating/processing.

Added following self-explanatory netlink events.

        W1_SLAVE_ADD = 0,
        W1_SLAVE_REMOVE,
        W1_MASTER_ADD,
        W1_MASTER_REMOVE,
Signed-off-by: default avatarEvgeniy Polyakov <johnpol@2ka.mipt.ru>
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent c7ddf55a
......@@ -383,6 +383,7 @@ static int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn)
struct w1_slave *sl;
struct w1_family *f;
int err;
struct w1_netlink_msg msg;
sl = kmalloc(sizeof(struct w1_slave), GFP_KERNEL);
if (!sl) {
......@@ -427,11 +428,17 @@ static int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn)
dev->slave_count++;
msg.id.id = *rn;
msg.type = W1_SLAVE_ADD;
w1_netlink_send(dev, &msg);
return 0;
}
static void w1_slave_detach(struct w1_slave *sl)
{
struct w1_netlink_msg msg;
dev_info(&sl->dev, "%s: detaching %s.\n", __func__, sl->name);
while (atomic_read(&sl->refcnt))
......@@ -441,6 +448,10 @@ static void w1_slave_detach(struct w1_slave *sl)
device_remove_file(&sl->dev, &w1_slave_attribute);
device_unregister(&sl->dev);
w1_family_put(sl->family);
msg.id.id = sl->reg_num;
msg.type = W1_SLAVE_REMOVE;
w1_netlink_send(sl->master, &msg);
}
static void w1_search(struct w1_master *dev)
......@@ -452,12 +463,9 @@ static void w1_search(struct w1_master *dev)
struct list_head *ent;
struct w1_slave *sl;
int family_found = 0;
struct w1_netlink_msg msg;
dev->attempts++;
memset(&msg, 0, sizeof(msg));
search_bit = id_bit = comp_bit = 0;
rn = tmp = last = 0;
last_device = last_zero = last_family_desc = 0;
......@@ -483,8 +491,6 @@ static void w1_search(struct w1_master *dev)
}
#if 1
memset(&msg, 0, sizeof(msg));
w1_write_8(dev, W1_SEARCH);
for (i = 0; i < 64; ++i) {
/*
......@@ -528,9 +534,6 @@ static void w1_search(struct w1_master *dev)
}
#endif
msg.id.w1_id = rn;
msg.val = w1_calc_crc8((u8 *) & rn, 7);
w1_netlink_send(dev, &msg);
if (desc_bit == last_zero)
last_device = 1;
......@@ -558,7 +561,7 @@ static void w1_search(struct w1_master *dev)
}
if (slave_count == dev->slave_count &&
msg.val && (*((__u8 *) & msg.val) == msg.id.id.crc)) {
((rn >> 56) & 0xff) == w1_calc_crc8((u8 *)&rn, 7)) {
w1_attach_slave_device(dev, (struct w1_reg_num *) &rn);
}
}
......
......@@ -24,6 +24,7 @@
#include "w1.h"
#include "w1_log.h"
#include "w1_netlink.h"
static u32 w1_ids = 1;
......@@ -118,6 +119,7 @@ int w1_add_master_device(struct w1_bus_master *master)
{
struct w1_master *dev;
int retval = 0;
struct w1_netlink_msg msg;
dev = w1_alloc_dev(w1_ids++, w1_max_slave_count, &w1_driver, &w1_device);
if (!dev)
......@@ -144,6 +146,11 @@ int w1_add_master_device(struct w1_bus_master *master)
list_add(&dev->w1_master_entry, &w1_masters);
spin_unlock(&w1_mlock);
msg.id.mst.id = dev->id;
msg.id.mst.pid = dev->kpid;
msg.type = W1_MASTER_ADD;
w1_netlink_send(dev, &msg);
return 0;
err_out_kill_thread:
......@@ -163,6 +170,7 @@ int w1_add_master_device(struct w1_bus_master *master)
void __w1_remove_master_device(struct w1_master *dev)
{
int err;
struct w1_netlink_msg msg;
dev->need_exit = 1;
err = kill_proc(dev->kpid, SIGTERM, 1);
......@@ -174,6 +182,11 @@ void __w1_remove_master_device(struct w1_master *dev)
while (atomic_read(&dev->refcnt))
schedule_timeout(10);
msg.id.mst.id = dev->id;
msg.id.mst.pid = dev->kpid;
msg.type = W1_MASTER_REMOVE;
w1_netlink_send(dev, &msg);
w1_free_dev(dev);
}
......
......@@ -26,14 +26,27 @@
#include "w1.h"
enum w1_netlink_message_types {
W1_SLAVE_ADD = 0,
W1_SLAVE_REMOVE,
W1_MASTER_ADD,
W1_MASTER_REMOVE,
};
struct w1_netlink_msg
{
__u8 type;
__u8 reserved[3];
union
{
struct w1_reg_num id;
__u64 w1_id;
struct
{
__u32 id;
__u32 pid;
} mst;
} id;
__u64 val;
};
#ifdef __KERNEL__
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment