]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2000-2004, 2012-2014 Apple Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ | |
5 | * | |
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. | |
14 | * | |
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 | |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
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. | |
25 | * | |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
27 | */ | |
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 | */ | |
33 | ||
34 | #ifndef KPI_KERN_CONTROL_H | |
35 | #define KPI_KERN_CONTROL_H | |
36 | ||
37 | ||
38 | #include <sys/appleapiopts.h> | |
39 | ||
40 | /* | |
41 | * Define Controller event subclass, and associated events. | |
42 | * Subclass of KEV_SYSTEM_CLASS | |
43 | */ | |
44 | ||
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 */ | |
57 | ||
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 */ | |
64 | ||
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 | */ | |
72 | struct ctl_event_data { | |
73 | u_int32_t ctl_id; /* Kernel Controller ID */ | |
74 | u_int32_t ctl_unit; | |
75 | }; | |
76 | ||
77 | /* | |
78 | * Controls destined to the Controller Manager. | |
79 | */ | |
80 | ||
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 | |
102 | ||
103 | /* | |
104 | * Controls destined to the Controller Manager. | |
105 | */ | |
106 | ||
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 { | |
138 | u_char sc_len; /* depends on size of bundle ID string */ | |
139 | u_char sc_family; /* AF_SYSTEM */ | |
140 | u_int16_t ss_sysaddr; /* AF_SYS_KERNCONTROL */ | |
141 | u_int32_t sc_id; /* Controller unique identifier */ | |
142 | u_int32_t sc_unit; /* Developer private unit number */ | |
143 | u_int32_t sc_reserved[5]; | |
144 | }; | |
145 | ||
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))); | |
190 | ||
191 | }; | |
192 | ||
193 | #endif /* PRIVATE */ | |
194 | ||
195 | #ifdef KERNEL | |
196 | ||
197 | #include <sys/kpi_mbuf.h> | |
198 | ||
199 | /*! | |
200 | @typedef kern_ctl_ref | |
201 | @discussion A control reference is used to track an attached kernel | |
202 | control. Registering a kernel control will create a kernel | |
203 | control reference. This reference is required for sending data | |
204 | or removing the kernel control. This reference will be passed to | |
205 | callbacks for that kernel control. | |
206 | */ | |
207 | typedef void * kern_ctl_ref; | |
208 | ||
209 | /*! | |
210 | @defined CTL_FLAG_PRIVILEGED | |
211 | @discussion The CTL_FLAG_PRIVILEGED flag is passed in ctl_flags. If | |
212 | this flag is set, only privileged processes may attach to this | |
213 | kernel control. | |
214 | */ | |
215 | #define CTL_FLAG_PRIVILEGED 0x1 | |
216 | /*! | |
217 | @defined CTL_FLAG_REG_ID_UNIT | |
218 | @discussion The CTL_FLAG_REG_ID_UNIT flag is passed to indicate that | |
219 | the ctl_id specified should be used. If this flag is not | |
220 | present, a unique ctl_id will be dynamically assigned to your | |
221 | kernel control. The CTLIOCGINFO ioctl can be used by the client | |
222 | to find the dynamically assigned id based on the control name | |
223 | specified in ctl_name. | |
224 | */ | |
225 | #define CTL_FLAG_REG_ID_UNIT 0x2 | |
226 | /*! | |
227 | @defined CTL_FLAG_REG_SOCK_STREAM | |
228 | @discussion Use the CTL_FLAG_REG_SOCK_STREAM flag when client need to open | |
229 | socket of type SOCK_STREAM to communicate with the kernel control. | |
230 | By default kernel control sockets are of type SOCK_DGRAM. | |
231 | */ | |
232 | #define CTL_FLAG_REG_SOCK_STREAM 0x4 | |
233 | ||
234 | #ifdef KERNEL_PRIVATE | |
235 | /*! | |
236 | @defined CTL_FLAG_REG_EXTENDED | |
237 | @discussion This flag indicates that this kernel control utilizes the | |
238 | the extended fields within the kern_ctl_reg structure. | |
239 | */ | |
240 | #define CTL_FLAG_REG_EXTENDED 0x8 | |
241 | ||
242 | /*! | |
243 | @defined CTL_FLAG_REG_CRIT | |
244 | @discussion This flag indicates that this kernel control utilizes the | |
245 | the extended fields within the kern_ctl_reg structure. | |
246 | */ | |
247 | #define CTL_FLAG_REG_CRIT 0x10 | |
248 | #endif /* KERNEL_PRIVATE */ | |
249 | ||
250 | /* Data flags for controllers */ | |
251 | /*! | |
252 | @defined CTL_DATA_NOWAKEUP | |
253 | @discussion The CTL_DATA_NOWAKEUP flag can be used for the enqueue | |
254 | data and enqueue mbuf functions to indicate that the process | |
255 | should not be woken up yet. This is useful when you want to | |
256 | enqueue data using more than one call but only want to wake up | |
257 | the client after all of the data has been enqueued. | |
258 | */ | |
259 | #define CTL_DATA_NOWAKEUP 0x1 | |
260 | ||
261 | /*! | |
262 | @defined CTL_DATA_EOR | |
263 | @discussion The CTL_DATA_EOR flag can be used for the enqueue | |
264 | data and enqueue mbuf functions to mark the end of a record. | |
265 | */ | |
266 | #define CTL_DATA_EOR 0x2 | |
267 | ||
268 | #ifdef KERNEL_PRIVATE | |
269 | /*! | |
270 | @defined CTL_DATA_CRIT | |
271 | @discussion This flag indicates the data is critical to the client | |
272 | and that it needs to be forced into the socket buffer | |
273 | by resizing it if needed. | |
274 | */ | |
275 | #define CTL_DATA_CRIT 0x4 | |
276 | #endif /* KERNEL_PRIVATE */ | |
277 | ||
278 | __BEGIN_DECLS | |
279 | ||
280 | /*! | |
281 | @typedef ctl_connect_func | |
282 | @discussion The ctl_connect_func is used to receive | |
283 | notification of a client connecting to the kernel control. | |
284 | @param kctlref The control ref for the kernel control the client is | |
285 | connecting to. | |
286 | @param sac The address used to connect to this control. The field sc_unit | |
287 | contains the unit number of the kernel control instance the client is | |
288 | connecting to. If CTL_FLAG_REG_ID_UNIT was set when the kernel control | |
289 | was registered, sc_unit is the ctl_unit of the kern_ctl_reg structure. | |
290 | If CTL_FLAG_REG_ID_UNIT was not set when the kernel control was | |
291 | registered, sc_unit is the dynamically allocated unit number of | |
292 | the new kernel control instance that is used for this connection. | |
293 | @param unitinfo A placeholder for a pointer to the optional user-defined | |
294 | private data associated with this kernel control instance. This | |
295 | opaque info will be provided to the user when the rest of the | |
296 | callback routines are executed. For example, it can be used | |
297 | to pass a pointer to an instance-specific data structure in | |
298 | order for the user to keep track of the states related to this | |
299 | kernel control instance. | |
300 | */ | |
301 | typedef errno_t (*ctl_connect_func)(kern_ctl_ref kctlref, | |
302 | struct sockaddr_ctl *sac, | |
303 | void **unitinfo); | |
304 | ||
305 | /*! | |
306 | @typedef ctl_disconnect_func | |
307 | @discussion The ctl_disconnect_func is used to receive notification | |
308 | that a client has disconnected from the kernel control. This | |
309 | usually happens when the socket is closed. If this is the last | |
310 | socket attached to your kernel control, you may unregister your | |
311 | kernel control from this callback. | |
312 | @param kctlref The control ref for the kernel control instance the client has | |
313 | disconnected from. | |
314 | @param unit The unit number of the kernel control instance the client has | |
315 | disconnected from. | |
316 | @param unitinfo The user-defined private data initialized by the | |
317 | ctl_connect_func callback. | |
318 | */ | |
319 | typedef errno_t (*ctl_disconnect_func)(kern_ctl_ref kctlref, u_int32_t unit, void *unitinfo); | |
320 | ||
321 | /*! | |
322 | @typedef ctl_send_func | |
323 | @discussion The ctl_send_func is used to receive data sent from | |
324 | the client to the kernel control. | |
325 | @param kctlref The control ref of the kernel control. | |
326 | @param unit The unit number of the kernel control instance the client has | |
327 | connected to. | |
328 | @param unitinfo The user-defined private data initialized by the | |
329 | ctl_connect_func callback. | |
330 | @param m The data sent by the client to the kernel control in an | |
331 | mbuf chain. Your function is responsible for releasing the | |
332 | mbuf chain. | |
333 | @param flags The flags specified by the client when calling | |
334 | send/sendto/sendmsg (MSG_OOB/MSG_DONTROUTE). | |
335 | */ | |
336 | typedef errno_t (*ctl_send_func)(kern_ctl_ref kctlref, u_int32_t unit, void *unitinfo, | |
337 | mbuf_t m, int flags); | |
338 | ||
339 | /*! | |
340 | @typedef ctl_setopt_func | |
341 | @discussion The ctl_setopt_func is used to handle set socket option | |
342 | calls for the SYSPROTO_CONTROL option level. | |
343 | @param kctlref The control ref of the kernel control. | |
344 | @param unit The unit number of the kernel control instance. | |
345 | @param unitinfo The user-defined private data initialized by the | |
346 | ctl_connect_func callback. | |
347 | @param opt The socket option. | |
348 | @param data A pointer to the socket option data. The data has | |
349 | already been copied in to the kernel for you. | |
350 | @param len The length of the socket option data. | |
351 | */ | |
352 | typedef errno_t (*ctl_setopt_func)(kern_ctl_ref kctlref, u_int32_t unit, void *unitinfo, | |
353 | int opt, void *data, size_t len); | |
354 | ||
355 | /*! | |
356 | @typedef ctl_getopt_func | |
357 | @discussion The ctl_getopt_func is used to handle client get socket | |
358 | option requests for the SYSPROTO_CONTROL option level. A buffer | |
359 | is allocated for storage and passed to your function. The length | |
360 | of that buffer is also passed. Upon return, you should set *len | |
361 | to length of the buffer used. In some cases, data may be NULL. | |
362 | When this happens, *len should be set to the length you would | |
363 | have returned had data not been NULL. If the buffer is too small, | |
364 | return an error. | |
365 | @param kctlref The control ref of the kernel control. | |
366 | @param unit The unit number of the kernel control instance. | |
367 | @param unitinfo The user-defined private data initialized by the | |
368 | ctl_connect_func callback. | |
369 | @param opt The socket option. | |
370 | @param data A buffer to copy the results in to. May be NULL, see | |
371 | discussion. | |
372 | @param len A pointer to the length of the buffer. This should be set | |
373 | to the length of the buffer used before returning. | |
374 | */ | |
375 | typedef errno_t (*ctl_getopt_func)(kern_ctl_ref kctlref, u_int32_t unit, void *unitinfo, | |
376 | int opt, void *data, size_t *len); | |
377 | ||
378 | #ifdef KERNEL_PRIVATE | |
379 | /*! | |
380 | @typedef ctl_rcvd_func | |
381 | @discussion The ctl_rcvd_func is called when the client reads data from | |
382 | the kernel control socket. The kernel control can use this callback | |
383 | in combination with ctl_getenqueuespace() to avoid overflowing | |
384 | the socket's receive buffer. When ctl_getenqueuespace() returns | |
385 | 0 or ctl_enqueuedata()/ctl_enqueuembuf() return ENOBUFS, the | |
386 | kernel control can wait until this callback is called before | |
387 | trying to enqueue the data again. | |
388 | @param kctlref The control ref of the kernel control. | |
389 | @param unit The unit number of the kernel control instance. | |
390 | @param unitinfo The user-defined private data initialized by the | |
391 | ctl_connect_func callback. | |
392 | @param flags The recv flags. See the recv(2) man page. | |
393 | */ | |
394 | typedef void (*ctl_rcvd_func)(kern_ctl_ref kctlref, u_int32_t unit, void *unitinfo, | |
395 | int flags); | |
396 | ||
397 | /*! | |
398 | @typedef ctl_send_list_func | |
399 | @discussion The ctl_send_list_func is used to receive data sent from | |
400 | the client to the kernel control. | |
401 | @param kctlref The control ref of the kernel control. | |
402 | @param unit The unit number of the kernel control instance the client has | |
403 | connected to. | |
404 | @param unitinfo The user-defined private data initialized by the | |
405 | ctl_connect_func callback. | |
406 | @param m The data sent by the client to the kernel control in an | |
407 | mbuf packet chain. Your function is responsible for releasing | |
408 | mbuf packet chain. | |
409 | @param flags The flags specified by the client when calling | |
410 | send/sendto/sendmsg (MSG_OOB/MSG_DONTROUTE). | |
411 | */ | |
412 | typedef errno_t (*ctl_send_list_func)(kern_ctl_ref kctlref, u_int32_t unit, void *unitinfo, | |
413 | mbuf_t m, int flags); | |
414 | #endif /* KERNEL_PRIVATE */ | |
415 | ||
416 | /*! | |
417 | @struct kern_ctl_reg | |
418 | @discussion This structure defines the properties of a kernel | |
419 | control being registered. | |
420 | @field ctl_name A Bundle ID string of up to MAX_KCTL_NAME bytes (including the ending zero). | |
421 | This string should not be empty. | |
422 | @field ctl_id The control ID may be dynamically assigned or it can be a | |
423 | 32-bit creator code assigned by DTS. | |
424 | For a DTS assigned creator code the CTL_FLAG_REG_ID_UNIT flag must be set. | |
425 | For a dynamically assigned control ID, do not set the CTL_FLAG_REG_ID_UNIT flag. | |
426 | The value of the dynamically assigned control ID is set to this field | |
427 | when the registration succeeds. | |
428 | @field ctl_unit A separate unit number to register multiple units that | |
429 | share the same control ID with DTS assigned creator code when | |
430 | the CTL_FLAG_REG_ID_UNIT flag is set. | |
431 | This field is ignored for a dynamically assigned control ID. | |
432 | @field ctl_flags CTL_FLAG_PRIVILEGED and/or CTL_FLAG_REG_ID_UNIT. | |
433 | @field ctl_sendsize Override the default send size. If set to zero, | |
434 | the default send size will be used, and this default value | |
435 | is set to this field to be retrieved by the caller. | |
436 | @field ctl_recvsize Override the default receive size. If set to | |
437 | zero, the default receive size will be used, and this default value | |
438 | is set to this field to be retrieved by the caller. | |
439 | @field ctl_connect Specify the function to be called whenever a client | |
440 | connects to the kernel control. This field must be specified. | |
441 | @field ctl_disconnect Specify a function to be called whenever a | |
442 | client disconnects from the kernel control. | |
443 | @field ctl_send Specify a function to handle data send from the | |
444 | client to the kernel control. | |
445 | @field ctl_setopt Specify a function to handle set socket option | |
446 | operations for the kernel control. | |
447 | @field ctl_getopt Specify a function to handle get socket option | |
448 | operations for the kernel control. | |
449 | */ | |
450 | struct kern_ctl_reg | |
451 | { | |
452 | /* control information */ | |
453 | char ctl_name[MAX_KCTL_NAME]; | |
454 | u_int32_t ctl_id; | |
455 | u_int32_t ctl_unit; | |
456 | ||
457 | /* control settings */ | |
458 | u_int32_t ctl_flags; | |
459 | u_int32_t ctl_sendsize; | |
460 | u_int32_t ctl_recvsize; | |
461 | ||
462 | /* Dispatch functions */ | |
463 | ctl_connect_func ctl_connect; | |
464 | ctl_disconnect_func ctl_disconnect; | |
465 | ctl_send_func ctl_send; | |
466 | ctl_setopt_func ctl_setopt; | |
467 | ctl_getopt_func ctl_getopt; | |
468 | #ifdef KERNEL_PRIVATE | |
469 | ctl_rcvd_func ctl_rcvd; /* Only valid if CTL_FLAG_REG_EXTENDED is set */ | |
470 | ctl_send_list_func ctl_send_list; /* Only valid if CTL_FLAG_REG_EXTENDED is set */ | |
471 | #endif /* KERNEL_PRIVATE */ | |
472 | }; | |
473 | ||
474 | /*! | |
475 | @function ctl_register | |
476 | @discussion Register a kernel control. This will enable clients to | |
477 | connect to the kernel control using a PF_SYSTEM socket. | |
478 | @param userkctl A structure defining the kernel control to be | |
479 | attached. The ctl_connect callback must be specified, the other callbacks | |
480 | are optional. If ctl_connect is set to zero, ctl_register fails with | |
481 | the error code EINVAL. | |
482 | @param kctlref Upon successful return, the kctlref will contain a | |
483 | reference to the attached kernel control. This reference is used | |
484 | to unregister the kernel control. This reference will also be | |
485 | passed in to the callbacks each time they are called. | |
486 | @result 0 - Kernel control was registered. | |
487 | EINVAL - The registration structure was not valid. | |
488 | ENOMEM - There was insufficient memory. | |
489 | EEXIST - A controller with that id/unit is already registered. | |
490 | */ | |
491 | errno_t | |
492 | ctl_register(struct kern_ctl_reg *userkctl, kern_ctl_ref *kctlref); | |
493 | ||
494 | /*! | |
495 | @function ctl_deregister | |
496 | @discussion Unregister a kernel control. A kernel extension must | |
497 | unregister it's kernel control(s) before unloading. If a kernel | |
498 | control has clients attached, this call will fail. | |
499 | @param kctlref The control reference of the control to unregister. | |
500 | @result 0 - Kernel control was unregistered. | |
501 | EINVAL - The kernel control reference was invalid. | |
502 | EBUSY - The kernel control has clients still attached. | |
503 | */ | |
504 | errno_t | |
505 | ctl_deregister(kern_ctl_ref kctlref); | |
506 | ||
507 | /*! | |
508 | @function ctl_enqueuedata | |
509 | @discussion Send data from the kernel control to the client. | |
510 | @param kctlref The control reference of the kernel control. | |
511 | @param unit The unit number of the kernel control instance. | |
512 | @param data A pointer to the data to send. | |
513 | @param len The length of data to send. | |
514 | @param flags Send flags. CTL_DATA_NOWAKEUP and CTL_DATA_EOR are currently | |
515 | the only supported flags. | |
516 | @result 0 - Data was enqueued to be read by the client. | |
517 | EINVAL - Invalid parameters. | |
518 | EMSGSIZE - The buffer is too large. | |
519 | ENOBUFS - The queue is full or there are no free mbufs. | |
520 | */ | |
521 | errno_t | |
522 | ctl_enqueuedata(kern_ctl_ref kctlref, u_int32_t unit, void *data, size_t len, u_int32_t flags); | |
523 | ||
524 | /*! | |
525 | @function ctl_enqueuembuf | |
526 | @discussion Send data stored in an mbuf chain from the kernel | |
527 | control to the client. The caller is responsible for freeing | |
528 | the mbuf chain if ctl_enqueuembuf returns an error. | |
529 | @param kctlref The control reference of the kernel control. | |
530 | @param unit The unit number of the kernel control instance. | |
531 | @param m An mbuf chain containing the data to send to the client. | |
532 | @param flags Send flags. CTL_DATA_NOWAKEUP and CTL_DATA_EOR are currently | |
533 | the only supported flags. | |
534 | @result 0 - Data was enqueued to be read by the client. | |
535 | EINVAL - Invalid parameters. | |
536 | ENOBUFS - The queue is full. | |
537 | */ | |
538 | errno_t | |
539 | ctl_enqueuembuf(kern_ctl_ref kctlref, u_int32_t unit, mbuf_t m, u_int32_t flags); | |
540 | ||
541 | #ifdef PRIVATE | |
542 | /*! | |
543 | @function ctl_enqueuembuf_list | |
544 | @discussion Send data stored in an mbuf packet chain from the kernel | |
545 | control to the client. The caller is responsible for freeing | |
546 | the mbuf chain if ctl_enqueuembuf returns an error. | |
547 | Not valid if ctl_flags contains CTL_FLAG_REG_SOCK_STREAM. | |
548 | @param kctlref The control reference of the kernel control. | |
549 | @param unit The unit number of the kernel control instance. | |
550 | @param m An mbuf chain containing the data to send to the client. | |
551 | @param flags Send flags. CTL_DATA_NOWAKEUP is | |
552 | the only supported flags. | |
553 | @param m_remain A pointer to the list of mbuf packets in the chain that | |
554 | could not be enqueued. | |
555 | @result 0 - Data was enqueued to be read by the client. | |
556 | EINVAL - Invalid parameters. | |
557 | ENOBUFS - The queue is full. | |
558 | */ | |
559 | errno_t | |
560 | ctl_enqueuembuf_list(kern_ctl_ref kctlref, u_int32_t unit, mbuf_t m_list, | |
561 | u_int32_t flags, mbuf_t *m_remain); | |
562 | ||
563 | ||
564 | #endif | |
565 | ||
566 | /*! | |
567 | @function ctl_getenqueuespace | |
568 | @discussion Retrieve the amount of space currently available for data to be sent | |
569 | from the kernel control to the client. | |
570 | @param kctlref The control reference of the kernel control. | |
571 | @param unit The unit number of the kernel control instance. | |
572 | @param space The address where to return the current space available | |
573 | @result 0 - Success; the amount of space is returned to caller. | |
574 | EINVAL - Invalid parameters. | |
575 | */ | |
576 | errno_t | |
577 | ctl_getenqueuespace(kern_ctl_ref kctlref, u_int32_t unit, size_t *space); | |
578 | ||
579 | /*! | |
580 | @function ctl_getenqueuereadable | |
581 | @discussion Retrieve the difference between enqueued bytes and | |
582 | low-water mark for the socket receive buffer. | |
583 | @param kctlref The control reference of the kernel control. | |
584 | @param unit The unit number of the kernel control instance. | |
585 | @param u_int32_t The address at which to return the current difference | |
586 | between the low-water mark for the socket and the number of bytes | |
587 | enqueued. 0 indicates that the socket is readable by the client | |
588 | (the number of bytes in the buffer is above the low-water mark). | |
589 | @result 0 - Success; the difference is returned to caller. | |
590 | EINVAL - Invalid parameters. | |
591 | */ | |
592 | errno_t | |
593 | ctl_getenqueuereadable(kern_ctl_ref kctlref, u_int32_t unit, u_int32_t *difference); | |
594 | ||
595 | #ifdef KERNEL_PRIVATE | |
596 | ||
597 | #include <sys/queue.h> | |
598 | #include <libkern/locks.h> | |
599 | ||
600 | /* | |
601 | * internal structure maintained for each register controller | |
602 | */ | |
603 | struct ctl_cb; | |
604 | struct socket; | |
605 | ||
606 | struct kctl { | |
607 | TAILQ_ENTRY(kctl) next; /* controller chain */ | |
608 | ||
609 | /* controller information provided when registering */ | |
610 | char name[MAX_KCTL_NAME]; /* unique nke identifier, provided by DTS */ | |
611 | u_int32_t id; | |
612 | u_int32_t reg_unit; | |
613 | ||
614 | /* misc communication information */ | |
615 | u_int32_t flags; /* support flags */ | |
616 | u_int32_t recvbufsize; /* request more than the default buffer size */ | |
617 | u_int32_t sendbufsize; /* request more than the default buffer size */ | |
618 | ||
619 | /* Dispatch functions */ | |
620 | ctl_connect_func connect; /* Make contact */ | |
621 | ctl_disconnect_func disconnect; /* Break contact */ | |
622 | ctl_send_func send; /* Send data to nke */ | |
623 | ctl_send_list_func send_list; /* Send list of packets */ | |
624 | ctl_setopt_func setopt; /* set kctl configuration */ | |
625 | ctl_getopt_func getopt; /* get kctl configuration */ | |
626 | ctl_rcvd_func rcvd; /* Notify nke when client reads data */ | |
627 | ||
628 | TAILQ_HEAD(, ctl_cb) kcb_head; | |
629 | u_int32_t lastunit; | |
630 | }; | |
631 | ||
632 | struct ctl_cb { | |
633 | TAILQ_ENTRY(ctl_cb) next; /* controller chain */ | |
634 | lck_mtx_t *mtx; | |
635 | struct socket *so; /* controlling socket */ | |
636 | struct kctl *kctl; /* back pointer to controller */ | |
637 | void *userdata; | |
638 | u_int32_t unit; | |
639 | u_int32_t usecount; | |
640 | }; | |
641 | ||
642 | u_int32_t ctl_id_by_name(const char *name); | |
643 | errno_t ctl_name_by_id(u_int32_t id, char *out_name, size_t maxsize); | |
644 | #endif /* KERNEL_PRIVATE */ | |
645 | ||
646 | __END_DECLS | |
647 | #endif /* KERNEL */ | |
648 | ||
649 | #endif /* KPI_KERN_CONTROL_H */ | |
650 |