hv_kvp.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * An implementation of HyperV key value pair (KVP) functionality for Linux.
  3. *
  4. *
  5. * Copyright (C) 2010, Novell, Inc.
  6. * Author : K. Y. Srinivasan <ksrinivasan@novell.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License version 2 as published
  10. * by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  15. * NON INFRINGEMENT. See the GNU General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. */
  23. #ifndef _KVP_H
  24. #define _KVP_H_
  25. /*
  26. * Maximum value size - used for both key names and value data, and includes
  27. * any applicable NULL terminators.
  28. *
  29. * Note: This limit is somewhat arbitrary, but falls easily within what is
  30. * supported for all native guests (back to Win 2000) and what is reasonable
  31. * for the IC KVP exchange functionality. Note that Windows Me/98/95 are
  32. * limited to 255 character key names.
  33. *
  34. * MSDN recommends not storing data values larger than 2048 bytes in the
  35. * registry.
  36. *
  37. * Note: This value is used in defining the KVP exchange message - this value
  38. * cannot be modified without affecting the message size and compatibility.
  39. */
  40. /*
  41. * bytes, including any null terminators
  42. */
  43. #define HV_KVP_EXCHANGE_MAX_VALUE_SIZE (2048)
  44. /*
  45. * Maximum key size - the registry limit for the length of an entry name
  46. * is 256 characters, including the null terminator
  47. */
  48. #define HV_KVP_EXCHANGE_MAX_KEY_SIZE (512)
  49. /*
  50. * In Linux, we implement the KVP functionality in two components:
  51. * 1) The kernel component which is packaged as part of the hv_utils driver
  52. * is responsible for communicating with the host and responsible for
  53. * implementing the host/guest protocol. 2) A user level daemon that is
  54. * responsible for data gathering.
  55. *
  56. * Host/Guest Protocol: The host iterates over an index and expects the guest
  57. * to assign a key name to the index and also return the value corresponding to
  58. * the key. The host will have atmost one KVP transaction outstanding at any
  59. * given point in time. The host side iteration stops when the guest returns
  60. * an error. Microsoft has specified the following mapping of key names to
  61. * host specified index:
  62. *
  63. * Index Key Name
  64. * 0 FullyQualifiedDomainName
  65. * 1 IntegrationServicesVersion
  66. * 2 NetworkAddressIPv4
  67. * 3 NetworkAddressIPv6
  68. * 4 OSBuildNumber
  69. * 5 OSName
  70. * 6 OSMajorVersion
  71. * 7 OSMinorVersion
  72. * 8 OSVersion
  73. * 9 ProcessorArchitecture
  74. *
  75. * The Windows host expects the Key Name and Key Value to be encoded in utf16.
  76. *
  77. * Guest Kernel/KVP Daemon Protocol: As noted earlier, we implement all of the
  78. * data gathering functionality in a user mode daemon. The user level daemon
  79. * is also responsible for binding the key name to the index as well. The
  80. * kernel and user-level daemon communicate using a connector channel.
  81. *
  82. * The user mode component first registers with the
  83. * the kernel component. Subsequently, the kernel component requests, data
  84. * for the specified keys. In response to this message the user mode component
  85. * fills in the value corresponding to the specified key. We overload the
  86. * sequence field in the cn_msg header to define our KVP message types.
  87. *
  88. *
  89. * The kernel component simply acts as a conduit for communication between the
  90. * Windows host and the user-level daemon. The kernel component passes up the
  91. * index received from the Host to the user-level daemon. If the index is
  92. * valid (supported), the corresponding key as well as its
  93. * value (both are strings) is returned. If the index is invalid
  94. * (not supported), a NULL key string is returned.
  95. */
  96. /*
  97. *
  98. * The following definitions are shared with the user-mode component; do not
  99. * change any of this without making the corresponding changes in
  100. * the KVP user-mode component.
  101. */
  102. #define CN_KVP_VAL 0x1 /* This supports queries from the kernel */
  103. #define CN_KVP_USER_VAL 0x2 /* This supports queries from the user */
  104. enum hv_ku_op {
  105. KVP_REGISTER = 0, /* Register the user mode component */
  106. KVP_KERNEL_GET, /* Kernel is requesting the value */
  107. KVP_KERNEL_SET, /* Kernel is providing the value */
  108. KVP_USER_GET, /* User is requesting the value */
  109. KVP_USER_SET /* User is providing the value */
  110. };
  111. struct hv_ku_msg {
  112. __u32 kvp_index; /* Key index */
  113. __u8 kvp_key[HV_KVP_EXCHANGE_MAX_KEY_SIZE]; /* Key name */
  114. __u8 kvp_value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE]; /* Key value */
  115. };
  116. #ifdef __KERNEL__
  117. /*
  118. * Registry value types.
  119. */
  120. #define REG_SZ 1
  121. enum hv_kvp_exchg_op {
  122. KVP_OP_GET = 0,
  123. KVP_OP_SET,
  124. KVP_OP_DELETE,
  125. KVP_OP_ENUMERATE,
  126. KVP_OP_COUNT /* Number of operations, must be last. */
  127. };
  128. enum hv_kvp_exchg_pool {
  129. KVP_POOL_EXTERNAL = 0,
  130. KVP_POOL_GUEST,
  131. KVP_POOL_AUTO,
  132. KVP_POOL_AUTO_EXTERNAL,
  133. KVP_POOL_AUTO_INTERNAL,
  134. KVP_POOL_COUNT /* Number of pools, must be last. */
  135. };
  136. struct hv_kvp_hdr {
  137. u8 operation;
  138. u8 pool;
  139. };
  140. struct hv_kvp_exchg_msg_value {
  141. u32 value_type;
  142. u32 key_size;
  143. u32 value_size;
  144. u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
  145. u8 value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE];
  146. };
  147. struct hv_kvp_msg_enumerate {
  148. u32 index;
  149. struct hv_kvp_exchg_msg_value data;
  150. };
  151. struct hv_kvp_msg {
  152. struct hv_kvp_hdr kvp_hdr;
  153. struct hv_kvp_msg_enumerate kvp_data;
  154. };
  155. int hv_kvp_init(struct hv_util_service *);
  156. void hv_kvp_deinit(void);
  157. void hv_kvp_onchannelcallback(void *);
  158. #endif /* __KERNEL__ */
  159. #endif /* _KVP_H */