1*1b191cb5SApple OSS Distributions /*
2*1b191cb5SApple OSS Distributions * Copyright (c) 1998-2020 Apple Computer, Inc. All rights reserved.
3*1b191cb5SApple OSS Distributions *
4*1b191cb5SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*1b191cb5SApple OSS Distributions *
6*1b191cb5SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code
7*1b191cb5SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License
8*1b191cb5SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in
9*1b191cb5SApple OSS Distributions * compliance with the License. The rights granted to you under the License
10*1b191cb5SApple OSS Distributions * may not be used to create, or enable the creation or redistribution of,
11*1b191cb5SApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to
12*1b191cb5SApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any
13*1b191cb5SApple OSS Distributions * terms of an Apple operating system software license agreement.
14*1b191cb5SApple OSS Distributions *
15*1b191cb5SApple OSS Distributions * Please obtain a copy of the License at
16*1b191cb5SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*1b191cb5SApple OSS Distributions *
18*1b191cb5SApple OSS Distributions * The Original Code and all software distributed under the License are
19*1b191cb5SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*1b191cb5SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*1b191cb5SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*1b191cb5SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*1b191cb5SApple OSS Distributions * Please see the License for the specific language governing rights and
24*1b191cb5SApple OSS Distributions * limitations under the License.
25*1b191cb5SApple OSS Distributions *
26*1b191cb5SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*1b191cb5SApple OSS Distributions */
28*1b191cb5SApple OSS Distributions /*
29*1b191cb5SApple OSS Distributions * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
30*1b191cb5SApple OSS Distributions *
31*1b191cb5SApple OSS Distributions */
32*1b191cb5SApple OSS Distributions
33*1b191cb5SApple OSS Distributions #include <IOKit/assert.h>
34*1b191cb5SApple OSS Distributions #include <IOKit/IOLib.h>
35*1b191cb5SApple OSS Distributions #include <IOKit/IOKitKeys.h>
36*1b191cb5SApple OSS Distributions #include <IOKit/IOBufferMemoryDescriptor.h>
37*1b191cb5SApple OSS Distributions #include "RootDomainUserClient.h"
38*1b191cb5SApple OSS Distributions #include <IOKit/pwr_mgt/IOPMLibDefs.h>
39*1b191cb5SApple OSS Distributions #include <IOKit/pwr_mgt/IOPMPrivate.h>
40*1b191cb5SApple OSS Distributions #include <sys/proc.h>
41*1b191cb5SApple OSS Distributions
42*1b191cb5SApple OSS Distributions #define super IOUserClient2022
43*1b191cb5SApple OSS Distributions
44*1b191cb5SApple OSS Distributions /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
45*1b191cb5SApple OSS Distributions
OSDefineMetaClassAndStructors(RootDomainUserClient,IOUserClient2022)46*1b191cb5SApple OSS Distributions OSDefineMetaClassAndStructors(RootDomainUserClient, IOUserClient2022)
47*1b191cb5SApple OSS Distributions
48*1b191cb5SApple OSS Distributions /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
49*1b191cb5SApple OSS Distributions
50*1b191cb5SApple OSS Distributions bool
51*1b191cb5SApple OSS Distributions RootDomainUserClient::initWithTask(task_t owningTask, void *security_id,
52*1b191cb5SApple OSS Distributions UInt32 type, OSDictionary * properties)
53*1b191cb5SApple OSS Distributions {
54*1b191cb5SApple OSS Distributions if (properties) {
55*1b191cb5SApple OSS Distributions properties->setObject(kIOUserClientCrossEndianCompatibleKey, kOSBooleanTrue);
56*1b191cb5SApple OSS Distributions }
57*1b191cb5SApple OSS Distributions
58*1b191cb5SApple OSS Distributions if (!super::initWithTask(owningTask, security_id, type, properties)) {
59*1b191cb5SApple OSS Distributions return false;
60*1b191cb5SApple OSS Distributions }
61*1b191cb5SApple OSS Distributions
62*1b191cb5SApple OSS Distributions fOwningTask = owningTask;
63*1b191cb5SApple OSS Distributions task_reference(fOwningTask);
64*1b191cb5SApple OSS Distributions return true;
65*1b191cb5SApple OSS Distributions }
66*1b191cb5SApple OSS Distributions
67*1b191cb5SApple OSS Distributions
68*1b191cb5SApple OSS Distributions bool
start(IOService * provider)69*1b191cb5SApple OSS Distributions RootDomainUserClient::start( IOService * provider )
70*1b191cb5SApple OSS Distributions {
71*1b191cb5SApple OSS Distributions assert(OSDynamicCast(IOPMrootDomain, provider));
72*1b191cb5SApple OSS Distributions if (!super::start(provider)) {
73*1b191cb5SApple OSS Distributions return false;
74*1b191cb5SApple OSS Distributions }
75*1b191cb5SApple OSS Distributions fOwner = (IOPMrootDomain *)provider;
76*1b191cb5SApple OSS Distributions
77*1b191cb5SApple OSS Distributions setProperty(kIOUserClientDefaultLockingKey, kOSBooleanTrue);
78*1b191cb5SApple OSS Distributions setProperty(kIOUserClientDefaultLockingSetPropertiesKey, kOSBooleanTrue);
79*1b191cb5SApple OSS Distributions setProperty(kIOUserClientDefaultLockingSingleThreadExternalMethodKey, kOSBooleanFalse);
80*1b191cb5SApple OSS Distributions
81*1b191cb5SApple OSS Distributions setProperty(kIOUserClientEntitlementsKey, kOSBooleanFalse);
82*1b191cb5SApple OSS Distributions
83*1b191cb5SApple OSS Distributions return true;
84*1b191cb5SApple OSS Distributions }
85*1b191cb5SApple OSS Distributions
86*1b191cb5SApple OSS Distributions IOReturn
secureSleepSystem(uint32_t * return_code)87*1b191cb5SApple OSS Distributions RootDomainUserClient::secureSleepSystem( uint32_t *return_code )
88*1b191cb5SApple OSS Distributions {
89*1b191cb5SApple OSS Distributions return secureSleepSystemOptions(NULL, 0, return_code);
90*1b191cb5SApple OSS Distributions }
91*1b191cb5SApple OSS Distributions
92*1b191cb5SApple OSS Distributions IOReturn
secureSleepSystemOptions(const void * inOptions,IOByteCount inOptionsSize,uint32_t * returnCode)93*1b191cb5SApple OSS Distributions RootDomainUserClient::secureSleepSystemOptions(
94*1b191cb5SApple OSS Distributions const void *inOptions,
95*1b191cb5SApple OSS Distributions IOByteCount inOptionsSize,
96*1b191cb5SApple OSS Distributions uint32_t *returnCode)
97*1b191cb5SApple OSS Distributions {
98*1b191cb5SApple OSS Distributions int local_priv = 0;
99*1b191cb5SApple OSS Distributions int admin_priv = 0;
100*1b191cb5SApple OSS Distributions IOReturn ret = kIOReturnNotPrivileged;
101*1b191cb5SApple OSS Distributions
102*1b191cb5SApple OSS Distributions ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeLocalUser);
103*1b191cb5SApple OSS Distributions local_priv = (kIOReturnSuccess == ret);
104*1b191cb5SApple OSS Distributions
105*1b191cb5SApple OSS Distributions ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeAdministrator);
106*1b191cb5SApple OSS Distributions admin_priv = (kIOReturnSuccess == ret);
107*1b191cb5SApple OSS Distributions
108*1b191cb5SApple OSS Distributions if ((local_priv || admin_priv) && fOwner) {
109*1b191cb5SApple OSS Distributions OSString *unserializeErrorString = NULL;
110*1b191cb5SApple OSS Distributions OSObject *unserializedObject = NULL;
111*1b191cb5SApple OSS Distributions OSDictionary *sleepOptionsDict = NULL; // do not release
112*1b191cb5SApple OSS Distributions
113*1b191cb5SApple OSS Distributions proc_t p;
114*1b191cb5SApple OSS Distributions p = (proc_t)get_bsdtask_info(fOwningTask);
115*1b191cb5SApple OSS Distributions if (p) {
116*1b191cb5SApple OSS Distributions fOwner->setProperty("SleepRequestedByPID", proc_pid(p), 32);
117*1b191cb5SApple OSS Distributions }
118*1b191cb5SApple OSS Distributions
119*1b191cb5SApple OSS Distributions if (inOptions) {
120*1b191cb5SApple OSS Distributions unserializedObject = OSUnserializeXML((const char *)inOptions, inOptionsSize, &unserializeErrorString);
121*1b191cb5SApple OSS Distributions sleepOptionsDict = OSDynamicCast( OSDictionary, unserializedObject);
122*1b191cb5SApple OSS Distributions if (!sleepOptionsDict) {
123*1b191cb5SApple OSS Distributions IOLog("IOPMRootDomain SleepSystem unserialization failure: %s\n",
124*1b191cb5SApple OSS Distributions unserializeErrorString ? unserializeErrorString->getCStringNoCopy() : "Unknown");
125*1b191cb5SApple OSS Distributions }
126*1b191cb5SApple OSS Distributions }
127*1b191cb5SApple OSS Distributions
128*1b191cb5SApple OSS Distributions if (sleepOptionsDict) {
129*1b191cb5SApple OSS Distributions // Publish Sleep Options in registry under root_domain
130*1b191cb5SApple OSS Distributions fOwner->setProperty( kRootDomainSleepOptionsKey, sleepOptionsDict);
131*1b191cb5SApple OSS Distributions } else {
132*1b191cb5SApple OSS Distributions // No options
133*1b191cb5SApple OSS Distributions // Clear any pre-existing options
134*1b191cb5SApple OSS Distributions fOwner->removeProperty( kRootDomainSleepOptionsKey );
135*1b191cb5SApple OSS Distributions }
136*1b191cb5SApple OSS Distributions
137*1b191cb5SApple OSS Distributions *returnCode = fOwner->sleepSystemOptions( sleepOptionsDict );
138*1b191cb5SApple OSS Distributions OSSafeReleaseNULL(unserializedObject);
139*1b191cb5SApple OSS Distributions OSSafeReleaseNULL(unserializeErrorString);
140*1b191cb5SApple OSS Distributions } else {
141*1b191cb5SApple OSS Distributions *returnCode = kIOReturnNotPrivileged;
142*1b191cb5SApple OSS Distributions }
143*1b191cb5SApple OSS Distributions
144*1b191cb5SApple OSS Distributions return kIOReturnSuccess;
145*1b191cb5SApple OSS Distributions }
146*1b191cb5SApple OSS Distributions
147*1b191cb5SApple OSS Distributions IOReturn
secureSetAggressiveness(unsigned long type,unsigned long newLevel,int * return_code)148*1b191cb5SApple OSS Distributions RootDomainUserClient::secureSetAggressiveness(
149*1b191cb5SApple OSS Distributions unsigned long type,
150*1b191cb5SApple OSS Distributions unsigned long newLevel,
151*1b191cb5SApple OSS Distributions int *return_code )
152*1b191cb5SApple OSS Distributions {
153*1b191cb5SApple OSS Distributions int local_priv = 0;
154*1b191cb5SApple OSS Distributions int admin_priv = 0;
155*1b191cb5SApple OSS Distributions IOReturn ret = kIOReturnNotPrivileged;
156*1b191cb5SApple OSS Distributions
157*1b191cb5SApple OSS Distributions ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeLocalUser);
158*1b191cb5SApple OSS Distributions local_priv = (kIOReturnSuccess == ret);
159*1b191cb5SApple OSS Distributions
160*1b191cb5SApple OSS Distributions ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeAdministrator);
161*1b191cb5SApple OSS Distributions admin_priv = (kIOReturnSuccess == ret);
162*1b191cb5SApple OSS Distributions
163*1b191cb5SApple OSS Distributions if ((local_priv || admin_priv) && fOwner) {
164*1b191cb5SApple OSS Distributions *return_code = fOwner->setAggressiveness(type, newLevel);
165*1b191cb5SApple OSS Distributions } else {
166*1b191cb5SApple OSS Distributions *return_code = kIOReturnNotPrivileged;
167*1b191cb5SApple OSS Distributions }
168*1b191cb5SApple OSS Distributions return kIOReturnSuccess;
169*1b191cb5SApple OSS Distributions }
170*1b191cb5SApple OSS Distributions
171*1b191cb5SApple OSS Distributions IOReturn
secureSetMaintenanceWakeCalendar(IOPMCalendarStruct * inCalendar,uint32_t * returnCode)172*1b191cb5SApple OSS Distributions RootDomainUserClient::secureSetMaintenanceWakeCalendar(
173*1b191cb5SApple OSS Distributions IOPMCalendarStruct *inCalendar,
174*1b191cb5SApple OSS Distributions uint32_t *returnCode)
175*1b191cb5SApple OSS Distributions {
176*1b191cb5SApple OSS Distributions int admin_priv = 0;
177*1b191cb5SApple OSS Distributions IOReturn ret = kIOReturnNotPrivileged;
178*1b191cb5SApple OSS Distributions
179*1b191cb5SApple OSS Distributions ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeAdministrator);
180*1b191cb5SApple OSS Distributions admin_priv = (kIOReturnSuccess == ret);
181*1b191cb5SApple OSS Distributions
182*1b191cb5SApple OSS Distributions if (admin_priv && fOwner) {
183*1b191cb5SApple OSS Distributions *returnCode = fOwner->setMaintenanceWakeCalendar(inCalendar);
184*1b191cb5SApple OSS Distributions } else {
185*1b191cb5SApple OSS Distributions *returnCode = kIOReturnNotPrivileged;
186*1b191cb5SApple OSS Distributions }
187*1b191cb5SApple OSS Distributions return kIOReturnSuccess;
188*1b191cb5SApple OSS Distributions }
189*1b191cb5SApple OSS Distributions
190*1b191cb5SApple OSS Distributions IOReturn
secureSetUserAssertionLevels(uint32_t assertionBitfield)191*1b191cb5SApple OSS Distributions RootDomainUserClient::secureSetUserAssertionLevels(
192*1b191cb5SApple OSS Distributions uint32_t assertionBitfield)
193*1b191cb5SApple OSS Distributions {
194*1b191cb5SApple OSS Distributions int admin_priv = 0;
195*1b191cb5SApple OSS Distributions IOReturn ret = kIOReturnNotPrivileged;
196*1b191cb5SApple OSS Distributions
197*1b191cb5SApple OSS Distributions ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeAdministrator);
198*1b191cb5SApple OSS Distributions admin_priv = (kIOReturnSuccess == ret);
199*1b191cb5SApple OSS Distributions
200*1b191cb5SApple OSS Distributions if (admin_priv && fOwner) {
201*1b191cb5SApple OSS Distributions ret = fOwner->setPMAssertionUserLevels(assertionBitfield);
202*1b191cb5SApple OSS Distributions } else {
203*1b191cb5SApple OSS Distributions ret = kIOReturnNotPrivileged;
204*1b191cb5SApple OSS Distributions }
205*1b191cb5SApple OSS Distributions return kIOReturnSuccess;
206*1b191cb5SApple OSS Distributions }
207*1b191cb5SApple OSS Distributions
208*1b191cb5SApple OSS Distributions IOReturn
secureGetSystemSleepType(uint32_t * outSleepType,uint32_t * sleepTimer)209*1b191cb5SApple OSS Distributions RootDomainUserClient::secureGetSystemSleepType(
210*1b191cb5SApple OSS Distributions uint32_t *outSleepType, uint32_t *sleepTimer)
211*1b191cb5SApple OSS Distributions {
212*1b191cb5SApple OSS Distributions int admin_priv = 0;
213*1b191cb5SApple OSS Distributions IOReturn ret;
214*1b191cb5SApple OSS Distributions
215*1b191cb5SApple OSS Distributions ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeAdministrator);
216*1b191cb5SApple OSS Distributions admin_priv = (kIOReturnSuccess == ret);
217*1b191cb5SApple OSS Distributions
218*1b191cb5SApple OSS Distributions if (admin_priv && fOwner) {
219*1b191cb5SApple OSS Distributions ret = fOwner->getSystemSleepType(outSleepType, sleepTimer);
220*1b191cb5SApple OSS Distributions } else {
221*1b191cb5SApple OSS Distributions ret = kIOReturnNotPrivileged;
222*1b191cb5SApple OSS Distributions }
223*1b191cb5SApple OSS Distributions return ret;
224*1b191cb5SApple OSS Distributions }
225*1b191cb5SApple OSS Distributions
226*1b191cb5SApple OSS Distributions IOReturn
clientClose(void)227*1b191cb5SApple OSS Distributions RootDomainUserClient::clientClose( void )
228*1b191cb5SApple OSS Distributions {
229*1b191cb5SApple OSS Distributions terminate();
230*1b191cb5SApple OSS Distributions
231*1b191cb5SApple OSS Distributions return kIOReturnSuccess;
232*1b191cb5SApple OSS Distributions }
233*1b191cb5SApple OSS Distributions
234*1b191cb5SApple OSS Distributions void
stop(IOService * provider)235*1b191cb5SApple OSS Distributions RootDomainUserClient::stop( IOService *provider)
236*1b191cb5SApple OSS Distributions {
237*1b191cb5SApple OSS Distributions if (fOwningTask) {
238*1b191cb5SApple OSS Distributions task_deallocate(fOwningTask);
239*1b191cb5SApple OSS Distributions fOwningTask = NULL;
240*1b191cb5SApple OSS Distributions }
241*1b191cb5SApple OSS Distributions
242*1b191cb5SApple OSS Distributions super::stop(provider);
243*1b191cb5SApple OSS Distributions }
244*1b191cb5SApple OSS Distributions
245*1b191cb5SApple OSS Distributions IOReturn
externalMethod(uint32_t selector,IOExternalMethodArgumentsOpaque * args)246*1b191cb5SApple OSS Distributions RootDomainUserClient::externalMethod(uint32_t selector, IOExternalMethodArgumentsOpaque * args )
247*1b191cb5SApple OSS Distributions {
248*1b191cb5SApple OSS Distributions static const IOExternalMethodDispatch2022 dispatchArray[] = {
249*1b191cb5SApple OSS Distributions [kPMSetAggressiveness] = {
250*1b191cb5SApple OSS Distributions .function = &RootDomainUserClient::externalMethodDispatched,
251*1b191cb5SApple OSS Distributions .checkScalarInputCount = 2,
252*1b191cb5SApple OSS Distributions .checkStructureInputSize = 0,
253*1b191cb5SApple OSS Distributions .checkScalarOutputCount = 1,
254*1b191cb5SApple OSS Distributions .checkStructureOutputSize = 0,
255*1b191cb5SApple OSS Distributions .allowAsync = false,
256*1b191cb5SApple OSS Distributions .checkEntitlement = NULL,
257*1b191cb5SApple OSS Distributions },
258*1b191cb5SApple OSS Distributions [kPMGetAggressiveness] = {
259*1b191cb5SApple OSS Distributions .function = &RootDomainUserClient::externalMethodDispatched,
260*1b191cb5SApple OSS Distributions .checkScalarInputCount = 1,
261*1b191cb5SApple OSS Distributions .checkStructureInputSize = 0,
262*1b191cb5SApple OSS Distributions .checkScalarOutputCount = 1,
263*1b191cb5SApple OSS Distributions .checkStructureOutputSize = 0,
264*1b191cb5SApple OSS Distributions .allowAsync = false,
265*1b191cb5SApple OSS Distributions .checkEntitlement = NULL,
266*1b191cb5SApple OSS Distributions },
267*1b191cb5SApple OSS Distributions [kPMSleepSystem] = {
268*1b191cb5SApple OSS Distributions .function = &RootDomainUserClient::externalMethodDispatched,
269*1b191cb5SApple OSS Distributions .checkScalarInputCount = 0,
270*1b191cb5SApple OSS Distributions .checkStructureInputSize = 0,
271*1b191cb5SApple OSS Distributions .checkScalarOutputCount = 1,
272*1b191cb5SApple OSS Distributions .checkStructureOutputSize = 0,
273*1b191cb5SApple OSS Distributions .allowAsync = false,
274*1b191cb5SApple OSS Distributions .checkEntitlement = NULL,
275*1b191cb5SApple OSS Distributions },
276*1b191cb5SApple OSS Distributions [kPMAllowPowerChange] = {
277*1b191cb5SApple OSS Distributions .function = &RootDomainUserClient::externalMethodDispatched,
278*1b191cb5SApple OSS Distributions .checkScalarInputCount = 1,
279*1b191cb5SApple OSS Distributions .checkStructureInputSize = 0,
280*1b191cb5SApple OSS Distributions .checkScalarOutputCount = 0,
281*1b191cb5SApple OSS Distributions .checkStructureOutputSize = 0,
282*1b191cb5SApple OSS Distributions .allowAsync = false,
283*1b191cb5SApple OSS Distributions .checkEntitlement = NULL,
284*1b191cb5SApple OSS Distributions },
285*1b191cb5SApple OSS Distributions [kPMCancelPowerChange] = {
286*1b191cb5SApple OSS Distributions .function = &RootDomainUserClient::externalMethodDispatched,
287*1b191cb5SApple OSS Distributions .checkScalarInputCount = 1,
288*1b191cb5SApple OSS Distributions .checkStructureInputSize = 0,
289*1b191cb5SApple OSS Distributions .checkScalarOutputCount = 0,
290*1b191cb5SApple OSS Distributions .checkStructureOutputSize = 0,
291*1b191cb5SApple OSS Distributions .allowAsync = false,
292*1b191cb5SApple OSS Distributions .checkEntitlement = NULL,
293*1b191cb5SApple OSS Distributions },
294*1b191cb5SApple OSS Distributions [kPMShutdownSystem] = {
295*1b191cb5SApple OSS Distributions .function = &RootDomainUserClient::externalMethodDispatched,
296*1b191cb5SApple OSS Distributions .checkScalarInputCount = 0,
297*1b191cb5SApple OSS Distributions .checkStructureInputSize = 0,
298*1b191cb5SApple OSS Distributions .checkScalarOutputCount = 0,
299*1b191cb5SApple OSS Distributions .checkStructureOutputSize = 0,
300*1b191cb5SApple OSS Distributions .allowAsync = false,
301*1b191cb5SApple OSS Distributions .checkEntitlement = NULL,
302*1b191cb5SApple OSS Distributions },
303*1b191cb5SApple OSS Distributions [kPMRestartSystem] = {
304*1b191cb5SApple OSS Distributions .function = &RootDomainUserClient::externalMethodDispatched,
305*1b191cb5SApple OSS Distributions .checkScalarInputCount = 0,
306*1b191cb5SApple OSS Distributions .checkStructureInputSize = 0,
307*1b191cb5SApple OSS Distributions .checkScalarOutputCount = 0,
308*1b191cb5SApple OSS Distributions .checkStructureOutputSize = 0,
309*1b191cb5SApple OSS Distributions .allowAsync = false,
310*1b191cb5SApple OSS Distributions .checkEntitlement = NULL,
311*1b191cb5SApple OSS Distributions },
312*1b191cb5SApple OSS Distributions [kPMSleepSystemOptions] = {
313*1b191cb5SApple OSS Distributions .function = &RootDomainUserClient::externalMethodDispatched,
314*1b191cb5SApple OSS Distributions .checkScalarInputCount = 0,
315*1b191cb5SApple OSS Distributions .checkStructureInputSize = kIOUCVariableStructureSize,
316*1b191cb5SApple OSS Distributions .checkScalarOutputCount = 0,
317*1b191cb5SApple OSS Distributions .checkStructureOutputSize = sizeof(uint32_t),
318*1b191cb5SApple OSS Distributions .allowAsync = false,
319*1b191cb5SApple OSS Distributions .checkEntitlement = NULL,
320*1b191cb5SApple OSS Distributions },
321*1b191cb5SApple OSS Distributions [kPMSetMaintenanceWakeCalendar] = {
322*1b191cb5SApple OSS Distributions .function = &RootDomainUserClient::externalMethodDispatched,
323*1b191cb5SApple OSS Distributions .checkScalarInputCount = 0,
324*1b191cb5SApple OSS Distributions .checkStructureInputSize = sizeof(IOPMCalendarStruct),
325*1b191cb5SApple OSS Distributions .checkScalarOutputCount = 0,
326*1b191cb5SApple OSS Distributions .checkStructureOutputSize = sizeof(uint32_t),
327*1b191cb5SApple OSS Distributions .allowAsync = false,
328*1b191cb5SApple OSS Distributions .checkEntitlement = NULL,
329*1b191cb5SApple OSS Distributions },
330*1b191cb5SApple OSS Distributions [kPMSetUserAssertionLevels] = {
331*1b191cb5SApple OSS Distributions .function = &RootDomainUserClient::externalMethodDispatched,
332*1b191cb5SApple OSS Distributions .checkScalarInputCount = 1,
333*1b191cb5SApple OSS Distributions .checkStructureInputSize = 0,
334*1b191cb5SApple OSS Distributions .checkScalarOutputCount = 0,
335*1b191cb5SApple OSS Distributions .checkStructureOutputSize = 0,
336*1b191cb5SApple OSS Distributions .allowAsync = false,
337*1b191cb5SApple OSS Distributions .checkEntitlement = NULL,
338*1b191cb5SApple OSS Distributions },
339*1b191cb5SApple OSS Distributions [kPMActivityTickle] = {
340*1b191cb5SApple OSS Distributions .function = &RootDomainUserClient::externalMethodDispatched,
341*1b191cb5SApple OSS Distributions .checkScalarInputCount = 0,
342*1b191cb5SApple OSS Distributions .checkStructureInputSize = 0,
343*1b191cb5SApple OSS Distributions .checkScalarOutputCount = 0,
344*1b191cb5SApple OSS Distributions .checkStructureOutputSize = 0,
345*1b191cb5SApple OSS Distributions .allowAsync = false,
346*1b191cb5SApple OSS Distributions .checkEntitlement = NULL,
347*1b191cb5SApple OSS Distributions },
348*1b191cb5SApple OSS Distributions [kPMSetClamshellSleepState] = {
349*1b191cb5SApple OSS Distributions .function = &RootDomainUserClient::externalMethodDispatched,
350*1b191cb5SApple OSS Distributions .checkScalarInputCount = 1,
351*1b191cb5SApple OSS Distributions .checkStructureInputSize = 0,
352*1b191cb5SApple OSS Distributions .checkScalarOutputCount = 0,
353*1b191cb5SApple OSS Distributions .checkStructureOutputSize = 0,
354*1b191cb5SApple OSS Distributions .allowAsync = false,
355*1b191cb5SApple OSS Distributions .checkEntitlement = NULL,
356*1b191cb5SApple OSS Distributions },
357*1b191cb5SApple OSS Distributions [kPMGetSystemSleepType] = {
358*1b191cb5SApple OSS Distributions .function = &RootDomainUserClient::externalMethodDispatched,
359*1b191cb5SApple OSS Distributions .checkScalarInputCount = 0,
360*1b191cb5SApple OSS Distributions .checkStructureInputSize = 0,
361*1b191cb5SApple OSS Distributions .checkScalarOutputCount = 2,
362*1b191cb5SApple OSS Distributions .checkStructureOutputSize = 0,
363*1b191cb5SApple OSS Distributions .allowAsync = false,
364*1b191cb5SApple OSS Distributions .checkEntitlement = NULL,
365*1b191cb5SApple OSS Distributions },
366*1b191cb5SApple OSS Distributions [kPMSleepWakeWatchdogEnable] = {
367*1b191cb5SApple OSS Distributions .function = &RootDomainUserClient::externalMethodDispatched,
368*1b191cb5SApple OSS Distributions .checkScalarInputCount = 0,
369*1b191cb5SApple OSS Distributions .checkStructureInputSize = 0,
370*1b191cb5SApple OSS Distributions .checkScalarOutputCount = 0,
371*1b191cb5SApple OSS Distributions .checkStructureOutputSize = 0,
372*1b191cb5SApple OSS Distributions .allowAsync = false,
373*1b191cb5SApple OSS Distributions .checkEntitlement = NULL,
374*1b191cb5SApple OSS Distributions },
375*1b191cb5SApple OSS Distributions [kPMSleepWakeDebugTrig] = {
376*1b191cb5SApple OSS Distributions .function = &RootDomainUserClient::externalMethodDispatched,
377*1b191cb5SApple OSS Distributions .checkScalarInputCount = 0,
378*1b191cb5SApple OSS Distributions .checkStructureInputSize = 0,
379*1b191cb5SApple OSS Distributions .checkScalarOutputCount = 0,
380*1b191cb5SApple OSS Distributions .checkStructureOutputSize = 0,
381*1b191cb5SApple OSS Distributions .allowAsync = false,
382*1b191cb5SApple OSS Distributions .checkEntitlement = NULL,
383*1b191cb5SApple OSS Distributions },
384*1b191cb5SApple OSS Distributions [kPMSetDisplayPowerOn] = {
385*1b191cb5SApple OSS Distributions .function = &RootDomainUserClient::externalMethodDispatched,
386*1b191cb5SApple OSS Distributions .checkScalarInputCount = 1,
387*1b191cb5SApple OSS Distributions .checkStructureInputSize = 0,
388*1b191cb5SApple OSS Distributions .checkScalarOutputCount = 0,
389*1b191cb5SApple OSS Distributions .checkStructureOutputSize = 0,
390*1b191cb5SApple OSS Distributions .allowAsync = false,
391*1b191cb5SApple OSS Distributions .checkEntitlement = NULL,
392*1b191cb5SApple OSS Distributions },
393*1b191cb5SApple OSS Distributions };
394*1b191cb5SApple OSS Distributions
395*1b191cb5SApple OSS Distributions return dispatchExternalMethod(selector, args, dispatchArray, sizeof(dispatchArray) / sizeof(dispatchArray[0]), this, NULL);
396*1b191cb5SApple OSS Distributions }
397*1b191cb5SApple OSS Distributions IOReturn
externalMethodDispatched(OSObject * target,void * reference,IOExternalMethodArguments * arguments)398*1b191cb5SApple OSS Distributions RootDomainUserClient::externalMethodDispatched(OSObject * target, void * reference, IOExternalMethodArguments * arguments)
399*1b191cb5SApple OSS Distributions {
400*1b191cb5SApple OSS Distributions IOReturn ret = kIOReturnBadArgument;
401*1b191cb5SApple OSS Distributions RootDomainUserClient * me = (typeof(me))target;
402*1b191cb5SApple OSS Distributions switch (arguments->selector) {
403*1b191cb5SApple OSS Distributions case kPMSetAggressiveness:
404*1b191cb5SApple OSS Distributions ret = me->secureSetAggressiveness(
405*1b191cb5SApple OSS Distributions (unsigned long)arguments->scalarInput[0],
406*1b191cb5SApple OSS Distributions (unsigned long)arguments->scalarInput[1],
407*1b191cb5SApple OSS Distributions (int *)&arguments->scalarOutput[0]);
408*1b191cb5SApple OSS Distributions break;
409*1b191cb5SApple OSS Distributions
410*1b191cb5SApple OSS Distributions case kPMGetAggressiveness:
411*1b191cb5SApple OSS Distributions ret = me->fOwner->getAggressiveness(
412*1b191cb5SApple OSS Distributions (unsigned long)arguments->scalarInput[0],
413*1b191cb5SApple OSS Distributions (unsigned long *)&arguments->scalarOutput[0]);
414*1b191cb5SApple OSS Distributions break;
415*1b191cb5SApple OSS Distributions
416*1b191cb5SApple OSS Distributions case kPMSleepSystem:
417*1b191cb5SApple OSS Distributions ret = me->secureSleepSystem(
418*1b191cb5SApple OSS Distributions (uint32_t *)&arguments->scalarOutput[0]);
419*1b191cb5SApple OSS Distributions break;
420*1b191cb5SApple OSS Distributions
421*1b191cb5SApple OSS Distributions case kPMAllowPowerChange:
422*1b191cb5SApple OSS Distributions ret = me->fOwner->allowPowerChange(
423*1b191cb5SApple OSS Distributions arguments->scalarInput[0]);
424*1b191cb5SApple OSS Distributions break;
425*1b191cb5SApple OSS Distributions
426*1b191cb5SApple OSS Distributions case kPMCancelPowerChange:
427*1b191cb5SApple OSS Distributions ret = me->fOwner->cancelPowerChange(
428*1b191cb5SApple OSS Distributions arguments->scalarInput[0]);
429*1b191cb5SApple OSS Distributions break;
430*1b191cb5SApple OSS Distributions
431*1b191cb5SApple OSS Distributions case kPMShutdownSystem:
432*1b191cb5SApple OSS Distributions // deprecated interface
433*1b191cb5SApple OSS Distributions ret = kIOReturnUnsupported;
434*1b191cb5SApple OSS Distributions break;
435*1b191cb5SApple OSS Distributions
436*1b191cb5SApple OSS Distributions case kPMRestartSystem:
437*1b191cb5SApple OSS Distributions // deprecated interface
438*1b191cb5SApple OSS Distributions ret = kIOReturnUnsupported;
439*1b191cb5SApple OSS Distributions break;
440*1b191cb5SApple OSS Distributions
441*1b191cb5SApple OSS Distributions case kPMSleepSystemOptions:
442*1b191cb5SApple OSS Distributions ret = me->secureSleepSystemOptions(
443*1b191cb5SApple OSS Distributions arguments->structureInput,
444*1b191cb5SApple OSS Distributions arguments->structureInputSize,
445*1b191cb5SApple OSS Distributions (uint32_t *)&arguments->structureOutput);
446*1b191cb5SApple OSS Distributions break;
447*1b191cb5SApple OSS Distributions case kPMSetMaintenanceWakeCalendar:
448*1b191cb5SApple OSS Distributions ret = me->secureSetMaintenanceWakeCalendar(
449*1b191cb5SApple OSS Distributions (IOPMCalendarStruct *)arguments->structureInput,
450*1b191cb5SApple OSS Distributions (uint32_t *)&arguments->structureOutput);
451*1b191cb5SApple OSS Distributions arguments->structureOutputSize = sizeof(uint32_t);
452*1b191cb5SApple OSS Distributions break;
453*1b191cb5SApple OSS Distributions
454*1b191cb5SApple OSS Distributions case kPMSetUserAssertionLevels:
455*1b191cb5SApple OSS Distributions ret = me->secureSetUserAssertionLevels(
456*1b191cb5SApple OSS Distributions (uint32_t)arguments->scalarInput[0]);
457*1b191cb5SApple OSS Distributions break;
458*1b191cb5SApple OSS Distributions
459*1b191cb5SApple OSS Distributions case kPMActivityTickle:
460*1b191cb5SApple OSS Distributions if (me->fOwner->checkSystemCanSustainFullWake()) {
461*1b191cb5SApple OSS Distributions me->fOwner->reportUserInput();
462*1b191cb5SApple OSS Distributions me->fOwner->setProperty(kIOPMRootDomainWakeTypeKey, "UserActivity Assertion");
463*1b191cb5SApple OSS Distributions }
464*1b191cb5SApple OSS Distributions ret = kIOReturnSuccess;
465*1b191cb5SApple OSS Distributions break;
466*1b191cb5SApple OSS Distributions
467*1b191cb5SApple OSS Distributions case kPMSetClamshellSleepState:
468*1b191cb5SApple OSS Distributions me->fOwner->setClamShellSleepDisable(arguments->scalarInput[0] ? true : false,
469*1b191cb5SApple OSS Distributions IOPMrootDomain::kClamshellSleepDisablePowerd);
470*1b191cb5SApple OSS Distributions ret = kIOReturnSuccess;
471*1b191cb5SApple OSS Distributions break;
472*1b191cb5SApple OSS Distributions
473*1b191cb5SApple OSS Distributions case kPMGetSystemSleepType:
474*1b191cb5SApple OSS Distributions ret = me->secureGetSystemSleepType(
475*1b191cb5SApple OSS Distributions (uint32_t *) &arguments->scalarOutput[0],
476*1b191cb5SApple OSS Distributions (uint32_t *) &arguments->scalarOutput[1]);
477*1b191cb5SApple OSS Distributions break;
478*1b191cb5SApple OSS Distributions
479*1b191cb5SApple OSS Distributions #if defined(__i386__) || defined(__x86_64__)
480*1b191cb5SApple OSS Distributions case kPMSleepWakeWatchdogEnable:
481*1b191cb5SApple OSS Distributions ret = clientHasPrivilege(me->fOwningTask, kIOClientPrivilegeAdministrator);
482*1b191cb5SApple OSS Distributions if (ret == kIOReturnSuccess) {
483*1b191cb5SApple OSS Distributions me->fOwner->sleepWakeDebugEnableWdog();
484*1b191cb5SApple OSS Distributions }
485*1b191cb5SApple OSS Distributions break;
486*1b191cb5SApple OSS Distributions
487*1b191cb5SApple OSS Distributions
488*1b191cb5SApple OSS Distributions case kPMSleepWakeDebugTrig:
489*1b191cb5SApple OSS Distributions ret = clientHasPrivilege(me->fOwningTask, kIOClientPrivilegeAdministrator);
490*1b191cb5SApple OSS Distributions if (ret == kIOReturnSuccess) {
491*1b191cb5SApple OSS Distributions me->fOwner->sleepWakeDebugTrig(false);
492*1b191cb5SApple OSS Distributions }
493*1b191cb5SApple OSS Distributions break;
494*1b191cb5SApple OSS Distributions #endif
495*1b191cb5SApple OSS Distributions
496*1b191cb5SApple OSS Distributions case kPMSetDisplayPowerOn:
497*1b191cb5SApple OSS Distributions ret = clientHasPrivilege(me->fOwningTask, kIOClientPrivilegeAdministrator);
498*1b191cb5SApple OSS Distributions if (ret == kIOReturnSuccess) {
499*1b191cb5SApple OSS Distributions me->fOwner->setDisplayPowerOn((uint32_t)arguments->scalarInput[0]);
500*1b191cb5SApple OSS Distributions }
501*1b191cb5SApple OSS Distributions break;
502*1b191cb5SApple OSS Distributions
503*1b191cb5SApple OSS Distributions default:
504*1b191cb5SApple OSS Distributions // bad selector
505*1b191cb5SApple OSS Distributions return kIOReturnBadArgument;
506*1b191cb5SApple OSS Distributions }
507*1b191cb5SApple OSS Distributions
508*1b191cb5SApple OSS Distributions return ret;
509*1b191cb5SApple OSS Distributions }
510*1b191cb5SApple OSS Distributions
511*1b191cb5SApple OSS Distributions /* getTargetAndMethodForIndex
512*1b191cb5SApple OSS Distributions * Not used. We prefer to use externalMethod() for user client invocations.
513*1b191cb5SApple OSS Distributions * We maintain getTargetAndExternalMethod since it's an exported symbol,
514*1b191cb5SApple OSS Distributions * and only for that reason.
515*1b191cb5SApple OSS Distributions */
516*1b191cb5SApple OSS Distributions IOExternalMethod *
getTargetAndMethodForIndex(IOService ** targetP,UInt32 index)517*1b191cb5SApple OSS Distributions RootDomainUserClient::getTargetAndMethodForIndex(
518*1b191cb5SApple OSS Distributions IOService ** targetP, UInt32 index )
519*1b191cb5SApple OSS Distributions {
520*1b191cb5SApple OSS Distributions // DO NOT EDIT
521*1b191cb5SApple OSS Distributions return super::getTargetAndMethodForIndex(targetP, index);
522*1b191cb5SApple OSS Distributions }
523*1b191cb5SApple OSS Distributions
524*1b191cb5SApple OSS Distributions /* setPreventative
525*1b191cb5SApple OSS Distributions * Does nothing. Exists only for exported symbol compatibility.
526*1b191cb5SApple OSS Distributions */
527*1b191cb5SApple OSS Distributions void
setPreventative(UInt32 on_off,UInt32 types_of_sleep)528*1b191cb5SApple OSS Distributions RootDomainUserClient::setPreventative(UInt32 on_off, UInt32 types_of_sleep)
529*1b191cb5SApple OSS Distributions {
530*1b191cb5SApple OSS Distributions return;
531*1b191cb5SApple OSS Distributions } // DO NOT EDIT
532