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