1c942fddfSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 21da177e4SLinus Torvalds /* 3a8018766SEvgeniy Polyakov * Copyright (c) 2003 Evgeniy Polyakov <zbr@ioremap.net> 41da177e4SLinus Torvalds */ 51da177e4SLinus Torvalds 61da177e4SLinus Torvalds #ifndef __W1_NETLINK_H 71da177e4SLinus Torvalds #define __W1_NETLINK_H 81da177e4SLinus Torvalds 91da177e4SLinus Torvalds #include <asm/types.h> 1012003375SEvgeniy Polyakov #include <linux/connector.h> 111da177e4SLinus Torvalds 12de0d6dbdSAndrew F. Davis #include "w1_internal.h" 131da177e4SLinus Torvalds 14b3be177aSDavid Fries /** 158a0427d1SDavid Fries * enum w1_cn_msg_flags - bitfield flags for struct cn_msg.flags 168a0427d1SDavid Fries * 178a0427d1SDavid Fries * @W1_CN_BUNDLE: Request bundling replies into fewer messagse. Be prepared 188a0427d1SDavid Fries * to handle multiple struct cn_msg, struct w1_netlink_msg, and 198a0427d1SDavid Fries * struct w1_netlink_cmd in one packet. 208a0427d1SDavid Fries */ 218a0427d1SDavid Fries enum w1_cn_msg_flags { 228a0427d1SDavid Fries W1_CN_BUNDLE = 1, 238a0427d1SDavid Fries }; 248a0427d1SDavid Fries 258a0427d1SDavid Fries /** 26b3be177aSDavid Fries * enum w1_netlink_message_types - message type 2770b34d2eSDavid Fries * 2870b34d2eSDavid Fries * @W1_SLAVE_ADD: notification that a slave device was added 2970b34d2eSDavid Fries * @W1_SLAVE_REMOVE: notification that a slave device was removed 3070b34d2eSDavid Fries * @W1_MASTER_ADD: notification that a new bus master was added 3170b34d2eSDavid Fries * @W1_MASTER_REMOVE: notification that a bus masterwas removed 3270b34d2eSDavid Fries * @W1_MASTER_CMD: initiate operations on a specific master 3370b34d2eSDavid Fries * @W1_SLAVE_CMD: sends reset, selects the slave, then does a read/write/touch 3470b34d2eSDavid Fries * operation 3570b34d2eSDavid Fries * @W1_LIST_MASTERS: used to determine the bus master identifiers 3670b34d2eSDavid Fries */ 371da177e4SLinus Torvalds enum w1_netlink_message_types { 381da177e4SLinus Torvalds W1_SLAVE_ADD = 0, 391da177e4SLinus Torvalds W1_SLAVE_REMOVE, 401da177e4SLinus Torvalds W1_MASTER_ADD, 411da177e4SLinus Torvalds W1_MASTER_REMOVE, 4212003375SEvgeniy Polyakov W1_MASTER_CMD, 4312003375SEvgeniy Polyakov W1_SLAVE_CMD, 44610705e7SEvgeniy Polyakov W1_LIST_MASTERS, 451da177e4SLinus Torvalds }; 461da177e4SLinus Torvalds 478a0427d1SDavid Fries /** 488a0427d1SDavid Fries * struct w1_netlink_msg - holds w1 message type, id, and result 498a0427d1SDavid Fries * 508a0427d1SDavid Fries * @type: one of enum w1_netlink_message_types 518a0427d1SDavid Fries * @status: kernel feedback for success 0 or errno failure value 528a0427d1SDavid Fries * @len: length of data following w1_netlink_msg 53aa931b44SMauro Carvalho Chehab * @id: union holding bus master id (msg.id) and slave device id (id[8]). 54aa931b44SMauro Carvalho Chehab * @id.id: Slave ID (8 bytes) 55aa931b44SMauro Carvalho Chehab * @id.mst: bus master identification 56aa931b44SMauro Carvalho Chehab * @id.mst.id: bus master ID 57aa931b44SMauro Carvalho Chehab * @id.mst.res: bus master reserved 588a0427d1SDavid Fries * @data: start address of any following data 598a0427d1SDavid Fries * 608a0427d1SDavid Fries * The base message structure for w1 messages over netlink. 618a0427d1SDavid Fries * The netlink connector data sequence is, struct nlmsghdr, struct cn_msg, 628a0427d1SDavid Fries * then one or more struct w1_netlink_msg (each with optional data). 638a0427d1SDavid Fries */ 641da177e4SLinus Torvalds struct w1_netlink_msg 651da177e4SLinus Torvalds { 661da177e4SLinus Torvalds __u8 type; 674037014eSEvgeniy Polyakov __u8 status; 6812003375SEvgeniy Polyakov __u16 len; 6912003375SEvgeniy Polyakov union { 7012003375SEvgeniy Polyakov __u8 id[8]; 7112003375SEvgeniy Polyakov struct w1_mst { 721da177e4SLinus Torvalds __u32 id; 7312003375SEvgeniy Polyakov __u32 res; 741da177e4SLinus Torvalds } mst; 751da177e4SLinus Torvalds } id; 76*76fafbffSGustavo A. R. Silva __u8 data[]; 7712003375SEvgeniy Polyakov }; 7812003375SEvgeniy Polyakov 79b3be177aSDavid Fries /** 80b3be177aSDavid Fries * enum w1_commands - commands available for master or slave operations 818a0427d1SDavid Fries * 8270b34d2eSDavid Fries * @W1_CMD_READ: read len bytes 8370b34d2eSDavid Fries * @W1_CMD_WRITE: write len bytes 8470b34d2eSDavid Fries * @W1_CMD_SEARCH: initiate a standard search, returns only the slave 8570b34d2eSDavid Fries * devices found during that search 8670b34d2eSDavid Fries * @W1_CMD_ALARM_SEARCH: search for devices that are currently alarming 8770b34d2eSDavid Fries * @W1_CMD_TOUCH: Touches a series of bytes. 8870b34d2eSDavid Fries * @W1_CMD_RESET: sends a bus reset on the given master 8970b34d2eSDavid Fries * @W1_CMD_SLAVE_ADD: adds a slave to the given master, 9070b34d2eSDavid Fries * 8 byte slave id at data[0] 9170b34d2eSDavid Fries * @W1_CMD_SLAVE_REMOVE: removes a slave to the given master, 9270b34d2eSDavid Fries * 8 byte slave id at data[0] 9370b34d2eSDavid Fries * @W1_CMD_LIST_SLAVES: list of slaves registered on this master 9470b34d2eSDavid Fries * @W1_CMD_MAX: number of available commands 9570b34d2eSDavid Fries */ 96325a06fbSEvgeniy Polyakov enum w1_commands { 97325a06fbSEvgeniy Polyakov W1_CMD_READ = 0, 98325a06fbSEvgeniy Polyakov W1_CMD_WRITE, 99325a06fbSEvgeniy Polyakov W1_CMD_SEARCH, 100325a06fbSEvgeniy Polyakov W1_CMD_ALARM_SEARCH, 101325a06fbSEvgeniy Polyakov W1_CMD_TOUCH, 102f89735c4SEvgeniy Polyakov W1_CMD_RESET, 10370b34d2eSDavid Fries W1_CMD_SLAVE_ADD, 10470b34d2eSDavid Fries W1_CMD_SLAVE_REMOVE, 10570b34d2eSDavid Fries W1_CMD_LIST_SLAVES, 10670b34d2eSDavid Fries W1_CMD_MAX 107325a06fbSEvgeniy Polyakov }; 10812003375SEvgeniy Polyakov 1098a0427d1SDavid Fries /** 1108a0427d1SDavid Fries * struct w1_netlink_cmd - holds the command and data 1118a0427d1SDavid Fries * 1128a0427d1SDavid Fries * @cmd: one of enum w1_commands 1138a0427d1SDavid Fries * @res: reserved 1148a0427d1SDavid Fries * @len: length of data following w1_netlink_cmd 1158a0427d1SDavid Fries * @data: start address of any following data 1168a0427d1SDavid Fries * 1178a0427d1SDavid Fries * One or more struct w1_netlink_cmd is placed starting at w1_netlink_msg.data 1188a0427d1SDavid Fries * each with optional data. 1198a0427d1SDavid Fries */ 12012003375SEvgeniy Polyakov struct w1_netlink_cmd 12112003375SEvgeniy Polyakov { 12212003375SEvgeniy Polyakov __u8 cmd; 12312003375SEvgeniy Polyakov __u8 res; 12412003375SEvgeniy Polyakov __u16 len; 125*76fafbffSGustavo A. R. Silva __u8 data[]; 1261da177e4SLinus Torvalds }; 1271da177e4SLinus Torvalds 1281da177e4SLinus Torvalds #ifdef __KERNEL__ 1291da177e4SLinus Torvalds 1301da177e4SLinus Torvalds void w1_netlink_send(struct w1_master *, struct w1_netlink_msg *); 13112003375SEvgeniy Polyakov int w1_init_netlink(void); 13212003375SEvgeniy Polyakov void w1_fini_netlink(void); 1331da177e4SLinus Torvalds 1341da177e4SLinus Torvalds #endif /* __KERNEL__ */ 1351da177e4SLinus Torvalds #endif /* __W1_NETLINK_H */ 136