w1_netlink.h 4.0 KB

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