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