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