2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
33 #include <IOKit/assert.h>
34 #include <IOKit/IOLib.h>
35 #include <IOKit/IOBufferMemoryDescriptor.h>
36 #include "RootDomainUserClient.h"
37 #include <IOKit/pwr_mgt/IOPMLibDefs.h>
39 #define super IOUserClient
41 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
43 OSDefineMetaClassAndStructors(RootDomainUserClient
, IOUserClient
)
45 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
47 bool RootDomainUserClient::initWithTask(task_t owningTask
, void *security_id
, UInt32
)
52 fOwningTask
= owningTask
;
53 task_reference (fOwningTask
);
58 bool RootDomainUserClient::start( IOService
* provider
)
60 assert(OSDynamicCast(IOPMrootDomain
, provider
));
61 if(!super::start(provider
))
63 fOwner
= (IOPMrootDomain
*)provider
;
69 IOReturn
RootDomainUserClient::secureSleepSystem( int *return_code
)
73 IOReturn ret
= kIOReturnNotPrivileged
;
75 ret
= clientHasPrivilege(fOwningTask
, kIOClientPrivilegeLocalUser
);
76 local_priv
= (kIOReturnSuccess
== ret
);
78 ret
= clientHasPrivilege(fOwningTask
, kIOClientPrivilegeAdministrator
);
79 admin_priv
= (kIOReturnSuccess
== ret
);
81 if((local_priv
|| admin_priv
) && fOwner
) {
82 *return_code
= fOwner
->sleepSystem();
83 return kIOReturnSuccess
;
85 *return_code
= kIOReturnNotPrivileged
;
86 return kIOReturnSuccess
;
91 IOReturn
RootDomainUserClient::secureSetAggressiveness(
93 unsigned long newLevel
,
98 IOReturn ret
= kIOReturnNotPrivileged
;
100 ret
= clientHasPrivilege(fOwningTask
, kIOClientPrivilegeLocalUser
);
101 local_priv
= (kIOReturnSuccess
== ret
);
103 ret
= clientHasPrivilege(fOwningTask
, kIOClientPrivilegeAdministrator
);
104 admin_priv
= (kIOReturnSuccess
== ret
);
106 if((local_priv
|| admin_priv
) && fOwner
) {
107 *return_code
= fOwner
->setAggressiveness(type
, newLevel
);
108 return kIOReturnSuccess
;
110 *return_code
= kIOReturnNotPrivileged
;
111 return kIOReturnSuccess
;
117 IOReturn
RootDomainUserClient::clientClose( void )
122 task_deallocate(fOwningTask
);
126 return kIOReturnSuccess
;
130 RootDomainUserClient::getTargetAndMethodForIndex( IOService
** targetP
, UInt32 index
)
132 static IOExternalMethod sMethods
[] = {
133 { // kPMSetAggressiveness, 0
134 1, (IOMethod
)&RootDomainUserClient::secureSetAggressiveness
, kIOUCScalarIScalarO
, 2, 1
136 { // kPMGetAggressiveness, 1
137 0, (IOMethod
)&IOPMrootDomain::getAggressiveness
, kIOUCScalarIScalarO
, 1, 1
139 { // kPMSleepSystem, 2
140 1, (IOMethod
)&RootDomainUserClient::secureSleepSystem
, kIOUCScalarIScalarO
, 0, 1
142 { // kPMAllowPowerChange, 3
143 0, (IOMethod
)&IOPMrootDomain::allowPowerChange
, kIOUCScalarIScalarO
, 1, 0
145 { // kPMCancelPowerChange, 4
146 0, (IOMethod
)&IOPMrootDomain::cancelPowerChange
, kIOUCScalarIScalarO
, 1, 0
148 { // kPMShutdownSystem, 5
149 0, (IOMethod
)&IOPMrootDomain::shutdownSystem
, kIOUCScalarIScalarO
, 0, 0
151 { // kPMRestartSystem, 6
152 0, (IOMethod
)&IOPMrootDomain::restartSystem
, kIOUCScalarIScalarO
, 0, 0
154 { // kPMSetPreventative, 7
155 1, (IOMethod
) &RootDomainUserClient::setPreventative
, kIOUCScalarIScalarO
, 2, 0
159 if(index
>= kNumPMMethods
)
162 if (sMethods
[index
].object
)
167 return &sMethods
[index
];
172 RootDomainUserClient::setPreventative(UInt32 on_off
, UInt32 types_of_sleep
)