]>
Commit | Line | Data |
---|---|---|
9bccf70c | 1 | /* |
39037602 | 2 | * Copyright (c) 2000-2004, 2012-2016 Apple Inc. All rights reserved. |
5d5c5d0d | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
9bccf70c | 5 | * |
2d21ac55 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
9bccf70c | 27 | */ |
91447636 A |
28 | /*! |
29 | @header kern_control.h | |
30 | This header defines an API to communicate between a kernel | |
31 | extension and a process outside of the kernel. | |
32 | */ | |
9bccf70c | 33 | |
91447636 A |
34 | #ifndef KPI_KERN_CONTROL_H |
35 | #define KPI_KERN_CONTROL_H | |
9bccf70c | 36 | |
9bccf70c A |
37 | |
38 | #include <sys/appleapiopts.h> | |
39 | ||
9bccf70c A |
40 | /* |
41 | * Define Controller event subclass, and associated events. | |
91447636 | 42 | * Subclass of KEV_SYSTEM_CLASS |
9bccf70c A |
43 | */ |
44 | ||
91447636 A |
45 | /*! |
46 | @defined KEV_CTL_SUBCLASS | |
47 | @discussion The kernel event subclass for kernel control events. | |
48 | */ | |
49 | #define KEV_CTL_SUBCLASS 2 | |
50 | ||
51 | /*! | |
52 | @defined KEV_CTL_REGISTERED | |
53 | @discussion The event code indicating a new controller was | |
54 | registered. The data portion will contain a ctl_event_data. | |
55 | */ | |
56 | #define KEV_CTL_REGISTERED 1 /* a new controller appears */ | |
9bccf70c | 57 | |
91447636 A |
58 | /*! |
59 | @defined KEV_CTL_DEREGISTERED | |
60 | @discussion The event code indicating a controller was unregistered. | |
61 | The data portion will contain a ctl_event_data. | |
62 | */ | |
63 | #define KEV_CTL_DEREGISTERED 2 /* a controller disappears */ | |
9bccf70c | 64 | |
91447636 A |
65 | /*! |
66 | @struct ctl_event_data | |
67 | @discussion This structure is used for KEV_CTL_SUBCLASS kernel | |
68 | events. | |
69 | @field ctl_id The kernel control id. | |
70 | @field ctl_unit The kernel control unit. | |
71 | */ | |
9bccf70c | 72 | struct ctl_event_data { |
91447636 | 73 | u_int32_t ctl_id; /* Kernel Controller ID */ |
9bccf70c A |
74 | u_int32_t ctl_unit; |
75 | }; | |
76 | ||
9bccf70c A |
77 | /* |
78 | * Controls destined to the Controller Manager. | |
79 | */ | |
80 | ||
91447636 A |
81 | /*! |
82 | @defined CTLIOCGCOUNT | |
83 | @discussion The CTLIOCGCOUNT ioctl can be used to determine the | |
84 | number of kernel controllers registered. | |
85 | */ | |
86 | #define CTLIOCGCOUNT _IOR('N', 2, int) /* get number of control structures registered */ | |
87 | ||
88 | /*! | |
89 | @defined CTLIOCGINFO | |
90 | @discussion The CTLIOCGINFO ioctl can be used to convert a kernel | |
91 | control name to a kernel control id. | |
92 | */ | |
93 | #define CTLIOCGINFO _IOWR('N', 3, struct ctl_info) /* get id from name */ | |
94 | ||
95 | ||
96 | /*! | |
97 | @defined MAX_KCTL_NAME | |
98 | @discussion Kernel control names must be no longer than | |
99 | MAX_KCTL_NAME. | |
100 | */ | |
101 | #define MAX_KCTL_NAME 96 | |
9bccf70c A |
102 | |
103 | /* | |
91447636 | 104 | * Controls destined to the Controller Manager. |
9bccf70c A |
105 | */ |
106 | ||
91447636 A |
107 | /*! |
108 | @struct ctl_info | |
109 | @discussion This structure is used with the CTLIOCGINFO ioctl to | |
110 | translate from a kernel control name to a control id. | |
111 | @field ctl_id The kernel control id, filled out upon return. | |
112 | @field ctl_name The kernel control name to find. | |
113 | */ | |
114 | struct ctl_info { | |
115 | u_int32_t ctl_id; /* Kernel Controller ID */ | |
116 | char ctl_name[MAX_KCTL_NAME]; /* Kernel Controller Name (a C string) */ | |
117 | }; | |
118 | ||
119 | ||
120 | /*! | |
121 | @struct sockaddr_ctl | |
122 | @discussion The controller address structure is used to establish | |
123 | contact between a user client and a kernel controller. The | |
124 | sc_id/sc_unit uniquely identify each controller. sc_id is a | |
125 | unique identifier assigned to the controller. The identifier can | |
126 | be assigned by the system at registration time or be a 32-bit | |
127 | creator code obtained from Apple Computer. sc_unit is a unit | |
128 | number for this sc_id, and is privately used by the kernel | |
129 | controller to identify several instances of the controller. | |
130 | @field sc_len The length of the structure. | |
131 | @field sc_family AF_SYSTEM. | |
132 | @field ss_sysaddr AF_SYS_KERNCONTROL. | |
133 | @field sc_id Controller unique identifier. | |
134 | @field sc_unit Kernel controller private unit number. | |
135 | @field sc_reserved Reserved, must be set to zero. | |
136 | */ | |
137 | struct sockaddr_ctl { | |
fe8ab488 A |
138 | u_char sc_len; /* depends on size of bundle ID string */ |
139 | u_char sc_family; /* AF_SYSTEM */ | |
91447636 A |
140 | u_int16_t ss_sysaddr; /* AF_SYS_KERNCONTROL */ |
141 | u_int32_t sc_id; /* Controller unique identifier */ | |
9bccf70c A |
142 | u_int32_t sc_unit; /* Developer private unit number */ |
143 | u_int32_t sc_reserved[5]; | |
144 | }; | |
9bccf70c | 145 | |
fe8ab488 A |
146 | #ifdef PRIVATE |
147 | ||
148 | struct xkctl_reg { | |
149 | u_int32_t xkr_len; | |
150 | u_int32_t xkr_kind; | |
151 | u_int32_t xkr_id; | |
152 | u_int32_t xkr_reg_unit; | |
153 | u_int32_t xkr_flags; | |
154 | u_int64_t xkr_kctlref; | |
155 | u_int32_t xkr_recvbufsize; | |
156 | u_int32_t xkr_sendbufsize; | |
157 | u_int32_t xkr_lastunit; | |
158 | u_int32_t xkr_pcbcount; | |
159 | u_int64_t xkr_connect; | |
160 | u_int64_t xkr_disconnect; | |
161 | u_int64_t xkr_send; | |
162 | u_int64_t xkr_send_list; | |
163 | u_int64_t xkr_setopt; | |
164 | u_int64_t xkr_getopt; | |
165 | u_int64_t xkr_rcvd; | |
166 | char xkr_name[MAX_KCTL_NAME]; | |
167 | }; | |
168 | ||
169 | struct xkctlpcb { | |
170 | u_int32_t xkp_len; | |
171 | u_int32_t xkp_kind; | |
172 | u_int64_t xkp_kctpcb; | |
173 | u_int32_t xkp_unit; | |
174 | u_int32_t xkp_kctlid; | |
175 | u_int64_t xkp_kctlref; | |
176 | char xkp_kctlname[MAX_KCTL_NAME]; | |
177 | }; | |
178 | ||
179 | struct kctlstat { | |
180 | u_int64_t kcs_reg_total __attribute__((aligned(8))); | |
181 | u_int64_t kcs_reg_count __attribute__((aligned(8))); | |
182 | u_int64_t kcs_pcbcount __attribute__((aligned(8))); | |
183 | u_int64_t kcs_gencnt __attribute__((aligned(8))); | |
184 | u_int64_t kcs_connections __attribute__((aligned(8))); | |
185 | u_int64_t kcs_conn_fail __attribute__((aligned(8))); | |
186 | u_int64_t kcs_send_fail __attribute__((aligned(8))); | |
187 | u_int64_t kcs_send_list_fail __attribute__((aligned(8))); | |
188 | u_int64_t kcs_enqueue_fail __attribute__((aligned(8))); | |
189 | u_int64_t kcs_enqueue_fullsock __attribute__((aligned(8))); | |
3e170ce0 | 190 | u_int64_t kcs_bad_kctlref __attribute__((aligned(8))); |
39037602 A |
191 | u_int64_t kcs_tbl_size_too_big __attribute__((aligned(8))); |
192 | u_int64_t kcs_enqdata_mb_alloc_fail __attribute__((aligned(8))); | |
193 | u_int64_t kcs_enqdata_sbappend_fail __attribute__((aligned(8))); | |
fe8ab488 A |
194 | }; |
195 | ||
196 | #endif /* PRIVATE */ | |
197 | ||
9bccf70c | 198 | #ifdef KERNEL |
9bccf70c | 199 | |
91447636 A |
200 | #include <sys/kpi_mbuf.h> |
201 | ||
202 | /*! | |
203 | @typedef kern_ctl_ref | |
204 | @discussion A control reference is used to track an attached kernel | |
205 | control. Registering a kernel control will create a kernel | |
206 | control reference. This reference is required for sending data | |
207 | or removing the kernel control. This reference will be passed to | |
208 | callbacks for that kernel control. | |
209 | */ | |
9bccf70c A |
210 | typedef void * kern_ctl_ref; |
211 | ||
91447636 A |
212 | /*! |
213 | @defined CTL_FLAG_PRIVILEGED | |
214 | @discussion The CTL_FLAG_PRIVILEGED flag is passed in ctl_flags. If | |
215 | this flag is set, only privileged processes may attach to this | |
216 | kernel control. | |
217 | */ | |
218 | #define CTL_FLAG_PRIVILEGED 0x1 | |
219 | /*! | |
220 | @defined CTL_FLAG_REG_ID_UNIT | |
221 | @discussion The CTL_FLAG_REG_ID_UNIT flag is passed to indicate that | |
222 | the ctl_id specified should be used. If this flag is not | |
223 | present, a unique ctl_id will be dynamically assigned to your | |
224 | kernel control. The CTLIOCGINFO ioctl can be used by the client | |
225 | to find the dynamically assigned id based on the control name | |
226 | specified in ctl_name. | |
227 | */ | |
228 | #define CTL_FLAG_REG_ID_UNIT 0x2 | |
229 | /*! | |
230 | @defined CTL_FLAG_REG_SOCK_STREAM | |
231 | @discussion Use the CTL_FLAG_REG_SOCK_STREAM flag when client need to open | |
232 | socket of type SOCK_STREAM to communicate with the kernel control. | |
233 | By default kernel control sockets are of type SOCK_DGRAM. | |
234 | */ | |
235 | #define CTL_FLAG_REG_SOCK_STREAM 0x4 | |
9bccf70c | 236 | |
39236c6e A |
237 | #ifdef KERNEL_PRIVATE |
238 | /*! | |
239 | @defined CTL_FLAG_REG_EXTENDED | |
240 | @discussion This flag indicates that this kernel control utilizes the | |
241 | the extended fields within the kern_ctl_reg structure. | |
242 | */ | |
243 | #define CTL_FLAG_REG_EXTENDED 0x8 | |
fe8ab488 A |
244 | |
245 | /*! | |
246 | @defined CTL_FLAG_REG_CRIT | |
247 | @discussion This flag indicates that this kernel control utilizes the | |
248 | the extended fields within the kern_ctl_reg structure. | |
249 | */ | |
250 | #define CTL_FLAG_REG_CRIT 0x10 | |
39236c6e A |
251 | #endif /* KERNEL_PRIVATE */ |
252 | ||
9bccf70c | 253 | /* Data flags for controllers */ |
91447636 A |
254 | /*! |
255 | @defined CTL_DATA_NOWAKEUP | |
256 | @discussion The CTL_DATA_NOWAKEUP flag can be used for the enqueue | |
257 | data and enqueue mbuf functions to indicate that the process | |
258 | should not be woken up yet. This is useful when you want to | |
259 | enqueue data using more than one call but only want to wake up | |
260 | the client after all of the data has been enqueued. | |
261 | */ | |
262 | #define CTL_DATA_NOWAKEUP 0x1 | |
fe8ab488 | 263 | |
91447636 A |
264 | /*! |
265 | @defined CTL_DATA_EOR | |
2d21ac55 | 266 | @discussion The CTL_DATA_EOR flag can be used for the enqueue |
91447636 A |
267 | data and enqueue mbuf functions to mark the end of a record. |
268 | */ | |
269 | #define CTL_DATA_EOR 0x2 | |
9bccf70c | 270 | |
fe8ab488 A |
271 | #ifdef KERNEL_PRIVATE |
272 | /*! | |
273 | @defined CTL_DATA_CRIT | |
274 | @discussion This flag indicates the data is critical to the client | |
275 | and that it needs to be forced into the socket buffer | |
276 | by resizing it if needed. | |
277 | */ | |
278 | #define CTL_DATA_CRIT 0x4 | |
279 | #endif /* KERNEL_PRIVATE */ | |
280 | ||
2d21ac55 A |
281 | __BEGIN_DECLS |
282 | ||
91447636 A |
283 | /*! |
284 | @typedef ctl_connect_func | |
285 | @discussion The ctl_connect_func is used to receive | |
286 | notification of a client connecting to the kernel control. | |
287 | @param kctlref The control ref for the kernel control the client is | |
288 | connecting to. | |
289 | @param sac The address used to connect to this control. The field sc_unit | |
290 | contains the unit number of the kernel control instance the client is | |
291 | connecting to. If CTL_FLAG_REG_ID_UNIT was set when the kernel control | |
292 | was registered, sc_unit is the ctl_unit of the kern_ctl_reg structure. | |
293 | If CTL_FLAG_REG_ID_UNIT was not set when the kernel control was | |
294 | registered, sc_unit is the dynamically allocated unit number of | |
295 | the new kernel control instance that is used for this connection. | |
2d21ac55 A |
296 | @param unitinfo A placeholder for a pointer to the optional user-defined |
297 | private data associated with this kernel control instance. This | |
298 | opaque info will be provided to the user when the rest of the | |
299 | callback routines are executed. For example, it can be used | |
300 | to pass a pointer to an instance-specific data structure in | |
301 | order for the user to keep track of the states related to this | |
302 | kernel control instance. | |
91447636 A |
303 | */ |
304 | typedef errno_t (*ctl_connect_func)(kern_ctl_ref kctlref, | |
305 | struct sockaddr_ctl *sac, | |
306 | void **unitinfo); | |
9bccf70c | 307 | |
91447636 A |
308 | /*! |
309 | @typedef ctl_disconnect_func | |
310 | @discussion The ctl_disconnect_func is used to receive notification | |
311 | that a client has disconnected from the kernel control. This | |
312 | usually happens when the socket is closed. If this is the last | |
313 | socket attached to your kernel control, you may unregister your | |
314 | kernel control from this callback. | |
315 | @param kctlref The control ref for the kernel control instance the client has | |
316 | disconnected from. | |
317 | @param unit The unit number of the kernel control instance the client has | |
318 | disconnected from. | |
2d21ac55 A |
319 | @param unitinfo The user-defined private data initialized by the |
320 | ctl_connect_func callback. | |
9bccf70c | 321 | */ |
91447636 A |
322 | typedef errno_t (*ctl_disconnect_func)(kern_ctl_ref kctlref, u_int32_t unit, void *unitinfo); |
323 | ||
324 | /*! | |
325 | @typedef ctl_send_func | |
326 | @discussion The ctl_send_func is used to receive data sent from | |
327 | the client to the kernel control. | |
328 | @param kctlref The control ref of the kernel control. | |
329 | @param unit The unit number of the kernel control instance the client has | |
330 | connected to. | |
2d21ac55 A |
331 | @param unitinfo The user-defined private data initialized by the |
332 | ctl_connect_func callback. | |
91447636 | 333 | @param m The data sent by the client to the kernel control in an |
6d2010ae | 334 | mbuf chain. Your function is responsible for releasing the |
91447636 A |
335 | mbuf chain. |
336 | @param flags The flags specified by the client when calling | |
337 | send/sendto/sendmsg (MSG_OOB/MSG_DONTROUTE). | |
338 | */ | |
339 | typedef errno_t (*ctl_send_func)(kern_ctl_ref kctlref, u_int32_t unit, void *unitinfo, | |
340 | mbuf_t m, int flags); | |
341 | ||
342 | /*! | |
343 | @typedef ctl_setopt_func | |
344 | @discussion The ctl_setopt_func is used to handle set socket option | |
345 | calls for the SYSPROTO_CONTROL option level. | |
346 | @param kctlref The control ref of the kernel control. | |
347 | @param unit The unit number of the kernel control instance. | |
2d21ac55 A |
348 | @param unitinfo The user-defined private data initialized by the |
349 | ctl_connect_func callback. | |
91447636 A |
350 | @param opt The socket option. |
351 | @param data A pointer to the socket option data. The data has | |
352 | already been copied in to the kernel for you. | |
353 | @param len The length of the socket option data. | |
354 | */ | |
355 | typedef errno_t (*ctl_setopt_func)(kern_ctl_ref kctlref, u_int32_t unit, void *unitinfo, | |
356 | int opt, void *data, size_t len); | |
357 | ||
358 | /*! | |
359 | @typedef ctl_getopt_func | |
360 | @discussion The ctl_getopt_func is used to handle client get socket | |
361 | option requests for the SYSPROTO_CONTROL option level. A buffer | |
362 | is allocated for storage and passed to your function. The length | |
363 | of that buffer is also passed. Upon return, you should set *len | |
364 | to length of the buffer used. In some cases, data may be NULL. | |
365 | When this happens, *len should be set to the length you would | |
366 | have returned had data not been NULL. If the buffer is too small, | |
367 | return an error. | |
368 | @param kctlref The control ref of the kernel control. | |
369 | @param unit The unit number of the kernel control instance. | |
2d21ac55 A |
370 | @param unitinfo The user-defined private data initialized by the |
371 | ctl_connect_func callback. | |
91447636 A |
372 | @param opt The socket option. |
373 | @param data A buffer to copy the results in to. May be NULL, see | |
374 | discussion. | |
375 | @param len A pointer to the length of the buffer. This should be set | |
376 | to the length of the buffer used before returning. | |
377 | */ | |
378 | typedef errno_t (*ctl_getopt_func)(kern_ctl_ref kctlref, u_int32_t unit, void *unitinfo, | |
379 | int opt, void *data, size_t *len); | |
380 | ||
39236c6e A |
381 | #ifdef KERNEL_PRIVATE |
382 | /*! | |
383 | @typedef ctl_rcvd_func | |
384 | @discussion The ctl_rcvd_func is called when the client reads data from | |
385 | the kernel control socket. The kernel control can use this callback | |
386 | in combination with ctl_getenqueuespace() to avoid overflowing | |
387 | the socket's receive buffer. When ctl_getenqueuespace() returns | |
388 | 0 or ctl_enqueuedata()/ctl_enqueuembuf() return ENOBUFS, the | |
389 | kernel control can wait until this callback is called before | |
390 | trying to enqueue the data again. | |
391 | @param kctlref The control ref of the kernel control. | |
392 | @param unit The unit number of the kernel control instance. | |
393 | @param unitinfo The user-defined private data initialized by the | |
394 | ctl_connect_func callback. | |
395 | @param flags The recv flags. See the recv(2) man page. | |
396 | */ | |
397 | typedef void (*ctl_rcvd_func)(kern_ctl_ref kctlref, u_int32_t unit, void *unitinfo, | |
fe8ab488 A |
398 | int flags); |
399 | ||
400 | /*! | |
401 | @typedef ctl_send_list_func | |
402 | @discussion The ctl_send_list_func is used to receive data sent from | |
403 | the client to the kernel control. | |
404 | @param kctlref The control ref of the kernel control. | |
405 | @param unit The unit number of the kernel control instance the client has | |
406 | connected to. | |
407 | @param unitinfo The user-defined private data initialized by the | |
408 | ctl_connect_func callback. | |
409 | @param m The data sent by the client to the kernel control in an | |
410 | mbuf packet chain. Your function is responsible for releasing | |
411 | mbuf packet chain. | |
412 | @param flags The flags specified by the client when calling | |
413 | send/sendto/sendmsg (MSG_OOB/MSG_DONTROUTE). | |
414 | */ | |
415 | typedef errno_t (*ctl_send_list_func)(kern_ctl_ref kctlref, u_int32_t unit, void *unitinfo, | |
416 | mbuf_t m, int flags); | |
39236c6e A |
417 | #endif /* KERNEL_PRIVATE */ |
418 | ||
91447636 A |
419 | /*! |
420 | @struct kern_ctl_reg | |
421 | @discussion This structure defines the properties of a kernel | |
422 | control being registered. | |
423 | @field ctl_name A Bundle ID string of up to MAX_KCTL_NAME bytes (including the ending zero). | |
424 | This string should not be empty. | |
425 | @field ctl_id The control ID may be dynamically assigned or it can be a | |
426 | 32-bit creator code assigned by DTS. | |
427 | For a DTS assigned creator code the CTL_FLAG_REG_ID_UNIT flag must be set. | |
428 | For a dynamically assigned control ID, do not set the CTL_FLAG_REG_ID_UNIT flag. | |
429 | The value of the dynamically assigned control ID is set to this field | |
430 | when the registration succeeds. | |
431 | @field ctl_unit A separate unit number to register multiple units that | |
432 | share the same control ID with DTS assigned creator code when | |
433 | the CTL_FLAG_REG_ID_UNIT flag is set. | |
434 | This field is ignored for a dynamically assigned control ID. | |
435 | @field ctl_flags CTL_FLAG_PRIVILEGED and/or CTL_FLAG_REG_ID_UNIT. | |
436 | @field ctl_sendsize Override the default send size. If set to zero, | |
437 | the default send size will be used, and this default value | |
438 | is set to this field to be retrieved by the caller. | |
439 | @field ctl_recvsize Override the default receive size. If set to | |
440 | zero, the default receive size will be used, and this default value | |
441 | is set to this field to be retrieved by the caller. | |
442 | @field ctl_connect Specify the function to be called whenever a client | |
443 | connects to the kernel control. This field must be specified. | |
444 | @field ctl_disconnect Specify a function to be called whenever a | |
445 | client disconnects from the kernel control. | |
446 | @field ctl_send Specify a function to handle data send from the | |
447 | client to the kernel control. | |
448 | @field ctl_setopt Specify a function to handle set socket option | |
449 | operations for the kernel control. | |
450 | @field ctl_getopt Specify a function to handle get socket option | |
451 | operations for the kernel control. | |
452 | */ | |
9bccf70c A |
453 | struct kern_ctl_reg |
454 | { | |
91447636 A |
455 | /* control information */ |
456 | char ctl_name[MAX_KCTL_NAME]; | |
457 | u_int32_t ctl_id; | |
458 | u_int32_t ctl_unit; | |
459 | ||
9bccf70c | 460 | /* control settings */ |
91447636 A |
461 | u_int32_t ctl_flags; |
462 | u_int32_t ctl_sendsize; | |
463 | u_int32_t ctl_recvsize; | |
9bccf70c A |
464 | |
465 | /* Dispatch functions */ | |
91447636 A |
466 | ctl_connect_func ctl_connect; |
467 | ctl_disconnect_func ctl_disconnect; | |
468 | ctl_send_func ctl_send; | |
469 | ctl_setopt_func ctl_setopt; | |
470 | ctl_getopt_func ctl_getopt; | |
39236c6e A |
471 | #ifdef KERNEL_PRIVATE |
472 | ctl_rcvd_func ctl_rcvd; /* Only valid if CTL_FLAG_REG_EXTENDED is set */ | |
fe8ab488 | 473 | ctl_send_list_func ctl_send_list; /* Only valid if CTL_FLAG_REG_EXTENDED is set */ |
39236c6e | 474 | #endif /* KERNEL_PRIVATE */ |
9bccf70c A |
475 | }; |
476 | ||
91447636 A |
477 | /*! |
478 | @function ctl_register | |
479 | @discussion Register a kernel control. This will enable clients to | |
480 | connect to the kernel control using a PF_SYSTEM socket. | |
481 | @param userkctl A structure defining the kernel control to be | |
482 | attached. The ctl_connect callback must be specified, the other callbacks | |
483 | are optional. If ctl_connect is set to zero, ctl_register fails with | |
484 | the error code EINVAL. | |
485 | @param kctlref Upon successful return, the kctlref will contain a | |
486 | reference to the attached kernel control. This reference is used | |
487 | to unregister the kernel control. This reference will also be | |
488 | passed in to the callbacks each time they are called. | |
489 | @result 0 - Kernel control was registered. | |
490 | EINVAL - The registration structure was not valid. | |
491 | ENOMEM - There was insufficient memory. | |
492 | EEXIST - A controller with that id/unit is already registered. | |
493 | */ | |
494 | errno_t | |
495 | ctl_register(struct kern_ctl_reg *userkctl, kern_ctl_ref *kctlref); | |
9bccf70c | 496 | |
91447636 A |
497 | /*! |
498 | @function ctl_deregister | |
499 | @discussion Unregister a kernel control. A kernel extension must | |
500 | unregister it's kernel control(s) before unloading. If a kernel | |
501 | control has clients attached, this call will fail. | |
502 | @param kctlref The control reference of the control to unregister. | |
503 | @result 0 - Kernel control was unregistered. | |
504 | EINVAL - The kernel control reference was invalid. | |
505 | EBUSY - The kernel control has clients still attached. | |
9bccf70c | 506 | */ |
91447636 A |
507 | errno_t |
508 | ctl_deregister(kern_ctl_ref kctlref); | |
9bccf70c | 509 | |
91447636 A |
510 | /*! |
511 | @function ctl_enqueuedata | |
512 | @discussion Send data from the kernel control to the client. | |
513 | @param kctlref The control reference of the kernel control. | |
514 | @param unit The unit number of the kernel control instance. | |
515 | @param data A pointer to the data to send. | |
516 | @param len The length of data to send. | |
39236c6e A |
517 | @param flags Send flags. CTL_DATA_NOWAKEUP and CTL_DATA_EOR are currently |
518 | the only supported flags. | |
91447636 A |
519 | @result 0 - Data was enqueued to be read by the client. |
520 | EINVAL - Invalid parameters. | |
521 | EMSGSIZE - The buffer is too large. | |
522 | ENOBUFS - The queue is full or there are no free mbufs. | |
9bccf70c | 523 | */ |
91447636 A |
524 | errno_t |
525 | ctl_enqueuedata(kern_ctl_ref kctlref, u_int32_t unit, void *data, size_t len, u_int32_t flags); | |
9bccf70c | 526 | |
91447636 A |
527 | /*! |
528 | @function ctl_enqueuembuf | |
529 | @discussion Send data stored in an mbuf chain from the kernel | |
530 | control to the client. The caller is responsible for freeing | |
531 | the mbuf chain if ctl_enqueuembuf returns an error. | |
532 | @param kctlref The control reference of the kernel control. | |
533 | @param unit The unit number of the kernel control instance. | |
534 | @param m An mbuf chain containing the data to send to the client. | |
39236c6e A |
535 | @param flags Send flags. CTL_DATA_NOWAKEUP and CTL_DATA_EOR are currently |
536 | the only supported flags. | |
91447636 A |
537 | @result 0 - Data was enqueued to be read by the client. |
538 | EINVAL - Invalid parameters. | |
539 | ENOBUFS - The queue is full. | |
9bccf70c | 540 | */ |
91447636 A |
541 | errno_t |
542 | ctl_enqueuembuf(kern_ctl_ref kctlref, u_int32_t unit, mbuf_t m, u_int32_t flags); | |
9bccf70c | 543 | |
fe8ab488 A |
544 | #ifdef PRIVATE |
545 | /*! | |
546 | @function ctl_enqueuembuf_list | |
547 | @discussion Send data stored in an mbuf packet chain from the kernel | |
548 | control to the client. The caller is responsible for freeing | |
549 | the mbuf chain if ctl_enqueuembuf returns an error. | |
550 | Not valid if ctl_flags contains CTL_FLAG_REG_SOCK_STREAM. | |
551 | @param kctlref The control reference of the kernel control. | |
552 | @param unit The unit number of the kernel control instance. | |
39037602 | 553 | @param m_list An mbuf chain containing the data to send to the client. |
fe8ab488 A |
554 | @param flags Send flags. CTL_DATA_NOWAKEUP is |
555 | the only supported flags. | |
556 | @param m_remain A pointer to the list of mbuf packets in the chain that | |
557 | could not be enqueued. | |
558 | @result 0 - Data was enqueued to be read by the client. | |
559 | EINVAL - Invalid parameters. | |
560 | ENOBUFS - The queue is full. | |
561 | */ | |
562 | errno_t | |
563 | ctl_enqueuembuf_list(kern_ctl_ref kctlref, u_int32_t unit, mbuf_t m_list, | |
564 | u_int32_t flags, mbuf_t *m_remain); | |
565 | ||
3e170ce0 A |
566 | /*! |
567 | @function ctl_getenqueuepacketcount | |
568 | @discussion Retrieve the number of packets in the socket | |
569 | receive buffer. | |
570 | @param kctlref The control reference of the kernel control. | |
571 | @param unit The unit number of the kernel control instance. | |
572 | @param pcnt The address where to return the current count. | |
573 | @result 0 - Success; the packet count is returned to caller. | |
574 | EINVAL - Invalid parameters. | |
575 | */ | |
576 | errno_t | |
577 | ctl_getenqueuepacketcount(kern_ctl_ref kctlref, u_int32_t unit, u_int32_t *pcnt); | |
fe8ab488 | 578 | |
3e170ce0 | 579 | #endif /* PRIVATE */ |
91447636 A |
580 | |
581 | /*! | |
582 | @function ctl_getenqueuespace | |
583 | @discussion Retrieve the amount of space currently available for data to be sent | |
584 | from the kernel control to the client. | |
585 | @param kctlref The control reference of the kernel control. | |
586 | @param unit The unit number of the kernel control instance. | |
587 | @param space The address where to return the current space available | |
2d21ac55 | 588 | @result 0 - Success; the amount of space is returned to caller. |
91447636 | 589 | EINVAL - Invalid parameters. |
9bccf70c | 590 | */ |
91447636 A |
591 | errno_t |
592 | ctl_getenqueuespace(kern_ctl_ref kctlref, u_int32_t unit, size_t *space); | |
593 | ||
fe8ab488 A |
594 | /*! |
595 | @function ctl_getenqueuereadable | |
596 | @discussion Retrieve the difference between enqueued bytes and | |
597 | low-water mark for the socket receive buffer. | |
598 | @param kctlref The control reference of the kernel control. | |
599 | @param unit The unit number of the kernel control instance. | |
39037602 | 600 | @param difference The address at which to return the current difference |
fe8ab488 A |
601 | between the low-water mark for the socket and the number of bytes |
602 | enqueued. 0 indicates that the socket is readable by the client | |
603 | (the number of bytes in the buffer is above the low-water mark). | |
604 | @result 0 - Success; the difference is returned to caller. | |
605 | EINVAL - Invalid parameters. | |
606 | */ | |
607 | errno_t | |
608 | ctl_getenqueuereadable(kern_ctl_ref kctlref, u_int32_t unit, u_int32_t *difference); | |
609 | ||
6d2010ae | 610 | #ifdef KERNEL_PRIVATE |
fe8ab488 A |
611 | |
612 | #include <sys/queue.h> | |
613 | #include <libkern/locks.h> | |
614 | ||
615 | /* | |
616 | * internal structure maintained for each register controller | |
617 | */ | |
618 | struct ctl_cb; | |
3e170ce0 | 619 | struct kctl; |
fe8ab488 | 620 | struct socket; |
3e170ce0 | 621 | struct socket_info; |
fe8ab488 | 622 | |
3e170ce0 | 623 | void kctl_fill_socketinfo(struct socket *, struct socket_info *); |
fe8ab488 | 624 | |
6d2010ae A |
625 | u_int32_t ctl_id_by_name(const char *name); |
626 | errno_t ctl_name_by_id(u_int32_t id, char *out_name, size_t maxsize); | |
627 | #endif /* KERNEL_PRIVATE */ | |
628 | ||
2d21ac55 | 629 | __END_DECLS |
9bccf70c A |
630 | #endif /* KERNEL */ |
631 | ||
91447636 | 632 | #endif /* KPI_KERN_CONTROL_H */ |
9bccf70c | 633 |