^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (c) 2003 Evgeniy Polyakov <zbr@ioremap.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #ifndef __W1_NETLINK_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #define __W1_NETLINK_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <asm/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/connector.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "w1_internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * enum w1_cn_msg_flags - bitfield flags for struct cn_msg.flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * @W1_CN_BUNDLE: Request bundling replies into fewer messagse. Be prepared
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * to handle multiple struct cn_msg, struct w1_netlink_msg, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * struct w1_netlink_cmd in one packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) enum w1_cn_msg_flags {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) W1_CN_BUNDLE = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * enum w1_netlink_message_types - message type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * @W1_SLAVE_ADD: notification that a slave device was added
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * @W1_SLAVE_REMOVE: notification that a slave device was removed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * @W1_MASTER_ADD: notification that a new bus master was added
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * @W1_MASTER_REMOVE: notification that a bus masterwas removed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * @W1_MASTER_CMD: initiate operations on a specific master
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * @W1_SLAVE_CMD: sends reset, selects the slave, then does a read/write/touch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * @W1_LIST_MASTERS: used to determine the bus master identifiers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) enum w1_netlink_message_types {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) W1_SLAVE_ADD = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) W1_SLAVE_REMOVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) W1_MASTER_ADD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) W1_MASTER_REMOVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) W1_MASTER_CMD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) W1_SLAVE_CMD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) W1_LIST_MASTERS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * struct w1_netlink_msg - holds w1 message type, id, and result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * @type: one of enum w1_netlink_message_types
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * @status: kernel feedback for success 0 or errno failure value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * @len: length of data following w1_netlink_msg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * @id: union holding bus master id (msg.id) and slave device id (id[8]).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * @id.id: Slave ID (8 bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * @id.mst: bus master identification
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * @id.mst.id: bus master ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * @id.mst.res: bus master reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * @data: start address of any following data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * The base message structure for w1 messages over netlink.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * The netlink connector data sequence is, struct nlmsghdr, struct cn_msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * then one or more struct w1_netlink_msg (each with optional data).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct w1_netlink_msg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) __u8 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) __u8 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) __u16 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) __u8 id[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct w1_mst {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) __u32 id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) __u32 res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) } mst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) } id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) __u8 data[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * enum w1_commands - commands available for master or slave operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * @W1_CMD_READ: read len bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * @W1_CMD_WRITE: write len bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * @W1_CMD_SEARCH: initiate a standard search, returns only the slave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * devices found during that search
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * @W1_CMD_ALARM_SEARCH: search for devices that are currently alarming
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * @W1_CMD_TOUCH: Touches a series of bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * @W1_CMD_RESET: sends a bus reset on the given master
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * @W1_CMD_SLAVE_ADD: adds a slave to the given master,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * 8 byte slave id at data[0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * @W1_CMD_SLAVE_REMOVE: removes a slave to the given master,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * 8 byte slave id at data[0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * @W1_CMD_LIST_SLAVES: list of slaves registered on this master
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * @W1_CMD_MAX: number of available commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) enum w1_commands {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) W1_CMD_READ = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) W1_CMD_WRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) W1_CMD_SEARCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) W1_CMD_ALARM_SEARCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) W1_CMD_TOUCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) W1_CMD_RESET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) W1_CMD_SLAVE_ADD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) W1_CMD_SLAVE_REMOVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) W1_CMD_LIST_SLAVES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) W1_CMD_MAX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * struct w1_netlink_cmd - holds the command and data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * @cmd: one of enum w1_commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * @res: reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * @len: length of data following w1_netlink_cmd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * @data: start address of any following data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * One or more struct w1_netlink_cmd is placed starting at w1_netlink_msg.data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * each with optional data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct w1_netlink_cmd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) __u8 cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) __u8 res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) __u16 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) __u8 data[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) #ifdef __KERNEL__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) void w1_netlink_send(struct w1_master *, struct w1_netlink_msg *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) int w1_init_netlink(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) void w1_fini_netlink(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) #endif /* __KERNEL__ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #endif /* __W1_NETLINK_H */