2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
31 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
35 #include <IOKit/assert.h>
36 #include <IOKit/IOLib.h>
37 #include <IOKit/IOKitKeys.h>
38 #include <IOKit/IOBufferMemoryDescriptor.h>
39 #include "RootDomainUserClient.h"
40 #include <IOKit/pwr_mgt/IOPMLibDefs.h>
42 #define super IOUserClient
44 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
46 OSDefineMetaClassAndStructors(RootDomainUserClient
, IOUserClient
)
48 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
50 bool RootDomainUserClient::initWithTask(task_t owningTask
, void *security_id
,
51 UInt32 type
, OSDictionary
* properties
)
54 properties
->setObject(kIOUserClientCrossEndianCompatibleKey
, kOSBooleanTrue
);
56 if (!super::initWithTask(owningTask
, security_id
, type
, properties
))
59 fOwningTask
= owningTask
;
60 task_reference (fOwningTask
);
65 bool RootDomainUserClient::start( IOService
* provider
)
67 assert(OSDynamicCast(IOPMrootDomain
, provider
));
68 if(!super::start(provider
))
70 fOwner
= (IOPMrootDomain
*)provider
;
76 IOReturn
RootDomainUserClient::secureSleepSystem( int *return_code
)
80 IOReturn ret
= kIOReturnNotPrivileged
;
82 ret
= clientHasPrivilege(fOwningTask
, kIOClientPrivilegeLocalUser
);
83 local_priv
= (kIOReturnSuccess
== ret
);
85 ret
= clientHasPrivilege(fOwningTask
, kIOClientPrivilegeAdministrator
);
86 admin_priv
= (kIOReturnSuccess
== ret
);
88 if((local_priv
|| admin_priv
) && fOwner
) {
89 *return_code
= fOwner
->sleepSystem();
90 return kIOReturnSuccess
;
92 *return_code
= kIOReturnNotPrivileged
;
93 return kIOReturnSuccess
;
98 IOReturn
RootDomainUserClient::secureSetAggressiveness(
100 unsigned long newLevel
,
105 IOReturn ret
= kIOReturnNotPrivileged
;
107 ret
= clientHasPrivilege(fOwningTask
, kIOClientPrivilegeLocalUser
);
108 local_priv
= (kIOReturnSuccess
== ret
);
110 ret
= clientHasPrivilege(fOwningTask
, kIOClientPrivilegeAdministrator
);
111 admin_priv
= (kIOReturnSuccess
== ret
);
113 if((local_priv
|| admin_priv
) && fOwner
) {
114 *return_code
= fOwner
->setAggressiveness(type
, newLevel
);
115 return kIOReturnSuccess
;
117 *return_code
= kIOReturnNotPrivileged
;
118 return kIOReturnSuccess
;
124 IOReturn
RootDomainUserClient::clientClose( void )
129 task_deallocate(fOwningTask
);
133 return kIOReturnSuccess
;
137 RootDomainUserClient::getTargetAndMethodForIndex( IOService
** targetP
, UInt32 index
)
139 static IOExternalMethod sMethods
[] = {
140 { // kPMSetAggressiveness, 0
141 (IOService
*)1, (IOMethod
)&RootDomainUserClient::secureSetAggressiveness
, kIOUCScalarIScalarO
, 2, 1
143 { // kPMGetAggressiveness, 1
144 0, (IOMethod
)&IOPMrootDomain::getAggressiveness
, kIOUCScalarIScalarO
, 1, 1
146 { // kPMSleepSystem, 2
147 (IOService
*)1, (IOMethod
)&RootDomainUserClient::secureSleepSystem
, kIOUCScalarIScalarO
, 0, 1
149 { // kPMAllowPowerChange, 3
150 0, (IOMethod
)&IOPMrootDomain::allowPowerChange
, kIOUCScalarIScalarO
, 1, 0
152 { // kPMCancelPowerChange, 4
153 0, (IOMethod
)&IOPMrootDomain::cancelPowerChange
, kIOUCScalarIScalarO
, 1, 0
155 { // kPMShutdownSystem, 5
156 0, (IOMethod
)&IOPMrootDomain::shutdownSystem
, kIOUCScalarIScalarO
, 0, 0
158 { // kPMRestartSystem, 6
159 0, (IOMethod
)&IOPMrootDomain::restartSystem
, kIOUCScalarIScalarO
, 0, 0
161 { // kPMSetPreventative, 7
162 (IOService
*)1, (IOMethod
)&RootDomainUserClient::setPreventative
, kIOUCScalarIScalarO
, 2, 0
166 if(index
>= kNumPMMethods
)
169 if (sMethods
[index
].object
)
174 return &sMethods
[index
];
179 RootDomainUserClient::setPreventative(UInt32 on_off
, UInt32 types_of_sleep
)