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/IOBufferMemoryDescriptor.h>
38 #include "RootDomainUserClient.h"
39 #include <IOKit/pwr_mgt/IOPMLibDefs.h>
41 #define super IOUserClient
43 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
45 OSDefineMetaClassAndStructors(RootDomainUserClient
, IOUserClient
)
47 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
49 bool RootDomainUserClient::initWithTask(task_t owningTask
, void *security_id
, UInt32
)
54 fOwningTask
= owningTask
;
55 task_reference (fOwningTask
);
60 bool RootDomainUserClient::start( IOService
* provider
)
62 assert(OSDynamicCast(IOPMrootDomain
, provider
));
63 if(!super::start(provider
))
65 fOwner
= (IOPMrootDomain
*)provider
;
71 IOReturn
RootDomainUserClient::secureSleepSystem( int *return_code
)
75 IOReturn ret
= kIOReturnNotPrivileged
;
77 ret
= clientHasPrivilege(fOwningTask
, kIOClientPrivilegeLocalUser
);
78 local_priv
= (kIOReturnSuccess
== ret
);
80 ret
= clientHasPrivilege(fOwningTask
, kIOClientPrivilegeAdministrator
);
81 admin_priv
= (kIOReturnSuccess
== ret
);
83 if((local_priv
|| admin_priv
) && fOwner
) {
84 *return_code
= fOwner
->sleepSystem();
85 return kIOReturnSuccess
;
87 *return_code
= kIOReturnNotPrivileged
;
88 return kIOReturnSuccess
;
93 IOReturn
RootDomainUserClient::secureSetAggressiveness(
95 unsigned long newLevel
,
100 IOReturn ret
= kIOReturnNotPrivileged
;
102 ret
= clientHasPrivilege(fOwningTask
, kIOClientPrivilegeLocalUser
);
103 local_priv
= (kIOReturnSuccess
== ret
);
105 ret
= clientHasPrivilege(fOwningTask
, kIOClientPrivilegeAdministrator
);
106 admin_priv
= (kIOReturnSuccess
== ret
);
108 if((local_priv
|| admin_priv
) && fOwner
) {
109 *return_code
= fOwner
->setAggressiveness(type
, newLevel
);
110 return kIOReturnSuccess
;
112 *return_code
= kIOReturnNotPrivileged
;
113 return kIOReturnSuccess
;
119 IOReturn
RootDomainUserClient::clientClose( void )
124 task_deallocate(fOwningTask
);
128 return kIOReturnSuccess
;
132 RootDomainUserClient::getTargetAndMethodForIndex( IOService
** targetP
, UInt32 index
)
134 static IOExternalMethod sMethods
[] = {
135 { // kPMSetAggressiveness, 0
136 1, (IOMethod
)&RootDomainUserClient::secureSetAggressiveness
, kIOUCScalarIScalarO
, 2, 1
138 { // kPMGetAggressiveness, 1
139 0, (IOMethod
)&IOPMrootDomain::getAggressiveness
, kIOUCScalarIScalarO
, 1, 1
141 { // kPMSleepSystem, 2
142 1, (IOMethod
)&RootDomainUserClient::secureSleepSystem
, kIOUCScalarIScalarO
, 0, 1
144 { // kPMAllowPowerChange, 3
145 0, (IOMethod
)&IOPMrootDomain::allowPowerChange
, kIOUCScalarIScalarO
, 1, 0
147 { // kPMCancelPowerChange, 4
148 0, (IOMethod
)&IOPMrootDomain::cancelPowerChange
, kIOUCScalarIScalarO
, 1, 0
150 { // kPMShutdownSystem, 5
151 0, (IOMethod
)&IOPMrootDomain::shutdownSystem
, kIOUCScalarIScalarO
, 0, 0
153 { // kPMRestartSystem, 6
154 0, (IOMethod
)&IOPMrootDomain::restartSystem
, kIOUCScalarIScalarO
, 0, 0
156 { // kPMSetPreventative, 7
157 1, (IOMethod
) &RootDomainUserClient::setPreventative
, kIOUCScalarIScalarO
, 2, 0
161 if(index
>= kNumPMMethods
)
164 if (sMethods
[index
].object
)
169 return &sMethods
[index
];
174 RootDomainUserClient::setPreventative(UInt32 on_off
, UInt32 types_of_sleep
)