2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
27 #include <IOKit/assert.h>
28 #include <IOKit/IOLib.h>
29 #include <IOKit/IOBufferMemoryDescriptor.h>
30 #include "RootDomainUserClient.h"
31 #include <IOKit/pwr_mgt/IOPMLibDefs.h>
33 #define super IOUserClient
35 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
37 OSDefineMetaClassAndStructors(RootDomainUserClient
, IOUserClient
)
39 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
41 bool RootDomainUserClient::initWithTask(task_t owningTask
, void *security_id
, UInt32
)
46 fOwningTask
= owningTask
;
47 task_reference (fOwningTask
);
52 bool RootDomainUserClient::start( IOService
* provider
)
54 assert(OSDynamicCast(IOPMrootDomain
, provider
));
55 if(!super::start(provider
))
57 fOwner
= (IOPMrootDomain
*)provider
;
63 IOReturn
RootDomainUserClient::secureSleepSystem( int *return_code
)
67 IOReturn ret
= kIOReturnNotPrivileged
;
69 ret
= clientHasPrivilege(fOwningTask
, kIOClientPrivilegeLocalUser
);
70 local_priv
= (kIOReturnSuccess
== ret
);
72 ret
= clientHasPrivilege(fOwningTask
, kIOClientPrivilegeAdministrator
);
73 admin_priv
= (kIOReturnSuccess
== ret
);
75 if((local_priv
|| admin_priv
) && fOwner
) {
76 *return_code
= fOwner
->sleepSystem();
77 return kIOReturnSuccess
;
79 *return_code
= kIOReturnNotPrivileged
;
80 return kIOReturnSuccess
;
85 IOReturn
RootDomainUserClient::secureSetAggressiveness(
87 unsigned long newLevel
,
92 IOReturn ret
= kIOReturnNotPrivileged
;
94 ret
= clientHasPrivilege(fOwningTask
, kIOClientPrivilegeLocalUser
);
95 local_priv
= (kIOReturnSuccess
== ret
);
97 ret
= clientHasPrivilege(fOwningTask
, kIOClientPrivilegeAdministrator
);
98 admin_priv
= (kIOReturnSuccess
== ret
);
100 if((local_priv
|| admin_priv
) && fOwner
) {
101 *return_code
= fOwner
->setAggressiveness(type
, newLevel
);
102 return kIOReturnSuccess
;
104 *return_code
= kIOReturnNotPrivileged
;
105 return kIOReturnSuccess
;
111 IOReturn
RootDomainUserClient::clientClose( void )
116 task_deallocate(fOwningTask
);
120 return kIOReturnSuccess
;
124 RootDomainUserClient::getTargetAndMethodForIndex( IOService
** targetP
, UInt32 index
)
126 static IOExternalMethod sMethods
[] = {
127 { // kPMSetAggressiveness, 0
128 1, (IOMethod
)&RootDomainUserClient::secureSetAggressiveness
, kIOUCScalarIScalarO
, 2, 1
130 { // kPMGetAggressiveness, 1
131 0, (IOMethod
)&IOPMrootDomain::getAggressiveness
, kIOUCScalarIScalarO
, 1, 1
133 { // kPMSleepSystem, 2
134 1, (IOMethod
)&RootDomainUserClient::secureSleepSystem
, kIOUCScalarIScalarO
, 0, 1
136 { // kPMAllowPowerChange, 3
137 0, (IOMethod
)&IOPMrootDomain::allowPowerChange
, kIOUCScalarIScalarO
, 1, 0
139 { // kPMCancelPowerChange, 4
140 0, (IOMethod
)&IOPMrootDomain::cancelPowerChange
, kIOUCScalarIScalarO
, 1, 0
142 { // kPMShutdownSystem, 5
143 0, (IOMethod
)&IOPMrootDomain::shutdownSystem
, kIOUCScalarIScalarO
, 0, 0
145 { // kPMRestartSystem, 6
146 0, (IOMethod
)&IOPMrootDomain::restartSystem
, kIOUCScalarIScalarO
, 0, 0
148 { // kPMSetPreventative, 7
149 1, (IOMethod
) &RootDomainUserClient::setPreventative
, kIOUCScalarIScalarO
, 2, 0
153 if(index
>= kNumPMMethods
)
156 if (sMethods
[index
].object
)
161 return &sMethods
[index
];
166 RootDomainUserClient::setPreventative(UInt32 on_off
, UInt32 types_of_sleep
)