blob: 449680a615699a19aadca93951ed11410708af1e [file] [log] [blame]
Thomas Gleixnerc942fdd2019-05-27 08:55:06 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Evgeniy Polyakova8018762011-08-25 15:59:06 -07003 * Copyright (c) 2003 Evgeniy Polyakov <zbr@ioremap.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 */
5
6#ifndef __W1_NETLINK_H
7#define __W1_NETLINK_H
8
9#include <asm/types.h>
Evgeniy Polyakov12003372006-03-23 19:11:58 +030010#include <linux/connector.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Andrew F. Davisde0d6db2017-06-05 08:52:08 -050012#include "w1_internal.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
David Friesb3be1772014-01-15 22:29:25 -060014/**
David Fries8a0427d2014-04-08 22:37:09 -050015 * enum w1_cn_msg_flags - bitfield flags for struct cn_msg.flags
16 *
17 * @W1_CN_BUNDLE: Request bundling replies into fewer messagse. Be prepared
18 * to handle multiple struct cn_msg, struct w1_netlink_msg, and
19 * struct w1_netlink_cmd in one packet.
20 */
21enum w1_cn_msg_flags {
22 W1_CN_BUNDLE = 1,
23};
24
25/**
David Friesb3be1772014-01-15 22:29:25 -060026 * enum w1_netlink_message_types - message type
David Fries70b34d22014-01-15 22:29:17 -060027 *
28 * @W1_SLAVE_ADD: notification that a slave device was added
29 * @W1_SLAVE_REMOVE: notification that a slave device was removed
30 * @W1_MASTER_ADD: notification that a new bus master was added
31 * @W1_MASTER_REMOVE: notification that a bus masterwas removed
32 * @W1_MASTER_CMD: initiate operations on a specific master
33 * @W1_SLAVE_CMD: sends reset, selects the slave, then does a read/write/touch
34 * operation
35 * @W1_LIST_MASTERS: used to determine the bus master identifiers
36 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070037enum w1_netlink_message_types {
38 W1_SLAVE_ADD = 0,
39 W1_SLAVE_REMOVE,
40 W1_MASTER_ADD,
41 W1_MASTER_REMOVE,
Evgeniy Polyakov12003372006-03-23 19:11:58 +030042 W1_MASTER_CMD,
43 W1_SLAVE_CMD,
Evgeniy Polyakov610705e2009-01-07 18:08:59 -080044 W1_LIST_MASTERS,
Linus Torvalds1da177e2005-04-16 15:20:36 -070045};
46
David Fries8a0427d2014-04-08 22:37:09 -050047/**
48 * struct w1_netlink_msg - holds w1 message type, id, and result
49 *
50 * @type: one of enum w1_netlink_message_types
51 * @status: kernel feedback for success 0 or errno failure value
52 * @len: length of data following w1_netlink_msg
Mauro Carvalho Chehabaa931b42017-12-18 10:30:19 -020053 * @id: union holding bus master id (msg.id) and slave device id (id[8]).
54 * @id.id: Slave ID (8 bytes)
55 * @id.mst: bus master identification
56 * @id.mst.id: bus master ID
57 * @id.mst.res: bus master reserved
David Fries8a0427d2014-04-08 22:37:09 -050058 * @data: start address of any following data
59 *
60 * The base message structure for w1 messages over netlink.
61 * The netlink connector data sequence is, struct nlmsghdr, struct cn_msg,
62 * then one or more struct w1_netlink_msg (each with optional data).
63 */
Evgeniy Polyakov77859252005-05-20 22:33:25 +040064struct w1_netlink_msg
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
66 __u8 type;
Evgeniy Polyakov40370142009-01-07 18:09:05 -080067 __u8 status;
Evgeniy Polyakov12003372006-03-23 19:11:58 +030068 __u16 len;
69 union {
70 __u8 id[8];
71 struct w1_mst {
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 __u32 id;
Evgeniy Polyakov12003372006-03-23 19:11:58 +030073 __u32 res;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 } mst;
75 } id;
Gustavo A. R. Silva76fafbfff2020-05-28 09:35:11 -050076 __u8 data[];
Evgeniy Polyakov12003372006-03-23 19:11:58 +030077};
78
David Friesb3be1772014-01-15 22:29:25 -060079/**
80 * enum w1_commands - commands available for master or slave operations
David Fries8a0427d2014-04-08 22:37:09 -050081 *
David Fries70b34d22014-01-15 22:29:17 -060082 * @W1_CMD_READ: read len bytes
83 * @W1_CMD_WRITE: write len bytes
84 * @W1_CMD_SEARCH: initiate a standard search, returns only the slave
85 * devices found during that search
86 * @W1_CMD_ALARM_SEARCH: search for devices that are currently alarming
87 * @W1_CMD_TOUCH: Touches a series of bytes.
88 * @W1_CMD_RESET: sends a bus reset on the given master
89 * @W1_CMD_SLAVE_ADD: adds a slave to the given master,
90 * 8 byte slave id at data[0]
91 * @W1_CMD_SLAVE_REMOVE: removes a slave to the given master,
92 * 8 byte slave id at data[0]
93 * @W1_CMD_LIST_SLAVES: list of slaves registered on this master
94 * @W1_CMD_MAX: number of available commands
95 */
Evgeniy Polyakov325a06f2009-01-07 18:09:03 -080096enum w1_commands {
97 W1_CMD_READ = 0,
98 W1_CMD_WRITE,
99 W1_CMD_SEARCH,
100 W1_CMD_ALARM_SEARCH,
101 W1_CMD_TOUCH,
Evgeniy Polyakovf89735c2009-01-07 18:09:04 -0800102 W1_CMD_RESET,
David Fries70b34d22014-01-15 22:29:17 -0600103 W1_CMD_SLAVE_ADD,
104 W1_CMD_SLAVE_REMOVE,
105 W1_CMD_LIST_SLAVES,
106 W1_CMD_MAX
Evgeniy Polyakov325a06f2009-01-07 18:09:03 -0800107};
Evgeniy Polyakov12003372006-03-23 19:11:58 +0300108
David Fries8a0427d2014-04-08 22:37:09 -0500109/**
110 * struct w1_netlink_cmd - holds the command and data
111 *
112 * @cmd: one of enum w1_commands
113 * @res: reserved
114 * @len: length of data following w1_netlink_cmd
115 * @data: start address of any following data
116 *
117 * One or more struct w1_netlink_cmd is placed starting at w1_netlink_msg.data
118 * each with optional data.
119 */
Evgeniy Polyakov12003372006-03-23 19:11:58 +0300120struct w1_netlink_cmd
121{
122 __u8 cmd;
123 __u8 res;
124 __u16 len;
Gustavo A. R. Silva76fafbfff2020-05-28 09:35:11 -0500125 __u8 data[];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126};
127
128#ifdef __KERNEL__
129
130void w1_netlink_send(struct w1_master *, struct w1_netlink_msg *);
Evgeniy Polyakov12003372006-03-23 19:11:58 +0300131int w1_init_netlink(void);
132void w1_fini_netlink(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134#endif /* __KERNEL__ */
135#endif /* __W1_NETLINK_H */