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