2 * Copyright (c) 2014 Microsoft Corp.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * An implementation of HyperV key value pair (KVP) functionality for FreeBSD
38 * Maximum value size - used for both key names and value data, and includes
39 * any applicable NULL terminators.
41 * Note: This limit is somewhat arbitrary, but falls easily within what is
42 * supported for all native guests (back to Win 2000) and what is reasonable
43 * for the IC KVP exchange functionality. Note that Windows Me/98/95 are
44 * limited to 255 character key names.
46 * MSDN recommends not storing data values larger than 2048 bytes in the
49 * Note: This value is used in defining the KVP exchange message - this value
50 * cannot be modified without affecting the message size and compatibility.
54 * bytes, including any null terminators
56 #define HV_KVP_EXCHANGE_MAX_VALUE_SIZE (2048)
60 * Maximum key size - the registry limit for the length of an entry name
61 * is 256 characters, including the null terminator
63 #define HV_KVP_EXCHANGE_MAX_KEY_SIZE (512)
67 * In FreeBSD, we implement the KVP functionality in two components:
68 * 1) The kernel component which is packaged as part of the hv_utils driver
69 * is responsible for communicating with the host and responsible for
70 * implementing the host/guest protocol. 2) A user level daemon that is
71 * responsible for data gathering.
73 * Host/Guest Protocol: The host iterates over an index and expects the guest
74 * to assign a key name to the index and also return the value corresponding to
75 * the key. The host will have atmost one KVP transaction outstanding at any
76 * given point in time. The host side iteration stops when the guest returns
77 * an error. Microsoft has specified the following mapping of key names to
78 * host specified index:
81 * 0 FullyQualifiedDomainName
82 * 1 IntegrationServicesVersion
83 * 2 NetworkAddressIPv4
84 * 3 NetworkAddressIPv6
90 * 9 ProcessorArchitecture
92 * The Windows host expects the Key Name and Key Value to be encoded in utf16.
94 * Guest Kernel/KVP Daemon Protocol: As noted earlier, we implement all of the
95 * data gathering functionality in a user mode daemon. The user level daemon
96 * is also responsible for binding the key name to the index as well. The
97 * kernel and user-level daemon communicate using a connector channel.
99 * The user mode component first registers with the
100 * the kernel component. Subsequently, the kernel component requests, data
101 * for the specified keys. In response to this message the user mode component
102 * fills in the value corresponding to the specified key. We overload the
103 * sequence field in the cn_msg header to define our KVP message types.
106 * The kernel component simply acts as a conduit for communication between the
107 * Windows host and the user-level daemon. The kernel component passes up the
108 * index received from the Host to the user-level daemon. If the index is
109 * valid (supported), the corresponding key as well as its
110 * value (both are strings) is returned. If the index is invalid
111 * (not supported), a NULL key string is returned.
116 * Registry value types.
124 * Daemon code supporting IP injection.
126 #define HV_KVP_OP_REGISTER 4
129 enum hv_kvp_exchg_op {
134 HV_KVP_OP_GET_IP_INFO,
135 HV_KVP_OP_SET_IP_INFO,
136 HV_KVP_OP_COUNT /* Number of operations, must be last. */
139 enum hv_kvp_exchg_pool {
140 HV_KVP_POOL_EXTERNAL = 0,
143 HV_KVP_POOL_AUTO_EXTERNAL,
144 HV_KVP_POOL_AUTO_INTERNAL,
145 HV_KVP_POOL_COUNT /* Number of pools, must be last. */
150 * Some Hyper-V status codes.
152 #define HV_KVP_S_OK 0x00000000
153 #define HV_KVP_E_FAIL 0x80004005
154 #define HV_KVP_S_CONT 0x80070103
155 #define HV_ERROR_NOT_SUPPORTED 0x80070032
156 #define HV_ERROR_MACHINE_LOCKED 0x800704F7
157 #define HV_ERROR_DEVICE_NOT_CONNECTED 0x8007048F
158 #define HV_INVALIDARG 0x80070057
159 #define HV_KVP_GUID_NOTFOUND 0x80041002
161 #define ADDR_FAMILY_NONE 0x00
162 #define ADDR_FAMILY_IPV4 0x01
163 #define ADDR_FAMILY_IPV6 0x02
165 #define MAX_ADAPTER_ID_SIZE 128
166 #define MAX_IP_ADDR_SIZE 1024
167 #define MAX_GATEWAY_SIZE 512
170 struct hv_kvp_ipaddr_value {
171 uint16_t adapter_id[MAX_ADAPTER_ID_SIZE];
173 uint8_t dhcp_enabled;
174 uint16_t ip_addr[MAX_IP_ADDR_SIZE];
175 uint16_t sub_net[MAX_IP_ADDR_SIZE];
176 uint16_t gate_way[MAX_GATEWAY_SIZE];
177 uint16_t dns_addr[MAX_IP_ADDR_SIZE];
178 }__attribute__((packed));
184 } __attribute__((packed));
186 struct hv_kvp_exchg_msg_value {
190 uint8_t key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
192 uint8_t value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE];
196 } __attribute__((packed));
198 struct hv_kvp_msg_enumerate {
200 struct hv_kvp_exchg_msg_value data;
201 } __attribute__((packed));
203 struct hv_kvp_msg_get {
204 struct hv_kvp_exchg_msg_value data;
205 } __attribute__((packed));
207 struct hv_kvp_msg_set {
208 struct hv_kvp_exchg_msg_value data;
209 } __attribute__((packed));
211 struct hv_kvp_msg_delete {
213 uint8_t key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
214 } __attribute__((packed));
216 struct hv_kvp_register {
217 uint8_t version[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
218 } __attribute__((packed));
222 struct hv_kvp_hdr kvp_hdr;
226 struct hv_kvp_msg_get kvp_get;
227 struct hv_kvp_msg_set kvp_set;
228 struct hv_kvp_msg_delete kvp_delete;
229 struct hv_kvp_msg_enumerate kvp_enum_data;
230 struct hv_kvp_ipaddr_value kvp_ip_val;
231 struct hv_kvp_register kvp_register;
233 } __attribute__((packed));
235 struct hv_kvp_ip_msg {
238 struct hv_kvp_ipaddr_value kvp_ip_val;
239 } __attribute__((packed));
242 #define HV_SHUT_DOWN 0
243 #define HV_TIME_SYNCH 1
244 #define HV_HEART_BEAT 2
246 #define HV_MAX_UTIL_SERVICES 4
248 #define HV_WLTIMEDELTA 116444736000000000L /* in 100ns unit */
249 #define HV_ICTIMESYNCFLAG_PROBE 0
250 #define HV_ICTIMESYNCFLAG_SYNC 1
251 #define HV_ICTIMESYNCFLAG_SAMPLE 2
252 #define HV_NANO_SEC_PER_SEC 1000000000