2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
28 #include <IOKit/assert.h>
29 #include <IOKit/IOLib.h>
30 #include <IOKit/IOBufferMemoryDescriptor.h>
31 #include "RootDomainUserClient.h"
32 #include <IOKit/pwr_mgt/IOPMLibDefs.h>
34 #define super IOUserClient
36 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
38 OSDefineMetaClassAndStructors(RootDomainUserClient
, IOUserClient
)
40 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
42 bool RootDomainUserClient::initWithTask(task_t owningTask
, void *security_id
, UInt32
)
47 fOwningTask
= owningTask
;
48 task_reference (fOwningTask
);
53 bool RootDomainUserClient::start( IOService
* provider
)
55 assert(OSDynamicCast(IOPMrootDomain
, provider
));
56 if(!super::start(provider
))
58 fOwner
= (IOPMrootDomain
*)provider
;
64 IOReturn
RootDomainUserClient::secureSleepSystem( int *return_code
)
68 IOReturn ret
= kIOReturnNotPrivileged
;
70 ret
= clientHasPrivilege(fOwningTask
, kIOClientPrivilegeLocalUser
);
71 local_priv
= (kIOReturnSuccess
== ret
);
73 ret
= clientHasPrivilege(fOwningTask
, kIOClientPrivilegeAdministrator
);
74 admin_priv
= (kIOReturnSuccess
== ret
);
76 if((local_priv
|| admin_priv
) && fOwner
) {
77 *return_code
= fOwner
->sleepSystem();
78 return kIOReturnSuccess
;
80 *return_code
= kIOReturnNotPrivileged
;
81 return kIOReturnSuccess
;
86 IOReturn
RootDomainUserClient::secureSetAggressiveness(
88 unsigned long newLevel
,
93 IOReturn ret
= kIOReturnNotPrivileged
;
95 ret
= clientHasPrivilege(fOwningTask
, kIOClientPrivilegeLocalUser
);
96 local_priv
= (kIOReturnSuccess
== ret
);
98 ret
= clientHasPrivilege(fOwningTask
, kIOClientPrivilegeAdministrator
);
99 admin_priv
= (kIOReturnSuccess
== ret
);
101 if((local_priv
|| admin_priv
) && fOwner
) {
102 *return_code
= fOwner
->setAggressiveness(type
, newLevel
);
103 return kIOReturnSuccess
;
105 *return_code
= kIOReturnNotPrivileged
;
106 return kIOReturnSuccess
;
112 IOReturn
RootDomainUserClient::clientClose( void )
117 task_deallocate(fOwningTask
);
121 return kIOReturnSuccess
;
125 RootDomainUserClient::getTargetAndMethodForIndex( IOService
** targetP
, UInt32 index
)
127 static IOExternalMethod sMethods
[] = {
128 { // kPMSetAggressiveness, 0
129 1, (IOMethod
)&RootDomainUserClient::secureSetAggressiveness
, kIOUCScalarIScalarO
, 2, 1
131 { // kPMGetAggressiveness, 1
132 0, (IOMethod
)&IOPMrootDomain::getAggressiveness
, kIOUCScalarIScalarO
, 1, 1
134 { // kPMSleepSystem, 2
135 1, (IOMethod
)&RootDomainUserClient::secureSleepSystem
, kIOUCScalarIScalarO
, 0, 1
137 { // kPMAllowPowerChange, 3
138 0, (IOMethod
)&IOPMrootDomain::allowPowerChange
, kIOUCScalarIScalarO
, 1, 0
140 { // kPMCancelPowerChange, 4
141 0, (IOMethod
)&IOPMrootDomain::cancelPowerChange
, kIOUCScalarIScalarO
, 1, 0
143 { // kPMShutdownSystem, 5
144 0, (IOMethod
)&IOPMrootDomain::shutdownSystem
, kIOUCScalarIScalarO
, 0, 0
146 { // kPMRestartSystem, 6
147 0, (IOMethod
)&IOPMrootDomain::restartSystem
, kIOUCScalarIScalarO
, 0, 0
149 { // kPMSetPreventative, 7
150 1, (IOMethod
) &RootDomainUserClient::setPreventative
, kIOUCScalarIScalarO
, 2, 0
154 if(index
>= kNumPMMethods
)
157 if (sMethods
[index
].object
)
162 return &sMethods
[index
];
167 RootDomainUserClient::setPreventative(UInt32 on_off
, UInt32 types_of_sleep
)