w1_netlink.h 3.5 KB

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